DBA Data[Home] [Help]

PACKAGE BODY: APPS.OE_VALIDATE_HEADER

Source


1 PACKAGE BODY OE_Validate_Header AS
2 /* $Header: OEXLHDRB.pls 120.20 2008/01/10 07:10:56 smanian ship $ */
3 
4 --  Global constant holding the package name
5 
6 G_PKG_NAME    CONSTANT VARCHAR2(30) := 'OE_Validate_Header';
7 
8 
9 /* LOCAL PROCEDURES */
10 
11 -- QUOTING changes
12 /*-------------------------------------------------------
13 PROCEDURE:    Check_Negotiation_Attributes
14 Description:  This procedures validates the order attributes
15               against transaction phase (Negotiation vs Fulfillment).
16 --------------------------------------------------------*/
17 
18 PROCEDURE Check_Negotiation_Attributes
19 ( p_header_rec            IN OE_Order_PUB.Header_Rec_Type
20 , p_old_header_rec        IN OE_Order_PUB.Header_Rec_Type
21 , x_return_status         IN OUT NOCOPY VARCHAR2
22 )
23 IS
24  l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
25 BEGIN
26 
27     if l_debug_level > 0 then
28        oe_debug_pub.add('Enter OE_VALIDATE_HEADER.Check_Negotiation_Attributes',1);
29     end if;
30 
31     x_return_status := FND_API.G_RET_STS_SUCCESS;
32 
33 
34     IF p_header_rec.operation = OE_GLOBALS.G_OPR_UPDATE THEN
35 
36        -- Transaction phase cannot be updated on a saved transaction.
37 
38        IF OE_Quote_Util.G_COMPLETE_NEG = 'N' AND
39           NOT OE_GLOBALS.EQUAL(p_header_rec.transaction_phase_code
40                                 ,p_old_header_rec.transaction_phase_code)
41        THEN
42           FND_MESSAGE.SET_NAME('ONT','OE_PHASE_UPDATE_NOT_ALLOWED');
43           OE_MSG_PUB.ADD;
44           RAISE FND_API.G_EXC_ERROR;
45        END IF;
46 
47        -- New version number cannot be lower than previous version
48 
49        IF nvl(p_header_rec.version_number,-1) < p_old_header_rec.version_number
50        THEN
51           FND_MESSAGE.SET_NAME('ONT','OE_VERSION_NUM_ERROR');
52           OE_MSG_PUB.ADD;
53           x_return_status := FND_API.G_RET_STS_ERROR;
54        END IF;
55 
56     END IF; -- End of check for UPDATE operation
57 
58 
59     -- Start checks specific to the transaction phase
60 
61     IF nvl(p_header_rec.transaction_phase_code,'F') = 'F' THEN
62 
63        -- Cannot update following quote attributes in fulfillment phase
64 
65        IF (NOT OE_GLOBALS.EQUAL(p_header_rec.quote_number
66                          ,p_old_header_rec.quote_number)) OR
67           (p_header_rec.operation = OE_GLOBALS.G_OPR_CREATE AND
68            p_header_rec.quote_number IS NOT NULL )
69           --OR cnd added for Bug 5060064
70        THEN
71           FND_MESSAGE.SET_NAME('ONT','OE_CANT_UPDATE_QUOTE_ATTR');
72           FND_MESSAGE.SET_TOKEN('ATTRIBUTE',
73               OE_Order_UTIL.Get_Attribute_Name('QUOTE_NUMBER'));
74           OE_MSG_PUB.ADD;
75           x_return_status := FND_API.G_RET_STS_ERROR;
76        END IF;
77 
78        IF (NOT OE_GLOBALS.EQUAL(p_header_rec.quote_date
79                          ,p_old_header_rec.quote_date)) OR
80           (p_header_rec.operation = OE_GLOBALS.G_OPR_CREATE AND
81            p_header_rec.quote_date IS NOT NULL )
82           --OR cnd added for Bug 5060064
83        THEN
84           FND_MESSAGE.SET_NAME('ONT','OE_CANT_UPDATE_QUOTE_ATTR');
85           FND_MESSAGE.SET_TOKEN('ATTRIBUTE',
86               OE_Order_UTIL.Get_Attribute_Name('QUOTE_DATE'));
87           OE_MSG_PUB.ADD;
88           x_return_status := FND_API.G_RET_STS_ERROR;
89        END IF;
90 
91        IF (NOT OE_GLOBALS.EQUAL(p_header_rec.expiration_date
92                          ,p_old_header_rec.expiration_date)) OR
93           (p_header_rec.operation = OE_GLOBALS.G_OPR_CREATE AND
94            p_header_rec.expiration_date IS NOT NULL )
95           --OR cnd added for Bug 5060064
96        THEN
97           FND_MESSAGE.SET_NAME('ONT','OE_CANT_UPDATE_QUOTE_ATTR');
98           FND_MESSAGE.SET_TOKEN('ATTRIBUTE',
99               OE_Order_UTIL.Get_Attribute_Name('EXPIRATION_DATE'));
100           OE_MSG_PUB.ADD;
101           x_return_status := FND_API.G_RET_STS_ERROR;
102        END IF;
103 
104        -- Bug 3189579
105        -- Sales document name is supported on both sales orders and
106        -- quoted orders. Check is not needed here.
107 
108     -- Checks if order is in negotiation phase
109 
110     ELSIF p_header_rec.transaction_phase_code = 'N' THEN
111 
112        -- Cannot update following order attributes in negotiation phase
113 
114        IF (NOT OE_GLOBALS.EQUAL(p_header_rec.order_number
115                          ,p_old_header_rec.order_number)) OR
116           (p_header_rec.operation = OE_GLOBALS.G_OPR_CREATE AND
117            p_header_rec.order_number IS NOT NULL )
118           --OR cnd added for Bug 5060064
119        THEN
120           FND_MESSAGE.SET_NAME('ONT','OE_CANT_UPDATE_ORDER_ATTR');
121           FND_MESSAGE.SET_TOKEN('ATTRIBUTE',
122               OE_Order_UTIL.Get_Attribute_Name('ORDER_NUMBER'));
123           OE_MSG_PUB.ADD;
124           x_return_status := FND_API.G_RET_STS_ERROR;
125        END IF;
126 
127        IF (NOT OE_GLOBALS.EQUAL(p_header_rec.ordered_date
128                          ,p_old_header_rec.ordered_date))  OR
129           (p_header_rec.operation = OE_GLOBALS.G_OPR_CREATE AND
130            p_header_rec.ordered_date IS NOT NULL )
131           --OR cnd added for Bug 5060064
132        THEN
133           FND_MESSAGE.SET_NAME('ONT','OE_CANT_UPDATE_ORDER_ATTR');
134           FND_MESSAGE.SET_TOKEN('ATTRIBUTE',
135               OE_Order_UTIL.Get_Attribute_Name('ORDERED_DATE'));
136           OE_MSG_PUB.ADD;
137           x_return_status := FND_API.G_RET_STS_ERROR;
138        END IF;
139 
140        -- Return orders not supported
141        IF p_header_rec.order_category_code = 'RETURN' THEN
142           FND_MESSAGE.SET_NAME('ONT','OE_QUOTE_RETURN_NOT_SUPP');
143           OE_MSG_PUB.ADD;
144           x_return_status := FND_API.G_RET_STS_ERROR;
145        END IF;
146 
147        -- Internal sales orders not allowed
148        IF p_header_rec.order_source_id = 10 THEN
149           FND_MESSAGE.SET_NAME('ONT','OE_QUOTE_INT_ORD_NOT_SUPP');
150           OE_MSG_PUB.ADD;
151           x_return_status := FND_API.G_RET_STS_ERROR;
152        END IF;
153 
154        -- Cancellation operation not supported for quotes
155        IF p_header_rec.cancelled_flag = 'Y' THEN
156           FND_MESSAGE.SET_NAME('ONT','OE_QUOTE_CANCEL_NOT_SUPP');
157           OE_MSG_PUB.ADD;
158           x_return_status := FND_API.G_RET_STS_ERROR;
159        END IF;
160 
161     END IF; -- End of check if phase = F/N
162 
163     oe_debug_pub.add('Exiting OE_VALIDATE_HEADER.Check_Negotiation_Attributes',1);
164 
165 EXCEPTION
166   WHEN FND_API.G_EXC_ERROR THEN
167     x_return_status := FND_API.G_RET_STS_ERROR;
168   WHEN OTHERS THEN
169     x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
170 
171     IF OE_MSG_PUB.Check_Msg_Level (OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
172     THEN
173       OE_MSG_PUB.Add_Exc_Msg
174       (  G_PKG_NAME ,
175         'Check_Negotiation_Attributes'
176       );
177     END IF;
178 
179     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
180 END Check_Negotiation_Attributes;
181 
182 /*-------------------------------------------------------
183 PROCEDURE:    Check_Book_Reqd_Attributes
184 Description:
185 --------------------------------------------------------*/
186 
187 PROCEDURE Check_Book_Reqd_Attributes
188 ( p_header_rec            IN OE_Order_PUB.Header_Rec_Type
189 , x_return_status         IN OUT NOCOPY /* file.sql.39 change */ VARCHAR2
190 )
191 IS
192 l_order_type_rec      OE_Order_Cache.Order_Type_Rec_Type;
193 l_set_of_books_rec    OE_Order_Cache.Set_Of_Books_Rec_Type;
194 BEGIN
195 
196     oe_debug_pub.add('Enter OE_VALIDATE_HEADER.CHECK_BOOK_REQD',1);
197 
198   -- Check for the following required fields on a booked order:
199   -- Order Number, Sold To Org, Invoice To Org,
200   -- Price List, Tax Exempt Flag, Sales Person, Order Date
201 
202   IF p_header_rec.sold_to_org_id IS NULL
203   THEN
204     x_return_status := FND_API.G_RET_STS_ERROR;
205     FND_MESSAGE.SET_NAME('ONT','OE_BOOK_REQUIRED_ATTRIBUTE');
206     FND_MESSAGE.SET_TOKEN('ATTRIBUTE',
207     OE_Order_UTIL.Get_Attribute_Name('SOLD_TO_ORG_ID'));
208     OE_MSG_PUB.ADD;
209   END IF;
210 
211   IF p_header_rec.salesrep_id IS NULL
212   THEN
213     x_return_status := FND_API.G_RET_STS_ERROR;
214     FND_MESSAGE.SET_NAME('ONT','OE_BOOK_REQUIRED_ATTRIBUTE');
215     FND_MESSAGE.SET_TOKEN('ATTRIBUTE',
216     OE_Order_UTIL.Get_Attribute_Name('SALESREP_ID'));
217     OE_MSG_PUB.ADD;
218   END IF;
219 
220   IF p_header_rec.ordered_date IS NULL
221   THEN
222     x_return_status := FND_API.G_RET_STS_ERROR;
223     FND_MESSAGE.SET_NAME('ONT','OE_BOOK_REQUIRED_ATTRIBUTE');
224     FND_MESSAGE.SET_TOKEN('ATTRIBUTE',
225     OE_Order_UTIL.Get_Attribute_Name('ORDERED_DATE'));
226     OE_MSG_PUB.ADD;
227   END IF;
228 
229   IF p_header_rec.invoice_to_org_id IS NULL
230   THEN
231     x_return_status := FND_API.G_RET_STS_ERROR;
232     FND_MESSAGE.SET_NAME('ONT','OE_BOOK_REQUIRED_ATTRIBUTE');
233     FND_MESSAGE.SET_TOKEN('ATTRIBUTE',
234       OE_Order_UTIL.Get_Attribute_Name('INVOICE_TO_ORG_ID'));
235     OE_MSG_PUB.ADD;
236   END IF;
237 
238   IF p_header_rec.tax_exempt_flag IS NULL
239   THEN
240     x_return_status := FND_API.G_RET_STS_ERROR;
241     FND_MESSAGE.SET_NAME('ONT','OE_BOOK_REQUIRED_ATTRIBUTE');
242     FND_MESSAGE.SET_TOKEN('ATTRIBUTE',
243       OE_Order_UTIL.Get_Attribute_Name('TAX_EXEMPT_FLAG'));
244     OE_MSG_PUB.ADD;
245   END IF;
246 
247 
248   -- Fix bug 1262790
249   -- Ship To Org and Payment Term are required only on regular or
250   -- MIXED orders, NOT on RETURN orders
251 
252   IF p_header_rec.order_category_code <>
253                OE_GLOBALS.G_RETURN_CATEGORY_CODE THEN
254 
255     IF p_header_rec.ship_to_org_id IS NULL
256     THEN
257       x_return_status := FND_API.G_RET_STS_ERROR;
258       FND_MESSAGE.SET_NAME('ONT','OE_BOOK_REQUIRED_ATTRIBUTE');
259       FND_MESSAGE.SET_TOKEN('ATTRIBUTE',
260         OE_Order_UTIL.Get_Attribute_Name('SHIP_TO_ORG_ID'));
261       OE_MSG_PUB.ADD;
262     END IF;
263 
264     IF p_header_rec.payment_term_id IS NULL
265     THEN
266       x_return_status := FND_API.G_RET_STS_ERROR;
267       FND_MESSAGE.SET_NAME('ONT','OE_BOOK_REQUIRED_ATTRIBUTE');
268       FND_MESSAGE.SET_TOKEN('ATTRIBUTE',
269         OE_Order_UTIL.Get_Attribute_Name('PAYMENT_TERM_ID'));
270       OE_MSG_PUB.ADD;
271     END IF;
272 
273   END IF;
274 
275 --key transaction dates
276    IF (OE_CODE_CONTROL.CODE_RELEASE_LEVEL >= '110509' and p_header_rec.order_firmed_date > p_header_rec.booked_date) THEN
277        x_return_status := FND_API.G_RET_STS_ERROR;
278        FND_MESSAGE.SET_NAME('ONT','ONT_ORDER_FIRMED_DATE_INVALID');
279        OE_MSG_PUB.ADD;
280    END IF;
281 --end
282 
283   -- Check for additional required fields based on flags set
284   -- at the order type: agreement, customer po number
285 
286   l_order_type_rec := OE_Order_Cache.Load_Order_Type
287                       (p_header_rec.order_type_id);
288 
289   IF ( l_order_type_rec.agreement_required_flag = 'Y' AND
290        p_header_rec.agreement_id IS NULL)
291   THEN
292     x_return_status := FND_API.G_RET_STS_ERROR;
293     FND_MESSAGE.SET_NAME('ONT','OE_BOOK_REQUIRED_ATTRIBUTE');
294     FND_MESSAGE.SET_TOKEN('ATTRIBUTE',
295     OE_Order_UTIL.Get_Attribute_Name('AGREEMENT_ID'));
296     OE_MSG_PUB.ADD;
297   END IF;
298 
299   IF ( l_order_type_rec.require_po_flag = 'Y' AND
300        p_header_rec.cust_po_number IS NULL)
301   THEN
302     x_return_status := FND_API.G_RET_STS_ERROR;
303     FND_MESSAGE.SET_NAME('ONT','OE_BOOK_REQUIRED_ATTRIBUTE');
304     FND_MESSAGE.SET_TOKEN('ATTRIBUTE',
305     OE_Order_UTIL.Get_Attribute_Name('CUST_PO_NUMBER'));
306     OE_MSG_PUB.ADD;
307   END IF;
308 
309 
310   -- Conversion Type Related Checks
311 
312   -- IF SOB currency is dIFferent from order currency,
313   -- conversion type is required
314 
315   IF p_header_rec.conversion_type_code IS NULL
316   THEN
317      l_set_of_books_rec := OE_Order_Cache.Load_Set_Of_Books;
318 
319      IF ( l_set_of_books_rec.currency_code <>
320       p_header_rec.transactional_curr_code) THEN
321       x_return_status := FND_API.G_RET_STS_ERROR;
322       FND_MESSAGE.SET_NAME('ONT','OE_VAL_REQ_NON_BASE_CURRENCY');
323       FND_MESSAGE.SET_TOKEN
324       ('ORDER_CURRENCY',p_header_rec.transactional_curr_code);
325       FND_MESSAGE.SET_TOKEN('SOB_CURRENCY',l_set_of_books_rec.currency_code);
326       OE_MSG_PUB.ADD;
327      END IF;
328 
329   -- IF conversion type is 'User', conversion rate AND conversion rate date
330   -- required.
331 
332   ELSIF p_header_rec.conversion_type_code = 'User'
333   THEN
334 
335     IF p_header_rec.conversion_rate IS NULL OR
336        p_header_rec.conversion_rate_date IS NULL
337     THEN
338       x_return_status := FND_API.G_RET_STS_ERROR;
339       FND_MESSAGE.SET_NAME('ONT','OE_VAL_USER_CONVERSION_TYPE');
340       OE_MSG_PUB.ADD;
341     END IF;
342   END IF; -- END of checks based on conversion type
343 
344 
345   -- Checks based on payment type attached to the order
346 
347   IF p_header_rec.payment_type_code IS NOT NULL THEN
348 
349     -- payment amount should be specIFied
350 
351     IF    OE_PREPAYMENT_UTIL.IS_MULTIPLE_PAYMENTS_ENABLED = FALSE
352     AND   p_header_rec.payment_type_code <> 'CREDIT_CARD'
353     AND   p_header_rec.payment_amount IS NULL
354     THEN
355       x_return_status := FND_API.G_RET_STS_ERROR;
356       FND_MESSAGE.SET_NAME('ONT','OE_BOOK_REQUIRED_ATTRIBUTE');
357       FND_MESSAGE.SET_TOKEN('ATTRIBUTE',
358       OE_Order_UTIL.Get_Attribute_Name('PAYMENT_AMOUNT'));
359       OE_MSG_PUB.ADD;
360     END IF;
361 
362     -- check number required IF payment type is Check
363 
364     IF (p_header_rec.payment_type_code = 'CHECK' AND
365         p_header_rec.check_number IS NULL )
366     THEN
367       x_return_status := FND_API.G_RET_STS_ERROR;
368       FND_MESSAGE.SET_NAME('ONT','OE_VAL_CHECK_NUM_REQD');
369       OE_MSG_PUB.ADD;
370     END IF;
371 
372     -- credit card holder name, number AND expiration date
373     -- required for payment type of Credit Card
374 
375     /*
376     ** Following Validation Moved to Authorize Credit Card
377     ** Payment Routine. Not required anymore at BOOKING.
378     IF p_header_rec.payment_type_code = 'CREDIT_CARD' THEN
379       IF p_header_rec.credit_card_holder_name IS NULL
380       OR p_header_rec.credit_card_number IS NULL
381       OR p_header_rec.credit_card_expiration_date IS NULL
382       THEN
383       x_return_status := FND_API.G_RET_STS_ERROR;
384       FND_MESSAGE.SET_NAME('ONT','OE_VAL_CREDIT_CARD_REQD');
385       OE_MSG_PUB.ADD;
386       END IF;
387     END IF;
388     */
389 
390   END IF; -- END of checks related to payment type
391 
392     oe_debug_pub.add('Exiting OE_VALIDATE_HEADER.CHECK_BOOK_REQD',1);
393 EXCEPTION
394   WHEN OTHERS THEN
395     x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
396 
397     IF OE_MSG_PUB.Check_Msg_Level (OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
398     THEN
399       OE_MSG_PUB.Add_Exc_Msg
400       (  G_PKG_NAME ,
401         'Check_Book_Reqd_Attributes'
402       );
403     END IF;
404 
405     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
406 END Check_Book_Reqd_Attributes;
407 
408 
409 
410 /*-------------------------------------------------------
411 PROCEDURE:   Validate_Order_Type
412 Description:
413 --------------------------------------------------------*/
414 
415 Procedure Validate_Order_Type(p_order_type_id     IN NUMBER,
416                               p_old_order_type_id IN NUMBER,
417                               p_header_id         IN NUMBER,
418                               p_operation         IN VARCHAR2)
419 IS
420 lexists      varchar2(30);
421 lprocessname varchar2(80);
422 BEGIN
423 
424   oe_debug_pub.add('Entering OE_VALIDATE_HEADER.Validate_Order_Type',1);
425   IF p_operation = OE_GLOBALS.G_OPR_UPDATE
426   THEN
427     IF NOT OE_GLOBALS.EQUAL(p_order_type_id
428                            ,p_old_Order_type_id)
429     THEN
430       SELECT root_activity
431       into   lprocessname
432       from   wf_items_v
433       where  item_key = to_char(p_header_id)
434       AND    item_type = 'OEOH'
435       AND rownum = 1;
436 
437       SELECT 'EXISTS'
438       INTO   lexists
439       FROM   oe_workflow_assignments a
440       WHERE  a.order_type_id = p_order_type_id
441       AND    a.process_name = lprocessname
442       AND    a.line_type_id IS NULL
443       AND    a.end_date_active is null
444       AND    rownum = 1;
445     END IF;
446   END IF;
447 
448    oe_debug_pub.add('Exiting OE_VALIDATE_HEADER.Validate_Order_Type',1);
449 EXCEPTION
450   WHEN NO_DATA_FOUND THEN
451     FND_MESSAGE.SET_NAME('ONT','OE_FLOW_CNT_CHANGE');
452     OE_MSG_PUB.ADD;
453     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
454 
455   WHEN OTHERS THEN
456     IF OE_MSG_PUB.Check_Msg_Level (OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
457     THEN
458       OE_MSG_PUB.Add_Exc_Msg
459       ( G_PKG_NAME ,
460         'Validate_Order_Type'
461       );
462     END IF;
463     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
464 END Validate_Order_type;
465 
466 -- bug 1618229.
467 -- Procedure to validate if the currency matches the currency for
468 -- the commitment on order line if there is any.
469 Procedure Validate_Commitment_Currency(p_header_id 		 IN NUMBER
470                                       ,p_transactional_curr_code IN VARCHAR2
471                                       ,x_return_status		 OUT NOCOPY /* file.sql.39 change */ VARCHAR2)
472 IS
473 
474 l_commitment_id		NUMBER;
475 L_COMMITMENT_CURR_CODE	VARCHAR2(15);
476 
477 CURSOR l_line_csr IS
478 SELECT commitment_id
479 FROM   oe_order_lines
480 WHERE  header_id = p_header_id
481 AND    commitment_id is not null;
482 
483 BEGIN
484 
485   oe_debug_pub.add('Entering OE_VALIDATE_HEADER.Validate_Commitment_Currency',1);
486   OPEN l_line_csr;
487   LOOP
488     FETCH l_line_csr INTO l_commitment_id;
489     EXIT WHEN l_line_csr%NOTFOUND;
490 
491     -- get the currency code associated with the commitment.
492     IF l_commitment_id IS NOT NULL THEN
493       BEGIN
494         SELECT invoice_currency_code
495         INTO   l_commitment_curr_code
496         FROM   ra_customer_trx
497         WHERE  customer_trx_id = l_commitment_id;
498 
499       EXCEPTION WHEN NO_DATA_FOUND THEN
500         null;
501       END;
502 
503       oe_debug_pub.add('OEXLHDRB: commitment currency is: '||l_commitment_curr_code, 3);
504       oe_debug_pub.add('OEXLHDRB: order currency is: '||p_transactional_curr_code, 3);
505 
506       IF NOT OE_GLOBALS.EQUAL(l_commitment_curr_code, p_transactional_curr_code) THEN
507         x_return_status := FND_API.G_RET_STS_ERROR;
508         EXIT;
509       END IF;
510     END IF;
511 
512   END LOOP;
513   CLOSE l_line_csr;
514 
515   oe_debug_pub.add('Exiting OE_VALIDATE_HEADER.Validate_Commitment_Currency',1);
516 
517 EXCEPTION
518   WHEN NO_DATA_FOUND THEN
519     FND_MESSAGE.SET_NAME('ONT','OE_FLOW_CNT_CHANGE');
520     OE_MSG_PUB.ADD;
521     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
522 
523   WHEN OTHERS THEN
524     IF OE_MSG_PUB.Check_Msg_Level (OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
525     THEN
526       OE_MSG_PUB.Add_Exc_Msg
527       ( G_PKG_NAME ,
528         'Validate_Commitment_Currency'
529       );
530     END IF;
531     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
532 END Validate_Commitment_Currency;
533 
534 -- bug 1618229.
535 -- Procedure to validate if the the customer on order header matches
536 -- the customer for the commitment on order line if there is any.
537 Procedure Validate_Commitment_Customer(p_header_id 		 IN NUMBER
538                                       ,p_sold_to_org_id		 IN NUMBER
539                                       ,x_return_status		 OUT NOCOPY /* file.sql.39 change */ VARCHAR2)
540 IS
541 
542 l_commitment_id		NUMBER;
543 l_exists		VARCHAR2(1) := 'N';
544 
545 CURSOR l_line_csr IS
546 SELECT commitment_id
547 FROM   oe_order_lines
548 WHERE  header_id = p_header_id
549 AND    commitment_id is not null;
550 
551 Cursor cur_customer_relations (p_commitment_id IN NUMBER) is
552 	select 'Y'
553 	from ra_customer_trx ratrx
554 	where ratrx.customer_trx_id = p_commitment_id
555 	and ratrx.bill_to_customer_id = p_sold_to_org_id
556 
557 	union all
558 
559 	select 'Y'
560 	from ra_customer_trx ratrx
561 	where ratrx.customer_trx_id = p_commitment_id
562 	and exists (SELECT 1
563                    FROM   hz_cust_acct_relate_all hcar
564                    WHERE  hcar.cust_account_id = ratrx.bill_to_customer_id
565 		   and    hcar.related_cust_account_id = p_sold_to_org_id
566                    AND    hcar.status = 'A'
567 		   and    hcar.org_id = ratrx.org_id
568                    AND    hcar.bill_to_flag = 'Y');
569 
570 BEGIN
571 
572   oe_debug_pub.add('Entering OE_VALIDATE_HEADER.Validate_Commitment_Customer',1);
573   OPEN l_line_csr;
574   LOOP
575     FETCH l_line_csr INTO l_commitment_id;
576     EXIT WHEN l_line_csr%NOTFOUND;
577 
578     -- validate the sold_to_org_id of order against the customer for commitment.
579     oe_debug_pub.add('OEXLHDRB: l_commitment_id in validation is: '||l_commitment_id, 3);
580     IF l_commitment_id IS NOT NULL THEN
581       BEGIN
582         /*SELECT  MOAC_SQL_CHANGE 'Y'
583         INTO   l_exists
584         FROM   ra_customer_trx ratrx
585         WHERE  ratrx.bill_to_customer_id
586                IN (SELECT p_sold_to_org_id
587                    FROM   sys.dual
588                    UNION
589                    SELECT cust_account_id customer_id
590                    FROM   hz_cust_acct_relate_all h
591                    WHERE  related_cust_account_id = p_sold_to_org_id
592                    AND    status = 'A'
593 		   and    h.org_id = ratrx.org_id
594                    AND    bill_to_flag = 'Y')
595 
596         AND    ratrx.customer_trx_id = l_commitment_id;*/
597 	--bug 4729536
598 	OPEN cur_customer_relations(l_commitment_id);
599 	Fetch cur_customer_relations into l_exists;
600 	Close cur_customer_relations;
601 	--bug 4729536
602 
603 
604       EXCEPTION WHEN NO_DATA_FOUND THEN
605         null;
606       END;
607 
608       oe_debug_pub.add('OEXLHDRB: l_exists in validate_commitment_customer is: '||l_exists, 3);
609 
610       IF l_exists = 'N' THEN
611         x_return_status := FND_API.G_RET_STS_ERROR;
612         EXIT;
613       END IF;
614     END IF;
615 
616     END LOOP;
617     CLOSE l_line_csr;
618 
619     oe_debug_pub.add('Exiting OE_VALIDATE_HEADER.Validate_Commitment_Customer',1);
620 
621 EXCEPTION
622   WHEN NO_DATA_FOUND THEN
623     FND_MESSAGE.SET_NAME('ONT','OE_FLOW_CNT_CHANGE');
624     OE_MSG_PUB.ADD;
625     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
626 
627   WHEN OTHERS THEN
628     IF OE_MSG_PUB.Check_Msg_Level (OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
629     THEN
630       OE_MSG_PUB.Add_Exc_Msg
631       ( G_PKG_NAME ,
632         'Validate_Commitment_Customer'
633       );
634     END IF;
635     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
636 END Validate_Commitment_Customer;
637 
638 ---------------------------------------------------------------
639 -- FUNCTION Is_Duplicate_PO_Number
640 -- Added to fix bug 1162304
641 -- Returns TRUE if the PO number is referenced on another order
642 -- for the same customer
643 ---------------------------------------------------------------
644 
645 FUNCTION Is_Duplicate_PO_Number
646 ( p_cust_po_number                  IN VARCHAR2
647 , p_sold_to_org_id                  IN NUMBER
648 , p_header_id                       IN NUMBER
649 ) RETURN BOOLEAN
650 IS
651 l_duplicate_exists		varchar2(1);
652 l_check_duplicate varchar2(1) :='Y';  --Added for 5053933
653 BEGIN
654      --Added for 5053933 start
655      l_check_duplicate :=nvl(FND_PROFILE.VALUE('ONT_ENFORCE_DUP_PO'),'Y');
656      if l_check_duplicate='Y' then
657      --Added for ER 4760436 end
658 	SELECT /* MOAC_SQL_NO_CHANGE */ 'Y'
659 	INTO l_duplicate_exists
660 	FROM DUAL
661 	WHERE EXISTS (SELECT 'Y'
662 			    FROM OE_ORDER_HEADERS
663 			    WHERE HEADER_ID <> p_header_id
664 				 AND SOLD_TO_ORG_ID = p_sold_to_org_id
665 				 AND CUST_PO_NUMBER = p_cust_po_number )
666         OR EXISTS (SELECT 'Y'
667                    FROM OE_ORDER_LINES
668                    WHERE HEADER_ID <> p_header_id
669                      AND SOLD_TO_ORG_ID = p_sold_to_org_id
670                      AND CUST_PO_NUMBER = p_cust_po_number );
671      else
672        RETURN FALSE;
673      end if ; --l_check_duplicate
674      RETURN TRUE;
675 
676 EXCEPTION
677      WHEN NO_DATA_FOUND THEN
678         RETURN FALSE;
679 
680 END Is_Duplicate_PO_Number;
681 
682 ----------------------------------------------------------------------------
683 -- Procedure Validate_Blanket_Values
684 ----------------------------------------------------------------------------
685 
686 Procedure Validate_Blanket_Values
687 ( p_header_rec                IN  OE_Order_PUB.Header_Rec_Type,
688   p_old_header_rec            IN  OE_Order_PUB.Header_Rec_Type,
689   x_return_status             OUT NOCOPY VARCHAR2
690 )
691 
692 IS
693  l_sold_to_org_id                   NUMBER;
694  l_agreement_id                     NUMBER;
695  l_on_hold_flag                     VARCHAR2(1);
696  l_start_date_active                DATE;
697  l_end_date_active                  DATE;
698  l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
699  --FOR BUG 3192386
700  l_flow_status_code                 VARCHAR2(30);
701  -- Bug 3232544
702  lcustomer_relations    varchar2(1)  :=
703            OE_Sys_Parameters.VALUE('CUSTOMER_RELATIONSHIPS_FLAG');
704  l_exists               varchar2(1);
705  --For Bug 3257240
706  l_customer_name                    VARCHAR2(240);
707  l_customer_number                  NUMBER;
708 BEGIN
709     if l_debug_level > 0 then
710     OE_DEBUG_PUB.Add('Entering OE_VALIDATE_HEADER.Validate_Blanket_Values',1);
711     OE_DEBUG_PUB.Add('Blanket Number :'||p_header_rec.blanket_number,1);
712     end if;
713 
714     IF p_header_rec.blanket_number IS NULL THEN
715        FND_MESSAGE.SET_NAME('ONT', 'OE_BLKT_NO_BLANKET_LINE_NUM');
716        OE_MSG_PUB.Add;
717        x_return_status := FND_API.G_RET_STS_ERROR;
718        RETURN;
719     END IF;
720 
721    BEGIN
722    --Altered the sql for bug 3192386. Blankets in Negotiation or with Draft submitted as 'N' will not be selected.
723        SELECT  BH.AGREEMENT_ID,
724                BH.SOLD_TO_ORG_ID,
725                BHE.on_hold_flag,
726                BHE.START_DATE_ACTIVE,
727                BHE.END_DATE_ACTIVE,
728                NVL(BH.FLOW_STATUS_CODE,'ACTIVE')
729        INTO    l_agreement_id,
730                l_sold_to_org_id,
731                l_on_hold_flag,
732                l_start_date_active,
733                l_end_date_active,
734                l_flow_status_code
735        FROM    OE_BLANKET_HEADERS BH,OE_BLANKET_HEADERS_EXT BHE
736       WHERE    BH.ORDER_NUMBER  = p_header_rec.blanket_number
737         AND    BH.ORDER_NUMBER  = BHE.ORDER_NUMBER
738         AND    BH.SALES_DOCUMENT_TYPE_CODE = 'B'
739         AND    NVL(BH.TRANSACTION_PHASE_CODE,'F')='F'
740         AND    NVL(BH.DRAFT_SUBMITTED_FLAG,'Y') = 'Y';
741 
742    EXCEPTION
743 
744        WHEN NO_DATA_FOUND THEN
745              FND_MESSAGE.SET_NAME('ONT', 'OE_INVALID_ATTRIBUTE');
746              FND_MESSAGE.SET_TOKEN('ATTRIBUTE',
747                 OE_Order_Util.Get_Attribute_Name('BLANKET_NUMBER'));
748              OE_MSG_PUB.Add;
749              if l_debug_level > 0 then
750                  OE_DEBUG_PUB.Add('No Data Found when Validating Blanket',3);
751              end if;
752              RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
753         WHEN OTHERS THEN
754             if l_debug_level > 0 then
755                  OE_DEBUG_PUB.Add('When Others when Validating Blanket',3);
756             end if;
757              RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
758     END;
759 
760     IF ( p_header_rec.sold_to_org_id <> l_sold_to_org_id) AND
761               (NOT OE_GLOBALS.EQUAL(p_header_rec.sold_to_org_id
762                                   ,p_old_header_rec.sold_to_org_id) OR
763                NOT OE_GLOBALS.EQUAL(p_header_rec.blanket_number
764                                   ,p_old_header_rec.blanket_number) ) THEN
765        If l_debug_level > 0 then
766         oe_debug_pub.add('Customer on release does not match blanket customer');
767        End if;
768         if lcustomer_relations = 'Y' then
769            begin
770            SELECT 'Y'
771              INTO l_exists
772              FROM HZ_CUST_ACCT_RELATE
773             WHERE RELATED_CUST_ACCOUNT_ID = p_header_rec.sold_to_org_id
774               AND CUST_ACCOUNT_ID = l_sold_to_org_id
775               AND STATUS = 'A'
776               AND ROWNUM = 1;
777            exception
778              when no_data_found then
779                FND_MESSAGE.SET_NAME('ONT','OE_BLKT_INVALID_ATTRIBUTE');
780                FND_MESSAGE.SET_TOKEN('ATTRIBUTE',OE_Order_Util.Get_Attribute_Name
781                                                 ('SOLD_TO_ORG_ID'));
782                --for bug 3257240
783                OE_Id_To_Value.Sold_To_Org
784                 (   p_sold_to_org_id              => l_sold_to_org_id
785                 ,   x_org                         => l_customer_name
786                 ,   x_customer_number             => l_customer_number
787                 );
788                FND_MESSAGE.SET_TOKEN('BLANKET_VALUE',l_customer_name);
789                OE_MSG_PUB.Add;
790                x_return_status := FND_API.G_RET_STS_ERROR;
791            end;
792         else
793            FND_MESSAGE.SET_NAME('ONT','OE_BLKT_INVALID_ATTRIBUTE');
794            FND_MESSAGE.SET_TOKEN('ATTRIBUTE',OE_Order_Util.Get_Attribute_Name
795                                                 ('SOLD_TO_ORG_ID'));
796            --for bug 3257240
797            OE_Id_To_Value.Sold_To_Org
798             (   p_sold_to_org_id              => l_sold_to_org_id
799             ,   x_org                         => l_customer_name
800             ,   x_customer_number             => l_customer_number
801             );
802            FND_MESSAGE.SET_TOKEN('BLANKET_VALUE',l_customer_name);
803            OE_MSG_PUB.Add;
804            x_return_status := FND_API.G_RET_STS_ERROR;
805         end if;
806     END IF;
807 
808     IF (p_header_rec.order_category_code = 'ORDER')  AND ( l_on_hold_flag <> 'N') AND
809               (NOT OE_GLOBALS.EQUAL(p_header_rec.blanket_number
810                                   ,p_old_header_rec.blanket_number) ) THEN
811        if l_debug_level > 0 then
812            OE_DEBUG_PUB.Add('Blanket order is currently on hold', 1);
813       end if;
814       FND_MESSAGE.SET_NAME('ONT', 'OE_BLKT_ON_HOLD');
815       OE_MSG_PUB.Add;
816       x_return_status := FND_API.G_RET_STS_ERROR;
817     END IF;
818 
819     IF p_header_rec.order_category_code = 'ORDER' AND
820            (NOT OE_GLOBALS.EQUAL(p_header_rec.request_date
821                                   ,p_old_header_rec.request_date)   OR
822            NOT OE_GLOBALS.EQUAL(p_header_rec.blanket_number
823                                   ,p_old_header_rec.blanket_number)) AND
824          NOT (trunc(nvl(p_header_rec.request_date,sysdate))
825          BETWEEN trunc(l_start_date_active)
826          AND     trunc(nvl(l_end_date_active, nvl(p_header_rec.request_date,sysdate)))) THEN
827       if l_debug_level > 0 then
828           oe_debug_pub.add('Request date is not within active blanket  dates', 1);
829       end if;
830       FND_MESSAGE.SET_NAME('ONT', 'OE_INVALID_ATTRIBUTE');
831       FND_MESSAGE.SET_TOKEN('ATTRIBUTE',
832                 OE_Order_Util.Get_Attribute_Name('BLANKET_NUMBER'));
833       OE_MSG_PUB.Add;
834       x_return_status := FND_API.G_RET_STS_ERROR;
835     END IF;
836 
837     --For Bug 3192386
838     IF p_header_rec.order_category_code  = 'ORDER' AND
839                 l_flow_status_code <> 'ACTIVE'
840     THEN
841        if l_debug_level > 0 then
842           oe_debug_pub.add('Not an active Blanket for Release', 1);
843        end if;
844        FND_MESSAGE.SET_NAME('ONT', 'OE_INVALID_ATTRIBUTE');
845        FND_MESSAGE.SET_TOKEN('ATTRIBUTE',
846                 OE_Order_Util.Get_Attribute_Name('BLANKET_NUMBER'));
847        OE_MSG_PUB.Add;
848        x_return_status := FND_API.G_RET_STS_ERROR;
849     END IF;
850 
851     IF p_header_rec.agreement_id IS NOT NULL THEN
852        FND_MESSAGE.SET_NAME('ONT', 'OE_BLKT_AGREEMENT_EXISTS');
853        OE_MSG_PUB.Add;
854        x_return_status := FND_API.G_RET_STS_ERROR;
855     END IF;
856     if l_debug_level > 0 then
857          OE_DEBUG_PUB.Add('Exiting OE_VALIDATE_HEADER.Validate_Blanket_Values',1);
858     end if;
859 EXCEPTION
860 
861     WHEN FND_API.G_EXC_ERROR THEN
862         if l_debug_level > 0 then
863            OE_DEBUG_PUB.Add('Expected Error in Validate Blanket Values',2);
864         End if;
865 
866         x_return_status := FND_API.G_RET_STS_ERROR;
867 
868     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
869     if l_debug_level > 0 then
870         OE_DEBUG_PUB.Add('Unexpected Error in Validate Blanket Values:'||SqlErrm, 1);
871     End if;
872         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
873 
874 
875     WHEN OTHERS THEN
876 
877         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
878 
879         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
880         THEN
881             OE_MSG_PUB.Add_Exc_Msg
882             (   'OE_VALIDATE_LINE',
883               'Validate_Blanket_Values');
884         END IF;
885 
886 End Validate_Blanket_Values;
887 
888 
889 /*-------------------------------------------------------
890 PROCEDURE:    Entity
891 Description:
892 --------------------------------------------------------*/
893 
894 PROCEDURE Entity
895 (   x_return_status                 OUT NOCOPY /* file.sql.39 change */ VARCHAR2
896 ,   p_header_rec                    IN OUT NOCOPY /* file.sql.39 change */  OE_Order_PUB.Header_Rec_Type
897       /* modified the above line to fix the bug 2824240 */
898 ,   p_old_header_rec                IN  OE_Order_PUB.Header_Rec_Type :=
899                                         OE_Order_PUB.G_MISS_HEADER_REC
900 ,   p_validation_level              IN  NUMBER := FND_API.G_VALID_LEVEL_FULL
901       /* added the above line to fix the bug 2824240 */
902 )
903 IS
904 l_return_status     VARCHAR2(1) := FND_API.G_RET_STS_SUCCESS;
905 l_dummy             VARCHAR2(10);
906 l_price_list_rec    OE_Order_Cache.Price_List_Rec_Type;
907 -- l_order_type_rec    OE_Order_Cache.Order_Type_Rec_Type;
908 -- L_agreement_rec     OE_Order_Cache.Agreement_Rec_Type;
909 
910 l_agreement_name    varchar2(240);
911 l_agreement_revision    varchar2(50);
912 l_sold_to_org       number;
913 l_price_list_id     number;
914 lcustomer_relations varchar2(1);
915 l_list_type_code	VARCHAR2(30);
916 --MC Bgn
917 l_validate_result Varchar2(1):='N';
918 --MC End
919 L_COMMITMENT_CURR_CODE	VARCHAR2(15);
920 l_creation_status	VARCHAR2(30);
921 l_receipt_method_id	NUMBER;
922 l_cc_only               BOOLEAN := TRUE ;
923 l_customer_name		VARCHAR2(360);
924 l_temp                  pls_integer;
925 l_comt_cust_status  VARCHAR2(1) := FND_API.G_RET_STS_SUCCESS;
926 l_comt_curr_status  VARCHAR2(1) := FND_API.G_RET_STS_SUCCESS;
927 l_blanket_status    VARCHAR2(1) := FND_API.G_RET_STS_SUCCESS;
928 
929 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
930 l_control_rec               OE_GLOBALS.Control_Rec_Type;
931 l_header_rec                OE_Order_PUB.Header_Rec_Type := p_header_rec;
932 l_old_header_rec            OE_Order_PUB.Header_Rec_Type := p_old_header_rec;
933 /* Added the above  3 line to fix the bug 2824240 */
934 
935  -- eBTax Changes
936   l_ship_to_cust_Acct_id  hz_cust_Accounts.cust_Account_id%type;
937   l_ship_to_party_id      hz_cust_accounts.party_id%type;
938   l_ship_to_party_site_id hz_party_sites.party_site_id%type;
939   l_bill_to_cust_Acct_id  hz_cust_Accounts.cust_Account_id%type;
940   l_bill_to_party_id      hz_cust_accounts.party_id%type;
941   l_bill_to_party_site_id hz_party_sites.party_site_id%type;
942   l_org_id                NUMBER;
943 
944    cursor partyinfo(p_site_org_id HZ_CUST_SITE_USES_ALL.SITE_USE_ID%type) is
945      SELECT cust_acct.cust_account_id,
946             cust_Acct.party_id,
947             acct_site.party_site_id,
948             site_use.org_id
949       FROM
950             HZ_CUST_SITE_USES_ALL       site_use,
951             HZ_CUST_ACCT_SITES_ALL      acct_site,
952             HZ_CUST_ACCOUNTS_ALL        cust_Acct
953      WHERE  site_use.site_use_id = p_site_org_id
954        AND  site_use.cust_acct_site_id  = acct_site.cust_acct_site_id
955        and  acct_site.cust_account_id = cust_acct.cust_account_id;
956 
957 l_payment_count number;
958 
959 -- required for IN line level validation, a corner case
960 CURSOR ib_lines IS
961    SELECT l.line_id,
962    l.ib_current_location,
963    l.ib_installed_at_location
964    FROM oe_order_lines_all l
965    WHERE l.header_id=p_old_header_rec.header_id;
966  --added for bug 3739650
967    l_site_use_code   VARCHAR2(30);
968 BEGIN
969     oe_debug_pub.add('Enter OE_VALIDATE_HEADER.ENTITY',1);
970 
971     --  Check required attributes.
972  --lcustomer_relations := FND_PROFILE.VALUE('ONT_CUSTOMER_RELATIONSHIPS');
973  lcustomer_relations := OE_Sys_Parameters.VALUE('CUSTOMER_RELATIONSHIPS_FLAG');
974 
975     IF  p_header_rec.header_id IS NULL
976     THEN
977       l_return_status := FND_API.G_RET_STS_ERROR;
978 
979       IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_ERROR)
980       THEN
981         fnd_message.set_name('ONT','OE_ATTRIBUTE_REQUIRED');
982         FND_MESSAGE.SET_TOKEN('ATTRIBUTE',
983         OE_Order_UTIL.Get_Attribute_Name('HEADER_ID'));
984         OE_MSG_PUB.Add;
985       END IF;
986 
987     END IF;
988 
989     -- QUOTING changes
990     IF oe_code_control.code_release_level >= '110510'
991        AND p_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
992        AND p_header_rec.transaction_phase_code IS NULL
993     THEN
994       l_return_status := FND_API.G_RET_STS_ERROR;
995 
996       IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_ERROR)
997       THEN
998         fnd_message.set_name('ONT','OE_ATTRIBUTE_REQUIRED');
999         FND_MESSAGE.SET_TOKEN('ATTRIBUTE',
1000         OE_Order_UTIL.Get_Attribute_Name('TRANSACTION_PHASE_CODE'));
1001         OE_MSG_PUB.Add;
1002       END IF;
1003 
1004     END IF;
1005 
1006 
1007     ----------------------------------------------------------
1008     --  Check rest of required attributes here.
1009     ----------------------------------------------------------
1010 
1011     IF p_header_rec.order_type_id IS NULL
1012     THEN
1013       l_return_status := FND_API.G_RET_STS_ERROR;
1014 
1015       IF OE_MSG_PUB.Check_Msg_Level (OE_MSG_PUB.G_MSG_LVL_ERROR)
1016       THEN
1017         fnd_message.set_name('ONT','OE_ATTRIBUTE_REQUIRED');
1018         FND_MESSAGE.SET_TOKEN('ATTRIBUTE',
1019         OE_Order_UTIL.Get_Attribute_Name('ORDER_TYPE_ID'));
1020         OE_MSG_PUB.Add;
1021       END IF;
1022     ELSE
1023       Validate_Order_Type
1024                 (p_order_type_id     => p_header_rec.order_type_id,
1025                  p_old_order_type_id => p_old_header_rec.order_type_id,
1026                  p_header_id         => p_header_rec.header_id,
1027                  p_operation         => p_header_rec.operation);
1028     END IF;
1029 
1030 
1031     IF p_header_rec.transactional_curr_code IS NULL
1032     THEN
1033       l_return_status := FND_API.G_RET_STS_ERROR;
1034 
1035       IF OE_MSG_PUB.Check_Msg_Level (OE_MSG_PUB.G_MSG_LVL_ERROR)
1036       THEN
1037         fnd_message.set_name('ONT','OE_ATTRIBUTE_REQUIRED');
1038         FND_MESSAGE.SET_TOKEN('ATTRIBUTE',
1039         OE_Order_UTIL.Get_Attribute_Name('TRANSACTIONAL_CURR_CODE'));
1040         OE_MSG_PUB.Add;
1041       END IF;
1042 
1043     END IF;
1044 
1045 
1046     --  Return Error IF a required attribute is missing.
1047     IF l_return_status = FND_API.G_RET_STS_ERROR
1048     THEN
1049         if l_debug_level > 0 then
1050            oe_debug_pub.add('reqd attribute missing');
1051         end if;
1052         RAISE FND_API.G_EXC_ERROR;
1053     END IF;
1054 
1055     ----------------------------------------------------------
1056     --  Check conditionally required attributes here.
1057     ----------------------------------------------------------
1058 
1059     -- QUOTING changes
1060     IF oe_code_control.code_release_level >= '110510' THEN
1061 
1062        Check_Negotiation_Attributes(p_header_rec
1063                                    ,p_old_header_rec
1064                                    ,l_return_status
1065                                    );
1066 
1067     ELSE
1068 
1069        -- Feature not supported prior to 11i10, raise error
1070        IF p_header_rec.transaction_phase_code = 'N' THEN
1071           FND_MESSAGE.SET_NAME('ONT','OE_QUOTE_INVALID_RELEASE');
1072           OE_MSG_PUB.ADD;
1073           RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1074        END IF;
1075 
1076     END IF;
1077     -- QUOTING changes END
1078 
1079 
1080     --  Check attributes required for booked header
1081     IF p_header_rec.booked_flag = 'Y' THEN
1082 
1083       Check_Book_Reqd_Attributes
1084       ( p_header_rec      => p_header_rec
1085       , x_return_status    => l_return_status
1086        );
1087 
1088     END IF;
1089 
1090 
1091 
1092 
1093     --bug6441512
1094    IF p_header_rec.tax_exempt_flag ='S'  THEN
1095 
1096       -- Check for Tax exempt number/Tax exempt reason.
1097 
1098       IF (p_header_rec.tax_exempt_number IS NOT NULL AND
1099           p_header_rec.tax_exempt_number <> FND_API.G_MISS_CHAR)
1100           OR
1101          (p_header_rec.tax_exempt_reason_code IS NOT NULL AND
1102           p_header_rec.tax_exempt_reason_code <> FND_API.G_MISS_CHAR) THEN
1103           l_return_status := FND_API.G_RET_STS_ERROR;
1104 
1105           IF OE_MSG_PUB.Check_Msg_Level (OE_MSG_PUB.G_MSG_LVL_ERROR)
1106           THEN
1107             fnd_message.set_name('ONT','OE_NO_TAX_EXEMPTION');
1108             OE_MSG_PUB.Add;
1109           END IF;
1110       END IF;
1111 
1112    END IF;
1113 
1114 
1115    --bug6441512
1116     IF p_header_rec.tax_exempt_flag = 'E'     THEN
1117 
1118          --bug6732513
1119 	/* IF p_header_rec.tax_exempt_number IS NULL  OR
1120 		 p_header_rec.tax_exempt_number = FND_API.G_MISS_CHAR
1121 	      THEN
1122 
1123 		 l_return_status := FND_API.G_RET_STS_ERROR;
1124 
1125 		 IF OE_MSG_PUB.Check_Msg_Level (OE_MSG_PUB.G_MSG_LVL_ERROR)
1126 		 THEN
1127 	          fnd_message.set_name('ONT','OE_TAX_EXEMPTION_REQUIRED');
1128 	          OE_MSG_PUB.Add;
1129 		 END IF;
1130 
1131            END IF; */
1132 
1133 
1134 
1135 	IF p_header_rec.tax_exempt_reason_code IS NULL  OR
1136 		 p_header_rec.tax_exempt_reason_code = FND_API.G_MISS_CHAR
1137 	      THEN
1138 		 l_return_status := FND_API.G_RET_STS_ERROR;
1139 
1140 	         IF OE_MSG_PUB.Check_Msg_Level (OE_MSG_PUB.G_MSG_LVL_ERROR)
1141 	         THEN
1142 	           fnd_message.set_name('ONT','OE_ATTRIBUTE_REQUIRED');
1143 	           FND_MESSAGE.SET_TOKEN('ATTRIBUTE',
1144 	           OE_Order_UTIL.Get_Attribute_Name('TAX_EXEMPT_REASON_CODE'));
1145 	           OE_MSG_PUB.Add;
1146 	         END IF;
1147 
1148 	END IF;
1149 
1150    END IF; -- IF Tax handling is exempt
1151 
1152 
1153      --bug6441512
1154   IF p_header_rec.tax_exempt_flag ='R'  THEN
1155 
1156       IF (p_header_rec.tax_exempt_number IS NOT NULL AND
1157           p_header_rec.tax_exempt_number <> FND_API.G_MISS_CHAR)
1158           OR
1159          (p_header_rec.tax_exempt_reason_code IS NOT NULL AND
1160           p_header_rec.tax_exempt_reason_code <> FND_API.G_MISS_CHAR)
1161       THEN
1162           l_return_status := FND_API.G_RET_STS_ERROR;
1163 
1164           IF OE_MSG_PUB.Check_Msg_Level (OE_MSG_PUB.G_MSG_LVL_ERROR)
1165           THEN
1166             fnd_message.set_name('ONT','OE_TAX_EXEMPTION_NOT_ALLOWED');
1167             OE_MSG_PUB.Add;
1168           END IF;
1169       END IF;
1170 
1171  END IF;
1172 
1173     --  Return Error IF a conditionally required attribute is missing.
1174 
1175     IF l_return_status = FND_API.G_RET_STS_ERROR
1176     THEN
1177       RAISE FND_API.G_EXC_ERROR;
1178     END IF;
1179 
1180 
1181     ----------------------------------------------------------------
1182     -- VALIDATE ATTRIBUTE DEPENDENCIES
1183     ----------------------------------------------------------------
1184 
1185     oe_debug_pub.add('old price ' ||  p_old_header_rec.price_list_id,2);
1186     oe_debug_pub.add('New price ' ||  p_header_rec.price_list_id,2);
1187     oe_debug_pub.add('old curr ' ||  p_old_header_rec.transactional_curr_code,2);
1188     oe_debug_pub.add('New curr ' ||  p_header_rec.transactional_curr_code,2);
1189     -- Validate currency
1190 
1191     l_price_list_rec :=OE_Order_Cache.Load_Price_List (p_header_rec.price_list_id );
1192 
1193     --Added OR condition for CREATE Operation for bug 5060064
1194 
1195     IF (p_header_rec.price_list_id <>
1196         Nvl(p_old_header_rec.price_list_id,FND_API.G_MISS_NUM) OR
1197         p_header_rec.transactional_curr_code <>
1198         p_old_header_rec.transactional_curr_code OR
1199         p_header_rec.operation = OE_GLOBALS.G_OPR_CREATE ) AND
1200         p_header_rec.price_list_id IS NOT NULL
1201     THEN
1202        Begin
1203        QP_UTIL_PUB.Validate_Price_list_Curr_code(p_header_rec.price_list_id,
1204                                                  p_header_rec.transactional_curr_code,
1205                                                  p_header_rec.pricing_date,
1206                                                  l_validate_result);
1207        Exception when others then
1208             IF OE_MSG_PUB.Check_Msg_Level (OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
1209             THEN
1210 
1211               OE_MSG_PUB.Add_Exc_Msg
1212               (  G_PKG_NAME ,
1213                 'OE_VALIDATE_HEADER-QP_UTIL_PUB'
1214                );
1215             END IF;
1216             Oe_Debug_Pub.Add('Error when calling QP_UTIL_PUB.Validate_Price_list_Curr_code:'||SQLERRM);
1217             RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1218 
1219        End;
1220 
1221       Oe_Debug_Pub.add(' M Currency:'||l_validate_result);
1222       IF l_validate_result = 'N' THEN
1223         Begin
1224           Select 1
1225           into   l_temp
1226           From   Oe_Order_Lines_All
1227           Where  header_id =   p_header_rec.header_id
1228           and    calculate_price_flag in ('P','N')
1229           and    rownum = 1;
1230 
1231         Exception when no_data_found then
1232 --retro{
1233           /* Added the following if condition to fix the bug 2824240 */
1234           IF p_validation_level = OE_GLOBALS.G_VALID_LEVEL_PARTIAL AND
1235              p_header_rec.operation = 'CREATE'
1236           THEN
1237 	     IF(p_header_rec.order_source_id=27) THEN
1238 	       p_header_rec.price_list_id := OE_RETROBILL_PVT.Get_First_Line_Price_List_Id;
1239 	     ELSE
1240                p_header_rec.price_list_id := NULL;
1241 	     END IF;
1242           ELSIF p_validation_level = OE_GLOBALS.G_VALID_PARTIAL_WITH_DEF AND
1243                 p_header_rec.operation = 'CREATE'
1244           THEN
1245 	     IF(p_header_rec.order_source_id=27) THEN
1246 	       p_header_rec.price_list_id := OE_RETROBILL_PVT.Get_First_Line_Price_List_Id;
1247 	     ELSE
1248                p_header_rec.price_list_id  := FND_API.G_MISS_NUM;
1249              END IF;
1250 --retro}
1251              l_header_rec                := p_header_rec;
1252              l_old_header_rec            := p_old_header_rec;
1253              l_control_rec.controlled_operation := TRUE;
1254              l_control_rec.write_to_DB          := FALSE ;
1255              l_control_rec.process              := FALSE ;
1256              Oe_Order_Pvt.Header
1257              (    p_validation_level    => FND_API.G_VALID_LEVEL_NONE
1258              ,    p_control_rec         =>l_control_rec
1259              ,    p_x_header_rec        =>l_header_rec
1260              ,    p_x_old_header_rec    =>l_old_header_rec
1261              ,    x_return_status       =>l_return_status
1262               );
1263              p_header_rec                := l_header_rec;
1264              IF l_return_status  = FND_API.G_RET_STS_UNEXP_ERROR THEN
1265                  RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1266              ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
1267                  RAISE FND_API.G_EXC_ERROR;
1268              END IF;
1269 
1270           /* End of code added to fix the bug 2824240 */
1271 
1272           ELSE
1273              --no frozen lines, error condition
1274              l_return_status := FND_API.G_RET_STS_ERROR;
1275              fnd_message.set_name('ONT','OE_VAL_ORD_CURRENCY_MISMATCH');
1276              FND_MESSAGE.SET_TOKEN('ORDER_CURRENCY',p_header_rec.transactional_curr_code);
1277              FND_MESSAGE.SET_TOKEN('PRICE_LIST_CURRENCY',l_price_list_rec.currency_code);
1278              OE_MSG_PUB.Add;
1279           END IF;
1280         End;
1281       END IF;
1282     END IF; -- Price list or currency changed.
1283 
1284     -- bug 1618229, if the currency changed, also needs to revalidate commitment
1285     -- on the order line.
1286     IF NOT OE_GLOBALS.EQUAL(p_header_rec.transactional_curr_code,
1287            p_old_header_rec.transactional_curr_code) THEN
1288 
1289        oe_debug_pub.add('OEXLHDRB: before validating currency for commitment.', 3);
1290        Validate_Commitment_Currency
1291                   (p_header_id 	    	     => p_header_rec.header_id
1292                   ,p_transactional_curr_code => p_header_rec.transactional_curr_code
1293                   ,x_return_status 	     => l_comt_curr_status);
1294 
1295        IF l_comt_curr_status = FND_API.G_RET_STS_ERROR THEN
1296          l_return_status := FND_API.G_RET_STS_ERROR;
1297          Fnd_Message.Set_Name('ONT','ONT_INVALID_CURR_CHANGE');
1298          Fnd_message.set_token('REASON','ONT_COMMITMENT_ON_LINE',TRUE);
1299          OE_MSG_PUB.Add;
1300          oe_debug_pub.add('Error: currency code does not match the currency for the commitment.', 3);
1301          RAISE FND_API.G_EXC_ERROR;
1302        END IF;
1303      END IF;
1304 
1305     -- Currency_date, currency_rate should be null when type is null.
1306 
1307     IF p_header_rec.Conversion_type_code IS NULL
1308     THEN
1309       IF Nvl(p_header_rec.conversion_rate, FND_API.G_MISS_NUM)
1310                                         <> FND_API.G_MISS_NUM  OR
1311          Nvl(p_header_rec.conversion_rate_date, FND_API.G_MISS_DATE)
1312                                         <> FND_API.G_MISS_DATE
1313       THEN
1314         l_return_status :=  FND_API.G_RET_STS_ERROR;
1315         fnd_message.set_name('ONT','OE_VAL_CONVERSION_TYPE');
1316         OE_MSG_PUB.Add;
1317       END IF;
1318 
1319     END IF;
1320 
1321 --bug 3220059 for other conversion types, conversion rate should be NULL, not conversion rate date
1322    IF p_header_rec.conversion_type_code <> 'User' AND
1323         p_header_rec.conversion_rate IS NOT NULL
1324    THEN
1325     l_return_status := FND_API.G_RET_STS_ERROR;
1326     FND_MESSAGE.SET_NAME('ONT','OE_VALIDATION_CONV_TYPE');
1327     OE_MSG_PUB.ADD;
1328 
1329   END IF; -- END of checks based on conversion type
1330 
1331 
1332     --  Order Type has to be valid on the date ordered.
1333     IF (p_header_rec.order_type_id <>
1334         NVL(p_old_header_rec.order_type_id,FND_API.G_MISS_NUM)) OR
1335        (p_header_rec.ordered_date <>
1336         NVL(p_old_header_rec.ordered_date,FND_API.G_MISS_DATE))
1337     THEN
1338 
1339       IF p_header_rec.ordered_date IS NOT NULL THEN
1340 
1341         BEGIN
1342           -- Bug 3942415
1343           SELECT  'VALID'
1344           INTO  l_dummy
1345           FROM  OE_ORDER_TYPES_V
1346           WHERE  ORDER_TYPE_ID = p_header_rec.order_type_id
1347           AND  TRUNC(p_header_rec.ordered_date)
1348           BETWEEN NVL(START_DATE_ACTIVE,TRUNC(p_header_rec.ordered_date))
1349           AND     NVL( END_DATE_ACTIVE,TRUNC(p_header_rec.ordered_date));
1350           --  Valid Order Type.
1351 
1352         EXCEPTION
1353           WHEN NO_DATA_FOUND THEN
1354             l_return_status := FND_API.G_RET_STS_ERROR;
1355             fnd_message.set_name('ONT','OE_INVALID_ATTRIBUTE');
1356             FND_MESSAGE.SET_TOKEN('ATTRIBUTE',
1357             OE_Order_Util.Get_Attribute_Name('ORDER_TYPE_ID'));
1358             OE_MSG_PUB.Add;
1359 
1360           WHEN OTHERS THEN
1361 
1362             IF OE_MSG_PUB.Check_Msg_Level
1363                           (OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
1364             THEN
1365 
1366               OE_MSG_PUB.Add_Exc_Msg
1367               (  G_PKG_NAME ,
1368                 'Record - Order Type'
1369                );
1370             END IF;
1371 
1372             RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1373         END;
1374 
1375       END IF; -- date ordered is not null.
1376 
1377     END IF; -- Order Type or date has changed.
1378 
1379 
1380     --  Agreement depends on Order Type AND Sold To Org
1381     -- Added OR condition for CREATE Operation. Bug 5060064
1382 
1383     IF (NOT OE_GLOBALS.EQUAL(p_header_rec.order_type_id
1384                            ,p_old_header_rec.order_type_id)) OR
1385        (NOT OE_GLOBALS.EQUAL(p_header_rec.agreement_id
1386                            ,p_old_header_rec.agreement_id)) OR
1387        (NOT OE_GLOBALS.EQUAL(p_header_rec.sold_to_org_id
1388                            ,p_old_header_rec.sold_to_org_id)) OR
1389        (p_header_rec.operation = OE_GLOBALS.G_OPR_CREATE)
1390     THEN
1391 
1392       IF p_header_rec.agreement_id IS NOT NULL THEN
1393         -- commented by Geresh
1394         -- l_agreement_rec :=
1395         -- OE_Order_Cache.Load_Agreement (p_header_rec.agreement_id);
1396 
1397         BEGIN
1398 		BEGIN
1399             select list_type_code
1400 		  into l_list_type_code
1401 		  from qp_list_headers_vl
1402 		  where list_header_id = p_header_rec.price_list_id;
1403 		EXCEPTION WHEN NO_DATA_FOUND THEN
1404 		  null;
1405           END;
1406 
1407 /* Added the following code to fix the bug 2124912 */
1408 
1409                 BEGIN
1410                   --bug 5206956 added sold_to_org_id in the next 2 selects
1411                   select name,revision, sold_to_org_id
1412                   into l_agreement_name,l_agreement_revision, l_sold_to_org
1413                   from oe_agreements_vl
1414                   where agreement_id = p_header_rec.agreement_id;
1415 
1416                   select name,revision, sold_to_org_id
1417                   into l_agreement_name,l_agreement_revision, l_sold_to_org
1418                   from oe_agreements_vl
1419                   where agreement_id = p_header_rec.agreement_id
1420                   AND trunc(nvl(p_header_rec.pricing_date,sysdate)) between
1421                   trunc(nvl(START_DATE_ACTIVE,add_months(sysdate,-10000)))
1422                   AND  trunc(nvl(END_DATE_ACTIVE,add_months(sysdate,+10000)));
1423 
1424                 EXCEPTION
1425                  WHEN NO_DATA_FOUND THEN
1426                     /* Added the following if condition to fix the bug 2824240 */
1427                     IF p_validation_level = OE_GLOBALS.G_VALID_LEVEL_PARTIAL AND
1428                        p_header_rec.operation = 'CREATE'
1429                      THEN
1430                        p_header_rec.agreement_id := NULL;
1431                      ELSIF p_validation_level = OE_GLOBALS.G_VALID_PARTIAL_WITH_DEF AND
1432                            p_header_rec.operation = 'CREATE'
1433                      THEN
1434                        p_header_rec.agreement_id  := FND_API.G_MISS_NUM;
1435                        l_header_rec                := p_header_rec;
1436                        l_old_header_rec            := p_old_header_rec;
1437                        l_control_rec.controlled_operation := TRUE;
1438                        l_control_rec.write_to_DB          := FALSE ;
1439                        l_control_rec.process              := FALSE ;
1440                        Oe_Order_Pvt.Header
1441                        (    p_validation_level    => FND_API.G_VALID_LEVEL_NONE
1442                        ,    p_control_rec         =>l_control_rec
1443                        ,    p_x_header_rec        =>l_header_rec
1444                        ,    p_x_old_header_rec    =>l_old_header_rec
1445                        ,    x_return_status       =>l_return_status
1446                         );
1447                        p_header_rec                := l_header_rec;
1448                        IF l_return_status  = FND_API.G_RET_STS_UNEXP_ERROR THEN
1449                           RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1450                        ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
1451                           RAISE FND_API.G_EXC_ERROR;
1452                        END IF;
1453 
1454                     /* End of code added to fix the bug 2824240 */
1455                     ELSE
1456                       fnd_message.set_name('ONT', 'ONT_INVALID_AGREEMENT');
1457                       fnd_message.set_Token('AGREEMENT_NAME',l_agreement_name);
1458                       fnd_message.set_Token('REVISION',l_agreement_revision);
1459                       OE_MSG_PUB.Add;
1460                       oe_debug_pub.add('Invalid Agreement ',1);
1461                       raise FND_API.G_EXC_ERROR;
1462                     END IF;
1463                 END;
1464 
1465 /* End of code added to fix the bug 2124912 */
1466 
1467           IF NOT OE_GLOBALS.EQUAL(l_list_type_code,'PRL') THEN
1468 		-- any price list with 'PRL' type should be allowed to
1469 		-- be associated with any agreement according to bug 1386406.
1470 
1471             select name ,sold_to_org_id , price_list_id
1472             into l_agreement_name,l_sold_to_org,l_price_list_id
1473             from oe_agreements_v
1474             where agreement_id = p_header_rec.agreement_id
1475             AND trunc(nvl(p_header_rec.pricing_date,sysdate)) between
1476             trunc(nvl(START_DATE_ACTIVE,add_months(sysdate,-10000)))
1477             AND  trunc(nvl(END_DATE_ACTIVE,add_months(sysdate,+10000)));
1478 
1479             -- Geresh added
1480             IF l_price_list_id <> p_Header_rec.price_list_id
1481             THEN
1482               fnd_message.set_name('ONT', 'OE_INVALID_AGREEMENT_PLIST');
1483               fnd_message.set_Token
1484               ('AGREEMENT_NAME', l_agreement_name || sqlerrm);
1485               fnd_message.set_Token('PRICE_LIST1', p_Header_rec.price_list_id);
1486               fnd_message.set_Token('PRICE_LIST2', l_price_list_id);
1487               OE_MSG_PUB.Add;
1488               oe_debug_pub.add('Invalid Agreement +price_list_id combination',2);
1489               raise FND_API.G_EXC_ERROR;
1490             END IF;
1491           END IF;
1492 
1493    --bug 5206956 to check for customer relationships
1494         IF l_sold_to_org IS NOT NULL AND l_sold_to_org <> -1
1495                 AND NOT OE_GLOBALS.EQUAL(l_sold_to_org,p_header_rec.sold_to_org_id) THEN
1496                 IF nvl(lcustomer_relations,'N') = 'N' THEN
1497                         fnd_message.set_name('ONT', 'OE_INVALID_AGREEMENT');
1498                         fnd_message.set_Token('AGREEMENT_ID', p_header_rec.agreement_id);
1499                         fnd_message.set_Token('AGREEMENT_NAME', l_agreement_name);
1500                         fnd_message.set_Token('CUSTOMER_ID', p_header_rec.sold_to_org_id);
1501                         OE_MSG_PUB.Add;
1502                         IF l_debug_level > 0 then
1503                                 oe_debug_pub.add('Invalid Agreement +sold_org_id combination',2);
1504                         END IF;
1505                                 RAISE FND_API.G_EXC_ERROR;
1506         ELSIF lcustomer_relations = 'Y' THEN
1507 
1508                         BEGIN
1509                           SELECT        'VALID'
1510                           INTO  l_dummy
1511                           FROM  dual
1512                           WHERE         exists(
1513                         select 'x' from
1514                         hz_cust_acct_relate where
1515                         related_cust_account_id = p_header_rec.sold_to_org_id
1516                         and status = 'A'
1517                                 AND cust_account_id = l_sold_to_org
1518                                         );
1519 
1520                         EXCEPTION
1521                  WHEN NO_DATA_FOUND THEN
1522                         fnd_message.set_name('ONT', 'OE_INVALID_AGREEMENT');
1523                         fnd_message.set_Token('AGREEMENT_ID', p_header_rec.agreement_id);
1524                         fnd_message.set_Token('AGREEMENT_NAME', l_agreement_name);
1525                         fnd_message.set_Token('CUSTOMER_ID', p_header_rec.sold_to_org_id);
1526                         OE_MSG_PUB.Add;
1527                         IF l_debug_level > 0 then
1528                                 oe_debug_pub.add('Invalid Agreement +sold_org_id combination',2);
1529                         END IF;
1530                                 RAISE FND_API.G_EXC_ERROR;
1531                         END;
1532            END IF;
1533          END IF;
1534    --bug 5206956
1535 
1536 
1537 
1538         EXCEPTION
1539            WHEN NO_DATA_FOUND THEN
1540              fnd_message.set_name('ONT', 'OE_INVALID_AGREEMENT_PLIST');
1541              fnd_message.set_Token('AGREEMENT_NAME', l_agreement_name);
1542              fnd_message.set_Token('PRICE_LIST1', p_Header_rec.price_list_id);
1543              fnd_message.set_Token('PRICE_LIST2', l_price_list_id || sqlerrm);
1544              OE_MSG_PUB.Add;
1545              oe_debug_pub.add
1546              ('No Data Found Agreement+price_list_id combination',2);
1547              raise FND_API.G_EXC_ERROR;
1548         END;
1549 
1550        -- l_order_type_rec :=
1551        --  OE_Order_Cache.Load_Order_Type (p_header_rec.order_type_id);
1552 
1553 	   /***
1554         IF (l_agreement_rec.sold_to_org_id IS NOT NULL AND
1555             l_agreement_rec.sold_to_org_id <>
1556             p_header_rec.sold_to_org_id ) OR
1557             (l_order_type_rec.agreement_type_code IS NOT NULL AND
1558             l_agreement_rec.agreement_type_code <>
1559             l_order_type_rec.agreement_type_code ) THEN
1560            	l_return_status := FND_API.G_RET_STS_ERROR;
1561           	IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_ERROR)
1562           	THEN
1563             	 	fnd_message.set_name('ONT','OE_INVALID_AGREEMENT');
1564             		OE_MSG_PUB.Add;
1565           	END IF;
1566         END IF;
1567 	   ***/
1568 
1569       END IF;  --  Agreement is not null
1570 
1571     END IF; -- Agreement needed validation.
1572 
1573 
1574     --  Ship to Org id depends on sold to org.
1575     -- Added OR condition for CREATE Operation. Bug 5060064
1576     IF p_header_rec.ship_to_org_id IS NOT NULL AND
1577      ( NOT OE_GLOBALS.EQUAL(p_header_rec.ship_to_org_id
1578                            ,p_old_header_rec.ship_to_org_id)
1579        OR
1580        NOT OE_GLOBALS.EQUAL(p_header_rec.sold_to_org_id
1581                            ,p_old_header_rec.sold_to_org_id)
1582        OR (p_header_rec.operation = OE_GLOBALS.G_OPR_CREATE))
1583     THEN
1584 
1585       BEGIN
1586         oe_debug_pub.add
1587         ('ship_to_org_id :'||to_char(p_header_rec.ship_to_org_id),2);
1588         oe_debug_pub.add
1589         ('Customer Relation :'||lcustomer_relations,2);
1590 
1591     --lcustomer_relations := FND_PROFILE.VALUE('ONT_CUSTOMER_RELATIONSHIPS');
1592 
1593     IF nvl(lcustomer_relations,'N') = 'N' THEN
1594         oe_debug_pub.add
1595         ('Cr: No',2);
1596 
1597         SELECT 'VALID'
1598         INTO   l_dummy
1599         FROM   oe_ship_to_orgs_v
1600         WHERE  customer_id = p_header_rec.sold_to_org_id
1601         AND    site_use_id = p_header_rec.ship_to_org_id
1602         AND    status = 'A'
1603 	AND    address_status ='A'; --bug 2752321
1604 
1605    ELSIF lcustomer_relations = 'Y' THEN
1606         oe_debug_pub.add
1607         ('Cr: Yes Ship',2);
1608     --variable added for bug 3739650
1609     l_site_use_code := 'SHIP_TO' ;
1610     SELECT /* MOAC_SQL_CHANGE */ 'VALID'
1611     Into   l_dummy
1612     FROM   HZ_CUST_SITE_USES_ALL SITE,
1613 	   HZ_CUST_ACCT_SITES ACCT_SITE
1614     WHERE SITE.SITE_USE_ID     = p_header_rec.ship_to_org_id
1615     AND SITE.SITE_USE_CODE     = l_site_use_code
1616     AND SITE.CUST_ACCT_SITE_ID = ACCT_SITE.CUST_ACCT_SITE_ID
1617     AND SITE.STATUS = 'A'
1618     AND ACCT_SITE.STATUS ='A' AND --bug 2752321
1619      ACCT_SITE.CUST_ACCOUNT_ID in (
1620                     SELECT p_header_rec.sold_to_org_id FROM DUAL
1621                     UNION
1622                     SELECT CUST_ACCOUNT_ID FROM
1623                     HZ_CUST_ACCT_RELATE_ALL h  WHERE
1624                     RELATED_CUST_ACCOUNT_ID = p_header_rec.sold_to_org_id
1625 		    and h.org_id =acct_site.org_id
1626 			and ship_to_flag = 'Y' and status = 'A')
1627 	--bug 4205113
1628     AND EXISTS(SELECT 1 FROM HZ_CUST_ACCOUNTS WHERE CUST_ACCOUNT_ID = ACCT_SITE.CUST_ACCOUNT_ID AND STATUS='A')
1629     AND ROWNUM = 1;
1630         oe_debug_pub.add
1631         ('Cr: Yes- After the select',2);
1632    ELSIF lcustomer_relations = 'A' THEN
1633     SELECT  'VALID'
1634     INTO    l_dummy
1635     FROM    OE_SHIP_TO_ORGS_V   SHP
1636     WHERE   SHP.ORGANIZATION_ID =p_header_rec.ship_to_org_id
1637     AND     SHP.STATUS = 'A'
1638     AND     SHP.ADDRESS_STATUS ='A' --bug 2752321
1639     AND     SYSDATE BETWEEN NVL(SHP.START_DATE_ACTIVE, SYSDATE)
1640                     AND     NVL(SHP.END_DATE_ACTIVE, SYSDATE);
1641 
1642 
1643    END IF;
1644 
1645 
1646         --  Valid Ship To Org Id.
1647 
1648       EXCEPTION
1649 
1650         WHEN NO_DATA_FOUND THEN
1651         oe_debug_pub.add
1652         ('In: No data found',2);
1653           l_return_status := FND_API.G_RET_STS_ERROR;
1654           fnd_message.set_name('ONT','OE_INVALID_ATTRIBUTE');
1655           FND_MESSAGE.SET_TOKEN('ATTRIBUTE', OE_Order_Util.Get_Attribute_Name
1656                                              ('ship_to_org_id'));
1657           OE_MSG_PUB.Add;
1658 
1659         WHEN OTHERS THEN
1660 
1661           IF OE_MSG_PUB.Check_Msg_Level
1662              (OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
1663           THEN
1664             OE_MSG_PUB.Add_Exc_Msg
1665            (  G_PKG_NAME ,
1666               'Record - Ship To'
1667             );
1668           END IF;
1669           RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1670 
1671       END;
1672 
1673     END IF; -- Ship To needed validation.
1674 
1675     --  Deliver to Org id depends on sold to org.
1676     IF p_header_rec.deliver_to_org_id IS NOT NULL AND
1677        ( NOT OE_GLOBALS.EQUAL(p_header_rec.deliver_to_org_id
1678                              ,p_old_header_rec.deliver_to_org_id)
1679        OR
1680         NOT OE_GLOBALS.EQUAL(p_header_rec.sold_to_org_id
1681                             ,p_old_header_rec.sold_to_org_id)
1682        OR (p_header_rec.operation = OE_GLOBALS.G_OPR_CREATE))
1683     THEN
1684       BEGIN
1685 
1686       oe_debug_pub.add('deliver_to_org_id :'||to_char(p_header_rec.deliver_to_org_id),2);
1687       oe_debug_pub.add('Customer Relation :'||lcustomer_relations,2);
1688 
1689       IF nvl(lcustomer_relations,'N') = 'N' THEN
1690 
1691         oe_debug_pub.add('Cr: No',2);
1692 
1693         SELECT 'VALID'
1694         INTO   l_dummy
1695         FROM   oe_deliver_to_orgs_v
1696         WHERE  customer_id = p_header_rec.sold_to_org_id
1697         AND    site_use_id = p_header_rec.deliver_to_org_id
1698         AND    status = 'A'
1699 	AND    address_status ='A'; --bug 2752321
1700         --  Valid Deliver To Org Id.
1701 
1702       ELSIF lcustomer_relations = 'Y' THEN
1703         oe_debug_pub.add('Cr: Yes deliver',2);
1704      --variable added for bug 3739650
1705        l_site_use_code := 'DELIVER_TO' ;
1706         SELECT /* MOAC_SQL_CHANGE */ 'VALID'
1707          Into   l_dummy
1708          FROM   HZ_CUST_SITE_USES_ALL SITE,
1709 	        HZ_CUST_ACCT_SITES ACCT_SITE
1710         WHERE SITE.SITE_USE_ID     = p_header_rec.deliver_to_org_id
1711          AND SITE.SITE_USE_CODE    = l_site_use_code
1712          AND SITE.CUST_ACCT_SITE_ID = ACCT_SITE.CUST_ACCT_SITE_ID
1713          AND SITE.STATUS = 'A'
1714 	   AND ACCT_SITE.STATUS = 'A' AND --bug 2752321
1715          ACCT_SITE.CUST_ACCOUNT_ID in (
1716                     SELECT p_header_rec.sold_to_org_id FROM DUAL
1717                     UNION
1718                     SELECT CUST_ACCOUNT_ID FROM
1719                     HZ_CUST_ACCT_RELATE_ALL h WHERE
1720                     RELATED_CUST_ACCOUNT_ID = p_header_rec.sold_to_org_id
1721                     and h.org_id =acct_site.org_id
1722 			and ship_to_flag = 'Y' and status='A')
1723 	--bug 4205113
1724     AND EXISTS(SELECT 1 FROM HZ_CUST_ACCOUNTS WHERE CUST_ACCOUNT_ID = ACCT_SITE.CUST_ACCOUNT_ID AND STATUS='A')
1725     AND ROWNUM = 1;
1726         oe_debug_pub.add('Cr: Yes- After the select',2);
1727 
1728       ELSIF lcustomer_relations = 'A' THEN
1729 
1730         SELECT  'VALID'
1731          INTO    l_dummy
1732          FROM    OE_DELIVER_TO_ORGS_V   DEL
1733         WHERE   DEL.ORGANIZATION_ID =p_header_rec.deliver_to_org_id
1734           AND     DEL.STATUS = 'A'
1735 	  AND     DEL.ADDRESS_STATUS ='A' --bug 2752321
1736           AND     SYSDATE BETWEEN NVL(DEL.START_DATE_ACTIVE, SYSDATE)
1737                           AND     NVL(DEL.END_DATE_ACTIVE, SYSDATE);
1738 
1739 
1740       END IF;
1741 
1742 
1743       EXCEPTION
1744 
1745         WHEN NO_DATA_FOUND THEN
1746           l_return_status := FND_API.G_RET_STS_ERROR;
1747           fnd_message.set_name('ONT','OE_INVALID_ATTRIBUTE');
1748           FND_MESSAGE.SET_TOKEN('ATTRIBUTE',
1749           OE_Order_Util.Get_Attribute_Name('deliver_to_org_id'));
1750           OE_MSG_PUB.Add;
1751 
1752         WHEN OTHERS THEN
1753 
1754           IF OE_MSG_PUB.Check_Msg_Level
1755              (OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
1756           THEN
1757 
1758             OE_MSG_PUB.Add_Exc_Msg
1759             (  G_PKG_NAME ,
1760                'Record - Deliver To'
1761             );
1762           END IF;
1763 
1764           RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1765 
1766       END;
1767 
1768     END IF; -- Deliver To needed validation.
1769 
1770 
1771 
1772     --  Invoice to Org id depends on sold to org.
1773 
1774     IF p_header_rec.invoice_to_org_id IS NOT NULL AND
1775       ( NOT OE_GLOBALS.EQUAL(p_header_rec.invoice_to_org_id
1776                             ,p_old_header_rec.invoice_to_org_id) OR
1777         NOT OE_GLOBALS.EQUAL(p_header_rec.sold_to_org_id
1778                             ,p_old_header_rec.sold_to_org_id)
1779        OR (p_header_rec.operation = OE_GLOBALS.G_OPR_CREATE))
1780     THEN
1781       BEGIN
1782         oe_debug_pub.add
1783         ('invoice_to_org_id :'||to_char(p_header_rec.invoice_to_org_id),2);
1784 
1785 	   IF nvl(lcustomer_relations,'N') = 'N' THEN
1786 
1787         Select 'VALID'
1788         Into   l_dummy
1789         From   oe_invoice_to_orgs_v
1790         Where  customer_id = p_header_rec.sold_to_org_id
1791         AND    site_use_id = p_header_rec.invoice_to_org_id
1792         and    status = 'A'
1793 	and    address_status ='A'; --bug 2752321
1794     -- validation for lcustomer_relations=A is done at the attribute level.
1795     -- for Order entered in the Sales Order form , it is assumed that the
1796     -- invoice to org passed is the correct one
1797     ELSIF lcustomer_relations = 'Y' THEN
1798 
1799         oe_debug_pub.add
1800         ('Cr: Yes Inv',2);
1801   --variable added for bug 3739650
1802     l_site_use_code := 'BILL_TO' ;
1803     SELECT 'VALID'
1804     Into   l_dummy
1805     FROM   HZ_CUST_SITE_USES_ALL SITE,
1806 	   HZ_CUST_ACCT_SITES ACCT_SITE
1807     WHERE SITE.SITE_USE_ID     = p_header_rec.invoice_to_org_id
1808     AND SITE.SITE_USE_CODE     = l_site_use_code
1809     AND SITE.CUST_ACCT_SITE_ID = ACCT_SITE.CUST_ACCT_SITE_ID
1810     AND SITE.STATUS = 'A'
1811     AND ACCT_SITE.ORG_ID=SITE.ORG_ID
1812     AND ACCT_SITE.STATUS = 'A' AND
1813     ACCT_SITE.CUST_ACCOUNT_ID in (
1814                     SELECT p_header_rec.sold_to_org_id FROM DUAL
1815                     UNION
1816                     SELECT CUST_ACCOUNT_ID FROM
1817                     HZ_CUST_ACCT_RELATE_ALL h WHERE
1818                     RELATED_CUST_ACCOUNT_ID = p_header_rec.sold_to_org_id
1819 		    and h.org_id =site.org_id
1820 		    and bill_to_flag = 'Y' and status='A' )
1821     --bug 4205113
1822     AND EXISTS(SELECT 1 FROM HZ_CUST_ACCOUNTS WHERE CUST_ACCOUNT_ID = ACCT_SITE.CUST_ACCOUNT_ID AND STATUS='A')
1823     AND ROWNUM = 1;
1824     END IF;
1825 
1826 
1827       EXCEPTION
1828 
1829       WHEN NO_DATA_FOUND THEN
1830         l_return_status := FND_API.G_RET_STS_ERROR;
1831         fnd_message.set_name('ONT','OE_INVALID_ATTRIBUTE');
1832         FND_MESSAGE.SET_TOKEN('ATTRIBUTE',
1833         OE_Order_Util.Get_Attribute_Name('invoice_to_org_id'));
1834       OE_MSG_PUB.Add;
1835 
1836       WHEN OTHERS THEN
1837 
1838         IF OE_MSG_PUB.Check_Msg_Level (OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
1839         THEN
1840           OE_MSG_PUB.Add_Exc_Msg
1841           (  G_PKG_NAME ,
1842             'Record - Invoice To'
1843           );
1844         END IF;
1845 
1846         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1847       END;
1848 
1849     END IF; -- Invoice to org needed validation.
1850 
1851     -- QUOTING changes
1852     --  Customer Location depends on Sold To Org
1853 
1854     IF p_header_rec.sold_to_site_use_id IS NOT NULL AND
1855       ( NOT OE_GLOBALS.EQUAL(p_header_rec.sold_to_site_use_id
1856                             ,p_old_header_rec.sold_to_site_use_id) OR
1857         NOT OE_GLOBALS.EQUAL(p_header_rec.sold_to_org_id
1858                             ,p_old_header_rec.sold_to_org_id)
1859        OR (p_header_rec.operation = OE_GLOBALS.G_OPR_CREATE))
1860     THEN
1861 
1862       BEGIN
1863 
1864         SELECT /* MOAC_SQL_CHANGE */ 'VALID'
1865         INTO    l_dummy
1866         FROM
1867              HZ_CUST_SITE_USES_ALL   SITE,
1868              HZ_CUST_ACCT_SITES  ACCT_SITE
1869         WHERE
1870              SITE.SITE_USE_ID = p_header_rec.sold_to_site_use_id
1871              AND  SITE.SITE_USE_CODE = 'SOLD_TO'
1872              AND  SITE.CUST_ACCT_SITE_ID = ACCT_SITE.CUST_ACCT_SITE_ID
1873              AND  ACCT_SITE.CUST_ACCOUNT_ID = p_header_rec.sold_to_org_id
1874              AND  SITE.STATUS = 'A'
1875              AND  ACCT_SITE.STATUS='A';
1876 
1877         --  Valid Customer Location
1878 
1879 
1880 
1881       EXCEPTION
1882 
1883         WHEN NO_DATA_FOUND THEN
1884           l_return_status := FND_API.G_RET_STS_ERROR;
1885           fnd_message.set_name('ONT','OE_INVALID_ATTRIBUTE');
1886           FND_MESSAGE.SET_TOKEN('ATTRIBUTE',
1887           OE_Order_Util.Get_Attribute_Name('SOLD_TO_SITE_USE_ID'));
1888           OE_MSG_PUB.Add;
1889 
1890         WHEN OTHERS THEN
1891 
1892          IF OE_MSG_PUB.Check_Msg_Level
1893          (OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
1894          THEN
1895 
1896            OE_MSG_PUB.Add_Exc_Msg
1897            (  G_PKG_NAME ,
1898              'Record - Customer Location'
1899            );
1900          END IF;
1901 
1902          RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1903 
1904       END;
1905 
1906     END IF;
1907     -- QUOTING changes
1908 
1909     -- end customer contact id depends on end customer id
1910     IF p_header_rec.end_customer_contact_id IS NOT NULL AND
1911      ( NOT OE_GLOBALS.EQUAL(p_header_rec.end_customer_contact_id
1912                            ,p_old_header_rec.end_customer_contact_id) OR
1913        NOT OE_GLOBALS.EQUAL(p_header_rec.end_customer_id
1914                            ,p_old_header_rec.end_customer_id)
1915        OR (p_header_rec.operation = OE_GLOBALS.G_OPR_CREATE))
1916     THEN
1917 
1918       BEGIN
1919 
1920         SELECT  'VALID'
1921         INTO  l_dummy
1922         FROM
1923              HZ_CUST_ACCOUNT_ROLES ACCT_ROLE
1924         WHERE
1925              ACCT_ROLE.CUST_ACCOUNT_ROLE_ID = p_header_rec.end_customer_contact_id
1926              AND  ACCT_ROLE.CUST_ACCOUNT_ID = p_header_rec.end_customer_id
1927              AND  ROWNUM = 1
1928              AND  ACCT_ROLE.ROLE_TYPE = 'CONTACT'
1929              AND  STATUS= 'A';
1930 
1931         --  Valid Sold To Contact
1932 
1933       EXCEPTION
1934 
1935         WHEN NO_DATA_FOUND THEN
1936           l_return_status := FND_API.G_RET_STS_ERROR;
1937           fnd_message.set_name('ONT','OE_INVALID_ATTRIBUTE');
1938           FND_MESSAGE.SET_TOKEN('ATTRIBUTE',
1939           OE_Order_Util.Get_Attribute_Name('END_CUSTOMER_CONTACT_ID'));
1940           OE_MSG_PUB.Add;
1941 
1942         WHEN OTHERS THEN
1943           IF OE_MSG_PUB.Check_Msg_Level
1944           ( OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
1945           THEN
1946             OE_MSG_PUB.Add_Exc_Msg
1947             (  G_PKG_NAME ,
1948               'Record - End Customer Contact'
1949              );
1950           END IF;
1951 
1952           RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1953 
1954       END; -- BEGIN
1955 
1956     END IF; -- End Customer contact needed validation.
1957 
1958 
1959     IF p_header_rec.end_customer_site_use_id IS NOT NULL AND
1960      ( NOT OE_GLOBALS.EQUAL(p_header_rec.end_customer_site_use_id
1961                            ,p_old_header_rec.end_customer_id) OR
1962        NOT OE_GLOBALS.EQUAL(p_header_rec.end_customer_id
1963                            ,p_old_header_rec.end_customer_id)
1964        OR (p_header_rec.operation = OE_GLOBALS.G_OPR_CREATE))
1965     THEN
1966 
1967       BEGIN
1968 
1969 	 SELECT /* MOAC_SQL_CHANGE */ 'VALID'
1970 	    INTO
1971 	    l_dummy
1972 	    FROM
1973 	    hz_cust_site_uses_all site_use,
1974 	    hz_cust_acct_sites acct_site
1975 	    WHERE
1976 	    site_use.site_use_id=p_header_rec.end_customer_site_use_id
1977 	    and site_use.cust_acct_site_id=acct_site.cust_acct_site_id
1978 	    and acct_site.cust_account_id=p_header_rec.end_customer_id;
1979         --  Valid End customer site
1980 
1981       EXCEPTION
1982 
1983         WHEN NO_DATA_FOUND THEN
1984           l_return_status := FND_API.G_RET_STS_ERROR;
1985           fnd_message.set_name('ONT','OE_INVALID_ATTRIBUTE');
1986           FND_MESSAGE.SET_TOKEN('ATTRIBUTE',
1987           OE_Order_Util.Get_Attribute_Name('END_CUSTOMER_SITE_USE_ID'));
1988           OE_MSG_PUB.Add;
1989 
1990         WHEN OTHERS THEN
1991           IF OE_MSG_PUB.Check_Msg_Level
1992           ( OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
1993           THEN
1994             OE_MSG_PUB.Add_Exc_Msg
1995             (  G_PKG_NAME ,
1996               'Record - End Customer Site'
1997              );
1998           END IF;
1999 
2000           RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2001 
2002       END; -- BEGIN
2003 
2004     END IF; -- End Customer site needed validation.
2005 
2006     --  Sold to contact depends on Sold To Org
2007 
2008     IF p_header_rec.sold_to_contact_id IS NOT NULL AND
2009      ( NOT OE_GLOBALS.EQUAL(p_header_rec.sold_to_contact_id
2010                            ,p_old_header_rec.sold_to_contact_id) OR
2011        NOT OE_GLOBALS.EQUAL(p_header_rec.sold_to_org_id
2012                            ,p_old_header_rec.sold_to_org_id)
2013        OR (p_header_rec.operation = OE_GLOBALS.G_OPR_CREATE))
2014     THEN
2015 
2016       BEGIN
2017 
2018         SELECT  'VALID'
2019         INTO  l_dummy
2020         FROM
2021              HZ_CUST_ACCOUNT_ROLES ACCT_ROLE
2022         WHERE
2023              ACCT_ROLE.CUST_ACCOUNT_ROLE_ID = p_header_rec.sold_to_contact_id
2024              AND  ACCT_ROLE.CUST_ACCOUNT_ID = p_header_rec.sold_to_org_id
2025              AND  ROWNUM = 1
2026              AND  ACCT_ROLE.ROLE_TYPE = 'CONTACT'
2027              AND  STATUS= 'A';
2028 
2029         --  Valid Sold To Contact
2030 
2031       EXCEPTION
2032 
2033         WHEN NO_DATA_FOUND THEN
2034           l_return_status := FND_API.G_RET_STS_ERROR;
2035           fnd_message.set_name('ONT','OE_INVALID_ATTRIBUTE');
2036           FND_MESSAGE.SET_TOKEN('ATTRIBUTE',
2037           OE_Order_Util.Get_Attribute_Name('SOLD_TO_CONTACT_ID'));
2038           OE_MSG_PUB.Add;
2039 
2040         WHEN OTHERS THEN
2041           IF OE_MSG_PUB.Check_Msg_Level
2042           ( OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
2043           THEN
2044             OE_MSG_PUB.Add_Exc_Msg
2045             (  G_PKG_NAME ,
2046               'Record - Sold To Contact'
2047              );
2048           END IF;
2049 
2050           RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2051 
2052       END; -- BEGIN
2053 
2054     END IF; -- Sold to contact needed validation.
2055 
2056 
2057     --  Invoice to contact depends on Invoice To Org
2058 
2059     IF p_header_rec.invoice_to_contact_id IS NOT NULL AND
2060        ( NOT OE_GLOBALS.EQUAL(p_header_rec.invoice_to_contact_id
2061                              ,p_old_header_rec.invoice_to_contact_id) OR
2062          NOT OE_GLOBALS.EQUAL(p_header_rec.invoice_to_org_id
2063                              ,p_old_header_rec.invoice_to_org_id)
2064        OR (p_header_rec.operation = OE_GLOBALS.G_OPR_CREATE))
2065     THEN
2066       BEGIN
2067         oe_debug_pub.add
2068         ('inv_to_contact :'||to_char(p_header_rec.invoice_to_contact_id),2);
2069 
2070         SELECT /* MOAC_SQL_CHANGE */ 'VALID'
2071         INTO    l_dummy
2072         FROM
2073              HZ_CUST_ACCOUNT_ROLES ACCT_ROLE,
2074              HZ_CUST_SITE_USES_ALL   SITE_USE,         --changed INV to SITE_USE for bug 3739650
2075              HZ_CUST_ACCT_SITES  ADDR
2076         WHERE
2077              ACCT_ROLE.CUST_ACCOUNT_ROLE_ID = p_header_rec.invoice_to_contact_id
2078              AND  ACCT_ROLE.CUST_ACCOUNT_ID = ADDR.CUST_ACCOUNT_ID
2079              AND  ACCT_ROLE.ROLE_TYPE = 'CONTACT'
2080              AND  ADDR.CUST_ACCT_SITE_ID = SITE_USE.CUST_ACCT_SITE_ID
2081              AND  SITE_USE.SITE_USE_ID = p_header_rec.invoice_to_org_id
2082              AND  SITE_USE.STATUS = 'A'
2083              AND  ADDR.STATUS ='A' --bug 2752321
2084              AND  ACCT_ROLE.STATUS = 'A'
2085              AND  ROWNUM = 1;
2086 
2087       EXCEPTION
2088 
2089         WHEN NO_DATA_FOUND THEN
2090 
2091           l_return_status := FND_API.G_RET_STS_ERROR;
2092           fnd_message.set_name('ONT','OE_INVALID_ATTRIBUTE');
2093           FND_MESSAGE.SET_TOKEN('ATTRIBUTE',
2094           OE_Order_Util.Get_Attribute_Name('INVOICE_TO_CONTACT_ID'));
2095           OE_MSG_PUB.Add;
2096 
2097 
2098         WHEN OTHERS THEN
2099 
2100           IF OE_MSG_PUB.Check_Msg_Level
2101             (OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
2102           THEN
2103 
2104             OE_MSG_PUB.Add_Exc_Msg
2105             (  G_PKG_NAME ,
2106               'Record - Invoice To Contact'
2107             );
2108           END IF;
2109 
2110           RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2111 
2112       END;
2113 
2114     END IF; -- Invoice to contact needed validation.
2115 
2116 
2117     --  Ship to contact depends on Ship To Org
2118 
2119     IF p_header_rec.ship_to_contact_id IS NOT NULL AND
2120       ( NOT OE_GLOBALS.EQUAL(p_header_rec.ship_to_contact_id
2121                             ,p_old_header_rec.ship_to_contact_id) OR
2122         NOT OE_GLOBALS.EQUAL(p_header_rec.ship_to_org_id
2123                             ,p_old_header_rec.ship_to_org_id)
2124        OR (p_header_rec.operation = OE_GLOBALS.G_OPR_CREATE))
2125     THEN
2126 
2127       BEGIN
2128 
2129         SELECT /* MOAC_SQL_CHANGE */  'VALID'
2130         INTO    l_dummy
2131         FROM
2132              HZ_CUST_ACCOUNT_ROLES ACCT_ROLE,
2133              HZ_CUST_SITE_USES_ALL   SITE_USE,               --changed SHIP to SITE_USE for bug 3739650
2134              HZ_CUST_ACCT_SITES  ADDR
2135         WHERE
2136              ACCT_ROLE.CUST_ACCOUNT_ROLE_ID = p_header_rec.ship_to_contact_id
2137              AND  ACCT_ROLE.CUST_ACCOUNT_ID = ADDR.CUST_ACCOUNT_ID
2138              AND  ACCT_ROLE.ROLE_TYPE = 'CONTACT'
2139              AND  ADDR.CUST_ACCT_SITE_ID = SITE_USE.CUST_ACCT_SITE_ID
2140              AND  SITE_USE.SITE_USE_ID = p_header_rec.ship_to_org_id
2141              AND  SITE_USE.STATUS = 'A'
2142 	     AND  ADDR.STATUS ='A' --bug 2752321
2143              AND  ACCT_ROLE.STATUS = 'A'
2144              AND  ROWNUM = 1;
2145 
2146         --  Valid Ship To Contact
2147 
2148       EXCEPTION
2149 
2150         WHEN NO_DATA_FOUND THEN
2151           l_return_status := FND_API.G_RET_STS_ERROR;
2152           fnd_message.set_name('ONT','OE_INVALID_ATTRIBUTE');
2153           FND_MESSAGE.SET_TOKEN('ATTRIBUTE',
2154           OE_Order_Util.Get_Attribute_Name('SHIP_TO_CONTACT_ID'));
2155           OE_MSG_PUB.Add;
2156 
2157 
2158         WHEN OTHERS THEN
2159 
2160          IF OE_MSG_PUB.Check_Msg_Level
2161          (OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
2162          THEN
2163 
2164            OE_MSG_PUB.Add_Exc_Msg
2165            (  G_PKG_NAME ,
2166              'Record - Ship To Contact'
2167            );
2168          END IF;
2169 
2170          RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2171 
2172       END; -- BEGIN
2173 
2174     END IF; -- Ship to contact needed validation.
2175 
2176 
2177     --  Deliver to contact depends on Deliver To Org
2178 
2179     IF p_header_rec.deliver_to_contact_id IS NOT NULL AND
2180        ( NOT OE_GLOBALS.EQUAL(p_header_rec.deliver_to_contact_id
2181                              ,p_old_header_rec.deliver_to_contact_id) OR
2182          NOT OE_GLOBALS.EQUAL(p_header_rec.deliver_to_org_id
2183                              ,p_old_header_rec.deliver_to_org_id)
2184        OR (p_header_rec.operation = OE_GLOBALS.G_OPR_CREATE))
2185     THEN
2186 
2187       BEGIN
2188 
2189         SELECT /* MOAC_SQL_CHANGE */ 'VALID'
2190         INTO    l_dummy
2191         FROM
2192              HZ_CUST_ACCOUNT_ROLES ACCT_ROLE,
2193              HZ_CUST_SITE_USES_ALL   SITE_USE,   --changed DELIVER to SITE_USE for bug 3739650
2194              HZ_CUST_ACCT_SITES  ADDR
2195         WHERE
2196              ACCT_ROLE.CUST_ACCOUNT_ROLE_ID = p_header_rec.deliver_to_contact_id
2197              AND  ACCT_ROLE.CUST_ACCOUNT_ID = ADDR.CUST_ACCOUNT_ID
2198              AND  ACCT_ROLE.ROLE_TYPE = 'CONTACT'
2199              AND  ADDR.CUST_ACCT_SITE_ID = SITE_USE.CUST_ACCT_SITE_ID
2200              AND  SITE_USE.SITE_USE_ID = p_header_rec.deliver_to_org_id
2201              AND  SITE_USE.STATUS = 'A'
2202 	     AND  ADDR.STATUS ='A' --bug 2752321
2203              AND  ACCT_ROLE.STATUS = 'A'
2204              AND  ROWNUM = 1;
2205 
2206         --  Valid Deliver To Org.
2207 
2208       EXCEPTION
2209 
2210         WHEN NO_DATA_FOUND THEN
2211           l_return_status := FND_API.G_RET_STS_ERROR;
2212           fnd_message.set_name('ONT','OE_INVALID_ATTRIBUTE');
2213           FND_MESSAGE.SET_TOKEN('ATTRIBUTE',
2214           OE_Order_Util.Get_Attribute_Name('DELIVER_TO_CONTACT_ID'));
2215           OE_MSG_PUB.Add;
2216 
2217         WHEN OTHERS THEN
2218 
2219           IF OE_MSG_PUB.Check_Msg_Level (
2220           OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
2221           THEN
2222             OE_MSG_PUB.Add_Exc_Msg
2223             (  G_PKG_NAME ,
2224               'Record - Deliver To Contact'
2225              );
2226           END IF;
2227 
2228           RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2229 
2230       END; -- BEGIN
2231 
2232     END IF; -- Deliver to contact needed validation.
2233 
2234 
2235 
2236     --Following validation for Tax Exemption Number is removed for bug 6441512
2237     --  Check for Tax Exempt number/Tax exempt reason code IF the Tax exempt
2238     --    flag is 'S' (StANDard).
2239 
2240 
2241    /* IF p_header_rec.tax_exempt_flag IS NOT NULL
2242        AND ( NOT OE_GLOBALS.EQUAL(p_header_rec.tax_exempt_number
2243                                  ,p_old_header_rec.tax_exempt_number)
2244        OR NOT OE_GLOBALS.EQUAL(p_header_rec.tax_exempt_reason_code
2245                               ,p_old_header_rec.tax_exempt_reason_code)
2246        OR NOT OE_GLOBALS.EQUAL(p_header_rec.ship_to_org_id
2247                               ,p_old_header_rec.ship_to_org_id)
2248        OR NOT OE_GLOBALS.EQUAL(p_header_rec.invoice_to_org_id
2249                               ,p_old_header_rec.invoice_to_org_id)
2250        OR NOT OE_GLOBALS.EQUAL(p_header_rec.sold_to_org_id
2251                               ,p_old_header_rec.sold_to_org_id)
2252        OR (p_header_rec.operation = OE_GLOBALS.G_OPR_CREATE)
2253            )
2254     THEN
2255 
2256       BEGIN
2257         -- 6118092
2258         IF ( p_header_rec.tax_exempt_flag = 'S' OR p_header_rec.tax_exempt_flag = 'E' ) AND
2259            p_header_rec.tax_exempt_number IS NOT NULL AND
2260            p_header_rec.tax_exempt_reason_code IS NOT NULL
2261         THEN
2262 
2263          -- EBTax Changes
2264 
2265          open partyinfo(p_header_rec.invoice_to_org_id);
2266          fetch partyinfo into l_bill_to_cust_Acct_id,
2267                               l_bill_to_party_id,
2268                               l_bill_to_party_site_id,
2269                               l_org_id;
2270          close partyinfo;
2271 
2272          if p_header_rec.ship_to_org_id = p_header_rec.invoice_to_org_id then
2273             l_ship_to_cust_Acct_id    :=  l_bill_to_cust_Acct_id;
2274             l_ship_to_party_id        :=  l_bill_to_party_id;
2275             l_ship_to_party_site_id   :=  l_bill_to_party_site_id ;
2276          else
2277             open partyinfo(p_header_rec.ship_to_org_id);
2278             fetch partyinfo into l_ship_to_cust_Acct_id,
2279                               l_ship_to_party_id,
2280                               l_ship_to_party_site_id,
2281                               l_org_id;
2282             close partyinfo;
2283          end if;
2284 
2285          -- Modified below code to validate Tax Exempt Number based on Tax Handling for Bug 6378168
2286          IF ( p_header_rec.tax_exempt_flag = 'S' ) THEN
2287           SELECT 'VALID'
2288           INTO l_dummy
2289           FROM ZX_EXEMPTIONS_V
2290           WHERE EXEMPT_CERTIFICATE_NUMBER = p_header_rec.tax_exempt_number
2291           AND EXEMPT_REASON_CODE=p_header_rec.tax_exempt_reason_code
2292           AND nvl(site_use_id,nvl(p_header_rec.ship_to_org_id,p_header_rec.invoice_to_org_id)) =
2293                     nvl(p_header_rec.ship_to_org_id,p_header_rec.invoice_to_org_id)
2294           AND nvl(cust_account_id, l_bill_to_cust_acct_id) = l_bill_to_cust_acct_id
2295           AND nvl(PARTY_SITE_ID,nvl(l_ship_to_party_site_id, l_bill_to_party_site_id))=
2296                        nvl(l_ship_to_party_site_id, l_bill_to_party_site_id)
2297           and  org_id = p_header_rec.org_id
2298           and  party_id = l_bill_to_party_id
2299           AND EXEMPTION_STATUS_CODE = 'PRIMARY'
2300           AND TRUNC(NVL(p_header_rec.request_date,sysdate)) BETWEEN
2301           TRUNC(EFFECTIVE_FROM) AND
2302           TRUNC(NVL(EFFECTIVE_TO,NVL(p_header_rec.request_date,sysdate)))
2303           AND ROWNUM = 1;
2304          ELSIF ( p_header_rec.tax_exempt_flag = 'E' ) THEN
2305           SELECT 'VALID'
2306           INTO l_dummy
2307           FROM ZX_EXEMPTIONS_V
2308           WHERE EXEMPT_CERTIFICATE_NUMBER = p_header_rec.tax_exempt_number
2309           AND EXEMPT_REASON_CODE=p_header_rec.tax_exempt_reason_code
2310           AND nvl(site_use_id,nvl(p_header_rec.ship_to_org_id,p_header_rec.invoice_to_org_id)) =
2311                     nvl(p_header_rec.ship_to_org_id,p_header_rec.invoice_to_org_id)
2312           AND nvl(cust_account_id, l_bill_to_cust_acct_id) = l_bill_to_cust_acct_id
2313           AND nvl(PARTY_SITE_ID,nvl(l_ship_to_party_site_id, l_bill_to_party_site_id))=
2314                        nvl(l_ship_to_party_site_id, l_bill_to_party_site_id)
2315           and  org_id = p_header_rec.org_id
2316           and  party_id = l_bill_to_party_id
2317           AND EXEMPTION_STATUS_CODE IN ('PRIMARY','MANUAL','UNAPPROVED')
2318           AND TRUNC(NVL(p_header_rec.request_date,sysdate)) BETWEEN
2319           TRUNC(EFFECTIVE_FROM) AND
2320           TRUNC(NVL(EFFECTIVE_TO,NVL(p_header_rec.request_date,sysdate)))
2321           AND ROWNUM = 1;
2322          END IF;
2323 
2324         END IF;
2325 
2326        oe_debug_pub.Add(' Valid Tax Exempt Number',1);
2327 
2328       EXCEPTION
2329 
2330         WHEN NO_DATA_FOUND THEN
2331 
2332                    -- Bug 6118092 Redefault as it may be no more valid
2333                   IF p_header_rec.order_category_code = 'RETURN' THEN  -- 6430711
2334                      null;
2335                     ELSIF p_validation_level = OE_GLOBALS.G_VALID_PARTIAL_WITH_DEF AND
2336                           p_header_rec.operation = OE_GLOBALS.G_OPR_CREATE   THEN
2337                           p_header_rec.tax_exempt_number := FND_API.G_MISS_CHAR;
2338                           p_header_rec.tax_exempt_reason_code := FND_API.G_MISS_CHAR;
2339                           p_header_rec.tax_exempt_flag :=FND_API.G_MISS_CHAR;
2340 
2341                           oe_debug_pub.Add('Redefault the tax_exempt_number',1);
2342                    ELSE
2343                         l_return_status := FND_API.G_RET_STS_ERROR;
2344                         fnd_message.set_name('ONT','OE_INVALID_ATTRIBUTE');
2345                         FND_MESSAGE.SET_TOKEN('ATTRIBUTE',
2346                         OE_Order_Util.Get_Attribute_Name('TAX_EXEMPT_NUMBER'));
2347                         OE_MSG_PUB.Add;
2348                    END IF;
2349 
2350         WHEN OTHERS THEN
2351 
2352           IF OE_MSG_PUB.Check_Msg_Level (OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
2353           THEN
2354 
2355             OE_MSG_PUB.Add_Exc_Msg
2356             (  G_PKG_NAME ,
2357               'Record - Tax Exempt Number'
2358             );
2359           END IF;
2360 
2361           RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2362 
2363       END; -- BEGIN
2364 
2365     END IF; -- Tax exempton info validation.
2366 
2367     */
2368 
2369     oe_debug_pub.Add('p_header_rec.cust_po_number'|| p_header_rec.cust_po_number);-- Bug# 6603714
2370     IF p_header_rec.order_source_id <> 27 THEN-- Bug# 6603714
2371 
2372     -- Fix bug 1162304: issue a warning message if the PO number
2373     -- is being referenced by another order
2374     IF p_header_rec.cust_po_number IS NOT NULL
2375 	  AND ( NOT OE_GLOBALS.EQUAL(p_header_rec.sold_to_org_id
2376                               ,p_old_header_rec.sold_to_org_id)
2377              OR NOT OE_GLOBALS.EQUAL(p_header_rec.cust_po_number
2378                               ,p_old_header_rec.cust_po_number)
2379              OR (p_header_rec.operation = OE_GLOBALS.G_OPR_CREATE)
2380             )
2381     THEN
2382 
2383       IF OE_Validate_Header.Is_Duplicate_PO_Number
2384            (p_header_rec.cust_po_number
2385            ,p_header_rec.sold_to_org_id
2386            ,p_header_rec.header_id )
2387       THEN
2388           FND_MESSAGE.SET_NAME('ONT','OE_VAL_DUP_PO_NUMBER');
2389           OE_MSG_PUB.ADD;
2390       END IF;
2391 
2392     END IF;
2393     -- End of check for duplicate PO number
2394     END IF;-- Bug# 6603714
2395 
2396 
2397     -- bug 1618229, validation for sold_to_org_id on order against
2398     -- the customer for commitment when commitment is used.
2399     /*
2400     ** Fix Bug # 3015881
2401     ** No need to validate here as this will be validated anyway
2402     ** when the sold to org id changes are cascaded to the line.
2403 
2404     IF (NOT OE_GLOBALS.EQUAL(p_header_rec.sold_to_org_id
2405                             ,p_old_header_rec.sold_to_org_id)) THEN
2406 
2407        oe_debug_pub.add('OEXLHDRB: before validating customer for commitment.', 3);
2408        Validate_Commitment_Customer
2409                   (p_header_id 	    	=> p_header_rec.header_id
2410                   ,p_sold_to_org_id    	=> p_header_rec.sold_to_org_id
2411                   ,x_return_status      => l_comt_cust_status);
2412 
2413        IF l_comt_cust_status = FND_API.G_RET_STS_ERROR THEN
2414 
2415          l_return_status := FND_API.G_RET_STS_ERROR;
2416 
2417          -- to get the customer name of the order.
2418          BEGIN
2419            SELECT party.party_name
2420            INTO   l_customer_name
2421            FROM   hz_parties party,
2422                   hz_cust_accounts cust_acct
2423            WHERE  cust_acct.cust_account_id = p_header_rec.sold_to_org_id
2424            AND    cust_acct.party_id = party.party_id;
2425 
2426          EXCEPTION WHEN NO_DATA_FOUND THEN
2427            null;
2428          END;
2429 
2430          Fnd_Message.Set_Name('ONT','ONT_COM_CUSTOMER_MISMATCH');
2431          Fnd_message.set_token('CUSTOMER',l_customer_name);
2432          OE_MSG_PUB.Add;
2433          oe_debug_pub.add('Error: customer of the order does not match the customer for the commitment.', 3);
2434          RAISE FND_API.G_EXC_ERROR;
2435        END IF;
2436     END IF;
2437     */
2438 
2439      -------------------------------------------------------------------
2440      -- Validating Blankets
2441      -------------------------------------------------------------------
2442 
2443      IF OE_CODE_CONTROL.Get_Code_Release_Level < '110509' AND
2444                              p_header_rec.blanket_number IS NOT NULL THEN
2445         If l_debug_level > 0 THEN
2446             OE_DEBUG_PUB.Add('Blankets are only available in Pack I or greater',1);
2447         End if;
2448         l_return_status := FND_API.G_RET_STS_ERROR;
2449         FND_MESSAGE.Set_Name('ONT','OE_BLANKET_INVALID_VERSION');
2450         OE_MSG_PUB.Add;
2451      ELSE
2452          IF p_header_rec.blanket_number IS NOT NULL THEN
2453             Validate_Blanket_Values
2454                  (p_header_rec     => p_header_rec,
2455                   p_old_header_rec => p_old_header_rec,
2456                   x_return_status  => l_blanket_status);
2457             IF l_blanket_status = FND_API.G_RET_STS_ERROR THEN
2458                x_return_status := l_blanket_status;
2459             ELSIF l_blanket_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
2460                RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2461             END IF;
2462          END IF;
2463      END IF;
2464 
2465      --Commenting the following for bug 3733877
2466 /*
2467      IF OE_PREPAYMENT_UTIL.IS_MULTIPLE_PAYMENTS_ENABLED = TRUE THEN
2468 
2469        IF (NOT OE_GLOBALS.EQUAL(p_header_rec.payment_type_code
2470                             ,p_old_header_rec.payment_type_code))
2471           or
2472           (NOT OE_GLOBALS.EQUAL(p_header_rec.credit_card_code
2473                             ,p_old_header_rec.credit_card_code))
2474           or
2475           (NOT OE_GLOBALS.EQUAL(p_header_rec.credit_card_number
2476                             ,p_old_header_rec.credit_card_number))
2477           or
2478           (NOT OE_GLOBALS.EQUAL(p_header_rec.credit_card_holder_name
2479                             ,p_old_header_rec.credit_card_holder_name))
2480           or
2481            (NOT OE_GLOBALS.EQUAL(p_header_rec.credit_card_expiration_date
2482                             ,p_old_header_rec.credit_card_expiration_date))
2483           or
2484            (NOT OE_GLOBALS.EQUAL(p_header_rec.check_number
2485                             ,p_old_header_rec.check_number))
2486           or
2487            (NOT OE_GLOBALS.EQUAL(p_header_rec.payment_amount
2488                             ,p_old_header_rec.payment_amount))
2489 
2490            THEN
2491 
2492             select count(payment_type_code) into l_payment_count
2493             from oe_payments
2494             where header_id = p_header_rec.header_id
2495             and line_id is null;
2496 
2497             if l_payment_count > 1 then
2498                l_return_status := FND_API.G_RET_STS_ERROR;
2499 
2500               fnd_message.Set_Name('ONT','ONT_MULTIPLE_PAYMENTS_EXIST');
2501               OE_MSG_PUB.Add;
2502               oe_debug_pub.add('Error: multiple payments exist. cannot update order header',3);
2503 
2504             end if;
2505 
2506          END IF; -- if not oe_globals.equal...
2507 
2508       END IF; -- if multiple_payments is enabled
2509 */
2510      --distributed orders @
2511       oe_debug_pub.ADD('ib_owner: '||p_header_rec.ib_owner);
2512      IF p_header_rec.ib_owner IS NOT NULL AND
2513 	( NOT OE_GLOBALS.EQUAL(p_header_rec.ib_owner ,p_old_header_rec.ib_owner)
2514 	  OR p_old_header_rec.ib_owner is null
2515 	  OR NOT OE_GLOBALS.EQUAL(p_header_rec.sold_to_org_id, p_old_header_rec.sold_to_org_id)
2516 	  OR NOT OE_GLOBALS.EQUAL(p_header_rec.end_customer_id, p_old_header_rec.end_customer_id)
2517           OR p_header_rec.operation = OE_GLOBALS.G_OPR_CREATE)
2518      THEN
2519 	IF (p_header_rec.ib_owner = 'SOLD_TO' AND
2520 	     p_header_rec.sold_to_org_id is null)
2521 	THEN
2522 	   l_return_status := FND_API.G_RET_STS_ERROR;
2523 	   fnd_message.set_name('ONT','OE_INVALID_ATTRIBUTE');
2524 	   FND_MESSAGE.SET_TOKEN('ATTRIBUTE',OE_Order_UTIL.Get_attribute_name('IB_OWNER'));
2525 	   OE_MSG_PUB.Add;
2526 	  ELSIF p_header_rec.ib_owner = 'END_CUSTOMER' AND
2527 		p_header_rec.end_customer_id is null
2528 	  THEN
2529 	     l_return_status := FND_API.G_RET_STS_ERROR;
2530 	     fnd_message.set_name('ONT','OE_INVALID_ATTRIBUTE');
2531 	     FND_MESSAGE.SET_TOKEN('ATTRIBUTE',OE_Order_UTIL.Get_attribute_name('IB_OWNER'));
2532 	     OE_MSG_PUB.Add;
2533 	  END IF;
2534        END IF;
2535        oe_debug_pub.ADD('ib_installed_at_location: '||p_header_rec.ib_installed_at_location);
2536 
2537        IF p_header_rec.ib_installed_at_location IS NOT NULL AND
2538 	  ( NOT OE_GLOBALS.EQUAL(p_header_rec.ib_installed_at_location ,p_old_header_rec.ib_installed_at_location)
2539 	    OR p_old_header_rec.ib_installed_at_location is null
2540 	    OR NOT OE_GLOBALS.EQUAL(p_header_rec.invoice_to_org_id ,p_old_header_rec.invoice_to_org_id)
2541 	    OR NOT OE_GLOBALS.EQUAL(p_header_rec.ship_to_org_id ,p_old_header_rec.ship_to_org_id)
2542 	    OR NOT OE_GLOBALS.EQUAL(p_header_rec.deliver_to_org_id ,p_old_header_rec.deliver_to_org_id)
2543 	    OR NOT OE_GLOBALS.EQUAL(p_header_rec.end_customer_site_use_id ,p_old_header_rec.end_customer_site_use_id)
2544 	    OR NOT OE_GLOBALS.EQUAL(p_header_rec.sold_to_site_use_id ,p_old_header_rec.sold_to_site_use_id)
2545             OR p_header_rec.operation = OE_GLOBALS.G_OPR_CREATE)
2546        THEN
2547 	IF (p_header_rec.ib_installed_at_location = 'BILL_TO' AND
2548 	     p_header_rec.invoice_to_org_id is null)
2549 	THEN
2550 	   l_return_status := FND_API.G_RET_STS_ERROR;
2551 	   fnd_message.set_name('ONT','OE_INVALID_ATTRIBUTE');
2552 	   FND_MESSAGE.SET_TOKEN('ATTRIBUTE',OE_Order_UTIL.Get_attribute_name('IB_INSTALLED_AT_LOCATION'));
2553 	   OE_MSG_PUB.Add;
2554 	  ELSIF p_header_rec.ib_installed_at_location = 'SHIP_TO' AND
2555 		p_header_rec.ship_to_org_id is null
2556 	  THEN
2557 	     l_return_status := FND_API.G_RET_STS_ERROR;
2558 	     fnd_message.set_name('ONT','OE_INVALID_ATTRIBUTE');
2559 	     FND_MESSAGE.SET_TOKEN('ATTRIBUTE',OE_Order_UTIL.Get_attribute_name('IB_INSTALLED_AT_LOCATION'));
2560 	     OE_MSG_PUB.Add;
2561 	  ELSIF p_header_rec.ib_installed_at_location = 'DELIVER_TO' AND
2562 		p_header_rec.deliver_to_org_id is null
2563 	  THEN
2564 	     l_return_status := FND_API.G_RET_STS_ERROR;
2565 	     fnd_message.set_name('ONT','OE_INVALID_ATTRIBUTE');
2566 	     FND_MESSAGE.SET_TOKEN('ATTRIBUTE',OE_Order_UTIL.Get_attribute_name('IB_INSTALLED_AT_LOCATION'));
2567 	     OE_MSG_PUB.Add;
2568 	  ELSIF p_header_rec.ib_installed_at_location = 'END_CUSTOMER' AND
2569 		p_header_rec.end_customer_site_use_id is null
2570 	  THEN
2571 	     l_return_status := FND_API.G_RET_STS_ERROR;
2572 	     fnd_message.set_name('ONT','OE_INVALID_ATTRIBUTE');
2573 	     FND_MESSAGE.SET_TOKEN('ATTRIBUTE',OE_Order_UTIL.Get_attribute_name('IB_INSTALLED_AT_LOCATION'));
2574 	     OE_MSG_PUB.Add;
2575 	  ELSIF p_header_rec.ib_installed_at_location = 'SOLD_TO' AND
2576 		p_header_rec.sold_to_site_use_id is null
2577 	  THEN
2578 	     l_return_status := FND_API.G_RET_STS_ERROR;
2579 	     fnd_message.set_name('ONT','OE_INVALID_ATTRIBUTE');
2580 	     FND_MESSAGE.SET_TOKEN('ATTRIBUTE',OE_Order_UTIL.Get_attribute_name('IB_INSTALLED_AT_LOCATION'));
2581 	     OE_MSG_PUB.Add;
2582 	  END IF;
2583        END IF;
2584        oe_debug_pub.ADD('ib_current_location: '||p_header_rec.ib_current_location);
2585 
2586        IF p_header_rec.ib_current_location IS NOT NULL AND
2587 	  ( NOT OE_GLOBALS.EQUAL(p_header_rec.ib_current_location ,p_old_header_rec.ib_current_location)
2588 	    OR NOT OE_GLOBALS.EQUAL(p_header_rec.invoice_to_org_id ,p_old_header_rec.invoice_to_org_id)
2589 	    OR NOT OE_GLOBALS.EQUAL(p_header_rec.ship_to_org_id ,p_old_header_rec.ship_to_org_id)
2590 	    OR NOT OE_GLOBALS.EQUAL(p_header_rec.deliver_to_org_id ,p_old_header_rec.deliver_to_org_id)
2591 	    OR NOT OE_GLOBALS.EQUAL(p_header_rec.end_customer_site_use_id ,p_old_header_rec.end_customer_site_use_id)
2592 	    OR NOT OE_GLOBALS.EQUAL(p_header_rec.sold_to_site_use_id ,p_old_header_rec.sold_to_site_use_id)
2593 	    OR p_old_header_rec.ib_current_location is null
2594             OR p_header_rec.operation = OE_GLOBALS.G_OPR_CREATE )
2595        THEN
2596 	IF (p_header_rec.ib_current_location = 'BILL_TO' AND
2597 	     p_header_rec.invoice_to_org_id is null)
2598 	THEN
2599 	   l_return_status := FND_API.G_RET_STS_ERROR;
2600 	   fnd_message.set_name('ONT','OE_INVALID_ATTRIBUTE');
2601 	   FND_MESSAGE.SET_TOKEN('ATTRIBUTE',OE_Order_UTIL.Get_attribute_name('IB_CURRENT_LOCATION'));
2602 	   OE_MSG_PUB.Add;
2603 	  ELSIF p_header_rec.ib_current_location = 'SHIP_TO' AND
2604 		p_header_rec.ship_to_org_id is null
2605 	  THEN
2606 	     l_return_status := FND_API.G_RET_STS_ERROR;
2607 	     fnd_message.set_name('ONT','OE_INVALID_ATTRIBUTE');
2608 	     FND_MESSAGE.SET_TOKEN('ATTRIBUTE',OE_Order_UTIL.Get_attribute_name('IB_CURRENT_LOCATION'));
2609 	     OE_MSG_PUB.Add;
2610 	  ELSIF p_header_rec.ib_current_location = 'DELIVER_TO' AND
2611 		p_header_rec.deliver_to_org_id is null
2612 	  THEN
2613 	     l_return_status := FND_API.G_RET_STS_ERROR;
2614 	     fnd_message.set_name('ONT','OE_INVALID_ATTRIBUTE');
2615 	     FND_MESSAGE.SET_TOKEN('ATTRIBUTE',OE_Order_UTIL.Get_attribute_name('IB_CURRENT_LOCATION'));
2616 	     OE_MSG_PUB.Add;
2617 	  ELSIF p_header_rec.ib_current_location = 'END_CUSTOMER' AND
2618 		p_header_rec.end_customer_site_use_id is null
2619 	  THEN
2620 	     l_return_status := FND_API.G_RET_STS_ERROR;
2621 	     fnd_message.set_name('ONT','OE_INVALID_ATTRIBUTE');
2622 	     FND_MESSAGE.SET_TOKEN('ATTRIBUTE',OE_Order_UTIL.Get_attribute_name('IB_CURRENT_LOCATION'));
2623 	     OE_MSG_PUB.Add;
2624 	  ELSIF p_header_rec.ib_current_location = 'SOLD_TO' AND
2625 		p_header_rec.sold_to_site_use_id is null
2626 	  THEN
2627 	     l_return_status := FND_API.G_RET_STS_ERROR;
2628 	     fnd_message.set_name('ONT','OE_INVALID_ATTRIBUTE');
2629 	     FND_MESSAGE.SET_TOKEN('ATTRIBUTE',OE_Order_UTIL.Get_attribute_name('IB_CURRENT_LOCATION'));
2630 	     OE_MSG_PUB.Add;
2631 	  END IF;
2632        END IF;
2633 
2634    -- IB Validation START
2635    -- for validating line level ib_installed_at_location
2636    -- and ib_current_location for all lines
2637    -- This should be a CORNER CASE, hence not much perf impact
2638    IF p_old_header_rec.sold_to_site_use_id IS NOT NULL
2639       and p_header_rec.sold_to_site_use_id IS NULL
2640       and p_old_header_rec.header_id is not null
2641    then
2642       -- okay, loop for all lines
2643       If l_debug_level > 0 THEN
2644 	 oe_debug_pub.add('>sold_to_site_use_id has changed to null,');
2645 	 oe_debug_pub.add('>checking all lines for IB validation');
2646       end if;
2647 
2648       for l in ib_lines loop
2649 	 if l.ib_current_location='SOLD_TO'
2650 	 then
2651 	    If l_debug_level > 0 THEN
2652 	       oe_debug_pub.add('>line_id:'||l.line_id||' has ib_current_location as SOLD_TO');
2653 	    end if;
2654 	    l_return_status := FND_API.G_RET_STS_ERROR;
2655 	    fnd_message.set_name('ONT','OE_INVALID_ATTRIBUTE');
2656 	    FND_MESSAGE.SET_TOKEN('ATTRIBUTE',OE_Order_UTIL.Get_attribute_name('IB_CURRENT_LOCATION'));
2657 	    OE_MSG_PUB.Add;
2658 	 elsif l.ib_installed_at_location='SOLD_TO'
2659 	 then
2660 	    If l_debug_level > 0 THEN
2661 	       oe_debug_pub.add('>line_id:'||l.line_id||' has ib_installed_at_location as SOLD_TO');
2662 	    end if;
2663 	    l_return_status := FND_API.G_RET_STS_ERROR;
2664 	    fnd_message.set_name('ONT','OE_INVALID_ATTRIBUTE');
2665 	    FND_MESSAGE.SET_TOKEN('ATTRIBUTE',OE_Order_UTIL.Get_attribute_name('IB_INSTALLED_AT_LOCATION'));
2666 	    OE_MSG_PUB.Add;
2667 	 end if;
2668       end loop;
2669    end if;
2670    If l_debug_level > 0 THEN
2671       oe_debug_pub.add('>IB Line validation done');
2672    end if;
2673    -- IB Validation ENDS
2674 
2675    --R12 CC Encryption
2676    IF p_header_rec.payment_type_code = 'CREDIT_CARD' THEN
2677 	IF p_header_rec.invoice_to_org_id is NULL THEN
2678 		l_return_status := FND_API.G_RET_STS_ERROR;
2679 		FND_MESSAGE.SET_NAME('ONT','OE_VPM_INV_TO_REQUIRED');
2680 		OE_MSG_PUB.ADD;
2681 	END IF;
2682    END IF;
2683    --R12 CC Encryption
2684    /*
2685 		OE_MSG_PUB.ADD;
2686 	      	ELSIF p_header_rec.credit_card_number is NULL THEN
2687 			l_return_status := FND_API.G_RET_STS_ERROR;
2688 	    		FND_MESSAGE.SET_NAME('ONT','OE_VPM_CC_NUM_REQUIRED');
2689 	    		OE_MSG_PUB.ADD;
2690 	     	ELSIF p_header_rec.credit_card_expiration_date is NULL THEN
2691 			l_return_status := FND_API.G_RET_STS_ERROR;
2692 	   		FND_MESSAGE.SET_NAME('ONT','OE_VPM_CC_EXP_DT_REQUIRED');
2693 	    		OE_MSG_PUB.ADD;
2694 	    	ELSIF p_header_rec.credit_card_holder_name is NULL THEN
2695 			l_return_status := FND_API.G_RET_STS_ERROR;
2696 	    		FND_MESSAGE.SET_NAME('ONT','OE_VPM_CC_HOLDER_REQUIRED');
2697 	    		OE_MSG_PUB.ADD;
2698 	    	END IF;
2699     END IF;*/
2700 
2701     --  Done validating entity
2702     x_return_status := l_return_status;
2703 
2704     oe_debug_pub.add('Exit OE_VALIDATE_HEADER.ENTITY',1);
2705 
2706 EXCEPTION
2707 
2708     WHEN FND_API.G_EXC_ERROR THEN
2709       x_return_status := FND_API.G_RET_STS_ERROR;
2710 
2711     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2712       x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2713 
2714     WHEN OTHERS THEN
2715       x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2716 
2717       IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
2718       THEN
2719         OE_MSG_PUB.Add_Exc_Msg
2720         (   G_PKG_NAME
2721         ,   'Entity'
2722          );
2723       END IF;
2724 
2725 END Entity;
2726 
2727 
2728 
2729 /*-------------------------------------------------------
2730 PROCEDURE:    Attributes
2731 Description:
2732 --------------------------------------------------------*/
2733 
2734 PROCEDURE Attributes
2735 (   x_return_status      OUT NOCOPY /* file.sql.39 change */ VARCHAR2
2736 ,   p_x_header_rec       IN  OUT NOCOPY OE_Order_PUB.Header_Rec_Type
2737 ,   p_old_header_rec     IN  OE_Order_PUB.Header_Rec_Type :=
2738                                    OE_Order_PUB.G_MISS_HEADER_REC
2739 ,   p_validation_level   IN  NUMBER := FND_API.G_VALID_LEVEL_FULL
2740 )
2741 IS
2742   l_cc_security_code_use Varchar2(20);
2743 BEGIN
2744 
2745     oe_debug_pub.add('Entering OE_VALIDATE_HEADER.ATTRIBUTES',1);
2746 
2747     x_return_status := FND_API.G_RET_STS_SUCCESS;
2748 
2749     --  Validate header attributes
2750     /* Bug 5060064 - PC firing inappropriately for Order Import.
2751        To fix the issue we are now passing in old header rec same
2752        as new header rec, before calling process_order. B'cas of this
2753        old rec and new rec may have the same values. To make sure that
2754        validation is done for the attributes during CREATE added an
2755        additional check of
2756             OR
2757            ( p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE ))
2758        in all the conditions.
2759     */
2760 
2761     IF  p_x_header_rec.accounting_rule_id IS NOT NULL AND
2762         (  ( p_x_header_rec.accounting_rule_id <>
2763             p_old_header_rec.accounting_rule_id OR
2764             p_old_header_rec.accounting_rule_id IS NULL ) OR
2765            ( p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE ))
2766         --bug 5060064
2767     THEN
2768 
2769       IF NOT OE_Validate.Accounting_Rule(p_x_header_rec.accounting_rule_id)
2770       THEN
2771 
2772         IF p_validation_level = OE_GLOBALS.G_VALID_LEVEL_PARTIAL AND
2773            p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
2774         THEN
2775           p_x_header_rec.accounting_rule_id := NULL;
2776         ELSIF p_validation_level = OE_GLOBALS.G_VALID_PARTIAL_WITH_DEF AND
2777               p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
2778         THEN
2779           p_x_header_rec.accounting_rule_id := FND_API.G_MISS_NUM;
2780         ELSE
2781           x_return_status := FND_API.G_RET_STS_ERROR;
2782         END IF;
2783 
2784       END IF;
2785 
2786     END IF;
2787 
2788     IF  p_x_header_rec.accounting_rule_duration IS NOT NULL AND
2789         ( (p_x_header_rec.accounting_rule_duration <>
2790             p_old_header_rec.accounting_rule_duration OR
2791             p_old_header_rec.accounting_rule_duration IS NULL ) OR
2792            ( p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE ))
2793         --bug 5060064
2794     THEN
2795 
2796       IF NOT OE_Validate.Accounting_Rule_Duration(p_x_header_rec.accounting_rule_duration)
2797       THEN
2798 
2799         IF p_validation_level = OE_GLOBALS.G_VALID_LEVEL_PARTIAL AND
2800            p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
2801         THEN
2802           p_x_header_rec.accounting_rule_duration := NULL;
2803         ELSIF p_validation_level = OE_GLOBALS.G_VALID_PARTIAL_WITH_DEF AND
2804               p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
2805         THEN
2806           p_x_header_rec.accounting_rule_duration := FND_API.G_MISS_NUM;
2807         ELSE
2808           x_return_status := FND_API.G_RET_STS_ERROR;
2809         END IF;
2810 
2811       END IF;
2812 
2813     END IF;
2814 
2815     IF  p_x_header_rec.agreement_id IS NOT NULL AND
2816         ( ( p_x_header_rec.agreement_id <>
2817             p_old_header_rec.agreement_id OR
2818             p_old_header_rec.agreement_id IS NULL ) OR
2819            ( p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE ))
2820         --bug 5060064
2821     THEN
2822 
2823       IF NOT OE_Validate.Agreement(p_x_header_rec.agreement_id)
2824       THEN
2825         IF p_validation_level = OE_GLOBALS.G_VALID_LEVEL_PARTIAL AND
2826            p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
2827         THEN
2828           p_x_header_rec.agreement_id := NULL;
2829         ELSIF p_validation_level = OE_GLOBALS.G_VALID_PARTIAL_WITH_DEF AND
2830               p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
2831         THEN
2832           p_x_header_rec.agreement_id := FND_API.G_MISS_NUM;
2833         ELSE
2834           x_return_status := FND_API.G_RET_STS_ERROR;
2835         END IF;
2836       END IF;
2837 
2838     END IF;
2839 
2840     oe_debug_pub.add('sarita:p_x_header_rec.booked_flag :'||
2841                       p_x_header_rec.booked_flag);
2842 
2843     IF  p_x_header_rec.booked_flag IS NOT NULL AND
2844         ( ( p_x_header_rec.booked_flag <>
2845             p_old_header_rec.booked_flag OR
2846             p_old_header_rec.booked_flag IS NULL ) OR
2847            ( p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE ))
2848         --bug 5060064
2849     THEN
2850       oe_debug_pub.add('sarita:before validate booked flag');
2851 
2852       IF NOT OE_Validate.Booked(p_x_header_rec.booked_flag)
2853       THEN
2854         IF p_validation_level = OE_GLOBALS.G_VALID_LEVEL_PARTIAL AND
2855            p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
2856         THEN
2857           p_x_header_rec.booked_flag := NULL;
2858         ELSIF p_validation_level = OE_GLOBALS.G_VALID_PARTIAL_WITH_DEF AND
2859               p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
2860         THEN
2861           p_x_header_rec.booked_flag := FND_API.G_MISS_CHAR;
2862         ELSE
2863           x_return_status := FND_API.G_RET_STS_ERROR;
2864         END IF;
2865       END IF;
2866 
2867     END IF;
2868 
2869     IF  p_x_header_rec.cancelled_flag IS NOT NULL AND
2870         (  (p_x_header_rec.cancelled_flag <>
2871             p_old_header_rec.cancelled_flag OR
2872             p_old_header_rec.cancelled_flag IS NULL ) OR
2873            ( p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE ))
2874         --bug 5060064
2875     THEN
2876 
2877       IF NOT OE_Validate.Cancelled(p_x_header_rec.cancelled_flag)
2878       THEN
2879         IF p_validation_level = OE_GLOBALS.G_VALID_LEVEL_PARTIAL AND
2880            p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
2881         THEN
2882           p_x_header_rec.cancelled_flag := NULL;
2883         ELSIF p_validation_level = OE_GLOBALS.G_VALID_PARTIAL_WITH_DEF AND
2884               p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
2885         THEN
2886           p_x_header_rec.cancelled_flag := FND_API.G_MISS_CHAR;
2887         ELSE
2888           x_return_status := FND_API.G_RET_STS_ERROR;
2889         END IF;
2890       END IF;
2891 
2892     END IF;
2893 
2894     IF  p_x_header_rec.conversion_type_code IS NOT NULL AND
2895         (  (p_x_header_rec.conversion_type_code <>
2896             p_old_header_rec.conversion_type_code OR
2897             p_old_header_rec.conversion_type_code IS NULL ) OR
2898            ( p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE ))
2899         --bug 5060064
2900     THEN
2901 
2902       IF NOT OE_Validate.Conversion_Type(p_x_header_rec.conversion_type_code)
2903       THEN
2904         IF p_validation_level = OE_GLOBALS.G_VALID_LEVEL_PARTIAL AND
2905            p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
2906         THEN
2907           p_x_header_rec.conversion_type_code := NULL;
2908         ELSIF p_validation_level = OE_GLOBALS.G_VALID_PARTIAL_WITH_DEF AND
2909               p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
2910         THEN
2911           p_x_header_rec.conversion_type_code := FND_API.G_MISS_CHAR;
2912         ELSE
2913           x_return_status := FND_API.G_RET_STS_ERROR;
2914         END IF;
2915       END IF;
2916 
2917     END IF;
2918 
2919     IF  p_x_header_rec.deliver_to_contact_id IS NOT NULL AND
2920         (  (p_x_header_rec.deliver_to_contact_id <>
2921             p_old_header_rec.deliver_to_contact_id OR
2922             p_old_header_rec.deliver_to_contact_id IS NULL ) OR
2923            ( p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE ))
2924         --bug 5060064
2925     THEN
2926 
2927       IF NOT OE_Validate.Deliver_To_Contact(p_x_header_rec.deliver_to_contact_id)      THEN
2928         IF p_validation_level = OE_GLOBALS.G_VALID_LEVEL_PARTIAL AND
2929            p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
2930         THEN
2931           p_x_header_rec.deliver_to_contact_id := NULL;
2932         ELSIF p_validation_level = OE_GLOBALS.G_VALID_PARTIAL_WITH_DEF AND
2933               p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
2934         THEN
2935           p_x_header_rec.deliver_to_contact_id := FND_API.G_MISS_NUM;
2936         ELSE
2937           x_return_status := FND_API.G_RET_STS_ERROR;
2938         END IF;
2939       END IF;
2940 
2941     END IF;
2942 
2943     IF  p_x_header_rec.deliver_to_org_id IS NOT NULL AND
2944         ( ( p_x_header_rec.deliver_to_org_id <>
2945             p_old_header_rec.deliver_to_org_id OR
2946             p_old_header_rec.deliver_to_org_id IS NULL ) OR
2947            ( p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE ))
2948         --bug 5060064
2949     THEN
2950 
2951       IF NOT OE_Validate.Deliver_To_Org(p_x_header_rec.deliver_to_org_id)
2952       THEN
2953         IF p_validation_level = OE_GLOBALS.G_VALID_LEVEL_PARTIAL AND
2954            p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
2955         THEN
2956           p_x_header_rec.deliver_to_org_id := NULL;
2957         ELSIF p_validation_level = OE_GLOBALS.G_VALID_PARTIAL_WITH_DEF AND
2958               p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
2959         THEN
2960           p_x_header_rec.deliver_to_org_id := FND_API.G_MISS_NUM;
2961         ELSE
2962           x_return_status := FND_API.G_RET_STS_ERROR;
2963         END IF;
2964       END IF;
2965 
2966     END IF;
2967 
2968     IF  p_x_header_rec.demAND_class_code IS NOT NULL AND
2969         (  (p_x_header_rec.demAND_class_code <>
2970             p_old_header_rec.demAND_class_code OR
2971             p_old_header_rec.demAND_class_code IS NULL ) OR
2972            ( p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE ))
2973         --bug 5060064
2974     THEN
2975 
2976       IF NOT OE_Validate.DemAND_Class(p_x_header_rec.demAND_class_code)
2977       THEN
2978         IF p_validation_level = OE_GLOBALS.G_VALID_LEVEL_PARTIAL AND
2979            p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
2980         THEN
2981           p_x_header_rec.demAND_class_code := NULL;
2982         ELSIF p_validation_level = OE_GLOBALS.G_VALID_PARTIAL_WITH_DEF AND
2983               p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
2984         THEN
2985           p_x_header_rec.demAND_class_code := FND_API.G_MISS_CHAR;
2986         ELSE
2987           x_return_status := FND_API.G_RET_STS_ERROR;
2988         END IF;
2989       END IF;
2990 
2991     END IF;
2992 
2993     IF  p_x_header_rec.fob_point_code IS NOT NULL AND
2994         ( ( p_x_header_rec.fob_point_code <>
2995             p_old_header_rec.fob_point_code OR
2996             p_old_header_rec.fob_point_code IS NULL ) OR
2997            ( p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE ))
2998         --bug 5060064
2999     THEN
3000 
3001       IF NOT OE_Validate.Fob_Point(p_x_header_rec.fob_point_code)
3002       THEN
3003         IF p_validation_level = OE_GLOBALS.G_VALID_LEVEL_PARTIAL AND
3004            p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
3005         THEN
3006           p_x_header_rec.fob_point_code := NULL;
3007         ELSIF p_validation_level = OE_GLOBALS.G_VALID_PARTIAL_WITH_DEF AND
3008               p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
3009         THEN
3010           p_x_header_rec.fob_point_code := FND_API.G_MISS_CHAR;
3011         ELSE
3012           x_return_status := FND_API.G_RET_STS_ERROR;
3013         END IF;
3014       END IF;
3015 
3016     END IF;
3017 
3018     IF  p_x_header_rec.freight_terms_code IS NOT NULL AND
3019         (  (p_x_header_rec.freight_terms_code <>
3020             p_old_header_rec.freight_terms_code OR
3021             p_old_header_rec.freight_terms_code IS NULL ) OR
3022            ( p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE ))
3023         --bug 5060064
3024     THEN
3025 
3026       IF NOT OE_Validate.Freight_Terms(p_x_header_rec.freight_terms_code)
3027       THEN
3028         IF p_validation_level = OE_GLOBALS.G_VALID_LEVEL_PARTIAL AND
3029            p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
3030         THEN
3031           p_x_header_rec.freight_terms_code := NULL;
3032         ELSIF p_validation_level = OE_GLOBALS.G_VALID_PARTIAL_WITH_DEF AND
3033               p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
3034         THEN
3035           p_x_header_rec.freight_terms_code := FND_API.G_MISS_CHAR;
3036         ELSE
3037           x_return_status := FND_API.G_RET_STS_ERROR;
3038         END IF;
3039       END IF;
3040 
3041     END IF;
3042 
3043     IF  p_x_header_rec.invoice_to_contact_id IS NOT NULL AND
3044         (  (p_x_header_rec.invoice_to_contact_id <>
3045             p_old_header_rec.invoice_to_contact_id OR
3046             p_old_header_rec.invoice_to_contact_id IS NULL ) OR
3047            ( p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE ))
3048         --bug 5060064
3049     THEN
3050 
3051       IF NOT OE_Validate.Invoice_To_Contact(p_x_header_rec.invoice_to_contact_id)      THEN
3052         IF p_validation_level = OE_GLOBALS.G_VALID_LEVEL_PARTIAL AND
3053            p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
3054         THEN
3055           p_x_header_rec.invoice_to_contact_id := NULL;
3056         ELSIF p_validation_level = OE_GLOBALS.G_VALID_PARTIAL_WITH_DEF AND
3057               p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
3058         THEN
3059           p_x_header_rec.invoice_to_contact_id := FND_API.G_MISS_NUM;
3060         ELSE
3061           x_return_status := FND_API.G_RET_STS_ERROR;
3062         END IF;
3063       END IF;
3064 
3065     END IF;
3066 
3067     IF  p_x_header_rec.invoice_to_org_id IS NOT NULL AND
3068         (  (p_x_header_rec.invoice_to_org_id <>
3069             p_old_header_rec.invoice_to_org_id OR
3070             p_old_header_rec.invoice_to_org_id IS NULL ) OR
3071            ( p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE ))
3072         --bug 5060064
3073     THEN
3074 
3075       IF NOT OE_Validate.Invoice_To_Org(p_x_header_rec.invoice_to_org_id)
3076       THEN
3077        IF p_validation_level = OE_GLOBALS.G_VALID_LEVEL_PARTIAL AND
3078           p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
3079        THEN
3080           p_x_header_rec.invoice_to_org_id := NULL;
3081        ELSIF p_validation_level = OE_GLOBALS.G_VALID_PARTIAL_WITH_DEF AND
3082              p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
3083        THEN
3084          p_x_header_rec.invoice_to_org_id := FND_API.G_MISS_NUM;
3085        ELSE
3086          x_return_status := FND_API.G_RET_STS_ERROR;
3087        END IF;
3088      END IF;
3089 
3090     END IF;
3091 
3092     IF  p_x_header_rec.invoicing_rule_id IS NOT NULL AND
3093         ( ( p_x_header_rec.invoicing_rule_id <>
3094             p_old_header_rec.invoicing_rule_id OR
3095             p_old_header_rec.invoicing_rule_id IS NULL ) OR
3096            ( p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE ))
3097         --bug 5060064
3098     THEN
3099 
3100       IF NOT OE_Validate.Invoicing_Rule(p_x_header_rec.invoicing_rule_id)
3101       THEN
3102         IF p_validation_level = OE_GLOBALS.G_VALID_LEVEL_PARTIAL AND
3103            p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
3104         THEN
3105           p_x_header_rec.invoicing_rule_id := NULL;
3106         ELSIF p_validation_level = OE_GLOBALS.G_VALID_PARTIAL_WITH_DEF AND
3107               p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
3108         THEN
3109           p_x_header_rec.invoicing_rule_id := FND_API.G_MISS_NUM;
3110         ELSE
3111           x_return_status := FND_API.G_RET_STS_ERROR;
3112         END IF;
3113       END IF;
3114 
3115     END IF;
3116 
3117     IF  p_x_header_rec.open_flag IS NOT NULL AND
3118         (  (p_x_header_rec.open_flag <>
3119             p_old_header_rec.open_flag OR
3120             p_old_header_rec.open_flag IS NULL ) OR
3121            ( p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE ))
3122         --bug 5060064
3123     THEN
3124 
3125       IF NOT OE_Validate.Open(p_x_header_rec.open_flag)
3126       THEN
3127         IF p_validation_level = OE_GLOBALS.G_VALID_LEVEL_PARTIAL AND
3128            p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
3129         THEN
3130           p_x_header_rec.open_flag := NULL;
3131         ELSIF p_validation_level = OE_GLOBALS.G_VALID_PARTIAL_WITH_DEF AND
3132               p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
3133         THEN
3134           p_x_header_rec.open_flag := FND_API.G_MISS_CHAR;
3135         ELSE
3136           x_return_status := FND_API.G_RET_STS_ERROR;
3137         END IF;
3138       END IF;
3139 
3140     END IF;
3141 
3142     IF  p_x_header_rec.order_date_type_code IS NOT NULL AND
3143         (  (p_x_header_rec.order_date_type_code <>
3144             p_old_header_rec.order_date_type_code OR
3145             p_old_header_rec.order_date_type_code IS NULL ) OR
3146            ( p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE ))
3147         --bug 5060064
3148     THEN
3149 
3150       IF NOT OE_Validate.Order_Date_Type_Code
3151                          (p_x_header_rec.order_date_type_code)
3152       THEN
3153         IF p_validation_level = OE_GLOBALS.G_VALID_LEVEL_PARTIAL AND
3154            p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
3155         THEN
3156           p_x_header_rec.order_date_type_code := NULL;
3157         ELSIF p_validation_level = OE_GLOBALS.G_VALID_PARTIAL_WITH_DEF AND
3158               p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
3159         THEN
3160           p_x_header_rec.order_date_type_code := FND_API.G_MISS_CHAR;
3161         ELSE
3162           x_return_status := FND_API.G_RET_STS_ERROR;
3163         END IF;
3164       END IF;
3165 
3166     END IF;
3167 
3168     oe_debug_pub.add('sarita: p_x_header_rec.order_type_id:'||
3169                         p_x_header_rec.order_type_id);
3170     oe_debug_pub.add('sarita: p_old_header_rec.order_type_id:'||
3171                         p_old_header_rec.order_type_id);
3172 
3173     IF  p_x_header_rec.order_type_id IS NOT NULL AND
3174         (  (p_x_header_rec.order_type_id <>
3175             p_old_header_rec.order_type_id OR
3176             p_old_header_rec.order_type_id IS NULL ) OR
3177            ( p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE ))
3178         --bug 5060064
3179     THEN
3180       oe_debug_pub.add('Before OE_Validate.Order_Type');
3181 
3182       IF NOT OE_Validate.Order_Type(p_x_header_rec.order_type_id)
3183       THEN
3184         IF p_validation_level = OE_GLOBALS.G_VALID_LEVEL_PARTIAL AND
3185            p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
3186         THEN
3187           p_x_header_rec.order_type_id := NULL;
3188         ELSIF p_validation_level = OE_GLOBALS.G_VALID_PARTIAL_WITH_DEF AND
3189               p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
3190         THEN
3191           p_x_header_rec.order_type_id := FND_API.G_MISS_NUM;
3192         ELSE
3193           x_return_status := FND_API.G_RET_STS_ERROR;
3194         END IF;
3195       END IF;
3196 
3197     END IF;
3198 
3199     IF  p_x_header_rec.payment_term_id IS NOT NULL AND
3200         (  (p_x_header_rec.payment_term_id <>
3201             p_old_header_rec.payment_term_id OR
3202             p_old_header_rec.payment_term_id IS NULL ) OR
3203            ( p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE ))
3204         --bug 5060064
3205     THEN
3206 
3207       IF NOT OE_Validate.Payment_Term(p_x_header_rec.payment_term_id)
3208       THEN
3209         IF p_validation_level = OE_GLOBALS.G_VALID_LEVEL_PARTIAL AND
3210            p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
3211         THEN
3212           p_x_header_rec.payment_term_id := NULL;
3213         ELSIF p_validation_level = OE_GLOBALS.G_VALID_PARTIAL_WITH_DEF AND
3214               p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
3215         THEN
3216           p_x_header_rec.payment_term_id := FND_API.G_MISS_NUM;
3217         ELSE
3218           x_return_status := FND_API.G_RET_STS_ERROR;
3219         END IF;
3220       END IF;
3221 
3222     END IF;
3223 
3224     IF  p_x_header_rec.price_list_id IS NOT NULL AND
3225         (  (p_x_header_rec.price_list_id <>
3226             p_old_header_rec.price_list_id OR
3227             p_old_header_rec.price_list_id IS NULL ) OR
3228            ( p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE ))
3229         --bug 5060064
3230     THEN
3231 
3232       IF NOT OE_Validate.Price_List(p_x_header_rec.price_list_id)
3233       THEN
3234       -- Bug 3572931 Commented the code below.
3235       -- p_x_header_rec.price_list_id := NULL;
3236       -- ELSE
3237       -- IF p_validation_level = OE_GLOBALS.G_VALID_LEVEL_PARTIAL AND
3238       --   p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
3239       -- THEN
3240       --  x_return_status := FND_API.G_RET_STS_ERROR;
3241       -- END IF;
3242       -- Bug 3572931 if the validation level is partial set to NULL,
3243       -- if partial with defaulting set to G_MISS_NUM.
3244          IF p_validation_level = OE_GLOBALS.G_VALID_LEVEL_PARTIAL AND
3245               p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
3246          THEN
3247               p_x_header_rec.price_list_id := NULL;
3248 	 ELSIF p_validation_level = OE_GLOBALS.G_VALID_PARTIAL_WITH_DEF AND
3249               p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
3250          THEN
3251               p_x_header_rec.price_list_id := FND_API.G_MISS_NUM;
3252          ELSE
3253               x_return_status := FND_API.G_RET_STS_ERROR;
3254          END IF;
3255       END IF;
3256 
3257     END IF;
3258 
3259     IF  p_x_header_rec.shipment_priority_code IS NOT NULL AND
3260         (  (p_x_header_rec.shipment_priority_code <>
3261             p_old_header_rec.shipment_priority_code OR
3262             p_old_header_rec.shipment_priority_code IS NULL ) OR
3263            ( p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE ))
3264         --bug 5060064
3265     THEN
3266 
3267       IF NOT OE_Validate.Shipment_Priority(p_x_header_rec.shipment_priority_code)      THEN
3268         IF p_validation_level = OE_GLOBALS.G_VALID_LEVEL_PARTIAL AND
3269            p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
3270         THEN
3271           p_x_header_rec.shipment_priority_code := NULL;
3272         ELSIF p_validation_level = OE_GLOBALS.G_VALID_PARTIAL_WITH_DEF AND
3273               p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
3274         THEN
3275           p_x_header_rec.shipment_priority_code := FND_API.G_MISS_CHAR;
3276         ELSE
3277           x_return_status := FND_API.G_RET_STS_ERROR;
3278         END IF;
3279       END IF;
3280 
3281     END IF;
3282 
3283     IF  p_x_header_rec.shipping_method_code IS NOT NULL AND
3284         (  (p_x_header_rec.shipping_method_code <>
3285             p_old_header_rec.shipping_method_code OR
3286             p_old_header_rec.shipping_method_code IS NULL ) OR
3287            ( p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE ))
3288         --bug 5060064
3289     THEN
3290 
3291       IF NOT OE_Validate.Shipping_Method(p_x_header_rec.shipping_method_code)
3292       THEN
3293         IF p_validation_level = OE_GLOBALS.G_VALID_LEVEL_PARTIAL AND
3294            p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
3295         THEN
3296           p_x_header_rec.shipping_method_code := NULL;
3297         ELSIF p_validation_level = OE_GLOBALS.G_VALID_PARTIAL_WITH_DEF AND
3298               p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
3299         THEN
3300           p_x_header_rec.shipping_method_code := FND_API.G_MISS_CHAR;
3301         ELSE
3302           x_return_status := FND_API.G_RET_STS_ERROR;
3303         END IF;
3304       END IF;
3305 
3306     END IF;
3307 
3308     IF  p_x_header_rec.ship_from_org_id IS NOT NULL AND
3309         (  (p_x_header_rec.ship_from_org_id <>
3310             p_old_header_rec.ship_from_org_id OR
3311             p_old_header_rec.ship_from_org_id IS NULL ) OR
3312            ( p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE ))
3313         --bug 5060064
3314     THEN
3315 
3316       IF NOT OE_Validate.Ship_From_Org(p_x_header_rec.ship_from_org_id)
3317       THEN
3318         IF p_validation_level = OE_GLOBALS.G_VALID_LEVEL_PARTIAL AND
3319            p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
3320         THEN
3321           p_x_header_rec.ship_from_org_id := NULL;
3322         ELSIF p_validation_level = OE_GLOBALS.G_VALID_PARTIAL_WITH_DEF AND
3323               p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
3324         THEN
3325           p_x_header_rec.ship_from_org_id := FND_API.G_MISS_NUM;
3326         ELSE
3327           x_return_status := FND_API.G_RET_STS_ERROR;
3328         END IF;
3329       END IF;
3330 
3331     END IF;
3332 
3333     IF  p_x_header_rec.ship_to_contact_id IS NOT NULL AND
3334         (  (p_x_header_rec.ship_to_contact_id <>
3335             p_old_header_rec.ship_to_contact_id OR
3336             p_old_header_rec.ship_to_contact_id IS NULL ) OR
3337            ( p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE ))
3338         --bug 5060064
3339     THEN
3340 
3341       IF NOT OE_Validate.Ship_To_Contact(p_x_header_rec.ship_to_contact_id)
3342       THEN
3343         IF p_validation_level = OE_GLOBALS.G_VALID_LEVEL_PARTIAL AND
3344            p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
3345         THEN
3346           p_x_header_rec.ship_to_contact_id := NULL;
3347         ELSIF p_validation_level = OE_GLOBALS.G_VALID_PARTIAL_WITH_DEF AND
3348               p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
3349         THEN
3350           p_x_header_rec.ship_to_contact_id := FND_API.G_MISS_NUM;
3351         ELSE
3352           x_return_status := FND_API.G_RET_STS_ERROR;
3353         END IF;
3354       END IF;
3355 
3356     END IF;
3357 
3358     IF  p_x_header_rec.ship_to_org_id IS NOT NULL AND
3359         (  (p_x_header_rec.ship_to_org_id <>
3360             p_old_header_rec.ship_to_org_id OR
3361             p_old_header_rec.ship_to_org_id IS NULL ) OR
3362            ( p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE ))
3363         --bug 5060064
3364     THEN
3365 
3366       IF NOT OE_Validate.Ship_To_Org(p_x_header_rec.ship_to_org_id)
3367       THEN
3368         IF p_validation_level = OE_GLOBALS.G_VALID_LEVEL_PARTIAL AND
3369            p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
3370         THEN
3371           p_x_header_rec.ship_to_org_id := NULL;
3372         ELSIF p_validation_level = OE_GLOBALS.G_VALID_PARTIAL_WITH_DEF AND
3373               p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
3374         THEN
3375           p_x_header_rec.ship_to_org_id := FND_API.G_MISS_NUM;
3376         ELSE
3377           x_return_status := FND_API.G_RET_STS_ERROR;
3378         END IF;
3379       END IF;
3380 
3381     END IF;
3382 
3383 
3384     IF  p_x_header_rec.sold_to_contact_id IS NOT NULL AND
3385         (  (p_x_header_rec.sold_to_contact_id <>
3386             p_old_header_rec.sold_to_contact_id OR
3387             p_old_header_rec.sold_to_contact_id IS NULL ) OR
3388            ( p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE ))
3389         --bug 5060064
3390     THEN
3391 
3392       IF NOT OE_Validate.Sold_To_Contact(p_x_header_rec.sold_to_contact_id)
3393       THEN
3394         IF p_validation_level = OE_GLOBALS.G_VALID_LEVEL_PARTIAL AND
3395            p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
3396         THEN
3397           p_x_header_rec.sold_to_contact_id := NULL;
3398         ELSIF p_validation_level = OE_GLOBALS.G_VALID_PARTIAL_WITH_DEF AND
3399               p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
3400         THEN
3401           p_x_header_rec.sold_to_contact_id := FND_API.G_MISS_NUM;
3402         ELSE
3403           x_return_status := FND_API.G_RET_STS_ERROR;
3404         END IF;
3405       END IF;
3406 
3407     END IF;
3408 
3409     IF  p_x_header_rec.sold_to_org_id IS NOT NULL AND
3410         (  (p_x_header_rec.sold_to_org_id <>
3411             p_old_header_rec.sold_to_org_id OR
3412             p_old_header_rec.sold_to_org_id IS NULL ) OR
3413            ( p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE ))
3414         --bug 5060064
3415     THEN
3416 
3417       IF NOT OE_Validate.Sold_To_Org(p_x_header_rec.sold_to_org_id)
3418       THEN
3419         IF p_validation_level = OE_GLOBALS.G_VALID_LEVEL_PARTIAL AND
3420            p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
3421         THEN
3422           p_x_header_rec.sold_to_org_id := NULL;
3423         ELSIF p_validation_level = OE_GLOBALS.G_VALID_PARTIAL_WITH_DEF AND
3424               p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
3425         THEN
3426           p_x_header_rec.sold_to_org_id := FND_API.G_MISS_NUM;
3427         ELSE
3428           x_return_status := FND_API.G_RET_STS_ERROR;
3429         END IF;
3430       END IF;
3431 
3432     END IF;
3433 
3434     IF  p_x_header_rec.sold_to_phone_id IS NOT NULL AND
3435         (  (p_x_header_rec.sold_to_phone_id <>
3436             p_old_header_rec.sold_to_phone_id OR
3437             p_old_header_rec.sold_to_phone_id IS NULL ) OR
3438            ( p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE ))
3439         --bug 5060064
3440     THEN
3441 
3442       IF NOT OE_Validate.Sold_To_Phone(p_x_header_rec.sold_to_phone_id)
3443       THEN
3444         IF p_validation_level = OE_GLOBALS.G_VALID_LEVEL_PARTIAL AND
3445            p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
3446         THEN
3447           p_x_header_rec.sold_to_phone_id := NULL;
3448         ELSIF p_validation_level = OE_GLOBALS.G_VALID_PARTIAL_WITH_DEF AND
3449               p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
3450         THEN
3451           p_x_header_rec.sold_to_phone_id := FND_API.G_MISS_NUM;
3452         ELSE
3453           x_return_status := FND_API.G_RET_STS_ERROR;
3454         END IF;
3455       END IF;
3456 
3457     END IF;
3458 
3459     IF  p_x_header_rec.source_document_type_id IS NOT NULL AND
3460         (  (p_x_header_rec.source_document_type_id <>
3461             p_old_header_rec.source_document_type_id OR
3462             p_old_header_rec.source_document_type_id IS NULL ) OR
3463            ( p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE ))
3464         --bug 5060064
3465     THEN
3466 
3467         IF NOT OE_Validate.Source_Document_Type
3468                            (p_x_header_rec.source_document_type_id)
3469         THEN
3470           IF p_validation_level = OE_GLOBALS.G_VALID_LEVEL_PARTIAL AND
3471              p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
3472           THEN
3473             p_x_header_rec.source_document_type_id := NULL;
3474           ELSIF p_validation_level = OE_GLOBALS.G_VALID_PARTIAL_WITH_DEF AND
3475                 p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
3476           THEN
3477             p_x_header_rec.source_document_type_id := FND_API.G_MISS_NUM;
3478           ELSE
3479             x_return_status := FND_API.G_RET_STS_ERROR;
3480           END IF;
3481         END IF;
3482 
3483     END IF;
3484 
3485     IF  p_x_header_rec.tax_exempt_flag IS NOT NULL AND
3486         (  (p_x_header_rec.tax_exempt_flag <>
3487             p_old_header_rec.tax_exempt_flag OR
3488             p_old_header_rec.tax_exempt_flag IS NULL ) OR
3489            ( p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE ))
3490         --bug 5060064
3491     THEN
3492       IF NOT OE_Validate.Tax_Exempt(p_x_header_rec.tax_exempt_flag)
3493       THEN
3494         IF p_validation_level = OE_GLOBALS.G_VALID_LEVEL_PARTIAL AND
3495            p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
3496         THEN
3497           p_x_header_rec.tax_exempt_flag := NULL;
3498         ELSIF p_validation_level = OE_GLOBALS.G_VALID_PARTIAL_WITH_DEF AND
3499               p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
3500         THEN
3501           p_x_header_rec.tax_exempt_flag := FND_API.G_MISS_CHAR;
3502         ELSE
3503           x_return_status := FND_API.G_RET_STS_ERROR;
3504         END IF;
3505       END IF;
3506 
3507     END IF;
3508 
3509     IF  p_x_header_rec.tax_exempt_reason_code IS NOT NULL AND
3510         (  (p_x_header_rec.tax_exempt_reason_code <>
3511             p_old_header_rec.tax_exempt_reason_code OR
3512             p_old_header_rec.tax_exempt_reason_code IS NULL ) OR
3513            ( p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE ))
3514         --bug 5060064
3515     THEN
3516 
3517       IF NOT OE_Validate.Tax_Exempt_Reason
3518                          (p_x_header_rec.tax_exempt_reason_code)
3519       THEN
3520         IF p_validation_level = OE_GLOBALS.G_VALID_LEVEL_PARTIAL AND
3521            p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
3522         THEN
3523           p_x_header_rec.tax_exempt_reason_code := NULL;
3524         ELSIF p_validation_level = OE_GLOBALS.G_VALID_PARTIAL_WITH_DEF AND
3525               p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
3526         THEN
3527           p_x_header_rec.tax_exempt_reason_code := FND_API.G_MISS_CHAR;
3528         ELSE
3529           x_return_status := FND_API.G_RET_STS_ERROR;
3530         END IF;
3531       END IF;
3532 
3533     END IF;
3534 
3535     IF  p_x_header_rec.tax_point_code IS NOT NULL AND
3536         ( ( p_x_header_rec.tax_point_code <>
3537             p_old_header_rec.tax_point_code OR
3538             p_old_header_rec.tax_point_code IS NULL ) OR
3539            ( p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE ))
3540         --bug 5060064
3541     THEN
3542 
3543       IF NOT OE_Validate.Tax_Point(p_x_header_rec.tax_point_code)
3544       THEN
3545         IF p_validation_level = OE_GLOBALS.G_VALID_LEVEL_PARTIAL AND
3546            p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
3547         THEN
3548           p_x_header_rec.tax_point_code := NULL;
3549         ELSIF p_validation_level = OE_GLOBALS.G_VALID_PARTIAL_WITH_DEF AND
3550               p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
3551         THEN
3552           p_x_header_rec.tax_point_code := FND_API.G_MISS_CHAR;
3553         ELSE
3554           x_return_status := FND_API.G_RET_STS_ERROR;
3555         END IF;
3556       END IF;
3557 
3558     END IF;
3559 
3560     IF  p_x_header_rec.transactional_curr_code IS NOT NULL AND
3561         (  (p_x_header_rec.transactional_curr_code <>
3562             p_old_header_rec.transactional_curr_code OR
3563             p_old_header_rec.transactional_curr_code IS NULL ) OR
3564            ( p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE ))
3565         --bug 5060064
3566     THEN
3567 
3568       IF NOT OE_Validate.Transactional_Curr
3569                          (p_x_header_rec.transactional_curr_code)
3570       THEN
3571         IF p_validation_level = OE_GLOBALS.G_VALID_LEVEL_PARTIAL AND
3572            p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
3573         THEN
3574           p_x_header_rec.transactional_curr_code := NULL;
3575         ELSIF p_validation_level = OE_GLOBALS.G_VALID_PARTIAL_WITH_DEF AND
3576               p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
3577         THEN
3578           p_x_header_rec.transactional_curr_code := FND_API.G_MISS_CHAR;
3579         ELSE
3580           x_return_status := FND_API.G_RET_STS_ERROR;
3581         END IF;
3582       END IF;
3583 
3584     END IF;
3585 
3586     IF  p_x_header_rec.payment_type_code IS NOT NULL AND
3587         (  (p_x_header_rec.payment_type_code <>
3588             p_old_header_rec.payment_type_code OR
3589             p_old_header_rec.payment_type_code IS NULL ) OR
3590            ( p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE ))
3591         --bug 5060064
3592     THEN
3593 
3594       IF NOT OE_Validate.Payment_Type(p_x_header_rec.payment_type_code)
3595       THEN
3596         IF p_validation_level = OE_GLOBALS.G_VALID_LEVEL_PARTIAL AND
3597            p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
3598         THEN
3599           p_x_header_rec.payment_type_code := NULL;
3600         ELSIF p_validation_level = OE_GLOBALS.G_VALID_PARTIAL_WITH_DEF AND
3601               p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
3602         THEN
3603           p_x_header_rec.payment_type_code := FND_API.G_MISS_CHAR;
3604         ELSE
3605           x_return_status := FND_API.G_RET_STS_ERROR;
3606         END IF;
3607       END IF;
3608 
3609     END IF;
3610 
3611     oe_debug_pub.add('after payment_type_code');
3612 
3613     IF  p_x_header_rec.credit_card_code IS NOT NULL AND
3614         ( ( p_x_header_rec.credit_card_code <>
3615             p_old_header_rec.credit_card_code OR
3616             p_old_header_rec.credit_card_code IS NULL ) OR
3617            ( p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE ))
3618         --bug 5060064
3619     THEN
3620       IF NOT OE_Validate.Credit_Card(p_x_header_rec.credit_card_code)
3621       THEN
3622         IF p_validation_level = OE_GLOBALS.G_VALID_LEVEL_PARTIAL AND
3623            p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
3624         THEN
3625           p_x_header_rec.credit_card_code := NULL;
3626         ELSIF p_validation_level = OE_GLOBALS.G_VALID_PARTIAL_WITH_DEF AND
3627               p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
3628         THEN
3629           p_x_header_rec.credit_card_code := FND_API.G_MISS_CHAR;
3630         ELSE
3631           x_return_status := FND_API.G_RET_STS_ERROR;
3632         END IF;
3633       END IF;
3634 
3635     END IF;
3636 
3637     oe_debug_pub.add('after credit_card_code');
3638 
3639     --R12 CVV2
3640     IF p_x_header_rec.credit_card_number IS NOT NULL AND p_x_header_rec.credit_card_number <> FND_API.G_MISS_CHAR THEN
3641       l_cc_security_code_use := OE_Payment_Trxn_Util.Get_CC_Security_Code_Use;
3642       IF l_cc_security_code_use = 'REQUIRED' THEN
3643          IF p_x_header_rec.instrument_security_code IS NULL OR p_x_header_rec.instrument_security_code = FND_API.G_MISS_CHAR THEN --bug 4613168, issue 22
3644             FND_MESSAGE.SET_NAME('ONT','OE_CC_SECURITY_CODE_REQD');
3645             OE_MSG_PUB.ADD;
3646             x_return_status := FND_API.G_RET_STS_ERROR;
3647          END IF;
3648       END IF;
3649     END IF;
3650     --R12 CVV2
3651 
3652     oe_debug_pub.add('after security code');
3653 
3654     IF  p_x_header_rec.flow_status_code IS NOT NULL AND
3655         (  (p_x_header_rec.flow_status_code <>
3656             p_old_header_rec.flow_status_code OR
3657             p_old_header_rec.flow_status_code IS NULL ) OR
3658            ( p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE ))
3659         --bug 5060064
3660     THEN
3661 
3662       IF NOT OE_Validate.Flow_Status(p_x_header_rec.flow_status_code)
3663       THEN
3664         IF p_validation_level = OE_GLOBALS.G_VALID_LEVEL_PARTIAL AND
3665            p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
3666         THEN
3667           p_x_header_rec.flow_status_code := NULL;
3668         ELSIF p_validation_level = OE_GLOBALS.G_VALID_PARTIAL_WITH_DEF AND
3669               p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
3670         THEN
3671           p_x_header_rec.flow_status_code := FND_API.G_MISS_CHAR;
3672         ELSE
3673           x_return_status := FND_API.G_RET_STS_ERROR;
3674         END IF;
3675       END IF;
3676 
3677     END IF;
3678 
3679     oe_Debug_pub.add('after flow_status_code');
3680    if OE_GLOBALS.g_validate_desc_flex ='Y' then -- bug4343612
3681       oe_debug_pub.add('Validation of desc flex is set to Y in OE_Validate_Header.attributes ',1);
3682     IF p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE OR
3683 
3684     (  p_x_header_rec.operation = OE_GLOBALS.G_OPR_UPDATE AND
3685          (p_x_header_rec.attribute1 IS NOT NULL AND
3686         (   p_x_header_rec.attribute1 <>
3687             p_old_header_rec.attribute1 OR
3688             p_old_header_rec.attribute1 IS NULL ))
3689     OR  (p_x_header_rec.attribute10 IS NOT NULL AND
3690         (   p_x_header_rec.attribute10 <>
3691             p_old_header_rec.attribute10 OR
3692             p_old_header_rec.attribute10 IS NULL ))
3693     OR  (p_x_header_rec.attribute11 IS NOT NULL AND
3694         (   p_x_header_rec.attribute11 <>
3695             p_old_header_rec.attribute11 OR
3696             p_old_header_rec.attribute11 IS NULL ))
3697     OR  (p_x_header_rec.attribute12 IS NOT NULL AND
3698         (   p_x_header_rec.attribute12 <>
3699             p_old_header_rec.attribute12 OR
3700             p_old_header_rec.attribute12 IS NULL ))
3701     OR  (p_x_header_rec.attribute13 IS NOT NULL AND
3702         (   p_x_header_rec.attribute13 <>
3703             p_old_header_rec.attribute13 OR
3704             p_old_header_rec.attribute13 IS NULL ))
3705     OR  (p_x_header_rec.attribute14 IS NOT NULL AND
3706         (   p_x_header_rec.attribute14 <>
3707             p_old_header_rec.attribute14 OR
3708             p_old_header_rec.attribute14 IS NULL ))
3709     OR  (p_x_header_rec.attribute15 IS NOT NULL AND
3710         (   p_x_header_rec.attribute15 <>
3711             p_old_header_rec.attribute15 OR
3712             p_old_header_rec.attribute15 IS NULL ))
3713     OR  (p_x_header_rec.attribute16 IS NOT NULL AND --For bug 2184255
3714         (   p_x_header_rec.attribute16 <>
3715             p_old_header_rec.attribute16 OR
3716             p_old_header_rec.attribute16 IS NULL ))
3717     OR  (p_x_header_rec.attribute17 IS NOT NULL AND
3718         (   p_x_header_rec.attribute17 <>
3719             p_old_header_rec.attribute17 OR
3720             p_old_header_rec.attribute17 IS NULL ))
3721     OR  (p_x_header_rec.attribute18 IS NOT NULL AND
3722         (   p_x_header_rec.attribute18 <>
3723             p_old_header_rec.attribute18 OR
3724             p_old_header_rec.attribute18 IS NULL ))
3725     OR  (p_x_header_rec.attribute19 IS NOT NULL AND
3726         (   p_x_header_rec.attribute19 <>
3727             p_old_header_rec.attribute19 OR
3728             p_old_header_rec.attribute19 IS NULL ))
3729     OR  (p_x_header_rec.attribute2 IS NOT NULL AND
3730         (   p_x_header_rec.attribute2 <>
3731             p_old_header_rec.attribute2 OR
3732             p_old_header_rec.attribute2 IS NULL ))
3733     OR  (p_x_header_rec.attribute20 IS NOT NULL AND  -- for bug 2184255
3734         (   p_x_header_rec.attribute20 <>
3735             p_old_header_rec.attribute20 OR
3736             p_old_header_rec.attribute20 IS NULL ))
3737     OR  (p_x_header_rec.attribute3 IS NOT NULL AND
3738         (   p_x_header_rec.attribute3 <>
3739             p_old_header_rec.attribute3 OR
3740             p_old_header_rec.attribute3 IS NULL ))
3741     OR  (p_x_header_rec.attribute4 IS NOT NULL AND
3742         (   p_x_header_rec.attribute4 <>
3743             p_old_header_rec.attribute4 OR
3744             p_old_header_rec.attribute4 IS NULL ))
3745     OR  (p_x_header_rec.attribute5 IS NOT NULL AND
3746         (   p_x_header_rec.attribute5 <>
3747             p_old_header_rec.attribute5 OR
3748             p_old_header_rec.attribute5 IS NULL ))
3749     OR  (p_x_header_rec.attribute6 IS NOT NULL AND
3750         (   p_x_header_rec.attribute6 <>
3751             p_old_header_rec.attribute6 OR
3752             p_old_header_rec.attribute6 IS NULL ))
3753     OR  (p_x_header_rec.attribute7 IS NOT NULL AND
3754         (   p_x_header_rec.attribute7 <>
3755             p_old_header_rec.attribute7 OR
3756             p_old_header_rec.attribute7 IS NULL ))
3757     OR  (p_x_header_rec.attribute8 IS NOT NULL AND
3758         (   p_x_header_rec.attribute8 <>
3759             p_old_header_rec.attribute8 OR
3760             p_old_header_rec.attribute8 IS NULL ))
3761     OR  (p_x_header_rec.attribute9 IS NOT NULL AND
3762         (   p_x_header_rec.attribute9 <>
3763             p_old_header_rec.attribute9 OR
3764             p_old_header_rec.attribute9 IS NULL ))
3765     OR  (p_x_header_rec.context IS NOT NULL AND
3766         (   p_x_header_rec.context <>
3767             p_old_header_rec.context OR
3768             p_old_header_rec.context IS NULL )))
3769     THEN
3770 
3771 
3772          oe_debug_pub.add('Before calling header_desc_flex',2);
3773          oe_debug_pub.add('source doc type:'||to_char(p_x_header_rec.source_document_type_id),5);
3774          /*  Fixing 2375476 to skip the Flex field validation in case of
3775              Internal Orders. This condition will be removed once process Order
3776              starts defaulting the FF */
3777          /*  Fixing 2611912 to skip the Flex field validation in case of
3778              orders coming from CRM. This condition can be removed once process Order
3779              starts defaulting the FF */
3780 	IF OE_ORDER_CACHE.IS_FLEX_ENABLED('OE_HEADER_ATTRIBUTES') = 'Y' THEN
3781         -- AND p_x_header_rec.order_source_id <> 10 AND -- added for 2611912
3782 --             (p_x_header_rec.source_document_type_id IS NULL OR
3783 --              p_x_header_rec.source_document_type_id = FND_API.G_MISS_NUM OR
3784 --              p_x_header_rec.source_document_type_id = 2) THEN
3785 -- commented above, bug 2511313
3786 
3787          IF NOT OE_VALIDATE.Header_Desc_Flex
3788           (p_context            => p_x_header_rec.context
3789           ,p_attribute1         => p_x_header_rec.attribute1
3790           ,p_attribute2         => p_x_header_rec.attribute2
3791           ,p_attribute3         => p_x_header_rec.attribute3
3792           ,p_attribute4         => p_x_header_rec.attribute4
3793           ,p_attribute5         => p_x_header_rec.attribute5
3794           ,p_attribute6         => p_x_header_rec.attribute6
3795           ,p_attribute7         => p_x_header_rec.attribute7
3796           ,p_attribute8         => p_x_header_rec.attribute8
3797           ,p_attribute9         => p_x_header_rec.attribute9
3798           ,p_attribute10        => p_x_header_rec.attribute10
3799           ,p_attribute11        => p_x_header_rec.attribute11
3800           ,p_attribute12        => p_x_header_rec.attribute12
3801           ,p_attribute13        => p_x_header_rec.attribute13
3802           ,p_attribute14        => p_x_header_rec.attribute14
3803           ,p_attribute15        => p_x_header_rec.attribute15
3804           ,p_attribute16        => p_x_header_rec.attribute16  -- for bug 2184255
3805           ,p_attribute17        => p_x_header_rec.attribute17
3806           ,p_attribute18        => p_x_header_rec.attribute18
3807           ,p_attribute19        => p_x_header_rec.attribute19
3808           ,p_attribute20        => p_x_header_rec.attribute20)
3809           THEN
3810 
3811             IF p_validation_level = OE_GLOBALS.G_VALID_LEVEL_PARTIAL AND
3812                p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
3813             THEN
3814                 p_x_header_rec.context    := null;
3815                 p_x_header_rec.attribute1 := null;
3816                 p_x_header_rec.attribute2 := null;
3817                 p_x_header_rec.attribute3 := null;
3818                 p_x_header_rec.attribute4 := null;
3819                 p_x_header_rec.attribute5 := null;
3820                 p_x_header_rec.attribute6 := null;
3821                 p_x_header_rec.attribute7 := null;
3822                 p_x_header_rec.attribute8 := null;
3823                 p_x_header_rec.attribute9 := null;
3824                 p_x_header_rec.attribute10 := null;
3825                 p_x_header_rec.attribute11 := null;
3826                 p_x_header_rec.attribute12 := null;
3827                 p_x_header_rec.attribute13 := null;
3828                 p_x_header_rec.attribute14 := null;
3829                 p_x_header_rec.attribute15 := null;
3830                 p_x_header_rec.attribute16 := null;  -- for bug 2184255
3831                 p_x_header_rec.attribute17 := null;
3832                 p_x_header_rec.attribute18 := null;
3833                 p_x_header_rec.attribute19 := null;
3834                 p_x_header_rec.attribute20 := null;
3835 
3836 
3837             ELSIF p_validation_level = OE_GLOBALS.G_VALID_PARTIAL_WITH_DEF AND
3838                   p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
3839             THEN
3840                 p_x_header_rec.context    := FND_API.G_MISS_CHAR;
3841                 p_x_header_rec.attribute1 := FND_API.G_MISS_CHAR;
3842                 p_x_header_rec.attribute2 := FND_API.G_MISS_CHAR;
3843                 p_x_header_rec.attribute3 := FND_API.G_MISS_CHAR;
3844                 p_x_header_rec.attribute4 := FND_API.G_MISS_CHAR;
3845                 p_x_header_rec.attribute5 := FND_API.G_MISS_CHAR;
3846                 p_x_header_rec.attribute6 := FND_API.G_MISS_CHAR;
3847                 p_x_header_rec.attribute7 := FND_API.G_MISS_CHAR;
3848                 p_x_header_rec.attribute8 := FND_API.G_MISS_CHAR;
3849                 p_x_header_rec.attribute9 := FND_API.G_MISS_CHAR;
3850                 p_x_header_rec.attribute10 := FND_API.G_MISS_CHAR;
3851                 p_x_header_rec.attribute11 := FND_API.G_MISS_CHAR;
3852                 p_x_header_rec.attribute12 := FND_API.G_MISS_CHAR;
3853                 p_x_header_rec.attribute13 := FND_API.G_MISS_CHAR;
3854                 p_x_header_rec.attribute14 := FND_API.G_MISS_CHAR;
3855                 p_x_header_rec.attribute15 := FND_API.G_MISS_CHAR;
3856                 p_x_header_rec.attribute16 := FND_API.G_MISS_CHAR;  -- for bug 2184255
3857                 p_x_header_rec.attribute17 := FND_API.G_MISS_CHAR;
3858                 p_x_header_rec.attribute18 := FND_API.G_MISS_CHAR;
3859                 p_x_header_rec.attribute19 := FND_API.G_MISS_CHAR;
3860                 p_x_header_rec.attribute20 := FND_API.G_MISS_CHAR;
3861 
3862 
3863             ELSE
3864                 x_return_status := FND_API.G_RET_STS_ERROR;
3865             END IF;
3866 	  ELSE -- if the flex validation is successfull
3867 	    -- For bug 2511313
3868 	    IF p_x_header_rec.context IS NULL
3869 	      OR p_x_header_rec.context = FND_API.G_MISS_CHAR THEN
3870 	       p_x_header_rec.context    := oe_validate.g_context;
3871 	    END IF;
3872 
3873 	    IF p_x_header_rec.attribute1 IS NULL
3874 	      OR p_x_header_rec.attribute1 = FND_API.G_MISS_CHAR THEN
3875 	       p_x_header_rec.attribute1 := oe_validate.g_attribute1;
3876 	    END IF;
3877 
3878 	    IF p_x_header_rec.attribute2 IS NULL
3879 	      OR p_x_header_rec.attribute2 = FND_API.G_MISS_CHAR THEN
3880 	       p_x_header_rec.attribute2 := oe_validate.g_attribute2;
3881 	    END IF;
3882 
3883 	    IF p_x_header_rec.attribute3 IS NULL
3884 	      OR p_x_header_rec.attribute3 = FND_API.G_MISS_CHAR THEN
3885 	       p_x_header_rec.attribute3 := oe_validate.g_attribute3;
3886 	    END IF;
3887 
3888 	    IF p_x_header_rec.attribute4 IS NULL
3889 	      OR p_x_header_rec.attribute4 = FND_API.G_MISS_CHAR THEN
3890 	       p_x_header_rec.attribute4 := oe_validate.g_attribute4;
3891 	    END IF;
3892 
3893 	    IF p_x_header_rec.attribute5 IS NULL
3894 	      OR p_x_header_rec.attribute5 = FND_API.G_MISS_CHAR THEN
3895 	       p_x_header_rec.attribute5 := oe_validate.g_attribute5;
3896 	    END IF;
3897 
3898 	    IF p_x_header_rec.attribute6 IS NULL
3899 	      OR p_x_header_rec.attribute6 = FND_API.G_MISS_CHAR THEN
3900 	       p_x_header_rec.attribute6 := oe_validate.g_attribute6;
3901 	    END IF;
3902 
3903 	    IF p_x_header_rec.attribute7 IS NULL
3904 	      OR p_x_header_rec.attribute7 = FND_API.G_MISS_CHAR THEN
3905 	       p_x_header_rec.attribute7 := oe_validate.g_attribute7;
3906 	    END IF;
3907 
3908 	    IF p_x_header_rec.attribute8 IS NULL
3909 	      OR p_x_header_rec.attribute8 = FND_API.G_MISS_CHAR THEN
3910 	       p_x_header_rec.attribute8 := oe_validate.g_attribute8;
3911 	    END IF;
3912 
3913 	    IF p_x_header_rec.attribute9 IS NULL
3914 	      OR p_x_header_rec.attribute9 = FND_API.G_MISS_CHAR THEN
3915 	       p_x_header_rec.attribute9 := oe_validate.g_attribute9;
3916 	    END IF;
3917 
3918 	    IF p_x_header_rec.attribute10 IS NULL
3919 	      OR p_x_header_rec.attribute10 = FND_API.G_MISS_CHAR THEN
3920 	       p_x_header_rec.attribute10 := Oe_validate.G_attribute10;
3921 	    End IF;
3922 
3923 	    IF p_x_header_rec.attribute11 IS NULL
3924 	      OR p_x_header_rec.attribute11 = FND_API.G_MISS_CHAR THEN
3925 	       p_x_header_rec.attribute11 := oe_validate.g_attribute11;
3926 	    END IF;
3927 
3928 	    IF p_x_header_rec.attribute12 IS NULL
3929 	      OR p_x_header_rec.attribute12 = FND_API.G_MISS_CHAR THEN
3930 	       p_x_header_rec.attribute12 := oe_validate.g_attribute12;
3931 	    END IF;
3932 
3933 	    IF p_x_header_rec.attribute13 IS NULL
3934 	      OR p_x_header_rec.attribute13 = FND_API.G_MISS_CHAR THEN
3935 	       p_x_header_rec.attribute13 := oe_validate.g_attribute13;
3936 	    END IF;
3937 
3938 	    IF p_x_header_rec.attribute14 IS NULL
3939 	      OR p_x_header_rec.attribute14 = FND_API.G_MISS_CHAR THEN
3940 	       p_x_header_rec.attribute14 := oe_validate.g_attribute14;
3941 	    END IF;
3942 
3943 	    IF p_x_header_rec.attribute15 IS NULL
3944 	      OR p_x_header_rec.attribute15 = FND_API.G_MISS_CHAR THEN
3945 	       p_x_header_rec.attribute15 := oe_validate.g_attribute15;
3946 	    END IF;
3947 
3948 	    IF p_x_header_rec.attribute16 IS NULL  -- for bug 2184255
3949 	      OR p_x_header_rec.attribute16 = FND_API.G_MISS_CHAR THEN
3950 	       p_x_header_rec.attribute16 := oe_validate.g_attribute16;
3951 	    END IF;
3952 
3953 	    IF p_x_header_rec.attribute17 IS NULL
3954 	      OR p_x_header_rec.attribute17 = FND_API.G_MISS_CHAR THEN
3955 	       p_x_header_rec.attribute17 := oe_validate.g_attribute17;
3956 	    END IF;
3957 
3958 	    IF p_x_header_rec.attribute18 IS NULL
3959 	      OR p_x_header_rec.attribute18 = FND_API.G_MISS_CHAR THEN
3960 	       p_x_header_rec.attribute18 := oe_validate.g_attribute18;
3961 	    END IF;
3962 
3963 	    IF p_x_header_rec.attribute19 IS NULL
3964 	      OR p_x_header_rec.attribute19 = FND_API.G_MISS_CHAR THEN
3965 	       p_x_header_rec.attribute19 := oe_validate.g_attribute19;
3966 	    END IF;
3967 
3968 	    IF p_x_header_rec.attribute20 IS NULL
3969 	      OR p_x_header_rec.attribute20 = FND_API.G_MISS_CHAR THEN
3970 	       p_x_header_rec.attribute20 := oe_validate.g_attribute20;
3971 	    END IF;
3972 
3973 	    -- end of assignments, bug 2511313
3974 	 END IF;
3975 	END IF ; -- If flex enabled
3976     END IF;
3977 
3978     oe_debug_pub.add('After header_desc_flex  ' || x_return_status,2);
3979 	IF p_x_header_rec.operation = oe_globals.g_opr_create OR
3980     ( p_x_header_rec.operation = oe_globals.g_opr_update AND
3981       (p_x_header_rec.global_attribute1 IS NOT NULL AND
3982         (   p_x_header_rec.global_attribute1 <>
3983             p_old_header_rec.global_attribute1 OR
3984             p_old_header_rec.global_attribute1 IS NULL ))
3985     OR  (p_x_header_rec.global_attribute10 IS NOT NULL AND
3986         (   p_x_header_rec.global_attribute10 <>
3987             p_old_header_rec.global_attribute10 OR
3988             p_old_header_rec.global_attribute10 IS NULL ))
3989     OR  (p_x_header_rec.global_attribute11 IS NOT NULL AND
3990         (   p_x_header_rec.global_attribute11 <>
3991             p_old_header_rec.global_attribute11 OR
3992             p_old_header_rec.global_attribute11 IS NULL ))
3993     OR  (p_x_header_rec.global_attribute12 IS NOT NULL AND
3994         (   p_x_header_rec.global_attribute12 <>
3995             p_old_header_rec.global_attribute12 OR
3996             p_old_header_rec.global_attribute12 IS NULL ))
3997     OR  (p_x_header_rec.global_attribute13 IS NOT NULL AND
3998         (   p_x_header_rec.global_attribute13 <>
3999             p_old_header_rec.global_attribute13 OR
4000             p_old_header_rec.global_attribute13 IS NULL ))
4001     OR  (p_x_header_rec.global_attribute14 IS NOT NULL AND
4002         (   p_x_header_rec.global_attribute14 <>
4003             p_old_header_rec.global_attribute14 OR
4004             p_old_header_rec.global_attribute14 IS NULL ))
4005     OR  (p_x_header_rec.global_attribute15 IS NOT NULL AND
4006         (   p_x_header_rec.global_attribute15 <>
4007             p_old_header_rec.global_attribute15 OR
4008             p_old_header_rec.global_attribute15 IS NULL ))
4009     OR  (p_x_header_rec.global_attribute16 IS NOT NULL AND
4010         (   p_x_header_rec.global_attribute16 <>
4011             p_old_header_rec.global_attribute16 OR
4012             p_old_header_rec.global_attribute16 IS NULL ))
4013     OR  (p_x_header_rec.global_attribute17 IS NOT NULL AND
4014         (   p_x_header_rec.global_attribute17 <>
4015             p_old_header_rec.global_attribute17 OR
4016             p_old_header_rec.global_attribute17 IS NULL ))
4017     OR  (p_x_header_rec.global_attribute18 IS NOT NULL AND
4018         (   p_x_header_rec.global_attribute18 <>
4019             p_old_header_rec.global_attribute18 OR
4020             p_old_header_rec.global_attribute18 IS NULL ))
4021     OR  (p_x_header_rec.global_attribute19 IS NOT NULL AND
4022         (   p_x_header_rec.global_attribute19 <>
4023             p_old_header_rec.global_attribute19 OR
4024             p_old_header_rec.global_attribute19 IS NULL ))
4025     OR  (p_x_header_rec.global_attribute2 IS NOT NULL AND
4026         (   p_x_header_rec.global_attribute2 <>
4027             p_old_header_rec.global_attribute2 OR
4028             p_old_header_rec.global_attribute2 IS NULL ))
4029     OR  (p_x_header_rec.global_attribute20 IS NOT NULL AND
4030         (   p_x_header_rec.global_attribute20 <>
4031             p_old_header_rec.global_attribute20 OR
4032             p_old_header_rec.global_attribute20 IS NULL ))
4033     OR  (p_x_header_rec.global_attribute3 IS NOT NULL AND
4034         (   p_x_header_rec.global_attribute3 <>
4035             p_old_header_rec.global_attribute3 OR
4036             p_old_header_rec.global_attribute3 IS NULL ))
4037     OR  (p_x_header_rec.global_attribute4 IS NOT NULL AND
4038         (   p_x_header_rec.global_attribute4 <>
4039             p_old_header_rec.global_attribute4 OR
4040             p_old_header_rec.global_attribute4 IS NULL ))
4041     OR  (p_x_header_rec.global_attribute5 IS NOT NULL AND
4042         (   p_x_header_rec.global_attribute5 <>
4043             p_old_header_rec.global_attribute5 OR
4044             p_old_header_rec.global_attribute5 IS NULL ))
4045     OR  (p_x_header_rec.global_attribute6 IS NOT NULL AND
4046         (   p_x_header_rec.global_attribute6 <>
4047             p_old_header_rec.global_attribute6 OR
4048             p_old_header_rec.global_attribute6 IS NULL ))
4049     OR  (p_x_header_rec.global_attribute7 IS NOT NULL AND
4050         (   p_x_header_rec.global_attribute7 <>
4051             p_old_header_rec.global_attribute7 OR
4052             p_old_header_rec.global_attribute7 IS NULL ))
4053     OR  (p_x_header_rec.global_attribute8 IS NOT NULL AND
4054         (   p_x_header_rec.global_attribute8 <>
4055             p_old_header_rec.global_attribute8 OR
4056             p_old_header_rec.global_attribute8 IS NULL ))
4057     OR  (p_x_header_rec.global_attribute9 IS NOT NULL AND
4058         (   p_x_header_rec.global_attribute9 <>
4059             p_old_header_rec.global_attribute9 OR
4060             p_old_header_rec.global_attribute9 IS NULL ))
4061     OR  (p_x_header_rec.global_attribute_category IS NOT NULL AND
4062         (   p_x_header_rec.global_attribute_category <>
4063             p_old_header_rec.global_attribute_category OR
4064             p_old_header_rec.global_attribute_category IS NULL )))
4065     THEN
4066 
4067 
4068 
4069           OE_DEBUG_PUB.ADD('Before G_header_desc_flex',2);
4070           /*  Fixing 2375476 to skip the Flex field validation in case of
4071              Internal Orders. This condition will be removed once process Order
4072              starts defaulting the FF */
4073     IF OE_ORDER_CACHE.IS_FLEX_ENABLED('OE_HEADER_GLOBAL_ATTRIBUTE') = 'Y' THEN
4074 --    AND p_x_header_rec.order_source_id <> 10 THEN
4075           IF NOT OE_VALIDATE.G_Header_Desc_Flex
4076           (p_context            => p_x_header_rec.global_attribute_category
4077           ,p_attribute1         => p_x_header_rec.global_attribute1
4078           ,p_attribute2         => p_x_header_rec.global_attribute2
4079           ,p_attribute3         => p_x_header_rec.global_attribute3
4080           ,p_attribute4         => p_x_header_rec.global_attribute4
4081           ,p_attribute5         => p_x_header_rec.global_attribute5
4082           ,p_attribute6         => p_x_header_rec.global_attribute6
4083           ,p_attribute7         => p_x_header_rec.global_attribute7
4084           ,p_attribute8         => p_x_header_rec.global_attribute8
4085           ,p_attribute9         => p_x_header_rec.global_attribute9
4086           ,p_attribute10        => p_x_header_rec.global_attribute10
4087           ,p_attribute11        => p_x_header_rec.global_attribute11
4088           ,p_attribute12        => p_x_header_rec.global_attribute12
4089           ,p_attribute13        => p_x_header_rec.global_attribute13
4090           ,p_attribute14        => p_x_header_rec.global_attribute13
4091           ,p_attribute15        => p_x_header_rec.global_attribute14
4092           ,p_attribute16        => p_x_header_rec.global_attribute16
4093           ,p_attribute17        => p_x_header_rec.global_attribute17
4094           ,p_attribute18        => p_x_header_rec.global_attribute18
4095           ,p_attribute19        => p_x_header_rec.global_attribute19
4096           ,p_attribute20        => p_x_header_rec.global_attribute20)
4097           THEN
4098 
4099             IF p_validation_level = OE_GLOBALS.G_VALID_LEVEL_PARTIAL AND
4100                p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
4101             THEN
4102 
4103                 p_x_header_rec.global_attribute_category    := null;
4104                 p_x_header_rec.global_attribute1 := null;
4105                 p_x_header_rec.global_attribute2 := null;
4106                 p_x_header_rec.global_attribute3 := null;
4107                 p_x_header_rec.global_attribute4 := null;
4108                 p_x_header_rec.global_attribute5 := null;
4109                 p_x_header_rec.global_attribute6 := null;
4110                 p_x_header_rec.global_attribute7 := null;
4111                 p_x_header_rec.global_attribute8 := null;
4112                 p_x_header_rec.global_attribute9 := null;
4113                 p_x_header_rec.global_attribute11 := null;
4114                 p_x_header_rec.global_attribute12 := null;
4115                 p_x_header_rec.global_attribute13 := null;
4116                 p_x_header_rec.global_attribute14 := null;
4117                 p_x_header_rec.global_attribute15 := null;
4118                 p_x_header_rec.global_attribute16 := null;
4119                 p_x_header_rec.global_attribute17 := null;
4120                 p_x_header_rec.global_attribute18 := null;
4121                 p_x_header_rec.global_attribute19 := null;
4122                 p_x_header_rec.global_attribute20 := null;
4123 
4124             ELSIF p_validation_level = OE_GLOBALS.G_VALID_PARTIAL_WITH_DEF AND
4125                   p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
4126             THEN
4127 
4128                 p_x_header_rec.global_attribute_category
4129                                                := FND_API.G_MISS_CHAR;
4130                 p_x_header_rec.global_attribute1 := FND_API.G_MISS_CHAR;
4131                 p_x_header_rec.global_attribute2 := FND_API.G_MISS_CHAR;
4132                 p_x_header_rec.global_attribute3 := FND_API.G_MISS_CHAR;
4133                 p_x_header_rec.global_attribute4 := FND_API.G_MISS_CHAR;
4134                 p_x_header_rec.global_attribute5 := FND_API.G_MISS_CHAR;
4135                 p_x_header_rec.global_attribute6 := FND_API.G_MISS_CHAR;
4136                 p_x_header_rec.global_attribute7 := FND_API.G_MISS_CHAR;
4137                 p_x_header_rec.global_attribute8 := FND_API.G_MISS_CHAR;
4138                 p_x_header_rec.global_attribute9 := FND_API.G_MISS_CHAR;
4139                 p_x_header_rec.global_attribute11 := FND_API.G_MISS_CHAR;
4140                 p_x_header_rec.global_attribute12 := FND_API.G_MISS_CHAR;
4141                 p_x_header_rec.global_attribute13 := FND_API.G_MISS_CHAR;
4142                 p_x_header_rec.global_attribute14 := FND_API.G_MISS_CHAR;
4143                 p_x_header_rec.global_attribute15 := FND_API.G_MISS_CHAR;
4144                 p_x_header_rec.global_attribute16 := FND_API.G_MISS_CHAR;
4145                 p_x_header_rec.global_attribute17 := FND_API.G_MISS_CHAR;
4146                 p_x_header_rec.global_attribute18 := FND_API.G_MISS_CHAR;
4147                 p_x_header_rec.global_attribute19 := FND_API.G_MISS_CHAR;
4148                 p_x_header_rec.global_attribute20 := FND_API.G_MISS_CHAR;
4149 
4150             ELSE
4151                 x_return_status := FND_API.G_RET_STS_ERROR;
4152             END IF;
4153 	   ELSE -- for bug 2511313
4154 	        IF p_x_header_rec.global_attribute_category IS NULL
4155 		  OR p_x_header_rec.global_attribute_category = FND_API.G_MISS_CHAR THEN
4156 		   p_x_header_rec.global_attribute_category := oe_validate.g_context;
4157 		END IF;
4158 
4159 		IF p_x_header_rec.global_attribute1 IS NULL
4160 		  OR p_x_header_rec.global_attribute1 = FND_API.G_MISS_CHAR THEN
4161 		   p_x_header_rec.global_attribute1 := oe_validate.g_attribute1;
4162 		END IF;
4163 
4164 		IF p_x_header_rec.global_attribute2 IS NULL
4165 		  OR p_x_header_rec.global_attribute2 = FND_API.G_MISS_CHAR THEN
4166 		   p_x_header_rec.global_attribute2 := oe_validate.g_attribute2;
4167 		END IF;
4168 
4169 		IF p_x_header_rec.global_attribute3 IS NULL
4170 		  OR p_x_header_rec.global_attribute3 = FND_API.G_MISS_CHAR THEN
4171 		   p_x_header_rec.global_attribute3 := oe_validate.g_attribute3;
4172 		END IF;
4173 
4174 		IF p_x_header_rec.global_attribute4 IS NULL
4175 		  OR p_x_header_rec.global_attribute4 = FND_API.G_MISS_CHAR THEN
4176 		   p_x_header_rec.global_attribute4 := oe_validate.g_attribute4;
4177 		END IF;
4178 
4179 		IF p_x_header_rec.global_attribute5 IS NULL
4180 		  OR p_x_header_rec.global_attribute5 = FND_API.G_MISS_CHAR THEN
4181 		   p_x_header_rec.global_attribute5 := oe_validate.g_attribute5;
4182 		END IF;
4183 
4184 		IF p_x_header_rec.global_attribute6 IS NULL
4185 		  OR p_x_header_rec.global_attribute6 = FND_API.G_MISS_CHAR THEN
4186 		   p_x_header_rec.global_attribute6 := oe_validate.g_attribute6;
4187 		END IF;
4188 
4189 		IF p_x_header_rec.global_attribute7 IS NULL
4190 		  OR p_x_header_rec.global_attribute7 = FND_API.G_MISS_CHAR THEN
4191 		   p_x_header_rec.global_attribute7 := oe_validate.g_attribute7;
4192 		END IF;
4193 
4194 		IF p_x_header_rec.global_attribute8 IS NULL
4195 		  OR p_x_header_rec.global_attribute8 = FND_API.G_MISS_CHAR THEN
4196 		   p_x_header_rec.global_attribute8 := oe_validate.g_attribute8;
4197 		END IF;
4198 
4199 		IF p_x_header_rec.global_attribute9 IS NULL
4200 		  OR p_x_header_rec.global_attribute9 = FND_API.G_MISS_CHAR THEN
4201 		   p_x_header_rec.global_attribute9 := oe_validate.g_attribute9;
4202 		END IF;
4203 
4204 		IF p_x_header_rec.global_attribute11 IS NULL
4205 		  OR p_x_header_rec.global_attribute11 = FND_API.G_MISS_CHAR THEN
4206 		   p_x_header_rec.global_attribute11 := oe_validate.g_attribute11;
4207 		END IF;
4208 
4209 		IF p_x_header_rec.global_attribute12 IS NULL
4210 		  OR p_x_header_rec.global_attribute12 = FND_API.G_MISS_CHAR THEN
4211 		   p_x_header_rec.global_attribute12 := oe_validate.g_attribute12;
4212 		END IF;
4213 
4214 		IF p_x_header_rec.global_attribute13 IS NULL
4215 		  OR p_x_header_rec.global_attribute13 = FND_API.G_MISS_CHAR THEN
4216 		   p_x_header_rec.global_attribute13 := oe_validate.g_attribute13;
4217 		END IF;
4218 
4219 		IF p_x_header_rec.global_attribute14 IS NULL
4220 		  OR p_x_header_rec.global_attribute14 = FND_API.G_MISS_CHAR THEN
4221 		   p_x_header_rec.global_attribute14 := oe_validate.g_attribute14;
4222 		END IF;
4223 
4224 		IF p_x_header_rec.global_attribute15 IS NULL
4225 		  OR p_x_header_rec.global_attribute15 = FND_API.G_MISS_CHAR THEN
4226 		   p_x_header_rec.global_attribute15 := oe_validate.g_attribute15;
4227 		END IF;
4228 
4229 		IF p_x_header_rec.global_attribute16 IS NULL
4230 		  OR p_x_header_rec.global_attribute16 = FND_API.G_MISS_CHAR THEN
4231 		   p_x_header_rec.global_attribute16 := oe_validate.g_attribute16;
4232 		END IF;
4233 
4234 		IF p_x_header_rec.global_attribute17 IS NULL
4235 		  OR p_x_header_rec.global_attribute17 = FND_API.G_MISS_CHAR THEN
4236 		   p_x_header_rec.global_attribute17 := oe_validate.g_attribute17;
4237 		END IF;
4238 
4239 		IF p_x_header_rec.global_attribute18 IS NULL
4240 		  OR p_x_header_rec.global_attribute18 = FND_API.G_MISS_CHAR THEN
4241 		   p_x_header_rec.global_attribute18 := oe_validate.g_attribute18;
4242 		END IF;
4243 
4244 		IF p_x_header_rec.global_attribute19 IS NULL
4245 		  OR p_x_header_rec.global_attribute19 = FND_API.G_MISS_CHAR THEN
4246 		   p_x_header_rec.global_attribute19 := oe_validate.g_attribute19;
4247 		END IF;
4248 
4249 		IF p_x_header_rec.global_attribute20 IS NULL
4250 		  OR p_x_header_rec.global_attribute20 = FND_API.G_MISS_CHAR THEN
4251 		   p_x_header_rec.global_attribute20 := oe_validate.g_attribute20;
4252 		END IF;
4253 
4254 		IF p_x_header_rec.global_attribute10 IS NULL
4255 		  OR p_x_header_rec.global_attribute10 = FND_API.G_MISS_CHAR THEN
4256 		   p_x_header_rec.global_attribute10 := oe_validate.g_attribute10;
4257 		END IF;
4258 		-- end of bug 2511313
4259          END IF;
4260 	END IF; -- Enabled
4261    END IF;
4262 
4263    OE_DEBUG_PUB.ADD('After G_header_desc_flex ' || x_return_status,2);
4264 
4265    -- Added the Trading Partner Flex Validation and also the changes for defaulting
4266    -- for bug 2511313
4267 
4268    IF  p_x_header_rec.operation = oe_globals.g_opr_create OR
4269      (  p_x_header_rec.operation = oe_globals.g_opr_update  AND
4270 	(p_x_header_rec.tp_attribute1 IS NOT NULL AND
4271 	 (   p_x_header_rec.tp_attribute1 <>
4272 	     p_old_header_rec.tp_attribute1 OR
4273 	     p_old_header_rec.tp_attribute1 IS NULL ))
4274     OR  (p_x_header_rec.tp_attribute2 IS NOT NULL AND
4275         (   p_x_header_rec.tp_attribute2 <>
4276             p_old_header_rec.tp_attribute2 OR
4277             p_old_header_rec.tp_attribute2 IS NULL ))
4278     OR  (p_x_header_rec.tp_attribute3 IS NOT NULL AND
4279         (   p_x_header_rec.tp_attribute3 <>
4280             p_old_header_rec.tp_attribute3 OR
4281             p_old_header_rec.tp_attribute3 IS NULL ))
4282     OR  (p_x_header_rec.tp_attribute4 IS NOT NULL AND
4283         (   p_x_header_rec.tp_attribute4 <>
4284             p_old_header_rec.tp_attribute4 OR
4285             p_old_header_rec.tp_attribute4 IS NULL ))
4286     OR  (p_x_header_rec.tp_attribute5 IS NOT NULL AND
4287         (   p_x_header_rec.tp_attribute5 <>
4288             p_old_header_rec.tp_attribute5 OR
4289             p_old_header_rec.tp_attribute5 IS NULL ))
4290     OR  (p_x_header_rec.tp_attribute6 IS NOT NULL AND
4291         (   p_x_header_rec.tp_attribute6 <>
4292             p_old_header_rec.tp_attribute6 OR
4293             p_old_header_rec.tp_attribute6 IS NULL ))
4294     OR  (p_x_header_rec.tp_attribute7 IS NOT NULL AND
4295         (   p_x_header_rec.tp_attribute7 <>
4296             p_old_header_rec.tp_attribute7 OR
4297             p_old_header_rec.tp_attribute7 IS NULL ))
4298     OR  (p_x_header_rec.tp_attribute8 IS NOT NULL AND
4299         (   p_x_header_rec.tp_attribute8 <>
4300             p_old_header_rec.tp_attribute8 OR
4301             p_old_header_rec.tp_attribute8 IS NULL ))
4302     OR  (p_x_header_rec.tp_attribute9 IS NOT NULL AND
4303         (   p_x_header_rec.tp_attribute9 <>
4304             p_old_header_rec.tp_attribute9 OR
4305             p_old_header_rec.tp_attribute9 IS NULL ))
4306     OR  (p_x_header_rec.tp_attribute10 IS NOT NULL AND
4307         (   p_x_header_rec.tp_attribute10 <>
4308             p_old_header_rec.tp_attribute10 OR
4309             p_old_header_rec.tp_attribute10 IS NULL ))
4310     OR  (p_x_header_rec.tp_attribute11 IS NOT NULL AND
4311         (   p_x_header_rec.tp_attribute11 <>
4312             p_old_header_rec.tp_attribute11 OR
4313             p_old_header_rec.tp_attribute11 IS NULL ))
4314     OR  (p_x_header_rec.tp_attribute12 IS NOT NULL AND
4315         (   p_x_header_rec.tp_attribute12 <>
4316             p_old_header_rec.tp_attribute12 OR
4317             p_old_header_rec.tp_attribute12 IS NULL ))
4318     OR  (p_x_header_rec.tp_attribute13 IS NOT NULL AND
4319         (   p_x_header_rec.tp_attribute13 <>
4320             p_old_header_rec.tp_attribute13 OR
4321             p_old_header_rec.tp_attribute13 IS NULL ))
4322     OR  (p_x_header_rec.tp_attribute14 IS NOT NULL AND
4323         (   p_x_header_rec.tp_attribute14 <>
4324             p_old_header_rec.tp_attribute14 OR
4325             p_old_header_rec.tp_attribute14 IS NULL ))
4326     OR  (p_x_header_rec.tp_attribute15 IS NOT NULL AND
4327         (   p_x_header_rec.tp_attribute15 <>
4328             p_old_header_rec.tp_attribute15 OR
4329             p_old_header_rec.tp_attribute15 IS NULL )))
4330 
4331     THEN
4332 
4333        IF Oe_Order_Cache.IS_FLEX_ENABLED('OE_HEADER_TP_ATTRIBUTES') = 'Y' THEN
4334          IF NOT OE_VALIDATE.TP_Header_Desc_Flex
4335           (p_context            => p_x_header_rec.tp_context
4336           ,p_attribute1         => p_x_header_rec.tp_attribute1
4337           ,p_attribute2         => p_x_header_rec.tp_attribute2
4338           ,p_attribute3         => p_x_header_rec.tp_attribute3
4339           ,p_attribute4         => p_x_header_rec.tp_attribute4
4340           ,p_attribute5         => p_x_header_rec.tp_attribute5
4341           ,p_attribute6         => p_x_header_rec.tp_attribute6
4342           ,p_attribute7         => p_x_header_rec.tp_attribute7
4343           ,p_attribute8         => p_x_header_rec.tp_attribute8
4344           ,p_attribute9         => p_x_header_rec.tp_attribute9
4345           ,p_attribute10        => p_x_header_rec.tp_attribute10
4346           ,p_attribute11        => p_x_header_rec.tp_attribute11
4347           ,p_attribute12        => p_x_header_rec.tp_attribute12
4348           ,p_attribute13        => p_x_header_rec.tp_attribute13
4349           ,p_attribute14        => p_x_header_rec.tp_attribute14
4350           ,p_attribute15        => p_x_header_rec.tp_attribute15) THEN
4351 
4352           IF p_validation_level = OE_GLOBALS.G_VALID_LEVEL_PARTIAL AND
4353              p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE   THEN
4354 
4355 
4356                 p_x_header_rec.tp_context    := null;
4357                 p_x_header_rec.tp_attribute1 := null;
4358                 p_x_header_rec.tp_attribute2 := null;
4359                 p_x_header_rec.tp_attribute3 := null;
4360                 p_x_header_rec.tp_attribute4 := null;
4361                 p_x_header_rec.tp_attribute5 := null;
4362                 p_x_header_rec.tp_attribute6 := null;
4363                 p_x_header_rec.tp_attribute7 := null;
4364                 p_x_header_rec.tp_attribute8 := null;
4365                 p_x_header_rec.tp_attribute9 := null;
4366                 p_x_header_rec.tp_attribute10 := null;
4367                 p_x_header_rec.tp_attribute11 := null;
4368                 p_x_header_rec.tp_attribute12 := null;
4369                 p_x_header_rec.tp_attribute13 := null;
4370                 p_x_header_rec.tp_attribute14 := null;
4371                 p_x_header_rec.tp_attribute15 := null;
4372 
4373         ELSIF p_validation_level = OE_GLOBALS.G_VALID_PARTIAL_WITH_DEF AND
4374            p_x_header_rec.operation =OE_GLOBALS.G_OPR_CREATE THEN
4375 
4376                 p_x_header_rec.tp_context    := FND_API.G_MISS_CHAR;
4377                 p_x_header_rec.tp_attribute1 := FND_API.G_MISS_CHAR;
4378                 p_x_header_rec.tp_attribute2 := FND_API.G_MISS_CHAR;
4379                 p_x_header_rec.tp_attribute3 := FND_API.G_MISS_CHAR;
4380                 p_x_header_rec.tp_attribute4 := FND_API.G_MISS_CHAR;
4381                 p_x_header_rec.tp_attribute5 := FND_API.G_MISS_CHAR;
4382                 p_x_header_rec.tp_attribute6 := FND_API.G_MISS_CHAR;
4383                 p_x_header_rec.tp_attribute7 := FND_API.G_MISS_CHAR;
4384                 p_x_header_rec.tp_attribute8 := FND_API.G_MISS_CHAR;
4385                 p_x_header_rec.tp_attribute9 := FND_API.G_MISS_CHAR;
4386                 p_x_header_rec.tp_attribute10 := FND_API.G_MISS_CHAR;
4387                 p_x_header_rec.tp_attribute11 := FND_API.G_MISS_CHAR;
4388                 p_x_header_rec.tp_attribute12 := FND_API.G_MISS_CHAR;
4389                 p_x_header_rec.tp_attribute13 := FND_API.G_MISS_CHAR;
4390                 p_x_header_rec.tp_attribute14 := FND_API.G_MISS_CHAR;
4391                 p_x_header_rec.tp_attribute15 := FND_API.G_MISS_CHAR;
4392 	   ELSE
4393 	     x_return_status := FND_API.G_RET_STS_ERROR;
4394           END IF;
4395 
4396 	  ELSE
4397 
4398 	    IF p_x_header_rec.tp_context IS NULL
4399 	      OR p_x_header_rec.tp_context = FND_API.G_MISS_CHAR THEN
4400 	       p_x_header_rec.tp_context    := oe_validate.g_context;
4401 	    END IF;
4402 
4403 	    IF p_x_header_rec.tp_attribute1 IS NULL
4404 	      OR p_x_header_rec.tp_attribute1 = FND_API.G_MISS_CHAR THEN
4405 	       p_x_header_rec.tp_attribute1 := oe_validate.g_attribute1;
4406 	    END IF;
4407 
4408 	    IF p_x_header_rec.tp_attribute2 IS NULL
4409 	      OR p_x_header_rec.tp_attribute2 = FND_API.G_MISS_CHAR THEN
4410 	       p_x_header_rec.tp_attribute2 := oe_validate.g_attribute2;
4411 	    END IF;
4412 
4413 	    IF p_x_header_rec.tp_attribute3 IS NULL
4414 	      OR p_x_header_rec.tp_attribute3 = FND_API.G_MISS_CHAR THEN
4415 	       p_x_header_rec.tp_attribute3 := oe_validate.g_attribute3;
4416 	    END IF;
4417 
4418 	    IF p_x_header_rec.tp_attribute4 IS NULL
4419 	      OR p_x_header_rec.tp_attribute4 = FND_API.G_MISS_CHAR THEN
4420 	       p_x_header_rec.tp_attribute4 := oe_validate.g_attribute4;
4421 	    END IF;
4422 
4423 	    IF p_x_header_rec.tp_attribute5 IS NULL
4424 	      OR p_x_header_rec.tp_attribute5 = FND_API.G_MISS_CHAR THEN
4425 	       p_x_header_rec.tp_attribute5 := oe_validate.g_attribute5;
4426 	    END IF;
4427 
4428 	    IF p_x_header_rec.tp_attribute6 IS NULL
4429 	      OR p_x_header_rec.tp_attribute6 = FND_API.G_MISS_CHAR THEN
4430 	       p_x_header_rec.tp_attribute6 := oe_validate.g_attribute6;
4431 	    END IF;
4432 
4433 	    IF p_x_header_rec.tp_attribute7 IS NULL
4434 	      OR p_x_header_rec.tp_attribute7 = FND_API.G_MISS_CHAR THEN
4435 	       p_x_header_rec.tp_attribute7 := oe_validate.g_attribute7;
4436 	    END IF;
4437 
4438 	    IF p_x_header_rec.tp_attribute8 IS NULL
4439 	      OR p_x_header_rec.tp_attribute8 = FND_API.G_MISS_CHAR THEN
4440 	       p_x_header_rec.tp_attribute8 := oe_validate.g_attribute8;
4441 	    END IF;
4442 
4443 	    IF p_x_header_rec.tp_attribute9 IS NULL
4444 	      OR p_x_header_rec.tp_attribute9 = FND_API.G_MISS_CHAR THEN
4445 	       p_x_header_rec.tp_attribute9 := oe_validate.g_attribute9;
4446 	    END IF;
4447 
4448 	    IF p_x_header_rec.tp_attribute10 IS NULL
4449 	      OR p_x_header_rec.tp_attribute10 = FND_API.G_MISS_CHAR THEN
4450 	       p_x_header_rec.tp_attribute10 := Oe_validate.G_attribute10;
4451 	    End IF;
4452 
4453 	    IF p_x_header_rec.tp_attribute11 IS NULL
4454 	      OR p_x_header_rec.tp_attribute11 = FND_API.G_MISS_CHAR THEN
4455 	       p_x_header_rec.tp_attribute11 := oe_validate.g_attribute11;
4456 	    END IF;
4457 
4458 	    IF p_x_header_rec.tp_attribute12 IS NULL
4459 	      OR p_x_header_rec.tp_attribute12 = FND_API.G_MISS_CHAR THEN
4460 	       p_x_header_rec.tp_attribute12 := oe_validate.g_attribute12;
4461 	    END IF;
4462 
4463 	    IF p_x_header_rec.tp_attribute13 IS NULL
4464 	      OR p_x_header_rec.tp_attribute13 = FND_API.G_MISS_CHAR THEN
4465 	       p_x_header_rec.tp_attribute13 := oe_validate.g_attribute13;
4466 	    END IF;
4467 
4468 	    IF p_x_header_rec.tp_attribute14 IS NULL
4469 	      OR p_x_header_rec.tp_attribute14 = FND_API.G_MISS_CHAR THEN
4470 	       p_x_header_rec.tp_attribute14 := oe_validate.g_attribute14;
4471 	    END IF;
4472 
4473 	    IF p_x_header_rec.tp_attribute15 IS NULL
4474 	      OR p_x_header_rec.tp_attribute15 = FND_API.G_MISS_CHAR THEN
4475 	       p_x_header_rec.tp_attribute15 := oe_validate.g_attribute15;
4476 	    END IF;
4477 
4478          END IF;
4479 	END IF; -- Is flex enabled
4480 
4481          --oe_debug_pub.add('After TP_header_desc_flex  ' || x_return_status);
4482 
4483     END IF;
4484     /* Trading Partner */
4485    end if; --for bug4343612
4486     --  Done validating attributes
4487 
4488     -- Salesrep_id
4489     IF  p_x_header_rec.salesrep_id IS NOT NULL AND
4490         (  (p_x_header_rec.salesrep_id <>
4491             p_old_header_rec.salesrep_id OR
4492             p_old_header_rec.salesrep_id IS NULL ) OR
4493            (p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE ) )
4494         --bug 5060064
4495     THEN
4496 
4497       IF NOT OE_Validate.salesrep(p_x_header_rec.salesrep_id)
4498       THEN
4499         IF p_validation_level = OE_GLOBALS.G_VALID_LEVEL_PARTIAL AND
4500            p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
4501         THEN
4502            p_x_header_rec.salesrep_id := NULL;
4503         ELSIF p_validation_level = OE_GLOBALS.G_VALID_PARTIAL_WITH_DEF AND
4504               p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
4505         THEN
4506           p_x_header_rec.salesrep_id := FND_API.G_MISS_NUM;
4507         ELSE
4508           x_return_status := FND_API.G_RET_STS_ERROR;
4509         END IF;
4510       END IF;
4511 
4512     END IF;
4513 
4514     oe_debug_pub.add('after salesrep_id');
4515 
4516     IF  p_x_header_rec.sales_channel_code IS NOT NULL AND
4517         (  (p_x_header_rec.sales_channel_code <>
4518             p_old_header_rec.sales_channel_code OR
4519             p_old_header_rec.sales_channel_code IS NULL ) OR
4520            (p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE ) )
4521         --bug 5060064
4522     THEN
4523 
4524       IF NOT OE_Validate.sales_channel(p_x_header_rec.sales_channel_code)
4525       THEN
4526         IF p_validation_level = OE_GLOBALS.G_VALID_LEVEL_PARTIAL AND
4527            p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
4528         THEN
4529            p_x_header_rec.sales_channel_code := NULL;
4530         ELSIF p_validation_level = OE_GLOBALS.G_VALID_PARTIAL_WITH_DEF AND
4531               p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
4532         THEN
4533           p_x_header_rec.sales_channel_code := FND_API.G_MISS_CHAR;
4534         ELSE
4535           x_return_status := FND_API.G_RET_STS_ERROR;
4536         END IF;
4537       END IF;
4538 
4539     END IF;
4540 
4541     -- Return_reason_code
4542 
4543     IF  p_x_header_rec.return_reason_code IS NOT NULL AND
4544         (  (p_x_header_rec.return_reason_code <>
4545             p_old_header_rec.return_reason_code OR
4546             p_old_header_rec.return_reason_code IS NULL ) OR
4547            (p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE ) )
4548         --bug 5060064
4549     THEN
4550 
4551       IF NOT OE_Validate.return_reason(p_x_header_rec.return_reason_code) THEN
4552         IF p_validation_level = OE_GLOBALS.G_VALID_LEVEL_PARTIAL AND
4553            p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
4554         THEN
4555           p_x_header_rec.return_reason_code := NULL;
4556         ELSIF p_validation_level = OE_GLOBALS.G_VALID_PARTIAL_WITH_DEF AND
4557               p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
4558         THEN
4559           p_x_header_rec.return_reason_code := FND_API.G_MISS_CHAR;
4560         ELSE
4561           x_return_status := FND_API.G_RET_STS_ERROR;
4562         END IF;
4563       END IF;
4564 
4565     END IF;
4566 
4567     -- Changes for Line Set Enhancements
4568 
4569      IF  p_x_header_rec.Default_fulfillment_set IS NOT NULL AND
4570          ( (p_x_header_rec.default_fulfillment_set <>
4571             p_old_header_rec.default_fulfillment_set OR
4572             p_old_header_rec.default_fulfillment_set IS NULL ) OR
4573            (p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE ) )
4574         --bug 5060064
4575       THEN
4576 
4577        IF NOT OE_Validate.Default_fulfillment_set(p_x_header_rec.default_fulfillment_set)
4578        THEN
4579           IF p_validation_level = OE_GLOBALS.G_VALID_LEVEL_PARTIAL AND
4580              p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
4581           THEN
4582              p_x_header_rec.default_fulfillment_set := NULL;
4583           ELSIF p_validation_level = OE_GLOBALS.G_VALID_PARTIAL_WITH_DEF AND
4584              p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
4585           THEN
4586              p_x_header_rec.default_fulfillment_set := FND_API.G_MISS_CHAR;
4587           ELSE
4588              x_return_status := FND_API.G_RET_STS_ERROR;
4589           END IF;
4590 
4591       END IF;
4592 
4593     END IF;
4594 
4595     IF  p_x_header_rec.fulfillment_set_name IS NOT NULL AND
4596         (  (p_x_header_rec.fulfillment_set_name <>
4597             p_old_header_rec.fulfillment_set_name OR
4598             p_old_header_rec.fulfillment_set_name IS NULL ) OR
4599            (p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE ) )
4600         --bug 5060064
4601     THEN
4602 
4603        IF NOT OE_Validate.Fulfillment_Set_name (p_x_header_rec.fulfillment_set_name)
4604        THEN
4605           IF p_validation_level = OE_GLOBALS.G_VALID_LEVEL_PARTIAL AND
4606              p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
4607           THEN
4608              p_x_header_rec.fulfillment_set_name := NULL;
4609           ELSIF p_validation_level = OE_GLOBALS.G_VALID_PARTIAL_WITH_DEF AND
4610              p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
4611           THEN
4612              p_x_header_rec.fulfillment_set_name := FND_API.G_MISS_CHAR;
4613           ELSE
4614           x_return_status := FND_API.G_RET_STS_ERROR;
4615         END IF;
4616 
4617       END IF;
4618 
4619     END IF;
4620 
4621     IF  p_x_header_rec.Line_set_name IS NOT NULL AND
4622         (  (p_x_header_rec.Line_set_name  <>
4623             p_old_header_rec.Line_set_name OR
4624             p_old_header_rec.Line_set_name IS NULL ) OR
4625            (p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE ) )
4626         --bug 5060064
4627     THEN
4628 
4629         IF NOT OE_Validate.Line_set_name (p_x_header_rec.line_set_name)
4630         THEN
4631            IF p_validation_level = OE_GLOBALS.G_VALID_LEVEL_PARTIAL AND
4632               p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
4633            THEN
4634               p_x_header_rec.line_set_name := NULL;
4635            ELSIF p_validation_level = OE_GLOBALS.G_VALID_PARTIAL_WITH_DEF AND
4636               p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
4637            THEN
4638               p_x_header_rec.line_set_name := FND_API.G_MISS_CHAR;
4639            ELSE
4640               x_return_status := FND_API.G_RET_STS_ERROR;
4641            END IF;
4642 
4643         END IF;
4644 
4645      END IF;
4646 
4647 
4648     -- QUOTING changes
4649 
4650     IF  p_x_header_rec.user_status_code IS NOT NULL AND
4651         (  (p_x_header_rec.user_status_code  <>
4652             p_old_header_rec.user_status_code OR
4653             p_old_header_rec.user_status_code IS NULL ) OR
4654            (p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE ) )
4655         --bug 5060064
4656     THEN
4657 
4658         IF NOT OE_Validate.User_Status (p_x_header_rec.user_status_code)
4659         THEN
4660            IF p_validation_level = OE_GLOBALS.G_VALID_LEVEL_PARTIAL AND
4661               p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
4662            THEN
4663               p_x_header_rec.user_status_code := NULL;
4664            ELSIF p_validation_level = OE_GLOBALS.G_VALID_PARTIAL_WITH_DEF AND
4665               p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
4666            THEN
4667               p_x_header_rec.user_status_code := FND_API.G_MISS_CHAR;
4668            ELSE
4669               x_return_status := FND_API.G_RET_STS_ERROR;
4670            END IF;
4671 
4672         END IF;
4673 
4674     END IF;
4675 
4676 
4677     IF  p_x_header_rec.version_number IS NOT NULL AND
4678         (  (p_x_header_rec.version_number  <>
4679             p_old_header_rec.version_number OR
4680             p_old_header_rec.version_number IS NULL ) OR
4681            (p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE ) )
4682         --bug 5060064
4683     THEN
4684 
4685         IF NOT OE_Validate.Version_Number (p_x_header_rec.version_number)
4686         THEN
4687            IF p_validation_level = OE_GLOBALS.G_VALID_LEVEL_PARTIAL AND
4688               p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
4689            THEN
4690               p_x_header_rec.version_number := NULL;
4691            ELSIF p_validation_level = OE_GLOBALS.G_VALID_PARTIAL_WITH_DEF AND
4692               p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
4693            THEN
4694               p_x_header_rec.version_number := FND_API.G_MISS_CHAR;
4695            ELSE
4696               x_return_status := FND_API.G_RET_STS_ERROR;
4697            END IF;
4698 
4699         END IF;
4700 
4701     END IF;
4702 
4703     IF  p_x_header_rec.expiration_date IS NOT NULL AND
4704         (  (p_x_header_rec.expiration_date  <>
4705             p_old_header_rec.expiration_date OR
4706             p_old_header_rec.expiration_date IS NULL ) OR
4707            (p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE ) )
4708     --bug 5060064
4709      THEN
4710 
4711         IF NOT OE_Validate.Expiration_Date (p_x_header_rec.expiration_date)
4712         THEN
4713            IF p_validation_level = OE_GLOBALS.G_VALID_LEVEL_PARTIAL AND
4714               p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
4715            THEN
4716               p_x_header_rec.expiration_date := NULL;
4717            ELSIF p_validation_level = OE_GLOBALS.G_VALID_PARTIAL_WITH_DEF AND
4718               p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
4719            THEN
4720               -- Bug 3222419
4721               -- Copy was failing with numeric/value error if expiration date
4722               -- supplied was < sysdate
4723               p_x_header_rec.expiration_date := FND_API.G_MISS_DATE;
4724            ELSE
4725               x_return_status := FND_API.G_RET_STS_ERROR;
4726            END IF;
4727 
4728         END IF;
4729 
4730     END IF;
4731 
4732     IF  p_x_header_rec.sold_to_site_use_id IS NOT NULL AND
4733         (  (p_x_header_rec.sold_to_site_use_id <>
4734             p_old_header_rec.sold_to_site_use_id OR
4735             p_old_header_rec.sold_to_site_use_id IS NULL ) OR
4736            (p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE ) )
4737     --bug 5060064
4738     THEN
4739       IF NOT OE_Validate.Customer_Location(p_x_header_rec.sold_to_site_use_id)
4740       THEN
4741 	 IF p_validation_level = OE_GLOBALS.G_VALID_LEVEL_PARTIAL AND
4742 	    p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
4743 	 THEN
4744 	    p_x_header_rec.sold_to_site_use_id := NULL;
4745 	 ELSIF p_validation_level = OE_GLOBALS.G_VALID_PARTIAL_WITH_DEF AND
4746 	       p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
4747 	 THEN
4748 	    p_x_header_rec.sold_to_site_use_id := FND_API.G_MISS_NUM;
4749 	 ELSE
4750 	    x_return_status := FND_API.G_RET_STS_ERROR;
4751 	 END IF;
4752       END IF;
4753 
4754    END IF;
4755 
4756     -- QUOTING changes END
4757 
4758 
4759     IF  p_x_header_rec.Minisite_Id IS NOT NULL AND
4760         (  (p_x_header_rec.Minisite_Id  <>
4761             p_old_header_rec.Minisite_Id OR
4762             p_old_header_rec.Minisite_Id IS NULL )  OR
4763            (p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE ) )
4764     --bug 5060064
4765     THEN
4766 
4767         IF NOT OE_Validate.Minisite (p_x_header_rec.Minisite_Id)
4768         THEN
4769            IF p_validation_level = OE_GLOBALS.G_VALID_LEVEL_PARTIAL AND
4770               p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
4771            THEN
4772               p_x_header_rec.Minisite_Id := NULL;
4773            ELSIF p_validation_level = OE_GLOBALS.G_VALID_PARTIAL_WITH_DEF AND
4774               p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
4775            THEN
4776               p_x_header_rec.Minisite_Id := FND_API.G_MISS_NUM;
4777            ELSE
4778               x_return_status := FND_API.G_RET_STS_ERROR;
4779            END IF;
4780 
4781         END IF;
4782 
4783      END IF;
4784 
4785    IF  p_x_header_rec.Ib_owner  IS NOT NULL AND
4786         (  (p_x_header_rec.Ib_owner  <>
4787             p_old_header_rec.Ib_owner OR
4788             p_old_header_rec.Ib_owner IS NULL ) OR
4789            (p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE ) )
4790     --bug 5060064
4791    THEN
4792 
4793         IF NOT OE_Validate.IB_OWNER (p_x_header_rec.Ib_owner)
4794         THEN
4795            IF p_validation_level = OE_GLOBALS.G_VALID_LEVEL_PARTIAL AND
4796               p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
4797            THEN
4798               p_x_header_rec.Ib_owner := NULL;
4799            ELSIF p_validation_level = OE_GLOBALS.G_VALID_PARTIAL_WITH_DEF AND
4800               p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
4801            THEN
4802               p_x_header_rec.Ib_owner := FND_API.G_MISS_CHAR;
4803            ELSE
4804               x_return_status := FND_API.G_RET_STS_ERROR;
4805            END IF;
4806 
4807         END IF;
4808 
4809      END IF;
4810 
4811   IF  p_x_header_rec.Ib_installed_at_location  IS NOT NULL AND
4812         (  (p_x_header_rec.Ib_installed_at_location  <>
4813             p_old_header_rec.Ib_installed_at_location OR
4814             p_old_header_rec.Ib_installed_at_location IS NULL ) OR
4815            (p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE ) )
4816     --bug 5060064
4817     THEN
4818 
4819         IF NOT OE_Validate.IB_INSTALLED_AT_LOCATION (p_x_header_rec.Ib_installed_at_location)
4820         THEN
4821            IF p_validation_level = OE_GLOBALS.G_VALID_LEVEL_PARTIAL AND
4822               p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
4823            THEN
4824               p_x_header_rec.Ib_installed_at_location := NULL;
4825            ELSIF p_validation_level = OE_GLOBALS.G_VALID_PARTIAL_WITH_DEF AND
4826               p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
4827            THEN
4828               p_x_header_rec.Ib_installed_at_location := FND_API.G_MISS_CHAR;
4829            ELSE
4830               x_return_status := FND_API.G_RET_STS_ERROR;
4831            END IF;
4832 
4833         END IF;
4834 
4835      END IF;
4836 
4837    IF  p_x_header_rec.Ib_current_location  IS NOT NULL AND
4838         (  (p_x_header_rec.Ib_current_location  <>
4839             p_old_header_rec.Ib_current_location OR
4840             p_old_header_rec.Ib_current_location IS NULL ) OR
4841            (p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE ) )
4842     --bug 5060064
4843    THEN
4844 
4845         IF NOT OE_Validate.IB_CURRENT_LOCATION (p_x_header_rec.Ib_current_location)
4846         THEN
4847            IF p_validation_level = OE_GLOBALS.G_VALID_LEVEL_PARTIAL AND
4848               p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
4849            THEN
4850               p_x_header_rec.Ib_current_location := NULL;
4851            ELSIF p_validation_level = OE_GLOBALS.G_VALID_PARTIAL_WITH_DEF AND
4852               p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
4853            THEN
4854               p_x_header_rec.Ib_current_location := FND_API.G_MISS_CHAR;
4855            ELSE
4856               x_return_status := FND_API.G_RET_STS_ERROR;
4857            END IF;
4858 
4859         END IF;
4860 
4861      END IF;
4862 
4863    IF  p_x_header_rec.End_customer_id  IS NOT NULL AND
4864         (  (p_x_header_rec.End_customer_id  <>
4865             p_old_header_rec.End_customer_id OR
4866             p_old_header_rec.End_customer_id IS NULL ) OR
4867            (p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE ) )
4868     --bug 5060064
4869    THEN
4870 
4871         IF NOT OE_Validate.END_CUSTOMER (p_x_header_rec.End_customer_id)
4872         THEN
4873            IF p_validation_level = OE_GLOBALS.G_VALID_LEVEL_PARTIAL AND
4874               p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
4875            THEN
4876               p_x_header_rec.End_customer_id := NULL;
4877            ELSIF p_validation_level = OE_GLOBALS.G_VALID_PARTIAL_WITH_DEF AND
4878               p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
4879            THEN
4880               p_x_header_rec.End_customer_id := FND_API.G_MISS_NUM;
4881            ELSE
4882               x_return_status := FND_API.G_RET_STS_ERROR;
4883            END IF;
4884 
4885         END IF;
4886 
4887      END IF;
4888 
4889    IF  p_x_header_rec.End_customer_contact_id  IS NOT NULL AND
4890         (  (p_x_header_rec.End_customer_contact_id  <>
4891             p_old_header_rec.End_customer_contact_id OR
4892             p_old_header_rec.End_customer_contact_id IS NULL ) OR
4893            (p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE ) )
4894     --bug 5060064
4895     THEN
4896 
4897         IF NOT OE_Validate.END_CUSTOMER_CONTACT (p_x_header_rec.End_customer_contact_id)
4898         THEN
4899            IF p_validation_level = OE_GLOBALS.G_VALID_LEVEL_PARTIAL AND
4900               p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
4901            THEN
4902               p_x_header_rec.End_customer_contact_id := NULL;
4903            ELSIF p_validation_level = OE_GLOBALS.G_VALID_PARTIAL_WITH_DEF AND
4904               p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
4905            THEN
4906               p_x_header_rec.End_customer_contact_id := FND_API.G_MISS_NUM;
4907            ELSE
4908               x_return_status := FND_API.G_RET_STS_ERROR;
4909            END IF;
4910 
4911         END IF;
4912 
4913      END IF;
4914 
4915   IF  p_x_header_rec.End_customer_site_use_id  IS NOT NULL AND
4916         (  (p_x_header_rec.End_customer_site_use_id  <>
4917             p_old_header_rec.End_customer_site_use_id OR
4918             p_old_header_rec.End_customer_site_use_id IS NULL ) OR
4919            (p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE ) )
4920     --bug 5060064
4921   THEN
4922 
4923         IF NOT OE_Validate.END_CUSTOMER_SITE_USE (p_x_header_rec.End_customer_site_use_id)
4924         THEN
4925            IF p_validation_level = OE_GLOBALS.G_VALID_LEVEL_PARTIAL AND
4926               p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
4927            THEN
4928               p_x_header_rec.End_customer_site_use_id := NULL;
4929            ELSIF p_validation_level = OE_GLOBALS.G_VALID_PARTIAL_WITH_DEF AND
4930               p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
4931            THEN
4932               p_x_header_rec.End_customer_site_use_id := FND_API.G_MISS_NUM;
4933            ELSE
4934               x_return_status := FND_API.G_RET_STS_ERROR;
4935            END IF;
4936 
4937         END IF;
4938 
4939      END IF;
4940 
4941    IF  p_x_header_rec.supplier_signature  IS NOT NULL AND
4942         (  (p_x_header_rec.supplier_signature  <>
4943             p_old_header_rec.supplier_signature OR
4944             p_old_header_rec.supplier_signature IS NULL ) OR
4945            (p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE ) )
4946     --bug 5060064
4947     THEN
4948 
4949        IF NOT OE_Validate.SUPPLIER_SIGNATURE (p_x_header_rec.supplier_signature)
4950         THEN
4951            IF p_validation_level = OE_GLOBALS.G_VALID_LEVEL_PARTIAL AND
4952               p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
4953            THEN
4954               p_x_header_rec.supplier_signature := NULL;
4955            ELSIF p_validation_level = OE_GLOBALS.G_VALID_PARTIAL_WITH_DEF AND
4956               p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
4957            THEN
4958               p_x_header_rec.supplier_signature := FND_API.G_MISS_CHAR;
4959            ELSE
4960               x_return_status := FND_API.G_RET_STS_ERROR;
4961            END IF;
4962 
4963         END IF;
4964 
4965      END IF;
4966 
4967    IF  p_x_header_rec.supplier_signature_date  IS NOT NULL AND
4968         (  (p_x_header_rec.supplier_signature_date  <>
4969             p_old_header_rec.supplier_signature_date OR
4970             p_old_header_rec.supplier_signature_date IS NULL ) OR
4971            (p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE ) )
4972     --bug 5060064
4973    THEN
4974 
4975        IF NOT OE_Validate.SUPPLIER_SIGNATURE_DATE (p_x_header_rec.supplier_signature_date)
4976         THEN
4977            IF p_validation_level = OE_GLOBALS.G_VALID_LEVEL_PARTIAL AND
4978               p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
4979            THEN
4980               p_x_header_rec.supplier_signature_date := NULL;
4981            ELSIF p_validation_level = OE_GLOBALS.G_VALID_PARTIAL_WITH_DEF AND
4982               p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
4983            THEN
4984               p_x_header_rec.supplier_signature_date := FND_API.G_MISS_DATE;
4985            ELSE
4986               x_return_status := FND_API.G_RET_STS_ERROR;
4987            END IF;
4988 
4989         END IF;
4990 
4991      END IF;
4992 
4993    IF  p_x_header_rec.customer_signature  IS NOT NULL AND
4994         (  (p_x_header_rec.customer_signature  <>
4995             p_old_header_rec.customer_signature OR
4996             p_old_header_rec.customer_signature IS NULL ) OR
4997            (p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE ) )
4998     --bug 5060064
4999    THEN
5000 
5001        IF NOT OE_Validate.CUSTOMER_SIGNATURE (p_x_header_rec.customer_signature)
5002         THEN
5003            IF p_validation_level = OE_GLOBALS.G_VALID_LEVEL_PARTIAL AND
5004               p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
5005            THEN
5006               p_x_header_rec.customer_signature := NULL;
5007            ELSIF p_validation_level = OE_GLOBALS.G_VALID_PARTIAL_WITH_DEF AND
5008               p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
5009            THEN
5010               p_x_header_rec.customer_signature := FND_API.G_MISS_CHAR;
5011            ELSE
5012               x_return_status := FND_API.G_RET_STS_ERROR;
5013            END IF;
5014 
5015         END IF;
5016 
5017      END IF;
5018 
5019   IF  p_x_header_rec.customer_signature_date  IS NOT NULL AND
5020         (  (p_x_header_rec.customer_signature_date  <>
5021             p_old_header_rec.customer_signature_date OR
5022             p_old_header_rec.customer_signature_date IS NULL ) OR
5023            (p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE ) )
5024     --bug 5060064
5025    THEN
5026 
5027        IF NOT OE_Validate.CUSTOMER_SIGNATURE_DATE (p_x_header_rec.customer_signature_date)
5028         THEN
5029            IF p_validation_level = OE_GLOBALS.G_VALID_LEVEL_PARTIAL AND
5030               p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
5031            THEN
5032               p_x_header_rec.customer_signature_date := NULL;
5033            ELSIF p_validation_level = OE_GLOBALS.G_VALID_PARTIAL_WITH_DEF AND
5034               p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
5035            THEN
5036               p_x_header_rec.customer_signature_date := FND_API.G_MISS_DATE;
5037            ELSE
5038               x_return_status := FND_API.G_RET_STS_ERROR;
5039            END IF;
5040 
5041         END IF;
5042 
5043      END IF;
5044 
5045 
5046 
5047 
5048 --End Of Addition
5049 --End Of Addition
5050     oe_debug_pub.add('Exiting OE_VALIDATE_HEADER.ATTRIBUTES',1);
5051 
5052 EXCEPTION
5053 
5054     WHEN FND_API.G_EXC_ERROR THEN
5055       x_return_status := FND_API.G_RET_STS_ERROR;
5056 
5057     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
5058       x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5059 
5060     WHEN OTHERS THEN
5061       x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5062 
5063       IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
5064       THEN
5065         OE_MSG_PUB.Add_Exc_Msg
5066         (   G_PKG_NAME
5067            ,'Attributes'
5068          );
5069       END IF;
5070 
5071 END Attributes;
5072 
5073 
5074 
5075 /*-----------------------------------------------------
5076 PROCEDURE:   Entity_Delete
5077 Description:
5078 -------------------------------------------------------*/
5079 
5080 PROCEDURE Entity_Delete
5081 (   x_return_status                 OUT NOCOPY /* file.sql.39 change */ VARCHAR2
5082 ,   p_header_rec                    IN  OE_Order_PUB.Header_Rec_Type
5083 )
5084 IS
5085 l_return_status               VARCHAR2(1) := FND_API.G_RET_STS_SUCCESS;
5086 BEGIN
5087 
5088     --  Validate entity delete.
5089     NULL;
5090     --  Done.
5091 
5092     x_return_status := l_return_status;
5093 
5094 EXCEPTION
5095 
5096     WHEN FND_API.G_EXC_ERROR THEN
5097       x_return_status := FND_API.G_RET_STS_ERROR;
5098 
5099     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
5100       x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5101 
5102     WHEN OTHERS THEN
5103       x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5104 
5105       IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
5106       THEN
5107        OE_MSG_PUB.Add_Exc_Msg
5108        (   G_PKG_NAME
5109           ,'Entity_Delete'
5110         );
5111       END IF;
5112 
5113 END Entity_Delete;
5114 
5115 END OE_Validate_Header;