[Home] [Help]
PACKAGE BODY: APPS.OZF_SD_REQUEST_PUB
Source
1 PACKAGE BODY OZF_SD_REQUEST_PUB AS
2 /* $Header: ozfpsdrb.pls 120.47.12020000.2 2012/11/20 09:17:24 annsrini ship $ */
3
4 G_PKG_NAME CONSTANT VARCHAR2(30):= 'OZF_SD_REQUEST_PUB';
5 G_FILE_NAME CONSTANT VARCHAR2(14) := 'ozfpsdrb.pls';
6 G_DEBUG BOOLEAN := FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_debug_high);
7 G_ITEM_ORG_ID NUMBER;
8 G_REQUEST_HEADER_ID NUMBER;
9
10 CURSOR c_currency(p_currency_code IN VARCHAR2) IS
11 SELECT currency_code
12 FROM fnd_currencies
13 WHERE currency_code = p_currency_code
14 AND enabled_flag='Y';
15
16 -----------------------------------------------------------------------
17 -- PROCEDURE
18 -- raise_stat_change_business_event
19 --
20 -- HISTORY
21 --
22 -----------------------------------------------------------------------
23 PROCEDURE raise_status_business_event(
24 p_request_header_id IN NUMBER
25 ,p_from_status IN VARCHAR2
26 ,p_to_status IN VARCHAR2)
27 IS
28
29 l_item_key VARCHAR2(30);
30 l_event_name VARCHAR2(80);
31 l_parameter_list wf_parameter_list_t;
32
33 BEGIN
34 l_item_key := p_request_header_id ||'SD_STAT'|| TO_CHAR(SYSDATE,'DDMMRRRRHH24MISS');
35 l_parameter_list := WF_PARAMETER_LIST_T();
36
37 l_event_name := 'oracle.apps.ozf.sd.request.statuschange';
38
39 IF G_DEBUG THEN
40 ozf_utility_pvt.debug_message(' Request Header Id :'||p_request_header_id );
41 END IF;
42
43 wf_event.AddParameterToList(p_name => 'OZF_SDR_HEADER_ID',
44 p_value => p_request_header_id,
45 p_parameterlist => l_parameter_list);
46
47 wf_event.AddParameterToList(p_name => 'OZF_SDR_FROM_STATUS',
48 p_value => p_from_status,
49 p_parameterlist => l_parameter_list);
50
51 wf_event.AddParameterToList(p_name => 'OZF_SDR_TO_STATUS',
52 p_value => p_to_status,
53 p_parameterlist => l_parameter_list);
54
55 IF G_DEBUG THEN
56 ozf_utility_pvt.debug_message('Item Key is :'||l_item_key);
57 END IF;
58
59 wf_event.raise( p_event_name =>l_event_name,
60 p_event_key => l_item_key,
61 p_parameters => l_parameter_list);
62
63 EXCEPTION
64 WHEN OTHERS THEN
65 RAISE Fnd_Api.g_exc_error;
66 IF G_DEBUG THEN
67 ozf_utility_pvt.debug_message('Exception in raising business event');
68 END IF;
69
70 END;
71
72
73 -----------------------------------------------------------------------
74 -- PROCEDURE
75 -- raise_XMLGateway_business_event
76 --
77 -- HISTORY
78 --
79 -----------------------------------------------------------------------
80 PROCEDURE raise_XML_business_event(
81 p_request_header_id IN NUMBER
82 ,p_supplier_id IN NUMBER
83 ,p_supplier_site_id IN NUMBER)
84 IS
85
86 l_item_key VARCHAR2(30);
87 l_event_name VARCHAR2(80);
88 l_parameter_list wf_parameter_list_t;
89
90 BEGIN
91 l_item_key := p_request_header_id ||'SD_XML'|| TO_CHAR(SYSDATE,'DDMMRRRRHH24MISS');
92 l_parameter_list := WF_PARAMETER_LIST_T();
93
94 l_event_name := 'oracle.apps.ozf.sd.request.outbound';
95
96 IF G_DEBUG THEN
97 ozf_utility_pvt.debug_message(' Request Header Id :'||p_request_header_id );
98 END IF;
99
100 wf_event.AddParameterToList(p_name => 'ECX_MAP_CODE',
101 p_value => 'OZF_SD_REQ_OUT',
102 p_parameterlist => l_parameter_list);
103
104 wf_event.AddParameterToList(p_name => 'ECX_PARTY_ID',
105 p_value => p_supplier_id,
106 p_parameterlist => l_parameter_list);
107
108 wf_event.AddParameterToList(p_name => 'ECX_PARTY_SITE_ID',
109 p_value => p_supplier_site_id,
110 p_parameterlist => l_parameter_list);
111
112 wf_event.AddParameterToList(p_name => 'ECX_PARTY_TYPE',
113 p_value => 'S',
114 p_parameterlist => l_parameter_list);
115
116 wf_event.AddParameterToList(p_name => 'ECX_DOCUMENT_ID',
117 p_value => p_request_header_id,
118 p_parameterlist => l_parameter_list);
119
120 wf_event.AddParameterToList(p_name => 'ECX_TRANSACTION_TYPE',
121 p_value => 'OZF',
122 p_parameterlist => l_parameter_list);
123
124 wf_event.AddParameterToList(p_name => 'ECX_TRANSACTION_SUBTYPE',
125 p_value => 'SDRO',
126 p_parameterlist => l_parameter_list);
127
128 wf_event.AddParameterToList(p_name => 'ECX_PARAMETER1',
129 p_value => NULL,
130 p_parameterlist => l_parameter_list);
131
132 wf_event.AddParameterToList(p_name => 'ECX_PARAMETER2',
133 p_value => NULL,
134 p_parameterlist => l_parameter_list);
135
136 wf_event.AddParameterToList(p_name => 'ECX_PARAMETER3',
137 p_value => NULL,
138 p_parameterlist => l_parameter_list);
139
140 wf_event.AddParameterToList(p_name => 'ECX_PARAMETER4',
141 p_value => NULL,
142 p_parameterlist => l_parameter_list);
143
144 wf_event.AddParameterToList(p_name => 'ECX_PARAMETER5',
145 p_value => NULL,
146 p_parameterlist => l_parameter_list);
147
148 wf_event.AddParameterToList(p_name => 'ECX_DEBUG_LEVEL',
149 p_value => 3,
150 p_parameterlist => l_parameter_list);
151
152 IF G_DEBUG THEN
153 ozf_utility_pvt.debug_message('Item Key is :'||l_item_key);
154 END IF;
155
156 wf_event.raise( p_event_name =>l_event_name,
157 p_event_key => l_item_key,
158 p_parameters => l_parameter_list);
159
160 EXCEPTION
161 WHEN OTHERS THEN
162 RAISE Fnd_Api.g_exc_error;
163 IF G_DEBUG THEN
164 ozf_utility_pvt.debug_message('Exception in raising XML Gateway business event');
165 END IF;
166 END;
167
168 ---------------------------------------------------------------------
169 -- FUNCTION
170 -- check_zero
171 --
172 -- PURPOSE
173 --
174 --Parameters
175 ---------------------------------------------------------------------
176 FUNCTION check_zero(p_value IN NUMBER)
177 RETURN VARCHAR2
178 IS
179 BEGIN
180 IF p_value <= 0 THEN
181 RETURN FND_API.g_false;
182 ELSE
183 RETURN FND_API.g_true;
184 END IF;
185 END check_zero;
186 -----------------------------------------------------------------------
187 -- FUNCTION
188 -- get_user_status_id
189 --
190 -- HISTORY
191
192 -----------------------------------------------------------------------
193 FUNCTION get_user_status_id(
194 p_system_status_code IN VARCHAR2
195 )
196 RETURN NUMBER
197 IS
198 l_user_status_id NUMBER;
199
200 CURSOR c_user_status_id IS
201 SELECT user_status_id
202 FROM ams_user_statuses_b
203 WHERE system_status_type ='OZF_SD_REQUEST_STATUS'
204 AND enabled_flag ='Y'
205 AND default_flag ='Y'
206 AND system_status_code = p_system_status_code;
207
208 BEGIN
209
210 OPEN c_user_status_id;
211 FETCH c_user_status_id INTO l_user_status_id;
212 CLOSE c_user_status_id;
213
214 RETURN l_user_status_id;
215
216 END get_user_status_id;
217
218 ---------------------------------------------------------------------
219 -- FUNCTION
220 -- get_system_status_code
221 --
222 -- PURPOSE
223
224 ---------------------------------------------------------------------
225 FUNCTION get_system_status_code(
226 p_user_status_id IN NUMBER
227 )
228 RETURN VARCHAR2
229 IS
230 l_system_status_code VARCHAR2(30);
231
232 CURSOR c_system_status_code IS
233 SELECT system_status_code
234 FROM ams_user_statuses_b
235 WHERE system_status_type ='OZF_SD_REQUEST_STATUS'
236 AND enabled_flag ='Y'
237 AND user_status_id = p_user_status_id ;
238
239 BEGIN
240
241 OPEN c_system_status_code;
242 FETCH c_system_status_code INTO l_system_status_code;
243 CLOSE c_system_status_code;
244
245 RETURN l_system_status_code;
246
247 END get_system_status_code;
248
249 ---------------------------------------------------------------------
250 -- FUNCTION
251 -- check_status_transition
252 --
253 -- PURPOSE
254 ---------------------------------------------------------------------
255
256 FUNCTION check_status_transition(
257 p_from_status IN VARCHAR2,
258 p_to_status IN VARCHAR2,
259 p_owner_flag IN VARCHAR2,
260 p_pm_flag IN VARCHAR2,
261 p_internal_flag IN VARCHAR2,
262 p_external_flag IN VARCHAR2)
263 RETURN VARCHAR2
264 IS
265 l_owner_count NUMBER :=0;
266 l_pm_count NUMBER :=0;
267 l_owner_pm_count NUMBER :=0;
268
269 CURSOR c_external_transition (p_cur_owner_flag IN VARCHAR2,p_cur_pm_flag IN VARCHAR2) IS
270 SELECT COUNT(1)
271 FROM ozf_sd_status_transitions
272 WHERE enabled_flag ='Y'
273 AND from_status = p_from_status
274 AND to_status = p_to_status
275 AND NVL(owner_flag,'N') = p_cur_owner_flag
276 AND NVL(product_manager_flag,'N') = p_cur_pm_flag
277 AND external_flag = p_external_flag
278 AND system_flag IS NULL;
279
280 CURSOR c_internal_transition (p_cur_owner_flag IN VARCHAR2,p_cur_pm_flag IN VARCHAR2) IS
281 SELECT COUNT(1)
282 FROM ozf_sd_status_transitions
283 WHERE enabled_flag ='Y'
284 AND from_status = p_from_status
285 AND to_status = p_to_status
286 AND NVL(owner_flag,'N') = p_cur_owner_flag
287 AND NVL(product_manager_flag,'N') = p_cur_pm_flag
288 AND internal_flag = p_internal_flag
289 AND system_flag IS NULL;
290 BEGIN
291 IF p_external_flag ='Y' THEN
292
293 IF G_DEBUG THEN
294 OZF_UTILITY_PVT.debug_message('Checking status transitions for External Request');
295 END IF;
296
297 IF p_owner_flag ='Y' THEN
298
299 OPEN c_external_transition('Y','N');
300 FETCH c_external_transition INTO l_owner_count;
301 CLOSE c_external_transition;
302
303 IF G_DEBUG THEN
304 OZF_UTILITY_PVT.debug_message('l_owner_count :'||l_owner_count);
305 END IF;
306 END IF;
307
308 IF p_pm_flag ='Y' THEN
309
310 OPEN c_external_transition('N','Y');
311 FETCH c_external_transition INTO l_pm_count;
312 CLOSE c_external_transition;
313
314 IF G_DEBUG THEN
315 OZF_UTILITY_PVT.debug_message('l_pm_count :'||l_pm_count);
316 END IF;
317 END IF;
318
319 IF p_owner_flag ='Y' AND p_pm_flag ='Y' THEN
320 OPEN c_external_transition('Y','Y');
321 FETCH c_external_transition INTO l_owner_pm_count;
322 CLOSE c_external_transition;
323 END IF;
324
325 IF l_owner_count = 0 AND l_pm_count = 0 AND l_owner_pm_count= 0 THEN
326 RETURN FND_API.g_false;
327 ELSE
328 RETURN FND_API.g_true;
329 END IF;
330
331 ELSIF p_internal_flag ='Y' THEN
332
333 IF G_DEBUG THEN
334 OZF_UTILITY_PVT.debug_message('Checking status transitions for Internal Request');
335 END IF;
336
337 IF p_owner_flag ='Y' THEN
338
339 OPEN c_internal_transition('Y','N');
340 FETCH c_internal_transition INTO l_owner_count;
341 CLOSE c_internal_transition;
342
343 IF G_DEBUG THEN
344 OZF_UTILITY_PVT.debug_message('l_owner_count :'||l_owner_count);
345 END IF;
346 END IF;
347
348 IF p_pm_flag ='Y' THEN
349
350 OPEN c_internal_transition('N','Y');
351 FETCH c_internal_transition INTO l_pm_count;
352 CLOSE c_internal_transition;
353
354 IF G_DEBUG THEN
355 OZF_UTILITY_PVT.debug_message('l_pm_count :'||l_pm_count);
356 END IF;
357 END IF;
358
359 IF p_owner_flag ='Y' AND p_pm_flag ='Y' THEN
360 OPEN c_internal_transition('Y','Y');
361 FETCH c_internal_transition INTO l_owner_pm_count;
362 CLOSE c_internal_transition;
363 END IF;
364
365 IF l_owner_count = 0 AND l_pm_count = 0 AND l_owner_pm_count= 0 THEN
366 RETURN FND_API.g_false;
367 ELSE
368 RETURN FND_API.g_true;
369 END IF;
370
371 END IF;
372
373 END check_status_transition;
374 ---------------------------------------------------------------------
375 -- FUNCTION
376 -- validate_UOM
377 --
378 -- PURPOSE
379 -- Validate UOM for Product Lines
380 -- Added for bugfix 12620229
381 ---------------------------------------------------------------------
382 FUNCTION validate_UOM(p_item_type IN VARCHAR2
383 ,p_inventory_item_id IN NUMBER
384 ,p_category_id IN NUMBER
385 ,p_item_UOM IN VARCHAR2)
386 RETURN BOOLEAN
387 IS
388 l_uom_code VARCHAR2(30);
389 l_category_chk VARCHAR2(1);
390
391 --//Cursor for item UOM
392 CURSOR c_item_uom(p_item_uom IN VARCHAR2
393 ,p_inventory_item_id IN NUMBER
394 ,p_org_id IN NUMBER)IS
395 SELECT uom_code
396 FROM mtl_item_uoms_view
397 WHERE organization_id = p_org_id
398 AND inventory_item_id = p_inventory_item_id
399 AND uom_code = p_item_uom;
400
401 --//Cursor for Product Categories
402 CURSOR c_category_UOM_Y(p_parent_id IN NUMBER
403 ,p_org_id IN NUMBER
404 ,p_uom_code IN VARCHAR2) IS
405 SELECT DISTINCT a.uom_code
406 FROM mtl_item_uoms_view a,
407 (SELECT inventory_item_id
408 FROM mtl_item_categories
409 WHERE category_id IN(SELECT child_id
410 FROM eni_denorm_hierarchies
411 WHERE parent_id = p_parent_id
412 AND organization_id = p_org_id)) b
413 WHERE a.organization_id = p_org_id
414 AND a.inventory_item_id = b.inventory_item_id
415 AND a.uom_code = p_uom_code;
416
417 --Cursor for Product categories 2
418 CURSOR c_category_UOM_N(p_category_id IN NUMBER
419 ,p_org_id IN NUMBER
420 ,p_uom_code IN VARCHAR2) IS
421 SELECT MTLUOM2.uom_code
422 FROM mtl_units_of_measure_vl MTLUOM2
423 WHERE EXISTS
424 (SELECT /*+no_unnest*/ 1
425 FROM mtl_system_items_b MTLITM1,
426 mtl_uom_conversions MTLUCV
427 WHERE MTLUOM2.uom_code = MTLUCV.uom_code
428 AND MTLITM1.organization_id = p_org_id
429 AND MTLITM1.inventory_item_id IN
430 (SELECT inventory_item_id
431 FROM mtl_item_categories
432 WHERE category_id = p_category_id
433 AND organization_id = p_org_id
434 )
435 AND NVL( MTLUCV.DISABLE_DATE, TRUNC(SYSDATE) +1 ) > TRUNC(SYSDATE)
436 AND ( ( MTLITM1.ALLOWED_UNITS_LOOKUP_CODE IN (1, 3)
437 AND MTLUCV.INVENTORY_ITEM_ID = MTLITM1.INVENTORY_ITEM_ID
438 OR ( MTLUCV.INVENTORY_ITEM_ID = 0
439 AND MTLUOM2.BASE_UOM_FLAG = 'Y'
440 AND MTLUOM2.UOM_CLASS = MTLUCV.UOM_CLASS
441 AND MTLUCV.UOM_CLASS IN
442 (SELECT MTLPRI1.UOM_CLASS
443 FROM MTL_UNITS_OF_MEASURE MTLPRI1
444 WHERE MTLPRI1.UOM_CODE = MTLITM1.PRIMARY_UOM_CODE
445 ))
446 OR ( MTLUCV.INVENTORY_ITEM_ID = 0
447 AND MTLUCV.UOM_CODE IN
448 (SELECT MTLUCC1.TO_UOM_CODE
449 FROM MTL_UOM_CLASS_CONVERSIONS MTLUCC1
450 WHERE MTLUCC1.INVENTORY_ITEM_ID = MTLITM1.INVENTORY_ITEM_ID
451 AND NVL(MTLUCC1.DISABLE_DATE, TRUNC(SYSDATE)+1) > TRUNC(SYSDATE)
452 ) ) )
453 OR ( MTLITM1.ALLOWED_UNITS_LOOKUP_CODE IN (2, 3)
454 AND MTLUCV.INVENTORY_ITEM_ID = 0
455 AND ( MTLUCV.UOM_CLASS IN
456 (SELECT MTLUCC.TO_UOM_CLASS
457 FROM MTL_UOM_CLASS_CONVERSIONS MTLUCC
458 WHERE MTLUCC.INVENTORY_ITEM_ID = MTLITM1.INVENTORY_ITEM_ID
459 AND NVL(MTLUCC.DISABLE_DATE, TRUNC(SYSDATE)+1) > TRUNC(SYSDATE)
460 )
461 OR MTLUCV.UOM_CLASS =
462 (SELECT MTLPRI.UOM_CLASS
463 FROM MTL_UNITS_OF_MEASURE MTLPRI
464 WHERE MTLPRI.UOM_CODE = MTLITM1.PRIMARY_UOM_CODE
465 ) ) ) )
466 )
467 AND MTLUOM2.uom_code = p_uom_code;
468
469 --//Cursor for ALL ITEMS UOM
470 CURSOR c_all_items_UOM(p_uom_code IN VARCHAR2) IS
471 SELECT uom_code
472 FROM mtl_units_of_measure
473 WHERE uom_code = p_uom_code;
474
475 CURSOR c_category_chk (p_category_id IN NUMBER) IS
476 SELECT 'Y'
477 FROM dual
478 WHERE EXISTS(SELECT 1
479 FROM eni_denorm_hierarchies
480 WHERE parent_id = p_category_id);
481
482 BEGIN
483 l_uom_code := NULL;
484
485 IF p_item_type ='PRODUCT' THEN
486 OPEN c_item_UOM(p_item_UOM,p_inventory_item_id,G_ITEM_ORG_ID);
487 FETCH c_item_UOM INTO l_uom_code;
488 CLOSE c_item_UOM;
489
490 IF G_DEBUG THEN
491 OZF_UTILITY_PVT.debug_message('UOM Code for PRODUCT :'|| l_uom_code );
492 END IF;
493 ELSIF p_item_type = 'PRODUCT_CATEGORY' THEN
494 OPEN c_category_chk(p_category_id);
495 FETCH c_category_chk INTO l_category_chk;
496 CLOSE c_category_chk;
497
498 IF l_category_chk ='Y' THEN
499 OPEN c_category_UOM_Y(p_category_id,G_ITEM_ORG_ID,p_item_UOM);
500 FETCH c_category_UOM_Y INTO l_uom_code;
501 CLOSE c_category_UOM_Y;
502 ELSE
503 OPEN c_category_UOM_N(p_category_id,G_ITEM_ORG_ID,p_item_UOM);
504 FETCH c_category_UOM_N INTO l_uom_code;
505 CLOSE c_category_UOM_N;
506 END IF;
507 IF G_DEBUG THEN
508 OZF_UTILITY_PVT.debug_message('UOM Code for PRODUCT_CATEGORY :'|| l_uom_code );
509 END IF;
510
511 ELSIF p_item_type = 'ALL_ITEMS' THEN
512 OPEN c_all_items_UOM(p_item_UOM);
513 FETCH c_all_items_UOM INTO l_uom_code;
514 CLOSE c_all_items_UOM;
515
516 IF G_DEBUG THEN
517 OZF_UTILITY_PVT.debug_message('UOM Code for ALL_ITEMS :'|| l_uom_code );
518 END IF;
519 END IF;
520
521 IF l_uom_code IS NOT NULL THEN
522 IF G_DEBUG THEN
523 OZF_UTILITY_PVT.debug_message('Check_UOM Returns TRUE');
524 END IF;
525 RETURN TRUE;
526
527 ELSE
528 IF G_DEBUG THEN
529 OZF_UTILITY_PVT.debug_message('Check_UOM Returns TRUE');
530 END IF;
531 RETURN FALSE;
532 END IF;
533
534 END validate_UOM;
535
536 ---------------------------------------------------------------------
537 -- PROCEDURE
538 -- Validate_Header_items
539 --
540 -- PURPOSE
541 -- This procedure validates Header record
542 --Parameters
543 -- p_SDR_hdr_rec -Header Recordset
544 -- p_mode -Insert /Update Mode
545 -- x_return_status - Result
546 ---------------------------------------------------------------------
547 PROCEDURE validate_header_items(
548 p_SDR_hdr_rec IN OUT NOCOPY SDR_Hdr_rec_type
549 ,p_mode IN VARCHAR2
550 ,x_return_status OUT NOCOPY VARCHAR2
551 )
552 IS
553 l_lookup_stat VARCHAR2(1); --To validate from lookups
554 l_req_hdr_id_count NUMBER;
555 l_req_no_count NUMBER;
556 l_org_id NUMBER;
557 l_requestor_id NUMBER;
558 l_supplier_id NUMBER;
559 l_supplier_site_id NUMBER;
560 l_supplier_contact_id NUMBER;
561 l_supp_email VARCHAR2(2000);
562 l_supp_phone VARCHAR2(40);
563 l_cust_account_id NUMBER;
564 l_authorization_period NUMBER :=0;
565 l_currency_code VARCHAR2(30);
566 l_assignee_resource_id NUMBER;
567 l_sales_order_currency VARCHAR2(30);
568 l_user_id NUMBER;
569 l_system_status_code VARCHAR2(30);
570 l_internal_order_number NUMBER;
571 l_resource_id NUMBER;
572 l_sup_contact_full_name VARCHAR2(360) := NULL; --//Bugfix :7822442
573 l_stp_count NUMBER :=0; --//Bugfix : 9748413
574
575 CURSOR c_user(p_user_id IN NUMBER) IS
576 SELECT user_id
577 FROM fnd_user
578 WHERE user_id =p_user_id;
579
580 CURSOR c_org_id(p_org_id IN NUMBER)IS
581 SELECT ou.organization_id org_id
582 FROM hr_operating_units ou
583 WHERE MO_GLOBAL.check_access(ou.organization_id) = 'Y'
584 AND ou.organization_id =p_org_id;
585
586 CURSOR c_resource_id (p_user_id IN NUMBER) IS
587 SELECT resource_id
588 FROM jtf_rs_resource_extns
589 WHERE start_date_active <= sysdate
590 AND nvl(end_date_active,sysdate) >= sysdate
591 AND resource_id > 0
592 AND (category = 'EMPLOYEE' OR category = 'PARTNER' OR category = 'PARTY')
593 AND user_id = p_user_id;
594
595 CURSOR c_requestor_id (p_requestor_id IN NUMBER) IS
596 SELECT resource_id
597 FROM jtf_rs_resource_extns
598 WHERE start_date_active <= sysdate
599 AND nvl(end_date_active,sysdate) >= sysdate
600 AND resource_id > 0
601 AND (category = 'EMPLOYEE' OR category = 'PARTNER' OR category = 'PARTY')
602 AND resource_id = p_requestor_id;
603
604 CURSOR c_supp_id(p_supplier_id IN NUMBER) IS
605 SELECT vendor_id
606 FROM ap_suppliers
607 WHERE vendor_id = p_supplier_id;
608
609 CURSOR c_supplier_site_id(p_supplier_site_id IN NUMBER,
610 p_supplier_id IN NUMBER,
611 p_org_id IN NUMBER) IS
612 SELECT vendor_site_id
613 FROM ap_supplier_sites_all
614 WHERE vendor_site_id = p_supplier_site_id
615 AND vendor_id = p_supplier_id
616 AND org_id = p_org_id;
617
618 --//Bugfix : 9748413
619 CURSOR c_chk_stp_exists(p_supplier_id IN NUMBER,
620 p_supplier_site_id IN NUMBER,
621 p_org_id IN NUMBER) IS
622 SELECT COUNT(1)
623 FROM ozf_supp_trd_prfls_all
624 WHERE supplier_id = p_supplier_id
625 AND supplier_site_id = p_supplier_site_id
626 AND org_id = p_org_id;
627
628 --//Bugfix : 7822442
629 CURSOR c_sup_contacts(p_supplier_site_id IN NUMBER,
630 p_vendor_contact_id IN NUMBER) IS
631 SELECT apc.vendor_contact_id
632 ,apc.area_code||apc.phone phone_number
633 ,apc.email_address
634 ,decode(pvc.last_name,null,null,'','',pvc.last_name || ', ') || nvl(pvc.middle_name, '')|| ' '|| pvc.first_name AS Sup_contact_full_name
635 FROM ap_supplier_contacts apc,po_vendor_contacts pvc
636 WHERE apc.vendor_site_id = pvc.vendor_site_id
637 AND apc.vendor_contact_id = pvc.vendor_contact_id
638 AND NVL(pvc.inactive_date, SYSDATE +1) > SYSDATE
639 AND apc.vendor_site_id = p_supplier_site_id
640 AND apc.vendor_contact_id = p_vendor_contact_id;
641
642 /*
643 CURSOR c_currency(p_currency_code IN VARCHAR2) IS
644 SELECT currency_code
645 FROM fnd_currencies
646 WHERE currency_code = p_currency_code
647 AND enabled_flag='Y';
648 */
649 CURSOR c_cust_account_id(p_cust_account_id IN NUMBER) IS
650 SELECT cust_account_id
651 FROM hz_cust_accounts
652 WHERE status ='A'
653 AND customer_type ='I'
654 AND cust_account_id =p_cust_account_id;
655
656 CURSOR c_language_code(p_language_code IN VARCHAR2)IS
657 SELECT language_code
658 FROM fnd_languages
659 WHERE language_code =p_language_code;
660
661 CURSOR c_authorization_period(p_supplier_id IN NUMBER,
662 p_supplier_site_id IN NUMBER,
663 p_org_id IN NUMBER)IS
664 SELECT NVL(authorization_period,-1)
665 FROM ozf_supp_trd_prfls_all
666 WHERE supplier_id = p_supplier_id
667 AND supplier_site_id = p_supplier_site_id
668 AND org_id = p_org_id;
669
670 CURSOR c_request_header_id_count(p_request_header_id IN VARCHAR2)IS
671 SELECT COUNT(1)
672 FROM ozf_sd_request_headers_all_b
673 WHERE request_header_id = p_request_header_id;
674
675 CURSOR c_request_number_count(p_request_number IN VARCHAR2)IS
676 SELECT COUNT(1)
677 FROM ozf_sd_request_headers_all_b
678 WHERE request_number =p_request_number;
679
680 CURSOR c_system_status_code(p_user_status_id IN VARCHAR2)IS
681 SELECT system_status_code
682 FROM ams_user_statuses_b
683 WHERE system_status_type ='OZF_SD_REQUEST_STATUS'
684 AND user_status_id = p_user_status_id;
685
686 CURSOR c_order_no(p_internal_order_number IN NUMBER,p_org_id IN NUMBER)IS
687 SELECT order_number
688 FROM oe_order_headers_all
689 WHERE order_number = p_internal_order_number
690 AND org_id = p_org_id;
691
692 BEGIN
693 x_return_status := FND_API.G_RET_STS_SUCCESS;
694
695 --// User ID validation
696 IF p_SDR_hdr_rec.user_id <> FND_API.g_miss_num AND p_SDR_hdr_rec.user_id IS NOT NULL THEN
697 OPEN c_user(p_SDR_hdr_rec.user_id);
698 FETCH c_user INTO l_user_id;
699 CLOSE c_user;
700
701 IF l_user_id IS NULL THEN
702 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
703 FND_MESSAGE.set_name('OZF', 'OZF_SD_INVALID_USER_ID');
704 --//User Id is invalid, Please re-enter
705 FND_MSG_PUB.add;
706 END IF;
707 x_return_status := fnd_api.g_ret_sts_error;
708 RETURN;
709 ELSE --// Check if User is a valid resource or not
710 OPEN c_resource_id(p_SDR_hdr_rec.user_id);
711 FETCH c_resource_id INTO l_resource_id;
712 CLOSE c_resource_id;
713
714 IF l_resource_id IS NULL THEN
715 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
716 FND_MESSAGE.set_name('OZF', 'OZF_SD_USER_IS_NOT_RESOURCE');
717 FND_MSG_PUB.add;
718 END IF;
719 x_return_status := fnd_api.g_ret_sts_error;
720 RETURN;
721 END IF;
722 IF g_debug THEN
723 OZF_UTILITY_PVT.debug_message('l_resource_id of the user :'||l_resource_id);
724 END IF;
725 END IF;
726
727 ELSE
728 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
729 FND_MESSAGE.set_name('OZF', 'OZF_SD_NO_USER_ID');
730 --//User Id is Mandatory
731 FND_MSG_PUB.add;
732 END IF;
733 x_return_status := fnd_api.g_ret_sts_error;
734 RETURN;
735 END IF;
736
737 --// Organization id Validation
738 IF p_SDR_hdr_rec.org_id <> FND_API.g_miss_num AND p_SDR_hdr_rec.org_id IS NOT NULL THEN
739 OPEN c_org_id(p_SDR_hdr_rec.org_id);
740 FETCH c_org_id INTO l_org_id;
741 CLOSE c_org_id;
742
743 IF l_org_id IS NULL THEN
744 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
745 FND_MESSAGE.set_name('OZF', 'OZF_SD_INVALID_ORG_ID');
746 --//Organization id entered is invalid
747 FND_MSG_PUB.add;
748 END IF;
749 x_return_status := fnd_api.g_ret_sts_error;
750 RETURN;
751 END IF;
752 --//Set Org ID to Global Variable
753 -- G_ORG_ID := p_SDR_hdr_rec.org_id;
754 ELSE
755 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
756 FND_MESSAGE.set_name('OZF', 'OZF_SD_NO_ORG_ID');
757 --//Organization id is Mandatory
758 FND_MSG_PUB.add;
759 END IF;
760 x_return_status := fnd_api.g_ret_sts_error;
761 RETURN;
762 END IF;
763
764 --// Requestor ID Validation (owner)
765 IF p_SDR_hdr_rec.requestor_id <> FND_API.g_miss_num AND p_SDR_hdr_rec.requestor_id IS NOT NULL THEN
766 IF G_DEBUG THEN
767 OZF_UTILITY_PVT.debug_message('Requestor NOT NULL');
768 END IF;
769 OPEN c_requestor_id(p_SDR_hdr_rec.requestor_id);
770 FETCH c_requestor_id INTO l_requestor_id;
771 CLOSE c_requestor_id;
772
773 IF l_requestor_id IS NULL THEN
774 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
775 FND_MESSAGE.set_name('OZF', 'OZF_SD_INVALID_REQUESTOR_ID');
776 --//Requestor id entered is invalid
777 IF G_DEBUG THEN
778 OZF_UTILITY_PVT.debug_message('Requestor id entered is invalid');
779 END IF;
780 FND_MSG_PUB.add;
781 END IF;
782 x_return_status := fnd_api.g_ret_sts_error;
783 RETURN;
784 END IF;
785 ELSE
786 p_SDR_hdr_rec.requestor_id := l_resource_id;
787 IF G_DEBUG THEN
788 OZF_UTILITY_PVT.debug_message('l_resource_id :'||l_resource_id);
789 END IF;
790 END IF;
791
792 IF p_SDR_hdr_rec.accrual_type ='SUPPLIER' THEN
793 --//Supplier Validations
794 p_SDR_hdr_rec.cust_account_id := NULL;
795
796 --//Supplier ID
797 IF p_SDR_hdr_rec.supplier_id <> FND_API.g_miss_num AND p_SDR_hdr_rec.supplier_id IS NOT NULL THEN
798 OPEN c_supp_id(p_SDR_hdr_rec.supplier_id);
799 FETCH c_supp_id INTO l_supplier_id;
800 CLOSE c_supp_id;
801
802 IF l_supplier_id IS NULL THEN
803 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
804 FND_MESSAGE.set_name('OZF', 'OZF_SD_INVALID_SUPPLIER_ID');
805 --//Supplier id entered is invalid
806 FND_MSG_PUB.add;
807 END IF;
808 x_return_status := fnd_api.g_ret_sts_error;
809 RETURN;
810 END IF;
811
812 ELSE
813 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
814 FND_MESSAGE.set_name('OZF', 'OZF_SD_NO_SUPPLIER_ID');
815 --//Supplier id is Mandatory
816 FND_MSG_PUB.add;
817 END IF;
818 x_return_status := fnd_api.g_ret_sts_error;
819 RETURN;
820 END IF;
821
822 --//Supplier site ID
823 IF p_SDR_hdr_rec.supplier_site_id <> FND_API.g_miss_num AND p_SDR_hdr_rec.supplier_site_id IS NOT NULL THEN
824 OPEN c_supplier_site_id(p_SDR_hdr_rec.supplier_site_id
825 ,p_SDR_hdr_rec.supplier_id
826 ,p_SDR_hdr_rec.org_id);
827
828 FETCH c_supplier_site_id INTO l_supplier_site_id;
829 CLOSE c_supplier_site_id;
830
831 IF l_supplier_site_id IS NULL THEN
832 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
833 FND_MESSAGE.set_name('OZF', 'OZF_SD_INVALID_SUPP_SITE_ID');
834 --//Supplier site id entered is invalid
835 FND_MSG_PUB.add;
836 END IF;
837 x_return_status := fnd_api.g_ret_sts_error;
838 RETURN;
839 END IF;
840
841 ELSE
842 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
843 FND_MESSAGE.set_name('OZF', 'OZF_SD_NO_SUPP_SITE_ID');
844 --//Supplier site id is Mandatory
845 FND_MSG_PUB.add;
846 END IF;
847 x_return_status := fnd_api.g_ret_sts_error;
848 RETURN;
849 END IF;
850
851 --//Bugfix : 9748413
852 --//Supplier trade profile validation.
853 OPEN c_chk_stp_exists(p_SDR_hdr_rec.supplier_id
854 ,p_SDR_hdr_rec.supplier_site_id
855 ,p_SDR_hdr_rec.org_id);
856
857 FETCH c_chk_stp_exists INTO l_stp_count;
858 CLOSE c_chk_stp_exists;
859
860 IF l_stp_count = 0 THEN
861 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
862 FND_MESSAGE.set_name('OZF', 'OZF_SD_NO_SUP_TRD_PRFL');
863 --//Supplier site id entered is invalid
864 FND_MSG_PUB.add;
865 END IF;
866 x_return_status := fnd_api.g_ret_sts_error;
867 RETURN;
868 END IF;
869
870 --//Supplier Contact ID
871 --// Bugfix : 7822442
872 IF p_SDR_hdr_rec.supplier_contact_id <> FND_API.g_miss_num AND p_SDR_hdr_rec.supplier_contact_id IS NOT NULL THEN
873
874 OPEN c_sup_contacts(p_SDR_hdr_rec.supplier_site_id
875 ,p_SDR_hdr_rec.supplier_contact_id);
876
877 FETCH c_sup_contacts INTO l_supplier_contact_id,l_supp_email,l_supp_phone,l_sup_contact_full_name;
878 CLOSE c_sup_contacts;
879
880 IF l_supplier_contact_id IS NOT NULL THEN
881 p_SDR_hdr_rec.supplier_contact_name := l_sup_contact_full_name;
882 ELSE
883 IF p_SDR_hdr_rec.supplier_contact_name = FND_API.g_miss_char OR p_SDR_hdr_rec.supplier_contact_name IS NULL THEN
884 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
885 FND_MESSAGE.set_name('OZF', 'OZF_SD_INVALID_SUPP_CONTACT_ID');
886 --//Supplier contact id entered is invalid
887 FND_MSG_PUB.add;
888 END IF;
889 x_return_status := fnd_api.g_ret_sts_error;
890 RETURN;
891 ELSE
892 p_SDR_hdr_rec.supplier_contact_id := NULL;
893 END IF;
894 END IF;
895 END IF;
896
897 --Supplier Contact Info
898 IF p_SDR_hdr_rec.supplier_contact_email_address = FND_API.g_miss_char OR p_SDR_hdr_rec.supplier_contact_email_address IS NULL THEN
899 p_SDR_hdr_rec.supplier_contact_email_address :=l_supp_email;
900 END IF;
901 IF p_SDR_hdr_rec.supplier_contact_phone_number = FND_API.g_miss_char OR p_SDR_hdr_rec.supplier_contact_phone_number IS NULL THEN
902 p_SDR_hdr_rec.supplier_contact_phone_number :=l_supp_phone;
903 END IF;
904
905 --supplier_response_by_date --ninarasi fix for bug 12837291
906 /*IF p_SDR_hdr_rec.supplier_response_by_date <> FND_API.g_miss_date AND p_SDR_hdr_rec.supplier_response_by_date IS NOT NULL THEN
907 p_SDR_hdr_rec.supplier_response_by_date := TRUNC(p_SDR_hdr_rec.supplier_response_by_date);
908
909 IF p_SDR_hdr_rec.supplier_response_by_date NOT BETWEEN p_SDR_hdr_rec.request_start_date AND
910 p_SDR_hdr_rec.request_end_date THEN
911
912 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
913 FND_MESSAGE.set_name('OZF', 'OZF_SD_INVALID_SUPRESPB_DATE');
914 FND_MSG_PUB.add;
915 END IF;
916 x_return_status := fnd_api.g_ret_sts_error;
917 RETURN;
918 END IF;
919 END IF;*/
920
921 --supplier_response_date --ninarasi fix for bug 12837291
922 /* IF p_SDR_hdr_rec.supplier_response_date <> FND_API.g_miss_date AND p_SDR_hdr_rec.supplier_response_date IS NOT NULL THEN
923 p_SDR_hdr_rec.supplier_response_date := TRUNC(p_SDR_hdr_rec.supplier_response_date);
924
925 IF p_SDR_hdr_rec.supplier_response_date NOT BETWEEN p_SDR_hdr_rec.request_start_date AND
926 p_SDR_hdr_rec.request_end_date THEN
927
928 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
929 FND_MESSAGE.set_name('OZF', 'OZF_SD_INVALID_SUPRESP_DATE');
930 FND_MSG_PUB.add;
931 END IF;
932 x_return_status := fnd_api.g_ret_sts_error;
933 RETURN;
934 END IF;
935 END IF;*/
936
937 --supplier_submission_date --ninarasi fix for bug 12837291
938 /*IF p_SDR_hdr_rec.supplier_submission_date <> FND_API.g_miss_date AND p_SDR_hdr_rec.supplier_submission_date IS NOT NULL THEN
939 p_SDR_hdr_rec.supplier_submission_date := TRUNC(p_SDR_hdr_rec.supplier_submission_date);
940
941 IF p_SDR_hdr_rec.supplier_submission_date NOT BETWEEN p_SDR_hdr_rec.request_start_date AND
942 p_SDR_hdr_rec.request_end_date THEN
943
944 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
945 FND_MESSAGE.set_name('OZF', 'OZF_SD_INVALID_SUPSUB_DATE');
946 FND_MSG_PUB.add;
947 END IF;
948 x_return_status := fnd_api.g_ret_sts_error;
949 RETURN;
950 END IF;
951 END IF;*/
952
953 --//Validating Assignee Resource ID
954 l_system_status_code := get_system_status_code(p_SDR_hdr_rec.user_status_id);
955
956 IF G_DEBUG THEN
957 OZF_UTILITY_PVT.debug_message('Validating Assignee Resource ID');
958 END IF;
959
960 IF l_system_status_code <> 'DRAFT' THEN
961
962 IF G_DEBUG THEN
963 OZF_UTILITY_PVT.debug_message('Assignee resource_id ID :'||p_SDR_hdr_rec.assignee_resource_id);
964 END IF;
965
966 IF p_SDR_hdr_rec.assignee_resource_id <> FND_API.g_miss_num AND p_SDR_hdr_rec.assignee_resource_id IS NOT NULL THEN
967
968 OPEN c_requestor_id(p_SDR_hdr_rec.assignee_resource_id);
969 FETCH c_requestor_id INTO l_assignee_resource_id;
970 CLOSE c_requestor_id;
971
972 IF l_assignee_resource_id IS NULL THEN
973 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
974 FND_MESSAGE.set_name('OZF', 'OZF_SD_INVALID_ASSIGNEE_ID');
975 --//Assignee id entered is invalid (Approver)
976 FND_MSG_PUB.add;
977 END IF;
978 x_return_status := fnd_api.g_ret_sts_error;
979 RETURN;
980 END IF;
981 ELSE
982 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
983 FND_MESSAGE.set_name('OZF', 'OZF_SD_NO_ASSIGNEE_ID');
984 --//Assignee resource id is Mandatory (Approver is mandatory)
985 FND_MSG_PUB.add;
986 END IF;
987 x_return_status := fnd_api.g_ret_sts_error;
988 RETURN;
989 END IF;
990
991 --asignee_response_by_date --ninarasi fix for bug 12837291
992 /*IF p_SDR_hdr_rec.assignee_response_by_date <> FND_API.g_miss_date AND p_SDR_hdr_rec.assignee_response_by_date IS NOT NULL THEN
993 p_SDR_hdr_rec.assignee_response_by_date := TRUNC(p_SDR_hdr_rec.assignee_response_by_date);
994
995 IF p_SDR_hdr_rec.assignee_response_by_date NOT BETWEEN p_SDR_hdr_rec.request_start_date AND
996 p_SDR_hdr_rec.request_end_date THEN
997
998 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
999 FND_MESSAGE.set_name('OZF', 'OZF_SD_INVALID_ASRESPB_DATE');
1000 FND_MSG_PUB.add;
1001 END IF;
1002 x_return_status := fnd_api.g_ret_sts_error;
1003 RETURN;
1004 END IF;
1005 END IF;*/
1006
1007 --asignee_response_date --ninarasi fix for bug 12837291
1008 /*IF p_SDR_hdr_rec.assignee_response_date <> FND_API.g_miss_date AND p_SDR_hdr_rec.assignee_response_date IS NOT NULL THEN
1009 p_SDR_hdr_rec.assignee_response_date := TRUNC(p_SDR_hdr_rec.assignee_response_date);
1010
1011 IF p_SDR_hdr_rec.assignee_response_date NOT BETWEEN p_SDR_hdr_rec.request_start_date AND
1012 p_SDR_hdr_rec.request_end_date THEN
1013
1014 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
1015 FND_MESSAGE.set_name('OZF', 'OZF_SD_INVALID_ASRESP_DATE');
1016 FND_MSG_PUB.add;
1017 END IF;
1018 x_return_status := fnd_api.g_ret_sts_error;
1019 RETURN;
1020 END IF;
1021 END IF;*/
1022 ELSE
1023 p_SDR_hdr_rec.assignee_resource_id :=NULL;
1024 p_SDR_hdr_rec.assignee_response_by_date :=NULL;
1025 p_SDR_hdr_rec.assignee_response_date :=NULL;
1026
1027 END IF;
1028
1029 ELSIF p_SDR_hdr_rec.accrual_type ='INTERNAL' THEN
1030
1031 p_SDR_hdr_rec.supplier_id :=NULL;
1032 p_SDR_hdr_rec.supplier_site_id :=NULL;
1033 p_SDR_hdr_rec.supplier_contact_id :=NULL;
1034 p_SDR_hdr_rec.supplier_contact_phone_number :=NULL;
1035 p_SDR_hdr_rec.supplier_contact_email_address:=NULL;
1036 p_SDR_hdr_rec.supplier_response_by_date :=NULL;
1037 p_SDR_hdr_rec.supplier_response_date :=NULL;
1038 p_SDR_hdr_rec.supplier_submission_date :=NULL;
1039 p_SDR_hdr_rec.supplier_quote_number :=NULL;
1040 p_SDR_hdr_rec.assignee_resource_id :=NULL;
1041 p_SDR_hdr_rec.assignee_response_by_date :=NULL;
1042 p_SDR_hdr_rec.assignee_response_date :=NULL;
1043
1044
1045 IF p_SDR_hdr_rec.cust_account_id <> FND_API.g_miss_num AND p_SDR_hdr_rec.cust_account_id IS NOT NULL THEN
1046
1047 OPEN c_cust_account_id(p_SDR_hdr_rec.cust_account_id);
1048 FETCH c_cust_account_id INTO l_cust_account_id;
1049 CLOSE c_cust_account_id;
1050
1051 IF l_cust_account_id IS NULL THEN
1052 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
1053 FND_MESSAGE.set_name('OZF', 'OZF_SD_INVALID_CUST_ACCOUNT_ID');
1054 --//Cust Account ID entered is invalid
1055 FND_MSG_PUB.add;
1056 END IF;
1057 x_return_status := fnd_api.g_ret_sts_error;
1058 RETURN;
1059 END IF;
1060
1061 ELSE
1062 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
1063 FND_MESSAGE.set_name('OZF', 'OZF_SD_NO_CUST_ACCOUNT_ID');
1064 --//Cust Account id is Mandatory
1065 FND_MSG_PUB.add;
1066 END IF;
1067 x_return_status := fnd_api.g_ret_sts_error;
1068 RETURN;
1069 END IF;
1070 END IF;
1071
1072 --//Bugfix : 7607795 - Start Date/End date Validations
1073 IF p_SDR_hdr_rec.request_start_date <> FND_API.g_miss_date AND p_SDR_hdr_rec.request_start_date IS NOT NULL THEN
1074
1075 IF (p_SDR_hdr_rec.request_end_date = FND_API.g_miss_date OR p_SDR_hdr_rec.request_end_date IS NULL) AND p_mode = 'CREATE' THEN
1076 --//Generate End Date from Supplier trade profile
1077 OPEN c_authorization_period(p_SDR_hdr_rec.supplier_id
1078 ,p_SDR_hdr_rec.supplier_site_id
1079 ,p_SDR_hdr_rec.org_id);
1080
1081 FETCH c_authorization_period INTO l_authorization_period;
1082 CLOSE c_authorization_period;
1083
1084 IF l_authorization_period <> -1 THEN
1085 p_SDR_hdr_rec.request_end_date := p_SDR_hdr_rec.request_start_date + l_authorization_period;
1086 END IF;
1087
1088 ELSIF p_SDR_hdr_rec.request_end_date < p_SDR_hdr_rec.request_start_date THEN
1089 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
1090 FND_MESSAGE.set_name('OZF', 'OZF_SD_INVALID_END_DATE');
1091 --//End date should be greater than start date
1092 FND_MSG_PUB.add;
1093 END IF;
1094 x_return_status := fnd_api.g_ret_sts_error;
1095 RETURN;
1096 END IF;
1097 END IF;
1098
1099 --//TRUNC Date
1100 p_SDR_hdr_rec.request_start_date := TRUNC(p_SDR_hdr_rec.request_start_date);
1101 p_SDR_hdr_rec.request_end_date := TRUNC(p_SDR_hdr_rec.request_end_date);
1102
1103 --Request Currency code
1104 IF p_SDR_hdr_rec.request_currency_code <> FND_API.g_miss_char AND p_SDR_hdr_rec.request_currency_code IS NOT NULL THEN
1105 OPEN c_currency (p_SDR_hdr_rec.request_currency_code);
1106 FETCH c_currency INTO l_currency_code;
1107 CLOSE c_currency;
1108
1109 IF l_currency_code IS NULL THEN
1110 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
1111 FND_MESSAGE.set_name('OZF', 'OZF_SD_INVALID_CURRENCY_CODE');
1112 FND_MSG_PUB.add;
1113 END IF;
1114 x_return_status := fnd_api.g_ret_sts_error;
1115 RETURN;
1116 END IF;
1117 ELSE
1118 --//Get currency code from profile :JTF_PROFILE_DEFAULT_CURRENCY
1119 p_SDR_hdr_rec.request_currency_code :=FND_PROFILE.value('JTF_PROFILE_DEFAULT_CURRENCY');
1120
1121 IF p_SDR_hdr_rec.request_currency_code IS NULL THEN
1122
1123 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
1124 FND_MESSAGE.set_name('OZF', 'OZF_SD_ADD_PROFILE_CURRENCY');
1125 --//Please set default Currency in profile JTF_PROFILE_DEFAULT_CURRENCY
1126 FND_MSG_PUB.add;
1127 END IF;
1128 x_return_status := fnd_api.g_ret_sts_error;
1129 RETURN;
1130 END IF;
1131 END IF;
1132
1133 --Request Outcome
1134 IF p_SDR_hdr_rec.request_outcome <> FND_API.g_miss_char AND p_SDR_hdr_rec.request_outcome IS NOT NULL THEN
1135 l_lookup_stat :=OZF_UTILITY_PVT.check_lookup_exists(
1136 p_lookup_table_name =>'OZF_LOOKUPS'
1137 ,p_lookup_type =>'OZF_SD_REQUEST_OUTCOME'
1138 ,p_lookup_code => p_SDR_hdr_rec.request_outcome);
1139
1140 IF l_lookup_stat = FND_API.g_false THEN
1141 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
1142 FND_MESSAGE.set_name('OZF', 'OZF_SD_INVALID_REQ_OUTCOME');
1143 FND_MSG_PUB.add;
1144 END IF;
1145 x_return_status := fnd_api.g_ret_sts_error;
1146 RETURN;
1147 END IF;
1148 END IF;
1149
1150 --Internal Order Number
1151 IF p_SDR_hdr_rec.internal_order_number <> FND_API.g_miss_num AND p_SDR_hdr_rec.internal_order_number IS NOT NULL THEN
1152 OPEN c_order_no (p_SDR_hdr_rec.internal_order_number,p_SDR_hdr_rec.org_id);
1153 FETCH c_order_no INTO l_internal_order_number;
1154 CLOSE c_order_no;
1155
1156 IF l_internal_order_number IS NULL THEN
1157 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
1158 FND_MESSAGE.set_name('OZF', 'OZF_SD_INVALID_ORDER_NUMBER');
1159 FND_MSG_PUB.add;
1160 END IF;
1161 x_return_status := fnd_api.g_ret_sts_error;
1162 RETURN;
1163 END IF;
1164 END IF;
1165
1166 --Sales Order Currency
1167 IF p_SDR_hdr_rec.sales_order_currency <> FND_API.g_miss_char AND p_SDR_hdr_rec.sales_order_currency IS NOT NULL THEN
1168 OPEN c_currency (p_SDR_hdr_rec.sales_order_currency);
1169 FETCH c_currency INTO l_sales_order_currency;
1170 CLOSE c_currency;
1171
1172 IF l_sales_order_currency IS NULL THEN
1173 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
1174 FND_MESSAGE.set_name('OZF', 'OZF_SD_INVALID_SO_CURRENCY');
1175 --//Invalid Sales order Currency.
1176 FND_MSG_PUB.add;
1177 END IF;
1178 x_return_status := fnd_api.g_ret_sts_error;
1179 RETURN;
1180 END IF;
1181 END IF;
1182
1183 --internal_submission_date --ninarasi fix for bug 12837291
1184 /*IF p_SDR_hdr_rec.internal_submission_date <> FND_API.g_miss_date AND p_SDR_hdr_rec.internal_submission_date IS NOT NULL THEN
1185 p_SDR_hdr_rec.internal_submission_date := TRUNC(p_SDR_hdr_rec.internal_submission_date);
1186
1187 IF p_SDR_hdr_rec.internal_submission_date NOT BETWEEN p_SDR_hdr_rec.request_start_date AND
1188 p_SDR_hdr_rec.request_end_date THEN
1189
1190 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
1191 FND_MESSAGE.set_name('OZF', 'OZF_SD_INVALID_INTSUB_DATE');
1192 FND_MSG_PUB.add;
1193 END IF;
1194 x_return_status := fnd_api.g_ret_sts_error;
1195 RETURN;
1196 END IF;
1197 END IF;*/
1198
1199
1200 END Validate_Header_Items;
1201 ---------------------------------------------------------------------
1202 -- PROCEDURE
1203 -- validate_product_lines
1204 --
1205 -- PURPOSE
1206 -- This procedure validates Lines table
1207 --Parameters
1208 -- p_SDR_hdr_rec -Header Recordset
1209 -- p_mode -Insert /Update Mode
1210 -- x_return_status - Result
1211 ---------------------------------------------------------------------
1212 PROCEDURE validate_product_lines(
1213 p_SDR_lines_tbl IN OUT NOCOPY SDR_lines_tbl_type
1214 ,p_SDR_hdr_rec IN SDR_Hdr_rec_type
1215 ,p_mode IN VARCHAR2
1216 ,x_return_status OUT NOCOPY VARCHAR2
1217 )
1218 IS
1219 l_lookup_stat VARCHAR2(1); --To validate from lookups
1220
1221 l_request_line_id NUMBER;
1222 l_inventory_item_id NUMBER;
1223 l_category_id NUMBER;
1224 l_category_set_id NUMBER;
1225 l_formula_count NUMBER;
1226 l_status VARCHAR2(30);
1227 l_qty_increase_tolerance NUMBER := 0 ;
1228 l_item_uom VARCHAR2(30);
1229 l_status_code VARCHAR2(30);
1230 l_external_code VARCHAR2(240);
1231 l_internal_code NUMBER;
1232 l_old_product_lines OZF_SD_REQUEST_PUB.SDR_lines_rec_type;
1233 l_currency_var VARCHAR2(30) := NULL;
1234 l_UOM_chk BOOLEAN;
1235
1236 CURSOR c_master_org_id(p_header_org_id IN NUMBER)IS
1237 SELECT master_organization_id
1238 FROM oe_system_parameters
1239 WHERE org_id = p_header_org_id;
1240
1241 CURSOR c_request_line_id(p_request_line_id IN NUMBER,p_request_header_id IN NUMBER) IS
1242 SELECT request_line_id
1243 FROM ozf_sd_request_lines_all
1244 WHERE request_line_id = p_request_line_id
1245 AND request_header_id = p_request_header_id;
1246
1247 CURSOR c_inventory_item_id(p_inventory_item_id IN NUMBER,p_org_id IN NUMBER)IS
1248 SELECT inventory_item_id
1249 FROM mtl_system_items_kfv
1250 WHERE inventory_item_id = p_inventory_item_id
1251 AND organization_id = p_org_id;
1252
1253 CURSOR c_category_id(p_category_id IN NUMBER) IS
1254 SELECT category_id
1255 FROM mtl_categories_v
1256 WHERE category_id = p_category_id;
1257
1258 CURSOR c_category_set_id(p_category_id IN NUMBER,p_category_set_id IN NUMBER)IS
1259 SELECT b.category_set_id
1260 FROM mtl_default_category_sets a ,
1261 mtl_category_sets_b b ,
1262 mtl_categories_v c
1263 WHERE a.functional_area_id in (7,11)
1264 AND a.category_set_id = b.category_set_id
1265 AND b.structure_id = c.structure_id
1266 AND c.category_id = p_category_id
1267 AND a.category_set_id = p_category_set_id;
1268
1269 CURSOR c_get_category_set_id(p_category_id IN NUMBER)IS
1270 SELECT b.category_set_id
1271 FROM mtl_default_category_sets a ,
1272 mtl_category_sets_b b ,
1273 mtl_categories_v c
1274 WHERE a.functional_area_id in (7,11)
1275 AND a.category_set_id = b.category_set_id
1276 AND b.structure_id = c.structure_id
1277 AND c.category_id = p_category_id;
1278
1279 CURSOR c_product_cost(p_inventory_item_id IN NUMBER,p_org_id IN NUMBER)IS
1280 SELECT list_price_per_unit
1281 FROM mtl_system_items_kfv
1282 WHERE inventory_item_id = p_inventory_item_id
1283 AND organization_id = p_org_id;
1284
1285 --//Bugfix : 12538544
1286 /*
1287 CURSOR c_item_uom(p_item_uom IN VARCHAR2,p_inventory_item_id IN NUMBER,p_org_id IN NUMBER)IS
1288 SELECT a.uom_code
1289 FROM mtl_units_of_measure a,
1290 mtl_system_items c
1291 WHERE c.primary_unit_of_measure = a.unit_of_measure
1292 AND c.organization_id = p_org_id
1293 AND c.inventory_item_id = p_inventory_item_id
1294 AND uom_code = p_item_uom;
1295 */
1296 CURSOR c_item_uom(p_item_uom IN VARCHAR2,p_inventory_item_id IN NUMBER,p_org_id IN NUMBER)IS
1297 SELECT uom_code
1298 FROM mtl_item_uoms_view
1299 WHERE organization_id = p_org_id
1300 AND inventory_item_id = p_inventory_item_id
1301 AND uom_code = p_item_uom;
1302
1303 --//Bugfix :8511949
1304 CURSOR c_price_formula(p_price_formula_id IN NUMBER) IS
1305 SELECT COUNT(1)
1306 FROM qp_price_formulas_b
1307 WHERE TRUNC(sysdate) between NVL(start_date_active, TRUNC(sysdate))
1308 AND NVL(end_date_active, TRUNC(sysdate))
1309 AND price_formula_id = p_price_formula_id;
1310
1311 CURSOR c_func_currency(p_org_id IN NUMBER)IS
1312 SELECT gs.currency_code
1313 FROM gl_sets_of_books gs ,
1314 ozf_sys_parameters_all org
1315 WHERE org.set_of_books_id = gs.set_of_books_id
1316 AND org.org_id = p_org_id;
1317
1318 CURSOR c_cost_basis(p_supplier_id IN NUMBER
1319 ,p_supplier_site_id IN NUMBER
1320 ,p_org_id IN NUMBER)IS
1321 SELECT claim_computation_basis
1322 FROM ozf_supp_trd_prfls_all otrpf
1323 WHERE supplier_id = p_supplier_id
1324 AND supplier_site_id = p_supplier_site_id
1325 AND org_id = p_org_id;
1326
1327 CURSOR c_qty_increase_tolerance(p_supplier_id IN NUMBER
1328 ,p_supplier_site_id IN NUMBER
1329 ,p_org_id IN NUMBER)IS
1330 SELECT NVL(qty_increase_tolerance,0)
1331 FROM ozf_supp_trd_prfls_all
1332 WHERE supplier_id = p_supplier_id
1333 AND supplier_site_id = p_supplier_site_id
1334 AND org_id = p_org_id;
1335
1336 CURSOR c_object_version_number(p_request_line_id IN NUMBER)IS
1337 SELECT object_version_number
1338 FROM ozf_sd_request_lines_all
1339 WHERE request_line_id = p_request_line_id;
1340
1341 CURSOR c_vendor_item_code(p_supplier_id IN NUMBER
1342 ,p_supplier_site_id IN NUMBER
1343 ,p_org_id IN NUMBER
1344 ,p_inventory_item_id IN NUMBER)IS
1345 SELECT external_code
1346 FROM ozf_supp_code_conversions_all code,
1347 ozf_supp_trd_prfls_all trd_profile
1348 WHERE code.code_conversion_type = 'OZF_PRODUCT_CODES'
1349 AND code.supp_trade_profile_id = trd_profile.supp_trade_profile_id
1350 AND trd_profile.supplier_id = p_supplier_id
1351 AND trd_profile.supplier_site_id = p_supplier_site_id
1352 AND trd_profile.org_id = p_org_id
1353 AND internal_code = p_inventory_item_id;
1354
1355
1356 CURSOR c_ext_int_code(p_supplier_id IN NUMBER
1357 ,p_supplier_site_id IN NUMBER
1358 ,p_org_id IN NUMBER) IS
1359 SELECT external_code, --Vendor Item Code
1360 internal_code --Inventory Item ID
1361 FROM ozf_supp_code_conversions_all code,
1362 ozf_supp_trd_prfls_all trd_profile
1363 WHERE code.code_conversion_type = 'OZF_PRODUCT_CODES'
1364 AND code.supp_trade_profile_id = trd_profile.supp_trade_profile_id
1365 AND trd_profile.supplier_id = p_supplier_id
1366 AND trd_profile.supplier_site_id = p_supplier_site_id
1367 AND trd_profile.org_id = p_org_id;
1368
1369 CURSOR c_old_product_lines(p_request_line_id IN NUMBER)IS
1370 SELECT object_version_number,
1371 request_header_id,
1372 product_context,
1373 inventory_item_id,
1374 prod_catg_id,
1375 product_cat_set_id,
1376 product_cost,
1377 item_uom,
1378 requested_discount_type,
1379 requested_discount_value,
1380 cost_basis,
1381 max_qty,
1382 limit_qty,
1383 design_win,
1384 end_customer_price,
1385 requested_line_amount,
1386 approved_discount_type,
1387 approved_discount_value,
1388 approved_max_qty,
1389 attribute_category,
1390 attribute1,
1391 attribute2,
1392 attribute3,
1393 attribute4,
1394 attribute5,
1395 attribute6,
1396 attribute7,
1397 attribute8,
1398 attribute9,
1399 attribute10,
1400 attribute11,
1401 attribute12,
1402 attribute13,
1403 attribute14,
1404 attribute15,
1405 vendor_approved_flag,
1406 vendor_item_code,
1407 start_date,
1408 end_date,
1409 end_customer_price_type,
1410 end_customer_tolerance_type,
1411 end_customer_tolerance_value,
1412 org_id,
1413 rejection_code,
1414 requested_discount_currency,
1415 product_cost_currency,
1416 end_customer_currency,
1417 approved_discount_currency
1418 FROM ozf_sd_request_lines_all
1419 WHERE request_line_id = p_request_line_id;
1420
1421 BEGIN
1422
1423 x_return_status := FND_API.G_RET_STS_SUCCESS;
1424
1425 --//Get the master organization id
1426 OPEN c_master_org_id(p_SDR_hdr_rec.org_id);
1427 FETCH c_master_org_id INTO G_ITEM_ORG_ID;
1428 CLOSE c_master_org_id;
1429
1430 IF G_DEBUG THEN
1431 OZF_UTILITY_PVT.debug_message('c_master_org_id -->G_ITEM_ORG_ID: ' || G_ITEM_ORG_ID);
1432 END IF;
1433
1434
1435 FOR i IN p_SDR_lines_tbl.FIRST..p_SDR_lines_tbl.LAST LOOP
1436 --//Update Mode
1437 IF p_mode ='UPDATE' THEN
1438
1439 IF p_SDR_lines_tbl(i).request_line_id <> FND_API.g_miss_num AND p_SDR_lines_tbl(i).request_line_id IS NOT NULL THEN
1440 --Updating existing lines
1441 OPEN c_request_line_id(p_SDR_lines_tbl(i).request_line_id,p_SDR_hdr_rec.request_header_id);
1442 FETCH c_request_line_id INTO l_request_line_id;
1443 CLOSE c_request_line_id;
1444
1445 IF l_request_line_id IS NULL AND p_SDR_lines_tbl(i).create_from <> 'ADJ' THEN
1446 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
1447 FND_MESSAGE.set_name('OZF', 'OZF_SD_INVALID_REQUEST_LINE_ID');
1448 --//Request Line id is Invalid , Please Re-enter
1449 FND_MSG_PUB.add;
1450 END IF;
1451 x_return_status := fnd_api.g_ret_sts_error;
1452 RETURN;
1453 ELSIF p_SDR_lines_tbl(i).create_from <> 'ADJ' THEN
1454
1455 --//Reset the values of new record from old record if NULL.
1456 OPEN c_old_product_lines(p_SDR_lines_tbl(i).request_line_id);
1457 FETCH c_old_product_lines INTO l_old_product_lines.object_version_number,
1458 l_old_product_lines.request_header_id,
1459 l_old_product_lines.product_context,
1460 l_old_product_lines.inventory_item_id,
1461 l_old_product_lines.prod_catg_id,
1462 l_old_product_lines.product_cat_set_id,
1463 l_old_product_lines.product_cost,
1464 l_old_product_lines.item_uom,
1465 l_old_product_lines.requested_discount_type,
1466 l_old_product_lines.requested_discount_value,
1467 l_old_product_lines.cost_basis,
1468 l_old_product_lines.max_qty,
1469 l_old_product_lines.limit_qty,
1470 l_old_product_lines.design_win,
1471 l_old_product_lines.end_customer_price,
1472 l_old_product_lines.requested_line_amount,
1473 l_old_product_lines.approved_discount_type,
1474 l_old_product_lines.approved_discount_value,
1475 l_old_product_lines.approved_max_qty,
1476 l_old_product_lines.attribute_category,
1477 l_old_product_lines.attribute1,
1478 l_old_product_lines.attribute2,
1479 l_old_product_lines.attribute3,
1480 l_old_product_lines.attribute4,
1481 l_old_product_lines.attribute5,
1482 l_old_product_lines.attribute6,
1483 l_old_product_lines.attribute7,
1484 l_old_product_lines.attribute8,
1485 l_old_product_lines.attribute9,
1486 l_old_product_lines.attribute10,
1487 l_old_product_lines.attribute11,
1488 l_old_product_lines.attribute12,
1489 l_old_product_lines.attribute13,
1490 l_old_product_lines.attribute14,
1491 l_old_product_lines.attribute15,
1492 l_old_product_lines.vendor_approved_flag,
1493 l_old_product_lines.vendor_item_code,
1494 l_old_product_lines.start_date,
1495 l_old_product_lines.end_date,
1496 l_old_product_lines.end_customer_price_type,
1497 l_old_product_lines.end_customer_tolerance_type,
1498 l_old_product_lines.end_customer_tolerance_value,
1499 l_old_product_lines.org_id,
1500 l_old_product_lines.rejection_code,
1501 l_old_product_lines.requested_discount_currency,
1502 l_old_product_lines.product_cost_currency,
1503 l_old_product_lines.end_customer_currency,
1504 l_old_product_lines.approved_discount_currency;
1505 CLOSE c_old_product_lines;
1506
1507 p_SDR_lines_tbl(i).object_version_number := l_old_product_lines.object_version_number;
1508 p_SDR_lines_tbl(i).request_header_id := NVL(p_SDR_lines_tbl(i).request_header_id,l_old_product_lines.request_header_id);
1509 p_SDR_lines_tbl(i).product_context := NVL(p_SDR_lines_tbl(i).product_context,l_old_product_lines.product_context);
1510 p_SDR_lines_tbl(i).inventory_item_id := NVL(p_SDR_lines_tbl(i).inventory_item_id,l_old_product_lines.inventory_item_id);
1511 p_SDR_lines_tbl(i).prod_catg_id := NVL(p_SDR_lines_tbl(i).prod_catg_id,l_old_product_lines.prod_catg_id);
1512 p_SDR_lines_tbl(i).product_cat_set_id := NVL(p_SDR_lines_tbl(i).product_cat_set_id,l_old_product_lines.product_cat_set_id);
1513 p_SDR_lines_tbl(i).product_cost := NVL(p_SDR_lines_tbl(i).product_cost,l_old_product_lines.product_cost);
1514 p_SDR_lines_tbl(i).item_uom := NVL(p_SDR_lines_tbl(i).item_uom,l_old_product_lines.item_uom);
1515 p_SDR_lines_tbl(i).requested_discount_type := NVL(p_SDR_lines_tbl(i).requested_discount_type,l_old_product_lines.requested_discount_type);
1516 p_SDR_lines_tbl(i).requested_discount_value := NVL(p_SDR_lines_tbl(i).requested_discount_value,l_old_product_lines.requested_discount_value);
1517 p_SDR_lines_tbl(i).cost_basis := NVL(p_SDR_lines_tbl(i).cost_basis,l_old_product_lines.cost_basis);
1518 p_SDR_lines_tbl(i).max_qty := NVL(p_SDR_lines_tbl(i).max_qty,l_old_product_lines.max_qty);
1519 p_SDR_lines_tbl(i).limit_qty := NVL(p_SDR_lines_tbl(i).limit_qty,l_old_product_lines.limit_qty);
1520 p_SDR_lines_tbl(i).design_win := NVL(p_SDR_lines_tbl(i).design_win,l_old_product_lines.design_win);
1521 p_SDR_lines_tbl(i).end_customer_price := NVL(p_SDR_lines_tbl(i).end_customer_price,l_old_product_lines.end_customer_price);
1522 p_SDR_lines_tbl(i).requested_line_amount := NVL(p_SDR_lines_tbl(i).requested_line_amount,l_old_product_lines.requested_line_amount);
1523 p_SDR_lines_tbl(i).approved_discount_type := NVL(p_SDR_lines_tbl(i).approved_discount_type,l_old_product_lines.approved_discount_type);
1524 p_SDR_lines_tbl(i).approved_discount_value := NVL(p_SDR_lines_tbl(i).approved_discount_value,l_old_product_lines.approved_discount_value);
1525 p_SDR_lines_tbl(i).approved_max_qty := NVL(p_SDR_lines_tbl(i).approved_max_qty,l_old_product_lines.approved_max_qty);
1526 p_SDR_lines_tbl(i).attribute_category := NVL(p_SDR_lines_tbl(i).attribute_category,l_old_product_lines.attribute_category);
1527 p_SDR_lines_tbl(i).attribute1 := NVL(p_SDR_lines_tbl(i).attribute1,l_old_product_lines.attribute1);
1528 p_SDR_lines_tbl(i).attribute2 := NVL(p_SDR_lines_tbl(i).attribute2,l_old_product_lines.attribute2);
1529 p_SDR_lines_tbl(i).attribute3 := NVL(p_SDR_lines_tbl(i).attribute3,l_old_product_lines.attribute3);
1530 p_SDR_lines_tbl(i).attribute4 := NVL(p_SDR_lines_tbl(i).attribute4,l_old_product_lines.attribute4);
1531 p_SDR_lines_tbl(i).attribute5 := NVL(p_SDR_lines_tbl(i).attribute5,l_old_product_lines.attribute5);
1532 p_SDR_lines_tbl(i).attribute6 := NVL(p_SDR_lines_tbl(i).attribute6,l_old_product_lines.attribute6);
1533 p_SDR_lines_tbl(i).attribute7 := NVL(p_SDR_lines_tbl(i).attribute7,l_old_product_lines.attribute7);
1534 p_SDR_lines_tbl(i).attribute8 := NVL(p_SDR_lines_tbl(i).attribute8,l_old_product_lines.attribute8);
1535 p_SDR_lines_tbl(i).attribute9 := NVL(p_SDR_lines_tbl(i).attribute9,l_old_product_lines.attribute9);
1536 p_SDR_lines_tbl(i).attribute10 := NVL(p_SDR_lines_tbl(i).attribute10,l_old_product_lines.attribute10);
1537 p_SDR_lines_tbl(i).attribute11 := NVL(p_SDR_lines_tbl(i).attribute11,l_old_product_lines.attribute11);
1538 p_SDR_lines_tbl(i).attribute12 := NVL(p_SDR_lines_tbl(i).attribute12,l_old_product_lines.attribute12);
1539 p_SDR_lines_tbl(i).attribute13 := NVL(p_SDR_lines_tbl(i).attribute13,l_old_product_lines.attribute13);
1540 p_SDR_lines_tbl(i).attribute14 := NVL(p_SDR_lines_tbl(i).attribute14,l_old_product_lines.attribute14);
1541 p_SDR_lines_tbl(i).attribute15 := NVL(p_SDR_lines_tbl(i).attribute15,l_old_product_lines.attribute15);
1542 p_SDR_lines_tbl(i).vendor_approved_flag := NVL(p_SDR_lines_tbl(i).vendor_approved_flag,l_old_product_lines.vendor_approved_flag);
1543 p_SDR_lines_tbl(i).vendor_item_code := NVL(p_SDR_lines_tbl(i).vendor_item_code,l_old_product_lines.vendor_item_code);
1544 p_SDR_lines_tbl(i).start_date := NVL(p_SDR_lines_tbl(i).start_date,l_old_product_lines.start_date);
1545 p_SDR_lines_tbl(i).end_date := NVL(p_SDR_lines_tbl(i).end_date,l_old_product_lines.end_date);
1546 p_SDR_lines_tbl(i).end_customer_price_type := NVL(p_SDR_lines_tbl(i).end_customer_price_type,l_old_product_lines.end_customer_price_type);
1547 p_SDR_lines_tbl(i).end_customer_tolerance_type := NVL(p_SDR_lines_tbl(i).end_customer_tolerance_type,l_old_product_lines.end_customer_tolerance_type);
1548 p_SDR_lines_tbl(i).end_customer_tolerance_value := NVL(p_SDR_lines_tbl(i).end_customer_tolerance_value,l_old_product_lines.end_customer_tolerance_value);
1549 p_SDR_lines_tbl(i).org_id := NVL(p_SDR_lines_tbl(i).org_id,l_old_product_lines.org_id);
1550 p_SDR_lines_tbl(i).rejection_code := NVL(p_SDR_lines_tbl(i).rejection_code,l_old_product_lines.rejection_code);
1551 p_SDR_lines_tbl(i).requested_discount_currency := NVL(p_SDR_lines_tbl(i).requested_discount_currency,l_old_product_lines.requested_discount_currency);
1552 p_SDR_lines_tbl(i).product_cost_currency := NVL(p_SDR_lines_tbl(i).product_cost_currency,l_old_product_lines.product_cost_currency);
1553 p_SDR_lines_tbl(i).end_customer_currency := NVL(p_SDR_lines_tbl(i).end_customer_currency,l_old_product_lines.end_customer_currency);
1554 p_SDR_lines_tbl(i).approved_discount_currency := NVL(p_SDR_lines_tbl(i).approved_discount_currency,l_old_product_lines.approved_discount_currency);
1555
1556 END IF;
1557 END IF;
1558 END IF;
1559
1560 --//Update Mode End
1561
1562 --Product Context
1563 IF p_SDR_lines_tbl(i).product_context <> FND_API.g_miss_char AND p_SDR_lines_tbl(i).product_context IS NOT NULL THEN
1564
1565 l_lookup_stat :=OZF_UTILITY_PVT.check_lookup_exists(
1566 p_lookup_table_name =>'OZF_LOOKUPS'
1567 ,p_lookup_type =>'OZF_SD_PRODUCT_CONTEXT'
1568 ,p_lookup_code => p_SDR_lines_tbl(i).product_context);
1569
1570 IF l_lookup_stat = FND_API.g_false THEN
1571 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
1572 FND_MESSAGE.set_name('OZF', 'OZF_SD_INVALID_PRODUCT_TYPE');
1573 FND_MSG_PUB.add;
1574 END IF;
1575 x_return_status := fnd_api.g_ret_sts_error;
1576 RETURN;
1577 END IF;
1578 ELSE
1579 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
1580 FND_MESSAGE.set_name('OZF', 'OZF_SD_NO_PRODUCT_CONTEXT');
1581 --//Product context is Mandatory
1582 FND_MSG_PUB.add;
1583 END IF;
1584 x_return_status := fnd_api.g_ret_sts_error;
1585 RETURN;
1586 END IF;
1587
1588 --//PRODUCT
1589 --==========
1590 IF p_SDR_lines_tbl(i).product_context ='PRODUCT' THEN
1591
1592 p_SDR_lines_tbl(i).prod_catg_id := NULL;
1593 p_SDR_lines_tbl(i).product_cat_set_id := NULL;
1594
1595 IF p_SDR_lines_tbl(i).inventory_item_id <> FND_API.g_miss_num AND p_SDR_lines_tbl(i).inventory_item_id IS NOT NULL THEN
1596
1597 OPEN c_inventory_item_id(p_SDR_lines_tbl(i).inventory_item_id,G_ITEM_ORG_ID);
1598 FETCH c_inventory_item_id INTO l_inventory_item_id;
1599 CLOSE c_inventory_item_id;
1600
1601 IF l_inventory_item_id IS NULL THEN
1602 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
1603 FND_MESSAGE.set_name('OZF', 'OZF_SD_INVALID_INVENTORY_ITEM_ID');
1604 --//Inventory item id is Invalid
1605 FND_MSG_PUB.add;
1606 END IF;
1607 x_return_status := fnd_api.g_ret_sts_error;
1608 RETURN;
1609 END IF;
1610 --//Populating Vendor Item code
1611 --// Bugfix 7372272 gmiss_num changed to gmiss_char
1612 IF p_SDR_lines_tbl(i).vendor_item_code = FND_API.g_miss_char OR p_SDR_lines_tbl(i).vendor_item_code IS NULL THEN
1613
1614 OPEN c_vendor_item_code(p_SDR_hdr_rec.supplier_id,p_SDR_hdr_rec.supplier_site_id,p_SDR_hdr_rec.org_id,p_SDR_lines_tbl(i).inventory_item_id);
1615 FETCH c_vendor_item_code INTO p_SDR_lines_tbl(i).vendor_item_code;
1616 CLOSE c_vendor_item_code;
1617 END IF;
1618
1619 ELSIF p_SDR_lines_tbl(i).vendor_item_code <> FND_API.g_miss_char AND p_SDR_lines_tbl(i).vendor_item_code IS NOT NULL THEN
1620
1621 l_external_code := NULL;
1622 l_internal_code := NULL;
1623 OPEN c_ext_int_code(p_SDR_hdr_rec.supplier_id,p_SDR_hdr_rec.supplier_site_id,p_SDR_hdr_rec.org_id);
1624 FETCH c_ext_int_code INTO l_external_code,l_internal_code;
1625 CLOSE c_ext_int_code;
1626
1627 IF l_external_code IS NULL THEN
1628 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
1629 FND_MESSAGE.set_name('OZF', 'OZF_SD_INVALID_VENDOR_ITEM_CODE');
1630 FND_MSG_PUB.add;
1631 END IF;
1632 x_return_status := fnd_api.g_ret_sts_error;
1633 RETURN;
1634 END IF;
1635 p_SDR_lines_tbl(i).inventory_item_id := l_internal_code;
1636
1637 ELSE
1638 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
1639 FND_MESSAGE.set_name('OZF', 'OZF_SD_NO_INVENTORY_ITEM_ID');
1640 --//Inventory item id is mandatory
1641 FND_MSG_PUB.add;
1642 END IF;
1643 x_return_status := fnd_api.g_ret_sts_error;
1644 RETURN;
1645 END IF;
1646
1647 /* Bugfix : 12620229 - Commented UOM Mandatory check for PRODUCTS
1648 IF p_SDR_lines_tbl(i).item_uom <> FND_API.g_miss_char AND p_SDR_lines_tbl(i).item_uom IS NOT NULL THEN
1649
1650 OPEN c_item_uom(p_SDR_lines_tbl(i).item_uom
1651 ,p_SDR_lines_tbl(i).inventory_item_id
1652 ,G_ITEM_ORG_ID);
1653 FETCH c_item_uom INTO l_item_uom;
1654 CLOSE c_item_uom;
1655
1656 IF l_item_uom IS NULL THEN
1657 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
1658 FND_MESSAGE.set_name('OZF', 'OZF_SD_INVALID_ITEM_UOM');
1659 --//Unit of Measurement is Invalid
1660 FND_MSG_PUB.add;
1661 END IF;
1662 x_return_status := fnd_api.g_ret_sts_error;
1663 RETURN;
1664 END IF;
1665 ELSE
1666 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
1667 FND_MESSAGE.set_name('OZF', 'OZF_SD_NO_ITEM_UOM');
1668 --//Unit of Measurement is mandatory
1669 FND_MSG_PUB.add;
1670 END IF;
1671 x_return_status := fnd_api.g_ret_sts_error;
1672 RETURN;
1673 END IF;
1674 */
1675
1676 --//Product Cost Validation Bugfix: 7501046
1677 IF p_SDR_lines_tbl(i).product_cost = FND_API.g_miss_num OR p_SDR_lines_tbl(i).product_cost IS NULL THEN
1678 OPEN c_product_cost(p_SDR_lines_tbl(i).inventory_item_id,G_ITEM_ORG_ID);
1679 FETCH c_product_cost INTO p_SDR_lines_tbl(i).product_cost;
1680 CLOSE c_product_cost;
1681
1682 IF p_SDR_lines_tbl(i).product_cost IS NULL THEN
1683 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
1684 FND_MESSAGE.set_name('OZF', 'OZF_SD_NO_PRODUCT_COST');
1685 --//A value must be entered for Product Cost
1686 FND_MSG_PUB.add;
1687 END IF;
1688 x_return_status := fnd_api.g_ret_sts_error;
1689 RETURN;
1690 END IF;
1691 END IF;
1692
1693 --//Bugfix : 8511949 - Product Cost Currency Validation - If NULL is passed to API, get from Functional Currency, Else validate and process
1694 IF p_SDR_lines_tbl(i).product_cost_currency = FND_API.g_miss_char OR p_SDR_lines_tbl(i).product_cost_currency IS NULL THEN
1695
1696 l_currency_var := NULL;
1697 OPEN c_func_currency(p_SDR_hdr_rec.org_id);
1698 FETCH c_func_currency INTO p_SDR_lines_tbl(i).product_cost_currency;
1699 CLOSE c_func_currency;
1700 ELSE
1701 OPEN c_currency(p_SDR_lines_tbl(i).product_cost_currency);
1702 FETCH c_currency INTO l_currency_var;
1703 CLOSE c_currency;
1704
1705 IF l_currency_var IS NULL THEN
1706 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
1707 FND_MESSAGE.set_name('OZF', 'OZF_INVALID_PROD_COST_CURR');
1708 FND_MSG_PUB.add;
1709 END IF;
1710 x_return_status := fnd_api.g_ret_sts_error;
1711 RETURN;
1712 END IF;
1713 END IF;
1714
1715 --//PRODUCT CATEGORY
1716 --===================
1717 ELSIF p_SDR_lines_tbl(i).product_context ='PRODUCT_CATEGORY' THEN
1718
1719 p_SDR_lines_tbl(i).inventory_item_id := NULL;
1720 p_SDR_lines_tbl(i).vendor_item_code := NULL;
1721 --p_SDR_lines_tbl(i).item_uom := NULL;
1722 p_SDR_lines_tbl(i).product_cost := NULL;
1723 p_SDR_lines_tbl(i).product_cost_currency := NULL;
1724
1725 --//Category ID
1726 IF p_SDR_lines_tbl(i).prod_catg_id <> FND_API.g_miss_num AND p_SDR_lines_tbl(i).prod_catg_id IS NOT NULL THEN
1727
1728 OPEN c_category_id(p_SDR_lines_tbl(i).prod_catg_id);
1729 FETCH c_category_id INTO l_category_id;
1730 CLOSE c_category_id;
1731
1732 IF l_category_id IS NULL THEN
1733 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
1734 FND_MESSAGE.set_name('OZF', 'OZF_SD_INVALID_PRODUCT_CATEGORY');
1735 --//Product category is Invalid
1736 FND_MSG_PUB.add;
1737 END IF;
1738 x_return_status := fnd_api.g_ret_sts_error;
1739 RETURN;
1740 END IF;
1741 ELSE
1742 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
1743 FND_MESSAGE.set_name('OZF', 'OZF_SD_NO_PRODUCT_CATEGORY');
1744 --//Product category is mandatory
1745 FND_MSG_PUB.add;
1746 END IF;
1747 x_return_status := fnd_api.g_ret_sts_error;
1748 RETURN;
1749 END IF;
1750
1751 --//Category set id
1752 IF p_SDR_lines_tbl(i).product_cat_set_id <> FND_API.g_miss_num AND p_SDR_lines_tbl(i).product_cat_set_id IS NOT NULL THEN
1753
1754 OPEN c_category_set_id(p_SDR_lines_tbl(i).prod_catg_id
1755 ,p_SDR_lines_tbl(i).product_cat_set_id);
1756 FETCH c_category_set_id INTO l_category_set_id;
1757 CLOSE c_category_set_id;
1758
1759 IF l_category_set_id IS NULL THEN
1760 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
1761 FND_MESSAGE.set_name('OZF', 'OZF_SD_INVALID_PRODUCT_CATEGORY_SET');
1762 --//Product category set is Invalid
1763 FND_MSG_PUB.add;
1764 END IF;
1765 x_return_status := fnd_api.g_ret_sts_error;
1766 RETURN;
1767 END IF;
1768 ELSE --//get the Default category set
1769 OPEN c_get_category_set_id(p_SDR_lines_tbl(i).prod_catg_id);
1770 FETCH c_get_category_set_id INTO p_SDR_lines_tbl(i).product_cat_set_id;
1771 CLOSE c_get_category_set_id;
1772 END IF;
1773
1774 --//Bugfix :12620229
1775 --// For ALL_ITEMS
1776 ELSIF p_SDR_lines_tbl(i).product_context ='ALL_ITEMS' THEN
1777
1778 p_SDR_lines_tbl(i).prod_catg_id := NULL;
1779 p_SDR_lines_tbl(i).product_cat_set_id := NULL;
1780 p_SDR_lines_tbl(i).inventory_item_id := NULL;
1781 p_SDR_lines_tbl(i).vendor_item_code := NULL;
1782 p_SDR_lines_tbl(i).product_cost := NULL;
1783 p_SDR_lines_tbl(i).product_cost_currency := NULL;
1784
1785 END IF;
1786 --//Bugfix : 12620229
1787 --//UOM Validation
1788 IF p_SDR_lines_tbl(i).item_uom <> FND_API.g_miss_char AND p_SDR_lines_tbl(i).item_uom IS NOT NULL THEN
1789
1790 l_UOM_chk := validate_UOM(p_item_type => p_SDR_lines_tbl(i).product_context
1791 ,p_inventory_item_id => p_SDR_lines_tbl(i).inventory_item_id
1792 ,p_category_id => p_SDR_lines_tbl(i).prod_catg_id
1793 ,p_item_UOM => p_SDR_lines_tbl(i).item_uom);
1794
1795 IF NOT l_UOM_chk THEN
1796 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
1797 FND_MESSAGE.set_name('OZF', 'OZF_SD_INVALID_ITEM_UOM');
1798 --//Unit of Measurement is Invalid
1799 FND_MSG_PUB.add;
1800 END IF;
1801 x_return_status := fnd_api.g_ret_sts_error;
1802 RETURN;
1803 END IF;
1804 END IF;
1805
1806
1807
1808 --//Requested discount type
1809 IF p_SDR_lines_tbl(i).requested_discount_type <> FND_API.g_miss_char AND p_SDR_lines_tbl(i).requested_discount_type IS NOT NULL THEN
1810 l_lookup_stat :=OZF_UTILITY_PVT.check_lookup_exists(
1811 p_lookup_table_name =>'OZF_LOOKUPS'
1812 ,p_lookup_type =>'OZF_SD_REQUEST_DISTYPE'
1813 ,p_lookup_code => p_SDR_lines_tbl(i).requested_discount_type);
1814
1815 IF l_lookup_stat = FND_API.g_false THEN
1816 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
1817 FND_MESSAGE.set_name('OZF', 'OZF_SD_INVALID_DISCOUNT_TYPE');
1818 FND_MSG_PUB.add;
1819 END IF;
1820 x_return_status := fnd_api.g_ret_sts_error;
1821 RETURN;
1822 END IF;
1823 ELSE
1824 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
1825 FND_MESSAGE.set_name('OZF', 'OZF_SD_NO_DISCOUNT_TYPE');
1826 FND_MSG_PUB.add;
1827 END IF;
1828 x_return_status := fnd_api.g_ret_sts_error;
1829 RETURN;
1830 END IF;
1831
1832 --//Requested discount Value
1833
1834 IF p_SDR_lines_tbl(i).requested_discount_value = FND_API.g_miss_num OR p_SDR_lines_tbl(i).requested_discount_value IS NULL THEN
1835 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
1836 FND_MESSAGE.set_name('OZF', 'OZF_SD_NO_DISC_VALUE');
1837 FND_MSG_PUB.add;
1838 END IF;
1839 x_return_status := fnd_api.g_ret_sts_error;
1840 RETURN;
1841 END IF;
1842 --//Bugfix : 12673769
1843 /*
1844 ELSE
1845 l_status := check_zero(p_SDR_lines_tbl(i).requested_discount_value);
1846 IF l_status = FND_API.g_false THEN
1847 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
1848 FND_MESSAGE.set_name('OZF', 'OZF_SD_DISCOUNT_VALUE_IS_ZERO');
1849 --//Discount value should not be zero
1850 FND_MSG_PUB.add;
1851 END IF;
1852 x_return_status := fnd_api.g_ret_sts_error;
1853 RETURN;
1854 END IF;
1855 */
1856
1857
1858
1859 --//Bugfix : 8511949 - Requested discount Currency Validation
1860 --//For Discount type other than % , if requested_discount_currency is NULL, default it to Header Request Currency, Else Validate and Process.
1861 IF p_SDR_lines_tbl(i).requested_discount_type <> '%' THEN
1862 IF p_SDR_lines_tbl(i).requested_discount_currency = FND_API.g_miss_char OR p_SDR_lines_tbl(i).requested_discount_currency IS NULL THEN
1863 p_SDR_lines_tbl(i).requested_discount_currency := p_SDR_hdr_rec.request_currency_code;
1864 ELSE
1865 l_currency_var := NULL;
1866 OPEN c_currency(p_SDR_lines_tbl(i).requested_discount_currency);
1867 FETCH c_currency INTO l_currency_var;
1868 CLOSE c_currency;
1869
1870 IF l_currency_var IS NULL THEN
1871 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
1872 FND_MESSAGE.set_name('OZF', 'OZF_INVALID_REQ_DISC_CURR');
1873 FND_MSG_PUB.add;
1874 END IF;
1875 x_return_status := fnd_api.g_ret_sts_error;
1876 RETURN;
1877 END IF;
1878 END IF;
1879 END IF;
1880
1881 --//Populating Cost Basis
1882 --//Bugfix :8511949
1883 IF p_SDR_lines_tbl(i).cost_basis <> FND_API.g_miss_num AND p_SDR_lines_tbl(i).cost_basis IS NOT NULL THEN
1884
1885 OPEN c_price_formula(p_SDR_lines_tbl(i).cost_basis);
1886 FETCH c_price_formula INTO l_formula_count;
1887 CLOSE c_price_formula;
1888
1889 IF l_formula_count = 0 THEN
1890 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
1891 FND_MESSAGE.set_name('OZF', 'OZF_SD_INVALID_COST_BASIS');
1892 FND_MSG_PUB.add;
1893 END IF;
1894 x_return_status := fnd_api.g_ret_sts_error;
1895 RETURN;
1896 END IF;
1897 ELSE
1898 --//Default cost basis only in Line create Mode
1899 IF p_SDR_lines_tbl(i).request_line_id = FND_API.g_miss_num OR p_SDR_lines_tbl(i).request_line_id IS NULL THEN
1900 OPEN c_cost_basis(p_SDR_hdr_rec.supplier_id
1901 ,p_SDR_hdr_rec.supplier_site_id
1902 ,p_SDR_hdr_rec.org_id);
1903 FETCH c_cost_basis INTO p_SDR_lines_tbl(i).cost_basis;
1904 CLOSE c_cost_basis;
1905 END IF;
1906 END IF;
1907
1908 --//Max Qty
1909 IF p_SDR_lines_tbl(i).max_qty <> FND_API.g_miss_num AND p_SDR_lines_tbl(i).max_qty IS NOT NULL THEN
1910 l_status := check_zero(p_SDR_lines_tbl(i).max_qty);
1911 IF l_status = FND_API.g_false THEN
1912 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
1913 FND_MESSAGE.set_name('OZF', 'OZF_SD_MAX_QTY_ZERO_CHECK'); --//Check the message!
1914 --//Discount value should not be zero
1915 FND_MSG_PUB.add;
1916 END IF;
1917 x_return_status := fnd_api.g_ret_sts_error;
1918 RETURN;
1919 END IF;
1920
1921 --//Set limit Qty
1922 OPEN c_qty_increase_tolerance(p_SDR_hdr_rec.supplier_id
1923 ,p_SDR_hdr_rec.supplier_site_id
1924 ,p_SDR_hdr_rec.org_id);
1925 FETCH c_qty_increase_tolerance INTO l_qty_increase_tolerance;
1926 CLOSE c_qty_increase_tolerance;
1927
1928 p_SDR_lines_tbl(i).limit_qty := p_SDR_lines_tbl(i).max_qty + ((p_SDR_lines_tbl(i).max_qty * l_qty_increase_tolerance)/100);
1929
1930 END IF;
1931
1932 --//End Customer price
1933 IF p_SDR_lines_tbl(i).end_customer_price <> FND_API.g_miss_num AND p_SDR_lines_tbl(i).end_customer_price IS NOT NULL THEN
1934 l_status := check_zero(p_SDR_lines_tbl(i).end_customer_price);
1935 IF l_status = FND_API.g_false THEN
1936 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
1937 FND_MESSAGE.set_name('OZF', 'OZF_SD_END_CUST_PRICE_VALUE_IS_ZERO');
1938 --//Discount value should not be zero
1939 FND_MSG_PUB.add;
1940 END IF;
1941 x_return_status := fnd_api.g_ret_sts_error;
1942 RETURN;
1943 END IF;
1944 --//End Customer Currency. Bugfix : 8511949, Introduced the validation
1945 IF p_SDR_lines_tbl(i).end_customer_currency <> FND_API.g_miss_char AND p_SDR_lines_tbl(i).end_customer_currency IS NOT NULL THEN
1946
1947 l_currency_var := NULL;
1948 OPEN c_currency(p_SDR_lines_tbl(i).end_customer_currency);
1949 FETCH c_currency INTO l_currency_var;
1950 CLOSE c_currency;
1951
1952 IF l_currency_var IS NULL THEN
1953 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
1954 FND_MESSAGE.set_name('OZF', 'OZF_INVALID_END_CUST_CURR');
1955 FND_MSG_PUB.add;
1956 END IF;
1957 x_return_status := fnd_api.g_ret_sts_error;
1958 RETURN;
1959 END IF;
1960 ELSE
1961 p_SDR_lines_tbl(i).end_customer_currency := p_SDR_hdr_rec.request_currency_code;
1962 END IF;
1963 --There is a possibility that the orig line has only end_customer_currency. Other cols end_customer_price, end_customer_price_type might be null.
1964 -- In those cases, the copy of SDR fails from UI. Since the new line created via adjustment (which callls public API), will not have end_customer_currency
1965 --due to the code given below. This causes OA Ui to error out. Since it has a validation and it wont call offer API.
1966 -- hence commented out this line. If original line can only have currency then so can adjusted line.
1967 --ELSE
1968 -- p_SDR_lines_tbl(i).end_customer_currency := NULL;
1969 END IF;
1970
1971
1972
1973 --Vendor Approved Flag
1974 --//Bugfix : 9791659 - Changed <> to = in condition vendor_approved_flag = FND_API.g_miss_char
1975 IF p_SDR_lines_tbl(i).vendor_approved_flag = FND_API.g_miss_char OR p_SDR_lines_tbl(i).vendor_approved_flag IS NULL THEN
1976 p_SDR_lines_tbl(i).vendor_approved_flag := 'Y';
1977 ELSE
1978 IF p_SDR_lines_tbl(i).vendor_approved_flag NOT IN ('Y','N')THEN
1979 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
1980 FND_MESSAGE.set_name('OZF', 'OZF_SD_INVALID_VENDOR_APPR_FLAG');
1981 FND_MSG_PUB.add;
1982 END IF;
1983 x_return_status := fnd_api.g_ret_sts_error;
1984 RETURN;
1985 END IF;
1986 END IF;
1987 --//Bugfix : 7607795
1988 IF p_mode ='CREATE' THEN
1989 IF p_SDR_lines_tbl(i).start_date = FND_API.g_miss_date OR p_SDR_lines_tbl(i).start_date IS NULL THEN
1990 p_SDR_lines_tbl(i).start_date :=p_SDR_hdr_rec.request_start_date;
1991
1992 ELSIF TRUNC(p_SDR_lines_tbl(i).start_date) NOT BETWEEN
1993 TRUNC(p_SDR_hdr_rec.request_start_date) AND TRUNC(p_SDR_hdr_rec.request_end_date) THEN
1994
1995 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
1996 FND_MESSAGE.set_name('OZF', 'OZF_SD_LINE_START_DATE_CHECK');
1997 --//Start Date should fall in between Header Start date and End Date
1998 FND_MSG_PUB.add;
1999 END IF;
2000 x_return_status := fnd_api.g_ret_sts_error;
2001 RETURN;
2002 END IF;
2003
2004 --End Date
2005 IF p_SDR_lines_tbl(i).end_date = FND_API.g_miss_date OR p_SDR_lines_tbl(i).end_date IS NULL THEN
2006 p_SDR_lines_tbl(i).end_date :=p_SDR_hdr_rec.request_end_date;
2007
2008 ELSIF TRUNC(p_SDR_lines_tbl(i).end_date) NOT BETWEEN
2009 TRUNC(p_SDR_hdr_rec.request_start_date) AND TRUNC(p_SDR_hdr_rec.request_end_date) THEN
2010
2011 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
2012 FND_MESSAGE.set_name('OZF', 'OZF_SD_LINE_END_DATE_CHECK');
2013 --//End Date should fall in between Header Start date and End Date
2014 FND_MSG_PUB.add;
2015 END IF;
2016 x_return_status := fnd_api.g_ret_sts_error;
2017 RETURN;
2018 END IF;
2019 END IF;
2020
2021 IF G_DEBUG THEN
2022 OZF_UTILITY_PVT.debug_message('p_SDR_lines_tbl(i).start_date ' || p_SDR_lines_tbl(i).start_date);
2023 OZF_UTILITY_PVT.debug_message('p_SDR_lines_tbl(i).end_date: ' || p_SDR_lines_tbl(i).end_date);
2024 END IF;
2025
2026
2027 IF p_SDR_lines_tbl(i).end_date < p_SDR_lines_tbl(i).start_date THEN
2028 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
2029 FND_MESSAGE.set_name('OZF', 'OZF_SD_LINE_END_DATE_GT_CHECK');
2030 --//End Date should be greater than start date
2031 FND_MSG_PUB.add;
2032 END IF;
2033 x_return_status := fnd_api.g_ret_sts_error;
2034 RETURN;
2035 END IF;
2036
2037 p_SDR_lines_tbl(i).start_date := TRUNC(p_SDR_lines_tbl(i).start_date);
2038 p_SDR_lines_tbl(i).end_date := TRUNC(p_SDR_lines_tbl(i).end_date);
2039
2040 --//Price Type
2041 IF p_SDR_lines_tbl(i).end_customer_price_type <> FND_API.g_miss_char AND p_SDR_lines_tbl(i).end_customer_price_type IS NOT NULL THEN
2042 l_lookup_stat :=OZF_UTILITY_PVT.check_lookup_exists(
2043 p_lookup_table_name =>'OZF_LOOKUPS'
2044 ,p_lookup_type =>'OZF_SD_PRICE_TYPE'
2045 ,p_lookup_code => p_SDR_lines_tbl(i).end_customer_price_type);
2046
2047 IF l_lookup_stat = FND_API.g_false THEN
2048 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
2049 FND_MESSAGE.set_name('OZF', 'OZF_SD_INVALID_PRICE_TYPE');
2050 FND_MSG_PUB.add;
2051 END IF;
2052 x_return_status := fnd_api.g_ret_sts_error;
2053 RETURN;
2054 END IF;
2055 END IF;
2056
2057 --Tolerance Type
2058 IF p_SDR_lines_tbl(i).end_customer_tolerance_type <> FND_API.g_miss_char AND p_SDR_lines_tbl(i).end_customer_tolerance_type IS NOT NULL THEN
2059 l_lookup_stat :=OZF_UTILITY_PVT.check_lookup_exists(
2060 p_lookup_table_name =>'OZF_LOOKUPS'
2061 ,p_lookup_type =>'OZF_SD_TOLERANCE_TYPE'
2062 ,p_lookup_code => p_SDR_lines_tbl(i).end_customer_tolerance_type);
2063
2064 IF l_lookup_stat = FND_API.g_false THEN
2065 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
2066 FND_MESSAGE.set_name('OZF', 'OZF_SD_BAD_TOLERANCE_TYPE');
2067 FND_MSG_PUB.add;
2068 END IF;
2069 x_return_status := fnd_api.g_ret_sts_error;
2070 RETURN;
2071 END IF;
2072 END IF;
2073
2074 --//Rejection Code
2075 IF p_SDR_lines_tbl(i).rejection_code <> FND_API.g_miss_char AND p_SDR_lines_tbl(i).rejection_code IS NOT NULL THEN
2076 l_lookup_stat :=OZF_UTILITY_PVT.check_lookup_exists(
2077 p_lookup_table_name =>'OZF_LOOKUPS'
2078 ,p_lookup_type =>'OZF_SD_REQ_LINE_REJECT_CODE'
2079 ,p_lookup_code => p_SDR_lines_tbl(i).rejection_code);
2080
2081 IF l_lookup_stat = FND_API.g_false THEN
2082 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
2083 FND_MESSAGE.set_name('OZF', 'OZF_SD_INVALID_REJECTION_CODE');
2084 FND_MSG_PUB.add;
2085 END IF;
2086 x_return_status := fnd_api.g_ret_sts_error;
2087 RETURN;
2088 END IF;
2089 END IF;
2090 l_status_code := get_system_status_code(p_SDR_hdr_rec.user_status_id);
2091 IF G_DEBUG THEN
2092 OZF_UTILITY_PVT.debug_message('Validate Product Lines Status Code :'||l_status_code);
2093 END IF;
2094
2095 --//Bugfix : 8511949
2096 --//Populate Approved discount type and Value in the following statuses. If value is not passed, default it from requested_discount_type and Value
2097 IF l_status_code IN ('SUPPLIER_APPROVED'
2098 ,'PENDING_SALES_APPROVAL'
2099 ,'SALES_APPROVED'
2100 ,'PENDING_OFFER_APPROVAL'
2101 ,'ACTIVE') THEN
2102 IF G_DEBUG THEN
2103 OZF_UTILITY_PVT.debug_message('Validate Product Lines Status Code INSIDE');
2104 END IF;
2105
2106 --//Approved discount type
2107 IF p_SDR_lines_tbl(i).approved_discount_type <> FND_API.g_miss_char AND p_SDR_lines_tbl(i).approved_discount_type IS NOT NULL THEN
2108 l_lookup_stat :=OZF_UTILITY_PVT.check_lookup_exists(
2109 p_lookup_table_name =>'OZF_LOOKUPS'
2110 ,p_lookup_type =>'OZF_SP_REQUEST_DISTYPE'
2111 ,p_lookup_code => p_SDR_lines_tbl(i).approved_discount_type);
2112
2113 IF l_lookup_stat =FND_API.g_false THEN
2114 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
2115 FND_MESSAGE.set_name('OZF', 'OZF_SD_INVALID_APPROVED_DISC_TYPE');
2116 FND_MSG_PUB.add;
2117 END IF;
2118 x_return_status := fnd_api.g_ret_sts_error;
2119 RETURN;
2120 END IF;
2121 ELSE
2122 p_SDR_lines_tbl(i).approved_discount_type := p_SDR_lines_tbl(i).requested_discount_type;
2123 END IF;
2124
2125 --//Bugfix : 12673769
2126 /*
2127 --//Approved discount Value
2128 IF p_SDR_lines_tbl(i).approved_discount_value <> FND_API.g_miss_num AND p_SDR_lines_tbl(i).approved_discount_value IS NOT NULL THEN
2129 l_status := check_zero(p_SDR_lines_tbl(i).approved_discount_value);
2130 IF l_status = FND_API.g_false THEN
2131 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
2132 FND_MESSAGE.set_name('OZF', 'OZF_SD_APPR_DISC_VALUE_IS_ZERO');
2133 FND_MSG_PUB.add;
2134 END IF;
2135 x_return_status := fnd_api.g_ret_sts_error;
2136 RETURN;
2137 END IF;
2138 ELSE
2139 p_SDR_lines_tbl(i).approved_discount_value := p_SDR_lines_tbl(i).requested_discount_value;
2140 END IF;
2141 */
2142 IF p_SDR_lines_tbl(i).approved_discount_value = FND_API.g_miss_num OR p_SDR_lines_tbl(i).approved_discount_value IS NULL THEN
2143 p_SDR_lines_tbl(i).approved_discount_value := p_SDR_lines_tbl(i).requested_discount_value;
2144 END IF;
2145
2146 --//Approved Discount Currency
2147 IF p_SDR_lines_tbl(i).approved_discount_currency <> FND_API.g_miss_char AND p_SDR_lines_tbl(i).approved_discount_currency IS NOT NULL THEN
2148 l_currency_var := NULL;
2149 OPEN c_currency(p_SDR_lines_tbl(i).approved_discount_currency);
2150 FETCH c_currency INTO l_currency_var;
2151 CLOSE c_currency;
2152
2153 IF l_currency_var IS NULL THEN
2154 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
2155 FND_MESSAGE.set_name('OZF', 'OZF_INVALID_APPR_DISC_CURR');
2156 --//A value must be entered for Product Cost
2157 FND_MSG_PUB.add;
2158 END IF;
2159 x_return_status := fnd_api.g_ret_sts_error;
2160 RETURN;
2161 END IF;
2162 ELSE
2163 p_SDR_lines_tbl(i).approved_discount_currency := p_SDR_lines_tbl(i).requested_discount_currency;
2164 END IF;
2165
2166 --//Approved Max Qty
2167 IF p_SDR_lines_tbl(i).approved_max_qty <> FND_API.g_miss_num AND p_SDR_lines_tbl(i).approved_max_qty IS NOT NULL THEN
2168 l_status := check_zero(p_SDR_lines_tbl(i).approved_max_qty);
2169 IF l_status = FND_API.g_false THEN
2170 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
2171 FND_MESSAGE.set_name('OZF', 'OZF_SD_APPR_MAX_QTY_VALUE_IS_ZERO');
2172 FND_MSG_PUB.add;
2173 END IF;
2174 x_return_status := fnd_api.g_ret_sts_error;
2175 RETURN;
2176 END IF;
2177 ELSE
2178 p_SDR_lines_tbl(i).approved_max_qty := p_SDR_lines_tbl(i).max_qty;
2179 END IF;
2180
2181 /* BugFix : 7501013
2182 ELSE
2183 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
2184 FND_MESSAGE.set_name('OZF', 'OZF_SD_NO_APPROVED_MAX_QTY');
2185 FND_MSG_PUB.add;
2186 END IF;
2187 x_return_status := fnd_api.g_ret_sts_error;
2188 RETURN; */
2189
2190 ELSIF l_status_code IN ('DRAFT'
2191 ,'ASSIGNED'
2192 ,'PENDING_SUPPLIER_APPROVAL') THEN
2193 p_SDR_lines_tbl(i).approved_discount_type := NULL;
2194 p_SDR_lines_tbl(i).approved_discount_value := NULL;
2195 p_SDR_lines_tbl(i).approved_max_qty := NULL;
2196 p_SDR_lines_tbl(i).approved_discount_currency := NULL;
2197
2198 END IF;
2199
2200 END LOOP;
2201 END validate_product_lines;
2202
2203 ---------------------------------------------------------------------
2204 -- PROCEDURE
2205 -- validate_customer_items
2206 --
2207 -- PURPOSE
2208 -- This procedure validates customer record table
2209 --Parameters
2210 -- p_SDR_cust_tbl -Customer recordset
2211 -- p_mode -Insert /Update Mode
2212 -- x_return_status - Result
2213 ---------------------------------------------------------------------
2214 PROCEDURE validate_customer_items(
2215 p_SDR_cust_tbl IN OUT NOCOPY SDR_cust_tbl_type
2216 ,p_mode IN VARCHAR2
2217 ,x_return_status OUT NOCOPY VARCHAR2
2218 )
2219 IS
2220 l_lookup_stat VARCHAR2(1); --To validate from lookups
2221
2222 l_request_customer_id NUMBER;
2223 l_cust_account_id NUMBER;
2224 l_party_id NUMBER;
2225 l_bg_party_id NUMBER;
2226 l_site_use_id NUMBER;
2227 l_cust_usage_chk NUMBER;
2228 l_old_cust_details OZF_SD_REQUEST_PUB.SDR_cust_rec_type;
2229
2230
2231 CURSOR c_request_customer_id(p_request_customer_id IN NUMBER,p_request_header_id IN NUMBER)IS
2232 SELECT request_customer_id
2233 FROM ozf_sd_customer_details
2234 WHERE request_customer_id = p_request_customer_id
2235 AND request_header_id = p_request_header_id ;
2236
2237 CURSOR c_party_id(p_party_id IN NUMBER)IS
2238 SELECT party_id
2239 FROM hz_parties
2240 WHERE party_id = p_party_id;
2241
2242 CURSOR c_cust_account_id(p_cust_account_id IN NUMBER)IS
2243 SELECT cust_acct.cust_account_id
2244 FROM hz_parties party,
2245 hz_cust_accounts cust_acct
2246 WHERE cust_acct.party_id = party.party_id
2247 AND cust_acct.status = 'A'
2248 AND cust_acct.cust_account_id = p_cust_account_id;
2249
2250 CURSOR c_site_use_id(p_cust_account_id IN NUMBER
2251 ,p_party_id IN NUMBER
2252 ,p_site_use_id IN NUMBER
2253 ,p_site_use_code IN VARCHAR2)IS
2254 SELECT sites.site_use_id
2255 FROM hz_cust_site_uses sites,
2256 hz_cust_acct_sites acct_sites,
2257 hz_party_sites party_sites
2258 WHERE sites.cust_acct_site_id = acct_sites.cust_acct_site_id
2259 AND acct_sites.party_site_id = party_sites.party_site_id
2260 AND acct_sites.cust_account_id = p_cust_account_id
2261 AND party_sites.party_id = p_party_id
2262 AND sites.site_use_id = p_site_use_id
2263 AND sites.site_use_code = p_site_use_code;
2264
2265 CURSOR c_old_cust_details(p_request_customer_id IN NUMBER)IS
2266 SELECT object_version_number,
2267 request_header_id,
2268 cust_account_id,
2269 party_id,
2270 site_use_id,
2271 cust_usage_code,
2272 attribute_category,
2273 attribute1,
2274 attribute2,
2275 attribute3,
2276 attribute4,
2277 attribute5,
2278 attribute6,
2279 attribute7,
2280 attribute8,
2281 attribute9,
2282 attribute10,
2283 attribute11,
2284 attribute12,
2285 attribute13,
2286 attribute14,
2287 attribute15,
2288 end_customer_flag,
2289 cust_usage_value
2290 FROM ozf_sd_customer_details
2291 WHERE request_customer_id = p_request_customer_id;
2292
2293 CURSOR c_buying_group(p_party_id IN NUMBER)IS
2294 SELECT party_id
2295 FROM ams_party_market_segments ams
2296 WHERE ams.market_qualifier_type = 'BG'
2297 AND ams.market_qualifier_reference = ams.party_id
2298 AND EXISTS
2299 (SELECT 1
2300 FROM ams_party_market_segments
2301 WHERE market_qualifier_type = 'BG'
2302 AND market_qualifier_reference = ams.market_qualifier_reference
2303 AND market_qualifier_reference <> party_id)
2304 AND party_id = p_party_id;
2305
2306 CURSOR c_get_list_header(p_list_header_id IN VARCHAR2)IS
2307 SELECT 1
2308 FROM ams_list_headers_all
2309 WHERE status_code IN ( 'AVAILABLE','LOCKED','EXECUTED','EXECUTING','VALIDATED','VALIDATING')
2310 AND list_header_id = p_list_header_id;
2311
2312 CURSOR c_get_segment(p_cell_id IN VARCHAR2)IS
2313 SELECT 1
2314 FROM AMS_CELLS_ALL_B
2315 WHERE status_code = 'AVAILABLE'
2316 AND cell_id = p_cell_id;
2317
2318 CURSOR c_get_territory (p_terr_id IN VARCHAR2) IS
2319 SELECT 1
2320 FROM JTF_TERR_QTYPE_USGS_ALL jtqu,
2321 JTF_TERR_ALL jt,
2322 JTF_QUAL_TYPE_USGS jqtu
2323 WHERE ( TRUNC(jt.start_date_active) <= TRUNC(SYSDATE)
2324 AND ( TRUNC(jt.end_date_active) >= TRUNC(SYSDATE)
2325 OR jt.end_date_active IS NULL ) )
2326 AND jt.terr_id = jtqu.terr_id
2327 AND jtqu.qual_type_usg_id = jqtu.qual_type_usg_id
2328 AND jqtu.source_id = -1003
2329 AND jqtu.qual_type_id = -1007
2330 AND jt.terr_id = p_terr_id;
2331
2332 BEGIN
2333
2334 x_return_status := FND_API.G_RET_STS_SUCCESS;
2335
2336 FOR j IN p_SDR_cust_tbl.FIRST..p_SDR_cust_tbl.LAST LOOP
2337
2338 --//Update Mode Check
2339 IF p_mode ='UPDATE' THEN
2340
2341 IF p_SDR_cust_tbl(j).request_customer_id <> FND_API.g_miss_num AND p_SDR_cust_tbl(j).request_customer_id IS NOT NULL THEN
2342 OPEN c_request_customer_id (p_SDR_cust_tbl(j).request_customer_id,G_REQUEST_HEADER_ID);
2343 FETCH c_request_customer_id INTO l_request_customer_id;
2344 CLOSE c_request_customer_id;
2345
2346 IF l_request_customer_id IS NULL THEN
2347 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
2348 FND_MESSAGE.set_name('OZF', 'OZF_SD_INVALID_REQUEST_CUSTOMER_ID');
2349 FND_MSG_PUB.add;
2350 END IF;
2351 x_return_status := fnd_api.g_ret_sts_error;
2352 RETURN;
2353 ELSE
2354 --//Set old value to New If NULL.
2355 OPEN c_old_cust_details(p_SDR_cust_tbl(j).request_customer_id);
2356 FETCH c_old_cust_details INTO l_old_cust_details.object_version_number,
2357 l_old_cust_details.request_header_id,
2358 l_old_cust_details.cust_account_id,
2359 l_old_cust_details.party_id,
2360 l_old_cust_details.site_use_id,
2361 l_old_cust_details.cust_usage_code,
2362 l_old_cust_details.attribute_category,
2363 l_old_cust_details.attribute1,
2364 l_old_cust_details.attribute2,
2365 l_old_cust_details.attribute3,
2366 l_old_cust_details.attribute4,
2367 l_old_cust_details.attribute5,
2368 l_old_cust_details.attribute6,
2369 l_old_cust_details.attribute7,
2370 l_old_cust_details.attribute8,
2371 l_old_cust_details.attribute9,
2372 l_old_cust_details.attribute10,
2373 l_old_cust_details.attribute11,
2374 l_old_cust_details.attribute12,
2375 l_old_cust_details.attribute13,
2376 l_old_cust_details.attribute14,
2377 l_old_cust_details.attribute15,
2378 l_old_cust_details.end_customer_flag,
2379 l_old_cust_details.cust_usage_value; --ER 9779889
2380
2381 CLOSE c_old_cust_details;
2382 p_SDR_cust_tbl(j).object_version_number := l_old_cust_details.object_version_number;
2383 p_SDR_cust_tbl(j).request_header_id := NVL(p_SDR_cust_tbl(j).request_header_id,l_old_cust_details.request_header_id);
2384 p_SDR_cust_tbl(j).cust_account_id := NVL(p_SDR_cust_tbl(j).cust_account_id,l_old_cust_details.cust_account_id);
2385 p_SDR_cust_tbl(j).party_id := NVL(p_SDR_cust_tbl(j).party_id,l_old_cust_details.party_id);
2386 p_SDR_cust_tbl(j).site_use_id := NVL(p_SDR_cust_tbl(j).site_use_id,l_old_cust_details.site_use_id);
2387 p_SDR_cust_tbl(j).cust_usage_code := NVL(p_SDR_cust_tbl(j).cust_usage_code,l_old_cust_details.cust_usage_code);
2388 p_SDR_cust_tbl(j).attribute_category := NVL(p_SDR_cust_tbl(j).attribute_category,l_old_cust_details.attribute_category);
2389 p_SDR_cust_tbl(j).attribute1 := NVL(p_SDR_cust_tbl(j).attribute1,l_old_cust_details.attribute1);
2390 p_SDR_cust_tbl(j).attribute2 := NVL(p_SDR_cust_tbl(j).attribute2,l_old_cust_details.attribute2);
2391 p_SDR_cust_tbl(j).attribute3 := NVL(p_SDR_cust_tbl(j).attribute3,l_old_cust_details.attribute3);
2392 p_SDR_cust_tbl(j).attribute4 := NVL(p_SDR_cust_tbl(j).attribute4,l_old_cust_details.attribute4);
2393 p_SDR_cust_tbl(j).attribute5 := NVL(p_SDR_cust_tbl(j).attribute5,l_old_cust_details.attribute5);
2394 p_SDR_cust_tbl(j).attribute6 := NVL(p_SDR_cust_tbl(j).attribute6,l_old_cust_details.attribute6);
2395 p_SDR_cust_tbl(j).attribute7 := NVL(p_SDR_cust_tbl(j).attribute7,l_old_cust_details.attribute7);
2396 p_SDR_cust_tbl(j).attribute8 := NVL(p_SDR_cust_tbl(j).attribute8,l_old_cust_details.attribute8);
2397 p_SDR_cust_tbl(j).attribute9 := NVL(p_SDR_cust_tbl(j).attribute9,l_old_cust_details.attribute9);
2398 p_SDR_cust_tbl(j).attribute10 := NVL(p_SDR_cust_tbl(j).attribute10,l_old_cust_details.attribute10);
2399 p_SDR_cust_tbl(j).attribute11 := NVL(p_SDR_cust_tbl(j).attribute11,l_old_cust_details.attribute11);
2400 p_SDR_cust_tbl(j).attribute12 := NVL(p_SDR_cust_tbl(j).attribute12,l_old_cust_details.attribute12);
2401 p_SDR_cust_tbl(j).attribute13 := NVL(p_SDR_cust_tbl(j).attribute13,l_old_cust_details.attribute13);
2402 p_SDR_cust_tbl(j).attribute14 := NVL(p_SDR_cust_tbl(j).attribute14,l_old_cust_details.attribute14);
2403 p_SDR_cust_tbl(j).attribute15 := NVL(p_SDR_cust_tbl(j).attribute15,l_old_cust_details.attribute15);
2404 p_SDR_cust_tbl(j).end_customer_flag := NVL(p_SDR_cust_tbl(j).end_customer_flag,l_old_cust_details.end_customer_flag);
2405 p_SDR_cust_tbl(j).cust_usage_value := NVL(p_SDR_cust_tbl(j).cust_usage_value,l_old_cust_details.cust_usage_value); --ER 9779889
2406 END IF;
2407 END IF;
2408 END IF;
2409
2410 --//End Customer Flag check
2411 IF p_SDR_cust_tbl(j).end_customer_flag <> FND_API.g_miss_char AND p_SDR_cust_tbl(j).end_customer_flag IS NOT NULL THEN
2412
2413 IF p_SDR_cust_tbl(j).end_customer_flag NOT IN ('N','Y') THEN
2414
2415 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
2416 FND_MESSAGE.set_name('OZF', 'OZF_SD_INVALID_END_CUST_FLAG');
2417 --//Invalid End Customer flag
2418 FND_MSG_PUB.add;
2419 END IF;
2420 x_return_status := fnd_api.g_ret_sts_error;
2421 RETURN;
2422 END IF;
2423 ELSE
2424 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
2425 FND_MESSAGE.set_name('OZF', 'OZF_SD_NO_END_CUST_FLAG');
2426 --//End Customer Flag is Mandatory
2427 FND_MSG_PUB.add;
2428 END IF;
2429 x_return_status := fnd_api.g_ret_sts_error;
2430 RETURN;
2431 END IF;
2432
2433 --//Customer usage code Check
2434 IF p_SDR_cust_tbl(j).cust_usage_code <> FND_API.g_miss_char AND p_SDR_cust_tbl(j).cust_usage_code IS NOT NULL THEN
2435
2436 l_lookup_stat :=OZF_UTILITY_PVT.check_lookup_exists(
2437 p_lookup_table_name =>'OZF_LOOKUPS'
2438 ,p_lookup_type =>'OZF_SD_CUSTOMER_TYPE'
2439 ,p_lookup_code => p_SDR_cust_tbl(j).cust_usage_code);
2440
2441 IF l_lookup_stat = FND_API.g_false THEN
2442 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
2443 FND_MESSAGE.set_name('OZF', 'OZF_SD_INVALID_CUST_ADDR_TYPE');
2444 FND_MSG_PUB.add;
2445 END IF;
2446 x_return_status := fnd_api.g_ret_sts_error;
2447 RETURN;
2448 END IF;
2449
2450 --//if end_customer_flag = 'Y' then cust_usage_code should be CUSTOMER only
2451 IF ((p_SDR_cust_tbl(j).end_customer_flag ='Y')
2452 AND (p_SDR_cust_tbl(j).cust_usage_code <> 'CUSTOMER')) THEN
2453 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
2454 FND_MESSAGE.set_name('OZF', 'OZF_SD_INVALID_CUST_COMB');
2455 FND_MSG_PUB.add;
2456 END IF;
2457 x_return_status := fnd_api.g_ret_sts_error;
2458 RETURN;
2459 END IF;
2460
2461 --ER 9779889
2462 IF p_SDR_cust_tbl(j).cust_usage_code IN ('CUSTOMER','BILL_TO','SHIP_TO','BUYING_GROUP') THEN
2463 p_SDR_cust_tbl(j).cust_usage_value := NULL;
2464
2465 --//Party ID is mandatory for All Combinations
2466 IF p_SDR_cust_tbl(j).party_id <> FND_API.g_miss_num AND p_SDR_cust_tbl(j).party_id IS NOT NULL THEN
2467
2468 IF p_SDR_cust_tbl(j).cust_usage_code = 'BUYING_GROUP' THEN
2469 OPEN c_buying_group (p_SDR_cust_tbl(j).party_id);
2470 FETCH c_buying_group INTO l_bg_party_id;
2471 CLOSE c_buying_group;
2472
2473 IF l_bg_party_id IS NULL THEN
2474 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
2475 FND_MESSAGE.set_name('OZF', 'OZF_SD_INVALID_BUYING_GRP');
2476 --//Buying Group selected is invalid. Please select a valid Buying Group.
2477 FND_MSG_PUB.add;
2478 END IF;
2479 x_return_status := fnd_api.g_ret_sts_error;
2480 RETURN;
2481 END IF;
2482 ELSE
2483 OPEN c_party_id (p_SDR_cust_tbl(j).party_id);
2484 FETCH c_party_id INTO l_party_id;
2485 CLOSE c_party_id;
2486
2487 IF l_party_id IS NULL THEN
2488 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
2489 FND_MESSAGE.set_name('OZF', 'OZF_SD_INVALID_PARTY_ID');
2490 FND_MSG_PUB.add;
2491 END IF;
2492 x_return_status := fnd_api.g_ret_sts_error;
2493 RETURN;
2494 END IF;
2495 END IF;
2496 ELSE
2497 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
2498 FND_MESSAGE.set_name('OZF', 'OZF_SD_NO_PARTY_ID');
2499 --//Party Id is mandatory
2500 FND_MSG_PUB.add;
2501 END IF;
2502 x_return_status := fnd_api.g_ret_sts_error;
2503 RETURN;
2504 END IF;
2505
2506 IF p_SDR_cust_tbl(j).cust_usage_code ='CUSTOMER' THEN
2507
2508 --//Cust Account ID
2509 IF p_SDR_cust_tbl(j).cust_account_id <> FND_API.g_miss_num AND p_SDR_cust_tbl(j).cust_account_id IS NOT NULL THEN
2510 OPEN c_cust_account_id (p_SDR_cust_tbl(j).cust_account_id);
2511 FETCH c_cust_account_id INTO l_cust_account_id;
2512 CLOSE c_cust_account_id;
2513
2514 IF l_cust_account_id IS NULL THEN
2515 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
2516 FND_MESSAGE.set_name('OZF', 'OZF_SD_INVALID_CUST_ACCOUNT_ID');
2517 FND_MSG_PUB.add;
2518 END IF;
2519 x_return_status := fnd_api.g_ret_sts_error;
2520 RETURN;
2521 END IF;
2522 ELSE
2523 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
2524 FND_MESSAGE.set_name('OZF', 'OZF_SD_NO_CUST_ACCOUNT_ID');
2525 FND_MSG_PUB.add;
2526 END IF;
2527 x_return_status := fnd_api.g_ret_sts_error;
2528 RETURN;
2529 END IF;
2530
2531 --//For Bill To/Ship To Site Use Id is Mandatory
2532 ELSIF p_SDR_cust_tbl(j).cust_usage_code IN ('BILL_TO','SHIP_TO') THEN
2533
2534 --//Cust Account ID
2535 IF p_SDR_cust_tbl(j).cust_account_id <> FND_API.g_miss_num AND p_SDR_cust_tbl(j).cust_account_id IS NOT NULL THEN
2536 OPEN c_cust_account_id (p_SDR_cust_tbl(j).cust_account_id);
2537 FETCH c_cust_account_id INTO l_cust_account_id;
2538 CLOSE c_cust_account_id;
2539
2540 IF l_cust_account_id IS NULL THEN
2541 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
2542 FND_MESSAGE.set_name('OZF', 'OZF_SD_INVALID_CUST_ACCOUNT_ID');
2543 FND_MSG_PUB.add;
2544 END IF;
2545 x_return_status := fnd_api.g_ret_sts_error;
2546 RETURN;
2547 END IF;
2548 END IF;
2549
2550 --//Site Use Id
2551 IF p_SDR_cust_tbl(j).site_use_id <> FND_API.g_miss_num AND p_SDR_cust_tbl(j).site_use_id IS NOT NULL THEN
2552 OPEN c_site_use_id (p_SDR_cust_tbl(j).cust_account_id
2553 ,p_SDR_cust_tbl(j).party_id
2554 ,p_SDR_cust_tbl(j).site_use_id
2555 ,p_SDR_cust_tbl(j).cust_usage_code);
2556 FETCH c_site_use_id INTO l_site_use_id;
2557 CLOSE c_site_use_id;
2558
2559 IF l_site_use_id IS NULL THEN
2560 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
2561 FND_MESSAGE.set_name('OZF', 'OZF_SD_INVALID_SITE_USE_ID');
2562 FND_MSG_PUB.add;
2563 END IF;
2564 x_return_status := fnd_api.g_ret_sts_error;
2565 RETURN;
2566 END IF;
2567 ELSE
2568 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
2569 FND_MESSAGE.set_name('OZF', 'OZF_SD_NO_SITE_USE_ID');
2570 FND_MSG_PUB.add;
2571 END IF;
2572 x_return_status := fnd_api.g_ret_sts_error;
2573 RETURN;
2574 END IF;
2575 ELSIF p_SDR_cust_tbl(j).cust_usage_code ='BUYING_GROUP' THEN
2576 p_SDR_cust_tbl(j).cust_account_id := NULL;
2577 p_SDR_cust_tbl(j).site_use_id := NULL;
2578 END IF;
2579
2580 --ER 9779889
2581 ELSIF p_SDR_cust_tbl(j).cust_usage_code IN ('LIST','SEGMENT','TERRITORY') THEN
2582 IF p_SDR_cust_tbl(j).cust_usage_value = FND_API.g_miss_char OR p_SDR_cust_tbl(j).cust_usage_value IS NULL THEN
2583 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
2584 FND_MESSAGE.set_name('OZF', 'OZF_SD_NO_CUST_USAGE_VALUE');
2585 --//
2586 FND_MSG_PUB.add;
2587 END IF;
2588 x_return_status := fnd_api.g_ret_sts_error;
2589 RETURN;
2590 END IF;
2591
2592 p_SDR_cust_tbl(j).party_id := NULL;
2593 p_SDR_cust_tbl(j).cust_account_id := NULL;
2594 p_SDR_cust_tbl(j).site_use_id := NULL;
2595 l_cust_usage_chk := NULL;
2596
2597 IF p_SDR_cust_tbl(j).cust_usage_code ='LIST' THEN
2598 OPEN c_get_list_header (p_SDR_cust_tbl(j).cust_usage_value);
2599 FETCH c_get_list_header INTO l_cust_usage_chk;
2600 CLOSE c_get_list_header;
2601
2602 IF l_cust_usage_chk IS NULL THEN
2603 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
2604 FND_MESSAGE.set_name('OZF', 'OZF_SD_INVALID_LIST');
2605 --//List selected is invalid. Please select a valid List.
2606 FND_MSG_PUB.add;
2607 END IF;
2608 x_return_status := fnd_api.g_ret_sts_error;
2609 RETURN;
2610 END IF;
2611
2612 ELSIF p_SDR_cust_tbl(j).cust_usage_code ='SEGMENT' THEN
2613 OPEN c_get_segment (p_SDR_cust_tbl(j).cust_usage_value);
2614 FETCH c_get_segment INTO l_cust_usage_chk;
2615 CLOSE c_get_segment;
2616
2617 IF l_cust_usage_chk IS NULL THEN
2618 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
2619 FND_MESSAGE.set_name('OZF', 'OZF_SD_INVALID_SEGMENT');
2620 --//Segment selected is invalid. Please select a valid Segment.
2621 FND_MSG_PUB.add;
2622 END IF;
2623 x_return_status := fnd_api.g_ret_sts_error;
2624 RETURN;
2625 END IF;
2626
2627 ELSIF p_SDR_cust_tbl(j).cust_usage_code ='TERRITORY' THEN
2628 OPEN c_get_territory (p_SDR_cust_tbl(j).cust_usage_value);
2629 FETCH c_get_territory INTO l_cust_usage_chk;
2630 CLOSE c_get_territory;
2631
2632 IF l_cust_usage_chk IS NULL THEN
2633 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
2634 FND_MESSAGE.set_name('OZF', 'OZF_SD_INVALID_TERRITORY');
2635 --//Territory selected is invalid. Please select a valid Territory.
2636 FND_MSG_PUB.add;
2637 END IF;
2638 x_return_status := fnd_api.g_ret_sts_error;
2639 RETURN;
2640 END IF;
2641 END IF;
2642 END IF;
2643 ELSE
2644 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
2645 FND_MESSAGE.set_name('OZF', 'OZF_SD_NO_CUST_ADDR_TYPE');
2646 --//Invalid Customer Usage Code
2647 FND_MSG_PUB.add;
2648 END IF;
2649 x_return_status := fnd_api.g_ret_sts_error;
2650 RETURN;
2651 END IF;
2652
2653 END LOOP;
2654 END validate_customer_items;
2655
2656 ---------------------------------------------------------------------
2657 -- PROCEDURE
2658 -- Insert_SDR_Header_record
2659 --
2660 -- PURPOSE
2661 -- This procedure Inserts record into SDR Header table
2662 ---------------------------------------------------------------------
2663 PROCEDURE insert_header_record(
2664 p_SDR_hdr_rec IN SDR_Hdr_rec_type
2665 ,p_request_source IN VARCHAR2
2666 ,x_request_header_id OUT NOCOPY NUMBER
2667 ,x_return_status OUT NOCOPY VARCHAR2)
2668 IS
2669
2670 l_SDR_hdr_rec OZF_SD_REQUEST_PUB.SDR_Hdr_rec_type := p_SDR_hdr_rec;
2671 l_req_hdr_seq NUMBER;
2672 l_code_prefix VARCHAR2(3);
2673 l_request_class VARCHAR2(30):='SD_REQUEST';
2674 --l_request_source VARCHAR2(30) :='API';
2675 l_root_request_header_id NUMBER;
2676
2677 CURSOR c_reqest_header_seq IS
2678 SELECT OZF_SD_REQUEST_HEADERS_ALL_B_S.nextval
2679 FROM dual;
2680
2681 CURSOR c_code_prefix(p_request_type_setup_id IN NUMBER) IS
2682 SELECT source_code_suffix
2683 FROM ams_custom_setups_vl
2684 WHERE custom_setup_id = p_request_type_setup_id;
2685
2686 BEGIN
2687
2688 x_return_status := FND_API.G_RET_STS_SUCCESS;
2689
2690 IF G_DEBUG THEN
2691 OZF_UTILITY_PVT.debug_message('Inside INSERT HEADER RECORD Procedure ');
2692 END IF;
2693
2694 IF l_SDR_hdr_rec.request_basis IS NULL THEN
2695 l_SDR_hdr_rec.request_basis := FND_PROFILE.value('OZF_SD_REQUEST_BASED');
2696 END IF;
2697
2698 OPEN c_reqest_header_seq;
2699 FETCH c_reqest_header_seq INTO l_req_hdr_seq;
2700 CLOSE c_reqest_header_seq;
2701
2702 --Generate Request Number, If Null
2703 IF l_SDR_hdr_rec.request_number = FND_API.g_miss_char OR l_SDR_hdr_rec.request_number IS NULL THEN
2704
2705 OPEN c_code_prefix(p_SDR_hdr_rec.request_type_setup_id);
2706 FETCH c_code_prefix INTO l_code_prefix;
2707 CLOSE c_code_prefix;
2708
2709 l_SDR_hdr_rec.request_number :=l_code_prefix||TO_CHAR(l_req_hdr_seq);
2710 IF G_DEBUG THEN
2711 OZF_UTILITY_PVT.debug_message('Request Number : '||l_SDR_hdr_rec.request_number);
2712 END IF;
2713
2714 END IF;
2715
2716 IF l_SDR_hdr_rec.request_header_id IS NOT NULL THEN
2717 --//Set the root request header id for Copy
2718 l_root_request_header_id :=l_SDR_hdr_rec.request_header_id;
2719 IF G_DEBUG THEN
2720 OZF_UTILITY_PVT.debug_message('Root Request Header ID :'||l_root_request_header_id);
2721 END IF;
2722 END IF;
2723
2724 OZF_SD_REQUEST_HEADER_PKG.Insert_Row(
2725 p_request_header_id =>l_req_hdr_seq
2726 ,p_object_version_number =>1
2727 ,p_last_update_date =>SYSDATE
2728 ,p_last_updated_by =>NVL(FND_GLOBAL.user_id,-1)
2729 ,p_creation_date =>SYSDATE
2730 ,p_created_by =>NVL(FND_GLOBAL.user_id,-1)
2731 ,p_last_update_login =>NVL(FND_GLOBAL.conc_login_id,-1)
2732 ,p_request_id =>FND_GLOBAL.CONC_REQUEST_ID
2733 ,p_program_application_id =>FND_GLOBAL.PROG_APPL_ID
2734 ,p_program_update_date =>SYSDATE
2735 ,p_program_id =>FND_GLOBAL.CONC_PROGRAM_ID
2736 ,p_created_from =>NULL
2737 ,p_request_number =>l_SDR_hdr_rec.request_number
2738 ,p_request_class =>l_request_class
2739 ,p_offer_type =>NULL
2740 ,p_offer_id =>NULL
2741 ,p_root_request_header_id =>l_root_request_header_id
2742 ,p_linked_request_header_id =>NULL
2743 ,p_request_start_date =>l_SDR_hdr_rec.request_start_date
2744 ,p_request_end_date =>l_SDR_hdr_rec.request_end_date
2745 ,p_user_status_id =>l_SDR_hdr_rec.user_status_id
2746 ,p_request_outcome =>l_SDR_hdr_rec.request_outcome
2747 ,p_decline_reason_code =>NULL
2748 ,p_return_reason_code =>NULL
2749 ,p_request_currency_code =>l_SDR_hdr_rec.request_currency_code
2750 ,p_authorization_number =>l_SDR_hdr_rec.authorization_number
2751 ,p_sd_requested_budget_amount =>NULL
2752 ,p_sd_approved_budget_amount =>NULL
2753 ,p_attribute_category =>l_SDR_hdr_rec.attribute_category
2754 ,p_attribute1 =>l_SDR_hdr_rec.attribute1
2755 ,p_attribute2 =>l_SDR_hdr_rec.attribute2
2756 ,p_attribute3 =>l_SDR_hdr_rec.attribute3
2757 ,p_attribute4 =>l_SDR_hdr_rec.attribute4
2758 ,p_attribute5 =>l_SDR_hdr_rec.attribute5
2759 ,p_attribute6 =>l_SDR_hdr_rec.attribute6
2760 ,p_attribute7 =>l_SDR_hdr_rec.attribute7
2761 ,p_attribute8 =>l_SDR_hdr_rec.attribute8
2762 ,p_attribute9 =>l_SDR_hdr_rec.attribute9
2763 ,p_attribute10 =>l_SDR_hdr_rec.attribute10
2764 ,p_attribute11 =>l_SDR_hdr_rec.attribute11
2765 ,p_attribute12 =>l_SDR_hdr_rec.attribute12
2766 ,p_attribute13 =>l_SDR_hdr_rec.attribute13
2767 ,p_attribute14 =>l_SDR_hdr_rec.attribute14
2768 ,p_attribute15 =>l_SDR_hdr_rec.attribute15
2769 ,p_supplier_id =>l_SDR_hdr_rec.supplier_id
2770 ,p_supplier_site_id =>l_SDR_hdr_rec.supplier_site_id
2771 ,p_supplier_contact_id =>l_SDR_hdr_rec.supplier_contact_id
2772 ,p_internal_submission_date =>l_SDR_hdr_rec.internal_submission_date
2773 ,p_assignee_response_by_date =>l_SDR_hdr_rec.assignee_response_by_date
2774 ,p_assignee_response_date =>l_SDR_hdr_rec.assignee_response_date
2775 ,p_submtd_by_for_supp_appr =>l_SDR_hdr_rec.submtd_by_for_supp_approval
2776 ,p_supplier_response_by_date =>l_SDR_hdr_rec.supplier_response_by_date
2777 ,p_supplier_response_date =>l_SDR_hdr_rec.supplier_response_date
2778 ,p_supplier_submission_date =>l_SDR_hdr_rec.supplier_submission_date
2779 ,p_requestor_id =>l_SDR_hdr_rec.requestor_id
2780 ,p_supplier_quote_number =>l_SDR_hdr_rec.supplier_quote_number
2781 ,p_internal_order_number =>l_SDR_hdr_rec.internal_order_number
2782 ,p_sales_order_currency =>l_SDR_hdr_rec.sales_order_currency
2783 ,p_request_source => p_request_source
2784 ,p_assignee_resource_id =>l_SDR_hdr_rec.assignee_resource_id
2785 ,p_org_id =>l_SDR_hdr_rec.org_id
2786 ,p_security_group_id =>NULL
2787 ,p_accrual_type =>l_SDR_hdr_rec.accrual_type
2788 ,p_cust_account_id =>l_SDR_hdr_rec.cust_account_id
2789 ,p_supplier_email =>l_SDR_hdr_rec.supplier_contact_email_address
2790 ,p_supplier_phone =>l_SDR_hdr_rec.supplier_contact_phone_number
2791 ,p_request_type_setup_id =>l_SDR_hdr_rec.request_type_setup_id
2792 ,p_request_basis =>l_SDR_hdr_rec.request_basis
2793 ,p_supplier_contact_name =>l_SDR_hdr_rec.supplier_contact_name); --//Bugfix : 7822442
2794
2795 x_request_header_id := l_req_hdr_seq;
2796
2797 EXCEPTION
2798 WHEN FND_API.G_EXC_ERROR THEN
2799 x_return_status := FND_API.G_RET_STS_ERROR;
2800 WHEN OTHERS THEN
2801 x_return_status := FND_API.g_ret_sts_unexp_error;
2802 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
2803 FND_MESSAGE.set_name('OZF', 'OZF_TABLE_HANDLER_ERROR');
2804 FND_MSG_PUB.add;
2805 END IF;
2806 End insert_header_record;
2807 ---------------------------------------------------------------------
2808 -- PROCEDURE
2809 -- Insert_translation_record
2810 --
2811 -- PURPOSE
2812 -- This procedure Insert records into SDR TL table
2813 ---------------------------------------------------------------------
2814 PROCEDURE populate_translation_record(
2815 p_request_header_id IN NUMBER,
2816 p_description IN VARCHAR2,
2817 p_org_id IN NUMBER,
2818 p_mode IN VARCHAR2,
2819 x_return_status OUT NOCOPY VARCHAR2)
2820 IS
2821
2822 BEGIN
2823 x_return_status := FND_API.G_RET_STS_SUCCESS;
2824
2825 IF p_mode ='CREATE' OR p_mode ='COPY' THEN
2826
2827 INSERT INTO ozf_sd_request_headers_all_tl
2828 (request_header_id,
2829 last_update_date,
2830 last_updated_by,
2831 creation_date,
2832 created_by,
2833 last_update_login,
2834 request_description,
2835 language,
2836 source_lang,
2837 request_id,
2838 program_application_id,
2839 program_update_date,
2840 program_id,
2841 created_from,
2842 security_group_id,
2843 org_id)
2844 SELECT
2845 p_request_header_id,
2846 SYSDATE,
2847 NVL(FND_GLOBAL.user_id,-1),
2848 SYSDATE,
2849 NVL(FND_GLOBAL.user_id,-1),
2850 NVL(FND_GLOBAL.conc_login_id,-1),
2851 p_description,
2852 l.language_code,
2853 USERENV('LANG'),
2854 FND_GLOBAL.CONC_REQUEST_ID,
2855 FND_GLOBAL.PROG_APPL_ID,
2856 SYSDATE,
2857 FND_GLOBAL.CONC_PROGRAM_ID,
2858 NULL,
2859 NULL,
2860 p_org_id
2861 FROM fnd_languages l
2862 WHERE l.installed_flag IN('I', 'B')
2863 AND NOT EXISTS(SELECT NULL
2864 FROM ozf_sd_request_headers_all_tl t
2865 WHERE t.request_header_id = p_request_header_id
2866 AND t.language = l.language_code);
2867
2868 ELSIF p_mode ='UPDATE' THEN
2869
2870 UPDATE ozf_sd_request_headers_all_tl
2871 SET request_description = p_description
2872 ,org_id = p_org_id
2873 WHERE request_header_id =p_request_header_id;
2874
2875 END IF;
2876
2877 EXCEPTION
2878 WHEN FND_API.G_EXC_ERROR THEN
2879 x_return_status := FND_API.G_RET_STS_ERROR;
2880 WHEN OTHERS THEN
2881 x_return_status := FND_API.g_ret_sts_unexp_error;
2882 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
2883 FND_MESSAGE.set_name('OZF', 'OZF_SD_TL_POPULATION_ERROR');
2884 FND_MSG_PUB.add;
2885 END IF;
2886
2887 END populate_translation_record;
2888 ---------------------------------------------------------------------
2889 -- PROCEDURE
2890 -- Insert_SDR_lines_record
2891 --
2892 -- PURPOSE
2893 -- This procedure Insert records into SDR Lines table
2894 ---------------------------------------------------------------------
2895 PROCEDURE populate_product_lines(
2896 p_request_header_id IN NUMBER
2897 ,p_SDR_lines_tbl IN SDR_lines_tbl_type
2898 ,x_return_status OUT NOCOPY VARCHAR2)
2899
2900 --,p_SDR_lines_tbl IN SDR_lines_tbl_type
2901
2902 IS
2903 -- l_api_name CONSTANT VARCHAR2(30) := 'insert lines record';
2904 -- l_api_version_number CONSTANT NUMBER := 1.0;
2905 l_req_line_seq NUMBER ;
2906 l_req_line_seq_id NUMBER;
2907
2908
2909 CURSOR c_val_reqest_lines_seq(p_request_line_id NUMBER) IS
2910 SELECT -1
2911 FROM ozf_sd_request_lines_all
2912 WHERE request_line_id = p_request_line_id;
2913
2914 CURSOR c_reqest_lines_seq IS
2915 SELECT ozf_sd_request_lines_all_s.nextval
2916 FROM dual;
2917
2918 BEGIN
2919 -- Initialize API return status to sucess
2920 x_return_status := FND_API.G_RET_STS_SUCCESS;
2921 l_req_line_seq := 0;
2922
2923 FOR p IN p_SDR_lines_tbl.FIRST..p_SDR_lines_tbl.LAST LOOP
2924
2925 IF p_SDR_lines_tbl(p).request_line_id <> FND_API.g_miss_num AND p_SDR_lines_tbl(p).request_line_id IS NOT NULL THEN
2926 -- l_req_line_seq := p_SDR_lines_tbl(p).request_line_id; --fix for bug 15882888
2927 OPEN c_val_reqest_lines_seq(p_SDR_lines_tbl(p).request_line_id);
2928 FETCH c_val_reqest_lines_seq into l_req_line_seq;
2929 CLOSE c_val_reqest_lines_seq;
2930 ELSE
2931 OPEN c_reqest_lines_seq;
2932 FETCH c_reqest_lines_seq INTO l_req_line_seq;
2933 CLOSE c_reqest_lines_seq;
2934 END IF;
2935
2936 --IF G_DEBUG THEN
2937 OZF_UTILITY_PVT.debug_message('Count :'||p_SDR_lines_tbl.count);
2938 OZF_UTILITY_PVT.debug_message('l_req_line_seq :'|| l_req_line_seq);
2939 OZF_UTILITY_PVT.debug_message('l_req_line_seq_id :'|| l_req_line_seq_id);
2940 -- END IF;
2941
2942
2943 IF l_req_line_seq <> -1 THEN
2944
2945 OZF_UTILITY_PVT.debug_message('populate_product_lines - Create Mode');
2946
2947 OZF_SD_REQUEST_LINES_PKG.Insert_Row(
2948 p_request_line_id =>l_req_line_seq
2949 ,p_object_version_number =>1
2950 ,p_last_update_date =>SYSDATE
2951 ,p_last_updated_by =>NVL(FND_GLOBAL.user_id,-1)
2952 ,p_creation_date =>SYSDATE
2953 ,p_created_by =>NVL(FND_GLOBAL.user_id,-1)
2954 ,p_last_update_login =>NVL(FND_GLOBAL.conc_login_id,-1)
2955 ,p_request_id =>FND_GLOBAL.CONC_REQUEST_ID
2956 ,p_program_application_id =>FND_GLOBAL.PROG_APPL_ID
2957 ,p_program_update_date =>SYSDATE
2958 ,p_program_id =>FND_GLOBAL.CONC_PROGRAM_ID
2959 ,p_create_from =>p_SDR_lines_tbl(p).create_from
2960 ,p_request_header_id =>p_request_header_id
2961 ,p_product_context =>p_SDR_lines_tbl(p).product_context
2962 ,p_inventory_item_id =>p_SDR_lines_tbl(p).inventory_item_id
2963 ,p_prod_catg_id =>p_SDR_lines_tbl(p).prod_catg_id
2964 ,p_product_cat_set_id =>p_SDR_lines_tbl(p).product_cat_set_id
2965 ,p_product_cost =>p_SDR_lines_tbl(p).product_cost
2966 ,p_item_uom =>p_SDR_lines_tbl(p).item_uom
2967 ,p_requested_discount_type =>p_SDR_lines_tbl(p).requested_discount_type
2968 ,p_requested_discount_value =>p_SDR_lines_tbl(p).requested_discount_value
2969 ,p_cost_basis =>p_SDR_lines_tbl(p).cost_basis
2970 ,p_max_qty =>p_SDR_lines_tbl(p).max_qty
2971 ,p_limit_qty =>p_SDR_lines_tbl(p).limit_qty
2972 ,p_design_win =>p_SDR_lines_tbl(p).design_win
2973 ,p_end_customer_price =>p_SDR_lines_tbl(p).end_customer_price
2974 ,p_requested_line_amount =>p_SDR_lines_tbl(p).requested_line_amount
2975 ,p_approved_discount_type =>p_SDR_lines_tbl(p).approved_discount_type
2976 ,p_approved_discount_value =>p_SDR_lines_tbl(p).approved_discount_value
2977 ,p_approved_amount =>NULL
2978 ,p_total_requested_amount =>NULL
2979 ,p_total_approved_amount =>NULL
2980 ,p_approved_max_qty =>p_SDR_lines_tbl(p).approved_max_qty
2981 ,p_attribute_category =>p_SDR_lines_tbl(p).attribute_category
2982 ,p_attribute1 =>p_SDR_lines_tbl(p).attribute1
2983 ,p_attribute2 =>p_SDR_lines_tbl(p).attribute2
2984 ,p_attribute3 =>p_SDR_lines_tbl(p).attribute3
2985 ,p_attribute4 =>p_SDR_lines_tbl(p).attribute4
2986 ,p_attribute5 =>p_SDR_lines_tbl(p).attribute5
2987 ,p_attribute6 =>p_SDR_lines_tbl(p).attribute6
2988 ,p_attribute7 =>p_SDR_lines_tbl(p).attribute7
2989 ,p_attribute8 =>p_SDR_lines_tbl(p).attribute8
2990 ,p_attribute9 =>p_SDR_lines_tbl(p).attribute9
2991 ,p_attribute10 =>p_SDR_lines_tbl(p).attribute10
2992 ,p_attribute11 =>p_SDR_lines_tbl(p).attribute11
2993 ,p_attribute12 =>p_SDR_lines_tbl(p).attribute12
2994 ,p_attribute13 =>p_SDR_lines_tbl(p).attribute13
2995 ,p_attribute14 =>p_SDR_lines_tbl(p).attribute14
2996 ,p_attribute15 =>p_SDR_lines_tbl(p).attribute15
2997 ,p_vendor_approved_flag =>p_SDR_lines_tbl(p).vendor_approved_flag
2998 ,p_vendor_item_code =>p_SDR_lines_tbl(p).vendor_item_code
2999 ,p_start_date =>p_SDR_lines_tbl(p).start_date
3000 ,p_end_date =>p_SDR_lines_tbl(p).end_date
3001 ,p_end_customer_price_type =>p_SDR_lines_tbl(p).end_customer_price_type
3002 ,p_end_customer_tolerance_type =>p_SDR_lines_tbl(p).end_customer_tolerance_type
3003 ,p_end_customer_tolerance_value =>p_SDR_lines_tbl(p).end_customer_tolerance_value
3004 ,p_security_group_id =>NULL
3005 ,p_org_id =>G_ITEM_ORG_ID
3006 ,p_rejection_code =>p_SDR_lines_tbl(p).rejection_code
3007 ,p_discount_currency =>p_SDR_lines_tbl(p).requested_discount_currency
3008 ,p_product_cost_currency =>p_SDR_lines_tbl(p).product_cost_currency
3009 ,p_end_customer_currency =>p_SDR_lines_tbl(p).end_customer_currency
3010 ,p_approved_discount_currency =>p_SDR_lines_tbl(p).approved_discount_currency);
3011
3012 ELSE --UPDATE MODE
3013
3014 OZF_UTILITY_PVT.debug_message('populate_product_lines - Update Mode');
3015
3016 OZF_SD_REQUEST_LINES_PKG.Update_Row(
3017 p_request_line_id =>p_SDR_lines_tbl(p).request_line_id
3018 ,p_object_version_number =>p_SDR_lines_tbl(p).object_version_number + 1
3019 ,p_last_update_date =>SYSDATE
3020 ,p_last_updated_by =>NVL(FND_GLOBAL.user_id,-1)
3021 ,p_last_update_login =>NVL(FND_GLOBAL.conc_login_id,-1)
3022 ,p_request_id =>FND_GLOBAL.CONC_REQUEST_ID
3023 ,p_program_application_id =>FND_GLOBAL.PROG_APPL_ID
3024 ,p_program_update_date =>SYSDATE
3025 ,p_program_id =>FND_GLOBAL.CONC_PROGRAM_ID
3026 ,p_create_from =>p_SDR_lines_tbl(p).create_from
3027 ,p_request_header_id =>p_request_header_id
3028 ,p_product_context =>p_SDR_lines_tbl(p).product_context
3029 ,p_inventory_item_id =>p_SDR_lines_tbl(p).inventory_item_id
3030 ,p_prod_catg_id =>p_SDR_lines_tbl(p).prod_catg_id
3031 ,p_product_cat_set_id =>p_SDR_lines_tbl(p).product_cat_set_id
3032 ,p_product_cost =>p_SDR_lines_tbl(p).product_cost
3033 ,p_item_uom =>p_SDR_lines_tbl(p).item_uom
3034 ,p_requested_discount_type =>p_SDR_lines_tbl(p).requested_discount_type
3035 ,p_requested_discount_value =>p_SDR_lines_tbl(p).requested_discount_value
3036 ,p_cost_basis =>p_SDR_lines_tbl(p).cost_basis
3037 ,p_max_qty =>p_SDR_lines_tbl(p).max_qty
3038 ,p_limit_qty =>p_SDR_lines_tbl(p).limit_qty
3039 ,p_design_win =>p_SDR_lines_tbl(p).design_win
3040 ,p_end_customer_price =>p_SDR_lines_tbl(p).end_customer_price
3041 ,p_requested_line_amount =>p_SDR_lines_tbl(p).requested_line_amount
3042 ,p_approved_discount_type =>p_SDR_lines_tbl(p).approved_discount_type
3043 ,p_approved_discount_value =>p_SDR_lines_tbl(p).approved_discount_value
3044 ,p_approved_amount =>NULL
3045 ,p_total_requested_amount =>NULL
3046 ,p_total_approved_amount =>NULL
3047 ,p_approved_max_qty =>p_SDR_lines_tbl(p).approved_max_qty
3048 ,p_attribute_category =>p_SDR_lines_tbl(p).attribute_category
3049 ,p_attribute1 =>p_SDR_lines_tbl(p).attribute1
3050 ,p_attribute2 =>p_SDR_lines_tbl(p).attribute2
3051 ,p_attribute3 =>p_SDR_lines_tbl(p).attribute3
3052 ,p_attribute4 =>p_SDR_lines_tbl(p).attribute4
3053 ,p_attribute5 =>p_SDR_lines_tbl(p).attribute5
3054 ,p_attribute6 =>p_SDR_lines_tbl(p).attribute6
3055 ,p_attribute7 =>p_SDR_lines_tbl(p).attribute7
3056 ,p_attribute8 =>p_SDR_lines_tbl(p).attribute8
3057 ,p_attribute9 =>p_SDR_lines_tbl(p).attribute9
3058 ,p_attribute10 =>p_SDR_lines_tbl(p).attribute10
3059 ,p_attribute11 =>p_SDR_lines_tbl(p).attribute11
3060 ,p_attribute12 =>p_SDR_lines_tbl(p).attribute12
3061 ,p_attribute13 =>p_SDR_lines_tbl(p).attribute13
3062 ,p_attribute14 =>p_SDR_lines_tbl(p).attribute14
3063 ,p_attribute15 =>p_SDR_lines_tbl(p).attribute15
3064 ,p_vendor_approved_flag =>p_SDR_lines_tbl(p).vendor_approved_flag
3065 ,p_vendor_item_code =>p_SDR_lines_tbl(p).vendor_item_code
3066 ,p_start_date =>p_SDR_lines_tbl(p).start_date
3067 ,p_end_date =>p_SDR_lines_tbl(p).end_date
3068 ,p_end_customer_price_type =>p_SDR_lines_tbl(p).end_customer_price_type
3069 ,p_end_customer_tolerance_type =>p_SDR_lines_tbl(p).end_customer_tolerance_type
3070 ,p_end_customer_tolerance_value =>p_SDR_lines_tbl(p).end_customer_tolerance_value
3071 ,p_security_group_id =>NULL--p_SDR_lines_tbl(p).security_group_id
3072 ,p_org_id =>G_ITEM_ORG_ID
3073 ,p_rejection_code =>p_SDR_lines_tbl(p).rejection_code
3074 ,p_discount_currency =>p_SDR_lines_tbl(p).requested_discount_currency
3075 ,p_product_cost_currency =>p_SDR_lines_tbl(p).product_cost_currency
3076 ,p_end_customer_currency =>p_SDR_lines_tbl(p).end_customer_currency
3077 ,p_approved_discount_currency =>p_SDR_lines_tbl(p).approved_discount_currency);
3078 END IF;
3079
3080 l_req_line_seq := 0;
3081 END LOOP;
3082
3083 EXCEPTION
3084 WHEN FND_API.G_EXC_ERROR THEN
3085 x_return_status := FND_API.G_RET_STS_ERROR;
3086 WHEN OTHERS THEN
3087 x_return_status := FND_API.g_ret_sts_unexp_error;
3088 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
3089 FND_MESSAGE.set_name('OZF', 'OZF_TABLE_HANDLER_ERROR');
3090 FND_MSG_PUB.add;
3091 END IF;
3092
3093 END populate_product_lines;
3094
3095 ---------------------------------------------------------------------
3096 -- PROCEDURE
3097 -- populate_customer_details.
3098 --
3099 -- PURPOSE
3100 -- This procedure Insert records into SDR Lines table
3101 ---------------------------------------------------------------------
3102 PROCEDURE populate_customer_details(
3103 p_request_header_id IN NUMBER
3104 ,p_SDR_cust_tbl IN SDR_cust_tbl_type
3105 ,x_return_status OUT NOCOPY VARCHAR2)
3106 IS
3107
3108 l_request_cust_seq NUMBER;
3109 l_cust_count NUMBER;
3110
3111 CURSOR c_reqest_cust_seq IS
3112 SELECT OZF_SD_CUSTOMER_DETAILS_S.nextval
3113 FROM dual;
3114
3115 CURSOR c_cust_details(p_request_header_id IN NUMBER
3116 ,p_cust_usage_code IN VARCHAR2
3117 ,p_party_id IN NUMBER
3118 ,p_cust_account_id IN NUMBER
3119 ,p_site_use_id IN NUMBER --//Bugfix :8724614
3120 ,p_end_customer_flag IN VARCHAR2
3121 ,p_cust_usage_value IN VARCHAR2)IS
3122 SELECT COUNT(1)
3123 FROM ozf_sd_customer_details
3124 WHERE request_header_id = p_request_header_id
3125 AND cust_usage_code = p_cust_usage_code
3126 AND party_id = p_party_id
3127 AND cust_account_id = p_cust_account_id
3128 AND NVL(site_use_id,0) = NVL(p_site_use_id,0) --//Bugfix :8724614
3129 AND end_customer_flag = p_end_customer_flag
3130 AND cust_usage_value = p_cust_usage_value;
3131
3132 BEGIN
3133 -- Initialize API return status to SUCCESS
3134 x_return_status := FND_API.G_RET_STS_SUCCESS;
3135
3136 IF G_DEBUG THEN
3137 OZF_UTILITY_PVT.debug_message('Inside populate_customer_details');
3138 END IF;
3139
3140 FOR c IN p_SDR_cust_tbl.FIRST..p_SDR_cust_tbl.LAST LOOP
3141
3142 --//Duplicate check for Customers
3143
3144 l_cust_count :=0;
3145 OPEN c_cust_details(p_request_header_id
3146 ,p_SDR_cust_tbl(c).cust_usage_code
3147 ,p_SDR_cust_tbl(c).party_id
3148 ,p_SDR_cust_tbl(c).cust_account_id
3149 ,p_SDR_cust_tbl(c).site_use_id
3150 ,p_SDR_cust_tbl(c).end_customer_flag
3151 ,p_SDR_cust_tbl(c).cust_usage_value);
3152 FETCH c_cust_details INTO l_cust_count;
3153 CLOSE c_cust_details;
3154
3155 IF l_cust_count <> 0 THEN
3156
3157 IF G_DEBUG THEN
3158 OZF_UTILITY_PVT.debug_message('Duplicate Customer/End Customer ');
3159 OZF_UTILITY_PVT.debug_message('Cust Usage Code :'||p_SDR_cust_tbl(c).cust_usage_code);
3160 OZF_UTILITY_PVT.debug_message('Party Id :'||p_SDR_cust_tbl(c).party_id);
3161 OZF_UTILITY_PVT.debug_message('Cust Account id :'||p_SDR_cust_tbl(c).cust_account_id);
3162 OZF_UTILITY_PVT.debug_message('Site use id :'||p_SDR_cust_tbl(c).site_use_id);
3163 OZF_UTILITY_PVT.debug_message('End Customer Flag :'||p_SDR_cust_tbl(c).end_customer_flag);
3164 OZF_UTILITY_PVT.debug_message('Cust Usage Value :'||p_SDR_cust_tbl(c).cust_usage_value);
3165 END IF;
3166
3167 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
3168 IF p_SDR_cust_tbl(c).end_customer_flag = 'Y' THEN
3169 FND_MESSAGE.set_name('OZF', 'OZF_SD_REQ_DUP_END_CUST');
3170 ELSE
3171 FND_MESSAGE.set_name('OZF', 'OZF_SD_REQ_DUP_CUSTOMER');
3172 END IF;
3173 FND_MSG_PUB.add;
3174 END IF;
3175 x_return_status := fnd_api.g_ret_sts_error;
3176 RETURN;
3177 END IF;
3178
3179 IF p_SDR_cust_tbl(c).request_customer_id = FND_API.g_miss_num OR p_SDR_cust_tbl(c).request_customer_id IS NULL THEN
3180 --//Create mode
3181 OPEN c_reqest_cust_seq;
3182 FETCH c_reqest_cust_seq INTO l_request_cust_seq;
3183 CLOSE c_reqest_cust_seq;
3184
3185 OZF_SD_CUSTOMER_PKG.Insert_Row(
3186 p_request_customer_id =>l_request_cust_seq
3187 ,p_request_header_id =>p_request_header_id
3188 ,p_cust_account_id =>p_SDR_cust_tbl(c).cust_account_id
3189 ,p_party_id =>p_SDR_cust_tbl(c).party_id
3190 ,p_site_use_id =>p_SDR_cust_tbl(c).site_use_id
3191 ,p_cust_usage_code =>p_SDR_cust_tbl(c).cust_usage_code
3192 ,p_security_group_id =>NULL
3193 ,p_creation_date =>SYSDATE
3194 ,p_created_by =>NVL(FND_GLOBAL.user_id,-1)
3195 ,p_last_update_date =>SYSDATE
3196 ,p_last_updated_by =>NVL(FND_GLOBAL.user_id,-1)
3197 ,p_last_update_login =>NVL(FND_GLOBAL.conc_login_id,-1)
3198 ,p_object_version_number =>1
3199 ,p_attribute_category =>p_SDR_cust_tbl(c).attribute_category
3200 ,p_attribute1 =>p_SDR_cust_tbl(c).attribute1
3201 ,p_attribute2 =>p_SDR_cust_tbl(c).attribute2
3202 ,p_attribute3 =>p_SDR_cust_tbl(c).attribute3
3203 ,p_attribute4 =>p_SDR_cust_tbl(c).attribute4
3204 ,p_attribute5 =>p_SDR_cust_tbl(c).attribute5
3205 ,p_attribute6 =>p_SDR_cust_tbl(c).attribute6
3206 ,p_attribute7 =>p_SDR_cust_tbl(c).attribute7
3207 ,p_attribute8 =>p_SDR_cust_tbl(c).attribute8
3208 ,p_attribute9 =>p_SDR_cust_tbl(c).attribute9
3209 ,p_attribute10 =>p_SDR_cust_tbl(c).attribute10
3210 ,p_attribute11 =>p_SDR_cust_tbl(c).attribute11
3211 ,p_attribute12 =>p_SDR_cust_tbl(c).attribute12
3212 ,p_attribute13 =>p_SDR_cust_tbl(c).attribute13
3213 ,p_attribute14 =>p_SDR_cust_tbl(c).attribute14
3214 ,p_attribute15 =>p_SDR_cust_tbl(c).attribute15
3215 ,p_end_customer_flag =>p_SDR_cust_tbl(c).end_customer_flag
3216 ,p_cust_usage_value =>p_SDR_cust_tbl(c).cust_usage_value);
3217 ELSE --ninarasi fix for bug 12656359
3218
3219 IF p_SDR_cust_tbl(c).operation = 'DELETE' THEN
3220 OZF_SD_CUSTOMER_PKG.Delete_Row(
3221 p_request_customer_id =>p_SDR_cust_tbl(c).request_customer_id
3222 ,p_request_header_id =>p_request_header_id);
3223
3224 ELSE
3225 OZF_SD_CUSTOMER_PKG.Update_Row(
3226 p_request_customer_id =>p_SDR_cust_tbl(c).request_customer_id
3227 ,p_request_header_id =>p_request_header_id
3228 ,p_cust_account_id =>p_SDR_cust_tbl(c).cust_account_id
3229 ,p_party_id =>p_SDR_cust_tbl(c).party_id
3230 ,p_site_use_id =>p_SDR_cust_tbl(c).site_use_id
3231 ,p_cust_usage_code =>p_SDR_cust_tbl(c).cust_usage_code
3232 ,p_security_group_id =>NULL
3233 ,p_last_update_date =>SYSDATE
3234 ,p_last_updated_by =>NVL(FND_GLOBAL.user_id,-1)
3235 ,p_last_update_login =>NVL(FND_GLOBAL.conc_login_id,-1)
3236 ,p_object_version_number =>p_SDR_cust_tbl(c).object_version_number + 1
3237 ,p_attribute_category =>p_SDR_cust_tbl(c).attribute_category
3238 ,p_attribute1 =>p_SDR_cust_tbl(c).attribute1
3239 ,p_attribute2 =>p_SDR_cust_tbl(c).attribute2
3240 ,p_attribute3 =>p_SDR_cust_tbl(c).attribute3
3241 ,p_attribute4 =>p_SDR_cust_tbl(c).attribute4
3242 ,p_attribute5 =>p_SDR_cust_tbl(c).attribute5
3243 ,p_attribute6 =>p_SDR_cust_tbl(c).attribute6
3244 ,p_attribute7 =>p_SDR_cust_tbl(c).attribute7
3245 ,p_attribute8 =>p_SDR_cust_tbl(c).attribute8
3246 ,p_attribute9 =>p_SDR_cust_tbl(c).attribute9
3247 ,p_attribute10 =>p_SDR_cust_tbl(c).attribute10
3248 ,p_attribute11 =>p_SDR_cust_tbl(c).attribute11
3249 ,p_attribute12 =>p_SDR_cust_tbl(c).attribute12
3250 ,p_attribute13 =>p_SDR_cust_tbl(c).attribute13
3251 ,p_attribute14 =>p_SDR_cust_tbl(c).attribute14
3252 ,p_attribute15 =>p_SDR_cust_tbl(c).attribute15
3253 ,p_end_customer_flag =>p_SDR_cust_tbl(c).end_customer_flag
3254 ,p_cust_usage_value =>p_SDR_cust_tbl(c).cust_usage_value);
3255
3256 END IF;
3257
3258 END IF;
3259 END LOOP;
3260 EXCEPTION
3261 WHEN FND_API.G_EXC_ERROR THEN
3262 x_return_status := FND_API.G_RET_STS_ERROR;
3263 WHEN OTHERS THEN
3264 x_return_status := FND_API.g_ret_sts_unexp_error;
3265 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
3266 FND_MESSAGE.set_name('OZF', 'OZF_TABLE_HANDLER_ERROR');
3267 FND_MSG_PUB.add;
3268 END IF;
3269 END populate_customer_details;
3270 ---------------------------------------------------------------------
3271 -- PROCEDURE
3272 -- update_header_record
3273 --
3274 ---------------------------------------------------------------------
3275 PROCEDURE update_header_record(
3276 p_SDR_hdr_rec IN SDR_Hdr_rec_type
3277 ,x_return_status OUT NOCOPY VARCHAR2
3278 )
3279 IS
3280 l_api_name CONSTANT VARCHAR2(30) := 'Update_SDR';
3281 l_api_version_number CONSTANT NUMBER := 1.0;
3282 x_msg_count NUMBER;
3283 x_msg_data VARCHAR2(30);
3284 l_status_code VARCHAR2(30);
3285 l_qp_list_header_id NUMBER;
3286 l_error_location NUMBER;
3287 l_offer_type VARCHAR2(30);
3288
3289
3290 CURSOR c_qp_list_header_id(p_request_header_id IN NUMBER)IS
3291 SELECT offer_id
3292 FROM ozf_sd_request_headers_all_b
3293 WHERE request_header_id =p_request_header_id;
3294 /*
3295 --//To check the offer status
3296 CURSOR c_offer_status_code (p_qp_list_header_id IN NUMBER)IS
3297 SELECT status_code
3298 FROM ozf_offers
3299 WHERE qp_list_header_id = p_qp_list_header_id;
3300 */
3301
3302 BEGIN
3303 x_return_status := FND_API.G_RET_STS_SUCCESS;
3304
3305 --//Update process
3306 IF G_DEBUG THEN
3307 OZF_UTILITY_PVT.debug_message('Invokes Update Row');
3308 END IF;
3309
3310 OPEN c_qp_list_header_id(p_SDR_hdr_rec.request_header_id);
3311 FETCH c_qp_list_header_id INTO l_qp_list_header_id;
3312 CLOSE c_qp_list_header_id;
3313
3314 IF l_qp_list_header_id IS NOT NULL THEN
3315 l_offer_type :='ACCRUAL';
3316 END IF;
3317
3318
3319 OZF_SD_REQUEST_HEADER_PKG.Update_Row(
3320 p_request_header_id =>p_SDR_hdr_rec.request_header_id
3321 ,p_object_version_number =>p_SDR_hdr_rec.object_version_number + 1
3322 ,p_last_update_date =>SYSDATE
3323 ,p_last_updated_by =>NVL(FND_GLOBAL.user_id,-1)
3324 ,p_last_update_login =>NVL(FND_GLOBAL.conc_login_id,-1)
3325 ,p_request_id =>FND_GLOBAL.CONC_REQUEST_ID
3326 ,p_program_application_id =>FND_GLOBAL.PROG_APPL_ID
3327 ,p_program_update_date =>SYSDATE
3328 ,p_program_id =>FND_GLOBAL.CONC_PROGRAM_ID
3329 ,p_created_from =>NULL
3330 ,p_request_number =>p_SDR_hdr_rec.request_number
3331 ,p_request_class =>'SD_REQUEST'
3332 ,p_offer_type =>l_offer_type
3333 ,p_offer_id =>l_qp_list_header_id
3334 ,p_root_request_header_id =>NULL
3335 ,p_linked_request_header_id =>NULL
3336 ,p_request_start_date =>p_SDR_hdr_rec.request_start_date
3337 ,p_request_end_date =>p_SDR_hdr_rec.request_end_date
3338 ,p_user_status_id =>p_SDR_hdr_rec.user_status_id
3339 ,p_request_outcome =>p_SDR_hdr_rec.request_outcome
3340 ,p_decline_reason_code =>NULL
3341 ,p_return_reason_code =>NULL
3342 ,p_request_currency_code =>p_SDR_hdr_rec.request_currency_code
3343 ,p_authorization_number =>p_SDR_hdr_rec.authorization_number
3344 ,p_sd_requested_budget_amount =>NULL
3345 ,p_sd_approved_budget_amount =>NULL
3346 ,p_attribute_category =>p_SDR_hdr_rec.attribute_category
3347 ,p_attribute1 =>p_SDR_hdr_rec.attribute1
3348 ,p_attribute2 =>p_SDR_hdr_rec.attribute2
3349 ,p_attribute3 =>p_SDR_hdr_rec.attribute3
3350 ,p_attribute4 =>p_SDR_hdr_rec.attribute4
3351 ,p_attribute5 =>p_SDR_hdr_rec.attribute5
3352 ,p_attribute6 =>p_SDR_hdr_rec.attribute6
3353 ,p_attribute7 =>p_SDR_hdr_rec.attribute7
3354 ,p_attribute8 =>p_SDR_hdr_rec.attribute8
3355 ,p_attribute9 =>p_SDR_hdr_rec.attribute9
3356 ,p_attribute10 =>p_SDR_hdr_rec.attribute10
3357 ,p_attribute11 =>p_SDR_hdr_rec.attribute11
3358 ,p_attribute12 =>p_SDR_hdr_rec.attribute12
3359 ,p_attribute13 =>p_SDR_hdr_rec.attribute13
3360 ,p_attribute14 =>p_SDR_hdr_rec.attribute14
3361 ,p_attribute15 =>p_SDR_hdr_rec.attribute15
3362 ,p_supplier_id =>p_SDR_hdr_rec.supplier_id
3363 ,p_supplier_site_id =>p_SDR_hdr_rec.supplier_site_id
3364 ,p_supplier_contact_id =>p_SDR_hdr_rec.supplier_contact_id
3365 ,p_internal_submission_date =>p_SDR_hdr_rec.internal_submission_date
3366 ,p_assignee_response_by_date =>p_SDR_hdr_rec.assignee_response_by_date
3367 ,p_assignee_response_date =>p_SDR_hdr_rec.assignee_response_date
3368 ,p_submtd_by_for_supp_appr =>p_SDR_hdr_rec.submtd_by_for_supp_approval
3369 ,p_supplier_response_by_date =>p_SDR_hdr_rec.supplier_response_by_date
3370 ,p_supplier_response_date =>p_SDR_hdr_rec.supplier_response_date
3371 ,p_supplier_submission_date =>p_SDR_hdr_rec.supplier_submission_date
3372 ,p_requestor_id =>p_SDR_hdr_rec.requestor_id
3373 ,p_supplier_quote_number =>p_SDR_hdr_rec.supplier_quote_number
3374 ,p_internal_order_number =>p_SDR_hdr_rec.internal_order_number
3375 ,p_sales_order_currency =>p_SDR_hdr_rec.sales_order_currency
3376 ,p_request_source =>'API'
3377 ,p_assignee_resource_id =>p_SDR_hdr_rec.assignee_resource_id
3378 ,p_org_id =>p_SDR_hdr_rec.org_id
3379 ,p_security_group_id =>NULL
3380 ,p_accrual_type =>p_SDR_hdr_rec.accrual_type
3381 ,p_cust_account_id =>p_SDR_hdr_rec.cust_account_id
3382 ,p_supplier_email =>p_SDR_hdr_rec.supplier_contact_email_address
3383 ,p_supplier_phone =>p_SDR_hdr_rec.supplier_contact_phone_number
3384 ,p_request_type_setup_id =>p_SDR_hdr_rec.request_type_setup_id
3385 ,p_request_basis =>p_SDR_hdr_rec.request_basis
3386 ,p_supplier_contact_name =>p_SDR_hdr_rec.supplier_contact_name); --//Bugfix : 7822442
3387
3388 IF G_DEBUG THEN
3389 OZF_UTILITY_PVT.debug_message('End update_header_record');
3390 END IF;
3391
3392 EXCEPTION
3393 WHEN FND_API.G_EXC_ERROR THEN
3394 x_return_status := FND_API.G_RET_STS_ERROR;
3395 WHEN OTHERS THEN
3396 IF G_DEBUG THEN
3397 OZF_UTILITY_PVT.debug_message(SQLERRM);
3398 END IF;
3399 x_return_status := FND_API.g_ret_sts_unexp_error;
3400 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
3401 FND_MESSAGE.set_name('OZF', 'OZF_TABLE_HANDLER_ERROR');
3402 FND_MSG_PUB.add;
3403 END IF;
3404
3405 END update_header_record;
3406 ---------------------------------------------------------------------
3407 -- PROCEDURE
3408 -- create_sd_request
3409 --
3410 -- PURPOSE
3411 -- Public API for creating SDR
3412 ---------------------------------------------------------------------
3413
3414 PROCEDURE create_sd_request(
3415 p_api_version_number IN NUMBER,
3416 p_init_msg_list IN VARCHAR2 := FND_API.G_FALSE,
3417 p_commit IN VARCHAR2 := FND_API.G_FALSE,
3418 p_validation_level IN NUMBER := FND_API.g_valid_level_full,
3419 x_return_status OUT NOCOPY VARCHAR2,
3420 x_msg_count OUT NOCOPY NUMBER,
3421 x_msg_data OUT NOCOPY VARCHAR2,
3422 p_SDR_hdr_rec IN SDR_Hdr_rec_type,
3423 p_SDR_lines_tbl IN SDR_lines_tbl_type,
3424 p_SDR_cust_tbl IN SDR_cust_tbl_type ,
3425 x_request_header_id OUT NOCOPY NUMBER)
3426 IS
3427 l_api_name CONSTANT VARCHAR2(30) := 'Create_sd_request';
3428 l_api_version_number CONSTANT NUMBER := 1.0;
3429
3430 l_SDR_rec OZF_SD_REQUEST_PUB.SDR_Hdr_rec_type := p_SDR_hdr_rec;
3431 l_SDR_lines_tbl OZF_SD_REQUEST_PUB.SDR_lines_tbl_type := p_SDR_lines_tbl;
3432 l_SDR_cust_tbl OZF_SD_REQUEST_PUB.SDR_cust_tbl_type := p_SDR_cust_tbl;
3433
3434 l_line_rec_flag VARCHAR2(1):='N';
3435 l_cust_rec_flag VARCHAR2(1):='N';
3436 l_user_id NUMBER;
3437 l_resource_id NUMBER;
3438 l_system_status_code VARCHAR2(100);
3439 l_request_type_setup_id NUMBER;
3440 l_request_type VARCHAR2(100);
3441 l_request_number VARCHAR2(30);
3442 l_lookup_check VARCHAR2(1); --To validate from lookups
3443
3444 CURSOR c_request_type_setup(p_request_type_setup_id IN NUMBER)IS
3445 SELECT custom_setup_id,
3446 activity_type_code
3447 FROM ams_custom_setups_vl
3448 WHERE object_type = 'SDREQUEST'
3449 AND enabled_flag = 'Y'
3450 AND custom_setup_id = p_request_type_setup_id;
3451
3452 CURSOR c_request_number(p_request_number IN VARCHAR2)IS
3453 SELECT request_number
3454 FROM ozf_sd_request_headers_all_b
3455 WHERE request_number =p_request_number;
3456
3457 BEGIN
3458 -- Standard Start of API savepoint
3459 SAVEPOINT CREATE_SDR_PUB;
3460 -- Standard call to check for call compatibility.
3461 IF NOT FND_API.Compatible_API_Call ( l_api_version_number,
3462 p_api_version_number,
3463 l_api_name,
3464 G_PKG_NAME)
3465 THEN
3466 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3467 END IF;
3468
3469 -- Initialize message list if p_init_msg_list is set to TRUE.
3470 IF FND_API.to_Boolean( p_init_msg_list )
3471 THEN
3472 FND_MSG_PUB.initialize;
3473 END IF;
3474 -- Debug Message
3475 IF G_DEBUG THEN
3476 OZF_UTILITY_PVT.debug_message('Public API: ' || l_api_name || ' PUB start');
3477 END IF;
3478 -- Initialize API return status to SUCCESS
3479 x_return_status := FND_API.G_RET_STS_SUCCESS;
3480
3481 --//API Body
3482 --========================================================================
3483 --//Validations
3484
3485 --//Accrual type Validation
3486 IF l_SDR_rec.accrual_type <> FND_API.g_miss_char AND l_SDR_rec.accrual_type IS NOT NULL THEN
3487
3488 l_lookup_check :=OZF_UTILITY_PVT.check_lookup_exists(
3489 p_lookup_table_name =>'OZF_LOOKUPS'
3490 ,p_lookup_type =>'OZF_SDR_ACCRUAL_TYPE'
3491 ,p_lookup_code => l_SDR_rec.accrual_type);
3492
3493 IF l_lookup_check = FND_API.g_false THEN
3494 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
3495 FND_MESSAGE.set_name('OZF', 'OZF_SD_INVALID_ACCRUAL_TYPE');
3496 FND_MSG_PUB.add;
3497 END IF;
3498 x_return_status := fnd_api.g_ret_sts_error;
3499 RETURN;
3500 END IF;
3501 ELSE
3502 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
3503 FND_MESSAGE.set_name('OZF', 'OZF_SD_NO_ACCRUAL_TYPE');
3504 --//Accrual type is Mandatory
3505 FND_MSG_PUB.add;
3506 END IF;
3507 x_return_status := fnd_api.g_ret_sts_error;
3508 RETURN;
3509 END IF;
3510
3511 --//Set default user status id
3512 IF l_SDR_rec.user_status_id = FND_API.g_miss_num OR l_SDR_rec.user_status_id IS NULL THEN
3513 l_SDR_rec.user_status_id :=get_user_status_id('DRAFT');
3514 END IF;
3515 l_system_status_code := get_system_status_code(l_SDR_rec.user_status_id);
3516
3517 IF l_system_status_code IS NULL THEN
3518 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
3519 FND_MESSAGE.set_name('OZF', 'OZF_SD_INVALID_USER_STATUS_ID');
3520 --//User status id entered is invalid
3521 FND_MSG_PUB.add;
3522 END IF;
3523 x_return_status := fnd_api.g_ret_sts_error;
3524 RETURN;
3525 END IF;
3526
3527 --//Accrual type wise status check
3528 IF l_SDR_rec.accrual_type ='SUPPLIER' THEN
3529 IF l_system_status_code NOT IN ('DRAFT','ASSIGNED','SUPPLIER_APPROVED') THEN
3530 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
3531 FND_MESSAGE.set_name('OZF', 'OZF_SD_INVALID_CREATE_STATUS');
3532 --//User status id entered is invalid for Create
3533 FND_MSG_PUB.add;
3534 END IF;
3535 x_return_status := fnd_api.g_ret_sts_error;
3536 RETURN;
3537 END IF;
3538
3539 ELSIF l_SDR_rec.accrual_type ='INTERNAL' THEN
3540 IF l_system_status_code <> 'DRAFT' THEN
3541 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
3542 FND_MESSAGE.set_name('OZF', 'OZF_SD_INVALID_CREATE_STATUS_I');
3543 --//User status id entered is invalid for Create
3544 FND_MSG_PUB.add;
3545 END IF;
3546 x_return_status := fnd_api.g_ret_sts_error;
3547 RETURN;
3548 END IF;
3549 END IF;
3550
3551 IF G_DEBUG THEN
3552 OZF_UTILITY_PVT.debug_message('User Status id '||l_SDR_rec.user_status_id);
3553 OZF_UTILITY_PVT.debug_message('l_system_status_code :'||l_system_status_code);
3554 END IF;
3555
3556 IF (l_system_status_code <> 'DRAFT') AND (p_SDR_lines_tbl.count = 0) THEN
3557 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
3558 FND_MESSAGE.set_name('OZF', 'OZF_SD_NO_PRODUCT_RECORDS');
3559 --//Product Line records are mandatory
3560 FND_MSG_PUB.add;
3561 END IF;
3562 x_return_status := fnd_api.g_ret_sts_error;
3563 RETURN;
3564 END IF;
3565 --//Request Number Validation
3566 IF l_SDR_rec.request_number <> FND_API.g_miss_char AND l_SDR_rec.request_number IS NOT NULL THEN
3567 OPEN c_request_number(l_SDR_rec.request_number);
3568 FETCH c_request_number INTO l_request_number;
3569 CLOSE c_request_number;
3570
3571 IF l_request_number IS NOT NULL THEN
3572 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
3573 FND_MESSAGE.set_name('OZF', 'OZF_SD_DUP_SOURCE_REQ_NO');
3574 FND_MSG_PUB.add;
3575 END IF;
3576 x_return_status := fnd_api.g_ret_sts_error;
3577 RETURN;
3578 END IF;
3579 END IF;
3580
3581 --//Request type validation
3582 IF l_SDR_rec.request_type_setup_id <> FND_API.g_miss_num AND l_SDR_rec.request_type_setup_id IS NOT NULL THEN
3583 OPEN c_request_type_setup(l_SDR_rec.request_type_setup_id);
3584 FETCH c_request_type_setup INTO l_request_type_setup_id,l_request_type;
3585 CLOSE c_request_type_setup;
3586
3587 IF l_request_type_setup_id IS NULL THEN
3588 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
3589 FND_MESSAGE.set_name('OZF', 'OZF_SD_INVALID_REQUEST_TYPE_SETUP');
3590 --//Request type setup id is Mandatory
3591 FND_MSG_PUB.add;
3592 END IF;
3593 x_return_status := fnd_api.g_ret_sts_error;
3594 RETURN;
3595 ELSE
3596 IF ((l_request_type = 'BID')
3597 AND (l_system_status_code <> 'DRAFT')
3598 AND (l_SDR_cust_tbl.count = 0)) THEN
3599
3600 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
3601 FND_MESSAGE.set_name('OZF', 'OZF_SD_NO_CUSTOMER_DETAILS');
3602 FND_MSG_PUB.add;
3603 END IF;
3604 x_return_status := fnd_api.g_ret_sts_error;
3605 RETURN;
3606 END IF;
3607 END IF;
3608 ELSE
3609 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
3610 FND_MESSAGE.set_name('OZF', 'OZF_SD_NO_REQUEST_TYPE_SETUP');
3611 --//Request type setup id is Mandatory
3612 FND_MSG_PUB.add;
3613 END IF;
3614 x_return_status := fnd_api.g_ret_sts_error;
3615 RETURN;
3616 END IF;
3617
3618 IF G_DEBUG THEN
3619 OZF_UTILITY_PVT.debug_message('Validate Header Record');
3620 END IF;
3621 --//Validate Header Record
3622 validate_header_items(p_SDR_hdr_rec => l_SDR_rec
3623 ,p_mode =>'CREATE'
3624 ,x_return_status => x_return_status);
3625
3626 IF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
3627 RAISE fnd_api.g_exc_unexpected_error;
3628 ELSIF x_return_status = fnd_api.g_ret_sts_error THEN
3629 RAISE fnd_api.g_exc_error;
3630 END IF;
3631
3632 --//Validate Product Lines
3633 IF G_DEBUG THEN
3634 OZF_UTILITY_PVT.debug_message('Validate Product Lines');
3635 END IF;
3636 IF p_SDR_lines_tbl.count > 0 THEN
3637 validate_product_lines(p_SDR_lines_tbl => l_SDR_lines_tbl
3638 ,p_SDR_hdr_rec => l_SDR_rec
3639 ,p_mode => 'CREATE'
3640 ,x_return_status => x_return_status);
3641
3642 IF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
3643 RAISE fnd_api.g_exc_unexpected_error;
3644 ELSIF x_return_status = fnd_api.g_ret_sts_error THEN
3645 RAISE fnd_api.g_exc_error;
3646 END IF;
3647 l_line_rec_flag :='Y';
3648 END IF;
3649
3650 IF G_DEBUG THEN
3651 OZF_UTILITY_PVT.debug_message('Validate Customer Records');
3652 END IF;
3653 --//Validate Customer Records
3654 IF ((p_SDR_cust_tbl.count > 0) AND (l_request_type = 'BID' ))THEN
3655 validate_customer_items(p_SDR_cust_tbl => l_SDR_cust_tbl
3656 ,p_mode => 'CREATE'
3657 ,x_return_status => x_return_status);
3658
3659 IF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
3660 RAISE fnd_api.g_exc_unexpected_error;
3661 ELSIF x_return_status = fnd_api.g_ret_sts_error THEN
3662 RAISE fnd_api.g_exc_error;
3663 END IF;
3664 l_cust_rec_flag :='Y';
3665 END IF;
3666
3667 IF G_DEBUG THEN
3668 OZF_UTILITY_PVT.debug_message('Inserting data into SD Request Header table');
3669 END IF;
3670 --// Insert into Header Table
3671 Insert_header_record(
3672 p_SDR_hdr_rec => l_SDR_rec
3673 ,p_request_source => 'API'
3674 ,x_request_header_id => x_request_header_id
3675 ,x_return_status => x_return_status);
3676
3677 IF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
3678 RAISE fnd_api.g_exc_unexpected_error;
3679 ELSIF x_return_status = fnd_api.g_ret_sts_error THEN
3680 RAISE fnd_api.g_exc_error;
3681 END IF;
3682
3683 IF G_DEBUG THEN
3684 OZF_UTILITY_PVT.debug_message('Populating Translation table');
3685 END IF;
3686 --//Populate Transilation table
3687 populate_translation_record(
3688 p_request_header_id =>x_request_header_id
3689 ,p_description =>l_SDR_rec.request_description
3690 ,p_org_id =>l_SDR_rec.org_id
3691 ,p_mode =>'CREATE'
3692 ,x_return_status => x_return_status);
3693
3694 IF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
3695 RAISE fnd_api.g_exc_unexpected_error;
3696 ELSIF x_return_status = fnd_api.g_ret_sts_error THEN
3697 RAISE fnd_api.g_exc_error;
3698 END IF;
3699
3700 IF G_DEBUG THEN
3701 OZF_UTILITY_PVT.debug_message('Populate SD Access table for Requestor');
3702 OZF_UTILITY_PVT.debug_message('p_resource_id =>'||l_SDR_rec.requestor_id);
3703 END IF;
3704 --Populate SD Access table
3705
3706 OZF_APPROVAL_PVT.Add_SD_Access(
3707 p_api_version =>p_api_version_number
3708 ,p_init_msg_list =>FND_API.G_FALSE
3709 ,p_commit =>FND_API.G_FALSE
3710 ,p_validation_level =>p_validation_level
3711 ,p_request_header_id =>x_request_header_id
3712 ,p_user_id =>NULL
3713 ,p_resource_id =>l_SDR_rec.requestor_id
3714 ,p_person_id =>NULL
3715 ,p_owner_flag =>'Y'
3716 ,p_approver_flag =>NULL
3717 ,p_enabled_flag =>'Y'
3718 ,x_return_status =>x_return_status
3719 ,x_msg_count =>x_msg_count
3720 ,x_msg_data =>x_msg_data);
3721
3722
3723 IF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
3724 RAISE fnd_api.g_exc_unexpected_error;
3725 ELSIF x_return_status = fnd_api.g_ret_sts_error THEN
3726 RAISE fnd_api.g_exc_error;
3727 END IF;
3728
3729 IF l_SDR_rec.assignee_resource_id IS NOT NULL THEN
3730 IF G_DEBUG THEN
3731 OZF_UTILITY_PVT.debug_message('Populate SD Access table for Assignee');
3732 OZF_UTILITY_PVT.debug_message('p_resource_id =>'||l_SDR_rec.assignee_resource_id);
3733 END IF;
3734 --//Assignee Entry
3735 OZF_APPROVAL_PVT.Add_SD_Access(
3736 p_api_version =>p_api_version_number
3737 ,p_init_msg_list =>FND_API.G_FALSE
3738 ,p_commit =>FND_API.G_FALSE
3739 ,p_validation_level =>p_validation_level
3740 ,p_request_header_id =>x_request_header_id
3741 ,p_user_id =>NULL
3742 ,p_resource_id =>l_SDR_rec.assignee_resource_id
3743 ,p_person_id =>NULL
3744 ,p_owner_flag =>NULL
3745 ,p_approver_flag =>'Y'
3746 ,p_enabled_flag =>'Y'
3747 ,x_return_status =>x_return_status
3748 ,x_msg_count =>x_msg_count
3749 ,x_msg_data =>x_msg_data);
3750
3751
3752 IF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
3753 RAISE fnd_api.g_exc_unexpected_error;
3754 ELSIF x_return_status = fnd_api.g_ret_sts_error THEN
3755 RAISE fnd_api.g_exc_error;
3756 END IF;
3757 END IF;
3758
3759
3760 IF l_line_rec_flag ='Y' THEN
3761 IF G_DEBUG THEN
3762 OZF_UTILITY_PVT.debug_message('Populate Product Lines table');
3763 END IF;
3764 --//Populate Product Lines table
3765 populate_product_lines(
3766 p_request_header_id => x_request_header_id
3767 ,p_SDR_lines_tbl => l_SDR_lines_tbl
3768 ,x_return_status => x_return_status);
3769
3770 IF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
3771 RAISE fnd_api.g_exc_unexpected_error;
3772 ELSIF x_return_status = fnd_api.g_ret_sts_error THEN
3773 RAISE fnd_api.g_exc_error;
3774 END IF;
3775 END IF;
3776
3777 IF ((l_cust_rec_flag ='Y') AND (l_request_type = 'BID' ))THEN
3778
3779 IF G_DEBUG THEN
3780 OZF_UTILITY_PVT.debug_message('Populate Customer Details table');
3781 END IF;
3782 --//Populate Customer Details table
3783 populate_customer_details(
3784 p_request_header_id => x_request_header_id
3785 ,p_SDR_cust_tbl => l_SDR_cust_tbl
3786 ,x_return_status => x_return_status);
3787
3788 IF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
3789 RAISE fnd_api.g_exc_unexpected_error;
3790 ELSIF x_return_status = fnd_api.g_ret_sts_error THEN
3791 RAISE fnd_api.g_exc_error;
3792 END IF;
3793 END IF;
3794 --========================================================================
3795 --// Commit the process
3796 IF G_DEBUG THEN
3797 OZF_UTILITY_PVT.debug_message('Request Header Id: '||x_request_header_id);
3798 OZF_UTILITY_PVT.debug_message('Public API: '|| l_api_name||' End');
3799 END IF;
3800 IF FND_API.to_Boolean( p_commit )
3801 THEN
3802 COMMIT WORK;
3803 END IF;
3804
3805 FND_MSG_PUB.Count_And_Get (
3806 p_encoded => FND_API.G_FALSE,
3807 p_count => x_msg_count,
3808 p_data => x_msg_data
3809 );
3810
3811 EXCEPTION
3812 WHEN FND_API.G_EXC_ERROR THEN
3813 ROLLBACK TO CREATE_SDR_PUB;
3814 x_return_status := FND_API.G_RET_STS_ERROR;
3815 -- Standard call to get message count and if count=1, get the message
3816 FND_MSG_PUB.Count_And_Get (
3817 p_encoded => FND_API.G_FALSE,
3818 p_count => x_msg_count,
3819 p_data => x_msg_data
3820 );
3821 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
3822 ROLLBACK TO CREATE_SDR_PUB;
3823 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3824 -- Standard call to get message count and if count=1, get the message
3825 FND_MSG_PUB.Count_And_Get (
3826 p_encoded => FND_API.G_FALSE,
3827 p_count => x_msg_count,
3828 p_data => x_msg_data
3829 );
3830 WHEN OTHERS THEN
3831 ROLLBACK TO CREATE_SDR_PUB;
3832 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3833 IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
3834 FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
3835 END IF;
3836 -- Standard call to get message count and if count=1, get the message
3837 FND_MSG_PUB.Count_And_Get (
3838 p_encoded => FND_API.G_FALSE,
3839 p_count => x_msg_count,
3840 p_data => x_msg_data
3841 );
3842 End create_sd_request;
3843 ---------------------------------------------------------------------
3844 -- PROCEDURE
3845 -- update_sd_request
3846 --
3847 -- PURPOSE
3848 -- Public API for updating Ship & Debit Request
3849 ---------------------------------------------------------------------
3850 PROCEDURE update_sd_request(
3851 p_api_version_number IN NUMBER,
3852 p_init_msg_list IN VARCHAR2 := FND_API.G_FALSE,
3853 p_commit IN VARCHAR2 := FND_API.G_FALSE,
3854 p_validation_level IN NUMBER := FND_API.g_valid_level_full,
3855 x_return_status OUT NOCOPY VARCHAR2,
3856 x_msg_count OUT NOCOPY NUMBER,
3857 x_msg_data OUT NOCOPY VARCHAR2,
3858 p_SDR_hdr_rec IN SDR_Hdr_rec_type,
3859 p_SDR_lines_tbl IN SDR_lines_tbl_type,
3860 p_SDR_cust_tbl IN SDR_cust_tbl_type)
3861
3862 IS
3863 l_api_name CONSTANT VARCHAR2(30) := 'Update_sd_request';
3864 l_api_version_number CONSTANT NUMBER := 1.0;
3865
3866 l_new_sdr_hdr_rec OZF_SD_REQUEST_PUB.SDR_Hdr_rec_type := p_SDR_hdr_rec;
3867 l_old_sdr_hdr_rec OZF_SD_REQUEST_PUB.SDR_Hdr_rec_type;
3868 l_new_sdr_lines_tbl OZF_SD_REQUEST_PUB.SDR_lines_tbl_type := p_SDR_lines_tbl;
3869 l_new_sdr_cust_tbl OZF_SD_REQUEST_PUB.SDR_cust_tbl_type := p_SDR_cust_tbl;
3870
3871 l_internal_flag VARCHAR2(1);
3872 l_external_flag VARCHAR2(1);
3873 l_admin_flag VARCHAR2(1);
3874 l_owner_flag VARCHAR2(1);
3875 l_approver_flag VARCHAR2(1);
3876 l_group_member_id NUMBER;
3877 l_old_user_status_id NUMBER;
3878 l_new_user_status_id NUMBER;
3879 l_old_status_code VARCHAR2(60);
3880 l_new_status_code VARCHAR2(60);
3881 l_is_stat_trns_allowed VARCHAR2(30);
3882 l_line_rec_flag VARCHAR2(1) := 'N';
3883 l_cust_rec_flag VARCHAR2(1) := 'N';
3884 l_resource_id NUMBER;
3885 l_line_update_flag VARCHAR2(1) := 'N';
3886 l_cust_update_flag VARCHAR2(1) := 'N';
3887 l_user_id NUMBER;
3888 l_request_header_id NUMBER;
3889 l_request_number VARCHAR2(30);
3890 l_request_communication VARCHAR2(30);
3891 l_old_user_stat_name VARCHAR2(120);
3892 l_new_user_stat_name VARCHAR2(120);
3893 l_qp_list_header_id NUMBER;
3894 l_error_location NUMBER;
3895
3896 CURSOR c_old_sdr_hdr(p_request_header_id IN NUMBER)IS
3897 SELECT
3898 object_version_number,
3899 request_header_id,
3900 request_number,
3901 request_start_date,
3902 request_end_date,
3903 user_status_id,
3904 request_outcome,
3905 request_currency_code,
3906 authorization_number,
3907 attribute_category,
3908 attribute1,
3909 attribute2,
3910 attribute3,
3911 attribute4,
3912 attribute5,
3913 attribute6,
3914 attribute7,
3915 attribute8,
3916 attribute9,
3917 attribute10,
3918 attribute11,
3919 attribute12,
3920 attribute13,
3921 attribute14,
3922 attribute15,
3923 supplier_id,
3924 supplier_site_id,
3925 supplier_contact_id,
3926 internal_submission_date,
3927 asignee_response_by_date,
3928 asignee_response_date,
3929 submtd_by_for_supp_approval,
3930 supplier_response_by_date,
3931 supplier_response_date,
3932 supplier_submission_date,
3933 requestor_id,
3934 supplier_quote_number,
3935 internal_order_number,
3936 sales_order_currency ,
3937 asignee_resource_id,
3938 org_id,
3939 accrual_type,
3940 cust_account_id,
3941 supplier_contact_email_address,
3942 supplier_contact_phone_number,
3943 request_type_setup_id,
3944 request_basis,
3945 supplier_contact_name --//Bugfix : 7822442
3946 FROM ozf_sd_Request_headers_all_b
3947 WHERE request_header_id =p_request_header_id;
3948
3949 CURSOR c_old_sdr_tl(p_request_header_id IN NUMBER)IS
3950 SELECT request_description
3951 FROM ozf_sd_request_headers_all_tl
3952 WHERE request_header_id = p_request_header_id;
3953
3954 CURSOR c_admin_check(p_resource_id IN NUMBER)IS
3955 SELECT jrgm.group_member_id
3956 FROM jtf_rs_group_members jrgm
3957 WHERE jrgm.resource_id = p_resource_id
3958 AND jrgm.delete_flag = 'N'
3959 AND jrgm.group_id = to_number(fnd_profile.value('AMS_ADMIN_GROUP'));
3960
3961 CURSOR c_sd_access(p_request_header_id IN NUMBER,p_user_id IN NUMBER)IS
3962 SELECT owner_flag,
3963 approver_flag
3964 FROM ozf_sd_request_access
3965 WHERE enabled_flag ='Y'
3966 AND request_header_id =p_request_header_id
3967 AND user_id =p_user_id;
3968
3969 CURSOR c_user(p_user_id IN NUMBER) IS
3970 SELECT user_id
3971 FROM fnd_user
3972 WHERE user_id =p_user_id;
3973
3974 CURSOR c_resource_id (p_user_id IN NUMBER) IS
3975 SELECT resource_id
3976 FROM jtf_rs_resource_extns
3977 WHERE start_date_active <= sysdate
3978 AND nvl(end_date_active,sysdate) >= sysdate
3979 AND resource_id > 0
3980 AND (category = 'EMPLOYEE' OR category = 'PARTNER' OR category = 'PARTY')
3981 AND user_id = p_user_id;
3982
3983 CURSOR c_request_header_id(p_request_header_id IN VARCHAR2)IS
3984 SELECT request_header_id
3985 FROM ozf_sd_request_headers_all_b
3986 WHERE request_header_id = p_request_header_id;
3987
3988 CURSOR c_request_number(p_request_number IN VARCHAR2)IS
3989 SELECT request_number
3990 FROM ozf_sd_request_headers_all_b
3991 WHERE request_number =p_request_number;
3992
3993 CURSOR c_user_status_name(p_user_status_id IN NUMBER)IS
3994 SELECT name
3995 FROM ams_user_statuses_vl
3996 WHERE user_status_id = p_user_status_id;
3997
3998 CURSOR c_communication(p_supplier_id IN NUMBER,p_supplier_site_id IN NUMBER)IS
3999 SELECT request_communication
4000 FROM ozf_supp_trd_prfls_all
4001 WHERE supplier_id =p_supplier_id
4002 AND supplier_site_id =p_supplier_site_id;
4003
4004 CURSOR c_qp_list_header_id(p_request_header_id IN NUMBER)IS
4005 SELECT offer_id
4006 FROM ozf_sd_request_headers_all_b
4007 WHERE request_header_id =p_request_header_id;
4008
4009 BEGIN
4010 -- Standard Start of API savepoint
4011 SAVEPOINT UPDATE_SDR_PUB;
4012 -- Standard call to check for call compatibility.
4013 IF NOT FND_API.Compatible_API_Call ( l_api_version_number,
4014 p_api_version_number,
4015 l_api_name,
4016 G_PKG_NAME)
4017 THEN
4018 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4019 END IF;
4020
4021 -- Initialize message list if p_init_msg_list is set to TRUE.
4022 IF FND_API.to_Boolean( p_init_msg_list )
4023 THEN
4024 FND_MSG_PUB.initialize;
4025 END IF;
4026 -- Debug Message
4027 IF G_DEBUG THEN
4028 OZF_UTILITY_PVT.debug_message('Public API: ' || l_api_name || ' PUB start');
4029 END IF;
4030 -- Initialize API return status to SUCCESS
4031 x_return_status := FND_API.G_RET_STS_SUCCESS;
4032 --==============================================================================
4033 IF l_new_sdr_hdr_rec.request_header_id = FND_API.g_miss_num OR l_new_sdr_hdr_rec.request_header_id IS NULL THEN
4034
4035 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
4036 FND_MESSAGE.set_name('OZF', 'OZF_SD_REQUEST_HEADER_ID_NULL');
4037 FND_MSG_PUB.add;
4038 END IF;
4039 x_return_status := fnd_api.g_ret_sts_error;
4040 RETURN;
4041 ELSE
4042 OPEN c_request_header_id(l_new_sdr_hdr_rec.request_header_id);
4043 FETCH c_request_header_id INTO l_request_header_id;
4044 CLOSE c_request_header_id;
4045
4046 IF l_request_header_id IS NULL THEN
4047 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
4048 FND_MESSAGE.set_name('OZF', 'OZF_SD_INVALID_REQ_HEADER_ID');
4049 --//Request id is invalid. Please re-enter
4050 FND_MSG_PUB.add;
4051 END IF;
4052 x_return_status := fnd_api.g_ret_sts_error;
4053 RETURN;
4054 END IF;
4055 END IF;
4056 --//Set the request Header ID to Global var
4057 G_REQUEST_HEADER_ID :=l_request_header_id;
4058 IF G_DEBUG THEN
4059 OZF_UTILITY_PVT.debug_message('G_REQUEST_HEADER_ID: ' ||G_REQUEST_HEADER_ID);
4060 END IF;
4061
4062 --//Request Number Validation
4063 IF l_new_sdr_hdr_rec.request_number <> FND_API.g_miss_char AND l_new_sdr_hdr_rec.request_number IS NOT NULL THEN
4064 OPEN c_request_number(l_new_sdr_hdr_rec.request_number);
4065 FETCH c_request_number INTO l_request_number;
4066 CLOSE c_request_number;
4067
4068 IF l_request_number IS NOT NULL THEN
4069 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
4070 FND_MESSAGE.set_name('OZF', 'OZF_SD_DUP_SOURCE_REQ_NO');
4071 FND_MSG_PUB.add;
4072 END IF;
4073 x_return_status := fnd_api.g_ret_sts_error;
4074 RETURN;
4075 END IF;
4076 END IF;
4077
4078 OPEN c_old_sdr_hdr(l_new_sdr_hdr_rec.request_header_id);
4079
4080 FETCH c_old_sdr_hdr INTO l_old_sdr_hdr_rec.object_version_number,
4081 l_old_sdr_hdr_rec.request_header_id,
4082 l_old_sdr_hdr_rec.request_number,
4083 l_old_sdr_hdr_rec.request_start_date,
4084 l_old_sdr_hdr_rec.request_end_date,
4085 l_old_sdr_hdr_rec.user_status_id,
4086 l_old_sdr_hdr_rec.request_outcome,
4087 l_old_sdr_hdr_rec.request_currency_code,
4088 l_old_sdr_hdr_rec.authorization_number,
4089 l_old_sdr_hdr_rec.attribute_category,
4090 l_old_sdr_hdr_rec.attribute1,
4091 l_old_sdr_hdr_rec.attribute2,
4092 l_old_sdr_hdr_rec.attribute3,
4093 l_old_sdr_hdr_rec.attribute4,
4094 l_old_sdr_hdr_rec.attribute5,
4095 l_old_sdr_hdr_rec.attribute6,
4096 l_old_sdr_hdr_rec.attribute7,
4097 l_old_sdr_hdr_rec.attribute8,
4098 l_old_sdr_hdr_rec.attribute9,
4099 l_old_sdr_hdr_rec.attribute10,
4100 l_old_sdr_hdr_rec.attribute11,
4101 l_old_sdr_hdr_rec.attribute12,
4102 l_old_sdr_hdr_rec.attribute13,
4103 l_old_sdr_hdr_rec.attribute14,
4104 l_old_sdr_hdr_rec.attribute15,
4105 l_old_sdr_hdr_rec.supplier_id,
4106 l_old_sdr_hdr_rec.supplier_site_id,
4107 l_old_sdr_hdr_rec.supplier_contact_id,
4108 l_old_sdr_hdr_rec.internal_submission_date,
4109 l_old_sdr_hdr_rec.assignee_response_by_date,
4110 l_old_sdr_hdr_rec.assignee_response_date,
4111 l_old_sdr_hdr_rec.submtd_by_for_supp_approval,
4112 l_old_sdr_hdr_rec.supplier_response_by_date,
4113 l_old_sdr_hdr_rec.supplier_response_date,
4114 l_old_sdr_hdr_rec.supplier_submission_date,
4115 l_old_sdr_hdr_rec.requestor_id,
4116 l_old_sdr_hdr_rec.supplier_quote_number,
4117 l_old_sdr_hdr_rec.internal_order_number,
4118 l_old_sdr_hdr_rec.sales_order_currency ,
4119 l_old_sdr_hdr_rec.assignee_resource_id,
4120 l_old_sdr_hdr_rec.org_id,
4121 l_old_sdr_hdr_rec.accrual_type,
4122 l_old_sdr_hdr_rec.cust_account_id,
4123 l_old_sdr_hdr_rec.supplier_contact_email_address,
4124 l_old_sdr_hdr_rec.supplier_contact_phone_number,
4125 l_old_sdr_hdr_rec.request_type_setup_id,
4126 l_old_sdr_hdr_rec.request_basis,
4127 l_old_sdr_hdr_rec.supplier_contact_name; --//Bugfix : 7822442
4128 CLOSE c_old_sdr_hdr;
4129
4130 --// Object Version number check
4131 IF l_old_sdr_hdr_rec.object_version_number <> l_new_sdr_hdr_rec.object_version_number THEN
4132 IF FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
4133 FND_MESSAGE.Set_Name('OZF', 'OZF_API_RESOURCE_LOCKED');
4134 FND_MSG_PUB.ADD;
4135 END IF;
4136 RAISE FND_API.G_EXC_ERROR;
4137 END IF;
4138
4139 OPEN c_old_sdr_tl(l_new_sdr_hdr_rec.request_header_id);
4140 FETCH c_old_sdr_tl INTO l_old_sdr_hdr_rec.request_description;
4141 CLOSE c_old_sdr_tl;
4142
4143 IF G_DEBUG THEN
4144 OZF_UTILITY_PVT.debug_message('Validating User');
4145 END IF;
4146 --//User Check
4147 IF l_new_sdr_hdr_rec.user_id <> FND_API.g_miss_num AND l_new_sdr_hdr_rec.user_id IS NOT NULL THEN
4148 OPEN c_user(l_new_sdr_hdr_rec.user_id);
4149 FETCH c_user INTO l_user_id;
4150 CLOSE c_user;
4151
4152 IF l_user_id IS NULL THEN
4153 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
4154 FND_MESSAGE.set_name('OZF', 'OZF_SD_INVALID_USER_ID');
4155 --//User Id is invalid, Please re-enter
4156 FND_MSG_PUB.add;
4157 END IF;
4158 x_return_status := fnd_api.g_ret_sts_error;
4159 RETURN;
4160 ELSE --// Check if User is a valid resource or not
4161 OPEN c_resource_id(p_SDR_hdr_rec.user_id);
4162 FETCH c_resource_id INTO l_resource_id;
4163 CLOSE c_resource_id;
4164
4165 IF l_resource_id IS NULL THEN
4166 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
4167 FND_MESSAGE.set_name('OZF', 'OZF_SD_USER_IS_NOT_RESOURCE');
4168 FND_MSG_PUB.add;
4169 END IF;
4170 x_return_status := fnd_api.g_ret_sts_error;
4171 RETURN;
4172 END IF;
4173 END IF;
4174
4175 ELSE
4176 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
4177 FND_MESSAGE.set_name('OZF', 'OZF_SD_NO_USER_ID');
4178 --//User Id is Mandatory
4179 FND_MSG_PUB.add;
4180 END IF;
4181 x_return_status := fnd_api.g_ret_sts_error;
4182 RETURN;
4183 END IF;
4184
4185 --//Admin check
4186 OPEN c_admin_check(l_resource_id);
4187 FETCH c_admin_check INTO l_group_member_id;
4188 CLOSE c_admin_check;
4189
4190 IF l_group_member_id IS NOT NULL THEN
4191 l_admin_flag :='Y';
4192 END IF;
4193
4194 IF G_DEBUG THEN
4195 OZF_UTILITY_PVT.debug_message('SD Access Check');
4196 OZF_UTILITY_PVT.debug_message('Request Header ID :'||l_new_sdr_hdr_rec.request_header_id);
4197 OZF_UTILITY_PVT.debug_message('User id :'||l_new_sdr_hdr_rec.user_id);
4198 END IF;
4199 OPEN c_sd_access(l_new_sdr_hdr_rec.request_header_id
4200 ,l_new_sdr_hdr_rec.user_id);
4201
4202 FETCH c_sd_access INTO l_owner_flag,l_approver_flag;
4203 CLOSE c_sd_access;
4204
4205 IF l_admin_flag = 'Y' THEN
4206 l_approver_flag :='Y';
4207 END IF;
4208
4209 IF G_DEBUG THEN
4210 OZF_UTILITY_PVT.debug_message('Owner Flag :'||l_owner_flag);
4211 OZF_UTILITY_PVT.debug_message('Approver Flag :'||l_approver_flag);
4212 OZF_UTILITY_PVT.debug_message('Admin Flag :'||l_admin_flag);
4213 END IF;
4214
4215 --//Access Permission check
4216 IF ((l_owner_flag IS NULL)
4217 AND (l_approver_flag IS NULL)
4218 AND(l_admin_flag IS NULL)) THEN
4219
4220 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
4221 FND_MESSAGE.set_name('OZF', 'OZF_SD_NO_USER_PERMISSIONS');
4222 --//User has no previlage to update the record.
4223 FND_MSG_PUB.add;
4224 END IF;
4225 x_return_status := fnd_api.g_ret_sts_error;
4226 RETURN;
4227 END IF;
4228
4229 --//Get the internal and external flags
4230 IF l_old_sdr_hdr_rec.accrual_type ='INTERNAL' THEN
4231 l_internal_flag := 'Y';
4232 l_external_flag := NULL;
4233 ELSIF l_old_sdr_hdr_rec.accrual_type ='SUPPLIER' THEN
4234 l_internal_flag := NULL;
4235 l_external_flag := 'Y';
4236 END IF;
4237
4238 IF G_DEBUG THEN
4239 OZF_UTILITY_PVT.debug_message('Internal Flag :'||l_internal_flag);
4240 OZF_UTILITY_PVT.debug_message('External Flag :'||l_external_flag);
4241
4242 END IF;
4243
4244 l_old_user_status_id :=NVL(l_old_sdr_hdr_rec.user_status_id,0);
4245 l_new_user_status_id :=NVL(l_new_sdr_hdr_rec.user_status_id,l_old_sdr_hdr_rec.user_status_id);
4246
4247 --//Status Transition check
4248 IF l_new_sdr_hdr_rec.user_status_id <> FND_API.g_miss_num AND l_new_sdr_hdr_rec.user_status_id IS NOT NULL THEN
4249 l_old_status_code := get_system_status_code(l_old_sdr_hdr_rec.user_status_id);
4250 l_new_status_code := get_system_status_code(l_new_sdr_hdr_rec.user_status_id);
4251 ELSE
4252 l_old_status_code := get_system_status_code(l_old_sdr_hdr_rec.user_status_id);
4253 l_new_status_code := l_old_status_code;
4254 END IF;
4255
4256 IF G_DEBUG THEN
4257 OZF_UTILITY_PVT.debug_message('Checking the Status transition ');
4258 OZF_UTILITY_PVT.debug_message('Old Status Code :'||l_old_status_code);
4259 OZF_UTILITY_PVT.debug_message('New Status Code :'||l_new_status_code);
4260 OZF_UTILITY_PVT.debug_message('Old Status Id :'||l_old_user_status_id);
4261 OZF_UTILITY_PVT.debug_message('New Status Id :'||l_new_user_status_id);
4262 END IF;
4263
4264 --//Update is not allowed in the following statuses
4265 IF l_old_status_code IN ('CLOSED','CANCELLED') THEN
4266 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
4267 FND_MESSAGE.set_name('OZF', 'OZF_SD_NO_UPDATE_ALLOWED');
4268 --//Ship and Debit Request updation is not allowed in Closed/Cancelled Status.
4269 FND_MSG_PUB.add;
4270 END IF;
4271 x_return_status := fnd_api.g_ret_sts_error;
4272 RETURN;
4273 END IF;
4274
4275
4276 IF l_old_status_code <> l_new_status_code THEN
4277 l_is_stat_trns_allowed := check_status_transition(
4278 p_from_status =>l_old_status_code
4279 ,p_to_status =>l_new_status_code
4280 ,p_owner_flag =>l_owner_flag
4281 ,p_pm_flag =>l_approver_flag
4282 ,p_internal_flag =>l_internal_flag
4283 ,p_external_flag =>l_external_flag);
4284
4285 IF l_is_stat_trns_allowed = FND_API.g_false THEN
4286 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
4287 FND_MESSAGE.set_name('OZF', 'OZF_SD_INVALID_STATUS_TRANS');
4288 --//Status transition is invalid
4289 FND_MSG_PUB.add;
4290 END IF;
4291 x_return_status := fnd_api.g_ret_sts_error;
4292 RETURN;
4293 END IF;
4294 l_old_sdr_hdr_rec.user_status_id := l_new_sdr_hdr_rec.user_status_id;
4295
4296 END IF;
4297
4298 --//Set Common updatable values
4299 -- nvl clauses for flex field added for bug 13064072
4300 l_old_sdr_hdr_rec.attribute_category := nvl(l_new_sdr_hdr_rec.attribute_category,l_old_sdr_hdr_rec.attribute_category);
4301 l_old_sdr_hdr_rec.attribute1 := nvl(l_new_sdr_hdr_rec.attribute1,l_old_sdr_hdr_rec.attribute1);
4302 l_old_sdr_hdr_rec.attribute2 := nvl(l_new_sdr_hdr_rec.attribute2,l_old_sdr_hdr_rec.attribute2);
4303 l_old_sdr_hdr_rec.attribute3 := nvl(l_new_sdr_hdr_rec.attribute3,l_old_sdr_hdr_rec.attribute3);
4304 l_old_sdr_hdr_rec.attribute4 := nvl(l_new_sdr_hdr_rec.attribute4,l_old_sdr_hdr_rec.attribute4);
4305 l_old_sdr_hdr_rec.attribute5 := nvl(l_new_sdr_hdr_rec.attribute5,l_old_sdr_hdr_rec.attribute5);
4306 l_old_sdr_hdr_rec.attribute6 := nvl(l_new_sdr_hdr_rec.attribute6,l_old_sdr_hdr_rec.attribute6);
4307 l_old_sdr_hdr_rec.attribute7 := nvl(l_new_sdr_hdr_rec.attribute7,l_old_sdr_hdr_rec.attribute7);
4308 l_old_sdr_hdr_rec.attribute8 := nvl(l_new_sdr_hdr_rec.attribute8,l_old_sdr_hdr_rec.attribute8);
4309 l_old_sdr_hdr_rec.attribute9 := nvl(l_new_sdr_hdr_rec.attribute9,l_old_sdr_hdr_rec.attribute9);
4310 l_old_sdr_hdr_rec.attribute10 := nvl(l_new_sdr_hdr_rec.attribute10,l_old_sdr_hdr_rec.attribute10);
4311 l_old_sdr_hdr_rec.attribute11 := nvl(l_new_sdr_hdr_rec.attribute11,l_old_sdr_hdr_rec.attribute11);
4312 l_old_sdr_hdr_rec.attribute12 := nvl(l_new_sdr_hdr_rec.attribute12,l_old_sdr_hdr_rec.attribute12);
4313 l_old_sdr_hdr_rec.attribute13 := nvl(l_new_sdr_hdr_rec.attribute13,l_old_sdr_hdr_rec.attribute13);
4314 l_old_sdr_hdr_rec.attribute14 := nvl(l_new_sdr_hdr_rec.attribute14,l_old_sdr_hdr_rec.attribute14);
4315 l_old_sdr_hdr_rec.attribute15 := nvl(l_new_sdr_hdr_rec.attribute15,l_old_sdr_hdr_rec.attribute15);
4316
4317
4318 IF l_external_flag ='Y' THEN
4319 l_old_sdr_hdr_rec.supplier_contact_email_address := NVL
4320 (l_new_sdr_hdr_rec.supplier_contact_email_address,l_old_sdr_hdr_rec.supplier_contact_email_address);
4321 l_old_sdr_hdr_rec.supplier_contact_phone_number := NVL
4322 (l_new_sdr_hdr_rec.supplier_contact_phone_number,l_old_sdr_hdr_rec.supplier_contact_phone_number);
4323 END IF;
4324
4325 IF G_DEBUG THEN
4326 OZF_UTILITY_PVT.debug_message('l_old_status_code :'||l_old_status_code);
4327 END IF;
4328
4329 --//Statuswise transitions
4330 IF l_old_status_code ='DRAFT' THEN
4331
4332 IF l_owner_flag ='Y' THEN
4333 l_old_sdr_hdr_rec.request_number :=NVL(l_new_sdr_hdr_rec.request_number,l_old_sdr_hdr_rec.request_number);
4334 l_old_sdr_hdr_rec.org_id :=NVL(l_new_sdr_hdr_rec.org_id,l_old_sdr_hdr_rec.org_id);
4335 l_old_sdr_hdr_rec.cust_account_id :=NVL(l_new_sdr_hdr_rec.cust_account_id,l_old_sdr_hdr_rec.cust_account_id);
4336 l_old_sdr_hdr_rec.supplier_id :=NVL(l_new_sdr_hdr_rec.supplier_id,l_old_sdr_hdr_rec.supplier_id);
4337 l_old_sdr_hdr_rec.supplier_site_id :=NVL(l_new_sdr_hdr_rec.supplier_site_id,l_old_sdr_hdr_rec.supplier_site_id);
4338 l_old_sdr_hdr_rec.supplier_response_date :=NVL(l_new_sdr_hdr_rec.supplier_response_date,l_old_sdr_hdr_rec.supplier_response_date);
4339 l_old_sdr_hdr_rec.assignee_response_by_date :=NVL(l_new_sdr_hdr_rec.assignee_response_by_date,l_old_sdr_hdr_rec.assignee_response_by_date);
4340 l_old_sdr_hdr_rec.authorization_number :=NVL(l_new_sdr_hdr_rec.authorization_number,l_old_sdr_hdr_rec.authorization_number);
4341 l_old_sdr_hdr_rec.request_start_date :=NVL(l_new_sdr_hdr_rec.request_start_date,l_old_sdr_hdr_rec.request_start_date);
4342 l_old_sdr_hdr_rec.request_end_date :=NVL(l_new_sdr_hdr_rec.request_end_date,l_old_sdr_hdr_rec.request_end_date);
4343 l_old_sdr_hdr_rec.request_outcome :=NVL(l_new_sdr_hdr_rec.request_outcome,l_old_sdr_hdr_rec.request_outcome);
4344 l_old_sdr_hdr_rec.supplier_quote_number :=NVL(l_new_sdr_hdr_rec.supplier_quote_number,l_old_sdr_hdr_rec.supplier_quote_number);
4345 l_old_sdr_hdr_rec.internal_order_number :=NVL(l_new_sdr_hdr_rec.internal_order_number,l_old_sdr_hdr_rec.internal_order_number);
4346 l_old_sdr_hdr_rec.request_currency_code :=NVL(l_new_sdr_hdr_rec.request_currency_code,l_old_sdr_hdr_rec.request_currency_code);
4347 l_old_sdr_hdr_rec.sales_order_currency :=NVL(l_new_sdr_hdr_rec.sales_order_currency,l_old_sdr_hdr_rec.sales_order_currency);
4348 l_old_sdr_hdr_rec.request_description :=NVL(l_new_sdr_hdr_rec.request_description,l_old_sdr_hdr_rec.request_description);
4349 l_old_sdr_hdr_rec.request_basis :=NVL(l_new_sdr_hdr_rec.request_basis,l_old_sdr_hdr_rec.request_basis);
4350
4351 --//Bugfix 7822442
4352 IF ((l_new_sdr_hdr_rec.supplier_contact_id = FND_API.g_miss_num OR l_new_sdr_hdr_rec.supplier_contact_id IS NULL)
4353 AND (l_new_sdr_hdr_rec.supplier_contact_name <> FND_API.g_miss_char AND l_new_sdr_hdr_rec.supplier_contact_name IS NOT NULL)) THEN
4354 l_old_sdr_hdr_rec.supplier_contact_id :=NULL;
4355 l_old_sdr_hdr_rec.supplier_contact_name :=l_new_sdr_hdr_rec.supplier_contact_name;
4356 ELSE
4357 l_old_sdr_hdr_rec.supplier_contact_id :=NVL(l_new_sdr_hdr_rec.supplier_contact_id,l_old_sdr_hdr_rec.supplier_contact_id);
4358 l_old_sdr_hdr_rec.supplier_contact_name :=NVL(l_new_sdr_hdr_rec.supplier_contact_name,l_old_sdr_hdr_rec.supplier_contact_name);
4359 END IF;
4360
4361 END IF;
4362 IF (l_approver_flag ='Y') OR (l_admin_flag='Y') THEN
4363 l_old_sdr_hdr_rec.cust_account_id :=NVL(l_new_sdr_hdr_rec.cust_account_id,l_old_sdr_hdr_rec.cust_account_id);
4364
4365 END IF;
4366
4367 ELSIF l_old_status_code ='ASSIGNED' THEN
4368
4369 IF l_owner_flag ='Y' THEN
4370 l_old_sdr_hdr_rec.assignee_response_by_date :=NVL(l_new_sdr_hdr_rec.assignee_response_by_date,l_old_sdr_hdr_rec.assignee_response_by_date);
4371 l_old_sdr_hdr_rec.request_outcome :=NVL(l_new_sdr_hdr_rec.request_outcome,l_old_sdr_hdr_rec.request_outcome);
4372 l_old_sdr_hdr_rec.supplier_quote_number :=NVL(l_new_sdr_hdr_rec.supplier_quote_number,l_old_sdr_hdr_rec.supplier_quote_number);
4373 l_old_sdr_hdr_rec.internal_order_number :=NVL(l_new_sdr_hdr_rec.internal_order_number,l_old_sdr_hdr_rec.internal_order_number);
4374 l_old_sdr_hdr_rec.request_description :=NVL(l_new_sdr_hdr_rec.request_description,l_old_sdr_hdr_rec.request_description);
4375 l_old_sdr_hdr_rec.request_basis :=NVL(l_new_sdr_hdr_rec.request_basis,l_old_sdr_hdr_rec.request_basis);
4376 END IF;
4377
4378 IF (l_approver_flag ='Y') OR (l_admin_flag='Y') THEN
4379 l_old_sdr_hdr_rec.authorization_number :=NVL(l_new_sdr_hdr_rec.authorization_number,l_old_sdr_hdr_rec.authorization_number);
4380 l_old_sdr_hdr_rec.request_start_date :=NVL(l_new_sdr_hdr_rec.request_start_date,l_old_sdr_hdr_rec.request_start_date);
4381 l_old_sdr_hdr_rec.request_end_date :=NVL(l_new_sdr_hdr_rec.request_end_date,l_old_sdr_hdr_rec.request_end_date);
4382 l_old_sdr_hdr_rec.request_outcome :=NVL(l_new_sdr_hdr_rec.request_outcome,l_old_sdr_hdr_rec.request_outcome);
4383 l_old_sdr_hdr_rec.supplier_quote_number :=NVL(l_new_sdr_hdr_rec.supplier_quote_number,l_old_sdr_hdr_rec.supplier_quote_number);
4384 l_old_sdr_hdr_rec.internal_order_number :=NVL(l_new_sdr_hdr_rec.internal_order_number,l_old_sdr_hdr_rec.internal_order_number);
4385 l_old_sdr_hdr_rec.request_currency_code :=NVL(l_new_sdr_hdr_rec.request_currency_code,l_old_sdr_hdr_rec.request_currency_code);
4386 l_old_sdr_hdr_rec.sales_order_currency :=NVL(l_new_sdr_hdr_rec.sales_order_currency,l_old_sdr_hdr_rec.sales_order_currency);
4387 l_old_sdr_hdr_rec.request_description :=NVL(l_new_sdr_hdr_rec.request_description,l_old_sdr_hdr_rec.request_description);
4388 l_old_sdr_hdr_rec.request_basis :=NVL(l_new_sdr_hdr_rec.request_basis,l_old_sdr_hdr_rec.request_basis);
4389 END IF;
4390
4391 ELSIF l_old_status_code IN ('WITHDRAW','REJECTED')THEN
4392
4393 IF l_owner_flag ='Y' THEN
4394 l_old_sdr_hdr_rec.request_description :=NVL(l_new_sdr_hdr_rec.request_description,l_old_sdr_hdr_rec.request_description);
4395 END IF;
4396
4397 IF (l_approver_flag ='Y') OR (l_admin_flag='Y') THEN
4398 l_old_sdr_hdr_rec.request_description :=NVL(l_new_sdr_hdr_rec.request_description,l_old_sdr_hdr_rec.request_description);
4399 END IF;
4400
4401 ELSIF l_old_status_code ='PENDING_SUPPLIER_APPROVAL' THEN
4402
4403 IF l_owner_flag ='Y' THEN
4404 l_old_sdr_hdr_rec.assignee_response_by_date :=NVL(l_new_sdr_hdr_rec.assignee_response_by_date,l_old_sdr_hdr_rec.assignee_response_by_date);
4405 l_old_sdr_hdr_rec.request_outcome :=NVL(l_new_sdr_hdr_rec.request_outcome,l_old_sdr_hdr_rec.request_outcome);
4406 l_old_sdr_hdr_rec.supplier_quote_number :=NVL(l_new_sdr_hdr_rec.supplier_quote_number,l_old_sdr_hdr_rec.supplier_quote_number);
4407 l_old_sdr_hdr_rec.internal_order_number :=NVL(l_new_sdr_hdr_rec.internal_order_number,l_old_sdr_hdr_rec.internal_order_number);
4408 l_old_sdr_hdr_rec.request_description :=NVL(l_new_sdr_hdr_rec.request_description,l_old_sdr_hdr_rec.request_description);
4409 END IF;
4410
4411 IF (l_approver_flag ='Y') OR (l_admin_flag='Y') THEN
4412 OZF_UTILITY_PVT.debug_message('l_new_sdr_hdr_rec.request_number '||l_new_sdr_hdr_rec.request_number);
4413
4414 l_old_sdr_hdr_rec.request_number :=NVL(l_new_sdr_hdr_rec.request_number,l_old_sdr_hdr_rec.request_number);
4415 l_old_sdr_hdr_rec.org_id :=NVL(l_new_sdr_hdr_rec.org_id,l_old_sdr_hdr_rec.org_id);
4416 l_old_sdr_hdr_rec.supplier_id :=NVL(l_new_sdr_hdr_rec.supplier_id,l_old_sdr_hdr_rec.supplier_id);
4417 l_old_sdr_hdr_rec.supplier_site_id :=NVL(l_new_sdr_hdr_rec.supplier_site_id,l_old_sdr_hdr_rec.supplier_site_id);
4418 l_old_sdr_hdr_rec.supplier_response_date :=NVL(l_new_sdr_hdr_rec.supplier_response_date,l_old_sdr_hdr_rec.supplier_response_date);
4419 l_old_sdr_hdr_rec.authorization_number :=NVL(l_new_sdr_hdr_rec.authorization_number,l_old_sdr_hdr_rec.authorization_number);
4420 l_old_sdr_hdr_rec.request_outcome :=NVL(l_new_sdr_hdr_rec.request_outcome,l_old_sdr_hdr_rec.request_outcome);
4421 l_old_sdr_hdr_rec.supplier_quote_number :=NVL(l_new_sdr_hdr_rec.supplier_quote_number,l_old_sdr_hdr_rec.supplier_quote_number);
4422 l_old_sdr_hdr_rec.internal_order_number :=NVL(l_new_sdr_hdr_rec.internal_order_number,l_old_sdr_hdr_rec.internal_order_number);
4423 l_old_sdr_hdr_rec.request_description :=NVL(l_new_sdr_hdr_rec.request_description,l_old_sdr_hdr_rec.request_description);
4424
4425 --//Bugfix 7822442
4426 IF ((l_new_sdr_hdr_rec.supplier_contact_id = FND_API.g_miss_num OR l_new_sdr_hdr_rec.supplier_contact_id IS NULL)
4427 AND (l_new_sdr_hdr_rec.supplier_contact_name <> FND_API.g_miss_char AND l_new_sdr_hdr_rec.supplier_contact_name IS NOT NULL)) THEN
4428 l_old_sdr_hdr_rec.supplier_contact_id :=NULL;
4429 l_old_sdr_hdr_rec.supplier_contact_name :=l_new_sdr_hdr_rec.supplier_contact_name;
4430 ELSE
4431 l_old_sdr_hdr_rec.supplier_contact_id :=NVL(l_new_sdr_hdr_rec.supplier_contact_id,l_old_sdr_hdr_rec.supplier_contact_id);
4432 l_old_sdr_hdr_rec.supplier_contact_name :=NVL(l_new_sdr_hdr_rec.supplier_contact_name,l_old_sdr_hdr_rec.supplier_contact_name);
4433 END IF;
4434 END IF;
4435
4436 ELSIF l_old_status_code = 'SUPPLIER_APPROVED' THEN
4437 IF l_owner_flag ='Y' THEN
4438 l_old_sdr_hdr_rec.assignee_response_by_date :=NVL(l_new_sdr_hdr_rec.assignee_response_by_date,l_old_sdr_hdr_rec.assignee_response_by_date);
4439 l_old_sdr_hdr_rec.request_outcome :=NVL(l_new_sdr_hdr_rec.request_outcome,l_old_sdr_hdr_rec.request_outcome);
4440 l_old_sdr_hdr_rec.supplier_quote_number :=NVL(l_new_sdr_hdr_rec.supplier_quote_number,l_old_sdr_hdr_rec.supplier_quote_number);
4441 l_old_sdr_hdr_rec.internal_order_number :=NVL(l_new_sdr_hdr_rec.internal_order_number,l_old_sdr_hdr_rec.internal_order_number);
4442 l_old_sdr_hdr_rec.request_description :=NVL(l_new_sdr_hdr_rec.request_description,l_old_sdr_hdr_rec.request_description);
4443 END IF;
4444
4445 IF (l_approver_flag ='Y') OR (l_admin_flag='Y') THEN
4446 l_old_sdr_hdr_rec.authorization_number :=NVL(l_new_sdr_hdr_rec.authorization_number,l_old_sdr_hdr_rec.authorization_number);
4447 l_old_sdr_hdr_rec.request_start_date :=NVL(l_new_sdr_hdr_rec.request_start_date,l_old_sdr_hdr_rec.request_start_date);
4448 l_old_sdr_hdr_rec.request_end_date :=NVL(l_new_sdr_hdr_rec.request_end_date,l_old_sdr_hdr_rec.request_end_date);
4449 l_old_sdr_hdr_rec.request_outcome :=NVL(l_new_sdr_hdr_rec.request_outcome,l_old_sdr_hdr_rec.request_outcome);
4450 l_old_sdr_hdr_rec.supplier_quote_number :=NVL(l_new_sdr_hdr_rec.supplier_quote_number,l_old_sdr_hdr_rec.supplier_quote_number);
4451 l_old_sdr_hdr_rec.internal_order_number :=NVL(l_new_sdr_hdr_rec.internal_order_number,l_old_sdr_hdr_rec.internal_order_number);
4452 l_old_sdr_hdr_rec.request_currency_code :=NVL(l_new_sdr_hdr_rec.request_currency_code,l_old_sdr_hdr_rec.request_currency_code);
4453 l_old_sdr_hdr_rec.sales_order_currency :=NVL(l_new_sdr_hdr_rec.sales_order_currency,l_old_sdr_hdr_rec.sales_order_currency);
4454 l_old_sdr_hdr_rec.request_description :=NVL(l_new_sdr_hdr_rec.request_description,l_old_sdr_hdr_rec.request_description);
4455 l_old_sdr_hdr_rec.request_basis :=NVL(l_new_sdr_hdr_rec.request_basis,l_old_sdr_hdr_rec.request_basis);
4456
4457 --//Bugfix 7822442
4458 IF ((l_new_sdr_hdr_rec.supplier_contact_id = FND_API.g_miss_num OR l_new_sdr_hdr_rec.supplier_contact_id IS NULL)
4459 AND (l_new_sdr_hdr_rec.supplier_contact_name <> FND_API.g_miss_char AND l_new_sdr_hdr_rec.supplier_contact_name IS NOT NULL)) THEN
4460 l_old_sdr_hdr_rec.supplier_contact_id :=NULL;
4461 l_old_sdr_hdr_rec.supplier_contact_name :=l_new_sdr_hdr_rec.supplier_contact_name;
4462 ELSE
4463 l_old_sdr_hdr_rec.supplier_contact_id :=NVL(l_new_sdr_hdr_rec.supplier_contact_id,l_old_sdr_hdr_rec.supplier_contact_id);
4464 l_old_sdr_hdr_rec.supplier_contact_name :=NVL(l_new_sdr_hdr_rec.supplier_contact_name,l_old_sdr_hdr_rec.supplier_contact_name);
4465 END IF;
4466 END IF;
4467
4468 ELSIF l_old_status_code = 'SUPPLIER_REJECTED'THEN
4469 IF l_owner_flag ='Y' THEN
4470 l_old_sdr_hdr_rec.request_outcome :=NVL(l_new_sdr_hdr_rec.request_outcome,l_old_sdr_hdr_rec.request_outcome);
4471 l_old_sdr_hdr_rec.supplier_quote_number :=NVL(l_new_sdr_hdr_rec.supplier_quote_number,l_old_sdr_hdr_rec.supplier_quote_number);
4472 l_old_sdr_hdr_rec.internal_order_number :=NVL(l_new_sdr_hdr_rec.internal_order_number,l_old_sdr_hdr_rec.internal_order_number);
4473 l_old_sdr_hdr_rec.request_description :=NVL(l_new_sdr_hdr_rec.request_description,l_old_sdr_hdr_rec.request_description);
4474 END IF;
4475
4476 IF (l_approver_flag ='Y') OR (l_admin_flag='Y') THEN
4477 l_old_sdr_hdr_rec.request_number :=NVL(l_new_sdr_hdr_rec.request_number,l_old_sdr_hdr_rec.request_number);
4478 l_old_sdr_hdr_rec.org_id :=NVL(l_new_sdr_hdr_rec.org_id,l_old_sdr_hdr_rec.org_id);
4479 l_old_sdr_hdr_rec.supplier_id :=NVL(l_new_sdr_hdr_rec.supplier_id,l_old_sdr_hdr_rec.supplier_id);
4480 l_old_sdr_hdr_rec.supplier_site_id :=NVL(l_new_sdr_hdr_rec.supplier_site_id,l_old_sdr_hdr_rec.supplier_site_id);
4481 l_old_sdr_hdr_rec.supplier_response_date :=NVL(l_new_sdr_hdr_rec.supplier_response_date,l_old_sdr_hdr_rec.supplier_response_date);
4482 l_old_sdr_hdr_rec.authorization_number :=NVL(l_new_sdr_hdr_rec.authorization_number,l_old_sdr_hdr_rec.authorization_number);
4483 l_old_sdr_hdr_rec.request_outcome :=NVL(l_new_sdr_hdr_rec.request_outcome,l_old_sdr_hdr_rec.request_outcome);
4484 l_old_sdr_hdr_rec.supplier_quote_number :=NVL(l_new_sdr_hdr_rec.supplier_quote_number,l_old_sdr_hdr_rec.supplier_quote_number);
4485 l_old_sdr_hdr_rec.internal_order_number :=NVL(l_new_sdr_hdr_rec.internal_order_number,l_old_sdr_hdr_rec.internal_order_number);
4486 l_old_sdr_hdr_rec.request_currency_code :=NVL(l_new_sdr_hdr_rec.request_currency_code,l_old_sdr_hdr_rec.request_currency_code);
4487 l_old_sdr_hdr_rec.sales_order_currency :=NVL(l_new_sdr_hdr_rec.sales_order_currency,l_old_sdr_hdr_rec.sales_order_currency);
4488 l_old_sdr_hdr_rec.request_description :=NVL(l_new_sdr_hdr_rec.request_description,l_old_sdr_hdr_rec.request_description);
4489
4490 --//Bugfix 7822442
4491 IF ((l_new_sdr_hdr_rec.supplier_contact_id = FND_API.g_miss_num OR l_new_sdr_hdr_rec.supplier_contact_id IS NULL)
4492 AND (l_new_sdr_hdr_rec.supplier_contact_name <> FND_API.g_miss_char AND l_new_sdr_hdr_rec.supplier_contact_name IS NOT NULL)) THEN
4493 l_old_sdr_hdr_rec.supplier_contact_id :=NULL;
4494 l_old_sdr_hdr_rec.supplier_contact_name :=l_new_sdr_hdr_rec.supplier_contact_name;
4495 ELSE
4496 l_old_sdr_hdr_rec.supplier_contact_id :=NVL(l_new_sdr_hdr_rec.supplier_contact_id,l_old_sdr_hdr_rec.supplier_contact_id);
4497 l_old_sdr_hdr_rec.supplier_contact_name :=NVL(l_new_sdr_hdr_rec.supplier_contact_name,l_old_sdr_hdr_rec.supplier_contact_name);
4498 END IF;
4499
4500 END IF;
4501
4502 ELSIF l_old_status_code IN ('PENDING_SALES_APPROVAL','SALES_REJECTED',
4503 'SALES_APPROVED','PENDING_OFFER_APPROVAL') THEN
4504
4505 IF l_owner_flag ='Y' THEN
4506 l_old_sdr_hdr_rec.request_outcome :=NVL(l_new_sdr_hdr_rec.request_outcome,l_old_sdr_hdr_rec.request_outcome);
4507 l_old_sdr_hdr_rec.request_description :=NVL(l_new_sdr_hdr_rec.request_description,l_old_sdr_hdr_rec.request_description);
4508 END IF;
4509
4510 IF (l_approver_flag ='Y') OR (l_admin_flag='Y') THEN
4511 l_old_sdr_hdr_rec.request_outcome :=NVL(l_new_sdr_hdr_rec.request_outcome,l_old_sdr_hdr_rec.request_outcome);
4512 l_old_sdr_hdr_rec.request_description :=NVL(l_new_sdr_hdr_rec.request_description,l_old_sdr_hdr_rec.request_description);
4513 END IF;
4514
4515 ELSIF (l_old_status_code ='SALES_APPROVED')THEN
4516
4517 IF l_owner_flag ='Y' THEN
4518 l_old_sdr_hdr_rec.request_outcome :=NVL(l_new_sdr_hdr_rec.request_outcome,l_old_sdr_hdr_rec.request_outcome);
4519 l_old_sdr_hdr_rec.request_description :=NVL(l_new_sdr_hdr_rec.request_description,l_old_sdr_hdr_rec.request_description);
4520 END IF;
4521
4522 IF (l_approver_flag ='Y') OR (l_admin_flag='Y') THEN
4523 l_old_sdr_hdr_rec.request_outcome :=NVL(l_new_sdr_hdr_rec.request_outcome,l_old_sdr_hdr_rec.request_outcome);
4524 l_old_sdr_hdr_rec.request_description :=NVL(l_new_sdr_hdr_rec.request_description,l_old_sdr_hdr_rec.request_description);
4525 l_old_sdr_hdr_rec.request_basis :=NVL(l_new_sdr_hdr_rec.request_basis,l_old_sdr_hdr_rec.request_basis);
4526 END IF;
4527
4528 ELSIF l_old_status_code ='ACTIVE' THEN
4529 IF l_owner_flag ='Y' THEN
4530 l_old_sdr_hdr_rec.request_outcome :=NVL(l_new_sdr_hdr_rec.request_outcome,l_old_sdr_hdr_rec.request_outcome);
4531 l_old_sdr_hdr_rec.request_description :=NVL(l_new_sdr_hdr_rec.request_description,l_old_sdr_hdr_rec.request_description);
4532 END IF;
4533
4534 IF (l_approver_flag ='Y') OR (l_admin_flag='Y') THEN
4535 l_old_sdr_hdr_rec.authorization_number :=NVL(l_new_sdr_hdr_rec.authorization_number,l_old_sdr_hdr_rec.authorization_number);
4536 l_old_sdr_hdr_rec.request_start_date :=NVL(l_new_sdr_hdr_rec.request_start_date,l_old_sdr_hdr_rec.request_start_date);
4537 l_old_sdr_hdr_rec.request_end_date :=NVL(l_new_sdr_hdr_rec.request_end_date,l_old_sdr_hdr_rec.request_end_date);
4538 l_old_sdr_hdr_rec.request_outcome :=NVL(l_new_sdr_hdr_rec.request_outcome,l_old_sdr_hdr_rec.request_outcome);
4539 l_old_sdr_hdr_rec.request_description :=NVL(l_new_sdr_hdr_rec.request_description,l_old_sdr_hdr_rec.request_description);
4540 l_old_sdr_hdr_rec.request_basis :=NVL(l_new_sdr_hdr_rec.request_basis,l_old_sdr_hdr_rec.request_basis);
4541 END IF;
4542
4543 ELSIF l_old_status_code IN ('OFFER_REJECTED','CANCELLED','CLOSED') THEN
4544 IF l_owner_flag ='Y' THEN
4545 l_old_sdr_hdr_rec.request_description :=NVL(l_new_sdr_hdr_rec.request_description,l_old_sdr_hdr_rec.request_description);
4546 END IF;
4547
4548 IF (l_approver_flag ='Y') OR (l_admin_flag='Y') THEN
4549 l_old_sdr_hdr_rec.request_description :=NVL(l_new_sdr_hdr_rec.request_description,l_old_sdr_hdr_rec.request_description);
4550 END IF;
4551 END IF;
4552
4553 IF G_DEBUG THEN
4554 OZF_UTILITY_PVT.debug_message('End of Statuswise Data set');
4555 END IF;
4556 --//Set the user Id
4557 l_old_sdr_hdr_rec.user_id := l_new_sdr_hdr_rec.user_id;
4558
4559 --//Admin Actions
4560 IF l_admin_flag ='Y' THEN
4561 IF G_DEBUG THEN
4562 OZF_UTILITY_PVT.debug_message('Admin Actions ');
4563 END IF;
4564
4565 IF (l_new_sdr_hdr_rec.requestor_id IS NOT NULL)
4566 AND (NVL(l_old_sdr_hdr_rec.requestor_id,0) <> NVL(l_new_sdr_hdr_rec.requestor_id,0)) THEN
4567 --//Admin is updating the Owner
4568 IF G_DEBUG THEN
4569 OZF_UTILITY_PVT.debug_message('Admin is updating the Owner ');
4570 END IF;
4571
4572 OZF_APPROVAL_PVT.Add_SD_Access(
4573 p_api_version =>p_api_version_number
4574 ,p_init_msg_list =>FND_API.G_FALSE
4575 ,p_commit =>FND_API.G_FALSE
4576 ,p_validation_level =>p_validation_level
4577 ,p_request_header_id =>l_old_sdr_hdr_rec.request_header_id
4578 ,p_user_id =>NULL
4579 ,p_resource_id =>l_new_sdr_hdr_rec.requestor_id
4580 ,p_person_id =>NULL
4581 ,p_owner_flag =>'Y'
4582 ,p_approver_flag =>NULL
4583 ,p_enabled_flag =>'Y'
4584 ,x_return_status =>x_return_status
4585 ,x_msg_count =>x_msg_count
4586 ,x_msg_data =>x_msg_data);
4587
4588 IF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
4589 RAISE fnd_api.g_exc_unexpected_error;
4590 ELSIF x_return_status = fnd_api.g_ret_sts_error THEN
4591 RAISE fnd_api.g_exc_error;
4592 END IF;
4593 l_old_sdr_hdr_rec.requestor_id :=l_new_sdr_hdr_rec.requestor_id;
4594
4595 END IF;
4596 IF l_external_flag = 'Y' THEN
4597 IF ((l_new_sdr_hdr_rec.assignee_resource_id IS NOT NULL)
4598 AND NVL(l_old_sdr_hdr_rec.assignee_resource_id,0) <> NVL(l_new_sdr_hdr_rec.assignee_resource_id,0)) THEN
4599 --//Admin is updating the Assignee
4600 IF g_debug THEN
4601 OZF_UTILITY_PVT.debug_message('Admin is updating the Assignee ');
4602 END IF;
4603
4604 OZF_APPROVAL_PVT.Add_SD_Access(
4605 p_api_version =>p_api_version_number
4606 ,p_init_msg_list =>FND_API.G_FALSE
4607 ,p_commit =>FND_API.G_FALSE
4608 ,p_validation_level =>p_validation_level
4609 ,p_request_header_id =>l_old_sdr_hdr_rec.request_header_id
4610 ,p_user_id =>NULL
4611 ,p_resource_id =>l_new_sdr_hdr_rec.assignee_resource_id
4612 ,p_person_id =>NULL
4613 ,p_owner_flag =>NULL
4614 ,p_approver_flag =>'Y'
4615 ,p_enabled_flag =>'Y'
4616 ,x_return_status =>x_return_status
4617 ,x_msg_count =>x_msg_count
4618 ,x_msg_data =>x_msg_data);
4619
4620 IF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
4621 RAISE fnd_api.g_exc_unexpected_error;
4622 ELSIF x_return_status = fnd_api.g_ret_sts_error THEN
4623 RAISE fnd_api.g_exc_error;
4624 END IF;
4625 l_old_sdr_hdr_rec.assignee_resource_id :=l_new_sdr_hdr_rec.assignee_resource_id;
4626 END IF;
4627 END IF;
4628 ELSE
4629 l_old_sdr_hdr_rec.requestor_id :=NVL(l_new_sdr_hdr_rec.requestor_id,l_old_sdr_hdr_rec.requestor_id);
4630 l_old_sdr_hdr_rec.assignee_resource_id :=NVL(l_new_sdr_hdr_rec.assignee_resource_id,l_old_sdr_hdr_rec.assignee_resource_id);
4631 END IF;
4632
4633 IF G_DEBUG THEN
4634 OZF_UTILITY_PVT.debug_message('Validate Header Records');
4635 END IF;
4636 --//Validate Header Record
4637 validate_header_items(p_SDR_hdr_rec => l_old_sdr_hdr_rec
4638 ,p_mode =>'UPDATE'
4639 ,x_return_status => x_return_status);
4640
4641 IF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
4642 RAISE fnd_api.g_exc_unexpected_error;
4643 ELSIF x_return_status = fnd_api.g_ret_sts_error THEN
4644 RAISE fnd_api.g_exc_error;
4645 END IF;
4646
4647 --//Proc Lines and Customer details Validation
4648 IF G_DEBUG THEN
4649 OZF_UTILITY_PVT.debug_message('Proc Lines and Customer details Validation');
4650 END IF;
4651
4652 IF l_old_status_code ='DRAFT' AND (l_owner_flag ='Y' OR l_admin_flag ='Y') THEN
4653 IF G_DEBUG THEN
4654 OZF_UTILITY_PVT.debug_message('Owner can update Product Lines and Customer Details');
4655 END IF;
4656 --//Owner can update Product Lines and Customer Details
4657 l_line_update_flag := 'Y';
4658 l_cust_update_flag := 'Y';
4659 ELSIF l_old_status_code <>'DRAFT' AND (l_approver_flag ='Y' OR l_admin_flag ='Y') THEN
4660 IF G_DEBUG THEN
4661 OZF_UTILITY_PVT.debug_message('PM Can update Product Lines and Customer Details');
4662 END IF;
4663 --//PM Can update Product Lines and Customer Details
4664 l_line_update_flag := 'Y';
4665 l_cust_update_flag := 'Y';
4666 END IF;
4667
4668 --//Validate Product Line Records
4669 IF l_line_update_flag ='Y' THEN
4670
4671 IF G_DEBUG THEN
4672 OZF_UTILITY_PVT.debug_message('Validate Product Line Records');
4673 END IF;
4674
4675 IF l_new_sdr_lines_tbl.count > 0 THEN
4676
4677 validate_product_lines(p_SDR_lines_tbl => l_new_sdr_lines_tbl
4678 ,p_SDR_hdr_rec => l_old_sdr_hdr_rec
4679 ,p_mode => 'UPDATE'
4680 ,x_return_status => x_return_status);
4681
4682 IF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
4683 RAISE fnd_api.g_exc_unexpected_error;
4684 ELSIF x_return_status = fnd_api.g_ret_sts_error THEN
4685 RAISE fnd_api.g_exc_error;
4686 END IF;
4687 l_line_rec_flag :='Y';
4688 END IF;
4689 END IF;
4690
4691 --//Validate Customer Records
4692 IF l_cust_update_flag = 'Y' THEN
4693 IF G_DEBUG THEN
4694 OZF_UTILITY_PVT.debug_message('Validate Customer Records');
4695 END IF;
4696
4697 IF l_new_sdr_cust_tbl.count > 0 THEN
4698
4699
4700 validate_customer_items(p_SDR_cust_tbl => l_new_sdr_cust_tbl
4701 ,p_mode => 'UPDATE'
4702 ,x_return_status => x_return_status);
4703
4704 IF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
4705 RAISE fnd_api.g_exc_unexpected_error;
4706 ELSIF x_return_status = fnd_api.g_ret_sts_error THEN
4707 RAISE fnd_api.g_exc_error;
4708 END IF;
4709 l_cust_rec_flag :='Y';
4710 END IF;
4711 END IF;
4712
4713 --//UPDATE PROCESS
4714 --//Update Header Records
4715 IF G_DEBUG THEN
4716 OZF_UTILITY_PVT.debug_message('update_header_record');
4717 END IF;
4718
4719 update_header_record(
4720 p_SDR_hdr_rec =>l_old_sdr_hdr_rec
4721 ,x_return_status =>x_return_status);
4722
4723 IF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
4724 RAISE fnd_api.g_exc_unexpected_error;
4725 ELSIF x_return_status = fnd_api.g_ret_sts_error THEN
4726 RAISE fnd_api.g_exc_error;
4727 END IF;
4728
4729 IF G_DEBUG THEN
4730 OZF_UTILITY_PVT.debug_message('populate_translation_record');
4731 END IF;
4732 --//Update TL record
4733 populate_translation_record(
4734 p_request_header_id =>l_old_sdr_hdr_rec.request_header_id
4735 ,p_description =>l_old_sdr_hdr_rec.request_description
4736 ,p_org_id =>l_old_sdr_hdr_rec.org_id
4737 ,p_mode =>'UPDATE'
4738 ,x_return_status => x_return_status);
4739
4740 IF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
4741 RAISE fnd_api.g_exc_unexpected_error;
4742 ELSIF x_return_status = fnd_api.g_ret_sts_error THEN
4743 RAISE fnd_api.g_exc_error;
4744 END IF;
4745
4746 --//Populating SD Access Table
4747 IF l_old_sdr_hdr_rec.accrual_type ='SUPPLIER'
4748 AND l_new_status_code ='ASSIGNED'
4749 AND l_old_status_code <>l_new_status_code THEN
4750
4751 OZF_APPROVAL_PVT.Add_SD_Access(
4752 p_api_version =>p_api_version_number
4753 ,p_init_msg_list =>FND_API.G_FALSE
4754 ,p_commit =>FND_API.G_FALSE
4755 ,p_validation_level =>p_validation_level
4756 ,p_request_header_id =>l_old_sdr_hdr_rec.request_header_id
4757 ,p_user_id =>NULL
4758 ,p_resource_id =>l_old_sdr_hdr_rec.assignee_resource_id
4759 ,p_person_id =>NULL
4760 ,p_owner_flag =>NULL
4761 ,p_approver_flag =>'Y'
4762 ,p_enabled_flag =>'Y'
4763 ,x_return_status =>x_return_status
4764 ,x_msg_count =>x_msg_count
4765 ,x_msg_data =>x_msg_data);
4766
4767 IF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
4768 RAISE fnd_api.g_exc_unexpected_error;
4769 ELSIF x_return_status = fnd_api.g_ret_sts_error THEN
4770 RAISE fnd_api.g_exc_error;
4771 END IF;
4772 END IF;
4773
4774 --//Update Lines Record
4775 IF l_line_rec_flag ='Y' THEN
4776
4777 IF G_DEBUG THEN
4778 OZF_UTILITY_PVT.debug_message('Update Lines Record');
4779 END IF;
4780 populate_product_lines(
4781 p_request_header_id => l_new_sdr_hdr_rec.request_header_id
4782 ,p_SDR_lines_tbl => l_new_sdr_lines_tbl
4783 ,x_return_status => x_return_status);
4784
4785 IF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
4786 RAISE fnd_api.g_exc_unexpected_error;
4787 ELSIF x_return_status = fnd_api.g_ret_sts_error THEN
4788 RAISE fnd_api.g_exc_error;
4789 END IF;
4790 END IF;
4791
4792 --//Update Customer Record
4793 IF l_cust_rec_flag ='Y' THEN
4794 IF G_DEBUG THEN
4795 OZF_UTILITY_PVT.debug_message('Populate Customer Details table');
4796 END IF;
4797 populate_customer_details(
4798 p_request_header_id => l_new_sdr_hdr_rec.request_header_id
4799 ,p_SDR_cust_tbl => l_new_sdr_cust_tbl
4800 ,x_return_status => x_return_status);
4801
4802 IF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
4803 RAISE fnd_api.g_exc_unexpected_error;
4804 ELSIF x_return_status = fnd_api.g_ret_sts_error THEN
4805 RAISE fnd_api.g_exc_error;
4806 END IF;
4807 END IF;
4808
4809 --//Invoking Offer API Process
4810 --//Moved the code from update_header_record Procedure - Bugfix : 7501052
4811 IF G_DEBUG THEN
4812 OZF_UTILITY_PVT.debug_message('Request Header id from update_header_record :'||p_SDR_hdr_rec.request_header_id);
4813 END IF;
4814
4815 IF l_new_status_code IN ('PENDING_OFFER_APPROVAL','ACTIVE') OR
4816 l_old_status_code ='ACTIVE' OR
4817 (l_old_status_code ='ACTIVE' AND l_new_status_code IN('CANCELLED','CLOSED')) THEN
4818
4819 OPEN c_qp_list_header_id(l_new_sdr_hdr_rec.request_header_id);
4820 FETCH c_qp_list_header_id INTO l_qp_list_header_id;
4821 CLOSE c_qp_list_header_id;
4822
4823 IF G_DEBUG THEN
4824 OZF_UTILITY_PVT.debug_message('l_qp_list_header_id:'||l_qp_list_header_id);
4825 OZF_UTILITY_PVT.debug_message('l_new_status_code :'||l_new_status_code);
4826 OZF_UTILITY_PVT.debug_message('IG_OLD_STATUS_CODE:'||l_old_status_code);
4827 OZF_UTILITY_PVT.debug_message('Invoking OZF_OFFER_PVT.process_sd_modifiers :'||p_SDR_hdr_rec.request_header_id);
4828 END IF;
4829
4830 OZF_OFFER_PVT.process_sd_modifiers(
4831 p_sdr_header_id => p_SDR_hdr_rec.request_header_id
4832 ,p_init_msg_list => FND_API.G_FALSE
4833 ,p_api_version => l_api_version_number
4834 ,p_commit => FND_API.G_FALSE
4835 ,x_return_status => x_return_status
4836 ,x_msg_count => x_msg_count
4837 ,x_msg_data => x_msg_data
4838 ,x_qp_list_header_id => l_qp_list_header_id
4839 ,x_error_location => l_error_location);
4840
4841 IF G_DEBUG THEN
4842 OZF_UTILITY_PVT.debug_message('l_qp_list_header_id(Offer Id) :'||l_qp_list_header_id);
4843 OZF_UTILITY_PVT.debug_message('Invoking OZF_OFFER_PVT.process_sd_modifiers'||l_error_location);
4844 END IF;
4845
4846 IF l_new_status_code ='PENDING_OFFER_APPROVAL' THEN
4847 --//Updating SD Request Header table with offer information
4848 UPDATE ozf_sd_request_headers_all_b
4849 SET offer_id = l_qp_list_header_id,
4850 offer_type = 'ACCRUAL'
4851 WHERE request_header_id = p_SDR_hdr_rec.request_header_id;
4852 END IF;
4853
4854 IF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
4855 RAISE fnd_api.g_exc_unexpected_error;
4856 ELSIF x_return_status = fnd_api.g_ret_sts_error THEN
4857 RAISE fnd_api.g_exc_error;
4858 END IF;
4859 END IF;
4860
4861
4862 --// Commit the process
4863 IF G_DEBUG THEN
4864 OZF_UTILITY_PVT.debug_message('Public API: ' || l_api_name || ' End');
4865 END IF;
4866 IF FND_API.to_Boolean( p_commit )
4867 THEN
4868 COMMIT WORK;
4869 END IF;
4870
4871 --// Invoke Business Events
4872 --//1.Status Change Business Event
4873
4874 IF l_old_user_status_id <> l_new_user_status_id THEN
4875 IF G_DEBUG THEN
4876 OZF_UTILITY_PVT.debug_message('Raises business event');
4877 END IF;
4878 --//Get the user status names
4879 OPEN c_user_status_name(l_old_user_status_id);
4880 FETCH c_user_status_name INTO l_old_user_stat_name;
4881 CLOSE c_user_status_name;
4882
4883 OPEN c_user_status_name(l_new_user_status_id);
4884 FETCH c_user_status_name INTO l_new_user_stat_name;
4885 CLOSE c_user_status_name;
4886
4887 raise_status_business_event(
4888 p_request_header_id =>l_new_sdr_hdr_rec.request_header_id
4889 ,p_from_status => l_old_user_stat_name
4890 ,p_to_status => l_new_user_stat_name);
4891
4892 END IF;
4893
4894 --//1.XML Gateway Business Event
4895 /*
4896 Raises a XML Gateway business event if the following three conditions are satisfied:
4897 * a) whenever there is status change
4898 * b) New status is 'PENDING_SUPPLIER_APPROVAL'
4899 * c) Trade profile value is 'XML'
4900 */
4901 OPEN c_communication(l_old_sdr_hdr_rec.supplier_id,l_old_sdr_hdr_rec.supplier_site_id);
4902 FETCH c_communication INTO l_request_communication;
4903 CLOSE c_communication;
4904
4905 IF (l_old_status_code <> l_new_status_code)
4906 AND (l_new_status_code='PENDING_SUPPLIER_APPROVAL')
4907 AND (l_request_communication ='XML') THEN
4908
4909 IF G_DEBUG THEN
4910 OZF_UTILITY_PVT.debug_message('Raises a XML Gateway business event');
4911 END IF;
4912 raise_XML_business_event(
4913 p_request_header_id => l_new_sdr_hdr_rec.request_header_id
4914 ,p_supplier_id => l_old_sdr_hdr_rec.supplier_id
4915 ,p_supplier_site_id => l_old_sdr_hdr_rec.supplier_site_id);
4916
4917 END IF;
4918
4919 FND_MSG_PUB.Count_And_Get (
4920 p_encoded => FND_API.G_FALSE,
4921 p_count => x_msg_count,
4922 p_data => x_msg_data
4923 );
4924 --==============================================================================
4925 EXCEPTION
4926 WHEN FND_API.G_EXC_ERROR THEN
4927 ROLLBACK TO UPDATE_SDR_PUB;
4928 x_return_status := FND_API.G_RET_STS_ERROR;
4929 -- Standard call to get message count and if count=1, get the message
4930 FND_MSG_PUB.Count_And_Get (
4931 p_encoded => FND_API.G_FALSE,
4932 p_count => x_msg_count,
4933 p_data => x_msg_data
4934 );
4935 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
4936 ROLLBACK TO UPDATE_SDR_PUB;
4937 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4938 -- Standard call to get message count and if count=1, get the message
4939 FND_MSG_PUB.Count_And_Get (
4940 p_encoded => FND_API.G_FALSE,
4941 p_count => x_msg_count,
4942 p_data => x_msg_data
4943 );
4944 WHEN OTHERS THEN
4945 ROLLBACK TO UPDATE_SDR_PUB;
4946 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4947 IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
4948 FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
4949 END IF;
4950 -- Standard call to get message count and if count=1, get the message
4951 FND_MSG_PUB.Count_And_Get (
4952 p_encoded => FND_API.G_FALSE,
4953 p_count => x_msg_count,
4954 p_data => x_msg_data
4955 );
4956 END update_sd_request;
4957
4958 ---------------------------------------------------------------------
4959 -- PROCEDURE
4960 -- copy_sd_request
4961 --
4962 -- PURPOSE
4963 -- Public API for Copying SDR
4964 ---------------------------------------------------------------------
4965 PROCEDURE copy_sd_request(
4966 p_api_version_number IN NUMBER,
4967 p_init_msg_list IN VARCHAR2 := FND_API.G_FALSE,
4968 p_commit IN VARCHAR2 := FND_API.G_FALSE,
4969 p_validation_level IN NUMBER := FND_API.g_valid_level_full,
4970 x_return_status OUT NOCOPY VARCHAR2,
4971 x_msg_count OUT NOCOPY NUMBER,
4972 x_msg_data OUT NOCOPY VARCHAR2,
4973 p_source_request_id IN VARCHAR2,
4974 p_new_request_number IN VARCHAR2,
4975 p_accrual_type IN VARCHAR2,
4976 p_cust_account_id IN NUMBER,
4977 p_request_start_date IN DATE,
4978 p_request_end_date IN DATE,
4979 p_copy_product_flag IN VARCHAR2 DEFAULT 'N',
4980 p_copy_customer_flag IN VARCHAR2 DEFAULT 'N',
4981 p_copy_end_customer_flag IN VARCHAR2 DEFAULT 'N',
4982 p_request_source IN VARCHAR2 DEFAULT 'API',
4983 x_request_header_id OUT NOCOPY NUMBER)
4984 IS
4985
4986 l_api_name CONSTANT VARCHAR2(30) := 'copy_sd_request';
4987 l_api_version_number CONSTANT NUMBER := 1.0;
4988 l_sdr_source_rec OZF_SD_REQUEST_PUB.SDR_Hdr_rec_type;
4989 l_sd_access_rec OZF_APPROVAL_PVT.sd_access_rec_type;
4990 l_sdr_source_lines_tbl OZF_SD_REQUEST_PUB.SDR_lines_tbl_type;
4991 l_sdr_source_cust_tbl OZF_SD_REQUEST_PUB.SDR_cust_tbl_type;
4992
4993 l_lookup_stat VARCHAR2(1); --To validate from lookups
4994 l_source_rid NUMBER;
4995 l_new_req_no VARCHAR2(30);
4996 l_product_count NUMBER := 0;
4997 l_customer_count NUMBER := 0;
4998 l_end_customer_count NUMBER := 0;
4999 l_product_flag_chk NUMBER;
5000 l_customer_flag_chk NUMBER;
5001 l_end_customer_flag_chk NUMBER;
5002 l_cust_account_id NUMBER;
5003 l_product_exists VARCHAR2(1) :='N';
5004 l_customer_exists VARCHAR2(1) :='N';
5005 l_end_customer_exists VARCHAR2(1) :='N';
5006 l_authorization_period NUMBER :=0;
5007 l_request_end_date DATE;
5008 l_request_start_date DATE;
5009 l_user_id NUMBER;
5010 l_resource_id NUMBER;
5011
5012 CURSOR c_source_request_header_id(p_request_header_id IN NUMBER)IS
5013 SELECT request_header_id
5014 FROM ozf_sd_request_headers_all_b
5015 WHERE request_header_id = p_request_header_id;
5016
5017 CURSOR c_new_request_no(p_request_number IN VARCHAR2)IS
5018 SELECT request_number
5019 FROM ozf_sd_request_headers_all_b
5020 WHERE request_number = p_request_number;
5021
5022 CURSOR c_cust_account_id(p_cust_account_id IN NUMBER) IS
5023 SELECT cust_account_id
5024 FROM hz_cust_accounts
5025 WHERE status ='A'
5026 AND customer_type ='I'
5027 AND cust_account_id =p_cust_account_id;
5028
5029 CURSOR c_source_sd_header(p_request_header_id IN NUMBER)IS
5030 SELECT
5031 request_outcome,
5032 request_currency_code,
5033 attribute_category,
5034 attribute1,
5035 attribute2,
5036 attribute3,
5037 attribute4,
5038 attribute5,
5039 attribute6,
5040 attribute7,
5041 attribute8,
5042 attribute9,
5043 attribute10,
5044 attribute11,
5045 attribute12,
5046 attribute13,
5047 attribute14,
5048 attribute15,
5049 supplier_id,
5050 supplier_site_id,
5051 supplier_contact_id,
5052 --requestor_id,
5053 sales_order_currency,
5054 org_id,
5055 accrual_type,
5056 cust_account_id,
5057 supplier_contact_email_address,
5058 supplier_contact_phone_number,
5059 request_type_setup_id,
5060 request_basis,
5061 supplier_contact_name --//Bugfix : 7822442
5062 FROM ozf_sd_request_headers_all_b
5063 WHERE request_header_id = p_request_header_id;
5064
5065 CURSOR c_tl_description(p_request_header_id IN NUMBER)IS
5066 SELECT request_description
5067 FROM ozf_sd_request_headers_all_tl
5068 WHERE request_header_id = p_request_header_id;
5069
5070 CURSOR c_product_flag_check(p_request_header_id IN NUMBER)IS
5071 SELECT COUNT(1)
5072 FROM ozf_sd_request_lines_all
5073 WHERE request_header_id = p_request_header_id;
5074
5075 --backdated Adjustment ER , the lines that are end dated and restricted via qualifier should not be copied.
5076 CURSOR c_source_sd_lines(p_request_header_id IN NUMBER)IS
5077 SELECT product_context,
5078 inventory_item_id,
5079 prod_catg_id,
5080 product_cat_set_id,
5081 product_cost,
5082 item_uom,
5083 requested_discount_type,
5084 requested_discount_value,
5085 cost_basis,
5086 max_qty,
5087 limit_qty,
5088 design_win,
5089 end_customer_price,
5090 requested_line_amount,
5091 attribute_category,
5092 attribute1,
5093 attribute2,
5094 attribute3,
5095 attribute4,
5096 attribute5,
5097 attribute6,
5098 attribute7,
5099 attribute8,
5100 attribute9,
5101 attribute10,
5102 attribute11,
5103 attribute12,
5104 attribute13,
5105 attribute14,
5106 attribute15,
5107 vendor_approved_flag,
5108 vendor_item_code,
5109 end_customer_price_type,
5110 end_customer_tolerance_type,
5111 end_customer_tolerance_value,
5112 org_id,
5113 rejection_code,
5114 requested_discount_currency,
5115 product_cost_currency,
5116 end_customer_currency,
5117 approved_discount_currency
5118 FROM ozf_sd_request_lines_all
5119 WHERE request_header_id = p_request_header_id;
5120
5121 CURSOR c_cust_flag_check(p_request_header_id IN NUMBER,p_end_customer_flag IN VARCHAR2)IS
5122 SELECT COUNT(1)
5123 FROM ozf_sd_customer_details
5124 WHERE request_header_id = p_request_header_id
5125 AND end_customer_flag = p_end_customer_flag;
5126
5127 CURSOR c_source_customer_dtl(p_request_header_id IN NUMBER,p_end_customer_flag IN VARCHAR2)IS
5128 SELECT
5129 cust_account_id,
5130 party_id,
5131 site_use_id,
5132 cust_usage_code,
5133 attribute_category,
5134 attribute1,
5135 attribute2,
5136 attribute3,
5137 attribute4,
5138 attribute5,
5139 attribute6,
5140 attribute7,
5141 attribute8,
5142 attribute9,
5143 attribute10,
5144 attribute11,
5145 attribute12,
5146 attribute13,
5147 attribute14,
5148 attribute15,
5149 end_customer_flag,
5150 cust_usage_value
5151 FROM ozf_sd_customer_details
5152 WHERE request_header_id = p_request_header_id
5153 AND end_customer_flag = p_end_customer_flag;
5154
5155 CURSOR c_authorization_period(p_supplier_id IN NUMBER,
5156 p_supplier_site_id IN NUMBER,
5157 p_org_id IN NUMBER)IS
5158 SELECT NVL(authorization_period,-1)
5159 FROM ozf_supp_trd_prfls_all
5160 WHERE supplier_id = p_supplier_id
5161 AND supplier_site_id = p_supplier_site_id
5162 AND org_id = p_org_id;
5163
5164 CURSOR c_resource_id (p_user_id IN NUMBER) IS
5165 SELECT resource_id
5166 FROM jtf_rs_resource_extns
5167 WHERE start_date_active <= sysdate
5168 AND nvl(end_date_active,sysdate) >= sysdate
5169 AND resource_id > 0
5170 AND (category = 'EMPLOYEE' OR category = 'PARTNER' OR category = 'PARTY')
5171 AND user_id = p_user_id;
5172
5173 BEGIN
5174 -- Standard Start of API savepoint
5175 SAVEPOINT COPY_SDR_PUB;
5176 -- Standard call to check for call compatibility.
5177 IF NOT FND_API.Compatible_API_Call ( l_api_version_number,
5178 p_api_version_number,
5179 l_api_name,
5180 G_PKG_NAME)
5181 THEN
5182 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5183 END IF;
5184
5185 -- Initialize message list if p_init_msg_list is set to TRUE.
5186 IF FND_API.to_Boolean( p_init_msg_list )
5187 THEN
5188 FND_MSG_PUB.initialize;
5189 END IF;
5190 -- Debug Message
5191 IF G_DEBUG THEN
5192 OZF_UTILITY_PVT.debug_message('Public API: ' || l_api_name || ' pub start');
5193 END IF;
5194 -- Initialize API return status to SUCCESS
5195 x_return_status := FND_API.G_RET_STS_SUCCESS;
5196 --==============================================================================
5197 --//Bug 7190421 - User Check and population
5198
5199 l_user_id := FND_GLOBAL.user_id;
5200
5201 IF G_DEBUG THEN
5202 OZF_UTILITY_PVT.debug_message('l_user_id: ' ||l_user_id);
5203 END IF;
5204 --//Check if user is a valid resource or not
5205 OPEN c_resource_id(l_user_id);
5206 FETCH c_resource_id INTO l_resource_id;
5207 CLOSE c_resource_id;
5208
5209 IF l_resource_id IS NULL THEN
5210 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
5211 FND_MESSAGE.set_name('OZF', 'OZF_SD_USER_IS_NOT_RESOURCE');
5212 FND_MSG_PUB.add;
5213 END IF;
5214 x_return_status := fnd_api.g_ret_sts_error;
5215 RETURN;
5216 END IF;
5217
5218 IF G_DEBUG THEN
5219 OZF_UTILITY_PVT.debug_message('l_resource_id: ' ||l_resource_id);
5220 END IF;
5221
5222
5223 --//Check If Source Request Id is valid
5224 IF p_source_request_id IS NOT NULL THEN
5225 OPEN c_source_request_header_id(p_source_request_id);
5226 FETCH c_source_request_header_id INTO l_source_rid;
5227 CLOSE c_source_request_header_id;
5228
5229 IF l_source_rid IS NULL THEN
5230 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
5231 FND_MESSAGE.set_name('OZF', 'OZF_SD_INVALID_SOURCE_REQ_ID');
5232 --//Invalid source request id. Please re-enter
5233 FND_MSG_PUB.add;
5234 END IF;
5235 x_return_status := fnd_api.g_ret_sts_error;
5236 RETURN;
5237 END IF;
5238 ELSE
5239 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
5240 FND_MESSAGE.set_name('OZF', 'OZF_SD_NO_SOURCE_REQ_ID');
5241 --//Invalid source request id. Please re-enter
5242 FND_MSG_PUB.add;
5243 END IF;
5244 x_return_status := fnd_api.g_ret_sts_error;
5245 RETURN;
5246 END IF;
5247
5248 --//Check If New Request Number already exists
5249 IF p_new_request_number IS NOT NULL THEN
5250 OPEN c_new_request_no(p_new_request_number);
5251 FETCH c_new_request_no INTO l_new_req_no;
5252 CLOSE c_new_request_no;
5253
5254 IF l_new_req_no IS NOT NULL THEN
5255 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
5256 FND_MESSAGE.set_name('OZF', 'OZF_SD_DUP_SOURCE_REQ_NO');
5257 --//New request number entered is already exists.
5258 FND_MSG_PUB.add;
5259 END IF;
5260 x_return_status := fnd_api.g_ret_sts_error;
5261 RETURN;
5262 END IF;
5263 END IF;
5264 --//Accrual type Check
5265 IF p_accrual_type IS NOT NULL THEN
5266 l_lookup_stat :=OZF_UTILITY_PVT.check_lookup_exists(
5267 p_lookup_table_name =>'OZF_LOOKUPS'
5268 ,p_lookup_type =>'OZF_SDR_ACCRUAL_TYPE'
5269 ,p_lookup_code => p_accrual_type);
5270
5271 IF l_lookup_stat = FND_API.g_false THEN
5272 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
5273 FND_MESSAGE.set_name('OZF', 'OZF_SD_INVALID_ACCRUAL_TYPE');
5274 FND_MSG_PUB.add;
5275 END IF;
5276 x_return_status := fnd_api.g_ret_sts_error;
5277 RETURN;
5278 END IF;
5279 ELSE
5280 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
5281 FND_MESSAGE.set_name('OZF', 'OZF_SD_NO_ACCRUAL_TYPE');
5282 --//Accrual type is Mandatory
5283 FND_MSG_PUB.add;
5284 END IF;
5285 x_return_status := fnd_api.g_ret_sts_error;
5286 RETURN;
5287 END IF;
5288
5289 --//Cust Account ID Validation
5290 IF p_accrual_type ='INTERNAL' THEN
5291
5292 IF p_cust_account_id IS NULL THEN
5293 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
5294 FND_MESSAGE.set_name('OZF', 'OZF_SD_NO_CUST_ACCOUNT_ID');
5295 FND_MSG_PUB.add;
5296 END IF;
5297 x_return_status := fnd_api.g_ret_sts_error;
5298 RETURN;
5299 ELSE
5300 OPEN c_cust_account_id(p_cust_account_id);
5301 FETCH c_cust_account_id INTO l_cust_account_id;
5302 CLOSE c_cust_account_id;
5303
5304 IF l_cust_account_id IS NULL THEN
5305 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
5306 FND_MESSAGE.set_name('OZF', 'OZF_SD_INVALID_CUST_ACCOUNT_ID');
5307 FND_MSG_PUB.add;
5308 END IF;
5309 x_return_status := fnd_api.g_ret_sts_error;
5310 RETURN;
5311 END IF;
5312 END IF;
5313 END IF;
5314
5315 --//Check if product lines exists
5316 IF p_copy_product_flag ='Y' THEN
5317 OPEN c_product_flag_check(p_source_request_id);
5318 FETCH c_product_flag_check INTO l_product_flag_chk;
5319 CLOSE c_product_flag_check;
5320
5321 IF l_product_flag_chk > 0 THEN
5322 l_product_exists :='Y';
5323 ELSE
5324 l_product_exists :='N';
5325 END IF;
5326 END IF;
5327
5328 --//Check if Customer exists
5329 IF p_copy_customer_flag ='Y' THEN
5330 OPEN c_cust_flag_check(p_source_request_id,'N'); --> N for Customer
5331 FETCH c_cust_flag_check INTO l_customer_flag_chk;
5332 CLOSE c_cust_flag_check;
5333
5334 IF l_customer_flag_chk > 0 THEN
5335 l_customer_exists :='Y';
5336 ELSE
5337 l_customer_exists :='N';
5338 END IF;
5339 END IF;
5340
5341 --//Check if End Customer exists
5342 IF p_copy_end_customer_flag ='Y' THEN
5343 OPEN c_cust_flag_check(p_source_request_id,'Y'); --> Y for End Customer
5344 FETCH c_cust_flag_check INTO l_end_customer_flag_chk;
5345 CLOSE c_cust_flag_check;
5346
5347 IF l_end_customer_flag_chk > 0 THEN
5348 l_end_customer_exists :='Y';
5349 ELSE
5350 l_end_customer_exists :='N';
5351 END IF;
5352 END IF;
5353
5354 IF p_request_source NOT IN ('API','Manual') THEN
5355 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
5356 FND_MESSAGE.set_name('OZF', 'OZF_SD_INVALID_REQUEST_SOURCE');
5357 FND_MSG_PUB.add;
5358 END IF;
5359 x_return_status := fnd_api.g_ret_sts_error;
5360 RETURN;
5361 END IF;
5362
5363 --//Get the source Information
5364 --l_sdr_source_rec.request_source := p_request_source;
5365
5366 OPEN c_source_sd_header(p_source_request_id);
5367 FETCH c_source_sd_header INTO l_sdr_source_rec.request_outcome,
5368 l_sdr_source_rec.request_currency_code,
5369 l_sdr_source_rec.attribute_category,
5370 l_sdr_source_rec.attribute1,
5371 l_sdr_source_rec.attribute2,
5372 l_sdr_source_rec.attribute3,
5373 l_sdr_source_rec.attribute4,
5374 l_sdr_source_rec.attribute5,
5375 l_sdr_source_rec.attribute6,
5376 l_sdr_source_rec.attribute7,
5377 l_sdr_source_rec.attribute8,
5378 l_sdr_source_rec.attribute9,
5379 l_sdr_source_rec.attribute10,
5380 l_sdr_source_rec.attribute11,
5381 l_sdr_source_rec.attribute12,
5382 l_sdr_source_rec.attribute13,
5383 l_sdr_source_rec.attribute14,
5384 l_sdr_source_rec.attribute15,
5385 l_sdr_source_rec.supplier_id,
5386 l_sdr_source_rec.supplier_site_id,
5387 l_sdr_source_rec.supplier_contact_id,
5388 -- l_sdr_source_rec.requestor_id,
5389 l_sdr_source_rec.sales_order_currency,
5390 l_sdr_source_rec.org_id,
5391 l_sdr_source_rec.accrual_type,
5392 l_sdr_source_rec.cust_account_id,
5393 l_sdr_source_rec.supplier_contact_email_address,
5394 l_sdr_source_rec.supplier_contact_phone_number,
5395 l_sdr_source_rec.request_type_setup_id,
5396 l_sdr_source_rec.request_basis,
5397 l_sdr_source_rec.supplier_contact_name; --//Bugfix : 7822442
5398 CLOSE c_source_sd_header;
5399
5400 --//BugFix : 7607795 - Start Date/End date Validation
5401 l_request_start_date :=p_request_start_date;
5402
5403 IF l_request_start_date IS NOT NULL AND p_request_end_date IS NULL THEN
5404 OPEN c_authorization_period(l_sdr_source_rec.supplier_id
5405 ,l_sdr_source_rec.supplier_site_id
5406 ,l_sdr_source_rec.org_id);
5407
5408 FETCH c_authorization_period INTO l_authorization_period;
5409 CLOSE c_authorization_period;
5410
5411 IF l_authorization_period <> -1 THEN
5412 l_request_end_date := l_request_start_date + l_authorization_period;
5413 END IF;
5414 END IF;
5415
5416 IF p_request_end_date IS NOT NULL THEN
5417 l_request_end_date := p_request_end_date;
5418 END IF;
5419
5420 IF p_request_end_date < p_request_start_date THEN
5421 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
5422 FND_MESSAGE.set_name('OZF', 'OZF_SD_INVALID_END_DATE');
5423 --//End date should be greater than start date
5424 FND_MSG_PUB.add;
5425 END IF;
5426 x_return_status := fnd_api.g_ret_sts_error;
5427 RETURN;
5428 END IF;
5429
5430 IF G_DEBUG THEN
5431 OZF_UTILITY_PVT.debug_message('Copy Option ');
5432 OZF_UTILITY_PVT.debug_message('Source accrual_type :'||l_sdr_source_rec.accrual_type);
5433 OZF_UTILITY_PVT.debug_message('New accrual_type :'|| p_accrual_type);
5434 END IF;
5435
5436 IF (l_sdr_source_rec.accrual_type ='INTERNAL') AND (p_accrual_type ='SUPPLIER') THEN
5437 --Invalid Copy Option
5438 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
5439 FND_MESSAGE.set_name('OZF', 'OZF_SD_INVALID_COPY_OPTION');
5440 --//Internal to Supplier Copy option is invalid!
5441 FND_MSG_PUB.add;
5442 END IF;
5443 x_return_status := fnd_api.g_ret_sts_error;
5444 RETURN;
5445
5446 ELSIF ((l_sdr_source_rec.accrual_type ='SUPPLIER') AND (p_accrual_type ='INTERNAL')) OR p_accrual_type ='INTERNAL' THEN
5447 l_sdr_source_rec.accrual_type := p_accrual_type;
5448 l_sdr_source_rec.cust_account_id := p_cust_account_id;
5449 l_sdr_source_rec.supplier_id :=NULL;
5450 l_sdr_source_rec.supplier_site_id :=NULL;
5451 l_sdr_source_rec.supplier_contact_id :=NULL;
5452 l_sdr_source_rec.supplier_contact_name :=NULL; --//Bugfix : 7822442
5453 l_sdr_source_rec.supplier_contact_email_address :=NULL;
5454 l_sdr_source_rec.supplier_contact_phone_number :=NULL;
5455
5456
5457 END IF;
5458
5459 --//Copy Header Information
5460
5461 --//Initilizations
5462 l_sdr_source_rec.request_header_id :=p_source_request_id; --//To populate Root Request Header ID
5463 l_sdr_source_rec.request_number :=p_new_request_number;
5464 l_sdr_source_rec.request_start_date :=TRUNC(l_request_start_date);
5465 l_sdr_source_rec.request_end_date :=TRUNC(l_request_end_date);
5466 l_sdr_source_rec.requestor_id :=l_resource_id;
5467
5468 --//Get the User status ID
5469 l_sdr_source_rec.user_status_id :=get_user_status_id('DRAFT');
5470
5471 IF G_DEBUG THEN
5472 OZF_UTILITY_PVT.debug_message('Populate Header table');
5473 END IF;
5474 --//Populate Header table
5475 Insert_header_record(
5476 p_SDR_hdr_rec => l_sdr_source_rec
5477 ,p_request_source => p_request_source
5478 ,x_request_header_id => x_request_header_id
5479 ,x_return_status => x_return_status);
5480
5481 IF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
5482 RAISE fnd_api.g_exc_unexpected_error;
5483 ELSIF x_return_status = fnd_api.g_ret_sts_error THEN
5484 RAISE fnd_api.g_exc_error;
5485 END IF;
5486
5487 --//Populate Translation table
5488 OPEN c_tl_description(p_source_request_id);
5489 FETCH c_tl_description INTO l_sdr_source_rec.request_description;
5490 CLOSE c_tl_description;
5491
5492 IF G_DEBUG THEN
5493 OZF_UTILITY_PVT.debug_message('Populate Translation table');
5494 END IF;
5495 populate_translation_record(
5496 p_request_header_id =>x_request_header_id
5497 ,p_description =>l_sdr_source_rec.request_description
5498 ,p_org_id =>l_sdr_source_rec.org_id
5499 ,p_mode =>'COPY'
5500 ,x_return_status => x_return_status);
5501
5502 IF G_DEBUG THEN
5503 OZF_UTILITY_PVT.debug_message('x_request_header_id '||x_request_header_id);
5504 END IF;
5505
5506 IF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
5507 RAISE fnd_api.g_exc_unexpected_error;
5508 ELSIF x_return_status = fnd_api.g_ret_sts_error THEN
5509 RAISE fnd_api.g_exc_error;
5510 END IF;
5511
5512 --//Populate SD Access table
5513 --//For Owner
5514
5515 OZF_APPROVAL_PVT.Add_SD_Access(
5516 p_api_version =>p_api_version_number
5517 ,p_init_msg_list =>FND_API.G_FALSE
5518 ,p_commit =>FND_API.G_FALSE
5519 ,p_validation_level =>p_validation_level
5520 ,p_request_header_id =>x_request_header_id
5521 ,p_user_id =>NULL
5522 ,p_resource_id =>l_sdr_source_rec.requestor_id
5523 ,p_person_id =>NULL
5524 ,p_owner_flag =>'Y'
5525 ,p_approver_flag =>NULL
5526 ,p_enabled_flag =>'Y'
5527 ,x_return_status =>x_return_status
5528 ,x_msg_count =>x_msg_count
5529 ,x_msg_data =>x_msg_data);
5530
5531 IF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
5532 RAISE fnd_api.g_exc_unexpected_error;
5533 ELSIF x_return_status = fnd_api.g_ret_sts_error THEN
5534 RAISE fnd_api.g_exc_error;
5535 END IF;
5536
5537
5538 IF G_DEBUG THEN
5539 OZF_UTILITY_PVT.debug_message('Copy Product Lines');
5540 END IF;
5541 --//Copy Product Lines
5542 IF ((p_copy_product_flag ='Y') AND (l_product_exists ='Y'))THEN
5543 OPEN c_source_sd_lines(p_source_request_id);
5544 LOOP
5545 l_product_count := l_product_count + 1;
5546 IF G_DEBUG THEN
5547 OZF_UTILITY_PVT.debug_message('Inside Loop :'||l_product_count);
5548 END IF;
5549
5550 FETCH c_source_sd_lines INTO
5551 l_sdr_source_lines_tbl(l_product_count).product_context,
5552 l_sdr_source_lines_tbl(l_product_count).inventory_item_id,
5553 l_sdr_source_lines_tbl(l_product_count).prod_catg_id,
5554 l_sdr_source_lines_tbl(l_product_count).product_cat_set_id,
5555 l_sdr_source_lines_tbl(l_product_count).product_cost,
5556 l_sdr_source_lines_tbl(l_product_count).item_uom,
5557 l_sdr_source_lines_tbl(l_product_count).requested_discount_type,
5558 l_sdr_source_lines_tbl(l_product_count).requested_discount_value,
5559 l_sdr_source_lines_tbl(l_product_count).cost_basis,
5560 l_sdr_source_lines_tbl(l_product_count).max_qty,
5561 l_sdr_source_lines_tbl(l_product_count).limit_qty,
5562 l_sdr_source_lines_tbl(l_product_count).design_win,
5563 l_sdr_source_lines_tbl(l_product_count).end_customer_price,
5564 l_sdr_source_lines_tbl(l_product_count).requested_line_amount,
5565 l_sdr_source_lines_tbl(l_product_count).attribute_category,
5566 l_sdr_source_lines_tbl(l_product_count).attribute1,
5567 l_sdr_source_lines_tbl(l_product_count).attribute2,
5568 l_sdr_source_lines_tbl(l_product_count).attribute3,
5569 l_sdr_source_lines_tbl(l_product_count).attribute4,
5570 l_sdr_source_lines_tbl(l_product_count).attribute5,
5571 l_sdr_source_lines_tbl(l_product_count).attribute6,
5572 l_sdr_source_lines_tbl(l_product_count).attribute7,
5573 l_sdr_source_lines_tbl(l_product_count).attribute8,
5574 l_sdr_source_lines_tbl(l_product_count).attribute9,
5575 l_sdr_source_lines_tbl(l_product_count).attribute10,
5576 l_sdr_source_lines_tbl(l_product_count).attribute11,
5577 l_sdr_source_lines_tbl(l_product_count).attribute12,
5578 l_sdr_source_lines_tbl(l_product_count).attribute13,
5579 l_sdr_source_lines_tbl(l_product_count).attribute14,
5580 l_sdr_source_lines_tbl(l_product_count).attribute15,
5581 l_sdr_source_lines_tbl(l_product_count).vendor_approved_flag,
5582 l_sdr_source_lines_tbl(l_product_count).vendor_item_code,
5583 l_sdr_source_lines_tbl(l_product_count).end_customer_price_type,
5584 l_sdr_source_lines_tbl(l_product_count).end_customer_tolerance_type,
5585 l_sdr_source_lines_tbl(l_product_count).end_customer_tolerance_value,
5586 l_sdr_source_lines_tbl(l_product_count).org_id,
5587 l_sdr_source_lines_tbl(l_product_count).rejection_code,
5588 l_sdr_source_lines_tbl(l_product_count).requested_discount_currency,
5589 l_sdr_source_lines_tbl(l_product_count).product_cost_currency,
5590 l_sdr_source_lines_tbl(l_product_count).end_customer_currency,
5591 l_sdr_source_lines_tbl(l_product_count).approved_discount_currency;
5592 EXIT WHEN c_source_sd_lines%NOTFOUND;
5593
5594 l_sdr_source_lines_tbl(l_product_count).start_date := TRUNC(l_request_start_date);
5595 l_sdr_source_lines_tbl(l_product_count).end_date := TRUNC(l_request_end_date);
5596
5597 --//Item Organization ID setup
5598 G_ITEM_ORG_ID :=l_sdr_source_lines_tbl(l_product_count).org_id;
5599 IF p_accrual_type ='INTERNAL' THEN
5600 --//Vendor Approved Flag should be defaulted to Y
5601 l_sdr_source_lines_tbl(l_product_count).vendor_approved_flag := 'Y';
5602 END IF;
5603 END LOOP;
5604 CLOSE c_source_sd_lines;
5605
5606 --//Proulate Product Lines
5607 populate_product_lines(
5608 p_request_header_id => x_request_header_id
5609 ,p_SDR_lines_tbl => l_sdr_source_lines_tbl
5610 ,x_return_status => x_return_status);
5611
5612 IF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
5613 RAISE fnd_api.g_exc_unexpected_error;
5614 ELSIF x_return_status = fnd_api.g_ret_sts_error THEN
5615 RAISE fnd_api.g_exc_error;
5616 END IF;
5617 END IF;
5618
5619 --//Copy Customer
5620 IF ((p_copy_customer_flag='Y') AND (l_customer_exists ='Y')) THEN
5621 l_sdr_source_cust_tbl.DELETE;
5622 OPEN c_source_customer_dtl(p_source_request_id,'N');
5623 LOOP
5624 l_customer_count := l_customer_count + 1;
5625 FETCH c_source_customer_dtl INTO
5626 l_sdr_source_cust_tbl(l_customer_count).cust_account_id,
5627 l_sdr_source_cust_tbl(l_customer_count).party_id,
5628 l_sdr_source_cust_tbl(l_customer_count).site_use_id,
5629 l_sdr_source_cust_tbl(l_customer_count).cust_usage_code,
5630 l_sdr_source_cust_tbl(l_customer_count).attribute_category,
5631 l_sdr_source_cust_tbl(l_customer_count).attribute1,
5632 l_sdr_source_cust_tbl(l_customer_count).attribute2,
5633 l_sdr_source_cust_tbl(l_customer_count).attribute3,
5634 l_sdr_source_cust_tbl(l_customer_count).attribute4,
5635 l_sdr_source_cust_tbl(l_customer_count).attribute5,
5636 l_sdr_source_cust_tbl(l_customer_count).attribute6,
5637 l_sdr_source_cust_tbl(l_customer_count).attribute7,
5638 l_sdr_source_cust_tbl(l_customer_count).attribute8,
5639 l_sdr_source_cust_tbl(l_customer_count).attribute9,
5640 l_sdr_source_cust_tbl(l_customer_count).attribute10,
5641 l_sdr_source_cust_tbl(l_customer_count).attribute11,
5642 l_sdr_source_cust_tbl(l_customer_count).attribute12,
5643 l_sdr_source_cust_tbl(l_customer_count).attribute13,
5644 l_sdr_source_cust_tbl(l_customer_count).attribute14,
5645 l_sdr_source_cust_tbl(l_customer_count).attribute15,
5646 l_sdr_source_cust_tbl(l_customer_count).end_customer_flag,
5647 l_sdr_source_cust_tbl(l_customer_count).cust_usage_value;
5648 EXIT WHEN c_source_customer_dtl%NOTFOUND;
5649 END LOOP;
5650 CLOSE c_source_customer_dtl;
5651 --//Populate Customer Details table
5652 IF G_DEBUG THEN
5653 OZF_UTILITY_PVT.debug_message('populate_customer_details');
5654 END IF;
5655 populate_customer_details(
5656 p_request_header_id => x_request_header_id
5657 ,p_SDR_cust_tbl => l_sdr_source_cust_tbl
5658 ,x_return_status => x_return_status);
5659
5660
5661 IF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
5662 RAISE fnd_api.g_exc_unexpected_error;
5663 ELSIF x_return_status = fnd_api.g_ret_sts_error THEN
5664 RAISE fnd_api.g_exc_error;
5665 END IF;
5666
5667 END IF;
5668
5669 IF ((p_copy_end_customer_flag='Y') AND (l_end_customer_exists ='Y')) THEN
5670 l_sdr_source_cust_tbl.DELETE;
5671 OPEN c_source_customer_dtl(p_source_request_id,'Y');
5672 LOOP
5673 l_end_customer_count := l_end_customer_count + 1;
5674 FETCH c_source_customer_dtl INTO
5675 l_sdr_source_cust_tbl(l_end_customer_count).cust_account_id,
5676 l_sdr_source_cust_tbl(l_end_customer_count).party_id,
5677 l_sdr_source_cust_tbl(l_end_customer_count).site_use_id,
5678 l_sdr_source_cust_tbl(l_end_customer_count).cust_usage_code,
5679 l_sdr_source_cust_tbl(l_end_customer_count).attribute_category,
5680 l_sdr_source_cust_tbl(l_end_customer_count).attribute1,
5681 l_sdr_source_cust_tbl(l_end_customer_count).attribute2,
5682 l_sdr_source_cust_tbl(l_end_customer_count).attribute3,
5683 l_sdr_source_cust_tbl(l_end_customer_count).attribute4,
5684 l_sdr_source_cust_tbl(l_end_customer_count).attribute5,
5685 l_sdr_source_cust_tbl(l_end_customer_count).attribute6,
5686 l_sdr_source_cust_tbl(l_end_customer_count).attribute7,
5687 l_sdr_source_cust_tbl(l_end_customer_count).attribute8,
5688 l_sdr_source_cust_tbl(l_end_customer_count).attribute9,
5689 l_sdr_source_cust_tbl(l_end_customer_count).attribute10,
5690 l_sdr_source_cust_tbl(l_end_customer_count).attribute11,
5691 l_sdr_source_cust_tbl(l_end_customer_count).attribute12,
5692 l_sdr_source_cust_tbl(l_end_customer_count).attribute13,
5693 l_sdr_source_cust_tbl(l_end_customer_count).attribute14,
5694 l_sdr_source_cust_tbl(l_end_customer_count).attribute15,
5695 l_sdr_source_cust_tbl(l_end_customer_count).end_customer_flag,
5696 l_sdr_source_cust_tbl(l_end_customer_count).cust_usage_value;
5697 EXIT WHEN c_source_customer_dtl%NOTFOUND;
5698 END LOOP;
5699 CLOSE c_source_customer_dtl;
5700 --//Populate End Customer Details table
5701 populate_customer_details(
5702 p_request_header_id => x_request_header_id
5703 ,p_SDR_cust_tbl => l_sdr_source_cust_tbl
5704 ,x_return_status => x_return_status);
5705
5706 IF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
5707 RAISE fnd_api.g_exc_unexpected_error;
5708 ELSIF x_return_status = fnd_api.g_ret_sts_error THEN
5709 RAISE fnd_api.g_exc_error;
5710 END IF;
5711
5712 END IF;
5713
5714 -- Commit the process
5715 IF G_DEBUG THEN
5716 OZF_UTILITY_PVT.debug_message('New request_header_id :'||x_request_header_id );
5717 OZF_UTILITY_PVT.debug_message('Return Status :'|| x_return_status );
5718 OZF_UTILITY_PVT.debug_message('Public API: ' || l_api_name || ' End..');
5719 END IF;
5720 IF FND_API.to_Boolean( p_commit )
5721 THEN
5722 COMMIT WORK;
5723 END IF;
5724
5725 FND_MSG_PUB.Count_And_Get (
5726 p_encoded => FND_API.G_FALSE,
5727 p_count => x_msg_count,
5728 p_data => x_msg_data
5729 );
5730
5731 --==============================================================================
5732 EXCEPTION
5733 WHEN FND_API.G_EXC_ERROR THEN
5734 ROLLBACK TO COPY_SDR_PUB;
5735 x_return_status := FND_API.G_RET_STS_ERROR;
5736 -- Standard call to get message count and if count=1, get the message
5737 FND_MSG_PUB.Count_And_Get (
5738 p_encoded => FND_API.G_FALSE,
5739 p_count => x_msg_count,
5740 p_data => x_msg_data
5741 );
5742 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
5743 ROLLBACK TO COPY_SDR_PUB;
5744 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5745 -- Standard call to get message count and if count=1, get the message
5746 FND_MSG_PUB.Count_And_Get (
5747 p_encoded => FND_API.G_FALSE,
5748 p_count => x_msg_count,
5749 p_data => x_msg_data
5750 );
5751 WHEN OTHERS THEN
5752 ROLLBACK TO COPY_SDR_PUB;
5753 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5754 IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
5755 FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
5756 END IF;
5757 -- Standard call to get message count and if count=1, get the message
5758 FND_MSG_PUB.Count_And_Get (
5759 p_encoded => FND_API.G_FALSE,
5760 p_count => x_msg_count,
5761 p_data => x_msg_data
5762 );
5763 END copy_sd_request;
5764 END OZF_SD_REQUEST_PUB;