DBA Data[Home] [Help]

PACKAGE BODY: APPS.PO_CHORD_WF1

Source


1 PACKAGE BODY PO_CHORD_WF1 AS
2 /* $Header: POXWCO1B.pls 120.6 2008/02/21 22:03:00 jburugul 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 
7 PROCEDURE chord_hd(itemtype IN VARCHAR2,
8 		   itemkey  IN VARCHAR2,
9 		   actid    IN NUMBER,
10 		   funcmode IN VARCHAR2,
11 		   result   OUT NOCOPY VARCHAR2)
12 IS
13 	x_header_control	t_header_control_type;
14 	x_header_parameters	t_header_parameters_type;
15         l_org_id                PO_HEADERS_ALL.org_id%TYPE; --<BUG 3254056>
16 
17 BEGIN
18 	IF (g_po_wf_debug = 'Y') THEN
19    	PO_WF_DEBUG_PKG.INSERT_DEBUG(ITEMTYPE, ITEMKEY,
20    		'*** In Procedure: chord_hd ***' );
21 	END IF;
22 
23 	IF funcmode <> 'RUN' THEN
24 		result := 'COMPLETE';
25 		return;
26 	END IF;
27 
28         /* Bug# 2353153
29         ** Setting application context
30         */
31 
32         -- Context Setting revamp
33         -- PO_REQAPPROVAL_INIT1.Set_doc_mgr_context(itemtype, itemkey);
34 
35         --<BUG 3254056 START>
36         l_org_id := PO_WF_UTIL_PKG.GetItemAttrNumber (itemtype => itemtype,
37                                                       itemkey  => itemkey,
38                                                       aname    => 'ORG_ID');
39 
40         IF l_org_id IS NOT NULL THEN
41            PO_MOAC_UTILS_PVT.set_org_context(l_org_id) ;         -- <R12 MOAC>
42         END IF;
43         --<BUG 3254056 END>
44 
45 	get_wf_header_parameters(itemtype, itemkey, x_header_parameters);
46 
47 	check_header_change(itemtype, itemkey, x_header_parameters, x_header_control);
48 
49 	set_wf_header_control(itemtype, itemkey, x_header_control);
50 
51 	IF (g_po_wf_debug = 'Y') THEN
52    	PO_WF_DEBUG_PKG.INSERT_DEBUG(ITEMTYPE, ITEMKEY,
53    		'*** Finish: chord_hd ***' );
54 	END IF;
55 
56 	result := wf_engine.eng_completed || ':' ||  'ACTIVITY_PERFORMED';
57 	return;
58 
59 EXCEPTION
60 
61  WHEN OTHERS THEN
62   wf_core.context('POAPPRV', 'po_chord_wf1.chord_hd', 'others');
63   RAISE;
64 
65 END;
66 
67 PROCEDURE check_header_change(itemtype	IN 	VARCHAR2,
68 			      itemkey	IN	VARCHAR2,
69 			      x_header_parameters IN t_header_parameters_type,
70 			      x_header_control IN OUT NOCOPY t_header_control_type)
71 IS
72 	x_po_header_id			NUMBER;
73         l_document_type 		PO_DOCUMENT_TYPES_ALL.DOCUMENT_TYPE_CODE%TYPE;
74         l_document_subtype 		PO_DOCUMENT_TYPES_ALL.DOCUMENT_SUBTYPE%TYPE;
75 
76 BEGIN
77 	IF (g_po_wf_debug = 'Y') THEN
78    	PO_WF_DEBUG_PKG.INSERT_DEBUG(ITEMTYPE, ITEMKEY,
79    		'*** In Procedure check_header_change ***');
80 	END IF;
81 
82 		/* To use change order,
83 		 * System should have Archive on Approval set
84 		 */
85 
86 		/* initialize */
87 
88 		x_header_control.agent_id       		:= 'N';
89 		x_header_control.vendor_site_id			:= 'N';
90 		x_header_control.ship_to_location_id     	:= 'N';
91 		x_header_control.bill_to_location_id     	:= 'N';
92 		x_header_control.terms_id       		:= 'N';
93 		x_header_control.ship_via_lookup_code    	:= 'N';
94 		x_header_control.fob_lookup_code       		:= 'N';
95 		x_header_control.freight_terms_lookup_code	:= 'N';
96 		x_header_control.note_to_vendor      		:= 'N';
97 		x_header_control.confirming_order_flag	      	:= 'N';
98 		x_header_control.acceptance_required_flag       := 'N';
99 		x_header_control.acceptance_due_date        	:= 'N';
100 		x_header_control.start_date		       	:= 'N';
101 		x_header_control.end_date		       	:= 'N';
102 		x_header_control.cancel_flag		       	:= 'N';
103 
104 	        /* Percentage Change */
105 		x_header_control.blanket_total_change		:=0;
106 		x_header_control.amount_limit_change		:=0;
107 		x_header_control.po_total_change		:=0;
108 
109 		/* po_acceptance Table */
110 		x_header_control.po_acknowledged	:='N';
111 		x_header_control.po_accepted		:='N';
112 
113 /* Added following for Bug 6616522 */
114                 x_header_control.amount_limit      := 'N';
115 
116 		x_po_header_id	  := x_header_parameters.po_header_id;
117 
118    /* Each of the following select statement maps to one attribute.
119     * It is written like this for clarity.  Since each statemet consists
120     * of one index access and one range scan, performance should not
121     * suffer too much.
122     * However, they can be combined into one sql statement
123     * for slight performance gain.
124     */
125 
126    BEGIN
127                 -- SQL What: Select 'Y' if agent id is changed
128                 -- SQL Why: Need the value for routing to reapproval
129                 --          if there is a change
130                 -- SQL Join: po_header_id, agent_id
131                 SELECT DISTINCT 'Y'
132                 INTO  x_header_control.agent_id
133                 FROM   PO_HEADERS_all POH,
134                 PO_HEADERS_ARCHIVE_all POHA
135                 WHERE  POH.po_header_id = x_po_header_id
136                 AND    POH.po_header_id = POHA.po_header_id (+)
137                 AND    POHA.latest_external_flag (+) = 'Y'
138                 AND   (
139                       ( POHA.po_header_id IS NULL)
140                 OR (POH.agent_id <> POHA.agent_id));
141    EXCEPTION
142 	WHEN NO_DATA_FOUND THEN
143 		x_header_control.agent_id :='N';
144    END;
145 
146    BEGIN
147                 -- SQL What: Select 'Y' if vendor site id is changed
148                 -- SQL Why: Need the value for routing to reapproval
149                 --          if there is a change
150                 -- SQL Join: po_header_id, vendor_site_id
151                 SELECT DISTINCT 'Y'
152                 INTO  x_header_control.vendor_site_id
153                 FROM   PO_HEADERS_all POH,
154                 PO_HEADERS_ARCHIVE_all POHA
155                 WHERE  POH.po_header_id = x_po_header_id
156                 AND    POH.po_header_id = POHA.po_header_id (+)
157                 AND    POHA.latest_external_flag (+) = 'Y'
158                 AND   (
159                       ( POHA.po_header_id IS NULL)
160                 OR (POH.vendor_site_id <> POHA.vendor_site_id)
161                 OR (POH.vendor_site_id IS NULL
162                          AND POHA.vendor_site_id IS NOT NULL)
163                 OR (POH.vendor_site_id IS NOT NULL
164                          AND POHA.vendor_site_id IS NULL)
165 		);
166    EXCEPTION
167 	WHEN NO_DATA_FOUND THEN
168 		x_header_control.vendor_site_id :='N';
169    END;
170 
171    BEGIN
172                 -- SQL What: Select 'Y' if vendor contact id is changed
173                 -- SQL Why: Need the value for routing to reapproval
174                 --          if there is a change
175                 -- SQL Join: po_header_id, vendor_contact_id
176                 SELECT DISTINCT 'Y'
177                 INTO  x_header_control.vendor_contact_id
178                 FROM   PO_HEADERS_all POH,
179                 PO_HEADERS_ARCHIVE_all POHA
180                 WHERE  POH.po_header_id = x_po_header_id
181                 AND    POH.po_header_id = POHA.po_header_id (+)
182                 AND    POHA.latest_external_flag (+) = 'Y'
183                 AND   (
184                       ( POHA.po_header_id IS NULL)
185                 OR (POH.vendor_contact_id <> POHA.vendor_contact_id)
186                 OR (POH.vendor_contact_id IS NULL
187                          AND POHA.vendor_contact_id IS NOT NULL)
188                 OR (POH.vendor_contact_id IS NOT NULL
189                          AND POHA.vendor_contact_id IS NULL)
190 		);
191    EXCEPTION
192 	WHEN NO_DATA_FOUND THEN
193 		x_header_control.vendor_contact_id :='N';
194    END;
195 
196    BEGIN
197                 -- SQL What: Select 'Y' if Ship to location is changed
198                 -- SQL Why: Need the value for routing to reapproval
199                 --          if there is a change
200                 -- SQL Join: po_header_id, ship_to_location_id
201                 SELECT DISTINCT 'Y'
202                 INTO  x_header_control.ship_to_location_id
203                 FROM   PO_HEADERS_all POH,
204                 PO_HEADERS_ARCHIVE_all POHA
205                 WHERE  POH.po_header_id = x_po_header_id
206                 AND    POH.po_header_id = POHA.po_header_id (+)
207                 AND    POHA.latest_external_flag (+) = 'Y'
208                 AND   (
209                       ( POHA.po_header_id IS NULL)
210                 OR (POH.ship_to_location_id <> POHA.ship_to_location_id)
211                 OR (POH.ship_to_location_id IS NULL
212                          AND POHA.ship_to_location_id IS NOT NULL)
213                 OR (POH.ship_to_location_id IS NOT NULL
214                          AND POHA.ship_to_location_id IS NULL)
215 		);
216    EXCEPTION
217 	WHEN NO_DATA_FOUND THEN
218 		x_header_control.ship_to_location_id :='N';
219    END;
220 
221    BEGIN
222                 -- SQL What: Select 'Y' if bill to location is changed
223                 -- SQL Why: Need the value for routing to reapproval
224                 --          if there is a change
225                 -- SQL Join: po_header_id, bill_to_location_id
226                 SELECT DISTINCT 'Y'
227                 INTO  x_header_control.bill_to_location_id
228                 FROM   PO_HEADERS_all POH,
229                 PO_HEADERS_ARCHIVE_all POHA
230                 WHERE  POH.po_header_id = x_po_header_id
231                 AND    POH.po_header_id = POHA.po_header_id (+)
232                 AND    POHA.latest_external_flag (+) = 'Y'
233                 AND   (
234                       ( POHA.po_header_id IS NULL)
235                 OR (POH.bill_to_location_id <> POHA.bill_to_location_id)
236                 OR (POH.bill_to_location_id IS NULL
237                          AND POHA.bill_to_location_id IS NOT NULL)
238                 OR (POH.bill_to_location_id IS NOT NULL
239                          AND POHA.bill_to_location_id IS NULL)
240 		);
241    EXCEPTION
242 	WHEN NO_DATA_FOUND THEN
243 		x_header_control.bill_to_location_id :='N';
244    END;
245 
246 
247    BEGIN
248                -- SQL What: Select 'Y' if terms id is changed
249                -- SQL Why: Need the value for routing to reapproval
250                --          if there is a change
251                -- SQL Join: po_header_id, terms_id
252                SELECT DISTINCT 'Y'
253                 INTO  x_header_control.terms_id
254                 FROM   PO_HEADERS_all POH,
255                 PO_HEADERS_ARCHIVE_all POHA
256                 WHERE  POH.po_header_id = x_po_header_id
257                 AND    POH.po_header_id = POHA.po_header_id (+)
258                 AND    POHA.latest_external_flag (+) = 'Y'
259                 AND   (
260                       ( POHA.po_header_id IS NULL)
261                 OR (POH.terms_id <> POHA.terms_id)
262                 OR (POH.terms_id IS NULL
263                          AND POHA.terms_id IS NOT NULL)
264                 OR (POH.terms_id IS NOT NULL
265                          AND POHA.terms_id IS NULL)
266 		);
267    EXCEPTION
268 	WHEN NO_DATA_FOUND THEN
269 		x_header_control.terms_id :='N';
270    END;
271 
272 
273    BEGIN
274                 -- SQL What: Select 'Y' if ship lookup code is changed
275                 -- SQL Why: Need the value for routing to reapproval
276                 --          if there is a change
277                 -- SQL Join: po_header_id, ship_via_lookup_code
278                 SELECT DISTINCT 'Y'
279                 INTO  x_header_control.ship_via_lookup_code
280                 FROM   PO_HEADERS_all POH,
281                 PO_HEADERS_ARCHIVE_all POHA
282                 WHERE  POH.po_header_id = x_po_header_id
283                 AND    POH.po_header_id = POHA.po_header_id (+)
284                 AND    POHA.latest_external_flag (+) = 'Y'
285                 AND   (
286                       ( POHA.po_header_id IS NULL)
287                 OR (POH.ship_via_lookup_code <> POHA.ship_via_lookup_code)
288                 OR (POH.ship_via_lookup_code IS NULL
289                          AND POHA.ship_via_lookup_code IS NOT NULL)
290                 OR (POH.ship_via_lookup_code IS NOT NULL
291                          AND POHA.ship_via_lookup_code IS NULL)
292 		);
293    EXCEPTION
294 	WHEN NO_DATA_FOUND THEN
295 		x_header_control.ship_via_lookup_code :='N';
296    END;
297 
298 
299    BEGIN
300                 -- SQL What: Select 'Y' if fob is changed
301                 -- SQL Why: Need the value for routing to reapproval
302                 --          if there is a change
303                 -- SQL Join: po_header_id, fob_lookup_code
304                 SELECT DISTINCT 'Y'
305                 INTO  x_header_control.fob_lookup_code
306                 FROM   PO_HEADERS_all POH,
307                 PO_HEADERS_ARCHIVE_all POHA
308                 WHERE  POH.po_header_id = x_po_header_id
309                 AND    POH.po_header_id = POHA.po_header_id (+)
310                 AND    POHA.latest_external_flag (+) = 'Y'
311                 AND   (
312                       ( POHA.po_header_id IS NULL)
313                 OR (POH.fob_lookup_code <> POHA.fob_lookup_code)
314                 OR (POH.fob_lookup_code IS NULL
315                          AND POHA.fob_lookup_code IS NOT NULL)
316                 OR (POH.fob_lookup_code IS NOT NULL
317                          AND POHA.fob_lookup_code IS NULL)
318 		);
319    EXCEPTION
320 	WHEN NO_DATA_FOUND THEN
321 		x_header_control.fob_lookup_code :='N';
322    END;
323 
324    BEGIN
325                 -- SQL What: Select 'Y' if frieght terms is changed
326                 -- SQL Why: Need the value for routing to reapproval
327                 --          if there is a change
328                 -- SQL Join: po_header_id, freight_terms_lookup_code
329                 SELECT DISTINCT 'Y'
330                 INTO  x_header_control.freight_terms_lookup_code
331                 FROM   PO_HEADERS_all POH,
332                 PO_HEADERS_ARCHIVE_all POHA
333                 WHERE  POH.po_header_id = x_po_header_id
334                 AND    POH.po_header_id = POHA.po_header_id (+)
335                 AND    POHA.latest_external_flag (+) = 'Y'
336                 AND   (
337                       ( POHA.po_header_id IS NULL)
338                 OR (POH.freight_terms_lookup_code <> POHA.freight_terms_lookup_code)
339                 OR (POH.freight_terms_lookup_code IS NULL
340                          AND POHA.freight_terms_lookup_code IS NOT NULL)
341                 OR (POH.freight_terms_lookup_code IS NOT NULL
342                          AND POHA.freight_terms_lookup_code IS NULL)
343 		);
344    EXCEPTION
345 	WHEN NO_DATA_FOUND THEN
346 		x_header_control.freight_terms_lookup_code :='N';
347    END;
348 
349 
350    BEGIN
351                 -- SQL What: Select 'Y' if note to vendor is changed
352                 -- SQL Why: Need the value for routing to reapproval
353                 --          if there is a change
354                 -- SQL Join: po_header_id, note_to_vendor
355                 SELECT DISTINCT 'Y'
356                 INTO  x_header_control.note_to_vendor
357                 FROM   PO_HEADERS_all POH,
358                 PO_HEADERS_ARCHIVE_all POHA
359                 WHERE  POH.po_header_id = x_po_header_id
360                 AND    POH.po_header_id = POHA.po_header_id (+)
361                 AND    POHA.latest_external_flag (+) = 'Y'
362                 AND   (
363                       ( POHA.po_header_id IS NULL)
364                 OR (POH.note_to_vendor <> POHA.note_to_vendor)
365                 OR (POH.note_to_vendor IS NULL
366                          AND POHA.note_to_vendor IS NOT NULL)
367                 OR (POH.note_to_vendor IS NOT NULL
368                          AND POHA.note_to_vendor IS NULL)
369 		);
370    EXCEPTION
371 	WHEN NO_DATA_FOUND THEN
372 		x_header_control.note_to_vendor :='N';
373    END;
374 
375 
376    BEGIN
377                 -- SQL What: Select 'Y' if confrim order flag is changed
378                 -- SQL Why: Need the value for routing to reapproval
379                 --          if there is a change
380                 -- SQL Join: po_header_id, confirming_order_flag
381                 SELECT DISTINCT 'Y'
382                 INTO  x_header_control.confirming_order_flag
383                 FROM   PO_HEADERS_all POH,
384                 PO_HEADERS_ARCHIVE_all POHA
385                 WHERE  POH.po_header_id = x_po_header_id
386                 AND    POH.po_header_id = POHA.po_header_id (+)
387                 AND    POHA.latest_external_flag (+) = 'Y'
388                 AND   (
389                       ( POHA.po_header_id IS NULL)
390                 OR (POH.confirming_order_flag <> POHA.confirming_order_flag)
391                 OR (POH.confirming_order_flag IS NULL
392                          AND POHA.confirming_order_flag IS NOT NULL)
393                 OR (POH.confirming_order_flag IS NOT NULL
394                          AND POHA.confirming_order_flag IS NULL)
395 		);
396    EXCEPTION
397 	WHEN NO_DATA_FOUND THEN
398 		x_header_control.confirming_order_flag :='N';
399    END;
400 
401    BEGIN
402                 -- SQL What: Select 'Y' if acceptance req flag is changed
403                 -- SQL Why: Need the value for routing to reapproval
404                 --          if there is a change
405                 -- SQL Join: po_header_id, acceptance_required_flag
406                 SELECT DISTINCT 'Y'
407                 INTO  x_header_control.acceptance_required_flag
408                 FROM   PO_HEADERS_all POH,
409                 PO_HEADERS_ARCHIVE_all POHA
410                 WHERE  POH.po_header_id = x_po_header_id
411                 AND    POH.po_header_id = POHA.po_header_id (+)
412                 AND    POHA.latest_external_flag (+) = 'Y'
413                 AND   (
414                       ( POHA.po_header_id IS NULL)
415                 OR (POH.acceptance_required_flag <> POHA.acceptance_required_flag)
416                 OR (POH.acceptance_required_flag IS NULL
417                          AND POHA.acceptance_required_flag IS NOT NULL)
418                 OR (POH.acceptance_required_flag IS NOT NULL
419                          AND POHA.acceptance_required_flag IS NULL)
420 		);
421    EXCEPTION
422 	WHEN NO_DATA_FOUND THEN
423 		x_header_control.acceptance_required_flag :='N';
424    END;
425 
426    BEGIN
427                 -- SQL What: Select 'Y' if acceptance due date is changed
428                 -- SQL Why: Need the value for routing to reapproval
429                 --          if there is a change
430                 -- SQL Join: po_header_id, acceptance_due_date
431                 SELECT DISTINCT 'Y'
432                 INTO  x_header_control.acceptance_due_date
433                 FROM   PO_HEADERS_all POH,
434                 PO_HEADERS_ARCHIVE_all POHA
435                 WHERE  POH.po_header_id = x_po_header_id
436                 AND    POH.po_header_id = POHA.po_header_id (+)
437                 AND    POHA.latest_external_flag (+) = 'Y'
438                 AND   (
439                       ( POHA.po_header_id IS NULL)
440                 OR (POH.acceptance_due_date <> POHA.acceptance_due_date)
441                 OR (POH.acceptance_due_date IS NULL
442                          AND POHA.acceptance_due_date IS NOT NULL)
443                 OR (POH.acceptance_due_date IS NOT NULL
444                          AND POHA.acceptance_due_date IS NULL)
445 		);
446    EXCEPTION
447 	WHEN NO_DATA_FOUND THEN
448 		x_header_control.acceptance_due_date :='N';
449    END;
450 
451    BEGIN
452         -- SQL What: Select Y if start date changed
453         -- SQL Why: Need the value in tolerance check (i.e reapproval
454         --          rule validations)
455         -- SQL Join: po_header_id
456 	SELECT DISTINCT 'Y'
457 	INTO  x_header_control.start_date
458 	FROM   PO_HEADERS_all POH,
459 		PO_HEADERS_ARCHIVE_all POHA
460 	WHERE  POH.po_header_id = x_po_header_id
461 	AND    POH.po_header_id = POHA.po_header_id (+)
462 	AND    POHA.latest_external_flag (+) = 'Y'
463         AND   (
464                       ( POHA.po_header_id IS NULL)
465                 OR (POH.start_date <> POHA.start_date)
466                 OR (POH.start_date IS NULL
467                          AND POHA.start_date IS NOT NULL)
468                 OR (POH.start_date IS NOT NULL
469                          AND POHA.start_date IS NULL)
470 		);
471 
472    EXCEPTION
473      WHEN NO_DATA_FOUND THEN
474 	x_header_control.start_date :='N';
475    END;
476 
477    BEGIN
478         -- SQL What: Select Y if start date changed
479         -- SQL Why: Need the value in tolerance check (i.e reapproval
480         --          rule validations)
481         -- SQL Join: po_header_id
482 	SELECT DISTINCT 'Y'
483 	INTO  x_header_control.end_date
484 	FROM   PO_HEADERS_all POH,
485 	       PO_HEADERS_ARCHIVE_all POHA
486 	WHERE  POH.po_header_id = x_po_header_id
487 	AND    POH.po_header_id = POHA.po_header_id (+)
488 	AND    POHA.latest_external_flag (+) = 'Y'
489         AND   (
490                       ( POHA.po_header_id IS NULL)
491                 OR (POH.end_date <> POHA.end_date)
492                 OR (POH.end_date IS NULL
493                          AND POHA.end_date IS NOT NULL)
494                 OR (POH.end_date IS NOT NULL
495                          AND POHA.end_date IS NULL)
496 		);
497 
498    EXCEPTION
499      WHEN NO_DATA_FOUND THEN
500 	x_header_control.end_date :='N';
501    END;
502 
503    BEGIN
504                 -- SQL What: Select 'Y' if cancel flag is changed
505                 -- SQL Why: Need the value for routing to reapproval
506                 --          if there is a change
507                 -- SQL Join: po_header_id, cancel_flag
508                 SELECT DISTINCT 'Y'
509                 INTO  x_header_control.cancel_flag
510                 FROM   PO_HEADERS_all POH,
511                 PO_HEADERS_ARCHIVE_all POHA
512                 WHERE  POH.po_header_id = x_po_header_id
513                 AND    POH.po_header_id = POHA.po_header_id (+)
514                 AND    POHA.latest_external_flag (+) = 'Y'
515                 AND   (
516                       ( POHA.po_header_id IS NULL)
517                 OR (POH.cancel_flag <> POHA.cancel_flag)
518                 OR (POH.cancel_flag IS NULL
519                          AND POHA.cancel_flag IS NOT NULL)
520                 OR (POH.cancel_flag IS NOT NULL
521                          AND POHA.cancel_flag IS NULL)
522 		);
523    EXCEPTION
524 	WHEN NO_DATA_FOUND THEN
525 		x_header_control.cancel_flag :='N';
526    END;
527 
528    BEGIN
529 /* Bug# 1151387: frkhan
530 ** Desc: The SQL was resulting in division by zero when the value
531 **       of POHA.blanket_total_amount was 0.
532 ** Modified the divisor in the select statement
533 ** from:        nvl(POHA.blanket_total_amount,1)
534 ** to:          decode(nvl(POHA.blanket_total_amount,0),0,1,
535 **                     POHA.blanket_total_amount)
536 */
537                  -- SQL What: Retrieving the percentage change in
538                  --           blanket total amount
539                  -- SQL Why: Need the value in tolerance check (i.e reapproval
540                  --          rule validations)
541                  -- SQL Join: po_header_id
542                 SELECT max((nvl(POH.blanket_total_amount,0)
543 			    -nvl(POHA.blanket_total_amount,0))
544 			   / decode(nvl(POHA.blanket_total_amount,0),0,1,
545                                     POHA.blanket_total_amount)*100)
546                 INTO  x_header_control.blanket_total_change
547                 FROM   PO_HEADERS_all POH,
548                 PO_HEADERS_ARCHIVE_all POHA
549                 WHERE  POH.po_header_id = x_po_header_id
550                 AND    POH.po_header_id = POHA.po_header_id (+)
551                 AND    POHA.latest_external_flag (+) = 'Y';
552    EXCEPTION
553 	WHEN NO_DATA_FOUND THEN
554 		x_header_control.blanket_total_change := 0;
555    END;
556 
557 
558 /* Bug# 6616522: jburugul
559  *  * ** Desc: Added following SQL to capture changes when amount limit
560  *   * ** is made null
561  *    * */
562 
563 BEGIN
564                 SELECT DISTINCT 'Y'
565                 INTO  x_header_control.amount_limit
566                 FROM   PO_HEADERS_all POH,
567                 PO_HEADERS_ARCHIVE_all POHA
568                 WHERE  POH.po_header_id = x_po_header_id
569                 AND    POH.po_header_id = POHA.po_header_id (+)
570                 AND    POHA.latest_external_flag (+) = 'Y'
571                 AND   ((POH.amount_limit IS NULL AND
572                        POHA.amount_limit IS NOT NULL)
573                 );
574    EXCEPTION
575         WHEN NO_DATA_FOUND THEN
576                 x_header_control.amount_limit :='N';
577    END;
578 
579 /* end of Bug 6616522 */
580 
581 
582 
583    BEGIN
584 /* Bug# 1151387: frkhan
585 ** Desc: The SQL was resulting in division by zero when the value
586 **       of POHA.amount_limit was 0.
587 ** Modified the divisor in the select statement
588 ** from:	nvl(POHA.amount_limit,1)
589 ** to:		decode(nvl(POHA.amount_limit,0),0,1,POHA.amount_limit)
590 */
591                  -- SQL What: Retrieving the percentage change in
592                  --           amount limit
593                  -- SQL Why: Need the value in tolerance check (i.e reapproval
594                  --          rule validations)
595                  -- SQL Join: po_header_id
596                 SELECT max((nvl(POH.amount_limit,0)
597 			    -nvl(POHA.amount_limit,0))
598 		   / decode(nvl(POHA.amount_limit,0),0,1,POHA.amount_limit)
599 			   *100)
600                 INTO  x_header_control.amount_limit_change
601                 FROM   PO_HEADERS_all POH,
602                 PO_HEADERS_ARCHIVE_all POHA
603                 WHERE  POH.po_header_id = x_po_header_id
604                 AND    POH.po_header_id = POHA.po_header_id (+)
605                 AND    POHA.latest_external_flag (+) = 'Y';
606    EXCEPTION
607 	WHEN NO_DATA_FOUND THEN
608 		x_header_control.amount_limit_change := 0;
609    END;
610 
611    BEGIN
612                 -- SQL What: Select 'Y' if po_acknowledged is changed
613                 -- SQL Why: Need the value for routing to reapproval
614                 --          if there is a change
615 	        SELECT DISTINCT 'Y'
616 		INTO   x_header_control.po_acknowledged
617                 FROM   PO_ACCEPTANCES PA
618                 WHERE  PA.po_header_id = x_po_header_id;
619    EXCEPTION
620 	WHEN NO_DATA_FOUND THEN
621 		x_header_control.po_acknowledged:='N';
622    END;
623 
624    BEGIN
625                 -- SQL What: Select 'Y' if po_accepted is changed
626                 -- SQL Why: Need the value for routing to reapproval
627                 --          if there is a change
628 	        SELECT DISTINCT 'Y'
629 		INTO   x_header_control.po_accepted
630                 FROM   PO_ACCEPTANCES PA
631                 WHERE  PA.po_header_id = x_po_header_id
632 		AND    PA.accepted_flag = 'Y';
633    EXCEPTION
634 	WHEN NO_DATA_FOUND THEN
635 		x_header_control.po_accepted:='N';
636    END;
637 
638 /* Bug# 2427993: kagarwal
639 ** Desc: For Blanket Agreements (Blanket Purchase Orders), the shipments
640 ** and distributions do not exist hence there is no need to calculate the
641 ** po total change. Morever this is not even considered in blanket_po_reapproval.
642 */
643 
644    l_document_type := wf_engine.GetItemAttrText (itemtype => itemtype,
645                                                 itemkey => itemkey,
646                                                 aname => 'DOCUMENT_TYPE');
647 
648    l_document_subtype := wf_engine.GetItemAttrText (itemtype =>itemtype,
649                                                 itemkey => itemkey,
650                                                 aname => 'DOCUMENT_SUBTYPE');
651 
652    if ((l_document_type = 'PA') and (l_document_subtype = 'BLANKET')) then
653         x_header_control.po_total_change := 0;
654    else
655         x_header_control.po_total_change := po_total_change(x_po_header_id);
656    end if;
657 
658 	IF (g_po_wf_debug = 'Y') THEN
659    	PO_WF_DEBUG_PKG.INSERT_DEBUG(ITEMTYPE, ITEMKEY,
660    		'*** Finish check_header_change ***');
661 	END IF;
662 
663 EXCEPTION
664 
665  WHEN OTHERS THEN
666   wf_core.context('POAPPRV', 'check_header_change', 'others');
667   RAISE;
668 
669 END;
670 
671 FUNCTION po_total_change(x_po_header_id IN NUMBER) return NUMBER
672 IS
673 	x_po_total			NUMBER;
674 	x_po_total_archive		NUMBER;
675 	x_base_currency  		VARCHAR2(16);
676 	x_po_currency    		VARCHAR2(16);
677 	x_min_unit       		NUMBER;
678 	x_base_min_unit  		NUMBER;
679 	x_precision      		INTEGER;
680 	x_base_precision 		INTEGER;
681 	x_total_change			NUMBER;
682 BEGIN
683 
684    /* Find the percentage change for po_total */
685 
686   po_core_s2.get_po_currency (x_po_header_id,
687 	                      x_base_currency,
688                               x_po_currency );
689 
690   IF x_base_currency <> x_po_currency THEN
691 
692         po_core_s2.get_currency_info (x_po_currency,
693                            x_precision,
694                            x_min_unit );
695 
696         po_core_s2.get_currency_info (x_base_currency,
697                            x_base_precision,
698                            x_base_min_unit );
699 
700 /* Bug #: 1415223 draising
701    Forward fix of Bug # 1377624
702    Modified the SQL statements to take header_id from PO_DISTRIBUTIONS_ALL
703    table (for example : POLLA.po_header_id = x_po_header_id is changed to
704    PODA.po_header_id = x_po_header_id) to improve the performance
705    of sql statements.
706 */
707 /*
708    Bug # 5172716
709    Modified the statements to calculate amount information from amount_ordered and
710    amount_cancelled fields when the matching basis is AMOUNT.
711 */
712 
713     Begin
714             SELECT
715                  nvl(round(round(sum(
716                                       DECODE(POLL.matching_basis
717                                       , 'AMOUNT',
718                                       (nvl(POD.amount_ordered, 0) -
719                                        nvl(POD.amount_cancelled, 0)) *
720                                        nvl(POD.rate,1) /
721                                        nvl(X_min_unit,1)
722                                       , --QUANTITY
723                                       (nvl(POD.quantity_ordered, 0) -
724                                        nvl(POD.quantity_cancelled, 0)) *
725                                        nvl(POLL.price_override, 0) *
726                                        nvl(POD.rate,1) /
727                                        nvl(X_min_unit,1))
728                                       )
729                                   * nvl(X_min_unit,1)/ nvl(X_base_min_unit,1)
730                                  )
731                                * nvl(X_base_min_unit,1)) , 0)
732             INTO   x_po_total
733             FROM   PO_DISTRIBUTIONS_ALL POD, PO_LINE_LOCATIONS_ALL POLL
734             WHERE  POD.po_header_id = x_po_header_id
735             AND    POLL.shipment_type in ('STANDARD','PLANNED','BLANKET')
736             AND    POLL.line_location_id = POD.line_location_id;
737     EXCEPTION
738 	WHEN NO_DATA_FOUND THEN
739 		x_po_total := 0;
740 
741     End;
742 
743     Begin
744             SELECT
745                  nvl(round(round(sum(
746                                       DECODE(POLLA.matching_basis
747                                       , 'AMOUNT',
748                                       (nvl(PODA.amount_ordered, 0) -
749                                        nvl(PODA.amount_cancelled, 0)) *
750                                        nvl(PODA.rate,1) /
751                                        nvl(X_min_unit,1)
752                                       , --QUANTITY
753                                       (nvl(PODA.quantity_ordered, 0) -
754                                        nvl(PODA.quantity_cancelled, 0)) *
755                                        nvl(POLLA.price_override, 0) *
756                                        nvl(PODA.rate,1) /
757                                        nvl(X_min_unit,1))
758                                       )
759                                   * nvl(X_min_unit,1)/ nvl(X_base_min_unit,1)
760                                  )
761                                * nvl(X_base_min_unit,1)) , 0)
762             INTO   x_po_total_archive
763 	          FROM   PO_LINE_LOCATIONS_ARCHIVE_ALL POLLA,
764      		   PO_DISTRIBUTIONS_ARCHIVE_ALL PODA
765             WHERE  PODA.po_header_id = x_po_header_id
766             AND    POLLA.latest_external_flag (+) = 'Y'
767             AND    PODA.latest_external_flag (+) = 'Y'
768             AND    POLLA.shipment_type in ('STANDARD','PLANNED','BLANKET')
769             AND    POLLA.line_location_id = PODA.line_location_id;
770    EXCEPTION
771 	WHEN NO_DATA_FOUND THEN
772 		x_po_total_archive :=0;
773 
774     End;
775 
776   ELSE 	/* base currency = po_currrency */
777 
778    Begin
779             SELECT sum(
780                         DECODE(POLL.matching_basis
781                                   , 'AMOUNT',
782                                  (nvl(POD.amount_ordered, 0) -
783                                   nvl(POD.amount_cancelled, 0))
784                                   , --QUANTITY
785                                  (nvl(POD.quantity_ordered, 0) -
786                                   nvl(POD.quantity_cancelled, 0)) *
787                                   nvl(POLL.price_override, 0)))
788             INTO   x_po_total
789             FROM   PO_DISTRIBUTIONS_ALL POD, PO_LINE_LOCATIONS_ALL POLL
790             WHERE  POD.po_header_id = x_po_header_id
791             AND    POLL.shipment_type in ('STANDARD','PLANNED','BLANKET')
792             AND    POLL.line_location_id = POD.line_location_id;
793    EXCEPTION
794 	WHEN NO_DATA_FOUND THEN
795 		x_po_total :=0;
796 
797     End;
798 
799  /* bug# 880416 : brought forward the changes form release 11 fixed by
800     csheu (bug# 875997). added the line POLLA.po_header_id = PODA.po_header_id.    to improve performance.
801  */
802 
803     Begin
804             SELECT sum(
805                         DECODE(POLLA.matching_basis
806                                   , 'AMOUNT',
807                                  (nvl(PODA.amount_ordered, 0) -
808                                   nvl(PODA.amount_cancelled, 0))
809                                   , --QUANTITY
810                                  (nvl(PODA.quantity_ordered, 0) -
811                                   nvl(PODA.quantity_cancelled, 0)) *
812                                   nvl(POLLA.price_override, 0)))
813             INTO   x_po_total_archive
814             FROM   PO_LINE_LOCATIONS_ARCHIVE_ALL POLLA,
815                    PO_DISTRIBUTIONS_ARCHIVE_ALL PODA
816             WHERE  PODA.po_header_id = x_po_header_id
817             AND    POLLA.latest_external_flag (+) = 'Y'
818             AND    PODA.latest_external_flag (+) = 'Y'
819             AND    POLLA.shipment_type in ('STANDARD','PLANNED','BLANKET')
820             AND    POLLA.line_location_id = PODA.line_location_id
821             AND    PODA.po_header_id = POLLA.po_header_id;
822    EXCEPTION
823 	WHEN NO_DATA_FOUND THEN
824 		x_po_total_archive :=0;
825 
826    End;
827 
828   END IF;
829 
830   x_total_change := PO_CHORD_WF0.percentage_change(x_po_total_archive,
831 						    x_po_total);
832 
833   return(round(x_total_change,2));
834 
835 EXCEPTION
836 
837  WHEN OTHERS THEN
838   wf_core.context('POAPPRV', 'po_total_change', 'others');
839 
840 END;
841 
842 
843 PROCEDURE set_wf_header_control(itemtype		IN VARCHAR2,
844 				itemkey			IN VARCHAR2,
845 				x_header_control 	IN t_header_control_type)
846 IS
847 BEGIN
848 	IF (g_po_wf_debug = 'Y') THEN
849    	PO_WF_DEBUG_PKG.INSERT_DEBUG(ITEMTYPE, ITEMKEY,
850    		'*** In procedure set_wf_header_control ***');
851 	END IF;
852 
853  wf_engine.SetItemAttrText(itemtype,
854 			   itemkey,
855 			   'CO_H_AGENT_MODIFIED',
856 			   x_header_control.agent_id);
857 
858  wf_engine.SetItemAttrText(itemtype,
859 			   itemkey,
860 			   'CO_H_VENDOR_SITE_MODIFIED',
861 			   x_header_control.vendor_site_id);
862 
863  wf_engine.SetItemAttrText(itemtype,
864 			   itemkey,
865 			   'CO_H_VENDOR_CONTACT_MODIFIED',
866 			   x_header_control.vendor_contact_id);
867 
868  wf_engine.SetItemAttrText(itemtype,
869 			   itemkey,
870 			   'CO_H_SHIP_TO_MODIFIED',
871 			   x_header_control.ship_to_location_id);
872 
873  wf_engine.SetItemAttrText(itemtype,
874 			   itemkey,
875 			   'CO_H_BILL_TO_MODIFIED',
876 			   x_header_control.bill_to_location_id);
877 
878  wf_engine.SetItemAttrText(itemtype,
879 			   itemkey,
880 			   'CO_H_TERMS_MODIFIED',
881 			   x_header_control.terms_id);
882 
883  wf_engine.SetItemAttrText(itemtype,
884 			   itemkey,
885 			   'CO_H_SHIP_VIA_MODIFIED',
886 			   x_header_control.ship_via_lookup_code);
887 
888  wf_engine.SetItemAttrText(itemtype,
889 			   itemkey,
890 			   'CO_H_FOB_MODIFIED',
891 			   x_header_control.fob_lookup_code);
892 
893  wf_engine.SetItemAttrText(itemtype,
894 			   itemkey,
895 			   'CO_H_FREIGHT_MODIFIED',
896 			   x_header_control.freight_terms_lookup_code);
897 
898  wf_engine.SetItemAttrText(itemtype,
899 			   itemkey,
900 			   'CO_H_NOTE_TO_VENDOR_MODIFIED',
901 			   x_header_control.note_to_vendor);
902 
903  wf_engine.SetItemAttrText(itemtype,
904 			   itemkey,
905 			   'CO_H_CONFIRMING_ORDER_MODIFIED',
906 			   x_header_control.confirming_order_flag);
907 
908  wf_engine.SetItemAttrText(itemtype,
909 			   itemkey,
910 			   'CO_H_ACCEPT_REQUIRED_MODIFIED',
911 			   x_header_control.acceptance_required_flag);
912 
913  wf_engine.SetItemAttrText(itemtype,
914 			   itemkey,
915 			   'CO_H_ACCEPT_DUE_MODIFIED',
916 			   x_header_control.acceptance_due_date);
917 
918 
919  wf_engine.SetItemAttrText(itemtype,
920 			   itemkey,
921 			   'CO_H_START_DATE_MODIFIED',
922 			   x_header_control.start_date);
923 
924  wf_engine.SetItemAttrText(itemtype,
925 			   itemkey,
926 			   'CO_H_END_DATE_MODIFIED',
927 			   x_header_control.end_date);
928 
929 
930  wf_engine.SetItemAttrText(itemtype,
931 			   itemkey,
932 			   'CO_H_CANCEL_FLAG',
933 			   x_header_control.cancel_flag);
934 
935  wf_engine.SetItemAttrNumber(itemtype,
936 			     itemkey,
937 			     'CO_H_BLANKET_TOTAL_CHANGE',
938 			     x_header_control.blanket_total_change);
939 
940  wf_engine.SetItemAttrNumber(itemtype,
941 			     itemkey,
942 			     'CO_H_AMOUNT_LIMIT_CHANGE',
943 			     x_header_control.amount_limit_change);
944 
945  wf_engine.SetItemAttrText(itemtype,
946 			   itemkey,
947 			   'CO_H_PO_ACKNOWLEDGED',
948 			   x_header_control.po_acknowledged);
949 
950  wf_engine.SetItemAttrText(itemtype,
951 			   itemkey,
952 			   'CO_H_PO_ACCEPTED',
953 			   x_header_control.po_accepted);
954 
955  wf_engine.SetItemAttrNumber(itemtype,
956 			     itemkey,
957 			     'CO_H_PO_TOTAL_CHANGE',
958 			     x_header_control.po_total_change);
959 
960 /* Added following for Bug 6616522  */
961 
962  wf_engine.SetItemAttrText(itemtype,
963                              itemkey,
964                              'CO_H_AMOUNT_LIMIT_MODIFIED',
965                              x_header_control.amount_limit);
966 
967 	--debug_header_control(itemtype, itemkey, x_header_control);
968 
969 	IF (g_po_wf_debug = 'Y') THEN
970    	PO_WF_DEBUG_PKG.INSERT_DEBUG(ITEMTYPE, ITEMKEY,
971    		'*** Finish set_wf_header_control ***');
972 	END IF;
973 
974 END;
975 
976 PROCEDURE get_wf_header_control(itemtype	 IN VARCHAR2,
977 				itemkey 	 IN VARCHAR2,
978 			 	x_header_control IN OUT NOCOPY t_header_control_type)
979 IS
980 BEGIN
981 	IF (g_po_wf_debug = 'Y') THEN
982    	PO_WF_DEBUG_PKG.INSERT_DEBUG(ITEMTYPE, ITEMKEY,
983    		'*** In procedure get_wf_header_control ***');
984 	END IF;
985 
986 	x_header_control.agent_id :=
987 		wf_engine.GetItemAttrText(itemtype,
988 		itemkey,
989 		'CO_H_AGENT_MODIFIED');
990 
991 	x_header_control.vendor_site_id :=
992 		wf_engine.GetItemAttrText(itemtype,
993 		itemkey,
994 		'CO_H_VENDOR_SITE_MODIFIED');
995 
996 	x_header_control.vendor_contact_id :=
997 		wf_engine.GetItemAttrText(itemtype,
998 		itemkey,
999 		'CO_H_VENDOR_CONTACT_MODIFIED');
1000 
1001 	x_header_control.ship_to_location_id :=
1002 		wf_engine.GetItemAttrText(itemtype,
1003 		itemkey,
1004 		'CO_H_SHIP_TO_MODIFIED');
1005 
1006 	x_header_control.bill_to_location_id  :=
1007 		wf_engine.GetItemAttrText(itemtype,
1008 		itemkey,
1009 		'CO_H_BILL_TO_MODIFIED');
1010 
1011 	x_header_control.terms_id :=
1012 		wf_engine.GetItemAttrText(itemtype,
1013 		itemkey,
1014 		'CO_H_TERMS_MODIFIED');
1015 
1016 	x_header_control.ship_via_lookup_code :=
1017 		wf_engine.GetItemAttrText(itemtype,
1018 		itemkey,
1019 		'CO_H_SHIP_VIA_MODIFIED');
1020 
1021 	x_header_control.fob_lookup_code :=
1022 		wf_engine.GetItemAttrText(itemtype,
1023 		itemkey,
1024 		'CO_H_FOB_MODIFIED');
1025 
1026 	x_header_control.freight_terms_lookup_code :=
1027 		wf_engine.GetItemAttrText(itemtype,
1028 		itemkey,
1029 		'CO_H_FREIGHT_MODIFIED');
1030 
1031 	x_header_control.note_to_vendor :=
1032 		wf_engine.GetItemAttrText(itemtype,
1033 		itemkey,
1034 		'CO_H_NOTE_TO_VENDOR_MODIFIED');
1035 
1036 	x_header_control.confirming_order_flag :=
1037 		wf_engine.GetItemAttrText(itemtype,
1038 		itemkey,
1039 		'CO_H_CONFIRMING_ORDER_MODIFIED');
1040 
1041 	x_header_control.acceptance_required_flag :=
1042 		wf_engine.GetItemAttrText(itemtype,
1043 		itemkey,
1044 		'CO_H_ACCEPT_REQUIRED_MODIFIED');
1045 
1046 	x_header_control.acceptance_due_date :=
1047 		wf_engine.GetItemAttrText(itemtype,
1048 		itemkey,
1049 		'CO_H_ACCEPT_DUE_MODIFIED');
1050 
1051 	x_header_control.start_date :=
1052 		wf_engine.GetItemAttrText(itemtype,
1053 		itemkey,
1054 		'CO_H_START_DATE_MODIFIED');
1055 
1056 	x_header_control.end_date :=
1057 		wf_engine.GetItemAttrText(itemtype,
1058 		itemkey,
1059 		'CO_H_END_DATE_MODIFIED');
1060 
1061 	x_header_control.cancel_flag :=
1062 		wf_engine.GetItemAttrText(itemtype,
1063 		itemkey,
1064 		'CO_H_CANCEL_FLAG');
1065 
1066 	x_header_control.blanket_total_change :=
1067 		wf_engine.GetItemAttrNumber(itemtype,
1068 			     itemkey,
1069 			     'CO_H_BLANKET_TOTAL_CHANGE');
1070 
1071 	x_header_control.amount_limit_change :=
1072 	 	wf_engine.GetItemAttrNumber(itemtype,
1073 			     itemkey,
1074 			     'CO_H_AMOUNT_LIMIT_CHANGE');
1075 
1076 	x_header_control.po_acknowledged:=
1077 		 wf_engine.GetItemAttrText(itemtype,
1078 			itemkey,
1079 			'CO_H_PO_ACKNOWLEDGED');
1080 
1081 	x_header_control.po_accepted:=
1082 		 wf_engine.GetItemAttrText(itemtype,
1083 			itemkey,
1084 			'CO_H_PO_ACCEPTED');
1085 
1086 	x_header_control.po_total_change:=
1087 		 wf_engine.GetItemAttrNumber(itemtype,
1088 			     itemkey,
1089 			     'CO_H_PO_TOTAL_CHANGE');
1090 
1091  /* Added following for Bug 6616522 */
1092         x_header_control.amount_limit:=
1093            wf_engine.GetItemAttrText(itemtype,
1094                          itemkey,
1095                          'CO_H_AMOUNT_LIMIT_MODIFIED');
1096 
1097 	debug_header_control(itemtype, itemkey, x_header_control);
1098 
1099 	IF (g_po_wf_debug = 'Y') THEN
1100    	PO_WF_DEBUG_PKG.INSERT_DEBUG(ITEMTYPE, ITEMKEY,
1101    		'*** FINISH: get_wf_header_control ***');
1102 	END IF;
1103 END;
1104 
1105 PROCEDURE get_wf_header_parameters(itemtype	 IN VARCHAR2,
1106 				itemkey 	 IN VARCHAR2,
1107 			 	x_header_parameters IN OUT NOCOPY t_header_parameters_type)
1108 IS
1109 BEGIN
1110 	IF (g_po_wf_debug = 'Y') THEN
1111    	PO_WF_DEBUG_PKG.INSERT_DEBUG(ITEMTYPE, ITEMKEY,
1112    		'*** In procedure get_wf_header_parameters ***');
1113 	END IF;
1114 
1115 	x_header_parameters.po_header_id :=
1116 		wf_engine.GetItemAttrNumber(itemtype,
1117 					    itemkey,
1118 				    	    'DOCUMENT_ID');
1119 
1120 	IF (g_po_wf_debug = 'Y') THEN
1121    	PO_WF_DEBUG_PKG.INSERT_DEBUG(ITEMTYPE, ITEMKEY,
1122    		'po_header_id = '|| to_char(x_header_parameters.po_header_id));
1123 	END IF;
1124 
1125 	IF (g_po_wf_debug = 'Y') THEN
1126    	PO_WF_DEBUG_PKG.INSERT_DEBUG(ITEMTYPE, ITEMKEY,
1127    		'*** FINISH: get_wf_header_parameters ***');
1128 	END IF;
1129 
1130 EXCEPTION
1131 
1132  WHEN OTHERS THEN
1133   wf_core.context('POAPPRV', 'get_wf_headers_paramters', 'others');
1134   RAISE;
1135 
1136 END;
1137 
1138 PROCEDURE debug_header_control(itemtype	IN VARCHAR2,
1139 			       itemkey	IN VARCHAR2,
1140 			       x_header_control IN t_header_control_type)
1141 IS
1142 BEGIN
1143 	IF (g_po_wf_debug = 'Y') THEN
1144    	PO_WF_DEBUG_PKG.INSERT_DEBUG(ITEMTYPE, ITEMKEY,
1145    		'*** In procedure: debug_header_control ***');
1146 	END IF;
1147 
1148  IF (g_po_wf_debug = 'Y') THEN
1149     PO_WF_DEBUG_PKG.insert_debug(itemtype, itemkey,
1150    	'agent_id                 : ' ||x_header_control.agent_id);
1151     PO_WF_DEBUG_PKG.insert_debug(itemtype, itemkey,
1152    	'vendor_site_id           : ' ||x_header_control.vendor_site_id);
1153     PO_WF_DEBUG_PKG.insert_debug(itemtype, itemkey,
1154    	'vendor_contact_id 	  : ' ||x_header_control.vendor_contact_id);
1155     PO_WF_DEBUG_PKG.insert_debug(itemtype, itemkey,
1156    	'ship_to_location_id 	  : ' ||x_header_control.ship_to_location_id);
1157     PO_WF_DEBUG_PKG.insert_debug(itemtype, itemkey,
1158    	'bill_to_location_id 	  : ' ||x_header_control.bill_to_location_id);
1159     PO_WF_DEBUG_PKG.insert_debug(itemtype, itemkey,
1160    	'terms_id 		  : ' ||x_header_control.terms_id);
1161     PO_WF_DEBUG_PKG.insert_debug(itemtype, itemkey,
1162    	'ship_via_lookup_code 	  : ' ||x_header_control.ship_via_lookup_code);
1163     PO_WF_DEBUG_PKG.insert_debug(itemtype, itemkey,
1164    	'fob_lookup_code          : ' ||x_header_control.fob_lookup_code);
1165     PO_WF_DEBUG_PKG.insert_debug(itemtype, itemkey,
1166    	'freight_terms_lookup_code: ' ||x_header_control.freight_terms_lookup_code);
1167     PO_WF_DEBUG_PKG.insert_debug(itemtype, itemkey,
1168    	'note_to_vendor           : ' ||x_header_control.note_to_vendor);
1169     PO_WF_DEBUG_PKG.insert_debug(itemtype, itemkey,
1170    	'confirming_order_flag    : ' ||x_header_control.confirming_order_flag);
1171     PO_WF_DEBUG_PKG.insert_debug(itemtype, itemkey,
1172    	'acceptance_required_flag : ' ||x_header_control.acceptance_required_flag);
1173     PO_WF_DEBUG_PKG.insert_debug(itemtype, itemkey,
1174    	'acceptance_due_date      : ' ||x_header_control.acceptance_due_date);
1175     PO_WF_DEBUG_PKG.insert_debug(itemtype, itemkey,
1176    	'start_date               : ' ||x_header_control.start_date);
1177     PO_WF_DEBUG_PKG.insert_debug(itemtype, itemkey,
1178    	'end_date                 : ' ||x_header_control.end_date);
1179     PO_WF_DEBUG_PKG.insert_debug(itemtype, itemkey,
1180    	'cancel_flag              : ' ||x_header_control.cancel_flag);
1181  END IF;
1182 
1183  IF (g_po_wf_debug = 'Y') THEN
1184     PO_WF_DEBUG_PKG.insert_debug(itemtype, itemkey,
1185    	'blanket_total_change     : ' ||to_char(x_header_control.blanket_total_change));
1186     PO_WF_DEBUG_PKG.insert_debug(itemtype, itemkey,
1187    	'amount_limit_change      : ' ||to_char(x_header_control.amount_limit_change));
1188  END IF;
1189 
1190  IF (g_po_wf_debug = 'Y') THEN
1191     PO_WF_DEBUG_PKG.insert_debug(itemtype, itemkey,
1192    	'po_acknowledged          : ' ||x_header_control.po_acknowledged);
1193     PO_WF_DEBUG_PKG.insert_debug(itemtype, itemkey,
1194    	'po_accepted              : ' ||x_header_control.po_accepted);
1195  END IF;
1196 
1197 	IF (g_po_wf_debug = 'Y') THEN
1198    	PO_WF_DEBUG_PKG.INSERT_DEBUG(ITEMTYPE, ITEMKEY,
1199    		'*** Finished: debug_header_control ***');
1200 	END IF;
1201 END;
1202 
1203 END PO_CHORD_WF1;