[Home] [Help]
PACKAGE BODY: APPS.PO_REQAPPROVAL_INIT1
Source
1 PACKAGE BODY PO_REQAPPROVAL_INIT1 AS
2 /* $Header: POXWPA1B.pls 120.56.12010000.7 2009/01/20 05:50:56 lgoyal ship $ */
3
4 -- Read the profile option that enables/disables the debug log
5 g_po_wf_debug VARCHAR2(1) := NVL(FND_PROFILE.VALUE('PO_SET_DEBUG_WORKFLOW_ON'),'N');
6 -- Read the profile option that determines whether the promise date will be defaulted with need-by date or not
7 g_default_promise_date VARCHAR2(1) := NVL(FND_PROFILE.VALUE('POS_DEFAULT_PROMISE_DATE_ACK'),'N');
8
9 g_document_subtype PO_HEADERS_ALL.TYPE_LOOKUP_CODE%TYPE;
10
11 --Bug#3497033
12 --g_currency_format_mask declared to pass in as the second parameter
13 --in FND_CURRENCY.GET_FORMAT_MASK
14 g_currency_format_mask NUMBER := 60;
15
16 /*=======================================================================+
17 | FILENAME
18 | POXWPA1B.pls
19 |
20 | DESCRIPTION
21 | PL/SQL body for package: PO_REQAPPROVAL_INIT1
22 |
23 | NOTES Ben Chihaoui Created 6/15/97
24 | MODIFIED (MM/DD/YY)
25 | davidng 06/04/2002 Fix for bug 2401183. Used the Workflow Utility
26 | Package wrapper function and procedure to get
27 | and set attributes REL_NUM and REL_NUM_DASH
28 | in procedure PO_REQAPPROVAL_INIT1.Initialise_Error
29 *=======================================================================*/
30 --
31
32 TYPE g_refcur IS REF CURSOR;
33
34 -- Bug#3147435
35 -- Added contractor_requisition_flag and contractor_status to GetRecHdr_csr
36 Cursor GetRecHdr_csr(p_requisition_header_id NUMBER) RETURN ReqHdrRecord is
37 select REQUISITION_HEADER_ID,DESCRIPTION,AUTHORIZATION_STATUS,
38 TYPE_LOOKUP_CODE,PREPARER_ID,SEGMENT1,CLOSED_CODE,EMERGENCY_PO_NUM,
39 NVL(CONTRACTOR_REQUISITION_FLAG, 'N'),
40 NVL(CONTRACTOR_STATUS, 'NULL'), NOTE_TO_AUTHORIZER
41 from po_requisition_headers_all
42 where REQUISITION_HEADER_ID = p_requisition_header_id;
43
44 /*****************************************************************************
45 * The following are local/Private procedure that support the workflow APIs: *
46 *****************************************************************************/
47
48
49 procedure SetReqHdrAttributes(itemtype in varchar2, itemkey in varchar2);
50
51 --
52 procedure SetReqAuthStat(p_document_id in number, itemtype in varchar2,itemkey in varchar2, note varchar2,
53 p_auth_status varchar2);
54 --
55 procedure SetPOAuthStat(p_document_id in number, itemtype in varchar2,itemkey in varchar2, note varchar2,
56 p_auth_status varchar2);
57 --
58 procedure SetRelAuthStat(p_document_id in number, itemtype in varchar2,itemkey in varchar2, note varchar2,
59 p_auth_status varchar2);
60 --
61 procedure UpdtReqItemtype(itemtype in varchar2,itemkey in varchar2, p_doc_id number);
62 --
63 procedure UpdtPOItemtype(itemtype in varchar2,itemkey in varchar2, p_doc_id number);
64 --
65 procedure UpdtRelItemtype(itemtype in varchar2,itemkey in varchar2, p_doc_id number);
66 --
67
68 procedure GetCanOwnerApprove(itemtype in varchar2,itemkey in varchar2,
69 CanOwnerApproveFlag OUT NOCOPY varchar2);
70
71 PROCEDURE InsertActionHistSubmit(itemtype varchar2, itemkey varchar2,
72 p_doc_id number, p_doc_type varchar2,
73 p_doc_subtype varchar2, p_employee_id number,
74 p_action varchar2, p_note varchar2, p_path_id number);
75
76 --
77 -- Bug 3845048 : Added update action history procedure as an autonomous transaction
78 PROCEDURE UpdateActionHistory(p_doc_id IN number,
79 p_doc_type IN varchar2,
80 p_doc_subtype IN varchar2,
81 p_action IN varchar2
82 ) ;
83
84 -- <ENCUMBRANCE FPJ START>
85
86 FUNCTION EncumbOn_DocUnreserved(p_doc_type varchar2, p_doc_subtype varchar2,
87 p_doc_id number)
88 RETURN varchar2;
89
90 -- <ENCUMBRANCE FPJ END>
91
92 PROCEDURE PrintDocument(itemtype varchar2,itemkey varchar2);
93
94
95 -- DKC 10/10/99
96 PROCEDURE FaxDocument(itemtype varchar2,itemkey varchar2);
97
98
99 FUNCTION Print_Requisition(p_doc_num varchar2, p_qty_precision varchar,
100 p_user_id varchar2) RETURN number ;
101
102 --Bug 6692126 Added p_document_id ,document subtype,with terms ,document type parameters
103 FUNCTION Print_PO(p_doc_num varchar2, p_qty_precision varchar,
104 p_user_id varchar2, p_document_id number default NULL,
105 p_document_subtype varchar2 default NULL,
106 p_withterms varchar2 default NULL) RETURN number ;
107
108 --DKC 10/10/99
109
110 --Bug 6692126 Added p_document_id ,document subtype,with terms ,document type parameters
111 FUNCTION Fax_PO(p_doc_num varchar2, p_qty_precision varchar,
112 p_user_id varchar2, p_fax_enable varchar2,
113 p_fax_num varchar2,p_document_id number default NULL,
114 p_document_subtype varchar2 default NULL,
115 p_withterms varchar2 default NULL) RETURN number ;
116
117 --Bug 6692126 Added p_document_id ,document subtype,with terms ,document type parameters
118 FUNCTION Print_Release(p_doc_num varchar2, p_qty_precision varchar,
119 p_release_num varchar2, p_user_id varchar2,
120 p_document_id number default NULL) RETURN number ;
121
122
123 -- DKC 10/10/99
124
125 --Bug 6692126 Added p_document_id ,document subtype,with terms ,document type parameters
126 FUNCTION Fax_Release(p_doc_num varchar2, p_qty_precision varchar,
127 p_release_num varchar2, p_user_id varchar2,
128 p_fax_enable varchar2, p_fax_num varchar2,
129 p_document_id number default NULL) RETURN number ;
130
131
132 procedure CLOSE_OLD_NOTIF(itemtype in varchar2,
133 itemkey in varchar2);
134
135
136 Procedure Insert_Acc_Rejection_Row(itemtype in varchar2,
137 itemkey in varchar2,
138 actid in number,
139 flag in varchar2);
140
141 /************************************************************************************
142 * Added this procedure as part of Bug #: 2843760
143 * This procedure basically checks if archive_on_print option is selected, and if yes
144 * call procedure PO_ARCHIVE_PO_SV.ARCHIVE_PO to archive the PO
145 *************************************************************************************/
146 procedure archive_po(p_document_id in number,
147 p_document_type in varchar2,
148 p_document_subtype in varchar2);
149
150 -- <HTML Agreement R12 START>
151 PROCEDURE unlock_document
152 ( p_po_header_id IN NUMBER
153 );
154 -- <HTML Agreement R12 END>
155
156 /**************************************************************************************
157 * The following are the global APIs. *
158 **************************************************************************************/
159
160 /*******************************************************************
161 < Added this procedure as part of Bug #: 2810150 >
162 PROCEDURE NAME: get_diff_in_user_list
163
164 DESCRIPTION :
165 Given a two lists of users, this procedure gives the difference of the two lists.
166 The users must be present in the fnd_user table.
167
168 Referenced by : locate_notifier
169 parameters :
170
171 Input:
172 p_super_set : A string having the list of user names
173 Example string: 'GE1', 'GE2', 'GE22'
174 p_subset : A list of string having the subset of user names present in the
175 previous list.
176 Output:
177 x_name_list: A list users present in the super set but not in
178 subset.
179 x_users_count: The number of users in the above list.
180
181 CHANGE History: Created 27-Feb-2003 jpasala
182 *******************************************************************/
183 PROCEDURE get_diff_in_user_list ( p_super_set in varchar2, p_subset in varchar2 ,
184 x_name_list out nocopy varchar2,
185 x_name_list_for_sql out nocopy varchar2,
186 x_users_count out nocopy number )
187 IS
188 l_refcur g_refcur;
189 l_name_list varchar2(2000);
190 l_count number;
191 l_user_name FND_USER.USER_NAME%type;
192 l_progress varchar2(255);
193 BEGIN
194 l_count := 0;
195 open l_refcur for
196 'select distinct fu.user_name
197 from fnd_user fu
198 where fu.user_name in ('|| p_super_set || ')
199 and fu.user_name not in (' || p_subset || ')';
200
201
202
203 -- Loop through the cursor and construct the
204 -- user list.
205 LOOP
206 fetch l_refcur into l_user_name;
207 if l_refcur%notfound then
208 exit;
209 end if;
210 IF l_count = 0 THEN
211 l_count := l_count+1;
212 x_name_list_for_sql := '''' ||l_user_name ||'''';
213 x_name_list := l_user_name;
214 ELSE
215 l_count := l_count+1;
216 x_name_list_for_sql := x_name_list_for_sql || ', ' || '''' || l_user_name||'''';
217 x_name_list := x_name_list || ' ' || l_user_name;
218 END IF;
219 END LOOP;
220
221 -- If there are no users found simply
222 -- send back null.
223 if l_count = 0 then
224 x_name_list := ' NULL ';
225 end if;
226 x_users_count := l_count;
227
228 EXCEPTION
229 WHEN OTHERS THEN
230 x_name_list := null;
231 l_progress := 'PO_REQAPPROVAL_INIT1.get_diff_in_user_list : Failed to get the list of users';
232 po_message_s.sql_error('In Exception of get_diff_in_user_list ()', l_progress, sqlcode);
233 END;
234 /*******************************************************************
235 < Added this function as part of Bug #: 2810150 >
236 PROCEDURE NAME: get_wf_role_for_users
237
238 DESCRIPTION :
239 Given a list of users, the procedure looks through the wf_user_roles
240 to get a role that has exactly same set of input list of users.
241
242 Referenced by : locate_notifier
243 parameters :
244
245 Input:
246 p_list_of_users - String containing the list of users
247 Example string: 'GE1', 'GE2', 'GE22'
248 p_num_users - number of users in the above list
249 Output:
250 A string containg the role name ( or null , if such role
251 does not exist ).
252
253 CHANGE History: Created 27-Feb-2003 jpasala
254 *******************************************************************/
255
256 FUNCTION get_wf_role_for_users(p_list_of_users IN VARCHAR2, p_num_users IN NUMBER) RETURN VARCHAR2
257 IS
258 l_role_name WF_USER_ROLES.ROLE_NAME%TYPE;
259 l_adhoc VARCHAR2(10);
260 l_progress VARCHAR2(255);
261 l_offset PLS_INTEGER;
262 l_length PLS_INTEGER;
263 l_start PLS_INTEGER;
264 l_end PLS_INTEGER;
265 l_user_name fnd_user.user_name%TYPE;
266 l_count PLS_INTEGER;
267
268 CURSOR l_cur IS
269 SELECT role_name
270 FROM (
271 SELECT role_name
272 FROM wf_user_roles
273 WHERE role_name IN
274 (SELECT role_name
275 FROM wf_user_roles
276 WHERE user_name in (SELECT user_name FROM po_wf_user_tmp)
277 AND role_name like 'ADHOC%'
278 AND NVL(EXPIRATION_DATE,SYSDATE+1) > SYSDATE
279 GROUP BY role_name
280 HAVING count(role_name) = p_num_users
281 )
282 GROUP BY role_name
283 HAVING COUNT(role_name) = p_num_users
284 )
285 WHERE ROWNUM < 2;
286 BEGIN
287
288 DELETE po_wf_user_tmp; -- delete rows in the global temp table
289
290 -- split the user names from p_list_of_users and insert them to the
291 -- global temp table
292
293 l_offset := 1;
294 l_count := 0;
295
296 WHILE TRUE LOOP
297 l_start := Instr(p_list_of_users, '''', l_offset);
298 IF l_start = 0 THEN
299 EXIT;
300 END IF;
301
302 l_end := Instr(p_list_of_users, '''', l_start + 1);
303 IF l_end = 0 THEN
304 EXIT;
305 END IF;
306
307 l_user_name := Substr(p_list_of_users, l_start+1, l_end - l_start - 1);
308 l_offset := l_end + 1;
309
310 INSERT INTO po_wf_user_tmp (user_name) VALUES (l_user_name);
311 l_count := l_count + 1;
312 END LOOP;
313
314 IF l_count = 0 OR l_count <> p_num_users THEN
315 RETURN NULL;
316 END IF;
317
318 OPEN l_cur;
319 FETCH l_cur INTO l_role_name;
320 IF l_cur%notfound THEN
321 l_role_name := NULL;
322 END IF;
323 CLOSE l_cur;
324
325 DELETE po_wf_user_tmp;
326 RETURN l_role_name;
327
328 EXCEPTION
329 WHEN OTHERS THEN
330 l_role_name := null;
331 l_progress := 'PO_REQAPPROVAL_INIT1.get_wf_role_for_users: Failed to get the list of users';
332 po_message_s.sql_error('In Exception of get_wf_role_for_users()', l_progress, sqlcode);
333 END get_wf_role_for_users;
334
335 /**
336 < Added this function as part of Bug #: 2810150 >
337 FUNCTION NAME: get_function_id
338 Get the function id given the function name as in FND_FORM_FUNCTIONS table
339 String p_function_name - Function name
340 Return Number - The function id
341
342 CHANGE History : Created 27-Feb-2003 JPASALA
343 */
344 FUNCTION get_function_id (p_function_name IN VARCHAR2) RETURN NUMBER IS
345 CURSOR l_cur IS
346 SELECT function_id
347 FROM fnd_form_functions
348 WHERE function_name = p_function_name;
349 l_function_id NUMBER:=0;
350 BEGIN
351 OPEN l_cur;
352 FETCH l_cur INTO l_function_id;
353 CLOSE l_cur;
354 if( l_function_id is null ) then
355 l_function_id := -1;
356 end if;
357 RETURN l_function_id;
358
359 EXCEPTION
360 WHEN OTHERS THEN
361 l_function_id := -1;
362 return l_function_id;
363 END get_function_id;
364
365 /*******************************************************************
366 < Added this procedure as part of Bug #: 2810150 >
367 PROCEDURE NAME: get_user_list_with_resp
368
369 DESCRIPTION :
370 Given a set of users and and a set of responsibilities,
371 this procedures returns a new set of users that are
372 assigned atleast one of the responsibilities in the
373 given set.
374
375 Referenced by : locate_notifier
376 parameters :
377
378 Input:
379 p_function_id - function id
380 p_namelist - String containing the list of users
381 Example string: 'GE1', 'GE2', 'GE22'
382 Output:
383 x_new_list - list of users that have the given responsibility.
384 x_count - number of users in the above list
385
386
387 CHANGE History: Created 27-Feb-2003 jpasala
388 *******************************************************************/
389
390 PROCEDURE get_user_list_with_resp(
391 p_function_id IN NUMBER,
392 p_namelist IN VARCHAR2,
393 x_new_list OUT NOCOPY VARCHAR2,
394 x_new_list_for_sql OUT NOCOPY VARCHAR2,
395 x_count out nocopy number)
396 is
397 l_refcur g_refcur;
398 l_first boolean;
399 l_user_name varchar2(100);
400 l_count number;
401 l_progress varchar2(200);
402 l_f varchar2 (10);
403 begin
404 l_count := 0;
405 l_f := '''' || 'F' || '''';
406 open l_refcur for
407 'select distinct fu.user_name
408 from fnd_user fu, fnd_user_resp_groups furg
409 where fu.user_id = furg.user_id
410 and furg.responsibility_id in
411 (
412 SELECT
413 responsibility_id
414 FROM fnd_responsibility fr
415 WHERE menu_id in
416 ( SELECT fme.menu_id
417 FROM fnd_menu_entries fme
418 START WITH fme.function_id ='|| p_function_id ||'
419 CONNECT BY PRIOR menu_id = sub_menu_id
420 )
421 and (end_date is null or end_date > sysdate) '||
422 ' and fr.responsibility_id not in (select responsibility_id from fnd_resp_functions
423 where action_id= '|| p_function_id ||
424 ' and rule_type=' || l_f || ' )' ||
425
426 ' )
427 and fu.user_name in (' || p_namelist || ')
428 and (furg.end_date is null or furg.end_date > sysdate )' ;
429
430
431
432
433 -- Loop through the cursor and construct the
434 -- user list.
435 LOOP
436 fetch l_refcur into l_user_name;
437 if l_refcur%notfound then
438 exit;
439 end if;
440 IF l_count = 0 THEN
441 l_count := l_count+1;
442 x_new_list_for_sql := '''' ||l_user_name ||'''';
443 x_new_list := l_user_name;
444 ELSE
445 l_count := l_count+1;
446 x_new_list_for_sql := x_new_list_for_sql || ', ' || '''' || l_user_name||'''';
447 x_new_list := x_new_list || ' ' || l_user_name;
448 END IF;
449 END LOOP;
450
451 -- If there are no users found simply
452 -- send back null.
453 if l_count = 0 then
454 x_new_list := ' NULL ';
455 end if;
456 x_count := l_count;
457
458 EXCEPTION
459 WHEN OTHERS THEN
460 x_new_list := ' null ';
461 l_progress := 'PO_REQAPPROVAL_INIT1.get_user_list_with_resp: Failed to get the list of users';
462 po_message_s.sql_error('In Exception of get_user_list_with_resp()', l_progress, sqlcode);
463 end get_user_list_with_resp;
464
465 -------------------------------------------------------------------------------
466 --Start of Comments
467 --Name: start_wf_process
468 --Pre-reqs:
469 -- N/A
470 --Modifies:
471 -- N/A
472 --Locks:
473 -- None
474 --Function:
475 -- Starts a Document Approval workflow process.
476 --Parameters:
477 --IN:
478 --ItemType
479 -- Item Type of the workflow to be started; if NULL, we will use the default
480 -- Approval Workflow Item Type for the given DocumentType
481 --ItemKey
482 -- Item Key for starting the workflow; if NULL, we will construct a new key
483 -- from the sequence
484 --WorkflowProcess
485 -- Workflow process to be started; if NULL, we will use the default Approval
486 -- Workflow Process for the given DocumentType
487 --ActionOriginatedFrom
488 -- Indicates the caller of this procedure. If 'CANCEL', then the approval will
489 -- not insert into the action history.
490 --DocumentID
491 -- This value for this parameter depends on the DocumentType:
492 -- 'REQUISITION': PO_REQUISITION_HEADERS_ALL.requisition_header_id
493 -- 'PO' or 'PA': PO_HEADERS_ALL.po_header_id
494 -- 'RELEASE': PO_RELEASES_ALL.po_release_id
495 --DocumentNumber
496 -- (Obsolete) This parameter is ignored. This procedure will derive the
497 -- document number from DocumentID and DocumentType. (Bug 3284628)
498 --PreparerID
499 -- Requester (for Requisitions) or buyer (for other document types)
500 -- whose approval authority should be used in the approval workflow
501 --DocumentType
502 -- 'REQUISITION', 'PO', 'PA', 'RELEASE'
503 --DocumentSubType
504 -- The value for this parameter depends on the DocumentType:
505 -- 'REQUISITION': PO_REQUISITION_HEADERS_ALL.type_lookup_code
506 -- 'PO' or 'PA': PO_HEADERS_ALL.type_lookup_code
507 -- 'RELEASE': PO_RELEASES_ALL.release_type
508 --SubmitterAction
509 -- (Unused) This parameter is not currently used.
510 --ForwardToID
511 -- Requester (for Requisitions) or buyer (for other document types)
512 -- that this document is being forwarded to
513 --ForwardFromID
514 -- Requester (for Requisitions) or buyer (for other document types)
515 -- that this document is being forwarded from.
516 --DefaultApprovalPathID
517 -- Approval hierarchy to use in the approval workflow
518 --Note
519 -- Note to be entered into Action History for this document
520 --PrintFlag
521 -- If 'Y', this document will be printed.
522 --FaxFlag
523 -- If 'Y', this document will be faxed.
524 --FaxNumber
525 -- Phone number that this document will be faxed to
526 --EmailFlag
527 -- If 'Y', this document will be emailed.
528 --EmailAddress
529 -- Email address that this document will be sent to
530 --CreateSourcingRule
531 -- Blankets only: If 'Y', the workflow will create new sourcing rules,
532 -- rule assignments, and ASL entries.
533 --ReleaseGenMethod
534 -- Blankets only: Release Generation Method to use when creating ASL entries
535 --UpdateSourcingRule
536 -- Blankets only: If 'Y', the workflow will update existing sourcing rules
537 -- and ASL entries.
538 --MassUpdateReleases
539 -- <RETROACTIVE FPI> Blankets / GAs only: If 'Y', we will update the price
540 -- on the releases of the blanket or standard POs of the GA with the
541 -- retroactive price change on the blanket/GA line.
542 --RetroactivePriceChange
543 -- <RETROACTIVE FPI> Releases / Standard POs only: If 'Y', indicates that
544 -- this release/PO has been updated with a retroactive price change.
545 -- This flag is used to differentiate between approval of releases from
546 -- the form and from the Mass Update Releases concurrent program.
547 --OrgAssignChange
548 -- <GA FPI> Global Agreements only: If 'Y', indicates that an Organization
549 -- Assignment change has been made to this GA.
550 --CommunicatePriceChange
551 -- <RETROACTIVE FPJ> Blankets only: If 'Y', we will communicate any releases
552 -- or POs that were retroactively priced to the Supplier.
553 --p_background_flag
554 -- <DROPSHIP FPJ> If 'Y', we will do the following:
555 -- 1. No database commit
556 -- 2. Change the authorization_status to 'IN PROCESS'.
557 -- 3. Launch the approval workflow with background_flag set to 'Y', so that
558 -- it blocks immediately at a deferred activity.
559 -- As a result, the caller can choose to commit or rollback its changes.
560 --p_Initiator
561 -- Added for RCO Enhancement changes for R12. RCO will pass this parameter
562 -- value as : 'SUPPLIER' or 'REQUESTER'. Other callers will pass as NULL
563 -- value (default). The corresponding value('REQUESTER'/'SUPPLIER') is used
564 -- to set INITIATOR wf attribute in RCO wf.
565 --p_xml_flag
566 -- If 'Y' or 'N', this procedure will update the xml_flag in PO_HEADERS_ALL
567 -- or PO_RELEASES_ALL accordingly. This is used by HTML Orders. (Bug 5218538)
568 -- If null, no updates will be made.
569 -- p_source_type_code VARCHAR2 DEFAULT null
570 -- For the internal change order for requisitions the value will be INVENTORY
571
572 --End of Comments
573 -------------------------------------------------------------------------------
574 PROCEDURE Start_WF_Process ( ItemType VARCHAR2,
575 ItemKey VARCHAR2,
576 WorkflowProcess VARCHAR2,
577 ActionOriginatedFrom VARCHAR2,
578 DocumentID NUMBER,
579 DocumentNumber VARCHAR2,
580 PreparerID NUMBER,
581 DocumentTypeCode VARCHAR2,
582 DocumentSubtype VARCHAR2,
583 SubmitterAction VARCHAR2,
584 forwardToID NUMBER,
585 forwardFromID NUMBER,
586 DefaultApprovalPathID NUMBER,
587 Note VARCHAR2,
588 PrintFlag VARCHAR2,
589 FaxFlag VARCHAR2,
590 FaxNumber VARCHAR2,
591 EmailFlag VARCHAR2,
592 EmailAddress VARCHAR2,
593 CreateSourcingRule VARCHAR2,
594 ReleaseGenMethod VARCHAR2,
595 UpdateSourcingRule VARCHAR2,
596 MassUpdateReleases VARCHAR2,
597 RetroactivePriceChange VARCHAR2,
598 OrgAssignChange VARCHAR2, -- GA FPI
599 CommunicatePriceChange VARCHAR2, -- <FPJ Retroactive>
600 p_Background_Flag VARCHAR2 default 'N', -- <DropShip FPJ>
601 p_Initiator VARCHAR2 default NULL,
602 p_xml_flag VARCHAR2 default NULL,
603 /* Bug6708182 FPDS-NG ER. */
604 /* Added */
605 FpdsngFlag VARCHAR2 default 'N' ,
606 p_source_type_code VARCHAR2 DEFAULT null
607 /* End Added*/
608 )
609 IS
610 l_responsibility_id number;
611 l_user_id number;
612 l_application_id number;
613
614 x_progress varchar2(300);
615 x_wf_created number;
616 x_orgid number;
617
618 EmailAddProfile VARCHAR2(60);
619
620
621 x_acceptance_required_flag varchar2(1) := null;
622 x_acceptance_due_date date;
623 x_agent_id NUMBER;
624
625 x_buyer_username varchar2(100);
626 x_buyer_display_name varchar2(240);
627
628 l_userkey varchar2(40);
629 l_doc_num_rel varchar2(30);
630 l_doc_display_name FND_NEW_MESSAGES.message_text%TYPE; -- Bug 3215186
631 l_release_num PO_RELEASES.release_num%TYPE; -- Bug 3215186
632 l_revision_num PO_HEADERS.revision_num%TYPE; -- Bug 3215186
633 l_ga_flag varchar2(1) := null; -- FPI GA
634
635 /* RETROACTIVE FPI START */
636 l_seq_for_item_key varchar2(6) := null;
637 l_can_change_forward_from_flag
638 po_document_types.can_change_forward_from_flag%type;
639 l_can_change_forward_to_flag po_document_types.can_change_forward_to_flag%type;
640 l_can_change_approval_path po_document_types.can_change_approval_path_flag%type;
641 l_can_preparer_approve_flag po_document_types.can_preparer_approve_flag%type;
642 l_default_approval_path_id po_document_types.default_approval_path_id%type;
643 l_can_approver_modify_flag po_document_types.can_approver_modify_doc_flag%type;
644 l_forwarding_mode_code po_document_types.forwarding_mode_code%type;
645 l_itemtype po_document_types.wf_approval_itemtype%type;
646 l_workflow_process po_document_types.wf_approval_process%type;
647 l_itemkey varchar2(60);
648 l_type_name po_document_types.type_name%type;
649
650 /* RETROACTIVE FPI END */
651
652 l_drop_ship_flag po_line_locations.drop_ship_flag%type; -- <DropShip FPJ>
653 l_conterms_exist_flag PO_HEADERS_ALL.CONTERMS_EXIST_FLAG%TYPE; --<CONTERMS FPJ>
654 --bug##3682458 replaced legal entity name with operating unit
655 l_operating_unit hr_all_organization_units_tl.name%TYPE; --<POC FPJ>
656
657 l_document_number PO_HEADERS_ALL.segment1%TYPE; -- Bug 3284628
658
659 l_consigned_flag PO_HEADERS_ALL.CONSIGNED_CONSUMPTION_FLAG%TYPE;
660 l_autoapprove_retro varchar2(1);
661
662 l_okc_doc_type varchar2(20); -- <Word Integration 11.5.10+>
663 l_vendor po_vendors.vendor_name%type; --Bug 4254468
664 l_vendor_site_code po_vendor_sites_all.vendor_site_code%type; --Bug 4254468
665
666 l_communicatePriceChange VARCHAR2(1); -- bug4176111
667 BEGIN
668
669
670 /* DBMS_OUTPUT.enable(10000); */
671
672 x_progress := 'PO_REQAPPROVAL_INIT1.Start_WF_Process: at beginning of Start_WF_Process';
673 IF (g_po_wf_debug = 'Y') THEN
674 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
675 END IF;
676
677 --
678 -- Start Process :
679 -- - If a process is passed then it will be run
680 -- - If a process is not passed then the selector function defined in
681 -- item type will be determine which process to run
682 --
683
684 /* RETROACTIVE FPI START.
685 * Get the itemtype and WorkflowProcess from po_document_types
686 * if it is not set.
687 */
688
689 If ((ItemType is NULL) or (WorkflowProcess is NULL)) then
690
691 po_approve_sv.get_document_types(
692 p_document_type_code => DocumentTypeCode,
693 p_document_subtype => DocumentSubtype,
694 x_can_change_forward_from_flag =>l_can_change_forward_from_flag,
695 x_can_change_forward_to_flag => l_can_change_forward_to_flag,
696 x_can_change_approval_path => l_can_change_approval_path,
697 x_default_approval_path_id => l_default_approval_path_id,
698 x_can_preparer_approve_flag => l_can_preparer_approve_flag, -- Bug 2737257
699 x_can_approver_modify_flag => l_can_approver_modify_flag,
700 x_forwarding_mode_code => l_forwarding_mode_code,
701 x_wf_approval_itemtype => l_itemtype,
702 x_wf_approval_process => l_workflow_process,
703 x_type_name => l_type_name);
704
705 else
706 l_itemtype := ItemType;
707 l_workflow_process := WorkflowProcess;
708
709 END IF;
710
711 If (ItemKey is NULL) then
712
713 select to_char(PO_WF_ITEMKEY_S.NEXTVAL)
714 into l_seq_for_item_key
715 from sys.dual;
716
717 l_itemkey := to_char(DocumentID) || '-' ||
718 l_seq_for_item_key;
719 else
720 l_itemkey := ItemKey;
721
722 END IF;
723
724 /* RETROACTIVE FPI END */
725
726 IF ( l_itemtype is NOT NULL ) AND
727 ( l_itemkey is NOT NULL) AND
728 ( DocumentID is NOT NULL ) THEN
729
730 -- bug 852056: check to see if process has already been created
731 -- if it has, don't create process again.
732 begin
733 select count(*)
734 into x_wf_created
735 from wf_items
736 where item_type = l_itemtype
737 and item_key = l_itemkey;
738 exception
739 when others then
740 x_progress := 'PO_REQAPPROVAL_INIT1.Start_WF_Process: check process existance';
741 po_message_s.sql_error('In Exception of Start_WF_Process()', x_progress, sqlcode);
742 raise;
743 end;
744
745 -- Bug 5218538 START
746 -- Update the XML/EDI flags in the database based on p_xml_flag.
747 -- Do this before the commit, to avoid deadlock situations.
748 IF ((p_xml_flag IS NOT NULL)
749 AND
750 ((DocumentTypeCode='RELEASE' and DocumentSubtype='BLANKET')
751 OR (DocumentTypeCode='PO' and DocumentSubtype='STANDARD'))) THEN
752
753 x_progress := 'PO_REQAPPROVAL_INIT1.Start_WF_Process: Updating the xml_flag: ' || p_xml_flag;
754 IF (g_po_wf_debug = 'Y') THEN
755 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(l_itemtype,l_itemkey,x_progress);
756 END IF;
757
758 IF (p_xml_flag = 'Y') THEN
759
760 IF (DocumentTypeCode = 'RELEASE') THEN
761 UPDATE po_releases_all
762 SET xml_flag = 'Y',
763 edi_processed_flag = 'N'
764 WHERE po_release_id = DocumentID;
765 ELSE
766 UPDATE po_headers_all
767 SET xml_flag = 'Y',
768 edi_processed_flag = 'N'
769 WHERE po_header_id = DocumentID;
770 END IF;
771
772 ELSIF (p_xml_flag = 'N') THEN
773
774 IF (DocumentTypeCode = 'RELEASE') THEN
775 UPDATE po_releases_all
776 SET xml_flag = 'N'
777 WHERE po_release_id = DocumentID;
778 ELSE
779 update po_headers_all
780 SET xml_flag = 'N'
781 WHERE po_header_id = DocumentID;
782 END IF;
783
784 END IF; -- p_xml_flag = 'Y'
785 END IF; -- p_xml_flag IS NOT NULL
786 -- Bug 5218538 END
787
788 --<DropShip FPJ Start>
789 --commit only when background flag is not N.
790 --Default value is N which will commit to retain behavior of current callers.
791 --background flag is passed as 'Y' when called from OM for Drop Ship FPJ, commit not done
792 IF p_Background_Flag <> 'Y' THEN
793 commit;
794 END IF;
795 --<DropShip FPJ End>
796
797 if x_wf_created = 0 then
798 wf_engine.CreateProcess( ItemType => l_itemtype,
799 ItemKey => l_itemkey,
800 process => l_workflow_process );
801 end if;
802
803 --
804 -- Initialize workflow item attributes
805 --
806 /* get the profile option value for the second Email Address */
807
808 FND_PROFILE.GET('PO_SECONDRY_EMAIL_ADD', EmailAddProfile);
809
810 if NVL(ActionOriginatedFrom, 'Approval') = 'POS_DATE_CHG' then
811
812 wf_engine.SetItemAttrText ( itemtype => l_itemtype,
813 itemkey => l_itemkey,
814 aname => 'WEB_SUPPLIER_REQUEST',
815 avalue => 'Y');
816 end if;
817
818 --< Bug 3631960 Start >
819 /* bug 4621626 : passing ActionOriginatedFrom to INTERFACE_SOURCE_CODE,
820 instead of NULL in case of CANCEL, will use the same in the workflow
821 to skip the PO_APPROVED notification ,when wf is called from cancel.
822 */
823
824 x_progress := 'start wf process called interface source code:'||ActionOriginatedFrom;
825 PO_WF_DEBUG_PKG.insert_debug(l_itemtype,l_itemkey,x_progress);
826
827 IF (ActionOriginatedFrom = 'CANCEL') THEN
828
829 -- If approval workflow is being called from a Cancel action, then
830 -- do not insert into action history.
831 PO_WF_UTIL_PKG.SetItemAttrText( itemtype => l_itemtype
832 , itemkey => l_itemkey
833 , aname => 'INSERT_ACTION_HIST_FLAG'
834 , avalue => 'N'
835 );
836 PO_WF_UTIL_PKG.SetItemAttrText( itemtype => l_itemtype
837 , itemkey => l_itemkey
838 , aname => 'INTERFACE_SOURCE_CODE'
839 , avalue => ActionOriginatedFrom
840 );
841 -- Bug 5701051 We should always bypass the approval hierarchy
842 -- for a Cancel action, since the approval workflow is only being
843 -- invoked for communication and archival purposes.
844 PO_WF_UTIL_PKG.SetItemAttrText( itemtype => l_itemtype
845 , itemkey => l_itemkey
846 , aname =>
847 'BYPASS_APPROVAL_HIERARCHY_FLAG'
848 , avalue => 'Y'
849 );
850 ELSE
851
852 -- All other cases, we need to insert into action history.
853 PO_WF_UTIL_PKG.SetItemAttrText( itemtype => l_itemtype
854 , itemkey => l_itemkey
855 , aname => 'INSERT_ACTION_HIST_FLAG'
856 , avalue => 'Y'
857 );
858 PO_WF_UTIL_PKG.SetItemAttrText( itemtype => l_itemtype
859 , itemkey => l_itemkey
860 , aname => 'INTERFACE_SOURCE_CODE'
861 , avalue => ActionOriginatedFrom
862 );
863 -- Bug 5701051 We do not need to bypass the approval hierarchy
864 -- for other actions.
865 PO_WF_UTIL_PKG.SetItemAttrText( itemtype => l_itemtype
866 , itemkey => l_itemkey
867 , aname =>
868 'BYPASS_APPROVAL_HIERARCHY_FLAG'
869 , avalue => 'N'
870 );
871 END IF; --< if ActionOriginatedFrom ... >
872 --< Bug 3631960 End >
873
874 IF (p_Initiator IS NOT NULL) THEN
875
876 PO_WF_UTIL_PKG.SetItemAttrText( itemtype => l_itemtype
877 , itemkey => l_itemkey
878 , aname => 'INITIATOR'
879 , avalue => p_Initiator
880 );
881
882 END IF;
883
884 --
885 wf_engine.SetItemAttrNumber ( itemtype => l_itemtype,
886 itemkey => l_itemkey,
887 aname => 'DOCUMENT_ID',
888 avalue => DocumentID);
889 --
890 wf_engine.SetItemAttrText ( itemtype => l_itemtype,
891 itemkey => l_itemkey,
892 aname => 'DOCUMENT_TYPE',
893 avalue => DocumentTypeCode);
894 --
895
896 wf_engine.SetItemAttrText ( itemtype => l_itemtype,
897 itemkey => l_itemkey,
898 aname => 'DOCUMENT_SUBTYPE',
899 avalue => DocumentSubtype);
900 --<POC FPJ>
901 g_document_subtype := DocumentSubtype;
902 --
903 wf_engine.SetItemAttrNumber ( itemtype => l_itemtype,
904 itemkey => l_itemkey,
905 aname => 'PREPARER_ID',
906 avalue => PreparerID);
907 --
908 wf_engine.SetItemAttrNumber ( itemtype => l_itemtype,
909 itemkey => l_itemkey,
910 aname => 'FORWARD_TO_ID',
911 avalue => ForwardToID);
912 --
913
914 /* Bug# 2308846: kagarwal
915 ** Description: The forward from user was always set to the preparer
916 ** in the Approval process. Hence if the forward from user was
917 ** different from the preparer, the forward from was showing
918 ** wrong information.
919 **
920 ** Fix Details: Modified the procedure Start_WF_Process() and
921 ** Set_Startup_Values() to set the forward from attributes
922 ** correctly.
923 */
924
925 if (forwardFromID is not NULL) then
926 wf_engine.SetItemAttrNumber ( itemtype => l_itemtype,
927 itemkey => l_itemkey,
928 aname => 'FORWARD_FROM_ID',
929 avalue => forwardFromID);
930
931 else
932 wf_engine.SetItemAttrNumber ( itemtype => l_itemtype,
933 itemkey => l_itemkey,
934 aname => 'FORWARD_FROM_ID',
935 avalue => forwardFromID);
936 end if;
937
938 --
939 wf_engine.SetItemAttrNumber ( itemtype => l_itemtype,
940 itemkey => l_itemkey,
941 aname => 'APPROVAL_PATH_ID',
942 avalue => DefaultApprovalPathID);
943 --
944 wf_engine.SetItemAttrText ( itemtype => l_itemtype,
945 itemkey => l_itemkey,
946 aname => 'NOTE',
947 avalue => Note);
948 --
949 wf_engine.SetItemAttrText ( itemtype => l_itemtype,
950 itemkey => l_itemkey,
951 aname => 'PRINT_DOCUMENT',
952 avalue => PrintFlag);
953
954 PO_WF_UTIL_PKG.SetItemAttrText (itemtype => l_itemtype,
955 itemkey => l_itemkey,
956 aname => 'JUSTIFICATION',
957 avalue => Note);
958
959 -- DKC 10/13/99
960 IF DocumentTypeCode IN ('PO', 'PA', 'RELEASE') THEN
961
962 /* Bug6708182 FPDS-NG ER. */
963 /* Bug 6708182 Start */
964 IF DocumentTypeCode IN ('PO', 'RELEASE') THEN
965
966 wf_engine.SetItemAttrText ( itemtype => l_itemtype,
967 itemkey => l_itemkey,
968 aname => 'FPDSNG_FLAG',
969 avalue => FpdsngFlag);
970 END IF;
971 /* Bug 6708182 End */
972
973 if DocumentTypeCode <> 'RELEASE' then
974
975 SELECT poh.acceptance_required_flag,
976 poh.acceptance_due_date,
977 poh.agent_id
978 into x_acceptance_required_flag,
979 x_acceptance_due_date,
980 x_agent_id
981 from po_headers poh
982 where poh.po_header_id = DocumentID;
983
984 ELSE
985
986 SELECT por.acceptance_required_flag,
987 por.acceptance_due_date, por.agent_id
988 into x_acceptance_required_flag,
989 x_acceptance_due_date,
990 x_agent_id
991 from po_releases por,
992 po_headers_all poh -- <R12 MOAC>
993 where por.po_release_id = DocumentID
994 and por.po_header_id = poh.po_header_id;
995
996
997 END IF;
998
999 wf_engine.SetItemAttrText ( itemtype => l_itemtype,
1000 itemkey => l_itemkey,
1001 aname => 'ACCEPTANCE_REQUIRED',
1002 avalue => x_acceptance_required_flag);
1003
1004 wf_engine.SetItemAttrDate ( itemtype => l_itemtype,
1005 itemkey => l_itemkey,
1006 aname => 'ACCEPTANCE_DUE_DATE',
1007 avalue => x_acceptance_due_date);
1008
1009 wf_engine.SetItemAttrNumber ( itemtype => l_itemtype,
1010 itemkey => l_itemkey,
1011 aname => 'BUYER_USER_ID',
1012 avalue => x_agent_id);
1013
1014 if (DocumentTypeCode in ('PO', 'PA')) then
1015
1016 /* FPI GA Start */
1017
1018 -- <GC FPJ>
1019 -- Pass ga flag to the wf for all PA documents (BLANKET and CONTRACT)
1020
1021 -- IF DocumentTypeCode = 'PA' AND DocumentSubtype = 'BLANKET' THEN
1022
1023 IF DocumentTypeCode = 'PA' THEN
1024
1025 select global_agreement_flag
1026 into l_ga_flag
1027 from po_headers_all
1028 where po_header_id = DocumentID;
1029
1030 PO_WF_UTIL_PKG.SetItemAttrText ( itemtype => l_itemtype,
1031 itemkey => l_itemkey,
1032 aname => 'GLOBAL_AGREEMENT_FLAG',
1033 avalue => l_ga_flag);
1034 END IF;
1035 /* FPI GA End */
1036
1037 /* bug 2115200 */
1038 /* Added logic to derive the doc display name */
1039 --CONTERMS FPJ Extracting Contract Terms value in this Query as well
1040 select revision_num,
1041 DECODE(TYPE_LOOKUP_CODE,
1042 'BLANKET',FND_MESSAGE.GET_STRING('POS','POS_POTYPE_BLKT'),
1043 'CONTRACT',FND_MESSAGE.GET_STRING('POS','POS_POTYPE_CNTR'),
1044 'STANDARD',FND_MESSAGE.GET_STRING('POS','POS_POTYPE_STD'),
1045 'PLANNED',FND_MESSAGE.GET_STRING('POS','POS_POTYPE_PLND')),
1046 NVL(CONTERMS_EXIST_FLAG,'N'), --<CONTERMS FPJ>
1047 segment1 -- Bug 3284628
1048 into l_revision_num,
1049 l_doc_display_name,
1050 l_conterms_exist_flag, --<CONTERMS FPJ>
1051 l_document_number -- Bug 3284628
1052 from po_headers
1053 where po_header_id = DocumentID;
1054
1055 l_doc_num_rel := l_document_number;
1056
1057 --<CONTERMS FPJ Start>
1058 PO_WF_UTIL_PKG.SetItemAttrText( itemtype => l_itemtype,
1059 itemkey => l_itemkey,
1060 aname => 'CONTERMS_EXIST_FLAG',
1061 avalue => l_conterms_exist_flag);
1062 --<CONTERMS FPJ END>
1063
1064 /* FPI GA Start */
1065 if l_ga_flag = 'Y' then
1066 l_doc_display_name := FND_MESSAGE.GET_STRING('PO','PO_GA_TYPE');
1067 end if;
1068 /* FPI GA End */
1069
1070 elsif (DocumentTypeCode = 'RELEASE') then
1071
1072 -- Bug 3859714. Workflow attribute WITH_TERMS should be set to 'N' for
1073 -- a Release because a release will not have Terms.
1074 l_conterms_exist_flag := 'N';
1075
1076 /* bug 2115200 */
1077 select POR.revision_num,
1078 POR.release_num,
1079 DECODE(POR.release_type,
1080 'BLANKET', FND_MESSAGE.GET_STRING('POS','POS_POTYPE_BLKTR'),
1081 'SCHEDULED',FND_MESSAGE.GET_STRING('POS','POS_POTYPE_PLNDR')),
1082 POH.segment1 -- Bug 3284628
1083 into l_revision_num,
1084 l_release_num,
1085 l_doc_display_name,
1086 l_document_number -- Bug 3284628
1087 from po_releases POR,
1088 po_headers_all POH -- <R12 MOAC>
1089 where POR.po_release_id = DocumentID
1090 and POR.po_header_id = POH.po_header_id; -- JOIN
1091
1092 l_doc_num_rel := l_document_number || '-' || l_release_num;
1093
1094 -- Bug 3284628 START
1095 ELSIF (DocumentTypeCode = 'REQUISITION') THEN
1096
1097 SELECT PRH.segment1
1098 INTO l_document_number
1099 FROM po_requisition_headers PRH
1100 WHERE PRH.requisition_header_id = DocumentID;
1101
1102 END IF; -- DocumentTypeCode
1103 -- Bug 3284628 END
1104
1105 /* Bug# 2474660: kagarwal
1106 ** Desc: Setting the item user key for all documents.
1107 ** The item user key will be the document number for PO/PA/Requisitions
1108 ** and BPA Number - Release Num for releases.
1109 */
1110
1111
1112 if (DocumentTypeCode = 'RELEASE') then
1113 l_userkey := l_doc_num_rel;
1114 else
1115 l_userkey := l_document_number; -- Bug 3284628
1116 end if;
1117
1118 BEGIN
1119 wf_engine.SetItemUserKey(itemtype => l_itemtype,
1120 itemkey => l_itemkey,
1121 userkey => l_userkey);
1122
1123 EXCEPTION
1124 when others then
1125 null;
1126 END;
1127
1128 -- bug4176111
1129 -- The default of communicate price change should be 'Y' for Standard PO
1130 -- /Releases, and 'N' for everything else
1131 l_communicatePriceChange := CommunicatePriceChange;
1132
1133 IF (l_CommunicatePriceChange IS NULL) THEN
1134 IF (DocumentTypeCode='RELEASE' and DocumentSubtype='BLANKET')
1135 OR (DocumentTypeCode='PO' and DocumentSubtype='STANDARD') THEN
1136
1137 l_communicatePriceChange := 'Y';
1138 ELSE
1139 l_communicatePriceChange := 'N';
1140 END IF;
1141 END IF;
1142
1143
1144
1145
1146 -- Bug 3284628 START
1147 wf_engine.SetItemAttrText ( itemtype => l_itemtype,
1148 itemkey => l_itemkey,
1149 aname => 'DOCUMENT_NUMBER',
1150 avalue => l_document_number);
1151 -- Bug 3284628 END
1152
1153 /* bug 2115200 */
1154
1155 wf_engine.SetItemAttrText (itemtype => l_itemtype,
1156 itemkey => l_itemkey,
1157 aname => 'DOCUMENT_NUM_REL',
1158 avalue => l_doc_num_rel);
1159
1160 wf_engine.SetItemAttrText (itemtype => l_itemtype,
1161 itemkey => l_itemkey,
1162 aname => 'REVISION_NUMBER',
1163 avalue => l_revision_num);
1164
1165 IF (DocumentTypeCode = 'PA' AND DocumentSubtype IN ('BLANKET','CONTRACT')) OR
1166 (DocumentTypeCode = 'PO' AND DocumentSubtype = 'STANDARD') THEN
1167
1168 l_doc_display_name := PO_DOC_STYLE_PVT.GET_STYLE_DISPLAY_NAME(DocumentID);
1169
1170 END IF;
1171
1172 wf_engine.SetItemAttrText (itemtype => l_itemtype,
1173 itemkey => l_itemkey,
1174 aname => 'DOCUMENT_DISPLAY_NAME',
1175 avalue => l_doc_display_name);
1176
1177
1178
1179 if x_agent_id is not null then
1180
1181 x_progress := '003';
1182
1183 -- Get the buyer user name
1184
1185
1186 WF_DIRECTORY.GetUserName( 'PER',
1187 x_agent_id,
1188 x_buyer_username,
1189 x_buyer_display_name);
1190 x_progress := '004';
1191
1192 wf_engine.SetItemAttrText ( itemtype => l_itemtype,
1193 itemkey => l_itemkey,
1194 aname => 'BUYER_USER_NAME',
1195 avalue => x_buyer_username);
1196 end if;
1197
1198
1199 --DKC 10/10/99
1200 wf_engine.SetItemAttrText ( itemtype => l_itemtype,
1201 itemkey => l_itemkey,
1202 aname => 'FAX_DOCUMENT',
1203 avalue => FaxFlag);
1204 --DKC 10/10/99
1205 wf_engine.SetItemAttrText ( itemtype => l_itemtype,
1206 itemkey => l_itemkey,
1207 aname => 'FAX_NUMBER',
1208 avalue => FaxNumber);
1209
1210
1211 wf_engine.SetItemAttrText ( itemtype => l_itemtype,
1212 itemkey => l_itemkey,
1213 aname => 'EMAIL_DOCUMENT',
1214 avalue => EmailFlag);
1215
1216 wf_engine.SetItemAttrText ( itemtype => l_itemtype,
1217 itemkey => l_itemkey,
1218 aname => 'EMAIL_ADDRESS',
1219 avalue => EmailAddress);
1220
1221 wf_engine.SetItemAttrText ( itemtype => l_itemtype,
1222 itemkey => l_itemkey,
1223 aname => 'EMAIL_ADD_FROM_PROFILE',
1224 avalue => EmailAddProfile);
1225
1226
1227 wf_engine.SetItemAttrText ( itemtype => l_itemtype,
1228 itemkey => l_itemkey,
1229 aname => 'CREATE_SOURCING_RULE',
1230 avalue => createsourcingrule);
1231
1232 wf_engine.SetItemAttrText ( itemtype => l_itemtype,
1233 itemkey => l_itemkey,
1234 aname => 'UPDATE_SOURCING_RULE',
1235 avalue => updatesourcingrule);
1236
1237 wf_engine.SetItemAttrText ( itemtype => l_itemtype,
1238 itemkey => l_itemkey,
1239 aname => 'RELEASE_GENERATION_METHOD',
1240 avalue => ReleaseGenMethod);
1241
1242 /* RETROACTIVE FPI START */
1243 PO_WF_UTIL_PKG.SetItemAttrText ( itemtype => l_itemtype,
1244 itemkey => l_itemkey,
1245 aname => 'MASSUPDATE_RELEASES',
1246 avalue => MassUpdateReleases);
1247
1248 PO_WF_UTIL_PKG.SetItemAttrText ( itemtype => l_itemtype,
1249 itemkey => l_itemkey,
1250 aname => 'CO_R_RETRO_CHANGE',
1251 avalue => RetroactivePriceChange);
1252 /* RETROACTIVE FPI END */
1253
1254 /* GA FPI start */
1255 PO_WF_UTIL_PKG.SetItemAttrText ( itemtype => l_itemtype,
1256 itemkey => l_itemkey,
1257 aname => 'GA_ORG_ASSIGN_CHANGE',
1258 avalue => OrgAssignChange);
1259 /* GA FPI End */
1260
1261 -- <FPJ Retroactive START>
1262 PO_WF_UTIL_PKG.SetItemAttrText ( itemtype => l_itemtype,
1263 itemkey => l_itemkey,
1264 aname => 'CO_H_RETROACTIVE_SUPPLIER_COMM',
1265 avalue => l_communicatePriceChange); -- bug4176111
1266 -- <FPJ Retroactive END>
1267
1268 --<DropShip FPJ Start>
1269 PO_WF_UTIL_PKG.SetItemAttrText(itemtype => l_itemtype,
1270 itemkey => l_itemkey,
1271 aname => 'BACKGROUND_FLAG',
1272 avalue => p_background_flag);
1273
1274 -- l_drop_ship_flag indicates if current Release/PO has any DropShip Shipments
1275 BEGIN
1276 l_drop_ship_flag := 'N';
1277
1278 IF DocumentTypeCode = 'RELEASE' THEN
1279 select 'Y'
1280 into l_drop_ship_flag
1281 from dual
1282 where exists
1283 (select 'Release DropShip Shipment Exists'
1284 from po_line_locations
1285 where po_release_id = DocumentId
1286 and drop_ship_flag = 'Y');
1287
1288 ELSIF DocumentTypeCode = 'PO' THEN
1289 select 'Y'
1290 into l_drop_ship_flag
1291 from dual
1292 where exists
1293 (select 'PO DropShip Shipment Exists'
1294 from po_line_locations
1295 where po_header_id = DocumentId
1296 and drop_ship_flag = 'Y');
1297 END IF;
1298
1299 EXCEPTION
1300 WHEN NO_DATA_FOUND THEN
1301 l_drop_ship_flag := 'N';
1302 END;
1303
1304 -- Workflow Attribute DROP_SHIP_FLAG added for any customizations to refer to it.
1305 -- Base Purchasing code does NOT refer to DROP_SHIP_FLAG attribute
1306 PO_WF_UTIL_PKG.SetItemAttrText(itemtype => l_itemtype,
1307 itemkey => l_itemkey,
1308 aname => 'DROP_SHIP_FLAG',
1309 avalue => l_drop_ship_flag);
1310 --<DropShip FPJ End>
1311
1312 -- Bug 3318625 START
1313 -- Set the autoapprove attribute for retroactively priced consumption
1314 -- advices so that they are always routed through change order skipping
1315 -- the authority checks
1316 BEGIN
1317 l_consigned_flag := 'N';
1318
1319 IF DocumentTypeCode = 'RELEASE' THEN
1320 select NVL(consigned_consumption_flag, 'N') -- Bug 3318625
1321 into l_consigned_flag
1322 from po_releases_all
1323 where po_release_id = DocumentId;
1324 ELSIF DocumentTypeCode = 'PO' THEN
1325 select NVL(consigned_consumption_flag, 'N')
1326 into l_consigned_flag
1327 from po_headers_all
1328 where po_header_id = DocumentId;
1329 END IF;
1330
1331 EXCEPTION
1332 WHEN NO_DATA_FOUND THEN
1333 l_consigned_flag := 'N';
1334 END;
1335
1336 IF l_consigned_flag = 'Y' THEN
1337 l_autoapprove_retro := 'Y';
1338
1339 PO_WF_UTIL_PKG.SetItemAttrText ( itemtype => l_itemtype,
1340 itemkey => l_itemkey,
1341 aname => 'CO_H_RETROACTIVE_AUTOAPPROVAL',
1342 avalue => l_autoapprove_retro);
1343 END IF;
1344
1345 -- Bug 3318625 END
1346
1347 /* Get the multi-org context and store it in item attribute ORG_ID. This will be
1348 ** By all other activities.
1349 */
1350 PO_REQAPPROVAL_INIT1.get_multiorg_context (DocumentTypeCode, DocumentID, x_orgid);
1351
1352 IF x_orgid is NOT NULL THEN
1353
1354 PO_MOAC_UTILS_PVT.set_org_context(x_orgid) ; -- <R12 MOAC>
1355
1356 /* Set the Org_id item attribute. We will use it to get the context for every activity */
1357 wf_engine.SetItemAttrNumber ( itemtype => l_itemtype,
1358 itemkey => l_itemkey,
1359 aname => 'ORG_ID',
1360 avalue => x_orgid);
1361
1362 END IF;
1363
1364
1365 -- DKC 02/06/01
1366 wf_engine.SetItemAttrText ( itemtype => l_itemtype,
1367 itemkey => l_itemkey,
1368 aname => 'PO_EMAIL_HEADER',
1369 avalue => 'PLSQL:PO_EMAIL_GENERATE.GENERATE_HEADER/'|| to_char(DocumentID) || ':' || DocumentTypeCode);
1370
1371
1372 -- DKC 02/06/01
1373 wf_engine.SetItemAttrText ( itemtype => l_itemtype,
1374 itemkey => l_itemkey,
1375 aname => 'PO_EMAIL_BODY',
1376 avalue => 'PLSQLCLOB:PO_EMAIL_GENERATE.GENERATE_HTML/'|| to_char(DocumentID) || ':' || DocumentTypeCode);
1377
1378 /* set the terms and conditions read from a file */
1379 --EMAILPO FPH--
1380 -- GENERATE_TERMS is changed to take itemtype and itemkey instead of DocumentID and DocumentTypeCode
1381 -- as itemtype and itemkey are necessary for retrieving the profile options
1382 -- Upgrade related issues are handled in PO_EMAIL_GENERATE.GENERATE_TERMS procedure
1383 /* Bug 2687751. When we refactored start_wf_process, we defaulted
1384 * item type and item key and changed all the occurences of
1385 * itemkey to use local variable l_itemkey. This was left out in the
1386 * SetItemAttrText for PO_TERMS_CONDITIONS. Changing this as part
1387 * of bug 2687751.
1388 */
1389 wf_engine.SetItemAttrText ( itemtype => l_itemtype,
1390 itemkey => l_itemkey,
1391 aname => 'PO_TERMS_CONDITIONS',
1392 avalue => 'PLSQLCLOB:PO_EMAIL_GENERATE.GENERATE_TERMS/'|| l_itemtype || ':' || l_itemkey);
1393
1394 END IF;
1395 --<Bug 4254468 Start> Need to show supplier and operating unit in
1396 -- PO Approval notifications
1397
1398 BEGIN
1399 if DocumentTypeCode <> 'RELEASE' then
1400 select pov.vendor_name,
1401 pvs.vendor_site_code
1402 into l_vendor,
1403 l_vendor_site_code
1404 from po_vendors pov,po_headers poh,po_vendor_sites_all pvs
1405 where pov.vendor_id = poh.vendor_id
1406 and poh.po_header_id = DocumentId
1407 and poh.vendor_site_id = pvs.vendor_site_id;
1408 else
1409 select pov.vendor_name,
1410 pvs.vendor_site_code
1411 into l_vendor,
1412 l_vendor_site_code
1413 from po_releases por,po_headers poh,
1414 po_vendors pov,po_vendor_sites_all pvs
1415 where por.po_release_id = DocumentId
1416 and por.po_header_id = poh.po_header_id
1417 and poh.vendor_id = pov.vendor_id
1418 and poh.vendor_site_id = pvs.vendor_site_id;
1419 end if;
1420 EXCEPTION
1421 WHEN OTHERS THEN
1422 --In case of any exception, the supplier will show up as null
1423 null;
1424 END;
1425
1426 PO_WF_UTIL_PKG.SetItemAttrText (itemtype => l_itemtype,
1427 itemkey => l_itemkey,
1428 aname => 'SUPPLIER',
1429 avalue => l_vendor);
1430
1431 PO_WF_UTIL_PKG.SetItemAttrText (itemtype => l_itemtype,
1432 itemkey => l_itemkey,
1433 aname => 'SUPPLIER_SITE',
1434 avalue => l_vendor_site_code);
1435
1436 --Brought the following code out of POC FPJ block
1437 --Need to display the Legal Entity Name on the Notification Subject
1438
1439 IF x_orgid is not null THEN
1440 --bug#3682458 replaced the sql that retrieves legal entity
1441 --name with sql that retrieves operating unit name
1442 BEGIN
1443 SELECT hou.name
1444 into l_operating_unit
1445 FROM
1446 hr_organization_units hou
1447 WHERE
1448 hou.organization_id = x_orgid;
1449 EXCEPTION
1450 WHEN OTHERS THEN
1451 l_operating_unit:=null;
1452 END;
1453 END IF;
1454
1455 --bug#3682458 replaced legal_entity_name with operating_unit_name
1456 PO_WF_UTIL_PKG.SetItemAttrText(itemtype => l_itemtype,
1457 itemkey => l_itemkey,
1458 aname => 'OPERATING_UNIT_NAME',
1459 avalue=>l_operating_unit);
1460 --<Bug 4254468 End>
1461
1462 --<POC FPJ Start>
1463 --Bug#3528330 used the procedure po_communication_profile() to check for the
1464 --PO output format option instead of checking for the installation of
1465 --XDO product
1466 IF PO_COMMUNICATION_PVT.PO_COMMUNICATION_PROFILE = 'T' THEN
1467
1468 PO_WF_UTIL_PKG.SetItemAttrText (itemtype => l_itemtype,
1469 itemkey => l_itemkey,
1470 aname => 'WITH_TERMS',
1471 avalue =>l_conterms_exist_flag);
1472
1473 PO_WF_UTIL_PKG.SetItemAttrText (itemtype => l_itemtype,
1474 itemkey => l_itemkey,
1475 aname => 'LANGUAGE_CODE',
1476 avalue =>userenv('LANG'));
1477
1478 PO_WF_UTIL_PKG.SetItemAttrText(itemtype => l_itemtype,
1479 itemkey => l_itemkey,
1480 aname => 'EMAIL_TEXT_WITH_PDF',
1481 avalue=>FND_MESSAGE.GET_STRING('PO','PO_PDF_EMAIL_TEXT'));
1482
1483 PO_WF_UTIL_PKG.SetItemAttrText(itemtype => l_itemtype,
1484 itemkey => l_itemkey,
1485 aname => 'PO_PDF_ERROR',
1486 avalue=>FND_MESSAGE.GET_STRING('PO','PO_PDF_ERROR'));
1487
1488 PO_WF_UTIL_PKG.SetItemAttrText (itemtype => l_itemtype,
1489 itemkey => l_itemkey,
1490 aname => 'PDF_ATTACHMENT_BUYER',
1491 avalue => 'PLSQLBLOB:PO_COMMUNICATION_PVT.PDF_ATTACH_APP/'|| l_itemtype||':'||l_itemkey);
1492
1493 -- Bug 3851357. Replaced PDF_ATTACH_SUPP with PDF_ATTACH so that the procedure
1494 -- PO_COMMUNICATION_PKG.PDF_ATTACH is consistently called for all Approval PDF
1495 -- supplier notifications
1496 PO_WF_UTIL_PKG.SetItemAttrText (itemtype => l_itemtype,
1497 itemkey => l_itemkey,
1498 aname => 'PDF_ATTACHMENT_SUPP',
1499 avalue => 'PLSQLBLOB:PO_COMMUNICATION_PVT.PDF_ATTACH/'|| l_itemtype||':'||l_itemkey);
1500
1501 PO_WF_UTIL_PKG.SetItemAttrText (itemtype => l_itemtype,
1502 itemkey => l_itemkey,
1503 aname => 'PDF_ATTACHMENT',
1504 avalue => 'PLSQLBLOB:PO_COMMUNICATION_PVT.PDF_ATTACH/'||l_itemtype||':'||l_itemkey);
1505
1506
1507 -- <Start Word Integration 11.5.10+>
1508 -- <Set up okc doc attachmetn attribute, if necessary>
1509 IF (l_conterms_exist_flag = 'Y')
1510 THEN
1511
1512 l_okc_doc_type := PO_CONTERMS_UTL_GRP.get_po_contract_doctype(DocumentSubtype);
1513
1514 IF ( ('STRUCTURED' <> OKC_TERMS_UTIL_GRP.get_contract_source_code(p_document_type => l_okc_doc_type
1515 , p_document_id => DocumentID))
1516 AND
1517 ('N' = OKC_TERMS_UTIL_GRP.is_primary_terms_doc_mergeable(p_document_type => l_okc_doc_type
1518 , p_document_id => DocumentID))
1519 )
1520 THEN
1521
1522 PO_WF_UTIL_PKG.SetItemAttrText (itemtype => l_itemtype,
1523 itemkey => l_itemkey,
1524 aname => 'OKC_DOC_ATTACHMENT',
1525 avalue =>
1526 'PLSQLBLOB:PO_COMMUNICATION_PVT.OKC_DOC_ATTACH/'||
1527 l_itemtype||':'||l_itemkey);
1528
1529 END IF; -- not structured and not mergeable
1530
1531 -- <Start Contract Dev. Report 11.5.10+>: Set up attachments links region.
1532 -- create attchment with actual l revision number instead of -99
1533 PO_WF_UTIL_PKG.SetItemAttrText(itemtype => l_itemtype,
1534 itemkey => l_itemkey,
1535 aname => 'PO_OKC_ATTACHMENTS',
1536 avalue =>
1537 'FND:entity=OKC_CONTRACT_DOCS'
1538 || '&' || 'pk1name=BusinessDocumentType'
1539 || '&' || 'pk1value=' || DocumentTypeCode || '_' || DocumentSubtype
1540 || '&' || 'pk2name=BusinessDocumentId'
1541 || '&' || 'pk2value=' || DocumentID
1542 || '&' || 'pk3name=BusinessDocumentVersion'
1543 || '&' || 'pk3value=' || '-99'
1544 || '&' || 'categories=OKC_REPO_CONTRACT,OKC_REPO_APP_ABSTRACT');
1545 -- <End Contract Dev. Report 11.5.10+>
1546
1547
1548 END IF; -- l_conterms_exist_flag = 'Y'
1549 -- <End Word Integration 11.5.10+>
1550
1551 END IF;
1552 --<POC FPJ End>
1553 IF DocumentTypeCode = 'REQUISITION' AND p_source_type_code = 'INVENTORY' THEN
1554 wf_engine.SetItemAttrText ( itemtype => l_itemtype,
1555 itemkey => l_itemkey,
1556 aname => 'SOURCE_TYPE_CODE',
1557 avalue => p_source_type_code);
1558
1559 END IF;
1560
1561 -- R12 PO change Order tolerances ECO : 4716963
1562 -- Retrive the tolerances from the new PO tolerances table and
1563 -- set the corresponding workflow attributes if the values in
1564 -- the table are not null.
1565 IF DocumentTypeCode = 'PO' THEN
1566 PO_CHORD_WF6.Set_Wf_Order_Tol(l_itemtype, l_itemkey , DocumentSubtype);
1567 ELSIF DocumentTypeCode = 'PA' THEN
1568 PO_CHORD_WF6.Set_Wf_Agreement_Tol(l_itemtype, l_itemkey , DocumentSubtype);
1569 ELSIF DocumentTypeCode = 'RELEASE' THEN
1570 PO_CHORD_WF6.Set_Wf_Release_Tol(l_itemtype, l_itemkey , DocumentSubtype);
1571 END IF;
1572
1573 x_progress := 'PO_REQAPPROVAL_INIT1.Start_WF_Process: Before call to FND_PROFILE';
1574 IF (g_po_wf_debug = 'Y') THEN
1575 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(l_itemtype,l_itemkey,x_progress);
1576 END IF;
1577
1578 /* Get the USER_ID and the RESPONSIBLITY_ID for the current forms session.
1579 ** This will be used in later calls to APPS_INITIALIZE(), before calling
1580 ** the Document Manager.
1581 */
1582
1583 if (x_wf_created = 0) then
1584 --FND_PROFILE.GET('USER_ID', l_user_id);
1585 --FND_PROFILE.GET('RESP_ID', l_responsibility_id);
1586 --FND_PROFILE.GET('RESP_APPL_ID', l_application_id);
1587
1588
1589 l_user_id := fnd_global.user_id;
1590 l_responsibility_id := fnd_global.resp_id;
1591 l_application_id := fnd_global.resp_appl_id;
1592
1593 IF (l_user_id = -1) THEN
1594 l_user_id := NULL;
1595 END IF;
1596
1597 IF (l_responsibility_id = -1) THEN
1598 l_responsibility_id := NULL;
1599 END IF;
1600
1601 IF (l_application_id = -1) THEN
1602 l_application_id := NULL;
1603 END IF;
1604
1605
1606 /* l_application_id := 201; */
1607 --
1608 wf_engine.SetItemAttrNumber ( itemtype => l_itemtype,
1609 itemkey => l_itemkey,
1610 aname => 'USER_ID',
1611 avalue => l_user_id);
1612 --
1613 wf_engine.SetItemAttrNumber ( itemtype => l_itemtype,
1614 itemkey => l_itemkey,
1615 aname => 'APPLICATION_ID',
1616 avalue => l_application_id);
1617 --
1618 wf_engine.SetItemAttrNumber ( itemtype => l_itemtype,
1619 itemkey => l_itemkey,
1620 aname => 'RESPONSIBILITY_ID',
1621 avalue => l_responsibility_id);
1622
1623 /* Set the context for the doc manager */
1624 fnd_global.APPS_INITIALIZE (l_user_id, l_responsibility_id, l_application_id);
1625 -- bug fix 2424044
1626 IF x_orgid is NOT NULL THEN
1627 PO_MOAC_UTILS_PVT.set_org_context(x_orgid) ; -- <R12 MOAC>
1628 END IF;
1629 end if;
1630
1631
1632 --<DropShip FPJ Start>
1633 -- When background flag is 'Y' the approval workflow blocks at a background activity
1634 -- set authorization_status to IN PROCESS so that the header is 'locked'
1635 -- while the workflow process is waiting for background engine to pick it up
1636
1637 IF p_background_flag = 'Y' THEN
1638 IF DocumentTypeCode = 'RELEASE' THEN
1639 update po_releases
1640 set AUTHORIZATION_STATUS = 'IN PROCESS',
1641 last_updated_by = fnd_global.user_id,
1642 last_update_login = fnd_global.login_id,
1643 last_update_date = sysdate
1644 where po_release_id = DocumentID;
1645 ELSE --PO or PA
1646 update po_headers
1647 set AUTHORIZATION_STATUS = 'IN PROCESS',
1648 last_updated_by = fnd_global.user_id,
1649 last_update_login = fnd_global.login_id,
1650 last_update_date = sysdate
1651 where po_header_id = DocumentID;
1652 END IF;
1653 END IF; -- END of IF p_background_flag = 'Y'
1654
1655 --<DropShip FPJ End>
1656
1657
1658 x_progress := 'PO_REQAPPROVAL_INIT1.Start_WF_Process: Before call to wf_engine.StartProcess()' ||
1659 ' parameter DefaultApprovalPathID= ' || to_char(DefaultApprovalPathID);
1660 IF (g_po_wf_debug = 'Y') THEN
1661 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,l_itemkey,x_progress);
1662 END IF;
1663
1664 --
1665 wf_engine.StartProcess( itemtype => l_itemtype,
1666 itemkey => l_itemkey );
1667
1668 END IF;
1669
1670 EXCEPTION
1671 WHEN OTHERS THEN
1672
1673 x_progress := 'PO_REQAPPROVAL_INIT1.Start_WF_Process: In Exception handler';
1674 IF (g_po_wf_debug = 'Y') THEN
1675 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,l_itemkey,x_progress);
1676 END IF;
1677
1678 po_message_s.sql_error('In Exception of Start_WF_Process()', x_progress, sqlcode);
1679
1680 RAISE;
1681
1682 END Start_WF_Process;
1683
1684
1685 -- SetStartupValues
1686 -- Iinitialize/assigns startup values to workflow attributes.
1687 --
1688 -- IN
1689 -- itemtype, itemkey, actid, funcmode
1690 -- OUT
1691 -- Resultout
1692 -- - Completed - Activity was completed without any errors.
1693 --
1694 procedure Set_Startup_Values( itemtype in varchar2,
1695 itemkey in varchar2,
1696 actid in number,
1697 funcmode in varchar2,
1698 resultout out NOCOPY varchar2 ) is
1699
1700 l_document_type varchar2(25);
1701 l_doc_subtype varchar2(25);
1702 l_document_id number;
1703
1704 l_preparer_id number;
1705 x_username varchar2(100);
1706 x_user_display_name varchar2(240);
1707 x_ff_username varchar2(100);
1708 x_ff_user_display_name varchar2(240);
1709 x_ft_username varchar2(100);
1710 x_ft_user_display_name varchar2(240);
1711 l_forward_to_id number;
1712 l_forward_from_id number;
1713 l_authorization_status varchar2(25);
1714 l_open_form varchar2(200);
1715 l_update_req_url varchar2(1000);
1716 l_open_req_url varchar2(1000);
1717 l_resubmit_req_url varchar2(1000); -- Bug 636924, lpo, 03/31/98
1718 --Bug#3147435
1719 --Variables for VIEW_REQ_DTLS_URL, EDIT_REQ_URL and RESUBMIT_REQ_URL
1720 l_view_req_dtls_url varchar2(1000);
1721 l_edit_req_url varchar2(1000);
1722 l_resubmit_url varchar2(1000);
1723 l_error_msg varchar2(200);
1724 x_orgid number;
1725
1726 l_doc_string varchar2(200);
1727 l_preparer_user_name varchar2(100);
1728 l_po_revision number;
1729
1730 l_interface_source VARCHAR2(30);
1731 l_can_modify_flag VARCHAR2(1);
1732
1733 l_view_po_url varchar2(1000); -- HTML Orders R12
1734 l_edit_po_url varchar2(1000); -- HTML Orders R12
1735 l_style_id po_headers_all.style_id%TYPE;
1736 l_ga_flag po_headers_all.global_agreement_flag%TYPE;
1737
1738 /* Bug 7535468
1739 Increasing the length of x_progress from 200 to 1200 */
1740 x_progress varchar2(1200);
1741
1742 --Context Setting Revamp
1743 l_printer VARCHAR2(30);
1744 l_conc_copies number;
1745 l_conc_save_output varchar2(1);
1746 --Bug 6164753
1747 l_external_url varchar2(500);
1748
1749 BEGIN
1750
1751 x_progress := 'PO_REQAPPROVAL_INIT1.Set_Startup_Values: 01';
1752 IF (g_po_wf_debug = 'Y') THEN
1753 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
1754 END IF;
1755
1756
1757 -- Do nothing in cancel or timeout mode
1758 --
1759 if (funcmode <> wf_engine.eng_run) then
1760
1761 resultout := wf_engine.eng_null;
1762 return;
1763
1764 end if;
1765
1766 /* Bug# 2353153
1767 ** Setting application context
1768 */
1769
1770 --Context Setting Revamp
1771 /* PO_REQAPPROVAL_INIT1.Set_doc_mgr_context(itemtype, itemkey); */
1772
1773 -- Set the multi-org context
1774
1775 x_orgid := wf_engine.GetItemAttrNumber (itemtype => itemtype,
1776 itemkey => itemkey,
1777 aname => 'ORG_ID');
1778
1779 IF x_orgid is NOT NULL THEN
1780
1781 PO_MOAC_UTILS_PVT.set_org_context(x_orgid) ; -- <R12 MOAC>
1782
1783 END IF;
1784
1785 l_document_type := wf_engine.GetItemAttrText (itemtype => itemtype,
1786 itemkey => itemkey,
1787 aname => 'DOCUMENT_TYPE');
1788
1789 l_document_id := wf_engine.GetItemAttrNumber (itemtype => itemtype,
1790 itemkey => itemkey,
1791 aname => 'DOCUMENT_ID');
1792
1793 l_doc_subtype := wf_engine.GetItemAttrText (itemtype => itemtype,
1794 itemkey => itemkey,
1795 aname => 'DOCUMENT_SUBTYPE');
1796
1797 /* Since we are just starting the workflow assign the preparer_id to
1798 ** variable APPROVER_EMPID. This variable always holds the
1799 ** employee id of the approver i.e. activity VERIFY AUTHORITY will
1800 ** always use this employee id to verify authority against.
1801 ** If the preparer can not approve, then process FIND APPROVER will
1802 ** find an approver and put his/her employee_id in APPROVER_EMPID
1803 ** item attribute.
1804 */
1805 l_preparer_id := wf_engine.GetItemAttrNumber (itemtype => itemtype,
1806 itemkey => itemkey,
1807 aname => 'PREPARER_ID');
1808
1809 /*7125551, including the sql to get the value of l_can_modify_flag here*/
1810
1811 SELECT CAN_APPROVER_MODIFY_DOC_FLAG
1812 INTO l_can_modify_flag
1813 FROM po_document_types
1814 WHERE DOCUMENT_TYPE_CODE = l_document_type
1815 AND DOCUMENT_SUBTYPE = l_doc_subtype;
1816
1817 wf_engine.SetItemAttrNumber (itemtype => itemtype,
1818 itemkey => itemkey,
1819 aname => 'APPROVER_EMPID',
1820 avalue => l_preparer_id);
1821
1822 /* Get the username and display_name of the preparer. This will
1823 ** be used as the FORWARD-FROM in the notifications.
1824 ** Initially the preparer is also considered as the approver, so
1825 ** set the approver_username also.
1826 */
1827 PO_REQAPPROVAL_INIT1.get_user_name(l_preparer_id, x_username,
1828 x_user_display_name);
1829
1830 -- Bug 711141 fix (setting process owner here)
1831
1832 wf_engine.SetItemOwner (itemtype => itemtype,
1833 itemkey => itemkey,
1834
1835 /* { Bug 2148872: owner => 'PER:' || l_preparer_id);
1836
1837 wf_engine.SetItemOwner needs 'owner' parameter to be passed as
1838 the internal user name of the owner in wf_users. To pass it as
1839 "PER:person_id" has been disallowed by WF. */
1840
1841 owner => x_username); -- Bug 2148872 }
1842
1843 -- Context Setting revamp (begin)
1844
1845 l_printer := fnd_profile.value('PRINTER');
1846 l_conc_copies := to_number(fnd_profile.value('CONC_COPIES'));
1847 l_conc_save_output := fnd_profile.value('CONC_SAVE_OUTPUT');
1848
1849
1850 /* changed the call from wf_engine.setiteattrtext to
1851 po_wf_util_pkg.setitemattrtext because the later handles
1852 attrbute not found exception. req change order wf also
1853 uses these procedures and does not have the preparer_printer
1854 attribute, hence this was required */
1855
1856
1857 po_wf_util_pkg.SetItemAttrText (itemtype => itemType,
1858 itemkey => itemkey,
1859 aname => 'PREPARER_PRINTER',
1860 avalue => l_printer);
1861
1862 po_wf_util_pkg.SetItemAttrNumber (itemtype => itemType,
1863 itemkey => itemkey,
1864 aname => 'PREPARER_CONC_COPIES',
1865 avalue => l_conc_copies);
1866
1867 po_wf_util_pkg.SetItemAttrText (itemtype => itemType,
1868 itemkey => itemkey,
1869 aname => 'PREPARER_CONC_SAVE_OUTPUT',
1870 avalue => l_conc_save_output);
1871
1872 --Context Setting revamp (end)
1873
1874 wf_engine.SetItemAttrText ( itemtype => itemType,
1875 itemkey => itemkey,
1876 aname => 'PREPARER_USER_NAME' ,
1877 avalue => x_username);
1878
1879 wf_engine.SetItemAttrText ( itemtype => itemType,
1880 itemkey => itemkey,
1881 aname => 'PREPARER_DISPLAY_NAME' ,
1882 avalue => x_user_display_name);
1883
1884 wf_engine.SetItemAttrText ( itemtype => itemType,
1885 itemkey => itemkey,
1886 aname => 'APPROVER_USER_NAME' ,
1887 avalue => x_username);
1888
1889 wf_engine.SetItemAttrText ( itemtype => itemType,
1890 itemkey => itemkey,
1891 aname => 'APPROVER_DISPLAY_NAME' ,
1892 avalue => x_user_display_name);
1893
1894 /* Bug# 2308846: kagarwal
1895 ** Description: The forward from user was always set to the preparer
1896 ** in the Approval process. Hence if the forward from user was
1897 ** different from the preparer, the forward from was showing
1898 ** wrong information.
1899 **
1900 ** Fix Details: Modified the procedure Start_WF_Process() and
1901 ** Set_Startup_Values() to set the forward from attributes
1902 ** correctly.
1903 */
1904
1905
1906 l_forward_from_id := wf_engine.GetItemAttrNumber (itemtype => itemtype,
1907 itemkey => itemkey,
1908 aname => 'FORWARD_FROM_ID');
1909
1910 IF (l_forward_from_id <> l_preparer_id) THEN
1911
1912 PO_REQAPPROVAL_INIT1.get_user_name(l_forward_from_id, x_ff_username,
1913 x_ff_user_display_name);
1914
1915 wf_engine.SetItemAttrText ( itemtype => itemType,
1916 itemkey => itemkey,
1917 aname => 'FORWARD_FROM_USER_NAME' ,
1918 avalue => x_ff_username);
1919
1920 wf_engine.SetItemAttrText ( itemtype => itemType,
1921 itemkey => itemkey,
1922 aname => 'FORWARD_FROM_DISP_NAME' ,
1923 avalue => x_ff_user_display_name);
1924
1925 ELSE
1926
1927 wf_engine.SetItemAttrText ( itemtype => itemType,
1928 itemkey => itemkey,
1929 aname => 'FORWARD_FROM_USER_NAME' ,
1930 avalue => x_username);
1931
1932 wf_engine.SetItemAttrText ( itemtype => itemType,
1933 itemkey => itemkey,
1934 aname => 'FORWARD_FROM_DISP_NAME' ,
1935 avalue => x_user_display_name);
1936
1937 END IF;
1938
1939
1940 /* Get the username (this is the name used to forward the notification to)
1941 ** from the FORWARD_TO_ID. We need to do this here!
1942 ** Also set the item attribute FORWARD_TO_USERNAME to that username.
1943 */
1944 l_forward_to_id := wf_engine.GetItemAttrNumber (itemtype => itemtype,
1945 itemkey => itemkey,
1946 aname => 'FORWARD_TO_ID');
1947
1948 IF l_forward_to_id is NOT NULL THEN
1949
1950 /* kagarwal: Use a diff variable for username and display name
1951 ** for forward to as later we set the responder attributes to same
1952 ** as that of preparer using the var x_username and
1953 ** x_user_display_name
1954 */
1955 /* Get the forward-to display name */
1956 PO_REQAPPROVAL_INIT1.get_user_name(l_forward_to_id, x_ft_username,
1957 x_ft_user_display_name);
1958
1959 /* Set the forward-to display name */
1960 wf_engine.SetItemAttrText ( itemtype => itemType,
1961 itemkey => itemkey,
1962 aname => 'FORWARD_TO_USERNAME' ,
1963 avalue => x_ft_username);
1964
1965 wf_engine.SetItemAttrText ( itemtype => itemType,
1966 itemkey => itemkey,
1967 aname => 'FORWARD_TO_DISPLAY_NAME' ,
1968 avalue => x_ft_user_display_name);
1969
1970 END IF;
1971
1972 /* Bug 1064651
1973 ** Init RESPONDER to PREPARER if document is a requisition.
1974 */
1975
1976 IF l_document_type = 'REQUISITION' THEN
1977
1978 wf_engine.SetItemAttrNumber (itemtype => itemtype,
1979 itemkey => itemkey,
1980 aname => 'RESPONDER_ID',
1981 avalue => l_preparer_id);
1982
1983 wf_engine.SetItemAttrText ( itemtype => itemType,
1984 itemkey => itemkey,
1985 aname => 'RESPONDER_USER_NAME' ,
1986 avalue => x_username);
1987
1988 wf_engine.SetItemAttrText ( itemtype => itemType,
1989 itemkey => itemkey,
1990 aname => 'RESPONDER_DISPLAY_NAME' ,
1991 avalue => x_user_display_name);
1992
1993 /* Bug 3800933
1994 ** Need to set the preparer's language as worflow attribute for info template attachment of req approval
1995 */
1996 PO_WF_UTIL_PKG.SetItemAttrText ( itemtype => itemtype,
1997 itemkey => itemkey,
1998 aname => 'PREPARER_LANGUAGE',
1999 avalue => userenv('LANG'));
2000
2001 END IF;
2002
2003 -- Set the Command for the button that opens the Enter PO/Releases form
2004 -- Note: the Open Form command for the requisition is hard-coded in the
2005 -- Requisition approval workflow.
2006
2007 IF l_document_type IN ('PO', 'PA') THEN
2008 -- <HTML Orders R12 Start >
2009 -- Set the URL and form link attributes based on doc style and type
2010 IF l_doc_subtype in ('BLANKET', 'CONTRACT') THEN
2011 l_ga_flag := PO_WF_UTIL_PKG.GetItemAttrText (itemtype => itemtype,
2012 itemkey => itemkey,
2013 aname => 'GLOBAL_AGREEMENT_FLAG');
2014 END IF;
2015
2016 IF (nvl(l_ga_flag,'N') = 'N' AND (l_doc_subtype = 'BLANKET' OR l_doc_subtype = 'CONTRACT')) OR
2017 l_doc_subtype = 'PLANNED' THEN --added the condition to check for contract PO also as part of bug 7125551 fix
2018 -- HTML Orders R12
2019 -- The url links are not applicable for local agreements
2020 l_view_po_url := null;
2021 l_edit_po_url := null;
2022 --Bug 7716930
2023 l_open_form := 'PO_POXPOEPO:PO_HEADER_ID=' || '&' || 'DOCUMENT_ID' ||
2024 ' ACCESS_LEVEL_CODE="MODIFY"' ||
2025 ' POXPOEPO_CALLING_FORM="POXSTNOT"';
2026
2027 ELSIF nvl(l_ga_flag,'N') = 'Y' OR
2028 l_doc_subtype = 'STANDARD' THEN
2029
2030 Begin
2031 -- SQL What : Get the style id fromm po_headers
2032 -- SQL Why : To derive the style type
2033 SELECT style_id
2034 INTO l_style_id
2035 FROM po_headers_all
2036 WHERE po_header_id = l_document_id;
2037 Exception
2038 When Others Then
2039 l_style_id := null;
2040 End;
2041
2042 l_view_po_url := get_po_url(p_po_header_id => l_document_id,
2043 p_doc_subtype => l_doc_subtype,
2044 p_mode => 'viewOnly');
2045
2046 /* Bug 7307832
2047 Added Debug Messages */
2048 x_progress := 'PO_REQAPPROVAL_INIT1.get_po_url viewOnly' || 'l_view_po_url ::'|| l_view_po_url;
2049 IF (g_po_wf_debug = 'Y') THEN
2050 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
2051 END IF;
2052
2053 IF nvl(l_can_modify_flag,'N') = 'Y' THEN /*Bug 7125551, edit document link should not be available if approver can modify is
2054 unchecked for the document type.*/
2055
2056 l_edit_po_url := get_po_url(p_po_header_id => l_document_id,
2057 p_doc_subtype => l_doc_subtype,
2058 p_mode => 'update');
2059 /* Bug 7307832
2060 Added WF Debug Messages */
2061 x_progress := 'PO_REQAPPROVAL_INIT1.get_po_url update' || 'l_edit_po_url ::'|| l_edit_po_url;
2062 IF (g_po_wf_debug = 'Y') THEN
2063 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
2064 END IF;
2065
2066 ELSE
2067 l_edit_po_url := null;
2068 END IF;
2069
2070 IF PO_DOC_STYLE_GRP.is_standard_doc_style(l_style_id) = 'Y' THEN
2071 --Bug 7716930
2072 l_open_form := 'PO_POXPOEPO:PO_HEADER_ID=' || '&' || 'DOCUMENT_ID' ||
2073 ' ACCESS_LEVEL_CODE="MODIFY"' ||
2074 ' POXPOEPO_CALLING_FORM="POXSTNOT"';
2075 ELSE
2076 l_open_form := null;
2077 END IF;
2078
2079 END IF;
2080 -- <HTML Orders R12 End >
2081
2082 ELSIF l_document_type = 'RELEASE' THEN
2083
2084 --Bug 7716930
2085 l_open_form := 'PO_POXPOERL:PO_RELEASE_ID=' || '&' || 'DOCUMENT_ID' ||
2086 ' ACCESS_LEVEL_CODE="MODIFY"' ||
2087 ' POXPOERL_CALLING_FORM="POXSTNOT"';
2088
2089 -- HTML Orders R12
2090 -- The url links are not applicable for releases
2091 l_view_po_url := null;
2092 l_edit_po_url := null;
2093
2094 END IF;
2095
2096 IF (l_document_type <> 'REQUISITION') then
2097 -- HTML Orders R12
2098 -- Set the URL and form attributes
2099 PO_WF_UTIL_PKG.SetItemAttrText ( itemtype => itemType,
2100 itemkey => itemkey,
2101 aname => 'OPEN_FORM_COMMAND' ,
2102 avalue => l_open_form);
2103
2104 PO_WF_UTIL_PKG.SetItemAttrText ( itemtype => itemType,
2105 itemkey => itemkey,
2106 aname => 'VIEW_DOC_URL' ,
2107 avalue => l_view_po_url);
2108
2109 PO_WF_UTIL_PKG.SetItemAttrText ( itemtype => itemType,
2110 itemkey => itemkey,
2111 aname => 'EDIT_DOC_URL' ,
2112 avalue => l_edit_po_url);
2113
2114 END IF;
2115 /* WEB REQUISITIONS:
2116 ** Set the URL to VIEW/UPDATE web requisitions
2117 */
2118
2119 -- The support for icx 3.0 is removed.
2120
2121 IF (fnd_profile.value('POR_SSP4_INSTALLED') = 'Y' AND
2122 l_document_type = 'REQUISITION' and
2123 po_core_s.get_product_install_status('ICX') = 'I') THEN
2124
2125 --Bug#3147435
2126 --Set the values for workflow attribute
2127 --VIEW_REQ_DTLS_URL and EDIT_REQ_URL
2128
2129 l_view_req_dtls_url := 'JSP:/OA_HTML/OA.jsp?OAFunc=ICX_POR_LAUNCH_IP' || '&' ||
2130 'porMode=viewReq' || '&' ||
2131 'porReqHeaderId=' || to_char(l_document_id) || '&' ||
2132 '_OrgId=' || to_char(x_orgid) || '&' ||
2133 'addBreadCrumb=Y';
2134
2135 l_edit_req_url := 'JSP:/OA_HTML/OA.jsp?OAFunc=ICX_POR_LAUNCH_IP' || '&' ||
2136 'porMode=approverCheckout' || '&' ||
2137 'porReqHeaderId=' || to_char(l_document_id) || '&' ||
2138 '_OrgId=' || to_char(x_orgid);
2139
2140 l_resubmit_url := 'JSP:/OA_HTML/OA.jsp?OAFunc=ICX_POR_LAUNCH_IP' || '&' ||
2141 'porMode=resubmitReq' || '&' ||
2142 'porReqHeaderId=' || to_char(l_document_id) || '&' ||
2143 '_OrgId=' || to_char(x_orgid);
2144
2145 PO_WF_UTIL_PKG.SetItemAttrText ( itemtype => itemType,
2146 itemkey => itemkey,
2147 aname => 'VIEW_REQ_DTLS_URL',
2148 avalue => l_view_req_dtls_url);
2149
2150 PO_WF_UTIL_PKG.SetItemAttrText ( itemtype => itemType,
2151 itemkey => itemkey,
2152 aname => 'EDIT_REQ_URL',
2153 avalue => l_edit_req_url);
2154
2155 PO_WF_UTIL_PKG.SetItemAttrText ( itemtype => itemType,
2156 itemkey => itemkey,
2157 aname => 'RESUBMIT_REQ_URL',
2158 avalue => l_resubmit_url);
2159
2160 /* Removed call for jumpIntoFunction() to set the attributes value.
2161 Instead of that setting the values of l_view_req_dtls_url, l_edit_req_url and l_resubmit_url variables
2162 into corrosponding attributes */
2163
2164 l_open_req_url := l_view_req_dtls_url;
2165 l_update_req_url := l_edit_req_url;
2166
2167 -- Bug 636924, lpo, 03/31/98
2168 -- Added resubmit link.
2169 l_resubmit_req_url := l_resubmit_url;
2170
2171 -- End of fix. Bug 636924, lpo, 03/31/98
2172
2173 wf_engine.SetItemAttrText ( itemtype => itemType,
2174 itemkey => itemkey,
2175 aname => 'REQ_URL' ,
2176 avalue => l_open_req_url);
2177
2178 wf_engine.SetItemAttrText ( itemtype => itemType,
2179 itemkey => itemkey,
2180 aname => 'REQ_UPDATE_URL' ,
2181 avalue => l_update_req_url);
2182
2183 -- Bug 636924, lpo, 03/31/98
2184 -- Added resubmit workflow attribute.
2185
2186 wf_engine.SetItemAttrText ( itemtype => itemType,
2187 itemkey => itemkey,
2188 aname => 'REQ_RESUBMIT_URL' ,
2189 avalue => l_resubmit_req_url);
2190
2191 l_interface_source := wf_engine.GetItemAttrText (itemtype => itemtype,
2192 itemkey => itemkey,
2193 aname => 'INTERFACE_SOURCE_CODE');
2194
2195 l_doc_subtype := wf_engine.GetItemAttrText (itemtype => itemtype,
2196 itemkey => itemkey,
2197 aname => 'DOCUMENT_SUBTYPE');
2198
2199 /* bug 7125551, as part of this bug, commenting out the below sql and including it at the beginning of this procedure so
2200 that the l_can_modify_flag can be used elsewhere also*/
2201
2202 /*SELECT CAN_APPROVER_MODIFY_DOC_FLAG
2203 INTO l_can_modify_flag
2204 FROM po_document_types
2205 WHERE DOCUMENT_TYPE_CODE = l_document_type
2206 AND DOCUMENT_SUBTYPE = l_doc_subtype;*/
2207
2208 -- Not showing the open form icon if this is an IP req and owner can't
2209 -- modify.
2210
2211 if l_can_modify_flag = 'N' and l_interface_source = 'POR' then
2212
2213 wf_engine.SetItemAttrText ( itemtype => itemType,
2214 itemkey => itemkey,
2215 aname => 'OPEN_FORM_COMMAND' ,
2216 avalue => '');
2217 end if;
2218
2219 END IF;
2220
2221 /* Set the Subject of the Approval notification initially to
2222 ** "requires your approval". If the user enters an invalid forward-to
2223 ** then this messages gets nulled-out and the "Invalid Forward-to"
2224 ** message gets a value (see notification: Approve Requisition).
2225 */
2226 fnd_message.set_name ('PO','PO_WF_NOTIF_REQUIRES_APPROVAL');
2227 l_error_msg := fnd_message.get;
2228
2229 wf_engine.SetItemAttrText ( itemtype => itemType,
2230 itemkey => itemkey,
2231 aname => 'REQUIRES_APPROVAL_MSG' ,
2232 avalue => l_error_msg);
2233
2234 wf_engine.SetItemAttrText ( itemtype => itemType,
2235 itemkey => itemkey,
2236 aname => 'WRONG_FORWARD_TO_MSG' ,
2237 avalue => '');
2238
2239 /* Get the orignial authorization status from the document
2240 ** This has to be done here as we set the document status to
2241 ** IN-PROCESS after this.
2242 */
2243
2244 IF l_document_type='REQUISITION' THEN
2245
2246 select AUTHORIZATION_STATUS
2247 into l_authorization_status
2248 from po_requisition_headers_all
2249 where REQUISITION_HEADER_ID = l_document_id;
2250
2251 /* Bug#1810322: kagarwal
2252 ** Desc: If the original authorization status is IN PROCESS or PRE-APPROVED
2253 ** for Reqs then we need to store INCOMPLETE as the original authorization
2254 ** status.
2255 */
2256
2257 IF l_authorization_status IN ('IN PROCESS', 'PRE-APPROVED') THEN
2258 l_authorization_status := 'INCOMPLETE';
2259 END IF;
2260
2261 ELSIF l_document_type IN ('PO','PA') THEN
2262
2263 select AUTHORIZATION_STATUS, NVL(REVISION_NUM,0)
2264 into l_authorization_status, l_po_revision
2265 from po_headers_all
2266 where PO_HEADER_ID = l_document_id;
2267
2268 /* Bug#1810322: kagarwal
2269 ** Desc: If the original authorization status is IN PROCESS or PRE-APPROVED
2270 ** for PO/Releases then we need to store REQUIRES REAPPROVAL as the original
2271 ** authorization status if the revision number is greater than 0 else
2272 ** INCOMPLETE.
2273 */
2274
2275 IF l_authorization_status IN ('IN PROCESS', 'PRE-APPROVED') THEN
2276 IF l_po_revision > 0 THEN
2277 l_authorization_status := 'REQUIRES REAPPROVAL';
2278 ELSE
2279 l_authorization_status := 'INCOMPLETE';
2280 END IF;
2281 END IF;
2282
2283 ELSIF l_document_type = 'RELEASE' THEN
2284
2285 select AUTHORIZATION_STATUS, NVL(REVISION_NUM,0)
2286 into l_authorization_status, l_po_revision
2287 from po_releases_all
2288 where PO_RELEASE_ID = l_document_id;
2289
2290 IF l_authorization_status IN ('IN PROCESS', 'PRE-APPROVED') THEN
2291 IF l_po_revision > 0 THEN
2292 l_authorization_status := 'REQUIRES REAPPROVAL';
2293 ELSE
2294 l_authorization_status := 'INCOMPLETE';
2295 END IF;
2296 END IF;
2297
2298 END IF;
2299
2300 /* Set the doc authorization_status into original_autorization_status */
2301
2302 wf_engine.SetItemAttrText ( itemtype => itemType,
2303 itemkey => itemkey,
2304 aname => 'ORIG_AUTH_STATUS' ,
2305 avalue => l_authorization_status);
2306
2307
2308 /* Set PLSQL document attribute */
2309
2310 if l_document_type='REQUISITION' then
2311
2312 /* bug 2480327 notification UI enhancement
2313 add NID to PLSQL document attributes
2314 */
2315
2316 wf_engine.SetItemAttrText(itemtype => itemtype,
2317 itemkey => itemkey,
2318 aname => 'PO_REQ_APPROVE_MSG',
2319 avalue =>
2320 'PLSQL:PO_WF_REQ_NOTIFICATION.GET_PO_REQ_APPROVE_MSG/'||
2321 itemtype||':'||
2322 itemkey||':'||
2323 '&'||'#NID');
2324
2325 wf_engine.SetItemAttrText(itemtype => itemtype,
2326 itemkey => itemkey,
2327 aname => 'PO_REQ_APPROVED_MSG',
2328 avalue =>
2329 'PLSQL:PO_WF_REQ_NOTIFICATION.GET_PO_REQ_APPROVED_MSG/'||
2330 itemtype||':'||
2331 itemkey||':'||
2332 '&'||'#NID');
2333
2334 wf_engine.SetItemAttrText(itemtype => itemtype,
2335 itemkey => itemkey,
2336 aname => 'PO_REQ_NO_APPROVER_MSG',
2337 avalue =>
2338 'PLSQL:PO_WF_REQ_NOTIFICATION.GET_PO_REQ_NO_APPROVER_MSG/'||
2339 itemtype||':'||
2340 itemkey||':'||
2341 '&'||'#NID');
2342
2343 wf_engine.SetItemAttrText(itemtype => itemtype,
2344 itemkey => itemkey,
2345 aname => 'PO_REQ_REJECT_MSG',
2346 avalue =>
2347 'PLSQL:PO_WF_REQ_NOTIFICATION.GET_PO_REQ_REJECT_MSG/'||
2348 itemtype||':'||
2349 itemkey||':'||
2350 '&'||'#NID');
2351
2352 wf_engine.SetItemAttrText(itemtype => itemtype,
2353 itemkey => itemkey,
2354 aname => 'REQ_LINES_DETAILS',
2355 avalue =>
2356 'PLSQL:PO_WF_REQ_NOTIFICATION.GET_REQ_LINES_DETAILS/'||
2357 itemtype||':'||
2358 itemkey);
2359
2360 wf_engine.SetItemAttrText(itemtype => itemtype,
2361 itemkey => itemkey,
2362 aname => 'ACTION_HISTORY',
2363 avalue =>
2364 'PLSQL:PO_WF_REQ_NOTIFICATION.GET_ACTION_HISTORY/'||
2365 itemtype||':'||
2366 itemkey);
2367
2368 elsif l_document_type IN ('PO', 'PA', 'RELEASE') then
2369
2370 wf_engine.SetItemAttrText(itemtype => itemtype,
2371 itemkey => itemkey,
2372 aname => 'PO_APPROVE_MSG',
2373 avalue => 'PLSQL:PO_WF_PO_NOTIFICATION.GET_PO_APPROVE_MSG/' ||
2374 itemtype || ':' || itemkey);
2375
2376 -- <BUG 7006113>
2377 wf_engine.SetItemAttrText(itemtype => itemtype,
2378 itemkey => itemkey,
2379 aname => 'PO_LINES_DETAILS',
2380 avalue => 'PLSQLCLOB:PO_WF_PO_NOTIFICATION.GET_PO_LINES_DETAILS/'||
2381 itemtype||':'|| itemkey);
2382
2383 wf_engine.SetItemAttrText(itemtype => itemtype,
2384 itemkey => itemkey,
2385 aname => 'ACTION_HISTORY',
2386 avalue => 'PLSQL:PO_WF_PO_NOTIFICATION.GET_ACTION_HISTORY/'||
2387 itemtype||':'|| itemkey);
2388
2389 end if;
2390
2391 --Bug 6164753
2392 l_external_url := fnd_profile.value('POS_EXTERNAL_URL');
2393
2394 PO_WF_UTIL_PKG.SetItemAttrText ( itemtype => itemtype,
2395 itemkey => itemkey,
2396 aname => '#WFM_HTMLAGENT',
2397 avalue => l_external_url);
2398 --Bug 6164753
2399
2400
2401 --
2402 resultout := wf_engine.eng_completed || ':' || 'ACTIVITY_PERFORMED';
2403 --
2404
2405 x_progress := 'PO_REQAPPROVAL_INIT1.Set_Startup_Values: 03'||
2406 'Open Form Command= ' || l_open_form;
2407 IF (g_po_wf_debug = 'Y') THEN
2408 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
2409 END IF;
2410
2411 EXCEPTION
2412
2413 WHEN OTHERS THEN
2414 l_doc_string := PO_REQAPPROVAL_INIT1.get_error_doc(itemType, itemkey);
2415 l_preparer_user_name := PO_REQAPPROVAL_INIT1.get_preparer_user_name(itemType, itemkey);
2416 wf_core.context('PO_REQAPPROVAL_INIT1','Set_Startup_Values',x_progress);
2417 PO_REQAPPROVAL_INIT1.send_error_notif(itemType, itemkey, l_preparer_user_name, l_doc_string, sqlerrm, 'PO_REQAPPROVAL_INIT1.SET_STARTUP_VALUES');
2418 raise;
2419
2420 END Set_Startup_Values;
2421
2422
2423 --
2424 -- Get_Req_Attributes
2425 -- Get the requisition values on the doc header and assigns then to workflow attributes
2426 --
2427 procedure Get_Req_Attributes( itemtype in varchar2,
2428 itemkey in varchar2,
2429 actid in number,
2430 funcmode in varchar2,
2431 resultout out NOCOPY varchar2 ) is
2432 l_requisition_header_id NUMBER;
2433 l_authorization_status varchar2(25);
2434 l_orgid number;
2435 x_progress varchar2(100);
2436
2437 l_doc_string varchar2(200);
2438 l_preparer_user_name varchar2(100);
2439
2440 BEGIN
2441
2442 x_progress := 'PO_REQAPPROVAL_INIT1.Get_Req_Attributes: 01';
2443 IF (g_po_wf_debug = 'Y') THEN
2444 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
2445 END IF;
2446
2447
2448 -- Do nothing in cancel or timeout mode
2449 --
2450 if (funcmode <> wf_engine.eng_run) then
2451
2452 resultout := wf_engine.eng_null;
2453 return;
2454
2455 end if;
2456
2457 /* Bug# 2377333
2458 ** Setting application context
2459 */
2460
2461 --Context Setting Revamp
2462 /* PO_REQAPPROVAL_INIT1.Set_doc_mgr_context(itemtype, itemkey); */
2463
2464
2465 l_orgid := wf_engine.GetItemAttrNumber (itemtype => itemtype,
2466 itemkey => itemkey,
2467 aname => 'ORG_ID');
2468
2469 IF l_orgid is NOT NULL THEN
2470
2471 PO_MOAC_UTILS_PVT.set_org_context(l_orgid) ; -- <R12 MOAC>
2472
2473 END IF;
2474
2475 l_requisition_header_id := wf_engine.GetItemAttrNumber (itemtype => itemtype,
2476 itemkey => itemkey,
2477 aname => 'DOCUMENT_ID');
2478
2479
2480 GetReqAttributes(l_requisition_header_id,itemtype,itemkey);
2481
2482 --
2483 resultout := wf_engine.eng_completed || ':' || 'ACTIVITY_PERFORMED';
2484 --
2485 x_progress := 'PO_REQAPPROVAL_INIT1.Get_Req_Attributes: 02';
2486 IF (g_po_wf_debug = 'Y') THEN
2487 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
2488 END IF;
2489
2490
2491 EXCEPTION
2492
2493 WHEN OTHERS THEN
2494 l_doc_string := PO_REQAPPROVAL_INIT1.get_error_doc(itemType, itemkey);
2495 l_preparer_user_name := PO_REQAPPROVAL_INIT1.get_preparer_user_name(itemType, itemkey);
2496 wf_core.context('PO_REQAPPROVAL_INIT1','Get_Req_Attributes',x_progress);
2497 PO_REQAPPROVAL_INIT1.send_error_notif(itemType, itemkey, l_preparer_user_name, l_doc_string, sqlerrm, 'PO_REQAPPROVAL_INIT1.GET_REQ_ATTRIBUTES');
2498 raise;
2499
2500 END Get_Req_Attributes;
2501
2502 -- set_doc_stat_preapproved
2503 -- Added for WR4
2504 procedure set_doc_stat_preapproved(itemtype in varchar2,
2505 itemkey in varchar2,
2506 actid in number,
2507 funcmode in varchar2,
2508 resultout out NOCOPY varchar2 ) is
2509
2510 -- Bug 3326847: Change l_requisition_header_id to l_doc__header_id
2511 -- This is because the PO Approval WF will now call this as code as well.
2512 l_doc_header_id NUMBER;
2513 l_po_header_id NUMBER;
2514 l_doc_type VARCHAR2(14);
2515 l_authorization_stat VARCHAR2(25);
2516 l_note VARCHAR2(4000);
2517 l_orgid NUMBER;
2518 x_progress varchar2(100);
2519
2520 l_doc_string varchar2(200);
2521 l_preparer_user_name varchar2(100);
2522
2523 BEGIN
2524
2525 x_progress := 'PO_REQAPPROVAL_INIT1.set_doc_stat_preapproved: 01';
2526 --
2527 if (funcmode <> wf_engine.eng_run) then
2528
2529 resultout := wf_engine.eng_null;
2530 return;
2531
2532 end if;
2533
2534 -- Set the multi-org context
2535 l_orgid := wf_engine.GetItemAttrNumber (itemtype => itemtype,
2536 itemkey => itemkey,
2537 aname => 'ORG_ID');
2538
2539 IF l_orgid is NOT NULL THEN
2540
2541 PO_MOAC_UTILS_PVT.set_org_context(l_orgid) ; -- <R12 MOAC>
2542
2543 END IF;
2544
2545 -- Bug 3326847: Change l_requisition_header_id to l_doc_header_id
2546 l_doc_header_id := wf_engine.GetItemAttrNumber (itemtype => itemtype,
2547 itemkey => itemkey,
2548 aname => 'DOCUMENT_ID');
2549
2550 l_doc_type := wf_engine.GetItemAttrText (itemtype => itemtype,
2551 itemkey => itemkey,
2552 aname => 'DOCUMENT_TYPE');
2553
2554 l_authorization_stat := wf_engine.GetItemAttrText (itemtype => itemtype,
2555 itemkey => itemkey,
2556 aname => 'AUTHORIZATION_STATUS');
2557
2558 l_note := wf_engine.GetItemAttrText (itemtype => itemtype,
2559 itemkey => itemkey,
2560 aname => 'NOTE');
2561
2562 IF l_doc_type = 'REQUISITION' THEN
2563
2564 -- Bug 3326847: Change l_requisition_header_id to l_doc_header_id
2565 SetReqAuthStat(l_doc_header_id, itemtype,itemkey,l_note, 'PRE-APPROVED');
2566
2567 wf_engine.SetItemAttrText ( itemtype => itemtype,
2568 itemkey => itemkey,
2569 aname => 'AUTHORIZATION_STATUS',
2570 avalue => 'PRE-APPROVED');
2571
2572
2573 ELSIF l_doc_type IN ('PO', 'PA') THEN
2574
2575 -- Bug 3327847: Added code to set POs to 'PRE-APPROVED' status.
2576
2577 SetPOAuthStat(l_doc_header_id, itemtype, itemkey, l_note, 'PRE-APPROVED');
2578
2579 wf_engine.SetItemAttrText ( itemtype => itemtype,
2580 itemkey => itemkey,
2581 aname => 'AUTHORIZATION_STATUS',
2582 avalue => 'PRE-APPROVED');
2583
2584 ELSIF l_doc_type = 'RELEASE' THEN
2585
2586 -- Bug 3327847: Added code to set Releases to 'PRE-APPROVED' status.
2587
2588 SetRelAuthStat(l_doc_header_id, itemtype, itemkey, l_note, 'PRE-APPROVED');
2589
2590 wf_engine.SetItemAttrText ( itemtype => itemtype,
2591 itemkey => itemkey,
2592 aname => 'AUTHORIZATION_STATUS',
2593 avalue => 'PRE-APPROVED');
2594
2595 END IF;
2596 --
2597 resultout := wf_engine.eng_completed || ':' || 'ACTIVITY_PERFORMED';
2598 --
2599
2600 x_progress := 'PO_REQAPPROVAL_INIT1.set_doc_stat_inprocess: 02';
2601 IF (g_po_wf_debug = 'Y') THEN
2602 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
2603 END IF;
2604
2605
2606 EXCEPTION
2607 WHEN OTHERS THEN
2608 l_doc_string := PO_REQAPPROVAL_INIT1.get_error_doc(itemType, itemkey);
2609 l_preparer_user_name := PO_REQAPPROVAL_INIT1.get_preparer_user_name(itemType, itemkey);
2610 wf_core.context('PO_REQAPPROVAL_INIT1','set_doc_stat_preapproved',x_progress);
2611 PO_REQAPPROVAL_INIT1.send_error_notif(itemType, itemkey, l_preparer_user_name, l_doc_string, sqlerrm, 'PO_REQAPPROVAL_INIT1.SET_DOC_STAT_PREAPPROVED');
2612 raise;
2613
2614 END set_doc_stat_preapproved;
2615
2616
2617 -- set_doc_stat_inprocess
2618 -- Set the Doc status to In process and update the Doc Header table with the Itemtype
2619 -- and Itemkey indicating that this doc has been submitted to workflow.
2620 --
2621 procedure set_doc_stat_inprocess(itemtype in varchar2,
2622 itemkey in varchar2,
2623 actid in number,
2624 funcmode in varchar2,
2625 resultout out NOCOPY varchar2 ) is
2626
2627 l_document_id NUMBER;
2628 l_doc_type VARCHAR2(14);
2629 l_authorization_stat VARCHAR2(25);
2630 l_note VARCHAR2(4000);
2631 l_orgid NUMBER;
2632 x_progress varchar2(100);
2633
2634 l_doc_string varchar2(200);
2635 l_preparer_user_name varchar2(100);
2636
2637 BEGIN
2638
2639 x_progress := 'PO_REQAPPROVAL_INIT1.set_doc_stat_inprocess: 01';
2640 IF (g_po_wf_debug = 'Y') THEN
2641 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
2642 END IF;
2643
2644
2645 -- Do nothing in cancel or timeout mode
2646 --
2647 if (funcmode <> wf_engine.eng_run) then
2648
2649 resultout := wf_engine.eng_null;
2650 return;
2651
2652 end if;
2653
2654 -- Set the multi-org context
2655 l_orgid := wf_engine.GetItemAttrNumber (itemtype => itemtype,
2656 itemkey => itemkey,
2657 aname => 'ORG_ID');
2658
2659 IF l_orgid is NOT NULL THEN
2660
2661 PO_MOAC_UTILS_PVT.set_org_context(l_orgid) ; -- <R12 MOAC>
2662
2663 END IF;
2664
2665 l_document_id := wf_engine.GetItemAttrNumber (itemtype => itemtype,
2666 itemkey => itemkey,
2667 aname => 'DOCUMENT_ID');
2668
2669 l_doc_type := wf_engine.GetItemAttrText (itemtype => itemtype,
2670 itemkey => itemkey,
2671 aname => 'DOCUMENT_TYPE');
2672
2673 l_authorization_stat := wf_engine.GetItemAttrText (itemtype => itemtype,
2674 itemkey => itemkey,
2675 aname => 'AUTHORIZATION_STATUS');
2676
2677 l_note := wf_engine.GetItemAttrText (itemtype => itemtype,
2678 itemkey => itemkey,
2679 aname => 'NOTE');
2680
2681 /* If the Doc is INCOMPLETE or REJECTED (not IN PROCESS or PRE-APPROVED), then
2682 ** we want to set it to IN PROCESS and update the ITEMTYPE/ITEMKEY columns.
2683 ** If this is an upgrade to R11, then we need to update the ITEMTYPE/ITEMKEY columns
2684 ** Note that we only pickup docs is IN PROCESS or PRE-APPROVED in the upgrade step.
2685 */
2686 IF ( NVL(l_authorization_stat, 'INCOMPLETE') NOT IN ('IN PROCESS', 'PRE-APPROVED') )
2687 OR
2688 ( l_note = 'UPGRADE_TO_R11' ) THEN
2689
2690 IF l_doc_type = 'REQUISITION' THEN
2691
2692 SetReqAuthStat(l_document_id, itemtype,itemkey,l_note, 'IN PROCESS');
2693
2694 ELSIF l_doc_type IN ('PO', 'PA') THEN
2695
2696 SetPOAuthStat(l_document_id, itemtype,itemkey,l_note, 'IN PROCESS');
2697
2698 -- <HTML Agreement R12 START>
2699 -- Release functional lock, if needed
2700
2701 x_progress := 'PO_REQAPPROVAL_INIT1.set_doc_stat_inprocess: 02 unlock document';
2702 IF (g_po_wf_debug = 'Y') THEN
2703 PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
2704 END IF;
2705
2706
2707 unlock_document
2708 ( p_po_header_id => l_document_id);
2709
2710 -- <HTML Agreement R12 END>
2711
2712
2713 ELSIF l_doc_type = 'RELEASE' THEN
2714
2715 SetRelAuthStat(l_document_id, itemtype,itemkey,l_note, 'IN PROCESS');
2716
2717 END IF;
2718
2719 wf_engine.SetItemAttrText ( itemtype => itemtype,
2720 itemkey => itemkey,
2721 aname => 'AUTHORIZATION_STATUS',
2722 avalue => 'IN PROCESS' );
2723
2724
2725
2726 END IF;
2727
2728 --
2729 resultout := wf_engine.eng_completed || ':' || 'ACTIVITY_PERFORMED';
2730 --
2731
2732 x_progress := 'PO_REQAPPROVAL_INIT1.set_doc_stat_inprocess: 02';
2733 IF (g_po_wf_debug = 'Y') THEN
2734 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
2735 END IF;
2736
2737
2738 EXCEPTION
2739 WHEN OTHERS THEN
2740 l_doc_string := PO_REQAPPROVAL_INIT1.get_error_doc(itemType, itemkey);
2741 l_preparer_user_name := PO_REQAPPROVAL_INIT1.get_preparer_user_name(itemType, itemkey);
2742 wf_core.context('PO_REQAPPROVAL_INIT1','set_doc_stat_inprocess',x_progress);
2743 PO_REQAPPROVAL_INIT1.send_error_notif(itemType, itemkey, l_preparer_user_name, l_doc_string, sqlerrm, 'PO_REQAPPROVAL_INIT1.SET_DOC_STAT_INPROCESS');
2744 raise;
2745
2746 END set_doc_stat_inprocess;
2747
2748 --
2749 procedure set_doc_to_originalstat(itemtype in varchar2,
2750 itemkey in varchar2,
2751 actid in number,
2752 funcmode in varchar2,
2753 resultout out NOCOPY varchar2 ) is
2754
2755 l_orig_auth_stat VARCHAR2(25);
2756 l_auth_stat VARCHAR2(25);
2757 l_requisition_header_id NUMBER;
2758 l_po_header_id NUMBER;
2759 l_doc_id NUMBER;
2760 l_doc_type VARCHAR2(14);
2761 l_doc_subtype VARCHAR2(25);
2762 l_orgid NUMBER;
2763 x_progress varchar2(200);
2764
2765 l_doc_string varchar2(200);
2766 l_preparer_user_name varchar2(100);
2767
2768 BEGIN
2769
2770 x_progress := 'PO_REQAPPROVAL_INIT1.set_doc_to_originalstat: 01';
2771 IF (g_po_wf_debug = 'Y') THEN
2772 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
2773 END IF;
2774
2775
2776 -- Do nothing in cancel or timeout mode
2777 --
2778 if (funcmode <> wf_engine.eng_run) then
2779
2780 resultout := wf_engine.eng_null;
2781 return;
2782
2783 end if;
2784
2785 -- Set the multi-org context
2786 l_orgid := wf_engine.GetItemAttrNumber (itemtype => itemtype,
2787 itemkey => itemkey,
2788 aname => 'ORG_ID');
2789
2790 IF l_orgid is NOT NULL THEN
2791
2792 PO_MOAC_UTILS_PVT.set_org_context(l_orgid) ; -- <R12 MOAC>
2793
2794 END IF;
2795
2796 l_orig_auth_stat := wf_engine.GetItemAttrText (itemtype => itemtype,
2797 itemkey => itemkey,
2798 aname => 'ORIG_AUTH_STATUS');
2799
2800 l_doc_type := wf_engine.GetItemAttrText (itemtype => itemtype,
2801 itemkey => itemkey,
2802 aname => 'DOCUMENT_TYPE');
2803
2804 l_doc_subtype := wf_engine.GetItemAttrText(itemtype => itemtype,
2805 itemkey => itemkey,
2806 aname => 'DOCUMENT_SUBTYPE');
2807
2808 l_doc_id := wf_engine.GetItemAttrNumber (itemtype => itemtype,
2809 itemkey => itemkey,
2810 aname => 'DOCUMENT_ID');
2811
2812 /* If the doc is APPROVED then don't reset the status. We should
2813 ** not run into this case. But this is to prevent any problems
2814 */
2815 IF l_doc_type = 'REQUISITION' THEN
2816
2817 select NVL(authorization_status, 'INCOMPLETE') into l_auth_stat
2818 from PO_REQUISITION_HEADERS
2819 where requisition_header_id = l_doc_id;
2820
2821 IF l_auth_stat <> 'APPROVED' THEN
2822 SetReqAuthStat(l_doc_id, itemtype,itemkey,NULL, l_orig_auth_stat);
2823 END IF;
2824
2825 ELSIF l_doc_type IN ('PO', 'PA') THEN
2826
2827 select NVL(authorization_status,'INCOMPLETE') into l_auth_stat
2828 from PO_HEADERS
2829 where po_header_id = l_doc_id;
2830
2831 IF l_auth_stat <> 'APPROVED' THEN
2832 SetPOAuthStat(l_doc_id, itemtype,itemkey,NULL, l_orig_auth_stat );
2833 END IF;
2834
2835 ELSIF l_doc_type = 'RELEASE' THEN
2836
2837 select NVL(authorization_status,'INCOMPLETE') into l_auth_stat
2838 from PO_RELEASES
2839 where po_release_id = l_doc_id;
2840
2841 IF l_auth_stat <> 'APPROVED' THEN
2842 SetRelAuthStat(l_doc_id, itemtype,itemkey,NULL, l_orig_auth_stat );
2843 END IF;
2844
2845 END IF;
2846
2847 IF l_auth_stat <> 'APPROVED' THEN
2848
2849 wf_engine.SetItemAttrText ( itemtype => itemtype,
2850 itemkey => itemkey,
2851 aname => 'AUTHORIZATION_STATUS',
2852 avalue => l_orig_auth_stat);
2853
2854 END IF;
2855
2856 x_progress := 'PO_REQAPPROVAL_INIT1.set_doc_to_originalstat: 02' ||
2857 ' Auth_status= ' || l_auth_stat || ', Orig_auth_stat= ' || l_orig_auth_stat;
2858 IF (g_po_wf_debug = 'Y') THEN
2859 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
2860 END IF;
2861
2862
2863 -- Bug 3845048: Added the code to update the action history with 'no action'
2864 -- so that the action history code is completed properly when the document
2865 -- is returned to the submitter, in case of no approver found or time out
2866
2867 x_progress := 'PO_REQAPPROVAL_INIT1.set_doc_to_originalstat: 03' || 'Update Action History'
2868 || 'Action Code = No Action';
2869 IF (g_po_wf_debug = 'Y') THEN
2870 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
2871 END IF;
2872 /* This was added for bug 3845048.
2873 As part of fix 5691965 moving this code to prior location in approval wf.
2874 UpdateActionHistory(p_doc_id => l_doc_id,
2875 p_doc_type => l_doc_type,
2876 p_doc_subtype => l_doc_subtype,
2877 p_action => 'NO ACTION'
2878 ) ;
2879 */
2880 --
2881 resultout := wf_engine.eng_completed || ':' || 'ACTIVITY_PERFORMED';
2882 --
2883
2884 EXCEPTION
2885 WHEN OTHERS THEN
2886 l_doc_string := PO_REQAPPROVAL_INIT1.get_error_doc(itemType, itemkey);
2887 l_preparer_user_name := PO_REQAPPROVAL_INIT1.get_preparer_user_name(itemType, itemkey);
2888 wf_core.context('PO_REQAPPROVAL_INIT1','set_doc_stat_inprocess',x_progress);
2889 PO_REQAPPROVAL_INIT1.send_error_notif(itemType, itemkey, l_preparer_user_name, l_doc_string, sqlerrm, 'PO_REQAPPROVAL_INIT1.SET_DOC_STAT_INPROCESS');
2890 raise;
2891
2892 END set_doc_to_originalstat;
2893
2894 -- Register_doc_submitted
2895 --
2896 -- Update the DOC HEADER with the Workflow Itemtype and ItemKey
2897 --
2898 procedure Register_doc_submitted(itemtype in varchar2,
2899 itemkey in varchar2,
2900 actid in number,
2901 funcmode in varchar2,
2902 resultout out NOCOPY varchar2 ) is
2903 l_doc_id NUMBER;
2904 l_doc_type VARCHAR2(25);
2905 l_authorization_stat VARCHAR2(25);
2906 l_orgid NUMBER;
2907 x_progress varchar2(100);
2908
2909 l_doc_string varchar2(200);
2910 l_preparer_user_name varchar2(100);
2911
2912 BEGIN
2913
2914 x_progress := 'PO_REQAPPROVAL_INIT1.Register_doc_submitted: 01';
2915 IF (g_po_wf_debug = 'Y') THEN
2916 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
2917 END IF;
2918
2919
2920 -- Do nothing in cancel or timeout mode
2921 --
2922 if (funcmode <> wf_engine.eng_run) then
2923
2924 resultout := wf_engine.eng_null;
2925 return;
2926
2927 end if;
2928
2929 -- Set the multi-org context
2930 l_orgid := wf_engine.GetItemAttrNumber (itemtype => itemtype,
2931 itemkey => itemkey,
2932 aname => 'ORG_ID');
2933
2934 IF l_orgid is NOT NULL THEN
2935
2936 PO_MOAC_UTILS_PVT.set_org_context(l_orgid) ; -- <R12 MOAC>
2937
2938 END IF;
2939
2940 l_doc_id := wf_engine.GetItemAttrText (itemtype => itemtype,
2941 itemkey => itemkey,
2942 aname => 'DOCUMENT_ID');
2943
2944 l_doc_type := wf_engine.GetItemAttrText (itemtype => itemtype,
2945 itemkey => itemkey,
2946 aname => 'DOCUMENT_TYPE');
2947
2948 IF l_doc_type = 'REQUISITION' THEN
2949
2950 UpdtReqItemtype(itemtype,itemkey, l_doc_id);
2951
2952 ELSIF l_doc_type IN ('PO', 'PA') THEN
2953
2954 UpdtPOItemtype(itemtype,itemkey, l_doc_id );
2955
2956 ELSIF l_doc_type = 'RELEASE' THEN
2957
2958 UpdtRelItemtype(itemtype,itemkey, l_doc_id);
2959
2960 END IF;
2961
2962
2963 --
2964 resultout := wf_engine.eng_completed || ':' || 'ACTIVITY_PERFORMED';
2965 --
2966
2967 x_progress := 'PO_REQAPPROVAL_INIT1.Register_doc_submitted: 02';
2968 IF (g_po_wf_debug = 'Y') THEN
2969 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
2970 END IF;
2971
2972 EXCEPTION
2973 WHEN OTHERS THEN
2974 l_doc_string := PO_REQAPPROVAL_INIT1.get_error_doc(itemType, itemkey);
2975 l_preparer_user_name := PO_REQAPPROVAL_INIT1.get_preparer_user_name(itemType, itemkey);
2976 wf_core.context('PO_REQAPPROVAL_INIT1','Register_doc_submitted',x_progress);
2977 PO_REQAPPROVAL_INIT1.send_error_notif(itemType, itemkey, l_preparer_user_name, l_doc_string, sqlerrm, 'PO_REQAPPROVAL_INIT1.REGISTER_DOC_SUBMITTED');
2978 raise;
2979
2980 END Register_doc_submitted;
2981
2982 --
2983 -- can_owner_approve
2984 -- Get the requisition values on the doc header and assigns then to workflow attributes
2985 --
2986 procedure can_owner_approve(itemtype in varchar2,
2987 itemkey in varchar2,
2988 actid in number,
2989 funcmode in varchar2,
2990 resultout out NOCOPY varchar2 ) is
2991
2992 l_document_type varchar2(25);
2993 l_document_id number;
2994 l_orgid number;
2995 x_CanOwnerApproveFlag VARCHAR2(1);
2996 l_interface_source VARCHAR2(30);
2997 x_progress varchar2(100);
2998
2999 l_doc_string varchar2(200);
3000 l_preparer_user_name varchar2(100);
3001
3002 BEGIN
3003
3004 x_progress := 'PO_REQAPPROVAL_INIT1.can_owner_approve: 01';
3005 IF (g_po_wf_debug = 'Y') THEN
3006 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
3007 END IF;
3008
3009
3010 -- Do nothing in cancel or timeout mode
3011 --
3012 if (funcmode <> wf_engine.eng_run) then
3013
3014 resultout := wf_engine.eng_null;
3015 return;
3016
3017 end if;
3018
3019 l_interface_source := wf_engine.GetItemAttrText (itemtype => itemtype,
3020 itemkey => itemkey,
3021 aname => 'INTERFACE_SOURCE_CODE');
3022
3023 /* For one time upgrade of notifications for the client, we want to
3024 ** follow a certain path in the workflow. We do not want to go through
3025 ** the VERIFY AUTHORITY path. Therefore, set the RESULT to N
3026 */
3027 IF NVL(l_interface_source,'X') = 'ONE_TIME_UPGRADE' THEN
3028 --
3029 resultout := wf_engine.eng_completed || ':' || 'N';
3030 --
3031 ELSE
3032
3033 l_document_type := wf_engine.GetItemAttrText (itemtype => itemtype,
3034 itemkey => itemkey,
3035 aname => 'DOCUMENT_TYPE');
3036 l_document_id := wf_engine.GetItemAttrNumber (itemtype => itemtype,
3037 itemkey => itemkey,
3038 aname => 'DOCUMENT_ID');
3039
3040 -- Set the multi-org context
3041 l_orgid := wf_engine.GetItemAttrNumber (itemtype => itemtype,
3042 itemkey => itemkey,
3043 aname => 'ORG_ID');
3044
3045 IF l_orgid is NOT NULL THEN
3046
3047 PO_MOAC_UTILS_PVT.set_org_context(l_orgid) ; -- <R12 MOAC>
3048
3049 END IF;
3050
3051 PO_REQAPPROVAL_INIT1.GetCanOwnerApprove(itemtype, itemkey, x_CanOwnerApproveFlag);
3052
3053 --
3054 resultout := wf_engine.eng_completed || ':' || x_CanOwnerApproveFlag ;
3055 --
3056
3057 END IF;
3058
3059 x_progress := 'PO_REQAPPROVAL_INIT1.can_owner_approve: 02';
3060 IF (g_po_wf_debug = 'Y') THEN
3061 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
3062 END IF;
3063
3064 EXCEPTION
3065 WHEN OTHERS THEN
3066 l_doc_string := PO_REQAPPROVAL_INIT1.get_error_doc(itemType, itemkey);
3067 l_preparer_user_name := PO_REQAPPROVAL_INIT1.get_preparer_user_name(itemType, itemkey);
3068 wf_core.context('PO_REQAPPROVAL_INIT1','can_owner_approve',x_progress);
3069 PO_REQAPPROVAL_INIT1.send_error_notif(itemType, itemkey, l_preparer_user_name, l_doc_string, sqlerrm, 'PO_REQAPPROVAL_INIT1.CAN_OWNER_APPROVE');
3070 raise;
3071
3072 END can_owner_approve;
3073
3074 --
3075 -- Is_doc_preapproved
3076 -- Is document status pre-approved
3077 --
3078 procedure Is_doc_preapproved(itemtype in varchar2,
3079 itemkey in varchar2,
3080 actid in number,
3081 funcmode in varchar2,
3082 resultout out NOCOPY varchar2 ) is
3083
3084 l_auth_stat varchar2(25);
3085 l_doc_type varchar2(25);
3086 l_doc_id number;
3087 l_orgid number;
3088 x_progress varchar2(200);
3089
3090 l_doc_string varchar2(200);
3091 l_preparer_user_name varchar2(100);
3092
3093 BEGIN
3094
3095 x_progress := 'PO_REQAPPROVAL_INIT1.Is_doc_preapproved: 01';
3096 IF (g_po_wf_debug = 'Y') THEN
3097 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
3098 END IF;
3099
3100
3101 -- Do nothing in cancel or timeout mode
3102 --
3103 if (funcmode <> wf_engine.eng_run) then
3104
3105 resultout := wf_engine.eng_null;
3106 return;
3107
3108 end if;
3109
3110 /* Bug# 2353153
3111 ** Setting application context
3112 */
3113
3114 --Context Setting Revamp
3115 /* PO_REQAPPROVAL_INIT1.Set_doc_mgr_context(itemtype, itemkey); */
3116
3117 l_doc_type := wf_engine.GetItemAttrText (itemtype => itemtype,
3118 itemkey => itemkey,
3119 aname => 'DOCUMENT_TYPE');
3120
3121 l_doc_id := wf_engine.GetItemAttrNumber (itemtype => itemtype,
3122 itemkey => itemkey,
3123 aname => 'DOCUMENT_ID');
3124
3125 -- Bug 762194: Need to set multi-org context.
3126
3127 l_orgid := wf_engine.GetItemAttrNumber (itemtype => itemtype,
3128 itemkey => itemkey,
3129 aname => 'ORG_ID');
3130
3131 IF l_orgid is NOT NULL THEN
3132
3133 PO_MOAC_UTILS_PVT.set_org_context(l_orgid) ; -- <R12 MOAC>
3134
3135 END IF;
3136
3137
3138 IF l_doc_type = 'REQUISITION' THEN
3139
3140 select NVL(authorization_status, 'INCOMPLETE') into l_auth_stat
3141 from PO_REQUISITION_HEADERS
3142 where requisition_header_id = l_doc_id;
3143
3144 ELSIF l_doc_type IN ('PO', 'PA') THEN
3145
3146 select NVL(authorization_status,'INCOMPLETE') into l_auth_stat
3147 from PO_HEADERS
3148 where po_header_id = l_doc_id;
3149
3150 ELSIF l_doc_type = 'RELEASE' THEN
3151
3152 select NVL(authorization_status,'INCOMPLETE') into l_auth_stat
3153 from PO_RELEASES
3154 where po_release_id = l_doc_id;
3155
3156 END IF;
3157
3158
3159 IF l_auth_stat = 'PRE-APPROVED' THEN
3160
3161 --
3162 resultout := wf_engine.eng_completed || ':' || 'Y' ;
3163 --
3164
3165 ELSIF l_auth_stat = 'IN PROCESS' THEN
3166 --
3167 resultout := wf_engine.eng_completed || ':' || 'N' ;
3168 --
3169
3170 ELSE
3171 -- The doc is either APPROVED, INCOMPLETE or REJECTED. This invalid, therefore
3172 -- we will exit the workflow with an INVALID ACTION status.
3173 resultout := wf_engine.eng_completed || ':' || 'INVALID_AUTH_STATUS' ;
3174 --
3175
3176 END IF;
3177
3178 x_progress := 'PO_REQAPPROVAL_INIT1.Is_doc_preapproved: 02' ||
3179 ' Authorization_status= ' || l_auth_stat ;
3180 IF (g_po_wf_debug = 'Y') THEN
3181 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
3182 END IF;
3183
3184
3185 EXCEPTION
3186 WHEN OTHERS THEN
3187 l_doc_string := PO_REQAPPROVAL_INIT1.get_error_doc(itemType, itemkey);
3188 l_preparer_user_name := PO_REQAPPROVAL_INIT1.get_preparer_user_name(itemType, itemkey);
3189 wf_core.context('PO_REQAPPROVAL_INIT1','Is_doc_preapproved',x_progress);
3190 PO_REQAPPROVAL_INIT1.send_error_notif(itemType, itemkey, l_preparer_user_name, l_doc_string, sqlerrm, 'PO_REQAPPROVAL_INIT1.IS_DOC_PREAPPROVED');
3191 raise;
3192
3193 END Is_doc_preapproved;
3194
3195
3196 --
3197 --
3198 -- Ins_actionhist_submit
3199 -- When we start the workflow, if the document status is NOT 'IN PROCESS' or
3200 -- PRE-APPROVED, then insert a SUBMIT action row into PO_ACTION_HISTORY
3201 -- to signal the submission of the document for approval.
3202 -- Also, insert an additional row with a NULL ACTION_CODE (to simulate a
3203 -- forward-to since the DOC status is IN PROCESS. The code in the DOC-MANAGER
3204 -- looks for this row.
3205 --
3206 procedure Ins_actionhist_submit(itemtype in varchar2,
3207 itemkey in varchar2,
3208 actid in number,
3209 funcmode in varchar2,
3210 resultout out NOCOPY varchar2 ) is
3211
3212 l_doc_id number;
3213 l_doc_type varchar2(25);
3214 l_doc_subtype varchar2(25);
3215 l_note PO_ACTION_HISTORY.note%TYPE;
3216 l_employee_id number;
3217 l_orgid number;
3218
3219 x_progress varchar2(100);
3220
3221 l_doc_string varchar2(200);
3222 l_preparer_user_name varchar2(100);
3223
3224 l_path_id number;
3225
3226 BEGIN
3227
3228 x_progress := 'PO_REQAPPROVAL_INIT1.Ins_actionhist_submit: 01';
3229 IF (g_po_wf_debug = 'Y') THEN
3230 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
3231 END IF;
3232
3233
3234 -- Do nothing in cancel or timeout mode
3235 --
3236 if (funcmode <> wf_engine.eng_run) then
3237
3238 resultout := wf_engine.eng_null;
3239 return;
3240
3241 end if;
3242
3243 l_doc_id := wf_engine.GetItemAttrNumber (itemtype => itemtype,
3244 itemkey => itemkey,
3245 aname => 'DOCUMENT_ID');
3246
3247 l_doc_type := wf_engine.GetItemAttrText (itemtype => itemtype,
3248 itemkey => itemkey,
3249 aname => 'DOCUMENT_TYPE');
3250
3251 l_doc_subtype := wf_engine.GetItemAttrText (itemtype => itemtype,
3252 itemkey => itemkey,
3253 aname => 'DOCUMENT_SUBTYPE');
3254
3255 /* Bug 1100247 Amitabh
3256 ** Desc:Initially the Workflow sets the preparer_id, approver_empid
3257 ** as the value passed to it by the POXAPAPC.pld file. As it always
3258 ** assumed that an Incomplete Requisition would get approved by
3259 ** preparer only. Then when it calls the GetReqAttributes()
3260 ** it would reget the preparer_id from the po_requisition_headers_all
3261 ** table hence if the preparer_id and approver_empid are different
3262 ** then the action history would be wrongly updated.
3263 **
3264 ** Modifying the parameter l_employee_id to be passed to
3265 ** InsertActionHistSubmit() from PREPARER_ID to
3266 ** APPROVER_EMPID.
3267 **
3268 ** Also modified the SetReqHdrAttributes() to also set the
3269 ** PREPARER_USER_NAME and PREPARER_DISPLAY_NAME.
3270 **
3271 */
3272
3273 l_employee_id := wf_engine.GetItemAttrNumber (itemtype => itemtype,
3274 itemkey => itemkey,
3275 aname => 'APPROVER_EMPID');
3276
3277 PO_WF_UTIL_PKG.SetItemAttrNumber (itemtype => itemtype,
3278 itemkey => itemkey,
3279 aname => 'SUBMITTER_ID',
3280 avalue => l_employee_id);
3281
3282 l_note := wf_engine.GetItemAttrText (itemtype => itemtype,
3283 itemkey => itemkey,
3284 aname => 'NOTE');
3285
3286 -- Set the multi-org context
3287 l_orgid := wf_engine.GetItemAttrNumber (itemtype => itemtype,
3288 itemkey => itemkey,
3289 aname => 'ORG_ID');
3290
3291 IF l_orgid is NOT NULL THEN
3292
3293 PO_MOAC_UTILS_PVT.set_org_context(l_orgid) ; -- <R12 MOAC>
3294
3295 END IF;
3296
3297 l_path_id := wf_engine.GetItemAttrNumber (itemtype => itemtype,
3298 itemkey => itemkey,
3299 aname => 'APPROVAL_PATH_ID');
3300
3301 PO_REQAPPROVAL_INIT1.InsertActionHistSubmit(itemtype,itemkey,l_doc_id, l_doc_type,
3302 l_doc_subtype, l_employee_id, 'SUBMIT', l_note, l_path_id);
3303
3304
3305 --
3306 resultout := wf_engine.eng_completed || ':' || 'ACTIVITY_PERFORMED' ;
3307 --
3308
3309
3310 x_progress := 'PO_REQAPPROVAL_INIT1.Ins_actionhist_submit: 02';
3311 IF (g_po_wf_debug = 'Y') THEN
3312 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
3313 END IF;
3314
3315 EXCEPTION
3316 WHEN OTHERS THEN
3317 l_doc_string := PO_REQAPPROVAL_INIT1.get_error_doc(itemType, itemkey);
3318 l_preparer_user_name := PO_REQAPPROVAL_INIT1.get_preparer_user_name(itemType, itemkey);
3319 wf_core.context('PO_REQAPPROVAL_INIT1','Ins_actionhist_submit',x_progress);
3320 PO_REQAPPROVAL_INIT1.send_error_notif(itemType, itemkey, l_preparer_user_name, l_doc_string, sqlerrm, 'PO_REQAPPROVAL_INIT1.INS_ACTIONHIST_SUBMIT');
3321 raise;
3322
3323 END Ins_actionhist_submit;
3324
3325 --
3326 -- Set_End_VerifyDoc_Passed
3327 -- Sets the value of the transition to PASSED_VERIFICATION to match the
3328 -- transition value for the VERIFY_REQUISITION Process
3329 --
3330 -- IN
3331 -- itemtype -- itemkey -- actid -- funcmode
3332 -- OUT
3333 -- Resultout
3334 -- - Activity Performed - Activity was completed without any errors.
3335 --
3336 procedure Set_End_VerifyDoc_Passed( itemtype in varchar2,
3337 itemkey in varchar2,
3338 actid in number,
3339 funcmode in varchar2,
3340 resultout out NOCOPY varchar2 ) is
3341
3342 BEGIN
3343
3344
3345 -- Do nothing in cancel or timeout mode
3346 --
3347 if (funcmode <> wf_engine.eng_run) then
3348
3349 resultout := wf_engine.eng_null;
3350 return;
3351
3352 end if;
3353
3354 --
3355 resultout := wf_engine.eng_completed || ':' || 'PASSED_VERIFICATION' ;
3356 --
3357
3358 END Set_End_VerifyDoc_Passed;
3359
3360 --
3361 -- Set_End_VerifyDoc_Passed
3362 -- Sets the value of the transition to PASSED_VERIFICATION to match the
3363 -- transition value for the VERIFY_REQUISITION Process
3364 --
3365 -- IN
3366 -- itemtype -- itemkey -- actid -- funcmode
3367 -- OUT
3368 -- Resultout
3369 -- - Activity Performed - Activity was completed without any errors.
3370 --
3371 procedure Set_End_VerifyDoc_Failed( itemtype in varchar2,
3372 itemkey in varchar2,
3373 actid in number,
3374 funcmode in varchar2,
3375 resultout out NOCOPY varchar2 ) is
3376
3377 BEGIN
3378
3379 -- Do nothing in cancel or timeout mode
3380 --
3381 if (funcmode <> wf_engine.eng_run) then
3382
3383 resultout := wf_engine.eng_null;
3384 return;
3385
3386 end if;
3387
3388 --
3389 resultout := wf_engine.eng_completed || ':' || 'FAILED_VERIFICATION' ;
3390 --
3391
3392 END Set_End_VerifyDoc_Failed;
3393
3394 --
3395 -- Set_End_Valid_Action
3396 -- Sets the value of the transition to VALID_ACTION to match the
3397 -- transition value for the APPROVE_REQUISITION, APPROVE_PO,
3398 -- APPROVE_AND_FORWARD_REQUISITION and APPROVE_AND_FORWARD_PO Processes.
3399 --
3400 -- IN
3401 -- itemtype -- itemkey -- actid -- funcmode
3402 -- OUT
3403 -- Resultout
3404 -- - VALID_ACTION
3405 --
3406 procedure Set_End_Valid_Action( itemtype in varchar2,
3407 itemkey in varchar2,
3408 actid in number,
3409 funcmode in varchar2,
3410 resultout out NOCOPY varchar2 ) is
3411
3412 x_progress varchar2(100);
3413 BEGIN
3414
3415 --
3416 resultout := wf_engine.eng_completed || ':' || 'VALID_ACTION' ;
3417 --
3418
3419 x_progress := 'PO_REQAPPROVAL_INIT1.Set_End_Valid_Action: RESULT=VALID_ACTION';
3420 IF (g_po_wf_debug = 'Y') THEN
3421 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
3422 END IF;
3423
3424 END Set_End_Valid_Action;
3425
3426 --
3427 -- Set_End_Invalid_Action
3428 -- Sets the value of the transition to VALID_ACTION to match the
3429 -- transition value for the APPROVE_REQUISITION, APPROVE_PO,
3430 -- APPROVE_AND_FORWARD_REQUISITION and APPROVE_AND_FORWARD_PO Processes.
3431 --
3432 -- IN
3433 -- itemtype -- itemkey -- actid -- funcmode
3434 -- OUT
3435 -- Resultout
3436 -- - VALID_ACTION
3437 --
3438 procedure Set_End_Invalid_Action( itemtype in varchar2,
3439 itemkey in varchar2,
3440 actid in number,
3441 funcmode in varchar2,
3442 resultout out NOCOPY varchar2 ) is
3443
3444 BEGIN
3445
3446 --
3447 resultout := wf_engine.eng_completed || ':' || 'INVALID_ACTION' ;
3448 --
3449
3450 END Set_End_Invalid_Action;
3451
3452 --
3453 -- Is_Interface_ReqImport
3454 -- IN
3455 -- itemtype -- itemkey -- actid -- funcmode
3456 -- OUT
3457 -- Resultout
3458 -- - Y/N
3459 -- Is the calling module REQ IMPORT. If it is, then we need to RESERVE the doc.
3460 -- Web Requisition come through REQ IMPORT.
3461 procedure Is_Interface_ReqImport( itemtype in varchar2,
3462 itemkey in varchar2,
3463 actid in number,
3464 funcmode in varchar2,
3465 resultout out NOCOPY varchar2 ) is
3466
3467 l_interface_source varchar2(25);
3468 BEGIN
3469
3470 l_interface_source := wf_engine.GetItemAttrText (itemtype => itemtype,
3471 itemkey => itemkey,
3472 aname => 'INTERFACE_SOURCE_CODE');
3473
3474 IF l_interface_source <> 'PO_FORM' THEN
3475
3476 --
3477 resultout := wf_engine.eng_completed || ':' || 'Y' ;
3478 --
3479 ELSE
3480 --
3481 resultout := wf_engine.eng_completed || ':' || 'N' ;
3482 --
3483 END IF;
3484
3485 END Is_Interface_ReqImport;
3486
3487 --
3488 -- Encumb_on_doc_unreserved
3489 -- IN
3490 -- itemtype -- itemkey -- actid -- funcmode
3491 -- OUT
3492 -- Resultout
3493 -- - Y/N
3494 -- If Encumbrance is ON and Document is NOT reserved, then return Y.
3495 -- We need to reserve the doc.
3496
3497 procedure Encumb_on_doc_unreserved( itemtype in varchar2,
3498 itemkey in varchar2,
3499 actid in number,
3500 funcmode in varchar2,
3501 resultout out NOCOPY varchar2 ) is
3502 l_document_type varchar2(25);
3503 l_document_subtype varchar2(25) := NULL;
3504 l_document_id number;
3505 l_orgid number;
3506
3507 x_progress varchar2(100);
3508
3509 l_doc_string varchar2(200);
3510 l_preparer_user_name varchar2(100);
3511
3512 BEGIN
3513
3514
3515 l_document_type := wf_engine.GetItemAttrText (itemtype => itemtype,
3516 itemkey => itemkey,
3517 aname => 'DOCUMENT_TYPE');
3518
3519 -- <ENCUMBRANCE FPJ START>
3520 -- Get the subtype for doc type other than requisition
3521
3522 if l_document_type <> 'REQUISITION' THEN
3523
3524 l_document_subtype := PO_WF_UTIL_PKG.GetItemAttrText (itemtype => itemtype,
3525 itemkey => itemkey,
3526 aname => 'DOCUMENT_SUBTYPE');
3527 end if;
3528
3529 -- <ENCUMBRANCE FPJ END>
3530
3531 l_document_id := wf_engine.GetItemAttrNumber (itemtype => itemtype,
3532 itemkey => itemkey,
3533 aname => 'DOCUMENT_ID');
3534
3535 l_orgid := wf_engine.GetItemAttrNumber (itemtype => itemtype,
3536 itemkey => itemkey,
3537 aname => 'ORG_ID');
3538
3539 IF l_orgid is NOT NULL THEN
3540
3541 PO_MOAC_UTILS_PVT.set_org_context(l_orgid) ; -- <R12 MOAC>
3542
3543 END IF;
3544
3545
3546 IF ( EncumbOn_DocUnreserved(
3547 p_doc_type => l_document_type,
3548 p_doc_subtype => l_document_subtype,
3549 p_doc_id => l_document_id)
3550 = 'Y' ) THEN
3551
3552 --
3553 resultout := wf_engine.eng_completed || ':' || 'Y' ;
3554 --
3555 x_progress := 'PO_REQAPPROVAL_INIT1.Encumb_on_doc_unreserved: 01';
3556 IF (g_po_wf_debug = 'Y') THEN
3557 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
3558 END IF;
3559
3560 ELSE
3561 --
3562 resultout := wf_engine.eng_completed || ':' || 'N' ;
3563 --
3564 x_progress := 'PO_REQAPPROVAL_INIT1.Encumb_on_doc_unreserved: 02';
3565 IF (g_po_wf_debug = 'Y') THEN
3566 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
3567 END IF;
3568
3569 END IF;
3570
3571 EXCEPTION
3572 WHEN OTHERS THEN
3573 l_doc_string := PO_REQAPPROVAL_INIT1.get_error_doc(itemType, itemkey);
3574 l_preparer_user_name := PO_REQAPPROVAL_INIT1.get_preparer_user_name(itemType, itemkey);
3575 wf_core.context('PO_REQAPPROVAL_INIT1.Encumb_on_doc_unreserved',x_progress);
3576 PO_REQAPPROVAL_INIT1.send_error_notif(itemType, itemkey, l_preparer_user_name, l_doc_string, sqlerrm, 'PO_REQAPPROVAL_INIT1.ENCUMB_ON_DOC_UNRESERVED');
3577 raise;
3578
3579 END Encumb_on_doc_unreserved;
3580
3581 --
3582 --
3583 -- RESERVE_AT_COMPLETION_CHECK
3584 -- IN
3585 -- itemtype -- itemkey -- actid -- funcmode
3586 -- OUT
3587 -- Resultout
3588 -- - Y/N
3589 -- If the reserve at completion flag is checked, then return Y.
3590
3591 procedure RESERVE_AT_COMPLETION_CHECK( itemtype in varchar2,
3592 itemkey in varchar2,
3593 actid in number,
3594 funcmode in varchar2,
3595 resultout out NOCOPY varchar2 ) is
3596
3597 l_reserve_at_compl varchar2(1);
3598 x_CanOwnerApproveFlag varchar2(1);
3599
3600 x_progress varchar2(100);
3601 l_doc_string varchar2(200);
3602 l_preparer_user_name varchar2(100);
3603
3604 BEGIN
3605
3606 /* Bug# 2234341: kagarwal
3607 ** Desc: The preparer cannot reserve a requisiton at the start of the
3608 ** approval workflow, if the preparer cannot approve and also the reserve
3609 ** at completion is No.
3610 ** The logic that follows here is that the owner/preparer is also an
3611 ** approver, if the preparer can approve is allowed.
3612 */
3613
3614 select nvl(fsp.reserve_at_completion_flag,'N') into l_reserve_at_compl
3615 from financials_system_parameters fsp;
3616
3617 PO_REQAPPROVAL_INIT1.GetCanOwnerApprove(itemtype, itemkey, x_CanOwnerApproveFlag);
3618
3619 IF ((l_reserve_at_compl = 'N' ) OR (x_CanOwnerApproveFlag = 'N')) THEN
3620
3621 --
3622 resultout := wf_engine.eng_completed || ':' || 'N' ;
3623 --
3624 x_progress := 'PO_REQAPPROVAL_INIT1.Encumb_on_doc_commit: 01';
3625 IF (g_po_wf_debug = 'Y') THEN
3626 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
3627 END IF;
3628
3629 ELSE
3630 --
3631 resultout := wf_engine.eng_completed || ':' || 'Y' ;
3632 --
3633 x_progress := 'PO_REQAPPROVAL_INIT1.Encumb_on_doc_commit: 02';
3634 IF (g_po_wf_debug = 'Y') THEN
3635 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
3636 END IF;
3637
3638 END IF;
3639
3640 EXCEPTION
3641 WHEN OTHERS THEN
3642 l_doc_string := PO_REQAPPROVAL_INIT1.get_error_doc(itemType, itemkey);
3643 l_preparer_user_name := PO_REQAPPROVAL_INIT1.get_preparer_user_name(itemType, itemkey);
3644 wf_core.context('PO_REQAPPROVAL_INIT1.Encumb_on_doc_unreserved',x_progress);
3645 PO_REQAPPROVAL_INIT1.send_error_notif(itemType, itemkey, l_preparer_user_name, l_doc_string, sqlerrm, 'PO_REQAPPROVAL_INIT1.RESERVE_AT_COMPLETION_CHECK');
3646 raise;
3647
3648 END RESERVE_AT_COMPLETION_CHECK;
3649
3650
3651 -- Remove_reminder_notif
3652 -- IN
3653 -- itemtype -- itemkey -- actid -- funcmode
3654 -- OUT
3655 -- Resultout
3656 --
3657 -- Remove the reminder notifications since this doc is now approved.
3658
3659 procedure Remove_reminder_notif( itemtype in varchar2,
3660 itemkey in varchar2,
3661 actid in number,
3662 funcmode in varchar2,
3663 resultout out NOCOPY varchar2 ) is
3664
3665 l_release_flag varchar2(1);
3666 l_orgid number;
3667 l_document_type varchar2(25);
3668 l_document_subtype varchar2(25);
3669 l_document_id number;
3670 l_wf_item_key varchar2(100);
3671 x_progress varchar2(300);
3672
3673 l_doc_string varchar2(200);
3674 l_preparer_user_name varchar2(100);
3675
3676 cursor po_cursor(p_header_id number) is
3677 select wf_item_key
3678 from po_headers
3679 where po_header_id= p_header_id;
3680
3681 cursor req_cursor(p_header_id number) is
3682 select wf_item_key
3683 from po_requisition_headers
3684 where requisition_header_id= p_header_id;
3685
3686 cursor rel_cursor(p_header_id number) is
3687 select wf_item_key
3688 from po_releases
3689 where po_release_id= p_header_id;
3690
3691 BEGIN
3692
3693 x_progress := 'PO_REQAPPROVAL_INIT1.Remove_reminder_notif: 01';
3694 IF (g_po_wf_debug = 'Y') THEN
3695 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
3696 END IF;
3697
3698 -- Do nothing in cancel or timeout mode
3699 --
3700 if (funcmode <> wf_engine.eng_run) then
3701
3702 resultout := wf_engine.eng_null;
3703 return;
3704
3705 end if;
3706 /* Bug #: 1384323 draising
3707 Forward fix of Bug # 1338325
3708 We need to set multi org context by getting it from the
3709 database rather rather than the org id attribute.
3710 */
3711
3712 /*
3713 l_orgid := wf_engine.GetItemAttrNumber (itemtype => itemtype,
3714 itemkey => itemkey,
3715 aname => 'ORG_ID');
3716
3717 IF l_orgid is NOT NULL THEN
3718
3719 PO_MOAC_UTILS_PVT.set_org_context(l_orgid) ; -- <R12 MOAC>
3720
3721 END IF;
3722 */
3723 l_document_type := wf_engine.GetItemAttrText (itemtype => itemtype,
3724 itemkey => itemkey,
3725 aname => 'DOCUMENT_TYPE');
3726 l_document_subtype := wf_engine.GetItemAttrText (itemtype => itemtype,
3727 itemkey => itemkey,
3728 aname => 'DOCUMENT_SUBTYPE');
3729 l_document_id := wf_engine.GetItemAttrNumber (itemtype => itemtype,
3730 itemkey => itemkey,
3731 aname => 'DOCUMENT_ID');
3732
3733 PO_REQAPPROVAL_INIT1.get_multiorg_context(l_document_type,l_document_id,l_orgid);
3734
3735 IF l_orgid is NOT NULL THEN
3736 PO_MOAC_UTILS_PVT.set_org_context(l_orgid) ; -- <R12 MOAC>
3737 wf_engine.SetItemAttrNumber (itemtype => itemtype ,
3738 itemkey => itemkey ,
3739 aname => 'ORG_ID' ,
3740 avalue => l_orgid );
3741 END IF;
3742
3743 /* End of fix for Bug # 1384323 */
3744 IF l_document_type = 'RELEASE' THEN
3745
3746 l_release_flag := 'Y';
3747
3748 ELSE
3749
3750 l_release_flag := 'N';
3751
3752 END IF;
3753
3754 /* Remove reminder notifications */
3755 PO_APPROVAL_REMINDER_SV. Cancel_Notif ( l_document_subtype,
3756 l_document_id,
3757 l_release_flag);
3758
3759 /* If the document has been previously submitted to workflow, and did not
3760 ** complete because of some error or some action such as Document being rejected,
3761 ** then notifications may have been issued to users.
3762 ** We need to remove those notifications once we submit the document to a
3763 ** new workflow run, so that the user is not confused.
3764 */
3765
3766 IF l_document_type='REQUISITION' THEN
3767
3768 open req_cursor(l_document_id);
3769 fetch req_cursor into l_wf_item_key;
3770 close req_cursor;
3771
3772 ELSIF l_document_type IN ('PO','PA') THEN
3773
3774 open po_cursor(l_document_id);
3775 fetch po_cursor into l_wf_item_key;
3776 close po_cursor;
3777
3778 ELSIF l_document_type = 'RELEASE' THEN
3779
3780 open rel_cursor(l_document_id);
3781 fetch rel_cursor into l_wf_item_key;
3782 close rel_cursor;
3783
3784 END IF;
3785
3786 IF l_wf_item_key is NOT NULL THEN
3787
3788 Close_Old_Notif(itemtype, l_wf_item_key);
3789
3790 END IF;
3791
3792 resultout := wf_engine.eng_completed ;
3793
3794 x_progress := 'PO_REQAPPROVAL_INIT1.Remove_reminder_notif: 02.';
3795 IF (g_po_wf_debug = 'Y') THEN
3796 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
3797 END IF;
3798
3799 EXCEPTION
3800 WHEN OTHERS THEN
3801 l_doc_string := PO_REQAPPROVAL_INIT1.get_error_doc(itemType, itemkey);
3802 l_preparer_user_name := PO_REQAPPROVAL_INIT1.get_preparer_user_name(itemType, itemkey);
3803 wf_core.context('PO_REQAPPROVAL_INIT1.Remove_reminder_notif',x_progress);
3804 PO_REQAPPROVAL_INIT1.send_error_notif(itemType, itemkey, l_preparer_user_name, l_doc_string, sqlerrm, 'PO_REQAPPROVAL_INIT1.REMOVE_REMINDER_NOTIF');
3805 raise;
3806
3807 END Remove_reminder_notif;
3808
3809
3810 procedure Print_Doc_Yes_No( itemtype in varchar2,
3811 itemkey in varchar2,
3812 actid in number,
3813 funcmode in varchar2,
3814 resultout out NOCOPY varchar2 ) is
3815 l_orgid number;
3816 l_print_doc varchar2(2);
3817 x_progress varchar2(300);
3818
3819 l_doc_string varchar2(200);
3820 l_preparer_user_name varchar2(100);
3821
3822 BEGIN
3823 x_progress := 'PO_REQAPPROVAL_INIT1.Print_Doc_Yes_No: 01';
3824 IF (g_po_wf_debug = 'Y') THEN
3825 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
3826 END IF;
3827
3828
3829 -- Do nothing in cancel or timeout mode
3830 --
3831 if (funcmode <> wf_engine.eng_run) then
3832
3833 resultout := wf_engine.eng_null;
3834 return;
3835
3836 end if;
3837
3838 l_print_doc := wf_engine.GetItemAttrText (itemtype => itemtype,
3839 itemkey => itemkey,
3840 aname => 'PRINT_DOCUMENT');
3841
3842 /* the value of l_print_doc should be Y or N */
3843 IF (nvl(l_print_doc,'N') <> 'Y') THEN
3844 l_print_doc := 'N';
3845 END IF;
3846
3847 --
3848 resultout := wf_engine.eng_completed || ':' || l_print_doc ;
3849 --
3850 x_progress := 'PO_REQAPPROVAL_INIT1.Print_Doc_Yes_No: 02. Result= ' || l_print_doc;
3851 IF (g_po_wf_debug = 'Y') THEN
3852 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
3853 END IF;
3854
3855 EXCEPTION
3856 WHEN OTHERS THEN
3857 l_doc_string := PO_REQAPPROVAL_INIT1.get_error_doc(itemType, itemkey);
3858 l_preparer_user_name := PO_REQAPPROVAL_INIT1.get_preparer_user_name(itemType, itemkey);
3859 wf_core.context('PO_REQAPPROVAL_INIT1.Print_Doc_Yes_No',x_progress);
3860 PO_REQAPPROVAL_INIT1.send_error_notif(itemType, itemkey, l_preparer_user_name, l_doc_string, sqlerrm, 'PO_REQAPPROVAL_INIT1.PRINT_DOC_YES_NO');
3861 raise;
3862
3863 END Print_Doc_Yes_No;
3864
3865
3866
3867
3868 -- DKC 10/10/99
3869 procedure Fax_Doc_Yes_No( itemtype in varchar2,
3870 itemkey in varchar2,
3871 actid in number,
3872 funcmode in varchar2,
3873 resultout out NOCOPY varchar2 ) is
3874 l_orgid number;
3875 l_fax_doc varchar2(2);
3876 x_progress varchar2(300);
3877
3878 l_doc_string varchar2(200);
3879 l_preparer_user_name varchar2(100);
3880
3881 BEGIN
3882 x_progress := 'PO_REQAPPROVAL_INIT1.Fax_Doc_Yes_No: 01';
3883 IF (g_po_wf_debug = 'Y') THEN
3884 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
3885 END IF;
3886
3887
3888 -- Do nothing in cancel or timeout mode
3889 --
3890 if (funcmode <> wf_engine.eng_run) then
3891
3892 resultout := wf_engine.eng_null;
3893 return;
3894
3895 end if;
3896
3897 l_fax_doc := wf_engine.GetItemAttrText (itemtype => itemtype,
3898 itemkey => itemkey,
3899 aname => 'FAX_DOCUMENT');
3900
3901 /* the value of l_fax_doc should be Y or N */
3902 IF (nvl(l_fax_doc,'N') <> 'Y') THEN
3903 l_fax_doc := 'N';
3904 END IF;
3905
3906 --
3907 resultout := wf_engine.eng_completed || ':' || l_fax_doc ;
3908 --
3909 x_progress := 'PO_REQAPPROVAL_INIT1.Fax_Doc_Yes_No: 02. Result= ' || l_fax_doc;
3910 IF (g_po_wf_debug = 'Y') THEN
3911 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
3912 END IF;
3913
3914 EXCEPTION
3915 WHEN OTHERS THEN
3916 l_doc_string := PO_REQAPPROVAL_INIT1.get_error_doc(itemType, itemkey);
3917 l_preparer_user_name := PO_REQAPPROVAL_INIT1.get_preparer_user_name(itemType, itemkey);
3918 wf_core.context('PO_REQAPPROVAL_INIT1.Fax_Doc_Yes_No',x_progress);
3919 PO_REQAPPROVAL_INIT1.send_error_notif(itemType, itemkey, l_preparer_user_name, l_doc_string, sqlerrm, 'PO_REQAPPROVAL_INIT1.FAX_DOC_YES_NO');
3920 raise;
3921
3922 END Fax_Doc_Yes_No;
3923
3924 --SR-ASL FPH --
3925 procedure Create_SR_ASL_Yes_No( itemtype in varchar2,
3926 itemkey in varchar2,
3927 actid in number,
3928 funcmode in varchar2,
3929 resultout out NOCOPY varchar2 ) is
3930 l_orgid number;
3931 l_create_sr_asl varchar2(2);
3932 x_progress varchar2(300);
3933
3934 l_doc_string varchar2(200);
3935 l_preparer_user_name varchar2(100);
3936 l_document_type PO_DOCUMENT_TYPES_ALL.DOCUMENT_TYPE_CODE%TYPE;
3937 l_document_subtype PO_DOCUMENT_TYPES_ALL.DOCUMENT_SUBTYPE%TYPE;
3938
3939 l_resp_id number;
3940 l_user_id number;
3941 l_appl_id number;
3942
3943 BEGIN
3944 x_progress := 'PO_REQAPPROVAL_INIT1.Create_SR_ASL_Yes_No: 01';
3945 IF (g_po_wf_debug = 'Y') THEN
3946 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
3947 END IF;
3948
3949 -- Do nothing in cancel or timeout mode
3950 if (funcmode <> wf_engine.eng_run) then
3951
3952 resultout := wf_engine.eng_null;
3953 return;
3954
3955 end if;
3956
3957 l_orgid := wf_engine.GetItemAttrNumber (itemtype => itemtype,
3958 itemkey => itemkey,
3959 aname => 'ORG_ID');
3960
3961
3962 l_user_id := wf_engine.GetItemAttrNumber (itemtype => itemtype,
3963 itemkey => itemkey,
3964 aname => 'USER_ID');
3965
3966 l_resp_id := wf_engine.GetItemAttrNumber (itemtype => itemtype,
3967 itemkey => itemkey,
3968 aname => 'RESPONSIBILITY_ID');
3969
3970 l_appl_id := wf_engine.GetItemAttrNumber (itemtype => itemtype,
3971 itemkey => itemkey,
3972 aname => 'APPLICATION_ID');
3973
3974 /* Since the call may be started from background engine (new seesion),
3975 * need to ensure the fnd context is correct
3976 */
3977
3978 --Context Setting Revamp
3979 /* if (l_user_id is not null and
3980 l_resp_id is not null and
3981 l_appl_id is not null )then
3982
3983 -- Bug 4290541,replaced apps init call with set doc mgr contxt
3984 PO_REQAPPROVAL_INIT1.Set_doc_mgr_context(itemtype, itemkey); */
3985
3986 IF l_orgid is NOT NULL THEN
3987 PO_MOAC_UTILS_PVT.set_org_context(l_orgid) ; -- <R12 MOAC>
3988 END IF;
3989
3990 -- end if;
3991
3992
3993
3994 l_create_sr_asl := wf_engine.GetItemAttrText (itemtype => itemtype,
3995 itemkey => itemkey,
3996 aname => 'CREATE_SOURCING_RULE');
3997 l_document_type := wf_engine.GetItemAttrText (itemtype => itemtype,
3998 itemkey => itemkey,
3999 aname => 'DOCUMENT_TYPE');
4000 l_document_subtype := wf_engine.GetItemAttrText (itemtype =>itemtype,
4001 itemkey => itemkey,
4002 aname => 'DOCUMENT_SUBTYPE');
4003
4004 /* the value of CREATE_SOURCING_RULE should be Y or N */
4005 IF (nvl(l_create_sr_asl,'N') <> 'Y') THEN
4006 l_create_sr_asl := 'N';
4007 ELSE
4008 if l_document_type = 'PA' then
4009 if l_document_subtype = 'BLANKET' then
4010 l_create_sr_asl := 'Y';
4011 else
4012 l_create_sr_asl := 'N';
4013 end if;
4014 else
4015 l_create_sr_asl := 'N';
4016 end if;
4017 END IF;
4018
4019 resultout := wf_engine.eng_completed || ':' || l_create_sr_asl;
4020
4021 x_progress := 'PO_REQAPPROVAL_INIT1.Create_SR_ASL_Yes_No: 02. Result= ' || l_create_sr_asl;
4022 IF (g_po_wf_debug = 'Y') THEN
4023 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
4024 END IF;
4025
4026 EXCEPTION
4027 WHEN OTHERS THEN
4028 l_create_sr_asl := 'N';
4029 resultout := wf_engine.eng_completed || ':' || l_create_sr_asl;
4030 END Create_SR_ASL_Yes_No;
4031
4032
4033
4034
4035
4036
4037 -- DKC 10/10/99
4038 procedure Send_WS_Notif_Yes_No( itemtype in varchar2,
4039 itemkey in varchar2,
4040 actid in number,
4041 funcmode in varchar2,
4042 resultout out NOCOPY varchar2 ) is
4043 l_orgid number;
4044 l_send_notif varchar2(2);
4045 x_progress varchar2(300);
4046
4047
4048 l_document_type varchar2(25);
4049 l_document_subtype po_document_types.document_subtype%type;
4050 l_document_id number;
4051 l_notifier varchar2(100);
4052
4053 l_doc_string varchar2(200);
4054 l_preparer_user_name varchar2(100);
4055
4056 BEGIN
4057 x_progress := 'PO_REQAPPROVAL_INIT1.Send_Notification_Yes_No: 01';
4058 IF (g_po_wf_debug = 'Y') THEN
4059 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
4060 END IF;
4061
4062
4063 -- Do nothing in cancel or timeout mode
4064 --
4065 if (funcmode <> wf_engine.eng_run) then
4066
4067 resultout := wf_engine.eng_null;
4068 return;
4069
4070 end if;
4071
4072
4073 l_document_type := wf_engine.GetItemAttrText (itemtype => itemtype,
4074 itemkey => itemkey,
4075 aname => 'DOCUMENT_TYPE');
4076
4077 l_document_id := wf_engine.GetItemAttrNumber (itemtype => itemtype,
4078 itemkey => itemkey,
4079 aname => 'DOCUMENT_ID');
4080
4081 l_document_subtype := wf_engine.GetItemAttrText (itemtype => itemtype,
4082 itemkey => itemkey,
4083 aname => 'DOCUMENT_SUBTYPE');
4084
4085 PO_REQAPPROVAL_INIT1.locate_notifier(l_document_id, l_document_type, l_notifier);
4086
4087
4088 if (l_notifier is not null) then
4089 l_send_notif := 'Y';
4090 --Bug#2843760: Call ARCHIVE_PO whenever notification is sent to supplier
4091 ARCHIVE_PO(l_document_id, l_document_type, l_document_subtype);
4092
4093 wf_engine.SetItemAttrText (itemtype => itemtype,
4094 itemkey => itemkey,
4095 aname => 'PO_WF_NOTIF_PERFORMER',
4096 avalue => l_notifier);
4097 else
4098 l_send_notif := 'N';
4099 end if;
4100
4101 resultout := wf_engine.eng_completed || ':' || l_send_notif ;
4102
4103 x_progress := 'PO_REQAPPROVAL_INIT1.Send_Notification_Yes_No: 02. Result= ' || l_send_notif;
4104 IF (g_po_wf_debug = 'Y') THEN
4105 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
4106 END IF;
4107
4108 EXCEPTION
4109 WHEN OTHERS THEN
4110 l_doc_string := PO_REQAPPROVAL_INIT1.get_error_doc(itemType, itemkey);
4111 l_preparer_user_name := PO_REQAPPROVAL_INIT1.get_preparer_user_name(itemType, itemkey);
4112 wf_core.context('PO_REQAPPROVAL_INIT1.Send_Notification_Yes_No',x_progress);
4113 PO_REQAPPROVAL_INIT1.send_error_notif(itemType, itemkey, l_preparer_user_name, l_doc_string, sqlerrm, 'PO_REQAPPROVAL_INIT1.FAX_DOC_YES_NO');
4114 raise;
4115
4116 END Send_WS_Notif_Yes_No;
4117
4118
4119 /*
4120 < Added this procedure as part of Bug #: 2810150 >
4121 */
4122 procedure Send_WS_FYI_Notif_Yes_No( itemtype in varchar2,
4123 itemkey in varchar2,
4124 actid in number,
4125 funcmode in varchar2,
4126 resultout out NOCOPY varchar2 ) is
4127 l_orgid number;
4128 l_send_notif varchar2(2);
4129 x_progress varchar2(300);
4130
4131
4132 l_document_type varchar2(25);
4133 l_document_subtype po_document_types.document_subtype%type;
4134 l_document_id number;
4135 l_notifier varchar2(100);
4136 l_notifier_resp varchar2(100);
4137
4138 l_doc_string varchar2(200);
4139 l_preparer_user_name varchar2(100);
4140
4141 -- BINDING FPJ
4142 l_acceptance_flag PO_HEADERS_ALL.acceptance_required_flag%TYPE;
4143
4144 BEGIN
4145 x_progress := 'PO_REQAPPROVAL_INIT1.Send_WS_FYI_Notif_Yes_No: 01';
4146 IF (g_po_wf_debug = 'Y') THEN
4147 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
4148 END IF;
4149
4150
4151 -- Do nothing in cancel or timeout mode
4152 --
4153 if (funcmode <> wf_engine.eng_run) then
4154
4155 resultout := wf_engine.eng_null;
4156 return;
4157
4158 end if;
4159
4160
4161 l_document_type := wf_engine.GetItemAttrText (itemtype => itemtype,
4162 itemkey => itemkey,
4163 aname => 'DOCUMENT_TYPE');
4164
4165 l_document_id := wf_engine.GetItemAttrNumber (itemtype => itemtype,
4166 itemkey => itemkey,
4167 aname => 'DOCUMENT_ID');
4168
4169 l_document_subtype := wf_engine.GetItemAttrText (itemtype => itemtype,
4170 itemkey => itemkey,
4171 aname => 'DOCUMENT_SUBTYPE');
4172
4173 -- BINDING FPJ START
4174
4175 IF ((l_document_type <> 'RELEASE') AND
4176 l_document_subtype IN ('STANDARD','BLANKET','CONTRACT')) THEN
4177 SELECT acceptance_required_flag
4178 INTO l_acceptance_flag
4179 FROM po_headers_all
4180 WHERE po_header_Id = l_document_id;
4181
4182 IF l_acceptance_flag = 'S' THEN
4183 PO_REQAPPROVAL_INIT1.locate_notifier(l_document_id, l_document_type, 'Y', l_notifier, l_notifier_resp);
4184 ELSE
4185 PO_REQAPPROVAL_INIT1.locate_notifier(l_document_id, l_document_type, 'N', l_notifier, l_notifier_resp);
4186 END IF;
4187 ELSE
4188 -- BINDING FPJ END
4189 PO_REQAPPROVAL_INIT1.locate_notifier(l_document_id, l_document_type, 'N', l_notifier, l_notifier_resp);
4190 END IF;
4191
4192
4193 if (l_notifier is not null) then
4194 l_send_notif := 'Y';
4195 --Bug#2843760: Call ARCHIVE_PO whenever notification is sent to supplier
4196 ARCHIVE_PO(l_document_id, l_document_type, l_document_subtype);
4197
4198 wf_engine.SetItemAttrText (itemtype => itemtype,
4199 itemkey => itemkey,
4200 aname => 'PO_WF_NOTIF_PERFORMER',
4201 avalue => l_notifier);
4202 else
4203 l_send_notif := 'N';
4204 end if;
4205
4206 wf_engine.SetItemAttrText (itemtype => itemtype,
4207 itemkey => itemkey,
4208 aname => 'PO_WF_ACK_NOTIF_PERFORMER',
4209 avalue => l_notifier_resp);
4210
4211 resultout := wf_engine.eng_completed || ':' || l_send_notif ;
4212
4213
4214 x_progress := 'PO_REQAPPROVAL_INIT1.Send_WS_FYI_Notif_Yes_No: 02. Result= ' || l_send_notif;
4215 IF (g_po_wf_debug = 'Y') THEN
4216 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
4217 END IF;
4218
4219 EXCEPTION
4220 WHEN OTHERS THEN
4221 l_doc_string := PO_REQAPPROVAL_INIT1.get_error_doc(itemType, itemkey);
4222 l_preparer_user_name := PO_REQAPPROVAL_INIT1.get_preparer_user_name(itemType, itemkey);
4223 wf_core.context('PO_REQAPPROVAL_INIT1.Send_WS_FYI_Notif_Yes_No',x_progress);
4224 PO_REQAPPROVAL_INIT1.send_error_notif(itemType, itemkey, l_preparer_user_name, l_doc_string, sqlerrm, 'PO_REQAPPROVAL_INIT1.Send_WS_FYI_Notif_Yes_No');
4225 raise;
4226
4227 END Send_WS_FYI_Notif_Yes_No;
4228
4229
4230
4231 /*
4232 < Added this procedure as part of Bug #: 2810150 >
4233 */
4234 procedure Send_WS_ACK_Notif_Yes_No( itemtype in varchar2,
4235 itemkey in varchar2,
4236 actid in number,
4237 funcmode in varchar2,
4238 resultout out NOCOPY varchar2 ) is
4239 l_orgid number;
4240 l_send_notif varchar2(2);
4241 x_progress varchar2(300);
4242
4243
4244 l_document_type varchar2(25);
4245 l_document_subtype po_document_types.document_subtype%type;
4246 l_document_id number;
4247 l_notifier varchar2(100);
4248
4249 l_doc_string varchar2(200);
4250 l_preparer_user_name varchar2(100);
4251
4252 BEGIN
4253 x_progress := 'PO_REQAPPROVAL_INIT1.Send_WS_ACK_Notif_Yes_No: 01';
4254 IF (g_po_wf_debug = 'Y') THEN
4255 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
4256 END IF;
4257
4258
4259 -- Do nothing in cancel or timeout mode
4260 --
4261 if (funcmode <> wf_engine.eng_run) then
4262
4263 resultout := wf_engine.eng_null;
4264 return;
4265
4266 end if;
4267
4268 l_document_type := wf_engine.GetItemAttrText (itemtype => itemtype,
4269 itemkey => itemkey,
4270 aname => 'DOCUMENT_TYPE');
4271
4272 l_document_id := wf_engine.GetItemAttrNumber (itemtype => itemtype,
4273 itemkey => itemkey,
4274 aname => 'DOCUMENT_ID');
4275
4276 l_document_subtype := wf_engine.GetItemAttrText (itemtype => itemtype,
4277 itemkey => itemkey,
4278 aname => 'DOCUMENT_SUBTYPE');
4279
4280 l_notifier:=wf_engine.GetItemAttrText (itemtype => itemtype,
4281 itemkey => itemkey,
4282 aname => 'PO_WF_ACK_NOTIF_PERFORMER');
4283
4284 if (l_notifier is not null) then
4285 --Bug#2843760: Call ARCHIVE_PO whenever notification is sent to supplier
4286 ARCHIVE_PO(l_document_id, l_document_type, l_document_subtype);
4287 l_send_notif := 'Y';
4288 else
4289 l_send_notif := 'N';
4290 end if;
4291
4292
4293 resultout := wf_engine.eng_completed || ':' || l_send_notif ;
4294
4295 x_progress := 'PO_REQAPPROVAL_INIT1.Send_WS_ACK_Notif_Yes_No: 02. Result= ' || l_send_notif;
4296 IF (g_po_wf_debug = 'Y') THEN
4297 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
4298 END IF;
4299
4300 EXCEPTION
4301 WHEN OTHERS THEN
4302 l_doc_string := PO_REQAPPROVAL_INIT1.get_error_doc(itemType, itemkey);
4303 l_preparer_user_name := PO_REQAPPROVAL_INIT1.get_preparer_user_name(itemType, itemkey);
4304 wf_core.context('PO_REQAPPROVAL_INIT1.Send_WS_ACK_Notif_Yes_No',x_progress);
4305 PO_REQAPPROVAL_INIT1.send_error_notif(itemType, itemkey, l_preparer_user_name, l_doc_string, sqlerrm, 'PO_REQAPPROVAL_INIT1.Send_WS_ACK_Notif_Yes_No');
4306 raise;
4307
4308 END Send_WS_ACK_Notif_Yes_No;
4309
4310
4311 /*
4312 For the given document_id ( ie. po_header_id ), this procedure
4313 tries to find out the correct users that need to be sent the
4314 notifications.
4315
4316 This procedure assumes that all the supplier users related to this
4317 document need to be sent the notification.
4318
4319 Returns the role containing all the users in the "resultout" variable
4320 */
4321 procedure locate_notifier(document_id in varchar2,
4322 document_type in varchar2,
4323 resultout in out NOCOPY varchar2) IS
4324 l_role_with_resp varchar2(1000);
4325 l_notify_only_flag varchar2(10);
4326 BEGIN
4327 l_notify_only_flag := 'Y';
4328 locate_notifier(document_id, document_type, l_notify_only_flag, resultout, l_role_with_resp);
4329 END;
4330
4331
4332 /*******************************************************************
4333 < Added this procedure as part of Bug #: 2810150 >
4334 PROCEDURE NAME: locate_notifier
4335
4336 DESCRIPTION :
4337 For the given document_id ( ie. po_header_id ), this procedure
4338 tries to find out the correct users that need to be sent the
4339 notifications.
4340
4341 Referenced by : Workflow procedures
4342 parameters :
4343 Input:
4344 document_id - the document id
4345 document_type - Document type
4346 p_notify_only_flag -
4347 The values can be 'Y' or 'N'
4348 'Y' means: The procedure will return all the users that are supplier users related to the document.
4349 Returns the role containing all the users in the "x_resultout" variable
4350
4351 'N' means: we want users that need to be sent FYI and also the users with resp.
4352 x_resultout: will have the role for the users that need to be sent the FYI
4353 x_role_with_resp: will have the role for users having the fucntion "POS_ACK_ORDER" assigned to
4354 them.
4355
4356 Output:
4357 x_resultout - Role for the users that need to be sent FYI
4358 x_role_with_resp - Role for the users who have the ability to acknowledge.
4359
4360 CHANGE History: Created 27-Feb-2003 jpasala
4361 modified 10-JUL-2003 sahegde
4362 Bugs Fixed: 7233648 - Start
4363 Added a condition cancel_flag = N in where-clause of the query to calculate
4364 expiration_date. Also added if-condition to check if expiration_date is less
4365 than sysdate then expiration_date = sysdate +180, so that role's expiry date
4366 is six months from sysdate.
4367 Bugs Fixed: 7233648 - End
4368
4369 *******************************************************************/
4370
4371 procedure locate_notifier (p_document_id in varchar2,
4372 p_document_type in varchar2,
4373 p_notify_only_flag in varchar2,
4374 x_resultout in out NOCOPY varchar2,
4375 x_role_with_resp in out NOCOPY VARCHAR2) IS
4376
4377
4378 /*CONERMS FPJ START*/
4379 -- declare local variables to hold output of get_supplier_userlist call
4380 l_supplier_user_tbl po_vendors_grp.external_user_tbl_type;
4381 l_namelist varchar2(31990):=null;
4382 l_namelist_for_sql varchar2(32000):=null;
4383 l_num_users number := 0;
4384 l_vendor_id NUMBER;
4385 l_return_status VARCHAR2(1);
4386 l_msg_count NUMBER := 0;
4387 l_msg_data VARCHAR2(2000);
4388 /*CONERMS FPJ END*/
4389
4390 -- local variables for role creation
4391 l_role_name WF_USER_ROLES.ROLE_NAME%TYPE;
4392 l_role_display_name varchar2(100):=null;
4393 l_temp varchar2(100);
4394 l_expiration_date DATE;
4395 l_count number;
4396 l_select boolean;
4397 l_refcur1 g_refcur;
4398 l_users_with_resp varchar2(32000);
4399 l_step varchar2(32000) := '0';
4400 l_diff_users_for_sql varchar2(32000);
4401 l_user_count_with_resp number:=0;
4402 l_fyi_user_count number:=0;
4403
4404
4405 BEGIN
4406 l_num_users := 0;
4407 l_step := '0';
4408
4409 /* CONTERMS FPJ START */
4410 -- The code to create the user list has been sliced into another procedure
4411 -- called po_vendors_grp.get_external_userlist. This procedure now makes a
4412 -- call to it to retrieve, comma and space delimited userlist, and number
4413 -- of users, supplier list in a table and vendor id.
4414 /*po_doc_utl_pvt.get_supplier_userlist(p_document_id => p_document_id
4415 ,p_document_type => p_document_type
4416 ,x_return_status => l_return_status
4417 ,x_supplier_user_tbl => l_supplier_user_tbl
4418 ,x_supplier_userlist => l_namelist
4419 ,x_supplier_userlist_for_sql => l_namelist_for_sql
4420 ,x_num_users => l_num_users
4421 ,x_vendor_id => l_vendor_id);*/
4422
4423 po_vendors_grp.get_external_userlist
4424 (p_api_version => 1.0
4425 ,p_init_msg_list => FND_API.G_FALSE
4426 ,p_document_id => p_document_id
4427 ,p_document_type => p_document_type
4428 ,x_return_status => l_return_status
4429 ,x_msg_count => l_msg_count
4430 ,x_msg_data => l_msg_data
4431 ,x_external_user_tbl => l_supplier_user_tbl
4432 ,x_supplier_userlist => l_namelist
4433 ,x_supplier_userlist_for_sql => l_namelist_for_sql
4434 ,x_num_users => l_num_users
4435 ,x_vendor_id => l_vendor_id);
4436
4437 l_step := '0'||l_namelist;
4438 -- proceed if return status is success
4439 IF (l_return_status = FND_API.G_RET_STS_SUCCESS) THEN
4440
4441 l_step := '4'|| l_namelist;
4442 if(l_namelist is null) then
4443 x_resultout := null;
4444 else
4445 if (p_document_type in ('PO', 'PA')) then
4446 select max(need_by_date)+180
4447 into l_expiration_date
4448 from po_line_locations
4449 where po_header_id = to_number(p_document_id)
4450 and cancel_flag = 'N';
4451
4452 if l_expiration_date <= sysdate then
4453 l_expiration_date := sysdate + 180;
4454 end if;
4455
4456 elsif (p_document_type = 'RELEASE') then
4457 select max(need_by_date)+180
4458 into l_expiration_date
4459 from po_line_locations
4460 where po_release_id = to_number(p_document_id)
4461 and cancel_flag = 'N';
4462
4463 if l_expiration_date <= sysdate then
4464 l_expiration_date := sysdate + 180;
4465 end if;
4466
4467 else
4468 l_expiration_date:=null;
4469 end if;
4470 begin
4471 select vendor_name
4472 into l_role_display_name
4473 from po_vendors
4474 where vendor_id=l_vendor_id;
4475 exception
4476 when others then
4477 l_role_display_name:=' ';
4478 end;
4479
4480 IF p_notify_only_flag = 'Y' THEN
4481 l_role_name:= get_wf_role_for_users(l_namelist_for_sql, l_num_users ) ;
4482 ELSE
4483
4484 -- get the list of users with the given resp from the current set of users
4485 l_step := '6';
4486 get_user_list_with_resp( get_function_id('POS_ACK_ORDER'),
4487 l_namelist_for_sql, l_namelist, l_users_with_resp,l_user_count_with_resp);
4488
4489 IF ( l_user_count_with_resp > 0 ) then
4490 l_step := '7 : '|| l_user_count_with_resp;
4491 x_role_with_resp := get_wf_role_for_users(l_users_with_resp, l_user_count_with_resp ) ;
4492
4493 if(x_role_with_resp is null ) then
4494 x_role_with_resp:=substr('ADHOCR' || to_char(sysdate, 'JSSSSS')|| p_document_id || p_document_type, 1, 30);
4495 l_step := '17'|| x_role_with_resp ;
4496 WF_DIRECTORY.CreateAdHocRole(x_role_with_resp, l_role_display_name ,
4497 null,
4498 null,
4499 null,
4500 'MAILHTML',
4501 l_namelist,
4502 null,
4503 null,
4504 'ACTIVE',
4505 l_expiration_date);
4506 end if;
4507 ELSE
4508 x_role_with_resp := null;
4509 END IF;
4510
4511 l_fyi_user_count := l_num_users - l_user_count_with_resp;
4512
4513 if ( l_fyi_user_count =0 ) then
4514 /* x_resultout := x_role_with_resp;*/
4515 /* Bug 5087421 */
4516 x_resultout :=null;
4517 return;
4518 end if;
4519
4520
4521 l_step := '10: ' ;
4522 if ( l_user_count_with_resp > 0 ) then
4523 get_diff_in_user_list ( l_namelist_for_sql, l_users_with_resp ,
4524 l_namelist , l_diff_users_for_sql, l_fyi_user_count);
4525 else
4526 l_diff_users_for_sql:= l_namelist_for_sql;
4527 l_fyi_user_count := l_num_users;
4528 end if;
4529 l_step := '11: count='||l_fyi_user_count ;
4530 l_role_name := get_wf_role_for_users(l_diff_users_for_sql, l_fyi_user_count ) ;
4531 END IF; -- End of notify flag check
4532
4533 if (l_role_name is null ) then
4534 l_step := '17'|| l_role_name;
4535
4536 /* Bug 2966804 START */
4537 /* We need to give a role name before creating an ADHOC role. */
4538
4539 l_role_name := substr('ADHOC' || to_char(sysdate, 'JSSSSS')|| p_document_id || p_document_type, 1, 30);
4540
4541 /* Bug 2966804 END */
4542
4543 WF_DIRECTORY.CreateAdHocRole(l_role_name, l_role_display_name ,
4544 null,
4545 null,
4546 null,
4547 'MAILHTML',
4548 l_namelist,
4549 null,
4550 null,
4551 'ACTIVE',
4552 l_expiration_date);
4553 x_resultout:=l_role_name;
4554 else
4555 l_step := '11'|| l_role_name;
4556 x_resultout:= l_role_name;
4557 end if;
4558 end if;
4559 END IF;
4560 EXCEPTION
4561 WHEN OTHERS THEN
4562 wf_core.context('PO_REQAPPROVAL_INIT1.locate_notifier failed at:',l_step);
4563 wf_core.context('PO_REQAPPROVAL_INIT1.locate_notifier',l_role_name||sqlerrm);
4564 --raise_application_error(-20001,'l_role_name ='||l_role_name ||' and l_step='||l_step ||' and l_list='||l_namelist_for_sql, true);
4565 end locate_notifier;
4566
4567 -- DKC 02/06/01
4568 procedure Email_Doc_Yes_No( itemtype in varchar2,
4569 itemkey in varchar2,
4570 actid in number,
4571 funcmode in varchar2,
4572 resultout out NOCOPY varchar2 ) is
4573 l_orgid number;
4574 l_email_doc varchar2(2);
4575 x_progress varchar2(300);
4576
4577 l_doc_string varchar2(200);
4578 l_preparer_user_name varchar2(100);
4579
4580 l_document_type varchar2(25);
4581 l_document_subtype varchar2(25);
4582 l_document_id number;
4583 l_po_header_id number;
4584 l_vendor_site_code varchar2(15);
4585 l_vendor_site_id number;
4586 --EMAILPO FPH START--
4587 l_vendor_site_lang PO_VENDOR_SITES.LANGUAGE%TYPE;
4588 l_adhocuser_lang WF_LANGUAGES.NLS_LANGUAGE%TYPE;
4589 l_adhocuser_territory WF_LANGUAGES.NLS_TERRITORY%TYPE;
4590 --EMAILPO FPH START--
4591 /* Bug 2989951 Increased the width of the following variables */
4592 l_po_email_performer WF_USERS.NAME%TYPE;
4593 l_po_email_add WF_USERS.EMAIL_ADDRESS%TYPE;
4594 l_display_name WF_USERS.DISPLAY_NAME%TYPE;
4595 l_po_email_performer_prof WF_USERS.NAME%TYPE;
4596 l_po_email_add_prof WF_USERS.EMAIL_ADDRESS%TYPE;
4597 l_display_name_prof WF_USERS.DISPLAY_NAME%TYPE;
4598 l_performer_exists number;
4599 l_notification_preference varchar2(20) := 'MAILHTM2'; -- Bug 3788367
4600 l_when_to_archive varchar2(80);
4601 l_archive_result varchar2(2);
4602
4603 BEGIN
4604 x_progress := 'PO_REQAPPROVAL_INIT1.Email_Doc_Yes_No: 01';
4605 IF (g_po_wf_debug = 'Y') THEN
4606 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
4607 END IF;
4608
4609
4610 -- Do nothing in cancel or timeout mode
4611 --
4612 if (funcmode <> wf_engine.eng_run) then
4613
4614 resultout := wf_engine.eng_null;
4615 return;
4616
4617 end if;
4618
4619 /* Bug 2687751.
4620 * For blankets, the org context was not getting set and hence
4621 * sql query which selecs vendor_site_id below from po_vendor_sites
4622 * was throwing an exception. Hence setting the org context here.
4623 */
4624 l_orgid := wf_engine.GetItemAttrNumber (itemtype => itemtype,
4625 itemkey => itemkey,
4626 aname => 'ORG_ID');
4627
4628 IF l_orgid is NOT NULL THEN
4629
4630 PO_MOAC_UTILS_PVT.set_org_context(l_orgid) ; -- <R12 MOAC>
4631
4632 END IF;
4633
4634 x_progress := '001';
4635 -- Create the attribute email document
4636 l_email_doc := wf_engine.GetItemAttrText (itemtype => itemtype,
4637 itemkey => itemkey,
4638 aname => 'EMAIL_DOCUMENT');
4639
4640
4641 -- the value of l_email_doc should be Y or N
4642 IF (nvl(l_email_doc,'N') <> 'Y') THEN
4643 l_email_doc := 'N';
4644 END IF;
4645
4646
4647 -- Here, we are creating an entry in wf_local_users and assigning that to the email performer
4648 IF (l_email_doc = 'Y') THEN
4649
4650
4651 l_document_type := wf_engine.GetItemAttrText (itemtype => itemtype,
4652 itemkey => itemkey,
4653 aname => 'DOCUMENT_TYPE');
4654
4655 l_document_subtype := wf_engine.GetItemAttrText (itemtype => itemtype,
4656 itemkey => itemkey,
4657 aname => 'DOCUMENT_SUBTYPE');
4658
4659 l_document_id := wf_engine.GetItemAttrNumber (itemtype => itemtype,
4660 itemkey => itemkey,
4661 aname => 'DOCUMENT_ID');
4662
4663 l_po_email_add := wf_engine.GetItemAttrText (itemtype => itemtype,
4664 itemkey => itemkey,
4665 aname => 'EMAIL_ADDRESS');
4666
4667 l_po_email_add_prof := wf_engine.GetItemAttrText (itemtype => itemtype,
4668 itemkey => itemkey,
4669 aname => 'EMAIL_ADD_FROM_PROFILE');
4670
4671
4672 if (l_document_type in ('PO', 'PA')) then
4673 l_po_header_id := l_document_id;
4674
4675 elsif (l_document_type = 'RELEASE') then
4676 select po_header_id into l_po_header_id
4677 from po_releases
4678 where po_release_id = l_document_id;
4679
4680 else
4681 null;
4682 end if;
4683
4684 x_progress := '002';
4685
4686 --EMAILPO FPH--
4687 --also retrieve language to set the adhocuser language to supplier site preferred language
4688 select poh.vendor_site_id, pvs.vendor_site_code, pvs.language
4689 into l_vendor_site_id, l_vendor_site_code, l_vendor_site_lang
4690 from po_headers poh, po_vendor_sites pvs
4691 where pvs.vendor_site_id = poh.vendor_site_id
4692 and poh.po_header_id = l_po_header_id;
4693
4694 /* Bug 2989951
4695 l_po_email_performer := l_vendor_site_code || substr(l_vendor_site_id, 1, 15);
4696 l_display_name := l_vendor_site_code || substr(l_vendor_site_id, 1, 15); */
4697
4698 --EMAILPO FPH START--
4699 IF l_vendor_site_lang is NOT NULL then
4700 SELECT wfl.nls_language, wfl.nls_territory INTO l_adhocuser_lang, l_adhocuser_territory
4701 FROM wf_languages wfl, fnd_languages_vl flv
4702 WHERE wfl.code = flv.language_code AND flv.nls_language = l_vendor_site_lang;
4703 ELSE
4704 SELECT wfl.nls_language, wfl.nls_territory into l_adhocuser_lang, l_adhocuser_territory
4705 FROM wf_languages wfl, fnd_languages_vl flv
4706 WHERE wfl.code = flv.language_code AND flv.installed_flag = 'B';
4707 END IF;
4708 --EMAILPO FPH END--
4709
4710 /* Bug 2989951. AdHocUser Name should be concatenation of the E-mail Address and the language */
4711 l_po_email_performer := l_po_email_add||'.'||l_adhocuser_lang;
4712 l_po_email_performer := upper(l_po_email_performer);
4713 l_display_name := l_po_email_performer;
4714
4715 select count(*) into l_performer_exists
4716 from wf_users where name = l_po_email_performer;
4717 /* Bug 2864242 The wf_local_users table is obsolete after the patch 2350501. So used the
4718 wf_users view instead of wf_local_users table */
4719
4720
4721 x_progress := '003';
4722
4723 if (l_performer_exists = 0) then
4724 --EMAILPO FPH--
4725 -- Pass in the correct adhocuser language and territory for CreateAdHocUser and SetAdhocUserAttr instead of null
4726 WF_DIRECTORY.CreateAdHocUser(l_po_email_performer, l_display_name, l_adhocuser_lang, l_adhocuser_territory, null, l_notification_preference, l_po_email_add, null, 'ACTIVE', null);
4727
4728 else
4729 WF_DIRECTORY.SETADHOCUSERATTR(l_po_email_performer, l_display_name, l_notification_preference, l_adhocuser_lang, l_adhocuser_territory, l_po_email_add, null);
4730
4731 end if;
4732
4733 wf_engine.SetItemAttrText ( itemtype => itemtype,
4734 itemkey => itemkey,
4735 aname => 'PO_WF_EMAIL_PERFORMER',
4736 avalue => l_po_email_performer);
4737
4738 /* set the performer from thr profilr to send the second email */
4739 /* Bug 2989951. Secondary AdHocUser Name should be concatenation of the Secondary E-mail Address and the language
4740
4741 l_po_email_performer_prof := 'PO_SECONDRY_EMAIL_ADD';
4742 l_display_name_prof := 'PO_SECONDRY_EMAIL_ADD'; */
4743
4744 l_po_email_performer_prof := l_po_email_add_prof||'.'||l_adhocuser_lang;
4745 l_po_email_performer_prof := upper(l_po_email_performer_prof);
4746 l_display_name_prof := l_po_email_performer_prof;
4747
4748
4749 select count(*) into l_performer_exists
4750 from wf_users where name = l_po_email_performer_prof;
4751 /* Bug 2864242 The wf_local_users table is obsolete after the patch 2350501. So used the
4752 wf_users view instead of wf_local_users table */
4753
4754
4755 --EMAILPO FPH START--
4756 -- For second email also the language and territory settings should be same as for the first one above
4757 x_progress := '004';
4758 if (l_performer_exists = 0) then
4759
4760 WF_DIRECTORY.CreateAdHocUser(l_po_email_performer_prof, l_display_name_prof, l_adhocuser_lang, l_adhocuser_territory, null, l_notification_preference, l_po_email_add_prof, null, 'ACTIVE', null);
4761
4762 else
4763 WF_DIRECTORY.SETADHOCUSERATTR(l_po_email_performer_prof, l_display_name_prof, l_notification_preference, l_adhocuser_lang, l_adhocuser_territory, l_po_email_add_prof, null);
4764
4765 end if;
4766 --EMAILPO FPH END--
4767
4768 wf_engine.SetItemAttrText ( itemtype => itemtype,
4769 itemkey => itemkey,
4770 aname => 'PO_WF_EMAIL_PERFORMER2',
4771 avalue => l_po_email_performer_prof);
4772
4773
4774
4775 x_progress := '005';
4776
4777
4778 -- bug 4727400 : updates need to autonomous, PA needs to be take care of.
4779 update_print_count(l_document_id,l_document_type);
4780
4781 --Bug#2843760: Moved portion of code which does the PO archiving to internal procedure ARCHIVE_PO
4782 ARCHIVE_PO(l_document_id, l_document_type, l_document_subtype);
4783
4784
4785 END IF;
4786
4787
4788 resultout := wf_engine.eng_completed || ':' || l_email_doc ;
4789
4790 x_progress := 'PO_REQAPPROVAL_INIT1.Email_Doc_Yes_No: 02. Result= ' || l_email_doc;
4791 IF (g_po_wf_debug = 'Y') THEN
4792 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
4793 END IF;
4794
4795 -- resultout := wf_engine.eng_completed || ':' || 'Y' ;
4796
4797 EXCEPTION
4798 WHEN OTHERS THEN
4799 l_doc_string := PO_REQAPPROVAL_INIT1.get_error_doc(itemType, itemkey);
4800 l_preparer_user_name := PO_REQAPPROVAL_INIT1.get_preparer_user_name(itemType, itemkey);
4801 wf_core.context('PO_REQAPPROVAL_INIT1.Email_Doc_Yes_No',x_progress||':'||sqlerrm);
4802 PO_REQAPPROVAL_INIT1.send_error_notif(itemType, itemkey, l_preparer_user_name, l_doc_string, sqlerrm, 'PO_REQAPPROVAL_INIT1.EMAIL_DOC_YES_NO');
4803 raise;
4804
4805 END Email_Doc_Yes_No;
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817 -- Print_Document
4818 -- Resultout
4819 -- ACTIVITY_PERFORMED
4820 -- Print Document.
4821
4822 procedure Print_Document( itemtype in varchar2,
4823 itemkey in varchar2,
4824 actid in number,
4825 funcmode in varchar2,
4826 resultout out NOCOPY varchar2 ) is
4827 l_orgid number;
4828 l_print_doc varchar2(2);
4829 x_progress varchar2(300);
4830
4831 l_doc_string varchar2(200);
4832 l_preparer_user_name varchar2(100);
4833
4834 BEGIN
4835 x_progress := 'PO_REQAPPROVAL_INIT1.Print_Document: 01';
4836 IF (g_po_wf_debug = 'Y') THEN
4837 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
4838 END IF;
4839
4840
4841 -- Do nothing in cancel or timeout mode
4842 --
4843 if (funcmode <> wf_engine.eng_run) then
4844
4845 resultout := wf_engine.eng_null;
4846 return;
4847
4848 end if;
4849
4850 l_orgid := wf_engine.GetItemAttrNumber (itemtype => itemtype,
4851 itemkey => itemkey,
4852 aname => 'ORG_ID');
4853
4854 IF l_orgid is NOT NULL THEN
4855
4856 PO_MOAC_UTILS_PVT.set_org_context(l_orgid) ; -- <R12 MOAC>
4857
4858 END IF;
4859
4860 x_progress := 'PO_REQAPPROVAL_INIT1.Print_Document: 02';
4861
4862 PrintDocument(itemtype,itemkey);
4863 --
4864 resultout := wf_engine.eng_completed || ':' || 'ACTIVITY_PERFORMED' ;
4865 --
4866 x_progress := 'PO_REQAPPROVAL_INIT1.Print_Document: 03';
4867
4868 EXCEPTION
4869 WHEN OTHERS THEN
4870 l_doc_string := PO_REQAPPROVAL_INIT1.get_error_doc(itemType, itemkey);
4871 l_preparer_user_name := PO_REQAPPROVAL_INIT1.get_preparer_user_name(itemType, itemkey);
4872 wf_core.context('PO_REQAPPROVAL_INIT1.Print_Document',x_progress);
4873 PO_REQAPPROVAL_INIT1.send_error_notif(itemType, itemkey, l_preparer_user_name, l_doc_string, sqlerrm, 'PO_REQAPPROVAL_INIT1.PRINT_DOCUMENT');
4874 raise;
4875
4876 END Print_Document;
4877
4878
4879
4880
4881 -- Procedure called by wf.
4882 -- DKC 10/10/99
4883 procedure Fax_Document( itemtype in varchar2,
4884 itemkey in varchar2,
4885 actid in number,
4886 funcmode in varchar2,
4887 resultout out NOCOPY varchar2 ) is
4888 l_orgid number;
4889 l_fax_doc varchar2(2);
4890 x_progress varchar2(300);
4891
4892 l_doc_string varchar2(200);
4893 l_preparer_user_name varchar2(100);
4894
4895 BEGIN
4896 x_progress := 'PO_REQAPPROVAL_INIT1.Fax_Document: 01';
4897 IF (g_po_wf_debug = 'Y') THEN
4898 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
4899 END IF;
4900
4901
4902 -- Do nothing in cancel or timeout mode
4903 --
4904 if (funcmode <> wf_engine.eng_run) then
4905
4906 resultout := wf_engine.eng_null;
4907 return;
4908
4909 end if;
4910
4911 l_orgid := wf_engine.GetItemAttrNumber (itemtype => itemtype,
4912 itemkey => itemkey,
4913 aname => 'ORG_ID');
4914
4915 IF l_orgid is NOT NULL THEN
4916
4917 PO_MOAC_UTILS_PVT.set_org_context(l_orgid) ; -- <R12 MOAC>
4918
4919 END IF;
4920
4921 x_progress := 'PO_REQAPPROVAL_INIT1.Fax_Document: 02';
4922
4923 FaxDocument(itemtype,itemkey);
4924 --
4925 resultout := wf_engine.eng_completed || ':' || 'ACTIVITY_PERFORMED' ;
4926 --
4927 x_progress := 'PO_REQAPPROVAL_INIT1.Fax_Document: 03';
4928
4929 EXCEPTION
4930 WHEN OTHERS THEN
4931 l_doc_string := PO_REQAPPROVAL_INIT1.get_error_doc(itemType, itemkey);
4932 l_preparer_user_name := PO_REQAPPROVAL_INIT1.get_preparer_user_name(itemType, itemkey);
4933 wf_core.context('PO_REQAPPROVAL_INIT1.Fax_Document',x_progress);
4934 PO_REQAPPROVAL_INIT1.send_error_notif(itemType, itemkey, l_preparer_user_name, l_doc_string, sqlerrm, 'PO_REQAPPROVAL_INIT1.FAX_DOCUMENT');
4935 raise;
4936
4937 END Fax_Document;
4938
4939
4940
4941
4942
4943
4944 -- Is_document_Approved
4945 -- IN
4946 -- itemtype -- itemkey -- actid -- funcmode
4947 -- OUT
4948 -- Resultout
4949 --
4950 -- Is the document already approved. This may be the case if the document
4951 -- was PRE-APPROVED before it goes through the reserve action. The RESERVE
4952 -- would then approve the doc after it reserved the funds.
4953
4954 procedure Is_document_Approved( itemtype in varchar2,
4955 itemkey in varchar2,
4956 actid in number,
4957 funcmode in varchar2,
4958 resultout out NOCOPY varchar2 ) is
4959 l_auth_stat varchar2(25);
4960 l_doc_type varchar2(25);
4961 l_doc_id number;
4962 l_orgid number;
4963 x_resultout varchar2(1);
4964 x_progress varchar2(300);
4965
4966 l_doc_string varchar2(200);
4967 l_preparer_user_name varchar2(100);
4968
4969 BEGIN
4970 x_progress := 'PO_REQAPPROVAL_INIT1.Is_document_Approved: 01';
4971 IF (g_po_wf_debug = 'Y') THEN
4972 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
4973 END IF;
4974
4975
4976 -- Do nothing in cancel or timeout mode
4977 --
4978 if (funcmode <> wf_engine.eng_run) then
4979
4980 resultout := wf_engine.eng_null;
4981 return;
4982
4983 end if;
4984
4985 /* Bug# 2377333
4986 ** Setting application context
4987 */
4988 --Context Setting Revamp
4989 --PO_REQAPPROVAL_INIT1.Set_doc_mgr_context(itemtype, itemkey);
4990
4991 l_orgid := wf_engine.GetItemAttrNumber (itemtype => itemtype,
4992 itemkey => itemkey,
4993 aname => 'ORG_ID');
4994
4995 IF l_orgid is NOT NULL THEN
4996
4997 PO_MOAC_UTILS_PVT.set_org_context(l_orgid) ; -- <R12 MOAC>
4998
4999 END IF;
5000
5001 l_doc_type := wf_engine.GetItemAttrText (itemtype => itemtype,
5002 itemkey => itemkey,
5003 aname => 'DOCUMENT_TYPE');
5004
5005 l_doc_id := wf_engine.GetItemAttrNumber (itemtype => itemtype,
5006 itemkey => itemkey,
5007 aname => 'DOCUMENT_ID');
5008 IF l_doc_type='REQUISITION' THEN
5009
5010 x_progress := '002';
5011
5012 select NVL(authorization_status, 'INCOMPLETE') into l_auth_stat
5013 from PO_REQUISITION_HEADERS
5014 where requisition_header_id = l_doc_id;
5015
5016
5017 ELSIF l_doc_type IN ('PO','PA') THEN
5018
5019 x_progress := '003';
5020
5021 select NVL(authorization_status,'INCOMPLETE') into l_auth_stat
5022 from PO_HEADERS
5023 where po_header_id = l_doc_id;
5024
5025 ELSIF l_doc_type = 'RELEASE' THEN
5026
5027 x_progress := '004';
5028
5029 select NVL(authorization_status,'INCOMPLETE') into l_auth_stat
5030 from PO_RELEASES
5031 where po_release_id = l_doc_id;
5032
5033 END IF;
5034
5035 IF l_auth_stat = 'APPROVED' THEN
5036
5037 resultout := wf_engine.eng_completed || ':' || 'Y' ;
5038 x_resultout := 'Y';
5039 ELSE
5040 resultout := wf_engine.eng_completed || ':' || 'N';
5041 x_resultout := 'N';
5042 END IF;
5043
5044 x_progress := 'PO_REQAPPROVAL_INIT1.Is_document_Approved: 02. Result=' || x_resultout;
5045 IF (g_po_wf_debug = 'Y') THEN
5046 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress );
5047 END IF;
5048
5049 EXCEPTION
5050
5051 WHEN OTHERS THEN
5052 l_doc_string := PO_REQAPPROVAL_INIT1.get_error_doc(itemType, itemkey);
5053 l_preparer_user_name := PO_REQAPPROVAL_INIT1.get_preparer_user_name(itemType, itemkey);
5054 wf_core.context('PO_REQAPPROVAL_INIT1','Is_document_Approved',x_progress);
5055 PO_REQAPPROVAL_INIT1.send_error_notif(itemType, itemkey, l_preparer_user_name, l_doc_string, sqlerrm, 'PO_REQAPPROVAL_INIT1.IS_DOCUMENT_APPROVED');
5056 raise;
5057
5058
5059 END Is_document_Approved;
5060
5061 -- Get_Create_PO_Mode
5062 -- IN
5063 -- itemtype -- itemkey -- actid -- funcmode
5064 -- OUT
5065 -- Resultout
5066 -- Activity Performed
5067
5068 procedure Get_Create_PO_Mode(itemtype in varchar2,
5069 itemkey in varchar2,
5070 actid in number,
5071 funcmode in varchar2,
5072 resultout out NOCOPY varchar2 ) is
5073 l_create_po_mode VARCHAR2(1);
5074 x_progress varchar2(300);
5075
5076 l_doc_string varchar2(200);
5077 l_preparer_user_name varchar2(100);
5078
5079 BEGIN
5080
5081
5082 x_progress := 'PO_REQAPPROVAL_INIT1.Get_Create_PO_Mode: 01';
5083 IF (g_po_wf_debug = 'Y') THEN
5084 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
5085 END IF;
5086
5087
5088 -- Do nothing in cancel or timeout mode
5089 --
5090 if (funcmode <> wf_engine.eng_run) then
5091
5092 resultout := wf_engine.eng_null;
5093 return;
5094
5095 end if;
5096
5097 l_create_po_mode := wf_engine.GetItemAttrText (itemtype => itemtype,
5098 itemkey => itemkey,
5099 aname => 'SEND_CREATEPO_TO_BACKGROUND');
5100
5101 /* Bug 678291 by dkfchan
5102 ** if the approval mode is background, set the result to 'BACKGROUD'
5103 ** Removed the original method which set the WF_ENGINE.THRESHOLD to -1.
5104 ** This fix depends on the change poxwfrqa.wft and poxwfpoa.wft also.
5105 */
5106
5107 IF NVL(l_create_po_mode,'N') = 'Y' THEN
5108 resultout := wf_engine.eng_completed || ':' || 'BACKGROUND';
5109 ELSE
5110 resultout := wf_engine.eng_completed || ':' || 'ONLINE';
5111 END IF;
5112
5113 x_progress := 'PO_REQAPPROVAL_INIT1.Get_Create_PO_Mode: ' ||
5114 'Create PO Mode= ' || l_create_po_mode;
5115 IF (g_po_wf_debug = 'Y') THEN
5116 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
5117 END IF;
5118
5119
5120 EXCEPTION
5121
5122 WHEN OTHERS THEN
5123 l_doc_string := PO_REQAPPROVAL_INIT1.get_error_doc(itemType, itemkey);
5124 l_preparer_user_name := PO_REQAPPROVAL_INIT1.get_preparer_user_name(itemType, itemkey);
5125 wf_core.context('PO_REQAPPROVAL_INIT1','Get_Create_PO_Mode',x_progress);
5126 PO_REQAPPROVAL_INIT1.send_error_notif(itemType, itemkey, l_preparer_user_name, l_doc_string, sqlerrm, 'PO_REQAPPROVAL_INIT1.GET_CREATE_PO_MODE');
5127 raise;
5128
5129 END Get_Create_PO_Mode;
5130
5131 -- Get_Workflow_Approval_Mode
5132 -- IN
5133 -- itemtype -- itemkey -- actid -- funcmode
5134 -- OUT
5135 -- Resultout
5136 -- On-line
5137 -- Background
5138
5139 procedure Get_Workflow_Approval_Mode( itemtype in varchar2,
5140 itemkey in varchar2,
5141 actid in number,
5142 funcmode in varchar2,
5143 resultout out NOCOPY varchar2 ) is
5144 l_approval_mode VARCHAR2(30);
5145 x_progress varchar2(300);
5146
5147 l_doc_string varchar2(200);
5148 l_preparer_user_name varchar2(100);
5149
5150 BEGIN
5151
5152 /* get the profile PO_WORKFLOW_APPROVAL_MODE and return the value */
5153
5154 x_progress := 'PO_REQAPPROVAL_INIT1.Get_Workflow_Approval_Mode: 01';
5155 IF (g_po_wf_debug = 'Y') THEN
5156 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
5157 END IF;
5158
5159
5160 -- Do nothing in cancel or timeout mode
5161 --
5162 if (funcmode <> wf_engine.eng_run) then
5163
5164 resultout := wf_engine.eng_null;
5165 return;
5166
5167 end if;
5168
5169 fnd_profile.get('PO_WORKFLOW_APPROVAL_MODE', l_approval_mode);
5170
5171 /* Bug 678291 by dkfchan
5172 ** if the approval mode is background, set the result to 'BACKGROUD'
5173 ** Removed the original method which set the WF_ENGINE.THRESHOLD to -1.
5174 ** This fix depends on the change poxwfrqa.wft and poxwfpoa.wft also.
5175 */
5176
5177 IF l_approval_mode = 'BACKGROUND' or l_approval_mode is NULL THEN
5178 resultout := wf_engine.eng_completed || ':' || 'BACKGROUND';
5179 ELSE
5180 resultout := wf_engine.eng_completed || ':' || 'ONLINE';
5181 END IF;
5182
5183 x_progress := 'PO_REQAPPROVAL_INIT1.Get_Workflow_Approval_Mode: ' ||
5184 'Approval Mode= ' || l_approval_mode;
5185 IF (g_po_wf_debug = 'Y') THEN
5186 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
5187 END IF;
5188
5189
5190 EXCEPTION
5191
5192 WHEN OTHERS THEN
5193 l_doc_string := PO_REQAPPROVAL_INIT1.get_error_doc(itemType, itemkey);
5194 l_preparer_user_name := PO_REQAPPROVAL_INIT1.get_preparer_user_name(itemType, itemkey);
5195 wf_core.context('PO_REQAPPROVAL_INIT1','Get_Workflow_Approval_Mode',x_progress);
5196 PO_REQAPPROVAL_INIT1.send_error_notif(itemType, itemkey, l_preparer_user_name, l_doc_string, sqlerrm, 'PO_REQAPPROVAL_INIT1.GET_WORKFLOW_APPROVAL_MODE');
5197 raise;
5198
5199 END Get_Workflow_Approval_Mode;
5200
5201 -- Dummy
5202 -- IN
5203 -- itemtype -- itemkey -- actid -- funcmode
5204 -- OUT
5205 -- Resultout
5206 -- Activity Performed
5207 -- Dummy procedure that does nothing (NOOP). Used to set the
5208 -- cost above the backgound engine threshold. This causes the
5209 -- workflow to execute in the background.
5210 procedure Dummy( itemtype in varchar2,
5211 itemkey in varchar2,
5212 actid in number,
5213 funcmode in varchar2,
5214 resultout out NOCOPY varchar2 ) is
5215
5216 BEGIN
5217
5218 /* Do nothing */
5219 NULL;
5220
5221 END Dummy;
5222
5223
5224
5225 /****************************************************************************
5226 * The Following are the supporting APIs to the workflow functions.
5227 * These API's are Private (Not declared in the Package specs).
5228 ****************************************************************************/
5229
5230 procedure GetReqAttributes(p_requisition_header_id in NUMBER,
5231 itemtype in varchar2,
5232 itemkey in varchar2) is
5233
5234 l_line_num varchar2(80);
5235 x_progress varchar2(100) := '000';
5236
5237 counter NUMBER:=0;
5238 BEGIN
5239
5240
5241 x_progress := 'PO_REQAPPROVAL_INIT1.GetReqAttributes: 01';
5242 IF (g_po_wf_debug = 'Y') THEN
5243 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
5244 END IF;
5245
5246 /* Fetch the Req Header, then set the attributes. */
5247 open GetRecHdr_csr(p_requisition_header_id);
5248 FETCH GetRecHdr_csr into ReqHdr_rec;
5249 close GetRecHdr_csr;
5250
5251 x_progress := 'PO_REQAPPROVAL_INIT1.GetReqAttributes: 02';
5252 IF (g_po_wf_debug = 'Y') THEN
5253 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
5254 END IF;
5255
5256 SetReqHdrAttributes(itemtype, itemkey);
5257
5258 x_progress := 'PO_REQAPPROVAL_INIT1.GetReqAttributes: 03';
5259 IF (g_po_wf_debug = 'Y') THEN
5260 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
5261 END IF;
5262
5263 EXCEPTION
5264 WHEN OTHERS THEN
5265 wf_core.context('PO_REQAPPROVAL_INIT1','GetReqAttributes',x_progress);
5266 raise;
5267
5268 end GetReqAttributes;
5269 --
5270
5271
5272 --------------------------------------------------------------------------------
5273 --Start of Comments
5274 --Name: getReqAmountInfo
5275 --Pre-reqs:
5276 -- None.
5277 --Modifies:
5278 -- None.
5279 --Locks:
5280 -- None.
5281 --Function:
5282 -- convert req total, req amount, req tax into approver preferred currency for display
5283 --Parameters:
5284 --IN:
5285 --itemtype
5286 -- workflow item type
5287 --itemtype
5288 -- workflow item key
5289 --p_function_currency
5290 -- functional currency
5291 --p_total_amount_disp
5292 -- req total including tax, in displayable format
5293 --p_total_amount
5294 -- req total including tax, number
5295 --p_req_amount_disp
5296 -- req total without including tax, in displayable format
5297 --p_req_amount
5298 -- req total without including tax, number
5299 --p_tax_amount_disp
5300 -- req tax, in displayable format
5301 --p_tax_amount
5302 -- req tax number
5303 --OUT:
5304 --p_amount_for_subject
5305 --p_amount_for_header
5306 --p_amount_for_tax
5307 --End of Comments
5308 -------------------------------------------------------------------------------
5309 procedure getReqAmountInfo(itemtype in varchar2,
5310 itemkey in varchar2,
5311 p_function_currency in varchar2,
5312 p_total_amount_disp in varchar2,
5313 p_total_amount in number,
5314 p_req_amount_disp in varchar2,
5315 p_req_amount in number,
5316 p_tax_amount_disp in varchar2,
5317 p_tax_amount in number,
5318 x_amount_for_subject out nocopy varchar2,
5319 x_amount_for_header out nocopy varchar2,
5320 x_amount_for_tax out nocopy varchar2) is
5321
5322 l_rate_type po_system_parameters.default_rate_type%TYPE;
5323 l_rate number;
5324 l_denominator_rate number;
5325 l_numerator_rate number;
5326 l_approval_currency varchar2(30);
5327 l_amount_disp varchar2(60);
5328 l_amount_approval_currency number;
5329 l_approver_user_name fnd_user.user_name%TYPE;
5330 l_user_id fnd_user.user_id%TYPE;
5331 l_progress varchar2(200);
5332 l_no_rate_msg varchar2(200);
5333
5334 begin
5335 SELECT default_rate_type
5336 INTO l_rate_type
5337 FROM po_system_parameters;
5338
5339 l_progress := 'getReqAmountInfo:' || l_rate_type;
5340 IF (g_po_wf_debug = 'Y') THEN
5341 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,l_progress);
5342 END IF;
5343
5344 l_approver_user_name := PO_WF_UTIL_PKG.GetItemAttrText(itemtype=>itemtype,
5345 itemkey=>itemkey,
5346 aname=>'APPROVER_USER_NAME');
5347 if (l_approver_user_name is not null) then
5348 SELECT user_id
5349 INTO l_user_id
5350 FROM fnd_user
5351 WHERE user_name = l_approver_user_name;
5352
5353 l_progress := 'getReqAmountInfo:' || l_user_id;
5354 IF (g_po_wf_debug = 'Y') THEN
5355 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,l_progress);
5356 END IF;
5357
5358 l_approval_currency := FND_PROFILE.VALUE_SPECIFIC('ICX_PREFERRED_CURRENCY', l_user_id);
5359 end if;
5360
5361 if (l_approval_currency = p_function_currency or l_approver_user_name is null
5362 or l_rate_type is null or l_approval_currency is null) then
5363 x_amount_for_subject := p_total_amount_disp || ' ' || p_function_currency;
5364 x_amount_for_header := p_req_amount_disp || ' ' || p_function_currency;
5365 x_amount_for_tax := p_tax_amount_disp || ' ' || p_function_currency;
5366 return;
5367 end if;
5368
5369 l_progress := 'getReqAmountInfo:' || l_approval_currency;
5370 IF (g_po_wf_debug = 'Y') THEN
5371 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,l_progress);
5372 END IF;
5373
5374 gl_currency_api.get_closest_triangulation_rate(
5375 x_from_currency => p_function_currency,
5376 x_to_currency => l_approval_currency,
5377 x_conversion_date => sysdate,
5378 x_conversion_type => l_rate_type,
5379 x_max_roll_days => 5,
5380 x_denominator => l_denominator_rate,
5381 x_numerator => l_numerator_rate,
5382 x_rate => l_rate);
5383
5384
5385 l_progress := 'getReqAmountInfo:' || substrb(to_char(l_rate), 1, 30);
5386
5387 IF (g_po_wf_debug = 'Y') THEN
5388 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,l_progress);
5389 END IF;
5390
5391 /* setting amount for notification subject */
5392 l_amount_approval_currency := (p_total_amount/l_denominator_rate) * l_numerator_rate;
5393
5394 l_amount_disp := TO_CHAR(l_amount_approval_currency,
5395 FND_CURRENCY.GET_FORMAT_MASK(l_approval_currency,g_currency_format_mask));
5396 x_amount_for_subject := l_amount_disp || ' ' || l_approval_currency;
5397
5398 /* setting amount for header attribute */
5399 l_amount_approval_currency := (p_req_amount/l_denominator_rate) * l_numerator_rate;
5400
5401 l_amount_disp := TO_CHAR(l_amount_approval_currency,
5402 FND_CURRENCY.GET_FORMAT_MASK(l_approval_currency,g_currency_format_mask));
5403
5404 l_progress := 'getReqAmountInfo:' || l_amount_disp;
5405 IF (g_po_wf_debug = 'Y') THEN
5406 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,l_progress);
5407 END IF;
5408
5409 x_amount_for_header := p_req_amount_disp || ' ' || p_function_currency;
5410 x_amount_for_header := x_amount_for_header || ' (' || l_amount_disp || ' ' || l_approval_currency || ')';
5411
5412 l_amount_approval_currency := (p_tax_amount/l_denominator_rate) * l_numerator_rate;
5413
5414 l_amount_disp := TO_CHAR(l_amount_approval_currency,
5415 FND_CURRENCY.GET_FORMAT_MASK(l_approval_currency,g_currency_format_mask));
5416
5417 x_amount_for_tax := p_tax_amount_disp || ' ' || p_function_currency;
5418 x_amount_for_tax := x_amount_for_tax || ' (' || l_amount_disp || ' ' || l_approval_currency || ')';
5419
5420 exception
5421 when gl_currency_api.no_rate then
5422 l_progress := 'getReqAmountInfo: no rate';
5423
5424 IF (g_po_wf_debug = 'Y') THEN
5425 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,l_progress);
5426 END IF;
5427 x_amount_for_subject := p_req_amount_disp || ' ' || p_function_currency;
5428
5429 l_no_rate_msg := fnd_message.get_string('PO', 'PO_WF_NOTIF_NO_RATE');
5430 l_no_rate_msg := replace (l_no_rate_msg, '`&CURRENCY', l_approval_currency);
5431
5432 x_amount_for_header := p_req_amount_disp || ' ' || p_function_currency;
5433 x_amount_for_header := x_amount_for_header || ' (' || l_no_rate_msg || ')';
5434
5435 x_amount_for_tax := p_tax_amount_disp || ' ' || p_function_currency;
5436 x_amount_for_tax := x_amount_for_tax || ' (' || l_no_rate_msg || ')';
5437
5438 when others then
5439
5440 l_progress := 'getReqAmountInfo:' || substrb(SQLERRM, 1,200);
5441
5442 IF (g_po_wf_debug = 'Y') THEN
5443 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,l_progress);
5444 END IF;
5445 x_amount_for_subject := p_req_amount_disp || ' ' || p_function_currency;
5446 x_amount_for_header := p_req_amount_disp || ' ' || p_function_currency;
5447 x_amount_for_tax := p_tax_amount_disp || ' ' || p_function_currency;
5448
5449 end;
5450
5451 procedure SetReqHdrAttributes(itemtype in varchar2, itemkey in varchar2) is
5452
5453 x_progress varchar2(200) := '000';
5454
5455 l_auth_stat varchar2(80);
5456 l_closed_code varchar2(80);
5457 l_doc_type varchar2(25);
5458 l_doc_subtype varchar2(25);
5459 l_doc_type_disp varchar2(240); /* Bug# 2616355: kagarwal */
5460 -- l_doc_subtype_disp varchar2(80);
5461
5462 l_req_amount number;
5463 l_req_amount_disp varchar2(60);
5464 l_tax_amount number;
5465 l_tax_amount_disp varchar2(60);
5466 l_total_amount number;
5467 l_total_amount_disp varchar2(60);
5468
5469 l_amount_for_subject varchar2(400);
5470 l_amount_for_header varchar2(400);
5471 l_amount_for_tax varchar2(400);
5472
5473 /* Bug# 1162252: Amitabh
5474 ** Desc: Changed the length of l_currency_code from 8 to 30
5475 ** as the call to PO_CORE_S2.get_base_currency would
5476 ** return varchar2(30).
5477 */
5478
5479 l_currency_code varchar2(30);
5480 l_doc_id number;
5481
5482 /* Bug 1100247: Amitabh
5483 */
5484 x_username varchar2(100);
5485 x_user_display_name varchar2(240);
5486
5487 /* Bug 2830992
5488 */
5489 l_num_attachments number;
5490 /*Start Bug#3406460 */
5491 l_precision number;
5492 l_ext_precision number;
5493 l_min_acct_unit number;
5494 /*End Bug#3406460 */
5495 cursor c1(p_auth_stat varchar2) is
5496 select DISPLAYED_FIELD
5497 from po_lookup_codes
5498 where lookup_type='AUTHORIZATION STATUS'
5499 and lookup_code = p_auth_stat;
5500
5501 cursor c2(p_closed_code varchar2) is
5502 select DISPLAYED_FIELD
5503 from po_lookup_codes
5504 where lookup_type='DOCUMENT STATE'
5505 and lookup_code = p_closed_code;
5506
5507 /* Bug# 2616355: kagarwal
5508 ** Desc: We will get the document type display value from
5509 ** po document types.
5510 */
5511
5512 cursor c3(p_doc_type varchar2, p_doc_subtype varchar2) is
5513 select type_name
5514 from po_document_types
5515 where document_type_code = p_doc_type
5516 and document_subtype = p_doc_subtype;
5517
5518 /*
5519 cursor c4(p_doc_subtype varchar2) is
5520 select DISPLAYED_FIELD
5521 from po_lookup_codes
5522 where lookup_type='REQUISITION TYPE'
5523 and lookup_code = p_doc_subtype;
5524 */
5525
5526 /* Bug# 1470041: kagarwal
5527 ** Desc: Modified the cursor req_total_csr for calculating the Req Total
5528 ** in procedure SetReqHdrAttributes() to ignore the Req lines modified using
5529 ** the modify option in the autocreate form.
5530 **
5531 ** Added condition:
5532 ** AND NVL(modified_by_agent_flag, 'N') = 'N'
5533 */
5534 /*Start Bug#3406460 - Added precision parameter to round the line amount*/
5535 cursor req_total_csr(p_doc_id number,l_precision number) is
5536 SELECT nvl(SUM(round(decode(order_type_lookup_code,
5537 'RATE', amount,
5538 'FIXED PRICE', amount,
5539 quantity * unit_price),l_precision)) ,0)
5540 FROM po_requisition_lines
5541 WHERE requisition_header_id = p_doc_id
5542 AND NVL(cancel_flag,'N') = 'N'
5543 AND NVL(modified_by_agent_flag, 'N') = 'N';
5544 /*End Bug#3406460*/
5545 /* Bug# 2483898: kagarwal
5546 ** Desc: When calculating the Tax for Requisitons submitted for approval,
5547 ** the cancelled requisition lines should be ignored. Also the lines modified in
5548 ** the autocreate form using the modify option should also be ignored.
5549 */
5550
5551 cursor req_tax_csr(p_doc_id number) is
5552 SELECT nvl(sum(nonrecoverable_tax), 0)
5553 FROM po_requisition_lines rl,
5554 po_req_distributions_all rd -- <R12 MOAC>
5555 WHERE rl.requisition_header_id = p_doc_id
5556 AND rd.requisition_line_id = rl.requisition_line_id
5557 AND NVL(rl.cancel_flag,'N') = 'N'
5558 AND NVL(rl.modified_by_agent_flag, 'N') = 'N';
5559
5560 BEGIN
5561
5562 x_progress := 'PO_REQAPPROVAL_INIT1.SetReqHdrAttributes: 01';
5563 IF (g_po_wf_debug = 'Y') THEN
5564 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
5565 END IF;
5566
5567
5568 wf_engine.SetItemAttrText ( itemtype => itemtype,
5569 itemkey => itemkey,
5570 aname => 'DOCUMENT_NUMBER',
5571 avalue => ReqHdr_rec.segment1);
5572 --
5573 wf_engine.SetItemAttrNumber ( itemtype => itemType,
5574 itemkey => itemkey,
5575 aname => 'DOCUMENT_ID',
5576 avalue => ReqHdr_rec.requisition_header_id);
5577 --
5578 wf_engine.SetItemAttrNumber ( itemtype => itemType,
5579 itemkey => itemkey,
5580 aname => 'PREPARER_ID',
5581 avalue => ReqHdr_rec.preparer_id);
5582 --
5583 wf_engine.SetItemAttrText ( itemtype => itemtype,
5584 itemkey => itemkey,
5585 aname => 'AUTHORIZATION_STATUS',
5586 avalue => ReqHdr_rec.authorization_status);
5587 --
5588
5589 wf_engine.SetItemAttrText ( itemtype => itemtype,
5590 itemkey => itemkey,
5591 aname => 'REQ_DESCRIPTION',
5592 avalue => ReqHdr_rec.description);
5593 --
5594 wf_engine.SetItemAttrText ( itemtype => itemtype,
5595 itemkey => itemkey,
5596 aname => 'CLOSED_CODE',
5597 avalue => ReqHdr_rec.closed_code);
5598 --
5599
5600 wf_engine.SetItemAttrText ( itemtype => itemtype,
5601 itemkey => itemkey,
5602 aname => 'EMERGENCY_PO_NUMBER',
5603 avalue => ReqHdr_rec.emergency_po_num);
5604 --
5605
5606 -- Bug#3147435
5607 x_progress := 'PO_REQAPPROVAL_INIT1.SetReqHdrAttributes: 02 Start of Hdr Att for JRAD';
5608 IF (g_po_wf_debug = 'Y') THEN
5609 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
5610 END IF;
5611
5612 -- Bug#3147435
5613 --Set the CONTRACTOR_REQUISITION_FLAG
5614 PO_WF_UTIL_PKG.SetItemAttrText (itemtype => itemtype,
5615 itemkey => itemkey,
5616 aname => 'CONTRACTOR_REQUISITION_FLAG',
5617 avalue => ReqHdr_rec.contractor_requisition_flag);
5618 --
5619
5620 -- Bug#3147435
5621 --Set the CONTRACTOR_STATUS
5622 PO_WF_UTIL_PKG.SetItemAttrText (itemtype => itemtype,
5623 itemkey => itemkey,
5624 aname => 'CONTRACTOR_STATUS',
5625 avalue => ReqHdr_rec.contractor_status);
5626 --
5627
5628 -- Bug#3147435
5629 x_progress := 'PO_REQAPPROVAL_INIT1.SetReqHdrAttributes: 03 End of Hdr Att for JRAD';
5630 IF (g_po_wf_debug = 'Y') THEN
5631 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
5632 END IF;
5633
5634 /* Bug 1100247 Amitabh*/
5635 PO_REQAPPROVAL_INIT1.get_user_name(ReqHdr_rec.preparer_id, x_username,
5636 x_user_display_name);
5637
5638 wf_engine.SetItemAttrText ( itemtype => itemType,
5639 itemkey => itemkey,
5640 aname => 'PREPARER_USER_NAME' ,
5641 avalue => x_username);
5642
5643 wf_engine.SetItemAttrText ( itemtype => itemType,
5644 itemkey => itemkey,
5645 aname => 'PREPARER_DISPLAY_NAME' ,
5646 avalue => x_user_display_name);
5647
5648 /* Get the translated values for the DOC_TYPE, DOC_SUBTYPE, AUTH_STATUS and
5649 ** CLOSED_CODE. These will be displayed in the notifications.
5650 */
5651 l_doc_type := wf_engine.GetItemAttrText (itemtype => itemtype,
5652 itemkey => itemkey,
5653 aname => 'DOCUMENT_TYPE');
5654
5655 l_doc_subtype := wf_engine.GetItemAttrText (itemtype => itemtype,
5656 itemkey => itemkey,
5657 aname => 'DOCUMENT_SUBTYPE');
5658
5659 OPEN C1(ReqHdr_rec.authorization_status);
5660 FETCH C1 into l_auth_stat;
5661 CLOSE C1;
5662
5663 OPEN C2(ReqHdr_rec.closed_code);
5664 FETCH C2 into l_closed_code;
5665 CLOSE C2;
5666
5667 /* Bug# 2616355: kagarwal */
5668
5669 OPEN C3(l_doc_type, l_doc_subtype);
5670 FETCH C3 into l_doc_type_disp;
5671 CLOSE C3;
5672
5673 /*
5674 OPEN C4(l_doc_subtype);
5675 FETCH C4 into l_doc_subtype_disp;
5676 CLOSE C4;
5677 */
5678
5679 --
5680 wf_engine.SetItemAttrText ( itemtype => itemtype,
5681 itemkey => itemkey,
5682 aname => 'AUTHORIZATION_STATUS_DISP',
5683 avalue => l_auth_stat);
5684 --
5685 wf_engine.SetItemAttrText ( itemtype => itemtype,
5686 itemkey => itemkey,
5687 aname => 'CLOSED_CODE_DISP',
5688 avalue => l_closed_code);
5689 --
5690 wf_engine.SetItemAttrText ( itemtype => itemtype,
5691 itemkey => itemkey,
5692 aname => 'DOCUMENT_TYPE_DISP',
5693 avalue => l_doc_type_disp);
5694 --
5695 /* Bug# 2616355: kagarwal
5696 ** Desc: We will only be using one display attribute for type and
5697 ** subtype - DOCUMENT_TYPE_DISP, hence commenting the code below
5698 */
5699 /*
5700 wf_engine.SetItemAttrText ( itemtype => itemtype,
5701 itemkey => itemkey,
5702 aname => 'DOCUMENT_SUBTYPE_DISP',
5703 avalue => l_doc_subtype_disp);
5704 */
5705
5706 l_doc_id := wf_engine.GetItemAttrNumber (itemtype => itemtype,
5707 itemkey => itemkey,
5708 aname => 'DOCUMENT_ID');
5709
5710 l_currency_code := PO_CORE_S2.get_base_currency;
5711 /*Start Bug#3406460 - call to fnd function to get precision */
5712 fnd_currency.get_info(l_currency_code,
5713 l_precision,
5714 l_ext_precision,
5715 l_min_acct_unit);
5716 /* End Bug#3406460*/
5717
5718 OPEN req_total_csr(l_doc_id,l_precision); --Bug#3406460 added parameter X_precision
5719 FETCH req_total_csr into l_req_amount;
5720 CLOSE req_total_csr;
5721
5722 /* For REQUISITIONS, since every line could have a different currency, then
5723 ** will show the total in the BASE/FUNCTIONAL currency.
5724 ** For POs, we will show it in the Document currency specified by the user.
5725 */
5726
5727 l_req_amount_disp := TO_CHAR(l_req_amount,FND_CURRENCY.GET_FORMAT_MASK(
5728 l_currency_code, g_currency_format_mask));
5729
5730 wf_engine.SetItemAttrText ( itemtype => itemtype,
5731 itemkey => itemkey,
5732 aname => 'FUNCTIONAL_CURRENCY',
5733 avalue => l_currency_code);
5734
5735 wf_engine.SetItemAttrText ( itemtype => itemtype,
5736 itemkey => itemkey,
5737 aname => 'REQ_AMOUNT_DSP',
5738 avalue => l_req_amount_disp);
5739
5740 OPEN req_tax_csr(l_doc_id);
5741 FETCH req_tax_csr into l_tax_amount;
5742 CLOSE req_tax_csr;
5743
5744 l_tax_amount_disp := TO_CHAR(l_tax_amount,FND_CURRENCY.GET_FORMAT_MASK(
5745 l_currency_code, g_currency_format_mask));
5746
5747 wf_engine.SetItemAttrText ( itemtype => itemtype,
5748 itemkey => itemkey,
5749 aname => 'TAX_AMOUNT_DSP',
5750 avalue => l_tax_amount_disp);
5751
5752 l_total_amount := l_req_amount + l_tax_amount;
5753
5754 l_total_amount_disp := TO_CHAR(l_total_amount,FND_CURRENCY.GET_FORMAT_MASK(
5755 l_currency_code, g_currency_format_mask));
5756
5757
5758 /* bug 3105327
5759 support approval currency in notification header and subject
5760 because TOTAL_AMOUNT_DSP is only used in notification,
5761 this bug fix changes the meaning of this attribute from total to
5762 total with currency;
5763 the workflow definition is modified such that
5764 currency atribute is removed from the subject.
5765 */
5766 getReqAmountInfo(itemtype => itemtype,
5767 itemkey => itemkey,
5768 p_function_currency => l_currency_code,
5769 p_total_amount_disp => l_total_amount_disp,
5770 p_total_amount => l_total_amount,
5771 p_req_amount_disp => l_req_amount_disp,
5772 p_req_amount => l_req_amount,
5773 p_tax_amount_disp => l_tax_amount_disp,
5774 p_tax_amount => l_tax_amount,
5775 x_amount_for_subject => l_amount_for_subject,
5776 x_amount_for_header => l_amount_for_header,
5777 x_amount_for_tax => l_amount_for_tax);
5778
5779 PO_WF_UTIL_PKG.SetItemAttrText ( itemtype => itemtype,
5780 itemkey => itemkey,
5781 aname => 'TOTAL_AMOUNT_DSP',
5782 avalue => l_amount_for_subject);
5783
5784 /* begin bug 2480327 notification UI enhancement */
5785
5786 PO_WF_UTIL_PKG.SetItemAttrText ( itemtype => itemtype,
5787 itemkey => itemkey,
5788 aname => 'REQ_AMOUNT_CURRENCY_DSP',
5789 avalue => l_amount_for_header);
5790
5791 PO_WF_UTIL_PKG.SetItemAttrText ( itemtype => itemtype,
5792 itemkey => itemkey,
5793 aname => 'TAX_AMOUNT_CURRENCY_DSP',
5794 avalue => l_amount_for_tax);
5795
5796
5797 /* Bug 2830992
5798 */
5799 begin
5800 select count(1)
5801 into l_num_attachments
5802 from fnd_attached_documents
5803 where pk1_value = to_char(ReqHdr_rec.requisition_header_id)
5804 and entity_name = 'REQ_HEADERS';
5805 exception
5806 when others then
5807 l_num_attachments := 0;
5808 end;
5809
5810 if (l_num_attachments > 0 ) then
5811 PO_WF_UTIL_PKG.SetItemAttrDocument(itemtype => itemtype,
5812 itemkey => itemkey,
5813 aname => 'ATTACHMENT',
5814 documentid =>
5815 'FND:entity=REQ_HEADERS' || '&' || 'pk1name=REQUISITION_HEADER_ID' ||
5816 '&' || 'pk1value='|| ReqHdr_rec.requisition_header_id);
5817 end if;
5818
5819
5820 /* end bug 2480327 notification UI enhancement */
5821
5822 x_progress := 'SetReqHdrAttributes (end): : ' || l_auth_stat ||
5823 l_currency_code || l_req_amount_disp;
5824 IF (g_po_wf_debug = 'Y') THEN
5825 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
5826 END IF;
5827
5828 if (ReqHdr_rec.NOTE_TO_AUTHORIZER is not null) then
5829 PO_WF_UTIL_PKG.SetItemAttrText ( itemtype => itemtype,
5830 itemkey => itemkey,
5831 aname => 'JUSTIFICATION',
5832 avalue => ReqHdr_rec.NOTE_TO_AUTHORIZER);
5833 end if;
5834
5835 EXCEPTION
5836 WHEN OTHERS THEN
5837 wf_core.context('PO_REQAPPROVAL_INIT1','SetReqHdrAttributes',x_progress);
5838 raise;
5839
5840
5841 end SetReqHdrAttributes;
5842
5843 --
5844 -- procedure SetReqAuthStat, SetPOAuthStat, SetRelAuthStat
5845 -- This procedure sets the document status to IN PROCESS, if called at the beginning of the
5846 -- Approval Workflow,
5847 -- or to INCOMPLETE if doc failed STATE VERIFICATION or COMPLETENESS check at the
5848 -- beginning of WF,
5849 -- or to it's original status if No Approver was found or doc failed STATE VERIFICATION
5850 -- or COMPLETENESS check before APPROVE, REJECT or FORWARD
5851
5852 procedure SetReqAuthStat(p_document_id in number, itemtype in varchar2,itemkey in varchar2,note varchar2,
5853 p_auth_status in varchar2) is
5854 pragma AUTONOMOUS_TRANSACTION;
5855
5856 l_requisition_header_id number;
5857 x_progress varchar2(3):= '000';
5858
5859 BEGIN
5860
5861 l_requisition_header_id := p_document_id;
5862
5863 /* If this is for the upgrade, then only put in the ITEMTYPE/ITEMKEY.
5864 ** We should not change the doc status to IN PROCESS (it could have been
5865 ** PRE-APPROVED).
5866 ** If normal processing then at this point the status is NOT 'IN PROCESS'
5867 ** or 'PRE-APPROVED', therefore we should update the status to IN PROCESS.
5868 */
5869
5870 /* Bug# 1894960: kagarwal
5871 ** Desc: Requisitons Upgraded from 10.7 fails to set the status of Requisiton
5872 ** to Pre-Approved.
5873 **
5874 ** Reason being that when the procedure SetReqAuthStat() is called to set the
5875 ** Requisiton status to Pre-Approved, the conditon
5876 ** "IF (note = 'UPGRADE_TO_R11')" do not set the authorization status causes
5877 ** the Requisiton to remain in the existing status.
5878 ** Hence the Upgraded Requisitons can never be set to 'Pre-Approved' status and
5879 ** the approval process will always return the Req with Notification
5880 ** "No Approver Found".
5881 **
5882 ** Whereas the reason for this condition was to not set the status of upgrade
5883 ** Reqs to IN PROCESS as it could have been PRE-APPROVED.
5884 **
5885 ** Changed the procedure SetReqAuthStat().
5886 **
5887 ** Modified the clause IF note = 'UPGRADE_TO_R11'
5888 **
5889 ** TO:
5890 **
5891 ** IF (note = 'UPGRADE_TO_R11' and p_auth_status = 'IN PROCESS') THEN
5892 **
5893 ** Now when the approval process will call the procedure SetReqAuthStat()
5894 ** to set the Requisiton to 'Pre-Approved' status then it will go to the
5895 ** else part and set its authorization status to 'Pre-Approved'.
5896 */
5897
5898 IF (note = 'UPGRADE_TO_R11' and p_auth_status = 'IN PROCESS') THEN
5899
5900 update po_requisition_headers set
5901 WF_ITEM_TYPE = itemtype,
5902 WF_ITEM_KEY = itemkey,
5903 active_shopping_cart_flag = NULL,
5904 last_updated_by = fnd_global.user_id,
5905 last_update_login = fnd_global.login_id,
5906 last_update_date = sysdate
5907 where requisition_header_id = l_requisition_header_id;
5908
5909 ELSE
5910
5911 update po_requisition_headers set
5912 AUTHORIZATION_STATUS = p_auth_status,
5913 WF_ITEM_TYPE = itemtype,
5914 WF_ITEM_KEY = itemkey,
5915 active_shopping_cart_flag = NULL,
5916 last_updated_by = fnd_global.user_id,
5917 last_update_login = fnd_global.login_id,
5918 last_update_date = sysdate
5919 where requisition_header_id = l_requisition_header_id;
5920
5921 END IF;
5922
5923 commit;
5924
5925 EXCEPTION
5926 WHEN OTHERS THEN
5927 wf_core.context('PO_REQAPPROVAL_INIT1','SetReqAuthStat',x_progress);
5928 raise;
5929
5930 END SetReqAuthStat;
5931
5932 --
5933 procedure SetPOAuthStat(p_document_id in number, itemtype in varchar2,itemkey in varchar2, note varchar2,
5934 p_auth_status in varchar2) is
5935 pragma AUTONOMOUS_TRANSACTION;
5936
5937 l_po_header_id NUMBER;
5938 x_progress varchar2(3):= '000';
5939
5940 BEGIN
5941
5942 x_progress := '001';
5943
5944 l_po_header_id := p_document_id;
5945
5946 /* If this is for the upgrade, then only put in the ITEMTYPE/ITEMKEY.
5947 ** We should not change the doc status to IN PROCESS (it could have been
5948 ** PRE-APPROVED).
5949 ** If normal processing then at this point the status is NOT 'IN PROCESS'
5950 ** or 'PRE-APPROVED', therefore we should update the status to IN PROCESS.
5951 */
5952 IF note = 'UPGRADE_TO_R11' THEN
5953
5954 update po_headers set
5955 WF_ITEM_TYPE = itemtype,
5956 WF_ITEM_KEY = itemkey,
5957 last_updated_by = fnd_global.user_id,
5958 last_update_login = fnd_global.login_id,
5959 last_update_date = sysdate
5960 where po_header_id = l_po_header_id;
5961
5962 ELSE
5963
5964 update po_headers set
5965 AUTHORIZATION_STATUS = p_auth_status,
5966 WF_ITEM_TYPE = itemtype,
5967 WF_ITEM_KEY = itemkey,
5968 last_updated_by = fnd_global.user_id,
5969 last_update_login = fnd_global.login_id,
5970 last_update_date = sysdate
5971 ,submit_date = decode(p_auth_status,
5972 'INCOMPLETE', to_date(null),submit_date) --<DBI Req Fulfillment 11.5.11>
5973 where po_header_id = l_po_header_id;
5974 END IF;
5975
5976 commit;
5977
5978 EXCEPTION
5979 WHEN OTHERS THEN
5980 wf_core.context('PO_REQAPPROVAL_INIT1','SetPOAuthStat',x_progress);
5981 raise;
5982
5983 END SetPOAuthStat;
5984
5985 --
5986 procedure SetRelAuthStat(p_document_id in number, itemtype in varchar2,itemkey in varchar2, note varchar2,
5987 p_auth_status in varchar2) is
5988 pragma AUTONOMOUS_TRANSACTION;
5989
5990 l_Release_header_id NUMBER;
5991 x_progress varchar2(3):= '000';
5992
5993 BEGIN
5994
5995 x_progress := '001';
5996
5997 l_Release_header_id := p_document_id;
5998
5999 /* If this is for the upgrade, then only put in the ITEMTYPE/ITEMKEY.
6000 ** We should not change the doc status to IN PROCESS (it could have been
6001 ** PRE-APPROVED).
6002 ** If normal processing then at this point the status is NOT 'IN PROCESS'
6003 ** or 'PRE-APPROVED', therefore we should update the status to IN PROCESS.
6004 */
6005 IF note = 'UPGRADE_TO_R11' THEN
6006
6007 update po_releases set
6008 WF_ITEM_TYPE = itemtype,
6009 WF_ITEM_KEY = itemkey,
6010 last_updated_by = fnd_global.user_id,
6011 last_update_login = fnd_global.login_id,
6012 last_update_date = sysdate
6013 where po_release_id = l_Release_header_id;
6014
6015 ELSE
6016
6017 update po_releases set
6018 AUTHORIZATION_STATUS = p_auth_status,
6019 WF_ITEM_TYPE = itemtype,
6020 WF_ITEM_KEY = itemkey,
6021 last_updated_by = fnd_global.user_id,
6022 last_update_login = fnd_global.login_id,
6023 last_update_date = sysdate
6024 ,submit_date = decode(p_auth_status,
6025 'INCOMPLETE', to_date(null),submit_date) --<DBI Req Fulfillment 11.5.11>
6026 where po_release_id = l_Release_header_id;
6027 END IF;
6028
6029 commit;
6030
6031 EXCEPTION
6032 WHEN OTHERS THEN
6033 wf_core.context('PO_REQAPPROVAL_INIT1','SetRelAuthStat',x_progress);
6034 raise;
6035
6036 END SetRelAuthStat;
6037 --
6038 --
6039 procedure UpdtReqItemtype(itemtype in varchar2,itemkey in varchar2, p_doc_id in number) is
6040 pragma AUTONOMOUS_TRANSACTION;
6041 x_progress varchar2(3):= '000';
6042
6043 BEGIN
6044
6045 x_progress := '001';
6046
6047 update po_requisition_headers set
6048 WF_ITEM_TYPE = itemtype,
6049 WF_ITEM_KEY = itemkey,
6050 last_updated_by = fnd_global.user_id,
6051 last_update_login = fnd_global.login_id,
6052 last_update_date = sysdate
6053 where requisition_header_id = p_doc_id;
6054
6055 commit;
6056
6057 EXCEPTION
6058 WHEN OTHERS THEN
6059 wf_core.context('PO_REQAPPROVAL_INIT1','UpdtReqItemtype',x_progress);
6060 raise;
6061
6062 END UpdtReqItemtype;
6063
6064 --
6065 procedure UpdtPOItemtype(itemtype in varchar2,itemkey in varchar2, p_doc_id in number) is
6066 pragma AUTONOMOUS_TRANSACTION;
6067
6068 x_progress varchar2(3):= '000';
6069
6070 BEGIN
6071
6072 x_progress := '001';
6073
6074 update po_headers set
6075 WF_ITEM_TYPE = itemtype,
6076 WF_ITEM_KEY = itemkey,
6077 last_updated_by = fnd_global.user_id,
6078 last_update_login = fnd_global.login_id,
6079 last_update_date = sysdate
6080 ,submit_date = sysdate --<DBI Req Fulfillment 11.5.11>
6081 where po_header_id = p_doc_id;
6082
6083 commit;
6084
6085 EXCEPTION
6086 WHEN OTHERS THEN
6087 wf_core.context('PO_REQAPPROVAL_INIT1','UpdtPOItemtype',x_progress);
6088 raise;
6089
6090 END UpdtPOItemtype;
6091
6092
6093 --
6094 procedure UpdtRelItemtype(itemtype in varchar2,itemkey in varchar2, p_doc_id in number) is
6095 pragma AUTONOMOUS_TRANSACTION;
6096
6097 x_progress varchar2(3):= '000';
6098
6099 BEGIN
6100
6101 x_progress := '001';
6102
6103 update po_releases set
6104 WF_ITEM_TYPE = itemtype,
6105 WF_ITEM_KEY = itemkey,
6106 last_updated_by = fnd_global.user_id,
6107 last_update_login = fnd_global.login_id,
6108 last_update_date = sysdate
6109 ,submit_date = sysdate --<DBI Req Fulfillment 11.5.11>
6110 where po_release_id = p_doc_id;
6111
6112 commit;
6113
6114 EXCEPTION
6115 WHEN OTHERS THEN
6116 wf_core.context('PO_REQAPPROVAL_INIT1','UpdtRelItemtype',x_progress);
6117 raise;
6118
6119 END UpdtRelItemtype;
6120
6121 --
6122 procedure GetCanOwnerApprove(itemtype in varchar2,itemkey in varchar2,
6123 CanOwnerApproveFlag out NOCOPY varchar2)
6124 is
6125
6126 Cursor C1(p_document_type_code VARCHAR2, p_document_subtype VARCHAR2) is
6127 select NVL(can_preparer_approve_flag,'N')
6128 from po_document_types
6129 where document_type_code = p_document_type_code
6130 and document_subtype = p_document_subtype;
6131
6132 l_document_type_code VARCHAR2(25);
6133 l_document_subtype VARCHAR2(25);
6134 x_progress varchar2(3):= '000';
6135
6136 BEGIN
6137
6138 x_progress := '001';
6139 l_document_type_code := wf_engine.GetItemAttrText (itemtype => itemtype,
6140 itemkey => itemkey,
6141 aname => 'DOCUMENT_TYPE');
6142
6143 l_document_subtype := wf_engine.GetItemAttrText (itemtype => itemtype,
6144 itemkey => itemkey,
6145 aname => 'DOCUMENT_SUBTYPE');
6146
6147 open C1(l_document_type_code, l_document_subtype);
6148 Fetch C1 into CanOwnerApproveFlag;
6149 close C1;
6150
6151 EXCEPTION
6152 WHEN OTHERS THEN
6153 wf_core.context('PO_REQAPPROVAL_INIT1','GetCanOwnerApprove',x_progress);
6154 raise;
6155
6156 END GetCanOwnerApprove;
6157 --
6158
6159 /*****************************************************************************
6160 *
6161 * Supporting APIs declared in the package spec.
6162 *****************************************************************************/
6163
6164
6165 PROCEDURE get_multiorg_context(document_type varchar2, document_id number,
6166 x_orgid IN OUT NOCOPY number) is
6167
6168 cursor get_req_orgid is
6169 select org_id
6170 from po_requisition_headers_all
6171 where requisition_header_id = document_id;
6172
6173 cursor get_po_orgid is
6174 select org_id
6175 from po_headers_all
6176 where po_header_id = document_id;
6177
6178 cursor get_release_orgid is
6179 select org_id
6180 from po_releases_all
6181 where po_release_id = document_id;
6182
6183 x_progress varchar2(3):= '000';
6184
6185 BEGIN
6186
6187 x_progress := '001';
6188 IF document_type = 'REQUISITION' THEN
6189
6190
6191 OPEN get_req_orgid;
6192 FETCH get_req_orgid into x_orgid;
6193 CLOSE get_req_orgid;
6194
6195 ELSIF document_type IN ( 'PO','PA' ) THEN
6196
6197 OPEN get_po_orgid;
6198 FETCH get_po_orgid into x_orgid;
6199 CLOSE get_po_orgid;
6200
6201 ELSIF document_type = 'RELEASE' THEN
6202
6203 OPEN get_release_orgid ;
6204 FETCH get_release_orgid into x_orgid;
6205 CLOSE get_release_orgid;
6206
6207 END IF;
6208
6209
6210 EXCEPTION
6211 WHEN OTHERS THEN
6212 wf_core.context('PO_REQAPPROVAL_INIT1','get_multiorg_context',x_progress);
6213 raise;
6214
6215 END get_multiorg_context;
6216
6217
6218 --
6219 PROCEDURE get_employee_id(p_username IN varchar2, x_employee_id OUT NOCOPY number) is
6220
6221 -- DEBUG: Is this the best way to get the emp_id of the username
6222 -- entered as a forward-to in the notification?????
6223 --
6224 /* 1578061 add orig system condition to enhance performance. */
6225
6226 cursor c_empid is
6227 select ORIG_SYSTEM_ID
6228 from wf_users WF
6229 where WF.name = p_username
6230 and ORIG_SYSTEM NOT IN ('HZ_PARTY', 'POS', 'ENG_LIST', 'CUST_CONT');
6231
6232 x_progress varchar2(3):= '000';
6233
6234 BEGIN
6235
6236 open c_empid;
6237 fetch c_empid into x_employee_id;
6238
6239 /* DEBUG: get Vance and Kevin opinion on this:
6240 ** If no employee_id is found then return null. We will
6241 ** treat that as the user not supplying a forward-to username.
6242 */
6243 IF c_empid%NOTFOUND THEN
6244
6245 x_employee_id := NULL;
6246
6247 END IF;
6248
6249 close c_empid;
6250
6251 EXCEPTION
6252 WHEN OTHERS THEN
6253 wf_core.context('PO_REQAPPROVAL_INIT1','get_employee_id',p_username);
6254 raise;
6255
6256
6257 END get_employee_id;
6258
6259
6260 --
6261 PROCEDURE get_user_name(p_employee_id IN number, x_username OUT NOCOPY varchar2,
6262 x_user_display_name OUT NOCOPY varchar2) is
6263
6264 p_orig_system varchar2(20);
6265
6266 BEGIN
6267
6268 p_orig_system:= 'PER';
6269
6270 WF_DIRECTORY.GetUserName(p_orig_system,
6271 p_employee_id,
6272 x_username,
6273 x_user_display_name);
6274
6275 EXCEPTION
6276 WHEN OTHERS THEN
6277 wf_core.context('PO_REQAPPROVAL_INIT1','get_user_name',to_char(p_employee_id));
6278 raise;
6279
6280 END get_user_name;
6281
6282
6283 --
6284 PROCEDURE InsertActionHistSubmit(itemtype varchar2, itemkey varchar2,
6285 p_doc_id number, p_doc_type varchar2,
6286 p_doc_subtype varchar2, p_employee_id number,
6287 p_action varchar2, p_note varchar2,
6288 p_path_id number) is
6289
6290 pragma AUTONOMOUS_TRANSACTION;
6291
6292 l_auth_stat varchar2(25);
6293 l_action_code varchar2(25);
6294 l_revision_num number := NULL;
6295 l_hist_count number := NULL;
6296 l_sequence_num number := NULL;
6297 l_approval_path_id number;
6298
6299 CURSOR action_hist_cursor(doc_id number , doc_type varchar2) is
6300 select max(sequence_num)
6301 from po_action_history
6302 where object_id= doc_id and
6303 object_type_code = doc_type;
6304
6305 CURSOR action_hist_code_cursor (doc_id number , doc_type varchar2, seq_num number) is
6306 select action_code
6307 from po_action_history
6308 where object_id = doc_id and
6309 object_type_code = doc_type and
6310 sequence_num = seq_num;
6311
6312
6313 x_progress varchar2(3):='000';
6314
6315 BEGIN
6316
6317 /* Get the document authorization status.
6318 ** has been submitted before, i.e.
6319 ** First insert a row with a SUBMIT action.
6320 ** Then insert a row with a NULL ACTION_CODE to simulate the forward-to
6321 ** since the doc status has been changed to IN PROCESS.
6322 */
6323
6324 x_progress := '001';
6325
6326 l_approval_path_id := p_path_id;
6327
6328 IF p_doc_type='REQUISITION' THEN
6329
6330 x_progress := '002';
6331
6332 select NVL(authorization_status, 'INCOMPLETE') into l_auth_stat
6333 from PO_REQUISITION_HEADERS
6334 where requisition_header_id = p_doc_id;
6335
6336
6337 ELSIF p_doc_type IN ('PO','PA') THEN
6338
6339 x_progress := '003';
6340
6341 select NVL(authorization_status,'INCOMPLETE'),revision_num
6342 into l_auth_stat, l_revision_num
6343 from PO_HEADERS
6344 where po_header_id = p_doc_id;
6345
6346 ELSIF p_doc_type = 'RELEASE' THEN
6347
6348 x_progress := '004';
6349
6350 select NVL(authorization_status,'INCOMPLETE'),revision_num
6351 into l_auth_stat, l_revision_num
6352 from PO_RELEASES
6353 where po_release_id = p_doc_id;
6354
6355 END IF;
6356
6357 x_progress := '005';
6358
6359 /* Check if this document had been submitted to workflow at some point
6360 ** and somehow kicked out. If that's the case, the sequence number
6361 ** needs to be incremented by one. Otherwise start at zero.
6362 */
6363 OPEN action_hist_cursor(p_doc_id , p_doc_type );
6364 FETCH action_hist_cursor into l_sequence_num;
6365 CLOSE action_hist_cursor;
6366 IF l_sequence_num is NULL THEN
6367 l_sequence_num := 0;
6368 ELSE
6369 OPEN action_hist_code_cursor(p_doc_id , p_doc_type, l_sequence_num);
6370 FETCH action_hist_code_cursor into l_action_code;
6371 l_sequence_num := l_sequence_num +1;
6372 END IF;
6373
6374
6375 x_progress := '006';
6376 IF ((l_sequence_num = 0)
6377 OR
6378 (l_sequence_num > 0 and l_action_code is NOT NULL)) THEN
6379 INSERT into PO_ACTION_HISTORY
6380 (object_id,
6381 object_type_code,
6382 object_sub_type_code,
6383 sequence_num,
6384 last_update_date,
6385 last_updated_by,
6386 creation_date,
6387 created_by,
6388 action_code,
6389 action_date,
6390 employee_id,
6391 note,
6392 object_revision_num,
6393 last_update_login,
6394 request_id,
6395 program_application_id,
6396 program_id,
6397 program_update_date,
6398 approval_path_id,
6399 offline_code)
6400 VALUES
6401 (p_doc_id,
6402 p_doc_type,
6403 p_doc_subtype,
6404 l_sequence_num,
6405 sysdate,
6406 fnd_global.user_id,
6407 sysdate,
6408 fnd_global.user_id,
6409 p_action,
6410 decode(p_action, '',to_date(null), sysdate),
6411 p_employee_id,
6412 p_note,
6413 l_revision_num,
6414 fnd_global.login_id,
6415 0,
6416 0,
6417 0,
6418 '',
6419 l_approval_path_id,
6420 '' );
6421
6422 ELSE
6423 l_sequence_num := l_sequence_num - 1;
6424 UPDATE PO_ACTION_HISTORY
6425 set object_id = p_doc_id,
6426 object_type_code = p_doc_type,
6427 object_sub_type_code = p_doc_subtype,
6428 sequence_num = l_sequence_num,
6429 last_update_date = sysdate,
6430 last_updated_by = fnd_global.user_id,
6431 creation_date = sysdate,
6432 created_by = fnd_global.user_id,
6433 action_code = p_action,
6434 action_date = decode(p_action, '',to_date(null), sysdate),
6435 employee_id = p_employee_id,
6436 note = p_note,
6437 object_revision_num = l_revision_num,
6438 last_update_login = fnd_global.login_id,
6439 request_id = 0,
6440 program_application_id = 0,
6441 program_id = 0,
6442 program_update_date = '',
6443 approval_path_id = l_approval_path_id,
6444 offline_code = ''
6445 WHERE
6446 object_id= p_doc_id and
6447 object_type_code = p_doc_type and
6448 sequence_num = l_sequence_num;
6449
6450 END IF;
6451
6452 -- iProcurement: Approval History changes.
6453 -- Null action code will not be inserted into po_action_history table.
6454
6455 -- bug4643013
6456 -- Still insert null action during submission except for requisition
6457
6458 IF (p_doc_type <> 'REQUISITION') THEN
6459
6460 INSERT into PO_ACTION_HISTORY
6461 (object_id,
6462 object_type_code,
6463 object_sub_type_code,
6464 sequence_num,
6465 last_update_date,
6466 last_updated_by,
6467 creation_date,
6468 created_by,
6469 action_code,
6470 action_date,
6471 employee_id,
6472 note,
6473 object_revision_num,
6474 last_update_login,
6475 request_id,
6476 program_application_id,
6477 program_id,
6478 program_update_date,
6479 approval_path_id,
6480 offline_code)
6481 VALUES
6482 (p_doc_id,
6483 p_doc_type,
6484 p_doc_subtype,
6485 l_sequence_num + 1,
6486 sysdate,
6487 fnd_global.user_id,
6488 sysdate,
6489 fnd_global.user_id,
6490 NULL, -- ACTION_CODE
6491 decode(p_action, '',to_date(null), sysdate),
6492 p_employee_id,
6493 NULL,
6494 l_revision_num,
6495 fnd_global.login_id,
6496 0,
6497 0,
6498 0,
6499 '',
6500 0,
6501 '' );
6502 END IF;
6503
6504 x_progress := '007';
6505
6506 commit;
6507 EXCEPTION
6508
6509 WHEN OTHERS THEN
6510 wf_core.context('PO_REQAPPROVAL_INIT1','InsertActionHistSubmit',x_progress);
6511 raise;
6512
6513 END InsertActionHistSubmit;
6514
6515
6516 --
6517
6518 -- <ENCUMBRANCE FPJ START>
6519 -- Rewriting the following procedure to use the encumbrance APIs
6520
6521 FUNCTION EncumbOn_DocUnreserved(
6522 p_doc_type varchar2,
6523 p_doc_subtype varchar2,
6524 p_doc_id number)
6525 RETURN varchar2
6526 IS
6527 PRAGMA AUTONOMOUS_TRANSACTION;
6528 -- The autonomous_transaction is required due to the use of the global temp
6529 -- table PO_ENCUMBRANCE_GT, as the call to do_reserve later in the workflow
6530 -- process is in an autonomous transaction because it must commit.
6531 -- Without this autonomous transaction, the following error is raised:
6532 -- ORA-14450: attempt to access a transactional temp table already in use
6533
6534 p_return_status varchar2(1);
6535 p_reservable_flag varchar2(1);
6536 l_progress varchar2(200);
6537
6538 l_unreserved_flag VARCHAR2(1) := 'N';
6539 l_return_exc EXCEPTION;
6540
6541 BEGIN
6542
6543 l_progress := '000';
6544
6545 -- If the document is contract then we do not encumber it
6546
6547 IF p_doc_subtype = 'CONTRACT' THEN
6548
6549 RAISE l_return_exc;
6550
6551 END IF;
6552
6553 -- Check if encumbrance is on
6554
6555 IF NOT (PO_CORE_S.is_encumbrance_on(
6556 p_doc_type => p_doc_type,
6557 p_org_id => NULL))
6558 THEN
6559 l_progress := '010';
6560 RAISE l_return_exc;
6561 END IF;
6562
6563 l_progress := '020';
6564
6565 -- Check if there is any distribution that can be reserved
6566
6567 PO_DOCUMENT_FUNDS_PVT.is_reservable(
6568 x_return_status => p_return_status
6569 , p_doc_type => p_doc_type
6570 , p_doc_subtype => p_doc_subtype
6571 , p_doc_level => PO_DOCUMENT_FUNDS_PVT.g_doc_level_HEADER
6572 , p_doc_level_id => p_doc_id
6573 , x_reservable_flag => p_reservable_flag);
6574
6575 l_progress := '030';
6576
6577 IF p_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
6578 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6579 ELSIF p_return_status = FND_API.G_RET_STS_ERROR THEN
6580 RAISE FND_API.G_EXC_ERROR;
6581 END IF;
6582
6583 l_progress := '040';
6584
6585 IF (p_return_status = FND_API.G_RET_STS_SUCCESS) AND
6586 (p_reservable_flag = PO_DOCUMENT_FUNDS_PVT.g_parameter_YES) THEN
6587
6588 l_progress := '050';
6589
6590 l_unreserved_flag := 'Y';
6591 END IF;
6592
6593 l_progress := '060';
6594
6595 ROLLBACK;
6596 RETURN(l_unreserved_flag);
6597
6598 EXCEPTION
6599
6600 WHEN l_return_exc THEN
6601 ROLLBACK;
6602 RETURN(l_unreserved_flag);
6603
6604 WHEN OTHERS THEN
6605 wf_core.context('PO_REQAPPROVAL_INIT1','EncumbOn_DocUnreserved',
6606 l_progress);
6607
6608 ROLLBACK;
6609 RAISE;
6610
6611 END EncumbOn_DocUnreserved;
6612
6613 -- <ENCUMBRANCE FPJ END>
6614
6615 PROCEDURE PrintDocument(itemtype varchar2,itemkey varchar2) is
6616
6617 l_document_type VARCHAR2(25);
6618 l_document_num VARCHAR2(30);
6619 l_release_num NUMBER;
6620 l_request_id NUMBER := 0;
6621 l_qty_precision VARCHAR2(30);
6622 l_user_id VARCHAR2(30);
6623
6624 --Context Setting Revamp
6625 l_printer VARCHAR2(30);
6626 l_conc_copies NUMBER;
6627 l_conc_save_output VARCHAR2(1);
6628 l_conc_save_output_bool BOOLEAN;
6629 l_spo_result BOOLEAN;
6630
6631 x_progress varchar2(200);
6632
6633 /*Bug 6692126 start */
6634 l_document_id number;
6635 l_withterms varchar2(1);
6636 l_document_subtype po_headers.type_lookup_code%TYPE;
6637 /*Bug 6692126 end */
6638
6639 BEGIN
6640
6641 x_progress := 'PO_REQAPPROVAL_INIT1.PrintDocument: 01';
6642 IF (g_po_wf_debug = 'Y') THEN
6643 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
6644 END IF;
6645
6646 -- Get the profile option report_quantity_precision
6647
6648 fnd_profile.get('REPORT_QUANTITY_PRECISION', l_qty_precision);
6649
6650 /* Bug 2012896: the profile option REPORT_QUANTITY_PRECISION could be
6651 NULL. Even at site level! And in that case the printing of report
6652 results into the inappropriate printing of quantities.
6653 Fix: Now, if the profile option is NULL, we are setting the variable
6654 l_qty_precision to 2, so that the printing would not fail. Why 2 ?
6655 This is the default defined in the definition of the said profile
6656 option. */
6657
6658 IF l_qty_precision IS NULL THEN
6659 l_qty_precision := '2';
6660 END IF;
6661
6662 -- Get the user id for the current user. This information
6663 -- is used when sending concurrent request.
6664
6665 FND_PROFILE.GET('USER_ID', l_user_id);
6666
6667 -- Send the concurrent request to print document.
6668
6669 l_document_type := wf_engine.GetItemAttrText (itemtype => itemtype,
6670 itemkey => itemkey,
6671 aname => 'DOCUMENT_TYPE');
6672
6673 l_document_num := wf_engine.GetItemAttrText (itemtype => itemtype,
6674 itemkey => itemkey,
6675 aname => 'DOCUMENT_NUMBER');
6676
6677 /*Bug 6692126 Get the item attributes DOCUMENT_ID,DOCUMENT_SUBTYPE
6678 and WITH_TERMS and pass it to Print_PO and Print_Release procedures*/
6679
6680 l_document_id := wf_engine.GetItemAttrNumber (itemtype => itemtype,
6681 itemkey => itemkey,
6682 aname => 'DOCUMENT_ID');
6683
6684 l_document_subtype := wf_engine.GetItemAttrText (itemtype => itemtype,
6685 itemkey => itemkey,
6686 aname => 'DOCUMENT_SUBTYPE');
6687
6688 /*Bug6692126 Donot set the item attribute with_terms for requisitions
6689 as this attribute doesnot exist in req approval workflow*/
6690 IF l_document_type <> 'REQUISITION' THEN
6691 l_withterms := wf_engine.GetItemAttrText (itemtype => itemtype,
6692 itemkey => itemkey,
6693 aname => 'WITH_TERMS');
6694 END IF;
6695
6696 -- Bug 4918772
6697 -- The global variable 4918772 should be populated. This is used by
6698 -- the print/fax routines
6699 g_document_subtype := wf_engine.GetItemAttrText (itemtype => itemtype,
6700 itemkey => itemkey,
6701 aname => 'DOCUMENT_SUBTYPE');
6702 -- End Bug 4918772
6703
6704
6705 -- Context Setting Revamp.
6706 /* changed the call from wf_engine.setiteattrtext to
6707 po_wf_util_pkg.setitemattrtext because the later handles
6708 attribute not found exception. req change order wf also
6709 uses these procedures and does not have the preparer_printer
6710 attribute, hence this was required */
6711
6712 l_printer := po_wf_util_pkg.GetItemAttrText (itemtype => itemtype,
6713 itemkey => itemkey,
6714 aname => 'PREPARER_PRINTER');
6715 -- Need to get the no of copies, and save output values for the
6716 -- preparer and pass it to the set_print_options procedure
6717 l_conc_copies := po_wf_util_pkg.GetItemAttrNumber (itemtype => itemtype,
6718 itemkey => itemkey,
6719 aname => 'PREPARER_CONC_COPIES');
6720 l_conc_save_output := po_wf_util_pkg.GetItemAttrText (itemtype => itemtype,
6721 itemkey => itemkey,
6722 aname => 'PREPARER_CONC_SAVE_OUTPUT');
6723
6724 if l_conc_save_output = 'Y' then
6725 l_conc_save_output_bool := TRUE;
6726 else
6727 l_conc_save_output_bool := FALSE;
6728 end if;
6729
6730
6731 -- <Debug start>
6732 x_progress := 'SPO : got printer as '||l_printer||
6733 ' conc_copies '||l_conc_copies||
6734 ' save o/p '||l_conc_save_output;
6735
6736 IF (g_po_wf_debug = 'Y') THEN
6737 PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
6738 END IF;
6739 -- <debug end>
6740
6741 if (l_printer is not null) then
6742 l_spo_result := fnd_request.set_print_options(printer=> l_printer,
6743 copies=> l_conc_copies,
6744 save_output => l_conc_save_output_bool);
6745
6746 if (l_spo_result) then
6747 -- <Debug start>
6748 x_progress := 'SPO:set print options successful';
6749 IF (g_po_wf_debug = 'Y') THEN
6750 PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
6751 END IF;
6752 -- <debug end>
6753 else
6754 -- <Debug start>
6755 x_progress := 'SPO:set print options not successful ';
6756 IF (g_po_wf_debug = 'Y') THEN
6757 PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
6758 END IF;
6759 -- <Debug end>
6760 end if;
6761 end if;
6762
6763 --End Context Setting Revamp.
6764
6765 IF l_document_type = 'REQUISITION' THEN
6766
6767 l_request_id := Print_Requisition(l_document_num, l_qty_precision,
6768 l_user_id);
6769
6770 ELSIF l_document_type = 'RELEASE' THEN
6771
6772 l_release_num := wf_engine.GetItemAttrNumber (itemtype => itemtype,
6773 itemkey => itemkey,
6774 aname => 'RELEASE_NUM');
6775
6776 --Bug 6692126 Pass document_id,documentsubtype parameters
6777 l_request_id := Print_Release(l_document_num, l_qty_precision,
6778 to_char(l_release_num), l_user_id, l_document_id);
6779
6780 ELSE
6781 --Bug 6692126 Pass document_id,subtype and with terms parameters
6782 l_request_id := Print_PO(l_document_num, l_qty_precision,
6783 l_user_id,
6784 l_document_id,l_document_subtype,l_withterms);
6785 END IF;
6786
6787 wf_engine.SetItemAttrNumber (itemtype => itemtype,
6788 itemkey => itemkey,
6789 aname => 'CONCURRENT_REQUEST_ID',
6790 avalue => l_request_id);
6791
6792 x_progress := 'PO_REQAPPROVAL_INIT1.PrintDocument: 02. request_id= ' || to_char(l_request_id);
6793 IF (g_po_wf_debug = 'Y') THEN
6794 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
6795 END IF;
6796
6797 EXCEPTION
6798
6799 WHEN OTHERS THEN
6800 wf_core.context('PO_REQAPPROVAL_INIT1','PrintDocument',x_progress);
6801 raise;
6802
6803 END PrintDocument;
6804
6805
6806
6807
6808 -- DKC 10/10/99
6809 PROCEDURE FaxDocument(itemtype varchar2,itemkey varchar2) is
6810
6811 l_document_type VARCHAR2(25);
6812 l_document_num VARCHAR2(30);
6813 l_release_num NUMBER;
6814 l_request_id NUMBER := 0;
6815 l_qty_precision VARCHAR2(30);
6816 l_user_id VARCHAR2(30);
6817
6818 l_fax_enable VARCHAR2(25);
6819 l_fax_num VARCHAR2(30); -- 5765243
6820
6821 --Context Setting Revamp
6822 l_spo_result BOOLEAN;
6823 l_printer VARCHAR2(30);
6824 /*Bug 6692126 start */
6825 l_document_id number;
6826 l_withterms varchar2(1);
6827 l_document_subtype po_headers.type_lookup_code%TYPE;
6828 /*Bug 6692126 end */
6829
6830 x_progress varchar2(200);
6831
6832 BEGIN
6833
6834 x_progress := 'PO_REQAPPROVAL_INIT1.FaxDocument: 01';
6835 IF (g_po_wf_debug = 'Y') THEN
6836 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
6837 END IF;
6838
6839 -- Get the profile option report_quantity_precision
6840
6841 fnd_profile.get('REPORT_QUANTITY_PRECISION', l_qty_precision);
6842
6843 -- Get the user id for the current user. This information
6844 -- is used when sending concurrent request.
6845
6846 FND_PROFILE.GET('USER_ID', l_user_id);
6847
6848 -- Send the concurrent request to fax document.
6849
6850 l_document_type := wf_engine.GetItemAttrText (itemtype => itemtype,
6851 itemkey => itemkey,
6852 aname => 'DOCUMENT_TYPE');
6853
6854 l_document_num := wf_engine.GetItemAttrText (itemtype => itemtype,
6855 itemkey => itemkey,
6856 aname => 'DOCUMENT_NUMBER');
6857
6858 /*Bug 6692126 Get the document_id ,document subtype and with terms
6859 item attribute and pass it to Fax_PO and Fax_Release procedures
6860 Donot rely on global variable.Instead get the document subtype
6861 and pass it as a paramter */
6862
6863 l_document_id := wf_engine.GetItemAttrNumber (itemtype => itemtype,
6864 itemkey => itemkey,
6865 aname => 'DOCUMENT_ID');
6866
6867 l_document_subtype := wf_engine.GetItemAttrText (itemtype => itemtype,
6868 itemkey => itemkey,
6869 aname => 'DOCUMENT_SUBTYPE');
6870
6871 l_withterms := wf_engine.GetItemAttrText (itemtype => itemtype,
6872 itemkey => itemkey,
6873 aname => 'WITH_TERMS');
6874
6875 l_document_type := wf_engine.GetItemAttrText (itemtype => itemtype,
6876 itemkey => itemkey,
6877 aname => 'DOCUMENT_TYPE');
6878
6879 -- Bug 4918772
6880 -- The global variable 4918772 should be populated. This is used by
6881 -- the print/fax routines
6882 g_document_subtype := wf_engine.GetItemAttrText (itemtype => itemtype,
6883 itemkey => itemkey,
6884 aname => 'DOCUMENT_SUBTYPE');
6885 -- End Bug 4918772
6886
6887
6888 -- Context Setting revamp : setting the printer to that of the preparer, so that
6889 -- irrespective of who submits the request, the printing should happen
6890 -- on preparer's printer
6891 /* changed the call from wf_engine.setiteattrtext to
6892 po_wf_util_pkg.setitemattrtext because the later handles
6893 attrbute not found exception. req change order wf also
6894 uses these procedures and does not have the preparer_printer
6895 attribute, hence this was required */
6896
6897 l_printer := po_wf_util_pkg.GetItemAttrText (itemtype => itemtype,
6898 itemkey => itemkey,
6899 aname => 'PREPARER_PRINTER');
6900
6901 if (l_printer is not null) then
6902 l_spo_result:= fnd_request.set_print_options(printer=> l_printer);
6903 end if;
6904
6905 IF l_document_type IN ('PO', 'PA') THEN
6906
6907 l_fax_enable := wf_engine.GetItemAttrText (itemtype => itemtype,
6908 itemkey => itemkey,
6909 aname => 'FAX_DOCUMENT');
6910
6911 l_fax_num := wf_engine.GetItemAttrText (itemtype => itemtype,
6912 itemkey => itemkey,
6913 aname => 'FAX_NUMBER');
6914
6915 --Bug 6692126 Pass document_id ,document subtype and with terms parameters
6916
6917 l_request_id := Fax_PO(l_document_num, l_qty_precision,
6918 l_user_id, l_fax_enable, l_fax_num,l_document_id,l_document_subtype,l_withterms);
6919
6920 ELSIF l_document_type = 'RELEASE' THEN
6921
6922 l_release_num := wf_engine.GetItemAttrNumber (itemtype => itemtype,
6923 itemkey => itemkey,
6924 aname => 'RELEASE_NUM');
6925
6926 l_fax_enable := wf_engine.GetItemAttrText (itemtype => itemtype,
6927 itemkey => itemkey,
6928 aname => 'FAX_DOCUMENT');
6929
6930 l_fax_num := wf_engine.GetItemAttrText (itemtype => itemtype,
6931 itemkey => itemkey,
6932 aname => 'FAX_NUMBER');
6933
6934 --Bug 6692126 Pass document_id ,document subtype parameters
6935
6936 l_request_id := Fax_Release(l_document_num, l_qty_precision,
6937 to_char(l_release_num), l_user_id,
6938 l_fax_enable, l_fax_num,l_document_id);
6939
6940 END IF;
6941
6942 wf_engine.SetItemAttrNumber (itemtype => itemtype,
6943 itemkey => itemkey,
6944 aname => 'CONCURRENT_REQUEST_ID',
6945 avalue => l_request_id);
6946
6947 x_progress := 'PO_REQAPPROVAL_INIT1.FaxDocument: 02. request_id= ' || to_char(l_request_id);
6948 IF (g_po_wf_debug = 'Y') THEN
6949 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
6950 END IF;
6951
6952 EXCEPTION
6953
6954 WHEN OTHERS THEN
6955 wf_core.context('PO_REQAPPROVAL_INIT1','FaxDocument',x_progress);
6956 raise;
6957
6958 END FaxDocument;
6959
6960
6961
6962
6963
6964
6965 FUNCTION Print_Requisition(p_doc_num varchar2, p_qty_precision varchar,
6966 p_user_id varchar2) RETURN number is
6967
6968 l_request_id NUMBER;
6969 x_progress varchar2(200);
6970
6971 BEGIN
6972 --<R12 MOAC START>
6973 po_moac_utils_pvt.set_request_context(po_moac_utils_pvt.get_current_org_id);
6974 --<R12 MOAC END>
6975
6976 l_request_id := fnd_request.submit_request('PO',
6977 'PRINTREQ',
6978 null,
6979 null,
6980 false,
6981 'P_REQ_NUM_FROM=' || p_doc_num,
6982 'P_REQ_NUM_TO=' || p_doc_num,
6983 'P_QTY_PRECISION=' || p_qty_precision,
6984 fnd_global.local_chr(0),
6985 NULL,
6986 NULL,
6987 NULL,
6988 NULL, NULL,
6989 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
6990 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
6991 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
6992 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
6993 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
6994 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
6995 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
6996 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
6997 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
6998 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
6999 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7000 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7001 NULL, NULL, NULL, NULL, NULL, NULL, NULL);
7002
7003 return(l_request_id);
7004
7005 EXCEPTION
7006
7007 WHEN OTHERS THEN
7008 wf_core.context('PO_REQAPPROVAL_INIT1','Print_Requisition',x_progress);
7009 raise;
7010 END;
7011
7012 FUNCTION Print_PO(p_doc_num varchar2, p_qty_precision varchar,
7013 p_user_id varchar2,p_document_id number default NULL,
7014 p_document_subtype varchar2 default NULL,p_withterms varchar2 default NULL) RETURN number is
7015
7016 l_request_id number;
7017 x_progress varchar2(200);
7018
7019 BEGIN
7020 --<POC FPJ Start>
7021 --Bug#3528330 used the procedure po_communication_profile() to check for the
7022 --PO output format option instead of checking for the installation of
7023 --XDO product
7024 --Bug5080617 Pass the parameters P_PO_TEMPLATE_CODE and P_CONTRACT_TEMPLATE_CODE as null
7025 IF (PO_COMMUNICATION_PVT.PO_COMMUNICATION_PROFILE = 'T' and
7026 g_document_subtype <>'PLANNED') THEN
7027 --Launching the Dispatch Purchase Order Concurrent Program
7028 --<R12 MOAC START>
7029 po_moac_utils_pvt.set_request_context(po_moac_utils_pvt.get_current_org_id);
7030 --<R12 MOAC END>
7031
7032 l_request_id := fnd_request.submit_request('PO',
7033 'POXPOPDF',
7034 null,
7035 null,
7036 false,
7037 'R',--P_report_type
7038 null ,--P_agent_name
7039 p_doc_num ,--P_po_num_from
7040 p_doc_num ,--P_po_num_to
7041 null ,--P_relaese_num_from
7042 null ,--P_release_num_to
7043 null ,--P_date_from
7044 null ,--P_date_to
7045 null ,--P_approved_flag
7046 'N' ,--P_test_flag
7047 null ,--P_print_releases
7048 null ,--P_sortby
7049 p_user_id ,--P_user_id
7050 null ,--P_fax_enable
7051 null ,--P_fax_number
7052 'Y' ,--P_BLANKET_LINES
7053 'Communicate' ,--View_or_Communicate,
7054 p_withterms ,--P_WITHTERMS Bug# 6692126 instead of 'Y'
7055 'N' ,--P_storeFlag Bug#3528330 Changed to "N"
7056 'Y' ,--P_PRINT_FLAG
7057 p_document_id ,--P_DOCUMENT_ID Bug# 6692126
7058 null ,--P_REVISION_NUM
7059 null ,--P_AUTHORIZATION_STATUS
7060 p_document_subtype, --P_DOCUMENT_TYPE Bug# 6692126
7061 0 ,--P_max_zip_size, <PO Attachment Support 11i.11>
7062 null ,--P_PO_TEMPLATE_CODE
7063 null ,--P_CONTRACT_TEMPLATE_CODE
7064 fnd_global.local_chr(0),
7065 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7066 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7067 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7068 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7069 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7070 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7071 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7072 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7073 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7074 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7075 NULL, NULL);
7076 --<POC FPJ End>
7077 ELSE
7078
7079 --<R12 MOAC START>
7080 po_moac_utils_pvt.set_request_context(po_moac_utils_pvt.get_current_org_id);
7081 --<R12 MOAC END>
7082
7083 l_request_id := fnd_request.submit_request('PO',
7084 'POXPPO',
7085 null,
7086 null,
7087 false,
7088 'P_REPORT_TYPE=R',
7089 'P_TEST_FLAG=N',
7090 'P_PO_NUM_FROM=' || p_doc_num,
7091 'P_PO_NUM_TO=' || p_doc_num,
7092 'P_USER_ID=' || p_user_id,
7093 'P_QTY_PRECISION=' || p_qty_precision,
7094 'P_BLANKET_LINES=Y',
7095 'P_PRINT_RELEASES=N',
7096 fnd_global.local_chr(0),
7097 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7098 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7099 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7100 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7101 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7102 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7103 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7104 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7105 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7106 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7107 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7108 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7109 NULL, NULL, NULL, NULL, NULL, NULL, NULL);
7110 END IF;
7111
7112 return(l_request_id);
7113
7114 EXCEPTION
7115
7116 WHEN OTHERS THEN
7117 wf_core.context('PO_REQAPPROVAL_INIT1','Print_PO',x_progress);
7118 raise;
7119
7120 END Print_PO;
7121
7122
7123
7124
7125
7126 --DKC 10/10/99
7127 FUNCTION Fax_PO(p_doc_num varchar2, p_qty_precision varchar,
7128 p_user_id varchar2, p_fax_enable varchar2,
7129 p_fax_num varchar2,p_document_id number default NULL,
7130 p_document_subtype varchar2,p_withterms varchar2) RETURN number is
7131
7132 l_request_id number;
7133 x_progress varchar2(200);
7134
7135 BEGIN
7136 --<POC FPJ Start>
7137 --Bug#3528330 used the procedure po_communication_profile() to check for the
7138 --PO output format option instead of checking for the installation of
7139 --XDO product
7140 IF (PO_COMMUNICATION_PVT.PO_COMMUNICATION_PROFILE = 'T' and
7141 g_document_subtype <>'PLANNED') THEN
7142
7143 --Launching the Dispatch Purchase Order Concurrent Program
7144 --<R12 MOAC START>
7145 po_moac_utils_pvt.set_request_context(po_moac_utils_pvt.get_current_org_id);
7146 --<R12 MOAC END>
7147 --Bug5080617 Pass the parameters P_PO_TEMPLATE_CODE and P_CONTRACT_TEMPLATE_CODE as null
7148 l_request_id := fnd_request.submit_request('PO',
7149 'POXPOFAX' ,--Bug 6332444
7150 null,
7151 null,
7152 false,
7153 'R',--P_report_type
7154 null ,--P_agent_name
7155 p_doc_num ,--P_po_num_from
7156 p_doc_num ,--P_po_num_to
7157 null ,--P_relaese_num_from
7158 null ,--P_release_num_to
7159 null ,--P_date_from
7160 null ,--P_date_to
7161 null ,--P_approved_flag
7162 'N' ,--P_test_flag
7163 null ,--P_print_releases
7164 null ,--P_sortby
7165 p_user_id ,--P_user_id
7166 'Y' ,--P_fax_enable
7167 p_fax_num ,--P_fax_number
7168 'Y' ,--P_BLANKET_LINES
7169 'Communicate' ,--View_or_Communicate,
7170 p_withterms ,--P_WITHTERMS Bug# 6692126 instead of 'Y'
7171 'N' ,--P_storeFlag Bug#3528330 Changed to "N"
7172 'Y' ,--P_PRINT_FLAG
7173 p_document_id ,--P_DOCUMENT_ID Bug# 6692126
7174 null ,--P_REVISION_NUM
7175 null ,--P_AUTHORIZATION_STATUS
7176 p_document_subtype,--P_DOCUMENT_TYPE Bug# 6692126
7177 0 ,--P_max_zip_size, <PO Attachment Support 11i.11>
7178 null ,--P_PO_TEMPLATE_CODE
7179 null ,--P_CONTRACT_TEMPLATE_CODE
7180 fnd_global.local_chr(0),
7181 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7182 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7183 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7184 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7185 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7186 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7187 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7188 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7189 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7190 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7191 NULL, NULL);
7192
7193 --<POC FPJ End>
7194
7195 ELSE
7196 --<R12 MOAC START>
7197 po_moac_utils_pvt.set_request_context(po_moac_utils_pvt.get_current_org_id);
7198 --<R12 MOAC END>
7199
7200 l_request_id := fnd_request.submit_request('PO',
7201 'POXPPO',
7202 null,
7203 null,
7204 false,
7205 'P_REPORT_TYPE=R',
7206 'P_TEST_FLAG=N',
7207 'P_PO_NUM_FROM=' || p_doc_num,
7208 'P_PO_NUM_TO=' || p_doc_num,
7209 'P_USER_ID=' || p_user_id,
7210 'P_QTY_PRECISION=' || p_qty_precision,
7211 'P_FAX_ENABLE=' || p_fax_enable,
7212 'P_FAX_NUM=' || p_fax_num,
7213 'P_BLANKET_LINES=Y', -- Bug 3672088
7214 'P_PRINT_RELEASES=N', -- Bug 3672088
7215 fnd_global.local_chr(0),
7216 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7217 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7218 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7219 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7220 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7221 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7222 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7223 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7224 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7225 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7226 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7227 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7228 NULL, NULL, NULL, NULL, NULL);
7229 END IF;
7230
7231 return(l_request_id);
7232
7233 EXCEPTION
7234
7235 WHEN OTHERS THEN
7236 wf_core.context('PO_REQAPPROVAL_INIT1','Fax_PO',x_progress);
7237 raise;
7238
7239 END Fax_PO;
7240
7241
7242
7243
7244
7245 FUNCTION Print_Release(p_doc_num varchar2, p_qty_precision varchar,
7246 p_release_num varchar2, p_user_id varchar2,p_document_id number default NULL) RETURN number is
7247
7248 l_request_id number;
7249 x_progress varchar2(200);
7250
7251 BEGIN
7252 --<POC FPJ Start>
7253 --Bug#3528330 used the procedure po_communication_profile() to check for the
7254 --PO output format option instead of checking for the installation of
7255 --XDO product
7256 IF (PO_COMMUNICATION_PVT.PO_COMMUNICATION_PROFILE = 'T' and
7257 g_document_subtype = 'BLANKET') THEN
7258 --Launching the Dispatch Purchase Order Concurrent Program
7259 --<R12 MOAC START>
7260 po_moac_utils_pvt.set_request_context(po_moac_utils_pvt.get_current_org_id);
7261 --<R12 MOAC END>
7262 --Bug5080617 Pass the parameters P_PO_TEMPLATE_CODE and P_CONTRACT_TEMPLATE_CODE as null
7263 l_request_id := fnd_request.submit_request('PO',
7264 'POXPOPDF',
7265 null,
7266 null,
7267 false,
7268 'R',--P_report_type
7269 null ,--P_agent_name
7270 p_doc_num ,--P_po_num_from
7271 p_doc_num ,--P_po_num_to
7272 p_release_num ,--P_release_num_from
7273 p_release_num ,--P_release_num_to
7274 null ,--P_date_from
7275 null ,--P_date_to
7276 null ,--P_approved_flag
7277 'N' ,--P_test_flag
7278 'Y' ,--P_print_releases
7279 null ,--P_sortby
7280 p_user_id ,--P_user_id
7281 null ,--P_fax_enable
7282 null ,--P_fax_number
7283 'Y' ,--P_BLANKET_LINES
7284 'Communicate' ,--View_or_Communicate,
7285 'N' ,--P_WITHTERMS
7286 'N' ,--P_storeFlag Bug#3528330 Changed to "N"
7287 'Y' ,--P_PRINT_FLAG
7288 p_document_id ,--P_DOCUMENT_ID Bug# 6692126
7289 null ,--P_REVISION_NUM
7290 null ,--P_AUTHORIZATION_STATUS
7291 'RELEASE' ,--P_DOCUMENT_TYPE Bug# 6692126
7292 0 ,--P_max_zip_size, <PO Attachment Support 11i.11>
7293 null ,--P_PO_TEMPLATE_CODE
7294 null ,--P_CONTRACT_TEMPLATE_CODE
7295 fnd_global.local_chr(0),
7296 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7297 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7298 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7299 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7300 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7301 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7302 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7303 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7304 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7305 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7306 NULL, NULL);
7307 --<POC FPJ End >
7308 ELSE
7309
7310 -- FRKHAN 09/17/98. Change 'p_doc_num || p_release_num' from P_RELEASE_NUM_FROM and TO to just p_release_num
7311 --<R12 MOAC START>
7312 po_moac_utils_pvt.set_request_context(po_moac_utils_pvt.get_current_org_id);
7313 --<R12 MOAC END>
7314
7315 l_request_id := fnd_request.submit_request('PO',
7316 'POXPPO',
7317 null,
7318 null,
7319 false,
7320 'P_REPORT_TYPE=R',
7321 'P_TEST_FLAG=N',
7322 'P_USER_ID=' || p_user_id,
7323 'P_PO_NUM_FROM=' || p_doc_num,
7324 'P_PO_NUM_TO=' || p_doc_num,
7325 'P_RELEASE_NUM_FROM=' || p_release_num,
7326 'P_RELEASE_NUM_TO=' || p_release_num,
7327 'P_QTY_PRECISION=' || p_qty_precision,
7328 'P_BLANKET_LINES=N',
7329 'P_PRINT_RELEASES=Y',
7330 fnd_global.local_chr(0),
7331 NULL, NULL, NULL, NULL, NULL,
7332 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7333 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7334 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7335 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7336 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7337 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7338 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7339 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7340 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7341 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7342 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7343 NULL, NULL, NULL, NULL, NULL, NULL, NULL);
7344
7345 END IF;
7346
7347 return(l_request_id);
7348
7349 EXCEPTION
7350
7351 WHEN OTHERS THEN
7352 wf_core.context('PO_REQAPPROVAL_INIT1','Print_Release',x_progress);
7353 raise;
7354
7355 END Print_Release;
7356
7357
7358
7359
7360 -- Auto Fax
7361 -- DKC 10/10/99
7362 FUNCTION Fax_Release(p_doc_num varchar2, p_qty_precision varchar,
7363 p_release_num varchar2, p_user_id varchar2,
7364 p_fax_enable varchar2, p_fax_num varchar2,p_document_id number default NULL) RETURN number is
7365
7366 l_request_id number;
7367 x_progress varchar2(200);
7368
7369 BEGIN
7370 --<POC FPJ Start>
7371 --Bug#3528330 used the procedure po_communication_profile() to check for the
7372 --PO output format option instead of checking for the installation of
7373 --XDO product
7374 IF (PO_COMMUNICATION_PVT.PO_COMMUNICATION_PROFILE = 'T' and
7375 g_document_subtype = 'BLANKET') THEN
7376 --Launching the Dispatch Purchase Order Concurrent Program
7377 --<R12 MOAC START>
7378 po_moac_utils_pvt.set_request_context(po_moac_utils_pvt.get_current_org_id);
7379 --<R12 MOAC END>
7380 --Bug5080617 Pass the parameters P_PO_TEMPLATE_CODE and P_CONTRACT_TEMPLATE_CODE as null
7381 l_request_id := fnd_request.submit_request('PO',
7382 'POXPOPDF',
7383 null,
7384 null,
7385 false,
7386 'R',--P_report_type
7387 null ,--P_agent_name
7388 p_doc_num ,--P_po_num_from
7389 p_doc_num ,--P_po_num_to
7390 p_release_num ,--P_relaese_num_from
7391 p_release_num ,--P_release_num_to
7392 null ,--P_date_from
7393 null ,--P_date_to
7394 null ,--P_approved_flag
7395 'N' ,--P_test_flag
7396 'Y' ,--P_print_releases
7397 null ,--P_sortby
7398 p_user_id ,--P_user_id
7399 'Y' ,--P_fax_enable
7400 p_fax_num ,--P_fax_number
7401 'N' ,--P_BLANKET_LINES
7402 'Communicate' ,--View_or_Communicate,
7403 'N' ,--P_WITHTERMS
7404 'N' ,--P_storeFlag Bug#3528330 Changed to "N"
7405 'Y' ,--P_PRINT_FLAG
7406 p_document_id ,--P_DOCUMENT_ID Bug# 6692126
7407 null ,--P_REVISION_NUM
7408 null ,--P_AUTHORIZATION_STATUS
7409 'RELEASE' ,--P_DOCUMENT_TYPE Bug# 6692126
7410 0 ,--P_max_zip_size, <PO Attachment Support 11i.11>
7411 null ,--P_PO_TEMPLATE_CODE
7412 null ,--P_CONTRACT_TEMPLATE_CODE
7413 fnd_global.local_chr(0),
7414 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7415 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7416 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7417 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7418 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7419 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7420 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7421 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7422 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7423 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7424 NULL, NULL);
7425 --<POC FPJ End>
7426
7427 ELSE
7428 --<R12 MOAC START>
7429 po_moac_utils_pvt.set_request_context(po_moac_utils_pvt.get_current_org_id);
7430 --<R12 MOAC END>
7431
7432 l_request_id := fnd_request.submit_request('PO',
7433 'POXPPO',
7434 null,
7435 null,
7436 false,
7437 'P_REPORT_TYPE=R',
7438 'P_TEST_FLAG=N',
7439 'P_USER_ID=' || p_user_id,
7440 'P_PO_NUM_FROM=' || p_doc_num,
7441 'P_PO_NUM_TO=' || p_doc_num,
7442 'P_RELEASE_NUM_FROM=' || p_release_num,
7443 'P_RELEASE_NUM_TO=' || p_release_num,
7444 'P_QTY_PRECISION=' || p_qty_precision,
7445 'P_FAX_ENABLE=' || p_fax_enable,
7446 'P_FAX_NUM=' || p_fax_num,
7447 'P_BLANKET_LINES=N', -- Bug 3672088
7448 'P_PRINT_RELEASES=Y', -- Bug 3672088
7449 fnd_global.local_chr(0),
7450 NULL, NULL, NULL, NULL, NULL,
7451 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7452 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7453 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7454 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7455 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7456 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7457 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7458 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7459 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7460 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7461 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7462 NULL, NULL, NULL, NULL, NULL);
7463 END IF;
7464
7465
7466 return(l_request_id);
7467
7468 EXCEPTION
7469
7470 WHEN OTHERS THEN
7471 wf_core.context('PO_REQAPPROVAL_INIT1','Fax_Release',x_progress);
7472 raise;
7473
7474 END Fax_Release;
7475
7476
7477
7478
7479
7480
7481 --
7482 -- Is apps source code POR ?
7483 -- Determines if the requisition is created
7484 -- through web requisition 4.0 or higher
7485 --
7486 procedure is_apps_source_POR(itemtype in varchar2,
7487 itemkey in varchar2,
7488 actid in number,
7489 funcmode in varchar2,
7490 resultout out NOCOPY varchar2) IS
7491 l_progress VARCHAR2(100) := '000';
7492 l_document_id NUMBER;
7493 l_apps_source_code VARCHAR2(25) :='';
7494
7495 l_doc_string varchar2(200);
7496 l_preparer_user_name varchar2(100);
7497
7498 BEGIN
7499 IF (funcmode='RUN') THEN
7500 l_document_id := wf_engine.GetItemAttrNumber (itemtype => itemtype,
7501 itemkey => itemkey,
7502 aname => 'DOCUMENT_ID');
7503
7504 IF l_document_id IS NOT NULL THEN
7505
7506 select nvl(apps_source_code, 'PO')
7507 into l_apps_source_code
7508 from po_requisition_headers_all
7509 where requisition_header_id=l_document_id;
7510
7511 END IF;
7512
7513 l_progress:='002-'||to_char(l_document_id);
7514
7515 /* POR = Web Requisition 4.0 or higher */
7516 IF (l_apps_source_code='POR') THEN
7517
7518 resultout:='COMPLETE:'||'Y';
7519 return;
7520 ELSE
7521 resultout:='COMPLETE:'||'N';
7522 return;
7523
7524 END IF;
7525
7526 END IF; -- run mode
7527
7528 EXCEPTION
7529 WHEN OTHERS THEN
7530 l_doc_string := PO_REQAPPROVAL_INIT1.get_error_doc(itemType, itemkey);
7531 l_preparer_user_name := PO_REQAPPROVAL_INIT1.get_preparer_user_name(itemType, itemkey);
7532 wf_core.context('PO_REQAPPROVAL_INIT1','is_apps_source_POR',l_progress);
7533 PO_REQAPPROVAL_INIT1.send_error_notif(itemType, itemkey, l_preparer_user_name, l_doc_string, sqlerrm, 'PO_REQAPPROVAL_INIT1.IS_APPS_SOURCE_POR');
7534 RAISE;
7535
7536 END is_apps_source_POR;
7537
7538 -- Bug#3147435
7539 -- Is contractor status PENDING?
7540 -- Determines if the requisition has contractor_status PENDING at header level
7541 procedure is_contractor_status_pending(itemtype in varchar2,
7542 itemkey in varchar2,
7543 actid in number,
7544 funcmode in varchar2,
7545 resultout out NOCOPY varchar2) IS
7546 l_progress VARCHAR2(100) := '000';
7547 l_contractor_status VARCHAR2(25) := '';
7548
7549 l_doc_string varchar2(200);
7550 l_preparer_user_name varchar2(100);
7551
7552 BEGIN
7553 l_progress:='001-'||funcmode;
7554 IF (g_po_wf_debug = 'Y') THEN
7555 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,l_progress);
7556 END IF;
7557
7558 IF (funcmode='RUN') THEN
7559 l_contractor_status := PO_WF_UTIL_PKG.GetItemAttrText (itemtype => itemtype,
7560 itemkey => itemkey,
7561 aname => 'CONTRACTOR_STATUS');
7562
7563 l_progress:='002-'||l_contractor_status;
7564 IF (g_po_wf_debug = 'Y') THEN
7565 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,l_progress);
7566 END IF;
7567
7568 IF (l_contractor_status = 'PENDING') THEN
7569 --Bug#3268971
7570 --Setting the item attribute value to Y, which will be used in
7571 --ReqLinesNOtificationsCO to determine whether to display the helptext
7572 --for contractor assignment
7573 PO_WF_UTIL_PKG.SetItemAttrText ( itemtype => itemtype,
7574 itemkey => itemkey,
7575 aname => 'CONTRACTOR_ASSIGNMENT_REQD',
7576 avalue => 'Y' );
7577 resultout:='COMPLETE:'||'Y';
7578
7579 l_progress:='003-'||resultout;
7580 IF (g_po_wf_debug = 'Y') THEN
7581 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,l_progress);
7582 END IF;
7583
7584 return;
7585 ELSE
7586 resultout:='COMPLETE:'||'N';
7587
7588 l_progress:='004-'||resultout;
7589 IF (g_po_wf_debug = 'Y') THEN
7590 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,l_progress);
7591 END IF;
7592
7593 return;
7594 END IF;
7595
7596 END IF; -- run mode
7597
7598 EXCEPTION
7599 WHEN OTHERS THEN
7600 l_doc_string := PO_REQAPPROVAL_INIT1.get_error_doc(itemType, itemkey);
7601 l_preparer_user_name := PO_REQAPPROVAL_INIT1.get_preparer_user_name(itemType, itemkey);
7602 wf_core.context('PO_REQAPPROVAL_INIT1','is_contractor_status_pending',l_progress);
7603 PO_REQAPPROVAL_INIT1.send_error_notif(itemType, itemkey, l_preparer_user_name, l_doc_string, sqlerrm, 'PO_REQAPPROVAL_INIT1.is_contractor_status_pending');
7604 RAISE;
7605
7606 END is_contractor_status_pending;
7607
7608 -- Bug 823167 kbenjami
7609 --
7610 -- Is the Submitter the last Approver?
7611 -- Checks to see if submitter is also the current
7612 -- approver of the doc.
7613 -- Prevents two notifications from being sent to the
7614 -- same person.
7615 --
7616 procedure Is_Submitter_Last_Approver(itemtype in varchar2,
7617 itemkey in varchar2,
7618 actid in number,
7619 funcmode in varchar2,
7620 resultout out NOCOPY varchar2 ) is
7621
7622 approver_id number;
7623 preparer_id number;
7624
7625 x_username varchar2(100);
7626
7627 x_progress varchar2(300);
7628
7629 l_doc_string varchar2(200);
7630 l_preparer_user_name varchar2(100);
7631
7632 BEGIN
7633 x_progress := 'PO_REQAPPROVAL_INIT1.Is_Submitter_Last_Approver: 01';
7634 IF (g_po_wf_debug = 'Y') THEN
7635 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype, itemkey,x_progress);
7636 END IF;
7637
7638 preparer_id := wf_engine.GetItemAttrNumber (itemtype => itemtype,
7639 itemkey => itemkey,
7640 aname => 'PREPARER_ID');
7641
7642 approver_id := wf_engine.GetItemAttrNumber (itemtype => itemtype,
7643 itemkey => itemkey,
7644 aname => 'FORWARD_FROM_ID');
7645
7646 x_username := wf_engine.GetItemAttrText (itemtype => itemtype,
7647 itemkey => itemkey,
7648 aname => 'FORWARD_FROM_USER_NAME');
7649
7650 -- return Y if forward from user name is null.
7651 /* Bug5142627(forward fix 3733830) After the fix 2308846 the FORWARD_FROM_ID might be null
7652 when it is just submitted for approval and no-approver-found.
7653 So this also should be excluded.
7654 */
7655 if (approver_id is null OR
7656 preparer_id = approver_id OR x_username is null) then
7657 resultout := wf_engine.eng_completed || ':' || 'Y';
7658 x_progress := 'PO_REQAPPROVAL_INIT1.Is_Submitter_Last_Approver: 02. Result = Yes';
7659 else
7660 resultout := wf_engine.eng_completed || ':' || 'N';
7661 x_progress := 'PO_REQAPPROVAL_INIT1.Is_Submitter_Last_Approver: 02. Result = No';
7662 end if;
7663
7664 EXCEPTION
7665 WHEN OTHERS THEN
7666 l_doc_string := PO_REQAPPROVAL_INIT1.get_error_doc(itemType, itemkey);
7667 l_preparer_user_name := PO_REQAPPROVAL_INIT1.get_preparer_user_name(itemType, itemkey);
7668 wf_core.context('PO_REQAPPROVAL_INIT1','Is_Submitter_Last_Approver',x_progress);
7669 PO_REQAPPROVAL_INIT1.send_error_notif(itemType, itemkey, l_preparer_user_name, l_doc_string, sqlerrm, 'PO_REQAPPROVAL_INIT1.IS_SUBMITTER_LAST_APPROVER');
7670 raise;
7671
7672 end Is_Submitter_Last_Approver;
7673
7674 --
7675
7676 function get_error_doc(itemtype in varchar2,
7677 itemkey in varchar2) return varchar2
7678 IS
7679 l_doc_string varchar2(200);
7680
7681 l_document_type varchar2(25);
7682 l_document_subtype varchar2(25);
7683 l_document_id number;
7684 l_org_id number;
7685
7686 BEGIN
7687
7688 l_document_type := wf_engine.GetItemAttrText (itemtype => itemtype,
7689 itemkey => itemkey,
7690 aname => 'DOCUMENT_TYPE');
7691
7692 l_document_id := wf_engine.GetItemAttrNumber (itemtype => itemtype,
7693 itemkey => itemkey,
7694 aname => 'DOCUMENT_ID');
7695
7696 l_org_id := wf_engine.GetItemAttrNumber (itemtype => itemtype,
7697 itemkey => itemkey,
7698 aname => 'ORG_ID');
7699
7700 PO_MOAC_UTILS_PVT.set_org_context(l_org_id) ; -- <R12 MOAC>
7701
7702 IF (l_document_type IN ('PO', 'PA')) THEN
7703 select st.DISPLAYED_FIELD || ' ' ||
7704 ty.DISPLAYED_FIELD || ' ' ||
7705 hd.SEGMENT1
7706 into l_doc_string
7707 from po_headers hd,
7708 po_lookup_codes ty,
7709 po_lookup_codes st
7710 where hd.po_header_id = l_document_id
7711 and ty.lookup_type = 'DOCUMENT TYPE'
7712 and ty.lookup_code = l_document_type
7713 and st.lookup_type = 'DOCUMENT SUBTYPE'
7714 and st.lookup_code = hd.TYPE_LOOKUP_CODE;
7715 ELSIF (l_document_type = 'REQUISITION') THEN
7716 select st.DISPLAYED_FIELD || ' ' ||
7717 ty.DISPLAYED_FIELD || ' ' ||
7718 hd.SEGMENT1
7719 into l_doc_string
7720 from po_requisition_headers hd,
7721 po_lookup_codes ty,
7722 po_lookup_codes st
7723 where hd.requisition_header_id = l_document_id
7724 and ty.lookup_type = 'DOCUMENT TYPE'
7725 and ty.lookup_code = l_document_type
7726 and st.lookup_type = 'REQUISITION TYPE'
7727 and st.lookup_code = hd.TYPE_LOOKUP_CODE;
7728 ELSIF (l_document_type = 'RELEASE') THEN
7729 select st.DISPLAYED_FIELD || ' ' ||
7730 ty.DISPLAYED_FIELD || ' ' ||
7731 hd.SEGMENT1 || '-' ||
7732 rl.RELEASE_NUM
7733 into l_doc_string
7734 from po_headers hd,
7735 po_releases rl,
7736 po_lookup_codes ty,
7737 po_lookup_codes st
7738 where rl.po_release_id = l_document_id
7739 and rl.po_header_id = hd.po_header_id
7740 and ty.lookup_type = 'DOCUMENT TYPE'
7741 and ty.lookup_code = l_document_type
7742 and st.lookup_type = 'DOCUMENT SUBTYPE'
7743 and st.lookup_code = rl.RELEASE_TYPE;
7744 END IF;
7745
7746 return(l_doc_string);
7747
7748 EXCEPTION
7749 WHEN OTHERS THEN
7750 RAISE;
7751
7752 END get_error_doc;
7753
7754 function get_preparer_user_name(itemtype in varchar2,
7755 itemkey in varchar2) return varchar2
7756 IS
7757
7758 l_name varchar2(100);
7759 l_preparer_id number;
7760 l_disp varchar2(240);
7761
7762 BEGIN
7763
7764 l_preparer_id := wf_engine.GetItemAttrNumber (itemtype => itemtype,
7765 itemkey => itemkey,
7766 aname => 'PREPARER_ID');
7767
7768 PO_REQAPPROVAL_INIT1.get_user_name(l_preparer_id, l_name, l_disp);
7769
7770 return(l_name);
7771
7772 END;
7773
7774 procedure send_error_notif(itemtype in varchar2,
7775 itemkey in varchar2,
7776 username in varchar2,
7777 doc in varchar2,
7778 msg in varchar2,
7779 loc in varchar2,
7780 document_id in number) is
7781
7782 pragma AUTONOMOUS_TRANSACTION;
7783
7784 /* Bug# 2074072: kagarwal
7785 ** Desc: Calling wf process to send Error Notification
7786 ** instead of the wf API.
7787 */
7788
7789 -- l_nid NUMBER;
7790 l_seq varchar2(10);
7791 Err_ItemKey varchar2(240);
7792 Err_ItemType varchar2(240):= 'POERROR';
7793 l_document_id number;
7794 x_progress varchar2(1000);
7795
7796 BEGIN
7797
7798 -- To be used only for PO and Req Approval wf
7799
7800 x_progress := 'PO_REQAPPROVAL_INIT1.send_error_notif: 10';
7801 IF (g_po_wf_debug = 'Y') THEN
7802 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
7803 END IF;
7804
7805 x_progress := 'PO_REQAPPROVAL_INIT1.send_error_notif: 20'
7806 ||' username: '|| username
7807 ||' doc: '|| doc
7808 ||' location: '|| loc
7809 ||' error msg: '|| msg;
7810 IF (g_po_wf_debug = 'Y') THEN
7811 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
7812 END IF;
7813
7814
7815 if username is not null and doc is not null then
7816
7817 /* l_nid := wf_notification.Send(username,
7818 itemtype,
7819 'PLSQL_ERROR_OCCURS',
7820 null, null, null, null);
7821
7822 wf_Notification.SetAttrText(l_nid, 'PLSQL_ERROR_DOC', doc);
7823 wf_Notification.SetAttrText(l_nid, 'PLSQL_ERROR_LOC', loc);
7824 wf_Notification.SetAttrText(l_nid, 'PLSQL_ERROR_MSG', msg);
7825 */
7826
7827 -- Get Document Id for the Errored Item.
7828
7829 IF (document_id IS NULL) THEN
7830
7831 l_document_id := wf_engine.GetItemAttrNumber (itemtype => itemtype,
7832 itemkey => itemkey,
7833 aname => 'DOCUMENT_ID');
7834 ELSE
7835
7836 l_document_id := document_id;
7837
7838 END IF;
7839
7840 select to_char(PO_WF_ITEMKEY_S.NEXTVAL) into l_seq from sys.dual;
7841 Err_ItemKey := to_char(l_document_id) || '-' || l_seq;
7842
7843
7844 x_progress := 'PO_REQAPPROVAL_INIT1.send_error_notif: 50'
7845 ||' Parent Itemtype: '|| ItemType
7846 ||' Parent Itemkey: '|| ItemKey
7847 ||' Error Itemtype: '|| Err_ItemType
7848 ||' Error Itemkey: '|| Err_ItemKey;
7849 IF (g_po_wf_debug = 'Y') THEN
7850 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
7851 END IF;
7852
7853 wf_engine.CreateProcess( ItemType => Err_ItemType,
7854 ItemKey => Err_ItemKey,
7855 process => 'PLSQL_ERROR_NOTIF');
7856
7857 x_progress := 'PO_REQAPPROVAL_INIT1.send_error_notif: 70';
7858 IF (g_po_wf_debug = 'Y') THEN
7859 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
7860 END IF;
7861
7862 -- Set the attributes
7863 wf_engine.SetItemAttrText ( itemtype => Err_ItemType,
7864 itemkey => Err_ItemKey,
7865 aname => 'PLSQL_ERROR_DOC',
7866 avalue => doc);
7867
7868 --
7869 wf_engine.SetItemAttrText ( itemtype => Err_ItemType,
7870 itemkey => Err_ItemKey,
7871 aname => 'PLSQL_ERROR_LOC',
7872 avalue => loc);
7873 --
7874 wf_engine.SetItemAttrText ( itemtype => Err_ItemType,
7875 itemkey => Err_ItemKey,
7876 aname => 'PLSQL_ERROR_MSG',
7877 avalue => msg);
7878 --
7879 wf_engine.SetItemAttrText ( itemtype => Err_ItemType,
7880 itemkey => Err_ItemKey,
7881 aname => 'PREPARER_USER_NAME' ,
7882 avalue => username);
7883 --
7884 x_progress := 'PO_REQAPPROVAL_INIT1.send_error_notif: 100';
7885 IF (g_po_wf_debug = 'Y') THEN
7886 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
7887 END IF;
7888
7889
7890 wf_engine.StartProcess(itemtype => Err_ItemType,
7891 itemkey => Err_ItemKey);
7892
7893 x_progress := 'PO_REQAPPROVAL_INIT1.send_error_notif: 900';
7894 IF (g_po_wf_debug = 'Y') THEN
7895 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
7896 END IF;
7897
7898 commit;
7899
7900 end if;
7901
7902 EXCEPTION
7903 WHEN OTHERS THEN
7904 x_progress := 'PO_REQAPPROVAL_INIT1.send_error_notif: '|| sqlerrm;
7905 IF (g_po_wf_debug = 'Y') THEN
7906 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
7907 END IF;
7908 RAISE;
7909
7910 END send_error_notif;
7911
7912 -- This procedure will close all the notification of all the
7913 -- previous approval WF.
7914
7915 procedure CLOSE_OLD_NOTIF(itemtype in varchar2,
7916 itemkey in varchar2) is
7917 pragma AUTONOMOUS_TRANSACTION;
7918 begin
7919
7920 update wf_notifications set status = 'CLOSED'
7921 where notification_id in (
7922 select ias.notification_id
7923 from wf_item_activity_statuses ias,
7924 wf_notifications ntf
7925 where ias.item_type = itemtype
7926 and ias.item_key = itemkey
7927 and ntf.notification_id = ias.notification_id);
7928
7929 commit;
7930
7931 end;
7932
7933 /* Bug# 1739194: kagarwal
7934 ** Desc: Added new procedure to check the document manager error.
7935 */
7936 procedure Is_Document_Manager_Error_1_2(itemtype in varchar2,
7937 itemkey in varchar2,
7938 actid in number,
7939 funcmode in varchar2,
7940 resultout out NOCOPY varchar2) IS
7941 l_progress VARCHAR2(100) := '000';
7942 l_error_number NUMBER;
7943
7944 BEGIN
7945
7946 IF (funcmode='RUN') THEN
7947
7948 l_progress := 'Is_Document_Manager_Error_1_2: 001';
7949 IF (g_po_wf_debug = 'Y') THEN
7950 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,l_progress);
7951 END IF;
7952
7953 l_error_number:=
7954 wf_engine.GetItemAttrNumber ( itemtype => itemtype,
7955 itemkey => itemkey,
7956 aname => 'DOC_MGR_ERROR_NUM');
7957
7958 l_progress := 'Is_Document_Manager_Error_1_2: 002 - '||
7959 to_char(l_error_number);
7960 IF (g_po_wf_debug = 'Y') THEN
7961 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,l_progress);
7962 END IF;
7963
7964 IF (l_error_number = 1 or l_error_number = 2) THEN
7965 resultout:='COMPLETE:'||'Y';
7966 return;
7967
7968 ELSE
7969 resultout:='COMPLETE:'||'N';
7970 return;
7971
7972 END IF;
7973
7974 END IF; --run mode
7975
7976 EXCEPTION
7977 WHEN OTHERS THEN
7978 WF_CORE.context('PO_APPROVAL_LIST_WF1S' , 'Is_Document_Manager_Error_1_2',
7979 itemtype, itemkey, l_progress);
7980 resultout:='COMPLETE:'||'N';
7981
7982 END Is_Document_Manager_Error_1_2;
7983
7984
7985
7986 /**************************************************************************/
7987 procedure PROFILE_VALUE_CHECK(itemtype in varchar2,
7988 itemkey in varchar2,
7989 actid in number,
7990 funcmode in varchar2,
7991 resultout out NOCOPY varchar2 ) is
7992 x_progress varchar2(300);
7993 l_po_email_add_prof varchar2(60);
7994 l_prof_value varchar2(2);
7995 l_doc_string varchar2(200);
7996 l_preparer_user_name varchar2(100);
7997
7998 BEGIN
7999 x_progress := 'PO_REQAPPROVAL_INIT1.profile_value_check: 01';
8000 IF (g_po_wf_debug = 'Y') THEN
8001 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
8002 END IF;
8003
8004
8005 -- Do nothing in cancel or timeout mode
8006 --
8007 if (funcmode <> wf_engine.eng_run) then
8008
8009 resultout := wf_engine.eng_null;
8010 return;
8011
8012 end if;
8013
8014 l_po_email_add_prof := wf_engine.GetItemAttrText (itemtype => itemtype,
8015 itemkey => itemkey,
8016 aname => 'EMAIL_ADD_FROM_PROFILE');
8017
8018 /* the value of l_po_email_add_prof has a value or it is null*/
8019 IF l_po_email_add_prof is null THEN
8020 l_prof_value := 'N';
8021 ELSE
8022 l_prof_value := 'Y';
8023 END IF;
8024
8025 --
8026 resultout := wf_engine.eng_completed || ':' || l_prof_value ;
8027 --
8028 x_progress := 'PO_REQAPPROVAL_INIT1.profile_value_check: 02. Result= ' || l_prof_value;
8029 IF (g_po_wf_debug = 'Y') THEN
8030 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
8031 END IF;
8032
8033 EXCEPTION
8034 WHEN OTHERS THEN
8035 l_doc_string := PO_REQAPPROVAL_INIT1.get_error_doc(itemType, itemkey);
8036 l_preparer_user_name := PO_REQAPPROVAL_INIT1.get_preparer_user_name(itemType, itemkey);
8037 WF_CORE.context('PO_REQAPPROVAL_INIT1', 'PROFILE_VALUE_CHECK' ,
8038 itemtype, itemkey, x_progress);
8039 resultout:='COMPLETE:'||'N';
8040
8041 END;
8042
8043 procedure Check_Error_Count(itemtype in varchar2,
8044 itemkey in varchar2,
8045 actid in number,
8046 funcmode in varchar2,
8047 resultout out NOCOPY varchar2) IS
8048 l_progress VARCHAR2(100) := '000';
8049 l_count NUMBER;
8050 l_error_count NUMBER;
8051 l_item_type varchar2(30);
8052 l_item_key varchar2(30);
8053
8054 BEGIN
8055
8056 IF (funcmode='RUN') THEN
8057
8058 l_progress := 'CHECK_ERROR_COUNT: 001';
8059 IF (g_po_wf_debug = 'Y') THEN
8060 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,l_progress);
8061 END IF;
8062
8063 l_item_type :=wf_engine.GetItemAttrText ( itemtype => itemtype,
8064 itemkey => itemkey,
8065 aname => 'ERROR_ITEM_TYPE');
8066 l_item_key :=wf_engine.GetItemAttrText ( itemtype => itemtype,
8067 itemkey => itemkey,
8068 aname => 'ERROR_ITEM_KEY');
8069 l_count:= wf_engine.GetItemAttrNumber ( itemtype => itemtype,
8070 itemkey => itemkey,
8071 aname => 'RETRY_COUNT');
8072
8073
8074 Select count(*)
8075 into l_error_count
8076 from wf_items
8077 where parent_item_type=l_item_type
8078 and parent_item_key = l_item_key;
8079
8080
8081 IF (l_error_count <= l_count) then
8082 resultout:='COMPLETE:'||'Y'; -- retry
8083 return;
8084
8085 ELSE
8086 resultout:='COMPLETE:'||'N';
8087 return;
8088
8089 END IF;
8090
8091 END IF; --run mode
8092
8093 EXCEPTION
8094 WHEN OTHERS THEN
8095 WF_CORE.context('PO_APPROVAL_LIST_WF1S' , 'Check_Error_Count',
8096 itemtype, itemkey, l_progress);
8097 resultout:='COMPLETE:'||'N';
8098 END Check_Error_Count;
8099
8100 procedure Initialise_Error(itemtype in varchar2,
8101 itemkey in varchar2,
8102 actid in number,
8103 funcmode in varchar2,
8104 resultout out NOCOPY varchar2) IS
8105 l_progress VARCHAR2(100) := '000';
8106 l_error_number number;
8107 l_name varchar2(100);
8108 l_preparer_id number;
8109 l_disp varchar2(240);
8110 l_item_type varchar2(30);
8111 l_item_key varchar2(30);
8112 l_doc_err_num number;
8113 l_doc_type varchar2(25); /* Bug# 2655410 */
8114 l_doc_subtype varchar2(25);
8115 -- l_doc_subtype_disp varchar2(30);
8116 l_doc_type_disp varchar2(240);
8117 l_orgid number;
8118 l_ga_flag varchar2(1) := null; -- FPI GA
8119
8120 l_doc_num varchar2(30);
8121 l_sys_error_msg varchar2(2000) :='';
8122 l_release_num_dash varchar2(30);
8123 l_release_num number; --1942901
8124 l_document_id PO_HEADERS_ALL.po_header_id%TYPE; --<R12 STYLES PHASE II>
8125
8126 /* Bug# 2655410: kagarwal
8127 ** Desc: We will get the document type display value from
8128 ** po document types.
8129 */
8130
8131 cursor docDisp(p_doc_type varchar2, p_doc_subtype varchar2) is
8132 select type_name
8133 from po_document_types
8134 where document_type_code = p_doc_type
8135 and document_subtype = p_doc_subtype;
8136
8137
8138 BEGIN
8139
8140 IF (funcmode='RUN') THEN
8141
8142 l_progress := 'Initialise_Error: 001';
8143 IF (g_po_wf_debug = 'Y') THEN
8144 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,l_progress);
8145 END IF;
8146
8147 l_item_type :=wf_engine.GetItemAttrText ( itemtype => itemtype,
8148 itemkey => itemkey,
8149 aname => 'ERROR_ITEM_TYPE');
8150 l_item_key :=wf_engine.GetItemAttrText ( itemtype => itemtype,
8151 itemkey => itemkey,
8152 aname => 'ERROR_ITEM_KEY');
8153
8154 /* Bug# 2708702 kagarwal
8155 ** Fix Details: Make all the Set and Get calls for parent item type to use the PO wrapper
8156 ** PO_WF_UTIL_PKG so that the missing attribute errors are ignored.
8157 */
8158
8159 l_preparer_id := PO_WF_UTIL_PKG.GetItemAttrNumber ( itemtype => l_item_type,
8160 itemkey => l_item_key,
8161 aname => 'PREPARER_ID');
8162
8163 PO_REQAPPROVAL_INIT1.get_user_name(l_preparer_id, l_name, l_disp);
8164
8165 /* Bug# 2655410: kagarwal
8166 ** Desc: We will get the document type display value from
8167 ** po document types. Hence we need to get the doc type and subtype
8168 ** from the parent wf and then set the doc type display in the
8169 ** error wf.
8170 **
8171 ** Also need to set the org context before calling the cursor
8172 */
8173
8174 l_doc_subtype := PO_WF_UTIL_PKG.GetItemAttrText (itemtype => l_item_type,
8175 itemkey => l_item_key,
8176 aname => 'DOCUMENT_SUBTYPE');
8177
8178 l_doc_type := PO_WF_UTIL_PKG.GetItemAttrText ( itemtype => l_item_type,
8179 itemkey => l_item_key,
8180 aname => 'DOCUMENT_TYPE');
8181
8182 IF l_doc_type = 'PA' AND l_doc_subtype = 'BLANKET' THEN
8183
8184 l_ga_flag := PO_WF_UTIL_PKG.GetItemAttrText (itemtype => l_item_type,
8185 itemkey => l_item_key,
8186 aname => 'GLOBAL_AGREEMENT_FLAG');
8187 END IF;
8188
8189
8190 --<R12 STYLES PHASE II START >
8191
8192 l_document_id := PO_WF_UTIL_PKG.GetItemAttrNumber
8193 (itemtype => l_item_type,
8194 itemkey => l_item_key,
8195 aname => 'DOCUMENT_ID');
8196
8197
8198 if l_ga_flag = 'N' then
8199
8200 l_orgid := PO_WF_UTIL_PKG.GetItemAttrNumber (itemtype => l_item_type,
8201 itemkey => l_item_key,
8202 aname => 'ORG_ID');
8203
8204 IF l_orgid is NOT NULL THEN
8205
8206 PO_MOAC_UTILS_PVT.set_org_context(l_orgid) ; -- <R12 MOAC>
8207
8208 END IF;
8209
8210 end if; /* if l_ga_flag = 'N' */
8211
8212 if (l_doc_type = 'PA' AND l_doc_subtype IN ('BLANKET','CONTRACT')) OR
8213 (l_doc_type = 'PO' AND l_doc_subtype = 'STANDARD') then
8214
8215 l_doc_type_disp:= PO_DOC_STYLE_PVT.get_style_display_name(l_document_id);
8216
8217 else
8218
8219 OPEN docDisp(l_doc_type, l_doc_subtype);
8220 FETCH docDisp into l_doc_type_disp;
8221 CLOSE docDisp;
8222
8223 end if;
8224 --<R12 STYLES PHASE II END >
8225
8226
8227 l_doc_num := PO_WF_UTIL_PKG.GetItemAttrText ( itemtype => l_item_type,
8228 itemkey => l_item_key,
8229 aname => 'DOCUMENT_NUMBER');
8230
8231
8232 l_sys_error_msg := PO_WF_UTIL_PKG.GetItemAttrText ( itemtype => l_item_type,
8233 itemkey => l_item_key,
8234 aname => 'SYSADMIN_ERROR_MSG');
8235
8236 l_release_num_dash := PO_WF_UTIL_PKG.GetItemAttrText (itemtype => l_item_type,
8237 itemkey => l_item_key,
8238 aname => 'RELEASE_NUM_DASH');
8239
8240 l_release_num:= PO_WF_UTIL_PKG.GetItemAttrNumber(itemtype => l_item_type,
8241 itemkey => l_item_key,
8242 aname => 'RELEASE_NUM');
8243
8244 PO_WF_UTIL_PKG.SetItemAttrText ( itemtype => itemType,
8245 itemkey => itemkey,
8246 aname => 'PREPARER_USER_NAME' ,
8247 avalue => l_name);
8248
8249 /* Bug# 2655410: kagarwal
8250 ** Desc: We will only be using one display attribute for type and
8251 ** subtype - DOCUMENT_TYPE_DISP, hence commenting the code below
8252 */
8253
8254 /* wf_engine.SetItemAttrText ( itemtype => itemType,
8255 itemkey => itemkey,
8256 aname => 'DOCUMENT_SUBTYPE_DISP' ,
8257 avalue => l_doc_subtype_disp);
8258 */
8259 PO_WF_UTIL_PKG.SetItemAttrText ( itemtype => itemType,
8260 itemkey => itemkey,
8261 aname => 'DOCUMENT_TYPE_DISP' ,
8262 avalue => l_doc_type_disp);
8263
8264 PO_WF_UTIL_PKG.SetItemAttrText ( itemtype => itemType,
8265 itemkey => itemkey,
8266 aname => 'DOCUMENT_NUMBER' ,
8267 avalue => l_doc_num);
8268
8269 PO_WF_UTIL_PKG.SetItemAttrText ( itemtype => itemType,
8270 itemkey => itemkey,
8271 aname => 'RELEASE_NUM_DASH' ,
8272 avalue => l_release_num_dash);
8273
8274 PO_WF_UTIL_PKG.SetItemAttrNumber ( itemtype => itemType,
8275 itemkey => itemkey,
8276 aname => 'RELEASE_NUM' ,
8277 avalue => l_release_num);
8278
8279
8280 l_error_number := PO_REQAPPROVAL_ACTION.doc_mgr_err_num;
8281 /* bug 1942091. Set the Error attributes */
8282 l_sys_error_msg := PO_REQAPPROVAL_ACTION.sysadmin_err_msg;
8283
8284 PO_WF_UTIL_PKG.SetItemAttrNumber ( itemtype => itemType,
8285 itemkey => itemkey,
8286 aname => 'DOC_MGR_ERROR_NUM',
8287 avalue => l_error_number);
8288 PO_WF_UTIL_PKG.SetItemAttrText ( itemtype => itemType,
8289 itemkey => itemkey,
8290 aname => 'SYSADMIN_ERROR_MSG' ,
8291 avalue => l_sys_error_msg);
8292 /* Set the parents doc manager error number and sysadmin error mesg*/
8293 PO_WF_UTIL_PKG.SetItemAttrNumber ( itemtype => l_item_type,
8294 itemkey => l_item_key,
8295 aname => 'DOC_MGR_ERROR_NUM',
8296 avalue => l_error_number);
8297 PO_WF_UTIL_PKG.SetItemAttrText ( itemtype => l_item_type,
8298 itemkey => l_item_key,
8299 aname => 'SYSADMIN_ERROR_MSG' ,
8300 avalue => l_sys_error_msg);
8301
8302 END IF; --run mode
8303
8304 EXCEPTION
8305 WHEN OTHERS THEN
8306 WF_CORE.context('PO_APPROVAL_LIST_WF1S' , 'Initialise_Error',
8307 itemtype, itemkey, l_progress);
8308 resultout:='COMPLETE:'||'N';
8309 END Initialise_Error;
8310
8311
8312
8313 procedure acceptance_required ( itemtype in varchar2,
8314 itemkey in varchar2,
8315 actid in number,
8316 funcmode in varchar2,
8317 result out NOCOPY varchar2 )
8318 is
8319 l_acceptance_flag po_headers_all.acceptance_required_flag%TYPE;
8320 x_progress varchar2(3) := '000';
8321 l_document_id number;
8322 l_document_type po_document_types.document_type_code%type;
8323 l_document_subtype po_document_types.document_subtype%type;
8324 l_when_to_archive po_document_types.archive_external_revision_code%type;
8325 l_archive_result varchar2(1);
8326 l_revision_num number; -- <Bug 5501659> --
8327 l_responded_shipments number; -- <Bug 5501659> --
8328 begin
8329 /*
8330 1. Bug#2742276: To find out if acceptance is required, older version used to check workflow
8331 attribute ACCEPTANCE_REQUIRED.
8332 This may not be correct since acceptance_requried_flag may be updated in the DB.
8333 Thus, we shall query acceptance_required_flag from po_headers/po_releases view.
8334
8335 */
8336 x_progress := '001';
8337
8338 l_document_type := wf_engine.GetItemAttrText (itemtype => itemtype,
8339 itemkey => itemkey,
8340 aname => 'DOCUMENT_TYPE');
8341
8342 l_document_id := wf_engine.GetItemAttrNumber (itemtype => itemtype,
8343 itemkey => itemkey,
8344 aname => 'DOCUMENT_ID');
8345
8346 l_document_subtype := wf_engine.GetItemAttrText (itemtype => itemtype,
8347 itemkey => itemkey,
8348 aname => 'DOCUMENT_SUBTYPE');
8349
8350 if(l_document_type <> 'RELEASE') then
8351 select acceptance_required_flag
8352 into l_acceptance_flag
8353 from po_headers_all --bug 4764963
8354 where po_header_Id = l_document_id;
8355 else
8356 select acceptance_required_flag
8357 into l_acceptance_flag
8358 from po_releases_all --bug 4764963
8359 where po_release_Id = l_document_id;
8360 end if;
8361
8362 /* BINDING FPJ START*/
8363 IF nvl(l_acceptance_flag,'N') <> 'N' THEN
8364 result := 'COMPLETE:' || 'Y';
8365 ELSE
8366 result := 'COMPLETE:' || 'N';
8367 END IF;
8368 /* BINDING FPJ END*/
8369
8370 /*** Checking if at least one shipment has been responded to (Bug 5501659) */
8371 -- There should be no notification if there has been at least on reponse
8372
8373 if(l_document_type <> 'RELEASE') then
8374 select revision_num
8375 into l_revision_num
8376 from po_headers_all
8377 where po_header_id = l_document_id;
8378
8379 select count(*)
8380 into l_responded_shipments
8381 from PO_ACCEPTANCES
8382 where po_header_id = l_document_id and
8383 revision_num = l_revision_num;
8384 else
8385 select revision_num
8386 into l_revision_num
8387 from po_releases_all
8388 where po_release_id = l_document_id;
8389
8390 select count(*)
8391 into l_responded_shipments
8392 from PO_ACCEPTANCES
8393 where po_release_id = l_document_id and
8394 revision_num = l_revision_num;
8395 end if;
8396
8397
8398 if(l_responded_shipments > 0) THEN
8399 result := 'COMPLETE:' || 'N';
8400 end if;
8401
8402 /*** (Bug 5501659) ***/
8403
8404
8405 exception
8406 WHEN OTHERS THEN
8407 wf_core.context('PO_REQAPPROVAL_INIT1','acceptance_required',x_progress);
8408 raise;
8409 end;
8410
8411 --
8412
8413 procedure Register_acceptance ( itemtype in varchar2,
8414 itemkey in varchar2,
8415 actid in number,
8416 funcmode in varchar2,
8417 result out NOCOPY varchar2 )
8418 is
8419 x_progress varchar2(3) := '000';
8420 x_acceptance_result fnd_new_messages.message_text%type := null; -- Bug 2821341
8421 x_org_id number;
8422 x_user_id number;
8423 x_document_id number;
8424 x_document_type_code varchar2(30);
8425 x_po_header_id po_headers_all.po_header_id%TYPE;
8426 x_vendor po_vendors.vendor_name%TYPE; /* Bug 7172641 Changing the size as equal to the column size of vendor_name in po_vendors table */
8427 x_supp_user_name varchar2(100);
8428 x_supplier_displayname varchar2(100);
8429 x_revision_num number; -- RDP
8430 -- x_accp_type varchar2(100);
8431 l_nid number;
8432 l_ntf_role_name varchar2(320);
8433
8434 begin
8435
8436 -- set the org context
8437 x_org_id := wf_engine.GetItemAttrNumber ( itemtype => itemtype,
8438 itemkey => itemkey,
8439 aname => 'ORG_ID');
8440
8441 PO_MOAC_UTILS_PVT.set_org_context(x_org_id) ; -- <R12 MOAC>
8442
8443 x_document_id := wf_engine.GetItemAttrNumber ( itemtype => itemtype,
8444 itemkey => itemkey,
8445 aname => 'DOCUMENT_ID');
8446
8447 x_document_type_code := wf_engine.GetItemAttrText ( itemtype => itemtype,
8448 itemkey => itemkey,
8449 aname => 'DOCUMENT_TYPE');
8450
8451 -- commented out the usage of accptance_type (FPI)
8452 /* x_accp_type := PO_WF_UTIL_PKG.GetItemAttrText(itemtype => itemtype,
8453 itemkey => itemkey,
8454 aname => 'ACCEPTANCE_TYPE'); */
8455
8456 x_acceptance_result := PO_WF_UTIL_PKG.GetItemAttrText(itemtype => itemtype,
8457 itemkey => itemkey,
8458 aname => 'ACCEPTANCE_RESULT');
8459
8460 if x_document_type_code <> 'RELEASE' then
8461 select pov.vendor_name,poh.revision_num
8462 into x_vendor,x_revision_num -- RDP
8463 from po_vendors pov,po_headers poh
8464 where pov.vendor_id = poh.vendor_id
8465 and poh.po_header_id=x_document_id;
8466 else
8467 select pov.vendor_name, poh.po_header_id, por.revision_num --RDP
8468 into x_vendor,x_po_header_id,x_revision_num
8469 from po_releases por,
8470 po_headers_all poh, -- <R12 MOAC>
8471 po_vendors pov
8472 where por.po_release_id = x_document_id
8473 and por.po_header_id = poh.po_header_id
8474 and poh.vendor_id = pov.vendor_id;
8475 end if;
8476
8477
8478
8479 if (x_document_type_code <> 'RELEASE') then
8480
8481 --dbms_output.put_line('For std pos');
8482 begin
8483 select a.notification_id, a.recipient_role
8484 INTO l_nid, l_ntf_role_name
8485 from wf_notifications a,
8486 wf_item_activity_statuses wa
8487 where itemkey=wa.item_key
8488 and itemtype=wa.item_type
8489 and a.message_name in ('PO_EMAIL_PO_WITH_RESPONSE', 'PO_EMAIL_PO_PDF_WITH_RESPONSE')
8490 and a.notification_id=wa.notification_id and a.status = 'CLOSED';
8491 exception
8492 when others then l_nid := null;
8493 end;
8494
8495 else
8496 begin
8497 --dbms_output.put_line('For Releases');
8498 select a.notification_id, a.recipient_role
8499 INTO l_nid, l_ntf_role_name
8500 from wf_notifications a,
8501 wf_item_activity_statuses wa
8502 where itemkey=wa.item_key
8503 and itemtype=wa.item_type
8504 and a.message_name in ('PO_EMAIL_PO_WITH_RESPONSE', 'PO_EMAIL_PO_PDF_WITH_RESPONSE')
8505 and a.notification_id=wa.notification_id and a.status = 'CLOSED';
8506 exception
8507 when others then l_nid := null;
8508 end;
8509 end if;
8510
8511 if (l_nid is null) then
8512 --we do not want to continue if the notification is not closed.
8513 return;
8514 else
8515 x_supp_user_name := wf_notification.responder(l_nid);
8516 end if;
8517
8518
8519 PO_WF_UTIL_PKG.SetItemAttrText (itemtype => itemtype,
8520 itemkey => itemkey,
8521 aname => 'SUPPLIER',
8522 avalue => x_vendor);
8523
8524 -- commented out the usage of accptance_type (FPI)
8525 /* IF (x_accp_type is NULL) THEN
8526 PO_WF_UTIL_PKG.SetItemAttrText ( itemtype => itemtype,
8527 itemkey => itemkey,
8528 aname => 'ACCEPTANCE_TYPE',
8529 avalue => 'Accepted' );
8530 END IF; */
8531
8532
8533 IF (x_acceptance_result is NULL) THEN
8534 PO_WF_UTIL_PKG.SetItemAttrText ( itemtype => itemtype,
8535 itemkey => itemkey,
8536 aname => 'ACCEPTANCE_RESULT',
8537 avalue => fnd_message.get_string('PO','PO_WF_NOTIF_ACCEPTED') );
8538 END IF;
8539
8540
8541 if (substr(x_supp_user_name, 1, 6) = 'email:') then
8542 --Get the username and store that in the supplier_user_name.
8543 x_supp_user_name := PO_ChangeOrderWF_PVT.getEmailResponderUserName(x_supp_user_name, l_ntf_role_name);
8544 end if;
8545
8546
8547 PO_WF_UTIL_PKG.SetItemAttrText (itemtype => itemtype,
8548 itemkey => itemkey,
8549 aname => 'SUPPLIER_USER_NAME',
8550 avalue => x_supp_user_name);
8551
8552 x_user_id := PO_WF_UTIL_PKG.GetItemAttrNumber (itemtype => itemtype, -- RDP
8553 itemkey => itemkey,
8554 aname => 'BUYER_USER_ID');
8555
8556 -- Default only when the profile option is set
8557 IF( g_default_promise_date = 'Y') THEN
8558 IF(x_document_type_code <> 'RELEASE') THEN -- RDP
8559 POS_ACK_PO.Acknowledge_promise_date(null,x_document_id,null,x_revision_num,x_user_id);
8560 ELSE
8561 POS_ACK_PO.Acknowledge_promise_date(null,x_po_header_id,x_document_id,x_revision_num,x_user_id);
8562 END IF;
8563 END IF;
8564
8565
8566
8567
8568 -- insert acceptance record.
8569 Insert_Acc_Rejection_Row(itemtype, itemkey, actid, 'Y');
8570
8571 EXCEPTION
8572 WHEN OTHERS THEN
8573 wf_core.context('PO_REQAPPROVAL_INIT1','Register_acceptance',x_progress);
8574 raise;
8575 end;
8576
8577 --
8578
8579 procedure Register_rejection ( itemtype in varchar2,
8580 itemkey in varchar2,
8581 actid in number,
8582 funcmode in varchar2,
8583 result out NOCOPY varchar2 )
8584 is
8585 x_progress varchar2(3) := '000';
8586 x_acceptance_result fnd_new_messages.message_text%type := null; -- Bug 2821341
8587 x_org_id number;
8588 x_document_id number;
8589 x_document_type_code varchar2(30);
8590 x_vendor varchar2(80);
8591 x_supp_user_name varchar2(100);
8592 x_supplier_displayname varchar2(100);
8593 --x_accp_type varchar2(100);
8594 l_revision_num number;
8595 l_is_hdr_rejected varchar2(1);
8596 l_return_status varchar2(1);
8597 l_role_name varchar2(50);
8598 l_role_display_name varchar2(50);
8599 l_nid number;
8600 l_ntf_role_name varchar2(320);
8601
8602 begin
8603
8604 -- set the org context
8605 x_org_id := wf_engine.GetItemAttrNumber ( itemtype => itemtype,
8606 itemkey => itemkey,
8607 aname => 'ORG_ID');
8608
8609 PO_MOAC_UTILS_PVT.set_org_context(x_org_id) ; -- <R12 MOAC>
8610
8611 x_progress := '001';
8612 x_document_id := wf_engine.GetItemAttrNumber ( itemtype => itemtype,
8613 itemkey => itemkey,
8614 aname => 'DOCUMENT_ID');
8615
8616 x_document_type_code := wf_engine.GetItemAttrText ( itemtype => itemtype,
8617 itemkey => itemkey,
8618 aname => 'DOCUMENT_TYPE');
8619
8620
8621 -- commented out the usage of accptance_type (FPI)
8622 /* x_accp_type := PO_WF_UTIL_PKG.GetItemAttrText(itemtype => itemtype,
8623 itemkey => itemkey,
8624 aname => 'ACCEPTANCE_TYPE'); */
8625
8626 x_acceptance_result := PO_WF_UTIL_PKG.GetItemAttrText(itemtype => itemtype,
8627 itemkey => itemkey,
8628 aname => 'ACCEPTANCE_RESULT');
8629
8630 if x_document_type_code <> 'RELEASE' then
8631 select
8632 pov.vendor_name,
8633 poh.revision_num
8634 into
8635 x_vendor,
8636 l_revision_num
8637 from po_vendors pov,po_headers poh
8638 where pov.vendor_id = poh.vendor_id
8639 and poh.po_header_id=x_document_id;
8640
8641 x_progress := '002';
8642 PO_ChangeOrderWF_PVT.IsPOHeaderRejected(
8643 1.0,
8644 l_return_status,
8645 x_document_id,
8646 null,
8647 l_revision_num,
8648 l_is_hdr_rejected);
8649 else
8650 select
8651 pov.vendor_name,
8652 por.revision_num
8653 into
8654 x_vendor,
8655 l_revision_num
8656 from po_releases por,
8657 po_headers_all poh, --<R12 MOAC>
8658 po_vendors pov
8659 where por.po_release_id = x_document_id
8660 and por.po_header_id = poh.po_header_id
8661 and poh.vendor_id = pov.vendor_id;
8662
8663 x_progress := '003';
8664 PO_ChangeOrderWF_PVT.IsPOHeaderRejected(
8665 1.0,
8666 l_return_status,
8667 null,
8668 x_document_id,
8669 l_revision_num,
8670 l_is_hdr_rejected);
8671 end if;
8672
8673
8674 if (x_document_type_code <> 'RELEASE') then
8675
8676 --dbms_output.put_line('For std pos');
8677 begin
8678 select a.notification_id, a.recipient_role
8679 INTO l_nid, l_ntf_role_name
8680 from wf_notifications a,
8681 wf_item_activity_statuses wa
8682 where itemkey=wa.item_key
8683 and itemtype=wa.item_type
8684 and a.message_name in ('PO_EMAIL_PO_WITH_RESPONSE', 'PO_EMAIL_PO_PDF_WITH_RESPONSE')
8685 and a.notification_id=wa.notification_id and a.status = 'CLOSED';
8686 exception
8687 when others then l_nid := null;
8688 end;
8689
8690 else
8691 begin
8692 --dbms_output.put_line('For Releases');
8693 select a.notification_id, a.recipient_role
8694 INTO l_nid, l_ntf_role_name
8695 from wf_notifications a,
8696 wf_item_activity_statuses wa
8697 where itemkey=wa.item_key
8698 and itemtype=wa.item_type
8699 and a.message_name in ('PO_EMAIL_PO_WITH_RESPONSE', 'PO_EMAIL_PO_PDF_WITH_RESPONSE')
8700 and a.notification_id=wa.notification_id and a.status = 'CLOSED';
8701 exception
8702 when others then l_nid := null;
8703 end;
8704 end if;
8705
8706 if (l_nid is null) then
8707 --We do not want to continue if the notification is not closed.
8708 return;
8709 else
8710 x_supp_user_name := wf_notification.responder(l_nid);
8711 end if;
8712
8713
8714 PO_WF_UTIL_PKG.SetItemAttrText ( itemtype => itemtype,
8715 itemkey => itemkey,
8716 aname => 'SUPPLIER',
8717 avalue => x_vendor);
8718
8719 -- commented out the usage of accptance_type (FPI)
8720 /* IF (x_accp_type is NULL) THEN
8721 PO_WF_UTIL_PKG.SetItemAttrText ( itemtype => itemtype,
8722 itemkey => itemkey,
8723 aname => 'ACCEPTANCE_TYPE',
8724 avalue => 'Rejected' );
8725 END IF; */
8726
8727
8728 IF (x_acceptance_result is NULL) THEN
8729 PO_WF_UTIL_PKG.SetItemAttrText ( itemtype => itemtype,
8730 itemkey => itemkey,
8731 aname => 'ACCEPTANCE_RESULT',
8732 avalue => 'Rejected' );
8733 END IF;
8734
8735
8736 if (substr(x_supp_user_name, 1, 6) = 'email:') then
8737 --Get the username and store that in the supplier_user_name.
8738 x_supp_user_name := PO_ChangeOrderWF_PVT.getEmailResponderUserName(x_supp_user_name, l_ntf_role_name);
8739 end if;
8740
8741 PO_WF_UTIL_PKG.SetItemAttrText ( itemtype => itemtype,
8742 itemkey => itemkey,
8743 aname => 'SUPPLIER_USER_NAME',
8744 avalue => x_supp_user_name);
8745
8746
8747
8748 -- insert rejection record.
8749 if(l_is_hdr_rejected = 'Y') then
8750 x_progress := '004';
8751 Insert_Acc_Rejection_Row(itemtype, itemkey, actid, 'N');
8752 else
8753 x_progress := '005';
8754 wf_directory.createadhocrole(
8755 l_role_name ,
8756 l_role_display_name ,
8757 null,
8758 null,
8759 null,
8760 'MAILHTML',
8761 null,
8762 null,
8763 null,
8764 'ACTIVE',
8765 sysdate+1);
8766 PO_WF_UTIL_PKG.SetItemAttrText ( itemtype => itemtype,
8767 itemkey => itemkey,
8768 aname => 'BUYER_USER_NAME',
8769 avalue => l_role_name);
8770 end if;
8771
8772 EXCEPTION
8773 WHEN OTHERS THEN
8774 wf_core.context('PO_REQAPPROVAL_INIT1','Register_rejection',x_progress);
8775 raise;
8776 end;
8777
8778
8779 Procedure Insert_Acc_Rejection_Row(itemtype in varchar2,
8780 itemkey in varchar2,
8781 actid in number,
8782 flag in varchar2)
8783 is
8784
8785 x_row_id varchar2(30);
8786 -- Bug 2850566
8787 -- x_Acceptance_id number;
8788 -- x_Last_Update_Date date := TRUNC(SYSDATE);
8789 -- x_Last_Updated_By number := fnd_global.user_id;
8790 -- End of Bug 2850566
8791
8792 x_Creation_Date date := TRUNC(SYSDATE);
8793 x_Created_By number := fnd_global.user_id;
8794 x_Po_Header_Id number;
8795 x_Po_Release_Id number;
8796 x_Action varchar2(240) := 'NEW';
8797 x_Action_Date date := TRUNC(SYSDATE);
8798 x_Employee_Id number;
8799 x_Revision_Num number;
8800 x_Accepted_Flag varchar2(1) := flag;
8801 -- x_Acceptance_Lookup_Code varchar2(25);
8802 x_document_id number;
8803 x_document_type_code varchar2(30);
8804 x_acceptance_note PO_ACCEPTANCES.note%TYPE; --bug 2178922
8805
8806 -- Bug 2850566
8807 l_rowid ROWID;
8808 l_Last_Update_Login PO_ACCEPTANCES.last_update_login%TYPE;
8809 l_Last_Update_Date PO_ACCEPTANCES.last_update_date%TYPE;
8810 l_Last_Updated_By PO_ACCEPTANCES.last_updated_by%TYPE;
8811 l_acc_po_header_id PO_HEADERS_ALL.po_header_id%TYPE;
8812 l_acceptance_id PO_ACCEPTANCES.acceptance_id%TYPE;
8813 -- End of Bug 2850566
8814 l_rspndr_usr_name fnd_user.user_name%TYPE := '';
8815 l_accepting_party varchar2(1);
8816 begin
8817 -- Bug 2850566
8818 -- Commented out the select statement as it is handled in the PO_ACCEPTANCES rowhandler
8819 -- SELECT po_acceptances_s.nextval into x_Acceptance_id FROM sys.dual;
8820
8821 -- commented out the usage of accptance_type (FPI)
8822 /* x_Acceptance_Lookup_Code := wf_engine.GetItemAttrText( itemtype => itemtype,
8823 itemkey => itemkey,
8824 aname => 'ACCEPTANCE_LOOKUP_CODE'); */
8825
8826 x_acceptance_note := PO_WF_UTIL_PKG.GetItemAttrText( itemtype => itemtype,
8827 itemkey => itemkey,
8828 aname => 'ACCEPTANCE_COMMENTS');
8829
8830 -- commented out the usage of accptance_type (FPI)
8831 /* if (x_Acceptance_Lookup_Code is NULL) then
8832 if flag = 'Y' then
8833 x_Acceptance_Lookup_Code := 'Accepted Terms';
8834 else
8835 x_Acceptance_Lookup_Code := 'Unacceptable Changes';
8836 end if;
8837 end if; */
8838
8839 x_document_id := wf_engine.GetItemAttrNumber ( itemtype => itemtype,
8840 itemkey => itemkey,
8841 aname => 'DOCUMENT_ID');
8842
8843 x_document_type_code := wf_engine.GetItemAttrText ( itemtype => itemtype,
8844 itemkey => itemkey,
8845 aname => 'DOCUMENT_TYPE');
8846
8847 -- abort any outstanding acceptance notifications for any previous revision of the document.
8848
8849 if x_document_type_code <> 'RELEASE' then
8850 x_Po_Header_Id := x_document_id;
8851
8852 select revision_num,agent_id
8853 into x_revision_num,x_employee_id
8854 from po_headers
8855 where po_header_id = x_document_id;
8856 else
8857 x_Po_Release_Id := x_document_id;
8858
8859 select po_header_id, revision_num,agent_id
8860 into x_Po_Header_Id, x_revision_num,x_employee_id
8861 from po_releases
8862 where po_release_id = x_document_id;
8863 end if;
8864
8865 -- Bug 2850566 RBAIRRAJ
8866 -- Calling the Acceptances row handler to insert into the PO_ACCEPTANCES table
8867 -- instead of writing an Insert statement.
8868
8869 IF x_po_release_id IS NULL THEN
8870 l_acc_po_header_id := x_po_header_id;
8871 ELSE
8872 l_acc_po_header_id := NULL;
8873 END IF;
8874
8875 l_rspndr_usr_name := wf_engine.GetItemAttrText ( itemtype => itemtype,
8876 itemkey => itemkey,
8877 aname => 'SUPPLIER_USER_NAME');
8878
8879 begin
8880 select user_id into l_Last_Updated_By
8881 from fnd_user
8882 where user_name = upper(l_rspndr_usr_name);
8883 l_accepting_party := 'S';
8884 exception when others then
8885 --in case of non-isp users there wont be any suppliers
8886 l_Last_Updated_By := x_created_by;
8887 l_accepting_party := 'S'; --ack is always by supplier.
8888 end;
8889 l_Last_Update_Login := l_Last_Updated_By;
8890
8891 PO_ACCEPTANCES_INS_PVT.insert_row(
8892 x_rowid => l_rowid,
8893 x_acceptance_id => l_acceptance_id,
8894 x_Last_Update_Date => l_Last_Update_Date,
8895 x_Last_Updated_By => l_Last_Updated_By,
8896 x_Last_Update_Login => l_Last_Update_Login,
8897 p_creation_date => x_Creation_Date,
8898 p_created_by => l_Last_Updated_By,
8899 p_po_header_id => l_acc_po_header_id,
8900 p_po_release_id => x_Po_Release_Id,
8901 p_action => x_Action,
8902 p_action_date => x_Action_Date,
8903 p_employee_id => null,
8904 p_revision_num => x_Revision_Num,
8905 p_accepted_flag => x_Accepted_Flag,
8906 p_note => x_acceptance_note,
8907 p_accepting_party => l_accepting_party
8908 );
8909
8910 -- End of Bug 2850566 RBAIRRAJ
8911
8912
8913 -- Reset the Acceptance required Flag
8914 --Bug 6847039 - Start
8915 --Update the last update date when po_headers_all/po_releases_all tables are updated.
8916 if x_po_release_id is not null then
8917 update po_releases
8918 set acceptance_required_flag = 'N',
8919 LAST_UPDATE_DATE = SYSDATE,
8920 acceptance_due_date = ''
8921 where po_release_id = x_po_release_id;
8922 else
8923 update po_headers
8924 set acceptance_required_flag = 'N',
8925 LAST_UPDATE_DATE = SYSDATE,
8926 acceptance_due_date = ''
8927 where po_header_id = x_po_header_id;
8928 end if;
8929
8930 exception
8931 when others then
8932 raise;
8933 end;
8934
8935 /* Bug#2353153: kagarwal
8936 ** Added new PROCEDURE set_doc_mgr_context as a global procedure as this
8937 ** is being used by wf apis present in different packages.
8938 **
8939 ** Calling Set_doc_mgr_context to set the application context in procedures
8940 ** Set_Startup_Values() and Is_doc_preapproved() procedures for PO Approval
8941 ** to succeed when SLS SUB LEDGER SECURITY (IGI) is being used
8942 */
8943
8944 PROCEDURE Set_doc_mgr_context (itemtype VARCHAR2,
8945 itemkey VARCHAR2) is
8946
8947 l_user_id number;
8948 l_responsibility_id number;
8949 l_application_id number;
8950 l_orgid number; --RETRO FPI
8951
8952 x_progress varchar2(200);
8953
8954 -- Bug 4290541 Start
8955 X_User_Id NUMBER;
8956 X_Responsibility_Id NUMBER;
8957 X_Application_Id NUMBER;
8958 -- Bug 4290541 End
8959
8960 BEGIN
8961
8962 -- Bug 4290541 Start
8963 --Fnd_Profile.Get('USER_ID',X_User_Id);
8964 --Fnd_Profile.Get('RESP_ID',X_Responsibility_Id);
8965 --Fnd_Profile.Get('RESP_APPL_ID',X_Application_Id);
8966 -- Bug 4290541 End
8967 -- Context Setting Revamp
8968 X_User_Id := fnd_global.user_id;
8969 X_Responsibility_Id := fnd_global.resp_id;
8970 X_Application_Id := fnd_global.resp_appl_id;
8971
8972
8973 x_progress := 'PO_REQAPPROVAL_INIT1.set_doc_mgr_context.X_USER_ID= '
8974 || to_char(x_user_id)
8975 || 'X_ APPLICATION_ID= ' || to_char(x_application_id)
8976 || 'X_RESPONSIBILITY_ID= ' || to_char(x_responsibility_id);
8977 IF (g_po_wf_debug = 'Y') THEN
8978 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
8979 END IF;
8980
8981
8982 IF (X_User_Id = -1) THEN
8983 X_User_Id := NULL;
8984 END IF;
8985
8986 IF (X_Responsibility_Id = -1) THEN
8987 X_Responsibility_Id := NULL;
8988 END IF;
8989
8990 IF (X_Application_Id = -1) THEN
8991 X_Application_Id := NULL;
8992 END IF;
8993
8994 l_user_id := wf_engine.GetItemAttrNumber ( itemtype => itemtype,
8995 itemkey => itemkey,
8996 aname => 'USER_ID');
8997 --
8998 l_application_id := wf_engine.GetItemAttrNumber ( itemtype => itemtype,
8999 itemkey => itemkey,
9000 aname => 'APPLICATION_ID');
9001 --
9002 l_responsibility_id := wf_engine.GetItemAttrNumber ( itemtype => itemtype,
9003 itemkey => itemkey,
9004 aname => 'RESPONSIBILITY_ID');
9005
9006 x_progress := 'PO_REQAPPROVAL_INIT1.set_doc_mgr_context.L_USER_ID= '
9007 || to_char(l_user_id)
9008 || ' L_APPLICATION_ID= ' || to_char(l_application_id)
9009 || 'L_RESPONSIBILITY_ID= ' || to_char(l_responsibility_id);
9010 IF (g_po_wf_debug = 'Y') THEN
9011 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
9012 END IF;
9013
9014 -- bug 3543578
9015 -- Returning a Req from AutoCreate was nulling out the FND context.
9016 -- No particular context is required for sending the notification in
9017 -- the NOTIFY_RETURN_REQ process, so only change the context if
9018 -- a valid context has been explicitly set for the workflow process.
9019
9020 -- Bug 4125251 Start
9021 -- Set the application context to the logged-in user
9022 -- if not null
9023
9024 IF (NVL(X_USER_ID,-1) = -1 OR
9025 NVL(X_RESPONSIBILITY_ID,-1) = -1 OR
9026 NVL(X_APPLICATION_ID,-1) = -1)THEN
9027 IF X_USER_ID IS NOT NULL THEN
9028 FND_GLOBAL.APPS_INITIALIZE (X_USER_ID, L_RESPONSIBILITY_ID, L_APPLICATION_ID);
9029 ELSE
9030 -- Start fix for Bug 3543578
9031 IF ( L_USER_ID IS NOT NULL
9032 AND L_RESPONSIBILITY_ID IS NOT NULL
9033 AND L_APPLICATION_ID IS NOT NULL) THEN
9034 FND_GLOBAL.APPS_INITIALIZE (L_USER_ID, L_RESPONSIBILITY_ID, L_APPLICATION_ID);
9035 END IF;
9036 -- End fix for Bug 3543578
9037 END IF;
9038 END IF;
9039 -- Bug 4125251 End
9040
9041 /* RETRO FPI START.
9042 * If we had set the org context for a different operating unit, the above
9043 * fnd_global.APPS_INITIALIZE resets it back to the operating unit of
9044 * the responsibility. So set the org context explicitly again.
9045 */
9046 l_orgid := PO_WF_UTIL_PKG.GetItemAttrNumber (itemtype => itemtype,
9047 itemkey => itemkey,
9048 aname => 'ORG_ID');
9049
9050 IF l_orgid is NOT NULL THEN
9051
9052 PO_MOAC_UTILS_PVT.set_org_context(l_orgid) ; -- <R12 MOAC>
9053
9054 END IF;
9055
9056 /* RETRO FPI END. */
9057
9058
9059 -- Bug 3571038
9060 igi_sls_context_pkg.set_sls_context;
9061
9062
9063 EXCEPTION
9064
9065 WHEN OTHERS THEN
9066 wf_core.context('PO_REQAPPROVAL_ACTION','set_doc_mgr_context',x_progress);
9067 raise;
9068
9069 END Set_doc_mgr_context;
9070
9071 /* RETROACTIVE FPI START */
9072 procedure MassUpdate_Releases_Yes_No( itemtype in varchar2,
9073 itemkey in varchar2,
9074 actid in number,
9075 funcmode in varchar2,
9076 resultout out NOCOPY varchar2 ) IS
9077 l_orgid number;
9078 l_massupdate_releases varchar2(2);
9079 l_progress varchar2(300);
9080
9081 l_doc_string varchar2(200);
9082 l_preparer_user_name varchar2(100);
9083 l_document_type PO_DOCUMENT_TYPES_ALL.DOCUMENT_TYPE_CODE%TYPE;
9084 l_document_subtype PO_DOCUMENT_TYPES_ALL.DOCUMENT_SUBTYPE%TYPE;
9085
9086 l_resp_id number;
9087 l_user_id number;
9088 l_appl_id number;
9089
9090 BEGIN
9091
9092 l_progress := 'PO_REQAPPROVAL_INIT1.MassUpdate_Releases_Yes_No: 01';
9093 IF (g_po_wf_debug = 'Y') THEN
9094 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,l_progress);
9095 END IF;
9096
9097 -- Do nothing in cancel or timeout mode
9098 if (funcmode <> wf_engine.eng_run) then
9099
9100 resultout := wf_engine.eng_null;
9101 return;
9102
9103 end if;
9104
9105 l_orgid := PO_WF_UTIL_PKG.GetItemAttrNumber (itemtype => itemtype,
9106 itemkey => itemkey,
9107 aname => 'ORG_ID');
9108
9109
9110 l_user_id := PO_WF_UTIL_PKG.GetItemAttrNumber (itemtype => itemtype,
9111 itemkey => itemkey,
9112 aname => 'USER_ID');
9113
9114 l_resp_id := PO_WF_UTIL_PKG.GetItemAttrNumber (itemtype => itemtype,
9115 itemkey => itemkey,
9116 aname => 'RESPONSIBILITY_ID');
9117
9118 l_appl_id := PO_WF_UTIL_PKG.GetItemAttrNumber (itemtype => itemtype,
9119 itemkey => itemkey,
9120 aname => 'APPLICATION_ID');
9121
9122 /* Since the call may be started from background engine (new seesion),
9123 * need to ensure the fnd context is correct
9124 */
9125
9126 --Context Setting Revamp
9127 /* if (l_user_id is not null and
9128 l_resp_id is not null and
9129 l_appl_id is not null )then
9130
9131 -- Bug 4125251,replaced apps init call with set doc mgr context call
9132 PO_REQAPPROVAL_INIT1.Set_doc_mgr_context(itemtype, itemkey); */
9133
9134 IF l_orgid is NOT NULL THEN
9135 PO_MOAC_UTILS_PVT.set_org_context(l_orgid) ; -- <R12 MOAC>
9136 END IF;
9137
9138 -- end if;
9139
9140
9141
9142 l_massupdate_releases := PO_WF_UTIL_PKG.GetItemAttrText (itemtype => itemtype,
9143 itemkey => itemkey,
9144 aname => 'MASSUPDATE_RELEASES');
9145 l_document_type := PO_WF_UTIL_PKG.GetItemAttrText (itemtype => itemtype,
9146 itemkey => itemkey,
9147 aname => 'DOCUMENT_TYPE');
9148 l_document_subtype := PO_WF_UTIL_PKG.GetItemAttrText (itemtype =>itemtype,
9149 itemkey => itemkey,
9150 aname => 'DOCUMENT_SUBTYPE');
9151
9152 /* the value of CREATE_SOURCING_RULE should be Y or N */
9153 IF (nvl(l_massupdate_releases,'N') <> 'Y') THEN
9154 l_massupdate_releases := 'N';
9155 ELSE
9156 if (l_document_type = 'PA' and l_document_subtype = 'BLANKET') then
9157 l_massupdate_releases := 'Y';
9158 else
9159 l_massupdate_releases := 'N';
9160 end if;
9161 END IF;
9162
9163 resultout := wf_engine.eng_completed || ':' || l_massupdate_releases;
9164
9165 l_progress := 'PO_REQAPPROVAL_INIT1.MassUpdate_Releases_Yes_No: 02. Result= ' || l_massupdate_releases;
9166 IF (g_po_wf_debug = 'Y') THEN
9167 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,l_progress);
9168 END IF;
9169
9170 EXCEPTION
9171 WHEN OTHERS THEN
9172 l_massupdate_releases := 'N';
9173 resultout := wf_engine.eng_completed || ':' || l_massupdate_releases;
9174 END MassUpdate_Releases_Yes_No;
9175
9176 procedure MassUpdate_Releases_Workflow( itemtype in varchar2,
9177 itemkey in varchar2,
9178 actid in number,
9179 funcmode in varchar2,
9180 resultout out NOCOPY varchar2 ) is
9181 l_document_id po_headers_all.po_header_id%type;
9182 l_vendor_id po_headers_all.vendor_id%type;
9183 l_vendor_site_id po_headers_all.vendor_site_id%type;
9184 l_progress varchar2(300);
9185 l_update_releases varchar2(1) := 'Y';
9186 l_return_status varchar2(1) ;
9187 l_communicate_update varchar2(30); -- Bug 3574895. Length same as that on the form field PO_APPROVE.COMMUNICATE_UPDATES
9188 l_category_struct_id mtl_category_sets_b.structure_id%type; -- Bug 3592705
9189 begin
9190
9191 l_progress := 'PO_REQAPPROVAL_INIT1.MassUpdate_Releases_Workflow: 01';
9192
9193 /* Bug# 2846210
9194 ** Desc: Setting application context as this wf api will be executed
9195 ** after the background engine is run.
9196 */
9197
9198 Set_doc_mgr_context(itemtype, itemkey);
9199
9200 l_document_id := PO_WF_UTIL_PKG.GetItemAttrNumber (itemtype => itemtype,
9201 itemkey => itemkey,
9202 aname => 'DOCUMENT_ID');
9203 select poh.vendor_id, poh.vendor_site_id
9204 into l_vendor_id, l_vendor_site_id
9205 from po_headers poh
9206 where poh.po_header_id = l_document_id;
9207
9208 --<Bug 3592705 Start> Retrieved the default structure for
9209 -- Purchasing from the view mtl_default_sets_view.
9210 Begin
9211 SELECT structure_id
9212 INTO l_category_struct_id
9213 FROM mtl_default_sets_view
9214 WHERE functional_area_id = 2 ;
9215 Exception
9216 when others then
9217 l_progress := 'PO_REQAPPROVAL_INIT1.MassUpdate_Releases_Workflow: Could not find Category Structure Id';
9218 IF (g_po_wf_debug = 'Y') THEN
9219 PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,l_progress);
9220 END IF;
9221 raise;
9222 End;
9223 --<Bug 3592705 End>
9224
9225 --Bug 3574895. Retroactively Repriced Releases/Std PO's are not getting
9226 -- communicated to supplier. Need to pick up the workflow
9227 -- attribute CO_H_RETROACTIVE_SUPPLIER_COMM here from the
9228 -- Blanket Approval Workflow and pass it in the procedure
9229 -- call below so that it may be set correctly for Release/
9230 -- Standard PO Approval as well.
9231 l_communicate_update := PO_WF_UTIL_PKG.GetItemAttrText (itemtype => itemtype,
9232 itemkey => itemkey,
9233 aname => 'CO_H_RETROACTIVE_SUPPLIER_COMM');
9234
9235 PO_RETROACTIVE_PRICING_PVT. MassUpdate_Releases
9236 ( p_api_version => 1.0,
9237 p_validation_level => 100,
9238 p_vendor_id => l_vendor_id,
9239 p_vendor_site_id => l_vendor_site_id ,
9240 p_po_header_id => l_document_id,
9241 p_category_struct_id => l_category_struct_id, -- Bug 3592705
9242 p_category_from => null,
9243 p_category_to => null,
9244 p_item_from => null,
9245 p_item_to => null,
9246 p_date => null,
9247 p_communicate_update => l_communicate_update, --Bug 3574895
9248 x_return_status => l_return_status);
9249
9250 If (l_return_status <> 'S') then
9251 l_update_releases := 'N';
9252 End if;
9253
9254 l_progress := ': 02. Result= ' || l_update_releases;
9255 IF (g_po_wf_debug = 'Y') THEN
9256 PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,l_progress);
9257 END IF;
9258 resultout := wf_engine.eng_completed || ':' || l_update_releases;
9259 EXCEPTION
9260 WHEN OTHERS THEN
9261 l_update_releases := 'N';
9262 l_progress := 'PO_REQAPPROVAL_INIT1.MassUpdate_Releases_Workflow: 03.'||
9263 ' Result= ' || l_update_releases;
9264 resultout := wf_engine.eng_completed || ':' || l_update_releases;
9265 IF (g_po_wf_debug = 'Y') THEN
9266 PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,l_progress);
9267 END IF;
9268 END MassUpdate_Releases_Workflow;
9269
9270 procedure Send_Supplier_Comm_Yes_No( itemtype in varchar2,
9271 itemkey in varchar2,
9272 actid in number,
9273 funcmode in varchar2,
9274 resultout out NOCOPY varchar2 ) IS
9275 l_retro_change varchar2(1);
9276 l_supplier_comm varchar2(1) := 'Y'; --default has to be Y
9277 l_progress varchar2(300);
9278 l_document_type PO_DOCUMENT_TYPES_ALL.DOCUMENT_TYPE_CODE%TYPE;
9279 l_document_subtype PO_DOCUMENT_TYPES_ALL.DOCUMENT_SUBTYPE%TYPE;
9280
9281 BEGIN
9282 l_progress := 'PO_REQAPPROVAL_INIT1.Send_Supplier_Comm_Yes_No: 01';
9283
9284 l_retro_change := PO_WF_UTIL_PKG.GetItemAttrText (itemtype => itemtype,
9285 itemkey => itemkey,
9286 aname => 'CO_R_RETRO_CHANGE');
9287
9288 -- Bug 3694128 : get the document type and subtype
9289 l_document_type := PO_WF_UTIL_PKG.GetItemAttrText (itemtype => itemtype,
9290 itemkey => itemkey,
9291 aname => 'DOCUMENT_TYPE');
9292
9293 l_document_subtype := PO_WF_UTIL_PKG.GetItemAttrText (itemtype => itemtype,
9294 itemkey => itemkey,
9295 aname => 'DOCUMENT_SUBTYPE');
9296
9297 -- Bug 3694128 : The communication depends on the WF attribute only
9298 -- for std PO's and blanket releases. For all other documents we
9299 -- always communicate.
9300 If (l_retro_change = 'Y') and
9301 ((l_document_type = 'RELEASE' AND l_document_subtype = 'BLANKET') OR
9302 (l_document_type = 'PO' AND l_document_subtype = 'STANDARD')) then
9303 l_supplier_comm := PO_WF_UTIL_PKG.GetItemAttrText (itemtype => itemtype,
9304 itemkey => itemkey,
9305 aname => 'CO_H_RETROACTIVE_SUPPLIER_COMM');
9306 else
9307 l_supplier_comm := 'Y';
9308 end if;
9309
9310 -- Bug 3325520
9311 IF (l_supplier_comm IS NULL) THEN
9312 l_supplier_comm := 'N';
9313 END IF; /*IF (l_supplier_comm IS NULL)*/
9314
9315 resultout := wf_engine.eng_completed || ':' || l_supplier_comm;
9316
9317 l_progress := 'PO_REQAPPROVAL_INIT1.Send_Supplier_Comm_Yes_No: 02. Result= ' || l_supplier_comm;
9318 IF (g_po_wf_debug = 'Y') THEN
9319 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,l_progress);
9320 END IF;
9321
9322
9323 EXCEPTION
9324 WHEN OTHERS THEN
9325 l_supplier_comm := 'Y';
9326 resultout := wf_engine.eng_completed || ':' || l_supplier_comm;
9327 END Send_Supplier_Comm_Yes_No;
9328
9329 /* RETROACTIVE FPI END */
9330
9331 /************************************************************************************
9332 * Added this procedure as part of Bug #: 2843760
9333 * This procedure basically checks if archive_on_print option is selected, and if yes
9334 * call procedure PO_ARCHIVE_PO_SV.ARCHIVE_PO to archive the PO
9335 *************************************************************************************/
9336 procedure archive_po(p_document_id in number,
9337 p_document_type in varchar2,
9338 p_document_subtype in varchar2)
9339 IS
9340 -- <FPJ Refactor Archiving API>
9341 l_return_status varchar2(1) ;
9342 l_msg_count NUMBER := 0;
9343 l_msg_data VARCHAR2(2000);
9344
9345 BEGIN
9346
9347 -- <FPJ Refactor Archiving API>
9348 PO_DOCUMENT_ARCHIVE_GRP.Archive_PO(
9349 p_api_version => 1.0,
9350 p_document_id => p_document_id,
9351 p_document_type => p_document_type,
9352 p_document_subtype => p_document_subtype,
9353 p_process => 'PRINT',
9354 x_return_status => l_return_status,
9355 x_msg_count => l_msg_count,
9356 x_msg_data => l_msg_data);
9357
9358 END ARCHIVE_PO;
9359
9360
9361 -- <FPJ Retroactive START>
9362 /**
9363 * Public Procedure: Retro_Invoice_Release_WF
9364 * Requires:
9365 * IN PARAMETERS:
9366 * Usual workflow attributes.
9367 * Modifies: PO_DISTRIBUTIONS_ALL.invoice_adjustment_flag
9368 * Effects: This procedure updates invoice adjustment flag, and calls Costing
9369 * and Inventory APIs.
9370 */
9371 PROCEDURE Retro_Invoice_Release_WF( itemtype IN VARCHAR2,
9372 itemkey IN VARCHAR2,
9373 actid IN NUMBER,
9374 funcmode IN VARCHAR2,
9375 resultout OUT NOCOPY VARCHAR2)
9376 IS
9377
9378 l_retro_change VARCHAR2(1);
9379 l_document_id PO_HEADERS_ALL.po_header_id%TYPE;
9380 l_document_type PO_DOCUMENT_TYPES.document_type_code%TYPE;
9381 l_progress VARCHAR2(2000);
9382 l_update_releases VARCHAR2(1) := 'Y';
9383 l_return_status VARCHAR2(1) ;
9384 l_msg_count NUMBER := 0;
9385 l_msg_data VARCHAR2(2000);
9386 l_retroactive_update VARCHAR2(30) := 'NEVER';
9387 l_reset_retro_update BOOLEAN := FALSE;
9388
9389 BEGIN
9390
9391 l_progress := 'PO_REQAPPROVAL_INIT1.Retro_Invoice_Release_WF: 01';
9392 IF (g_po_wf_debug = 'Y') THEN
9393 PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,l_progress);
9394 END IF;
9395
9396 resultout := wf_engine.eng_completed || ':' || l_update_releases;
9397
9398 /* Bug# 2846210
9399 ** Desc: Setting application context as this wf api will be executed
9400 ** after the background engine is run.
9401 */
9402
9403 Set_doc_mgr_context(itemtype, itemkey);
9404
9405 l_document_id := wf_engine.GetItemAttrNumber (itemtype => itemtype,
9406 itemkey => itemkey,
9407 aname => 'DOCUMENT_ID');
9408 l_document_type := wf_engine.GetItemAttrText (itemtype => itemtype,
9409 itemkey => itemkey,
9410 aname => 'DOCUMENT_TYPE');
9411
9412 l_retro_change := PO_WF_UTIL_PKG.GetItemAttrText (itemtype => itemtype,
9413 itemkey => itemkey,
9414 aname => 'CO_R_RETRO_CHANGE');
9415
9416 l_progress := 'PO_REQAPPROVAL_INIT1.Retro_Invoice_Release_WF: 02. ' ||
9417 'l_document_id = ' || l_document_id ||
9418 'l_document_type = ' || l_document_type ||
9419 'l_retro_change = ' || l_retro_change ;
9420
9421 IF (g_po_wf_debug = 'Y') THEN
9422 PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,l_progress);
9423 END IF;
9424
9425 -- Only handle retroactive invoice change for PO or Release
9426 IF (l_document_type NOT IN ('PO', 'RELEASE')) THEN
9427 RETURN;
9428 END IF;
9429
9430 -- Don't trust l_retro_change='N' because if user makes retro changes, instead
9431 -- of approving it immediately, he chooses to close the form and re-query
9432 -- the PO/Release, then approve it.
9433 -- In this case, d_globals.retroactive_change_flag is lost.
9434 -- Always trust l_retro_change='Y'
9435 IF (l_retro_change IS NULL OR l_retro_change = 'N') THEN
9436
9437 l_retro_change := PO_RETROACTIVE_PRICING_PVT.Is_Retro_Update(
9438 p_document_id => l_document_id,
9439 p_document_type => l_document_type);
9440
9441 l_progress := 'PO_REQAPPROVAL_INIT1.Retro_Invoice_Release_WF: 03' ||
9442 'l_retro_change = ' || l_retro_change ;
9443 IF (g_po_wf_debug = 'Y') THEN
9444 PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,l_progress);
9445 END IF;
9446
9447
9448 END IF; /*IF (l_retro_change IS NULL OR l_retro_change = 'N')*/
9449
9450 IF (l_retro_change = 'Y') THEN
9451 l_retroactive_update := PO_RETROACTIVE_PRICING_PVT.Get_Retro_Mode;
9452
9453 l_progress := 'PO_REQAPPROVAL_INIT1.Retro_Invoice_Release_WF: 04' ||
9454 'l_retroactive_update = ' || l_retroactive_update;
9455 IF (g_po_wf_debug = 'Y') THEN
9456 PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,l_progress);
9457 END IF;
9458
9459 -- Need to reset retroactive_date afterwards
9460 l_reset_retro_update := TRUE;
9461
9462 IF (l_retroactive_update = 'NEVER') THEN
9463 l_retro_change := 'N';
9464 END IF; /*IF (l_retroactive_update = 'NEVER')*/
9465
9466 END IF; /*IF (l_retro_change = 'Y')*/
9467
9468 l_progress := 'PO_REQAPPROVAL_INIT1.Retro_Invoice_Release_WF: 05' ||
9469 'l_retroactive_update = ' || l_retroactive_update ||
9470 'l_retro_change = ' || l_retro_change ;
9471 IF (g_po_wf_debug = 'Y') THEN
9472 PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,l_progress);
9473 END IF;
9474
9475 -- Set 'CO_R_RETRO_CHANGE' attribute so that later Workflow process can
9476 -- use this attribute safely
9477 PO_WF_UTIL_PKG.SetItemAttrText (itemtype => itemtype,
9478 itemkey => itemkey,
9479 aname => 'CO_R_RETRO_CHANGE',
9480 avalue => l_retro_change);
9481
9482 IF (l_retro_change = 'Y' AND l_retroactive_update = 'ALL_RELEASES') THEN
9483 l_progress := 'PO_REQAPPROVAL_INIT1.Retro_Invoice_Release_WF: 06. Calling ' ||
9484 'PO_RETROACTIVE_PRICING_PVT.Retro_Invoice_Release';
9485 IF (g_po_wf_debug = 'Y') THEN
9486 PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,l_progress);
9487 END IF;
9488
9489 PO_RETROACTIVE_PRICING_PVT.Retro_Invoice_Release
9490 ( p_api_version => 1.0,
9491 p_document_id => l_document_id,
9492 p_document_type => l_document_type ,
9493 x_return_status => l_return_status,
9494 x_msg_count => l_msg_count,
9495 x_msg_data => l_msg_data);
9496
9497 IF (l_return_status <> 'S') THEN
9498 l_update_releases := 'N';
9499 END IF;
9500
9501 l_progress := 'PO_REQAPPROVAL_INIT1.Retro_Invoice_Release_WF: 07. Result= ' ||
9502 l_update_releases;
9503 IF (g_po_wf_debug = 'Y') THEN
9504 PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,l_progress);
9505 END IF;
9506
9507 END IF; /*IF (l_retro_change = 'Y' AND l_retroactive_update = 'ALL_RELEASES')*/
9508
9509 IF (l_reset_retro_update) THEN
9510 l_progress := 'PO_REQAPPROVAL_INIT1.Retro_Invoice_Release_WF: 08. Reset_Retro_Update';
9511 IF (g_po_wf_debug = 'Y') THEN
9512 PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,l_progress);
9513 END IF;
9514
9515 PO_RETROACTIVE_PRICING_PVT.Reset_Retro_Update(
9516 p_document_id => l_document_id,
9517 p_document_type => l_document_type);
9518 END IF; /*IF (l_reset_retro_update)*/
9519
9520 resultout := wf_engine.eng_completed || ':' || l_update_releases;
9521
9522 EXCEPTION
9523 WHEN OTHERS THEN
9524 l_update_releases := 'N';
9525 l_progress := 'PO_REQAPPROVAL_INIT1.Retro_Invoice_Release_WF: 09.'||
9526 ' Result= ' || l_update_releases;
9527 resultout := wf_engine.eng_completed || ':' || l_update_releases;
9528 IF (g_po_wf_debug = 'Y') THEN
9529 PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,l_progress);
9530 END IF;
9531
9532 END Retro_Invoice_Release_WF;
9533
9534 -- <FPJ Retroactive END>
9535
9536 -------------------------------------------------------------------------------
9537 --Start of Comments : Bug 3845048
9538 --Name: UpdateActionHistory
9539 --Pre-reqs:
9540 -- None.
9541 --Modifies:
9542 -- None.
9543 --Locks:
9544 -- None.
9545 --Function:
9546 -- Updates the action history for the given doc with an action
9547 --Parameters:
9548 --IN:
9549 --p_doc_id
9550 -- Document id
9551 --p_doc_type
9552 -- Document type
9553 --p_doc_subtype
9554 -- Document Sub type
9555 --p_action
9556 -- Action to be inserted into the action history
9557 --Testing:
9558 -- None.
9559 --End of Comments
9560 -------------------------------------------------------------------------------
9561 -- <BUG 5691965 START>
9562 /*
9563 Update the Action History with a note ICX_POR_NOTIF_TIMEOUT in approvers
9564 language
9565 */
9566 PROCEDURE UpdateActionHistory(p_doc_id IN number,
9567 p_doc_type IN varchar2,
9568 p_doc_subtype IN varchar2,
9569 p_action IN varchar2
9570 ) is
9571 pragma AUTONOMOUS_TRANSACTION;
9572
9573 l_emp_id NUMBER;
9574 l_rowid ROWID;
9575 l_name wf_local_roles.NAME%TYPE;
9576 l_display_name wf_local_roles.display_name%TYPE;
9577 l_email_address wf_local_roles.email_address%TYPE;
9578 l_notification_preference wf_local_roles.notification_preference%TYPE;
9579 l_language wf_local_roles.LANGUAGE%TYPE;
9580 l_territory wf_local_roles.territory%TYPE;
9581 l_note fnd_new_messages.message_text%TYPE;
9582
9583 BEGIN
9584 -- SQL What : Get the employee_id corresponding to the last NULL action record.
9585 -- Sql Why : To get hold the language of the employee.
9586
9587 BEGIN
9588 SELECT pah.employee_id, pah.ROWID
9589 INTO l_emp_id, l_rowid
9590 FROM po_action_history pah
9591 WHERE pah.object_id = p_doc_id
9592 AND pah.object_type_code = p_doc_type
9593 AND pah.object_sub_type_code = p_doc_subtype
9594 AND pah.sequence_num = (SELECT Max(sequence_num)
9595 FROM po_action_history pah1
9596 WHERE pah1.object_id = p_doc_id
9597 AND pah1.object_type_code = p_doc_type
9598 AND pah1.object_sub_type_code = p_doc_subtype)
9599 AND pah.action_code is NULL;
9600 EXCEPTION
9601 WHEN OTHERS THEN
9602 NULL;
9603 END;
9604
9605 IF l_emp_id IS NOT NULL THEN
9606
9607 wf_directory.GetUserName ( p_orig_system => 'PER',
9608 p_orig_system_id => l_emp_id,
9609 p_name => l_name,
9610 p_display_name => l_display_name );
9611
9612 IF l_name IS NOT NULL THEN
9613
9614 WF_DIRECTORY.GETROLEINFO ( ROLE => l_name,
9615 Display_Name => l_display_name,
9616 Email_Address => l_email_address,
9617 Notification_Preference => l_notification_preference,
9618 LANGUAGE => l_language,
9619 Territory => l_territory );
9620
9621 IF l_language IS NOT NULL THEN
9622 BEGIN
9623 -- SQL What : Get the message in the approvers language.
9624 -- Sql Why : To maintain the NO ACTION message in approver language.
9625 SELECT message_text
9626 INTO l_note
9627 FROM fnd_new_messages fm,
9628 fnd_languages fl
9629 WHERE fm.message_name = 'ICX_POR_NOTIF_TIMEOUT'
9630 AND fm.language_code = fl.language_code
9631 AND fl.nls_language = l_language;
9632 EXCEPTION
9633 WHEN OTHERS THEN
9634 NULL;
9635 END;
9636 END IF;
9637 END IF;
9638 END IF;
9639
9640 IF l_note IS NULL THEN
9641 l_note := fnd_message.get_string('ICX', 'ICX_POR_NOTIF_TIMEOUT');
9642 END IF;
9643
9644 IF l_rowid IS NOT NULL THEN
9645 -- SQL What : Update the No action in the action history.
9646 -- Sql Why : To maintain the NO ACTION message in approver language.
9647 UPDATE po_action_history pah
9648 SET pah.action_code = p_action,
9649 pah.action_date = SYSDATE,
9650 pah.Note = l_note,
9651 pah.last_updated_by = fnd_global.user_id,
9652 pah.last_update_login = fnd_global.login_id,
9653 pah.last_update_date = SYSDATE
9654 WHERE ROWID = l_rowid;
9655 END IF;
9656 COMMIT;
9657
9658 EXCEPTION
9659 WHEN OTHERS THEN
9660 NULL;
9661 END;
9662 -- <BUG 5691965 END>
9663 -------------------------------------------------------------------------------
9664 --Start of Comments : R12 Online authoring Notifications
9665 --Name: should_notify_cat_admin
9666 --Pre-reqs:
9667 -- None.
9668 --Modifies:
9669 -- None.
9670 --Locks:
9671 -- None.
9672 --Function:
9673 -- Determines if the Catalog admin has to be notified of the
9674 -- PO approval. The catalog admin will be notified if the changes
9675 -- were initiated by admin. In this scenario, the notification will be
9676 -- sent to both the catalog admin (in addition to the buyer+supplier, which is
9677 -- an existing logic)
9678 --Parameters:
9679 --IN:
9680 --p_item_type
9681 -- WF item type
9682 --p_item_key
9683 -- WF Item key
9684 --p_act_id
9685 -- ActionId
9686 --p_func_mode
9687 -- Function mode
9688 --OUT
9689 --x_result_out
9690 -- Y/N: Whether to send notification to catalog admin or not
9691 --Testing:
9692 -- None.
9693 --End of Comments
9694 -------------------------------------------------------------------------------
9695 PROCEDURE should_notify_cat_admin(p_item_type in varchar2,
9696 p_item_key in varchar2,
9697 p_act_id in number,
9698 p_func_mode in varchar2,
9699 x_result_out out NOCOPY varchar2 ) is
9700 l_progress varchar2(200);
9701 l_doc_id number;
9702 l_doc_type PO_HEADERS_ALL.TYPE_LOOKUP_CODE%type;
9703 l_cat_admin_user_name FND_USER.USER_NAME%type;
9704 BEGIN
9705 l_progress := '100';
9706 IF (g_po_wf_debug = 'Y') THEN
9707 PO_WF_DEBUG_PKG.insert_debug(p_item_type,p_item_key,l_progress);
9708 END IF;
9709
9710 l_progress := '110';
9711 -- Get the Catalog Admin User Name
9712 l_cat_admin_user_name := wf_engine.GetItemAttrText (
9713 itemtype => p_item_type,
9714 itemkey => p_item_key,
9715 aname => 'CATALOG_ADMIN_USER_NAME');
9716
9717 l_progress := '130';
9718 IF (g_po_wf_debug = 'Y') THEN
9719 PO_WF_DEBUG_PKG.insert_debug(p_item_type,p_item_key,'Item Attribute value for CATALOG_ADMIN_USER_NAME='|| l_cat_admin_user_name);
9720 END IF;
9721
9722 IF l_cat_admin_user_name is not null THEN
9723 l_progress := '150';
9724 x_result_out := wf_engine.eng_completed || ':' || 'Y' ;
9725 ELSE
9726 l_progress := '190';
9727 x_result_out := wf_engine.eng_completed || ':' || 'N' ;
9728 END IF;
9729 l_progress := '200';
9730
9731 EXCEPTION
9732 WHEN OTHERS THEN
9733 wf_core.context('PO_REQAPPROVAL_INIT1','should_notify_cat_admin',l_progress||' DocumentId='||to_char(l_doc_id));
9734 raise;
9735
9736 END should_notify_cat_admin;
9737
9738
9739 -------------------------------------------------------------------------------
9740 --Start of Comments : R12 Online authoring Notifications
9741 --Name: should_notify_cat_admin
9742 --Pre-reqs:
9743 -- None.
9744 --Modifies:
9745 -- None.
9746 --Locks:
9747 -- None.
9748 --Function:
9749 -- If this is an agreement that has been locked by the catalog admin (change
9750 -- initiator, then set the item attribute CATALOG_ADMIN_USER_NAME so that
9751 -- the catalog admin can be notified later in the workflow process.
9752 -- The reason why we are setting the attribute here instead of checking later
9753 -- in the wf process is because, the lock_owner_role/lock_owner_id will be
9754 -- cleared from po_headers_all later. So first capture the item attribute
9755 -- use it later in the workflow to decide whether a notification has to be
9756 -- sent. See Node "SHOULD_NOTIFY_CAT_ADMIN" function in the PO Approval and
9757 -- PO Approval Top Process(Also see function should_notify_cat_admin() in
9758 -- this file).
9759 --Parameters:
9760 --IN:
9761 --p_item_type
9762 -- WF item type
9763 --p_item_key
9764 -- WF Item key
9765 --p_doc_id
9766 -- Document Id(PO Header Id)
9767 --p_doc_type
9768 -- Document type (PO/PA)
9769 --Testing:
9770 -- None.
9771 --End of Comments
9772 -------------------------------------------------------------------------------
9773 PROCEDURE set_catalog_admin_user_name(p_item_type in varchar2,
9774 p_item_key in varchar2,
9775 p_doc_id in number,
9776 p_doc_type in varchar2) is
9777 l_progress varchar2(255);
9778 l_user_name FND_USER.USER_NAME%type;
9779 l_lock_owner_role PO_HEADERS_ALL.lock_owner_role%type;
9780 l_lock_owner_user_id PO_HEADERS_ALL.lock_owner_user_id%type;
9781 BEGIN
9782 l_progress := 'PO_REQAPPROVAL_INIT1.set_catalog_admin_user_name: 100' ||
9783 'Document Id='|| to_char(p_doc_id) ||
9784 'Document Type='|| p_doc_type;
9785 IF (g_po_wf_debug = 'Y') THEN
9786 PO_WF_DEBUG_PKG.insert_debug(p_item_type,p_item_key,l_progress);
9787 END IF;
9788
9789 l_progress := 'PO_REQAPPROVAL_INIT1.set_catalog_admin_user_name: 110';
9790 -- Proceed only if this is an agreement
9791 IF (g_po_wf_debug = 'Y') THEN
9792 PO_WF_DEBUG_PKG.insert_debug(p_item_type,p_item_key,l_progress);
9793 END IF;
9794
9795 IF p_doc_type = 'PA' THEN
9796 -- Get the locking user role and user id information
9797 select lock_owner_user_id, lock_owner_role
9798 into l_lock_owner_user_id, l_lock_owner_role
9799 from po_headers_all
9800 where po_header_id = p_doc_id;
9801
9802 l_progress := 'PO_REQAPPROVAL_INIT1.set_catalog_admin_user_name: 140' ||
9803 'l_lock_owner_user_id ='|| to_char(l_lock_owner_user_id) ||
9804 'l_lock_owner_role Type='|| l_lock_owner_role;
9805
9806 IF (g_po_wf_debug = 'Y') THEN
9807 PO_WF_DEBUG_PKG.insert_debug(p_item_type,p_item_key,l_progress);
9808 END IF;
9809
9810 IF l_lock_owner_role = 'CAT ADMIN' THEN
9811 l_progress := 'PO_REQAPPROVAL_INIT1.set_catalog_admin_user_name: 150';
9812
9813 -- The performer attribute holds the user name, get the user name
9814 -- associated with the user id
9815 select user_name into l_user_name
9816 from fnd_user
9817 where user_id = l_lock_owner_user_id;
9818
9819 l_progress := 'PO_REQAPPROVAL_INIT1.set_catalog_admin_user_name: 155' ||
9820 'UserName='|| l_user_name;
9821 IF (g_po_wf_debug = 'Y') THEN
9822 PO_WF_DEBUG_PKG.insert_debug(p_item_type,p_item_key,l_progress);
9823 END IF;
9824
9825 l_progress := 'PO_REQAPPROVAL_INIT1.set_catalog_admin_user_name: 160';
9826 -- Set the item attribute tied to the performer of the
9827 -- approval notification
9828 wf_engine.SetItemAttrText ( itemtype => p_item_type ,
9829 itemkey => p_item_key ,
9830 aname => 'CATALOG_ADMIN_USER_NAME',
9831 avalue => l_user_name);
9832 l_progress := 'PO_REQAPPROVAL_INIT1.set_catalog_admin_user_name: 170';
9833 END IF; -- End of check for "CAT ADMIN"
9834 END IF; -- End of Check for "PA" (Agreement check)
9835 l_progress := '200';
9836
9837 EXCEPTION
9838 WHEN OTHERS THEN
9839 wf_core.context('PO_REQAPPROVAL_INIT1','set_catalog_admin_user_name',l_progress||' DocumentId='||to_char(p_doc_id));
9840 raise;
9841
9842 END set_catalog_admin_user_name;
9843
9844 -------------------------------------------------------------------------------
9845 --Start of Comments : HTML Orders R12
9846 --Name: get_po_url
9847 --Pre-reqs:
9848 -- None.
9849 --Modifies:
9850 -- None.
9851 --Locks:
9852 -- None.
9853 --Function:
9854 -- Constructs the PO view/Update page URLs based on the document
9855 -- type and mode
9856 --Parameters:
9857 --IN:
9858 --p_po_header_id
9859 -- Document Id
9860 --p_doc_subtype
9861 -- Document subtype
9862 --p_mode
9863 -- ViewOnly or Update mode
9864 --Testing:
9865 -- None.
9866 --End of Comments
9867 -------------------------------------------------------------------------------
9868 Function get_po_url (p_po_header_id IN NUMBER,
9869 p_doc_subtype IN VARCHAR2,
9870 p_mode IN VARCHAR2)
9871 Return VARCHAR2 IS
9872
9873 l_url varchar2(1000);
9874 l_page_function varchar2(25);
9875
9876 BEGIN
9877
9878 IF p_doc_subtype = 'STANDARD' THEN
9879 l_page_function := 'PO_ORDER';
9880 ELSIF p_doc_subtype = 'BLANKET' THEN
9881 l_page_function := 'PO_BLANKET';
9882 ELSIF p_doc_subtype = 'CONTRACT' THEN
9883 l_page_function := 'PO_CONTRACT';
9884 END IF;
9885
9886 IF p_mode = 'viewOnly' THEN
9887
9888 /* Bug 7307832
9889 Added JSP:/OA_HTML/ before OA.jsp?OAFunc= */
9890 l_url := 'JSP:/OA_HTML/OA.jsp?OAFunc=' || l_page_function || '&' ||
9891 'poHeaderId=' || p_po_header_id || '&' ||
9892 'poMode=' || p_mode || '&' ||
9893 'poCallingModule=notification'|| '&' ||
9894 'poHideUpdate=Y'|| '&' ||
9895 'poCallingNotifId=-NID-'|| '&' ||
9896 'retainAM=Y' || '&' || 'addBreadCrumb=Y' ;
9897
9898 ELSE
9899 /* Bug 7307832
9900 Added JSP:/OA_HTML/ before OA.jsp?OAFunc= */
9901 l_url := 'JSP:/OA_HTML/OA.jsp?OAFunc=' || l_page_function || '&' ||
9902 'poHeaderId=' || p_po_header_id || '&' ||
9903 'poMode=' || p_mode || '&' ||
9904 'poCallingModule=notification'|| '&' ||
9905 'poCallingNotifId=-NID-'|| '&' ||
9906 'retainAM=Y' || '&' || 'addBreadCrumb=Y' ;
9907
9908 END IF;
9909
9910 Return l_url;
9911
9912 END;
9913
9914
9915 -- <HTML Agreement R12 START>
9916
9917 -------------------------------------------------------------------------------
9918 --Start of Comments
9919 --Name: unlock_document
9920 --Function:
9921 -- Clear Lock owner information autonomously
9922 --Parameters:
9923 --IN:
9924 --p_po_header_id
9925 -- Document Id
9926 --End of Comments
9927 -------------------------------------------------------------------------------
9928 PROCEDURE unlock_document
9929 ( p_po_header_id IN NUMBER
9930 ) IS
9931 PRAGMA AUTONOMOUS_TRANSACTION;
9932
9933 BEGIN
9934
9935 PO_DRAFTS_PVT.unlock_document
9936 ( p_po_header_id => p_po_header_id
9937 );
9938
9939 COMMIT;
9940 END unlock_document;
9941 -- <HTML Agreement R12 END>
9942
9943 -- <Bug 5059002 Begin>
9944
9945 /**
9946 * Public Procedure: set_is_supplier_context_y
9947 * Sets the workflow attribute IS_SUPPLIER_CONTEXT to Y to let
9948 * the POREQ_SELECTOR know we should be in the supplier's context
9949 * and not reset to the buyer's context
9950 * Requires:
9951 * IN PARAMETERS:
9952 * Usual workflow attributes.
9953 * Modifies: Sets the workflow attribute IS_SUPPLIER_CONTEXT to Y
9954 */
9955
9956 -- Commenting this code. Most likely will not be required with our context Setting fix.
9957 /* procedure set_is_supplier_context_y(p_item_type in varchar2,
9958 p_item_key in varchar2,
9959 p_act_id in number,
9960 p_func_mode in varchar2,
9961 x_result_out out NOCOPY varchar2) is
9962 l_progress VARCHAR2(300);
9963 begin
9964 l_progress := 'PO_REQAPPROVAL_INIT1.set_is_supplier_context_y: ';
9965 IF (g_po_wf_debug = 'Y') THEN
9966 PO_WF_DEBUG_PKG.insert_debug(p_item_type, p_item_key, l_progress || 'Begin');
9967 END IF;
9968
9969 PO_WF_UTIL_PKG.SetItemAttrText(itemtype => p_item_type,
9970 itemkey => p_item_key,
9971 aname => 'IS_SUPPLIER_CONTEXT',
9972 avalue => 'Y');
9973
9974 IF (g_po_wf_debug = 'Y') THEN
9975 PO_WF_DEBUG_PKG.insert_debug(p_item_type, p_item_key, l_progress || 'End');
9976 END IF;
9977
9978 EXCEPTION
9979 WHEN OTHERS THEN
9980 IF (g_po_wf_debug = 'Y') THEN
9981 PO_WF_DEBUG_PKG.insert_debug(p_item_type, p_item_key, l_progress || 'Unexpected error');
9982 END IF;
9983 RAISE;
9984 end set_is_supplier_context_y; */
9985
9986 /**
9987 * Public Procedure: set_is_supplier_context_n
9988 * Sets the workflow attribute IS_SUPPLIER_CONTEXT to N to let
9989 * the POREQ_SELECTOR know we are no longer in the suppliers
9990 * context.
9991 * Requires:
9992 * IN PARAMETERS:
9993 * Usual workflow attributes.
9994 * Modifies: Sets the workflow attribute IS_SUPPLIER_CONTEXT to N
9995 */
9996 /* procedure set_is_supplier_context_n(p_item_type in varchar2,
9997 p_item_key in varchar2,
9998 p_act_id in number,
9999 p_func_mode in varchar2,
10000 x_result_out out NOCOPY varchar2) is
10001
10002 l_progress VARCHAR2(300);
10003 begin
10004
10005 l_progress := 'PO_REQAPPROVAL_INIT1.set_is_supplier_context_n: ';
10006 IF (g_po_wf_debug = 'Y') THEN
10007 PO_WF_DEBUG_PKG.insert_debug(p_item_type, p_item_key, l_progress || 'Begin');
10008 END IF;
10009
10010 -- Set the IS_SUPPLIER_CONTEXT value to 'N'
10011 PO_WF_UTIL_PKG.SetItemAttrText(itemtype => p_item_type,
10012 itemkey => p_item_key,
10013 aname => 'IS_SUPPLIER_CONTEXT',
10014 avalue => 'N');
10015
10016 IF (g_po_wf_debug = 'Y') THEN
10017 PO_WF_DEBUG_PKG.insert_debug(p_item_type, p_item_key, l_progress || 'End');
10018 END IF;
10019
10020 EXCEPTION
10021 WHEN OTHERS THEN
10022 IF (g_po_wf_debug = 'Y') THEN
10023 PO_WF_DEBUG_PKG.insert_debug(p_item_type, p_item_key, l_progress || 'Unexpected error');
10024 END IF;
10025 RAISE;
10026 end set_is_supplier_context_n; */
10027 -- <Bug 5059002 End>
10028
10029 -- <Bug 4950854 Begin>
10030 -- added the following proc to update the print count
10031 PROCEDURE update_print_count( p_doc_id NUMBER,
10032 p_doc_type VARCHAR2 )
10033 IS PRAGMA AUTONOMOUS_TRANSACTION;
10034 BEGIN
10035
10036 IF (p_doc_type = 'RELEASE') THEN
10037
10038 UPDATE po_releases_all pr
10039 SET pr.printed_date = sysdate, pr.print_count = nvl(pr.print_count,0) + 1
10040 WHERE pr.po_release_id = p_doc_id ;
10041
10042 ELSIF (p_doc_type in ('PO','PA')) THEN
10043
10044 UPDATE po_headers_all ph
10045 SET ph.printed_date = sysdate, ph.print_count = nvl(ph.print_count,0) + 1
10046 WHERE ph.po_header_id = p_doc_id ;
10047 END IF;
10048 COMMIT;
10049 END;
10050 -- <Bug 4950854 End>
10051
10052 -- <BUG 5691965 START>
10053 /*
10054 ** Public Procedure: Update_Action_History_TimeOut
10055 ** Requires:
10056 ** IN PARAMETERS:
10057 ** Usual workflow attributes.
10058 ** Modifies: Action History
10059 ** Effects: Actoin History is updated with No Action if the approval
10060 ** notification is TimedOut.
10061 */
10062
10063 PROCEDURE Update_Action_History_Timeout (Itemtype IN VARCHAR2,
10064 Itemkey IN VARCHAR2,
10065 Actid IN NUMBER,
10066 Funcmode IN VARCHAR2,
10067 Resultout OUT NOCOPY VARCHAR2) IS
10068
10069 L_Doc_Id NUMBER;
10070 L_Doc_Type Po_Action_History.Object_Type_Code%TYPE;
10071 L_Doc_Subtype Po_Action_History.Object_Sub_Type_Code%TYPE;
10072
10073 BEGIN
10074
10075 L_Doc_Type := Wf_Engine.Getitemattrtext (Itemtype => Itemtype,
10076 Itemkey => Itemkey,
10077 Aname => 'DOCUMENT_TYPE');
10078
10079 L_Doc_Subtype := Wf_Engine.Getitemattrtext(Itemtype => Itemtype,
10080 Itemkey => Itemkey,
10081 Aname => 'DOCUMENT_SUBTYPE');
10082
10083 L_Doc_Id := Wf_Engine.Getitemattrnumber (Itemtype => Itemtype,
10084 Itemkey => Itemkey,
10085 Aname => 'DOCUMENT_ID');
10086
10087 UpdateActionHistory ( p_doc_id => L_Doc_Id,
10088 p_doc_type => L_Doc_Type,
10089 p_doc_subtype => L_Doc_Subtype,
10090 p_action => 'NO ACTION'
10091 );
10092
10093 END Update_Action_History_Timeout;
10094 -- <BUG 5691965 END>
10095
10096 -- <Bug 6144768 Begin>
10097 -- When Supplier responds from iSP then the responder should show
10098 -- as supplier and also supplier acknowledgement notifications
10099 -- should be available in the To-Do Notification full list.
10100
10101
10102 /**
10103 * Public Procedure: set_is_supplier_context_y
10104 * Sets the workflow attribute IS_SUPPLIER_CONTEXT to Y to let
10105 * the POREQ_SELECTOR know we should be in the supplier's context
10106 * and not reset to the buyer's context
10107 * Requires:
10108 * IN PARAMETERS:
10109 * Usual workflow attributes.
10110 * Modifies: Sets the workflow attribute IS_SUPPLIER_CONTEXT to Y
10111 */
10112 procedure set_is_supplier_context_y(p_item_type in varchar2,
10113 p_item_key in varchar2,
10114 p_act_id in number,
10115 p_func_mode in varchar2,
10116 x_result_out out NOCOPY varchar2) is
10117 l_progress VARCHAR2(300);
10118 begin
10119 l_progress := 'PO_REQAPPROVAL_INIT1.set_is_supplier_context_y: ';
10120 IF (g_po_wf_debug = 'Y') THEN
10121 PO_WF_DEBUG_PKG.insert_debug(p_item_type, p_item_key, l_progress || 'Begin');
10122 END IF;
10123
10124 PO_WF_UTIL_PKG.SetItemAttrText(itemtype => p_item_type,
10125 itemkey => p_item_key,
10126 aname => 'IS_SUPPLIER_CONTEXT',
10127 avalue => 'Y');
10128
10129 IF (g_po_wf_debug = 'Y') THEN
10130 PO_WF_DEBUG_PKG.insert_debug(p_item_type, p_item_key, l_progress || 'End');
10131 END IF;
10132
10133 EXCEPTION
10134 WHEN OTHERS THEN
10135 IF (g_po_wf_debug = 'Y') THEN
10136 PO_WF_DEBUG_PKG.insert_debug(p_item_type, p_item_key, l_progress || 'Unexpected error');
10137 END IF;
10138 RAISE;
10139 end set_is_supplier_context_y;
10140
10141 /**
10142 * Public Procedure: set_is_supplier_context_n
10143 * Sets the workflow attribute IS_SUPPLIER_CONTEXT to N to let
10144 * the POREQ_SELECTOR know we are no longer in the suppliers
10145 * context.
10146 * Requires:
10147 * IN PARAMETERS:
10148 * Usual workflow attributes.
10149 * Modifies: Sets the workflow attribute IS_SUPPLIER_CONTEXT to N
10150 */
10151 procedure set_is_supplier_context_n(p_item_type in varchar2,
10152 p_item_key in varchar2,
10153 p_act_id in number,
10154 p_func_mode in varchar2,
10155 x_result_out out NOCOPY varchar2) is
10156
10157 l_progress VARCHAR2(300);
10158 begin
10159
10160 l_progress := 'PO_REQAPPROVAL_INIT1.set_is_supplier_context_n: ';
10161 IF (g_po_wf_debug = 'Y') THEN
10162 PO_WF_DEBUG_PKG.insert_debug(p_item_type, p_item_key, l_progress || 'Begin');
10163 END IF;
10164
10165 -- Set the IS_SUPPLIER_CONTEXT value to 'N'
10166 PO_WF_UTIL_PKG.SetItemAttrText(itemtype => p_item_type,
10167 itemkey => p_item_key,
10168 aname => 'IS_SUPPLIER_CONTEXT',
10169 avalue => 'N');
10170
10171 IF (g_po_wf_debug = 'Y') THEN
10172 PO_WF_DEBUG_PKG.insert_debug(p_item_type, p_item_key, l_progress || 'End');
10173 END IF;
10174
10175 EXCEPTION
10176 WHEN OTHERS THEN
10177 IF (g_po_wf_debug = 'Y') THEN
10178 PO_WF_DEBUG_PKG.insert_debug(p_item_type, p_item_key, l_progress || 'Unexpected error');
10179 END IF;
10180 RAISE;
10181 end set_is_supplier_context_n;
10182 -- <Bug 6144768 End>
10183
10184 end PO_REQAPPROVAL_INIT1;