DBA Data[Home] [Help]

PACKAGE BODY: APPS.PON_AUCTION_PKG

Source


1 PACKAGE BODY PON_AUCTION_PKG as
2 /* $Header: PONAUCTB.pls 120.93.12010000.2 2008/08/03 03:45:17 sarunach ship $ */
3 
4 g_module_prefix         CONSTANT VARCHAR2(50) := 'pon.plsql.PON_AUCTION_PKG.';
5 g_userName    varchar2(2000);
6 g_phoneNumber varchar2(2000);
7 g_faxNumber   varchar2(2000);
8 g_eMail       varchar2(2000);
9 p_t_zone_temp varchar2(20) := '243';
10 g_module      varchar2(200) := 'pon.plsql.pon_auction_pkg';
11 g_original_language  FND_LANGUAGES.nls_language%TYPE;
12 g_original_lang_code FND_LANGUAGES.language_code%TYPE;
13 g_tp_cache_rec two_part_cache_rec; -- bug 6374353
14 
15 -------------------------------------------------------------------------------
16 --------------------------  HELPER FUNCTIONS ----------------------------------
17 -------------------------------------------------------------------------------
18 
19 PROCEDURE EMAIL_LIST(p_itemtype      IN  VARCHAR2,
20          p_itemkey      IN  VARCHAR2,
21             p_actid      IN  NUMBER,
22          p_notification_id    OUT NOCOPY NUMBER);
23 
24 PROCEDURE EMAIL_BIDDERS(p_itemtype      IN  VARCHAR2,
25            p_itemkey      IN  VARCHAR2,
26                p_actid        IN  NUMBER,
27            p_message_name      IN  VARCHAR2,
28            p_notification_id    OUT NOCOPY NUMBER);
29 
30 
31 PROCEDURE SET_PREVIEW_DATE(
32           p_itemtype      IN  VARCHAR2,
33            p_itemkey      IN  VARCHAR2,
34            p_preview_date  IN DATE,
35           p_publish_auction_now_flag IN VARCHAR2,
36           p_timezone_disp  IN VARCHAR2,
37           p_msg_suffix  IN VARCHAR2);
38 
39 PROCEDURE SET_OPEN_DATE(
40           p_itemtype      IN  VARCHAR2,
41            p_itemkey      IN  VARCHAR2,
42            p_auction_start_date  IN DATE,
43           p_open_auction_now_flag IN VARCHAR2,
44           p_timezone_disp  IN VARCHAR2,
45           p_msg_suffix  IN VARCHAR2);
46 
47 PROCEDURE SET_CLOSE_DATE(
48           p_itemtype      IN  VARCHAR2,
49            p_itemkey      IN  VARCHAR2,
50            p_auction_end_date  IN DATE,
51           p_timezone_disp  IN VARCHAR2);
52 
53 
54 PROCEDURE ADD_BIDDER_TO_ROLE(p_user_name  VARCHAR2,
55            p_role_name  VARCHAR2);
56 
57 
58 PROCEDURE LAUNCH_NOTIF_PROCESS(p_itemtype    in varchar2,
59              p_itemkey    in varchar2,
60              p_actid                  IN NUMBER,
61              p_process   IN VARCHAR2);
62 
63 FUNCTION IS_EVENT_AUCTION(p_auction_number IN NUMBER) RETURN VARCHAR2;
64 
65 FUNCTION getTokenMessage (msg VARCHAR2) RETURN VARCHAR2;
66 
67 PROCEDURE init_two_part_cache; -- bug 6374353
68 PROCEDURE update_cache_rec; -- bug 6374353
69 
70 PO_SUCCESS NUMBER := 1;
71 DUPLICATE_PO_NUMBER NUMBER := 2;
72 PO_SYSTEM_ERROR NUMBER := 3;
73 SOURCING_SYSTEM_ERROR NUMBER := 4;
74 
75 TYPE MsgTokensType IS TABLE OF VARCHAR2(50) INDEX BY BINARY_INTEGER;
76 TYPE MsgTokenValuesType IS TABLE OF VARCHAR2(2000) INDEX BY BINARY_INTEGER;
77 
78 MsgTokens MsgTokensType;
79 MsgTokenValues MsgTokenValuesType;
80 
81 FUNCTION GET_USER_NAME (p_user_id NUMBER) RETURN VARCHAR2;
82 
83 FUNCTION MEMBER_USER(p_user_name VARCHAR2) RETURN BOOLEAN;
84 FUNCTION ADDITIONAL_BIDDER(p_user_name VARCHAR2, p_doc_id int, p_preparer_tp_contact_name varchar2,
85 x_profile_user IN OUT NOCOPY VARCHAR2) return BOOLEAN;
86 
87 FUNCTION differentStrings(st1 VARCHAR2, st2 VARCHAR2) return BOOLEAN;
88 
89 PROCEDURE NOTIFY_MEMBER(p_userPartyId           IN NUMBER,
90                         p_auctioneer_user_name  IN VARCHAR2,
91                         p_auction_start_date    IN DATE,
92                         p_auction_end_date      IN DATE,
93                         p_preview_date          IN DATE,
94                         p_msg_sent_date         IN DATE,
95                         p_msg_suffix            IN VARCHAR2,
96                         p_doc_number            IN VARCHAR2,
97                         p_auction_title         IN VARCHAR2,
98                         p_entryid               IN NUMBER,
99                         p_auction_header_id     IN NUMBER,
100                         p_fromFirstName         IN VARCHAR2,
101                         p_fromLastName          IN VARCHAR2,
102                         p_from_id               IN NUMBER,
103                         p_notif_performer       IN VARCHAR2,
104                         p_subject               IN VARCHAR2,
105                         p_message_type          IN VARCHAR2,
106                         p_fromCompanyName       IN VARCHAR2,
107                         p_discussion_id         IN NUMBER,
108                         p_stagger_closing_interval IN NUMBER,
109                         p_open_auction_now_flag IN VARCHAR2,
110                         p_publish_auction_now_flag IN VARCHAR2
111                         );
112 
113 -------------------------------------------------------------------------------
114 --------------------------  PACKAGE BODY --------------------------------------
115 -------------------------------------------------------------------------------
116 -- FPK: CPA Function to check if negotiation has lines or not
117 FUNCTION NEG_HAS_LINES (p_auction_number IN NUMBER) RETURN VARCHAR2 AS
118       x_has_items_flag       VARCHAR2(1);
119 BEGIN
120      BEGIN
121          select has_items_flag
122          into x_has_items_flag
123          from pon_auction_headers_all
124          where auction_header_id = p_auction_number;
125      EXCEPTION
126        WHEN NO_DATA_FOUND THEN
127         x_has_items_flag := 'Y';
128      END;
129          return(x_has_items_flag);
130 END NEG_HAS_LINES;
131 
132 
133 PROCEDURE EMAIL_LIST(p_itemtype      IN  VARCHAR2,
134          p_itemkey      IN  VARCHAR2,
135             p_actid      IN  NUMBER,
136          p_notification_id    OUT NOCOPY  NUMBER) IS
137 
138 x_auction_header_id  NUMBER;
139 x_open_bidding_date  DATE;
140 x_close_bidding_date  DATE;
141 x_original_close_bidding_date DATE;
142 x_newpreviewtime     DATE;
143 x_progress     VARCHAR2(3);
144 x_sequence    NUMBER;
145 x_itemtype    VARCHAR2(8) := 'PONPBLSH';
146 x_itemkey    VARCHAR2(50);
147 x_user_name    VARCHAR2(100);
148 x_contact_id    NUMBER;
149 x_timezone    VARCHAR2(80);
150 x_timezone1    VARCHAR2(80);
151 x_newstarttime    DATE;
152 x_newendtime    DATE;
153 x_startdate    DATE;
154 x_enddate    DATE;
155 x_auction_type          Varchar2(30);
156 x_auction_type_name     Varchar2(30) := '';
157 x_auctioneer_tag        Varchar2(30);
158 x_event_id              NUMBER;
159 x_event_title           VARCHAR2(80);
160 x_language_code    VARCHAR2(3) := null;
161 x_auctioneer_user_name  FND_USER.USER_NAME%TYPE;
162 x_preview_message       VARCHAR2(100);
163 x_article_doc_type      VARCHAR2(100);
164 
165 x_doctype_group_name    VARCHAR2(100);
166 x_msg_suffix     VARCHAR2(3) := '';
167 x_doc_number_dsp   VARCHAR2(30);
168 x_auction_contact_id    NUMBER;
169 x_oex_timezone          VARCHAR2(80);
170 x_oex_timezone1          VARCHAR2(80);
171 
172 x_wf_role_name          VARCHAR2(30);
173 x_app                   VARCHAR2(20);
174 
175 x_oex_header            VARCHAR2(2000);
176 x_oex_footer            VARCHAR2(2000);
177 x_status                VARCHAR2(10);
178 x_exception_msg         VARCHAR2(100);
179 x_operation_url   VARCHAR2(300);
180 x_oex_operation    VARCHAR2(2000);
181 x_auction_owner_tp_name VARCHAR2(300);
182 x_tp_display_name  VARCHAR2(300);
183 x_tp_id      NUMBER;
184 x_auction_title    VARCHAR2(2000);
185 x_note_to_new_supplier_type  VARCHAR2(30);
186 x_appstr                VARCHAR2(20);
187 x_auction_creator_contact_id  NUMBER;
188 x_timezone_disp                VARCHAR2(240);
189 x_timezone1_disp               VARCHAR2(240);
190 x_oex_timezone1_disp           VARCHAR2(240);
191 x_registration_key             VARCHAR2(100);
192 x_neg_summary_url_supplier     VARCHAR2(2000);
193 x_net_changes_url_supplier     VARCHAR2(2000);
194 x_isp_supplier_register_url    VARCHAR2(2000);
195 x_ack_part_url_supplier        VARCHAR2(2000);
196 x_amendment_number             NUMBER;
197 x_isAmendment                  VARCHAR(1) := 'N';
198 x_auction_round_number                 NUMBER;
199 x_auction_header_id_encrypted  varchar2(2000);
200 x_auction_header_id_orig_amend NUMBER;
201 x_orig_document_number PON_AUCTION_HEADERS_ALL.DOCUMENT_NUMBER%TYPE;
202 x_preview_date        DATE;
203 x_preview_date_notspec VARCHAR2(240);
204 l_origin_user_name             FND_USER.USER_NAME%TYPE;
205 
206 x_staggered_closing_interval   NUMBER;
207 x_staggered_close_note         VARCHAR2(1000);
208 
209 -- Bug 3824928: Removed obsolete columns from the SELECT below
210 CURSOR bidder_list IS
211     select pbp.trading_partner_name,
212      pbp.trading_partner_id,
213      pbp.trading_partner_contact_id,
214      pbp.trading_partner_contact_name,
215      pbp.additional_contact_email,
216      pbp.wf_user_name,
217            pbp.registration_id,
218            pbp.vendor_site_id,
219            decode(pbp.vendor_site_code, '-1', null, pbp.vendor_site_code) vendor_site_code,
220            pbp.requested_supplier_id,
221            pbp.requested_supplier_name,
222            pbp.requested_supplier_contact_id,
223            pbp.requested_supp_contact_name,
224            pcr.email_address rs_contact_email
225 -- lxchen
226     from pon_bidding_parties pbp,
227          pos_contact_requests pcr
228     where pbp.auction_header_id = x_auction_header_id and
229           pbp.requested_supplier_contact_id = pcr.contact_request_id (+)
230     union
231     select distinct trading_partner_name,
232            trading_partner_id,
233            trading_partner_contact_id,
234            pon_locale_pkg.get_party_display_name(trading_partner_contact_id) trading_partner_contact_name,
235            null additional_contact_email,
236            null wf_user_name,
237            to_number(null) registration_id,
238            vendor_site_id,
239            decode(vendor_site_code, '-1', null, vendor_site_code) vendor_site_code,
240            null requested_supplier_id,
241            null requested_supplier_name,
242            null requested_supplier_contact_id,
243            null requested_supp_contact_name,
244            null rs_contact_email
245      from  pon_bid_headers
246      where x_isAmendment = 'Y' and
247            auction_header_id in (select auction_header_id
248                                  from   pon_auction_headers_all
249                                  where  auction_header_id_orig_amend = (select auction_header_id_orig_amend
250                                                                         from   pon_auction_headers_all
251                                                                         where  auction_header_id = x_auction_header_id)) and
252            bid_status in ('ACTIVE', 'RESUBMISSION', 'DISQUALIFIED', 'DRAFT') and
253            trading_partner_contact_id NOT IN
254                        (SELECT nvl(trading_partner_contact_id, -1)
255                         FROM   pon_bidding_parties
256                         WHERE  auction_header_id = x_auction_header_id);
257 
258 
259 CURSOR c1_auction_type IS
260     select auction_header_id_orig_amend, nvl(amendment_number,0), nvl(auction_round_number, 1), auction_type,
261     event_id, event_title, trading_partner_id,
262     trading_partner_contact_id, original_close_bidding_date, trading_partner_contact_name,
263     staggered_closing_interval
264     from pon_auction_headers_all
265     where auction_header_id = x_auction_header_id;
266 
267 BEGIN
268 
269     x_progress := '010';
270 
271     x_auction_header_id := wf_engine.GetItemAttrNumber (itemtype => p_itemtype,
272                                                         itemkey  => p_itemkey,
273                                                        aname    => 'AUCTION_ID');
274 
275     l_origin_user_name := wf_engine.GetItemAttrText   (itemtype => p_itemtype,
276                                                         itemkey  => p_itemkey,
277                                                        aname    => 'ORIGIN_USER_NAME');
278 
279     x_auction_header_id_encrypted := wf_engine.GetItemAttrText (itemtype => p_itemtype,
280                                                          itemkey  => p_itemkey,
281                                                          aname    => 'AUCTION_ID_ENCRYPTED');
282 
283 --    x_auctioneer_user_name := wf_engine.GetItemAttrText (itemtype => p_itemtype,
284 --                                             itemkey  => p_itemkey,
285 --                                               aname    => 'PREPARER_TP_CONTACT_NAME');
286 
287     x_doctype_group_name := wf_engine.GetItemAttrText   (itemtype => p_itemtype,
288                                                          itemkey  => p_itemkey,
289                                                         aname    => 'DOC_INTERNAL_NAME');
290 
291     x_doc_number_dsp     := wf_engine.GetItemAttrText   (itemtype => p_itemtype,
292                                                          itemkey  => p_itemkey,
293                                                         aname    => 'DOC_NUMBER');
294 
295     x_preview_date := wf_engine.GetItemAttrDate (itemtype   => p_itemtype,
296                                                  itemkey    => p_itemkey,
297                                                  aname      => 'PREVIEW_DATE');
298 
299 
300     x_progress := '020';
301     open c1_auction_type;
302     fetch c1_auction_type
303     into x_auction_header_id_orig_amend,
304          x_amendment_number,
305          x_auction_round_number,
306          x_auction_type,
307          x_event_id,
308          x_event_title,
309    x_tp_id,
310    x_auction_creator_contact_id,
311          x_original_close_bidding_date,
312          x_auctioneer_user_name,
313          x_staggered_closing_interval;
314     close c1_auction_type;
315 
316     x_msg_suffix := GET_MESSAGE_SUFFIX (x_doctype_group_name);
317 
318     if (x_amendment_number > 0) then
319        x_isAmendment := 'Y';
320     end if;
321 
322     FOR bidder IN bidder_list LOOP
323 
324       --
325       -- Get next value in sequence for itemkey
326       --
327 
328       SELECT pon_auction_wf_publish_s.nextval
329       INTO   x_sequence
330       FROM   dual;
331 
332 
333       x_itemkey := (p_itemkey||'-'||to_char(x_sequence));
334 
335       wf_engine.CreateProcess(itemtype => x_itemtype,
336                             itemkey  => x_itemkey,
337                             process  => 'PUBLISH_MAIN');
338 
339       --
340       -- Set all the item attributes
341       --
342 
343       x_progress := '022';
344 
345 
346       wf_engine.SetItemAttrDate   (itemtype   => x_itemtype,
347                                    itemkey    => x_itemkey,
348                                    aname      => 'ORIGINAL_AUCTION_CLOSE_DATE',
349                                    avalue     => x_original_close_bidding_date);
350 
351       wf_engine.SetItemAttrNumber (itemtype   => x_itemtype,
352                                    itemkey    => x_itemkey,
353                                    aname      => 'AUCTION_ID',
354                                    avalue     => x_auction_header_id); /* using auction_id instead of
355                                                                          auction_number as a standard
356                                                                          across item types */
357 
358       wf_engine.SetItemAttrText (itemtype   => x_itemtype,
359                                  itemkey    => x_itemkey,
360                                  aname      => 'DOC_NUMBER',
361                                  avalue     => x_doc_number_dsp);
362 
363       wf_engine.SetItemAttrText (itemtype   => x_itemtype,
364                                  itemkey    => x_itemkey,
365                                  aname      => 'ORIGIN_USER_NAME',
366                                  avalue     => l_origin_user_name);
367 
368       wf_engine.SetItemAttrText (itemtype   => x_itemtype,
369                                  itemkey    => x_itemkey,
370                                  aname      => 'NOTE_TO_BIDDERS',
371                                  avalue     => replaceHtmlChars(wf_engine.GetItemAttrText (itemtype => p_itemtype,
372                     itemkey  => p_itemkey,
373                     aname    => 'NOTE_TO_BIDDERS')));
374 
375       x_auction_title := wf_engine.GetItemAttrText(itemtype => p_itemtype,
376                                  itemkey  => p_itemkey,
377                                  aname    => 'AUCTION_TITLE');
378 
379       wf_engine.SetItemAttrText (itemtype   => x_itemtype,
380                                  itemkey    => x_itemkey,
381                                  aname      => 'AUCTION_TITLE',
382                                  avalue     => replaceHtmlChars(x_auction_title));
383 
384       x_auction_owner_tp_name := wf_engine.GetItemAttrText(itemtype => p_itemtype,
385                                    itemkey  => p_itemkey,
386                                    aname    => 'PREPARER_TP_NAME');
387 
388       wf_engine.SetItemAttrText (itemtype   => x_itemtype,
389                                  itemkey    => x_itemkey,
390                                  aname      => 'PREPARER_TP_NAME',
391                              avalue     => x_auction_owner_tp_name);
392 
393       wf_engine.SetItemAttrNumber (itemtype  => x_itemtype,
394                                    itemkey    => x_itemkey,
395                                    aname      => 'NUMBER_OF_ITEMS',
396                              avalue     => wf_engine.GetItemAttrNumber (itemtype => p_itemtype,
397                                                                  itemkey  => p_itemkey,
398                                                                 aname    => 'NUMBER_OF_ITEMS'));
399       wf_engine.SetItemAttrNumber (itemtype  => x_itemtype,
400                                    itemkey    => x_itemkey,
401                                    aname      => 'TRADING_PARTNER_ID',
402                              avalue     => bidder.trading_partner_id);
403 
404       wf_engine.SetItemAttrNumber (itemtype  => x_itemtype,
405                                    itemkey    => x_itemkey,
406                                    aname      => 'DOC_ROUND_NUMBER',
407                              avalue     => wf_engine.GetItemAttrNumber (itemtype => p_itemtype,
408                                                                   itemkey  => p_itemkey,
409                                                                  aname    => 'DOC_ROUND_NUMBER'));
410 
411 
412       wf_engine.SetItemAttrNumber (itemtype  => x_itemtype,
413                                    itemkey    => x_itemkey,
414                                    aname      => 'DOC_AMENDMENT_NUMBER',
415                                                    avalue     => wf_engine.GetItemAttrNumber (itemtype => p_itemtype,
416                                                                               itemkey  => p_itemkey,
417                                                                               aname    => 'DOC_AMENDMENT_NUMBER'));
418 
419       begin
420 
421         wf_engine.SetItemAttrText   (itemtype   => x_itemtype,
422                                          itemkey    => x_itemkey,
423                                          aname      => '#WFM_HTMLAGENT',
424                                          avalue     => pon_wf_utl_pkg.get_base_external_supplier_url);
425       exception when others then
426         null;
427       end;
428 
429 
430       wf_engine.setItemAttrNumber  (itemtype =>  x_itemtype,
431                                     itemkey    => x_itemkey,
432                                     aname      => 'VENDOR_SITE_ID',
433                                     avalue     => bidder.vendor_site_id);
434 
435 
436      wf_engine.SetItemAttrText (itemtype  => x_itemtype,
437                              itemkey  => x_itemkey,
438                              aname  => 'PREPARER_TP_CONTACT_NAME',
439                              avalue  => x_auctioneer_user_name);
440 
441      BEGIN
442           x_staggered_close_note := NULL;
443           IF x_staggered_closing_interval IS NOT NULL THEN
444                x_staggered_close_note := wf_core.newline || wf_core.newline ||
445                                          getMessage('PON_STAGGERED_CLOSE_NOTIF_MSG') ||
446                                          wf_core.newline || wf_core.newline;
447           END IF;
448           wf_engine.SetItemAttrText( itemtype => x_itemtype,
449                                      itemkey  => x_itemkey,
450                                      aname    => 'STAGGERED_CLOSE_NOTE',
451                                      avalue   => x_staggered_close_note);
452                                                                                                                                                                EXCEPTION
453           WHEN OTHERS THEN
454                NULL;
455      END;
456 
457       begin
458         if (x_event_id is not null) then
459          wf_engine.SetItemAttrText (itemtype   => x_itemtype,
460                                     itemkey    => x_itemkey,
461                                     aname      => 'EVENT_TITLE',
462                               avalue     => replaceHtmlChars(wf_engine.GetItemAttrText (itemtype => p_itemtype,
463                                                                  itemkey  => p_itemkey,
464                                                                    aname    => 'EVENT_TITLE')));
465   end if;
466       exception
467    when others then
468     null;  -- if event title attr. does not exist in the workflow item then it is an older version
469       end;
470 
471        x_oex_timezone := Get_Oex_Time_Zone;
472 
473          --
474          -- Get the dates from the auction workflow
475          --
476 
477        x_startdate := wf_engine.GetItemAttrDate (itemtype => p_itemtype,
478                                                  itemkey  => p_itemkey,
479                                                  aname    => 'AUCTION_START_DATE');
480 
481        x_enddate   := wf_engine.GetItemAttrDate (itemtype => p_itemtype,
482                                                  itemkey  => p_itemkey,
483                                                  aname    => 'AUCTION_END_DATE');
484 
485 
486           x_progress := '030';
487 
488     -- Try and send the notification to the Auction Contact user for the company.
489     -- If no such person exists, then just send the noification to the Default
490     -- Admin for the company.  Every company should have a Default Admin relationship
491     -- and we do not allow users to invite companies that do not have a Defualt Admin
492     -- relationship.
493     -- FPH: bidder.trading_partner_contact_id should never be null and thus no need
494     -- for this if.
495 
496     x_auction_contact_id := bidder.trading_partner_contact_id;
497 
498      -- Bug 3824928: Contact id may be null.  Added IF below to prevent a
499      -- no data found error
500      IF x_auction_contact_id IS NOT NULL
501      THEN
502       BEGIN
503     select user_name,
504                  person_party_id
505     into x_user_name,
506                x_contact_id
507     from fnd_user
508           where person_party_id = x_auction_contact_id
509           and nvl(end_date, sysdate+1) > sysdate;
510       EXCEPTION
511        WHEN TOO_MANY_ROWS THEN
512           IF (NVL(FND_PROFILE.VALUE('AFLOG_ENABLED'),'N') = 'Y') THEN
513                IF (FND_LOG.level_unexpected >= FND_LOG.g_current_runtime_level) THEN
514                          FND_LOG.string(log_level => FND_LOG.level_unexpected,
515                                         module    => 'pon.plsql.pon_auction_pkg.email_list',
516                                         message   => 'Multiple Users found for person_party_id:'|| x_auction_contact_id);
517                END IF;
518          END IF;
519          select user_name,
520                 person_party_id
521           into x_user_name,
522                x_contact_id
523           from fnd_user
524           where person_party_id = x_auction_contact_id
525           and nvl(end_date, sysdate+1) > sysdate
526           and rownum=1;
527 
528       END;
529 
530 
531       wf_engine.SetItemAttrText (itemtype  => x_itemtype,
532                          itemkey  => x_itemkey,
533                          aname  => 'BIDDER_TP_CONTACT_NAME',
534                          avalue  => x_user_name);
535 
536     -- Get the user's time zone
537     --
538     x_timezone := Get_Time_Zone(x_auction_contact_id);
539 
540     if (x_timezone is null or x_timezone = '') then
541     x_timezone := x_oex_timezone;
542     end if;
543 
544 
545     --
546       -- Convert the dates to the user's timezone.
547     -- If the timezone is not recognized, just use PST
548     --
549 
550     IF (PON_OEX_TIMEZONE_PKG.VALID_ZONE(x_timezone) = 1) THEN
551        x_newstarttime := PON_OEX_TIMEZONE_PKG.CONVERT_TIME(x_startdate,x_oex_timezone,x_timezone);
552        x_newendtime := PON_OEX_TIMEZONE_PKG.CONVERT_TIME(x_enddate,x_oex_timezone,x_timezone);
553        x_newpreviewtime := PON_OEX_TIMEZONE_PKG.CONVERT_TIME(x_preview_date,x_oex_timezone,x_timezone);
554     ELSE
555        x_newstarttime := x_startdate;
556        x_newendtime := x_enddate;
557          x_newpreviewtime := x_preview_date;
558        x_timezone := x_oex_timezone;
559       END IF;
560 
561     PON_PROFILE_UTIL_PKG.GET_WF_LANGUAGE(x_user_name,x_language_code);
562    ELSE -- auction_contact_id is null -- Bug 3824928: added this
563 
564              --
565              -- Get the auctioneer's time zone
566              --
567              x_timezone := Get_Time_Zone(x_auctioneer_user_name);
568 
569              if (x_timezone is null or x_timezone = '') then
570                    x_timezone := x_oex_timezone;
571              end if;
572 
573 
574              --
575              -- Convert the dates to the auctioneer's timezone.
576              -- If the timezone is not recognized, just use PST
577              --
578 
579              IF (PON_OEX_TIMEZONE_PKG.VALID_ZONE(x_timezone) = 1) THEN
580 
581                 x_newstarttime := PON_OEX_TIMEZONE_PKG.CONVERT_TIME(x_startdate,x_oex_timezone,x_timezone);
582                 x_newendtime := PON_OEX_TIMEZONE_PKG.CONVERT_TIME(x_enddate,x_oex_timezone,x_timezone);
583                 x_newpreviewtime := PON_OEX_TIMEZONE_PKG.CONVERT_TIME(x_preview_date,x_oex_timezone,x_timezone);
584              ELSE
585 
586                 x_newstarttime := x_startdate;
587                 x_newendtime := x_enddate;
588                 x_newpreviewtime := x_preview_date;
589                 x_timezone := x_oex_timezone;
590             END IF;
591          -- Get the auctioneer's language
592             PON_PROFILE_UTIL_PKG.GET_WF_LANGUAGE(x_auctioneer_user_name,x_language_code);
593 
594         -- add requested supplier info if specified
595         if (bidder.requested_supplier_contact_id is not null) then --{
596         wf_engine.SetItemAttrText (itemtype => x_itemtype,
597                                    itemkey  => x_itemkey,
598                                    aname    => 'REQ_SUPPLIER_CONTACT_NAME',
599                                    avalue   => bidder.requested_supp_contact_NAME);
600 
601           wf_engine.SetItemAttrNumber (itemtype => x_itemtype,
602                                      itemkey  => x_itemkey,
603                                      aname    => 'REQ_SUPPLIER_CONTACT_ID',
604                                      avalue   => bidder.requested_supplier_contact_id);
605 
606           wf_engine.SetItemAttrText (itemtype => x_itemtype,
607                                    itemkey  => x_itemkey,
608                                    aname    => 'BIDDER_TP_CONTACT_NAME',
609                                    avalue   => bidder.requested_supp_contact_name);
610 
611       wf_engine.SetItemAttrText (itemtype   => x_itemtype,
612                                      itemkey    => x_itemkey,
613                                      aname      => 'REQ_SUPPLIER_USERNAME',
614                                      avalue   => bidder.wf_user_name); --(performer)
615 
616         end if; --} bidder.requested_supplier_contact_id is not null
617 
618       END IF; -- IF x_auction_contact_id IS NOT NULL
619 
620 
621     --
622      --Set the dates based on the user's time zone or auctioneer's time zone if bidder contact id is null
623     --
624 
625      x_timezone_disp := Get_TimeZone_Description(x_timezone, x_language_code);
626 
627 
628     wf_engine.SetItemAttrText (itemtype  => x_itemtype,
629                          itemkey  => x_itemkey,
630                          aname  => 'TP_TIME_ZONE',
631                          avalue  => x_timezone_disp);
632 
633           IF (x_preview_date IS NULL) THEN
634              x_timezone1_disp := null;
635           ELSE
636             x_timezone1_disp := x_timezone_disp;
637           END IF;
638 
639  -- Bug 4304399: Set the values of AUCTION_START_DATE and AUCTION_END_DATE
640  -- as the end_date is used to determine the timeout for the notifications
641  -- sent to the supplier
642           wf_engine.SetItemAttrDate     (itemtype   => x_itemtype,
643                                      itemkey    => x_itemkey,
644                                    aname      => 'AUCTION_START_DATE',
645                                    avalue     => x_startdate);
646 
647           wf_engine.SetItemAttrDate     (itemtype   => x_itemtype,
648                                      itemkey    => x_itemkey,
649                                    aname      => 'AUCTION_END_DATE',
650                                    avalue     => x_enddate);
651 
652           wf_engine.SetItemAttrDate (itemtype   => x_itemtype,
653                                      itemkey    => x_itemkey,
654                                    aname      => 'AUCTION_START_DATE_TZ',
655                                    avalue     => x_newstarttime);
656 
657 
658           wf_engine.SetItemAttrDate (itemtype   => x_itemtype,
659                                      itemkey    => x_itemkey,
660                                    aname      => 'AUCTION_END_DATE_TZ',
661                                    avalue     => x_newendtime);
662 
663           --
664           -- Set the Languague code base on the user's language or auctioneer's language if bidder contact id is null
665         --
666 
667     wf_engine.SetItemAttrText (itemtype  => x_itemtype,
668              itemkey  => x_itemkey,
669              aname  => 'TP_LANGUAGE_CODE',
670              avalue  => x_language_code);
671 
672           -- Set the userenv language so the message token (attribute) values that we retrieve using the
673           -- getMessage call return the message in the correct language => x_language_code
674      IF (FND_LOG.level_statement >= FND_LOG.g_current_runtime_level) THEN --{
675        FND_LOG.string(log_level => FND_LOG.level_statement,
676           module => g_module_prefix || 'EMAIL_LIST',
677           message  => '1. Calling SET_SESSION_LANGUAGE with x_language_code : ' || x_language_code);
678      END IF; --}
679 
680 	  SET_SESSION_LANGUAGE(null, x_language_code);
681 
682       --Bug 6472383 : Shifted the setting of preview date to this place so that the recipient's language, instead
683       --of the sender's language is taken into account when setting the preview date to 'Not Specified'
684 
685       IF (x_newpreviewtime is not null) THEN
686             wf_engine.SetItemAttrDate (itemtype    => x_itemtype,
687                                                        itemkey        => x_itemkey,
688                                                        aname        => 'PREVIEW_DATE_TZ',
689                                                        avalue        => x_newpreviewtime);
690 
691             wf_engine.SetItemAttrText (itemtype    => x_itemtype,
692                                                        itemkey        => x_itemkey,
693                                                        aname        => 'TP_TIME_ZONE1',
694                                                        avalue        => x_timezone1_disp);
695 
696             wf_engine.SetItemAttrText (itemtype    => x_itemtype,
697                                                       itemkey        => x_itemkey,
698                                                       aname        => 'PREVIEW_DATE_NOTSPECIFIED',
699                                                       avalue        => null);
700       ELSE
701             wf_engine.SetItemAttrDate (itemtype    => x_itemtype,
702                                                        itemkey        => x_itemkey,
703                                                        aname        => 'PREVIEW_DATE_TZ',
704                                                        avalue        => null);
705 
706             wf_engine.SetItemAttrText (itemtype    => x_itemtype,
707                                                         itemkey        => x_itemkey,
708                                                        aname        => 'TP_TIME_ZONE1',
709                                                         avalue        => x_timezone1_disp);
710 
711            wf_engine.SetItemAttrText (itemtype     => x_itemtype,
712                                                       itemkey        => x_itemkey,
713                                                       aname        => 'PREVIEW_DATE_NOTSPECIFIED',
714                                                       avalue        => PON_AUCTION_PKG.getMessage('PON_AUC_PREVIEW_DATE_NOTSPEC'));
715       END IF;
716 
717       --Bug 6268467 : Shifted the operation of setting of the attribute NET_CHANGES_URL to this place (i.e. after call to SET_SESSION_LANGUAGE) so that the
718       --logged in user will be able to login to the application in the language that is set in his preferences.
719       if (x_amendment_number > 0) then
720          -- call to notification utility package to get the redirect page url that
721          -- is responsible for getting the Net Changes page url and forward to it.
722          x_net_changes_url_supplier := pon_wf_utl_pkg.get_dest_page_url (
723 		                          p_dest_func => 'PONINQ_VIEW_NET_CHNG'
724                                  ,p_notif_performer  => 'SUPPLIER');
725       elsif (x_auction_round_number > 1 and x_amendment_number = 0) then
726          -- call to notification utility package to get the redirect page url that
727          -- is responsible for getting the Round Modifications page url and forward to it.
728          x_net_changes_url_supplier := pon_wf_utl_pkg.get_dest_page_url (
729 		                          p_dest_func => 'PONINQ_NEW_ROUND_SUM'
730                                  ,p_notif_performer  => 'SUPPLIER');
731       end if;
732 
733       wf_engine.SetItemAttrText (itemtype   => x_itemtype,
734                                  itemkey    => x_itemkey,
735                                  aname      => 'NET_CHANGES_URL',
736                                  avalue     => x_net_changes_url_supplier);
737 
738       --Bug 6268467 : Shifted the operation of setting of the attribute NEG_SUMMARY_URL to this place (i.e. after call to SET_SESSION_LANGUAGE) so that the
739       --logged in user will be able to login to the application in the language that is set in his preferences.
740 
741        -- call to notification utility package to get the redirect page url that
742        -- is responsible for getting the Negotiation Summary url and forward to it.
743        x_neg_summary_url_supplier := pon_wf_utl_pkg.get_dest_page_url (
744 		                          p_dest_func => 'PON_NEG_SUMMARY'
745                                  ,p_notif_performer  => 'SUPPLIER');
746 
747 
748       wf_engine.SetItemAttrText (itemtype   => x_itemtype,
749                                  itemkey    => x_itemkey,
750                                  aname      => 'NEG_SUMMARY_URL',
751                                  avalue     => x_neg_summary_url_supplier);
752 
753       --Bug 6268467 : Shifted the operation of setting of the attribute ACK_PARTICIPATION_URL to this place (i.e. after call to SET_SESSION_LANGUAGE) so that the
754       --logged in user will be able to login to the application in the language that is set in his preferences.
755 
756        -- call to notification utility package to get the redirect page url that
757        -- is responsible for getting the Acknowledge participation url and forward to it.
758        x_ack_part_url_supplier := pon_wf_utl_pkg.get_dest_page_url (
759 		                          p_dest_func => 'PONRESAPN_ACKPARTICIPATN'
760                                  ,p_notif_performer  => 'SUPPLIER');
761 
762        wf_engine.SetItemAttrText (itemtype   => x_itemtype,
763                                  itemkey    => x_itemkey,
764                                  aname      => 'ACK_PARTICIPATION_URL',
765                                  avalue     => x_ack_part_url_supplier);
766 
767 
768       x_tp_display_name := nvl(bidder.trading_partner_name, bidder.requested_supplier_name);
769 
770       wf_engine.SetItemAttrText (itemtype  => x_itemtype,
771         itemkey  => x_itemkey,
772         aname   => 'TP_DISPLAY_NAME',
773         avalue  => x_tp_display_name);
774 
775       wf_engine.SetItemAttrText (itemtype   => x_itemtype,
776                                         itemkey    => x_itemkey,
777                                         aname      => 'BIDDER_TP_NAME',
778                                         avalue     => x_tp_display_name);
779 
780       wf_engine.SetItemAttrText (itemtype  => x_itemtype,
781         itemkey  => x_itemkey,
782         aname      => 'BIDDER_TP_ADDRESS_NAME',
783         avalue     => bidder.vendor_site_code);
784 
785 
786       wf_engine.SetItemAttrText (itemtype   => x_itemtype,
787                                itemkey    => x_itemkey,
788                                aname      => 'DOC_INTERNAL_NAME',
789                                avalue     => x_doctype_group_name);
790 
791 
792       -- New messages for complete customization
793 
794       select document_number
795       into   x_orig_document_number
796       from   pon_auction_headers_all
797       where  auction_header_id = x_auction_header_id_orig_amend;
798 
799 
800       wf_engine.SetItemAttrText (itemtype       => x_itemtype,
801                                  itemkey        => x_itemkey,
802                                  aname          => 'AMENDMENT_START_SUB',
803                                  avalue         => getMessage('PON_AUC_WF_PUB_AMEND_RG_S', x_msg_suffix,
804                                                                       'AMENDMENT_NUMBER', x_amendment_number,
805                                                                       'ORIG_NUMBER', x_orig_document_number,
806                                           'AUCTION_TITLE', replaceHtmlChars(x_auction_title)));
807 
808 
809       wf_engine.SetItemAttrText (itemtype  => x_itemtype,
810          itemkey  => x_itemkey,
811          aname    => 'INVITE_NEW_ROUND_START_SUB',
812          avalue    => getMessage('PON_AUC_WF_PUB_NEWRND_RG_S', x_msg_suffix,
813                             'DOC_NUMBER', x_doc_number_dsp,
814                                           'AUCTION_TITLE', replaceHtmlChars(x_auction_title)));
815 
816       wf_engine.SetItemAttrText (itemtype       => x_itemtype,
817                                  itemkey        => x_itemkey,
818                                  aname          => 'INVITE_RESPONSE_SUB',
819                                  avalue         => getMessage('PON_AUC_WF_PUB_OPEN_RG_S', x_msg_suffix,
820                                                               'DOC_NUMBER', x_doc_number_dsp,
821                                                               'AUCTION_TITLE', replaceHtmlChars(x_auction_title)));
822 
823 
824       --
825       -- Start the publish notification
826       --
827 
828       -- IF (bidder.additional_contact_email is not null) then we need to send a notification
829       -- to the additional contact as well
830       -- Populate the ADDITIONAL_CONTACT_USERNAME attribute so that a notification is sent to this local
831       -- use as well
832       -- In FPH, we provide a registration link to the additional contact.
833 
834       if (bidder.additional_contact_email is not null) then
835 
836         wf_engine.SetItemAttrText (itemtype   => x_itemtype,
837                                     itemkey    => x_itemkey,
838                                     aname      => 'ADDITIONAL_CONTACT_USERNAME',
839                            avalue    => bidder.wf_user_name);
840 
841 
842               begin
843                 select registration_key
844                   into x_registration_key
845                   from fnd_registrations
846                  where registration_id  = bidder.registration_id;
847               exception
848                   WHEN NO_DATA_FOUND THEN
849                        x_registration_key := '';
850               end;
851 
852            -- call to notification utility package to get the iSupplier registration page url
853            x_isp_supplier_register_url := pon_wf_utl_pkg.get_isp_supplier_register_url(p_registration_key => x_registration_key
854                                                                                       ,p_language_code => x_language_code);
855 
856            wf_engine.SetItemAttrText (itemtype   => x_itemtype,
857                                       itemkey    => x_itemkey,
858                                       aname      => 'ISP_SUPPLIER_REG_URL',
859                                       avalue     => x_isp_supplier_register_url);
860 
861       end if;
862 
863     -- Bug 4295915: Set the  workflow owner
864       wf_engine.SetItemOwner(itemtype => x_itemtype,
865                              itemkey  => x_itemkey,
866                              owner    => fnd_global.user_name);
867 
868       wf_engine.StartProcess(itemtype => x_itemtype,
869                              itemkey  => x_itemkey );
870 
871       update pon_bidding_parties
872          set wf_item_key = x_itemkey
873       where  auction_header_id = x_auction_header_id and
874              ((trading_partner_id = bidder.trading_partner_id and
875                vendor_site_id = bidder.vendor_site_id) or
876                requested_supplier_id = bidder.requested_supplier_id);
877 
878    END LOOP;
879 
880    UNSET_SESSION_LANGUAGE;
881 
882 END;
883 
884 
885 
886 PROCEDURE EMAIL_BIDDERS(p_itemtype      IN  VARCHAR2,
887            p_itemkey      IN  VARCHAR2,
888                p_actid        IN  NUMBER,
889            p_message_name      IN  VARCHAR2,
890            p_notification_id    OUT NOCOPY NUMBER) IS
891 
892 x_auction_header_id  NUMBER;
893 x_progress     VARCHAR2(3);
894 
895 CURSOR bidder_list IS
896     select trading_partner_contact_name
897     from pon_bid_headers
898     where auction_header_id = x_auction_header_id;
899 
900 BEGIN
901 
902     x_progress := '010';
903 
904     x_auction_header_id := wf_engine.GetItemAttrNumber (itemtype => p_itemtype,
905                                                         itemkey  => p_itemkey,
906                                                        aname    => 'AUCTION_ID');
907 
908     x_progress := '020';
909 
910     FOR bidder IN bidder_list LOOP
911 
912        x_progress := '030';
913 
914           wf_engine.SetItemAttrText (itemtype   => p_itemtype,
915                                   itemkey    => p_itemkey,
916                                     aname      => 'BIDDER_DISPLAY_NAME',
917                                      avalue     => bidder.trading_partner_contact_name);
918 
919 
920     p_notification_id := WF_NOTIFICATION.send(role   => bidder.trading_partner_contact_name,
921                  context  => p_itemtype||':'||p_itemkey||':'||to_char(p_actid),
922                        msg_type   => 'PONAUCT',
923                 msg_name   => p_message_name);
924    END LOOP;
925 
926 
927 END;
928 
929 PROCEDURE START_AUCTION(p_auction_header_id_encrypted   VARCHAR2,   --  1
930                         p_auction_header_id            NUMBER,    --  2
931                   p_trading_partner_contact_name  VARCHAR2,  --  3
932                       p_trading_partner_contact_id  NUMBER,    --  4
933                     p_trading_partner_name        VARCHAR2,  --  5
934                       p_trading_partner_id        NUMBER,    --  6
935                      p_open_bidding_date            DATE,    --  7
936                     p_close_bidding_date        DATE,    --  8
937                   p_award_by_date                 DATE,       --  9
938                   p_reminder_date              DATE,    -- 10
939                   p_bid_list_type              VARCHAR2,  -- 11
940                      p_note_to_bidders            VARCHAR2,  -- 12
941                   p_number_of_items            NUMBER,    -- 13
942                   p_auction_title              VARCHAR2,  -- 14
943                         p_event_id                      NUMBER) IS   -- 15
944 
945 
946 
947 x_sequence  NUMBER;
948 x_itemtype  VARCHAR2(7) := 'PONAUCT';
949 x_itemkey  VARCHAR2(50);
950 x_bid_list  VARCHAR2(1);
951 x_progress  VARCHAR2(3);
952 x_new_bidders_flag  VARCHAR2(1) := 'N';
953 x_timezone  VARCHAR2(80);
954 x_newstarttime  DATE;
955 x_newendtime  DATE;
956 x_preparer_contact_dp_name varchar2(240);
957 x_event_title   varchar2(80);
958 x_notification_date DATE;
959 x_language_code VARCHAR2(3) := null;
960 x_reminder_date DATE;
961 x_auction_round_number NUMBER;
962 x_amendment_number NUMBER;
963 x_auction_header_id_orig_amend NUMBER;
964 x_preview_date DATE;
965 x_difference NUMBER;
966 
967 x_doctype_group_name VARCHAR2(60);
968 x_doc_number_dsp     PON_AUCTION_HEADERS_ALL.DOCUMENT_NUMBER%TYPE;
969 x_neg_summary_url_buyer       VARCHAR2(2000);
970 x_net_changes_url_buyer       VARCHAR2(2000);
971 x_msg_suffix VARCHAR2(3);
972 
973 x_oex_timezone VARCHAR2(80);
974 
975 x_timezone_disp VARCHAR2(240);
976 x_doctype_display_name  VARCHAR2(10);
977 x_notif_subject VARCHAR2(300);
978 x_orig_document_number PON_AUCTION_HEADERS_ALL.DOCUMENT_NUMBER%TYPE;
979 
980 x_timezone1    VARCHAR2(80); -- preview timezone
981 x_newpreviewtime  DATE;
982 x_timezone1_disp        VARCHAR2(240);
983 
984 x_return_status   VARCHAR2(20);
985 x_msg_count       NUMBER;
986 x_msg_data         VARCHAR2(2000);
987 
988 CURSOR c1_auction_info(x_lang VARCHAR2) IS
989     select document_number, auction_header_id_orig_amend, dt.doctype_group_name,
990            nvl(auction_round_number, 1), nvl(amendment_number, 0),
991      hz.person_first_name || ' ' ||  hz.person_last_name,
992        decode(sign(close_bidding_date - nvl(view_by_date, open_bidding_date) - 7), 1, nvl(view_by_date, open_bidding_date)+3,
993                   decode(sign(close_bidding_date - nvl(view_by_date, open_bidding_date) - 1), 1, nvl(view_by_date, open_bidding_date) + 1,
994                   nvl(view_by_date, open_bidding_date) + 1/24)) reminder_time
995     from pon_auction_headers_all auh, hz_parties hz, pon_auc_doctypes dt
996     where hz.party_id = auh.trading_partner_contact_id
997     and auh.doctype_id = dt.doctype_id
998     and auction_header_id = p_auction_header_id;
999 BEGIN
1000 
1001     --
1002     -- Get the auctioneer's language code so that the c1_auction_info
1003     -- has right value for x_language_code
1004     --
1005     IF p_trading_partner_contact_name is not null THEN
1006       PON_PROFILE_UTIL_PKG.GET_WF_LANGUAGE(p_trading_partner_contact_name,x_language_code);
1007     END IF;
1008 
1009     x_progress := '010';
1010 
1011     --
1012     -- Get next value in sequence for itemkey
1013     --
1014     SELECT pon_auction_wf_s.nextval
1015     INTO   x_sequence
1016     FROM   dual;
1017     -- get the contact name and auction type
1018     -- to fix bug 2797825, overwritting reminder_date, which is null up to
1019     -- this point
1020     open c1_auction_info(x_language_code);
1021     fetch c1_auction_info
1022     into x_doc_number_dsp, x_auction_header_id_orig_amend, x_doctype_group_name, x_auction_round_number, x_amendment_number, x_preparer_contact_dp_name, x_reminder_date;
1023 
1024     x_progress := '020';
1025 
1026     x_itemkey := (to_char(p_auction_header_id)||'-'||to_char(x_sequence));
1027 
1028     --
1029     -- Create the wf process
1030     --
1031 
1032     wf_engine.CreateProcess(itemtype => x_itemtype,
1033                             itemkey  => x_itemkey,
1034                             process  => 'AUCTION_ENGINE');
1035 
1036 
1037     -- Set the userenv language so the message token (attribute) values that we retrieve using the
1038     -- getMessage call return the message in the correct language => x_language_code
1039     IF (FND_LOG.level_statement >= FND_LOG.g_current_runtime_level) THEN --{
1040        FND_LOG.string(log_level => FND_LOG.level_statement,
1041          module => g_module_prefix || 'START_AUCTION',
1042          message  => '2. Calling SET_SESSION_LANGUAGE with x_language_code : ' || x_language_code);
1043     END IF; --}
1044 
1045     SET_SESSION_LANGUAGE(null, x_language_code);
1046 
1047 
1048     --
1049     -- Set all the item attributes
1050     --
1051 
1052     x_progress := '022';
1053 
1054 
1055     wf_engine.SetItemAttrDate (itemtype   => x_itemtype,
1056                                itemkey    => x_itemkey,
1057                                aname      => 'AUCTION_REMINDER_DATE',
1058                                avalue     => x_reminder_date);
1059 
1060     wf_engine.SetItemAttrText(itemtype   => x_itemtype,
1061                               itemkey    => x_itemkey,
1062                               aname      => 'AUCTION_ID_ENCRYPTED',
1063                               avalue     => p_auction_header_id_encrypted);
1064 
1065     wf_engine.SetItemAttrNumber (itemtype   => x_itemtype,
1066                                itemkey    => x_itemkey,
1067                                aname      => 'AUCTION_ID',
1068                                avalue     => p_auction_header_id);
1069 
1070 
1071     wf_engine.SetItemAttrText (itemtype   => x_itemtype,
1072                                itemkey    => x_itemkey,
1073                                aname      => 'ORIGIN_USER_NAME',
1074                                avalue     => fnd_global.user_name);
1075 
1076 
1077     wf_engine.SetItemAttrNumber (itemtype   => x_itemtype,
1078                                itemkey    => x_itemkey,
1079                                aname      => 'PREPARER_TP_CONTACT_ID',
1080                                avalue     => p_trading_partner_contact_id);
1081 
1082     wf_engine.SetItemAttrNumber (itemtype   => x_itemtype,
1083                                itemkey    => x_itemkey,
1084                                aname      => 'PREPARER_TP_ID',
1085                                avalue     => p_trading_partner_id);
1086 
1087     wf_engine.SetItemAttrDate (itemtype   => x_itemtype,
1088                                itemkey    => x_itemkey,
1089                                aname      => 'AUCTION_START_DATE',
1090                                avalue     => p_open_bidding_date);
1091 
1092     wf_engine.SetItemAttrDate (itemtype   => x_itemtype,
1093                                itemkey    => x_itemkey,
1094                                aname      => 'AUCTION_END_DATE',
1095                                avalue     => p_close_bidding_date);
1096 
1097     wf_engine.SetItemAttrDate (itemtype   => x_itemtype,
1098                                itemkey    => x_itemkey,
1099                                aname      => 'AUCTION_AWARD_DATE',
1100                                avalue     => p_award_by_date);
1101 
1102 
1103    select nvl(view_by_date,open_bidding_date)
1104    into x_notification_date
1105    from pon_auction_headers_all where auction_header_id = p_auction_header_id;
1106 
1107     wf_engine.SetItemAttrDate (itemtype   => x_itemtype,
1108                                itemkey    => x_itemkey,
1109                                aname      => 'AUCTION_NOTIFICATION_DATE',
1110                                avalue     => x_notification_date);
1111 
1112     IF (p_bid_list_type IS NULL) THEN
1113   x_bid_list := 'N';
1114     ELSE
1115   x_bid_list := 'Y';
1116     END IF;
1117 
1118     wf_engine.SetItemAttrText (itemtype   => x_itemtype,
1119                                itemkey    => x_itemkey,
1120                                aname      => 'BIDDER_LIST_FLAG',
1121                                avalue     => x_bid_list);
1122 
1123     IF(x_bid_list = 'Y') THEN
1124   BEGIN
1125           select 'Y' into x_new_bidders_flag from pon_bidding_parties
1126           where auction_header_id = p_auction_header_id
1127           and trading_partner_id is null group by auction_header_id;
1128   EXCEPTION
1129          WHEN NO_DATA_FOUND THEN
1130       x_new_bidders_flag := 'N';
1131     END;
1132 
1133     END IF;
1134 
1135     wf_engine.SetItemAttrText (itemtype   => x_itemtype,
1136                                itemkey    => x_itemkey,
1137                                aname      => 'NEW_BIDDERS_FLAG',
1138                                avalue     => x_new_bidders_flag);
1139 
1140     wf_engine.SetItemAttrText (itemtype   => x_itemtype,
1141                                itemkey    => x_itemkey,
1142                                aname      => 'NOTE_TO_BIDDERS',
1143                                avalue     => replaceHtmlChars(p_note_to_bidders));
1144 
1145     wf_engine.SetItemAttrNumber (itemtype   => x_itemtype,
1146                                itemkey    => x_itemkey,
1147                                aname      => 'NUMBER_OF_ITEMS',
1148                                avalue     => p_number_of_items);
1149 
1150     -- call to notification utility package to set the message header common attributes and #from_role
1151     pon_wf_utl_pkg.set_hdr_attributes (p_itemtype        => x_itemtype
1152                                   ,p_itemkey        => x_itemkey
1153                                       ,p_auction_tp_name  => p_trading_partner_name
1154                                     ,p_auction_title    => p_auction_title
1155                                     ,p_document_number  => x_doc_number_dsp
1156                                       ,p_auction_tp_contact_name => p_trading_partner_contact_name
1157                                       );
1158 
1159     -- added the contact display name
1160     wf_engine.SetItemAttrText (itemtype   => x_itemtype,
1161                                itemkey    => x_itemkey,
1162                                aname      => 'PREPARER_CONTACT_DP_NAME',
1163                                avalue     => x_preparer_contact_dp_name);
1164 
1165 
1166     -- 000001
1167 
1168    select view_by_date
1169    into x_preview_date
1170    from pon_auction_headers_all where auction_header_id = p_auction_header_id;
1171 
1172    if ((x_preview_date is not null) AND (p_open_bidding_date is not null)) then
1173       x_difference := p_open_bidding_date - x_preview_date;
1174    else
1175       x_difference := 0;
1176    end if;
1177 
1178    wf_engine.SetItemAttrDate (itemtype   => x_itemtype,
1179                               itemkey    => x_itemkey,
1180                               aname      => 'PREVIEW_DATE',
1181                               avalue     => x_preview_date);
1182 
1183     --
1184     -- Get the exchange's time zone
1185     --
1186 
1187          x_oex_timezone := Get_Oex_Time_Zone;
1188 
1189     --
1190     -- Get the user's time zone
1191     --
1192   x_timezone := Get_Time_Zone(p_trading_partner_contact_id);
1193 
1194     --
1195     -- Make sure that it is a valid time zone
1196     --
1197 
1198     IF (PON_OEX_TIMEZONE_PKG.VALID_ZONE(x_timezone) = 0) THEN
1199   x_timezone := x_oex_timezone;
1200     END IF;
1201 
1202     --
1203     -- Convert the dates to the user's timezone.
1204     --
1205     IF (PON_OEX_TIMEZONE_PKG.VALID_ZONE(x_timezone) = 1) THEN
1206        x_newstarttime := PON_OEX_TIMEZONE_PKG.CONVERT_TIME(p_open_bidding_date,x_oex_timezone,x_timezone);
1207        x_newendtime   := PON_OEX_TIMEZONE_PKG.CONVERT_TIME(p_close_bidding_date,x_oex_timezone,x_timezone);
1208        x_newpreviewtime := PON_OEX_TIMEZONE_PKG.CONVERT_TIME(x_preview_date,x_oex_timezone,x_timezone);
1209     ELSE
1210      x_newstarttime := p_open_bidding_date;
1211      x_newendtime := p_close_bidding_date;
1212        x_newpreviewtime := x_preview_date;
1213     END IF;
1214 
1215     IF (x_preview_date IS NULL) THEN
1216         x_timezone1 := ' ';
1217     ELSE
1218         x_timezone1 := x_timezone;
1219     END IF;
1220 
1221     x_timezone_disp:= Get_TimeZone_Description(x_timezone, x_language_code);
1222 
1223     wf_engine.SetItemAttrText (itemtype   => x_itemtype,
1224                                itemkey    => x_itemkey,
1225                                aname      => 'TP_TIME_ZONE',
1226                                avalue     => x_timezone_disp);
1227 
1228     wf_engine.SetItemAttrDate (itemtype   => x_itemtype,
1229                                itemkey    => x_itemkey,
1230                                aname      => 'AUCTION_START_DATE_TZ',
1231                                avalue     => x_newstarttime);
1232 
1233     wf_engine.SetItemAttrDate (itemtype   => x_itemtype,
1234                                itemkey    => x_itemkey,
1235                                aname      => 'AUCTION_END_DATE_TZ',
1236                                avalue     => x_newendtime);
1237 
1238     IF (x_newpreviewtime is not null) THEN
1239       wf_engine.SetItemAttrDate (itemtype  => x_itemtype,
1240                            itemkey  => x_itemkey,
1241                            aname  => 'PREVIEW_DATE_TZ',
1242                            avalue   => x_newpreviewtime);
1243 
1244       x_timezone1_disp := Get_TimeZone_Description(x_timezone1, x_language_code);
1245 
1246       wf_engine.SetItemAttrText (itemtype  => x_itemtype,
1247                            itemkey   => x_itemkey,
1248                            aname     => 'TP_TIME_ZONE1',
1249                            avalue    => x_timezone1_disp);
1250 
1251         wf_engine.SetItemAttrText (itemtype  => x_itemtype,
1252                            itemkey  => x_itemkey,
1253                            aname  => 'PREVIEW_DATE_NOTSPECIFIED',
1254                            avalue  => null);
1255     ELSE
1256         wf_engine.SetItemAttrDate (itemtype  => x_itemtype,
1257                            itemkey  => x_itemkey,
1258                            aname  => 'PREVIEW_DATE_TZ',
1259                            avalue     => null);
1260 
1261       wf_engine.SetItemAttrText (itemtype  => x_itemtype,
1262                            itemkey  => x_itemkey,
1263                              aname  => 'TP_TIME_ZONE1',
1264                              avalue     => null);
1265 
1266         wf_engine.SetItemAttrText (itemtype  => x_itemtype,
1267                            itemkey  => x_itemkey,
1268                            aname  => 'PREVIEW_DATE_NOTSPECIFIED',
1269                            avalue  => PON_AUCTION_PKG.getMessage('PON_AUC_PREVIEW_DATE_NOTSPEC'));
1270     END IF;
1271 
1272 
1273     if (p_event_id is not null) then
1274         x_event_title := getEventTitle (p_auction_header_id);
1275       wf_engine.SetItemAttrText (itemtype   => x_itemtype,
1276                                    itemkey    => x_itemkey,
1277                                    aname      => 'EVENT_TITLE',
1278                                    avalue     => replaceHtmlChars(x_event_title));
1279     end if;
1280 
1281     -- new 6.2 attributes.
1282 
1283     wf_engine.SetItemAttrText (itemtype   => x_itemtype,
1284                                itemkey    => x_itemkey,
1285                                aname      => 'DOC_INTERNAL_NAME',
1286                                avalue     => x_doctype_group_name);
1287 
1288     wf_engine.SetItemAttrNumber (itemtype   => x_itemtype,
1289                                  itemkey    => x_itemkey,
1290                                  aname      => 'DOC_ROUND_NUMBER',
1291                                  avalue     => x_auction_round_number);
1292 
1293     -- amendment attribute
1294 
1295     wf_engine.SetItemAttrNumber (itemtype   => x_itemtype,
1296                                  itemkey    => x_itemkey,
1297                                  aname      => 'DOC_AMENDMENT_NUMBER',
1298                                  avalue     => x_amendment_number);
1299 
1300     --  New attribute to hold the vendor site id. Attribute value is going
1301   -- to be used as a parameter to access Negotiation Summary page
1302     wf_engine.SetItemAttrNumber (itemtype   => x_itemtype,
1303                                itemkey    => x_itemkey,
1304                                aname      => 'VENDOR_SITE_ID',
1305                                avalue     => -1);
1306 
1307 
1308     x_msg_suffix := GET_MESSAGE_SUFFIX (x_doctype_group_name);
1309 
1310        -- call to notification utility package to get the redirect page url that
1311        -- is responsible for getting the Negotiation Summary url and forward to it.
1312        x_neg_summary_url_buyer := pon_wf_utl_pkg.get_dest_page_url (
1313                               p_dest_func => 'PON_NEG_SUMMARY'
1314                                  ,p_notif_performer  => 'BUYER');
1315 
1316     wf_engine.SetItemAttrText (itemtype   => x_itemtype,
1317                                itemkey    => x_itemkey,
1318                                aname      => 'NEG_SUMMARY_URL',
1319                                avalue     => x_neg_summary_url_buyer);
1320 
1321     -- call to notification utility package to get the Net Changes url accessed by buyer.
1322 
1323     if (x_amendment_number > 0) then
1324       -- call to notification utility package to get the redirect page url that
1325        -- is responsible for getting the Net Changes page url and forward to it.
1326        x_net_changes_url_buyer := pon_wf_utl_pkg.get_dest_page_url (
1327                               p_dest_func => 'PONINQ_VIEW_NET_CHNG'
1328                                  ,p_notif_performer  => 'BUYER');
1329     elsif (x_auction_round_number > 1 and x_amendment_number = 0) then
1330        -- call to notification utility package to get the redirect page url that
1331        -- is responsible for getting the Round Modifications page url and forward to it.
1332        x_net_changes_url_buyer := pon_wf_utl_pkg.get_dest_page_url (
1333                               p_dest_func => 'PONINQ_NEW_ROUND_SUM'
1334                                  ,p_notif_performer  => 'BUYER');
1335     end if;
1336 
1337 
1338     wf_engine.SetItemAttrText (itemtype   => x_itemtype,
1339                                itemkey    => x_itemkey,
1340                                aname      => 'NET_CHANGES_URL',
1341                                avalue     => x_net_changes_url_buyer);
1342 
1343 
1344    select document_number
1345    into   x_orig_document_number
1346    from   pon_auction_headers_all
1347    where  auction_header_id = x_auction_header_id_orig_amend;
1348 
1349 
1350 --- 000001
1351 
1352    if (x_amendment_number = 0) then -- first round negotiaton
1353      if (x_difference > 0 and sysdate < p_open_bidding_date) then -- preview mode
1354        if (x_event_title is not null) then -- part of event
1355          x_notif_subject := getMessage('PON_AUC_WF_PSTART_EVENT_SUB', x_msg_suffix, 'DOC_NUMBER', x_doc_number_dsp, 'AUCTION_TITLE', replaceHtmlChars(p_auction_title), 'EVENT_TITLE', x_event_title);
1356        else -- NOT part of event
1357          x_notif_subject := getMessage('PON_AUC_WF_AUC_PSTART_SUB', x_msg_suffix,'DOC_NUMBER', x_doc_number_dsp,'AUCTION_TITLE', replaceHtmlChars(p_auction_title));
1358        end if;
1359      else -- open mode
1360        if (x_event_title is not null) then -- part of event
1361          x_notif_subject := getMessage('PON_AUC_WF_START_EVENT_SUB', x_msg_suffix, 'DOC_NUMBER', x_doc_number_dsp, 'AUCTION_TITLE', replaceHtmlChars(p_auction_title), 'EVENT_TITLE', x_event_title);
1362        else
1363          x_notif_subject := getMessage('PON_AUC_WF_AUC_START_SUB', x_msg_suffix, 'DOC_NUMBER', x_doc_number_dsp, 'AUCTION_TITLE', replaceHtmlChars(p_auction_title));
1364        end if;
1365      end if;
1366    else -- amendment
1367      if (x_difference > 0 and sysdate < p_open_bidding_date) then -- preview mode
1368        if (x_event_title is not null) then -- part of event
1369          x_notif_subject := getMessage('PON_AUC_AM_PSTART_EVENT_SUB', x_msg_suffix, 'AMENDMENT_NUMBER', x_amendment_number, 'ORIG_NUMBER', x_orig_document_number, 'AUCTION_TITLE', replaceHtmlChars(p_auction_title), 'EVENT_TITLE', x_event_title);
1370        else -- NOT part of event
1371          x_notif_subject := getMessage('PON_AUC_AM_AUC_PSTART_SUB', x_msg_suffix, 'AMENDMENT_NUMBER', x_amendment_number, 'ORIG_NUMBER', x_orig_document_number, 'AUCTION_TITLE', replaceHtmlChars(p_auction_title));
1372        end if;
1373      else -- open mode
1374        if (x_event_title is not null) then -- part of event
1375          x_notif_subject := getMessage('PON_AUC_AM_START_EVENT_SUB', x_msg_suffix, 'AMENDMENT_NUMBER', x_amendment_number, 'ORIG_NUMBER', x_orig_document_number, 'AUCTION_TITLE', replaceHtmlChars(p_auction_title), 'EVENT_TITLE', x_event_title);
1376        else
1377          x_notif_subject := getMessage('PON_AUC_AM_AUC_START_SUB', x_msg_suffix, 'AMENDMENT_NUMBER', x_amendment_number, 'ORIG_NUMBER', x_orig_document_number, 'AUCTION_TITLE', replaceHtmlChars(p_auction_title));
1378        end if;
1379      end if;
1380    end if;
1381 
1382 
1383    wf_engine.SetItemAttrText (itemtype   => x_itemtype,
1384                               itemkey    => x_itemkey,
1385                               aname      => 'AUCTION_STARTED_SUB',
1386                               avalue     => x_notif_subject);
1387 
1388 
1389    UNSET_SESSION_LANGUAGE;
1390 
1391    --
1392    -- Start the workflow
1393    --
1394 
1395    -- Bug 4295915: Set the  workflow owner
1396    wf_engine.SetItemOwner(itemtype => x_itemtype,
1397                           itemkey  => x_itemkey,
1398                           owner    => fnd_global.user_name);
1399 
1400    wf_engine.StartProcess(itemtype => x_itemtype,
1401                           itemkey  => x_itemkey );
1402 
1403 
1404    UPDATE pon_auction_headers_all set
1405           wf_item_key = x_itemkey,
1406           reminder_date = x_reminder_date
1407    WHERE auction_header_id = p_auction_header_id;
1408 
1409    -- Raise Business Event
1410    PON_BIZ_EVENTS_PVT.RAISE_NEG_PUB_EVENT (
1411       p_api_version  => 1.0 ,
1412       p_init_msg_list => FND_API.G_FALSE,
1413       p_commit         => FND_API.G_FALSE,
1414       p_auction_header_id => p_auction_header_id,
1415       x_return_status  => x_return_status,
1416       x_msg_count      => x_msg_count,
1417       x_msg_data        => x_msg_data);
1418 
1419 END;
1420 
1421 PROCEDURE START_BID(    p_bid_id               NUMBER,    --  1
1422       p_auction_header_id    NUMBER,    --  2
1423       p_bid_tp_contact_name    VARCHAR2,  --  3
1424       p_auction_tp_name      VARCHAR2,  --  4
1425          p_auction_open_bidding_date  DATE,    --  5
1426         p_auction_close_bidding_date  DATE,     --  6
1427       p_visibility_code    VARCHAR2,  --  7
1428       p_item_description    VARCHAR2,   --  8
1429       p_old_price      NUMBER,    --  9
1430       p_new_price      NUMBER,    -- 10
1431       p_auction_title      VARCHAR2,  -- 11
1432       p_oex_operation      VARCHAR2,  -- 12
1433       p_oex_operation_url    VARCHAR2) IS  -- 13
1434 
1435 
1436 x_sequence  NUMBER;
1437 x_itemtype  VARCHAR2(7) := 'PONABID';
1438 x_itemkey  VARCHAR2(50);
1439 x_progress  VARCHAR2(3);
1440 x_sealed_flag  VARCHAR2(1) := 'N';
1441 x_winning_bid   VARCHAR2(1) := 'N';
1442 
1443 BEGIN
1444 
1445 
1446     x_progress := '010';
1447 
1448     --
1449     -- Get next value in sequence for itemkey
1450     --
1451     SELECT pon_auction_wf_bid_s.nextval
1452     INTO   x_sequence
1453     FROM   dual;
1454 
1455     x_progress := '020';
1456 
1457 
1458     x_itemkey := (to_char(p_bid_id)||'-'||to_char(x_sequence));
1459 
1460     x_progress := '022';
1461 
1462 
1463     --
1464     -- Create the wf process
1465     --
1466 
1467     wf_engine.CreateProcess(itemtype => x_itemtype,
1468                             itemkey  => x_itemkey,
1469                             process  => 'PON_AUCTION_BID');
1470 
1471     --
1472     -- Set all the item attributes
1473     --
1474 
1475     x_progress := '025';
1476 
1477 
1478     wf_engine.SetItemAttrNumber (itemtype   => x_itemtype,
1479                                  itemkey    => x_itemkey,
1480                                  aname      => 'BID_ID',
1481                                  avalue     => p_bid_id);
1482 
1483     wf_engine.SetItemAttrNumber (itemtype   => x_itemtype,
1484                                   itemkey    => x_itemkey,
1485                                  aname      => 'AUCTION_ID',
1486                                  avalue     => p_auction_header_id);
1487 
1488     wf_engine.SetItemAttrText (itemtype   => x_itemtype,
1489                                itemkey    => x_itemkey,
1490                                aname      => 'AUCTION_TP_NAME',
1491                                avalue     => p_auction_tp_name);
1492 
1493 
1494     wf_engine.SetItemAttrDate (itemtype   => x_itemtype,
1495                                itemkey    => x_itemkey,
1496                                aname      => 'AUCTION_START_DATE',
1497                                avalue     => p_auction_open_bidding_date);
1498 
1499     wf_engine.SetItemAttrDate (itemtype   => x_itemtype,
1500                                itemkey    => x_itemkey,
1501                                aname      => 'AUCTION_END_DATE',
1502                                avalue     => p_auction_close_bidding_date);
1503 
1504 
1505     IF (p_visibility_code = 'SEALED_BIDDING') THEN
1506   x_sealed_flag := 'Y';
1507     END IF;
1508 
1509     wf_engine.SetItemAttrText (itemtype   => x_itemtype,
1510                                itemkey    => x_itemkey,
1511                                aname      => 'SEALED_FLAG',
1512                                avalue     => x_sealed_flag);
1513 
1514     x_progress := '028';
1515 
1516 
1517     wf_engine.SetItemAttrText (itemtype   => x_itemtype,
1518                                 itemkey    => x_itemkey,
1519                                aname      => 'OUTBID_TP_CONTACT_NAME',
1520                          avalue     => p_bid_tp_contact_name);
1521 
1522 
1523 
1524     wf_engine.SetItemAttrText (itemtype   => x_itemtype,
1525                                itemkey    => x_itemkey,
1526                                aname      => 'ITEM_DESCRIPTION',
1527                                avalue     => replaceHtmlChars(p_item_description));
1528 
1529     wf_engine.SetItemAttrNumber (itemtype   => x_itemtype,
1530                                   itemkey    => x_itemkey,
1531                                  aname      => 'OLD_BID',
1532                            avalue     => p_old_price);
1533 
1534     wf_engine.SetItemAttrNumber (itemtype   => x_itemtype,
1535                                   itemkey    => x_itemkey,
1536                                  aname      => 'NEW_BID',
1537                            avalue     => p_new_price);
1538 
1539     wf_engine.SetItemAttrText (itemtype   => x_itemtype,
1540                                itemkey    => x_itemkey,
1541                                aname      => 'AUCTION_TITLE',
1542                                avalue     => replaceHtmlChars(p_auction_title));
1543 /*
1544     wf_engine.SetItemAttrText (itemtype   => x_itemtype,
1545                                itemkey    => x_itemkey,
1546                                aname      => 'OEX_OPERATION',
1547                                avalue     => p_oex_operation);
1548 */
1549     wf_engine.SetItemAttrText (itemtype   => x_itemtype,
1550                                itemkey    => x_itemkey,
1551                                aname      => 'OEX_OPERATION_URL',
1552                                avalue     => p_oex_operation_url);
1553 
1554     -- Bug 4295915: Set the  workflow owner
1555     wf_engine.SetItemOwner(itemtype => x_itemtype,
1556                            itemkey  => x_itemkey,
1557                            owner    => fnd_global.user_name);
1558 
1559     --
1560     -- Start the workflow
1561     --
1562     wf_engine.StartProcess(itemtype => x_itemtype,
1563                            itemkey  => x_itemkey );
1564 
1565     x_progress := '029';
1566 
1567 
1568 END;
1569 
1570 
1571 PROCEDURE DISQUALIFY_BID(p_auction_header_id_encrypted   VARCHAR2,  --  1
1572                          p_bid_id                        NUMBER,  --  2
1573                    p_auction_header_id         NUMBER,    --  3
1574                          p_bid_tp_contact_name           VARCHAR2,  --  4
1575                    p_auction_tp_name               VARCHAR2,  --  5
1576                      p_auction_title               VARCHAR2,  --  6
1577                        p_disqualify_date                DATE,    --  7
1578                    p_disqualify_reason           VARCHAR2  --  8
1579                   ) IS
1580 
1581 
1582 
1583 x_sequence    NUMBER;
1584 x_itemtype    VARCHAR2(8) := 'PONDQBID';
1585 x_itemkey    VARCHAR2(50);
1586 x_bid_list    VARCHAR2(1);
1587 x_progress    VARCHAR2(3);
1588 x_role_name    VARCHAR2(30);
1589 x_sealed_flag    VARCHAR2(1) := 'N';
1590 x_bid_contact_dp_name   VARCHAR2(240);
1591 x_auction_type_name   VARCHAR2(30) := '';
1592 x_auctioneer_tag        VARCHAR2(30);
1593 x_timezone        VARCHAR2(80);
1594 x_new_disqualify_date   DATE;
1595 x_language_code VARCHAR2(3) := null;
1596 x_newstarttime    DATE;
1597 x_newendtime    DATE;
1598 x_startdate    DATE;
1599 x_enddate    DATE;
1600 x_doctype_group_name   VARCHAR2(60);
1601 x_msg_suffix     VARCHAR2(3) := '';
1602 p_doc_number_dsp   PON_AUCTION_HEADERS_ALL.DOCUMENT_NUMBER%TYPE;
1603 p_view_quote_url    VARCHAR2(2000);
1604 x_auction_tp_contact_name PON_AUCTION_HEADERS_ALL.TRADING_PARTNER_CONTACT_NAME%TYPE;
1605 p_bid_name           VARCHAR2(10);
1606 x_bidder_contact_id             NUMBER;
1607 x_auctioneer_contact_id NUMBER;
1608 x_oex_timezone VARCHAR2(80);
1609 x_timezone_disp VARCHAR2(240);
1610 
1611 -- bidder specific time zone related values
1612 x_timezone_bidder VARCHAR2(80);
1613 x_timezone_disp_bidder VARCHAR2(240);
1614 x_newstarttime_bidder    DATE;
1615 x_newendtime_bidder    DATE;
1616 x_new_disqualify_date_bidder   DATE;
1617 
1618 x_newendtime1    VARCHAR2(80);
1619 x_newstarttime1    VARCHAR2(80);
1620 p_view_quote_url_supplier VARCHAR2(2000);
1621 x_tp_display_name PON_BID_HEADERS.TRADING_PARTNER_NAME%TYPE;
1622 x_tp_address_name PON_BID_HEADERS.VENDOR_SITE_CODE%TYPE;
1623 x_auction_tp_name PON_AUCTION_HEADERS_ALL.TRADING_PARTNER_NAME%TYPE;
1624 x_preview_date           DATE;
1625 x_preview_date_in_tz       DATE;
1626 x_timezone1_disp          VARCHAR2(240);
1627 
1628 -- Bisuness Events Related Changes
1629 x_return_status   VARCHAR2(20);
1630 x_msg_count       NUMBER;
1631 x_msg_data         VARCHAR2(2000);
1632 
1633 x_staggered_closing_interval NUMBER;
1634 x_staggered_close_note       VARCHAR2(1000);
1635 
1636 CURSOR c1_bid_info(x_lang VARCHAR2) IS
1637     select ah.document_number, ah.trading_partner_name, dt.doctype_group_name,
1638      nvl(substr(bhz.attribute2,0,3),''),
1639      bhz.person_first_name || ' ' ||  bhz.person_last_name,
1640        bih.trading_partner_name, decode(bih.vendor_site_code, '-1', null, bih.vendor_site_code) vendor_site_code,
1641        ah.view_by_date, ah.staggered_closing_interval
1642     from hz_parties bhz, pon_bid_headers bih, pon_auction_headers_all ah, pon_auc_doctypes dt
1643     where bhz.party_id = bih.trading_partner_contact_id
1644     and   bih.bid_number = p_bid_id
1645     and   ah.auction_header_id = bih.auction_header_id
1646     and   ah.doctype_id = dt.doctype_id;
1647 
1648 BEGIN
1649 
1650 
1651     x_progress := '010';
1652 
1653     --
1654     -- Get the bidder's language code so that the c1_bid_info
1655     -- has right value for x_language_code
1656     --
1657     IF p_bid_tp_contact_name is not null THEN
1658        PON_PROFILE_UTIL_PKG.GET_WF_LANGUAGE(p_bid_tp_contact_name,x_language_code);
1659     END IF;
1660 
1661     -- Set the userenv language so the message token (attribute) values that we retrieve using the
1662     -- getMessage call return the message in the correct language => x_language_code
1663 
1664     IF (FND_LOG.level_statement >= FND_LOG.g_current_runtime_level) THEN --{
1665      FND_LOG.string(log_level => FND_LOG.level_statement,
1666        module => g_module_prefix || 'DISQUALIFY_BID',
1667        message  => '3. Calling SET_SESSION_LANGUAGE with x_language_code : ' || x_language_code);
1668     END IF; --}
1669 
1670     SET_SESSION_LANGUAGE(null, x_language_code);
1671 
1672     --
1673     -- Get next value in sequence for itemkey
1674     --
1675 
1676     SELECT pon_auction_wf_dqbid_s.nextval
1677     INTO   x_sequence
1678     FROM   dual;
1679 
1680         -- lxchen why???
1681     --
1682     -- Get the exchange's time zone
1683     --
1684 
1685   select trading_partner_contact_id
1686   into x_bidder_contact_id
1687   from pon_bid_headers
1688   where bid_number = p_bid_id ;
1689 
1690     x_oex_timezone := Get_Oex_Time_Zone;
1691 
1692     --
1693     -- Get the contact name, bidder's timezone and auction type
1694     --
1695 
1696     open c1_bid_info(x_language_code);
1697     fetch c1_bid_info
1698     into p_doc_number_dsp, x_auction_tp_name, x_doctype_group_name,
1699        x_timezone_bidder, x_bid_contact_dp_name,
1700          x_tp_display_name, x_tp_address_name, x_preview_date,
1701          x_staggered_closing_interval;
1702 
1703 
1704     x_timezone_bidder:= Get_Time_Zone(x_bidder_contact_id);
1705 
1706     x_progress := '020';
1707 
1708     x_itemkey := (to_char(p_bid_id)||'-'||to_char(x_sequence));
1709 
1710     x_progress := '022';
1711 
1712     --
1713     -- Create the wf process
1714     --
1715 
1716     wf_engine.CreateProcess(itemtype => x_itemtype,
1717                             itemkey  => x_itemkey,
1718                             process  => 'PON_DISQUALIFY_BID');
1719 
1720     --
1721     -- Set all the item attributes
1722     --
1723 
1724     x_progress := '025';
1725 
1726     x_msg_suffix := GET_MESSAGE_SUFFIX (x_doctype_group_name);
1727 
1728     wf_engine.SetItemAttrText (itemtype   => x_itemtype,
1729                                  itemkey    => x_itemkey,
1730                                  aname      => 'DOC_NUMBER',
1731                                  avalue     => p_doc_number_dsp);
1732 
1733     wf_engine.SetItemAttrNumber (itemtype   => x_itemtype,
1734                                  itemkey    => x_itemkey,
1735                                  aname      => 'AUCTION_ID',
1736                                  avalue     => p_auction_header_id);
1737 
1738     wf_engine.SetItemAttrText   (itemtype   => x_itemtype,
1739                                  itemkey    => x_itemkey,
1740                                  aname      => 'ORIGIN_USER_NAME',
1741                                  avalue     => fnd_global.user_name);
1742 
1743     -- Item attribute value is going to be used as a parameter to View Quote page
1744     wf_engine.SetItemAttrNumber (itemtype   => x_itemtype,
1745                                  itemkey    => x_itemkey,
1746                                  aname      => 'BID_ID',
1747                                  avalue     => p_bid_id);
1748 
1749     wf_engine.SetItemAttrText (itemtype   => x_itemtype,
1750                                itemkey    => x_itemkey,
1751                                aname      => 'BIDDER_TP_NAME',
1752                                avalue     => x_tp_display_name);
1753 
1754     wf_engine.SetItemAttrText (itemtype   => x_itemtype,
1755                                itemkey    => x_itemkey,
1756                                aname      => 'BIDDER_TP_ADDRESS_NAME',
1757                                avalue     => x_tp_address_name);
1758 
1759     wf_engine.SetItemAttrText (itemtype   => x_itemtype,
1760                                itemkey    => x_itemkey,
1761                                aname      => 'DOC_INTERNAL_NAME',
1762                                avalue     => x_doctype_group_name);
1763 
1764     BEGIN
1765         x_staggered_close_note := NULL;
1766         IF x_staggered_closing_interval IS NOT NULL THEN
1767              x_staggered_close_note := wf_core.newline || wf_core.newline ||
1768                                        getMessage('PON_STAGGERED_CLOSE_NOTIF_MSG') ||
1769                                        wf_core.newline || wf_core.newline;
1770         END IF;
1771         wf_engine.SetItemAttrText( itemtype => x_itemtype,
1772                                    itemkey  => x_itemkey,
1773                                    aname    => 'STAGGERED_CLOSE_NOTE',
1774                                    avalue   => x_staggered_close_note);
1775     EXCEPTION
1776         WHEN OTHERS THEN
1777              NULL;
1778     END;
1779 
1780     BEGIN
1781       wf_engine.SetItemAttrText(itemtype   => x_itemtype,
1782                                 itemkey    => x_itemkey,
1783                                 aname      => '#WFM_HTMLAGENT',
1784                                 avalue     => pon_wf_utl_pkg.get_base_external_supplier_url);
1785     EXCEPTION
1786           WHEN OTHERS THEN
1787         NULL;
1788     END;
1789 
1790     -- Bug 7156205. Get the value for p_bid_name from getMessage instead of hardcoding the message
1791     p_bid_name := getMessage('PON_AUC_BID_L', x_msg_suffix);
1792 
1793      wf_engine.SetItemAttrText (itemtype   => x_itemtype,
1794                                itemkey    => x_itemkey,
1795                                aname      => 'BID',
1796                                avalue     => p_bid_name);
1797 
1798      wf_engine.SetItemAttrText (itemtype   => x_itemtype,
1799                                itemkey    => x_itemkey,
1800                                aname      => 'BIDDER_TP_CONTACT_NAME',
1801                                avalue     => p_bid_tp_contact_name);
1802 
1803 
1804     wf_engine.SetItemAttrText (itemtype   => x_itemtype,
1805                               itemkey    => x_itemkey,
1806                                aname      => 'DISQUALIFY_REASON',
1807                                avalue     => replaceHtmlChars(p_disqualify_reason));
1808     --
1809     -- Get the dates from the auction header table
1810     --
1811 
1812     select open_bidding_date, close_bidding_date, trading_partner_contact_name
1813     into x_startdate, x_enddate, x_auction_tp_contact_name
1814     from pon_auction_headers_all
1815     where auction_header_id = p_auction_header_id;
1816 
1817     wf_engine.SetItemAttrDate (itemtype   => x_itemtype,
1818                                 itemkey    => x_itemkey,
1819                               aname      => 'AUCTION_START_DATE',
1820                               avalue     => x_startdate);
1821 
1822     wf_engine.SetItemAttrDate (itemtype   => x_itemtype,
1823                               itemkey    => x_itemkey,
1824                               aname      => 'AUCTION_END_DATE',
1825                              avalue     => x_enddate);
1826 
1827     wf_engine.SetItemAttrDate (itemtype   => x_itemtype,
1828                                 itemkey    => x_itemkey,
1829                               aname      => 'PREVIEW_DATE',
1830                              avalue     => x_preview_date);
1831 
1832     --
1833     -- Convert the dates to the bidder's timezone.
1834     -- If the timezone is not recognized, just use PST
1835     --
1836 
1837     IF (PON_OEX_TIMEZONE_PKG.VALID_ZONE(x_timezone_bidder) = 1) THEN
1838       x_newstarttime_bidder := PON_OEX_TIMEZONE_PKG.CONVERT_TIME(x_startdate,x_oex_timezone,x_timezone_bidder);
1839        x_newendtime_bidder := PON_OEX_TIMEZONE_PKG.CONVERT_TIME(x_enddate,x_oex_timezone,x_timezone_bidder);
1840        x_new_disqualify_date_bidder := PON_OEX_TIMEZONE_PKG.CONVERT_TIME(p_disqualify_date,x_oex_timezone,x_timezone_bidder);
1841         x_preview_date_in_tz := PON_OEX_TIMEZONE_PKG.CONVERT_TIME(x_preview_date,x_oex_timezone,x_timezone_bidder);
1842     ELSE
1843        x_newstarttime_bidder := x_startdate;
1844        x_newendtime_bidder := x_enddate;
1845        x_new_disqualify_date_bidder := p_disqualify_date;
1846        x_timezone_bidder := x_oex_timezone;
1847         x_preview_date_in_tz := x_preview_date;
1848     END IF;
1849 
1850     wf_engine.SetItemAttrDate (itemtype   => x_itemtype,
1851                                itemkey    => x_itemkey,
1852                                aname      => 'BIDDER_DISQUALIFY_DATE',
1853                                avalue     => x_new_disqualify_date_bidder);
1854 
1855     x_timezone_disp_bidder := Get_TimeZone_Description(x_timezone_bidder, x_language_code);
1856 
1857     wf_engine.SetItemAttrText (itemtype   => x_itemtype,
1858                                itemkey    => x_itemkey,
1859                                aname      => 'TP_TIME_ZONE',
1860                                avalue     => x_timezone_disp_bidder);
1861 
1862     wf_engine.SetItemAttrDate (itemtype   => x_itemtype,
1863                             itemkey    => x_itemkey,
1864                           aname      => 'AUCTION_START_DATE_BIDDER',
1865                           avalue     => x_newstarttime_bidder);
1866 
1867     wf_engine.SetItemAttrDate (itemtype   => x_itemtype,
1868                             itemkey    => x_itemkey,
1869                           aname      => 'AUCTION_END_DATE_BIDDER',
1870                           avalue     => x_newendtime_bidder);
1871 
1872     --
1873     -- Get the role name for this auction and the bid visibilty code
1874     -- to see if other bidders should be notified of this bid disqualification
1875     --
1876 
1877     select wf_role_name, decode(bid_visibility_code,'OPEN_BIDDING','N','SEALED_BIDDING','Y','N')
1878     into x_role_name, x_sealed_flag
1879     from pon_auction_headers_all
1880     where auction_header_id = p_auction_header_id;
1881 
1882     --
1883     -- Set the attributes
1884     --
1885 
1886     wf_engine.SetItemAttrText (itemtype   => x_itemtype,
1887                                 itemkey    => x_itemkey,
1888                                aname      => 'NEW_BIDDER_ROLE',
1889                              avalue     => x_role_name);
1890 
1891     wf_engine.SetItemAttrText (itemtype   => x_itemtype,
1892                                itemkey    => x_itemkey,
1893                                aname      => 'SEALED_FLAG',
1894                                avalue     => x_sealed_flag);
1895 
1896     -- added the contact display name and the auction type ( sellers or buyers)
1897 
1898     wf_engine.SetItemAttrText (itemtype   => x_itemtype,
1899                                itemkey    => x_itemkey,
1900                                aname      => 'BID_CONTACT_DP_NAME',
1901                                avalue     => x_bid_contact_dp_name);
1902 
1903 
1904     IF (x_preview_date_in_tz IS NULL) THEN
1905         x_timezone1_disp := null;
1906 
1907         wf_engine.SetItemAttrDate (itemtype  => x_itemtype,
1908                            itemkey  => x_itemkey,
1909                            aname  => 'PREVIEW_DATE_TZ',
1910                            avalue  => null);
1911 
1912         wf_engine.SetItemAttrText (itemtype  => x_itemtype,
1913                            itemkey  => x_itemkey,
1914                            aname  => 'TP_TIME_ZONE1',
1915                            avalue  => null);
1916 
1917         wf_engine.SetItemAttrText (itemtype  => x_itemtype,
1918                            itemkey  => x_itemkey,
1919                            aname  => 'PREVIEW_DATE_NOTSPECIFIED',
1920                            avalue  => PON_AUCTION_PKG.getMessage('PON_AUC_PREVIEW_DATE_NOTSPEC'));
1921     ELSE
1922         x_timezone1_disp := x_timezone_disp;
1923 
1924         wf_engine.SetItemAttrDate (itemtype  => x_itemtype,
1925                              itemkey  => x_itemkey,
1926                            aname  => 'PREVIEW_DATE_TZ',
1927                            avalue  => x_preview_date_in_tz);
1928 
1929         wf_engine.SetItemAttrText (itemtype  => x_itemtype,
1930                            itemkey  => x_itemkey,
1931                            aname  => 'TP_TIME_ZONE1',
1932                            avalue  => x_timezone1_disp);
1933 
1934         wf_engine.SetItemAttrText (itemtype  => x_itemtype,
1935                            itemkey  => x_itemkey,
1936                            aname  => 'PREVIEW_DATE_NOTSPECIFIED',
1937                            avalue  => null);
1938     END IF;
1939 
1940 
1941 
1942 
1943      -- call to notification utility package to set the message header common attributes and #from_role
1944     pon_wf_utl_pkg.set_hdr_attributes (p_itemtype        => x_itemtype
1945                                   ,p_itemkey        => x_itemkey
1946                                       ,p_auction_tp_name  => x_auction_tp_name
1947                                     ,p_auction_title    => p_auction_title
1948                                     ,p_document_number  => p_doc_number_dsp
1949                                       ,p_auction_tp_contact_name => x_auction_tp_contact_name
1950                                       );
1951 
1952     -- call to notification utility package to get the redirect page url that
1953     -- is responsible for getting the View Quote url and forward to it.
1954        p_view_quote_url := pon_wf_utl_pkg.get_dest_page_url (
1955                               p_dest_func => 'PONRESENQ_VIEWBID'
1956                                  ,p_notif_performer  => 'SUPPLIER');
1957 
1958     wf_engine.SetItemAttrText (itemtype   => x_itemtype,
1959                                itemkey    => x_itemkey,
1960                                aname      => 'VIEW_QUOTE_URL',
1961                                avalue     => p_view_quote_url);
1962 
1963 
1964 
1965        x_newstarttime1 := to_char(x_newstarttime_bidder,'Month dd, yyyy hh:mi am');
1966        x_newendtime1   := to_char(x_newendtime_bidder,'Month dd, yyyy hh:mi am');
1967 
1968 
1969 
1970 
1971 --- 000001
1972     wf_engine.SetItemAttrText ( itemtype => x_itemtype,
1973                                 itemkey   => x_itemkey,
1974                                 aname     => 'PON_WF_AUC_DSQBID_SUB',
1975                                 avalue     => getMessage('PON_WF_AUC_DSQBID_SUB', x_msg_suffix,
1976                                                 'BID_ID', p_bid_id,
1977                                                'DOC_NUMBER', p_doc_number_dsp,
1978                                                'AUCTION_TITLE', replaceHtmlChars(p_auction_title)));
1979 
1980 
1981 
1982     UNSET_SESSION_LANGUAGE;
1983 
1984     x_progress := '027';
1985 
1986     -- Bug 4295915: Set the  workflow owner
1987     wf_engine.SetItemOwner(itemtype => x_itemtype,
1988                            itemkey  => x_itemkey,
1989                            owner    => fnd_global.user_name);
1990 
1991     --
1992     -- Start the workflow
1993     --
1994 
1995     wf_engine.StartProcess(itemtype => x_itemtype,
1996                            itemkey  => x_itemkey );
1997 
1998     x_progress := '029';
1999 
2000     -- Raise Business Event
2001     PON_BIZ_EVENTS_PVT.RAISE_RESPNSE_DISQ_EVENT (
2002       p_api_version  => 1.0 ,
2003       p_init_msg_list => FND_API.G_FALSE,
2004       p_commit         => FND_API.G_FALSE,
2005       p_bid_number => p_bid_id,
2006       x_return_status  => x_return_status,
2007       x_msg_count      => x_msg_count,
2008       x_msg_data        => x_msg_data);
2009 
2010 END;
2011 
2012 
2013 PROCEDURE RETRACT_BID(   p_bid_id               NUMBER,    --  1
2014        p_auction_header_id    NUMBER,    --  2
2015        p_bid_tp_contact_name    VARCHAR2,  --  3
2016        p_bid_tp_contact_id    NUMBER,    --  4
2017        p_auction_tp_contact_name    VARCHAR2,  --  5
2018           p_auction_tp_contact_id  NUMBER,    --  6
2019           p_auction_open_bidding_date  DATE,    --  7
2020          p_auction_close_bidding_date  DATE,     --  8
2021        p_oex_operation_url    VARCHAR2) IS  -- 9
2022 
2023 x_sequence  NUMBER;
2024 x_itemtype  VARCHAR2(7) := 'PONBCAN';
2025 x_itemkey  VARCHAR2(50);
2026 x_bid_list  VARCHAR2(1);
2027 x_progress  VARCHAR2(3);
2028 
2029 BEGIN
2030 
2031 
2032     x_progress := '010';
2033 
2034 
2035     --
2036     -- Get next value in sequence for itemkey
2037     --
2038     SELECT pon_auction_wf_rtbid_s.nextval
2039     INTO   x_sequence
2040     FROM   dual;
2041 
2042     x_progress := '020';
2043 
2044 
2045     x_itemkey := (to_char(p_bid_id)||'-'||to_char(x_sequence));
2046 
2047     x_progress := '022';
2048 
2049 
2050     --
2051     -- Create the wf process
2052     --
2053 
2054     wf_engine.CreateProcess(itemtype => x_itemtype,
2055                             itemkey  => x_itemkey,
2056                             process  => 'PON_BID_CANCEL');
2057 
2058     --
2059     -- Set all the item attributes
2060     --
2061 
2062     x_progress := '025';
2063 
2064 
2065     wf_engine.SetItemAttrNumber (itemtype   => x_itemtype,
2066                                itemkey    => x_itemkey,
2067                                aname      => 'AUCTION_ID',
2068                                avalue     => p_auction_header_id);
2069 
2070 
2071     wf_engine.SetItemAttrNumber (itemtype   => x_itemtype,
2072                                itemkey    => x_itemkey,
2073                                aname      => 'BID_ID',
2074                                avalue     => p_bid_id);
2075 
2076     wf_engine.SetItemAttrText (itemtype   => x_itemtype,
2077                                itemkey    => x_itemkey,
2078                                aname      => 'PREPARER_TP_CONTACT_NAME',
2079                                avalue     => p_auction_tp_contact_name);
2080 
2081     wf_engine.SetItemAttrNumber (itemtype   => x_itemtype,
2082                                itemkey    => x_itemkey,
2083                                aname      => 'PREPARER_TP_CONTACT_ID',
2084                                avalue     => p_auction_tp_contact_id);
2085 
2086     wf_engine.SetItemAttrText (itemtype   => x_itemtype,
2087                                itemkey    => x_itemkey,
2088                                aname      => 'ORIGIN_USER_NAME',
2089                                avalue     => fnd_global.user_name);
2090     x_progress := '026';
2091 
2092 
2093     wf_engine.SetItemAttrText (itemtype   => x_itemtype,
2094                                itemkey    => x_itemkey,
2095                                aname      => 'BIDDER_TP_CONTACT_NAME',
2096                                avalue     => p_bid_tp_contact_name);
2097 
2098     wf_engine.SetItemAttrNumber (itemtype   => x_itemtype,
2099                                itemkey    => x_itemkey,
2100                                aname      => 'BIDDER_TP_CONTACT_ID',
2101                                avalue     => p_bid_tp_contact_id);
2102 
2103 
2104     wf_engine.SetItemAttrDate (itemtype   => x_itemtype,
2105                                itemkey    => x_itemkey,
2106                                aname      => 'AUCTION_START_DATE',
2107                                avalue     => p_auction_open_bidding_date);
2108 
2109     wf_engine.SetItemAttrDate (itemtype   => x_itemtype,
2110                                itemkey    => x_itemkey,
2111                                aname      => 'AUCTION_END_DATE',
2112                                avalue     => p_auction_close_bidding_date);
2113 
2114 
2115 --    wf_engine.SetItemAttrText (itemtype   => x_itemtype,
2116 --                               itemkey    => x_itemkey,
2117 --                               aname      => 'OEX_OPERATION',
2118 --                               avalue     => p_oex_operation);
2119 
2120     wf_engine.SetItemAttrText (itemtype   => x_itemtype,
2121                                itemkey    => x_itemkey,
2122                                aname      => 'OEX_OPERATION_URL',
2123                                avalue     => 'p_oex_operation_url');
2124     x_progress := '027';
2125 
2126 
2127     -- Bug 4295915: Set the  workflow owner
2128     wf_engine.SetItemOwner(itemtype => x_itemtype,
2129                            itemkey  => x_itemkey,
2130                            owner    => fnd_global.user_name);
2131 
2132     --
2133     -- Start the workflow
2134     --
2135     wf_engine.StartProcess(itemtype => x_itemtype,
2136                            itemkey  => x_itemkey );
2137 
2138     x_progress := '029';
2139 
2140 END;
2141 
2142 
2143 PROCEDURE AWARD_BID(p_bid_id                      NUMBER,    --  1
2144                 p_auction_header_id           NUMBER,    --  2
2145                 p_bid_tp_contact_name         VARCHAR2,  --  3
2146                 p_auction_tp_name            VARCHAR2,  --  4
2147                 p_auction_title               VARCHAR2,  --  5
2148                 p_auction_header_id_encrypted  VARCHAR2    --  6
2149                 ) IS
2150 
2151 
2152 
2153 x_number_awarded  NUMBER;
2154 x_number_rejected  NUMBER;
2155 x_sequence  NUMBER;
2156 x_itemtype  VARCHAR2(8) := 'PONAWARD';
2157 x_itemkey  VARCHAR2(50);
2158 x_bid_list  VARCHAR2(1);
2159 x_progress  VARCHAR2(3);
2160 x_bid_contact_tp_dp_name varchar2(240);
2161 x_auction_type varchar2(30);
2162 x_auction_type_name varchar2(30) := '';
2163 x_event_title       varchar2(80);
2164 x_event_id          NUMBER;
2165 x_auction_open_bidding_date DATE;
2166 x_auction_close_bidding_date DATE;
2167 x_language_code VARCHAR2(3) := null;
2168 x_timezone  VARCHAR2(80);
2169 x_newstarttime  DATE;
2170 x_newendtime  DATE;
2171 x_newawardtime  DATE;
2172 x_doctype_group_name   VARCHAR2(60);
2173 x_msg_suffix     VARCHAR2(3) := '';
2174 x_doc_number_dsp    PON_AUCTION_HEADERS_ALL.DOCUMENT_NUMBER%TYPE;
2175 x_auction_round_number    NUMBER;
2176 x_doctype_id_value    NUMBER;
2177 x_oex_timezone VARCHAR2(80);
2178 x_bidder_contact_id   NUMBER;
2179 x_timezone_disp VARCHAR2(240);
2180 x_bid           VARCHAR2(10);
2181 x_bid_caps      VARCHAR2(10);
2182 x_note_to_supplier PON_BID_HEADERS.NOTE_TO_SUPPLIER%TYPE;
2183 x_view_quote_url_supplier VARCHAR2(2000);
2184 x_award_date PON_AUCTION_HEADERS_ALL.AWARD_DATE%TYPE;
2185 x_trading_partner_contact_name PON_AUCTION_HEADERS_ALL.TRADING_PARTNER_CONTACT_NAME%TYPE;
2186 x_tp_display_name PON_BID_HEADERS.TRADING_PARTNER_NAME%TYPE;
2187 x_tp_address_name PON_BID_HEADERS.VENDOR_SITE_CODE%TYPE;
2188 x_preview_date             DATE;
2189 x_preview_date_in_tz             DATE;
2190 x_timezone1_disp                VARCHAR2(240);
2191 x_has_items_flag                PON_AUCTION_HEADERS_ALL.HAS_ITEMS_FLAG%TYPE;
2192 x_staggered_closing_interval    NUMBER;
2193 x_staggered_close_note          VARCHAR2(1000);
2194 x_bid_award_status PON_BID_HEADERS.AWARD_STATUS%TYPE;
2195 
2196 CURSOR c1_bid_info(x_lang VARCHAR2) IS
2197     select bid_type, nvl(ah.auction_round_number, 1) auction_round_number, bih.note_to_supplier,
2198      ah.document_number, dt.doctype_group_name, dt.doctype_id,
2199      bhz.person_first_name || ' ' ||  bhz.person_last_name, ah.trading_partner_contact_name,
2200        bih.trading_partner_name, decode(bih.vendor_site_code, '-1', null, bih.vendor_site_code) vendor_site_code,
2201        view_by_date, nvl(ah.has_items_flag, 'Y'), ah.staggered_closing_interval,bih.award_status
2202     from hz_parties bhz, pon_bid_headers bih, pon_auction_headers_all ah, pon_auc_doctypes dt
2203     where bhz.party_id = bih.trading_partner_contact_id
2204     and   bih.bid_number = p_bid_id
2205     and   ah.auction_header_id = bih.auction_header_id
2206     and   ah.doctype_id = dt.doctype_id;
2207 
2208 BEGIN
2209 
2210 
2211     x_progress := '010';
2212 
2213     --
2214     -- Get the bidder's language code so that the c1_bid_info
2215     -- has right value for x_language_code
2216     --
2217     IF p_bid_tp_contact_name is not null THEN
2218        PON_PROFILE_UTIL_PKG.GET_WF_LANGUAGE(p_bid_tp_contact_name,x_language_code);
2219     END IF;
2220 
2221     -- Set the userenv language so the message token (attribute) values that we retrieve using the
2222     -- getMessage call return the message in the correct language => x_language_code
2223     IF (FND_LOG.level_statement >= FND_LOG.g_current_runtime_level) THEN --{
2224      FND_LOG.string(log_level => FND_LOG.level_statement,
2225        module => g_module_prefix || 'AWARD_BID',
2226        message  => '4. Calling SET_SESSION_LANGUAGE with x_language_code : ' || x_language_code);
2227     END IF; --}
2228 
2229     SET_SESSION_LANGUAGE(null, x_language_code);
2230 
2231     --
2232     -- Get next value in sequence for itemkey
2233     --
2234 
2235     SELECT pon_auction_wf_acbid_s.nextval
2236     INTO   x_sequence
2237     FROM   dual;
2238 
2239     --
2240     -- get the contact name and auction type
2241     --
2242 
2243     open c1_bid_info(x_language_code);
2244     fetch c1_bid_info
2245     into x_auction_type, x_auction_round_number, x_note_to_supplier, x_doc_number_dsp,
2246    x_doctype_group_name, x_doctype_id_value,
2247    x_bid_contact_tp_dp_name, x_trading_partner_contact_name, x_tp_display_name,
2248          x_tp_address_name, x_preview_date, x_has_items_flag, x_staggered_closing_interval,x_bid_award_status;
2249 
2250  -- bug 6020309 : Get rejection note if any at the line level, if the buyer has
2251  -- not specified rejection note at the bid level. Though the buyer enters a
2252  -- single note in case of rejecting all the bids, the note is stored at the line level.
2253      if (x_bid_award_status ='REJECTED' and x_note_to_supplier is null ) then
2254        begin
2255           select reason
2256           into x_note_to_supplier
2257           FROM pon_acceptances
2258           WHERE auction_header_id = p_auction_header_id
2259           and bid_number = p_bid_id
2260           AND ACCEPTANCE_TYPE = 'REJECTED'
2261           AND rownum = 1;
2262        exception
2263       when others then null;
2264      end;
2265      end if;
2266 
2267 
2268     IF (x_doctype_group_name = 'BUYER_AUCTION') THEN
2269       x_bid := 'bid';
2270         x_bid_caps := 'Bid';
2271     ELSIF (x_doctype_group_name = 'REQUEST_FOR_QUOTE') THEN
2272       x_bid := 'quote';
2273         x_bid_caps := 'Quote';
2274     ELSIF (x_doctype_group_name = 'REQUEST_FOR_INFORMATION') THEN
2275         x_bid := 'response';
2276         x_bid_caps := 'Response';
2277     END IF;
2278 
2279     x_progress := '020';
2280 
2281     x_msg_suffix := GET_MESSAGE_SUFFIX (x_doctype_group_name);
2282 
2283     x_itemkey := (to_char(p_bid_id)||'-'||to_char(x_sequence));
2284 
2285     x_progress := '022';
2286 
2287     --
2288     -- Create the wf process
2289     --
2290 
2291     wf_engine.CreateProcess(itemtype => x_itemtype,
2292                             itemkey  => x_itemkey,
2293                             process  => 'PON_AWARD_BID');
2294 
2295     --
2296     -- Set all the item attributes
2297     --
2298 
2299     wf_engine.SetItemAttrText   (itemtype   => x_itemtype,
2300                                  itemkey    => x_itemkey,
2301                                  aname      => 'DOC_NUMBER',
2302                                  avalue     => x_doc_number_dsp);
2303 
2304 
2305     -- call to notification utility package to get the redirect page url that
2306     -- is responsible for getting the View Quote url and forward to it.
2307   x_view_quote_url_supplier := pon_wf_utl_pkg.get_dest_page_url (
2308                               p_dest_func => 'PONRESENQ_VIEWBID'
2309                                  ,p_notif_performer  => 'SUPPLIER');
2310 
2311     wf_engine.SetItemAttrText (itemtype   => x_itemtype,
2312                                itemkey    => x_itemkey,
2313                                aname      => 'VIEW_QUOTE_URL',
2314                                avalue     => x_view_quote_url_supplier);
2315 
2316     wf_engine.SetItemAttrText (itemtype   => x_itemtype,
2317                                itemkey    => x_itemkey,
2318                                aname      => 'BIDDER_TP_NAME',
2319                                avalue     => x_tp_display_name);
2320 
2321     wf_engine.SetItemAttrText (itemtype   => x_itemtype,
2322                                itemkey    => x_itemkey,
2323                                aname      => 'HAS_ITEMS_FLAG',
2324                                avalue     => x_has_items_flag);
2325 
2326     wf_engine.SetItemAttrText (itemtype   => x_itemtype,
2327                                itemkey    => x_itemkey,
2328                                aname      => 'BIDDER_TP_ADDRESS_NAME',
2329                                avalue     => x_tp_address_name);
2330 
2331     BEGIN
2332         x_staggered_close_note := NULL;
2333         IF x_staggered_closing_interval IS NOT NULL THEN
2334              x_staggered_close_note := wf_core.newline || wf_core.newline ||
2335                                        getMessage('PON_STAGGERED_CLOSE_NOTIF_MSG') ||
2336                                        wf_core.newline || wf_core.newline;
2337         END IF;
2338         wf_engine.SetItemAttrText( itemtype => x_itemtype,
2339                                    itemkey  => x_itemkey,
2340                                    aname    => 'STAGGERED_CLOSE_NOTE',
2341                                    avalue   => x_staggered_close_note);
2342     EXCEPTION
2343         WHEN OTHERS THEN
2344               NULL;
2345     END;
2346 
2347     BEGIN
2348       wf_engine.SetItemAttrText(itemtype   => x_itemtype,
2349                                 itemkey    => x_itemkey,
2350                                 aname      => '#WFM_HTMLAGENT',
2351                                 avalue     => pon_wf_utl_pkg.get_base_external_supplier_url);
2352     EXCEPTION
2353           WHEN OTHERS THEN
2354         NULL;
2355     END;
2356 
2357     x_progress := '025';
2358 
2359 -- FPK: CPA Setting number of items awarded or rejected only when negotiation has lines.
2360 IF x_has_items_flag  = 'Y' THEN
2361 
2362     /* set these variables to a default zero */
2363     x_number_awarded  := 0;
2364     x_number_rejected := 0;
2365 
2366 
2367     select   count(pbip.line_number)
2368     into   x_number_awarded
2369     from   pon_bid_item_prices pbip,
2370     pon_auction_item_prices_all paip
2371     where   paip.auction_header_id   = p_auction_header_id
2372     and    paip.line_number   = pbip.line_number
2373     and    pbip.bid_number    = p_bid_id
2374     and    nvl(pbip.award_status,'NONE')= 'AWARDED'
2375     and    paip.group_type in ('LINE', 'LOT', 'GROUP_LINE');
2376 
2377     select   count(pbip.line_number)
2378     into   x_number_rejected
2379     from   pon_bid_item_prices pbip,
2380     pon_auction_item_prices_all paip
2381     where   paip.auction_header_id   = p_auction_header_id
2382     and    paip.line_number   = pbip.line_number
2383     and    pbip.bid_number    = p_bid_id
2384     and    nvl(pbip.award_status,'NONE')= 'REJECTED'
2385     and    paip.group_type in ('LINE', 'LOT', 'GROUP_LINE');
2386 
2387     wf_engine.SetItemAttrNumber (itemtype   => x_itemtype,
2388                                  itemkey    => x_itemkey,
2389                                  aname      => 'NUMBER_AWARDED',
2390                                  avalue     => x_number_awarded);
2391 
2392     wf_engine.SetItemAttrNumber (itemtype   => x_itemtype,
2393                                  itemkey    => x_itemkey,
2394                                  aname      => 'NUMBER_REJECTED',
2395                                  avalue     => x_number_rejected);
2396 END IF;
2397 
2398 
2399     wf_engine.SetItemAttrNumber (itemtype   => x_itemtype,
2400                                  itemkey    => x_itemkey,
2401                                  aname      => 'AUCTION_ID',
2402                                  avalue     => p_auction_header_id);
2403 
2404     -- Item attribute value is going to be used as a parameter to View Quote page
2405     wf_engine.SetItemAttrNumber (itemtype   => x_itemtype,
2406                                  itemkey    => x_itemkey,
2407                                  aname      => 'BID_ID',
2408                                  avalue     => p_bid_id);
2409 
2410     wf_engine.SetItemAttrText (itemtype   => x_itemtype,
2411                                itemkey    => x_itemkey,
2412                                aname      => 'BIDDER_TP_CONTACT_NAME',
2413                                avalue     => p_bid_tp_contact_name);
2414 
2415     wf_engine.SetItemAttrText (itemtype   => x_itemtype,
2416                                itemkey    => x_itemkey,
2417                                aname      => 'ORIGIN_USER_NAME',
2418                                avalue     => fnd_global.user_name);
2419 
2420      wf_engine.SetItemAttrText (itemtype   => x_itemtype,
2421                                itemkey    => x_itemkey,
2422                                aname      => 'BID',
2423                                avalue     => x_bid);
2424 
2425      wf_engine.SetItemAttrText (itemtype   => x_itemtype,
2426                                itemkey    => x_itemkey,
2427                                aname      => 'BID_CAPS',
2428                                avalue     => x_bid_caps);
2429 
2430      wf_engine.SetItemAttrText (itemtype   => x_itemtype,
2431                                itemkey    => x_itemkey,
2432                                aname      => 'NOTE_TO_SUPPLIER',
2433                                avalue     => x_note_to_supplier);
2434 
2435 -- added the contact display name and the auction type ( sellers or buyers)
2436 
2437     wf_engine.SetItemAttrText (itemtype   => x_itemtype,
2438                                itemkey    => x_itemkey,
2439                                aname      => 'BID_CONTACT_TP_DP_NAME',
2440                          avalue     => x_bid_contact_tp_dp_name);
2441 
2442     wf_engine.SetItemAttrText (itemtype   => x_itemtype,
2443                                itemkey    => x_itemkey,
2444                                aname      => 'AUCTION_TYPE_NAME',
2445                                avalue     => x_auction_type_name);
2446 
2447     select open_bidding_date, close_bidding_date, award_date, event_id
2448     into x_auction_open_bidding_date, x_auction_close_bidding_date, x_award_date, x_event_id
2449     from pon_auction_headers_all
2450     where auction_header_id = p_auction_header_id;
2451 
2452     wf_engine.SetItemAttrDate (itemtype   => x_itemtype,
2453                                itemkey    => x_itemkey,
2454                                aname      => 'AWARD_DATE',
2455                                avalue     => x_award_date);
2456 
2457     if (x_event_id is not null) then
2458         x_event_title := getEventTitle (p_auction_header_id);
2459       wf_engine.SetItemAttrText (itemtype   => x_itemtype,
2460                              itemkey    => x_itemkey,
2461                              aname      => 'EVENT_TITLE',
2462                              avalue     => replaceHtmlChars(x_event_title));
2463     end if;
2464 
2465     --
2466     -- Get the exchange's time zone
2467     --
2468 
2469                 x_oex_timezone := Get_Oex_Time_Zone;
2470 
2471 
2472   select trading_partner_contact_id
2473   into x_bidder_contact_id
2474   from pon_bid_headers
2475   where bid_number = p_bid_id;
2476 
2477   begin
2478   x_timezone := Get_Time_Zone(x_bidder_contact_id);
2479    EXCEPTION
2480   WHEN OTHERS THEN
2481     x_timezone := x_oex_timezone;
2482         END;
2483 
2484 
2485     --
2486     -- Convert the dates to the user's timezone.
2487     -- If the timezone is not recognized, just use the default
2488     --
2489 
2490     IF (PON_OEX_TIMEZONE_PKG.VALID_ZONE(x_timezone) = 1) THEN
2491       x_newstarttime := PON_OEX_TIMEZONE_PKG.CONVERT_TIME(x_auction_open_bidding_date,x_oex_timezone,x_timezone);
2492        x_newendtime := PON_OEX_TIMEZONE_PKG.CONVERT_TIME(x_auction_close_bidding_date,x_oex_timezone,x_timezone);
2493         x_newawardtime := PON_OEX_TIMEZONE_PKG.CONVERT_TIME(x_award_date,x_oex_timezone,x_timezone);
2494         x_preview_date_in_tz := PON_OEX_TIMEZONE_PKG.CONVERT_TIME(x_preview_date,x_oex_timezone,x_timezone);
2495     ELSE
2496       x_newstarttime := x_auction_open_bidding_date;
2497       x_newendtime := x_auction_close_bidding_date;
2498         x_newawardtime := x_award_date;
2499       x_timezone := x_oex_timezone;
2500         x_preview_date_in_tz := x_preview_date;
2501     END IF;
2502 
2503     --
2504     -- Set the dates based on the user's time zone
2505     --
2506 
2507    x_timezone_disp := Get_TimeZone_Description(x_timezone, x_language_code);
2508 
2509 
2510     wf_engine.SetItemAttrText (itemtype  => x_itemtype,
2511              itemkey  => x_itemkey,
2512              aname  => 'TP_TIME_ZONE_AUCTION',
2513              avalue  => x_timezone_disp);
2514 
2515     wf_engine.SetItemAttrDate (itemtype   => x_itemtype,
2516                                  itemkey    => x_itemkey,
2517                                aname      => 'AUCTION_START_DATE_TZ',
2518                                avalue     => x_newstarttime);
2519 
2520     wf_engine.SetItemAttrDate (itemtype   => x_itemtype,
2521                                  itemkey    => x_itemkey,
2522                                aname      => 'AUCTION_END_DATE_TZ',
2523                                avalue     => x_newendtime);
2524 
2525     wf_engine.SetItemAttrDate (itemtype     => x_itemtype,
2526                                  itemkey    => x_itemkey,
2527                                aname      => 'AWARD_DATE_TZ',
2528                                avalue     => x_newawardtime);
2529 
2530   IF (x_preview_date_in_tz IS NULL) THEN
2531 
2532      x_timezone1_disp := null;
2533 
2534      wf_engine.SetItemAttrDate (itemtype  => x_itemtype,
2535                         itemkey  => x_itemkey,
2536                         aname  => 'PREVIEW_DATE_TZ',
2537                         avalue  => null);
2538 
2539      wf_engine.SetItemAttrText (itemtype  => x_itemtype,
2540                         itemkey  => x_itemkey,
2541                         aname  => 'TP_TIME_ZONE1',
2542                         avalue  => null);
2543 
2544      wf_engine.SetItemAttrText (itemtype  => x_itemtype,
2545                          itemkey  => x_itemkey,
2546                          aname  => 'PREVIEW_DATE_NOTSPECIFIED',
2547                          avalue  => PON_AUCTION_PKG.getMessage('PON_AUC_PREVIEW_DATE_NOTSPEC'));
2548  ELSE
2549      x_timezone1_disp := x_timezone_disp;
2550 
2551      wf_engine.SetItemAttrDate (itemtype  => x_itemtype,
2552                         itemkey  => x_itemkey,
2553                         aname  => 'PREVIEW_DATE_TZ',
2554                         avalue  => x_preview_date_in_tz);
2555 
2556      wf_engine.SetItemAttrText (itemtype  => x_itemtype,
2557                         itemkey  => x_itemkey,
2558                         aname  => 'TP_TIME_ZONE1',
2559                         avalue  => x_timezone1_disp);
2560 
2561        wf_engine.SetItemAttrText (itemtype  => x_itemtype,
2562                           itemkey  => x_itemkey,
2563                           aname  => 'PREVIEW_DATE_NOTSPECIFIED',
2564                           avalue  => null);
2565  END IF;
2566 
2567     x_progress := '027';
2568 
2569     -- call to notification utility package to set the message header common attributes and #from_role
2570     pon_wf_utl_pkg.set_hdr_attributes (p_itemtype               => x_itemtype
2571                                   ,p_itemkey               => x_itemkey
2572                                       ,p_auction_tp_name         => p_auction_tp_name
2573                                     ,p_auction_title           => p_auction_title
2574                                     ,p_document_number         => x_doc_number_dsp
2575                                       ,p_auction_tp_contact_name => x_trading_partner_contact_name
2576                                       );
2577 
2578 
2579      if (x_event_title is not null) then
2580 
2581         wf_engine.SetItemAttrText (itemtype   => x_itemtype,
2582                                    itemkey    => x_itemkey,
2583                                    aname      => 'PON_AUC_WF_AWARD_SUBJECT',
2584                                    avalue     => getMessage('PON_AUC_WF_AWARD_EVENT_SUB', x_msg_suffix,
2585                     'DOC_NUMBER', x_doc_number_dsp,
2586                     'AUCTION_TITLE', replaceHtmlChars(p_auction_title),
2587                                   'EVENT_TITLE', x_event_title));
2588 
2589     else
2590 
2591        wf_engine.SetItemAttrText (itemtype   => x_itemtype,
2592                                   itemkey    => x_itemkey,
2593                                   aname      => 'PON_AUC_WF_AWARD_SUBJECT',
2594                                   avalue     => getMessage('PON_AUC_WF_AWARD_SUBJECT', x_msg_suffix,
2595                    'DOC_NUMBER', x_doc_number_dsp,
2596                    'AUCTION_TITLE', replaceHtmlChars(p_auction_title)));
2597 
2598    end if;
2599 
2600     UNSET_SESSION_LANGUAGE;
2601 
2602     -- Bug 4295915: Set the  workflow owner
2603     wf_engine.SetItemOwner(itemtype => x_itemtype,
2604                            itemkey  => x_itemkey,
2605                            owner    => fnd_global.user_name);
2606 
2607     --
2608     -- Start the workflow
2609     --
2610 
2611     wf_engine.StartProcess(itemtype => x_itemtype,
2612                            itemkey  => x_itemkey );
2613 
2614     x_progress := '029';
2615 
2616 END;
2617 
2618 PROCEDURE UNREGISTERED_BIDDERS(  itemtype    in varchar2,
2619            itemkey    in varchar2,
2620                        actid           in number,
2621                        uncmode    in varchar2,
2622                        resultout       out NOCOPY varchar2) IS
2623 
2624 x_flag   VARCHAR2(1);
2625 BEGIN
2626 
2627     x_flag := wf_engine.GetItemAttrText (itemtype => itemtype,
2628                                          itemkey  => itemkey,
2629                                          aname    => 'NEW_BIDDERS_FLAG');
2630 
2631 
2632     IF (x_flag = 'Y') THEN
2633   resultout := 'Y';
2634     ELSE
2635   resultout := 'N';
2636 
2637     END IF;
2638 
2639 END;
2640 
2641 PROCEDURE BIDDERS_LIST(  itemtype    in varchar2,
2642            itemkey    in varchar2,
2643                        actid           in number,
2644                        uncmode    in varchar2,
2645                        resultout       out NOCOPY varchar2) IS
2646 
2647 x_flag   VARCHAR2(1);
2648 BEGIN
2649 
2650     x_flag := wf_engine.GetItemAttrText (itemtype => itemtype,
2651                                          itemkey  => itemkey,
2652                                          aname    => 'BIDDER_LIST_FLAG');
2653 
2654 
2655     IF (x_flag = 'Y') THEN
2656   resultout := 'Y';
2657     ELSE
2658   resultout := 'N';
2659 
2660     END IF;
2661 
2662 END;
2663 
2664 
2665 PROCEDURE COMPLETE_PREV_ROUND_WF(  p_itemtype            in varchar2,
2666            p_itemkey             in varchar2,
2667            actid                 in number,
2668            uncmode               in varchar2,
2669            resultout             out NOCOPY varchar2) IS
2670   x_doc_header_id number;
2671   x_itemkey varchar2(240);
2672 BEGIN
2673 
2674     x_doc_header_id := wf_engine.GetItemAttrNumber (itemtype => p_itemtype,
2675                                              itemkey  => p_itemkey,
2676                                              aname    => 'AUCTION_ID');
2677 
2678     begin
2679       select wf_item_key into x_itemkey
2680   from pon_auction_headers_all
2681   where auction_header_id = (select auction_header_id_prev_round
2682            from pon_auction_headers_all where auction_header_id = x_doc_header_id);
2683 
2684   wf_engine.completeActivity('PONAUCT', x_itemkey, 'WAIT_FOR_AUCTION_COMPLETE', 'PREPARER_COMPLETE');
2685 
2686     exception
2687   when others then
2688   null;
2689     end;
2690 END;
2691 
2692 
2693 PROCEDURE COMPLETE_PREV_DOC_WF(  p_itemtype            in varchar2,
2694                                  p_itemkey             in varchar2,
2695                                  actid                 in number,
2696                                  uncmode               in varchar2,
2697                                  resultout             out NOCOPY varchar2) IS
2698         x_doc_header_id number;
2699         x_prev_doc_header_id number;
2700         x_prev_doc_amendment_number number;
2701         x_itemtype                VARCHAR2(7) := 'PONAUCT';
2702         x_itemkey varchar2(240);
2703         x_current_activity        VARCHAR2(30);
2704 BEGIN
2705 
2706     x_doc_header_id := wf_engine.GetItemAttrNumber (itemtype => p_itemtype,
2707                                                   itemkey  => p_itemkey,
2708                                                   aname    => 'AUCTION_ID');
2709 
2710     begin
2711 
2712         select auction_header_id_prev_amend
2713         into   x_prev_doc_header_id
2714         from pon_auction_headers_all
2715         where auction_header_id = x_doc_header_id;
2716 
2717         select wf_item_key, nvl(amendment_number, 0)
2718         into x_itemkey, x_prev_doc_amendment_number
2719         from pon_auction_headers_all
2720         where auction_header_id = x_prev_doc_header_id;
2721 
2722         -- need to complete first round supplier notifications (might be waiting on ack response)
2723         if (x_prev_doc_amendment_number = 0) then
2724           complete_prev_suppl_notifs(x_prev_doc_header_id);
2725         end if;
2726 
2727         --
2728         -- First, see what activity (if any) the workflow is on
2729         -- If none, then return.  Workflow has already completed??
2730         --
2731         BEGIN
2732            select activity_label
2733            into x_current_activity
2734            from wf_item_activity_statuses_v
2735            where item_type = x_itemtype
2736            AND item_key = x_itemkey
2737            and activity_status_code = 'NOTIFIED';
2738         EXCEPTION WHEN no_data_found THEN
2739            RETURN;
2740         END;
2741 
2742         wf_engine.CompleteActivity(x_itemtype,x_itemkey,x_current_activity,'PREPARER_COMPLETE');
2743 
2744     exception
2745         when others then
2746         null;
2747     end;
2748 END;
2749 
2750 PROCEDURE COMPLETE_PREV_SUPPL_NOTIFS(p_prev_doc_header_id IN NUMBER) IS
2751 
2752 x_itemtype         varchar2(8) := 'PONPBLSH';
2753 x_itemkey          varchar2(240);
2754 x_current_activity varchar2(30);
2755 
2756 CURSOR bidder_list_wf_keys IS
2757     select pbp.wf_item_key wf_item_key, act.activity_label activity_label
2758     from   pon_bidding_parties pbp,
2759            wf_item_activity_statuses_v act
2760     where  pbp.auction_header_id = p_prev_doc_header_id and
2761            act.item_type = x_itemtype and
2762            act.item_key = pbp.wf_item_key and
2763            act.activity_status_code = 'NOTIFIED';
2764 BEGIN
2765 
2766   FOR item_key IN bidder_list_wf_keys LOOP
2767 
2768 
2769      x_itemkey := item_key.wf_item_key;
2770      x_current_activity := item_key.activity_label;
2771 
2772      wf_engine.CompleteActivity(x_itemtype,x_itemkey,x_current_activity,'PREPARER_COMPLETE');
2773 
2774   END LOOP;
2775 
2776 END;
2777 
2778 PROCEDURE SEND_BIDDERS_NOTIFICATION(itemtype                      in varchar2,
2779                                     itemkey                       in varchar2,
2780                                     actid                         in number,
2781                                     p_action_code                 in varchar2,
2782                                     p_user                        in varchar2,
2783                                     p_bidder_tp_name              in varchar2,
2784                                     p_vendor_site_code            in varchar2,
2785                                     p_vendor_site_id              in number,
2786                                     p_message_name                in varchar2,
2787                                     p_doc_number_dsp              in varchar2,
2788                                     p_auction_title               in varchar2,
2789                                     p_auction_start_date          in date,
2790                                     p_auction_end_date            in date,
2791                                     p_preview_date                in date,
2792                                     p_language_code               in varchar2,
2793                                     p_timezone                    in varchar2,
2794                                     p_change_type                 in number,
2795                                     p_original_close_bidding_date in date,
2796                                     p_event_title                 in varchar2,
2797                                     p_auc_tp_contact_name         in varchar2,
2798                                     p_staggered_closing_interval  in number)
2799 IS
2800 
2801    x_auction_header_id_encrypted  varchar2(2000);
2802    x_neg_summary_url_supplier VARCHAR2(2000);
2803    x_nid number;
2804 
2805    x_msg_suffix varchar2(3) := '';
2806    x_tp_time_zone_auction varchar2(30);
2807    x_oex_timezone varchar2(80);
2808    x_timezone     varchar2(80);
2809    x_new_auction_start_date date;
2810    x_new_auction_end_date date;
2811 
2812    x_close_early_subject varchar2(200);
2813    x_close_early_reason  varchar2(2000);
2814    x_close_early_no_reason varchar2(2000);
2815    x_close_early_at varchar2(200);
2816 
2817    x_close_changed_message varchar2(2000);
2818    x_close_changed_subject varchar2(200);
2819    x_close_changed_reason varchar2(2000);
2820    x_close_changed_no_reason varchar2(2000);
2821 
2822    x_status                VARCHAR2(10);
2823    x_exception_msg         VARCHAR2(100);
2824    x_person_party_id       NUMBER;
2825 
2826    x_new_supplier_name     VARCHAR2(240) := '';
2827    x_additional_invitee_flag BOOLEAN;
2828    x_deleted_contact_flag    BOOLEAN;
2829    x_count       NUMBER;
2830 
2831    x_listed_company_user   VARCHAR2(240) := '';
2832    x_timezone_disp VARCHAR2(240);
2833 
2834    x_close_early_date  DATE;
2835    x_close_date_changed DATE;
2836    x_new_close_early_date date;
2837    x_new_close_changed_date date;
2838    x_new_auction_preview_date DATE;
2839    x_timezone1_disp  VARCHAR2(240);
2840 
2841    x_cancel_reason PON_ACTION_HISTORY.ACTION_NOTE%TYPE := '';
2842    x_cancel_date          DATE;
2843    x_new_cancel_date      DATE;
2844    x_new_disqualify_date  DATE;
2845    x_disqualify_reason varchar2(2000) := '';
2846    x_bid_number number;
2847    x_disqualify_date date;
2848    x_bid_name      VARCHAR2(10);
2849    x_staggered_close_note   VARCHAR2(1000);
2850 
2851    l_origin_user_name    fnd_user.user_name%TYPE;
2852 
2853 begin
2854 
2855     if (p_action_code = 'CANCEL') then
2856 
2857         x_cancel_reason := wf_engine.GetItemAttrText(itemtype => itemtype,
2858                                            itemkey  => itemkey,
2859                                          aname    => 'CANCEL_REASON');
2860 
2861         x_cancel_date := wf_engine.GetItemAttrDate(itemtype => itemtype,
2862                                            itemkey  => itemkey,
2863                                          aname    => 'CANCEL_DATE');
2864 
2865     elsif (p_action_code = 'DISQUALIFY_BID') then
2866 
2867         x_disqualify_reason := wf_engine.GetItemAttrText(itemtype => itemtype,
2868                                                        itemkey  => itemkey,
2869                                                        aname    => 'DISQUALIFY_REASON');
2870 
2871         x_bid_number := wf_engine.GetItemAttrNumber (itemtype => itemtype,
2872                                                      itemkey  => itemkey,
2873                                                      aname    => 'BID_ID');
2874 
2875 
2876         x_disqualify_date := wf_engine.GetItemAttrDate (itemtype => itemtype,
2877                                                         itemkey  => itemkey,
2878                                                         aname    => 'BIDDER_DISQUALIFY_DATE');
2879 
2880         x_bid_name := wf_engine.GetItemAttrText (itemtype => itemtype,
2881                                                  itemkey  => itemkey,
2882                                                aname    => 'BID');
2883 
2884     end if;
2885 
2886 
2887       l_origin_user_name := wf_engine.GetItemAttrText (itemtype => itemtype,
2888                                                        itemkey  => itemkey,
2889                                                  aname    => 'ORIGIN_USER_NAME');
2890 
2891       x_msg_suffix := GET_MESSAGE_SUFFIX (wf_engine.GetItemAttrText (itemtype  => itemtype,
2892                                                                      itemkey   => itemkey,
2893                                                                      aname      => 'DOC_INTERNAL_NAME'));
2894 
2895       UNSET_SESSION_LANGUAGE;
2896 
2897       x_nid := WF_NOTIFICATION.send(role      => p_user ,
2898                                     context   => itemtype||':'||itemkey||':'||actid,
2899                                     msg_type  => itemtype,
2900                                     msg_name  => p_message_name);
2901 
2902       IF (p_language_code is not null) THEN
2903 
2904          IF (FND_LOG.level_statement >= FND_LOG.g_current_runtime_level) THEN --{
2905          FND_LOG.string(log_level => FND_LOG.level_statement,
2906            module => g_module_prefix || 'SEND_BIDDERS_NOTIFICATION',
2907            message  => '5. Calling SET_SESSION_LANGUAGE with x_language_code : ' || p_language_code);
2908          END IF; --}
2909          SET_SESSION_LANGUAGE(null, p_language_code);
2910       END IF;
2911 
2912       -- Set the staggered closing attribute
2913       x_staggered_close_note := NULL;
2914       IF p_staggered_closing_interval IS NOT NULL THEN
2915            x_staggered_close_note := wf_core.newline || wf_core.newline ||
2916                                      getMessage('PON_STAGGERED_CLOSE_NOTIF_MSG') ||
2917                                      wf_core.newline || wf_core.newline;
2918       END IF;
2919       wf_Notification.setAttrText(x_nid, 'STAGGERED_CLOSE_NOTE', x_staggered_close_note);
2920 
2921       BEGIN
2922         wf_Notification.setAttrText(x_nid,'#WFM_HTMLAGENT', pon_wf_utl_pkg.get_base_external_supplier_url);
2923       EXCEPTION
2924             WHEN OTHERS THEN
2925           NULL;
2926       END;
2927 
2928       if (p_action_code = 'CLOSEEARLY') then
2929 
2930         x_close_early_date := p_auction_end_date;
2931         x_close_early_subject := getMessage('PON_AUC_CLOSE_WF_1', x_msg_suffix,
2932                                             'DOC_NUMBER', p_doc_number_dsp,
2933                                             'AUCTION_TITLE', replaceHtmlChars(p_auction_title));
2934 
2935       elsif (p_action_code = 'CLOSECHANGED') then
2936 
2937        x_close_date_changed := p_auction_end_date;
2938 
2939        x_auction_header_id_encrypted := wf_engine.GetItemAttrText (itemtype => itemtype,
2940                                                                    itemkey  => itemkey,
2941                                                                    aname    => 'AUCTION_ID_ENCRYPTED');
2942 
2943      -- call to notification utility package to get the redirect page url that
2944      -- is responsible for getting the Negotiation Summary url and forward to it.
2945         x_neg_summary_url_supplier := pon_wf_utl_pkg.get_dest_page_url (
2946                                   p_dest_func => 'PON_NEG_SUMMARY'
2947                                      ,p_notif_performer  => 'SUPPLIER');
2948 
2949        -- auctioneer extends the auction
2950         if (p_change_type = 1) then
2951 
2952            x_close_changed_subject := getMessage('PON_AUC_EXTEND_WF_1', x_msg_suffix,
2953                                                  'DOC_NUMBER', p_doc_number_dsp,
2954                                                  'AUCTION_TITLE', replaceHtmlChars(p_auction_title));
2955 
2956         -- auctioneer shortens the auction
2957         else
2958            x_close_changed_subject := getMessage('PON_AUC_SHORTEN_WF_1', x_msg_suffix,
2959                                                  'DOC_NUMBER', p_doc_number_dsp,
2960                                                  'AUCTION_TITLE', replaceHtmlChars(p_auction_title));
2961         end if;
2962      end if;
2963 
2964       x_oex_timezone := Get_Oex_Time_Zone;
2965       x_timezone     := p_timezone;
2966 
2967       IF (PON_OEX_TIMEZONE_PKG.VALID_ZONE(x_timezone) = 1) THEN
2968           x_new_auction_start_date := PON_OEX_TIMEZONE_PKG.CONVERT_TIME(p_auction_start_date,x_oex_timezone,x_timezone);
2969           x_new_auction_preview_date := PON_OEX_TIMEZONE_PKG.CONVERT_TIME(p_preview_date,x_oex_timezone,x_timezone);
2970 
2971           if (p_action_code = 'CLOSEEARLY' or p_action_code = 'CLOSECHANGED') then
2972               x_new_auction_end_date := PON_OEX_TIMEZONE_PKG.CONVERT_TIME  (p_original_close_bidding_date,x_oex_timezone,x_timezone);
2973           else
2974              x_new_auction_end_date := PON_OEX_TIMEZONE_PKG.CONVERT_TIME(p_auction_end_date,x_oex_timezone,x_timezone);
2975          end if;
2976 
2977           if (p_action_code = 'CLOSEEARLY') then
2978               x_new_close_early_date := PON_OEX_TIMEZONE_PKG.CONVERT_TIME(x_close_early_date,x_oex_timezone,x_timezone);
2979               x_new_close_changed_date := PON_OEX_TIMEZONE_PKG.CONVERT_TIME(x_close_date_changed,x_oex_timezone,x_timezone);
2980           elsif (p_action_code = 'CLOSECHANGED') then
2981                  x_new_close_changed_date := PON_OEX_TIMEZONE_PKG.CONVERT_TIME(x_close_date_changed,x_oex_timezone,x_timezone);
2982           elsif (p_action_code = 'CANCEL') then
2983                  x_new_cancel_date := PON_OEX_TIMEZONE_PKG.CONVERT_TIME(x_cancel_date,x_oex_timezone,x_timezone);
2984           end if;
2985       ELSE
2986           x_new_auction_start_date := p_auction_start_date;
2987         x_new_auction_end_date := p_original_close_bidding_date;
2988           x_new_auction_preview_date := p_preview_date;
2989           if (p_action_code = 'CLOSEEARLY') then
2990              x_new_close_early_date := x_close_early_date;
2991           elsif (p_action_code = 'CLOSECHANGED') then
2992              x_new_close_changed_date := x_close_date_changed;
2993         end if;
2994         x_timezone := x_oex_timezone;
2995       END IF;
2996 
2997     x_timezone_disp := Get_TimeZone_Description(x_timezone, p_language_code);
2998       IF x_new_auction_preview_date IS NOT NULL THEN
2999          x_timezone1_disp := x_timezone_disp;
3000       ELSE
3001          x_timezone1_disp := null;
3002       END IF;
3003 
3004       -- Setup common attributes
3005       wf_Notification.setAttrDate(x_nid, 'AUCTION_START_DATE', x_new_auction_start_date);
3006       wf_Notification.setAttrDate(x_nid, 'AUCTION_END_DATE', x_new_auction_end_date);
3007       wf_Notification.SetAttrDate(x_nid, 'PREVIEW_DATE', x_new_auction_preview_date);
3008       wf_Notification.SetAttrText(x_nid, 'TP_TIME_ZONE1', x_timezone1_disp);
3009       wf_Notification.setAttrText(x_nid, '#HDR_NEG_TITLE', p_auction_title);
3010       wf_Notification.setAttrText(x_nid, '#HDR_NEG_NUMBER', p_doc_number_dsp);
3011       wf_Notification.setAttrText(x_nid, '#HDR_NEG_TP_NAME', wf_engine.GetItemAttrText (itemtype  => itemtype,
3012                                                                                         itemkey   => itemkey,
3013                                                                                         aname     =>'PREPARER_TP_NAME'));
3014 
3015       wf_Notification.setAttrText(x_nid, '#FROM_ROLE', l_origin_user_name);
3016 
3017       IF (x_new_auction_preview_date is null) THEN
3018             wf_Notification.SetAttrText(x_nid, 'PREVIEW_DATE_NOTSPECIFIED', PON_AUCTION_PKG.getMessage('PON_AUC_PREVIEW_DATE_NOTSPEC'));
3019 
3020       ELSE
3021             wf_Notification.SetAttrText(x_nid, 'PREVIEW_DATE_NOTSPECIFIED', wf_engine.GetItemAttrText (itemtype => itemtype,
3022                                                                                                  itemkey  => itemkey,
3023                                                                                                  aname    => 'PREVIEW_DATE_NOTSPECIFIED'));
3024       END IF;
3025 
3026       if (p_action_code <> 'DISQUALIFY_BID') then
3027           wf_Notification.setAttrText(x_nid, 'BIDDER_TP_NAME', p_bidder_tp_name);
3028           wf_Notification.setAttrText(x_nid, 'BIDDER_TP_ADDRESS_NAME', p_vendor_site_code);
3029       end if;
3030 
3031       IF (p_action_code is not null and p_action_code = 'CLOSEEARLY') THEN
3032 
3033           wf_Notification.setAttrText(x_nid, 'TP_TIME_ZONE_AUCTION', x_timezone_disp);
3034           wf_Notification.SetAttrText(x_nid, 'AUCTION_CLOSE_EARLY_SUB', x_close_early_subject);
3035           wf_Notification.SetAttrDate(x_nid, 'AUCTION_CLOSE_EARLY_DATE', x_new_close_early_date);
3036           wf_Notification.SetAttrText(x_nid, 'CLOSECHANGED_REASON', wf_engine.GetItemAttrText (itemtype => itemtype,
3037                                                                                                itemkey  => itemkey,
3038                                                                                                aname => 'CLOSECHANGED_REASON'));
3039       ELSIF (p_action_code = 'CLOSECHANGED') then
3040 
3041           wf_Notification.setAttrText(x_nid, 'TP_TIME_ZONE_AUCTION', x_timezone_disp);
3042           wf_Notification.SetAttrText(x_nid, 'CLOSE_DATE_CHANGED_SUBJECT', x_close_changed_subject);
3043           wf_Notification.SetAttrDate(x_nid, 'CLOSE_DATE_CHANGED', x_new_close_changed_date);
3044           wf_Notification.SetAttrText(x_nid, 'NEG_SUMMARY_URL_SUPPLIER', x_neg_summary_url_supplier);
3045           wf_Notification.SetAttrNumber(x_nid, 'VENDOR_SITE_ID', p_vendor_site_id);
3046 
3047           IF p_change_type <> 1  THEN --i.e if it is 'NEGOTIATION_SHORTENED'
3048             wf_Notification.SetAttrText(x_nid, 'CLOSECHANGED_REASON', wf_engine.GetItemAttrText (itemtype => itemtype,
3049                                                                                                itemkey  => itemkey,
3050                                                                                                aname => 'CLOSECHANGED_REASON'));
3051           END IF;
3052 
3053       ELSIF (p_action_code = 'CANCEL') THEN
3054 
3055             wf_Notification.SetAttrText(x_nid, 'TP_TIME_ZONE',x_timezone_disp);
3056             wf_Notification.SetAttrDate(x_nid, 'CANCEL_DATE', x_new_cancel_date);
3057 
3058            IF (p_event_title is not null) THEN
3059                     wf_Notification.SetAttrText(x_nid, 'EVENT_TITLE', p_event_title);
3060                     wf_Notification.SetAttrText(x_nid, 'AUCTION_CANCELED_SUB',
3061                                                 getMessage('PON_AUC_WF_CANCEL_EVENT_SUB', x_msg_suffix,
3062                                        'DOC_NUMBER', p_doc_number_dsp,
3063                                      'AUCTION_TITLE', p_auction_title,
3064                                                  'EVENT_TITLE', p_event_title));
3065             ELSE
3066                     wf_Notification.SetAttrText(x_nid, 'AUCTION_CANCELED_SUB',
3067                                                 getMessage('PON_AUC_WF_AUC_CANCEL_SUB', x_msg_suffix,
3068                                                    'DOC_NUMBER', p_doc_number_dsp,
3069                                                'AUCTION_TITLE', p_auction_title));
3070             END IF;
3071 
3072           IF (empty_reason(x_cancel_reason) = 'N') then
3073               wf_Notification.SetAttrText(x_nid, 'CANCEL_REASON', x_cancel_reason);
3074           END IF;
3075 
3076        ELSIF (p_action_code = 'DISQUALIFY_BID') then
3077 
3078             wf_Notification.SetAttrText(x_nid, 'TP_TIME_ZONE', x_timezone_disp);
3079 
3080             -- convert the disqualify date to user's timezone
3081         x_new_disqualify_date :=  PON_OEX_TIMEZONE_PKG.CONVERT_TIME(x_disqualify_date,x_oex_timezone,x_timezone);
3082 
3083         wf_Notification.SetAttrDate(x_nid, 'DISQUALIFY_DATE', x_new_disqualify_date);
3084             wf_Notification.SetAttrText(x_nid, 'BID', x_bid_name);
3085           wf_Notification.SetAttrText ( x_nid, 'PON_WF_AUC_DSQ_OTH_SUB',
3086                                           getMessage('PON_WF_AUC_DSQ_OTH_SUB', x_msg_suffix,
3087                                             'DOC_NUMBER', p_doc_number_dsp,
3088                                            'AUCTION_TITLE', p_auction_title));
3089      END IF;
3090 
3091 END;
3092 
3093 
3094 PROCEDURE NEW_ROUND_BIDDERS_NOT_INVITED(p_itemtype    in varchar2, -- {
3095                                  p_itemkey    in varchar2,
3096                                      actid           in number,
3097                                      uncmode        in varchar2,
3098                                      resultout       out NOCOPY varchar2) IS
3099 
3100 -- Bug 3824928: Added outer join to get previous invited bidder that does
3101 -- not have a contact specified and did not place a bid or previous
3102 -- invited bidder that has a contact specified and did not place a bid.
3103 --
3104 -- This cursor now returns all the previous round bidders to send this notifn.
3105 CURSOR c_prev_round_bidders (x_doc_header_id_prev_round NUMBER, x_role_name VARCHAR2)
3106 IS
3107 -- First pick all the invited suppliers from bidding parties table.
3108 
3109 --
3110 -- First sql of the cursor can have multiple fnd_user entries for a given trading
3111 -- partner contact id and thus it has virtually no way to remove the rows with
3112 -- duplicate TPC Ids. We are assuming that only one fnd_user will be alive after
3113 -- a party merge
3114 --
3115 SELECT fu.user_name user_name,
3116        trading_partner_id   party_id,
3117        trading_partner_name party_name,
3118        DECODE(vendor_site_code, '-1', NULL, vendor_site_code) vendor_site_code,
3119        vendor_site_id
3120 FROM   pon_bidding_parties pbp,
3121      fnd_user fu
3122 WHERE  auction_header_id = x_doc_header_id_prev_round
3123 AND    fu.person_party_id = pbp.trading_partner_contact_id
3124 AND    nvl(fu.end_date, sysdate+1) > sysdate
3125 UNION
3126 -- Then pick all the additional contacts from bidding parties table.
3127 SELECT DISTINCT(wlur.user_name)  user_name,
3128        pbp.trading_partner_id   party_id,
3129        pbp.trading_partner_name party_name,
3130        DECODE(pbp.vendor_site_code, '-1', NULL, pbp.vendor_site_code) vendor_site_code,
3131        pbp.vendor_site_id
3132 FROM   pon_bidding_parties pbp,
3133      wf_local_user_roles wlur
3134 WHERE  pbp.auction_header_id = x_doc_header_id_prev_round
3135 AND    wlur.role_name = x_role_name
3136 AND    wlur.user_name = pbp.wf_user_name
3137 AND pbp.trading_partner_id is not null --leave out requested suppliers
3138 UNION
3139 -- Then pick all the suppliers who have bid.
3140 -- The responses for negotiation may or may not be invited.
3141 SELECT DISTINCT(wlur.user_name)  user_name,
3142        pbh.trading_partner_id    party_id,
3143      pbh.trading_partner_name  party_name,
3144        DECODE(pbh.vendor_site_code, '-1', NULL, pbh.vendor_site_code) vendor_site_code,
3145        pbh.vendor_site_id
3146 FROM   wf_local_user_roles wlur,
3147        pon_bid_headers pbh
3148 WHERE  wlur.role_name = x_role_name
3149 AND    x_doc_header_id_prev_round  = pbh.auction_header_id
3150 AND    wlur.user_name = pbh.trading_partner_contact_name(+);
3151 
3152 CURSOR c2_inv_list (x_doc_header_id NUMBER) IS
3153     select trading_partner_id,vendor_site_id
3154     from   pon_bidding_parties pbp
3155     where  auction_header_id = x_doc_header_id;
3156 
3157 x_itemtype                 VARCHAR2(20) := 'PONPBLSH';
3158 x_itemkey                 VARCHAR2(60);
3159 x_process_name              VARCHAR2(30) := 'NEW_ROUND_NOT_INVITED_BIDDERS';
3160 x_flag                    VARCHAR2(1);
3161 x_doc_header_id            NUMBER;
3162 x_doc_header_id_prev_round NUMBER;
3163 x_bidder_found             BOOLEAN;
3164 x_member                 BOOLEAN;
3165 x_new_member               BOOLEAN;
3166 x_user_name              VARCHAR2(100);
3167 x_bidder_name              VARCHAR2(440);
3168 x_contact_id               NUMBER;
3169 x_language_code            VARCHAR2(60);
3170 x_doctype_group_name       VARCHAR2(80);
3171 x_app                      VARCHAR2(20);
3172 x_msg_suffix            VARCHAR2(3) := '';
3173 x_progress               VARCHAR2(3);
3174 x_sequence             NUMBER;
3175 
3176 x_role_name              VARCHAR2(240);
3177 x_trading_partner_id     NUMBER;
3178 l_vendor_site_id        NUMBER;
3179 x_invitation_id           NUMBER;
3180 
3181 x_oex_header              VARCHAR2(2000);
3182 x_oex_footer              VARCHAR2(2000);
3183 x_status                  VARCHAR2(10);
3184 x_exception_msg           VARCHAR2(100);
3185 x_prev_supplier_name      VARCHAR2(240);
3186 x_prev_supplier_site_code PO_VENDOR_SITES_ALL.VENDOR_SITE_CODE%TYPE;
3187 x_prev_supplier_site_id   PO_VENDOR_SITES_ALL.VENDOR_SITE_ID%TYPE;
3188 x_prev_trading_partner_id NUMBER;
3189 x_bidder_username         VARCHAR2(60);
3190 x_oex_operation           VARCHAR2(640);
3191 x_auction_title           VARCHAR2(640);
3192 x_auction_owner_tp_name   VARCHAR2(640);
3193 x_tp_display_name         VARCHAR2(640);
3194 x_auction_contact_id      NUMBER;
3195 x_person_party_id         NUMBER;
3196 x_language             VARCHAR2(60) := null;
3197 x_territory_code          VARCHAR2(30) := 'AMERICA';
3198 x_doc_number_dsp          PON_AUCTION_HEADERS_ALL.DOCUMENT_NUMBER%TYPE;
3199 x_startdate               DATE;
3200 x_enddate                 DATE;
3201 x_auctioneer_user_name    PON_AUCTION_HEADERS_ALL.TRADING_PARTNER_CONTACT_NAME%TYPE;
3202 x_add_contact_email       PON_BIDDING_PARTIES.ADDITIONAL_CONTACT_EMAIL%TYPE;
3203 x_preview_date       DATE;
3204 x_preview_date_notspec    VARCHAR2(240);
3205 x_timezone1_disp          VARCHAR2(240);
3206 x_newstarttime            DATE;
3207 x_newendtime              DATE;
3208 x_newpreviewtime          DATE;
3209 x_oex_timezone          VARCHAR2(80);
3210 x_timezone    VARCHAR2(80);
3211 x_timezone_disp VARCHAR2(240);
3212 x_staggered_closing_interval NUMBER;
3213 x_staggered_close_note   VARCHAR2(1000);
3214 
3215 l_origin_user_name       fnd_user.user_name%TYPE;
3216 
3217 BEGIN
3218 
3219     x_doc_header_id := wf_engine.GetItemAttrNumber (itemtype => p_itemtype,
3220                                              itemkey  => p_itemkey,
3221                                              aname    => 'AUCTION_ID');
3222 
3223     l_origin_user_name := wf_engine.GetItemAttrText (itemtype => p_itemtype,
3224                                                 itemkey  => p_itemkey,
3225                                                 aname    => 'ORIGIN_USER_NAME');
3226 
3227     x_doctype_group_name := wf_engine.GetItemAttrText (itemtype => p_itemtype,
3228                                                        itemkey  => p_itemkey,
3229                                                       aname    => 'DOC_INTERNAL_NAME');
3230 
3231     x_startdate := wf_engine.GetItemAttrDate (itemtype => p_itemtype,
3232                                       itemkey  => p_itemkey,
3233                                     aname    => 'AUCTION_START_DATE');
3234 
3235   x_enddate   := wf_engine.GetItemAttrDate (itemtype => p_itemtype,
3236                                     itemkey  => p_itemkey,
3237                                     aname    => 'AUCTION_END_DATE');
3238 
3239 --    x_auctioneer_user_name := wf_engine.GetItemAttrText (itemtype => p_itemtype,
3240 --                                                     itemkey  => p_itemkey,
3241 --                                                       aname    => 'PREPARER_TP_CONTACT_NAME');
3242 
3243     x_preview_date := wf_engine.GetItemAttrDate (itemtype   => p_itemtype,
3244                                                  itemkey    => p_itemkey,
3245                                                  aname      => 'PREVIEW_DATE');
3246 
3247     select auction_header_id_prev_round, trading_partner_contact_name,
3248            staggered_closing_interval
3249     into x_doc_header_id_prev_round, x_auctioneer_user_name,
3250          x_staggered_closing_interval
3251     from pon_auction_headers_all where auction_header_id = x_doc_header_id;
3252 
3253     select wf_role_name
3254     into x_role_name
3255     from pon_auction_headers_all
3256     where auction_header_id = x_doc_header_id_prev_round;
3257 
3258     FOR prevBidder IN c_prev_round_bidders(x_doc_header_id_prev_round, x_role_name) LOOP
3259 
3260   x_bidder_found := false;
3261   x_prev_supplier_name := prevBidder.party_name;
3262     x_prev_supplier_site_code := prevBidder.vendor_site_code;
3263     x_prev_supplier_site_id := prevBidder.vendor_site_id;
3264   x_prev_trading_partner_id := prevBidder.party_id;
3265 
3266   open c2_inv_list(x_doc_header_id);
3267   LOOP
3268 
3269       fetch c2_inv_list into  x_trading_partner_id, l_vendor_site_id;
3270 
3271       if c2_inv_list%NOTFOUND then
3272     exit;
3273       end if;
3274 
3275         -- Check if the combination of Trading-Partner-Id and Vendor-Site-Id
3276         -- are not existing in the current round.
3277     if (x_prev_trading_partner_id = x_trading_partner_id AND
3278             x_prev_supplier_site_id = l_vendor_site_id  ) then
3279       x_bidder_found := true;
3280       exit;
3281     end if;
3282 
3283       END LOOP;
3284 
3285   if (NOT x_bidder_found) then
3286 
3287       -- this bidder has not been invited to the new round
3288       -- Get next value in sequence for itemkey
3289 
3290       SELECT pon_auction_wf_publish_s.nextval
3291       INTO   x_sequence
3292       FROM   dual;
3293 
3294       x_itemkey := (p_itemkey||'-'||to_char(x_sequence));
3295 
3296       wf_engine.CreateProcess(itemtype => x_itemtype,
3297                               itemkey  => x_itemkey,
3298                               process  => x_process_name);
3299 
3300       --
3301       -- Set all the item attributes
3302       --
3303 
3304         wf_engine.SetItemAttrDate   (itemtype   => x_itemtype,
3305                                    itemkey    => x_itemkey,
3306                                    aname      => 'AUCTION_START_DATE',
3307                                    avalue     => x_startdate);
3308 
3309         wf_engine.SetItemAttrDate   (itemtype   => x_itemtype,
3310                                    itemkey    => x_itemkey,
3311                                    aname      => 'AUCTION_END_DATE',
3312                                    avalue     => x_enddate);
3313 
3314         wf_engine.SetItemAttrDate   (itemtype   => x_itemtype,
3315                                    itemkey    => x_itemkey,
3316                                    aname      => 'PREVIEW_DATE',
3317                                    avalue     => x_preview_date);
3318 
3319         wf_engine.SetItemAttrText   (itemtype   => x_itemtype,
3320                                    itemkey    => x_itemkey,
3321                                    aname      => 'PREPARER_TP_CONTACT_NAME',
3322                                    avalue     => x_auctioneer_user_name);
3323 
3324         wf_engine.SetItemAttrText (itemtype   => x_itemtype,
3325                                    itemkey    => x_itemkey,
3326                                    aname      => 'BIDDER_TP_NAME',
3327                                    avalue     => x_prev_supplier_name);
3328 
3329         wf_engine.SetItemAttrText (itemtype   => x_itemtype,
3330                                    itemkey    => x_itemkey,
3331                                    aname      => 'BIDDER_TP_ADDRESS_NAME',
3332                                    avalue     => x_prev_supplier_site_code);
3333 
3334         wf_engine.SetItemAttrText (itemtype   => x_itemtype,
3335                              itemkey    => x_itemkey,
3336                              aname      => 'ORIGIN_USER_NAME',
3337                              avalue     => l_origin_user_name);
3338 
3339 
3340       wf_engine.SetItemAttrNumber (itemtype   => x_itemtype,
3341                                    itemkey    => x_itemkey,
3342                                    aname      => 'AUCTION_ID',
3343                                    avalue     => x_doc_header_id); /* using auction_id instead of
3344                                                                        auction_number as a standard
3345                                                                        across item types */
3346 
3347         x_doc_number_dsp := wf_engine.GetItemAttrText (itemtype => p_itemtype,
3348                                                  itemkey  => p_itemkey,
3349                                                  aname    => 'DOC_NUMBER');
3350 
3351       wf_engine.SetItemAttrText (itemtype   => x_itemtype,
3352                                  itemkey    => x_itemkey,
3353                                  aname      => 'DOC_NUMBER',
3354                                  avalue     => x_doc_number_dsp);
3355 
3356       x_auction_title := wf_engine.GetItemAttrText (itemtype => p_itemtype,
3357                                         itemkey  => p_itemkey,
3358                                         aname    => 'AUCTION_TITLE');
3359 
3360 
3361       wf_engine.SetItemAttrText (itemtype   => x_itemtype,
3362                                  itemkey    => x_itemkey,
3363                                  aname      => 'AUCTION_TITLE',
3364                                  avalue     => replaceHtmlChars(x_auction_title));
3365 
3366       x_auction_owner_tp_name := wf_engine.GetItemAttrText (itemtype => p_itemtype,
3367                                           itemkey  => p_itemkey,
3368                                           aname    => 'PREPARER_TP_NAME');
3369 
3370       wf_engine.SetItemAttrText (itemtype   => x_itemtype,
3371                                  itemkey    => x_itemkey,
3372                                  aname      => 'PREPARER_TP_NAME',
3373                                  avalue     => x_auction_owner_tp_name);
3374 
3375       wf_engine.SetItemAttrText (itemtype   => x_itemtype,
3376                                itemkey    => x_itemkey,
3377                                aname      => 'DOC_INTERNAL_NAME',
3378                                avalue     => wf_engine.GetItemAttrText (itemtype => p_itemtype,
3379                                                                           itemkey  => p_itemkey,
3380                                                                           aname    => 'DOC_INTERNAL_NAME'));
3381 
3382 
3383             BEGIN
3384                  x_staggered_close_note := NULL;
3385                  IF x_staggered_closing_interval IS NOT NULL THEN
3386                       x_staggered_close_note := wf_core.newline || wf_core.newline ||
3387                                                 getMessage('PON_STAGGERED_CLOSE_NOTIF_MSG') ||
3388                                                 wf_core.newline || wf_core.newline;
3389                  END IF;
3390                  wf_engine.SetItemAttrText( itemtype => x_itemtype,
3391                                             itemkey  => x_itemkey,
3392                                             aname    => 'STAGGERED_CLOSE_NOTE',
3393                                             avalue   => x_staggered_close_note);
3394             EXCEPTION
3395                  WHEN OTHERS THEN
3396                         NULL;
3397             END;
3398 
3399             begin
3400 
3401               wf_engine.SetItemAttrText   (itemtype   => x_itemtype,
3402                                                itemkey    => x_itemkey,
3403                                                aname      => '#WFM_HTMLAGENT',
3404                                                avalue     => pon_wf_utl_pkg.get_base_external_supplier_url);
3405             exception when others then
3406               null;
3407             end;
3408 
3409         -- Use the language of the user to send the notification.
3410 
3411         x_bidder_username := prevBidder.user_name;
3412 
3413         wf_engine.SetItemAttrText (itemtype   => x_itemtype,
3414                                  itemkey    => x_itemkey,
3415                                  aname      => 'BIDDER_TP_CONTACT_NAME',
3416                                  avalue     => x_bidder_username);
3417 
3418 
3419         IF x_bidder_username is not null THEN
3420          PON_PROFILE_UTIL_PKG.GET_WF_LANGUAGE(x_bidder_username,x_language_code);
3421       END IF;
3422 
3423         -- Bug 3824928 Added code below
3424         begin
3425               if(x_language_code = null) then
3426                            select language into x_language_code
3427                            from wf_users where name = x_bidder_username;
3428               end if;
3429         exception
3430               when others then
3431                    x_language_code := null;
3432 
3433         end;
3434 
3435         x_oex_timezone := Get_Oex_Time_Zone;
3436 
3437         --
3438         -- Get the user's time zone
3439         --
3440       x_timezone := Get_Time_Zone(x_bidder_username);
3441 
3442         --
3443         -- Make sure that it is a valid time zone
3444         --
3445 
3446         IF (PON_OEX_TIMEZONE_PKG.VALID_ZONE(x_timezone) = 0) THEN
3447           x_timezone := x_oex_timezone;
3448         END IF;
3449 
3450         -- Create new timezone
3451         IF (PON_OEX_TIMEZONE_PKG.VALID_ZONE(x_timezone) = 1) THEN
3452             x_newstarttime   := PON_OEX_TIMEZONE_PKG.CONVERT_TIME(x_startdate,x_oex_timezone,x_timezone);
3453             x_newendtime     := PON_OEX_TIMEZONE_PKG.CONVERT_TIME(x_enddate,x_oex_timezone,x_timezone);
3454             x_newpreviewtime := PON_OEX_TIMEZONE_PKG.CONVERT_TIME(x_preview_date,x_oex_timezone,x_timezone);
3455         ELSE
3456             x_newstarttime   := x_startdate;
3457           x_newendtime     := x_enddate;
3458             x_newpreviewtime := x_preview_date;
3459         END IF;
3460 
3461         x_timezone_disp := Get_TimeZone_Description(x_timezone, x_language_code);
3462 
3463         IF (x_preview_date IS NULL) THEN
3464             x_timezone1_disp := null;
3465         ELSE
3466             x_timezone1_disp := x_timezone_disp;
3467         END IF;
3468 
3469       wf_engine.SetItemAttrDate   (itemtype   => x_itemtype,
3470                                    itemkey    => x_itemkey,
3471                                    aname      => 'AUCTION_START_DATE_TZ',
3472                                    avalue     => x_newstarttime);
3473 
3474         wf_engine.SetItemAttrDate   (itemtype   => x_itemtype,
3475                                    itemkey    => x_itemkey,
3476                                    aname      => 'AUCTION_END_DATE_TZ',
3477                                    avalue     => x_newendtime);
3478 
3479         wf_engine.SetItemAttrDate   (itemtype   => x_itemtype,
3480                                    itemkey    => x_itemkey,
3481                                    aname      => 'PREVIEW_DATE_TZ',
3482                                    avalue     => x_newpreviewtime);
3483 
3484 
3485         -- IF (x_add_contact_email is not null) then we need to send a notification
3486         -- to the additional contact as well (Bug 3824928: this can be deleted. We don't need to check separately
3487         -- for additional contact as prev_round_bidders cursor will return additional contact even when he is
3488         -- not associated to a tp contact id (new outer joins added to the query)
3489 
3490       x_bidder_name := null;
3491           x_member := true;
3492 
3493       begin
3494         -- Bug 3824928: Deleted IF condition that tested if trading_partner_id is not null
3495             -- since the condition is always true.
3496       select party_name into x_bidder_name
3497       from hz_parties where party_id = x_prev_trading_partner_id;
3498 
3499       exception
3500     when others then
3501     null;
3502       end;
3503 
3504       if (x_bidder_name is null or x_bidder_name = '') then
3505         begin
3506     select party_name into x_bidder_name
3507     from hz_parties where
3508     party_id = (select person_party_id from fnd_user where user_name = prevBidder.user_name);
3509         exception
3510     when others then
3511     x_bidder_name := prevBidder.user_name;
3512         end;
3513       end if;
3514 
3515       if (x_bidder_name is null or x_bidder_name = '') then
3516     x_bidder_name := prevBidder.user_name;
3517       end if;
3518 
3519       wf_engine.SetItemAttrText (itemtype   => x_itemtype,
3520                            itemkey    => x_itemkey,
3521                            aname      => 'TP_DISPLAY_NAME',
3522                            avalue     => x_bidder_name);
3523 
3524       x_tp_display_name := x_bidder_name;
3525 
3526         -- Set the userenv language so the message token (attribute) values that we retrieve
3527       -- using the getMessage call return the message in the correct language => x_language_code
3528 
3529      SET_SESSION_LANGUAGE(null, x_language_code);
3530 
3531      --Bug 6472383 : Shifted the setting of preview date to this place so that the recipient's language, instead
3532      --of the sender's language is taken into account when setting the preview date to 'Not Specified'
3533 
3534      IF (x_newpreviewtime is not null) THEN
3535         wf_engine.SetItemAttrDate (itemtype        => x_itemtype,
3536                                                    itemkey        => x_itemkey,
3537                                                    aname        => 'PREVIEW_DATE_TZ',
3538                                                    avalue        => x_newpreviewtime);
3539 
3540         wf_engine.SetItemAttrText (itemtype        => x_itemtype,
3541                                                    itemkey        => x_itemkey,
3542                                                    aname        => 'TP_TIME_ZONE1',
3543                                                    avalue        => x_timezone1_disp);
3544 
3545         wf_engine.SetItemAttrText (itemtype        => x_itemtype,
3546                                                    itemkey        => x_itemkey,
3547                                                    aname        => 'PREVIEW_DATE_NOTSPECIFIED',
3548                                                    avalue        => null);
3549      ELSE
3550         wf_engine.SetItemAttrDate (itemtype        => x_itemtype,
3551                                                    itemkey        => x_itemkey,
3552                                                    aname        => 'PREVIEW_DATE_TZ',
3553                                                    avalue        => null);
3554 
3555         wf_engine.SetItemAttrText (itemtype        => x_itemtype,
3556                                                     itemkey        => x_itemkey,
3557                                                    aname        => 'TP_TIME_ZONE1',
3558                                                     avalue        => x_timezone1_disp);
3559 
3560         wf_engine.SetItemAttrText (itemtype        => x_itemtype,
3561                                                    itemkey        => x_itemkey,
3562                                                    aname        => 'PREVIEW_DATE_NOTSPECIFIED',
3563                                                    avalue        => PON_AUCTION_PKG.getMessage('PON_AUC_PREVIEW_DATE_NOTSPEC'));
3564       END IF;
3565 
3566       x_msg_suffix := GET_MESSAGE_SUFFIX (x_doctype_group_name);
3567 
3568 
3569 
3570       wf_engine.SetItemAttrText (itemtype   => x_itemtype,
3571                                  itemkey    => x_itemkey,
3572                                  aname      => 'NON_INVITE_NEW_ROUND_START_SUB',
3573                                  avalue     => getMessage('PON_AUC_WF_PUB_NEWRND_NI_S', x_msg_suffix,
3574                                                             'DOC_NUMBER', x_doc_number_dsp,
3575                                       'AUCTION_TITLE', x_auction_title));
3576 
3577 
3578     -- Bug 4295915: Set the  workflow owner
3579             wf_engine.SetItemOwner(itemtype => x_itemtype,
3580                                    itemkey  => x_itemkey,
3581                                    owner    => fnd_global.user_name);
3582 
3583       wf_engine.StartProcess(itemtype => x_itemtype,
3584                              itemkey  => x_itemkey);
3585         end if;
3586 
3587   close c2_inv_list;
3588 
3589     END LOOP;
3590 
3591     UNSET_SESSION_LANGUAGE;
3592 
3593 END;  -- NEW_ROUND_BIDDERS_NOT_INVITED }
3594 
3595 
3596 
3597 PROCEDURE REGISTERED_BIDDER(itemtype    in varchar2,
3598                  itemkey    in varchar2,
3599                             actid           in number,
3600                             uncmode    in varchar2,
3601                             resultout       out NOCOPY varchar2) IS
3602 
3603 x_flag   VARCHAR2(1);
3604 BEGIN
3605 
3606     x_flag := wf_engine.GetItemAttrText (itemtype => itemtype,
3607                                          itemkey  => itemkey,
3608                                          aname    => 'REGISTERED');
3609 
3610 
3611     IF (x_flag = 'Y') THEN
3612   resultout := 'Y';
3613     ELSE
3614   resultout := 'N';
3615 
3616     END IF;
3617 
3618 END;
3619 
3620 PROCEDURE CREATE_LOCAL_ROLES(   itemtype  in varchar2,
3621         itemkey    in varchar2,
3622                                 actid           in number,
3623                                 uncmode          in varchar2,
3624                                 resultout       out NOCOPY varchar2) IS
3625 
3626 x_role_name      VARCHAR2(30);
3627 x_user_name      VARCHAR2(100);
3628 x_role_display_name    VARCHAR2(30);
3629 x_user_display_name    VARCHAR2(30);
3630 x_note_to_new_bidder    VARCHAR2(2000);
3631 x_auction_header_id      NUMBER;
3632 x_progress      VARCHAR2(3);
3633 x_sequence      NUMBER;
3634 x_user_orig_system    VARCHAR2(30);
3635 x_user_orig_system_id    NUMBER;
3636 x_role_orig_system    VARCHAR2(30) := 'WF_LOCAL_ROLES';
3637 x_role_orig_system_id    NUMBER := 0;
3638 x_person_party_id               NUMBER;
3639 
3640 BEGIN
3641     x_progress := '010';
3642 
3643     x_auction_header_id := wf_engine.GetItemAttrNumber (itemtype => itemtype,
3644                                              itemkey  => itemkey,
3645                                              aname    => 'AUCTION_ID');
3646 
3647     x_progress := '020';
3648 
3649     --
3650     -- Create a role for all bidders in this auction.
3651     --
3652 
3653            SELECT pon_auction_wf_role_s.nextval
3654     INTO   x_sequence
3655     FROM   dual;
3656 
3657     x_role_name := ('WF_PON_ROLE_'||to_char(x_auction_header_id)||'_'||to_char(x_sequence));
3658 
3659     x_progress := '021';
3660 
3661     WF_DIRECTORY.CreateAdHocRole(x_role_name,
3662          x_role_name,
3663                'AMERICAN',
3664                'AMERICA',
3665          'Oracle Exchange Bidder '||to_char(x_auction_header_id),
3666                'MAILHTML',
3667                null,
3668                null,
3669                null,
3670                'ACTIVE',
3671          null);
3672 
3673     UPDATE pon_auction_headers_all set
3674     wf_role_name = x_role_name
3675     WHERE auction_header_id = x_auction_header_id;
3676 
3677     wf_engine.SetItemAttrText (itemtype   => itemtype,
3678                                 itemkey    => itemkey,
3679                                aname      => 'NEW_BIDDER_ROLE',
3680                          avalue     => x_role_name);
3681    x_progress := '030';
3682 
3683 END;
3684 
3685 
3686 PROCEDURE POPULATE_ROLE_WITH_SUPPLIERS (itemtype         IN VARCHAR2,
3687                                         itemkey          IN VARCHAR2,
3688                                         actid            IN NUMBER,
3689                                         uncmode          IN VARCHAR2,
3690                                         resultout        OUT NOCOPY VARCHAR2) IS
3691 
3692 x_role_name            VARCHAR2(30);
3693 x_prev_doc_role_name       VARCHAR2(30);
3694 x_user_name            VARCHAR2(100);
3695 x_auction_header_id    NUMBER;
3696 x_progress             VARCHAR2(3);
3697 
3698 CURSOR suppliers IS
3699     select user_name
3700     from   wf_user_roles
3701     where  role_name = x_prev_doc_role_name;
3702 
3703 BEGIN
3704 
3705     x_progress := '010';
3706 
3707     x_auction_header_id := wf_engine.GetItemAttrNumber (itemtype => itemtype,
3708                                              itemkey  => itemkey,
3709                                              aname    => 'AUCTION_ID');
3710 
3711     x_progress := '20';
3712 
3713     select wf_role_name
3714     into   x_prev_doc_role_name
3715     from   pon_auction_headers_all
3716     where  auction_header_id = (select auction_header_id_prev_amend
3717                                 from   pon_auction_headers_all
3718                                 where  auction_header_id = x_auction_header_id);
3719 
3720 
3721     x_progress := '30';
3722 
3723     x_role_name := wf_engine.GetItemAttrText (itemtype   => itemtype,
3724                                               itemkey    => itemkey,
3725                                               aname      => 'NEW_BIDDER_ROLE');
3726 
3727     x_progress := '40';
3728 
3729     FOR supplier IN suppliers LOOP
3730 
3731         x_user_name := supplier.user_name;
3732 
3733         WF_DIRECTORY.AddUsersToAdHocRole(x_role_name,
3734                                          x_user_name);
3735 
3736     END LOOP;
3737 
3738     x_progress := '50';
3739 
3740 END;
3741 
3742 
3743 PROCEDURE POPULATE_ROLE_WITH_INVITEES (itemtype    IN VARCHAR2,
3744                     itemkey    IN VARCHAR2,
3745                     actid             IN NUMBER,
3746                     uncmode          IN VARCHAR2,
3747                     resultout         OUT NOCOPY VARCHAR2) IS
3748 
3749 x_role_name      VARCHAR2(30);
3750 x_user_name      VARCHAR2(100);
3751 x_role_display_name    VARCHAR2(30);
3752 x_user_display_name    VARCHAR2(30);
3753 x_note_to_new_bidder    VARCHAR2(2000);
3754 x_auction_header_id    NUMBER;
3755 x_progress      VARCHAR2(10);
3756 x_sequence      NUMBER;
3757 x_user_orig_system    VARCHAR2(30);
3758 x_user_orig_system_id    NUMBER;
3759 x_role_orig_system    VARCHAR2(30) := 'WF_LOCAL_ROLES';
3760 x_role_orig_system_id    NUMBER := 0;
3761 x_person_party_id               NUMBER;
3762 x_bidder_count      NUMBER;
3763 x_contact_notif_pref    VARCHAR2(4000);
3764 x_contact_lang      VARCHAR2(4000);
3765 x_contact_territory    VARCHAR2(4000);
3766 
3767 x_auctioneer_user_name         VARCHAR2(100);
3768 x_language_code                VARCHAR2(30) := null;
3769 x_nls_language                 VARCHAR2(60) := 'AMERICAN';
3770 x_territory_code               VARCHAR2(30) := 'AMERICA';
3771 x_nls_territory                VARCHAR2(60);
3772 
3773 l_auctioneer_nls_language      fnd_languages.nls_language%TYPE;
3774 l_auctioneer_nls_territory     fnd_territories.nls_territory%TYPE;
3775 
3776 
3777 CURSOR new_bidders IS
3778     select pbp.trading_partner_contact_name,
3779      pbp.trading_partner_contact_id,
3780      pbp.trading_partner_name,
3781      pbp.trading_partner_id,
3782      pbp.additional_contact_email,
3783            pbp.vendor_site_id,
3784            pbp.requested_supplier_id,
3785            pbp.requested_supplier_contact_id,
3786            pcr.email_address rs_contact_email
3787     from pon_bidding_parties pbp, pos_contact_requests pcr
3788     where pbp.auction_header_id = x_auction_header_id
3789     and pbp.requested_supplier_contact_id = pcr.contact_request_id (+);
3790 
3791 CURSOR c_user_name IS
3792     select user_name
3793   from fnd_user where person_party_id = (select   trading_partner_contact_id
3794                                        from pon_auction_headers_all
3795                                        where auction_header_id = x_auction_header_id)
3796         and nvl(end_date,sysdate+1) > sysdate
3797         and rownum = 1;
3798 
3799 BEGIN
3800     x_progress := '010';
3801     x_auction_header_id := wf_engine.GetItemAttrNumber (itemtype => itemtype,
3802                                              itemkey  => itemkey,
3803                                              aname    => 'AUCTION_ID');
3804 
3805     x_progress := '020';
3806     x_role_name := wf_engine.GetItemAttrText (itemtype   => itemtype,
3807                                           itemkey    => itemkey,
3808                                        aname      => 'NEW_BIDDER_ROLE');
3809     x_progress := '021';
3810 
3811     OPEN c_user_name;
3812     FETCH c_user_name
3813     INTO x_auctioneer_user_name;
3814     CLOSE c_user_name;
3815 
3816     IF x_auctioneer_user_name is not null THEN
3817        PON_PROFILE_UTIL_PKG.GET_WF_PREFERENCES(x_auctioneer_user_name,x_language_code,x_territory_code);
3818     END IF;
3819 
3820    -- Bug 3824928: Store the auctioneer's language and territory in new
3821    -- variables so that they can be used later.
3822 
3823     select NLS_LANGUAGE into l_auctioneer_nls_language
3824     from fnd_languages
3825     where language_code = x_language_code;
3826 
3827     select nls_territory into l_auctioneer_nls_territory
3828     from   fnd_territories
3829     where  territory_code = x_territory_code;
3830 
3831     FOR bidder IN new_bidders LOOP
3832 
3833         -- Bug 3824928: Handle the case where the contact is present (removed earlier
3834         -- if-else)
3835 
3836      IF bidder.trading_partner_contact_id IS NOT NULL  -- {
3837      THEN
3838 
3839     x_person_party_id := bidder.trading_partner_contact_id;
3840 
3841       BEGIN
3842         select user_name
3843       into x_user_name
3844       from fnd_user where person_party_id = x_person_party_id
3845             and nvl(end_date, sysdate+1) > sysdate;
3846       EXCEPTION
3847         when too_many_rows then
3848            if (nvl(fnd_profile.value('AFLOG_ENABLED'),'N') = 'Y') then
3849                if (fnd_log.level_unexpected >= fnd_log.g_current_runtime_level) then
3850                          fnd_log.string(log_level => fnd_log.level_unexpected,
3851                                         module    => 'pon.plsql.pon_auction_pkg.populate_role_with_invitees',
3852                                         message   => 'Multiple Users found for person_party_id:'|| x_person_party_id);
3853                end if;
3854           end if;
3855 
3856            select user_name
3857            into x_user_name
3858            from fnd_user
3859            where person_party_id = x_person_party_id
3860            and nvl(end_date, sysdate+1) > sysdate
3861            and rownum=1;
3862 
3863       END;
3864 
3865 
3866     x_user_orig_system := 'FND_USR';
3867           begin
3868             select to_char(user_id)
3869             into x_user_orig_system_id
3870             from fnd_user
3871             where user_name = x_user_name;
3872           exception when others then
3873         x_user_orig_system_id := 0;
3874           end;
3875 
3876   select count(*)
3877   into x_bidder_count
3878   from wf_local_user_roles
3879   where role_name = x_role_name
3880   and user_name = x_user_name;
3881 
3882   if (x_bidder_count < 1) then
3883 
3884   WF_DIRECTORY.AddUsersToAdHocRole(x_role_name,
3885                  x_user_name);
3886 
3887   end if;
3888    END IF;-- end IF bidder.trading_partner_contact_id IS NOT NULL }
3889    IF (bidder.additional_contact_email IS NOT NULL) THEN
3890 
3891     -- add new user to local users and also add to the role.
3892 
3893     -- Bug 3824928: If trading partner contact is not there then prevent
3894     -- this SELECT from erroring out
3895     -- The steps below try to set up the user for the additional contact
3896     -- email so that they have the same settings as the existing contact.
3897     -- However, if the row in pon_bidding_parties does not have a contact,
3898     -- then the additional contact user inherits the settings of the
3899     -- auctioneer
3900 
3901     IF bidder.trading_partner_contact_id IS NOT NULL  --{
3902     THEN  --<
3903 
3904 
3905     select NOTIFICATION_PREFERENCE, LANGUAGE, TERRITORY
3906     into   x_contact_notif_pref, x_contact_lang, x_contact_territory
3907     from wf_users where name = x_user_name;
3908 
3909     -- Get NLS_LANGUAGE and NLS_TERRITORY for the user corresponding to additional contact
3910 
3911     IF x_user_name is not null THEN
3912              PON_PROFILE_UTIL_PKG.GET_WF_PREFERENCES(x_user_name ,x_language_code,x_territory_code);
3913           END IF;
3914 
3915          x_progress := '021';
3916 
3917 
3918          begin
3919          select NLS_LANGUAGE into x_nls_language
3920          from fnd_languages
3921          where language_code = x_language_code;
3922 
3923          select nls_territory into x_nls_territory
3924          from   fnd_territories
3925          where  territory_code = x_territory_code;
3926        exception
3927         when others then
3928              x_nls_language := 'AMERICAN';
3929              x_nls_territory := 'AMERICA';
3930           end;
3931 
3932      ELSE
3933       -- Get auctioneer's settings
3934 
3935                 x_nls_language := l_auctioneer_nls_language;
3936                 x_nls_territory:= l_auctioneer_nls_territory;
3937      END IF;--}
3938 
3939      SELECT pon_auction_wf_bidder_s.nextval
3940              INTO   x_sequence
3941              FROM   dual;
3942 
3943       x_user_name := ('WF_PON_ADD_USER_'||to_char(x_sequence));
3944 
3945        x_progress := '022';
3946 
3947        -- Create an adhoc user for the additional contact
3948 
3949     WF_DIRECTORY.CreateAdHocUser(x_user_name,
3950                      x_user_name,
3951                      x_nls_language,
3952                      x_nls_territory,
3953                      'Oracle Exchange Additional Bidder '||to_char(x_auction_header_id),
3954                      'MAILHTML',
3955                      bidder.additional_contact_email,
3956                      null,
3957                      'ACTIVE',
3958                      null);
3959     x_progress := '023';
3960     UPDATE pon_bidding_parties set
3961         wf_user_name = x_user_name
3962     WHERE auction_header_id = x_auction_header_id
3963     AND   trading_partner_id = bidder.trading_partner_id
3964       AND   vendor_site_id     = bidder.vendor_site_id;
3965 
3966     -- Also insert into the role
3967 
3968     WF_DIRECTORY.AddUsersToAdHocRole(x_role_name,
3969                    x_user_name);
3970 
3971   end if;  -- (bidder.additional_contact_email IS NOT NULL)
3972 
3973     -- add requested suppliers
3974     if (bidder.trading_partner_id is null and
3975         bidder.requested_supplier_contact_id is not null) then
3976    -- {
3977       -- Get auctioneer's settings
3978       x_nls_language := l_auctioneer_nls_language;
3979       x_nls_territory:= l_auctioneer_nls_territory;
3980 
3981       -- Get next bidder from sequence
3982       SELECT pon_auction_wf_bidder_s.nextval
3983       INTO x_sequence
3984       FROM dual;
3985 
3986       x_user_name := ('WF_PON_ADD_USER_'||to_char(x_sequence));
3987       x_progress := '022_REQ';
3988 
3989       -- Create an adhoc user for the requested_supplier
3990       WF_DIRECTORY.CreateAdHocUser(x_user_name,
3991                                  x_user_name,
3992                                  x_nls_language,
3993                                  x_nls_territory,
3994                                  'Oracle Exchange Requested Bidder'||to_char(x_auction_header_id),
3995                                  'MAILHTML',
3996                                  bidder.rs_contact_email,
3997                                  null,
3998                                  'ACTIVE',
3999                                  null);
4000       x_progress := '023_REQ';
4001 
4002       -- record wf_user_name in pon_bidding_parties
4003       UPDATE pon_bidding_parties
4004          set wf_user_name = x_user_name
4005        WHERE auction_header_id = x_auction_header_id
4006          AND requested_supplier_id = bidder.requested_supplier_id;
4007 
4008       x_progress := '024_REQ';
4009 
4010       -- Also insert into the role
4011       WF_DIRECTORY.AddUsersToAdHocRole(x_role_name, x_user_name);
4012 
4013     end if; --} tp_id == null and requested_supplier_contact_id != null
4014 
4015    END LOOP;
4016 
4017    x_progress := '030';
4018 
4019 END;
4020 
4021 
4022 
4023 PROCEDURE REACHED_AUCTION_START_DATE (  itemtype  in varchar2,
4024           itemkey    in varchar2,
4025                                   actid           in number,
4026                                   uncmode          in varchar2,
4027                                   resultout       out NOCOPY varchar2) IS
4028 x_start_date  DATE;
4029 x_progress  VARCHAR2(3);
4030 x_reached_date  VARCHAR2(1) := 'N';
4031 
4032 BEGIN
4033 
4034     x_progress := '010';
4035 
4036     x_start_date := wf_engine.GetItemAttrDate (itemtype => itemtype,
4037                                                itemkey  => itemkey,
4038                                                aname    => 'AUCTION_NOTIFICATION_DATE');
4039     x_progress := '020';
4040 
4041     IF x_start_date <= SYSDATE
4042     THEN
4043        x_reached_date := 'Y';
4044     END IF;
4045 
4046     x_progress := '030';
4047 
4048     IF (x_reached_date = 'Y') THEN
4049   resultout := 'Y';
4050     ELSE
4051   resultout := 'N';
4052 
4053     END IF;
4054 
4055 END;
4056 
4057 PROCEDURE REACHED_AUCTION_END_DATE (  itemtype  in varchar2,
4058           itemkey    in varchar2,
4059                                   actid           in number,
4060                                   uncmode          in varchar2,
4061                                   resultout       out NOCOPY varchar2) IS
4062 
4063 x_end_date  DATE;
4064 x_progress  VARCHAR2(3);
4065 x_reached_date  VARCHAR2(1) := 'N';
4066 
4067 BEGIN
4068 
4069     x_progress := '010';
4070 
4071     x_end_date := wf_engine.GetItemAttrDate (itemtype => itemtype,
4072                                                itemkey  => itemkey,
4073                                                aname    => 'AUCTION_END_DATE');
4074     x_progress := '020';
4075 
4076     IF x_reached_date <= SYSDATE
4077     THEN
4078       x_reached_date := 'Y';
4079     END IF;
4080 
4081     x_progress := '030';
4082 
4083     IF (x_reached_date = 'Y') THEN
4084   resultout := 'Y';
4085     ELSE
4086   resultout := 'N';
4087 
4088     END IF;
4089 
4090 END;
4091 
4092 PROCEDURE DOES_BIDDER_LIST_EXIT(  itemtype  in varchar2,
4093           itemkey  in varchar2,
4094                              actid         in number,
4095                                 uncmode  in varchar2,
4096                                   resultout     out NOCOPY varchar2) IS
4097 
4098 x_flag     VARCHAR2(1);
4099 x_progress  VARCHAR2(3);
4100 
4101 BEGIN
4102 
4103    x_progress := '010';
4104 
4105    x_flag := wf_engine.GetItemAttrText (itemtype => itemtype,
4106                                         itemkey  => itemkey,
4107                                         aname    => 'BIDDER_LIST_FLAG');
4108 
4109    x_progress := '020';
4110 
4111    IF (x_flag = 'Y') THEN
4112      resultout := 'Y';
4113    ELSE
4114      resultout := 'N';
4115    END IF;
4116 
4117 END;
4118 
4119 
4120 PROCEDURE NON_BID_LIST_BIDDERS(  itemtype    in varchar2,
4121            itemkey    in varchar2,
4122                        actid           in number,
4123                        uncmode    in varchar2,
4124                        resultout       out NOCOPY varchar2) IS
4125 
4126 BEGIN
4127 null;
4128 END;
4129 
4130 
4131 
4132 PROCEDURE NOTIFY_BIDDER_LIST_START(itemtype  in varchar2,
4133         itemkey    in varchar2,
4134                          actid           in number,
4135                             uncmode    in varchar2,
4136                               resultout       out NOCOPY varchar2) IS
4137 
4138 x_notification_id  NUMBER;
4139 x_progress    VARCHAR2(3);
4140 
4141 BEGIN
4142 
4143     x_progress := '010';
4144 
4145 
4146     email_list(p_itemtype    => itemtype,
4147          p_itemkey    => itemkey,
4148          p_actid      => actid,
4149          p_notification_id  => x_notification_id);
4150 
4151     x_progress := '020';
4152 
4153 END;
4154 
4155 PROCEDURE NOTIFY_BIDDER_LIST_CANCEL(  itemtype  in varchar2,
4156         itemkey    in varchar2,
4157                          actid           in number,
4158                             uncmode    in varchar2,
4159                               resultout       out NOCOPY varchar2) IS
4160 BEGIN
4161 null;
4162 END;
4163 
4164 
4165 PROCEDURE NOTIFY_NON_BIDDER_LIST_CANCEL(  itemtype  in varchar2,
4166         itemkey    in varchar2,
4167                          actid           in number,
4168                             uncmode    in varchar2,
4169                               resultout       out NOCOPY varchar2) IS
4170 
4171 x_notification_id  NUMBER;
4172 x_progress    VARCHAR2(3);
4173 
4174 BEGIN
4175 
4176     x_progress := '010';
4177 
4178 
4179     email_bidders(p_itemtype    => itemtype,
4180              p_itemkey    => itemkey,
4181                p_actid    => actid,
4182             p_message_name  => 'AUCTION_CANCELLED',
4183            p_notification_id  => x_notification_id);
4184 
4185     x_progress := '020';
4186 
4187 END;
4188 
4189 PROCEDURE NOTIFY_BIDDER_LIST_END(  itemtype  in varchar2,
4190         itemkey    in varchar2,
4191                          actid           in number,
4192                             uncmode    in varchar2,
4193                               resultout       out NOCOPY varchar2) IS
4194 
4195 BEGIN
4196 null;
4197 END;
4198 
4199 PROCEDURE NOTIFY_NON_BIDDER_LIST_END(  itemtype  in varchar2,
4200         itemkey    in varchar2,
4201                          actid           in number,
4202                             uncmode    in varchar2,
4203                               resultout       out NOCOPY varchar2) IS
4204 
4205 
4206 x_notification_id  NUMBER;
4207 x_progress    VARCHAR2(3);
4208 
4209 BEGIN
4210 
4211     x_progress := '010';
4212 
4213 
4214     email_bidders(p_itemtype    => itemtype,
4215              p_itemkey    => itemkey,
4216                p_actid    => actid,
4217             p_message_name  => 'AUCTION_ENDED',
4218            p_notification_id  => x_notification_id);
4219 
4220     x_progress := '020';
4221 
4222 END;
4223 
4224 PROCEDURE CHECK_AUCTION_BIDDER
4225           (p_trading_partner_contact_id IN NUMBER,
4226            p_auction_header_id IN NUMBER,
4227            x_return_status OUT NOCOPY NUMBER)
4228 IS
4229 
4230 x_progress              VARCHAR2(3);
4231 x_bidder_user_name      VARCHAR2(100);
4232 x_role_name             VARCHAR2(30);
4233 
4234 BEGIN
4235 
4236     x_progress := '010';
4237 
4238     select wf_role_name
4239     into   x_role_name
4240     from   pon_auction_headers_all
4241     where  auction_header_id = p_auction_header_id;
4242 
4243     BEGIN
4244       select user_name
4245       into   x_bidder_user_name
4246       from   fnd_user
4247       where  person_party_id= p_trading_partner_contact_id
4248       and nvl(end_date, sysdate+1) > sysdate;
4249     EXCEPTION
4250        when too_many_rows then
4251           if (nvl(fnd_profile.value('AFLOG_ENABLED'),'N') = 'Y') then
4252                if (fnd_log.level_unexpected >= fnd_log.g_current_runtime_level) then
4253                          fnd_log.string(log_level => fnd_log.level_unexpected,
4254                                         module    => 'pon.plsql.pon_auction_pkg.check_auction_bidder',
4255                                         message   => 'Multiple Users found for person_party_id:'|| p_trading_partner_contact_id);
4256                end if;
4257          end if;
4258 
4259          select user_name
4260          into x_bidder_user_name
4261          from fnd_user
4262          where person_party_id = p_trading_partner_contact_id
4263          and nvl(end_date, sysdate+1) > sysdate
4264          and rownum=1;
4265 
4266     END;
4267 
4268     x_progress := '020';
4269 
4270     add_bidder_to_role(x_bidder_user_name,x_role_name);
4271 
4272     x_return_status := 0;
4273 
4274 EXCEPTION
4275 
4276     WHEN OTHERS THEN
4277        x_return_status := 1;
4278 
4279 END;
4280 
4281 
4282 PROCEDURE BIDDER_IN_LIST    (  itemtype  in varchar2,
4283         itemkey    in varchar2,
4284                          actid           in number,
4285                             uncmode    in varchar2,
4286                               resultout       out NOCOPY varchar2)  IS
4287 
4288 x_flag   VARCHAR2(1) := 'N';
4289 x_auction_header_id  NUMBER;
4290 x_bidder_contact_id   NUMBER;
4291 x_progress    VARCHAR2(3);
4292 
4293 BEGIN
4294 
4295     x_progress := '010';
4296 
4297     x_auction_header_id := wf_engine.GetItemAttrNumber (itemtype => itemtype,
4298                                                       itemkey  => itemkey,
4299                                                      aname    => 'AUCTION_ID');
4300 
4301     x_bidder_contact_id := wf_engine.GetItemAttrNumber (itemtype => itemtype,
4302                                                       itemkey  => itemkey,
4303                                                      aname    => 'PREPARER_TP_CONTACT_ID');
4304 
4305     x_progress := '020';
4306 
4307   begin
4308     select 'Y' into x_flag
4309     from pon_bidding_parties
4310     where auction_header_id = x_auction_header_id
4311     and trading_partner_contact_id = x_bidder_contact_id
4312     group by trading_partner_contact_id;
4313         exception when NO_DATA_FOUND then
4314      x_flag := 'N';
4315   end;
4316 
4317     x_progress := '030';
4318 
4319    IF (x_flag = 'Y') THEN
4320      resultout := 'Y';
4321    ELSE
4322      resultout := 'N';
4323    END IF;
4324 
4325 END;
4326 
4327 
4328 PROCEDURE ADD_BIDDER_TO_ROLE(p_user_name  VARCHAR2,
4329            p_role_name  VARCHAR2) IS
4330 
4331 x_progress      VARCHAR2(3);
4332 x_user_orig_system    VARCHAR2(30) := 'FND_USR';
4333 x_user_orig_system_id    NUMBER := 0;
4334 x_role_orig_system    VARCHAR2(30) := 'WF_LOCAL_ROLES';
4335 x_role_orig_system_id    NUMBER := 0;
4336 x_bidder_count      NUMBER;
4337 
4338 BEGIN
4339     x_progress := '010';
4340 
4341   select count(*)
4342   into x_bidder_count
4343   from wf_local_user_roles
4344   where role_name = p_role_name
4345   and user_name = p_user_name;
4346 
4347   if (x_bidder_count < 1) then
4348     WF_DIRECTORY.AddUsersToAdHocRole(p_role_name,
4349                    p_user_name);
4350   end if;
4351 END;
4352 
4353 PROCEDURE SEALED_BIDS(  itemtype  in varchar2,
4354         itemkey    in varchar2,
4355                          actid           in number,
4356                             uncmode    in varchar2,
4357                               resultout       out NOCOPY varchar2) IS
4358 
4359 x_flag       VARCHAR2(1);
4360 x_progress    VARCHAR2(3);
4361 
4362 BEGIN
4363 
4364     x_progress := '010';
4365 
4366     x_flag := wf_engine.GetItemAttrText (itemtype => itemtype,
4367                                                       itemkey  => itemkey,
4368                                                      aname    => 'SEALED_FLAG');
4369 
4370     x_progress := '020';
4371 
4372    IF (x_flag = 'Y') THEN
4373      resultout := 'Y';
4374    ELSE
4375      resultout := 'N';
4376    END IF;
4377 
4378 END;
4379 
4380 ----------------------------------------------------------------
4381 -- Procedure call to cancel an auction                        --
4382 ----------------------------------------------------------------
4383 PROCEDURE CANCEL_AUCTION (p_auction_header_id  IN NUMBER) IS
4384 
4385 x_itemtype   VARCHAR2(7) := 'PONAUCT';
4386 x_itemkey  VARCHAR2(30);
4387 x_notification_date  DATE;
4388 x_now    DATE;
4389 x_cancel_reason PON_ACTION_HISTORY.ACTION_NOTE%TYPE := '';
4390 x_cancel_date   PON_AUCTION_HEADERS_ALL.CANCEL_DATE%TYPE;
4391 x_current_activity VARCHAR2(30);
4392 
4393 
4394 BEGIN
4395 
4396 
4397    --
4398    -- Get the workflow item key and the current time so that we
4399    -- can complete the workflow
4400    --
4401    x_now := SYSDATE;
4402 
4403    select wf_item_key, sysdate, cancel_date
4404      into x_itemkey, x_now, x_cancel_date
4405      from pon_auction_headers_all
4406      where auction_header_id = p_auction_header_id;
4407 
4408 
4409    --
4410    -- First, see what activity (if any) the workflow is on
4411    -- If none, then return.  Workflow has already completed??
4412    --
4413    BEGIN
4414       select activity_label
4415   into x_current_activity
4416   from wf_item_activity_statuses_v
4417   where item_type = x_itemtype
4418   AND item_key = x_itemkey
4419   and activity_status_code = 'NOTIFIED';
4420    EXCEPTION WHEN no_data_found THEN
4421      RETURN;
4422    END;
4423    --
4424    -- Get the cancel reason from the action history table
4425    --
4426    BEGIN
4427       select action_note
4428   into   x_cancel_reason
4429   from pon_action_history
4430   where object_id = p_auction_header_id
4431   and   object_type_code = 'PON_AUCTION'
4432   and action_type = 'CANCEL';
4433    EXCEPTION WHEN NO_DATA_FOUND THEN
4434       x_cancel_reason := '';
4435    END;
4436 
4437 
4438    --
4439    -- Set the workflow attribute
4440    --
4441 
4442    if (x_cancel_reason is null) then
4443      wf_engine.SetItemAttrText(itemtype => x_itemtype,
4444           itemkey  => x_itemkey,
4445           aname    => 'CANCEL_REASON',
4446           avalue   => getMessage('PON_AUC_WF_NO_REASON', ''));
4447    else
4448      wf_engine.SetItemAttrText(itemtype => x_itemtype,
4449                itemkey  => x_itemkey,
4450                aname    => 'CANCEL_REASON',
4451                avalue   => x_cancel_reason);
4452    end if;
4453 
4454 
4455    if (x_cancel_date is not null) then
4456           wf_engine.SetItemAttrDate(itemtype => x_itemtype,
4457           itemkey  => x_itemkey,
4458           aname    => 'CANCEL_DATE',
4459           avalue   => x_cancel_date);
4460 
4461    end if;
4462 
4463    --
4464    -- Complete the workflow with a cancel action.
4465    -- This should either be
4466    --   1) Waiting for the start of the auction
4467    --   2) Pre  6.1 - waiting for the end of the auction
4468    --      Post 6.1 - waiting for user to complete the auction
4469    --
4470 
4471    wf_engine.CompleteActivity(x_itemtype,x_itemkey,x_current_activity,'PREPARER_CANCEL');
4472 
4473 END;
4474 
4475 FUNCTION GET_CLOSE_BIDDING_DATE(p_auction_header_id IN NUMBER) RETURN DATE
4476 
4477 IS
4478 
4479   v_end_date DATE;
4480 
4481 BEGIN
4482 
4483 
4484      select pah.close_bidding_date
4485      into   v_end_date
4486      from   pon_auction_headers_all pah
4487      where  pah.auction_header_id = p_auction_header_id;
4488 
4489      RETURN v_end_date;
4490 
4491 END;
4492 
4493 
4494 FUNCTION TIME_REMAINING_ORDER(p_auction_header_id IN NUMBER) RETURN NUMBER
4495 
4496 IS
4497 
4498   v_auction_status     VARCHAR2(25);
4499   v_creation_date      DATE;
4500   v_end_date           DATE;
4501   v_time_left_order    NUMBER;
4502   v_is_paused         VARCHAR2(1);
4503   v_last_pause_date    DATE;
4504   v_auction_header_id_orig_round NUMBER;
4505   v_auction_round_number NUMBER;
4506   v_amendment_number NUMBER;
4507 
4508 BEGIN
4509 
4510      select pah.auction_status, pah.creation_date, pah.close_bidding_date, nvl( pah.is_paused, 'N' ), nvl( pah.last_pause_date, sysdate )
4511             , auction_header_id_orig_round, nvl(auction_round_number,0),
4512 nvl(amendment_number,0)
4513      into   v_auction_status, v_creation_date, v_end_date, v_is_paused, v_last_pause_date
4514             , v_auction_header_id_orig_round, v_auction_round_number,
4515 v_amendment_number
4516      from   pon_auction_headers_all pah
4517      where  pah.auction_header_id = p_auction_header_id;
4518 
4519    RETURN TIME_REMAINING_ORDER( v_auction_status, v_creation_date , v_end_date, v_is_paused, v_last_pause_date, v_auction_header_id_orig_round, v_auction_round_number, v_amendment_number );
4520 
4521 END;
4522 
4523 
4524 -- Overloaded function to calculate time_remaining.
4525 -- This function will not make any database call,
4526 -- since all the necessary parameters are passed as an arguments.
4527 FUNCTION TIME_REMAINING_ORDER( p_auction_status      IN VARCHAR2,
4528                                p_creation_date       IN DATE,
4529                                p_close_bidding_date  IN DATE,
4530                                p_is_paused           IN VARCHAR2,
4531                                p_last_pause_date     IN DATE,
4532                                p_auction_header_id_orig_round IN NUMBER,
4533                                p_auction_round_number IN NUMBER,
4534                                p_amendment_number IN NUMBER) RETURN NUMBER
4535 
4536 IS
4537 
4538   v_time_left_order    NUMBER;
4539 
4540 BEGIN
4541 
4542    -- Check the dates are having valid inputs. If the dates are null,
4543    -- we will return output as Zero (0), since those records will be displayed at the top
4544    -- and the users can easily find out the problems.
4545    IF ( p_creation_date IS NULL OR  p_close_bidding_date IS NULL ) THEN
4546       v_time_left_order := 0;
4547       RETURN v_time_left_order;
4548    END IF;
4549 
4550    --
4551    -- If cancelled
4552    --
4553    IF ( p_auction_status = 'CANCELLED') THEN
4554       v_time_left_order := (2000*365) + (p_close_bidding_date - sysdate);
4555       RETURN v_time_left_order;
4556    END IF;
4557 
4558    --
4559    -- If amended or completed
4560    --
4561    IF (p_auction_status = 'AMENDED' or p_auction_status = 'AUCTION_CLOSED') THEN
4562       v_time_left_order := (1500*365) - (p_auction_header_id_orig_round +
4563                            nvl(p_auction_round_number,0)*0.0001 +
4564                            nvl(p_amendment_number,0)*0.00000001)/10000000000000000;
4565       --v_time_left_order := (1500*365) + (sysdate - p_creation_date);
4566       RETURN v_time_left_order;
4567    END IF;
4568 
4569    --
4570    -- If the negotiation is paused, return the constant time remaining.
4571    --
4572    IF ( p_is_paused = 'Y' ) THEN
4573       IF p_last_pause_date IS NOT NULL THEN
4574         v_time_left_order :=  p_close_bidding_date - p_last_pause_date;
4575         RETURN v_time_left_order;
4576       ELSE
4577         v_time_left_order := 0;
4578         RETURN v_time_left_order;
4579       END IF;
4580    END IF;
4581 
4582    --
4583    -- If closed
4584    --
4585    IF (p_close_bidding_date < sysdate) THEN
4586       v_time_left_order := (1000*365) + (p_close_bidding_date - sysdate);
4587       RETURN v_time_left_order;
4588    END IF;
4589 
4590    v_time_left_order := p_close_bidding_date - sysdate;
4591    return v_time_left_order;
4592 
4593 END;
4594 
4595 
4596 --
4597 -- Bug 3283581 and Bug 3275373
4598 --
4599 -- TIME_REMAINING has been revamped to always return the time left in
4600 -- days, hours, and minutes.  The actual date will never be returned to avoid
4601 -- any date formatting and translation issues.
4602 --
4603 
4604 
4605 FUNCTION TIME_REMAINING(p_auction_header_id IN NUMBER) RETURN VARCHAR2
4606 
4607 IS
4608 
4609 BEGIN
4610 
4611   RETURN TIME_REMAINING(p_auction_header_id, null);
4612 
4613 END;
4614 
4615 FUNCTION TIME_REMAINING(p_auction_header_id IN NUMBER, p_line_number IN NUMBER) RETURN VARCHAR2
4616 
4617 IS
4618 
4619   v_auction_status     VARCHAR2(25);
4620   v_startdate          DATE;
4621   v_enddate            DATE;
4622   v_difference         NUMBER := 0;
4623   v_days               NUMBER := 0;
4624   v_hours              NUMBER := 0;
4625   v_minutes            NUMBER := 0;
4626   v_time_left          VARCHAR2(50) := null;
4627   v_opens_in_suffix    VARCHAR2(2)  := '';
4628   v_pausedate          DATE;
4629   v_ispaused           VARCHAR2(1);
4630   v_staggered_closing_interval NUMBER := NULL;
4631 
4632 BEGIN
4633 
4634   IF (p_line_number is null) THEN
4635 
4636      select auction_status, open_bidding_date, close_bidding_date, nvl( last_pause_date, sysdate ), nvl( is_paused, 'N' ), staggered_closing_interval
4637      into   v_auction_status, v_startdate, v_enddate, v_pausedate, v_ispaused, v_staggered_closing_interval
4638      from   pon_auction_headers_all
4639      where  auction_header_id = p_auction_header_id;
4640 
4641   ELSE
4642 
4643      select pah.auction_status, pah.open_bidding_date, nvl(paip.close_bidding_date, pah.close_bidding_date),
4644             nvl( pah.last_pause_date, sysdate ), nvl( pah.is_paused, 'N' )
4645      into   v_auction_status, v_startdate, v_enddate, v_pausedate, v_ispaused
4646      from   pon_auction_headers_all pah, pon_auction_item_prices_all paip
4647      where  pah.auction_header_id = p_auction_header_id and
4648             paip.auction_header_id = pah.auction_header_id and
4649             paip.line_number = p_line_number;
4650 
4651   END IF;
4652 
4653   RETURN TIME_REMAINING( v_auction_status, v_startdate, v_enddate, v_ispaused, v_pausedate, v_staggered_closing_interval);
4654 
4655 END;
4656 
4657 -- Overloaded function to calculate time_remaining.
4658 -- This function will not make any database call,
4659 -- since all the necessary parameters are passed as an arguments.
4660 FUNCTION TIME_REMAINING( p_auction_status      IN VARCHAR2,
4661                          p_open_bidding_date   IN DATE,
4662                          p_close_bidding_date  IN DATE,
4663                          p_is_paused           IN VARCHAR2,
4664                          p_last_pause_date     IN DATE,
4665                          p_staggered_closing_interval IN NUMBER ) RETURN VARCHAR2
4666 IS
4667 
4668   v_difference         NUMBER := 0;
4669   v_days               NUMBER := 0;
4670   v_hours              NUMBER := 0;
4671   v_minutes            NUMBER := 0;
4672   v_seconds            NUMBER := 0;
4673   v_time_left          VARCHAR2(50) := null;
4674   v_opens_in_suffix    VARCHAR2(2)  := '';
4675 
4676 BEGIN
4677 
4678    --
4679    -- If cancelled, then return "Cancelled"
4680    --
4681    IF (p_auction_status = 'CANCELLED') THEN
4682       v_time_left :=  fnd_message.get_string('PON', 'PON_AUC_CANCELLED');
4683       RETURN v_time_left;
4684    END IF;
4685 
4686    --
4687    -- If amended, then return "N/A"
4688    --
4689    IF (p_auction_status = 'AMENDED') THEN
4690      v_time_left := fnd_message.get_string('PON', 'PON_NOT_APPLICABLE');
4691      RETURN v_time_left;
4692    END IF;
4693 
4694    -- We will check the dates are valid.
4695    -- If the dates are null, then we will return, BLANK message as time left.
4696    IF p_open_bidding_date IS NULL OR p_close_bidding_date IS NULL THEN
4697       v_time_left :=  ' ';
4698       RETURN v_time_left;
4699    END IF;
4700 
4701    --
4702    -- If the negotiation is paused, return the constant time remaining.
4703    --
4704    IF ( p_is_paused = 'Y' ) THEN
4705 
4706             IF p_last_pause_date IS NULL THEN
4707                 v_time_left :=  ' ';
4708                 RETURN v_time_left;
4709             ELSE
4710                 -- if a staggered  auction
4711                 --then show STAGGERED CLOSING for close date
4712                 IF p_staggered_closing_interval IS NOT NULL THEN
4713                   return fnd_message.get_string('PON','PON_STAGGERED_CLOSING_MSG');
4714                 END IF;
4715                 v_difference := to_number( p_close_bidding_date - p_last_pause_date );
4716             END IF;
4717 
4718    ELSE
4719 
4720      --
4721      -- If closed, then return "0 seconds"
4722      --
4723      IF (p_close_bidding_date < sysdate) THEN
4724         fnd_message.clear;
4725         fnd_message.set_name('PON','PON_AUC_INTERVAL_SEC');
4726         fnd_message.set_token('SECONDS',0);
4727         v_time_left := fnd_message.get;
4728         RETURN v_time_left;
4729      END IF;
4730 
4731      -- if a staggered  auction
4732      --then show STAGGERED CLOSING for close date
4733      IF p_staggered_closing_interval IS NOT NULL THEN
4734        return fnd_message.get_string('PON','PON_STAGGERED_CLOSING_MSG');
4735      END IF;
4736      --
4737      -- If the start date is in the future, then
4738      -- calculate the difference from sysdate to start date and
4739      -- use "Opens in XXXX" messages
4740      --
4741      IF(p_open_bidding_date > Sysdate) THEN
4742         v_opens_in_suffix := '_F';
4743         v_difference := to_number(p_open_bidding_date - sysdate);
4744       --
4745       -- Otherwise, calculate the difference from sysdate to end date
4746       --
4747       ELSE
4748         v_difference := to_number(p_close_bidding_date - sysdate);
4749      END IF;
4750    END IF;
4751 
4752    --
4753    -- Calculate time components
4754    --
4755    v_days := trunc(v_difference);
4756    v_hours := trunc(mod(v_difference*24,24));
4757    v_minutes := trunc(mod(v_difference*(24*60),60));
4758    v_seconds := trunc(mod(v_difference*(24*60*60),60));
4759 
4760     IF (FND_LOG.level_statement>= FND_LOG.g_current_runtime_level) THEN
4761       FND_LOG.string(log_level => FND_LOG.level_statement,
4762         module  =>  g_module_prefix || 'TIME_REMAINING',
4763         message  => 'v_days = ' || v_days
4764                     || ' v_hours = ' || v_hours
4765                     || ' v_minutes = ' || v_minutes
4766                     || ' v_seconds = ' || v_seconds
4767             );
4768     END IF;
4769 
4770    --
4771    -- If we have less than one minute
4772    --
4773    IF(v_days < 1 AND v_hours < 1 AND v_minutes < 1 AND 0 < v_seconds) THEN
4774       v_time_left :=  fnd_message.get_string('PON', 'PON_LESS_MINUTE'||v_opens_in_suffix);
4775    --
4776    -- If we have less than one second, display 0 minutes
4777    --
4778    ELSIF(v_days < 1 AND v_hours < 1 AND v_minutes < 1 AND v_seconds < 1) THEN
4779       fnd_message.clear;
4780       IF (v_opens_in_suffix is not null) THEN
4781         fnd_message.set_name('PON','PON_MINUTES'||v_opens_in_suffix);
4782         fnd_message.set_token('NUM_MINUTES',0);
4783       ELSE
4784         fnd_message.set_name('PON','PON_AUC_INTERVAL_SEC');
4785         fnd_message.set_token('SECONDS',0);
4786       END IF;
4787       v_time_left := fnd_message.get;
4788     --
4789     -- If we have just one minute
4790     --
4791     ELSIF(v_days < 1 AND v_hours < 1 AND v_minutes = 1) THEN
4792       v_time_left :=  fnd_message.get_string('PON', 'PON_MINUTE'||v_opens_in_suffix);
4793     --
4794     -- If we have just minutes
4795     --
4796     ELSIF(v_days < 1 AND v_hours < 1 AND v_minutes > 1 ) THEN
4797       fnd_message.clear;
4798       fnd_message.set_name('PON','PON_MINUTES'||v_opens_in_suffix);
4799       fnd_message.set_token('NUM_MINUTES',v_minutes);
4800       v_time_left := fnd_message.get;
4801     --
4802     -- If we have one hour
4803     --
4804     ELSIF(v_days < 1 AND v_hours = 1 AND v_minutes < 1) THEN
4805       v_time_left := fnd_message.get_string('PON','PON_HOUR'||v_opens_in_suffix);
4806     --
4807     -- If we have one hour and one minute
4808     --
4809     ELSIF(v_days < 1 AND v_hours = 1 AND v_minutes = 1) THEN
4810       v_time_left := fnd_message.get_string('PON','PON_HOUR_MINUTE'||v_opens_in_suffix);
4811     --
4812     -- If we have one hour and minutes
4813     --
4814     ELSIF(v_days < 1 AND v_hours = 1 AND v_minutes > 1) THEN
4815       fnd_message.clear;
4816       fnd_message.set_name('PON','PON_HOUR_MINUTES'||v_opens_in_suffix);
4817       fnd_message.set_token('NUM_MINUTES',v_minutes);
4818       v_time_left := fnd_message.get;
4819     --
4820     -- If we have hours
4821     --
4822     ELSIF(v_days < 1 AND v_hours > 1 AND v_minutes < 1) THEN
4823       fnd_message.clear;
4824       fnd_message.set_name('PON','PON_HOURS'||v_opens_in_suffix);
4825       fnd_message.set_token('NUM_HOURS',v_hours);
4826       v_time_left := fnd_message.get;
4827     --
4828     -- If we have hours and one minute
4829     --
4830     ELSIF(v_days < 1 AND v_hours > 1 AND v_minutes = 1) THEN
4831       fnd_message.clear;
4832       fnd_message.set_name('PON','PON_HOURS_MINUTE'||v_opens_in_suffix);
4833       fnd_message.set_token('NUM_HOURS',v_hours);
4834       v_time_left := fnd_message.get;
4835     --
4836     -- If we have hours and minutes
4837     --
4838     ELSIF(v_days < 1 AND v_hours > 1 AND v_minutes > 1) THEN
4839       fnd_message.clear;
4840       fnd_message.set_name('PON','PON_HOURS_MINUTES'||v_opens_in_suffix);
4841       fnd_message.set_token('NUM_HOURS',v_hours);
4842       fnd_message.set_token('NUM_MINUTES',v_minutes);
4843       v_time_left := fnd_message.get;
4844     --
4845     -- If we have one day
4846     --
4847     ELSIF(v_days = 1 AND v_hours < 1) THEN
4848       v_time_left := fnd_message.get_string('PON','PON_DAY'||v_opens_in_suffix);
4849     --
4850     -- If we have one day and one hour
4851     --
4852     ELSIF(v_days = 1 AND v_hours = 1) THEN
4853       v_time_left := fnd_message.get_string('PON','PON_DAY_HOUR'||v_opens_in_suffix);
4854     --
4855     -- If we have one day and hours
4856     --
4857     ELSIF(v_days = 1 AND v_hours > 1) THEN
4858       fnd_message.clear;
4859       fnd_message.set_name('PON','PON_DAY_HOURS'||v_opens_in_suffix);
4860       fnd_message.set_token('NUM_HOURS',v_hours);
4861       v_time_left := fnd_message.get;
4862     --
4863     -- If we have days
4864     --
4865     ELSIF(v_days > 1 AND v_hours < 1) THEN
4866       fnd_message.clear;
4867       fnd_message.set_name('PON','PON_DAYS'||v_opens_in_suffix);
4868       fnd_message.set_token('NUM_DAYS',v_days);
4869       v_time_left := fnd_message.get;
4870     --
4871     -- If we have days and one hour
4872     --
4873     ELSIF(v_days > 1 AND v_hours = 1) THEN
4874       fnd_message.clear;
4875       fnd_message.set_name('PON','PON_DAYS_HOUR'||v_opens_in_suffix);
4876       fnd_message.set_token('NUM_DAYS',v_days);
4877       v_time_left := fnd_message.get;
4878     --
4879     -- If we have days and hours
4880     --
4881     ELSIF(v_days > 1 AND v_hours > 1) THEN
4882       fnd_message.clear;
4883       fnd_message.set_name('PON','PON_DAYS_HOURS'||v_opens_in_suffix);
4884       fnd_message.set_token('NUM_DAYS',v_days);
4885       fnd_message.set_token('NUM_HOURS',v_hours);
4886       v_time_left := fnd_message.get;
4887    END IF;
4888    --
4889    -- Return the time left
4890    --
4891    RETURN v_time_left;
4892 
4893 END;
4894 
4895 
4896 
4897 PROCEDURE AUCTION_OPEN(   itemtype  IN VARCHAR2,
4898         itemkey    IN VARCHAR2,
4899                                 actid           IN NUMBER,
4900                                 uncmode          IN VARCHAR2,
4901                                 resultout       OUT NOCOPY VARCHAR2) IS
4902 
4903 x_auction_header_id  NUMBER;
4904 x_progress    VARCHAR2(3);
4905 
4906 BEGIN
4907 
4908     x_progress := '010';
4909 
4910     x_auction_header_id := wf_engine.GetItemAttrNumber (itemtype => itemtype,
4911                                                       itemkey  => itemkey,
4912                                                      aname    => 'AUCTION_ID');
4913 
4914     x_progress := '020';
4915 
4916     update pon_auction_headers_all
4917     set    auction_status = 'OPEN_FOR_BIDDING',
4918      auction_status_name = (select meaning from fnd_lookups
4919           where lookup_type = 'PON_AUCTION_STATUS' and
4920           lookup_code = 'OPEN_FOR_BIDDING')
4921     where auction_header_id = x_auction_header_id;
4922 
4923 
4924     x_progress := '030';
4925 
4926 END AUCTION_OPEN;
4927 
4928 PROCEDURE AUCTION_CLOSED(   itemtype  IN VARCHAR2,
4929         itemkey    IN VARCHAR2,
4930                                 actid           IN NUMBER,
4931                                 uncmode          IN VARCHAR2,
4932                                 resultout       OUT NOCOPY VARCHAR2) IS
4933 x_auction_header_id  NUMBER;
4934 x_progress    VARCHAR2(3);
4935 
4936 BEGIN
4937 
4938     x_progress := '010';
4939 
4940     x_auction_header_id := wf_engine.GetItemAttrNumber (itemtype => itemtype,
4941                                                       itemkey  => itemkey,
4942                                                      aname    => 'AUCTION_ID');
4943 
4944     x_progress := '020';
4945 
4946     update pon_auction_headers_all
4947     set    auction_status = 'CLOSED_FOR_BIDDING',
4948      auction_status_name = (select meaning from fnd_lookups
4949           where lookup_type = 'PON_AUCTION_STATUS' and
4950           lookup_code = 'CLOSED_FOR_BIDDING')
4951     where auction_header_id = x_auction_header_id;
4952 
4953 
4954     x_progress := '030';
4955 
4956 END AUCTION_CLOSED;
4957 
4958 
4959 
4960 ----------------------------------------------------------------
4961 -- getLookupMeaning returns the description of a lookup code
4962 -- in the language mentioaned as a parameter.
4963 -- PL/SQL equivalent of Lookups.getMeaning() (in services package)
4964 ----------------------------------------------------------------
4965 Function getLookupMeaning(lookupType in varchar2,
4966                           langCode   in varchar2,
4967                           lookupCode in varchar2) return varchar2 AS
4968 lookupMeaning varchar2(8000) :=  '';
4969 Begin
4970  begin
4971 if  nvl(lookupCode,'!') <> '!' then
4972 select meaning into lookupMeaning
4973 from fnd_lookup_values
4974 where lookup_type = lookupType and
4975       language    = langCode   and
4976       lookup_code = lookupCode;
4977 end if;
4978 end;
4979 return (lookupMeaning);
4980 End getLookupMeaning;
4981 
4982 ----------------------------------------------------------------
4983 -- GetPoTotal returns the sum of the extend amount for the lines
4984 -- including with this PO
4985 ----------------------------------------------------------------
4986 Function GetPOTotal( p_po_id    IN number) return Number AS
4987 x_amount number;
4988 cursor c1(p_po_id number) is
4989 select sum(AWARD_QUANTITY * BID_CURRENCY_PRICE)
4990 from pon_bid_item_prices
4991 where bid_number = p_po_id
4992 and award_status = 'AWARDED';
4993 Begin
4994  begin
4995     open c1(p_po_id);
4996     fetch c1
4997        into x_amount;
4998     close c1;
4999  exception When others then
5000    x_amount := 0;
5001  end;
5002  return(x_amount);
5003 End GetPOTotal;
5004 
5005 ----------------------------------------------------------------
5006 -- Replace HTML entity characters to actual characters    --
5007 -- This is required to pass proper string to workflow
5008 -- Example : <amp>quot;Test<amp>quit; is converted to "Test"
5009 ----------------------------------------------------------------
5010 function replaceHtmlChars(html_in varchar2) return varchar2 is
5011 html_out1 varchar2(4000);
5012 html_out2 varchar2(4000);
5013 html_out3 varchar2(4000);
5014 begin
5015 html_out1 := replace(html_in,concat(fnd_global.local_chr(38),'quot;'),fnd_global.local_chr(34));
5016 html_out2 := replace(html_out1,concat(fnd_global.local_chr(38),'lt;'),fnd_global.local_chr(60));
5017 html_out3 := replace(html_out2,concat(fnd_global.local_chr(38),'gt;'),fnd_global.local_chr(62));
5018 return(html_out3);
5019 end;
5020 
5021 
5022 ----------------------------------------------------------------
5023 -- Tells if a particular auction is part of an event using    --
5024 -- the auction id                                             --
5025 ----------------------------------------------------------------
5026 PROCEDURE EVENT_AUCTION    (itemtype    in varchar2,
5027                  itemkey    in varchar2,
5028                             actid           in number,
5029                             uncmode    in varchar2,
5030                             resultout       out NOCOPY varchar2) IS
5031 
5032 x_auction_number  NUMBER;
5033 
5034 BEGIN
5035 
5036     x_auction_number := wf_engine.GetItemAttrNumber (itemtype => itemtype,
5037                                                         itemkey  => itemkey,
5038                                                        aname    => 'AUCTION_NUMBER');
5039 
5040 
5041     resultout := is_event_auction(x_auction_number);
5042 END;
5043 
5044 ----------------------------------------------------------------
5045 -- Tells if a particular auction is part of an event using    --
5046 -- the auction id                                             --
5047 ----------------------------------------------------------------
5048 PROCEDURE EVENT_AUCTION_ID(itemtype    in varchar2,
5049          itemkey    in varchar2,
5050          actid           in number,
5051          uncmode    in varchar2,
5052          resultout       out NOCOPY varchar2) IS
5053 
5054 x_auction_number  NUMBER;
5055 
5056 BEGIN
5057 
5058     x_auction_number := wf_engine.GetItemAttrNumber (itemtype => itemtype,
5059                  itemkey  => itemkey,
5060                  aname    => 'AUCTION_ID');
5061 
5062     resultout := is_event_auction(x_auction_number);
5063 END;
5064 
5065 ----------------------------------------------------------------
5066 -- Local function which returns a flag 'Y' if an auction is   --
5067 -- part of an event and 'N' if it is not                      --
5068 ----------------------------------------------------------------
5069 FUNCTION IS_EVENT_AUCTION (p_auction_number IN NUMBER) RETURN VARCHAR2 AS
5070 
5071 x_flag       VARCHAR2(1);
5072 
5073 BEGIN
5074    BEGIN
5075       select 'Y'
5076   into x_flag
5077   from pon_auction_headers_all
5078   where auction_header_id = p_auction_number
5079   and   event_id is not null;
5080    EXCEPTION
5081       WHEN NO_DATA_FOUND THEN
5082    x_flag := 'N';
5083    END;
5084 
5085    return(x_flag);
5086 END;
5087 
5088 
5089 ----------------------------------------------------------------
5090 -- Tells if the cancel reason is empty                        --
5091 ----------------------------------------------------------------
5092 PROCEDURE EMPTY_CANCEL_REASON(itemtype    in varchar2,
5093             itemkey    in varchar2,
5094             actid           in number,
5095             uncmode    in varchar2,
5096             resultout       out NOCOPY varchar2) IS
5097 
5098 x_cancel_reason PON_ACTION_HISTORY.ACTION_NOTE%TYPE;
5099 
5100 BEGIN
5101 
5102     x_cancel_reason := wf_engine.GetItemAttrText (itemtype => itemtype,
5103               itemkey  => itemkey,
5104               aname    => 'CANCEL_REASON');
5105 
5106 
5107     resultout := empty_reason(x_cancel_reason);
5108 END;
5109 
5110 ----------------------------------------------------------------
5111 -- Tells if the auction close date changed reason is empty                      --
5112 ----------------------------------------------------------------
5113 PROCEDURE EMPTY_CLOSECHANGED_REASON(itemtype          in varchar2,
5114                               itemkey           in varchar2,
5115                               actid             in number,
5116                               uncmode           in varchar2,
5117                               resultout         out NOCOPY varchar2) IS
5118 
5119 x_closechanged_reason VARCHAR2(2000);
5120 
5121 BEGIN
5122 
5123     x_closechanged_reason := wf_engine.GetItemAttrText (itemtype => itemtype,
5124                                             itemkey  => itemkey,
5125                                             aname    => 'CLOSECHANGED_REASON');
5126 
5127     resultout := empty_reason(x_closechanged_reason);
5128 END;
5129 
5130 ----------------------------------------------------------------
5131 -- Tells if the disqualify reason is empty                    --
5132 ----------------------------------------------------------------
5133 PROCEDURE EMPTY_DISQUALIFY_REASON(itemtype    in varchar2,
5134           itemkey    in varchar2,
5135           actid           in number,
5136           uncmode    in varchar2,
5137           resultout       out NOCOPY varchar2) IS
5138 
5139 x_disqualify_reason VARCHAR2(2000);
5140 
5141 BEGIN
5142 
5143     x_disqualify_reason := wf_engine.GetItemAttrText (itemtype => itemtype,
5144                   itemkey  => itemkey,
5145                   aname    => 'DISQUALIFY_REASON');
5146 
5147 
5148     resultout := empty_reason(x_disqualify_reason);
5149 END;
5150 
5151 ----------------------------------------------------------------
5152 -- Local function which returns a flag 'Y' if a string is     --
5153 -- empty and 'N' if it not                                    --
5154 ----------------------------------------------------------------
5155 FUNCTION EMPTY_REASON(p_reason IN VARCHAR2) RETURN VARCHAR2 AS
5156 
5157 x_flag  VARCHAR2(1) := 'Y';
5158 
5159 BEGIN
5160 
5161    IF(p_reason IS NOT NULL) THEN
5162       x_flag := 'N';
5163    END IF;
5164 
5165    return(x_flag);
5166 END;
5167 
5168 ----------------------------------------------------------------
5169 -- Procedure to call to end an auction workflow.              --
5170 -- Once called, no more notifications for the auction can be  --
5171 -- sent.  Has the same effect as canceling an auction         --
5172 ----------------------------------------------------------------
5173 PROCEDURE COMPLETE_AUCTION(p_auction_header_id  IN NUMBER) IS
5174 
5175 x_now    DATE;
5176 x_itemtype   VARCHAR2(7) := 'PONAUCT';
5177 x_itemkey  VARCHAR2(30);
5178 x_notification_date  DATE;
5179 x_current_activity VARCHAR2(30);
5180 
5181 BEGIN
5182    --
5183    -- Get the workflow item key and the current time so that we
5184    -- can complete the workflow
5185    --
5186    select wf_item_key, sysdate
5187      into x_itemkey, x_now
5188      from pon_auction_headers_all
5189      where auction_header_id = p_auction_header_id;
5190 
5191    --
5192    -- First, see what activity (if any) the workflow is on
5193    -- If none, then return.  Workflow has already completed??
5194    --
5195    BEGIN
5196       select activity_label
5197   into x_current_activity
5198   from wf_item_activity_statuses_v
5199   where item_type = x_itemtype
5200   AND item_key = x_itemkey
5201   and activity_status_code = 'NOTIFIED';
5202    EXCEPTION WHEN no_data_found THEN
5203      RETURN;
5204    END;
5205 
5206    --
5207    -- Otherwise we have an active workflow, so go ahead and complete it
5208    --
5209    -- Get the notification date from the workflow
5210    --
5211    x_notification_date := wf_engine.GetItemAttrDate (itemtype => x_itemtype,
5212                  itemkey  => x_itemkey,
5213                  aname    => 'AUCTION_NOTIFICATION_DATE');
5214 
5215    --
5216    -- Only complete the workflow if it is in a 'completeable' state.
5217    -- That is, if we have passed the notification date for the auction.
5218    -- If we try and complete the auction before that, we will get a workflow
5219    -- exception.
5220    --
5221 
5222    IF(x_now > x_notification_date AND x_current_activity = 'WAIT_FOR_AUCTION_COMPLETE') THEN
5223       wf_engine.CompleteActivity(x_itemtype,x_itemkey,'WAIT_FOR_AUCTION_COMPLETE','PREPARER_COMPLETE');
5224    END IF;
5225 
5226 END;
5227 
5228 FUNCTION sub_token(msg IN OUT NOCOPY varchar2, msgdata IN varchar2)
5229   RETURN VARCHAR2
5230   IS
5231 
5232   TOK_NAM   varchar2(30);
5233   TOK_VAL   varchar2(2000);
5234   SRCH      varchar2(2000);
5235   FLAG      varchar2(1);
5236   POS       NUMBER;
5237   NEXTPOS   NUMBER;
5238   DATA_SIZE NUMBER;
5239   TSLATE    BOOLEAN;
5240 
5241 BEGIN
5242         POS := 1;
5243         DATA_SIZE := LENGTH(MSGDATA);
5244         while POS < DATA_SIZE loop
5245             FLAG := SUBSTR(MSGDATA, POS, 1);
5246             POS := POS + 2;
5247             /* Note that we are intentionally using chr(0) rather than */
5248             /* FND_GLOBAL.LOCAL_CHR() for a performance bug (982909) */
5249             NEXTPOS := INSTR(MSGDATA, chr(0), POS);
5250             TOK_NAM := SUBSTR(MSGDATA, POS, NEXTPOS - POS);
5251             POS := NEXTPOS + 1;
5252             NEXTPOS := INSTR(MSGDATA, chr(0), POS);
5253             TOK_VAL := SUBSTR(MSGDATA, POS, NEXTPOS - POS);
5254             POS := NEXTPOS + 1;
5255 
5256             SRCH := '&' || TOK_NAM;
5257             if (INSTR(MSG, SRCH) <> 0) then
5258                 MSG := substrb(REPLACE(MSG, SRCH, TOK_VAL),1,2000);
5259             else
5260                 /* try the uppercased version of the token name in case */
5261                 /* the caller is (wrongly) passing a mixed case token name */
5262                 /* Because now (July 99) all tokens in msg text should be */
5263                 /* uppercase. */
5264                 SRCH := '&' || UPPER(TOK_NAM);
5265                 if (INSTR(MSG, SRCH) <> 0) then
5266                    MSG := substrb(REPLACE(MSG, SRCH, TOK_VAL),1,2000);
5267                 else
5268                    MSG :=substrb(MSG||' ('||TOK_NAM||'='||TOK_VAL||')',1,2000);
5269               end if;
5270             end if;
5271         END LOOP;
5272         RETURN MSG;
5273 END sub_token;
5274 
5275 FUNCTION get_string(appin IN VARCHAR2,
5276         namein IN VARCHAR2,
5277         langin IN VARCHAR2)
5278   RETURN VARCHAR2
5279   IS
5280      MSG  varchar2(2000) := NULL;
5281      MSGDATA  varchar2(2000) := NULL;
5282 
5283 BEGIN
5284    /* In the PON_PROFILE_UTIL_PKG there is a three var input fn.*/
5285    MSG := PON_PROFILE_UTIL_PKG.get_string(appin,namein,langin);
5286    FOR i in 1 .. MsgTokens.COUNT LOOP
5287   MSGDATA := MSGDATA||'N'||chr(0)||MsgTokens(i)||chr(0)||MsgTokenValues(i)||chr(0);
5288    END LOOP;
5289    return sub_token(MSG, MSGDATA);
5290 
5291 END get_string;
5292 
5293 ----------------------------------------------------------------
5294 -- Procedure call to close an auction early                   --
5295 ----------------------------------------------------------------
5296 PROCEDURE CLOSEEARLY_AUCTION (p_auction_header_id   IN NUMBER,
5297                               p_new_close_date      IN DATE,
5298                               p_closeearly_reason   IN VARCHAR2) IS
5299 
5300 x_itemtype                VARCHAR2(7) := 'PONAUCT';
5301 x_itemkey                 VARCHAR2(30);
5302 x_current_activity        VARCHAR2(30);
5303 x_contact_id              NUMBER;
5304 x_timezone                VARCHAR2(80);
5305 x_oex_timezone            VARCHAR2(80);
5306 x_auctioneer_contact_id   NUMBER ;
5307 x_timezone_disp VARCHAR2(240);
5308 x_user_name         VARCHAR2(100);
5309 x_language_code     VARCHAR2(3);
5310 
5311 -------------------------------
5312 
5313 --select user_name, person_party_id
5314 --    into x_user_name, x_contact_id
5315 --    from fnd_user where person_party_id = x_auction_contact_id;
5316 --
5317 
5318 BEGIN
5319    --
5320    -- Get the workflow item key and the current time so that we
5321    -- can complete the workflow
5322    --
5323    select wf_item_key, trading_partner_contact_id
5324      into x_itemkey, x_contact_id
5325      from pon_auction_headers_all
5326      where auction_header_id = p_auction_header_id;
5327 
5328   BEGIN
5329     select user_name
5330     into x_user_name
5331     from fnd_user
5332     where  person_party_id = x_contact_id
5333     and nvl(end_date, sysdate+1) > sysdate;
5334   EXCEPTION
5335     WHEN TOO_MANY_ROWS THEN
5336          if (nvl(fnd_profile.value('AFLOG_ENABLED'),'N') = 'Y') then
5337                if (fnd_log.level_unexpected >= fnd_log.g_current_runtime_level) then
5338                          fnd_log.string(log_level => fnd_log.level_unexpected,
5339                                         module    => 'pon.plsql.pon_auction_pkg.closeearly_auction',
5340                                         message   => 'Multiple Users found for person_party_id:'|| x_contact_id);
5341                end if;
5342          end if;
5343 
5344          select user_name
5345          into x_user_name
5346          from fnd_user
5347          where person_party_id = x_contact_id
5348          and nvl(end_date, sysdate+1) > sysdate
5349          and rownum=1;
5350 
5351   END;
5352           IF x_user_name is not null THEN
5353        PON_PROFILE_UTIL_PKG.GET_WF_LANGUAGE(x_user_name,x_language_code);
5354     END IF;
5355 
5356 
5357    --
5358    -- First, see what activity (if any) the workflow is on
5359    -- If none, then return.  Workflow has already completed??
5360    --
5361    BEGIN
5362       select activity_label
5363         into x_current_activity
5364         from wf_item_activity_statuses_v
5365         where item_type = x_itemtype
5366         AND item_key = x_itemkey
5367         and activity_status_code = 'NOTIFIED';
5368    EXCEPTION WHEN no_data_found THEN
5369      RETURN;
5370    END;
5371 
5372    --
5373    -- Get the exchange's time zone
5374    --
5375 
5376 
5377    --
5378    -- Set the auction end date
5379    --
5380    wf_engine.SetItemAttrDate (itemtype   => x_itemtype,
5381                               itemkey    => x_itemkey,
5382                               aname      => 'AUCTION_END_DATE',
5383                               avalue     => p_new_close_date);
5384 
5385 
5386    wf_engine.SetItemAttrText(itemtype => x_itemtype,
5387                              itemkey  => x_itemkey,
5388                              aname    => 'CLOSECHANGED_REASON',
5389                              avalue   => replaceHtmlChars(p_closeearly_reason));
5390 
5391 
5392    complete_prev_suppl_notifs(p_auction_header_id);
5393 
5394    --
5395    -- Complete the workflow with a close early action.
5396    -- This should either be
5397    --   1) Waiting for the start of the auction
5398    --   2) Pre  6.1 - waiting for the end of the auction
5399    --      Post 6.1 - waiting for user to complete the auction
5400    --
5401    wf_engine.CompleteActivity(x_itemtype,x_itemkey,x_current_activity,'PREPARER_CLOSEEARLY');
5402 
5403 END;
5404 
5405 
5406 
5407 ----------------------------------------------------------------
5408 -- Procedure call to extend or shorten an auction             --
5409 ----------------------------------------------------------------
5410 PROCEDURE CLOSECHANGED_AUCTION (p_auction_header_id   IN NUMBER,
5411                                 p_change_type         IN NUMBER,
5412                                 p_new_close_date      IN DATE,
5413                                 p_closechanged_reason   IN VARCHAR2) IS
5414 
5415 x_itemtype                VARCHAR2(7) := 'PONAUCT';
5416 x_itemkey                 VARCHAR2(30);
5417 x_current_activity        VARCHAR2(30);
5418 x_contact_id              NUMBER;
5419 x_timezone                VARCHAR2(80);
5420 x_oex_timezone            VARCHAR2(80);
5421 x_auctioneer_contact_id   NUMBER;
5422 x_timezone_disp VARCHAR2(240);
5423 x_user_name         VARCHAR2(100);
5424 x_language_code     VARCHAR2(3);
5425 
5426 
5427 
5428 
5429 
5430 BEGIN
5431    --
5432    -- Get the workflow item key and the current time so that we
5433    -- can complete the workflow
5434    --
5435 
5436    select wf_item_key, trading_partner_contact_id
5437      into x_itemkey, x_contact_id
5438      from pon_auction_headers_all
5439      where auction_header_id = p_auction_header_id;
5440 
5441    BEGIN
5442      select user_name
5443      into x_user_name
5444      from fnd_user
5445      where  person_party_id = x_contact_id
5446      and nvl(end_date, sysdate+1) > sysdate;
5447    EXCEPTION
5448     WHEN TOO_MANY_ROWS THEN
5449           if (nvl(fnd_profile.value('AFLOG_ENABLED'),'N') = 'Y') then
5450                if (fnd_log.level_unexpected >= fnd_log.g_current_runtime_level) then
5451                          fnd_log.string(log_level => fnd_log.level_unexpected,
5452                                         module    => 'pon.plsql.pon_auction_pkg.closechanged_auction',
5453                                         message   => 'Multiple Users found for person_party_id:'|| x_contact_id);
5454                end if;
5455          end if;
5456 
5457          select user_name
5458          into x_user_name
5459          from fnd_user
5460          where person_party_id = x_contact_id
5461          and nvl(end_date, sysdate+1) > sysdate
5462          and rownum=1;
5463 
5464    END;
5465           IF x_user_name is not null THEN
5466        PON_PROFILE_UTIL_PKG.GET_WF_LANGUAGE(x_user_name,x_language_code);
5467     END IF;
5468 
5469    --
5470    -- First, see what activity (if any) the workflow is on
5471    -- If none, then return.  Workflow has already completed??
5472    --
5473    BEGIN
5474       select activity_label
5475         into x_current_activity
5476         from wf_item_activity_statuses_v
5477         where item_type = x_itemtype
5478         AND item_key = x_itemkey
5479         and activity_status_code = 'NOTIFIED';
5480    EXCEPTION WHEN no_data_found THEN
5481         RETURN;
5482    END;
5483 
5484    --
5485    -- Set the auction end date
5486    --
5487    wf_engine.SetItemAttrDate (itemtype   => x_itemtype,
5488                               itemkey    => x_itemkey,
5489                               aname      => 'AUCTION_END_DATE',
5490                               avalue     => p_new_close_date);
5491 
5492 begin
5493 
5494    wf_engine.SetItemAttrNumber (itemtype   => x_itemtype,
5495                               itemkey    => x_itemkey,
5496                               aname      => 'CHANGE_TYPE',
5497                               avalue     => p_change_type);
5498 
5499 exception
5500    when others then
5501       null; -- for auctions created before version 115.20 of ponwfau1.wft this attribute did not exist
5502 end;
5503 
5504   IF p_closechanged_reason IS NOT NULL THEN
5505     wf_engine.SetItemAttrText (itemtype   => x_itemtype,
5506                                itemkey    => x_itemkey,
5507              aname      => 'CLOSECHANGED_REASON',
5508              avalue     => replaceHtmlChars(p_closechanged_reason));
5509   END IF;
5510 
5511    --
5512    -- Complete the workflow with a close early action.
5513    -- This should either be
5514    --   1) Waiting for the start of the auction
5515    --   2) Pre  6.1 - waiting for the end of the auction
5516    --      Post 6.1 - waiting for user to complete the auction
5517    --
5518    wf_engine.CompleteActivity(x_itemtype,x_itemkey,x_current_activity,'PREPARER_CLOSECHANGED');
5519 
5520 
5521 
5522 
5523 END;
5524 
5525 
5526 ----------------------------------------------------------------
5527 -- Function which returns EVENT_TITLE if an auction is   --
5528 -- part of an event and '' if it is not                 --
5529 ----------------------------------------------------------------
5530 FUNCTION getEventTitle (p_auction_number IN NUMBER) RETURN VARCHAR2 AS
5531 
5532 eventTitle    VARCHAR2(80);
5533 
5534 BEGIN
5535    BEGIN
5536       select event.event_title
5537  into eventTitle
5538  from pon_auction_headers_all ah,pon_auction_events event
5539  where auction_header_id = p_auction_number
5540  and  ah.event_id=event.event_id;
5541    EXCEPTION
5542       WHEN NO_DATA_FOUND THEN
5543  eventTitle := '';
5544    END;
5545 
5546    return(eventTitle);
5547 END;
5548 
5549 --
5550 -- Retrieves message for the specific document type based on the msg_suffix (_B, _R etc.)
5551 --
5552 
5553 FUNCTION getMessage (msg VARCHAR2) RETURN VARCHAR2 AS
5554 message VARCHAR2(2000);
5555 BEGIN
5556    BEGIN
5557 
5558         -- In ERP only three arguements.
5559   --message := PON_PROFILE_UTIL_PKG.GET_STRING(PON_AUCTION_PKG.OperationId, 'PON', msg, PON_AUCTION_PKG.SessionLanguage);
5560   message := PON_PROFILE_UTIL_PKG.GET_STRING('PON', msg, PON_AUCTION_PKG.SessionLanguage);
5561 
5562   if (message is null) then
5563     message := fnd_message.get_string('PON', msg);
5564   end if;
5565 
5566    EXCEPTION
5567       WHEN others THEN
5568       message := null;
5569    END;
5570 
5571    if (message is null) then
5572   message := msg;
5573    end if;
5574 
5575    return(message);
5576 END;
5577 
5578 --
5579 -- Retrieves tokenized message for the specific document type based on the msg_suffix (_B, _R etc.)
5580 --
5581 
5582 FUNCTION getMessage (msg VARCHAR2, msg_suffix VARCHAR2) RETURN VARCHAR2 AS
5583 message VARCHAR2(2000);
5584 BEGIN
5585     message := getMessage(substrb(msg,1,28)||msg_suffix);
5586    if ( message = substrb(msg,1,28)||msg_suffix) then
5587       return getMessage (msg);
5588    else
5589       return(message);
5590    end if;
5591 
5592 END;
5593 
5594 --
5595 -- Retrieves tokenized message for the specific document type based on the msg_suffix (_B, _R etc.)
5596 --
5597 
5598 FUNCTION getMessage (msg VARCHAR2, msg_suffix VARCHAR2, token VARCHAR2, token_value VARCHAR2) RETURN VARCHAR2 AS
5599    message VARCHAR2(2000);
5600    application_code VARCHAR2(5) := 'PON';
5601    ind NUMBER := 1;
5602 BEGIN
5603 
5604    MsgTokens.DELETE;
5605    MsgTokenValues.DELETE;
5606    MsgTokens(ind) := token;
5607    MsgTokenValues(ind) := token_value;
5608 
5609    message := getMessage(substrb(msg,1,28)||msg_suffix);
5610    if ( message = substrb(msg,1,28)||msg_suffix) then
5611       return getTokenMessage(msg);
5612    else
5613       return getTokenMessage(substrb(msg,1,28)||msg_suffix);
5614    end if;
5615 END;
5616 
5617 
5618 FUNCTION getTokenMessage (msg VARCHAR2) RETURN
5619  VARCHAR2 AS
5620    message VARCHAR2(1000);
5621    application_code VARCHAR2(5) := 'PON';
5622 BEGIN
5623    BEGIN
5624       message := GET_STRING('PON', msg, PON_AUCTION_PKG.SessionLanguage);
5625    EXCEPTION
5626       WHEN others THEN
5627       message := null;
5628    END;
5629 
5630    if (message is null) then
5631       return msg;
5632    else
5633       return(message);
5634    end if;
5635 END;
5636 
5637 FUNCTION getMessage (msg VARCHAR2, msg_suffix VARCHAR2, token1 VARCHAR2,
5638       token1_value VARCHAR2, token2 VARCHAR2, token2_value VARCHAR2) RETURN VARCHAR2 AS
5639    message VARCHAR2(2000);
5640    application_code VARCHAR2(5) := 'PON';
5641    ind NUMBER := 1;
5642 BEGIN
5643    message := getMessage(substrb(msg,1,28)||msg_suffix);
5644 
5645    MsgTokens.DELETE;
5646    MsgTokenValues.DELETE;
5647    MsgTokens(ind) := token1;
5648    MsgTokenValues(ind) := token1_value;
5649    MsgTokens(ind+1) := token2;
5650    MsgTokenValues(ind+1) := token2_value;
5651 
5652    if ( message = substrb(msg,1,28)||msg_suffix) then
5653       return getTokenMessage(msg);
5654    else
5655       return getTokenMessage(substrb(msg,1,28)||msg_suffix);
5656    end if;
5657 END;
5658 
5659 FUNCTION getMessage (msg VARCHAR2, msg_suffix VARCHAR2, token1 VARCHAR2, token1_value VARCHAR2,
5660          token2 VARCHAR2, token2_value VARCHAR2, token3 VARCHAR2,
5661          token3_value VARCHAR2) RETURN VARCHAR2 AS
5662    message VARCHAR2(2000);
5663    application_code VARCHAR2(5) := 'PON';
5664    ind NUMBER := 1;
5665 BEGIN
5666    message := getMessage(substrb(msg,1,28)||msg_suffix);
5667 
5668    MsgTokens.DELETE;
5669    MsgTokenValues.DELETE;
5670    MsgTokens(ind) := token1;
5671    MsgTokenValues(ind) := token1_value;
5672    MsgTokens(ind+1) := token2;
5673    MsgTokenValues(ind+1) := token2_value;
5674    MsgTokens(ind+2) := token3;
5675    MsgTokenValues(ind+2) := token3_value;
5676 
5677    if ( message = substrb(msg,1,28)||msg_suffix) then
5678       return getTokenMessage(msg);
5679    else
5680       return getTokenMessage(substrb(msg,1,28)||msg_suffix);
5681    end if;
5682 END;
5683 
5684 FUNCTION getMessage (msg VARCHAR2, msg_suffix VARCHAR2, token1 VARCHAR2, token1_value VARCHAR2,
5685          token2 VARCHAR2, token2_value VARCHAR2, token3 VARCHAR2, token3_value VARCHAR2,
5686          token4 VARCHAR2, token4_value VARCHAR2) RETURN VARCHAR2 AS
5687    message VARCHAR2(2000);
5688    application_code VARCHAR2(5) := 'PON';
5689    ind NUMBER := 1;
5690 BEGIN
5691    message := getMessage(substrb(msg,1,28)||msg_suffix);
5692 
5693    MsgTokens.DELETE;
5694    MsgTokenValues.DELETE;
5695    MsgTokens(ind) := token1;
5696    MsgTokenValues(ind) := token1_value;
5697    MsgTokens(ind+1) := token2;
5698    MsgTokenValues(ind+1) := token2_value;
5699    MsgTokens(ind+2) := token3;
5700    MsgTokenValues(ind+2) := token3_value;
5701    MsgTokens(ind+3) := token4;
5702    MsgTokenValues(ind+3) := token4_value;
5703 
5704    if ( message = substrb(msg,1,28)||msg_suffix) then
5705       return getTokenMessage(msg);
5706    else
5707       return getTokenMessage(substrb(msg,1,28)||msg_suffix);
5708    end if;
5709 END;
5710 
5711 FUNCTION getMessage (msg VARCHAR2, msg_suffix VARCHAR2, token1 VARCHAR2, token1_value VARCHAR2,
5712          token2 VARCHAR2, token2_value VARCHAR2, token3 VARCHAR2, token3_value VARCHAR2,
5713          token4 VARCHAR2, token4_value VARCHAR2, token5 VARCHAR2, token5_value VARCHAR2) RETURN VARCHAR2 AS
5714    message VARCHAR2(2000);
5715    application_code VARCHAR2(5) := 'PON';
5716    ind NUMBER := 1;
5717 BEGIN
5718    message := getMessage(substrb(msg,1,28)||msg_suffix);
5719 
5720    MsgTokens.DELETE;
5721    MsgTokenValues.DELETE;
5722    MsgTokens(ind) := token1;
5723    MsgTokenValues(ind) := token1_value;
5724    MsgTokens(ind+1) := token2;
5725    MsgTokenValues(ind+1) := token2_value;
5726    MsgTokens(ind+2) := token3;
5727    MsgTokenValues(ind+2) := token3_value;
5728    MsgTokens(ind+3) := token4;
5729    MsgTokenValues(ind+3) := token4_value;
5730    MsgTokens(ind+4) := token5;
5731    MsgTokenValues(ind+4) := token5_value;
5732 
5733    if ( message = substrb(msg,1,28)||msg_suffix) then
5734       return getTokenMessage(msg);
5735    else
5736       return getTokenMessage(substrb(msg,1,28)||msg_suffix);
5737    end if;
5738 END;
5739 
5740 FUNCTION GET_MESSAGE_SUFFIX (x_doctype_group_name VARCHAR2) RETURN VARCHAR2 AS
5741 
5742 x_msg_suffix PON_AUC_DOCTYPES.MESSAGE_SUFFIX%TYPE := '';
5743 
5744 BEGIN
5745    BEGIN
5746       SELECT message_suffix
5747       INTO x_msg_suffix
5748       FROM pon_auc_doctypes
5749       WHERE doctype_group_name = x_doctype_group_name;
5750    EXCEPTION WHEN NO_DATA_FOUND THEN
5751       x_msg_suffix := '';
5752    END;
5753    IF(x_msg_suffix IS null) THEN
5754       RETURN '';
5755    ELSE
5756       RETURN ('_'||x_msg_suffix);
5757    END IF;
5758 END;
5759 
5760 FUNCTION GET_TRANSACTION_TYPE (p_doctype_group_name PON_AUC_DOCTYPES.INTERNAL_NAME%TYPE)
5761   RETURN PON_AUC_DOCTYPES.TRANSACTION_TYPE%TYPE AS
5762 
5763 x_trans_type PON_AUC_DOCTYPES.TRANSACTION_TYPE%TYPE;
5764 
5765 BEGIN
5766    BEGIN
5767       SELECT transaction_type
5768       INTO x_trans_type
5769       FROM pon_auc_doctypes
5770       WHERE doctype_group_name = p_doctype_group_name;
5771    EXCEPTION WHEN NO_DATA_FOUND THEN
5772       x_trans_type := '';
5773    END;
5774    return x_trans_type;
5775 END;
5776 
5777 
5778 --
5779 -- must provide at least one of the two arguments. both cannot be null.
5780 --
5781 
5782 PROCEDURE SET_SESSION_LANGUAGE(p_language VARCHAR2, p_language_code VARCHAR2) is
5783 
5784   x_language_code VARCHAR2(60);
5785   x_language VARCHAR2(60);
5786 BEGIN
5787      IF (FND_LOG.level_statement >= FND_LOG.g_current_runtime_level) THEN --{
5788        FND_LOG.string(log_level => FND_LOG.level_statement,
5789          module => g_module_prefix || 'SET_SESSION_LANGUAGE',
5790          message  => 'Entered procedure : p_language_code ' || p_language_code);
5791      END IF; --}
5792 
5793      g_original_lang_code := fnd_global.current_language;
5794 
5795      IF (FND_LOG.level_statement >= FND_LOG.g_current_runtime_level) THEN --{
5796         FND_LOG.string(log_level => FND_LOG.level_statement,
5797           module => g_module_prefix || 'SET_SESSION_LANGUAGE',
5798           message  => 'g_original_lang_code ' || g_original_lang_code);
5799      END IF; --}
5800 
5801    if (g_original_lang_code  is not null) then
5802 
5803            IF (FND_LOG.level_statement >= FND_LOG.g_current_runtime_level) THEN --{
5804             FND_LOG.string(log_level => FND_LOG.level_statement,
5805                module => g_module_prefix || 'SET_SESSION_LANGUAGE',
5806                message  => 'g_original_lang_code is not null so selecting g_original_language from the DB ');
5807            END IF; --}
5808 
5809          select nls_language
5810          into g_original_language
5811          from fnd_languages
5812          where language_code = g_original_lang_code;
5813 
5814            IF (FND_LOG.level_statement >= FND_LOG.g_current_runtime_level) THEN --{
5815             FND_LOG.string(log_level => FND_LOG.level_statement,
5816               module => g_module_prefix || 'SET_SESSION_LANGUAGE',
5817               message  => 'g_original_lang_code is : ' || g_original_lang_code || ' after selecting it from the DB ');
5818            END IF; --}
5819 
5820 
5821    else
5822            IF (FND_LOG.level_statement >= FND_LOG.g_current_runtime_level) THEN --{
5823            FND_LOG.string(log_level => FND_LOG.level_statement,
5824              module => g_module_prefix || 'SET_SESSION_LANGUAGE',
5825              message  => 'g_original_lang_code is null, so defaulting the language to US');
5826            END IF; --}
5827 
5828           g_original_lang_code := 'US';
5829         g_original_language := 'AMERICAN';
5830 
5831      end if;
5832 
5833           begin
5834        IF (FND_LOG.level_statement >= FND_LOG.g_current_runtime_level) THEN --{
5835          FND_LOG.string(log_level => FND_LOG.level_statement,
5836            module => g_module_prefix || 'SET_SESSION_LANGUAGE',
5837            message  => 'p_language_code : ' || p_language_code);
5838          END IF; --}
5839 
5840     if (p_language_code is null) then
5841 
5842          IF (FND_LOG.level_statement >= FND_LOG.g_current_runtime_level) THEN --{
5843                FND_LOG.string(log_level => FND_LOG.level_statement,
5844                  module => g_module_prefix || 'SET_SESSION_LANGUAGE',
5845                  message  => 'p_language_code is NULL so selecting it from fnd_language ');
5846          END IF; --}
5847 
5848       select language_code
5849       into x_language_code
5850       from fnd_languages
5851       where nls_language = p_language;
5852 
5853             IF (FND_LOG.level_statement >= FND_LOG.g_current_runtime_level) THEN --{
5854              FND_LOG.string(log_level => FND_LOG.level_statement,
5855                module => g_module_prefix || 'SET_SESSION_LANGUAGE',
5856                message  => 'x_language_code : ' || x_language_code);
5857             END IF; --}
5858 
5859     else
5860 
5861             IF (FND_LOG.level_statement >= FND_LOG.g_current_runtime_level) THEN --{
5862              FND_LOG.string(log_level => FND_LOG.level_statement,
5863                module => g_module_prefix || 'SET_SESSION_LANGUAGE',
5864                message  => 'p_language_code is NOT NULL so assigning it to x_language_code');
5865             END IF; --}
5866 
5867       x_language_code := p_language_code;
5868 
5869 
5870             IF (FND_LOG.level_statement >= FND_LOG.g_current_runtime_level) THEN --{
5871               FND_LOG.string(log_level => FND_LOG.level_statement,
5872                 module => g_module_prefix || 'SET_SESSION_LANGUAGE',
5873                 message  => 'x_language_code : ' || x_language_code);
5874             END IF; --}
5875     end if;
5876 
5877        IF (FND_LOG.level_statement >= FND_LOG.g_current_runtime_level) THEN --{
5878         FND_LOG.string(log_level => FND_LOG.level_statement,
5879           module => g_module_prefix || 'SET_SESSION_LANGUAGE',
5880           message  => 'p_language : ' || p_language);
5881         END IF; --}
5882 
5883     if (p_language is not null) then
5884 
5885            IF (FND_LOG.level_statement >= FND_LOG.g_current_runtime_level) THEN --{
5886               FND_LOG.string(log_level => FND_LOG.level_statement,
5887                 module => g_module_prefix || 'SET_SESSION_LANGUAGE',
5888                 message  => 'p_language is not NULL so calling the dbms_session.set_nls with p_language : '|| p_language);
5889            END IF; --}
5890 
5891        dbms_session.set_nls('NLS_LANGUAGE', p_language);
5892     else
5893 
5894            IF (FND_LOG.level_statement >= FND_LOG.g_current_runtime_level) THEN --{
5895              FND_LOG.string(log_level => FND_LOG.level_statement,
5896                module => g_module_prefix || 'SET_SESSION_LANGUAGE',
5897                message  => 'p_language is NULL so selecting it from fnd_languages');
5898            END IF; --}
5899 
5900       select nls_language
5901       into x_language
5902       from fnd_languages
5903       where language_code = x_language_code;
5904 
5905       dbms_session.set_nls('NLS_LANGUAGE', x_language);
5906 
5907             IF (FND_LOG.level_statement >= FND_LOG.g_current_runtime_level) THEN --{
5908              FND_LOG.string(log_level => FND_LOG.level_statement,
5909                module => g_module_prefix || 'SET_SESSION_LANGUAGE',
5910                message  => 'x_language : ' || x_language ||'; calling dbms_session.set_nls with x_language : '|| x_language);
5911             END IF; --}
5912 
5913     end if;
5914           exception
5915     when others then
5916 
5917           IF (FND_LOG.level_statement >= FND_LOG.g_current_runtime_level) THEN --{
5918               FND_LOG.string(log_level => FND_LOG.level_statement,
5919                 module => g_module_prefix || 'SET_SESSION_LANGUAGE',
5920                 message  => 'Exception when running the procedure; doing nothing');
5921           END IF; --}
5922 
5923     null;
5924           end;
5925 
5926         IF (FND_LOG.level_statement >= FND_LOG.g_current_runtime_level) THEN --{
5927             FND_LOG.string(log_level => FND_LOG.level_statement,
5928                 module => g_module_prefix || 'SET_SESSION_LANGUAGE',
5929                 message  => 'Setting PON_AUCTION_PKG.SessionLanguage to x_language_code : ' || x_language_code);
5930         END IF; --}
5931 
5932     -- set this package variable to be used with the get_message calls.
5933     PON_AUCTION_PKG.SessionLanguage := x_language_code;
5934 
5935         IF (FND_LOG.level_statement >= FND_LOG.g_current_runtime_level) THEN --{
5936             FND_LOG.string(log_level => FND_LOG.level_statement,
5937                module => g_module_prefix || 'SET_SESSION_LANGUAGE',
5938                message  => 'Setting PON_AUCTION_PKG.SessionLanguage : ' || PON_AUCTION_PKG.SessionLanguage);
5939         END IF; --}
5940 
5941 END;
5942 
5943 
5944 PROCEDURE UNSET_SESSION_LANGUAGE is
5945 BEGIN
5946         IF (FND_LOG.level_statement >= FND_LOG.g_current_runtime_level) THEN --{
5947             FND_LOG.string(log_level => FND_LOG.level_statement,
5948                 module => g_module_prefix || 'UNSET_SESSION_LANGUAGE',
5949                 message  => 'Entered the procedure; g_original_language : ' || g_original_language);
5950         END IF; --}
5951 
5952           begin
5953     --dbms_session.set_nls('NLS_LANGUAGE', 'AMERICAN');
5954         IF (FND_LOG.level_statement >= FND_LOG.g_current_runtime_level) THEN --{
5955             FND_LOG.string(log_level => FND_LOG.level_statement,
5956                 module => g_module_prefix || 'UNSET_SESSION_LANGUAGE',
5957                 message  => 'calling  dbms_session.set_nls with g_original_language : ' || g_original_language);
5958         END IF; --}
5959 
5960         dbms_session.set_nls('NLS_LANGUAGE', g_original_language);
5961           exception
5962     when others then
5963         IF (FND_LOG.level_statement >= FND_LOG.g_current_runtime_level) THEN --{
5964         FND_LOG.string(log_level => FND_LOG.level_statement,
5965           module => g_module_prefix || 'UNSET_SESSION_LANGUAGE',
5966           message  => 'Exception when running the procedure; doing nothing');
5967         END IF; --}
5968 
5969     null;
5970           end;
5971 
5972         IF (FND_LOG.level_statement >= FND_LOG.g_current_runtime_level) THEN --{
5973             FND_LOG.string(log_level => FND_LOG.level_statement,
5974                 module => g_module_prefix || 'UNSET_SESSION_LANGUAGE',
5975                 message  => 'Setting PON_AUCTION_PKG.SessionLanguage to g_original_lang_code : ' || g_original_lang_code);
5976         END IF; --}
5977     -- unset this package variable (used by the get_message calls).
5978    -- PON_AUCTION_PKG.SessionLanguage := 'US';
5979       PON_AUCTION_PKG.SessionLanguage := g_original_lang_code;
5980 
5981         IF (FND_LOG.level_statement >= FND_LOG.g_current_runtime_level) THEN --{
5982             FND_LOG.string(log_level => FND_LOG.level_statement,
5983                 module => g_module_prefix || 'UNSET_SESSION_LANGUAGE',
5984                 message  => 'Setting PON_AUCTION_PKG.SessionLanguage : ' || PON_AUCTION_PKG.SessionLanguage);
5985         END IF; --}
5986 
5987 END;
5988 
5989 
5990 PROCEDURE NOTIFY_BIDDERS_OF_CANCEL (itemtype    in varchar2,
5991             itemkey    in varchar2,
5992             actid           in number,
5993             uncmode    in varchar2,
5994             resultout       out NOCOPY varchar2)
5995 IS
5996    x_action_code varchar2(40) := 'CANCEL';
5997 BEGIN
5998 
5999   NOTIFY_BIDDERS_AUC_CHANGED(itemtype,
6000            itemkey,
6001            actid,
6002            uncmode,
6003            x_action_code);
6004 END;
6005 
6006 
6007 --
6008 -- Called to notify other bidders that a bid has been disqualified
6009 --
6010 
6011 PROCEDURE NOTIFY_OTHER_BIDDERS_OF_DISQ(itemtype    in varchar2,
6012                itemkey    in varchar2,
6013                actid           in number,
6014                uncmode    in varchar2,
6015                resultout       out NOCOPY varchar2)
6016 IS
6017         x_action_code varchar2(40) := 'DISQUALIFY_BID';
6018 BEGIN
6019 
6020   NOTIFY_BIDDERS_AUC_CHANGED(itemtype,
6021            itemkey,
6022            actid,
6023            uncmode,
6024            x_action_code);
6025 END;
6026 
6027 
6028 PROCEDURE NOTIFY_BIDDERS_AUC_CHANGED(itemtype    in varchar2,
6029              itemkey    in varchar2,
6030              actid           in number,
6031              uncmode    in varchar2,
6032              action_code    in varchar2)
6033 IS
6034 
6035    x_doc_number                  number;
6036    x_profile_user               VARCHAR2(240) := '';
6037    x_bidder_tp_name              PON_BIDDING_PARTIES.TRADING_PARTNER_NAME%TYPE;
6038    x_vendor_site_code            PON_BIDDING_PARTIES.VENDOR_SITE_CODE%TYPE;
6039    x_vendor_site_id              NUMBER;
6040    x_trading_partner_contact_id  PON_AUCTION_HEADERS_ALL.TRADING_PARTNER_CONTACT_ID%TYPE;
6041    x_wf_role_name                varchar2(100) := '';
6042    x_language_code               varchar2(30);
6043    x_message_name                varchar2(80);
6044    x_doc_number_dsp              varchar2(60);
6045    x_auction_title               PON_AUCTION_HEADERS_ALL.AUCTION_TITLE%TYPE;
6046    x_auction_start_date          date;
6047    x_auction_end_date            date;
6048    x_preview_date              DATE;
6049    x_timezone                    VARCHAR2(80);
6050    x_wf_item_key               VARCHAR2(240);
6051    x_change_type                 number; -- extend: 1, shorten: 2
6052    x_original_close_bidding_date PON_AUCTION_HEADERS_ALL.ORIGINAL_CLOSE_BIDDING_DATE%TYPE;
6053    x_event_title                 varchar2(240) := '';
6054    x_event_id                    NUMBER;
6055    x_bad_bidder                  varchar2(80) := null;
6056    x_tp_contact_name PON_AUCTION_HEADERS_ALL.TRADING_PARTNER_CONTACT_NAME%TYPE; -- Bug 3824928 added
6057    x_staggered_closing_interval  NUMBER;
6058 
6059 
6060     CURSOR bidders IS
6061       select wfu.user_name user_name, person_party_id
6062       from wf_user_roles wfu, fnd_user fnd
6063       where role_name = x_wf_role_name
6064       and fnd.user_name (+) =  wfu.user_name
6065       AND wfu.user_name NOT IN (SELECT wf_user_name FROM pon_bidding_parties
6066         WHERE auction_header_id = x_doc_number AND trading_partner_id IS NULL);
6067 
6068     CURSOR bidders_info IS
6069       select trading_partner_name, decode(vendor_site_code, '-1', null, vendor_site_code) vendor_site_code, nvl(vendor_site_id, -1) vendor_site_id
6070       from pon_bidding_parties
6071       where trading_partner_contact_id = x_trading_partner_contact_id
6072       and auction_header_id = x_doc_number
6073       union
6074       select trading_partner_name, decode(vendor_site_code, '-1', null, vendor_site_code) vendor_site_code, nvl(vendor_site_id, -1) vendor_site_id
6075       from pon_bid_headers
6076       where trading_partner_contact_id = x_trading_partner_contact_id
6077       and auction_header_id = x_doc_number;
6078 
6079 
6080 begin
6081 
6082       x_doc_number := wf_engine.GetItemAttrNumber (itemtype   => itemtype,
6083                                                    itemkey    => itemkey,
6084                                                    aname      => 'AUCTION_ID');
6085 
6086       x_doc_number_dsp := wf_engine.GetItemAttrText (itemtype   => itemtype,
6087                                                      itemkey    => itemkey,
6088                                                   aname      => 'DOC_NUMBER');
6089 
6090       x_auction_title := wf_engine.GetItemAttrText (itemtype   => itemtype,
6091                                                     itemkey    => itemkey,
6092                                                     aname      => 'AUCTION_TITLE');
6093 
6094       x_auction_start_date  := wf_engine.GetItemAttrDate (itemtype   => itemtype,
6095                                                           itemkey    => itemkey,
6096                                                           aname      => 'AUCTION_START_DATE');
6097 
6098       x_auction_end_date  := wf_engine.GetItemAttrDate (itemtype   => itemtype,
6099                                                         itemkey    => itemkey,
6100                                                         aname      => 'AUCTION_END_DATE');
6101 
6102       -- Bug 3824928: added below
6103 --      x_tp_contact_name := wf_engine.GetItemAttrText (itemtype => itemtype,
6104 --                                                         itemkey  => itemkey,
6105 --                                                         aname    => 'PREPARER_TP_CONTACT_NAME');
6106 
6107 
6108 
6109       x_preview_date := wf_engine.GetItemAttrDate (itemtype   => itemtype,
6110                                                    itemkey    => itemkey,
6111                                                    aname      => 'PREVIEW_DATE_TZ');
6112 
6113 
6114     begin
6115         select wf_role_name, wf_item_key, original_close_bidding_date, event_id, trading_partner_contact_name,
6116                staggered_closing_interval
6117         into  x_wf_role_name, x_wf_item_key, x_original_close_bidding_date, x_event_id, x_tp_contact_name,
6118               x_staggered_closing_interval
6119         from pon_auction_headers_all
6120         where auction_header_id = x_doc_number;
6121     exception
6122         when others then
6123         x_wf_role_name := '';
6124     end;
6125 
6126     if (x_wf_role_name = '') then
6127         return;
6128     end if;
6129 
6130     if (action_code is not null and action_code = 'CLOSEEARLY') then
6131         x_message_name := 'NEGOTIATION_CLOSED_EARLY';
6132     elsif (action_code = 'CLOSECHANGED') then
6133 
6134         begin
6135           x_change_type := wf_engine.GetItemAttrNumber (itemtype => itemtype,
6136                                         itemkey  => itemkey,
6137                                         aname => 'CHANGE_TYPE');
6138         exception
6139         when others then
6140           x_change_type := 1; -- for auctions created before version 115.20 of ponwfau1.wft this attribute did not exist
6141         end;
6142 
6143         -- auctioneer extends the auction
6144         if (x_change_type = 1) then
6145             x_message_name := 'NEGOTIATION_EXTENDED';
6146         -- auctioneer shortens the auction
6147         else
6148             x_message_name := 'NEGOTIATION_SHORTENED';
6149         end if;
6150     elsif (action_code = 'CANCEL') then
6151       IF (x_event_id is not null) THEN
6152           x_event_title := getEventTitle (x_doc_number);
6153           IF x_event_title IS NOT NULL THEN
6154              x_message_name := 'NEGOTIATION_CANCELED_EVENT';
6155           END IF;
6156       ELSE
6157           x_message_name := 'NEGOTIATION_CANCELED';
6158       END IF;
6159     elsif (action_code = 'DISQUALIFY_BID') then
6160         x_message_name := 'BID_DISQUALIFY_NOTIFY_OTHER';
6161 
6162     end if;
6163 
6164    FOR bidder IN bidders LOOP
6165 
6166       if (member_user(bidder.user_name)) then
6167 
6168          PON_PROFILE_UTIL_PKG.GET_WF_LANGUAGE(bidder.user_name,x_language_code);
6169          x_trading_partner_contact_id := bidder.person_party_id;
6170 
6171          -- Get the timezone for the user
6172          x_timezone := Get_Time_Zone(bidder.person_party_id);
6173 
6174          FOR bidder_info IN bidders_info LOOP
6175 
6176           x_bidder_tp_name := bidder_info.trading_partner_name;
6177           x_vendor_site_code := bidder_info.vendor_site_code;
6178           x_vendor_site_id := bidder_info.vendor_site_id;
6179 
6180           -- send a notification to bidders
6181           SEND_BIDDERS_NOTIFICATION(itemtype                   => itemtype,
6182                                  itemkey                       => itemkey,
6183                                  actid                         => actid,
6184                                  p_action_code                 => action_code,
6185                                  p_user                        => bidder.user_name,
6186                                  p_bidder_tp_name              => x_bidder_tp_name,
6187                                  p_vendor_site_code            => x_vendor_site_code,
6188                                  p_vendor_site_id              => x_vendor_site_id,
6189                                  p_message_name                => x_message_name,
6190                                  p_doc_number_dsp              => x_doc_number_dsp,
6191                                  p_auction_title               => x_auction_title,
6192                                  p_auction_start_date          => x_auction_start_date,
6193                                  p_auction_end_date            => x_auction_end_date,
6194                                  p_preview_date                => x_preview_date,
6195                                  p_language_code               => x_language_code,
6196                                  p_timezone                    => x_timezone,
6197                                  p_change_type                 => x_change_type,
6198                                  p_original_close_bidding_date => x_original_close_bidding_date,
6199                                  p_event_title                 => x_event_title,
6200                                  p_auc_tp_contact_name         => x_tp_contact_name,
6201                                  p_staggered_closing_interval  => x_staggered_closing_interval);
6202 
6203 
6204          END LOOP;
6205       elsif (additional_bidder(bidder.user_name, x_doc_number, x_tp_contact_name, x_profile_user)) then
6206          -- Bug 3824928: logic here will handle additional contact users
6207          -- associated to a trading partner contact id or not.
6208 
6209         PON_PROFILE_UTIL_PKG.GET_WF_LANGUAGE(x_profile_user,x_language_code);
6210 
6211        select trading_partner_name, decode(vendor_site_code, '-1', null, vendor_site_code) vendor_site_code, nvl(vendor_site_id, -1) vendor_site_id
6212        into x_bidder_tp_name, x_vendor_site_code, x_vendor_site_id
6213        from pon_bidding_parties
6214        where wf_user_name = bidder.user_name
6215        and auction_header_id = x_doc_number;
6216 
6217        -- Get the timezone for the user
6218        x_timezone := Get_Time_Zone(x_profile_user);
6219 
6220        -- send a notification to additional bidder contact
6221        SEND_BIDDERS_NOTIFICATION(itemtype                      => itemtype,
6222                                  itemkey                       => itemkey,
6223                                  actid                         => actid,
6224                                  p_action_code                 => action_code,
6225                                  p_user                        => bidder.user_name,
6226                                  p_bidder_tp_name              => x_bidder_tp_name,
6227                                  p_vendor_site_code            => x_vendor_site_code,
6228                                  p_vendor_site_id              => x_vendor_site_id,
6229                                  p_message_name                => x_message_name,
6230                                  p_doc_number_dsp              => x_doc_number_dsp,
6231                                  p_auction_title               => x_auction_title,
6232                                  p_auction_start_date          => x_auction_start_date,
6233                                  p_auction_end_date            => x_auction_end_date,
6234                                  p_preview_date                => x_preview_date,
6235                                  p_language_code               => x_language_code,
6236                                  p_timezone                    => x_timezone,
6237                                  p_change_type                 => x_change_type,
6238                                  p_original_close_bidding_date => x_original_close_bidding_date,
6239                                  p_event_title                 => x_event_title,
6240                                  p_auc_tp_contact_name         => x_tp_contact_name,
6241                                  p_staggered_closing_interval  => x_staggered_closing_interval);
6242 
6243 
6244     end if;
6245 
6246   END LOOP;
6247   UNSET_SESSION_LANGUAGE;
6248 
6249 end;
6250 
6251 PROCEDURE NOTIFY_BIDDERS_OF_CLOSEEARLY (itemtype            in varchar2,
6252                                     itemkey             in varchar2,
6253                                     actid               in number,
6254                                     uncmode             in varchar2,
6255                                     resultout           out NOCOPY varchar2)
6256 IS
6257    x_action_code varchar2(40) := 'CLOSEEARLY';
6258 BEGIN
6259 
6260         NOTIFY_BIDDERS_AUC_CHANGED(itemtype,
6261                                    itemkey,
6262                                    actid,
6263                                    uncmode,
6264                                    x_action_code);
6265 END;
6266 
6267 PROCEDURE NOTIFY_BIDDERS_OF_CLOSECHANGED (itemtype            in varchar2,
6268                                     itemkey             in varchar2,
6269                                     actid               in number,
6270                                     uncmode             in varchar2,
6271                                     resultout           out NOCOPY varchar2)
6272 IS
6273    x_action_code varchar2(40) := 'CLOSECHANGED';
6274 BEGIN
6275 
6276         NOTIFY_BIDDERS_AUC_CHANGED(itemtype,
6277                                    itemkey,
6278                                    actid,
6279                                    uncmode,
6280                                    x_action_code);
6281 END;
6282 
6283 
6284 PROCEDURE  NOTIFY_NEW_INVITEES (p_auction_id  NUMBER) IS -- 1
6285 
6286 x_auction_header_id  NUMBER;
6287 x_preview_date     DATE;
6288 x_progress     VARCHAR2(3);
6289 x_sequence    NUMBER;
6290 x_itemtype    VARCHAR2(8) := 'PONPBLSH';
6291 x_itemkey    VARCHAR2(50);
6292 x_user_name    VARCHAR2(100);
6293 x_contact_id    NUMBER;
6294 x_timezone    VARCHAR2(80);
6295 x_timezone1    VARCHAR2(80);
6296 x_newstarttime    DATE;
6297 x_newendtime    DATE;
6298 x_startdate    DATE;
6299 x_enddate    DATE;
6300 x_auctioneer_tag        Varchar2(30);
6301 x_event_id              NUMBER;
6302 x_event_title           VARCHAR2(80);
6303 x_language_code    VARCHAR2(3);
6304 x_auctioneer_user_name  VARCHAR2(100);
6305 x_preview_message       VARCHAR2(100);
6306 x_article_doc_type      VARCHAR2(100);
6307 
6308 x_doctype_group_name    VARCHAR2(100);
6309 x_msg_suffix     VARCHAR2(3) := '';
6310 x_doc_number_dsp   VARCHAR2(30);
6311 x_auction_contact_id    NUMBER;
6312 x_oex_timezone          VARCHAR2(80);
6313 x_oex_timezone1          VARCHAR2(80);
6314 
6315 x_wf_role_name          VARCHAR2(30);
6316 x_app                   VARCHAR2(20);
6317 
6318 x_oex_header            VARCHAR2(2000);
6319 x_oex_footer            VARCHAR2(2000);
6320 x_status                VARCHAR2(10);
6321 x_exception_msg         VARCHAR2(100);
6322 x_oex_operation    VARCHAR2(2000);
6323 x_auction_owner_tp_name VARCHAR2(300);
6324 x_tp_display_name  VARCHAR2(300);
6325 x_auction_title    VARCHAR2(2000);
6326 --lxchen
6327 x_note_to_new_supplier_type  VARCHAR2(30);
6328 
6329 p_itemtype varchar2(20) := 'PONAUCT';
6330 p_itemkey varchar2(360);
6331 x_timezone_disp VARCHAR2(240);
6332 x_auction_header_id_encrypted VARCHAR2(2000);
6333 x_vendor_site_id     NUMBER;
6334 x_preview_date_notspec VARCHAR2(240);
6335 
6336 
6337 BEGIN
6338 
6339       select wf_item_key into p_itemkey
6340       from pon_auction_headers_all
6341       where auction_header_id = p_auction_id;
6342 
6343       x_progress := '010';
6344 
6345       x_auction_header_id := wf_engine.GetItemAttrNumber (itemtype => p_itemtype,
6346                                                           itemkey  => p_itemkey,
6347                                                           aname    => 'AUCTION_ID');
6348 
6349       x_auction_header_id_encrypted := wf_engine.GetItemAttrText (itemtype => p_itemtype,
6350                                                          itemkey  => p_itemkey,
6351                                                          aname    => 'AUCTION_ID_ENCRYPTED');
6352 
6353       x_preview_date := wf_engine.GetItemAttrDate (itemtype   => p_itemtype,
6354                                                    itemkey    => p_itemkey,
6355                                                    aname      => 'PREVIEW_DATE');
6356 
6357       x_preview_date_notspec := wf_engine.GetItemAttrText (itemtype => p_itemtype,
6358                                                            itemkey  => p_itemkey,
6359                                                            aname    => 'PREVIEW_DATE_NOTSPECIFIED');
6360 
6361       BEGIN
6362             x_doctype_group_name := wf_engine.GetItemAttrText   (itemtype => p_itemtype,
6363                                                                  itemkey  => p_itemkey,
6364                                                                  aname    => 'DOC_INTERNAL_NAME');
6365       EXCEPTION
6366       WHEN OTHERS THEN
6367             select dt.doctype_group_name
6368             into x_doctype_group_name
6369             from pon_auction_headers_all auh, pon_auc_doctypes dt
6370             where auh.auction_header_id = x_auction_header_id
6371             and auh.doctype_id = dt.doctype_id;
6372       END;
6373 
6374       BEGIN
6375             x_doc_number_dsp     := wf_engine.GetItemAttrText   (itemtype => p_itemtype,
6376                                                                  itemkey  => p_itemkey,
6377                                                                  aname    => 'DOC_NUMBER');
6378       EXCEPTION
6379       WHEN OTHERS THEN
6380             x_doc_number_dsp   := to_char(x_auction_header_id);
6381       END;
6382 
6383 
6384 
6385       --
6386       -- Get next value in sequence for itemkey
6387       --
6388 
6389       SELECT pon_auction_wf_publish_s.nextval
6390       INTO   x_sequence
6391       FROM   dual;
6392 
6393 
6394       x_itemkey := (p_itemkey||'-'||to_char(x_sequence));
6395 
6396       wf_engine.CreateProcess(itemtype => x_itemtype,
6397                               itemkey  => x_itemkey,
6398                               process  => 'ADDED_INVITEES_MESSAGE');
6399 
6400       --
6401       -- Set all the item attributes
6402       --
6403 
6404       x_progress := '022';
6405 
6406       wf_engine.SetItemAttrNumber (itemtype   => x_itemtype,
6407                                    itemkey    => x_itemkey,
6408                                    aname      => 'AUCTION_ID',
6409                                    avalue     => x_auction_header_id); /* using auction_id instead of
6410                                                                          auction_number as a standard
6411                                                                          across item types */
6412 
6413       wf_engine.SetItemAttrText (itemtype   => x_itemtype,
6414                                  itemkey    => x_itemkey,
6415                                  aname      => 'DOC_NUMBER',
6416                                  avalue     => x_doc_number_dsp);
6417 
6418       wf_engine.SetItemAttrText (itemtype   => x_itemtype,
6419                                  itemkey    => x_itemkey,
6420                                  aname      => 'ORIGIN_USER_NAME',
6421                                  avalue     => fnd_global.user_name);
6422 
6423       wf_engine.SetItemAttrText (itemtype   => x_itemtype,
6424                                  itemkey    => x_itemkey,
6425                                  aname      => 'NOTE_TO_BIDDERS',
6426                                  avalue     => replaceHtmlChars(wf_engine.GetItemAttrText (itemtype => p_itemtype,
6427                     itemkey  => p_itemkey,
6428                     aname    => 'NOTE_TO_BIDDERS')));
6429 
6430       select view_by_date
6431       into x_preview_date
6432       from pon_auction_headers_all where auction_header_id = x_auction_header_id;
6433 
6434       x_auction_title := wf_engine.GetItemAttrText(itemtype => p_itemtype,
6435                                  itemkey  => p_itemkey,
6436                                  aname    => 'AUCTION_TITLE');
6437 
6438       wf_engine.SetItemAttrText (itemtype   => x_itemtype,
6439                                  itemkey    => x_itemkey,
6440                                  aname      => 'AUCTION_TITLE',
6441                                  avalue     => replaceHtmlChars(x_auction_title));
6442 
6443       x_auction_owner_tp_name := wf_engine.GetItemAttrText(itemtype => p_itemtype,
6444                                    itemkey  => p_itemkey,
6445                                    aname    => 'PREPARER_TP_NAME');
6446 
6447       wf_engine.SetItemAttrText (itemtype   => x_itemtype,
6448                                  itemkey    => x_itemkey,
6449                                  aname      => 'PREPARER_TP_NAME',
6450                              avalue     => x_auction_owner_tp_name);
6451 
6452       wf_engine.SetItemAttrNumber (itemtype  => x_itemtype,
6453                                    itemkey    => x_itemkey,
6454                                    aname      => 'NUMBER_OF_ITEMS',
6455                              avalue     => wf_engine.GetItemAttrNumber (itemtype => p_itemtype,
6456                                                                  itemkey  => p_itemkey,
6457                                                                 aname    => 'NUMBER_OF_ITEMS'));
6458       wf_engine.SetItemAttrDate (itemtype   => x_itemtype,
6459                                  itemkey    => x_itemkey,
6460                                  aname      => 'PREVIEW_DATE',
6461                              avalue     => x_preview_date);
6462 
6463       wf_engine.SetItemAttrText (itemtype   => x_itemtype,
6464                                  itemkey    => x_itemkey,
6465                                  aname      => 'PREVIEW_DATE_NOTSPECIFIED',
6466                              avalue     => x_preview_date_notspec);
6467 
6468       BEGIN
6469             wf_engine.SetItemAttrNumber (itemtype  => x_itemtype,
6470                                          itemkey    => x_itemkey,
6471                                          aname      => 'DOC_ROUND_NUMBER',
6472                                          avalue     => wf_engine.GetItemAttrNumber (itemtype => p_itemtype,
6473                                                                                     itemkey  => p_itemkey,
6474                                                                                     aname    => 'DOC_ROUND_NUMBER'));
6475       EXCEPTION
6476       WHEN OTHERS THEN
6477             wf_engine.SetItemAttrNumber (itemtype   => x_itemtype,
6478                                          itemkey    => x_itemkey,
6479                                          aname      => 'DOC_ROUND_NUMBER',
6480                                          avalue     => 1);
6481       END;
6482 
6483       wf_engine.SetItemAttrText (itemtype   => x_itemtype,
6484                                itemkey    => x_itemkey,
6485                                aname      => 'DOC_INTERNAL_NAME',
6486                                avalue     => x_doctype_group_name);
6487 
6488       begin
6489 
6490         wf_engine.SetItemAttrText   (itemtype   => x_itemtype,
6491                                          itemkey    => x_itemkey,
6492                                          aname      => '#WFM_HTMLAGENT',
6493                                          avalue     => pon_wf_utl_pkg.get_base_external_supplier_url);
6494       exception when others then
6495         null;
6496       end;
6497 
6498      -- Bug 4295915: Set the  workflow owner
6499       wf_engine.SetItemOwner(itemtype => x_itemtype,
6500                              itemkey  => x_itemkey,
6501                              owner    => fnd_global.user_name);
6502 
6503       --
6504       -- Start the workflow
6505       --
6506 
6507       wf_engine.StartProcess(itemtype => x_itemtype,
6508                              itemkey  => x_itemkey );
6509 
6510 END;
6511 
6512 PROCEDURE NOTIFY_ADDED_INVITEES(x_itemtype          in varchar2,
6513                                x_itemkey           in varchar2,
6514                                actid               in number,
6515                                uncmode             in varchar2,
6516                                resultout           out NOCOPY varchar2) IS
6517 
6518 x_role_name VARCHAR2(240);
6519 x_user_name VARCHAR2(100);
6520 x_additional_user_name          VARCHAR2(100);
6521 x_progress      VARCHAR2(3);
6522 x_sequence      NUMBER;
6523 x_user_orig_system    VARCHAR2(30);
6524 x_stringa                       VARCHAR2(30);
6525 x_user_orig_system_id    NUMBER;
6526 x_role_orig_system    VARCHAR2(30) := 'WF_LOCAL_ROLES';
6527 x_role_orig_system_id    NUMBER := 0;
6528 x_person_party_id               NUMBER;
6529 x_bidder_count      NUMBER;
6530 x_message      VARCHAR2(80);
6531 x_language_code      VARCHAR2(3);
6532 x_nid         NUMBER;
6533 x_auction_header_id    NUMBER;
6534 p_itemtype      VARCHAR2(8) := 'PONAUCT';
6535 p_itemkey      VARCHAR2(240);
6536 x_member      VARCHAR2(8) := 'None';
6537 x_doctype_group_name    VARCHAR2(80);
6538 x_msg_suffix      VARCHAR2(8);
6539 x_oex_timezone          VARCHAR2(80);
6540 x_oex_timezone1          VARCHAR2(80);
6541 x_timezone    VARCHAR2(80);
6542 x_timezone1    VARCHAR2(80);
6543 x_tp_display_name  VARCHAR2(300);
6544 x_startdate    DATE;
6545 x_enddate    DATE;
6546 x_newstarttime    DATE;
6547 x_newendtime    DATE;
6548 x_preview_date     DATE;
6549 x_newpreviewtime     DATE;
6550 x_open_bidding_date  DATE;
6551 
6552 x_auctioneer_user_name  VARCHAR2(100);
6553 x_preview_message       VARCHAR2(100);
6554 x_article_doc_type      VARCHAR2(100);
6555 
6556 x_wf_role_name          VARCHAR2(30);
6557 x_app                   VARCHAR2(20);
6558 x_invitation_id    NUMBER;
6559 
6560 x_oex_header            VARCHAR2(2000);
6561 x_oex_footer            VARCHAR2(2000);
6562 x_status                VARCHAR2(10);
6563 x_exception_msg         VARCHAR2(100);
6564 x_operation_url   VARCHAR2(300);
6565 x_oex_operation    VARCHAR2(2000);
6566 x_auction_owner_tp_name VARCHAR2(300);
6567 x_auction_title    VARCHAR2(2000);
6568 x_note_to_new_supplier_type  VARCHAR2(30);
6569 x_doc_number_dsp   VARCHAR2(30);
6570 
6571 x_auction_type          Varchar2(30);
6572 x_auction_type_name     Varchar2(30) := '';
6573 x_event_id              NUMBER;
6574 x_event_title           VARCHAR2(80);
6575 flag       BOOLEAN;
6576 t_itemtype    VARCHAR2(8) := 'PONPBLSH';
6577 t_itemkey    VARCHAR2(50);
6578 x_appstr                VARCHAR2(20);
6579 x_auction_creator_contact_id  NUMBER;
6580 x_timezone1_disp VARCHAR2(240);
6581 x_timezone_disp VARCHAR2(240);
6582 
6583 -- Added the following declaration for Affiliate ID related changes
6584 -- Auctioneer's trading partner id
6585 x_tp_id                      NUMBER;
6586 
6587 x_nls_language               VARCHAR2(60);
6588 x_territory_code             VARCHAR2(30);
6589 x_nls_territory              VARCHAR2(60);
6590 
6591 x_nls_addnl_language         VARCHAR2(60);
6592 x_nls_addnl_territory        VARCHAR2(30);
6593 x_registration_key           VARCHAR2(100);
6594 x_neg_summary_url_supplier   VARCHAR2(2000);
6595 x_isp_supplier_register_url  VARCHAR2(2000);
6596 x_ack_part_url_supplier      VARCHAR2(2000);
6597 x_vendor_site_code           PO_VENDOR_SITES_ALL.VENDOR_SITE_CODE%TYPE;
6598 x_vendor_site_id       NUMBER;
6599 x_auction_header_id_encrypted VARCHAR2(2000);
6600 x_preview_date_notspec VARCHAR2(240);
6601 x_staggered_closing_interval NUMBER;
6602 x_staggered_close_note       VARCHAR2(1000);
6603 
6604 
6605 -- added following for requested suppliers project
6606 l_requested_supplier      BOOLEAN;
6607 x_rs_user_name            VARCHAR2(100);
6608 x_nls_rs_language         VARCHAR2(60);
6609 x_nls_rs_territory        VARCHAR2(30);
6610 
6611 cursor newInvitees is
6612     select
6613      trading_partner_contact_name,
6614      trading_partner_contact_id,
6615      trading_partner_name,
6616      trading_partner_id,
6617      wf_user_name,
6618      additional_contact_email,
6619        registration_id,
6620        decode(pbp.vendor_site_code, '-1', null, pbp.vendor_site_code) vendor_site_code,
6621        pbp.vendor_site_id,
6622        pbp.requested_supplier_id,
6623        pbp.requested_supplier_name,
6624        pbp.requested_supplier_contact_id,
6625        pbp.requested_supp_contact_name,
6626        pcr.email_address rs_contact_email
6627     from pon_bidding_parties pbp,
6628          pos_contact_requests pcr
6629     where auction_header_id = x_auction_header_id
6630     and pbp.requested_supplier_contact_id = pcr.contact_request_id(+)
6631     and wf_item_key IS NULL;
6632 
6633 CURSOR c1_auction_type IS
6634     select auction_type, event_id, event_title, open_bidding_date, trading_partner_id,
6635            staggered_closing_interval
6636     from pon_auction_headers_all
6637     where auction_header_id = x_auction_header_id;
6638 
6639 BEGIN
6640     x_auction_header_id := wf_engine.GetItemAttrNumber (itemtype   => x_itemtype,
6641                                                        itemkey    => x_itemkey,
6642                                                        aname      => 'AUCTION_ID'); /* using auction_id instead of
6643                                                                                      auction_number as a standard
6644                                                                                      across item types */
6645 
6646     select wf_item_key , trading_partner_contact_name into p_itemkey, x_auctioneer_user_name
6647       from pon_auction_headers_all
6648       where auction_header_id = x_auction_header_id;
6649 
6650 --    x_auctioneer_user_name := wf_engine.GetItemAttrText (itemtype => p_itemtype,
6651 --                                               itemkey  => p_itemkey,
6652 --                                                     aname    => 'PREPARER_TP_CONTACT_NAME');
6653 
6654     x_auction_header_id_encrypted := wf_engine.GetItemAttrText (itemtype => p_itemtype,
6655                                                          itemkey  => p_itemkey,
6656                                                          aname    => 'AUCTION_ID_ENCRYPTED');
6657 
6658     x_doc_number_dsp :=  wf_engine.GetItemAttrText (itemtype   => x_itemtype,
6659                                          itemkey    => x_itemkey,
6660                                          aname      => 'DOC_NUMBER');
6661 
6662     x_auction_owner_tp_name := wf_engine.GetItemAttrText (itemtype => x_itemtype,
6663                                                           itemkey  => x_itemkey,
6664                                                           aname    => 'PREPARER_TP_NAME');
6665 
6666     x_auction_title := wf_engine.GetItemAttrText(itemtype => x_itemtype,
6667                                                  itemkey  => x_itemkey,
6668                                                  aname    => 'AUCTION_TITLE');
6669 
6670 
6671     x_preview_date := wf_engine.GetItemAttrDate (itemtype => x_itemtype,
6672                                       itemkey  => x_itemkey,
6673                                        aname    => 'PREVIEW_DATE');
6674 
6675      x_preview_date_notspec := wf_engine.GetItemAttrText (itemtype => x_itemtype,
6676                                                            itemkey  => x_itemkey,
6677                                                            aname    => 'PREVIEW_DATE_NOTSPECIFIED');
6678 
6679 
6680     x_doctype_group_name := wf_engine.GetItemAttrText   (itemtype => x_itemtype,
6681                                                          itemkey  => x_itemkey,
6682                                                          aname    => 'DOC_INTERNAL_NAME');
6683 
6684     x_startdate := wf_engine.GetItemAttrDate (itemtype => p_itemtype,
6685                                               itemkey  => p_itemkey,
6686                                               aname    => 'AUCTION_START_DATE');
6687 
6688     x_enddate   := wf_engine.GetItemAttrDate (itemtype => p_itemtype,
6689                                               itemkey  => p_itemkey,
6690                                               aname    => 'AUCTION_END_DATE');
6691 
6692     x_msg_suffix := GET_MESSAGE_SUFFIX (x_doctype_group_name);
6693 
6694     IF x_auctioneer_user_name is not null THEN
6695        PON_PROFILE_UTIL_PKG.GET_WF_PREFERENCES(x_auctioneer_user_name,x_language_code,x_territory_code);
6696     END IF;
6697 
6698     select NLS_LANGUAGE into x_nls_language
6699     from fnd_languages
6700     where language_code = x_language_code;
6701 
6702     select nls_territory into x_nls_territory
6703     from   fnd_territories
6704     where  territory_code = x_territory_code;
6705 
6706     open c1_auction_type;
6707     fetch c1_auction_type
6708     into x_auction_type,
6709          x_event_id,
6710          x_event_title,
6711    x_open_bidding_date,
6712          x_tp_id,
6713          x_staggered_closing_interval;
6714     close c1_auction_type;
6715 
6716 
6717     select wf_role_name, wf_item_key into x_role_name, p_itemkey
6718     from pon_auction_headers_all
6719     where auction_header_id = x_auction_header_id;
6720 
6721     x_oex_timezone := Get_Oex_Time_Zone;
6722 
6723    -- Get the auctioneer's language
6724      PON_PROFILE_UTIL_PKG.GET_WF_PREFERENCES(x_auctioneer_user_name,x_language_code,x_territory_code);
6725      for bidder in newInvitees loop
6726 
6727        -- Bug 3824928: Removed unnecessary statements from this version
6728 
6729     -- If we have a contact name, use it.
6730       -- Bug 3824928: Trading partner contact id can be null
6731       IF bidder.trading_partner_contact_id IS NOT NULL THEN -- {
6732 
6733       x_person_party_id := bidder.trading_partner_contact_id;
6734 
6735          -- check if the contact is in the role - if not this is a new invitee
6736       x_user_name := GET_USER_NAME(x_person_party_id);
6737 
6738        select count(*) into x_bidder_count
6739      from wf_local_user_roles
6740      where role_name = x_role_name
6741      and user_name = x_user_name;
6742 
6743 
6744      if (x_bidder_count < 1) then
6745 
6746         -- Add new user and send notification.
6747 
6748         WF_DIRECTORY.AddUsersToAdHocRole(x_role_name,
6749                      x_user_name);
6750        end if; -- Bug 3824928: Added end if
6751 
6752       -- send notfication to this bidder.
6753 
6754 
6755       -- Set bidder specific attributes
6756 
6757      -- Bug 3824928: calling get_wf_preferences instead of get_wf_language
6758 
6759        PON_PROFILE_UTIL_PKG.GET_WF_PREFERENCES(x_user_name,x_language_code,x_territory_code);
6760 
6761     --
6762     -- Get the user's time zone
6763     --
6764      x_timezone := Get_Time_Zone(x_person_party_id);
6765      ELSE  -- Bug 3824928: bidder.trading_partner_contact_id IS NULL
6766 
6767     --
6768     -- Get the auctioneer's time zone
6769 
6770         x_timezone := Get_Time_Zone(x_auctioneer_user_name);
6771               if (x_timezone is null or x_timezone = '') then
6772                              x_timezone := x_oex_timezone;
6773               end if;
6774 
6775      END IF; -- } IF bidder.trading_partner_contact_id IS NOT NULL
6776 
6777         -- Convert the dates to the user's or auctioneer's timezone
6778     -- If the timezone is not recognized, just use PST
6779     --
6780 
6781     IF (PON_OEX_TIMEZONE_PKG.VALID_ZONE(x_timezone) = 1) THEN
6782        x_newstarttime := PON_OEX_TIMEZONE_PKG.CONVERT_TIME(x_startdate,x_oex_timezone,x_timezone);
6783        x_newendtime := PON_OEX_TIMEZONE_PKG.CONVERT_TIME(x_enddate,x_oex_timezone,x_timezone);
6784            if x_preview_date is not null then
6785          x_newpreviewtime := PON_OEX_TIMEZONE_PKG.CONVERT_TIME(x_preview_date,x_oex_timezone,x_timezone);
6786            end if;
6787     ELSE
6788        x_newstarttime := x_startdate;
6789        x_newendtime := x_enddate;
6790            x_newpreviewtime := x_preview_date;
6791        x_timezone := x_oex_timezone;
6792     END IF;
6793 
6794         -- check if supplier is requested supplier
6795         IF (bidder.trading_partner_id is null
6796             AND bidder.requested_supplier_id is not null)THEN
6797            l_requested_supplier := TRUE;
6798         END IF;
6799 
6800         x_tp_display_name := nvl(bidder.trading_partner_name, bidder.requested_supplier_name);
6801 
6802         x_vendor_site_code := bidder.vendor_site_code;
6803 
6804         x_vendor_site_id := bidder.vendor_site_id;
6805 
6806 
6807       -- this is needed here because of a bug in wf (fixed in 2.6)
6808       UNSET_SESSION_LANGUAGE;
6809 
6810       SELECT pon_auction_wf_publish_s.nextval
6811       INTO   x_sequence
6812       FROM   dual;
6813 
6814       t_itemkey := (x_itemkey||'-'||to_char(x_sequence));
6815 
6816       wf_engine.CreateProcess(itemtype => t_itemtype,
6817                               itemkey  => t_itemkey,
6818                         process  => 'SEND_ADDED_INVITEES');
6819 
6820       IF (l_requested_supplier) THEN
6821 
6822             wf_engine.SetItemAttrText (itemtype => t_itemtype,
6823                                        itemkey    => t_itemkey,
6824                                        aname    => 'REQ_SUPPLIER_CONTACT_NAME',
6825                                        avalue   => bidder.requested_supp_contact_name);
6826       ELSE
6827             wf_engine.SetItemAttrText (itemtype => t_itemtype,
6828                                        itemkey  => t_itemkey,
6829                                        aname    => 'BIDDER_TP_CONTACT_NAME',
6830                                        avalue   => x_user_name);
6831       END IF;
6832 
6833       wf_engine.SetItemAttrNumber (itemtype  => t_itemtype,
6834              itemkey  => t_itemkey,
6835                aname  => 'TRADING_PARTNER_ID',
6836                avalue   => bidder.trading_partner_id);
6837 
6838             wf_engine.SetItemAttrNumber (itemtype  => t_itemtype,
6839              itemkey  => t_itemkey,
6840                aname  => 'AUCTION_ID',
6841                avalue   => x_auction_header_id); /* using auction_id instead of
6842                                                            auction_number as a standard
6843                                                            across item types */
6844 
6845             BEGIN
6846                  x_staggered_close_note := NULL;
6847                  IF x_staggered_closing_interval IS NOT NULL THEN
6848                      x_staggered_close_note := wf_core.newline || wf_core.newline ||
6849                                                getMessage('PON_STAGGERED_CLOSE_NOTIF_MSG') ||
6850                                                wf_core.newline || wf_core.newline;
6851                  END IF;
6852                  wf_engine.SetItemAttrText( itemtype     => t_itemtype,
6853                                             itemkey      => t_itemkey,
6854                                             aname        => 'STAGGERED_CLOSE_NOTE',
6855                                             avalue       => x_staggered_close_note);
6856             EXCEPTION                                                                                                                                                       WHEN OTHERS THEN NULL;
6857                                                                                                                                                                       END;
6858 
6859             IF (x_language_code is not null) THEN
6860 
6861                 IF (FND_LOG.level_statement >= FND_LOG.g_current_runtime_level) THEN --{
6862                 FND_LOG.string(log_level => FND_LOG.level_statement,
6863                   module => g_module_prefix || 'NOTIFY_ADDED_INVITEES',
6864                   message  => '7. Calling SET_SESSION_LANGUAGE with x_language_code : ' || x_language_code);
6865                 END IF; --}
6866 
6867         SET_SESSION_LANGUAGE(null, x_language_code);
6868             END IF;
6869 
6870 
6871       --- 000001
6872 
6873             wf_engine.SetItemAttrText (itemtype       => t_itemtype,
6874                                        itemkey        => t_itemkey,
6875                                        aname          => 'INVITE_RESPONSE_SUB',
6876                                        avalue         => getMessage('PON_AUC_WF_PUB_OPEN_RG_S', x_msg_suffix,
6877                                                                     'DOC_NUMBER', x_doc_number_dsp,
6878                                                                     'AUCTION_TITLE', replaceHtmlChars(x_auction_title)));
6879 
6880       wf_engine.SetItemAttrText (itemtype  => t_itemtype,
6881                            itemkey  => t_itemkey,
6882                            aname  => 'PREPARER_TP_CONTACT_NAME',
6883                            avalue   => x_auctioneer_user_name);
6884 
6885       wf_engine.SetItemAttrText (itemtype  => t_itemtype,
6886                            itemkey  => t_itemkey,
6887                            aname  => 'TP_DISPLAY_NAME',
6888                            avalue   => x_tp_display_name);
6889 
6890         wf_engine.SetItemAttrText (itemtype   => t_itemtype,
6891                                    itemkey    => t_itemkey,
6892                                    aname      => 'BIDDER_TP_NAME',
6893                                    avalue     => x_tp_display_name);
6894 
6895         wf_engine.SetItemAttrText (itemtype   => t_itemtype,
6896                                itemkey    => t_itemkey,
6897                                aname      => 'BIDDER_TP_ADDRESS_NAME',
6898                                avalue     => x_vendor_site_code);
6899 
6900     -- Item attribute value is going to be used as a parameter to Acknowledge Participation page
6901         wf_engine.SetItemAttrNumber (itemtype   => t_itemtype,
6902                                itemkey    => t_itemkey,
6903                                aname      => 'VENDOR_SITE_ID',
6904                                avalue     => x_vendor_site_id);
6905 
6906         -- call to notification utility package to get the redirect page url that
6907         -- is responsible for getting the Negotiation Summary url and forward to it.
6908         x_neg_summary_url_supplier := pon_wf_utl_pkg.get_dest_page_url (
6909                               p_dest_func => 'PON_NEG_SUMMARY'
6910                                  ,p_notif_performer  => 'SUPPLIER');
6911 
6912         wf_engine.SetItemAttrText (itemtype   => t_itemtype,
6913                                itemkey    => t_itemkey,
6914                                aname      => 'NEG_SUMMARY_URL',
6915                                avalue     => x_neg_summary_url_supplier);
6916 
6917         begin
6918           wf_engine.SetItemAttrText   (itemtype   => t_itemtype,
6919                                          itemkey    => t_itemkey,
6920                                          aname      => '#WFM_HTMLAGENT',
6921                                          avalue     => pon_wf_utl_pkg.get_base_external_supplier_url);
6922         exception
6923           when others then
6924             null;
6925         end;
6926 
6927       if (x_open_bidding_date < sysdate) then
6928 
6929 
6930       wf_engine.SetItemAttrText (itemtype  => t_itemtype,
6931              itemkey  => t_itemkey,
6932                aname  => 'PON_AUC_WF_DOC_IN_PR0G',
6933                avalue   => getMessage('PON_AUC_WF_DOC_IN_PR0G', x_msg_suffix));
6934 
6935       end if;
6936 
6937 
6938       wf_engine.SetItemAttrText (itemtype  => t_itemtype,
6939              itemkey  => t_itemkey,
6940                aname  => 'PREPARER_TP_NAME',
6941                avalue   => x_auction_owner_tp_name);
6942 
6943 
6944       wf_engine.SetItemAttrText (itemtype  => t_itemtype,
6945              itemkey  => t_itemkey,
6946                aname  => 'AUCTION_TITLE',
6947                avalue   => replaceHtmlChars(x_auction_title));
6948 
6949 
6950       wf_engine.SetItemAttrText (itemtype  => t_itemtype,
6951              itemkey  => t_itemkey,
6952                aname  => 'DOC_NUMBER',
6953                avalue   => x_doc_number_dsp);
6954 
6955         x_timezone_disp := Get_TimeZone_Description(x_timezone, x_language_code);
6956         IF (x_preview_date IS NULL) THEN
6957         x_timezone1_disp := null;
6958     ELSE
6959         x_timezone1_disp := x_timezone_disp;
6960     END IF;
6961 
6962   IF (x_preview_date is not null) THEN
6963          wf_engine.SetItemAttrDate (itemtype  => t_itemtype,
6964                    itemkey  => t_itemkey,
6965                    aname  => 'PREVIEW_DATE',
6966                    avalue   => x_newpreviewtime);
6967 
6968          wf_engine.SetItemAttrDate (itemtype  => t_itemtype,
6969                    itemkey  => t_itemkey,
6970                    aname  => 'PREVIEW_DATE_TZ',
6971                    avalue   => x_newpreviewtime);
6972 
6973          wf_engine.SetItemAttrText (itemtype  => t_itemtype,
6974                    itemkey  => t_itemkey,
6975                    aname  => 'TP_TIME_ZONE1',
6976                    avalue   => x_timezone1_disp);
6977 
6978          wf_engine.SetItemAttrText (itemtype  => t_itemtype,
6979                            itemkey  => t_itemkey,
6980                            aname  => 'PREVIEW_DATE_NOTSPECIFIED',
6981                            avalue  => null);
6982     ELSE
6983          wf_engine.SetItemAttrDate (itemtype  => t_itemtype,
6984                   itemkey  => t_itemkey,
6985                   aname  => 'PREVIEW_DATE',
6986                   avalue   => null);
6987 
6988          wf_engine.SetItemAttrDate (itemtype  => t_itemtype,
6989                    itemkey  => t_itemkey,
6990                    aname  => 'PREVIEW_DATE_TZ',
6991                    avalue   => null);
6992 
6993          wf_engine.SetItemAttrText (itemtype  => t_itemtype,
6994                    itemkey  => t_itemkey,
6995                    aname  => 'TP_TIME_ZONE1',
6996                    avalue   => x_timezone1_disp);
6997 
6998          wf_engine.SetItemAttrText (itemtype  => t_itemtype,
6999                            itemkey  => t_itemkey,
7000                            aname  => 'PREVIEW_DATE_NOTSPECIFIED',
7001                            avalue  => PON_AUCTION_PKG.getMessage('PON_AUC_PREVIEW_DATE_NOTSPEC'));
7002 
7003   END IF;
7004 
7005       wf_engine.SetItemAttrDate (itemtype  => t_itemtype,
7006              itemkey  => t_itemkey,
7007                aname  => 'AUCTION_START_DATE_TZ',
7008                avalue   => x_newstarttime);
7009 
7010       wf_engine.SetItemAttrText (itemtype  => t_itemtype,
7011              itemkey  => t_itemkey,
7012                aname  => 'TP_TIME_ZONE',
7013                avalue   => x_timezone_disp);
7014 
7015 
7016       wf_engine.SetItemAttrDate (itemtype  => t_itemtype,
7017              itemkey  => t_itemkey,
7018                aname  => 'AUCTION_END_DATE_TZ',
7019                avalue   => x_newendtime);
7020 
7021       wf_engine.SetItemAttrText (itemtype  => t_itemtype,
7022                itemkey  => t_itemkey,
7023                aname  => 'ORIGIN_USER_NAME',
7024                avalue   => fnd_global.user_name);
7025 
7026 
7027   -- Bug 3824928: Deleted unwanted lines here
7028 
7029 
7030   -- end if;
7031     -- Bug 3824928: Checking if additional_contact_email is not null
7032 
7033    if bidder.additional_contact_email is not NULL THEN --{
7034 
7035          SELECT pon_auction_wf_bidder_s.nextval
7036       INTO   x_sequence
7037       FROM   dual;
7038         -- Bug 3824928 - check if the additional contact is in the role - if
7039         -- not this is the additional contact of a new invitee
7040 
7041 
7042          select count(*) into x_bidder_count
7043          from wf_local_user_roles
7044          where role_name = x_role_name
7045         and user_name = bidder.wf_user_name;
7046 
7047        if (x_bidder_count < 1) then
7048 
7049 
7050       x_additional_user_name := ('WF_PON_USER_'||to_char(x_sequence));
7051 
7052          wf_engine.SetItemAttrText (itemtype  => t_itemtype,
7053              itemkey  => t_itemkey,
7054                aname  => 'ADDITIONAL_CONTACT_USERNAME',
7055                avalue   => x_additional_user_name);
7056 
7057               -- add a registration link in FPH for additional contact
7058               begin
7059                  select registration_key
7060                   into x_registration_key
7061                   from fnd_registrations
7062                  where registration_id = bidder.registration_id;
7063               exception
7064                   WHEN NO_DATA_FOUND THEN
7065                        x_registration_key := '';
7066               end;
7067 
7068         -- call to notification utility package to get the iSupplier registration page url
7069         x_isp_supplier_register_url := pon_wf_utl_pkg.get_isp_supplier_register_url(p_registration_key => x_registration_key
7070                                                                                    ,p_language_code => x_language_code);
7071 
7072 
7073         wf_engine.SetItemAttrText (itemtype   => t_itemtype,
7074                                    itemkey    => t_itemkey,
7075                                    aname      => 'ISP_SUPPLIER_REG_URL',
7076                                    avalue     => x_isp_supplier_register_url);
7077 
7078            -- call to notification utility package to get the redirect page url that
7079            -- is responsible for getting the Acknowledge participation url and forward to it.
7080            x_ack_part_url_supplier := pon_wf_utl_pkg.get_dest_page_url (
7081                               p_dest_func => 'PONRESAPN_ACKPARTICIPATN'
7082                                  ,p_notif_performer  => 'SUPPLIER');
7083 
7084         wf_engine.SetItemAttrText (itemtype   => t_itemtype,
7085                                    itemkey    => t_itemkey,
7086                                    aname      => 'ACK_PARTICIPATION_URL',
7087                                    avalue     => x_ack_part_url_supplier);
7088 
7089     -- Bug 3824928: if tpcontactid is not null use language and territory
7090         -- from tp contact id else use auctioneer's language and territory
7091 
7092         select NLS_LANGUAGE into x_nls_addnl_language
7093         from fnd_languages
7094         where language_code = x_language_code;
7095 
7096         select nls_territory into x_nls_addnl_territory
7097         from   fnd_territories
7098         where  territory_code = x_territory_code;
7099 
7100 
7101       WF_DIRECTORY.CreateAdHocUser(x_additional_user_name,
7102                                          x_additional_user_name,
7103                                          x_nls_addnl_language,
7104                                          x_nls_addnl_territory,
7105                                          'Oracle Exchange Additional Bidder '||to_char(x_auction_header_id),
7106                                              'MAILHTML',
7107                                          bidder.additional_contact_email,
7108                                          null,
7109                                          'ACTIVE',
7110                                              null);
7111 
7112     WF_DIRECTORY.AddUsersToAdHocRole(x_role_name,
7113                    x_additional_user_name);
7114 
7115          -- Bug 3709564
7116          -- If this update is not performed here, it will error out
7117          -- in notify_bidder_list_reminder as wf_user_name will be null
7118             UPDATE pon_bidding_parties set
7119             wf_user_name = x_additional_user_name
7120             WHERE auction_header_id = x_auction_header_id
7121             AND  trading_partner_id = bidder.trading_partner_id
7122             AND  vendor_site_id = bidder.vendor_site_id;
7123 
7124       end if; -- if (x_bidder_count < 1)
7125 
7126    end if; -- } if bidder.additional_contact_email is not NULL
7127 
7128 -- create adhoc user for this rs contact
7129 if (l_requested_supplier and bidder.rs_contact_email is not NULL) THEN
7130 -- {
7131        SELECT pon_auction_wf_bidder_s.nextval
7132                 INTO   x_sequence
7133                 FROM   dual;
7134 
7135        SELECT count(*) INTO x_bidder_count
7136        FROM wf_local_user_roles
7137        WHERE role_name = x_role_name
7138           AND user_name = bidder.wf_user_name;
7139 
7140        IF (x_bidder_count < 1) THEN  --{
7141 
7142           x_rs_user_name := ('WF_PON_USER_'||to_char(x_sequence));
7143           wf_engine.SetItemAttrText (itemtype   => t_itemtype,
7144                                      itemkey    => t_itemkey,
7145                                      aname      => 'REQ_SUPPLIER_USERNAME',
7146                                      avalue   => x_rs_user_name); --(performer)
7147 
7148           x_ack_part_url_supplier := pon_wf_utl_pkg.get_dest_page_url (
7149                                           p_dest_func => 'PONRESAPN_ACKPARTICIPATN'
7150                                          ,p_notif_performer  => 'SUPPLIER');
7151 
7152           wf_engine.SetItemAttrText (itemtype   => t_itemtype,
7153                                    itemkey    => t_itemkey,
7154                                    aname      => 'ACK_PARTICIPATION_URL',
7155                                    avalue     => x_ack_part_url_supplier);
7156 
7157           -- create user
7158 
7159           WF_DIRECTORY.CreateAdHocUser(x_rs_user_name,
7160                      x_rs_user_name,
7161                      x_nls_rs_language,
7162                      x_nls_rs_territory,
7163                      'Oracle Exchange Requested Bidder'||to_char(x_auction_header_id),
7164                      'MAILHTML',
7165                      bidder.rs_contact_email,
7166                      null,
7167                      'ACTIVE',
7168                      null);
7169 
7170           WF_DIRECTORY.AddUsersToAdHocRole(x_role_name,
7171                                            x_rs_user_name);
7172 
7173           UPDATE pon_bidding_parties SET
7174             wf_user_name = x_rs_user_name
7175             WHERE auction_header_id = x_auction_header_id
7176             AND  (trading_partner_id = bidder.trading_partner_id
7177                              or requested_supplier_id = bidder.requested_supplier_id)
7178             AND  vendor_site_id = bidder.vendor_site_id;
7179 
7180       END IF; --} if (x_bidder_count < 1)
7181 
7182    END IF; --} if requested supplier
7183 
7184     -- Bug 4295915: Set the  workflow owner
7185        wf_engine.SetItemOwner(itemtype => t_itemtype,
7186                               itemkey  => t_itemkey,
7187                               owner    => fnd_global.user_name);
7188 
7189   wf_engine.StartProcess(itemtype => t_itemtype,
7190                                itemkey  => t_itemkey );
7191 
7192     -- Bug 3709564
7193     -- If this update is not performed here, wf_engine.abort_process call
7194     -- in notify_bidder_list_reminder will fail, as wf_item_key will be null
7195        update pon_bidding_parties
7196        set wf_item_key = t_itemkey
7197        where  auction_header_id = x_auction_header_id and
7198               (trading_partner_id = bidder.trading_partner_id
7199                or requested_supplier_id = bidder.requested_supplier_Id) and
7200               vendor_site_id = bidder.vendor_site_id and
7201               wf_item_key is null;
7202 
7203     -- end if;  -- if newly added invitee check Bug 3824928 commenting this
7204 
7205     end loop;
7206 
7207     UNSET_SESSION_LANGUAGE;
7208 
7209 END;
7210 
7211 
7212 PROCEDURE SET_INVITATION_LIST_FLAG(p_auction_header_id  NUMBER) IS
7213   x_item_key VARCHAR2(240);
7214 BEGIN
7215 
7216   select wf_item_key into x_item_key
7217   from pon_auction_headers_all
7218   where auction_header_id = p_auction_header_id;
7219 
7220         wf_engine.SetItemAttrText (itemtype   => 'PONAUCT',
7221                                    itemkey    => x_item_key,
7222                                    aname      => 'BIDDER_LIST_FLAG',
7223                                    avalue     => 'Y');
7224 END;
7225 
7226 
7227 FUNCTION GET_USER_NAME (p_user_id NUMBER) RETURN VARCHAR2
7228 IS
7229 x_user_name varchar2(100);
7230 BEGIN
7231       begin
7232   select user_name
7233         into x_user_name
7234   from fnd_user
7235         where person_party_id = p_user_id
7236         and nvl(end_date,sysdate+1) > sysdate;
7237       exception
7238        when too_many_rows then
7239           if (nvl(fnd_profile.value('AFLOG_ENABLED'),'N') = 'Y') then
7240                if (fnd_log.level_unexpected >= fnd_log.g_current_runtime_level) then
7241                          fnd_log.string(log_level => fnd_log.level_unexpected,
7242                                         module    => 'pon.plsql.pon_auction_pkg.get_user_name',
7243                                         message   => 'Multiple Users found for person_party_id:'|| p_user_id);
7244                end if;
7245          end if;
7246 
7247          select user_name
7248          into x_user_name
7249          from fnd_user
7250          where person_party_id = p_user_id
7251          and nvl(end_date, sysdate+1) > sysdate
7252          and rownum=1;
7253       end;
7254       return x_user_name;
7255 END;
7256 
7257 
7258 FUNCTION MEMBER_USER(p_user_name VARCHAR2) RETURN BOOLEAN
7259 IS
7260 x_count int := 0;
7261 BEGIN
7262   select count(*) into x_count
7263   from fnd_user where user_name = p_user_name;
7264 
7265   if (x_count > 0) then return true; else return false; end if;
7266 END;
7267 
7268 
7269 FUNCTION ADDITIONAL_BIDDER(p_user_name VARCHAR2, p_doc_id int, p_preparer_tp_contact_name varchar2,
7270 x_profile_user IN OUT NOCOPY VARCHAR2)
7271 RETURN BOOLEAN
7272 IS
7273 x_found BOOLEAN;
7274 x_user_name VARCHAR2(100);
7275 x_user_id   int;
7276 BEGIN
7277   begin
7278     select trading_partner_contact_id
7279         into x_user_id
7280     from pon_bidding_parties
7281     where auction_header_id = p_doc_id
7282     and wf_user_name = p_user_name;
7283 
7284          if x_user_id is null then -- it means the additional contact is not associated to any
7285                                     -- tp_contact_id
7286              x_profile_user := p_preparer_tp_contact_name;
7287          else
7288 
7289        x_profile_user := GET_USER_NAME(x_user_id);
7290 
7291        if (x_profile_user is null) then -- this condition should not occur. It may
7292                                             -- occur if user is deleted from fnd_user table
7293        x_profile_user := p_preparer_tp_contact_name; -- Bug 3824928: changed from p_user_name to
7294                                                           -- default to the auctioneer name
7295        end if;
7296         end if;
7297     x_found := true;
7298   exception
7299     when no_data_found then
7300     -- no additional contact
7301     x_found := false;
7302   end;
7303   return x_found;
7304 
7305 END;
7306 
7307 FUNCTION Get_TimeZone_Description(p_timezone_id varchar2, lang varchar2) return varchar2
7308 is
7309 x_timezone_desc  varchar2(80) := '';
7310 begin
7311 
7312   begin
7313     select name
7314     into x_timezone_desc
7315     from fnd_timezones_tl tl, fnd_timezones_b b
7316     where b.upgrade_tz_id = p_timezone_id
7317     and b.timezone_code = tl.timezone_code
7318           and tl.language = lang;
7319   exception
7320     when others  then
7321             null;
7322         end;
7323 
7324   return x_timezone_desc  ;
7325 end;
7326 
7327 
7328 FUNCTION Get_Oex_Time_Zone return varchar2
7329 is
7330 x_oex_timezone  varchar2(80) := '';
7331 begin
7332     --
7333     -- Get the exchange time zone
7334     --
7335                 x_oex_timezone :=  fnd_profile.value_specific('SERVER_TIMEZONE_ID');
7336     return x_oex_timezone;
7337 end;
7338 
7339 
7340 FUNCTION Get_Time_Zone(contact_id number) return varchar2
7341 is
7342 x_timezone  varchar2(80) := '';
7343 x_user_id NUMBER;
7344 begin
7345     --
7346     -- Get the contact/tp time zone
7347     --
7348 
7349   begin
7350     select user_id
7351     into  x_user_id
7352     from fnd_user
7353     where person_party_id = contact_id
7354                 and nvl(end_date, sysdate+1) > sysdate;
7355     x_timezone := fnd_profile.value_specific('CLIENT_TIMEZONE_ID',x_user_id);
7356   exception
7357                when too_many_rows then
7358                   if (nvl(fnd_profile.value('AFLOG_ENABLED'),'N') = 'Y') then
7359                        if (fnd_log.level_unexpected >= fnd_log.g_current_runtime_level) then
7360                                  fnd_log.string(log_level => fnd_log.level_unexpected,
7361                                                 module    => 'pon.plsql.pon_auction_pkg.get_time_zone',
7362                                                 message   => 'Multiple Users found for person_party_id:'|| contact_id);
7363                        end if;
7364                  end if;
7365 
7366                  select user_id
7367                  into x_user_id
7368                  from fnd_user
7369                  where person_party_id = contact_id
7370                  and nvl(end_date, sysdate+1) > sysdate
7371                  and rownum=1;
7372 
7373                  x_timezone := fnd_profile.value_specific('CLIENT_TIMEZONE_ID',x_user_id);
7374 
7375                when NO_DATA_FOUND then
7376                   if (nvl(fnd_profile.value('AFLOG_ENABLED'),'N') = 'Y') then
7377                        if (fnd_log.level_unexpected >= fnd_log.g_current_runtime_level) then
7378                                  fnd_log.string(log_level => fnd_log.level_unexpected,
7379                                                 module    => 'pon.plsql.pon_auction_pkg.get_time_zone',
7380                                                 message   => 'No Active Users found for person_party_id:'|| contact_id);
7381                        end if;
7382                  end if;
7383 
7384                  select user_id
7385                  into x_user_id
7386                  from fnd_user
7387                  where person_party_id = contact_id
7388                  and rownum=1;
7389 
7390                  x_timezone := fnd_profile.value_specific('CLIENT_TIMEZONE_ID',x_user_id);
7391 
7392                when OTHERS then
7393                   if (nvl(fnd_profile.value('AFLOG_ENABLED'),'N') = 'Y') then
7394                        if (fnd_log.level_unexpected >= fnd_log.g_current_runtime_level) then
7395                                  fnd_log.string(log_level => fnd_log.level_unexpected,
7396                                                 module    => 'pon.plsql.pon_auction_pkg.get_time_zone',
7397                                                 message   => 'Unknown exception for person_party_id:'|| contact_id);
7398                        end if;
7399                  end if;
7400                  x_timezone := Get_Oex_Time_Zone;
7401 
7402   end;
7403 
7404   return x_timezone;
7405 
7406 
7407 end;
7408 
7409 
7410 FUNCTION Get_Time_Zone(contact_name varchar2) return varchar2
7411 is
7412 x_timezone  varchar2(80) := null;
7413 x_contact_id number;
7414 begin
7415          begin
7416     SELECT person_party_id
7417     INTO x_contact_id
7418     FROM fnd_user
7419     WHERE user_name = contact_name;
7420   exception
7421     when others then
7422     x_contact_id := null;
7423   end;
7424 
7425   if (x_contact_id is null) then
7426     return '';
7427   end if;
7428 
7429   --
7430   -- Get the contact/tp time zone
7431   --
7432   x_timezone := Get_Time_Zone(x_contact_id);
7433 
7434   return x_timezone;
7435 end;
7436 
7437 
7438 FUNCTION differentStrings(st1 VARCHAR2, st2 VARCHAR2) return BOOLEAN
7439 IS
7440 BEGIN
7441   if (st1 is not null and st2 is not null) then
7442     if (st1 = st2) then
7443       return false;
7444     else
7445       return true;
7446     end if;
7447   else
7448     return false;
7449   end if;
7450 END;
7451 
7452 ----------------------------------------------------------------
7453 -- getNeedByDatesToPrint
7454 -- XTANG: in FPJ, we added timestamp to need-by dates.
7455 ----------------------------------------------------------------
7456 Function getNeedByDatesToPrint(auctionID IN number, lineNumber IN number,userDateFormat IN varchar2) return varchar2 AS
7457 outputString varchar2(8000) := '';
7458 x_msg_suffix varchar2(3) := '';
7459 needByFromDate Date := null;
7460 needByToDate Date := null;
7461 sLanguage varchar2(10) := 'US';
7462 cursor c1(auctionID number,lineNumber number) is
7463 select need_by_start_date,need_by_date
7464 from   pon_auction_item_prices_all
7465 where  auction_header_id = auctionID and
7466       line_number = lineNumber;
7467 Begin
7468  begin
7469 sLanguage := USERENV('LANG');
7470 PON_AUCTION_PKG.SessionLanguage := sLanguage;
7471 
7472  open c1(auctionID,lineNumber);
7473     loop
7474        fetch c1 into needByFromDate,needByToDate;
7475      EXIT WHEN c1%NOTFOUND;
7476 end loop;
7477 if needByFromDate IS NOT NULL and needByToDate IS NULL then
7478 return (getMessage('PON_AUC_NEEDBY_ONLY_START_DATE',x_msg_suffix,'FROMDATE',PON_OA_UTIL_PKG.DISPLAY_DATE_TIME(needByFromDate,fnd_profile.value('CLIENT_TIMEZONE_ID'),fnd_profile.value('SERVER_TIMEZONE_ID'),userDateFormat,'N')));
7479 else
7480 if needByFromDate IS NULL and needByToDate IS NOT NULL then
7481 return (getMessage('PON_AUC_NEEDBY_ONLY_END_DATE',x_msg_suffix,'TODATE',PON_OA_UTIL_PKG.DISPLAY_DATE_TIME(needByToDate,fnd_profile.value('CLIENT_TIMEZONE_ID'),fnd_profile.value('SERVER_TIMEZONE_ID'),userDateFormat,'N')));
7482 else
7483 if needByFromDate IS NOT NULL and needByToDate IS NOT NULL then
7484 return (getMessage('PON_AUC_NEEDBY_RANGE',x_msg_suffix,'FROMDATE',PON_OA_UTIL_PKG.DISPLAY_DATE_TIME(needByFromDate,fnd_profile.value('CLIENT_TIMEZONE_ID'),fnd_profile.value('SERVER_TIMEZONE_ID'),userDateFormat,'N'),
7485 'TODATE',PON_OA_UTIL_PKG.DISPLAY_DATE_TIME(needByToDate,fnd_profile.value('CLIENT_TIMEZONE_ID'),fnd_profile.value('SERVER_TIMEZONE_ID'),userDateFormat,'N')));
7486 else return (outputString);
7487           end if;
7488        end if;
7489 end if;
7490     close c1;
7491  exception When others then
7492    return (outputString);
7493  end;
7494 End getNeedByDatesToPrint;
7495 
7496 
7497 
7498 
7499 PROCEDURE AUCTION_PO_SEND (
7500         transaction_code        IN     VARCHAR2,
7501         document_id             IN     NUMBER,
7502   party_id    IN     NUMBER,
7503         debug_mode              IN     PLS_INTEGER,
7504   trigger_id    OUT    NOCOPY  PLS_INTEGER,
7505   retcode            OUT    NOCOPY  PLS_INTEGER,
7506   errmsg      OUT    NOCOPY  VARCHAR2
7507 )
7508 IS
7509 l_seq varchar2(10);
7510 l_ItemType     VARCHAR2(8) := 'PONAUCT';
7511 l_ItemKey      VARCHAR2(240) ;
7512 l_debug_level varchar2(3);
7513 
7514 BEGIN
7515 
7516 trigger_id := 1;
7517 retcode := 0;
7518 errmsg := null;
7519 
7520 l_debug_level := '0';
7521 /* Hardcoded for present
7522 begin
7523   select parameter_value into l_debug_level from pon_operator_parameters where parameter_name ='xmlDebugLevel' ;
7524   exception when others then
7525   l_debug_level := '0';
7526 end;
7527 
7528  select to_char(PON_PO_WF_ITEMKEY_S.NEXTVAL)
7529  into l_seq from sys.dual;
7530 */
7531 -- Hardcoded sequence number not acceptable
7532 l_seq := 9999;
7533 l_itemkey := to_char (document_id)|| '-' || l_seq;
7534 
7535 wf_engine.createProcess     ( ItemType  => l_ItemType,
7536                                   ItemKey   => l_ItemKey,
7537                                   Process   => 'MAIN_AUCTION_PROCESS');
7538 
7539 wf_engine.SetItemAttrText (   itemtype   => l_ItemType,
7540                                         itemkey    => l_ItemKey,
7541                                         aname      => 'XML_EVENT_KEY',
7542                                         avalue     => l_itemkey);
7543 
7544 wf_engine.SetItemAttrText (      itemtype => l_ItemType,
7545                      itemkey  => l_ItemKey,
7546                      aname    => 'ECX_TRANSACTION_TYPE',
7547                      avalue   => 'PON_AUPO');
7548 wf_engine.SetItemAttrText (      itemtype => l_ItemType,
7549                      itemkey  => l_ItemKey,
7550                      aname    => 'ECX_TRANSACTION_SUBTYPE',
7551                      avalue   => 'AUPO');
7552 
7553 wf_engine.SetItemAttrText (      itemtype => l_ItemType,
7554                      itemkey  => l_ItemKey,
7555                      aname    => 'ECX_DOCUMENT_ID',
7556                      avalue   => document_id);
7557 
7558 wf_engine.SetItemAttrText (      itemtype => l_ItemType,
7559                      itemkey  => l_ItemKey,
7560                      aname    => 'ECX_PARTY_ID',
7561                      avalue   => party_id);
7562 
7563 wf_engine.SetItemAttrText (      itemtype => l_ItemType,
7564                      itemkey  => l_ItemKey,
7565                      aname    => 'ECX_PARTY_SITE_ID',
7566                      avalue   => party_id);
7567 
7568 wf_engine.SetItemAttrText (   itemtype => l_ItemType,
7569                           itemkey => l_ItemKey,
7570         aname  => 'ECX_DEBUG_LEVEL',
7571         avalue => l_debug_level );
7572 
7573     -- Bug 4295915: Set the  workflow owner
7574 wf_engine.SetItemOwner(itemtype => l_itemtype,
7575                        itemkey  => l_itemkey,
7576                        owner    => fnd_global.user_name);
7577 
7578 wf_engine.StartProcess ( ItemType  => l_ItemType,
7579                                   ItemKey   => l_ItemKey );
7580 
7581 END AUCTION_PO_SEND;
7582 
7583 PROCEDURE SET_NEW_ITEM_KEY(  itemtype        in varchar2,
7584                                itemkey         in varchar2,
7585                                actid           in number,
7586                                funcmode        in varchar2,
7587                                resultout       out NOCOPY varchar2)
7588 IS
7589 l_doc_id number;
7590 l_xml_event_key varchar2(100);
7591 l_wf_item_seq number;
7592 BEGIN
7593 if (funcmode <> wf_engine.eng_run) then
7594        resultout := wf_engine.eng_null;
7595        return;  --do not raise the exception, as it would end the wflow.
7596 end if;
7597 l_doc_id := Wf_Engine.GetActivityAttrText(itemtype, itemkey, actid,
7598 'ECX_DOCUMENT_ID');
7599 /* sequence number hardcoded
7600 select PON_PO_WF_ITEMKEY_S.nextval into l_wf_item_seq from dual;
7601 */
7602 l_wf_item_seq := 9999;
7603 
7604  l_xml_event_key := to_char(l_doc_id) || '-' || to_char(l_wf_item_seq);
7605 
7606 wf_engine.SetItemAttrText (   itemtype   => itemType,
7607                               itemkey    => itemkey,
7608                               aname      => 'XML_EVENT_KEY',
7609                               avalue     => l_xml_event_key);
7610 
7611 END SET_NEW_ITEM_KEY;
7612 
7613 
7614 
7615 
7616 
7617 
7618  PROCEDURE CLOSEDATE_EARLIER_REMINDERDATE(  itemtype    in varchar2,
7619            itemkey    in varchar2,
7620                        actid           in number,
7621                        uncmode    in varchar2,
7622              resultout       out NOCOPY varchar2)
7623   IS
7624 
7625      x_closedate   DATE;
7626      x_reminderdate     DATE;
7627      x_this_auction_header_id   NUMBER;
7628 
7629 BEGIN
7630 
7631     x_this_auction_header_id := wf_engine.GetItemAttrNumber (itemtype => itemtype,
7632                                                         itemkey  => itemkey,
7633                                                        aname    => 'AUCTION_ID');
7634 
7635    SELECT close_bidding_date, reminder_date
7636      INTO x_closedate, x_reminderdate
7637      FROM pon_auction_headers_all
7638      WHERE auction_header_id=x_this_auction_header_id;
7639 
7640 
7641     IF (x_closedate<x_reminderdate) THEN
7642   resultout := 'Y';
7643     ELSE
7644   resultout := 'N';
7645 
7646     END IF;
7647 
7648 END;
7649 
7650 PROCEDURE  update_ack_to_YES (        itemtype    in varchar2,
7651              itemkey    in varchar2,
7652              actid           in number,
7653              uncmode    in varchar2,
7654              resultout          out NOCOPY varchar2)
7655 
7656   IS
7657 
7658      x_trading_partner_id     NUMBER;
7659      x_wf_user_name    VARCHAR2(100);
7660      x_doc_number NUMBER;
7661      x_note     VARCHAR2(4000);
7662      x_closedate DATE;
7663      x_now DATE;
7664      x_auction_status VARCHAR2(100);
7665      x_vendor_site_id NUMBER;
7666 
7667 BEGIN
7668 
7669 
7670     x_wf_user_name := wf_engine.GetItemAttrText (itemtype => itemtype,
7671                                              itemkey  => itemkey,
7672              aname    => 'BIDDER_TP_CONTACT_NAME');
7673 
7674     x_trading_partner_id := wf_engine.GetItemAttrNumber (itemtype => itemtype,
7675                                              itemkey  => itemkey,
7676                                                aname    => 'TRADING_PARTNER_ID');
7677 
7678     x_vendor_site_id := wf_engine.GetItemAttrNumber (itemtype => itemtype,
7679                                              itemkey  => itemkey,
7680                                                aname    => 'VENDOR_SITE_ID');
7681 
7682     x_doc_number := wf_engine.GetItemAttrNumber (itemtype => itemtype,
7683                                              itemkey  => itemkey,
7684                                      aname    => 'AUCTION_ID'); /* using auction_id instead of
7685                                                                               auction_number as a standard
7686                                                                               across item types */
7687 
7688 
7689         x_note :=  wf_engine.GetItemAttrText (itemtype => itemtype,
7690                                              itemkey  => itemkey,
7691              aname    => 'NOTE_TO_BUYER');
7692 
7693    SELECT close_bidding_date,auction_status
7694      INTO x_closedate, x_auction_status
7695      FROM pon_auction_headers_all
7696      WHERE auction_header_id=x_doc_number;
7697 
7698    x_now := SYSDATE;
7699 
7700    IF (x_closedate>x_now AND x_auction_status<>'CANCELLED' AND x_auction_status<>'DELETED') then
7701 
7702         UPDATE pon_bidding_parties
7703   SET supp_acknowledgement='Y',
7704     ack_note_to_auctioneer = x_note,
7705           ack_partner_contact_id = trading_partner_contact_id,
7706           acknowledgement_time = x_now
7707         WHERE (trading_partner_id= x_trading_partner_id
7708          or  wf_user_name= x_wf_user_name )
7709          and nvl(vendor_site_id, -1) = nvl(x_vendor_site_id , -1)
7710          and auction_header_id=x_doc_number;
7711 
7712        x_doc_number :=x_doc_number;
7713 
7714    END IF;
7715 
7716    END update_ack_to_yes;
7717 
7718 
7719 
7720 
7721 PROCEDURE  UPDATE_ACK_TO_NO (        itemtype    in varchar2,
7722              itemkey    in varchar2,
7723              actid           in number,
7724              uncmode    in varchar2,
7725              resultout          out NOCOPY varchar2)
7726 
7727   IS
7728 
7729      x_trading_partner_id     NUMBER;
7730      x_wf_user_name    VARCHAR2(100);
7731      x_doc_number NUMBER;
7732      x_note     VARCHAR2(4000);
7733      x_closedate DATE;
7734      x_now DATE;
7735      x_auction_status VARCHAR2(100);
7736      x_vendor_site_id NUMBER;
7737 
7738 
7739    BEGIN
7740 
7741 
7742     x_wf_user_name := wf_engine.GetItemAttrText (itemtype => itemtype,
7743                                              itemkey  => itemkey,
7744              aname    => 'BIDDER_TP_CONTACT_NAME');
7745 
7746     x_trading_partner_id := wf_engine.GetItemAttrNumber (itemtype => itemtype,
7747                                              itemkey  => itemkey,
7748                                                aname    => 'TRADING_PARTNER_ID');
7749 
7750     x_vendor_site_id := wf_engine.GetItemAttrNumber (itemtype => itemtype,
7751                                              itemkey  => itemkey,
7752                                                aname    => 'VENDOR_SITE_ID');
7753 
7754     x_doc_number := wf_engine.GetItemAttrNumber (itemtype => itemtype,
7755                                              itemkey  => itemkey,
7756                                      aname    => 'AUCTION_ID'); /* using auction_id instead of
7757                                                                               auction_number as a standard
7758                                                                               across item types */
7759 
7760         x_note :=  wf_engine.GetItemAttrText (itemtype => itemtype,
7761                                              itemkey  => itemkey,
7762              aname    => 'NOTE_TO_BUYER');
7763 
7764   SELECT close_bidding_date,auction_status
7765      INTO x_closedate, x_auction_status
7766      FROM pon_auction_headers_all
7767      WHERE auction_header_id=x_doc_number;
7768 
7769    x_now := SYSDATE;
7770 
7771    IF (x_closedate>x_now AND x_auction_status<>'CANCELLED' AND x_auction_status<>'DELETED') then
7772 
7773 
7774         UPDATE pon_bidding_parties
7775   SET supp_acknowledgement='N',
7776     ack_note_to_auctioneer = x_note,
7777           ack_partner_contact_id = trading_partner_contact_id,
7778           acknowledgement_time = x_now
7779        WHERE (trading_partner_id= x_trading_partner_id
7780          or  wf_user_name= x_wf_user_name )
7781          and nvl(vendor_site_id,-1) = nvl(x_vendor_site_id,-1)
7782          and auction_header_id=x_doc_number;
7783 
7784        x_doc_number :=x_doc_number;
7785 
7786    END IF;
7787 
7788    END update_ack_to_no;
7789 
7790 
7791    PROCEDURE launch_init_notif_proc(itemtype IN VARCHAR2,
7792             itemkey  IN VARCHAR2,
7793             actid    IN NUMBER,
7794             uncmode  IN VARCHAR2,
7795             resultout OUT NOCOPY VARCHAR2)
7796      IS
7797 
7798 --  x_process VARCHAR2;
7799   x_progress VARCHAR2(3);
7800 --  x_notification_id NUMBER;
7801 
7802    BEGIN
7803 
7804  --     x_process :='NOT_BIDDERS_AUC_START';
7805       x_progress :='010';
7806 
7807 
7808       launch_notif_process(p_itemtype => itemtype,
7809          p_itemkey => itemkey,
7810          p_actid => actid,
7811          p_process => 'NOT_BIDDERS_AUC_START');
7812       x_progress :='020';
7813 
7814    END launch_init_notif_proc;
7815 
7816      PROCEDURE launch_init_notif_p_add(itemtype IN VARCHAR2,
7817             itemkey  IN VARCHAR2,
7818             actid    IN NUMBER,
7819             uncmode  IN VARCHAR2,
7820             resultout OUT NOCOPY VARCHAR2)
7821      IS
7822 
7823 --  x_process VARCHAR2;
7824   x_progress VARCHAR2(3);
7825 --  x_notification_id NUMBER;
7826 
7827    BEGIN
7828 
7829  --     x_process :='NOT_BIDDERS_AUC_START';
7830       x_progress :='010';
7831 
7832 
7833       launch_notif_process(p_itemtype => itemtype,
7834          p_itemkey => itemkey,
7835          p_actid => actid,
7836          p_process => 'NOT_BIDDER_AUC_START_ADD');
7837       x_progress :='020';
7838 
7839      END launch_init_notif_p_add;
7840 
7841         PROCEDURE launch_new_round_notif(itemtype IN VARCHAR2,
7842             itemkey  IN VARCHAR2,
7843             actid    IN NUMBER,
7844             uncmode  IN VARCHAR2,
7845             resultout OUT NOCOPY VARCHAR2)
7846      IS
7847 
7848 --  x_process VARCHAR2;
7849   x_progress VARCHAR2(3);
7850 --  x_notification_id NUMBER;
7851 
7852    BEGIN
7853 
7854  --     x_process :='NOT_BIDDERS_AUC_START';
7855       x_progress :='010';
7856 
7857 
7858       launch_notif_process(p_itemtype => itemtype,
7859          p_itemkey => itemkey,
7860          p_actid => actid,
7861          p_process => 'NOT_NEW_ROUND_START');
7862       x_progress :='020';
7863 
7864    END launch_new_round_notif;
7865 
7866       PROCEDURE launch_new_round_notif_add(itemtype IN VARCHAR2,
7867             itemkey  IN VARCHAR2,
7868             actid    IN NUMBER,
7869             uncmode  IN VARCHAR2,
7870             resultout OUT NOCOPY VARCHAR2)
7871      IS
7872 
7873 --  x_process VARCHAR2;
7874   x_progress VARCHAR2(3);
7875 --  x_notification_id NUMBER;
7876 
7877    BEGIN
7878 
7879  --     x_process :='NOT_BIDDERS_AUC_START';
7880       x_progress :='010';
7881 
7882 
7883       launch_notif_process(p_itemtype => itemtype,
7884          p_itemkey => itemkey,
7885          p_actid => actid,
7886          p_process => 'NOT_NEW_ROUND_START_ADD');
7887       x_progress :='020';
7888 
7889    END launch_new_round_notif_add;
7890 
7891     PROCEDURE launch_added_notif_proc(itemtype IN VARCHAR2,
7892             itemkey  IN VARCHAR2,
7893             actid    IN NUMBER,
7894             uncmode  IN VARCHAR2,
7895             resultout OUT NOCOPY VARCHAR2)
7896      IS
7897 
7898 --  x_process VARCHAR2;
7899   x_progress VARCHAR2(3);
7900 --  x_notification_id NUMBER;
7901 
7902    BEGIN
7903 
7904  --     x_process :='NOT_BIDDERS_AUC_START';
7905       x_progress :='010';
7906 
7907 
7908       launch_notif_process(p_itemtype => itemtype,
7909          p_itemkey => itemkey,
7910          p_actid => actid,
7911          p_process => 'NOT_ADD_BIDDERS_AUC_START');
7912       x_progress :='020';
7913 
7914    END launch_added_notif_proc;
7915 
7916 
7917 PROCEDURE LAUNCH_NOTIF_PROCESS(p_itemtype    in varchar2,
7918              p_itemkey    in varchar2,
7919              p_actid                  IN NUMBER,
7920              p_process   IN VARCHAR2)
7921 
7922 
7923   IS
7924 
7925      x_itemtype    VARCHAR2(8) := 'PONPBLSH';
7926      x_sequence    NUMBER;
7927      x_itemkey    VARCHAR2(50);
7928      x_auction_header_id          NUMBER;
7929      x_tp_id                      NUMBER;
7930 
7931 BEGIN
7932 
7933       SELECT pon_auction_wf_publish_s.nextval
7934       INTO   x_sequence
7935       FROM   dual;
7936       x_itemkey := (p_itemkey||'-'||to_char(x_sequence));
7937 
7938       wf_engine.CreateProcess(itemtype => x_itemtype,
7939                             itemkey  => x_itemkey,
7940             process  => p_process);
7941 
7942       wf_engine.SetItemAttrText (itemtype   => x_itemtype,
7943                                  itemkey    => x_itemkey,
7944                                  aname      => 'BIDDER_TP_CONTACT_NAME',
7945                                  avalue     => wf_engine.GetItemAttrText (itemtype => p_itemtype,
7946                     itemkey  => p_itemkey,
7947                     aname    => 'BIDDER_TP_CONTACT_NAME'));
7948 
7949       wf_engine.SetItemAttrText (itemtype   => x_itemtype,
7950                                  itemkey    => x_itemkey,
7951                                  aname      => 'ORIGIN_USER_NAME',
7952                                  avalue     => wf_engine.GetItemAttrText (itemtype => p_itemtype,
7953                     itemkey  => p_itemkey,
7954                     aname    => 'ORIGIN_USER_NAME'));
7955 
7956        wf_engine.SetItemAttrNumber (itemtype   => x_itemtype,
7957                                  itemkey    => x_itemkey,
7958                                  aname      => 'AUCTION_ID',
7959                                  avalue     => wf_engine.GetItemAttrNumber (itemtype => p_itemtype,
7960                     itemkey  => p_itemkey,
7961                     aname    => 'AUCTION_ID')); /* using auction_id instead of
7962                                                                     auction_number as a standard
7963                                                                     across item types */
7964 
7965        wf_engine.SetItemAttrNumber (itemtype   => x_itemtype,
7966                                  itemkey    => x_itemkey,
7967                                  aname      => 'INVITATION_ID',
7968                                  avalue     => wf_engine.GetItemAttrNumber (itemtype => p_itemtype,
7969                     itemkey  => p_itemkey,
7970                     aname    => 'INVITATION_ID'));
7971 
7972        wf_engine.SetItemAttrText (itemtype   => x_itemtype,
7973                                   itemkey    => x_itemkey,
7974                                   aname      => 'EVENT_TITLE',
7975                                   avalue     => replaceHtmlChars(wf_engine.GetItemAttrText (itemtype => p_itemtype,
7976                                                                              itemkey  => p_itemkey,
7977                                                                              aname    => 'EVENT_TITLE')));
7978 
7979       wf_engine.SetItemAttrText (itemtype   => x_itemtype,
7980                                  itemkey    => x_itemkey,
7981                                  aname      => 'AUCTION_DESCRIPTION',
7982                                  avalue     => replaceHtmlChars(wf_engine.GetItemAttrText (itemtype => p_itemtype,
7983                     itemkey  => p_itemkey,
7984                     aname    => 'AUCTION_DESCRIPTION')));
7985 
7986       wf_engine.SetItemAttrDate (itemtype   => x_itemtype,
7987                                  itemkey    => x_itemkey,
7988                                  aname      => 'AUCTION_START_DATE',
7989                                  avalue     => wf_engine.GetItemAttrDate (itemtype => p_itemtype,
7990                     itemkey  => p_itemkey,
7991                     aname    => 'AUCTION_START_DATE'));
7992 
7993       wf_engine.SetItemAttrDate (itemtype   => x_itemtype,
7994                                  itemkey    => x_itemkey,
7995                                  aname      => 'AUCTION_END_DATE',
7996                                  avalue     => wf_engine.GetItemAttrDate (itemtype => p_itemtype,
7997                     itemkey  => p_itemkey,
7998                     aname    => 'AUCTION_END_DATE'));
7999 
8000       wf_engine.SetItemAttrText (itemtype   => x_itemtype,
8001                                  itemkey    => x_itemkey,
8002                                  aname      => 'NOTE_TO_BIDDERS',
8003                                  avalue     => replaceHtmlChars(wf_engine.GetItemAttrText (itemtype => p_itemtype,
8004                     itemkey  => p_itemkey,
8005                     aname    => 'NOTE_TO_BIDDERS')));
8006 
8007       wf_engine.SetItemAttrText (itemtype   => x_itemtype,
8008                                  itemkey    => x_itemkey,
8009                                  aname      => 'TP_DISPLAY_NAME',
8010                                  avalue     => wf_engine.GetItemAttrText (itemtype => p_itemtype,
8011                     itemkey  => p_itemkey,
8012                     aname    => 'TP_DISPLAY_NAME'));
8013 
8014 
8015       wf_engine.SetItemAttrText (itemtype   => x_itemtype,
8016                                  itemkey    => x_itemkey,
8017                                  aname      => 'PON_AUC_WF_DOC_TYPE_OPEN',
8018                                  avalue     => wf_engine.GetItemAttrText (itemtype => p_itemtype,
8019                     itemkey  => p_itemkey,
8020                     aname    => 'PON_AUC_WF_DOC_TYPE_OPEN'));
8021 
8022        wf_engine.SetItemAttrText (itemtype   => x_itemtype,
8023                                  itemkey    => x_itemkey,
8024                                  aname      => 'PON_AUC_WF_DOC_TYPE_CLOSE',
8025                                  avalue     => wf_engine.GetItemAttrText (itemtype => p_itemtype,
8026                     itemkey  => p_itemkey,
8027                     aname    => 'PON_AUC_WF_DOC_TYPE_CLOSE'));
8028 
8029         wf_engine.SetItemAttrText (itemtype   => x_itemtype,
8030                                  itemkey    => x_itemkey,
8031                                  aname      => 'PON_AUC_WF_PUB_OPEN_RG_S',
8032                                  avalue     => wf_engine.GetItemAttrText (itemtype => p_itemtype,
8033                     itemkey  => p_itemkey,
8034                     aname    => 'PON_AUC_WF_PUB_OPEN_RG_S'));
8035 
8036    wf_engine.SetItemAttrText (itemtype   => x_itemtype,
8037                                  itemkey    => x_itemkey,
8038                                  aname      => 'PON_AUC_WF_PUB_OPEN_RG_M1',
8039                                  avalue     => wf_engine.GetItemAttrText (itemtype => p_itemtype,
8040                     itemkey  => p_itemkey,
8041                     aname    => 'PON_AUC_WF_PUB_OPEN_RG_M1'));
8042 
8043    wf_engine.SetItemAttrText (itemtype   => x_itemtype,
8044                                  itemkey    => x_itemkey,
8045                                  aname      => 'PLACE_BID',
8046                                  avalue     => wf_engine.GetItemAttrText (itemtype => p_itemtype,
8047                     itemkey  =>p_itemkey,
8048                     aname    => 'PLACE_BID'));
8049 
8050     wf_engine.SetItemAttrText (itemtype   => x_itemtype,
8051                                  itemkey    => x_itemkey,
8052                                  aname      => 'PON_AUC_WF_TOACKNOWLEDGE',
8053                                  avalue     => wf_engine.GetItemAttrText (itemtype => p_itemtype,
8054                     itemkey  => p_itemkey,
8055                     aname    => 'PON_AUC_WF_TOACKNOWLEDGE'));
8056 
8057      wf_engine.SetItemAttrText (itemtype   => x_itemtype,
8058                                  itemkey    => x_itemkey,
8059                                  aname      => 'PREPARER_TP_NAME',
8060                                  avalue     => wf_engine.GetItemAttrText (itemtype => p_itemtype,
8061                     itemkey  => p_itemkey,
8062                     aname    => 'PREPARER_TP_NAME'));
8063 
8064 
8065       wf_engine.SetItemAttrNumber (itemtype   => x_itemtype,
8066                                  itemkey    => x_itemkey,
8067                                  aname      => 'NUMBER_OF_ITEMS',
8068                                  avalue     => wf_engine.GetItemAttrNumber (itemtype => p_itemtype,
8069                     itemkey  => p_itemkey,
8070                       aname    => 'NUMBER_OF_ITEMS'));
8071       wf_engine.SetItemAttrText (itemtype   => x_itemtype,
8072                                  itemkey    => x_itemkey,
8073                                  aname      => 'AUCTION_TITLE',
8074                                  avalue     => replaceHtmlChars(wf_engine.GetItemAttrText (itemtype => p_itemtype,
8075                     itemkey  => p_itemkey,
8076                     aname    => 'AUCTION_TITLE')));
8077 
8078 --      wf_engine.SetItemAttrText (itemtype   => x_itemtype,
8079 --                                 itemkey    => x_itemkey,
8080 --                                 aname      => 'OEX_OPERATION',
8081 --                                 avalue     => wf_engine.GetItemAttrText (itemtype => p_itemtype,
8082 --                    itemkey  => p_itemkey,
8083 --                    aname    => 'OEX_OPERATION'));
8084 
8085       wf_engine.SetItemAttrText (itemtype   => x_itemtype,
8086                                  itemkey    => x_itemkey,
8087                                  aname      => 'OEX_OPERATION_URL',
8088                                  avalue     => wf_engine.GetItemAttrText (itemtype => p_itemtype,
8089                     itemkey  => p_itemkey,
8090                     aname    => 'OEX_OPERATION_URL'));
8091         wf_engine.SetItemAttrText (itemtype   => x_itemtype,
8092                                  itemkey    => x_itemkey,
8093                                  aname      => 'TP_TIME_ZONE',
8094                                  avalue     => wf_engine.GetItemAttrText (itemtype => p_itemtype,
8095                     itemkey  => p_itemkey,
8096                     aname    => 'TP_TIME_ZONE'));
8097 
8098       wf_engine.SetItemAttrText (itemtype   => x_itemtype,
8099                                  itemkey    => x_itemkey,
8100                                  aname      => 'AUCTION_TYPE_NAME',
8101                                  avalue     => wf_engine.GetItemAttrText (itemtype => p_itemtype,
8102                     itemkey  => p_itemkey,
8103                     aname    => 'AUCTION_TYPE_NAME'));
8104 
8105 /*
8106       wf_engine.SetItemAttrText (itemtype   => x_itemtype,
8107                                  itemkey    => x_itemkey,
8108                                  aname      => 'OEX_OPERATION_START',
8109                                  avalue     => wf_engine.GetItemAttrText (itemtype => p_itemtype,
8110                     itemkey  => p_itemkey,
8111                     aname    => 'OEX_OPERATION_START'));
8112 
8113 
8114       wf_engine.SetItemAttrText (itemtype   => x_itemtype,
8115                                  itemkey    => x_itemkey,
8116                                  aname      => 'TEXT_HEADER',
8117                                  avalue     => wf_engine.GetItemAttrText (itemtype => p_itemtype,
8118                     itemkey  => p_itemkey,
8119                     aname    => 'TEXT_HEADER'));
8120 
8121       wf_engine.SetItemAttrText (itemtype   => x_itemtype,
8122                                  itemkey    => x_itemkey,
8123                                  aname      => 'TEXT_FOOTER',
8124                                  avalue     => wf_engine.GetItemAttrText (itemtype => p_itemtype,
8125                     itemkey  => p_itemkey,
8126                     aname    => 'TEXT_FOOTER'));
8127 
8128 
8129       wf_engine.SetItemAttrText (itemtype   => x_itemtype,
8130                                  itemkey    => x_itemkey,
8131                                  aname      => 'HTML_HEADER',
8132                                  avalue     => wf_engine.GetItemAttrText (itemtype => p_itemtype,
8133                     itemkey  => p_itemkey,
8134                     aname    => 'HTML_HEADER'));
8135 
8136       wf_engine.SetItemAttrText (itemtype   => x_itemtype,
8137                                  itemkey    => x_itemkey,
8138                                  aname      => 'HTML_FOOTER',
8139                                  avalue     => wf_engine.GetItemAttrText (itemtype => p_itemtype,
8140                     itemkey  => p_itemkey,
8141                     aname    => 'HTML_FOOTER'));
8142 */
8143       wf_engine.SetItemAttrText (itemtype   => x_itemtype,
8144                                  itemkey    => x_itemkey,
8145                                  aname      => 'TP_LANGUAGE_CODE',
8146                                  avalue     => wf_engine.GetItemAttrText (itemtype => p_itemtype,
8147                     itemkey  => p_itemkey,
8148                     aname    => 'TP_LANGUAGE_CODE'));
8149 
8150       wf_engine.SetItemAttrText (itemtype   => x_itemtype,
8151                                  itemkey    => x_itemkey,
8152                                  aname      => 'PON_AUC_WF_DOC_TITLE',
8153                                  avalue     => wf_engine.GetItemAttrText (itemtype => p_itemtype,
8154                     itemkey  => p_itemkey,
8155                     aname    => 'PON_AUC_WF_DOC_TITLE'));
8156 
8157 
8158       wf_engine.SetItemAttrText (itemtype   => x_itemtype,
8159                                  itemkey    => x_itemkey,
8160                                  aname      => 'PON_AUC_WF_DOC_NUM',
8161                                  avalue     => wf_engine.GetItemAttrText (itemtype => p_itemtype,
8162                     itemkey  => p_itemkey,
8163                     aname    => 'PON_AUC_WF_DOC_NUM'));
8164 
8165       wf_engine.SetItemAttrText (itemtype   => x_itemtype,
8166                                  itemkey    => x_itemkey,
8167                                  aname      => 'PON_AUC_WF_DOC_EVENT',
8168                                  avalue     => wf_engine.GetItemAttrText (itemtype => p_itemtype,
8169                     itemkey  => p_itemkey,
8170                     aname    => 'PON_AUC_WF_DOC_EVENT'));
8171 
8172       wf_engine.SetItemAttrText (itemtype   => x_itemtype,
8173                                  itemkey    => x_itemkey,
8174                                  aname      => 'PON_AUC_WF_PUB_NEWRND_M1',
8175                                  avalue     => wf_engine.GetItemAttrText (itemtype => p_itemtype,
8176                     itemkey  => p_itemkey,
8177                     aname    => 'PON_AUC_WF_PUB_NEWRND_M1'));
8178 
8179       wf_engine.SetItemAttrText (itemtype   => x_itemtype,
8180                                  itemkey    => x_itemkey,
8181                                  aname      => 'PON_AUC_WF_PUB_NEWRND_M2',
8182                                  avalue     => wf_engine.GetItemAttrText (itemtype => p_itemtype,
8183                     itemkey  => p_itemkey,
8184                     aname    => 'PON_AUC_WF_PUB_NEWRND_M2'));
8185 
8186      wf_engine.SetItemAttrText (itemtype   => x_itemtype,
8187                                  itemkey    => x_itemkey,
8188                                  aname      => 'PON_AUC_WF_PUB_NEWRND_RG_S',
8189                                  avalue     => wf_engine.GetItemAttrText (itemtype => p_itemtype,
8190                     itemkey  => p_itemkey,
8191                     aname    => 'PON_AUC_WF_PUB_NEWRND_RG_S'));
8192 
8193       wf_engine.SetItemAttrText (itemtype   => x_itemtype,
8194                                  itemkey    => x_itemkey,
8195                                  aname      => 'PON_AUC_WF_AUCTIONEER',
8196                                  avalue     => wf_engine.GetItemAttrText (itemtype => p_itemtype,
8197                     itemkey  => p_itemkey,
8198                     aname    => 'PON_AUC_WF_AUCTIONEER'));
8199 
8200  wf_engine.SetItemAttrText (itemtype   => x_itemtype,
8201                                  itemkey    => x_itemkey,
8202                                  aname      => 'PREVIEW_MESSAGE',
8203                                  avalue     => wf_engine.GetItemAttrText (itemtype => p_itemtype,
8204                     itemkey  => p_itemkey,
8205                     aname    => 'PREVIEW_MESSAGE'));
8206 
8207    wf_engine.SetItemAttrDate (itemtype   => x_itemtype,
8208                                  itemkey    => x_itemkey,
8209                                  aname      => 'AUCTION_NOTIFICATION_DATE',
8210                                  avalue     => wf_engine.GetItemAttrDate (itemtype => p_itemtype,
8211                     itemkey  => p_itemkey,
8212                     aname    => 'AUCTION_NOTIFICATION_DATE'));
8213 
8214     wf_engine.SetItemAttrText (itemtype   => x_itemtype,
8215                                  itemkey    => x_itemkey,
8216                                  aname      => 'TP_TIME_ZONE1',
8217                                  avalue     => wf_engine.GetItemAttrText (itemtype => p_itemtype,
8218                     itemkey  => p_itemkey,
8219                     aname    => 'TP_TIME_ZONE1'));
8220 
8221      wf_engine.SetItemAttrText (itemtype   => x_itemtype,
8222                                  itemkey    => x_itemkey,
8223                                  aname      => 'ARTICLE_DOC_TYPE',
8224                                  avalue     => wf_engine.GetItemAttrText (itemtype => p_itemtype,
8225                     itemkey  => p_itemkey,
8226                     aname    => 'ARTICLE_DOC_TYPE'));
8227  wf_engine.SetItemAttrText (itemtype   => x_itemtype,
8228                                  itemkey    => x_itemkey,
8229                                  aname      => 'APPSTR',
8230                                  avalue     => wf_engine.GetItemAttrText (itemtype => p_itemtype,
8231                     itemkey  => p_itemkey,
8232                     aname    => 'APPSTR'));
8233 
8234 
8235  wf_engine.SetItemAttrText (itemtype   => x_itemtype,
8236                                  itemkey    => x_itemkey,
8237                                  aname      => 'APP',
8238                                  avalue     => wf_engine.GetItemAttrText (itemtype => p_itemtype,
8239                     itemkey  => p_itemkey,
8240                     aname    => 'APP'));
8241 
8242  wf_engine.SetItemAttrText (itemtype   => x_itemtype,
8243                                  itemkey    => x_itemkey,
8244                                  aname      => 'DOC_NUMBER',
8245                                  avalue     => wf_engine.GetItemAttrText (itemtype => p_itemtype,
8246                     itemkey  => p_itemkey,
8247                     aname    => 'DOC_NUMBER'));
8248 
8249        wf_engine.SetItemAttrNumber (itemtype   => x_itemtype,
8250                                  itemkey    => x_itemkey,
8251                                  aname      => 'TRADING_PARTNER_ID',
8252                                  avalue     => wf_engine.GetItemAttrNumber (itemtype => p_itemtype,
8253                     itemkey  => p_itemkey,
8254                     aname    => 'TRADING_PARTNER_ID'));
8255 
8256  wf_engine.SetItemAttrText (itemtype   => x_itemtype,
8257                                  itemkey    => x_itemkey,
8258                                  aname      => 'ADDITIONAL_CONTACT_USERNAME',
8259                                  avalue     => wf_engine.GetItemAttrText (itemtype => p_itemtype,
8260                     itemkey  => p_itemkey,
8261                     aname    => 'ADDITIONAL_CONTACT_USERNAME'));
8262 
8263  wf_engine.SetItemAttrText (itemtype   => x_itemtype,
8264                                  itemkey    => x_itemkey,
8265                                  aname      => 'PON_AUC_WF_DOC_IN_PR0G',
8266                                  avalue     => wf_engine.GetItemAttrText (itemtype => p_itemtype,
8267                     itemkey  => p_itemkey,
8268                     aname    => 'PON_AUC_WF_DOC_IN_PR0G'));
8269 
8270  wf_engine.SetItemAttrText (itemtype   => x_itemtype,
8271                                  itemkey    => x_itemkey,
8272                                  aname      => 'PON_AUC_WF_LOGON_BEFORE',
8273                                  avalue     => wf_engine.GetItemAttrText (itemtype => p_itemtype,
8274                     itemkey  => p_itemkey,
8275                     aname    => 'PON_AUC_WF_LOGON_BEFORE'));
8276 
8277     -- Bug 4295915: Set the  workflow owner
8278  wf_engine.SetItemOwner(itemtype => x_itemtype,
8279                         itemkey  => x_itemkey,
8280                         owner    => fnd_global.user_name);
8281 
8282  wf_engine.StartProcess(itemtype => x_itemtype,
8283                         itemkey  => x_itemkey );
8284 
8285  -- For members, store item key in pom_bidding_parties
8286  x_auction_header_id := wf_engine.GetItemAttrNumber(itemtype => p_itemtype,
8287                                                     itemkey  => p_itemkey,
8288                                                     aname    => 'AUCTION_ID'); /* using auction_id instead of
8289                                                                                  auction_number as a standard
8290                                                                                  across item types */
8291 
8292  x_tp_id := wf_engine.GetItemAttrNumber (itemtype => p_itemtype,
8293                                     itemkey  => p_itemkey,
8294                                          aname    => 'TRADING_PARTNER_ID');
8295 
8296 
8297  UPDATE pon_bidding_parties set
8298  wf_item_key = x_itemkey
8299  WHERE trading_partner_id = x_tp_id
8300  AND auction_header_id = x_auction_header_id;
8301 
8302 
8303 END LAUNCH_NOTIF_PROCESS;
8304 
8305 PROCEDURE NOTIFY_BIDDER_LIST_REMINDER(itemtype    in varchar2,
8306                               itemkey    in varchar2,
8307                               actid           in number,
8308                               uncmode    in varchar2,
8309                               resultout          out NOCOPY varchar2)
8310 IS
8311 
8312     x_doc_number                   NUMBER;
8313     x_neg_summary_url_supplier     VARCHAR2(2000);
8314     x_isp_supplier_register_url    VARCHAR2(2000);
8315     x_ack_part_url_supplier        VARCHAR2(2000);
8316     x_auction_tp_contact_name      PON_AUCTION_HEADERS_ALL.TRADING_PARTNER_CONTACT_NAME%TYPE;
8317     x_preview_date                DATE;
8318     x_preview_date_notspec         VARCHAR2(240);
8319     x_timezone1_disp               VARCHAR2(240);
8320 -- Bug 3824928: Removed obsolete columns
8321 CURSOR bidders IS
8322    select
8323      fu.user_name my_user_name,
8324      pbd.trading_partner_id,
8325      pbd.trading_partner_name my_user_display_name,
8326      decode(pbd.vendor_site_code, '-1', null, pbd.vendor_site_code) vendor_site_code,
8327      pbd.wf_user_name additional_name,
8328      pbd.wf_item_key,
8329      pbd.additional_contact_email,
8330      pbd.registration_id,
8331      pbd.trading_partner_contact_id, -- Bug 3824928 added
8332      pbd.vendor_site_id
8333    from pon_bidding_parties pbd,
8334         fnd_user fu
8335    WHERE pbd.trading_partner_contact_id=fu.person_party_id (+) AND -- Bug 3824928: added outer join
8336           nvl(fu.end_date, sysdate+1) > sysdate  AND                                -- Added for TCA project
8337           pbd.auction_header_id=x_doc_number AND
8338           nvl(pbd.supp_acknowledgement,'havenot')= 'havenot'
8339           and pbd.trading_partner_id is not null;
8340 
8341    -- Bug 3824928: Removed union below
8342 
8343     x_language_code varchar2(30);
8344   x_auctioneer_user_name VARCHAR2(60);
8345     x_profile_user VARCHAR2(60);
8346   x_member_flag VARCHAR2(3);
8347     x_message_name varchar2(80);
8348   x_process_name VARCHAR2(80);
8349   x_text_header varchar2(540) := '';
8350   x_text_footer varchar2(540) := '';
8351   x_doc_internal_name varchar2(60) := '';
8352   x_msg_suffix varchar2(3) := '';
8353   x_nid number;
8354   x_newendtime          DATE;
8355   x_itemtype    VARCHAR2(8) := 'PONPBLSH';
8356     x_itemkey    VARCHAR2(50);
8357   x_sequence    NUMBER;
8358   x_auction_tp_name PON_AUCTION_HEADERS_ALL.TRADING_PARTNER_NAME%TYPE := '';
8359     x_auction_contact_dp_name varchar2(240) := '';
8360   x_tp_display_name varchar2(240) :='';
8361   x_auction_title varchar2(240) := '';
8362   x_auction_start_date date;
8363   x_auction_end_date date;
8364   x_operation_url   VARCHAR2(300);
8365   x_invitation_id number;
8366   x_oex_operation   VARCHAR2(640);
8367   x_wf_item_key VARCHAR2(240);
8368   x_appstr VARCHAR2(20);
8369   x_app VARCHAR2(20);
8370   x_oex_timezone VARCHAR2(80);
8371   x_person_party_id NUMBER(15);
8372   x_timezone    VARCHAR2(80);
8373   x_newstarttime          DATE;
8374   x_doc_number_dsp   VARCHAR2(30);
8375   x_bids_by_company NUMBER;
8376   x_commits_by_company NUMBER;
8377   x_total_participations NUMBER;
8378   x_timezone_disp  VARCHAR2(240);
8379     x_timezone1    VARCHAR2(80); -- preview timezone
8380     x_newpreviewtime  DATE;
8381     x_timezone1_dsp         VARCHAR2(240);
8382 
8383     -- Added the following declaration for Affiliate ID related changes
8384     -- Auctioneer's trading partner id
8385     x_tp_id NUMBER;
8386 
8387     x_registration_key VARCHAR2(100);
8388 
8389     l_origin_user_name   fnd_user.user_name%TYPE;
8390 
8391 BEGIN
8392 
8393             x_doc_number := wf_engine.GetItemAttrNumber (itemtype   => itemtype,
8394                                                    itemkey    => itemkey,
8395                                                    aname      => 'AUCTION_ID');
8396 
8397           x_doc_internal_name := wf_engine.GetItemAttrText (itemtype   => itemtype,
8398                                                               itemkey    => itemkey,
8399                                                 aname      => 'DOC_INTERNAL_NAME');
8400 
8401              BEGIN
8402                  x_preview_date := wf_engine.GetItemAttrDate (itemtype   => itemtype,
8403                                                               itemkey    => itemkey,
8404                                                      aname      => 'PREVIEW_DATE');
8405 
8406                  x_preview_date_notspec := wf_engine.GetItemAttrText (itemtype => itemtype,
8407                                                                       itemkey  => itemkey,
8408                                                                       aname    => 'PREVIEW_DATE_NOTSPECIFIED');
8409              EXCEPTION
8410            WHEN NO_DATA_FOUND
8411            THEN
8412            -- Assigning null to the item attributes
8413                x_preview_date := null;
8414                  x_preview_date_notspec := null;
8415              WHEN OTHERS
8416            THEN
8417                RAISE;
8418            END;
8419 
8420         x_msg_suffix := GET_MESSAGE_SUFFIX (x_doc_internal_name);
8421 
8422       x_doc_number_dsp     := wf_engine.GetItemAttrText   (itemtype => itemtype,
8423                                                              itemkey  => itemkey,
8424                                                             aname    => 'DOC_NUMBER');
8425         x_oex_timezone := Get_Oex_Time_Zone;
8426 
8427 --        x_auction_tp_contact_name  := wf_engine.GetItemAttrText (itemtype   => itemtype,
8428 --                                                                 itemkey    => itemkey,
8429 --                                                                 aname      => 'PREPARER_TP_CONTACT_NAME');
8430 
8431 
8432       x_auction_tp_name := wf_engine.GetItemAttrText (itemtype   => itemtype,
8433                                                         itemkey    => itemkey,
8434                                           aname      => 'PREPARER_TP_NAME');
8435 
8436       x_auction_contact_dp_name := wf_engine.GetItemAttrText (itemtype   => itemtype,
8437                                                         itemkey    => itemkey,
8438                                           aname      => 'PREPARER_CONTACT_DP_NAME');
8439 
8440        x_auction_title := wf_engine.GetItemAttrText (itemtype   => itemtype,
8441                                                     itemkey    => itemkey,
8442                                                     aname      => 'AUCTION_TITLE');
8443 
8444        l_origin_user_name := wf_engine.GetItemAttrText (itemtype   => itemtype,
8445                                                           itemkey    => itemkey,
8446                                                           aname      => 'ORIGIN_USER_NAME');
8447 
8448       x_auction_start_date := wf_engine.GetItemAttrDate (itemtype   => itemtype,
8449                                                     itemkey    => itemkey,
8450                                                     aname      => 'AUCTION_START_DATE');
8451 
8452       x_auction_end_date := wf_engine.GetItemAttrDate (itemtype   => itemtype,
8453                                                     itemkey    => itemkey,
8454                                                     aname      => 'AUCTION_END_DATE');
8455 
8456      begin
8457     SELECT wf_item_key
8458     INTO x_wf_item_key
8459     FROM pon_auction_headers_all
8460     WHERE auction_header_id=x_doc_number;
8461 
8462        select trading_partner_id, trading_partner_contact_name
8463           into x_tp_id, x_auction_tp_contact_name
8464           from pon_auction_headers_all
8465           where auction_header_id = x_doc_number;
8466 
8467      END;
8468 
8469 
8470      FOR bidder IN bidders LOOP --{
8471 
8472   SELECT COUNT(bid_number)
8473     INTO x_bids_by_company
8474     FROM pon_bid_headers
8475     WHERE auction_header_id=x_doc_number
8476     AND trading_partner_id=bidder.trading_partner_id;
8477 
8478   x_total_participations :=x_bids_by_company;
8479 
8480 
8481   IF(x_total_participations=0) then
8482 
8483       x_member_flag :='Y';
8484       x_process_name :='REMIND_MEMBERS_PROCESS';
8485      -- Bug 3824928: Trading partner contact id can be null
8486        IF bidder.trading_partner_contact_id is not null then -- {
8487          PON_PROFILE_UTIL_PKG.GET_WF_LANGUAGE(bidder.my_user_name,x_language_code);
8488 
8489 
8490           BEGIN
8491             SELECT person_party_id
8492         INTO x_person_party_id
8493         FROM fnd_user
8494         WHERE user_name = bidder.my_user_name;
8495           EXCEPTION
8496           WHEN TOO_MANY_ROWS THEN
8497             null;  -- This can never throw too many row exception
8498           END;
8499 
8500       -- Get the user's time zone
8501       --
8502     x_timezone := Get_Time_Zone(x_person_party_id);
8503 
8504       --
8505       -- Make sure that it is a valid time zone
8506       --
8507 
8508       IF (PON_OEX_TIMEZONE_PKG.VALID_ZONE(x_timezone) = 0) THEN
8509        x_timezone := x_oex_timezone;
8510       END IF;
8511 
8512       -- Create new timezone
8513       IF (PON_OEX_TIMEZONE_PKG.VALID_ZONE(x_timezone) = 1) THEN
8514         x_newstarttime   := PON_OEX_TIMEZONE_PKG.CONVERT_TIME(x_auction_start_date,x_oex_timezone,x_timezone);
8515         x_newendtime     := PON_OEX_TIMEZONE_PKG.CONVERT_TIME(x_auction_end_date,x_oex_timezone,x_timezone);
8516         x_newpreviewtime := PON_OEX_TIMEZONE_PKG.CONVERT_TIME(x_preview_date,x_oex_timezone,x_timezone);
8517       ELSE
8518         x_newstarttime   := x_auction_start_date;
8519       x_newendtime     := x_auction_end_date;
8520         x_newpreviewtime := x_preview_date;
8521       END IF;
8522     END IF; -- IF bidder.trading_partner_contact_id is not null
8523 
8524     -- Bug 3824928: Checking if additional_contact_email is not null
8525     if bidder.additional_contact_email is not null then -- {
8526 
8527            if bidder.trading_partner_contact_id is null then -- {
8528                          -- use auctioneer's language
8529                          --x_auctioneer_user_name := wf_engine.GetItemAttrText (itemtype => 'PONAUCT',
8530                          --                                                     itemkey  => x_wf_item_key,
8531                          --                                                     aname    => 'PREPARER_TP_CONTACT_NAME');
8532                          x_auctioneer_user_name := x_auction_tp_contact_name;
8533 
8534                          PON_PROFILE_UTIL_PKG.GET_WF_LANGUAGE(x_auctioneer_user_name,x_language_code);
8535 
8536                          -- get auctioneer's timezone
8537                          x_timezone := Get_Time_Zone(x_auctioneer_user_name);
8538 
8539                          --
8540                          -- Make sure that it is a valid time zone
8541                          --
8542 
8543                          IF (PON_OEX_TIMEZONE_PKG.VALID_ZONE(x_timezone) = 0) THEN
8544                             x_timezone := x_oex_timezone;
8545                          END IF;
8546 
8547                          -- Create new timezone
8548                          x_newstarttime := PON_OEX_TIMEZONE_PKG.CONVERT_TIME(x_auction_start_date,x_oex_timezone,x_timezone);
8549                          x_newendtime   := PON_OEX_TIMEZONE_PKG.CONVERT_TIME(x_auction_end_date,x_oex_timezone,x_timezone);
8550 
8551 
8552              end if; -- }
8553 
8554       end if; -- }
8555 
8556        IF (x_language_code is not null) THEN
8557            IF (FND_LOG.level_statement >= FND_LOG.g_current_runtime_level) THEN --{
8558                 FND_LOG.string(log_level => FND_LOG.level_statement,
8559                   module => g_module_prefix || 'NOTIFY_BIDDER_LIST_REMINDER',
8560                   message  => '8. Calling SET_SESSION_LANGUAGE with x_language_code : ' || x_language_code);
8561            END IF; --}
8562 
8563         SET_SESSION_LANGUAGE(null, x_language_code);
8564        END IF;
8565 
8566     SELECT pon_auction_wf_publish_s.nextval
8567       INTO   x_sequence
8568       FROM   dual;
8569 
8570       x_tp_display_name := bidder.my_user_display_name;
8571 
8572       x_itemkey := (itemkey||'-'||to_char(x_sequence));
8573 
8574       wf_engine.CreateProcess(itemtype => x_itemtype,
8575                               itemkey  => x_itemkey,
8576                         process  => x_process_name);
8577 
8578       wf_engine.SetItemAttrText (itemtype => x_itemtype,
8579                                itemkey    => x_itemkey,
8580                                aname      => 'PREPARER_TP_CONTACT_NAME',
8581                                avalue     => x_auction_tp_contact_name);
8582 
8583       wf_engine.SetItemAttrText (itemtype => x_itemtype,
8584                                itemkey    => x_itemkey,
8585                                aname      => 'ORIGIN_USER_NAME',
8586                                avalue     => l_origin_user_name);
8587 
8588       wf_engine.SetItemAttrText (itemtype => x_itemtype,
8589                                itemkey    => x_itemkey,
8590                                aname      => 'BIDDER_TP_NAME',
8591                                avalue     => bidder.my_user_display_name);
8592 
8593      wf_engine.SetItemAttrText (itemtype  => x_itemtype,
8594                                itemkey    => x_itemkey,
8595                                aname      => 'BIDDER_TP_ADDRESS_NAME',
8596                                avalue     => bidder.vendor_site_code);
8597 
8598 
8599      wf_engine.SetItemAttrText (itemtype  => x_itemtype,
8600              itemkey  => x_itemkey,
8601              aname  => 'REGISTERED',
8602         avalue  => x_member_flag);
8603 
8604      wf_engine.SetItemAttrText   (itemtype => x_itemtype,
8605           itemkey  => x_itemkey,
8606           aname    => 'DOC_NUMBER',
8607           avalue   => x_doc_number_dsp);
8608 
8609 
8610       wf_engine.SetItemAttrText (itemtype  => x_itemtype,
8611              itemkey  => x_itemkey,
8612              aname  => 'BIDDER_TP_CONTACT_NAME',
8613          avalue  => bidder.my_user_name);
8614 
8615 
8616      wf_engine.SetItemAttrText (itemtype  => x_itemtype,
8617                                   itemkey  => x_itemkey,
8618                            aname=> 'PREPARER_TP_NAME',
8619          avalue  => x_auction_tp_name);
8620 
8621 
8622               wf_engine.SetItemAttrNumber (itemtype  => x_itemtype,
8623              itemkey  => x_itemkey,
8624              aname  => 'TRADING_PARTNER_ID',
8625            avalue  => bidder.trading_partner_id);
8626 
8627 
8628             wf_engine.SetItemAttrText (itemtype  => x_itemtype,
8629              itemkey  => x_itemkey,
8630              aname  => 'PREPARER_CONTACT_DP_NAME',
8631          avalue  => x_auction_contact_dp_name);
8632 
8633 
8634               wf_engine.SetItemAttrText (itemtype  => x_itemtype,
8635              itemkey  => x_itemkey,
8636              aname  => 'INVITE_REMINDER_SUB',
8637              avalue  => getMessage('PON_AUC_WF_REQA', x_msg_suffix,
8638                                           'DOC_NUMBER', x_doc_number_dsp,
8639                                           'AUCTION_TITLE', replaceHtmlChars(x_auction_title)));
8640 -- Bug 6965954: START of Code Fix
8641 -- Set the values of AUCTION_START_DATE and AUCTION_END_DATE
8642 -- as the end_date is used to determine the timeout for the notifications
8643 -- sent to the supplier
8644 
8645              wf_engine.SetItemAttrDate     (itemtype   => x_itemtype,
8646                                      itemkey    => x_itemkey,
8647                                      aname      => 'AUCTION_START_DATE',
8648                                      avalue     => x_auction_start_date);
8649 
8650              wf_engine.SetItemAttrDate     (itemtype   => x_itemtype,
8651                                      itemkey    => x_itemkey,
8652                                      aname      => 'AUCTION_END_DATE',
8653                                      avalue     => x_auction_end_date);
8654 
8655 -- Bug 6965954: End of Code Fix
8656 
8657            wf_engine.SetItemAttrText (itemtype  => x_itemtype,
8658              itemkey  => x_itemkey,
8659              aname  => 'TP_DISPLAY_NAME',
8660          avalue  => x_tp_display_name);
8661 
8662 
8663            wf_engine.SetItemAttrText (itemtype  => x_itemtype,
8664              itemkey  => x_itemkey,
8665              aname  => 'AUCTION_TITLE',
8666          avalue  => replaceHtmlChars(x_auction_title));
8667 
8668 
8669            wf_engine.SetItemAttrNumber (itemtype  => x_itemtype,
8670              itemkey  => x_itemkey,
8671              aname  => 'AUCTION_ID',
8672              avalue  => x_doc_number); /* using auction_id instead of
8673                                                auction_number as a standard
8674                                                across item types */
8675 
8676 
8677               wf_engine.SetItemAttrDate(itemtype  => x_itemtype,
8678              itemkey  => x_itemkey,
8679              aname  => 'AUCTION_END_DATE_TZ',
8680          avalue  => x_newendtime);
8681 
8682            wf_engine.SetItemAttrDate (itemtype  => x_itemtype,
8683              itemkey  => x_itemkey,
8684              aname  => 'AUCTION_START_DATE_TZ',
8685          avalue  => x_newstarttime);
8686 
8687        -- call to notification utility package to get the redirect page url that
8688        -- is responsible for getting the Neg. Summary url and forward to it.
8689        x_neg_summary_url_supplier := pon_wf_utl_pkg.get_dest_page_url (
8690                               p_dest_func => 'PON_NEG_SUMMARY'
8691                                  ,p_notif_performer  => 'SUPPLIER');
8692 
8693       wf_engine.SetItemAttrText (itemtype  => x_itemtype,
8694                         itemkey    => x_itemkey,
8695                         aname      => 'NEG_SUMMARY_URL',
8696                         avalue      => x_neg_summary_url_supplier);
8697 
8698      -- call to notification utility package to get the redirect page url that
8699        -- is responsible for getting the Acknowledge participation url and forward to it.
8700        x_ack_part_url_supplier := pon_wf_utl_pkg.get_dest_page_url (
8701                               p_dest_func => 'PONRESAPN_ACKPARTICIPATN'
8702                                  ,p_notif_performer  => 'SUPPLIER');
8703 
8704        begin
8705         wf_engine.SetItemAttrText   (itemtype   => x_itemtype,
8706                                          itemkey    => x_itemkey,
8707                                          aname      => '#WFM_HTMLAGENT',
8708                                          avalue     => pon_wf_utl_pkg.get_base_external_supplier_url);
8709         exception
8710           when others then
8711             null;
8712         end;
8713 
8714 
8715       wf_engine.SetItemAttrText (itemtype  => x_itemtype,
8716                         itemkey    => x_itemkey,
8717                         aname      => 'ACK_PARTICIPATION_URL',
8718                         avalue      => x_ack_part_url_supplier);
8719 
8720    x_timezone_disp := Get_TimeZone_Description(x_timezone, x_language_code);
8721      IF (x_preview_date IS NULL) THEN
8722          x_timezone1_disp := null;
8723      ELSE
8724          x_timezone1_disp := x_timezone_disp;
8725      END IF;
8726 
8727            wf_engine.SetItemAttrText (itemtype  => x_itemtype,
8728              itemkey  => x_itemkey,
8729              aname  => 'TP_TIME_ZONE',
8730          avalue  => x_timezone_disp);
8731 
8732   IF (x_preview_date is not null) THEN
8733         wf_engine.SetItemAttrDate (itemtype  => x_itemtype,
8734              itemkey  => x_itemkey,
8735              aname  => 'PREVIEW_DATE_TZ',
8736              avalue   => x_newpreviewtime);
8737 
8738       wf_engine.SetItemAttrText (itemtype  => x_itemtype,
8739                  itemkey   => x_itemkey,
8740                  aname     => 'TP_TIME_ZONE1',
8741                  avalue    => x_timezone1_disp);
8742 
8743         wf_engine.SetItemAttrText (itemtype  => x_itemtype,
8744                            itemkey  => x_itemkey,
8745                            aname  => 'PREVIEW_DATE_NOTSPECIFIED',
8746                            avalue  => null);
8747 
8748   ELSE
8749           wf_engine.SetItemAttrDate (itemtype  => x_itemtype,
8750              itemkey  => x_itemkey,
8751              aname  => 'PREVIEW_DATE_TZ',
8752              avalue     => null);
8753 
8754           wf_engine.SetItemAttrText (itemtype  => x_itemtype,
8755              itemkey  => x_itemkey,
8756              aname  => 'TP_TIME_ZONE1',
8757              avalue     => x_timezone1_disp);
8758 
8759          wf_engine.SetItemAttrText (itemtype  => x_itemtype,
8760                            itemkey  => x_itemkey,
8761                            aname  => 'PREVIEW_DATE_NOTSPECIFIED',
8762                            avalue  => PON_AUCTION_PKG.getMessage('PON_AUC_PREVIEW_DATE_NOTSPEC'));
8763 
8764 
8765     END IF;
8766 
8767 
8768            if (bidder.additional_contact_email is not null) then
8769 
8770                  wf_engine.SetItemAttrText (itemtype   => x_itemtype,
8771                                            itemkey    => x_itemkey,
8772                                    aname      => 'ADDITIONAL_CONTACT_USERNAME',
8773                                    avalue     => bidder.additional_name);
8774 
8775               begin
8776                 select registration_key
8777                   into x_registration_key
8778                   from fnd_registrations
8779                  where registration_id = bidder.registration_id;
8780               exception
8781                   WHEN NO_DATA_FOUND THEN
8782                        x_registration_key := '';
8783               end;
8784 
8785 
8786              -- call to notification utility package to get the iSupplier registration page url
8787              x_isp_supplier_register_url := pon_wf_utl_pkg.get_isp_supplier_register_url(p_registration_key => x_registration_key
8788                                                                                         ,p_language_code => x_language_code);
8789 
8790              wf_engine.SetItemAttrText (itemtype   => x_itemtype,
8791                                         itemkey    => x_itemkey,
8792                                         aname      => 'ISP_SUPPLIER_REG_URL',
8793                                         avalue     => x_isp_supplier_register_url);
8794 
8795            end if;
8796 
8797 
8798     -- Bug 4295915: Set the  workflow owner
8799       wf_engine.SetItemOwner(itemtype => x_itemtype,
8800                              itemkey  => x_itemkey,
8801                              owner    => fnd_global.user_name);
8802 
8803       wf_engine.StartProcess(itemtype => x_itemtype,
8804                              itemkey  => x_itemkey );
8805 
8806       -- Bug 3824928: replacing if x_member_flag ='Y' with IF trading
8807       -- partner contact id is not null
8808 
8809       IF bidder.trading_partner_contact_id IS NOT NULL THEN -- {
8810 
8811         -- For members, store item key in pon_bidding_parties
8812         -- End the previous waiting process
8813         Wf_Engine.AbortProcess(x_itemtype, bidder.wf_item_key, '', null);
8814 
8815         UPDATE pon_bidding_parties set
8816             wf_item_key = x_itemkey
8817         WHERE trading_partner_id = bidder.trading_partner_id
8818         AND auction_header_id = x_doc_number
8819         AND vendor_site_id = bidder.vendor_site_id; -- Supplier/supplier site combination can be different in 11.5.10
8820 
8821        END IF; -- } IF bidder.trading_partner_contact_id IS NOT NULL
8822 
8823        END IF; -- } participation already check
8824 
8825      END LOOP; --}
8826 
8827 
8828 END notify_bidder_list_reminder;
8829 
8830 procedure retrieve_user_info(param1 varchar2) is
8831 type refCurType is Ref Cursor;
8832 param2 integer;
8833 param3  varchar2(2000);
8834 param4  varchar2(2000);
8835 param5  varchar2(2000);
8836 param6  varchar2(2000);
8837 param7  varchar2(2000);
8838 param8  varchar2(2000);
8839 param9  varchar2(2000);
8840 param11  varchar2(2000);
8841 param12  varchar2(2000);
8842 param14  varchar2(2000);
8843 param15  varchar2(2000);
8844 param16  varchar2(2000);
8845 param18  varchar2(2000);
8846 param19  varchar2(2000);
8847 param20  varchar2(2000);
8848 param21  refCurType;
8849 param22  integer;
8850 param23  integer;
8851 param24  integer;
8852 param25  integer;
8853 param26  varchar2(2000);
8854 param27  varchar2(2000);
8855 param28  varchar2(2000);
8856 param29  integer;
8857 param30  varchar2(2000);
8858 param31  varchar2(2000);
8859 param32  varchar2(2000);
8860 param33  refCurType;
8861 param34  varchar2(2000);
8862 param35  varchar2(2000);
8863 param36  varchar2(2000);
8864 param37  varchar2(2000);
8865 
8866 begin
8867 -- this is tricky there are just 20 vars as input in the new fn.
8868 
8869 g_userName := param1;
8870 end retrieve_user_info;
8871 
8872 /*======================================================================
8873  PROCEDURE :  DELETE_NEGOTIATION_LINE_REF    PUBLIC
8874  PARAMETERS:
8875   x_negotiation_id        in      auction header id
8876   x_negotiation_line_num  in      negotiation line number
8877   x_org_id                in      organization id
8878 x  x_error_code            out     internal code for error
8879 
8880  COMMENT   : delete negotiation line references
8881 ======================================================================*/
8882 PROCEDURE DELETE_NEGOTIATION_LINE_REF (
8883     x_negotiation_id        in   number,
8884     x_negotiation_line_num  in   number,
8885     x_org_id                in   number,
8886     x_error_code            out  NOCOPY varchar2) is
8887 
8888 BEGIN
8889 
8890       -- first, remove records in pon_backing_requisitions
8891       delete
8892         from  pon_backing_requisitions
8893        where  auction_header_id = x_negotiation_id
8894          and  line_number = x_negotiation_line_num;
8895 
8896       -- remove negotiation references in po_requisition_lines
8897       -- and return the requisitions to the req pool
8898       PO_NEGOTIATIONS_SV1.DELETE_NEGOTIATION_REF(
8899   X_NEGOTIATION_ID  =>  x_negotiation_id,
8900   X_NEGOTIATION_LINE_NUM  =>  x_negotiation_line_num,
8901   X_ERROR_CODE    =>  x_error_code);
8902 
8903 END DELETE_NEGOTIATION_LINE_REF;
8904 
8905 /*======================================================================
8906  PROCEDURE :  DELETE_NEGOTIATION_REF    PUBLIC
8907  PARAMETERS:
8908   x_negotiation_id        in      auction header id
8909   x_error_code            out     internal code for error
8910 
8911  COMMENT   : delete negotiation references
8912 ======================================================================*/
8913 PROCEDURE DELETE_NEGOTIATION_REF (
8914    x_negotiation_id in  number,
8915    x_error_code     out NOCOPY varchar2) is
8916 
8917 BEGIN
8918 
8919       PO_NEGOTIATIONS_SV1.DELETE_NEGOTIATION_REF(
8920   X_NEGOTIATION_ID  =>  x_negotiation_id,
8921   X_NEGOTIATION_LINE_NUM  =>  null,
8922   X_ERROR_CODE    =>  x_error_code);
8923 
8924 END DELETE_NEGOTIATION_REF;
8925 
8926 /*======================================================================
8927  PROCEDURE :  CANCEL_NEGOTIATION_REF   PUBLIC
8928  PARAMETERS:
8929   x_negotiation_id        in      auction header id
8930   x_error_code            out     internal code for error
8931 
8932  COMMENT   : cancel negotiation references
8933 ======================================================================*/
8934 PROCEDURE CANCEL_NEGOTIATION_REF (
8935    x_negotiation_id in  number,
8936    x_error_code     out NOCOPY varchar2) is
8937 
8938 BEGIN
8939 
8940       -- return backing requisitions to the req pool
8941       PO_NEGOTIATIONS_SV1.UPDATE_REQ_POOL(
8942   X_NEGOTIATION_ID  =>  x_negotiation_id,
8943   X_NEGOTIATION_LINE_NUM  =>  null,
8944   X_FLAG_VALUE    =>  'Y',
8945   X_ERROR_CODE    =>  x_error_code);
8946 
8947 END CANCEL_NEGOTIATION_REF;
8948 
8949 /*======================================================================
8950  PROCEDURE :  UPDATE_NEGOTIATION_REF   PUBLIC
8951  PARAMETERS:
8952   x_old_negotiation_id   in   old auction header id
8953   x_old_negotiation_num  in   old auction display number
8954   x_new_negotiation_id   in   new auction header id
8955   x_new_negotiation_num  in   new auction display number
8956   x_error_code           out  internal code for error
8957   x_error_message        out  error message
8958 
8959  COMMENT   : update negotiation references
8960 ======================================================================*/
8961 PROCEDURE UPDATE_NEGOTIATION_REF(
8962     x_old_negotiation_id   in   number,
8963     x_old_negotiation_num  in   varchar2,
8964     x_new_negotiation_id   in   number,
8965     x_new_negotiation_num  in   varchar2,
8966     x_error_code           out  NOCOPY varchar2,
8967     x_error_message        out  NOCOPY varchar2  ) is
8968 
8969 l_line_number number;
8970 
8971 CURSOR deletedItems IS
8972      SELECT LINE_NUMBER
8973       FROM  PON_AUCTION_ITEM_PRICES_ALL
8974      WHERE  auction_header_id = x_old_negotiation_id and
8975             line_number not in ( select line_number
8976                                    from PON_AUCTION_ITEM_PRICES_ALL
8977                                   where auction_header_id = x_new_negotiation_id);
8978 
8979 BEGIN
8980 
8981       PO_NEGOTIATIONS_SV1.UPDATE_NEGOTIATION_REF(
8982   X_OLD_NEGOTIATION_ID  =>  x_old_negotiation_id,
8983   X_NEW_NEGOTIATION_ID  =>  x_new_negotiation_id,
8984   X_NEW_NEGOTIATION_NUM  =>  x_new_negotiation_num,
8985   X_ERROR_CODE    =>  x_error_code);
8986 
8987       -- the above routine does't use FND constants,
8988       -- while UPDATE_NEGOTIATION_LINE_REF does, so convert it.
8989       IF (x_error_code = 'SUCCESS') THEN
8990    x_error_code := FND_API.G_RET_STS_SUCCESS;
8991       END IF;
8992 
8993       -- changes for FPI. For items that are carried over from previous round
8994       -- update the corresponding backing requisition references (no change
8995       -- from FPH).
8996       -- For items that are deleted between rounds, do nothing (ie, keep
8997       -- the references, references are cleared in FPH).
8998       -- We can either update only the carried over items or update all items
8999       -- and change deleted items back.
9000       -- Use the second approach here based on the assumption that a small
9001       -- number of items are deleted between rounds.
9002 
9003       -- some items may be deleted between rounds. Remove corresponding references
9004       -- and return requisition back to pool (FPH)
9005       OPEN deletedItems;
9006       LOOP
9007         FETCH deletedItems INTO
9008           l_line_number;
9009         EXIT WHEN deletedItems%NOTFOUND OR (x_error_code <> FND_API.G_RET_STS_SUCCESS);
9010 
9011       --  PO_NEGOTIATIONS_SV1.DELETE_NEGOTIATION_REF(x_new_negotiation_id, l_line_number, x_error_code);
9012 
9013         PO_NEGOTIATIONS_SV1.UPDATE_NEGOTIATION_LINE_REF(
9014     P_API_VERSION      =>  1.0,
9015     P_OLD_NEGOTIATION_ID    =>  x_new_negotiation_id,
9016     P_OLD_NEGOTIATION_LINE_NUM  =>  l_line_number,
9017     P_NEW_NEGOTIATION_ID    =>  x_old_negotiation_id,
9018     P_NEW_NEGOTIATION_LINE_NUM  =>  l_line_number,
9019     P_NEW_NEGOTIATION_NUM    =>  x_old_negotiation_num,
9020     X_RETURN_STATUS      =>  x_error_code,
9021     X_ERROR_MESSAGE      =>  x_error_message);
9022       END LOOP;
9023 
9024       -- FPI: bug 2811671 still need to return the req back to pool
9025       IF (x_error_code = FND_API.G_RET_STS_SUCCESS) THEN
9026         PO_NEGOTIATIONS_SV1.UPDATE_REQ_POOL(
9027     X_NEGOTIATION_ID    =>  x_old_negotiation_id,
9028     X_NEGOTIATION_LINE_NUM     =>  null,
9029     X_FLAG_VALUE      =>  'Y',
9030     X_ERROR_CODE      =>  x_error_code);
9031       END IF;
9032 
9033       -- convert fnd constant to our own internal code
9034       IF (x_error_code = FND_API.G_RET_STS_SUCCESS) THEN
9035    x_error_code := 'SUCCESS';
9036       END IF;
9037 
9038 END UPDATE_NEGOTIATION_REF;
9039 
9040 /*======================================================================
9041  PROCEDURE :  COPY_BACKING_REQ  PUBLIC
9042  PARAMETERS:
9043   x_old_negotiation_id   in   old auction header id
9044   x_new_negotiation_id   in   new auction header id
9045   x_error_code           out  internal code for error
9046 
9047  COMMENT   : update negotiation references
9048 ======================================================================*/
9049 PROCEDURE COPY_BACKING_REQ(x_old_negotiation_id in  number,
9050                            x_new_negotiation_id in  number,
9051                            x_error_code         out NOCOPY varchar2) is
9052 
9053 neg_item_count    NUMBER;
9054 l_count           NUMBER;
9055 
9056 l_line_number     NUMBER;
9057 l_req_header_id   NUMBER;
9058 l_req_line_id     NUMBER;
9059 l_req_quantity    NUMBER;
9060 l_req_number      pon_backing_requisitions.requisition_number%TYPE;
9061 
9062 CURSOR backingReqs IS
9063      SELECT LINE_NUMBER,
9064             REQUISITION_HEADER_ID,
9065             REQUISITION_LINE_ID,
9066             REQUISITION_QUANTITY,
9067             REQUISITION_NUMBER
9068       FROM  PON_BACKING_REQUISITIONS
9069      WHERE  auction_header_id = x_old_negotiation_id;
9070 
9071 BEGIN
9072    IF(x_new_negotiation_id IS NOT NULL) THEN
9073      OPEN backingReqs;
9074      LOOP
9075        FETCH backingReqs INTO
9076          l_line_number,
9077          l_req_header_id,
9078          l_req_line_id,
9079          l_req_quantity,
9080          l_req_number;
9081        EXIT WHEN backingReqs%NOTFOUND;
9082 
9083        SELECT count(*)
9084          INTO l_count
9085          FROM PON_BACKING_REQUISITIONS
9086         WHERE auction_header_id = x_new_negotiation_id and
9087               line_number = l_line_number and
9088               requisition_header_id = l_req_header_id and
9089               requisition_line_id = l_req_line_id;
9090 
9091        -- check if the item is still in the next round negotiation
9092        SELECT count(*)
9093    INTO neg_item_count
9094          FROM PON_AUCTION_ITEM_PRICES_ALL
9095         WHERE auction_header_id = x_new_negotiation_id and
9096               line_number = l_line_number;
9097 
9098        IF ((l_count = 0) AND (neg_item_count) = 1) THEN
9099           INSERT INTO PON_BACKING_REQUISITIONS(
9100             AUCTION_HEADER_ID,
9101             LINE_NUMBER,
9102             REQUISITION_HEADER_ID,
9103             REQUISITION_LINE_ID,
9104             REQUISITION_QUANTITY,
9105             REQUISITION_NUMBER)
9106           VALUES (
9107             x_new_negotiation_id,
9108             l_line_number,
9109             l_req_header_id,
9110             l_req_line_id,
9111             l_req_quantity,
9112             l_req_number);
9113        END IF;
9114      END LOOP;
9115   END IF;
9116 
9117   x_error_code := 'SUCCESS';
9118 
9119 EXCEPTION
9120 WHEN OTHERS THEN
9121     x_error_code := 'FAILURE';
9122 
9123 END COPY_BACKING_REQ;
9124 
9125 
9126 /*======================================================================
9127  PROCEDURE :  CANCEL_NEGOTIATION_REF_BY_LINE   PUBLIC
9128  PARAMETERS:
9129   x_negotiation_id        in      auction header id
9130   x_negotiation_line_id   in      line number
9131   x_error_code            out     internal code for error
9132 
9133  COMMENT   : cancel negotiation references
9134 ======================================================================*/
9135 PROCEDURE CANCEL_NEGOTIATION_REF_BY_LINE (
9136    x_negotiation_id in  number,
9137    x_negotiation_line_id number,
9138    x_error_code     out NOCOPY varchar2) is
9139 
9140 BEGIN
9141 
9142       -- return backing requisitions to the req pool
9143       PO_NEGOTIATIONS_SV1.UPDATE_REQ_POOL(
9144     X_NEGOTIATION_ID  =>  x_negotiation_id,
9145     X_NEGOTIATION_LINE_NUM   =>  x_negotiation_line_id,
9146     X_FLAG_VALUE    =>  'Y',
9147     X_ERROR_CODE    =>  x_error_code);
9148 
9149 END CANCEL_NEGOTIATION_REF_BY_LINE;
9150 
9151 
9152 PROCEDURE Check_Unique_Wrapper(X_Segment1 In VARCHAR2,
9153                                X_rowid IN VARCHAR2,
9154                                X_Type_lookup_code IN VARCHAR2,
9155                                X_Unique OUT NOCOPY VARCHAR2) is
9156 BEGIN
9157   IF (PO_HEADERS_PKG_S2.Check_Unique(X_Segment1, X_rowid, X_Type_lookup_code)) THEN
9158     X_Unique := 'T';
9159     RETURN;
9160   ELSE
9161     X_Unique := 'F';
9162     RETURN;
9163   END IF;
9164 EXCEPTION
9165   WHEN NO_DATA_FOUND THEN
9166     X_Unique := 'F';
9167     RETURN;
9168   WHEN OTHERS THEN
9169     raise;
9170 END Check_Unique_Wrapper;
9171 
9172 FUNCTION CHECK_UNIQUE_ORDER_NUMBER (p_auction_id IN NUMBER,
9173                                 p_order_number IN VARCHAR2)
9174 RETURN VARCHAR2 IS
9175   v_contract_type pon_auction_headers_all.contract_type%TYPE;
9176   v_org_id pon_auction_headers_all.org_id%TYPE;
9177   v_old_org_id NUMBER;
9178   v_old_policy VARCHAR2(1);
9179   v_is_unique VARCHAR2(1);
9180 
9181 BEGIN
9182    -- Get the current policy
9183    v_old_policy := mo_global.get_access_mode();
9184    v_old_org_id := mo_global.get_current_org_id();
9185 
9186    if (fnd_log.level_statement >= fnd_log.g_current_runtime_level) then
9187      fnd_log.string(
9188         fnd_log.level_statement,
9189         g_module || '.check_unique_order_number',
9190         'old_policy = ' || v_old_policy || ', old_org_id = ' || v_old_org_id);
9191    end if;
9192 
9193    -- Get the org id for the negotiation
9194    SELECT org_id, contract_type
9195    INTO   v_org_id, v_contract_type
9196    FROM   pon_auction_headers_all
9197    WHERE  auction_header_id = p_auction_id;
9198 
9199    -- Set the connection's policy context
9200    mo_global.set_policy_context('S', v_org_id);
9201 
9202    PON_AUCTION_PKG.Check_Unique_Wrapper(p_order_number, null,
9203                                         v_contract_type, v_is_unique);
9204 
9205    -- Set the org context back
9206    mo_global.set_policy_context(v_old_policy, v_old_org_id);
9207 
9208    return v_is_unique;
9209 EXCEPTION
9210   WHEN NO_DATA_FOUND THEN
9211      return 'E';
9212         WHEN OTHERS THEN
9213            RETURN 'E';
9214 
9215 END CHECK_UNIQUE_ORDER_NUMBER;
9216 
9217 
9218 /* This procedure helps to send the response back to workflow for
9219    Acknowledgments.
9220 */
9221 
9222 PROCEDURE ACK_NOTIF_RESPONSE(p_wf_item_key VARCHAR2,
9223                              p_user_name   VARCHAR2,
9224                              p_supp_ack    VARCHAR2,
9225                              p_ack_note    VARCHAR2,
9226                              x_return_status OUT NOCOPY NUMBER)
9227 
9228 is
9229 
9230 l_supp_ack varchar2(10);
9231 l_notification_id number;
9232 l_activity_status wf_item_activity_statuses.ACTIVITY_STATUS%type;
9233 
9234 begin
9235 
9236     BEGIN
9237 
9238    select   notification_id,   ACTIVITY_STATUS
9239       into   l_notification_id, l_activity_status
9240     from   wf_item_activity_statuses
9241     where   item_key  = p_wf_item_key
9242     and   item_type  = 'PONPBLSH'
9243     and   notification_id is not null
9244   and   activity_status = 'NOTIFIED'
9245     and   rownum    = 1;
9246 
9247    EXCEPTION
9248   WHEN NO_DATA_FOUND THEN
9249     -- Do we want to fail this procedure if we there's no such email sent?
9250     -- x_return_status   := 1;
9251     l_notification_id := -9999;
9252    END;
9253 
9254   IF p_supp_ack ='Y' then
9255      l_supp_ack :='A-YES';
9256   ELSIF p_supp_ack='N' THEN
9257      l_supp_ack :='B-NO';
9258   END IF;
9259 
9260   if (l_notification_id > 0) then
9261      Wf_Notification.SetAttrText(l_notification_id, 'RESULT', l_supp_ack);
9262      Wf_Notification.SetAttrText(l_notification_id, 'NOTE_TO_BUYER', p_ack_note);
9263      Wf_Notification.Respond(l_notification_id, 'On-Line', p_user_name);
9264   end if;
9265 
9266   x_return_status := 0;
9267 
9268  EXCEPTION
9269 
9270   WHEN OTHERS THEN
9271           x_return_status := 1;
9272 
9273 end ACK_NOTIF_RESPONSE;
9274 
9275 PROCEDURE ACK_NOTIF_RESPONSE(p_wf_item_key VARCHAR2,
9276                              p_user_name   VARCHAR2,
9277                              p_supp_ack    VARCHAR2,
9278                              p_ack_note    VARCHAR2)
9279 IS
9280 
9281   v_temp NUMBER;
9282 
9283 BEGIN
9284 
9285     ACK_NOTIF_RESPONSE(p_wf_item_key, p_user_name, p_supp_ack, p_ack_note, v_temp);
9286 
9287 END;
9288 
9289 /* Implemented as part of bug 2809753.  Move logic for
9290    NegotiationDoc.getTimeRemaining() to pl/sql procedure to bypass binding
9291    of timestamps on sql arithmetic operations, which causes problems on
9292    certain jdbc versions */
9293 
9294 PROCEDURE GET_TIME_REMAINING(p_auction_header_id IN NUMBER,
9295                              p_time_remaining OUT NOCOPY FLOAT) is
9296 begin
9297   select (sysdate - close_bidding_date) into p_time_remaining
9298   from pon_auction_headers_all
9299   where auction_header_id = p_auction_header_id;
9300 
9301 EXCEPTION
9302   WHEN OTHERS THEN
9303       RAISE;
9304 end GET_TIME_REMAINING;
9305 
9306 FUNCTION get_product_install_status ( x_product_name IN VARCHAR2) RETURN VARCHAR2 IS
9307   x_progress     VARCHAR2(3) := NULL;
9308   x_app_id       NUMBER;
9309   x_install      BOOLEAN;
9310   x_status       VARCHAR2(1);
9311   x_org          VARCHAR2(1);
9312   x_temp_product_name varchar2(10);
9313 begin
9314   --Retreive product id from fnd_application based on product name
9315   x_progress := 10;
9316 
9317   select application_id
9318   into   x_app_id
9319   from   fnd_application
9320   where application_short_name = x_product_name ;
9321 
9322   --get product installation status
9323   x_progress := 20;
9324   x_install := fnd_installation.get(x_app_id,x_app_id,x_status,x_org);
9325 
9326   if (x_install)
9327   THEN
9328     x_status := 'Y';
9329   ELSE
9330     x_status := 'N';
9331   end if;
9332 
9333   RETURN(x_status);
9334 
9335   EXCEPTION
9336     WHEN NO_DATA_FOUND then
9337       null;
9338       RETURN(null);
9339     WHEN OTHERS THEN
9340       RAISE;
9341 
9342 end get_product_install_status;
9343 
9344 
9345 
9346 function getPhoneNumber(p_user_name varchar2) return varchar2 is
9347 begin
9348 if g_userName is null or g_userName <> p_user_name then
9349 retrieve_user_info(p_user_name);
9350 end if;
9351 return g_phoneNumber;
9352 end getPhoneNumber;
9353 
9354 function getFaxNumber(p_user_name varchar2) return varchar2 is
9355 begin
9356 if g_userName is null or g_userName <> p_user_name then
9357 retrieve_user_info(p_user_name);
9358 end if;
9359 return g_faxNumber;
9360 end getFaxNumber;
9361 
9362 function getEMail(p_user_name varchar2) return varchar2 is
9363 begin
9364 if g_userName is null or g_userName <> p_user_name then
9365 retrieve_user_info(p_user_name);
9366 end if;
9367 return g_eMail;
9368 end getEMail;
9369 
9370 
9371 procedure getTriangulationRate(toCurrency varchar2,
9372                               fromCurrency varchar2,
9373                               rateDate date,
9374                               rateType varchar2,
9375                               rollDays number,
9376                               rate out nocopy number
9377                               ) is
9378 denom number;
9379 num number;
9380 
9381 begin
9382 GL_CURRENCY_API.get_closest_triangulation_Rate(toCurrency,fromCurrency,rateDate,null,rollDays,denom,num,rate);
9383 
9384 end getTriangulationRate;
9385 
9386 
9387 function getClosestRate(fromCurrency varchar2,
9388                         toCurrency varchar2,
9389                         conversionDate date,
9390                         conversionType varchar2,
9391                         maxRollDays number) return varchar2 is
9392   x_rate number;
9393 begin
9394   x_rate := GL_CURRENCY_API.get_closest_rate(fromCurrency, toCurrency, conversionDate, conversionType, maxRollDays);
9395   return x_rate;
9396 end getClosestRate;
9397 
9398 
9399 /*======================================================================
9400  PROCEDURE :  DELETE_NEGOTIATION_AMENDMENTS    PUBLIC
9401  PARAMETERS:
9402   x_negotiation_id        in      auction header id
9403   x_error_code            out     internal code for error
9404 
9405  COMMENT   : delete negotiation amendments created
9406 ======================================================================*/
9407 PROCEDURE DELETE_NEGOTIATION_AMENDMENTS (
9408     x_negotiation_id        in   number,
9409     x_error_code            out  NOCOPY varchar2) is
9410 
9411 BEGIN
9412 
9413     x_error_code := 'SUCCESS';
9414 
9415     BEGIN
9416 
9417   UPDATE PON_AUCTION_HEADERS_ALL
9418   SET AUCTION_STATUS = 'DELETED'
9419   WHERE
9420     AUCTION_HEADER_ID_ORIG_AMEND IS NOT NULL
9421   AND  AUCTION_HEADER_ID_ORIG_AMEND = x_negotiation_id;
9422 
9423   UPDATE PON_AUCTION_HEADERS_ALL
9424   SET AUCTION_STATUS = 'DELETED'
9425   WHERE
9426     AUCTION_HEADER_ID  = x_negotiation_id;
9427 
9428      EXCEPTION
9429 
9430   WHEN OTHERS THEN
9431     x_error_code := 'FAILURE';
9432      END;
9433 
9434 END DELETE_NEGOTIATION_AMENDMENTS;
9435 
9436 /*======================================================================
9437  *  PROCEDURE :  GET_MOST_RECENT_AMENDMENT    PUBLIC
9438  *   PARAMETERS:
9439  *     x_negotiation_id        in      auction header id
9440  *
9441  *        COMMENT   : returns the auction header id of the most recent active
9442  *        amendment
9443  *        ======================================================================*/
9444 FUNCTION GET_MOST_RECENT_AMENDMENT(p_auction_header_id IN NUMBER) RETURN NUMBER
9445 
9446 IS
9447 
9448     v_auction_status               VARCHAR2(25);
9449     v_auction_header_id_orig_amend NUMBER;
9450     v_most_recent_amendment        NUMBER;
9451 
9452 
9453 BEGIN
9454 
9455     select auction_status
9456     into   v_auction_status
9457     from   pon_auction_headers_all
9458     where  auction_header_id = p_auction_header_id;
9459 
9460     IF (v_auction_status = 'AMENDED') THEN
9461 
9462       select auction_header_id_orig_amend
9463       into   v_auction_header_id_orig_amend
9464       from   pon_auction_headers_all
9465       where  auction_header_id = p_auction_header_id;
9466 
9467       select auction_header_id
9468       into   v_most_recent_amendment
9469       from   pon_auction_headers_all
9470       where  auction_header_id_orig_amend = v_auction_header_id_orig_amend and
9471              auction_status <> 'AMENDED' and auction_status <> 'DRAFT' and
9472              rownum = 1;  -- rownum = 1 is a sanity check
9473 
9474     ELSE
9475 
9476       v_most_recent_amendment := p_auction_header_id;
9477 
9478     END IF;
9479 
9480    RETURN v_most_recent_amendment;
9481 
9482 END GET_MOST_RECENT_AMENDMENT;
9483 
9484 FUNCTION GET_MEMBER_TYPE(p_auction_header_id IN NUMBER,p_user_id IN NUMBER) RETURN VARCHAR2
9485 IS
9486     v_member_type               VARCHAR2(1);
9487 BEGIN
9488     v_member_type   := 'X';
9489     select nvl(member_type,'X')
9490                 into v_member_type
9491                 from pon_neg_team_members
9492     where auction_header_id =p_auction_header_id
9493     and user_id = p_user_id;
9494 
9495                 return v_member_type;
9496 END GET_MEMBER_TYPE;
9497 
9498 
9499 -- this procedure is added for header price break default
9500 -- The procedure determines the price_break_response for pon_auction_headers_all table.
9501 -- It's used in plsql routines where new negotiation created,
9502 -- including negotiation copy/new round/amendment, autocreation and renegotiation.
9503 -- The logic is same as AuctionHeadersAllEO
9504 
9505 PROCEDURE get_default_hdr_pb_settings (p_doctype_id IN NUMBER,
9506                                        p_tp_id IN NUMBER,
9507                                        x_price_break_response OUT NOCOPY VARCHAR2) IS
9508 
9509         l_pref_unused_1       VARCHAR2(300);
9510         l_pref_unused_2       VARCHAR2(300);
9511         l_pref_unused_3       VARCHAR2(300);
9512 
9513         l_price_break_display_flag PON_AUC_DOCTYPE_RULES.display_flag%type;
9514 
9515 BEGIN
9516 
9517         select display_flag
9518           into l_price_break_display_flag
9519           from PON_AUC_DOCTYPE_RULES dr,
9520                PON_AUC_BIZRULES b
9521          where b.bizrule_id = dr.bizrule_id
9522            and dr.doctype_id = p_doctype_id
9523            and b.name = 'PRICE_BREAK';
9524 
9525         if (l_price_break_display_flag = 'N') then
9526            x_price_break_response := 'NONE';
9527         else
9528 
9529            BEGIN
9530                 PON_PROFILE_UTIL_PKG.RETRIEVE_PARTY_PREF_COVER(
9531                                 p_party_id        => p_tp_id,
9532                                 p_app_short_name  => 'PON',
9533                                 p_pref_name       => 'PRICE_BREAK_RESPONSE_TYPE',
9534                                 x_pref_value      => x_price_break_response,
9535                                 x_pref_meaning    => l_pref_unused_1,
9536                                 x_status          => l_pref_unused_2,
9537                                 x_exception_msg   => l_pref_unused_3);
9538 
9539                                 IF  (l_pref_unused_2 <> FND_API.G_RET_STS_SUCCESS) THEN
9540                                         x_price_break_response := 'NONE';
9541                                 END IF;
9542 
9543            EXCEPTION
9544                 WHEN OTHERS THEN
9545                         x_price_break_response := 'NONE';
9546            END;
9547 
9548         end if;
9549 
9550 END get_default_hdr_pb_settings;
9551 
9552 
9553 -- this procedure is added for header price break default
9554 -- The procedure determines the price_break_type and price_break_neg_flag
9555 -- for pon_auction_item_prices_all table.
9556 -- It assumes the auction header already exists.
9557 -- It's used in plsql routines where lines are inserted, including line spreadsheet upload,
9558 -- negotiation copy/new round/amendment, autocreation and renegotiation.
9559 
9560 PROCEDURE get_default_pb_settings (p_auction_header_id IN NUMBER,
9561                                    x_price_break_type OUT NOCOPY VARCHAR2,
9562                                    x_price_break_neg_flag OUT NOCOPY VARCHAR2) IS
9563 
9564 l_price_break_response                pon_auction_headers_all.price_break_response%type;
9565 l_contract_type                       pon_auction_headers_all.contract_type%type;
9566 l_doctype_id                          pon_auction_headers_all.doctype_id%type;
9567 l_po_style_id                         pon_auction_headers_all.po_style_id%type;
9568 l_template_id                         pon_auction_headers_all.template_id%type;
9569 l_template_pb_type                    pon_auction_item_prices_all.price_break_type%type;
9570 l_org_id                              pon_auction_headers_all.org_id%type;
9571 l_po_pb_type                          po_system_parameters_all.price_break_lookup_code%type;
9572 l_price_break_display_flag            PON_AUC_DOCTYPE_RULES.display_flag%type;
9573 l_price_break_enabled_flag            VARCHAR2(1);
9574 l_price_break_allowed                 VARCHAR2(1);
9575 l_price_tiers_indicator               pon_auction_headers_all.price_tiers_indicator%type;
9576 
9577 l_dummy1     VARCHAR2(240);
9578 l_dummy2     VARCHAR2(240);
9579 l_dummy3     VARCHAR2(30);
9580 l_dummy4     VARCHAR2(30);
9581 l_dummy5     VARCHAR2(1);
9582 l_dummy6     VARCHAR2(1);
9583 l_dummy7     VARCHAR2(1);
9584 l_dummy8     VARCHAR2(1);
9585 l_dummy9     VARCHAR2(1);
9586 l_dummy10    VARCHAR2(30);
9587 
9588 BEGIN
9589 
9590       select contract_type, doctype_id, price_break_response, po_style_id, template_id, org_id, price_tiers_indicator
9591         into l_contract_type, l_doctype_id, l_price_break_response, l_po_style_id, l_template_id, l_org_id, l_price_tiers_indicator
9592         from pon_auction_headers_all
9593        where auction_header_id = p_auction_header_id;
9594 
9595       select display_flag
9596         into l_price_break_display_flag
9597         from PON_AUC_DOCTYPE_RULES dr,
9598              PON_AUC_BIZRULES b
9599        where b.bizrule_id = dr.bizrule_id
9600          and dr.doctype_id = l_doctype_id
9601          and b.name = 'PRICE_BREAK';
9602 
9603 
9604       -- invoke po api to get price break setting for the po style
9605       BEGIN
9606                 PO_DOC_STYLE_GRP.GET_DOCUMENT_STYLE_SETTINGS(
9607                                                    P_API_VERSION => '1.0',
9608                                                    P_STYLE_ID    => l_po_style_id,
9609                                                    X_STYLE_NAME  => l_dummy1,
9610                                                    X_STYLE_DESCRIPTION => l_dummy2,
9611                                                    X_STYLE_TYPE  => l_dummy3,
9612                                                    X_STATUS => l_dummy4,
9613                                                    X_ADVANCES_FLAG => l_dummy5,
9614                                                    X_RETAINAGE_FLAG => l_dummy6,
9615                                                    X_PRICE_BREAKS_FLAG => l_price_break_enabled_flag,
9616                                                    X_PRICE_DIFFERENTIALS_FLAG => l_dummy7,
9617                                                    X_PROGRESS_PAYMENT_FLAG=> l_dummy8,
9618                                                    X_CONTRACT_FINANCING_FLAG=> l_dummy9,
9619                                                    X_LINE_TYPE_ALLOWED  => l_dummy10);
9620 
9621       EXCEPTION
9622                 WHEN OTHERS THEN
9623                     l_price_break_enabled_flag := 'Y';
9624       END;
9625 
9626 
9627       -- if price break doesn't apply, set to NONE
9628       -- check if price break is allowed
9629       if ( l_price_break_display_flag = 'Y' and
9630            (l_contract_type = 'BLANKET' or l_contract_type = 'CONTRACT') and
9631            l_price_break_enabled_flag = 'Y') then
9632 
9633             l_price_break_allowed := 'Y';
9634       else
9635             l_price_break_allowed := 'N';
9636             l_price_break_response := 'NONE';
9637       end if;
9638 
9639 
9640       if (l_price_break_allowed = 'N' or l_price_break_response = 'NONE' or l_price_tiers_indicator = 'QUANTITY_BASED' ) then
9641            -- not allowed by biz rule or header setting is NONE
9642            x_price_break_type := 'NONE';
9643       else
9644            x_price_break_type := 'NON-CUMULATIVE';
9645 
9646            -- if negotiation has template, use template setting if template is CUMULATIVE or NON CUMULATIVE
9647            if (l_template_id is not null) then
9648 
9649                    BEGIN
9650                        select price_break_type
9651                          into l_template_pb_type
9652                          from pon_auction_item_prices_all
9653                         where auction_header_id = l_template_id;
9654                    EXCEPTION
9655                          WHEN OTHERS THEN
9656                              l_template_pb_type := 'NONE';
9657                    END;
9658 
9659                    if (l_template_pb_type <> 'NONE') then
9660                         x_price_break_type := l_template_pb_type;
9661                    end if;
9662            else
9663            -- get the setting from po price break setting for the specified org
9664                    BEGIN
9665                         select decode(price_break_lookup_code, 'NON CUMULATIVE',
9666                                       'NON-CUMULATIVE', price_break_lookup_code)
9667                           into l_po_pb_type
9668                           from po_system_parameters_all
9669                          where org_id = l_org_id;
9670                    EXCEPTION
9671                          WHEN OTHERS THEN
9672                              l_po_pb_type := 'NON-CUMULATIVE';
9673                    END;
9674 
9675                    x_price_break_type := l_po_pb_type;
9676            end if;
9677       end if;
9678 
9679 
9680       if (l_price_break_response = 'REQUIRED') then
9681          x_price_break_neg_flag := 'N';
9682       else
9683          x_price_break_neg_flag := 'Y';
9684       end if;
9685 
9686 END get_default_pb_settings;
9687 
9688 
9689 -- Used in Complex work
9690 --returns whether Projects is installed for current org or not
9691 FUNCTION getPAOUInstalled (p_orgId IN NUMBER) RETURN VARCHAR2 IS
9692     l_progress     VARCHAR2(3) := NULL;
9693     l_app_id       NUMBER;
9694     l_install      BOOLEAN;
9695     l_status       VARCHAR2(1);
9696   begin
9697     l_progress := 10;
9698     --get Projects  installation status
9699     return  PA_UTILS4.IsProjectsImplemented(p_orgId);
9700 
9701 EXCEPTION
9702       WHEN OTHERS THEN
9703         RAISE;
9704 
9705 end getPAOUInstalled;
9706 
9707 -- Used in Complex work
9708 --returns whether Grants is installed for current org or not
9709 FUNCTION getGMSOUInstalled ( p_orgId IN NUMBER) RETURN VARCHAR2 IS
9710     l_progress     VARCHAR2(3) := NULL;
9711     l_app_id       NUMBER;
9712     l_install      BOOLEAN;
9713     l_status       VARCHAR2(1);
9714   begin
9715     l_progress := 10;
9716     --get Grants  installation status
9717       l_install := GMS_INSTALL.ENABLED(p_orgId);
9718 
9719          l_progress := 20;
9720     if (l_install)
9721     THEN
9722       l_status := 'Y';
9723     ELSE
9724       l_status := 'N';
9725     end if;
9726 
9727     RETURN(l_status);
9728 
9729 EXCEPTION
9730       WHEN OTHERS THEN
9731         RAISE;
9732 
9733 end getGMSOUInstalled;
9734 
9735 --------------------------------------------------------------------------------
9736 --                      IS_NEGOTIATION_REQ_BACKED                         --
9737 --------------------------------------------------------------------------------
9738 -- Start of Comments
9739 --
9740 -- API Name: IS_NEGOTIATION_REQ_BACKED
9741 --
9742 -- Type    : Private
9743 --
9744 -- Pre-reqs: None
9745 --
9746 -- Function: This API is called by the Negotiation Import Spreadsheet code.
9747 --           It determines if all the lines in the spreadsheet have a
9748 --           backing requisition or not.  If all the lines have a backing
9749 --           requisition, then project related attributes will not be downloaded
9750 --           into the spreasheet
9751 --
9752 -- Parameters:
9753 --
9754 --              p_auction_header_id       IN      NUMBER
9755 --                   Auction header id - required
9756 --
9757 --              x_req_backed OUT      VARCHAR2
9758 --                   Returns Y if all the lines that are eligible to have
9759 --                   payitems have a backing Requisition
9760 --
9761 -- End of Comments
9762 --------------------------------------------------------------------------------
9763 
9764 PROCEDURE  IS_NEGOTIATION_REQ_BACKED(
9765              p_auction_header_id       IN        NUMBER,
9766              x_req_backed              OUT NOCOPY VARCHAR2) IS
9767 BEGIN
9768   x_req_backed := 'Y';
9769 
9770     SELECT 'N'
9771       INTO x_req_backed
9772       FROM dual
9773      WHERE EXISTS (SELECT 1
9774        FROM pon_auction_item_prices_all al
9775       WHERE al.auction_header_id = p_auction_header_id
9776             AND al.group_type NOT IN ('GROUP','LOT_LINE')
9777             AND nvl(al.line_origination_code,'-9998') <> 'REQUISITION');
9778 EXCEPTION
9779   WHEN NO_DATA_FOUND
9780    THEN
9781      x_req_backed := 'N';
9782   WHEN OTHERS THEN
9783        RAISE;
9784 END IS_NEGOTIATION_REQ_BACKED;
9785 
9786 /*=========================================================================+
9787 -- 12.0 Enhancement
9788 -- New procedure to send Notification to the given Collaboration
9789 -- Team Member as requested by Negotiation Creator.
9790 -- Parameter :
9791 --
9792 --           p_auction_header_id IN NUMBER,
9793 --           p_user_id           IN NUMBER, This will be user id
9794 --                                          of Notification Recipient,
9795 --                                          i.e. Team Member.
9796 --           x_return_status     OUT NOCOPY VARCHAR2,
9797 --                                          flag to indicate if the copy procedure
9798 --                                          was successful or not; It can have
9799 --                                          following values -
9800 --                                              FND_API.G_RET_STS_SUCCESS (Success)
9801 --                                              FND_API.G_RET_STS_ERROR  (Success with warning)
9802 --                                              FND_API.G_RET_STS_UNEXP_ERROR (Failed due to error)
9803 --
9804 +=========================================================================*/
9805 
9806 
9807 PROCEDURE SEND_TASK_ASSIGN_NOTIF (p_auction_header_id IN     NUMBER,
9808                                   p_user_id           IN     NUMBER,
9809                                   x_return_status     OUT NOCOPY VARCHAR2)
9810 IS
9811     l_module_name constant VARCHAR2(40) := 'SEND_TASK_ASSIGN_NOTIF';
9812     l_progress                  VARCHAR2(3);
9813     l_language_code             VARCHAR2(20);
9814     l_lang_code                 VARCHAR2(4);
9815     l_doc_number                PON_AUCTION_HEADERS_ALL.DOCUMENT_NUMBER%TYPE;
9816     l_auction_start_date        DATE;
9817     l_auction_end_date          DATE;
9818     l_preview_date              DATE;
9819     l_msg_suffix                PON_AUC_DOCTYPES.MESSAGE_SUFFIX%TYPE;
9820     l_auction_title             PON_AUCTION_HEADERS_ALL.AUCTION_TITLE%TYPE;
9821     l_preparer_tp_name          HZ_PARTIES.PARTY_NAME%TYPE;
9822     l_task_name                 PON_NEG_TEAM_MEMBERS.TASK_NAME%TYPE;
9823     l_task_target_date          DATE;
9824     l_task_assignment_date      DATE;
9825     l_task_assigned_subject     VARCHAR2(2000);
9826     l_timezone_disp             VARCHAR2(240);
9827     l_auctioneer_user_name      VARCHAR2(244);
9828     l_user_name       VARCHAR2(244);
9829     l_person_party_id           NUMBER;
9830     l_sequence                  NUMBER;
9831     x_itemtype                  VARCHAR2(7);
9832     x_itemkey                  VARCHAR2(50);
9833     l_open_auction_now_flag VARCHAR2(1);
9834     l_publish_auction_now_flag VARCHAR2(1);
9835 
9836  BEGIN
9837       BEGIN
9838 
9839          l_progress := '000';
9840          x_return_status := FND_API.G_RET_STS_SUCCESS;
9841              IF (FND_LOG.level_procedure >= FND_LOG.g_current_runtime_level) THEN
9842                           FND_LOG.string (log_level => FND_LOG.level_procedure,
9843                                        module => g_module || l_module_name,
9844                                        message  => 'Entering to Procedure ' || g_module || l_module_name
9845                                        || ', l_progress = ' || l_progress
9846                                        || ', p_auction_header_id = ' || p_auction_header_id
9847                                        || ', p_user_id = ' || p_user_id);
9848              END IF;
9849 
9850 
9851            l_language_code := fnd_profile.value_specific('ICX_LANGUAGE', p_user_id, NULL, NULL);
9852 
9853            l_progress := '010';
9854 
9855            SELECT LANGUAGE_CODE
9856            INTO l_lang_code
9857            FROM FND_LANGUAGES
9858            WHERE NLS_LANGUAGE = l_language_code;
9859 
9860            l_progress := '020';
9861 
9862            select auh.DOCUMENT_NUMBER,
9863                   auh.OPEN_BIDDING_DATE,
9864                   auh.CLOSE_BIDDING_DATE,
9865                   auh.VIEW_BY_DATE,
9866                   pad.MESSAGE_SUFFIX,
9867                   auh.AUCTION_TITLE,
9868                   hz.PARTY_NAME PREPARER_TP_NAME,
9869                   pntm.TASK_NAME,
9870                   pntm.TARGET_DATE TASK_TARGET_DATE,
9871                   pntm.LAST_NOTIFIED_DATE TASK_ASSIGNMENT_DATE,
9872                   auh.TRADING_PARTNER_CONTACT_NAME,
9873                   fu.person_party_id,
9874                   fu.user_name,
9875                   auh.open_auction_now_flag,
9876                   auh.publish_auction_now_flag
9877 
9878             into  l_doc_number,
9879                   l_auction_start_date,
9880                   l_auction_end_date,
9881                   l_preview_date,
9882                   l_msg_suffix,
9883                   l_auction_title,
9884                   l_preparer_tp_name,
9885                   l_task_name,
9886                   l_task_target_date,
9887                   l_task_assignment_date,
9888                   l_auctioneer_user_name,
9889                   l_person_party_id,
9890                   l_user_name,
9891                   l_open_auction_now_flag,
9892                   l_publish_auction_now_flag
9893 
9894            from pon_auction_headers_all auh,
9895                   hz_parties hz,
9896                   pon_neg_team_members pntm,
9897                   fnd_user fu,
9898                   pon_auc_doctypes pad
9899            where auh.auction_header_id = p_auction_header_id
9900                   AND hz.party_id = auh.trading_partner_id
9901                   AND pntm.auction_header_id = auh.auction_header_id
9902                   AND pntm.user_id = p_user_id
9903                   AND fu.user_id = pntm.user_id
9904                   AND pad.doctype_id = auh.doctype_id;
9905 
9906               l_progress := '030';
9907 
9908               IF (FND_LOG.level_procedure >= FND_LOG.g_current_runtime_level) THEN
9909                                         FND_LOG.string (log_level => FND_LOG.level_procedure,
9910                                         module => g_module || l_module_name,
9911                                         message  => 'After query execution : ' || g_module || l_module_name
9912                                         || ', l_progress = ' || l_progress
9913                                         || ', l_doc_number          = ' || l_doc_number
9914                                         || ', l_language_code = ' || l_language_code
9915                                         || ', l_lang_code = ' || l_lang_code
9916                                         || ', l_auction_start_date      = ' || l_auction_start_date
9917                                         || ', l_auction_end_date        = ' || l_auction_end_date
9918                                         || ', l_preview_date            = ' || l_preview_date
9919                                         || ', l_msg_suffix          = ' || l_msg_suffix
9920                                         || ', l_auction_title           = ' || l_auction_title
9921                                         || ', l_preparer_tp_name        = ' || l_preparer_tp_name
9922                                         || ', l_task_name           = ' || l_task_name
9923                                         || ', l_task_target_date        = ' || l_task_target_date
9924                                         || ', l_task_assignment_date        = ' || l_task_assignment_date
9925                                         || ', l_auctioneer_user_name        = ' || l_auctioneer_user_name
9926                                         || ', l_user_name         = ' || l_user_name
9927                                         || ', l_open_auction_now_flag         = ' || l_open_auction_now_flag
9928                                         || ', l_publish_auction_now_flag         = ' || l_publish_auction_now_flag
9929                                         || ', l_person_party_id     = ' || l_person_party_id);
9930 
9931               END IF;
9932 
9933           -- Get the recipient user's language preference
9934           -- And set the session language so messages are
9935           -- retrieved in that language.
9936           IF p_user_id IS NOT NULL THEN
9937             PON_PROFILE_UTIL_PKG.GET_WF_LANGUAGE (p_user_id, l_lang_code);
9938 
9939             IF (FND_LOG.level_statement >= FND_LOG.g_current_runtime_level) THEN --{
9940             FND_LOG.string(log_level => FND_LOG.level_statement,
9941               module => g_module_prefix || 'SEND_TASK_ASSIGN_NOTIF',
9942               message  => '9. Calling SET_SESSION_LANGUAGE with l_lang_code : ' || l_lang_code);
9943             END IF; --}
9944 
9945             SET_SESSION_LANGUAGE (null, l_lang_code);
9946           END IF;
9947 
9948           --Subject should be retrieved from seed message
9949 
9950           PON_OEX_TIMEZONE_PKG.CONVERT_DATE_TO_USER_TZ(p_person_party_id => l_person_party_id,
9951                                                        p_auctioneer_user_name => l_auctioneer_user_name,
9952                                                        x_date_value1  => l_auction_start_date,
9953                                                        x_date_value2  => l_auction_end_date,
9954                                                        x_date_value3  => l_preview_date,
9955                                                        x_date_value4  => l_task_target_date,
9956                                                        x_date_value5  => l_task_assignment_date,
9957                                                        x_timezone_disp =>l_timezone_disp);
9958 
9959           l_progress := '040';
9960 
9961           l_task_assigned_subject :=  PON_AUCTION_PKG.getMessage( msg => 'PON_AUC_TASK_ASN_NOTIF_SUB',
9962                                                                  msg_suffix => '_'|| l_msg_suffix,
9963                                                                  token1 => 'DOC_NUMBER',
9964                                                                  token1_value => l_doc_number,
9965                                                                  token2 => 'AUCTION_TITLE',
9966                                                                  token2_value => replaceHtmlChars(l_auction_title));
9967           l_progress := '050';
9968 
9969 
9970               IF (FND_LOG.level_procedure >= FND_LOG.g_current_runtime_level) THEN
9971                                         FND_LOG.string (log_level => FND_LOG.level_procedure,
9972                                         module => g_module || l_module_name,
9973                                         message  => 'After getting new time and subject : ' || g_module || l_module_name
9974                                         || ', l_progress = ' || l_progress
9975                                         || ', l_auction_start_date      = ' || l_auction_start_date
9976                                         || ', l_auction_end_date        = ' || l_auction_end_date
9977                                         || ', l_preview_date            = ' || l_preview_date
9978                                         || ', l_timezone_disp = ' || l_timezone_disp
9979                                         || ', l_task_assigned_subject = ' || l_task_assigned_subject);
9980               END IF;
9981 
9982           x_itemtype := 'PONAUCT';
9983 
9984           SELECT pon_auction_wf_publish_s.nextval
9985           INTO   l_sequence
9986           FROM   dual;
9987 
9988           x_itemkey := p_auction_header_id||'-'|| l_sequence;
9989 
9990           wf_engine.CreateProcess(itemtype => x_itemtype,
9991                                   itemkey  => x_itemkey,
9992                                   process  => 'TEAM_MEM_TASK_ASSIGNED');
9993           l_progress := '060';
9994 
9995               IF (FND_LOG.level_procedure >= FND_LOG.g_current_runtime_level) THEN
9996                                         FND_LOG.string (log_level => FND_LOG.level_procedure,
9997                                         module => g_module || l_module_name,
9998                                         message  => 'After CreateProcess ' || g_module || l_module_name
9999                                         || ', l_progress = ' || l_progress
10000                                         || ', x_itemtype = ' || x_itemtype
10001                                         || ', x_itemkey = ' || x_itemkey);
10002               END IF;
10003 
10004 
10005               SET_PREVIEW_DATE(
10006                         p_itemtype => x_itemtype,
10007                         p_itemkey   => x_itemkey,
10008                         p_preview_date  => l_preview_date,
10009                         p_publish_auction_now_flag => l_publish_auction_now_flag,
10010                         p_timezone_disp  => l_timezone_disp,
10011                         p_msg_suffix => l_msg_suffix);
10012 
10013               SET_OPEN_DATE(
10014                         p_itemtype      => x_itemtype,
10015                         p_itemkey      => x_itemkey,
10016                         p_auction_start_date  => l_auction_start_date,
10017                         p_open_auction_now_flag => l_open_auction_now_flag,
10018                         p_timezone_disp  => l_timezone_disp,
10019                         p_msg_suffix => l_msg_suffix);
10020 
10021               SET_CLOSE_DATE(
10022                         p_itemtype  =>x_itemtype,
10023                         p_itemkey    =>x_itemkey,
10024                         p_auction_end_date  => l_auction_end_date,
10025                         p_timezone_disp  => l_timezone_disp);
10026 
10027              l_progress := '090';
10028 
10029              wf_engine.SetItemAttrText (itemtype   => x_itemtype,
10030                                        itemkey    => x_itemkey,
10031                                        aname      => 'DOC_NUMBER',
10032                                        avalue     => l_doc_number);
10033 
10034             wf_engine.SetItemAttrText (itemtype   => x_itemtype,
10035                                        itemkey    => x_itemkey,
10036                                        aname      => 'AUCTION_TITLE',
10037                                        avalue     => l_auction_title);
10038 
10039             wf_engine.SetItemAttrText (itemtype   => x_itemtype,
10040                                        itemkey    => x_itemkey,
10041                                        aname      => 'PREPARER_TP_CONTACT_NAME',
10042                                        avalue     => l_auctioneer_user_name);
10043 
10044             wf_engine.SetItemAttrText (itemtype   => x_itemtype,
10045                                        itemkey    => x_itemkey,
10046                                        aname      => 'ORIGIN_USER_NAME',
10047                                        avalue     => fnd_global.user_name);
10048 
10049              wf_engine.SetItemAttrText (itemtype   => x_itemtype,
10050                                         itemkey    => x_itemkey,
10051                                         aname      => 'RECIPIENT_ROLE',
10052                                         avalue     => l_user_name);
10053 
10054             wf_engine.SetItemAttrText (itemtype   => x_itemtype,
10055                                        itemkey    => x_itemkey,
10056                                        aname      => 'PREPARER_TP_NAME',
10057                                        avalue     => l_preparer_tp_name);
10058 
10059             wf_engine.SetItemAttrDate (itemtype   => x_itemtype,
10060                                        itemkey    => x_itemkey,
10061                                        aname      => 'TASK_TARGET_DATE',
10062                                        avalue     => l_task_target_date);
10063 
10064             wf_engine.SetItemAttrText (itemtype   => x_itemtype,
10065                                        itemkey    => x_itemkey,
10066                                        aname      => 'TASK_NAME',
10067                                        avalue     => l_task_name);
10068 
10069             wf_engine.SetItemAttrText (itemtype   => x_itemtype,
10070                                        itemkey    => x_itemkey,
10071                                        aname      => 'TASK_ASSIGNED_SUBJECT',
10072                                        avalue     => l_task_assigned_subject);
10073 
10074             wf_engine.SetItemAttrText (itemtype   => x_itemtype,
10075                                        itemkey    => x_itemkey,
10076                                        aname      => 'AUCTION_ID',
10077                                        avalue     => p_auction_header_id);
10078 
10079             l_progress := '100';
10080 
10081     -- Bug 4295915: Set the  workflow owner
10082             wf_engine.SetItemOwner(itemtype => x_itemtype,
10083                                    itemkey  => x_itemkey,
10084                                    owner    => fnd_global.user_name);
10085 
10086             wf_engine.StartProcess(itemtype => x_itemtype,
10087                                    itemkey  => x_itemkey );
10088 
10089 
10090             l_progress := 'END';
10091 
10092             IF (FND_LOG.level_procedure >= FND_LOG.g_current_runtime_level) THEN
10093                          FND_LOG.string (log_level => FND_LOG.level_procedure,
10094                                       module => g_module || l_module_name,
10095                                        message  => 'Procedure Ends ' || g_module || l_module_name
10096                                       || ', l_progress = ' || l_progress);
10097             END IF;
10098 
10099             UNSET_SESSION_LANGUAGE;
10100 
10101         EXCEPTION WHEN OTHERS THEN
10102             IF (FND_LOG.level_procedure >= FND_LOG.g_current_runtime_level) THEN
10103                                         FND_LOG.string (log_level => FND_LOG.level_procedure,
10104                                         module => g_module || l_module_name,
10105                                         message  => 'In Exception Block : ' || g_module || l_module_name
10106                                         || ', l_progress = ' || l_progress
10107                                         || ', p_auction_header_id = ' || p_auction_header_id
10108                                         || ', p_user_id = ' || p_user_id);
10109             END IF;
10110             UNSET_SESSION_LANGUAGE;
10111             x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
10112         END;
10113 
10114 END SEND_TASK_ASSIGN_NOTIF;
10115 
10116 /*===========================================================================================+
10117 --
10118 -- 12.0 Enhancement
10119 -- SEND_TASK_COMPL_NOTIF procedure will be responsible
10120 -- for sending notification from the Buyer user to the
10121 -- Negotiation Creator when the former completes a given
10122 -- task for a Collaboration Team Member.
10123 -- Parameter :
10124 --             p_auction_header_id IN NUMBER,
10125 --             p_user_id           IN NUMBER, This will be user id
10126 --                                            Notification sender,
10127 --                                            i.e.Team Member.
10128 --             x_return_status     OUT NOCOPY VARCHAR2,
10129 --                                          flag to indicate if the copy procedure
10130 --                                          was successful or not; It can have
10131 --                                          following values -
10132 --                                              FND_API.G_RET_STS_SUCCESS (Success)
10133 --                                              FND_API.G_RET_STS_ERROR  (Success with warning)
10134 --                                              FND_API.G_RET_STS_UNEXP_ERROR (Failed due to error)
10135 --
10136 +===========================================================================================*/
10137 
10138 PROCEDURE SEND_TASK_COMPL_NOTIF ( p_auction_header_id IN NUMBER,
10139                                   p_user_id           IN NUMBER,
10140                                   x_return_status     OUT NOCOPY VARCHAR2)
10141 IS
10142     l_module_name constant VARCHAR2(40) := 'SEND_TASK_COMPL_NOTIF';
10143     l_progress                  VARCHAR2(3);
10144     l_language_code             VARCHAR2(20);
10145     l_lang_code                 VARCHAR2(4);
10146     l_doc_number                PON_AUCTION_HEADERS_ALL.DOCUMENT_NUMBER%TYPE;
10147     l_auction_start_date        DATE;
10148     l_auction_end_date          DATE;
10149     l_preview_date              DATE;
10150     l_msg_suffix                PON_AUC_DOCTYPES.MESSAGE_SUFFIX%TYPE;
10151     l_auction_title             PON_AUCTION_HEADERS_ALL.AUCTION_TITLE%TYPE;
10152     l_preparer_tp_name          HZ_PARTIES.PARTY_NAME%TYPE;
10153     l_task_name                 PON_NEG_TEAM_MEMBERS.TASK_NAME%TYPE;
10154     l_task_target_date          DATE;
10155     l_task_completion_date      DATE;
10156     l_task_completed_subject     VARCHAR2(2000);
10157     l_timezone_disp             VARCHAR2(240);
10158     l_auctioneer_user_name      VARCHAR2(244);
10159     l_user_name                 VARCHAR2(244);
10160     l_tp_contact_id             NUMBER;
10161     l_tp_contact_usr_id         NUMBER;
10162     l_trading_partner_id        NUMBER;
10163     l_sequence                  NUMBER;
10164     x_itemtype                  VARCHAR2(7);
10165     x_itemkey                  VARCHAR2(50);
10166     l_open_auction_now_flag VARCHAR2(1);
10167     l_publish_auction_now_flag   VARCHAR2(1);
10168     l_doctype_group_name varchar2(100);
10169 
10170 
10171  BEGIN
10172       BEGIN
10173 
10174          l_progress := '000';
10175          x_return_status := FND_API.G_RET_STS_SUCCESS;
10176 
10177              IF (FND_LOG.level_procedure >= FND_LOG.g_current_runtime_level) THEN
10178                           FND_LOG.string (log_level => FND_LOG.level_procedure,
10179                                        module => g_module || l_module_name,
10180                                        message  => 'Entering to Procedure ' || g_module || l_module_name
10181                                        || ', l_progress = ' || l_progress
10182                                        || ', p_auction_header_id = ' || p_auction_header_id
10183                                        || ', p_user_id = ' || p_user_id);
10184              END IF;
10185 
10186              BEGIN
10187                    select auh.DOCUMENT_NUMBER,
10188                           auh.OPEN_BIDDING_DATE,
10189                           auh.CLOSE_BIDDING_DATE,
10190                           auh.VIEW_BY_DATE,
10191                           pad.MESSAGE_SUFFIX,
10192                           auh.AUCTION_TITLE,
10193                           auh.TRADING_PARTNER_CONTACT_NAME,
10194                           auh.TRADING_PARTNER_CONTACT_ID,
10195                           auh.TRADING_PARTNER_ID,
10196                           fu.user_id,
10197                           auh.open_auction_now_flag,
10198                           auh.publish_auction_now_flag
10199                     into  l_doc_number,
10200                           l_auction_start_date,
10201                           l_auction_end_date,
10202                           l_preview_date,
10203                           l_msg_suffix,
10204                           l_auction_title,
10205                           l_auctioneer_user_name,
10206                           l_tp_contact_id,
10207                           l_trading_partner_id,
10208                           l_tp_contact_usr_id,
10209                           l_open_auction_now_flag,
10210                           l_publish_auction_now_flag
10211                    from pon_auction_headers_all auh,
10212                           pon_auc_doctypes pad,
10213                           fnd_user fu
10214                    where auh.auction_header_id = p_auction_header_id
10215                           AND pad.doctype_id = auh.doctype_id
10216                           AND fu.person_party_id = auh.TRADING_PARTNER_CONTACT_ID
10217                           AND nvl(fu.end_date,sysdate+1) > sysdate;
10218 
10219            EXCEPTION
10220                    WHEN TOO_MANY_ROWS THEN
10221                      if (nvl(fnd_profile.value('AFLOG_ENABLED'),'N') = 'Y') then
10222                            if (fnd_log.level_unexpected >= fnd_log.g_current_runtime_level) then
10223                                          fnd_log.string(log_level => fnd_log.level_unexpected,
10224                                                         module    => 'pon.plsql.pon_auction_pkg.send_task_compl_notif',
10225                                                         message   => 'Multiple Users found for auction_header_id:'|| p_auction_header_id);
10226                            end if;
10227                      end if;
10228 
10229                     select auh.DOCUMENT_NUMBER,
10230                           auh.OPEN_BIDDING_DATE,
10231                           auh.CLOSE_BIDDING_DATE,
10232                           auh.VIEW_BY_DATE,
10233                           pad.MESSAGE_SUFFIX,
10234                           auh.AUCTION_TITLE,
10235                           auh.TRADING_PARTNER_CONTACT_NAME,
10236                           auh.TRADING_PARTNER_CONTACT_ID,
10237                           auh.TRADING_PARTNER_ID,
10238                           fu.user_id,
10239                           auh.open_auction_now_flag,
10240                           auh.publish_auction_now_flag
10241                      into  l_doc_number,
10242                           l_auction_start_date,
10243                           l_auction_end_date,
10244                           l_preview_date,
10245                           l_msg_suffix,
10246                           l_auction_title,
10247                           l_auctioneer_user_name,
10248                           l_tp_contact_id,
10249                           l_trading_partner_id,
10250                           l_tp_contact_usr_id,
10251                           l_open_auction_now_flag,
10252                           l_publish_auction_now_flag
10253                     from pon_auction_headers_all auh,
10254                           pon_auc_doctypes pad,
10255                           fnd_user fu
10256                     where auh.auction_header_id = p_auction_header_id
10257                           AND pad.doctype_id = auh.doctype_id
10258                           AND fu.person_party_id = auh.TRADING_PARTNER_CONTACT_ID
10259                           AND nvl(fu.end_date,sysdate+1) > sysdate
10260                           AND rownum=1;
10261            END;
10262 
10263            l_progress := '005';
10264 
10265            IF (FND_LOG.level_procedure >= FND_LOG.g_current_runtime_level) THEN
10266                                    FND_LOG.string (log_level => FND_LOG.level_procedure,
10267                                      module => g_module || l_module_name,
10268                                      message  => 'Entering to Procedure ' || g_module || l_module_name
10269                                      || ', l_progress = ' || l_progress
10270                                      || ', l_doc_number           = ' || l_doc_number
10271                                      || ', l_auction_start_date       = ' || l_auction_start_date
10272                                      || ', l_auction_end_date     = ' || l_auction_end_date
10273                                      || ', l_preview_date         = ' || l_preview_date
10274                                      || ', l_msg_suffix           = ' || l_msg_suffix
10275                                      || ', l_auction_title            = ' || l_auction_title
10276                                      || ', l_auctioneer_user_name     = ' || l_auctioneer_user_name
10277                                      || ', l_user_name     = ' || l_user_name
10278                                      || ', l_tp_contact_id        = ' || l_tp_contact_id
10279                                      || ', l_tp_contact_usr_id = ' || l_tp_contact_usr_id
10280                                      || ', l_trading_partner_id       = ' || l_trading_partner_id
10281                                      || ', l_open_auction_now_flag  = ' || l_open_auction_now_flag
10282                                      || ', l_publish_auction_now_flag = ' || l_publish_auction_now_flag
10283                                      );
10284            END IF;
10285 
10286            l_language_code := fnd_profile.value_specific('ICX_LANGUAGE', l_tp_contact_usr_id, NULL, NULL);
10287 
10288            l_progress := '010';
10289 
10290            SELECT LANGUAGE_CODE
10291            INTO l_lang_code
10292            FROM FND_LANGUAGES
10293            WHERE NLS_LANGUAGE = l_language_code;
10294 
10295            l_progress := '020';
10296 
10297            select hz.PARTY_NAME PREPARER_TP_NAME,
10298                   pntm.TASK_NAME,
10299                   pntm.TARGET_DATE TASK_TARGET_DATE,
10300                   pntm.COMPLETION_DATE TASK_COMPLETION_DATE,
10301                   fu.user_name
10302             into  l_preparer_tp_name,
10303                   l_task_name,
10304                   l_task_target_date,
10305                   l_task_completion_date,
10306                   l_user_name
10307            from hz_parties hz,
10308                   pon_neg_team_members pntm,
10309                   fnd_user fu
10310            where pntm.auction_header_id = p_auction_header_id
10311                   AND hz.party_id = l_trading_partner_id
10312                   AND pntm.user_id = p_user_id
10313                   AND fu.user_id = pntm.user_id;
10314 
10315 
10316               l_progress := '030';
10317 
10318               IF (FND_LOG.level_procedure >= FND_LOG.g_current_runtime_level) THEN
10319                                         FND_LOG.string (log_level => FND_LOG.level_procedure,
10320                                         module => g_module || l_module_name,
10321                                         message  => 'After query execution : ' || g_module || l_module_name
10322                                         || ', l_progress = ' || l_progress
10323                                         || ', l_language_code = ' || l_language_code
10324                                         || ', l_lang_code = ' || l_lang_code
10325                                         || ', l_preparer_tp_name        = ' || l_preparer_tp_name
10326                                         || ', l_task_name           = ' || l_task_name
10327                                         || ', l_task_target_date        = ' || l_task_target_date
10328                                         || ', l_task_completion_date = ' || l_task_completion_date);
10329               END IF;
10330 
10331           -- Get the recipient user's language preference
10332           -- And set the session language so messages are
10333           -- retrieved in that language.
10334           IF l_tp_contact_usr_id IS NOT NULL THEN
10335             PON_PROFILE_UTIL_PKG.GET_WF_LANGUAGE (l_tp_contact_usr_id, l_lang_code);
10336 
10337             IF (FND_LOG.level_statement >= FND_LOG.g_current_runtime_level) THEN --{
10338             FND_LOG.string(log_level => FND_LOG.level_statement,
10339               module => g_module_prefix || 'SEND_TASK_COMPL_NOTIF',
10340               message  => '10. Calling SET_SESSION_LANGUAGE with l_lang_code : ' || l_lang_code);
10341             END IF; --}
10342 
10343             SET_SESSION_LANGUAGE (null, l_lang_code);
10344           END IF;
10345 
10346 
10347           --Subject should be retrieved from seed message
10348 
10349           PON_OEX_TIMEZONE_PKG.CONVERT_DATE_TO_USER_TZ(p_person_party_id => l_tp_contact_id,
10350                                                        p_auctioneer_user_name => l_auctioneer_user_name,
10351                                                        x_date_value1  => l_auction_start_date,
10352                                                        x_date_value2  => l_auction_end_date,
10353                                                        x_date_value3  => l_preview_date,
10354                                                        x_date_value4  => l_task_target_date,
10355                                                        x_date_value5  => l_task_completion_date,
10356                                                        x_timezone_disp =>l_timezone_disp);
10357 
10358           l_progress := '040';
10359 
10360           l_task_completed_subject :=  PON_AUCTION_PKG.getMessage( msg => 'PON_AUC_TASK_COMPL_NOTIF_SUB',
10361                                                                  msg_suffix => '_'|| l_msg_suffix,
10362                                                                  token1 => 'DOC_NUMBER',
10363                                                                  token1_value => l_doc_number,
10364                                                                  token2 => 'AUCTION_TITLE',
10365                                                                  token2_value => replaceHtmlChars(l_auction_title));
10366 
10367           l_progress := '050';
10368 
10369 
10370               IF (FND_LOG.level_procedure >= FND_LOG.g_current_runtime_level) THEN
10371                                         FND_LOG.string (log_level => FND_LOG.level_procedure,
10372                                         module => g_module || l_module_name,
10373                                         message  => 'After getting new time and subject : ' || g_module || l_module_name
10374                                         || ', l_progress = ' || l_progress
10375                                         || ', l_auction_start_date      = ' || l_auction_start_date
10376                                         || ', l_auction_end_date        = ' || l_auction_end_date
10377                                         || ', l_preview_date            = ' || l_preview_date
10378                                         || ', l_task_target_date = ' || l_task_target_date
10379                                         || ', l_task_completion_date = ' || l_task_completion_date
10380                                         || ', l_timezone_disp = ' || l_timezone_disp
10381                                         || ', l_task_completed_subject = ' || l_task_completed_subject);
10382               END IF;
10383 
10384           x_itemtype := 'PONAUCT';
10385 
10386           SELECT pon_auction_wf_publish_s.nextval
10387           INTO   l_sequence
10388           FROM   dual;
10389 
10390           x_itemkey := p_auction_header_id||'-'|| l_sequence;
10391 
10392           wf_engine.CreateProcess(itemtype => x_itemtype,
10393                                   itemkey  => x_itemkey,
10394                                   process  => 'TEAM_MEM_TASK_COMPLTD');
10395           l_progress := '060';
10396 
10397               IF (FND_LOG.level_procedure >= FND_LOG.g_current_runtime_level) THEN
10398                                         FND_LOG.string (log_level => FND_LOG.level_procedure,
10399                                         module => g_module || l_module_name,
10400                                         message  => 'After CreateProcess ' || g_module || l_module_name
10401                                         || ', l_progress = ' || l_progress
10402                                         || ', x_itemtype = ' || x_itemtype
10403                                         || ', x_itemkey = ' || x_itemkey);
10404               END IF;
10405 
10406                 SET_PREVIEW_DATE(
10407                           p_itemtype => x_itemtype,
10408                           p_itemkey   => x_itemkey,
10409                           p_preview_date  => l_preview_date,
10410                           p_publish_auction_now_flag => l_publish_auction_now_flag,
10411                           p_timezone_disp  => l_timezone_disp,
10412                           p_msg_suffix => l_msg_suffix);
10413 
10414                 SET_OPEN_DATE(
10415                           p_itemtype      => x_itemtype,
10416                           p_itemkey      => x_itemkey,
10417                           p_auction_start_date  => l_auction_start_date,
10418                           p_open_auction_now_flag => l_open_auction_now_flag,
10419                           p_timezone_disp  => l_timezone_disp,
10420                           p_msg_suffix => l_msg_suffix);
10421 
10422                 SET_CLOSE_DATE(
10423                           p_itemtype  =>x_itemtype,
10424                           p_itemkey    =>x_itemkey,
10425                           p_auction_end_date  => l_auction_end_date,
10426                           p_timezone_disp  => l_timezone_disp);
10427 
10428             l_progress := '091';
10429 
10430             wf_engine.SetItemAttrText (itemtype   => x_itemtype,
10431                                        itemkey    => x_itemkey,
10432                                        aname      => 'DOC_NUMBER',
10433                                        avalue     => l_doc_number);
10434 
10435             wf_engine.SetItemAttrText (itemtype   => x_itemtype,
10436                                        itemkey    => x_itemkey,
10437                                        aname      => 'AUCTION_TITLE',
10438                                        avalue     => l_auction_title);
10439 
10440             wf_engine.SetItemAttrText (itemtype   => x_itemtype,
10441                                        itemkey    => x_itemkey,
10442                                        aname      => 'PREPARER_TP_CONTACT_NAME',
10443                                        avalue     => l_auctioneer_user_name);
10444 
10445              wf_engine.SetItemAttrText (itemtype   => x_itemtype,
10446                                         itemkey    => x_itemkey,
10447                                         aname      => 'RECIPIENT_ROLE',
10448                                         avalue     => l_user_name);
10449 
10450             wf_engine.SetItemAttrText (itemtype   => x_itemtype,
10451                                        itemkey    => x_itemkey,
10452                                        aname      => 'PREPARER_TP_NAME',
10453                                        avalue     => l_preparer_tp_name);
10454 
10455             wf_engine.SetItemAttrDate (itemtype   => x_itemtype,
10456                                        itemkey    => x_itemkey,
10457                                        aname      => 'TASK_TARGET_DATE',
10458                                        avalue     => l_task_target_date);
10459 
10460             wf_engine.SetItemAttrText (itemtype   => x_itemtype,
10461                                        itemkey    => x_itemkey,
10462                                        aname      => 'TASK_NAME',
10463                                        avalue     => l_task_name);
10464 
10465             wf_engine.SetItemAttrText (itemtype   => x_itemtype,
10466                                        itemkey    => x_itemkey,
10467                                        aname      => 'TASK_COMPLETED_SUBJECT',
10468                                        avalue     => l_task_completed_subject);
10469 
10470             wf_engine.SetItemAttrText (itemtype   => x_itemtype,
10471                                        itemkey    => x_itemkey,
10472                                        aname      => 'AUCTION_ID',
10473                                        avalue     => p_auction_header_id);
10474 
10475     -- Bug 4295915: Set the  workflow owner
10476             wf_engine.SetItemOwner(itemtype => x_itemtype,
10477                                    itemkey  => x_itemkey,
10478                                    owner    => fnd_global.user_name);
10479 
10480             l_progress := '100';
10481 
10482             wf_engine.StartProcess(itemtype => x_itemtype,
10483                                    itemkey  => x_itemkey );
10484 
10485 
10486             l_progress := 'END';
10487 
10488             IF (FND_LOG.level_procedure >= FND_LOG.g_current_runtime_level) THEN
10489                          FND_LOG.string (log_level => FND_LOG.level_procedure,
10490                                       module => g_module || l_module_name,
10491                                        message  => 'Procedure Ends ' || g_module || l_module_name
10492                                       || ', l_progress = ' || l_progress);
10493             END IF;
10494 
10495             UNSET_SESSION_LANGUAGE;
10496 
10497         EXCEPTION WHEN OTHERS THEN
10498             IF (FND_LOG.level_procedure >= FND_LOG.g_current_runtime_level) THEN
10499                                         FND_LOG.string (log_level => FND_LOG.level_procedure,
10500                                         module => g_module || l_module_name,
10501                                         message  => 'In Exception Block : ' || g_module || l_module_name
10502                                         || ', l_progress = ' || l_progress
10503                                         || ', p_auction_header_id = ' || p_auction_header_id
10504                                         || ', p_user_id = ' || p_user_id);
10505             END IF;
10506             UNSET_SESSION_LANGUAGE;
10507             x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
10508         END;
10509 
10510 END SEND_TASK_COMPL_NOTIF;
10511 
10512 
10513 /*=========================================================================+
10514 -- 12.0 Enhancement
10515 -- SEND_RESP_NOTIF procedure will be responsible for
10516 -- sending notification to the Buyer when a Seller
10517 -- submits a Response.
10518 -- Parameter :
10519 --            p_bid_number               IN NUMBER,
10520 --            x_return_status            OUT NOCOPY VARCHAR2
10521 --
10522 +=========================================================================*/
10523 
10524 PROCEDURE SEND_RESP_NOTIF ( p_bid_number               IN NUMBER,
10525                            x_return_status             OUT NOCOPY VARCHAR2)
10526 IS
10527     l_module_name constant VARCHAR2(40) := 'SEND_RESP_NOTIF';
10528     l_msg_suffix                PON_AUC_DOCTYPES.MESSAGE_SUFFIX%TYPE;
10529     l_progress                  VARCHAR2(3);
10530     l_lang_code                 VARCHAR2(4);
10531     l_itemtype                  VARCHAR2(7);
10532     l_language_code             VARCHAR2(20);
10533     l_itemkey                  VARCHAR2(50);
10534     l_auctioneer_user_name      VARCHAR2(244);
10535     l_bidder_user_name          VARCHAR2(244);
10536 
10537     l_doc_number                PON_AUCTION_HEADERS_ALL.DOCUMENT_NUMBER%TYPE;
10538     l_auction_header_id         PON_AUCTION_HEADERS_ALL.AUCTION_HEADER_ID%TYPE;
10539     l_auction_title             PON_AUCTION_HEADERS_ALL.AUCTION_TITLE%TYPE;
10540     l_tp_contact_id             PON_AUCTION_HEADERS_ALL.TRADING_PARTNER_CONTACT_ID%TYPE;
10541     l_trading_partner_id        PON_AUCTION_HEADERS_ALL.TRADING_PARTNER_ID%TYPE;
10542     l_preparer_tp_name          PON_AUCTION_HEADERS_ALL.TRADING_PARTNER_NAME%TYPE;
10543     l_response_number           PON_BID_HEADERS.BID_NUMBER%TYPE;
10544     l_bidder_tpc_id             PON_BID_HEADERS.TRADING_PARTNER_CONTACT_ID%TYPE;
10545     l_bidder_tp_name            HZ_PARTIES.PARTY_NAME%TYPE;
10546     l_tp_contact_usr_id         FND_USER.USER_ID%TYPE;
10547     l_timezone_disp             VARCHAR2(240);
10548     l_bid_contact_dp_name       VARCHAR2(350);
10549     l_bidder_dp_name            VARCHAR2(350);
10550     l_response_type_name        VARCHAR2(2000);
10551     l_supplier_site_name        VARCHAR2(2000);
10552     l_response_url              VARCHAR2(2000);
10553     l_resp_publish_sub          VARCHAR2(2000);
10554     l_preview_date              DATE;
10555     l_auction_start_date        DATE;
10556     l_auction_end_date          DATE;
10557     l_bid_publish_date          DATE;
10558     l_null_date                 DATE;
10559 
10560  BEGIN
10561       BEGIN
10562 
10563          l_progress := '000';
10564          x_return_status := FND_API.G_RET_STS_SUCCESS;
10565          l_null_date := null;
10566 
10567              IF (FND_LOG.level_procedure >= FND_LOG.g_current_runtime_level) THEN
10568                           FND_LOG.string (log_level => FND_LOG.level_procedure,
10569                                        module => g_module || l_module_name,
10570                                        message  => 'Entering to Procedure ' || g_module || l_module_name
10571                                        || ', l_progress = ' || l_progress
10572                                        || ', p_bid_number = ' || p_bid_number);
10573              END IF;
10574 
10575          BEGIN
10576            select auh.DOCUMENT_NUMBER,
10577                   auh.OPEN_BIDDING_DATE,
10578                   auh.CLOSE_BIDDING_DATE,
10579                   auh.VIEW_BY_DATE,
10580                   pad.MESSAGE_SUFFIX,
10581                   auh.AUCTION_TITLE,
10582                   auh.TRADING_PARTNER_CONTACT_NAME,
10583                   auh.TRADING_PARTNER_NAME PREPARER_TP_NAME,
10584                   auh.TRADING_PARTNER_CONTACT_ID,
10585                   auh.TRADING_PARTNER_ID,
10586                   fu.user_name,
10587                   decode(pbh.VENDOR_SITE_CODE, null, '', pbh.VENDOR_SITE_CODE) SUPPLIER_SITE_NAME,
10588                   pbh.TRADING_PARTNER_NAME BIDDER_TP_NAME,
10589                   pbh.PUBLISH_DATE BID_PUBLISH_DATE,
10590                   pbh.TRADING_PARTNER_CONTACT_ID BIDDER_TPC_ID,
10591                   auh.AUCTION_HEADER_ID
10592            into  l_doc_number,
10593                   l_auction_start_date,
10594                   l_auction_end_date,
10595                   l_preview_date,
10596                   l_msg_suffix,
10597                   l_auction_title,
10598                   l_auctioneer_user_name,
10599                   l_preparer_tp_name,
10600                   l_tp_contact_id,
10601                   l_trading_partner_id,
10602                   l_bidder_user_name,
10603                   l_supplier_site_name,
10604                   l_bidder_tp_name,
10605                   l_bid_publish_date,
10606                   l_bidder_tpc_id,
10607                   l_auction_header_id
10608            from pon_auction_headers_all auh,
10609                   pon_auc_doctypes pad,
10610                   pon_bid_headers pbh,
10611                   fnd_user fu
10612            where pbh.bid_number = p_bid_number
10613                   AND pad.doctype_id = auh.doctype_id
10614                   AND auh.auction_header_id = pbh.auction_header_id
10615                   AND fu.person_party_id = pbh.trading_partner_contact_id
10616                   AND nvl(fu.end_date, sysdate+1) > sysdate;
10617          EXCEPTION
10618              WHEN TOO_MANY_ROWS THEN
10619                   if (nvl(fnd_profile.value('AFLOG_ENABLED'),'N') = 'Y') then
10620                        if (fnd_log.level_unexpected >= fnd_log.g_current_runtime_level) then
10621                                  fnd_log.string(log_level => fnd_log.level_unexpected,
10622                                                 module    => 'pon.plsql.pon_auction_pkg.send_resp_notif',
10623                                                 message   => 'Multiple Users found for bid number:'|| p_bid_number);
10624                        end if;
10625                  end if;
10626 
10627            select auh.DOCUMENT_NUMBER,
10628                   auh.OPEN_BIDDING_DATE,
10629                   auh.CLOSE_BIDDING_DATE,
10630                   auh.VIEW_BY_DATE,
10631                   pad.MESSAGE_SUFFIX,
10632                   auh.AUCTION_TITLE,
10633                   auh.TRADING_PARTNER_CONTACT_NAME,
10634                   auh.TRADING_PARTNER_NAME PREPARER_TP_NAME,
10635                   auh.TRADING_PARTNER_CONTACT_ID,
10636                   auh.TRADING_PARTNER_ID,
10637                   fu.user_name,
10638                   decode(pbh.VENDOR_SITE_CODE, null, '', pbh.VENDOR_SITE_CODE) SUPPLIER_SITE_NAME,
10639                   pbh.TRADING_PARTNER_NAME BIDDER_TP_NAME,
10640                   pbh.PUBLISH_DATE BID_PUBLISH_DATE,
10641                   pbh.TRADING_PARTNER_CONTACT_ID BIDDER_TPC_ID,
10642                   auh.AUCTION_HEADER_ID
10643            into  l_doc_number,
10644                   l_auction_start_date,
10645                   l_auction_end_date,
10646                   l_preview_date,
10647                   l_msg_suffix,
10648                   l_auction_title,
10649                   l_auctioneer_user_name,
10650                   l_preparer_tp_name,
10651                   l_tp_contact_id,
10652                   l_trading_partner_id,
10653                   l_bidder_user_name,
10654                   l_supplier_site_name,
10655                   l_bidder_tp_name,
10656                   l_bid_publish_date,
10657                   l_bidder_tpc_id,
10658                   l_auction_header_id
10659            from pon_auction_headers_all auh,
10660                   pon_auc_doctypes pad,
10661                   pon_bid_headers pbh,
10662                   fnd_user fu
10663            where pbh.bid_number = p_bid_number
10664                   AND pad.doctype_id = auh.doctype_id
10665                   AND auh.auction_header_id = pbh.auction_header_id
10666                   AND fu.person_party_id = pbh.trading_partner_contact_id
10667                   AND nvl(fu.end_date, sysdate+1) > sysdate
10668                   AND rownum = 1;
10669 
10670 
10671          END;
10672 
10673            l_progress := '010';
10674 
10675            IF (FND_LOG.level_procedure >= FND_LOG.g_current_runtime_level) THEN
10676                                FND_LOG.string (log_level => FND_LOG.level_procedure,
10677                                      module => g_module || l_module_name,
10678                                      message  => 'Entering to Procedure ' || g_module || l_module_name
10679                                      || ', l_progress = ' || l_progress
10680                                      || ', l_doc_number           = ' || l_doc_number
10681                                      || ', l_auction_start_date       = ' || l_auction_start_date
10682                                      || ', l_auction_end_date     = ' || l_auction_end_date
10683                                      || ', l_preview_date         = ' || l_preview_date
10684                                      || ', l_msg_suffix           = ' || l_msg_suffix
10685                                      || ', l_auction_title            = ' || l_auction_title
10686                                      || ', l_auctioneer_user_name     = ' || l_auctioneer_user_name
10687                                      || ', l_bidder_user_name = ' || l_bidder_user_name
10688                                      || ', l_tp_contact_id        = ' || l_tp_contact_id
10689                                      || ', l_trading_partner_id       = ' || l_trading_partner_id
10690                                      || ', l_supplier_site_name = ' || l_supplier_site_name
10691                                      || ', l_bidder_tp_name = ' || l_bidder_tp_name
10692                                      || ', l_bid_publish_date = ' || l_bid_publish_date
10693                                      || ', l_auction_header_id = ' || l_auction_header_id
10694                                      || ', l_bidder_tpc_id = ' || l_bidder_tpc_id);
10695            END IF;
10696 
10697            l_progress := '020';
10698 
10699      PON_PROFILE_UTIL_PKG.GET_WF_LANGUAGE(l_auctioneer_user_name,l_lang_code);
10700 
10701           IF (FND_LOG.level_statement >= FND_LOG.g_current_runtime_level) THEN --{
10702           FND_LOG.string(log_level => FND_LOG.level_statement,
10703             module => g_module_prefix ||l_module_name,
10704             message  => '11. Calling SET_SESSION_LANGUAGE with l_lang_code : ' || l_lang_code);
10705           END IF; --}
10706            SET_SESSION_LANGUAGE (null, l_lang_code);
10707 
10708            l_progress := '030';
10709 
10710               IF (FND_LOG.level_procedure >= FND_LOG.g_current_runtime_level) THEN
10711                                         FND_LOG.string (log_level => FND_LOG.level_procedure,
10712                                         module => g_module || l_module_name,
10713                                         message  => 'After query execution : ' || g_module || l_module_name
10714                                         || ', l_progress = ' || l_progress
10715                                         || ', l_language_code = ' || l_language_code
10716                                         || ', l_lang_code = ' || l_lang_code);
10717               END IF;
10718 
10719           --Subject should be retrieved from seed message
10720 
10721           PON_OEX_TIMEZONE_PKG.CONVERT_DATE_TO_USER_TZ(p_person_party_id => l_tp_contact_id,
10722                                                        p_auctioneer_user_name => l_auctioneer_user_name,
10723                                                        x_date_value1  => l_auction_start_date,
10724                                                        x_date_value2  => l_auction_end_date,
10725                                                        x_date_value3  => l_preview_date,
10726                                                        x_date_value4  => l_bid_publish_date,
10727                                                        x_date_value5  => l_null_date,
10728                                                        x_timezone_disp =>l_timezone_disp);
10729 
10730           l_progress := '040';
10731 
10732           -- Submitted: <Quote> 4512 for <RFQ> 2759 (Equipment Renewal)
10733 
10734           l_resp_publish_sub :=  PON_AUCTION_PKG.getMessage( msg => 'PON_AUC_RESP_SUBM_NOTIF_SUB',
10735                                                                  msg_suffix => '_'||l_msg_suffix,
10736                                                                  token1 => 'RESPONSE_NUMBER',
10737                                                                  token1_value => p_bid_number,
10738                                                                  token2 => 'DOC_NUMBER',
10739                                                                  token2_value => l_doc_number,
10740                                                                  token3 => 'AUCTION_TITLE',
10741                                                                  token3_value => replaceHtmlChars(l_auction_title));
10742 
10743           l_progress := '050';
10744 
10745 
10746               IF (FND_LOG.level_procedure >= FND_LOG.g_current_runtime_level) THEN
10747                                         FND_LOG.string (log_level => FND_LOG.level_procedure,
10748                                         module => g_module || l_module_name,
10749                                         message  => 'After getting new time and subject : ' || g_module || l_module_name
10750                                         || ', l_progress = ' || l_progress
10751                                         || ', l_auction_start_date      = ' || l_auction_start_date
10752                                         || ', l_auction_end_date        = ' || l_auction_end_date
10753                                         || ', l_preview_date            = ' || l_preview_date
10754                                         || ', l_bid_publish_date = ' ||l_bid_publish_date
10755                                         || ', l_timezone_disp = ' || l_timezone_disp
10756                                         || ', l_resp_publish_sub = ' || l_resp_publish_sub);
10757               END IF;
10758 
10759           l_itemtype := 'PONAUCT';
10760           l_itemkey := p_bid_number ||'-'|| l_bidder_tpc_id;
10761 
10762           l_response_url := pon_wf_utl_pkg.get_dest_page_url (p_dest_func => 'PONRESENQ_VIEWBID'
10763                                  ,p_notif_performer  => 'BUYER');
10764 
10765           l_response_type_name :=  PON_AUCTION_PKG.getMessage( msg => 'PON_AUCTS_BID',
10766                                                                  msg_suffix => '_'||l_msg_suffix);
10767 
10768           wf_engine.CreateProcess(itemtype => l_itemtype,
10769                                   itemkey  => l_itemkey,
10770                                   process  => 'RESPONSE_PUBLISH');
10771           l_progress := '060';
10772 
10773               IF (FND_LOG.level_procedure >= FND_LOG.g_current_runtime_level) THEN
10774                                         FND_LOG.string (log_level => FND_LOG.level_procedure,
10775                                         module => g_module || l_module_name,
10776                                         message  => 'After CreateProcess ' || g_module || l_module_name
10777                                         || ', l_progress = ' || l_progress
10778                                         || ', l_itemtype = ' || l_itemtype
10779                                         || ', l_itemkey = ' || l_itemkey);
10780               END IF;
10781 
10782           IF (l_preview_date is not null) THEN
10783              l_progress := '070';
10784              wf_engine.SetItemAttrDate (itemtype  => l_itemtype,
10785                                 itemkey  => l_itemkey,
10786                                 aname  => 'PREVIEW_DATE',
10787                                 avalue  => l_preview_date);
10788 
10789              wf_engine.SetItemAttrText (itemtype  => l_itemtype,
10790                                 itemkey  => l_itemkey,
10791                                 aname  => 'TP_TIME_ZONE1',
10792                                 avalue  => l_timezone_disp);
10793 
10794              wf_engine.SetItemAttrText (itemtype  => l_itemtype,
10795                                itemkey  => l_itemkey,
10796                                aname  => 'PREVIEW_DATE_NOTSPECIFIED',
10797                                avalue  => null);
10798           ELSE
10799              l_progress := '080';
10800              wf_engine.SetItemAttrDate (itemtype  => l_itemtype,
10801                                 itemkey  => l_itemkey,
10802                                 aname  => 'PREVIEW_DATE',
10803                                 avalue  => null);
10804 
10805              wf_engine.SetItemAttrText (itemtype  => l_itemtype,
10806                                  itemkey  => l_itemkey,
10807                                 aname  => 'TP_TIME_ZONE1',
10808                                  avalue  => null);
10809 
10810             wf_engine.SetItemAttrText (itemtype  => l_itemtype,
10811                                itemkey  => l_itemkey,
10812                                aname  => 'PREVIEW_DATE_NOTSPECIFIED',
10813                                avalue  => PON_AUCTION_PKG.getMessage('PON_AUC_PREVIEW_DATE_NOTSPEC'));
10814           END IF;
10815 
10816             l_progress := '090';
10817 
10818             wf_engine.SetItemAttrNumber (itemtype       => l_itemtype,
10819                                                         itemkey => l_itemkey,
10820                                                         aname   => 'BID_ID',
10821                                                         avalue  => p_bid_number);
10822 
10823             wf_engine.SetItemAttrText (itemtype   => l_itemtype,
10824                                        itemkey    => l_itemkey,
10825                                        aname      => 'DOC_NUMBER',
10826                                        avalue     => l_doc_number);
10827 
10828             wf_engine.SetItemAttrText (itemtype   => l_itemtype,
10829                                        itemkey    => l_itemkey,
10830                                        aname      => 'TP_TIME_ZONE',
10831                                        avalue     => l_timezone_disp);
10832 
10833             wf_engine.SetItemAttrDate (itemtype   => l_itemtype,
10834                                        itemkey    => l_itemkey,
10835                                        aname      => 'AUCTION_START_DATE',
10836                                        avalue     => l_auction_start_date);
10837 
10838             wf_engine.SetItemAttrDate (itemtype   => l_itemtype,
10839                                        itemkey    => l_itemkey,
10840                                        aname      => 'AUCTION_END_DATE',
10841                                        avalue     => l_auction_end_date);
10842 
10843             wf_engine.SetItemAttrText (itemtype   => l_itemtype,
10844                                        itemkey    => l_itemkey,
10845                                        aname      => 'AUCTION_TITLE',
10846                                        avalue     => l_auction_title);
10847 
10848            /* Set value for Role - PREPARER_TP_CONTACT_NAME,
10849               this will be set as performer i.e. Notification Recipient
10850            */
10851             wf_engine.SetItemAttrText (itemtype   => l_itemtype,
10852                                        itemkey    => l_itemkey,
10853                                        aname      => 'PREPARER_TP_CONTACT_NAME',
10854                                        avalue     => l_auctioneer_user_name);
10855 
10856             /* Set value for Role - RECIPIENT_ROLE, this will
10857                be set as HDE_FROM_ID i.e. Notification Sender
10858             */
10859       -- Set the sender as the current logged in user
10860       -- This is so that if a surrogate bid is being created,
10861       -- then the sender is the buyer creating the surrogate bid
10862 
10863             wf_engine.SetItemAttrText (itemtype   => l_itemtype,
10864                                        itemkey    => l_itemkey,
10865                                        aname      => 'RECIPIENT_ROLE',
10866                                        avalue     => fnd_global.user_name);
10867 
10868 
10869             wf_engine.SetItemAttrText (itemtype   => l_itemtype,
10870                                        itemkey    => l_itemkey,
10871                                        aname      => 'PREPARER_TP_NAME',
10872                                        avalue     => l_preparer_tp_name);
10873 
10874             wf_engine.SetItemAttrDate (itemtype   => l_itemtype,
10875                                        itemkey    => l_itemkey,
10876                                        aname      => 'BID_PUBLISH_DATE',
10877                                        avalue     => l_bid_publish_date);
10878 
10879             wf_engine.SetItemAttrText (itemtype   => l_itemtype,
10880                                        itemkey    => l_itemkey,
10881                                        aname      => 'BIDDER_TP_NAME',
10882                                        avalue     => l_bidder_tp_name);
10883 
10884             wf_engine.SetItemAttrText (itemtype   => l_itemtype,
10885                                        itemkey    => l_itemkey,
10886                                        aname      => 'SUPPLIER_SITE_NAME',
10887                                        avalue     => l_supplier_site_name);
10888 
10889             wf_engine.SetItemAttrText (itemtype   => l_itemtype,
10890                                        itemkey    => l_itemkey,
10891                                        aname      => 'RESP_PUBLISH_SUBJECT',
10892                                        avalue     => l_resp_publish_sub);
10893 
10894              wf_engine.SetItemAttrText (itemtype  => l_itemtype,
10895                                 itemkey  => l_itemkey,
10896                                 aname  => 'RESPONSE_TYPE',
10897                                 avalue  => l_response_type_name);
10898 
10899              wf_engine.SetItemAttrText (itemtype  => l_itemtype,
10900                                 itemkey  => l_itemkey,
10901                                 aname  => 'RESPONSE_URL',
10902                                 avalue  => l_response_url);
10903 
10904             wf_engine.SetItemAttrText (itemtype   => l_itemtype,
10905                                        itemkey    => l_itemkey,
10906                                        aname      => 'AUCTION_ID',
10907                                        avalue     => l_auction_header_id);
10908 
10909     -- Bug 4295915: Set the  workflow owner
10910             wf_engine.SetItemOwner(itemtype => l_itemtype,
10911                                    itemkey  => l_itemkey,
10912                                    owner    => fnd_global.user_name);
10913 
10914             l_progress := '100';
10915 
10916             wf_engine.StartProcess(itemtype => l_itemtype,
10917                                    itemkey  => l_itemkey );
10918 
10919 
10920             l_progress := 'END';
10921 
10922             IF (FND_LOG.level_procedure >= FND_LOG.g_current_runtime_level) THEN
10923                          FND_LOG.string (log_level => FND_LOG.level_procedure,
10924                                       module => g_module || l_module_name,
10925                                        message  => 'Procedure Ends ' || g_module || l_module_name
10926                                       || ', l_progress = ' || l_progress);
10927             END IF;
10928 
10929             UNSET_SESSION_LANGUAGE;
10930 
10931         EXCEPTION WHEN OTHERS THEN
10932             IF (FND_LOG.level_procedure >= FND_LOG.g_current_runtime_level) THEN
10933                                         FND_LOG.string (log_level => FND_LOG.level_procedure,
10934                                         module => g_module || l_module_name,
10935                                         message  => 'In Exception Block : ' || g_module || l_module_name
10936                                         || ', l_progress = ' || l_progress
10937                                         || ', l_auction_header_id = ' || l_auction_header_id);
10938             END IF;
10939             UNSET_SESSION_LANGUAGE;
10940             x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
10941         END;
10942 
10943 END SEND_RESP_NOTIF;
10944 
10945 /*=========================================================================+
10946 -- 12.0 Enhancement
10947 -- SEND_MSG_SENT_NOTIF procedure will be responsible for
10948 -- sending notification to the Buyer when a Seller sends
10949 -- a message to Buyer or a Buyer sends an internal message
10950 -- to other Collaboration Team Members
10951 -- Parameter :
10952 --          p_toFirstName       IN VARCHAR2
10953 --          p_toLastName        IN VARCHAR2
10954 --          p_toCompanyName     IN VARCHAR2
10955 --          p_toCompanyId       IN NUMBER
10956 --          p_fromFirstName     IN VARCHAR2
10957 --          p_fromLastName      IN VARCHAR2
10958 --          p_fromCompanyName   IN VARCHAR2
10959 --          p_fromCompanyId     IN NUMBER
10960 --          p_creatorCompanyId  IN NUMBER
10961 --          p_userPartyId       IN NUMBER
10962 --          p_entryid           IN NUMBER
10963 --          p_message_type      IN VARCHAR2
10964 --          x_return_status     OUT NOCOPY VARCHAR2
10965 --
10966 +=========================================================================*/
10967 
10968 PROCEDURE SEND_MSG_SENT_NOTIF(
10969           p_toFirstName      IN VARCHAR2,
10970           p_toLastName       IN VARCHAR2,
10971           p_toCompanyName    IN VARCHAR2,
10972           p_toCompanyId      IN NUMBER,
10973           p_fromFirstName    IN VARCHAR2,
10974           p_fromLastName     IN VARCHAR2,
10975           p_fromCompanyName  IN VARCHAR2,
10976           p_fromCompanyId    IN NUMBER,
10977           p_creatorCompanyId IN NUMBER,
10978           p_userPartyId      IN NUMBER,
10979           p_entryid          IN NUMBER,
10980           p_message_type     IN VARCHAR2,
10981           x_return_status    OUT NOCOPY VARCHAR2
10982         )
10983 IS  -- {
10984 
10985     l_module_name CONSTANT   VARCHAR2(40) := 'SEND_MSG_SENT_NOTIF';
10986     l_progress               VARCHAR2(3);
10987     l_language               VARCHAR2(20);
10988     l_lang_code              VARCHAR2(4);
10989     l_doc_number             PON_AUCTION_HEADERS_ALL.DOCUMENT_NUMBER%TYPE;
10990     l_auction_header_id      PON_AUCTION_HEADERS_ALL.AUCTION_HEADER_ID%TYPE;
10991     l_auction_start_date     DATE;
10992     l_auction_end_date       DATE;
10993     l_preview_date           DATE;
10994     l_msg_sent_date          DATE;
10995     l_null_date              DATE;
10996     l_msg_suffix             PON_AUC_DOCTYPES.MESSAGE_SUFFIX%TYPE;
10997     l_auction_title          PON_AUCTION_HEADERS_ALL.AUCTION_TITLE%TYPE;
10998     l_subject                PON_THREADS.SUBJECT%TYPE;
10999     l_sender_name            VARCHAR2(350);
11000     l_recipient_name         VARCHAR2(350);
11001     l_preparer_tp_name       HZ_PARTIES.PARTY_NAME%TYPE;
11002     l_task_name              PON_NEG_TEAM_MEMBERS.TASK_NAME%TYPE;
11003     l_task_target_date       DATE;
11004     l_task_assignment_date   DATE;
11005     l_msg_sent_subject       VARCHAR2(2000);
11006     l_timezone_disp          VARCHAR2(240);
11007     l_timezone_disp1         VARCHAR2(240);
11008     l_timezone_nodisp        VARCHAR2(240);
11009     l_auctioneer_user_name   VARCHAR2(244);
11010     l_auctioneer_tpc_id      NUMBER;
11011     l_person_party_id        NUMBER;
11012     l_sequence               NUMBER;
11013     l_itemtype               VARCHAR2(7);
11014     l_itemkey               VARCHAR2(50);
11015     l_user_id                NUMBER;
11016     l_user_name              FND_USER.USER_NAME%TYPE;
11017     l_sender_user            FND_USER.USER_NAME%TYPE;
11018     l_from_id                NUMBER;
11019     l_from_company_id        NUMBER;
11020     l_page_url               VARCHAR2(500);
11021     l_discussion_id          NUMBER;
11022     l_is_sealed_neg          VARCHAR2(1);
11023     l_notif_performer        VARCHAR2(10); -- BUYER or SUPPLIER
11024     l_staggered_cls_intrvl   NUMBER;
11025     l_open_auction_now_flag VARCHAR2(1);
11026     l_publish_auction_now_flag   VARCHAR2(1);
11027 
11028 
11029     CURSOR INT_MEMBERS (p_sender_id               NUMBER,
11030                         p_auction_header_id       NUMBER,
11031                         p_discussion_id           NUMBER)
11032     IS
11033         SELECT
11034                 hz.party_id TO_PARTY_ID,
11035                 PON_LOCALE_PKG.get_party_display_name(hz.party_id,2, userenv('LANG')) TO_PARTY_NAME,
11036                 hz.person_first_name FIRST_NAME,
11037                 hz.person_last_name LAST_NAME
11038         FROM pon_neg_team_members  pntm,
11039                   HZ_PARTIES hz,
11040                   fnd_user fu
11041         WHERE hz.party_id=fu.person_party_id
11042         AND nvl(fu.end_date,sysdate+1) > sysdate
11043         AND fu.user_id=pntm.user_id
11044         AND fu.person_party_id <> p_sender_id
11045         AND pntm.auction_header_id = p_auction_header_id
11046         UNION
11047         SELECT
11048                 distinct pte.from_id TO_PARTY_ID,
11049                 PON_LOCALE_PKG.get_party_display_name(pte.from_id,2, userenv('LANG'))  TO_PARTY_NAME,
11050                 pte.from_first_name FIRST_NAME, pte.from_last_name LAST_NAME
11051         FROM pon_threads pt,
11052                   pon_thread_entries pte
11053         WHERE pt.discussion_id = p_discussion_id
11054         AND pt.discussion_id = pte.discussion_id
11055         AND pt.thread_number = pte.thread_number
11056         AND pte.from_id <> p_sender_id
11057         AND pte.vendor_id is null;
11058 
11059    CURSOR EXT_MEMBER (p_auction_header_id       NUMBER,
11060                       p_discussion_id           NUMBER,
11061                       p_auctioneer_tpc_id       NUMBER)
11062    IS
11063       SELECT DISTINCT
11064         PBP.TRADING_PARTNER_CONTACT_ID TO_PARTY_ID,
11065         PON_LOCALE_PKG.GET_PARTY_DISPLAY_NAME(PBP.TRADING_PARTNER_CONTACT_ID, 2 , USERENV('LANG'))||' - '||NVL(HZ.PARTY_NAME,'')  TO_PARTY_NAME,
11066         HZ1.PERSON_FIRST_NAME FIRST_NAME,
11067         HZ1.PERSON_LAST_NAME LAST_NAME,
11068         HZ.PARTY_ID COMPANY_ID,
11069         HZ.PARTY_NAME COMPANY_NAME
11070       FROM PON_BIDDING_PARTIES PBP,
11071         HZ_PARTIES HZ,
11072         HZ_PARTIES HZ1
11073       WHERE PBP.AUCTION_HEADER_ID = p_auction_header_id
11074         AND HZ.PARTY_ID=PBP.TRADING_PARTNER_ID
11075         AND HZ1.PARTY_ID= PBP.TRADING_PARTNER_CONTACT_ID
11076       UNION
11077       SELECT DISTINCT
11078         PBH.TRADING_PARTNER_CONTACT_ID TO_PARTY_ID,
11079         PON_LOCALE_PKG.GET_PARTY_DISPLAY_NAME(PBH.TRADING_PARTNER_CONTACT_ID,2,USERENV('LANG'))||' - '||NVL(HZ.PARTY_NAME,'')  TO_PARTY_NAME,
11080         HZ1.PERSON_FIRST_NAME FIRST_NAME,
11081         HZ1.PERSON_LAST_NAME LAST_NAME,
11082         HZ.PARTY_ID COMPANY_ID,
11083         HZ.PARTY_NAME COMPANY_NAME
11084       FROM PON_BID_HEADERS PBH,
11085         HZ_PARTIES HZ,
11086         HZ_PARTIES HZ1
11087       WHERE PBH.AUCTION_HEADER_ID = p_auction_header_id
11088         AND HZ.PARTY_ID=PBH.TRADING_PARTNER_ID
11089         AND HZ1.PARTY_ID=PBH.TRADING_PARTNER_CONTACT_ID
11090         AND PBH.BID_STATUS NOT IN ('ARCHIVED','DISQUALIFIED')
11091       UNION
11092       SELECT DISTINCT
11093         PTE.FROM_ID TO_PARTY_ID,
11094         PON_LOCALE_PKG.GET_PARTY_DISPLAY_NAME(PTE.FROM_ID, 2,USERENV('LANG')) ||' - '||NVL(PTE.FROM_COMPANY_NAME,'')  TO_PARTY_NAME,
11095         PTE.FROM_FIRST_NAME FIRST_NAME,
11096         PTE.FROM_LAST_NAME LAST_NAME,
11097         PTE.FROM_COMPANY_ID COMPANY_ID,
11098         PTE.FROM_COMPANY_NAME COMPANY_NAME
11099       FROM PON_THREADS PT,
11100         PON_THREAD_ENTRIES PTE,
11101         PON_TE_RECIPIENTS PTR
11102       WHERE PT.DISCUSSION_ID = p_discussion_id
11103         AND PT.DISCUSSION_ID = PTE.DISCUSSION_ID
11104         AND PT.THREAD_NUMBER = PTE.THREAD_NUMBER
11105         AND PTE.ENTRY_ID = PTR.ENTRY_ID
11106         AND PTR.TO_ID = p_auctioneer_tpc_id
11107         AND PTE.VENDOR_ID IS NOT NULL;
11108 
11109 
11110             CURSOR SCORING_MEMBERS (p_sender_id               NUMBER,
11111                                 p_auction_header_id       NUMBER,
11112                                 p_team_id                        NUMBER)
11113             IS
11114                 SELECT
11115                         hz.party_id TO_PARTY_ID,
11116                         PON_LOCALE_PKG.get_party_display_name(hz.party_id,2, userenv('LANG')) TO_PARTY_NAME,
11117                         hz.person_first_name FIRST_NAME,
11118                         hz.person_last_name LAST_NAME
11119                 FROM pon_scoring_team_members  pntm,
11120                           HZ_PARTIES hz,
11121                           fnd_user fu
11122                 WHERE hz.party_id=fu.person_party_id
11123                 AND fu.user_id=pntm.user_id
11124                 AND nvl(fu.end_date,sysdate+1) > sysdate
11125                 AND fu.person_party_id <> p_sender_id
11126                 AND pntm.auction_header_id = p_auction_header_id
11127                 AND pntm.team_id = p_team_id;
11128 
11129             CURSOR ALL_SCORING_MEMBERS (p_sender_id               NUMBER,
11130                                 p_auction_header_id       NUMBER)
11131             IS
11132                 SELECT  distinct
11133                         hz.party_id TO_PARTY_ID,
11134                         PON_LOCALE_PKG.get_party_display_name(hz.party_id,2, userenv('LANG')) TO_PARTY_NAME,
11135                         hz.person_first_name FIRST_NAME,
11136                         hz.person_last_name LAST_NAME
11137                 FROM pon_scoring_team_members  pntm,
11138                           HZ_PARTIES hz,
11139                           fnd_user fu
11140                 WHERE hz.party_id=fu.person_party_id
11141                 AND fu.user_id=pntm.user_id
11142                 AND nvl(fu.end_date,sysdate+1) > sysdate
11143                 AND fu.person_party_id <> p_sender_id
11144                 AND pntm.auction_header_id = p_auction_header_id;
11145 
11146             CURSOR GROUP_MEMBERS (p_sender_id NUMBER,
11147                                   p_entryId   NUMBER)
11148             IS
11149                 SELECT ptr.to_id TO_PARTY_ID,
11150                        PON_LOCALE_PKG.get_party_display_name(ptr.to_id,2, userenv('LANG')) TO_PARTY_NAME,
11151                        ptr.to_first_name FIRST_NAME,
11152                        ptr.to_last_name LAST_NAME
11153                 FROM pon_te_recipients ptr
11154                 WHERE ptr.entry_id = p_entryId
11155                   AND ptr.to_id <> p_sender_id;
11156 
11157 
11158       --}
11159 
11160 BEGIN --{
11161        x_return_status := FND_API.G_RET_STS_ERROR;
11162 
11163         l_progress := '000';
11164         l_null_date := null;
11165 
11166         IF (FND_LOG.level_procedure >= FND_LOG.g_current_runtime_level) THEN
11167                       FND_LOG.string (log_level => FND_LOG.level_procedure,
11168                                    module => g_module || l_module_name,
11169                                    message  => 'Entering to Procedure ' || g_module || l_module_name
11170                                    || ', l_progress = ' || l_progress
11171                                    || ', p_entryid = ' || p_entryid
11172                                    || ', p_toFirstName = ' ||   p_toFirstName
11173                                    || ', p_toLastName = ' ||  p_toLastName
11174                                    || ', p_toCompanyName = ' || p_toCompanyName
11175                                    || ', p_toCompanyId  = ' || p_toCompanyId
11176                                    || ', p_fromFirstName = ' || p_fromFirstName
11177                                    || ', p_fromLastName = ' || p_fromLastName
11178                                    || ', p_fromCompanyName = ' || p_fromCompanyName
11179                                    || ', p_fromCompanyId = ' || p_fromCompanyId
11180                                    || ', p_creatorCompanyId = ' ||  p_creatorCompanyId
11181                                    || ', p_userPartyId = ' || p_userPartyId
11182                                    || ', p_entryid = ' || p_entryid  );
11183          END IF;
11184 
11185            l_progress := '001';
11186            SELECT
11187                 auh.DOCUMENT_NUMBER,
11188                 auh.AUCTION_HEADER_ID,
11189                 auh.OPEN_BIDDING_DATE,
11190                 auh.CLOSE_BIDDING_DATE,
11191                 auh.VIEW_BY_DATE,
11192                 pad.MESSAGE_SUFFIX,
11193                 auh.AUCTION_TITLE,
11194                 auh.TRADING_PARTNER_CONTACT_NAME,
11195                 auh.TRADING_PARTNER_CONTACT_ID,
11196                 auh.STAGGERED_CLOSING_INTERVAL,
11197                 decode(nvl(auh.bid_visibility_code,'N'),
11198                           'SEALED_AUCTION','Y',
11199                                            'N'),
11200                 SYSDATE,
11201                 pt.SUBJECT,
11202                 pte.FROM_ID,
11203                 pte.FROM_COMPANY_ID,
11204                 pd.discussion_id,
11205                 open_auction_now_flag,
11206                 publish_auction_now_flag
11207             INTO
11208                   l_doc_number,
11209                   l_auction_header_id,
11210                   l_auction_start_date,
11211                   l_auction_end_date,
11212                   l_preview_date,
11213                   l_msg_suffix,
11214                   l_auction_title,
11215                   l_auctioneer_user_name,
11216                   l_auctioneer_tpc_id,
11217                   l_staggered_cls_intrvl,
11218                   l_is_sealed_neg,
11219                   l_msg_sent_date,
11220                   l_subject,
11221                   l_from_id,
11222                   l_from_company_id,
11223                   l_discussion_id,
11224                   l_open_auction_now_flag ,
11225                   l_publish_auction_now_flag
11226             FROM pon_auction_headers_all auh,
11227                 pon_auc_doctypes pad,
11228                 pon_thread_entries pte,
11229                 pon_threads pt,
11230                 pon_discussions pd
11231             WHERE pte.entry_id = p_entryid
11232                 AND pd.discussion_id = pte.discussion_id
11233                 AND pt.discussion_id = pte.discussion_id
11234                 AND pt.thread_number = pte.thread_number
11235                 AND auh.auction_header_id = pd.pk1_value
11236                 AND pad.doctype_id = auh.doctype_id;
11237 
11238           l_progress := '002';
11239           IF (FND_LOG.level_procedure >= FND_LOG.g_current_runtime_level) THEN
11240                       FND_LOG.string (log_level => FND_LOG.level_procedure,
11241                                    module => g_module || l_module_name,
11242                                    message  => 'Negotiation Data retrieved for Document Number: ' || l_doc_number);
11243           END IF;
11244 
11245 
11246 
11247           IF (p_toCompanyId = 0 ) THEN --{
11248                 --
11249                 -- Group Message / Multiselect Case
11250                 --
11251 
11252                 l_progress := '020';
11253 
11254                 IF ('EXTERNAL' = p_message_type) THEN
11255                     l_notif_performer := 'SUPPLIER';
11256                 ELSE
11257                     l_notif_performer := 'BUYER';
11258                 END IF;
11259 
11260 
11261                 FOR member IN  GROUP_MEMBERS(l_from_id, p_entryid)
11262                 LOOP
11263                 --{
11264                                NOTIFY_MEMBER(   p_userPartyId                => member.to_party_id,
11265                                                 p_auctioneer_user_name       => l_auctioneer_user_name,
11266                                                 p_auction_start_date         => l_auction_start_date,
11267                                                 p_auction_end_date           => l_auction_end_date,
11268                                                 p_preview_date               => l_preview_date,
11269                                                 p_msg_sent_date              => l_msg_sent_date,
11270                                                 p_msg_suffix                 => l_msg_suffix,
11271                                                 p_doc_number                 => l_doc_number,
11272                                                 p_auction_title              => l_auction_title,
11273                                                 p_entryid                    => p_entryid,
11274                                                 p_auction_header_id          => l_auction_header_id,
11275                                                 p_fromFirstName              => p_fromFirstName,
11276                                                 p_fromLastName               => p_fromLastName,
11277                                                 p_from_id                    => l_from_id,
11278                                                 p_notif_performer            => l_notif_performer,
11279                                                 p_subject                    => l_subject,
11280                                                 p_message_type               => p_message_type,
11281                                                 p_fromCompanyName            => p_fromCompanyName,
11282                                                 p_discussion_id              => l_discussion_id,
11283                                                 p_stagger_closing_interval   => l_staggered_cls_intrvl,
11284                                                 p_open_auction_now_flag      => l_open_auction_now_flag,
11285                                                 p_publish_auction_now_flag   => l_publish_auction_now_flag);
11286                 --}
11287                 END LOOP;
11288 
11289           -- } End of If it is group / multiSelect message
11290           --
11291           --  If it is a point to point message then we need to send the notification
11292           --  to the Recipient of the message only
11293           --
11294           ELSIF (p_toCompanyId > 0 ) THEN --{
11295                 --
11296                 -- Point to point messaging
11297                 --
11298 
11299                 l_progress := '030';
11300                 IF ( p_creatorCompanyId = l_from_company_id ) THEN
11301                     l_notif_performer := 'SUPPLIER';
11302                 ELSE
11303                     l_notif_performer := 'BUYER';
11304                 END IF;
11305 
11306                 IF ('EXTERNAL' = p_message_type AND p_creatorCompanyId = l_from_company_id) THEN
11307                     --
11308                     -- So, this is a message to Supplier hence make the From
11309                     -- id to that of the Negotiation Creator
11310                     --
11311                     l_from_id := l_auctioneer_tpc_id;
11312 
11313                 END IF;
11314 
11315                 NOTIFY_MEMBER(                  p_userPartyId                => p_userPartyId,
11316                                                 p_auctioneer_user_name       => l_auctioneer_user_name,
11317                                                 p_auction_start_date         => l_auction_start_date,
11318                                                 p_auction_end_date           => l_auction_end_date,
11319                                                 p_preview_date               => l_preview_date,
11320                                                 p_msg_sent_date              => l_msg_sent_date,
11321                                                 p_msg_suffix                 => l_msg_suffix,
11322                                                 p_doc_number                 => l_doc_number,
11323                                                 p_auction_title              => l_auction_title,
11324                                                 p_entryid                    => p_entryid,
11325                                                 p_auction_header_id          => l_auction_header_id,
11326                                                 p_fromFirstName              => p_fromFirstName,
11327                                                 p_fromLastName               => p_fromLastName,
11328                                                 p_from_id                    => l_from_id,
11329                                                 p_notif_performer            => l_notif_performer,
11330                                                 p_subject                    => l_subject,
11331                                                 p_message_type               => p_message_type,
11332                                                 p_fromCompanyName            => p_fromCompanyName,
11333                                                 p_discussion_id              => l_discussion_id,
11334                                                 p_stagger_closing_interval   => l_staggered_cls_intrvl,
11335                                                 p_open_auction_now_flag      => l_open_auction_now_flag,
11336                                                 p_publish_auction_now_flag   => l_publish_auction_now_flag);
11337 
11338           -- } End of If it is not a broadcast msg
11339           --
11340           -- The next block is meant for - Sealed Negotiation
11341           --                               And External Broadcast
11342           --                               And Seller initiated message
11343           -- Then only Buyer will get a notification from the seller
11344           -- and other sellers will NOT get any notification to protect
11345           -- the seller's identity
11346           --
11347           ELSIF ('Y' = l_is_sealed_neg
11348                  AND 'EXTERNAL' = p_message_type
11349                  AND p_toCompanyId < 0
11350                  AND p_creatorCompanyId <> l_from_company_id) THEN --{
11351 
11352                 --
11353                 -- It is the case of Sealed  External Broadcast
11354                 -- where we will be sending point to point notification
11355                 -- It will be always a Seller to Buyer notification
11356                 --
11357 
11358                 l_progress := '040';
11359 
11360                 l_notif_performer := 'BUYER'; -- As Buyer is the only reciever of this notification
11361 
11362                 NOTIFY_MEMBER(                  p_userPartyId                => l_auctioneer_tpc_id,
11363                                                 p_auctioneer_user_name       => l_auctioneer_user_name,
11364                                                 p_auction_start_date         => l_auction_start_date,
11365                                                 p_auction_end_date           => l_auction_end_date,
11366                                                 p_preview_date               => l_preview_date,
11367                                                 p_msg_sent_date              => l_msg_sent_date,
11368                                                 p_msg_suffix                 => l_msg_suffix,
11369                                                 p_doc_number                 => l_doc_number,
11370                                                 p_auction_title              => l_auction_title,
11371                                                 p_entryid                    => p_entryid,
11372                                                 p_auction_header_id          => l_auction_header_id,
11373                                                 p_fromFirstName              => p_fromFirstName,
11374                                                 p_fromLastName               => p_fromLastName,
11375                                                 p_from_id                    => l_from_id,
11376                                                 p_notif_performer            => l_notif_performer,
11377                                                 p_subject                    => l_subject,
11378                                                 p_message_type               => p_message_type,
11379                                                 p_fromCompanyName            => p_fromCompanyName,
11380                                                 p_discussion_id              => l_discussion_id,
11381                                                 p_stagger_closing_interval   => l_staggered_cls_intrvl,
11382                                                 p_open_auction_now_flag      => l_open_auction_now_flag,
11383                                                 p_publish_auction_now_flag   => l_publish_auction_now_flag);
11384 
11385 
11386           ELSE  --} End of If it is not a Selaed broadcast msg
11387           --{
11388                 --
11389                 -- Broadcast messaging
11390                 --
11391                 l_progress := '050';
11392                 --
11393                 -- Check if it is the internal broadcast
11394                 --
11395                 IF ('INTERNAL' = p_message_type ) THEN --{
11396                         --
11397                         -- Get the list of the team members and post them the
11398                         -- notifications
11399                         --
11400                         l_progress := '060';
11401 
11402                         l_notif_performer := 'BUYER'; -- As Buyer users are the only recievers of this notification
11403 
11404       --
11405       -- Now this broadcast can be three simple varieties namely -
11406       --  All Team Members Broadcast          (p_toCompanyId = -2)
11407       --  All Scoring Team Members Broadcast  (p_toCompanyId = -3)
11408       --   Specific Scoring Team Broadcast     (p_toCompanyId = -X), where X is the Scoring Team Id
11409       --
11410       -- We, need handle those cases in the following if else blocks
11411       --
11412 
11413                         IF  (p_toCompanyId = -2) THEN  --{
11414 
11415                                 l_progress := '062';
11416 
11417                           FOR member IN  INT_MEMBERS (l_from_id, l_auction_header_id,l_discussion_id)
11418                           LOOP
11419                           --{
11420 
11421                                 NOTIFY_MEMBER(  p_userPartyId                => member.to_party_id,
11422                                                     p_auctioneer_user_name       => l_auctioneer_user_name,
11423                                                     p_auction_start_date         => l_auction_start_date,
11424                                                     p_auction_end_date           => l_auction_end_date,
11425                                                     p_preview_date               => l_preview_date,
11426                                                     p_msg_sent_date              => l_msg_sent_date,
11427                                                     p_msg_suffix                 => l_msg_suffix,
11428                                                     p_doc_number                 => l_doc_number,
11429                                                     p_auction_title              => l_auction_title,
11430                                                     p_entryid                    => p_entryid,
11431                                                     p_auction_header_id          => l_auction_header_id,
11432                                                     p_fromFirstName              => p_fromFirstName,
11433                                                     p_fromLastName               => p_fromLastName,
11434                                                     p_from_id                    => l_from_id,
11435                                                     p_notif_performer            => l_notif_performer,
11436                                                     p_subject                    => l_subject,
11437                                                     p_message_type               => p_message_type,
11438                                                     p_fromCompanyName            => p_fromCompanyName,
11439                                                     p_discussion_id              => l_discussion_id,
11440                                                     p_stagger_closing_interval   => l_staggered_cls_intrvl,
11441                                                     p_open_auction_now_flag      => l_open_auction_now_flag,
11442                                                     p_publish_auction_now_flag   => l_publish_auction_now_flag);
11443 
11444                           --}
11445                           END LOOP;
11446       --}
11447                         ELSIF (p_toCompanyId = -3) THEN --{
11448 
11449         l_progress := '065';
11450 
11451         FOR member IN  ALL_SCORING_MEMBERS (l_from_id, l_auction_header_id)
11452                                 LOOP
11453                                 --{
11454 
11455                                         NOTIFY_MEMBER(      p_userPartyId                => member.to_party_id,
11456                                                             p_auctioneer_user_name       => l_auctioneer_user_name,
11457                                                             p_auction_start_date         => l_auction_start_date,
11458                                                             p_auction_end_date           => l_auction_end_date,
11459                                                             p_preview_date               => l_preview_date,
11460                                                             p_msg_sent_date              => l_msg_sent_date,
11461                                                             p_msg_suffix                 => l_msg_suffix,
11462                                                             p_doc_number                 => l_doc_number,
11463                                                             p_auction_title              => l_auction_title,
11464                                                             p_entryid                    => p_entryid,
11465                                                             p_auction_header_id          => l_auction_header_id,
11466                                                             p_fromFirstName              => p_fromFirstName,
11467                                                             p_fromLastName               => p_fromLastName,
11468                                                             p_from_id                    => l_from_id,
11469                                                             p_notif_performer            => l_notif_performer,
11470                                                             p_subject                    => l_subject,
11471                                                             p_message_type               => p_message_type,
11472                                                             p_fromCompanyName            => p_fromCompanyName,
11473                                                             p_discussion_id              => l_discussion_id,
11474                                                             p_stagger_closing_interval   => l_staggered_cls_intrvl,
11475                                                             p_open_auction_now_flag      => l_open_auction_now_flag,
11476                                                             p_publish_auction_now_flag   => l_publish_auction_now_flag);
11477 
11478                                 --}
11479                                 END LOOP;
11480 
11481       --}
11482       ELSIF (p_toCompanyId < -3) THEN --{
11483 
11484         l_progress := '067';
11485 
11486              FOR member IN  SCORING_MEMBERS (l_from_id, l_auction_header_id, -1*p_toCompanyId)
11487                                 LOOP
11488                                 --{
11489 
11490                                         NOTIFY_MEMBER(      p_userPartyId                => member.to_party_id,
11491                                                             p_auctioneer_user_name       => l_auctioneer_user_name,
11492                                                             p_auction_start_date         => l_auction_start_date,
11493                                                             p_auction_end_date           => l_auction_end_date,
11494                                                             p_preview_date               => l_preview_date,
11495                                                             p_msg_sent_date              => l_msg_sent_date,
11496                                                             p_msg_suffix                 => l_msg_suffix,
11497                                                             p_doc_number                 => l_doc_number,
11498                                                             p_auction_title              => l_auction_title,
11499                                                             p_entryid                    => p_entryid,
11500                                                             p_auction_header_id          => l_auction_header_id,
11501                                                             p_fromFirstName              => p_fromFirstName,
11502                                                             p_fromLastName               => p_fromLastName,
11503                                                             p_from_id                    => l_from_id,
11504                                                             p_notif_performer            => l_notif_performer,
11505                                                             p_subject                    => l_subject,
11506                                                             p_message_type               => p_message_type,
11507                                                             p_fromCompanyName            => p_fromCompanyName,
11508                                                             p_discussion_id              => l_discussion_id,
11509                                                               p_stagger_closing_interval   => l_staggered_cls_intrvl,
11510                                                             p_open_auction_now_flag      => l_open_auction_now_flag,
11511                                                             p_publish_auction_now_flag   => l_publish_auction_now_flag);
11512 
11513                                 --}
11514                                 END LOOP;
11515 
11516       --}
11517       END IF;
11518          --}
11519                 ELSIF ('EXTERNAL' = p_message_type ) THEN --{
11520                         --
11521                         -- So, it is an external broadcast
11522                         --
11523 
11524                         l_notif_performer := 'SUPPLIER'; -- As Supplier users are the only recievers of this notification
11525 
11526                         l_progress := '070';
11527 
11528                         FOR member IN  EXT_MEMBER (l_auction_header_id,l_discussion_id, l_from_id)
11529                         LOOP
11530                         --{
11531 
11532                             NOTIFY_MEMBER(      p_userPartyId                => member.to_party_id,
11533                                                 p_auctioneer_user_name       => l_auctioneer_user_name,
11534                                                 p_auction_start_date         => l_auction_start_date,
11535                                                 p_auction_end_date           => l_auction_end_date,
11536                                                 p_preview_date               => l_preview_date,
11537                                                 p_msg_sent_date              => l_msg_sent_date,
11538                                                 p_msg_suffix                 => l_msg_suffix,
11539                                                 p_doc_number                 => l_doc_number,
11540                                                 p_auction_title              => l_auction_title,
11541                                                 p_entryid                    => p_entryid,
11542                                                 p_auction_header_id          => l_auction_header_id,
11543                                                 p_fromFirstName              => p_fromFirstName,
11544                                                 p_fromLastName               => p_fromLastName,
11545                                                 p_from_id                    => l_from_id,
11546                                                 p_notif_performer            => l_notif_performer,
11547                                                 p_subject                    => l_subject,
11548                                                 p_message_type               => p_message_type,
11549                                                 p_fromCompanyName            => p_fromCompanyName,
11550                                                 p_discussion_id              => l_discussion_id,
11551                                                 p_stagger_closing_interval   => l_staggered_cls_intrvl,
11552                                                 p_open_auction_now_flag      => l_open_auction_now_flag,
11553                                                 p_publish_auction_now_flag   => l_publish_auction_now_flag);
11554 
11555                         --}
11556                         END LOOP;
11557                 END IF;
11558                 --}
11559           END IF;
11560           --}
11561 
11562           l_progress := '090';
11563 
11564           x_return_status := FND_API.G_RET_STS_SUCCESS;
11565 
11566 EXCEPTION
11567       WHEN OTHERS THEN
11568            WF_CORE.CONTEXT ('PONAUCT','SEND_MSG_SENT_NOTIF','Process:'||l_progress||'SQL error:' || sqlcode|| ', error message:' ||substr(sqlerrm,1,512));
11569            RAISE;
11570 
11571 END SEND_MSG_SENT_NOTIF;  -- }
11572 
11573 /*=========================================================================+
11574 --
11575 -- 12.0 Enhancement
11576 -- IS_NOTIF_SUBSCRIBED  is a wrapper over the GET_NOTIF_PREFERENCE
11577 -- of PON_WF_UTL_PKG. It will call the procedure GET_NOTIF_PREFERENCE with
11578 -- appropriate message type and auction header id.
11579 --
11580 -- Parameter :
11581 --             itemtype  IN VARCHAR2
11582 --             itemkey   IN VARCHAR2
11583 --             actid     IN NUMBER
11584 --         funcmode  IN VARCHAR2
11585 --         resultout OUT NOCOPY VARCHAR2
11586 --
11587 +=========================================================================*/
11588 
11589 
11590 PROCEDURE IS_NOTIF_SUBSCRIBED(itemtype        in varchar2,
11591                               itemkey         in varchar2,
11592                               actid           in number,
11593                               funcmode        in varchar2,
11594                               resultout       out NOCOPY varchar2)
11595 IS
11596      l_negotiation_id   NUMBER;
11597      l_wf_message_name  VARCHAR2(100);
11598      l_tp_type          VARCHAR2(20); -- TO indicate if it is a buyer or a seller
11599      l_module_name      CONSTANT VARCHAR2(30) := 'IS_NOTIF_SUBSCRIBED';
11600      l_change_type      NUMBER;
11601      l_is_event_auction VARCHAR2(1);
11602 
11603 BEGIN --{
11604           --
11605           -- Get the auction_header_id depending on the different itemtype possible
11606           --
11607           IF (itemtype = 'PONAPPRV' OR itemtype = 'PONAWAPR') THEN
11608                 l_negotiation_id := wf_engine.GetItemAttrNumber (itemtype => itemtype,
11609                                                                  itemkey  => itemkey,
11610                                                                  aname    => 'AUCTION_HEADER_ID');
11611           ELSE
11612                 l_negotiation_id := wf_engine.GetItemAttrNumber (itemtype => itemtype,
11613                                                                  itemkey  => itemkey,
11614                                                                  aname    => 'AUCTION_ID');
11615           END IF;
11616 
11617           --
11618           -- Get the Function Attribute for this call. It will pass the
11619           -- WF_MESSAGE_NAME attribute associated with a notification
11620           --
11621     l_wf_message_name := Wf_Engine.GetActivityAttrText( itemtype,
11622                     itemkey,
11623                     actid,
11624                     'PON_WF_MESSAGE_NAME');
11625 
11626 
11627     IF (FND_LOG.level_procedure >= FND_LOG.g_current_runtime_level) THEN
11628       FND_LOG.string (log_level => FND_LOG.level_procedure,
11629       module => g_module || l_module_name,
11630       message  => 'In ' || g_module || l_module_name
11631             || ', itemtype = ' || itemtype
11632             || ', itemkey = ' || itemkey
11633             || ', actid = ' || actid
11634             || ', funcmode = ' || funcmode
11635             || ', resultout = ' || resultout
11636             || ', l_negotiation_id = ' || l_negotiation_id
11637             || ', l_wf_message_name = ' || l_wf_message_name);
11638     END IF;
11639 
11640           --
11641           -- CLOSECHANGED Block, responsible for finding the exact message name for
11642           -- CLOSECHANGED process. The process starts with a different message name and
11643           -- can change the message name as the workflow progresses
11644           --
11645           IF (l_wf_message_name= 'CLOSECHANGED') THEN
11646               BEGIN
11647                    l_change_type := wf_engine.GetItemAttrNumber (itemtype => itemtype,
11648                                                                  itemkey  => itemkey,
11649                                                                  aname => 'CHANGE_TYPE');
11650               EXCEPTION
11651                    WHEN OTHERS THEN
11652                        l_change_type := 1; -- for auctions created before version 115.20 of ponwfau1.wft this attribute did not exist
11653               END;
11654 
11655 
11656               IF (l_change_type = 1) THEN
11657                     --
11658                     -- auctioneer has extended the auction
11659                     --
11660                     l_wf_message_name := 'NEGOTIATION_EXTENDED';
11661               ELSE
11662                      --
11663                      -- auctioneer has shortened the auction
11664                      --
11665                     l_wf_message_name := 'NEGOTIATION_SHORTENED';
11666               END IF;
11667           END IF; -- END OF CLOSECHANGED Block
11668 
11669           --
11670           -- CALCEL Block
11671           --
11672 
11673           IF (l_wf_message_name = 'CANCEL') THEN
11674             l_is_event_auction := IS_EVENT_AUCTION(l_negotiation_id);
11675 
11676             IF (l_is_event_auction = 'Y') THEN
11677                l_wf_message_name := 'NEGOTIATION_CANCELED_EVENT';
11678             ELSE
11679                l_wf_message_name := 'NEGOTIATION_CANCELED';
11680             END IF;
11681 
11682           END IF;  -- END OF CANCEL Block
11683 
11684           --
11685           -- Online Discussion Message Sent Block
11686           --
11687 
11688           IF (l_wf_message_name = 'DISCUSSIONMESSAGE') THEN
11689 
11690             l_tp_type := wf_engine.GetItemAttrText (itemtype => itemtype,
11691                                                     itemkey  => itemkey,
11692                                                     aname    => 'TRADING_PARTNER_TYPE');
11693 
11694             IF (l_tp_type = 'BUYER') THEN
11695                l_wf_message_name := 'BUYER_DISC_MESSAGE_SENT_MSG';
11696             ELSE
11697                l_wf_message_name := 'SUPPLIER_DISC_MESSAGE_SENT_MSG';
11698             END IF;
11699 
11700           END IF;  -- END of Disc. Meg Sent Block
11701 
11702    resultout := PON_WF_UTL_PKG.GET_NOTIF_PREFERENCE(l_wf_message_name,l_negotiation_id);
11703 
11704 EXCEPTION  --}
11705       WHEN OTHERS THEN
11706               resultout := PON_WF_UTL_PKG.G_NO;
11707               IF (FND_LOG.level_procedure >= FND_LOG.g_current_runtime_level) THEN
11708           FND_LOG.string (log_level => FND_LOG.level_procedure,
11709           module => g_module || l_module_name,
11710           message  => 'Exception Block ' || g_module || l_module_name
11711            || ', l_negotiation_id = ' || l_negotiation_id
11712                || ', l_wf_message_name = ' || l_wf_message_name
11713                            ||', sql error code'||sqlcode);
11714         END IF;
11715       RAISE;
11716 END IS_NOTIF_SUBSCRIBED;
11717 
11718 PROCEDURE NOTIFY_MEMBER(p_userPartyId           IN NUMBER,
11719                         p_auctioneer_user_name  IN VARCHAR2,
11720                         p_auction_start_date    IN DATE,
11721                         p_auction_end_date      IN DATE,
11722                         p_preview_date          IN DATE,
11723                         p_msg_sent_date         IN DATE,
11724                         p_msg_suffix            IN VARCHAR2,
11725                         p_doc_number            IN VARCHAR2,
11726                         p_auction_title         IN VARCHAR2,
11727                         p_entryid               IN NUMBER,
11728                         p_auction_header_id     IN NUMBER,
11729                         p_fromFirstName         IN VARCHAR2,
11730                         p_fromLastName          IN VARCHAR2,
11731                         p_from_id               IN NUMBER,
11732                         p_notif_performer       IN VARCHAR2,
11733                         p_subject               IN VARCHAR2,
11734                         p_message_type          IN VARCHAR2,
11735                         p_fromCompanyName       IN VARCHAR2,
11736                         p_discussion_id         IN NUMBER,
11737                         p_stagger_closing_interval IN NUMBER,
11738                         p_open_auction_now_flag  IN VARCHAR2,
11739                         p_publish_auction_now_flag IN VARCHAR2
11740                         )
11741 IS
11742         l_null_date           DATE;
11743         l_progress            VARCHAR2(3);
11744         l_module_name         CONSTANT VARCHAR2(20) := '.NOTIFY_MEMBER';
11745 
11746         l_language            VARCHAR2(20);
11747         l_lang_code           VARCHAR2(4);
11748         l_sender_name         VARCHAR2(350);
11749         l_recipient_name      VARCHAR2(350);
11750 
11751         l_msg_sent_subject    VARCHAR2(2000);
11752         l_timezone_disp       VARCHAR2(240);
11753         l_timezone_disp1      VARCHAR2(240);
11754         l_timezone_nodisp     VARCHAR2(240);
11755 
11756         l_itemtype        VARCHAR2(7);
11757         l_itemkey        VARCHAR2(50);
11758         l_user_id             NUMBER;
11759         l_user_name           FND_USER.USER_NAME%TYPE;
11760         l_sender_user         FND_USER.USER_NAME%TYPE;
11761         l_page_url            VARCHAR2(500);
11762         l_wfm_htmlagent       VARCHAR2(500);
11763         l_discussion_id       NUMBER;
11764         l_auction_start_date  DATE;
11765         l_auction_end_date    DATE;
11766         l_preview_date        DATE;
11767         l_msg_sent_date       DATE;
11768         l_staggered_close_note VARCHAR2(1000);
11769 
11770         x_language_code       VARCHAR2(60);
11771         x_territory_code      VARCHAR2(30);
11772 
11773 BEGIN
11774 --{
11775                 l_null_date := NULL;
11776                 l_auction_start_date  := p_auction_start_date;
11777                 l_auction_end_date   := p_auction_end_date;
11778                 l_preview_date          := p_preview_date;
11779                 l_msg_sent_date       := p_msg_sent_date;
11780                 l_progress  := '010';
11781 
11782                 BEGIN
11783 
11784                   BEGIN
11785 
11786                     SELECT
11787                         USER_ID,
11788                         USER_NAME
11789                     INTO
11790                         l_user_id,
11791                         l_user_name
11792                     FROM FND_USER
11793                     WHERE PERSON_PARTY_ID = p_userPartyId
11794                     AND NVL(END_DATE, SYSDATE+1) > SYSDATE;
11795 
11796                  EXCEPTION
11797                        WHEN TOO_MANY_ROWS THEN
11798                           IF (NVL(FND_PROFILE.VALUE('AFLOG_ENABLED'),'N') = 'Y') THEN
11799                                IF (FND_LOG.level_unexpected >= FND_LOG.g_current_runtime_level) THEN
11800                                          FND_LOG.string(log_level => FND_LOG.level_unexpected,
11801                                                         module    => 'pon.plsql.pon_auction_pkg.notify_member 1',
11802                                                         message   => 'Multiple Users found for person_party_id:'|| p_userPartyId);
11803                                END IF;
11804                          END IF;
11805 
11806                      SELECT
11807                         USER_ID,
11808                         USER_NAME
11809                     INTO
11810                         l_user_id,
11811                         l_user_name
11812                     FROM FND_USER
11813                     WHERE PERSON_PARTY_ID = p_userPartyId
11814                     AND NVL(END_DATE, SYSDATE+1) > SYSDATE
11815                     AND ROWNUM=1;
11816 
11817                  END;
11818 
11819                  BEGIN
11820 
11821                     SELECT
11822                         USER_NAME
11823                     INTO
11824                         l_sender_user
11825                     FROM FND_USER
11826                     WHERE PERSON_PARTY_ID = p_from_id
11827                     AND NVL(END_DATE, SYSDATE+1) > SYSDATE;
11828 
11829                  EXCEPTION
11830                        WHEN TOO_MANY_ROWS THEN
11831                           IF (NVL(FND_PROFILE.VALUE('AFLOG_ENABLED'),'N') = 'Y') THEN
11832                                IF (FND_LOG.level_unexpected >= FND_LOG.g_current_runtime_level) THEN
11833                                          FND_LOG.string(log_level => FND_LOG.level_unexpected,
11834                                                         module    => 'pon.plsql.pon_auction_pkg.notify_member 2',
11835                                                         message   => 'Multiple Users found for person_party_id:'|| p_from_id);
11836                                END IF;
11837                          END IF;
11838 
11839                     SELECT
11840                         USER_NAME
11841                     INTO
11842                         l_sender_user
11843                     FROM FND_USER
11844                     WHERE PERSON_PARTY_ID = p_from_id
11845                     AND NVL(END_DATE, SYSDATE+1) > SYSDATE
11846                     AND ROWNUM=1;
11847 
11848                  END;
11849 
11850                     -- Get the language of the Recipient of the message
11851                    l_language := fnd_profile.value_specific('ICX_LANGUAGE', l_user_id, NULL, NULL);
11852                EXCEPTION
11853                     WHEN NO_DATA_FOUND THEN
11854                         l_language := 'AMERICAN';
11855                END;
11856 
11857                SELECT LANGUAGE_CODE
11858                        INTO l_lang_code
11859                FROM FND_LANGUAGES
11860                WHERE NLS_LANGUAGE = l_language;
11861 
11862                 l_recipient_name := PON_LOCALE_PKG.GET_PARTY_DISPLAY_NAME(p_userPartyId, 2 ,l_lang_code) ;
11863                 l_sender_name := PON_LOCALE_PKG.GET_PARTY_DISPLAY_NAME(p_from_id, 2 ,l_lang_code);
11864 
11865                 --
11866                 -- Subject should be retrieved from seed message
11867                 --
11868                 IF l_user_name is not null THEN
11869                         PON_PROFILE_UTIL_PKG.GET_WF_PREFERENCES(l_user_name ,x_language_code,x_territory_code);
11870                 END IF;
11871 
11872                 IF (x_language_code is not null) THEN
11873                         IF (FND_LOG.level_statement >= FND_LOG.g_current_runtime_level) THEN --{
11874                         FND_LOG.string(log_level => FND_LOG.level_statement,
11875                           module => g_module_prefix || 'EMAIL_LIST',
11876                           message  => '12. Calling SET_SESSION_LANGUAGE with x_language_code : ' || x_language_code);
11877                         END IF; --}
11878                         SET_SESSION_LANGUAGE(null, x_language_code);
11879                 END IF;
11880 
11881                 PON_OEX_TIMEZONE_PKG.CONVERT_DATE_TO_USER_TZ(p_person_party_id => p_userPartyId,
11882                                                                p_auctioneer_user_name => p_auctioneer_user_name,
11883                                                                x_date_value1  => l_auction_start_date,
11884                                                                x_date_value2  => l_auction_end_date,
11885                                                                x_date_value3  => l_preview_date,
11886                                                                x_date_value4  => l_msg_sent_date,
11887                                                                x_date_value5  => l_null_date,
11888                                                                x_timezone_disp =>l_timezone_disp);
11889 
11890 
11891                 l_progress := '020';
11892                 IF (FND_LOG.level_procedure >= FND_LOG.g_current_runtime_level) THEN
11893                               FND_LOG.string (log_level => FND_LOG.level_procedure,
11894                                            module => g_module || l_module_name,
11895                                            message  => 'Negotiation Dates are converted to destination timezone: ' || l_timezone_disp);
11896                 END IF;
11897 
11898                 l_msg_sent_subject :=  PON_AUCTION_PKG.getMessage(msg => 'PON_DISC_MESSAGE_SENT_MSG',
11899                                                                     msg_suffix => '_'|| p_msg_suffix,
11900                                                                     token1 => 'DOC_NUMBER',
11901                                                                     token1_value => p_doc_number,
11902                                                                     token2 => 'NEG_TITLE',
11903                                                                     token2_value => replaceHtmlChars(p_auction_title));
11904 
11905 
11906                 l_progress := '030';
11907                 IF (FND_LOG.level_procedure >= FND_LOG.g_current_runtime_level) THEN
11908                               FND_LOG.string (log_level => FND_LOG.level_procedure,
11909                                            module => g_module || l_module_name,
11910                                            message  => 'Disc. Message Subject: ' || l_msg_sent_subject);
11911                 END IF;
11912 
11913                 l_itemtype := 'PONAUCT';
11914                 l_itemkey := p_auction_header_id||'-'|| p_entryid||'-'||p_userPartyId;
11915 
11916                 IF (p_preview_date is not null) THEN
11917                         l_timezone_disp1 := l_timezone_disp;
11918                         l_timezone_nodisp := NULL;
11919                 ELSE
11920                         l_timezone_disp1 := NULL;
11921                         l_timezone_nodisp := PON_AUCTION_PKG.getMessage('PON_AUC_PREVIEW_DATE_NOTSPEC');
11922                 END IF;
11923 
11924                 l_progress := '040';
11925                 IF (FND_LOG.level_procedure >= FND_LOG.g_current_runtime_level) THEN
11926                               FND_LOG.string (log_level => FND_LOG.level_procedure,
11927                                            module => g_module || l_module_name,
11928                                            message  => 'Negotiation Preview Date is: ' || p_preview_date);
11929                 END IF;
11930 
11931                 l_progress := '050';
11932                 IF (FND_LOG.level_procedure >= FND_LOG.g_current_runtime_level) THEN
11933                           FND_LOG.string (log_level => FND_LOG.level_procedure,
11934                                        module => g_module || l_module_name,
11935                                        message  => 'This is a Point to Point Message');
11936                 END IF;
11937 
11938 
11939                 l_progress := '060';
11940                 IF (FND_LOG.level_procedure >= FND_LOG.g_current_runtime_level) THEN
11941                           FND_LOG.string (log_level => FND_LOG.level_procedure,
11942                                        module => g_module || l_module_name,
11943                                        message  => 'Fetched the Formatted To Name:'|| l_recipient_name ||' , '||'and From Name:'|| l_sender_name);
11944                 END IF;
11945 
11946                 IF p_notif_performer = 'BUYER' THEN
11947    	            l_wfm_htmlagent := pon_wf_utl_pkg.get_base_internal_buyer_url;
11948 	        ELSE
11949 	            l_wfm_htmlagent := pon_wf_utl_pkg.get_base_external_supplier_url;
11950 	        END IF;
11951 
11952                 l_page_url := pon_wf_utl_pkg.get_dest_page_url (p_dest_func => 'PON_VIEW_MESSAGE_DETAILS'
11953                                  ,p_notif_performer  => p_notif_performer);
11954 
11955                 --
11956                 -- Stagger Closing Note is to be shown for ONLY Supplier
11957                 -- facing notification ONLY with staggered line Negotiation
11958                 --
11959                 l_staggered_close_note := NULL;
11960                 IF (p_notif_performer IS NOT NULL AND
11961                     p_notif_performer = 'SUPPLIER' AND
11962                     p_stagger_closing_interval IS NOT NULL ) THEN
11963                          l_staggered_close_note := wf_core.newline || wf_core.newline ||
11964                                                    getMessage('PON_STAGGERED_CLOSE_NOTIF_MSG') ||
11965                                                    wf_core.newline || wf_core.newline;
11966 
11967                 END IF;
11968 
11969 
11970                 wf_engine.CreateProcess(itemtype => l_itemtype,
11971                       itemkey  => l_itemkey,
11972                       process  => 'DISC_MESSAGE_SENT');
11973 
11974                 l_progress := '070';
11975                 IF (FND_LOG.level_procedure >= FND_LOG.g_current_runtime_level) THEN
11976                           FND_LOG.string (log_level => FND_LOG.level_procedure,
11977                                        module => g_module || l_module_name,
11978                                        message  => 'Created the DISC_MESSAGE_SENT Workflow process');
11979                 END IF;
11980 
11981               SET_PREVIEW_DATE(
11982                         p_itemtype => l_itemtype,
11983                         p_itemkey   => l_itemkey,
11984                         p_preview_date  => l_preview_date,
11985                         p_publish_auction_now_flag => p_publish_auction_now_flag,
11986                         p_timezone_disp  => l_timezone_disp,
11987                         p_msg_suffix => p_msg_suffix);
11988 
11989               SET_OPEN_DATE(
11990                         p_itemtype      => l_itemtype,
11991                         p_itemkey      => l_itemkey,
11992                         p_auction_start_date  => l_auction_start_date,
11993                         p_open_auction_now_flag => p_open_auction_now_flag,
11994                         p_timezone_disp  => l_timezone_disp,
11995                         p_msg_suffix => p_msg_suffix);
11996 
11997               SET_CLOSE_DATE(
11998                         p_itemtype  =>l_itemtype,
11999                         p_itemkey    =>l_itemkey,
12000                         p_auction_end_date  => l_auction_end_date,
12001                         p_timezone_disp  => l_timezone_disp);
12002 
12003                 wf_engine.SetItemAttrText (itemtype   => l_itemtype,
12004                            itemkey    => l_itemkey,
12005                            aname      => 'DOC_NUMBER',
12006                            avalue     => p_doc_number);
12007 
12008                 wf_engine.SetItemAttrText (itemtype   => l_itemtype,
12009                                            itemkey    => l_itemkey,
12010                                            aname      => 'STAGGERED_CLOSE_NOTE',
12011                                            avalue     => l_staggered_close_note);
12012 
12013                 wf_engine.SetItemAttrText (itemtype   => l_itemtype,
12014                            itemkey    => l_itemkey,
12015                            aname      => 'AUCTION_TITLE',
12016                            avalue     => p_auction_title);
12017 
12018                 wf_engine.SetItemAttrText (itemtype   => l_itemtype,
12019                            itemkey    => l_itemkey,
12020                            aname      => 'MSG_RECIPIENT_NAME',
12021                            avalue     => l_recipient_name);
12022 
12023                 wf_engine.SetItemAttrText (itemtype   => l_itemtype,
12024                            itemkey    => l_itemkey,
12025                            aname      => 'MSG_SENDER_NAME',
12026                            avalue     => l_sender_name);
12027 
12028                 wf_engine.SetItemAttrText (itemtype   => l_itemtype,
12029                                  itemkey    => l_itemkey,
12030                                  aname      => 'VIEW_MESSAGE_URL',
12031                                  avalue     => l_page_url);
12032 
12033                 wf_engine.SetItemAttrText (itemtype   => l_itemtype,
12034                                  itemkey    => l_itemkey,
12035                                  aname      => 'MESSAGE_TYPE',
12036                                  avalue     => p_message_type);
12037 
12038                 wf_engine.SetItemAttrText (itemtype   => l_itemtype,
12039                            itemkey    => l_itemkey,
12040                            aname      => 'MSG_SENDER_COMP_NAME',
12041                            avalue     => p_fromCompanyName);
12042 
12043                 wf_engine.SetItemAttrText (itemtype   => l_itemtype,
12044                            itemkey    => l_itemkey,
12045                            aname      => 'MESSAGE_SENT_SUBJECT',
12046                            avalue     => l_msg_sent_subject);
12047 
12048                 wf_engine.SetItemAttrText (itemtype   => l_itemtype,
12049                            itemkey    => l_itemkey,
12050                            aname      => 'MESSAGE_POSTED_DATE',
12051                            avalue     => p_msg_sent_date);
12052 
12053                wf_engine.SetItemAttrText (itemtype   => l_itemtype,
12054                            itemkey    => l_itemkey,
12055                            aname      => 'MESSAGE_SUBJECT',
12056                            avalue     => p_subject);
12057 
12058                wf_engine.SetItemAttrText (itemtype   => l_itemtype,
12059                            itemkey    => l_itemkey,
12060                            aname      => 'PREPARER_TP_CONTACT_NAME',
12061                            avalue     => l_sender_user);
12062 
12063                wf_engine.SetItemAttrText (itemtype   => l_itemtype,
12064                            itemkey    => l_itemkey,
12065                            aname      => 'RECIPIENT_ROLE',
12066                            avalue     => l_user_name);
12067 
12068                 wf_engine.SetItemAttrText (itemtype   => l_itemtype,
12069                            itemkey    => l_itemkey,
12070                            aname      => 'TRADING_PARTNER_TYPE',
12071                            avalue     => p_notif_performer);
12072 
12073                 wf_engine.SetItemAttrText (itemtype   => l_itemtype,
12074                            itemkey    => l_itemkey,
12075                            aname      => 'AUCTION_ID',
12076                            avalue     => p_auction_header_id);
12077 
12078                 wf_engine.SetItemAttrNumber (itemtype   => l_itemtype,
12079                            itemkey    => l_itemkey,
12080                            aname      => 'MESSAGE_ENTRY_ID',
12081                            avalue     => p_entryid);
12082 
12083                 wf_engine.SetItemAttrNumber (itemtype   => l_itemtype,
12084                            itemkey    => l_itemkey,
12085                            aname      => 'DISCUSSION_ID',
12086                            avalue     => p_discussion_id);
12087 
12088                 wf_engine.SetItemAttrText (itemtype   => l_itemtype,
12089                            itemkey    => l_itemkey,
12090                            aname      => 'ORIGIN_USER_NAME',
12091                            avalue     => fnd_global.user_name);
12092 
12093              -- Bug 4295915: Set the  workflow owner
12094                 wf_engine.SetItemOwner(itemtype => l_itemtype,
12095                                        itemkey  => l_itemkey,
12096                                        owner    => fnd_global.user_name);
12097 
12098                 BEGIN
12099 
12100                     wf_engine.SetItemAttrText   (itemtype   => l_itemtype,
12101                                                  itemkey    => l_itemkey,
12102                                                  aname      => '#WFM_HTMLAGENT',
12103                                                  avalue     => l_wfm_htmlagent);
12104                 EXCEPTION
12105                   WHEN OTHERS THEN
12106                      null;
12107                 END;
12108 
12109                 wf_engine.StartProcess(itemtype => l_itemtype,
12110                        itemkey  => l_itemkey );
12111 
12112                 l_progress := '080';
12113 
12114 
12115                 IF (FND_LOG.level_procedure >= FND_LOG.g_current_runtime_level) THEN
12116                     FND_LOG.string (log_level => FND_LOG.level_procedure,
12117                               module => g_module || l_module_name,
12118                                message  => 'Procedure Ends ' || g_module || l_module_name
12119                               || ', l_progress = ' || l_progress);
12120                 END IF;
12121 
12122 EXCEPTION
12123       WHEN OTHERS THEN
12124            WF_CORE.CONTEXT ('PONAUCT','NOTIFY_MEMBER','Progress:'|| l_progress ||', SQL error:' || sqlcode|| ', error message:' ||substr(sqlerrm,1,512));
12125            RAISE;
12126 --}
12127 END NOTIFY_MEMBER;
12128 
12129 /*=========================================================================+
12130 --
12131 -- 12.0 Enhancement
12132 -- GET_MAPPED_IP_CATEGORY takes in a po category id as a parameter and
12133 -- returns an ip category if mapping exists else returns -2
12134 --
12135 --
12136 -- Parameter :
12137 --             p_po_category_id  IN NUMBER
12138 --
12139 +=========================================================================*/
12140 
12141 
12142 FUNCTION GET_MAPPED_IP_CATEGORY(p_po_category_id  IN NUMBER) return NUMBER AS
12143 
12144 v_ip_category_id NUMBER;
12145 
12146 BEGIN
12147 
12148   BEGIN
12149     select nvl(shopping_category_id, -2)
12150     into   v_ip_category_id
12151     from   icx_cat_purchasing_cat_map_v
12152     where  po_category_id = p_po_category_id and
12153            rownum = 1;
12154 
12155   EXCEPTION
12156 
12157     WHEN OTHERS THEN
12158 
12159       v_ip_category_id := -2;
12160 
12161   END;
12162 
12163   RETURN v_ip_category_id;
12164 
12165 END GET_MAPPED_IP_CATEGORY;
12166 
12167 /*=========================================================================+
12168 --
12169 -- 12.0 Enhancement
12170 -- GET_MAPPED_PO_CATEGORY takes in an ip category id as a parameter and
12171 -- returns a po category if mapping exists else returns -2
12172 --
12173 --
12174 -- Parameter :
12175 --             p_ip_category_id  IN NUMBER
12176 --
12177 +=========================================================================*/
12178 
12179 
12180 FUNCTION GET_MAPPED_PO_CATEGORY(p_ip_category_id  IN NUMBER) return NUMBER AS
12181 
12182 v_po_category_id NUMBER;
12183 
12184 BEGIN
12185 
12186   BEGIN
12187     select nvl(po_category_id, -2)
12188     into   v_po_category_id
12189     from   icx_cat_shopping_cat_map_v
12190     where  shopping_category_id = p_ip_category_id and
12191            rownum = 1;
12192 
12193   EXCEPTION
12194 
12195     WHEN OTHERS THEN
12196 
12197       v_po_category_id := -2;
12198 
12199   END;
12200 
12201   RETURN v_po_category_id;
12202 
12203 END GET_MAPPED_PO_CATEGORY;
12204 
12205 PROCEDURE SET_PREVIEW_DATE(
12206           p_itemtype      IN  VARCHAR2,
12207            p_itemkey      IN  VARCHAR2,
12208            p_preview_date  IN DATE,
12209           p_publish_auction_now_flag IN VARCHAR2,
12210           p_timezone_disp  IN VARCHAR2,
12211           p_msg_suffix IN VARCHAR2) IS
12212 
12213 BEGIN
12214 
12215         IF (NVL(FND_PROFILE.VALUE('AFLOG_ENABLED'),'N') = 'Y') THEN
12216              IF (FND_LOG.level_statement >= FND_LOG.g_current_runtime_level) THEN
12217                        FND_LOG.string(log_level => FND_LOG.level_statement,
12218                                       module    => 'pon.plsql.pon_auction_pkg.set_preview_date',
12219                                       message   => 'Entered the procedure with params --- ' ||
12220                                                     'p_itemtype : ' || p_itemtype||
12221                                                     ',p_itemkey : ' ||p_itemkey||
12222                                                     ',p_preview_date : '||p_preview_date||
12223                                                     ',p_publish_auction_now_flag : '||p_publish_auction_now_flag||
12224                                                     ',p_timezone_disp : '||p_timezone_disp||
12225                                                     ',p_msg_suffix : '||p_msg_suffix);
12226              END IF;
12227        END IF;
12228 
12229       IF (p_publish_auction_now_flag = 'Y') THEN --if Immediately is selected
12230 
12231         wf_engine.SetItemAttrDate (itemtype  => p_itemtype,
12232                     itemkey  => p_itemkey,
12233                     aname  => 'PREVIEW_DATE',
12234                     avalue  => null);
12235 
12236         wf_engine.SetItemAttrText (itemtype  => p_itemtype,
12237                     itemkey  => p_itemkey,
12238                     aname  => 'TP_TIME_ZONE1',
12239                     avalue  => null);
12240 
12241         wf_engine.SetItemAttrText (itemtype  => p_itemtype,
12242                        itemkey  => p_itemkey,
12243                        aname  => 'PREVIEW_DATE_NOTSPECIFIED',
12244                        avalue  => PON_AUCTION_PKG.getMessage('PON_AUC_OPEN_IMM_AFTER_PUB',p_msg_suffix));
12245 
12246       ELSIF (p_preview_date is NULL) THEN --if Not specified
12247 
12248         wf_engine.SetItemAttrDate (itemtype  => p_itemtype,
12249                     itemkey  => p_itemkey,
12250                     aname  => 'PREVIEW_DATE',
12251                     avalue  => null);
12252 
12253         wf_engine.SetItemAttrText (itemtype  => p_itemtype,
12254                         itemkey  => p_itemkey,
12255                         aname  => 'TP_TIME_ZONE1',
12256                         avalue  => null);
12257 
12258         wf_engine.SetItemAttrText (itemtype  => p_itemtype,
12259                        itemkey  => p_itemkey,
12260                        aname  => 'PREVIEW_DATE_NOTSPECIFIED',
12261                        avalue  => PON_AUCTION_PKG.getMessage('PON_AUC_PREVIEW_DATE_NOTSPEC'));
12262 
12263       ELSE
12264         wf_engine.SetItemAttrDate (itemtype  => p_itemtype,
12265                     itemkey  => p_itemkey,
12266                     aname  => 'PREVIEW_DATE',
12267                     avalue  => p_preview_date);
12268 
12269         wf_engine.SetItemAttrText (itemtype  => p_itemtype,
12270                     itemkey  => p_itemkey,
12271                     aname  => 'TP_TIME_ZONE1',
12272                     avalue  => p_timezone_disp);
12273 
12274         wf_engine.SetItemAttrText (itemtype  => p_itemtype,
12275                    itemkey  => p_itemkey,
12276                    aname  => 'PREVIEW_DATE_NOTSPECIFIED',
12277                    avalue  => null);
12278       END IF;
12279 
12280       IF (NVL(FND_PROFILE.VALUE('AFLOG_ENABLED'),'N') = 'Y') THEN
12281            IF (FND_LOG.level_statement >= FND_LOG.g_current_runtime_level) THEN
12282                      FND_LOG.string(log_level => FND_LOG.level_statement,
12283                                     module    => 'pon.plsql.pon_auction_pkg.set_preview_date',
12284                                     message   => 'Exiting the procedure');
12285            END IF;
12286      END IF;
12287 
12288 END;
12289 
12290 PROCEDURE SET_OPEN_DATE(
12291           p_itemtype      IN  VARCHAR2,
12292            p_itemkey      IN  VARCHAR2,
12293            p_auction_start_date  IN DATE,
12294           p_open_auction_now_flag IN VARCHAR2,
12295           p_timezone_disp  IN VARCHAR2,
12296           p_msg_suffix IN VARCHAR2) IS
12297 
12298 BEGIN
12299 
12300       IF (NVL(FND_PROFILE.VALUE('AFLOG_ENABLED'),'N') = 'Y') THEN
12301            IF (FND_LOG.level_statement >= FND_LOG.g_current_runtime_level) THEN
12302                      FND_LOG.string(log_level => FND_LOG.level_statement,
12303                                     module    => 'pon.plsql.pon_auction_pkg.set_open_date',
12304                                     message   => 'Entered the procedure with params --- ' ||
12305                                                   'p_itemtype : ' || p_itemtype||
12306                                                   ',p_itemkey : ' ||p_itemkey||
12307                                                   ',p_auction_start_date : '||p_auction_start_date||
12308                                                   ',p_open_auction_now_flag : '||p_open_auction_now_flag||
12309                                                   ',p_timezone_disp : '||p_timezone_disp||
12310                                                   ',p_msg_suffix : '||p_msg_suffix);
12311            END IF;
12312        END IF;
12313 
12314       IF (p_open_auction_now_flag = 'Y') THEN --if Immediately  is selected
12315 
12316         wf_engine.SetItemAttrDate (itemtype   => p_itemtype,
12317                    itemkey    => p_itemkey,
12318                    aname      => 'AUCTION_START_DATE',
12319                    avalue     => null);
12320 
12321         wf_engine.SetItemAttrText (itemtype   => p_itemtype,
12322                    itemkey    => p_itemkey,
12323                    aname      => 'TP_TIME_ZONE',
12324                    avalue     => null);
12325 
12326         wf_engine.SetItemAttrText (itemtype     => p_itemtype,
12327                    itemkey  => p_itemkey,
12328                    aname    => 'OPEN_DATE_NOT_SPECIFIED',
12329                    avalue   => PON_AUCTION_PKG.getMessage('PON_AUC_OPEN_IMM_AFTER_PUB',p_msg_suffix));
12330 
12331       ELSIF(p_auction_start_date is NULL) THEN --if not specified
12332         wf_engine.SetItemAttrDate (itemtype   => p_itemtype,
12333                    itemkey    => p_itemkey,
12334                    aname      => 'AUCTION_START_DATE',
12335                    avalue     => null);
12336 
12337         wf_engine.SetItemAttrText (itemtype   => p_itemtype,
12338                    itemkey    => p_itemkey,
12339                    aname      => 'TP_TIME_ZONE',
12340                    avalue     => null);
12341 
12342         wf_engine.SetItemAttrText (itemtype   => p_itemtype,
12343                    itemkey  => p_itemkey,
12344                    aname    => 'OPEN_DATE_NOT_SPECIFIED',
12345                    avalue   => PON_AUCTION_PKG.getMessage('PON_AUC_PREVIEW_DATE_NOTSPEC'));
12346 
12347       ELSE
12348         wf_engine.SetItemAttrDate (itemtype   => p_itemtype,
12349                    itemkey    => p_itemkey,
12350                    aname      => 'AUCTION_START_DATE',
12351                    avalue     => p_auction_start_date);
12352 
12353         wf_engine.SetItemAttrText (itemtype   => p_itemtype,
12354                    itemkey    => p_itemkey,
12355                    aname      => 'TP_TIME_ZONE',
12356                    avalue     => p_timezone_disp);
12357 
12358         wf_engine.SetItemAttrText (itemtype   => p_itemtype,
12359                    itemkey  => p_itemkey,
12360                    aname    => 'OPEN_DATE_NOT_SPECIFIED',
12361                    avalue   => null);
12362 
12363       END IF;
12364 
12365       IF (NVL(FND_PROFILE.VALUE('AFLOG_ENABLED'),'N') = 'Y') THEN
12366            IF (FND_LOG.level_statement >= FND_LOG.g_current_runtime_level) THEN
12367                      FND_LOG.string(log_level => FND_LOG.level_statement,
12368                                     module    => 'pon.plsql.pon_auction_pkg.set_open_date',
12369                                     message   => 'Exiting the procedure');
12370            END IF;
12371      END IF;
12372 
12373 END;
12374 
12375 
12376 PROCEDURE SET_CLOSE_DATE(
12377           p_itemtype      IN  VARCHAR2,
12378            p_itemkey      IN  VARCHAR2,
12379            p_auction_end_date  IN DATE,
12380           p_timezone_disp  IN VARCHAR2) IS
12381 
12382 BEGIN
12383 
12384         IF (NVL(FND_PROFILE.VALUE('AFLOG_ENABLED'),'N') = 'Y') THEN
12385              IF (FND_LOG.level_statement >= FND_LOG.g_current_runtime_level) THEN
12386                        FND_LOG.string(log_level => FND_LOG.level_statement,
12387                                       module    => 'pon.plsql.pon_auction_pkg.set_close_date',
12388                                       message   => 'Entered the procedure with params --- ' ||
12389                                                     'p_itemtype : ' || p_itemtype||
12390                                                     ',p_itemkey : ' ||p_itemkey||
12391                                                     ',p_auction_end_date : '||p_auction_end_date||
12392                                                     ',p_timezone_disp : '||p_timezone_disp);
12393              END IF;
12394        END IF;
12395 
12396 
12397        IF (p_auction_end_date is NULL) THEN --if not specified
12398           wf_engine.SetItemAttrDate (itemtype   => p_itemtype,
12399                      itemkey    => p_itemkey,
12400                      aname      => 'AUCTION_END_DATE',
12401                      avalue     => null);
12402 
12403           wf_engine.SetItemAttrText (itemtype   => p_itemtype,
12404                      itemkey    => p_itemkey,
12405                      aname      => 'TP_TIME_ZONE2',
12406                      avalue     => null);
12407 
12408           wf_engine.SetItemAttrText (itemtype   => p_itemtype,
12409                      itemkey  => p_itemkey,
12410                      aname    => 'CLOSE_DATE_NOT_SPECIFIED',
12411                      avalue   => PON_AUCTION_PKG.getMessage('PON_AUC_PREVIEW_DATE_NOTSPEC'));
12412 
12413 
12414         ELSE
12415           wf_engine.SetItemAttrDate (itemtype   => p_itemtype,
12416                      itemkey    => p_itemkey,
12417                      aname      => 'AUCTION_END_DATE',
12418                      avalue     => p_auction_end_date);
12419 
12420           wf_engine.SetItemAttrText (itemtype   => p_itemtype,
12421                      itemkey    => p_itemkey,
12422                      aname      => 'TP_TIME_ZONE2',
12423                      avalue     => p_timezone_disp);
12424 
12425           wf_engine.SetItemAttrText (itemtype     => p_itemtype,
12426                      itemkey  => p_itemkey,
12427                      aname    => 'CLOSE_DATE_NOT_SPECIFIED',
12428                      avalue   => null);
12429 
12430         END IF;
12431 
12432 
12433       IF (NVL(FND_PROFILE.VALUE('AFLOG_ENABLED'),'N') = 'Y') THEN
12434            IF (FND_LOG.level_statement >= FND_LOG.g_current_runtime_level) THEN
12435                      FND_LOG.string(log_level => FND_LOG.level_statement,
12436                                     module    => 'pon.plsql.pon_auction_pkg.set_close_date',
12437                                     message   => 'Exiting the procedure');
12438            END IF;
12439      END IF;
12440 
12441 END;
12442 
12443 --
12444 -- This procedure is added as part of bug fix for 4914024.
12445 -- Some attributes were removed from the AuctionHeadersAllVO query
12446 -- to prevent the shared memory from going higher. These attributes
12447 -- are now obtained from this PL/SQL API instead.
12448 --
12449 PROCEDURE GET_NEGOTIATION_DETAILS( p_auction_header_id            NUMBER,
12450                                    p_user_trading_partner_id      NUMBER,
12451                                    x_time_left                    OUT NOCOPY VARCHAR2,
12452                                    x_buyer_display                OUT NOCOPY VARCHAR2,
12453                                    x_carrier                      OUT NOCOPY VARCHAR2,
12454                                    x_unlocked_by_display          OUT NOCOPY VARCHAR2,
12455                                    x_unsealed_by_display          OUT NOCOPY VARCHAR2,
12456                                    x_has_active_company_bid       OUT NOCOPY VARCHAR2,
12457                                    x_is_multi_site                OUT NOCOPY VARCHAR2,
12458                                    x_all_site_bid_on              OUT NOCOPY VARCHAR2,
12459                                    x_is_paused                    OUT NOCOPY VARCHAR2,
12460                                    x_outcome_display              OUT NOCOPY VARCHAR2,
12461                                    x_advances_flag                OUT NOCOPY VARCHAR2,
12462                                    x_retainage_flag               OUT NOCOPY VARCHAR2,
12463                                    x_payment_rate_rype_enabled    OUT NOCOPY VARCHAR2
12464                                  ) IS
12465 
12466 v_org_id NUMBER;
12467 v_carrier_code PON_AUCTION_HEADERS_ALL.CARRIER_CODE%TYPE;
12468 v_sealed_unlock_tp_contact_id NUMBER;
12469 v_sealed_unseal_tp_contact_id NUMBER;
12470 v_is_paused VARCHAR2(1);
12471 v_trading_partner_contact_id NUMBER;
12472 v_staggered_closing_interval NUMBER;
12473 v_temp NUMBER;
12474 
12475 BEGIN
12476 
12477   IF (FND_LOG.level_statement >= FND_LOG.g_current_runtime_level) THEN
12478     FND_LOG.string(log_level => FND_LOG.level_statement,
12479       module    => g_module_prefix || '.get_negotiation_details',
12480       message   => 'Entered the procedure ' ||
12481                    'p_auction_header_id = ' || p_auction_header_id ||
12482                    ', p_trading_partner_contact_id = ' || p_user_trading_partner_id);
12483   END IF;
12484 
12485   SELECT
12486     org_id,
12487     carrier_code,
12488     decode(two_part_flag,'Y',decode(sealed_auction_status,'LOCKED',technical_unlock_tp_contact_id,sealed_unlock_tp_contact_id),sealed_unlock_tp_contact_id),
12489     decode(two_part_flag,'Y',decode(sealed_auction_status,'ACTIVE', sealed_unseal_tp_contact_id,technical_unseal_tp_contact_id),sealed_unseal_tp_contact_id),
12490     is_paused,
12491     staggered_closing_interval,
12492     trading_partner_contact_id
12493   INTO
12494     v_org_id,
12495     v_carrier_code,
12496     v_sealed_unlock_tp_contact_id,
12497     v_sealed_unseal_tp_contact_id,
12498     v_is_paused,
12499     v_staggered_closing_interval,
12500     v_trading_partner_contact_id
12501   FROM
12502     pon_auction_headers_all_v
12503   WHERE
12504     auction_header_id = p_auction_header_id;
12505 
12506   x_time_left            :=  TIME_REMAINING(p_auction_header_id);
12507   x_buyer_display        :=  PON_LOCALE_PKG.GET_PARTY_DISPLAY_NAME(v_trading_partner_contact_id);
12508   x_carrier              :=  PON_PRINTING_PKG.GET_CARRIER_DESCRIPTION(v_org_id,v_carrier_code);
12509   x_unlocked_by_display  :=  PON_LOCALE_PKG.GET_PARTY_DISPLAY_NAME(v_sealed_unlock_tp_contact_id);
12510   x_unsealed_by_display  :=  PON_LOCALE_PKG.GET_PARTY_DISPLAY_NAME(v_sealed_unseal_tp_contact_id);
12511 
12512   IF (FND_LOG.level_statement >= FND_LOG.g_current_runtime_level) THEN
12513     FND_LOG.string( log_level => FND_LOG.level_statement,
12514       module  =>  g_module_prefix || '.get_negotiation_details',
12515       message  => 'x_time_left = ' || x_time_left
12516                   || ', x_buyer_display = ' || x_buyer_display
12517                   || ', x_carrier = ' || x_carrier
12518                   || ', x_unlocked_by_display = ' || x_unlocked_by_display
12519                   || ', x_unsealed_by_display = ' || x_unsealed_by_display);
12520   END IF;
12521 
12522   BEGIN
12523     SELECT
12524       a.auction_header_id
12525     INTO
12526       v_temp
12527     FROM
12528       pon_auction_headers_all a,
12529       pon_bid_headers b
12530     WHERE
12531       a.auction_header_id = b.auction_header_id
12532       and a.auction_header_id =  p_auction_header_id
12533       and b.trading_partner_id = p_user_trading_partner_id
12534       and b.bid_status = 'ACTIVE'
12535       AND rownum = 1;
12536 
12537     x_has_active_company_bid := 'Y';
12538 
12539     EXCEPTION WHEN NO_DATA_FOUND THEN
12540       x_has_active_company_bid := 'N';
12541   END;
12542 
12543   BEGIN
12544     SELECT
12545       ppbp.auction_header_id
12546     INTO
12547       v_temp
12548     FROM
12549       pon_bidding_parties ppbp
12550     WHERE
12551       ppbp.auction_header_id = p_auction_header_id
12552       and ppbp.trading_partner_id = p_user_trading_partner_id
12553       AND rownum = 1;
12554 
12555     x_is_multi_site := 'Y';
12556 
12557     EXCEPTION WHEN NO_DATA_FOUND THEN
12558       x_is_multi_site := 'N';
12559   END;
12560 
12561   SELECT
12562     DECODE(
12563       (SELECT
12564          count(distinct vendor_site_id)
12565        FROM
12566          pon_bid_headers ppbh
12567        WHERE
12568          ppbh.auction_header_id = p_auction_header_id
12569          and ppbh.trading_partner_id = p_user_trading_partner_id
12570          and ppbh.bid_status = 'ACTIVE'
12571       ),
12572       (SELECT
12573          count(pbp.auction_header_id)
12574        FROM
12575          pon_bidding_parties pbp
12576        WHERE
12577          pbp.auction_header_id = p_auction_header_id
12578          and pbp.trading_partner_id = p_user_trading_partner_id
12579       ), 'Y', 'N')
12580   INTO
12581     x_all_site_bid_on
12582   FROM
12583     DUAL;
12584 
12585   SELECT
12586     DECODE( nvl(v_is_paused, 'N'), 'Y', 'Y', nvl2(v_staggered_closing_interval, 'S', 'N'))
12587   INTO
12588     x_is_paused
12589   FROM
12590     DUAL;
12591 
12592   IF (FND_LOG.level_statement >= FND_LOG.g_current_runtime_level) THEN
12593     FND_LOG.string (log_level => FND_LOG.level_statement,
12594       module  =>  g_module_prefix || '.get_negotiation_details',
12595       message  => 'x_has_active_company_bid = ' || x_has_active_company_bid
12596         || ' x_is_multi_site = ' || x_is_multi_site
12597         || ' x_all_site_bid_on = ' || x_all_site_bid_on
12598         || ' x_is_paused = ' || x_is_paused);
12599   END IF;
12600 
12601   SELECT
12602     ps.display_name,
12603     pdsh.advances_flag,
12604     pdsh.retainage_flag,
12605     nvl2(pspay.pay_item_type , 'Y','N')
12606   INTO
12607     x_outcome_display,
12608     x_advances_flag,
12609     x_retainage_flag,
12610     x_payment_rate_rype_enabled
12611   FROM
12612     po_all_doc_style_lines ps,
12613     pon_auction_headers_all_v ah,
12614     po_doc_style_headers pdsh,
12615     po_style_enabled_pay_items pspay,
12616     po_lookup_codes fl_pay_item
12617   WHERE
12618     ah.auction_header_id = p_auction_header_id
12619     AND ah.po_style_id = ps.style_id(+)
12620     AND ah.contract_type = ps.document_subtype(+)
12621     AND USERENV('LANG') = ps.language(+)
12622     AND ah.po_style_id = pdsh.style_id(+)
12623     AND ah.po_style_id = pspay.style_id(+)
12624     AND pspay.pay_item_type(+) ='RATE'
12625     AND fl_pay_item.lookup_type(+)  =  'PAYMENT TYPE'
12626     AND fl_pay_item.lookup_code(+) = pspay.pay_item_type;
12627 
12628   IF (FND_LOG.level_statement >= FND_LOG.g_current_runtime_level) THEN
12629        FND_LOG.string (log_level => FND_LOG.level_statement,
12630          module  =>  g_module_prefix || '.get_negotiation_details',
12631          message  => 'x_outcome_display = ' || x_outcome_display
12632          || ' x_advances_flag = ' || x_advances_flag
12633          || ' x_retainage_flag = ' || x_retainage_flag
12634          || ' x_payment_rate_rype_enabled = ' || x_payment_rate_rype_enabled);
12635   END IF;
12636 
12637 END GET_NEGOTIATION_DETAILS;
12638 
12639 ---------------------------------------------------------------------------------------
12640 --      R12 Rollup1 Enhancement - Countdown Clock Project (adsahay)
12641 --
12642 --      Start of comments
12643 --      API Name:               SHOW_COUNTDOWN
12644 --      Function:               Given an auction id, returns "Y" if the auction is active or paused and
12645 --                              closing within next 24 hours. Auctions that are in preview mode,
12646 --                              cancelled or amended, or closing in more than 24 hours return "N".
12647 --      Parameters:
12648 --      IN:     p_auction_header_id IN NUMBER           - Auction header id
12649 --      OUT:    x_return_status OUT NOCOPY VARCHAR2     - Return status
12650 --              x_error_code OUT NOCOPY VARCHAR2        - Error code
12651 --              x_error_message OUT NOCOPY VARCHAR2     - Error message
12652 --
12653 --      End of Comments
12654 --      Return : l_show_countdown VARCHAR2
12655 ----------------------------------------------------------------------------------------
12656 
12657 FUNCTION SHOW_COUNTDOWN(x_result OUT NOCOPY VARCHAR2,
12658                         x_error_code OUT NOCOPY VARCHAR2,
12659                         x_error_message OUT NOCOPY VARCHAR2,
12660                         p_auction_header_id IN NUMBER)
12661 RETURN VARCHAR2
12662 AS
12663 v_auction_status pon_auction_headers_all.auction_status%TYPE;  -- to store auction status
12664 v_time_remaining number;  -- to store the time remaining for auction to close
12665 l_show_countdown varchar2(1) := 'N';    -- return value, default 'N'
12666 
12667 BEGIN
12668         IF (FND_LOG.level_statement >= FND_LOG.g_current_runtime_level) THEN
12669                 FND_LOG.string (log_level => FND_LOG.level_statement,
12670                 module  =>  g_module_prefix || '.show_countdown',
12671                 message  => 'Entered show_countdown with p_auction_header_id = ' || p_auction_header_id);
12672         END IF;
12673 
12674         x_result := FND_API.G_RET_STS_SUCCESS;
12675 
12676         -- adsahay: bug 6319438 - replace sysdate with last_pause_date for paused auctions,
12677         -- since close_bidding_date can be in the past (lesser than sysdate).
12678         SELECT (close_bidding_date - decode(is_paused, 'Y', last_pause_date, sysdate)), auction_status
12679         INTO v_time_remaining, v_auction_status
12680         FROM pon_auction_headers_all
12681         WHERE auction_header_id = p_auction_header_id
12682         AND open_bidding_date < sysdate;
12683 
12684         IF (FND_LOG.level_statement >= FND_LOG.g_current_runtime_level) THEN
12685         FND_LOG.string (log_level => FND_LOG.level_statement,
12686         module  =>  g_module_prefix || '.show_countdown',
12687         message  => 'p_auction_header_id = ' || p_auction_header_id
12688           || ', v_auction_status = ' || v_auction_status
12689           || ', v_time_remaining = ' || v_time_remaining);
12690         END IF;
12691 
12692 -- v_time_remaining will be in days, 1.0 being full 24 hours.
12693 IF (v_time_remaining > 0 AND v_time_remaining <= 1.0) then
12694         IF(v_auction_status = 'CANCELLED') THEN   -- auction is cancelled
12695                 l_show_countdown := 'N';
12696         ELSIF (v_auction_status = 'AMENDED') THEN -- auction is amended
12697                 l_show_countdown := 'N';
12698         ELSE
12699                 l_show_countdown := 'Y';        -- looks good if reached here.
12700         END IF;
12701 
12702 ELSE    -- more than 24 hours left
12703         l_show_countdown := 'N';
12704 END IF;
12705 
12706 IF (FND_LOG.level_statement >= FND_LOG.g_current_runtime_level) THEN
12707         FND_LOG.string (log_level => FND_LOG.level_statement,
12708         module  =>  g_module_prefix || '.show_countdown',
12709         message  => 'Returning l_show_countdown = ' || l_show_countdown);
12710 END IF;
12711 
12712 -- return l_show_countdown
12713 RETURN l_show_countdown;
12714 
12715 EXCEPTION
12716   WHEN NO_DATA_FOUND THEN       -- auction is in preview mode, return 'N'
12717         l_show_countdown := 'N';
12718         IF (FND_LOG.level_statement >= FND_LOG.g_current_runtime_level) THEN
12719                 FND_LOG.string (log_level => FND_LOG.level_statement,
12720                 module  =>  g_module_prefix || '.show_countdown',
12721                 message  => 'Returning l_show_countdown = ' || l_show_countdown);
12722         END IF;
12723         Return l_show_countdown;
12724 
12725   WHEN OTHERS THEN
12726         x_result := FND_API.G_RET_STS_UNEXP_ERROR;
12727         x_error_code := SQLCODE;
12728         x_error_message := SUBSTR(SQLERRM, 1, 100);
12729 
12730         IF (FND_LOG.LEVEL_EXCEPTION >= FND_LOG.g_current_runtime_level) THEN
12731                 FND_LOG.string (log_level => FND_LOG.level_exception,
12732                 module  => g_module_prefix || '.show_countdown',
12733                 message => 'Exception occured in show_countdown'
12734                 || ' Error Number :' || SQLCODE || ' Exception Message :' || SUBSTR(SQLERRM, 1, 200) );
12735         END IF;
12736 
12737 END SHOW_COUNTDOWN; -- end of function definition.
12738 
12739 -----------------------------------------------------------------------------------
12740 --      R12 Rollup1 Enhancement - Countdown Clock Project (adsahay)
12741 --
12742 --      Start of comments
12743 --      API Name:       HAS_DISTINCT_CLOSING_LINES
12744 --      Function:       Given an auction id, Returns 'Y' if the auction has lines
12745 --                      closing in different times, else 'N'. This means that either the auction is
12746 --                      staggered or has "auto extend" feature enabled such that it extends one line
12747 --                      instead of all lines.
12748 --
12749 --      Parameters:
12750 --      IN:     p_auction_header_id IN NUMBER   - The auction header id
12751 --      OUT:    x_return_status OUT NOCOPY VARCHAR2     - Return status
12752 --              x_error_code OUT NOCOPY VARCHAR2        - Error code
12753 --              x_error_message OUT NOCOPY VARCHAR2     - Error message
12754 --
12755 --      End of Comments
12756 --
12757 --      Return : l_flag VARCHAR2
12758 ------------------------------------------------------------------------------------
12759 
12760 FUNCTION HAS_DISTINCT_CLOSING_DATES(x_result OUT NOCOPY VARCHAR2,
12761                                 x_error_code OUT NOCOPY VARCHAR2,
12762                                 x_error_message OUT NOCOPY VARCHAR2,
12763                                 p_auction_header_id IN NUMBER)
12764 RETURN VARCHAR2
12765 AS
12766 v_time_left number;        --gets the time left for auction to close
12767 v_is_staggered varchar2(1);     -- whether auction is staggered
12768 v_ext_all_lines varchar2(1);    -- whether auto extend all lines
12769 l_flag varchar2(1) := 'N';      -- Return value defaulted to 'N'
12770 BEGIN
12771 
12772         IF (FND_LOG.level_statement >= FND_LOG.g_current_runtime_level) THEN
12773                 FND_LOG.string (log_level => FND_LOG.level_statement,
12774                 module  =>  g_module_prefix || '.has_distinct_closing_dates',
12775                 message  => 'Entered has_distinct_closing_dates with p_auction_header_id = ' || p_auction_header_id);
12776         END IF;
12777 
12778         x_result := FND_API.G_RET_STS_SUCCESS;
12779 
12780         -- adsahay: bug 6319438 - replace sysdate with last_pause_date for paused auctions,
12781         -- since close_bidding_date can be in the past (lesser than sysdate).
12782         SELECT (close_bidding_date-decode(is_paused, 'Y', last_pause_date, sysdate)), nvl2(staggered_closing_interval, 'Y', 'N'),
12783         -- if auto extend is enabled and auto extends all lines, 'N' else 'Y'
12784         decode(auto_extend_flag, 'Y', decode(auto_extend_all_lines_flag, 'N', 'Y', 'N'), 'N')
12785         INTO v_time_left, v_is_staggered, v_ext_all_lines
12786         FROM pon_auction_headers_all
12787         WHERE auction_header_id = p_auction_header_id;
12788 
12789         IF (FND_LOG.level_statement >= FND_LOG.g_current_runtime_level) THEN
12790         FND_LOG.string (log_level => FND_LOG.level_statement,
12791         module  =>  g_module_prefix || '.has_distinct_closing_dates',
12792         message  => 'p_auction_header_id = ' || p_auction_header_id
12793           || ', v_time_left = ' || v_time_left
12794           || ', v_is_staggered = ' || v_is_staggered
12795           || ', v_ext_all_lines = ' || v_ext_all_lines);
12796         END IF;
12797 
12798         -- negative time left means auction already closed
12799         IF (v_time_left < 0) THEN
12800         l_flag := 'N';
12801         -- staggered or auto extend allows different lines to close differently
12802         ELSIF (v_is_staggered = 'Y' OR v_ext_all_lines = 'Y') THEN
12803                 l_flag := 'Y';
12804         ELSE
12805                 l_flag := 'N';
12806         END IF;
12807 
12808         IF (FND_LOG.level_statement >= FND_LOG.g_current_runtime_level) THEN
12809                 FND_LOG.string (log_level => FND_LOG.level_statement,
12810                 module  =>  g_module_prefix || '.has_distinct_closing_dates',
12811                 message  => 'Returning l_flag = ' || l_flag);
12812         END IF;
12813 
12814         RETURN l_flag;
12815 
12816 EXCEPTION
12817   WHEN OTHERS THEN
12818         x_result := FND_API.G_RET_STS_UNEXP_ERROR;
12819         x_error_code := SQLCODE;
12820         x_error_message := SUBSTR(SQLERRM, 1, 100);
12821 
12822         IF (FND_LOG.LEVEL_EXCEPTION >= FND_LOG.g_current_runtime_level) THEN
12823                 FND_LOG.string (log_level => FND_LOG.level_exception,
12824                 module  => g_module_prefix || '.has_distinct_closing_dates',
12825                 message => 'Exception occured in has_distinct_closing_dates'
12826                 || ' Error Number :' || SQLCODE || ' Exception Message :' || SUBSTR(SQLERRM, 1, 200) );
12827         END IF;
12828 
12829 END HAS_DISTINCT_CLOSING_DATES; -- end of function definition
12830 
12831 -----------------------------------------------------------------------------------
12832 --      R12 Rollup1 Enhancement - Two Part RFQ Project (adsahay)
12833 --
12834 --      Start of comments
12835 --      API Name:       GET_TECHNICAL_MEANING
12836 --      Function:       Returns meaning of 'TECHNICAL' from lookups.
12837 --
12838 --      Parameters:
12839 --      IN:
12840 --      OUT:
12841 --
12842 --      End of Comments
12843 --
12844 --      Return : g_technical_meaning VARCHAR2
12845 ------------------------------------------------------------------------------------
12846 FUNCTION get_technical_meaning
12847 RETURN VARCHAR2 AS
12848 BEGIN
12849         -- adsahay: bug 6374353 - caching should take care of language too.
12850         -- if cache is empty first populate the cache
12851         IF (g_two_part_cache.COUNT = 0) then -- {
12852           init_two_part_cache;
12853         END IF; -- }
12854 
12855         -- update g_tp_cache_rec from the cache
12856         update_cache_rec;
12857 
12858         IF (FND_LOG.level_statement >= FND_LOG.g_current_runtime_level) THEN
12859                 FND_LOG.string (log_level => FND_LOG.level_statement,
12860                 module  =>  g_module_prefix || '.get_technical_meaning',
12861                 message  => 'Returning technical_meaning = ' || g_tp_cache_rec.technical_meaning);
12862         END IF;
12863 
12864         -- return technical_meaning
12865         return g_tp_cache_rec.technical_meaning;
12866 EXCEPTION
12867   WHEN OTHERS THEN
12868         IF (FND_LOG.LEVEL_EXCEPTION >= FND_LOG.g_current_runtime_level) THEN
12869                 FND_LOG.string (log_level => FND_LOG.level_exception,
12870                 module  => g_module_prefix || '.get_technical_meaning',
12871                 message => 'Exception occured in get_technical_meaning'
12872                 || ' Error Number :' || SQLCODE || ' Exception Message :' || SUBSTR(SQLERRM, 1, 200) );
12873         END IF;
12874 
12875 END get_technical_meaning;
12876 
12877 -----------------------------------------------------------------------------------
12878 --      R12 Rollup1 Enhancement - Two Part RFQ Project (adsahay)
12879 --
12880 --      Start of comments
12881 --      API Name:       GET_COMMERCIAL_MEANING
12882 --      Function:       Returns meaning of 'COMMERCIAL' from lookups.
12883 --
12884 --      Parameters:
12885 --      IN:
12886 --      OUT:
12887 --
12888 --      End of Comments
12889 --
12890 --      Return : g_commercial_meaning VARCHAR2
12891 ------------------------------------------------------------------------------------
12892 FUNCTION get_commercial_meaning
12893 RETURN VARCHAR2 AS
12894 BEGIN
12895         -- adsahay: bug 6374353 - caching should take care of language too.
12896         -- if cache is empty first populate the cache
12897         IF (g_two_part_cache.COUNT = 0) then -- {
12898           init_two_part_cache;
12899         END IF; -- }
12900 
12901         -- update g_tp_cache_rec from the cache
12902         update_cache_rec;
12903 
12904         IF (FND_LOG.level_statement >= FND_LOG.g_current_runtime_level) THEN
12905                 FND_LOG.string (log_level => FND_LOG.level_statement,
12906                 module  =>  g_module_prefix || '.get_commercial_meaning',
12907                 message  => 'Returning commercial_meaning = ' || g_tp_cache_rec.commercial_meaning);
12908         END IF;
12909 
12910         -- return commercial_meaning
12911         return g_tp_cache_rec.commercial_meaning;
12912 EXCEPTION
12913   WHEN OTHERS THEN
12914         IF (FND_LOG.LEVEL_EXCEPTION >= FND_LOG.g_current_runtime_level) THEN
12915                 FND_LOG.string (log_level => FND_LOG.level_exception,
12916                 module  => g_module_prefix || '.get_commercial_meaning',
12917                 message => 'Exception occured in get_commercial_meaning'
12918                 || ' Error Number :' || SQLCODE || ' Exception Message :' || SUBSTR(SQLERRM, 1, 200) );
12919         END IF;
12920 
12921 END get_commercial_meaning;
12922 
12923 -----------------------------------------------------------------------------------
12924 --      R12 Rollup1 Enhancement - Two Part RFQ Project (adsahay)
12925 --
12926 --      Start of comments
12927 --      API Name:       NOTIFY_BIDDERS_TECH_COMPLETE
12928 --      Procedure:      Notify bidders that their bids have/have not been short listed
12929 --      in technical evaluation.
12930 --
12931 --      Parameters:
12932 --      IN:        p_auction_header_id IN NUMBER - The auction header id.
12933 --      OUT:       x_return_status OUT NOCOPY VARCHAR2     - Return status
12934 --        This is a flag to indicate if the procedure
12935 --                              was successful or not; It can have
12936 --                              following values -
12937 --                                              FND_API.G_RET_STS_SUCCESS (Success)
12938 --                                              FND_API.G_RET_STS_ERROR  (Success with warning)
12939 --                                              FND_API.G_RET_STS_UNEXP_ERROR (Failed due to error)
12940 --
12941 --                x_error_code OUT NOCOPY VARCHAR2        - Error code
12942 --                x_error_message OUT NOCOPY VARCHAR2     - Error message
12943 --
12944 --      End of Comments
12945 ------------------------------------------------------------------------------------
12946 PROCEDURE NOTIFY_BIDDERS_TECH_COMPLETE(x_return_status OUT NOCOPY VARCHAR2,
12947           x_error_code OUT NOCOPY VARCHAR2 ,
12948           x_error_message OUT NOCOPY VARCHAR2,
12949           p_auction_header_id IN NUMBER)
12950 AS
12951   -- get list of bidders, along with the shortlist flags.
12952   CURSOR bidder_list IS
12953     SELECT bid_number, trading_partner_contact_name, nvl(shortlist_flag, 'Y') as shortlist_flag
12954     FROM pon_bid_headers
12955     WHERE   auction_header_id = p_auction_header_id
12956       AND bid_status = 'ACTIVE';
12957 
12958   -- other local variables
12959   x_item_key VARCHAR2(15);  -- workflow item key
12960   x_item_type VARCHAR2(8) := 'PONTEVAL';  -- workflow item type
12961   l_bidder_name pon_bid_headers.trading_partner_contact_name%TYPE;
12962   l_auction_title pon_auction_headers_all.auction_title%TYPE;
12963   l_document_number pon_auction_headers_all.document_number%TYPE;
12964   l_trading_partner_name pon_auction_headers_all.trading_partner_name%TYPE;
12965 
12966 BEGIN
12967         IF (FND_LOG.level_statement >= FND_LOG.g_current_runtime_level) THEN
12968                 FND_LOG.string (log_level => FND_LOG.level_statement,
12969                 module  =>  g_module_prefix || '.notify_bidders_tech_complete',
12970                 message  => 'Entered notify_bidders_tech_complete with p_auction_header_id = ' || p_auction_header_id);
12971         END IF;
12972 
12973         x_return_status := FND_API.G_RET_STS_SUCCESS;
12974 
12975   BEGIN
12976     -- get auction information
12977     SELECT   auction_title, document_number, trading_partner_name
12978     INTO  l_auction_title, l_document_number, l_trading_partner_name
12979     FROM  pon_auction_headers_all
12980     WHERE  auction_header_id = p_auction_header_id;
12981   EXCEPTION
12982     WHEN NO_DATA_FOUND THEN
12983       x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
12984       x_error_code := SQLCODE;
12985       x_error_message := SUBSTR(SQLERRM, 1, 100);
12986 
12987       IF (FND_LOG.LEVEL_EXCEPTION >= FND_LOG.g_current_runtime_level) THEN
12988         FND_LOG.string (log_level => FND_LOG.level_exception,
12989         module  => g_module_prefix || '.notify_bidders_tech_complete',
12990         message => 'NO_DATA_FOUND in pon_auction_headers_all for p_auction_header_id :'
12991         || p_auction_header_id || ' Error Number :' || SQLCODE || ' Exception Message :' || SUBSTR(SQLERRM, 1, 200) );
12992       END IF;
12993 
12994     WHEN TOO_MANY_ROWS THEN
12995       x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
12996       x_error_code := SQLCODE;
12997       x_error_message := SUBSTR(SQLERRM, 1, 100);
12998 
12999       IF (FND_LOG.LEVEL_EXCEPTION >= FND_LOG.g_current_runtime_level) THEN
13000         FND_LOG.string (log_level => FND_LOG.level_exception,
13001         module  => g_module_prefix || '.notify_bidders_tech_complete',
13002         message => 'TOO_MANY_ROWS in pon_auction_headers_all for p_auction_header_id :'
13003         || p_auction_header_id || ' Error Number :' || SQLCODE || ' Exception Message :' || SUBSTR(SQLERRM, 1, 200) );
13004       END IF;
13005 
13006       WHEN OTHERS THEN
13007       x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
13008       x_error_code := SQLCODE;
13009       x_error_message := SUBSTR(SQLERRM, 1, 100);
13010 
13011       IF (FND_LOG.LEVEL_EXCEPTION >= FND_LOG.g_current_runtime_level) THEN
13012         FND_LOG.string (log_level => FND_LOG.level_exception,
13013         module  => g_module_prefix || '.notify_bidders_tech_complete',
13014         message => 'Exception occured in notify_bidders_tech_complete'
13015         || ' Error Number :' || SQLCODE || ' Exception Message :' || SUBSTR(SQLERRM, 1, 200) );
13016       END IF;
13017   END;
13018 
13019   -- for every bidder,
13020   FOR bidder IN bidder_list LOOP
13021 
13022     -- get unique item key by a combination of sequence and bid number.
13023     SELECT   pon_auction_wf_dqbid_s.nextval
13024     INTO   x_item_key
13025     FROM   dual;
13026     x_item_key := bidder.bid_number || '-' || x_item_key;
13027 
13028     -- bidder name: this is the person who gets the notification
13029     l_bidder_name := bidder.trading_partner_contact_name;
13030 
13031     -- create workflow process
13032     wf_engine.CreateProcess(itemtype => x_item_type,
13033               itemkey => x_item_key,
13034           process => 'PON_TECH_SHORTLIST_NOTIFY');
13035 
13036     IF (FND_LOG.level_statement >= FND_LOG.g_current_runtime_level) THEN
13037       FND_LOG.string (log_level => FND_LOG.level_statement,
13038       module  =>  g_module_prefix || '.notify_bidders_tech_complete',
13039       message  => 'Created workflow process with itemtype = ' || x_item_type || ' and itemkey = '
13040           || x_item_key);
13041     END IF;
13042 
13043     -- bidder trading party contact name
13044     wf_engine.SetItemAttrText(  itemtype => x_item_type,
13045                   itemkey => x_item_key,
13046                   aname => 'BIDDER_TP_CONTACT_NAME',
13047                   avalue => l_bidder_name);
13048 
13049         -- auctioneer trading party name
13050     wf_engine.SetItemAttrText(  itemtype => x_item_type,
13051                   itemkey => x_item_key,
13052                   aname => 'PREPARER_TP_NAME',
13053                   avalue => l_trading_partner_name);
13054 
13055         -- auction header id
13056     wf_engine.SetItemAttrText(  itemtype => x_item_type,
13057                   itemkey => x_item_key,
13058                   aname => 'AUCTION_ID',
13059                   avalue => p_auction_header_id);
13060 
13061         -- bid id
13062     wf_engine.SetItemAttrText(  itemtype => x_item_type,
13063                   itemkey => x_item_key,
13064                   aname => 'BID_ID',
13065                   avalue => bidder.bid_number);
13066 
13067         -- auction title
13068     wf_engine.SetItemAttrText(  itemtype => x_item_type,
13069                   itemkey => x_item_key,
13070                   aname => 'AUCTION_TITLE',
13071                   avalue => l_auction_title);
13072 
13073         -- bid technically shortlisted flag
13074     wf_engine.SetItemAttrText(  itemtype => x_item_type,
13075                   itemkey => x_item_key,
13076                   aname => 'BID_TECH_SHORTLISTED',
13077                   avalue => bidder.shortlist_flag);
13078 
13079         -- document number (display value)
13080     wf_engine.SetItemAttrText(  itemtype => x_item_type,
13081                   itemkey => x_item_key,
13082                   aname => 'DOC_NUMBER',
13083                   avalue => l_document_number);
13084 
13085         -- meaning of Technical
13086     wf_engine.SetItemAttrText(  itemtype => x_item_type,
13087                   itemkey => x_item_key,
13088                   aname => 'TECHNICAL',
13089                   avalue => get_technical_meaning);
13090 
13091         -- meaning of Commercial
13092     wf_engine.SetItemAttrText(  itemtype => x_item_type,
13093                   itemkey => x_item_key,
13094                   aname => 'COMMERCIAL',
13095                   avalue => get_commercial_meaning);
13096 
13097         -- origin user name
13098     wf_engine.SetItemAttrText(  itemtype => x_item_type,
13099                   itemkey => x_item_key,
13100                   aname => 'ORIGIN_USER_NAME',
13101                   avalue => fnd_global.user_name);
13102 
13103     IF (FND_LOG.level_statement >= FND_LOG.g_current_runtime_level) THEN
13104       FND_LOG.string (log_level => FND_LOG.level_statement,
13105       module  =>  g_module_prefix || '.notify_bidders_tech_complete',
13106       message  =>    ' Passed these attributes -- BIDDER_TP_CONTACT_NAME :' || l_bidder_name  ||
13107           ' PREPARER_TP_NAME :' || l_trading_partner_name || ' AUCTION_ID :' || p_auction_header_id ||
13108           ' BID_ID :' || bidder.bid_number || ' AUCTION_TITLE :' || l_auction_title ||
13109           ' BID_TECH_SHORTLISTED :' || bidder.shortlist_flag || ' DOC_NUMBER :' || l_document_number ||
13110           ' TECHNICAL :' || get_technical_meaning || ' COMMERCIAL :' || get_commercial_meaning);
13111     END IF;
13112 
13113     -- start the workflow
13114     wf_engine.StartProcess(  itemtype => x_item_type,
13115              itemkey => x_item_key);
13116 
13117     IF (FND_LOG.level_statement >= FND_LOG.g_current_runtime_level) THEN
13118       FND_LOG.string (log_level => FND_LOG.level_statement,
13119       module  =>  g_module_prefix || '.notify_bidders_tech_complete',
13120       message  =>  ' Workflow process started');
13121     END IF;
13122 
13123     END LOOP;
13124 
13125 EXCEPTION
13126   WHEN OTHERS THEN
13127         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
13128         x_error_code := SQLCODE;
13129         x_error_message := SUBSTR(SQLERRM, 1, 100);
13130 
13131         IF (FND_LOG.LEVEL_EXCEPTION >= FND_LOG.g_current_runtime_level) THEN
13132                 FND_LOG.string (log_level => FND_LOG.level_exception,
13133                 module  => g_module_prefix || '.notify_bidders_tech_complete',
13134                 message => 'Exception occured in notify_bidders_tech_complete'
13135                 || ' Error Number :' || SQLCODE || ' Exception Message :' || SUBSTR(SQLERRM, 1, 200) );
13136         END IF;
13137 
13138 END notify_bidders_tech_complete;
13139 
13140 FUNCTION GET_AUCTION_STATUS_DISPLAY(
13141 p_auction_header_id IN pon_auction_headers_all.AUCTION_HEADER_ID%TYPE,
13142 p_user_trading_partner_id IN pon_auction_headers_all.TRADING_PARTNER_ID%TYPE)
13143 RETURN VARCHAR2
13144 AS
13145 
13146 l_is_buyer BOOLEAN;
13147 l_two_part_flag pon_auction_headers_all.TWO_PART_FLAG%type;
13148 l_technical_lock_status pon_auction_headers_all.TECHNICAL_LOCK_STATUS%type;
13149 l_technical_evaluation_status pon_auction_headers_all.TECHNICAL_EVALUATION_STATUS%type;
13150 l_message VARCHAR2(100);
13151 l_commercial_lock_status pon_auction_headers_all.sealed_auction_status%type;
13152 l_auction_status pon_auction_headers_all.auction_status%type;
13153 l_auction_status2 pon_auction_headers_all.auction_status%type;
13154 l_award_status pon_auction_headers_all.award_status%type;
13155 
13156 l_auction_trading_partner_id pon_auction_headers_all.trading_partner_id%type;
13157 l_technical_lock_meaning VARCHAR2(30);
13158 l_commercial_lock_meaning VARCHAR2(30);
13159 
13160 BEGIN
13161 
13162     IF (FND_LOG.level_statement>= FND_LOG.g_current_runtime_level) THEN
13163       FND_LOG.string(log_level => FND_LOG.level_statement,
13164         module  =>  g_module_prefix || 'GET_AUCTION_STATUS_DISPLAY',
13165         message  => 'Entering the function with params -- p_auction_header_id = ' || p_auction_header_id
13166                     || ' p_user_trading_partner_id = ' || p_user_trading_partner_id
13167             );
13168     END IF;
13169 
13170     l_message := 'NO MESSAGE FORMED YET FOR THIS AUCTION';
13171 
13172    SELECT nvl(two_part_flag,'N'),
13173           nvl(technical_lock_status,''),
13174           nvl(technical_evaluation_status,''),
13175           nvl(sealed_auction_status, ''),
13176           decode(nvl(is_paused, 'N'), 'Y', 'NOTCLOSED',
13177               decode(SIGN(close_bidding_date - sysdate) , -1, 'CLOSED', 'NOTCLOSED')), --auction status
13178           trading_partner_id,
13179           auction_status,
13180           award_status
13181    INTO
13182           l_two_part_flag,
13183           l_technical_lock_status,
13184           l_technical_evaluation_status,
13185           l_commercial_lock_status,
13186           l_auction_status,
13187           l_auction_trading_partner_id,
13188           l_auction_status2,
13189           l_award_status
13190     FROM pon_auction_headers_all
13191     WHERE auction_header_id = p_auction_header_id;
13192 
13193     IF (FND_LOG.level_statement>= FND_LOG.g_current_runtime_level) THEN
13194       FND_LOG.string(log_level => FND_LOG.level_statement,
13195         module  =>  g_module_prefix || 'GET_AUCTION_STATUS_DISPLAY',
13196         message  => 'l_two_part_flag = ' || l_two_part_flag
13197                     || ' l_technical_lock_status = ' || l_technical_lock_status
13198                     || ' l_technical_evaluation_status = ' || l_technical_evaluation_status
13199                     || ' l_commercial_lock_status = ' || l_commercial_lock_status
13200                     || ' l_auction_status = ' || l_auction_status
13201                     || ' l_auction_trading_partner_id = ' || l_auction_trading_partner_id
13202                     || ' l_auction_status2 = ' || l_auction_status2
13203                     || ' l_award_status = ' || l_award_status
13204             );
13205     END IF;
13206 
13207     -- buyer or supplier?
13208     if p_user_trading_partner_id = l_auction_trading_partner_id then
13209       l_is_buyer := true;
13210     else l_is_buyer := false;
13211     end if;
13212 
13213     -- if it is not a two part flag,
13214     IF l_two_part_flag <> 'Y'
13215         -- or two-part rfq with technical status locked
13216         OR l_technical_lock_status = 'LOCKED'
13217         -- or two-part for supplier with commercial part not locked
13218         OR (not l_is_buyer and l_commercial_lock_status <> 'LOCKED')
13219         -- or it is not closed yet
13220         OR l_auction_status <> 'CLOSED'
13221         -- or the award scenario is saved i.e award process has started
13222         -- or the award status is Completed
13223         -- or the award status is Qualified
13224         -- Note: though we need not check for the QUALIFIED because it's used only
13225         -- for RFIs, I add it here for readability
13226         OR l_award_status in ('AWARDED', 'PARTIAL', 'COMPLETED', 'QUALIFIED')
13227         -- or if the RFQ is cancelled
13228         OR (l_auction_status2 in ('CANCELLED') and l_commercial_lock_status in ('ACTIVE','UNLOCKED') )
13229 
13230     THEN --{
13231       -- comes here when we should show the status old style.
13232       -- check if it is buyer
13233       IF (FND_LOG.level_statement>= FND_LOG.g_current_runtime_level) THEN
13234         FND_LOG.string(log_level => FND_LOG.level_statement,
13235           module  =>  g_module_prefix || 'GET_AUCTION_STATUS_DISPLAY',
13236           message  => 'Old style status has to be shown for this auction'
13237               );
13238       END IF;
13239 
13240       IF (l_is_buyer) THEN
13241 
13242           IF (FND_LOG.level_statement>= FND_LOG.g_current_runtime_level) THEN
13243             FND_LOG.string(log_level => FND_LOG.level_statement,
13244               module  =>  g_module_prefix || 'GET_AUCTION_STATUS_DISPLAY',
13245               message  => '1. Buyer Status'
13246                   );
13247           END IF;
13248 
13249         DECLARE
13250           l_buyer_meaning fnd_lookups.meaning%type;
13251           l_buyer_sealed_meaning fnd_lookups.meaning%type;
13252 
13253         BEGIN
13254           SELECT fl.meaning,
13255                  nvl2(pav.sealed_auction_status,
13256                       ' (' ||
13257                               (select meaning
13258                               from fnd_lookups
13259                               where lookup_type = 'PON_SEALED_AUCTION_STATUS'
13260                               and (
13261                                   (nvl(pav.two_part_flag, 'N') <> 'Y' and lookup_code = pav.sealed_auction_status)
13262                                   or lookup_code = pav.technical_lock_status))
13263                        ||')', '')
13264           INTO l_buyer_meaning, l_buyer_sealed_meaning
13265           FROM fnd_lookups fl, pon_auction_headers_all_v pav
13266           WHERE pav.auction_header_id = p_auction_header_id
13267             AND fl.lookup_type = 'PON_AUCTION_STATUS'
13268             AND fl.lookup_code = pav.negotiation_status;
13269 
13270           IF (FND_LOG.level_statement>= FND_LOG.g_current_runtime_level) THEN
13271             FND_LOG.string(log_level => FND_LOG.level_statement,
13272               module  =>  g_module_prefix || 'GET_AUCTION_STATUS_DISPLAY',
13273               message  => 'l_buyer_meaning : ' || l_buyer_meaning
13274                           || '; l_buyer_sealed_meaning = ' || l_buyer_sealed_meaning
13275                   );
13276           END IF;
13277           -- set up message
13278           l_message := l_buyer_meaning || l_buyer_sealed_meaning;
13279 
13280           IF (FND_LOG.level_statement>= FND_LOG.g_current_runtime_level) THEN
13281             FND_LOG.string(log_level => FND_LOG.level_statement,
13282               module  =>  g_module_prefix || 'GET_AUCTION_STATUS_DISPLAY',
13283               message  => 'l_message : ' || l_message
13284                   );
13285           END IF;
13286 
13287         END;
13288 
13289       -- not a buyer, generate message for supplier
13290       ELSE
13291 
13292           IF (FND_LOG.level_statement>= FND_LOG.g_current_runtime_level) THEN
13293             FND_LOG.string(log_level => FND_LOG.level_statement,
13294               module  =>  g_module_prefix || 'GET_AUCTION_STATUS_DISPLAY',
13295               message  => '3. Supplier Status'
13296                   );
13297           END IF;
13298 
13299         DECLARE
13300           l_supp_meaning fnd_lookups.meaning%type;
13301           l_supp_sealed_meaning fnd_lookups.meaning%type;
13302 
13303         BEGIN
13304           SELECT fl.meaning, nvl2(pav.sealed_auction_status,
13305                               ' (' || (select meaning
13306                               from fnd_lookups
13307                               where lookup_type = 'PON_SEALED_AUCTION_STATUS'
13308                               and (
13309                                   (nvl(pav.two_part_flag, 'N') <> 'Y' and lookup_code = pav.sealed_auction_status)
13310                                   or lookup_code = decode(pav.sealed_auction_status, 'UNLOCKED', pav.sealed_auction_status,pav.technical_lock_status)) )
13311                               ||')', '')
13312           INTO l_supp_meaning, l_supp_sealed_meaning
13313           FROM fnd_lookups fl, pon_auction_headers_all_v pav
13314           WHERE pav.auction_header_id = p_auction_header_id
13315             AND fl.lookup_type = 'PON_AUCTION_STATUS'
13316             AND fl.lookup_code = pav.suppl_negotiation_status;
13317 
13318           IF (FND_LOG.level_statement>= FND_LOG.g_current_runtime_level) THEN
13319             FND_LOG.string(log_level => FND_LOG.level_statement,
13320               module  =>  g_module_prefix || 'GET_AUCTION_STATUS_DISPLAY',
13321               message  => 'l_supp_meaning : ' || l_supp_meaning
13322                           || '; l_supp_sealed_meaning : ' || l_supp_sealed_meaning
13323                   );
13324           END IF;
13325 
13326           -- set up message
13327           l_message := l_supp_meaning || l_supp_sealed_meaning;
13328 
13329           IF (FND_LOG.level_statement>= FND_LOG.g_current_runtime_level) THEN
13330             FND_LOG.string(log_level => FND_LOG.level_statement,
13331               module  =>  g_module_prefix || 'GET_AUCTION_STATUS_DISPLAY',
13332               message  => '4. l_message : ' || l_message
13333                   );
13334           END IF;
13335 
13336         END;
13337 
13338       END IF;
13339     --}
13340     ELSE  -- it is a two part RFQ, conditions for new-style messages are met
13341     --{
13342 
13343       IF (FND_LOG.level_statement>= FND_LOG.g_current_runtime_level) THEN
13344         FND_LOG.string(log_level => FND_LOG.level_statement,
13345           module  =>  g_module_prefix || 'GET_AUCTION_STATUS_DISPLAY',
13346           message  => '5. This is a Two Part RFQ'
13347               );
13348       END IF;
13349 
13350 
13351       -- get the meanings of the technical and commercial locks for use later
13352       SELECT  (SELECT meaning from fnd_lookups
13353        WHERE lookup_type = 'PON_SEALED_AUCTION_STATUS' and
13354         lookup_code = nvl(technical_lock_status,'')), --technical status
13355        (SELECT meaning from fnd_lookups
13356        WHERE lookup_type = 'PON_SEALED_AUCTION_STATUS' and
13357        lookup_code = nvl(sealed_auction_status,'')) --commercial status
13358       INTO l_technical_lock_meaning, l_commercial_lock_meaning
13359       FROM pon_auction_headers_all
13360       WHERE auction_header_id = p_auction_header_id;
13361 
13362       IF (FND_LOG.level_statement>= FND_LOG.g_current_runtime_level) THEN
13363         FND_LOG.string(log_level => FND_LOG.level_statement,
13364           module  =>  g_module_prefix || 'GET_AUCTION_STATUS_DISPLAY',
13365           message  => 'l_technical_lock_meaning : ' || l_technical_lock_meaning
13366                       || ';l_commercial_lock_meaning : ' || l_commercial_lock_meaning
13367               );
13368       END IF;
13369 
13370       -- Bug 6445077 : If the RFQ is cancelled after technically
13371       --unlocking or unsealing it, then the status has to be Cancelled (Technical Unlocked)
13372       --or Cancelled (Technical Unsealed)
13373       IF (l_auction_status2 in ('CANCELLED') ) THEN
13374 
13375         fnd_message.set_name('PON', 'PON_TWO_PART_CANCELLED');
13376 
13377         IF (FND_LOG.level_statement>= FND_LOG.g_current_runtime_level) THEN
13378             FND_LOG.string(log_level => FND_LOG.level_statement,
13379               module  =>  g_module_prefix || 'GET_AUCTION_STATUS_DISPLAY',
13380               message  => 'The auction is cancelled after technically unlocking/unsealing it');
13381         END IF;
13382 
13383         fnd_message.set_token('LOCK_STATUS', l_technical_lock_meaning);
13384         fnd_message.set_token('ROUND',get_technical_meaning);
13385 
13386         l_message := fnd_message.get;
13387 
13388       ELSE
13389 
13390               -- check if it is buyer
13391               if (l_is_buyer) then
13392 
13393                 IF (FND_LOG.level_statement>= FND_LOG.g_current_runtime_level) THEN
13394                   FND_LOG.string(log_level => FND_LOG.level_statement,
13395                     module  =>  g_module_prefix || 'GET_AUCTION_STATUS_DISPLAY',
13396                     message  => '6. Buyer Status '
13397                         );
13398                 END IF;
13399 
13400 
13401                 -- if auction_status is AUCTION_CLOSED and AWARD_STATUS is NO
13402                 -- it means round is completed
13403                 -- show Round Completed (Unlocked/Unsealed: Technical)
13404                 if l_auction_status2 = 'AUCTION_CLOSED' and l_award_status = 'NO' then
13405 
13406                   IF (FND_LOG.level_statement>= FND_LOG.g_current_runtime_level) THEN
13407                     FND_LOG.string(log_level => FND_LOG.level_statement,
13408                       module  =>  g_module_prefix || 'GET_AUCTION_STATUS_DISPLAY',
13409                       message  => 'l_auction_status2 :  '|| l_auction_status2
13410                                   ||'l_award_status :  '|| l_award_status
13411                                   ||'That is Round is complete. So showing Round Completed (Unlocked/Unsealed: Technical)'
13412                                   ||'; l_commercial_lock_status : ' || l_commercial_lock_status
13413                           );
13414                   END IF;
13415 
13416                   if l_commercial_lock_status = 'LOCKED' then
13417 
13418                     IF (FND_LOG.level_statement>= FND_LOG.g_current_runtime_level) THEN
13419                       FND_LOG.string(log_level => FND_LOG.level_statement,
13420                         module  =>  g_module_prefix || 'GET_AUCTION_STATUS_DISPLAY',
13421                         message  => 'Auction has a commercial lock on it'
13422                             );
13423                     END IF;
13424 
13425                     fnd_message.set_name('PON', 'PON_TWO_PART_ROUNDCOMP');
13426                     fnd_message.set_token('SEALED_STATUS', l_technical_lock_meaning);
13427                     fnd_message.set_token('ROUND',get_technical_meaning);
13428                     l_message := fnd_message.get;
13429 
13430                     IF (FND_LOG.level_statement>= FND_LOG.g_current_runtime_level) THEN
13431                       FND_LOG.string(log_level => FND_LOG.level_statement,
13432                         module  =>  g_module_prefix || 'GET_AUCTION_STATUS_DISPLAY',
13433                         message  => '7. l_message : '|| l_message
13434                             );
13435                     END IF;
13436 
13437                   else
13438                        fnd_message.set_name('PON', 'PON_AUC_ROUNDCOMP');
13439                       l_message := fnd_message.get || ' (' || l_commercial_lock_meaning || ')';
13440 
13441                       IF (FND_LOG.level_statement>= FND_LOG.g_current_runtime_level) THEN
13442                         FND_LOG.string(log_level => FND_LOG.level_statement,
13443                           module  =>  g_module_prefix || 'GET_AUCTION_STATUS_DISPLAY',
13444                           message  => '8. l_message : '|| l_message
13445                               );
13446                       END IF;
13447 
13448                   end if;
13449                       -- if technical evaluation is complete,
13450                       elsif l_technical_evaluation_status = 'COMPLETED' and l_commercial_lock_status = 'LOCKED' then
13451 
13452                         IF (FND_LOG.level_statement>= FND_LOG.g_current_runtime_level) THEN
13453                           FND_LOG.string(log_level => FND_LOG.level_statement,
13454                             module  =>  g_module_prefix || 'GET_AUCTION_STATUS_DISPLAY',
13455                             message  => 'Technical evaluation is completed and the commercial lock is still on'
13456                                 );
13457                         END IF;
13458 
13459                         -- show Evaluation Complete: Technical
13460                         fnd_message.set_name('PON', 'PON_EVALUATION_COMPLETE');
13461                         --fnd_message.set_token('EVALUATION_COMPLETE', eval_complete_meaning);
13462                         fnd_message.set_token('ROUND',get_technical_meaning);
13463                         l_message := fnd_message.get;
13464 
13465                         IF (FND_LOG.level_statement>= FND_LOG.g_current_runtime_level) THEN
13466                           FND_LOG.string(log_level => FND_LOG.level_statement,
13467                             module  =>  g_module_prefix || 'GET_AUCTION_STATUS_DISPLAY',
13468                             message  => '9. l_message : ' ||l_message
13469                                 );
13470                         END IF;
13471 
13472 
13473                       -- technical evaluation is in progress, check commercial seal status
13474                       elsif l_commercial_lock_status = 'LOCKED' then
13475 
13476                         IF (FND_LOG.level_statement>= FND_LOG.g_current_runtime_level) THEN
13477                           FND_LOG.string(log_level => FND_LOG.level_statement,
13478                             module  =>  g_module_prefix || 'GET_AUCTION_STATUS_DISPLAY',
13479                             message  => 'Technical evaluation is in progress  and the commercial lock is still on'
13480                                 );
13481                         END IF;
13482 
13483                         if l_technical_lock_status = 'ACTIVE' then
13484 
13485                           IF (FND_LOG.level_statement>= FND_LOG.g_current_runtime_level) THEN
13486                             FND_LOG.string(log_level => FND_LOG.level_statement,
13487                               module  =>  g_module_prefix || 'GET_AUCTION_STATUS_DISPLAY',
13488                               message  => 'Technical lock status is ACTIVE'
13489                                   );
13490                           END IF;
13491 
13492                           -- show Evaluation in Progress: Technical (Unsealed)
13493                           fnd_message.set_name('PON','PON_EVALUATION_IN_PROGRESS');
13494                           --fnd_message.set_token('EVALUATION_IN_PROGRESS',eval_in_prog_meaning);
13495                           fnd_message.set_token('ROUND',get_technical_meaning);
13496                           --fnd_message.set_token('SEALED_AUCTION_STATUS', l_commercial_lock_meaning);
13497                           l_message := fnd_message.get || ' (' || l_technical_lock_meaning || ')';
13498 
13499                           IF (FND_LOG.level_statement>= FND_LOG.g_current_runtime_level) THEN
13500                             FND_LOG.string(log_level => FND_LOG.level_statement,
13501                               module  =>  g_module_prefix || 'GET_AUCTION_STATUS_DISPLAY',
13502                               message  => '10. l_message : ' || l_message
13503                                   );
13504                           END IF;
13505 
13506                         else  -- technical unlocked, commercial locked
13507                           -- show Evaluation in Progress: Technical
13508                           IF (FND_LOG.level_statement>= FND_LOG.g_current_runtime_level) THEN
13509                             FND_LOG.string(log_level => FND_LOG.level_statement,
13510                               module  =>  g_module_prefix || 'GET_AUCTION_STATUS_DISPLAY',
13511                               message  => 'Technical unclocked but commercially locked '
13512                                   );
13513                           END IF;
13514 
13515                           fnd_message.set_name('PON', 'PON_EVALUATION_IN_PROGRESS');
13516                           --fnd_message.set_token('EVALUATION_IN_PROGRESS', eval_in_prog_meaning);
13517                           fnd_message.set_token('ROUND',get_technical_meaning);
13518                           l_message := fnd_message.get;
13519 
13520                           IF (FND_LOG.level_statement>= FND_LOG.g_current_runtime_level) THEN
13521                             FND_LOG.string(log_level => FND_LOG.level_statement,
13522                               module  =>  g_module_prefix || 'GET_AUCTION_STATUS_DISPLAY',
13523                               message  => '11. l_message : ' ||l_message
13524                                   );
13525                           END IF;
13526 
13527                         end if;
13528 
13529                       -- commercial part unlocked
13530                       elsif l_commercial_lock_status = 'UNLOCKED' then
13531                         -- show Evaluation in Progress: Commercial
13532 
13533                         IF (FND_LOG.level_statement>= FND_LOG.g_current_runtime_level) THEN
13534                           FND_LOG.string(log_level => FND_LOG.level_statement,
13535                             module  =>  g_module_prefix || 'GET_AUCTION_STATUS_DISPLAY',
13536                             message  => 'commercial part unlocked'
13537                                 );
13538                         END IF;
13539 
13540                         fnd_message.set_name('PON', 'PON_EVALUATION_IN_PROGRESS');
13541                         --fnd_message.set_token('EVALUATION_IN_PROGRESS', eval_in_prog_meaning);
13542                         fnd_message.set_token('ROUND',get_commercial_meaning);
13543                         l_message := fnd_message.get;
13544 
13545                         IF (FND_LOG.level_statement>= FND_LOG.g_current_runtime_level) THEN
13546                           FND_LOG.string(log_level => FND_LOG.level_statement,
13547                             module  =>  g_module_prefix || 'GET_AUCTION_STATUS_DISPLAY',
13548                             message  => '12. l_message'
13549                                 );
13550                         END IF;
13551 
13552                 -- commercial part unsealed
13553                       else
13554                   -- if auction_status is AUCTION_CLOSED and AWARD_STATUS is NO
13555                   -- it means round is completed
13556                   -- show Round Completed (Unsealed)
13557                         IF (FND_LOG.level_statement>= FND_LOG.g_current_runtime_level) THEN
13558                           FND_LOG.string(log_level => FND_LOG.level_statement,
13559                             module  =>  g_module_prefix || 'GET_AUCTION_STATUS_DISPLAY',
13560                             message  => 'commercial unsealed ; Auction Statuses : '||
13561                             'l_auction_status2 ' || l_auction_status2 || '; l_award_status : ' || l_award_status
13562                             );
13563                         END IF;
13564 
13565                         -- show Evaluation in Progress: Commercial (Unsealed)
13566                         fnd_message.set_name('PON', 'PON_EVALUATION_IN_PROGRESS');
13567                         --fnd_message.set_token('EVALUATION_IN_PROGRESS', eval_in_prog_meaning);
13568                         fnd_message.set_token('ROUND',get_commercial_meaning);
13569                         l_message := fnd_message.get || ' (' || l_commercial_lock_meaning || ')';
13570 
13571                         IF (FND_LOG.level_statement>= FND_LOG.g_current_runtime_level) THEN
13572                           FND_LOG.string(log_level => FND_LOG.level_statement,
13573                             module  =>  g_module_prefix || 'GET_AUCTION_STATUS_DISPLAY',
13574                             message  => 'l_message : ' || l_message);
13575                         END IF;
13576 
13577                       end if;
13578 
13579               -- is a supplier
13580               else
13581 
13582                   IF (FND_LOG.level_statement>= FND_LOG.g_current_runtime_level) THEN
13583                     FND_LOG.string(log_level => FND_LOG.level_statement,
13584                       module  =>  g_module_prefix || 'GET_AUCTION_STATUS_DISPLAY',
13585                       message  => '14. Supplier Status');
13586                   END IF;
13587 
13588                 declare
13589                   l_closed_meaning VARCHAR2(30);
13590                 begin
13591                   -- show Closed (Unlocked: Technical) or Closed (Unsealed: Technical)
13592                   fnd_message.set_name('PON','PON_AUC_CLOSED_ROUND');
13593                   --fnd_message.set_token('CLOSED', l_closed_meaning);
13594                   fnd_message.set_token('SEALED_STATUS',l_technical_lock_meaning);
13595                   fnd_message.set_token('ROUND',get_technical_meaning);
13596                   l_message := fnd_message.get;
13597 
13598                   IF (FND_LOG.level_statement>= FND_LOG.g_current_runtime_level) THEN
13599                     FND_LOG.string(log_level => FND_LOG.level_statement,
13600                       module  =>  g_module_prefix || 'GET_AUCTION_STATUS_DISPLAY',
13601                       message  => '15. l_message  : ' || l_message );
13602                   END IF;
13603 
13604                 END;
13605               END IF; -- if  is_buyer
13606     --}
13607       END IF;
13608 
13609     END IF;
13610 
13611     IF (FND_LOG.level_statement>= FND_LOG.g_current_runtime_level) THEN
13612       FND_LOG.string(log_level => FND_LOG.level_statement,
13613         module  =>  g_module_prefix || 'GET_AUCTION_STATUS_DISPLAY',
13614         message  => 'Returning l_message : ' || l_message );
13615     END IF;
13616 
13617     return l_message;
13618 
13619   EXCEPTION
13620     WHEN OTHERS THEN
13621 
13622       IF (FND_LOG.level_unexpected>= FND_LOG.g_current_runtime_level) THEN
13623         FND_LOG.string(log_level => FND_LOG.level_unexpected,
13624           module  =>  g_module_prefix || 'GET_AUCTION_STATUS_DISPLAY',
13625           message  => 'Exception encountered for auction : ' || p_auction_header_id
13626                       ||'and p_user_trading_partner_id : ' || p_user_trading_partner_id
13627                       ||' Returning l_message : ' || l_message);
13628       END IF;
13629       return l_message;
13630 
13631 END GET_AUCTION_STATUS_DISPLAY;
13632 
13633 
13634 PROCEDURE GET_MONITOR_IMAGE_AND_STATUS(
13635       p_auction_header_id     IN NUMBER,
13636       p_doctype_id IN NUMBER,
13637       p_bid_visibility         IN VARCHAR2,
13638       p_sealed_auction_status  IN VARCHAR2,
13639       p_auctioneer_id          IN NUMBER,
13640       p_viewer_id              IN NUMBER,
13641       p_has_items              IN VARCHAR2,
13642       p_doc_type               IN VARCHAR2,
13643       p_auction_status         IN VARCHAR2,
13644       p_view_by_date           IN DATE,
13645       p_open_bidding_date      IN DATE,
13646       p_has_scoring_teams_flag IN VARCHAR2,
13647       p_user_trading_partner_id IN NUMBER,
13648       x_buyer_monitor_image OUT NOCOPY VARCHAR2,
13649       x_auction_status_display OUT NOCOPY VARCHAR2)
13650 AS
13651 BEGIN
13652 
13653     IF (FND_LOG.level_statement>= FND_LOG.g_current_runtime_level) THEN
13654       FND_LOG.string(log_level => FND_LOG.level_statement,
13655         module  =>  g_module_prefix || 'GET_MONITOR_IMAGE_AND_STATUS',
13656         message  => 'Entering the function with params --'
13657                     || 'p_auction_header_id = ' || p_auction_header_id
13658                     || ';p_doctype_id = ' || p_doctype_id
13659                     || ';p_bid_visibility = ' || p_bid_visibility
13660                     || ';p_sealed_auction_status = ' || p_sealed_auction_status
13661                     || ';p_auctioneer_id = ' || p_auctioneer_id
13662                     || ';p_viewer_id = ' || p_viewer_id
13663                     || ';p_has_items = ' || p_has_items
13664                     || ';p_doc_type = ' || p_doc_type
13665                     || ';p_auction_status = ' || p_auction_status
13666                     || ';p_view_by_date = ' || p_view_by_date
13667                     || ';p_open_bidding_date = ' || p_open_bidding_date
13668                     || ';p_has_scoring_teams_flag = ' || p_has_scoring_teams_flag
13669                     || ';p_user_trading_partner_id = ' || p_user_trading_partner_id
13670             );
13671     END IF;
13672 
13673     x_buyer_monitor_image := PON_OA_UTIL_PKG.BUYER_MONITOR_IMAGE (p_doctype_id,
13674               p_bid_visibility         ,
13675               p_sealed_auction_status  ,
13676               p_auctioneer_id          ,
13677               p_viewer_id              ,
13678               p_has_items              ,
13679               p_doc_type               ,
13680               p_auction_status         ,
13681               p_view_by_date           ,
13682               p_open_bidding_date      ,
13683               p_auction_header_id     ,
13684               p_has_scoring_teams_flag);
13685 
13686 
13687     IF (FND_LOG.level_statement>= FND_LOG.g_current_runtime_level) THEN
13688       FND_LOG.string(log_level => FND_LOG.level_statement,
13689         module  =>  g_module_prefix || 'GET_MONITOR_IMAGE_AND_STATUS',
13690         message  => 'x_buyer_monitor_image = ' || x_buyer_monitor_image);
13691     END IF;
13692 
13693     x_auction_status_display := GET_AUCTION_STATUS_DISPLAY(p_auction_header_id,
13694                       p_user_trading_partner_id);
13695 
13696     IF (FND_LOG.level_statement>= FND_LOG.g_current_runtime_level) THEN
13697       FND_LOG.string(log_level => FND_LOG.level_statement,
13698         module  =>  g_module_prefix || 'GET_MONITOR_IMAGE_AND_STATUS',
13699         message  => 'x_auction_status_display = ' || x_auction_status_display);
13700     END IF;
13701 
13702   EXCEPTION
13703     WHEN OTHERS THEN
13704 
13705       IF (FND_LOG.level_unexpected>= FND_LOG.g_current_runtime_level) THEN
13706         FND_LOG.string(log_level => FND_LOG.level_unexpected,
13707           module  =>  g_module_prefix || 'GET_MONITOR_IMAGE_AND_STATUS',
13708           message  => 'Exception encountered for auction : ' || p_auction_header_id);
13709       END IF;
13710 
13711 END GET_MONITOR_IMAGE_AND_STATUS;
13712 
13713 --========================================================================
13714 -- PROCEDURE : GET_SUPPL_NEGOTIATION_STATUS
13715 -- PARAMETERS:
13716 --             p_auction_status - The auction_status column
13717 --             p_is_paused - is_paused column
13718 --             p_view_by_date - view_by_date column
13719 --             p_open_bidding_date - open_bidding_date column
13720 --             p_close_bidding_date - close_bidding_date column
13721 --
13722 -- COMMENT   : This procedure will be used in the pon_auction_headers_all_v
13723 --             view to get the value for the suppl_negotiation_status
13724 --             column in the view. Prior to the use of this function the
13725 --             same code existed as decodes in the view itself.
13726 --========================================================================
13727 FUNCTION GET_SUPPL_NEGOTIATION_STATUS (
13728   p_auction_status IN VARCHAR2,
13729   p_is_paused IN VARCHAR2,
13730   p_view_by_date IN DATE,
13731   p_open_bidding_date IN DATE,
13732   p_close_bidding_date IN DATE
13733 ) RETURN VARCHAR2 IS -- {
13734 
13735 l_module_name VARCHAR2(40) := 'GET_SUPPL_NEGOTIATION_STATUS';
13736 l_return_value VARCHAR2(40);
13737 
13738 BEGIN
13739 
13740   IF (FND_LOG.level_statement >= FND_LOG.g_current_runtime_level) THEN --{
13741     FND_LOG.string(log_level => FND_LOG.level_statement,
13742       module  =>  g_module_prefix || l_module_name,
13743       message  => 'Entered procedure with p_auction_status = ' ||
13744                   p_auction_status || ', p_is_paused = ' || p_is_paused
13745                   || ', p_view_by_date = ' || p_view_by_date ||
13746                   ', p_open_bidding_date = ' || p_open_bidding_date ||
13747                   ', p_close_bidding_date = ' || p_close_bidding_date);
13748   END IF; --}
13749 
13750   IF (p_auction_status = 'CANCELLED') THEN -- {
13751     l_return_value := 'CANCELLED';
13752   ELSIF (p_auction_status = 'AMENDED') THEN
13753     l_return_value := 'AMENDED';
13754   ELSIF (p_auction_status = 'DRAFT') THEN
13755     l_return_value := 'DRAFT';
13756   ELSIF (nvl (p_is_paused, 'N') = 'Y') THEN
13757     l_return_value := 'PAUSED';
13758   ELSIF (sign (nvl (p_view_by_date, p_open_bidding_date) - sysdate) = 1) THEN
13759     l_return_value := 'SUBMITTED';
13760   ELSIF (sign (p_open_bidding_date - sysdate) = 1) THEN
13761     l_return_value := 'PREVIEW';
13762   ELSIF (sign (p_close_bidding_date - sysdate) = 1) THEN
13763     l_return_value := 'ACTIVE';
13764   ELSE
13765     l_return_value := 'CLOSED';
13766   END IF; --}
13767 
13768   IF (FND_LOG.level_statement >= FND_LOG.g_current_runtime_level) THEN --{
13769     FND_LOG.string(log_level => FND_LOG.level_statement,
13770       module  =>  g_module_prefix || l_module_name,
13771       message  => 'Returning value = ' || l_return_value);
13772   END IF; --}
13773 
13774   RETURN l_return_value;
13775 
13776 END; -- }
13777 
13778 --========================================================================
13779 -- PROCEDURE : GET_NEGOTIATION_STATUS
13780 -- PARAMETERS:
13781 --             p_auction_status - The auction_status column
13782 --             p_is_paused - is_paused column
13783 --             p_view_by_date - view_by_date column
13784 --             p_open_bidding_date - open_bidding_date column
13785 --             p_close_bidding_date - close_bidding_date column
13786 --             p_award_status - award_status column
13787 --             p_award_approval_status - award_approval_status column
13788 --             p_outcome_status - outcome_status column
13789 --
13790 -- COMMENT   : This procedure will be used in the pon_auction_headers_all_v
13791 --             view to get the value for the negotiation_status
13792 --             column in the view. Prior to the use of this function the
13793 --             same code existed as decodes in the view itself.
13794 --========================================================================
13795 FUNCTION GET_NEGOTIATION_STATUS (
13796   p_auction_status VARCHAR2,
13797   p_is_paused VARCHAR2,
13798   p_view_by_date DATE,
13799   p_open_bidding_date DATE,
13800   p_close_bidding_date DATE,
13801   p_award_status VARCHAR2,
13802   p_award_approval_status VARCHAR2,
13803   p_outcome_status VARCHAR2
13804 ) RETURN VARCHAR2 IS -- {
13805 
13806 l_module_name VARCHAR2(40) := 'GET_NEGOTIATION_STATUS';
13807 l_return_value VARCHAR2(40);
13808 
13809 BEGIN
13810 
13811   IF (FND_LOG.level_statement >= FND_LOG.g_current_runtime_level) THEN --{
13812     FND_LOG.string(log_level => FND_LOG.level_statement,
13813       module  =>  g_module_prefix || l_module_name,
13814       message  => 'Entered with p_auction_status = ' || p_auction_status ||
13815                   ', p_is_paused = ' || p_is_paused || ', p_view_by_date = ' ||
13816                   p_view_by_date || ', p_open_bidding_date = ' || p_open_bidding_date
13817                   || ', p_close_bidding_date = ' || p_close_bidding_date ||
13818 		  'p_award_approval_status = ' || p_award_approval_status ||
13819 		  'p_award_status = ' || p_award_status || ', p_outcome_status = '
13820                   || p_outcome_status);
13821   END IF; --}
13822 
13823   IF (p_auction_status = 'CANCELLED') THEN -- {
13824     l_return_value :=  'CANCELLED';
13825   ELSIF (p_auction_status = 'AMENDED') THEN
13826     l_return_value :=  'AMENDED';
13827   ELSIF (p_auction_status = 'DRAFT') THEN
13828     l_return_value :=  'DRAFT';
13829   ELSIF (nvl (p_is_paused, 'N') = 'Y') THEN
13830     l_return_value :=  'PAUSED';
13831   ELSIF (sign (nvl (p_view_by_date, p_open_bidding_date) - sysdate) = 1) THEN
13832     l_return_value :=  'SUBMITTED';
13833   ELSIF (sign (p_open_bidding_date - sysdate) = 1) THEN
13834     l_return_value :=  'PREVIEW';
13835   ELSIF (sign (p_close_bidding_date - sysdate) = 1) THEN
13836     l_return_value :=  'ACTIVE';
13837   ELSIF (p_auction_status = 'ACTIVE') THEN
13838     IF (p_award_status = 'NO') THEN -- {
13839       IF (p_award_approval_status = 'APPROVED') THEN -- {
13840         l_return_value :=  'AWARD_APPROVED';
13841       ELSIF (p_award_approval_status = 'REJECTED') THEN
13842         l_return_value :=  'AWARD_REJECTED';
13843       ELSIF (p_award_approval_status = 'INPROCESS') THEN
13844         l_return_value :=  'AWARD_APPROVAL_INPROCESS';
13845       ELSE
13846         l_return_value :=  'CLOSED';
13847       END IF; -- }
13848     ELSIF (p_award_status = 'PARTIAL') THEN
13849       IF (p_award_approval_status = 'APPROVED') THEN -- {
13850         l_return_value :=  'AWARD_APPROVED';
13851       ELSIF (p_award_approval_status = 'REJECTED') THEN
13852         l_return_value :=  'AWARD_REJECTED';
13853       ELSIF (p_award_approval_status = 'INPROCESS') THEN
13854         l_return_value :=  'AWARD_APPROVAL_INPROCESS';
13855       ELSE
13856         l_return_value :=  'AWARD_IN_PROG';
13857       END IF; -- }
13858     ELSIF (p_award_status = 'AWARDED') THEN
13859       IF (p_award_approval_status = 'APPROVED') THEN -- {
13860         l_return_value :=  'AWARD_APPROVED';
13861       ELSIF (p_award_approval_status = 'REJECTED') THEN
13862         l_return_value :=  'AWARD_REJECTED';
13863       ELSIF (p_award_approval_status = 'INPROCESS') THEN
13864         l_return_value :=  'AWARD_APPROVAL_INPROCESS';
13865       ELSE
13866         l_return_value :=  'AWARD_IN_PROG';
13867       END IF; -- }
13868     END IF; -- }
13869   ELSIF (p_auction_status = 'AUCTION_CLOSED') THEN
13870     IF (p_award_status = 'NO') THEN -- {
13871       l_return_value :=  'ROUND_COMPLETED';
13872     ELSIF (p_award_status = 'QUALIFIED') THEN
13873       l_return_value :=  'RFI_COMPLETED';
13874     ELSIF (p_outcome_status = 'NOT_ALLOCATED') THEN
13875       l_return_value :=  'AWARD_COMPLETED';
13876     ELSIF (p_outcome_status = 'PARTIALLY_ALLOCATED') THEN
13877       l_return_value :=  'ALLOCATION_IN_PROG';
13878     ELSIF (p_outcome_status = 'ALLOCATED') THEN
13879       l_return_value :=  'ALLOCATION_IN_PROG';
13880     ELSIF (p_outcome_status = 'ALLOCATION_NOT_REQUIRED') THEN
13881       l_return_value :=  'AWARD_COMPLETED';
13882     ELSE
13883       l_return_value :=  p_outcome_status;
13884     END IF; -- }
13885   END IF; -- }
13886 
13887   IF (FND_LOG.level_statement >= FND_LOG.g_current_runtime_level) THEN --{
13888     FND_LOG.string(log_level => FND_LOG.level_statement,
13889       module  =>  g_module_prefix || l_module_name,
13890       message  => 'Returning ' || l_return_value);
13891   END IF; --}
13892 
13893   RETURN l_return_value;
13894 
13895 END; -- }
13896 
13897 /*============================================================================================================*
13898  * PROCEDURE : GET_DEFAULT_TIERS_INDICATOR                                                                    *
13899  * PARAMETERS:                                                                                                *
13900  *             p_contract_type - outcome of the negotiation                                                   *
13901  *             p_price_breaks_enabled - to indicate if price breaks are applicable as per po style            *
13902  *             p_qty_price_tiers_enabled - to indicate if price tiers are applicable as per neg style         *
13903  *             p_doctype_id - document type id of the negotiation                                             *
13904  *             x_price_tiers_indicator - default price tiers indicator value.                                 *
13905  *                                                                                                            *
13906  * COMMENT   : This procedure will be used in getting the default  price tier indicator value.                *
13907  *             It's used in plsql routines where new negotiation created from autocreation and renegotiation. *
13908  *             The logic is same as AuctionHeadersAllEO.getPriceTiersPoplist. Only difference is that we      *
13909  *             don't have to return the poplist here. So few conditions where default values is same can be   *
13910  *             clubbeb together.                                                                              *
13911  * ===========================================================================================================*/
13912 
13913 PROCEDURE GET_DEFAULT_TIERS_INDICATOR (
13914   p_contract_type                   IN VARCHAR2,
13915   p_price_breaks_enabled            IN VARCHAR2,
13916   p_qty_price_tiers_enabled         IN VARCHAR2,
13917   p_doctype_id                      IN NUMBER,
13918   x_price_tiers_indicator           OUT NOCOPY VARCHAR2
13919 ) IS -- {
13920 
13921 l_module_name VARCHAR2(40) := 'GET_DEFAULT_TIERS_INDICATOR';
13922 l_rfi_doctype_id   NUMBER;
13923 
13924 BEGIN
13925 
13926   IF (FND_LOG.level_statement >= FND_LOG.g_current_runtime_level) THEN --{
13927     FND_LOG.string(log_level => FND_LOG.level_statement,
13928       module  =>  g_module_prefix || l_module_name,
13929       message  => 'Entered with p_contract_type = ' || p_contract_type ||
13930                   ', p_price_breaks_enabled = ' || p_price_breaks_enabled || ', p_qty_price_tiers_enabled = ' ||
13931                   p_qty_price_tiers_enabled || ', p_doctype_id = ' || p_doctype_id);
13932   END IF; --}
13933 
13934   --
13935   -- To check if given doctype_id corresponds to a RFI we need to select doctype id for RFI from PON_AUC_DOCTYPES
13936   --
13937 
13938   SELECT doctype_id
13939   INTO l_rfi_doctype_id
13940   FROM PON_AUC_DOCTYPES
13941   WHERE doctype_group_name = 'REQUEST_FOR_INFORMATION';
13942 
13943   --
13944   -- Default price tiers value is Null if neg is
13945   -- 1. RFI  OR
13946   -- 2. SPO and Sourcing style does not allows quantity based tiers
13947   -- 3. BPA/CPA and Sourcing style doe not allows quantity based tiers and PO Flag disables price breaks
13948   --
13949 
13950   IF ( (p_doctype_id = l_rfi_doctype_id) OR (p_contract_type = 'STANDARD' and p_qty_price_tiers_enabled = 'N')
13951         OR (p_contract_type <> 'STANDARD' and p_qty_price_tiers_enabled = 'N' and p_price_breaks_enabled = 'N') ) THEN --{
13952 
13953         IF (FND_LOG.level_statement >= FND_LOG.g_current_runtime_level) THEN --{
13954           FND_LOG.string(log_level => FND_LOG.level_statement,
13955             module  =>  g_module_prefix || l_module_name,
13956             message  => '(Neg is RFI) or(SPO and Sourcing style does not allows quantity based tiers.) or ' ||
13957                          '(BPA/CPA and Sourcing style doe not allows quantity based tiers and PO Flag disables price breaks)');
13958           FND_LOG.string(log_level => FND_LOG.level_statement,
13959             module  =>  g_module_prefix || l_module_name,
13960             message  => ' Setting the default price tiers indicator as null.');
13961         END IF; --}
13962 
13963         x_price_tiers_indicator := null;
13964 
13965   -- } End of is rfi or spo ....
13966 
13967   --
13968   -- Default value is PRICE_BREAKS if
13969   -- 1. a BPA/CPA AND
13970   -- 2. PO Flag enables price breaks
13971   --
13972 
13973   ELSIF ( p_contract_type <> 'STANDARD' and p_price_breaks_enabled = 'Y') THEN --{
13974 
13975         IF (FND_LOG.level_statement >= FND_LOG.g_current_runtime_level) THEN --{
13976           FND_LOG.string(log_level => FND_LOG.level_statement,
13977             module  =>  g_module_prefix || l_module_name,
13978             message  => 'BPA/CPA; price breaks are enabled. Setting default value to price_breaks');
13979         END IF; --}
13980 
13981         x_price_tiers_indicator := 'PRICE_BREAKS';
13982 
13983   --} End of else if
13984 
13985   --
13986   -- Default value is NONE if
13987   -- Sourcing style allows quantity based tiers  and
13988   -- 1. a BPA/CPA AND PO Flag disables price breaks  OR
13989   -- 2. a SPO
13990   --
13991 
13992   ELSE  --{
13993 
13994         IF (FND_LOG.level_statement >= FND_LOG.g_current_runtime_level) THEN --{
13995           FND_LOG.string(log_level => FND_LOG.level_statement,
13996             module  =>  g_module_prefix || l_module_name,
13997             message  => 'Price tiers are enabled and ( price breaks are disabled for BPA/CPA OR is an SPO) Setting default value to none');
13998         END IF; --}
13999 
14000         x_price_tiers_indicator := 'NONE';
14001 
14002   END IF;   --} End of else
14003 
14004   IF (FND_LOG.level_statement >= FND_LOG.g_current_runtime_level) THEN --{
14005     FND_LOG.string(log_level => FND_LOG.level_statement,
14006       module  =>  g_module_prefix || l_module_name,
14007       message  => 'Returning to the caller with  x_price_tiers_indicator as '|| x_price_tiers_indicator);
14008   END IF; --}
14009 
14010 END GET_DEFAULT_TIERS_INDICATOR; -- }
14011 
14012 -- adsahay: bug 6374353
14013 -- populate the two part meanings' cache
14014 procedure init_two_part_cache
14015 as
14016 begin
14017     IF (FND_LOG.level_procedure >= FND_LOG.g_current_runtime_level) THEN --{
14018       FND_LOG.string(log_level => FND_LOG.level_procedure,
14019         module  =>  g_module_prefix || 'init_two_part_cache',
14020         message  => 'Entered procedure init_two_part_cache');
14021     END IF; --}
14022 
14023     SELECT flv1.LANGUAGE, flv1.meaning AS technical_meaning, flv2.meaning AS commercial_meaning
14024     BULK COLLECT INTO g_two_part_cache
14025     FROM fnd_lookup_values flv1, fnd_lookup_values flv2
14026     WHERE flv1.lookup_type='PON_TWO_PART_TYPE'
14027     AND flv2.lookup_type=flv1.lookup_type
14028     AND flv1.lookup_code='TECHNICAL'
14029     AND flv2.lookup_code='COMMERCIAL'
14030     AND flv1.LANGUAGE=flv2.LANGUAGE;
14031 
14032     g_tp_cache_rec := g_two_part_cache(1); -- first time initialisation
14033 
14034     IF (FND_LOG.level_procedure >= FND_LOG.g_current_runtime_level) THEN --{
14035       FND_LOG.string(log_level => FND_LOG.level_procedure,
14036         module  =>  g_module_prefix || 'init_two_part_cache',
14037         message  => 'Exiting procedure init_two_part_cache');
14038     END IF; --}
14039 
14040 end init_two_part_cache;
14041 
14042 -- adsahay: bug 6374353
14043 -- update record from from cache table when needed
14044 PROCEDURE update_cache_rec
14045 AS
14046 BEGIN
14047   IF (FND_LOG.level_procedure >= FND_LOG.g_current_runtime_level) THEN --{
14048     FND_LOG.string(log_level => FND_LOG.level_procedure,
14049       module  =>  g_module_prefix || 'update_cache_rec',
14050       message  => 'Entered procedure update_cache_rec');
14051   END IF; --}
14052 
14053   IF (g_tp_cache_rec.language <> USERENV('LANG')) THEN -- {
14054 
14055     IF (FND_LOG.level_statement >= FND_LOG.g_current_runtime_level) THEN --{
14056       FND_LOG.string(log_level => FND_LOG.level_statement,
14057         module  =>  g_module_prefix || 'update_cache_rec',
14058         message  => 'User session language is now ' || USERENV('LANG'));
14059     END IF; --}
14060 
14061     FOR i in 1..g_two_part_cache.COUNT LOOP
14062       IF (g_two_part_cache(i).language = USERENV('LANG')) THEN
14063         g_tp_cache_rec := g_two_part_cache(i);
14064         exit;        -- if we got our values, then break loop.
14065       END IF;
14066     END LOOP;
14067   END IF; -- }
14068 
14069   IF (FND_LOG.level_procedure >= FND_LOG.g_current_runtime_level) THEN --{
14070     FND_LOG.string(log_level => FND_LOG.level_procedure,
14071       module  =>  g_module_prefix || 'update_cache_rec',
14072       message  => 'Exiting procedure update_cache_rec');
14073   END IF; --}
14074 END update_cache_rec;
14075 
14076 END PON_AUCTION_PKG;