DBA Data[Home] [Help]

PACKAGE BODY: APPS.WIP_FLOW_DERIVE

Source


1 Package Body Wip_Flow_Derive as
2  /* $Header: wipwodfb.pls 120.1 2006/01/18 12:15:40 ksuleman noship $ */
3 
4 /* *********************************************************************
5 			Public Procedures
6 ***********************************************************************/
7 
8 
9 function class_code( p_class_code in out NOCOPY varchar2,
10 		     p_err_mesg in out NOCOPY varchar2,
11 		     p_org_id in number,
12 		     p_item_id in number,
13 		     p_wip_entity_type in number,
14 		     p_project_id in number) return number is
15 x_success number := 0;
16 x_err_code1 varchar2(30);
17 x_token1 varchar2(10);
18 x_err_code2 varchar2(30);
19 x_token2 varchar2(10);
20 begin
21 
22 	if (p_class_code is null) then
23 		p_class_code := wip_common.default_acc_class(
24          				X_ORG_ID    => p_org_id,
25          				X_ITEM_ID   => p_item_id,
26          				X_ENTITY_TYPE => p_wip_entity_type,
27          				X_PROJECT_ID   => p_project_id,
28          				X_ERR_MESG_1  => x_err_code1,
29          				X_ERR_CLASS_1 => x_token1,
30          				X_ERR_MESG_2  => x_err_code2,
31          				X_ERR_CLASS_2 => x_token2
32          			) ;
33 
34 		if(p_class_code is null) then
35 
36 			fnd_message.set_name('WIP',x_err_code1);
37 			fnd_message.set_token('CLASS_CODE',x_token1);
38 			p_err_mesg := fnd_message.get;
39 			return 0 ;
40 		end if;
41 
42 	end if ;
43 
44 	return 1;
45 
46     exception
47      when others then
48 	return 0;
49 
50 end class_code ;
51 
52 
53 
54 function bom_revision(
55 			   p_bom_rev in out NOCOPY varchar2,
56 		           p_rev in out NOCOPY varchar2,
57 			   p_bom_rev_date in out NOCOPY date,
58 			   p_item_id in number,
59 			   p_start_date in date,
60 			   p_Org_id in number) return number is
61 x_success number := 0;
62 x_rev_exists number ;
63 x_bom_rev_exists number;
64 x_bom_rev varchar2(3);
65 begin
66 
67 	/* Try to handle the corner case when the rev and Bom_rev
68 	   are not in Sync - That is done in the Validation
69 	   Routine */
70 
71 	x_bom_rev := p_bom_rev ;
72 
73 
74 	x_bom_rev_exists := wip_common.bill_exists(
75 				p_item_id => p_item_id,
76 				p_org_id => p_org_id );
77 
78 	if (x_bom_rev_exists = -1) then
79 	  /* SQLERROR occured in bill_exists routine */
80 	  raise PROGRAM_ERROR ;
81 	end if ;
82 
83 	x_rev_exists := wip_common.revision_exists(
84                                 p_item_id => p_item_id,
85                                 p_org_id => p_org_id );
86 
87 	if(x_rev_exists in (-1, -2)) then
88 	  /* SQLERROR or Application Error occured in
89 	     the revision_exists routine */
90 	  raise PROGRAM_ERROR ;
91 	end if ;
92 
93 	/* This basically fetches you the revision for
94 	   the Item - doesnot worry about whether it is
95 	   a Bill or the Item			*/
96 
97 	wip_revisions.bom_revision(
98                   P_Organization_Id => p_org_id,
99                   P_Item_Id => p_item_id,
100                   P_Revision => x_bom_rev,
101                   P_Revision_Date => p_bom_rev_date,
102                   P_Start_Date => p_start_date );
103 
104 	-- If revision exists
105 	if (x_rev_exists = 2) and (p_rev is null) then
106 	    p_rev := x_bom_rev  ;
107 	end if ;
108 
109 	-- If the Bill exists
110 	if (x_bom_rev_exists = 1) and (p_bom_rev is null) then
111 	   p_bom_rev := x_bom_rev ;
112 	end if ;
113 
114 	return 1;
115 
116         exception
117            when others then
118                    return 0;
119 
120 end bom_revision ;
121 
122 
123 
124 function routing_revision(  p_rout_rev in out NOCOPY varchar2,
125 			    p_rout_rev_date in out NOCOPY date,
126 			    p_item_id in number,
127 			    p_start_date in date,
128                             p_Org_id in number) return number is
129 x_success number := 0;
130 x_rtg_exists number := 0;
131 begin
132 
133 	x_rtg_exists := wip_common.routing_exists(
134 			   	p_item_id => p_item_id,
135 				p_org_id => p_org_id );
136 
137 	if (x_rtg_exists >= 1 ) then
138 
139 	        wip_revisions.Routing_Revision(
140                         P_Organization_Id => p_org_id,
141                         P_Item_Id => p_item_id,
142                         P_Revision => p_rout_rev,
143                         P_Revision_Date => p_rout_rev_date,
144                         P_Start_Date => p_start_date );
145 
146 	elsif(x_rtg_exists = -1) then
147 		/* SQLERROR from the routing_exists routine */
148 		raise PROGRAM_ERROR ;
149 	end if ;
150 
151 	return 1;
152 
153      exception
154 	when others then
155 		return 0;
156 
157 end routing_revision ;
158 
159 
160 
161 
162 function completion_sub(p_comp_sub in out NOCOPY varchar2,
163                         p_item_id in number,
164                         p_org_id in number,
165 		        p_alt_rtg_des in varchar2) return number is
166 x_success number := 0;
167 begin
168 
169 	if p_comp_sub is null then
170 
171 	     select BOR.COMPLETION_SUBINVENTORY
172 	     into   p_comp_sub
173              from   BOM_OPERATIONAL_ROUTINGS BOR
174              where  BOR.ORGANIZATION_ID = p_org_id
175              and    BOR.ASSEMBLY_ITEM_ID = p_item_id
176              and    NVL(BOR.ALTERNATE_ROUTING_DESIGNATOR,'@@@') =
177                           NVL(p_alt_rtg_des, '@@@');
178 
179 	end if;
180 
181 	return 1;
182 
183   exception
184        when no_data_found then
185 	return 1;  	-- This was not defined in the routing
186 
187        when others then
188         return 0;
189 
190 end completion_sub ;
191 
192 
193 /* Defaulting Routing Completion Locator Id */
194 function routing_completion_sub_loc(
195                         p_rout_comp_sub in out NOCOPY varchar2,
196                         p_rout_comp_loc in out NOCOPY number,
197                         p_item_id in number,
198                         p_org_id in number,
199                         p_alt_rtg_des in varchar2) return number is
200 x_success number := 0;
201 begin
202 
203 
204 	if p_rout_comp_sub is null and p_rout_comp_loc is null  then
205 
206                select BOR.COMPLETION_SUBINVENTORY,
207                       BOR.COMPLETION_LOCATOR_ID
208                into   p_rout_comp_sub,
209                       p_rout_comp_loc
210                from   BOM_OPERATIONAL_ROUTINGS BOR
211                where  BOR.ORGANIZATION_ID = p_org_id
212                and    BOR.ASSEMBLY_ITEM_ID = p_item_id
213                and    NVL(BOR.ALTERNATE_ROUTING_DESIGNATOR,'@@@') =
214                             NVL(p_alt_rtg_des, '@@@') ;
215 
216 	end if ;
217 
218 
219    return 1 ;
220 
221    exception
222 
223       when no_data_found then
224            return 1 ;
225 
226       when others then
227            return 0 ;
228 
229 end routing_completion_sub_loc ;
230 
231 /* Defaulting completion locator id. In completion_loc, we only default locator id from
232    the routing if p_proj_id is not null. I don't think we need that restriction. Also,
233    p_txn_int_id is unneccessary. INV validation should derive the locator id from the
234    segments provided. We only need to check the existence of locator id */
235 function completion_locator_id(p_comp_loc in out NOCOPY number,
236                                p_item_id in number,
237                                p_org_id in number,
238                                p_alt_rtg_des in varchar2,
239                                p_proj_id in number,
240                                p_task_id in number,
241                                p_comp_sub in varchar2) return number is
242   l_success number := 0;
243   l_comp_sub varchar2(10);
244   general exception;
245 begin
246   l_comp_sub := null;
247 
248   l_success := routing_completion_sub_loc(
249                    p_rout_comp_sub => l_comp_sub,
250                    p_rout_comp_loc => p_comp_loc,
251                    p_item_id => p_item_id,
252                    p_org_id => p_org_id,
253                    p_alt_rtg_des => p_alt_rtg_des) ;
254 
255   if (l_success = 0) then
256     raise general;
257   end if;
258 
259   if (l_comp_sub <> p_comp_sub) then
260     p_comp_loc := null ;
261   end if ;
262 
263   if ((p_proj_id is not null) and
264       (p_comp_sub is not null) and
265       (p_comp_loc is not null)) then
266 
267     --The following piece of code that checks for dynamic
268     --locator creation, will be replaced by call to pacifia's routine.
269 
270     if (pjm_project_locator.check_itemlocatorcontrol(
271                         p_organization_id => p_org_id,
272                         p_sub => p_comp_sub,
273                         p_loc => p_comp_loc,
274                         p_item_id => p_item_id,
275                         p_hardpeg_only => 2 ) = TRUE ) then
276 
277       select count(*) into l_success
278       from mtl_item_locations
279       where inventory_location_id = p_comp_loc
280       and organization_id = p_org_id
281       and subinventory_code = p_comp_sub ;
282 
283       if (l_success = 1 ) then
284         pjm_project_locator.Get_DefaultProjectLocator(
285                         p_organization_id => p_org_id,
286                         p_locator_id => p_comp_loc,
287                         p_project_id => p_proj_id,
288                         p_task_id => p_task_id,
289                         p_project_locator_id => p_comp_loc ) ;
290       end if ;
291     end if ;
292   end if ;
293 
294   return 1;
295 
296   exception
297   when others then
298     return 0;
299 end completion_locator_id;
300 
301 
302 function completion_loc(p_comp_loc in out NOCOPY number,
303                         p_item_id in number,
304                         p_org_id in number,
305                         p_alt_rtg_des in varchar2,
306 			p_proj_id in number,
307                         p_task_id in number,
308 			p_comp_sub in varchar2,
309                         p_txn_int_id in number default null ) return number is
310 x_success number := 0;
311 x_comp_sub varchar2(10);
312 x_loc_seg_exists number := 0 ;
313 x_item_loc_control number := null ;
314 x_item_loc_restrict number := null ;
315 x_item_sub_restrict number := null ;
316 x_sub_loc_control number := null ;
317 x_org_loc_control number := null ;
318 general exception;
319 begin
320 
321 
322 
323         if (p_comp_loc is null) and (p_comp_sub is not null) and (p_proj_id is not null)  then
324 
325            if p_txn_int_id is not null then
326 
327                 select count(*) into x_loc_seg_exists
328                 from mtl_transactions_interface
329                 where transaction_interface_id = p_txn_int_id
330                 and (  LOC_SEGMENT1 is not null
331                        or LOC_SEGMENT2 is not null
332                        or LOC_SEGMENT3 is not null
333                        or LOC_SEGMENT4 is not null
334                        or LOC_SEGMENT5 is not null
335                        or LOC_SEGMENT6 is not null
336                        or LOC_SEGMENT7 is not null
337                        or LOC_SEGMENT8 is not null
338                        or LOC_SEGMENT9 is not null
339                        or LOC_SEGMENT10 is not null
340                        or LOC_SEGMENT11 is not null
341                        or LOC_SEGMENT12 is not null
342                        or LOC_SEGMENT13 is not null
343                        or LOC_SEGMENT14 is not null
344                        or LOC_SEGMENT15 is not null
345                        or LOC_SEGMENT16 is not null
346                        or LOC_SEGMENT17 is not null
347                        or LOC_SEGMENT18 is not null
348                        or LOC_SEGMENT19 is not null
349                        or LOC_SEGMENT20 is not null
350                    ) ;
351 
352            end if;
353 
354 
355            if (p_txn_int_id is null) or (x_loc_seg_exists = 0) then
356 
357 	       x_success := routing_completion_sub_loc(
358 				p_rout_comp_sub => x_comp_sub,
359                         	p_rout_comp_loc => p_comp_loc,
360                         	p_item_id => p_item_id,
361                         	p_org_id => p_org_id,
362                         	p_alt_rtg_des => p_alt_rtg_des) ;
363 
364 		if (x_success = 0) then
365 		 	raise general;
366 		end if;
367 
368 	     	if x_comp_sub <> p_comp_sub then
369 		      p_comp_loc := null ;
370 	     	end if ;
371 
372 	  end if ;
373 
374         end if;
375 
376 
377         if (p_proj_id is not null) and (p_comp_sub is not null) and (p_comp_loc is not null) then
378 
379 	/*****************************************************
380 	   The following piece of code that checks for dynamic
381 	   locator creation, will be replaced by call to
382 	   pacifia's routine.
383 	*****************************************************/
384 
385 		if (pjm_project_locator.check_itemlocatorcontrol(
386 			p_organization_id => p_org_id,
387 			p_sub => p_comp_sub,
388 			p_loc => p_comp_loc,
389 			p_item_id => p_item_id,
390 			p_hardpeg_only => 2 ) = TRUE ) then
391 
392 		     select count(*) into x_success
393 		     from mtl_item_locations
394 		     where inventory_location_id = p_comp_loc
395 		     and organization_id = p_org_id
396 		     and subinventory_code = p_comp_sub ;
397 
398 		     if (x_success = 1 ) then
399 
400             		pjm_project_locator.Get_DefaultProjectLocator(
401                   	p_organization_id => p_org_id,
402                   	p_locator_id => p_comp_loc,
403                   	p_project_id => p_proj_id,
404                   	p_task_id => p_task_id,
405                   	p_project_locator_id => p_comp_loc ) ;
406 
407 		    end if ;
408 
409 		end if ;
410 
411 
412         end if ;
413 
414         return 1;
415 
416   exception
417 
418        when others then
419         return 0;
420 
421 end completion_loc ;
422 
423 
424 
425 function schedule_group_id(p_sched_grp_id in out NOCOPY number) return number is
426 x_success number := 0;
427 begin
428 
429         return 1;
430 
431   exception
432        when others then
433         return 0;
434 
435 
436 end schedule_group_id ;
437 
438 
439 
440 function build_sequence(p_build_seq in out NOCOPY number) return number is
441 x_success number := 0;
442 begin
443 
444         return 1;
445 
446   exception
447        when others then
448         return 0;
449 
450 
451 end build_sequence ;
452 
453 
454 
455 function src_project_id(p_src_proj_id in out NOCOPY number,
456 			p_proj_id in out NOCOPY number) return number is
457 x_success number := 0;
458 begin
459 
460 	if(p_src_proj_id is null) and (p_proj_id is not null) then
461 		p_src_proj_id := p_proj_id ;
462 	elsif (p_src_proj_id is not null) and (p_proj_id is null) then
463 		p_proj_id := p_src_proj_id ;
464 	end if ;
465 
466         return 1;
467 
468   exception
469        when others then
470         return 0;
471 
472 end src_project_id ;
473 
474 
475 function src_task_id(p_src_task_id in out NOCOPY number,
476 		      p_task_id in out NOCOPY number) return number is
477 x_success number := 0;
478 begin
479 
480 
481         if(p_src_task_id is null) and (p_task_id is not null) then
482                 p_src_task_id := p_task_id ;
483         elsif (p_src_task_id is not null) and (p_task_id is null) then
484                 p_task_id := p_src_task_id ;
485         end if ;
486 
487         return 1;
488 
489   exception
490        when others then
491         return 0;
492 
493 end src_task_id ;
494 
495 
496 
497 function schedule_number(p_sched_num in out NOCOPY varchar2) return number is
498 begin
499 
500         if(p_sched_num is null) then
501 
502                 select WIP_JOB_NUMBER_S.nextval into p_sched_num
503                 from dual ;
504                 p_sched_num := substr(FND_PROFILE.value('WIP_JOB_PREFIX'),1,20)
505                                      || p_sched_num ;
506 
507         end if ;
508 
509 	return 1;
510 
511     exception
512 	when others then
513 	    return 0;
514 end schedule_number ;
515 
516 
517 function Last_Updated_Id(p_last_up_by_name in out NOCOPY varchar2,
518 			      p_last_up_id in out NOCOPY number) return number is
519 x_success number := 0;
520 BEGIN
521 
522 	if (p_last_up_id is null) and (p_last_up_by_name is not null) then
523 
524 	   select USER_ID
525 	   into p_last_up_id
526 	   from FND_USER
527 	   where USER_NAME = p_last_up_by_name ;
528 
529 	elsif (p_last_up_id is not null) and (p_last_up_by_name is null) then
530 
531            select USER_NAME
532            into p_last_up_by_name
533            from FND_USER
534            where USER_ID = p_last_up_id ;
535 
536 	end if ;
537 
538 	return 1;
539 
540   exception
541        when others then
542         return 0;
543 
544 END Last_Updated_Id;
545 
546 function Created_By_ID(p_created_by_name in out NOCOPY varchar2,
547                               p_created_id in out NOCOPY number) return number is
548 x_success number := 0;
549 BEGIN
550 
551         if (p_created_id is null) and (p_created_by_name is not null) then
552 
553            select USER_ID
554 	   into p_created_id
555            from FND_USER
556            where USER_NAME = p_created_by_name ;
557 
558        elsif (p_created_id is not null) and (p_created_by_name is null) then
559 
560            select USER_NAME
561            into p_created_by_name
562            from FND_USER
563            where USER_ID = p_created_id ;
564 
565         end if ;
566 
567         return 1;
568 
569   exception
570        when others then
571         return 0;
572 
573 END Created_By_ID;
574 
575 
576 
577 function Organization_Code(p_org_name in out NOCOPY varchar2,
578                            p_org_id in out NOCOPY number) return number is
579 x_success number := 0;
580 BEGIN
581 
582 	if (p_org_id is null) and (p_org_name is not null) then
583 
584 	    select ORGANIZATION_ID
585 	    into p_org_id
586 	    --from ORG_ORGANIZATION_DEFINITIONS
587             from mtl_parameters
588 	    where ORGANIZATION_CODE = p_org_name ;
589 
590 	elsif (p_org_id is not null) and (p_org_name is null) then
591 
592             select ORGANIZATION_CODE
593             into p_org_name
594             --from ORG_ORGANIZATION_DEFINITIONS
595             from mtl_parameters
596             where ORGANIZATION_ID = p_org_id ;
597 
598 	end if ;
599 
600         return 1;
601 
602   exception
603        when others then
604         return 0;
605 
606 
607 
608 END Organization_Code;
609 
610 
611 
612 /**********************************************************
613 * This particular function should be called only for      *
614 * Scheduled Flow Schedules as in the case of Unscheduled  *
615 * Flow Schedules we create a New Flow Schedule at runtime *
616 * and this does not make sense for them			  *
617 *							  *
618 *				- dsoosai 12/11/97	  *
619 **********************************************************/
620 
621 function Transaction_Source_Name(
622 			p_txn_src_name in out NOCOPY varchar2,
623                         p_txn_src_id in out NOCOPY number,
624 			p_Org_id in number) return number is
625 
626 BEGIN
627 
628 
629 	if (p_txn_src_id is null) and (p_txn_src_name is not null) then
630 
631 		select wip_entity_id
632 		into p_txn_src_id
633 		from wip_entities we
634 		where we.organization_id = p_org_id
635 		and we.wip_entity_name  = p_txn_src_name ;
636 
637 	elsif (p_txn_src_id is not null) and (p_txn_src_name is null) then
638 
639                 select wip_entity_name
640                 into p_txn_src_name
641                 from wip_entities we
642                 where we.organization_id = p_org_id
643                 and we.wip_entity_id  = p_txn_src_id ;
644 
645 	end if ;
646 
647 	return 1;
648 
649      exception
650       when others then
651 	return 0 ;
652 
653 END Transaction_Source_Name;
654 
655 
656 
657 function Scheduled_Flow_Derivation(
658 			p_txn_action_id IN NUMBER,-- CFM Scrap
659 			p_item_id in number,
660                         p_org_id in number,
661                         p_txn_src_id in number,
662                         p_sched_num in out NOCOPY varchar2,
663                         p_src_proj_id in out NOCOPY number,
664                         p_proj_id in out NOCOPY number,
665                         p_src_task_id in out NOCOPY number,
666                         p_task_id in out NOCOPY number,
667                         p_bom_rev in out NOCOPY varchar2,
668                         p_rev in out NOCOPY varchar2,
669                         p_bom_rev_date  in out NOCOPY date,
670                         p_rout_rev in out NOCOPY varchar2,
671                         p_rout_rev_date in out NOCOPY date,
672                         p_comp_sub in out NOCOPY varchar2,
673                         p_class_code in out NOCOPY varchar2,
674                         p_wip_entity_type in out NOCOPY number,
675                         p_comp_loc in out NOCOPY number,
676                         p_alt_rtg_des in out NOCOPY varchar2,
677 			p_alt_bom_des in out NOCOPY varchar2) return number is
678 x_success number := 0;
679 x_sched_cmp_date date;
680 begin
681 
682 	select
683 		nvl(p_sched_num, schedule_number),
684 		nvl(p_src_proj_id,project_id),
685 		nvl(p_src_task_id,task_id),
686 		nvl(p_proj_id,project_id),
687 		nvl(p_task_id,task_id),
688 		nvl(p_bom_rev,bom_revision),
689 		nvl(p_bom_rev_date,bom_revision_date),
690 		nvl(p_rout_rev,routing_revision),
691 		nvl(p_rout_rev_date,routing_revision_date),
692 		Decode(p_txn_action_id, 30, NULL, nvl(p_comp_sub,completion_subinventory)),-- CFM Scrap
693 		nvl(p_class_code,class_code),
694 		nvl(p_wip_entity_type,4),  -- Work Order-less Completions
695 		-- fix bug#956467
696 		Decode(p_txn_action_id, 30, NULL,nvl(p_comp_loc,completion_locator_id)),-- CFM Scrap
697 		nvl(p_alt_rtg_des,alternate_routing_designator),
698 		nvl(p_alt_bom_des,alternate_bom_designator),
699 		scheduled_completion_date
700 	into
701 		p_sched_num,
702 		p_src_proj_id,
703 		p_src_task_id,
704 		p_proj_id,
705 		p_task_id,
706 		p_bom_rev,
707 		p_bom_rev_date,
708 		p_rout_rev,
709 		p_rout_rev_date,
710 		p_comp_sub,
711 		p_class_code,
712 		p_wip_entity_type,
713 		p_comp_loc,
714 		p_alt_rtg_des,
715 		p_alt_bom_des,
716 		x_sched_cmp_date
717 	from
718 		wip_flow_schedules
719 	where
720 		wip_entity_id = p_txn_src_id
721 		and organization_id = p_org_id ;
722 
723 
724        x_success := 1 ;
725 
726        --if p_bom_rev is null then(fix bug#1032431)
727 
728 	  x_success :=  bom_revision(
729                            	p_bom_rev => p_bom_rev,
730                            	p_rev => p_rev,
731                            	p_bom_rev_date => p_bom_rev_date,
732                            	p_item_id => p_item_id,
733                            	p_start_date => x_sched_cmp_date,
734                            	p_Org_id => p_org_id ) ;
735        --end if ;
736 
737 
738        if (p_rout_rev is null) and (x_success = 1) then
739 
740 	  x_success :=  routing_revision(
741 				p_rout_rev => p_rout_rev,
742                             	p_rout_rev_date => p_rout_rev_date,
743                             	p_item_id => p_item_id,
744                             	p_start_date => x_sched_cmp_date,
745                             	p_Org_id => p_org_id ) ;
746 
747        end if;
748 
749 /* The revision should be derived based on the transaction date, but for CFM the scheduled completion date has to be the same as the transaction date. We are using this fact here to derive the bill and routing revisions */
750 
751 	return x_success;
752 
753      exception
754 
755 	when others then
756 		return 0;
757 
758 end Scheduled_Flow_Derivation ;
759 
760 
761 
762 
763 function Flow_Form_Defaulting(
764 	  p_txn_action_id IN NUMBER,-- CFM Scrap
765           p_txn_type_id in number,
766           p_item_id in number,
767           p_org_id in number,
768           p_start_date in date,
769           p_alt_rtg_des in varchar2,
770           p_bom_rev in out NOCOPY varchar2,
771           p_rev in out NOCOPY varchar2,
772           p_bom_rev_date in out NOCOPY date,
773           p_rout_rev in out NOCOPY varchar2,
774           p_rout_rev_date in out NOCOPY date,
775           p_comp_sub in out NOCOPY varchar2,
776           p_comp_loc in out NOCOPY number,
777           p_proj_id in number,
778           p_task_id in number) return number is
779 
780 x_bom_ret number := 0 ;
781 x_rout_ret number := 0;
782 x_sub_ret number := 0;
783 x_loc_ret number := 0 ;
784 
785 begin
786 
787 
788         x_bom_ret := bom_revision (
789                            p_bom_rev => p_bom_rev,
790                            p_rev => p_rev,
791                            p_bom_rev_date => p_bom_rev_date,
792                            p_item_id => p_item_id,
793                            p_start_date => p_start_date,
794                            p_Org_id => p_org_id );
795 
796 
797 
798      x_rout_ret := routing_revision(
799                                 p_rout_rev => p_rout_rev,
800                                 p_rout_rev_date => p_rout_rev_date,
801                                 p_item_id => p_item_id,
802                                 p_start_date => p_start_date,
803                                 p_Org_id => p_org_id );
804 
805 
806 
807      IF (p_txn_action_id <> 30) then
808 	x_sub_ret := routing_completion_sub_loc(
809                                 p_rout_comp_sub => p_comp_sub,
810                                 p_rout_comp_loc => p_comp_loc,
811                                 p_item_id => p_item_id,
812                                 p_org_id => p_org_id,
813                                 p_alt_rtg_des => p_alt_rtg_des);
814 
815 
816 
817 	x_loc_ret := Completion_loc(
818                                 p_comp_loc => p_comp_loc,
819                                 p_item_id => p_item_id,
820                                 p_org_id => p_org_id,
821                                 p_alt_rtg_des => p_alt_rtg_des,
822                                 p_proj_id => p_proj_id,
823                                 p_task_id => p_task_id,
824                                 p_comp_sub => p_comp_sub,
825                     p_txn_int_id => null) ;
826         /* for bug 3710003
827            check if subinventory is inactive, if yes then make subinv and locator null
828         */
829            if p_comp_sub is not null then
830              BEGIN
831                select null,null           /*completion subinventory is inactive */
832                into p_comp_sub,p_comp_loc
833                from   mtl_secondary_inventories
834                where  organization_id = p_org_id
835                and    secondary_inventory_name = p_comp_sub
836                and   (
837                         NVL(disable_date, TRUNC(p_start_date)+1) <= TRUNC(p_start_date)
838                               OR
839                        /*Bug3784658. Consider material status */
840                         wip_utilities.is_status_applicable(NULL,
841                                                            p_txn_type_id,
842                                                            NULL,
843                                                            NULL,
844                                                            p_org_id,
845                                                            p_item_id,
846                                                            p_comp_sub,
847                                                            NULL,
848                                                            NULL,
849                                                            NULL,
850                                                            'Z') = 'N');
851                x_sub_ret := 1;
852                x_loc_ret := 1;
853              EXCEPTION
854                when no_data_found then /*completion subinventory is active */
855                  null;
856              END;
857            end if;
858 
859       ELSE
860 	x_sub_ret := 1;
861 	x_loc_ret := 1;
862      END IF;
863 
864      return  (x_bom_ret * x_rout_ret * x_sub_ret * x_loc_ret) ;
865 
866     exception
867 
868        when others then
869           return 0 ;
870 
871 End Flow_Form_Defaulting ;
872 
873 
874 
875 
876 
877 End Wip_Flow_Derive ;