[Home] [Help]
PACKAGE BODY: APPS.PO_CHANGEORDERWF_PVT
Source
1 PACKAGE BODY PO_ChangeOrderWF_PVT AS
2 /* $Header: POXVSCWB.pls 120.52.12020000.3 2013/02/10 18:36:48 vegajula ship $ */
3
4
5 g_pkg_name CONSTANT VARCHAR2(50) := 'PO_ChangeOrderWF_PVT';
6 g_module_prefix CONSTANT VARCHAR2(50) := 'po.plsql.' || g_pkg_name || '.';
7 g_fnd_debug VARCHAR2(1) := NVL(FND_PROFILE.VALUE('AFLOG_ENABLED'),'N');
8 g_po_wf_debug VARCHAR2(1) := NVL(FND_PROFILE.VALUE('PO_SET_DEBUG_WORKFLOW_ON'),'N');
9
10 -- Read the profile option that determines whether the promise date will be defaulted with need-by date or not
11 g_default_promise_date VARCHAR2(1) := NVL(FND_PROFILE.VALUE('POS_DEFAULT_PROMISE_DATE_ACK'),'N');
12 NL VARCHAR2(1) := fnd_global.newline;
13
14 /*Initializing Private Procedures/Functions*/
15 PROCEDURE Notify_Requester_Sup_Change( p_header_id in number,
16 p_release_id in number,
17 p_revision_num in number,
18 p_chg_req_grp_id in number,
19 p_requestor_id in number);
20
21 PROCEDURE Notify_Planner_Sup_Change( p_header_id in number,
22 p_release_id in number,
23 p_revision_num in number,
24 p_chg_req_grp_id in number,
25 p_planner_id in number);
26
27 /*************************************************************************
28 * Private Procedure: InsertActionHist
29 * Effects: insert into action history table.
30 *
31 * It is called when the change request is submitted (by requester
32 * or buyer) and when buyer responds to the change request.
33 *
34 * the action can be 'SUBMIT CHANGE', 'ACCEPTED', 'REJECTED'
35 * or 'RESPOND'
36 *
37 * the process will commit when it exits.
38 *
39 * Returns:
40 ************************************************************************/
41 PROCEDURE InsertActionHist(
42 p_doc_id number,
43 p_doc_type varchar2,
44 p_doc_subtype varchar2,
45 p_employee_id number,
46 p_action varchar2,
47 p_note varchar2,
48 p_path_id number);
49
50 PROCEDURE Commit_CancelPO(
51 x_return_status out NOCOPY varchar2,
52 p_can_doc_type in varchar2,
53 p_can_doc_subtype in varchar2,
54 p_can_hdr_id in number,
55 p_can_rel_id in number,
56 p_can_line_id in number,
57 p_can_line_loc_id in number,
58 p_can_reason in varchar2,
59 p_can_req_flag in varchar2,
60 p_launch_approvals_flag IN VARCHAR2 --Bug 13114334
61 );
62
63 PROCEDURE initialize(p_employee_id in NUMBER, p_org_id IN NUMBER);
64
65 -- Making this api public RDP requirements
66 /* procedure NotifySupAllChgRpdWF( p_header_id in number,
67 p_release_id in number,
68 p_revision_num in number,
69 p_chg_req_grp_id in number); */
70
71 procedure CancelPO( x_return_status out NOCOPY varchar2,
72 p_header_id in number,
73 p_release_id in number,
74 p_chg_req_grp_id in number);
75
76 Procedure Insert_Acc_Rejection_Row( p_itemtype in varchar2,
77 p_itemkey in varchar2,
78 p_actid in number,
79 p_flag in varchar2);
80
81 Procedure Update_Chg_Req_If_Po_Apprvd( p_header_id in number,
82 p_release_id in number);
83
84 /**
85 * Private procedure: Carry_Over_Acknowledgement
86 * Requires: PO_HEADER_ID, PO_RELEASE_ID, REVISION_NUM,
87 * Effects: Carry over the shipment_level acknowledgement results from the
88 * previous revision, it is called before launching PO approval
89 * workflow after supplier's change has been accepted by buyer.
90 * Returns:
91 * x_return_status - FND_API.G_RET_STS_SUCCESS if all messages are appended
92 * FND_API.G_RET_STS_ERROR if an error occurs
93 * FND_API.G_RET_STS_UNEXP_ERROR if unexpected error occurs
94 *
95 * Bugs Fixed:
96 * 7205793 - Added internal procedure, which is an autonomous transaction
97 * to avoid deadlock during PO Approval Process.
98 */
99 PROCEDURE Carry_Over_Acknowledgement (x_return_status OUT NOCOPY VARCHAR2,
100 p_po_header_id IN NUMBER,
101 p_po_release_id IN NUMBER,
102 p_revision_num IN NUMBER );
103
104 PROCEDURE Notify_Requester_Sup_Change( p_header_id in number,
105 p_release_id in number,
106 p_revision_num in number,
107 p_chg_req_grp_id in number,
108 p_requestor_id in number)
109 IS
110 l_api_name varchar2(50):= 'Notify_Requester_Sup_Change';
111 l_progress varchar2(5) := '000';
112 l_seq number;
113 l_item_key varchar2(2000);
114
115 l_supplier_username fnd_user.user_name%type;
116 l_requestor_username fnd_user.user_name%type;
117 l_requestor_disp_name varchar2(2000);
118
119 n_varname Wf_Engine.NameTabTyp;
120 n_varval Wf_Engine.NumTabTyp;
121 t_varname Wf_Engine.NameTabTyp;
122 t_varval Wf_Engine.TextTabTyp;
123 BEGIN
124
125 if(p_requestor_id is null or p_chg_req_grp_id is null) then
126 return;
127 end if;
128
129 select PO_SUPPLIER_CHANGE_WF_S.nextval into l_seq from dual;
130 if(p_release_id is null) then
131 l_item_key := 'NRSC-'||to_char(p_requestor_id)||'-'||to_char(p_header_id)||'-'||to_char(p_revision_num)||'-'||to_char(l_seq);
132 else
133 l_item_key := 'NRSC-'||to_char(p_requestor_id)||'-'||to_char(p_release_id)||'-'||to_char(p_revision_num)||'-'||to_char(l_seq);
134 end if;
135
136 l_progress := '001';
137
138 wf_engine.createProcess ( ItemType => 'POSCHORD',
139 ItemKey => l_item_key,
140 Process => 'NOTIFY_REQUESTER_SUP_CHN');
141
142 l_progress := '002';
143 wf_directory.GetUserName ( p_orig_system => 'PER',
144 p_orig_system_id => p_requestor_id,
145 p_name => l_requestor_username,
146 p_display_name => l_requestor_disp_name);
147
148 IF(l_requestor_disp_name is not null) THEN
149 l_progress := '003';
150 -- Get Supplier User Name
151 select user_name
152 into l_supplier_username
153 from fnd_user
154 where user_id = fnd_global.user_id;
155
156 n_varname(1) := 'PO_HEADER_ID';
157 n_varval(1) := p_header_id;
158 n_varname(2) := 'PO_RELEASE_ID';
159 n_varval(2) := p_release_id;
160 n_varname(3) := 'PO_REVISION_NUM';
161 n_varval(3) := p_revision_num;
162 n_varname(4) := 'CHANGE_REQUEST_GROUP_ID';
163 n_varval(4) := p_chg_req_grp_id;
164
165 t_varname(1) := 'FROM_SUPPLIER';
166 t_varval(1) := l_supplier_username;
167 t_varname(2) := 'NTF_FOR_REQ_SUP_CHN';
168 t_varval(2) := 'PLSQLCLOB:PO_ChangeOrderWF_PVT.GEN_NTF_FOR_REQ_SUP_CHN/'||
169 '@' ||p_header_id||'#'
170 ||p_release_id||'$'
171 ||p_chg_req_grp_id||'%'
172 ||p_requestor_id||'^';
173
174 t_varname(3) := 'NTF_FOR_REQ_SUBJECT';
175 t_varval(3) := 'PLSQL:PO_ChangeOrderWF_PVT.GEN_NTF_FOR_REQ_SUBJECT/'||l_item_key;
176 t_varname(4) := 'PREPARER_USERNAME';
177 t_varval(4) := l_requestor_username;
178
179
180 l_progress := '004';
181
182 Wf_Engine.SetItemAttrNumberArray('POSCHORD', l_item_key,n_varname,n_varval);
183 Wf_Engine.SetItemAttrTextArray('POSCHORD', l_item_key,t_varname,t_varval);
184
185 wf_engine.StartProcess( ItemType => 'POSCHORD',
186 ItemKey => l_item_key);
187 END IF;
188 exception when others then
189 IF g_fnd_debug = 'Y' AND FND_LOG.LEVEL_UNEXPECTED >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
190 FND_LOG.string(FND_LOG.level_unexpected, g_module_prefix ||
191 l_api_name || '.others_exception', l_progress||':'||sqlerrm);
192 END IF;
193
194 END Notify_Requester_Sup_Change;
195
196 PROCEDURE Notify_Planner_Sup_Change( p_header_id in number,
197 p_release_id in number,
198 p_revision_num in number,
199 p_chg_req_grp_id in number,
200 p_planner_id in number)
201 IS
202 l_api_name varchar2(50):= 'Notify_Planner_Sup_Change';
203 l_progress varchar2(5) := '000';
204 l_seq number;
205 l_item_key varchar2(2000);
206
207 l_supplier_username fnd_user.user_name%type;
208 l_planner_username fnd_user.user_name%type;
209 l_planner_disp_name varchar2(2000);
210 l_type_lookup_code po_headers_all.type_lookup_code%type;
211
212 n_varname Wf_Engine.NameTabTyp;
213 n_varval Wf_Engine.NumTabTyp;
214 t_varname Wf_Engine.NameTabTyp;
215 t_varval Wf_Engine.TextTabTyp;
216
217 BEGIN
218
219 if(p_planner_id is null or p_chg_req_grp_id is null) then
220 return;
221 end if;
222
223 select PO_SUPPLIER_CHANGE_WF_S.nextval into l_seq from dual;
224
225 if(p_release_id is null) then
226 l_item_key := 'NPSC-'||to_char(p_planner_id)||'-'||to_char(p_header_id)||'-'||to_char(p_revision_num)||'-'||to_char(l_seq);
227 else
228 l_item_key := 'NPSC-'||to_char(p_planner_id)||'-'||to_char(p_release_id)||'-'||to_char(p_revision_num)||'-'||to_char(l_seq);
229 end if;
230
231 l_progress := '001';
232 wf_engine.createProcess ( ItemType => 'POSCHORD',
233 ItemKey => l_item_key,
234 Process => 'NOTIFY_PLANNER_SUP_CHN');
235
236 l_progress := '002';
237 wf_directory.GetUserName ( p_orig_system => 'PER',
238 p_orig_system_id => p_planner_id,
239 p_name => l_planner_username,
240 p_display_name => l_planner_disp_name);
241
242 IF(l_planner_disp_name is not null) THEN
243 l_progress := '003';
244 -- Get Supplier User Name
245 select user_name
246 into l_supplier_username
247 from fnd_user
248 where user_id = fnd_global.user_id;
249
250
251 n_varname(1) := 'PO_HEADER_ID';
252 n_varval(1) := p_header_id;
253 n_varname(2) := 'PO_RELEASE_ID';
254 n_varval(2) := p_release_id;
255 n_varname(3) := 'PO_REVISION_NUM';
256 n_varval(3) := p_revision_num;
257 n_varname(4) := 'CHANGE_REQUEST_GROUP_ID';
258 n_varval(4) := p_chg_req_grp_id;
259
260
261 t_varname(1) := 'FROM_SUPPLIER';
262 t_varval(1) := l_supplier_username;
263 t_varname(2) := 'NTF_FOR_PLAN_SUP_CHN';
264 t_varval(2) := 'PLSQLCLOB:PO_ChangeOrderWF_PVT.GEN_NTF_FOR_PLAN_SUP_CHN/'||
265 '@' ||p_header_id||'#'
266 ||p_release_id||'$'
267 ||p_chg_req_grp_id||'%'
268 ||p_planner_id||'^';
269
270 t_varname(3) := 'NTF_FOR_PLAN_SUBJECT';
271 t_varval(3) := 'PLSQL:PO_ChangeOrderWF_PVT.GEN_NTF_FOR_PLAN_SUBJECT/'||l_item_key;
272 t_varname(4) := 'PLANNER_USERNAME';
273 t_varval(4) := l_planner_username;
274
275
276 l_progress := '004';
277
278 Wf_Engine.SetItemAttrNumberArray('POSCHORD', l_item_key,n_varname,n_varval);
279 Wf_Engine.SetItemAttrTextArray('POSCHORD', l_item_key,t_varname,t_varval);
280
281 wf_engine.StartProcess( ItemType => 'POSCHORD',
282 ItemKey => l_item_key);
283 END IF;
284 exception when others then
285 IF g_fnd_debug = 'Y' AND FND_LOG.LEVEL_UNEXPECTED >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
286 FND_LOG.string(FND_LOG.level_unexpected, g_module_prefix ||
287 l_api_name || '.others_exception', l_progress||':'||sqlerrm);
288 END IF;
289
290 END Notify_Planner_Sup_Change;
291
292
293 /*************************************************************************
294 * Private Procedure: InsertActionHist
295 * Effects: insert into action history table.
296 *
297 * It is called when the change request is submitted (by requester
298 * or buyer) and when buyer responds to the change request.
299 *
300 * the action can be 'SUBMIT CHANGE', 'ACCEPTED', 'REJECTED'
301 * or 'RESPOND'
302 *
303 * the process will commit when it exits.
304 *
305 * Returns:
306 ************************************************************************/
307 PROCEDURE InsertActionHist(
308 p_doc_id number,
309 p_doc_type varchar2,
310 p_doc_subtype varchar2,
311 p_employee_id number,
312 p_action varchar2,
313 p_note varchar2,
314 p_path_id number) is
315
316 pragma AUTONOMOUS_TRANSACTION;
317
318 l_action_code po_action_history.action_code%type;
319 l_revision_num number := NULL;
320 l_hist_count number := NULL;
321 l_sequence_num number := NULL;
322 l_approval_path_id number;
323
324 CURSOR action_hist_cursor(doc_id number , doc_type varchar2) is
325 select max(sequence_num)
326 from po_action_history
327 where object_id= doc_id and
328 object_type_code = doc_type;
329
330 CURSOR action_hist_code_cursor (doc_id number , doc_type varchar2, seq_num number) is
331 select action_code
332 from po_action_history
333 where object_id = doc_id and
334 object_type_code = doc_type and
335 sequence_num = seq_num;
336
337
338 x_progress varchar2(3):='000';
339
340 BEGIN
341
342 /* Get the document authorization status.
343 ** has been submitted before, i.e.
344 ** First insert a row with a SUBMIT action.
345 ** Then insert a row with a NULL ACTION_CODE to simulate the forward-to
346 */
347
348 x_progress := '001';
349
350 l_approval_path_id := p_path_id;
351
352 IF p_doc_type IN ('PO','PA') THEN
353
354 x_progress := '003';
355
356 select revision_num
357 into l_revision_num
358 from PO_HEADERS_ALL
359 where po_header_id = p_doc_id;
360
361 ELSIF p_doc_type = 'RELEASE' THEN
362
363 x_progress := '004';
364
365 select revision_num
366 into l_revision_num
367 from PO_RELEASES_ALL
368 where po_release_id = p_doc_id;
369
370 END IF;
371
372 x_progress := '005';
373
374 /* Check if this document had been submitted to workflow at some point
375 ** and somehow kicked out. If that's the case, the sequence number
376 ** needs to be incremented by one. Otherwise start at zero.
377 */
378 OPEN action_hist_cursor(p_doc_id , p_doc_type );
379 FETCH action_hist_cursor into l_sequence_num;
380 CLOSE action_hist_cursor;
381 IF l_sequence_num is NULL THEN
382 l_sequence_num := 0;
383 ELSE
384 OPEN action_hist_code_cursor(p_doc_id , p_doc_type, l_sequence_num);
385 FETCH action_hist_code_cursor into l_action_code;
386 l_sequence_num := l_sequence_num +1;
387 END IF;
388
389
390 x_progress := '006';
391 IF ((l_sequence_num = 0)
392 OR
393 (l_sequence_num > 0 and l_action_code is NOT NULL)) THEN
394 x_progress := '007';
395 INSERT into PO_ACTION_HISTORY
396 (object_id,
397 object_type_code,
398 object_sub_type_code,
399 sequence_num,
400 last_update_date,
401 last_updated_by,
402 creation_date,
403 created_by,
404 action_code,
405 action_date,
406 employee_id,
407 note,
408 object_revision_num,
409 last_update_login,
410 request_id,
411 program_application_id,
412 program_id,
413 program_update_date,
414 approval_path_id,
415 offline_code)
416 VALUES
417 (p_doc_id,
418 p_doc_type,
419 p_doc_subtype,
420 l_sequence_num,
421 sysdate,
422 nvl(fnd_global.user_id, 1),
423 sysdate,
424 nvl(fnd_global.user_id, 1),
425 p_action,
426 decode(p_action, '',to_date(null,'DD/MM/YYYY'), sysdate),
427 p_employee_id,
428 p_note,
429 l_revision_num,
430 nvl(fnd_global.login_id, 1),
431 0,
432 0,
433 0,
434 '',
435 l_approval_path_id,
436 '' );
437 x_progress := '008';
438
439 ELSE
440 l_sequence_num := l_sequence_num - 1;
441 x_progress := '009';
442 UPDATE PO_ACTION_HISTORY
443 set object_id = p_doc_id,
444 object_type_code = p_doc_type,
445 object_sub_type_code = p_doc_subtype,
446 sequence_num = l_sequence_num,
447 last_update_date = sysdate,
448 last_updated_by = nvl(fnd_global.user_id, 1),
449 creation_date = sysdate,
450 created_by = nvl(fnd_global.user_id, 1),
451 action_code = p_action,
452 action_date = decode(p_action, '',to_date(null,'DD/MM/YYYY'), sysdate),
453 employee_id = p_employee_id,
454 note = p_note,
455 object_revision_num = l_revision_num,
456 last_update_login = nvl(fnd_global.login_id, 1),
457 request_id = 0,
458 program_application_id = 0,
459 program_id = 0,
460 program_update_date = '',
461 approval_path_id = l_approval_path_id,
462 offline_code = ''
463 WHERE
464 object_id= p_doc_id and
465 object_type_code = p_doc_type and
466 sequence_num = l_sequence_num;
467
468 x_progress := '010';
469 END IF;
470 x_progress := '017';
471
472 commit;
473 EXCEPTION
474 WHEN OTHERS THEN
475 wf_core.context('PO_ChangeOrderWF_PVT',
476 'InsertActionHist'||sqlerrm,x_progress);
477 raise;
478
479 END InsertActionHist;
480
481
482 PROCEDURE Update_Chg_Req_If_Po_Apprvd(p_header_id number ,
483 p_release_id number)
484 IS
485 PRAGMA AUTONOMOUS_TRANSACTION;
486 l_api_name varchar2(50) :='Update_Chg_Req_If_Po_Apprvd';
487 Begin
488
489 IF (p_release_id is not null) THEN
490 update po_releases_all
491 set change_requested_by = null
492 where po_release_id = p_release_id;
493 ELSE
494 update po_headers_all
495 set change_requested_by = null
496 where po_header_id = p_header_id;
497 END IF;
498
499 commit;
500 exception when others then
501 IF g_fnd_debug = 'Y' AND FND_LOG.LEVEL_UNEXPECTED >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
502 FND_LOG.string(FND_LOG.level_unexpected, g_module_prefix ||
503 l_api_name || '.others_exception',sqlerrm);
504 END IF;
505 End Update_Chg_Req_If_Po_Apprvd;
506
507 /**
508 * Private procedure: Carry_Over_Acknowledgement
509 * Requires: PO_HEADER_ID, PO_RELEASE_ID, REVISION_NUM,
510 * Effects: Carry over the shipment_level acknowledgement results from the
511 * previous revision, it is called before launching PO approval
512 * workflow after supplier's change has been accepted by buyer.
513 * Returns:
514 * x_return_status - FND_API.G_RET_STS_SUCCESS if all messages are appended
515 * FND_API.G_RET_STS_ERROR if an error occurs
516 * FND_API.G_RET_STS_UNEXP_ERROR if unexpected error occurs
517 *
518 * Bugs Fixed:
519 * 7205793 - Added internal procedure, which is an autonomous transaction
520 * to avoid deadlock during PO Approval Process.
521 */
522
523 PROCEDURE Carry_Over_Acknowledgement( x_return_status OUT NOCOPY VARCHAR2,
524 p_po_header_id IN NUMBER,
525 p_po_release_id IN NUMBER,
526 p_revision_num IN NUMBER )
527 IS
528 PRAGMA AUTONOMOUS_TRANSACTION;
529 l_api_name varchar2(50) :='Carry_Over_Acknowledgement';
530 l_carryover_exception exception;
531 Begin
532 IF g_fnd_debug = 'Y' AND FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
533 FND_LOG.string(FND_LOG.LEVEL_PROCEDURE, g_module_prefix || l_api_name || '.invoked','Autonomous Transaction');
534 END IF;
535
536 PO_ACKNOWLEDGE_PO_GRP.carry_over_acknowledgement(1.0,
537 FND_API.G_FALSE,
538 x_return_status,
539 p_po_header_id,
540 p_po_release_id,
541 p_revision_num);
542 if(x_return_status <> FND_API.G_RET_STS_SUCCESS) then
543 raise l_carryover_exception;
544 end if;
545 commit;
546 exception when others then
547 IF g_fnd_debug = 'Y' AND FND_LOG.LEVEL_UNEXPECTED >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
548 FND_LOG.string(FND_LOG.level_unexpected, g_module_prefix || l_api_name || '.others_exception',sqlerrm);
549 END IF;
550 RAISE;
551 End Carry_Over_Acknowledgement;
552
553 PROCEDURE Commit_CancelPO(
554 x_return_status out NOCOPY varchar2,
555 p_can_doc_type in varchar2,
556 p_can_doc_subtype in varchar2,
557 p_can_hdr_id in number,
558 p_can_rel_id in number,
559 p_can_line_id in number,
560 p_can_line_loc_id in number,
561 p_can_reason in varchar2,
562 p_can_req_flag in varchar2,
563 p_launch_approvals_flag IN VARCHAR2 --Bug 13114334
564 )
565 IS
566 pragma AUTONOMOUS_TRANSACTION;
567 l_api_name varchar2(50):= 'Commit_CancelPO';
568 l_cancel_flag varchar2(1);
569 BEGIN
570
571 -- start of fix for bug 3864512
572 -- update status of buyer approved cancel shipment requests to a special status WAIT_CANCEL_APP
573
574 update po_change_requests
575 set request_status = 'WAIT_CANCEL_APP'
576 where request_status = 'BUYER_APP'
577 and action_type = 'CANCELLATION'
578 and request_level = 'SHIPMENT'
579 and document_line_location_id = p_can_line_loc_id;
580
581 -- end of fix for bug 3864512
582
583
584 --Commiting Status to "APPOVED".
585 if(p_can_rel_id is null) then
586 update po_headers_all
587 set authorization_status = 'APPROVED'
588 where po_header_id = p_can_hdr_id;
589 else
590 update po_releases_all
591 set authorization_status = 'APPROVED'
592 where po_release_id = p_can_rel_id;
593 end if;
594 commit;
595 PO_Document_Control_GRP.control_document
596 (p_api_version => 1.0,
597 p_init_msg_list => FND_API.G_TRUE,
598 p_commit => FND_API.G_TRUE,
599 x_return_status => x_return_status,
600 p_doc_type => p_can_doc_type,
601 p_doc_subtype => p_can_doc_subtype,
602 p_doc_id => p_can_hdr_id,
603 p_doc_num => null,
604 p_release_id => p_can_rel_id,
605 p_release_num => null,
606 p_doc_line_id => p_can_line_id,
607 p_doc_line_num => null,
608 p_doc_line_loc_id => p_can_line_loc_id ,
609 p_doc_shipment_num => null,
610 p_source => null,
611 p_action => 'CANCEL',
612 p_action_date => sysdate,
613 p_cancel_reason => p_can_reason,
614 p_cancel_reqs_flag => p_can_req_flag,
615 p_print_flag => 'N',
616 p_note_to_vendor =>null,
617 p_launch_approvals_flag => p_launch_approvals_flag --Bug 13114334
618 );
619 --Restoring PO's Authorization status back to "IN PROCESS".
620 if(p_can_rel_id is null) then
621 if(p_can_line_loc_id is null) then
622 select cancel_flag into l_cancel_flag
623 from po_headers_all
624 where po_header_id = p_can_hdr_id;
625 else
626 select cancel_flag into l_cancel_flag
627 from po_line_locations_all
628 where line_location_id = p_can_line_loc_id;
629 end if;
630 update po_headers_all
631 set authorization_status = 'IN PROCESS'
632 where po_header_id = p_can_hdr_id;
633 else
634 if(p_can_line_loc_id is null) then
635 select cancel_flag into l_cancel_flag
636 from po_releases_all
637 where po_release_id = p_can_rel_id;
638 else
639 select cancel_flag into l_cancel_flag
640 from po_line_locations_all
641 where line_location_id = p_can_line_loc_id;
642 end if;
643
644 update po_releases_all
645 set authorization_status = 'IN PROCESS'
646 where po_release_id = p_can_rel_id;
647 end if;
648 commit;
649
650 if(l_cancel_flag = 'Y') then
651 x_return_status := FND_API.G_RET_STS_SUCCESS;
652 end if;
653
654 exception when others then
655 IF g_fnd_debug = 'Y' AND FND_LOG.LEVEL_UNEXPECTED >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
656 FND_LOG.string(FND_LOG.level_unexpected, g_module_prefix ||
657 l_api_name || '.others_exception', sqlerrm);
658 END IF;
659 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
660 --Restoring PO's Authorization status back to "IN PROCESS".
661 if(p_can_rel_id is null) then
662 update po_headers_all
663 set authorization_status = 'IN PROCESS'
664 where po_header_id = p_can_hdr_id;
665 else
666 update po_releases_all
667 set authorization_status = 'IN PROCESS'
668 where po_release_id = p_can_rel_id;
669 end if;
670 commit;
671
672 end Commit_CancelPO;
673
674
675 /*
676 *This API is called by ProcessResponse, to process Cancellation Requests approved by the Buyer.
677 *This API needs to be an autonomous transaction because of the following reason:
678 *The moment when this API is called, the PO authorization status should be "IN PROCESS". However, in order to
679 *call PO Cancel API, the autho status needs to be commited to "APPROVED". Thus this API
680 *commits the status to "APPROVED", afterwhich commits it back to "IN PROCESS".
681 */
682 procedure CancelPO( x_return_status out NOCOPY varchar2,
683 p_header_id in number,
684 p_release_id in number,
685 p_chg_req_grp_id in number)
686 is
687 l_api_name varchar2(50) := 'CancelPO';
688 l_can_req_id number;
689 l_can_hdr_id number;
690 l_can_rel_id number;
691 l_can_line_id number;
692 l_can_line_loc_id number;
693 l_can_reason po_change_requests.request_reason%TYPE;
694 l_cancel_backing_req po_change_requests.cancel_backing_req%TYPE;
695 l_can_doc_type po_document_types_all.document_type_code%TYPE;
696 l_can_doc_subtype po_document_types_all.document_subtype%TYPE;
697 l_type_lookup_code po_headers_all.type_lookup_code%TYPE;
698 l_return_status varchar2(1);
699 x_progress varchar2(3);
700 l_ship_can_err_msg varchar2(2000) := fnd_message.get_string('PO','PO_CHN_CAN_SHIP_ERR');
701 l_hdr_can_err_msg varchar2(2000) := fnd_message.get_string('PO','PO_CHN_CAN_HDR_ERR');
702 /* Code changes for bug 13114334 - Start */
703 l_cancel_count number;
704 l_cancel_index number;
705 l_launch_approvals_flag varchar2(1) := 'N';
706 /* Code changes for bug 13114334 - End */
707 cursor l_cancel_ship_csr(grp_id number) is
708 select
709 change_request_id,
710 document_header_id,
711 po_release_id,
712 document_line_id,
713 document_line_location_id,
714 request_reason,
715 document_type,
716 cancel_backing_req
717 from po_change_requests
718 where change_request_group_id = grp_id
719 and action_type = 'CANCELLATION'
720 and request_level = 'SHIPMENT'
721 and request_status = 'BUYER_APP';
722
723 cursor l_cancel_hdr_csr(grp_id number) is
724 select
725 change_request_id,
726 document_header_id,
727 po_release_id,
728 request_reason
729 ,document_type
730 from po_change_requests
731 where change_request_group_id = grp_id
732 and action_type = 'CANCELLATION'
733 and request_level = 'HEADER'
734 and request_status = 'BUYER_APP';
735
736 begin
737 x_return_status := FND_API.G_RET_STS_SUCCESS;
738 /* Code changes for bug 13114334 - Start */
739 select count(*) into l_cancel_count
740 from po_change_requests
741 where change_request_group_id=p_chg_req_grp_id
742 and request_status='BUYER_APP'
743 and request_level = 'SHIPMENT'
744 and action_type='CANCELLATION';
745 l_cancel_index := 0;
746 /* Code changes for bug 13114334 - End */
747
748 --Calling PO Cancel API to process Shipment level Cancellation approved by the buyer.
749 open l_cancel_ship_csr(p_chg_req_grp_id);
750 loop
751 fetch l_cancel_ship_csr into
752 l_can_req_id,
753 l_can_hdr_id,
754 l_can_rel_id,
755 l_can_line_id,
756 l_can_line_loc_id,
757 l_can_reason,
758 l_can_doc_type,
759 l_cancel_backing_req;
760 exit when l_cancel_ship_csr%NOTFOUND;
761
762 if (l_cancel_backing_req <> 'Y') then
763 l_cancel_backing_req := 'N';
764 end if;
765
766 /* Code changes for bug 13114334 - Start */
767 l_cancel_index := l_cancel_index + 1;
768 if(l_cancel_index = l_cancel_count ) then
769 l_launch_approvals_flag := 'Y';
770 end if;
771 /* Code changes for bug 13114334 - End */
772
773 select type_lookup_code
774 into l_type_lookup_code
775 from po_headers_all
776 where po_header_id = l_can_hdr_id;
777 if(l_can_rel_id is null) then
778 l_can_doc_type := 'PO';
779 if(l_type_lookup_code = 'STANDARD') then
780 l_can_doc_subtype := 'STANDARD';
781 elsif(l_type_lookup_code = 'PLANNED') then
782 l_can_doc_subtype := 'PLANNED';
783 elsif(l_type_lookup_code = 'BLANKET') then
784 l_can_doc_type := 'PA';
785 l_can_doc_subtype := 'BLANKET';
786 else
787 l_can_doc_subtype := 'ERROR';
788 end if;
789
790 else
791 l_can_doc_type := 'RELEASE';
792 l_can_line_id := null;
793 if(l_type_lookup_code = 'BLANKET') then
794 l_can_doc_subtype := 'BLANKET';
795 elsif(l_type_lookup_code = 'PLANNED') then
796 l_can_doc_subtype := 'SCHEDULED';
797 else
798 l_can_doc_subtype := 'ERROR';
799 end if;
800
801 end if;
802
803 Commit_CancelPO(
804 l_return_status,
805 l_can_doc_type,
806 l_can_doc_subtype,
807 l_can_hdr_id,
808 l_can_rel_id,
809 l_can_line_id,
810 l_can_line_loc_id,
811 l_can_reason,
812 l_cancel_backing_req,
813 l_launch_approvals_flag --bug 13114334
814 );
815
816 --If PO Cancel API fails, we'll assume buyer has rejected the cancellation request
817 if(l_return_status <> 'S') then
818 x_return_status := FND_API.G_RET_STS_ERROR;
819 update po_change_requests
820 set request_status = 'REJECTED',
821 response_reason = l_ship_can_err_msg,
822 validation_error = l_ship_can_err_msg
823 -- change_active_flag = 'N' /* commented out due to bug 3574114 */
824 where change_request_id = l_can_req_id;
825 end if;
826 end loop;
827 close l_cancel_ship_csr;
828 x_progress:='003';
829
830 --Calling PO Cancel API to process Header level Cancellation approved by the buyer.
831 open l_cancel_hdr_csr(p_chg_req_grp_id);
832 loop
833 fetch l_cancel_hdr_csr into
834 l_can_req_id,
835 l_can_hdr_id,
836 l_can_rel_id,
837 l_can_reason,
838 l_can_doc_type;
839 exit when l_cancel_hdr_csr%NOTFOUND;
840 select type_lookup_code
841 into l_type_lookup_code
842 from po_headers_all
843 where po_header_id = l_can_hdr_id;
844 if(l_can_rel_id is null) then
845 l_can_doc_type := 'PO';
846 if(l_type_lookup_code = 'STANDARD') then
847 l_can_doc_subtype := 'STANDARD';
848 elsif(l_type_lookup_code = 'PLANNED') then
849 l_can_doc_subtype := 'PLANNED';
850 elsif(l_type_lookup_code = 'BLANKET') then
851 l_can_doc_type := 'PA';
852 l_can_doc_subtype := 'BLANKET';
853 elsif(l_type_lookup_code = 'CONTRACT') then
854 l_can_doc_type := 'PA';
855 l_can_doc_subtype := 'CONTRACT';
856 else
857 l_can_doc_subtype := 'ERROR';
858 end if;
859
860 else
861 l_can_doc_type := 'RELEASE';
862 if(l_type_lookup_code = 'BLANKET') then
863 l_can_doc_subtype := 'BLANKET';
864 elsif(l_type_lookup_code = 'PLANNED') then
865 l_can_doc_subtype := 'SCHEDULED';
866 else
867 l_can_doc_subtype := 'ERROR';
868 end if;
869
870 end if;
871
872 Commit_CancelPO(
873 l_return_status,
874 l_can_doc_type,
875 l_can_doc_subtype,
876 l_can_hdr_id,
877 l_can_rel_id,
878 null,
879 null,
880 l_can_reason,
881 'N',
882 'Y' --bug 13114334
883 );
884
885 --If PO Cancel API fails, we'll assume buyer has rejected the cancellation request
886 if(l_return_status <> 'S') then
887 x_return_status := FND_API.G_RET_STS_ERROR;
888 update po_change_requests
889 set request_status = 'REJECTED' ,
890 response_reason = l_hdr_can_err_msg,
891 validation_error = l_hdr_can_err_msg,
892 change_active_flag = 'N'
893 where change_request_id = l_can_req_id;
894 end if;
895 end loop;
896 close l_cancel_hdr_csr;
897
898 exception when others then
899 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
900 IF g_fnd_debug = 'Y' AND FND_LOG.LEVEL_UNEXPECTED >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
901 FND_LOG.string(FND_LOG.level_unexpected, g_module_prefix ||
902 l_api_name || '.others_exception', sqlerrm);
903 END IF;
904 end CancelPO;
905
906 /*
907 *taken from PO_REQAPPROVAL_INIT1, because it had the procedure as a PRIVATE procedure
908 *This API is used by Register_rejection
909 */
910 Procedure Insert_Acc_Rejection_Row(p_itemtype in varchar2,
911 p_itemkey in varchar2,
912 p_actid in number,
913 p_flag in varchar2)
914 is
915 l_api_name varchar2(50) := 'Insert_Acc_Rejection_Row';
916 l_Acceptance_id number;
917 -- Bug 2850566
918 l_rowid ROWID;
919 l_Last_Update_Login PO_ACCEPTANCES.last_update_login%TYPE;
920 l_acc_po_header_id PO_HEADERS_ALL.po_header_id%TYPE;
921 -- End of Bug 2850566
922 l_Last_Update_Date date;
923 l_Last_Updated_By number;
924 l_Creation_Date date := TRUNC(SYSDATE);
925 l_Created_By number := fnd_global.user_id;
926 l_Po_Header_Id number;
927 l_Po_Release_Id number;
928 l_Action varchar2(240) := 'NEW';
929 l_Action_Date date := TRUNC(SYSDATE);
930 l_Employee_Id number;
931 l_Revision_Num number;
932 l_Accepted_Flag varchar2(1) := p_flag;
933 -- l_Acceptance_Lookup_Code varchar2(25);
934 l_document_id number;
935 l_document_type_code po_document_types_all.DOCUMENT_TYPE_CODE%TYPE;
936 l_acceptance_note PO_ACCEPTANCES.note%TYPE; --bug 2178922
937 l_rspndr_usr_name fnd_user.user_name%TYPE := '';
938 l_accepting_party varchar2(1);
939 begin
940
941 SELECT po_acceptances_s.nextval into l_Acceptance_id FROM sys.dual;
942
943 -- commented out the usage of accptance_type (FPI)
944 /*
945 l_Acceptance_Lookup_Code := wf_engine.GetItemAttrText( itemtype => p_itemtype,
946 itemkey => p_itemkey,
947 aname => 'ACCEPTANCE_LOOKUP_CODE');
948 */
949
950 l_acceptance_note := PO_WF_UTIL_PKG.GetItemAttrText( itemtype => p_itemtype,
951 itemkey => p_itemkey,
952 aname => 'ACCEPTANCE_COMMENTS');
953
954 -- commented out the usage of accptance_type (FPI)
955 /*
956 if (l_Acceptance_Lookup_Code is NULL) then
957 if p_flag = 'Y' then
958 l_Acceptance_Lookup_Code := 'Accepted Terms';
959 else
960 l_Acceptance_Lookup_Code := 'Unacceptable Changes';
961 end if;
962 end if;
963 */
964
965 l_document_id := wf_engine.GetItemAttrNumber ( itemtype => p_itemtype,
966 itemkey => p_itemkey,
967 aname => 'DOCUMENT_ID');
968
969 l_document_type_code := wf_engine.GetItemAttrText ( itemtype => p_itemtype,
970 itemkey => p_itemkey,
971 aname => 'DOCUMENT_TYPE');
972
973 -- abort any outstanding acceptance notifications for any previous revision of the document.
974
975 if l_document_type_code <> 'RELEASE' then
976 l_Po_Header_Id := l_document_id;
977
978 select
979 revision_num,
980 agent_id
981 into
982 l_revision_num,
983 l_employee_id
984 from po_headers
985 where po_header_id = l_document_id;
986 else
987 l_Po_Release_Id := l_document_id;
988
989 select
990 po_header_id,
991 revision_num,
992 agent_id
993 into
994 l_Po_Header_Id,
995 l_revision_num,
996 l_employee_id
997 from po_releases
998 where po_release_id = l_document_id;
999 end if;
1000
1001 -- Bug 2850566 RBAIRRAJ
1002 -- Calling the Acceptances row handler to insert into the PO_ACCEPTANCES table
1003 -- instead of writing an Insert statement.
1004
1005 IF l_po_release_id IS NULL THEN
1006 l_acc_po_header_id := l_po_header_id;
1007 ELSE
1008 l_acc_po_header_id := NULL;
1009 END IF;
1010
1011 l_rspndr_usr_name := wf_engine.GetItemAttrText ( itemtype => p_itemtype,
1012 itemkey => p_itemkey,
1013 aname => 'SUPPLIER_USER_NAME');
1014
1015 begin
1016 select user_id into l_Last_Updated_By
1017 from fnd_user
1018 where user_name = upper(l_rspndr_usr_name);
1019 l_accepting_party := 'S';
1020 exception when others then
1021 --in case of non-isp users there wont be any suppliers
1022 l_Last_Updated_By := l_Created_By;
1023 l_accepting_party := 'S'; --ack is always by the supplier.
1024 end;
1025 l_Last_Update_Login := l_Last_Updated_By;
1026
1027
1028 PO_ACCEPTANCES_INS_PVT.insert_row(
1029 x_rowid => l_rowid,
1030 x_acceptance_id => l_Acceptance_id,
1031 x_Last_Update_Date => l_Last_Update_Date,
1032 x_Last_Updated_By => l_Last_Updated_By,
1033 x_Last_Update_Login => l_Last_Update_Login,
1034 p_creation_date => l_Creation_Date,
1035 p_created_by => l_Last_Updated_By,
1036 p_po_header_id => l_acc_po_header_id,
1037 p_po_release_id => l_Po_Release_Id,
1038 p_action => l_Action,
1039 p_action_date => l_Action_Date,
1040 p_employee_id => NULL,
1041 p_revision_num => l_Revision_Num,
1042 p_accepted_flag => l_Accepted_Flag,
1043 p_note => l_acceptance_note,
1044 p_accepting_party => l_accepting_party
1045 );
1046
1047 -- End of Bug 2850566 RBAIRRAJ
1048
1049 -- Reset the Acceptance required Flag
1050 --Bug 6772960 - Start
1051 --Update the last update date when po_headers_all/po_releases_all tables are updated.
1052 if l_po_release_id is not null then
1053 update po_releases
1054 set acceptance_required_flag = 'N',
1055 LAST_UPDATE_DATE = SYSDATE,
1056 acceptance_due_date = ''
1057 where po_release_id = l_po_release_id;
1058 else
1059 update po_headers
1060 set acceptance_required_flag = 'N',
1061 LAST_UPDATE_DATE = SYSDATE,
1062 acceptance_due_date = ''
1063 where po_header_id = l_po_header_id;
1064 end if;
1065 --Bug 6772960 - End
1066
1067 exception
1068 when others then
1069 IF g_fnd_debug = 'Y' AND FND_LOG.LEVEL_UNEXPECTED >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
1070 FND_LOG.string(FND_LOG.level_unexpected, g_module_prefix ||
1071 l_api_name || '.others_exception', sqlerrm);
1072 END IF;
1073 raise;
1074 end;
1075
1076 /*
1077 *taken from PO_REQAPPROVAL_INIT1
1078 *PO_REQAPPROVAL_INIT1.Register_rejection will be updated to support older version of poxwfpoa.wft
1079 *In other words, initial version of poxwfpoa.wft only calls PO_REQ_APPROVAL_INIT1.Register_rejection.
1080 *New version will call PO_ChangeOrderWF_PVT.IS_PO_HDR_REJECTED followed by PO_ChangeOrderWF_PVT.Register_rejection.
1081 *In order for older version of workflow to have the new functionality, PO_REQ_APPROVAL_INIT1.Register_rejection will
1082 *need to include the logic of PO_ChangeOrderWF_PVT.IS_PO_HDR_REJECTED within.
1083 */
1084 procedure Register_rejection ( itemtype in varchar2,
1085 itemkey in varchar2,
1086 actid in number,
1087 funcmode in varchar2,
1088 result out NOCOPY varchar2 )
1089 is
1090 l_api_name varchar2(50):= 'Register_rejection';
1091 l_progress varchar2(3) := '000';
1092 l_acceptance_result varchar2(30);
1093 l_org_id number;
1094 l_document_id number;
1095 l_document_type_code po_document_types_all.DOCUMENT_TYPE_CODE%TYPE;
1096 l_vendor po_vendors.vendor_name%TYPE;
1097 --l_accp_type varchar2(100);
1098 x_supp_user_name varchar2(100);
1099 x_supplier_displayname varchar2(100);
1100 l_nid number;
1101 l_ntf_role_name varchar2(320);
1102 begin
1103
1104 -- set the org context
1105 l_org_id := wf_engine.GetItemAttrNumber ( itemtype => itemtype,
1106 itemkey => itemkey,
1107 aname => 'ORG_ID');
1108
1109 PO_MOAC_UTILS_PVT.set_org_context(l_org_id) ; -- <R12 MOAC>
1110
1111 fnd_message.set_name ('PO','PO_WF_REJECTED_VALUE');
1112 l_acceptance_result := fnd_message.get;
1113
1114 l_document_id := wf_engine.GetItemAttrNumber ( itemtype => itemtype,
1115 itemkey => itemkey,
1116 aname => 'DOCUMENT_ID');
1117
1118 l_document_type_code := wf_engine.GetItemAttrText ( itemtype => itemtype,
1119 itemkey => itemkey,
1120 aname => 'DOCUMENT_TYPE');
1121
1122 -- commented out the usage of accptance_type (FPI)
1123 /*
1124 l_accp_type := PO_WF_UTIL_PKG.GetItemAttrText(itemtype => itemtype,
1125 itemkey => itemkey,
1126 aname => 'ACCEPTANCE_TYPE');
1127 */
1128
1129 l_acceptance_result := PO_WF_UTIL_PKG.GetItemAttrText(itemtype => itemtype,
1130 itemkey => itemkey,
1131 aname => 'ACCEPTANCE_RESULT');
1132
1133 if l_document_type_code <> 'RELEASE' then
1134 select pov.vendor_name
1135 into l_vendor
1136 from
1137 po_vendors pov,
1138 po_headers poh
1139 where pov.vendor_id = poh.vendor_id
1140 and poh.po_header_id=l_document_id;
1141 else
1142 select pov.vendor_name
1143 into l_vendor
1144 from
1145 po_releases por,
1146 po_headers_all poh, -- <R12 MOAC>
1147 po_vendors pov
1148 where por.po_release_id = l_document_id
1149 and por.po_header_id = poh.po_header_id
1150 and poh.vendor_id = pov.vendor_id;
1151 end if;
1152
1153
1154
1155 PO_WF_UTIL_PKG.SetItemAttrText ( itemtype => itemtype,
1156 itemkey => itemkey,
1157 aname => 'SUPPLIER',
1158 avalue => l_vendor);
1159
1160 -- commented out the usage of accptance_type (FPI)
1161 /*
1162 IF (l_accp_type is NULL) THEN
1163 PO_WF_UTIL_PKG.SetItemAttrText ( itemtype => itemtype,
1164 itemkey => itemkey,
1165 aname => 'ACCEPTANCE_TYPE',
1166 avalue => 'Rejected' );
1167 END IF;
1168 */
1169
1170 IF (l_acceptance_result is NULL) THEN
1171 PO_WF_UTIL_PKG.SetItemAttrText ( itemtype => itemtype,
1172 itemkey => itemkey,
1173 aname => 'ACCEPTANCE_RESULT',
1174 avalue => fnd_message.get_string('PO','PO_WF_NOTIF_REJ') );
1175 END IF;
1176
1177 if (l_document_type_code <> 'RELEASE') then
1178
1179 --dbms_output.put_line('For std pos');
1180 begin
1181 select a.notification_id, a.recipient_role
1182 INTO l_nid, l_ntf_role_name
1183 from wf_notifications a,
1184 wf_item_activity_statuses wa
1185 where itemkey=wa.item_key
1186 and itemtype=wa.item_type
1187 and a.message_name in ('PO_EMAIL_PO_WITH_RESPONSE', 'PO_EMAIL_PO_PDF_WITH_RESPONSE')
1188 and a.notification_id=wa.notification_id and a.status = 'CLOSED';
1189 exception
1190 when others then l_nid := null;
1191 end;
1192
1193 else
1194 begin
1195 --dbms_output.put_line('For Releases');
1196 select a.notification_id, a.recipient_role
1197 INTO l_nid, l_ntf_role_name
1198 from wf_notifications a,
1199 wf_item_activity_statuses wa
1200 where itemkey=wa.item_key
1201 and itemtype=wa.item_type
1202 and a.message_name in ('PO_EMAIL_PO_WITH_RESPONSE', 'PO_EMAIL_PO_PDF_WITH_RESPONSE')
1203 and a.notification_id=wa.notification_id and a.status = 'CLOSED';
1204 exception
1205 when others then l_nid := null;
1206 end;
1207 end if;
1208
1209 if (l_nid is null) then
1210 --we do not want to continue if the notification is not closed.
1211 return;
1212 else
1213 x_supp_user_name := wf_notification.responder(l_nid);
1214 end if;
1215
1216 if (substr(x_supp_user_name, 1, 6) = 'email:') then
1217 --Get the username and store that in the supplier_user_name.
1218 x_supp_user_name := PO_ChangeOrderWF_PVT.getEmailResponderUserName
1219 (x_supp_user_name, l_ntf_role_name);
1220
1221
1222 end if;
1223 PO_WF_UTIL_PKG.SetItemAttrText (itemtype => itemtype,
1224 itemkey => itemkey,
1225 aname => 'SUPPLIER_USER_NAME',
1226 avalue => x_supp_user_name);
1227
1228
1229
1230 Insert_Acc_Rejection_Row(itemtype, itemkey, actid, 'N');
1231
1232 EXCEPTION
1233 WHEN OTHERS THEN
1234 IF g_fnd_debug = 'Y' AND FND_LOG.LEVEL_UNEXPECTED >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
1235 FND_LOG.string(FND_LOG.level_unexpected, g_module_prefix ||
1236 l_api_name || '.others_exception', sqlerrm);
1237 END IF;
1238 wf_core.context('PO_ChangeOrderWF_PVT','Register_rejection',l_progress);
1239 raise;
1240 end;
1241
1242 /*
1243 *Kicks of POAPPRV workflow for supplier change or for requester change.
1244 */
1245 procedure KickOffPOApproval( p_api_version in number,
1246 x_return_status out NOCOPY varchar2,
1247 p_header_id in number,
1248 p_release_id in number,
1249 x_return_msg out NOCOPY varchar2)
1250 IS
1251 l_api_name varchar2(50) := 'KickOffPOApproval';
1252 l_org_id number;
1253 l_agent_id number;
1254 l_document_id number;
1255 l_document_num po_headers_all.segment1%TYPE;
1256 l_document_type_code po_document_types_all.DOCUMENT_TYPE_CODE%TYPE;
1257 l_document_subtype po_document_types_all.DOCUMENT_SUBTYPE%TYPE;
1258 l_seq number;
1259 l_item_key po_headers_all.wf_item_key%TYPE;
1260 l_item_type po_headers_all.wf_item_type%TYPE;
1261 l_workflow_process PO_DOCUMENT_TYPES_V.WF_APPROVAL_PROCESS%TYPE;
1262
1263 /* Bug 2810156 BEGIN*/
1264 l_orig_itemtype po_headers.wf_item_type%TYPE;
1265 l_orig_itemkey po_headers.wf_item_key%TYPE;
1266 l_user_id number;
1267 l_resp_id number;
1268 l_appl_id number;
1269 /* Bug 2810156 END */
1270
1271 /* BUG 5228026: Added the l_CommunicatePriceChange variable */
1272 l_CommunicatePriceChange varchar2(1) := 'N';
1273
1274 --<BUG 7688032 START>
1275 l_email_address po_vendor_sites_all.email_address%TYPE;
1276 l_email_flag VARCHAR2(1) := 'N';
1277 l_fax_flag VARCHAR2(1) := 'N';
1278 l_faxnum po_vendor_contacts.fax%TYPE;
1279 l_fax_area po_vendor_sites_all.fax_area_code%TYPE;
1280 l_preparer_id NUMBER;
1281 l_default_method po_vendor_sites_all.supplier_notif_method%TYPE;
1282 l_doc_num po_headers_all.segment1%TYPE;
1283 l_print_flag VARCHAR2(1) := 'N';
1284 --<BUG 7688032 END>
1285
1286 BEGIN
1287
1288 if p_release_id is not null then
1289 -- shipment for a release
1290 l_document_id := p_release_id;
1291 select por.release_type,
1292 por.org_id ,
1293 poh.segment1,
1294 por.agent_id
1295 into l_Document_SubType,
1296 l_org_id,
1297 l_document_num,
1298 l_agent_id
1299 from po_releases_all por,
1300 po_headers_all poh
1301 where po_release_id = p_release_id
1302 and por.po_header_id=poh.po_header_id;
1303
1304 l_Document_Type_Code := 'RELEASE';
1305
1306 else
1307 l_document_id := p_header_id;
1308 select
1309 poh.segment1,
1310 poh.agent_id,
1311 poh.type_lookup_code,
1312 poh.org_id
1313 into
1314 l_document_num,
1315 l_agent_id,
1316 l_document_subtype,
1317 l_org_id
1318 from po_headers_all poh
1319 where
1320 poh.po_header_id = p_header_id;
1321
1322 if l_Document_SubType in ('BLANKET', 'CONTRACT') then
1323 l_Document_Type_Code := 'PA';
1324 else
1325 l_Document_Type_Code := 'PO';
1326 end if;
1327 end if;
1328
1329 x_return_msg:='001';
1330
1331 /* Bug 2810156 BEGIN
1332 Call apps_initialze using IDs stored in the original PO approval workflow.
1333 */
1334
1335 BEGIN
1336 if (NVL(l_Document_Type_Code, 'PO') <> 'RELEASE') then
1337 select wf_item_type, wf_item_key
1338 into l_orig_itemtype, l_orig_itemkey
1339 from po_headers_all
1340 where po_header_id = l_document_id;
1341 else
1342 select wf_item_type, wf_item_key
1343 into l_orig_itemtype, l_orig_itemkey
1344 from po_releases_all
1345 where po_release_id = l_document_id;
1346 end if;
1347
1348 EXCEPTION
1349 WHEN NO_DATA_FOUND THEN
1350 l_orig_itemtype := null;
1351 l_orig_itemkey := null;
1352 END;
1353
1354 if (l_orig_itemtype is not null and l_orig_itemkey is not null) then
1355
1356 l_user_id := PO_WF_UTIL_PKG.GetItemAttrNumber(itemtype => l_orig_itemtype,
1357 itemkey => l_orig_itemkey,
1358 aname => 'USER_ID');
1359
1360 l_resp_id := PO_WF_UTIL_PKG.GetItemAttrNumber(itemtype => l_orig_itemtype,
1361 itemkey => l_orig_itemkey,
1362 aname => 'RESPONSIBILITY_ID');
1363
1364 l_appl_id := PO_WF_UTIL_PKG.GetItemAttrNumber(itemtype => l_orig_itemtype,
1365 itemkey => l_orig_itemkey,
1366 aname => 'APPLICATION_ID');
1367
1368 if (l_user_id is not null and
1369 l_resp_id is not null and
1370 l_appl_id is not null )then
1371
1372 fnd_global.APPS_INITIALIZE(l_user_id, l_resp_id, l_appl_id);
1373
1374 else
1375
1376 initialize (l_agent_id, l_org_id);
1377
1378 end if;
1379
1380 end if;
1381
1382 x_return_msg:='002';
1383
1384 if (l_org_id is NOT NULL) then
1385 PO_MOAC_UTILS_PVT.set_org_context(l_org_id) ; -- <R12 MOAC>
1386 end if;
1387
1388 /* Bug 2810156 END */
1389
1390
1391 x_return_msg:='003';
1392
1393 select
1394 wf_approval_itemtype,
1395 wf_approval_process
1396 into
1397 l_Item_Type,
1398 l_Workflow_Process
1399 from PO_DOCUMENT_TYPES_V
1400 where DOCUMENT_TYPE_CODE = l_Document_Type_Code
1401 and DOCUMENT_SUBTYPE = l_Document_Subtype;
1402
1403 select to_char(PO_WF_ITEMKEY_S.NEXTVAL) into l_seq from sys.dual;
1404 l_Item_Key := to_char(l_Document_ID) || '-' || l_seq;
1405
1406
1407
1408 x_return_msg:='004';
1409 IF g_fnd_debug = 'Y' AND FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
1410 FND_LOG.string(FND_LOG.level_procedure, g_module_prefix ||
1411 l_api_name || '.start_wf_process', l_Item_Type||'*'||l_Item_Key);
1412 END IF;
1413
1414 --<BUG 7688032 START>
1415 --Added the following code to fetch the default transmission
1416 --method of the supplier and setting the corresponding flags accordingly.
1417 PO_VENDOR_SITES_SV.Get_Transmission_Defaults(p_document_id => l_document_id,
1418 p_document_type => l_Document_Type_Code,
1419 p_document_subtype => l_document_subtype,
1420 p_preparer_id => l_preparer_id,
1421 x_default_method => l_default_method,
1422 x_email_address => l_email_address,
1423 x_fax_number => l_faxnum,
1424 x_document_num => l_doc_num );
1425
1426 IF (l_default_method = 'EMAIL' ) AND (l_email_address IS NOT NULL) THEN
1427 l_email_flag := 'Y';
1428 ELSIF (l_default_method = 'FAX') AND (l_faxnum IS NOT NULL) THEN
1429 l_email_address := NULL;
1430 l_faxnum := l_fax_area || l_faxnum;
1431 l_fax_flag := 'Y';
1432 ELSIF l_default_method = 'PRINT' THEN
1433 l_email_address := NULL;
1434 l_faxnum := NULL;
1435 l_print_flag := 'Y';
1436 ELSE
1437 l_email_address := null;
1438 l_faxnum := null;
1439 END IF;
1440 --<BUG 7688032 END>
1441
1442 IF( (l_Document_Type_Code = 'RELEASE' AND l_Document_Subtype = 'BLANKET') OR (l_Document_Type_Code = 'PO' AND l_Document_Subtype = 'STANDARD') ) THEN
1443 l_CommunicatePriceChange := 'Y';
1444 END IF;
1445 --<BUG 7688032 Passing the transmission flags to the Start_WF_Process
1446 --so that the change request flow transmit the changes done to the PO
1447 --to the supplier in their default transmission method.
1448 PO_REQAPPROVAL_INIT1.Start_WF_Process(
1449 ItemType => l_Item_Type,
1450 ItemKey => l_Item_Key,
1451 WorkflowProcess => l_workflow_process,
1452 ActionOriginatedFrom => 'POS_SUP_CHN',
1453 DocumentID => l_document_id,
1454 DocumentNumber => l_document_num,
1455 preparerid => l_agent_id,
1456 DocumentTypeCode => l_Document_Type_Code,
1457 DocumentSubtype => l_Document_Subtype,
1458 SubmitterAction => 'APPROVE',
1459 forwardToID => null,
1460 forwardFromID => null,
1461 DefaultApprovalPathID => null,
1462 Note => '',
1463 printFlag => l_print_flag,
1464 FaxFlag => l_fax_flag,
1465 FaxNumber => l_faxnum,
1466 EmailFlag => l_email_flag,
1467 EmailAddress => l_email_address,
1468 CommunicatePriceChange => l_CommunicatePriceChange);
1469 x_return_msg:='005';
1470 x_return_status := FND_API.G_RET_STS_SUCCESS;
1471 exception when others then
1472 x_return_msg:='KO_U'||x_return_msg||sqlerrm;
1473 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1474 IF g_fnd_debug = 'Y' AND FND_LOG.LEVEL_UNEXPECTED >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
1475 FND_LOG.string(FND_LOG.level_unexpected, g_module_prefix ||
1476 l_api_name || '.others_exception', x_return_msg);
1477 END IF;
1478
1479 END KickOffPOApproval;
1480
1481
1482 /*
1483 *Called from POAPPRV workflow, to execute IsPOHeaderRejected
1484 */
1485 procedure IS_PO_HDR_REJECTED( itemtype in varchar2,
1486 itemkey in varchar2,
1487 actid in number,
1488 funcmode in varchar2,
1489 resultout out NOCOPY varchar2)
1490 IS
1491 l_document_id number;
1492 l_document_type_code po_document_types_all.DOCUMENT_TYPE_CODE%TYPE;
1493 l_revision_num number;
1494 x_progress varchar2(3) := '000';
1495 l_return_status varchar2(1);
1496 BEGIN
1497 l_document_id := wf_engine.GetItemAttrNumber ( itemtype => itemtype,
1498 itemkey => itemkey,
1499 aname => 'DOCUMENT_ID');
1500
1501 l_document_type_code := wf_engine.GetItemAttrText ( itemtype => itemtype,
1502 itemkey => itemkey,
1503 aname => 'DOCUMENT_TYPE');
1504 x_progress := '001';
1505 if (l_document_type_code <> 'RELEASE') then
1506 select revision_num
1507 into l_revision_num
1508 from po_headers_all
1509 where po_header_id = l_document_id;
1510 IsPOHeaderRejected(
1511 1.0,
1512 l_return_status,
1513 l_document_id,
1514 null,
1515 l_revision_num,
1516 resultout);
1517 else
1518 select revision_num
1519 into l_revision_num
1520 from po_releases_all
1521 where po_release_id = l_document_id;
1522 IsPOHeaderRejected(
1523 1.0,
1524 l_return_status,
1525 null,
1526 l_document_id,
1527 l_revision_num,
1528 resultout);
1529 end if;
1530 exception when others then
1531 wf_core.context('PO_ChangeOrderWF_PVT','IS_PO_HDR_REJECTED',x_progress);
1532 raise;
1533 END IS_PO_HDR_REJECTED;
1534
1535 /*
1536 *Checks if Supplier has rejected the PO (which requires acknowledgement) at the Header Level.
1537 *Explaination: When a PO (which requires ACK) is created, it holds at the node which awaits supplier to respond.
1538 *If supplier rejects the header level via notification or UI, this node will be awaken, and this API shall return "Y".
1539 *On the other hand, supplier could respond to the PO at the shipment level, and this node will be awaken with
1540 *action = "REJECT", even though there is no rejection. Thus this API will return "N".
1541 */
1542 procedure IsPOHeaderRejected( p_api_version in number,
1543 x_return_status out NOCOPY varchar2,
1544 p_header_id in number,
1545 p_release_id in number,
1546 p_revision_num in number,
1547 x_result_code out NOCOPY varchar)
1548 IS
1549 l_id number;
1550
1551 cursor l_header_csr(hdr_id number, rev_num number) is
1552 select change_request_id
1553 from po_change_requests
1554 where document_header_id = hdr_id
1555 and document_revision_num = rev_num
1556 and request_status = 'PENDING'
1557 and initiator = 'SUPPLIER'
1558 union all
1559 select acceptance_id
1560 from po_acceptances
1561 where po_header_id = hdr_id
1562 and revision_num = rev_num
1563 and po_line_location_id is not null;
1564
1565 cursor l_release_csr(rel_id number,rev_num number) is
1566 select change_request_id
1567 from po_change_requests
1568 where po_release_id = rel_id
1569 and document_revision_num = rev_num
1570 and request_status = 'PENDING'
1571 and initiator = 'SUPPLIER'
1572 union all
1573 select acceptance_id
1574 from po_acceptances
1575 where po_release_id = rel_id
1576 and revision_num = rev_num
1577 and po_line_location_id is not null;
1578
1579 BEGIN
1580 x_result_code := 'Y';
1581 -- If any Pending records exist in PO_CHANGE_REQUESTS table, that means the PO is not really header rejected
1582 if(p_header_id is not null) then
1583 open l_header_csr(p_header_id, p_revision_num);
1584 fetch l_header_csr into l_id;
1585 close l_header_csr;
1586 if(l_id is not null) then
1587 x_result_code := 'N';
1588 end if;
1589 else
1590 open l_release_csr(p_release_id, p_revision_num);
1591 fetch l_release_csr into l_id;
1592 close l_release_csr;
1593 if(l_id is not null) then
1594 x_result_code := 'N';
1595 end if;
1596 end if;
1597 exception when others then
1598 wf_core.context('PO_ChangeOrderWF_PVT','IsPOHeaderRejected','000');
1599 raise;
1600 END IsPOHeaderRejected;
1601
1602 PROCEDURE GEN_NTF_FOR_REQ_SUP_CHN( p_code IN varchar2,
1603 display_type in Varchar2,
1604 document in out NOCOPY clob,
1605 document_type in out NOCOPY varchar2)
1606 IS
1607 l_header_id number;
1608 l_release_id number;
1609 l_grp_id number;
1610 l_requester_id number;
1611 l_api_name varchar2(50) := 'GEN_NTF_FOR_REQ_SUP_CHN';
1612
1613 l_progress varchar2(5) := '000';
1614
1615 l_rel_total number;
1616 l_rel_currency po_headers.currency_code%TYPE;
1617 --l_blanket_num number;
1618 l_blanket_num po_headers_all.segment1%TYPE;
1619 --l_release_num number;
1620 l_release_num po_releases_all.release_num%TYPE;
1621 l_po_doc_id number;
1622 l_rel_doc_id number;
1623 l_acc_req_flag varchar2(1);
1624 l_document varchar2(32000);
1625 l_type_lookup_code po_headers_all.type_lookup_code%TYPE;
1626 l_document_type varchar2(2000);
1627 l_po_num po_headers_all.segment1%TYPE;
1628 l_revision_num number;
1629 l_po_total number;
1630 l_po_currency po_headers.currency_code%TYPE;
1631 l_vendor_id number;
1632 l_vendor_site_id number;
1633 l_supplier_name po_vendors.vendor_name%TYPE;
1634 l_sup_address_line1 po_vendor_sites_all.address_line1%TYPE;
1635 l_sup_address_line2 po_vendor_sites_all.address_line2%TYPE;
1636 l_sup_address_line3 po_vendor_sites_all.address_line3%TYPE;
1637 l_sup_city po_vendor_sites_all.city%TYPE;
1638 l_sup_state po_vendor_sites_all.state%TYPE;
1639 l_sup_zip po_vendor_sites_all.zip%TYPE;
1640 l_order_date varchar2(2000);
1641 l_fob po_headers_all.fob_lookup_code%TYPE;
1642 l_carrier po_headers_all.ship_via_lookup_code%TYPE;
1643 l_ship_to_id number;
1644 l_ship_addr_l1 hr_locations_all.address_line_1%TYPE;
1645 l_ship_addr_l2 hr_locations_all.address_line_2%TYPE;
1646 l_ship_addr_l3 hr_locations_all.address_line_3%TYPE;
1647 l_ship_city hr_locations_all.town_or_city%TYPE;
1648 l_ship_state hr_locations_all.region_1%TYPE;
1649 l_ship_zip hr_locations_all.postal_code%TYPE;
1650 l_base_url varchar2(2000);
1651 l_base_url_tag varchar2(2000);
1652
1653 l_document1 VARCHAR2(32000) := '';
1654
1655 /*varchar Variables for creating the notification*/
1656 lc_line_num varchar2(2000);
1657 lc_ship_num varchar2(2000);
1658 lc_buyer_pt_num mtl_system_items_kfv.concatenated_segments%TYPE;
1659 lc_old_sup_pt_num po_lines_all.vendor_product_num%TYPE;
1660 lc_new_sup_pt_num po_change_requests.new_supplier_part_number%TYPE;
1661 lc_old_prom_date varchar2(2000);
1662 lc_new_prom_date varchar2(2000);
1663 lc_old_qty varchar2(2000);
1664 lc_new_qty varchar2(2000);
1665 lc_old_price varchar2(2000);
1666 lc_new_price varchar2(2000);
1667 lc_action_type varchar2(2000);
1668 lc_item_desc po_lines_all.item_description%TYPE;
1669 lc_uom po_lines_all.unit_meas_lookup_code%TYPE;
1670 lc_ship_to_location hr_locations_all.location_code%TYPE;
1671 lc_action_code po_change_requests.ACTION_TYPE%TYPE;
1672 lc_reason po_change_requests.request_reason%TYPE;
1673 lc_split varchar2(2000);
1674 l_global_agreement_flag po_headers_all.GLOBAL_AGREEMENT_FLAG%TYPE := 'F';
1675 /*Modified as part of bug 7550964 changing date format*/
1676 cursor l_po_chg_req_csr(grp_id number, l_requestor_id number) is
1677 select
1678 to_char(LINE_NUM),
1679 to_char(SHIPMENT_NUM),
1680 BUYER_PT_NUM,
1681 OLD_SUP_PT_NUM,
1682 NEW_SUP_PT_NUM,
1683 to_char(OLD_PROM_DATE,FND_PROFILE.VALUE_SPECIFIC('ICX_DATE_FORMAT_MASK', fnd_global.user_id),
1684 'NLS_CALENDAR = ''' || NVL( FND_PROFILE.VALUE_SPECIFIC('FND_FORMS_USER_CALENDAR', fnd_global.user_id) ,'GREGORIAN' ) || ''''),
1685 to_char(NEW_PROM_DATE, FND_PROFILE.VALUE_SPECIFIC('ICX_DATE_FORMAT_MASK', fnd_global.user_id),
1686 'NLS_CALENDAR = ''' || NVL( FND_PROFILE.VALUE_SPECIFIC('FND_FORMS_USER_CALENDAR', fnd_global.user_id) ,'GREGORIAN' ) || ''''),
1687 to_char(OLD_QTY),
1688 to_char(NEW_QTY),
1689 to_char(OLD_PRICE),
1690 to_char(NEW_PRICE),
1691 ACTION_TYPE,
1692 ITEM_DESCRIPTION,
1693 UOM,
1694 SHIP_TO_LOCATION,
1695 ACTION_CODE,
1696 REASON,
1697 SPLIT
1698 from(
1699
1700 -- LINE CHANGES for Standard PO
1701 select
1702 pcr.document_line_number LINE_NUM,
1703 pcr.document_shipment_number SHIPMENT_NUM,
1704 msi.concatenated_segments BUYER_PT_NUM,
1705 pla.vendor_product_num OLD_SUP_PT_NUM,
1706 pcr.new_supplier_part_number NEW_SUP_PT_NUM,
1707 to_date(null,'DD/MM/YYYY') OLD_PROM_DATE,
1708 to_date(null,'DD/MM/YYYY') NEW_PROM_DATE,
1709 pla.quantity OLD_QTY,
1710 to_number(null) NEW_QTY,
1711 pla.unit_price OLD_PRICE,
1712 pcr.new_price NEW_PRICE,
1713 decode(pcr.ACTION_TYPE,'MODIFICATION',fnd_message.get_string('PO','PO_WF_NOTIF_CHANGE'),
1714 'CANCELLATION',fnd_message.get_string('PO','PO_WF_NOTIF_CANCEL'),'Error') ACTION_TYPE,
1715 pla.item_description ITEM_DESCRIPTION,
1716 pla.unit_meas_lookup_code UOM,
1717 null SHIP_TO_LOCATION,
1718 pcr.ACTION_TYPE ACTION_CODE,
1719 pcr.request_reason REASON,
1720 null SPLIT
1721 from
1722 po_change_requests pcr,
1723 po_lines_archive_all pla,
1724 mtl_system_items_kfv msi,
1725 FINANCIALS_SYSTEM_PARAMS_ALL FSP
1726 where pla.po_line_id = pcr.document_line_id
1727 and pcr.change_request_group_id =grp_id
1728 and pcr.request_level = 'LINE'
1729 and pcr.request_status in ('PENDING','REQ_APP')
1730 and pla.latest_external_flag = 'Y'
1731 and msi.inventory_item_id(+) = pla.item_id
1732 --and msi.organization_id(+) = pla.org_id
1733 and NVL(MSI.ORGANIZATION_ID, FSP.INVENTORY_ORGANIZATION_ID) = FSP.INVENTORY_ORGANIZATION_ID
1734 AND FSP.ORG_ID = PLA.ORG_ID
1735 and exists (select 1 from po_distributions_all
1736 where po_line_id = pcr.document_line_id
1737 and deliver_to_person_id = l_requestor_id)
1738 UNION ALL
1739
1740 -- SHIPMENT CHANGES for Standard PO and Releases
1741 select
1742 pla.line_num LINE_NUM,
1743 pcr.document_shipment_number SHIPMENT_NUM,
1744 msi.concatenated_segments BUYER_PT_NUM,
1745 pla.vendor_product_num OLD_SUP_PT_NUM,
1746 null NEW_SUP_PT_NUM,
1747 nvl(pcr.old_promised_date, nvl(plla.promised_date,plla.need_by_date)) OLD_PROM_DATE,
1748 pcr.new_promised_date NEW_PROM_DATE,
1749 plla.quantity OLD_QTY,
1750 pcr.new_quantity NEW_QTY,
1751 decode(pla.matching_basis,'AMOUNT',DECODE(plla.payment_type,'RATE',nvl(pcr.old_price,plla.price_override),nvl(pcr.old_amount,plla.amount)),nvl(pcr.old_price,plla.price_override)) OLD_PRICE,
1752 decode(pla.matching_basis,'AMOUNT',DECODE(plla.payment_type,'RATE',pcr.new_price,pcr.new_amount),pcr.new_price) NEW_PRICE,
1753 decode(pcr.ACTION_TYPE,'MODIFICATION',fnd_message.get_string('PO','PO_WF_NOTIF_CHANGE'),'CANCELLATION',
1754 fnd_message.get_string('PO','PO_WF_NOTIF_CANCEL'),'Error') ACTION_TYPE,
1755 pla.item_description ITEM_DESCRIPTION,
1756 nvl(plla.unit_meas_lookup_code,pla.unit_meas_lookup_code) UOM,
1757 nvl(hla.location_code, substr(rtrim(hz.address1)||'-'||rtrim(hz.city),1,60)) SHIP_TO_LOCATION,
1758 pcr.ACTION_TYPE ACTION_CODE,
1759 pcr.REQUEST_REASON REASON,
1760 null SPLIT
1761 from
1762 po_change_requests pcr,
1763 po_lines_archive_all pla,
1764 po_line_locations_archive_all plla,
1765 hr_locations_all hla, hz_locations hz,
1766 mtl_system_items_kfv msi,
1767 FINANCIALS_SYSTEM_PARAMS_ALL FSP
1768 where pcr.change_request_group_id =grp_id
1769 and pla.po_line_id = pcr.document_line_id
1770 and pla.latest_external_flag = 'Y'
1771 and plla.line_location_id = pcr.document_line_location_id
1772 and plla.latest_external_flag = 'Y'
1773 and request_level = 'SHIPMENT'
1774 and pcr.request_status in ('PENDING','REQ_APP')
1775 and hla.location_id(+) = plla.ship_to_location_id
1776 and plla.SHIP_TO_LOCATION_ID = hz.LOCATION_ID(+)
1777 and msi.inventory_item_id(+) = pla.item_id
1778 --and msi.organization_id(+) = pla.org_id
1779 and NVL(MSI.ORGANIZATION_ID, FSP.INVENTORY_ORGANIZATION_ID) = FSP.INVENTORY_ORGANIZATION_ID
1780 AND FSP.ORG_ID = PLA.ORG_ID
1781 and exists (select 1 from po_distributions_all
1782 where line_location_id = pcr.document_line_location_id
1783 and deliver_to_person_id = l_requestor_id)
1784 UNION ALL
1785
1786 --SPLIT SHIPMENTS
1787 select
1788 pla.line_num LINE_NUM,
1789 pcr.document_shipment_number SHIPMENT_NUM,
1790 msi.concatenated_segments BUYER_PT_NUM,
1791 pla.vendor_product_num OLD_SUP_PT_NUM,
1792 null NEW_SUP_PT_NUM,
1793 nvl(pcr.old_promised_date, nvl(plla.promised_date,plla.need_by_date)) OLD_PROM_DATE,
1794 pcr.new_promised_date NEW_PROM_DATE,
1795 plla.quantity OLD_QTY,
1796 pcr.new_quantity NEW_QTY,
1797 decode(pla.matching_basis,'AMOUNT',DECODE(nvl(pcr.new_progress_type,plla.payment_type),'RATE',nvl(pcr.new_price,plla.price_override),nvl(pcr.old_amount,plla.amount)),nvl(pcr.old_price,plla.price_override)) OLD_PRICE,
1798 decode(pla.matching_basis,'AMOUNT',DECODE(nvl(pcr.new_progress_type,plla.payment_type),'RATE',pcr.new_price,pcr.new_amount),pcr.new_price) NEW_PRICE,
1799 decode(pcr.ACTION_TYPE,'MODIFICATION',fnd_message.get_string('PO','PO_WF_NOTIF_CHANGE'),'CANCELLATION',
1800 fnd_message.get_string('PO','PO_WF_NOTIF_CANCEL'),'Error') ACTION_TYPE,
1801 pla.item_description ITEM_DESCRIPTION,
1802 nvl(plla.unit_meas_lookup_code,pla.unit_meas_lookup_code) UOM,
1803 nvl(hla.location_code, substr(rtrim(hz.address1)||'-'||rtrim(hz.city),1,60)) SHIP_TO_LOCATION,
1804 pcr.ACTION_TYPE ACTION_CODE,
1805 pcr.REQUEST_REASON REASON,
1806 fnd_message.get_string('PO','PO_WF_NOTIF_YES') SPLIT
1807 from
1808 po_change_requests pcr,
1809 po_lines_archive_all pla,
1810 po_line_locations_archive_all plla,
1811 hr_locations_all hla, hz_locations hz,
1812 mtl_system_items_kfv msi,
1813 FINANCIALS_SYSTEM_PARAMS_ALL FSP
1814 where pcr.change_request_group_id =grp_id
1815 and pla.po_line_id = pcr.document_line_id
1816 and pla.latest_external_flag = 'Y'
1817 and plla.line_location_id = pcr.parent_line_location_id
1818 and plla.latest_external_flag = 'Y'
1819 and request_level = 'SHIPMENT'
1820 and pcr.request_status in ('PENDING','REQ_APP')
1821 and hla.location_id(+) = plla.ship_to_location_id
1822 and plla.SHIP_TO_LOCATION_ID = hz.LOCATION_ID(+)
1823 and msi.inventory_item_id(+) = pla.item_id
1824 --and msi.organization_id(+) = pla.org_id
1825 and NVL(MSI.ORGANIZATION_ID, FSP.INVENTORY_ORGANIZATION_ID) = FSP.INVENTORY_ORGANIZATION_ID
1826 AND FSP.ORG_ID = PLA.ORG_ID
1827 and exists (select 1 from po_distributions_all
1828 where line_location_id = pcr.parent_line_location_id
1829 and deliver_to_person_id = l_requestor_id)
1830 )
1831 order by LINE_NUM,nvl(SHIPMENT_NUM,0);
1832
1833 l_id number;
1834 l_header_response po_change_requests.request_status%type;
1835 l_header_cancel varchar2(1);
1836 cursor l_header_cancel_csr(grp_id number) is
1837 select change_request_id,
1838 request_status
1839 from po_change_requests
1840 where change_request_group_id = grp_id
1841 and action_type = 'CANCELLATION'
1842 and request_level = 'HEADER';
1843
1844 l_additional_changes po_change_requests.additional_changes%type;
1845
1846 cursor l_header_changes_csr(grp_id number)
1847 is
1848 select additional_changes
1849 from po_change_requests
1850 where change_request_group_id = grp_id
1851 and request_level = 'HEADER'
1852 and additional_changes is not null;
1853
1854 BEGIN
1855 l_header_id := to_number(substr(p_code,2, instr(p_code,'#')-instr(p_code,'@')-1));
1856 l_release_id := to_number(substr(p_code,instr(p_code,'#')+1, instr(p_code,'$')-instr(p_code,'#')-1));
1857 l_grp_id := to_number(substr(p_code,instr(p_code,'$')+1, instr(p_code,'%')-instr(p_code,'$')-1));
1858 l_requester_id := substr(p_code,instr(p_code,'%')+1, instr(p_code,'^')-instr(p_code,'%')-1);
1859
1860 l_progress := '001';
1861 l_base_url := fnd_profile.value('APPS_WEB_AGENT');
1862 l_base_url := substr(
1863 l_base_url,
1864 0,
1865 instr(rtrim(l_base_url,'/'),'/',-1,2)-1
1866 );
1867 l_base_url_tag := '<base href= "'||l_base_url||'">';
1868 l_progress := '001a';
1869
1870 l_header_cancel := 'N';
1871 if(l_grp_id is not null) then
1872 open l_header_cancel_csr(l_grp_id);
1873 fetch l_header_cancel_csr
1874 into l_id,
1875 l_header_response;
1876 close l_header_cancel_csr;
1877 if(l_id is not null) then
1878 l_header_cancel := 'Y';
1879 end if;
1880 end if;
1881
1882 if(l_release_id is null) then
1883 /*Modified as part of bug 7550964 changing date format*/
1884
1885 select segment1,
1886 revision_num,
1887 pos_totals_po_sv.get_po_total(po_header_id),
1888 currency_code,
1889 vendor_id,
1890 vendor_site_id,
1891 to_char(creation_date, FND_PROFILE.VALUE_SPECIFIC('ICX_DATE_FORMAT_MASK', fnd_global.user_id),
1892 'NLS_CALENDAR = ''' || NVL( FND_PROFILE.VALUE_SPECIFIC('FND_FORMS_USER_CALENDAR', fnd_global.user_id) , 'GREGORIAN' ) || ''''),
1893 fob_lookup_code,
1894 ship_via_lookup_code,
1895 ship_to_location_id,
1896 type_lookup_code,
1897 GLOBAL_AGREEMENT_FLAG
1898 into
1899 l_po_num,
1900 l_revision_num,
1901 l_po_total,
1902 l_po_currency,
1903 l_vendor_id,
1904 l_vendor_site_id,
1905 l_order_date,
1906 l_fob,
1907 l_carrier,
1908 l_ship_to_id,
1909 l_type_lookup_code,
1910 l_global_agreement_flag
1911 from po_headers_all
1912 where po_header_id = l_header_id;
1913
1914 if(l_type_lookup_code = 'STANDARD') then
1915 l_document_type := fnd_message.get_string('PO','PO_WF_NOTIF_STD_PO');
1916 elsif(l_type_lookup_code = 'PLANNED') then
1917 l_document_type := fnd_message.get_string('PO','PO_WF_NOTIF_PLAN_PO');
1918 elsif (l_global_agreement_flag = 'Y' and l_type_lookup_code = 'BLANKET') then
1919 l_document_type := fnd_message.get_string('PO','PO_GA_TYPE');
1920 elsif(l_type_lookup_code = 'BLANKET') then
1921 l_document_type := fnd_message.get_string('PO','PO_WF_NOTIF_BLANKET');
1922 elsif(l_type_lookup_code = 'CONTRACT') then
1923 l_document_type := fnd_message.get_string('PO','PO_POTYPE_CNTR');
1924 else
1925 l_document_type := 'Error';
1926 end if;
1927
1928 else
1929
1930 select
1931 ph.segment1,
1932 pr.release_num,
1933 pr.revision_num,
1934 pos_totals_po_sv.get_release_total(pr.po_release_id),
1935 ph.currency_code,
1936 ph.vendor_id,
1937 ph.vendor_site_id,
1938 to_char(pr.creation_date,FND_PROFILE.VALUE_SPECIFIC('ICX_DATE_FORMAT_MASK', fnd_global.user_id),
1939 'NLS_CALENDAR = ''' || NVL( FND_PROFILE.VALUE_SPECIFIC('FND_FORMS_USER_CALENDAR', fnd_global.user_id) ,'GREGORIAN' ) || ''''),
1940 ph.fob_lookup_code,
1941 ph.ship_via_lookup_code,
1942 ph.ship_to_location_id,
1943 ph.type_lookup_code
1944 into
1945 l_blanket_num,
1946 l_release_num,
1947 l_revision_num,
1948 l_rel_total,
1949 l_rel_currency,
1950 l_vendor_id,
1951 l_vendor_site_id,
1952 l_order_date,
1953 l_fob,
1954 l_carrier,
1955 l_ship_to_id,
1956 l_type_lookup_code
1957 from po_releases_all pr,
1958 po_headers_all ph
1959 where pr.po_release_id = l_release_id
1960 and pr.po_header_id = ph.po_header_id;
1961 /*Modified as part of bug 7550964 changing date format*/
1962
1963 if(l_type_lookup_code = 'BLANKET') then
1964 l_document_type := fnd_message.get_string('PO','PO_WF_NOTIF_BKT_REL');
1965 elsif(l_type_lookup_code = 'PLANNED') then
1966 l_document_type := fnd_message.get_string('PO','PO_WF_NOTIF_SCH_REL');
1967 else
1968 l_document_type := 'Error';
1969 end if;
1970
1971 end if;
1972 l_progress := '002';
1973 select
1974 vendor_name
1975 into
1976 l_supplier_name
1977 from po_vendors
1978 where vendor_id = l_vendor_id;
1979
1980 select
1981 address_line1,
1982 address_line2,
1983 address_line3,
1984 city,
1985 state,
1986 zip
1987 into
1988 l_sup_address_line1,
1989 l_sup_address_line2,
1990 l_sup_address_line3,
1991 l_sup_city,
1992 l_sup_state,
1993 l_sup_zip
1994 from po_vendor_sites_all
1995 where vendor_site_id = l_vendor_site_id;
1996
1997 /* Shipto */
1998 select
1999 address_line_1,
2000 address_line_2,
2001 address_line_3,
2002 town_or_city,
2003 region_1,
2004 postal_code
2005 into
2006 l_ship_addr_l1,
2007 l_ship_addr_l2,
2008 l_ship_addr_l3,
2009 l_ship_city,
2010 l_ship_state,
2011 l_ship_zip
2012 from hr_locations_all
2013 where location_id = l_ship_to_id;
2014 l_progress := '003';
2015
2016 if(l_release_id is null) then
2017 l_document := l_base_url_tag||
2018 '
2019 <font size=3 color=#336699 face=arial><b>'||l_document_type||' '||l_po_num||' '||fnd_message.get_string('PO','PO_WF_NOTIF_REV')
2020 ||' '||l_revision_num||' ('||fnd_message.get_string('PO','PO_WF_NOTIF_TOTAL')||'('||
2021 l_po_currency||') '||
2022 TO_CHAR(l_po_total, FND_CURRENCY.GET_FORMAT_MASK(l_po_currency, 30))
2023 ||')</B></font><HR size=1 color=#cccc99>';
2024 else
2025 l_document := l_base_url_tag||
2026 '
2027 <font size=3 color=#336699 face=arial><b>'||l_document_type||' '||l_blanket_num||'-'||l_release_num||' '||fnd_message.get_string('PO','PO_WF_NOTIF_REV')||' '
2028 ||l_revision_num||' ('||fnd_message.get_string('PO','PO_WF_NOTIF_TOTAL')||'('||
2029 l_po_currency||') '||
2030 TO_CHAR(l_po_total, FND_CURRENCY.GET_FORMAT_MASK(l_po_currency, 30))
2031 ||')</B></font><HR size=1 color=#cccc99>';
2032 end if;
2033
2034 l_document := l_document||'
2035 <TABLE cellpadding=2 cellspacing=1>
2036 <TR>
2037 <TD>
2038 <TABLE cellpadding=2 cellspacing=1>
2039 <TR>
2040 <TD nowrap><font color=black><B>
2041 '||fnd_message.get_string('PO','PO_WF_NOTIF_VENDOR')||'</B></font></TD>
2042 <TD nowrap><font color=black>'||l_supplier_name||'</font></TD>
2043 </TR>
2044 <TR>
2045 <TD nowrap valign=TOP><font color=black><B>
2046 '||fnd_message.get_string('PO','PO_WF_NOTIF_ADDRESS')||'</B></font></TD>
2047 <TD nowrap><font color=black>';
2048
2049 if(l_sup_address_line1 is not null) then
2050 l_document := l_document || l_sup_address_line1||'<BR>';
2051 end if;
2052 if(l_sup_address_line2 is not null) then
2053 l_document := l_document || l_sup_address_line2||'<BR>';
2054 end if;
2055 if(l_sup_address_line3 is not null) then
2056 l_document := l_document || l_sup_address_line3||'<BR>';
2057 end if;
2058
2059 l_document := l_document||l_sup_city||', '||l_sup_state||' '||l_sup_zip||
2060 '</font></TD>
2061 </TR>
2062 <TR>
2063 <TD nowrap><font color=black><B>
2064 '||fnd_message.get_string('PO','PO_WF_NOTIF_FOB')||'</B></font></TD>
2065 <TD nowrap><font color=black>'||l_fob||
2066 '</font></TD>
2067 </TR>
2068
2069
2070 <TR>
2071 <TD nowrap><font color=black><B>
2072 '||fnd_message.get_string('PO','PO_WF_NOTIF_CARRIER')||'</B></font></TD>
2073 <TD nowrap><font color=black>'||l_carrier||
2074 '</font></TD>
2075 </TR>
2076 </TABLE>
2077 </TD>
2078 <TD valign=TOP>
2079 <TABLE cellpadding=2 cellspacing=1>
2080 <TR>
2081 <TD nowrap><font color=black><B>
2082 '||fnd_message.get_string('PO','PO_WF_NOTIF_ORDER_DATE')||'</B></font></TD>
2083 <TD nowrap><font color=black>'||l_order_date||
2084 '</font></TD>
2085 </TR>
2086
2087 <TR>
2088 <TD nowrap valign=TOP><font color=black><B>
2089 '||fnd_message.get_string('PO','PO_WF_NOTIF_SHPTO_ADD')||'</B></font></TD>
2090 <TD nowrap><font color=black>
2091 '||
2092 l_ship_addr_l1||' '||l_ship_addr_l2||' '||l_ship_addr_l3||'<BR>'||
2093 l_ship_city||', '||l_ship_state||' '||l_ship_zip
2094 ||'
2095 </font></TD>
2096 </TR>
2097
2098 </TABLE>
2099 </TD>
2100 </TABLE></P>';
2101 WF_NOTIFICATION.WriteToClob(document,l_document);
2102
2103
2104 lc_line_num := null;
2105 if(l_header_cancel = 'N') then
2106 open l_po_chg_req_csr(l_grp_id,l_requester_id);
2107 fetch l_po_chg_req_csr
2108 into
2109 lc_line_num,
2110 lc_ship_num,
2111 lc_buyer_pt_num,
2112 lc_old_sup_pt_num,
2113 lc_new_sup_pt_num,
2114 lc_old_prom_date,
2115 lc_new_prom_date,
2116 lc_old_qty,
2117 lc_new_qty,
2118 lc_old_price,
2119 lc_new_price,
2120 lc_action_type,
2121 lc_item_desc,
2122 lc_uom,
2123 lc_ship_to_location,
2124 lc_action_code,
2125 lc_reason,
2126 lc_split;
2127 close l_po_chg_req_csr;
2128 if(lc_line_num is not null) then
2129 l_document := '<font size=3 color=#336699 face=arial><b>'||
2130 fnd_message.get_string('PO', 'PO_WF_NOTIF_CH_CA_REQ')||
2131 '</B></font><HR size=1 color=#cccc99>';
2132 l_document := l_document||'<TABLE><TR>'|| NL;
2133 l_document:= l_document||'<TD class=instructiontext>'||
2134 '<img src=/OA_MEDIA/newupdateditem_status.gif ALT="">'
2135 || fnd_message.get_string('PO', 'PO_WF_NOTIF_NEW_VALUE');
2136 l_document := l_document || '</TD></TR>' || NL;
2137 l_document := l_document || '<TR>'|| NL;
2138 l_document:= l_document||'<TD class=instructiontext>'||
2139 '<img src=/OA_MEDIA/cancelind_status.gif ALT="">'
2140 || fnd_message.get_string('PO', 'PO_WF_NOTIF_CANCEL_PENDING');
2141 l_document := l_document || '</TD></TR>' || NL;
2142 l_document := l_document || '</TABLE>' || NL;
2143 l_document := l_document ||'
2144 <TABLE WIDTH=100% cellpadding=2 cellspacing=1>
2145 <TR bgcolor=#cccc99>
2146 <TH align=left><font color=#336699 >'||fnd_message.get_string('PO','PO_WF_NOTIF_LINE_NUMBER')||'</font></TH>
2147 <TH align=left><font color=#336699 >'||fnd_message.get_string('PO','PO_WF_NOTIF_SHIPMENT')||'</font></TH>
2148 <TH align=left><font color=#336699 >'||fnd_message.get_string('PO','PO_WF_NOTIF_ITEM')||'</font></TH>
2149 <TH align=left><font color=#336699 >'||fnd_message.get_string('PO','PO_WF_NOTIF_SUP_ITEM')||'</font></TH>
2150 <TH align=left><font color=#336699 >'||fnd_message.get_string('PO','PO_WF_NOTIF_DOC_DESCRIPTION')||'</font></TH>
2151 <TH align=left><font color=#336699 >'||fnd_message.get_string('PO','PO_WF_NOTIF_UNIT')||'</font></TH>';
2152 if (l_type_lookup_code = 'BLANKET') then
2153 l_document := l_document || ' <TH align=left><font color=#336699 >'||fnd_message.get_string('PO','POS_PRICE_BREAK')||'</font></TH>';
2154 else
2155 l_document := l_document || ' <TH align=left><font color=#336699 >'||fnd_message.get_string('PO','PO_WF_NOTIF_PRICE')||'</font></TH> ';
2156 end if;
2157 l_document := l_document ||
2158 '<TH align=left><font color=#336699 >'||fnd_message.get_string('PO','PO_WF_NOTIF_QTY_ORDERED')||'</font></TH>
2159 <TH align=left><font color=#336699 >'||fnd_message.get_string('PO','PO_WF_NOTIF_PROM_DATE')||'</font></TH>
2160 <TH align=left><font color=#336699 >'||fnd_message.get_string('PO','PO_WF_NOTIF_SHIPTO')||'</font></TH>
2161 <TH align=left><font color=#336699 >'||fnd_message.get_string('PO','PO_WF_NOTIF_ACTION')||'</font></TH>
2162 <TH align=left><font color=#336699 >'||fnd_message.get_string('PO','PO_WF_NOTIF_REASON')||'</font></TH>
2163 <TH align=left><font color=#336699 >'||fnd_message.get_string('PO','PO_WF_NOTIF_SPLIT')||'</font></TH>
2164 </TR>
2165 </B>';
2166
2167 WF_NOTIFICATION.WriteToClob(document,l_document);
2168
2169 open l_po_chg_req_csr(l_grp_id,l_requester_id);
2170 loop
2171 fetch l_po_chg_req_csr
2172 into
2173 lc_line_num,
2174 lc_ship_num,
2175 lc_buyer_pt_num,
2176 lc_old_sup_pt_num,
2177 lc_new_sup_pt_num,
2178 lc_old_prom_date,
2179 lc_new_prom_date,
2180 lc_old_qty,
2181 lc_new_qty,
2182 lc_old_price,
2183 lc_new_price,
2184 lc_action_type,
2185 lc_item_desc,
2186 lc_uom,
2187 lc_ship_to_location,
2188 lc_action_code,
2189 lc_reason,
2190 lc_split;
2191 EXIT when l_po_chg_req_csr%NOTFOUND;
2192
2193 if(lc_split is not null) then
2194 lc_old_sup_pt_num := nvl(lc_old_sup_pt_num,lc_new_sup_pt_num);
2195 lc_new_sup_pt_num := null;
2196
2197 lc_old_price:=nvl(lc_old_price,lc_new_price);
2198 lc_new_price:= null;
2199
2200 lc_new_prom_date:= nvl(lc_new_prom_date,lc_old_prom_date);
2201 lc_old_prom_date:= null;
2202
2203 lc_new_qty:=nvl(lc_new_qty,lc_old_qty);
2204 lc_old_qty:= null;
2205 end if;
2206
2207 lc_line_num := nvl(lc_line_num,'` ');
2208 lc_ship_num:= nvl(lc_ship_num,'` ');
2209 lc_buyer_pt_num:= nvl(lc_buyer_pt_num,'` ');
2210
2211 lc_old_sup_pt_num:= nvl(lc_old_sup_pt_num,'` ');
2212 lc_new_sup_pt_num:= nvl(lc_new_sup_pt_num,'` ');
2213
2214 lc_old_prom_date:= nvl(lc_old_prom_date,'` ');
2215 lc_new_prom_date:= nvl(lc_new_prom_date,'` ');
2216
2217 lc_old_qty:= nvl(lc_old_qty,'` ');
2218 lc_new_qty:= nvl(lc_new_qty,'` ');
2219
2220 lc_old_price:= nvl(lc_old_price,'` ');
2221 lc_new_price:= nvl(lc_new_price,'` ');
2222
2223 lc_action_type:= nvl(lc_action_type,'` ');
2224 lc_item_desc:= nvl(lc_item_desc,'` ');
2225 lc_uom:= nvl(lc_uom,'` ');
2226 lc_ship_to_location:= nvl(lc_ship_to_location,'` ');
2227 lc_reason := nvl(lc_reason,'` ');
2228 lc_split := nvl(lc_split,'` ');
2229
2230
2231 l_document := '
2232 <TR bgcolor=#f7f7e7>
2233
2234 <TD align=left><font color=black>'||lc_line_num||
2235 '</font></TD> ';
2236
2237 if(lc_action_code = 'CANCELLATION') then
2238 l_document := l_document ||'
2239 <TD align=left><font color=black>
2240 <TABLE>
2241 <TR>
2242 <TD>
2243 <img src=/OA_MEDIA/cancelind_status.gif ALT="">
2244 </TD>
2245 <TD alight=right>'
2246 ||lc_ship_num||
2247 '</TD>
2248 </TR>
2249 </TABLE>
2250 </font></TD> ';
2251 else
2252 l_document := l_document ||'
2253 <TD align=left><font color=black>'||lc_ship_num||
2254 '</font></TD> ';
2255 end if;
2256 l_document := l_document ||'
2257 <TD align=left><font color=black>'||lc_buyer_pt_num||
2258 '</font></TD> ';
2259
2260 if(lc_new_sup_pt_num = '` ') then
2261 l_document := l_document || '
2262 <TD align=left><font color=black>'||lc_old_sup_pt_num||'
2263 </font></TD>';
2264 else
2265 l_document := l_document || '
2266 <TD align=left><font color=black>
2267 <table>
2268 <tr>
2269 <td>'||lc_old_sup_pt_num||'
2270 </td>
2271 </tr>
2272 <tr>
2273 <td>'||lc_new_sup_pt_num||'
2274 </td>
2275 <td>
2276 <img src=/OA_MEDIA/newupdateditem_status.gif ALT="">
2277 </td>
2278 </tr>
2279 </table>
2280 </font></TD>';
2281 end if;
2282
2283 l_document := l_document || '
2284 <TD align=left><font color=black>'||lc_item_desc||
2285 '</font></TD>
2286
2287 <TD align=left><font color=black>'||lc_uom||
2288 '</font></TD> ';
2289
2290 if(lc_new_price = '` ') then
2291 l_document := l_document || '
2292 <TD align=left><font color=black>'||lc_old_price||'
2293 </font></TD>';
2294 else
2295 l_document := l_document || '
2296 <TD align=left><font color=black>
2297 <table>
2298 <tr>
2299 <td>'||lc_old_price||'
2300 </td>
2301 </tr>
2302 <tr>
2303 <td>'||lc_new_price||'
2304 </td>
2305 <td>
2306 <img src=/OA_MEDIA/newupdateditem_status.gif ALT="">
2307 </td>
2308 </tr>
2309 </table>
2310 </font></TD>';
2311 end if;
2312
2313 if(lc_new_qty = '` ') then
2314 l_document := l_document || '
2315 <TD align=left><font color=black>'||lc_old_qty||'
2316 </font></TD>';
2317 elsif(lc_split <> '` ') then
2318 l_document := l_document || '
2319 <TD align=left><font color=black>
2320 <table>
2321 <tr>
2322 <td>'||lc_new_qty||'
2323 </td>
2324 <td>
2325 <img src=/OA_MEDIA/newupdateditem_status.gif ALT="">
2326 </td>
2327 </tr>
2328 </table>
2329 </font></TD>';
2330 else
2331 l_document := l_document || '
2332 <TD align=left><font color=black>
2333 <table>
2334 <tr>
2335 <td>'||lc_old_qty||'
2336 </td>
2337 </tr>
2338 <tr>
2339 <td>'||lc_new_qty||'
2340 </td>
2341 <td>
2342 <img src=/OA_MEDIA/newupdateditem_status.gif ALT="">
2343 </td>
2344 </tr>
2345 </table>
2346 </font></TD>';
2347 end if;
2348
2349 if(lc_new_prom_date = '` ') then
2350 l_document := l_document || '
2351 <TD align=left><font color=black>'||lc_old_prom_date||'
2352 </font></TD>';
2353 elsif(lc_split <> '` ') then
2354 l_document := l_document || '
2355 <TD align=left><font color=black>
2356 <table>
2357 <tr>
2358 <td>'||lc_new_prom_date||'
2359 </td>
2360 <td>
2361 <img src=/OA_MEDIA/newupdateditem_status.gif ALT="">
2362 </td>
2363 </tr>
2364 </table>
2365 </font></TD>';
2366 else
2367 l_document := l_document || '
2368 <TD align=left><font color=black>
2369 <table>
2370 <tr>
2371 <td>'||lc_old_prom_date||'
2372 </td>
2373 </tr>
2374 <tr>
2375 <td>'||lc_new_prom_date||'
2376 </td>
2377 <td>
2378 <img src=/OA_MEDIA/newupdateditem_status.gif ALT="">
2379 </td>
2380 </tr>
2381 </table>
2382 </font></TD>';
2383 end if;
2384 l_document := l_document || '
2385
2386 <TD align=left><font color=black>'||lc_ship_to_location||
2387 '</font></TD>
2388
2389 <TD align=left><font color=black>'||lc_action_type||
2390 '</font></TD>
2391
2392 <TD align=left><font color=black>'||lc_reason||
2393 '</font></TD>
2394
2395 <TD align=left><font color=black>'||lc_split||
2396 '</font></TD>
2397
2398 </TR>
2399 ';
2400 WF_NOTIFICATION.WriteToClob(document,l_document);
2401
2402 END LOOP;
2403 CLOSE l_po_chg_req_csr;
2404 WF_NOTIFICATION.WriteToClob(document, '
2405 </TABLE></P>
2406 ');
2407
2408
2409 end if;
2410 open l_header_changes_csr(l_grp_id);
2411 fetch l_header_changes_csr into l_additional_changes;
2412 close l_header_changes_csr;
2413
2414 if(l_additional_changes is not null) then
2415 l_document := '<BR><B>'||fnd_message.get_string('PO','PO_WF_NOTIF_ADD_CHN_REQ')||'</B>'||
2416 ' `  '||l_additional_changes||'<BR>';
2417 WF_NOTIFICATION.WriteToClob(document,l_document);
2418 end if;
2419
2420 else
2421 fnd_message.set_name('PO','PO_WF_NOTIF_CAN_ENTIER');
2422 fnd_message.set_token('DOC',l_document_type);
2423 l_document := fnd_message.get;
2424 WF_NOTIFICATION.WriteToClob(document,l_document);
2425 end if;
2426 exception when others then
2427 WF_NOTIFICATION.WriteToClob(document,'Exception occured:'||sqlerrm);
2428 END GEN_NTF_FOR_REQ_SUP_CHN;
2429
2430
2431 PROCEDURE GEN_NTF_FOR_PLAN_SUP_CHN( p_code IN varchar2,
2432 display_type in Varchar2,
2433 document in out NOCOPY clob,
2434 document_type in out NOCOPY varchar2)
2435 IS
2436 l_header_id number;
2437 l_release_id number;
2438 l_grp_id number;
2439 l_planner_id number;
2440 l_api_name varchar2(50) := 'GEN_NTF_FOR_PLAN_SUP_CHN';
2441
2442 l_progress varchar2(5) := '000';
2443
2444 l_rel_total number;
2445 l_rel_currency po_headers.currency_code%TYPE;
2446 --l_blanket_num number;
2447 l_blanket_num po_headers_all.segment1%TYPE;
2448 --l_release_num number;
2449 l_release_num po_releases_all.release_num%TYPE;
2450 l_po_doc_id number;
2451 l_rel_doc_id number;
2452 l_acc_req_flag varchar2(1);
2453 l_document varchar2(32000);
2454 l_type_lookup_code po_headers_all.type_lookup_code%TYPE;
2455 l_document_type varchar2(2000);
2456 l_po_num po_headers_all.segment1%TYPE;
2457 l_revision_num number;
2458 l_po_total number;
2459 l_po_currency po_headers.currency_code%TYPE;
2460 l_vendor_id number;
2461 l_vendor_site_id number;
2462 l_supplier_name po_vendors.vendor_name%TYPE;
2463 l_sup_address_line1 po_vendor_sites_all.address_line1%TYPE;
2464 l_sup_address_line2 po_vendor_sites_all.address_line2%TYPE;
2465 l_sup_address_line3 po_vendor_sites_all.address_line3%TYPE;
2466 l_sup_city po_vendor_sites_all.city%TYPE;
2467 l_sup_state po_vendor_sites_all.state%TYPE;
2468 l_sup_zip po_vendor_sites_all.zip%TYPE;
2469 l_order_date varchar2(2000);
2470 l_fob po_headers_all.fob_lookup_code%TYPE;
2471 l_carrier po_headers_all.ship_via_lookup_code%TYPE;
2472 l_ship_to_id number;
2473 l_ship_addr_l1 hr_locations_all.address_line_1%TYPE;
2474 l_ship_addr_l2 hr_locations_all.address_line_2%TYPE;
2475 l_ship_addr_l3 hr_locations_all.address_line_3%TYPE;
2476 l_ship_city hr_locations_all.town_or_city%TYPE;
2477 l_ship_state hr_locations_all.region_1%TYPE;
2478 l_ship_zip hr_locations_all.postal_code%TYPE;
2479
2480 l_document1 VARCHAR2(32000) := '';
2481 l_base_url varchar2(2000);
2482 l_base_url_tag varchar2(2000);
2483
2484 /*varchar Variables for creating the notification*/
2485 lc_change_id number;
2486 lc_line_num varchar2(2000);
2487 lc_ship_num varchar2(2000);
2488 lc_buyer_pt_num mtl_system_items_kfv.concatenated_segments%TYPE;
2489 lc_old_sup_pt_num po_lines_all.vendor_product_num%TYPE;
2490 lc_new_sup_pt_num po_change_requests.new_supplier_part_number%TYPE;
2491 lc_old_prom_date varchar2(2000);
2492 lc_new_prom_date varchar2(2000);
2493 lc_old_qty varchar2(2000);
2494 lc_new_qty varchar2(2000);
2495 lc_old_price varchar2(2000);
2496 lc_new_price varchar2(2000);
2497 lc_action_type varchar2(2000);
2498 lc_item_desc po_lines_all.item_description%TYPE;
2499 lc_uom po_lines_all.unit_meas_lookup_code%TYPE;
2500 lc_ship_to_location hr_locations_all.location_code%TYPE;
2501 lc_action_code po_change_requests.ACTION_TYPE%TYPE;
2502 lc_reason po_change_requests.request_reason%TYPE;
2503 lc_split varchar2(2000);
2504 l_global_agreement_flag po_headers_all.GLOBAL_AGREEMENT_FLAG%TYPE := 'F';
2505 /*Modified as part of bug 7550964 changing date format*/
2506 cursor l_po_chg_req_csr(grp_id number, l_planner_id number) is
2507 select
2508 distinct
2509 CHANGE_ID,
2510 to_char(LINE_NUM),
2511 to_char(SHIPMENT_NUM),
2512 BUYER_PT_NUM,
2513 OLD_SUP_PT_NUM,
2514 NEW_SUP_PT_NUM,
2515 to_char(OLD_PROM_DATE, FND_PROFILE.VALUE_SPECIFIC('ICX_DATE_FORMAT_MASK', fnd_global.user_id),
2516 'NLS_CALENDAR = ''' || NVL( FND_PROFILE.VALUE_SPECIFIC('FND_FORMS_USER_CALENDAR', fnd_global.user_id) ,'GREGORIAN' ) || ''''),
2517 to_char(NEW_PROM_DATE, FND_PROFILE.VALUE_SPECIFIC('ICX_DATE_FORMAT_MASK', fnd_global.user_id),
2518 'NLS_CALENDAR = ''' || NVL( FND_PROFILE.VALUE_SPECIFIC('FND_FORMS_USER_CALENDAR', fnd_global.user_id) ,'GREGORIAN' ) || ''''),
2519 to_char(OLD_QTY),
2520 to_char(NEW_QTY),
2521 to_char(OLD_PRICE),
2522 to_char(NEW_PRICE),
2523 ACTION_TYPE,
2524 ITEM_DESCRIPTION,
2525 UOM,
2526 SHIP_TO_LOCATION,
2527 ACTION_CODE,
2528 REASON,
2529 SPLIT
2530 from(
2531
2532 -- LINE CHANGES for Standard PO
2533 select
2534 pcr.change_request_id CHANGE_ID,
2535 pcr.document_line_number LINE_NUM,
2536 pcr.document_shipment_number SHIPMENT_NUM,
2537 msi.concatenated_segments BUYER_PT_NUM,
2538 pla.vendor_product_num OLD_SUP_PT_NUM,
2539 pcr.new_supplier_part_number NEW_SUP_PT_NUM,
2540 to_date(null,'DD/MM/YYYY') OLD_PROM_DATE,
2541 to_date(null,'DD/MM/YYYY') NEW_PROM_DATE,
2542 pla.quantity OLD_QTY,
2543 to_number(null) NEW_QTY,
2544 pla.unit_price OLD_PRICE,
2545 pcr.new_price NEW_PRICE,
2546 decode(pcr.ACTION_TYPE,'MODIFICATION',fnd_message.get_string('PO','PO_WF_NOTIF_CHANGE'),
2547 'CANCELLATION',fnd_message.get_string('PO','PO_WF_NOTIF_CANCEL'),'Error') ACTION_TYPE,
2548 pla.item_description ITEM_DESCRIPTION,
2549 pla.unit_meas_lookup_code UOM,
2550 null SHIP_TO_LOCATION,
2551 pcr.ACTION_TYPE ACTION_CODE,
2552 pcr.request_reason REASON,
2553 null SPLIT
2554 from
2555 po_change_requests pcr,
2556 po_lines_archive_all pla,
2557 mtl_system_items_kfv msi,
2558 mtl_planners mtp,
2559 financials_system_params_all fsp
2560 where pla.po_line_id = pcr.document_line_id
2561 and pcr.change_request_group_id =grp_id
2562 and pcr.request_level = 'LINE'
2563 and pcr.request_status in ('PENDING','REQ_APP')
2564 and pla.latest_external_flag = 'Y'
2565 and msi.inventory_item_id(+) = pla.item_id
2566 --and msi.organization_id(+) = pla.org_id
2567 and fsp.org_id = pla.org_id
2568 and msi.organization_id = fsp.inventory_organization_id
2569 and msi.planner_code = mtp.planner_code
2570 and msi.organization_id = mtp.organization_id
2571 and mtp.employee_id = l_planner_id
2572 UNION ALL
2573
2574 -- SHIPMENT CHANGES for Standard PO and Releases
2575 select
2576 pcr.change_request_id CHANGE_ID,
2577 pla.line_num LINE_NUM,
2578 pcr.document_shipment_number SHIPMENT_NUM,
2579 msi.concatenated_segments BUYER_PT_NUM,
2580 pla.vendor_product_num OLD_SUP_PT_NUM,
2581 null NEW_SUP_PT_NUM,
2582 nvl(pcr.old_promised_date, nvl(plla.promised_date,plla.need_by_date)) OLD_PROM_DATE,
2583 pcr.new_promised_date NEW_PROM_DATE,
2584 plla.quantity OLD_QTY,
2585 pcr.new_quantity NEW_QTY,
2586 decode(pla.matching_basis,'AMOUNT',DECODE(plla.payment_type,'RATE',nvl(pcr.old_price,plla.price_override),nvl(pcr.old_amount,plla.amount)),nvl(pcr.old_price,plla.price_override)) OLD_PRICE,
2587 decode(pla.matching_basis,'AMOUNT',DECODE(plla.payment_type,'RATE',pcr.new_price,pcr.new_amount),pcr.new_price) NEW_PRICE,
2588 decode(pcr.ACTION_TYPE,'MODIFICATION',fnd_message.get_string('PO','PO_WF_NOTIF_CHANGE'),'CANCELLATION',
2589 fnd_message.get_string('PO','PO_WF_NOTIF_CANCEL'),'Error') ACTION_TYPE,
2590 pla.item_description ITEM_DESCRIPTION,
2591 nvl(plla.unit_meas_lookup_code,pla.unit_meas_lookup_code) UOM,
2592 nvl(hla.location_code, substr(rtrim(hz.address1)||'-'||rtrim(hz.city),1,60)) SHIP_TO_LOCATION,
2593 pcr.ACTION_TYPE ACTION_CODE,
2594 pcr.REQUEST_REASON REASON,
2595 null SPLIT
2596 from
2597 po_change_requests pcr,
2598 po_lines_archive_all pla,
2599 po_line_locations_archive_all plla,
2600 hr_locations_all hla, hz_locations hz,
2601 mtl_system_items_kfv msi,
2602 mtl_planners mtp,
2603 financials_system_params_all fsp
2604 where pcr.change_request_group_id =grp_id
2605 and pla.po_line_id = pcr.document_line_id
2606 and pla.latest_external_flag = 'Y'
2607 and plla.line_location_id = pcr.document_line_location_id
2608 and plla.latest_external_flag = 'Y'
2609 and request_level = 'SHIPMENT'
2610 and pcr.request_status in ('PENDING','REQ_APP')
2611 and hla.location_id(+) = plla.ship_to_location_id
2612 and plla.SHIP_TO_LOCATION_ID = hz.LOCATION_ID(+)
2613 and msi.inventory_item_id(+) = pla.item_id
2614 --and msi.organization_id(+) = pla.org_id
2615 and fsp.org_id = pla.org_id
2616 and msi.organization_id = fsp.inventory_organization_id
2617 and msi.planner_code = mtp.planner_code
2618 and msi.organization_id = mtp.organization_id
2619 and mtp.employee_id = l_planner_id
2620
2621 UNION ALL
2622
2623 --SPLIT SHIPMENTS
2624 select
2625 pcr.change_request_id CHANGE_ID,
2626 pla.line_num LINE_NUM,
2627 pcr.document_shipment_number SHIPMENT_NUM,
2628 msi.concatenated_segments BUYER_PT_NUM,
2629 pla.vendor_product_num OLD_SUP_PT_NUM,
2630 null NEW_SUP_PT_NUM,
2631 nvl(pcr.old_promised_date, nvl(plla.promised_date,plla.need_by_date)) OLD_PROM_DATE,
2632 pcr.new_promised_date NEW_PROM_DATE,
2633 plla.quantity OLD_QTY,
2634 pcr.new_quantity NEW_QTY,
2635 decode(pla.matching_basis,'AMOUNT',DECODE(nvl(pcr.new_progress_type,plla.payment_type),'RATE',nvl(pcr.new_price,plla.price_override),nvl(pcr.old_amount,plla.amount)),nvl(pcr.old_price,plla.price_override)) OLD_PRICE,
2636 decode(pla.matching_basis,'AMOUNT',DECODE(nvl(pcr.new_progress_type,plla.payment_type),'RATE',pcr.new_price,pcr.new_amount),pcr.new_price) NEW_PRICE,
2637 decode(pcr.ACTION_TYPE,'MODIFICATION',fnd_message.get_string('PO','PO_WF_NOTIF_CHANGE'),'CANCELLATION',
2638 fnd_message.get_string('PO','PO_WF_NOTIF_CANCEL'),'Error') ACTION_TYPE,
2639 pla.item_description ITEM_DESCRIPTION,
2640 nvl(plla.unit_meas_lookup_code,pla.unit_meas_lookup_code) UOM,
2641 nvl(hla.location_code, substr(rtrim(hz.address1)||'-'||rtrim(hz.city),1,60)) SHIP_TO_LOCATION,
2642 pcr.ACTION_TYPE ACTION_CODE,
2643 pcr.REQUEST_REASON REASON,
2644 fnd_message.get_string('PO','PO_WF_NOTIF_YES') SPLIT
2645 from
2646 po_change_requests pcr,
2647 po_lines_archive_all pla,
2648 po_line_locations_archive_all plla,
2649 hr_locations_all hla, hz_locations hz,
2650 mtl_system_items_kfv msi,
2651 mtl_planners mtp,
2652 financials_system_params_all fsp
2653 where pcr.change_request_group_id =grp_id
2654 and pla.po_line_id = pcr.document_line_id
2655 and pla.latest_external_flag = 'Y'
2656 and plla.line_location_id = pcr.parent_line_location_id
2657 and plla.latest_external_flag = 'Y'
2658 and request_level = 'SHIPMENT'
2659 and pcr.request_status in ('PENDING','REQ_APP')
2660 and hla.location_id(+) = plla.ship_to_location_id
2661 and plla.SHIP_TO_LOCATION_ID = hz.LOCATION_ID(+)
2662 and msi.inventory_item_id(+) = pla.item_id
2663 --and msi.organization_id(+) = pla.org_id
2664 and fsp.org_id = pla.org_id
2665 and msi.organization_id = fsp.inventory_organization_id
2666 and msi.planner_code = mtp.planner_code
2667 and msi.organization_id = mtp.organization_id
2668 and mtp.employee_id = l_planner_id
2669 )
2670 order by LINE_NUM,nvl(SHIPMENT_NUM,0);
2671
2672 l_id number;
2673 l_header_response po_change_requests.request_status%type;
2674 l_header_cancel varchar2(1);
2675 cursor l_header_cancel_csr(grp_id number) is
2676 select change_request_id,
2677 request_status
2678 from po_change_requests
2679 where change_request_group_id = grp_id
2680 and action_type = 'CANCELLATION'
2681 and request_level = 'HEADER';
2682
2683 l_additional_changes po_change_requests.additional_changes%type;
2684
2685 cursor l_header_changes_csr(grp_id number)
2686 is
2687 select additional_changes
2688 from po_change_requests
2689 where change_request_group_id = grp_id
2690 and request_level = 'HEADER'
2691 and additional_changes is not null;
2692
2693 BEGIN
2694 l_header_id := to_number(substr(p_code,2, instr(p_code,'#')-instr(p_code,'@')-1));
2695 l_release_id := to_number(substr(p_code,instr(p_code,'#')+1, instr(p_code,'$')-instr(p_code,'#')-1));
2696 l_grp_id := to_number(substr(p_code,instr(p_code,'$')+1, instr(p_code,'%')-instr(p_code,'$')-1));
2697 l_planner_id := substr(p_code,instr(p_code,'%')+1, instr(p_code,'^')-instr(p_code,'%')-1);
2698
2699 l_progress := '001';
2700 l_base_url := fnd_profile.value('APPS_WEB_AGENT');
2701 l_base_url := substr(
2702 l_base_url,
2703 0,
2704 instr(rtrim(l_base_url,'/'),'/',-1,2)-1
2705 );
2706 l_base_url_tag := '<base href= "'||l_base_url||'">';
2707 l_progress := '001a';
2708
2709 l_header_cancel := 'N';
2710 if(l_grp_id is not null) then
2711 open l_header_cancel_csr(l_grp_id);
2712 fetch l_header_cancel_csr
2713 into l_id,
2714 l_header_response;
2715 close l_header_cancel_csr;
2716 if(l_id is not null) then
2717 l_header_cancel := 'Y';
2718 end if;
2719 end if;
2720
2721 if(l_release_id is null) then
2722
2723 select segment1,
2724 revision_num,
2725 pos_totals_po_sv.get_po_total(po_header_id),
2726 currency_code,
2727 vendor_id,
2728 vendor_site_id,
2729 to_char(creation_date, FND_PROFILE.VALUE_SPECIFIC('ICX_DATE_FORMAT_MASK', fnd_global.user_id),
2730 'NLS_CALENDAR = ''' || NVL( FND_PROFILE.VALUE_SPECIFIC('FND_FORMS_USER_CALENDAR', fnd_global.user_id) ,'GREGORIAN' ) || ''''),
2731 fob_lookup_code,
2732 ship_via_lookup_code,
2733 ship_to_location_id,
2734 type_lookup_code,
2735 GLOBAL_AGREEMENT_FLAG
2736 into
2737 l_po_num,
2738 l_revision_num,
2739 l_po_total,
2740 l_po_currency,
2741 l_vendor_id,
2742 l_vendor_site_id,
2743 l_order_date,
2744 l_fob,
2745 l_carrier,
2746 l_ship_to_id,
2747 l_type_lookup_code,
2748 l_global_agreement_flag
2749 from po_headers_all
2750 where po_header_id = l_header_id;
2751
2752 if(l_type_lookup_code = 'STANDARD') then
2753 l_document_type := fnd_message.get_string('PO','PO_WF_NOTIF_STD_PO');
2754 elsif(l_type_lookup_code = 'PLANNED') then
2755 l_document_type := fnd_message.get_string('PO','PO_WF_NOTIF_PLAN_PO');
2756 elsif (l_global_agreement_flag = 'Y' and l_type_lookup_code = 'BLANKET') then
2757 l_document_type := fnd_message.get_string('PO','PO_GA_TYPE');
2758 elsif(l_type_lookup_code = 'BLANKET') then
2759 l_document_type := fnd_message.get_string('PO','PO_WF_NOTIF_BLANKET');
2760 elsif(l_type_lookup_code = 'CONTRACT') then
2761 l_document_type := fnd_message.get_string('PO','PO_POTYPE_CNTR');
2762 else
2763 l_document_type := 'Error';
2764 end if;
2765
2766 else
2767 /*Modified as part of bug 7550964 changing date format*/
2768 select
2769 ph.segment1,
2770 pr.release_num,
2771 pr.revision_num,
2772 pos_totals_po_sv.get_release_total(pr.po_release_id),
2773 ph.currency_code,
2774 ph.vendor_id,
2775 ph.vendor_site_id,
2776 to_char(pr.creation_date, FND_PROFILE.VALUE_SPECIFIC('ICX_DATE_FORMAT_MASK', fnd_global.user_id),
2777 'NLS_CALENDAR = ''' || NVL( FND_PROFILE.VALUE_SPECIFIC('FND_FORMS_USER_CALENDAR', fnd_global.user_id) ,'GREGORIAN' ) || ''''),
2778 ph.fob_lookup_code,
2779 ph.ship_via_lookup_code,
2780 ph.ship_to_location_id,
2781 ph.type_lookup_code
2782 into
2783 l_blanket_num,
2784 l_release_num,
2785 l_revision_num,
2786 l_rel_total,
2787 l_rel_currency,
2788 l_vendor_id,
2789 l_vendor_site_id,
2790 l_order_date,
2791 l_fob,
2792 l_carrier,
2793 l_ship_to_id,
2794 l_type_lookup_code
2795 from po_releases_all pr,
2796 po_headers_all ph
2797 where pr.po_release_id = l_release_id
2798 and pr.po_header_id = ph.po_header_id;
2799
2800 if(l_type_lookup_code = 'BLANKET') then
2801 l_document_type := fnd_message.get_string('PO','PO_WF_NOTIF_BKT_REL');
2802 elsif(l_type_lookup_code = 'PLANNED') then
2803 l_document_type := fnd_message.get_string('PO','PO_WF_NOTIF_SCH_REL');
2804 else
2805 l_document_type := 'Error';
2806 end if;
2807
2808 end if;
2809 l_progress := '002';
2810 select
2811 vendor_name
2812 into
2813 l_supplier_name
2814 from po_vendors
2815 where vendor_id = l_vendor_id;
2816
2817 select
2818 address_line1,
2819 address_line2,
2820 address_line3,
2821 city,
2822 state,
2823 zip
2824 into
2825 l_sup_address_line1,
2826 l_sup_address_line2,
2827 l_sup_address_line3,
2828 l_sup_city,
2829 l_sup_state,
2830 l_sup_zip
2831 from po_vendor_sites_all
2832 where vendor_site_id = l_vendor_site_id;
2833
2834 select
2835 address_line_1,
2836 address_line_2,
2837 address_line_3,
2838 town_or_city,
2839 region_1,
2840 postal_code
2841 into
2842 l_ship_addr_l1,
2843 l_ship_addr_l2,
2844 l_ship_addr_l3,
2845 l_ship_city,
2846 l_ship_state,
2847 l_ship_zip
2848 from hr_locations_all
2849 where location_id = l_ship_to_id;
2850 l_progress := '003';
2851
2852 if(l_release_id is null) then
2853 l_document :=l_base_url_tag||
2854 '
2855 <font size=3 color=#336699 face=arial><b>'||l_document_type||' '||l_po_num||' '||fnd_message.get_string('PO','PO_WF_NOTIF_REV')
2856 ||' '||l_revision_num||' ('||fnd_message.get_string('PO','PO_WF_NOTIF_TOTAL')||'('||
2857 l_po_currency||') '||
2858 TO_CHAR(l_po_total, FND_CURRENCY.GET_FORMAT_MASK(l_po_currency, 30))
2859 ||')</B></font><HR size=1 color=#cccc99>';
2860 else
2861 l_document :=l_base_url_tag||
2862 '
2863 <font size=3 color=#336699 face=arial><b>'||l_document_type||' '||l_blanket_num||'-'||l_release_num||' '||fnd_message.get_string('PO','PO_WF_NOTIF_REV')||' '
2864 ||l_revision_num||' ('||fnd_message.get_string('PO','PO_WF_NOTIF_TOTAL')||'('||
2865 l_po_currency||') '||
2866 TO_CHAR(l_po_total, FND_CURRENCY.GET_FORMAT_MASK(l_po_currency, 30))
2867 ||')</B></font><HR size=1 color=#cccc99>';
2868 end if;
2869
2870 l_document := l_document||'
2871 <TABLE cellpadding=2 cellspacing=1>
2872 <TR>
2873 <TD>
2874 <TABLE cellpadding=2 cellspacing=1>
2875 <TR>
2876 <TD nowrap><font color=black><B>
2877 '||fnd_message.get_string('PO','PO_WF_NOTIF_VENDOR')||'</B></font></TD>
2878 <TD nowrap><font color=black>'||l_supplier_name||'</font></TD>
2879 </TR>
2880 <TR>
2881 <TD nowrap valign=TOP><font color=black><B>
2882 '||fnd_message.get_string('PO','PO_WF_NOTIF_ADDRESS')||'</B></font></TD>
2883 <TD nowrap><font color=black>';
2884
2885 if(l_sup_address_line1 is not null) then
2886 l_document := l_document || l_sup_address_line1||'<BR>';
2887 end if;
2888 if(l_sup_address_line2 is not null) then
2889 l_document := l_document || l_sup_address_line2||'<BR>';
2890 end if;
2891 if(l_sup_address_line3 is not null) then
2892 l_document := l_document || l_sup_address_line3||'<BR>';
2893 end if;
2894
2895 l_document := l_document||l_sup_city||', '||l_sup_state||' '||l_sup_zip||
2896 '</font></TD>
2897 </TR>
2898 <TR>
2899 <TD nowrap><font color=black><B>
2900 '||fnd_message.get_string('PO','PO_WF_NOTIF_FOB')||'</B></font></TD>
2901 <TD nowrap><font color=black>'||l_fob||
2902 '</font></TD>
2903 </TR>
2904
2905
2906 <TR>
2907 <TD nowrap><font color=black><B>
2908 '||fnd_message.get_string('PO','PO_WF_NOTIF_CARRIER')||'</B></font></TD>
2909 <TD nowrap><font color=black>'||l_carrier||
2910 '</font></TD>
2911 </TR>
2912 </TABLE>
2913 </TD>
2914 <TD valign=TOP>
2915 <TABLE cellpadding=2 cellspacing=1>
2916 <TR>
2917 <TD nowrap><font color=black><B>
2918 '||fnd_message.get_string('PO','PO_WF_NOTIF_ORDER_DATE')||'</B></font></TD>
2919 <TD nowrap><font color=black>'||l_order_date||
2920 '</font></TD>
2921 </TR>
2922
2923 <TR>
2924 <TD nowrap valign=TOP><font color=black><B>
2925 '||fnd_message.get_string('PO','PO_WF_NOTIF_SHPTO_ADD')||'</B></font></TD>
2926 <TD nowrap><font color=black>
2927 '||
2928 l_ship_addr_l1||' '||l_ship_addr_l2||' '||l_ship_addr_l3||'<BR>'||
2929 l_ship_city||', '||l_ship_state||' '||l_ship_zip
2930 ||'
2931 </font></TD>
2932 </TR>
2933
2934 </TABLE>
2935 </TD>
2936 </TABLE></P>';
2937 WF_NOTIFICATION.WriteToClob(document,l_document);
2938
2939 lc_line_num := null;
2940 if(l_header_cancel = 'N') then
2941 open l_po_chg_req_csr(l_grp_id,l_planner_id);
2942 fetch l_po_chg_req_csr
2943 into
2944 lc_change_id,
2945 lc_line_num,
2946 lc_ship_num,
2947 lc_buyer_pt_num,
2948 lc_old_sup_pt_num,
2949 lc_new_sup_pt_num,
2950 lc_old_prom_date,
2951 lc_new_prom_date,
2952 lc_old_qty,
2953 lc_new_qty,
2954 lc_old_price,
2955 lc_new_price,
2956 lc_action_type,
2957 lc_item_desc,
2958 lc_uom,
2959 lc_ship_to_location,
2960 lc_action_code,
2961 lc_reason,
2962 lc_split;
2963 close l_po_chg_req_csr;
2964 if(lc_line_num is not null) then
2965 l_document := '<font size=3 color=#336699 face=arial><b>'||
2966 fnd_message.get_string('PO', 'PO_WF_NOTIF_CH_CA_REQ')||
2967 '</B></font><HR size=1 color=#cccc99>';
2968 l_document := l_document||'<TABLE><TR>'|| NL;
2969 l_document:= l_document||'<TD class=instructiontext>'||
2970 '<img src=/OA_MEDIA/newupdateditem_status.gif ALT="">'
2971 || fnd_message.get_string('PO', 'PO_WF_NOTIF_NEW_VALUE');
2972 l_document := l_document || '</TD></TR>' || NL;
2973 l_document := l_document || '<TR>'|| NL;
2974 l_document:= l_document||'<TD class=instructiontext>'||
2975 '<img src=/OA_MEDIA/cancelind_status.gif ALT="">'
2976 || fnd_message.get_string('PO', 'PO_WF_NOTIF_CANCEL_PENDING');
2977 l_document := l_document || '</TD></TR>' || NL;
2978 l_document := l_document || '</TABLE>' || NL;
2979 l_document := l_document ||'
2980 <TABLE WIDTH=100% cellpadding=2 cellspacing=1>
2981 <TR bgcolor=#cccc99>
2982 <TH align=left><font color=#336699 >'||fnd_message.get_string('PO','PO_WF_NOTIF_LINE_NUMBER')||'</font></TH>
2983 <TH align=left><font color=#336699 >'||fnd_message.get_string('PO','PO_WF_NOTIF_SHIPMENT')||'</font></TH>
2984 <TH align=left><font color=#336699 >'||fnd_message.get_string('PO','PO_WF_NOTIF_ITEM')||'</font></TH>
2985 <TH align=left><font color=#336699 >'||fnd_message.get_string('PO','PO_WF_NOTIF_SUP_ITEM')||'</font></TH>
2986 <TH align=left><font color=#336699 >'||fnd_message.get_string('PO','PO_WF_NOTIF_DOC_DESCRIPTION')||'</font></TH>
2987 <TH align=left><font color=#336699 >'||fnd_message.get_string('PO','PO_WF_NOTIF_UNIT')||'</font></TH>
2988 <TH align=left><font color=#336699 >'||fnd_message.get_string('PO','PO_WF_NOTIF_PRICE')||'</font></TH>
2989 <TH align=left><font color=#336699 >'||fnd_message.get_string('PO','PO_WF_NOTIF_QTY_ORDERED')||'</font></TH>
2990 <TH align=left><font color=#336699 >'||fnd_message.get_string('PO','PO_WF_NOTIF_PROM_DATE')||'</font></TH>
2991 <TH align=left><font color=#336699 >'||fnd_message.get_string('PO','PO_WF_NOTIF_SHIPTO')||'</font></TH>
2992 <TH align=left><font color=#336699 >'||fnd_message.get_string('PO','PO_WF_NOTIF_ACTION')||'</font></TH>
2993 <TH align=left><font color=#336699 >'||fnd_message.get_string('PO','PO_WF_NOTIF_REASON')||'</font></TH>
2994 <TH align=left><font color=#336699 >'||fnd_message.get_string('PO','PO_WF_NOTIF_SPLIT')||'</font></TH>
2995 </TR>
2996 </B>';
2997
2998 WF_NOTIFICATION.WriteToClob(document,l_document);
2999
3000 open l_po_chg_req_csr(l_grp_id,l_planner_id);
3001 loop
3002 fetch l_po_chg_req_csr
3003 into
3004 lc_change_id,
3005 lc_line_num,
3006 lc_ship_num,
3007 lc_buyer_pt_num,
3008 lc_old_sup_pt_num,
3009 lc_new_sup_pt_num,
3010 lc_old_prom_date,
3011 lc_new_prom_date,
3012 lc_old_qty,
3013 lc_new_qty,
3014 lc_old_price,
3015 lc_new_price,
3016 lc_action_type,
3017 lc_item_desc,
3018 lc_uom,
3019 lc_ship_to_location,
3020 lc_action_code,
3021 lc_reason,
3022 lc_split;
3023 EXIT when l_po_chg_req_csr%NOTFOUND;
3024
3025 if(lc_split is not null) then
3026 lc_old_sup_pt_num := nvl(lc_old_sup_pt_num,lc_new_sup_pt_num);
3027 lc_new_sup_pt_num := null;
3028
3029 lc_old_price:=nvl(lc_old_price,lc_new_price);
3030 lc_new_price:= null;
3031
3032 lc_new_prom_date:= nvl(lc_new_prom_date,lc_old_prom_date);
3033 lc_old_prom_date:= null;
3034
3035 lc_new_qty:=nvl(lc_new_qty,lc_old_qty);
3036 lc_old_qty:= null;
3037 end if;
3038 lc_line_num := nvl(lc_line_num,'` ');
3039 lc_ship_num:= nvl(lc_ship_num,'` ');
3040 lc_buyer_pt_num:= nvl(lc_buyer_pt_num,'` ');
3041 lc_old_sup_pt_num:= nvl(lc_old_sup_pt_num,'` ');
3042 lc_new_sup_pt_num:= nvl(lc_new_sup_pt_num,'` ');
3043 lc_old_prom_date:= nvl(lc_old_prom_date,'` ');
3044 lc_new_prom_date:= nvl(lc_new_prom_date,'` ');
3045 lc_old_qty:= nvl(lc_old_qty,'` ');
3046 lc_new_qty:= nvl(lc_new_qty,'` ');
3047 lc_old_price:= nvl(lc_old_price,'` ');
3048 lc_new_price:= nvl(lc_new_price,'` ');
3049 lc_action_type:= nvl(lc_action_type,'` ');
3050 lc_item_desc:= nvl(lc_item_desc,'` ');
3051 lc_uom:= nvl(lc_uom,'` ');
3052 lc_ship_to_location:= nvl(lc_ship_to_location,'` ');
3053 lc_reason := nvl(lc_reason,'` ');
3054 lc_split := nvl(lc_split,'` ');
3055
3056
3057 l_document := '
3058 <TR bgcolor=#f7f7e7>
3059
3060 <TD align=left><font color=black>'||lc_line_num||
3061 '</font></TD> ';
3062
3063 if(lc_action_code = 'CANCELLATION') then
3064 l_document := l_document ||'
3065 <TD align=left><font color=black>
3066 <TABLE>
3067 <TR>
3068 <TD>
3069 <img src=/OA_MEDIA/cancelind_status.gif ALT="">
3070 </TD>
3071 <TD alight=right>'
3072 ||lc_ship_num||
3073 '</TD>
3074 </TR>
3075 </TABLE>
3076 </font></TD> ';
3077 else
3078 l_document := l_document ||'
3079 <TD align=left><font color=black>'||lc_ship_num||
3080 '</font></TD> ';
3081 end if;
3082 l_document := l_document ||'
3083 <TD align=left><font color=black>'||lc_buyer_pt_num||
3084 '</font></TD> ';
3085
3086 if(lc_new_sup_pt_num = '` ') then
3087 l_document := l_document || '
3088 <TD align=left><font color=black>'||lc_old_sup_pt_num||'
3089 </font></TD>';
3090 else
3091 l_document := l_document || '
3092 <TD align=left><font color=black>
3093 <table>
3094 <tr>
3095 <td>'||lc_old_sup_pt_num||'
3096 </td>
3097 </tr>
3098 <tr>
3099 <td>'||lc_new_sup_pt_num||'
3100 </td>
3101 <td>
3102 <img src=/OA_MEDIA/newupdateditem_status.gif ALT="">
3103 </td>
3104 </tr>
3105 </table>
3106 </font></TD>';
3107 end if;
3108
3109 l_document := l_document || '
3110 <TD align=left><font color=black>'||lc_item_desc||
3111 '</font></TD>
3112
3113 <TD align=left><font color=black>'||lc_uom||
3114 '</font></TD> ';
3115
3116 if(lc_new_price = '` ') then
3117 l_document := l_document || '
3118 <TD align=left><font color=black>'||lc_old_price||'
3119 </font></TD>';
3120 else
3121 l_document := l_document || '
3122 <TD align=left><font color=black>
3123 <table>
3124 <tr>
3125 <td>'||lc_old_price||'
3126 </td>
3127 </tr>
3128 <tr>
3129 <td>'||lc_new_price||'
3130 </td>
3131 <td>
3132 <img src=/OA_MEDIA/newupdateditem_status.gif ALT="">
3133 </td>
3134 </tr>
3135 </table>
3136 </font></TD>';
3137 end if;
3138
3139 if(lc_new_qty = '` ') then
3140 l_document := l_document || '
3141 <TD align=left><font color=black>'||lc_old_qty||'
3142 </font></TD>';
3143 elsif(lc_split <> '` ') then
3144 l_document := l_document || '
3145 <TD align=left><font color=black>
3146 <table>
3147 <tr>
3148 <td>'||lc_new_qty||'
3149 </td>
3150 <td>
3151 <img src=/OA_MEDIA/newupdateditem_status.gif ALT="">
3152 </td>
3153 </tr>
3154 </table>
3155 </font></TD>';
3156 else
3157 l_document := l_document || '
3158 <TD align=left><font color=black>
3159 <table>
3160 <tr>
3161 <td>'||lc_old_qty||'
3162 </td>
3163 </tr>
3164 <tr>
3165 <td>'||lc_new_qty||'
3166 </td>
3167 <td>
3168 <img src=/OA_MEDIA/newupdateditem_status.gif ALT="">
3169 </td>
3170 </tr>
3171 </table>
3172 </font></TD>';
3173 end if;
3174
3175 if(lc_new_prom_date = '` ') then
3176 l_document := l_document || '
3177 <TD align=left><font color=black>'||lc_old_prom_date||'
3178 </font></TD>';
3179 elsif(lc_split <> '` ') then
3180 l_document := l_document || '
3181 <TD align=left><font color=black>
3182 <table>
3183 <tr>
3184 <td>'||lc_new_prom_date||'
3185 </td>
3186 <td>
3187 <img src=/OA_MEDIA/newupdateditem_status.gif ALT="">
3188 </td>
3189 </tr>
3190 </table>
3191 </font></TD>';
3192 else
3193 l_document := l_document || '
3194 <TD align=left><font color=black>
3195 <table>
3196 <tr>
3197 <td>'||lc_old_prom_date||'
3198 </td>
3199 </tr>
3200 <tr>
3201 <td>'||lc_new_prom_date||'
3202 </td>
3203 <td>
3204 <img src=/OA_MEDIA/newupdateditem_status.gif ALT="">
3205 </td>
3206 </tr>
3207 </table>
3208 </font></TD>';
3209 end if;
3210 l_document := l_document || '
3211
3212 <TD align=left><font color=black>'||lc_ship_to_location||
3213 '</font></TD>
3214
3215 <TD align=left><font color=black>'||lc_action_type||
3216 '</font></TD>
3217
3218 <TD align=left><font color=black>'||lc_reason||
3219 '</font></TD>
3220
3221 <TD align=left><font color=black>'||lc_split||
3222 '</font></TD>
3223
3224 </TR>
3225 ';
3226 WF_NOTIFICATION.WriteToClob(document,l_document);
3227
3228 END LOOP;
3229 CLOSE l_po_chg_req_csr;
3230 WF_NOTIFICATION.WriteToClob(document, '
3231 </TABLE></P>
3232 ');
3233 end if;
3234 open l_header_changes_csr(l_grp_id);
3235 fetch l_header_changes_csr into l_additional_changes;
3236 close l_header_changes_csr;
3237
3238 if(l_additional_changes is not null) then
3239 l_document := '<BR><B>'||fnd_message.get_string('PO','PO_WF_NOTIF_ADD_CHN_REQ')||'</B>'||
3240 ' `  '||l_additional_changes||'<BR>';
3241 WF_NOTIFICATION.WriteToClob(document,l_document);
3242 end if;
3243
3244 else
3245 fnd_message.set_name('PO','PO_WF_NOTIF_CAN_ENTIER');
3246 fnd_message.set_token('DOC',l_document_type);
3247 l_document := fnd_message.get;
3248 WF_NOTIFICATION.WriteToClob(document,l_document);
3249 end if;
3250 exception when others then
3251 WF_NOTIFICATION.WriteToClob(document,'Exception occured:'||sqlerrm);
3252
3253 END GEN_NTF_FOR_PLAN_SUP_CHN;
3254
3255 /*
3256 * Generate Notification Body for Buyer.
3257 * This Notification will be sent when
3258 * 1. Supplier changes a PO which was in 'APPROVED' status
3259 * 2. Supplier acknowledges a PO (which requires acknowledgement) with acceptance, rejection, or modifications
3260 */
3261 PROCEDURE GEN_NTF_FOR_BUYER_SUP_CHG(p_code IN varchar2,
3262 display_type in Varchar2,
3263 document in out NOCOPY clob,
3264 document_type in out NOCOPY varchar2)
3265 IS
3266 /* l_api_name varchar2(50) := 'GEN_NTF_FOR_BUYER_SUP_CHG'; -- RDP Not needed , Replaced by JRAD Notification
3267 l_progress varchar2(5) := '000';
3268 l_header_id number;
3269 l_release_id number;
3270 l_grp_id number;
3271 l_rel_total number;
3272 l_rel_currency po_headers.currency_code%TYPE;
3273 --l_blanket_num number;
3274 l_blanket_num po_headers_all.segment1%TYPE;
3275 --l_release_num number;
3276 l_release_num po_releases_all.release_num%TYPE;
3277 l_po_doc_id number;
3278 l_rel_doc_id number;
3279 l_acc_req_flag varchar2(1);
3280 l_document varchar2(32000);
3281 l_type_lookup_code po_headers_all.type_lookup_code%TYPE;
3282 l_document_type varchar2(2000);
3283 l_po_num po_headers_all.segment1%TYPE;
3284 l_revision_num number;
3285 l_po_total number;
3286 l_po_currency po_headers.currency_code%TYPE;
3287 l_vendor_id number;
3288 l_vendor_site_id number;
3289 l_supplier_name po_vendors.vendor_name%TYPE;
3290 l_sup_address_line1 po_vendor_sites_all.address_line1%TYPE;
3291 l_sup_address_line2 po_vendor_sites_all.address_line2%TYPE;
3292 l_sup_address_line3 po_vendor_sites_all.address_line3%TYPE;
3293 l_sup_city po_vendor_sites_all.city%TYPE;
3294 l_sup_state po_vendor_sites_all.state%TYPE;
3295 l_sup_zip po_vendor_sites_all.zip%TYPE;
3296 l_order_date varchar2(2000);
3297 l_fob po_headers_all.fob_lookup_code%TYPE;
3298 l_carrier po_headers_all.ship_via_lookup_code%TYPE;
3299 l_ship_to_id number;
3300 l_ship_addr_l1 hr_locations_all.address_line_1%TYPE;
3301 l_ship_addr_l2 hr_locations_all.address_line_2%TYPE;
3302 l_ship_addr_l3 hr_locations_all.address_line_3%TYPE;
3303 l_ship_city hr_locations_all.town_or_city%TYPE;
3304 l_ship_state hr_locations_all.region_1%TYPE;
3305 l_ship_zip hr_locations_all.postal_code%TYPE;
3306
3307 l_document1 VARCHAR2(32000) := '';
3308 l_base_url varchar2(2000);
3309 l_base_url_tag varchar2(2000);
3310 l_new_prom_date varchar2(2000);
3311 l_old_prom_date varchar2(2000); */
3312
3313 /*varchar Variables for creating the notification*/
3314 /* lc_line_num varchar2(2000);
3315 lc_ship_num varchar2(2000);
3316 lc_buyer_pt_num mtl_system_items_kfv.concatenated_segments%TYPE;
3317 lc_old_sup_pt_num po_lines_all.vendor_product_num%TYPE;
3318 lc_new_sup_pt_num po_change_requests.new_supplier_part_number%TYPE;
3319 lc_old_prom_date date;
3320 lc_new_prom_date date;
3321 lc_old_qty varchar2(2000);
3322 lc_new_qty varchar2(2000);
3323 lc_old_price varchar2(2000);
3324 lc_new_price varchar2(2000);
3325 lc_action_type varchar2(2000);
3326 lc_item_desc po_lines_all.item_description%TYPE;
3327 lc_uom po_lines_all.unit_meas_lookup_code%TYPE;
3328 lc_ship_to_location hr_locations_all.location_code%TYPE;
3329 lc_action_code po_change_requests.ACTION_TYPE%TYPE;
3330 lc_reason po_change_requests.request_reason%TYPE;
3331 lc_split varchar2(2000);
3332 l_global_agreement_flag po_headers_all.GLOBAL_AGREEMENT_FLAG%TYPE;
3333 l_po_rev number;
3334 l_rel_rev number;
3335
3336 cursor l_po_chg_req_csr(grp_id number) is
3337 select
3338 to_char(LINE_NUM),
3339 to_char(SHIPMENT_NUM),
3340 BUYER_PT_NUM,
3341 OLD_SUP_PT_NUM,
3342 NEW_SUP_PT_NUM,
3343 OLD_PROM_DATE,
3344 NEW_PROM_DATE,
3345 to_char(OLD_QTY),
3346 to_char(NEW_QTY),
3347 to_char(OLD_PRICE),
3348 to_char(NEW_PRICE),
3349 ACTION_TYPE,
3350 ITEM_DESCRIPTION,
3351 UOM,
3352 SHIP_TO_LOCATION,
3353 ACTION_CODE,
3354 REASON,
3355 SPLIT
3356 from(
3357
3358 -- LINE CHANGES for Standard PO
3359 select
3360 pcr.document_line_number LINE_NUM,
3361 pcr.document_shipment_number SHIPMENT_NUM,
3362 msi.concatenated_segments BUYER_PT_NUM,
3363 pla.vendor_product_num OLD_SUP_PT_NUM,
3364 pcr.new_supplier_part_number NEW_SUP_PT_NUM,
3365 to_date(null,'DD/MM/YYYY') OLD_PROM_DATE,
3366 to_date(null,'DD/MM/YYYY') NEW_PROM_DATE,
3367 pla.quantity OLD_QTY,
3368 to_number(null) NEW_QTY,
3369 pla.unit_price OLD_PRICE,
3370 pcr.new_price NEW_PRICE,
3371 decode(pcr.ACTION_TYPE,'MODIFICATION',fnd_message.get_string('PO','PO_WF_NOTIF_CHANGE'),
3372 'CANCELLATION',fnd_message.get_string('PO','PO_WF_NOTIF_CANCEL'),'Error') ACTION_TYPE,
3373 pla.item_description ITEM_DESCRIPTION,
3374 pla.unit_meas_lookup_code UOM,
3375 null SHIP_TO_LOCATION,
3376 pcr.ACTION_TYPE ACTION_CODE,
3377 pcr.request_reason REASON,
3378 null SPLIT
3379 from
3380 po_change_requests pcr,
3381 po_lines_archive_all pla,
3382 mtl_system_items_kfv msi,
3383 FINANCIALS_SYSTEM_PARAMS_ALL FSP
3384 where pla.po_line_id = pcr.document_line_id
3385 and pcr.change_request_group_id =grp_id
3386 and pcr.request_level = 'LINE'
3387 and pcr.request_status = 'PENDING'
3388 and pla.latest_external_flag = 'Y'
3389 and msi.inventory_item_id(+) = pla.item_id
3390 --and msi.organization_id(+) = pla.org_id
3391 and NVL(MSI.ORGANIZATION_ID, FSP.INVENTORY_ORGANIZATION_ID) = FSP.INVENTORY_ORGANIZATION_ID
3392 AND FSP.ORG_ID = PLA.ORG_ID
3393 UNION ALL
3394
3395 -- SHIPMENT CHANGES for Standard PO and Releases
3396 select
3397 pla.line_num LINE_NUM,
3398 pcr.document_shipment_number SHIPMENT_NUM,
3399 msi.concatenated_segments BUYER_PT_NUM,
3400 pla.vendor_product_num OLD_SUP_PT_NUM,
3401 null NEW_SUP_PT_NUM,
3402 decode(pcr.new_promised_date, null, plla.promised_date, pcr.old_promised_date) OLD_PROM_DATE,
3403 pcr.new_promised_date NEW_PROM_DATE,
3404 plla.quantity OLD_QTY,
3405 pcr.new_quantity NEW_QTY,
3406 plla.price_override OLD_PRICE,
3407 pcr.new_price NEW_PRICE,
3408 decode(pcr.ACTION_TYPE,'MODIFICATION',fnd_message.get_string('PO','PO_WF_NOTIF_CHANGE'),'CANCELLATION',
3409 fnd_message.get_string('PO','PO_WF_NOTIF_CANCEL'),'Error') ACTION_TYPE,
3410 pla.item_description ITEM_DESCRIPTION,
3411 nvl(plla.unit_meas_lookup_code,pla.unit_meas_lookup_code) UOM,
3412 nvl(hla.location_code, substr(rtrim(hz.address1)||'-'||rtrim(hz.city),1,60)) SHIP_TO_LOCATION,
3413 pcr.ACTION_TYPE ACTION_CODE,
3414 pcr.REQUEST_REASON REASON,
3415 null SPLIT
3416 from
3417 po_change_requests pcr,
3418 po_lines_archive_all pla,
3419 po_line_locations_archive_all plla,
3420 hr_locations_all hla, hz_locations hz,
3421 mtl_system_items_kfv msi,
3422 FINANCIALS_SYSTEM_PARAMS_ALL FSP
3423 where pcr.change_request_group_id =grp_id
3424 and pla.po_line_id = pcr.document_line_id
3425 and pla.latest_external_flag = 'Y'
3426 and plla.line_location_id = pcr.document_line_location_id
3427 and plla.latest_external_flag = 'Y'
3428 and request_level = 'SHIPMENT'
3429 and pcr.request_status = 'PENDING'
3430 and hla.location_id(+) = plla.ship_to_location_id
3431 and plla.SHIP_TO_LOCATION_ID = hz.LOCATION_ID(+)
3432 and msi.inventory_item_id(+) = pla.item_id
3433 --and msi.organization_id(+) = pla.org_id
3434 and NVL(MSI.ORGANIZATION_ID, FSP.INVENTORY_ORGANIZATION_ID) = FSP.INVENTORY_ORGANIZATION_ID
3435 AND FSP.ORG_ID = PLA.ORG_ID
3436 UNION ALL
3437
3438 --SPLIT SHIPMENTS
3439 select
3440 pla.line_num LINE_NUM,
3441 pcr.document_shipment_number SHIPMENT_NUM,
3442 msi.concatenated_segments BUYER_PT_NUM,
3443 pla.vendor_product_num OLD_SUP_PT_NUM,
3444 null NEW_SUP_PT_NUM,
3445 decode(pcr.new_promised_date, null, plla.promised_date, pcr.old_promised_date) OLD_PROM_DATE,
3446 pcr.new_promised_date NEW_PROM_DATE,
3447 plla.quantity OLD_QTY,
3448 pcr.new_quantity NEW_QTY,
3449 plla.price_override OLD_PRICE,
3450 pcr.new_price NEW_PRICE,
3451 decode(pcr.ACTION_TYPE,'MODIFICATION',fnd_message.get_string('PO','PO_WF_NOTIF_CHANGE'),'CANCELLATION',
3452 fnd_message.get_string('PO','PO_WF_NOTIF_CANCEL'),'Error') ACTION_TYPE,
3453 pla.item_description ITEM_DESCRIPTION,
3454 nvl(plla.unit_meas_lookup_code,pla.unit_meas_lookup_code) UOM,
3455 nvl(hla.location_code, substr(rtrim(hz.address1)||'-'||rtrim(hz.city),1,60)) SHIP_TO_LOCATION,
3456 pcr.ACTION_TYPE ACTION_CODE,
3457 pcr.REQUEST_REASON REASON,
3458 fnd_message.get_string('PO','PO_WF_NOTIF_YES') SPLIT
3459 from
3460 po_change_requests pcr,
3461 po_lines_archive_all pla,
3462 po_line_locations_archive_all plla,
3463 hr_locations_all hla, hz_locations hz,
3464 mtl_system_items_kfv msi,
3465 FINANCIALS_SYSTEM_PARAMS_ALL FSP
3466 where pcr.change_request_group_id =grp_id
3467 and pla.po_line_id = pcr.document_line_id
3468 and pla.latest_external_flag = 'Y'
3469 and plla.line_location_id = pcr.parent_line_location_id
3470 and plla.latest_external_flag = 'Y'
3471 and request_level = 'SHIPMENT'
3472 and pcr.request_status = 'PENDING'
3473 and hla.location_id(+) = plla.ship_to_location_id
3474 and plla.SHIP_TO_LOCATION_ID = hz.LOCATION_ID(+)
3475 and msi.inventory_item_id(+) = pla.item_id
3476 --and msi.organization_id(+) = pla.org_id
3477 and NVL(MSI.ORGANIZATION_ID, FSP.INVENTORY_ORGANIZATION_ID) = FSP.INVENTORY_ORGANIZATION_ID
3478 AND FSP.ORG_ID = PLA.ORG_ID
3479 )
3480 order by LINE_NUM,nvl(SHIPMENT_NUM,0);
3481
3482 cursor l_po_ack_csr(l_po_document_id number, l_rel_document_id number, l_rev number)
3483 IS
3484 select
3485 to_char(LINE_NUM),
3486 to_char(SHIPMENT_NUM),
3487 BUYER_PT_NUM,
3488 OLD_SUP_PT_NUM,
3489 NEW_SUP_PT_NUM,
3490 OLD_PROM_DATE,
3491 NEW_PROM_DATE,
3492 to_char(OLD_QTY),
3493 to_char(NEW_QTY),
3494 to_char(OLD_PRICE),
3495 to_char(NEW_PRICE),
3496 ACTION_TYPE,
3497 ITEM_DESCRIPTION,
3498 UOM,
3499 SHIP_TO_LOCATION,
3500 NOTE
3501 from(
3502 -- SHIPMENT ACCEPTANCE/REJECTION for Standard PO
3503 select
3504 pla.line_num LINE_NUM,
3505 plla.shipment_num SHIPMENT_NUM,
3506 msi.concatenated_segments BUYER_PT_NUM,
3507 pla.VENDOR_PRODUCT_NUM OLD_SUP_PT_NUM,
3508 null NEW_SUP_PT_NUM,
3509 nvl(plla.promised_date,plla.need_by_date) OLD_PROM_DATE,
3510 to_date(null,'DD/MM/YYYY') NEW_PROM_DATE,
3511 plla.quantity OLD_QTY,
3512 to_number(null) NEW_QTY,
3513 plla.price_override OLD_PRICE,
3514 to_number(null) NEW_PRICE,
3515 decode(pa.accepted_flag,'Y',fnd_message.get_string('PO','PO_WF_NOTIF_ACCEPT'),
3516 'N',fnd_message.get_string('PO','PO_WF_NOTIF_REJECT'),'NA') ACTION_TYPE,
3517 pla.item_description ITEM_DESCRIPTION,
3518 nvl(plla.unit_meas_lookup_code,pla.unit_meas_lookup_code) UOM,
3519 nvl(hla.location_code, substr(rtrim(hz.address1)||'-'||rtrim(hz.city),1,60)) SHIP_TO_LOCATION,
3520 pa.note NOTE
3521 from
3522 po_acceptances pa,
3523 po_lines_archive_all pla,
3524 po_line_locations_archive_all plla,
3525 hr_locations_all hla, hz_locations hz,
3526 mtl_system_items_kfv msi,
3527 FINANCIALS_SYSTEM_PARAMS_ALL FSP
3528 where plla.po_header_id = l_po_document_id
3529 and plla.po_line_id = pla.po_line_id
3530 and pa.po_line_location_id = plla.line_location_id
3531 and hla.location_id(+) = plla.ship_to_location_id
3532 and plla.SHIP_TO_LOCATION_ID = hz.LOCATION_ID(+)
3533 --and plla.latest_external_flag = 'Y'
3534 and pla.latest_external_flag = 'Y'
3535 and pa.revision_num = l_rev
3536 and plla.revision_num = (select max(revision_num)
3537 from po_line_locations_archive_all plla2
3538 where plla2.line_location_id = plla.line_location_id and
3539 plla.revision_num <= l_rev)
3540 and msi.inventory_item_id(+) = pla.item_id
3541 --and msi.organization_id(+) = pla.org_id
3542 and NVL(MSI.ORGANIZATION_ID, FSP.INVENTORY_ORGANIZATION_ID) = FSP.INVENTORY_ORGANIZATION_ID
3543 AND FSP.ORG_ID = PLA.ORG_ID
3544 UNION ALL
3545
3546 -- SHIPMENT ACCEPTANCE/REJECTION for Releases
3547 select
3548 pla.line_num LINE_NUM,
3549 plla.shipment_num SHIPMENT_NUM,
3550 msi.concatenated_segments BUYER_PT_NUM,
3551 pla.VENDOR_PRODUCT_NUM OLD_SUP_PT_NUM,
3552 null NEW_SUP_PT_NUM,
3553 nvl(plla.promised_date,plla.need_by_date) OLD_PROM_DATE,
3554 to_date(null,'DD/MM/YYYY') NEW_PROM_DATE,
3555 plla.quantity OLD_QTY,
3556 to_number(null) NEW_QTY,
3557 plla.price_override OLD_PRICE,
3558 to_number(null) NEW_PRICE,
3559 decode(pa.accepted_flag,'Y',fnd_message.get_string('PO','PO_WF_NOTIF_ACCEPT'),'N',fnd_message.get_string('PO','PO_WF_NOTIF_REJECT'),'NA') ACTION_TYPE,
3560 pla.item_description ITEM_DESCRIPTION,
3561 nvl(plla.unit_meas_lookup_code,pla.unit_meas_lookup_code) UOM,
3562 nvl(hla.location_code, substr(rtrim(hz.address1)||'-'||rtrim(hz.city),1,60)) SHIP_TO_LOCATION,
3563 pa.NOTE NOTE
3564 from
3565 po_acceptances pa,
3566 po_lines_archive_all pla,
3567 po_line_locations_archive_all plla,
3568 hr_locations_all hla, hz_locations hz,
3569 mtl_system_items_kfv msi,
3570 FINANCIALS_SYSTEM_PARAMS_ALL FSP
3571 where plla.po_release_id = l_rel_document_id
3572 and plla.po_line_id = pla.po_line_id
3573 and pa.po_line_location_id = plla.line_location_id
3574 and hla.location_id(+) = plla.ship_to_location_id
3575 and plla.SHIP_TO_LOCATION_ID = hz.LOCATION_ID(+)
3576 --and plla.latest_external_flag = 'Y'
3577 and pla.latest_external_flag = 'Y'
3578 and pa.revision_num = l_rev
3579 and plla.revision_num = (select max(revision_num)
3580 from po_line_locations_archive_all plla2
3581 where plla2.line_location_id = plla.line_location_id and
3582 plla.revision_num <= l_rev)
3583 and msi.inventory_item_id(+) = pla.item_id
3584 --and msi.organization_id(+) = pla.org_id
3585 and NVL(MSI.ORGANIZATION_ID, FSP.INVENTORY_ORGANIZATION_ID) = FSP.INVENTORY_ORGANIZATION_ID
3586 AND FSP.ORG_ID = PLA.ORG_ID
3587 )
3588 order by LINE_NUM,SHIPMENT_NUM;
3589
3590 l_id number;
3591 l_header_response po_change_requests.request_status%type;
3592 l_header_cancel varchar2(1);
3593
3594 cursor l_header_cancel_csr(grp_id number) is
3595 select change_request_id,
3596 request_status
3597 from po_change_requests
3598 where change_request_group_id = grp_id
3599 and action_type = 'CANCELLATION'
3600 and request_level = 'HEADER';
3601
3602 l_additional_changes po_change_requests.additional_changes%type;
3603
3604 cursor l_header_changes_csr(grp_id number)
3605 is
3606 select additional_changes
3607 from po_change_requests
3608 where change_request_group_id = grp_id
3609 and request_level = 'HEADER'
3610 and additional_changes is not null;
3611 */
3612 BEGIN
3613 /* l_header_id := to_number(substr(p_code,2, instr(p_code,'#')-instr(p_code,'@')-1));
3614 l_release_id := to_number(substr(p_code,instr(p_code,'#')+1, instr(p_code,'$')-instr(p_code,'#')-1));
3615 l_grp_id := to_number(substr(p_code,instr(p_code,'$')+1, instr(p_code,'%')-instr(p_code,'$')-1));
3616 l_acc_req_flag := substr(p_code,instr(p_code,'%')+1, instr(p_code,'^')-instr(p_code,'%')-1);
3617
3618
3619 l_progress := '001';
3620 l_base_url := fnd_profile.value('APPS_WEB_AGENT');
3621 l_base_url := substr(
3622 l_base_url,
3623 0,
3624 instr(rtrim(l_base_url,'/'),'/',-1,2)-1
3625 );
3626 l_base_url_tag := '<base href= "'||l_base_url||'">';
3627 l_progress := '001a';
3628 l_header_cancel := 'N';
3629 if(l_grp_id is not null) then
3630 open l_header_cancel_csr(l_grp_id);
3631 fetch l_header_cancel_csr
3632 into l_id,
3633 l_header_response;
3634 close l_header_cancel_csr;
3635 if(l_id is not null) then
3636 l_header_cancel := 'Y';
3637 end if;
3638 end if;
3639
3640 if(l_release_id is null) then
3641
3642 select segment1,
3643 revision_num,
3644 pos_totals_po_sv.get_po_total(po_header_id),
3645 currency_code,
3646 vendor_id,
3647 vendor_site_id,
3648 to_char(creation_date, fnd_profile.value_wnps('ICX_DATE_FORMAT_MASK')||' HH24:MI:SS'),
3649 fob_lookup_code,
3650 ship_via_lookup_code,
3651 ship_to_location_id,
3652 type_lookup_code,
3653 GLOBAL_AGREEMENT_FLAG
3654 into
3655 l_po_num,
3656 l_revision_num,
3657 l_po_total,
3658 l_po_currency,
3659 l_vendor_id,
3660 l_vendor_site_id,
3661 l_order_date,
3662 l_fob,
3663 l_carrier,
3664 l_ship_to_id,
3665 l_type_lookup_code,
3666 l_global_agreement_flag
3667 from po_headers_all
3668 where po_header_id = l_header_id;
3669
3670 if(l_type_lookup_code = 'STANDARD') then
3671 l_document_type := fnd_message.get_string('PO','PO_WF_NOTIF_STD_PO');
3672 elsif(l_type_lookup_code = 'PLANNED') then
3673 l_document_type := fnd_message.get_string('PO','PO_WF_NOTIF_PLAN_PO');
3674 elsif (l_global_agreement_flag = 'Y' and l_type_lookup_code = 'BLANKET') then
3675 l_document_type := fnd_message.get_string('PO','PO_GA_TYPE');
3676 elsif(l_type_lookup_code = 'BLANKET') then
3677 l_document_type := fnd_message.get_string('PO','PO_WF_NOTIF_BLANKET');
3678 elsif(l_type_lookup_code = 'CONTRACT') then
3679 l_document_type := fnd_message.get_string('PO','PO_POTYPE_CNTR');
3680 else
3681 l_document_type := 'Error';
3682 end if;
3683
3684 if(l_acc_req_flag = 'Y') then
3685 l_po_doc_id := l_header_id;
3686 else
3687 l_po_doc_id := -1;
3688 end if;
3689
3690 else
3691
3692 select
3693 ph.segment1,
3694 pr.release_num,
3695 pr.revision_num,
3696 pos_totals_po_sv.get_release_total(pr.po_release_id),
3697 ph.currency_code,
3698 ph.vendor_id,
3699 ph.vendor_site_id,
3700 to_char(pr.creation_date, fnd_profile.value_wnps('ICX_DATE_FORMAT_MASK')||' HH24:MI:SS'),
3701 ph.fob_lookup_code,
3702 ph.ship_via_lookup_code,
3703 ph.ship_to_location_id,
3704 ph.type_lookup_code
3705 into
3706 l_blanket_num,
3707 l_release_num,
3708 l_revision_num,
3709 l_rel_total,
3710 l_rel_currency,
3711 l_vendor_id,
3712 l_vendor_site_id,
3713 l_order_date,
3714 l_fob,
3715 l_carrier,
3716 l_ship_to_id,
3717 l_type_lookup_code
3718 from po_releases_all pr,
3719 po_headers_all ph
3720 where pr.po_release_id = l_release_id
3721 and pr.po_header_id = ph.po_header_id;
3722
3723 if(l_type_lookup_code = 'BLANKET') then
3724 l_document_type := fnd_message.get_string('PO','PO_WF_NOTIF_BKT_REL');
3725 elsif(l_type_lookup_code = 'PLANNED') then
3726 l_document_type := fnd_message.get_string('PO','PO_WF_NOTIF_SCH_REL');
3727 else
3728 l_document_type := 'Error';
3729 end if;
3730
3731 if(l_acc_req_flag = 'Y') then
3732 l_rel_doc_id := l_release_id;
3733 else
3734 l_rel_doc_id := -1;
3735 end if;
3736
3737 end if;
3738 l_progress := '002';
3739 select
3740 vendor_name
3741 into
3742 l_supplier_name
3743 from po_vendors
3744 where vendor_id = l_vendor_id;
3745
3746 select
3747 address_line1,
3748 address_line2,
3749 address_line3,
3750 city,
3751 state,
3752 zip
3753 into
3754 l_sup_address_line1,
3755 l_sup_address_line2,
3756 l_sup_address_line3,
3757 l_sup_city,
3758 l_sup_state,
3759 l_sup_zip
3760 from po_vendor_sites_all
3761 where vendor_site_id = l_vendor_site_id;
3762
3763 select
3764 address_line_1,
3765 address_line_2,
3766 address_line_3,
3767 town_or_city,
3768 region_1,
3769 postal_code
3770 into
3771 l_ship_addr_l1,
3772 l_ship_addr_l2,
3773 l_ship_addr_l3,
3774 l_ship_city,
3775 l_ship_state,
3776 l_ship_zip
3777 from hr_locations_all
3778 where location_id = l_ship_to_id;
3779 l_progress := '003';
3780
3781 if(l_release_id is null) then
3782 l_document :=l_base_url_tag||
3783 '
3784 <font size=3 color=#336699 face=arial><b>'||l_document_type||' '||l_po_num||' '||fnd_message.get_string('PO','PO_WF_NOTIF_REV')
3785 ||' '||l_revision_num||' ('||fnd_message.get_string('PO','PO_WF_NOTIF_TOTAL')||'('||
3786 l_po_currency||') '||
3787 TO_CHAR(l_po_total, FND_CURRENCY.GET_FORMAT_MASK(l_po_currency, 30))
3788 ||')</B></font><HR size=1 color=#cccc99>'; */
3789 /*
3790 if(l_acc_req_flag <> 'Y') then
3791 l_document := l_document ||
3792 '- '||fnd_message.get_string('PO','PO_WF_NOTIF_NUM_OF_CHN')||' - '||
3793 l_num_of_changes||' '||fnd_message.get_string('PO','PO_WF_NOTIF_CANCELLED')||' - '||l_num_of_cancels||'</B></font><HR size=1 color=#cccc99>';
3794 end if; */
3795 /*
3796 else
3797 l_document :=l_base_url_tag||
3798 '
3799 <font size=3 color=#336699 face=arial><b>'||l_document_type||' '||l_blanket_num||'-'||l_release_num||' '||fnd_message.get_string('PO','PO_WF_NOTIF_REV')||' '
3800 ||l_revision_num||' ('||fnd_message.get_string('PO','PO_WF_NOTIF_TOTAL')||'('||
3801 l_rel_currency||') '||
3802 TO_CHAR(l_rel_total, FND_CURRENCY.GET_FORMAT_MASK(l_rel_currency, 30))
3803 ||')</B></font><HR size=1 color=#cccc99>'; */
3804 /*
3805 if(l_acc_req_flag <> 'Y') then
3806 l_document := l_document ||
3807 '- '||fnd_message.get_string('PO','PO_WF_NOTIF_NUM_OF_CHN')||' - '||
3808 l_num_of_changes||' '||fnd_message.get_string('PO','PO_WF_NOTIF_CANCELLED')||' - '||l_num_of_cancels||'</B></font><HR size=1 color=#cccc99>';
3809 end if;*/
3810 /*
3811 end if;
3812
3813 l_document := l_document||'
3814 <TABLE cellpadding=2 cellspacing=1>
3815 <TR>
3816 <TD>
3817 <TABLE cellpadding=2 cellspacing=1>
3818 <TR>
3819 <TD nowrap><font color=black><B>
3820 '||fnd_message.get_string('PO','PO_WF_NOTIF_VENDOR')||'</B></font></TD>
3821 <TD nowrap><font color=black>'||l_supplier_name||'</font></TD>
3822 </TR>
3823 <TR>
3824 <TD nowrap valign=TOP><font color=black><B>
3825 '||fnd_message.get_string('PO','PO_WF_NOTIF_ADDRESS')||'</B></font></TD>
3826 <TD nowrap><font color=black>';
3827
3828 if(l_sup_address_line1 is not null) then
3829 l_document := l_document || l_sup_address_line1||'<BR>';
3830 end if;
3831 if(l_sup_address_line2 is not null) then
3832 l_document := l_document || l_sup_address_line2||'<BR>';
3833 end if;
3834 if(l_sup_address_line3 is not null) then
3835 l_document := l_document || l_sup_address_line3||'<BR>';
3836 end if;
3837
3838 l_document := l_document||l_sup_city||', '||l_sup_state||' '||l_sup_zip||
3839 '</font></TD>
3840 </TR>
3841 <TR>
3842 <TD nowrap><font color=black><B>
3843 '||fnd_message.get_string('PO','PO_WF_NOTIF_FOB')||'</B></font></TD>
3844 <TD nowrap><font color=black>'||l_fob||
3845 '</font></TD>
3846 </TR>
3847
3848
3849 <TR>
3850 <TD nowrap><font color=black><B>
3851 '||fnd_message.get_string('PO','PO_WF_NOTIF_CARRIER')||'</B></font></TD>
3852 <TD nowrap><font color=black>'||l_carrier||
3853 '</font></TD>
3854 </TR>
3855 </TABLE>
3856 </TD>
3857 <TD valign=TOP>
3858 <TABLE cellpadding=2 cellspacing=1>
3859 <TR>
3860 <TD nowrap><font color=black><B>
3861 '||fnd_message.get_string('PO','PO_WF_NOTIF_ORDER_DATE')||'</B></font></TD>
3862 <TD nowrap><font color=black>'||l_order_date||
3863 '</font></TD>
3864 </TR>
3865
3866 <TR>
3867 <TD nowrap valign=TOP><font color=black><B>
3868 '||fnd_message.get_string('PO','PO_WF_NOTIF_SHPTO_ADD')||'</B></font></TD>
3869 <TD nowrap><font color=black>
3870 '||
3871 l_ship_addr_l1||' '||l_ship_addr_l2||' '||l_ship_addr_l3||'<BR>'||
3872 l_ship_city||', '||l_ship_state||' '||l_ship_zip
3873 ||'
3874 </font></TD>
3875 </TR>
3876
3877 </TABLE>
3878 </TD>
3879 </TABLE></P>';
3880 WF_NOTIFICATION.WriteToClob(document,l_document);
3881
3882 if(l_header_cancel = 'N') then
3883 open l_po_ack_csr(l_po_doc_id, l_rel_doc_id, l_revision_num);
3884 fetch l_po_ack_csr
3885 into
3886 lc_line_num,
3887 lc_ship_num,
3888 lc_buyer_pt_num,
3889 lc_old_sup_pt_num,
3890 lc_new_sup_pt_num,
3891 lc_old_prom_date,
3892 lc_new_prom_date,
3893 lc_old_qty,
3894 lc_new_qty,
3895 lc_old_price,
3896 lc_new_price,
3897 lc_action_type,
3898 lc_item_desc,
3899 lc_uom,
3900 lc_ship_to_location,
3901 lc_reason;
3902 close l_po_ack_csr;
3903 if(lc_line_num is not null) then
3904 l_document := '<font size=3 color=#336699 face=arial><b>'||fnd_message.get_string('PO','PO_WF_NOTIF_ACK_RESPONSE')||'</B></font><HR size=1 color=#cccc99>
3905 <TABLE WIDTH=100% cellpadding=2 cellspacing=1>
3906 <TR bgcolor=#cccc99>
3907 <TH align=left><font color=#336699 >'||fnd_message.get_string('PO','PO_WF_NOTIF_LINE_NUMBER')||'</font></TH>
3908 <TH align=left><font color=#336699 >'||fnd_message.get_string('PO','PO_WF_NOTIF_SHIPMENT')||'</font></TH>
3909 <TH align=left><font color=#336699 >'||fnd_message.get_string('PO','PO_WF_NOTIF_ITEM')||'</font></TH>
3910 <TH align=left><font color=#336699 >'||fnd_message.get_string('PO','PO_WF_NOTIF_SUP_ITEM')||'</font></TH>
3911 <TH align=left><font color=#336699 >'||fnd_message.get_string('PO','PO_WF_NOTIF_DOC_DESCRIPTION')||'</font></TH>
3912 <TH align=left><font color=#336699 >'||fnd_message.get_string('PO','PO_WF_NOTIF_UNIT')||'</font></TH>
3913 <TH align=left><font color=#336699 >'||fnd_message.get_string('PO','PO_WF_NOTIF_PRICE')||'</font></TH>
3914 <TH align=left><font color=#336699 >'||fnd_message.get_string('PO','PO_WF_NOTIF_QTY_ORDERED')||'</font></TH>
3915 <TH align=left><font color=#336699 >'||fnd_message.get_string('PO','PO_WF_NOTIF_PROM_DATE')||'</font></TH>
3916 <TH align=left><font color=#336699 >'||fnd_message.get_string('PO','PO_WF_NOTIF_SHIPTO')||'</font></TH>
3917 <TH align=left><font color=#336699 >'||fnd_message.get_string('PO','PO_WF_NOTIF_ACTION')||'</font></TH>
3918 <TH align=left><font color=#336699 >'||fnd_message.get_string('PO','PO_WF_NOTIF_REASON')||'</font></TH>
3919 </TR>
3920 </B>';
3921
3922 WF_NOTIFICATION.WriteToClob(document,l_document);
3923 open l_po_ack_csr(l_po_doc_id, l_rel_doc_id, l_revision_num);
3924 loop
3925 fetch l_po_ack_csr
3926 into
3927 lc_line_num,
3928 lc_ship_num,
3929 lc_buyer_pt_num,
3930 lc_old_sup_pt_num,
3931 lc_new_sup_pt_num,
3932 lc_old_prom_date,
3933 lc_new_prom_date,
3934 lc_old_qty,
3935 lc_new_qty,
3936 lc_old_price,
3937 lc_new_price,
3938 lc_action_type,
3939 lc_item_desc,
3940 lc_uom,
3941 lc_ship_to_location,
3942 lc_reason;
3943 EXIT when l_po_ack_csr%NOTFOUND;
3944
3945 l_old_prom_date := to_char(lc_old_prom_date,fnd_profile.value_wnps('ICX_DATE_FORMAT_MASK')||' HH24:MI:SS');
3946 l_new_prom_date := to_char(lc_new_prom_date,fnd_profile.value_wnps('ICX_DATE_FORMAT_MASK')||' HH24:MI:SS');
3947 lc_line_num := nvl(lc_line_num,'` ');
3948 lc_ship_num:= nvl(lc_ship_num,'` ');
3949 lc_buyer_pt_num := nvl(lc_buyer_pt_num,'` ');
3950 lc_old_sup_pt_num:= nvl(lc_old_sup_pt_num,'` ');
3951 lc_new_sup_pt_num:= nvl(lc_new_sup_pt_num,'` ');
3952 l_old_prom_date:= nvl(l_old_prom_date,'` ');
3953 l_new_prom_date:= nvl(l_new_prom_date,'` ');
3954 lc_old_qty:= nvl(lc_old_qty,'` ');
3955 lc_new_qty:= nvl(lc_new_qty,'` ');
3956 lc_old_price:= nvl(lc_old_price,'` ');
3957 lc_new_price:= nvl(lc_new_price,'` ');
3958 lc_action_type:= nvl(lc_action_type,'` ');
3959 lc_item_desc:= nvl(lc_item_desc,'` ');
3960 lc_uom:= nvl(lc_uom,'` ');
3961 lc_ship_to_location:= nvl(lc_ship_to_location,'` ');
3962 lc_reason := nvl(lc_reason,'` ');
3963
3964
3965 l_document := '
3966 <TR bgcolor=#f7f7e7>
3967
3968 <TD align=left><font color=black>'||lc_line_num||
3969 '</font></TD>
3970 <TD align=left><font color=black>'||lc_ship_num||
3971 '</font></TD>
3972 <TD align=left><font color=black>'||lc_buyer_pt_num||
3973 '</font></TD>
3974 <TD align=left><font color=black>'||lc_old_sup_pt_num||
3975 '</font></TD>
3976 <TD align=left><font color=black>'||lc_item_desc||
3977 '</font></TD>
3978 <TD align=left><font color=black>'||lc_uom||
3979 '</font></TD>
3980 <TD align=left><font color=black>'||lc_old_price||'
3981 </font></TD>
3982 <TD align=left><font color=black>'||lc_old_qty||'
3983 </font></TD>
3984 <TD align=left><font color=black>'||l_old_prom_date||'
3985 </font></TD>
3986 <TD align=left><font color=black>'||lc_ship_to_location||
3987 '</font></TD>
3988 <TD align=left><font color=black>'||lc_action_type||
3989 '</font></TD>
3990 <TD align=left><font color=black>'||lc_reason||
3991 '</font></TD>
3992
3993 </TR>
3994 ';
3995 WF_NOTIFICATION.WriteToClob(document,l_document);
3996
3997 END LOOP;
3998 CLOSE l_po_ack_csr;
3999 WF_NOTIFICATION.WriteToClob(document, '
4000 </TABLE></P>
4001 ');
4002 end if;
4003
4004
4005 lc_line_num := null;
4006 open l_po_chg_req_csr(l_grp_id);
4007 fetch l_po_chg_req_csr
4008 into
4009 lc_line_num,
4010 lc_ship_num,
4011 lc_buyer_pt_num,
4012 lc_old_sup_pt_num,
4013 lc_new_sup_pt_num,
4014 lc_old_prom_date,
4015 lc_new_prom_date,
4016 lc_old_qty,
4017 lc_new_qty,
4018 lc_old_price,
4019 lc_new_price,
4020 lc_action_type,
4021 lc_item_desc,
4022 lc_uom,
4023 lc_ship_to_location,
4024 lc_action_code,
4025 lc_reason,
4026 lc_split;
4027 close l_po_chg_req_csr;
4028 if(lc_line_num is not null) then
4029 l_document := '<font size=3 color=#336699 face=arial><b>'||
4030 fnd_message.get_string('PO', 'PO_WF_NOTIF_CH_CA_REQ')||
4031 '</B></font><HR size=1 color=#cccc99>';
4032 l_document := l_document||'<TABLE><TR>'|| NL;
4033 l_document:= l_document||'<TD class=instructiontext>'||
4034 '<img src=/OA_MEDIA/newupdateditem_status.gif ALT="">'
4035 || fnd_message.get_string('PO', 'PO_WF_NOTIF_NEW_VALUE');
4036 l_document := l_document || '</TD></TR>' || NL;
4037 l_document := l_document || '<TR>'|| NL;
4038 l_document:= l_document||'<TD class=instructiontext>'||
4039 '<img src=/OA_MEDIA/cancelind_status.gif ALT="">'
4040 || fnd_message.get_string('PO', 'PO_WF_NOTIF_CANCEL_PENDING');
4041 l_document := l_document || '</TD></TR>' || NL;
4042 l_document := l_document || '</TABLE>' || NL;
4043 l_document := l_document ||'
4044 <TABLE WIDTH=100% cellpadding=2 cellspacing=1>
4045 <TR bgcolor=#cccc99>
4046 <TH align=left><font color=#336699 >'||fnd_message.get_string('PO','PO_WF_NOTIF_LINE_NUMBER')||'</font></TH>
4047 <TH align=left><font color=#336699 >'||fnd_message.get_string('PO','PO_WF_NOTIF_SHIPMENT')||'</font></TH>
4048 <TH align=left><font color=#336699 >'||fnd_message.get_string('PO','PO_WF_NOTIF_ITEM')||'</font></TH>
4049 <TH align=left><font color=#336699 >'||fnd_message.get_string('PO','PO_WF_NOTIF_SUP_ITEM')||'</font></TH>
4050 <TH align=left><font color=#336699 >'||fnd_message.get_string('PO','PO_WF_NOTIF_DOC_DESCRIPTION')||'</font></TH>
4051 <TH align=left><font color=#336699 >'||fnd_message.get_string('PO','PO_WF_NOTIF_UNIT')||'</font></TH>
4052 <TH align=left><font color=#336699 >'||fnd_message.get_string('PO','PO_WF_NOTIF_PRICE')||'</font></TH>
4053 <TH align=left><font color=#336699 >'||fnd_message.get_string('PO','PO_WF_NOTIF_QTY_ORDERED')||'</font></TH>
4054 <TH align=left><font color=#336699 >'||fnd_message.get_string('PO','PO_WF_NOTIF_PROM_DATE')||'</font></TH>
4055 <TH align=left><font color=#336699 >'||fnd_message.get_string('PO','PO_WF_NOTIF_SHIPTO')||'</font></TH>
4056 <TH align=left><font color=#336699 >'||fnd_message.get_string('PO','PO_WF_NOTIF_ACTION')||'</font></TH>
4057 <TH align=left><font color=#336699 >'||fnd_message.get_string('PO','PO_WF_NOTIF_REASON')||'</font></TH>
4058 <TH align=left><font color=#336699 >'||fnd_message.get_string('PO','PO_WF_NOTIF_SPLIT')||'</font></TH>
4059 </TR>
4060 </B>';
4061
4062 WF_NOTIFICATION.WriteToClob(document,l_document);
4063 --, l_po_doc_id, l_rel_doc_id
4064 open l_po_chg_req_csr(l_grp_id);
4065 loop
4066 fetch l_po_chg_req_csr
4067 into
4068 lc_line_num,
4069 lc_ship_num,
4070 lc_buyer_pt_num,
4071 lc_old_sup_pt_num,
4072 lc_new_sup_pt_num,
4073 lc_old_prom_date,
4074 lc_new_prom_date,
4075 lc_old_qty,
4076 lc_new_qty,
4077 lc_old_price,
4078 lc_new_price,
4079 lc_action_type,
4080 lc_item_desc,
4081 lc_uom,
4082 lc_ship_to_location,
4083 lc_action_code,
4084 lc_reason,
4085 lc_split;
4086 EXIT when l_po_chg_req_csr%NOTFOUND;
4087
4088 if(lc_split is not null) then
4089 lc_old_sup_pt_num := nvl(lc_old_sup_pt_num,lc_new_sup_pt_num);
4090 lc_new_sup_pt_num := null;
4091
4092 lc_old_price:=nvl(lc_old_price,lc_new_price);
4093 lc_new_price:= null;
4094
4095 lc_new_prom_date:= nvl(lc_new_prom_date,lc_old_prom_date);
4096 lc_old_prom_date:= null;
4097
4098 lc_new_qty:=nvl(lc_new_qty,lc_old_qty);
4099 lc_old_qty:= null;
4100 end if;
4101
4102 if(fnd_timezones.timezones_enabled()='Y') then
4103 fnd_date_tz.init_timezones_for_fnd_date(true);
4104 l_old_prom_date := fnd_date.date_to_displayDT(lc_old_prom_date);
4105 l_new_prom_date := fnd_date.date_to_displayDT(lc_new_prom_date);
4106 else
4107 l_old_prom_date := to_char(lc_old_prom_date,fnd_profile.value_wnps('ICX_DATE_FORMAT_MASK')||' HH24:MI:SS');
4108 l_new_prom_date := to_char(lc_new_prom_date,fnd_profile.value_wnps('ICX_DATE_FORMAT_MASK')||' HH24:MI:SS');
4109 end if;
4110
4111
4112 lc_line_num := nvl(lc_line_num,'` ');
4113 lc_ship_num:= nvl(lc_ship_num,'` ');
4114 lc_buyer_pt_num:= nvl(lc_buyer_pt_num,'` ');
4115 lc_old_sup_pt_num:= nvl(lc_old_sup_pt_num,'` ');
4116 lc_new_sup_pt_num:= nvl(lc_new_sup_pt_num,'` ');
4117 l_old_prom_date:= nvl(l_old_prom_date,'` ');
4118 l_new_prom_date:= nvl(l_new_prom_date,'` ');
4119 lc_old_qty:= nvl(lc_old_qty,'` ');
4120 lc_new_qty:= nvl(lc_new_qty,'` ');
4121 lc_old_price:= nvl(lc_old_price,'` ');
4122 lc_new_price:= nvl(lc_new_price,'` ');
4123 lc_action_type:= nvl(lc_action_type,'` ');
4124 lc_item_desc:= nvl(lc_item_desc,'` ');
4125 lc_uom:= nvl(lc_uom,'` ');
4126 lc_ship_to_location:= nvl(lc_ship_to_location,'` ');
4127 lc_reason := nvl(lc_reason,'` ');
4128 lc_split := nvl(lc_split,'` ');
4129
4130
4131 l_document := '
4132 <TR bgcolor=#f7f7e7>
4133
4134 <TD align=left><font color=black>'||lc_line_num||
4135 '</font></TD> ';
4136
4137 if(lc_action_code = 'CANCELLATION') then
4138 l_document := l_document ||'
4139 <TD align=left><font color=black>
4140 <TABLE>
4141 <TR>
4142 <TD>
4143 <img src=/OA_MEDIA/cancelind_status.gif ALT="">
4144 </TD>
4145 <TD alight=right>'
4146 ||lc_ship_num||
4147 '</TD>
4148 </TR>
4149 </TABLE>
4150 </font></TD> ';
4151 else
4152 l_document := l_document ||'
4153 <TD align=left><font color=black>'||lc_ship_num||
4154 '</font></TD> ';
4155 end if;
4156 l_document := l_document ||'
4157 <TD align=left><font color=black>'||lc_buyer_pt_num||
4158 '</font></TD> ';
4159
4160 if(lc_new_sup_pt_num = '` ') then
4161 l_document := l_document || '
4162 <TD align=left><font color=black>'||lc_old_sup_pt_num||'
4163 </font></TD>';
4164 else
4165 l_document := l_document || '
4166 <TD align=left><font color=black>
4167 <table>
4168 <tr>
4169 <td>'||lc_old_sup_pt_num||'
4170 </td>
4171 </tr>
4172 <tr>
4173 <td>'||lc_new_sup_pt_num||'
4174 </td>
4175 <td>
4176 <img src=/OA_MEDIA/newupdateditem_status.gif ALT="">
4177 </td>
4178 </tr>
4179 </table>
4180 </font></TD>';
4181 end if;
4182
4183 l_document := l_document || '
4184 <TD align=left><font color=black>'||lc_item_desc||
4185 '</font></TD>
4186
4187 <TD align=left><font color=black>'||lc_uom||
4188 '</font></TD> ';
4189
4190 if(lc_new_price = '` ') then
4191 l_document := l_document || '
4192 <TD align=left><font color=black>'||lc_old_price||'
4193 </font></TD>';
4194 else
4195 l_document := l_document || '
4196 <TD align=left><font color=black>
4197 <table>
4198 <tr>
4199 <td>'||lc_old_price||'
4200 </td>
4201 </tr>
4202 <tr>
4203 <td>'||lc_new_price||'
4204 </td>
4205 <td>
4206 <img src=/OA_MEDIA/newupdateditem_status.gif ALT="">
4207 </td>
4208 </tr>
4209 </table>
4210 </font></TD>';
4211 end if;
4212
4213 if(lc_new_qty = '` ') then
4214 l_document := l_document || '
4215 <TD align=left><font color=black>'||lc_old_qty||'
4216 </font></TD>';
4217 elsif(lc_split <> '` ') then
4218 l_document := l_document || '
4219 <TD align=left><font color=black>
4220 <table>
4221 <tr>
4222 <td>'||lc_new_qty||'
4223 </td>
4224 <td>
4225 <img src=/OA_MEDIA/newupdateditem_status.gif ALT="">
4226 </td>
4227 </tr>
4228 </table>
4229 </font></TD>';
4230 else
4231 l_document := l_document || '
4232 <TD align=left><font color=black>
4233 <table>
4234 <tr>
4235 <td>'||lc_old_qty||'
4236 </td>
4237 </tr>
4238 <tr>
4239 <td>'||lc_new_qty||'
4240 </td>
4241 <td>
4242 <img src=/OA_MEDIA/newupdateditem_status.gif ALT="">
4243 </td>
4244 </tr>
4245 </table>
4246 </font></TD>';
4247 end if;
4248
4249 if(l_new_prom_date = '` ') then
4250 l_document := l_document || '
4251 <TD align=left><font color=black>'||l_old_prom_date||'
4252 </font></TD>';
4253 elsif(lc_split <> '` ' OR l_old_prom_date = '` ') then
4254 l_document := l_document || '
4255 <TD align=left><font color=black>
4256 <table>
4257 <tr>
4258 <td>'||l_new_prom_date||'
4259 </td>
4260 <td>
4261 <img src=/OA_MEDIA/newupdateditem_status.gif ALT="">
4262 </td>
4263 </tr>
4264 </table>
4265 </font></TD>';
4266 else
4267 l_document := l_document || '
4268 <TD align=left><font color=black>
4269 <table>
4270 <tr>
4271 <td>'||l_old_prom_date||'
4272 </td>
4273 </tr>
4274 <tr>
4275 <td>'||l_new_prom_date||'
4276 </td>
4277 <td>
4278 <img src=/OA_MEDIA/newupdateditem_status.gif ALT="">
4279 </td>
4280 </tr>
4281 </table>
4282 </font></TD>';
4283 end if;
4284 l_document := l_document || '
4285
4286 <TD align=left><font color=black>'||lc_ship_to_location||
4287 '</font></TD>
4288
4289 <TD align=left><font color=black>'||lc_action_type||
4290 '</font></TD>
4291
4292 <TD align=left><font color=black>'||lc_reason||
4293 '</font></TD>
4294
4295 <TD align=left><font color=black>'||lc_split||
4296 '</font></TD>
4297
4298 </TR>
4299 ';
4300 WF_NOTIFICATION.WriteToClob(document,l_document);
4301
4302 END LOOP;
4303 CLOSE l_po_chg_req_csr;
4304 WF_NOTIFICATION.WriteToClob(document, '
4305 </TABLE></P>
4306 ');
4307 end if;
4308 open l_header_changes_csr(l_grp_id);
4309 fetch l_header_changes_csr into l_additional_changes;
4310 close l_header_changes_csr;
4311
4312 if(l_additional_changes is not null) then
4313 l_document := '<BR><B>'||fnd_message.get_string('PO','PO_WF_NOTIF_ADD_CHN_REQ')||'</B>'||
4314 ' `  '||l_additional_changes||'<BR>';
4315 WF_NOTIFICATION.WriteToClob(document,l_document);
4316 end if;
4317 else
4318 fnd_message.set_name('PO','PO_WF_NOTIF_CAN_ENTIER');
4319 fnd_message.set_token('DOC',l_document_type);
4320 l_document := fnd_message.get;
4321 WF_NOTIFICATION.WriteToClob(document,l_document);
4322 end if;
4323 exception when others then
4324 IF g_fnd_debug = 'Y' THEN
4325 FND_LOG.string(FND_LOG.level_unexpected, g_module_prefix ||
4326 l_api_name || '.others_exception', l_progress||':'||sqlerrm);
4327 END IF;
4328 WF_NOTIFICATION.WriteToClob(document,'Exception occured:'||sqlerrm); */
4329 null;
4330
4331 END GEN_NTF_FOR_BUYER_SUP_CHG;
4332
4333
4334 /*
4335 *Generate Notification for Supplier, informing him/her of Buyer's response to supplier's change request.
4336 */
4337 PROCEDURE GEN_NTF_FOR_SUP_BUY_RP( p_chg_req_grp_id IN number,
4338 display_type in Varchar2,
4339 document in out NOCOPY clob,
4340 document_type in out NOCOPY varchar2)
4341 IS
4342 /* -- RDP changes replaced by Jrad Notification
4343 l_api_name varchar2(50):='GEN_NTF_FOR_SUP_BUY_RP';
4344 l_progress varchar2(5) := '000';
4345 l_po_release_id number;
4346 l_rel_total number;
4347 l_rel_currency po_headers.currency_code%TYPE;
4348 --l_blanket_num number;
4349 l_blanket_num po_headers_all.segment1%TYPE;
4350 --l_release_num number;
4351 l_release_num po_releases_all.release_num%TYPE;
4352 l_document varchar2(32000);
4353 l_document_header_id number;
4354 l_document_type varchar2(2000);
4355 l_po_num po_headers_all.segment1%TYPE;
4356 l_revision_num number;
4357 l_po_total number;
4358 l_po_currency po_headers.currency_code%TYPE;
4359 l_vendor_id number;
4360 l_vendor_site_id number;
4361 l_supplier_name po_vendors.vendor_name%TYPE;
4362 l_sup_address_line1 po_vendor_sites_all.address_line1%TYPE;
4363 l_sup_address_line2 po_vendor_sites_all.address_line2%TYPE;
4364 l_sup_address_line3 po_vendor_sites_all.address_line3%TYPE;
4365 l_sup_city po_vendor_sites_all.city%TYPE;
4366 l_sup_state po_vendor_sites_all.state%TYPE;
4367 l_sup_zip po_vendor_sites_all.zip%TYPE;
4368 l_order_date varchar2(2000);
4369 l_fob po_headers_all.fob_lookup_code%TYPE;
4370 l_carrier po_headers_all.ship_via_lookup_code%TYPE;
4371 l_ship_to_id number;
4372 l_ship_addr_l1 hr_locations_all.address_line_1%TYPE;
4373 l_ship_addr_l2 hr_locations_all.address_line_2%TYPE;
4374 l_ship_addr_l3 hr_locations_all.address_line_3%TYPE;
4375 l_ship_city hr_locations_all.town_or_city%TYPE;
4376 l_ship_state hr_locations_all.region_1%TYPE;
4377 l_ship_zip hr_locations_all.postal_code%TYPE;
4378
4379 l_base_url varchar2(2000);
4380 l_base_url_tag varchar2(2000);
4381
4382 l_document1 VARCHAR2(32000) := '';
4383 l_type_lookup_code po_headers_all.type_lookup_code%TYPE;
4384 l_global_agreement_flag po_headers_all.GLOBAL_AGREEMENT_FLAG%TYPE := 'F';
4385
4386 l_old_prom_date varchar2(2000);
4387 l_new_prom_date varchar2(2000);
4388
4389 l_doc_hdr_info varchar2(2000);
4390 lc_action_code po_change_requests.action_type%type;
4391 lc_line_num varchar2(2000);
4392 lc_ship_num varchar2(2000);
4393 lc_old_sup_pt_num po_lines_all.vendor_product_num%TYPE;
4394 lc_new_sup_pt_num po_change_requests.new_supplier_part_number%TYPE;
4395 lc_old_prom_date date;
4396 lc_new_prom_date date;
4397 lc_old_qty varchar2(2000);
4398 lc_new_qty varchar2(2000);
4399 lc_old_price varchar2(2000);
4400 lc_new_price varchar2(2000);
4401 lc_response varchar2(2000);
4402 lc_item_desc po_lines_all.item_description%TYPE;
4403 lc_uom po_lines_all.unit_meas_lookup_code%TYPE;
4404 lc_ship_to_location hr_locations_all.location_code%TYPE;
4405 lc_reason po_change_requests.response_reason%TYPE;
4406 lc_split varchar2(2000);
4407
4408
4409 cursor l_po_chg_req_csr(grp_id number) is
4410 select
4411 to_char(LINE_NUM),
4412 to_char(SHIPMENT_NUM),
4413 OLD_SUP_PT_NUM,
4414 NEW_SUP_PT_NUM,
4415 OLD_PROM_DATE,
4416 NEW_PROM_DATE,
4417 to_char(OLD_QTY),
4418 to_char(NEW_QTY),
4419 to_char(OLD_PRICE),
4420 to_char(NEW_PRICE),
4421 RESPONSE,
4422 ITEM_DESCRIPTION,
4423 UOM,
4424 SHIP_TO_LOCATION,
4425 REASON,
4426 SPLIT,
4427 ACTION_CODE
4428 from(
4429 -- Respond to Changes on Line for Standard PO
4430 select
4431 pcr.document_line_number LINE_NUM,
4432 pcr.document_shipment_number SHIPMENT_NUM,
4433 pcr.old_supplier_part_number OLD_SUP_PT_NUM,
4434 pcr.new_supplier_part_number NEW_SUP_PT_NUM,
4435 to_date(null,'DD/MM/YYYY') OLD_PROM_DATE,
4436 to_date(null,'DD/MM/YYYY') NEW_PROM_DATE,
4437 nvl(pcr.old_quantity, pla.quantity) OLD_QTY,
4438 to_number(null) NEW_QTY,
4439 nvl(pcr.old_price,pla.unit_price) OLD_PRICE,
4440 pcr.new_price NEW_PRICE,
4441 decode(pcr.REQUEST_STATUS,'ACCEPTED',fnd_message.get_string('PO','PO_WF_NOTIF_ACCEPTED'),
4442 'REJECTED',fnd_message.get_string('PO','PO_WF_NOTIF_REJ'),'Error') RESPONSE,
4443 pla.item_description ITEM_DESCRIPTION,
4444 pla.unit_meas_lookup_code UOM,
4445 null SHIP_TO_LOCATION,
4446 pcr.response_reason REASON,
4447 null SPLIT,
4448 pcr.action_type ACTION_CODE
4449 from po_change_requests pcr, po_lines_archive_all pla
4450 where pla.po_line_id = pcr.document_line_id
4451 and pcr.change_request_group_id =grp_id
4452 --and pcr.document_revision_num = pla.revision_num
4453 and pcr.request_level = 'LINE'
4454 and pla.latest_external_flag = 'Y'
4455 UNION ALL
4456 --Respond to changes on Shipment for Releases AND Standard PO
4457 select
4458 pla.line_num LINE_NUM,
4459 pcr.document_shipment_number SHIPMENT_NUM,
4460 pla.vendor_product_num OLD_SUP_PT_NUM,
4461 null NEW_SUP_PT_NUM,
4462 pcr.old_promised_date OLD_PROM_DATE,
4463 pcr.new_promised_date NEW_PROM_DATE,
4464 nvl(pcr.old_quantity,plla.quantity) OLD_QTY,
4465 pcr.new_quantity NEW_QTY,
4466 nvl(pcr.old_price,plla.price_override) OLD_PRICE,
4467 pcr.new_price NEW_PRICE,
4468 decode(pcr.REQUEST_STATUS,'ACCEPTED',fnd_message.get_string('PO','PO_WF_NOTIF_ACCEPTED'),
4469 'REJECTED',fnd_message.get_string('PO','PO_WF_NOTIF_REJ'),'Error') RESPONSE,
4470 pla.item_description ITEM_DESCRIPTION,
4471 nvl(plla.unit_meas_lookup_code,pla.unit_meas_lookup_code) UOM,
4472 nvl(hla.location_code, substr(rtrim(hz.address1)||'-'||rtrim(hz.city),1,60)) SHIP_TO_LOCATION,
4473 pcr.response_reason REASON,
4474 decode(pcr.parent_line_location_id, null, null, fnd_message.get_string('PO','PO_WF_NOTIF_YES')) SPLIT,
4475 pcr.action_type ACTION_CODE
4476
4477 from po_change_requests pcr, po_lines_archive_all pla, po_line_locations_archive_all plla,
4478 hr_locations_all hla, hz_locations hz
4479 where change_request_group_id =grp_id
4480 and pla.po_line_id = pcr.document_line_id
4481 and pla.latest_external_flag = 'Y'
4482 and plla.line_location_id = pcr.document_line_location_id
4483 --and pcr.document_revision_num = pla.revision_num
4484 --and pcr.document_revision_num = plla.revision_num
4485 and plla.latest_external_flag = 'Y'
4486 and request_level = 'SHIPMENT'
4487 and pcr.new_supplier_order_line_number is null
4488 and hla.location_id(+) = plla.ship_to_location_id
4489 and plla.SHIP_TO_LOCATION_ID = hz.LOCATION_ID(+)
4490 and pcr.parent_line_location_id is null
4491 UNION ALL
4492 --Respond to changes on Split Shipment
4493 select
4494 pla.line_num LINE_NUM,
4495 pcr.document_shipment_number SHIPMENT_NUM,
4496 pla.vendor_product_num OLD_SUP_PT_NUM,
4497 null NEW_SUP_PT_NUM,
4498 pcr.old_promised_date OLD_PROM_DATE,
4499 pcr.new_promised_date NEW_PROM_DATE,
4500 pcr.old_quantity OLD_QTY,
4501 pcr.new_quantity NEW_QTY,
4502 nvl(pcr.old_price,plla.price_override) OLD_PRICE,
4503 pcr.new_price NEW_PRICE,
4504 decode(pcr.REQUEST_STATUS,'ACCEPTED',fnd_message.get_string('PO','PO_WF_NOTIF_ACCEPTED'),
4505 'REJECTED',fnd_message.get_string('PO','PO_WF_NOTIF_REJ'),'Error') RESPONSE,
4506 pla.item_description ITEM_DESCRIPTION,
4507 nvl(plla.unit_meas_lookup_code,pla.unit_meas_lookup_code) UOM,
4508 nvl(hla.location_code, substr(rtrim(hz.address1)||'-'||rtrim(hz.city),1,60)) SHIP_TO_LOCATION,
4509 pcr.response_reason REASON,
4510 decode(pcr.parent_line_location_id, null, null, fnd_message.get_string('PO','PO_WF_NOTIF_YES')) SPLIT,
4511 pcr.action_type ACTION_CODE
4512 from po_change_requests pcr, po_lines_archive_all pla, po_line_locations_archive_all plla,
4513 hr_locations_all hla, hz_locations hz
4514 where change_request_group_id =grp_id
4515 and pla.po_line_id = pcr.document_line_id
4516 and pla.latest_external_flag = 'Y'
4517 and plla.line_location_id = pcr.parent_line_location_id
4518 --and pcr.document_revision_num = pla.revision_num
4519 --and pcr.document_revision_num = plla.revision_num
4520 and plla.latest_external_flag = 'Y'
4521 and request_level = 'SHIPMENT'
4522 and hla.location_id(+) = plla.ship_to_location_id
4523 and plla.SHIP_TO_LOCATION_ID = hz.LOCATION_ID(+)
4524
4525 )
4526 order by LINE_NUM,nvl(SHIPMENT_NUM,0);
4527
4528 l_id number;
4529 l_header_response po_change_requests.request_status%type;
4530 l_header_cancel varchar2(1);
4531
4532 cursor l_header_cancel_csr(grp_id number) is
4533 select change_request_id,
4534 request_status
4535 from po_change_requests
4536 where change_request_group_id = grp_id
4537 and action_type = 'CANCELLATION'
4538 and request_level = 'HEADER';
4539
4540 l_additional_changes po_change_requests.additional_changes%type;
4541
4542 cursor l_header_changes_csr(grp_id number)
4543 is
4544 select additional_changes, request_status
4545 from po_change_requests
4546 where change_request_group_id = grp_id
4547 and request_level = 'HEADER'
4548 and additional_changes is not null; */
4549
4550 BEGIN
4551 /* select distinct
4552 document_header_id,
4553 document_type,
4554 po_release_id
4555 into
4556 l_document_header_id,
4557 l_document_type,
4558 l_po_release_id
4559 from po_change_requests
4560 where change_request_group_id = p_chg_req_grp_id;
4561
4562 l_progress := '001';
4563 l_base_url := POS_URL_PKG.get_external_url;
4564
4565 l_base_url_tag := '<base href= "'||l_base_url||'">';
4566 l_progress := '001a';
4567 l_header_cancel := 'N';
4568 if(p_chg_req_grp_id is not null) then
4569 open l_header_cancel_csr(p_chg_req_grp_id);
4570 fetch l_header_cancel_csr
4571 into l_id,
4572 l_header_response;
4573 close l_header_cancel_csr;
4574 if(l_id is not null) then
4575 l_header_cancel := 'Y';
4576 end if;
4577 end if;
4578
4579 if(l_po_release_id is null) then
4580 select segment1,
4581 revision_num,
4582 pos_totals_po_sv.get_po_total(po_header_id),
4583 currency_code,
4584 vendor_id,
4585 vendor_site_id,
4586 to_char(creation_date, fnd_profile.value_wnps('ICX_DATE_FORMAT_MASK')||' HH24:MI:SS'),
4587 fob_lookup_code,
4588 ship_via_lookup_code,
4589 ship_to_location_id,
4590 type_lookup_code,
4591 GLOBAL_AGREEMENT_FLAG
4592 into
4593 l_po_num,
4594 l_revision_num,
4595 l_po_total,
4596 l_po_currency,
4597 l_vendor_id,
4598 l_vendor_site_id,
4599 l_order_date,
4600 l_fob,
4601 l_carrier,
4602 l_ship_to_id,
4603 l_type_lookup_code,
4604 l_global_agreement_flag
4605 from po_headers_all
4606 where po_header_id = l_document_header_id;
4607 else
4608 select ph.segment1,
4609 pr.release_num,
4610 pr.revision_num,
4611 pos_totals_po_sv.get_release_total(pr.po_release_id),
4612 ph.currency_code,
4613 ph.vendor_id,
4614 ph.vendor_site_id,
4615 to_char(pr.creation_date, fnd_profile.value_wnps('ICX_DATE_FORMAT_MASK')||' HH24:MI:SS'),
4616 ph.fob_lookup_code,
4617 ph.ship_via_lookup_code,
4618 ph.ship_to_location_id,
4619 ph.type_lookup_code,
4620 global_agreement_flag
4621 into
4622 l_blanket_num,
4623 l_release_num,
4624 l_revision_num,
4625 l_rel_total,
4626 l_rel_currency,
4627 l_vendor_id,
4628 l_vendor_site_id,
4629 l_order_date,
4630 l_fob,
4631 l_carrier,
4632 l_ship_to_id,
4633 l_type_lookup_code,
4634 l_global_agreement_flag
4635 from po_releases_all pr,
4636 po_headers_all ph
4637 where pr.po_release_id = l_po_release_id
4638 and pr.po_header_id = ph.po_header_id;
4639 end if;
4640 l_progress := '002';
4641 select vendor_name
4642 into l_supplier_name
4643 from po_vendors
4644 where vendor_id = l_vendor_id;
4645
4646 select
4647 address_line1,
4648 address_line2,
4649 address_line3,
4650 city,
4651 state,
4652 zip
4653 into
4654 l_sup_address_line1,
4655 l_sup_address_line2,
4656 l_sup_address_line3,
4657 l_sup_city,
4658 l_sup_state,
4659 l_sup_zip
4660 from po_vendor_sites_all
4661 where vendor_site_id = l_vendor_site_id;
4662
4663 select
4664 address_line_1,
4665 address_line_2,
4666 address_line_3,
4667 town_or_city,
4668 region_1,
4669 postal_code
4670 into
4671 l_ship_addr_l1,
4672 l_ship_addr_l2,
4673 l_ship_addr_l3,
4674 l_ship_city,
4675 l_ship_state,
4676 l_ship_zip
4677 from hr_locations_all
4678 where location_id = l_ship_to_id;
4679 l_progress := '003';
4680 if (display_type = 'text/html') then
4681
4682 if(l_po_release_id is null) then
4683 if(l_type_lookup_code = 'STANDARD') then
4684 l_doc_hdr_info := fnd_message.get_string('PO','PO_WF_NOTIF_STD_PO')||' '||l_po_num;
4685 elsif (l_global_agreement_flag = 'Y' and l_type_lookup_code = 'BLANKET') then
4686 l_doc_hdr_info := fnd_message.get_string('PO','PO_GA_TYPE') ||' '||l_po_num;
4687 elsif(l_type_lookup_code = 'BLANKET') then
4688 l_doc_hdr_info := fnd_message.get_string('PO','PO_WF_NOTIF_BLANKET')||' '||l_po_num;
4689 l_po_total := pos_totals_po_sv.get_po_archive_total(l_document_header_id,l_revision_num,
4690 l_type_lookup_code );
4691 elsif(l_type_lookup_code = 'CONTRACT') then
4692 l_doc_hdr_info := fnd_message.get_string('PO','PO_POTYPE_CNTR')||' '||l_po_num;
4693 elsif(l_type_lookup_code = 'PLANNED') then
4694 l_doc_hdr_info := fnd_message.get_string('PO','PO_WF_NOTIF_PLAN_PO')||' '||l_po_num;
4695 end if;
4696 l_document :=l_base_url_tag|| '
4697 <font size=3 color=#336699 face=arial><b>'||l_doc_hdr_info||' '||
4698 fnd_message.get_string('PO','PO_WF_NOTIF_REV')||' '
4699 ||l_revision_num||' ('||fnd_message.get_string('PO','PO_WF_NOTIF_TOTAL')||'('||l_po_currency||')'||
4700 TO_CHAR(l_po_total, FND_CURRENCY.GET_FORMAT_MASK(l_po_currency, 30))
4701 ||')</B></font><HR size=1 color=#cccc99>';
4702
4703 else
4704 if(l_type_lookup_code = 'BLANKET') then
4705 l_doc_hdr_info := fnd_message.get_string('PO','PO_WF_NOTIF_BKT_REL')||' '||l_blanket_num||'-'||l_release_num;
4706 elsif(l_type_lookup_code = 'PLANNED') then
4707 l_doc_hdr_info := fnd_message.get_string('PO','PO_WF_NOTIF_SCH_REL')||' '||l_blanket_num||'-'||l_release_num;
4708 end if;
4709 l_document :=l_base_url_tag|| '
4710 <font size=3 color=#336699 face=arial><b>'||l_doc_hdr_info||
4711 ' '||fnd_message.get_string('PO','PO_WF_NOTIF_REV')||' '
4712 ||l_revision_num||' ('||fnd_message.get_string('PO','PO_WF_NOTIF_TOTAL')||'('||
4713 l_rel_currency||')'||
4714 TO_CHAR(l_rel_total, FND_CURRENCY.GET_FORMAT_MASK(l_rel_currency, 30))
4715 ||')</B></font><HR size=1 color=#cccc99>';
4716
4717 end if;
4718 l_progress := '004';
4719 l_document := l_document || '
4720 <TABLE cellpadding=2 cellspacing=1>
4721 <TR>
4722 <TD>
4723 <TABLE cellpadding=2 cellspacing=1>
4724 <TR>
4725 <TD nowrap><font color=black><B>
4726 '||fnd_message.get_string('PO','PO_WF_NOTIF_VENDOR')||'</B></font></TD>
4727 <TD nowrap><font color=black>'||l_supplier_name||'</font></TD>
4728 </TR>
4729 <TR>
4730 <TD nowrap valign=TOP><font color=black><B>
4731 '||fnd_message.get_string('PO','PO_WF_NOTIF_ADDRESS')||'</B></font></TD>
4732 <TD nowrap><font color=black>'||l_sup_address_line1||' '||l_sup_address_line2||' '||
4733 l_sup_address_line3||'<BR>'||l_sup_city||', '||l_sup_state||' '||l_sup_zip||
4734 '</font></TD>
4735 </TR>
4736 <TR>
4737 <TD nowrap><font color=black><B>
4738 '||fnd_message.get_string('PO','PO_WF_NOTIF_FOB')||'</B></font></TD>
4739 <TD nowrap><font color=black>'||l_fob||
4740 '</font></TD>
4741 </TR>
4742
4743
4744 <TR>
4745 <TD nowrap><font color=black><B>
4746 '||fnd_message.get_string('PO','PO_WF_NOTIF_CARRIER')||'</B></font></TD>
4747 <TD nowrap><font color=black>'||l_carrier||
4748 '</font></TD>
4749 </TR>
4750 </TABLE>
4751 </TD>
4752 <TD valign=TOP>
4753 <TABLE cellpadding=2 cellspacing=1>
4754 <TR>
4755 <TD nowrap><font color=black><B>
4756 '||fnd_message.get_string('PO','PO_WF_NOTIF_ORDER_DATE')||'</B></font></TD>
4757 <TD nowrap><font color=black>'||l_order_date||
4758 '</font></TD>
4759 </TR>
4760
4761 <TR>
4762 <TD nowrap valign=TOP><font color=black><B>
4763 '||fnd_message.get_string('PO','PO_WF_NOTIF_SHPTO_ADD')||'</B></font></TD>
4764 <TD nowrap><font color=black>';
4765 if(l_ship_addr_l1 is not null) then
4766 l_document := l_document || l_ship_addr_l1||'<BR>';
4767 end if;
4768 if(l_ship_addr_l2 is not null) then
4769 l_document := l_document || l_ship_addr_l2||'<BR>';
4770 end if;
4771 if(l_ship_addr_l3 is not null) then
4772 l_document := l_document || l_ship_addr_l3||'<BR>';
4773 end if;
4774
4775
4776 l_document := l_document || l_ship_city||', '||l_ship_state||' '||l_ship_zip
4777 ||'
4778 </font></TD>
4779 </TR>
4780
4781 </TABLE>
4782 </TD>
4783 </TABLE></P>';
4784
4785 WF_Notification.WriteToClob(document,l_document);
4786 if(l_header_cancel = 'N') then
4787 l_document := '<font size=3 color=#336699 face=arial><b>'||fnd_message.get_string('PO', 'PO_WF_NOTIF_PO_DETAILS')||'</B></font><HR size=1 color=#cccc99>';
4788 --LEGENDS
4789 l_document := l_document||'<TABLE><TR>'|| NL;
4790 l_document:= l_document||'<TD class=instructiontext>'||
4791 '<img src=/OA_MEDIA/newupdateditem_status.gif ALT="">'
4792 || fnd_message.get_string('PO', 'PO_WF_NOTIF_NEW_VALUE');
4793 l_document := l_document || '</TD></TR>' || NL;
4794 l_document := l_document || '<TR>'|| NL;
4795 l_document:= l_document||'<TD class=instructiontext>'||
4796 '<img src=/OA_MEDIA/cancelind_status.gif ALT="">'
4797 || fnd_message.get_string('PO', 'PO_WF_NOTIF_CANCEL_PENDING');
4798 l_document := l_document || '</TD></TR>' || NL;
4799 l_document := l_document || '</TABLE>' || NL;
4800
4801 l_document := l_document ||
4802 '<TABLE WIDTH=100% cellpadding=2 cellspacing=1>
4803 <TR bgcolor=#cccc99>
4804 <TH align=left><font color=#336699 >'||fnd_message.get_string('PO','PO_WF_NOTIF_LINE_NUMBER')||'</font></TH>
4805 <TH align=left><font color=#336699 >'||fnd_message.get_string('PO','PO_WF_NOTIF_SHIPMENT')||'</font></TH>
4806 <TH align=left><font color=#336699 >'||fnd_message.get_string('PO','PO_WF_NOTIF_SUP_ITEM')||'</font></TH>
4807 <TH align=left><font color=#336699 >'||fnd_message.get_string('PO','PO_WF_NOTIF_DOC_DESCRIPTION')||'</font></TH>
4808 <TH align=left><font color=#336699 >'||fnd_message.get_string('PO','PO_WF_NOTIF_UNIT')||'</font></TH>
4809 <TH align=left><font color=#336699 >'||fnd_message.get_string('PO','PO_WF_NOTIF_PRICE')||'</font></TH>
4810 <TH align=left><font color=#336699 >'||fnd_message.get_string('PO','PO_WF_NOTIF_QTY_ORDERED')||'</font></TH>
4811 <TH align=left><font color=#336699 >'||fnd_message.get_string('PO','PO_WF_NOTIF_PROM_DATE')||'</font></TH>
4812 <TH align=left><font color=#336699 >'||fnd_message.get_string('PO','PO_WF_NOTIF_SHIPTO')||'</font></TH>
4813 <TH align=left><font color=#336699 >'||fnd_message.get_string('PO','PO_WF_NOTIF_RESPONSE')||'</font></TH>
4814 <TH align=left><font color=#336699 >'||fnd_message.get_string('PO','PO_WF_NOTIF_REASON')||'</font></TH>
4815 <TH align=left><font color=#336699 >'||fnd_message.get_string('PO','PO_WF_NOTIF_SPLIT')||'</font></TH>
4816 </TR>
4817 </B>';
4818 WF_NOTIFICATION.WriteToClob(document,l_document);
4819 open l_po_chg_req_csr(p_chg_req_grp_id);
4820 loop
4821 fetch l_po_chg_req_csr
4822 into
4823 lc_line_num,
4824 lc_ship_num,
4825 lc_old_sup_pt_num,
4826 lc_new_sup_pt_num,
4827 lc_old_prom_date,
4828 lc_new_prom_date,
4829 lc_old_qty,
4830 lc_new_qty,
4831 lc_old_price,
4832 lc_new_price,
4833 lc_response,
4834 lc_item_desc,
4835 lc_uom,
4836 lc_ship_to_location,
4837 lc_reason,
4838 lc_split,
4839 lc_action_code;
4840 EXIT when l_po_chg_req_csr%NOTFOUND;
4841 if(lc_split is not null) then
4842 lc_old_sup_pt_num := nvl(lc_old_sup_pt_num,lc_new_sup_pt_num);
4843 lc_new_sup_pt_num := null;
4844
4845 lc_old_price:=nvl(lc_old_price,lc_new_price);
4846 lc_new_price:= null;
4847
4848
4849 lc_new_prom_date := nvl(lc_new_prom_date,lc_old_prom_date);
4850 lc_old_prom_date := null;
4851
4852 lc_new_qty:= nvl(lc_new_qty,lc_old_qty);
4853 lc_old_qty:= null;
4854 end if;
4855
4856 if(fnd_timezones.timezones_enabled()='Y') then
4857 fnd_date_tz.init_timezones_for_fnd_date(true);
4858 l_old_prom_date := fnd_date.date_to_displayDT(lc_old_prom_date);
4859 l_new_prom_date := fnd_date.date_to_displayDT(lc_new_prom_date);
4860 else
4861 l_old_prom_date := to_char(lc_old_prom_date,fnd_profile.value_wnps('ICX_DATE_FORMAT_MASK')||' HH24:MI:SS');
4862 l_new_prom_date := to_char(lc_new_prom_date,fnd_profile.value_wnps('ICX_DATE_FORMAT_MASK')||' HH24:MI:SS');
4863 end if;
4864
4865
4866 lc_line_num := nvl(lc_line_num,'` ');
4867 lc_ship_num:= nvl(lc_ship_num,'` ');
4868 lc_old_sup_pt_num:= nvl(lc_old_sup_pt_num,'` ');
4869 lc_new_sup_pt_num:= nvl(lc_new_sup_pt_num,'` ');
4870 l_old_prom_date:= nvl(l_old_prom_date,'` ');
4871 l_new_prom_date:= nvl(l_new_prom_date,'` ');
4872 lc_old_qty:= nvl(lc_old_qty,'` ');
4873 lc_new_qty:= nvl(lc_new_qty,'` ');
4874 lc_old_price:= nvl(lc_old_price,'` ');
4875 lc_new_price:= nvl(lc_new_price,'` ');
4876 lc_response := nvl(lc_response ,'` ');
4877 lc_item_desc:= nvl(lc_item_desc,'` ');
4878 lc_uom:= nvl(lc_uom,'` ');
4879 lc_ship_to_location:= nvl(lc_ship_to_location,'` ');
4880 lc_reason:= nvl(lc_reason,'` ');
4881 lc_split:= nvl(lc_split,'` ');
4882
4883 l_document := '
4884 <TR bgcolor=#f7f7e7>';
4885
4886 if(lc_action_code = 'CANCELLATION') then
4887 l_document := l_document ||'
4888 <TD align=left><font color=black>
4889 <TABLE>
4890 <TR>
4891 <TD>
4892 <img src=/OA_MEDIA/cancelind_status.gif ALT="">
4893 </TD>
4894 <TD alight=right>'
4895 ||lc_line_num||
4896 '</TD>
4897 </TR>
4898 </TABLE>
4899 </font></TD> ';
4900 else
4901 l_document := l_document ||'
4902 <TD align=left><font color=black>'||lc_line_num||
4903 '</font></TD> ';
4904 end if;
4905 l_document := l_document ||
4906 '<TD align=left><font color=black>'||lc_ship_num||
4907 '</font></TD> ';
4908
4909 if(lc_new_sup_pt_num = '` ') then
4910 l_document := l_document || '
4911 <TD align=left><font color=black>'||lc_old_sup_pt_num||'
4912 </font></TD>';
4913 else
4914 l_document := l_document || '
4915 <TD align=left><font color=black>
4916 <table>
4917 <tr>
4918 <td>'||lc_old_sup_pt_num||'
4919 </td>
4920 </tr>
4921 <tr>
4922 <td>'||lc_new_sup_pt_num||'
4923 </td>
4924 <td>
4925 <img src=/OA_MEDIA/newupdateditem_status.gif ALT="">
4926 </td>
4927 </tr>
4928 </table>
4929 </font></TD>';
4930 end if;
4931
4932 l_document := l_document || '
4933 <TD align=left><font color=black>'||lc_item_desc||
4934 '</font></TD>
4935
4936 <TD align=left><font color=black>'||lc_uom||
4937 '</font></TD> ';
4938
4939 if(lc_new_price = '` ') then
4940 l_document := l_document || '
4941 <TD align=left><font color=black>'||lc_old_price||'
4942 </font></TD>';
4943 else
4944 l_document := l_document || '
4945 <TD align=left><font color=black>
4946 <table>
4947 <tr>
4948 <td>'||lc_old_price||'
4949 </td>
4950 </tr>
4951 <tr>
4952 <td>'||lc_new_price||'
4953 </td>
4954 <td>
4955 <img src=/OA_MEDIA/newupdateditem_status.gif ALT="">
4956 </td>
4957 </tr>
4958 </table>
4959 </font></TD>';
4960 end if;
4961
4962 if(lc_new_qty = '` ') then
4963 l_document := l_document || '
4964 <TD align=left><font color=black>'||lc_old_qty||'
4965 </font></TD>';
4966 elsif(lc_split <> '` ') then
4967 l_document := l_document || '
4968 <TD align=left><font color=black>
4969 <table>
4970 <tr>
4971 <td>'||lc_new_qty||'
4972 </td>
4973 <td>
4974 <img src=/OA_MEDIA/newupdateditem_status.gif ALT="">
4975 </td>
4976 </tr>
4977 </table>
4978 </font></TD>';
4979 else
4980 l_document := l_document || '
4981 <TD align=left><font color=black>
4982 <table>
4983 <tr>
4984 <td>'||lc_old_qty||'
4985 </td>
4986 </tr>
4987 <tr>
4988 <td>'||lc_new_qty||'
4989 </td>
4990 <td>
4991 <img src=/OA_MEDIA/newupdateditem_status.gif ALT="">
4992 </td>
4993 </tr>
4994 </table>
4995 </font></TD>';
4996 end if;
4997
4998 if(l_new_prom_date = '` ') then
4999 l_document := l_document || '
5000 <TD align=left><font color=black>'||l_old_prom_date||'
5001 </font></TD>';
5002 elsif(lc_split <> '` ' OR l_old_prom_date = '` ') then
5003 l_document := l_document || '
5004 <TD align=left><font color=black>
5005 <table>
5006 <tr>
5007 <td>'||l_new_prom_date||'
5008 </td>
5009 <td>
5010 <img src=/OA_MEDIA/newupdateditem_status.gif ALT="">
5011 </td>
5012 </tr>
5013 </table>
5014 </font></TD>';
5015 else
5016 l_document := l_document || '
5017 <TD align=left><font color=black>
5018 <table>
5019 <tr>
5020 <td>'||l_old_prom_date||'
5021 </td>
5022 </tr>
5023 <tr>
5024 <td>'||l_new_prom_date||'
5025 </td>
5026 <td>
5027 <img src=/OA_MEDIA/newupdateditem_status.gif ALT="">
5028 </td>
5029 </tr>
5030 </table>
5031 </font></TD>';
5032 end if;
5033 l_document := l_document || '
5034
5035 <TD align=left><font color=black>'||lc_ship_to_location||
5036 '</font></TD>
5037
5038 <TD align=left><font color=black>'||lc_response||
5039 '</font></TD>
5040 <TD align=left><font color=black>'||lc_reason||
5041 '</font></TD>
5042 <TD align=left><font color=black>'||lc_split||
5043 '</font></TD>
5044
5045 </TR>
5046 ';
5047 WF_NOTIFICATION.WriteToClob(document,l_document);
5048 END LOOP;
5049 CLOSE l_po_chg_req_csr;
5050 WF_NOTIFICATION.WriteToClob(document, '
5051 </TABLE></P>
5052 ');
5053 open l_header_changes_csr(p_chg_req_grp_id);
5054 fetch l_header_changes_csr into l_additional_changes, l_header_response ;
5055 close l_header_changes_csr;
5056
5057 if(l_additional_changes is not null) then
5058 if(l_header_response = 'ACCEPTED') then
5059 l_header_response := fnd_message.get_string('PO','PO_WF_NOTIF_ACCEPTED');
5060 else
5061 l_header_response := fnd_message.get_string('PO','PO_WF_NOTIF_REJ');
5062 end if;
5063 l_document := '<BR><TABLE WIDTH=100% cellpadding=2 cellspacing=1>' ||
5064 '<TR bgcolor=#cccc99>' ||
5065 '<TH align=left><font color=#336699 >'||fnd_message.get_string('PO','PO_WF_NOTIF_ADD_CHN_REQ_NCOL')||
5066 '</font></TH>' ||
5067 '<TH align=left><font color=#336699 >'||fnd_message.get_string('PO','PO_WF_NOTIF_RESPONSE')||
5068 '</font></TH>' ||
5069 '</TR>' ||
5070 '<TR>' || '<TD align=left><font color=black>' || l_additional_changes ||
5071 '</font></TD><TD align=left><font color=black>' || l_header_response ||
5072
5073 '</font></TD></TR>' ||
5074 '</TABLE>';
5075
5076 WF_NOTIFICATION.WriteToClob(document,l_document);
5077 end if;
5078
5079 else --if header_cnacel = N
5080 if(l_header_response = 'ACCEPTED') then
5081 l_header_response := fnd_message.get_string('PO','PO_WF_NOTIF_SACCEPTED');
5082 else
5083 l_header_response := fnd_message.get_string('PO','PO_WF_NOTIF_SREJECTED');
5084 end if;
5085 fnd_message.set_name('PO','PO_WF_NOTIF_BUY_RESP_CAN');
5086 fnd_message.set_token('DOC',l_doc_hdr_info);
5087 fnd_message.set_token('RESPONSE',l_header_response);
5088 l_document := fnd_message.get;
5089 WF_NOTIFICATION.WriteToClob(document,l_document);
5090 end if;
5091 else
5092 WF_NOTIFICATION.WriteToClob(document,'GEN_NTF_FOR_SUP_BUY_RP for no html customer');
5093 end if;
5094 exception when others then
5095 IF g_fnd_debug = 'Y' THEN
5096 FND_LOG.string(FND_LOG.level_unexpected, g_module_prefix ||
5097 l_api_name || '.others_exception', l_progress||':'||sqlerrm);
5098 END IF;
5099 WF_NOTIFICATION.WriteToClob(document,'Exception occured:'||sqlerrm); */
5100 null;
5101
5102 END GEN_NTF_FOR_SUP_BUY_RP;
5103
5104 ---------------------------------------------------------
5105 -- public
5106 --
5107 -- workflow document procedure to generate notification
5108 -- subject for buyer
5109 ---------------------------------------------------------
5110 PROCEDURE GEN_NTF_FOR_BUYER_SUBJECT
5111 (document_id IN VARCHAR2,
5112 display_type IN VARCHAR2,
5113 document IN OUT nocopy VARCHAR2,
5114 document_type IN OUT nocopy VARCHAR2)
5115 IS
5116
5117 l_po_num po_headers_all.segment1%TYPE;
5118 l_supplier_name po_vendors.vendor_name%TYPE;
5119 l_blanket_num po_headers_all.segment1%TYPE;
5120 --l_release_num number;
5121 l_release_num po_releases_all.release_num%TYPE;
5122 l_document_header_info varchar2(2000);
5123 l_type_lookup_code po_headers_all.type_lookup_code%TYPE;
5124 l_global_agreement_flag varchar2(3);
5125 l_header_cancel varchar2(1);
5126 l_id NUMBER;
5127 l_revision_num NUMBER; -- RDP changes
5128 l_po_total NUMBER;
5129 l_currency_code VARCHAR2(5);
5130 l_rel_revision_num NUMBER;
5131 l_rel_total NUMBER;
5132 l_rel_currency_code VARCHAR2(5);
5133
5134 CURSOR l_header_cancel_csr(grp_id number) IS
5135 select change_request_id
5136 from po_change_requests
5137 where change_request_group_id = grp_id
5138 and action_type = 'CANCELLATION'
5139 and request_level = 'HEADER';
5140
5141 l_itemtype VARCHAR2(30);
5142 l_itemkey po_change_requests.wf_item_key%TYPE;
5143 l_header_id NUMBER;
5144 l_release_id NUMBER;
5145 l_chg_req_grp_id NUMBER;
5146 l_ack_req_flag VARCHAR2(30);
5147 l_notif_usage VARCHAR2(30); -- RDP changes
5148 l_message_name fnd_new_messages.message_name%TYPE;
5149 l_display_name varchar2(1000);
5150 l_msg_header varchar2(1000);
5151
5152 BEGIN
5153
5154 l_itemtype := 'POSCHORD';
5155 l_itemkey := document_id;
5156
5157 l_header_id := wf_engine.GetItemAttrNumber(
5158 itemtype => l_itemtype,
5159 itemkey => l_itemkey,
5160 aname => 'PO_HEADER_ID');
5161
5162 l_release_id := wf_engine.GetItemAttrNumber(
5163 itemtype => l_itemtype,
5164 itemkey => l_itemkey,
5165 aname => 'PO_RELEASE_ID');
5166
5167 l_chg_req_grp_id := wf_engine.GetItemAttrNumber(
5168 itemtype => l_itemtype,
5169 itemkey => l_itemkey,
5170 aname => 'CHANGE_REQUEST_GROUP_ID');
5171
5172 l_ack_req_flag := wf_engine.GetItemAttrText(
5173 itemtype => l_itemtype,
5174 itemkey => l_itemkey,
5175 aname => 'ACKNOWLEDGE_REQ_FLAG');
5176
5177 l_notif_usage := wf_engine.GetItemAttrText( -- RDP changes
5178 itemtype => l_itemtype,
5179 itemkey => l_itemKey,
5180 aname => 'NOTIF_USAGE');
5181
5182
5183
5184
5185 l_header_cancel := 'N';
5186
5187 IF(l_chg_req_grp_id is not null) THEN
5188 OPEN l_header_cancel_csr(l_chg_req_grp_id);
5189 FETCH l_header_cancel_csr
5190 INTO l_id;
5191 CLOSE l_header_cancel_csr;
5192 IF(l_id is not null) THEN
5193 l_header_cancel := 'Y';
5194 END IF;
5195 END IF;
5196
5197 IF(l_release_id is null) THEN
5198 select
5199 pv.vendor_name,
5200 pha.segment1,
5201 pha.type_lookup_code,
5202 pha.GLOBAL_AGREEMENT_FLAG,
5203 pha.revision_num,
5204 pos_totals_po_sv.get_po_total(pha.po_header_id),
5205 pha.currency_code,
5206 PDSL.DISPLAY_NAME
5207 into
5208 l_supplier_name,
5209 l_po_num,
5210 l_type_lookup_code,
5211 l_global_agreement_flag,
5212 l_revision_num,
5213 l_po_total,
5214 l_currency_code,
5215 l_display_name
5216 from
5217 po_headers_all pha,
5218 po_vendors pv,
5219 PO_ALL_DOC_STYLE_LINES PDSL
5220 where pha.po_header_id = l_header_id
5221 and pha.vendor_id = pv.vendor_id
5222 AND NVL(PHA.STYLE_ID, 0) = PDSL.STYLE_ID (+)
5223 AND PHA.TYPE_LOOKUP_CODE = PDSL.DOCUMENT_SUBTYPE (+)
5224 AND PDSL.ENABLED_FLAG (+) = 'Y' AND PDSL.STATUS (+) = 'ACTIVE'
5225 AND PDSL.LANGUAGE (+) = USERENV('LANG');
5226
5227 IF( l_display_name IS NULL) THEN
5228 if(l_type_lookup_code = 'STANDARD') then
5229 l_message_name := 'PO_WF_NOTIF_STD_PO';
5230 elsif (l_global_agreement_flag = 'Y' and l_type_lookup_code = 'BLANKET') then
5231 l_message_name := 'PO_GA_TYPE';
5232 elsif(l_type_lookup_code = 'BLANKET') then
5233 l_message_name := 'PO_WF_NOTIF_BLANKET';
5234 elsif(l_type_lookup_code = 'CONTRACT') then
5235 l_message_name := 'PO_POTYPE_CNTR';
5236 elsif(l_type_lookup_code = 'PLANNED') then
5237 l_message_name := 'PO_WF_NOTIF_PLAN_PO';
5238 else
5239 return;
5240 end if;
5241
5242 fnd_message.set_name('PO', l_message_name);
5243 l_msg_header := fnd_message.get;
5244 ELSIF( l_display_name IS NOT NULL) THEN
5245 l_msg_header := l_display_name;
5246 END IF;
5247
5248 --fnd_message.set_token('PO_NUMBER', l_po_num);
5249 IF (l_notif_usage = 'BUYER_AUTO_FYI') THEN -- RDP if Auto Approved add Auto Approve message
5250 l_document_header_info := l_msg_header || ' ' || l_po_num || ', ' ||
5251 l_revision_num|| ' ('||fnd_message.get_string('PO','PO_WF_NOTIF_TOTAL')||' '
5252 ||TO_CHAR(l_po_total, FND_CURRENCY.GET_FORMAT_MASK(l_currency_code, 30)) ||
5253 ' ' || l_currency_code || ') ' || fnd_message.get_string('POS','POS_AUTO_APP_MSG');
5254 ELSE
5255 IF(l_type_lookup_code = 'BLANKET') THEN
5256 l_document_header_info := l_msg_header || ' ' || l_po_num || ', ' || l_revision_num; -- RDP if Blanket don't display Total
5257 ELSE
5258 l_document_header_info := l_msg_header || ' ' || l_po_num || ', ' || l_revision_num|| ' ('||fnd_message.get_string('PO','PO_WF_NOTIF_TOTAL')
5259 ||' '||TO_CHAR(l_po_total, FND_CURRENCY.GET_FORMAT_MASK(l_currency_code, 30))
5260 || ' ' || l_currency_code || ') ';
5261 END IF;
5262 END IF;
5263
5264 ELSE -- l_release_id is not null
5265 select
5266 pv.vendor_name,
5267 pha.segment1,
5268 pra.release_num,
5269 pha.type_lookup_code,
5270 pra.revision_num,
5271 pos_totals_po_sv.get_release_total(pra.po_release_id),
5272 pha.currency_code
5273 into
5274 l_supplier_name,
5275 l_blanket_num,
5276 l_release_num,
5277 l_type_lookup_code,
5278 l_rel_revision_num,
5279 l_rel_total,
5280 l_rel_currency_code
5281 from
5282 po_releases_all pra,
5283 po_headers_all pha,
5284 po_vendors pv
5285 where pra.po_release_id = l_release_id
5286 and pra.po_header_id = pha.po_header_id
5287 and pha.vendor_id = pv.vendor_id;
5288
5289 if(l_type_lookup_code = 'BLANKET')then
5290 l_message_name := 'PO_WF_NOTIF_BKT_REL2';
5291 elsif(l_type_lookup_code = 'PLANNED') then
5292 l_message_name := 'PO_WF_NOTIF_SCH_REL2';
5293 else
5294 return;
5295 end if;
5296
5297 fnd_message.set_name('PO', l_message_name);
5298 fnd_message.set_token('BLANKET_NUMBER', l_blanket_num);
5299 fnd_message.set_token('RELEASE_NUMBER', l_release_num);
5300 IF (l_notif_usage = 'BUYER_AUTO_FYI') THEN -- RDP generating subject for releases if auto approved
5301 l_document_header_info := fnd_message.get || ', ' || l_rel_revision_num ||'('
5302 ||fnd_message.get_string('PO','PO_WF_NOTIF_TOTAL')|| ' '|| TO_CHAR(l_rel_total, FND_CURRENCY.GET_FORMAT_MASK(l_rel_currency_code, 30))||' '||l_rel_currency_code||') '|| fnd_message.get_string('POS','POS_AUTO_APP_MSG');
5303 ELSE
5304 l_document_header_info := fnd_message.get || ', ' || l_rel_revision_num ||'('
5305 ||fnd_message.get_string('PO','PO_WF_NOTIF_TOTAL')|| ' '|| TO_CHAR(l_rel_total, FND_CURRENCY.GET_FORMAT_MASK(l_rel_currency_code, 30))||' '||l_rel_currency_code||')';
5306 END IF;
5307
5308 END IF;
5309
5310
5311
5312 IF(l_header_cancel = 'N') THEN
5313 if(l_ack_req_flag = 'Y') then
5314 l_message_name := 'PO_WF_NOTIF_ACK_REP_FROM2';
5315 else
5316 l_message_name := 'PO_WF_NOTIF_CHN_REQ_FROM2';
5317 end if;
5318
5319 ELSE
5320 l_message_name := 'PO_WF_NOTIF_CANCEL_REQ_FROM';
5321 END IF;
5322
5323 fnd_message.set_name('PO', l_message_name);
5324 fnd_message.set_token('SUPPLIER_NAME', l_supplier_name);
5325 fnd_message.set_token('HEADER_INFO', l_document_header_info);
5326 document := fnd_message.get;
5327
5328 END GEN_NTF_FOR_BUYER_SUBJECT;
5329
5330 ---------------------------------------------------------
5331 -- public
5332 --
5333 -- workflow document procedure to generate notification
5334 -- subject for supplier
5335 ---------------------------------------------------------
5336 PROCEDURE GEN_NTF_FOR_SUP_SUBJECT
5337 (document_id IN VARCHAR2,
5338 display_type IN VARCHAR2,
5339 document IN OUT nocopy VARCHAR2,
5340 document_type IN OUT nocopy VARCHAR2)
5341 IS
5342
5343 l_po_num po_headers_all.segment1%TYPE;
5344 l_blanket_num po_headers_all.segment1%TYPE;
5345 --l_release_num number;
5346 l_release_num po_releases_all.release_num%TYPE;
5347 l_buyer_name hr_all_organization_units_tl.name%TYPE;
5348 l_type_lookup_code po_headers_all.type_lookup_code%TYPE;
5349 l_global_agreement_flag po_headers_all.GLOBAL_AGREEMENT_FLAG%TYPE := 'F';
5350 l_doc_hdr_info varchar2(2000);
5351
5352 l_id number;
5353 l_header_cancel varchar2(1);
5354 CURSOR l_header_cancel_csr(grp_id number) IS
5355 select change_request_id
5356 from po_change_requests
5357 where change_request_group_id = grp_id
5358 and action_type = 'CANCELLATION'
5359 and request_level = 'HEADER';
5360
5361 l_itemtype VARCHAR2(30);
5362 l_itemkey po_change_requests.wf_item_key%TYPE;
5363 l_header_id NUMBER;
5364 l_release_id NUMBER;
5365 l_chg_req_grp_id NUMBER;
5366 l_revision_num NUMBER;
5367 l_display_name varchar2(1000);
5368 l_msg_header varchar2(1000);
5369 l_message_name fnd_new_messages.message_name%TYPE;
5370 -- Bug 8223635. Modified size of the l_temp_message from 30 to 1000
5371 -- in order store longer buyer names.
5372 l_temp_message varchar2(1000);
5373
5374 BEGIN
5375
5376 l_itemtype := 'POSCHORD';
5377 l_itemkey := document_id;
5378
5379 l_header_id := wf_engine.GetItemAttrNumber(
5380 itemtype => l_itemtype,
5381 itemkey => l_itemkey,
5382 aname => 'PO_HEADER_ID');
5383
5384 l_release_id := wf_engine.GetItemAttrNumber(
5385 itemtype => l_itemtype,
5386 itemkey => l_itemkey,
5387 aname => 'PO_RELEASE_ID');
5388
5389 l_chg_req_grp_id := wf_engine.GetItemAttrNumber(
5390 itemtype => l_itemtype,
5391 itemkey => l_itemkey,
5392 aname => 'CHANGE_REQUEST_GROUP_ID');
5393
5394 l_revision_num := wf_engine.GetItemAttrNumber(
5395 itemtype => l_itemtype,
5396 itemkey => l_itemkey,
5397 aname => 'PO_REVISION_NUM');
5398
5399 l_header_cancel := 'N';
5400 if(l_chg_req_grp_id is not null) then
5401 open l_header_cancel_csr(l_chg_req_grp_id);
5402 fetch l_header_cancel_csr
5403 into l_id;
5404 close l_header_cancel_csr;
5405 if(l_id is not null) then
5406 l_header_cancel := 'Y';
5407 end if;
5408 end if;
5409
5410 IF(l_release_id is null) THEN
5411 select pha.segment1,
5412 hou.name,
5413 pha.type_lookup_code,
5414 pha.global_agreement_flag,
5415 PDSL.DISPLAY_NAME
5416 into l_po_num,
5417 l_buyer_name,
5418 l_type_lookup_code,
5419 l_global_agreement_flag,
5420 l_display_name
5421 from po_headers_all pha,
5422 hr_all_organization_units_tl hou,
5423 PO_ALL_DOC_STYLE_LINES PDSL
5424 where pha.po_header_id = l_header_id
5425 and pha.org_id = hou.organization_id(+)
5426 and hou.language(+) = userenv('LANG')
5427 AND NVL(PHA.STYLE_ID, 0) = PDSL.STYLE_ID (+)
5428 AND PHA.TYPE_LOOKUP_CODE = PDSL.DOCUMENT_SUBTYPE (+)
5429 AND PDSL.ENABLED_FLAG (+) = 'Y' AND PDSL.STATUS (+) = 'ACTIVE'
5430 AND PDSL.LANGUAGE (+) = USERENV('LANG');
5431
5432 IF(l_display_name IS NULL) THEN
5433 if(l_type_lookup_code = 'STANDARD') then
5434 l_message_name := 'PO_WF_NOTIF_STD_PO';
5435 elsif(l_type_lookup_code = 'PLANNED') then
5436 l_message_name := 'PO_WF_NOTIF_PLAN_PO';
5437 elsif (l_global_agreement_flag = 'Y' and l_type_lookup_code = 'BLANKET') then
5438 l_message_name := 'PO_GA_TYPE';
5439 elsif(l_type_lookup_code = 'BLANKET') then
5440 l_message_name := 'PO_WF_NOTIF_BLANKET';
5441 elsif(l_type_lookup_code = 'CONTRACT') then
5442 l_message_name := 'PO_POTYPE_CNTR';
5443 else
5444 RETURN;
5445 end if;
5446
5447 fnd_message.set_name('PO', l_message_name);
5448 l_msg_header := fnd_message.get;
5449 ELSIF(l_display_name IS NOT NULL) THEN
5450 l_msg_header := l_display_name;
5451 END IF;
5452 --fnd_message.set_token('PO_NUMBER', l_po_num);
5453 l_doc_hdr_info := l_msg_header || ' ' || l_po_num || ',' || l_revision_num; -- RDP changes (generating subject for Supplier Notification)
5454
5455 ELSE
5456 select pha.segment1,
5457 pra.release_num,
5458 hou.name,
5459 pha.type_lookup_code
5460 into l_blanket_num,
5461 l_release_num,
5462 l_buyer_name,
5463 l_type_lookup_code
5464 from po_headers_all pha,
5465 po_releases_all pra,
5466 hr_all_organization_units_tl hou
5467 where pra.po_release_id = l_release_id
5468 and pha.po_header_id = pra.po_header_id
5469 and pha.org_id = hou.organization_id(+)
5470 and hou.language(+) = userenv('LANG');
5471
5472 if(l_type_lookup_code = 'BLANKET') then
5473 l_message_name := 'PO_WF_NOTIF_BKT_REL2';
5474 elsif(l_type_lookup_code = 'PLANNED') then
5475 l_message_name := 'PO_WF_NOTIF_SCH_REL2';
5476 else
5477 RETURN;
5478 end if;
5479
5480 fnd_message.set_name('PO', l_message_name);
5481 fnd_message.set_token('BLANKET_NUMBER', l_blanket_num);
5482 fnd_message.set_token('RELEASE_NUMBER', l_release_num);
5483 l_doc_hdr_info := fnd_message.get || ',' || l_revision_num; -- RDP changes
5484
5485 END IF;
5486
5487 if(l_header_cancel = 'N') then
5488
5489
5490 /* fnd_message.set_name('POS','PO_WF_NOTIF_RESP_SUB_CHG');
5491 fnd_message.set_token('DOC',l_doc_hdr_info);
5492 fnd_message.set_token('BUYER',l_buyer_name);
5493 document := fnd_message.get; */
5494
5495 l_temp_message := l_buyer_name || ' - ';
5496 fnd_message.set_name('POS','POS_SUP_RESP_MSG');
5497 fnd_message.set_token('DOC',l_doc_hdr_info);
5498 document := l_temp_message || fnd_message.get; -- RDP changes
5499
5500 else
5501
5502 /* fnd_message.set_name('POS','PO_WF_NOTIF_RESP_SUB_CAN');
5503 fnd_message.set_token('DOC',l_doc_hdr_info);
5504 fnd_message.set_token('BUYER',l_buyer_name);
5505 document := fnd_message.get; */
5506
5507 l_temp_message := l_buyer_name || ' - ';
5508 fnd_message.set_name('POS','POS_SUP_RESP_MSG_CAN');
5509 fnd_message.set_token('DOC',l_doc_hdr_info);
5510 document := l_temp_message || fnd_message.get; -- RDP changes
5511
5512 end if;
5513
5514 END GEN_NTF_FOR_SUP_SUBJECT;
5515
5516 ---------------------------------------------------------
5517 -- public
5518 --
5519 -- workflow document procedure to generate notification
5520 -- subject for planner
5521 ---------------------------------------------------------
5522 PROCEDURE GEN_NTF_FOR_PLAN_SUBJECT
5523 (document_id IN VARCHAR2,
5524 display_type IN VARCHAR2,
5525 document IN OUT nocopy VARCHAR2,
5526 document_type IN OUT nocopy VARCHAR2)
5527 IS
5528
5529 l_po_num po_headers_all.segment1%TYPE;
5530 l_blanket_num po_headers_all.segment1%TYPE;
5531 --l_release_num number;
5532 l_release_num po_releases_all.release_num%TYPE;
5533 l_supplier_name po_vendors.vendor_name%TYPE;
5534 l_type_lookup_code po_headers_all.type_lookup_code%TYPE;
5535 l_document_header_info varchar2(2000);
5536
5537 l_id number;
5538 l_header_cancel varchar2(1);
5539 CURSOR l_header_cancel_csr(grp_id number) IS
5540 select change_request_id
5541 from po_change_requests
5542 where change_request_group_id = grp_id
5543 and action_type = 'CANCELLATION'
5544 and request_level = 'HEADER';
5545
5546 l_itemtype VARCHAR2(30);
5547 l_itemkey po_change_requests.wf_item_key%TYPE;
5548 l_header_id NUMBER;
5549 l_release_id NUMBER;
5550 l_chg_req_grp_id NUMBER;
5551
5552 l_message_name fnd_new_messages.message_name%TYPE;
5553 l_global_agreement_flag po_headers_all.GLOBAL_AGREEMENT_FLAG%TYPE := 'F';
5554 l_display_name varchar2(1000);
5555 l_msg_header varchar2(1000);
5556
5557
5558 BEGIN
5559
5560 l_itemtype := 'POSCHORD';
5561 l_itemkey := document_id;
5562
5563 l_header_id := wf_engine.GetItemAttrNumber(
5564 itemtype => l_itemtype,
5565 itemkey => l_itemkey,
5566 aname => 'PO_HEADER_ID');
5567
5568 l_release_id := wf_engine.GetItemAttrNumber(
5569 itemtype => l_itemtype,
5570 itemkey => l_itemkey,
5571 aname => 'PO_RELEASE_ID');
5572
5573 l_chg_req_grp_id := wf_engine.GetItemAttrNumber(
5574 itemtype => l_itemtype,
5575 itemkey => l_itemkey,
5576 aname => 'CHANGE_REQUEST_GROUP_ID');
5577
5578 IF(l_release_id is null) THEN
5579 select pha.type_lookup_code,
5580 pha.segment1,
5581 pv.vendor_name,
5582 pha.global_agreement_flag,
5583 PDSL.display_name
5584 into l_type_lookup_code,
5585 l_po_num,
5586 l_supplier_name,
5587 l_global_agreement_flag,
5588 l_display_name
5589 from po_headers_all pha,
5590 po_vendors pv,
5591 PO_ALL_DOC_STYLE_LINES PDSL
5592 where pha.po_header_id = l_header_id
5593 and pv.vendor_id = pha.vendor_id
5594 AND NVL(PHA.STYLE_ID, 0) = PDSL.STYLE_ID (+)
5595 AND PHA.TYPE_LOOKUP_CODE = PDSL.DOCUMENT_SUBTYPE (+)
5596 AND PDSL.ENABLED_FLAG (+) = 'Y' AND PDSL.STATUS (+) = 'ACTIVE'
5597 AND PDSL.LANGUAGE (+) = USERENV('LANG');
5598
5599 IF(l_display_name IS NULL) THEN
5600 if(l_type_lookup_code = 'STANDARD') then
5601 l_message_name := 'PO_WF_NOTIF_STD_PO';
5602 elsif(l_type_lookup_code = 'PLANNED') then
5603 l_message_name := 'PO_WF_NOTIF_PLAN_PO';
5604 elsif (l_global_agreement_flag = 'Y' and l_type_lookup_code = 'BLANKET') then
5605 l_message_name := 'PO_GA_TYPE';
5606 elsif(l_type_lookup_code = 'BLANKET') then
5607 l_message_name := 'PO_WF_NOTIF_BLANKET';
5608 elsif(l_type_lookup_code = 'CONTRACT') then
5609 l_message_name := 'PO_POTYPE_CNTR';
5610 end if;
5611
5612 fnd_message.set_name('PO', l_message_name);
5613 l_msg_header := fnd_message.get;
5614 ELSIF(l_display_name IS NOT NULL) THEN
5615 l_msg_header := l_display_name;
5616 END IF;
5617 --fnd_message.set_token('PO_NUMBER', l_po_num);
5618 l_document_header_info := l_msg_header || ' ' || l_po_num;
5619
5620 ELSE
5621 select pha.type_lookup_code,
5622 pha.segment1,
5623 pra.release_num,
5624 pv.vendor_name
5625 into l_type_lookup_code,
5626 l_blanket_num,
5627 l_release_num,
5628 l_supplier_name
5629 from po_headers_all pha,
5630 po_releases_all pra,
5631 po_vendors pv
5632 where pra.po_release_id = l_release_id
5633 and pra.po_header_id = pha.po_header_id
5634 and pv.vendor_id = pha.vendor_id;
5635
5636 if(l_type_lookup_code = 'BLANKET')then
5637 l_message_name := 'PO_WF_NOTIF_BKT_REL2';
5638 elsif(l_type_lookup_code = 'PLANNED') then
5639 l_message_name := 'PO_WF_NOTIF_SCH_REL2';
5640 end if;
5641
5642 fnd_message.set_name('PO', l_message_name);
5643 fnd_message.set_token('BLANKET_NUMBER', l_blanket_num);
5644 fnd_message.set_token('RELEASE_NUMBER', l_release_num);
5645 l_document_header_info := fnd_message.get;
5646
5647 END IF;
5648
5649 l_header_cancel := 'N';
5650 if(l_chg_req_grp_id is not null) then
5651 open l_header_cancel_csr(l_chg_req_grp_id);
5652 fetch l_header_cancel_csr
5653 into l_id;
5654 close l_header_cancel_csr;
5655 if(l_id is not null) then
5656 l_header_cancel := 'Y';
5657 end if;
5658 end if;
5659
5660 if(l_header_cancel = 'N') then
5661 l_message_name := 'PO_WF_NOTIF_CHN_REQ_FROM2';
5662 else
5663 l_message_name := 'PO_WF_NOTIF_CANCEL_REQ_FROM';
5664 end if;
5665
5666 fnd_message.set_name('PO', l_message_name);
5667 fnd_message.set_token('SUPPLIER_NAME', l_supplier_name);
5668 fnd_message.set_token('HEADER_INFO', l_document_header_info);
5669 document := fnd_message.get;
5670
5671 END GEN_NTF_FOR_PLAN_SUBJECT;
5672
5673 ---------------------------------------------------------
5674 -- public
5675 --
5676 -- workflow document procedure to generate notification
5677 -- subject for requester
5678 ---------------------------------------------------------
5679 PROCEDURE GEN_NTF_FOR_REQ_SUBJECT
5680 (document_id IN VARCHAR2,
5681 display_type IN VARCHAR2,
5682 document IN OUT nocopy VARCHAR2,
5683 document_type IN OUT nocopy VARCHAR2)
5684 IS
5685
5686 l_po_num po_headers_all.segment1%TYPE;
5687 l_blanket_num po_headers_all.segment1%TYPE;
5688 --l_release_num number;
5689 l_release_num po_releases_all.release_num%TYPE;
5690 l_supplier_name po_vendors.vendor_name%TYPE;
5691 l_type_lookup_code po_headers_all.type_lookup_code%TYPE;
5692 l_document_header_info varchar2(2000);
5693
5694 l_id number;
5695 l_header_cancel varchar2(1);
5696 CURSOR l_header_cancel_csr(grp_id number) IS
5697 select change_request_id
5698 from po_change_requests
5699 where change_request_group_id = grp_id
5700 and action_type = 'CANCELLATION'
5701 and request_level = 'HEADER';
5702
5703 l_itemtype VARCHAR2(30);
5704 l_itemkey po_change_requests.wf_item_key%TYPE;
5705 l_header_id NUMBER;
5706 l_release_id NUMBER;
5707 l_chg_req_grp_id NUMBER;
5708
5709 l_message_name fnd_new_messages.message_name%TYPE;
5710 l_global_agreement_flag po_headers_all.GLOBAL_AGREEMENT_FLAG%TYPE := 'F';
5711 l_display_name varchar2(1000);
5712 l_msg_header varchar2(1000);
5713
5714 BEGIN
5715
5716 l_itemtype := 'POSCHORD';
5717 l_itemkey := document_id;
5718
5719 l_header_id := wf_engine.GetItemAttrNumber(
5720 itemtype => l_itemtype,
5721 itemkey => l_itemkey,
5722 aname => 'PO_HEADER_ID');
5723
5724 l_release_id := wf_engine.GetItemAttrNumber(
5725 itemtype => l_itemtype,
5726 itemkey => l_itemkey,
5727 aname => 'PO_RELEASE_ID');
5728
5729 l_chg_req_grp_id := wf_engine.GetItemAttrNumber(
5730 itemtype => l_itemtype,
5731 itemkey => l_itemkey,
5732 aname => 'CHANGE_REQUEST_GROUP_ID');
5733
5734 IF(l_release_id is null) THEN
5735 select pha.type_lookup_code,
5736 pha.segment1,
5737 pv.vendor_name,
5738 pha.global_agreement_flag,
5739 PDSL.display_name
5740 into l_type_lookup_code,
5741 l_po_num,
5742 l_supplier_name,
5743 l_global_agreement_flag,
5744 l_display_name
5745 from po_headers_all pha,
5746 po_vendors pv,
5747 PO_ALL_DOC_STYLE_LINES PDSL
5748 where pha.po_header_id = l_header_id
5749 and pv.vendor_id = pha.vendor_id
5750 AND NVL(PHA.STYLE_ID, 0) = PDSL.STYLE_ID (+)
5751 AND PHA.TYPE_LOOKUP_CODE = PDSL.DOCUMENT_SUBTYPE (+)
5752 AND PDSL.ENABLED_FLAG (+) = 'Y' AND PDSL.STATUS (+) = 'ACTIVE'
5753 AND PDSL.LANGUAGE (+) = USERENV('LANG');
5754
5755 IF(l_display_name IS NULL) THEN
5756 if(l_type_lookup_code = 'STANDARD') then
5757 l_message_name := 'PO_WF_NOTIF_STD_PO';
5758 elsif(l_type_lookup_code = 'PLANNED') then
5759 l_message_name := 'PO_WF_NOTIF_PLAN_PO';
5760 elsif (l_global_agreement_flag = 'Y' and l_type_lookup_code = 'BLANKET') then
5761 l_message_name := 'PO_GA_TYPE';
5762 elsif(l_type_lookup_code = 'BLANKET') then
5763 l_message_name := 'PO_WF_NOTIF_BLANKET';
5764 elsif(l_type_lookup_code = 'CONTRACT') then
5765 l_message_name := 'PO_POTYPE_CNTR';
5766 end if;
5767
5768 fnd_message.set_name('PO', l_message_name);
5769 l_msg_header := fnd_message.get;
5770 ELSIF(l_display_name IS NOT NULL) THEN
5771 l_msg_header := l_display_name;
5772 END IF;
5773 --fnd_message.set_token('PO_NUMBER', l_po_num);
5774 l_document_header_info := l_msg_header || ' ' || l_po_num;
5775
5776 ELSE
5777 select pha.type_lookup_code,
5778 pha.segment1,
5779 pra.release_num,
5780 pv.vendor_name
5781 into l_type_lookup_code,
5782 l_blanket_num,
5783 l_release_num,
5784 l_supplier_name
5785 from po_headers_all pha,
5786 po_releases_all pra,
5787 po_vendors pv
5788 where pra.po_release_id = l_release_id
5789 and pra.po_header_id = pha.po_header_id
5790 and pv.vendor_id = pha.vendor_id;
5791
5792 if(l_type_lookup_code = 'BLANKET')then
5793 l_message_name := 'PO_WF_NOTIF_BKT_REL2';
5794 elsif(l_type_lookup_code = 'PLANNED') then
5795 l_message_name := 'PO_WF_NOTIF_SCH_REL2';
5796 end if;
5797
5798 fnd_message.set_name('PO', l_message_name);
5799 fnd_message.set_token('BLANKET_NUMBER', l_blanket_num);
5800 fnd_message.set_token('RELEASE_NUMBER', l_release_num);
5801 l_document_header_info := fnd_message.get;
5802
5803 end if;
5804
5805 l_header_cancel := 'N';
5806 if(l_chg_req_grp_id is not null) then
5807 open l_header_cancel_csr(l_chg_req_grp_id);
5808 fetch l_header_cancel_csr
5809 into l_id;
5810 close l_header_cancel_csr;
5811 if(l_id is not null) then
5812 l_header_cancel := 'Y';
5813 end if;
5814 end if;
5815
5816 if(l_header_cancel = 'N') then
5817 l_message_name := 'PO_WF_NOTIF_CHN_REQ_FROM2';
5818 else
5819 l_message_name := 'PO_WF_NOTIF_CANCEL_REQ_FROM';
5820 end if;
5821
5822 fnd_message.set_name('PO', l_message_name);
5823 fnd_message.set_token('SUPPLIER_NAME', l_supplier_name);
5824 fnd_message.set_token('HEADER_INFO', l_document_header_info);
5825 document := fnd_message.get;
5826
5827 END GEN_NTF_FOR_REQ_SUBJECT;
5828
5829 /*
5830 *Prorate is needed if supplier has changed the Quantity of a PO SHipment,Price of a Shipment of FPS Type with multiple distributions.
5831 */
5832 procedure IS_PRORATE_NEEDED( itemtype in varchar2,
5833 itemkey in varchar2,
5834 actid in number,
5835 funcmode in varchar2,
5836 resultout out NOCOPY varchar2)
5837 IS
5838 l_chg_req_grp_id number;
5839 l_po_header_id number;
5840 l_temp number;
5841 x_progress varchar2(3) := '000';
5842 cursor l_x_csr(id number) is
5843 select pcr.document_line_locatiON_id
5844 from po_change_requests pcr,
5845 po_distributions_all pda
5846 where pcr.document_line_location_id = pda.line_location_id
5847 and pcr.change_request_group_id = id -- added checks FPS Shipment Amount, Shipment price Prorate
5848 and (pcr.new_quantity is not null or pcr.new_amount is not null or pcr.new_price is not null)
5849 group by pcr.document_line_location_id
5850 having count(1) > 1;
5851 l_header_change number;
5852 l_retro_count number;
5853
5854 BEGIN
5855 l_chg_req_grp_id := wf_engine.GetItemAttrNumber(itemtype => itemtype,
5856 itemkey => itemkey,
5857 aname => 'CHANGE_REQUEST_GROUP_ID');
5858
5859 l_po_header_id := wf_engine.GetItemAttrNumber(itemtype => itemtype,
5860 itemkey => itemkey,
5861 aname => 'PO_HEADER_ID');
5862
5863 select count(*) into l_retro_count
5864 from po_change_requests pcr, po_headers_all poh
5865 where poh.po_header_id = pcr.document_header_id
5866 and poh.po_header_id = l_po_header_id
5867 and poh.type_lookup_code = 'BLANKET'
5868 and pcr.change_request_group_id = l_chg_req_grp_id
5869 and pcr.po_release_id is null
5870 and pcr.request_level in ('LINE', 'SHIPMENT')
5871 and pcr.action_type='MODIFICATION'
5872 and ((pcr.new_price is not null) or (pcr.new_quantity is not null))
5873 and pcr.request_status in ('PENDING');
5874
5875 open l_x_csr(l_chg_req_grp_id);
5876 fetch l_x_csr into l_temp;
5877 close l_x_csr;
5878
5879 select count(*)
5880 into l_header_change
5881 from po_change_requests
5882 where change_request_group_id = l_chg_req_grp_id
5883 and request_level = 'HEADER'
5884 and additional_changes is not null;
5885
5886 if(l_temp is not null or l_header_change > 0 or l_retro_count > 0) then
5887 resultout := 'Y';
5888 wf_engine.SetItemAttrText(itemtype => itemtype, -- RDP if PRORATE,ADIITIONAL CHANGES , set the NOTIF_USAGE as BUYER_FYI
5889 itemkey => itemkey,
5890 aname => 'NOTIF_USAGE',
5891 avalue => 'BUYER_FYI');
5892
5893
5894 if(l_header_change = 0) then -- RDP means no ADDITIONAL changes but PRORATE is required, set EXPLAIN_FYI
5895 wf_engine.SetItemAttrText ( itemtype => itemtype,
5896 itemkey => itemkey,
5897 aname => 'EXPLAIN_FYI',
5898 avalue => fnd_message.get_string('PO','PO_WF_NOTIF_EXPLAIN_FYI'));
5899 else
5900 wf_engine.SetItemAttrText ( itemtype => itemtype,
5901 itemkey => itemkey,
5902 aname => 'EXPLAIN_FYI',
5903 avalue => '');
5904 end if;
5905
5906 else
5907 resultout := 'N';
5908 wf_engine.SetItemAttrText ( itemtype => itemtype,
5909 itemkey => itemkey,
5910 aname => 'EXPLAIN_FYI',
5911 avalue => '');
5912
5913 end if;
5914 exception when others then
5915 wf_core.context('PO_ChangeOrderWF_PVT','IS_PRORATE_NEEDED',x_progress);
5916 raise;
5917 END IS_PRORATE_NEEDED;
5918
5919 /*
5920 *update authorization_status of PO to "APPROVED".
5921 */
5922 procedure CHG_STATUS_TO_APPROVED( itemtype in varchar2,
5923 itemkey in varchar2,
5924 actid in number,
5925 funcmode in varchar2,
5926 resultout out NOCOPY varchar2)
5927 IS
5928 l_header_id number;
5929 l_release_id number;
5930 l_revision_num number;
5931 l_chg_req_grp_id number;
5932 l_add_changes_accepted number;
5933 l_responded_by number;
5934 l_authorization_status po_headers_all.authorization_status%TYPE;
5935 l_check_result varchar2(1);
5936
5937 x_progress varchar2(3) := '000';
5938 BEGIN
5939
5940 l_header_id := wf_engine.GetItemAttrNumber(itemtype => itemtype,
5941 itemkey => itemkey,
5942 aname => 'PO_HEADER_ID');
5943 l_release_id := wf_engine.GetItemAttrNumber(itemtype => itemtype,
5944 itemkey => itemkey,
5945 aname => 'PO_RELEASE_ID');
5946 l_revision_num := wf_engine.GetItemAttrNumber(itemtype => itemtype,
5947 itemkey => itemkey,
5948 aname => 'PO_REVISION_NUM');
5949 l_chg_req_grp_id := wf_engine.GetItemAttrNumber(itemtype => itemtype,
5950 itemkey => itemkey,
5951 aname => 'CHANGE_REQUEST_GROUP_ID');
5952
5953
5954 l_authorization_status := 'APPROVED';
5955
5956 select count(*)
5957 into l_add_changes_accepted
5958 from po_change_requests
5959 where change_request_group_id = l_chg_req_grp_id
5960 -- and request_status = 'ACCEPTED'
5961 and request_status = 'BUYER_APP' /* fix for bug 3691061 */
5962 and request_level = 'HEADER'
5963 and additional_changes is not null;
5964
5965 if (l_add_changes_accepted > 0) then
5966 l_authorization_status := 'REQUIRES REAPPROVAL';
5967 end if;
5968
5969 if (l_authorization_status = 'REQUIRES REAPPROVAL') then
5970
5971 select max(responded_by) into l_responded_by
5972 from po_change_requests
5973 where request_level = 'HEADER'
5974 -- and request_status = 'ACCEPTED'
5975 and request_status = 'BUYER_APP' /* fix for bug 3691061 */
5976 and additional_changes is not null
5977 and change_request_group_id = l_chg_req_grp_id;
5978
5979 if (l_responded_by = 0) then
5980 l_responded_by := null;
5981 end if;
5982
5983 if(l_release_id is not null) then
5984
5985 update po_releases_all set
5986 authorization_status = 'REQUIRES REAPPROVAL',
5987 revision_num = revision_num + 1,
5988 revised_date = sysdate,
5989 last_update_date = sysdate,
5990 last_updated_by = nvl(l_responded_by, last_updated_by),
5991 change_requested_by = null,
5992 approved_flag = 'R'
5993 where po_release_id = l_release_id;
5994
5995 else
5996
5997 update po_headers_all set
5998 authorization_status = 'REQUIRES REAPPROVAL',
5999 revision_num = revision_num + 1,
6000 revised_date = sysdate,
6001 last_update_date = sysdate,
6002 last_updated_by = nvl(l_responded_by, last_updated_by),
6003 change_requested_by = null,
6004 approved_flag = 'R'
6005 where po_header_id = l_header_id;
6006
6007 end if;
6008
6009 else -- authorization status is approved
6010
6011 -- added due to bug 3574114
6012 update po_change_requests
6013 set change_active_flag = 'N'
6014 where change_request_group_id = l_chg_req_grp_id;
6015
6016 if(l_release_id is not null) then
6017 update po_releases_all
6018 set authorization_status = l_authorization_status,
6019 change_requested_by = null
6020 where po_release_id = l_release_id;
6021 else
6022 update po_headers_all
6023 set authorization_status = l_authorization_status,
6024 change_requested_by = null
6025 where po_header_id = l_header_id;
6026 end if;
6027
6028
6029 x_progress := '002';
6030
6031 /* Bug 3534807, mji
6032 Check if all shipments has been acknowledged, if yes post header
6033 acknowledgement record.
6034 */
6035 PO_ACKNOWLEDGE_PO_GRP.Set_Header_Acknowledgement (
6036 1.0,
6037 FND_API.G_FALSE,
6038 l_check_result,
6039 l_header_id,
6040 l_release_id );
6041
6042 x_progress := '003';
6043
6044
6045 end if;
6046
6047 exception when others then
6048 wf_core.context('PO_ChangeOrderWF_PVT','CHG_STATUS_TO_APPROVED',x_progress);
6049 raise;
6050 END CHG_STATUS_TO_APPROVED;
6051
6052
6053 /*
6054 *Supplier could have changed and accepted shipments at the same time. Once the change requests are responded, we will need
6055 *to carry over the previously accepted shipments to the new revision, by Calling
6056 *PO_ACKNOWLEDGE_PO_GRP.carry_over_acknowledgement
6057 */
6058 procedure CARRY_SUP_ACK_TO_NEW_REV( itemtype in varchar2,
6059 itemkey in varchar2,
6060 actid in number,
6061 funcmode in varchar2,
6062 resultout out NOCOPY varchar2)
6063 IS
6064 l_document_id number;
6065 l_document_type po_document_types_all.document_type_code%TYPE;
6066 l_header_id number;
6067 l_release_id number;
6068 l_revision_num number;
6069 x_progress varchar2(3) := '000';
6070 l_carryover_status varchar2(1);
6071 l_carryover_exception exception;
6072 BEGIN
6073
6074 l_document_id := wf_engine.GetItemAttrNumber(itemtype => itemtype,
6075 itemkey => itemkey,
6076 aname => 'DOCUMENT_ID');
6077 l_document_type := wf_engine.GetItemAttrText(itemtype => itemtype,
6078 itemkey => itemkey,
6079 aname => 'DOCUMENT_TYPE');
6080 x_progress := '001';
6081 if(l_document_type = 'RELEASE') then
6082 l_header_id := null;
6083 l_release_id := l_document_id;
6084 select revision_num
6085 into l_revision_num
6086 from po_releases_all
6087 where po_release_id = l_document_id;
6088 else
6089 l_header_id := l_document_id;
6090 l_release_id := null;
6091 select revision_num
6092 into l_revision_num
6093 from po_headers_all
6094 where po_header_id = l_document_id;
6095 end if;
6096 x_progress := '002';
6097 /*PO_ACKNOWLEDGE_PO_GRP.carry_over_acknowledgement(1.0,
6098 FND_API.G_FALSE,
6099 l_carryover_status,
6100 l_header_id ,
6101 l_release_id ,
6102 l_revision_num);*/
6103
6104 /*Bug 7205793: Added an internal procedure, which is an autonomous transaction
6105 to avoid deadlock during PO Approval Process. */
6106 Carry_Over_Acknowledgement( l_carryover_status,
6107 l_header_id,
6108 l_release_id,
6109 l_revision_num);
6110
6111 exception when others then
6112 wf_core.context('PO_ChangeOrderWF_PVT','CARRY_SUP_ACK_TO_NEW_REV',x_progress);
6113 raise;
6114 END CARRY_SUP_ACK_TO_NEW_REV;
6115
6116 /*
6117 *Checks if acceptance_required_flag = 'Y'
6118 */
6119 procedure DOES_PO_REQ_SUP_ACK( itemtype in varchar2,
6120 itemkey in varchar2,
6121 actid in number,
6122 funcmode in varchar2,
6123 resultout out NOCOPY varchar2)
6124 IS
6125 l_document_id number;
6126 l_document_type po_document_types_all.document_type_code%TYPE;
6127 l_acc_flag varchar2(1);
6128 x_progress varchar2(3) := '000';
6129 BEGIN
6130 l_document_id := wf_engine.GetItemAttrNumber(itemtype => itemtype,
6131 itemkey => itemkey,
6132 aname => 'DOCUMENT_ID');
6133 l_document_type := wf_engine.GetItemAttrText(itemtype => itemtype,
6134 itemkey => itemkey,
6135 aname => 'DOCUMENT_TYPE');
6136
6137 if(l_document_type = 'RELEASE') then
6138 select acceptance_required_flag
6139 into l_acc_flag
6140 from po_releases_all
6141 where po_release_id = l_document_id;
6142 else
6143 select acceptance_required_flag
6144 into l_acc_flag
6145 from po_headers_all
6146 where po_header_id = l_document_id;
6147 end if;
6148 if(l_acc_flag= 'Y') then
6149 resultout := 'Y';
6150 else
6151 resultout := 'N';
6152 END if;
6153
6154 exception when others then
6155 wf_core.context('PO_ChangeOrderWF_PVT','DOES_PO_REQ_SUP_ACK',x_progress);
6156 raise;
6157 END DOES_PO_REQ_SUP_ACK;
6158
6159 /*
6160 *Checks if PO Change request is approved/rejected by the PO Approval Hierachy.
6161 *Meanwhile, prepare the notification which is to be sent to the supplier, informing him/her of buyer's response to
6162 *Supplier's Change request
6163 *Note: Also sets the request_group_id value into the wf attribute
6164 * which is useful for the later activities.
6165 */
6166 procedure is_po_approved_by_hie( itemtype in varchar2,
6167 itemkey in varchar2,
6168 actid in number,
6169 funcmode in varchar2,
6170 resultout out NOCOPY varchar2)
6171 IS
6172 l_document_id number;
6173 p_header_id number;
6174 l_document_type po_document_types_all.document_type_code%TYPE;
6175 l_authorization_status po_headers_all.authorization_status%TYPE;
6176 l_acceptance_required_flag po_headers_all.acceptance_required_flag%TYPE; -- fix for bug 4946410
6177 l_supplier_user_id number;
6178 l_change_request_group_id number;
6179 l_supplier_username fnd_user.user_name%TYPE;
6180 l_blanket_num po_headers_all.segment1%TYPE;
6181 --l_release_num number;
6182 l_release_num po_releases_all.release_num%TYPE;
6183 l_buyer_name hr_all_organization_units_tl.name%TYPE;
6184 l_po_num po_headers_all.segment1%TYPE;
6185 l_revision_num number;
6186 l_revision_num2 number;
6187 l_notification_subject varchar2(2000);
6188 l_type_lookup_code po_headers_all.type_lookup_code%TYPE;
6189 l_doc_hdr_info varchar2(1000);
6190 l_buyer_agent_id number;
6191 l_responded_by_id number;
6192 l_buyer_username fnd_user.user_name%TYPE;
6193 l_buyer_disp_name varchar2(2000);
6194 l_po_style varchar2(10);
6195 x_return_status varchar2(1);
6196 x_complex_flag varchar2(1);
6197
6198 -- Bug 6722239 - Start
6199 /*
6200 Added the following variables
6201 l_role_name -> Adhoc Role Name Created
6202 l_vendor_id -> Supplier Id
6203 l_role_display_name -> Supplier_Name which need to be displayed in the Notification
6204 sent to supplier for buyer's response
6205 l_expiration_date -> Notification Expiry Date
6206 l_user_name -> Supplier User Name who modified the purchase order
6207 l_users -> Users list in the form of userTable to create an Adhoc role
6208 x_resultout -> Variable to set the role in the Workflow file
6209 t_document_type -> Temporary Variable used to store the document type
6210 */
6211
6212 l_role_name WF_USER_ROLES.ROLE_NAME%TYPE;
6213 l_role_display_name varchar2(100):=null;
6214 l_expiration_date DATE;
6215 l_vendor_id NUMBER;
6216 x_resultout varchar2(100):=null;
6217 l_users WF_DIRECTORY.UserTable;
6218 l_user_name varchar2(100);
6219 t_document_type po_document_types_all.document_type_code%TYPE := null;
6220 u1 pls_integer := 0;
6221 --Bug 6722239 - End
6222
6223 x_progress varchar2(100) := '000';
6224 t_varname Wf_Engine.NameTabTyp;
6225 t_varval Wf_Engine.TextTabTyp;
6226 l_global_agreement_flag po_headers_all.GLOBAL_AGREEMENT_FLAG%TYPE := 'F';
6227 l_po_header_id po_headers_all.po_header_id%TYPE;
6228 l_id number;
6229 l_header_cancel varchar2(1);
6230
6231 cursor l_header_cancel_csr(grp_id number) is
6232 select change_request_id
6233 from po_change_requests
6234 where change_request_group_id = grp_id
6235 and action_type = 'CANCELLATION'
6236 and request_level = 'HEADER';
6237
6238 /*
6239 Collecting the accepted line location ids for which changes were made during
6240 Acknowledgement process.
6241 */
6242 l_line_loc_id number;
6243 l_user_id number;
6244
6245 -- Bug 6722239 - Start
6246 /*
6247 Added the Following Cursor; This will get the list of supplier users
6248 who have done the changes to the purchase order during the process of
6249 PO Acknowledgement.
6250 */
6251 cursor l_get_user_list_csr(x_document_id NUMBER,x_document_type varchar2) is
6252 select distinct created_by ,
6253 change_request_group_id
6254 from po_change_requests
6255 where request_status in ('BUYER_APP', 'WAIT_CANCEL_APP')
6256 and ((document_header_id = x_document_id) OR (po_release_id = x_document_id))
6257 and initiator = 'SUPPLIER'
6258 and document_type = x_document_type;
6259 --Bug 6722239 - End
6260
6261 CURSOR getLineLocID(l_chg_req_grp_id_csr IN NUMBER) IS
6262 SELECT document_line_location_id
6263 FROM PO_CHANGE_REQUESTS
6264 WHERE change_request_group_id = l_chg_req_grp_id_csr
6265 AND request_level = 'SHIPMENT'
6266 AND request_status = 'BUYER_APP'
6267 AND (NEW_AMOUNT is not null OR NEW_QUANTITY is not null);
6268
6269 /* Curosr to get the change_responded by*/
6270 CURSOR getChangeRespBy(l_chg_req_grp_id_csr IN NUMBER) IS
6271 SELECT distinct fndu.employee_id
6272 FROM po_change_requests pcr,
6273 fnd_user fndu
6274 WHERE pcr.change_request_group_id = l_chg_req_grp_id_csr
6275 AND fndu.user_id = pcr.responded_by;
6276
6277 BEGIN
6278 l_document_id := wf_engine.GetItemAttrNumber(itemtype => itemtype,
6279 itemkey => itemkey,
6280 aname => 'DOCUMENT_ID');
6281
6282 l_document_type := wf_engine.GetItemAttrText(itemtype => itemtype,
6283 itemkey => itemkey,
6284 aname => 'DOCUMENT_TYPE');
6285
6286 if(l_document_type = 'RELEASE') then
6287 -- Bug 6722239 - Start
6288 -- Added a cursor above to fetch multiple records
6289 /*
6290 select distinct created_by,
6291 change_request_group_id
6292 into l_supplier_user_id ,
6293 l_change_request_group_id
6294 from po_change_requests
6295 where request_status in ('BUYER_APP', 'WAIT_CANCEL_APP')
6296 and po_release_id = l_document_id
6297 and initiator = 'SUPPLIER'
6298 and document_type = 'RELEASE';
6299 */
6300 -- Bug 6722239 - End
6301
6302 select pha.segment1,
6303 pha.po_header_id, -- RDP changes
6304 pra.release_num,
6305 pra.revision_num, -- RDP changes
6306 hou.name,
6307 pra.authorization_status,
6308 pha.type_lookup_code,
6309 pra.agent_id,
6310 pha.vendor_id,
6311 pra.acceptance_required_flag -- bug 4868859
6312 into l_blanket_num,
6313 l_po_header_id,
6314 l_release_num,
6315 l_revision_num,
6316 l_buyer_name ,
6317 l_authorization_status,
6318 l_type_lookup_code,
6319 l_buyer_agent_id,
6320 l_vendor_id,
6321 l_acceptance_required_flag
6322 from po_headers_all pha,
6323 po_releases_all pra,
6324 hr_all_organization_units_tl hou
6325 where pra.po_release_id = l_document_id
6326 and pha.po_header_id = pra.po_header_id
6327 and pha.org_id = hou.organization_id(+)
6328 and hou.language(+) = userenv('LANG');
6329
6330 select revision_num
6331 into l_revision_num2
6332 from po_releases_archive_all
6333 where po_release_id = l_document_id
6334 and latest_external_flag='Y';
6335
6336 l_header_cancel := 'N';
6337 if(l_change_request_group_id is not null) then
6338 open l_header_cancel_csr(l_change_request_group_id);
6339 fetch l_header_cancel_csr
6340 into l_id;
6341 close l_header_cancel_csr;
6342 if(l_id is not null) then
6343 l_header_cancel := 'Y';
6344 end if;
6345 end if;
6346
6347 if(l_type_lookup_code = 'PLANNED') then
6348 l_doc_hdr_info := fnd_message.get_string('PO','PO_WF_NOTIF_SCH_REL')||' '||l_blanket_num||'-'||l_release_num;
6349 elsif(l_type_lookup_code = 'BLANKET') then
6350 l_doc_hdr_info := fnd_message.get_string('PO','PO_WF_NOTIF_BKT_REL')||' '||l_blanket_num||'-'||l_release_num;
6351 end if;
6352
6353 if(l_header_cancel = 'N') then
6354 fnd_message.set_name('PO','PO_WF_NOTIF_RESP_SUB_CHG');
6355 fnd_message.set_token('DOC',l_doc_hdr_info);
6356 fnd_message.set_token('BUYER',l_buyer_name);
6357 l_notification_subject := fnd_message.get;
6358 else
6359 fnd_message.set_name('PO','PO_WF_NOTIF_RESP_SUB_CAN');
6360 fnd_message.set_token('DOC',l_doc_hdr_info);
6361 fnd_message.set_token('BUYER',l_buyer_name);
6362 l_notification_subject := fnd_message.get;
6363 end if;
6364
6365 /*
6366 update po_releases_all
6367 set change_requested_by = null
6368 where po_release_id = l_document_id;
6369 */
6370
6371 Update_Chg_Req_If_Po_Apprvd(null,l_document_id);
6372
6373 PO_WF_UTIL_PKG.SetItemAttrNumber (itemtype => itemtype,
6374 itemkey => itemkey,
6375 aname => 'PO_RELEASE_ID',
6376 avalue => l_document_id);
6377
6378 PO_WF_UTIL_PKG.SetItemAttrNumber (itemtype => itemtype,
6379 itemkey => itemkey,
6380 aname => 'PO_REVISION_NUM',
6381 avalue => l_revision_num2);
6382
6383 PO_WF_UTIL_PKG.SetItemAttrNumber (itemtype => itemtype,
6384 itemkey => itemkey,
6385 aname => 'PO_HEADER_ID',
6386 avalue => l_po_header_id);
6387
6388 else
6389 -- Bug 6722239 - Start
6390 -- Added a cursor above to fetch multiple records
6391 /*
6392 select distinct created_by ,
6393 change_request_group_id
6394 into l_supplier_user_id ,
6395 l_change_request_group_id
6396 from po_change_requests
6397 where request_status in ('BUYER_APP', 'WAIT_CANCEL_APP')
6398 and document_header_id = l_document_id
6399 and initiator = 'SUPPLIER'
6400 and document_type = 'PO';
6401 */
6402 -- Bug 6722239 - End
6403
6404 select pha.segment1,
6405 hou.name,
6406 pha.authorization_status,
6407 pha.revision_num,
6408 pha.type_lookup_code,
6409 pha.agent_id,
6410 pha.GLOBAL_AGREEMENT_FLAG,
6411 pha.vendor_id,
6412 pha.acceptance_required_flag
6413 into l_po_num,
6414 l_buyer_name,
6415 l_authorization_status,
6416 l_revision_num,
6417 l_type_lookup_code,
6418 l_buyer_agent_id,
6419 l_global_agreement_flag,
6420 l_vendor_id,
6421 l_acceptance_required_flag
6422 from po_headers_all pha,
6423 hr_all_organization_units_tl hou
6424 where pha.po_header_id = l_document_id
6425 and pha.org_id = hou.organization_id(+)
6426 and hou.language(+) = userenv('LANG');
6427
6428 select revision_num
6429 into l_revision_num2
6430 from po_headers_archive_all
6431 where po_header_id=l_document_id
6432 and latest_external_flag='Y';
6433
6434 l_header_cancel := 'N';
6435 if(l_change_request_group_id is not null) then
6436 open l_header_cancel_csr(l_change_request_group_id);
6437 fetch l_header_cancel_csr
6438 into l_id;
6439 close l_header_cancel_csr;
6440 if(l_id is not null) then
6441 l_header_cancel := 'Y';
6442 end if;
6443 end if;
6444
6445 if(l_type_lookup_code = 'STANDARD') then
6446 l_doc_hdr_info := fnd_message.get_string('PO','PO_WF_NOTIF_STD_PO')||' '||l_po_num;
6447 elsif (l_global_agreement_flag = 'Y' and l_type_lookup_code = 'BLANKET') then
6448 l_doc_hdr_info := fnd_message.get_string('PO','PO_GA_TYPE') ||' '||l_po_num;
6449 elsif(l_type_lookup_code = 'BLANKET') then
6450 l_doc_hdr_info := fnd_message.get_string('PO','PO_WF_NOTIF_BLANKET')||' '||l_po_num;
6451 elsif(l_type_lookup_code = 'CONTRACT') then
6452 l_doc_hdr_info := fnd_message.get_string('PO','PO_POTYPE_CNTR')||' '||l_po_num;
6453 elsif(l_type_lookup_code = 'PLANNED') then
6454 l_doc_hdr_info := fnd_message.get_string('PO','PO_WF_NOTIF_PLAN_PO')||' '||l_po_num;
6455 end if;
6456
6457 if(l_header_cancel = 'N') then
6458 fnd_message.set_name('PO','PO_WF_NOTIF_RESP_SUB_CHG');
6459 fnd_message.set_token('DOC',l_doc_hdr_info);
6460 fnd_message.set_token('BUYER',l_buyer_name);
6461 l_notification_subject := fnd_message.get;
6462 else
6463 fnd_message.set_name('PO','PO_WF_NOTIF_RESP_SUB_CAN');
6464 fnd_message.set_token('DOC',l_doc_hdr_info);
6465 fnd_message.set_token('BUYER',l_buyer_name);
6466 l_notification_subject := fnd_message.get;
6467 end if;
6468
6469 /*
6470 update po_headers_all
6471 set change_requested_by = null
6472 where po_header_id = l_document_id;
6473 */
6474
6475 Update_Chg_Req_If_Po_Apprvd(l_document_id,null);
6476
6477 PO_WF_UTIL_PKG.SetItemAttrNumber (itemtype => itemtype,
6478 itemkey => itemkey,
6479 aname => 'PO_HEADER_ID',
6480 avalue => l_document_id);
6481
6482 PO_WF_UTIL_PKG.SetItemAttrNumber (itemtype => itemtype,
6483 itemkey => itemkey,
6484 aname => 'PO_REVISION_NUM',
6485 avalue => l_revision_num2);
6486
6487 end if; --end of if on l_doc_type
6488
6489 -- Bug 6722239 - Start
6490 /* Added a cursor to fetch multiple records. Previous code was not capable of holding more than one record if
6491 fetched FROM database. Because of the cursor multiple records can be stored from which supplier user names
6492 will be fetched. So, the notifications will be send to all the supplier users who have done the modification
6493 to the PO during PO Acknowledgement process.*/
6494
6495 if(l_document_type = 'RELEASE') THEN
6496 t_document_type := 'RELEASE';
6497 ELSE
6498 t_document_type := 'PO';
6499 END IF;
6500
6501 open l_get_user_list_csr(l_document_id,t_document_type);
6502 loop
6503 fetch l_get_user_list_csr INTO
6504 l_supplier_user_id ,
6505 l_change_request_group_id;
6506 exit when l_get_user_list_csr%NOTFOUND;
6507 select user_name
6508 INTO l_user_name
6509 from fnd_user
6510 where user_id = l_supplier_user_id;
6511 l_users(u1) := l_user_name;
6512 u1 := u1 + 1;
6513 end loop;
6514 close l_get_user_list_csr;
6515 -- Bug 6722239 - End
6516
6517 x_progress := '001';
6518
6519 PO_WF_UTIL_PKG.SetItemAttrNumber (itemtype => itemtype,
6520 itemkey => itemkey,
6521 aname => 'CHANGE_REQUEST_GROUP_ID',
6522 avalue => l_change_request_group_id);
6523
6524 -- fix for bug 4946410 added signature flag check( these po's are blocked and changed to 'APPROVED' after background process is run
6525 if((l_authorization_status = 'APPROVED') OR (l_authorization_status = 'PRE-APPROVED' AND l_acceptance_required_flag = 'S')) then
6526 resultout := 'Y';
6527 l_user_id := FND_GLOBAL.USER_ID;
6528 -- For those records which has been approved default the promised date
6529 if(l_authorization_status = 'APPROVED' AND l_acceptance_required_flag = 'Y' AND g_default_promise_date = 'Y') THEN
6530 OPEN getLineLocID(l_change_request_group_id);
6531 LOOP
6532 FETCH getLineLocID INTO l_line_loc_id;
6533 EXIT WHEN getLineLocID%NOTFOUND;
6534 IF(l_document_type = 'RELEASE') THEN
6535 POS_ACK_PO.Acknowledge_promise_date(l_line_loc_id,l_po_header_id,l_document_id,l_revision_num,l_user_id);
6536 ELSE
6537 POS_ACK_PO.Acknowledge_promise_date(l_line_loc_id,l_document_id,null,l_revision_num,l_user_id);
6538 END IF;
6539 END LOOP;
6540 CLOSE getLineLocID;
6541 end if;
6542
6543 update po_change_requests
6544 set request_status = 'ACCEPTED'
6545 where change_request_group_id = l_change_request_group_id
6546 and request_status in ('BUYER_APP', 'WAIT_CANCEL_APP');
6547
6548 /* added code for bug 3574114 - update change active flag due to final buyer response */
6549
6550 update po_change_requests
6551 set change_active_flag = 'N'
6552 where change_request_group_id = l_change_request_group_id;
6553
6554 else
6555 resultout := 'N';
6556
6557 update po_change_requests
6558 set request_status = 'REJECTED',
6559 response_reason = null
6560 where change_request_group_id = l_change_request_group_id
6561 and request_status in ('BUYER_APP', 'WAIT_CANCEL_APP');
6562
6563 /* added code for bug 3574114 - update change active flag due to final buyer response */
6564
6565 update po_change_requests
6566 set change_active_flag = 'N'
6567 where change_request_group_id = l_change_request_group_id;
6568
6569 END if;
6570
6571
6572 x_progress := '002';
6573 -- Bug 6722239 - Start
6574 -- Commented the below code because the new changes will send
6575 -- notification to the role instead of a single supplier.
6576
6577 /*
6578 select user_name
6579 into l_supplier_username
6580 from fnd_user
6581 where user_id = l_supplier_user_id;
6582 */
6583
6584 /*Following code creates and Adhoc role for all the supplier users who have done
6585 some modification to the Purchase order during PO Acknowledgement process.
6586 l_role_name -> Adhoc role name created for the above mentioned users
6587 l_role_display_name -> Name which need to be mentioned in the Notification
6588 l_expiration_date -> Expiry date of the notification
6589 CreateAdHocRole2 -> Takes the above parameters as input and creates an Adhoc role.
6590 x_resultout -> Variable used to set the Performer in the Workflow.
6591 */
6592
6593 l_role_name := substr('ADHOC_SUP_CHG_RESP' || to_char(sysdate, 'JSSSSS')|| l_document_id || l_document_type, 1, 50);
6594
6595 select vendor_name
6596 into l_role_display_name
6597 from po_vendors
6598 where vendor_id=l_vendor_id;
6599
6600 if (l_document_type in ('PO', 'PA')) then
6601 select max(need_by_date)+180
6602 into l_expiration_date
6603 from po_line_locations
6604 where po_header_id = to_number(l_document_id)
6605 and cancel_flag = 'N';
6606
6607 if l_expiration_date <= sysdate then
6608 l_expiration_date := sysdate + 180;
6609 end if;
6610 elsif (l_document_type = 'RELEASE') then
6611 select max(need_by_date)+180
6612 into l_expiration_date
6613 from po_line_locations
6614 where po_release_id = to_number(l_document_id)
6615 and cancel_flag = 'N';
6616
6617 if l_expiration_date <= sysdate then
6618 l_expiration_date := sysdate + 180;
6619 end if;
6620 else
6621 l_expiration_date:=null;
6622 end if;
6623
6624 WF_DIRECTORY.CreateAdHocRole2(l_role_name,
6625 l_role_display_name,
6626 null,
6627 null,
6628 null,
6629 'MAILHTML',
6630 l_users,
6631 null,
6632 null,
6633 'ACTIVE',
6634 l_expiration_date);
6635 x_resultout:=l_role_name;
6636 -- Bug 6722239 - End
6637
6638 /* Bug 4949617 get the reponded_by id from po_change_requests table */
6639 OPEN getChangeRespBy(l_change_request_group_id);
6640 LOOP
6641 FETCH getChangeRespBy INTO l_responded_by_id;
6642 EXIT WHEN getChangeRespBy%NOTFOUND;
6643 END LOOP;
6644 CLOSE getChangeRespBy;
6645
6646 IF(l_responded_by_id = l_buyer_agent_id) THEN
6647 wf_directory.GetUserName ( p_orig_system => 'PER',
6648 p_orig_system_id => l_buyer_agent_id,
6649 p_name => l_buyer_username,
6650 p_display_name => l_buyer_disp_name);
6651 ELSE
6652 wf_directory.GetUserName ( p_orig_system => 'PER',
6653 p_orig_system_id => l_responded_by_id,
6654 p_name => l_buyer_username,
6655 p_display_name => l_buyer_disp_name);
6656 END IF;
6657
6658 if(l_document_type = 'RELEASE' OR l_document_type = 'PA') THEN
6659 l_po_style := 'NORMAL';
6660 elsif(l_document_type = 'PO') THEN
6661 p_header_id := l_document_id;
6662
6663 /*
6664 PO- API set item attribute PO_STYLE_TYPE depending upon the type of the PO
6665 PO_STYLE_TYPE - COMPLEX ,complex work PO's
6666 PO_STYLE_TYPE - NORMAL
6667 */
6668
6669 PO_COMPLEX_WORK_GRP.is_complex_work_po(1.0,
6670 p_header_id,
6671 x_return_status,
6672 x_complex_flag);
6673
6674 IF x_return_status IS NOT NULL AND x_return_status = FND_API.g_ret_sts_success THEN
6675 IF( g_fnd_debug = 'Y' AND FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
6676 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE,
6677 g_module_prefix,
6678 x_progress || 'x_return_status=' || x_return_status || 'x_complex_flag ' || x_complex_flag);
6679 END IF;
6680
6681 ELSE
6682 IF( g_fnd_debug = 'Y' AND FND_LOG.LEVEL_ERROR >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
6683 FND_LOG.STRING(FND_LOG.LEVEL_ERROR,
6684 g_module_prefix,
6685 x_progress ||'x_return_status = ' || x_return_status);
6686 END IF;
6687 END IF;
6688
6689 IF (x_complex_flag = 'N') THEN
6690 l_po_style :='NORMAL';
6691 ELSE
6692 l_po_style := 'COMPLEX';
6693 END IF;
6694 end if;
6695
6696 t_varname(1) := 'NTF_FOR_SUP_SUBJECT';
6697 t_varval(1) := 'PLSQL:PO_ChangeOrderWF_PVT.GEN_NTF_FOR_SUP_SUBJECT/'||itemkey;
6698 t_varname(2) := 'NTF_FOR_SUP_BUY_RP';
6699 -- RDP set the item Attribute to point to the notifications page
6700 t_varval(2) := 'JSP:/OA_HTML/OA.jsp?page=/oracle/apps/pos/notifications/webui/PosNotificationsRN'||
6701 '&L_CHG_REQ_GRP_ID=-&CHANGE_REQUEST_GROUP_ID-&L_PO_HEADER_ID=-&PO_HEADER_ID-&L_PO_RELEASE_ID=-&PO_RELEASE_ID-'||
6702 '&L_PO_ACC_REQ_FLAG=-&ACKNOWLEDGE_REQ_FLAG-&L_NOTIF_USAGE=-&NOTIF_USAGE-&L_EXPLAIN_FYI=-&EXPLAIN_FYI-&L_STYLE_PARAM=-&PO_STYLE_TYPE-';
6703 t_varname(3) := 'SUPPLIER_USERNAME';
6704 --t_varval(3) := l_supplier_username;
6705 t_varval(3) := x_resultout;
6706 t_varname(4) := 'FROM_BUYER';
6707 t_varval(4) := l_buyer_username;
6708 t_varname(5) := 'NOTIF_USAGE';
6709 t_varval(5) := 'BUYER_RESP';
6710 t_varname(6) := 'PO_STYLE_TYPE';
6711 t_varval(6) := l_po_style;
6712
6713 Wf_Engine.SetItemAttrTextArray(itemtype, itemkey,t_varname,t_varval);
6714
6715 exception when others then
6716 wf_core.context('PO_ChangeOrderWF_PVT','is_po_approved_by_hie',x_progress);
6717 raise;
6718 END is_po_approved_by_hie;
6719
6720
6721 procedure set_data_sup_chn_evt( itemtype in varchar2,
6722 itemkey in varchar2,
6723 actid in number,
6724 funcmode in varchar2,
6725 resultout out NOCOPY varchar2)
6726 IS
6727 l_document_id number;
6728 l_document_type po_document_types_all.document_type_code%TYPE;
6729 l_seq number;
6730 l_item_key varchar2(2000);
6731 x_progress varchar2(3) := '000';
6732 BEGIN
6733 l_document_id := wf_engine.GetItemAttrNumber(itemtype => itemtype,
6734 itemkey => itemkey,
6735 aname => 'DOCUMENT_ID');
6736 l_document_type := wf_engine.GetItemAttrText(itemtype => itemtype,
6737 itemkey => itemkey,
6738 aname => 'DOCUMENT_TYPE');
6739
6740
6741
6742 select PO_SUPPLIER_CHANGE_WF_S.nextval into l_seq from dual;
6743
6744 if(l_document_type = 'RELEASE') then
6745 l_item_key := 'SC_REL'||'-'||l_document_id||'-'||l_seq;
6746 else
6747 l_item_key := 'SC_PO'||'-'||l_document_id||'-'||l_seq;
6748 end if;
6749
6750
6751 wf_engine.SetItemAttrText ( itemtype => itemtype,
6752 itemkey => itemkey,
6753 aname => 'SUP_CHANGE_EVENT_KEY',
6754 avalue => l_item_key );
6755
6756
6757 exception when others then
6758 wf_core.context('PO_ChangeOrderWF_PVT','set_data_sup_chn_evt',x_progress);
6759 raise;
6760 END set_data_sup_chn_evt;
6761
6762
6763 procedure ANY_NEW_SUP_CHN( itemtype in varchar2,
6764 itemkey in varchar2,
6765 actid in number,
6766 funcmode in varchar2,
6767 resultout out NOCOPY varchar2)
6768 IS
6769 l_chg_req_grp_id number;
6770 l_header_id number;
6771 l_release_id number;
6772 l_doc_id number;
6773 l_doc_type po_document_types_all.document_type_code%TYPE;
6774 l_doc_subtype po_document_types_all.document_subtype%TYPE;
6775 l_employee_id number;
6776 l_acc_req_flag VARCHAR2(10);
6777
6778 x_progress varchar2(3) := '000';
6779 cursor l_change_csr(grp_id number) is
6780 select change_request_id from
6781 po_change_requests
6782 where action_type = 'MODIFICATION'
6783 and change_request_group_id = grp_id;
6784
6785 BEGIN
6786 l_header_id := wf_engine.GetItemAttrNumber(itemtype => itemtype,
6787 itemkey => itemkey,
6788 aname => 'PO_HEADER_ID');
6789 l_release_id := wf_engine.GetItemAttrNumber(itemtype => itemtype,
6790 itemkey => itemkey,
6791 aname => 'PO_RELEASE_ID');
6792
6793 l_chg_req_grp_id := wf_engine.GetItemAttrNumber(itemtype => itemtype,
6794 itemkey => itemkey,
6795 aname => 'CHANGE_REQUEST_GROUP_ID');
6796 l_acc_req_flag := wf_engine.GetItemAttrText( itemtype => itemtype,
6797 itemkey => itemkey,
6798 aname => 'ACKNOWLEDGE_REQ_FLAG');
6799
6800
6801 if(l_release_id is null) then
6802 l_doc_id := l_header_id;
6803 select
6804 type_lookup_code,
6805 agent_id
6806 into
6807 l_doc_subtype,
6808 l_employee_id
6809 from po_headers_all
6810 where po_header_id = l_header_id;
6811
6812 if(l_doc_subtype = 'BLANKET' or l_doc_subtype = 'CONTRACT') then
6813 l_doc_type := 'PA';
6814 elsif(l_doc_subtype in ('PLANNED','STANDARD')) then
6815 l_doc_type := 'PO';
6816 end if;
6817 else
6818 l_doc_id := l_release_id;
6819 l_doc_type := 'RELEASE';
6820 select
6821 pha.type_lookup_code,
6822 pra.agent_id
6823 into
6824 l_doc_subtype,
6825 l_employee_id
6826 from po_headers_all pha, po_releases_all pra
6827 where pra.po_release_id = l_release_id
6828 and pra.po_header_id = pha.po_header_id;
6829 end if;
6830 x_progress := '001';
6831 if(l_chg_req_grp_id is null) then
6832 resultout := 'N';
6833 wf_engine.SetItemAttrText ( itemtype => itemtype,
6834 itemkey => itemkey,
6835 aname => 'EXPLAIN_FYI',
6836 avalue => '');
6837
6838 if(l_acc_req_flag = 'Y') then -- RDP no changes just Acknowledged ( Set the NOTIF_USAGE as BUYER_ACK)
6839 wf_engine.SetItemAttrText ( itemtype => itemtype,
6840 itemkey => itemkey,
6841 aname => 'NOTIF_USAGE',
6842 avalue => 'BUYER_ACK');
6843 end if;
6844 else
6845 resultout := 'Y';
6846 InsertActionHist(
6847 p_doc_id => l_doc_id,
6848 p_doc_type => l_doc_type,
6849 p_doc_subtype => l_doc_subtype,
6850 p_employee_id => null,
6851 p_action => 'SUBMIT CHANGE',
6852 p_note => null,
6853 p_path_id => null);
6854 end if;
6855 exception when others then
6856 wf_core.context('PO_ChangeOrderWF_PVT','ANY_NEW_SUP_CHN',x_progress);
6857 raise;
6858 END ANY_NEW_SUP_CHN;
6859
6860 procedure any_supplier_change( itemtype in varchar2,
6861 itemkey in varchar2,
6862 actid in number,
6863 funcmode in varchar2,
6864 resultout out NOCOPY varchar2)
6865 IS
6866 l_document_id number;
6867 l_document_type po_document_types_all.document_type_code%TYPE;
6868 l_count number;
6869 l_cancel_app_count number; /* fix for bug 3864512 */
6870 x_progress varchar2(100) := '000';
6871 l_change_request_group_id number := null;
6872 BEGIN
6873
6874 l_document_id := wf_engine.GetItemAttrNumber(itemtype => itemtype,
6875 itemkey => itemkey,
6876 aname => 'DOCUMENT_ID');
6877 l_document_type := wf_engine.GetItemAttrText(itemtype => itemtype,
6878 itemkey => itemkey,
6879 aname => 'DOCUMENT_TYPE');
6880
6881
6882 if(l_document_type = 'RELEASE') then
6883 select count(1)
6884 into l_count
6885 from po_change_requests
6886 where initiator = 'SUPPLIER'
6887 and document_type = 'RELEASE'
6888 and po_release_id = l_document_id
6889 and request_status = 'BUYER_APP';
6890
6891 select count(1)
6892 into l_cancel_app_count
6893 from po_change_requests
6894 where initiator = 'SUPPLIER'
6895 and document_type = 'RELEASE'
6896 and po_release_id = l_document_id
6897 and request_status = 'WAIT_CANCEL_APP';
6898
6899 if ((l_count > 0) OR (l_cancel_app_count > 0)) then
6900 -- no chance for no_data_found exception.
6901 select distinct(change_request_group_id)
6902 into l_change_request_group_id
6903 from po_change_requests
6904 where initiator = 'SUPPLIER'
6905 and document_type = 'RELEASE'
6906 and po_release_id = l_document_id
6907 and request_status in ('BUYER_APP', 'WAIT_CANCEL_APP');
6908 end if;
6909
6910 -- need to update the processed cancel shipment record to ACCEPTED
6911 -- so as to prevent it from blocking processing of other records
6912
6913 if (l_count > 0 AND l_cancel_app_count > 0) then
6914
6915 update po_change_requests set request_status = 'ACCEPTED'
6916 where initiator = 'SUPPLIER'
6917 and document_type = 'RELEASE'
6918 and po_release_id = l_document_id
6919 and request_status = 'WAIT_CANCEL_APP';
6920
6921 end if;
6922
6923 else
6924 select count(1)
6925 into l_count
6926 from po_change_requests
6927 where initiator = 'SUPPLIER'
6928 and document_type = 'PO'
6929 and document_header_id = l_document_id
6930 and request_status = 'BUYER_APP';
6931
6932 select count(1)
6933 into l_cancel_app_count
6934 from po_change_requests
6935 where initiator = 'SUPPLIER'
6936 and document_type = 'PO'
6937 and document_header_id = l_document_id
6938 and request_status = 'WAIT_CANCEL_APP';
6939
6940 if ((l_count > 0) OR (l_cancel_app_count > 0)) then
6941 -- no chance for no_data_found exception.
6942 select distinct(change_request_group_id)
6943 into l_change_request_group_id
6944 from po_change_requests
6945 where initiator = 'SUPPLIER'
6946 and document_type = 'PO'
6947 and document_header_id = l_document_id
6948 and request_status in ('BUYER_APP', 'WAIT_CANCEL_APP');
6949 end if;
6950
6951 -- need to update the processed cancel shipment record to ACCEPTED
6952 -- so as to prevent it from blocking processing of other records
6953
6954 if (l_count > 0 AND l_cancel_app_count > 0) then
6955
6956 update po_change_requests set request_status = 'ACCEPTED'
6957 where initiator = 'SUPPLIER'
6958 and document_type = 'PO'
6959 and document_header_id = l_document_id
6960 and request_status = 'WAIT_CANCEL_APP';
6961
6962 end if;
6963
6964 end if;
6965
6966 begin
6967 PO_WF_UTIL_PKG.SetItemAttrNumber (itemtype => itemtype,
6968 itemkey => itemkey,
6969 aname => 'CHANGE_REQUEST_GROUP_ID',
6970 avalue => l_change_request_group_id);
6971 exception when others then
6972 null;
6973 end;
6974
6975 if ((l_count > 0 AND l_cancel_app_count = 0) OR (l_count = 0 AND l_cancel_app_count > 0)) then
6976 resultout := 'Y';
6977 else
6978 resultout := 'N';
6979 end if;
6980
6981 exception when no_data_found then
6982 wf_core.context('PO_ChangeOrderWF_PVT','any_supplier_change','010');
6983 raise;
6984 when others then
6985 wf_core.context('PO_ChangeOrderWF_PVT','any_supplier_change',x_progress);
6986 raise;
6987 END any_supplier_change;
6988
6989
6990
6991 procedure NotifySupAllChgRpdWF( p_header_id in number,
6992 p_release_id in number,
6993 p_revision_num in number,
6994 p_chg_req_grp_id in number)
6995 IS
6996 l_api_name varchar2(50) := 'NotifySupAllChgRpdWF';
6997 l_progress varchar2(100) := '000';
6998 l_item_key varchar2(2000);
6999 l_seq number;
7000 l_supplier_username fnd_user.user_name%TYPE;
7001 l_notification_subject varchar2(2000);
7002
7003 --l_po_num po_headers_all.segment1%TYPE;
7004 --l_blanket_num po_headers_all.segment1%TYPE;
7005 --l_release_num number;
7006 --l_buyer_name hr_all_organization_units_tl.name%TYPE;
7007 --l_type_lookup_code po_headers_all.type_lookup_code%TYPE;
7008 --l_document_type varchar2(2000);
7009 l_buyer_agent_id number;
7010 l_responded_by_id number;
7011 l_buyer_username fnd_user.user_name%TYPE;
7012 l_buyer_disp_name varchar2(2000);
7013 --l_doc_type po_document_types_all.document_type_code%TYPE;
7014 l_document_id number;
7015 l_po_style varchar2(10);
7016 x_return_status varchar2(1);
7017 x_complex_flag varchar2(1);
7018
7019 n_varname Wf_Engine.NameTabTyp;
7020 n_varval Wf_Engine.NumTabTyp;
7021 t_varname Wf_Engine.NameTabTyp;
7022 t_varval Wf_Engine.TextTabTyp;
7023
7024
7025 --l_id number;
7026 --l_header_cancel varchar2(1);
7027 --cursor l_header_cancel_csr(grp_id number) is
7028 --select change_request_id
7029 --from po_change_requests
7030 --where change_request_group_id = grp_id
7031 --and action_type = 'CANCELLATION'
7032 --and request_level = 'HEADER';
7033 --l_doc_hdr_info varchar2(2000);
7034 l_supplier_user_id number;
7035
7036 /* Curosr to get the change_responded by*/
7037 CURSOR getChangeRespBy(l_chg_req_grp_id_csr IN NUMBER) IS
7038 SELECT distinct fndu.employee_id
7039 FROM po_change_requests pcr,
7040 fnd_user fndu
7041 WHERE pcr.change_request_group_id = l_chg_req_grp_id_csr
7042 AND fndu.user_id = pcr.responded_by;
7043
7044
7045 BEGIN
7046 select PO_SUPPLIER_CHANGE_WF_S.nextval into l_seq from dual;
7047 if(p_release_id is not null) then
7048 l_document_id := p_release_id;
7049 l_item_key := 'NSCR'||'-'||to_char(p_release_id)||'-'||to_char(p_revision_num)||'-'||to_char(l_seq);
7050 else
7051 l_document_id := p_header_id;
7052 l_item_key := 'NSCR'||'-'||to_char(p_header_id)||'-'||to_char(p_revision_num)||'-'||to_char(l_seq);
7053 end if;
7054
7055 wf_engine.createProcess ( ItemType => 'POSCHORD',
7056 ItemKey => l_item_key,
7057 Process => 'CHG_RESPONDED_FYI_TO_SUPPLIER');
7058
7059 l_progress := '001';
7060 if(p_release_id is null) then
7061 select pha.agent_id
7062 into l_buyer_agent_id
7063 from po_headers_all pha
7064 where pha.po_header_id = p_header_id;
7065 else
7066 select pra.agent_id
7067 into l_buyer_agent_id
7068 from po_releases_all pra
7069 where pra.po_release_id = p_release_id;
7070 end if;
7071
7072 /* Commenting out for bug 3484201. Since change has already been requested by a
7073 specific user, the notification needs to be sent to the user on the change request */
7074
7075 --PO_REQAPPROVAL_INIT1.locate_notifier(l_document_id, l_doc_type, l_supplier_username);
7076
7077 if(l_supplier_username is null) then
7078 select max(created_by)
7079 into l_supplier_user_id
7080 from po_change_requests
7081 where change_request_group_id = p_chg_req_grp_id;
7082
7083 select user_name
7084 into l_supplier_username
7085 from fnd_user
7086 where user_id = l_supplier_user_id;
7087 end if;
7088
7089 /* Bug 4949617 get the reponded_by id from po_change_requests table */
7090 OPEN getChangeRespBy(p_chg_req_grp_id);
7091 LOOP
7092 FETCH getChangeRespBy INTO l_responded_by_id;
7093 EXIT WHEN getChangeRespBy%NOTFOUND;
7094 END LOOP;
7095 CLOSE getChangeRespBy;
7096
7097 IF(l_responded_by_id = l_buyer_agent_id) THEN
7098
7099 wf_directory.GetUserName ( p_orig_system => 'PER',
7100 p_orig_system_id => l_buyer_agent_id,
7101 p_name => l_buyer_username,
7102 p_display_name => l_buyer_disp_name);
7103 ELSE
7104 wf_directory.GetUserName ( p_orig_system => 'PER',
7105 p_orig_system_id => l_responded_by_id,
7106 p_name => l_buyer_username,
7107 p_display_name => l_buyer_disp_name);
7108 END IF;
7109
7110
7111 l_progress := '002: call is_complex_po'; -- RDP Changes
7112
7113 /* PO- API set item attribute PO_STYLE_TYPE depending upon the type of the PO
7114 PO_STYLE_TYPE - COMPLEX ,complex work PO's
7115 PO_STYLE_TYPE - NORMAL */
7116
7117 IF( p_release_id is not null) THEN
7118 l_po_style := 'NORMAL';
7119
7120 ELSIF( p_release_id is null) THEN
7121 PO_COMPLEX_WORK_GRP.is_complex_work_po(
7122 1.0,
7123 p_header_id,
7124 x_return_status,
7125 x_complex_flag);
7126
7127 IF x_return_status IS NOT NULL AND x_return_status = FND_API.g_ret_sts_success THEN
7128 IF( g_fnd_debug = 'Y' AND FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
7129 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE,
7130 g_module_prefix,
7131 l_progress
7132 || 'x_return_status=' || x_return_status
7133 || 'x_complex_flag ' || x_complex_flag);
7134 END IF;
7135
7136 ELSE
7137 IF( g_fnd_debug = 'Y' AND FND_LOG.LEVEL_ERROR >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
7138 FND_LOG.STRING(FND_LOG.LEVEL_ERROR,
7139 g_module_prefix,
7140 l_progress
7141 ||'x_return_status = ' || x_return_status);
7142 END IF;
7143 END IF;
7144
7145 IF(x_complex_flag = 'N') THEN
7146 l_po_style :='NORMAL';
7147 ELSE
7148 l_po_style := 'COMPLEX';
7149 END IF;
7150
7151 END IF;
7152
7153
7154 n_varname(1) := 'PO_HEADER_ID';
7155 n_varval(1) := p_header_id;
7156 n_varname(2) := 'PO_RELEASE_ID';
7157 n_varval(2) := p_release_id;
7158 n_varname(3) := 'PO_REVISION_NUM';
7159 n_varval(3) := p_revision_num;
7160 n_varname(4) := 'CHANGE_REQUEST_GROUP_ID';
7161 n_varval (4) := p_chg_req_grp_id;
7162
7163 t_varname(1) := 'SUPPLIER_USERNAME';
7164 t_varval(1) := l_supplier_username;
7165 /* t_varname(2) := 'NTF_FOR_SUP_BUY_RP';
7166 t_varval(2) := 'PLSQLCLOB:PO_ChangeOrderWF_PVT.GEN_NTF_FOR_SUP_BUY_RP/'|| p_chg_req_grp_id; */
7167
7168 t_varname(2) := 'NTF_FOR_SUP_BUY_RP'; -- RDP changing to point to the notifications Page
7169 t_varval(2) := 'JSP:/OA_HTML/OA.jsp?page=/oracle/apps/pos/notifications/webui/PosNotificationsRN'||
7170 '&L_CHG_REQ_GRP_ID=-&CHANGE_REQUEST_GROUP_ID-&L_PO_HEADER_ID=-&PO_HEADER_ID-&L_PO_RELEASE_ID=-&PO_RELEASE_ID-'||
7171 '&L_PO_ACC_REQ_FLAG=-&ACKNOWLEDGE_REQ_FLAG-&L_NOTIF_USAGE=-&NOTIF_USAGE-&L_EXPLAIN_FYI=-&EXPLAIN_FYI-&L_STYLE_PARAM=-&PO_STYLE_TYPE-';
7172 t_varname(3) := 'NTF_FOR_SUP_SUBJECT';
7173 t_varval(3) := 'PLSQL:PO_ChangeOrderWF_PVT.GEN_NTF_FOR_SUP_SUBJECT/'||l_item_key;
7174 t_varname(4) := 'FROM_BUYER';
7175 t_varval(4) := l_buyer_username;
7176 t_varname(5) := 'NOTIF_USAGE';
7177 t_varval(5) := 'BUYER_RESP';
7178 t_varname(6) := 'PO_STYLE_TYPE';
7179 t_varval(6) := l_po_style;
7180 t_varname(7) := '#WFM_HTMLAGENT';
7181 t_varval(7) := fnd_profile.value('POS_EXTERNAL_URL');
7182
7183
7184 Wf_Engine.SetItemAttrNumberArray('POSCHORD', l_item_key,n_varname,n_varval);
7185 Wf_Engine.SetItemAttrTextArray('POSCHORD', l_item_key,t_varname,t_varval);
7186 l_progress := '003';
7187 wf_engine.StartProcess( ItemType => 'POSCHORD',
7188 ItemKey => l_item_key);
7189
7190 exception when others then
7191 IF g_fnd_debug = 'Y' AND FND_LOG.LEVEL_UNEXPECTED >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
7192 FND_LOG.string(FND_LOG.level_unexpected, g_module_prefix ||
7193 l_api_name || '.others_exception', l_progress||':'||sqlerrm);
7194 END IF;
7195 END NotifySupAllChgRpdWF;
7196
7197 procedure ProcessHdrCancelResponse( p_api_version in number,
7198 x_return_status out NOCOPY varchar2,
7199 p_header_id in number,
7200 p_release_id in number,
7201 p_revision_num in number,
7202 p_user_id in number,
7203 p_acc_rej in varchar2,
7204 p_reason in varchar2)
7205 IS
7206 l_api_name varchar2(50) := 'ProcessHdrCancelResponse';
7207 l_progress varchar2(5) := '000';
7208 l_chn_req_grp_id number;
7209 l_retcode number;
7210 l_retmsg varchar2(2000);
7211 l_doc_check_rec_type POS_ERR_TYPE;
7212
7213 BEGIN
7214 x_return_status := 'S';
7215 if(p_release_id is null) then
7216 select change_request_group_id
7217 into l_chn_req_grp_id
7218 from po_change_requests
7219 where document_header_id = p_header_id
7220 and request_status = 'PENDING'
7221 and request_level = 'HEADER'
7222 and initiator = 'SUPPLIER'
7223 and action_type ='CANCELLATION';
7224
7225 else
7226 select change_request_group_id
7227 into l_chn_req_grp_id
7228 from po_change_requests
7229 where po_release_id = p_release_id
7230 and request_status = 'PENDING'
7231 and request_level = 'HEADER'
7232 and initiator = 'SUPPLIER'
7233 and action_type ='CANCELLATION';
7234 end if;
7235 l_progress := '001';
7236 if(p_acc_rej = 'A') then
7237 update po_change_requests
7238 set request_status = 'BUYER_APP',
7239 responded_by = p_user_id,
7240 response_date = sysdate,
7241 response_reason = p_reason
7242 where change_request_group_id = l_chn_req_grp_id;
7243 else
7244 update po_change_requests
7245 set request_status = 'REJECTED',
7246 change_active_flag = 'N',
7247 responded_by = p_user_id,
7248 response_date = sysdate,
7249 response_reason = p_reason
7250 where change_request_group_id = l_chn_req_grp_id;
7251 end if;
7252 l_progress := '002';
7253 ProcessResponse(1.0, x_return_status, p_header_id, p_release_id,
7254 p_revision_num, l_chn_req_grp_id, p_user_id, l_retmsg,
7255 l_retcode, l_doc_check_rec_type, null, 'Y');
7256
7257 exception when others then
7258 IF g_fnd_debug = 'Y' AND FND_LOG.LEVEL_UNEXPECTED >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
7259 FND_LOG.string(FND_LOG.level_unexpected, g_module_prefix ||
7260 l_api_name || '.others_exception', l_progress||':'||sqlerrm);
7261 END IF;
7262 x_return_status := 'U';
7263 End ProcessHdrCancelResponse;
7264
7265
7266 /*
7267 *This API could originate from 2 sources
7268 *1. Buyer Accept or Reject Supplier Change through Notification => Buyer Accept ALL OR Rejects ALL
7269 *2. Buyer Accept or Reject Supplier Change through UI. If response DOES NOT cover all changes
7270 * return;
7271 * Else (response cover all changes)
7272 * continue...
7273 * 1. Send Notification to Supplier if all changes are responded
7274 * => NO BUYER_APP/PENDING
7275 * 2. Send Notification to Buyer if PO requires Acknowledgement, and everything is responded
7276 * => ACC_REQUIRED_FLAG = 'Y'
7277 * NO BUYER_APP/PENDING
7278 * ALL SHIPMENTS ACCEPTED/REJECTED
7279 *
7280 *
7281 */
7282 procedure ProcessResponse(p_api_version in number,
7283 x_return_status out NOCOPY varchar2,
7284 p_header_id in number,
7285 p_release_id in number,
7286 p_revision_num in number,
7287 p_chg_req_grp_id in number,
7288 p_user_id in number,
7289 x_err_msg out NOCOPY varchar2,
7290 x_return_code out NOCOPY number,
7291 x_doc_check_rec_type out NOCOPY POS_ERR_TYPE,
7292 p_flag in varchar2,
7293 p_launch_approvals_flag in varchar2,
7294 p_mass_update_releases IN VARCHAR2 DEFAULT NULL -- Bug 3373453
7295 )
7296 IS
7297 l_api_name varchar2(50):= 'ProcessResponse';
7298 l_count number;
7299 l_number_of_buyer_app number;
7300 l_acc_req_flag varchar2(1);
7301 l_item_key po_change_requests.wf_item_key%TYPE;
7302 l_return_status varchar2(1);
7303 l_po_cancel_api exception;
7304 l_org_id number;
7305 l_agent_id number;
7306 x_progress varchar2(3):='000';
7307 l_cancel_status varchar2(1);
7308 l_mc_return_status varchar2(1);
7309 l_mc_return_code number;
7310 l_kickoff_status varchar2(1);
7311 l_kickoff_msg varchar2(2000);
7312 l_doc_id number;
7313 l_employee_id number;
7314
7315 l_authorization_status po_headers_all.authorization_status%TYPE;
7316 l_add_changes_accepted NUMBER;
7317
7318 l_doc_type po_document_types_all.document_type_code%TYPE;
7319 l_doc_subtype po_document_types_all.document_subtype%TYPE;
7320 l_id number;
7321 l_action po_lookup_codes.lookup_code%TYPE;
7322 l_acc_id number;
7323 l_rej_id number;
7324 l_closed_code po_headers_all.closed_code%type;
7325
7326 cursor l_accept_csr(grp_id number) is
7327 select change_request_id
7328 from po_change_requests
7329 where change_request_group_id = grp_id
7330 and request_status in ('ACCEPTED','BUYER_APP');
7331
7332 cursor l_reject_csr(grp_id number) is
7333 select change_request_id
7334 from po_change_requests
7335 where change_request_group_id = grp_id
7336 and request_status = 'REJECTED';
7337
7338 cursor l_pending_csr(grp_id number) is
7339 select change_request_id
7340 from po_change_requests
7341 where change_request_group_id = grp_id
7342 and request_status = 'PENDING';
7343
7344
7345 BEGIN
7346
7347 x_return_status := FND_API.G_RET_STS_SUCCESS;
7348
7349
7350 if p_release_id is not null then
7351 l_doc_id := p_release_id;
7352 l_doc_type := 'RELEASE';
7353 select
7354 por.org_id ,
7355 por.agent_id,
7356 pha.type_lookup_code,
7357 nvl(por.closed_code,'OPEN')
7358 into
7359 l_org_id,
7360 l_agent_id,
7361 l_doc_subtype,
7362 l_closed_code
7363 from po_releases_all por,
7364 po_headers_all pha
7365 where po_release_id = p_release_id
7366 and por.po_header_id= pha.po_header_id;
7367
7368
7369 else
7370 l_doc_id := p_header_id;
7371 select
7372 poh.agent_id,
7373 poh.org_id,
7374 poh.type_lookup_code,
7375 nvl(poh.closed_code,'OPEN')
7376 into
7377 l_agent_id,
7378 l_org_id,
7379 l_doc_subtype,
7380 l_closed_code
7381 from po_headers_all poh
7382 where poh.po_header_id = p_header_id ;
7383
7384 if(l_doc_subtype = 'BLANKET' or l_doc_subtype = 'CONTRACT') then
7385 l_doc_type := 'PA';
7386 elsif(l_doc_subtype = 'PLANNED' or l_doc_subtype = 'STANDARD') then
7387 l_doc_type := 'PO';
7388 end if;
7389 end if;
7390 initialize(l_agent_id, l_org_id);
7391 PO_MOAC_UTILS_PVT.set_org_context(l_org_id) ; -- <R12 MOAC>
7392
7393 --Check if any Change is still Pending, if yes, return
7394 --This is just for double check.. This API should only be called when all changes are responded
7395 open l_pending_csr(p_chg_req_grp_id);
7396 fetch l_pending_csr into l_id;
7397 if (l_id is not null) then
7398 x_return_status := FND_API.G_RET_STS_ERROR;
7399 x_err_msg := 'PENDING RECORDS EXIST';
7400 close l_pending_csr;
7401 return;
7402 end if;
7403 close l_pending_csr;
7404 l_id := null;
7405
7406 --Action History
7407 open l_accept_csr(p_chg_req_grp_id);
7408 fetch l_accept_csr into l_acc_id;
7409 close l_accept_csr;
7410 open l_reject_csr(p_chg_req_grp_id);
7411 fetch l_reject_csr into l_rej_id;
7412 close l_reject_csr;
7413
7414 if(l_acc_id is not null and l_rej_id is not null) then
7415 l_action := 'RESPOND';
7416 elsif(l_acc_id is not null) then
7417 l_action := 'ACCEPT';
7418 elsif(l_rej_id is not null) then
7419 l_action := 'REJECT';
7420 end if;
7421
7422 if(l_closed_code = 'OPEN') then
7423
7424 l_employee_id := l_agent_id;
7425 if (p_user_id is not null) then
7426 begin
7427 select employee_id into l_employee_id from fnd_user where user_id = p_user_id;
7428 exception when others then
7429 null;
7430 end;
7431 end if;
7432
7433 if (l_employee_id is null) then
7434
7435 l_employee_id := l_agent_id;
7436 end if ;
7437
7438
7439 InsertActionHist(
7440 p_doc_id => l_doc_id,
7441 p_doc_type => l_doc_type,
7442 p_doc_subtype => l_doc_subtype,
7443 p_employee_id => l_employee_id,
7444 -- p_employee_id => l_agent_id,
7445 -- p_employee_id => p_user_id, -- RDP ( instead of agent_id , user_id should be used)
7446 p_action => l_action,
7447 p_note => null,
7448 p_path_id => null);
7449 end if;
7450
7451 /* 0. Are changes responded at header level?
7452 If NO => There is a notification waiting for Buyer to Respond at the Header Level.
7453 Kill IT!!!
7454 */
7455 x_progress:='001';
7456 if(p_flag is null) then
7457 begin
7458 select distinct wf_item_key
7459 into l_item_key
7460 from po_change_requests
7461 where change_request_group_id = p_chg_req_grp_id;
7462 wf_engine.completeActivity('POSCHORD',l_item_key,'NOTIFY_BUYER_OF_CHN', 'Abort');
7463 exception when others then
7464 null;
7465 end;
7466 end if;
7467
7468 x_progress:='002';
7469 CancelPO(l_cancel_status, p_header_id,p_release_id,p_chg_req_grp_id);
7470
7471
7472 x_progress:='004';
7473
7474 -- 2. Update po_change_requests table.. for those supplier change request to cancel, if accepted
7475 -- change them from BUYER_APP to ACCEPTED
7476 update po_change_requests
7477 set request_status = 'ACCEPTED'
7478 -- change_active_flag = 'N' /* commented out due to bug 3574114 */
7479 where change_request_group_id = p_chg_req_grp_id
7480 and request_status in ('BUYER_APP', 'WAIT_CANCEL_APP')
7481 and action_type = 'CANCELLATION';
7482
7483 /*
7484 WHETHER TO SEND NOTIFICATION TO SUPPLIER OR NOT:
7485 At this Stage, there is NO MORE Changes in Pending Stage.
7486 If There is no more change that requires Buyer Hierachy Approval (BUYER_APP),
7487 we know the supplier changes have been fully responded. => Send Notification to Supplier
7488 Else
7489 There are records which requries Buyer Hierachy Approval
7490 => MoveChangeToPO, kick off Buyer Approval Workflow
7491 */
7492
7493 -- Bug 3771964
7494
7495 if (l_rej_id is not null) then
7496 if (p_release_id is null) then
7497 update po_line_locations_all
7498 set approved_flag = 'Y'
7499 where po_header_id=p_header_id
7500 and po_release_id is null;
7501 else
7502 update po_line_locations_all
7503 set approved_flag = 'Y'
7504 where po_header_id=p_header_id
7505 and po_release_id = p_release_id;
7506 end if;
7507 end if;
7508
7509 x_progress:='005';
7510
7511 select count(1)
7512 into l_number_of_buyer_app
7513 from po_change_requests
7514 where change_request_group_id = p_chg_req_grp_id
7515 and request_status = 'BUYER_APP';
7516
7517 if(l_number_of_buyer_app = 0) then
7518 x_progress:='006';
7519
7520 NotifySupAllChgRpdWF(
7521 p_header_id,
7522 p_release_id,
7523 p_revision_num,
7524 p_chg_req_grp_id);
7525
7526 else
7527 -- Call MoveChangeToPO
7528 x_progress:='007';
7529 PO_CHANGE_RESPONSE_PVT.MoveChangeToPO(
7530 1.0,
7531 l_mc_return_status,
7532 p_header_id,
7533 p_release_id,
7534 p_chg_req_grp_id ,
7535 p_user_id,
7536 l_mc_return_code,
7537 x_err_msg,
7538 x_doc_check_rec_type,
7539 p_launch_approvals_flag,
7540 p_mass_update_releases
7541 );
7542
7543 x_return_status := l_mc_return_status;
7544 x_return_code := l_mc_return_code;
7545
7546
7547 /* COMMENTED OUT - WAIT_MGR_APP status is no longer used and is replaced by BUYER_APP
7548 update po_change_requests
7549 set request_status = 'WAIT_MGR_APP'
7550 where change_request_group_id = p_chg_req_grp_id
7551 and request_status = 'BUYER_APP';
7552 */
7553
7554 x_progress:='008';
7555 /* COMMENTED OUT - Now handled in Change PO API
7556 KickOffPOApproval(
7557 1.0,
7558 l_kickoff_status,
7559 p_header_id,
7560 p_release_id,
7561 l_kickoff_msg);
7562
7563
7564 if(l_kickoff_status <> FND_API.G_RET_STS_SUCCESS) then
7565 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
7566 x_err_msg := 'STARTPOWF_ERROR:'||l_kickoff_msg;
7567 end if;
7568 */
7569 end if;
7570
7571 exception when others then
7572 IF g_fnd_debug = 'Y' AND FND_LOG.LEVEL_UNEXPECTED >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
7573 FND_LOG.string(FND_LOG.level_unexpected, g_module_prefix ||
7574 l_api_name || '.others_exception', x_progress||':'||sqlerrm);
7575 END IF;
7576 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
7577 x_err_msg := x_progress||'*'||sqlerrm;
7578
7579 END ProcessResponse;
7580
7581 procedure NOTIFY_REQ_PLAN ( itemtype in varchar2,
7582 itemkey in varchar2,
7583 actid in number,
7584 funcmode in varchar2,
7585 resultout out NOCOPY varchar2)
7586 IS
7587 l_progress varchar2(5) := '000';
7588 l_chg_req_grp_id number;
7589 l_requestor_id number;
7590 l_planner_id number;
7591 l_header_id number;
7592 l_release_id number;
7593 l_revision_num number;
7594 l_agent_id number;
7595
7596 --Bug6885296 - Added condition to restrict requesters from being
7597 --notified when supplier requests changes for Blanket Purchase Agreement.
7598
7599 cursor l_requestors_csr(grp_id number)
7600 is
7601 select pda.deliver_to_person_id
7602 from
7603 po_change_requests pcr,
7604 po_distributions_all pda,
7605 po_line_locations_all pll
7606 where pcr.change_request_group_id = grp_id
7607 and pcr.request_level = 'LINE'
7608 and pcr.document_line_id = pda.po_line_id
7609 and pda.line_location_id = pll.line_location_id
7610 and pll.shipment_type = 'STANDARD'
7611 union
7612 select pda.deliver_to_person_id
7613 from
7614 po_change_requests pcr,
7615 po_distributions_all pda
7616 where pcr.change_request_group_id = grp_id
7617 and pcr.request_level = 'SHIPMENT'
7618 and pcr.document_line_location_id = pda.line_location_id;
7619
7620 cursor l_planners_csr(grp_id number)
7621 is
7622 select
7623 distinct mtp.employee_id
7624 from
7625 mtl_system_items msi,
7626 mtl_planners mtp,
7627 po_change_requests pcr,
7628 po_lines_all pla,
7629 financials_system_params_all fsp
7630 where pcr.change_request_group_id = grp_id
7631 and pcr.document_line_id = pla.po_line_id
7632 and pla.item_id = msi.inventory_item_id
7633 and pla.org_id = fsp.org_id
7634 and fsp.inventory_organization_id= msi.organization_id
7635 and msi.planner_code = mtp.planner_code
7636 and msi.organization_id = mtp.organization_id;
7637
7638 BEGIN
7639 l_header_id := wf_engine.GetItemAttrNumber(itemtype => itemtype,
7640 itemkey => itemkey,
7641 aname => 'PO_HEADER_ID');
7642 l_release_id := wf_engine.GetItemAttrNumber(itemtype => itemtype,
7643 itemkey => itemkey,
7644 aname => 'PO_RELEASE_ID');
7645 l_revision_num := wf_engine.GetItemAttrNumber(itemtype => itemtype,
7646 itemkey => itemkey,
7647 aname => 'PO_REVISION_NUM');
7648
7649 l_chg_req_grp_id := wf_engine.GetItemAttrNumber(itemtype => itemtype,
7650 itemkey => itemkey,
7651 aname => 'CHANGE_REQUEST_GROUP_ID');
7652 if(l_release_id is null) then
7653 select agent_id
7654 into l_agent_id
7655 from po_headers_all
7656 where po_header_id = l_header_id;
7657 else
7658 select agent_id
7659 into l_agent_id
7660 from po_releases_all
7661 where po_release_id = l_release_id;
7662 end if;
7663
7664 l_progress := '001';
7665 open l_requestors_csr( l_chg_req_grp_id );
7666 loop
7667 fetch l_requestors_csr into l_requestor_id;
7668 exit when l_requestors_csr%NOTFOUND;
7669 if(l_requestor_id is not null AND
7670 l_requestor_id <> l_agent_id) then
7671 Notify_Requester_Sup_Change(
7672 l_header_id,
7673 l_release_id,
7674 l_revision_num,
7675 l_chg_req_grp_id,
7676 l_requestor_id);
7677 end if;
7678 end loop;
7679 close l_requestors_csr;
7680
7681 l_progress := '002';
7682
7683 open l_planners_csr(l_chg_req_grp_id );
7684 loop
7685 fetch l_planners_csr into l_planner_id;
7686 exit when l_planners_csr%NOTFOUND;
7687 if(l_planner_id is not null AND
7688 l_planner_id <> l_agent_id) then
7689 Notify_Planner_Sup_Change(
7690 l_header_id,
7691 l_release_id,
7692 l_revision_num,
7693 l_chg_req_grp_id,
7694 l_planner_id);
7695 end if;
7696 end loop;
7697 close l_planners_csr;
7698
7699 exception when others then
7700 wf_core.context('PO_ChangeOrderWF_PVT','NOTIFY_REQ_PLAN',l_progress);
7701 raise;
7702 END NOTIFY_REQ_PLAN ;
7703
7704 procedure PROCESS_RESPONSE ( itemtype in varchar2,
7705 itemkey in varchar2,
7706 actid in number,
7707 funcmode in varchar2,
7708 resultout out NOCOPY varchar2)
7709 IS
7710 l_header_id number;
7711 l_release_id number;
7712 l_revision_num number;
7713 l_chg_req_grp_id number;
7714 l_return_code number;
7715 l_err_msg varchar2(2000);
7716 x_progress varchar2(3) := '000';
7717 l_return_status varchar2(1);
7718 l_doc_check_rec_type POS_ERR_TYPE;
7719
7720 BEGIN
7721 l_header_id := wf_engine.GetItemAttrNumber(itemtype => itemtype,
7722 itemkey => itemkey,
7723 aname => 'PO_HEADER_ID');
7724 l_release_id := wf_engine.GetItemAttrNumber(itemtype => itemtype,
7725 itemkey => itemkey,
7726 aname => 'PO_RELEASE_ID');
7727 l_revision_num := wf_engine.GetItemAttrNumber(itemtype => itemtype,
7728 itemkey => itemkey,
7729 aname => 'PO_REVISION_NUM');
7730 l_chg_req_grp_id := wf_engine.GetItemAttrNumber(itemtype => itemtype,
7731 itemkey => itemkey,
7732 aname => 'CHANGE_REQUEST_GROUP_ID');
7733
7734 x_progress := '001';
7735 ProcessResponse(1.0, l_return_status, l_header_id, l_release_id,
7736 l_revision_num, l_chg_req_grp_id, fnd_global.user_id, l_err_msg,
7737 l_return_code,l_doc_check_rec_type, 'Y', 'Y');
7738
7739 exception when others then
7740 wf_core.context('PO_ChangeOrderWF_PVT','PROCESS_RESPONSE',x_progress);
7741 raise;
7742 END PROCESS_RESPONSE;
7743
7744 procedure BUYER_ACCEPT_CHANGE ( itemtype in varchar2,
7745 itemkey in varchar2,
7746 actid in number,
7747 funcmode in varchar2,
7748 resultout out NOCOPY varchar2)
7749 IS
7750
7751 l_chg_req_grp_id number;
7752 l_responded_by number;
7753 l_notif_usage VARCHAR2(30);
7754
7755 BEGIN
7756
7757 l_chg_req_grp_id := wf_engine.GetItemAttrNumber(itemtype => itemtype,
7758 itemkey => itemkey,
7759 aname => 'CHANGE_REQUEST_GROUP_ID');
7760
7761 l_notif_usage := wf_engine.GetItemAttrText(itemtype =>itemtype,
7762 itemkey => itemKey,
7763 aname => 'NOTIF_USAGE');
7764
7765 IF( l_notif_usage = 'BUYER_AUTO_FYI') THEN
7766 l_responded_by :=null;
7767 ELSE
7768 l_responded_by :=fnd_global.user_id;
7769 END IF;
7770
7771 update po_change_requests
7772 set request_status ='BUYER_APP',
7773 responded_by = l_responded_by,
7774 response_date = sysdate
7775 where change_request_group_id = l_chg_req_grp_id
7776 and request_status in ('PENDING','REQ_APP'); -- RDP ( Update records lying in REQ_APP status too)
7777
7778 exception when others then
7779 wf_core.context('PO_ChangeOrderWF_PVT','BUYER_ACCEPT_CHANGE','000');
7780 raise;
7781 end BUYER_ACCEPT_CHANGE;
7782
7783 procedure BUYER_REJECT_CHANGE ( itemtype in varchar2,
7784 itemkey in varchar2,
7785 actid in number,
7786 funcmode in varchar2,
7787 resultout out NOCOPY varchar2)
7788 IS
7789
7790 -- curosr to get the ReqHeaderId
7791 cursor c_getReqHdrId(p_po_header_id_csr IN NUMBER) is
7792 select distinct porh.requisition_header_id
7793 from po_requisition_headers_all porh,
7794 po_requisition_lines_all porl,
7795 po_headers_all poh,
7796 po_line_locations_all poll
7797 where porh.requisition_header_id = porl.requisition_header_id AND
7798 porl.line_location_id = poll.line_location_id AND
7799 poh.po_header_id = poll.po_header_id AND
7800 poh.po_header_id = p_po_header_id_csr;
7801
7802 l_chg_req_grp_id number;
7803 l_notif_usage VARCHAR2(30);
7804 l_req_hdr_id number;
7805 l_po_header_id number;
7806 BEGIN
7807
7808 l_chg_req_grp_id := wf_engine.GetItemAttrNumber(itemtype => itemtype,
7809 itemkey => itemkey,
7810 aname => 'CHANGE_REQUEST_GROUP_ID');
7811
7812
7813 l_notif_usage := wf_engine.GetItemAttrText(itemtype => itemtype,
7814 itemkey => itemkey,
7815 aname => 'NOTIF_USAGE');
7816
7817 l_po_header_id := wf_engine.GetItemAttrNumber (itemtype => itemtype,
7818 itemkey => itemkey,
7819 aname => 'PO_HEADER_ID');
7820
7821 -- Withdraw the lock from requisition , if the changes have been rejected by the requester
7822 IF( l_notif_usage = 'REQ') THEN
7823 OPEN c_getReqHdrId(l_po_header_id);
7824 LOOP
7825 FETCH c_getReqHdrId INTO l_req_hdr_id;
7826 EXIT WHEN c_getReqHdrId%NOTFOUND;
7827 BEGIN
7828 update po_requisition_headers_all
7829 set change_pending_flag = 'N'
7830 where requisition_header_id = l_req_hdr_id
7831 AND change_pending_flag = 'Y';
7832 EXCEPTION
7833 WHEN OTHERS THEN NULL;
7834 END;
7835 END LOOP;
7836 CLOSE c_getReqHdrId;
7837 END IF;
7838
7839
7840
7841 update po_change_requests
7842 set request_status ='REJECTED',
7843 change_active_flag = 'N',
7844 responded_by = fnd_global.user_id,
7845 response_date = sysdate
7846 where change_request_group_id = l_chg_req_grp_id
7847 and request_status in ('PENDING','REQ_APP'); -- RDP ( Update records lying in REQ_APP status too)
7848 exception when others then
7849 wf_core.context('PO_ChangeOrderWF_PVT','BUYER_REJECT_CHANGE','000');
7850 raise;
7851 end BUYER_REJECT_CHANGE;
7852
7853 /*
7854 This API is called from ISP Change Details Page. If the supplier submits a change, OR, if the supplier completely finishes
7855 acknowledging the PO at the shipment level (which may contain accept/reject/change), this API will be executed.
7856 */
7857 procedure StartSupplierChangeWF( p_api_version in number,
7858 x_return_status out NOCOPY varchar2,
7859 p_header_id in number,
7860 p_release_id in number,
7861 p_revision_num in number,
7862 p_chg_req_grp_id in number,
7863 p_acc_req_flag in varchar2 default 'N')
7864 IS
7865 l_api_name varchar2(50) := 'StartSupplierChangeWF';
7866 l_progress varchar2(100) := '000';
7867 l_count number;
7868 l_seq number;
7869 l_po_style varchar2(10);
7870 l_item_key po_change_requests.wf_item_key%TYPE;
7871 l_doc_type_code varchar2(1);
7872 l_buyer_notif_code varchar2(240);
7873 l_buyer_agent_id number;
7874 l_buyer_username fnd_user.user_name%TYPE;
7875 l_supplier_username fnd_user.user_name%TYPE;
7876 l_buyer_disp_name varchar2(2000);
7877 n_varname Wf_Engine.NameTabTyp;
7878 n_varval Wf_Engine.NumTabTyp;
7879 t_varname Wf_Engine.NameTabTyp;
7880 t_varval Wf_Engine.TextTabTyp;
7881 x_ret_status varchar2(1);
7882 x_complex_flag varchar2(1);
7883
7884
7885 BEGIN
7886 IF g_fnd_debug = 'Y' AND FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
7887 FND_LOG.string(FND_LOG.level_procedure, g_module_prefix ||
7888 l_api_name || 'start',p_header_id||'*'||p_release_id||'*'||p_revision_num||'*'||p_chg_req_grp_id);
7889 END IF;
7890
7891 -- Start Workflow
7892 select PO_SUPPLIER_CHANGE_WF_S.nextval into l_seq from dual;
7893 if(p_release_id is not null) then
7894 l_doc_type_code := 'R';
7895 l_item_key := p_release_id||'-'||p_revision_num||'-'||l_doc_type_code||'-'||to_char(l_seq);
7896 else
7897 l_doc_type_code := 'P';
7898 l_item_key := p_header_id||'-'||p_revision_num||'-'||l_doc_type_code||'-'||to_char(l_seq);
7899 end if;
7900
7901
7902
7903
7904 wf_engine.createProcess ( ItemType => 'POSCHORD',
7905 ItemKey => l_item_key,
7906 Process => 'MAIN_PROCESS');
7907
7908 l_progress := '001';
7909
7910 l_buyer_notif_code := '@'||p_header_id||'#'||p_release_id||'$'||p_chg_req_grp_id||'%'||p_acc_req_flag||'^';
7911
7912 -- Get Supplier User Name
7913 select user_name
7914 into l_supplier_username
7915 from fnd_user
7916 where user_id = fnd_global.user_id;
7917
7918 wf_engine.SetItemAttrText(itemtype => 'POSCHORD',
7919 itemkey => l_item_key,
7920 aname => 'RESP_ID',
7921 avalue => fnd_global.RESP_ID);
7922
7923 wf_engine.SetItemAttrText(itemtype => 'POSCHORD',
7924 itemkey => l_item_key,
7925 aname => 'APPL_RESP_ID',
7926 avalue => fnd_global.RESP_APPL_ID);
7927
7928 if(p_release_id is null) then
7929 select agent_id
7930 into l_buyer_agent_id
7931 from po_headers_all
7932 where po_headers_all.po_header_id = p_header_id;
7933 else
7934 select pra.agent_id
7935 into l_buyer_agent_id
7936 from po_releases_all pra,
7937 po_headers_all pha
7938 where pra.po_release_id = p_release_id
7939 and pra.po_header_id = pha.po_header_id;
7940 end if;
7941
7942 l_progress := '003';
7943
7944 -- Get Buyer UserName:
7945 wf_directory.GetUserName ( p_orig_system => 'PER',
7946 p_orig_system_id => l_buyer_agent_id,
7947 p_name => l_buyer_username,
7948 p_display_name => l_buyer_disp_name);
7949
7950 IF(p_release_id is not null) THEN
7951
7952 l_po_style := 'NORMAL';
7953
7954 ELSIF(p_release_id is null) THEN
7955
7956 l_progress := '004: call is_complex_po';
7957
7958 /* PO- API set item attribute PO_STYLE_TYPE depending upon the type of the PO
7959 PO_STYLE_TYPE - COMPLEX ,complex work PO's
7960 PO_STYLE_TYPE - NORMAL */
7961
7962
7963 PO_COMPLEX_WORK_GRP.is_complex_work_po(
7964 1.0,
7965 p_header_id,
7966 x_ret_status,
7967 x_complex_flag);
7968
7969 IF x_return_status IS NOT NULL AND x_return_status = FND_API.g_ret_sts_success THEN
7970 IF( g_fnd_debug = 'Y' AND FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
7971 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE,
7972 g_module_prefix,
7973 l_progress
7974 || 'x_return_status=' || x_return_status);
7975 END IF;
7976
7977 ELSE
7978 IF( g_fnd_debug = 'Y' AND FND_LOG.LEVEL_ERROR >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
7979 FND_LOG.STRING(FND_LOG.LEVEL_ERROR,
7980 g_module_prefix,
7981 l_progress
7982 ||'x_return_status = ' || x_return_status);
7983 END IF;
7984 END IF;
7985
7986 IF(x_complex_flag = 'N') THEN
7987 l_po_style :='NORMAL';
7988 ELSE
7989 l_po_style := 'COMPLEX';
7990 END IF;
7991 END IF;
7992
7993 n_varname(1) := 'PO_HEADER_ID';
7994 n_varval(1) := p_header_id;
7995 n_varname(2) := 'PO_RELEASE_ID';
7996 n_varval(2) := p_release_id;
7997 n_varname(3) := 'PO_REVISION_NUM';
7998 n_varval(3) := p_revision_num;
7999 n_varname(4) := 'CHANGE_REQUEST_GROUP_ID';
8000 n_varval(4) := p_chg_req_grp_id;
8001
8002 t_varname(1) := 'NTF_FOR_BUYER_SUBJECT';
8003 t_varval(1) := 'PLSQL:PO_ChangeOrderWF_PVT.GEN_NTF_FOR_BUYER_SUBJECT/'||l_item_key;
8004 t_varname(2) := 'NOTIF_FOR_BUYER_SUP_CHG'; -- RDP set the item Attibute value to the Notifications Page
8005 t_varval(2) := 'JSP:/OA_HTML/OA.jsp?page=/oracle/apps/pos/notifications/webui/PosNotificationsRN'||
8006 '&L_CHG_REQ_GRP_ID=-&CHANGE_REQUEST_GROUP_ID-&L_PO_HEADER_ID=-&PO_HEADER_ID-&L_PO_RELEASE_ID=-&PO_RELEASE_ID-'||
8007 '&L_PO_ACC_REQ_FLAG=-&ACKNOWLEDGE_REQ_FLAG-&L_NOTIF_USAGE=-&NOTIF_USAGE-&L_EXPLAIN_FYI=-&EXPLAIN_FYI-&L_STYLE_PARAM=-&PO_STYLE_TYPE-';
8008 t_varname(3) := 'BUYER_USERNAME';
8009 t_varval(3) := l_buyer_username;
8010 t_varname(4) := 'FROM_SUPPLIER';
8011 t_varval(4) := l_supplier_username;
8012 t_varname(5) := 'ACKNOWLEDGE_REQ_FLAG';
8013 t_varval(5) := p_acc_req_flag;
8014 t_varname(6) := 'PO_STYLE_TYPE';
8015 t_varval(6) := l_po_style;
8016
8017 Wf_Engine.SetItemAttrNumberArray('POSCHORD', l_item_key,n_varname,n_varval);
8018 Wf_Engine.SetItemAttrTextArray('POSCHORD', l_item_key,t_varname,t_varval);
8019
8020
8021
8022 /*update data to include wf item key and item type. p_chg_req_grp_id could be null in the case where user accepts/rejects
8023 all shipments and no changes was made. Thus, in this case, we will NOT store the wf_item_key or wf_item_type anywhere.
8024 */
8025 if(p_chg_req_grp_id is not null) then
8026 update po_change_requests
8027 set wf_item_type = 'POSCHORD',wf_item_key = l_item_key
8028 where change_request_group_id = p_chg_req_grp_id;
8029 end if;
8030 l_progress := '004';
8031
8032 wf_engine.StartProcess( ItemType => 'POSCHORD',
8033 ItemKey => l_item_key);
8034
8035 x_return_status := FND_API.G_RET_STS_SUCCESS;
8036 exception when others then
8037 IF g_fnd_debug = 'Y' AND FND_LOG.LEVEL_UNEXPECTED >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
8038 FND_LOG.string(FND_LOG.level_unexpected, g_module_prefix ||
8039 l_api_name || '.others_exception', l_progress||':'||sqlerrm);
8040 END IF;
8041 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
8042 end StartSupplierChangeWF;
8043
8044
8045 PROCEDURE initialize(p_employee_id in NUMBER,p_org_id IN NUMBER) IS
8046
8047 l_resp_id NUMBER := -1;
8048 l_user_id NUMBER := -1;
8049
8050 /* bug 9672656 : application id is hard coded to 201. In case of custom application with custom reponsibilities,
8051 when requistion is changed (which is on an approved PO), and the eventual PO Change Request fires, the
8052 resulting POAPPRV process errors.
8053 Fetching application id from fnd_global resolves the issue. */
8054 -- Bug 13915321 reverting the fix
8055 l_resp_appl_id NUMBER := 201;
8056
8057 --l_resp_appl_id NUMBER := fnd_global.resp_appl_id;
8058
8059
8060 l_api_name varchar2(50) := 'initialize';
8061 l_progress varchar2(5) := '000';
8062
8063 cursor l_get_user_info_csr
8064 is
8065 select fr.responsibility_id,fu.user_id
8066 from wf_local_user_roles wur,
8067 fnd_responsibility fr,
8068 financials_system_params_all fsp,
8069 fnd_user fu
8070 where wur.user_name = fu.user_name
8071 and wur.role_orig_system = 'FND_RESP'
8072 and wur.role_orig_system_id = fr.responsibility_id
8073 and wur.partition_id = 2
8074 and (((wur.start_date is NULL) or (trunc(sysdate) >= trunc(wur.start_date)))
8075 and ((wur.expiration_date is NULL) or
8076 (trunc(sysdate) < trunc(wur.expiration_date)))
8077 and ((wur.user_start_date is NULL) or
8078 (trunc(sysdate) >= trunc(wur.user_start_date)))
8079 and ((wur.user_end_date is NULL) or
8080 (trunc(sysdate) < trunc(wur.user_end_date)))
8081 and ((wur.role_start_date is NULL) or
8082 (trunc(sysdate) >= trunc(wur.role_start_date)))
8083 and ((wur.role_end_date is NULL) or
8084 (trunc(sysdate) < trunc(wur.role_end_date))))
8085 and fr.application_id = 201
8086 and fr.start_date < sysdate
8087 and nvl(fr.end_date, sysdate +1) >= sysdate
8088 and nvl(fsp.org_id,-1) = nvl(p_org_id,-1)
8089 and nvl(fsp.business_group_id,-1) = nvl(fnd_profile.value_specific('PER_BUSINESS_GROUP_ID', NULL, fr.responsibility_id, fr.application_id),-1);
8090
8091
8092 BEGIN
8093 /* bug 13915321 begin Moving the block here*/
8094 BEGIN
8095 l_progress := '001';
8096 SELECT FND.user_id
8097 INTO l_user_id
8098 FROM FND_USER FND, HR_EMPLOYEES_CURRENT_V HR
8099 WHERE HR.EMPLOYEE_ID = p_employee_id
8100 AND FND.EMPLOYEE_ID = HR.EMPLOYEE_ID
8101 AND ROWNUM = 1;
8102
8103 EXCEPTION
8104 WHEN OTHERS THEN
8105 l_user_id := -1;
8106 END;
8107
8108 IF g_fnd_debug = 'Y' AND FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
8109 FND_LOG.string(FND_LOG.level_procedure, g_module_prefix ||
8110 l_api_name || '.intialize parameters',l_progress||' '||l_user_id||'*'||l_resp_id||'*'||l_resp_appl_id );
8111 END IF;
8112 /* bug 13915321 end*/
8113 /* bug 13915321 The fix to use following logic for searching
8114 first of all search for the user id
8115 if user id is valid, search for a valid purchasing responsibility
8116
8117 if user id is not valid, search for user and responsibility associated
8118 with purchasing.
8119 if responsibility is not found search for a custom responsibility as fail safe case
8120 (retaining fix 9672656)
8121 If still the responsibility is not found then
8122 search for custom responsibility and user associated*/
8123
8124 /* bug 13915321 begin*/
8125 /* If user_id is valid, search for a valid responsibility*/
8126 if(l_user_id <>-1) then
8127 BEGIN
8128 l_progress := '002';
8129 select fr.responsibility_id
8130 into l_resp_id
8131 from wf_local_user_roles wur,
8132 fnd_responsibility fr,
8133 financials_system_params_all fsp
8134 where
8135 wur.role_orig_system = 'FND_RESP'
8136 and wur.role_orig_system_id = fr.responsibility_id
8137 and wur.partition_id = 2
8138 and (((wur.start_date is NULL) or (trunc(sysdate) >= trunc(wur.start_date)))
8139 and ((wur.expiration_date is NULL) or
8140 (trunc(sysdate) < trunc(wur.expiration_date)))
8141 and ((wur.user_start_date is NULL) or
8142 (trunc(sysdate) >= trunc(wur.user_start_date)))
8143 and ((wur.user_end_date is NULL) or
8144 (trunc(sysdate) < trunc(wur.user_end_date)))
8145 and ((wur.role_start_date is NULL) or
8146 (trunc(sysdate) >= trunc(wur.role_start_date)))
8147 and ((wur.role_end_date is NULL) or
8148 (trunc(sysdate) < trunc(wur.role_end_date))))
8149 and fr.application_id = 201
8150 and fr.start_date < sysdate
8151 and nvl(fr.end_date, sysdate +1) >= sysdate
8152 and nvl(fsp.org_id,-1) = nvl(p_org_id,-1);
8153 EXCEPTION
8154 when others then
8155 l_resp_id := -1;
8156 END;
8157 IF g_fnd_debug = 'Y' AND FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
8158 FND_LOG.string(FND_LOG.level_procedure, g_module_prefix ||
8159 l_api_name || '.intialize parameters',l_progress||' '||l_user_id||'*'||l_resp_id||'*'||l_resp_appl_id );
8160 END IF;
8161 end if;
8162 if ((l_user_id = -1) or (l_resp_id = -1 OR l_resp_id is null)) then
8163 l_progress := '003';
8164 open l_get_user_info_csr;
8165 fetch l_get_user_info_csr into
8166 l_resp_id, l_user_id;
8167 close l_get_user_info_csr;
8168 IF g_fnd_debug = 'Y' AND FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
8169 FND_LOG.string(FND_LOG.level_procedure, g_module_prefix ||
8170 l_api_name || '.intialize parameters',l_progress||' '||l_user_id||'*'||l_resp_id||'*'||l_resp_appl_id );
8171 END IF;
8172 end if;
8173 /* As a fail safe case retaining the fix in 9672656
8174 Actually we should not have entertained the fix in that bug
8175 whenever customer creates a custom responsibility
8176 he should attach it to purchasing only
8177 in 11.5.10 it is all the more important because
8178 document manager can proceed only on
8179 purchasing responsibility
8180 But retaining the fix for avoiding regressions after discussion with Raja*/
8181 if (l_resp_id = -1 OR l_resp_id is null) then
8182 l_resp_appl_id := fnd_global.resp_appl_id;
8183 if(l_user_id <>-1) then
8184 l_progress := '004';
8185 BEGIN
8186
8187
8188 select MIN(fr.responsibility_id)
8189 into l_resp_id
8190 from wf_local_user_roles wur,
8191 fnd_responsibility fr,
8192 financials_system_params_all fsp,
8193 fnd_user fu
8194 where wur.user_name = fu.user_name
8195 and fu.user_id = l_user_id
8196 and wur.role_orig_system = 'FND_RESP'
8197 and wur.role_orig_system_id = fr.responsibility_id
8198 and wur.partition_id = 2
8199 and (((wur.start_date is NULL) or (trunc(sysdate) >= trunc(wur.start_date)))
8200 and ((wur.expiration_date is NULL) or
8201 (trunc(sysdate) < trunc(wur.expiration_date)))
8202 and ((wur.user_start_date is NULL) or
8203 (trunc(sysdate) >= trunc(wur.user_start_date)))
8204 and ((wur.user_end_date is NULL) or
8205 (trunc(sysdate) < trunc(wur.user_end_date)))
8206 and ((wur.role_start_date is NULL) or
8207 (trunc(sysdate) >= trunc(wur.role_start_date)))
8208 and ((wur.role_end_date is NULL) or
8209 (trunc(sysdate) < trunc(wur.role_end_date))))
8210 and fr.application_id = l_resp_appl_id
8211 and fr.start_date < sysdate
8212 and nvl(fr.end_date, sysdate +1) >= sysdate
8213 and nvl(fsp.org_id,-1) = nvl(p_org_id,-1);
8214 /* and nvl(fsp.business_group_id,-1) = nvl(fnd_profile.value_specific('PER_BUSINESS_GROUP_ID', NULL, fr.responsibility_id, fr.application_id),-1); */
8215 IF g_fnd_debug = 'Y' AND FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
8216 FND_LOG.string(FND_LOG.level_procedure, g_module_prefix ||
8217 l_api_name || '.intialize parameters',l_progress||' '||l_user_id||'*'||l_resp_id||'*'||l_resp_appl_id );
8218 END IF;
8219 EXCEPTION
8220 when others then
8221 l_resp_id := -1;
8222 END;
8223 end if;
8224 if ((l_user_id = -1) or (l_resp_id = -1 OR l_resp_id is null)) then
8225 l_progress := '005';
8226 BEGIN
8227 select MIN(fr.responsibility_id),fu.user_id
8228 into l_resp_id,l_user_id
8229 from wf_local_user_roles wur,
8230 fnd_responsibility fr,
8231 financials_system_params_all fsp,
8232 fnd_user fu
8233 where wur.user_name = fu.user_name
8234 and wur.role_orig_system = 'FND_RESP'
8235 and wur.role_orig_system_id = fr.responsibility_id
8236 and wur.partition_id = 2
8237 and (((wur.start_date is NULL) or (trunc(sysdate) >= trunc(wur.start_date)))
8238 and ((wur.expiration_date is NULL) or
8239 (trunc(sysdate) < trunc(wur.expiration_date)))
8240 and ((wur.user_start_date is NULL) or
8241 (trunc(sysdate) >= trunc(wur.user_start_date)))
8242 and ((wur.user_end_date is NULL) or
8243 (trunc(sysdate) < trunc(wur.user_end_date)))
8244 and ((wur.role_start_date is NULL) or
8245 (trunc(sysdate) >= trunc(wur.role_start_date)))
8246 and ((wur.role_end_date is NULL) or
8247 (trunc(sysdate) < trunc(wur.role_end_date))))
8248 and fr.application_id = l_resp_appl_id
8249 and fr.start_date < sysdate
8250 and nvl(fr.end_date, sysdate +1) >= sysdate
8251 and nvl(fsp.org_id,-1) = nvl(p_org_id,-1);
8252 /* and nvl(fsp.business_group_id,-1) = nvl(fnd_profile.value_specific('PER_BUSINESS_GROUP_ID', NULL, fr.responsibility_id, fr.application_id),-1); */
8253 IF g_fnd_debug = 'Y' AND FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
8254 FND_LOG.string(FND_LOG.level_procedure, g_module_prefix ||
8255 l_api_name || '.intialize parameters',l_progress||' '||l_user_id||'*'||l_resp_id||'*'||l_resp_appl_id );
8256 END IF;
8257 EXCEPTION
8258 when others then
8259 l_resp_id := -1;
8260 END;
8261 end if;
8262 end if;
8263 /* bug 13915321 end*/
8264 l_progress := '006';
8265 IF g_fnd_debug = 'Y' AND FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
8266 FND_LOG.string(FND_LOG.level_procedure, g_module_prefix ||
8267 l_api_name || '.intialize parameters',l_user_id||'*'||l_resp_id||'*'||l_resp_appl_id );
8268 END IF;
8269 FND_GLOBAL.APPS_INITIALIZE(l_user_id,l_resp_id,l_resp_appl_id);
8270 exception when others then
8271 IF g_fnd_debug = 'Y' AND FND_LOG.LEVEL_UNEXPECTED >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
8272 FND_LOG.string(FND_LOG.level_unexpected, g_module_prefix ||
8273 l_api_name || '.others_exception', sqlerrm);
8274 END IF;
8275 END initialize;
8276
8277 function getEmailResponderUserName(p_supp_user_name varchar2,
8278 p_ntf_role_name varchar2) return varchar2
8279 IS
8280 l_user_name varchar2(320);
8281 l_email varchar2(2000);
8282 l_start pls_integer;
8283 l_end pls_integer;
8284 begin
8285 /* This part of the code is copied from the procedure
8286 wf_directory.GetInfoFromMail. So, watch for fixes by wf in this part
8287 of the code.
8288 */
8289
8290 -- strip off the unwanted info from email. Emails from the mailer
8291 -- could be of the form "Vijay Shanmugam"[email protected]>
8292 l_start := instr(p_supp_user_name, '<', 1, 1);
8293 if (l_start > 0) then
8294 l_end := instr(p_supp_user_name, '>', l_start);
8295 l_email := substr(p_supp_user_name, l_start+1, l_end-l_start-1);
8296 else
8297 l_email := p_supp_user_name;
8298 end if;
8299
8300 select wur.user_name
8301 into l_user_name
8302 from wf_user_roles wur,wf_users wr
8303 where wur.role_name=p_ntf_role_name and
8304 wr.name =wur.user_name and
8305 upper(wr.email_address)=upper(l_email);
8306
8307 return l_user_name;
8308
8309 exception when others then
8310 --note: if the ntf has been responded by somebody not in the role,
8311 -- it can fail.
8312 return null;
8313 end;
8314 -- RDP called from NotificationsAMImpl.java ( gets the additional changes if any)
8315 PROCEDURE getAdditionalChanges( p_chg_req_grp_id in number,
8316 x_addl_chg out nocopy varchar2,
8317 x_count out nocopy number)
8318 is
8319 CURSOR additional_changes(chg_req_grp_id_csr IN NUMBER) IS
8320 select additional_changes
8321 from po_change_requests
8322 where change_request_group_id = chg_req_grp_id_csr
8323 and request_level = 'HEADER'
8324 and additional_changes is not null;
8325
8326 -- returns 1 when only additional changes at header level are requested otherwise 0
8327 CURSOR getRequestLevel(chg_req_grp_id_csr IN NUMBER) IS
8328 SELECT COUNT(1) FROM po_change_requests WHERE NOT EXISTS ( SELECT 1
8329 FROM po_change_requests
8330 WHERE change_request_group_id = chg_req_grp_id_csr
8331 AND request_level IN ('LINE','SHIPMENT'))
8332 AND change_request_group_id = chg_req_grp_id_csr
8333 AND action_type = 'MODIFICATION';
8334
8335 -- Bug 7487461
8336 -- Modified the data type for additional changes to capture the entire text.
8337 l_additional_changes po_change_requests.additional_changes%type;
8338 l_count NUMBER(10);
8339 begin
8340 OPEN getRequestLevel(p_chg_req_grp_id);
8341 LOOP
8342 FETCH getRequestLevel
8343 INTO l_count;
8344 EXIT WHEN getRequestLevel%NOTFOUND;
8345 END LOOP;
8346 CLOSE getRequestLevel;
8347
8348 IF(l_count = 1) THEN
8349 x_count := l_count;
8350 ELSE
8351 x_count := 0;
8352 END IF;
8353
8354 OPEN additional_changes(p_chg_req_grp_id);
8355 LOOP
8356 FETCH additional_changes
8357 INTO l_additional_changes;
8358 EXIT WHEN additional_changes%NOTFOUND;
8359 END LOOP;
8360 CLOSE additional_changes;
8361
8362 x_addl_chg := l_additional_changes;
8363
8364 end getAdditionalChanges;
8365
8366
8367 PROCEDURE getReqNumber(p_po_header_id in number , p_po_release_id in number, x_req_num out nocopy varchar2, x_req_hdr_id out nocopy varchar2) -- RDP(backing)
8368 IS
8369 CURSOR getReqHdrId(c_po_header_id in NUMBER) IS
8370 select distinct(porla.requisition_header_id)
8371 from po_requisition_lines_all porla,
8372 po_line_locations_all polla
8373 where polla.po_header_id = c_po_header_id
8374 and porla.line_location_id = polla.line_location_id;
8375
8376 CURSOR getReqNum(c_req_header_id in NUMBER) IS
8377 select porha.segment1
8378 from po_requisition_headers_all porha
8379 where requisition_header_id = c_req_header_id;
8380
8381 -- for releases
8382 CURSOR getReqHdrId_rel(c_po_header_id in NUMBER, c_po_release_id in NUMBER) IS
8383 select distinct(porla.requisition_header_id)
8384 from po_requisition_lines_all porla,
8385 po_line_locations_all polla
8386 where polla.po_header_id = c_po_header_id
8387 and polla.po_release_id = c_po_release_id
8388 and porla.line_location_id = polla.line_location_id;
8389
8390
8391
8392 l_req_header_id NUMBER(10);
8393 l_req_num NUMBER(10);
8394
8395
8396 BEGIN
8397 IF (p_po_release_id is null) THEN
8398 OPEN getReqHdrId(p_po_header_id);
8399 LOOP
8400 FETCH getReqHdrId INTO l_req_header_id;
8401 EXIT WHEN getReqHdrId%NOTFOUND;
8402 END LOOP;
8403 CLOSE getReqHdrId;
8404 ELSE
8405 OPEN getReqHdrId_rel(p_po_header_id,p_po_release_id);
8406 LOOP
8407 FETCH getReqHdrId_rel INTO l_req_header_id;
8408 EXIT WHEN getReqHdrId_rel%NOTFOUND;
8409 END LOOP;
8410 CLOSE getReqHdrId_rel;
8411 END IF;
8412
8413 OPEN getReqNum(l_req_header_id);
8414 LOOP
8415 FETCH getReqNum INTO l_req_num;
8416 EXIT WHEN getReqNum%NOTFOUND;
8417 END LOOP;
8418
8419 CLOSE getReqNum;
8420
8421 IF g_fnd_debug = 'Y' AND FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
8422 FND_LOG.string(FND_LOG.level_procedure, g_module_prefix || '.getReqNumber', l_req_num ||' * '|| l_req_header_id);
8423 END IF;
8424
8425 x_req_num := TO_CHAR(l_req_num);
8426 x_req_hdr_id := TO_CHAR(l_req_header_id);
8427
8428 EXCEPTION
8429 WHEN OTHERS THEN
8430 IF( g_fnd_debug = 'Y' AND FND_LOG.LEVEL_ERROR >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
8431 FND_LOG.STRING(FND_LOG.LEVEL_ERROR,
8432 g_module_prefix,
8433 ':unexpected error' || Sqlerrm);
8434 END IF;
8435
8436 end getReqNumber;
8437
8438
8439 PROCEDURE getChgReqMode(p_chg_req_grp_id in number, x_req_mode out nocopy varchar2) -- RDP(identifies whether this is a CANCELLATION or MODIFICATION request)
8440 IS -- To be used to set the Header Msg of Chg Request Table
8441 l_temp VARCHAR2(15);
8442 l_req_mode VARCHAR2(15);
8443 BEGIN
8444 select decode(count(distinct(action_type)),2,'BOTH',1,'CHG') into
8445 l_req_mode
8446 from
8447 po_change_requests
8448 where
8449 change_request_group_id = p_chg_req_grp_id
8450 and request_level in('LINE','SHIPMENT')
8451 and action_type in('MODIFICATION','CANCELLATION');
8452
8453 if l_req_mode = 'BOTH' then
8454 x_req_mode := 'BOTH';
8455 elsif l_req_mode = 'CHG' then
8456 select distinct(action_type) into
8457 l_temp
8458 from
8459 po_change_requests
8460 where
8461 change_request_group_id = p_chg_req_grp_id
8462 and request_level in('LINE','SHIPMENT')
8463 and action_type in('MODIFICATION','CANCELLATION');
8464
8465 if l_temp = 'CANCELLATION' then
8466 x_req_mode := 'CANCELLATION';
8467 elsif l_temp = 'MODIFICATION' then
8468 x_req_mode := 'MODIFICATION';
8469 end if;
8470 end if;
8471
8472 EXCEPTION
8473 WHEN OTHERS THEN
8474 IF( g_fnd_debug = 'Y' AND FND_LOG.LEVEL_ERROR >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
8475 FND_LOG.STRING(FND_LOG.LEVEL_ERROR,
8476 g_module_prefix,
8477 ':unexpected error' || Sqlerrm);
8478 END IF;
8479
8480 end getChgReqMode;
8481
8482 PROCEDURE getOpenShipCount(po_line_location_id in number, x_ship_invalid_for_ctrl_actn out nocopy varchar2)
8483 IS
8484 l_ship_invalid_for_ctrl_actn varchar2(1);
8485 BEGIN
8486 SELECT 'N'
8487 INTO l_ship_invalid_for_ctrl_actn
8488 FROM DUAL
8489 WHERE EXISTS(
8490 SELECT 1
8491 FROM po_line_locations_all poll1,
8492 po_line_locations_all poll2
8493 WHERE poll1.line_location_id = po_line_location_id
8494 AND poll1.po_line_id = poll2.po_line_id
8495 AND NVL(poll2.cancel_flag,'N') <> 'Y'
8496 AND NVL(poll2.payment_type, 'NULL') NOT IN ('ADVANCE', 'DELIVERY') --<Complex Work R12>
8497 AND NVL(poll2.closed_code, 'OPEN')
8498 <> 'FINALLY CLOSED'
8499 AND poll2.line_location_id <> po_line_location_id);
8500
8501 x_ship_invalid_for_ctrl_actn := l_ship_invalid_for_ctrl_actn;
8502 EXCEPTION
8503 WHEN NO_DATA_FOUND THEN
8504 --Current shipment is the only shipment on the line that is not cancelled or finally closed
8505 --OR there are no open, uncancelled shipments.
8506 x_ship_invalid_for_ctrl_actn := 'Y';
8507 END getOpenShipCount;
8508
8509
8510
8511 PROCEDURE getHdrCancel(p_chg_req_grp_id in number,
8512 po_header_id in number,
8513 po_release_id in number,
8514 x_action_type out nocopy varchar2,
8515 x_request_status out nocopy varchar2,
8516 x_doc_type out nocopy varchar2,
8517 x_doc_num out nocopy varchar2,
8518 x_revision_num out nocopy varchar2)
8519 IS
8520 l_count number;
8521 l_action_type varchar2(15) := null;
8522 l_request_status varchar2(15) := null;
8523 l_doc_type varchar2(15) := null;
8524 l_doc_num varchar2(15) := null;
8525 l_revision_num varchar2(15) := null;
8526
8527 CURSOR HdrCancelCsrCount(p_chg_req_grp_id_csr IN NUMBER) IS
8528 SELECT count(*)
8529 FROM po_change_requests pcr
8530 WHERE pcr.CHANGE_REQUEST_GROUP_ID = p_chg_req_grp_id_csr
8531 AND pcr.REQUEST_LEVEL = 'HEADER'
8532 AND pcr.ACTION_TYPE = 'CANCELLATION';
8533
8534 CURSOR HdrCancelCsrVal(p_chg_req_grp_id_csr IN NUMBER) IS
8535 SELECT pcr.action_type,
8536 pcr.request_status,
8537 poh.type_lookup_code,
8538 pcr.document_num
8539 FROM PO_CHANGE_REQUESTS pcr,
8540 PO_HEADERS_ALL poh
8541 WHERE pcr.CHANGE_REQUEST_GROUP_ID = p_chg_req_grp_id_csr
8542 AND pcr.REQUEST_LEVEL = 'HEADER'
8543 AND pcr.ACTION_TYPE = 'CANCELLATION'
8544 AND pcr.document_header_id = poh.po_header_id;
8545
8546 CURSOR getRevisionNum(p_chg_req_grp_id_csr IN NUMBER) IS
8547 SELECT distinct(pcr.document_revision_num)
8548 FROM po_change_requests pcr
8549 WHERE pcr.CHANGE_REQUEST_GROUP_ID = p_chg_req_grp_id_csr;
8550
8551 CURSOR getRevisionNumAck(po_header_id_csr IN NUMBER) IS
8552 SELECT revision_num
8553 FROM po_headers_all
8554 WHERE po_header_id = po_header_id_csr;
8555
8556 CURSOR getRevisionNumAckRel(po_header_id_csr IN NUMBER,po_release_id_csr IN NUMBER) IS
8557 SELECT pora.revision_num
8558 FROM po_releases_all pora
8559 WHERE pora.po_header_id = po_header_id_csr
8560 AND pora.po_release_id = po_release_id_csr;
8561
8562 BEGIN
8563
8564 IF(p_chg_req_grp_id is null) THEN
8565
8566 IF(po_release_id is null) THEN
8567 OPEN getRevisionNumAck(po_header_id);
8568 FETCH getRevisionNumAck
8569 INTO
8570 l_revision_num;
8571 CLOSE getRevisionNumAck;
8572 ELSE
8573 OPEN getRevisionNumAckRel(po_header_id,po_release_id);
8574 FETCH getRevisionNumAckRel
8575 INTO
8576 l_revision_num;
8577 CLOSE getRevisionNumAckRel;
8578 END IF;
8579
8580 ELSE
8581
8582 OPEN HdrCancelCsrCount(p_chg_req_grp_id);
8583 LOOP
8584 FETCH HdrCancelCsrCount
8585 INTO
8586 l_count;
8587 EXIT WHEN HdrCancelCsrCount%NOTFOUND;
8588 END LOOP;
8589 CLOSE HdrCancelCsrCount;
8590
8591 IF(l_count = 0) THEN
8592 l_action_type := 'NOCANCEL';
8593 OPEN getRevisionNum(p_chg_req_grp_id);
8594 LOOP
8595 FETCH getRevisionNum
8596 INTO l_revision_num;
8597 EXIT WHEN getRevisionNum%NOTFOUND;
8598 END LOOP;
8599 CLOSE getRevisionNum;
8600
8601 ELSIF(l_count = 1) THEN
8602 OPEN HdrCancelCsrVal(p_chg_req_grp_id);
8603 LOOP
8604 FETCH HdrCancelCsrVal
8605 INTO l_action_type,
8606 l_request_status,
8607 l_doc_type,
8608 l_doc_num;
8609 EXIT WHEN HdrCancelCsrVal%NOTFOUND;
8610 END LOOP;
8611 CLOSE HdrCancelCsrVal;
8612
8613 END IF;
8614 END IF;
8615
8616 x_action_type := l_action_type;
8617 x_request_status := l_request_status;
8618 x_doc_type := l_doc_type;
8619 x_doc_num := l_doc_num;
8620 x_revision_num := l_revision_num;
8621
8622 EXCEPTION
8623 WHEN OTHERS THEN
8624 IF( g_fnd_debug = 'Y' AND FND_LOG.LEVEL_ERROR >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
8625 FND_LOG.STRING(FND_LOG.LEVEL_ERROR,
8626 g_module_prefix,
8627 ':unexpected error' || Sqlerrm);
8628 END IF;
8629
8630 END getHdrCancel;
8631
8632 /*
8633 This procedure sets the supplier user context after the auto acceptance of
8634 the PO.
8635 */
8636
8637 PROCEDURE SET_SUPPLIER_CONTEXT(p_supplier_user_id in NUMBER,p_resp_id in NUMBER,p_appl_resp_id in NUMBER)
8638 IS
8639 BEGIN
8640
8641 IF g_fnd_debug = 'Y' AND FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
8642 FND_LOG.string(FND_LOG.level_procedure, g_module_prefix || '.SET_SUPPLIER_CONTEXT', 'user_id:'||p_supplier_user_id||'resp:'||p_resp_id||'appl id:'||p_appl_resp_id );
8643 END IF;
8644
8645 fnd_global.APPS_INITIALIZE(p_supplier_user_id, p_resp_id, p_appl_resp_id);
8646
8647 EXCEPTION
8648 WHEN OTHERS THEN
8649 IF( g_fnd_debug = 'Y' AND FND_LOG.LEVEL_ERROR >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
8650 FND_LOG.STRING(FND_LOG.LEVEL_ERROR,
8651 g_module_prefix,
8652 ':unexpected error' || Sqlerrm);
8653 END IF;
8654
8655 END SET_SUPPLIER_CONTEXT;
8656
8657 procedure CHECK_POS_EXTERNAL_URL( itemtype in varchar2,
8658 itemkey in varchar2,
8659 actid in number,
8660 funcmode in varchar2,
8661 resultout out NOCOPY varchar2)
8662 is
8663 l_api_name varchar2(50) := 'CHECK_POS_EXTERNAL_URL';
8664 l_external_url varchar2(500);
8665 begin
8666
8667 l_external_url := fnd_profile.value('POS_EXTERNAL_URL');
8668 IF (g_fnd_debug = 'Y' AND FND_LOG.level_procedure >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
8669 FND_LOG.string(FND_LOG.level_procedure, g_module_prefix ||
8670 l_api_name || '.start', 'POS_EXTERNAL_URL=' || l_external_url);
8671 END IF;
8672 resultout := 'N:' || l_external_url;
8673
8674 if (l_external_url is not null) then
8675
8676 PO_WF_UTIL_PKG.SetItemAttrText ( itemtype => itemtype,
8677 itemkey => itemkey,
8678 aname => '#WFM_HTMLAGENT',
8679 avalue => l_external_url);
8680
8681 resultout := 'Y:' || l_external_url;
8682 end if;
8683
8684 exception when others then
8685 IF (g_fnd_debug = 'Y' AND FND_LOG.LEVEL_UNEXPECTED >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
8686 FND_LOG.string(FND_LOG.level_unexpected, g_module_prefix ||
8687 l_api_name || '.others_exception', sqlerrm);
8688 END IF;
8689 resultout := 'F:' || l_external_url;
8690 return;
8691 end CHECK_POS_EXTERNAL_URL;
8692
8693 procedure post_approval_notif (p_itemtype in varchar2,
8694 p_itemkey in varchar2,
8695 p_actid in number,
8696 p_funcmode in varchar2,
8697 x_resultout out NOCOPY varchar2) IS
8698
8699 l_api_name varchar2(50) := p_itemkey || ' post_approval_notif';
8700 l_notification_id number;
8701 l_forwardTo varchar2(240);
8702 l_result varchar2(100);
8703 l_forward_to_username_response varchar2(240) :='';
8704 l_action po_action_history.action_code%TYPE;
8705 l_new_recipient_id wf_roles.orig_system_id%TYPE;
8706 l_current_recipient_id wf_roles.orig_system_id%TYPE;
8707 l_origsys wf_roles.orig_system%TYPE;
8708
8709 -- Declare following context setting variables.
8710 l_responder_id fnd_user.user_id%TYPE;
8711 l_session_user_id NUMBER;
8712 l_session_resp_id NUMBER;
8713 l_session_appl_id NUMBER;
8714 l_preparer_resp_id NUMBER;
8715 l_preparer_appl_id NUMBER;
8716 l_progress VARCHAR2(1000);
8717 l_preserved_ctx VARCHAR2(5);
8718
8719 BEGIN
8720
8721 l_progress := 'PO_ChangeOrderWF_PVT.post_approval_notif: 01.';
8722 IF (g_fnd_debug = 'Y') THEN
8723 FND_LOG.string(FND_LOG.LEVEL_PROCEDURE, l_api_name, 'Enter in post_approval_notif ' || l_progress);
8724 FND_LOG.string(FND_LOG.LEVEL_PROCEDURE, l_api_name, 'p_itemtype ' || p_itemtype);
8725 FND_LOG.string(FND_LOG.LEVEL_PROCEDURE, l_api_name, 'p_itemkey ' || p_itemkey);
8726 FND_LOG.string(FND_LOG.LEVEL_PROCEDURE, l_api_name, 'p_actid ' || p_actid);
8727 FND_LOG.string(FND_LOG.LEVEL_PROCEDURE, l_api_name, 'p_funcmode ' || p_funcmode);
8728 END IF;
8729
8730 if (p_funcmode IN ('FORWARD', 'QUESTION', 'ANSWER')) THEN
8731 if (p_funcmode = 'FORWARD') then
8732 l_action := 'DELEGATE';
8733 elsif (p_funcmode = 'QUESTION') then
8734 l_action := 'QUESTION';
8735 elsif (p_funcmode = 'ANSWER') then
8736 l_action := 'ANSWER';
8737 end if;
8738
8739
8740 Wf_Directory.GetRoleOrigSysInfo(WF_ENGINE.CONTEXT_NEW_ROLE, l_origsys, l_new_recipient_id);
8741 l_progress := 'PO_ChangeOrderWF_PVT.post_approval_notif: 02.';
8742
8743 if (p_funcmode = 'RESPOND') then
8744 l_notification_id := WF_ENGINE.context_nid;
8745 IF (g_fnd_debug = 'Y') THEN
8746 FND_LOG.string(FND_LOG.LEVEL_PROCEDURE, l_api_name, 'l_notification_id '||l_notification_id );
8747 END IF;
8748 l_result := wf_notification.GetAttrText(l_notification_id, 'RESULT');
8749
8750 IF (g_fnd_debug = 'Y') THEN
8751 FND_LOG.string(FND_LOG.LEVEL_PROCEDURE, l_api_name, 'l_result '||l_result );
8752 END IF;
8753
8754 if (l_result = 'FORWARD') THEN
8755
8756 l_forwardTo := wf_notification.GetAttrText(l_notification_id, 'FORWARD_TO_USERNAME_RESPONSE');
8757 l_forward_to_username_response := wf_engine.GetItemAttrText (itemtype => p_itemtype,
8758 itemkey => p_itemkey,
8759 aname => 'FORWARD_TO_USERNAME_RESPONSE');
8760
8761 if(l_forwardTo is null) then
8762 fnd_message.set_name('ICX', 'ICX_POR_WF_NOTIF_NO_USER');
8763 app_exception.raise_exception;
8764 end if;
8765 end if;
8766
8767 if (wf_engine.preserved_context = TRUE) then
8768 l_preserved_ctx := 'TRUE';
8769 else
8770 l_preserved_ctx := 'FALSE';
8771 end if;
8772
8773 l_progress := 'PO_ChangeOrderWF_PVT.post_approval_notif: 03.' ;
8774
8775 -- <debug start>
8776 IF (g_fnd_debug = 'Y') THEN
8777 FND_LOG.string(FND_LOG.LEVEL_PROCEDURE,l_api_name,'l_progress ' ||l_progress);
8778 FND_LOG.string(FND_LOG.LEVEL_PROCEDURE,l_api_name,'l_preserved_ctx ' ||l_preserved_ctx);
8779 END IF;
8780 -- <debug end>
8781
8782
8783 SELECT fu.USER_ID
8784 INTO l_responder_id
8785 FROM fnd_user fu,
8786 wf_notifications wfn
8787 WHERE wfn.notification_id = l_notification_id
8788 AND wfn.original_recipient = fu.user_name;
8789
8790 l_progress := 'PO_ChangeOrderWF_PVT.post_approval_notif: 04.' ;
8791
8792 -- <debug start>
8793 IF (g_fnd_debug = 'Y') THEN
8794 FND_LOG.string(FND_LOG.LEVEL_PROCEDURE,l_api_name,'l_progress ' ||l_progress);
8795 FND_LOG.string(FND_LOG.LEVEL_PROCEDURE,l_api_name,'l_responder_id ' ||l_responder_id);
8796 END IF;
8797 -- <debug end>
8798 l_session_user_id := fnd_global.user_id;
8799 l_session_resp_id := fnd_global.resp_id;
8800 l_session_appl_id := fnd_global.resp_appl_id;
8801
8802 -- <debug start>
8803 IF (g_fnd_debug = 'Y') THEN
8804 FND_LOG.string(FND_LOG.LEVEL_PROCEDURE,l_api_name,'l_session_user_id ' ||l_session_user_id);
8805 FND_LOG.string(FND_LOG.LEVEL_PROCEDURE,l_api_name,'l_session_resp_id ' ||l_session_resp_id);
8806 FND_LOG.string(FND_LOG.LEVEL_PROCEDURE,l_api_name,'l_session_appl_id ' ||l_session_appl_id);
8807 END IF;
8808 -- <debug end>
8809 IF (l_session_user_id = -1) THEN
8810 l_session_user_id := NULL;
8811 END IF;
8812
8813 IF (l_session_resp_id = -1) THEN
8814 l_session_resp_id := NULL;
8815 END IF;
8816
8817 IF (l_session_appl_id = -1) THEN
8818 l_session_appl_id := NULL;
8819 END IF;
8820 -- <debug start>
8821 IF (g_fnd_debug = 'Y') THEN
8822 FND_LOG.string(FND_LOG.LEVEL_PROCEDURE,l_api_name,'l_session_user_id ' ||l_session_user_id);
8823 FND_LOG.string(FND_LOG.LEVEL_PROCEDURE,l_api_name,'l_session_resp_id ' ||l_session_resp_id);
8824 FND_LOG.string(FND_LOG.LEVEL_PROCEDURE,l_api_name,'l_session_appl_id ' ||l_session_appl_id);
8825 END IF;
8826 -- <debug end>
8827
8828 l_preparer_resp_id := wf_engine.GetItemAttrNumber(itemtype => p_itemtype,
8829 itemkey => p_itemkey,
8830 aname => 'RESP_ID');
8831 l_preparer_appl_id := wf_engine.GetItemAttrNumber(itemtype => p_itemtype,
8832 itemkey => p_itemkey,
8833 aname => 'APPLICATION_ID');
8834
8835 l_progress := 'PO_ChangeOrderWF_PVT.post_approval_notif: 05.' ;
8836
8837 -- <debug start>
8838 IF (g_fnd_debug = 'Y') THEN
8839 FND_LOG.string(FND_LOG.LEVEL_PROCEDURE,l_api_name,'l_progress ' ||l_progress);
8840 FND_LOG.string(FND_LOG.LEVEL_PROCEDURE,l_api_name,'l_preparer_resp_id ' ||l_preparer_resp_id);
8841 FND_LOG.string(FND_LOG.LEVEL_PROCEDURE,l_api_name,'l_preparer_appl_id ' ||l_preparer_appl_id);
8842 END IF;
8843 -- <debug end>
8844 if (l_responder_id is not null) then
8845 if (l_responder_id <> l_session_user_id) then
8846 /* possible in 2 scenarios :
8847 1. when the response is made from email using guest user feature
8848 2. When the response is made from sysadmin login
8849 */
8850
8851 l_progress := 'PO_ChangeOrderWF_PVT.post_approval_notif: 06.' ;
8852
8853 -- <debug start>
8854 IF (g_fnd_debug = 'Y') THEN
8855 FND_LOG.string(FND_LOG.LEVEL_PROCEDURE,l_api_name,'l_progress ' ||l_progress || 'When the response is made from email using guest user feature');
8856 END IF;
8857 -- <debug end>
8858
8859 wf_engine.SetItemAttrNumber(itemtype => p_itemtype,
8860 itemkey => p_itemkey,
8861 aname => 'RESPONDER_USER_ID',
8862 avalue => l_responder_id);
8863 wf_engine.SetItemAttrNumber(itemtype => p_itemtype,
8864 itemkey => p_itemkey,
8865 aname => 'RESPONDER_RESP_ID',
8866 avalue => l_preparer_resp_id);
8867 wf_engine.SetItemAttrNumber(itemtype => p_itemtype,
8868 itemkey => p_itemkey,
8869 aname => 'RESPONDER_APPL_ID',
8870 avalue => l_preparer_appl_id);
8871 ELSE
8872 l_progress := 'PO_ChangeOrderWF_PVT.post_approval_notif: 07.' ;
8873
8874 -- <debug start>
8875 IF (g_fnd_debug = 'Y') THEN
8876 FND_LOG.string(FND_LOG.LEVEL_PROCEDURE,l_api_name,'l_progress ' ||l_progress || 'When the response is made from sysadmin login');
8877 END IF;
8878 -- <debug end>
8879
8880 if (l_session_resp_id is null) THEN
8881 /* possible when the response is made from the default worklist without choosing a valid responsibility */
8882 l_progress := 'PO_ChangeOrderWF_PVT.post_approval_notif: 07.' ;
8883 -- <debug start>
8884 IF (g_fnd_debug = 'Y') THEN
8885 FND_LOG.string(FND_LOG.LEVEL_PROCEDURE,l_api_name,'l_progress '||l_progress || 'When the response is made from the default worklist');
8886 END IF;
8887 -- <debug end>
8888 wf_engine.SetItemAttrNumber(itemtype => p_itemtype,
8889 itemkey => p_itemkey,
8890 aname => 'RESPONDER_USER_ID',
8891 avalue => l_responder_id);
8892 wf_engine.SetItemAttrNumber(itemtype => p_itemtype,
8893 itemkey => p_itemkey,
8894 aname => 'RESPONDER_RESP_ID',
8895 avalue => l_preparer_resp_id);
8896 wf_engine.SetItemAttrNumber(itemtype => p_itemtype,
8897 itemkey => p_itemkey,
8898 aname => 'RESPONDER_APPL_ID',
8899 avalue => l_preparer_appl_id);
8900 else
8901
8902 /* All values available - possible when the response is made after choosing a correct responsibility */
8903 /* If the values of responsibility_id and application
8904 id are available but are incorrect. This may happen when a
8905 response is made through the email or the background process
8906 picks the wf up. This may happen due to the fact that the
8907 mailer / background process carries the context set by
8908 the notification /wf it processed last */
8909
8910 l_progress := 'PO_ChangeOrderWF_PVT.post_approval_notif: 09.' ;
8911
8912 -- <debug start>
8913 IF (g_fnd_debug = 'Y') THEN
8914 FND_LOG.string(FND_LOG.LEVEL_PROCEDURE,l_api_name,'l_progress ' ||l_progress || 'When the response is made after choosing a correct responsibility');
8915 END IF;
8916 -- <debug end>
8917
8918 if ( l_preserved_ctx = 'TRUE') then
8919 wf_engine.SetItemAttrNumber(itemtype => p_itemtype,
8920 itemkey => p_itemkey,
8921 aname => 'RESPONDER_USER_ID',
8922 avalue => l_responder_id);
8923 wf_engine.SetItemAttrNumber(itemtype => p_itemtype,
8924 itemkey => p_itemkey,
8925 aname => 'RESPONDER_RESP_ID',
8926 avalue => l_session_resp_id);
8927 wf_engine.SetItemAttrNumber(itemtype => p_itemtype,
8928 itemkey => p_itemkey,
8929 aname => 'RESPONDER_APPL_ID',
8930 avalue => l_session_appl_id);
8931 else
8932 wf_engine.SetItemAttrNumber(itemtype => p_itemtype,
8933 itemkey => p_itemkey,
8934 aname => 'RESPONDER_USER_ID',
8935 avalue => l_responder_id);
8936 wf_engine.SetItemAttrNumber(itemtype => p_itemtype,
8937 itemkey => p_itemkey,
8938 aname => 'RESPONDER_RESP_ID',
8939 avalue => l_preparer_resp_id);
8940 wf_engine.SetItemAttrNumber(itemtype => p_itemtype,
8941 itemkey => p_itemkey,
8942 aname => 'RESPONDER_APPL_ID',
8943 avalue => l_preparer_appl_id);
8944 end if;
8945 end if;
8946 end if;
8947 end if;
8948 end if;
8949
8950 x_resultout := wf_engine.eng_completed || ':' || wf_engine.eng_null;
8951 return;
8952 end if;
8953
8954
8955
8956 EXCEPTION
8957 when no_data_found then
8958 IF (g_fnd_debug = 'Y') THEN
8959 FND_LOG.string(FND_LOG.LEVEL_UNEXPECTED, l_api_name, 'No data found in post_approval_notif ' || l_progress);
8960 END IF;
8961 raise;
8962
8963 when others then
8964 IF (g_fnd_debug = 'Y') THEN
8965 FND_LOG.string(FND_LOG.LEVEL_UNEXPECTED, l_api_name,'Exception in post_approval_notif ' || l_progress);
8966 END IF;
8967 raise;
8968 END post_approval_notif;
8969
8970 -------------------------------------------------------------------------------
8971 -- Start of Comments
8972 -- Name: PO_SUPCHG_SELECTOR
8973 -- Pre-reqs: None.
8974 -- Modifies:
8975 -- Application user id
8976 -- Application responsibility id
8977 -- Application application id
8978 -- Locks: None.
8979 -- Function:
8980 -- This procedure sets the correct application context when a process is
8981 -- picked up by the workflow background engine. When called in
8982 -- TEST_CTX mode it compares workflow attribute org id with the current
8983 -- org id and workflow attributes user id, responsibility id and
8984 -- application id with their corresponding profile values. It returns TRUE
8985 -- if these values match and FALSE otherwise. When called in SET_CTX mode
8986 -- it sets the correct apps context based on workflow parameters.
8987 -- Parameters:
8988 -- IN:
8989 -- p_itemtype
8990 -- Specifies the itemtype of the workflow process
8991 -- p_itemkey
8992 -- Specifies the itemkey of the workflow process
8993 -- p_actid
8994 -- activity id passed by the workflow
8995 -- p_funcmode
8996 -- Input values can be TEST_CTX or SET_CTX (RUN not implemented)
8997 -- TEST_CTX to test if current context is correct
8998 -- SET_CTX to set the correct context if current context is wrong
8999 -- IN OUT:
9000 -- resultout
9001 -- For TEST_CTX a TRUE value means that the context is correct and
9002 -- SET_CTX need not be called. A FALSE value means that current context
9003 -- is incorrect and SET_CTX need to set correct context
9004 -- Testing:
9005 -- There is not script to test this procedure but the correct functioning
9006 -- may be tested by verifying from the debug_message in table po_wf_debug
9007 -- that if at any time the workflow process gets started with a wrong
9008 -- context then the selector is called in TEST_CTX and SET_CTX modes and
9009 -- correct context is set.
9010 -- End of Comments
9011 -------------------------------------------------------------------------------
9012 PROCEDURE PO_SUPCHG_SELECTOR ( p_itemtype IN VARCHAR2,
9013 p_itemkey IN VARCHAR2,
9014 p_actid IN NUMBER,
9015 p_funcmode IN VARCHAR2,
9016 resultout IN OUT NOCOPY VARCHAR2) IS
9017
9018 -- Declare context setting variables start
9019 l_session_user_id NUMBER;
9020 l_session_resp_id NUMBER;
9021 l_responder_id NUMBER;
9022 l_user_id_to_set NUMBER;
9023 l_resp_id_to_set NUMBER;
9024 l_appl_id_to_set NUMBER;
9025 l_progress VARCHAR2(1000);
9026 l_preserved_ctx VARCHAR2(5):= 'TRUE';
9027 l_org_id NUMBER;
9028 -- Declare context setting variables End
9029
9030 BEGIN
9031 -- <debug start>
9032 IF (g_fnd_debug = 'Y') THEN
9033 fnd_log.string(FND_LOG.LEVEL_PROCEDURE, 'pos.plsql.PO_ChangeOrderWF_PVT.PO_SUPCHG_SELECTOR.invoked','Inside PO_SUPCHG_SELECTOR procedure');
9034 fnd_log.string(FND_LOG.LEVEL_PROCEDURE, 'pos.plsql.PO_ChangeOrderWF_PVT.PO_SUPCHG_SELECTOR.invoked','p_itemtype : '||p_itemtype);
9035 fnd_log.string(FND_LOG.LEVEL_PROCEDURE, 'pos.plsql.PO_ChangeOrderWF_PVT.PO_SUPCHG_SELECTOR.invoked','p_itemkey : '||p_itemkey);
9036 fnd_log.string(FND_LOG.LEVEL_PROCEDURE, 'pos.plsql.PO_ChangeOrderWF_PVT.PO_SUPCHG_SELECTOR.invoked','p_actid : '||p_actid);
9037 fnd_log.string(FND_LOG.LEVEL_PROCEDURE, 'pos.plsql.PO_ChangeOrderWF_PVT.PO_SUPCHG_SELECTOR.invoked','p_funcmode : '||p_funcmode);
9038 END IF;
9039 -- <debug end>
9040
9041
9042 l_org_id := wf_engine.GetItemAttrNumber (itemtype => p_itemtype,
9043 itemkey => p_itemkey,
9044 aname => 'ORG_ID');
9045 l_session_user_id := fnd_global.user_id;
9046 l_session_resp_id := fnd_global.resp_id;
9047
9048 IF (l_session_user_id = -1) THEN
9049 l_session_user_id := NULL;
9050 END IF;
9051
9052 IF (l_session_resp_id = -1) THEN
9053 l_session_resp_id := NULL;
9054 END IF;
9055
9056 l_responder_id := wf_engine.GetItemAttrNumber(itemtype => p_itemtype,
9057 itemkey => p_itemkey,
9058 aname => 'RESPONDER_USER_ID');
9059
9060 --<debug start>
9061 l_progress :='010 - ses_user_id:'||l_session_user_id ||' ses_resp_id :'||l_session_resp_id||' responder id:' ||l_responder_id||' org id :'||l_org_id;
9062
9063 IF (g_fnd_debug = 'Y') THEN
9064 fnd_log.string(FND_LOG.LEVEL_PROCEDURE, 'pos.plsql.PO_ChangeOrderWF_PVT.PO_SUPCHG_SELECTOR.invoked','l_progress1 : '||l_progress);
9065 END IF;
9066 --<debug end>
9067
9068 IF (p_funcmode = 'TEST_CTX') THEN
9069 -- wf shouldn't run without the session user, hence always set the ctx if session user id is null.
9070 if (l_session_user_id is null) then
9071 resultout := 'NOTSET';
9072 return;
9073 else
9074 if (l_responder_id is not null) then
9075 if (l_responder_id <> l_session_user_id) then
9076 resultout := 'FALSE';
9077 return;
9078 else
9079 if (l_session_resp_id is Null) then
9080 resultout := 'NOTSET';
9081 return;
9082 else
9083 -- If the selector fn is called from a background ps
9084 -- notif mailer then force the session to use preparer's or responder
9085 -- context. This is required since the mailer/bckgrnd ps carries the
9086 -- context from the last wf processed and hence even if the context values
9087 -- are present, they might not be correct.
9088
9089 if (wf_engine.preserved_context = TRUE) then
9090 resultout := 'TRUE';
9091 else
9092 resultout:= 'NOTSET';
9093 end if;
9094
9095 -- introduce an org context setting call here
9096 -- required in the case when the right resonder makes a response
9097 -- from a NON-PO RESP.
9098 IF l_org_id is NOT NULL THEN
9099 PO_MOAC_UTILS_PVT.set_org_context(l_org_id) ;
9100 END IF;
9101 return;
9102 end if;
9103 end if;
9104 else
9105 -- always setting the ctx at the start of the wf
9106 resultout := 'NOTSET';
9107 return;
9108 end if;
9109 end if; -- l_session_user_id is null
9110 ELSIF (p_funcmode = 'SET_CTX') THEN
9111 if l_responder_id is not null then
9112
9113 l_user_id_to_set := l_responder_id;
9114
9115 l_resp_id_to_set := wf_engine.GetItemAttrNumber (itemtype => p_itemtype,
9116 itemkey => p_itemkey,
9117 aname => 'RESPONDER_RESP_ID');
9118 l_appl_id_to_set := wf_engine.GetItemAttrNumber (itemtype => p_itemtype,
9119 itemkey => p_itemkey,
9120 aname => 'RESPONDER_APPL_ID');
9121 --<debug start>
9122 l_progress := '020 selection fn responder id not null';
9123
9124 IF (g_fnd_debug = 'Y') THEN
9125 fnd_log.string(FND_LOG.LEVEL_PROCEDURE, 'pos.plsql.PO_ChangeOrderWF_PVT.PO_SUPCHG_SELECTOR.invoked','l_progress2 : '||l_progress);
9126 END IF;
9127 --<debug end>
9128
9129 --<debug start>
9130 l_progress :='030 selector fn : setting user id :'||l_responder_id ||' resp id '||l_resp_id_to_set||' l_appl id '||l_appl_id_to_set;
9131
9132 IF (g_fnd_debug = 'Y') THEN
9133 fnd_log.string(FND_LOG.LEVEL_PROCEDURE, 'pos.plsql.PO_ChangeOrderWF_PVT.PO_SUPCHG_SELECTOR.invoked','l_progress3 : '||l_progress);
9134 END IF;
9135 --<debug end>
9136 else
9137 l_user_id_to_set := wf_engine.GetItemAttrNumber (itemtype => p_itemtype,
9138 itemkey => p_itemkey,
9139 aname => 'USER_ID');
9140 l_resp_id_to_set := wf_engine.GetItemAttrNumber (itemtype => p_itemtype,
9141 itemkey => p_itemkey,
9142 aname => 'RESP_ID');
9143 l_appl_id_to_set := wf_engine.GetItemAttrNumber (itemtype => p_itemtype,
9144 itemkey => p_itemkey,
9145 aname => 'APPLICATION_ID');
9146 --<debug start>
9147 l_progress := '040 selector fn responder id null';
9148 IF (g_fnd_debug = 'Y') THEN
9149 fnd_log.string(FND_LOG.LEVEL_PROCEDURE, 'pos.plsql.PO_ChangeOrderWF_PVT.PO_SUPCHG_SELECTOR.invoked','l_progress4 : '||l_progress);
9150 END IF;
9151 --<debug end>
9152
9153 --<debug start>
9154 l_progress := '050 selector fn : set user '||l_user_id_to_set||' resp id ' ||l_resp_id_to_set||' appl id '||l_appl_id_to_set;
9155
9156 IF (g_fnd_debug = 'Y') THEN
9157 fnd_log.string(FND_LOG.LEVEL_PROCEDURE, 'pos.plsql.PO_ChangeOrderWF_PVT.PO_SUPCHG_SELECTOR.invoked','l_progress4 : '||l_progress);
9158 END IF;
9159 --<debug end>
9160 end if;
9161
9162 fnd_global.apps_initialize(l_user_id_to_set, l_resp_id_to_set,l_appl_id_to_set);
9163
9164 -- obvious place to make such a call, since we are using an apps_initialize,
9165 -- this is required since the responsibility might have a different OU attached
9166 -- than what is required.
9167 IF l_org_id is NOT NULL THEN
9168 PO_MOAC_UTILS_PVT.set_org_context(l_org_id) ;
9169 END IF;
9170
9171 END IF;
9172 EXCEPTION WHEN OTHERS THEN
9173
9174 IF (g_fnd_debug = 'Y') THEN
9175 fnd_log.string(FND_LOG.LEVEL_PROCEDURE, 'pos.plsql.PO_ChangeOrderWF_PVT.PO_SUPCHG_SELECTOR.invoked','Exception in Selector Procedure');
9176 END IF;
9177
9178 WF_CORE.context('PO_ChangeOrderWF_PVT', 'PO_SUPCHG_SELECTOR', p_itemtype, p_itemkey, p_actid, p_funcmode);
9179 RAISE;
9180
9181 END PO_SUPCHG_SELECTOR;
9182
9183 END PO_ChangeOrderWF_PVT;