DBA Data[Home] [Help]

PACKAGE BODY: APPS.OE_HEADER_UTIL

Source


1 PACKAGE BODY OE_Header_Util AS
2 /* $Header: OEXUHDRB.pls 120.70.12020000.5 2013/01/07 09:42:30 sujithku ship $ */
3 
4 --  Global constant holding the package name
5 
6 G_PKG_NAME                    CONSTANT VARCHAR2(30) := 'OE_Header_Util';
7 
8 -- LOCAL Procedures
9 
10 -- Added 09-DEC-2002
11 -- Forward declaration of LOCAL PROCEDURE Blkt_Req_For_Curr_Upd_And_Del
12 PROCEDURE Blkt_Req_For_Curr_Upd_And_Del
13   (p_header_rec          IN OE_Order_PUB.Header_Rec_Type
14    ,p_old_header_rec     IN OE_Order_PUB.Header_Rec_Type
15   );
16 
17 --bug 5083663
18 PROCEDURE Set_CC_Selected_From_Lov (p_CC_selected_from_LOV IN VARCHAR2)
19 IS
20 BEGIN
21      g_is_cc_selected_from_LOV := p_CC_selected_from_LOV;
22 EXCEPTION
23 WHEN OTHERS THEN
24        NULL;
25 END Set_CC_Selected_From_Lov;
26 
27 -- Clear_Dependents
28 
29 PROCEDURE Clear_Dependents
30 	(p_src_attr_tbl				IN  OE_GLOBALS.NUMBER_Tbl_Type
31      ,p_initial_header_rec		IN  OE_AK_ORDER_HEADERS_V%ROWTYPE
32      ,p_old_header_rec			IN  OE_AK_ORDER_HEADERS_V%ROWTYPE
33 	,p_x_header_rec				IN OUT NOCOPY OE_AK_ORDER_HEADERS_V%ROWTYPE
34 	,p_x_instrument_id		IN NUMBER DEFAULT NULL
35 	,p_old_instrument_id		IN NUMBER DEFAULT NULL)
36 IS
37 	l_dep_attr_tbl          OE_GLOBALS.NUMBER_Tbl_Type;
38 
39 	PROCEDURE ACCOUNTING_RULE
40 	IS
41 	BEGIN
42 		IF (p_initial_header_rec.accounting_rule_id = FND_API.G_MISS_NUM
43 		  OR (OE_GLOBALS.Equal(p_initial_header_rec.accounting_rule_id, p_old_header_rec.accounting_rule_id)
44                       AND (p_old_header_rec.header_id IS NOT NULL OR
45                            p_initial_header_rec.accounting_rule_id IS NOT NULL))
46                    ) -- AND condition added to fix 3098878
47 		THEN
48 			p_x_header_rec.accounting_rule_id := FND_API.G_MISS_NUM;
49 		END IF;
50 	END ACCOUNTING_RULE;
51 
52 	PROCEDURE ACCOUNTING_RULE_DURATION
53 	IS
54 	BEGIN
55 		IF (p_initial_header_rec.accounting_rule_duration = FND_API.G_MISS_NUM
56 		  OR (OE_GLOBALS.Equal(p_initial_header_rec.accounting_rule_duration, p_old_header_rec.accounting_rule_duration)
57                       AND (p_old_header_rec.header_id IS NOT NULL OR
58                            p_initial_header_rec.accounting_rule_duration IS NOT NULL))
59                    ) -- AND condition added to fix 3098878
60 		THEN
61 			p_x_header_rec.accounting_rule_duration := FND_API.G_MISS_NUM;
62 		END IF;
63 	END ACCOUNTING_RULE_DURATION;
64 
65 	PROCEDURE AGREEMENT IS
66 	BEGIN
67 		IF (p_initial_header_rec.agreement_id = FND_API.G_MISS_NUM
68 		  OR (OE_GLOBALS.Equal(p_initial_header_rec.agreement_id, p_old_header_rec.agreement_id)
69                       AND (p_old_header_rec.header_id IS NOT NULL OR
70                            p_initial_header_rec.agreement_id IS NOT NULL))
71                    ) -- AND condition added to fix 3098878
72 		THEN
73 			p_x_header_rec.agreement_id := FND_API.G_MISS_NUM;
74 		END IF;
75 	END AGREEMENT;
76 
77 	PROCEDURE CONVERSION_RATE IS
78 	BEGIN
79 		IF (p_initial_header_rec.conversion_rate = FND_API.G_MISS_NUM
80 		  OR (OE_GLOBALS.Equal(p_initial_header_rec.conversion_rate, p_old_header_rec.conversion_rate)
81                       AND (p_old_header_rec.header_id IS NOT NULL OR
82                            p_initial_header_rec.conversion_rate IS NOT NULL))
83                    ) -- AND condition added to fix 3098878
84 		THEN
85 			p_x_header_rec.conversion_rate := FND_API.G_MISS_NUM;
86 		END IF;
87 	END CONVERSION_RATE;
88 
89 	PROCEDURE CONVERSION_RATE_DATE IS
90 	BEGIN
91 		IF (p_initial_header_rec.conversion_rate_date = FND_API.G_MISS_DATE
92 		  OR (OE_GLOBALS.Equal(p_initial_header_rec.conversion_rate_date, p_old_header_rec.conversion_rate_date)
93                       AND (p_old_header_rec.header_id IS NOT NULL OR
94                            p_initial_header_rec.conversion_rate_date IS NOT NULL))
95                    ) -- AND condition added to fix 3098878
96 		THEN
97 			p_x_header_rec.conversion_rate_date := FND_API.G_MISS_DATE;
98 		END IF;
99 	END CONVERSION_RATE_DATE;
100 
101 	PROCEDURE CONVERSION_TYPE IS
102 	BEGIN
103 		IF (p_initial_header_rec.conversion_type_code = FND_API.G_MISS_CHAR
104 		  OR (OE_GLOBALS.Equal(p_initial_header_rec.conversion_type_code, p_old_header_rec.conversion_type_code)
105                       AND (p_old_header_rec.header_id IS NOT NULL OR
106                            p_initial_header_rec.conversion_type_code IS NOT NULL))
107                    ) -- AND condition added to fix 3098878
108 		THEN
109 			p_x_header_rec.conversion_type_code := FND_API.G_MISS_CHAR;
110 		END IF;
111 	END CONVERSION_TYPE;
112 
113 	PROCEDURE CREDIT_CARD_EXPIRATION_DATE IS
114 	BEGIN
115 		IF (p_initial_header_rec.credit_card_expiration_date = FND_API.G_MISS_DATE
116 		  OR (OE_GLOBALS.Equal(p_initial_header_rec.credit_card_expiration_date, p_old_header_rec.credit_card_expiration_date)
117                       AND (p_old_header_rec.header_id IS NOT NULL OR
118                            p_initial_header_rec.credit_card_expiration_date IS NOT NULL)
119 		      AND nvl(g_is_cc_selected_from_LOV,'N') <> 'Y') --bug 5083663
120                    ) -- AND condition added to fix 3098878
121 		THEN
122 			p_x_header_rec.credit_card_expiration_date := FND_API.G_MISS_DATE;
123 		END IF;
124 	END CREDIT_CARD_EXPIRATION_DATE;
125 
126 	PROCEDURE CREDIT_CARD_HOLDER_NAME IS
127 	BEGIN
128 		IF (p_initial_header_rec.credit_card_holder_name = FND_API.G_MISS_CHAR
129 		  OR (OE_GLOBALS.Equal(p_initial_header_rec.credit_card_holder_name, p_old_header_rec.credit_card_holder_name)
130                       AND (p_old_header_rec.header_id IS NOT NULL OR
131                            p_initial_header_rec.credit_card_holder_name IS NOT NULL)
132 		      AND nvl(g_is_cc_selected_from_LOV,'N') <> 'Y') --bug 5083663
133                    ) -- AND condition added to fix 3098878
134 		THEN
135 			p_x_header_rec.credit_card_holder_name := FND_API.G_MISS_CHAR;
136 		END IF;
137 	END CREDIT_CARD_HOLDER_NAME;
138 
139 	PROCEDURE CREDIT_CARD_NUMBER IS
140 	BEGIN
141 		IF (p_initial_header_rec.credit_card_number = FND_API.G_MISS_CHAR
142 		  OR (OE_GLOBALS.Is_Same_Credit_Card(p_old_header_rec.credit_card_number,p_initial_header_rec.credit_card_number,
143 		  p_old_instrument_id,p_x_instrument_id)
144                       AND (p_old_header_rec.header_id IS NOT NULL OR
145                            p_initial_header_rec.credit_card_number IS NOT NULL))
146                    ) -- AND condition added to fix 3098878
147 		THEN
148 			--oe_debug_pub.add('In credit card number clear ....'||p_x_header_rec.credit_card_number);
149 			p_x_header_rec.credit_card_number := FND_API.G_MISS_CHAR;
150 
151 		END IF;
152 	END CREDIT_CARD_NUMBER;
153 
154         /* Fix Bug # 2297053: Added to clear Credit Card Type */
155 	PROCEDURE CREDIT_CARD IS
156 	BEGIN
157 		IF (p_initial_header_rec.credit_card_code = FND_API.G_MISS_CHAR
158 		  OR (OE_GLOBALS.Equal(p_initial_header_rec.credit_card_code, p_old_header_rec.credit_card_code)
159                       AND (p_old_header_rec.header_id IS NOT NULL OR
160                            p_initial_header_rec.credit_card_code IS NOT NULL))
161                    ) -- AND condition added to fix 3098878
162 		THEN
163 			p_x_header_rec.credit_card_code := FND_API.G_MISS_CHAR;
164 		END IF;
165 	END CREDIT_CARD;
166 
167 	PROCEDURE CHECK_NUMBER IS    --For bug 2692314
168 	BEGIN
169 		IF (p_initial_header_rec.check_number = FND_API.G_MISS_CHAR
170 		  OR (OE_GLOBALS.Equal(p_initial_header_rec.check_number, p_old_header_rec.check_number)
171                       AND (p_old_header_rec.header_id IS NOT NULL OR
172                            p_initial_header_rec.check_number IS NOT NULL))
173                    ) -- AND condition added to fix 3098878
174 		THEN
175 			p_x_header_rec.check_number := FND_API.G_MISS_CHAR;
176 		END IF;
177 	END CHECK_NUMBER;
178 
179 	PROCEDURE CUST_PO_NUMBER IS
180 	BEGIN
181 		IF (p_initial_header_rec.cust_po_number = FND_API.G_MISS_CHAR
182 		  OR (OE_GLOBALS.Equal(p_initial_header_rec.cust_po_number, p_old_header_rec.cust_po_number)
183                       AND (p_old_header_rec.header_id IS NOT NULL OR
184                            p_initial_header_rec.cust_po_number IS NOT NULL))
185                    ) -- AND condition added to fix 3098878
186 		THEN
187 			p_x_header_rec.cust_po_number := FND_API.G_MISS_CHAR;
188 		END IF;
189 	END CUST_PO_NUMBER;
190 
191         PROCEDURE CUSTOMER_PREFERENCE_SET_CODE IS
192         BEGIN
193 		IF (p_initial_header_rec.Customer_Preference_Set_Code = FND_API.G_MISS_CHAR
194 		  OR (OE_GLOBALS.Equal(p_initial_header_rec.Customer_Preference_Set_Code, p_old_header_rec.Customer_Preference_Set_Code)
195                       AND (p_old_header_rec.header_id IS NOT NULL OR
196                            p_initial_header_rec.Customer_Preference_Set_Code IS NOT NULL))
197                    ) -- AND condition added to fix 3098878
198                 THEN
199                         p_x_header_rec.Customer_Preference_Set_Code := FND_API.G_MISS_CHAR;
200                 END IF;
201         END CUSTOMER_PREFERENCE_SET_CODE ;
202 
203         PROCEDURE DEFAULT_FULFILLMENT_SET IS
204         BEGIN
205 		IF (p_initial_header_rec.Default_Fulfillment_Set = FND_API.G_MISS_CHAR
206 		  OR (OE_GLOBALS.Equal(p_initial_header_rec.Default_Fulfillment_Set, p_old_header_rec.Default_Fulfillment_Set)
207                       AND (p_old_header_rec.header_id IS NOT NULL OR
208                            p_initial_header_rec.Default_Fulfillment_Set IS NOT NULL))
209                    ) -- AND condition added to fix 3098878
210                 THEN
211                         p_x_header_rec.Default_Fulfillment_Set := FND_API.G_MISS_CHAR;
212                 END IF;
213         END DEFAULT_FULFILLMENT_SET;
214 
215 	PROCEDURE DELIVER_TO_CONTACT IS
216 	BEGIN
217 		IF (p_initial_header_rec.deliver_to_contact_id = FND_API.G_MISS_NUM
218 		  OR (OE_GLOBALS.Equal(p_initial_header_rec.deliver_to_contact_id, p_old_header_rec.deliver_to_contact_id)
219                       AND (p_old_header_rec.header_id IS NOT NULL OR
220                            p_initial_header_rec.deliver_to_contact_id IS NOT NULL))
221                    ) -- AND condition added to fix 3098878
222 		THEN
223 			p_x_header_rec.deliver_to_contact_id := FND_API.G_MISS_NUM;
224 		END IF;
225 	END DELIVER_TO_CONTACT;
226 
227 	PROCEDURE DELIVER_TO_ORG IS
228 	BEGIN
229 		IF (p_initial_header_rec.deliver_to_org_id = FND_API.G_MISS_NUM
230 		  OR (OE_GLOBALS.Equal(p_initial_header_rec.deliver_to_org_id, p_old_header_rec.deliver_to_org_id)
231                       AND (p_old_header_rec.header_id IS NOT NULL OR
232                            p_initial_header_rec.deliver_to_org_id IS NOT NULL))
233                    ) -- AND condition added to fix 3098878
234 		THEN
235 			p_x_header_rec.deliver_to_org_id := FND_API.G_MISS_NUM;
236 		END IF;
237 	END DELIVER_TO_ORG;
238 
239 	PROCEDURE DEMAND_CLASS IS
240 	BEGIN
241 		IF (p_initial_header_rec.demand_class_code = FND_API.G_MISS_CHAR
242 		  OR (OE_GLOBALS.Equal(p_initial_header_rec.demand_class_code, p_old_header_rec.demand_class_code)
243                       AND (p_old_header_rec.header_id IS NOT NULL OR
244                            p_initial_header_rec.demand_class_code IS NOT NULL))
245                    ) -- AND condition added to fix 3098878
246 		THEN
247 			p_x_header_rec.demand_class_code := FND_API.G_MISS_CHAR;
248 		END IF;
249 	END DEMAND_CLASS;
250 
251 	PROCEDURE FOB_POINT IS
252 	BEGIN
253 		IF (p_initial_header_rec.fob_point_code = FND_API.G_MISS_CHAR
254 		  OR (OE_GLOBALS.Equal(p_initial_header_rec.fob_point_code, p_old_header_rec.fob_point_code)
255                       AND (p_old_header_rec.header_id IS NOT NULL OR
256                            p_initial_header_rec.fob_point_code IS NOT NULL))
257                    ) -- AND condition added to fix 3098878
258 		THEN
259 			p_x_header_rec.fob_point_code := FND_API.G_MISS_CHAR;
260 		END IF;
261 	END FOB_POINT;
262 
263 	PROCEDURE FREIGHT_TERMS IS
264 	BEGIN
265 		IF (p_initial_header_rec.freight_terms_code = FND_API.G_MISS_CHAR
266 		  OR (OE_GLOBALS.Equal(p_initial_header_rec.freight_terms_code, p_old_header_rec.freight_terms_code)
267                       AND (p_old_header_rec.header_id IS NOT NULL OR
268                            p_initial_header_rec.freight_terms_code IS NOT NULL))
269                    ) -- AND condition added to fix 3098878
270 		THEN
271 			p_x_header_rec.freight_terms_code := FND_API.G_MISS_CHAR;
272 		END IF;
273 	END FREIGHT_TERMS;
274 
275         PROCEDURE FULFILLMENT_SET_NAME IS
276         BEGIN
277 		IF (p_initial_header_rec.Fulfillment_Set_name = FND_API.G_MISS_CHAR
278 		  OR (OE_GLOBALS.Equal(p_initial_header_rec.Fulfillment_Set_name, p_old_header_rec.Fulfillment_Set_name)
279                       AND (p_old_header_rec.header_id IS NOT NULL OR
280                            p_initial_header_rec.Fulfillment_Set_name IS NOT NULL))
281                    ) -- AND condition added to fix 3098878
282                 THEN
283                         p_x_header_rec.Fulfillment_Set_Name := FND_API.G_MISS_CHAR;
284                 END IF;
285         END FULFILLMENT_SET_NAME;
286 
287 	PROCEDURE INVOICE_TO_CONTACT IS
288 	BEGIN
289 		IF (p_initial_header_rec.invoice_to_contact_id = FND_API.G_MISS_NUM
290 		  OR (OE_GLOBALS.Equal(p_initial_header_rec.invoice_to_contact_id, p_old_header_rec.invoice_to_contact_id)
291                       AND (p_old_header_rec.header_id IS NOT NULL OR
292                            p_initial_header_rec.invoice_to_contact_id IS NOT NULL))
293                    ) -- AND condition added to fix 3098878
294 		THEN
295 			p_x_header_rec.invoice_to_contact_id := FND_API.G_MISS_NUM;
296 		END IF;
297 	END INVOICE_TO_CONTACT;
298 
299 	PROCEDURE INVOICE_TO_ORG IS
300 	BEGIN
301 		IF (p_initial_header_rec.invoice_to_org_id = FND_API.G_MISS_NUM
302 		  OR (OE_GLOBALS.Equal(p_initial_header_rec.invoice_to_org_id, p_old_header_rec.invoice_to_org_id)
303                       AND (p_old_header_rec.header_id IS NOT NULL OR
304                            p_initial_header_rec.invoice_to_org_id IS NOT NULL))
305                    ) -- AND condition added to fix 3098878
306 		THEN
307 			p_x_header_rec.invoice_to_org_id := FND_API.G_MISS_NUM;
308 		END IF;
309 	END INVOICE_TO_ORG;
310 
311 	PROCEDURE INVOICING_RULE IS
312 	BEGIN
313 		IF (p_initial_header_rec.invoicing_rule_id = FND_API.G_MISS_NUM
314 		  OR (OE_GLOBALS.Equal(p_initial_header_rec.invoicing_rule_id, p_old_header_rec.invoicing_rule_id)
315                       AND (p_old_header_rec.header_id IS NOT NULL OR
316                            p_initial_header_rec.invoicing_rule_id IS NOT NULL))
317                    ) -- AND condition added to fix 3098878
318 		THEN
319 			p_x_header_rec.invoicing_rule_id := FND_API.G_MISS_NUM;
320 		END IF;
321 	END INVOICING_RULE;
322 
323         PROCEDURE LINE_SET_NAME IS
324         BEGIN
325 		IF (p_initial_header_rec.Line_Set_name = FND_API.G_MISS_CHAR
326 		  OR (OE_GLOBALS.Equal(p_initial_header_rec.Line_Set_name, p_old_header_rec.Line_Set_name)
327                       AND (p_old_header_rec.header_id IS NOT NULL OR
328                            p_initial_header_rec.Line_Set_name IS NOT NULL))
329                    ) -- AND condition added to fix 3098878
330                 THEN
331                         p_x_header_rec.Line_Set_Name := FND_API.G_MISS_CHAR;
332                 END IF;
333         END LINE_SET_NAME;
334 
335 	PROCEDURE ORDER_CATEGORY IS
336 	BEGIN
337 		IF (p_initial_header_rec.order_category_code = FND_API.G_MISS_CHAR
338 		  OR (OE_GLOBALS.Equal(p_initial_header_rec.order_category_code, p_old_header_rec.order_category_code)
339                       AND (p_old_header_rec.header_id IS NOT NULL OR
340                            p_initial_header_rec.order_category_code IS NOT NULL))
341                    ) -- AND condition added to fix 3098878
342 		THEN
343 			p_x_header_rec.order_category_code := FND_API.G_MISS_CHAR;
344 		END IF;
345 	END ORDER_CATEGORY;
346 
347 	PROCEDURE ORDER_DATE_TYPE IS
348 	BEGIN
349 
350 		IF (p_initial_header_rec.order_date_type_code = FND_API.G_MISS_CHAR
351 		  OR (OE_GLOBALS.Equal(p_initial_header_rec.order_date_type_code, p_old_header_rec.order_date_type_code)
352                       AND (p_old_header_rec.header_id IS NOT NULL OR
353                            p_initial_header_rec.order_date_type_code IS NOT NULL))
354                    ) -- AND condition added to fix 3098878
355 		THEN
356 			p_x_header_rec.order_date_type_code := FND_API.G_MISS_CHAR;
357 		END IF;
358 	END ORDER_DATE_TYPE;
359 
360 	PROCEDURE ORDER_TYPE IS
361 	BEGIN
362 		IF (p_initial_header_rec.order_type_id = FND_API.G_MISS_NUM
363 		  OR (OE_GLOBALS.Equal(p_initial_header_rec.order_type_id, p_old_header_rec.order_type_id)
364                       AND (p_old_header_rec.header_id IS NOT NULL OR
365                            p_initial_header_rec.order_type_id IS NOT NULL))
366                    ) -- AND condition added to fix 3098878
367 		THEN
368 			p_x_header_rec.order_type_id := FND_API.G_MISS_NUM;
369 		END IF;
370 	END ORDER_TYPE;
371 
372 	--Bug 4360599 Added this method to clear the payment Amount
373 	PROCEDURE PAYMENT_AMOUNT IS
374 	BEGIN
375 		IF (p_initial_header_rec.PAYMENT_AMOUNT = FND_API.G_MISS_NUM
376 		  OR (OE_GLOBALS.Equal(p_initial_header_rec.PAYMENT_AMOUNT, p_old_header_rec.PAYMENT_AMOUNT)
377                       AND (p_old_header_rec.header_id IS NOT NULL OR
378                            p_initial_header_rec.PAYMENT_AMOUNT IS NOT NULL))
379                    ) -- AND condition added to fix 3098878
380 		THEN
381 			p_x_header_rec.PAYMENT_AMOUNT := FND_API.G_MISS_NUM;
382 		END IF;
383 	END PAYMENT_AMOUNT;
384 
385 	PROCEDURE PAYMENT_TERM IS
386 	BEGIN
387 		IF (p_initial_header_rec.payment_term_id = FND_API.G_MISS_NUM
388 		  OR (OE_GLOBALS.Equal(p_initial_header_rec.payment_term_id, p_old_header_rec.payment_term_id)
389                       AND (p_old_header_rec.header_id IS NOT NULL OR
390                            p_initial_header_rec.payment_term_id IS NOT NULL))
391                    ) -- AND condition added to fix 3098878
392 		THEN
393 			p_x_header_rec.payment_term_id := FND_API.G_MISS_NUM;
394 		END IF;
395 	END PAYMENT_TERM;
396 
397 	PROCEDURE PRICE_LIST IS
398 	BEGIN
399 		IF (p_initial_header_rec.price_list_id = FND_API.G_MISS_NUM
400 		  OR (OE_GLOBALS.Equal(p_initial_header_rec.price_list_id, p_old_header_rec.price_list_id)
401                       AND (p_old_header_rec.header_id IS NOT NULL OR
402                            p_initial_header_rec.price_list_id IS NOT NULL))
403                    ) -- AND condition added to fix 3098878
404 		THEN
405 			p_x_header_rec.price_list_id := FND_API.G_MISS_NUM;
406 		END IF;
407 	END PRICE_LIST;
408 
409 	PROCEDURE PRICE_REQUEST_CODE IS  -- PROMOTIONS SEP/01 BEGIN
410 	BEGIN
411 		IF (p_initial_header_rec.price_request_code = FND_API.G_MISS_CHAR
412 		  OR (OE_GLOBALS.Equal(p_initial_header_rec.price_request_code, p_old_header_rec.price_request_code)
413                       AND (p_old_header_rec.header_id IS NOT NULL OR
414                            p_initial_header_rec.price_request_code IS NOT NULL))
415                    ) -- AND condition added to fix 3098878
416 		THEN
417 			p_x_header_rec.price_request_code := FND_API.G_MISS_CHAR;
418 		END IF;
419 	END PRICE_REQUEST_CODE;          -- PROMOTIONS SEP/01 END
420 
421 	PROCEDURE REQUEST_DATE IS
422 	BEGIN
423 		IF (p_initial_header_rec.request_date = FND_API.G_MISS_DATE
424 		  OR (OE_GLOBALS.Equal(p_initial_header_rec.request_date, p_old_header_rec.request_date)
425                       AND (p_old_header_rec.header_id IS NOT NULL OR
426                            p_initial_header_rec.request_date IS NOT NULL))
427                    ) -- AND condition added to fix 3098878
428 		THEN
429 			p_x_header_rec.request_date := FND_API.G_MISS_DATE;
430 		END IF;
431 	END REQUEST_DATE;
432 
433 	PROCEDURE SALESREP IS
434 	BEGIN
435 		IF (p_initial_header_rec.salesrep_id = FND_API.G_MISS_NUM
436 		  OR (OE_GLOBALS.Equal(p_initial_header_rec.salesrep_id, p_old_header_rec.salesrep_id)
437                       AND (p_old_header_rec.header_id IS NOT NULL OR
438                            p_initial_header_rec.salesrep_id IS NOT NULL))
439                    ) -- AND condition added to fix 3098878
440 		THEN
441 			p_x_header_rec.salesrep_id := FND_API.G_MISS_NUM;
442 		END IF;
443 	END SALESREP;
444 
445 	PROCEDURE SALES_CHANNEL IS
446 	BEGIN
447 		IF (p_initial_header_rec.sales_channel_code = FND_API.G_MISS_CHAR
448 		  OR (OE_GLOBALS.Equal(p_initial_header_rec.sales_channel_code, p_old_header_rec.sales_channel_code)
449                       AND (p_old_header_rec.header_id IS NOT NULL OR
450                            p_initial_header_rec.sales_channel_code IS NOT NULL))
451                    ) -- AND condition added to fix 3098878
452 		THEN
453 			p_x_header_rec.sales_channel_code := FND_API.G_MISS_CHAR;
454 		END IF;
455 	END SALES_CHANNEL;
456 
457 	PROCEDURE SHIPMENT_PRIORITY IS
458 	BEGIN
459 		IF (p_initial_header_rec.shipment_priority_code = FND_API.G_MISS_CHAR
460 		  OR (OE_GLOBALS.Equal(p_initial_header_rec.shipment_priority_code, p_old_header_rec.shipment_priority_code)
461                       AND (p_old_header_rec.header_id IS NOT NULL OR
462                            p_initial_header_rec.shipment_priority_code IS NOT NULL))
463                    ) -- AND condition added to fix 3098878
464 		THEN
465 			p_x_header_rec.shipment_priority_code := FND_API.G_MISS_CHAR;
466 		END IF;
467 	END SHIPMENT_PRIORITY;
468 
469 	PROCEDURE SHIPPING_METHOD IS
470 	BEGIN
471 		IF (p_initial_header_rec.shipping_method_code = FND_API.G_MISS_CHAR
472 		  OR (OE_GLOBALS.Equal(p_initial_header_rec.shipping_method_code, p_old_header_rec.shipping_method_code)
473                       AND (p_old_header_rec.header_id IS NOT NULL OR
474                            p_initial_header_rec.shipping_method_code IS NOT NULL))
475                    ) -- AND condition added to fix 3098878
476 		THEN
477 			p_x_header_rec.shipping_method_code := FND_API.G_MISS_CHAR;
478 		END IF;
479 	END SHIPPING_METHOD;
480 
481 	PROCEDURE SHIP_FROM_ORG IS
482 	BEGIN
483 		IF (p_initial_header_rec.ship_from_org_id = FND_API.G_MISS_NUM
484 		  OR (OE_GLOBALS.Equal(p_initial_header_rec.ship_from_org_id, p_old_header_rec.ship_from_org_id)
485                       AND (p_old_header_rec.header_id IS NOT NULL OR
486                            p_initial_header_rec.ship_from_org_id IS NOT NULL))
487                    ) -- AND condition added to fix 3098878
488 		THEN
489 			p_x_header_rec.ship_from_org_id := FND_API.G_MISS_NUM;
490 		END IF;
491 	END SHIP_FROM_ORG;
492 
493 	PROCEDURE SHIP_TOLERANCE_ABOVE IS
494 	BEGIN
495 		IF (p_initial_header_rec.ship_tolerance_above = FND_API.G_MISS_NUM
496 		  OR (OE_GLOBALS.Equal(p_initial_header_rec.ship_tolerance_above, p_old_header_rec.ship_tolerance_above)
497                       AND (p_old_header_rec.header_id IS NOT NULL OR
498                            p_initial_header_rec.ship_tolerance_above IS NOT NULL))
499                    ) -- AND condition added to fix 3098878
500 		THEN
501 			p_x_header_rec.ship_tolerance_above := FND_API.G_MISS_NUM;
502 		END IF;
503 	END SHIP_TOLERANCE_ABOVE;
504 
505 	PROCEDURE SHIP_TOLERANCE_BELOW IS
506 	BEGIN
507 		IF (p_initial_header_rec.ship_tolerance_below = FND_API.G_MISS_NUM
508 		  OR (OE_GLOBALS.Equal(p_initial_header_rec.ship_tolerance_below, p_old_header_rec.ship_tolerance_below)
509                       AND (p_old_header_rec.header_id IS NOT NULL OR
510                            p_initial_header_rec.ship_tolerance_below IS NOT NULL))
511                    ) -- AND condition added to fix 3098878
512 		THEN
513 			p_x_header_rec.ship_tolerance_below := FND_API.G_MISS_NUM;
514 		END IF;
515 	END SHIP_TOLERANCE_BELOW;
516 
517 	PROCEDURE SHIP_TO_CONTACT IS
518 	BEGIN
519 		IF (p_initial_header_rec.ship_to_contact_id = FND_API.G_MISS_NUM
520 		  OR (OE_GLOBALS.Equal(p_initial_header_rec.ship_to_contact_id, p_old_header_rec.ship_to_contact_id)
521                       AND (p_old_header_rec.header_id IS NOT NULL OR
522                            p_initial_header_rec.ship_to_contact_id IS NOT NULL))
523                    ) -- AND condition added to fix 3098878
524 		THEN
525 			p_x_header_rec.ship_to_contact_id := FND_API.G_MISS_NUM;
526 		END IF;
527 	END SHIP_TO_CONTACT;
528 
529 	PROCEDURE SHIP_TO_ORG IS
530 	BEGIN
531 		IF (p_initial_header_rec.ship_to_org_id = FND_API.G_MISS_NUM
532 		  OR (OE_GLOBALS.Equal(p_initial_header_rec.ship_to_org_id, p_old_header_rec.ship_to_org_id)
533                       AND (p_old_header_rec.header_id IS NOT NULL OR
534                            p_initial_header_rec.ship_to_org_id IS NOT NULL))
535                    ) -- AND condition added to fix 3098878
536 		THEN
537 			p_x_header_rec.ship_to_org_id := FND_API.G_MISS_NUM;
538 		END IF;
539 	END SHIP_TO_ORG;
540 
541         -- Fix bug 1753101: sold to contact dependency code added
542 	PROCEDURE SOLD_TO_CONTACT IS
543 	BEGIN
544 		IF (p_initial_header_rec.sold_to_contact_id = FND_API.G_MISS_NUM
545 		  OR (OE_GLOBALS.Equal(p_initial_header_rec.sold_to_contact_id, p_old_header_rec.sold_to_contact_id)
546                       AND (p_old_header_rec.header_id IS NOT NULL OR
547                            p_initial_header_rec.sold_to_contact_id IS NOT NULL))
548                    ) -- AND condition added to fix 3098878
549 		THEN
550 			p_x_header_rec.sold_to_contact_id := FND_API.G_MISS_NUM;
551 		END IF;
552 	END SOLD_TO_CONTACT;
553 
554 	PROCEDURE SOLD_TO_ORG IS
555 	BEGIN
556 		IF (p_initial_header_rec.sold_to_org_id = FND_API.G_MISS_NUM
557 		  OR (OE_GLOBALS.Equal(p_initial_header_rec.sold_to_org_id, p_old_header_rec.sold_to_org_id)
558                       AND (p_old_header_rec.header_id IS NOT NULL OR
559                            p_initial_header_rec.sold_to_org_id IS NOT NULL))
560                    ) -- AND condition added to fix 3098878
561 		THEN
562 			p_x_header_rec.sold_to_org_id := FND_API.G_MISS_NUM;
563 		END IF;
564 	END SOLD_TO_ORG;
565 
566         PROCEDURE SOLD_TO_PHONE IS
567         BEGIN
568 		IF (p_initial_header_rec.sold_to_phone_id = FND_API.G_MISS_NUM
569 		  OR (OE_GLOBALS.Equal(p_initial_header_rec.sold_to_phone_id, p_old_header_rec.sold_to_phone_id)
570                       AND (p_old_header_rec.header_id IS NOT NULL OR
571                            p_initial_header_rec.sold_to_phone_id IS NOT NULL))
572                    ) -- AND condition added to fix 3098878
573                 THEN
574                         p_x_header_rec.sold_to_phone_id := FND_API.G_MISS_NUM;
575                 END IF;
576         END SOLD_TO_PHONE;
577         --Start of bug# 14589391
578 	PROCEDURE TAX_EXEMPT IS
579 	BEGIN
580 		IF (p_initial_header_rec.tax_exempt_flag = FND_API.G_MISS_CHAR
581 		  OR (OE_GLOBALS.Equal(p_initial_header_rec.tax_exempt_flag, p_old_header_rec.tax_exempt_flag)
582                       AND (p_old_header_rec.header_id IS NOT NULL OR
583                            p_initial_header_rec.tax_exempt_flag IS NOT NULL))
584                    )
585 		THEN
586 			p_x_header_rec.tax_exempt_flag := FND_API.G_MISS_CHAR;
587 		END IF;
588 	END TAX_EXEMPT;  	--End of bug# 14589391
589 
590 	PROCEDURE TAX_EXEMPT_NUMBER IS
591 	BEGIN
592 		IF (p_initial_header_rec.tax_exempt_number = FND_API.G_MISS_CHAR
593 		  OR (OE_GLOBALS.Equal(p_initial_header_rec.tax_exempt_number, p_old_header_rec.tax_exempt_number)
594                       AND (p_old_header_rec.header_id IS NOT NULL OR
595                            p_initial_header_rec.tax_exempt_number IS NOT NULL))
596                    ) -- AND condition added to fix 3098878
597 		THEN
598 			p_x_header_rec.tax_exempt_number := FND_API.G_MISS_CHAR;
599 		END IF;
600 	END TAX_EXEMPT_NUMBER;
601 
602 	PROCEDURE TAX_EXEMPT_REASON IS
603 	BEGIN
604 		IF (p_initial_header_rec.tax_exempt_reason_code = FND_API.G_MISS_CHAR
605 		  OR (OE_GLOBALS.Equal(p_initial_header_rec.tax_exempt_reason_code, p_old_header_rec.tax_exempt_reason_code)
606                       AND (p_old_header_rec.header_id IS NOT NULL OR
607                            p_initial_header_rec.tax_exempt_reason_code IS NOT NULL))
608                    ) -- AND condition added to fix 3098878
609 		THEN
610                    -- If condition for bug #2892094
611                    IF OE_GLOBALS.G_UI_FLAG THEN
612 			p_x_header_rec.tax_exempt_reason_code := FND_API.G_MISS_CHAR;
613                    END IF;
614 		END IF;
615 	END TAX_EXEMPT_REASON;
616 
617 	PROCEDURE TRANSACTIONAL_CURR IS
618 	BEGIN
619 		IF (p_initial_header_rec.transactional_curr_code = FND_API.G_MISS_CHAR
620 		  OR (OE_GLOBALS.Equal(p_initial_header_rec.transactional_curr_code, p_old_header_rec.transactional_curr_code)
621                       AND (p_old_header_rec.header_id IS NOT NULL OR
622                            p_initial_header_rec.transactional_curr_code IS NOT NULL))
623                    ) -- AND condition added to fix 3098878
624 		THEN
625 			p_x_header_rec.transactional_curr_code := FND_API.G_MISS_CHAR;
626 		END IF;
627 	END TRANSACTIONAL_CURR;
628 
629      PROCEDURE LATEST_SCHEDULE_LIMIT IS
630      BEGIN
631 		IF (p_initial_header_rec.latest_schedule_limit = FND_API.G_MISS_NUM
632 		  OR (OE_GLOBALS.Equal(p_initial_header_rec.latest_schedule_limit, p_old_header_rec.latest_schedule_limit)
633                       AND (p_old_header_rec.header_id IS NOT NULL OR
634                            p_initial_header_rec.latest_schedule_limit IS NOT NULL))
635                    ) -- AND condition added to fix 3098878
636           THEN
637                p_x_header_rec.latest_schedule_limit := FND_API.G_MISS_NUM;
638           END IF;
639      END LATEST_SCHEDULE_LIMIT;
640 
641      PROCEDURE PACKING_INSTRUCTIONS IS -- added for 2665264
642      BEGIN
643 		IF (p_initial_header_rec.packing_instructions = FND_API.G_MISS_CHAR
644 		  OR (OE_GLOBALS.Equal(p_initial_header_rec.packing_instructions, p_old_header_rec.packing_instructions)
645                       AND (p_old_header_rec.header_id IS NOT NULL OR
646                            p_initial_header_rec.packing_instructions IS NOT NULL))
647                    ) -- AND condition added to fix 3098878
648           THEN
649                p_x_header_rec.packing_instructions := FND_API.G_MISS_CHAR;
650           END IF;
651      END PACKING_INSTRUCTIONS;
652 
653      PROCEDURE SHIPPING_INSTRUCTIONS IS -- added for 2766005
654      BEGIN
655 	  IF (p_initial_header_rec.shipping_instructions = FND_API.G_MISS_CHAR
656 		  OR (OE_GLOBALS.Equal(p_initial_header_rec.shipping_instructions, p_old_header_rec.shipping_instructions)
657                       AND (p_old_header_rec.header_id IS NOT NULL OR
658                            p_initial_header_rec.shipping_instructions IS NOT NULL))
659                    ) -- AND condition added to fix 3098878
660           THEN
661                p_x_header_rec.shipping_instructions := FND_API.G_MISS_CHAR;
662           END IF;
663      END SHIPPING_INSTRUCTIONS;
664 
665      -- QUOTING changes
666 
667      PROCEDURE TRANSACTION_PHASE IS
668      BEGIN
669           -- Transaction phase can only be cleared during CREATE operation
670           IF p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
671 		AND (p_initial_header_rec.transaction_phase_code = FND_API.G_MISS_CHAR
672 		  OR (OE_GLOBALS.Equal(p_initial_header_rec.transaction_phase_code, p_old_header_rec.transaction_phase_code)
673                       AND (p_old_header_rec.header_id IS NOT NULL OR
674                            p_initial_header_rec.transaction_phase_code IS NOT NULL))
675                    ) -- 2nd AND condition added to fix 3098878
676           THEN
677                p_x_header_rec.transaction_phase_code := FND_API.G_MISS_CHAR;
678           END IF;
679      END TRANSACTION_PHASE;
680 
681      PROCEDURE SOLD_TO_SITE_USE IS
682      BEGIN
683 	  IF (p_initial_header_rec.sold_to_site_use_id = FND_API.G_MISS_NUM
684 		  OR (OE_GLOBALS.Equal(p_initial_header_rec.sold_to_site_use_id, p_old_header_rec.sold_to_site_use_id)
685                       AND (p_old_header_rec.header_id IS NOT NULL OR
686                            p_initial_header_rec.sold_to_site_use_id IS NOT NULL))
687                    ) -- AND condition added to fix 3098878
688           THEN
689                p_x_header_rec.sold_to_site_use_id := FND_API.G_MISS_NUM;
690           END IF;
691      END SOLD_TO_SITE_USE;
692 
693      PROCEDURE QUOTE_DATE IS
694      BEGIN
695 	  IF (p_initial_header_rec.quote_date = FND_API.G_MISS_DATE
696 		  OR (OE_GLOBALS.Equal(p_initial_header_rec.quote_date, p_old_header_rec.quote_date)
697                       AND (p_old_header_rec.header_id IS NOT NULL OR
698                            p_initial_header_rec.quote_date IS NOT NULL))
699                    ) -- AND condition added to fix 3098878
700                    AND OE_Quote_Util.G_COMPLETE_NEG = 'N'
701 -- bug 3854887
702 		   AND  p_x_header_rec.transaction_phase_code = 'N'
703           THEN
704                p_x_header_rec.quote_date := FND_API.G_MISS_DATE;
705           END IF;
706      END QUOTE_DATE;
707 
708      PROCEDURE ORDERED_DATE IS
709      BEGIN
710 	  IF (p_initial_header_rec.ordered_date = FND_API.G_MISS_DATE
711 		  OR (OE_GLOBALS.Equal(p_initial_header_rec.ordered_date, p_old_header_rec.ordered_date)
712                       AND (p_old_header_rec.header_id IS NOT NULL OR
713                            p_initial_header_rec.ordered_date IS NOT NULL))
714 -- bug 3854887
715 		      AND (p_x_header_rec.transaction_phase_code IS NULL OR
716 			     p_x_header_rec.transaction_phase_code = 'F' OR
717 			     p_x_header_rec.transaction_phase_code =  FND_API.G_MISS_CHAR)
718                    ) -- AND condition added to fix 3098878
719           THEN
720                p_x_header_rec.ordered_date := FND_API.G_MISS_DATE;
721           END IF;
722      END ORDERED_DATE;
723 
724      -- QUOTING changes END
725 
726      --distributed orders
727      PROCEDURE end_customer IS
728      BEGIN
729 	IF (p_initial_header_rec.end_customer_id = FND_API.G_MISS_NUM
730 	    OR OE_GLOBALS.Equal(p_initial_header_rec.end_customer_id
731 				, p_old_header_rec.end_customer_id ))
732 	THEN
733 	 p_x_header_rec.end_customer_id := FND_API.G_MISS_NUM;
734       END IF;
735    END end_customer;
736 
737      PROCEDURE end_customer_contact IS
738      BEGIN
739 	IF (p_initial_header_rec.end_customer_contact_id = FND_API.G_MISS_NUM
740 	    OR OE_GLOBALS.Equal(p_initial_header_rec.end_customer_contact_id
741 				, p_old_header_rec.end_customer_contact_id ))
742 	THEN
743 	 p_x_header_rec.end_customer_contact_id := FND_API.G_MISS_NUM;
744       END IF;
745    END end_customer_contact;
746 
747    PROCEDURE end_customer_site_use IS
748    BEGIN
749       IF (p_initial_header_rec.end_customer_site_use_id = FND_API.G_MISS_NUM
750 	  OR OE_GLOBALS.Equal(p_initial_header_rec.end_customer_site_use_id ,
751 			      p_old_header_rec.end_customer_site_use_id ))
752       THEN
753 	 p_x_header_rec.end_customer_site_use_id := FND_API.G_MISS_NUM;
754       END IF;
755    END end_customer_site_use;
756 
757 --key Transaction dates
758    PROCEDURE order_firmed_date IS
759    BEGIN
760      IF (p_initial_header_rec.order_firmed_date = FND_API.G_MISS_DATE
761 			       OR
762         (OE_GLOBALS.equal(p_initial_header_rec.order_firmed_date  ,p_old_header_rec.order_firmed_date)
763 		AND (p_initial_header_rec.order_firmed_date IS NOT NULL OR p_old_header_rec.order_firmed_date IS NOT NULL))
764            )   THEN
765           p_x_header_rec.order_firmed_date := FND_API.G_MISS_DATE;
766      END IF ;
767    END order_firmed_date;
768  -- end
769        -----START bug 8517526
770  PROCEDURE BLANKET_NUMBER IS
771    BEGIN
772    IF (p_initial_header_rec.blanket_number = FND_API.G_MISS_NUM OR
773         (OE_GLOBAlS.Equal(p_initial_header_rec.blanket_number, p_old_header_rec.blanket_number)
774           AND
775         (p_old_header_rec.header_id IS NOT NULL OR p_initial_header_rec.blanket_number IS NOT NULL))
776        )
777    THEN
778        p_x_header_rec.blanket_number := FND_API.G_MISS_NUM;
779 
780    END IF;
781    END BLANKET_NUMBER;
782  ---END BUG 8517526
783 
784 
785 
786 BEGIN
787 
788 	oe_debug_pub.add('Entering OE_HEADER_UTIL.Clear_Dependent',1);
789 	IF	p_src_attr_tbl.COUNT <> 0 THEN
790 
791 		OE_Dependencies.Mark_Dependent
792 		(p_entity_code     => OE_GLOBALS.G_ENTITY_HEADER,
793 		p_source_attr_tbl => p_src_attr_tbl,
794 		p_dep_attr_tbl    => l_dep_attr_tbl);
795 
796 		FOR I IN 1..l_dep_attr_tbl.COUNT LOOP
797 			IF l_dep_attr_tbl(I) = OE_HEADER_UTIL.G_ACCOUNTING_RULE THEN
798 				ACCOUNTING_RULE;
799 			ELSIF 	l_dep_attr_tbl(I) = OE_HEADER_UTIL.G_ACCOUNTING_RULE_DURATION THEN
800 					ACCOUNTING_RULE_DURATION;
801 			ELSIF 	l_dep_attr_tbl(I) = OE_HEADER_UTIL.G_AGREEMENT THEN
802 					AGREEMENT;
803 			ELSIF 	l_dep_attr_tbl(I) = OE_HEADER_UTIL.G_CONVERSION_RATE THEN
804 					CONVERSION_RATE;
805 			ELSIF 	l_dep_attr_tbl(I) = OE_HEADER_UTIL.G_CONVERSION_RATE_DATE THEN
806 					CONVERSION_RATE_DATE;
807 			ELSIF 	l_dep_attr_tbl(I) = OE_HEADER_UTIL.G_CONVERSION_TYPE THEN
808 					CONVERSION_TYPE;
809 			ELSIF 	l_dep_attr_tbl(I) = OE_HEADER_UTIL.G_CREDIT_CARD_EXPIRATION_DATE THEN
810 					CREDIT_CARD_EXPIRATION_DATE;
811 			ELSIF 	l_dep_attr_tbl(I) = OE_HEADER_UTIL.G_CREDIT_CARD_HOLDER_NAME THEN
812 					CREDIT_CARD_HOLDER_NAME;
813 			ELSIF 	l_dep_attr_tbl(I) = OE_HEADER_UTIL.G_CREDIT_CARD_NUMBER THEN
814 					CREDIT_CARD_NUMBER;
815                         /* Fix Bug # 2297053: Added to clear Credit Card Type */
816 			ELSIF 	l_dep_attr_tbl(I) = OE_HEADER_UTIL.G_CREDIT_CARD THEN
817 					CREDIT_CARD;
818 			ELSIF 	l_dep_attr_tbl(I) = OE_HEADER_UTIL.G_CHECK_NUMBER THEN  --For bug 2692314
819 					CHECK_NUMBER;
820 			ELSIF 	l_dep_attr_tbl(I) = OE_HEADER_UTIL.G_CUST_PO_NUMBER THEN
821 					CUST_PO_NUMBER;
822 			ELSIF 	l_dep_attr_tbl(I) = OE_HEADER_UTIL.G_CUSTOMER_PREFERENCE_SET THEN
823 					CUSTOMER_PREFERENCE_SET_CODE;
824 			ELSIF 	l_dep_attr_tbl(I) = OE_HEADER_UTIL.G_DEFAULT_FULFILLMENT_SET THEN
825 					DEFAULT_FULFILLMENT_SET;
826 			ELSIF 	l_dep_attr_tbl(I) = OE_HEADER_UTIL.G_DELIVER_TO_CONTACT THEN
827 					DELIVER_TO_CONTACT;
828 			ELSIF 	l_dep_attr_tbl(I) = OE_HEADER_UTIL.G_DELIVER_TO_ORG THEN
829 					DELIVER_TO_ORG;
830 			ELSIF 	l_dep_attr_tbl(I) = OE_HEADER_UTIL.G_DEMAND_CLASS THEN
831 					DEMAND_CLASS;
832 			ELSIF 	l_dep_attr_tbl(I) = OE_HEADER_UTIL.G_FOB_POINT THEN
833 					FOB_POINT;
834 			ELSIF 	l_dep_attr_tbl(I) = OE_HEADER_UTIL.G_FREIGHT_TERMS THEN
835 					FREIGHT_TERMS;
836 			ELSIF 	l_dep_attr_tbl(I) = OE_HEADER_UTIL.G_INVOICE_TO_CONTACT THEN
837 					INVOICE_TO_CONTACT;
838 			ELSIF 	l_dep_attr_tbl(I) = OE_HEADER_UTIL.G_INVOICE_TO_ORG THEN
839 					INVOICE_TO_ORG;
840 			ELSIF 	l_dep_attr_tbl(I) = OE_HEADER_UTIL.G_INVOICING_RULE THEN
841 					INVOICING_RULE;
842 			ELSIF 	l_dep_attr_tbl(I) = OE_HEADER_UTIL.G_ORDER_CATEGORY THEN
843 					ORDER_CATEGORY;
844 			ELSIF 	l_dep_attr_tbl(I) = OE_HEADER_UTIL.G_ORDER_DATE_TYPE_CODE THEN
845 					ORDER_DATE_TYPE;
846 			ELSIF 	l_dep_attr_tbl(I) = OE_HEADER_UTIL.G_ORDER_TYPE THEN
847 					ORDER_TYPE;
848 			-- Added the call to the method to clear the payment amount bug 4360599
849 			ELSIF 	l_dep_attr_tbl(I) = OE_HEADER_UTIL.G_PAYMENT_AMOUNT THEN
850 					PAYMENT_AMOUNT;
851 			ELSIF 	l_dep_attr_tbl(I) = OE_HEADER_UTIL.G_PAYMENT_TERM THEN
852 					PAYMENT_TERM;
853 			ELSIF 	l_dep_attr_tbl(I) = OE_HEADER_UTIL.G_PRICE_LIST THEN
854 					PRICE_LIST;
855 			ELSIF 	l_dep_attr_tbl(I) = OE_HEADER_UTIL.G_PRICE_REQUEST_CODE THEN -- PROMOTIONS SEP/01
856 					PRICE_REQUEST_CODE;
857 			ELSIF 	l_dep_attr_tbl(I) = OE_HEADER_UTIL.G_REQUEST_DATE THEN
858 					REQUEST_DATE;
859 			ELSIF 	l_dep_attr_tbl(I) = OE_HEADER_UTIL.G_SALESREP THEN
860 					SALESREP;
861 			ELSIF 	l_dep_attr_tbl(I) = OE_HEADER_UTIL.G_SALES_CHANNEL THEN
862 					SALES_CHANNEL;
863 			ELSIF 	l_dep_attr_tbl(I) = OE_HEADER_UTIL.G_SHIPMENT_PRIORITY THEN
864 					SHIPMENT_PRIORITY;
865 			ELSIF 	l_dep_attr_tbl(I) = OE_HEADER_UTIL.G_SHIPPING_METHOD THEN
866 					SHIPPING_METHOD;
867 			ELSIF 	l_dep_attr_tbl(I) = OE_HEADER_UTIL.G_SHIP_FROM_ORG THEN
868 					SHIP_FROM_ORG;
869 			ELSIF 	l_dep_attr_tbl(I) = OE_HEADER_UTIL.G_SHIP_TOLERANCE_ABOVE THEN
870 					SHIP_TOLERANCE_ABOVE;
871 			ELSIF 	l_dep_attr_tbl(I) = OE_HEADER_UTIL.G_SHIP_TOLERANCE_BELOW THEN
872 					SHIP_TOLERANCE_BELOW;
873 			ELSIF 	l_dep_attr_tbl(I) = OE_HEADER_UTIL.G_SHIP_TO_CONTACT THEN
874 					SHIP_TO_CONTACT;
875 			ELSIF 	l_dep_attr_tbl(I) = OE_HEADER_UTIL.G_SHIP_TO_ORG THEN
876 					SHIP_TO_ORG;
877                         -- Fix bug 1753101: sold to contact dependency code added
878 			ELSIF 	l_dep_attr_tbl(I) = OE_HEADER_UTIL.G_SOLD_TO_CONTACT THEN
879 					SOLD_TO_CONTACT;
880 			ELSIF 	l_dep_attr_tbl(I) = OE_HEADER_UTIL.G_SOLD_TO_ORG THEN
881 					SOLD_TO_ORG;
882 			ELSIF 	l_dep_attr_tbl(I) = OE_HEADER_UTIL.G_SOLD_TO_PHONE THEN
883 					SOLD_TO_PHONE;
884 			ELSIF 	l_dep_attr_tbl(I) = OE_HEADER_UTIL.G_TAX_EXEMPT THEN
885 					TAX_EXEMPT;    -- Bug# 14589391
886 			ELSIF 	l_dep_attr_tbl(I) = OE_HEADER_UTIL.G_TAX_EXEMPT_NUMBER THEN
887 					TAX_EXEMPT_NUMBER;
888 			ELSIF 	l_dep_attr_tbl(I) = OE_HEADER_UTIL.G_TAX_EXEMPT_REASON THEN
889 					TAX_EXEMPT_REASON;
890 			ELSIF 	l_dep_attr_tbl(I) = OE_HEADER_UTIL.G_TRANSACTIONAL_CURR THEN
891 					TRANSACTIONAL_CURR;
892 			ELSIF 	l_dep_attr_tbl(I) = OE_HEADER_UTIL.G_LATEST_SCHEDULE_LIMIT THEN
893 					LATEST_SCHEDULE_LIMIT;
894                         ELSIF   l_dep_attr_tbl(I) = OE_HEADER_UTIL.G_PACKING_INSTRUCTIONS THEN
895                                         PACKING_INSTRUCTIONS;  -- added for 2665264
896                         ELSIF   l_dep_attr_tbl(I) = OE_HEADER_UTIL.G_SHIPPING_INSTRUCTIONS THEN
897                                         SHIPPING_INSTRUCTIONS;  -- added for 2766005
898 
899            -- QUOTING changes
900 			ELSIF 	l_dep_attr_tbl(I) = OE_HEADER_UTIL.G_TRANSACTION_PHASE THEN
901                            IF OE_Code_Control.Code_Release_Level >= '110510' THEN
902 					TRANSACTION_PHASE;
903                            END IF;
904 			ELSIF 	l_dep_attr_tbl(I) = OE_HEADER_UTIL.G_SOLD_TO_SITE_USE THEN
905                            IF OE_Code_Control.Code_Release_Level >= '110510' THEN
906 					SOLD_TO_SITE_USE;
907                            END IF;
908 			ELSIF 	l_dep_attr_tbl(I) = OE_HEADER_UTIL.G_QUOTE_DATE THEN
909                            IF OE_Code_Control.Code_Release_Level >= '110510' THEN
910 					QUOTE_DATE;
911                            END IF;
912 			ELSIF 	l_dep_attr_tbl(I) = OE_HEADER_UTIL.G_ORDERED_DATE THEN
913                            IF OE_Code_Control.Code_Release_Level >= '110510' THEN
914 					ORDERED_DATE;
915                            END IF;
916                         -- QUOTING changes END
917 			-- Distributed orders @
918 			ELSIF l_dep_attr_tbl(I) = OE_HEADER_UTIL.G_END_CUSTOMER THEN
919 			   END_CUSTOMER;
920 			ELSIF l_dep_attr_tbl(I) = OE_HEADER_UTIL.G_END_CUSTOMER_CONTACT THEN
921 			   END_CUSTOMER_CONTACT;
922 			ELSIF l_dep_attr_tbl(I) = OE_HEADER_UTIL.G_END_CUSTOMER_SITE_USE THEN
923 			   END_CUSTOMER_SITE_USE;
924                  	ELSIF l_dep_attr_tbl(I) = OE_HEADER_UTIL.G_ORDER_FIRMED_DATE THEN     --Key Transaction Dates
925                            IF OE_CODE_CONTROL.CODE_RELEASE_LEVEL >= '110509' THEN
926 			      order_firmed_date;
927 			   END IF;
928                         ELSIF l_dep_attr_tbl(I) = OE_HEADER_UTIL.G_BLANKET_NUMBER THEN   ---bug 8517526
929                                BLANKET_NUMBER;      ---bug 8517526
930 		END IF;
931 	END LOOP;
932    END IF;
933 
934 	oe_debug_pub.add('Exiting OE_HEADER_UTIL.Clear_Dependent',1);
935 
936 EXCEPTION
937 
938 	WHEN FND_API.G_EXC_ERROR THEN
939 		RAISE FND_API.G_EXC_ERROR;
940 	WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
941 		RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
942 	WHEN OTHERS THEN
943 		IF 	OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
944 		THEN
945 			OE_MSG_PUB.Add_Exc_Msg
946 			(   G_PKG_NAME
947 			,   'Clear_Dependents'
948 			);
949 		END IF;
950 
951 		oe_debug_pub.add('Error : '||substr(sqlerrm,1,200),1);
952 		RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
953 
954 END Clear_Dependents;
955 
956 FUNCTION G_MISS_OE_AK_HEADER_REC
957 RETURN OE_AK_ORDER_HEADERS_V%ROWTYPE IS
958 	l_rowtype_rec					OE_AK_ORDER_HEADERS_V%ROWTYPE;
959 BEGIN
960 
961 	l_rowtype_rec.ACCOUNTING_RULE_ID			:= FND_API.G_MISS_NUM;
962 	l_rowtype_rec.ACCOUNTING_RULE_DURATION			:= FND_API.G_MISS_NUM;
963 	l_rowtype_rec.AGREEMENT_ID					:= FND_API.G_MISS_NUM;
964 	l_rowtype_rec.ATTRIBUTE1					:= FND_API.G_MISS_CHAR;
965 	l_rowtype_rec.ATTRIBUTE10					:= FND_API.G_MISS_CHAR;
966 	l_rowtype_rec.ATTRIBUTE11					:= FND_API.G_MISS_CHAR;
967 	l_rowtype_rec.ATTRIBUTE12					:= FND_API.G_MISS_CHAR;
968 	l_rowtype_rec.ATTRIBUTE13					:= FND_API.G_MISS_CHAR;
969 	l_rowtype_rec.ATTRIBUTE14					:= FND_API.G_MISS_CHAR;
970 	l_rowtype_rec.ATTRIBUTE15					:= FND_API.G_MISS_CHAR;
971 	l_rowtype_rec.ATTRIBUTE16			  := FND_API.G_MISS_CHAR;   --For bug 2184255
972 	l_rowtype_rec.ATTRIBUTE17					:= FND_API.G_MISS_CHAR;
973 	l_rowtype_rec.ATTRIBUTE18					:= FND_API.G_MISS_CHAR;
974 	l_rowtype_rec.ATTRIBUTE19					:= FND_API.G_MISS_CHAR;
975 	l_rowtype_rec.ATTRIBUTE2					:= FND_API.G_MISS_CHAR;
976 	l_rowtype_rec.ATTRIBUTE20					:= FND_API.G_MISS_CHAR;
977 	l_rowtype_rec.ATTRIBUTE3					:= FND_API.G_MISS_CHAR;
978 	l_rowtype_rec.ATTRIBUTE4					:= FND_API.G_MISS_CHAR;
979 	l_rowtype_rec.ATTRIBUTE5					:= FND_API.G_MISS_CHAR;
980 	l_rowtype_rec.ATTRIBUTE6					:= FND_API.G_MISS_CHAR;
981 	l_rowtype_rec.ATTRIBUTE7					:= FND_API.G_MISS_CHAR;
982 	l_rowtype_rec.ATTRIBUTE8					:= FND_API.G_MISS_CHAR;
983 	l_rowtype_rec.ATTRIBUTE9					:= FND_API.G_MISS_CHAR;
984         l_rowtype_rec.BLANKET_NUMBER                                    := FND_API.G_MISS_NUM;
985 	l_rowtype_rec.BOOKED_FLAG					:= FND_API.G_MISS_CHAR;
986 	l_rowtype_rec.BOOKED_DATE					:= FND_API.G_MISS_DATE;
987 	l_rowtype_rec.CANCELLED_FLAG				:= FND_API.G_MISS_CHAR;
988 	l_rowtype_rec.CHANGE_COMMENTS				:= FND_API.G_MISS_CHAR;
989 	l_rowtype_rec.CHANGE_REASON					:= FND_API.G_MISS_CHAR;
990 	l_rowtype_rec.CHECK_NUMBER					:= FND_API.G_MISS_CHAR;
991 	l_rowtype_rec.CONTEXT						:= FND_API.G_MISS_CHAR;
992 	l_rowtype_rec.CONVERSION_RATE				:= FND_API.G_MISS_NUM;
993 	l_rowtype_rec.CONVERSION_RATE_DATE			:= FND_API.G_MISS_DATE;
994 	l_rowtype_rec.CONVERSION_TYPE_CODE			:= FND_API.G_MISS_CHAR;
995 	l_rowtype_rec.CUSTOMER_PREFERENCE_SET_CODE	:= FND_API.G_MISS_CHAR;
996 	l_rowtype_rec.CREATED_BY					:= FND_API.G_MISS_NUM;
997 	l_rowtype_rec.CREATION_DATE					:= FND_API.G_MISS_DATE;
998 	l_rowtype_rec.CREDIT_CARD_APPROVAL_CODE		:= FND_API.G_MISS_CHAR;
999 	l_rowtype_rec.CREDIT_CARD_CODE				:= FND_API.G_MISS_CHAR;
1000 	l_rowtype_rec.CREDIT_CARD_EXPIRATION_DATE	:= FND_API.G_MISS_DATE;
1001 	l_rowtype_rec.CREDIT_CARD_APPROVAL_DATE		:= FND_API.G_MISS_DATE;
1002 	l_rowtype_rec.CREDIT_CARD_HOLDER_NAME		:= FND_API.G_MISS_CHAR;
1003 	l_rowtype_rec.CREDIT_CARD_NUMBER			:= FND_API.G_MISS_CHAR;
1004 	l_rowtype_rec.CUST_PO_NUMBER				:= FND_API.G_MISS_CHAR;
1005         l_rowtype_rec.DEFAULT_FULFILLMENT_SET                   := FND_API.G_MISS_CHAR;
1006 	l_rowtype_rec.DB_FLAG					:= FND_API.G_MISS_CHAR;
1007 	l_rowtype_rec.DELIVER_TO_CONTACT_ID			:= FND_API.G_MISS_NUM;
1008 	l_rowtype_rec.DELIVER_TO_ORG_ID				:= FND_API.G_MISS_NUM;
1009 	l_rowtype_rec.DEMAND_CLASS_CODE				:= FND_API.G_MISS_CHAR;
1010 	l_rowtype_rec.EARLIEST_SCHEDULE_LIMIT		:= FND_API.G_MISS_NUM;
1011 	l_rowtype_rec.EXPIRATION_DATE				:= FND_API.G_MISS_DATE;
1012 	l_rowtype_rec.FIRST_ACK_CODE				:= FND_API.G_MISS_CHAR;
1013 	l_rowtype_rec.FIRST_ACK_DATE				:= FND_API.G_MISS_DATE;
1014 	l_rowtype_rec.FOB_POINT_CODE				:= FND_API.G_MISS_CHAR;
1015 	l_rowtype_rec.FREIGHT_CARRIER_CODE			:= FND_API.G_MISS_CHAR;
1016 	l_rowtype_rec.FREIGHT_TERMS_CODE			:= FND_API.G_MISS_CHAR;
1017         l_rowtype_rec.FULFILLMENT_SET_NAME                      := FND_API.G_MISS_CHAR;
1018 	l_rowtype_rec.GLOBAL_ATTRIBUTE1				:= FND_API.G_MISS_CHAR;
1019 	l_rowtype_rec.GLOBAL_ATTRIBUTE10			:= FND_API.G_MISS_CHAR;
1020 	l_rowtype_rec.GLOBAL_ATTRIBUTE11			:= FND_API.G_MISS_CHAR;
1021 	l_rowtype_rec.GLOBAL_ATTRIBUTE12			:= FND_API.G_MISS_CHAR;
1022 	l_rowtype_rec.GLOBAL_ATTRIBUTE13			:= FND_API.G_MISS_CHAR;
1023 	l_rowtype_rec.GLOBAL_ATTRIBUTE14			:= FND_API.G_MISS_CHAR;
1024 	l_rowtype_rec.GLOBAL_ATTRIBUTE15			:= FND_API.G_MISS_CHAR;
1025 	l_rowtype_rec.GLOBAL_ATTRIBUTE16			:= FND_API.G_MISS_CHAR;
1026 	l_rowtype_rec.GLOBAL_ATTRIBUTE17			:= FND_API.G_MISS_CHAR;
1027 	l_rowtype_rec.GLOBAL_ATTRIBUTE18			:= FND_API.G_MISS_CHAR;
1028 	l_rowtype_rec.GLOBAL_ATTRIBUTE19			:= FND_API.G_MISS_CHAR;
1029 	l_rowtype_rec.GLOBAL_ATTRIBUTE2				:= FND_API.G_MISS_CHAR;
1030 	l_rowtype_rec.GLOBAL_ATTRIBUTE20			:= FND_API.G_MISS_CHAR;
1031 	l_rowtype_rec.GLOBAL_ATTRIBUTE3				:= FND_API.G_MISS_CHAR;
1032 	l_rowtype_rec.GLOBAL_ATTRIBUTE4				:= FND_API.G_MISS_CHAR;
1033 	l_rowtype_rec.GLOBAL_ATTRIBUTE5				:= FND_API.G_MISS_CHAR;
1034 	l_rowtype_rec.GLOBAL_ATTRIBUTE6				:= FND_API.G_MISS_CHAR;
1035 	l_rowtype_rec.GLOBAL_ATTRIBUTE7				:= FND_API.G_MISS_CHAR;
1036 	l_rowtype_rec.GLOBAL_ATTRIBUTE8				:= FND_API.G_MISS_CHAR;
1037 	l_rowtype_rec.GLOBAL_ATTRIBUTE9				:= FND_API.G_MISS_CHAR;
1038 	l_rowtype_rec.GLOBAL_ATTRIBUTE_CATEGORY		:= FND_API.G_MISS_CHAR;
1039 	l_rowtype_rec.HEADER_ID						:= FND_API.G_MISS_NUM;
1040 	l_rowtype_rec.INVOICE_TO_CONTACT_ID			:= FND_API.G_MISS_NUM;
1041 	l_rowtype_rec.INVOICE_TO_ORG_ID				:= FND_API.G_MISS_NUM;
1042 	l_rowtype_rec.INVOICING_RULE_ID				:= FND_API.G_MISS_NUM;
1043 	l_rowtype_rec.LAST_ACK_CODE					:= FND_API.G_MISS_CHAR;
1044 	l_rowtype_rec.LAST_ACK_DATE					:= FND_API.G_MISS_DATE;
1045 	l_rowtype_rec.LAST_UPDATED_BY				:= FND_API.G_MISS_NUM;
1046 	l_rowtype_rec.LAST_UPDATE_DATE				:= FND_API.G_MISS_DATE;
1047 	l_rowtype_rec.LAST_UPDATE_LOGIN				:= FND_API.G_MISS_NUM;
1048 	l_rowtype_rec.LATEST_SCHEDULE_LIMIT			:= FND_API.G_MISS_NUM;
1049         l_rowtype_rec.LINE_SET_NAME                             := FND_API.G_MISS_CHAR;
1050 	l_rowtype_rec.OPEN_FLAG						:= FND_API.G_MISS_CHAR;
1051 	l_rowtype_rec.OPERATION						:= FND_API.G_MISS_CHAR;
1052 	l_rowtype_rec.ORDERED_DATE					:= FND_API.G_MISS_DATE;
1053 	l_rowtype_rec.ORDER_DATE_TYPE_CODE			:= FND_API.G_MISS_CHAR;
1054 	l_rowtype_rec.ORDER_NUMBER					:= FND_API.G_MISS_NUM;
1055 	l_rowtype_rec.ORDER_SOURCE_ID				:= FND_API.G_MISS_NUM;
1056 	l_rowtype_rec.ORDER_TYPE_ID					:= FND_API.G_MISS_NUM;
1057 	l_rowtype_rec.ORDER_CATEGORY_CODE 			:= FND_API.G_MISS_CHAR;
1058 	l_rowtype_rec.ORG_ID						:= FND_API.G_MISS_NUM;
1059 	l_rowtype_rec.ORIG_SYS_DOCUMENT_REF			:= FND_API.G_MISS_CHAR;
1060 	l_rowtype_rec.PACKING_INSTRUCTIONS			:= FND_API.G_MISS_CHAR;
1061 	l_rowtype_rec.PARTIAL_SHIPMENTS_ALLOWED		:= FND_API.G_MISS_CHAR;
1062 	l_rowtype_rec.PAYMENT_AMOUNT				:= FND_API.G_MISS_NUM;
1063 	l_rowtype_rec.PAYMENT_TERM_ID				:= FND_API.G_MISS_NUM;
1064 	l_rowtype_rec.PAYMENT_TYPE_CODE				:= FND_API.G_MISS_CHAR;
1065 	l_rowtype_rec.PRICE_LIST_ID					:= FND_API.G_MISS_NUM;
1066 	l_rowtype_rec.PRICE_REQUEST_CODE			:= FND_API.G_MISS_CHAR; -- PROMOTIONS SEP/01
1067 	l_rowtype_rec.PRICING_DATE					:= FND_API.G_MISS_DATE;
1068 	l_rowtype_rec.PROGRAM_APPLICATION_ID		:= FND_API.G_MISS_NUM;
1069 	l_rowtype_rec.PROGRAM_ID					:= FND_API.G_MISS_NUM;
1070 	l_rowtype_rec.PROGRAM_UPDATE_DATE			:= FND_API.G_MISS_DATE;
1071 	l_rowtype_rec.REQUEST_DATE					:= FND_API.G_MISS_DATE;
1072 	l_rowtype_rec.REQUEST_ID					:= FND_API.G_MISS_NUM;
1073 	l_rowtype_rec.RETURN_REASON_CODE			:= FND_API.G_MISS_CHAR;
1074 	l_rowtype_rec.upgraded_flag		          := FND_API.G_MISS_CHAR;
1075 	l_rowtype_rec.RETURN_STATUS					:= FND_API.G_MISS_CHAR;
1076 	l_rowtype_rec.SALESREP_ID					:= FND_API.G_MISS_NUM;
1077 	l_rowtype_rec.SALES_CHANNEL_CODE				:= FND_API.G_MISS_CHAR;
1078 	l_rowtype_rec.SHIPMENT_PRIORITY_CODE		:= FND_API.G_MISS_CHAR;
1079 	l_rowtype_rec.SHIPPING_INSTRUCTIONS			:= FND_API.G_MISS_CHAR;
1080 	l_rowtype_rec.SHIPPING_METHOD_CODE			:= FND_API.G_MISS_CHAR;
1081 	l_rowtype_rec.SHIP_FROM_ORG_ID				:= FND_API.G_MISS_NUM;
1082 	l_rowtype_rec.SHIP_TOLERANCE_ABOVE			:= FND_API.G_MISS_NUM;
1083 	l_rowtype_rec.SHIP_TOLERANCE_BELOW			:= FND_API.G_MISS_NUM;
1084 	l_rowtype_rec.SHIP_TO_CONTACT_ID			:= FND_API.G_MISS_NUM;
1085 	l_rowtype_rec.SHIP_TO_ORG_ID				:= FND_API.G_MISS_NUM;
1086 	l_rowtype_rec.SOLD_FROM_ORG_ID				:= FND_API.G_MISS_NUM;
1087 	l_rowtype_rec.SOLD_TO_CONTACT_ID			:= FND_API.G_MISS_NUM;
1088 	l_rowtype_rec.SOLD_TO_ORG_ID				:= FND_API.G_MISS_NUM;
1089 	l_rowtype_rec.SOURCE_DOCUMENT_ID			:= FND_API.G_MISS_NUM;
1090 	l_rowtype_rec.SOURCE_DOCUMENT_TYPE_ID		:= FND_API.G_MISS_NUM;
1091 	l_rowtype_rec.TAX_EXEMPT_FLAG				:= FND_API.G_MISS_CHAR;
1092 	l_rowtype_rec.TAX_EXEMPT_NUMBER				:= FND_API.G_MISS_CHAR;
1093 	l_rowtype_rec.TAX_EXEMPT_REASON_CODE		:= FND_API.G_MISS_CHAR;
1094 	l_rowtype_rec.TAX_POINT_CODE				:= FND_API.G_MISS_CHAR;
1095 	l_rowtype_rec.TRANSACTIONAL_CURR_CODE		:= FND_API.G_MISS_CHAR;
1096 	l_rowtype_rec.VERSION_NUMBER				:= FND_API.G_MISS_NUM;
1097 	l_rowtype_rec.TP_ATTRIBUTE1					:= FND_API.G_MISS_CHAR;
1098 	l_rowtype_rec.TP_ATTRIBUTE10				:= FND_API.G_MISS_CHAR;
1099 	l_rowtype_rec.TP_ATTRIBUTE11				:= FND_API.G_MISS_CHAR;
1100 	l_rowtype_rec.TP_ATTRIBUTE12				:= FND_API.G_MISS_CHAR;
1101 	l_rowtype_rec.TP_ATTRIBUTE13				:= FND_API.G_MISS_CHAR;
1102 	l_rowtype_rec.TP_ATTRIBUTE14				:= FND_API.G_MISS_CHAR;
1103 	l_rowtype_rec.TP_ATTRIBUTE15				:= FND_API.G_MISS_CHAR;
1104 	l_rowtype_rec.TP_ATTRIBUTE2					:= FND_API.G_MISS_CHAR;
1105 	l_rowtype_rec.TP_ATTRIBUTE3					:= FND_API.G_MISS_CHAR;
1106 	l_rowtype_rec.TP_ATTRIBUTE4					:= FND_API.G_MISS_CHAR;
1107 	l_rowtype_rec.TP_ATTRIBUTE5					:= FND_API.G_MISS_CHAR;
1108 	l_rowtype_rec.TP_ATTRIBUTE6					:= FND_API.G_MISS_CHAR;
1109 	l_rowtype_rec.TP_ATTRIBUTE7					:= FND_API.G_MISS_CHAR;
1110 	l_rowtype_rec.TP_ATTRIBUTE8					:= FND_API.G_MISS_CHAR;
1111 	l_rowtype_rec.TP_ATTRIBUTE9					:= FND_API.G_MISS_CHAR;
1112 	l_rowtype_rec.TP_CONTEXT       				:= FND_API.G_MISS_CHAR;
1113 
1114     --QUOTING changes
1115 	l_rowtype_rec.TRANSACTION_PHASE_CODE       		:= FND_API.G_MISS_CHAR;
1116 	l_rowtype_rec.USER_STATUS_CODE       			:= FND_API.G_MISS_CHAR;
1117 	l_rowtype_rec.QUOTE_NUMBER       			:= FND_API.G_MISS_NUM;
1118 	l_rowtype_rec.QUOTE_DATE     				:= FND_API.G_MISS_DATE;
1119 	l_rowtype_rec.SALES_DOCUMENT_NAME       		:= FND_API.G_MISS_CHAR;
1120 	l_rowtype_rec.SOLD_TO_SITE_USE_ID       		:= FND_API.G_MISS_NUM;
1121 	l_rowtype_rec.SOURCE_DOCUMENT_VERSION_NUMBER   		:= FND_API.G_MISS_NUM;
1122 	l_rowtype_rec.DRAFT_SUBMITTED_FLAG       		:= FND_API.G_MISS_CHAR;
1123         -- QUOTING changes END
1124         --Key Transaction Dates
1125         l_rowtype_rec.order_firmed_date                         := FND_API.G_MISS_DATE;
1126 
1127 	RETURN l_rowtype_rec;
1128 
1129 EXCEPTION
1130 
1131 	WHEN OTHERS THEN
1132 		IF 	OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
1133 		THEN
1134 			OE_MSG_PUB.Add_Exc_Msg
1135 			(   G_PKG_NAME
1136 			,   'G_MISS_OE_AK_HEADER_REC'
1137 			);
1138 		END IF;
1139 		RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1140 
1141 END G_MISS_OE_AK_HEADER_REC;
1142 
1143 PROCEDURE API_Rec_To_Rowtype_Rec
1144 (   p_HEADER_rec                    IN  OE_Order_PUB.HEADER_Rec_Type
1145 ,   x_rowtype_rec                   IN OUT NOCOPY OE_AK_ORDER_HEADERS_V%ROWTYPE
1146 ) IS
1147 BEGIN
1148 
1149 	x_rowtype_rec.ACCOUNTING_RULE_ID       := p_header_rec.ACCOUNTING_RULE_ID;
1150 	x_rowtype_rec.ACCOUNTING_RULE_DURATION := p_header_rec.ACCOUNTING_RULE_DURATION;
1151 	x_rowtype_rec.AGREEMENT_ID             := p_header_rec.AGREEMENT_ID;
1152 	x_rowtype_rec.ATTRIBUTE1               := p_header_rec.ATTRIBUTE1;
1153 	x_rowtype_rec.ATTRIBUTE10              := p_header_rec.ATTRIBUTE10;
1154 	x_rowtype_rec.ATTRIBUTE11              := p_header_rec.ATTRIBUTE11;
1155 	x_rowtype_rec.ATTRIBUTE12              := p_header_rec.ATTRIBUTE12;
1156 	x_rowtype_rec.ATTRIBUTE13              := p_header_rec.ATTRIBUTE13;
1157 	x_rowtype_rec.ATTRIBUTE14              := p_header_rec.ATTRIBUTE14;
1158 	x_rowtype_rec.ATTRIBUTE15              := p_header_rec.ATTRIBUTE15;
1159 	x_rowtype_rec.ATTRIBUTE16              := p_header_rec.ATTRIBUTE16;   --For bug 2184255
1160 	x_rowtype_rec.ATTRIBUTE17              := p_header_rec.ATTRIBUTE17;
1161 	x_rowtype_rec.ATTRIBUTE18              := p_header_rec.ATTRIBUTE18;
1162 	x_rowtype_rec.ATTRIBUTE19              := p_header_rec.ATTRIBUTE19;
1163 	x_rowtype_rec.ATTRIBUTE2               := p_header_rec.ATTRIBUTE2;
1164 	x_rowtype_rec.ATTRIBUTE20              := p_header_rec.ATTRIBUTE20;
1165 	x_rowtype_rec.ATTRIBUTE3               := p_header_rec.ATTRIBUTE3;
1166 	x_rowtype_rec.ATTRIBUTE4               := p_header_rec.ATTRIBUTE4;
1167 	x_rowtype_rec.ATTRIBUTE5               := p_header_rec.ATTRIBUTE5;
1168 	x_rowtype_rec.ATTRIBUTE6               := p_header_rec.ATTRIBUTE6;
1169 	x_rowtype_rec.ATTRIBUTE7               := p_header_rec.ATTRIBUTE7;
1170 	x_rowtype_rec.ATTRIBUTE8               := p_header_rec.ATTRIBUTE8;
1171 	x_rowtype_rec.ATTRIBUTE9               := p_header_rec.ATTRIBUTE9;
1172 	x_rowtype_rec.upgraded_flag            := p_header_rec.upgraded_flag;
1173         x_rowtype_rec.BLANKET_NUMBER           := p_header_rec.BLANKET_NUMBER;
1174 	x_rowtype_rec.BOOKED_FLAG              := p_header_rec.BOOKED_FLAG;
1175 	x_rowtype_rec.BOOKED_DATE              := p_header_rec.BOOKED_DATE;
1176 	x_rowtype_rec.CANCELLED_FLAG           := p_header_rec.CANCELLED_FLAG;
1177 	x_rowtype_rec.CHANGE_COMMENTS          := p_header_rec.CHANGE_COMMENTS;
1178 	x_rowtype_rec.CHANGE_REASON            := p_header_rec.CHANGE_REASON;
1179 	x_rowtype_rec.CHECK_NUMBER             := p_header_rec.CHECK_NUMBER;
1180 	x_rowtype_rec.CONTEXT                  := p_header_rec.CONTEXT;
1181 	x_rowtype_rec.CONVERSION_RATE          := p_header_rec.CONVERSION_RATE;
1182 	x_rowtype_rec.CONVERSION_RATE_DATE     := p_header_rec.CONVERSION_RATE_DATE;
1183 	x_rowtype_rec.CONVERSION_TYPE_CODE     := p_header_rec.CONVERSION_TYPE_CODE;
1184 	x_rowtype_rec.CUSTOMER_PREFERENCE_SET_CODE := p_header_rec.CUSTOMER_PREFERENCE_SET_CODE;
1185 	x_rowtype_rec.CREATED_BY               := p_header_rec.CREATED_BY;
1186 	x_rowtype_rec.CREATION_DATE            := p_header_rec.CREATION_DATE;
1187 	x_rowtype_rec.CREDIT_CARD_APPROVAL_CODE := p_header_rec.CREDIT_CARD_APPROVAL_CODE;
1188 	x_rowtype_rec.CREDIT_CARD_CODE         := p_header_rec.CREDIT_CARD_CODE;
1189 	x_rowtype_rec.CREDIT_CARD_EXPIRATION_DATE := p_header_rec.CREDIT_CARD_EXPIRATION_DATE;
1190 	x_rowtype_rec.CREDIT_CARD_APPROVAL_DATE := p_header_rec.CREDIT_CARD_APPROVAL_DATE;
1191 	x_rowtype_rec.CREDIT_CARD_HOLDER_NAME  := p_header_rec.CREDIT_CARD_HOLDER_NAME;
1192 	x_rowtype_rec.CREDIT_CARD_NUMBER       := p_header_rec.CREDIT_CARD_NUMBER;
1193 	x_rowtype_rec.CUST_PO_NUMBER           := p_header_rec.CUST_PO_NUMBER;
1194         x_rowtype_rec.DEFAULT_FULFILLMENT_SET := p_header_rec.DEFAULT_FULFILLMENT_SET;
1195 	x_rowtype_rec.DB_FLAG                  := p_header_rec.DB_FLAG;
1196 	x_rowtype_rec.DELIVER_TO_CONTACT_ID    := p_header_rec.DELIVER_TO_CONTACT_ID;
1197 	x_rowtype_rec.DELIVER_TO_ORG_ID        := p_header_rec.DELIVER_TO_ORG_ID;
1198 	x_rowtype_rec.DEMAND_CLASS_CODE        := p_header_rec.DEMAND_CLASS_CODE;
1199 	x_rowtype_rec.EARLIEST_SCHEDULE_LIMIT  := p_header_rec.EARLIEST_SCHEDULE_LIMIT;
1200 	x_rowtype_rec.EXPIRATION_DATE          := p_header_rec.EXPIRATION_DATE;
1201 	x_rowtype_rec.FIRST_ACK_CODE           := p_header_rec.FIRST_ACK_CODE;
1202 	x_rowtype_rec.FIRST_ACK_DATE           := p_header_rec.FIRST_ACK_DATE;
1203 	x_rowtype_rec.FOB_POINT_CODE           := p_header_rec.FOB_POINT_CODE;
1204 	x_rowtype_rec.FREIGHT_CARRIER_CODE     := p_header_rec.FREIGHT_CARRIER_CODE;
1205 	x_rowtype_rec.FREIGHT_TERMS_CODE       := p_header_rec.FREIGHT_TERMS_CODE;
1206         x_rowtype_rec.FULFILLMENT_SET_NAME     := p_header_rec.FULFILLMENT_SET_NAME;
1207 	x_rowtype_rec.GLOBAL_ATTRIBUTE1        := p_header_rec.GLOBAL_ATTRIBUTE1;
1208 	x_rowtype_rec.GLOBAL_ATTRIBUTE10       := p_header_rec.GLOBAL_ATTRIBUTE10;
1209 	x_rowtype_rec.GLOBAL_ATTRIBUTE11       := p_header_rec.GLOBAL_ATTRIBUTE11;
1210 	x_rowtype_rec.GLOBAL_ATTRIBUTE12       := p_header_rec.GLOBAL_ATTRIBUTE12;
1211 	x_rowtype_rec.GLOBAL_ATTRIBUTE13       := p_header_rec.GLOBAL_ATTRIBUTE13;
1212 	x_rowtype_rec.GLOBAL_ATTRIBUTE14       := p_header_rec.GLOBAL_ATTRIBUTE14;
1213 	x_rowtype_rec.GLOBAL_ATTRIBUTE15       := p_header_rec.GLOBAL_ATTRIBUTE15;
1214 	x_rowtype_rec.GLOBAL_ATTRIBUTE16       := p_header_rec.GLOBAL_ATTRIBUTE16;
1215 	x_rowtype_rec.GLOBAL_ATTRIBUTE17       := p_header_rec.GLOBAL_ATTRIBUTE17;
1216 	x_rowtype_rec.GLOBAL_ATTRIBUTE18       := p_header_rec.GLOBAL_ATTRIBUTE18;
1217 	x_rowtype_rec.GLOBAL_ATTRIBUTE19       := p_header_rec.GLOBAL_ATTRIBUTE19;
1218 	x_rowtype_rec.GLOBAL_ATTRIBUTE2        := p_header_rec.GLOBAL_ATTRIBUTE2;
1219 	x_rowtype_rec.GLOBAL_ATTRIBUTE20       := p_header_rec.GLOBAL_ATTRIBUTE20;
1220 	x_rowtype_rec.GLOBAL_ATTRIBUTE3        := p_header_rec.GLOBAL_ATTRIBUTE3;
1221 	x_rowtype_rec.GLOBAL_ATTRIBUTE4        := p_header_rec.GLOBAL_ATTRIBUTE4;
1222 	x_rowtype_rec.GLOBAL_ATTRIBUTE5        := p_header_rec.GLOBAL_ATTRIBUTE5;
1223 	x_rowtype_rec.GLOBAL_ATTRIBUTE6        := p_header_rec.GLOBAL_ATTRIBUTE6;
1224 	x_rowtype_rec.GLOBAL_ATTRIBUTE7        := p_header_rec.GLOBAL_ATTRIBUTE7;
1225 	x_rowtype_rec.GLOBAL_ATTRIBUTE8        := p_header_rec.GLOBAL_ATTRIBUTE8;
1226 	x_rowtype_rec.GLOBAL_ATTRIBUTE9        := p_header_rec.GLOBAL_ATTRIBUTE9;
1227 	x_rowtype_rec.GLOBAL_ATTRIBUTE_CATEGORY := p_header_rec.GLOBAL_ATTRIBUTE_CATEGORY;
1228 	x_rowtype_rec.HEADER_ID                := p_header_rec.HEADER_ID;
1229 	x_rowtype_rec.INVOICE_TO_CONTACT_ID    := p_header_rec.INVOICE_TO_CONTACT_ID;
1230 	x_rowtype_rec.INVOICE_TO_ORG_ID        := p_header_rec.INVOICE_TO_ORG_ID;
1231 	x_rowtype_rec.INVOICING_RULE_ID        := p_header_rec.INVOICING_RULE_ID;
1232 	x_rowtype_rec.LAST_ACK_CODE            := p_header_rec.LAST_ACK_CODE;
1233 	x_rowtype_rec.LAST_ACK_DATE            := p_header_rec.LAST_ACK_DATE;
1234 	x_rowtype_rec.LAST_UPDATED_BY          := p_header_rec.LAST_UPDATED_BY;
1235 	x_rowtype_rec.LAST_UPDATE_DATE         := p_header_rec.LAST_UPDATE_DATE;
1236 	x_rowtype_rec.LAST_UPDATE_LOGIN        := p_header_rec.LAST_UPDATE_LOGIN;
1237 	x_rowtype_rec.LATEST_SCHEDULE_LIMIT    := p_header_rec.LATEST_SCHEDULE_LIMIT;
1238         x_rowtype_rec.LINE_SET_NAME            := p_header_rec.LINE_SET_NAME;
1239 	x_rowtype_rec.OPEN_FLAG                := p_header_rec.OPEN_FLAG;
1240 	x_rowtype_rec.OPERATION                := p_header_rec.OPERATION;
1241 	x_rowtype_rec.ORDERED_DATE             := p_header_rec.ORDERED_DATE;
1242 	x_rowtype_rec.ORDER_DATE_TYPE_CODE     := p_header_rec.ORDER_DATE_TYPE_CODE;
1243 	x_rowtype_rec.ORDER_NUMBER             := p_header_rec.ORDER_NUMBER;
1244 	x_rowtype_rec.ORDER_SOURCE_ID          := p_header_rec.ORDER_SOURCE_ID;
1245 	x_rowtype_rec.ORDER_TYPE_ID            := p_header_rec.ORDER_TYPE_ID;
1246 	x_rowtype_rec.ORDER_CATEGORY_CODE      := p_header_rec.ORDER_CATEGORY_CODE;
1247 	x_rowtype_rec.ORG_ID                   := p_header_rec.ORG_ID;
1248 	x_rowtype_rec.ORIG_SYS_DOCUMENT_REF    := p_header_rec.ORIG_SYS_DOCUMENT_REF;
1249 	x_rowtype_rec.PACKING_INSTRUCTIONS     := p_header_rec.PACKING_INSTRUCTIONS;
1250 	x_rowtype_rec.PARTIAL_SHIPMENTS_ALLOWED := p_header_rec.PARTIAL_SHIPMENTS_ALLOWED;
1251 	x_rowtype_rec.PAYMENT_AMOUNT           := p_header_rec.PAYMENT_AMOUNT;
1252 	x_rowtype_rec.PAYMENT_TERM_ID          := p_header_rec.PAYMENT_TERM_ID;
1253 	x_rowtype_rec.PAYMENT_TYPE_CODE        := p_header_rec.PAYMENT_TYPE_CODE;
1254 	x_rowtype_rec.PRICE_LIST_ID            := p_header_rec.PRICE_LIST_ID;
1255 	x_rowtype_rec.PRICE_REQUEST_CODE       := p_header_rec.PRICE_REQUEST_CODE; -- PROMOTIONS SEP/01
1256 	x_rowtype_rec.PRICING_DATE             := p_header_rec.PRICING_DATE;
1257 	x_rowtype_rec.PROGRAM_APPLICATION_ID   := p_header_rec.PROGRAM_APPLICATION_ID;
1258 	x_rowtype_rec.PROGRAM_ID               := p_header_rec.PROGRAM_ID;
1259 	x_rowtype_rec.PROGRAM_UPDATE_DATE      := p_header_rec.PROGRAM_UPDATE_DATE;
1260 	x_rowtype_rec.REQUEST_DATE             := p_header_rec.REQUEST_DATE;
1261 	x_rowtype_rec.REQUEST_ID               := p_header_rec.REQUEST_ID;
1262 	x_rowtype_rec.RETURN_REASON_CODE       := p_header_rec.RETURN_REASON_CODE;
1263 	x_rowtype_rec.RETURN_STATUS            := p_header_rec.RETURN_STATUS;
1264 	x_rowtype_rec.SALESREP_ID              := p_header_rec.SALESREP_ID;
1265 	x_rowtype_rec.SALES_CHANNEL_CODE       := p_header_rec.SALES_CHANNEL_CODE;
1266 	x_rowtype_rec.SHIPMENT_PRIORITY_CODE   := p_header_rec.SHIPMENT_PRIORITY_CODE;
1267 	x_rowtype_rec.SHIPPING_INSTRUCTIONS    := p_header_rec.SHIPPING_INSTRUCTIONS;
1268 	x_rowtype_rec.SHIPPING_METHOD_CODE     := p_header_rec.SHIPPING_METHOD_CODE;
1269 	x_rowtype_rec.SHIP_FROM_ORG_ID         := p_header_rec.SHIP_FROM_ORG_ID;
1270 	x_rowtype_rec.SHIP_TOLERANCE_ABOVE     := p_header_rec.SHIP_TOLERANCE_ABOVE;
1271 	x_rowtype_rec.SHIP_TOLERANCE_BELOW     := p_header_rec.SHIP_TOLERANCE_BELOW;
1272 	x_rowtype_rec.SHIP_TO_CONTACT_ID       := p_header_rec.SHIP_TO_CONTACT_ID;
1273 	x_rowtype_rec.SHIP_TO_ORG_ID           := p_header_rec.SHIP_TO_ORG_ID;
1274 	x_rowtype_rec.SOLD_FROM_ORG_ID         := p_header_rec.SOLD_FROM_ORG_ID;
1275 	x_rowtype_rec.SOLD_TO_CONTACT_ID       := p_header_rec.SOLD_TO_CONTACT_ID;
1276 	x_rowtype_rec.SOLD_TO_ORG_ID           := p_header_rec.SOLD_TO_ORG_ID;
1277 	x_rowtype_rec.SOURCE_DOCUMENT_ID       := p_header_rec.SOURCE_DOCUMENT_ID;
1278 	x_rowtype_rec.SOURCE_DOCUMENT_TYPE_ID  := p_header_rec.SOURCE_DOCUMENT_TYPE_ID;
1279 	x_rowtype_rec.TAX_EXEMPT_FLAG          := p_header_rec.TAX_EXEMPT_FLAG;
1280 	x_rowtype_rec.TAX_EXEMPT_NUMBER        := p_header_rec.TAX_EXEMPT_NUMBER;
1281 	x_rowtype_rec.TAX_EXEMPT_REASON_CODE   := p_header_rec.TAX_EXEMPT_REASON_CODE;
1282 	x_rowtype_rec.TAX_POINT_CODE           := p_header_rec.TAX_POINT_CODE;
1283 	x_rowtype_rec.TRANSACTIONAL_CURR_CODE  := p_header_rec.TRANSACTIONAL_CURR_CODE;
1284 	x_rowtype_rec.VERSION_NUMBER           := p_header_rec.VERSION_NUMBER;
1285 	x_rowtype_rec.FLOW_STATUS_CODE         := p_header_rec.FLOW_STATUS_CODE;
1286 	x_rowtype_rec.TP_ATTRIBUTE1            := p_header_rec.TP_ATTRIBUTE1;
1287 	x_rowtype_rec.TP_ATTRIBUTE10           := p_header_rec.TP_ATTRIBUTE10;
1288 	x_rowtype_rec.TP_ATTRIBUTE11           := p_header_rec.TP_ATTRIBUTE11;
1289 	x_rowtype_rec.TP_ATTRIBUTE12           := p_header_rec.TP_ATTRIBUTE12;
1290 	x_rowtype_rec.TP_ATTRIBUTE13           := p_header_rec.TP_ATTRIBUTE13;
1291 	x_rowtype_rec.TP_ATTRIBUTE14           := p_header_rec.TP_ATTRIBUTE14;
1292 	x_rowtype_rec.TP_ATTRIBUTE15           := p_header_rec.TP_ATTRIBUTE15;
1293 	x_rowtype_rec.TP_ATTRIBUTE2            := p_header_rec.TP_ATTRIBUTE2;
1294 	x_rowtype_rec.TP_ATTRIBUTE3            := p_header_rec.TP_ATTRIBUTE3;
1295 	x_rowtype_rec.TP_ATTRIBUTE4            := p_header_rec.TP_ATTRIBUTE4;
1296 	x_rowtype_rec.TP_ATTRIBUTE5            := p_header_rec.TP_ATTRIBUTE5;
1297 	x_rowtype_rec.TP_ATTRIBUTE6            := p_header_rec.TP_ATTRIBUTE6;
1298 	x_rowtype_rec.TP_ATTRIBUTE7            := p_header_rec.TP_ATTRIBUTE7;
1299 	x_rowtype_rec.TP_ATTRIBUTE8            := p_header_rec.TP_ATTRIBUTE8;
1300 	x_rowtype_rec.TP_ATTRIBUTE9            := p_header_rec.TP_ATTRIBUTE9;
1301 	x_rowtype_rec.TP_CONTEXT               := p_header_rec.TP_CONTEXT;
1302 
1303      -- QUOTING changes
1304         x_rowtype_rec.quote_date               := p_header_rec.quote_date;
1305         x_rowtype_rec.quote_number             := p_header_rec.quote_number;
1306         x_rowtype_rec.sales_document_name      := p_header_rec.sales_document_name;
1307         x_rowtype_rec.transaction_phase_code   := p_header_rec.transaction_phase_code;
1308         x_rowtype_rec.user_status_code         := p_header_rec.user_status_code;
1309         x_rowtype_rec.draft_submitted_flag     := p_header_rec.draft_submitted_flag;
1310         x_rowtype_rec.source_document_version_number := p_header_rec.source_document_version_number;
1311         x_rowtype_rec.sold_to_site_use_id      := p_header_rec.sold_to_site_use_id;
1312         -- QUOTING changes END
1313        x_rowtype_rec.IB_OWNER                 := p_header_rec.IB_OWNER;
1314         x_rowtype_rec.IB_INSTALLED_AT_LOCATION := p_header_rec.IB_INSTALLED_AT_LOCATION;
1315         x_rowtype_rec.IB_CURRENT_LOCATION      := p_header_rec.IB_CURRENT_LOCATION;
1316         x_rowtype_rec.END_CUSTOMER_ID          := p_header_rec.END_CUSTOMER_ID;
1317         x_rowtype_rec.END_CUSTOMER_CONTACT_ID  := p_header_rec.END_CUSTOMER_CONTACT_ID;
1318         x_rowtype_rec.END_CUSTOMER_SITE_USE_ID := p_header_rec.END_CUSTOMER_SITE_USE_ID;
1319         x_rowtype_rec.CUSTOMER_SIGNATURE := p_header_rec.CUSTOMER_SIGNATURE;
1320         x_rowtype_rec.CUSTOMER_SIGNATURE_DATE := p_header_rec.CUSTOMER_SIGNATURE_DATE;
1321         x_rowtype_rec.SUPPLIER_SIGNATURE := p_header_rec.SUPPLIER_SIGNATURE;
1322         x_rowtype_rec.SUPPLIER_SIGNATURE_DATE := p_header_rec.SUPPLIER_SIGNATURE_DATE;
1323         --key Transaction Dates
1324         x_rowtype_rec.order_firmed_date       := p_header_rec.order_firmed_date;
1325 
1326 EXCEPTION
1327 
1328 	WHEN OTHERS THEN
1329  		IF 	OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
1330 		THEN
1331    			OE_MSG_PUB.Add_Exc_Msg
1332          	(   G_PKG_NAME
1333          	,   'API_Rec_To_RowType_Rec'
1334          	);
1335      	END IF;
1336 		RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1337 END API_Rec_To_RowType_Rec;
1338 
1339 PROCEDURE Rowtype_Rec_To_API_Rec
1340 (   p_record                        IN  OE_AK_ORDER_HEADERS_V%ROWTYPE
1341 ,   x_api_rec                       IN OUT NOCOPY OE_Order_PUB.HEADER_Rec_Type
1342 ) IS
1343 BEGIN
1344 
1345 	x_api_rec.ACCOUNTING_RULE_ID       := p_record.ACCOUNTING_RULE_ID;
1346 	x_api_rec.ACCOUNTING_RULE_DURATION := p_record.ACCOUNTING_RULE_DURATION;
1347 	x_api_rec.AGREEMENT_ID             := p_record.AGREEMENT_ID;
1348 	x_api_rec.ATTRIBUTE1               := p_record.ATTRIBUTE1;
1349 	x_api_rec.ATTRIBUTE10              := p_record.ATTRIBUTE10;
1350 	x_api_rec.ATTRIBUTE11              := p_record.ATTRIBUTE11;
1351 	x_api_rec.ATTRIBUTE12              := p_record.ATTRIBUTE12;
1352 	x_api_rec.ATTRIBUTE13              := p_record.ATTRIBUTE13;
1353 	x_api_rec.ATTRIBUTE14              := p_record.ATTRIBUTE14;
1354 	x_api_rec.ATTRIBUTE15              := p_record.ATTRIBUTE15;
1355 	x_api_rec.ATTRIBUTE16              := p_record.ATTRIBUTE16;   --For bug 2184255
1356 	x_api_rec.ATTRIBUTE17              := p_record.ATTRIBUTE17;
1357 	x_api_rec.ATTRIBUTE18              := p_record.ATTRIBUTE18;
1358 	x_api_rec.ATTRIBUTE19              := p_record.ATTRIBUTE19;
1359 	x_api_rec.ATTRIBUTE2               := p_record.ATTRIBUTE2;
1360 	x_api_rec.ATTRIBUTE20              := p_record.ATTRIBUTE20;
1361 	x_api_rec.ATTRIBUTE3               := p_record.ATTRIBUTE3;
1362 	x_api_rec.ATTRIBUTE4               := p_record.ATTRIBUTE4;
1363 	x_api_rec.ATTRIBUTE5               := p_record.ATTRIBUTE5;
1364 	x_api_rec.ATTRIBUTE6               := p_record.ATTRIBUTE6;
1365 	x_api_rec.ATTRIBUTE7               := p_record.ATTRIBUTE7;
1366 	x_api_rec.ATTRIBUTE8               := p_record.ATTRIBUTE8;
1367 	x_api_rec.ATTRIBUTE9               := p_record.ATTRIBUTE9;
1368         x_api_rec.BLANKET_NUMBER           := p_record.BLANKET_NUMBER;
1369 	x_api_rec.BOOKED_FLAG              := p_record.BOOKED_FLAG;
1370 	x_api_rec.BOOKED_DATE              := p_record.BOOKED_DATE;
1371 	x_api_rec.CANCELLED_FLAG           := p_record.CANCELLED_FLAG;
1372 	x_api_rec.CHANGE_COMMENTS          := p_record.CHANGE_COMMENTS;
1373 	x_api_rec.CHANGE_REASON            := p_record.CHANGE_REASON;
1374 	x_api_rec.CHECK_NUMBER             := p_record.CHECK_NUMBER;
1375 	x_api_rec.CONTEXT                  := p_record.CONTEXT;
1376 	x_api_rec.CONVERSION_RATE          := p_record.CONVERSION_RATE;
1377 	x_api_rec.CONVERSION_RATE_DATE     := p_record.CONVERSION_RATE_DATE;
1378 	x_api_rec.CONVERSION_TYPE_CODE     := p_record.CONVERSION_TYPE_CODE;
1379 	x_api_rec.upgraded_flag            := p_record.upgraded_flag;
1380 	x_api_rec.CUSTOMER_PREFERENCE_SET_CODE  := p_record.CUSTOMER_PREFERENCE_SET_CODE;
1381 	x_api_rec.CREATED_BY               := p_record.CREATED_BY;
1382 	x_api_rec.CREATION_DATE            := p_record.CREATION_DATE;
1383 	x_api_rec.CREDIT_CARD_APPROVAL_CODE := p_record.CREDIT_CARD_APPROVAL_CODE;
1384 	x_api_rec.CREDIT_CARD_CODE         := p_record.CREDIT_CARD_CODE;
1385 	x_api_rec.CREDIT_CARD_EXPIRATION_DATE := p_record.CREDIT_CARD_EXPIRATION_DATE;
1386 	x_api_rec.CREDIT_CARD_APPROVAL_DATE := p_record.CREDIT_CARD_APPROVAL_DATE;
1387 	x_api_rec.CREDIT_CARD_HOLDER_NAME  := p_record.CREDIT_CARD_HOLDER_NAME;
1388 	x_api_rec.CREDIT_CARD_NUMBER       := p_record.CREDIT_CARD_NUMBER;
1389 	x_api_rec.CUST_PO_NUMBER           := p_record.CUST_PO_NUMBER;
1390 	x_api_rec.DB_FLAG                  := p_record.DB_FLAG;
1391         x_api_rec.DEFAULT_FULFILLMENT_SET  := p_record.DEFAULT_FULFILLMENT_SET;
1392 	x_api_rec.DELIVER_TO_CONTACT_ID    := p_record.DELIVER_TO_CONTACT_ID;
1393 	x_api_rec.DELIVER_TO_ORG_ID        := p_record.DELIVER_TO_ORG_ID;
1394 	x_api_rec.DEMAND_CLASS_CODE        := p_record.DEMAND_CLASS_CODE;
1395 	x_api_rec.EARLIEST_SCHEDULE_LIMIT  := p_record.EARLIEST_SCHEDULE_LIMIT;
1396 	x_api_rec.EXPIRATION_DATE          := p_record.EXPIRATION_DATE;
1397 	x_api_rec.FIRST_ACK_CODE           := p_record.FIRST_ACK_CODE;
1398 	x_api_rec.FIRST_ACK_DATE           := p_record.FIRST_ACK_DATE;
1399 	x_api_rec.FOB_POINT_CODE           := p_record.FOB_POINT_CODE;
1400 	x_api_rec.FREIGHT_CARRIER_CODE     := p_record.FREIGHT_CARRIER_CODE;
1401 	x_api_rec.FREIGHT_TERMS_CODE       := p_record.FREIGHT_TERMS_CODE;
1402         x_api_rec.FULFILLMENT_SET_NAME     := p_record.FULFILLMENT_SET_NAME;
1403 	x_api_rec.GLOBAL_ATTRIBUTE1        := p_record.GLOBAL_ATTRIBUTE1;
1404 	x_api_rec.GLOBAL_ATTRIBUTE10       := p_record.GLOBAL_ATTRIBUTE10;
1405 	x_api_rec.GLOBAL_ATTRIBUTE11       := p_record.GLOBAL_ATTRIBUTE11;
1406 	x_api_rec.GLOBAL_ATTRIBUTE12       := p_record.GLOBAL_ATTRIBUTE12;
1407 	x_api_rec.GLOBAL_ATTRIBUTE13       := p_record.GLOBAL_ATTRIBUTE13;
1408 	x_api_rec.GLOBAL_ATTRIBUTE14       := p_record.GLOBAL_ATTRIBUTE14;
1409 	x_api_rec.GLOBAL_ATTRIBUTE15       := p_record.GLOBAL_ATTRIBUTE15;
1410 	x_api_rec.GLOBAL_ATTRIBUTE16       := p_record.GLOBAL_ATTRIBUTE16;
1411 	x_api_rec.GLOBAL_ATTRIBUTE17       := p_record.GLOBAL_ATTRIBUTE17;
1412 	x_api_rec.GLOBAL_ATTRIBUTE18       := p_record.GLOBAL_ATTRIBUTE18;
1413 	x_api_rec.GLOBAL_ATTRIBUTE19       := p_record.GLOBAL_ATTRIBUTE19;
1414 	x_api_rec.GLOBAL_ATTRIBUTE2        := p_record.GLOBAL_ATTRIBUTE2;
1415 	x_api_rec.GLOBAL_ATTRIBUTE20       := p_record.GLOBAL_ATTRIBUTE20;
1416 	x_api_rec.GLOBAL_ATTRIBUTE3        := p_record.GLOBAL_ATTRIBUTE3;
1417 	x_api_rec.GLOBAL_ATTRIBUTE4        := p_record.GLOBAL_ATTRIBUTE4;
1418 	x_api_rec.GLOBAL_ATTRIBUTE5        := p_record.GLOBAL_ATTRIBUTE5;
1419 	x_api_rec.GLOBAL_ATTRIBUTE6        := p_record.GLOBAL_ATTRIBUTE6;
1420 	x_api_rec.GLOBAL_ATTRIBUTE7        := p_record.GLOBAL_ATTRIBUTE7;
1421 	x_api_rec.GLOBAL_ATTRIBUTE8        := p_record.GLOBAL_ATTRIBUTE8;
1422 	x_api_rec.GLOBAL_ATTRIBUTE9        := p_record.GLOBAL_ATTRIBUTE9;
1423 	x_api_rec.GLOBAL_ATTRIBUTE_CATEGORY := p_record.GLOBAL_ATTRIBUTE_CATEGORY;
1424 	x_api_rec.HEADER_ID                := p_record.HEADER_ID;
1425 	x_api_rec.INVOICE_TO_CONTACT_ID    := p_record.INVOICE_TO_CONTACT_ID;
1426 	x_api_rec.INVOICE_TO_ORG_ID        := p_record.INVOICE_TO_ORG_ID;
1427 	x_api_rec.INVOICING_RULE_ID        := p_record.INVOICING_RULE_ID;
1428 	x_api_rec.LAST_ACK_CODE            := p_record.LAST_ACK_CODE;
1429 	x_api_rec.LAST_ACK_DATE            := p_record.LAST_ACK_DATE;
1430 	x_api_rec.LAST_UPDATED_BY          := p_record.LAST_UPDATED_BY;
1431 	x_api_rec.LAST_UPDATE_DATE         := p_record.LAST_UPDATE_DATE;
1432 	x_api_rec.LAST_UPDATE_LOGIN        := p_record.LAST_UPDATE_LOGIN;
1433 	x_api_rec.LATEST_SCHEDULE_LIMIT    := p_record.LATEST_SCHEDULE_LIMIT;
1434         x_api_rec.LINE_SET_NAME            := p_record.LINE_SET_NAME;
1435 	x_api_rec.OPEN_FLAG                := p_record.OPEN_FLAG;
1436 	x_api_rec.OPERATION                := p_record.OPERATION;
1437 	x_api_rec.ORDERED_DATE             := p_record.ORDERED_DATE;
1438 	x_api_rec.ORDER_DATE_TYPE_CODE     := p_record.ORDER_DATE_TYPE_CODE;
1439 	x_api_rec.ORDER_NUMBER             := p_record.ORDER_NUMBER;
1440 	x_api_rec.ORDER_SOURCE_ID          := p_record.ORDER_SOURCE_ID;
1441 	x_api_rec.ORDER_TYPE_ID            := p_record.ORDER_TYPE_ID;
1442 	x_api_rec.ORDER_CATEGORY_CODE      := p_record.ORDER_CATEGORY_CODE;
1443 	x_api_rec.ORG_ID                   := p_record.ORG_ID;
1444 	x_api_rec.ORIG_SYS_DOCUMENT_REF    := p_record.ORIG_SYS_DOCUMENT_REF;
1445 	x_api_rec.PACKING_INSTRUCTIONS     := p_record.PACKING_INSTRUCTIONS;
1446 	x_api_rec.PARTIAL_SHIPMENTS_ALLOWED := p_record.PARTIAL_SHIPMENTS_ALLOWED;
1447 	x_api_rec.PAYMENT_AMOUNT           := p_record.PAYMENT_AMOUNT;
1448 	x_api_rec.PAYMENT_TERM_ID          := p_record.PAYMENT_TERM_ID;
1449 	x_api_rec.PAYMENT_TYPE_CODE        := p_record.PAYMENT_TYPE_CODE;
1450 	x_api_rec.PRICE_LIST_ID            := p_record.PRICE_LIST_ID;
1451 	x_api_rec.PRICE_REQUEST_CODE       := p_record.PRICE_REQUEST_CODE; -- PROMOTIONS SEP/01
1452 	x_api_rec.PRICING_DATE             := p_record.PRICING_DATE;
1453 	x_api_rec.PROGRAM_APPLICATION_ID   := p_record.PROGRAM_APPLICATION_ID;
1454 	x_api_rec.PROGRAM_ID               := p_record.PROGRAM_ID;
1455 	x_api_rec.PROGRAM_UPDATE_DATE      := p_record.PROGRAM_UPDATE_DATE;
1456 	x_api_rec.REQUEST_DATE             := p_record.REQUEST_DATE;
1457 	x_api_rec.REQUEST_ID               := p_record.REQUEST_ID;
1458 	x_api_rec.RETURN_REASON_CODE       := p_record.RETURN_REASON_CODE;
1459 	x_api_rec.RETURN_STATUS            := p_record.RETURN_STATUS;
1460 	x_api_rec.SALESREP_ID              := p_record.SALESREP_ID;
1461 	x_api_rec.SALES_CHANNEL_CODE       := p_record.SALES_CHANNEL_CODE;
1462 	x_api_rec.SHIPMENT_PRIORITY_CODE   := p_record.SHIPMENT_PRIORITY_CODE;
1463 	x_api_rec.SHIPPING_INSTRUCTIONS    := p_record.SHIPPING_INSTRUCTIONS;
1464 	x_api_rec.SHIPPING_METHOD_CODE     := p_record.SHIPPING_METHOD_CODE;
1465 	x_api_rec.SHIP_FROM_ORG_ID         := p_record.SHIP_FROM_ORG_ID;
1466 	x_api_rec.SHIP_TOLERANCE_ABOVE     := p_record.SHIP_TOLERANCE_ABOVE;
1467 	x_api_rec.SHIP_TOLERANCE_BELOW     := p_record.SHIP_TOLERANCE_BELOW;
1468 	x_api_rec.SHIP_TO_CONTACT_ID       := p_record.SHIP_TO_CONTACT_ID;
1469 	x_api_rec.SHIP_TO_ORG_ID           := p_record.SHIP_TO_ORG_ID;
1470 	x_api_rec.SOLD_FROM_ORG_ID         := p_record.SOLD_FROM_ORG_ID;
1471 	x_api_rec.SOLD_TO_CONTACT_ID       := p_record.SOLD_TO_CONTACT_ID;
1472 	x_api_rec.SOLD_TO_ORG_ID           := p_record.SOLD_TO_ORG_ID;
1473 	x_api_rec.SOURCE_DOCUMENT_ID       := p_record.SOURCE_DOCUMENT_ID;
1474 	x_api_rec.SOURCE_DOCUMENT_TYPE_ID  := p_record.SOURCE_DOCUMENT_TYPE_ID;
1475 	x_api_rec.TAX_EXEMPT_FLAG          := p_record.TAX_EXEMPT_FLAG;
1476 	x_api_rec.TAX_EXEMPT_NUMBER        := p_record.TAX_EXEMPT_NUMBER;
1477 	x_api_rec.TAX_EXEMPT_REASON_CODE   := p_record.TAX_EXEMPT_REASON_CODE;
1478 	x_api_rec.TAX_POINT_CODE           := p_record.TAX_POINT_CODE;
1479 	x_api_rec.TRANSACTIONAL_CURR_CODE  := p_record.TRANSACTIONAL_CURR_CODE;
1480 	x_api_rec.VERSION_NUMBER           := p_record.VERSION_NUMBER;
1481 	x_api_rec.FLOW_STATUS_CODE         := p_record.FLOW_STATUS_CODE;
1482 	x_api_rec.TP_ATTRIBUTE1            := p_record.TP_ATTRIBUTE1;
1483 	x_api_rec.TP_ATTRIBUTE10           := p_record.TP_ATTRIBUTE10;
1484 	x_api_rec.TP_ATTRIBUTE11           := p_record.TP_ATTRIBUTE11;
1485 	x_api_rec.TP_ATTRIBUTE12           := p_record.TP_ATTRIBUTE12;
1486 	x_api_rec.TP_ATTRIBUTE13           := p_record.TP_ATTRIBUTE13;
1487 	x_api_rec.TP_ATTRIBUTE14           := p_record.TP_ATTRIBUTE14;
1488 	x_api_rec.TP_ATTRIBUTE15           := p_record.TP_ATTRIBUTE15;
1489 	x_api_rec.TP_ATTRIBUTE2            := p_record.TP_ATTRIBUTE2;
1490 	x_api_rec.TP_ATTRIBUTE3            := p_record.TP_ATTRIBUTE3;
1491 	x_api_rec.TP_ATTRIBUTE4            := p_record.TP_ATTRIBUTE4;
1492 	x_api_rec.TP_ATTRIBUTE5            := p_record.TP_ATTRIBUTE5;
1493 	x_api_rec.TP_ATTRIBUTE6            := p_record.TP_ATTRIBUTE6;
1494 	x_api_rec.TP_ATTRIBUTE7            := p_record.TP_ATTRIBUTE7;
1495 	x_api_rec.TP_ATTRIBUTE8            := p_record.TP_ATTRIBUTE8;
1496 	x_api_rec.TP_ATTRIBUTE9            := p_record.TP_ATTRIBUTE9;
1497 	x_api_rec.TP_CONTEXT               := p_record.TP_CONTEXT;
1498 
1499         -- QUOTING changes
1500 	x_api_rec.quote_number             := p_record.quote_number;
1501 	x_api_rec.quote_date               := p_record.quote_date;
1502 	x_api_rec.sales_document_name      := p_record.sales_document_name;
1503 	x_api_rec.transaction_phase_code   := p_record.transaction_phase_code;
1504 	x_api_rec.user_status_code         := p_record.user_status_code;
1505 	x_api_rec.draft_submitted_flag     := p_record.draft_submitted_flag;
1506 	x_api_rec.source_document_version_number := p_record.source_document_version_number;
1507 	x_api_rec.sold_to_site_use_id      := p_record.sold_to_site_use_id;
1508         -- QUOTING changes END
1509 	x_api_rec.IB_OWNER                 := p_record.IB_OWNER;
1510 	x_api_rec.IB_INSTALLED_AT_LOCATION := p_record.IB_INSTALLED_AT_LOCATION;
1511 	x_api_rec.IB_CURRENT_LOCATION      := p_record.IB_CURRENT_LOCATION;
1512 	x_api_rec.END_CUSTOMER_ID          := p_record.END_CUSTOMER_ID;
1513 	x_api_rec.END_CUSTOMER_CONTACT_ID  := p_record.END_CUSTOMER_CONTACT_ID;
1514 	x_api_rec.END_CUSTOMER_SITE_USE_ID := p_record.END_CUSTOMER_SITE_USE_ID;
1515 	x_api_rec.CUSTOMER_SIGNATURE       := p_record.CUSTOMER_SIGNATURE;
1516 	x_api_rec.CUSTOMER_SIGNATURE_DATE       := p_record.CUSTOMER_SIGNATURE_DATE;
1517 	x_api_rec.SUPPLIER_SIGNATURE       := p_record.SUPPLIER_SIGNATURE;
1518 	x_api_rec.SUPPLIER_SIGNATURE_DATE       := p_record.SUPPLIER_SIGNATURE_DATE;
1519         --key Transaction dates
1520         x_api_rec.order_firmed_date        := p_record.order_firmed_date;
1521 
1522 EXCEPTION
1523 
1524 	WHEN OTHERS THEN
1525 	IF	OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
1526 	THEN
1527 		OE_MSG_PUB.Add_Exc_Msg
1528          	(   G_PKG_NAME
1529          	,   'Rowtype_Rec_To_API_Rec'
1530          	);
1531 	END IF;
1532 	RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1533 END Rowtype_Rec_To_API_Rec;
1534 
1535 --  Procedure Clear_Dependent_Attr: Overloaded for view%rowtype PARAMETERS
1536 
1537 PROCEDURE Clear_Dependent_Attr
1538 (   p_attr_id                       IN  NUMBER := FND_API.G_MISS_NUM
1539 ,   p_initial_header_rec            IN  OE_AK_ORDER_HEADERS_V%ROWTYPE
1540 ,   p_old_header_rec                IN  OE_AK_ORDER_HEADERS_V%ROWTYPE
1541 ,   p_x_header_rec                  IN  OUT NOCOPY OE_AK_ORDER_HEADERS_V%ROWTYPE
1542 ,   p_x_instrument_id		    IN NUMBER DEFAULT NULL --R12 CC Encryption
1543 ,   p_old_instrument_id		    IN NUMBER DEFAULT NULL
1544 )
1545 IS
1546 	l_index			NUMBER :=0;
1547 	l_src_attr_tbl	OE_GLOBALS.NUMBER_Tbl_Type;
1548 BEGIN
1549 
1550 	oe_debug_pub.add('Entering OE_HEADER_UTIL.CLEAR_DEPENDENT_ATTR', 1);
1551 
1552 	IF 	p_attr_id <> FND_API.G_MISS_NUM THEN
1553 
1554 		l_index := l_index + 1.0;
1555 		l_src_attr_tbl(l_index) := p_attr_id;
1556 
1557     --  If attr_id is missing compare old and new records and for
1558     --  every changed attribute clear its dependent fields.
1559 
1560 	ELSE
1561 
1562 		IF NOT OE_GLOBALS.Equal(p_x_header_rec.agreement_id,p_old_header_rec.agreement_id)
1563 		THEN
1564 			l_index := l_index + 1.0;
1565 			l_src_attr_tbl(l_index) := OE_HEADER_UTIL.G_AGREEMENT;
1566 		END IF;
1567 
1568 		IF NOT OE_GLOBALS.Equal(p_x_header_rec.deliver_to_org_id,p_old_header_rec.deliver_to_org_id)
1569 		THEN
1570 			l_index := l_index + 1.0;
1571 			l_src_attr_tbl(l_index) := OE_HEADER_UTIL.G_DELIVER_TO_ORG;
1572 		END IF;
1573 
1574 		IF NOT OE_GLOBALS.Equal(p_x_header_rec.invoice_to_contact_id,p_old_header_rec.invoice_to_contact_id)
1575 		THEN
1576 			l_index := l_index + 1.0;
1577 			l_src_attr_tbl(l_index) := OE_HEADER_UTIL.G_INVOICE_TO_CONTACT;
1578 		END IF;
1579 
1580 		IF NOT OE_GLOBALS.Equal(p_x_header_rec.invoice_to_org_id,p_old_header_rec.invoice_to_org_id)
1581 		THEN
1582 			l_index := l_index + 1.0;
1583 			l_src_attr_tbl(l_index) := OE_HEADER_UTIL.G_INVOICE_TO_ORG;
1584 		END IF;
1585 
1586 		IF NOT OE_GLOBALS.Equal(p_x_header_rec.ordered_date,p_old_header_rec.ordered_date)
1587 		THEN
1588 			l_index := l_index + 1.0;
1589 			l_src_attr_tbl(l_index) := OE_HEADER_UTIL.G_ORDERED_DATE;
1590 		END IF;
1591 
1592 		IF NOT OE_GLOBALS.Equal(p_x_header_rec.order_type_id,p_old_header_rec.order_type_id)
1593 		THEN
1594 			l_index := l_index + 1.0;
1595 			l_src_attr_tbl(l_index) := OE_HEADER_UTIL.G_ORDER_TYPE;
1596 		END IF;
1597 
1598 		IF NOT OE_GLOBALS.Equal(p_x_header_rec.payment_type_code,p_old_header_rec.payment_type_code)
1599 		THEN
1600 			l_index := l_index + 1.0;
1601 			l_src_attr_tbl(l_index) := OE_HEADER_UTIL.G_PAYMENT_TYPE;
1602 		END IF;
1603 
1604                /* Fix Bug # 2297053: Clear attributes dependent on Credit Card Number */
1605                IF NOT OE_GLOBALS.Is_Same_Credit_Card(p_old_header_rec.credit_card_number,p_x_header_rec.credit_card_number,
1606 	       p_old_instrument_id,p_x_instrument_id)
1607                THEN
1608                         l_index := l_index + 1.0;
1609                         l_src_attr_tbl(l_index) := OE_HEADER_UTIL.G_CREDIT_CARD_NUMBER;
1610                 END IF;
1611 
1612 		IF NOT OE_GLOBALS.Equal(p_x_header_rec.price_list_id,p_old_header_rec.price_list_id)
1613 		THEN
1614 			l_index := l_index + 1.0;
1615 			l_src_attr_tbl(l_index) := OE_HEADER_UTIL.G_PRICE_LIST;
1616 		END IF;
1617 
1618 		IF NOT OE_GLOBALS.Equal(p_x_header_rec.request_date,p_old_header_rec.request_date)
1619 		THEN
1620 			l_index := l_index + 1.0;
1621 			l_src_attr_tbl(l_index) := OE_HEADER_UTIL.G_REQUEST_DATE;
1622 		END IF;
1623 
1624 		IF NOT OE_GLOBALS.Equal(p_x_header_rec.ship_from_org_id,p_old_header_rec.ship_from_org_id)
1625 		THEN
1626 			l_index := l_index + 1.0;
1627 			l_src_attr_tbl(l_index) := OE_HEADER_UTIL.G_SHIP_FROM_ORG;
1628 		END IF;
1629 
1630 		IF NOT OE_GLOBALS.Equal(p_x_header_rec.ship_to_contact_id,p_old_header_rec.ship_to_contact_id)
1631 		THEN
1632 			l_index := l_index + 1.0;
1633 			l_src_attr_tbl(l_index) := OE_HEADER_UTIL.G_SHIP_TO_CONTACT;
1634 		END IF;
1635 
1636 		IF NOT OE_GLOBALS.Equal(p_x_header_rec.ship_to_org_id,p_old_header_rec.ship_to_org_id)
1637 		THEN
1638 			l_index := l_index + 1.0;
1639 			l_src_attr_tbl(l_index) := OE_HEADER_UTIL.G_SHIP_TO_ORG;
1640 		END IF;
1641 
1642 		IF NOT OE_GLOBALS.Equal(p_x_header_rec.sold_to_org_id,p_old_header_rec.sold_to_org_id)
1643 		THEN
1644 			l_index := l_index + 1.0;
1645 			l_src_attr_tbl(l_index) := OE_HEADER_UTIL.G_SOLD_TO_ORG;
1646 		END IF;
1647 
1648 		IF NOT OE_GLOBALS.Equal(p_x_header_rec.sold_to_phone_id,p_old_header_rec.sold_to_phone_id)
1649 		THEN
1650 			l_index := l_index + 1.0;
1651 			l_src_attr_tbl(l_index) := OE_HEADER_UTIL.G_SOLD_TO_PHONE;
1652 		END IF;
1653 
1654 		IF NOT OE_GLOBALS.Equal(p_x_header_rec.tax_exempt_flag,p_old_header_rec.tax_exempt_flag)
1655 		THEN
1656 			l_index := l_index + 1.0;
1657 			l_src_attr_tbl(l_index) := OE_HEADER_UTIL.G_TAX_EXEMPT;
1658 		END IF;
1659 
1660 		IF NOT OE_GLOBALS.Equal(p_x_header_rec.transactional_curr_code,p_old_header_rec.transactional_curr_code)
1661 		THEN
1662 			l_index := l_index + 1.0;
1663 			l_src_attr_tbl(l_index) := OE_HEADER_UTIL.G_TRANSACTIONAL_CURR;
1664 		END IF;
1665 
1666                 IF NOT OE_GLOBALS.Equal(p_x_header_rec.blanket_number,p_old_header_rec.blanket_number)
1667                 THEN
1668                        l_index := l_index + 1.0;
1669                        l_src_attr_tbl(l_index) := OE_HEADER_UTIL.G_BLANKET_NUMBER;
1670                 END IF;
1671 
1672              -- QUOTING changes
1673                 IF NOT OE_GLOBALS.Equal(p_x_header_rec.transaction_phase_code,p_old_header_rec.transaction_phase_code)
1674                 THEN
1675                        l_index := l_index + 1.0;
1676                        l_src_attr_tbl(l_index) := OE_HEADER_UTIL.G_TRANSACTION_PHASE;
1677                 END IF;
1678                 -- QUOTING changes END
1679 
1680 		--distributed order @
1681 		IF NOT OE_GLOBALS.Equal(p_x_header_rec.end_customer_id,p_old_header_rec.end_customer_id)
1682                 THEN
1683                        l_index := l_index + 1.0;
1684                        l_src_attr_tbl(l_index) := OE_HEADER_UTIL.G_END_CUSTOMER;
1685                 END IF;
1686 
1687                 -- bug 5127922
1688                 IF NOT OE_GLOBALS.Equal(p_x_header_rec.sold_to_site_use_id,p_old_header_rec.sold_to_site_use_id)
1689                 THEN
1690                        l_index := l_index + 1.0;
1691                        l_src_attr_tbl(l_index) := OE_HEADER_UTIL.G_SOLD_TO_SITE_USE;
1692                 END IF;
1693 
1694 	END IF;
1695 
1696 	Clear_Dependents
1697 	(p_src_attr_tbl 	=> l_src_attr_tbl
1698 	,p_initial_header_rec	=> p_initial_header_rec
1699 	,p_old_header_rec	=> p_old_header_rec
1700 	,p_x_header_rec		=> p_x_header_rec
1701 	,p_x_instrument_id	=> p_x_instrument_id
1702 	,p_old_instrument_id    => p_old_instrument_id);
1703         --bug 5083663
1704 	--Need to reset the global flag for cc dependent attributes, so that they
1705 	--can be cleared during the future calls when the cc is not selected
1706 	--from the LOV.
1707 	g_is_cc_selected_from_LOV := 'N';
1708 
1709 	oe_debug_pub.add('Exiting OE_HEADER_UTIL.CLEAR_DEPENDENT_ATTR', 1);
1710 
1711 EXCEPTION
1712 	WHEN FND_API.G_EXC_ERROR THEN
1713 		RAISE FND_API.G_EXC_ERROR;
1714 	WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1715 		RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1716 	WHEN OTHERS THEN
1717 		IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
1718 		THEN
1719 			OE_MSG_PUB.Add_Exc_Msg
1720 			(   G_PKG_NAME
1721 			,   'Clear_Dependent_Attr'
1722 			);
1723 		END IF;
1724 		RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1725 
1726 END Clear_Dependent_Attr;
1727 
1728 PROCEDURE Clear_Dependent_Attr
1729 (   p_attr_id                       IN  NUMBER := FND_API.G_MISS_NUM
1730 ,   p_x_header_rec                    IN  OUT NOCOPY OE_Order_PUB.Header_Rec_Type
1731 ,   p_old_header_rec                IN  OE_Order_PUB.Header_Rec_Type :=
1732                                         OE_Order_PUB.G_MISS_HEADER_REC
1733 )
1734 IS
1735 	l_header_rec			OE_AK_ORDER_HEADERS_V%ROWTYPE;
1736 	l_old_header_rec		OE_AK_ORDER_HEADERS_V%ROWTYPE;
1737 	l_initial_header_rec	OE_AK_ORDER_HEADERS_V%ROWTYPE;
1738 BEGIN
1739 	oe_debug_pub.add('Security code in Clear_dep_attr....'||p_x_header_rec.instrument_security_code);
1740 	API_Rec_To_Rowtype_Rec(p_x_header_rec, l_header_rec);
1741 	API_Rec_To_Rowtype_Rec(p_old_header_rec, l_old_header_rec);
1742 
1743 	l_initial_header_rec := l_header_rec;
1744 
1745 	Clear_Dependent_Attr
1746 		(p_attr_id			=> p_attr_id
1747 		,p_initial_header_rec	=> l_initial_header_rec
1748 		,p_old_header_rec		=> l_old_header_rec
1749 		,p_x_header_rec			=> l_header_rec
1750 		,p_x_instrument_id	=> p_x_header_rec.cc_instrument_id
1751 		,p_old_instrument_id    => p_old_header_rec.cc_instrument_id
1752 		);
1753 
1754 	Rowtype_Rec_To_API_Rec(l_header_rec, p_x_header_rec);
1755 
1756 END Clear_Dependent_Attr;
1757 
1758 --  Procedure Apply_Attribute_Changes
1759 
1760 PROCEDURE Apply_Attribute_Changes
1761 (   p_x_header_rec                  IN OUT NOCOPY OE_Order_PUB.Header_Rec_Type
1762 ,   p_old_header_rec                IN  OE_Order_PUB.Header_Rec_Type :=
1763                                         OE_Order_PUB.G_MISS_HEADER_REC
1764 )
1765 IS
1766 	l_return_status			VARCHAR2(1):=  FND_API.G_RET_STS_SUCCESS;
1767 
1768 	l_verify_payment_flag	VARCHAR2(30) := 'N';
1769         l_level                 VARCHAR2(10) ;
1770         l_copy_orig_price       VARCHAR2(1):='Y';
1771   	idx                   NUMBER; --ER 12363706
1772   	-- added by Renga for multiple payments
1773 
1774 cursor payment_count_cur is
1775 select count(payment_type_code)
1776 from oe_payments
1777 where header_id = p_x_header_rec.header_id
1778 and line_id is null;
1779 
1780 cursor delete_payment_count_cur is
1781 select count(payment_type_code)
1782 from oe_payments
1783 where header_id = p_x_header_rec.header_id
1784 and line_id is null
1785 and payment_type_code in ('CREDIT_CARD','ACH','DIRECT_DEBIT');
1786 
1787 --- added for bug# 10194125
1788 cursor lines_cur is
1789 	select line_id from oe_order_lines_all
1790 	where header_id = p_x_header_rec.header_id;
1791 
1792 l_payments_upd_flag     VARCHAR2(1) := 'N';
1793 l_delete_payment_count NUMBER :=0;
1794 l_payment_count number := 0;
1795 l_log_delete_payment_req VARCHAR2(1) := 'N';
1796 
1797 -- ER#3667551 start
1798 l_new_tbl_entry varchar2(10) := '';
1799 l_bill_to_cust_id NUMBER := 0;
1800 l_credithold_cust VARCHAR2(10) := NVL(OE_SYS_PARAMETERS.value('ONT_CREDITHOLD_TYPE'),'S') ;
1801 -- ER#3667551 end
1802 
1803 BEGIN
1804 
1805 	oe_debug_pub.add('Entering OE_HEADER_UTIL.APPLY_ATTRIBUTE_CHANGES', 1);
1806 
1807     --  Load out record
1808 
1809 	IF NOT OE_GLOBALS.Equal(p_x_header_rec.booked_flag,p_old_header_rec.booked_flag)
1810 	THEN
1811 		IF 	p_x_header_rec.booked_flag = 'Y' THEN
1812 			p_x_header_rec.flow_status_code := 'BOOKED';
1813 		END IF;
1814 	END IF;
1815 
1816 	IF NOT OE_GLOBALS.Equal(p_x_header_rec.cancelled_flag,p_old_header_rec.cancelled_flag)
1817 	THEN
1818 		IF 	p_x_header_rec.cancelled_flag = 'Y' THEN
1819 
1820 			Oe_Sales_Can_Util.Check_Constraints(p_x_header_rec,
1821 												p_old_header_rec,
1822 												l_return_status);
1823 			IF 	l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1824 				IF 	l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
1825 					oe_debug_pub.ADD('Update Line Process Order return UNEXP_ERROR');
1826 					RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1827 				ELSIF	l_return_status = FND_API.G_RET_STS_ERROR THEN
1828 						oe_debug_pub.ADD('Update Line Process Order return RET_STS_ERROR');
1829 						RAISE FND_API.G_EXC_ERROR;
1830 				END IF;
1831 			END IF;
1832 
1833 			--p_x_header_rec.flow_status_code := 'CANCELLED';
1834 
1835 		END IF; -- cancelled flag
1836 
1837 	END IF;
1838 	oe_debug_pub.add('Raj1', 1);
1839 	oe_debug_pub.add('Operation--'||p_x_header_rec.operation);
1840 	oe_debug_pub.add('payment type--'||nvl(p_x_header_rec.payment_type_code,'xxx'));
1841 	oe_debug_pub.add('Old inv to ...'||p_x_header_rec.invoice_to_org_id);
1842 	oe_debug_pub.add('New inv to...'||p_old_header_rec.invoice_to_org_id);
1843 
1844 	IF NOT OE_GLOBALS.Equal(p_x_header_rec.invoice_to_org_id,p_old_header_rec.invoice_to_org_id)
1845 	THEN
1846 		IF  p_x_header_rec.operation = OE_GLOBALS.G_OPR_UPDATE THEN
1847 		 --R12 CC Encryption
1848 		 --Delayed request for deleting the payments when
1849 		 --invoice to changes
1850 	         IF p_x_header_rec.payment_type_code in ('ACH','DIRECT_DEBIT','CREDIT_CARD') OR
1851 	         p_x_header_rec.payment_type_code IS NULL THEN --null for prepayments
1852 			OPEN delete_payment_count_cur;
1853 			FETCH delete_payment_count_cur into l_delete_payment_count;
1854 			close delete_payment_count_cur;
1855 			IF l_delete_payment_count > 0  THEN
1856 				l_log_delete_payment_req := 'Y';
1857 			END IF;
1858 
1859 			oe_debug_pub.add('Payment_type code in invoice to '||p_x_header_rec.payment_type_code);
1860 			oe_debug_pub.add('Delete Payment Count count'||l_delete_payment_count);
1861 			oe_debug_pub.add('Log delete payment req Flag'||l_log_delete_payment_req);
1862 			IF l_log_delete_payment_req = 'Y' THEN
1863 				OE_delayed_requests_Pvt.log_request
1864 				    (p_entity_code            	=> OE_GLOBALS.G_ENTITY_HEADER_PAYMENT,
1865 				     p_entity_id              	=> p_x_Header_rec.header_id,
1866 				     p_requesting_entity_code	=> OE_GLOBALS.G_ENTITY_HEADER,
1867 				     p_requesting_entity_id  	=> p_x_Header_rec.header_id,
1868 				     p_request_type           	=> OE_GLOBALS.G_DELETE_PAYMENTS,
1869 				     p_param1			=> to_char(p_old_header_rec.invoice_to_org_id),
1870 				     x_return_status         	=> l_return_status);
1871 
1872 			END IF;--Log delayed req.
1873 		  END IF;--Payment type code check for deleting payments
1874 	          --R12 CC Encryption
1875 		  IF p_x_header_rec.payment_type_code = 'CREDIT_CARD' THEN
1876 			oe_debug_pub.add('Log Verify Payment Delayed Request in Invoice To');
1877 			-- Set Flag to Log a request for Verify Payment
1878 			l_verify_payment_flag := 'Y';
1879                   ELSE
1880                  -- BUG 2114156
1881                       oe_debug_pub.add('Call OE_CREDIT_CHECK_UTIL.GET_credit_check_level ');
1882                     l_level := NULL ;
1883 
1884                     l_level :=
1885                     OE_CREDIT_CHECK_UTIL.GET_credit_check_level
1886                     ( p_calling_action     => 'UPDATE'
1887                      , p_order_type_id     =>
1888                            p_x_header_rec.order_type_id
1889                      )  ;
1890 		oe_debug_pub.add('l_level = '|| l_level );
1891 
1892                      IF l_level = 'ORDER'
1893                      THEN
1894 
1895 
1896                      -- Set Flag to Log a request for Verify Payment
1897                       oe_debug_pub.add('Log Verify Payment Delayed Request in Invoice To - Credit Check');
1898                       --
1899                       l_verify_payment_flag := 'Y';
1900 	              OE_CREDIT_ENGINE_GRP.TOLERANCE_CHECK_REQUIRED := FALSE; --ER 12363706
1901  	              --ER 12363706 start
1902 		      idx                                                                := OE_CREDIT_CHECK_UTIL.G_CC_Invoice_tab.count;
1903 	              OE_CREDIT_CHECK_UTIL.G_CC_Invoice_tab(idx+1).new_invoice_to_org_id := p_x_header_rec.invoice_to_org_id;
1904 	              OE_CREDIT_CHECK_UTIL.G_CC_Invoice_tab(idx+1).old_invoice_to_org_id := p_old_header_rec.invoice_to_org_id;
1905 	              OE_CREDIT_CHECK_UTIL.G_CC_Invoice_tab(idx+1).line_id               := NULL;
1906 	              --ER 12363706 end
1907                     END IF;
1908                   END IF;
1909 		END IF;--Operation - Update
1910 	END IF;
1911 	oe_debug_pub.add('Raj2', 1);
1912         oe_debug_pub.add('p_x_header_rec.open_flag:'||p_x_header_rec.open_flag);
1913         oe_debug_pub.add('p_old_header_rec.open_flag:'||p_old_header_rec.open_flag);
1914 
1915 
1916 	IF (NOT OE_GLOBALS.Equal(p_x_header_rec.open_flag,
1917                                  p_old_header_rec.open_flag)) OR
1918            (p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE AND
1919             p_x_header_rec.open_flag IS NOT NULL)
1920             --OR cnd for bug 5060064
1921 	THEN
1922 		IF 	p_x_header_rec.open_flag = 'N' THEN
1923 			p_x_header_rec.flow_status_code := 'CLOSED';
1924 			IF 	p_x_header_rec.cancelled_flag = 'Y' THEN
1925 				--p_x_header_rec.flow_status_code := 'CANCELLED';
1926 				null;
1927 			END IF;
1928 		END IF;
1929 
1930 	END IF;
1931 
1932 	IF NOT OE_GLOBALS.Equal(p_x_header_rec.order_type_id,p_old_header_rec.order_type_id)
1933 	THEN
1934 
1935        -- If the Order Type has changed, we need to sync up the
1936        -- MTL_SALES_ORDERS table.
1937 		IF 	p_x_header_rec.operation = OE_GLOBALS.G_OPR_UPDATE THEN
1938 
1939 
1940 			IF p_x_header_rec.payment_type_code = 'CREDIT_CARD' THEN
1941 
1942 	     -- Set Flag to Log a request for Verify Payment
1943 				oe_debug_pub.add('Log Verify Payment Delayed Request in Order Type');
1944         			l_verify_payment_flag                         := 'Y';
1945        				OE_CREDIT_ENGINE_GRP.TOLERANCE_CHECK_REQUIRED := FALSE; --ER 12363706
1946 			ELSE
1947 
1948 			/* Additional Task - If the payment type is not CREDIT CARD ,
1949 			then also log the delayed request for Verify payment if the
1950 			Order is booked */
1951 
1952 				IF p_x_header_rec.booked_flag ='Y'
1953 				THEN
1954 
1955 					oe_debug_pub.add('Log Verify Payment Delayed Request in Order Type',3);
1956 				        l_verify_payment_flag                         := 'Y';
1957 				        OE_CREDIT_ENGINE_GRP.TOLERANCE_CHECK_REQUIRED := FALSE; --ER 12363706
1958 				END IF;
1959 
1960 			END IF;
1961 		END IF;
1962 	END IF;
1963 
1964 	IF (NOT OE_GLOBALS.Equal(p_x_header_rec.salesrep_id,
1965                                  p_old_header_rec.salesrep_id)) OR
1966            (p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE AND
1967             p_x_header_rec.salesrep_id IS NOT NULL )
1968             --OR condition added for bug 5060064
1969 	THEN
1970 
1971 		IF NOT (nvl(p_x_header_rec.source_document_type_id,-99) = 2 AND
1972 			p_x_header_rec.operation = oe_globals.g_opr_create)THEN
1973 		       IF p_x_header_rec.salesrep_id IS NOT NULL THEN
1974 	                  IF OE_Validate_Header_Scredit.G_Create_Auto_Sales_Credit = 'Y' THEN
1975 				OE_delayed_requests_Pvt.log_request
1976 				(p_entity_code				=> OE_GLOBALS.G_ENTITY_HEADER,
1977 				p_entity_id				=> p_x_header_rec.header_id,
1978 				p_requesting_entity_code	=> OE_GLOBALS.G_ENTITY_HEADER,
1979 				p_requesting_entity_id		=> p_x_header_rec.header_id,
1980 				p_request_type      		=> OE_GLOBALS.G_DFLT_HSCREDIT_FOR_SREP,
1981 				p_param1					=>  p_x_header_rec.header_id,
1982 				p_param2					=> p_x_header_rec.salesrep_id,
1983 				x_return_status				=> l_return_status);
1984 			  END IF;
1985 
1986 			 /* Else added for bug 4139105 */
1987 		       ELSE
1988 			 IF OE_Validate_Header_Scredit.G_Create_Auto_Sales_Credit = 'Y' THEN
1989 			    OE_DELAYED_REQUESTS_PVT.Delete_Request
1990                                (
1991 				p_entity_code   => OE_GLOBALS.G_ENTITY_HEADER,
1992 				p_entity_id     => p_x_header_rec.header_id,
1993 				p_request_type  => OE_GLOBALS.G_DFLT_HSCREDIT_FOR_SREP,
1994 				x_return_status => l_return_status
1995                                );
1996 			 END IF;
1997                          /* End of bug 4139105 */
1998 
1999 		      END IF;
2000 
2001 		END IF;
2002 
2003 		NULL;
2004 	END IF;
2005 	oe_debug_pub.add('Raj3', 1);
2006 
2007     IF NOT OE_GLOBALS.Equal(p_x_header_rec.sold_to_org_id,p_old_header_rec.sold_to_org_id)
2008     THEN
2009        IF p_x_header_rec.operation = OE_GLOBALS.G_OPR_UPDATE
2010 	 AND p_x_header_rec.payment_type_code = 'CREDIT_CARD' THEN
2011 
2012 	   -- Set Flag to Log a request for Verify Payment
2013 	   oe_debug_pub.add('Log Verify Payment Delayed Request in Sold To',3);
2014 	   --
2015 	   l_verify_payment_flag := 'Y';
2016        END IF;
2017 
2018        IF p_x_header_rec.operation = OE_GLOBALS.G_OPR_UPDATE THEN
2019           -- Log request to evaluate Holds.
2020           oe_debug_pub.ADD('Customer update: logging request for eval_hold_source',1);
2021           oe_debug_pub.ADD('Header ID:' || to_char(p_x_header_rec.header_id) ||
2022                            'Entity ID:' || to_char(p_x_header_rec.sold_to_org_id),1);
2023           OE_delayed_requests_Pvt.log_request
2024                  (p_entity_code            => OE_GLOBALS.G_ENTITY_HEADER,
2025                   p_entity_id              => p_x_header_rec.header_id,
2026                   p_requesting_entity_code => OE_GLOBALS.G_ENTITY_HEADER,
2027                   p_requesting_entity_id   => p_x_header_rec.header_id,
2028                   p_request_type           => OE_GLOBALS.G_EVAL_HOLD_SOURCE,
2029                   p_request_unique_key1    => 'CUSTOMER',
2030                   p_param1                 => 'C',
2031                   p_param2                 => p_x_header_rec.sold_to_org_id,
2032                   x_return_status          => l_return_status);
2033           oe_debug_pub.ADD('after call to log_request: l_return_status: '||l_return_status , 1);
2034        END IF;
2035 
2036 
2037     END IF;
2038 
2039 	 -- ER#3667551 start
2040 
2041 	IF NOT OE_GLOBALS.Equal(p_x_header_rec.invoice_to_org_id,p_old_header_rec.invoice_to_org_id)
2042     THEN
2043        -- only if system parameter is set to BTH then processing for BTH case needs to be done
2044        IF p_x_header_rec.operation = OE_GLOBALS.G_OPR_UPDATE AND l_credithold_cust ='BTH' THEN
2045           -- Log request to evaluate Holds.
2046           oe_debug_pub.ADD('Bill to Customer update: logging request for eval_hold_source',1);
2047 		  l_bill_to_cust_id := OE_Bulk_Holds_PVT.CustAcctID_func
2048 			                             (p_in_site_id => p_x_header_rec.invoice_to_org_id,
2049                                           p_out_IDfound=> l_new_tbl_entry);
2050 
2051           oe_debug_pub.ADD('Header ID:' || to_char(p_x_header_rec.header_id) ||
2052                            'Entity ID:' || to_char(l_bill_to_cust_id),1);
2053 
2054 
2055 		  OE_delayed_requests_Pvt.log_request
2056                  (p_entity_code            => OE_GLOBALS.G_ENTITY_HEADER,
2057                   p_entity_id              => p_x_header_rec.header_id,
2058                   p_requesting_entity_code => OE_GLOBALS.G_ENTITY_HEADER,
2059                   p_requesting_entity_id   => p_x_header_rec.header_id,
2060                   p_request_type           => OE_GLOBALS.G_EVAL_HOLD_SOURCE,
2061                   p_request_unique_key1    => 'BILL_TO_CUSTOMER',
2062                   p_param1                 => 'BTH',
2063                   p_param2                 => l_bill_to_cust_id,
2064                   x_return_status          => l_return_status);
2065           oe_debug_pub.ADD('after call to log_request: l_return_status: '||l_return_status , 1);
2066        END IF;
2067 
2068 
2069     END IF;
2070 	 -- ER#3667551 end
2071 
2072     IF NOT OE_GLOBALS.Equal(p_x_header_rec.tax_point_code,p_old_header_rec.tax_point_code)
2073     THEN
2074         NULL;
2075     END IF;
2076 
2077     IF NOT OE_GLOBALS.Equal(p_x_header_rec.transactional_curr_code,p_old_header_rec.transactional_curr_code)
2078     THEN
2079       IF p_x_header_rec.operation = OE_GLOBALS.G_OPR_UPDATE
2080 	 THEN
2081 
2082 	 	IF  p_x_header_rec.payment_type_code = 'CREDIT_CARD' THEN
2083 
2084 	   	-- Set Flag to Log a request for Verify Payment
2085 	   	oe_debug_pub.add('Log Verify Payment Delayed Request in Curr Code',3);
2086 	        l_verify_payment_flag                         := 'Y';
2087 	        OE_CREDIT_ENGINE_GRP.TOLERANCE_CHECK_REQUIRED := FALSE; --ER 12363706
2088 		ELSE
2089 			 /*  Additional Task - If the payment type is not CREDIT CARD,
2090 			 then also log delayed req for verify payment if the
2091 			 order is booked */
2092 
2093 			 if p_x_header_rec.booked_flag ='Y' then
2094 				 oe_debug_pub.add('Log Verify Payment Delayed Request in Currency Code',3);
2095 			         l_verify_payment_flag                         := 'Y';
2096 			         OE_CREDIT_ENGINE_GRP.TOLERANCE_CHECK_REQUIRED := FALSE; --ER 12363706
2097 			 end if;
2098 	     END IF;
2099 	 END IF;
2100     END IF;
2101 
2102 	IF 	NOT OE_GLOBALS.Equal(p_x_header_rec.payment_type_code,p_old_header_rec.payment_type_code)
2103 	THEN
2104 		IF p_x_header_rec.operation = OE_GLOBALS.G_OPR_UPDATE THEN
2105 		   --R12 CC Encryption
2106 		   --Credit card processing would
2107 		   --now be handled in pre_write_process procedure
2108 		   IF p_x_header_rec.payment_type_code IS NOT NULL
2109 		   AND p_x_header_rec.payment_type_code <> 'CREDIT_CARD' THEN
2110 			-- Set Flag Log a request for Verify Payment
2111 			oe_debug_pub.add('Log Verify Payment Delayed Request in Payment Type',3);
2112 		        l_verify_payment_flag                         := 'Y';
2113 		        OE_CREDIT_ENGINE_GRP.TOLERANCE_CHECK_REQUIRED := FALSE; --ER 12363706
2114                         l_payments_upd_flag := 'Y';
2115 		   END IF;
2116 
2117 		   --R12 CC Encryption
2118 		END IF;
2119 	END IF;
2120      IF 	NOT OE_GLOBALS.Equal(p_x_header_rec.payment_amount,p_old_header_rec.payment_amount)
2121 	THEN
2122 		IF 		p_x_header_rec.operation = OE_GLOBALS.G_OPR_UPDATE
2123 		AND 	p_x_header_rec.payment_type_code in ('CASH', 'CHECK')
2124 THEN
2125 
2126 	   -- Set Flag to Log a request for Verify Payment
2127 			oe_debug_pub.add('Log Update Payments Delayed',3);
2128 	   --
2129 			--l_verify_payment_flag := 'Y';
2130 
2131                         l_payments_upd_flag := 'Y';
2132 
2133 		END IF;
2134        END IF;
2135 
2136        IF NOT OE_GLOBALS.Equal(p_x_header_rec.check_number,p_old_header_rec.check_number)
2137 	THEN
2138 		IF 		p_x_header_rec.operation = OE_GLOBALS.G_OPR_UPDATE
2139 		AND 	p_x_header_rec.payment_type_code = 'CHECK'
2140 THEN
2141 
2142 	   -- Set Flag to Log a request for Verify Payment
2143 			oe_debug_pub.add('Log Update Payments Delayed',3);
2144 	   --
2145 			--l_verify_payment_flag := 'Y';
2146 
2147                         l_payments_upd_flag := 'Y';
2148 
2149 		END IF;
2150        END IF;
2151 
2152 
2153 	IF 	NOT OE_GLOBALS.Equal(p_x_header_rec.credit_card_holder_name,p_old_header_rec.credit_card_holder_name)
2154 	THEN
2155 		IF 		p_x_header_rec.operation = OE_GLOBALS.G_OPR_UPDATE
2156 		AND 	p_x_header_rec.payment_type_code = 'CREDIT_CARD' THEN
2157 
2158 	   -- Set Flag to Log a request for Verify Payment
2159 			oe_debug_pub.add('Log Verify Payment Delayed Request in CC Holder',3);
2160 	   --
2161 			l_verify_payment_flag := 'Y';
2162 
2163     		        --R12 CC Encryption
2164 		        --Credit card processing would now be handled in pre_write_process procedure
2165 				--l_payments_upd_flag := 'Y';
2166 			--R12 CC Encryption
2167 
2168 		END IF;
2169 	END IF;
2170 
2171     IF NOT OE_GLOBALS.Is_Same_Credit_Card(p_old_header_rec.credit_card_number,
2172 	    p_x_header_rec.credit_card_number,
2173 	    p_old_header_rec.cc_instrument_id,
2174 	    p_x_header_rec.cc_instrument_id)
2175     THEN
2176 		IF	p_x_header_rec.operation = OE_GLOBALS.G_OPR_UPDATE
2177 		AND	p_x_header_rec.payment_type_code = 'CREDIT_CARD' THEN
2178 
2179 	   -- Set Flag to Log a request for Verify Payment
2180 			oe_debug_pub.add('Log Verify Payment Delayed Request in CC Number',3);
2181 	   --
2182 			l_verify_payment_flag := 'Y';
2183 
2184      		        --R12 CC Encryption
2185 		        --Credit card processing would now be handled in pre_write_process procedure
2186 				--l_payments_upd_flag := 'Y';
2187 
2188 			--R12 CC Encryption
2189 		END IF;
2190 	END IF;
2191 	oe_debug_pub.add('Raj4', 1);
2192 
2193 	IF 	NOT OE_GLOBALS.Equal(p_x_header_rec.credit_card_expiration_date,p_old_header_rec.credit_card_expiration_date)
2194 	THEN
2195 	       /* Fix Bug # 3686048(FP 3659342): Set the Exp Date as the Last Day of the Month */
2196                 select last_day(p_x_header_rec.credit_card_expiration_date)
2197                 into   p_x_header_rec.credit_card_expiration_date from dual;
2198 
2199          	IF  p_x_header_rec.operation = OE_GLOBALS.G_OPR_UPDATE
2200 		AND p_x_header_rec.payment_type_code = 'CREDIT_CARD' THEN
2201 
2202 	   -- Set Flag to Log a request for Verify Payment
2203 			oe_debug_pub.add('Log Verify Payment Delayed Request in CC Exp Date',3);
2204 	   --
2205 			l_verify_payment_flag := 'Y';
2206 
2207      		        --R12 CC Encryption
2208 		        --Credit card processing would now be handled in pre_write_process procedure
2209 				--l_payments_upd_flag := 'Y';
2210 			--R12 CC Encryption
2211 
2212 		END IF;
2213 	END IF;
2214 
2215 	IF 	NOT OE_GLOBALS.Equal(p_x_header_rec.credit_card_approval_code,p_old_header_rec.credit_card_approval_code)
2216 	THEN
2217 		IF  p_x_header_rec.operation = OE_GLOBALS.G_OPR_UPDATE
2218 		AND p_x_header_rec.payment_type_code = 'CREDIT_CARD' THEN
2219 
2220 	   -- Set Flag to Log a request for Verify Payment
2221 			oe_debug_pub.add('Log Verify Payment Delayed Request in CC Approval',3);
2222 	   --
2223 			l_verify_payment_flag := 'Y';
2224 
2225      		        --R12 CC Encryption
2226 		        --Credit card processing would now be handled in pre_write_process procedure
2227 				--l_payments_upd_flag := 'Y';
2228 			--R12 CC Encryption
2229 
2230 		END IF;
2231 	END IF;
2232 
2233 
2234      /* Fix for 1559906: New Procedure to Copy Freight Charges */
2235 
2236      IF   (NOT OE_GLOBALS.Equal(p_x_header_rec.source_document_type_id,
2237                                 p_old_header_rec.source_document_type_id)) OR
2238            (p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
2239             AND p_x_header_rec.source_document_type_id = 2)
2240             --OR condition added for bug 5060064
2241      THEN
2242           IF  p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
2243           AND p_x_header_rec.source_document_type_id = 2 THEN
2244 
2245                -- Added IF condition for bug 6697401
2246 	       IF OE_ORDER_COPY_UTIL.G_COPY_REC.line_price_mode =
2247 	          OE_ORDER_COPY_UTIL.G_CPY_ORIG_PRICE THEN
2248 
2249 	   	       oe_debug_pub.add(' Copy as original price');
2250 	               -- bug 6697401
2251 	      	       -- Log a request to copy Freight Charges to the copied order.
2252 	               oe_debug_pub.add('Log Delayed Request To Copy Charges in SRC Doc Type Id',3);
2253 
2254 	       	       OE_delayed_requests_Pvt.log_request(
2255 	       	       p_entity_code            => OE_GLOBALS.G_ENTITY_HEADER,
2256 	       	       p_entity_id              => p_x_header_rec.header_id,
2257 	       	       p_requesting_entity_code => OE_GLOBALS.G_ENTITY_HEADER,
2258 	       	       p_requesting_entity_id   => p_x_header_rec.header_id,
2259 	      	       p_param1                 => p_x_header_rec.order_category_code,
2260 	       	       p_param2                 => p_x_header_rec.source_document_id,
2261 	       	       p_request_type           => OE_GLOBALS.G_COPY_FREIGHT_CHARGES,
2262 	      	       x_return_status          => l_return_status);
2263                END IF;  -- bug 6697401
2264           END IF;
2265      END IF;
2266 
2267 /* Added the following code to fix the bug 2170086 */
2268      IF   NOT OE_GLOBALS.Equal(p_x_header_rec.source_document_type_id,p_old_header_rec.source_document_type_id) OR
2269            (p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
2270             AND p_x_header_rec.source_document_type_id = 2 )
2271             --OR condition added for bug 5060064
2272      THEN
2273           IF  p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
2274           AND p_x_header_rec.source_document_type_id = 2 THEN
2275 
2276             -- Log a request to copy header adjustments to the copied order.
2277             oe_debug_pub.add('Log Delayed Request To Copy header adjustments ',3);
2278             --
2279 
2280             IF OE_ORDER_COPY_UTIL.G_COPY_REC.line_price_mode IN (OE_ORDER_COPY_UTIL.G_CPY_ORIG_PRICE,OE_ORDER_COPY_UTIL.G_CPY_REPRICE_PARTIAL) THEN
2281               oe_debug_pub.add(' Copy as original price');
2282               OE_delayed_requests_Pvt.log_request(
2283               p_entity_code            => OE_GLOBALS.G_ENTITY_HEADER,
2284               p_entity_id              => p_x_header_rec.header_id,
2285               p_requesting_entity_code => OE_GLOBALS.G_ENTITY_HEADER,
2286               p_requesting_entity_id   => p_x_header_rec.header_id,
2287               p_param1                 => p_x_header_rec.order_category_code,
2288               p_param2                 => p_x_header_rec.source_document_id,
2289               p_request_type           => OE_GLOBALS.G_COPY_HEADER_ADJUSTMENTS ,
2290               x_return_status          => l_return_status);
2291             END IF;
2292           END IF;
2293      END IF;
2294 
2295 /* End of the code added to fix the bug 2170086 */
2296    -- Bug 2619506
2297      IF (NOT OE_GLOBALS.Equal(p_x_header_rec.transactional_curr_code,p_old_header_rec.transactional_curr_code)) OR
2298         (p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE AND
2299          p_x_header_rec.transactional_curr_code IS NOT NULL)
2300          -- OR condition added for bug 5060064
2301         THEN
2302          IF p_x_header_rec.operation = OE_GLOBALS.G_OPR_UPDATE
2303           THEN
2304            If  nvl(p_x_header_rec.booked_flag, 'N')  <> 'Y'  Then
2305             OE_delayed_requests_Pvt.log_request(
2306             p_entity_code            => OE_GLOBALS.G_ENTITY_ALL,
2307             p_entity_id              => p_x_header_rec.header_id,
2308             p_requesting_entity_code => OE_GLOBALS.G_ENTITY_ALL,
2309             p_requesting_entity_id   => p_x_header_rec.header_id,
2310             p_param1                 => p_x_header_rec.header_id,
2311             p_param2                 => 'BATCH',
2312             p_request_unique_key1    => 'BATCH',
2313             p_param3                 =>  'PRICE_ORDER',
2314             p_request_type           =>  OE_GLOBALS.G_PRICE_ORDER,
2315             x_return_status          => l_return_status);
2316            Else
2317             OE_delayed_requests_Pvt.log_request(
2318             p_entity_code            => OE_GLOBALS.G_ENTITY_ALL,
2319             p_entity_id              => p_x_header_rec.header_id,
2320             p_requesting_entity_code => OE_GLOBALS.G_ENTITY_ALL,
2321             p_requesting_entity_id   => p_x_header_rec.header_id,
2322             p_param1                 => p_x_header_rec.header_id,
2323             p_param2                 => 'BATCH,BOOK',
2324             p_request_unique_key1    => 'BATCH,BOOK',
2325             p_param3                 =>  'PRICE_ORDER',
2326             p_request_type           =>  OE_GLOBALS.G_PRICE_ORDER,
2327             x_return_status          => l_return_status);
2328          End If;
2329 		 -- sol_ord_er #16014165 start
2330 			oe_delayed_requests_pvt.log_request(
2331 							 p_entity_code            => OE_GLOBALS.G_ENTITY_ALL,
2332 							 p_entity_id              => p_x_header_rec.Header_Id,
2333 							 p_requesting_entity_code => OE_GLOBALS.G_ENTITY_ALL,
2334 							 p_requesting_entity_id   => p_x_header_rec.Header_Id,
2335 							 p_request_type           => OE_GLOBALS.G_SERVICE_FIRST_PERIOD_BILL,
2336 							 p_request_unique_key1 => 'ORDER',
2337 							 p_param1                 => p_x_header_rec.Header_Id,
2338 							 x_return_status          => l_return_status);
2339 		-- sol_ord_er #16014165 end
2340 
2341 	 -- Bug 10194125 : Start
2342 	 oe_debug_pub.add('Logging GET_COST request for all lines ...',5);
2343 	 FOR i in lines_cur LOOP
2344          	oe_debug_pub.add('Fetching line_id :' || i.line_id ,0);
2345 
2346 	        IF Oe_Sys_Parameters.Value('COMPUTE_MARGIN') <> 'N' Then
2347 	        	oe_debug_pub.add(  'before oe_delayed_requests_pvt.log_request call',5 ) ;
2348 	 	       	oe_delayed_requests_pvt.log_request(
2349 	                        p_entity_code            => OE_GLOBALS.G_ENTITY_LINE,
2350 	                        p_entity_id              => i.line_id,
2351 	             	        p_requesting_entity_code => OE_GLOBALS.G_ENTITY_ALL,
2352 	                        p_requesting_entity_id   => p_x_header_rec.header_id,
2353 	                        p_request_type           => 'GET_COST',
2354 	                        x_return_status          => l_return_status);
2355 	 				oe_debug_pub.add( 'After OE_DELAYED_REQUESTS_PVT.LOG_REQUEST CALL '||l_return_status ,5) ;
2356 	         END IF;
2357 	 END LOOP;
2358 	 -- Bug 10194125 : End
2359        End If;
2360      End If;
2361 
2362 --ER#7479609 start
2363 	IF  NOT OE_GLOBALS.Equal(p_x_header_rec.payment_type_code,p_old_header_rec.payment_type_code)
2364 	AND p_x_header_rec.operation = OE_GLOBALS.G_OPR_UPDATE
2365 	THEN
2366 	  OE_Holds_PUB.G_PAYMENT_HOLD_APPLIED := 'N';
2367 	  OE_Holds_PUB.G_HDR_PAYMENT := 'Y';
2368           oe_debug_pub.ADD('payment type update: logging request for eval_hold_source',1);
2369           oe_debug_pub.ADD('Header ID:' || to_char(p_x_header_rec.header_id) ||
2370                            'Entity ID:' || to_char(p_x_header_rec.payment_type_code),1);
2371           OE_delayed_requests_Pvt.log_request
2372                  (p_entity_code            => OE_GLOBALS.G_ENTITY_HEADER,
2373                   p_entity_id              => p_x_header_rec.header_id,
2374                   p_requesting_entity_code => OE_GLOBALS.G_ENTITY_HEADER,
2375                   p_requesting_entity_id   => p_x_header_rec.header_id,
2376                   p_request_type           => OE_GLOBALS.G_EVAL_HOLD_SOURCE,
2377                   p_request_unique_key1    => 'PAYMENT_TYPE',
2378                   p_param1                 => 'P',
2379                   p_param2                 => p_x_header_rec.payment_type_code,
2380                   x_return_status          => l_return_status);
2381           oe_debug_pub.ADD('after call to log_request: l_return_status: '||l_return_status , 1);
2382 
2383 	END IF;
2384 
2385 	IF  NOT OE_GLOBALS.Equal(p_x_header_rec.transactional_curr_code,p_old_header_rec.transactional_curr_code)
2386 	AND p_x_header_rec.operation = OE_GLOBALS.G_OPR_UPDATE
2387 	THEN
2388           oe_debug_pub.ADD('Currency update: logging request for eval_hold_source',1);
2389           oe_debug_pub.ADD('Header ID:' || to_char(p_x_header_rec.header_id) ||
2390                            'Entity ID:' || to_char(p_x_header_rec.transactional_curr_code),1);
2391           OE_delayed_requests_Pvt.log_request
2392                  (p_entity_code            => OE_GLOBALS.G_ENTITY_HEADER,
2393                   p_entity_id              => p_x_header_rec.header_id,
2394                   p_requesting_entity_code => OE_GLOBALS.G_ENTITY_HEADER,
2395                   p_requesting_entity_id   => p_x_header_rec.header_id,
2396                   p_request_type           => OE_GLOBALS.G_EVAL_HOLD_SOURCE,
2397                   p_request_unique_key1    => 'CURRENCY',
2398                   p_param1                 => 'TC',
2399                   p_param2                 => p_x_header_rec.transactional_curr_code,
2400                   x_return_status          => l_return_status);
2401           oe_debug_pub.ADD('after call to log_request: l_return_status: '||l_return_status , 1);
2402 
2403 	END IF;
2404 
2405 	IF  NOT OE_GLOBALS.Equal(p_x_header_rec.sales_channel_code,p_old_header_rec.sales_channel_code)
2406 	AND p_x_header_rec.operation = OE_GLOBALS.G_OPR_UPDATE
2407 	THEN
2408           oe_debug_pub.ADD('sales channel update: logging request for eval_hold_source',1);
2409           oe_debug_pub.ADD('Header ID:' || to_char(p_x_header_rec.header_id) ||
2410                            'Entity ID:' || to_char(p_x_header_rec.sales_channel_code),1);
2411           OE_delayed_requests_Pvt.log_request
2412                  (p_entity_code            => OE_GLOBALS.G_ENTITY_HEADER,
2413                   p_entity_id              => p_x_header_rec.header_id,
2414                   p_requesting_entity_code => OE_GLOBALS.G_ENTITY_HEADER,
2415                   p_requesting_entity_id   => p_x_header_rec.header_id,
2416                   p_request_type           => OE_GLOBALS.G_EVAL_HOLD_SOURCE,
2417                   p_request_unique_key1    => 'SALES_CHANNEL',
2418                   p_param1                 => 'SC',
2419                   p_param2                 => p_x_header_rec.sales_channel_code,
2420                   x_return_status          => l_return_status);
2421           oe_debug_pub.ADD('after call to log_request: l_return_status: '||l_return_status , 1);
2422 
2423 	END IF;
2424 
2425 	IF  NOT OE_GLOBALS.Equal(p_x_header_rec.price_list_id,p_old_header_rec.price_list_id)
2426 	AND p_x_header_rec.operation = OE_GLOBALS.G_OPR_UPDATE
2427 	THEN
2428           oe_debug_pub.ADD('price list update: logging request for eval_hold_source',1);
2429           oe_debug_pub.ADD('Header ID:' || to_char(p_x_header_rec.header_id) ||
2430                            'Entity ID:' || to_char(p_x_header_rec.price_list_id),1);
2431           OE_delayed_requests_Pvt.log_request
2432                  (p_entity_code            => OE_GLOBALS.G_ENTITY_HEADER,
2433                   p_entity_id              => p_x_header_rec.header_id,
2434                   p_requesting_entity_code => OE_GLOBALS.G_ENTITY_HEADER,
2435                   p_requesting_entity_id   => p_x_header_rec.header_id,
2436                   p_request_type           => OE_GLOBALS.G_EVAL_HOLD_SOURCE,
2437                   p_request_unique_key1    => 'PRICE_LIST',
2438                   p_param1                 => 'PL',
2439                   p_param2                 => p_x_header_rec.price_list_id,
2440                   x_return_status          => l_return_status);
2441           oe_debug_pub.ADD('after call to log_request: l_return_status: '||l_return_status , 1);
2442 
2443 	END IF;
2444 
2445 	IF  NOT OE_GLOBALS.Equal(p_x_header_rec.order_type_id,p_old_header_rec.order_type_id)
2446 	AND p_x_header_rec.operation = OE_GLOBALS.G_OPR_UPDATE
2447 	THEN
2448           oe_debug_pub.ADD('Order type update: logging request for eval_hold_source',1);
2449           oe_debug_pub.ADD('Header ID:' || to_char(p_x_header_rec.header_id) ||
2450                            'Entity ID:' || to_char(p_x_header_rec.order_type_id),1);
2451           OE_delayed_requests_Pvt.log_request
2452                  (p_entity_code            => OE_GLOBALS.G_ENTITY_HEADER,
2453                   p_entity_id              => p_x_header_rec.header_id,
2454                   p_requesting_entity_code => OE_GLOBALS.G_ENTITY_HEADER,
2455                   p_requesting_entity_id   => p_x_header_rec.header_id,
2456                   p_request_type           => OE_GLOBALS.G_EVAL_HOLD_SOURCE,
2457                   p_request_unique_key1    => 'ORDER_TYPE',
2458                   p_param1                 => 'OT',
2459                   p_param2                 => p_x_header_rec.order_type_id,
2460                   x_return_status          => l_return_status);
2461           oe_debug_pub.ADD('after call to log_request: l_return_status: '||l_return_status , 1);
2462 
2463 	END IF;
2464 --ER#7479609 end
2465 
2466 	IF	(l_verify_payment_flag = 'Y') THEN
2467 
2468 	 -- Log a request for Verify Payment
2469 		oe_debug_pub.add('Logging Delayed Request for Verify Payment',3);
2470 	 --
2471 		OE_delayed_requests_Pvt.log_request
2472 		(p_entity_code            => OE_GLOBALS.G_ENTITY_ALL,
2473 		p_entity_id              => p_x_header_rec.header_id,
2474 		p_requesting_entity_code => OE_GLOBALS.G_ENTITY_HEADER,
2475 		p_requesting_entity_id   => p_x_header_rec.header_id,
2476 		p_request_type           => OE_GLOBALS.G_VERIFY_PAYMENT,
2477 		x_return_status          => l_return_status);
2478 
2479 	END IF;
2480 
2481     /* code added by Renga for multiple payments */
2482      l_payment_count := 0;
2483      Begin
2484 
2485       oe_debug_pub.add('before getting payment count ', 1);
2486       open payment_count_cur;
2487       fetch payment_count_cur into l_payment_count;
2488       close payment_count_cur;
2489 
2490      Exception
2491 
2492        when others then
2493          l_payment_count := 0;
2494 
2495      End;
2496 
2497       IF OE_PrePayment_UTIL.IS_MULTIPLE_PAYMENTS_ENABLED = TRUE
2498          and l_payments_upd_flag = 'Y'
2499          and l_payment_count > 0 then --modified for bug 3733877
2500 
2501 	oe_debug_pub.add('logging synch payment delayed request', 1);
2502 
2503        OE_delayed_requests_Pvt.log_request
2504 		(p_entity_code            => OE_GLOBALS.G_ENTITY_ALL,
2505 		p_entity_id              => p_x_header_rec.header_id,
2506 		p_requesting_entity_code => OE_GLOBALS.G_ENTITY_HEADER,
2507 		p_requesting_entity_id   => p_x_header_rec.header_id,
2508 		p_request_type           => OE_GLOBALS.G_UPDATE_HDR_PAYMENT,
2509                 p_param1                 => 'UPDATE_PAYMENT',
2510 		x_return_status          => l_return_status);
2511 
2512       END IF; -- if multiple payments enabled and l_payments_upd_flag = 'Y'
2513               -- and l_payment_count = 1
2514      /*-- 3288805
2515       Store the new order_date_type_code--*/
2516       IF (NOT OE_GLOBALS.Equal(p_x_header_rec.order_date_type_code, p_old_header_rec.order_date_type_code)) OR
2517          (p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE AND
2518            p_x_header_rec.order_date_type_code IS NOT NULL)
2519        --OR cnd added for bug 5060064
2520       THEN
2521          IF ( nvl(OE_Schedule_Util.G_HEADER_ID, 0) = p_x_header_rec.header_id )
2522 THEN
2523             OE_Schedule_Util.G_DATE_TYPE := p_x_header_rec.order_date_type_code;         END IF;
2524       END IF;
2525      /*-- 3288805 --*/
2526 	oe_debug_pub.add('Exiting OE_HEADER_UTIL.APPLY_ATTRIBUTE_CHANGES', 1);
2527 
2528 END Apply_Attribute_Changes;
2529 
2530 --  Procedure Complete_Record
2531 
2532 PROCEDURE Complete_Record
2533 (   p_x_header_rec                    IN OUT NOCOPY OE_Order_PUB.Header_Rec_Type
2534 ,   p_old_header_rec                IN  OE_Order_PUB.Header_Rec_Type
2535 )
2536 IS
2537 
2538 BEGIN
2539 
2540 	oe_debug_pub.add('Entering OE_HEADER_UTIL.COMPLETE_RECORD', 1);
2541 
2542 	IF 	p_x_header_rec.accounting_rule_id = FND_API.G_MISS_NUM THEN
2543 		p_x_header_rec.accounting_rule_id := p_old_header_rec.accounting_rule_id;
2544 	END IF;
2545 
2546 	IF 	p_x_header_rec.accounting_rule_duration = FND_API.G_MISS_NUM THEN
2547 		p_x_header_rec.accounting_rule_duration := p_old_header_rec.accounting_rule_duration;
2548 	END IF;
2549 
2550 	IF 	p_x_header_rec.agreement_id = FND_API.G_MISS_NUM THEN
2551 		p_x_header_rec.agreement_id := p_old_header_rec.agreement_id;
2552 	END IF;
2553 
2554 	IF 	p_x_header_rec.upgraded_flag = FND_API.G_MISS_CHAR THEN
2555 		p_x_header_rec.upgraded_flag := p_old_header_rec.upgraded_flag;
2556 	END IF;
2557 
2558         IF      p_x_header_rec.blanket_number = FND_API.G_MISS_NUM THEN
2559                 p_x_header_rec.blanket_number := p_old_header_rec.blanket_number;
2560         END IF;
2561 
2562 	IF 	p_x_header_rec.booked_flag = FND_API.G_MISS_CHAR THEN
2563 		p_x_header_rec.booked_flag := p_old_header_rec.booked_flag;
2564 	END IF;
2565 
2566 	IF 	p_x_header_rec.booked_date = FND_API.G_MISS_DATE THEN
2567 		p_x_header_rec.booked_date := p_old_header_rec.booked_date;
2568 	END IF;
2569 
2570 	IF 	p_x_header_rec.cancelled_flag = FND_API.G_MISS_CHAR THEN
2571 		p_x_header_rec.cancelled_flag := p_old_header_rec.cancelled_flag;
2572 	END IF;
2573 
2574 	IF 	p_x_header_rec.attribute1 = FND_API.G_MISS_CHAR THEN
2575 		p_x_header_rec.attribute1 := p_old_header_rec.attribute1;
2576 	END IF;
2577 
2578 	IF 	p_x_header_rec.attribute10 = FND_API.G_MISS_CHAR THEN
2579 		p_x_header_rec.attribute10 := p_old_header_rec.attribute10;
2580 	END IF;
2581 
2582 	IF 	p_x_header_rec.attribute11 = FND_API.G_MISS_CHAR THEN
2583 		p_x_header_rec.attribute11 := p_old_header_rec.attribute11;
2584 	END IF;
2585 
2586 	IF 	p_x_header_rec.attribute12 = FND_API.G_MISS_CHAR THEN
2587 		p_x_header_rec.attribute12 := p_old_header_rec.attribute12;
2588 	END IF;
2589 
2590 	IF 	p_x_header_rec.attribute13 = FND_API.G_MISS_CHAR THEN
2591 		p_x_header_rec.attribute13 := p_old_header_rec.attribute13;
2592 	END IF;
2593 
2594 	IF 	p_x_header_rec.attribute14 = FND_API.G_MISS_CHAR THEN
2595 		p_x_header_rec.attribute14 := p_old_header_rec.attribute14;
2596 	END IF;
2597 
2598 	IF 	p_x_header_rec.attribute15 = FND_API.G_MISS_CHAR THEN
2599 		p_x_header_rec.attribute15 := p_old_header_rec.attribute15;
2600 	END IF;
2601 
2602 	IF 	p_x_header_rec.attribute16 = FND_API.G_MISS_CHAR THEN --bug 2184255
2603 		p_x_header_rec.attribute16 := p_old_header_rec.attribute16;
2604 	END IF;
2605 
2606 	IF 	p_x_header_rec.attribute17 = FND_API.G_MISS_CHAR THEN
2607 		p_x_header_rec.attribute17 := p_old_header_rec.attribute17;
2608 	END IF;
2609 
2610 	IF 	p_x_header_rec.attribute18 = FND_API.G_MISS_CHAR THEN
2611 		p_x_header_rec.attribute18 := p_old_header_rec.attribute18;
2612 	END IF;
2613 
2614 	IF 	p_x_header_rec.attribute19 = FND_API.G_MISS_CHAR THEN
2615 		p_x_header_rec.attribute19 := p_old_header_rec.attribute19;
2616 	END IF;
2617 
2618 	IF 	p_x_header_rec.attribute2 = FND_API.G_MISS_CHAR THEN
2619 		p_x_header_rec.attribute2 := p_old_header_rec.attribute2;
2620 	END IF;
2621 
2622 	IF 	p_x_header_rec.attribute20 = FND_API.G_MISS_CHAR THEN --bug2184255
2623 		p_x_header_rec.attribute20:= p_old_header_rec.attribute20;
2624 	END IF;
2625 
2626 	IF 	p_x_header_rec.attribute3 = FND_API.G_MISS_CHAR THEN
2627 		p_x_header_rec.attribute3 := p_old_header_rec.attribute3;
2628 	END IF;
2629 
2630 	IF 	p_x_header_rec.attribute4 = FND_API.G_MISS_CHAR THEN
2631 		p_x_header_rec.attribute4 := p_old_header_rec.attribute4;
2632 	END IF;
2633 
2634 	IF 	p_x_header_rec.attribute5 = FND_API.G_MISS_CHAR THEN
2635 		p_x_header_rec.attribute5 := p_old_header_rec.attribute5;
2636 	END IF;
2637 
2638 	IF 	p_x_header_rec.attribute6 = FND_API.G_MISS_CHAR THEN
2639 		p_x_header_rec.attribute6 := p_old_header_rec.attribute6;
2640 	END IF;
2641 
2642 	IF 	p_x_header_rec.attribute7 = FND_API.G_MISS_CHAR THEN
2643 		p_x_header_rec.attribute7 := p_old_header_rec.attribute7;
2644 	END IF;
2645 
2646 	IF 	p_x_header_rec.attribute8 = FND_API.G_MISS_CHAR THEN
2647 		p_x_header_rec.attribute8 := p_old_header_rec.attribute8;
2648 	END IF;
2649 
2650 	IF 	p_x_header_rec.attribute9 = FND_API.G_MISS_CHAR THEN
2651 		p_x_header_rec.attribute9 := p_old_header_rec.attribute9;
2652 	END IF;
2653 
2654 	IF 	p_x_header_rec.context = FND_API.G_MISS_CHAR THEN
2655 		p_x_header_rec.context := p_old_header_rec.context;
2656 	END IF;
2657 
2658 	IF 	p_x_header_rec.conversion_rate = FND_API.G_MISS_NUM THEN
2659 		p_x_header_rec.conversion_rate := p_old_header_rec.conversion_rate;
2660 	END IF;
2661 
2662 	IF 	p_x_header_rec.conversion_rate_date = FND_API.G_MISS_DATE THEN
2663 		p_x_header_rec.conversion_rate_date := p_old_header_rec.conversion_rate_date;
2664 	END IF;
2665 
2666 	IF 	p_x_header_rec.conversion_type_code = FND_API.G_MISS_CHAR THEN
2667 		p_x_header_rec.conversion_type_code := p_old_header_rec.conversion_type_code;
2668 	END IF;
2669 	IF 	p_x_header_rec.CUSTOMER_PREFERENCE_SET_CODE = FND_API.G_MISS_CHAR THEN
2670 		p_x_header_rec.CUSTOMER_PREFERENCE_SET_CODE := p_old_header_rec.CUSTOMER_PREFERENCE_SET_CODE;
2671 	END IF;
2672 
2673 	IF 	p_x_header_rec.created_by = FND_API.G_MISS_NUM THEN
2674 		p_x_header_rec.created_by := p_old_header_rec.created_by;
2675 	END IF;
2676 
2677 	IF 	p_x_header_rec.creation_date = FND_API.G_MISS_DATE THEN
2678 		p_x_header_rec.creation_date := p_old_header_rec.creation_date;
2679 	END IF;
2680 
2681 	IF 	p_x_header_rec.cust_po_number = FND_API.G_MISS_CHAR THEN
2682 		p_x_header_rec.cust_po_number := p_old_header_rec.cust_po_number;
2683 	END IF;
2684 
2685 	IF 	p_x_header_rec.default_fulfillment_set = FND_API.G_MISS_CHAR THEN
2686 		p_x_header_rec.default_fulfillment_set := p_old_header_rec.default_fulfillment_set;
2687 	END IF;
2688 
2689 
2690 	IF 	p_x_header_rec.deliver_to_contact_id = FND_API.G_MISS_NUM THEN
2691 		p_x_header_rec.deliver_to_contact_id := p_old_header_rec.deliver_to_contact_id;
2692 	END IF;
2693 
2694 	IF 	p_x_header_rec.deliver_to_org_id = FND_API.G_MISS_NUM THEN
2695 		p_x_header_rec.deliver_to_org_id := p_old_header_rec.deliver_to_org_id;
2696 	END IF;
2697 
2698 	IF 	p_x_header_rec.demand_class_code = FND_API.G_MISS_CHAR THEN
2699 		p_x_header_rec.demand_class_code := p_old_header_rec.demand_class_code;
2700 	END IF;
2701 
2702 	IF 	p_x_header_rec.expiration_date = FND_API.G_MISS_DATE THEN
2703 		p_x_header_rec.expiration_date := p_old_header_rec.expiration_date;
2704 	END IF;
2705 
2706 	IF 	p_x_header_rec.earliest_schedule_limit = FND_API.G_MISS_NUM THEN
2707 		p_x_header_rec.earliest_schedule_limit := p_old_header_rec.earliest_schedule_limit;
2708 	END IF;
2709 
2710 	IF 	p_x_header_rec.fob_point_code = FND_API.G_MISS_CHAR THEN
2711 		p_x_header_rec.fob_point_code := p_old_header_rec.fob_point_code;
2712 	END IF;
2713 
2714 	IF 	p_x_header_rec.freight_carrier_code = FND_API.G_MISS_CHAR THEN
2715 		p_x_header_rec.freight_carrier_code := p_old_header_rec.freight_carrier_code;
2716 	END IF;
2717 
2718 	IF 	p_x_header_rec.freight_terms_code = FND_API.G_MISS_CHAR THEN
2719 		p_x_header_rec.freight_terms_code := p_old_header_rec.freight_terms_code;
2720 	END IF;
2721 
2722 	IF 	p_x_header_rec.fulfillment_set_name = FND_API.G_MISS_CHAR THEN
2723 		p_x_header_rec.fulfillment_set_name := p_old_header_rec.fulfillment_set_name;
2724 	END IF;
2725 
2726 	IF 	p_x_header_rec.global_attribute1 = FND_API.G_MISS_CHAR THEN
2727 		p_x_header_rec.global_attribute1 := p_old_header_rec.global_attribute1;
2728 	END IF;
2729 
2730 	IF 	p_x_header_rec.global_attribute10 = FND_API.G_MISS_CHAR THEN
2731 		p_x_header_rec.global_attribute10 := p_old_header_rec.global_attribute10;
2732 	END IF;
2733 
2734 	IF 	p_x_header_rec.global_attribute11 = FND_API.G_MISS_CHAR THEN
2735 		p_x_header_rec.global_attribute11 := p_old_header_rec.global_attribute11;
2736 	END IF;
2737 
2738 	IF 	p_x_header_rec.global_attribute12 = FND_API.G_MISS_CHAR THEN
2739 		p_x_header_rec.global_attribute12 := p_old_header_rec.global_attribute12;
2740 	END IF;
2741 
2742 	IF 	p_x_header_rec.global_attribute13 = FND_API.G_MISS_CHAR THEN
2743 		p_x_header_rec.global_attribute13 := p_old_header_rec.global_attribute13;
2744 	END IF;
2745 
2746 	IF 	p_x_header_rec.global_attribute14 = FND_API.G_MISS_CHAR THEN
2747 		p_x_header_rec.global_attribute14 := p_old_header_rec.global_attribute14;
2748 	END IF;
2749 
2750 	IF 	p_x_header_rec.global_attribute15 = FND_API.G_MISS_CHAR THEN
2751 		p_x_header_rec.global_attribute15 := p_old_header_rec.global_attribute15;
2752 	END IF;
2753 
2754 	IF 	p_x_header_rec.global_attribute16 = FND_API.G_MISS_CHAR THEN
2755 		p_x_header_rec.global_attribute16 := p_old_header_rec.global_attribute16;
2756 	END IF;
2757 
2758 	IF 	p_x_header_rec.global_attribute17 = FND_API.G_MISS_CHAR THEN
2759 		p_x_header_rec.global_attribute17 := p_old_header_rec.global_attribute17;
2760 	END IF;
2761 
2762 	IF 	p_x_header_rec.global_attribute18 = FND_API.G_MISS_CHAR THEN
2763 		p_x_header_rec.global_attribute18 := p_old_header_rec.global_attribute18;
2764 	END IF;
2765 
2766 	IF 	p_x_header_rec.global_attribute19 = FND_API.G_MISS_CHAR THEN
2767 		p_x_header_rec.global_attribute19 := p_old_header_rec.global_attribute19;
2768 	END IF;
2769 
2770 	IF 	p_x_header_rec.global_attribute2 = FND_API.G_MISS_CHAR THEN
2771 		p_x_header_rec.global_attribute2 := p_old_header_rec.global_attribute2;
2772 	END IF;
2773 
2774 	IF 	p_x_header_rec.global_attribute20 = FND_API.G_MISS_CHAR THEN
2775 		p_x_header_rec.global_attribute20 := p_old_header_rec.global_attribute20;
2776 	END IF;
2777 
2778 	IF 	p_x_header_rec.global_attribute3 = FND_API.G_MISS_CHAR THEN
2779 		p_x_header_rec.global_attribute3 := p_old_header_rec.global_attribute3;
2780 	END IF;
2781 
2782 	IF 	p_x_header_rec.global_attribute4 = FND_API.G_MISS_CHAR THEN
2783 		p_x_header_rec.global_attribute4 := p_old_header_rec.global_attribute4;
2784 	END IF;
2785 
2786 	IF 	p_x_header_rec.global_attribute5 = FND_API.G_MISS_CHAR THEN
2787 		p_x_header_rec.global_attribute5 := p_old_header_rec.global_attribute5;
2788 	END IF;
2789 
2790 	IF 	p_x_header_rec.global_attribute6 = FND_API.G_MISS_CHAR THEN
2791 		p_x_header_rec.global_attribute6 := p_old_header_rec.global_attribute6;
2792 	END IF;
2793 
2794 	IF 	p_x_header_rec.global_attribute7 = FND_API.G_MISS_CHAR THEN
2795 		p_x_header_rec.global_attribute7 := p_old_header_rec.global_attribute7;
2796 	END IF;
2797 
2798 	IF 	p_x_header_rec.global_attribute8 = FND_API.G_MISS_CHAR THEN
2799 		p_x_header_rec.global_attribute8 := p_old_header_rec.global_attribute8;
2800 	END IF;
2801 
2802 	IF 	p_x_header_rec.global_attribute9 = FND_API.G_MISS_CHAR THEN
2803 		p_x_header_rec.global_attribute9 := p_old_header_rec.global_attribute9;
2804 	END IF;
2805 
2806 	IF 	p_x_header_rec.global_attribute_category = FND_API.G_MISS_CHAR THEN
2807 		p_x_header_rec.global_attribute_category := p_old_header_rec.global_attribute_category;
2808 	END IF;
2809 
2810 	IF 	p_x_header_rec.header_id = FND_API.G_MISS_NUM THEN
2811 		p_x_header_rec.header_id := p_old_header_rec.header_id;
2812 	END IF;
2813 
2814 	IF 	p_x_header_rec.invoice_to_contact_id = FND_API.G_MISS_NUM THEN
2815 		p_x_header_rec.invoice_to_contact_id := p_old_header_rec.invoice_to_contact_id;
2816 	END IF;
2817 
2818 	IF 	p_x_header_rec.invoice_to_org_id = FND_API.G_MISS_NUM THEN
2819 		p_x_header_rec.invoice_to_org_id := p_old_header_rec.invoice_to_org_id;
2820 	END IF;
2821 
2822 	IF 	p_x_header_rec.invoicing_rule_id = FND_API.G_MISS_NUM THEN
2823 		p_x_header_rec.invoicing_rule_id := p_old_header_rec.invoicing_rule_id;
2824 	END IF;
2825 
2826 	IF 	p_x_header_rec.last_updated_by = FND_API.G_MISS_NUM THEN
2827 		p_x_header_rec.last_updated_by := p_old_header_rec.last_updated_by;
2828 	END IF;
2829 
2830 	IF 	p_x_header_rec.last_update_date = FND_API.G_MISS_DATE THEN
2831 		p_x_header_rec.last_update_date := p_old_header_rec.last_update_date;
2832 	END IF;
2833 
2834 	IF 	p_x_header_rec.last_update_login = FND_API.G_MISS_NUM THEN
2835 		p_x_header_rec.last_update_login := p_old_header_rec.last_update_login;
2836 	END IF;
2837 
2838 	IF 	p_x_header_rec.latest_schedule_limit = FND_API.G_MISS_NUM THEN
2839 		p_x_header_rec.latest_schedule_limit := p_old_header_rec.latest_schedule_limit;
2840 	END IF;
2841 
2842 	IF 	p_x_header_rec.open_flag = FND_API.G_MISS_CHAR THEN
2843 		p_x_header_rec.open_flag := p_old_header_rec.open_flag;
2844 	END IF;
2845 
2846 	IF 	p_x_header_rec.ordered_date = FND_API.G_MISS_DATE THEN
2847 		p_x_header_rec.ordered_date := p_old_header_rec.ordered_date;
2848 	END IF;
2849 
2850 	IF 	p_x_header_rec.order_number = FND_API.G_MISS_NUM THEN
2851 		p_x_header_rec.order_number := p_old_header_rec.order_number;
2852 	END IF;
2853 
2854 	IF 	p_x_header_rec.order_date_type_code = FND_API.G_MISS_CHAR THEN
2855 		p_x_header_rec.order_date_type_code := p_old_header_rec.order_date_type_code;
2856 	END IF;
2857 
2858 	IF 	p_x_header_rec.order_source_id = FND_API.G_MISS_NUM THEN
2859 		p_x_header_rec.order_source_id := p_old_header_rec.order_source_id;
2860 	END IF;
2861 
2862 	IF 	p_x_header_rec.order_type_id = FND_API.G_MISS_NUM THEN
2863 		p_x_header_rec.order_type_id := p_old_header_rec.order_type_id;
2864 	END IF;
2865 
2866 	IF 	p_x_header_rec.order_category_code = FND_API.G_MISS_CHAR THEN
2867 		p_x_header_rec.order_category_code := p_old_header_rec.order_category_code;
2868 	END IF;
2869 
2870 	IF 	p_x_header_rec.org_id = FND_API.G_MISS_NUM THEN
2871 		p_x_header_rec.org_id := p_old_header_rec.org_id;
2872 	END IF;
2873 
2874 	IF 	p_x_header_rec.orig_sys_document_ref = FND_API.G_MISS_CHAR THEN
2875 		p_x_header_rec.orig_sys_document_ref := p_old_header_rec.orig_sys_document_ref;
2876 	END IF;
2877 
2878 	IF 	p_x_header_rec.partial_shipments_allowed = FND_API.G_MISS_CHAR THEN
2879 		p_x_header_rec.partial_shipments_allowed := p_old_header_rec.partial_shipments_allowed;
2880 	END IF;
2881 
2882 	IF 	p_x_header_rec.payment_term_id = FND_API.G_MISS_NUM THEN
2883 		p_x_header_rec.payment_term_id := p_old_header_rec.payment_term_id;
2884 	END IF;
2885 
2886 	IF 	p_x_header_rec.price_list_id = FND_API.G_MISS_NUM THEN
2887 		p_x_header_rec.price_list_id := p_old_header_rec.price_list_id;
2888 	END IF;
2889 
2890 	IF 	p_x_header_rec.price_request_code = FND_API.G_MISS_CHAR THEN  -- PROMOTIONS SEP/01
2891 		p_x_header_rec.price_request_code := p_old_header_rec.price_request_code;
2892 	END IF;
2893 
2894 	IF 	p_x_header_rec.pricing_date = FND_API.G_MISS_DATE THEN
2895 		p_x_header_rec.pricing_date := p_old_header_rec.pricing_date;
2896 	END IF;
2897 
2898 	IF 	p_x_header_rec.program_application_id = FND_API.G_MISS_NUM THEN
2899 		p_x_header_rec.program_application_id := p_old_header_rec.program_application_id;
2900 	END IF;
2901 
2902 	IF 	p_x_header_rec.program_id = FND_API.G_MISS_NUM THEN
2903 		p_x_header_rec.program_id := p_old_header_rec.program_id;
2904 	END IF;
2905 
2906 	IF 	p_x_header_rec.program_update_date = FND_API.G_MISS_DATE THEN
2907 		p_x_header_rec.program_update_date := p_old_header_rec.program_update_date;
2908 	END IF;
2909 
2910 	IF 	p_x_header_rec.request_date = FND_API.G_MISS_DATE THEN
2911 		p_x_header_rec.request_date := p_old_header_rec.request_date;
2912 	END IF;
2913 
2914 	IF 	p_x_header_rec.request_id = FND_API.G_MISS_NUM THEN
2915 		p_x_header_rec.request_id := p_old_header_rec.request_id;
2916 	END IF;
2917 
2918 	IF 	p_x_header_rec.return_reason_code = FND_API.G_MISS_CHAR THEN
2919 		p_x_header_rec.return_reason_code := p_old_header_rec.return_reason_code;
2920 	END IF;
2921 
2922 	IF 	p_x_header_rec.salesrep_id = FND_API.G_MISS_NUM THEN
2923 		p_x_header_rec.salesrep_id := p_old_header_rec.salesrep_id;
2924 	END IF;
2925 
2926 	IF 	p_x_header_rec.sales_channel_code = FND_API.G_MISS_CHAR THEN
2927 		p_x_header_rec.sales_channel_code := p_old_header_rec.sales_channel_code;
2928 	END IF;
2929 
2930 	IF 	p_x_header_rec.shipment_priority_code = FND_API.G_MISS_CHAR THEN
2931 		p_x_header_rec.shipment_priority_code := p_old_header_rec.shipment_priority_code;
2932 	END IF;
2933 
2934 	IF 	p_x_header_rec.shipping_method_code = FND_API.G_MISS_CHAR THEN
2935 		p_x_header_rec.shipping_method_code := p_old_header_rec.shipping_method_code;
2936 	END IF;
2937 
2938 	IF 	p_x_header_rec.ship_from_org_id = FND_API.G_MISS_NUM THEN
2939 		p_x_header_rec.ship_from_org_id := p_old_header_rec.ship_from_org_id;
2940 	END IF;
2941 
2942 	IF 	p_x_header_rec.ship_tolerance_above = FND_API.G_MISS_NUM THEN
2943 		p_x_header_rec.ship_tolerance_above := p_old_header_rec.ship_tolerance_above;
2944 	END IF;
2945 
2946 	IF 	p_x_header_rec.ship_tolerance_below = FND_API.G_MISS_NUM THEN
2947 		p_x_header_rec.ship_tolerance_below := p_old_header_rec.ship_tolerance_below;
2948 	END IF;
2949 
2950 	IF 	p_x_header_rec.ship_to_contact_id = FND_API.G_MISS_NUM THEN
2951 		p_x_header_rec.ship_to_contact_id := p_old_header_rec.ship_to_contact_id;
2952 	END IF;
2953 
2954 	IF 	p_x_header_rec.ship_to_org_id = FND_API.G_MISS_NUM THEN
2955 		p_x_header_rec.ship_to_org_id := p_old_header_rec.ship_to_org_id;
2956 	END IF;
2957 
2958 	IF 	p_x_header_rec.sold_from_org_id = FND_API.G_MISS_NUM THEN
2959 		p_x_header_rec.sold_from_org_id := p_old_header_rec.sold_from_org_id;
2960 	END IF;
2961 
2962 	IF 	p_x_header_rec.sold_to_contact_id = FND_API.G_MISS_NUM THEN
2963 		p_x_header_rec.sold_to_contact_id := p_old_header_rec.sold_to_contact_id;
2964 	END IF;
2965 
2966 	IF 	p_x_header_rec.sold_to_org_id = FND_API.G_MISS_NUM THEN
2967 		p_x_header_rec.sold_to_org_id := p_old_header_rec.sold_to_org_id;
2968 	END IF;
2969 
2970 	IF 	p_x_header_rec.sold_to_phone_id = FND_API.G_MISS_NUM THEN
2971 		p_x_header_rec.sold_to_phone_id := p_old_header_rec.sold_to_phone_id;
2972 	END IF;
2973 
2974 	IF 	p_x_header_rec.source_document_id = FND_API.G_MISS_NUM THEN
2975 		p_x_header_rec.source_document_id := p_old_header_rec.source_document_id;
2976 	END IF;
2977 
2978 	IF 	p_x_header_rec.source_document_type_id = FND_API.G_MISS_NUM THEN
2979 		p_x_header_rec.source_document_type_id := p_old_header_rec.source_document_type_id;
2980 	END IF;
2981 
2982 	IF 	p_x_header_rec.tax_exempt_flag = FND_API.G_MISS_CHAR THEN
2983 		p_x_header_rec.tax_exempt_flag := p_old_header_rec.tax_exempt_flag;
2984 	END IF;
2985 
2986 	IF 	p_x_header_rec.tax_exempt_number = FND_API.G_MISS_CHAR THEN
2987 		p_x_header_rec.tax_exempt_number := p_old_header_rec.tax_exempt_number;
2988 	END IF;
2989 
2990 	IF 	p_x_header_rec.tax_exempt_reason_code = FND_API.G_MISS_CHAR THEN
2991 		p_x_header_rec.tax_exempt_reason_code := p_old_header_rec.tax_exempt_reason_code;
2992 	END IF;
2993 
2994 	IF 	p_x_header_rec.tax_point_code = FND_API.G_MISS_CHAR THEN
2995 		p_x_header_rec.tax_point_code := p_old_header_rec.tax_point_code;
2996 	END IF;
2997 
2998 	IF 	p_x_header_rec.transactional_curr_code = FND_API.G_MISS_CHAR THEN
2999 		p_x_header_rec.transactional_curr_code := p_old_header_rec.transactional_curr_code;
3000 	END IF;
3001 
3002 	-- For bug 2916613
3003 	IF 	p_x_header_rec.tp_attribute1 = FND_API.G_MISS_CHAR THEN
3004 		p_x_header_rec.tp_attribute1 := p_old_header_rec.tp_attribute1;
3005 	END IF;
3006 
3007 	IF 	p_x_header_rec.tp_attribute10 = FND_API.G_MISS_CHAR THEN
3008 		p_x_header_rec.tp_attribute10 := p_old_header_rec.tp_attribute10;
3009 	END IF;
3010 
3011 	IF 	p_x_header_rec.tp_attribute11 = FND_API.G_MISS_CHAR THEN
3012 		p_x_header_rec.tp_attribute11 := p_old_header_rec.tp_attribute11;
3013 	END IF;
3014 
3015 	IF 	p_x_header_rec.tp_attribute12 = FND_API.G_MISS_CHAR THEN
3016 		p_x_header_rec.tp_attribute12 := p_old_header_rec.tp_attribute12;
3017 	END IF;
3018 
3019 	IF 	p_x_header_rec.tp_attribute13 = FND_API.G_MISS_CHAR THEN
3020 		p_x_header_rec.tp_attribute13 := p_old_header_rec.tp_attribute13;
3021 	END IF;
3022 
3023 	IF 	p_x_header_rec.tp_attribute14 = FND_API.G_MISS_CHAR THEN
3024 		p_x_header_rec.tp_attribute14 := p_old_header_rec.tp_attribute14;
3025 	END IF;
3026 
3027 	IF 	p_x_header_rec.tp_attribute15 = FND_API.G_MISS_CHAR THEN
3028 		p_x_header_rec.tp_attribute15 := p_old_header_rec.tp_attribute15;
3029 	END IF;
3030 
3031 	IF 	p_x_header_rec.tp_attribute2 = FND_API.G_MISS_CHAR THEN
3032 		p_x_header_rec.tp_attribute2 := p_old_header_rec.tp_attribute2;
3033 	END IF;
3034 
3035 	IF 	p_x_header_rec.tp_attribute3 = FND_API.G_MISS_CHAR THEN
3036 		p_x_header_rec.tp_attribute3 := p_old_header_rec.tp_attribute3;
3037 	END IF;
3038 
3039 	IF 	p_x_header_rec.tp_attribute4 = FND_API.G_MISS_CHAR THEN
3040 		p_x_header_rec.tp_attribute4 := p_old_header_rec.tp_attribute4;
3041 	END IF;
3042 
3043 	IF 	p_x_header_rec.tp_attribute5 = FND_API.G_MISS_CHAR THEN
3044 		p_x_header_rec.tp_attribute5 := p_old_header_rec.tp_attribute5;
3045 	END IF;
3046 
3047 	IF 	p_x_header_rec.tp_attribute6 = FND_API.G_MISS_CHAR THEN
3048 		p_x_header_rec.tp_attribute6 := p_old_header_rec.tp_attribute6;
3049 	END IF;
3050 
3051 	IF 	p_x_header_rec.tp_attribute7 = FND_API.G_MISS_CHAR THEN
3052 		p_x_header_rec.tp_attribute7 := p_old_header_rec.tp_attribute7;
3053 	END IF;
3054 
3055 	IF 	p_x_header_rec.tp_attribute8 = FND_API.G_MISS_CHAR THEN
3056 		p_x_header_rec.tp_attribute8 := p_old_header_rec.tp_attribute8;
3057 	END IF;
3058 
3059 	IF 	p_x_header_rec.tp_attribute9 = FND_API.G_MISS_CHAR THEN
3060 		p_x_header_rec.tp_attribute9 := p_old_header_rec.tp_attribute9;
3061 	END IF;
3062 
3063 	IF 	p_x_header_rec.tp_context = FND_API.G_MISS_CHAR THEN
3064 		p_x_header_rec.tp_context := p_old_header_rec.tp_context;
3065 	END IF;
3066 	--End bug 2916613
3067 
3068 	IF 	p_x_header_rec.version_number = FND_API.G_MISS_NUM THEN
3069 		p_x_header_rec.version_number := p_old_header_rec.version_number;
3070 	END IF;
3071 
3072 	IF 	p_x_header_rec.payment_type_code = FND_API.G_MISS_CHAR THEN
3073 		p_x_header_rec.payment_type_code := p_old_header_rec.payment_type_code;
3074 	END IF;
3075 
3076 	IF 	p_x_header_rec.payment_amount = FND_API.G_MISS_NUM THEN
3077 		p_x_header_rec.payment_amount := p_old_header_rec.payment_amount;
3078 	END IF;
3079 
3080 	IF 	p_x_header_rec.check_number = FND_API.G_MISS_CHAR THEN
3081 		p_x_header_rec.check_number := p_old_header_rec.check_number;
3082 	END IF;
3083 	--R12 CC Encryption
3084 	--These details not stored in oe_payments table now and centrally stored in payments tables
3085 	--kadiraju Uncommented the below code for Bug#13499934  Begin
3086 	--/*
3087 	IF 	p_x_header_rec.credit_card_code = FND_API.G_MISS_CHAR THEN
3088 		p_x_header_rec.credit_card_code := p_old_header_rec.credit_card_code;
3089 	END IF;
3090 
3091 	IF 	p_x_header_rec.credit_card_holder_name = FND_API.G_MISS_CHAR THEN
3092 		p_x_header_rec.credit_card_holder_name := p_old_header_rec.credit_card_holder_name;
3093 	END IF;
3094 
3095 	IF 	p_x_header_rec.credit_card_number = FND_API.G_MISS_CHAR THEN
3096 		p_x_header_rec.credit_card_number := p_old_header_rec.credit_card_number;
3097 	END IF;
3098 
3099 	IF 	p_x_header_rec.credit_card_expiration_date = FND_API.G_MISS_DATE THEN
3100 		p_x_header_rec.credit_card_expiration_date := p_old_header_rec.credit_card_expiration_date;
3101 	END IF;
3102 
3103 	IF 	p_x_header_rec.credit_card_approval_date = FND_API.G_MISS_DATE THEN
3104 		p_x_header_rec.credit_card_approval_date := p_old_header_rec.credit_card_approval_date;
3105 	END IF;
3106 
3107 	IF 	p_x_header_rec.credit_card_approval_code = FND_API.G_MISS_CHAR THEN
3108 		p_x_header_rec.credit_card_approval_code := p_old_header_rec.credit_card_approval_code;
3109 	END IF;--*/
3110   --kadiraju Uncommented the code for Bug#13499934  End
3111 	--R12 CC Encryption
3112 
3113 	IF 	p_x_header_rec.first_ack_code = FND_API.G_MISS_CHAR THEN
3114 		p_x_header_rec.first_ack_code := p_old_header_rec.first_ack_code;
3115 	END IF;
3116 
3117 	IF 	p_x_header_rec.first_ack_date = FND_API.G_MISS_DATE THEN
3118 		p_x_header_rec.first_ack_date := p_old_header_rec.first_ack_date;
3119 	END IF;
3120 
3121 	IF 	p_x_header_rec.last_ack_code = FND_API.G_MISS_CHAR THEN
3122 		p_x_header_rec.last_ack_code := p_old_header_rec.last_ack_code;
3123 	END IF;
3124 
3125 	IF 	p_x_header_rec.last_ack_date = FND_API.G_MISS_DATE THEN
3126 		p_x_header_rec.last_ack_date := p_old_header_rec.last_ack_date;
3127 	END IF;
3128 
3129 	IF 	p_x_header_rec.line_set_name = FND_API.G_MISS_CHAR THEN
3130 		p_x_header_rec.line_set_name := p_old_header_rec.line_set_name;
3131 	END IF;
3132 
3133 	IF 	p_x_header_rec.shipping_instructions = FND_API.G_MISS_CHAR THEN
3134 		p_x_header_rec.shipping_instructions := p_old_header_rec.shipping_instructions;
3135 	END IF;
3136 
3137 	IF 	p_x_header_rec.packing_instructions = FND_API.G_MISS_CHAR THEN
3138 		p_x_header_rec.packing_instructions := p_old_header_rec.packing_instructions;
3139 	END IF;
3140 
3141 	IF 	p_x_header_rec.marketing_source_code_id = FND_API.G_MISS_NUM THEN
3142 		p_x_header_rec.marketing_source_code_id := p_old_header_rec.marketing_source_code_id;
3143 	END IF;
3144 
3145 	IF 	p_x_header_rec.flow_status_code = 'ENTERED' THEN
3146             -- QUOTING change - do not override 'ENTERED' status with old
3147             -- value as status should be set to entered during complete
3148             -- negotiation call
3149             IF OE_Quote_Util.G_COMPLETE_NEG = 'N' THEN
3150 	-- flow_status_code is initilized to ENTERED
3151 		p_x_header_rec.flow_status_code := p_old_header_rec.flow_status_code;
3152             END IF;
3153 	END IF;
3154 
3155         -- QUOTING changes
3156 
3157 	IF 	p_x_header_rec.quote_date = FND_API.G_MISS_DATE THEN
3158 		p_x_header_rec.quote_date := p_old_header_rec.quote_date;
3159 	END IF;
3160 
3161 	IF 	p_x_header_rec.quote_number = FND_API.G_MISS_NUM THEN
3162 		p_x_header_rec.quote_number := p_old_header_rec.quote_number;
3163 	END IF;
3164 
3165 	IF 	p_x_header_rec.sales_document_name = FND_API.G_MISS_CHAR THEN
3166 		p_x_header_rec.sales_document_name := p_old_header_rec.sales_document_name;
3167 	END IF;
3168 
3169 	IF 	p_x_header_rec.transaction_phase_code = FND_API.G_MISS_CHAR THEN
3170 		p_x_header_rec.transaction_phase_code := p_old_header_rec.transaction_phase_code;
3171 	END IF;
3172 
3173 	IF 	p_x_header_rec.user_status_code = FND_API.G_MISS_CHAR THEN
3174 		p_x_header_rec.user_status_code := p_old_header_rec.user_status_code;
3175 	END IF;
3176 
3177 	IF 	p_x_header_rec.draft_submitted_flag = FND_API.G_MISS_CHAR THEN
3178 		p_x_header_rec.draft_submitted_flag := p_old_header_rec.draft_submitted_flag;
3179 	END IF;
3180 
3181 	IF 	p_x_header_rec.source_document_version_number = FND_API.G_MISS_NUM THEN
3182 		p_x_header_rec.source_document_version_number := p_old_header_rec.source_document_version_number;
3183 	END IF;
3184 
3185 	IF 	p_x_header_rec.sold_to_site_use_id = FND_API.G_MISS_NUM THEN
3186 		p_x_header_rec.sold_to_site_use_id := p_old_header_rec.sold_to_site_use_id;
3187 	END IF;
3188 
3189         -- QUOTING changes END
3190 
3191 
3192         IF      p_x_header_rec.Minisite_id = FND_API.G_MISS_NUM THEN
3193                 p_x_header_rec.Minisite_id := p_old_header_rec.Minisite_id;
3194         END IF;
3195 
3196         IF      p_x_header_rec.End_customer_id = FND_API.G_MISS_NUM THEN
3197                 p_x_header_rec.End_customer_id := p_old_header_rec.End_customer_id;
3198         END IF;
3199 
3200         IF      p_x_header_rec.End_customer_contact_id = FND_API.G_MISS_NUM THEN
3201                 p_x_header_rec.End_customer_contact_id := p_old_header_rec.End_customer_contact_id;
3202         END IF;
3203 
3204         IF      p_x_header_rec.End_customer_site_use_id = FND_API.G_MISS_NUM THEN
3205                 p_x_header_rec.End_customer_site_use_id := p_old_header_rec.End_customer_site_use_id;
3206         END IF;
3207 
3208         IF      p_x_header_rec.Ib_owner = FND_API.G_MISS_CHAR THEN
3209                 p_x_header_rec.Ib_owner := p_old_header_rec.Ib_owner;
3210         END IF;
3211 
3212         IF      p_x_header_rec.Ib_installed_at_location = FND_API.G_MISS_CHAR THEN
3213                 p_x_header_rec.Ib_installed_at_location := p_old_header_rec.Ib_installed_at_location;
3214         END IF;
3215 
3216         IF      p_x_header_rec.Ib_current_location= FND_API.G_MISS_CHAR THEN
3217                 p_x_header_rec.Ib_current_location := p_old_header_rec.Ib_current_location;
3218         END IF;
3219 
3220         IF      p_x_header_rec.supplier_signature= FND_API.G_MISS_CHAR THEN
3221                 p_x_header_rec.supplier_signature := p_old_header_rec.supplier_signature;
3222         END IF;
3223 
3224         IF      p_x_header_rec.supplier_signature_date= FND_API.G_MISS_DATE THEN
3225                 p_x_header_rec.supplier_signature_date := p_old_header_rec.supplier_signature_date;
3226         END IF;
3227 
3228         IF      p_x_header_rec.customer_signature= FND_API.G_MISS_CHAR THEN
3229                 p_x_header_rec.customer_signature := p_old_header_rec.customer_signature;
3230         END IF;
3231 
3232         IF      p_x_header_rec.customer_signature_date= FND_API.G_MISS_DATE THEN
3233                 p_x_header_rec.customer_signature_date := p_old_header_rec.customer_signature_date;
3234         END IF;
3235 
3236       /* Contract related changes */
3237 
3238         IF      p_x_header_rec.contract_template_id = FND_API.G_MISS_NUM THEN
3239                 p_x_header_rec.contract_template_id := p_old_header_rec.contract_template_id;
3240         END IF;
3241 
3242         IF      p_x_header_rec.contract_source_doc_type_code = FND_API.G_MISS_CHAR THEN
3243                 p_x_header_rec.contract_source_doc_type_code := p_old_header_rec.contract_source_doc_type_code;
3244         END IF;
3245 
3246         IF      p_x_header_rec.contract_source_document_id = FND_API.G_MISS_NUM THEN
3247                 p_x_header_rec.contract_source_document_id := p_old_header_rec.contract_source_document_id;
3248         END IF;
3249 
3250      --key Transaction Dates
3251         IF      p_x_header_rec.order_firmed_date = FND_API.G_MISS_DATE THEN
3252 		p_x_header_rec.order_firmed_date := p_old_header_rec.order_firmed_date;
3253 	END IF;
3254 
3255 	--8219019 start
3256 
3257         IF      p_x_header_rec.CC_INSTRUMENT_ID = FND_API.G_MISS_NUM THEN
3258         	p_x_header_rec.CC_INSTRUMENT_ID := p_old_header_rec.CC_INSTRUMENT_ID;
3259 	END IF;
3260 
3261         IF      p_x_header_rec.CC_INSTRUMENT_ASSIGNMENT_ID = FND_API.G_MISS_NUM THEN
3262         	p_x_header_rec.CC_INSTRUMENT_ASSIGNMENT_ID := p_old_header_rec.CC_INSTRUMENT_ASSIGNMENT_ID;
3263 	END IF;
3264 
3265 	--8219019 end
3266 
3267 
3268 	oe_debug_pub.add('Exiting OE_HEADER_UTIL.COMPLETE_RECORD', 1);
3269 
3270 
3271 END Complete_Record;
3272 
3273 --  Procedure Convert_Miss_To_Null
3274 
3275 PROCEDURE Convert_Miss_To_Null
3276 (   p_x_header_rec        IN OUT NOCOPY  OE_Order_PUB.Header_Rec_Type
3277 )
3278 IS
3279 --p_x_header_rec                  OE_Order_PUB.Header_Rec_Type := p_header_rec;
3280 BEGIN
3281 
3282     oe_debug_pub.add('Entering OE_HEADER_UTIL.CONVERT_MISS_TO_NULL', 1);
3283 
3284     IF p_x_header_rec.accounting_rule_id = FND_API.G_MISS_NUM THEN
3285         p_x_header_rec.accounting_rule_id := NULL;
3286     END IF;
3287 
3288     IF p_x_header_rec.accounting_rule_duration = FND_API.G_MISS_NUM THEN
3289         p_x_header_rec.accounting_rule_duration := NULL;
3290     END IF;
3291 
3292     IF p_x_header_rec.agreement_id = FND_API.G_MISS_NUM THEN
3293         p_x_header_rec.agreement_id := NULL;
3294     END IF;
3295 
3296     IF p_x_header_rec.blanket_number = FND_API.G_MISS_NUM THEN
3297        p_x_header_rec.blanket_number := NULL;
3298     END IF;
3299 
3300     IF p_x_header_rec.booked_flag = FND_API.G_MISS_CHAR THEN
3301         p_x_header_rec.booked_flag := NULL;
3302     END IF;
3303 
3304     IF p_x_header_rec.upgraded_flag = FND_API.G_MISS_CHAR THEN
3305         p_x_header_rec.upgraded_flag := NULL;
3306     END IF;
3307 
3308     IF p_x_header_rec.booked_date = FND_API.G_MISS_DATE THEN
3309         p_x_header_rec.booked_date := NULL;
3310     END IF;
3311 
3312     IF p_x_header_rec.cancelled_flag = FND_API.G_MISS_CHAR THEN
3313         p_x_header_rec.cancelled_flag := NULL;
3314     END IF;
3315 
3316     IF p_x_header_rec.attribute1 = FND_API.G_MISS_CHAR THEN
3317         p_x_header_rec.attribute1 := NULL;
3318     END IF;
3319 
3320     IF p_x_header_rec.attribute10 = FND_API.G_MISS_CHAR THEN
3321         p_x_header_rec.attribute10 := NULL;
3322     END IF;
3323 
3324     IF p_x_header_rec.attribute11 = FND_API.G_MISS_CHAR THEN
3325         p_x_header_rec.attribute11 := NULL;
3326     END IF;
3327 
3328     IF p_x_header_rec.attribute12 = FND_API.G_MISS_CHAR THEN
3329         p_x_header_rec.attribute12 := NULL;
3330     END IF;
3331 
3332     IF p_x_header_rec.attribute13 = FND_API.G_MISS_CHAR THEN
3333         p_x_header_rec.attribute13 := NULL;
3334     END IF;
3335 
3336     IF p_x_header_rec.attribute14 = FND_API.G_MISS_CHAR THEN
3337         p_x_header_rec.attribute14 := NULL;
3338     END IF;
3339 
3340     IF p_x_header_rec.attribute15 = FND_API.G_MISS_CHAR THEN
3341         p_x_header_rec.attribute15 := NULL;
3342     END IF;
3343 
3344     IF p_x_header_rec.attribute16 = FND_API.G_MISS_CHAR THEN    --For bug 2184255
3345         p_x_header_rec.attribute16 := NULL;
3346     END IF;
3347 
3348     IF p_x_header_rec.attribute17 = FND_API.G_MISS_CHAR THEN
3349         p_x_header_rec.attribute17 := NULL;
3350     END IF;
3351 
3352     IF p_x_header_rec.attribute18 = FND_API.G_MISS_CHAR THEN
3353         p_x_header_rec.attribute18 := NULL;
3354     END IF;
3355 
3356     IF p_x_header_rec.attribute19 = FND_API.G_MISS_CHAR THEN
3357         p_x_header_rec.attribute19 := NULL;
3358     END IF;
3359 
3360     IF p_x_header_rec.attribute2 = FND_API.G_MISS_CHAR THEN
3361         p_x_header_rec.attribute2 := NULL;
3362     END IF;
3363 
3364     IF p_x_header_rec.attribute20 = FND_API.G_MISS_CHAR THEN    --For bug 2184255
3365         p_x_header_rec.attribute20 := NULL;
3366     END IF;
3367 
3368     IF p_x_header_rec.attribute3 = FND_API.G_MISS_CHAR THEN
3369         p_x_header_rec.attribute3 := NULL;
3370     END IF;
3371 
3372     IF p_x_header_rec.attribute4 = FND_API.G_MISS_CHAR THEN
3373         p_x_header_rec.attribute4 := NULL;
3374     END IF;
3375 
3376     IF p_x_header_rec.attribute5 = FND_API.G_MISS_CHAR THEN
3377         p_x_header_rec.attribute5 := NULL;
3378     END IF;
3379 
3380     IF p_x_header_rec.attribute6 = FND_API.G_MISS_CHAR THEN
3381         p_x_header_rec.attribute6 := NULL;
3382     END IF;
3383 
3384     IF p_x_header_rec.attribute7 = FND_API.G_MISS_CHAR THEN
3385         p_x_header_rec.attribute7 := NULL;
3386     END IF;
3387 
3388     IF p_x_header_rec.attribute8 = FND_API.G_MISS_CHAR THEN
3389         p_x_header_rec.attribute8 := NULL;
3390     END IF;
3391 
3392     IF p_x_header_rec.attribute9 = FND_API.G_MISS_CHAR THEN
3393         p_x_header_rec.attribute9 := NULL;
3394     END IF;
3395 
3396     IF p_x_header_rec.context = FND_API.G_MISS_CHAR THEN
3397         p_x_header_rec.context := NULL;
3398     END IF;
3399 
3400     IF p_x_header_rec.conversion_rate = FND_API.G_MISS_NUM THEN
3401         p_x_header_rec.conversion_rate := NULL;
3402     END IF;
3403 
3404     IF p_x_header_rec.conversion_rate_date = FND_API.G_MISS_DATE THEN
3405         p_x_header_rec.conversion_rate_date := NULL;
3406     END IF;
3407 
3408     IF p_x_header_rec.conversion_type_code = FND_API.G_MISS_CHAR THEN
3409         p_x_header_rec.conversion_type_code := NULL;
3410     END IF;
3411 
3412     IF p_x_header_rec.CUSTOMER_PREFERENCE_SET_CODE = FND_API.G_MISS_CHAR THEN
3413         p_x_header_rec.CUSTOMER_PREFERENCE_SET_CODE := NULL;
3414     END IF;
3415 
3416     IF p_x_header_rec.created_by = FND_API.G_MISS_NUM THEN
3417         p_x_header_rec.created_by := NULL;
3418     END IF;
3419 
3420     IF p_x_header_rec.creation_date = FND_API.G_MISS_DATE THEN
3421         p_x_header_rec.creation_date := NULL;
3422     END IF;
3423 
3424     IF p_x_header_rec.cust_po_number = FND_API.G_MISS_CHAR THEN
3425         p_x_header_rec.cust_po_number := NULL;
3426     END IF;
3427 
3428     IF p_x_header_rec.default_fulfillment_set = FND_API.G_MISS_CHAR THEN
3429         p_x_header_rec.default_fulfillment_set := NULL;
3430     END IF;
3431 
3432     IF p_x_header_rec.deliver_to_contact_id = FND_API.G_MISS_NUM THEN
3433         p_x_header_rec.deliver_to_contact_id := NULL;
3434     END IF;
3435 
3436     IF p_x_header_rec.deliver_to_org_id = FND_API.G_MISS_NUM THEN
3437         p_x_header_rec.deliver_to_org_id := NULL;
3438     END IF;
3439 
3440     IF p_x_header_rec.demand_class_code = FND_API.G_MISS_CHAR THEN
3441         p_x_header_rec.demand_class_code := NULL;
3442     END IF;
3443 
3444     IF p_x_header_rec.expiration_date = FND_API.G_MISS_DATE THEN
3445         p_x_header_rec.expiration_date := NULL;
3446     END IF;
3447 
3448     IF p_x_header_rec.earliest_schedule_limit = FND_API.G_MISS_NUM THEN
3449         p_x_header_rec.earliest_schedule_limit := NULL;
3450     END IF;
3451 
3452     IF p_x_header_rec.fob_point_code = FND_API.G_MISS_CHAR THEN
3453         p_x_header_rec.fob_point_code := NULL;
3454     END IF;
3455 
3456     IF p_x_header_rec.freight_carrier_code = FND_API.G_MISS_CHAR THEN
3457         p_x_header_rec.freight_carrier_code := NULL;
3458     END IF;
3459 
3460     IF p_x_header_rec.freight_terms_code = FND_API.G_MISS_CHAR THEN
3461         p_x_header_rec.freight_terms_code := NULL;
3462     END IF;
3463 
3464     IF p_x_header_rec.fulfillment_set_name = FND_API.G_MISS_CHAR THEN
3465         p_x_header_rec.fulfillment_set_name := NULL;
3466     END IF;
3467 
3468     IF p_x_header_rec.global_attribute1 = FND_API.G_MISS_CHAR THEN
3469         p_x_header_rec.global_attribute1 := NULL;
3470     END IF;
3471 
3472     IF p_x_header_rec.global_attribute10 = FND_API.G_MISS_CHAR THEN
3473         p_x_header_rec.global_attribute10 := NULL;
3474     END IF;
3475 
3476     IF p_x_header_rec.global_attribute11 = FND_API.G_MISS_CHAR THEN
3477         p_x_header_rec.global_attribute11 := NULL;
3478     END IF;
3479 
3480     IF p_x_header_rec.global_attribute12 = FND_API.G_MISS_CHAR THEN
3481         p_x_header_rec.global_attribute12 := NULL;
3482     END IF;
3483 
3484     IF p_x_header_rec.global_attribute13 = FND_API.G_MISS_CHAR THEN
3485         p_x_header_rec.global_attribute13 := NULL;
3486     END IF;
3487 
3488     IF p_x_header_rec.global_attribute14 = FND_API.G_MISS_CHAR THEN
3489         p_x_header_rec.global_attribute14 := NULL;
3490     END IF;
3491 
3492     IF p_x_header_rec.global_attribute15 = FND_API.G_MISS_CHAR THEN
3493         p_x_header_rec.global_attribute15 := NULL;
3494     END IF;
3495 
3496     IF p_x_header_rec.global_attribute16 = FND_API.G_MISS_CHAR THEN
3497         p_x_header_rec.global_attribute16 := NULL;
3498     END IF;
3499 
3500     IF p_x_header_rec.global_attribute17 = FND_API.G_MISS_CHAR THEN
3501         p_x_header_rec.global_attribute17 := NULL;
3502     END IF;
3503 
3504     IF p_x_header_rec.global_attribute18 = FND_API.G_MISS_CHAR THEN
3505         p_x_header_rec.global_attribute18 := NULL;
3506     END IF;
3507 
3508     IF p_x_header_rec.global_attribute19 = FND_API.G_MISS_CHAR THEN
3509         p_x_header_rec.global_attribute19 := NULL;
3510     END IF;
3511 
3512     IF p_x_header_rec.global_attribute2 = FND_API.G_MISS_CHAR THEN
3513         p_x_header_rec.global_attribute2 := NULL;
3514     END IF;
3515 
3516     IF p_x_header_rec.global_attribute20 = FND_API.G_MISS_CHAR THEN
3517         p_x_header_rec.global_attribute20 := NULL;
3518     END IF;
3519 
3520     IF p_x_header_rec.global_attribute3 = FND_API.G_MISS_CHAR THEN
3521         p_x_header_rec.global_attribute3 := NULL;
3522     END IF;
3523 
3524     IF p_x_header_rec.global_attribute4 = FND_API.G_MISS_CHAR THEN
3525         p_x_header_rec.global_attribute4 := NULL;
3526     END IF;
3527 
3528     IF p_x_header_rec.global_attribute5 = FND_API.G_MISS_CHAR THEN
3529         p_x_header_rec.global_attribute5 := NULL;
3530     END IF;
3531 
3532     IF p_x_header_rec.global_attribute6 = FND_API.G_MISS_CHAR THEN
3533         p_x_header_rec.global_attribute6 := NULL;
3534     END IF;
3535 
3536     IF p_x_header_rec.global_attribute7 = FND_API.G_MISS_CHAR THEN
3537         p_x_header_rec.global_attribute7 := NULL;
3538     END IF;
3539 
3540     IF p_x_header_rec.global_attribute8 = FND_API.G_MISS_CHAR THEN
3541         p_x_header_rec.global_attribute8 := NULL;
3542     END IF;
3543 
3544     IF p_x_header_rec.global_attribute9 = FND_API.G_MISS_CHAR THEN
3545         p_x_header_rec.global_attribute9 := NULL;
3546     END IF;
3547 
3548     IF p_x_header_rec.global_attribute_category = FND_API.G_MISS_CHAR THEN
3549         p_x_header_rec.global_attribute_category := NULL;
3550     END IF;
3551 
3552     IF p_x_header_rec.header_id = FND_API.G_MISS_NUM THEN
3553         p_x_header_rec.header_id := NULL;
3554     END IF;
3555 
3556     IF p_x_header_rec.invoice_to_contact_id = FND_API.G_MISS_NUM THEN
3557         p_x_header_rec.invoice_to_contact_id := NULL;
3558     END IF;
3559 
3560     IF p_x_header_rec.invoice_to_org_id = FND_API.G_MISS_NUM THEN
3561         p_x_header_rec.invoice_to_org_id := NULL;
3562     END IF;
3563 
3564     IF p_x_header_rec.invoicing_rule_id = FND_API.G_MISS_NUM THEN
3565         p_x_header_rec.invoicing_rule_id := NULL;
3566     END IF;
3567 
3568     IF p_x_header_rec.last_updated_by = FND_API.G_MISS_NUM THEN
3569         p_x_header_rec.last_updated_by := NULL;
3570     END IF;
3571 
3572     IF p_x_header_rec.last_update_date = FND_API.G_MISS_DATE THEN
3573         p_x_header_rec.last_update_date := NULL;
3574     END IF;
3575 
3576     IF p_x_header_rec.last_update_login = FND_API.G_MISS_NUM THEN
3577         p_x_header_rec.last_update_login := NULL;
3578     END IF;
3579 
3580 
3581     IF p_x_header_rec.latest_schedule_limit = FND_API.G_MISS_NUM THEN
3582         p_x_header_rec.latest_schedule_limit := NULL;
3583     END IF;
3584 
3585     IF p_x_header_rec.line_set_name = FND_API.G_MISS_CHAR THEN
3586         p_x_header_rec.line_set_name := NULL;
3587     END IF;
3588 
3589     IF p_x_header_rec.open_flag = FND_API.G_MISS_CHAR THEN
3590         p_x_header_rec.open_flag := NULL;
3591     END IF;
3592 
3593     IF p_x_header_rec.ordered_date = FND_API.G_MISS_DATE THEN
3594         p_x_header_rec.ordered_date := NULL;
3595     END IF;
3596 
3597     IF p_x_header_rec.order_date_type_code = FND_API.G_MISS_CHAR THEN
3598         p_x_header_rec.order_date_type_code := NULL;
3599     END IF;
3600 
3601     IF p_x_header_rec.order_number = FND_API.G_MISS_NUM THEN
3602         p_x_header_rec.order_number := NULL;
3603     END IF;
3604 
3605     IF p_x_header_rec.order_source_id = FND_API.G_MISS_NUM THEN
3606         p_x_header_rec.order_source_id := NULL;
3607     END IF;
3608 
3609     IF p_x_header_rec.order_type_id = FND_API.G_MISS_NUM THEN
3610         p_x_header_rec.order_type_id := NULL;
3611     END IF;
3612     IF p_x_header_rec.order_category_code = FND_API.G_MISS_CHAR THEN
3613         p_x_header_rec.order_category_code := NULL;
3614     END IF;
3615 
3616     IF p_x_header_rec.org_id = FND_API.G_MISS_NUM THEN
3617         p_x_header_rec.org_id := NULL;
3618     END IF;
3619 
3620     IF p_x_header_rec.orig_sys_document_ref = FND_API.G_MISS_CHAR THEN
3621         p_x_header_rec.orig_sys_document_ref := NULL;
3622     END IF;
3623 
3624     IF p_x_header_rec.partial_shipments_allowed = FND_API.G_MISS_CHAR THEN
3625         p_x_header_rec.partial_shipments_allowed := NULL;
3626     END IF;
3627 
3628     IF p_x_header_rec.payment_term_id = FND_API.G_MISS_NUM THEN
3629         p_x_header_rec.payment_term_id := NULL;
3630     END IF;
3631 
3632     IF p_x_header_rec.price_list_id = FND_API.G_MISS_NUM THEN
3633         p_x_header_rec.price_list_id := NULL;
3634     END IF;
3635 
3636     IF p_x_header_rec.price_request_code = FND_API.G_MISS_CHAR THEN  -- PROMOTIONS SEP/01
3637         p_x_header_rec.price_request_code := NULL;
3638     END IF;
3639 
3640     IF p_x_header_rec.pricing_date = FND_API.G_MISS_DATE THEN
3641         p_x_header_rec.pricing_date := NULL;
3642     END IF;
3643 
3644     IF p_x_header_rec.program_application_id = FND_API.G_MISS_NUM THEN
3645         p_x_header_rec.program_application_id := NULL;
3646     END IF;
3647 
3648     IF p_x_header_rec.program_id = FND_API.G_MISS_NUM THEN
3649         p_x_header_rec.program_id := NULL;
3650     END IF;
3651 
3652     IF p_x_header_rec.program_update_date = FND_API.G_MISS_DATE THEN
3653         p_x_header_rec.program_update_date := NULL;
3654     END IF;
3655 
3656     IF p_x_header_rec.request_date = FND_API.G_MISS_DATE THEN
3657         p_x_header_rec.request_date := NULL;
3658     END IF;
3659 
3660     IF p_x_header_rec.request_id = FND_API.G_MISS_NUM THEN
3661         p_x_header_rec.request_id := NULL;
3662     END IF;
3663 
3664     IF p_x_header_rec.return_reason_code = FND_API.G_MISS_CHAR THEN
3665         p_x_header_rec.return_reason_code := NULL;
3666     END IF;
3667 
3668     IF p_x_header_rec.salesrep_id = FND_API.G_MISS_NUM THEN
3669         p_x_header_rec.salesrep_id := NULL;
3670     END IF;
3671 
3672     IF p_x_header_rec.sales_channel_code = FND_API.G_MISS_CHAR THEN
3673         p_x_header_rec.sales_channel_code := NULL;
3674     END IF;
3675 
3676     IF p_x_header_rec.shipment_priority_code = FND_API.G_MISS_CHAR THEN
3677         p_x_header_rec.shipment_priority_code := NULL;
3678     END IF;
3679 
3680     IF p_x_header_rec.shipping_method_code = FND_API.G_MISS_CHAR THEN
3681         p_x_header_rec.shipping_method_code := NULL;
3682     END IF;
3683 
3684     IF p_x_header_rec.ship_from_org_id = FND_API.G_MISS_NUM THEN
3685         p_x_header_rec.ship_from_org_id := NULL;
3686     END IF;
3687 
3688     IF p_x_header_rec.ship_tolerance_above = FND_API.G_MISS_NUM THEN
3689         p_x_header_rec.ship_tolerance_above := NULL;
3690     END IF;
3691 
3692     IF p_x_header_rec.ship_tolerance_below = FND_API.G_MISS_NUM THEN
3693         p_x_header_rec.ship_tolerance_below := NULL;
3694     END IF;
3695 
3696     IF p_x_header_rec.ship_to_contact_id = FND_API.G_MISS_NUM THEN
3697         p_x_header_rec.ship_to_contact_id := NULL;
3698     END IF;
3699 
3700     IF p_x_header_rec.ship_to_org_id = FND_API.G_MISS_NUM THEN
3701         p_x_header_rec.ship_to_org_id := NULL;
3702     END IF;
3703 
3704     IF p_x_header_rec.sold_from_org_id = FND_API.G_MISS_NUM THEN
3705         p_x_header_rec.sold_from_org_id := NULL;
3706     END IF;
3707 
3708     IF p_x_header_rec.sold_to_contact_id = FND_API.G_MISS_NUM THEN
3709         p_x_header_rec.sold_to_contact_id := NULL;
3710     END IF;
3711 
3712     IF p_x_header_rec.sold_to_org_id = FND_API.G_MISS_NUM THEN
3713         p_x_header_rec.sold_to_org_id := NULL;
3714     END IF;
3715 
3716     IF p_x_header_rec.sold_to_phone_id = FND_API.G_MISS_NUM THEN
3717         p_x_header_rec.sold_to_phone_id := NULL;
3718     END IF;
3719 
3720     IF p_x_header_rec.source_document_id = FND_API.G_MISS_NUM THEN
3721         p_x_header_rec.source_document_id := NULL;
3722     END IF;
3723 
3724     IF p_x_header_rec.source_document_type_id = FND_API.G_MISS_NUM THEN
3725         p_x_header_rec.source_document_type_id := NULL;
3726     END IF;
3727 
3728     IF p_x_header_rec.tax_exempt_flag = FND_API.G_MISS_CHAR THEN
3729         p_x_header_rec.tax_exempt_flag := NULL;
3730     END IF;
3731 
3732     IF p_x_header_rec.tax_exempt_number = FND_API.G_MISS_CHAR THEN
3733         p_x_header_rec.tax_exempt_number := NULL;
3734     END IF;
3735 
3736     IF p_x_header_rec.tax_exempt_reason_code = FND_API.G_MISS_CHAR THEN
3737         p_x_header_rec.tax_exempt_reason_code := NULL;
3738     END IF;
3739 
3740     IF p_x_header_rec.tax_point_code = FND_API.G_MISS_CHAR THEN
3741         p_x_header_rec.tax_point_code := NULL;
3742     END IF;
3743 
3744     IF p_x_header_rec.transactional_curr_code = FND_API.G_MISS_CHAR THEN
3745         p_x_header_rec.transactional_curr_code := NULL;
3746     END IF;
3747 
3748     IF p_x_header_rec.version_number = FND_API.G_MISS_NUM THEN
3749         p_x_header_rec.version_number := NULL;
3750     END IF;
3751 
3752     IF p_x_header_rec.payment_type_code = FND_API.G_MISS_CHAR THEN
3753         p_x_header_rec.payment_type_code := NULL;
3754     END IF;
3755 
3756     IF p_x_header_rec.payment_amount = FND_API.G_MISS_NUM THEN
3757         p_x_header_rec.payment_amount := NULL;
3758     END IF;
3759 
3760     IF p_x_header_rec.check_number = FND_API.G_MISS_CHAR THEN
3761         p_x_header_rec.check_number := NULL;
3762     END IF;
3763     --R12 CC Encryption
3764     --These details not stored in oe_payments table now and centrally stored in payments tables
3765     --kadiraju Uncommented the below code for Bug#13499934  Begin
3766     --/*
3767     IF p_x_header_rec.credit_card_code = FND_API.G_MISS_CHAR THEN
3768         p_x_header_rec.credit_card_code := NULL;
3769     END IF;
3770 
3771     IF p_x_header_rec.credit_card_holder_name = FND_API.G_MISS_CHAR THEN
3772         p_x_header_rec.credit_card_holder_name := NULL;
3773     END IF;
3774 
3775     IF p_x_header_rec.credit_card_number = FND_API.G_MISS_CHAR THEN
3776         p_x_header_rec.credit_card_number := NULL;
3777     END IF;
3778 
3779     IF p_x_header_rec.credit_card_expiration_date = FND_API.G_MISS_DATE THEN
3780         p_x_header_rec.credit_card_expiration_date := NULL;
3781     END IF;
3782 
3783     IF p_x_header_rec.credit_card_approval_date = FND_API.G_MISS_DATE THEN
3784         p_x_header_rec.credit_card_approval_date := NULL;
3785     END IF;
3786 
3787     IF p_x_header_rec.credit_card_approval_code = FND_API.G_MISS_CHAR THEN
3788         p_x_header_rec.credit_card_approval_code := NULL;
3789     END IF;--*/
3790     --kadiraju Uncommented the  code for Bug#13499934  End
3791     --R12 CC Encryption
3792 
3793     IF p_x_header_rec.first_ack_code = FND_API.G_MISS_CHAR THEN
3794         p_x_header_rec.first_ack_code := NULL;
3795     END IF;
3796 
3797     IF p_x_header_rec.first_ack_date = FND_API.G_MISS_DATE THEN
3798         p_x_header_rec.first_ack_date := NULL;
3799     END IF;
3800 
3801     IF p_x_header_rec.last_ack_code = FND_API.G_MISS_CHAR THEN
3802         p_x_header_rec.last_ack_code := NULL;
3803     END IF;
3804 
3805     IF p_x_header_rec.last_ack_date = FND_API.G_MISS_DATE THEN
3806         p_x_header_rec.last_ack_date := NULL;
3807     END IF;
3808 
3809     IF p_x_header_rec.shipping_instructions = FND_API.G_MISS_CHAR THEN
3810         p_x_header_rec.shipping_instructions := NULL;
3811     END IF;
3812 
3813     IF p_x_header_rec.packing_instructions = FND_API.G_MISS_CHAR THEN
3814         p_x_header_rec.packing_instructions := NULL;
3815     END IF;
3816 
3817     IF p_x_header_rec.flow_status_code = FND_API.G_MISS_CHAR THEN
3818         p_x_header_rec.flow_status_code := NULL;
3819     END IF;
3820 
3821     IF p_x_header_rec.marketing_source_code_id = FND_API.G_MISS_NUM THEN
3822         p_x_header_rec.marketing_source_code_id := NULL;
3823     END IF;
3824 
3825      IF p_x_header_rec.change_sequence = FND_API.G_MISS_CHAR THEN --2416561
3826         p_x_header_rec.change_sequence := NULL;
3827     END IF;
3828 
3829     -- QUOTING changes
3830 
3831     IF p_x_header_rec.quote_date = FND_API.G_MISS_DATE THEN
3832         p_x_header_rec.quote_date := NULL;
3833     END IF;
3834 
3835     IF p_x_header_rec.quote_number = FND_API.G_MISS_NUM THEN
3836         p_x_header_rec.quote_number := NULL;
3837     END IF;
3838 
3839     IF p_x_header_rec.sales_document_name = FND_API.G_MISS_CHAR THEN
3840         p_x_header_rec.sales_document_name := NULL;
3841     END IF;
3842 
3843     IF p_x_header_rec.transaction_phase_code = FND_API.G_MISS_CHAR THEN
3844         p_x_header_rec.transaction_phase_code := NULL;
3845     END IF;
3846 
3847     IF p_x_header_rec.user_status_code = FND_API.G_MISS_CHAR THEN
3848         p_x_header_rec.user_status_code := NULL;
3849     END IF;
3850 
3851     IF p_x_header_rec.draft_submitted_flag = FND_API.G_MISS_CHAR THEN
3852         p_x_header_rec.draft_submitted_flag := NULL;
3853     END IF;
3854 
3855     IF p_x_header_rec.source_document_version_number = FND_API.G_MISS_NUM THEN
3856         p_x_header_rec.source_document_version_number := NULL;
3857     END IF;
3858 
3859     IF p_x_header_rec.sold_to_site_use_id = FND_API.G_MISS_NUM THEN
3860         p_x_header_rec.sold_to_site_use_id := NULL;
3861     END IF;
3862 
3863     -- QUOTING changes END
3864 
3865     IF p_x_header_rec.Minisite_id = FND_API.G_MISS_NUM THEN
3866         p_x_header_rec.Minisite_id := NULL;
3867     END IF;
3868 
3869     IF p_x_header_rec.End_customer_id = FND_API.G_MISS_NUM THEN
3870         p_x_header_rec.End_customer_id := NULL;
3871     END IF;
3872 
3873     IF p_x_header_rec.End_customer_contact_id = FND_API.G_MISS_NUM THEN
3874         p_x_header_rec.End_customer_contact_id := NULL;
3875     END IF;
3876 
3877     IF p_x_header_rec.End_customer_site_use_id = FND_API.G_MISS_NUM THEN
3878         p_x_header_rec.End_customer_site_use_id := NULL;
3879     END IF;
3880 
3881     IF p_x_header_rec.Ib_owner = FND_API.G_MISS_CHAR THEN
3882         p_x_header_rec.Ib_owner := NULL;
3883     END IF;
3884 
3885     IF p_x_header_rec.Ib_installed_at_location = FND_API.G_MISS_CHAR THEN
3886         p_x_header_rec.Ib_installed_at_location := NULL;
3887     END IF;
3888 
3889     IF p_x_header_rec.Ib_current_location = FND_API.G_MISS_CHAR THEN
3890         p_x_header_rec.Ib_current_location := NULL;
3891     END IF;
3892 
3893    IF p_x_header_rec.supplier_signature = FND_API.G_MISS_CHAR THEN
3894         p_x_header_rec.supplier_signature := NULL;
3895     END IF;
3896 
3897    IF p_x_header_rec.supplier_signature_date = FND_API.G_MISS_DATE THEN
3898         p_x_header_rec.supplier_signature_date := NULL;
3899     END IF;
3900 
3901    IF p_x_header_rec.customer_signature = FND_API.G_MISS_CHAR THEN
3902         p_x_header_rec.customer_signature := NULL;
3903     END IF;
3904 
3905   IF p_x_header_rec.customer_signature_date = FND_API.G_MISS_DATE THEN
3906         p_x_header_rec.customer_signature_date := NULL;
3907     END IF;
3908 
3909     IF p_x_header_rec.contract_template_id = FND_API.G_MISS_NUM THEN
3910         p_x_header_rec.contract_template_id := NULL;
3911     END IF;
3912 
3913     IF p_x_header_rec.contract_source_doc_type_code = FND_API.G_MISS_CHAR THEN
3914         p_x_header_rec.contract_source_doc_type_code := NULL;
3915     END IF;
3916 
3917     IF p_x_header_rec.contract_source_document_id = FND_API.G_MISS_NUM THEN
3918         p_x_header_rec.contract_source_document_id := NULL;
3919     END IF;
3920 
3921 --key Transaction dates
3922     IF p_x_header_rec.order_firmed_date = FND_API.G_MISS_DATE THEN
3923         p_x_header_rec.order_firmed_date := NULL;
3924     END IF;
3925 
3926    --8219019 start
3927 
3928     IF p_x_header_rec.CC_INSTRUMENT_ID = FND_API.G_MISS_NUM THEN
3929        p_x_header_rec.CC_INSTRUMENT_ID := NULL;
3930     END IF;
3931 
3932     IF p_x_header_rec.CC_INSTRUMENT_ASSIGNMENT_ID = FND_API.G_MISS_NUM THEN
3933     	p_x_header_rec.CC_INSTRUMENT_ASSIGNMENT_ID := NULL;
3934     END IF;
3935 
3936    --8219019 end
3937 
3938     oe_debug_pub.add('Exiting OE_HEADER_UTIL.CONVERT_MISS_TO_NULL', 1);
3939 
3940 
3941 END Convert_Miss_To_Null;
3942 
3943 --  Procedure Update_Row
3944 
3945 PROCEDURE Update_Row
3946 (   p_header_rec                    IN  OUT  NOCOPY OE_Order_PUB.Header_Rec_Type
3947 )
3948 IS
3949 	l_org_id		NUMBER;
3950         l_lock_control          NUMBER;
3951 -- added for notification framework
3952       l_index                  NUMBER;
3953       l_return_status          VARCHAR2(1);
3954 BEGIN
3955 
3956     oe_debug_pub.add('Entering OE_HEADER_UTIL.UPDATE_ROW', 1);
3957     --Commented for MOAC start
3958     /*l_org_id := OE_GLOBALS.G_ORG_ID;
3959 
3960     IF l_org_id IS NULL THEN
3961       OE_GLOBALS.Set_Context;
3962       l_org_id := OE_GLOBALS.G_ORG_ID;
3963     END IF;*/
3964     --Commented for MOAC end
3965     -- we need to increment lock_control by 1,
3966     -- everytime there is an update on the record.
3967 
3968     SELECT lock_control
3969     INTO   l_lock_control
3970     FROM   OE_ORDER_HEADERS
3971     WHERE  header_id = p_header_rec.header_id;
3972 
3973     l_lock_control := l_lock_control + 1;
3974 
3975   -- calling notification framework to update global picture
3976   -- check code release level first. Notification framework is at Pack H level
3977    IF OE_CODE_CONTROL.CODE_RELEASE_LEVEL >= '110508' THEN
3978       OE_ORDER_UTIL.Update_Global_Picture(p_Upd_New_Rec_If_Exists => True,
3979                     p_Header_rec =>p_header_rec,
3980                     p_header_id => p_header_rec.header_id,
3981                     x_index => l_index,
3982                     x_return_status => l_return_status);
3983 
3984       OE_DEBUG_PUB.ADD('Update_Global Return Status from OE_HEADER_UTIL.update_row is: ' || l_return_status);
3985       IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
3986         OE_DEBUG_PUB.ADD('EVENT NOTIFY - Unexpected Error');
3987         OE_DEBUG_PUB.ADD('Exiting OE_HEADER_UTIL.Update_ROW', 1);
3988 	RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3989      ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
3990         OE_DEBUG_PUB.ADD('Update_Global_Picture Error in OE_HEADER_UTIL.Update_row');
3991         OE_DEBUG_PUB.ADD('Exiting OE_HEADER_UTIL.Update_ROW', 1);
3992 	RAISE FND_API.G_EXC_ERROR;
3993       END IF;
3994   END IF; /*code_release_level*/
3995   -- notification framework end
3996 
3997     UPDATE  OE_ORDER_HEADERS
3998     SET     ACCOUNTING_RULE_ID             = p_header_rec.accounting_rule_id
3999     ,       ACCOUNTING_RULE_DURATION       = p_header_rec.accounting_rule_duration
4000     ,       AGREEMENT_ID                   = p_header_rec.agreement_id
4001     ,       ATTRIBUTE1                     = p_header_rec.attribute1
4002     ,       ATTRIBUTE10                    = p_header_rec.attribute10
4003     ,       ATTRIBUTE11                    = p_header_rec.attribute11
4004     ,       ATTRIBUTE12                    = p_header_rec.attribute12
4005     ,       ATTRIBUTE13                    = p_header_rec.attribute13
4006     ,       ATTRIBUTE14                    = p_header_rec.attribute14
4007     ,       ATTRIBUTE15                    = p_header_rec.attribute15
4008     ,       ATTRIBUTE16                    = p_header_rec.attribute16   --For bug 2184255
4009     ,       ATTRIBUTE17                    = p_header_rec.attribute17
4010     ,       ATTRIBUTE18                    = p_header_rec.attribute18
4011     ,       ATTRIBUTE19                    = p_header_rec.attribute19
4012     ,       ATTRIBUTE2                     = p_header_rec.attribute2
4013     ,       ATTRIBUTE20                    = p_header_rec.attribute20
4014     ,       ATTRIBUTE3                     = p_header_rec.attribute3
4015     ,       ATTRIBUTE4                     = p_header_rec.attribute4
4016     ,       ATTRIBUTE5                     = p_header_rec.attribute5
4017     ,       ATTRIBUTE6                     = p_header_rec.attribute6
4018     ,       ATTRIBUTE7                     = p_header_rec.attribute7
4019     ,       ATTRIBUTE8                     = p_header_rec.attribute8
4020     ,       ATTRIBUTE9                     = p_header_rec.attribute9
4021     ,       BLANKET_NUMBER                 = p_header_rec.Blanket_Number
4022     ,       BOOKED_FLAG                    = p_header_rec.booked_flag
4023     ,       BOOKED_DATE				       = p_header_rec.booked_date
4024     ,       CANCELLED_FLAG                 = p_header_rec.cancelled_flag
4025     ,       CONTEXT                        = p_header_rec.context
4026     ,       CONVERSION_RATE                = p_header_rec.conversion_rate
4027     ,       CONVERSION_RATE_DATE           = p_header_rec.conversion_rate_date
4028     ,       CONVERSION_TYPE_CODE           = p_header_rec.conversion_type_code
4029     ,       CUSTOMER_PREFERENCE_SET_CODE   = p_header_rec.CUSTOMER_PREFERENCE_SET_CODE
4030     ,       CREATED_BY                     = p_header_rec.created_by
4031     ,       CREATION_DATE                  = p_header_rec.creation_date
4032     ,       CUST_PO_NUMBER                 = p_header_rec.cust_po_number
4033     ,       DELIVER_TO_CONTACT_ID          = p_header_rec.deliver_to_contact_id
4034     ,       DELIVER_TO_ORG_ID              = p_header_rec.deliver_to_org_id
4035     ,       DEMAND_CLASS_CODE              = p_header_rec.demand_class_code
4036     ,       EXPIRATION_DATE                = p_header_rec.expiration_date
4037     ,       EARLIEST_SCHEDULE_LIMIT        = p_header_rec.earliest_schedule_limit
4038     ,       FIRST_ACK_CODE                 = p_header_rec.first_ack_code
4039     ,       FIRST_ACK_DATE                 = p_header_rec.first_ack_date
4040     ,       FOB_POINT_CODE                 = p_header_rec.fob_point_code
4041     ,       FREIGHT_CARRIER_CODE           = p_header_rec.freight_carrier_code
4042     ,       FREIGHT_TERMS_CODE             = p_header_rec.freight_terms_code
4043     ,       GLOBAL_ATTRIBUTE1              = p_header_rec.global_attribute1
4044     ,       GLOBAL_ATTRIBUTE10             = p_header_rec.global_attribute10
4045     ,       GLOBAL_ATTRIBUTE11             = p_header_rec.global_attribute11
4046     ,       GLOBAL_ATTRIBUTE12             = p_header_rec.global_attribute12
4047     ,       GLOBAL_ATTRIBUTE13             = p_header_rec.global_attribute13
4048     ,       GLOBAL_ATTRIBUTE14             = p_header_rec.global_attribute14
4049     ,       GLOBAL_ATTRIBUTE15             = p_header_rec.global_attribute15
4050     ,       GLOBAL_ATTRIBUTE16             = p_header_rec.global_attribute16
4051     ,       GLOBAL_ATTRIBUTE17             = p_header_rec.global_attribute17
4052     ,       GLOBAL_ATTRIBUTE18             = p_header_rec.global_attribute18
4053     ,       GLOBAL_ATTRIBUTE19             = p_header_rec.global_attribute19
4054     ,       GLOBAL_ATTRIBUTE2              = p_header_rec.global_attribute2
4055     ,       GLOBAL_ATTRIBUTE20             = p_header_rec.global_attribute20
4056     ,       GLOBAL_ATTRIBUTE3              = p_header_rec.global_attribute3
4057     ,       GLOBAL_ATTRIBUTE4              = p_header_rec.global_attribute4
4058     ,       GLOBAL_ATTRIBUTE5              = p_header_rec.global_attribute5
4059     ,       GLOBAL_ATTRIBUTE6              = p_header_rec.global_attribute6
4060     ,       GLOBAL_ATTRIBUTE7              = p_header_rec.global_attribute7
4061     ,       GLOBAL_ATTRIBUTE8              = p_header_rec.global_attribute8
4062     ,       GLOBAL_ATTRIBUTE9              = p_header_rec.global_attribute9
4063     ,       GLOBAL_ATTRIBUTE_CATEGORY      = p_header_rec.global_attribute_category
4064     --,       HEADER_ID                      = p_header_rec.header_id
4065 
4066     ,       INVOICE_TO_CONTACT_ID          = p_header_rec.invoice_to_contact_id
4067     ,       INVOICE_TO_ORG_ID              = p_header_rec.invoice_to_org_id
4068     ,       INVOICING_RULE_ID              = p_header_rec.invoicing_rule_id
4069     ,       LAST_ACK_CODE                  = p_header_rec.last_ack_code
4070     ,       LAST_ACK_DATE                  = p_header_rec.last_ack_date
4071     ,       LAST_UPDATED_BY                = p_header_rec.last_updated_by
4072     ,       LAST_UPDATE_DATE               = p_header_rec.last_update_date
4073     ,       LAST_UPDATE_LOGIN              = p_header_rec.last_update_login
4074     ,	    LATEST_SCHEDULE_LIMIT	   = p_header_rec.latest_schedule_limit
4075     ,       OPEN_FLAG                      = p_header_rec.open_flag
4076     ,       ORDERED_DATE                   = p_header_rec.ordered_date
4077     ,       ORDER_DATE_TYPE_CODE	   = p_header_rec.order_date_type_code
4078     ,       ORDER_NUMBER                   = p_header_rec.order_number
4079     ,       ORDER_SOURCE_ID                = p_header_rec.order_source_id
4080     ,       ORDER_TYPE_ID                  = p_header_rec.order_type_id
4081     ,       ORDER_CATEGORY_CODE            = p_header_rec.order_category_code
4082 -- Org_id should not allowed to update
4083 --    ,       ORG_ID                         = p_header_rec.org_id
4084     ,       ORIG_SYS_DOCUMENT_REF          = p_header_rec.orig_sys_document_ref
4085     ,       SOURCE_DOCUMENT_ID             = p_header_rec.source_document_id
4086     ,       SOURCE_DOCUMENT_TYPE_ID        = p_header_rec.source_document_type_id
4087     ,       PARTIAL_SHIPMENTS_ALLOWED      = p_header_rec.partial_shipments_allowed
4088     ,       PAYMENT_TERM_ID                = p_header_rec.payment_term_id
4089     ,       PRICE_LIST_ID                  = p_header_rec.price_list_id
4090     ,       PRICE_REQUEST_CODE             = p_header_rec.price_request_code  -- PROMOTIONS SEP/01
4091     ,       PRICING_DATE                   = p_header_rec.pricing_date
4092     ,       PROGRAM_APPLICATION_ID         = p_header_rec.program_application_id
4093     ,       PROGRAM_ID                     = p_header_rec.program_id
4094     ,       PROGRAM_UPDATE_DATE            = p_header_rec.program_update_date
4095 
4096 
4097     ,       REQUEST_DATE                   = p_header_rec.request_date
4098     ,       REQUEST_ID                     = p_header_rec.request_id
4099     ,       RETURN_REASON_CODE             = p_header_rec.return_reason_code
4100     ,       salesrep_id                    = p_header_rec.salesrep_id
4101     ,       SALES_CHANNEL_CODE             = p_header_rec.sales_channel_code
4102     ,       SHIPMENT_PRIORITY_CODE         = p_header_rec.shipment_priority_code
4103     ,       SHIPPING_METHOD_CODE           = p_header_rec.shipping_method_code
4104     ,       SHIP_FROM_ORG_ID               = p_header_rec.ship_from_org_id
4105     ,       SHIP_TOLERANCE_ABOVE           = p_header_rec.ship_tolerance_above
4106     ,       SHIP_TOLERANCE_BELOW           = p_header_rec.ship_tolerance_below
4107     ,       SHIP_TO_CONTACT_ID             = p_header_rec.ship_to_contact_id
4108     ,       SHIP_TO_ORG_ID                 = p_header_rec.ship_to_org_id
4109     --,       SOLD_FROM_ORG_ID			   = p_header_rec.sold_from_org_id
4110     ,       SOLD_TO_CONTACT_ID             = p_header_rec.sold_to_contact_id
4111     ,       SOLD_TO_ORG_ID                 = p_header_rec.sold_to_org_id
4112     ,       SOLD_TO_PHONE_ID               = p_header_rec.sold_to_phone_id
4113     ,       TAX_EXEMPT_FLAG                = p_header_rec.tax_exempt_flag
4114     ,       TAX_EXEMPT_NUMBER              = p_header_rec.tax_exempt_number
4115     ,       TAX_EXEMPT_REASON_CODE         = p_header_rec.tax_exempt_reason_code
4116     ,       TAX_POINT_CODE                 = p_header_rec.tax_point_code
4117     ,       TRANSACTIONAL_CURR_CODE        = p_header_rec.transactional_curr_code
4118     ,       VERSION_NUMBER                 = p_header_rec.version_number
4119     ,       PAYMENT_TYPE_CODE              = p_header_rec.payment_type_code
4120     ,       PAYMENT_AMOUNT                 = p_header_rec.payment_amount
4121     ,       CHECK_NUMBER                   = p_header_rec.check_number
4122     /*,       CREDIT_CARD_CODE               = p_header_rec.credit_card_code --R12 CC Encryption
4123     ,       CREDIT_CARD_HOLDER_NAME        = p_header_rec.credit_card_holder_name
4124     ,       CREDIT_CARD_NUMBER             = p_header_rec.credit_card_number
4125     ,       CREDIT_CARD_EXPIRATION_DATE    = p_header_rec.credit_card_expiration_date
4126     ,       CREDIT_CARD_APPROVAL_DATE      = p_header_rec.credit_card_approval_date
4127     ,       CREDIT_CARD_APPROVAL_CODE      = p_header_rec.credit_card_approval_code*/ --R12 CC Encryption
4128     ,       CHANGE_SEQUENCE      	   = p_header_rec.change_sequence
4129     --,       DROP_SHIP_FLAG      	   = p_header_rec.drop_ship_flag
4130     --,       CUSTOMER_PAYMENT_TERM_ID       = p_header_rec.customer_payment_term_id
4131     ,       SHIPPING_INSTRUCTIONS       = p_header_rec.shipping_instructions
4132     ,       PACKING_INSTRUCTIONS        = p_header_rec.packing_instructions
4133     ,       FLOW_STATUS_CODE 		= p_header_rec.flow_status_code
4134     ,       MARKETING_SOURCE_CODE_ID = p_header_rec.marketing_source_code_id
4135     ,       DEFAULT_FULFILLMENT_SET        = p_header_rec.default_fulfillment_set
4136     ,       FULFILLMENT_SET_NAME           = p_header_rec.fulfillment_set_name
4137     ,       LINE_SET_NAME                  = p_header_rec.line_set_name
4138     ,       LOCK_CONTROL                = l_lock_control
4139     ,       TP_CONTEXT                        = p_header_rec.TP_context  --added for bug 3977624
4140     ,       TP_ATTRIBUTE1                     = p_header_rec.TP_attribute1
4141     ,       TP_ATTRIBUTE10                    = p_header_rec.TP_attribute10
4142     ,       TP_ATTRIBUTE11                    = p_header_rec.TP_attribute11
4143     ,       TP_ATTRIBUTE12                    = p_header_rec.TP_attribute12
4144     ,       TP_ATTRIBUTE13                    = p_header_rec.TP_attribute13
4145     ,       TP_ATTRIBUTE14                    = p_header_rec.TP_attribute14
4146     ,       TP_ATTRIBUTE15                    = p_header_rec.TP_attribute15
4147     ,       TP_ATTRIBUTE2                     = p_header_rec.TP_attribute2
4148     ,       TP_ATTRIBUTE3                     = p_header_rec.TP_attribute3
4149     ,       TP_ATTRIBUTE4                     = p_header_rec.TP_attribute4
4150     ,       TP_ATTRIBUTE5                     = p_header_rec.TP_attribute5
4151     ,       TP_ATTRIBUTE6                     = p_header_rec.TP_attribute6
4152     ,       TP_ATTRIBUTE7                     = p_header_rec.TP_attribute7
4153     ,       TP_ATTRIBUTE8                     = p_header_rec.TP_attribute8
4154     ,       TP_ATTRIBUTE9                     = p_header_rec.TP_attribute9
4155     ,       XML_MESSAGE_ID                    = p_header_rec.xml_message_id
4156 
4157     -- QUOTING changes
4158     ,       quote_date      	           = p_header_rec.quote_date
4159     ,       quote_number      	           = p_header_rec.quote_number
4160     ,       sales_document_name            = p_header_rec.sales_document_name
4161     ,       transaction_phase_code         = p_header_rec.transaction_phase_code
4162     ,       user_status_code               = p_header_rec.user_status_code
4163     ,       draft_submitted_flag           = p_header_rec.draft_submitted_flag
4164     ,       source_document_version_number = p_header_rec.source_document_version_number
4165     ,       sold_to_site_use_id            = p_header_rec.sold_to_site_use_id
4166     -- QUOTING changes END
4167 
4168     ,       Minisite_Id                       = p_header_rec.minisite_id
4169     ,       End_customer_Id                   = p_header_rec.End_customer_id
4170     ,       End_customer_contact_Id           = p_header_rec.End_customer_contact_id
4171     ,       End_customer_site_use_Id          = p_header_rec.End_customer_site_use_id
4172     ,       Ib_owner                          = p_header_rec.Ib_owner
4173     ,       Ib_installed_at_location          = p_header_rec.Ib_installed_at_location
4174     ,       Ib_current_location               = p_header_rec.Ib_current_location
4175     ,       supplier_signature                = p_header_rec.supplier_signature
4176     ,       supplier_signature_date           = p_header_rec.supplier_signature_date
4177     ,       customer_signature                = p_header_rec.customer_signature
4178     ,       customer_signature_date           = p_header_rec.customer_signature_date
4179     ,       order_firmed_date                 = p_header_rec.order_firmed_date   --key transaction dates
4180     WHERE   HEADER_ID = p_header_rec.header_id;
4181    /* AND
4182    (NVL(ORG_ID,NVL(l_org_id,0))= NVL(l_org_id,0))
4183     ;*/
4184 
4185     p_header_rec.lock_control := l_lock_control;
4186 
4187     -- aksingh update the operation to NULL and update the cache with
4188     -- record
4189     oe_order_cache.g_header_rec := p_header_rec;
4190     oe_order_cache.g_header_rec.operation := null;
4191 
4192     -- Below line commented because as g_header_rec is now global, no need
4193     -- to call below procedure to update, updated directly above
4194 
4195     -- OE_Order_Cache.Set_Order_Header(p_header_rec);
4196 
4197     oe_debug_pub.add('Exiting OE_HEADER_UTIL.UPDATE_ROW', 1);
4198 
4199 EXCEPTION
4200 
4201     WHEN OTHERS THEN
4202 
4203         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
4204         THEN
4205             OE_MSG_PUB.Add_Exc_Msg
4206             (   G_PKG_NAME
4207             ,   'Update_Row'
4208             );
4209         END IF;
4210 
4211         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4212 
4213 END Update_Row;
4214 
4215 --  Procedure Insert_Row
4216 
4217 PROCEDURE Insert_Row
4218 (   p_header_rec                    IN  OUT  NOCOPY OE_Order_PUB.Header_Rec_Type
4219 )
4220 IS
4221 	l_org_id	NUMBER;
4222 	l_upgraded_flag varchar2(1) ;
4223         l_lock_control  NUMBER := 1;
4224         l_index    NUMBER;
4225         l_return_status VARCHAR2(1);
4226         l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
4227 BEGIN
4228 
4229     oe_debug_pub.add('Entering OE_HEADER_UTIL.INSERT_ROW', 1);
4230 
4231     --MOAC change
4232     OE_GLOBALS.Set_Context;
4233     l_org_id := OE_GLOBALS.G_ORG_ID;
4234     IF l_org_id IS NULL THEN
4235          -- org_id is null, don't do insert. raise an error
4236          If l_debug_level > 0 Then
4237            oe_debug_pub.add('Org_Id is NULL',1);
4238          End If;
4239          FND_MESSAGE.SET_NAME('FND','MO_ORG_REQUIRED');
4240      	 FND_MSG_PUB.ADD;
4241          RAISE FND_API.G_EXC_ERROR;
4242     END IF;
4243 
4244 
4245     INSERT  INTO OE_ORDER_HEADERS
4246     (       ACCOUNTING_RULE_ID
4247     ,       ACCOUNTING_RULE_DURATION
4248     ,       AGREEMENT_ID
4249     ,       ATTRIBUTE1
4250     ,       ATTRIBUTE10
4251     ,       ATTRIBUTE11
4252     ,       ATTRIBUTE12
4253     ,       ATTRIBUTE13
4254     ,       ATTRIBUTE14
4255     ,       ATTRIBUTE15
4256     ,       ATTRIBUTE16   --For bug 2184255
4257     ,       ATTRIBUTE17
4258     ,       ATTRIBUTE18
4259     ,       ATTRIBUTE19
4260     ,       ATTRIBUTE2
4261     ,       ATTRIBUTE20
4262     ,       ATTRIBUTE3
4263     ,       ATTRIBUTE4
4264     ,       ATTRIBUTE5
4265     ,       ATTRIBUTE6
4266     ,       ATTRIBUTE7
4267     ,       ATTRIBUTE8
4268     ,       ATTRIBUTE9
4269     ,       BLANKET_NUMBER
4270     ,       BOOKED_FLAG
4271     ,       BOOKED_DATE
4272     ,       CANCELLED_FLAG
4273     ,       CONTEXT
4274     ,       CONVERSION_RATE
4275     ,       CONVERSION_RATE_DATE
4276     ,       CONVERSION_TYPE_CODE
4277     ,       CUSTOMER_PREFERENCE_SET_CODE
4278     ,       CREATED_BY
4279     ,       CREATION_DATE
4280     ,       CUST_PO_NUMBER
4281     ,       DELIVER_TO_CONTACT_ID
4282     ,       DELIVER_TO_ORG_ID
4283     ,       DEMAND_CLASS_CODE
4284     ,       FIRST_ACK_CODE
4285     ,       FIRST_ACK_DATE
4286     ,       EXPIRATION_DATE
4287     ,	    EARLIEST_SCHEDULE_LIMIT
4288     ,       FOB_POINT_CODE
4289     ,       FREIGHT_CARRIER_CODE
4290     ,       FREIGHT_TERMS_CODE
4291     ,       GLOBAL_ATTRIBUTE1
4292     ,       GLOBAL_ATTRIBUTE10
4293     ,       GLOBAL_ATTRIBUTE11
4294     ,       GLOBAL_ATTRIBUTE12
4295     ,       GLOBAL_ATTRIBUTE13
4296     ,       GLOBAL_ATTRIBUTE14
4297     ,       GLOBAL_ATTRIBUTE15
4298     ,       GLOBAL_ATTRIBUTE16
4299     ,       GLOBAL_ATTRIBUTE17
4300     ,       GLOBAL_ATTRIBUTE18
4301     ,       GLOBAL_ATTRIBUTE19
4302     ,       GLOBAL_ATTRIBUTE2
4303     ,       GLOBAL_ATTRIBUTE20
4304     ,       GLOBAL_ATTRIBUTE3
4305     ,       GLOBAL_ATTRIBUTE4
4306     ,       GLOBAL_ATTRIBUTE5
4307     ,       GLOBAL_ATTRIBUTE6
4308     ,       GLOBAL_ATTRIBUTE7
4309     ,       GLOBAL_ATTRIBUTE8
4310     ,       GLOBAL_ATTRIBUTE9
4311     ,       GLOBAL_ATTRIBUTE_CATEGORY
4312     ,       HEADER_ID
4313 
4314     ,       INVOICE_TO_CONTACT_ID
4315     ,       INVOICE_TO_ORG_ID
4316     ,       INVOICING_RULE_ID
4317     ,       LAST_ACK_CODE
4318     ,       LAST_ACK_DATE
4319     ,       LAST_UPDATED_BY
4320     ,       LAST_UPDATE_DATE
4321     ,       LAST_UPDATE_LOGIN
4322     ,       LATEST_SCHEDULE_LIMIT
4323     ,       OPEN_FLAG
4324     ,       ORDERED_DATE
4325     ,       ORDER_DATE_TYPE_CODE
4326     ,       ORDER_NUMBER
4327     ,       ORDER_SOURCE_ID
4328     ,       ORDER_TYPE_ID
4329     ,       ORDER_CATEGORY_CODE
4330     ,       ORG_ID                    --MOAC change. Remove the comment out
4331     ,       ORIG_SYS_DOCUMENT_REF
4332     ,       PARTIAL_SHIPMENTS_ALLOWED
4333     ,       PAYMENT_TERM_ID
4334     ,       PRICE_LIST_ID
4335     ,       PRICE_REQUEST_CODE -- PROMOTIONS SEP/01
4336     ,       PRICING_DATE
4337     ,       PROGRAM_APPLICATION_ID
4338     ,       PROGRAM_ID
4339     ,       PROGRAM_UPDATE_DATE
4340     ,       REQUEST_DATE
4341     ,       REQUEST_ID
4342     ,       RETURN_REASON_CODE
4343     ,       SALESREP_ID
4344     ,       SALES_CHANNEL_CODE
4345     ,       SHIPMENT_PRIORITY_CODE
4346     ,       SHIPPING_METHOD_CODE
4347     ,       SHIP_FROM_ORG_ID
4348     ,       SHIP_TOLERANCE_ABOVE
4349     ,       SHIP_TOLERANCE_BELOW
4350     ,       SHIP_TO_CONTACT_ID
4351     ,       SHIP_TO_ORG_ID
4352     ,	  SOLD_FROM_ORG_ID
4353     ,       SOLD_TO_CONTACT_ID
4354     ,       SOLD_TO_ORG_ID
4355     ,       SOLD_TO_PHONE_ID
4356     ,       SOURCE_DOCUMENT_ID
4357     ,       SOURCE_DOCUMENT_TYPE_ID
4358     ,       TAX_EXEMPT_FLAG
4359     ,       TAX_EXEMPT_NUMBER
4360     ,       TAX_EXEMPT_REASON_CODE
4361     ,       TAX_POINT_CODE
4362     ,       TRANSACTIONAL_CURR_CODE
4363     ,       VERSION_NUMBER
4364     ,       PAYMENT_TYPE_CODE
4365     ,       PAYMENT_AMOUNT
4366     ,       CHECK_NUMBER
4367     /*,       CREDIT_CARD_CODE --R12 CC Encryption
4368     ,       CREDIT_CARD_HOLDER_NAME
4369     ,       CREDIT_CARD_NUMBER
4370     ,       CREDIT_CARD_EXPIRATION_DATE
4371     ,       CREDIT_CARD_APPROVAL_DATE
4372     ,       CREDIT_CARD_APPROVAL_CODE*/ --R12 CC Encryption
4373     ,       CHANGE_SEQUENCE
4374    -- ,       DROP_SHIP_FLAG
4375   --  ,       CUSTOMER_PAYMENT_TERM_ID
4376     ,       SHIPPING_INSTRUCTIONS
4377     ,       PACKING_INSTRUCTIONS
4378     ,       FLOW_STATUS_CODE
4379     ,       MARKETING_SOURCE_CODE_ID
4380     ,       DEFAULT_FULFILLMENT_SET
4381     ,       FULFILLMENT_SET_NAME
4382     ,       LINE_SET_NAME
4383     ,       TP_ATTRIBUTE1
4384     ,       TP_ATTRIBUTE10
4385     ,       TP_ATTRIBUTE11
4386     ,       TP_ATTRIBUTE12
4387     ,       TP_ATTRIBUTE13
4388     ,       TP_ATTRIBUTE14
4389     ,       TP_ATTRIBUTE15
4390     ,       TP_ATTRIBUTE2
4391     ,       TP_ATTRIBUTE3
4392     ,       TP_ATTRIBUTE4
4393     ,       TP_ATTRIBUTE5
4394     ,       TP_ATTRIBUTE6
4395     ,       TP_ATTRIBUTE7
4396     ,       TP_ATTRIBUTE8
4397     ,       TP_ATTRIBUTE9
4398     ,       TP_CONTEXT
4399     ,       XML_MESSAGE_ID
4400     ,       upgraded_flag
4401     ,       LOCK_CONTROL
4402 
4403    -- QUOTING changes
4404     ,       quote_date
4405     ,       quote_number
4406     ,       sales_document_name
4407     ,       transaction_phase_code
4408     ,       user_status_code
4409     ,       draft_submitted_flag
4410     ,       source_document_version_number
4411     ,       sold_to_site_use_id
4412     -- QUOTING changes END
4413 
4414     ,       Minisite_Id
4415     ,       Ib_owner
4416     ,       Ib_installed_at_location
4417     ,       Ib_current_location
4418     ,       End_customer_id
4419     ,       End_customer_contact_id
4420     ,       End_customer_site_use_id
4421     ,       Supplier_signature
4422     ,       Supplier_signature_date
4423     ,       customer_signature
4424     ,       customer_signature_date
4425    --key transaction dates
4426     ,       order_firmed_date
4427     )
4428     VALUES
4429     (       p_header_rec.accounting_rule_id
4430     ,       p_header_rec.accounting_rule_duration
4431     ,       p_header_rec.agreement_id
4432     ,       p_header_rec.attribute1
4433     ,       p_header_rec.attribute10
4434     ,       p_header_rec.attribute11
4435     ,       p_header_rec.attribute12
4436     ,       p_header_rec.attribute13
4437     ,       p_header_rec.attribute14
4438     ,       p_header_rec.attribute15
4439     ,       p_header_rec.attribute16   --For bug 2184255
4440     ,       p_header_rec.attribute17
4441     ,       p_header_rec.attribute18
4442     ,       p_header_rec.attribute19
4443     ,       p_header_rec.attribute2
4444     ,       p_header_rec.attribute20
4445     ,       p_header_rec.attribute3
4446     ,       p_header_rec.attribute4
4447     ,       p_header_rec.attribute5
4448     ,       p_header_rec.attribute6
4449     ,       p_header_rec.attribute7
4450     ,       p_header_rec.attribute8
4451     ,       p_header_rec.attribute9
4452     ,       p_header_rec.Blanket_Number
4453     ,       p_header_rec.booked_flag
4454     ,       p_header_rec.booked_date
4455     ,       p_header_rec.cancelled_flag
4456     ,       p_header_rec.context
4457     ,       p_header_rec.conversion_rate
4458     ,       p_header_rec.conversion_rate_date
4459     ,       p_header_rec.conversion_type_code
4460     ,       p_header_rec.CUSTOMER_PREFERENCE_SET_CODE
4461     ,       p_header_rec.created_by
4462     ,       p_header_rec.creation_date
4463     ,       p_header_rec.cust_po_number
4464     ,       p_header_rec.deliver_to_contact_id
4465     ,       p_header_rec.deliver_to_org_id
4466     ,       p_header_rec.demand_class_code
4467     ,       p_header_rec.first_ack_code
4468     ,       p_header_rec.first_ack_date
4469     ,       p_header_rec.expiration_date
4470     ,       p_header_rec.earliest_schedule_limit
4471     ,       p_header_rec.fob_point_code
4472     ,       p_header_rec.freight_carrier_code
4473     ,       p_header_rec.freight_terms_code
4474     ,       p_header_rec.global_attribute1
4475     ,       p_header_rec.global_attribute10
4476     ,       p_header_rec.global_attribute11
4477     ,       p_header_rec.global_attribute12
4478     ,       p_header_rec.global_attribute13
4479     ,       p_header_rec.global_attribute14
4480     ,       p_header_rec.global_attribute15
4481     ,       p_header_rec.global_attribute16
4482     ,       p_header_rec.global_attribute17
4483     ,       p_header_rec.global_attribute18
4484     ,       p_header_rec.global_attribute19
4485     ,       p_header_rec.global_attribute2
4486     ,       p_header_rec.global_attribute20
4487     ,       p_header_rec.global_attribute3
4488     ,       p_header_rec.global_attribute4
4489     ,       p_header_rec.global_attribute5
4490     ,       p_header_rec.global_attribute6
4491     ,       p_header_rec.global_attribute7
4492     ,       p_header_rec.global_attribute8
4493     ,       p_header_rec.global_attribute9
4494     ,       p_header_rec.global_attribute_category
4495     ,       p_header_rec.header_id
4496     ,       p_header_rec.invoice_to_contact_id
4497     ,       p_header_rec.invoice_to_org_id
4498     ,       p_header_rec.invoicing_rule_id
4499     ,       p_header_rec.last_ack_code
4500     ,       p_header_rec.last_ack_date
4501     ,       p_header_rec.last_updated_by
4502     ,       p_header_rec.last_update_date
4503     ,       p_header_rec.last_update_login
4504     ,       p_header_rec.latest_schedule_limit
4505     ,       p_header_rec.open_flag
4506     ,       p_header_rec.ordered_date
4507     ,       p_header_rec.order_date_type_code
4508     ,       p_header_rec.order_number
4509     ,       p_header_rec.order_source_id
4510     ,       p_header_rec.order_type_id
4511     ,       p_header_rec.order_category_code
4512     ,       l_org_id                            --MOAC change. Remove the comment
4513     ,       p_header_rec.orig_sys_document_ref
4514     ,       p_header_rec.partial_shipments_allowed
4515     ,       p_header_rec.payment_term_id
4516     ,       p_header_rec.price_list_id
4517     ,       p_header_rec.price_request_code -- PROMOTIONS SEP/01
4518     ,       p_header_rec.pricing_date
4519     ,       p_header_rec.program_application_id
4520     ,       p_header_rec.program_id
4521     ,       p_header_rec.program_update_date
4522     ,       p_header_rec.request_date
4523     ,       p_header_rec.request_id
4524     ,       p_header_rec.return_reason_code
4525     ,       p_header_rec.salesrep_id
4526     ,       p_header_rec.sales_channel_code
4527     ,       p_header_rec.shipment_priority_code
4528     ,       p_header_rec.shipping_method_code
4529     ,       p_header_rec.ship_from_org_id
4530     ,       p_header_rec.ship_tolerance_above
4531     ,       p_header_rec.ship_tolerance_below
4532     ,       p_header_rec.ship_to_contact_id
4533     ,       p_header_rec.ship_to_org_id
4534     ,       l_org_id
4535     ,       p_header_rec.sold_to_contact_id
4536     ,       p_header_rec.sold_to_org_id
4537     ,       p_header_rec.sold_to_phone_id
4538     ,       p_header_rec.source_document_id
4539     ,       p_header_rec.source_document_type_id
4540     ,       p_header_rec.tax_exempt_flag
4541     ,       p_header_rec.tax_exempt_number
4542     ,       p_header_rec.tax_exempt_reason_code
4543     ,       p_header_rec.tax_point_code
4544     ,       p_header_rec.transactional_curr_code
4545     ,       p_header_rec.version_number
4546     ,       p_header_rec.payment_type_code
4547     ,       p_header_rec.payment_amount
4548     ,       p_header_rec.check_number
4549     /*,       p_header_rec.credit_card_code --R12 CC Encryption
4550     ,       p_header_rec.credit_card_holder_name
4551     ,       p_header_rec.credit_card_number
4552     ,       p_header_rec.credit_card_expiration_date
4553     ,       p_header_rec.credit_card_approval_date
4554     ,       p_header_rec.credit_card_approval_code*/ --R12 CC Encryption
4555     ,       p_header_rec.change_sequence
4556  --   ,       p_header_rec.drop_ship_flag
4557  --   ,       p_header_rec.customer_payment_term_id
4558     ,	  p_header_rec.shipping_instructions
4559     ,	  p_header_rec.packing_instructions
4560     ,       p_header_rec.flow_status_code
4561     ,       p_header_rec.marketing_source_code_id
4562     ,       p_header_rec.default_fulfillment_set
4563     ,       p_header_rec.fulfillment_set_name
4564     ,       p_header_rec.line_set_name
4565     ,       p_header_rec.tp_attribute1
4566     ,       p_header_rec.tp_attribute10
4567     ,       p_header_rec.tp_attribute11
4568     ,       p_header_rec.tp_attribute12
4569     ,       p_header_rec.tp_attribute13
4570     ,       p_header_rec.tp_attribute14
4571     ,       p_header_rec.tp_attribute15
4572     ,       p_header_rec.tp_attribute2
4573     ,       p_header_rec.tp_attribute3
4574     ,       p_header_rec.tp_attribute4
4575     ,       p_header_rec.tp_attribute5
4576     ,       p_header_rec.tp_attribute6
4577     ,       p_header_rec.tp_attribute7
4578     ,       p_header_rec.tp_attribute8
4579     ,       p_header_rec.tp_attribute9
4580     ,       p_header_rec.tp_context
4581     ,       p_header_rec.xml_message_id
4582     ,       l_upgraded_flag
4583     ,       l_lock_control
4584 
4585    -- QUOTING changes
4586     ,       p_header_rec.quote_date
4587     ,       p_header_rec.quote_number
4588     ,       p_header_rec.sales_document_name
4589     ,       p_header_rec.transaction_phase_code
4590     ,       p_header_rec.user_status_code
4591     ,       p_header_rec.draft_submitted_flag
4592     ,       p_header_rec.source_document_version_number
4593     ,       p_header_rec.sold_to_site_use_id
4594     -- QUOTING changes END
4595 
4596     ,       p_header_rec.minisite_id
4597     ,       p_header_rec.Ib_owner
4598     ,       p_header_rec.Ib_installed_at_location
4599     ,       p_header_rec.Ib_current_location
4600     ,       p_header_rec.end_customer_id
4601     ,       p_header_rec.end_customer_contact_id
4602     ,       p_header_rec.end_customer_site_use_id
4603     ,       p_header_rec.supplier_signature
4604     ,       p_header_rec.supplier_signature_date
4605     ,       p_header_rec.customer_signature
4606     ,       p_header_rec.customer_signature_date
4607     --key transaction dates
4608     ,       p_header_rec.order_firmed_date
4609     );
4610 
4611     p_header_rec.lock_control := l_lock_control;
4612 
4613     -- aksingh update the operation to NULL and update the cache with
4614     -- record
4615     oe_order_cache.g_header_rec := p_header_rec;
4616     oe_order_cache.g_header_rec.operation := null;
4617     OE_GLOBALS.G_HEADER_CREATED := TRUE;
4618 
4619     -- calling notification framework to update global picture
4620   -- check code release level first. Notification framework is at Pack H level
4621    IF OE_CODE_CONTROL.CODE_RELEASE_LEVEL >= '110508' THEN
4622       OE_ORDER_UTIL.Update_Global_Picture(p_Upd_New_Rec_If_Exists => True,
4623                     p_old_header_rec => NULL,
4624                     p_Header_rec =>p_header_rec,
4625                     p_header_id => p_header_rec.header_id,
4626                     x_index => l_index,
4627                     x_return_status => l_return_status);
4628      OE_DEBUG_PUB.ADD('Update_Global Return Status from OE_HEADER_UTIL.insert_row is: ' || l_return_status);
4629     OE_DEBUG_PUB.ADD('returned index is: ' || l_index ,1);
4630       IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4631         OE_DEBUG_PUB.ADD('EVENT NOTIFY - Unexpected Error');
4632         OE_DEBUG_PUB.ADD('Exiting OE_HEADER_UTIL.INSERT_ROW', 1);
4633 	RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4634       ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
4635         OE_DEBUG_PUB.ADD('Update_Global_Picture Error in OE_HEADER_UTIL.Insert_row');
4636         OE_DEBUG_PUB.ADD('Exiting OE_HEADER_UTIL.INSERT_ROW', 1);
4637 	RAISE FND_API.G_EXC_ERROR;
4638       END IF;
4639    END IF; /*code_release_level*/
4640   -- notification framework end
4641 
4642     oe_debug_pub.add('Exiting OE_HEADER_UTIL.INSERT_ROW', 1);
4643 
4644 EXCEPTION
4645 
4646     WHEN OTHERS THEN
4647 
4648         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
4649         THEN
4650             OE_MSG_PUB.Add_Exc_Msg
4651             (   G_PKG_NAME
4652             ,   'Insert_Row'
4653             );
4654         END IF;
4655 
4656         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4657 
4658 END Insert_Row;
4659 
4660 --  Procedure Delete_row
4661 
4662 PROCEDURE Delete_Row
4663 (   p_header_id                     IN  NUMBER
4664 )
4665 IS
4666 	l_return_status				VARCHAR2(30);
4667 	l_org_id                	NUMBER;
4668      -- added for notification framework
4669         l_new_header_rec     OE_Order_PUB.Header_Rec_Type;
4670         l_index              NUMBER;
4671         l_price_request_code VARCHAR2(240);     -- BUG 2670775
4672         l_transaction_phase_code VARCHAR2(30);
4673 
4674    --takintoy added for delete articles
4675    l_msg_count NUMBER;
4676    l_msg_data VARCHAR2(2000);
4677 BEGIN
4678 
4679     oe_debug_pub.add('Entering OE_HEADER_UTIL.DELETE_ROW', 1);
4680       --Commented for MOAC start
4681 	/*l_org_id := OE_GLOBALS.G_ORG_ID;
4682 	IF l_org_id IS NULL THEN
4683   	   OE_GLOBALS.Set_Context;
4684 	   l_org_id := OE_GLOBALS.G_ORG_ID;
4685 	END IF;*/
4686       --Commented for MOAC end
4687    -- added for notification framework
4688    --check code release level first. Notification framework is at Pack H level
4689    IF OE_CODE_CONTROL.CODE_RELEASE_LEVEL >= '110508' THEN
4690     /* Set the operation on the record so that globals are updated as well */
4691      l_new_header_rec.operation := OE_GLOBALS.G_OPR_DELETE;
4692      l_new_header_rec.header_id := p_header_id;
4693      OE_ORDER_UTIL.Update_Global_Picture(p_Upd_New_Rec_If_Exists => True,
4694                     p_Header_rec =>l_new_header_rec,
4695                     p_header_id => p_header_id,
4696                     x_index => l_index,
4697                     x_return_status => l_return_status);
4698      OE_DEBUG_PUB.ADD('Update_Global Return Status from OE_HEADER_UTIL.delete_row is: ' || l_return_status);
4699 
4700       IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4701         OE_DEBUG_PUB.ADD('EVENT NOTIFY - Unexpected Error');
4702         OE_DEBUG_PUB.ADD('Exiting OE_HEADER_UTIL.DELETE_ROW', 1);
4703 	RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4704       ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
4705         OE_DEBUG_PUB.ADD('Update_Global_Picture Error in OE_HEADER_UTIL.Delete_row');
4706         OE_DEBUG_PUB.ADD('Exiting OE_HEADER_UTIL.DELETE_ROW', 1);
4707 	RAISE FND_API.G_EXC_ERROR;
4708       END IF;
4709    END IF; /* code_release_level*/
4710     -- notification framework end
4711 
4712    -- BUG 2670775 Reverse Limits Begin
4713    oe_debug_pub.add('log request to Reverse_Limits for HEADER level DELETE',1);
4714    OE_Order_Cache.Load_Order_Header(p_header_id);
4715    l_price_request_code := OE_ORDER_CACHE.g_header_rec.price_request_code;
4716    l_transaction_phase_code := OE_ORDER_CACHE.g_header_rec.transaction_phase_code;
4717 
4718    -- If price_request_code is not cached, retrieve it
4719    IF l_price_request_code = FND_API.G_MISS_CHAR
4720      OR l_price_request_code is NULL THEN
4721      oe_debug_pub.add('Select price_request_code from HEADER',1);
4722      SELECT price_request_code
4723 	  INTO l_price_request_code
4724 	  FROM OE_ORDER_HEADERS
4725 	  WHERE HEADER_ID = p_header_id;
4726    END IF;
4727 
4728    OE_DELAYED_REQUESTS_UTIL.REVERSE_LIMITS
4729               ( x_return_status           => l_return_status
4730               , p_action_code             => 'CANCEL'
4731               , p_cons_price_request_code => l_price_request_code
4732               , p_orig_ordered_qty        => NULL
4733               , p_amended_qty             => NULL
4734               , p_ret_price_request_code  => NULL
4735               , p_returned_qty            => NULL
4736               , p_line_id                 => NULL
4737               );
4738     oe_debug_pub.add('Request to Reverse_Limits in OE_HEADER_UTIL.Delete_Row is done',1);
4739     IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4740           RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4741     ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
4742           RAISE FND_API.G_EXC_ERROR;
4743     END IF;
4744     -- BUG 2670775 Reverse Limits End
4745     OE_Atchmt_Util.Delete_Attachments
4746                ( p_entity_code	=> OE_GLOBALS.G_ENTITY_HEADER
4747                , p_entity_id      	=> p_header_id
4748                , x_return_status   => l_return_status
4749                );
4750     IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4751           RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4752     ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
4753           RAISE FND_API.G_EXC_ERROR;
4754     END IF;
4755 
4756     OE_Header_Payment_Util.delete_row(p_header_id => p_header_id);  --10113279
4757     OE_Header_Adj_Util.delete_row(p_header_id => p_header_id);
4758     OE_Header_Scredit_Util.delete_row(p_header_id => p_header_id);
4759     OE_Line_Util.delete_row(p_header_id => p_header_id);
4760     -- Bug 3315531
4761     -- Pass appropriate value for p_type depending on transaction phase
4762     IF nvl(l_transaction_phase_code,'F') = 'F' THEN
4763        OE_Order_WF_Util.delete_row(p_type=>'HEADER', p_id => p_header_id);
4764     ELSIF l_transaction_phase_code = 'N' THEN
4765        OE_Order_WF_Util.delete_row(p_type=>'NEGOTIATE', p_id => p_header_id);
4766     END IF;
4767     OE_Holds_PUB.Delete_Holds(p_header_id => p_header_id);
4768 
4769     OE_Delayed_Requests_Pvt.Delete_Reqs_for_deleted_entity(
4770         p_entity_code  => OE_GLOBALS.G_ENTITY_HEADER,
4771         p_entity_id     => p_header_id,
4772         x_return_status => l_return_status
4773         );
4774     IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4775           RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4776     ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
4777           RAISE FND_API.G_EXC_ERROR;
4778     END IF;
4779 
4780     /* Start Audit Trail */
4781     DELETE  FROM OE_ORDER_HEADER_HISTORY
4782     WHERE   HEADER_ID = p_header_id;
4783     /* End Audit Trail */
4784 
4785 	/* takintoy delete Contracts*/
4786     IF OE_CODE_CONTROL.CODE_RELEASE_LEVEL >= '110510' THEN
4787 	 OE_CONTRACTS_UTIL.delete_articles
4788         (
4789         p_api_version    =>1,
4790         p_doc_type       => OE_CONTRACTS_UTIL.G_SO_DOC_TYPE,
4791         p_doc_id         =>p_header_id,
4792         x_return_status  =>l_return_status,
4793         x_msg_count      =>l_msg_count,
4794         x_msg_data       =>l_msg_data);
4795      END IF;
4796     /*End contract deletion*/
4797 
4798     DELETE  FROM OE_ORDER_HEADERS
4799     WHERE   HEADER_ID = p_header_id;
4800    /* AND
4801       (NVL(ORG_ID,NVL(l_org_id,0))= NVL(l_org_id,0))
4802     ;*/
4803 
4804     oe_debug_pub.add('Exiting OE_HEADER_UTIL.DELETE_ROW', 1);
4805 
4806 EXCEPTION
4807     WHEN FND_API.G_EXC_ERROR THEN
4808     --takintoy, added for delete articles
4809     OE_MSG_PUB.Count_And_Get
4810      (
4811        p_count       => l_msg_count,
4812        p_data        => l_msg_data
4813       );
4814 		RAISE FND_API.G_EXC_ERROR;
4815     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
4816     --takintoy, added for delete articles
4817     OE_MSG_PUB.Count_And_Get
4818      (
4819        p_count       => l_msg_count,
4820        p_data        => l_msg_data
4821      );
4822 		RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4823     WHEN OTHERS THEN
4824         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
4825         THEN
4826             OE_MSG_PUB.Add_Exc_Msg
4827             (   G_PKG_NAME
4828             ,   'Delete_Row'
4829             );
4830         END IF;
4831         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4832 END Delete_Row;
4833 
4834 --R12 CC Encryption
4835 PROCEDURE Query_card_Details
4836 (    p_header_id IN NUMBER,
4837      p_credit_card_code OUT NOCOPY VARCHAR2,
4838      p_credit_card_holder_name OUT NOCOPY VARCHAR2,
4839      p_credit_card_number OUT NOCOPY VARCHAR2,
4840      p_credit_Card_expiration_date OUT NOCOPY VARCHAR2,
4841      p_credit_card_approval_code OUT NOCOPY VARCHAR2,
4842      p_credit_card_approval_Date OUT NOCOPY VARCHAR2,
4843      p_instrument_security_code OUT NOCOPY VARCHAR2,
4844      p_instrument_id	OUT NOCOPY NUMBER,
4845      p_instrument_assignment_id OUT NOCOPY NUMBER
4846 )
4847 IS
4848 l_exists VARCHAR2(1);
4849 l_trxn_extension_id NUMBER;
4850 x_bank_account_number number;
4851 x_check_number        varchar2(100);
4852 l_payment_type_code VARCHAR2(40) := 'CREDIT_CARD';
4853 l_return_status      VARCHAR2(30) := NULL ;
4854 l_msg_count          NUMBER := 0 ;
4855 l_msg_data           VARCHAR2(2000) := NULL ;
4856 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
4857 
4858 BEGIN
4859 	IF l_debug_level >0 THEN
4860 		oe_debug_pub.add('Entering Query Card Details....');
4861 		l_return_status := FND_API.G_RET_STS_SUCCESS;
4862 	END IF;
4863 
4864 	BEGIN
4865 		SELECT 'Y',trxn_extension_id
4866 		into l_exists,l_trxn_extension_id
4867 		FROM OE_PAYMENTS
4868 		WHERE header_id = p_header_id
4869 		and line_id is null and
4870 		nvl(payment_collection_event,'PREPAY') = 'INVOICE';
4871 	EXCEPTION
4872 		WHEN NO_DATA_FOUND THEN
4873 			l_exists := 'N';
4874 			IF l_debug_level >0 THEN
4875 				oe_debug_pub.add('No record in oe_payments ...in query card details');
4876 				oe_debug_pub.add('Header id passed...'||p_header_id);
4877 			END IF;
4878 	END;
4879 
4880 	IF l_exists = 'Y' and l_trxn_extension_id is not null then
4881 		BEGIN
4882 			OE_Payment_Trxn_Util.Get_Payment_Trxn_Info(p_header_id => p_header_id,
4883 			 P_trxn_extension_id => l_trxn_extension_id,
4884 			 P_payment_type_code =>  l_payment_type_code,
4885 			 X_credit_card_number => p_credit_card_number,
4886 			 X_credit_card_holder_name => p_credit_card_holder_name,
4887 			 X_credit_card_expiration_date => p_credit_card_expiration_date,
4888 			 X_credit_card_code => p_credit_card_code,
4889 			 X_credit_card_approval_code => p_credit_card_approval_code,
4890 			 X_credit_card_approval_date => p_credit_card_approval_date,
4891 			 X_bank_account_number => X_bank_account_number,
4892 			 --X_check_number => X_check_number	,
4893 			 X_instrument_security_code => p_instrument_security_code,
4894 			 X_instrument_id	=> p_instrument_id,
4895 			 X_instrument_assignment_id => p_instrument_assignment_id,
4896 			 X_return_status => l_return_status,
4897 			 X_msg_count => l_msg_count,
4898 			 X_msg_data => l_msg_data);
4899 
4900 			 IF l_return_status = FND_API.G_RET_STS_ERROR OR
4901 			 l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4902 				OE_DEBUG_PUB.add('Error in get payment trxn info...');
4903 			 ELSIF l_return_status =FND_API.G_RET_STS_SUCCESS THEN
4904 				OE_DEBUG_PUB.add('Success in get payment trxn info...');
4905 				--oe_debug_pub.add('Card holder name...'||p_credit_card_holder_name);
4906 			 END IF;
4907 
4908 		EXCEPTION
4909 		WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
4910 			l_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4911 			IF l_debug_level>0 THEN
4912 				oe_debug_pub.add('Exception in Query card details....'||sqlerrm);
4913 				oe_debug_pub.add('Return status'||l_return_status);
4914 				oe_debug_pub.add('Msg data'||l_msg_data);
4915 			END IF;
4916 		WHEN OTHERS THEN
4917 			l_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4918 			IF l_debug_level>0 THEN
4919 				oe_debug_pub.add('Exception in Query card details....'||sqlerrm);
4920 				oe_debug_pub.add('Return status'||l_return_status);
4921 				oe_debug_pub.add('Msg data'||l_msg_data);
4922 			END IF;
4923 		END;
4924 	ELSIF l_exists = 'Y' and l_trxn_extension_id is null then
4925 		BEGIN
4926 			select credit_card_number,
4927 			credit_card_holder_name,
4928 			credit_card_expiration_date,
4929 			credit_card_code,
4930 			credit_card_approval_code,
4931 			credit_card_approval_date
4932 			into p_credit_card_number,
4933 			p_credit_card_holder_name,
4934 			p_credit_card_expiration_date,
4935 			p_credit_card_code,
4936 			p_credit_card_approval_code,
4937 			p_credit_card_approval_date
4938 			from oe_payments where
4939 			header_id = p_header_id and line_id is null
4940 			and nvl(payment_collection_event,'PREPAY') = 'INVOICE';
4941 			--Set the new attributes value to null as this record was created before R12
4942 			p_instrument_security_code := NULL;
4943 			p_instrument_id := null;
4944 			p_instrument_assignment_id := null;
4945 		EXCEPTION
4946 		WHEN NO_DATA_FOUND THEN
4947 			null;
4948 		END;
4949 	ELSIF l_exists = 'N' THEN
4950 		p_credit_card_number := null;
4951 		p_credit_card_holder_name := null;
4952 		p_credit_card_expiration_date := null;
4953 		p_credit_card_code := null;
4954 		p_credit_card_approval_code := null;
4955 		p_credit_card_approval_date  := null;
4956 		p_instrument_security_code := NULL;
4957 		p_instrument_id := null;
4958 		p_instrument_assignment_id := null;
4959 	END IF;
4960 
4961 
4962 EXCEPTION
4963 WHEN OTHERS THEN
4964 	IF l_debug_level>0 THEN
4965 		oe_debug_pub.add('Exception in Query card details....'||sqlerrm);
4966 		oe_debug_pub.add('Return status'||l_return_status);
4967 		oe_debug_pub.add('Msg data'||l_msg_data);
4968 	END IF;
4969 END Query_card_Details;
4970 --R12 CC Encryption
4971 
4972 -- FUNCTION Query_Row
4973 -- IMPORTANT: DO NOT CHANGE THE SPEC OF THIS FUNCTION
4974 -- IT IS PUBLIC AND BEING CALLED BY OTHER PRODUCTS
4975 -- Private OM callers should call the procedure query_row instead
4976 -- as it has the nocopy option which would improve the performance
4977 
4978 FUNCTION Query_Row
4979 (   p_header_id                       IN  NUMBER
4980 ) RETURN OE_Order_PUB.Header_Rec_Type
4981 IS
4982 l_header_rec               OE_Order_PUB.Header_Rec_Type;
4983 BEGIN
4984 
4985     Query_Row
4986         (   p_header_id                   => p_header_id
4987         ,   x_header_rec                  => l_header_rec
4988         );
4989 
4990     RETURN l_header_rec;
4991 
4992 END Query_Row;
4993 
4994 --  Function Query_Row
4995 
4996 PROCEDURE Query_Row
4997 (   p_header_id                     IN  NUMBER,
4998     x_header_rec                    IN OUT NOCOPY OE_Order_PUB.Header_Rec_Type
4999 )
5000 IS
5001 l_org_id		NUMBER;
5002 l_x_header_rec_oper  	VARCHAR2(30);
5003 l_trxn_extension_id	NUMBER;
5004 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
5005 l_return_status               VARCHAR2(1);
5006 BEGIN
5007 
5008   if l_debug_level > 0 then
5009     oe_debug_pub.add('Entering OE_HEADER_UTIL.QUERY_ROW', 1);
5010   end if;
5011       --Commented for MOAC start
5012        /*l_org_id := OE_GLOBALS.G_ORG_ID;
5013      IF l_org_id IS NULL THEN
5014   	   OE_GLOBALS.Set_Context;
5015 	   l_org_id := OE_GLOBALS.G_ORG_ID;
5016 	END IF;*/
5017       --Commented for MOAC end
5018      -- aksingh use global record if exists for header_id
5019      IF oe_order_cache.g_header_rec.header_id = p_header_id
5020     -- { Start of the fix 2436046
5021         AND x_header_rec.lock_control <> -1
5022     -- End of the fix 2436046 }
5023      THEN
5024         l_x_header_rec_oper := x_header_rec.operation;
5025         x_header_rec := oe_order_cache.g_header_rec;
5026         x_header_rec.operation := l_x_header_rec_oper;
5027         return;
5028      END IF;
5029 
5030    -- bug 3588660
5031 /*
5032    IF  OE_CODE_CONTROL.CODE_RELEASE_LEVEL >= '110508' THEN
5033       OE_ORDER_UTIL.Clear_Global_Picture(l_return_status);
5034    END IF;
5035 */
5036     SELECT  ACCOUNTING_RULE_ID
5037     ,       ACCOUNTING_RULE_DURATION
5038     ,       AGREEMENT_ID
5039     ,       ATTRIBUTE1
5040     ,       ATTRIBUTE10
5041     ,       ATTRIBUTE11
5042     ,       ATTRIBUTE12
5043     ,       ATTRIBUTE13
5044     ,       ATTRIBUTE14
5045     ,       ATTRIBUTE15
5046     ,       ATTRIBUTE16   --For bug 2184255
5047     ,       ATTRIBUTE17
5048     ,       ATTRIBUTE18
5049     ,       ATTRIBUTE19
5050     ,       ATTRIBUTE2
5051     ,       ATTRIBUTE20
5052     ,       ATTRIBUTE3
5053     ,       ATTRIBUTE4
5054     ,       ATTRIBUTE5
5055     ,       ATTRIBUTE6
5056     ,       ATTRIBUTE7
5057     ,       ATTRIBUTE8
5058     ,       ATTRIBUTE9
5059     ,       BLANKET_NUMBER
5060     ,       BOOKED_FLAG
5061     ,       BOOKED_DATE
5062     ,       CANCELLED_FLAG
5063     ,       CONTEXT
5064     ,       CONVERSION_RATE
5065     ,       CONVERSION_RATE_DATE
5066     ,       CONVERSION_TYPE_CODE
5067     ,       CUSTOMER_PREFERENCE_SET_CODE
5068     ,       CREATED_BY
5069     ,       CREATION_DATE
5070     ,       CUST_PO_NUMBER
5071     ,       DELIVER_TO_CONTACT_ID
5072     ,       DELIVER_TO_ORG_ID
5073     ,       DEMAND_CLASS_CODE
5074     ,       FIRST_ACK_CODE
5075     ,       FIRST_ACK_DATE
5076     ,       EXPIRATION_DATE
5077     ,       EARLIEST_SCHEDULE_LIMIT
5078     ,       FOB_POINT_CODE
5079     ,       FREIGHT_CARRIER_CODE
5080     ,       FREIGHT_TERMS_CODE
5081     ,       GLOBAL_ATTRIBUTE1
5082     ,       GLOBAL_ATTRIBUTE10
5083     ,       GLOBAL_ATTRIBUTE11
5084     ,       GLOBAL_ATTRIBUTE12
5085     ,       GLOBAL_ATTRIBUTE13
5086     ,       GLOBAL_ATTRIBUTE14
5087     ,       GLOBAL_ATTRIBUTE15
5088     ,       GLOBAL_ATTRIBUTE16
5089     ,       GLOBAL_ATTRIBUTE17
5090     ,       GLOBAL_ATTRIBUTE18
5091     ,       GLOBAL_ATTRIBUTE19
5092     ,       GLOBAL_ATTRIBUTE2
5093     ,       GLOBAL_ATTRIBUTE20
5094     ,       GLOBAL_ATTRIBUTE3
5095     ,       GLOBAL_ATTRIBUTE4
5096     ,       GLOBAL_ATTRIBUTE5
5097     ,       GLOBAL_ATTRIBUTE6
5098     ,       GLOBAL_ATTRIBUTE7
5099     ,       GLOBAL_ATTRIBUTE8
5100     ,       GLOBAL_ATTRIBUTE9
5101     ,       GLOBAL_ATTRIBUTE_CATEGORY
5102     ,       HEADER_ID
5103     ,       INVOICE_TO_CONTACT_ID
5104     ,       INVOICE_TO_ORG_ID
5105     ,       INVOICING_RULE_ID
5106     ,       LAST_ACK_CODE
5107     ,       LAST_ACK_DATE
5108     ,       LAST_UPDATED_BY
5109     ,       LAST_UPDATE_DATE
5110     ,       LAST_UPDATE_LOGIN
5111     ,       LATEST_SCHEDULE_LIMIT
5112     ,       OPEN_FLAG
5113     ,       ORDERED_DATE
5114     ,       ORDER_DATE_TYPE_CODE
5115     ,       ORDER_NUMBER
5116     ,       ORDER_SOURCE_ID
5117     ,       ORDER_TYPE_ID
5118     ,       ORDER_CATEGORY_CODE
5119     ,       ORG_ID
5120     ,       ORIG_SYS_DOCUMENT_REF
5121     ,       PARTIAL_SHIPMENTS_ALLOWED
5122     ,       PAYMENT_TERM_ID
5123     ,       PRICE_LIST_ID
5124     ,       PRICE_REQUEST_CODE                    -- PROMOTIONS SEP/01
5125     ,       PRICING_DATE
5126     ,       PROGRAM_APPLICATION_ID
5127     ,       PROGRAM_ID
5128     ,       PROGRAM_UPDATE_DATE
5129     ,       REQUEST_DATE
5130     ,       REQUEST_ID
5131     ,       RETURN_REASON_CODE
5132     ,       SALESREP_ID
5133     ,       SALES_CHANNEL_CODe
5134     ,       SHIPMENT_PRIORITY_CODE
5135     ,       SHIPPING_METHOD_CODE
5136     ,       SHIP_FROM_ORG_ID
5137     ,       SHIP_TOLERANCE_ABOVE
5138     ,       SHIP_TOLERANCE_BELOW
5139     ,       SHIP_TO_CONTACT_ID
5140     ,       SHIP_TO_ORG_ID
5141     ,	    SOLD_FROM_ORG_ID
5142     ,       SOLD_TO_CONTACT_ID
5143     ,       SOLD_TO_ORG_ID
5144     ,       SOLD_TO_PHONE_ID
5145     ,       SOURCE_DOCUMENT_ID
5146     ,       SOURCE_DOCUMENT_TYPE_ID
5147     ,       TAX_EXEMPT_FLAG
5148     ,       TAX_EXEMPT_NUMBER
5149     ,       TAX_EXEMPT_REASON_CODE
5150     ,       TAX_POINT_CODE
5151     ,       TRANSACTIONAL_CURR_CODE
5152     ,       VERSION_NUMBER
5153     ,       PAYMENT_TYPE_CODE
5154     ,       PAYMENT_AMOUNT
5155     ,       CHECK_NUMBER
5156     ,       CREDIT_CARD_CODE
5157     ,       CREDIT_CARD_HOLDER_NAME
5158     ,       CREDIT_CARD_NUMBER
5159     ,       CREDIT_CARD_EXPIRATION_DATE
5160     ,       CREDIT_CARD_APPROVAL_DATE
5161     ,       CREDIT_CARD_APPROVAL_CODE
5162     ,       SHIPPING_INSTRUCTIONS
5163     ,       PACKING_INSTRUCTIONS
5164     ,       FLOW_STATUS_CODE
5165     ,       MARKETING_SOURCE_CODE_ID
5166     ,       DEFAULT_FULFILLMENT_SET
5167     ,       FULFILLMENT_SET_NAME
5168     ,       LINE_SET_NAME
5169     ,       TP_ATTRIBUTE1
5170     ,       TP_ATTRIBUTE10
5171     ,       TP_ATTRIBUTE11
5172     ,       TP_ATTRIBUTE12
5173     ,       TP_ATTRIBUTE13
5174     ,       TP_ATTRIBUTE14
5175     ,       TP_ATTRIBUTE15
5176     ,       TP_ATTRIBUTE2
5177     ,       TP_ATTRIBUTE3
5178     ,       TP_ATTRIBUTE4
5179     ,       TP_ATTRIBUTE5
5180     ,       TP_ATTRIBUTE6
5181     ,       TP_ATTRIBUTE7
5182     ,       TP_ATTRIBUTE8
5183     ,       TP_ATTRIBUTE9
5184     ,       TP_CONTEXT
5185     ,       XML_MESSAGE_ID
5186     ,       upgraded_flag
5187     ,       LOCK_CONTROL
5188     ,       CHANGE_SEQUENCE
5189     ,	    quote_date
5190     ,       quote_number
5191     ,       sales_document_name
5192     ,       transaction_phase_code
5193     ,       user_status_code
5194     ,       draft_submitted_flag
5195     ,       source_document_version_number
5196     ,       sold_to_site_use_id
5197     ,       MINISITE_ID
5198     ,       IB_OWNER
5199     ,       IB_INSTALLED_AT_LOCATION
5200     ,       IB_CURRENT_LOCATION
5201     ,       END_CUSTOMER_ID
5202     ,       END_CUSTOMER_CONTACT_ID
5203     ,       END_CUSTOMER_SITE_USE_ID
5204     ,       SUPPLIER_SIGNATURE
5205     ,       SUPPLIER_SIGNATURE_DATE
5206     ,       CUSTOMER_SIGNATURE
5207     ,       CUSTOMER_SIGNATURE_DATE
5208 --key Transaction Dates
5209     ,       order_firmed_date
5210     INTO    x_header_rec.accounting_rule_id
5211     ,       x_header_rec.accounting_rule_duration
5212     ,       x_header_rec.agreement_id
5213     ,       x_header_rec.attribute1
5214     ,       x_header_rec.attribute10
5215     ,       x_header_rec.attribute11
5216     ,       x_header_rec.attribute12
5217     ,       x_header_rec.attribute13
5218     ,       x_header_rec.attribute14
5219     ,       x_header_rec.attribute15
5220     ,       x_header_rec.attribute16   --For bug 2184255
5221     ,       x_header_rec.attribute17
5222     ,       x_header_rec.attribute18
5223     ,       x_header_rec.attribute19
5224     ,       x_header_rec.attribute2
5225     ,       x_header_rec.attribute20
5226     ,       x_header_rec.attribute3
5227     ,       x_header_rec.attribute4
5228     ,       x_header_rec.attribute5
5229     ,       x_header_rec.attribute6
5230     ,       x_header_rec.attribute7
5231     ,       x_header_rec.attribute8
5232     ,       x_header_rec.attribute9
5233     ,       x_header_rec.Blanket_Number
5234     ,       x_header_rec.booked_flag
5235     ,       x_header_rec.booked_date
5236     ,       x_header_rec.cancelled_flag
5237     ,       x_header_rec.context
5238     ,       x_header_rec.conversion_rate
5239     ,       x_header_rec.conversion_rate_date
5240     ,       x_header_rec.conversion_type_code
5241     ,       x_header_rec.CUSTOMER_PREFERENCE_SET_CODE
5242     ,       x_header_rec.created_by
5243     ,       x_header_rec.creation_date
5244     ,       x_header_rec.cust_po_number
5245     ,       x_header_rec.deliver_to_contact_id
5246     ,       x_header_rec.deliver_to_org_id
5247     ,       x_header_rec.demand_class_code
5248     ,       x_header_rec.first_ack_code
5249     ,       x_header_rec.first_ack_date
5250     ,       x_header_rec.expiration_date
5251     ,       x_header_rec.earliest_schedule_limit
5252     ,       x_header_rec.fob_point_code
5253     ,       x_header_rec.freight_carrier_code
5254     ,       x_header_rec.freight_terms_code
5255     ,       x_header_rec.global_attribute1
5256     ,       x_header_rec.global_attribute10
5257     ,       x_header_rec.global_attribute11
5258     ,       x_header_rec.global_attribute12
5259     ,       x_header_rec.global_attribute13
5260     ,       x_header_rec.global_attribute14
5261     ,       x_header_rec.global_attribute15
5262     ,       x_header_rec.global_attribute16
5263     ,       x_header_rec.global_attribute17
5264     ,       x_header_rec.global_attribute18
5265     ,       x_header_rec.global_attribute19
5266     ,       x_header_rec.global_attribute2
5267     ,       x_header_rec.global_attribute20
5268     ,       x_header_rec.global_attribute3
5269     ,       x_header_rec.global_attribute4
5270     ,       x_header_rec.global_attribute5
5271     ,       x_header_rec.global_attribute6
5272     ,       x_header_rec.global_attribute7
5273     ,       x_header_rec.global_attribute8
5274     ,       x_header_rec.global_attribute9
5275     ,       x_header_rec.global_attribute_category
5276     ,       x_header_rec.header_id
5277     ,       x_header_rec.invoice_to_contact_id
5278     ,       x_header_rec.invoice_to_org_id
5279     ,       x_header_rec.invoicing_rule_id
5280     ,       x_header_rec.last_ack_code
5281     ,       x_header_rec.last_ack_date
5282     ,       x_header_rec.last_updated_by
5283     ,       x_header_rec.last_update_date
5284     ,       x_header_rec.last_update_login
5285     ,       x_header_rec.latest_schedule_limit
5286     ,       x_header_rec.open_flag
5287     ,       x_header_rec.ordered_date
5288     ,       x_header_rec.order_date_type_code
5289     ,       x_header_rec.order_number
5290     ,       x_header_rec.order_source_id
5291     ,       x_header_rec.order_type_id
5292     ,       x_header_rec.order_category_code
5293     ,       x_header_rec.org_id
5294     ,       x_header_rec.orig_sys_document_ref
5295     ,       x_header_rec.partial_shipments_allowed
5296     ,       x_header_rec.payment_term_id
5297     ,       x_header_rec.price_list_id
5298     ,       x_header_rec.price_request_code           -- PROMOTIONS SEP/01
5299     ,       x_header_rec.pricing_date
5300     ,       x_header_rec.program_application_id
5301     ,       x_header_rec.program_id
5302     ,       x_header_rec.program_update_date
5303     ,       x_header_rec.request_date
5304     ,       x_header_rec.request_id
5305     ,       x_header_rec.return_reason_code
5306     ,       x_header_rec.salesrep_id
5307     ,       x_header_rec.sales_channel_code
5308     ,       x_header_rec.shipment_priority_code
5309     ,       x_header_rec.shipping_method_code
5310     ,       x_header_rec.ship_from_org_id
5311     ,       x_header_rec.ship_tolerance_above
5312     ,       x_header_rec.ship_tolerance_below
5313     ,       x_header_rec.ship_to_contact_id
5314     ,       x_header_rec.ship_to_org_id
5315     ,	  x_header_rec.sold_from_org_id
5316     ,       x_header_rec.sold_to_contact_id
5317     ,       x_header_rec.sold_to_org_id
5318     ,       x_header_rec.sold_to_phone_id
5319     ,       x_header_rec.source_document_id
5320     ,       x_header_rec.source_document_type_id
5321     ,       x_header_rec.tax_exempt_flag
5322     ,       x_header_rec.tax_exempt_number
5323     ,       x_header_rec.tax_exempt_reason_code
5324     ,       x_header_rec.tax_point_code
5325     ,       x_header_rec.transactional_curr_code
5326     ,       x_header_rec.version_number
5327     ,       x_header_rec.payment_type_code
5328     ,       x_header_rec.payment_amount
5329     ,       x_header_rec.check_number
5330     ,       x_header_rec.credit_card_code
5331     ,       x_header_rec.credit_card_holder_name
5332     ,       x_header_rec.credit_card_number
5333     ,       x_header_rec.credit_card_expiration_date
5334     ,       x_header_rec.credit_card_approval_date
5335     ,       x_header_rec.credit_card_approval_code
5336     ,       x_header_rec.shipping_instructions
5337     ,       x_header_rec.packing_instructions
5338     ,       x_header_rec.flow_status_code
5339     ,       x_header_rec.marketing_source_code_id
5340     ,       x_header_rec.default_fulfillment_set
5341     ,       x_header_rec.fulfillment_set_name
5342     ,       x_header_rec.line_set_name
5343     ,       x_header_rec.tp_attribute1
5344     ,       x_header_rec.tp_attribute10
5345     ,       x_header_rec.tp_attribute11
5346     ,       x_header_rec.tp_attribute12
5347     ,       x_header_rec.tp_attribute13
5348     ,       x_header_rec.tp_attribute14
5349     ,       x_header_rec.tp_attribute15
5350     ,       x_header_rec.tp_attribute2
5351     ,       x_header_rec.tp_attribute3
5352     ,       x_header_rec.tp_attribute4
5353     ,       x_header_rec.tp_attribute5
5354     ,       x_header_rec.tp_attribute6
5355     ,       x_header_rec.tp_attribute7
5356     ,       x_header_rec.tp_attribute8
5357     ,       x_header_rec.tp_attribute9
5358     ,       x_header_rec.tp_context
5359     ,       x_header_rec.xml_message_id
5360     ,       x_header_rec.upgraded_flag
5361     ,       x_header_rec.lock_control
5362     ,       x_header_rec.change_sequence
5363     ,       x_header_rec.quote_date
5364     ,       x_header_rec.quote_number
5365     ,       x_header_rec.sales_document_name
5366     ,       x_header_rec.transaction_phase_code
5367     ,       x_header_rec.user_status_code
5368     ,       x_header_rec.draft_submitted_flag
5369     ,       x_header_rec.source_document_version_number
5370     ,       x_header_rec.sold_to_site_use_id
5371     ,       x_header_rec.minisite_id
5372     ,       x_header_rec.ib_owner
5373     ,       x_header_rec.ib_installed_at_location
5374     ,       x_header_rec.ib_current_location
5375     ,       x_header_rec.end_customer_id
5376     ,       x_header_rec.end_customer_contact_id
5377     ,       x_header_rec.end_customer_site_use_id
5378     ,       x_header_rec.supplier_signature
5379     ,       x_header_rec.supplier_signature_date
5380     ,       x_header_rec.customer_signature
5381     ,       x_header_rec.customer_signature_date
5382   --key Transaction Dates
5383     ,       x_header_rec.order_firmed_date
5384     FROM    OE_ORDER_HEADERS_ALL
5385     WHERE   HEADER_ID = p_header_id;
5386    /* AND
5387    (NVL(ORG_ID,NVL(l_org_id,0))= NVL(l_org_id,0))
5388     ;*/
5389 
5390     --R12 CC Encryption
5391 
5392     --Need to call query card details procedure to get the credit card
5393     --details as the OM tables would not have these values in R12
5394     IF x_header_rec.payment_type_code IS NOT NULL AND
5395        x_header_rec.payment_type_code = 'CREDIT_CARD' THEN
5396 
5397        BEGIN
5398          SELECT trxn_extension_id
5399          INTO   l_trxn_extension_id
5400          FROM   oe_payments
5401          WHERE  header_id = p_header_id
5402          AND    nvl(payment_collection_event,'PREPAY') = 'INVOICE'
5403          AND    payment_type_code = 'CREDIT_CARD'
5404          AND    line_id is null;
5405        EXCEPTION WHEN NO_DATA_FOUND THEN
5406          null;
5407        END;
5408 
5409        IF l_trxn_extension_id is not null THEN
5410  	 if l_debug_level > 0 then
5411 		oe_debug_pub.add('Calling query card details...');
5412 	 end if;
5413 		Query_card_details
5414 	       ( p_header_id	=> x_header_rec.header_id,
5415 		 p_credit_card_code => x_header_rec.credit_card_code,
5416 		 p_credit_card_holder_name => x_header_rec.credit_card_holder_name,
5417 		 p_credit_card_number => x_header_rec.credit_card_number,
5418 		 p_credit_Card_expiration_date => x_header_rec.credit_card_expiration_date,
5419 		 p_credit_card_approval_code => x_header_rec.credit_card_approval_code,
5420 		 p_credit_card_approval_Date => x_header_rec.credit_card_approval_date,
5421 		 p_instrument_security_code => x_header_rec.instrument_security_code,
5422 		 p_instrument_id => x_header_rec.cc_instrument_id,
5423 		 p_instrument_assignment_id => x_header_rec.cc_instrument_assignment_id
5424 		);
5425        END IF;
5426      END IF;
5427      --R12 CC Encryption
5428 
5429     -- aksingh assigning the global record, so later the cached record
5430     -- will be used instead of querying again
5431   if l_debug_level > 0 then
5432     oe_debug_pub.add('Before caching OE_HEADER_UTIL.QUERY_ROW', 1);
5433   end if;
5434 
5435     oe_order_cache.g_header_rec := x_header_rec;
5436     oe_order_cache.g_header_rec.operation := null;
5437 
5438   if l_debug_level > 0 then
5439     oe_debug_pub.add('Exiting OE_HEADER_UTIL.QUERY_ROW', 1);
5440   end if;
5441 
5442 
5443 EXCEPTION
5444 
5445     WHEN NO_DATA_FOUND THEN
5446 
5447 	   RAISE NO_DATA_FOUND;
5448 
5449     WHEN OTHERS THEN
5450 
5451         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
5452         THEN
5453             OE_MSG_PUB.Add_Exc_Msg
5454             (   G_PKG_NAME
5455             ,   'Query_Row'
5456             );
5457         END IF;
5458 
5459         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5460 
5461 END Query_Row;
5462 
5463 --  Procedure       lock_Row
5464 --
5465 
5466 PROCEDURE Lock_Row
5467 (   x_return_status                 OUT NOCOPY /* file.sql.39 change */ VARCHAR2
5468 ,   p_x_header_rec                  IN OUT NOCOPY OE_Order_PUB.Header_Rec_Type
5469 ,   p_header_id			    IN  NUMBER
5470 					:= FND_API.G_MISS_NUM
5471 )
5472 IS
5473      l_header_id		      NUMBER;
5474      l_lock_control                   NUMBER;
5475      l_db_lock_control                NUMBER;
5476 BEGIN
5477 
5478     oe_debug_pub.add('Entering OE_HEADER_UTIL.LOCK_ROW', 1);
5479 
5480     SAVEPOINT Lock_Row;
5481 
5482     l_lock_control := NULL;
5483 
5484     -- Retrieve the primary key.
5485     IF 	p_header_id <> FND_API.G_MISS_NUM THEN
5486 		l_header_id := p_header_id;
5487     ELSE
5488 		l_header_id    := p_x_header_rec.header_id;
5489           l_lock_control := p_x_header_rec.lock_control;
5490     END IF;
5491 
5492     SELECT header_id, lock_control
5493     INTO l_header_id, l_db_lock_control
5494     FROM OE_ORDER_HEADERS_ALL
5495     WHERE HEADER_ID = l_header_id
5496       FOR UPDATE NOWAIT;
5497 
5498     -- { Start of the fix 2436046, query part is old
5499     IF l_db_lock_control is not null and
5500        nvl(l_lock_control, FND_API.G_MISS_NUM) <> l_db_lock_control
5501     THEN
5502        p_x_header_rec.lock_control := -1;
5503     END IF;
5504     -- End of the fix 2436046 }
5505 
5506     OE_Header_Util.Query_Row(p_header_id  => l_header_id,
5507                             x_header_rec => p_x_header_rec);
5508 
5509     oe_debug_pub.add('selected for update, now compare', 3);
5510 
5511 
5512     -- If lock_control is not passed(is null or missing), then return the locked record.
5513 
5514     IF l_lock_control is null OR
5515        l_lock_control = FND_API.G_MISS_NUM
5516     THEN
5517 
5518         --  Set out parameter, out rec is already set by query row.
5519 
5520         --  Set return status
5521         x_return_status                := FND_API.G_RET_STS_SUCCESS;
5522         p_x_header_rec.return_status       := FND_API.G_RET_STS_SUCCESS;
5523 
5524 	RETURN;
5525 
5526     END IF;
5527 
5528     --  Row locked. If the whole record is passed, then
5529     --  Compare the value of lock_control column to DB value.
5530 
5531 -- following constants are used to debug lock_order,
5532 -- please do not use them for any other purpose.
5533 -- set G_LOCK_TEST := 'Y', for debugging.
5534 
5535     OE_GLOBALS.G_LOCK_CONST  := 0;
5536     --OE_GLOBALS.G_LOCK_TEST := 'Y';
5537     OE_GLOBALS.G_LOCK_TEST   := 'N';
5538 
5539     IF OE_GLOBALS.Equal(p_x_header_rec.lock_control,
5540                         l_lock_control)
5541       THEN
5542 
5543         oe_debug_pub.add('done comparison, success', 1);
5544         --  Row has not changed. Set out parameter.
5545 
5546         --  Set return status
5547 
5548         x_return_status                  := FND_API.G_RET_STS_SUCCESS;
5549         p_x_header_rec.return_status     := FND_API.G_RET_STS_SUCCESS;
5550 
5551     ELSE
5552 
5553         oe_debug_pub.add('row changed by other user', 1);
5554 
5555         --  Row has changed by another user.
5556 
5557         x_return_status                  := FND_API.G_RET_STS_ERROR;
5558         p_x_header_rec.return_status     := FND_API.G_RET_STS_ERROR;
5559 
5560         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_ERROR)
5561         THEN
5562 
5563 	    -- Release the lock
5564             ROLLBACK TO Lock_Row;
5565 
5566             fnd_message.set_name('ONT','OE_LOCK_ROW_CHANGED');
5567             OE_MSG_PUB.Add;
5568 
5569         END IF;
5570 
5571     END IF;
5572 
5573     oe_debug_pub.add('Exiting OE_HEADER_UTIL.LOCK_ROW', 1);
5574 
5575     OE_GLOBALS.G_LOCK_TEST := 'N';
5576 EXCEPTION
5577 
5578     WHEN NO_DATA_FOUND THEN
5579 
5580         x_return_status                := FND_API.G_RET_STS_ERROR;
5581         p_x_header_rec.return_status     := FND_API.G_RET_STS_ERROR;
5582 
5583         oe_debug_pub.add('no data found in lock_header', 1);
5584 
5585         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_ERROR)
5586         THEN
5587 
5588             fnd_message.set_name('ONT','OE_LOCK_ROW_DELETED');
5589             OE_MSG_PUB.Add;
5590 
5591         END IF;
5592 
5593         OE_GLOBALS.G_LOCK_TEST := 'N';
5594 
5595     WHEN APP_EXCEPTIONS.RECORD_LOCK_EXCEPTION THEN
5596 
5597         x_return_status                := FND_API.G_RET_STS_ERROR;
5598         p_x_header_rec.return_status     := FND_API.G_RET_STS_ERROR;
5599 
5600         oe_debug_pub.add('record_lock in lock_header', 1);
5601 
5602         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_ERROR)
5603         THEN
5604 
5605             fnd_message.set_name('ONT','OE_LOCK_ROW_ALREADY_LOCKED');
5606             OE_MSG_PUB.Add;
5607 
5608         END IF;
5609         OE_GLOBALS.G_LOCK_TEST := 'N';
5610     WHEN OTHERS THEN
5611 
5612         oe_debug_pub.add('others in lock_header', 1);
5613         x_return_status                := FND_API.G_RET_STS_UNEXP_ERROR;
5614         p_x_header_rec.return_status     := FND_API.G_RET_STS_UNEXP_ERROR;
5615 
5616         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
5617         THEN
5618             OE_MSG_PUB.Add_Exc_Msg
5619             (   G_PKG_NAME
5620             ,   'Lock_Row'
5621             );
5622         END IF;
5623         OE_GLOBALS.G_LOCK_TEST := 'N';
5624 END Lock_Row;
5625 
5626 --  Function Get_Values
5627 
5628 FUNCTION Get_Values
5629 (   p_header_rec                    IN  OE_Order_PUB.Header_Rec_Type
5630 ,   p_old_header_rec                IN  OE_Order_PUB.Header_Rec_Type :=
5631                                         OE_Order_PUB.G_MISS_HEADER_REC
5632 ) RETURN OE_Order_PUB.Header_Val_Rec_Type
5633 IS
5634 	l_header_val_rec          OE_Order_PUB.Header_Val_Rec_Type;
5635 -- FP contracts word integration
5636 	l_return_status                VARCHAR2(30);
5637         l_msg_count        NUMBER;
5638         l_msg_data         VARCHAR2(2000);
5639 BEGIN
5640 
5641     oe_debug_pub.add('Entering OE_HEADER_UTIL.GET_VALUES', 1);
5642 
5643     l_header_val_rec := OE_Order_PUB.G_MISS_HEADER_VAL_REC;
5644 
5645     IF (p_header_rec.accounting_rule_id IS NULL OR
5646         p_header_rec.accounting_rule_id <> FND_API.G_MISS_NUM) AND
5647         NOT OE_GLOBALS.Equal(p_header_rec.accounting_rule_id,
5648         p_old_header_rec.accounting_rule_id)
5649     THEN
5650         l_header_val_rec.accounting_rule := OE_Id_To_Value.Accounting_Rule
5651         (   p_accounting_rule_id          => p_header_rec.accounting_rule_id
5652         );
5653     END IF;
5654 
5655     IF (p_header_rec.agreement_id IS NULL OR
5656         p_header_rec.agreement_id <> FND_API.G_MISS_NUM) AND
5657         NOT OE_GLOBALS.Equal(p_header_rec.agreement_id,
5658         p_old_header_rec.agreement_id)
5659     THEN
5660         l_header_val_rec.agreement := OE_Id_To_Value.Agreement
5661         (   p_agreement_id                => p_header_rec.agreement_id
5662         );
5663     END IF;
5664 
5665     IF (p_header_rec.conversion_type_code IS NULL OR
5666         p_header_rec.conversion_type_code <> FND_API.G_MISS_CHAR) AND
5667         NOT OE_GLOBALS.Equal(p_header_rec.conversion_type_code,
5668         p_old_header_rec.conversion_type_code)
5669     THEN
5670         l_header_val_rec.conversion_type := OE_Id_To_Value.Conversion_Type
5671         (   p_conversion_type_code        => p_header_rec.conversion_type_code
5672         );
5673     END IF;
5674 
5675     IF (p_header_rec.deliver_to_contact_id IS NULL OR
5676         p_header_rec.deliver_to_contact_id <> FND_API.G_MISS_NUM) AND
5677         NOT OE_GLOBALS.Equal(p_header_rec.deliver_to_contact_id,
5678         p_old_header_rec.deliver_to_contact_id)
5679     THEN
5680         l_header_val_rec.deliver_to_contact := OE_Id_To_Value.Deliver_To_Contact
5681         (   p_deliver_to_contact_id       => p_header_rec.deliver_to_contact_id
5682         );
5683     END IF;
5684 
5685     IF (p_header_rec.deliver_to_org_id IS NULL OR
5686         p_header_rec.deliver_to_org_id <> FND_API.G_MISS_NUM) AND
5687         NOT OE_GLOBALS.Equal(p_header_rec.deliver_to_org_id,
5688         p_old_header_rec.deliver_to_org_id)
5689     THEN
5690         get_customer_details
5691         (   p_org_id             => p_header_rec.deliver_to_org_id
5692         ,   p_site_use_code      =>'DELIVER_TO'
5693         ,   x_customer_name      => l_header_val_rec.deliver_to_customer_name
5694         ,   x_customer_number    => l_header_val_rec.deliver_to_customer_number
5695         ,   x_customer_id        => l_header_val_rec.deliver_to_customer_id
5696         ,   x_location        => l_header_val_rec.deliver_to_location
5697         ,   x_address1        => l_header_val_rec.deliver_to_address1
5698         ,   x_address2        => l_header_val_rec.deliver_to_address2
5699         ,   x_address3        => l_header_val_rec.deliver_to_address3
5700         ,   x_address4        => l_header_val_rec.deliver_to_address4
5701         ,   x_city        => l_header_val_rec.deliver_to_city
5702         ,   x_state        => l_header_val_rec.deliver_to_state
5703         ,   x_zip        => l_header_val_rec.deliver_to_zip
5704         ,   x_country        => l_header_val_rec.deliver_to_country
5705         );
5706         l_header_val_rec.deliver_to_org :=l_header_val_rec.deliver_to_location;
5707 
5708     END IF;
5709 
5710     IF (p_header_rec.fob_point_code IS NULL OR
5711         p_header_rec.fob_point_code <> FND_API.G_MISS_CHAR) AND
5712         NOT OE_GLOBALS.Equal(p_header_rec.fob_point_code,
5713         p_old_header_rec.fob_point_code)
5714     THEN
5715         l_header_val_rec.fob_point := OE_Id_To_Value.Fob_Point
5716         (   p_fob_point_code              => p_header_rec.fob_point_code
5717         );
5718     END IF;
5719 
5720     IF (p_header_rec.freight_terms_code IS NULL OR
5721         p_header_rec.freight_terms_code <> FND_API.G_MISS_CHAR) AND
5722         NOT OE_GLOBALS.Equal(p_header_rec.freight_terms_code,
5723         p_old_header_rec.freight_terms_code)
5724     THEN
5725         l_header_val_rec.freight_terms := OE_Id_To_Value.Freight_Terms
5726         (   p_freight_terms_code          => p_header_rec.freight_terms_code
5727         );
5728     END IF;
5729 
5730     IF (p_header_rec.freight_carrier_code IS NULL OR
5731         p_header_rec.freight_carrier_code <> FND_API.G_MISS_CHAR) AND
5732         NOT OE_GLOBALS.Equal(p_header_rec.freight_carrier_code,
5733         p_old_header_rec.freight_carrier_code)
5734     THEN
5735         l_header_val_rec.freight_carrier := OE_Id_To_Value.Freight_Carrier
5736         (   p_freight_carrier_code          => p_header_rec.freight_carrier_code
5737 	   ,   p_ship_from_org_id		    => p_header_rec.ship_from_org_id
5738         );
5739     END IF;
5740     IF (p_header_rec.shipping_method_code IS NULL OR
5741         p_header_rec.shipping_method_code <> FND_API.G_MISS_CHAR) AND
5742         NOT OE_GLOBALS.Equal(p_header_rec.shipping_method_code,
5743         p_old_header_rec.shipping_method_code)
5744     THEN
5745         l_header_val_rec.shipping_method := OE_Id_To_Value.ship_method
5746         (   p_ship_method_code   => p_header_rec.shipping_method_code
5747         );
5748     END IF;
5749 
5750     IF (p_header_rec.invoice_to_contact_id IS NULL OR
5751         p_header_rec.invoice_to_contact_id <> FND_API.G_MISS_NUM) AND
5752         NOT OE_GLOBALS.Equal(p_header_rec.invoice_to_contact_id,
5753         p_old_header_rec.invoice_to_contact_id)
5754     THEN
5755         l_header_val_rec.invoice_to_contact := OE_Id_To_Value.Invoice_To_Contact
5756         (   p_invoice_to_contact_id       => p_header_rec.invoice_to_contact_id
5757         );
5758     END IF;
5759 
5760     IF (p_header_rec.invoice_to_org_id IS NULL OR
5761         p_header_rec.invoice_to_org_id <> FND_API.G_MISS_NUM) AND
5762         NOT OE_GLOBALS.Equal(p_header_rec.invoice_to_org_id,
5763         p_old_header_rec.invoice_to_org_id)
5764     THEN
5765 
5766         get_customer_details
5767         (   p_org_id             => p_header_rec.invoice_to_org_id
5768         ,   p_site_use_code      =>'BILL_TO'
5769         ,   x_customer_name      => l_header_val_rec.invoice_to_customer_name
5770         ,   x_customer_number    => l_header_val_rec.invoice_to_customer_number
5771         ,   x_customer_id        => l_header_val_rec.invoice_to_customer_id
5772         ,   x_location        => l_header_val_rec.invoice_to_location
5773         ,   x_address1        => l_header_val_rec.invoice_to_address1
5774         ,   x_address2        => l_header_val_rec.invoice_to_address2
5775         ,   x_address3        => l_header_val_rec.invoice_to_address3
5776         ,   x_address4        => l_header_val_rec.invoice_to_address4
5777         ,   x_city        => l_header_val_rec.invoice_to_city
5778         ,   x_state        => l_header_val_rec.invoice_to_state
5779         ,   x_zip        => l_header_val_rec.invoice_to_zip
5780         ,   x_country        => l_header_val_rec.invoice_to_country
5781         );
5782         l_header_val_rec.invoice_to_org :=l_header_val_rec.invoice_to_location;
5783 
5784     END IF;
5785 
5786     IF (p_header_rec.invoicing_rule_id IS NULL OR
5787         p_header_rec.invoicing_rule_id <> FND_API.G_MISS_NUM) AND
5788         NOT OE_GLOBALS.Equal(p_header_rec.invoicing_rule_id,
5789         p_old_header_rec.invoicing_rule_id)
5790     THEN
5791         l_header_val_rec.invoicing_rule := OE_Id_To_Value.Invoicing_Rule
5792         (   p_invoicing_rule_id           => p_header_rec.invoicing_rule_id
5793         );
5794     END IF;
5795 
5796     IF (p_header_rec.order_source_id IS NULL OR
5797         p_header_rec.order_source_id <> FND_API.G_MISS_NUM) AND
5798         NOT OE_GLOBALS.Equal(p_header_rec.order_source_id,
5799         p_old_header_rec.order_source_id)
5800     THEN
5801         l_header_val_rec.order_source := OE_Id_To_Value.Order_Source
5802         (   p_order_source_id             => p_header_rec.order_source_id
5803         );
5804     END IF;
5805 
5806     IF (p_header_rec.order_date_type_code IS NULL OR
5807         p_header_rec.order_date_type_code <> FND_API.G_MISS_CHAR) AND
5808         NOT OE_GLOBALS.Equal(p_header_rec.order_date_type_code,
5809         p_old_header_rec.order_date_type_code)
5810     THEN
5811         l_header_val_rec.order_date_type := OE_Id_To_Value.Order_Date_Type
5812         (   p_order_date_type_code        => p_header_rec.order_date_type_code
5813         );
5814     END IF;
5815 
5816     IF (p_header_rec.order_type_id IS NULL OR
5817         p_header_rec.order_type_id <> FND_API.G_MISS_NUM) AND
5818         NOT OE_GLOBALS.Equal(p_header_rec.order_type_id,
5819         p_old_header_rec.order_type_id)
5820     THEN
5821         l_header_val_rec.order_type := OE_Id_To_Value.Order_Type
5822         (   p_order_type_id               => p_header_rec.order_type_id
5823         );
5824     END IF;
5825 
5826     IF (p_header_rec.payment_term_id IS NULL OR
5827         p_header_rec.payment_term_id <> FND_API.G_MISS_NUM) AND
5828         NOT OE_GLOBALS.Equal(p_header_rec.payment_term_id,
5829         p_old_header_rec.payment_term_id)
5830     THEN
5831         l_header_val_rec.payment_term := OE_Id_To_Value.Payment_Term
5832         (   p_payment_term_id             => p_header_rec.payment_term_id
5833         );
5834     END IF;
5835 
5836     IF (p_header_rec.price_list_id IS NULL OR
5837         p_header_rec.price_list_id <> FND_API.G_MISS_NUM) AND
5838         NOT OE_GLOBALS.Equal(p_header_rec.price_list_id,
5839         p_old_header_rec.price_list_id)
5840     THEN
5841         l_header_val_rec.price_list := OE_Id_To_Value.Price_List
5842         (   p_price_list_id               => p_header_rec.price_list_id
5843         );
5844     END IF;
5845 
5846     IF (p_header_rec.return_reason_code IS NULL OR
5847         p_header_rec.return_reason_code <> FND_API.G_MISS_CHAR) AND
5848         NOT OE_GLOBALS.Equal(p_header_rec.return_reason_code,
5849         p_old_header_rec.return_reason_code)
5850     THEN
5851         l_header_val_rec.return_reason := OE_Id_To_Value.return_reason
5852         (   p_return_reason_code  => p_header_rec.return_reason_code
5853         );
5854     END IF;
5855 
5856     IF (p_header_rec.salesrep_id IS NULL OR
5857         p_header_rec.salesrep_id <> FND_API.G_MISS_NUM) AND
5858         NOT OE_GLOBALS.Equal(p_header_rec.salesrep_id,
5859         p_old_header_rec.salesrep_id)
5860     THEN
5861         l_header_val_rec.salesrep := OE_Id_To_Value.salesrep
5862         (   p_salesrep_id          => p_header_rec.salesrep_id
5863         );
5864     END IF;
5865 
5866     IF (p_header_rec.sales_channel_code IS NULL OR
5867         p_header_rec.sales_channel_code <> FND_API.G_MISS_CHAR) AND
5868         NOT OE_GLOBALS.Equal(p_header_rec.sales_channel_code,
5869         p_old_header_rec.sales_channel_code)
5870     THEN
5871         l_header_val_rec.sales_channel:= OE_Id_To_Value.sales_channel
5872         (   p_sales_channel_code          => p_header_rec.sales_channel_code
5873         );
5874     END IF;
5875 
5876     IF (p_header_rec.shipment_priority_code IS NULL OR
5877         p_header_rec.shipment_priority_code <> FND_API.G_MISS_CHAR) AND
5878         NOT OE_GLOBALS.Equal(p_header_rec.shipment_priority_code,
5879         p_old_header_rec.shipment_priority_code)
5880     THEN
5881         l_header_val_rec.shipment_priority := OE_Id_To_Value.Shipment_Priority
5882         (   p_shipment_priority_code      => p_header_rec.shipment_priority_code
5883         );
5884     END IF;
5885 
5886     IF (p_header_rec.demand_class_code IS NULL OR
5887         p_header_rec.demand_class_code <> FND_API.G_MISS_CHAR) AND
5888         NOT OE_GLOBALS.Equal(p_header_rec.demand_class_code,
5889         p_old_header_rec.demand_class_code)
5890     THEN
5891         l_header_val_rec.Demand_Class := OE_Id_To_Value.Demand_Class
5892         (   p_demand_class_code      => p_header_rec.demand_class_code
5893         );
5894     END IF;
5895 
5896     IF (p_header_rec.ship_from_org_id IS NULL OR
5897         p_header_rec.ship_from_org_id <> FND_API.G_MISS_NUM) AND
5898         NOT OE_GLOBALS.Equal(p_header_rec.ship_from_org_id,
5899         p_old_header_rec.ship_from_org_id)
5900     THEN
5901         OE_Id_To_Value.Ship_From_Org
5902         (   p_ship_from_org_id            => p_header_rec.ship_from_org_id
5903         ,   x_ship_from_address1          => l_header_val_rec.ship_from_address1
5904         ,   x_ship_from_address2          => l_header_val_rec.ship_from_address2
5905         ,   x_ship_from_address3          => l_header_val_rec.ship_from_address3
5906         ,   x_ship_from_address4          => l_header_val_rec.ship_from_address4
5907         ,   x_ship_from_location          => l_header_val_rec.ship_from_location
5908         ,   x_ship_from_org               => l_header_val_rec.ship_from_org
5909         );
5910     END IF;
5911 
5912     IF (p_header_rec.ship_to_contact_id IS NULL OR
5913         p_header_rec.ship_to_contact_id <> FND_API.G_MISS_NUM) AND
5914         NOT OE_GLOBALS.Equal(p_header_rec.ship_to_contact_id,
5915         p_old_header_rec.ship_to_contact_id)
5916     THEN
5917         l_header_val_rec.ship_to_contact := OE_Id_To_Value.Ship_To_Contact
5918         (   p_ship_to_contact_id          => p_header_rec.ship_to_contact_id
5919         );
5920     END IF;
5921 
5922     IF (p_header_rec.ship_to_org_id IS NULL OR
5923         p_header_rec.ship_to_org_id <> FND_API.G_MISS_NUM) AND
5924         NOT OE_GLOBALS.Equal(p_header_rec.ship_to_org_id,
5925         p_old_header_rec.ship_to_org_id)
5926     THEN
5927         get_customer_details
5928         (   p_org_id             => p_header_rec.ship_to_org_id
5929         ,   p_site_use_code      =>'SHIP_TO'
5930         ,   x_customer_name      => l_header_val_rec.ship_to_customer_name
5931         ,   x_customer_number    => l_header_val_rec.ship_to_customer_number
5932         ,   x_customer_id        => l_header_val_rec.ship_to_customer_id
5933         ,   x_location        => l_header_val_rec.ship_to_location
5934         ,   x_address1        => l_header_val_rec.ship_to_address1
5935         ,   x_address2        => l_header_val_rec.ship_to_address2
5936         ,   x_address3        => l_header_val_rec.ship_to_address3
5937         ,   x_address4        => l_header_val_rec.ship_to_address4
5938         ,   x_city        => l_header_val_rec.ship_to_city
5939         ,   x_state        => l_header_val_rec.ship_to_state
5940         ,   x_zip        => l_header_val_rec.ship_to_zip
5941         ,   x_country        => l_header_val_rec.ship_to_country
5942         );
5943         l_header_val_rec.ship_to_org :=l_header_val_rec.ship_to_location;
5944 
5945     END IF;
5946 
5947 
5948     IF (p_header_rec.sold_to_contact_id IS NULL OR
5949         p_header_rec.sold_to_contact_id <> FND_API.G_MISS_NUM) AND
5950         NOT OE_GLOBALS.Equal(p_header_rec.sold_to_contact_id,
5951         p_old_header_rec.sold_to_contact_id)
5952     THEN
5953         l_header_val_rec.sold_to_contact := OE_Id_To_Value.Sold_To_Contact
5954         (   p_sold_to_contact_id          => p_header_rec.sold_to_contact_id
5955         );
5956     END IF;
5957 
5958     IF (p_header_rec.sold_to_org_id IS NULL OR
5959         p_header_rec.sold_to_org_id <> FND_API.G_MISS_NUM) AND
5960         NOT OE_GLOBALS.Equal(p_header_rec.sold_to_org_id,
5961         p_old_header_rec.sold_to_org_id)
5962     THEN
5963         OE_Id_To_Value.Sold_To_Org
5964         (   p_sold_to_org_id              => p_header_rec.sold_to_org_id
5965         ,   x_org                         => l_header_val_rec.sold_to_org
5966         ,   x_customer_number             => l_header_val_rec.customer_number
5967 	--added for Ac. Desc, Registry ID Project
5968 	,   x_account_description	  => l_header_val_rec.account_description
5969 	,   x_registry_id		  => l_header_val_rec.registry_id
5970         );
5971     END IF;
5972 
5973     IF (p_header_rec.tax_exempt_flag IS NULL OR
5974         p_header_rec.tax_exempt_flag <> FND_API.G_MISS_CHAR) AND
5975         NOT OE_GLOBALS.Equal(p_header_rec.tax_exempt_flag,
5976         p_old_header_rec.tax_exempt_flag)
5977     THEN
5978         l_header_val_rec.tax_exempt := OE_Id_To_Value.Tax_Exempt
5979         (   p_tax_exempt_flag             => p_header_rec.tax_exempt_flag
5980         );
5981     END IF;
5982 
5983     IF (p_header_rec.tax_exempt_reason_code IS NULL OR
5984         p_header_rec.tax_exempt_reason_code <> FND_API.G_MISS_CHAR) AND
5985         NOT OE_GLOBALS.Equal(p_header_rec.tax_exempt_reason_code,
5986         p_old_header_rec.tax_exempt_reason_code)
5987     THEN
5988         l_header_val_rec.tax_exempt_reason := OE_Id_To_Value.Tax_Exempt_Reason
5989         (   p_tax_exempt_reason_code      => p_header_rec.tax_exempt_reason_code
5990         );
5991     END IF;
5992 
5993     IF (p_header_rec.tax_point_code IS NULL OR
5994         p_header_rec.tax_point_code <> FND_API.G_MISS_CHAR) AND
5995         NOT OE_GLOBALS.Equal(p_header_rec.tax_point_code,
5996         p_old_header_rec.tax_point_code)
5997     THEN
5998         l_header_val_rec.tax_point := OE_Id_To_Value.Tax_Point
5999         (   p_tax_point_code              => p_header_rec.tax_point_code
6000         );
6001     END IF;
6002 
6003     IF (p_header_rec.payment_type_code IS NULL OR
6004         p_header_rec.payment_type_code <> FND_API.G_MISS_CHAR) AND
6005         NOT OE_GLOBALS.Equal(p_header_rec.payment_type_code,
6006         p_old_header_rec.payment_type_code)
6007     THEN
6008         l_header_val_rec.payment_type := OE_Id_To_Value.Payment_Type
6009         (   p_payment_type_code              => p_header_rec.payment_type_code
6010         );
6011     END IF;
6012     --R12 CC Encryption
6013     IF (p_header_rec.credit_card_code IS NULL OR
6014         p_header_rec.credit_card_code <> FND_API.G_MISS_CHAR) AND
6015         NOT OE_GLOBALS.Equal(p_header_rec.credit_card_code,
6016         p_old_header_rec.credit_card_code)
6017     THEN
6018         l_header_val_rec.credit_card := OE_Id_To_Value.Credit_Card
6019         (   p_credit_card_code              => p_header_rec.credit_card_code
6020         );
6021     END IF;
6022     -- QUOTING changes
6023 
6024    IF (p_header_rec.sold_to_site_use_id IS NULL OR
6025         p_header_rec.sold_to_site_use_id <> FND_API.G_MISS_NUM) AND
6026         NOT OE_GLOBALS.Equal(p_header_rec.sold_to_site_use_id,
6027         p_old_header_rec.sold_to_site_use_id)
6028     THEN
6029 
6030         OE_ID_TO_VALUE.CUSTOMER_LOCATION
6031         (   p_sold_to_site_use_id           => p_header_rec.sold_to_site_use_id
6032         ,   x_sold_to_location_address1     => l_header_val_rec.sold_to_location_address1
6033         ,   x_sold_to_location_address2     => l_header_val_rec.sold_to_location_address2
6034         ,   x_sold_to_location_address3     => l_header_val_rec.sold_to_location_address3
6035         ,   x_sold_to_location_address4     => l_header_val_rec.sold_to_location_address4
6036         ,   x_sold_to_location              => l_header_val_rec.sold_to_location
6037         ,   x_sold_to_location_city         => l_header_val_rec.sold_to_location_city
6038         ,   x_sold_to_location_state        => l_header_val_rec.sold_to_location_state
6039         ,   x_sold_to_location_postal       => l_header_val_rec.sold_to_location_postal
6040         ,   x_sold_to_location_country      => l_header_val_rec.sold_to_location_country
6041         );
6042 
6043     END IF;
6044 
6045     IF (p_header_rec.transaction_phase_code IS NULL OR
6046         p_header_rec.transaction_phase_code <> FND_API.G_MISS_CHAR) AND
6047         NOT OE_GLOBALS.Equal(p_header_rec.transaction_phase_code,
6048         p_old_header_rec.transaction_phase_code)
6049     THEN
6050         l_header_val_rec.transaction_phase := OE_Id_To_Value.Transaction_Phase
6051         (   p_transaction_phase_code    => p_header_rec.transaction_phase_code
6052         );
6053     END IF;
6054 
6055     IF (p_header_rec.user_status_code IS NULL OR
6056         p_header_rec.user_status_code <> FND_API.G_MISS_CHAR) AND
6057         NOT OE_GLOBALS.Equal(p_header_rec.user_status_code,
6058         p_old_header_rec.user_status_code)
6059     THEN
6060         l_header_val_rec.user_status := OE_Id_To_Value.User_Status
6061         (   p_user_status_code          => p_header_rec.user_status_code
6062         );
6063     END IF;
6064 
6065     -- END QUOTING changes
6066 
6067     --distributed orders
6068     IF (p_header_rec.end_customer_id IS NOT NULL  AND
6069         p_header_rec.end_customer_id <> FND_API.G_MISS_NUM)
6070     THEN
6071        OE_ID_TO_VALUE.End_Customer(
6072 				   p_end_customer_id     => p_header_rec.end_customer_id
6073 				   ,x_end_customer_name   => l_header_val_rec.end_customer_name
6074 				   ,x_end_customer_number => l_header_val_rec.end_customer_number);
6075     END IF;
6076 
6077     IF (p_header_rec.end_customer_contact_id IS NOT NULL  AND
6078         p_header_rec.end_customer_contact_id <> FND_API.G_MISS_NUM)
6079     THEN
6080     l_header_val_rec.end_customer_contact :=
6081 	 OE_ID_TO_VALUE.end_customer_Contact(p_end_customer_contact_id => p_header_rec.end_customer_contact_id);
6082     END IF;
6083 
6084     IF (p_header_rec.end_customer_site_use_id IS NOT NULL  AND
6085         p_header_rec.end_customer_site_use_id <> FND_API.G_MISS_NUM)
6086     THEN
6087        OE_ID_TO_VALUE.end_customer_site_use(
6088 					 p_end_customer_site_use_id => p_header_rec.end_customer_site_use_id
6089 					 ,x_end_customer_address1    => l_header_val_rec.end_customer_site_address1
6090 					 ,x_end_customer_address2    => l_header_val_rec.end_customer_site_address2
6091 					 ,x_end_customer_address3    => l_header_val_rec.end_customer_site_address3
6092 					 ,x_end_customer_address4    => l_header_val_rec.end_customer_site_address4
6093 					 ,x_end_customer_location    => l_header_val_rec.end_customer_site_location
6094 					 ,x_end_customer_city        => l_header_val_rec.end_customer_site_city
6095 					 ,x_end_customer_state       => l_header_val_rec.end_customer_site_state
6096 					 ,x_end_customer_postal_code => l_header_val_rec.end_customer_site_postal_code
6097 					 ,x_end_customer_country     => l_header_val_rec.end_customer_site_country    );
6098     END IF;
6099 
6100   -- Start BSA pricing
6101     IF (p_header_rec.blanket_number IS NOT NULL  OR
6102         p_header_rec.blanket_number <> FND_API.G_MISS_NUM)
6103     THEN
6104                 oe_blanket_util_misc.get_blanketAgrName
6105                               (p_blanket_number   => p_header_rec.blanket_number,
6106                                x_blanket_agr_name => l_header_val_rec.blanket_agreement_name);
6107     END if;
6108   -- END BSA pricing
6109 
6110     IF (p_header_rec.ib_owner IS NULL OR
6111         p_header_rec.ib_owner <> FND_API.G_MISS_CHAR) AND
6112         NOT OE_GLOBALS.Equal(p_header_rec.ib_owner,
6113         p_old_header_rec.ib_owner)
6114     THEN
6115         l_header_val_rec.ib_owner_dsp := OE_Id_To_Value.ib_owner
6116         (   p_ib_owner    => p_header_rec.ib_owner
6117         );
6118     END IF;
6119 
6120     IF (p_header_rec.ib_current_location IS NULL OR
6121         p_header_rec.ib_current_location <> FND_API.G_MISS_CHAR) AND
6122         NOT OE_GLOBALS.Equal(p_header_rec.ib_current_location,
6123         p_old_header_rec.ib_current_location)
6124     THEN
6125         l_header_val_rec.ib_current_location_dsp := OE_Id_To_Value.ib_current_location(
6126         p_ib_current_location=>p_header_rec.ib_current_location
6127         );
6128     END IF;
6129 
6130     IF (p_header_rec.ib_installed_at_location IS NULL OR
6131         p_header_rec.ib_installed_at_location <> FND_API.G_MISS_CHAR) AND
6132         NOT OE_GLOBALS.Equal(p_header_rec.ib_installed_at_location,
6133         p_old_header_rec.ib_installed_at_location)
6134     THEN
6135         l_header_val_rec.ib_installed_at_location_dsp := OE_Id_To_Value.ib_installed_at_location(
6136         p_ib_installed_at_location=>p_header_rec.ib_installed_at_location
6137         );
6138     END IF;
6139 
6140 -- FP contracts word integration
6141     IF p_header_rec.order_type_id IS NOT NULL
6142        AND p_header_rec.order_type_id  <> FND_API.G_MISS_NUM
6143        AND OE_Contracts_util.check_license = 'Y'
6144     THEN
6145 
6146 	OE_CONTRACTS_UTIL.GET_CONTRACT_DEFAULTS(
6147        		p_api_version  		=> 1.0,
6148       		p_init_msg_list 	=> FND_API.G_FALSE,
6149   		p_doc_type 		=> 'O',
6150                	p_template_id 		=> p_header_rec.contract_template_id,
6151 	   	x_authoring_party       => l_header_val_rec.authoring_party,
6152    		x_contract_source  	=> l_header_val_rec.contract_source,
6153    		x_template_name   	=> l_header_val_rec.contract_template,
6154                 x_return_status	 	=> l_return_status,
6155                 x_msg_count     	=> l_msg_count,
6156                 x_msg_data      	=> l_msg_data
6157 		);
6158 
6159     END IF;
6160 
6161     oe_debug_pub.add('Exiting OE_HEADER_UTIL.GET_VALUES', 1);
6162 
6163     RETURN l_header_val_rec;
6164 
6165 END Get_Values;
6166 
6167 --  Function Get_Ids
6168 
6169 PROCEDURE Get_Ids
6170 (   p_x_header_rec                  IN OUT NOCOPY OE_Order_PUB.Header_Rec_Type
6171 ,   p_header_val_rec                IN  OE_Order_PUB.Header_Val_Rec_Type
6172 )
6173 IS
6174 l_sold_to_org_id               NUMBER;
6175 l_ship_to_org_id               NUMBER;
6176 l_invoice_to_org_id            NUMBER;
6177 l_deliver_to_org_id            NUMBER;
6178 BEGIN
6179 
6180     oe_debug_pub.add('Entering OE_HEADER_UTIL.GET_IDS', 1);
6181 
6182 
6183     IF  p_header_val_rec.accounting_rule <> FND_API.G_MISS_CHAR
6184     THEN
6185 
6186         IF p_x_header_rec.accounting_rule_id <> FND_API.G_MISS_NUM THEN
6187 
6188 
6189             IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_SUCCESS)
6190             THEN
6191 
6192                 fnd_message.set_name('ONT','OE_BOTH_VAL_AND_ID_EXIST');
6193                 FND_MESSAGE.SET_TOKEN('ATTRIBUTE','accounting_rule');
6194                 OE_MSG_PUB.Add;
6195 
6196             END IF;
6197 
6198         ELSE
6199 
6200             p_x_header_rec.accounting_rule_id := OE_Value_To_Id.accounting_rule
6201             (   p_accounting_rule             => p_header_val_rec.accounting_rule
6202             );
6203 
6204             IF p_x_header_rec.accounting_rule_id = FND_API.G_MISS_NUM THEN
6205                 p_x_header_rec.return_status := FND_API.G_RET_STS_ERROR;
6206             END IF;
6207 
6208         END IF;
6209 
6210     END IF;
6211 
6212     IF  p_header_val_rec.agreement <> FND_API.G_MISS_CHAR
6213     THEN
6214 
6215         IF p_x_header_rec.agreement_id <> FND_API.G_MISS_NUM THEN
6216 
6217 
6218 
6219             IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_SUCCESS)
6220             THEN
6221 
6222                 fnd_message.set_name('ONT','OE_BOTH_VAL_AND_ID_EXIST');
6223                 FND_MESSAGE.SET_TOKEN('ATTRIBUTE','agreement');
6224                 OE_MSG_PUB.Add;
6225 
6226             END IF;
6227 
6228         ELSE
6229 
6230             p_x_header_rec.agreement_id := OE_Value_To_Id.agreement
6231             (   p_agreement                   => p_header_val_rec.agreement
6232             );
6233 
6234             IF p_x_header_rec.agreement_id = FND_API.G_MISS_NUM THEN
6235                 p_x_header_rec.return_status := FND_API.G_RET_STS_ERROR;
6236             END IF;
6237 
6238         END IF;
6239 
6240     END IF;
6241 
6242     IF  p_header_val_rec.conversion_type <> FND_API.G_MISS_CHAR
6243     THEN
6244 
6245         IF p_x_header_rec.conversion_type_code <> FND_API.G_MISS_CHAR THEN
6246 
6247 
6248             IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_SUCCESS)
6249             THEN
6250 
6251                 fnd_message.set_name('ONT','OE_BOTH_VAL_AND_ID_EXIST');
6252                 FND_MESSAGE.SET_TOKEN('ATTRIBUTE','conversion_type');
6253                 OE_MSG_PUB.Add;
6254 
6255             END IF;
6256 
6257         ELSE
6258 
6259             p_x_header_rec.conversion_type_code := OE_Value_To_Id.conversion_type
6260             (   p_conversion_type             => p_header_val_rec.conversion_type
6261             );
6262 
6263             IF p_x_header_rec.conversion_type_code = FND_API.G_MISS_CHAR THEN
6264                 p_x_header_rec.return_status := FND_API.G_RET_STS_ERROR;
6265             END IF;
6266 
6267         END IF;
6268 
6269     END IF;
6270 
6271     IF  p_header_val_rec.fob_point <> FND_API.G_MISS_CHAR
6272     THEN
6273 
6274         IF p_x_header_rec.fob_point_code <> FND_API.G_MISS_CHAR THEN
6275 
6276 
6277             IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_SUCCESS)
6278             THEN
6279 
6280                 fnd_message.set_name('ONT','OE_BOTH_VAL_AND_ID_EXIST');
6281                 FND_MESSAGE.SET_TOKEN('ATTRIBUTE','fob_point');
6282                 OE_MSG_PUB.Add;
6283 
6284             END IF;
6285 
6286         ELSE
6287 
6288             p_x_header_rec.fob_point_code := OE_Value_To_Id.fob_point
6289             (   p_fob_point                   => p_header_val_rec.fob_point
6290             );
6291 
6292             IF p_x_header_rec.fob_point_code = FND_API.G_MISS_CHAR THEN
6293                 p_x_header_rec.return_status := FND_API.G_RET_STS_ERROR;
6294             END IF;
6295 
6296         END IF;
6297 
6298     END IF;
6299 
6300     IF  p_header_val_rec.freight_terms <> FND_API.G_MISS_CHAR
6301     THEN
6302 
6303         IF p_x_header_rec.freight_terms_code <> FND_API.G_MISS_CHAR THEN
6304 
6305 
6306             IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_SUCCESS)
6307             THEN
6308 
6309                 fnd_message.set_name('ONT','OE_BOTH_VAL_AND_ID_EXIST');
6310                 FND_MESSAGE.SET_TOKEN('ATTRIBUTE','freight_terms');
6311                 OE_MSG_PUB.Add;
6312 
6313             END IF;
6314 
6315         ELSE
6316 
6317             p_x_header_rec.freight_terms_code := OE_Value_To_Id.freight_terms
6318             (   p_freight_terms               => p_header_val_rec.freight_terms
6319             );
6320 
6321             IF p_x_header_rec.freight_terms_code = FND_API.G_MISS_CHAR THEN
6322                 p_x_header_rec.return_status := FND_API.G_RET_STS_ERROR;
6323             END IF;
6324 
6325         END IF;
6326 
6327     END IF;
6328     IF  p_header_val_rec.shipping_method <> FND_API.G_MISS_CHAR
6329     THEN
6330 
6331         IF p_x_header_rec.shipping_method_code <> FND_API.G_MISS_CHAR THEN
6332 
6333 
6334             IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_SUCCESS)
6335             THEN
6336 
6337                 fnd_message.set_name('ONT','OE_BOTH_VAL_AND_ID_EXIST');
6338                 FND_MESSAGE.SET_TOKEN('ATTRIBUTE','shipping_method');
6339                 OE_MSG_PUB.Add;
6340 
6341             END IF;
6342 
6343         ELSE
6344 
6345             p_x_header_rec.shipping_method_code := OE_Value_To_Id.ship_method
6346             (   p_ship_method           => p_header_val_rec.shipping_method
6347             );
6348 
6349             IF p_x_header_rec.shipping_method_code = FND_API.G_MISS_CHAR THEN
6350             oe_debug_pub.add('Ship Method Conversion Error');
6351                 p_x_header_rec.return_status := FND_API.G_RET_STS_ERROR;
6352             END IF;
6353 
6354         END IF;
6355 
6356     END IF;
6357 
6358 
6359     IF  p_header_val_rec.freight_carrier <> FND_API.G_MISS_CHAR
6360     THEN
6361 
6362         IF p_x_header_rec.freight_carrier_code <> FND_API.G_MISS_CHAR THEN
6363 
6364 
6365             IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_SUCCESS)
6366             THEN
6367 
6368                 fnd_message.set_name('ONT','OE_BOTH_VAL_AND_ID_EXIST');
6369                 FND_MESSAGE.SET_TOKEN('ATTRIBUTE','freight_carrier');
6370                 OE_MSG_PUB.Add;
6371 
6372             END IF;
6373 
6374         ELSE
6375 
6376             p_x_header_rec.freight_carrier_code := OE_Value_To_Id.freight_carrier
6377             (   p_freight_carrier               => p_header_val_rec.freight_carrier
6378 		  ,   p_ship_from_org_id			   => p_x_header_rec.ship_from_org_id
6379             );
6380 
6381             IF p_x_header_rec.freight_carrier_code = FND_API.G_MISS_CHAR THEN
6382                 p_x_header_rec.return_status := FND_API.G_RET_STS_ERROR;
6383             END IF;
6384 
6385         END IF;
6386 
6387     END IF;
6388 
6389     IF  p_header_val_rec.invoicing_rule <> FND_API.G_MISS_CHAR
6390     THEN
6391 
6392         IF p_x_header_rec.invoicing_rule_id <> FND_API.G_MISS_NUM THEN
6393 
6394 
6395             IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_SUCCESS)
6396             THEN
6397 
6398                 fnd_message.set_name('ONT','OE_BOTH_VAL_AND_ID_EXIST');
6399                 FND_MESSAGE.SET_TOKEN('ATTRIBUTE','invoicing_rule');
6400                 OE_MSG_PUB.Add;
6401 
6402             END IF;
6403 
6404         ELSE
6405 
6406             p_x_header_rec.invoicing_rule_id := OE_Value_To_Id.invoicing_rule
6407             (   p_invoicing_rule              => p_header_val_rec.invoicing_rule
6408             );
6409 
6410             IF p_x_header_rec.invoicing_rule_id = FND_API.G_MISS_NUM THEN
6411                 p_x_header_rec.return_status := FND_API.G_RET_STS_ERROR;
6412             END IF;
6413 
6414         END IF;
6415 
6416     END IF;
6417 
6418     IF  p_header_val_rec.order_source <> FND_API.G_MISS_CHAR
6419     THEN
6420 
6421         IF p_x_header_rec.order_source_id <> FND_API.G_MISS_NUM THEN
6422 
6423 
6424             IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_SUCCESS)
6425             THEN
6426 
6427                 fnd_message.set_name('ONT','OE_BOTH_VAL_AND_ID_EXIST');
6428                 FND_MESSAGE.SET_TOKEN('ATTRIBUTE','order_source');
6429                 OE_MSG_PUB.Add;
6430 
6431             END IF;
6432 
6433         ELSE
6434 
6435             p_x_header_rec.order_source_id := OE_Value_To_Id.order_source
6436             (   p_order_source                => p_header_val_rec.order_source
6437             );
6438 
6439             IF p_x_header_rec.order_source_id = FND_API.G_MISS_NUM THEN
6440                 p_x_header_rec.return_status := FND_API.G_RET_STS_ERROR;
6441             END IF;
6442 
6443         END IF;
6444 
6445     END IF;
6446 
6447     IF  p_header_val_rec.order_type <> FND_API.G_MISS_CHAR
6448     THEN
6449 
6450         IF p_x_header_rec.order_type_id <> FND_API.G_MISS_NUM THEN
6451 
6452 
6453             IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_SUCCESS)
6454             THEN
6455 
6456                 fnd_message.set_name('ONT','OE_BOTH_VAL_AND_ID_EXIST');
6457                 FND_MESSAGE.SET_TOKEN('ATTRIBUTE','order_type');
6458                 OE_MSG_PUB.Add;
6459 
6460             END IF;
6461 
6462         ELSE
6463 
6464             p_x_header_rec.order_type_id := OE_Value_To_Id.order_type
6465             (   p_order_type                  => p_header_val_rec.order_type
6466             );
6467 
6468             IF p_x_header_rec.order_type_id = FND_API.G_MISS_NUM THEN
6469                 p_x_header_rec.return_status := FND_API.G_RET_STS_ERROR;
6470             END IF;
6471 
6472         END IF;
6473 
6474     END IF;
6475 
6476     IF  p_header_val_rec.payment_term <> FND_API.G_MISS_CHAR
6477     THEN
6478 
6479         IF p_x_header_rec.payment_term_id <> FND_API.G_MISS_NUM THEN
6480 
6481 
6482             IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_SUCCESS)
6483             THEN
6484 
6485                 fnd_message.set_name('ONT','OE_BOTH_VAL_AND_ID_EXIST');
6486                 FND_MESSAGE.SET_TOKEN('ATTRIBUTE','payment_term');
6487                 OE_MSG_PUB.Add;
6488 
6489             END IF;
6490 
6491         ELSE
6492 
6493             p_x_header_rec.payment_term_id := OE_Value_To_Id.payment_term
6494             (   p_payment_term                => p_header_val_rec.payment_term
6495             );
6496 
6497             IF p_x_header_rec.payment_term_id = FND_API.G_MISS_NUM THEN
6498                 p_x_header_rec.return_status := FND_API.G_RET_STS_ERROR;
6499             END IF;
6500 
6501         END IF;
6502 
6503     END IF;
6504 
6505     IF  p_header_val_rec.price_list <> FND_API.G_MISS_CHAR
6506     THEN
6507 
6508         IF p_x_header_rec.price_list_id <> FND_API.G_MISS_NUM THEN
6509 
6510 
6511             IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_SUCCESS)
6512             THEN
6513 
6514                 fnd_message.set_name('ONT','OE_BOTH_VAL_AND_ID_EXIST');
6515                 FND_MESSAGE.SET_TOKEN('ATTRIBUTE','price_list');
6516                 OE_MSG_PUB.Add;
6517 
6518             END IF;
6519 
6520         ELSE
6521 
6522             p_x_header_rec.price_list_id := OE_Value_To_Id.price_list
6523             (   p_price_list                  => p_header_val_rec.price_list
6524             );
6525 
6526             IF p_x_header_rec.price_list_id = FND_API.G_MISS_NUM THEN
6527                 p_x_header_rec.return_status := FND_API.G_RET_STS_ERROR;
6528             END IF;
6529 
6530         END IF;
6531 
6532     END IF;
6533 
6534     IF  p_header_val_rec.return_reason <> FND_API.G_MISS_CHAR
6535     THEN
6536 
6537         IF p_x_header_rec.return_reason_code <> FND_API.G_MISS_CHAR THEN
6538 
6539 
6540             IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_SUCCESS)
6541             THEN
6542 
6543                 fnd_message.set_name('ONT','OE_BOTH_VAL_AND_ID_EXIST');
6544                 FND_MESSAGE.SET_TOKEN('ATTRIBUTE','return_reason');
6545                 OE_MSG_PUB.Add;
6546 
6547             END IF;
6548 
6549         ELSE
6550 
6551             p_x_header_rec.return_reason_code := OE_Value_To_Id.return_reason
6552             (   p_return_reason  => p_header_val_rec.return_reason
6553             );
6554 
6555 	 IF p_x_header_rec.return_reason_code = FND_API.G_MISS_CHAR THEN
6556                 p_x_header_rec.return_status := FND_API.G_RET_STS_ERROR;
6557             END IF;
6558 
6559         END IF;
6560 
6561     END IF;
6562 
6563     IF  p_header_val_rec.salesrep <> FND_API.G_MISS_CHAR
6564     THEN
6565 
6566         IF p_x_header_rec.salesrep_id <> FND_API.G_MISS_NUM THEN
6567 
6568 
6569             IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_SUCCESS)
6570             THEN
6571 
6572                 fnd_message.set_name('ONT','OE_BOTH_VAL_AND_ID_EXIST');
6573                 FND_MESSAGE.SET_TOKEN('ATTRIBUTE','salesrep');
6574                 OE_MSG_PUB.Add;
6575 
6576             END IF;
6577 
6578         ELSE
6579 
6580             p_x_header_rec.salesrep_id := OE_Value_To_Id.salesrep
6581             (   p_salesrep  => p_header_val_rec.salesrep
6582             );
6583             IF p_x_header_rec.salesrep_id = FND_API.G_MISS_NUM THEN
6584                 p_x_header_rec.return_status := FND_API.G_RET_STS_ERROR;
6585             END IF;
6586 
6587         END IF;
6588 
6589     END IF;
6590 
6591 
6592     IF  p_header_val_rec.sales_channel <> FND_API.G_MISS_CHAR
6593     THEN
6594 
6595         IF p_x_header_rec.sales_channel_code <> FND_API.G_MISS_CHAR THEN
6596 
6597 
6598             IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_SUCCESS)
6599             THEN
6600 
6601                 fnd_message.set_name('ONT','OE_BOTH_VAL_AND_ID_EXIST');
6602                 FND_MESSAGE.SET_TOKEN('ATTRIBUTE','sales_channel');
6603                 OE_MSG_PUB.Add;
6604 
6605             END IF;
6606 
6607         ELSE
6608 
6609             p_x_header_rec.sales_channel_code := OE_Value_To_Id.sales_channel
6610             (   p_sales_channel  => p_header_val_rec.sales_channel
6611             );
6612             IF p_x_header_rec.sales_channel_code = FND_API.G_MISS_CHAR THEN
6613                 p_x_header_rec.return_status := FND_API.G_RET_STS_ERROR;
6614             END IF;
6615 
6616         END IF;
6617 
6618     END IF;
6619 
6620 
6621     IF  p_header_val_rec.shipment_priority <> FND_API.G_MISS_CHAR
6622     THEN
6623 
6624         IF p_x_header_rec.shipment_priority_code <> FND_API.G_MISS_CHAR THEN
6625 
6626 
6627             IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_SUCCESS)
6628             THEN
6629 
6630                 fnd_message.set_name('ONT','OE_BOTH_VAL_AND_ID_EXIST');
6631                 FND_MESSAGE.SET_TOKEN('ATTRIBUTE','shipment_priority');
6632                 OE_MSG_PUB.Add;
6633 
6634             END IF;
6635 
6636         ELSE
6637 
6638             p_x_header_rec.shipment_priority_code := OE_Value_To_Id.shipment_priority
6639             (   p_shipment_priority           => p_header_val_rec.shipment_priority
6640             );
6641 
6642             IF p_x_header_rec.shipment_priority_code = FND_API.G_MISS_CHAR THEN
6643                 p_x_header_rec.return_status := FND_API.G_RET_STS_ERROR;
6644             END IF;
6645 
6646         END IF;
6647 
6648     END IF;
6649 
6650     IF  p_header_val_rec.ship_from_address1 <> FND_API.G_MISS_CHAR
6651     OR p_header_val_rec.ship_from_address2 <> FND_API.G_MISS_CHAR
6652     OR p_header_val_rec.ship_from_address3 <> FND_API.G_MISS_CHAR
6653     OR p_header_val_rec.ship_from_address4 <> FND_API.G_MISS_CHAR
6654     OR p_header_val_rec.ship_from_location <> FND_API.G_MISS_CHAR
6655     OR p_header_val_rec.ship_from_org <> FND_API.G_MISS_CHAR
6656     THEN
6657 
6658         IF p_x_header_rec.ship_from_org_id <> FND_API.G_MISS_NUM THEN
6659 
6660 
6661             IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_SUCCESS)
6662             THEN
6663 
6664                 fnd_message.set_name('ONT','OE_BOTH_VAL_AND_ID_EXIST');
6665                 FND_MESSAGE.SET_TOKEN('ATTRIBUTE','ship_from_org');
6666                 OE_MSG_PUB.Add;
6667 
6668             END IF;
6669 
6670         ELSE
6671 
6672             p_x_header_rec.ship_from_org_id := OE_Value_To_Id.ship_from_org
6673             (   p_ship_from_address1          => p_header_val_rec.ship_from_address1
6674             ,   p_ship_from_address2          => p_header_val_rec.ship_from_address2
6675             ,   p_ship_from_address3          => p_header_val_rec.ship_from_address3
6676             ,   p_ship_from_address4          => p_header_val_rec.ship_from_address4
6677             ,   p_ship_from_location          => p_header_val_rec.ship_from_location
6678             ,   p_ship_from_org               => p_header_val_rec.ship_from_org
6679             );
6680 
6681             IF p_x_header_rec.ship_from_org_id = FND_API.G_MISS_NUM THEN
6682                 p_x_header_rec.return_status := FND_API.G_RET_STS_ERROR;
6683             END IF;
6684 
6685         END IF;
6686 
6687     END IF;
6688 
6689     IF  p_header_val_rec.tax_exempt <> FND_API.G_MISS_CHAR
6690     THEN
6691 
6692         IF p_x_header_rec.tax_exempt_flag <> FND_API.G_MISS_CHAR THEN
6693 
6694 
6695             IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_SUCCESS)
6696             THEN
6697 
6698                 fnd_message.set_name('ONT','OE_BOTH_VAL_AND_ID_EXIST');
6699                 FND_MESSAGE.SET_TOKEN('ATTRIBUTE','tax_exempt');
6700                 OE_MSG_PUB.Add;
6701 
6702             END IF;
6703 
6704         ELSE
6705 
6706             p_x_header_rec.tax_exempt_flag := OE_Value_To_Id.tax_exempt
6707             (   p_tax_exempt                  => p_header_val_rec.tax_exempt
6708             );
6709 
6710             IF p_x_header_rec.tax_exempt_flag = FND_API.G_MISS_CHAR THEN
6711                 p_x_header_rec.return_status := FND_API.G_RET_STS_ERROR;
6712             END IF;
6713 
6714         END IF;
6715 
6716     END IF;
6717 
6718     IF  p_header_val_rec.tax_exempt_reason <> FND_API.G_MISS_CHAR
6719     THEN
6720 
6721         IF p_x_header_rec.tax_exempt_reason_code <> FND_API.G_MISS_CHAR THEN
6722 
6723 
6724             IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_SUCCESS)
6725             THEN
6726 
6727                 fnd_message.set_name('ONT','OE_BOTH_VAL_AND_ID_EXIST');
6728                 FND_MESSAGE.SET_TOKEN('ATTRIBUTE','tax_exempt_reason');
6729                 OE_MSG_PUB.Add;
6730 
6731             END IF;
6732 
6733         ELSE
6734 
6735             p_x_header_rec.tax_exempt_reason_code := OE_Value_To_Id.tax_exempt_reason
6736             (   p_tax_exempt_reason           => p_header_val_rec.tax_exempt_reason
6737             );
6738 
6739             IF p_x_header_rec.tax_exempt_reason_code = FND_API.G_MISS_CHAR THEN
6740                 p_x_header_rec.return_status := FND_API.G_RET_STS_ERROR;
6741             END IF;
6742 
6743         END IF;
6744 
6745     END IF;
6746 
6747     IF  p_header_val_rec.tax_point <> FND_API.G_MISS_CHAR
6748     THEN
6749 
6750         IF p_x_header_rec.tax_point_code <> FND_API.G_MISS_CHAR THEN
6751 
6752 
6753             IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_SUCCESS)
6754             THEN
6755 
6756                 fnd_message.set_name('ONT','OE_BOTH_VAL_AND_ID_EXIST');
6757                 FND_MESSAGE.SET_TOKEN('ATTRIBUTE','tax_point');
6758                 OE_MSG_PUB.Add;
6759 
6760             END IF;
6761 
6762         ELSE
6763 
6764             p_x_header_rec.tax_point_code := OE_Value_To_Id.tax_point
6765             (   p_tax_point                   => p_header_val_rec.tax_point
6766             );
6767 
6768             IF p_x_header_rec.tax_point_code = FND_API.G_MISS_CHAR THEN
6769                 p_x_header_rec.return_status := FND_API.G_RET_STS_ERROR;
6770             END IF;
6771 
6772         END IF;
6773 
6774     END IF;
6775 
6776     IF  p_header_val_rec.payment_type <> FND_API.G_MISS_CHAR
6777     THEN
6778 
6779         IF p_x_header_rec.payment_type_code <> FND_API.G_MISS_CHAR THEN
6780 
6781 
6782             IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_SUCCESS)
6783             THEN
6784 
6785                 fnd_message.set_name('ONT','OE_BOTH_VAL_AND_ID_EXIST');
6786                 FND_MESSAGE.SET_TOKEN('ATTRIBUTE','payment_type');
6787                 OE_MSG_PUB.Add;
6788 
6789             END IF;
6790 
6791         ELSE
6792 
6793             p_x_header_rec.payment_type_code := OE_Value_To_Id.payment_type
6794             (   p_payment_type                   => p_header_val_rec.payment_type
6795             );
6796 
6797             IF p_x_header_rec.payment_type_code = FND_API.G_MISS_CHAR THEN
6798                 p_x_header_rec.return_status := FND_API.G_RET_STS_ERROR;
6799             END IF;
6800 
6801         END IF;
6802 
6803     END IF;
6804 
6805     IF  p_header_val_rec.credit_card <> FND_API.G_MISS_CHAR
6806     THEN
6807 
6808         IF p_x_header_rec.credit_card_code <> FND_API.G_MISS_CHAR THEN
6809 
6810 
6811             IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_SUCCESS)
6812             THEN
6813 
6814                 fnd_message.set_name('ONT','OE_BOTH_VAL_AND_ID_EXIST');
6815                 FND_MESSAGE.SET_TOKEN('ATTRIBUTE','credit_card');
6816                 OE_MSG_PUB.Add;
6817 
6818             END IF;
6819 
6820         ELSE
6821 
6822             p_x_header_rec.credit_card_code := OE_Value_To_Id.credit_card
6823             (   p_credit_card                   => p_header_val_rec.credit_card
6824             );
6825 
6826             IF p_x_header_rec.credit_card_code = FND_API.G_MISS_CHAR THEN
6827                 p_x_header_rec.return_status := FND_API.G_RET_STS_ERROR;
6828             END IF;
6829 
6830         END IF;
6831 
6832     END IF;
6833 
6834 
6835     ----------------------------------------------------------------------
6836     -- Retreiving ids for invoice_to_customer
6837     ----------------------------------------------------------------------
6838 
6839     oe_debug_pub.add('hdr Invoice_to_cust_id='||p_x_header_rec.invoice_to_customer_id);
6840     IF  p_header_val_rec.invoice_to_customer_name_oi <> FND_API.G_MISS_CHAR
6841     OR  p_header_val_rec.invoice_to_customer_number_oi <> FND_API.G_MISS_CHAR
6842     THEN
6843 
6844         IF p_x_header_rec.invoice_to_customer_id <> FND_API.G_MISS_NUM THEN
6845 
6846 
6847             IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_SUCCESS)
6848             THEN
6849 
6850                 fnd_message.set_name('ONT','OE_BOTH_VAL_AND_ID_EXIST');
6851                 FND_MESSAGE.SET_TOKEN('ATTRIBUTE','invoice_to_customer');
6852                 OE_MSG_PUB.Add;
6853 
6854             END IF;
6855 
6856         ELSE
6857            IF p_x_header_rec.invoice_to_org_id = FND_API.G_MISS_NUM then -- 4231603
6858             p_x_header_rec.invoice_to_customer_id:=OE_Value_To_Id.site_customer
6859             ( p_site_customer       => p_header_val_rec.invoice_to_customer_name_oi
6860              ,p_site_customer_number=> p_header_val_rec.invoice_to_customer_number_oi
6861              ,p_type =>'INVOICE_TO'
6862             );
6863 
6864             IF p_x_header_rec.invoice_to_customer_id = FND_API.G_MISS_NUM THEN
6865                 p_x_header_rec.return_status := FND_API.G_RET_STS_ERROR;
6866             END IF;
6867            END IF;
6868         END IF;
6869 
6870     END IF;
6871 
6872     ----------------------------------------------------------------------
6873     -- Retreiving ids for ship_to_customer
6874     ----------------------------------------------------------------------
6875 
6876     IF  p_header_val_rec.ship_to_customer_name_oi <> FND_API.G_MISS_CHAR
6877     OR  p_header_val_rec.ship_to_customer_number_oi <> FND_API.G_MISS_CHAR
6878     THEN
6879 
6880         IF p_x_header_rec.ship_to_customer_id <> FND_API.G_MISS_NUM THEN
6881 
6882 
6883             IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_SUCCESS)
6884             THEN
6885 
6886                 fnd_message.set_name('ONT','OE_BOTH_VAL_AND_ID_EXIST');
6887                 FND_MESSAGE.SET_TOKEN('ATTRIBUTE','ship_to_customer');
6888                 OE_MSG_PUB.Add;
6889 
6890             END IF;
6891 
6892         ELSE
6893             IF p_x_header_rec.ship_to_org_id = FND_API.G_MISS_NUM then  -- 4231603
6894             p_x_header_rec.ship_to_customer_id:=OE_Value_To_Id.site_customer
6895             ( p_site_customer       => p_header_val_rec.ship_to_customer_name_oi
6896              ,p_site_customer_number=> p_header_val_rec.ship_to_customer_number_oi
6897              ,p_type =>'SHIP_TO'
6898             );
6899 
6900             IF p_x_header_rec.ship_to_customer_id = FND_API.G_MISS_NUM THEN
6901                 p_x_header_rec.return_status := FND_API.G_RET_STS_ERROR;
6902             END IF;
6903            END IF;
6904         END IF;
6905 
6906     END IF;
6907 
6908 
6909     ----------------------------------------------------------------------
6910     -- Retreiving ids for deliver_to_customer
6911     ----------------------------------------------------------------------
6912 
6913     IF  p_header_val_rec.deliver_to_customer_name_oi <> FND_API.G_MISS_CHAR
6914     OR  p_header_val_rec.deliver_to_customer_number_oi <> FND_API.G_MISS_CHAR
6915     THEN
6916 
6917         IF p_x_header_rec.deliver_to_customer_id <> FND_API.G_MISS_NUM THEN
6918 
6919 
6920             IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_SUCCESS)
6921             THEN
6922 
6923                 fnd_message.set_name('ONT','OE_BOTH_VAL_AND_ID_EXIST');
6924                 FND_MESSAGE.SET_TOKEN('ATTRIBUTE','deliver_to_customer');
6925                 OE_MSG_PUB.Add;
6926 
6927             END IF;
6928 
6929         ELSE
6930            IF p_x_header_rec.deliver_to_org_id = FND_API.G_MISS_NUM then  -- 4231603
6931             p_x_header_rec.deliver_to_customer_id:=OE_Value_To_Id.site_customer
6932             ( p_site_customer       => p_header_val_rec.ship_to_customer_name_oi
6933              ,p_site_customer_number=> p_header_val_rec.ship_to_customer_number_oi
6934              ,p_type =>'DELIVER_TO'
6935             );
6936 
6937             IF p_x_header_rec.deliver_to_customer_id = FND_API.G_MISS_NUM THEN
6938                 p_x_header_rec.return_status := FND_API.G_RET_STS_ERROR;
6939             END IF;
6940            END IF;
6941         END IF;
6942 
6943     END IF;
6944 
6945     ----------------------------------------------------------------------
6946     -- For customer related fields, IDs should be retrieved in the
6947     -- following order.
6948     ----------------------------------------------------------------------
6949 
6950     IF  p_header_val_rec.sold_to_org <> FND_API.G_MISS_CHAR
6951     OR  p_header_val_rec.customer_number <> FND_API.G_MISS_CHAR
6952     THEN
6953 
6954         IF p_x_header_rec.sold_to_org_id <> FND_API.G_MISS_NUM THEN
6955 
6956 
6957             IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_SUCCESS)
6958             THEN
6959 
6960                 fnd_message.set_name('ONT','OE_BOTH_VAL_AND_ID_EXIST');
6961                 FND_MESSAGE.SET_TOKEN('ATTRIBUTE','sold_to_org');
6962                 OE_MSG_PUB.Add;
6963 
6964             END IF;
6965 
6966         ELSE
6967 
6968             p_x_header_rec.sold_to_org_id := OE_Value_To_Id.sold_to_org
6969             (   p_sold_to_org                 => p_header_val_rec.sold_to_org
6970 		  ,   p_customer_number             => p_header_val_rec.customer_number
6971             );
6972 
6973             IF p_x_header_rec.sold_to_org_id = FND_API.G_MISS_NUM THEN
6974                 p_x_header_rec.return_status := FND_API.G_RET_STS_ERROR;
6975             END IF;
6976 
6977         END IF;
6978 
6979     END IF;
6980 
6981     -- Retrieve the sold_to_org_id if not passed on the header record. This
6982     -- will be needed by the value_to_id functions for related fields.
6983     -- For e.g. oe_value_to_id.ship_to_org_id requires sold_to_org_id
6984 
6985     IF p_x_header_rec.operation = OE_GLOBALS.G_OPR_UPDATE
6986 	  AND  p_x_header_rec.sold_to_org_id = FND_API.G_MISS_NUM
6987     THEN
6988 
6989 	  SELECT SOLD_TO_ORG_ID
6990 	  INTO l_sold_to_org_id
6991 	  FROM OE_ORDER_HEADERS
6992 	  WHERE HEADER_ID = p_x_header_rec.header_id;
6993 
6994     ELSE
6995 
6996 	  l_sold_to_org_id := p_x_header_rec.sold_to_org_id;
6997 
6998     END IF;
6999 
7000     IF  p_header_val_rec.sold_to_contact <> FND_API.G_MISS_CHAR
7001     THEN
7002 
7003         IF p_x_header_rec.sold_to_contact_id <> FND_API.G_MISS_NUM THEN
7004 
7005 
7006             IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_SUCCESS)
7007             THEN
7008 
7009                 fnd_message.set_name('ONT','OE_BOTH_VAL_AND_ID_EXIST');
7010                 FND_MESSAGE.SET_TOKEN('ATTRIBUTE','sold_to_contact');
7011                 OE_MSG_PUB.Add;
7012 
7013             END IF;
7014 
7015         ELSE
7016 
7017             p_x_header_rec.sold_to_contact_id := OE_Value_To_Id.sold_to_contact
7018             (   p_sold_to_contact             => p_header_val_rec.sold_to_contact
7019 		  ,   p_sold_to_org_id              => l_sold_to_org_id
7020             );
7021 
7022             IF p_x_header_rec.sold_to_contact_id = FND_API.G_MISS_NUM THEN
7023                 p_x_header_rec.return_status := FND_API.G_RET_STS_ERROR;
7024             END IF;
7025 
7026         END IF;
7027 
7028     END IF;
7029 
7030     IF  p_header_val_rec.deliver_to_address1 <> FND_API.G_MISS_CHAR
7031     OR p_header_val_rec.deliver_to_address2 <> FND_API.G_MISS_CHAR
7032     OR p_header_val_rec.deliver_to_address3 <> FND_API.G_MISS_CHAR
7033     OR p_header_val_rec.deliver_to_address4 <> FND_API.G_MISS_CHAR
7034     OR p_header_val_rec.deliver_to_location <> FND_API.G_MISS_CHAR
7035     OR p_header_val_rec.deliver_to_org <> FND_API.G_MISS_CHAR
7036     THEN
7037 
7038         IF p_x_header_rec.deliver_to_org_id <> FND_API.G_MISS_NUM THEN
7039 
7040 
7041             IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_SUCCESS)
7042             THEN
7043 
7044                 fnd_message.set_name('ONT','OE_BOTH_VAL_AND_ID_EXIST');
7045                 FND_MESSAGE.SET_TOKEN('ATTRIBUTE','deliver_to_org');
7046                 OE_MSG_PUB.Add;
7047 
7048             END IF;
7049 
7050         ELSE
7051 /*1621182*/
7052             p_x_header_rec.deliver_to_org_id := OE_Value_To_Id.deliver_to_org
7053             (   p_deliver_to_address1         => p_header_val_rec.deliver_to_address1
7054             ,   p_deliver_to_address2         => p_header_val_rec.deliver_to_address2
7055             ,   p_deliver_to_address3         => p_header_val_rec.deliver_to_address3
7056             ,   p_deliver_to_address4         => p_header_val_rec.deliver_to_address4
7057             ,   p_deliver_to_location         => p_header_val_rec.deliver_to_location
7058             ,   p_deliver_to_org              => p_header_val_rec.deliver_to_org
7059             ,   p_deliver_to_city             => p_header_val_rec.deliver_to_city
7060             ,   p_deliver_to_state            => p_header_val_rec.deliver_to_state
7061             ,   p_deliver_to_postal_code      => p_header_val_rec.deliver_to_zip
7062             ,   p_deliver_to_country          => p_header_val_rec.deliver_to_country
7063 		  ,   p_sold_to_org_id        => l_sold_to_org_id
7064             , p_deliver_to_customer_id => p_x_header_rec.deliver_to_customer_id
7065             );
7066 /*1621182*/
7067 
7068             IF p_x_header_rec.deliver_to_org_id = FND_API.G_MISS_NUM THEN
7069                 p_x_header_rec.return_status := FND_API.G_RET_STS_ERROR;
7070             END IF;
7071 
7072         END IF;
7073 
7074     END IF;
7075 
7076     IF  p_header_val_rec.invoice_to_address1 <> FND_API.G_MISS_CHAR
7077     OR p_header_val_rec.invoice_to_address2 <> FND_API.G_MISS_CHAR
7078     OR p_header_val_rec.invoice_to_address3 <> FND_API.G_MISS_CHAR
7079     OR p_header_val_rec.invoice_to_address4 <> FND_API.G_MISS_CHAR
7080     OR p_header_val_rec.invoice_to_location <> FND_API.G_MISS_CHAR
7081     OR p_header_val_rec.invoice_to_org <> FND_API.G_MISS_CHAR
7082     THEN
7083 
7084         IF p_x_header_rec.invoice_to_org_id <> FND_API.G_MISS_NUM THEN
7085 
7086 
7087             IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_SUCCESS)
7088             THEN
7089 
7090                 fnd_message.set_name('ONT','OE_BOTH_VAL_AND_ID_EXIST');
7091                 FND_MESSAGE.SET_TOKEN('ATTRIBUTE','invoice_to_org');
7092                 OE_MSG_PUB.Add;
7093 
7094             END IF;
7095 
7096         ELSE
7097 /*1621182*/
7098             p_x_header_rec.invoice_to_org_id := OE_Value_To_Id.invoice_to_org
7099             (   p_invoice_to_address1         => p_header_val_rec.invoice_to_address1
7100             ,   p_invoice_to_address2         => p_header_val_rec.invoice_to_address2
7101             ,   p_invoice_to_address3         => p_header_val_rec.invoice_to_address3
7102             ,   p_invoice_to_address4         => p_header_val_rec.invoice_to_address4
7103             ,   p_invoice_to_location         => p_header_val_rec.invoice_to_location
7104             ,   p_invoice_to_org              => p_header_val_rec.invoice_to_org
7105             ,   p_invoice_to_city             => p_header_val_rec.invoice_to_city
7106             ,   p_invoice_to_state            => p_header_val_rec.invoice_to_state
7107             ,   p_invoice_to_postal_code      => p_header_val_rec.invoice_to_zip
7108             ,   p_invoice_to_country          => p_header_val_rec.invoice_to_country
7109 		  ,   p_sold_to_org_id        => l_sold_to_org_id
7110             , p_invoice_to_customer_id => p_x_header_rec.invoice_to_customer_id
7111             );
7112 /*1621182*/
7113 
7114             IF p_x_header_rec.invoice_to_org_id = FND_API.G_MISS_NUM THEN
7115                 p_x_header_rec.return_status := FND_API.G_RET_STS_ERROR;
7116             END IF;
7117 
7118         END IF;
7119 
7120     END IF;
7121 
7122     IF  p_header_val_rec.ship_to_address1 <> FND_API.G_MISS_CHAR
7123     OR p_header_val_rec.ship_to_address2 <> FND_API.G_MISS_CHAR
7124     OR p_header_val_rec.ship_to_address3 <> FND_API.G_MISS_CHAR
7125     OR p_header_val_rec.ship_to_address4 <> FND_API.G_MISS_CHAR
7126     OR p_header_val_rec.ship_to_location <> FND_API.G_MISS_CHAR
7127     OR p_header_val_rec.ship_to_org <> FND_API.G_MISS_CHAR
7128     THEN
7129 
7130         IF p_x_header_rec.ship_to_org_id <> FND_API.G_MISS_NUM THEN
7131 
7132 
7133             IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_SUCCESS)
7134             THEN
7135 
7136                 fnd_message.set_name('ONT','OE_BOTH_VAL_AND_ID_EXIST');
7137                 FND_MESSAGE.SET_TOKEN('ATTRIBUTE','ship_to_org');
7138                 OE_MSG_PUB.Add;
7139 
7140             END IF;
7141 
7142         ELSE
7143 /*1621182*/
7144             p_x_header_rec.ship_to_org_id := OE_Value_To_Id.ship_to_org
7145             (   p_ship_to_address1            => p_header_val_rec.ship_to_address1
7146             ,   p_ship_to_address2            => p_header_val_rec.ship_to_address2
7147             ,   p_ship_to_address3            => p_header_val_rec.ship_to_address3
7148             ,   p_ship_to_address4            => p_header_val_rec.ship_to_address4
7149             ,   p_ship_to_location            => p_header_val_rec.ship_to_location
7150             ,   p_ship_to_city                => p_header_val_rec.ship_to_city
7151             ,   p_ship_to_state               => p_header_val_rec.ship_to_state
7152             ,   p_ship_to_postal_code         => p_header_val_rec.ship_to_zip
7153             ,   p_ship_to_country             => p_header_val_rec.ship_to_country
7154             ,   p_ship_to_org                 => p_header_val_rec.ship_to_org
7155 		  ,   p_sold_to_org_id        => l_sold_to_org_id
7156             , p_ship_to_customer_id => p_x_header_rec.ship_to_customer_id
7157             );
7158 /*1621182*/
7159 
7160             IF p_x_header_rec.ship_to_org_id = FND_API.G_MISS_NUM THEN
7161                 p_x_header_rec.return_status := FND_API.G_RET_STS_ERROR;
7162             END IF;
7163 
7164         END IF;
7165 
7166     END IF;
7167 
7168 -- QUOTING changes
7169     IF  p_header_val_rec.sold_to_location_address1 <> FND_API.G_MISS_CHAR
7170     OR p_header_val_rec.sold_to_location_address2 <> FND_API.G_MISS_CHAR
7171     OR p_header_val_rec.sold_to_location_address3 <> FND_API.G_MISS_CHAR
7172     OR p_header_val_rec.sold_to_location_address4 <> FND_API.G_MISS_CHAR
7173     OR p_header_val_rec.sold_to_location          <> FND_API.G_MISS_CHAR
7174     OR p_header_val_rec.sold_to_location <> FND_API.G_MISS_CHAR
7175     THEN
7176 
7177         IF p_x_header_rec.sold_to_site_use_id <> FND_API.G_MISS_NUM THEN
7178 
7179 
7180             IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_SUCCESS)
7181             THEN
7182 
7183                 fnd_message.set_name('ONT','OE_BOTH_VAL_AND_ID_EXIST');
7184                 FND_MESSAGE.SET_TOKEN('ATTRIBUTE','Customer_Location');
7185                 OE_MSG_PUB.Add;
7186 
7187             END IF;
7188 
7189         ELSE
7190             p_x_header_rec.sold_to_site_use_id := OE_Value_To_Id.Customer_Location
7191             (   p_sold_to_location_address1            => p_header_val_rec.sold_to_location_address1
7192             ,   p_sold_to_location_address2            => p_header_val_rec.sold_to_location_address2
7193             ,   p_sold_to_location_address3            => p_header_val_rec.sold_to_location_address3
7194             ,   p_sold_to_location_address4            => p_header_val_rec.sold_to_location_address4
7195             ,   p_sold_to_location                     => p_header_val_rec.sold_to_location
7196 	    ,   p_sold_to_org_id                       => l_sold_to_org_id
7197             ,   p_sold_to_location_city                => p_header_val_rec.sold_to_location_city
7198             ,   p_sold_to_location_state               => p_header_val_rec.sold_to_location_state
7199             ,   p_sold_to_location_postal_code         => p_header_val_rec.sold_to_location_postal
7200             ,   p_sold_to_location_country             => p_header_val_rec.sold_to_location_country
7201             );
7202 
7203 
7204     oe_debug_pub.add('after hdr sold_to_site_use_id='||p_x_header_rec.sold_to_site_use_id);
7205 
7206             IF p_x_header_rec.sold_to_site_use_id = FND_API.G_MISS_NUM THEN
7207                 p_x_header_rec.return_status := FND_API.G_RET_STS_ERROR;
7208             END IF;
7209 
7210         END IF;
7211 
7212     END IF;
7213 -- QUOTING changes
7214 
7215     -- Retrieve the org_ids if not passed on the header record. These
7216     -- IDs will be needed by the value_to_id functions for CONTACT fields.
7217     -- For e.g. oe_value_to_id.ship_to_contact_id requires ship_to_org_id
7218 
7219     IF p_x_header_rec.operation = OE_GLOBALS.G_OPR_UPDATE
7220 	  AND (  p_x_header_rec.ship_to_org_id = FND_API.G_MISS_NUM
7221 	       OR p_x_header_rec.invoice_to_org_id = FND_API.G_MISS_NUM
7222 	       OR p_x_header_rec.deliver_to_org_id = FND_API.G_MISS_NUM )
7223     THEN
7224 
7225 	  SELECT SHIP_TO_ORG_ID, INVOICE_TO_ORG_ID, DELIVER_TO_ORG_ID
7226 	 -- bug 8340976 INTO l_sold_to_org_id, l_invoice_to_org_id, l_deliver_to_org_id
7227           INTO l_ship_to_org_id, l_invoice_to_org_id, l_deliver_to_org_id
7228 	  FROM OE_ORDER_HEADERS
7229 	  WHERE HEADER_ID = p_x_header_rec.header_id;
7230 
7231 	  IF p_x_header_rec.ship_to_org_id <> FND_API.G_MISS_NUM THEN
7232 		l_ship_to_org_id := p_x_header_rec.ship_to_org_id;
7233        END IF;
7234 
7235 	  IF p_x_header_rec.invoice_to_org_id <> FND_API.G_MISS_NUM THEN
7236 		l_invoice_to_org_id := p_x_header_rec.invoice_to_org_id;
7237        END IF;
7238 
7239 	  IF p_x_header_rec.deliver_to_org_id <> FND_API.G_MISS_NUM THEN
7240 		l_deliver_to_org_id := p_x_header_rec.deliver_to_org_id;
7241        END IF;
7242 
7243     ELSE
7244 
7245 	  -- bug 8340976 l_sold_to_org_id := p_x_header_rec.sold_to_org_id;
7246           l_ship_to_org_id := p_x_header_rec.sold_to_org_id;  -- bug 8340976
7247 	  l_invoice_to_org_id := p_x_header_rec.invoice_to_org_id;
7248 	  l_deliver_to_org_id := p_x_header_rec.deliver_to_org_id;
7249 
7250     END IF;
7251 
7252     IF  p_header_val_rec.deliver_to_contact <> FND_API.G_MISS_CHAR
7253     THEN
7254 
7255         IF p_x_header_rec.deliver_to_contact_id <> FND_API.G_MISS_NUM THEN
7256 
7257 
7258             IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_SUCCESS)
7259             THEN
7260 
7261                 fnd_message.set_name('ONT','OE_BOTH_VAL_AND_ID_EXIST');
7262                 FND_MESSAGE.SET_TOKEN('ATTRIBUTE','deliver_to_contact');
7263                 OE_MSG_PUB.Add;
7264 
7265             END IF;
7266 
7267         ELSE
7268 
7269             p_x_header_rec.deliver_to_contact_id := OE_Value_To_Id.deliver_to_contact
7270             (   p_deliver_to_contact          => p_header_val_rec.deliver_to_contact
7271 		  ,   p_deliver_to_org_id           => l_deliver_to_org_id
7272             );
7273 
7274             IF p_x_header_rec.deliver_to_contact_id = FND_API.G_MISS_NUM THEN
7275                 p_x_header_rec.return_status := FND_API.G_RET_STS_ERROR;
7276             END IF;
7277 
7278         END IF;
7279 
7280     END IF;
7281 
7282     IF  p_header_val_rec.invoice_to_contact <> FND_API.G_MISS_CHAR
7283     THEN
7284 
7285         IF p_x_header_rec.invoice_to_contact_id <> FND_API.G_MISS_NUM THEN
7286 
7287 
7288             IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_SUCCESS)
7289             THEN
7290 
7291                 fnd_message.set_name('ONT','OE_BOTH_VAL_AND_ID_EXIST');
7292                 FND_MESSAGE.SET_TOKEN('ATTRIBUTE','invoice_to_contact');
7293                 OE_MSG_PUB.Add;
7294 
7295             END IF;
7296 
7297         ELSE
7298 
7299             p_x_header_rec.invoice_to_contact_id := OE_Value_To_Id.invoice_to_contact
7300             (   p_invoice_to_contact          => p_header_val_rec.invoice_to_contact
7301 		  ,   p_invoice_to_org_id           => l_invoice_to_org_id
7302             );
7303 
7304             IF p_x_header_rec.invoice_to_contact_id = FND_API.G_MISS_NUM THEN
7305                 p_x_header_rec.return_status := FND_API.G_RET_STS_ERROR;
7306             END IF;
7307 
7308         END IF;
7309 
7310     END IF;
7311 
7312     IF  p_header_val_rec.ship_to_contact <> FND_API.G_MISS_CHAR
7313     THEN
7314 
7315         IF p_x_header_rec.ship_to_contact_id <> FND_API.G_MISS_NUM THEN
7316 
7317 
7318             IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_SUCCESS)
7319             THEN
7320 
7321                 fnd_message.set_name('ONT','OE_BOTH_VAL_AND_ID_EXIST');
7322                 FND_MESSAGE.SET_TOKEN('ATTRIBUTE','ship_to_contact');
7323                 OE_MSG_PUB.Add;
7324 
7325             END IF;
7326 
7327         ELSE
7328 
7329             p_x_header_rec.ship_to_contact_id := OE_Value_To_Id.ship_to_contact
7330             (   p_ship_to_contact             => p_header_val_rec.ship_to_contact
7331 		  ,   p_ship_to_org_id              => l_ship_to_org_id
7332             );
7333 
7334             IF p_x_header_rec.ship_to_contact_id = FND_API.G_MISS_NUM THEN
7335                 p_x_header_rec.return_status := FND_API.G_RET_STS_ERROR;
7336             END IF;
7337 
7338         END IF;
7339 
7340     END IF;
7341 
7342 /* mvijayku */
7343     IF  p_header_val_rec.end_customer_name <> FND_API.G_MISS_CHAR
7344     OR  p_header_val_rec.end_customer_number <> FND_API.G_MISS_CHAR
7345     THEN
7346 
7347         IF p_x_header_rec.end_customer_id <> FND_API.G_MISS_NUM THEN
7348 
7349 
7350             IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_SUCCESS)
7351             THEN
7352 
7353                 fnd_message.set_name('ONT','OE_BOTH_VAL_AND_ID_EXIST');
7354                 FND_MESSAGE.SET_TOKEN('ATTRIBUTE','end_customer');
7355                 OE_MSG_PUB.Add;
7356 
7357             END IF;
7358 
7359         ELSE
7360            IF p_x_header_rec.end_customer_site_use_id = FND_API.G_MISS_NUM THEN -- 4231603
7361             p_x_header_rec.end_customer_id:=OE_Value_To_Id.end_customer
7362             ( p_end_customer       => p_header_val_rec.end_customer_name
7363              ,p_end_customer_number=> p_header_val_rec.end_customer_number
7364               );
7365 
7366             IF p_x_header_rec.end_customer_id = FND_API.G_MISS_NUM THEN
7367                 p_x_header_rec.return_status := FND_API.G_RET_STS_ERROR;
7368             END IF;
7369           END IF;
7370         END IF;
7371 
7372     END IF;
7373 
7374     IF  p_header_val_rec.end_customer_contact <> FND_API.G_MISS_CHAR
7375     THEN
7376 
7377         IF p_x_header_rec.end_customer_id <>FND_API.G_MISS_NUM and
7378                 p_x_header_rec.end_customer_contact_id <> FND_API.G_MISS_NUM THEN
7379 
7380 
7381             IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_SUCCESS)
7382             THEN
7383 
7384                 fnd_message.set_name('ONT','OE_BOTH_VAL_AND_ID_EXIST');
7385                 FND_MESSAGE.SET_TOKEN('ATTRIBUTE','end_customer__contact');
7386                 OE_MSG_PUB.Add;
7387 
7388             END IF;
7389 
7390         ELSE
7391                 oe_debug_pub.add('before calling aend customer contact value to id');
7392             p_x_header_rec.end_customer_contact_id := OE_Value_To_Id.end_customer_contact
7393             (   p_end_customer_contact             => p_header_val_rec.end_customer_contact
7394 		  ,p_end_customer_id              =>p_x_header_rec.end_customer_id
7395             );
7396 	    oe_debug_pub.add('End customer contact id is '||p_x_header_rec.end_customer_contact_id);
7397 
7398             IF p_x_header_rec.end_customer_contact_id = FND_API.G_MISS_NUM THEN
7399                 p_x_header_rec.return_status := FND_API.G_RET_STS_ERROR;
7400             END IF;
7401 
7402         END IF;
7403 
7404     END IF;
7405 
7406   IF (p_header_val_rec.end_customer_name <> FND_API.G_MISS_CHAR
7407       OR p_header_val_rec.end_customer_number <> FND_API.G_MISS_CHAR
7408       OR p_x_header_rec.end_customer_id <> FND_API.G_MISS_NUM)
7409 	 AND
7410      (p_header_val_rec.end_customer_site_address1 <> FND_API.G_MISS_CHAR
7411     OR p_header_val_rec.end_customer_site_address2 <> FND_API.G_MISS_CHAR
7412     OR p_header_val_rec.end_customer_site_address3 <> FND_API.G_MISS_CHAR
7413     OR p_header_val_rec.end_customer_site_address4 <> FND_API.G_MISS_CHAR
7414     OR p_header_val_rec.end_customer_site_location          <> FND_API.G_MISS_CHAR)
7415 
7416     THEN
7417 
7418         IF p_x_header_rec.end_customer_site_use_id <> FND_API.G_MISS_NUM THEN
7419 
7420 
7421             IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_SUCCESS)
7422             THEN
7423 
7424                 fnd_message.set_name('ONT','OE_BOTH_VAL_AND_ID_EXIST');
7425                 FND_MESSAGE.SET_TOKEN('ATTRIBUTE','end_Customer_Location');
7426                 OE_MSG_PUB.Add;
7427 
7428             END IF;
7429 
7430         ELSE
7431 	   oe_debug_pub.add('Before calling End custoemr site use value to id');
7432             p_x_header_rec.end_customer_site_use_id := OE_Value_To_Id.end_customer_site
7433             (   p_end_customer_site_address1            => p_header_val_rec.end_customer_site_address1
7434             ,   p_end_customer_site_address2            => p_header_val_rec.end_customer_site_address2
7435             ,   p_end_customer_site_address3            => p_header_val_rec.end_customer_site_address3
7436             ,   p_end_customer_site_address4            => p_header_val_rec.end_customer_site_address4
7437             ,   p_end_customer_site_location                     => p_header_val_rec.end_customer_site_location
7438 	    ,   p_end_customer_site_org                       => NULL
7439 		,   p_end_customer_id                         => p_x_header_rec.end_customer_id
7440             ,   p_end_customer_site_city                => p_header_val_rec.end_customer_site_city
7441             ,   p_end_customer_site_state               => p_header_val_rec.end_customer_site_state
7442             ,   p_end_customer_site_postalcode         => p_header_val_rec.end_customer_site_postal_code
7443             ,   p_end_customer_site_country             => p_header_val_rec.end_customer_site_country
7444             ,   p_end_customer_site_use_code           => NULL
7445             );
7446 
7447 
7448     oe_debug_pub.add('after hdr sold_to_site_use_id='||p_x_header_rec.end_customer_site_use_id);
7449 
7450             IF p_x_header_rec.end_customer_site_use_id = FND_API.G_MISS_NUM THEN
7451                 p_x_header_rec.return_status := FND_API.G_RET_STS_ERROR;
7452             END IF;
7453 
7454         END IF;
7455 
7456     END IF;
7457 
7458     -- {added for bug 4240715
7459     IF  p_header_val_rec.ib_owner_dsp <> FND_API.G_MISS_CHAR
7460     THEN
7461 
7462         IF p_x_header_rec.ib_owner <> FND_API.G_MISS_CHAR THEN
7463 
7464             IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_SUCCESS)
7465             THEN
7466 
7467                 fnd_message.set_name('ONT','OE_BOTH_VAL_AND_ID_EXIST');
7468                 FND_MESSAGE.SET_TOKEN('ATTRIBUTE','IB_Owner');
7469                 OE_MSG_PUB.Add;
7470 
7471             END IF;
7472 
7473         ELSE
7474 
7475             p_x_header_rec.ib_owner:=OE_Value_To_Id.ib_owner
7476             ( p_ib_owner       => p_header_val_rec.ib_owner_dsp
7477               );
7478 
7479 	     oe_Debug_pub.add('ib owner id is '||p_x_header_rec.ib_owner);
7480             IF p_x_header_rec.ib_owner = FND_API.G_MISS_CHAR THEN
7481                 p_x_header_rec.return_status := FND_API.G_RET_STS_ERROR;
7482             END IF;
7483 
7484         END IF;
7485 
7486     END IF;
7487 
7488     IF  p_header_val_rec.ib_installed_at_location_dsp <> FND_API.G_MISS_CHAR
7489     THEN
7490 
7491         IF p_x_header_rec.ib_installed_at_location <> FND_API.G_MISS_CHAR THEN
7492 
7493             IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_SUCCESS)
7494             THEN
7495 
7496                 fnd_message.set_name('ONT','OE_BOTH_VAL_AND_ID_EXIST');
7497                 FND_MESSAGE.SET_TOKEN('ATTRIBUTE','IB_Installed_at_location');
7498                 OE_MSG_PUB.Add;
7499 
7500             END IF;
7501 
7502         ELSE
7503 
7504             p_x_header_rec.ib_installed_at_location:=OE_Value_To_Id.ib_installed_at_location
7505             ( p_ib_installed_at_location       => p_header_val_rec.ib_installed_at_location_dsp
7506               );
7507               oe_Debug_pub.add('installed at location'||p_x_header_rec.ib_installed_at_location);
7508 
7509             IF p_x_header_rec.ib_installed_at_location = FND_API.G_MISS_CHAR THEN
7510                 p_x_header_rec.return_status := FND_API.G_RET_STS_ERROR;
7511             END IF;
7512 
7513         END IF;
7514 
7515     END IF;
7516 
7517      IF  p_header_val_rec.ib_current_location_dsp <> FND_API.G_MISS_CHAR
7518     THEN
7519         IF p_x_header_rec.ib_current_location <> FND_API.G_MISS_CHAR THEN
7520 
7521             IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_SUCCESS)
7522             THEN
7523 
7524                 fnd_message.set_name('ONT','OE_BOTH_VAL_AND_ID_EXIST');
7525                 FND_MESSAGE.SET_TOKEN('ATTRIBUTE','IB_current_location');
7526                 OE_MSG_PUB.Add;
7527 
7528             END IF;
7529 
7530         ELSE
7531 
7532             p_x_header_rec.ib_current_location:=OE_Value_To_Id.ib_current_location
7533             ( p_ib_current_location       => p_header_val_rec.ib_current_location_dsp
7534               );
7535 
7536             IF p_x_header_rec.ib_current_location = FND_API.G_MISS_CHAR THEN
7537                 p_x_header_rec.return_status := FND_API.G_RET_STS_ERROR;
7538             END IF;
7539 
7540         END IF;
7541 
7542     END IF;
7543 
7544     --bug 4240715}
7545 
7546     ----------------------------------------------------------------------
7547     -- End of get IDs for customer related fields
7548     ----------------------------------------------------------------------
7549 
7550     oe_debug_pub.add('Exiting OE_HEADER_UTIL.GET_IDS', 1);
7551 
7552 END Get_Ids;
7553 
7554 
7555 FUNCTION Get_ord_seq_type
7556 (   p_order_type_id                 IN  NUMBER
7557  ,  p_transaction_phase_code        IN  VARCHAR2 DEFAULT 'F'
7558 ) RETURN VARCHAR2 IS
7559 	x_doc_sequence_value    NUMBER;
7560 	x_doc_category_code     VARCHAR(30);
7561 	X_doc_sequence_id       NUMBER;
7562 	X_set_Of_Books_id       NUMBER;
7563 	seqassid                INTEGER;
7564 	x_Trx_Date          	DATE;
7565 	l_set_of_books_rec    	OE_Order_Cache.Set_Of_Books_Rec_Type;
7566 	l_dummy                 VARCHAR2(10);
7567 	t                   	VARCHAR2(1);
7568 	X_db_sequence_name     	VARCHAR2(50);
7569 	x_doc_sequence_type 	CHAR(1);
7570 	X_doc_sequence_name 	VARCHAR2(240);
7571 	X_Prd_Tbl_Name 			VARCHAR2(240) ;
7572 	X_Aud_Tbl_Name 			VARCHAR2(240);
7573 	X_Msg_Flag 				VARCHAR2(240);
7574 	x_result 				NUMBER;
7575 
7576 BEGIN
7577 
7578 	oe_debug_pub.add('Entering OE_HEADER_UTIL.Get_Ord_Seq_Type',1);
7579 
7580     IF p_order_type_id IS NULL OR
7581         p_order_type_id = FND_API.G_MISS_NUM
7582     THEN
7583        OE_MSG_PUB.Update_Msg_Context(p_attribute_code => null);
7584         RETURN NULL;
7585     END IF;
7586 
7587     l_set_of_books_rec :=
7588     OE_Order_Cache.Load_Set_Of_Books;
7589 
7590 	x_Set_Of_Books_Id := l_set_of_books_rec.set_of_books_id;
7591 
7592     -- X_Doc_Category_Code := to_char(p_order_type_id);
7593 
7594     -- QUOTING changes
7595     IF nvl(p_transaction_phase_code,'F') = 'F' THEN
7596         X_Doc_Category_Code := to_char(p_order_type_id);
7597     ELSIF p_transaction_phase_code = 'N' THEN
7598         X_Doc_Category_Code := to_char(p_order_type_id)||'-Quote';
7599     END IF;
7600 
7601     x_result :=   fnd_seqnum.get_seq_info(
7602                                           660,
7603                                           x_doc_category_code,
7604                                           x_set_of_books_id,
7605                                           null,
7606                                           sysdate,
7607                                           X_doc_sequence_id,
7608 										  x_doc_sequence_type,
7609 										  x_doc_sequence_name,
7610                                           X_db_sequence_name,
7611 			        				      seqassid,
7612 										  X_Prd_Tbl_Name,
7613 										  X_Aud_Tbl_Name,
7614 										  X_Msg_Flag
7615 										  );
7616 	IF x_result <> 0 THEN
7617     	RAISE FND_API.G_EXC_ERROR;
7618 	END IF;
7619 
7620 	oe_debug_pub.add('Exiting OE_HEADER_UTIL.Get_Ord_Seq_Type',1);
7621 
7622 	RETURN x_doc_sequence_type;
7623 
7624 EXCEPTION
7625 
7626 WHEN OTHERS THEN
7627 		RETURN NULL;
7628 
7629 END Get_ord_seq_type ;
7630 
7631 FUNCTION Get_Mtl_Sales_Order_Id(p_header_id    IN NUMBER
7632 						 ,p_order_number IN NUMBER := FND_API.G_MISS_NUM)
7633 RETURN NUMBER
7634 IS
7635 BEGIN
7636     return inv_salesorder.get_salesorder_for_oeheader
7637                              (p_oe_header_id => p_header_id);
7638 END Get_Mtl_Sales_Order_Id;
7639 
7640 PROCEDURE Get_Order_Info(p_header_id    IN  NUMBER,
7641                          x_order_number OUT NOCOPY /* file.sql.39 change */ NUMBER,
7642                          x_order_type   OUT NOCOPY /* file.sql.39 change */ VARCHAR2,
7643                          x_order_source OUT NOCOPY /* file.sql.39 change */ VARCHAR2)
7644 IS
7645 	l_order_number  NUMBER;
7646 	l_order_type_id NUMBER := 0;
7647 BEGIN
7648 
7649     --Commenting the oe_debug_pub call to fix bug 2105266.
7650 
7651 --	oe_debug_pub.add('Entering OE_HEADER_UTIL.Get_Order_Info',1);
7652 
7653     BEGIN
7654        SELECT order_number,order_type_id
7655        INTO l_order_number,l_order_type_id
7656        FROM oe_order_headers_all
7657        WHERE header_id = p_header_id;
7658 
7659        x_order_source := FND_PROFILE.VALUE('ONT_SOURCE_CODE');
7660        x_order_number := l_order_number;
7661     EXCEPTION
7662 	WHEN NO_DATA_FOUND THEN
7663 		x_order_number := NULL;
7664     END;
7665 
7666     BEGIN
7667        -- Fix for bug#1078323: the order type name should be selected in
7668        -- the base language
7669        SELECT name
7670        INTO x_order_type
7671        FROM OE_TRANSACTION_TYPES_TL
7672        WHERE TRANSACTION_TYPE_ID = l_order_type_id
7673        AND language = (select language_code from
7674 					fnd_languages
7675 					where installed_flag = 'B');
7676     EXCEPTION
7677 	WHEN NO_DATA_FOUND THEN
7678 		x_order_type := NULL;
7679     END;
7680 
7681 --	oe_debug_pub.add('Exiting OE_HEADER_UTIL.Get_Order_Info',1);
7682 
7683 END Get_Order_Info;
7684 
7685 FUNCTION Get_Header_Id (p_order_number    IN  NUMBER,
7686                         p_order_type      IN  VARCHAR2,
7687                         p_order_source    IN  VARCHAR2)
7688 RETURN NUMBER
7689 IS
7690 	l_order_type_id          NUMBER;
7691 	l_order_type             VARCHAR2(240);
7692 	l_header_id              NUMBER;
7693 BEGIN
7694 
7695     Select header_id
7696     into l_header_id
7697     from oe_order_headers
7698     where order_number = p_order_number AND
7699           order_type_id = (select tl.transaction_type_id
7700                            from oe_transaction_types_tl tl,
7701 						  oe_transaction_types_all ta
7702                            where ta.transaction_type_id =
7703 					  tl.transaction_type_id and
7704 					  tl.name = p_order_type and
7705 					  ta.transaction_type_code = 'ORDER'
7706  					 and LANGUAGE = (
7707  					select language_code
7708                       	from fnd_languages
7709                       	where installed_flag = 'B'));
7710 
7711     RETURN l_header_id;
7712 
7713 EXCEPTION
7714    WHEN NO_DATA_FOUND THEN
7715      RETURN -1;
7716    WHEN OTHERS THEN
7717      RETURN -1;
7718 
7719 END Get_Header_Id;
7720 
7721 FUNCTION Get_Order_Type
7722 (   p_order_type_id        IN  NUMBER)
7723 RETURN VARCHAR2
7724 IS
7725 	l_order_type_id          NUMBER;
7726 	l_order_type             VARCHAR2(240);
7727 BEGIN
7728 
7729 	oe_debug_pub.add('Entering OR_HEADER_UTIL.Get_Order_Type',1);
7730 
7731     Select order_category_code --name --commented for BUG#7671483
7732     into l_order_type
7733     from oe_order_types_v
7734     where transaction_type_id = p_order_type_id;
7735 
7736 	oe_debug_pub.add('Exiting OR_HEADER_UTIL.Get_Order_Type',1);
7737 
7738     RETURN l_order_type;
7739 
7740 EXCEPTION
7741    WHEN NO_DATA_FOUND THEN
7742      RETURN null;
7743    WHEN OTHERS THEN
7744      RETURN null;
7745 
7746 END Get_Order_Type;
7747 
7748 PROCEDURE Get_Order_Number
7749          ( p_x_header_rec 	IN OUT NOCOPY oe_order_pub.header_rec_type,
7750            p_old_header_rec    IN oe_order_pub.header_rec_type )
7751 IS
7752 	l_order_number	    		VARCHAR2(30):= NULL;
7753 	x_doc_sequence_value     	NUMBER;
7754 	x_doc_category_code      	VARCHAR(30);
7755 	X_doc_sequence_id       	NUMBER;
7756 	X_db_sequence_name      	VARCHAR2(50);
7757 	x_doc_sequence_type 		CHAR(1);
7758 	X_doc_sequence_name 		VARCHAR2(240);
7759 	X_Prd_Tbl_Name 			VARCHAR2(240) ;
7760 	X_Aud_Tbl_Name 			VARCHAR2(240);
7761 	X_Msg_Flag 			VARCHAR2(240);
7762 	X_set_Of_Books_id       	NUMBER;
7763 	seqassid                	INTEGER;
7764 	l_ord_num_src_id    		NUMBER	:= NULL;
7765 	l_order_type_rec    		OE_Order_Cache.Order_Type_Rec_Type;
7766 	l_set_of_books_rec    		OE_Order_Cache.Set_Of_Books_Rec_Type;
7767 	l_order_number_csr  		INTEGER;
7768 	l_result	    		INTEGER;
7769 	l_select_stmt	   		VARCHAR2(240);
7770 	l_column_name	   	 	VARCHAR2(80);
7771 	l_doc_seq_type                  VARCHAR2(240);
7772 	l_return_status	    		VARCHAR2(30);
7773 	X_trx_date         		DATE;
7774 	lcount 				NUMBER;
7775 	x_result 			NUMBER;
7776 
7777 BEGIN
7778         oe_debug_pub.add('Entering OE_HEADER_UTIL.Get_Order_Number',1);
7779         oe_debug_pub.add('Entering OE_HEADER_UTIL.Get_Order_Number',1);
7780         -- Check if Order Number can be updated or not???? bug 4146258
7781         -- Fixed by Srini
7782         IF NOT OE_GLOBALS.EQUAL(p_x_header_rec.order_number,
7783                                 p_old_header_rec.order_number)
7784            AND p_x_header_rec.operation = OE_GLOBALS.G_OPR_UPDATE
7785            AND p_old_header_rec.order_number is not null
7786            AND p_old_header_rec.order_number <> FND_API.G_MISS_NUM
7787         THEN
7788            if p_x_header_rec.booked_flag = 'Y' and
7789               nvl(p_x_header_rec.open_flag,'Y') = 'Y' then
7790               FND_MESSAGE.SET_NAME('ONT','ONT_INVALID_ORD_NUM_BOOKING');
7791               OE_MSG_PUB.Add;
7792               RAISE FND_API.G_EXC_ERROR;
7793            end if;
7794            l_set_of_books_rec := OE_Order_Cache.Load_Set_Of_Books;
7795            x_Set_Of_Books_Id := l_set_of_books_rec.set_of_books_id;
7796            l_order_type_rec := OE_Order_Cache.Load_Order_Type (p_x_header_rec.order_type_id);
7797            oe_debug_pub.add('When Order Number has been changed :'||p_x_header_rec.transaction_phase_code);
7798            IF nvl(p_x_header_rec.transaction_phase_code,'F') = 'F' THEN
7799               X_Doc_Category_Code := to_char(p_x_header_rec.order_type_id);
7800            ELSIF p_x_header_rec.transaction_phase_code = 'N' THEN
7801               X_Doc_Category_Code := to_char(p_x_header_rec.order_type_id)||'-Quote';
7802            END IF;
7803            x_result :=   fnd_seqnum.get_seq_info(
7804                                              660,
7805                                              x_doc_category_code,
7806                                              x_set_of_books_id,
7807                                              null,
7808                                              sysdate,
7809                                              X_doc_sequence_id,
7810                                              x_doc_sequence_type,
7811                                              x_doc_sequence_name,
7812                                              X_db_sequence_name,
7813                                              seqassid,
7814                                              X_Prd_Tbl_Name,
7815                                              X_Aud_Tbl_Name,
7816                                              X_Msg_Flag);
7817 
7818            if p_x_header_rec.operation = OE_GLOBALS.G_OPR_UPDATE and
7819               x_doc_sequence_type = 'A'
7820            then
7821               FND_MESSAGE.SET_NAME('ONT','ONT_ORD_NUM_MISMATCH');
7822               OE_MSG_PUB.Add;
7823               RAISE FND_API.G_EXC_ERROR;
7824            end if;
7825 
7826         END IF;
7827 
7828         -- QUOTING changes
7829 	IF NOT OE_GLOBALS.EQUAL(p_x_header_rec.order_type_id,
7830 					 p_old_header_rec.order_type_id)
7831            OR (OE_Quote_Util.G_COMPLETE_NEG = 'Y'
7832 	       AND NOT OE_GLOBALS.EQUAL(p_x_header_rec.transaction_phase_code,
7833 				 p_old_header_rec.transaction_phase_code)
7834                )
7835         THEN
7836 
7837     	   oe_debug_pub.ADD('Ordertype is :' || to_char(p_x_header_rec.order_type_id),3);
7838 
7839     	   l_set_of_books_rec := OE_Order_Cache.Load_Set_Of_Books;
7840 	   x_Set_Of_Books_Id := l_set_of_books_rec.set_of_books_id;
7841 
7842     	   IF p_x_header_rec.order_type_id IS NOT NULL AND
7843 			p_x_header_rec.order_type_id <> FND_API.G_MISS_NUM
7844     	   THEN
7845 
7846               l_order_type_rec := OE_Order_Cache.Load_Order_Type (p_x_header_rec.order_type_id);
7847 
7848               oe_debug_pub.add('transaction phase :'||p_x_header_rec.transaction_phase_code);
7849               -- Quoting Changes
7850               IF nvl(p_x_header_rec.transaction_phase_code,'F') = 'F' THEN
7851                  X_Doc_Category_Code := to_char(p_x_header_rec.order_type_id);
7852               ELSIF p_x_header_rec.transaction_phase_code = 'N' THEN
7853                  X_Doc_Category_Code := to_char(p_x_header_rec.order_type_id)||'-Quote';
7854               END IF;
7855     	   ELSE
7856 	      RAISE FND_API.G_EXC_ERROR ;
7857     	   END IF;
7858 
7859            -- QUOTING changes
7860            IF OE_Quote_Util.G_COMPLETE_NEG = 'Y'
7861               AND nvl(l_order_type_rec.quote_num_as_ord_num_flag,'Y') = 'Y' --added nvl for bug4474915
7862            THEN
7863               oe_debug_pub.ADD('retain document number is Yes');
7864               GOTO End_Of_Procedure;
7865            END IF;
7866 
7867     	   oe_debug_pub.ADD('before calling get_seq_info ', 2);
7868  	   oe_debug_pub.ADD('Category Code'||x_doc_category_code, 3);
7869     	   oe_debug_pub.ADD('Set of Books'||x_set_of_books_id, 3);
7870            x_result :=   fnd_seqnum.get_seq_info(
7871                                              660,
7872                                              x_doc_category_code,
7873                                              x_set_of_books_id,
7874                                              null,
7875                                              sysdate,
7876                                              X_doc_sequence_id,
7877 					     x_doc_sequence_type,
7878 					     x_doc_sequence_name,
7879                                              X_db_sequence_name,
7880 			        	     seqassid,
7881 					     X_Prd_Tbl_Name,
7882 					     X_Aud_Tbl_Name,
7883 					     X_Msg_Flag
7884 											 );
7885 
7886     	   oe_debug_pub.ADD('after calling get_seq_info ', 2);
7887 
7888            IF x_result <>  FND_SEQNUM.SEQSUCC   THEN
7889     	      IF x_result = FND_SEQNUM.NOTUSED THEN
7890     		 fnd_message.set_name('ONT','OE_MISS_DOC_SEQ');
7891     		 OE_MSG_PUB.Add;
7892     		 RAISE FND_API.G_EXC_ERROR;
7893     	      END IF;
7894            END IF;
7895 	   l_doc_seq_type := x_doc_sequence_type;
7896 
7897     	   IF ( l_doc_seq_type <> 'M')  THEN
7898 
7899                 X_result := fnd_seqnum.get_seq_val(
7900                                                 660,
7901                                                 x_doc_category_code,
7902                                                 x_set_of_books_id,
7903                                                 null,
7904                                                 sysdate,
7905 						x_doc_sequence_value,
7906                                                 X_doc_sequence_id,
7907 						'Y',
7908 						'Y');
7909    		IF x_result <>  0   THEN
7910     		   RAISE FND_API.G_EXC_ERROR;
7911    		END IF;
7912 
7913     		oe_debug_pub.ADD('fndseqresult'||to_char(x_result), 2);
7914     		oe_debug_pub.ADD('fndseqtype'||x_doc_sequence_value, 2);
7915 
7916                 -- Quoting Changes
7917                 IF nvl(p_x_header_rec.transaction_phase_code,'F') = 'F' THEN
7918     		   p_x_header_rec.order_number :=  x_doc_sequence_value;
7919                 ELSIF p_x_header_rec.transaction_phase_code = 'N' THEN
7920     		   p_x_header_rec.quote_number :=  x_doc_sequence_value;
7921     		   p_x_header_rec.order_number :=  x_doc_sequence_value;
7922                 END IF;
7923 
7924 
7925            ELSIF (l_doc_seq_type = 'M') THEN
7926                 oe_debug_pub.add('manual sequence');
7927 
7928                    -- Quoting Changes
7929                    -- Fix for bug 3204076
7930                    -- Raise error if manual sequence and quote/order number is
7931                    -- not provided.
7932                    IF nvl(p_x_header_rec.transaction_phase_code,'F') = 'F' THEN
7933                       IF p_x_header_rec.order_number IS NULL THEN
7934                          fnd_message.set_name('ONT','OE_ATTRIBUTE_REQUIRED');
7935                          FND_MESSAGE.SET_TOKEN('ATTRIBUTE',
7936                              OE_Order_UTIL.Get_Attribute_Name('ORDER_NUMBER'));
7937                          OE_MSG_PUB.Add;
7938                          RAISE FND_API.G_EXC_ERROR;
7939                       ELSE
7940                       x_doc_sequence_value := p_x_header_rec.order_number;
7941                       END IF;
7942                    ELSIF p_x_header_rec.transaction_phase_code = 'N' THEN
7943                       IF p_x_header_rec.quote_number IS NULL THEN
7944                          fnd_message.set_name('ONT','OE_ATTRIBUTE_REQUIRED');
7945                          FND_MESSAGE.SET_TOKEN('ATTRIBUTE',
7946                              OE_Order_UTIL.Get_Attribute_Name('QUOTE_NUMBER'));
7947                          OE_MSG_PUB.Add;
7948                          RAISE FND_API.G_EXC_ERROR;
7949                       ELSE
7950                       x_doc_sequence_value := p_x_header_rec.quote_number;
7951     		      p_x_header_rec.order_number :=  x_doc_sequence_value;
7952                       END IF;
7953                    END IF;
7954 
7955            END IF;
7956 
7957            -- QUOTING changes - unique key checks and set WF user keys
7958            -- based on transaction phase
7959            IF nvl(p_x_header_rec.transaction_phase_code,'F') = 'F' THEN
7960 
7961                  Select Count(Header_id) into
7962                         lcount
7963                  From   OE_ORDER_HEADERS_ALL
7964                  WHERE  order_type_id = p_x_header_rec.order_type_id
7965                  and    order_number = p_x_header_rec.order_number
7966                  -- We need to remove the check condition around the version number.
7967                  --Bug #3357896.
7968                  --and version_number = p_x_header_rec.version_number
7969                  and    header_id <> p_x_header_rec.header_id;
7970 
7971                  IF  lcount > 0 THEN
7972                    fnd_message.set_name('ONT','OE_ORDER_NUM_EXISTS');
7973                    OE_MSG_PUB.Add;
7974                    RAISE FND_API.G_EXC_ERROR;
7975 	         END IF;
7976 
7977                  -- Fix for bug# 3526149. Also see bug 3485680
7978                  oe_debug_pub.add('p_old_header_rec.order_number:' || p_old_header_rec.order_number,1);
7979                  oe_debug_pub.add('p_old_header_rec.transaction_phase_code:' ||
7980                                                             p_old_header_rec.transaction_phase_code,1);
7981                  IF (p_x_header_rec.order_number <> p_old_header_rec.order_number AND
7982                      p_old_header_rec.order_number is not null AND
7983                      p_old_header_rec.order_number <> FND_API.G_MISS_NUM) AND
7984                      OE_Quote_Util.G_COMPLETE_NEG = 'N' THEN
7985                        oe_debug_pub.add('Ord_Num Changed, Calling Set_Header_User_Key and WF_ENGINE.SetItemUserKey',1);
7986                        OE_Order_WF_Util.Set_Header_User_Key(p_x_header_rec);
7987                        WF_ENGINE.SetItemUserKey(OE_Globals.G_WFI_HDR, to_char(p_x_header_rec.header_id),
7988                                 substrb(fnd_message.get, 1, 240));
7989 
7990                        WF_ENGINE.SetItemAttrNumber(OE_Globals.G_WFI_HDR, to_char(p_x_header_rec.header_id),
7991                                         'ORDER_NUMBER', p_x_header_rec.order_number);  -- Bug 3589688
7992                  END IF;
7993 
7994            ELSIF p_x_header_rec.transaction_phase_code = 'N' THEN
7995 
7996                  Select Count(Header_id) into
7997                         lcount
7998                  From   OE_ORDER_HEADERS_ALL
7999                  WHERE  order_type_id = p_x_header_rec.order_type_id
8000                  and    quote_number = p_x_header_rec.quote_number
8001                  -- We need to remove the check condition around the version number.
8002                  --Bug #3357896.
8003                  --and version_number = p_x_header_rec.version_number
8004                  and header_id <> p_x_header_rec.header_id;
8005 
8006                  IF  lcount > 0 THEN
8007                      fnd_message.set_name('ONT','OE_QUOTE_NUM_EXISTS');
8008                      OE_MSG_PUB.Add;
8009                      RAISE FND_API.G_EXC_ERROR;
8010 	         END IF;
8011 
8012                  -- Fix for bug# 3526149. Also see bug 3485680
8013                  oe_debug_pub.add('p_old_header_rec.quote_number:' || p_old_header_rec.quote_number,1);
8014                  IF (p_x_header_rec.quote_number <> p_old_header_rec.quote_number AND
8015                      p_old_header_rec.quote_number is not null AND
8016                      p_old_header_rec.quote_number <> FND_API.G_MISS_NUM) THEN
8017                         oe_debug_pub.add('Calling OE_Order_WF_Util.Set_Negotiate_Hdr_User_Key for HeaderID:'
8018                                               || to_char(p_x_header_rec.header_id), 1);
8019                         OE_Order_WF_Util.Set_Negotiate_Hdr_User_Key
8020                                 (p_header_id => p_x_header_rec.header_id
8021                                 ,p_sales_document_type_code => 'O'
8022                                 ,p_transaction_number => p_x_header_rec.quote_number
8023                                 );
8024                         WF_ENGINE.SetItemAttrNumber(OE_GLOBALS.G_WFI_NGO, to_char(p_x_header_rec.header_id),
8025                                         'TRANSACTION_NUMBER', p_x_header_rec.quote_number);  -- Bug 3589688
8026                  END IF;
8027 
8028 
8029            END IF; -- end if transaction phase check
8030 
8031 	END IF;  -- Global equal
8032 
8033         <<End_Of_Procedure>>
8034 
8035 	oe_debug_pub.add('Exiting OR_HEADER_UTIL.Get_Order_Number',1);
8036 
8037 EXCEPTION
8038     WHEN FND_API.G_EXC_ERROR THEN
8039     oe_debug_pub.ADD('Get Order Number-Exp exception ', 1);
8040      RAISE FND_API.G_EXC_ERROR;
8041 
8042 
8043     WHEN OTHERS THEN
8044     oe_debug_pub.ADD('Get Order Number-exception ', 1);
8045 
8046 
8047     	IF OE_MSG_PUB.Check_Msg_Level (OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
8048 	THEN
8049     	    OE_MSG_PUB.Add_Exc_Msg
8050     	    (	G_PKG_NAME  	    ,
8051     	        'Get_Order_Number'
8052 	    );
8053     	END IF;
8054 
8055 	RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8056 
8057 END Get_Order_Number;
8058 
8059 FUNCTION Get_Base_Order_Type
8060 (   p_order_type_id        IN  NUMBER)
8061 RETURN VARCHAR2
8062 IS
8063    l_order_type_id          NUMBER;
8064    l_order_type             VARCHAR2(240);
8065 --
8066 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
8067 --
8068 BEGIN
8069    IF l_debug_level  > 0 THEN
8070       oe_debug_pub.add('Entering OR_HEADER_UTIL.Get_Base_Order_Type ' || p_order_type_id,1);
8071    END IF;
8072 
8073      SELECT NAME
8074      INTO l_order_type
8075      FROM OE_TRANSACTION_TYPES_TL
8076      WHERE TRANSACTION_TYPE_ID = p_order_type_id
8077      AND language = (select language_code
8078                      from fnd_languages
8079                      where installed_flag = 'B');
8080 
8081    IF l_debug_level  > 0 THEN
8082       oe_debug_pub.add('Exiting OR_HEADER_UTIL.Get_Base_Order_Type ' || l_order_type,1);
8083    END IF;
8084 
8085     RETURN l_order_type;
8086 
8087 EXCEPTION
8088    WHEN NO_DATA_FOUND THEN
8089      RETURN null;
8090    WHEN OTHERS THEN
8091      RETURN null;
8092 
8093 END Get_Base_Order_Type;
8094 
8095 --7688372 start
8096 PROCEDURE Load_attachment_rules
8097 IS
8098    CURSOR header_attributes IS
8099    SELECT oare.ATTRIBUTE_CODE  attribute_code,Count(1) attachment_count
8100    FROM   oe_attachment_rule_elements oare, oe_attachment_rules  oar
8101    WHERE  oare.rule_id=oar.rule_id
8102    AND    oar.DATABASE_OBJECT_NAME='OE_AK_ORDER_HEADERS_V'
8103    GROUP BY oare.ATTRIBUTE_CODE;
8104 
8105 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
8106 
8107 BEGIN
8108  IF l_debug_level > 0 then
8109   oe_debug_pub.add('Entering Load_attachment_rules');
8110  End IF;
8111 
8112  IF g_attachment_rule_count_tab.count = 0 THEN
8113    FOR header_attributes_rec IN header_attributes LOOP
8114       g_attachment_rule_count_tab(header_attributes_rec.attribute_code) := header_attributes_rec.attachment_count;
8115    END LOOP;
8116  END IF;
8117 
8118  IF l_debug_level > 0 then
8119   oe_debug_pub.add('Exiting Load_attachment_rules');
8120  End IF;
8121 
8122 END Load_attachment_rules;
8123 --7688372 end
8124 
8125 
8126 PROCEDURE Pre_Write_Process
8127          ( p_x_header_rec 	IN OUT NOCOPY  oe_order_pub.header_rec_type,
8128            p_old_header_rec    IN oe_order_pub.header_rec_type )
8129 IS
8130 -- included to fix bug 1589196   Begin
8131    CURSOR C_HSC_COUNT(t_header_id Number) IS
8132    SELECT count(sales_credit_id), max(sales_credit_id)
8133    FROM oe_sales_credits sc,
8134 	   oe_sales_credit_types sct
8135    WHERE header_id = t_header_id
8136    AND   sct.sales_credit_type_id = sc.sales_credit_type_id
8137    AND   sct.quota_flag = 'Y'
8138    AND   line_id is null;
8139 -- included to fix bug 1589196  End
8140 
8141 	l_return_status 			VARCHAR2(30);
8142 	l_count						NUMBER;
8143 /* Variables to call process order */
8144 	l_control_rec	OE_GLOBALS.Control_Rec_Type;
8145 	p_x_old_header_rec OE_ORDER_PUB.Header_Rec_Type:=  p_old_header_rec ;
8146 	l_msg_count NUMBER;
8147 	l_msg_data VARCHAR2(2000);
8148 	l_new_order_type  varchar2(80);
8149 	l_order_type varchar2(80);
8150 	l_return_value number;
8151 	l_source_code VARCHAR2(40);
8152 -- included to fix bug 1589196   Begin
8153         l_sales_crd_cnt number;
8154         l_sales_crd_id  number;
8155 -- included to fix bug 1589196   end
8156         l_reason_code VARCHAR2(30);
8157         l_reason_comments VARCHAR2(2000);
8158         --bug 4190357
8159         v_count                     NUMBER;
8160         l_meaning               VARCHAR2(80);
8161         l_old_line_tbl              OE_Order_PUB.Line_Tbl_Type;
8162         l_line_tbl                  OE_Order_PUB.Line_Tbl_Type;
8163         i                           Number;
8164         j                           Number := 0;
8165         lx_line_rec                 OE_Order_PUB.Line_Rec_Type;
8166         l_apply_automatic_atchmt    VARCHAR2(1) :=
8167 NVL(FND_PROFILE.VALUE('OE_APPLY_AUTOMATIC_ATCHMT'),'Y') ; --5893276
8168 
8169         cursor line_ids(p_header_id IN NUMBER) is
8170         select line_id from oe_order_lines_all
8171         where header_id = p_header_id;
8172         --bug 4190357
8173 -- R12 CC encryption
8174         l_changed_attribute VARCHAR2(200);
8175         l_modified_from     VARCHAR2(30);
8176 --
8177 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
8178 --
8179 l_attr_attach_change         boolean := FALSE;  --6896311
8180 
8181 
8182 BEGIN
8183 	oe_debug_pub.add('Entering OR_HEADER_UTIL.Pre_Write_Process',1);
8184 
8185         OE_SALES_CAN_UTIL.G_IR_ISO_HDR_CANCEL := FALSE;
8186         -- Setting the global for IR ISO Tracking bug 7667702
8187 
8188      /* Start AuditTrail */
8189 
8190      IF (p_x_header_rec.operation  = OE_GLOBALS.G_OPR_UPDATE) THEN
8191 
8192         IF OE_GLOBALS.G_AUDIT_REASON_RQD_FLAG = 'Y' THEN
8193            OE_DEBUG_PUB.add('OEXUHDRB: Audit check requires reason', 5);
8194 
8195            IF (p_x_header_rec.change_reason IS NULL
8196                 OR p_x_header_rec.change_reason = FND_API.G_MISS_CHAR
8197                 OR NOT OE_Validate.Change_Reason_Code(p_x_header_rec.change_reason)) then
8198 
8199                  IF OE_CODE_CONTROL.CODE_RELEASE_LEVEL >= '110510' THEN
8200                    IF OE_Versioning_Util.Captured_Reason IS NULL THEN
8201                       OE_Versioning_Util.Get_Reason_Info(l_reason_code, l_reason_comments);
8202                       IF l_reason_code IS NULL THEN
8203                        -- bug 3636884, defaulting reason from group API
8204                        IF OE_GLOBALS.G_DEFAULT_REASON THEN
8205                          oe_debug_pub.add('Defaulting Audit Reason for Order Header', 1);
8206                          p_x_header_rec.change_reason := 'SYSTEM';
8207                        ELSE
8208                          OE_DEBUG_PUB.add('Reason code for change is missing or invalid', 1);
8209                          fnd_message.set_name('ONT','OE_AUDIT_REASON_RQD');
8210                          fnd_message.set_token('OBJECT','ORDER');
8211                          oe_msg_pub.add;
8212                          RAISE FND_API.G_EXC_ERROR;
8213                        END IF;
8214                       END IF;
8215                    END IF;
8216                  ELSE
8217                    OE_DEBUG_PUB.add('Reason code for change is missing or invalid', 1);
8218                    fnd_message.set_name('ONT','OE_AUDIT_REASON_RQD');
8219                    fnd_message.set_token('OBJECT','ORDER');
8220                    oe_msg_pub.add;
8221                    RAISE FND_API.G_EXC_ERROR;
8222                  END IF;
8223            END IF;
8224         END IF;
8225      END IF;
8226 
8227 /* START PREPAYMENT */
8228      IF  (p_x_header_rec.payment_term_id IS NOT NULL AND --Bug 4207730
8229         NOT OE_GLOBALS.Equal(p_x_header_rec.payment_term_id,p_old_header_rec.payment_term_id))
8230      THEN
8231         IF OE_PREPAYMENT_UTIL.Is_Prepaid_Order(p_x_header_rec) = 'Y' THEN
8232            FND_MESSAGE.SET_NAME('ONT', 'ONT_USE_HDR_TERMS_FOR_INVOICE');
8233            OE_MSG_PUB.Add;
8234         END IF;
8235      END IF;
8236 /* END PREPAYMENT */
8237 -- Included to fix bug 1589196 Begin
8238 
8239 IF NOT OE_GLOBALS.Equal(p_x_header_rec.salesrep_id,p_old_header_rec.salesrep_id)
8240 then
8241    IF p_x_header_rec.operation <> OE_GLOBALS.G_OPR_CREATE THEN
8242      OPEN C_HSC_COUNT(p_x_header_rec.header_id);
8243      FETCH C_HSC_COUNT INTO l_sales_crd_cnt, l_sales_crd_id;
8244      CLOSE C_HSC_COUNT;
8245      if l_sales_crd_cnt > 1 then
8246        fnd_message.set_name('ONT','OE_TOO_MANY_HSCREDIT');
8247        OE_MSG_PUB.Add;
8248        RAISE  FND_API.G_EXC_ERROR;
8249      end if;
8250   END IF;
8251 END IF;
8252 -- Included to fix bug 1589196   End
8253 
8254 /*	Oe_Header_Util.get_order_number(p_x_header_rec => p_x_header_rec,p_old_header_rec => p_old_header_rec);*/
8255     --Commented for bug#13081490.Moved this call to after completion of Shipping Method validation.
8256 
8257 
8258 		-- Call Cancellation Related Code
8259 
8260 
8261     IF (p_x_header_rec.cancelled_flag = 'Y')AND
8262        (p_x_header_rec.cancelled_flag <> NVL(p_old_header_rec.cancelled_flag,'N')) THEN -- Bug 9241924
8263 
8264       /* Fix Bug # 3241831: Set Global before Order Cancellation Starts */
8265       IF OE_GLOBALS.G_UI_FLAG = FALSE THEN
8266         oe_debug_pub.add('SET G_ORD_LVL_CAN TO TRUE FOR NON UI ORDER CANCEL');
8267         OE_OE_FORM_CANCEL_LINE.g_ord_lvl_can := TRUE;
8268       END IF;
8269 
8270 /* 7576948: IR ISO Change Management project Start */
8271 --
8272 -- When the order header level cancellation is triggered, and all the
8273 -- order lines are successfully cancelled, we should log a delayed request
8274 -- G_UPDATE_REQUISITION to call the Purchasing API so as to trigger the
8275 -- requisition header cancellation. For this, we need to log the delayed
8276 -- requests from Pre_Write_Process procedure of OE_Header_Util package.
8277 -- In this procedure, we need to raise this delayed request only after
8278 -- successful execution of OE_Sales_Can_Util.Perform_Cancel_Order API,
8279 -- which is responsible for canceling both order header and all order
8280 -- lines. This code will be triggered in the event of Full Order
8281 -- Cancellation only.
8282 --
8283 -- If it is a partial order cancellation, i.e. cancellation of internal
8284 -- sales order lines, which are eligible for cancellation and there exists
8285 -- atleast one line in non-cancellation status, then purchasing product
8286 -- will be called only with the cancelled internal sales order lines
8287 -- information, such that corresponding requisition lines can be cancelled/
8288 -- updated.  However, in such a case, it may happen that due to system split,
8289 -- fulfillment organization user may cancel a specific line shipment, which
8290 -- may request for requisition line cancellation, but requesting org may
8291 -- have not yet received the partial shipment done so far. In that event,
8292 -- requestion line should be cancelled only after validating that there
8293 -- exists no open quantity for receiving. If there exists open quantity
8294 -- for receiving for requesting org, then inspite of fulfillment org requested
8295 -- for requestion line cancellation, it should be suppressed by the
8296 -- requesting org for update operation.
8297 --
8298 -- Additionally, while logging the delated request, system will ensure that
8299 -- global OE_Internal_Requisition_Pvt.G_Update_ISO_From_Req should be set to
8300 -- FALSE. If this global is TRUE then it signifies that the full header
8301 -- cancellation is triggered from Requesting Organization user.
8302 --
8303 -- Please refer to following delayed request params with their meaning
8304 -- useful while logging the delayed request -
8305 --
8306 -- P_entity_code        Entity for which delayed request has to be logged.
8307 --                      In this project it can be OE_Globals.G_Entity_Line
8308 --                      or OE_Globals.G_Entity_Header
8309 -- P_entity_id          Primary key of the entity record. In this project,
8310 --                      it can be Order Line_id or Header_id
8311 -- P_requesting_entity_code Which entity has requested this delayed request to
8312 --                          be logged! In this project it will be OE_Globals.
8313 --                          G_Entity_Line or OE_Globals.G_Entity_Header
8314 -- P_requesting_entity_id       Primary key of the requesting entity. In this
8315 --                              project, it is Line_id or Header_id
8316 -- P_request_type       Indicates which business logic (or which procedure)
8317 --                      should be executed. In this project, it is OE_Global
8318 --                      s.G_UPDATE_REQUISITION
8319 -- P_request_unique_key1        Additional argument in form of parameters.
8320 --                              In this project, it will denote the Sales Order
8321 --                              Header id
8322 -- P_request_unique_key2        Additional argument in form of parameters.
8323 --                              In this project, it will denote the Requisition
8324 --                              Header id
8325 -- P_request_unique_key3        Additional argument in form of parameters. In
8326 --                              this project, it will denote the Requistion Line
8327 --                              id
8328 -- P_param1     Additional argument in form of parameters. In this project, it
8329 --              will denote net change in order quantity with respective single
8330 --              requisition line. If it is greater than 0 then it is an increment
8331 --              in the quantity, while if it is less than 0 then it is a decrement
8332 --              in the ordered quantity. If it is 0 then it indicates there is no
8333 --              change in ordered quantity value
8334 -- P_param2     Additional argument in form of parameters. In this project, it
8335 --              will denote whether internal sales order is cancelled or not. If
8336 --              it is cancelled then respective Purchasing api will be called to
8337 --              trigger the requisition header cancellation. It accepts a value of
8338 --              Y indicating requisition header has to be cancelled.
8339 -- P_param3     Additional argument in form of parameters. In this project, it
8340 --              will denote the number of sales order lines cancelled while order
8341 --              header is (Full/Partial) cancelled.
8342 -- p_date_param1        Additional date argument in form of parameters. In this
8343 --                      project, it will denote the change in Schedule Ship Date
8344 --                      with to respect to single requisition line.
8345 -- P_Long_param1        Additional argument in form of parameters. In this project,
8346 --                      it will store all the sales order line_ids, which are getting
8347 --                      cancelled while order header gets cancelled (Full/Partial).
8348 --                      These Line_ids will be separated by a delimiter comma ','
8349 --
8350 -- For details on IR ISO CMS project, please refer to FOL >
8351 -- OM Development > OM GM > 12.1.1 > TDD > IR_ISO_CMS_TDD.doc
8352 --
8353 
8354       IF (p_x_header_rec.order_source_id = 10) THEN
8355         OE_SALES_CAN_UTIL.G_IR_ISO_HDR_CANCEL := TRUE;
8356         IF l_debug_level > 0 THEN
8357           oe_debug_pub.add(' Setting global Header Cancel for IR ISO to TRUE',5);
8358         END IF;
8359       END IF;
8360       -- Setting this global to TRUE confirming it to be
8361       -- Order header level full cancellation
8362 
8363         OE_SALES_CAN_UTIL.Perform_cancel_order(p_x_header_rec,
8364                                                p_old_header_rec,
8365                                                l_return_status);
8366 
8367       IF (p_x_header_rec.order_source_id = 10) THEN
8368         OE_SALES_CAN_UTIL.G_IR_ISO_HDR_CANCEL := FALSE;
8369         IF l_debug_level > 0 THEN
8370           oe_debug_pub.add(' Setting global Header Cancel for IR ISO to FALSE',5);
8371         END IF;
8372       END IF;
8373       -- Resetting the global to FALSE
8374 
8375     	IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
8376      		IF l_return_status = FND_API.G_RET_STS_ERROR THEN
8377         		RAISE FND_API.G_EXC_ERROR;
8378      		ELSE
8379      			RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8380      		END IF;
8381 
8382 
8383   ELSE -- If return status is SUCCESS
8384     IF (p_x_header_rec.order_source_id = 10) THEN
8385       IF NOT OE_Internal_Requisition_Pvt.G_Update_ISO_From_Req THEN
8386         IF l_debug_level > 0 THEN
8387           oe_debug_pub.add(' Header level cancellation. Log the IR ISO update delayed request',5);
8388         END IF;
8389 
8390         OE_delayed_requests_Pvt.log_request
8391         ( p_entity_code            => OE_GLOBALS.G_ENTITY_HEADER
8392         , p_entity_id              => p_x_header_rec.header_id
8393         , p_requesting_entity_code => OE_GLOBALS.G_ENTITY_HEADER
8394         , p_requesting_entity_id   => p_x_header_rec.header_id
8395         , p_request_unique_key2    => p_x_header_rec.source_document_id -- Req Hdr_id
8396         , p_param2                 => 'Y'
8397         , p_request_type           => OE_GLOBALS.G_UPDATE_REQUISITION
8398         , x_return_status          => l_return_status
8399         );
8400 
8401         IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
8402           RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8403         ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
8404           RAISE FND_API.G_EXC_ERROR;
8405         END IF;
8406       END IF;
8407     END IF; -- Order_Source_id
8408 
8409 
8410 /* ============================= */
8411 /* IR ISO Change Management Ends */
8412 
8413 
8414    		END IF;
8415    END IF;
8416 
8417 	-- If ship from org has been changed validate the freight carrier. If
8418 	-- freight carrier is not a valid one for the ship from org clear the
8419 	-- freight carrier field.
8420 
8421 	IF (p_x_header_rec.order_category_code <> 'RETURN') THEN
8422 
8423     IF (NOT OE_GLOBALS.Equal(p_x_header_rec.ship_from_org_id,
8424               p_old_header_rec.ship_from_org_id) OR
8425      NOT OE_GLOBALS.Equal(p_x_header_rec.shipping_method_code,
8426          p_old_header_rec.shipping_method_code))  THEN
8427 
8428 	    IF p_x_header_rec.shipping_method_code IS NOT NULL AND
8429            p_x_header_rec.ship_from_org_id IS NOT NULL THEN
8430 
8431               IF OE_CODE_CONTROL.CODE_RELEASE_LEVEL >= '110509' THEN
8432                  SELECT count(*)
8433                  INTO   l_count
8434                  FROM   wsh_carrier_services wsh,
8435                         wsh_org_carrier_services wsh_org
8436                  WHERE  wsh_org.organization_id      = p_x_header_rec.ship_from_org_id
8437                    AND  wsh.carrier_service_id       = wsh_org.carrier_service_id
8438                    AND  wsh.ship_method_code         = p_x_header_rec.shipping_method_code
8439                    AND  wsh_org.enabled_flag         = 'Y';
8440               ELSE
8441           	SELECT  count(CARRIER_SHIP_METHOD_ID)
8442           	INTO    l_count
8443      		FROM    wsh_carrier_ship_methods
8444        		WHERE   ship_method_code = p_x_header_rec.shipping_method_code
8445                   AND   organization_id = p_x_header_rec.ship_from_org_id
8446                   AND   enabled_flag = 'Y'; -- added for bug 3886064
8447               END IF;
8448 
8449 	   	--  Valid shipping method.
8450 
8451                IF l_debug_level > 0 THEN
8452                   oe_debug_pub.add('l_count : ' || l_count);
8453                   oe_debug_pub.add('shipping_method_code : ' || p_x_header_rec.shipping_method_code);
8454                END IF;
8455 
8456 	   		IF	l_count  = 0 THEN
8457 
8458                           --bug 4190357
8459                           select count(*) into v_count from oe_price_adjustments
8460                           where header_id = p_x_header_rec.header_id
8461                           and line_id is null
8462                           and substitution_attribute = 'QUALIFIER_ATTRIBUTE11'
8463                           and list_line_type_code = 'TSN'
8464                           and modified_to = p_x_header_rec.shipping_method_code;
8465                           IF v_count > 0 THEN
8466                              IF l_debug_level > 0 THEN
8467                                 oe_debug_pub.add('Deleting the header tsn adjustments');
8468                              END IF;
8469                              DELETE FROM OE_PRICE_ADJUSTMENTS
8470                              WHERE HEADER_ID = p_x_header_rec.header_id
8471                              AND LIST_LINE_TYPE_CODE = 'TSN'
8472                              AND SUBSTITUTION_ATTRIBUTE = 'QUALIFIER_ATTRIBUTE11'
8473                              AND MODIFIED_TO = p_x_header_rec.shipping_method_code
8474                              RETURNING MODIFIED_FROM INTO l_modified_from;
8475                           END IF;
8476                           select meaning into l_meaning from oe_ship_methods_v where lookup_type = 'SHIP_METHOD' and lookup_code = p_x_header_rec.shipping_method_code;
8477                           --bug 4190357
8478 
8479        			l_control_rec.write_to_DB          := FALSE;
8480        			l_control_rec.controlled_operation  := TRUE;
8481        			l_control_rec.process  := FALSE;
8482                          --bug 3941272
8483 	 		p_x_old_header_rec := p_x_header_rec ;
8484                         IF v_count = 0 THEN
8485         	        --end bug 3941272
8486 				p_x_header_rec.freight_carrier_code := NULL;
8487 				p_x_header_rec.shipping_method_code := NULL;
8488                         ELSE
8489                            p_x_header_rec.shipping_method_code := l_modified_from;
8490                         END IF;
8491 
8492 
8493   	          Oe_Order_Pvt.Header
8494 			(   p_validation_level    => FND_API.G_VALID_LEVEL_NONE
8495 			,   p_control_rec         => l_control_rec
8496 			,   p_x_header_rec    => p_x_header_rec
8497 			,   p_x_old_header_rec =>  p_x_old_header_rec
8498                         ,   x_return_status     => l_return_status );
8499 
8500 
8501                 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
8502                   RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8503                 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
8504                   RAISE FND_API.G_EXC_ERROR;
8505                 END IF;
8506 
8507 
8508        	OE_MSG_PUB.Update_Msg_Context(p_attribute_code => 'SHIPPING_METHOD');
8509 		    	fnd_message.set_name('ONT','OE_INVALID_ATTRIBUTE');
8510                           --bug 4190357 added l_meaning to the token
8511 				FND_MESSAGE.SET_TOKEN('ATTRIBUTE',
8512 				OE_Order_Util.Get_Attribute_Name('shipping_method_code') || ' ' || l_meaning);
8513 				OE_MSG_PUB.Add;
8514 				OE_MSG_PUB.Update_Msg_Context(p_attribute_code => null);
8515 
8516 		oe_debug_pub.add('Value of shipping Method:'
8517           ||p_x_header_rec.shipping_method_code,2);
8518 
8519           --bug 4190357
8520           for i in line_ids(p_x_header_rec.header_id) loop
8521             v_count := 0;
8522             select count(*) into v_count from oe_price_Adjustments
8523             where header_id = p_x_header_rec.header_id
8524               and line_id = i.line_id
8525               and substitution_attribute = 'QUALIFIER_ATTRIBUTE11'
8526               and list_line_type_code = 'TSN';
8527             If v_count = 0 Then
8528                j := j + 1;
8529                Oe_Line_Util.Query_Row(i.line_id, lx_line_rec);
8530                l_old_line_tbl(j) := lx_line_rec;
8531                l_line_tbl(j) := lx_line_rec;
8532                IF l_modified_from is NULL Then
8533                   l_line_tbl(j).freight_carrier_code := NULL;
8534                   l_line_tbl(j).shipping_method_code := NULL;
8535                ELSE
8536                   l_line_tbl(j).shipping_method_code := l_modified_from;
8537                END IF;
8538                l_line_tbl(j).operation := OE_GLOBALS.G_OPR_UPDATE;
8539             End If;
8540           end loop;
8541           IF l_line_tbl.count > 0 THEN
8542              OE_GLOBALS.G_PRICING_RECURSION := 'Y';
8543              l_control_rec.controlled_operation := TRUE;
8544              l_control_rec.check_security            := TRUE;
8545              l_control_rec.clear_dependents  := FALSE;
8546              l_control_rec.default_attributes        := FALSE;
8547              l_control_rec.change_attributes := TRUE;
8548              l_control_rec.validate_entity           := FALSE;
8549              l_control_rec.write_to_DB          := TRUE;
8550              l_control_rec.process := FALSE;
8551 
8552              Oe_Order_Pvt.Lines
8553              ( p_validation_level              => FND_API.G_VALID_LEVEL_NONE
8554               ,p_control_rec                   => l_control_rec
8555               ,p_x_line_tbl                    => l_line_tbl
8556               ,p_x_old_line_tbl                => l_old_line_tbl
8557               ,x_return_status                 => l_return_status
8558              );
8559 
8560              IF l_return_status = FND_API.G_RET_STS_ERROR THEN
8561                 RAISE FND_API.G_EXC_ERROR;
8562              ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
8563                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8564              END IF;
8565              OE_GLOBALS.G_PRICING_RECURSION := 'N';
8566           END IF;
8567           --bug 4190357
8568 
8569 			END IF;
8570 		END IF;
8571      END IF;
8572      END IF;
8573         Oe_Header_Util.get_order_number(p_x_header_rec => p_x_header_rec,
8574 							 p_old_header_rec => p_old_header_rec);       --Added for bug 13081490
8575 
8576 
8577 	-- Log delayed request to create automatic attachments
8578 /*6896311
8579         IF (p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE OR
8580             p_x_header_rec.operation = OE_GLOBALS.G_OPR_UPDATE) AND   --5893276
8581 6896311*/
8582          IF (p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE )  AND --6896311
8583             l_apply_automatic_atchmt  = 'Y' THEN
8584 		oe_debug_pub.add('log request to apply atcmt');
8585         OE_DELAYED_REQUESTS_PVT.Log_Request
8586 	(p_entity_code 	 => OE_GLOBALS.G_ENTITY_HEADER,
8587 	 p_entity_id         => p_x_header_rec.header_id,
8588 	 p_request_type      => OE_GLOBALS.G_APPLY_AUTOMATIC_ATCHMT,
8589 	 p_requesting_entity_code 	=> OE_GLOBALS.G_ENTITY_HEADER,
8590 	 p_requesting_entity_id		=> p_x_header_rec.header_id,
8591 	 x_return_status			=> l_return_status
8592 	 );
8593 	END IF;
8594 
8595 --6896311
8596         IF (p_x_header_rec.operation = OE_GLOBALS.G_OPR_UPDATE )  AND
8597             l_apply_automatic_atchmt  = 'Y'
8598 THEN
8599         oe_debug_pub.add('log request to update atcmt');
8600 
8601 --7688372 start
8602             Load_attachment_rules;
8603 --7688372 end
8604 
8605             IF (NOT OE_GLOBALS.Equal(p_x_header_rec.CUST_PO_NUMBER
8606                                     ,p_old_header_rec.CUST_PO_NUMBER) AND g_attachment_rule_count_tab.exists('CUST_PO_NUMBER'))  --7688372
8607             OR (NOT OE_GLOBALS.Equal(p_x_header_rec.INVOICE_TO_ORG_ID
8608                                     ,p_old_header_rec.INVOICE_TO_ORG_ID)  AND g_attachment_rule_count_tab.exists('INVOICE_TO_ORG_ID'))  --7688372
8609             OR (NOT OE_GLOBALS.Equal(p_x_header_rec.ORDER_TYPE_ID
8610                                     ,p_old_header_rec.ORDER_TYPE_ID) AND g_attachment_rule_count_tab.exists('ORDER_TYPE_ID'))  --7688372
8611             OR (NOT OE_GLOBALS.Equal(p_x_header_rec.SHIP_TO_ORG_ID
8612                                     ,p_old_header_rec.SHIP_TO_ORG_ID)  AND g_attachment_rule_count_tab.exists('SHIP_TO_ORG_ID'))  --7688372
8613             OR (NOT OE_GLOBALS.Equal(p_x_header_rec.SOLD_TO_ORG_ID
8614                                     ,p_old_header_rec.SOLD_TO_ORG_ID)   AND g_attachment_rule_count_tab.exists('SOLD_TO_ORG_ID'))  --7688372
8615             OR (NOT OE_GLOBALS.Equal(p_x_header_rec.ORDER_CATEGORY_CODE
8616                                     ,p_old_header_rec.ORDER_CATEGORY_CODE)  AND g_attachment_rule_count_tab.exists('ORDER_CATEGORY_CODE'))  --7688372
8617             THEN
8618 
8619                 l_attr_attach_change := TRUE;
8620 
8621             END IF;
8622 
8623           IF l_attr_attach_change THEN
8624            OE_delayed_requests_Pvt.Log_Request
8625                  (p_entity_code   => OE_GLOBALS.G_ENTITY_HEADER,
8626                  p_entity_id         => p_x_header_rec.header_id,
8627                  p_request_type      => OE_GLOBALS.G_APPLY_AUTOMATIC_ATCHMT,
8628                  p_requesting_entity_code       => OE_GLOBALS.G_ENTITY_HEADER,
8629                  p_requesting_entity_id         => p_x_header_rec.header_id,
8630                  x_return_status                        => l_return_status
8631                  );
8632           END IF;
8633         END IF;
8634 --6896311
8635 
8636 
8637         -- QUOTING changes
8638 	IF nvl(p_x_header_rec.transaction_phase_code,'F') = 'F'
8639            AND NOT OE_GLOBALS.Equal(p_x_header_rec.order_type_id
8640 				    ,p_old_header_rec.order_type_id)
8641 	THEN
8642 
8643        -- If the Order Type has changed, we need to sync up the
8644        -- MTL_SALES_ORDERS table.
8645 		IF p_x_header_rec.operation = OE_GLOBALS.G_OPR_UPDATE THEN
8646 
8647 		   l_source_code := FND_PROFILE.VALUE('ONT_SOURCE_CODE');
8648                    -- 3817802 : New api Get_Base_Order_Type is used to get order type based on base lang
8649 		   l_new_order_type := Get_Base_Order_Type(p_x_header_rec.order_type_id);
8650 		   l_order_type     := Get_Base_Order_Type(p_old_header_rec.order_type_id);
8651                    IF l_debug_level  > 0 THEN
8652                       oe_debug_pub.add('l_source_code ' || l_source_code,2);
8653                       oe_debug_pub.add('l_new_order_type ' || l_new_order_type,2);
8654                       oe_debug_pub.add('l_order_type ' || l_order_type,2);
8655                    END IF;
8656 			l_return_value :=
8657 						inv_salesorder.synch_salesorders_with_om(
8658 						p_original_order_number  =>
8659 						to_char(p_old_header_rec.order_number),
8660 						p_original_order_type    => l_order_type,
8661 						p_original_source_code   => l_source_code,
8662 						p_new_order_number       =>
8663 						to_char(p_x_header_rec.order_number),
8664 						p_new_order_type         => l_new_order_type,
8665 						p_new_order_source       => l_source_code,
8666 						p_multiple_rows          => 'N');
8667 		     oe_debug_pub.add(' Return Value ' || l_return_value,1);
8668 	    END IF;
8669 
8670 	 END IF;
8671 	--included for the create internal  requisition Spares Management (Ikon) project mshenoy
8672         -- For all Internal Sales Orders (Source Document Type ID = 10 ) and Create ISO Operations
8673         -- log a Delayed Request for the create Internal Requisition
8674         IF p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE AND
8675            p_x_header_rec.Source_Document_Type_id = 10   AND
8676            p_x_header_rec.Source_Document_id is null AND
8677            p_x_header_rec.Orig_sys_document_ref is null THEN
8678 		oe_debug_pub.add('log request to create internal Req for ISO');
8679             OE_delayed_requests_Pvt.Log_Request
8680 		        (p_entity_code 	 => OE_GLOBALS.G_ENTITY_ALL,
8681                  p_entity_id         => p_x_header_rec.header_id,
8682                  p_request_type      => OE_GLOBALS.G_CREATE_INTERNAL_REQ,
8683               	 p_requesting_entity_code 	=> OE_GLOBALS.G_ENTITY_HEADER,
8684                	 p_requesting_entity_id		=> p_x_header_rec.header_id,
8685 		         x_return_status			=> l_return_status );
8686 		oe_debug_pub.add(' Return Status log_request Delayed Requests for Int req ' || l_return_status);
8687 
8688         END IF;
8689 
8690      -- Fix for bug1167537
8691      -- Clear the header record cached by defaulting APIs so that the
8692      -- default values on the line record are obtained from the
8693      -- updated header record
8694      IF p_x_header_rec.operation = OE_GLOBALS.G_OPR_UPDATE THEN
8695            ONT_HEADER_Def_Util.Clear_HEADER_Cache;
8696      END IF;
8697 
8698      -- R12 CC encryption
8699      IF	p_x_header_rec.operation = OE_GLOBALS.G_OPR_UPDATE
8700 	AND	(p_x_header_rec.payment_type_code = 'CREDIT_CARD'
8701                 OR p_old_header_rec.payment_type_code = 'CREDIT_CARD') THEN
8702 
8703         IF (NOT OE_GLOBALS.Is_Same_Credit_Card(p_old_header_rec.credit_card_number,
8704 	    p_x_header_rec.credit_card_number,
8705 	    p_old_header_rec.cc_instrument_id,
8706 	    p_x_header_rec.cc_instrument_id))
8707             OR
8708             (p_x_header_rec.payment_type_code IS NULL AND NOT OE_GLOBALS.Is_Same_Credit_Card(p_old_header_rec.credit_card_number,p_x_header_rec.credit_card_number,p_old_header_rec.cc_instrument_id, NULL))
8709     	THEN
8710 
8711           l_changed_attribute := l_changed_attribute||',' ||'CREDIT_CARD_NUMBER';
8712 
8713                 /**
8714                 IF l_changed_attribute = 'CREDIT_CARD_CODE' THEN
8715                    l_changed_attribute := l_changed_attribute||',' ||'CREDIT_CARD_NUMBER';
8716                 ELSE
8717                    l_changed_attribute := 'CREDIT_CARD_NUMBER';
8718                 END IF;
8719                 **/
8720 
8721 	END IF;
8722 
8723 	IF 	NOT OE_GLOBALS.Equal(p_x_header_rec.credit_card_code,p_old_header_rec.credit_card_code)
8724 	THEN
8725 
8726           l_changed_attribute := l_changed_attribute||',' ||'CREDIT_CARD_CODE';
8727 
8728                 /**
8729                	IF l_changed_attribute = 'CREDIT_CARD_NUMBER' THEN
8730                    l_changed_attribute := l_changed_attribute||',' ||'CREDIT_CARD_CODE';
8731                 ELSE
8732                    l_changed_attribute := 'CREDIT_CARD_CODE';
8733                 END IF;
8734                  **/
8735 
8736 	END IF;
8737 
8738 	IF 	NOT OE_GLOBALS.Equal(p_x_header_rec.credit_card_holder_name,p_old_header_rec.credit_card_holder_name)
8739 	THEN
8740           l_changed_attribute := l_changed_attribute||',' ||'CREDIT_CARD_HOLDER_NAME';
8741 
8742 	END IF;
8743 
8744 	IF 	NOT OE_GLOBALS.Equal(p_x_header_rec.credit_card_expiration_date,p_old_header_rec.credit_card_expiration_date)
8745 	THEN
8746           l_changed_attribute := l_changed_attribute||',' ||'CREDIT_CARD_EXPIRATION_DATE';
8747 
8748 	END IF;
8749 		oe_debug_pub.add('changed attr is: '||l_changed_attribute, 3);
8750       END IF;
8751 
8752      -- Bug 1755817: clear the cached constraint results for header entity
8753      -- when order header is updated.
8754      OE_PC_Constraints_Admin_Pvt.Clear_Cached_Results
8755           (p_validation_entity_id => OE_PC_GLOBALS.G_ENTITY_HEADER);
8756 
8757        --11.5.10 Versioning/Audit Trail updates
8758      IF OE_CODE_CONTROL.CODE_RELEASE_LEVEL >= '110510' AND
8759          OE_GLOBALS.G_ROLL_VERSION <> 'N' THEN
8760        IF OE_GLOBALS.G_REASON_CODE IS NULL AND
8761            OE_GLOBALS.G_CAPTURED_REASON IN ('V','A') THEN
8762           IF p_x_header_rec.change_reason <> FND_API.G_MISS_CHAR THEN
8763               OE_GLOBALS.G_REASON_CODE := p_x_header_rec.change_reason;
8764               OE_GLOBALS.G_REASON_COMMENTS := p_x_header_rec.change_comments;
8765               OE_GLOBALS.G_CAPTURED_REASON := 'Y';
8766           ELSE
8767               OE_DEBUG_PUB.add('Reason code for versioning is missing', 1);
8768               if OE_GLOBALS.G_UI_FLAG THEN
8769                  raise FND_API.G_EXC_ERROR;
8770               end if;
8771           END IF;
8772        END IF;
8773 
8774        --log delayed request
8775         oe_debug_pub.add('log versioning request',1);
8776           OE_Delayed_Requests_Pvt.Log_Request(p_entity_code => OE_GLOBALS.G_ENTITY_ALL,
8777                                    p_entity_id => p_x_header_rec.header_id,
8778                                    p_requesting_entity_code => OE_GLOBALS.G_ENTITY_HEADER,
8779                                    p_requesting_entity_id => p_x_header_rec.header_id,
8780                                    p_request_type => OE_GLOBALS.G_VERSION_AUDIT,
8781                                    p_param1	  => l_changed_attribute,
8782                                    x_return_status => l_return_status);
8783      END IF;
8784 
8785      IF OE_GLOBALS.G_AUDIT_REASON_RQD_FLAG = 'Y' OR
8786 	   OE_GLOBALS.G_AUDIT_HISTORY_RQD_FLAG = 'Y' THEN
8787           OE_DEBUG_PUB.add('Call oe_order_chg_pvt to record Header Audit History',5);
8788 
8789        --11.5.10 Versioning/Audit Trail updates
8790        IF OE_CODE_CONTROL.CODE_RELEASE_LEVEL >= '110510' THEN
8791           OE_Versioning_Util.Capture_Audit_Info(p_entity_code => OE_GLOBALS.G_ENTITY_HEADER,
8792                                            p_entity_id => p_x_header_rec.header_id,
8793                                            p_hist_type_code =>  'UPDATE');
8794            --log delayed request
8795              OE_Delayed_Requests_Pvt.Log_Request(p_entity_code => OE_GLOBALS.G_ENTITY_ALL,
8796                                    p_entity_id => p_x_header_rec.header_id,
8797                                    p_requesting_entity_code => OE_GLOBALS.G_ENTITY_HEADER,
8798                                    p_requesting_entity_id => p_x_header_rec.header_id,
8799                                    p_request_type => OE_GLOBALS.G_VERSION_AUDIT,
8800                                    p_param1	  => l_changed_attribute,
8801                                    x_return_status => l_return_status);
8802           OE_GLOBALS.G_AUDIT_HISTORY_RQD_FLAG := 'N';
8803        ELSE
8804           OE_CHG_ORDER_PVT.RecordHeaderHist
8805               ( p_header_id => p_x_header_rec.header_id,
8806                 p_header_rec => null,
8807                 p_hist_type_code => 'UPDATE',
8808                 p_reason_code => p_x_header_rec.change_reason,
8809                 p_comments => p_x_header_rec.change_comments,
8810                 p_wf_activity_code => null,
8811                 p_wf_result_code => null,
8812                 x_return_status => l_return_status
8813               );
8814 
8815           if l_return_status <> FND_API.G_RET_STS_SUCCESS then
8816 	        oe_debug_pub.add('Inserting Header History Caused Error ',1);
8817              if l_return_status = FND_API.G_RET_STS_ERROR then
8818                 raise FND_API.G_EXC_ERROR;
8819              else
8820                 raise FND_API.G_EXC_UNEXPECTED_ERROR;
8821              end if;
8822           end if;
8823        END IF;
8824      END IF;
8825 
8826      -- QUOTING changes
8827      -- Initialize flow status to DRAFT or ENTERED dependening on transaction phase
8828      IF p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE THEN
8829 
8830         IF nvl(p_x_header_rec.transaction_phase_code,'F') = 'F' THEN
8831            /*
8832            ** Fix Bug # 3484862: iStore will be sending flow status as WORKING
8833            ** for RMAs created with Return for Submission with Approval Flow.
8834            */
8835            IF p_x_header_rec.flow_status_code = 'WORKING' THEN
8836              null;
8837            ELSE
8838              p_x_header_rec.flow_status_code := 'ENTERED';
8839            END IF;
8840         ELSIF p_x_header_rec.transaction_phase_code = 'N' THEN
8841            p_x_header_rec.flow_status_code := 'DRAFT';
8842         END IF;
8843 
8844      END IF; -- if operation CREATE
8845 
8846      --For bug 3563983. Logging REquest for updaet of Blanekt fields.
8847      --Moved this logic from post-write process.
8848      --Log request for deletes AND for update of currency
8849 
8850       IF OE_CODE_CONTROL.Get_Code_Release_Level >= '110509'
8851       AND NVL(p_x_header_rec.transaction_phase_code,'F') = 'F'
8852       AND (p_x_header_rec.operation = OE_GLOBALS.G_OPR_DELETE OR
8853            (p_x_header_rec.operation = OE_GLOBALS.G_OPR_UPDATE
8854            AND NOT OE_GLOBALS.EQUAL(p_x_header_rec.transactional_curr_code
8855                                  ,p_old_header_rec.transactional_curr_code)))
8856       THEN
8857           Blkt_Req_For_Curr_Upd_And_Del(p_x_header_rec,p_old_header_rec);
8858       END IF;
8859 
8860 
8861       oe_debug_pub.add('Exiting OR_HEADER_UTIL.Pre_Write_Process',1);
8862 
8863 EXCEPTION
8864 -- included to fix bug 1589196    Begin
8865     WHEN FND_API.G_EXC_ERROR THEN
8866 
8867      OE_SALES_CAN_UTIL.G_IR_ISO_HDR_CANCEL := FALSE;
8868      -- Adding this for IR ISO Tracking bug 7667702
8869 
8870      RAISE FND_API.G_EXC_ERROR;
8871 -- included to fix bug 1589196    End
8872 
8873     WHEN OTHERS THEN
8874 
8875         OE_SALES_CAN_UTIL.G_IR_ISO_HDR_CANCEL := FALSE;
8876         -- Adding this for IR ISO Tracking bug 7667702
8877 
8878         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
8879         THEN
8880             OE_MSG_PUB.Add_Exc_Msg
8881             (   G_PKG_NAME
8882             ,   'Pre_Write_Process'
8883             );
8884         END IF;
8885 		p_x_header_rec.return_status := FND_API.G_RET_STS_ERROR;
8886 
8887         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8888 
8889 
8890 End Pre_Write_Process;
8891 
8892 PROCEDURE Post_Write_Process
8893          ( p_x_header_rec 	IN OUT NOCOPY  oe_order_pub.header_rec_type,
8894            p_old_header_rec    IN oe_order_pub.header_rec_type )
8895 IS
8896 	l_return_status                VARCHAR2(30);
8897         l_msg_count        NUMBER;
8898         l_msg_data         VARCHAR2(2000);
8899 
8900 	l_control_rec                  OE_GLOBALS.Control_Rec_Type;
8901 	l_old_line_tbl                 OE_Order_PUB.Line_Tbl_Type;
8902 	l_line_tbl                     OE_Order_PUB.Line_Tbl_Type;
8903         l_recursion_mode               VARCHAR2(1);
8904         l_operation                    VARCHAR2(30);
8905 	--R12 CC Encryption
8906 	l_x_Header_Payment_tbl		OE_ORDER_PUB.Header_Payment_tbl_type;
8907 	l_x_old_Header_Payment_tbl	OE_ORDER_PUB.Header_Payment_tbl_type;
8908 	l_payment_exists		VARCHAR2(1) := 'N';
8909 	l_payment_number                NUMBER;
8910 	l_old_payment_type_code		VARCHAR2(30) := NULL;
8911 	--R12 CC Encryption
8912 	l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
8913 	--bug 5258767
8914 	l_payment_term_id	        NUMBER;
8915 	l_prepayment_flag		VARCHAR2(1) := NULL;
8916 	l_prepay_count			NUMBER := 0;
8917 	l_currency_code			VARCHAR2(30) := NULL;
8918 	l_subtotal number;
8919 	l_discount number;
8920 	l_charges number;
8921 	l_tax number;
8922 	L_ORDER_TOTAL number;
8923 	L_DOWNPAYMENT number;
8924 	l_line_payment_count NUMBER;
8925 	--bug 5258767
8926 BEGIN
8927 	oe_debug_pub.add('Entering OE_HEADER_UTIL.Post_Write_Process',1);
8928 
8929      -- Added call to new procedure eval_post_write_header for performance
8930      -- and to be consistent with evalualte_post_write for lines.
8931      -- See bug#1777317
8932      -- QUOTING changes - moved this call within another create loop
8933      -- later as holds should be applied only to orders in fulfillment phase.
8934 
8935      --Fix bug 1649402
8936      OE_DELAYED_REQUESTS_PVT.Process_Request_for_ReqType
8937                                (p_request_type => OE_GLOBALS.G_DFLT_HSCREDIT_FOR_SREP
8938                                ,p_delete       => FND_API.G_TRUE
8939                                ,x_return_status=> l_return_status
8940                                );
8941      IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
8942        RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8943      ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
8944        RAISE FND_API.G_EXC_ERROR;
8945      END IF;
8946 
8947      -- QUOTING changes - moved this call within another create loop
8948      -- later as mtl_sales_order records should be created only for
8949      -- orders in fulfillment phase.
8950 
8951      -- QUOTING changes
8952      IF p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
8953         OR (OE_Quote_Util.G_COMPLETE_NEG = 'Y'
8954 	    AND NOT OE_GLOBALS.EQUAL(p_x_header_rec.transaction_phase_code,
8955 				 p_old_header_rec.transaction_phase_code)
8956             )
8957      THEN
8958 
8959        -- Fulfillment phase specific actions - holds,
8960        -- MTL entry and fulfillment WF start
8961        IF nvl(p_x_header_rec.transaction_phase_code,'F') = 'F' THEN
8962 
8963         -- Added call to new procedure eval_post_write_header for performance
8964         -- and to be consistent with evalualte_post_write for lines.
8965         -- See bug#1777317
8966 
8967 /*ER#7479609
8968         oe_debug_pub.add('Before calling eval_post_write_header in HEADER Post Write',1);
8969 
8970         OE_HOLDS_PUB.eval_post_write_header
8971                        ( p_entity_code      => OE_GLOBALS.G_ENTITY_HEADER
8972                         ,p_entity_id        => p_x_header_rec.header_id
8973                         ,p_hold_entity_code => 'C'
8974                         ,p_hold_entity_id   => p_x_header_rec.sold_to_org_id
8975                         ,x_return_status    => l_return_status
8976                         ,x_msg_count        => l_msg_count
8977                         ,x_msg_data         => l_msg_data );
8978 
8979 
8980 
8981         IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
8982           RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8983         ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
8984           RAISE FND_API.G_EXC_ERROR;
8985         END IF;
8986 
8987         oe_debug_pub.add('After calling eval_post_write_header in HEADER Post Write',1);
8988 ER#7479609*/
8989 
8990 --ER#7479609 start
8991     if l_debug_level > 0 then
8992      oe_debug_pub.add('Call evaluate_holds_post_write for CREATE');
8993     end if;
8994      OE_Holds_PUB.evaluate_holds_post_write
8995       (p_entity_code => OE_GLOBALS.G_ENTITY_HEADER
8996       ,p_entity_id => p_x_header_rec.header_id
8997       ,x_msg_count => l_msg_count
8998       ,x_msg_data => l_msg_data
8999       ,x_return_status => l_return_status
9000       );
9001 
9002          IF l_return_status = FND_API.G_RET_STS_ERROR THEN
9003             RAISE FND_API.G_EXC_ERROR;
9004          ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
9005             RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9006          END IF;
9007 
9008     if l_debug_level > 0 then
9009       oe_debug_pub.add('After evaluate_holds_post_write in Header Post Write');
9010     end if;
9011 --ER#7479609 end
9012 
9013          --  Create record in the MTL_SALES_ORDERS table
9014 
9015            oe_debug_pub.add('Before calling OE_SCHEDULE_UTIL',3);
9016            OE_SCHEDULE_UTIL.Insert_into_mtl_sales_orders(p_x_header_rec);
9017 
9018          -- Create and Start the Header level Workflow
9019 
9020           OE_Order_WF_Util.CreateStart_HdrProcess(p_x_header_rec);
9021 
9022        -- Negotiation phase specific actions - negotiation WF start
9023        ELSE
9024 
9025           -- Sam to provide this API
9026           OE_Order_WF_Util.CreateStart_HdrInternal
9027                   (p_item_type => 'OENH'
9028                   ,p_header_id => p_x_header_rec.header_id
9029                   ,p_transaction_number => p_x_header_rec.quote_number
9030                   ,p_sales_document_type_code => 'O'
9031                   );
9032           NULL;
9033 
9034        END IF;
9035 
9036        -- Check if the lock_control has changed, it would if there
9037        -- were updates due to synchronous activities like booking in
9038        -- the header flow. If yes, refresh the header record
9039 
9040        OE_Order_Cache.Load_Order_Header(p_x_header_rec.header_id);
9041        oe_debug_pub.add('DB lock control :'||
9042                          OE_Order_Cache.g_header_rec.lock_control);
9043 
9044        IF OE_Order_Cache.g_header_rec.lock_control
9045          <> p_x_header_rec.lock_control
9046        THEN
9047           l_operation := p_x_header_rec.operation;
9048           p_x_header_rec := OE_Order_Cache.g_header_rec;
9049           p_x_header_rec.operation := l_operation;
9050           OE_GLOBALS.G_CASCADING_REQUEST_LOGGED := TRUE;
9051        END IF;
9052 
9053      END IF; -- END for check if CREATE operation
9054      -- QUOTING changes END
9055 
9056      -- Close the order if its a complet cancellation at the line and
9057      -- is indeed a cancellation (by constraints)
9058       IF p_x_header_rec.operation = OE_GLOBALS.G_OPR_UPDATE THEN
9059           IF oe_sales_can_util.g_order_cancel AND
9060               p_x_header_rec.cancelled_flag = 'Y' AND -- (p_old_header_rec.cancelled_flag <> 'Y') --7142748
9061 	      p_x_header_rec.cancelled_flag <> NVL(p_old_header_rec.cancelled_flag,'N') THEN -- Bug 9241924
9062           -- Bug 1895144: set recursion mode so that close does
9063           -- not execute any delayed requests
9064           BEGIN
9065           l_recursion_mode := OE_GLOBALS.G_RECURSION_MODE;
9066           -- OE_GLOBALS.G_RECURSION_MODE := 'Y';
9067 
9068 -- Log a request to cancel the workflow.
9069 /*
9070 -- commented to take care of P1 issues in configuration
9071 
9072 	OE_delayed_requests_Pvt.log_request
9073 	(p_entity_code				=> OE_GLOBALS.G_ENTITY_ALL,
9074 	p_entity_id				=> p_x_header_rec.header_id,
9075 	p_requesting_entity_code	=> OE_GLOBALS.G_ENTITY_ALL,
9076 	p_requesting_entity_id		=> p_x_header_rec.header_id,
9077 	p_request_type      		=> OE_GLOBALS.G_CANCEL_WF,
9078 	p_param1                 => OE_GLOBALS.G_ENTITY_HEADER,
9079 	x_return_status				=> l_return_status);
9080 */
9081 
9082 -- Commented the code to move the logic to delayed request
9083 -- Uncommented to take care of P1 configuration issues
9084           wf_engine.handleerror(OE_Globals.G_WFI_HDR
9085                     ,to_char(p_x_header_rec.header_id)
9086                     ,'CLOSE_HEADER',
9087                     'RETRY','CANCEL');
9088 
9089           -- OE_GLOBALS.G_RECURSION_MODE := l_recursion_mode;
9090           -- BUG 2013611 - Increment promotional balance in response to cancellation
9091           oe_debug_pub.add('log request to Reverse_Limits for CANCEL in HEADER Post Write',1);
9092           OE_delayed_requests_Pvt.log_request(
9093 			p_entity_code 		 => OE_GLOBALS.G_ENTITY_HEADER,
9094 			p_entity_id              => p_x_header_rec.header_id,
9095 			p_requesting_entity_code => OE_GLOBALS.G_ENTITY_HEADER,
9096 			p_requesting_entity_id   => p_x_header_rec.header_id,
9097 			p_request_unique_key1  	 => 'HEADER',
9098 		 	p_param1                 => 'CANCEL',
9099 	 		p_param2                 => p_x_header_rec.price_request_code,
9100 		 	p_param3                 => NULL,
9101 		 	p_param4                 => NULL,
9102 		 	p_param5                 => NULL,
9103 		 	p_param6                 => NULL,
9104 	 		p_request_type           => OE_GLOBALS.G_REVERSE_LIMITS,
9105 	 		x_return_status          => l_return_status);
9106           oe_debug_pub.add('Request to Reverse_Limits in HEADER Post Write is done',1);
9107           -- BUG 2013611 End
9108           EXCEPTION
9109             WHEN OTHERS THEN
9110                  -- OE_GLOBALS.G_RECURSION_MODE := l_recursion_mode;
9111                  RAISE;
9112           END;
9113           END IF;
9114       END IF;
9115           oe_sales_can_util.g_order_cancel := FALSE;
9116 
9117 
9118      ----------------------------------------------------------------
9119 	-- Update the customer on the order lines if changed on the
9120 	-- order header
9121      ----------------------------------------------------------------
9122      IF p_x_header_rec.operation = OE_GLOBALS.G_OPR_UPDATE
9123 	   AND NOT OE_GLOBALS.EQUAL( p_x_header_rec.sold_to_org_id,
9124 						    p_old_header_rec.sold_to_org_id )
9125      THEN
9126 
9127        OE_Line_Util.Query_Rows
9128 		( p_header_id => p_x_header_rec.header_id
9129 	     , x_line_tbl  => l_old_line_tbl );
9130 
9131        IF l_old_line_tbl.COUNT = 0 THEN
9132 		RETURN;
9133        END IF;
9134 
9135         ------Added by CKASERA bug 14763723
9136           IF(l_debug_level>0) THEN
9137             oe_debug_pub.ADD('14763723 Rasing the XML Event for Header before line processing');
9138           END IF;
9139 
9140            OE_DELAYED_REQUESTS_PVT.Process_Request_for_Reqtype
9141            (p_request_type   =>OE_GLOBALS.G_GENERATE_XML_REQ_HDR
9142            ,p_delete        => FND_API.G_TRUE
9143            ,x_return_status => l_return_status
9144            );
9145            IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
9146                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9147            ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
9148                  RAISE FND_API.G_EXC_ERROR;
9149            END IF;
9150          ---End CKASERA bug 14763723
9151 
9152        l_line_tbl := l_old_line_tbl;
9153        FOR I IN 1..l_line_tbl.COUNT LOOP
9154         -- IF condition added for bug 5471580
9155           IF nvl(l_line_tbl(I).cancelled_flag, 'N') = 'N' THEN
9156 		l_line_tbl(I).sold_to_org_id   := p_x_header_rec.sold_to_org_id;
9157 		l_line_tbl(I).operation        := OE_GLOBALS.G_OPR_UPDATE;
9158 	  ELSE
9159                 l_line_tbl(I).operation        := OE_GLOBALS.G_OPR_NONE;
9160           END IF;
9161        END LOOP;
9162 
9163        l_control_rec.controlled_operation := TRUE;
9164 	  l_control_rec.clear_dependents := TRUE;
9165 	  l_control_rec.default_attributes := TRUE;
9166 	  l_control_rec.check_security := TRUE;
9167 	  l_control_rec.change_attributes := TRUE;
9168 	  l_control_rec.validate_entity := TRUE;
9169 	  l_control_rec.write_to_db := TRUE;
9170 	  l_control_rec.process := FALSE;
9171 
9172        -- OE_GLOBALS.G_RECURSION_MODE := 'Y';
9173 	 -- SAVEPOINT added for Bug 12759791
9174           SAVEPOINT LINES_IN_HPOST_WRITE   ;
9175           OE_HEADER_UTIL.g_rollback_done := 'N';
9176 
9177 	  OE_Order_PVT.Lines
9178 	     ( p_validation_level      => FND_API.G_VALID_LEVEL_NONE
9179 	     , p_control_rec           => l_control_rec
9180           , p_x_line_tbl            => l_line_tbl
9181 		, p_x_old_line_tbl        => l_old_line_tbl
9182 		, x_return_status         => l_return_status
9183 		);
9184 
9185        -- OE_GLOBALS.G_RECURSION_MODE := 'N';
9186 
9187        IF l_return_status = FND_API.G_RET_STS_ERROR THEN
9188 		ROLLBACK TO SAVEPOINT  LINES_IN_HPOST_WRITE;  -- Bug 12759791
9189                 OE_HEADER_UTIL.g_rollback_done := 'Y';          -- Bug 12759791
9190 		RAISE FND_API.G_EXC_ERROR;
9191        ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
9192 		RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9193        END IF;
9194 
9195   -- commented out for notification framework
9196      /*  OE_Order_PVT.Process_Requests_And_Notify
9197 		( p_process_requests       => FALSE
9198 		, p_notify                 => TRUE
9199 		, p_line_tbl               => l_line_tbl
9200 		, p_old_line_tbl           => l_old_line_tbl
9201 		, x_return_status          => l_return_status
9202 		);
9203 
9204        IF l_return_status = FND_API.G_RET_STS_ERROR THEN
9205 		RAISE FND_API.G_EXC_ERROR;
9206        ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
9207 		RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9208        END IF;
9209      */
9210        OE_GLOBALS.G_CASCADING_REQUEST_LOGGED := TRUE;
9211 
9212      END IF;
9213 
9214      --For bug 3563983. Commented this code and moved this logic to pre-write process.
9215      --Line data will not be available for delete operation and this stage.
9216 /*     IF OE_CODE_CONTROL.Get_Code_Release_Level >= '110509'
9217         AND p_x_header_rec.operation = OE_GLOBALS.G_OPR_UPDATE
9218         AND NOT OE_GLOBALS.EQUAL(p_x_header_rec.transactional_curr_code
9219                                  ,p_old_header_rec.transactional_curr_code)
9220         -- QUOTING changes
9221         AND NVL(p_x_header_rec.transaction_phase_code,'F') = 'F'
9222      THEN
9223 
9224         Blanket_Req_For_Curr_Update(p_x_header_rec,p_old_header_rec);
9225 
9226      END IF;*/
9227 
9228      -- QUOTING changes
9229      IF p_x_header_rec.operation = OE_GLOBALS.G_OPR_UPDATE
9230         AND p_x_header_rec.transaction_phase_code = 'N'
9231         AND NOT OE_GLOBALS.EQUAL(p_x_header_rec.expiration_date
9232                                  ,p_old_header_rec.expiration_date)
9233      THEN
9234 
9235          -- Call WF API to re-set expiration date timer
9236          OE_Negotiate_WF.Offer_Date_Changed
9237                  (p_header_id => p_x_header_rec.header_id
9238                  ,x_return_status => l_return_status
9239                  );
9240 
9241          IF l_return_status = FND_API.G_RET_STS_ERROR THEN
9242 		RAISE FND_API.G_EXC_ERROR;
9243          ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
9244 		RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9245          END IF;
9246 
9247      END IF;
9248 
9249     -- Sales Contract changes.
9250     -- Instantiate the contract template for the sales order for create
9251     -- operation.
9252 
9253      IF p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE AND
9254         OE_CODE_CONTROL.Get_Code_Release_Level >= '110510' AND
9255         -- Do not instantiate for copied orders
9256         nvl(p_x_header_rec.source_document_type_id,-1) <> 2 AND
9257         (p_x_header_rec.contract_template_id IS NOT NULL OR
9258 	p_x_header_rec.contract_source_doc_type_code IS NOT NULL OR
9259 	p_x_header_rec.contract_source_document_id IS NOT NULL)
9260         THEN
9261 
9262 	IF  p_x_header_rec.contract_source_doc_type_code IS NOT NULL AND
9263 	    p_x_header_rec.Contract_Template_Id IS NULL AND
9264 	    p_x_header_rec.contract_source_document_id IS NULL THEN
9265             fnd_message.set_name('ONT','OE_INVALID_CONTRACT_ATTR_COMB');
9266             OE_MSG_PUB.Add;
9267 	END IF;
9268 
9269 	OE_CONTRACTS_UTIL.Copy_Doc(
9270        		p_api_version  		=> 1.0,
9271       		p_init_msg_list 	=> FND_API.G_FALSE,
9272   		p_commit      		=> FND_API.G_FALSE,
9273   		p_source_doc_type 	=> p_x_header_rec.contract_source_doc_type_code,
9274                	p_source_doc_id 	=> p_x_header_rec.contract_source_document_id,
9275                 p_target_doc_type 	=> 'O',
9276                 p_target_doc_id 	=> p_x_header_rec.header_id,
9277           	p_contract_template_id  => p_x_header_rec.contract_template_id,
9278                 x_return_status	 	=> l_return_status,
9279                 x_msg_count     	=> l_msg_count,
9280                 x_msg_data      	=> l_msg_data
9281 		);
9282 
9283          IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
9284               if l_debug_level > 0 then
9285                  oe_debug_pub.ADD('OE_Header_Util.Post_Write unexp error in instantiate doc terms',1);
9286               end if;
9287               RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9288          ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
9289               if l_debug_level > 0 then
9290                  oe_debug_pub.ADD('OE_Header_Util.Post_Write exp error in instantiate doc terms',1);
9291               end if;
9292               RAISE FND_API.G_EXC_ERROR;
9293          END IF;
9294 
9295       END IF;
9296       oe_debug_pub.add('Post Write Process R12 CCE changes...'||p_x_header_rec.header_id);
9297       oe_debug_pub.add('Old header id'||p_old_header_rec.header_id);
9298       oe_debug_pub.add('payment type'||p_x_header_rec.payment_type_code);
9299       --oe_debug_pub.add('card number'||p_x_header_rec.credit_Card_number);
9300       --If Bill to site is changed, then the payment record would
9301       --be deleted through the delayed request. So not calling
9302       --the process order if bill to site has changed.
9303       --bug 4885313
9304       IF NOT OE_GLOBALS.Equal(p_x_header_rec.invoice_to_org_id,p_old_header_rec.invoice_to_org_id)
9305       THEN
9306 	    --If the user has modified the bill to site and has entered a new
9307 	    --credit card before saving the record, then the global flag need
9308 	    --to be set to Y so that the current trxn extension id would be
9309 	    --deleted and a new one created (as the context has changed).
9310 	    oe_debug_pub.add('Old invoice to'||p_x_header_rec.invoice_to_org_id);
9311 	    oe_debug_pub.add('New invoice to'||p_old_header_rec.invoice_to_org_id);
9312 	    IF NOT OE_GLOBALS.Equal(p_old_header_rec.invoice_to_org_id,FND_API.G_MISS_NUM)
9313 	    AND p_old_header_rec.invoice_to_org_id IS NOT NULL AND
9314 	    p_x_header_rec.payment_type_code = 'CREDIT_CARD' THEN
9315 		    OE_Payment_Trxn_Util.g_old_bill_to_site := p_old_header_rec.invoice_to_org_id;
9316 	    END IF;
9317 	    oe_debug_pub.add('Bill to site changed in post_write_process'||OE_Payment_Trxn_Util.g_old_bill_to_site);
9318       END IF;
9319 
9320 	oe_debug_pub.add('Operatoin in post write...in header rec..'||p_x_header_rec.operation);
9321 
9322         --R12 CC Encryption
9323 	--As ACH and Direct Debit are not supported in Order Header Others tab
9324 	--only Credit card payment type code is checked here.
9325 	--Moreover, when  the old payment type code is credit card, then need
9326 	--to delete the trxn extension id created for this creditcard
9327 	--When the old payment type is not null and the new one is null then
9328 	--need to delete the payment record from oe_payments.
9329 	IF(  ( OE_GLOBALS.Equal(p_x_header_rec.payment_type_code, 'CREDIT_CARD') AND
9330 	       p_x_header_rec.credit_card_number is not null
9331 	      )
9332 	   OR (
9333 	        OE_GLOBALS.Equal(p_old_header_rec.payment_type_code,'CREDIT_CARD')
9334 	      )
9335 	   OR ( p_old_header_rec.payment_type_code IS NOT NULL AND
9336 	        p_x_header_rec.payment_type_code IS NULL
9337 	      ))
9338 	 AND --For copy orders, the CREATE operation need not call process order here
9339 	 (   --as the payment record would be inserted from oe_header_payment_util package.
9340 	     nvl(p_x_header_rec.source_document_type_id,-99) <> 2  OR
9341 	       ( --To create or update credit cards on copied orders
9342 	         nvl(p_x_header_rec.source_document_type_id,-99)=2 AND
9343 		 p_x_header_rec.operation=OE_GLOBALS.G_OPR_UPDATE
9344 	       )
9345 	  )
9346           AND p_x_header_rec.operation <> OE_GLOBALS.G_OPR_DELETE   --10113279
9347 
9348 	THEN
9349 	BEGIN
9350 		--For update operation, payment number needs to be set in
9351 		--the payment record type as otherwise the process order
9352 		--call was failing in Query_row procedure during update operation
9353 		SELECT 'Y',payment_number,payment_type_code
9354 		INTO l_payment_exists,l_payment_number,l_old_payment_type_code
9355 		FROM oe_payments
9356 		WHERE header_id = p_x_header_rec.header_id
9357 		and line_id is null
9358 		AND nvl(PAYMENT_COLLECTION_EVENT,'PREPAY') = 'INVOICE';
9359 
9360 	EXCEPTION
9361 	WHEN NO_DATA_FOUND THEN
9362 		l_payment_exists := 'N';
9363 	END;
9364 
9365 		l_control_rec.controlled_operation := TRUE;
9366 		l_control_rec.check_security       := TRUE;
9367 		l_control_rec.default_attributes   := TRUE;
9368 		l_control_rec.change_attributes    := TRUE;
9369 	    	--l_control_rec.clear_dependents     := FALSE;
9370 	    	l_control_rec.clear_dependents     := TRUE; -- bug 9200306
9371 		l_control_rec.validate_entity      := FALSE;
9372 		l_control_rec.write_to_DB          := TRUE;   --Verify
9373 		l_control_rec.process              := FALSE;
9374 	        l_control_rec.clear_api_cache      := FALSE;
9375 	   	l_control_rec.clear_api_requests   := FALSE;
9376 
9377 		l_x_Header_Payment_tbl(1):=OE_ORDER_PUB.G_MISS_HEADER_PAYMENT_REC;
9378 	    	l_x_old_Header_Payment_Tbl(1):=OE_ORDER_PUB.G_MISS_HEADER_PAYMENT_REC;
9379 
9380 	    	l_x_Header_Payment_tbl(1).header_id := p_x_header_rec.header_id;
9381 	    	l_x_Header_Payment_tbl(1).payment_collection_event := 'INVOICE';
9382 	    	l_x_Header_Payment_tbl(1).payment_level_code := 'ORDER';
9383 		l_x_Header_Payment_tbl(1).credit_card_number := p_x_header_rec.credit_card_number;
9384 		l_x_Header_Payment_tbl(1).credit_card_code := p_x_header_rec.credit_card_code;
9385 		l_x_Header_Payment_tbl(1).credit_card_holder_name := p_x_header_rec.credit_card_holder_name;
9386 		l_x_Header_Payment_tbl(1).credit_card_expiration_date := p_x_header_rec.credit_card_expiration_date;
9387 		l_x_Header_Payment_tbl(1).credit_card_approval_code := p_x_header_rec.credit_card_approval_code;
9388 		l_x_Header_Payment_tbl(1).credit_card_approval_date := p_x_header_rec.credit_card_approval_date;
9389 		l_x_Header_Payment_tbl(1).payment_type_code := p_x_header_rec.payment_type_code;
9390 		l_x_Header_Payment_tbl(1).CC_INSTRUMENT_ID := p_x_header_rec.CC_INSTRUMENT_ID;
9391 		l_x_Header_Payment_tbl(1).CC_INSTRUMENT_ASSIGNMENT_ID := p_x_header_rec.CC_INSTRUMENT_ASSIGNMENT_ID;
9392 		l_x_Header_Payment_tbl(1).instrument_security_code := p_x_header_rec.instrument_security_code;
9393 		l_x_Header_Payment_tbl(1).payment_number := l_payment_number;
9394 		l_x_Header_Payment_tbl(1).check_number := p_x_header_rec.check_number;
9395 	        oe_debug_pub.add('Old payment type'||l_old_payment_type_code);
9396 	        oe_debug_pub.add('New payment type'||p_x_header_rec.payment_type_code);
9397 		oe_debug_pub.add('Header_id'||p_x_header_rec.header_id);
9398 	        /*IF NOT OE_GLOBALS.Equal(l_old_payment_type_code,p_x_header_rec.payment_type_code) THEN
9399 			oe_debug_pub.add('ksurendr: Receipt method id in uhdrb post write'||l_x_Header_Payment_tbl(1).receipt_method_id);
9400 			l_x_Header_Payment_tbl(1).receipt_method_id := FND_API.G_MISS_NUM;
9401 	        END IF;*/
9402 
9403 		--Verify
9404 		IF l_payment_exists = 'Y' THEN
9405 			--If the old payment type code is not null and the new payment type code
9406 			--is null, then the payment record has been cleared by the user from the
9407 			--Others tab and hence it is required to delete this record from oe_payments.
9408 			IF l_old_payment_type_code IS NOT NULL
9409 			AND p_x_header_rec.payment_type_code IS NULL THEN
9410 				l_x_Header_Payment_tbl(1).operation := OE_GLOBALS.G_OPR_DELETE;
9411                         -- bug 5035651
9412 			ELSIF nvl(p_x_header_rec.cancelled_flag, 'N') <> 'Y' THEN
9413 				l_x_Header_Payment_tbl(1).operation := OE_GLOBALS.G_OPR_UPDATE;
9414 			ELSE
9415 				l_x_Header_Payment_tbl(1).operation := NULL;
9416 			END IF;
9417 
9418                         /*
9419 			ELSE
9420 				l_x_Header_Payment_tbl(1).operation := OE_GLOBALS.G_OPR_UPDATE;
9421 			END IF;
9422                         */
9423 		ELSE
9424 			l_x_Header_Payment_tbl(1).operation := OE_GLOBALS.G_OPR_CREATE;
9425 
9426 			--bug 5258767
9427 			--Only credit card payment types have the pre-payment records inserted
9428 			--from this procedure. The other payment types are taken care by the
9429 			--procedure Update_Hdr_Payment in Oe_Prepayment_Pvt.
9430 			IF OE_GLOBALS.Equal(p_x_header_rec.payment_type_code, 'CREDIT_CARD') THEN
9431 				--Need to check if the payment term present in the header
9432 				--has the prepayment check box checked so as to insert the
9433 				--prepayment record as well if the other conditions are
9434 				--satisfied.
9435 				BEGIN
9436 					SELECT PAYMENT_TERM_ID,TRANSACTIONAL_CURR_CODE
9437 					INTO l_payment_term_id,l_currency_code
9438 					FROM OE_ORDER_HEADERS_ALL
9439 					WHERE HEADER_ID = p_x_header_rec.header_id;
9440 				EXCEPTION
9441 				WHEN NO_DATA_FOUND THEN
9442 					l_payment_term_id := NULL;
9443 				END;
9444 				IF l_debug_level > 0 THEN
9445 					oe_debug_pub.add('OEXUHDRB post write: term id : ' || l_payment_term_id);
9446 				END IF;
9447 
9448 				if l_payment_term_id is not null then
9449 					l_prepayment_flag := AR_PUBLIC_UTILS.Check_Prepay_Payment_Term(l_payment_term_id);
9450 					IF l_debug_level > 0 THEN
9451 						oe_debug_pub.add('prepayment_flag is : ' || l_prepayment_flag );
9452 					END IF;
9453 				end if;
9454 
9455 				IF nvl(l_prepayment_flag,'N') = 'Y' THEN
9456 					--Checking the count for prepayments and not inserting
9457 					--the prepayment record if there is an existing prepayment
9458 					--for this header.
9459 					BEGIN
9460 						SELECT count(*) INTO l_prepay_count
9461 						FROM OE_PAYMENTS
9462 						WHERE HEADER_ID = p_x_header_rec.header_id
9463 						AND LINE_ID IS NULL AND
9464 						NVL(PAYMENT_COLLECTION_EVENT,'PREPAY') = 'PREPAY';
9465 					EXCEPTION
9466 					WHEN NO_DATA_FOUND THEN
9467 						l_prepay_count := 0;
9468 					END;
9469 
9470 					IF l_debug_level > 0 THEN
9471 						oe_debug_pub.add('OEXUHDRB post write: prepayment count...'||l_prepay_count);
9472 					END IF;
9473 
9474 					--Since prepayments should not be allowed when there are line
9475 					--payments, checking the line payments count before calling the
9476 					--process order for inserting the prepayments.
9477 					BEGIN
9478 						SELECT COUNT(PAYMENT_TYPE_CODE) INTO l_line_payment_count
9479 						FROM OE_PAYMENTS
9480 						WHERE HEADER_ID = p_x_header_rec.header_id
9481 						AND LINE_ID IS NOT NULL
9482 						AND PAYMENT_TYPE_CODE <> 'COMMITMENT';
9483 					EXCEPTION
9484 					WHEN NO_DATA_FOUND THEN
9485 						l_line_payment_count := 0;
9486 					END;
9487 
9488 					IF l_debug_level > 0 THEN
9489 						oe_debug_pub.add('OEXUHDRB post write: line payment count...'||l_line_payment_count);
9490 					END IF;
9491 
9492 					--If prepayment count is zero, then need to insert an
9493 					--additional prepayment record in Oe_Payments as the payment
9494 					--term used has the prepayment check box checked
9495 					IF nvl(l_prepay_count,0) = 0  and nvl(l_line_payment_count,0) = 0 THEN
9496 						IF l_debug_level > 0 THEN
9497 							oe_debug_pub.add('OEXUHDRB: Inside prepayment record insertion....'||l_prepay_count);
9498 							oe_debug_pub.add('Payment number value...'||l_payment_number);
9499 							oe_debug_pub.add('Header id ----> '||p_x_header_rec.header_id);
9500 						END IF;
9501 
9502 						l_x_Header_Payment_tbl(2):=OE_ORDER_PUB.G_MISS_HEADER_PAYMENT_REC;
9503 						l_x_old_Header_Payment_Tbl(2):=OE_ORDER_PUB.G_MISS_HEADER_PAYMENT_REC;
9504 
9505 						l_x_Header_Payment_tbl(2).header_id := p_x_header_rec.header_id;
9506 						l_x_Header_Payment_tbl(2).payment_collection_event := 'PREPAY';
9507 						l_x_Header_Payment_tbl(2).payment_level_code := 'ORDER';
9508 						l_x_Header_Payment_tbl(2).credit_card_number := p_x_header_rec.credit_card_number;
9509 						l_x_Header_Payment_tbl(2).credit_card_code := p_x_header_rec.credit_card_code;
9510 						l_x_Header_Payment_tbl(2).credit_card_holder_name := p_x_header_rec.credit_card_holder_name;
9511 						l_x_Header_Payment_tbl(2).credit_card_expiration_date := p_x_header_rec.credit_card_expiration_date;
9512 						l_x_Header_Payment_tbl(2).credit_card_approval_code := p_x_header_rec.credit_card_approval_code;
9513 						l_x_Header_Payment_tbl(2).credit_card_approval_date := p_x_header_rec.credit_card_approval_date;
9514 						l_x_Header_Payment_tbl(2).payment_type_code := p_x_header_rec.payment_type_code;
9515 						l_x_Header_Payment_tbl(2).CC_INSTRUMENT_ID := p_x_header_rec.CC_INSTRUMENT_ID;
9516 						l_x_Header_Payment_tbl(2).CC_INSTRUMENT_ASSIGNMENT_ID := p_x_header_rec.CC_INSTRUMENT_ASSIGNMENT_ID;
9517 						l_x_Header_Payment_tbl(2).instrument_security_code := p_x_header_rec.instrument_security_code;
9518 						l_x_Header_Payment_tbl(2).payment_number := l_payment_number+1;
9519 
9520 
9521 					       OE_OE_TOTALS_SUMMARY.Order_Totals
9522 							       (
9523 							       p_header_id=>p_x_header_rec.header_id,
9524 							       p_subtotal =>l_subtotal,
9525 							       p_discount =>l_discount,
9526 							       p_charges  =>l_charges,
9527 							       p_tax      =>l_tax
9528 							       );
9529 
9530 					       l_order_total := nvl(l_subtotal,0) + nvl(l_charges,0) + nvl(l_tax,0);
9531 
9532 					        l_downpayment := oe_prepayment_util.get_downpayment_amount(
9533 						p_header_id => p_x_header_rec.header_id,
9534 						p_term_id => l_payment_term_id,
9535 						p_curr_code => l_currency_code,
9536 						p_order_total => l_order_total);
9537 
9538 						l_x_Header_Payment_tbl(2).payment_amount := l_downpayment;
9539 
9540 						IF l_debug_level > 0 THEN
9541 							oe_debug_pub.add('Inside prepayment type'||l_old_payment_type_code);
9542 							oe_debug_pub.add('New prepayment type'||p_x_header_rec.payment_type_code);
9543 							oe_debug_pub.add('Header_id'||p_x_header_rec.header_id);
9544 						END IF;
9545 						l_x_Header_Payment_tbl(2).operation := OE_GLOBALS.G_OPR_CREATE;
9546 					END IF;
9547 				END IF;
9548 			END IF;
9549 			--bug 5258767
9550 		END IF;
9551 		oe_debug_pub.add('Operation to be performed....frm post write proces...'||l_x_Header_Payment_tbl(1).operation);
9552 
9553 		OE_Order_PVT.Header_Payments
9554 		(   p_validation_level            	=> FND_API.G_VALID_LEVEL_NONE
9555 		,   p_init_msg_list               	=> FND_API.G_FALSE
9556 		,   p_control_rec                 	=> l_control_rec
9557 		,   p_x_Header_Payment_tbl        	=> l_x_Header_Payment_tbl
9558 		,   p_x_old_Header_Payment_tbl		=> l_x_old_Header_Payment_tbl
9559 		,   x_return_Status               	=> l_return_status
9560 		);
9561 		IF l_return_status = FND_API.G_RET_STS_ERROR THEN
9562 			RAISE FND_API.G_EXC_ERROR;
9563 		ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
9564 			RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9565 		ELSIF l_return_Status = FND_API.G_RET_STS_SUCCESS THEN
9566 			oe_debug_pub.add('Success in Header Payments call...');
9567 		END IF;
9568         END IF;
9569 	--R12 CC Encryption
9570 	oe_debug_pub.add('Exiting OE_HEADER_UTIL.Post_Write_Process',1);
9571 EXCEPTION
9572 	WHEN FND_API.G_EXC_ERROR THEN
9573 		RAISE FND_API.G_EXC_ERROR;
9574 	WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
9575 		RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9576 	WHEN OTHERS THEN
9577 		IF 	OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
9578 		THEN
9579 			OE_MSG_PUB.Add_Exc_Msg
9580 			(   G_PKG_NAME
9581 			,   'Post_Write_Process'
9582 			);
9583 		END IF;
9584 		RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9585 END Post_Write_Process;
9586 
9587 
9588 Procedure Validate_gapless_seq( p_application_id IN NUMBER,
9589                          p_entity_short_name in VARCHAR2,
9590                          p_validation_entity_short_name in VARCHAR2,
9591                          p_validation_tmplt_short_name in VARCHAR2,
9592                          p_record_set_tmplt_short_name in VARCHAR2,
9593                          p_scope in VARCHAR2,
9594                          p_result OUT NOCOPY /* file.sql.39 change */ NUMBER )
9595 IS
9596 	ltype 			VARCHAR2(1);
9597 	l_header_id 	NUMBER := oe_header_security.g_record.header_id;
9598 	l_order_type_id NUMBER;
9599         l_transaction_phase_code VARCHAR2(1)
9600                        := oe_header_security.g_record.transaction_phase_code;
9601 BEGIN
9602 
9603 	oe_debug_pub.add('Entering OR_HEADER_UTIL.Validate_Gapless_Seq',1);
9604 
9605 	select order_type_id into
9606 	l_order_type_id
9607 	from oe_order_headers_all
9608 	where header_id = l_header_id;
9609 
9610 	ltype := Get_ord_seq_type(l_order_type_id,l_transaction_phase_code);
9611 
9612 	IF ltype = 'G' THEN
9613 		p_result := 1;
9614 	ELSE
9615 		p_result := 0;
9616 	END IF;
9617 
9618 EXCEPTION
9619 
9620      when no_data_found then
9621                p_result := 1;
9622 
9623 End Validate_gapless_seq;
9624 
9625 PROCEDURE get_customer_details
9626 (   p_org_id                IN  NUMBER
9627 ,   p_site_use_code         IN  VARCHAR2
9628 ,   x_customer_name         OUT NOCOPY /* file.sql.39 change */ VARCHAR2
9629 ,   x_customer_number       OUT NOCOPY /* file.sql.39 change */ VARCHAR2
9630 ,   x_customer_id           OUT NOCOPY /* file.sql.39 change */ number
9631 ,   x_location              OUT NOCOPY /* file.sql.39 change */ VARCHAR2
9632 ,   x_address1              OUT NOCOPY /* file.sql.39 change */ VARCHAR2
9633 ,   x_address2              OUT NOCOPY /* file.sql.39 change */ VARCHAR2
9634 ,   x_address3              OUT NOCOPY /* file.sql.39 change */ VARCHAR2
9635 ,   x_address4              OUT NOCOPY /* file.sql.39 change */ VARCHAR2
9636 ,   x_city              OUT NOCOPY /* file.sql.39 change */ VARCHAR2
9637 ,   x_state              OUT NOCOPY /* file.sql.39 change */ VARCHAR2
9638 ,   x_zip              OUT NOCOPY /* file.sql.39 change */ VARCHAR2
9639 ,   x_country              OUT NOCOPY /* file.sql.39 change */ VARCHAR2
9640 )
9641 
9642 IS
9643 BEGIN
9644 
9645     IF p_org_id is NOT NULL THEN
9646 
9647         SELECT /*MOAC_SQL_CHANGE*/  cust.cust_account_id,
9648                 party.party_name,
9649                 cust.account_number,
9650                 site.location,
9651                 loc.address1,
9652                 loc.address2,
9653                 loc.address3,
9654                 loc.address4,
9655                 loc.city,
9656                 nvl(loc.state,loc.province), --3603600
9657                 loc.postal_code,
9658                 loc.country
9659         INTO    x_customer_id,
9660                 x_customer_name,
9661                 x_customer_number,
9662                 x_location,
9663                 x_address1,
9664                 x_address2,
9665                 x_address3,
9666                 x_address4,
9667                 x_city,
9668                 x_state,
9669                 x_zip,
9670                 x_country
9671         FROM    HZ_CUST_SITE_USES_ALL site,
9672                 HZ_CUST_ACCT_SITES cas,
9673                 hz_cust_accounts cust,
9674                 hz_parties party,
9675                 hz_party_sites ps,
9676                 hz_locations loc
9677         WHERE   site.cust_acct_site_id=cas.cust_acct_site_id
9678         AND     site.site_use_code=p_site_use_code
9679         AND     site.site_use_id=p_org_id
9680         AND     cust.cust_account_id = cas.cust_account_id
9681         AND     cas.party_site_id = ps.party_site_id
9682         AND     ps.location_id = loc.location_id
9683         AND     party.party_id = cust.party_id;
9684 
9685     ELSE
9686 
9687         x_customer_name    :=  NULL    ;
9688         x_customer_number  :=  NULL    ;
9689         x_customer_id      :=  NULL    ;
9690         x_location         :=  NULL;
9691         x_address1         := nULL;
9692         x_address2         := nULL;
9693         x_address3         := nULL;
9694         x_address4         := nULL;
9695         x_city         := nULL;
9696         x_state         := nULL;
9697         x_zip         := nULL;
9698         x_country         := nULL;
9699 
9700     END IF;
9701 
9702 EXCEPTION
9703 
9704     WHEN NO_DATA_FOUND THEN
9705 
9706         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_SUCCESS)
9707         THEN
9708 
9709             fnd_message.set_name('ONT','OE_ID_TO_VALUE_ERROR');
9710             FND_MESSAGE.SET_TOKEN('ATTRIBUTE','get_customer_details');
9711             OE_MSG_PUB.Add;
9712 
9713         END IF;
9714 
9715 
9716     WHEN OTHERS THEN
9717 
9718         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
9719         THEN
9720             OE_MSG_PUB.Add_Exc_Msg
9721             (   G_PKG_NAME
9722             ,   'get_customer_details'
9723             );
9724         END IF;
9725 
9726         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9727 
9728 END get_customer_details;
9729 
9730  -- This procedure deletes all the header level charges when the order/all the lines are cancelled
9731 
9732 PROCEDURE cancel_header_charges
9733 ( p_header_id IN number ,
9734 --  p_x_line_id IN number,
9735   x_return_status OUT NOCOPY varchar2
9736 )
9737 IS
9738 l_total_quantity NUMBER;
9739 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
9740 
9741 BEGIN
9742     oe_debug_pub.add(' Entering Cancel_Header_Charges() ');
9743 
9744 --  SELECT sum(ordered_quantity) into l_total_quantity from OE_ORDER_LINES where header_id = p_header_id; --commented for bug#9434723
9745     --bug#9434723: Outer NVL() if the it is last line to be deleted. Inner NVL() if line is in ENTERED status w/out qty.
9746     SELECT Nvl(sum( Nvl(ordered_quantity,0) ),0) into l_total_quantity FROM OE_ORDER_LINES where header_id = p_header_id; --bug#9434723
9747     oe_debug_pub.add('   l_total_quantity = ' ||l_total_quantity, 1 ) ;
9748 
9749     IF l_total_quantity = 0 THEN
9750         OE_Header_Adj_Util.Delete_Header_Charges( p_header_id  => p_header_id );
9751     END IF;
9752     oe_debug_pub.add(' Exiting Cancel_Header_Charges() ');
9753 EXCEPTION
9754     WHEN FND_API.G_EXC_ERROR THEN
9755         x_return_status := FND_API.G_RET_STS_ERROR;
9756     WHEN OTHERS THEN
9757         IF l_debug_level  > 0 THEN
9758             oe_debug_pub.add(  'UNEXPECTED ERROR IN ' || G_PKG_NAME || ':' || 'PERFORM_LINE_CANCEL' ) ;
9759             x_return_status := FND_API.G_RET_STS_ERROR;
9760         END IF;
9761 END;
9762 
9763 --For bug 3563983
9764 --Changed the Function name from Blanket_Req_For_Curr_Update
9765 --Added code to mask logging Validate shipment and Incrementing amounts for delete
9766 
9767 PROCEDURE Blkt_Req_For_Curr_Upd_And_Del
9768   (p_header_rec          IN OE_Order_PUB.Header_Rec_Type
9769    ,p_old_header_rec     IN OE_Order_PUB.Header_Rec_Type
9770   )
9771 IS
9772 
9773   CURSOR lines IS
9774     SELECT  line_id
9775            ,blanket_number
9776            ,blanket_line_number
9777            ,ordered_quantity
9778            ,order_quantity_uom
9779            ,inventory_item_id
9780            ,unit_selling_price
9781            ,fulfilled_flag
9782            ,line_set_id
9783       FROM OE_ORDER_LINES
9784      WHERE HEADER_ID = p_header_rec.header_id
9785        AND BLANKET_NUMBER IS NOT NULL;
9786 
9787   l_return_status        VARCHAR2(1);
9788 
9789 BEGIN
9790 
9791     -- BUG 2746595, send currency code as request_unique_key1 parameter to
9792     -- process release request. This is required as 2 distinct requests need to
9793     -- be logged for currency updates.
9794 
9795     -- For all release lines i.e. lines with a blanket reference
9796     -- , log delayed requests to update amounts based on the new currency
9797     FOR c IN lines LOOP
9798 
9799          -- Request to decrement amounts based on old currency code
9800          OE_Delayed_Requests_Pvt.Log_Request
9801            (p_entity_code               => OE_GLOBALS.G_ENTITY_ALL
9802            ,p_entity_id                 => c.line_id
9803            ,p_requesting_entity_code    => OE_GLOBALS.G_ENTITY_HEADER
9804            ,p_requesting_entity_id      => p_header_rec.header_id
9805            ,p_request_type              => OE_GLOBALS.G_PROCESS_RELEASE
9806            -- Old values
9807            ,p_param1                    => c.blanket_number
9808            ,p_param2                    => c.blanket_line_number
9809            ,p_param3                    => c.ordered_quantity
9810            ,p_param4                    => c.order_quantity_uom
9811            ,p_param5                    => c.unit_selling_price
9812            ,p_param6                    => c.inventory_item_id
9813            -- New values
9814            ,p_param11                   => null
9815            ,p_param12                   => null
9816            ,p_param13                   => 0
9817            ,p_param14                   => null
9818            ,p_param15                   => 0
9819            ,p_param16                   => null
9820            -- Other parameters - old currency code here
9821            ,p_param8                    => c.fulfilled_flag
9822            ,p_param9                    => c.line_set_id
9823            ,p_request_unique_key1       => p_old_header_rec.transactional_curr_code
9824            ,x_return_status             => l_return_status
9825           );
9826          IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
9827             RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9828          END IF;
9829 
9830          --For bug 3563983
9831          IF p_header_rec.operation = OE_GLOBALS.G_OPR_UPDATE
9832          THEN
9833             -- Request to increment amounts based on new currency code
9834             OE_Delayed_Requests_Pvt.Log_Request
9835                (p_entity_code               => OE_GLOBALS.G_ENTITY_ALL
9836 	       ,p_entity_id                 => c.line_id
9837                ,p_requesting_entity_code    => OE_GLOBALS.G_ENTITY_HEADER
9838                ,p_requesting_entity_id      => p_header_rec.header_id
9839                ,p_request_type              => OE_GLOBALS.G_PROCESS_RELEASE
9840                -- Old values
9841                ,p_param1                    => null
9842                ,p_param2                    => null
9843                ,p_param3                    => 0
9844                ,p_param4                    => null
9845                ,p_param5                    => 0
9846                ,p_param6                    => null
9847                -- New values
9848                ,p_param11                   => c.blanket_number
9849                ,p_param12                   => c.blanket_line_number
9850                ,p_param13                   => c.ordered_quantity
9851                ,p_param14                   => c.order_quantity_uom
9852                ,p_param15                   => c.unit_selling_price
9853                ,p_param16                   => c.inventory_item_id
9854                -- Other parameters - new currency code here
9855                ,p_param8                    => c.fulfilled_flag
9856                ,p_param9                    => c.line_set_id
9857                ,p_request_unique_key1       => p_header_rec.transactional_curr_code
9858                ,x_return_status             => l_return_status
9859                );
9860 
9861 
9862            IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
9863               RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9864            END IF;
9865 
9866 	   -- For shipment lines, also log requests to validate that
9867            -- sum of amounts across all shipments in the line set are
9868            -- within release min/max limits set on blanket line
9869            IF c.line_set_id IS NOT NULL THEN
9870 
9871              OE_Delayed_Requests_Pvt.Log_Request
9872                (p_entity_code               => OE_GLOBALS.G_ENTITY_ALL
9873                 ,p_entity_id                 => c.line_set_id
9874                 ,p_requesting_entity_code    => OE_GLOBALS.G_ENTITY_LINE
9875                 ,p_requesting_entity_id      => c.line_id
9876                 ,p_request_type              => OE_GLOBALS.G_VALIDATE_RELEASE_SHIPMENTS
9877                 ,p_request_unique_key1       => c.blanket_number
9878                 ,p_request_unique_key2       => c.blanket_line_number
9879                 ,p_param1                    =>
9880                         p_header_rec.transactional_curr_code
9881                 ,x_return_status             => l_return_status
9882                 );
9883             IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
9884                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9885             END IF;
9886 
9887            END IF;
9888 
9889        END IF;
9890 
9891    END LOOP;
9892 
9893 EXCEPTION
9894 
9895     WHEN OTHERS THEN
9896 
9897         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
9898         THEN
9899             OE_MSG_PUB.Add_Exc_Msg
9900             (   G_PKG_NAME
9901             ,   'Blkt_Req_For_Curr_Upd_And_Del'
9902             );
9903         END IF;
9904 
9905         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9906 
9907 END Blkt_Req_For_Curr_Upd_And_Del;
9908 
9909 
9910 --ER7675548
9911 Procedure Get_customer_info_ids
9912 ( p_header_customer_info_tbl IN OUT NOCOPY OE_Order_Pub.CUSTOMER_INFO_TABLE_TYPE,
9913   p_x_header_rec             IN OUT NOCOPY OE_Order_Pub.Header_Rec_Type,
9914   x_return_status            OUT NOCOPY VARCHAR2,
9915   x_msg_count                OUT NOCOPY NUMBER,
9916   x_msg_data                 OUT NOCOPY VARCHAR2
9917 )IS
9918 
9919 x_sold_to_customer_id   NUMBER;
9920 x_ship_to_customer_id   NUMBER;
9921 x_bill_to_customer_id   NUMBER;
9922 x_deliver_to_customer_id  NUMBER;
9923 
9924 x_ship_to_org_id NUMBER;
9925 x_invoice_to_org_id NUMBER;
9926 x_deliver_to_org_id NUMBER;
9927 x_sold_to_site_use_id NUMBER;
9928 
9929 x_sold_to_contact_id  NUMBER;
9930 x_ship_to_contact_id  NUMBER;
9931 x_invoice_to_contact_id   NUMBER;
9932 x_deliver_to_contact_id   NUMBER;
9933 
9934 
9935 l_order_source_id           NUMBER := p_x_header_rec.order_source_id;
9936 l_orig_sys_document_ref     VARCHAR2(50) :=  p_x_header_rec.orig_sys_document_ref;
9937 l_orig_sys_line_ref     VARCHAR2(50);
9938 l_orig_sys_shipment_ref     VARCHAR2(50);
9939 l_change_sequence           VARCHAR2(50) := p_x_header_rec.change_sequence;
9940 l_source_document_type_id   NUMBER := p_x_header_rec.source_document_type_id;
9941 l_source_document_id        NUMBER := p_x_header_rec.source_document_id;
9942 l_source_document_line_id        NUMBER;
9943 
9944 
9945 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
9946 x_party_id NUMBER;
9947 x_cust_account_id NUMBER;
9948 begin
9949 
9950 x_return_status := FND_API.G_RET_STS_SUCCESS;
9951 
9952 IF l_debug_level >0 then
9953 	oe_debug_pub.add('Entering OE_HEADER_UTIL.Get_customer_info_ids :'||p_header_customer_info_tbl.count);
9954 End IF;
9955 
9956 OE_CUSTOMER_INFO_PVT.G_SOLD_TO_CUSTOMER_ID := NULL;
9957 
9958 IF p_header_customer_info_tbl.count = 0 THEN
9959 	x_return_status := FND_API.G_RET_STS_SUCCESS;
9960 	RETURN;
9961 END IF;
9962  --Get  nesessary attributes to set the message context in case of UPDATE operation
9963  IF p_x_header_rec.header_Id IS NOT NULL AND
9964            p_x_header_rec.header_Id <> FND_API.G_MISS_NUM THEN
9965            BEGIN
9966                SELECT order_source_id, orig_sys_document_ref, change_sequence,
9967                source_document_type_id, source_document_id
9968                INTO l_order_source_id, l_orig_sys_document_ref, l_change_sequence,
9969                l_source_document_type_id, l_source_document_id
9970                FROM   OE_ORDER_HEADERS_ALL
9971                WHERE  header_id = p_x_header_rec.header_Id;
9972             EXCEPTION
9973                WHEN NO_DATA_FOUND THEN
9974                    l_order_source_id := null;
9975                    l_orig_sys_document_ref := null;
9976                    l_change_sequence := null;
9977                    l_source_document_type_id := null;
9978                    l_source_document_id := null;
9979                WHEN OTHERS THEN
9980                    l_order_source_id := null;
9981                    l_orig_sys_document_ref := null;
9982                    l_change_sequence := null;
9983                    l_source_document_type_id := null;
9984                    l_source_document_id := null;
9985             END;
9986   END IF;
9987 
9988 
9989     OE_MSG_PUB.set_msg_context(
9990 	 p_entity_code			=> 'HEADER'
9991   	,p_entity_id         		=> p_x_header_rec.header_id
9992     	,p_header_id         		=> p_x_header_rec.header_id
9993     	,p_line_id           		=> null
9994     	,p_orig_sys_document_ref	=> l_orig_sys_document_ref
9995     	,p_orig_sys_document_line_ref	=> null
9996         ,p_change_sequence              => l_change_sequence
9997     	,p_source_document_id		=> l_source_document_id
9998     	,p_source_document_line_id	=> null
9999 	,p_order_source_id            => l_order_source_id
10000 	,p_source_document_type_id    => l_source_document_type_id);
10001 
10002 	IF p_x_header_rec.operation = OE_GLOBALS.G_OPR_UPDATE AND
10003 	   p_x_header_rec.sold_to_org_id = FND_API.G_MISS_NUM THEN
10004 
10005 		IF l_debug_level  > 0 THEN
10006 		     oe_debug_pub.add('Selecting sold_to_org_id in case of update');
10007 		END IF;
10008 
10009 		BEGIN
10010 				SELECT NVL(SOLD_TO_ORG_ID,p_x_header_rec.sold_to_org_id)
10011 				INTO p_x_header_rec.sold_to_org_id
10012 				FROM OE_ORDER_HEADERS_ALL
10013 				WHERE HEADER_ID = p_x_header_rec.header_id;
10014                 EXCEPTION
10015 			WHEN OTHERS THEN
10016 				NULL;
10017 		END;
10018         END IF;
10019 
10020 
10021 
10022 
10023 	OE_CUSTOMER_INFO_PVT.get_customer_info_ids (
10024                           p_customer_info_tbl  => p_header_customer_info_tbl,
10025 		          p_operation_code     => p_x_header_rec.operation,
10026 			  p_sold_to_customer_ref => p_x_header_rec.sold_to_customer_ref,
10027 			  p_ship_to_customer_ref => p_x_header_rec.ship_to_customer_ref,
10028 			  p_bill_to_customer_ref => p_x_header_rec.invoice_to_customer_ref,
10029 			  p_deliver_to_customer_ref => p_x_header_rec.deliver_to_customer_ref,
10030 
10031 			  p_ship_to_address_ref => p_x_header_rec.ship_to_address_ref,
10032 			  p_bill_to_address_ref => p_x_header_rec.invoice_to_address_ref,
10033 			  p_deliver_to_address_ref => p_x_header_rec.deliver_to_address_ref,
10034  		          p_sold_to_address_ref => p_x_header_rec.sold_to_address_ref,
10035 
10036 			  p_sold_to_contact_ref => p_x_header_rec.sold_to_contact_ref,
10037 			  p_ship_to_contact_ref => p_x_header_rec.ship_to_contact_ref,
10038 			  p_bill_to_contact_ref => p_x_header_rec.invoice_to_contact_ref,
10039 			  p_deliver_to_contact_ref => p_x_header_rec.deliver_to_contact_ref,
10040 
10041 			  p_sold_to_customer_id => p_x_header_rec.sold_to_org_id,
10042 			  p_ship_to_customer_id => p_x_header_rec.ship_to_customer_id,
10043 			  p_bill_to_customer_id  => p_x_header_rec.invoice_to_customer_id,
10044 			  p_deliver_to_customer_id  => p_x_header_rec.deliver_to_customer_id,
10045 
10046 			  p_ship_to_org_id     => p_x_header_rec.ship_to_org_id,
10047 			  p_invoice_to_org_id  => p_x_header_rec.invoice_to_org_id,
10048 			  p_deliver_to_org_id  => p_x_header_rec.deliver_to_org_id,
10049 			  p_sold_to_site_use_id => p_x_header_rec.sold_to_site_use_id,
10050 
10051 			  p_sold_to_contact_id  => p_x_header_rec.sold_to_contact_id,
10052 			  p_ship_to_contact_id  => p_x_header_rec.ship_to_contact_id,
10053 			  p_invoice_to_contact_id => p_x_header_rec.invoice_to_contact_id,
10054 			  p_deliver_to_contact_id => p_x_header_rec.deliver_to_contact_id,
10055 
10056 
10057 			  x_sold_to_customer_id => x_sold_to_customer_id,
10058 			  x_ship_to_customer_id => x_ship_to_customer_id,
10059 			  x_bill_to_customer_id => x_bill_to_customer_id,
10060 			  x_deliver_to_customer_id => x_deliver_to_customer_id,
10061 
10062 			  x_ship_to_org_id => x_ship_to_org_id,
10063 			  x_invoice_to_org_id => x_invoice_to_org_id,
10064 			  x_deliver_to_org_id => x_deliver_to_org_id,
10065 			  x_sold_to_site_use_id => x_sold_to_site_use_id,
10066 
10067 			  x_sold_to_contact_id => x_sold_to_contact_id,
10068 			  x_ship_to_contact_id => x_ship_to_contact_id,
10069 			  x_invoice_to_contact_id => x_invoice_to_contact_id,
10070 			  x_deliver_to_contact_id => x_deliver_to_contact_id ,
10071 
10072 
10073 			  x_return_status   => x_return_status,
10074 			  x_msg_count       => x_msg_count,
10075 			  x_msg_data        => x_msg_data
10076 
10077 			 );
10078 
10079 
10080 p_x_header_rec.sold_to_org_id := x_sold_to_customer_id;
10081 p_x_header_rec.ship_to_customer_id := x_ship_to_customer_id;
10082 p_x_header_rec.invoice_to_customer_id := x_bill_to_customer_id;
10083 p_x_header_rec.deliver_to_customer_id := x_deliver_to_customer_id;
10084 
10085 p_x_header_rec.ship_to_org_id := x_ship_to_org_id;
10086 p_x_header_rec.invoice_to_org_id := x_invoice_to_org_id;
10087 p_x_header_rec.deliver_to_org_id := x_deliver_to_org_id;
10088 p_x_header_rec.sold_to_site_use_id := x_sold_to_site_use_id;
10089 
10090 p_x_header_rec.sold_to_contact_id := x_sold_to_contact_id;
10091 p_x_header_rec.ship_to_contact_id := x_ship_to_contact_id;
10092 p_x_header_rec.invoice_to_contact_id := x_invoice_to_contact_id;
10093 p_x_header_rec.deliver_to_contact_id := x_deliver_to_contact_id;
10094 
10095 OE_CUSTOMER_INFO_PVT.G_SOLD_TO_CUSTOMER_ID := x_sold_to_customer_id;
10096 OE_CUSTOMER_INFO_PVT.G_SOLD_TO_CONTACT_ID := x_sold_to_contact_id;
10097 
10098 OE_MSG_PUB.reset_msg_context('HEADER');
10099 
10100 
10101 IF l_debug_level >0 then
10102 
10103 
10104 	oe_debug_pub.add('x_return_status :' ||x_return_status);
10105 
10106 	oe_debug_pub.add('p_x_header_rec.sold_to_org_id :' ||p_x_header_rec.sold_to_org_id);
10107 	oe_debug_pub.add('p_x_header_rec.ship_to_customer_id :' ||p_x_header_rec.ship_to_customer_id);
10108 	oe_debug_pub.add('p_x_header_rec.bill_to_customer_id :' ||p_x_header_rec.invoice_to_customer_id);
10109 	oe_debug_pub.add('p_x_header_rec.deliver_to_customer_id :' ||p_x_header_rec.deliver_to_customer_id);
10110 
10111 	oe_debug_pub.add('p_x_header_rec.ship_to_org_id :' ||p_x_header_rec.ship_to_org_id);
10112 	oe_debug_pub.add('p_x_header_rec.bill_to_org_id :' ||p_x_header_rec.invoice_to_org_id);
10113 	oe_debug_pub.add('p_x_header_rec.deliver_to_org_id :' ||p_x_header_rec.deliver_to_org_id);
10114 	oe_debug_pub.add('p_x_header_rec.sold_to_site_use_id :' ||p_x_header_rec.sold_to_site_use_id);
10115 
10116 	oe_debug_pub.add('p_x_header_rec.sold_to_contact_id :' ||p_x_header_rec.sold_to_contact_id);
10117 	oe_debug_pub.add('p_x_header_rec.ship_to_contact_id :' ||p_x_header_rec.ship_to_contact_id);
10118 	oe_debug_pub.add('p_x_header_rec.invoice_to_contact_id :' ||p_x_header_rec.invoice_to_contact_id);
10119 	oe_debug_pub.add('p_x_header_rec.deliver_to_contact_id :' ||p_x_header_rec.deliver_to_contact_id);
10120 
10121 	oe_debug_pub.add('Exiting OE_HEADER_UTIL.Get_customer_info_ids');
10122 End IF;
10123 
10124 
10125 EXCEPTION
10126 
10127 	WHEN OTHERS THEN
10128 	x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
10129 
10130         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
10131         THEN
10132             OE_MSG_PUB.Add_Exc_Msg
10133             (   G_PKG_NAME
10134             ,   'Get_customer_info_ids'
10135             );
10136         END IF;
10137 
10138 End Get_customer_info_ids;
10139 
10140  --Added for bug 8489881
10141  	 FUNCTION Get_Primary_Site_Use_Id
10142  	 (   p_site_use          IN VARCHAR2,
10143  	     p_cust_acct_id      IN NUMBER,
10144  	     p_org_id            IN NUMBER)
10145  	 RETURN NUMBER IS
10146  	    p_site_use_id NUMBER;
10147  	   BEGIN
10148  	   IF p_site_use = 'SHIP_TO' THEN
10149  	    SELECT site_use.SITE_USE_ID
10150  	      INTO p_site_use_id
10151  	      FROM HZ_CUST_SITE_USES_ALL site_use,
10152  	           HZ_CUST_ACCT_SITES site
10153  	     WHERE site_use.SITE_USE_CODE   = p_site_use
10154  	     AND site.CUST_ACCT_SITE_ID     = site_use.CUST_ACCT_SITE_ID
10155  	     AND site.CUST_ACCOUNT_ID       = p_cust_acct_id
10156  	     AND SITE_USE.PRIMARY_FLAG      = 'Y'
10157  	     AND SITE_USE.STATUS            = 'A'
10158  	     AND SITE.STATUS                = 'A'
10159  	     and SITE.ship_to_flag          = 'P'
10160  	     AND SITE.ORG_ID                = p_org_id;
10161  	   ELSE
10162  	     SELECT site_use.SITE_USE_ID
10163  	      INTO p_site_use_id
10164  	      FROM HZ_CUST_SITE_USES_ALL site_use,
10165  	           HZ_CUST_ACCT_SITES site
10166  	     WHERE site_use.SITE_USE_CODE   = p_site_use
10167  	     AND site.CUST_ACCT_SITE_ID     = site_use.CUST_ACCT_SITE_ID
10168  	     AND site.CUST_ACCOUNT_ID       = p_cust_acct_id
10169  	     AND SITE_USE.PRIMARY_FLAG      = 'Y'
10170  	     AND SITE_USE.STATUS            = 'A'
10171  	     AND SITE.STATUS                = 'A'
10172  	     and SITE.bill_to_flag          = 'P'
10173  	     AND SITE.ORG_ID                = p_org_id;
10174  	     END IF;
10175  	     RETURN p_site_use_id;
10176  	 EXCEPTION
10177  	 WHEN NO_DATA_FOUND THEN
10178  	   RETURN NULL;
10179  	 WHEN TOO_MANY_ROWS THEN
10180  	   RETURN NULL;
10181  	 END;
10182 
10183 END OE_Header_Util;