DBA Data[Home] [Help]

PACKAGE BODY: APPS.OE_DEFAULT_HEADER

Source


1 PACKAGE BODY OE_Default_Header AS
2 /* $Header: OEXDHDRB.pls 120.3 2006/09/04 07:31:17 ddey noship $ */
3 
4 --  Global constant holding the package name
5 G_PKG_NAME                    CONSTANT VARCHAR2(30) := 'OE_Default_Header';
6 
7 g_header_rec			OE_AK_ORDER_HEADERS_V%ROWTYPE;
8 
9 FUNCTION GET_FREIGHT_CARRIER(p_Header_rec OE_ORDER_PUB.Header_Rec_Type,
10                              p_old_header_rec OE_ORDER_PUB.Header_Rec_Type)
11 RETURN VARCHAR2
12 IS
13 l_freight_code VARCHAR2(80);
14 --
15 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
16 --
17 begin
18    IF l_debug_level  > 0 THEN
19       oe_debug_pub.add('Enter get_freight_carrier()',1);
20       oe_debug_pub.add('Performance Issue 2830725 fixed',5);
21    END IF;
22    IF (p_header_rec.shipping_method_code IS NOT NULL AND
23        p_header_rec.shipping_method_code <> FND_API.G_MISS_CHAR) AND
24       (p_header_rec.ship_from_org_id  IS NOT NULL AND
25        p_header_rec.ship_from_org_id<> FND_API.G_MISS_NUM) THEN
26 
27     -- 3610480 : Validate freight_carrier_code if shipping_method_code or ship_from_org_id is not null
28        IF  (NOT OE_GLOBALS.EQUAL(p_header_rec.shipping_method_code
29                                 ,p_old_header_rec.shipping_method_code) OR
30             NOT OE_GLOBALS.EQUAL(p_header_rec.ship_from_org_id
31                                 ,p_old_header_rec.ship_from_org_id) OR
32             NOT OE_GLOBALS.EQUAL(p_header_rec.freight_carrier_code
33                                 ,p_old_header_rec.freight_carrier_code)) THEN
34 
35            IF OE_CODE_CONTROL.CODE_RELEASE_LEVEL >= '110509' THEN
36               SELECT freight_code
37               INTO   l_freight_code
38               FROM   wsh_carriers wsh_ca,wsh_carrier_services wsh,
39                      wsh_org_carrier_services wsh_org
40               WHERE  wsh_org.organization_id      = p_header_rec.ship_from_org_id
41               AND    wsh.carrier_service_id       = wsh_org.carrier_service_id
42               AND    wsh_ca.carrier_id            = wsh.carrier_id
43               AND    wsh.ship_method_code         = p_header_rec.shipping_method_code
44               AND    wsh_org.enabled_flag         = 'Y';
45            ELSE
46               SELECT FREIGHT_CODE
47               INTO   l_freight_code
48               FROM   wsh_carrier_ship_methods
49               WHERE  ship_method_code = p_header_rec.shipping_method_code
50               AND    ORGANIZATION_ID = p_header_rec.ship_from_org_id;
51            END IF;
52            IF l_debug_level  > 0 THEN
53               oe_debug_pub.add('Freight carrier returned is '||l_freight_code,5);
54            END IF;
55            RETURN l_freight_code;
56         ELSE
57            IF l_debug_level  > 0 THEN
58               oe_debug_pub.add('into header null condition'||p_header_rec.ship_from_org_id,5);
59            END IF;
60            RETURN p_header_rec.freight_carrier_code;
61         END IF;
62     ELSE
63        IF l_debug_level  > 0 THEN
64           oe_debug_pub.add('SHIP FROM OR SHIP METHOD IS NULL/MISSING',5);
65        END IF;
66        RETURN NULL;
67     END IF;
68 
69     IF (p_header_rec.shipping_method_code IS NULL OR
70         p_header_rec.shipping_method_code = FND_API.G_MISS_CHAR) THEN
71         RETURN NULL;
72     END IF;
73     RETURN p_header_rec.freight_carrier_code;
74 
75 EXCEPTION
76 
77 WHEN NO_DATA_FOUND THEN
78      IF l_debug_level  > 0 THEN
79          oe_debug_pub.add('SQL Error : '||sqlerrm,1);
80      END IF;
81      RETURN NULL;
82 WHEN OTHERS THEN
83      IF l_debug_level  > 0 THEN
84          oe_debug_pub.add('SQL Other Error : '||sqlerrm,1);
85      END IF;
86      IF OE_MSG_PUB.Check_Msg_Level (OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
87      THEN
88          OE_MSG_PUB.Add_Exc_Msg
89          (     G_PKG_NAME         ,
90              'Get_freight_carrier'
91          );
92      END IF;
93      RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
94 END GET_FREIGHT_CARRIER;
95 
96 
97 FUNCTION Get_Order_Category(p_header_rec OE_ORDER_PUB.Header_rec_Type,
98 					p_old_header_rec OE_ORDER_PUB.Header_rec_Type)
99 RETURN VARCHAR2
100 IS
101 l_category_code varchar2(30);
102 --
103 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
104 --
105 BEGIN
106 /*
107  * Always default 1 as the order category
108  *
109  */
110  IF l_debug_level  > 0 THEN
111      oe_debug_pub.add(  'ENTER ORDER CATEGORY' ) ;
112  END IF;
113  IF l_debug_level  > 0 THEN
114      oe_debug_pub.add(  'ENTER ORDER CATEGORY'|| P_HEADER_REC.ORDER_TYPE_ID ) ;
115  END IF;
116      Select order_category_code
117      into l_category_code
118      from
119      oe_order_types_v
120      where
121      order_type_id = p_header_rec.order_type_id;
122 
123 	IF p_header_rec.operation = oe_globals.g_opr_update THEN
124 	IF (p_old_header_rec.order_category_code <> FND_API.G_MISS_CHAR AND
125 		   p_old_header_rec.order_category_code IS NOT NULL ) THEN
126 		IF NOT OE_GLOBALS.EQUAL(p_old_header_rec.order_category_code,
127 	       	l_category_code) THEN
128                          FND_MESSAGE.SET_NAME('ONT','OE_ORD_CAT_CONST');
129                          OE_MSG_PUB.ADD;
130                          IF l_debug_level  > 0 THEN
131                              oe_debug_pub.add(  'ORDER CATEGORY CONSTRAINED' ) ;
132                          END IF;
133                          RAISE FND_API.G_EXC_ERROR;
134 		END IF;
135 	END IF;
136 	END IF;
137 
138 
139 
140     RETURN l_category_code;
141 
142 EXCEPTION
143      WHEN NO_DATA_FOUND THEN
144           Return 'ORDER';
145 
146   --For Bug 3436556
147      WHEN FND_API.G_EXC_ERROR THEN
148           RAISE FND_API.G_EXC_ERROR;
149   --End Of Fix
150 
151     WHEN OTHERS THEN
152      IF OE_MSG_PUB.Check_Msg_Level (OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
153      THEN
154          OE_MSG_PUB.Add_Exc_Msg
155          (     G_PKG_NAME         ,
156              'Get_order_category'
157          );
158      END IF;
159 
160      RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
161 
162 END Get_Order_Category;
163 
164 FUNCTION Get_Customer_Preference_set(p_header_rec OE_ORDER_PUB.Header_rec_Type,
165 					p_old_header_rec OE_ORDER_PUB.Header_rec_Type)
166 RETURN VARCHAR2
167 IS
168 lshipset varchar2(30);
169 larrivalset varchar2(30);
170 lsiteuseid number;
171 
172 Cursor C1 IS
173 Select  SHIP_SETS_INCLUDE_LINES_FLAG,
174 ARRIVALSETS_INCLUDE_LINES_FLAG
175 from hz_cust_accounts
176 where
177 cust_account_id = p_header_rec.sold_to_org_id;
178 Cursor C2 IS
179 Select  SHIP_SETS_INCLUDE_LINES_FLAG,
180 ARRIVALSETS_INCLUDE_LINES_FLAG
181 from hz_cust_site_uses
182 where
183 site_use_id = lsiteuseid;
184 --
185 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
186 --
187 Begin
188 
189 --IF p_header_rec.operation = oe_globals.g_opr_create THEN
190 
191 IF NOT OE_GLOBALS.EQUAL(p_header_rec.ship_to_org_id,
192                            p_old_header_rec.ship_to_org_id) THEN
193 
194 lsiteuseid := p_header_rec.ship_to_org_id;
195 OPEN C2;
196 FETCH C2 INTO
197 lshipset,
198 larrivalset;
199 CLOSE C2;
200 		IF l_debug_level  > 0 THEN
201 		    oe_debug_pub.add(  'ENTER - CUST PREF SET IN SHIP TO' , 1 ) ;
202 		END IF;
203                 IF nvl(lshipset,'N') = 'Y' THEN
204                         RETURN 'SHIP';
205                 ELSIF nvl(larrivalset,'N') = 'Y' THEN
206                         RETURN 'ARRIVAL';
207                 END IF;
208 		IF l_debug_level  > 0 THEN
209 		    oe_debug_pub.add(  'EXIT - CUST PREF SET IN SHIP TO' , 1 ) ;
210 		END IF;
211 
212 END IF;
213 
214 IF NOT OE_GLOBALS.EQUAL(p_header_rec.invoice_to_org_id,
215                            p_old_header_rec.invoice_to_org_id) THEN
216 
217 lsiteuseid := p_header_rec.invoice_to_org_id;
218 OPEN C2;
219 FETCH C2 INTO
220 lshipset,
221 larrivalset;
222 CLOSE C2;
223 		IF l_debug_level  > 0 THEN
224 		    oe_debug_pub.add(  'ENTER - CUST PREF SET IN BILL TO' , 1 ) ;
225 		END IF;
226                 IF nvl(lshipset,'N') = 'Y' THEN
227                         RETURN 'SHIP';
228                 ELSIF nvl(larrivalset,'N') = 'Y' THEN
229                         RETURN 'ARRIVAL';
230                 END IF;
231 		IF l_debug_level  > 0 THEN
232 		    oe_debug_pub.add(  'EXIT - CUST PREF SET IN BILL TO' , 1 ) ;
233 		END IF;
234 
235 END IF;
236 
237 IF NOT OE_GLOBALS.EQUAL(p_header_rec.sold_to_org_id,
238 			   p_old_header_rec.sold_to_org_id) THEN
239 
240 /*OPEN C2;
241 FETCH C2 INTO
242 lshipset,
243 larrivalset;
244 CLOSE C2;
245 		IF nvl(lshipset,'N') = 'Y' THEN
246 			RETURN 'SHIP';
247 		ELSIF nvl(larrivalset,'N') = 'Y' THEN
248 			RETURN 'ARRIVAL';
249 		END IF;
250 */
251 
252 OPEN C1;
253 FETCH C1 INTO
254 lshipset,
255 larrivalset;
256 CLOSE C1;
257 		IF l_debug_level  > 0 THEN
258 		    oe_debug_pub.add(  'ENTER - CUST PREF SET IN SOLD TO' , 1 ) ;
259 		END IF;
260 
261 		IF nvl(lshipset,'N') = 'Y' THEN
262 			RETURN 'SHIP';
263 		ELSIF nvl(larrivalset,'N') = 'Y' THEN
264 			RETURN 'ARRIVAL';
265 		END IF;
266 
267 IF l_debug_level  > 0 THEN
268     oe_debug_pub.add(  'SET CODE'|| P_HEADER_REC.CUSTOMER_PREFERENCE_SET_CODE , 1 ) ;
269 END IF;
270 		RETURN p_header_rec.customer_preference_set_code;
271 		IF l_debug_level  > 0 THEN
272 		    oe_debug_pub.add(  'EXIT - CUST PREF SET IN SOLD TO' , 1 ) ;
273 		END IF;
274 END IF;
275 
276 
277 
278 --END IF;
279 IF l_debug_level  > 0 THEN
280     oe_debug_pub.add(  'SET CODE'|| P_HEADER_REC.CUSTOMER_PREFERENCE_SET_CODE , 1 ) ;
281 END IF;
282 	IF l_debug_level  > 0 THEN
283 	    oe_debug_pub.add(  'EXIT - ' , 1 ) ;
284 	END IF;
285 
286 RETURN p_header_rec.customer_preference_set_code;
287 EXCEPTION
288 
289     WHEN OTHERS THEN
290      IF OE_MSG_PUB.Check_Msg_Level (OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
291      THEN
292          OE_MSG_PUB.Add_Exc_Msg
293          (     G_PKG_NAME         ,
294              'Get_customer_preference_set'
295          );
296      END IF;
297 
298      RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
299 
300 END Get_customer_preference_set;
301 
302 
303 
304 
305 FUNCTION Get_Booked
306 RETURN VARCHAR2
307 IS
308 --
309 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
310 --
311 BEGIN
312 
313     RETURN 'N';
314 
315 END Get_Booked;
316 
317 FUNCTION Get_Cancelled
318 RETURN VARCHAR2
319 IS
320 --
321 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
322 --
323 BEGIN
324 
325     RETURN 'N';
326 
327 END Get_Cancelled;
328 
329 FUNCTION Get_Header
330 RETURN NUMBER
331 IS
332 l_hdr_id	NUMBER := NULL;
333 --
334 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
335 --
336 BEGIN
337 /*
338  * Select from the sequence
339  *
340  */
341     SELECT  OE_ORDER_HEADERS_S.NEXTVAL
342     INTO    l_hdr_id
343     FROM    DUAL;
344 
345     RETURN l_hdr_id;
346 
347 EXCEPTION
348 
349     WHEN OTHERS THEN
350 
351     	IF OE_MSG_PUB.Check_Msg_Level (OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
352 	THEN
353     	    OE_MSG_PUB.Add_Exc_Msg
354     	    (	G_PKG_NAME  	    ,
355     	        'Get_Header'
356 	    );
357     	END IF;
358 
359 	RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
360 
361 END Get_Header;
362 
363 FUNCTION Get_Open
364 RETURN VARCHAR2
365 IS
366 --
367 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
368 --
369 BEGIN
370 
371     RETURN 'Y';
372 
373 END Get_Open;
374 
375 FUNCTION Get_Org
376 RETURN NUMBER
377 IS
378 l_org_id NUMBER := NULL;
379 --
380 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
381 --
382 BEGIN
383 
384  OE_GLOBALS.Set_Context;
385  l_org_id := OE_GLOBALS.G_ORG_ID;
386 
387  RETURN l_org_id;
388 
389 END Get_Org;
390 
391 FUNCTION Get_Ordered_Date
392 RETURN DATE
393 IS
394 --
395 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
396 --
397 BEGIN
398 
399 /*
400  * Always default today as the date ordered
401  *
402  */
403 
404     RETURN SYSDATE;
405 
406 EXCEPTION
407 
408     WHEN OTHERS THEN
409 
410     	IF OE_MSG_PUB.Check_Msg_Level (OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
411 	THEN
412     	    OE_MSG_PUB.Add_Exc_Msg
413     	    (	G_PKG_NAME  	    ,
414     	        'Get_Ordered_Date'
415 	    );
416     	END IF;
417 
418 	RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
419 
420 END Get_Ordered_Date;
421 
422 FUNCTION Get_Version_Number
423 RETURN NUMBER
424 IS
425 --
426 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
427 --
428 BEGIN
429 /*
430  * Always default 1 as the version number prior to 11i10.
431  *
432  */
433 
434     -- QUOTING changes
435     IF OE_Code_Control.Code_Release_Level >= '110510' THEN
436        RETURN 0;
437     ELSE
438        RETURN 1;
439     END IF;
440 
441 EXCEPTION
442 
443     WHEN OTHERS THEN
444 
445     	IF OE_MSG_PUB.Check_Msg_Level (OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
446 	THEN
447     	    OE_MSG_PUB.Add_Exc_Msg
448     	    (	G_PKG_NAME  	    ,
449     	        'Get_Version_Number'
450 	    );
451     	END IF;
452 
453 	RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
454 
455 END Get_Version_Number;
456 
457 FUNCTION Get_Order_Source_Id
458 RETURN NUMBER
459 IS
460 --l_order_source_id  NUMBER;
461 --
462 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
463 --
464 BEGIN
465 /*
466   SELECT  ORDER_SOURCE_ID
467     INTO  l_order_source_id
468     FROM  OE_ORDER_SOURCES
469    WHERE name = 'Online';
470 */
471   RETURN 0;
472 
473 EXCEPTION
474 
475     WHEN OTHERS THEN
476 
477         IF OE_MSG_PUB.Check_Msg_Level (OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
478         THEN
479             OE_MSG_PUB.Add_Exc_Msg
480             (   G_PKG_NAME          ,
481                 'Get_Order_Source'
482             );
483         END IF;
484 
485         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
486 
487 END Get_Order_Source_Id;
488 
489 FUNCTION Get_EM_Message_Id
490 RETURN NUMBER
491 IS
492 l_em_message_id  NUMBER;
493 --
494 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
495 --
496 BEGIN
497    SELECT OE_XML_MESSAGE_SEQ_S.NEXTVAL
498      INTO l_em_message_id
499      FROM DUAL;
500      RETURN l_em_message_id;
501 
502 EXCEPTION
503     WHEN OTHERS THEN
504         RETURN NULL;
505 END Get_EM_Message_Id;
506 
507 FUNCTION  Get_Contract_Template_Id(p_header_rec OE_ORDER_PUB.Header_rec_Type,
508                                      p_old_header_rec OE_ORDER_PUB.Header_rec_Type)
509 RETURN NUMBER
510 IS
511 
512   l_contract_template_id    NUMBER := NULL;
513   l_return_status       VARCHAR2(1);
514   l_msg_count           NUMBER;
515   l_msg_data            VARCHAR2(2000);
516   l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
517   l_result VARCHAR2(1) := 'Y';
518 BEGIN
519 
520     IF l_debug_level  > 0 THEN
521        oe_debug_pub.add(  'ENTER GET CONTRACT TEMPLATE' ) ;
522     END IF;
523 
524     BEGIN
525       select contract_template_id
526       into l_contract_template_id
527       from oe_order_types_v
528       where order_type_id = p_header_rec.order_type_id;
529     EXCEPTION
530       WHEN NO_DATA_FOUND THEN
531         l_contract_template_id := NULL;
532     END;
533 
534     IF l_debug_level  > 0 THEN
535        oe_debug_pub.add(  'l_contract_template_id'|| l_contract_template_id ) ;
536        oe_debug_pub.add(  'p_header_rec.order_type_id'|| p_header_rec.order_type_id ) ;
537     END IF;
538 
539     -- call is_terms_template_valid
540     -- check for result and put msg on stack based if N
541     -- and set value of l_contract_template_id to NULL
542 
543       l_result := OE_CONTRACTS_UTIL.Is_Terms_Template_Valid
544 		(p_api_version        	=> 1.0,
545    	 	 p_init_msg_list      	=> FND_API.G_FALSE,
546    	 	 x_return_status       	=> l_return_status,
547    	 	 x_msg_count            => l_msg_count,
548    	 	 x_msg_data             => l_msg_data,
549   	 	 p_doc_type             => 'O',
550   	 	 p_template_id          => l_contract_template_id,
551   	 	 p_org_id           	=> p_header_rec.org_id
552 	 	 );
553 
554       IF l_contract_template_id IS NOT NULL AND l_result = 'N' THEN
555 
556 	l_contract_template_id := NULL;
557 
558         IF p_header_rec.transaction_phase_code = 'N' THEN
559           fnd_message.set_name('ONT','ONT_QUOTE_EXPIRED_TEMPLATE');
560           fnd_message.set_token('TEXT1',
561 			OE_Order_UTIL.Get_Attribute_Name('ORDER_TYPE'));
562         ELSE
563           fnd_message.set_name('ONT','ONT_ORDER_EXPIRED_TEMPLATE');
564           fnd_message.set_token('TEXT1',
565 			OE_Order_UTIL.Get_Attribute_Name('ORDER_TYPE'));
566         END IF;
567 
568         OE_MSG_PUB.Add;
569 
570       END IF;
571 
572     RETURN l_contract_template_id;
573 
574 EXCEPTION
575 
576      WHEN OTHERS THEN
577      IF OE_MSG_PUB.Check_Msg_Level (OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
578      THEN
579          OE_MSG_PUB.Add_Exc_Msg
580          (     G_PKG_NAME         ,
581              'Get_contract_template_id'
582          );
583      END IF;
584 
585      RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
586 
587 END Get_Contract_Template_ID;
588 
589 
590 
591 --BEGIN Blankets Code Merge
592 
593 PROCEDURE Clear_And_Re_Default
594 (p_blanket_number         IN NUMBER
595 ,p_x_header_rec           IN OUT NOCOPY OE_AK_ORDER_HEADERS_V%ROWTYPE
596 ,p_old_header_rec         IN OE_AK_ORDER_HEADERS_V%ROWTYPE
597 ,p_default_record         IN VARCHAR2
598 )
599 IS
600   l_header_rec            OE_AK_ORDER_HEADERS_V%ROWTYPE;
601 --
602 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
603 --
604 BEGIN
605   IF l_debug_level  > 0 THEN
606      oe_debug_pub.add('ENTER Clear_And_Re_Default') ;
607   END IF;
608 
609   -- Identify source attributes
610   -- And copy source attribute values from IN parameters
611   -- to the new record e.g. blanket number value is copied
612   -- to p_x_header_rec.
613   IF p_blanket_number IS NOT NULL
614      AND NOT OE_GLOBALS.EQUAL(p_blanket_number,
615                               p_x_header_rec.blanket_number)
616   THEN
617      p_x_header_rec.blanket_number := p_blanket_number;
618      l_header_rec := p_x_header_rec;
619      -- Clear dependents based on this source attribute tbl
620      OE_Header_Util.Clear_Dependent_Attr
621        (p_attr_id                      => OE_Header_Util.G_BLANKET_NUMBER
622        ,p_x_header_rec                 => p_x_header_rec
623        ,p_initial_header_rec           => l_header_rec
624        ,p_old_header_rec               => p_old_header_rec
625        );
626   END IF;
627 
628   IF p_default_record = 'Y' THEN
629      IF l_debug_level  > 0 THEN
630         oe_debug_pub.add('RE-CALLING ONT_HEADER_DEF_HDLR.DEFAULT_RECORD') ;
631      END IF;
632      ONT_HEADER_Def_Hdlr.Default_Record
633         (p_x_rec	        => p_x_header_rec
634         ,p_initial_rec	        => l_header_rec
635         ,p_in_old_rec		=> p_old_header_rec
636         );
637   END IF;
638 
639   IF l_debug_level  > 0 THEN
640      oe_debug_pub.add('EXIT Clear_And_Re_Default') ;
641   END IF;
642 
643 END Clear_And_Re_Default;
644 
645 FUNCTION Default_Blanket_Number (
646    p_sold_to_org_id IN NUMBER,
647    p_request_date IN DATE,
648    p_cust_po_number IN VARCHAR2
649 )
650 RETURN NUMBER
651 IS
652 l_blanket_number NUMBER := NULL;
653 l_request_date   DATE;
654 --
655 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
656 --
657 BEGIN
658 
659     if l_debug_level > 0 then
660        oe_debug_pub.add('Enter Default_Blanket_Number');
661        oe_debug_pub.add('Request Date :'||p_request_date);
662     end if;
663 
664     if p_request_date = fnd_api.g_miss_date then
665        l_request_date := null;
666     else
667        l_request_date := p_request_date;
668     end if;
669 
670     SELECT BH.ORDER_NUMBER
671     INTO l_blanket_number
672     FROM OE_BLANKET_HEADERS BH,OE_BLANKET_HEADERS_EXT BHE
673     WHERE     BH.CUST_PO_NUMBER = p_cust_po_number
674         AND   BH.SOLD_TO_ORG_ID = p_sold_to_org_id
675         AND   BHE.ON_HOLD_FLAG = 'N'
676         AND   trunc(nvl(l_request_date,sysdate))
677         BETWEEN trunc(BHE.START_DATE_ACTIVE)
678         AND   trunc(nvl(BHE.END_DATE_ACTIVE, nvl(l_request_date,sysdate)))
679         AND   BH.ORDER_NUMBER = BHE.ORDER_NUMBER
680         AND   BH.SALES_DOCUMENT_TYPE_CODE = 'B';
681 
682     if l_debug_level > 0 then
683        oe_debug_pub.add('Exit Default_Blanket_Number, default :'||l_blanket_number);
684     end if;
685 
686     RETURN l_blanket_number;
687 
688 EXCEPTION
689   WHEN TOO_MANY_ROWS THEN
690     RETURN NULL;
691   WHEN NO_DATA_FOUND THEN
692     IF l_debug_level  > 0 THEN
693          oe_debug_pub.add('No Blanket Number exists for this customer and  po number :'||p_sold_to_org_id || ', ' || p_cust_po_number,2);
694     END IF;
695   RETURN NULL;
696 END Default_Blanket_Number;
697 
698 --END Blankets Code Merge
699 
700 PROCEDURE Attributes
701 (   p_x_Header_rec                  IN OUT NOCOPY  OE_Order_PUB.Header_Rec_Type
702 ,   p_old_Header_rec                IN  OE_Order_PUB.Header_Rec_Type
703 ,   p_iteration                     IN  NUMBER := 1
704 )
705 IS
706 
707     l_old_header_rec     	OE_AK_ORDER_HEADERS_V%ROWTYPE;
708     l_record     	          OE_AK_ORDER_HEADERS_V%ROWTYPE;
709     l_operation		     VARCHAR2(30);
710     l_set_of_books_rec        OE_Order_Cache.Set_Of_Books_Rec_Type;
711     l_Is_Fixed_Rate           Varchar2(1);
712     l_cust_pref_set_code varchar2(240)
713 		:= p_x_Header_rec.customer_preference_Set_code;
714 
715     l_blanket_number          NUMBER := NULL;
716 
717     l_exists            VARCHAR2(1);
718     l_party_type        VARCHAR2(30);
719 
720 --
721 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
722 --
723 BEGIN
724 
725     IF l_debug_level  > 0 THEN
726         oe_debug_pub.add(  'ENTER OE_DEFAULT_HEADER.ATTRIBUTES' ) ;
727     END IF;
728 
729     --  Due to incompatibilities in the record type structure
730     --  copy the data to a rowtype record format
731 
732     OE_Header_UTIL.API_Rec_To_Rowtype_Rec
733 			(p_header_rec => p_x_header_rec
734                ,x_rowtype_rec => g_header_rec);
735     OE_Header_UTIL.API_Rec_To_Rowtype_Rec
736 			(p_header_rec => p_old_header_rec
737                ,x_rowtype_rec => l_old_header_rec);
738 
739     --  For some fields, get hardcoded defaults based on the operation
740     l_operation := p_x_header_rec.operation;
741 
742     --  IMPORTANT: For defaulting to work correctly, none of these fields should be
743     --  dependent on any other field (Refer OEXUDEPB.pls for the list of dependencies)
744     IF l_operation = OE_GLOBALS.G_OPR_CREATE THEN
745 
746 	   g_header_rec.org_id := Get_Org;
747 
748         IF g_header_rec.created_by = FND_API.G_MISS_NUM THEN
749 		g_header_rec.created_by := FND_GLOBAL.USER_ID;
750 	   END IF;
751 
752 --key Transaction Dates
753 	IF g_header_rec.creation_date = FND_API.G_MISS_DATE THEN
754 		g_header_rec.creation_date := sysdate ;
755 	END IF ;
756 --end
757 
758 	   IF g_header_rec.header_id = FND_API.G_MISS_NUM THEN
759 		g_header_rec.header_id	:= Get_Header;
760 	   END IF;
761 
762 	   IF g_header_rec.booked_flag = FND_API.G_MISS_CHAR THEN
763 		g_header_rec.booked_flag	:= Get_Booked;
764 	   END IF;
765 
766 	   IF g_header_rec.cancelled_flag = FND_API.G_MISS_CHAR THEN
767 		g_header_rec.cancelled_flag	:= Get_Cancelled;
768 	   END IF;
769 
770 	   IF g_header_rec.open_flag = FND_API.G_MISS_CHAR THEN
771 		g_header_rec.open_flag	:= Get_Open;
772 	   END IF;
773 
774 	   IF g_header_rec.version_number = FND_API.G_MISS_NUM THEN
775 		g_header_rec.version_number	:= Get_Version_Number;
776 	   END IF;
777            --bug3664313 FP start: added NULL check
778            IF ((g_header_rec.orig_sys_document_ref = FND_API.G_MISS_CHAR OR
779 	        g_header_rec.orig_sys_document_ref IS NULL) AND
780                g_header_rec.source_document_id <> 10) THEN
781               g_header_rec.orig_sys_document_ref := 'OE_ORDER_HEADERS_ALL'||g_header_rec.header_id;
782            END IF;
783 
784            IF g_header_rec.order_source_id = FND_API.G_MISS_NUM THEN
785              IF g_header_rec.source_document_type_id = FND_API.G_MISS_NUM THEN	  --2991163
786                g_header_rec.order_source_id := Get_Order_Source_Id;
787 	     ELSE
788                g_header_rec.order_source_id := g_header_rec.source_document_type_id ; --2991163
789              END IF; --2991163
790            END IF;
791 
792 
793 	END IF;
794 
795       --BEGIN Blankets Code Merge
796       --Blanket Header Hardcoded Defaulting
797       --defaults blanket_number based on sold_to_org and customer_po:
798       IF OE_CODE_CONTROL.Get_Code_Release_Level >= '110509' THEN
799 
800         IF l_debug_level > 0 THEN
801            oe_debug_pub.add('Blanket Number :'||g_header_rec.blanket_number);
802            oe_debug_pub.add('Sold To :'||g_header_rec.sold_to_org_id);
803            oe_debug_pub.add('Cust PO :'||g_header_rec.cust_po_number);
804            oe_debug_pub.add('Old Cust PO :'||l_old_header_rec.cust_po_number);
805         END IF;
806 
807         IF (g_header_rec.blanket_number IS NULL OR
808             g_header_rec.blanket_number = FND_API.G_MISS_NUM) AND
809             -- Re-default only if old record does not have a blanket
810             -- value either, as defaulting should not over-ride
811             -- existing blanket value.
812            (l_old_header_rec.blanket_number IS NULL OR
813              l_old_header_rec.blanket_number = FND_API.G_MISS_NUM ) AND
814             g_header_rec.sold_to_org_id IS NOT NULL AND
815             g_header_rec.sold_to_org_id <> FND_API.G_MISS_NUM AND
816             (g_header_rec.cust_po_number IS NOT NULL AND
817              g_header_rec.cust_po_number <> FND_API.G_MISS_CHAR
818              -- Re-default blanket number only if cust PO
819              -- OR customer is updated
820              AND (NOT OE_GLOBALS.EQUAL(g_header_rec.cust_po_number
821                                       ,l_old_header_rec.cust_po_number)
822                   OR NOT OE_GLOBALS.EQUAL(g_header_rec.sold_to_org_id
823                                       ,l_old_header_rec.sold_to_org_id))
824              )
825         THEN
826 
827            l_blanket_number := Default_Blanket_Number(
828                                     g_header_rec.sold_to_org_id,
829                                     g_header_rec.request_date,
830                                     g_header_rec.cust_po_number);
831 
832            IF l_blanket_number IS NOT NULL THEN
833               Clear_And_Re_Default
834                  (p_blanket_number        => l_blanket_number
835                  ,p_x_header_rec          => g_header_rec
836                  ,p_old_header_rec        => l_old_header_rec
837                  ,p_default_record        => 'N'
838                  );
839            END IF;
840 
841         END IF;
842 
843       END IF;
844       --END Blankets Code Merge
845 
846      --  call the default handler framework to default the missing attributes
847 	IF l_debug_level  > 0 THEN
848 	    oe_debug_pub.add(  'CALLING ONT_HEADER_DEF_HDLR.DEFAULT_RECORD ' ) ;
849 	END IF;
850 	l_record	:= g_header_rec;
851 
852         -- add the code below to populate party_type if pay now is enabled and
853     -- there exists any defaulting condition template using party_type.
854     -- the check here is to avoid performace overhead, so that party_type
855     -- information is only loaded when needed.
856     IF OE_Prepayment_Util.Get_Installment_Options = 'ENABLE_PAY_NOW'
857     AND g_header_rec.sold_to_org_id IS NOT NULL
858     AND g_header_rec.sold_to_org_id <> FND_API.G_MISS_NUM
859     THEN
860       BEGIN
861         SELECT 'Y'
862         INTO   l_exists
863         FROM   oe_def_condn_elems
864         WHERE  value_string = 'ORGANIZATION'
865         AND    attribute_code = 'PARTY_TYPE'
866         AND    rownum = 1;
867       EXCEPTION WHEN NO_DATA_FOUND THEN
868         null;
869       END;
870 
871       IF l_exists = 'Y' THEN
872         BEGIN
873           SELECT party.party_type
874           INTO   l_party_type
875           FROM   hz_cust_accounts cust_acct,
876                  hz_parties party
877           WHERE  party.party_id = cust_acct.party_id
878           AND    cust_acct.cust_account_id = g_header_rec.sold_to_org_id;
879         EXCEPTION WHEN NO_DATA_FOUND THEN
880           null;
881         END;
882 
883         l_record.party_type := l_party_type;
884         g_header_rec.party_type := l_party_type;
885         l_old_header_rec.party_type := l_party_type;
886 
887         IF l_debug_level > 0 then
888            oe_debug_pub.add('party type in defaulting is: '||l_party_type, 3);
889         END IF;
890       END IF;
891     END IF;
892 
893         ONT_HEADER_Def_Hdlr.Default_Record
894 		(p_x_rec	        => l_record
895 		, p_initial_rec	        => g_header_rec
896 		, p_in_old_rec		=> l_old_header_rec
897 		, p_iteration		=> p_iteration
898 		);
899 	IF l_debug_level  > 0 THEN
900 	    oe_debug_pub.add(  'RETURNING FROM ONT_HEADER_DEF_HDLR.DEFAULT_RECORD ' ) ;
901 	END IF;
902 
903       --BEGIN Blankets Code Merge
904       --Blanket Header Hardcoded Defaulting
905       --defaults blanket_number based on sold_to_org and customer_po:
906       IF OE_CODE_CONTROL.Get_Code_Release_Level >= '110509' THEN
907 
908         IF l_record.cust_po_number IS NOT NULL
909            AND l_record.blanket_number IS NULL
910             -- Re-default only if old record does not have a blanket
911             -- value either, as defaulting should not over-ride
912             -- existing blanket value.
913            AND (l_old_header_rec.blanket_number IS NULL OR
914                 l_old_header_rec.blanket_number = FND_API.G_MISS_NUM )
915            AND l_record.sold_to_org_id IS NOT NULL
916            AND NOT OE_GLOBALS.EQUAL(l_record.cust_po_number
917                                     ,g_header_rec.cust_po_number)
918         THEN
919 
920            if l_debug_level > 0 then
921               oe_debug_pub.add('cust po changed and blkt num is null');
922            end if;
923 
924            l_blanket_number := Default_Blanket_Number(
925                                     l_record.sold_to_org_id,
926                                     l_record.request_date,
927                                     l_record.cust_po_number);
928 
929            IF l_blanket_number IS NOT NULL THEN
930               Clear_And_Re_Default
931                  (p_blanket_number        => l_blanket_number
932                  ,p_x_header_rec          => l_record
933                  ,p_old_header_rec        => l_old_header_rec
934                  ,p_default_record        => 'Y'
935                  );
936            END IF;
937 
938          END IF;
939 
940       END IF;
941       --END Blankets Code Merge
942 
943      --  copy the data back to a format that is compatible with the API architecture
944      OE_Header_UTIL.RowType_Rec_to_API_Rec
945 			(p_record	=> l_record
946 			,x_api_rec => p_x_header_rec);
947 
948         IF p_x_header_rec.blanket_number = FND_API.G_MISS_NUM THEN
949            p_x_header_rec.blanket_number := NULL;
950         END IF;
951 --End Blankets Code Merge
952 
953      IF l_debug_level  > 0 THEN
954          oe_debug_pub.add(  'ENTER DEFAULT CATEGORY'|| P_X_HEADER_REC.ORDER_TYPE_ID ) ;
955      END IF;
956      IF l_debug_level  > 0 THEN
957          oe_debug_pub.add(  'ENTER DEFAULT CATEGORY'|| P_X_HEADER_REC.ORDER_CATEGORY_CODE ) ;
958      END IF;
959      IF (p_x_header_rec.order_category_code  = FND_API.G_MISS_CHAR OR
960 		 p_x_header_rec.order_category_code  IS NULL) THEN
961 
962         IF (p_x_header_rec.order_type_id  <> FND_API.G_MISS_NUM AND
963             p_x_header_rec.order_type_id  IS NOT NULL )THEN
964           	p_x_header_rec.order_category_code :=
965 			Get_order_category(p_x_header_rec,
966 					    		p_old_header_rec);
967         END IF;
968 
969      END IF;
970 
971    /* Get Contract template */
972     IF OE_CODE_CONTROL.Get_Code_Release_Level >= '110510'
973        AND p_x_header_rec.order_type_id IS NOT NULL
974        AND p_x_header_rec.order_type_id  <> FND_API.G_MISS_NUM
975        AND  p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
976        AND OE_Contracts_util.check_license = 'Y'
977     THEN
978        p_x_header_rec.contract_template_id :=
979 	 Get_contract_template_id(p_x_header_rec,
980 				  p_old_header_rec);
981     END IF;
982 
983      -- Get customer preferece
984 	IF (l_cust_pref_set_code <> FND_API.G_MISS_CHAR AND
985 	     l_cust_pref_set_code IS NOT NULL) THEN
986 	p_x_header_rec.customer_preference_set_code := l_cust_pref_set_code;
987 	END IF;
988 IF l_debug_level  > 0 THEN
989     oe_debug_pub.add(  'SET CODE'|| P_X_HEADER_REC.CUSTOMER_PREFERENCE_SET_CODE , 1 ) ;
990 END IF;
991 
992       IF OE_CODE_CONTROL.CODE_RELEASE_LEVEL <= '110509' THEN
993 	p_x_header_rec.customer_preference_set_code
994 		:= get_customer_preference_set(p_header_rec => p_x_header_rec,
995 								p_old_header_rec => p_old_header_rec);
996       END IF;
997 
998 IF l_debug_level  > 0 THEN
999     oe_debug_pub.add(  'AFTER SET CODE'|| P_X_HEADER_REC.CUSTOMER_PREFERENCE_SET_CODE , 1 ) ;
1000 END IF;
1001 
1002      -- Assign the marketing_source_code_id value back to the out record. This
1003      -- done because the column in not enabled in the AK tables for defaulting.
1004 
1005      if p_x_header_rec.marketing_source_code_id = FND_API.G_MISS_NUM then
1006 	   p_x_header_rec.marketing_source_code_id := NULL;
1007      else
1008 	   p_x_header_rec.marketing_source_code_id := p_x_header_rec.marketing_source_code_id;
1009      end if;
1010 
1011 	p_x_header_rec.freight_carrier_code :=
1012           Get_Freight_Carrier(p_header_rec => p_x_header_rec,
1013                          p_old_header_rec => p_old_header_rec);
1014 
1015 
1016      IF l_debug_level  > 0 THEN
1017          oe_debug_pub.add(  'JPN: MARKETING SOURCE CODE IS:' || P_X_HEADER_REC.MARKETING_SOURCE_CODE_ID ) ;
1018      END IF;
1019 
1020      --If order currency is different than SOB currency and
1021      --fixed_rate is detected as Yes, then both of them are
1022      --Euro or Euro dependent currencies, so default the
1023      --conversion type to 'EMU FIXED'.
1024 
1025      l_set_of_books_rec :=  OE_Order_Cache.Load_Set_Of_Books;
1026 
1027      IF p_x_header_rec.transactional_curr_code <> l_set_of_books_rec.currency_code
1028      THEN
1029 
1030         IF l_debug_level  > 0 THEN
1031             oe_debug_pub.add(  'WHEN CURR CODE IS NOT SAME' ) ;
1032         END IF;
1033 	   l_Is_Fixed_Rate :=
1034 	      GL_CURRENCY_API.IS_FIXED_RATE(
1035 						 p_x_header_rec.transactional_curr_code,
1036 						 l_set_of_books_rec.currency_code,
1037 						 Nvl(p_x_header_rec.Ordered_Date,Sysdate));
1038 
1039 	   IF  (L_Is_Fixed_Rate = 'Y')
1040 	-- AND (p_x_header_rec.Conversion_Type_Code <> 'EMU FIXED')
1041 	   THEN
1042 
1043 	      p_x_header_rec.Conversion_Type_Code := 'EMU FIXED';
1044 
1045         END IF;
1046 
1047       END IF;
1048 
1049      /* 1581620 start */
1050 
1051      IF (p_x_header_rec.tp_context  = FND_API.G_MISS_CHAR) THEN
1052 	   p_x_header_rec.tp_context := NULL;
1053 	END IF;
1054      IF (p_x_header_rec.tp_attribute1  = FND_API.G_MISS_CHAR) THEN
1055 	   p_x_header_rec.tp_attribute1 := NULL;
1056 	END IF;
1057 
1058      IF (p_x_header_rec.tp_attribute2  = FND_API.G_MISS_CHAR) THEN
1059 	   p_x_header_rec.tp_attribute2 := NULL;
1060 	END IF;
1061 
1062      IF (p_x_header_rec.tp_attribute3  = FND_API.G_MISS_CHAR) THEN
1063 	   p_x_header_rec.tp_attribute3 := NULL;
1064 	END IF;
1065 
1066      IF (p_x_header_rec.tp_attribute4  = FND_API.G_MISS_CHAR) THEN
1067 	   p_x_header_rec.tp_attribute4 := NULL;
1068 	END IF;
1069 
1070      IF (p_x_header_rec.tp_attribute5  = FND_API.G_MISS_CHAR) THEN
1071 	   p_x_header_rec.tp_attribute5 := NULL;
1072 	END IF;
1073 
1074      IF (p_x_header_rec.tp_attribute6  = FND_API.G_MISS_CHAR) THEN
1075 	   p_x_header_rec.tp_attribute6 := NULL;
1076 	END IF;
1077 
1078      IF (p_x_header_rec.tp_attribute7  = FND_API.G_MISS_CHAR) THEN
1079 	   p_x_header_rec.tp_attribute7 := NULL;
1080 	END IF;
1081 
1082      IF (p_x_header_rec.tp_attribute8  = FND_API.G_MISS_CHAR) THEN
1083 	   p_x_header_rec.tp_attribute8 := NULL;
1084 	END IF;
1085 
1086      IF (p_x_header_rec.tp_attribute9  = FND_API.G_MISS_CHAR) THEN
1087 	   p_x_header_rec.tp_attribute9 := NULL;
1088 	END IF;
1089 
1090      IF (p_x_header_rec.tp_attribute10  = FND_API.G_MISS_CHAR) THEN
1091 	   p_x_header_rec.tp_attribute10 := NULL;
1092 	END IF;
1093 
1094      IF (p_x_header_rec.tp_attribute11  = FND_API.G_MISS_CHAR) THEN
1095 	   p_x_header_rec.tp_attribute11 := NULL;
1096 	END IF;
1097 
1098      IF (p_x_header_rec.tp_attribute12  = FND_API.G_MISS_CHAR) THEN
1099 	   p_x_header_rec.tp_attribute12 := NULL;
1100 	END IF;
1101 
1102      IF (p_x_header_rec.tp_attribute13  = FND_API.G_MISS_CHAR) THEN
1103 	   p_x_header_rec.tp_attribute13 := NULL;
1104 	END IF;
1105 
1106      IF (p_x_header_rec.tp_attribute14  = FND_API.G_MISS_CHAR) THEN
1107 	   p_x_header_rec.tp_attribute14 := NULL;
1108 	END IF;
1109 
1110      IF (p_x_header_rec.tp_attribute15  = FND_API.G_MISS_CHAR) THEN
1111 	   p_x_header_rec.tp_attribute15 := NULL;
1112 	END IF;
1113 --Distributor Orders
1114 	IF (p_x_header_rec.IB_OWNER  = FND_API.G_MISS_CHAR) THEN
1115 	   p_x_header_rec.IB_OWNER := NULL;
1116 	END IF;
1117 	IF (p_x_header_rec.IB_INSTALLED_AT_LOCATION  = FND_API.G_MISS_CHAR) THEN
1118 	   p_x_header_rec.IB_INSTALLED_AT_LOCATION := NULL;
1119 	END IF;
1120 	IF (p_x_header_rec.IB_CURRENT_LOCATION  = FND_API.G_MISS_CHAR) THEN
1121 	   p_x_header_rec.IB_CURRENT_LOCATION := NULL;
1122 	END IF;
1123       IF (p_x_header_rec.END_CUSTOMER_ID  = FND_API.G_MISS_NUM) THEN
1124 	   p_x_header_rec.END_CUSTOMER_ID := NULL;
1125 	END IF;
1126       IF (p_x_header_rec.END_CUSTOMER_SITE_USE_ID  = FND_API.G_MISS_NUM) THEN
1127 	   p_x_header_rec.END_CUSTOMER_SITE_USE_ID := NULL;
1128 	END IF;
1129       IF (p_x_header_rec.END_CUSTOMER_CONTACT_ID  = FND_API.G_MISS_NUM) THEN
1130 	   p_x_header_rec.END_CUSTOMER_CONTACT_ID := NULL;
1131 	END IF;
1132 --
1133 	IF (p_x_header_rec.Contract_template_id  = FND_API.G_MISS_NUM) THEN
1134 	   p_x_header_rec.contract_template_id := NULL;
1135 	END IF;
1136 
1137      IF (p_x_header_rec.customer_preference_set_code  = FND_API.G_MISS_CHAR) THEN
1138 	   p_x_header_rec.customer_preference_set_code := NULL;
1139 	END IF;
1140 
1141      IF (p_x_header_rec.credit_card_approval_date  = FND_API.G_MISS_DATE) THEN
1142 	   p_x_header_rec.credit_card_approval_date := NULL;
1143 	END IF;
1144 
1145      IF (p_x_header_rec.flow_status_code  = FND_API.G_MISS_CHAR) THEN
1146 	   p_x_header_rec.flow_status_code := NULL;
1147 	END IF;
1148 
1149      IF (p_x_header_rec.customer_payment_term_id  = FND_API.G_MISS_NUM) THEN
1150 	   p_x_header_rec.customer_payment_term_id := NULL;
1151 	END IF;
1152 
1153      IF (p_x_header_rec.drop_ship_flag  = FND_API.G_MISS_CHAR) THEN
1154 	   p_x_header_rec.drop_ship_flag := NULL;
1155 	END IF;
1156 
1157      IF (p_x_header_rec.change_sequence  = FND_API.G_MISS_CHAR) THEN
1158 	   p_x_header_rec.change_sequence := NULL;
1159 	END IF;
1160 
1161      IF (p_x_header_rec.lock_control  = FND_API.G_MISS_NUM) THEN
1162 	   p_x_header_rec.lock_control := NULL;
1163      END IF;
1164 
1165      IF (p_x_header_rec.sold_to_phone_id  = FND_API.G_MISS_NUM) THEN
1166            p_x_header_rec.sold_to_phone_id := NULL;
1167      END IF;
1168 
1169      IF (p_x_header_rec.contract_source_doc_type_code  = FND_API.G_MISS_CHAR) THEN
1170            p_x_header_rec.contract_source_doc_type_code := NULL;
1171      END IF;
1172 
1173      IF (p_x_header_rec.contract_source_document_id  = FND_API.G_MISS_NUM) THEN
1174            p_x_header_rec.contract_source_document_id := NULL;
1175      END IF;
1176 
1177 
1178      /* 1581620 end */
1179 
1180 
1181     -- Bug # 5490345
1182 
1183     IF (p_x_header_rec.minisite_id  = FND_API.G_MISS_NUM) THEN
1184            p_x_header_rec.minisite_id := NULL;
1185     END IF;
1186 
1187      -- QUOTING changes
1188 
1189      IF l_debug_level > 0 THEN
1190         oe_debug_pub.add('Transaction phase after defaulting fwk :'
1191               ||p_x_header_rec.transaction_phase_code);
1192      END IF;
1193 
1194      IF oe_code_control.code_release_level >= '110510' THEN
1195 
1196         IF p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE THEN
1197 
1198            IF p_x_header_rec.transaction_phase_code is null then
1199               p_x_header_rec.transaction_phase_code := 'F';
1200            ELSIF p_x_header_rec.transaction_phase_code = 'N' THEN
1201               p_x_header_rec.ordered_date := null;
1202               -- Default initial flow status to 'Draft' for negotiation orders
1203               IF p_x_header_rec.flow_status_code = 'ENTERED' OR
1204                  p_x_header_rec.flow_status_code = FND_API.G_MISS_CHAR
1205               THEN
1206                  p_x_header_rec.flow_status_code := 'DRAFT';
1207               END IF;
1208  -- bug 3854887
1209           ELSIF p_x_header_rec.transaction_phase_code = 'F' THEN
1210               p_x_header_rec.quote_date := null;
1211               -- Default initial flow status to 'Entered' for fulfillment orders
1212               IF p_x_header_rec.flow_status_code = 'DRAFT' OR
1213                  p_x_header_rec.flow_status_code = FND_API.G_MISS_CHAR
1214               THEN
1215                  p_x_header_rec.flow_status_code := 'ENTERED';
1216               END IF;
1217            END IF;
1218 
1219 	END IF;
1220 
1221 	-- If expiration date is changing, update time component to midnight
1222         -- i.e. to 23:59:59
1223         IF NOT OE_GLOBALS.EQUAL(p_x_header_rec.expiration_date
1224                            ,p_old_header_rec.expiration_date)
1225 	THEN
1226 	   p_x_header_rec.expiration_date :=
1227 	        trunc(p_x_header_rec.expiration_date,'DD') +
1228                                           ((24*60*60)-1)/(24*60*60);
1229 	END IF;
1230 
1231      END IF;
1232 
1233      IF l_debug_level > 0 THEN
1234         oe_debug_pub.add('Transaction phase at end :'
1235               ||p_x_header_rec.transaction_phase_code);
1236      END IF;
1237 
1238      -- QUOTING changes END
1239      IF OE_CODE_CONTROL.Get_Code_Release_Level >= '110510' THEN
1240         -- bug 3417786
1241         IF (nvl(p_x_header_rec.xml_message_id, FND_API.G_MISS_NUM)= FND_API.G_MISS_NUM AND
1242            p_x_header_rec.order_source_id = 0) THEN
1243                p_x_header_rec.xml_message_id := Get_EM_Message_Id;
1244         END IF;
1245      END IF;
1246 
1247 	IF l_debug_level  > 0 THEN
1248 	    oe_debug_pub.add(  'EXIT OE_DEFAULT_HEADER.ATTRIBUTES' ) ;
1249 	END IF;
1250 
1251 EXCEPTION
1252 
1253     WHEN FND_API.G_EXC_ERROR THEN
1254 
1255       RAISE FND_API.G_EXC_ERROR;
1256 
1257     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1258 
1259       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1260 
1261     WHEN OTHERS THEN
1262 
1263     	IF OE_MSG_PUB.Check_Msg_Level (OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
1264 	THEN
1265     	    OE_MSG_PUB.Add_Exc_Msg
1266     	    ( G_PKG_NAME,
1267     	      'Attributes'
1268 	    );
1269     	END IF;
1270 
1271 	RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1272 
1273 END Attributes;
1274 
1275 END OE_Default_Header  ;