DBA Data[Home] [Help]

PACKAGE BODY: APPS.EAM_OP_VALIDATE_PVT

Source


1 PACKAGE BODY EAM_OP_VALIDATE_PVT AS
2 /* $Header: EAMVOPVB.pls 120.8.12020000.3 2012/11/30 10:58:08 vchidura ship $ */
3 /***************************************************************************
4 --
5 --  Copyright (c) 2002 Oracle Corporation, Redwood Shores, CA, USA
6 --  All rights reserved.
7 --
8 --  FILENAME
9 --
10 --      EAMVOPVB.pls
11 --
12 --  DESCRIPTION
13 --
14 --      Body of package EAM_OP_VALIDATE_PVT
15 --
16 --  NOTES
17 --
18 --  HISTORY
19 --
20 --  30-JUN-2002    Kenichi Nagumo     Initial Creation
21 ***************************************************************************/
22 
23 G_Pkg_Name      VARCHAR2(30) := 'EAM_OP_VALIDATE_PVT';
24 
25 g_token_tbl     EAM_ERROR_MESSAGE_PVT.Token_Tbl_Type;
26 g_shutdown_type VARCHAR2(30) := EAM_CONSTANTS.G_SHUTDOWN_TYPE;
27 
28     /*******************************************************************
29     * Procedure	: Check_Existence
30     * Returns	: None
31     * Parameters IN : Operation Record
32     * Parameters OUT NOCOPY: Old Operation Record
33     *                 Mesg Token Table
34     *                 Return Status
35     * Purpose	: Procedure will query the old EAM work order
36     *             record and return it in old record variables. If the
37     *             Transaction Type is Create and the record already
38     *             exists the return status would be error or if the
39     *             transaction type is Update and the record
40     *             does not exist then the return status would be an
41     *             error as well. Mesg_Token_Table will carry the
42     *             error messsage and the tokens associated with the
43     *             message.
44     *********************************************************************/
45 
46      PROCEDURE Check_Existence
47      ( p_eam_op_rec             IN  EAM_PROCESS_WO_PUB.eam_op_rec_type
48      , x_old_eam_op_rec         OUT NOCOPY EAM_PROCESS_WO_PUB.eam_op_rec_type
49      , x_Mesg_Token_Tbl	        OUT NOCOPY EAM_ERROR_MESSAGE_PVT.Mesg_Token_Tbl_Type
50      , x_return_status	        OUT NOCOPY VARCHAR2
51         )
52      IS
53             l_token_tbl      EAM_ERROR_MESSAGE_PVT.Token_Tbl_Type;
54             l_Mesg_Token_Tbl EAM_ERROR_MESSAGE_PVT.Mesg_Token_Tbl_Type;
55             l_out_Mesg_Token_Tbl EAM_ERROR_MESSAGE_PVT.Mesg_Token_Tbl_Type;
56             l_return_status  VARCHAR2(1);
57      BEGIN
58 
59 IF EAM_PROCESS_WO_PVT.GET_DEBUG = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Quering Operations'); END IF;
60 
61         EAM_OP_UTILITY_PVT.Query_Row
62         ( p_wip_entity_id       => p_eam_op_rec.wip_entity_id
63         , p_organization_id     => p_eam_op_rec.organization_id
64         , p_operation_seq_num   => p_eam_op_rec.operation_seq_num
65         , x_eam_op_rec          => x_old_eam_op_rec
66         , x_Return_status       => l_return_status
67         );
68 
69 IF EAM_PROCESS_WO_PVT.GET_DEBUG = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Query Row Returned with : ' || l_return_status); END IF;
70 
71         IF l_return_status = EAM_PROCESS_WO_PVT.G_RECORD_FOUND AND
72             p_eam_op_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_CREATE
73         THEN
74             l_token_tbl(1).token_name  := 'OPERATION_SEQ_NUM';
75             l_token_tbl(1).token_value := p_eam_op_rec.operation_seq_num;
76 
77             l_out_mesg_token_tbl  := l_mesg_token_tbl;
78             EAM_ERROR_MESSAGE_PVT.Add_Error_Token
79             (  x_Mesg_token_tbl => l_out_Mesg_Token_Tbl
80              , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
81              , p_message_name   => 'EAM_OP_ALREADY_EXISTS'
82              , p_token_tbl      => l_token_tbl
83              );
84             l_mesg_token_tbl      := l_out_mesg_token_tbl;
85 
86             l_return_status := FND_API.G_RET_STS_ERROR;
87 
88         ELSIF l_return_status = EAM_PROCESS_WO_PVT.G_RECORD_NOT_FOUND AND
89              p_eam_op_rec.transaction_type IN
90              (EAM_PROCESS_WO_PVT.G_OPR_UPDATE, EAM_PROCESS_WO_PVT.G_OPR_DELETE)
91         THEN
92             l_token_tbl(1).token_name  := 'OPERATION_SEQ_NUM';
93             l_token_tbl(1).token_value :=  p_eam_op_rec.operation_seq_num;
94 
95             l_out_mesg_token_tbl  := l_mesg_token_tbl;
96             EAM_ERROR_MESSAGE_PVT.Add_Error_Token
97                         (  x_Mesg_token_tbl => l_out_Mesg_Token_Tbl
98                          , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
99                          , p_message_name   => 'EAM_OP_DOESNOT_EXISTS'
100                          , p_token_tbl      => l_token_tbl
101                          );
102             l_mesg_token_tbl      := l_out_mesg_token_tbl;
103 
104             l_return_status := FND_API.G_RET_STS_ERROR;
105 
106         ELSIF l_Return_status = FND_API.G_RET_STS_UNEXP_ERROR
107         THEN
108             l_out_mesg_token_tbl  := l_mesg_token_tbl;
109             EAM_ERROR_MESSAGE_PVT.Add_Error_Token
110             (  x_Mesg_token_tbl     => l_out_Mesg_Token_Tbl
111              , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
112              , p_message_name       => NULL
113              , p_message_text       => 'Unexpected error while existence verification of ' || 'Operation '|| p_eam_op_rec.operation_seq_num , p_token_tbl => l_token_tbl
114              );
115             l_mesg_token_tbl      := l_out_mesg_token_tbl;
116             l_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
117 
118         ELSE /* Assign the relevant transaction type for SYNC operations */
119             IF p_eam_op_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_SYNC THEN
120                IF l_return_status = EAM_PROCESS_WO_PVT.G_RECORD_FOUND THEN
121                    x_old_eam_op_rec.transaction_type := EAM_PROCESS_WO_PVT.G_OPR_UPDATE;
122                ELSE
123                    x_old_eam_op_rec.transaction_type := EAM_PROCESS_WO_PVT.G_OPR_CREATE;
124                END IF;
125             END IF;
126             l_return_status := FND_API.G_RET_STS_SUCCESS;
127 
128         END IF;
129 
130         x_return_status := l_return_status;
131         x_mesg_token_tbl := l_mesg_token_tbl;
132     END Check_Existence;
133 
134 
135  /********************************************************************
136        * Procedure     :       Is_Dept_Updateable
137        * Parameters IN :   Wip_Entity_Id and Operation_Seq_Num
138        * Parameters OUT NOCOPY: Return Status
139        *                 Mesg Token Table
140        * Purpose       :   Is_Dept_Updateable will check if the operation's
141        *                        department can be updateable or not
142        **********************************************************************/
143        FUNCTION Is_Dept_Updateable
144            (  p_wip_entity_id                     NUMBER,
145               p_organization_id                NUMBER,
146               p_operation_seq_num        NUMBER
147        ) RETURN BOOLEAN
148        IS
149               l_inv_count     NUMBER;
150               l_direct_count   NUMBER;
151               l_res_count       NUMBER;
152               l_po_count         NUMBER;
153               l_req_count       NUMBER;
154               l_dist_count       NUMBER;
155        BEGIN
156 
157                --initialise variables
158                l_inv_count              := 0;
159                l_direct_count         :=  0;
160                l_res_count             :=  0;
161                l_po_count              := 0;
162                l_req_count             :=  0;
163                l_dist_count            := 0;
164 
165                 --check if any stocked/non-stocked inventory items exist for this op
166                        select count(*)
167                        into l_inv_count
168                        from dual
169                        where exists (select 1
170                                                  from wip_requirement_operations wro
171                                                  where wro.wip_entity_id = p_wip_entity_id
172                                                  and wro.organization_id   = p_organization_id
173                                                  and wro.operation_seq_num   = p_operation_seq_num
174 						 and ( quantity_issued > 0  or
175 						      EAM_MATERIAL_ALLOCQTY_PKG.allocated_quantity(
176 						       wro.wip_entity_id,
177 						       wro.organization_id,
178 						       wro.operation_seq_num,
179 						       wro.inventory_item_id ) >0 )
180 							 );
181 
182                   IF(l_inv_count > 0) THEN
183                        RETURN FALSE;
184                   END IF;
185 
186                    --check if any resources exist for this op
187                         select count(*)
188                         into l_res_count
189                         from dual
190                         where exists (select 1
191                                                    from wip_operation_resources
192                                                    where wip_entity_id = p_wip_entity_id
193                                                  and organization_id   = p_organization_id
194                                                  and operation_seq_num   = p_operation_seq_num);
195 
196                   IF(l_res_count > 0) THEN
197                        RETURN FALSE;
198                   END IF;
199 
200                   --check if any pending requisitions exist for this op
201                 /*  select count(*)
202                 into l_po_count
203                 from DUAL
204                 WHERE EXISTS (SELECT 1
205                                FROM po_requisitions_interface
206                                where wip_entity_id               = p_wip_entity_id
207                                  and destination_organization_id = p_organization_id
208                                  and wip_operation_seq_num       = p_operation_seq_num);
209 
210               if(l_po_count > 0) then
211                 RETURN FALSE;
212               end if; */
213 
214 
215                    --check if any requisitions exist for this op
216                 select count(*)
217                 into l_req_count
218                 from DUAL
219                 WHERE EXISTS (SELECT 1
220                                FROM po_requisition_lines prl, po_requisition_headers prh
221                                where prl.requisition_header_id = prh.requisition_header_id
222                                  and prl.wip_entity_id               = p_wip_entity_id
223                                  and prl.destination_organization_id = p_organization_id
224                                  and prl.wip_operation_seq_num       = p_operation_seq_num
225                                  and   (prh.authorization_status <>'CANCELLED'
226                                     or    prh.authorization_status is null)
227                                  and   (prl.cancel_flag <>'Y' or prl.cancel_flag is null)
228                                  and   (prl.closed_code not in ('FINALLY CLOSED')
229                                     or    prl.closed_code is null)
230                                  and   (prl.modified_by_agent_flag <> 'Y'
231                                     or    prl.modified_by_agent_flag is null));
232 
233 
234               if(l_req_count > 0) then
235                 RETURN FALSE;
236               end if;
237 
238 
239                  --check if any purchase orders exist for this op
240                 select count(*)
241                 into l_dist_count
242                 from DUAL
243                 WHERE EXISTS (SELECT 1
244                                FROM po_distributions pds,po_line_locations poll
245                                where pds.line_location_id =  poll.line_location_id
246                                  and pds.wip_entity_id               = p_wip_entity_id
247                                  and pds.destination_organization_id = p_organization_id
248                                  and pds.wip_operation_seq_num       = p_operation_seq_num
249                                  and   (poll.cancel_flag <>'Y' or poll.cancel_flag is null)
250                                  and   (poll.closed_code not in ('CANCELLED','FINALLY CLOSED')
251                                         or    poll.closed_code is null));
252 
253            IF(l_dist_count > 0) THEN
254                 RETURN FALSE;
255            END IF;
256 
257            --dept is updateable
258            RETURN TRUE ;
259 
260        END Is_Dept_Updateable;
261 
262 
263 
264 
265     /********************************************************************
266     * Procedure     : Check_Attributes
267     * Parameters IN : Operation Column record
268     *                 Old Operation Column record
269     * Parameters OUT NOCOPY: Return Status
270     *                 Mesg Token Table
271     * Purpose       : Check_Attrbibutes procedure will validate every
272     *                 revised item attrbiute in its entirety.
273     **********************************************************************/
274 
275     PROCEDURE Check_Attributes
276         (  p_eam_op_rec              IN EAM_PROCESS_WO_PUB.eam_op_rec_type
277          , p_old_eam_op_rec          IN EAM_PROCESS_WO_PUB.eam_op_rec_type
278          , x_return_status           OUT NOCOPY VARCHAR2
279          , x_Mesg_Token_Tbl          OUT NOCOPY EAM_ERROR_MESSAGE_PVT.Mesg_Token_Tbl_Type
280     )
281     IS
282     l_err_text              VARCHAR2(2000) := NULL;
283     l_Mesg_Token_Tbl        EAM_ERROR_MESSAGE_PVT.Mesg_Token_Tbl_Type;
284     l_out_Mesg_Token_Tbl        EAM_ERROR_MESSAGE_PVT.Mesg_Token_Tbl_Type;
285     l_Token_Tbl             EAM_ERROR_MESSAGE_PVT.Token_Tbl_Type;
286     g_dummy          NUMBER;
287     l_mat_count	     NUMBER;
288     l_di_count	     NUMBER;
289     l_wedi_count     NUMBER;
290     l_po_count       NUMBER;
291     l_req_count      NUMBER;
292     OP_DEPT_NOT_UPDATEABLE   EXCEPTION;
293 
294     l_count_res  NUMBER :=0;  -- fix for bug 1166647
295     l_cmro_count NUMBER :=0;   -- fix for bug 1166647
296 
297     BEGIN
298 
299         x_return_status := FND_API.G_RET_STS_SUCCESS;
300 
301         IF EAM_PROCESS_WO_PVT.GET_DEBUG = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Within WO Check Attributes . . . '); END IF;
302 
303 
304 --  department_id
305 IF EAM_PROCESS_WO_PVT.GET_DEBUG = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Validating department_id . . . '); END IF;
306 
307   begin
308 
309    if (p_eam_op_rec.transaction_type in (EAM_PROCESS_WO_PVT.G_OPR_CREATE, EAM_PROCESS_WO_PVT.G_OPR_UPDATE)) then
310 
311        select 1
312         into g_dummy
313         from bom_departments
314        where department_id = p_eam_op_rec.department_id
315          and organization_id = p_eam_op_rec.organization_id;
316 
317 				                 if (p_eam_op_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_UPDATE and
318 							   (p_eam_op_rec.department_id <> p_old_eam_op_rec.department_id)
319 							   and ((Is_Dept_Updateable(p_wip_entity_id              => p_eam_op_rec.wip_entity_id
320 													    , p_organization_id         => p_eam_op_rec.organization_id
321 													    , p_operation_seq_num => p_eam_op_rec.operation_seq_num ))
322 												  in (FALSE)  and is_op_dept_change_allowed(p_eam_op_rec.wip_entity_id,p_eam_op_rec.operation_seq_num)='N')
323 							   ) THEN
324 										raise OP_DEPT_NOT_UPDATEABLE;
325 						      end if;    --end of check for update and is_dept_updateable
326    end if;     --end of check for create/update transaction
327 
328    -- fix for bug 11666479 : do not allow dept change if resources exists for CMRO workorders
329   if (p_eam_op_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_UPDATE) and
330 							   (p_eam_op_rec.department_id <> p_old_eam_op_rec.department_id) then
331    select count(*)          --fix for bug 14096091
332    into l_cmro_count
333    from wip_discrete_jobs
334        where wip_entity_id = p_eam_op_rec.wip_entity_id
335        and organization_id = p_eam_op_rec.organization_id
336        and maintenance_object_source =2; --cmro
337 
338     if(l_cmro_count > 0) then
339          select count(*)
340              into l_count_res
341              from wip_operation_resources
342             where wip_entity_id         = p_eam_op_rec.wip_entity_id
343               and organization_id       = p_eam_op_rec.organization_id
344               and operation_seq_num     = p_eam_op_rec.operation_seq_num;
345 
346            if(l_count_res > 0) then
347              raise OP_DEPT_NOT_UPDATEABLE;
348            end if;
349     end if;
350     -- End -- fix for bug 11666479 : do not allow dept change if resources exists for CMRO workorders
351  end if;
352     x_return_status := FND_API.G_RET_STS_SUCCESS;
353 
354   exception
355    WHEN OP_DEPT_NOT_UPDATEABLE THEN
356       l_token_tbl(1).token_name  := 'DEPT_NAME';
357 
358       SELECT bd.department_code into l_token_tbl(1).token_value
359 	 FROM  bom_departments bd
360 	 WHERE 	 bd.DEPARTMENT_ID = p_eam_op_rec.department_id
361  	 AND     bd.organization_id   = p_eam_op_rec.organization_id;
362 
363 
364       l_out_mesg_token_tbl  := l_mesg_token_tbl;
365       EAM_ERROR_MESSAGE_PVT.Add_Error_Token
366       (  p_message_name  => 'EAM_OP_DEPT_UPDATE'
367        , p_token_tbl     => l_token_tbl
368        , p_mesg_token_tbl     => l_mesg_token_tbl
369        , x_mesg_token_tbl     => l_out_mesg_token_tbl
370       );
371       l_mesg_token_tbl      := l_out_mesg_token_tbl;
372 
373       x_return_status := FND_API.G_RET_STS_ERROR;
374       x_mesg_token_tbl := l_mesg_token_tbl ;
375       return;
376 
377     when others then
378 
379       l_token_tbl(1).token_name  := 'DEPARTMENT_NAME';
380 
381       SELECT bd.department_code into l_token_tbl(1).token_value
382 	 FROM  bom_departments bd
383 	 WHERE 	 bd.DEPARTMENT_ID = p_eam_op_rec.department_id
384  	 AND     bd.organization_id   = p_eam_op_rec.organization_id;
385 
386 
387       l_out_mesg_token_tbl  := l_mesg_token_tbl;
388       EAM_ERROR_MESSAGE_PVT.Add_Error_Token
389       (  p_message_name  => 'EAM_OP_DEPT_INVALID'
390        , p_token_tbl     => l_token_tbl
391        , p_mesg_token_tbl     => l_mesg_token_tbl
392        , x_mesg_token_tbl     => l_out_mesg_token_tbl
393       );
394       l_mesg_token_tbl      := l_out_mesg_token_tbl;
395 
396       x_return_status := FND_API.G_RET_STS_ERROR;
397       x_mesg_token_tbl := l_mesg_token_tbl ;
398       return;
399 
400   end;
401 
402 --  standard_operation_id
403 IF EAM_PROCESS_WO_PVT.GET_DEBUG = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Validating standard_operation_id . . . '); END IF;
404 
405   begin
406 
407    if (p_eam_op_rec.transaction_type in (EAM_PROCESS_WO_PVT.G_OPR_CREATE, EAM_PROCESS_WO_PVT.G_OPR_UPDATE)) then
408 
409     if (p_eam_op_rec.standard_operation_id is not null) then
410 
411       select 1
412         into g_dummy
413         from bom_standard_operations
414        where standard_operation_id = p_eam_op_rec.standard_operation_id
415          and organization_id = p_eam_op_rec.organization_id;
416     end if;
417 
418    end if;
419 
420     x_return_status := FND_API.G_RET_STS_SUCCESS;
421 
422   exception
423     when others then
424 
425       l_token_tbl(1).token_name  := 'STANDARD_OPERATION';
426       l_token_tbl(1).token_value :=  p_eam_op_rec.standard_operation_id;
427 
428       l_out_mesg_token_tbl  := l_mesg_token_tbl;
429       EAM_ERROR_MESSAGE_PVT.Add_Error_Token
430       (  p_message_name  => 'EAM_OP_STD_OP_INVALID'
431        , p_token_tbl     => l_token_tbl
432        , p_mesg_token_tbl     => l_mesg_token_tbl
433        , x_mesg_token_tbl     => l_out_mesg_token_tbl
434       );
435       l_mesg_token_tbl      := l_out_mesg_token_tbl;
436 
437       x_return_status := FND_API.G_RET_STS_ERROR;
438       x_mesg_token_tbl := l_mesg_token_tbl ;
439       return;
440 
441   end;
442 
443 --  minimum_transfer_quantity
444 IF EAM_PROCESS_WO_PVT.GET_DEBUG = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Validating minimum_transfer_quantity . . . '); END IF;
445 
446   begin
447 
448    if (p_eam_op_rec.transaction_type in (EAM_PROCESS_WO_PVT.G_OPR_CREATE, EAM_PROCESS_WO_PVT.G_OPR_UPDATE)) then
449 
450     if p_eam_op_rec.minimum_transfer_quantity < 0 then
451       raise fnd_api.g_exc_unexpected_error;
452     end if;
453 
454    end if;
455 
456     x_return_status := FND_API.G_RET_STS_SUCCESS;
457 
458   exception
459     when others then
460 
461       l_token_tbl(1).token_name  := 'MINIMUM_TRANSFER_QUANTITY';
462       l_token_tbl(1).token_value :=  p_eam_op_rec.minimum_transfer_quantity;
463 
464       l_out_mesg_token_tbl  := l_mesg_token_tbl;
465       EAM_ERROR_MESSAGE_PVT.Add_Error_Token
466       (  p_message_name  => 'EAM_OP_MIN_TRS_QTY_INVALID'
467        , p_token_tbl     => l_token_tbl
468        , p_mesg_token_tbl     => l_mesg_token_tbl
469        , x_mesg_token_tbl     => l_out_mesg_token_tbl
470       );
471       l_mesg_token_tbl      := l_out_mesg_token_tbl;
472 
473       x_return_status := FND_API.G_RET_STS_ERROR;
474       x_mesg_token_tbl := l_mesg_token_tbl ;
475       return;
476 
477   end;
478 
479 --  count_point_type
480 IF EAM_PROCESS_WO_PVT.GET_DEBUG = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Validating count_point_type . . . '); END IF;
481 
482   begin
483 
484    if (p_eam_op_rec.transaction_type in (EAM_PROCESS_WO_PVT.G_OPR_CREATE, EAM_PROCESS_WO_PVT.G_OPR_UPDATE)) then
485 
486       select 1
487         into g_dummy
488         from mfg_lookups
489        where lookup_type = 'BOM_COUNT_POINT_TYPE'
490          and lookup_code = p_eam_op_rec.count_point_type;
491 
492    end if;
493 
494     x_return_status := FND_API.G_RET_STS_SUCCESS;
495 
496   exception
497     when others then
498 
499       l_token_tbl(1).token_name  := 'COUNT_POINT_TYPE';
500       l_token_tbl(1).token_value :=  p_eam_op_rec.count_point_type;
501 
502       l_out_mesg_token_tbl  := l_mesg_token_tbl;
503       EAM_ERROR_MESSAGE_PVT.Add_Error_Token
504       (  p_message_name  => 'EAM_OP_COUNT_POINT_INVALID'
505        , p_token_tbl     => l_token_tbl
506        , p_mesg_token_tbl     => l_mesg_token_tbl
507        , x_mesg_token_tbl     => l_out_mesg_token_tbl
508       );
509       l_mesg_token_tbl      := l_out_mesg_token_tbl;
510 
511       x_return_status := FND_API.G_RET_STS_ERROR;
512       x_mesg_token_tbl := l_mesg_token_tbl ;
513       return;
514 
515   end;
516 
517 --  backflush_flag
518 IF EAM_PROCESS_WO_PVT.GET_DEBUG = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Validating backflush_flag . . . '); END IF;
519 
520   begin
521 
522    if (p_eam_op_rec.transaction_type in (EAM_PROCESS_WO_PVT.G_OPR_CREATE, EAM_PROCESS_WO_PVT.G_OPR_UPDATE)) then
523 
524       select 1
525         into g_dummy
526         from mfg_lookups
527        where lookup_type = 'SYS_YES_NO'
528          and lookup_code = p_eam_op_rec.backflush_flag;
529 
530    end if;
531 
532     x_return_status := FND_API.G_RET_STS_SUCCESS;
533 
534   exception
535     when others then
536 
537       l_token_tbl(1).token_name  := 'BACKFLUSH_FLAG';
538       l_token_tbl(1).token_value :=  p_eam_op_rec.backflush_flag;
539 
540       l_out_mesg_token_tbl  := l_mesg_token_tbl;
541       EAM_ERROR_MESSAGE_PVT.Add_Error_Token
542       (  p_message_name  => 'EAM_OP_BACKFLUSH_INVALID'
543        , p_token_tbl     => l_token_tbl
544        , p_mesg_token_tbl     => l_mesg_token_tbl
545        , x_mesg_token_tbl     => l_out_mesg_token_tbl
546       );
547       l_mesg_token_tbl      := l_out_mesg_token_tbl;
548 
549       x_return_status := FND_API.G_RET_STS_ERROR;
550       x_mesg_token_tbl := l_mesg_token_tbl ;
551       return;
552 
553   end;
554 
555 
556 --  shutdown_type
557 IF EAM_PROCESS_WO_PVT.GET_DEBUG = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Validating shutdown_type . . . '); END IF;
558 
559   begin
560 
561    if (p_eam_op_rec.transaction_type in (EAM_PROCESS_WO_PVT.G_OPR_CREATE, EAM_PROCESS_WO_PVT.G_OPR_UPDATE)) then
562 
563     if p_eam_op_rec.shutdown_type is not null then
564       select 1
565         into g_dummy
566         from mfg_lookups
567        where lookup_type = g_shutdown_type
568          and lookup_code = p_eam_op_rec.shutdown_type
569          and enabled_flag = 'Y';
570     end if;
571 
572    end if;
573 
574     x_return_status := FND_API.G_RET_STS_SUCCESS;
575 
576   exception
577     when others then
578 
579       l_token_tbl(1).token_name  := 'SHUTDOWN_TYPE';
580       l_token_tbl(1).token_value :=  p_eam_op_rec.shutdown_type;
581 
582       l_out_mesg_token_tbl  := l_mesg_token_tbl;
583       EAM_ERROR_MESSAGE_PVT.Add_Error_Token
584       (  p_message_name  => 'EAM_OP_SHUTDOWN_INVALID'
585        , p_token_tbl     => l_token_tbl
586        , p_mesg_token_tbl     => l_mesg_token_tbl
587        , x_mesg_token_tbl     => l_out_mesg_token_tbl
588       );
589       l_mesg_token_tbl      := l_out_mesg_token_tbl;
590 
591       x_return_status := FND_API.G_RET_STS_ERROR;
592       x_mesg_token_tbl := l_mesg_token_tbl ;
593       return;
594 
595   end;
596 
597 --  start_date
598 IF EAM_PROCESS_WO_PVT.GET_DEBUG = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Validating start_date . . . '); END IF;
599 
600   begin
601 
602    if (p_eam_op_rec.transaction_type in (EAM_PROCESS_WO_PVT.G_OPR_CREATE, EAM_PROCESS_WO_PVT.G_OPR_UPDATE)) then
603 
604     if p_eam_op_rec.start_date > p_eam_op_rec.completion_date then
605       raise fnd_api.g_exc_unexpected_error;
606     end if;
607 
608    end if;
609 
610     x_return_status := FND_API.G_RET_STS_SUCCESS;
611 
612   exception
613     when others then
614 
615       l_token_tbl(1).token_name  := 'START_DATE';
616       l_token_tbl(1).token_value :=  p_eam_op_rec.start_date;
617 
618       l_out_mesg_token_tbl  := l_mesg_token_tbl;
619       EAM_ERROR_MESSAGE_PVT.Add_Error_Token
620       (  p_message_name  => 'EAM_OP_START_DATE_INVALID'
621        , p_token_tbl     => l_token_tbl
622        , p_mesg_token_tbl     => l_mesg_token_tbl
623        , x_mesg_token_tbl     => l_out_mesg_token_tbl
624       );
625       l_mesg_token_tbl      := l_out_mesg_token_tbl;
626 
627       x_return_status := FND_API.G_RET_STS_ERROR;
628       x_mesg_token_tbl := l_mesg_token_tbl ;
629       return;
630 
631   end;
632 
633 
634 --  delete operation
635 IF EAM_PROCESS_WO_PVT.GET_DEBUG = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Validating operation . . . '); END IF;
636 
637        declare
638          l_count_eoct             NUMBER :=0;
639          l_count_res              NUMBER :=0;
640          l_count_on               NUMBER :=0;
641          l_count_mr               NUMBER :=0;
642        begin
643 
644        if (p_eam_op_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_DELETE) then
645 
646            select count(*)
647              into l_count_eoct
648              from eam_op_completion_txns
649             where wip_entity_id         = p_eam_op_rec.wip_entity_id
650               and organization_id       = p_eam_op_rec.organization_id
651               and operation_seq_num     = p_eam_op_rec.operation_seq_num;
652 
653            if(l_count_eoct > 0) then
654              raise fnd_api.g_exc_unexpected_error;
655            end if;
656 
657            select count(*)
658              into l_count_res
659              from wip_operation_resources
660             where wip_entity_id         = p_eam_op_rec.wip_entity_id
661               and organization_id       = p_eam_op_rec.organization_id
662               and operation_seq_num     = p_eam_op_rec.operation_seq_num;
663 
664            if(l_count_res > 0) then
665              raise fnd_api.g_exc_unexpected_error;
666            end if;
667 
668            select count(*)
669              into l_count_on
670              from wip_operation_networks
671             where wip_entity_id         = p_eam_op_rec.wip_entity_id
672               and organization_id       = p_eam_op_rec.organization_id
673               and (   prior_operation   = p_eam_op_rec.operation_seq_num
674                    or next_operation    = p_eam_op_rec.operation_seq_num);
675 
676            if(l_count_on > 0) then
677              raise fnd_api.g_exc_unexpected_error;
678            end if;
679 
680 
681            select count(*)
682              into l_count_mr
683              from wip_requirement_operations
684             where wip_entity_id         = p_eam_op_rec.wip_entity_id
685               and organization_id       = p_eam_op_rec.organization_id
686               and operation_seq_num     = p_eam_op_rec.operation_seq_num;
687 
688            if(l_count_mr <> 0) then
689              raise fnd_api.g_exc_unexpected_error;
690            end if;
691 
692        end if;
693 
694          x_return_status := FND_API.G_RET_STS_SUCCESS;
695 
696        exception
697          when others then
698 
699            l_token_tbl(1).token_name  := 'OPERATION_SEQ_NUM';
700            l_token_tbl(1).token_value :=  p_eam_op_rec.operation_seq_num;
701 
702            l_out_mesg_token_tbl  := l_mesg_token_tbl;
703            EAM_ERROR_MESSAGE_PVT.Add_Error_Token
704            (  p_message_name  => 'EAM_OP_DELETE_INVALID'
705             , p_token_tbl     => l_token_tbl
706             , p_mesg_token_tbl     => l_mesg_token_tbl
707             , x_mesg_token_tbl     => l_out_mesg_token_tbl
708            );
709            l_mesg_token_tbl      := l_out_mesg_token_tbl;
710 
711            x_return_status := FND_API.G_RET_STS_ERROR;
712            x_mesg_token_tbl := l_mesg_token_tbl ;
713            return;
714 
715        end;
716 
717 
718 
719     EXCEPTION
720         WHEN OTHERS THEN
721 
722         l_token_tbl(1).token_name  := 'Validation (Check Attributes)';
723         l_token_tbl(1).token_value :=  substrb(SQLERRM,1,200);
724 
725               l_out_mesg_token_tbl  := l_mesg_token_tbl;
726               EAM_ERROR_MESSAGE_PVT.Add_Error_Token
727               (  p_message_name   => NULL
728                , p_token_tbl      => l_token_tbl
729                , p_mesg_token_tbl => l_mesg_token_tbl
730                , x_mesg_token_tbl => l_out_mesg_token_tbl
731               ) ;
732               l_mesg_token_tbl      := l_out_mesg_token_tbl;
733 
734               -- Return the status and message table.
735               x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
736               x_mesg_token_tbl := l_mesg_token_tbl ;
737 
738 
739     END Check_Attributes;
740 
741     /*********************************************************************
742     * Procedure     : Check_Required
743     * Parameters IN : Operation column record
744     * Parameters OUT NOCOPY: Mesg Token Table
745     *                 Return_Status
746     * Purpose       :
747     **********************************************************************/
748 
749     PROCEDURE Check_Required
750         (  p_eam_op_rec             IN EAM_PROCESS_WO_PUB.eam_op_rec_type
751          , x_return_status          OUT NOCOPY VARCHAR2
752          , x_Mesg_Token_Tbl         OUT NOCOPY EAM_ERROR_MESSAGE_PVT.Mesg_Token_Tbl_Type
753          )
754     IS
755             l_Mesg_Token_Tbl        EAM_ERROR_MESSAGE_PVT.Mesg_Token_Tbl_Type;
756             l_out_Mesg_Token_Tbl        EAM_ERROR_MESSAGE_PVT.Mesg_Token_Tbl_Type;
757             l_Token_Tbl             EAM_ERROR_MESSAGE_PVT.Token_Tbl_Type;
758     BEGIN
759 
760         x_return_status := FND_API.G_RET_STS_SUCCESS;
761 
762         IF p_eam_op_rec.wip_entity_id IS NULL
763         THEN
764             l_token_tbl(1).token_name  := 'OPERATION_SEQ_NUM';
765             l_token_tbl(1).token_value :=  p_eam_op_rec.operation_seq_num;
766 
767             l_out_mesg_token_tbl  := l_mesg_token_tbl;
768             EAM_ERROR_MESSAGE_PVT.Add_Error_Token
769             (  p_message_name	=> 'EAM_OP_ENTITY_ID_REQUIRED'
770              , p_token_tbl		=> l_Token_tbl
771              , p_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
772              , x_Mesg_Token_Tbl	=> l_out_Mesg_Token_Tbl
773              );
774             l_mesg_token_tbl      := l_out_mesg_token_tbl;
775 
776             x_return_status := FND_API.G_RET_STS_ERROR;
777 
778         END IF;
779 
780         IF p_eam_op_rec.operation_seq_num IS NULL
781         THEN
782             --l_token_tbl(1).token_name  := 'OPERATION_SEQ_NUM';
783             --l_token_tbl(1).token_value :=  p_eam_op_rec.operation_seq_num;
784             l_token_tbl.delete;
785 
786             l_out_mesg_token_tbl  := l_mesg_token_tbl;
787             EAM_ERROR_MESSAGE_PVT.Add_Error_Token
788             (  p_message_name   => 'EAM_OP_OP_SEQ_REQUIRED'
789              , p_token_tbl              => l_Token_tbl
790              , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
791              , x_Mesg_Token_Tbl => l_out_Mesg_Token_Tbl
792              );
793             l_mesg_token_tbl      := l_out_mesg_token_tbl;
794 
795             x_return_status := FND_API.G_RET_STS_ERROR;
796 
797         END IF;
798 
799         IF p_eam_op_rec.organization_id IS NULL
800         THEN
801             l_token_tbl(1).token_name  := 'OPERATION_SEQ_NUM';
802             l_token_tbl(1).token_value :=  p_eam_op_rec.operation_seq_num;
803 
804             l_out_mesg_token_tbl  := l_mesg_token_tbl;
805             EAM_ERROR_MESSAGE_PVT.Add_Error_Token
806             (  p_message_name	=> 'EAM_OP_ORG_REQUIRED'
807              , p_token_tbl		=> l_Token_tbl
808              , p_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
809              , x_Mesg_Token_Tbl	=> l_out_Mesg_Token_Tbl
810              );
811             l_mesg_token_tbl      := l_out_mesg_token_tbl;
812 
813             x_return_status := FND_API.G_RET_STS_ERROR;
814 
815         END IF;
816 
817         IF p_eam_op_rec.department_id IS NULL
818         THEN
819             l_token_tbl(1).token_name  := 'OPERATION_SEQ_NUM';
820             l_token_tbl(1).token_value :=  p_eam_op_rec.operation_seq_num;
821 
822             l_out_mesg_token_tbl  := l_mesg_token_tbl;
823             EAM_ERROR_MESSAGE_PVT.Add_Error_Token
824             (  p_message_name	=> 'EAM_OP_DEPT_REQUIRED'
825              , p_token_tbl		=> l_Token_tbl
826              , p_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
827              , x_Mesg_Token_Tbl	=> l_out_Mesg_Token_Tbl
828              );
829             l_mesg_token_tbl      := l_out_mesg_token_tbl;
830 
831             x_return_status := FND_API.G_RET_STS_ERROR;
832 
833         END IF;
834 
835         IF p_eam_op_rec.start_date IS NULL
836         THEN
837             l_token_tbl(1).token_name  := 'OPERATION_SEQ_NUM';
838             l_token_tbl(1).token_value :=  p_eam_op_rec.operation_seq_num;
839 
840             l_out_mesg_token_tbl  := l_mesg_token_tbl;
841             EAM_ERROR_MESSAGE_PVT.Add_Error_Token
842             (  p_message_name	=> 'EAM_OP_START_DATE_REQUIRED'
843              , p_token_tbl		=> l_Token_tbl
844              , p_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
845              , x_Mesg_Token_Tbl	=> l_out_Mesg_Token_Tbl
846              );
847             l_mesg_token_tbl      := l_out_mesg_token_tbl;
848 
849             x_return_status := FND_API.G_RET_STS_ERROR;
850 
851         END IF;
852 
853         IF p_eam_op_rec.completion_date IS NULL
854         THEN
855             l_token_tbl(1).token_name  := 'OPERATION_SEQ_NUM';
856             l_token_tbl(1).token_value :=  p_eam_op_rec.operation_seq_num;
857 
858             l_out_mesg_token_tbl  := l_mesg_token_tbl;
859             EAM_ERROR_MESSAGE_PVT.Add_Error_Token
860             (  p_message_name	=> 'EAM_OP_COMPL_DATE_REQUIRED'
861              , p_token_tbl		=> l_Token_tbl
862              , p_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
863              , x_Mesg_Token_Tbl	=> l_out_Mesg_Token_Tbl
864              );
865             l_mesg_token_tbl      := l_out_mesg_token_tbl;
866 
867             x_return_status := FND_API.G_RET_STS_ERROR;
868 
869         END IF;
870 
871         IF p_eam_op_rec.count_point_type IS NULL
872         THEN
873             l_token_tbl(1).token_name  := 'OPERATION_SEQ_NUM';
874             l_token_tbl(1).token_value :=  p_eam_op_rec.operation_seq_num;
875 
876             l_out_mesg_token_tbl  := l_mesg_token_tbl;
877             EAM_ERROR_MESSAGE_PVT.Add_Error_Token
878             (  p_message_name	=> 'EAM_OP_COUNT_POINT_REQUIRED'
879              , p_token_tbl		=> l_Token_tbl
880              , p_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
881              , x_Mesg_Token_Tbl	=> l_out_Mesg_Token_Tbl
882              );
883             l_mesg_token_tbl      := l_out_mesg_token_tbl;
884 
885             x_return_status := FND_API.G_RET_STS_ERROR;
886 
887         END IF;
888 
889         IF p_eam_op_rec.backflush_flag IS NULL
890         THEN
891             l_token_tbl(1).token_name  := 'OPERATION_SEQ_NUM';
892             l_token_tbl(1).token_value :=  p_eam_op_rec.operation_seq_num;
893 
894             l_out_mesg_token_tbl  := l_mesg_token_tbl;
895             EAM_ERROR_MESSAGE_PVT.Add_Error_Token
896             (  p_message_name	=> 'EAM_OP_BACKFLUSH_REQUIRED'
897              , p_token_tbl		=> l_Token_tbl
898              , p_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
899              , x_Mesg_Token_Tbl	=> l_out_Mesg_Token_Tbl
900              );
901             l_mesg_token_tbl      := l_out_mesg_token_tbl;
902 
903             x_return_status := FND_API.G_RET_STS_ERROR;
904 
905         END IF;
906 
907         IF p_eam_op_rec.minimum_transfer_quantity IS NULL
908         THEN
909             l_token_tbl(1).token_name  := 'OPERATION_SEQ_NUM';
910             l_token_tbl(1).token_value :=  p_eam_op_rec.operation_seq_num;
911 
912             l_out_mesg_token_tbl  := l_mesg_token_tbl;
913             EAM_ERROR_MESSAGE_PVT.Add_Error_Token
914             (  p_message_name	=> 'EAM_OP_MIN_TRANS_QTY_REQUIRED'
915              , p_token_tbl		=> l_Token_tbl
916              , p_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
917              , x_Mesg_Token_Tbl	=> l_out_Mesg_Token_Tbl
918              );
919             l_mesg_token_tbl      := l_out_mesg_token_tbl;
920 
921             x_return_status := FND_API.G_RET_STS_ERROR;
922 
923         END IF;
924 
925 
926         x_Mesg_Token_Tbl := l_Mesg_Token_Tbl;
927 
928     END Check_Required;
929 
930     -- This procedure will check that after operation updatates,the depdendency in the operation depdendency network is valid
931     -- If the depdencdency fails then ,it throws an error
932 
933         PROCEDURE Check_Operation_Netwrok_Dates
934         (
935         p_api_version                   IN      NUMBER,
936         p_init_msg_list                 IN      VARCHAR2 := FND_API.G_FALSE,
937         p_commit                        IN      VARCHAR2 := FND_API.G_FALSE,
938         p_validation_level              IN      NUMBER  := FND_API.G_VALID_LEVEL_FULL,
939 
940         p_wip_entity_id                 IN      NUMBER,
941 
942         x_return_status                 OUT NOCOPY  VARCHAR2,
943 	x_pri_operation_no              OUT NOCOPY  NUMBER,
944 	x_next_operation_no             OUT NOCOPY  NUMBER
945         ) IS
946 
947        CURSOR l_op_network(l_wip_entity_id NUMBER) IS
948         SELECT
949 		won.prior_operation,won.next_operation,wo.last_unit_completion_date,wo1.first_unit_start_date
950 	FROM  wip_operation_networks won,wip_operations wo,wip_operations wo1
951 	WHERE won.wip_entity_id   = wo.wip_entity_id AND
952 	      won.wip_entity_id   = wo1.wip_entity_id AND
953 	      won.prior_operation = wo.operation_seq_num  AND
954 	      won.next_operation  = wo1.operation_seq_num  AND
955 	      won.wip_entity_id   =  l_wip_entity_id;
956 
957      BEGIN
958 
959        FOR l_opeation IN l_op_network (p_wip_entity_id)
960        LOOP
961 	 If l_opeation.last_unit_completion_date > l_opeation.first_unit_start_date THEN
962 		  x_return_status := FND_API.G_RET_STS_ERROR;
963 		  x_pri_operation_no := l_opeation.prior_operation;
964   		  x_next_operation_no := l_opeation.next_operation;
965 		  RETURN ;
966 	 End if;
967        END LOOP;
968 
969        x_return_status := FND_API.G_RET_STS_SUCCESS;
970 
971         EXCEPTION
972           when others then
973             x_return_status := FND_API.G_RET_STS_ERROR;
974             return;
975 
976      END Check_Operation_Netwrok_Dates;
977 
978  /*********************************************************************
979     * Procedure     : is_op_dept_change_allowed
980     * Parameters IN : Wip entity id operation sequence number
981     * Parameters OUT NOCOPY: Valication Flag
982     * Purpose       :
983     **********************************************************************/
984 
985 
986  FUNCTION is_op_dept_change_allowed(p_wip_entity_id NUMBER,   p_op_seq_num NUMBER) RETURN VARCHAR2 IS l_op_completed VARCHAR2(1);
987 l_q_issued NUMBER;
988 l_q_received NUMBER;
989 l_amount_delivered NUMBER;
990 l_charged_units NUMBER;
991 l_return VARCHAR2(1);
992 l_tx_count NUMBER;
993 BEGIN
994 
995   --1.Is Op Completed
996 
997   SELECT nvl(operation_completed,   'N')
998   INTO l_op_completed
999   FROM wip_operations
1000   WHERE wip_entity_id = p_wip_entity_id
1001    AND operation_seq_num = p_op_seq_num;
1002 
1003   IF l_op_completed = 'Y' THEN
1004     RETURN 'N';
1005   END IF;
1006 
1007   --2.Is Materail Tx Done
1008   --WIP_REQUIREMENT_OPERATIONS. quantity_issued > 0
1009   BEGIN
1010     SELECT nvl(sum(quantity_issued),   0)
1011     INTO l_q_issued
1012     FROM wip_requirement_operations
1013     WHERE wip_entity_id = p_wip_entity_id
1014      AND operation_seq_num = p_op_seq_num;
1015 
1016     IF l_q_issued > 0 THEN
1017       RETURN 'N';
1018     END IF;
1019 
1020   EXCEPTION
1021   WHEN no_data_found THEN
1022     l_return := 'Y';
1023   END;
1024 
1025 
1026   --3. Is Time charged on Operation
1027   BEGIN
1028 	  SELECT SUM(nvl(applied_resource_units,0))
1029 	  INTO l_charged_units
1030 	  FROM wip_operation_resources wor
1031 	  WHERE wip_entity_id = p_wip_entity_id
1032 	  AND operation_seq_num = p_op_seq_num;
1033 
1034 	  IF l_charged_units > 0 THEN
1035 	    RETURN 'N';
1036 	  END IF;
1037 
1038   EXCEPTION
1039 	  WHEN no_data_found THEN
1040 	    l_return := 'Y';
1041   END ;
1042 
1043   --3.Is non-stock material receipt Done
1044   --4.Is Direct material receipt  done
1045   --5.IS Out side processing (OSP) receipt done
1046   --EAM_WO_DIRECT_ITEMS_LITE_V. quantity_received > 0 or EAM_WO_DIRECT_ITEMS_LITE_V. amount_delivered > 0
1047   BEGIN
1048     SELECT nvl(sum(quantity_received),   0),
1049       nvl(sum(amount_delivered),   0)
1050     INTO l_q_received,
1051       l_amount_delivered
1052     FROM eam_wo_direct_items_lite_v
1053     WHERE wip_entity_id = p_wip_entity_id
1054      AND operation_seq_num = p_op_seq_num;
1055 
1056     IF l_q_received > 0 OR l_amount_delivered > 0 THEN
1057       RETURN 'N';
1058     END IF;
1059 
1060   EXCEPTION
1061   WHEN no_data_found THEN
1062     l_return := 'Y';
1063   END ;
1064   -- For checking resource transaction use wip_cost_txn_interface.
1065 
1066     select count(*)  into l_tx_count  from dual
1067                     where EXISTS (SELECT transaction_id FROM wip_cost_txn_interface
1068                                   WHERE wip_entity_id = p_wip_entity_id
1069                                   AND operation_seq_num = p_op_seq_num);
1070 
1071     IF l_tx_count > 0 THEN
1072       RETURN 'N';
1073     END IF;
1074     l_return := 'Y';
1075 
1076 
1077   RETURN l_return;
1078 
1079 EXCEPTION
1080 WHEN no_data_found THEN
1081   RETURN 'Y';
1082 END is_op_dept_change_allowed;
1083 
1084   /*********************************************************************
1085     * Procedure     : is_wo_dept_change_allowed
1086     * Parameters IN : Wip entity id
1087     * Parameters OUT NOCOPY: Valication Flag
1088     * Purpose       :
1089     **********************************************************************/
1090 
1091  FUNCTION is_wo_dept_change_allowed(x_wip_entity_id NUMBER) RETURN VARCHAR2 IS l_status NUMBER;
1092 BEGIN
1093 
1094 SELECT ewsv.SYSTEM_STATUS
1095   INTO l_status
1096   FROM EAM_WO_STATUSES_V ewsv
1097   WHERE ewsv.STATUS_ID = (SELECT ewod.user_defined_status_id
1098 			   FROM eam_work_order_details ewod
1099 			   WHERE ewod.wip_entity_id = x_wip_entity_id )  ;
1100 				--Changed for 14806418
1101 
1102   --Is WO status  in Draft(17), Un Released(1), Released(3), On Hold(6)
1103 
1104   IF l_status = 17 or l_status = 1 or l_status = 3 or l_status = 6 THEN
1105     RETURN 'Y';
1106   END IF;
1107 
1108   RETURN 'N';
1109 END is_wo_dept_change_allowed;
1110 
1111   /*********************************************************************
1112     * Procedure     : validate_dept_res
1113     * Parameters IN : Department ID Resource ID
1114     * Parameters OUT NOCOPY: Valication Flag
1115     * Purpose       :
1116     **********************************************************************/
1117 
1118 
1119  function validate_dept_res(p_dept_id number , p_res_code varchar2) return varchar2 is
1120 l_rowcount number := 0;
1121 begin
1122 select count(*) into l_rowcount from BOM_DEPARTMENT_RESOURCES_V where DEPARTMENT_ID=p_dept_id and RESOURCE_CODE=p_res_code;
1123 if(l_rowcount > 0) then
1124  return 'Y';
1125 end if;
1126 return 'N';
1127 end validate_dept_res;
1128  /*********************************************************************
1129     * Procedure     : validate_dept_res_instance
1130     * Parameters IN : Department Id Instance ID Resource ID
1131     * Parameters OUT NOCOPY: Valication Flag
1132     * Purpose       :
1133     **********************************************************************/
1134  function validate_dept_res_instance(p_dept_id number , p_inst_id number, p_res_id Number) return varchar2 is
1135 l_rowcount number := 0;
1136 begin
1137  select count(*)  into l_rowcount  from dual
1138                     where EXISTS (select ROW_ID from BOM_DEPT_RES_INSTANCES_EMP_V
1139 					where DEPARTMENT_ID=p_dept_id and INSTANCE_ID=p_inst_id and RESOURCE_ID=p_res_id);
1140 if(l_rowcount > 0) then
1141  return 'N';
1142 end if;
1143 return 'Y';
1144 end;
1145 
1146 
1147 
1148 END EAM_OP_VALIDATE_PVT;