DBA Data[Home] [Help]

PACKAGE BODY: APPS.INVPVALI

Source


1 PACKAGE BODY INVPVALI AS
2 /* $Header: INVPVALB.pls 120.11.12010000.2 2008/11/05 10:53:12 jatian ship $ */
3 
4 ------------------------ validate_item_revs -----------------------------------
5 
6 function validate_item_revs
7 (
8 org_id          number,
9 all_org         NUMBER          := 2,
10 prog_appid      NUMBER          := -1,
11 prog_id         NUMBER          := -1,
12 request_id      NUMBER          := -1,
13 user_id         NUMBER          := -1,
14 login_id        NUMBER          := -1,
15 err_text in out NOCOPY varchar2,
16 xset_id  IN     NUMBER     DEFAULT -999
17 )
18 return integer
19 is
20 
21 	/*
22 ???	** we have already validate org_id, catg_set_id and catg_id
23 	** in assign function. we only validate item_id here
24 	*/
25 
26    /*
27    ** any row that does not have a corresponding item row in prod or
28    ** inteface table must be flagged as error
29    */
30 
31    CURSOR cc is
32 	select  i.transaction_id,
33 	        i.transaction_type,
34 	        i.inventory_item_id,
35 		i.organization_id ,
36 		i.revision,
37                 rowid
38 	from mtl_item_revisions_interface i
39 	where i.process_flag = 2
40         and   i.set_process_id  = xset_id
41 	and (i.organization_id = org_id or all_org = 1)
42 	and not exists (select 'X'
43 			from mtl_system_items m
44 			where m.organization_id = i.organization_id
45                           and m.inventory_item_id = i.inventory_item_id)
46 	and not exists  (select 'X'
47                          from mtl_system_items_interface mi
48                         where mi.organization_id = i.organization_id
49                           and mi.inventory_item_id = i.inventory_item_id
50 			  and process_flag = 4);
51 
52 	/*
53 	** We are going to check for the validity against the unique index
54 	**	ORGANIZATION_ID,REVISION and INVENTORY_ITEM_ID
55 	*/
56 /*
57 ** if the item-revision combination already exists in production, then
58 ** mark it as an error
59 */
60 /*
61    Bug 1725851 : Removed + 0 on Set Process Id as it was causing
62    Performance issues. Removing this uses Index
63    mtl_item_revs_interface_N3 index instead of FULL Table Scan.
64    Also removed mtl_parameters as it is not required here
65 */
66 	--User can now populate revision_id in the interface table.
67 	CURSOR dd is
68 	select transaction_id,
69 	       transaction_type,
70 	       organization_id,
71 	       inventory_item_id,
72 	       revision,
73 	       revision_id,
74 	       rowid
75 	from mtl_item_revisions_interface
76 	where set_process_id  = xset_id
77 	and   process_flag    = 2;
78 	--2808277 : Above validation applicable to only CREATE
79 	--Above cursor modified to check revision id uniqueness
80 
81         --Start: Check for data security and user privileges
82 	--6318972:Privledge check missing on Rev creation
83         CURSOR c_get_rev_item is
84         select i.rowid,
85 	       i.organization_id,
86                i.inventory_item_id,
87 	       i.transaction_id,
88 	       i.created_by
89         from mtl_item_revisions_interface i
90         where i.set_process_id   = xset_id
91         and   i.process_flag     = 2
92 	and   (i.transaction_type  = 'UPDATE'
93 	       or  exists (select null
94 			  from  mtl_system_items_b m
95 			  where m.organization_id   = i.organization_id
96                           and   m.inventory_item_id = i.inventory_item_id));
97         --End: Check for data security and user privileges
98 /*
99 ** if there are duplicate rows in interface table for item-rev
100 ** combination, mark as error
101 */
102 /* Bug 1725851
103    Rewriting the below cursor to avoid performance issue
104 */
105         CURSOR ee is
106         select m.transaction_id,
107 	       m.transaction_type,
108                m.organization_id,
109                m.inventory_item_id,
110                m.revision,
111 	       m.rowid
112         from mtl_item_revisions_interface m
113         where m.set_process_id = xset_id
114         and   m.process_flag = 2;
115 
116 /*
117 ** item revs must be in alphanumeric and chronological order must check against
118 ** the interface table AND the database table
119 */
120 /* Bug 1725851
121    Rewriting the below cursor to avoid performance issue
122    2806275 : Revision Reason validation
123 */
124         CURSOR ff is
125         select m.transaction_id,
126 	       m.transaction_type,
127                m.organization_id,
128                m.inventory_item_id,
129                m.revision,
130 	       m.revision_id,
131                m.effectivity_date,
132 	       m.ecn_initiation_date,
133 	       m.implementation_date,
134 	       m.revision_reason
135         from mtl_item_revisions_interface m
136         where m.set_process_id = xset_id
137         and   m.process_flag = 2;
138 
139               /*NP 07SEP94 In cursor gg added an or clause here
140               **effectivity date being less or equal to current
141               **effective date..ie an invalid condition
142               **NP 21DEC95 removed check on past effectivity dates.
143               **They are allowed now.
144               */
145   -- Bug 4299292. Use base table mtl_item_revisions_b to fix performance issue
146         CURSOR gg is
147         select i.transaction_id,
148                i.organization_id,
149 	       i.rowid
150         from mtl_item_revisions_b m,
151              mtl_item_revisions_interface i
152         where m.organization_id = i.organization_id
153         and   i.set_process_id  = xset_id
154         and   m.inventory_item_id = i.inventory_item_id
155         and   ( (m.revision < i.revision and  m.effectivity_date >=
156                                                       i.effectivity_date)
157               or (i.revision < m.revision and  i.effectivity_date >=
158                                                       m.effectivity_date)
159                )
160 	and   i.process_flag = 2;
161 	--3569925 : Added = condition for > on effectivity dates.
162 
163 /*
164 ** item revs life cycle  and phases validation
165 */
166 
167         CURSOR c_get_revision_lifecycle IS
168 	   SELECT rowid,
169 	          inventory_item_id,
170 	          organization_id,
171 	          lifecycle_id,
172 	          current_phase_id,
173 		  transaction_id,
174 		  transaction_type,
175 		  revision,
176 		  revision_id
177 	   FROM   mtl_item_revisions_interface i
178 	   WHERE  set_process_id = xset_id
179            AND    process_flag = 2
180 	   FOR UPDATE OF current_phase_id NOWAIT;
181 
182         --3059993:Revision create should honour items phase policy
183 	--Changes added lifecycle,phase ids in the select list.
184 	CURSOR c_get_item_ids(cp_org_id         NUMBER,
185 	                      cp_item_id        NUMBER)
186 	IS
187            SELECT mi.item_catalog_group_id
188    		 ,mi.lifecycle_id
189 	         ,mi.current_phase_id
190 		 ,'U'
191                  ,mi.transaction_type
192            FROM  mtl_system_items_interface mi
193            WHERE mi.organization_id        = cp_org_id
194            AND   mi.inventory_item_id      = cp_item_id
195            AND   mi.process_flag           = 4
196 	   UNION
197            SELECT m.item_catalog_group_id
198    		 ,m.lifecycle_id
199 	         ,m.current_phase_id
200 		 ,NVL(m.approval_status,'A')
201 		 ,'EXISTS'
202 	   FROM  mtl_system_items_b m
203            WHERE m.organization_id        = cp_org_id
204            AND   m.inventory_item_id      = cp_item_id;
205 
206 
207        --2806275 : Revision Reason validation
208        CURSOR c_check_lookup (cp_type fnd_lookup_values_vl.lookup_type%TYPE,
209                               cp_code fnd_lookup_values_vl.lookup_code%TYPE)
210        IS
211          SELECT 'Y'
212          FROM   fnd_lookup_values_vl
213          WHERE  lookup_type  = cp_type
214          AND    lookup_code  = cp_code
215          AND    SYSDATE BETWEEN NVL(start_date_active, SYSDATE) and NVL(end_date_active, SYSDATE)
216          AND    enabled_flag = 'Y';
217 
218        --2885843: default revision error propagated to imported item
219        CURSOR c_get_default_rev(cp_org_id NUMBER)
220        IS
221           select  starting_revision
222           from  mtl_parameters
223           where organization_id = cp_org_id;
224 
225         CURSOR is_gdsn_batch(cp_xset_id NUMBER) IS
226           SELECT 1 FROM ego_import_option_sets
227            WHERE batch_id = cp_xset_id
228              AND enabled_for_data_pool = 'Y';
229 
230 	status		  number;
231 	error_msg	  varchar2(70);
232         l_process_flag_2  number := 2 ;
233         l_process_flag_3  number := 3 ;
234         l_process_flag_4  number := 4 ;
235         l_all_org         number := 1 ;
236         temp_count        number := 0;
237 	LOGGING_ERR	  exception;
238         l_item_catalog    NUMBER;
239 	l_lookup_exist    VARCHAR2(1):='N';
240 	l_default_rev     VARCHAR2(3);
241 	l_lifecycle_error BOOLEAN := FALSE;
242 
243 	--2808277: Update validations for Lifecycle-Phase
244 	l_row_count        NUMBER(3) := 0;
245         l_Old_Phase_Id     mtl_item_revisions_b.current_phase_id%TYPE;
246 	l_Policy_Code      VARCHAR2(20);
247         l_Return_Status    VARCHAR2(1);
248         l_Error_Code       NUMBER;
249         l_Msg_Count        NUMBER;
250         l_Msg_Data         VARCHAR2(2000);
251 	l_has_privilege    VARCHAR2(1) := 'F';
252 
253 	--Start:3059993:Revision create should honour items phase policy
254 	l_item_phase_id     mtl_item_revisions_b.current_phase_id%TYPE;
255 	l_item_lifecycle_id mtl_item_revisions_b.lifecycle_id%TYPE;
256 	--End:3059993:Revision create should honour items phase policy
257 	l_revision_id       mtl_item_revisions_interface.revision_id%TYPE;
258 	l_revid_error       BOOLEAN := FALSE;
259 
260 	l_item_approved    mtl_system_items_b.approval_status%TYPE  := NULL;
261 	l_item_trans_type  mtl_system_items_interface.transaction_type%TYPE := NULL;
262 
263 	l_inv_debug_level	NUMBER := INVPUTLI.get_debug_level;     --Bug: 4667452
264 	l_process_control     VARCHAR2(2000) := NULL; --Used by EGO API only for internal flow control
265    l_is_gdsn_batch   NUMBER;
266 
267    /* Bug 7513461*/
268    currval_not_def exception;
269    pragma exception_init(currval_not_def, -8002);
270 
271 begin
272 
273         l_process_control := INV_EGO_REVISION_VALIDATE.Get_Process_Control;
274 
275 	for cr in cc loop
276 		update mtl_item_revisions_interface
277 		set process_flag = l_process_flag_3
278                 where      rowid = cr.rowid ;
279 
280                 status := INVPUOPI.mtl_log_interface_err(
281                                 cr.organization_id,
282                                 user_id,
283                                 login_id,
284                                 prog_appid,
285                                 prog_id,
286                                 request_id,
287                                 cr.TRANSACTION_ID,
288                                 error_msg,
289 				'ITEM_ID',
290                                 'MTL_ITEM_REVISIONS_INTERFACE',
291                                 'INV_IOI_REV_NO_ITEM',
292                                 err_text);
293                  if status < 0 then
294                                  raise LOGGING_ERR;
295                  end if;
296 	end loop;
297 
298         --Start User can now populate revision_id in the interface table
299 	for cr in dd loop
300            l_revid_error := FALSE;
301 	   IF cr.transaction_type ='CREATE' AND cr.revision_id IS NOT NULL THEN
302 				/* Bug 7513461*/
303 	      BEGIN
304 	         SELECT MTL_ITEM_REVISIONS_B_S.CURRVAL
305 		 					INTO l_revision_id FROM DUAL;
306     	  EXCEPTION
307     	 		 WHEN currval_not_def THEN
308     	 		 		SELECT MTL_ITEM_REVISIONS_B_S.NEXTVAL
309 							INTO l_revision_id FROM DUAL;
310 	         WHEN OTHERS THEN
311 		    			l_revision_id := cr.revision_id - 1;
312 	      END;
313 
314 	      IF cr.revision_id > l_revision_id  THEN
315         		l_revid_error := TRUE;
316 		 		END IF;
317 
318 	      IF l_revid_error THEN
319                  update mtl_item_revisions_interface
320                  set process_flag = l_process_flag_3
321 	         where rowid = cr.rowid;
322 
323                  status := INVPUOPI.mtl_log_interface_err(
324                                 cr.organization_id,
325                                 user_id,
326                                 login_id,
327                                 prog_appid,
328                                 prog_id,
329                                 request_id,
330                                 cr.TRANSACTION_ID,
331                                 error_msg,
332 																'REVISION_ID',
333                                 'MTL_ITEM_REVISIONS_INTERFACE',
334                                 'INV_IOI_INVALID_REVISION_ID',
335                                 err_text);
336                  if status < 0 then
337                     raise LOGGING_ERR;
338                  end if;
339 	      END IF;
340 
341 	   END IF;
342 
343 	    --Start :3456560 Revision code validation.
344             IF cr.transaction_type ='CREATE'
345 	       AND cr.revision IS NULL THEN
346                l_revid_error := TRUE;
347             ELSIF cr.transaction_type ='UPDATE'
348 	       AND cr.revision IS NULL
349 	       AND cr.revision_id IS NULL THEN
350                l_revid_error := TRUE;
351             END IF;
352 	    IF l_revid_error THEN
353                update mtl_item_revisions_interface
354                set process_flag = l_process_flag_3
355 	       where rowid = cr.rowid;
356                status := INVPUOPI.mtl_log_interface_err(
357                                 cr.organization_id,
358                                 user_id,
359                                 login_id,
360                                 prog_appid,
361                                 prog_id,
362                                 request_id,
363                                 cr.TRANSACTION_ID,
364                                 error_msg,
365 				'REVISION',
366                                 'MTL_ITEM_REVISIONS_INTERFACE',
367                                 'INV_IOI_INVALID_REVISION',
368                                 err_text);
369                if status < 0 then
370                   raise LOGGING_ERR;
371                end if;
372 	    END IF;
373 	    --End :3456560 Revision code validation.
374 
375            SELECT count(1) INTO l_row_count
376 	   FROM   mtl_item_revisions_b
377 	   WHERE  organization_id   = cr.organization_id
378 	   AND    inventory_item_id = cr.inventory_item_id
379 	   AND    (revision = cr.revision  OR revision_id = cr.revision_id);
380 
381            IF cr.transaction_type ='CREATE' AND l_row_count > 0 THEN
382 
383               update mtl_item_revisions_interface
384               set process_flag = l_process_flag_3
385 	      where rowid = cr.rowid;
386 
387               status := INVPUOPI.mtl_log_interface_err(
388                                 cr.organization_id,
389                                 user_id,
390                                 login_id,
391                                 prog_appid,
392                                 prog_id,
393                                 request_id,
394                                 cr.TRANSACTION_ID,
395                                 error_msg,
396 				'REVISION',
397                                 'MTL_ITEM_REVISIONS_INTERFACE',
398                                 'INV_IOI_REV_DUP_2',
399                                 err_text);
400               if status < 0 then
401                  raise LOGGING_ERR;
402               end if;
403            ELSIF cr.transaction_type ='UPDATE' AND l_row_count = 0 THEN
404               update mtl_item_revisions_interface
405               set process_flag = l_process_flag_3
406 	      where rowid = cr.rowid;
407               status := INVPUOPI.mtl_log_interface_err(
408                                 cr.organization_id,
409                                 user_id,
410                                 login_id,
411                                 prog_appid,
412                                 prog_id,
413                                 request_id,
414                                 cr.TRANSACTION_ID,
415                                 error_msg,
416 				'REVISION',
417                                 'MTL_ITEM_REVISIONS_INTERFACE',
418                                 'INV_IOI_REV_NO_ITEM',
419                                 err_text);
420               if status < 0 then
421                  raise LOGGING_ERR;
422               end if;
423            END IF;
424 
425         end loop;
426         --End User can now populate revision_id in the interface table
427 
428         --Start : Check for data security and user privileges
429 	-- Bug 4538382 - NOT chk when control is from PLM:UI for perf
430     -- Bug 5218491 - Modified the IF clause : Changed <> to = in the below check
431 	IF (INSTR(NVL(l_process_control,'PLM_UI:N'),'PLM_UI:Y') = 0 )
432 	THEN
433           for cr in c_get_rev_item loop
434              --Fix for bug# 3032994. Changed the privilege to check from
435 	     --EGO_EDIT_ITEM to EGO_ADD_ITEM_REVISION
436 	     IF ( cr.created_by <> -99 ) THEN
437                 l_has_privilege := INV_EGO_REVISION_VALIDATE.check_data_security(
438 	       			     p_function           => 'EGO_ADD_ITEM_REVISION'
439 				    ,p_object_name        => 'EGO_ITEM'
440 				    ,p_instance_pk1_value => cr.inventory_item_id
441 				    ,p_instance_pk2_value => cr.organization_id
442 				    ,P_User_Id            => user_id);
443 
444                 IF l_has_privilege <> 'T' THEN
445                     update mtl_item_revisions_interface
446                     set process_flag = l_process_flag_3
447    	            where rowid = cr.rowid;
448 
449                     status := INVPUOPI.mtl_log_interface_err(
450                                 cr.organization_id,
451                                 user_id,
452                                 login_id,
453                                 prog_appid,
454                                 prog_id,
455                                 request_id,
456                                 cr.TRANSACTION_ID,
457                                 error_msg,
458 				'INVENTORY_ITEM_ID',
459                                 'MTL_ITEM_REVISIONS_INTERFACE',
460                                 'INV_IOI_ITEMREV_UPDATE_PRIV',
461                                 err_text);
462                    if status < 0 then
463                       raise LOGGING_ERR;
464                    end if;
465 	         END IF; --has privilege
466 	     ELSE
467                 IF l_inv_debug_level IN(101, 102) THEN
468                    INVPUTLI.info('INVPVALI.Security skipped for Item Org:' || cr.inventory_item_id || '-' || cr.organization_id  );
469                 END IF;
470 	     END IF; --created_by
471 
472 	    end loop;
473          END IF;
474         --End : Check for data security and user privileges
475 
476         for cr in ee loop
477 
478                 select count(*)
479                 into temp_count
480                 from mtl_item_revisions_interface i
481                 where i.organization_id    = cr.organization_id
482                 and   i.inventory_item_id  = cr.inventory_item_id
483                 and   i.set_process_id + 0 = xset_id
484                 and   i.revision = cr.revision
485 		--and   i.transaction_id     = cr.transaction_id --2808277 Removed for bug 5458317
486                 and   i.process_flag       = 2;
487 
488               if temp_count > 1 then
489 
490                  --Bypassing validation for GDSN batches
491                  l_is_gdsn_batch := 0;
492                  Open  is_gdsn_batch(xset_id);
493                  Fetch is_gdsn_batch INTO l_is_gdsn_batch;
494                  Close is_gdsn_batch;
495 
496                  if l_is_gdsn_batch <> 1 then
497 
498                    update mtl_item_revisions_interface
499                    set process_flag     = l_process_flag_3
500                    where transaction_id = cr.transaction_id
501                      and   set_process_id = xset_id
502                      and   revision       = cr.revision;
503 
504    -- R12C The duplicate Item-Org combination is already reported in INVPVHDR
505    /* 2885843: Start default revision error propagated to imported item
506 
507 		OPEN  c_get_default_rev(cp_org_id => cr.organization_id);
508 		FETCH c_get_default_rev INTO l_default_rev;
509 		CLOSE c_get_default_rev;
510 
511 		IF  cr.transaction_type ='CREATE'
512 		AND l_default_rev = cr.revision THEN
513 
514 		   UPDATE mtl_system_items_interface
515 		   SET    process_flag = l_process_flag_3
516 		   WHERE  inventory_item_id = cr.inventory_item_id
517    		   AND    organization_id   = cr.organization_id
518 		   AND    set_process_id = xset_id;
519 
520 		END IF;
521 		2885843: End default revision error propagated to imported item */
522 
523                 status := INVPUOPI.mtl_log_interface_err(
524                                 cr.organization_id,
525                                 user_id,
526                                 login_id,
527                                 prog_appid,
528                                 prog_id,
529                                 request_id,
530                                 cr.TRANSACTION_ID,
531                                 error_msg,
532                                 'DUP2',
533                                 'MTL_ITEM_REVISIONS_INTERFACE',
534                                 'INV_IOI_REV_DUP_1',
535                                 err_text);
536                   if status < 0 then
537                      raise LOGGING_ERR;
538                   end if;
539                 end if; --Is not GDSN Batch
540               end if;
541               -- Bug 4538382 - NOT chk when control is from PLM:UI for perf
542               -- Bug 5218491 - Modified the IF clause : Changed <> to = in the below check
543 	      IF (INSTR(NVL(l_process_control,'PLM_UI:N'),'PLM_UI:Y') = 0 )
544 	      THEN
545 	      --Start: 3059993:Revision create should honour items phase policy
546 	       IF  cr.transaction_type ='CREATE'  THEN
547 
548         	 OPEN  c_get_default_rev(cp_org_id => cr.organization_id);
549 		 FETCH c_get_default_rev INTO l_default_rev;
550 		 CLOSE c_get_default_rev;
551 
552 		 IF l_default_rev <> cr.revision THEN
553 
554                    OPEN  c_get_item_ids(cp_org_id  => cr.organization_id,
555 	                                cp_item_id => cr.inventory_item_id);
556 	           FETCH c_get_item_ids
557 		   INTO l_item_catalog
558 		       ,l_item_lifecycle_id
559 		       ,l_item_phase_id
560 	               ,l_item_approved
561 		       ,l_item_trans_type;
562 
563                    CLOSE c_get_item_ids;
564 
565 		   IF l_item_lifecycle_id IS NOT NULL AND l_item_phase_id IS NOT NULL THEN
566 		         INV_EGO_REVISION_VALIDATE.phase_change_policy
567 	                     (P_ORGANIZATION_ID   => cr.organization_id
568 		             ,P_INVENTORY_ITEM_ID => cr.inventory_item_id
569 		             ,P_CURR_PHASE_ID     => l_item_phase_id
570 		             ,P_FUTURE_PHASE_ID   => NULL
571 		             ,P_PHASE_CHANGE_CODE => 'REVISE'
572 		             ,P_LIFECYCLE_ID      => l_item_lifecycle_id
573 		             ,X_POLICY_CODE       => l_Policy_Code
574 		             ,X_RETURN_STATUS     => l_Return_Status
575 		             ,X_ERRORCODE         => l_Error_Code
576 		             ,X_MSG_COUNT         => l_Msg_Count
577 		             ,X_MSG_DATA          => l_Msg_Data);
578 
579 	                 IF l_Policy_Code <> 'ALLOWED' THEN
580 
581 		             UPDATE mtl_item_revisions_interface
582                              SET process_flag     = l_process_flag_3
583 		             WHERE rowid          = cr.rowid;
584                              status := INVPUOPI.mtl_log_interface_err(
585                                         cr.organization_id,
586                                         user_id,
587                                         login_id,
588                                         prog_appid,
589                                         prog_id,
590                                         request_id,
591                                         cr.TRANSACTION_ID,
592                                         error_msg,
593 				       'TRANSACTION_TYPE',
594                                        'MTL_ITEM_REVISIONS_INTERFACE',
595                                        'INV_IOI_REV_PHASE_CONFLICT',
596                                        err_text);
597                              if status < 0 then
598                                  raise LOGGING_ERR;
599                              end if;
600 
601 		          END IF; -- l_Policy_Code <> 'ALLOWED'
602 		    END IF;
603 
604 		   --Revisions cannot be created for unapproved items.
605 		   --We allow only default revision
606 		   IF (l_item_trans_type = 'EXISTS' AND l_item_approved <> 'A')
607 		   OR (l_item_trans_type = 'CREATE' AND INVIDIT3.CHECK_NPR_CATALOG(l_item_catalog))
608 		   THEN
609 		      UPDATE mtl_item_revisions_interface
610                       SET process_flag     = l_process_flag_3
611 		      WHERE rowid          = cr.rowid;
612                       status := INVPUOPI.mtl_log_interface_err(
613                                         cr.organization_id,
614                                         user_id,
615                                         login_id,
616                                         prog_appid,
617                                         prog_id,
618                                         request_id,
619                                         cr.TRANSACTION_ID,
620                                         error_msg,
621 				       'TRANSACTION_TYPE',
622                                        'MTL_ITEM_REVISIONS_INTERFACE',
623                                        'INV_IOI_UNAPPROVED_ITEM_REV',
624                                        err_text);
625                       if status < 0 then
626                          raise LOGGING_ERR;
627                       end if;
628 		   END IF;
629 
630 		 END IF; --l_default_rev <> cr.revision
631                END IF;
632 	     END IF;
633 	      --End:3059993:Revision create should honour items phase policy
634 
635         end loop;
636 
637         for cr in ff loop
638 
639            --2808277: Included trans id , create/update will run under different trans id.
640 	   -- Cannot update past/current effective dates.
641 	   IF (cr.transaction_type='UPDATE') THEN
642 
643 	       l_row_count:= 0;
644 
645 	       SELECT count(1) INTO l_row_count
646 	       FROM   mtl_item_revisions_b
647 	       WHERE  revision_id = cr.revision_id
648 	       AND  TRUNC(effectivity_date)<= TRUNC(sysdate)
649 	       AND  TRUNC(effectivity_date) <> TRUNC(cr.effectivity_date);
650 
651 	       IF (l_row_count > 0) THEN
652 	          update mtl_item_revisions_interface
653                   set process_flag = l_process_flag_3
654 	          where transaction_id = cr.transaction_id
655                   and   set_process_id = xset_id
656 	          and   revision = cr.revision;--Bug: 2593490
657 
658                   status := INVPUOPI.mtl_log_interface_err(
659                                 cr.organization_id,
660                                 user_id,
661                                 login_id,
662                                 prog_appid,
663                                 prog_id,
664                                 request_id,
665                                 cr.TRANSACTION_ID,
666                                 error_msg,
667 				'REVISION',
668                                 'MTL_ITEM_REVISIONS_INTERFACE',
669                                 'INV_REV_DATE_CHANGE_NOTALLOWED',
670                                 err_text);
671                   if status < 0 then
672                      raise LOGGING_ERR;
673                    end if;
674 	       END IF;
675 
676                --3070781:ECO Rev's update allow on description and rev label.
677 	       SELECT COUNT(1) INTO l_row_count
678 	       FROM   mtl_item_revisions_b
679 	       where  revision_id = cr.revision_id
680 	       AND    change_notice IS NOT NULL
681 	       AND    ((cr.ecn_initiation_date is NULL OR ecn_initiation_date <> cr.ecn_initiation_date)
682 	               OR (effectivity_date <> cr.effectivity_date)
683 		       OR ((implementation_date IS NULL AND cr.implementation_date IS NOT NULL)
684 		           OR(implementation_date <> cr.implementation_date)));
685 
686 	       IF (l_row_count > 0) THEN
687 
688 	          update mtl_item_revisions_interface
689                   set process_flag     = l_process_flag_3
690 	          where transaction_id = cr.transaction_id
691                   and   set_process_id = xset_id
692 	          and   revision       = cr.revision;--Bug: 2593490
693 
694                   status := INVPUOPI.mtl_log_interface_err(
695                                 cr.organization_id,
696                                 user_id,
697                                 login_id,
698                                 prog_appid,
699                                 prog_id,
700                                 request_id,
701                                 cr.TRANSACTION_ID,
702                                 error_msg,
703 				'REVISION',
704                                 'MTL_ITEM_REVISIONS_INTERFACE',
705                                 'INV_REV_ECO_CHANGE_NOTALLOWED',
706                                 err_text);
707                   if status < 0 then
708                      raise LOGGING_ERR;
709                    end if;
710 	       END IF;
711 
712 
713 	   END IF;
714 
715            select count(*)
716            into    temp_count
717            from mtl_item_revisions_interface i
718            where  i.organization_id = cr.organization_id
719            and   i.inventory_item_id = cr.inventory_item_id
720            and   i.set_process_id + 0 = xset_id
721 	   --and    i.transaction_id     = cr.transaction_id  Commented for bug 5458317
722            and  ((i.revision < cr.revision)
723 	          AND ((TRUNC(i.effectivity_date) = TRUNC(SYSDATE)
724 		        AND TRUNC(cr.effectivity_date) = TRUNC(SYSDATE)
725 			AND i.effectivity_date = cr.effectivity_date)
726                        OR(i.effectivity_date   >= cr.effectivity_date)))
727 	    --2861248 : Effective date validation changed
728 	    --3569925 : Added = condition for > on effectivity dates.
729 	   /**Bug: 2593490 No need to check with  greater revisions
730            or
731            ( cr.revision < i.revision and   cr.effectivity_date > i.effectivity_date)
732            ***/
733             and   i.process_flag = 2 ;
734 
735             IF temp_count >= 1 THEN
736 
737                update mtl_item_revisions_interface
738                set process_flag = l_process_flag_3
739 	       where transaction_id = cr.transaction_id
740                and   set_process_id = xset_id
741 	       and   revision = cr.revision;--Bug: 2593490
742 
743                IF l_inv_debug_level IN(101, 102) THEN
744                   INVPUTLI.info('INVPVALI.validate_item_revs: validation error: conflict with MIRI');
745                END IF;
746                status := INVPUOPI.mtl_log_interface_err(
747                                 cr.organization_id,
748                                 user_id,
749                                 login_id,
750                                 prog_appid,
751                                 prog_id,
752                                 request_id,
753                                 cr.TRANSACTION_ID,
754                                 error_msg,
755 				'EFF1',
756                                 'MTL_ITEM_REVISIONS_INTERFACE',
757                                 'INV_IOI_REV_BAD_ORDER',
758                                 err_text);
759                if status < 0 then
760                   raise LOGGING_ERR;
761                end if;
762             end if;  -- If temp_count >=1
763 
764 	    --Start 2806275 : Revision Reason validation
765             IF cr.revision_reason IS NOT NULL THEN
766 
767 	       l_lookup_exist := 'N';
768 
769 	       OPEN  c_check_lookup(cp_type => 'EGO_ITEM_REVISION_REASON',
770 	                            cp_code => cr.revision_reason);
771 	       FETCH c_check_lookup INTO l_lookup_exist;
772 	       CLOSE c_check_lookup;
773 
774 	       IF l_lookup_exist <> 'Y' THEN
775 
776 	          update mtl_item_revisions_interface
777                   set process_flag      = l_process_flag_3
778 	          where transaction_id  = cr.transaction_id
779                   and   set_process_id  = xset_id
780 		  and   revision        = cr.revision;
781 
782 		  --2885843: Start default revision error propagated to imported item
783   		  OPEN  c_get_default_rev(cp_org_id => cr.organization_id);
784 		  FETCH c_get_default_rev INTO l_default_rev;
785 		  CLOSE c_get_default_rev;
786 
787 		  IF  cr.transaction_type ='CREATE'
788 		  AND l_default_rev = cr.revision THEN
789 
790 		     UPDATE mtl_system_items_interface
791 		     SET    process_flag = l_process_flag_3
792 		     WHERE  inventory_item_id = cr.inventory_item_id
793      		     AND    organization_id   = cr.organization_id
794 		     AND    set_process_id = xset_id;
795 
796   		  END IF;
797 		  --2885843: End default revision error propagated to imported item
798 
799                   status := INVPUOPI.mtl_log_interface_err(
800                                 cr.organization_id,
801                                 user_id,
802                                 login_id,
803                                 prog_appid,
804                                 prog_id,
805                                 request_id,
806                                 cr.TRANSACTION_ID,
807                                 error_msg,
808 				'REVISION_REASON',
809                                 'MTL_ITEM_REVISIONS_INTERFACE',
810                                 'INV_IOI_INVALID_REV_REASON',
811                                 err_text);
812 
813                   IF status < 0 THEN
814                      raise LOGGING_ERR;
815                   END IF;
816 
817 	       END IF; -- l_lookup_exist != 'Y'
818             END IF;
819 	    -- End 2806275 : Revision Reason validation
820 
821         end loop;
822 
823         for cr in gg loop
824 
825                 update mtl_item_revisions_interface
826                 set process_flag = l_process_flag_3
827 		where rowid = cr.rowid;
828 
829                 IF l_inv_debug_level IN(101, 102) THEN
830                    INVPUTLI.info('INVPVALI.validate_item_revs: validation error: conflict with MIR');
831                 END IF;
832 
833                 status := INVPUOPI.mtl_log_interface_err(
834                                 cr.organization_id,
835                                 user_id,
836                                 login_id,
837                                 prog_appid,
838                                 prog_id,
839                                 request_id,
840                                 cr.TRANSACTION_ID,
841                                 error_msg,
842 				'EFF2',
843                                 'MTL_ITEM_REVISIONS_INTERFACE',
844                                 'INV_IOI_REV_BAD_ORDER',
845                                 err_text);
846 
847            if status < 0 then
848               raise LOGGING_ERR;
849            end if;
850 
851         end loop;
852 
853       FOR cr in c_get_revision_lifecycle LOOP
854          l_lifecycle_error := FALSE;
855 
856 	 --2808277: Start Revision update changes
857 	 IF cr.transaction_type = 'UPDATE' THEN
858 	    SELECT current_phase_id
859 	    INTO   l_Old_Phase_Id
860 	    FROM   mtl_item_revisions_b
861 	    WHERE  revision_id = cr.revision_id;
862 	 END IF;
863 	 --2808277: End Revision update changes
864 
865          -- Bug: 3769153 -- added OR part
866          IF cr.lifecycle_id IS NOT NULL OR cr.current_phase_id IS NOT NULL THEN
867 
868             OPEN  c_get_item_ids(cp_org_id  => cr.organization_id,
869 	                         cp_item_id => cr.inventory_item_id);
870 	    FETCH c_get_item_ids
871  	    INTO l_item_catalog
872 	        ,l_item_lifecycle_id
873 	        ,l_item_phase_id
874 	        ,l_item_approved
875 	        ,l_item_trans_type;
876             CLOSE c_get_item_ids;
877 
878             -- Bug: 3769153 - if lifecycle is not specified and phase is specified,
879             --   then update the lifecycle of item to the revision
880             IF cr.lifecycle_id IS NULL AND l_item_lifecycle_id IS NOT NULL THEN
881                update mtl_item_revisions_interface
882                set lifecycle_id = l_item_lifecycle_id
883                where rowid = cr.rowid;
884             END IF;
885 
886             -- 3624686 null check incorporated
887             IF cr.lifecycle_id <> NVL(l_item_lifecycle_id,-1) THEN
888                update mtl_item_revisions_interface
889                set process_flag = l_process_flag_3
890 	       where rowid = cr.rowid;
891 
892                l_lifecycle_error := TRUE;
893 
894                status := INVPUOPI.mtl_log_interface_err(
895                                 cr.organization_id,
896                                 user_id,
897                                 login_id,
898                                 prog_appid,
899                                 prog_id,
900                                 request_id,
901                                 cr.TRANSACTION_ID,
902                                 error_msg,
903 				'LIFECYCLE_ID',
904                                 'MTL_ITEM_REVISIONS_INTERFACE',
905                                 'INV_IOI_REV_INVALID_LIFECYCLE',
906                                 err_text);
907                IF status < 0 THEN
908                     raise LOGGING_ERR;
909                END IF;
910 	    END IF;
911 
912 	    IF cr.current_phase_id IS NOT NULL THEN
913                -- Bug: 3769153 - added NVL in nvl(cr.lifecycle_id, l_item_lifecycle_id)
914 	       -- Bug 4538382 - NOT chk when control is from PLM:UI for perf
915            -- Bug 5218491 - Modified the IF clause : Changed <> to = in the below check
916              IF (INSTR(NVL(l_process_control,'PLM_UI:N'),'PLM_UI:Y') = 0 )
917 	     THEN
918                IF NOT INV_EGO_REVISION_VALIDATE.Check_LifeCycle_Phase
919                                     ( p_lifecycle_id       => nvl(cr.lifecycle_id, l_item_lifecycle_id),
920                                       p_lifecycle_phase_id => cr.current_phase_id)
921                THEN
922                   update mtl_item_revisions_interface
923                   set process_flag = l_process_flag_3
924    		  where rowid = cr.rowid;
925 
926                   l_lifecycle_error := TRUE;
927 
928                   status := INVPUOPI.mtl_log_interface_err(
929                                 cr.organization_id,
930                                 user_id,
931                                 login_id,
932                                 prog_appid,
933                                 prog_id,
934                                 request_id,
935                                 cr.TRANSACTION_ID,
936                                 error_msg,
937 				'CURRENT_PHASSE_ID',
938                                 'MTL_ITEM_REVISIONS_INTERFACE',
939                                 'INV_IOI_REV_INVALID_PHASE',
940                                 err_text);
941                   IF  status < 0 THEN
942                      raise LOGGING_ERR;
943                   END IF;
944 	        ELSE
945   	          --Start: 3809876 :Unapproved item rev can have first phase ONLY.
946 		  IF  (l_item_trans_type = 'EXISTS' AND l_item_approved <> 'A')
947 		   OR (l_item_trans_type = 'CREATE' AND INVIDIT3.CHECK_NPR_CATALOG(l_item_catalog))
948 		  THEN
949                      IF  cr.current_phase_id <> INV_EGO_REVISION_VALIDATE.Get_Initial_Lifecycle_Phase(nvl(cr.lifecycle_id, l_item_lifecycle_id))
950 		     THEN
951                         update mtl_item_revisions_interface
952                         set process_flag = l_process_flag_3
953    		        where rowid = cr.rowid;
954 
955                         l_lifecycle_error := TRUE;
956 
957                         status := INVPUOPI.mtl_log_interface_err(
958                                 cr.organization_id,
959                                 user_id,
960                                 login_id,
961                                 prog_appid,
962                                 prog_id,
963                                 request_id,
964                                 cr.TRANSACTION_ID,
965                                 error_msg,
966 				'CURRENT_PHASSE_ID',
967                                 'MTL_ITEM_REVISIONS_INTERFACE',
968                                 'INV_IOI_REV_UNAPPROVED_PHASE',
969                                 err_text);
970                         IF  status < 0 THEN
971                            raise LOGGING_ERR;
972                         END IF;
973 		     END IF;
974 		  END IF;
975 	          -- End: 3809876 :Unapproved item rev can have first phase ONLY.
976                 END IF;
977              END IF;
978 	    ELSE --cr.current_phase_id IS NOT NULL THEN
979 	       --2891650 : Start IOI should not default LC phase.
980                update mtl_item_revisions_interface
981                set process_flag = l_process_flag_3
982 	       where rowid = cr.rowid;
983 
984 	       l_lifecycle_error := TRUE;
985 
986                status := INVPUOPI.mtl_log_interface_err(
987                                 cr.organization_id,
988                                 user_id,
989                                 login_id,
990                                 prog_appid,
991                                 prog_id,
992                                 request_id,
993                                 cr.TRANSACTION_ID,
994                                 error_msg,
995 				'CURRENT_PHASSE_ID',
996                                 'MTL_ITEM_REVISIONS_INTERFACE',
997                                 'INV_IOI_PHASE_MANDATORY',
998                                 err_text);
999                IF  status < 0 THEN
1000                      raise LOGGING_ERR;
1001                END IF;
1002 	       --2891650 : End IOI should not default LC phase.
1003 
1004 	    END IF; --Phase id if
1005           -- Bug 4538382 - NOT chk when control is from PLM:UI for perf
1006           -- Bug 5218491 - Modified the IF clause : Changed <> to = in the below check
1007 	    IF (INSTR(NVL(l_process_control,'PLM_UI:N'),'PLM_UI:Y') = 0 )
1008 	    THEN
1009 	     -- 2808277 : Start Check phase change is allowed or not
1010 	      IF (cr.transaction_type = 'UPDATE')
1011 	         AND (cr.current_phase_id <> l_Old_Phase_Id) THEN
1012 
1013                 --EGO Phase change policy called through INV wrapper.
1014  	        INV_EGO_REVISION_VALIDATE.phase_change_policy
1015 	         (P_ORGANIZATION_ID   => cr.organization_id
1016 		 ,P_INVENTORY_ITEM_ID => cr.inventory_item_id
1017 		 ,P_CURR_PHASE_ID     => l_item_phase_id
1018 		 ,P_FUTURE_PHASE_ID   => cr.current_phase_id
1019 		 ,P_PHASE_CHANGE_CODE => NULL
1020 		 ,P_LIFECYCLE_ID      => cr.lifecycle_id
1021 	 	 ,X_POLICY_CODE       => l_Policy_Code
1022 		 ,X_RETURN_STATUS     => l_Return_Status
1023 		 ,X_ERRORCODE         => l_Error_Code
1024 		 ,X_MSG_COUNT         => l_Msg_Count
1025 		 ,X_MSG_DATA          => l_Msg_Data);
1026 
1027 	        IF l_Policy_Code <> 'ALLOWED' THEN
1028 
1029 	          update mtl_item_revisions_interface
1030                   set process_flag = l_process_flag_3
1031 	          where rowid      = cr.rowid;
1032 
1033                   status := INVPUOPI.mtl_log_interface_err(
1034                                  cr.organization_id,
1035                                  user_id,
1036                                  login_id,
1037                                  prog_appid,
1038                                  prog_id,
1039                                  request_id,
1040                                  cr.TRANSACTION_ID,
1041                                  error_msg,
1042 	 			'CURRENT_PHASE_ID',
1043                                 'MTL_ITEM_REVISIONS_INTERFACE',
1044                                 'INV_IOI_PHASE_CHANGE_NOT_VALID',
1045                                  err_text);
1046                   IF status < 0 THEN
1047                      raise LOGGING_ERR;
1048                   END IF;
1049 
1050 	        END IF; --Policy code
1051 
1052               END IF;
1053 
1054 	    END IF;
1055  	    -- 2808277 : End Check phase change is allowed or not
1056          END IF;    -- cr.lifecycle_id IS NOT NULL OR cr.current_phase_id IS NOT NULL
1057 
1058          --2885843: Start default revision error propagated to imported item
1059          IF l_lifecycle_error AND cr.transaction_type ='CREATE' THEN
1060 
1061 	    OPEN  c_get_default_rev(cp_org_id => cr.organization_id);
1062 	    FETCH c_get_default_rev INTO l_default_rev;
1063 	    CLOSE c_get_default_rev;
1064 
1065 	    IF l_default_rev = cr.revision THEN
1066 	       UPDATE mtl_system_items_interface
1067 	       SET    process_flag      = l_process_flag_3
1068 	       WHERE  inventory_item_id = cr.inventory_item_id
1069      	       AND    organization_id   = cr.organization_id
1070 	       AND    set_process_id    = xset_id;
1071 
1072   	    END IF;
1073 	 END IF;
1074 	 --2885843: End default revision error propagated to imported item
1075 
1076       END LOOP;
1077 
1078       update mtl_item_revisions_interface
1079       set   process_flag     = l_process_flag_4,
1080 	    revision_label   = NVL(revision_label,revision),
1081 	    revision_id      = NVL(revision_id,MTL_ITEM_REVISIONS_B_S.NEXTVAL) --2808277
1082       where process_flag     = l_process_flag_2
1083       and   set_process_id   = xset_id
1084       and (organization_id   = org_id or all_org = l_all_org);
1085 
1086       return(0);
1087 
1088 exception
1089 
1090         when LOGGING_ERR then
1091 	   IF c_check_lookup%ISOPEN THEN
1092 	      CLOSE c_check_lookup;
1093 	   END IF;
1094            return(status);
1095         when OTHERS then
1096 	   IF c_check_lookup%ISOPEN THEN
1097 	      CLOSE c_check_lookup;
1098 	   END IF;
1099            err_text := substr('INVPVALI.validate_item_revs ' || SQLERRM, 1,240);
1100           return(SQLCODE);
1101 
1102 end validate_item_revs;
1103 
1104 ----------------------------- mtl_pr_validate_item ----------------------------
1105 
1106 FUNCTION mtl_pr_validate_item
1107 (
1108 org_id          number,
1109 all_org         NUMBER          := 2,
1110 prog_appid      NUMBER          := -1,
1111 prog_id         NUMBER          := -1,
1112 request_id      NUMBER          := -1,
1113 user_id         NUMBER          := -1,
1114 login_id        NUMBER          := -1,
1115 err_text in out NOCOPY varchar2,
1116 xset_id  IN     NUMBER     DEFAULT -999
1117 )
1118 RETURN INTEGER
1119 IS
1120    status    NUMBER := 0;
1121    l_inv_debug_level	NUMBER := INVPUTLI.get_debug_level;     --Bug: 4667452
1122    l_process_control     VARCHAR2(2000) := NULL; --Used by EGO API only for internal flow control
1123 
1124 BEGIN
1125 
1126    l_process_control := INV_EGO_REVISION_VALIDATE.Get_Process_Control;
1127 
1128    IF l_inv_debug_level IN(101, 102) THEN
1129       INVPUTLI.info('INVPVALI: first sta..set_id'||to_char(xset_id)||'org'||to_char(org_id)||'all'||to_char(all_org));
1130    END IF;
1131 
1132    if (xset_id < 900000000000) then
1133 
1134       IF l_inv_debug_level IN(101, 102) THEN
1135          INVPUTLI.info('INVPVALI: before INVPVALM.validate_item_org1');
1136       END IF;
1137       status := INVPVALM.validate_item_org1(
1138 		org_id,
1139 		all_org,
1140 		prog_appid,
1141 		prog_id,
1142 		request_id,
1143 		user_id,
1144 		login_id,
1145 		err_text,
1146                 xset_id);
1147    end if;
1148 
1149    if ( (status = 0) and (xset_id < 900000000000) ) then
1150 
1151       IF l_inv_debug_level IN(101, 102) THEN
1152          INVPUTLI.info('INVPVALI: before INVPALM2.validate_item_org4');
1153       END IF;
1154       status := INVPVLM2.validate_item_org4(
1155 			org_id,
1156 			all_org,
1157 			prog_appid,
1158 			prog_id,
1159 			request_id,
1160 			user_id,
1161 			login_id,
1162 			err_text,
1163                         xset_id);
1164    end if;
1165 
1166    if ( status = 0 and xset_id < 900000000000 ) then
1167 
1168       IF l_inv_debug_level IN(101, 102) THEN
1169          INVPUTLI.info('INVPVALI: before INVPVLM3.validate_item_org7');
1170       END IF;
1171       status := INVPVLM3.validate_item_org7(
1172 			org_id,
1173 			all_org,
1174 			prog_appid,
1175 			prog_id,
1176 			request_id,
1177 			user_id,
1178 			login_id,
1179 			err_text,
1180 			xset_id);
1181    end if;
1182 
1183    --Start : Check for data security and user privileges
1184    if (status = 0) then
1185      -- Bug 4538382 - NOT chk when control is from PLM:UI for perf
1186      -- Bug 5218491 - Modified the IF clause : Changed <> to = in the below check
1187      IF (INSTR(NVL(l_process_control,'PLM_UI:N'),'PLM_UI:Y') = 0 )
1188      THEN
1189        IF l_inv_debug_level IN(101, 102) THEN
1190           INVPUTLI.info('INVPVALI.mtl_pr_validate_item: before INV_EGO_REVISION_VALIDATE.validate_item_user_privileges');
1191        END IF;
1192 
1193        status := INV_EGO_REVISION_VALIDATE.validate_item_user_privileges(
1194 			 P_Org_Id     => org_id
1195 			,P_All_Org    => all_org
1196 			,P_Prog_AppId => prog_appid
1197 			,P_Prog_Id    => prog_id
1198 			,P_Request_Id => request_id
1199 			,P_User_Id    => user_id
1200 			,P_Login_Id   => login_id
1201 			,P_Set_Id     => xset_id
1202 			,X_Err_Text   => err_text);
1203 
1204         IF l_inv_debug_level IN(101, 102) THEN
1205            INVPUTLI.info('INVPVALI.mtl_pr_validate_item: INV_EGO_REVISION_VALIDATE.validate_item_user_privileges');
1206         END IF;
1207       END IF;
1208     end if;
1209    --End : Check for data security and user privileges
1210 
1211    if (status = 0) then
1212 
1213       IF l_inv_debug_level IN(101, 102) THEN
1214          INVPUTLI.info('INVPVALI: before INVPVHDR.validate_item_header'||to_char(xset_id)||'org'||to_char(org_id)||'all'||to_char(all_org));
1215       END IF;
1216       status := INVPVHDR.validate_item_header(
1217 			org_id,
1218 			all_org,
1219 			prog_appid,
1220 			prog_id,
1221 			request_id,
1222 			user_id,
1223 			login_id,
1224 			err_text,
1225                         xset_id);
1226    end if;
1227 
1228    if (status = 0) then
1229 
1230       IF l_inv_debug_level IN(101, 102) THEN
1231          INVPUTLI.info('INVPVALI: before INVPVDR2.validate_item_header2');
1232       END IF;
1233 
1234       status := INVPVDR2.validate_item_header2(
1235 			org_id,
1236 			all_org,
1237 			prog_appid,
1238 			prog_id,
1239 			request_id,
1240 			user_id,
1241 			login_id,
1242 			err_text,
1243                         xset_id);
1244    end if;
1245 
1246    if (status = 0) then
1247 
1248       IF l_inv_debug_level IN(101, 102) THEN
1249          INVPUTLI.info('INVPVALI: before INVPVDR3.validate_item_header3');
1250       END IF;
1251 
1252       status := INVPVDR3.validate_item_header3(
1253 			org_id,
1254 			all_org,
1255 			prog_appid,
1256 			prog_id,
1257 			request_id,
1258 			user_id,
1259 			login_id,
1260 			err_text,
1261                         xset_id);
1262    end if;
1263 
1264    if (status = 0) then
1265 
1266       IF l_inv_debug_level IN(101, 102) THEN
1267          INVPUTLI.info('INVPVALI: before INVPVDR4.validate_item_header4');
1268       END IF;
1269 
1270 
1271       status := INVPVDR4.validate_item_header4(
1272 			org_id,
1273 			all_org,
1274 			prog_appid,
1275 			prog_id,
1276 			request_id,
1277 			user_id,
1278 			login_id,
1279 			err_text,
1280                         xset_id);
1281    end if;
1282 
1283    if (status = 0) then
1284 
1285       IF l_inv_debug_level IN(101, 102) THEN
1286          INVPUTLI.info('INVPVALI: before INVPVDR5.validate_item_header5');
1287       END IF;
1288 
1289       status := INVPVDR5.validate_item_header5(
1290 			org_id,
1291 			all_org,
1292 			prog_appid,
1293 			prog_id,
1294 			request_id,
1295 			user_id,
1296 			login_id,
1297 			err_text,
1298                         xset_id);
1299    end if;
1300 
1301    if (status = 0) then
1302 
1303       IF l_inv_debug_level IN(101, 102) THEN
1304          INVPUTLI.info('INVPVALI.mtl_pr_validate_item: before INVPVDR6.validate_item_header6');
1305       END IF;
1306       status := INVPVDR6.validate_item_header6 (
1307 			org_id,
1308 			all_org,
1309 			prog_appid,
1310 			prog_id,
1311 			request_id,
1312 			user_id,
1313 			login_id,
1314 			err_text,
1315                         xset_id);
1316 
1317       IF l_inv_debug_level IN(101, 102) THEN
1318          INVPUTLI.info('INVPVALI.mtl_pr_validate_item: after INVPVDR6.validate_item_header6');
1319       END IF;
1320    end if;
1321 
1322 
1323    /* Start Bug 3713912 */
1324    if (status = 0) then
1325 
1326       IF l_inv_debug_level IN(101, 102) THEN
1327          INVPUTLI.info('INVPVALI.mtl_pr_validate_item: before INVPVDR7.validate_item_header7');
1328       END IF;
1329 
1330       status := INVPVDR7.validate_item_header7 (
1331 			org_id,
1332 			all_org,
1333 			prog_appid,
1334 			prog_id,
1335 			request_id,
1336 			user_id,
1337 			login_id,
1338 			err_text,
1339                         xset_id);
1340 
1341       IF l_inv_debug_level IN(101, 102) THEN
1342          INVPUTLI.info('INVPVALI.mtl_pr_validate_item: after INVPVDR7.validate_item_header7');
1343       END IF;
1344    end if;
1345    /* End Bug 3713912 */
1346 
1347 
1348    -- Start 2777118 : Lifecycle and Phase validations for IOI
1349    IF (status = 0) THEN
1350       IF l_inv_debug_level IN(101, 102) THEN
1351          INVPUTLI.info('INVPVALI.mtl_pr_validate_item: before INV_EGO_REVISION_VALIDATE.validate_items_lifecycle');
1352       END IF;
1353       status := INV_EGO_REVISION_VALIDATE.validate_items_lifecycle(
1354 			 P_Org_Id     => org_id
1355 			,P_All_Org    => all_org
1356 			,P_Prog_AppId => prog_appid
1357 			,P_Prog_Id    => prog_id
1358 			,P_Request_Id => request_id
1359 			,P_User_Id    => user_id
1360 			,P_Login_Id   => login_id
1361 			,P_Set_Id     => xset_id
1362 			,X_Err_Text   => err_text);
1363 
1364       IF l_inv_debug_level IN(101, 102) THEN
1365          INVPUTLI.info('INVPVALI.mtl_pr_validate_item: INV_EGO_REVISION_VALIDATE.validate_items_lifecycle');
1366       END IF;
1367     END IF;
1368    -- End 2777118 : Lifecycle and Phase validations for IOI
1369 
1370 
1371 
1372    -- validate item revisions
1373 
1374 --Bug:3531430 Validate Item revs irrespective of item is succeeded or not.
1375 -- if (status = 0) then
1376 
1377       IF l_inv_debug_level IN(101, 102) THEN
1378          INVPUTLI.info('INVPVALI.mtl_pr_validate_item: before validate_item_revs');
1379       END IF;
1380 
1381       status := INVPVALI.validate_item_revs (
1382 			org_id,
1383 			all_org,
1384 			prog_appid,
1385 			prog_id,
1386 			request_id,
1387 			user_id,
1388 			login_id,
1389 			err_text,
1390                         xset_id );
1391 
1392       IF l_inv_debug_level IN(101, 102) THEN
1393          INVPUTLI.info('INVPVALI.mtl_pr_validate_item: after validate_item_revs');
1394       END IF;
1395 
1396 --   end if;
1397      IF l_inv_debug_level IN(101, 102) THEN
1398         INVPUTLI.info('INVPVALI.mtl_pr_validate_item: before validate_items_catalog_group');
1399      END IF;
1400 
1401       --5208102
1402      INV_EGO_REVISION_VALIDATE.Insert_Revision_UserAttr(P_Set_id=>xset_id);
1403 
1404    RETURN (status);
1405 
1406 EXCEPTION
1407 
1408    when OTHERS then
1409       err_text := substr('INVPVALI.mtl_pr_validate_item ' || SQLERRM, 1,240);
1410       return(SQLCODE);
1411 
1412 END mtl_pr_validate_item;
1413 
1414 
1415 END INVPVALI;