[Home] [Help]
PACKAGE BODY: APPS.CSD_HV_WIP_JOB_PVT
Source
1 PACKAGE BODY CSD_HV_WIP_JOB_PVT as
2 /* $Header: csdvhvjb.pls 120.65.12020000.14 2013/04/10 01:08:37 takwong ship $ */
3 -- Start of Comments
4 -- Package name : CSD_HV_WIP_JOB_PVT
5 -- Purpose : This package is used for High Volume Repair Execution flow
6 --
7 --
8 -- History : 05/01/2005, Created by Shiv Ragunathan
9 -- History :
10 -- History :
11 -- NOTE :
12 -- End of Comments
13
14
15 -- Define Global Variable --
16 G_PKG_NAME CONSTANT VARCHAR2(30) := 'CSD_HV_WIP_JOB_PVT';
17
18 -- swai: bug 6995498/7182047 wrapper function to get the default item revision
19 -- Depending on the transaction type, check the corresponding profile option
20 -- and return null if the profile is No.
21 -- Transaction types are 'MAT_ISSUE' and 'JOB_COMP'. Passing null for
22 -- transaction type will always return a default from bom_revsions API.
23 FUNCTION get_default_item_revision
24 (
25 p_org_id IN NUMBER,
26 p_inventory_item_id IN NUMBER,
27 p_transaction_date IN DATE,
28 p_mat_transaction_type IN VARCHAR2 := null
29 ) RETURN VARCHAR2
30 IS
31 -- variables --
32 l_revision VARCHAR2(3) := null;
33 l_get_default VARCHAR2(1) := FND_API.G_TRUE;
34 BEGIN
35 if (p_mat_transaction_type = 'MAT_ISSUE') then -- material issue
36 --swai: bug 6654197 - allow user to specify revision based on profile option
37 if (nvl(fnd_profile.value('CSD_DEF_CUR_REVISION_MTL_TXN'), 'Y') = 'N' ) then
38 l_get_default := FND_API.G_FALSE;
39 end if;
40 elsif (p_mat_transaction_type = 'JOB_COMP') then -- job completion
41 -- swai: bug 6654197 - allow user to specify revision based on profile option
42 if (nvl(fnd_profile.value('CSD_DEF_CUR_REVISION_JOB_COMP'), 'Y') = 'N' ) then
43 l_get_default := FND_API.G_FALSE;
44 end if;
45 end if;
46 if (l_get_default = FND_API.G_TRUE) then
47 l_revision := bom_revisions.get_item_revision_fn
48 ('EXCLUDE_OPEN_HOLD', -- eco_status
49 'ALL', -- examine_type
50 p_org_id, -- org_id
51 p_inventory_item_id, -- item_id
52 p_transaction_date -- rev_date
53 ) ;
54 end if;
55 return l_revision;
56 END get_default_item_revision;
57
58 FUNCTION get_pending_quantity( p_wip_entity_id NUMBER,
59 p_operation_seq_num NUMBER,
60 p_resource_seq_num NUMBER,
61 p_primary_uom VARCHAR2 )
62 RETURN NUMBER IS
63
64
65 Cursor get_pending_qty_uom is
66 select wcti.transaction_quantity,
67 wcti.transaction_uom from
68 wip_cost_txn_interface wcti
69 where
70 wcti.wip_entity_id = p_wip_entity_id and
71 wcti.operation_seq_num = p_operation_seq_num and
72 wcti.resource_seq_num = p_resource_seq_num and
73 process_phase = 1 and
74 process_status = 1;
75
76 l_sum_pending_qty NUMBER := 0;
77 l_conversion_rate NUMBER;
78 l_primary_qty NUMBER;
79 BEGIN
80
81 FOR pending_qty_rec in get_pending_qty_uom
82 LOOP
83
84
85
86 l_conversion_rate :=
87 inv_convert.inv_um_convert(
88 item_id => 0,
89 precision => 38,
90 from_quantity => 1,
91 from_unit => p_primary_uom,
92 to_unit => pending_qty_rec.transaction_uom ,
93 from_name => NULL,
94 to_name => NULL);
95
96
97
98 -- perform UOM conversion
99 l_primary_qty := pending_qty_rec.transaction_quantity/l_conversion_rate;
100
101 l_sum_pending_qty := l_sum_pending_qty + l_primary_qty;
102
103 END LOOP;
104
105
106 RETURN l_sum_pending_qty;
107
108
109 END;
110
111
112 FUNCTION ml_error_exists( p_group_id NUMBER )
113 RETURN BOOLEAN IS
114
115 lc_error_process_status CONSTANT NUMBER := 3;
116
117
118 Cursor check_ml_interface_errors IS
119 select 'exists' from wip_job_schedule_interface where
120 group_id = p_group_id
121 and process_status = lc_error_process_status;
122
123 l_error_exists VARCHAR2(6);
124
125 BEGIN
126
127 open check_ml_interface_errors ;
128 fetch check_ml_interface_errors into l_error_exists;
129 close check_ml_interface_errors ;
130
131 If l_error_exists is null then
132 RETURN FALSE;
133 else
134 RETURN TRUE;
135 end if;
136
137 END;
138
139 FUNCTION txn_int_error_exists( p_transaction_header_id NUMBER )
140 RETURN BOOLEAN IS
141
142 lc_error_process_status CONSTANT NUMBER := 3;
143
144
145 Cursor check_txn_int_interface_errors IS
146 select 'exists' from mtl_transactions_interface where
147 transaction_header_id = p_transaction_header_id
148 and process_flag = lc_error_process_status;
149
150 -- yvchen: bug 13399147 - cursor to get the errors.
151 -- Currently, only gets the error explanation.
152 -- In the future, we may want to log the error_code
153 -- in the debug log, but this is simply the name of
154 -- procedure in which the error occured and is not
155 -- a user-friendly message that should be shown to
156 -- the user.
157 Cursor get_txn_interface_errors IS
158 SELECT error_explanation --,error_code
159 FROM mtl_transactions_interface mti
160 WHERE transaction_header_id = p_transaction_header_id
161 AND mti.process_flag = lc_error_process_status
162 AND mti.lock_flag = 2;
163
164 l_error_exists VARCHAR2(6);
165
166 BEGIN
167
168 open check_txn_int_interface_errors ;
169 fetch check_txn_int_interface_errors into l_error_exists;
170 close check_txn_int_interface_errors ;
171
172 If l_error_exists is null then
173 RETURN FALSE;
174 else
175 -- yvchen: bug 13399147 - if there are errors, get the errors
176 -- and put them in the message stack, since WIP and INV do
177 -- not log these errors in their debug logs
178 -- Commented this out for now, since code is untested. But
179 -- if customer runs into issues, we can uncomment this to
180 -- get additional error messages for debugging.
181
182 -- yvchen: bug 14050032
183 -- uncommented this code in order to show additional error
184 -- messages in the UI
185
186 FOR l_error in get_txn_interface_errors
187 LOOP
188 fnd_message.set_name('FND', 'FND_GENERIC_MESSAGE');
189 fnd_message.set_token('MESSAGE', l_error.error_explanation);
190 fnd_msg_pub.add;
191 END LOOP;
192
193 RETURN TRUE;
194 end if;
195
196 END;
197
198
199 -- this procedure adds any errors from the wip_interface_errors table
200 -- to the fnd_message stack.
201 -- assumption: each group has one type of transaction (op, material, resource)
202 --
203 PROCEDURE add_wip_interface_errors(p_group_id NUMBER, p_txn_type NUMBER) IS
204 -- CONSTANTS --
205 lc_txn_type_operations CONSTANT NUMBER := 1;
206 lc_txn_type_materials CONSTANT NUMBER := 2;
207 lc_txn_type_resources CONSTANT NUMBER := 3;
208
209 -- LOCAL VARIABLES --
210 l_resource_name VARCHAR2(10);
211 l_item_name VARCHAR2(10);
212
213 -- CURSORS --
214 Cursor c_wip_interface_errors is
215 select wie.error,
216 wie.error_type,
217 wie.error_type_meaning,
218 wjsi.wip_entity_id,
219 wjsi.organization_id,
220 we.wip_entity_name,
221 wjdi.operation_seq_num,
222 wjdi.inventory_item_id_new,
223 wjdi.resource_id_new
224 from
225 wip_interface_errors_v wie,
226 wip_job_schedule_interface wjsi,
227 wip_entities we,
228 wip_job_dtls_interface wjdi
229 where wie.interface_id = wjsi.interface_id
230 and we.wip_entity_id = wjsi.wip_entity_id
231 and wjsi.group_id = wjdi.group_id
232 and wjsi.group_id = p_group_id;
233
234 Cursor c_resource_name (p_resource_id_new number) is
235 select bom.resource_code
236 from bom_resources bom
237 where bom.resource_id = p_resource_id_new;
238
239 Cursor c_item_name (p_inventory_item_id_new number,
240 p_organization_id number) is
241 select mtl.concatenated_segments
242 from mtl_system_items_kfv mtl
243 where mtl.inventory_item_id = p_inventory_item_id_new
244 and mtl.organization_id = p_organization_id;
245 BEGIN
246
247 FOR wip_interface_rec in c_wip_interface_errors
248 LOOP
249 IF (p_txn_type = lc_txn_type_operations) THEN
250 FND_MESSAGE.SET_NAME('CSD','CSD_WIP_INTERFACE_OP_ERR');
251
252 ELSIF (p_txn_type = lc_txn_type_materials) THEN
253 FND_MESSAGE.SET_NAME('CSD','CSD_WIP_INTERFACE_MTL_ERR');
254 open c_item_name(wip_interface_rec.inventory_item_id_new,
255 wip_interface_rec.organization_id);
256 fetch c_item_name into l_item_name;
257 close c_item_name;
258 FND_MESSAGE.SET_TOKEN('ITEM_NAME', l_item_name);
259
260 ELSIF (p_txn_type = lc_txn_type_resources) THEN
261 FND_MESSAGE.SET_NAME('CSD','CSD_WIP_INTERFACE_RES_ERR');
262 open c_resource_name(wip_interface_rec.resource_id_new);
263 fetch c_resource_name into l_resource_name;
264 close c_resource_name;
265 FND_MESSAGE.SET_TOKEN('RES_NAME', l_resource_name);
266 END IF;
267
268 FND_MESSAGE.SET_TOKEN('JOB_NAME', wip_interface_rec.wip_entity_name);
269 FND_MESSAGE.SET_TOKEN('OP_SEQ', wip_interface_rec.operation_seq_num);
270 FND_MESSAGE.SET_TOKEN('ERROR_TYPE', wip_interface_rec.error_type_meaning);
271 FND_MESSAGE.SET_TOKEN('ERROR_MSG', wip_interface_rec.error);
272 FND_MSG_PUB.ADD;
273 END LOOP;
274 END add_wip_interface_errors;
275
276 -- This procedure checks if the specified Job name exists in the
277 -- specified organization. It checks if it exists in
278 -- wip_entities or wip_job_schedule_interface table.
279 -- If it exists, then an Error status is returned.
280 -- If it does not exist in either of the tables, then
281 -- a Sucess status is returned.
282 -- This procedure is used whenever a job_name is generated, to confirm that
283 -- the newly generated job_name does not already exist and hence can be
284 -- used to submit it to WIP Mass Load.
285
286
287 PROCEDURE validate_job_name
288 (
289 p_job_name IN VARCHAR2,
290 p_organization_id IN NUMBER,
291 x_return_status OUT NOCOPY VARCHAR2
292 )
293 IS
294
295 -- Used to check the existence of the Job_name for the specified organizization,
296 l_job_count NUMBER := 0;
297
298 BEGIN
299
300
301 Select count(*) into l_job_count from wip_entities where wip_entity_name = p_job_name and
302 organization_id = p_organization_id ;
303
304 If l_job_count = 0 Then
305
306 -- Job does not exist in WIP_entities, check if it is already inserted in the interface table by another
307 -- process and so may be in the process of getting into WIP.
308 -- If it exists, do not want to use this job name, so return Error
309
310 Select count(*) into l_job_count from wip_job_schedule_interface where job_name = p_job_name and
311 organization_id = p_organization_id ;
312
313 IF l_job_count = 0 THEN
314
315 -- Generated job name does exist either in the interface or wip_entities table,
316 -- Success is returned
317
318 x_return_status := FND_API.G_RET_STS_SUCCESS;
319 RETURN;
320
321 ELSE
322
323 -- Job exists in wip_job_schedule_interface table, hence return Error status
324
325 x_return_status := FND_API.G_RET_STS_ERROR;
326 RETURN;
327
328
329 END IF;
330
331
332 ELSE
333
334 -- Job exists in wip_entities table, hence return Error status
335
336 x_return_status := FND_API.G_RET_STS_ERROR;
337 RETURN;
338
339
340 END IF;
341
342
343
344 END validate_job_name;
345
346
347 -- This procedure generates a job name by appending a sequence generated number
348 -- to the passed in Job_Prefix
349 -- It Validates that the generated job name is unique for the specified organization,
350 -- It keeps looping and appending the subsequent sequence generated number, till a
351 -- unique Job name is generated
352
353
354 PROCEDURE generate_job_name
355 (
356 p_job_prefix IN VARCHAR2,
357 p_organization_id IN NUMBER,
358 x_job_name OUT NOCOPY VARCHAR2
359 )
360 IS
361
362 l_return_status VARCHAR2(1);
363
364 BEGIN
365
366 Loop
367
368 -- generate the Job Name by appending a sequence generated number to the passed in
369 -- job_prefix
370
371 Select p_job_prefix || TO_CHAR( CSD_JOB_NAME_S.NEXTVAL ) into
372 x_job_name From Dual;
373
374
375 -- Check if the job name generated is unique for the specified organization,
376 -- if not loop around till a unique job name is generated
377
378 Validate_job_name ( p_job_name => x_job_name,
379 p_organization_id => p_organization_id,
380 x_return_status => l_return_status ) ;
381
382 IF l_return_status = FND_API.G_RET_STS_SUCCESS THEN
383
384 -- Generated job name does not exist both in the interface and wip_entities table, so exit the loop
385
386 exit;
387
388 END IF;
389
390
391 End Loop;
392
393 END generate_job_name;
394
395
396 -- This procedure accepts job header, bills and routing information and inserts it into
397 -- WIP_JOB_SCHEDULE_INTERFACE table.
398
399 PROCEDURE insert_job_header
400 (
401 p_job_header_rec IN wip_job_schedule_interface%ROWTYPE,
402 x_return_status OUT NOCOPY VARCHAR2
403 )
404 IS
405
406 -- Job Record to hold the Job header, bills and routing information being inserted
407 -- into wip_job_schedule_interface
408
409 l_job_header_rec wip_job_schedule_interface%ROWTYPE := p_job_header_rec;
410
411
412 -- variables used for FND_LOG debug messages
413
414 l_debug_level NUMBER := FND_LOG.G_CURRENT_RUNTIME_LEVEL;
415 l_proc_level NUMBER := FND_LOG.LEVEL_PROCEDURE;
416 l_mod_name VARCHAR2(2000) := 'csd.plsql.csd_wip_job_pvt.insert_job_header.';
417
418
419 -- Constants Used for Inserting into wip_job_schedule_interface,
420 -- These are the values needed for WIP Mass Load to pick up the records
421
422 -- Indicates that the process Phase is Validation
423 lc_validation_phase CONSTANT NUMBER := 2;
424
425 -- Indicates that the process_status is Pending
426 lc_pending_status CONSTANT NUMBER := 1;
427
428 -- Source Code Value of 'Depot_Repair'
429 lc_depot_repair_source_code CONSTANT VARCHAR2(30) := 'DEPOT_REPAIR';
430
431 -- Depot repair Application Id passed as source_line_id
432 lc_depot_app_source_line_id CONSTANT NUMBER := 512;
433
434
435
436
437 BEGIN
438
439
440 IF ( l_proc_level >= l_debug_level ) then
441 FND_LOG.STRING( l_proc_level,
442 l_mod_name||'begin',
443 'Entering procedure insert_job_header' );
444 END IF;
445
446 x_return_status := FND_API.G_RET_STS_SUCCESS;
447
448
449 -- Populate the record l_job_header_rec
450
451
452 -- Populate the constant values
453
454 l_job_header_rec.process_phase := lc_validation_phase;
455 l_job_header_rec.process_status := lc_pending_status;
456 l_job_header_rec.source_code := lc_depot_repair_source_code;
457 l_job_header_rec.source_line_id := lc_depot_app_source_line_id ;
458
459
460 -- Populate the row who columns
461
462 l_job_header_rec.creation_date := SYSDATE;
463 l_job_header_rec.last_update_date := SYSDATE;
464 l_job_header_rec.created_by := fnd_global.user_id;
465 l_job_header_rec.last_updated_by := fnd_global.user_id;
466 l_job_header_rec.last_update_login := fnd_global.login_id;
467
468
469 --insert into table wip_job_schedule_interface
470 BEGIN
471 INSERT INTO wip_job_schedule_interface
472 (
473 wip_entity_id,
474 interface_id,
475 last_update_date,
476 last_updated_by,
477 creation_date,
478 created_by,
479 last_update_login,
480 load_type,
481 process_phase,
482 process_status,
483 group_id,
484 header_id,
485 source_code,
486 source_line_id,
487 job_name,
488 organization_id,
489 status_type,
490 first_unit_start_date,
491 last_unit_completion_date,
492 completion_subinventory,
493 completion_locator_id,
494 start_quantity,
495 net_quantity,
496 class_code,
497 primary_item_id,
498 bom_reference_id,
499 routing_reference_id,
500 alternate_routing_designator,
501 alternate_bom_designator,
502 project_id, --bug#13472453
503 task_id, --bug#13472453
504 end_item_unit_number --bug#13472453
505 )
506 VALUES
507 (
508 l_job_header_rec.wip_entity_id,
509 l_job_header_rec.interface_id,
510 l_job_header_rec.last_update_date,
511 l_job_header_rec.last_updated_by,
512 l_job_header_rec.creation_date,
513 l_job_header_rec.created_by,
514 l_job_header_rec.last_update_login,
515 l_job_header_rec.load_type,
516 l_job_header_rec.process_phase,
517 l_job_header_rec.process_status,
518 l_job_header_rec.group_id,
519 l_job_header_rec.header_id,
520 l_job_header_rec.source_code,
521 l_job_header_rec.source_line_id,
522 l_job_header_rec.job_name,
523 l_job_header_rec.organization_id,
524 l_job_header_rec.status_type,
525 l_job_header_rec.first_unit_start_date,
526 l_job_header_rec.last_unit_completion_date,
527 l_job_header_rec.completion_subinventory,
528 l_job_header_rec.completion_locator_id,
529 l_job_header_rec.start_quantity,
530 l_job_header_rec.net_quantity,
531 l_job_header_rec.class_code,
532 l_job_header_rec.primary_item_id,
533 l_job_header_rec.bom_reference_id,
534 l_job_header_rec.routing_reference_id,
535 l_job_header_rec.alternate_routing_designator,
536 l_job_header_rec.alternate_bom_designator,
537 l_job_header_rec.project_id, --bug#13472453
538 l_job_header_rec.task_id, --bug#13472453
539 l_job_header_rec.end_item_unit_number --bug#13472453
540 );
541 EXCEPTION
542 WHEN OTHERS THEN
543 FND_MESSAGE.SET_NAME('CSD','CSD_JOB_HEADER_INSERT_ERR');
544 FND_MESSAGE.SET_TOKEN('JOB_NAME', l_job_header_rec.job_name );
545 FND_MSG_PUB.ADD;
546 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
547 RETURN;
548 END;
549
550
551 IF ( l_proc_level >= l_debug_level ) then
552 FND_LOG.STRING( l_proc_level,
553 l_mod_name||'end',
554 'Leaving procedure insert_job_header');
555 END IF;
556
557
558 END insert_job_header;
559
560
561 -- This procedure accepts job details information and inserts it into
562 -- wip_job_dtls_interface table.
563
564 PROCEDURE insert_job_details
565 (
566 p_job_details_rec IN wip_job_dtls_interface%ROWTYPE,
567 x_return_status OUT NOCOPY VARCHAR2
568 )
569 IS
570
571 -- Job Record to hold the Job Details information being inserted
572 -- into wip_job_dtls_interface
573
574 l_job_details_rec wip_job_dtls_interface%ROWTYPE := p_job_details_rec;
575
576
577 -- variables used for FND_LOG debug messages
578
579 l_debug_level NUMBER := FND_LOG.G_CURRENT_RUNTIME_LEVEL;
580 l_proc_level NUMBER := FND_LOG.LEVEL_PROCEDURE;
581 l_mod_name VARCHAR2(2000) := 'csd.plsql.csd_wip_job_pvt.insert_job_header.';
582
583
584 -- Constants Used for Inserting into wip_job_schedule_interface,
585 -- These are the values needed for WIP Mass Load to pick up the records
586
587 -- Indicates that the process Phase is Validation
588 lc_validation_phase CONSTANT NUMBER := 2;
589
590 -- Indicates that the process_status is Pending
591 lc_pending_status CONSTANT NUMBER := 1;
592
593 -- lc_change_type CONSTANT NUMBER := 3;
594
595
596
597
598
599 BEGIN
600
601 -- dbms_output.put_line('Resource Seq Num is ' || l_job_details_rec.resource_seq_num );
602
603 -- dbms_output.put_line('usage_rate_or_amount is ' || l_job_details_rec.usage_rate_or_amount );
604
605 IF ( l_proc_level >= l_debug_level ) then
606 FND_LOG.STRING( l_proc_level,
607 l_mod_name||'begin',
608 'Entering procedure insert_job_details' );
609 END IF;
610
611 x_return_status := FND_API.G_RET_STS_SUCCESS;
612
613
614 -- Populate the record l_job_header_rec
615
616
617 -- Populate the constant values
618
619 l_job_details_rec.process_phase := lc_validation_phase;
620 l_job_details_rec.process_status := lc_pending_status;
621 -- l_job_details_rec.substitution_type := lc_change_type;
622
623 -- Populate the row who columns
624
625 l_job_details_rec.creation_date := SYSDATE;
626 l_job_details_rec.last_update_date := SYSDATE;
627 l_job_details_rec.created_by := fnd_global.user_id;
628 l_job_details_rec.last_updated_by := fnd_global.user_id;
629 l_job_details_rec.last_update_login := fnd_global.login_id;
630
631
632 BEGIN
633
634 INSERT INTO wip_job_dtls_interface
635 (last_updated_by,
636 last_update_date,
637 last_update_login,
638 created_by,
639 creation_date,
640 date_required,
641 start_date,
642 group_id,
643 parent_header_id,
644 inventory_item_id_old,
645 inventory_item_id_new,
646 resource_id_old,
647 resource_id_new,
648 resource_seq_num,
649 load_type,
650 mrp_net_flag,
651 operation_seq_num,
652 organization_id,
653 process_phase,
654 process_status,
655 -- quantity_issued,
656 quantity_per_assembly,
657 required_quantity,
658 uom_code,
659 usage_rate_or_amount,
660 assigned_units,
661 wip_entity_id,
662 wip_supply_type,
663 autocharge_type,
664 basis_type,
665 completion_date,
666 scheduled_flag,
667 standard_rate_flag,
668 substitution_type,
669 supply_subinventory,
670 supply_locator_id, --bug8465719
671 -- swai: add columns for operations
672 backflush_flag,
673 count_point_type,
674 department_id,
675 first_unit_completion_date,
676 first_unit_start_date,
677 last_unit_completion_date,
678 last_unit_start_date,
679 minimum_transfer_quantity,
680 standard_operation_id,
681 description
682 )
683 Values
684 (
685 l_job_details_rec.last_updated_by,
686 l_job_details_rec.last_update_date,
687 l_job_details_rec.last_update_login,
688 l_job_details_rec.created_by,
689 l_job_details_rec.creation_date, -- sysdate,
690 l_job_details_rec.date_required,
691 l_job_details_rec.start_date,
692 l_job_details_rec.group_id,
693 l_job_details_rec.parent_header_id,
694 l_job_details_rec.inventory_item_id_old,
695 l_job_details_rec.inventory_item_id_new, -- 'WIP Completion',
696 l_job_details_rec.resource_id_old,
697 l_job_details_rec.resource_id_new,
698 l_job_details_rec.resource_seq_num,
699 l_job_details_rec.load_type,
700 l_job_details_rec.mrp_net_flag,
701 l_job_details_rec.operation_seq_num,
702 l_job_details_rec.organization_id,
703 l_job_details_rec.process_phase,
704 l_job_details_rec.process_status,
705 -- l_job_details_rec.quantity_issued,
706 -- null,
707 l_job_details_rec.quantity_per_assembly,
708 l_job_details_rec.required_quantity,
709 l_job_details_rec.uom_code,
710 l_job_details_rec.usage_rate_or_amount,
711 l_job_details_rec.assigned_units,
712 l_job_details_rec.wip_entity_id,
713 l_job_details_rec.wip_supply_type,
714 l_job_details_rec.autocharge_type,
715 l_job_details_rec.basis_type,
716 l_job_details_rec.completion_date,
717 l_job_details_rec.scheduled_flag,
718 l_job_details_rec.standard_rate_flag,
719 l_job_details_rec.substitution_type,
720 l_job_details_rec.supply_subinventory,
721 l_job_details_rec.supply_locator_id, --bug#8465719
722 -- swai: add columns for operations
723 l_job_details_rec.backflush_flag,
724 l_job_details_rec.count_point_type,
725 l_job_details_rec.department_id,
726 l_job_details_rec.first_unit_completion_date,
727 l_job_details_rec.first_unit_start_date,
728 l_job_details_rec.last_unit_completion_date,
729 l_job_details_rec.last_unit_start_date,
730 l_job_details_rec.minimum_transfer_quantity,
731 l_job_details_rec.standard_operation_id,
732 l_job_details_rec.description
733 );
734
735
736 EXCEPTION
737 WHEN OTHERS THEN
738 FND_MESSAGE.SET_NAME('CSD','CSD_JOB_DETAILS_INSERT_ERR');
739 FND_MESSAGE.SET_TOKEN('JOB_NAME', l_job_details_rec.wip_entity_id);
740 FND_MSG_PUB.ADD;
741 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
742 RETURN;
743 END;
744
745
746 IF ( l_proc_level >= l_debug_level ) then
747 FND_LOG.STRING( l_proc_level,
748 l_mod_name||'end',
749 'Leaving procedure insert_job_details');
750 END IF;
751
752
753 END insert_job_details;
754
755
756 PROCEDURE insert_transactions_header
757 (
758 p_transactions_interface_rec IN mtl_transactions_interface%ROWTYPE,
759 x_return_status OUT NOCOPY VARCHAR2
760 )
761 IS
762
763 -- Job Record to hold the Job Details information being inserted
764 -- into wip_job_dtls_interface
765
766 l_transactions_interface_rec mtl_transactions_interface%ROWTYPE := p_transactions_interface_rec;
767
768
769 -- constant used for FND_LOG debug messages
770
771 lc_mod_name CONSTANT VARCHAR2(2000) := 'csd.plsql.csd_hv_wip_job_pvt.insert_transactions_header.';
772
773
774 -- Constants Used for Inserting into mtl_transactions_interface,
775
776 lc_concurrent_mode CONSTANT NUMBER := 1;
777 lc_yes_process_flag CONSTANT NUMBER := 1;
778
779
780
781
782 BEGIN
783
784
785 IF ( FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
786 FND_LOG.STRING( FND_LOG.LEVEL_PROCEDURE,
787 lc_mod_name||'begin',
788 'Entering procedure insert_transactions_header' );
789 END IF;
790
791 x_return_status := FND_API.G_RET_STS_SUCCESS;
792
793
794
795
796 -- Populate the constant values
797
798
799 l_transactions_interface_rec.transaction_mode := lc_concurrent_mode;
800 l_transactions_interface_rec.process_flag := lc_yes_process_flag;
801
802 -- Populate the row who columns
803
804 l_transactions_interface_rec.creation_date := SYSDATE;
805 l_transactions_interface_rec.last_update_date := SYSDATE;
806 l_transactions_interface_rec.created_by := fnd_global.user_id;
807 l_transactions_interface_rec.last_updated_by := fnd_global.user_id;
808 l_transactions_interface_rec.last_update_login := fnd_global.login_id;
809
810
811 --insert into table mtl_transactions_interface
812 BEGIN
813
814 INSERT INTO mtl_transactions_interface
815 (last_updated_by,
816 last_update_date,
817 last_update_login,
818 created_by,
819 creation_date,
820 transaction_header_id,
821 source_code,
822 completion_transaction_id,
823 inventory_item_id,
824 subinventory_code,
825 locator_id,
826 transaction_quantity,
827 transaction_uom,
828 primary_quantity,
829 transaction_date,
830 organization_id,
831 transaction_source_id,
832 transaction_source_type_id,
833 transaction_type_id,
834 wip_entity_type,
835 operation_seq_num,
836 revision,
837 transaction_mode,
838 process_flag,
839 source_header_id,
840 source_line_id,
841 transaction_interface_id,
842 reason_id, -- swai: bug 6841113
843 final_completion_flag
844 )
845 Values
846 (
847 l_transactions_interface_rec.last_updated_by,
848 l_transactions_interface_rec.last_update_date,
849 l_transactions_interface_rec.last_update_login,
850 l_transactions_interface_rec.created_by,
851 l_transactions_interface_rec.creation_date, -- sysdate,
852 l_transactions_interface_rec.transaction_header_id,
853 l_transactions_interface_rec.source_code, -- 'WIP Issue',
854 l_transactions_interface_rec.completion_transaction_id,
855 l_transactions_interface_rec.inventory_item_id, --8229,
856 l_transactions_interface_rec.subinventory_code,
857 l_transactions_interface_rec.locator_id,
858 l_transactions_interface_rec.transaction_quantity, -- 1,
859 l_transactions_interface_rec.transaction_uom, --'Ea',
860 l_transactions_interface_rec.primary_quantity, -- 1,
861 l_transactions_interface_rec.transaction_date, -- sysdate,
862 l_transactions_interface_rec.organization_id, --207,
863 l_transactions_interface_rec.transaction_source_id, --124743,
864 l_transactions_interface_rec.transaction_source_type_id, -- 5,
865 l_transactions_interface_rec.transaction_type_id, -- 35,
866 l_transactions_interface_rec.wip_entity_type, -- 3,
867 l_transactions_interface_rec.operation_seq_num,
868 l_transactions_interface_rec.revision, --null, -- ,
869 l_transactions_interface_rec.transaction_mode,
870 l_transactions_interface_rec.process_flag,
871 l_transactions_interface_rec.source_header_id, -- 124743, -- ,
872 l_transactions_interface_rec.source_line_id, -- -1, --10,
873 l_transactions_interface_rec.transaction_interface_id, -- null, -- mtl_material_transactions_s.nextval, --l_transaction_interface_id,
874 l_transactions_interface_rec.reason_id, -- swai: bug 6841113
875 l_transactions_interface_rec.final_completion_flag ); -- 'N' ) ;
876
877
878
879 EXCEPTION
880 WHEN OTHERS THEN
881 FND_MESSAGE.SET_NAME('CSD','CSD_TXNS_HEADER_INSERT_ERR');
882 FND_MESSAGE.SET_TOKEN('JOB_NAME', l_transactions_interface_rec.transaction_source_id );
883 FND_MSG_PUB.ADD;
884 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
885 RETURN;
886 END;
887
888
889
890 IF ( FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
891 FND_LOG.STRING( FND_LOG.LEVEL_PROCEDURE,
892 lc_mod_name||'end',
893 'Leaving procedure insert_transactions_header');
894 END IF;
895
896
897 END insert_transactions_header;
898
899
900 PROCEDURE update_transactions_header
901 (
902 p_transactions_interface_rec IN mtl_transactions_interface%ROWTYPE,
903 x_return_status OUT NOCOPY VARCHAR2
904 )
905 IS
906
907
908
909 -- constant used for FND_LOG debug messages
910
911 lc_mod_name CONSTANT VARCHAR2(2000) := 'csd.plsql.csd_hv_wip_job_pvt.update_transactions_header.';
912
913
914
915
916 BEGIN
917
918
919 IF ( FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
920 FND_LOG.STRING( FND_LOG.LEVEL_PROCEDURE,
921 lc_mod_name||'begin',
922 'Entering procedure update_transactions_header' );
923 END IF;
924
925 x_return_status := FND_API.G_RET_STS_SUCCESS;
926
927
928
929 --update table mtl_transactions_interface
930 BEGIN
931
932 /* dbms_output.put_line( 'p_transactions_interface_rec.transaction_interface_id is ' ||
933 p_transactions_interface_rec.transaction_interface_id ); */
934
935 UPDATE mtl_transactions_interface
936 SET
937 subinventory_code = p_transactions_interface_rec.subinventory_code,
938 locator_id = p_transactions_interface_rec.locator_id,
939 revision = p_transactions_interface_rec.revision,
940 reason_id = p_transactions_interface_rec.reason_id -- swai: bug 6841113
941 where
942 transaction_interface_id = p_transactions_interface_rec.transaction_interface_id;
943
944
945
946 EXCEPTION
947 WHEN OTHERS THEN
948 FND_MESSAGE.SET_NAME('CSD','CSD_TXNS_HEADER_UPDATE_ERR');
949 FND_MSG_PUB.ADD;
950 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
951 RETURN;
952 END;
953
954
955
956 IF ( FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
957 FND_LOG.STRING( FND_LOG.LEVEL_PROCEDURE,
958 lc_mod_name||'end',
959 'Leaving procedure update_transactions_header');
960 END IF;
961
962
963 END update_transactions_header;
964
965
966 PROCEDURE insert_transaction_lots
967 (
968 p_txn_lots_interface_rec IN mtl_transaction_lots_interface%ROWTYPE,
969 x_return_status OUT NOCOPY VARCHAR2
970 )
971 IS
972
973
974 -- constant used for FND_LOG debug messages
975
976 lc_mod_name CONSTANT VARCHAR2(2000) := 'csd.plsql.csd_hv_wip_job_pvt.insert_transaction_lots';
977
978
979 l_creation_date DATE;
980 l_last_update_date DATE;
981 l_created_by NUMBER;
982 l_last_updated_by NUMBER;
983 l_last_updated_by_name VARCHAR2(100);
984 l_last_update_login NUMBER;
985
986 BEGIN
987
988
989 IF ( FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
990 FND_LOG.STRING( FND_LOG.LEVEL_PROCEDURE,
991 lc_mod_name||'begin',
992 'Entering procedure insert_transaction_lots' );
993 END IF;
994
995 x_return_status := FND_API.G_RET_STS_SUCCESS;
996
997
998 -- Populate the row who columns
999
1000 l_creation_date := SYSDATE;
1001 l_last_update_date := SYSDATE;
1002 l_created_by := fnd_global.user_id;
1003 l_last_updated_by := fnd_global.user_id;
1004 l_last_update_login := fnd_global.login_id;
1005
1006
1007 --insert into table mtl_transactions_interface
1008 BEGIN
1009
1010 INSERT INTO mtl_transaction_lots_interface
1011 (last_updated_by,
1012 last_update_date,
1013 last_update_login,
1014 created_by,
1015 creation_date,
1016 transaction_interface_id,
1017 lot_number,
1018 transaction_quantity,
1019 serial_transaction_temp_id
1020 )
1021 Values
1022 (
1023 l_last_updated_by,
1024 l_last_update_date,
1025 l_last_update_login,
1026 l_created_by,
1027 l_creation_date, -- sysdate,
1028 p_txn_lots_interface_rec.transaction_interface_id,
1029 p_txn_lots_interface_rec.lot_number,
1030 p_txn_lots_interface_rec.transaction_quantity,
1031 p_txn_lots_interface_rec.serial_transaction_temp_id
1032 ); -- 'N' ) ;
1033
1034
1035 EXCEPTION
1036 WHEN OTHERS THEN
1037 FND_MESSAGE.SET_NAME('CSD','CSD_TXN_LOTS_INSERT_ERR');
1038 FND_MSG_PUB.ADD;
1039 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1040 RETURN;
1041 END;
1042
1043
1044
1045 IF ( FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
1046 FND_LOG.STRING( FND_LOG.LEVEL_PROCEDURE,
1047 lc_mod_name||'end',
1048 'Leaving procedure insert_transaction_lots');
1049 END IF;
1050
1051
1052 END insert_transaction_lots;
1053
1054
1055 PROCEDURE insert_upd_serial_numbers
1056 (
1057 p_srl_nmbrs_interface_rec IN mtl_serial_numbers_interface%ROWTYPE,
1058 x_return_status OUT NOCOPY VARCHAR2
1059 )
1060 IS
1061
1062
1063 -- constant used for FND_LOG debug messages
1064
1065 lc_mod_name CONSTANT VARCHAR2(2000) := 'csd.plsql.csd_hv_wip_job_pvt.insert_upd_serial_numbers.';
1066
1067
1068 l_creation_date DATE;
1069 l_last_update_date DATE;
1070 l_created_by NUMBER;
1071 l_last_updated_by NUMBER;
1072 l_last_updated_by_name VARCHAR2(100);
1073 l_last_update_login NUMBER;
1074 l_row_exists NUMBER := 0;
1075
1076 BEGIN
1077
1078
1079 IF ( FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
1080 FND_LOG.STRING( FND_LOG.LEVEL_PROCEDURE,
1081 lc_mod_name||'begin',
1082 'Entering procedure insert_upd_serial_numbers' );
1083 END IF;
1084
1085 x_return_status := FND_API.G_RET_STS_SUCCESS;
1086
1087 Select count(*) into l_row_exists from mtl_serial_numbers_interface
1088 where transaction_interface_id =
1089 p_srl_nmbrs_interface_rec.transaction_interface_id;
1090
1091 IF l_row_exists = 1 THEN
1092
1093 BEGIN
1094
1095 UPDATE mtl_serial_numbers_interface
1096 SET
1097 fm_serial_number = p_srl_nmbrs_interface_rec.fm_serial_number
1098 where transaction_interface_id =
1099 p_srl_nmbrs_interface_rec.transaction_interface_id;
1100
1101 EXCEPTION
1102 WHEN OTHERS THEN
1103 FND_MESSAGE.SET_NAME('CSD','CSD_SRL_NMBRS_UPDATE_ERR');
1104 FND_MSG_PUB.ADD;
1105 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1106 RETURN;
1107 END;
1108
1109 ELSE
1110
1111 -- Populate the row who columns
1112
1113 l_creation_date := SYSDATE;
1114 l_last_update_date := SYSDATE;
1115 l_created_by := fnd_global.user_id;
1116 l_last_updated_by := fnd_global.user_id;
1117 l_last_update_login := fnd_global.login_id;
1118
1119
1120 --insert into table mtl_transactions_interface
1121 BEGIN
1122
1123 INSERT INTO mtl_serial_numbers_interface
1124 ( last_updated_by,
1125 last_update_date,
1126 last_update_login,
1127 created_by,
1128 creation_date,
1129 transaction_interface_id,
1130 fm_serial_number
1131 )
1132 Values
1133 (
1134 l_last_updated_by,
1135 l_last_update_date,
1136 l_last_update_login,
1137 l_created_by,
1138 l_creation_date, -- sysdate,
1139 p_srl_nmbrs_interface_rec.transaction_interface_id,
1140 p_srl_nmbrs_interface_rec.fm_serial_number
1141 ); -- 'N' ) ;
1142
1143
1144 EXCEPTION
1145 WHEN OTHERS THEN
1146 FND_MESSAGE.SET_NAME('CSD','CSD_SRL_NMBRS_INSERT_ERR');
1147 FND_MSG_PUB.ADD;
1148 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1149 RETURN;
1150 END;
1151
1152 END IF;
1153
1154 IF ( FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
1155 FND_LOG.STRING( FND_LOG.LEVEL_PROCEDURE,
1156 lc_mod_name||'end',
1157 'Leaving procedure insert_upd_serial_numbers');
1158 END IF;
1159
1160
1161 END insert_upd_serial_numbers;
1162
1163
1164 PROCEDURE insert_wip_cost_txn
1165 (
1166 p_wip_cost_txn_interface_rec IN wip_cost_txn_interface%ROWTYPE,
1167 x_return_status OUT NOCOPY VARCHAR2
1168 )
1169 IS
1170
1171
1172
1173 -- constant used for FND_LOG debug messages
1174
1175 lc_mod_name CONSTANT VARCHAR2(2000) := 'csd.plsql.csd_hv_wip_job_pvt.insert_transactions_header.';
1176
1177
1178 -- Constants Used for Inserting into mtl_transactions_interface,
1179
1180 lc_concurrent_mode CONSTANT NUMBER := 1;
1181 lc_yes_process_flag CONSTANT NUMBER := 1;
1182
1183 lc_res_validation_phase CONSTANT NUMBER := 1;
1184 lc_res_pending_status CONSTANT NUMBER := 1;
1185 lc_discrete_entity_type CONSTANT NUMBER := 1;
1186
1187
1188 l_creation_date DATE;
1189 l_last_update_date DATE;
1190 l_created_by_name VARCHAr2(100);
1191 l_last_updated_by NUMBER;
1192 l_last_updated_by_name VARCHAR2(100);
1193 l_last_update_login NUMBER;
1194 l_process_phase NUMBER;
1195 l_process_status NUMBER;
1196 l_entity_type NUMBER;
1197
1198
1199
1200 BEGIN
1201
1202
1203 IF ( FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
1204 FND_LOG.STRING( FND_LOG.LEVEL_PROCEDURE,
1205 lc_mod_name||'begin',
1206 'Entering procedure insert_wip_cost_txn' );
1207 END IF;
1208
1209 x_return_status := FND_API.G_RET_STS_SUCCESS;
1210
1211
1212 -- Populate the constant values
1213
1214
1215 l_process_phase := lc_res_validation_phase;
1216 l_process_status := lc_res_pending_status;
1217 l_entity_type := lc_discrete_entity_type;
1218
1219 -- Populate the row who columns
1220
1221 l_creation_date := SYSDATE;
1222 l_last_update_date := SYSDATE;
1223 l_created_by_name := fnd_global.user_name;
1224 l_last_updated_by := fnd_global.user_id;
1225 l_last_updated_by_name := fnd_global.user_name;
1226 l_last_update_login := fnd_global.login_id;
1227
1228
1229 --insert into table wip_cost_txn_interface
1230 BEGIN
1231
1232 INSERT INTO wip_cost_txn_interface
1233 (last_updated_by_name,
1234 last_updated_by,
1235 last_update_date,
1236 last_update_login,
1237 created_by_name,
1238 creation_date,
1239 operation_seq_num,
1240 organization_id,
1241 organization_code,
1242 process_phase,
1243 process_status,
1244 resource_seq_num,
1245 transaction_date,
1246 transaction_quantity,
1247 transaction_type,
1248 transaction_uom,
1249 wip_entity_name,
1250 wip_entity_id,
1251 employee_id,
1252 employee_num,
1253 entity_type
1254 )
1255 Values
1256 (
1257 l_last_updated_by_name,
1258 l_last_updated_by,
1259 l_last_update_date,
1260 l_last_update_login,
1261 l_created_by_name,
1262 l_creation_date, -- sysdate,
1263 p_wip_cost_txn_interface_rec.operation_seq_num,
1264 p_wip_cost_txn_interface_rec.organization_id,
1265 p_wip_cost_txn_interface_rec.organization_code,
1266 l_process_phase,
1267 l_process_status,
1268 p_wip_cost_txn_interface_rec.resource_seq_num,
1269 p_wip_cost_txn_interface_rec.transaction_date,
1270 p_wip_cost_txn_interface_rec.transaction_quantity,
1271 p_wip_cost_txn_interface_rec.transaction_type,
1272 p_wip_cost_txn_interface_rec.transaction_uom,
1273 p_wip_cost_txn_interface_rec.wip_entity_name,
1274 p_wip_cost_txn_interface_rec.wip_entity_id,
1275 p_wip_cost_txn_interface_rec.employee_id,
1276 p_wip_cost_txn_interface_rec.employee_num,
1277 l_entity_type
1278 ) ;
1279
1280
1281 EXCEPTION
1282 WHEN OTHERS THEN
1283 FND_MESSAGE.SET_NAME('CSD','CSD_WIP_COST_TXN_INSERT_ERR');
1284 FND_MSG_PUB.ADD;
1285 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1286 RETURN;
1287
1288 END;
1289
1290
1291 IF ( FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
1292 FND_LOG.STRING( FND_LOG.LEVEL_PROCEDURE,
1293 lc_mod_name||'end',
1294 'Leaving procedure insert_transactions_header');
1295 END IF;
1296
1297
1298 END insert_wip_cost_txn;
1299
1300
1301 PROCEDURE insert_wip_move_txn
1302 (
1303 p_wip_move_txn_interface_rec IN wip_move_txn_interface%ROWTYPE,
1304 x_return_status OUT NOCOPY VARCHAR2
1305 )
1306 IS
1307
1308
1309
1310 -- constant used for FND_LOG debug messages
1311
1312 lc_mod_name CONSTANT VARCHAR2(2000) := 'csd.plsql.csd_hv_wip_job_pvt.insert_wip_move_txn';
1313
1314
1315 -- Indicates that the process Phase is Validation
1316 lc_validation_phase CONSTANT NUMBER := 1;
1317
1318
1319 -- Indicates that the process_status is Running
1320 lc_running_status CONSTANT NUMBER := 2;
1321
1322
1323 l_creation_date DATE;
1324 l_last_update_date DATE;
1325 l_created_by NUMBER;
1326 l_last_updated_by NUMBER;
1327 l_last_updated_by_name VARCHAR2(100);
1328 l_created_by_name VARCHAR2(100);
1329 l_last_update_login NUMBER;
1330 l_process_phase NUMBER;
1331 l_process_status NUMBER;
1332
1333
1334
1335 BEGIN
1336
1337
1338 IF ( FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
1339 FND_LOG.STRING( FND_LOG.LEVEL_PROCEDURE,
1340 lc_mod_name||'begin',
1341 'Entering procedure insert_wip_move_txn' );
1342 END IF;
1343
1344 x_return_status := FND_API.G_RET_STS_SUCCESS;
1345
1346
1347 -- Populate the constant values
1348
1349
1350 l_process_phase := lc_validation_phase;
1351 l_process_status := lc_running_status;
1352
1353 -- Populate the row who columns
1354
1355 l_creation_date := SYSDATE;
1356 l_last_update_date := SYSDATE;
1357 l_created_by := fnd_global.user_id;
1358 l_created_by_name := fnd_global.user_name;
1359 l_last_updated_by := fnd_global.user_id;
1360 l_last_updated_by_name := fnd_global.user_name;
1361 l_last_update_login := fnd_global.login_id;
1362
1363
1364
1365 --insert into table wip_move_txn_interface
1366 BEGIN
1367 insert into wip_move_txn_interface(
1368 transaction_id,
1369 last_update_date,
1370 last_updated_by,
1371 last_updated_by_name,
1372 creation_date,
1373 created_by,
1374 created_by_name,
1375 group_id,
1376 process_phase,
1377 process_status,
1378 organization_id,
1379 wip_entity_name,
1380 transaction_date,
1381 fm_operation_seq_num,
1382 fm_intraoperation_step_type,
1383 to_operation_seq_num,
1384 to_intraoperation_step_type,
1385 transaction_quantity,
1386 transaction_uom
1387 ) values (
1388 p_wip_move_txn_interface_rec.transaction_id,
1389 l_last_update_date, /* last_update_date */
1390 l_last_updated_by, /* last_updated_by */
1391 l_last_updated_by_name, /* last_updated_by_name */
1392 l_creation_date, /* creation_date */
1393 l_created_by, /* created_by */
1394 l_created_by_name, /* created_by_name */
1395 p_wip_move_txn_interface_rec.group_id, /* group_id */
1396 l_process_phase, /* process phase */
1397 l_process_status, /* process status */
1398 p_wip_move_txn_interface_rec.organization_id,
1399 p_wip_move_txn_interface_rec.wip_entity_name,
1400 p_wip_move_txn_interface_rec.transaction_date,
1401 p_wip_move_txn_interface_rec.fm_operation_seq_num,
1402 p_wip_move_txn_interface_rec.fm_intraoperation_step_type,
1403 p_wip_move_txn_interface_rec.to_operation_seq_num,
1404 p_wip_move_txn_interface_rec.to_intraoperation_step_type,
1405 p_wip_move_txn_interface_rec.transaction_quantity,
1406 p_wip_move_txn_interface_rec.transaction_uom
1407 );
1408
1409
1410 EXCEPTION
1411 WHEN OTHERS THEN
1412 FND_MESSAGE.SET_NAME('CSD','CSD_WIP_MOVE_TXN_INSERT_ERR');
1413 FND_MSG_PUB.ADD;
1414 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1415 RETURN;
1416
1417 END;
1418
1419
1420 IF ( FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
1421 FND_LOG.STRING( FND_LOG.LEVEL_PROCEDURE,
1422 lc_mod_name||'end',
1423 'Leaving procedure insert_wip_move_txn');
1424 END IF;
1425
1426
1427 END insert_wip_move_txn;
1428
1429 -- private routine.
1430 -- Inserts into costing interface table for average costing method.
1431 -- Bug#9453092, subhat
1432 PROCEDURE insert_cst_interface(p_wip_entity_id IN NUMBER,
1433 p_interface_id IN NUMBER
1434 )
1435 IS
1436 BEGIN
1437 INSERT INTO cst_comp_snap_interface
1438 ( created_by,
1439 creation_date,
1440 last_update_date,
1441 last_update_login,
1442 last_updated_by,
1443 OPERATION_SEQ_NUM,
1444 quantity_completed,
1445 transaction_interface_id,
1446 wip_entity_id,
1447 primary_quantity
1448 )
1449 SELECT
1450 fnd_global.user_id,
1451 SYSDATE,
1452 SYSDATE,
1453 fnd_global.login_id,
1454 fnd_global.user_id,
1455 operation_seq_num,
1456 quantity_completed,
1457 p_interface_id,
1458 p_wip_entity_id,
1459 quantity_completed
1460 FROM wip_operations wo
1461 WHERE wo.wip_entity_id = p_wip_entity_id;
1462
1463 END insert_cst_interface;
1464
1465 -- begin swai: bug 13820264, FP of bug#13797285, subhat
1466 PROCEDURE handle_missing_mat_rqmts
1467 (
1468 p_repair_line_id IN NUMBER DEFAULT NULL,
1469 p_wip_entity_id IN NUMBER DEFAULT NULL,
1470 p_start_txn_date IN DATE DEFAULT NULL,
1471 p_end_txn_date IN DATE DEFAULT NULL
1472 );
1473
1474 PROCEDURE handle_missing_mat_rqmts
1475 (
1476 p_repair_line_id IN NUMBER DEFAULT NULL,
1477 p_wip_entity_id IN NUMBER DEFAULT NULL,
1478 p_start_txn_date IN DATE DEFAULT NULL,
1479 p_end_txn_date IN DATE DEFAULT NULL
1480 )
1481 IS
1482 l_wip_transaction_ids JTF_NUMBER_TABLE := JTF_NUMBER_TABLE();
1483 l_quantities JTF_NUMBER_TABLE := JTF_NUMBER_TABLE();
1484 l_inventory_item_ids JTF_NUMBER_TABLE := JTF_NUMBER_TABLE();
1485 l_operation_seq_nums JTF_NUMBER_TABLE := JTF_NUMBER_TABLE();
1486 l_transaction_uoms JTF_VARCHAR2_TABLE_100 := JTF_VARCHAR2_TABLE_100();
1487 BEGIN
1488 IF p_repair_line_id IS NOT NULL
1489 THEN
1490
1491 INSERT INTO csd_wip_transaction_details
1492 (wip_transaction_detail_id,inventory_item_id,
1493 wip_entity_id,operation_seq_num,
1494 object_version_number,
1495 last_update_login,created_by,
1496 creation_date,last_updated_by,
1497 last_update_date)
1498 SELECT csd_wip_transaction_details_s1.nextval,t.*
1499 FROM (
1500 SELECT
1501 wro.inventory_item_id,
1502 wro.wip_entity_id,
1503 wro.operation_seq_num,
1504 to_number('1'),
1505 fnd_global.login_id,
1506 fnd_global.user_id created_by,
1507 sysdate creation_date,
1508 fnd_global.user_id last_updated_by,
1509 sysdate last_update_date
1510 FROM csd_repair_job_xref crj,wip_requirement_operations wro
1511 WHERE crj.wip_entity_id = wro.wip_entity_id
1512 AND crj.repair_line_id = p_repair_line_id
1513 AND NOT EXISTS (SELECT 'exists'
1514 FROM csd_wip_transaction_details cwt
1515 WHERE cwt.wip_entity_id = wro.wip_entity_id
1516 AND cwt.operation_seq_num = wro.operation_seq_num
1517 AND cwt.inventory_item_id = wro.inventory_item_id
1518 )
1519 )t;
1520
1521
1522
1523 ELSIF p_wip_entity_id IS NOT NULL
1524 THEN
1525 -- regular issue.
1526 INSERT INTO csd_wip_transaction_details
1527 (wip_transaction_detail_id,inventory_item_id,
1528 wip_entity_id,operation_seq_num,
1529 object_version_number,
1530 last_update_login,created_by,
1531 creation_date,last_updated_by,
1532 last_update_date)
1533 SELECT csd_wip_transaction_details_s1.nextval,t.*
1534 FROM (
1535 SELECT wro.inventory_item_id,
1536 wro.wip_entity_id,
1537 wro.operation_seq_num,
1538 to_number('1'),
1539 fnd_global.login_id,
1540 fnd_global.user_id created_by,
1541 sysdate creation_date,
1542 fnd_global.user_id last_updated_by,
1543 sysdate last_update_date
1544 FROM wip_requirement_operations wro
1545 WHERE wro.wip_entity_id = p_wip_entity_id
1546 AND NOT EXISTS (SELECT 'exists'
1547 FROM csd_wip_transaction_details cwt
1548 WHERE cwt.wip_entity_id = wro.wip_entity_id
1549 AND cwt.operation_seq_num = wro.operation_seq_num
1550 AND cwt.inventory_item_id = wro.inventory_item_id
1551 )
1552 ) t;
1553
1554 ELSE
1555
1556 INSERT INTO csd_wip_transaction_details
1557 (wip_transaction_detail_id,inventory_item_id,
1558 wip_entity_id,operation_seq_num,
1559 object_version_number,
1560 last_update_login,created_by,
1561 creation_date,last_updated_by,
1562 last_update_date)
1563 SELECT csd_wip_transaction_details_s1.nextval,t.*
1564 FROM (
1565 SELECT wro.inventory_item_id,
1566 wro.wip_entity_id,
1567 wro.operation_seq_num,
1568 to_number('1'),
1569 fnd_global.login_id,
1570 fnd_global.user_id created_by,
1571 sysdate creation_date,
1572 fnd_global.user_id last_updated_by,
1573 sysdate last_update_date
1574 FROM wip_requirement_operations wro,csd_repair_job_xref crj
1575 WHERE crj.wip_entity_id = wro.wip_entity_id
1576 AND NOT EXISTS (SELECT 'exists'
1577 FROM csd_wip_transaction_details cwt
1578 WHERE cwt.wip_entity_id = wro.wip_entity_id
1579 AND cwt.operation_seq_num = wro.operation_seq_num
1580 AND cwt.inventory_item_id = wro.inventory_item_id
1581 )
1582 ) t;
1583 END IF;
1584 END handle_missing_mat_rqmts;
1585 -- end swai: bug 13820264, FP of bug#13797285, subhat
1586
1587
1588 --
1589 -- Inserts the transaction line(s) for job completion and then
1590 -- processes the transaction lines if there are no details needed
1591 -- OUT param:
1592 -- x_transaction_header_id: If details are needed, the transaction
1593 -- header ID will be populated. Otherwise
1594 -- parameter is null.
1595 --
1596 PROCEDURE process_job_comp_txn
1597 (
1598 p_api_version_number IN NUMBER,
1599 p_init_msg_list IN VARCHAR2 ,
1600 p_commit IN VARCHAR2 ,
1601 p_validation_level IN NUMBER,
1602 x_return_status OUT NOCOPY VARCHAR2,
1603 x_msg_count OUT NOCOPY NUMBER,
1604 x_msg_data OUT NOCOPY VARCHAR2,
1605 p_comp_job_dtls_rec IN JOB_DTLS_REC_TYPE,
1606 x_transaction_header_id OUT NOCOPY NUMBER
1607 )
1608 IS
1609 lc_api_name CONSTANT VARCHAR2(30) := 'PROCESS_JOB_COMP_TXN';
1610 lc_api_version_number CONSTANT NUMBER := 1.0;
1611
1612 -- constants used for FND_LOG debug messages
1613 lc_mod_name VARCHAR2(2000) := 'csd.plsql.csd_hv_wip_job_pvt.process_job_comp_txn';
1614
1615 l_need_details_flag VARCHAR2(1) := 'F';
1616 l_transaction_header_id NUMBER;
1617
1618 BEGIN
1619 IF ( FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
1620 FND_LOG.STRING( FND_LOG.LEVEL_PROCEDURE,
1621 lc_mod_name||'begin',
1622 'Entering private API process_job_comp_txn' );
1623 END IF;
1624
1625 SAVEPOINT PROCESS_JOB_COMP_TXN_PVT;
1626
1627 -- Standard call to check for call compatibility.
1628 IF NOT FND_API.Compatible_API_Call(lc_api_version_number,
1629 p_api_version_number,
1630 lc_api_name,
1631 G_PKG_NAME) THEN
1632 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1633 END IF;
1634
1635 IF FND_API.to_boolean(p_init_msg_list) THEN
1636 FND_MSG_PUB.initialize;
1637 END IF;
1638
1639 x_return_status := FND_API.G_RET_STS_SUCCESS;
1640
1641 IF ( FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
1642 FND_LOG.STRING( FND_LOG.LEVEL_EVENT,
1643 lc_mod_name||'beforecallinsertjobcomptxn',
1644 'Just before calling insert_job_comp_txn');
1645 END IF;
1646 insert_job_comp_txn (
1647 p_api_version_number => lc_api_version_number,
1648 p_init_msg_list => fnd_api.g_false ,
1649 p_commit => fnd_api.g_false,
1650 p_validation_level => p_validation_level,
1651 x_return_status => x_return_status,
1652 x_msg_count => x_msg_count,
1653 x_msg_data => x_msg_data,
1654 p_comp_job_dtls_rec => p_comp_job_dtls_rec,
1655 x_need_details_flag => l_need_details_flag,
1656 x_transaction_header_id => l_transaction_header_id
1657 );
1658
1659 IF (x_return_status <> FND_API.G_RET_STS_SUCCESS ) THEN
1660 FND_MESSAGE.SET_NAME('CSD','CSD_JOB_COMP_TXN_FAILURE');
1661 FND_MSG_PUB.ADD;
1662 RAISE FND_API.G_EXC_ERROR;
1663 END IF;
1664
1665 -- if no need for details, then we can process transactions and commit
1666 IF l_need_details_flag = 'F' THEN
1667 IF ( FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
1668 FND_LOG.STRING( FND_LOG.LEVEL_EVENT,
1669 lc_mod_name||'beforecallprocesstxn',
1670 'Just before calling process_mti_transactions');
1671 END IF;
1672 process_mti_transactions(
1673 p_api_version_number => lc_api_version_number,
1674 p_init_msg_list => fnd_api.g_false ,
1675 p_commit => fnd_api.g_false,
1676 p_validation_level => p_validation_level,
1677 x_return_status => x_return_status,
1678 x_msg_count => x_msg_count,
1679 x_msg_data => x_msg_data,
1680 p_txn_header_id => l_transaction_header_id
1681 -- p_txn_type IN VARCHAR2
1682 );
1683 IF (x_return_status <> FND_API.G_RET_STS_SUCCESS ) THEN
1684 FND_MESSAGE.SET_NAME('CSD','CSD_JOB_COMP_TXN_FAILURE');
1685 FND_MSG_PUB.ADD;
1686 RAISE FND_API.G_EXC_ERROR;
1687 END IF;
1688 ELSE
1689 --if we need details, pass back the transaction header id
1690 x_transaction_header_id := l_transaction_header_id;
1691 END IF;
1692
1693 -- Check before commit
1694 IF l_need_details_flag = 'F' and FND_API.to_Boolean( p_commit )
1695 THEN
1696 COMMIT WORK;
1697 END IF;
1698
1699 EXCEPTION
1700 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1701 ROLLBACK to PROCESS_JOB_COMP_TXN_PVT ;
1702 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1703
1704 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
1705 p_count => x_msg_count,
1706 p_data => x_msg_data);
1707
1708 IF ( FND_LOG.LEVEL_EXCEPTION >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
1709 FND_LOG.STRING( FND_LOG.LEVEL_EXCEPTION,
1710 lc_mod_name||'unx_exception',
1711 'G_EXC_UNEXPECTED_ERROR Exception');
1712 END IF;
1713
1714
1715 WHEN FND_API.G_EXC_ERROR THEN
1716 ROLLBACK to PROCESS_JOB_COMP_TXN_PVT ;
1717 x_return_status := FND_API.G_RET_STS_ERROR;
1718
1719 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
1720 p_count => x_msg_count,
1721 p_data => x_msg_data);
1722
1723 IF ( FND_LOG.LEVEL_ERROR >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
1724 FND_LOG.STRING( FND_LOG.LEVEL_ERROR,
1725 lc_mod_name||'exc_exception',
1726 'G_EXC_ERROR Exception');
1727 END IF;
1728
1729 WHEN OTHERS THEN
1730 ROLLBACK to PROCESS_JOB_COMP_TXN_PVT ;
1731 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1732
1733 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
1734 -- Add Unexpected Error to Message List, here SQLERRM is used for
1735 -- getting the error
1736 FND_MSG_PUB.add_exc_msg(p_pkg_name => G_PKG_NAME,
1737 p_procedure_name => lc_api_name );
1738 END IF;
1739
1740 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
1741 p_count => x_msg_count,
1742 p_data => x_msg_data);
1743
1744 IF ( FND_LOG.LEVEL_EXCEPTION >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
1745 FND_LOG.STRING( FND_LOG.LEVEL_EXCEPTION,
1746 lc_mod_name||'others_exception',
1747 'OTHERS Exception');
1748 END IF;
1749 END process_job_comp_txn;
1750
1751 --
1752 -- Inserts the transaction line(s) for job completion
1753 -- Does NOT process the transaction lines
1754 -- OUT params:
1755 -- x_need_details_flag: set to 'T' if details are neede, otherwise 'F'
1756 -- x_transaction_header_id: Transaction header ID always passed back
1757 -- regardless of need details param
1758 --
1759 PROCEDURE insert_job_comp_txn
1760 (
1761 p_api_version_number IN NUMBER,
1762 p_init_msg_list IN VARCHAR2 ,
1763 p_commit IN VARCHAR2 ,
1764 p_validation_level IN NUMBER,
1765 x_return_status OUT NOCOPY VARCHAR2,
1766 x_msg_count OUT NOCOPY NUMBER,
1767 x_msg_data OUT NOCOPY VARCHAR2,
1768 p_comp_job_dtls_rec IN JOB_DTLS_REC_TYPE,
1769 x_need_details_flag OUT NOCOPY VARCHAR2,
1770 x_transaction_header_id OUT NOCOPY NUMBER
1771 )
1772 IS
1773
1774 lc_api_name CONSTANT VARCHAR2(30) := 'INSERT_JOB_COMP_TXN';
1775 lc_api_version_number CONSTANT NUMBER := 1.0;
1776
1777 -- constants used for FND_LOG debug messages
1778 lc_mod_name VARCHAR2(2000) := 'csd.plsql.csd_hv_wip_job_pvt.insert_job_comp_txn';
1779
1780 lc_revision_controlled CONSTANT NUMBER := 2;
1781 lc_full_lot_control CONSTANT NUMBER := 2;
1782 lc_predefined_serial_control CONSTANT NUMBER := 2;
1783 lc_inven_rct_srl_control CONSTANT NUMBER := 5;
1784 lc_predfn_loc_cntrl CONSTANT NUMBER := 2;
1785 lc_dyn_loc_cntrl CONSTANT NUMBER := 3;
1786 lc_subinv_lv_loc_cntrl CONSTANT NUMBER := 4;
1787 lc_inv_lv_loc_cntrl CONSTANT NUMBER := 5;
1788
1789 -- Constants used for inserting into mtl_transactions_interface
1790 lc_completion_source_code CONSTANT VARCHAR2(30) := 'WIP Completion';
1791 lc_wip_txn_source_type_id CONSTANT NUMBER := 5;
1792 lc_comp_txn_type CONSTANT NUMBER := 44;
1793 lc_non_std_wip_ent_type CONSTANT NUMBER := 3;
1794 lc_dummy_source_line_id CONSTANT NUMBER := -2;
1795
1796 -- final completion flag will not be constant. Rather will be populated from wip_parameters.
1797 -- swai: bug 14704127 (FP of bug#14264436, subhat)
1798 lc_n_final_completion_flag VARCHAR2(1) := 'N' ;
1799
1800 -- Records to hold the mtl_transactions_interface data
1801 l_transactions_interface_rec mtl_transactions_interface%ROWTYPE;
1802
1803 l_locator_controlled VARCHAR2(1) := 'F';
1804 l_revision_qty_control_code NUMBER;
1805 l_transaction_quantity NUMBER;
1806 l_lot_control_code NUMBER;
1807 l_SERIAL_NUMBER_CONTROL_CODE NUMBER;
1808
1809 l_last_op_move_quantity NUMBER;
1810 l_last_move_allowed VARCHAR2(1);
1811 l_location_control_code NUMBER;
1812
1813 -- bug#9453092, subhat.
1814 l_costing_method NUMBER := -1;
1815
1816 Cursor get_job_details IS
1817 SELECT wdj.organization_id, wdj.primary_item_id,
1818 (wdj.start_quantity - wdj.quantity_completed - wdj.quantity_scrapped)
1819 transaction_quantity,
1820 wdj.completion_subinventory, wdj.completion_locator_id,
1821 msi.primary_uom_code, msi.revision_qty_control_code,
1822 msi.SERIAL_NUMBER_CONTROL_CODE, msi.LOT_CONTROL_CODE
1823 from wip_discrete_jobs wdj, mtl_system_items_kfv msi
1824 where wdj.wip_entity_id = p_comp_job_dtls_rec.wip_entity_id and
1825 wdj.primary_item_id = msi.inventory_item_id and
1826 wdj.organization_id = msi.organization_id;
1827
1828 CURSOR get_mtl_header_id IS
1829 SELECT mtl_material_transactions_s.nextval from dual;
1830
1831 CURSOR get_last_operation_dtls(c_org_id NUMBER) IS
1832 SELECT
1833 wo.quantity_waiting_to_move,
1834 'Y' allow_moves
1835 FROM
1836 wip_operations wo
1837 WHERE wo.operation_seq_num =
1838 (select max(operation_seq_num)
1839 from wip_operations wo1
1840 where wo1.organization_id = wo.organization_id
1841 and wo1.wip_entity_id = wo.wip_entity_id
1842 and wo1.repetitive_schedule_id is NULL)
1843 AND wo.organization_id = c_org_id
1844 AND wo.wip_entity_id = p_comp_job_dtls_rec.wip_entity_id
1845 AND wo.repetitive_schedule_id is NULL
1846 AND not exists
1847 (select 'No move status exists'
1848 from wip_shop_floor_statuses ws,
1849 wip_shop_floor_status_codes wsc
1850 where wsc.organization_id = wo.organization_id
1851 and ws.organization_id = wo.organization_id
1852 and ws.wip_entity_id = wo.wip_entity_id
1853 and ws.line_id is NULL
1854 and ws.operation_seq_num = wo.operation_seq_num
1855 and ws.intraoperation_step_type = 3
1856 and ws.shop_floor_status_code = wsc.shop_floor_status_code
1857 and wsc.status_move_flag = 2
1858 and nvl(wsc.disable_date, SYSDATE + 1) > SYSDATE)
1859 UNION
1860 SELECT
1861 wo.quantity_waiting_to_move,
1862 'N' allow_moves
1863 FROM
1864 wip_operations wo
1865 WHERE wo.operation_seq_num =
1866 (select max(operation_seq_num)
1867 from wip_operations wo1
1868 where wo1.organization_id = wo.organization_id
1869 and wo1.wip_entity_id = wo.wip_entity_id
1870 and wo1.repetitive_schedule_id is NULL)
1871 AND wo.organization_id = c_org_id
1872 AND wo.wip_entity_id = p_comp_job_dtls_rec.wip_entity_id
1873 AND wo.repetitive_schedule_id is NULL
1874 AND exists
1875 (select 'Move status exists'
1876 from wip_shop_floor_statuses ws,
1877 wip_shop_floor_status_codes wsc
1878 where wsc.organization_id = wo.organization_id
1879 and ws.organization_id = wo.organization_id
1880 and ws.wip_entity_id = wo.wip_entity_id
1881 and ws.line_id is NULL
1882 and ws.operation_seq_num = wo.operation_seq_num
1883 and ws.intraoperation_step_type = 3
1884 and ws.shop_floor_status_code = wsc.shop_floor_status_code
1885 and wsc.status_move_flag = 2
1886 and nvl(wsc.disable_date, SYSDATE + 1) > SYSDATE);
1887
1888
1889 CURSOR get_org_locator_control_code(p_organization_id NUMBER) IS
1890 SELECT stock_locator_control_code
1891 from mtl_parameters
1892 where organization_id = p_organization_id;
1893
1894 CURSOR get_si_locator_control_code ( p_organization_id NUMBER,
1895 p_secondary_inventory_name VARCHAR2 ) IS
1896 SELECT locator_type
1897 from mtl_secondary_inventories
1898 where
1899 organization_id = p_organization_id and
1900 secondary_inventory_name = p_secondary_inventory_name;
1901
1902 CURSOR get_inv_location_control_code ( p_organization_id NUMBER,
1903 p_inventory_item_id NUMBER ) IS
1904 SELECT location_control_code
1905 from mtl_system_items_b
1906 where
1907 organization_id = p_organization_id and
1908 inventory_item_id = p_inventory_item_id;
1909
1910 BEGIN
1911 IF ( FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
1912 FND_LOG.STRING( FND_LOG.LEVEL_PROCEDURE,
1913 lc_mod_name||'begin',
1914 'Entering private API insert_job_comp_txn' );
1915 END IF;
1916
1917 SAVEPOINT INSERT_JOB_COMP_TXN_PVT;
1918
1919 -- Standard call to check for call compatibility.
1920 IF NOT FND_API.Compatible_API_Call(lc_api_version_number,
1921 p_api_version_number,
1922 lc_api_name,
1923 G_PKG_NAME) THEN
1924 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1925 END IF;
1926
1927
1928 IF FND_API.to_boolean(p_init_msg_list) THEN
1929 FND_MSG_PUB.initialize;
1930 END IF;
1931
1932 -- initialize out params
1933 x_return_status := FND_API.G_RET_STS_SUCCESS;
1934 x_need_details_flag := 'F';
1935
1936 -- generate transaction_id
1937 open get_mtl_header_id;
1938 fetch get_mtl_header_id into l_transactions_interface_rec.transaction_header_id;
1939 close get_mtl_header_id;
1940
1941 open get_job_details;
1942 fetch get_job_details into
1943 l_transactions_interface_rec.organization_id,
1944 l_transactions_interface_rec.inventory_item_id,
1945 l_transaction_quantity,
1946 l_transactions_interface_rec.subinventory_code,
1947 l_transactions_interface_rec.locator_id,
1948 l_transactions_interface_rec.transaction_uom,
1949 l_revision_qty_control_code,
1950 l_SERIAL_NUMBER_CONTROL_CODE,
1951 l_lot_control_code;
1952 close get_job_details;
1953
1954 open get_last_operation_dtls(
1955 c_org_id => l_transactions_interface_rec.organization_id);
1956 fetch get_last_operation_dtls into
1957 l_last_op_move_quantity,
1958 l_last_move_allowed;
1959 IF (get_last_operation_dtls%FOUND) THEN
1960 l_transaction_quantity := l_last_op_move_quantity;
1961 IF l_last_move_allowed = 'N' THEN
1962 FND_MESSAGE.SET_NAME('CSD','CSD_JOB_COMP_MV_NOT_ALL');
1963 FND_MSG_PUB.ADD;
1964 close get_last_operation_dtls;
1965 RAISE FND_API.G_EXC_ERROR;
1966 END IF;
1967 END IF;
1968 close get_last_operation_dtls;
1969
1970 IF l_transaction_quantity <= 0 THEN
1971 FND_MESSAGE.SET_NAME('CSD','CSD_JOB_COMP_ZER_QTY');
1972 FND_MSG_PUB.ADD;
1973 RAISE FND_API.G_EXC_ERROR;
1974 END IF;
1975
1976 l_transactions_interface_rec.source_code := lc_completion_source_code;
1977 l_transactions_interface_rec.transaction_date := sysdate;
1978 l_transactions_interface_rec.transaction_source_type_id := lc_wip_txn_source_type_id;
1979 l_transactions_interface_rec.transaction_type_id:= lc_comp_txn_type;
1980 l_transactions_interface_rec.wip_entity_type := lc_non_std_wip_ent_type;
1981 l_transactions_interface_rec.source_line_id := lc_dummy_source_line_id;
1982 -- swai: bug 14704127 (FP of bug#14264436, subhat)
1983 -- l_transactions_interface_rec.final_completion_flag := lc_n_final_completion_flag;
1984
1985 IF l_revision_qty_control_code = lc_revision_controlled THEN
1986 -- swai: bug 6995498/7182047 - move revision code to common wraper function
1987 l_transactions_interface_rec.revision := get_default_item_revision
1988 (
1989 p_org_id=>l_transactions_interface_rec.organization_id,
1990 p_inventory_item_id=> l_transactions_interface_rec.inventory_item_id,
1991 p_transaction_date=> l_transactions_interface_rec.transaction_date,
1992 p_mat_transaction_type=> 'JOB_COMP'
1993 ) ;
1994 IF l_transactions_interface_rec.revision is null THEN
1995 x_need_details_flag := 'T';
1996 END IF;
1997 END IF;
1998
1999 IF l_transactions_interface_rec.subinventory_code is null THEN
2000
2001 IF fnd_profile.value('CSD_DEF_REP_INV_ORG') = l_transactions_interface_rec.organization_id and
2002 fnd_profile.value('CSD_DEF_HV_CMP_SUBINV') is not null THEN
2003 l_transactions_interface_rec.subinventory_code := fnd_profile.value('CSD_DEF_HV_CMP_SUBINV');
2004 ELSE
2005 x_need_details_flag := 'T'; -- swai: bug 5262927
2006 END IF;
2007 END IF;
2008
2009 -- Get Locator Control
2010 open get_org_locator_control_code ( l_transactions_interface_rec.organization_id ) ;
2011 fetch get_org_locator_control_code into l_location_control_code ;
2012 close get_org_locator_control_code;
2013
2014 IF l_location_control_code = lc_subinv_lv_loc_cntrl THEN
2015 IF l_transactions_interface_rec.subinventory_code is not null THEN
2016 open get_si_locator_control_code ( l_transactions_interface_rec.organization_id ,
2017 l_transactions_interface_rec.subinventory_code ) ;
2018 fetch get_si_locator_control_code into l_location_control_code ;
2019 close get_si_locator_control_code;
2020
2021 IF l_location_control_code = lc_inv_lv_loc_cntrl THEN
2022 open get_inv_location_control_code ( l_transactions_interface_rec.organization_id ,
2023 l_transactions_interface_rec.inventory_item_id ) ;
2024 fetch get_inv_location_control_code into l_location_control_code ;
2025 close get_inv_location_control_code;
2026 END IF;
2027 END IF;
2028 END IF;
2029
2030
2031 IF l_location_control_code in (lc_predfn_loc_cntrl,
2032 lc_dyn_loc_cntrl ) THEN
2033 l_locator_controlled := 'T' ;
2034 END IF;
2035
2036 IF l_locator_controlled = 'T' THEN
2037 IF l_transactions_interface_rec.locator_id is null THEN
2038 x_need_details_flag := 'T';
2039 END IF;
2040 END IF;
2041
2042 -- Lot Contrrolled Check
2043 -- Later Need to handle it here as well - based on profile
2044 -- Value
2045 IF l_lot_control_code = lc_full_lot_control THEN
2046 x_need_details_flag := 'T' ;
2047 END IF;
2048
2049 l_transactions_interface_rec.transaction_quantity := l_transaction_quantity;
2050 l_transactions_interface_rec.primary_quantity := l_transactions_interface_rec.transaction_quantity;
2051 l_transactions_interface_rec.transaction_source_id := p_comp_job_dtls_rec.wip_entity_id;
2052 l_transactions_interface_rec.source_header_id := p_comp_job_dtls_rec.wip_entity_id;
2053
2054 -- generate transaction_interface_id
2055 open get_mtl_header_id;
2056 fetch get_mtl_header_id into l_transactions_interface_rec.transaction_interface_id;
2057 close get_mtl_header_id;
2058
2059 IF l_serial_number_control_code in (lc_predefined_serial_control,
2060 lc_inven_rct_srl_control) THEN
2061
2062 x_need_details_flag := 'T' ;
2063
2064 -- -1 identifies rows which are queried up in the details UI
2065 l_transactions_interface_rec.source_line_id := -1;
2066
2067 IF ( l_transaction_quantity > 1 ) THEN
2068 l_transactions_interface_rec.transaction_quantity := 1;
2069
2070 --insert into table mtl_transactions_interface
2071 FOR l_qty_ctr IN 1..l_transaction_quantity
2072 LOOP
2073 IF ( FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
2074 FND_LOG.STRING( FND_LOG.LEVEL_EVENT,
2075 lc_mod_name||'beforecallinserttxnshdr',
2076 'Just before calling insert_transactions_header');
2077 END IF;
2078 -- Support job completion for average costing method bug#9453092, Subhat
2079 -- swai: bug 14704127 (FP of bug#14264436)
2080 -- modified select statement to get final completion flag
2081 -- moved code above insert_transactions_header
2082 IF l_costing_method = -1 THEN
2083 SELECT primary_cost_method,decode(auto_compute_final_completion,1,'Y','N')
2084 INTO l_costing_method,lc_n_final_completion_flag
2085 FROM mtl_parameters mp,wip_parameters wp
2086 WHERE mp.organization_id = l_transactions_interface_rec.organization_id
2087 AND wp.organization_id = l_transactions_interface_rec.organization_id;
2088 END IF;
2089 l_transactions_interface_rec.final_completion_flag := lc_n_final_completion_flag;
2090
2091
2092 insert_transactions_header( p_transactions_interface_rec => l_transactions_interface_rec,
2093 x_return_status => x_return_status );
2094
2095 -- yvchen: bug 13399147 - if FIFO costing (5) also insert into cost table
2096 -- per metalink Doc ID 262980.1
2097 IF ((l_costing_method = 2) OR (l_costing_method = 5)) THEN
2098
2099 insert_cst_interface(p_wip_entity_id => p_comp_job_dtls_rec.wip_entity_id,
2100 p_interface_id => l_transactions_interface_rec.transaction_interface_id
2101 );
2102 END IF; -- end bug#9453092
2103
2104 IF l_qty_ctr <> l_transaction_quantity THEN
2105 -- generate transaction_interface_id for the next record
2106 open get_mtl_header_id;
2107 fetch get_mtl_header_id into l_transactions_interface_rec.transaction_interface_id;
2108 close get_mtl_header_id;
2109 END IF;
2110
2111 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2112 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2113 END IF;
2114 END LOOP;
2115 ELSE -- Quantity = 1
2116 --insert into table mtl_transactions_interface
2117 IF ( FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
2118 FND_LOG.STRING( FND_LOG.LEVEL_EVENT,
2119 lc_mod_name||'beforecallinserttxnshdr',
2120 'Just before calling insert_transactions_header');
2121 END IF;
2122
2123 -- Support job completion for average costing method bug#9453092, Subhat
2124 -- swai: bug 14704127 (FP of bug#14264436)
2125 -- modified select statement to get final completion flag
2126 -- moved code above insert_transactions_header
2127 IF l_costing_method = -1 THEN
2128 SELECT primary_cost_method,decode(auto_compute_final_completion,1,'Y','N')
2129 INTO l_costing_method,lc_n_final_completion_flag
2130 FROM mtl_parameters mp,wip_parameters wp
2131 WHERE mp.organization_id = l_transactions_interface_rec.organization_id
2132 AND wp.organization_id = l_transactions_interface_rec.organization_id;
2133 END IF;
2134 l_transactions_interface_rec.final_completion_flag := lc_n_final_completion_flag;
2135
2136 insert_transactions_header(p_transactions_interface_rec => l_transactions_interface_rec,
2137 x_return_status => x_return_status );
2138
2139 -- yvchen: bug 13399147 - if FIFO costing (5) also insert into cost table
2140 -- per metalink Doc ID 262980.1
2141 IF ((l_costing_method = 2) OR (l_costing_method = 5)) THEN
2142
2143 insert_cst_interface(p_wip_entity_id => p_comp_job_dtls_rec.wip_entity_id,
2144 p_interface_id => l_transactions_interface_rec.transaction_interface_id
2145 );
2146 END IF; -- end bug#9453092
2147
2148 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2149 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2150 END IF;
2151 END IF;
2152
2153 ELSE -- l_serial_number_control_code check
2154 IF x_need_details_flag = 'T' THEN
2155 -- -1 identifies rows which are queried up in the details UI
2156 l_transactions_interface_rec.source_line_id := -1;
2157 END IF;
2158
2159 --insert into table mtl_transactions_interface
2160 IF ( FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
2161 FND_LOG.STRING( FND_LOG.LEVEL_EVENT,
2162 lc_mod_name||'beforecallinserttxnshdr',
2163 'Just before calling insert_transactions_header');
2164 END IF;
2165
2166 -- Support job completion for average costing method bug#9453092, Subhat
2167 -- swai: bug 14704127 (FP of bug#14264436)
2168 -- modified select statement to get final completion flag
2169 -- moved code above insert_transactions_header
2170 IF l_costing_method = -1 THEN
2171 SELECT primary_cost_method,decode(auto_compute_final_completion,1,'Y','N')
2172 INTO l_costing_method,lc_n_final_completion_flag
2173 FROM mtl_parameters mp,wip_parameters wp
2174 WHERE mp.organization_id = l_transactions_interface_rec.organization_id
2175 AND wp.organization_id = l_transactions_interface_rec.organization_id;
2176 END IF;
2177 l_transactions_interface_rec.final_completion_flag := lc_n_final_completion_flag;
2178
2179 insert_transactions_header(p_transactions_interface_rec => l_transactions_interface_rec,
2180 x_return_status => x_return_status );
2181
2182 -- yvchen: bug 13399147 - if FIFO costing (5) also insert into cost table
2183 -- per metalink Doc ID 262980.1
2184 IF ((l_costing_method = 2) OR (l_costing_method = 5)) THEN
2185
2186 insert_cst_interface(p_wip_entity_id => p_comp_job_dtls_rec.wip_entity_id,
2187 p_interface_id => l_transactions_interface_rec.transaction_interface_id
2188 );
2189 END IF; -- end bug#9453092
2190 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2191 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2192 END IF;
2193 END IF; -- l_serial_number_control_code check
2194
2195 -- Regardless of whether or not details are needed, pass back
2196 -- the transaction header ID.
2197 x_transaction_header_id := l_transactions_interface_rec.transaction_header_id;
2198
2199 -- Standard check for p_commit
2200 IF FND_API.to_Boolean( p_commit )
2201 THEN
2202 COMMIT WORK;
2203 END IF;
2204
2205 EXCEPTION
2206 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2207 ROLLBACK to INSERT_JOB_COMP_TXN_PVT ;
2208 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2209
2210 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
2211 p_count => x_msg_count,
2212 p_data => x_msg_data);
2213
2214 IF ( FND_LOG.LEVEL_EXCEPTION >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
2215 FND_LOG.STRING( FND_LOG.LEVEL_EXCEPTION,
2216 lc_mod_name||'unx_exception',
2217 'G_EXC_UNEXPECTED_ERROR Exception');
2218 END IF;
2219
2220
2221 WHEN FND_API.G_EXC_ERROR THEN
2222 ROLLBACK to INSERT_JOB_COMP_TXN_PVT ;
2223 x_return_status := FND_API.G_RET_STS_ERROR;
2224
2225
2226 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
2227 p_count => x_msg_count,
2228 p_data => x_msg_data);
2229
2230 IF ( FND_LOG.LEVEL_ERROR >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
2231 FND_LOG.STRING( FND_LOG.LEVEL_ERROR,
2232 lc_mod_name||'exc_exception',
2233 'G_EXC_ERROR Exception');
2234 END IF;
2235
2236 WHEN OTHERS THEN
2237 ROLLBACK to INSERT_JOB_COMP_TXN_PVT ;
2238 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2239
2240 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
2241
2242 -- Add Unexpected Error to Message List, here SQLERRM is used for
2243 -- getting the error
2244
2245 FND_MSG_PUB.add_exc_msg(p_pkg_name => G_PKG_NAME,
2246 p_procedure_name => lc_api_name );
2247 END IF;
2248
2249 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
2250 p_count => x_msg_count,
2251 p_data => x_msg_data);
2252
2253 IF ( FND_LOG.LEVEL_EXCEPTION >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
2254 FND_LOG.STRING( FND_LOG.LEVEL_EXCEPTION,
2255 lc_mod_name||'others_exception',
2256 'OTHERS Exception');
2257 END IF;
2258 END insert_job_comp_txn;
2259
2260 PROCEDURE process_mti_transactions
2261 (
2262 p_api_version_number IN NUMBER,
2263 p_init_msg_list IN VARCHAR2,
2264 p_commit IN VARCHAR2,
2265 p_validation_level IN NUMBER,
2266 x_return_status OUT NOCOPY VARCHAR2,
2267 x_msg_count OUT NOCOPY NUMBER,
2268 x_msg_data OUT NOCOPY VARCHAR2,
2269 p_txn_header_id IN NUMBER
2270 )
2271 IS
2272 lc_api_name CONSTANT VARCHAR2(30) := 'PROCESS_MTI_TRANSACTIONS';
2273 lc_api_version_number CONSTANT NUMBER := 1.0;
2274
2275 -- constants used for FND_LOG debug messages
2276 lc_mod_name VARCHAR2(2000) := 'csd.plsql.csd_hv_wip_job_pvt.process_mti_transactions';
2277
2278 lc_MTI_source_table CONSTANT NUMBER := 1;
2279
2280 l_table NUMBER;
2281 l_trans_count NUMBER;
2282 l_return_count NUMBER;
2283 --subhat, FedEx material updates changes.
2284 -- swai: bug 13820264, FP of bug#13797285, subhat
2285 l_wip_entity_ids JTF_NUMBER_TABLE := JTF_NUMBER_TABLE();
2286 BEGIN
2287 IF ( FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
2288 FND_LOG.STRING( FND_LOG.LEVEL_PROCEDURE,
2289 lc_mod_name||'begin',
2290 'Entering private API process_mti_transactions' );
2291 END IF;
2292
2293 SAVEPOINT PROCESS_MTI_TRANSACTIONS_PVT;
2294
2295 -- Standard call to check for call compatibility.
2296 IF NOT FND_API.Compatible_API_Call(lc_api_version_number,
2297 p_api_version_number,
2298 lc_api_name,
2299 G_PKG_NAME) THEN
2300 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2301 END IF;
2302
2303
2304 IF FND_API.to_boolean(p_init_msg_list) THEN
2305 FND_MSG_PUB.initialize;
2306 END IF;
2307 x_return_status := FND_API.G_RET_STS_SUCCESS;
2308
2309 -- get the wip entity ids being processed.
2310 -- swai: bug 13820264, FP of bug#13797285, subhat
2311 SELECT DISTINCT transaction_source_id
2312 BULK COLLECT INTO l_wip_entity_ids
2313 FROM mtl_transactions_interface
2314 WHERE transaction_header_id = p_txn_header_id;
2315
2316 -- Populate the constant values
2317 l_table := lc_MTI_source_table;
2318
2319 IF ( FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
2320 FND_LOG.STRING( FND_LOG.LEVEL_EVENT,
2321 lc_mod_name||'beforecallprocesstxns',
2322 'Just before calling INV_TXN_MANAGER_PUB.process_Transactions');
2323 END IF;
2324
2325 l_return_count := INV_TXN_MANAGER_PUB.process_Transactions(
2326 p_api_version => lc_api_version_number, --1.0, -- ,
2327 p_init_msg_list => fnd_api.g_false, --'T', -- fnd_api.g_false ,
2328 p_commit => fnd_api.g_false, --'T', -- fnd_api.g_false ,
2329 p_validation_level => p_validation_level ,
2330 x_return_status => x_return_status,
2331 x_msg_count => x_msg_count,
2332 x_msg_data => x_msg_data,
2333 x_trans_count => l_trans_count,
2334 p_table => l_table,
2335 p_header_id => p_txn_header_id );
2336
2337 IF ( txn_int_error_exists( p_txn_header_id) or
2338 x_return_status <> FND_API.G_RET_STS_SUCCESS ) THEN
2339
2340 --bug#14456229 --14497341
2341 if (p_txn_header_id is not null) then
2342 IF (nvl(fnd_profile.value('MRP_DEBUG'),'Y') = 'N') THEN
2343
2344 IF ( FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
2345 FND_LOG.STRING( FND_LOG.LEVEL_EVENT,
2346 lc_mod_name||'Error',
2347 'delete from mtl_transactions_interface');
2348 END IF;
2349
2350 IF ( FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
2351 FND_LOG.STRING( FND_LOG.LEVEL_EVENT,
2352 lc_mod_name||'Error',
2353 'p_txn_header_id :' ||p_txn_header_id );
2354 END IF;
2355
2356 delete from mtl_transactions_interface where transaction_header_id = p_txn_header_id;
2357 End If;
2358 End if;
2359 --bug#14456229 --14497341
2360
2361
2362 FND_MESSAGE.SET_NAME('CSD','CSD_PROCESS_MTI_TXN_FAILURE');
2363 FND_MSG_PUB.ADD;
2364 RAISE FND_API.G_EXC_ERROR;
2365 END IF;
2366
2367 -- subhat FedEx material update changes.
2368 -- swai: bug 13820264, FP of bug#13797285, subhat
2369 FOR i IN 1 ..l_wip_entity_ids.COUNT
2370 LOOP
2371
2372 update_mat_issue_quantities
2373 (
2374 p_api_version_number => 1.0 ,
2375 p_init_msg_list => fnd_api.g_false ,
2376 p_commit => fnd_api.g_false ,
2377 p_validation_level => fnd_api.g_valid_level_none,
2378 x_return_status => x_return_status,
2379 x_msg_count => x_msg_count,
2380 x_msg_data => x_msg_data,
2381 p_repair_line_id => NULL,
2382 p_wip_entity_id => l_wip_entity_ids(i),
2383 p_wip_transaction_detail_id => NULL,
2384 p_transaction_type_id => NULL,
2385 p_quantity => NULL,
2386 p_exclude_closed_jobs => 'Y',
2387 p_transaction_date_start => NULL,
2388 p_transaction_date_end => NULL
2389 );
2390 END LOOP;
2391
2392 -- Standard check for p_commit
2393 IF FND_API.to_Boolean( p_commit )
2394 THEN
2395 COMMIT WORK;
2396 END IF;
2397
2398 EXCEPTION
2399 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2400 ROLLBACK to PROCESS_MTI_TRANSACTIONS_PVT ;
2401 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2402
2403 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
2404 p_count => x_msg_count,
2405 p_data => x_msg_data);
2406
2407 IF ( FND_LOG.LEVEL_EXCEPTION >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
2408 FND_LOG.STRING( FND_LOG.LEVEL_EXCEPTION,
2409 lc_mod_name||'unx_exception',
2410 'G_EXC_UNEXPECTED_ERROR Exception');
2411 END IF;
2412
2413
2414 WHEN FND_API.G_EXC_ERROR THEN
2415 --bug#14456229 --14497341
2416 IF (nvl(fnd_profile.value('MRP_DEBUG'),'Y') = 'Y') THEN
2417 ROLLBACK to PROCESS_MTI_TRANSACTIONS_PVT ;
2418 End if;
2419 --bug#14456229 --14497341
2420
2421 x_return_status := FND_API.G_RET_STS_ERROR;
2422
2423 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
2424 p_count => x_msg_count,
2425 p_data => x_msg_data);
2426
2427 IF ( FND_LOG.LEVEL_ERROR >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
2428 FND_LOG.STRING( FND_LOG.LEVEL_ERROR,
2429 lc_mod_name||'exc_exception',
2430 'G_EXC_ERROR Exception');
2431 END IF;
2432
2433 WHEN OTHERS THEN
2434 ROLLBACK to PROCESS_MTI_TRANSACTIONS_PVT ;
2435 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2436
2437 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
2438 -- Add Unexpected Error to Message List, here SQLERRM is used for
2439 -- getting the error
2440 FND_MSG_PUB.add_exc_msg(p_pkg_name => G_PKG_NAME,
2441 p_procedure_name => lc_api_name );
2442 END IF;
2443
2444 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
2445 p_count => x_msg_count,
2446 p_data => x_msg_data);
2447
2448 IF ( FND_LOG.LEVEL_EXCEPTION >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
2449 FND_LOG.STRING( FND_LOG.LEVEL_EXCEPTION,
2450 lc_mod_name||'others_exception',
2451 'OTHERS Exception');
2452 END IF;
2453 END process_mti_transactions;
2454
2455 PROCEDURE process_oper_comp_txn
2456 (
2457 p_api_version_number IN NUMBER,
2458 p_init_msg_list IN VARCHAR2,
2459 p_commit IN VARCHAR2,
2460 p_validation_level IN NUMBER,
2461 x_return_status OUT NOCOPY VARCHAR2,
2462 x_msg_count OUT NOCOPY NUMBER,
2463 x_msg_data OUT NOCOPY VARCHAR2,
2464 p_mv_txn_dtls_tbl IN MV_TXN_DTLS_TBL_TYPE
2465 )
2466 IS
2467 lc_api_name CONSTANT VARCHAR2(30) := 'PROCESS_OPER_COMP_TXN';
2468 lc_api_version_number CONSTANT NUMBER := 1.0;
2469
2470 -- constants used for FND_LOG debug messages
2471
2472 lc_mod_name VARCHAR2(2000) := 'csd.plsql.csd_hv_wip_job_pvt.process_oper_comp_txn';
2473
2474 -- Indicates that the process Phase is Validation
2475 -- lc_validation_phase CONSTANT NUMBER := 1;
2476
2477
2478
2479 -- Constants used for inserting into wip_move_txn_interface
2480
2481 lc_queue CONSTANT NUMBER := 1;
2482 lc_to_move CONSTANT NUMBER := 3;
2483 lc_error_process_status CONSTANT NUMBER := 3;
2484
2485
2486 -- Record to hold wip_move_txn_interface
2487
2488 l_wip_move_txn_interface_rec wip_move_txn_interface%ROWTYPE;
2489
2490
2491 /* l_process_phase NUMBER;
2492 l_material_transaction_id NUMBER; */
2493
2494 l_prev_wip_entity_id NUMBER := -1;
2495 l_prev_to_operation_seq_num NUMBER := -1;
2496 l_prev_transaction_quantity NUMBER := 0;
2497 --l_error_exists VARCHAR2(6);
2498 l_err_wip_entity_name VARCHAR2(240);
2499 l_err_op_seq_num NUMBER;
2500
2501 -- swai: bug 5330060
2502 -- temporary storgae of it move and in queue quantities
2503 l_qty_to_move NUMBER := 0;
2504 l_qty_in_queue NUMBER := 0;
2505 -- end swai: bug 5330060
2506
2507 CURSOR get_transaction_id IS
2508 SELECT wip_transactions_s.nextval from dual;
2509
2510
2511 Cursor check_mv_interface_errors ( c_group_id NUMBER ) IS
2512 select wip.wip_entity_name, mv.fm_operation_seq_num
2513 from wip_move_txn_interface mv, wip_entities wip
2514 where mv.group_id = c_group_id
2515 and mv.process_status = lc_error_process_status
2516 and mv.wip_entity_id = wip.wip_entity_id;
2517
2518 -- swai: bug 5330060
2519 -- Get the previous operation for this job that has qty > 1
2520 -- for either in queue or waiting to move
2521 Cursor get_valid_previous_op (c_wip_entity_id NUMBER, c_op_seq_num NUMBER) IS
2522 select *
2523 from
2524 (select operation_seq_num,
2525 quantity_in_queue,
2526 quantity_waiting_to_move
2527 from wip_operations
2528 where wip_entity_id = c_wip_entity_id
2529 and operation_seq_num < c_op_seq_num
2530 and quantity_in_queue + quantity_waiting_to_move > 0
2531 order by operation_seq_num desc)
2532 where rownum=1;
2533 -- end swai: bug 5330060
2534
2535 /* CURSOR get_material_transaction_id IS
2536 SELECT mtl_material_transactions_s.nextval from dual; */
2537
2538
2539 BEGIN
2540
2541 IF ( FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
2542 FND_LOG.STRING( FND_LOG.LEVEL_PROCEDURE,
2543 lc_mod_name||'begin',
2544 'Entering private API process_oper_comp_txn' );
2545 END IF;
2546
2547 SAVEPOINT PROCESS_OPER_COMP_TXN_PVT;
2548 -- Standard call to check for call compatibility.
2549 IF NOT FND_API.Compatible_API_Call
2550 (lc_api_version_number,
2551 p_api_version_number,
2552 lc_api_name,
2553 G_PKG_NAME)
2554 THEN
2555 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2556 END IF;
2557
2558
2559 IF FND_API.to_boolean(p_init_msg_list) THEN
2560 FND_MSG_PUB.initialize;
2561 END IF;
2562
2563
2564
2565
2566 x_return_status := FND_API.G_RET_STS_SUCCESS;
2567
2568
2569 -- Populate the constant values
2570
2571
2572 -- l_process_phase := lc_validation_phase;
2573
2574
2575 -- generate transaction_id
2576 open get_transaction_id;
2577 -- fetch get_transaction_id into l_wip_move_txn_interface_rec.transaction_id;
2578 fetch get_transaction_id into l_wip_move_txn_interface_rec.group_id;
2579 close get_transaction_id;
2580
2581 -- l_wip_move_txn_interface_rec.group_id := l_wip_move_txn_interface_rec.transaction_id;
2582 l_wip_move_txn_interface_rec.transaction_date := sysdate;
2583 l_wip_move_txn_interface_rec.fm_intraoperation_step_type := lc_queue;
2584
2585
2586 -- swai: bug 5330060
2587 -- updated logic within for loop
2588 FOR mv_ctr in p_mv_txn_dtls_tbl.FIRST.. p_mv_txn_dtls_tbl.LAST
2589 LOOP
2590
2591 l_wip_move_txn_interface_rec.organization_id := p_mv_txn_dtls_tbl(mv_ctr).organization_id;
2592 l_wip_move_txn_interface_rec.wip_entity_name := p_mv_txn_dtls_tbl(mv_ctr).wip_entity_name;
2593 l_wip_move_txn_interface_rec.transaction_uom := p_mv_txn_dtls_tbl(mv_ctr).transaction_uom;
2594 l_wip_move_txn_interface_rec.to_operation_seq_num := nvl(p_mv_txn_dtls_tbl(mv_ctr).to_operation_seq_num,
2595 p_mv_txn_dtls_tbl(mv_ctr).fm_operation_seq_num ) ;
2596 -- if the to operation seq is 0, then it's the last operation,
2597 -- make sure the to step type is to_move, otherwise, it's in queue.
2598 if (p_mv_txn_dtls_tbl(mv_ctr).to_operation_seq_num is null) then
2599 l_wip_move_txn_interface_rec.to_intraoperation_step_type := lc_to_move;
2600 else
2601 l_wip_move_txn_interface_rec.to_intraoperation_step_type := lc_queue;
2602 end if;
2603
2604 -- if we are completing more than one operation for the same job, make
2605 -- the quantities are passed forward. Currently, do not allow the user
2606 -- to skip operations for the same job. (eg, complete 10, skip 20, complete 30)
2607 IF l_prev_wip_entity_id = p_mv_txn_dtls_tbl(mv_ctr).wip_entity_id THEN
2608 IF l_prev_to_operation_seq_num <> p_mv_txn_dtls_tbl(mv_ctr).fm_operation_seq_num THEN
2609 FND_MESSAGE.SET_NAME('CSD','CSD_OP_COMP_SEQ_ERROR');
2610 FND_MSG_PUB.ADD;
2611 RAISE FND_API.G_EXC_ERROR;
2612 ELSE
2613 l_wip_move_txn_interface_rec.transaction_quantity := p_mv_txn_dtls_tbl(mv_ctr).transaction_quantity +
2614 l_prev_transaction_quantity;
2615 END IF;
2616 ELSE
2617 l_wip_move_txn_interface_rec.transaction_quantity := p_mv_txn_dtls_tbl(mv_ctr).transaction_quantity;
2618 END IF;
2619
2620 -- use the values passed in if there are items to be transacted. Otherwise,
2621 -- we will attempt to find the appropriate from operation with an item that
2622 -- can be moved
2623 IF (l_wip_move_txn_interface_rec.transaction_quantity > 0) then
2624 l_wip_move_txn_interface_rec.fm_operation_seq_num := p_mv_txn_dtls_tbl(mv_ctr).fm_operation_seq_num;
2625 ELSE
2626 -- find the operation with a qty to complete, set the from operation to this
2627 open get_valid_previous_op (p_mv_txn_dtls_tbl(mv_ctr).wip_entity_id,
2628 p_mv_txn_dtls_tbl(mv_ctr).fm_operation_seq_num);
2629 fetch get_valid_previous_op into
2630 l_wip_move_txn_interface_rec.fm_operation_seq_num,
2631 l_qty_in_queue,
2632 l_qty_to_move;
2633 close get_valid_previous_op;
2634
2635 -- depending on where the item is, set the qty and from step type accordingly.
2636 if l_qty_in_queue > 0 then
2637 l_wip_move_txn_interface_rec.fm_intraoperation_step_type := lc_queue;
2638 l_wip_move_txn_interface_rec.transaction_quantity := l_qty_in_queue;
2639 elsif (l_qty_to_move > 0) then
2640 l_wip_move_txn_interface_rec.fm_intraoperation_step_type := lc_to_move;
2641 l_wip_move_txn_interface_rec.transaction_quantity := l_qty_to_move;
2642 end if;
2643 END IF;
2644
2645 -- set the variables to compare in the next loop iteration
2646 l_prev_wip_entity_id := p_mv_txn_dtls_tbl(mv_ctr).wip_entity_id;
2647 l_prev_to_operation_seq_num := l_wip_move_txn_interface_rec.to_operation_seq_num;
2648 l_prev_transaction_quantity := l_wip_move_txn_interface_rec.transaction_quantity;
2649
2650 --insert into table wip_move_txn_interface
2651 IF ( FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
2652 FND_LOG.STRING( FND_LOG.LEVEL_EVENT,
2653 lc_mod_name||'beforecallinsertwipmvtxn',
2654 'Just before calling insert_wip_move_txn');
2655 END IF;
2656
2657 insert_wip_move_txn( p_wip_move_txn_interface_rec => l_wip_move_txn_interface_rec,
2658 x_return_status => x_return_status );
2659
2660 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2661 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2662 END IF;
2663
2664 END LOOP;
2665 -- end swai: bug 5330060
2666
2667
2668 /* open get_material_transaction_id;
2669 fetch get_material_transaction_id into l_material_transaction_id;
2670 close get_material_transaction_id;
2671 */
2672
2673 IF ( FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
2674 FND_LOG.STRING( FND_LOG.LEVEL_EVENT,
2675 lc_mod_name||'beforecallprocesstxns',
2676 'Just before calling INV_TXN_MANAGER_PUB.process_Transactions');
2677 END IF;
2678
2679 /*
2680 wip_movProc_grp.processInterface(p_movTxnID => l_wip_move_txn_interface_rec.transaction_id,
2681 p_procPhase => l_process_phase,
2682 p_txnHdrID => l_material_transaction_id,
2683 p_mtlMode => WIP_CONSTANTS.ONLINE,
2684 p_cplTxnID => NULL,
2685 p_commit => FND_API.G_FALSE,
2686 x_returnStatus => x_return_status,
2687 x_errorMsg => x_msg_data);
2688
2689 */
2690
2691 wip_movProc_grp.processInterface(p_groupID => l_wip_move_txn_interface_rec.group_id,
2692 p_commit => FND_API.G_FALSE,
2693 x_returnStatus => x_return_status ) ;
2694
2695 -- Need to get errors from error table and pass it back
2696 open check_mv_interface_errors ( l_wip_move_txn_interface_rec.group_id );
2697 fetch check_mv_interface_errors into l_err_wip_entity_name, l_err_op_seq_num;
2698
2699 If (( x_return_status <> FND_API.G_RET_STS_SUCCESS) or
2700 (l_err_op_seq_num is not null)) THEN
2701
2702 IF (l_err_op_seq_num is null) THEN
2703 close check_mv_interface_errors ;
2704 FND_MESSAGE.SET_NAME('CSD','CSD_MOVE_TXN_FAILURE');
2705 FND_MSG_PUB.ADD;
2706 RAISE FND_API.G_EXC_ERROR;
2707
2708 ELSE
2709 x_return_status := FND_API.G_RET_STS_ERROR;
2710 WHILE check_mv_interface_errors%FOUND LOOP
2711 FND_MESSAGE.SET_NAME('CSD','CSD_MOVE_TXN_FAILURE_DET');
2712 FND_MESSAGE.SET_TOKEN('WIP_ENTITY_NAME', l_err_wip_entity_name);
2713 FND_MESSAGE.SET_TOKEN('OPERATION_SEQ_NUM', l_err_op_seq_num );
2714 FND_MSG_PUB.ADD;
2715 fetch check_mv_interface_errors into l_err_wip_entity_name, l_err_op_seq_num;
2716 END LOOP;
2717 END IF;
2718 end if;
2719 close check_mv_interface_errors ;
2720
2721
2722 /* IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2723 ROLLBACK to PROCESS_OPER_COMP_TXN_PVT ;
2724
2725
2726 FND_MESSAGE.SET_NAME('CSD','CSD_MOVE_TXN_FAILURE');
2727 FND_MSG_PUB.ADD;
2728 RAISE FND_API.G_EXC_UNEXPECTED_ERROR; */
2729
2730
2731 /* IF ( FND_LOG.LEVEL_ERROR >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
2732 FND_LOG.STRING( FND_LOG.LEVEL_ERROR,
2733 lc_mod_name||'exc_exception',
2734 'G_EXC_ERROR Exception');
2735 END IF;
2736
2737 RETURN; */
2738
2739 -- END IF;
2740
2741
2742 -- Standard check for p_commit
2743 IF FND_API.to_Boolean( p_commit )
2744 THEN
2745 COMMIT WORK;
2746 END IF;
2747
2748 EXCEPTION
2749 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2750 ROLLBACK to PROCESS_OPER_COMP_TXN_PVT ;
2751 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2752
2753 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
2754 p_count => x_msg_count,
2755 p_data => x_msg_data);
2756
2757 IF ( FND_LOG.LEVEL_EXCEPTION >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
2758 FND_LOG.STRING( FND_LOG.LEVEL_EXCEPTION,
2759 lc_mod_name||'unx_exception',
2760 'G_EXC_UNEXPECTED_ERROR Exception');
2761 END IF;
2762
2763
2764 WHEN FND_API.G_EXC_ERROR THEN
2765 ROLLBACK to PROCESS_OPER_COMP_TXN_PVT ;
2766 x_return_status := FND_API.G_RET_STS_ERROR;
2767
2768
2769 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
2770 p_count => x_msg_count,
2771 p_data => x_msg_data);
2772
2773 IF ( FND_LOG.LEVEL_ERROR >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
2774 FND_LOG.STRING( FND_LOG.LEVEL_ERROR,
2775 lc_mod_name||'exc_exception',
2776 'G_EXC_ERROR Exception');
2777 END IF;
2778
2779 WHEN OTHERS THEN
2780 ROLLBACK to PROCESS_OPER_COMP_TXN_PVT ;
2781 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2782
2783 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
2784
2785 -- Add Unexpected Error to Message List, here SQLERRM is used for
2786 -- getting the error
2787
2788 FND_MSG_PUB.add_exc_msg(p_pkg_name => G_PKG_NAME,
2789 p_procedure_name => lc_api_name );
2790 END IF;
2791
2792 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
2793 p_count => x_msg_count,
2794 p_data => x_msg_data);
2795
2796 IF ( FND_LOG.LEVEL_EXCEPTION >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
2797 FND_LOG.STRING( FND_LOG.LEVEL_EXCEPTION,
2798 lc_mod_name||'others_exception',
2799 'OTHERS Exception');
2800 END IF;
2801
2802 END process_oper_comp_txn;
2803
2804
2805
2806 PROCEDURE process_issue_mtl_txn
2807 (
2808 p_api_version_number IN NUMBER,
2809 p_init_msg_list IN VARCHAR2,
2810 p_commit IN VARCHAR2,
2811 p_validation_level IN NUMBER,
2812 x_return_status OUT NOCOPY VARCHAR2,
2813 x_msg_count OUT NOCOPY NUMBER,
2814 x_msg_data OUT NOCOPY VARCHAR2,
2815 p_mtl_txn_dtls_tbl IN MTL_TXN_DTLS_TBL_TYPE,
2816 -- p_ro_quantity IN NUMBER,
2817 x_transaction_header_id OUT NOCOPY NUMBER
2818 )
2819 IS
2820
2821 lc_api_name CONSTANT VARCHAR2(30) := 'PROCESS_ISSUE_MTL_TXN';
2822 lc_api_version_number CONSTANT NUMBER := 1.0;
2823
2824 -- constants used for FND_LOG debug messages
2825
2826 lc_mod_name VARCHAR2(2000) := 'csd.plsql.csd_hv_wip_job_pvt.process_issue_mtl_txn';
2827
2828
2829 lc_revision_controlled CONSTANT NUMBER := 2;
2830 lc_full_lot_control CONSTANT NUMBER := 2;
2831 lc_predefined_serial_control CONSTANT NUMBER := 2;
2832 lc_inven_rct_srl_control CONSTANT NUMBER := 5;
2833
2834 lc_predfn_loc_cntrl CONSTANT NUMBER := 2;
2835 lc_dyn_loc_cntrl CONSTANT NUMBER := 3;
2836 lc_subinv_lv_loc_cntrl CONSTANT NUMBER := 4;
2837 lc_inv_lv_loc_cntrl CONSTANT NUMBER := 5;
2838 lc_MTI_source_table CONSTANT NUMBER := 1;
2839
2840
2841 -- Constants Used for Inserting into wip_job_schedule_interface,
2842 -- and details interface tables
2843
2844 lc_non_std_update_load_type CONSTANT NUMBER := 3;
2845 --lc_non_std_update_load_type CONSTANT NUMBER := 9;
2846 lc_load_mtl_type CONSTANT NUMBER := 2;
2847 lc_substitution_change_type CONSTANT NUMBER := 3;
2848 -- lc_mrp_net_flag CONSTANT NUMBER := 1;
2849 -- 11/7/05
2850 -- lc_push_wip_supply_type CONSTANT NUMBER := 1;
2851
2852 -- Constants used for inserting into mtl_transactions_interface
2853
2854 lc_issue_source_code CONSTANT VARCHAR2(30) := 'WIP Issue';
2855 lc_wip_txn_source_type_id CONSTANT NUMBER := 5;
2856 lc_issue_txn_type CONSTANT NUMBER := 35;
2857 lc_wip_comp_return_txn_type CONSTANT NUMBER := 43;
2858 lc_non_std_wip_ent_type CONSTANT NUMBER := 3;
2859 lc_n_final_completion_flag CONSTANT VARCHAR2(1) := 'N' ;
2860
2861
2862 -- Records to hold the Job header,details
2863 -- and mtl_transactions_interface data
2864
2865 l_transactions_interface_rec mtl_transactions_interface%ROWTYPE;
2866 l_srl_nmbrs_interface_rec mtl_serial_numbers_interface%ROWTYPE;
2867 l_job_header_rec wip_job_schedule_interface%ROWTYPE;
2868 l_job_details_rec wip_job_dtls_interface%ROWTYPE;
2869
2870
2871
2872 l_table NUMBER;
2873 l_trans_count NUMBER;
2874 l_return_count NUMBER;
2875
2876 l_last_update_date DATE;
2877 l_last_updated_by NUMBER;
2878 l_last_update_login NUMBER;
2879
2880 l_locator_controlled VARCHAR2(1) := 'F';
2881
2882 l_wip_update_needed VARCHAR2(1) := 'F';
2883
2884 l_row_need_details_flag VARCHAR2(1) := 'F';
2885 l_need_details_flag VARCHAR2(1) := 'F';
2886 l_location_control_code NUMBER;
2887 l_primary_qty NUMBER;
2888
2889 -- swai: bug 13820264, FP of bug#13797285, subhat
2890 -- FedEx materials update.
2891 TYPE job_ids_tbl IS TABLE OF VARCHAR2(1) INDEX BY BINARY_INTEGER;
2892 l_job_ids_tbl job_ids_tbl;
2893 l_counter NUMBER;
2894 l_use_wip_entity_id BOOLEAN;
2895 -- end swai: bug 13820264, FP of bug#13797285, subhat
2896
2897
2898 CURSOR get_mtl_header_id IS
2899 SELECT mtl_material_transactions_s.nextval from dual;
2900
2901 CURSOR get_org_locator_control_code(p_organization_id NUMBER) IS
2902 SELECT stock_locator_control_code from mtl_parameters
2903 where organization_id = p_organization_id;
2904
2905 CURSOR get_si_locator_control_code ( p_organization_id NUMBER,
2906 p_secondary_inventory_name VARCHAR2 ) IS
2907 SELECT locator_type from mtl_secondary_inventories where
2908 organization_id = p_organization_id and
2909 secondary_inventory_name = p_secondary_inventory_name;
2910
2911 CURSOR get_inv_location_control_code ( p_organization_id NUMBER,
2912 p_inventory_item_id NUMBER ) IS
2913 select location_control_code from mtl_system_items_b where
2914 organization_id = p_organization_id and
2915 inventory_item_id = p_inventory_item_id;
2916
2917
2918
2919
2920 BEGIN
2921
2922 IF ( FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
2923 FND_LOG.STRING( FND_LOG.LEVEL_PROCEDURE,
2924 lc_mod_name||'begin',
2925 'Entering private API process_issue_mtl_txn' );
2926 END IF;
2927
2928 SAVEPOINT PROCESS_ISSUE_MTL_TXN_PVT;
2929 -- Standard call to check for call compatibility.
2930 IF NOT FND_API.Compatible_API_Call
2931 (lc_api_version_number,
2932 p_api_version_number,
2933 lc_api_name,
2934 G_PKG_NAME)
2935 THEN
2936 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2937 END IF;
2938
2939
2940 IF FND_API.to_boolean(p_init_msg_list) THEN
2941 FND_MSG_PUB.initialize;
2942 END IF;
2943
2944
2945
2946
2947 x_return_status := FND_API.G_RET_STS_SUCCESS;
2948
2949 -- x_need_details_flag := 'F';
2950
2951
2952
2953 -- Populate the constant values
2954
2955
2956 l_table := lc_MTI_source_table;
2957
2958
2959 -- Populate the row who columns
2960
2961 l_last_update_date := SYSDATE;
2962 l_last_updated_by := fnd_global.user_id;
2963 l_last_update_login := fnd_global.login_id;
2964
2965
2966 -- generate transaction_header_id
2967 open get_mtl_header_id;
2968 fetch get_mtl_header_id into l_transactions_interface_rec.transaction_header_id;
2969 close get_mtl_header_id;
2970
2971
2972 l_transactions_interface_rec.source_code := lc_issue_source_code;
2973
2974 l_transactions_interface_rec.transaction_date := sysdate;
2975 l_transactions_interface_rec.transaction_source_type_id := lc_wip_txn_source_type_id;
2976 --check/verify above again
2977
2978
2979 l_transactions_interface_rec.wip_entity_type := lc_non_std_wip_ent_type;
2980 l_transactions_interface_rec.final_completion_flag := lc_n_final_completion_flag;
2981
2982
2983 -- Populate the constant values
2984
2985 l_job_header_rec.load_type := lc_non_std_update_load_type;
2986
2987 l_job_details_rec.date_required := sysdate;
2988 l_job_details_rec.load_type := lc_load_mtl_type;
2989
2990 l_job_details_rec.substitution_type := lc_substitution_change_type;
2991
2992 -- l_job_details_rec.mrp_net_flag := lc_mrp_net_flag;
2993 -- 11/7/05
2994 -- l_job_details_rec.wip_supply_type := lc_push_wip_supply_type;
2995 l_job_details_rec.wip_supply_type := null;
2996 -- Get the Group_id to be used for WIP Mass Load,
2997
2998 SELECT wip_job_schedule_interface_s.NEXTVAL INTO l_job_header_rec.group_id FROM dual;
2999
3000 -- l_job_header_rec.group_id := l_job_header_rec.header_id;
3001
3002 l_job_details_rec.group_id := l_job_header_rec.group_id;
3003 /* l_job_details_rec.parent_header_id := l_job_header_rec.group_id;
3004
3005 */
3006 -- l_completion_subinv := nvl( p_completion_subinv, fnd_profile.value('CSD_HV_COMP_SUBINV')) ;
3007 -- l_completion_loc_id : nvl( p_completion_loc_id, fnd_profile.value('CSD_HV_COMP_LOC_ID'));
3008
3009
3010
3011 FOR mtl_ctr in p_mtl_txn_dtls_tbl.FIRST.. p_mtl_txn_dtls_tbl.LAST
3012
3013 LOOP
3014
3015 l_transactions_interface_rec.transaction_quantity := (-1) * p_mtl_txn_dtls_tbl(mtl_ctr).transaction_quantity;
3016
3017 If l_transactions_interface_rec.transaction_quantity = 0 then
3018 FND_MESSAGE.SET_NAME('CSD','CSD_ISS_QTY_ZERO');
3019 FND_MSG_PUB.ADD;
3020 RAISE FND_API.G_EXC_ERROR;
3021 end if;
3022
3023
3024 l_transactions_interface_rec.transaction_uom := p_mtl_txn_dtls_tbl(mtl_ctr).transaction_uom;
3025 -- l_transactions_interface_rec.primary_quantity
3026 -- Need to check later for above
3027 l_transactions_interface_rec.organization_id := p_mtl_txn_dtls_tbl(mtl_ctr).organization_id;
3028 l_transactions_interface_rec.transaction_source_id := p_mtl_txn_dtls_tbl(mtl_ctr).wip_entity_id;
3029 l_transactions_interface_rec.source_header_id := p_mtl_txn_dtls_tbl(mtl_ctr).wip_entity_id;
3030 l_transactions_interface_rec.source_line_id := p_mtl_txn_dtls_tbl(mtl_ctr).operation_seq_num;
3031 l_transactions_interface_rec.operation_seq_num := p_mtl_txn_dtls_tbl(mtl_ctr).operation_seq_num;
3032
3033 l_transactions_interface_rec.reason_id := p_mtl_txn_dtls_tbl(mtl_ctr).reason_id; -- swai bug 6841113
3034
3035 -- swai: bug 13820264, FP of bug#13797285, subhat
3036 --FedEx materials update changes.
3037 IF NOT l_job_ids_tbl.EXISTS(p_mtl_txn_dtls_tbl(mtl_ctr).wip_entity_id)
3038 THEN
3039 l_job_ids_tbl(p_mtl_txn_dtls_tbl(mtl_ctr).wip_entity_id) := 'Y';
3040 END IF;
3041
3042 IF p_mtl_txn_dtls_tbl(mtl_ctr).wip_transaction_detail_id IS NULL
3043 THEN
3044 l_use_wip_entity_id := FALSE;
3045 END IF;
3046
3047 -- generate transaction_interface_id
3048 open get_mtl_header_id;
3049 fetch get_mtl_header_id into l_transactions_interface_rec.transaction_interface_id;
3050 close get_mtl_header_id;
3051
3052
3053 If p_mtl_txn_dtls_tbl(mtl_ctr).transaction_quantity > 0 then
3054
3055 l_transactions_interface_rec.transaction_type_id:= lc_issue_txn_type;
3056 else
3057
3058 l_transactions_interface_rec.transaction_type_id:= lc_wip_comp_return_txn_type;
3059
3060 end if;
3061
3062
3063 -- above needs to be issue or return from job - based on quantity
3064 -- entered . If negative quantity entered, then a negative issue
3065 -- ,meaning Return Job needs to be done
3066
3067 -- Need to do validation in the client, such that
3068 -- if the return quantity is > issued quantity, there
3069 -- should be an error message
3070
3071
3072 If p_mtl_txn_dtls_tbl(mtl_ctr).revision_qty_control_code = lc_revision_controlled then
3073 -- swai: bug 6995498/7182047 - revision is defaulted in the UI, so do not default
3074 -- behind the user's back in the API. Just get value from record.
3075 l_transactions_interface_rec.revision := p_mtl_txn_dtls_tbl(mtl_ctr).revision;
3076
3077 -- dbms_output.put_line( 'revision is ' || l_transactions_interface_rec.revision );
3078 If l_transactions_interface_rec.revision is null then
3079 l_row_need_details_flag := 'T';
3080 end if;
3081
3082 end if;
3083
3084 l_transactions_interface_rec.inventory_item_id := p_mtl_txn_dtls_tbl(mtl_ctr).inventory_item_id;
3085
3086 If p_mtl_txn_dtls_tbl(mtl_ctr).supply_subinventory is not null THEN
3087
3088 l_transactions_interface_rec.subinventory_code := p_mtl_txn_dtls_tbl(mtl_ctr).supply_subinventory;
3089
3090 ELSE
3091
3092 IF fnd_profile.value('CSD_DEF_REP_INV_ORG') = p_mtl_txn_dtls_tbl(mtl_ctr).organization_id and
3093 fnd_profile.value('CSD_DEF_HV_SUBINV') is not null THEN
3094 l_transactions_interface_rec.subinventory_code := fnd_profile.value('CSD_DEF_HV_SUBINV');
3095 ELSE
3096 l_row_need_details_flag := 'T';
3097 END IF;
3098 END IF;
3099
3100 -- l_locator_controlled := Call Inventory procedure to get this
3101
3102 -- Get Locator Control
3103
3104 open get_org_locator_control_code ( l_transactions_interface_rec.organization_id ) ;
3105 fetch get_org_locator_control_code into l_location_control_code ;
3106 close get_org_locator_control_code;
3107
3108 If l_location_control_code = lc_subinv_lv_loc_cntrl THEN
3109
3110 If l_transactions_interface_rec.subinventory_code is not null THEN
3111 open get_si_locator_control_code ( l_transactions_interface_rec.organization_id ,
3112 l_transactions_interface_rec.subinventory_code ) ;
3113 fetch get_si_locator_control_code into l_location_control_code ;
3114 close get_si_locator_control_code;
3115
3116 If l_location_control_code = lc_inv_lv_loc_cntrl THEN
3117
3118
3119 open get_inv_location_control_code ( l_transactions_interface_rec.organization_id ,
3120 l_transactions_interface_rec.inventory_item_id ) ;
3121 fetch get_inv_location_control_code into l_location_control_code ;
3122 close get_inv_location_control_code;
3123
3124 end if;
3125
3126
3127 end If;
3128
3129 end if;
3130
3131
3132 If l_location_control_code in ( lc_predfn_loc_cntrl ,
3133 lc_dyn_loc_cntrl ) THEN
3134
3135 l_locator_controlled := 'T' ;
3136
3137 end if;
3138
3139
3140 -- dbms_output.put_line( 'l_locator_contrl is'
3141 -- || l_locator_controlled );
3142
3143
3144
3145 If l_locator_controlled = 'T' THEN
3146
3147 IF p_mtl_txn_dtls_tbl(mtl_ctr).supply_locator_id is not null THEN
3148
3149 -- dbms_output.put_line( 'p_mtl_txn_dtls_tbl(mtl_ctr).supply_locator_id is'
3150 -- || p_mtl_txn_dtls_tbl(mtl_ctr).supply_locator_id );
3151
3152 l_transactions_interface_rec.locator_id := p_mtl_txn_dtls_tbl(mtl_ctr).supply_locator_id;
3153
3154 ELSE
3155
3156 /* IF fnd_profile.value('CSD_DEF_REP_INV_ORG') = p_mtl_txn_dtls_tbl(mtl_ctr).organization_id and
3157 fnd_profile.value('CSD_DEF_HV_LOC_ID') is not null THEN
3158
3159
3160 l_transactions_interface_rec.locator_id := fnd_profile.value('CSD_DEF_HV_LOC_ID');
3161 dbms_output.put_line( 'l_transactions_interface_rec.locator_id is'
3162 || l_transactions_interface_rec.locator_id );
3163
3164 ELSE */
3165
3166 l_row_need_details_flag := 'T';
3167 -- END IF;
3168 END IF;
3169 END IF;
3170
3171 -- Lot Contrrolled Check
3172 -- Later Need to handle it here as well - based on profile
3173 -- Value
3174
3175 IF p_mtl_txn_dtls_tbl(mtl_ctr).lot_control_code
3176 = lc_full_lot_control THEN
3177
3178 l_row_need_details_flag := 'T' ;
3179
3180 END IF;
3181
3182
3183
3184 IF p_mtl_txn_dtls_tbl(mtl_ctr).serial_number_control_code
3185 in ( lc_predefined_serial_control, lc_inven_rct_srl_control) THEN
3186
3187 IF ( abs(p_mtl_txn_dtls_tbl(mtl_ctr).transaction_quantity) > 1 ) THEN
3188
3189
3190 l_row_need_details_flag := 'T' ;
3191
3192
3193 If p_mtl_txn_dtls_tbl(mtl_ctr).transaction_quantity > 0 then
3194
3195 l_transactions_interface_rec.transaction_quantity := -1;
3196 else
3197
3198 l_transactions_interface_rec.transaction_quantity := 1;
3199 end if;
3200
3201
3202 FOR l_qty_ctr IN 1..abs(p_mtl_txn_dtls_tbl(mtl_ctr).transaction_quantity)
3203 LOOP
3204
3205
3206 --insert into table mtl_transactions_interface
3207
3208 IF ( FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
3209 FND_LOG.STRING( FND_LOG.LEVEL_EVENT,
3210 lc_mod_name||'beforecallinserttxnshdr',
3211 'Just before calling insert_transactions_header');
3212 END IF;
3213
3214 l_transactions_interface_rec.source_line_id := -1;
3215 -- -1 identifies rows which are queried up in the details UI
3216
3217
3218 insert_transactions_header( p_transactions_interface_rec => l_transactions_interface_rec,
3219 x_return_status => x_return_status );
3220
3221
3222 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
3223 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3224 END IF;
3225
3226 IF l_qty_ctr <> p_mtl_txn_dtls_tbl(mtl_ctr).transaction_quantity THEN
3227 -- generate transaction_interface_id for the next record
3228 open get_mtl_header_id;
3229 fetch get_mtl_header_id into l_transactions_interface_rec.transaction_interface_id;
3230 close get_mtl_header_id;
3231 END IF;
3232
3233
3234 END LOOP;
3235
3236 ELSE -- quantity =1, serial controlled
3237
3238 IF p_mtl_txn_dtls_tbl(mtl_ctr).lot_control_code
3239 <> lc_full_lot_control THEN
3240
3241
3242 IF ( p_mtl_txn_dtls_tbl(mtl_ctr).serial_number is not null ) then
3243
3244
3245 l_srl_nmbrs_interface_rec.transaction_interface_id := l_transactions_interface_rec.transaction_interface_id;
3246
3247 l_srl_nmbrs_interface_rec.fm_serial_number := p_mtl_txn_dtls_tbl(mtl_ctr).serial_number;
3248
3249 IF ( FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
3250 FND_LOG.STRING( FND_LOG.LEVEL_EVENT,
3251 lc_mod_name||'beforecallinsertsrlnmbrs',
3252 'Just before calling insert_upd_serial_numbers');
3253 END IF;
3254
3255
3256 insert_upd_serial_numbers( p_srl_nmbrs_interface_rec => l_srl_nmbrs_interface_rec,
3257 x_return_status => x_return_status );
3258
3259
3260 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
3261 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3262 END IF;
3263
3264 ELSE
3265
3266 l_row_need_details_flag := 'T';
3267
3268 END IF;
3269
3270
3271 END IF;
3272
3273
3274 If l_row_need_details_flag = 'T' then
3275
3276 l_transactions_interface_rec.source_line_id := -1;
3277 -- -1 identifies rows which are queried up in the details UI
3278 end if;
3279
3280 --insert into table mtl_transactions_interface
3281
3282 IF ( FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
3283 FND_LOG.STRING( FND_LOG.LEVEL_EVENT,
3284 lc_mod_name||'beforecallinserttxnshdr',
3285 'Just before calling insert_transactions_header');
3286 END IF;
3287
3288
3289
3290 insert_transactions_header( p_transactions_interface_rec => l_transactions_interface_rec,
3291 x_return_status => x_return_status );
3292
3293
3294 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
3295 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3296 END IF;
3297
3298
3299
3300 END IF;
3301
3302
3303 ELSE -- not serial controlled
3304
3305
3306 IF l_row_need_details_flag = 'T' THEN
3307
3308 l_transactions_interface_rec.source_line_id := -1;
3309 -- -1 identifies rows which are queried up in the details UI
3310 END IF;
3311
3312
3313 --insert into table mtl_transactions_interface
3314
3315 IF ( FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
3316 FND_LOG.STRING( FND_LOG.LEVEL_EVENT,
3317 lc_mod_name||'beforecallinserttxnshdr',
3318 'Just before calling insert_transactions_header');
3319 END IF;
3320
3321
3322 insert_transactions_header( p_transactions_interface_rec => l_transactions_interface_rec,
3323 x_return_status => x_return_status );
3324
3325
3326 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
3327 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3328 END IF;
3329
3330 END IF;
3331
3332 -- Here, check if required_quantity for the material is
3333 -- equal to (issued_quantity + transaction_quantity) ,
3334 -- Only if it is different, need to populate and call wip
3335 -- update program
3336
3337 l_primary_qty := INV_CONVERT.INV_UM_CONVERT
3338 ( item_id => l_transactions_interface_rec.inventory_item_id
3339 , lot_number => null
3340 , organization_id => l_transactions_interface_rec.organization_id
3341 , precision => 5
3342 , from_quantity => p_mtl_txn_dtls_tbl(mtl_ctr).transaction_quantity
3343 , from_unit => l_transactions_interface_rec.transaction_uom
3344 , to_unit => p_mtl_txn_dtls_tbl(mtl_ctr).uom_code
3345 , from_name => NULL
3346 , to_name => NULL);
3347
3348 -- dbms_output.put_line('primary qty is ' || l_primary_qty );
3349
3350 l_job_details_rec.required_quantity :=
3351 nvl(p_mtl_txn_dtls_tbl(mtl_ctr).issued_quantity, 0)+
3352 l_primary_qty;
3353 -- p_mtl_txn_dtls_tbl(mtl_ctr).transaction_quantity;
3354
3355 -- l_job_details_rec.required_quantity := 60;
3356
3357 If l_job_details_rec.required_quantity <> p_mtl_txn_dtls_tbl(mtl_ctr).required_quantity THEN
3358 l_wip_update_needed := 'T' ;
3359
3360
3361 -- Get the Group_id to be used for WIP Mass Load,
3362
3363 SELECT wip_job_schedule_interface_s.NEXTVAL INTO l_job_header_rec.header_id FROM dual;
3364
3365 -- l_job_header_rec.group_id := l_job_header_rec.header_id;
3366
3367 -- l_job_details_rec.group_id := l_job_header_rec.header_id;
3368 l_job_details_rec.parent_header_id := l_job_header_rec.header_id;
3369
3370
3371
3372 -- SELECT wip_job_schedule_interface_s.NEXTVAL INTO l_job_header_rec.interface_id FROM dual;
3373
3374
3375 --Commenting out as don't think this is needed
3376 -- Need to remove ro_quantity as well, later on if not neede
3377 l_job_details_rec.quantity_per_assembly := l_job_details_rec.required_quantity / p_mtl_txn_dtls_tbl(mtl_ctr).job_quantity;
3378
3379 -- l_job_details_rec.quantity_per_assembly := 3;
3380
3381 l_job_header_rec.wip_entity_id := p_mtl_txn_dtls_tbl(mtl_ctr).wip_entity_id;
3382 l_job_header_rec.organization_id := p_mtl_txn_dtls_tbl(mtl_ctr).organization_id;
3383
3384 l_job_details_rec.inventory_item_id_old := p_mtl_txn_dtls_tbl(mtl_ctr).inventory_item_id;
3385 l_job_details_rec.operation_seq_num := p_mtl_txn_dtls_tbl(mtl_ctr).operation_seq_num;
3386 l_job_details_rec.organization_id := p_mtl_txn_dtls_tbl(mtl_ctr).organization_id;
3387
3388 l_job_details_rec.wip_entity_id := p_mtl_txn_dtls_tbl(mtl_ctr).wip_entity_id;
3389
3390 -- Call procedures to insert job header and job details information
3391 -- into wip interface tables
3392
3393 IF ( FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
3394 FND_LOG.STRING( FND_LOG.LEVEL_EVENT,
3395 lc_mod_name||'beforecallinsertjob',
3396 'Just before calling insert_job_header');
3397 END IF;
3398
3399
3400 insert_job_header( p_job_header_rec => l_job_header_rec,
3401 x_return_status => x_return_status );
3402
3403
3404 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
3405 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3406 END IF;
3407
3408
3409 IF ( FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
3410 FND_LOG.STRING( FND_LOG.LEVEL_EVENT,
3411 lc_mod_name||'beforecallinsertjobdtls',
3412 'Just before calling insert_job_details');
3413 END IF;
3414
3415 /* dbms_output.put_line('ll_job_details_rec.required_quantity is '
3416 || l_job_details_rec.required_quantity );
3417
3418 dbms_output.put_line('ll_job_details_rec.quantity_per_assembly is '
3419 || l_job_details_rec.quantity_per_assembly ); */
3420
3421 insert_job_details( p_job_details_rec => l_job_details_rec,
3422 x_return_status => x_return_status );
3423
3424 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
3425 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3426 END IF;
3427
3428
3429 END IF;
3430
3431
3432 ---- Update CSD_WIP_TRANSACTION_DETAILS rows to have null values
3433
3434 If p_mtl_txn_dtls_tbl(mtl_ctr).WIP_TRANSACTION_DETAIL_ID is not null then
3435
3436 IF ( FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
3437 FND_LOG.STRING( FND_LOG.LEVEL_EVENT,
3438 lc_mod_name||'beforecallupdaterow',
3439 'Just before calling CSD_WIP_TRANSACTION_DTLS_PKG.Update_Row');
3440 END IF;
3441
3442 -- yvchen: bug 13258460
3443 -- 12.1.3+ adding DFFs - instead of deleting the row, update it
3444 -- so that the the DFFs are not deleted.
3445 -- null out transaction qty, uom, serial number, revision, and reason id
3446 -- table handler uses g_miss to indicate nulling out
3447 CSD_WIP_TRANSACTION_DTLS_PKG.Update_Row(
3448 p_WIP_TRANSACTION_DETAIL_ID => p_mtl_txn_dtls_tbl(mtl_ctr).WIP_TRANSACTION_DETAIL_ID
3449 ,p_CREATED_BY => null
3450 ,p_CREATION_DATE => null
3451 ,p_LAST_UPDATED_BY => l_last_updated_by
3452 ,p_LAST_UPDATE_DATE => l_last_update_date
3453 ,p_LAST_UPDATE_LOGIN => l_last_update_login
3454 ,p_INVENTORY_ITEM_ID => null
3455 ,p_WIP_ENTITY_ID => null
3456 ,p_OPERATION_SEQ_NUM => null
3457 ,p_RESOURCE_SEQ_NUM => null
3458 ,p_employee_id => null
3459 ,p_TRANSACTION_QUANTITY => FND_API.G_MISS_NUM
3460 ,p_TRANSACTION_UOM => FND_API.G_MISS_CHAR
3461 ,p_SERIAL_NUMBER => FND_API.G_MISS_CHAR
3462 ,p_REVISION => FND_API.G_MISS_CHAR
3463 ,p_REASON_ID => FND_API.G_MISS_NUM
3464 ,p_BACKFLUSH_FLAG => null
3465 ,p_COUNT_POINT_TYPE => null
3466 ,p_DEPARTMENT_ID => null
3467 ,p_DESCRIPTION => null
3468 ,p_FIRST_UNIT_COMPLETION_DATE => null
3469 ,p_FIRST_UNIT_START_DATE => null
3470 ,p_LAST_UNIT_COMPLETION_DATE => null
3471 ,p_LAST_UNIT_START_DATE => null
3472 ,p_MINIMUM_TRANSFER_QUANTITY => null
3473 ,p_STANDARD_OPERATION_ID => null
3474 ,p_OBJECT_VERSION_NUMBER => p_mtl_txn_dtls_tbl(mtl_ctr).object_version_number
3475 ,p_CREATE_RO_FLAG => nvl(p_mtl_txn_dtls_tbl(mtl_ctr).CREATE_RO_FLAG, FND_API.G_MISS_CHAR) -- bug#13698799 auto create ro, parent ro
3476 );
3477 /*
3478 CSD_WIP_TRANSACTION_DTLS_PKG.Delete_Row(
3479 p_WIP_TRANSACTION_DETAIL_ID => p_mtl_txn_dtls_tbl(mtl_ctr).WIP_TRANSACTION_DETAIL_ID );
3480 */
3481 end if;
3482
3483 IF l_row_need_details_flag = 'T' THEN
3484
3485 l_row_need_details_flag := 'F';
3486 l_need_details_flag := 'T' ;
3487
3488 END IF;
3489
3490 END LOOP;
3491
3492 IF l_need_details_flag = 'T' THEN
3493
3494 x_transaction_header_id := l_transactions_interface_rec.transaction_header_id;
3495
3496 END IF;
3497
3498 IF ( FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
3499 FND_LOG.STRING( FND_LOG.LEVEL_EVENT,
3500 lc_mod_name||'beforecallprocesstxns',
3501 'Just before calling INV_TXN_MANAGER_PUB.process_Transactions');
3502 END IF;
3503
3504 -- dbms_output.put_line('Before call to INV_TXN_MANAGER_PUB.process_Transactions');
3505
3506 -- If transaction_header_id is null, then details are not needed
3507 IF l_need_details_flag = 'F' THEN
3508
3509 l_return_count := INV_TXN_MANAGER_PUB.process_Transactions(
3510 p_api_version => lc_api_version_number, --1.0, -- ,
3511 p_init_msg_list => fnd_api.g_false, --'T', -- fnd_api.g_false ,
3512 p_commit => fnd_api.g_false, --'T', -- fnd_api.g_false ,
3513 p_validation_level => p_validation_level ,
3514 x_return_status => x_return_status,
3515 x_msg_count => x_msg_count,
3516 x_msg_data => x_msg_data,
3517 x_trans_count => l_trans_count,
3518 p_table => l_table,
3519 p_header_id => l_transactions_interface_rec.transaction_header_id );
3520
3521
3522 If ( txn_int_error_exists( l_transactions_interface_rec.transaction_header_id ) or
3523 x_return_status <> FND_API.G_RET_STS_SUCCESS ) THEN
3524 -- x_msg_data := x_msg_data||' after pt ' ;
3525 -- ROLLBACK to PROCESS_ISSUE_MTL_TXN_PVT ;
3526
3527
3528 -- IF nvl( x_msg_count, 0 ) = 0 THEN
3529
3530 FND_MESSAGE.SET_NAME('CSD','CSD_MAT_TXN_FAILURE');
3531 FND_MSG_PUB.ADD;
3532
3533 RAISE FND_API.G_EXC_ERROR;
3534
3535 -- END IF;
3536
3537
3538
3539 -- RETURN;
3540
3541 END IF;
3542
3543 END IF;
3544
3545
3546
3547 -- Call WIP Mass Load API
3548
3549 -- Comment out for now - till WIP API works - Uncomment later
3550
3551 IF l_wip_update_needed = 'T' THEN
3552
3553 -- dbms_output.put_line('before WIP Update Call');
3554
3555 BEGIN
3556
3557 -- swai: bug 16092967, FP of bug 14804273 change commitFlag to 0 so that transaction
3558 -- can be rolled back if user cancels
3559 WIP_MASSLOAD_PUB.massLoadJobs(p_groupID => l_job_header_rec.group_id,
3560 p_validationLevel => p_validation_level,
3561 p_commitFlag => 0,-- needs to be changed to 0 later, once WIP works
3562 x_returnStatus => x_return_status,
3563 x_errorMsg => x_msg_data );
3564
3565
3566 If ( ml_error_exists( l_job_header_rec.group_id ) or
3567 x_return_status <> FND_API.G_RET_STS_SUCCESS ) THEN
3568
3569
3570 FND_MESSAGE.SET_NAME('CSD','CSD_MTL_ISS_MASS_LD_FAILURE');
3571 FND_MSG_PUB.ADD;
3572 x_return_status := FND_API.G_RET_STS_ERROR;
3573
3574 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
3575 p_count => x_msg_count,
3576 p_data => x_msg_data);
3577
3578 RETURN;
3579 -- Need to rollback Raise exception -
3580 -- once commit is removed from above call
3581
3582 end if;
3583
3584 --bug#12316893
3585 IF (nvl(fnd_profile.value('MRP_DEBUG'),'Y') = 'N') THEN
3586 WIP_MASS_LOAD_PROCESSOR.Delete_Completed_Records(l_job_header_rec.group_id);
3587 End If;
3588 --bug#12316893
3589
3590
3591 EXCEPTION
3592 WHEN OTHERS THEN
3593
3594 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3595
3596 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
3597
3598 -- Add Unexpected Error to Message List, here SQLERRM is used for
3599 -- getting the error
3600
3601 FND_MSG_PUB.add_exc_msg(p_pkg_name => G_PKG_NAME,
3602 p_procedure_name => lc_api_name );
3603 END IF;
3604
3605 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
3606 p_count => x_msg_count,
3607 p_data => x_msg_data);
3608
3609 END;
3610
3611
3612 /* IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
3613 -- ROLLBACK to PROCESS_ISSUE_MTL_TXN_PVT ;
3614 -- dbms_output.put_line('WIP Update Error');
3615
3616
3617 FND_MESSAGE.SET_NAME('CSD','CSD_MAT_TXN_FAILURE');
3618 FND_MSG_PUB.ADD;
3619 RETURN; */
3620 -- RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3621
3622
3623 /* IF ( FND_LOG.LEVEL_ERROR >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
3624 FND_LOG.STRING( FND_LOG.LEVEL_ERROR,
3625 lc_mod_name||'exc_exception',
3626 'G_EXC_ERROR Exception');
3627 END IF;
3628
3629 RETURN; */
3630
3631 -- END IF;
3632 END IF;
3633
3634 -- subhat. FedEx materials region update.
3635 -- looks like the wip_transaction_detail id is very rarely populated by default. Calling the update
3636 -- materials procedure with wip_entity_id or repair line id is more beneficial.
3637 -- call this only if the material actually got transacted during the flow.
3638 -- swai: bug 13820264, FP of bug#13797285, subhat
3639 IF l_need_details_flag = 'F' AND l_use_wip_entity_id
3640 THEN
3641 l_counter := l_job_ids_tbl.FIRST;
3642 WHILE l_counter IS NOT NULL
3643 LOOP
3644 update_mat_issue_quantities
3645 (
3646 p_api_version_number => 1.0 ,
3647 p_init_msg_list => fnd_api.g_false ,
3648 p_commit => fnd_api.g_false ,
3649 p_validation_level => fnd_api.g_valid_level_none,
3650 x_return_status => x_return_status,
3651 x_msg_count => x_msg_count,
3652 x_msg_data => x_msg_data,
3653 p_repair_line_id => NULL,
3654 p_wip_entity_id => l_counter,
3655 p_wip_transaction_detail_id => NULL,
3656 p_transaction_type_id => NULL,
3657 p_quantity => NULL,
3658 p_exclude_closed_jobs => 'Y',
3659 p_transaction_date_start => NULL,
3660 p_transaction_date_end => NULL
3661 );
3662 l_counter := l_job_ids_tbl.NEXT(l_counter);
3663 END LOOP;
3664
3665 ELSIF l_need_details_flag = 'F'
3666 THEN
3667 FOR i IN 1 ..p_mtl_txn_dtls_tbl.COUNT
3668 LOOP
3669 update_mat_issue_quantities
3670 (
3671 p_api_version_number => 1.0 ,
3672 p_init_msg_list => fnd_api.g_false ,
3673 p_commit => fnd_api.g_false ,
3674 p_validation_level => fnd_api.g_valid_level_none,
3675 x_return_status => x_return_status,
3676 x_msg_count => x_msg_count,
3677 x_msg_data => x_msg_data,
3678 p_repair_line_id => NULL,
3679 p_wip_entity_id => NULL,
3680 p_wip_transaction_detail_id => p_mtl_txn_dtls_tbl(i).wip_transaction_detail_id,
3681 p_transaction_type_id => (CASE WHEN p_mtl_txn_dtls_tbl(i).transaction_quantity > 0 THEN 35 ELSE 43 END),
3682 p_quantity => p_mtl_txn_dtls_tbl(i).transaction_quantity*-1,
3683 p_exclude_closed_jobs => 'Y',
3684 p_transaction_date_start => NULL,
3685 p_transaction_date_end => NULL
3686 );
3687
3688 END LOOP;
3689
3690 END IF;
3691
3692
3693
3694 -- Standard check for p_commit
3695 IF l_need_details_flag = 'F' and FND_API.to_Boolean( p_commit )
3696 THEN
3697 COMMIT WORK;
3698 END IF;
3699
3700 EXCEPTION
3701 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
3702 -- dbms_output.put_line( 'FND_API.G_EXC_UNEXPECTED_ERROR error'|| sqlerrm);
3703 ROLLBACK to PROCESS_ISSUE_MTL_TXN_PVT ;
3704 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3705
3706 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
3707 p_count => x_msg_count,
3708 p_data => x_msg_data);
3709
3710 IF ( FND_LOG.LEVEL_EXCEPTION >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
3711 FND_LOG.STRING( FND_LOG.LEVEL_EXCEPTION,
3712 lc_mod_name||'unx_exception',
3713 'G_EXC_UNEXPECTED_ERROR Exception');
3714 END IF;
3715
3716
3717 WHEN FND_API.G_EXC_ERROR THEN
3718 ROLLBACK to PROCESS_ISSUE_MTL_TXN_PVT ;
3719 x_return_status := FND_API.G_RET_STS_ERROR;
3720
3721
3722 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
3723 p_count => x_msg_count,
3724 p_data => x_msg_data);
3725
3726 IF ( FND_LOG.LEVEL_ERROR >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
3727 FND_LOG.STRING( FND_LOG.LEVEL_ERROR,
3728 lc_mod_name||'exc_exception',
3729 'G_EXC_ERROR Exception');
3730 END IF;
3731
3732 WHEN OTHERS THEN
3733 -- dbms_output.put_line( 'OTHERS error' || sqlerrm );
3734 ROLLBACK to PROCESS_ISSUE_MTL_TXN_PVT ;
3735 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3736
3737 -- IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
3738
3739 -- Add Unexpected Error to Message List, here SQLERRM is used for
3740 -- getting the error
3741
3742 FND_MSG_PUB.add_exc_msg(p_pkg_name => G_PKG_NAME,
3743 p_procedure_name => lc_api_name );
3744 -- END IF;
3745
3746 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
3747 p_count => x_msg_count,
3748 p_data => x_msg_data);
3749
3750 IF ( FND_LOG.LEVEL_EXCEPTION >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
3751 FND_LOG.STRING( FND_LOG.LEVEL_EXCEPTION,
3752 lc_mod_name||'others_exception',
3753 'OTHERS Exception');
3754 END IF;
3755
3756
3757
3758 END process_issue_mtl_txn;
3759
3760 --
3761 -- Updates the transaction lines with lot and serial numbers
3762 -- and the processes the transaction lines
3763 --
3764 PROCEDURE process_issue_mtl_txns_lot_srl
3765 (
3766 p_api_version_number IN NUMBER,
3767 p_init_msg_list IN VARCHAR2,
3768 p_commit IN VARCHAR2,
3769 p_validation_level IN NUMBER,
3770 x_return_status OUT NOCOPY VARCHAR2,
3771 x_msg_count OUT NOCOPY NUMBER,
3772 x_msg_data OUT NOCOPY VARCHAR2,
3773 p_mtl_txn_dtls_tbl IN MTL_TXN_DTLS_TBL_TYPE,
3774 p_transaction_header_id IN NUMBER
3775 )
3776 IS
3777 lc_api_name CONSTANT VARCHAR2(30) := 'PROCESS_ISSUE_MTL_TXNS_LOT_SRL';
3778 lc_api_version_number CONSTANT NUMBER := 1.0;
3779
3780 -- constants used for FND_LOG debug messages
3781 lc_mod_name VARCHAR2(2000) := 'csd.plsql.csd_hv_wip_job_pvt.process_issue_mtl_txns_lot_srl';
3782
3783 BEGIN
3784 IF ( FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
3785 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE,
3786 lc_mod_name||'begin',
3787 'Entering private API process_issue_mtl_txns_lot_srl' );
3788 END IF;
3789
3790 SAVEPOINT PROCESS_MTL_TXNS_LOT_SRL_PVT;
3791 -- Standard call to check for call compatibility.
3792 IF NOT FND_API.Compatible_API_Call
3793 (lc_api_version_number,
3794 p_api_version_number,
3795 lc_api_name,
3796 G_PKG_NAME)
3797 THEN
3798 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3799 END IF;
3800
3801 IF FND_API.to_boolean(p_init_msg_list) THEN
3802 FND_MSG_PUB.initialize;
3803 END IF;
3804
3805 x_return_status := FND_API.G_RET_STS_SUCCESS;
3806
3807 IF ( FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
3808 FND_LOG.STRING( FND_LOG.LEVEL_EVENT,
3809 lc_mod_name||'beforecallinsertjobcomptxn',
3810 'Just before calling insert_job_comp_txn');
3811 END IF;
3812 update_mtl_txns_lot_srl (
3813 p_api_version_number => lc_api_version_number,
3814 p_init_msg_list => fnd_api.g_false ,
3815 p_commit => fnd_api.g_false,
3816 p_validation_level => p_validation_level,
3817 x_return_status => x_return_status,
3818 x_msg_count => x_msg_count,
3819 x_msg_data => x_msg_data,
3820 p_mtl_txn_dtls_tbl => p_mtl_txn_dtls_tbl,
3821 p_transaction_header_id => p_transaction_header_id
3822 );
3823 IF (x_return_status <> FND_API.G_RET_STS_SUCCESS ) THEN
3824 FND_MESSAGE.SET_NAME('CSD','CSD_MAT_TXN_FAILURE');
3825 FND_MSG_PUB.ADD;
3826 RAISE FND_API.G_EXC_ERROR;
3827 END IF;
3828
3829 IF ( FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
3830 FND_LOG.STRING( FND_LOG.LEVEL_EVENT,
3831 lc_mod_name||'beforecallprocesstxn',
3832 'Just before calling process_mti_transactions');
3833 END IF;
3834 process_mti_transactions(
3835 p_api_version_number => lc_api_version_number,
3836 p_init_msg_list => fnd_api.g_false ,
3837 p_commit => fnd_api.g_false,
3838 p_validation_level => p_validation_level,
3839 x_return_status => x_return_status,
3840 x_msg_count => x_msg_count,
3841 x_msg_data => x_msg_data,
3842 p_txn_header_id => p_transaction_header_id
3843 -- p_txn_type IN VARCHAR2
3844 );
3845 IF (x_return_status <> FND_API.G_RET_STS_SUCCESS ) THEN
3846 FND_MESSAGE.SET_NAME('CSD','CSD_MAT_TXN_FAILURE');
3847 FND_MSG_PUB.ADD;
3848 RAISE FND_API.G_EXC_ERROR;
3849 END IF;
3850
3851 -- Standard check for p_commit
3852 IF FND_API.to_Boolean( p_commit )
3853 THEN
3854 COMMIT WORK;
3855 END IF;
3856
3857 EXCEPTION
3858 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
3859 ROLLBACK to PROCESS_MTL_TXNS_LOT_SRL_PVT ;
3860 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3861
3862 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
3863 p_count => x_msg_count,
3864 p_data => x_msg_data);
3865
3866 IF ( FND_LOG.LEVEL_EXCEPTION >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
3867 FND_LOG.STRING( FND_LOG.LEVEL_EXCEPTION,
3868 lc_mod_name||'unx_exception',
3869 'G_EXC_UNEXPECTED_ERROR Exception');
3870 END IF;
3871
3872 WHEN FND_API.G_EXC_ERROR THEN
3873 ROLLBACK to PROCESS_MTL_TXNS_LOT_SRL_PVT ;
3874 x_return_status := FND_API.G_RET_STS_ERROR;
3875
3876 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
3877 p_count => x_msg_count,
3878 p_data => x_msg_data);
3879
3880 IF ( FND_LOG.LEVEL_ERROR >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
3881 FND_LOG.STRING( FND_LOG.LEVEL_ERROR,
3882 lc_mod_name||'exc_exception',
3883 'G_EXC_ERROR Exception');
3884 END IF;
3885
3886 WHEN OTHERS THEN
3887 ROLLBACK to PROCESS_MTL_TXNS_LOT_SRL_PVT ;
3888 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3889
3890 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
3891 -- Add Unexpected Error to Message List, here SQLERRM is used for
3892 -- getting the error
3893 FND_MSG_PUB.add_exc_msg(p_pkg_name => G_PKG_NAME,
3894 p_procedure_name => lc_api_name );
3895 END IF;
3896
3897 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
3898 p_count => x_msg_count,
3899 p_data => x_msg_data);
3900
3901 IF ( FND_LOG.LEVEL_EXCEPTION >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
3902 FND_LOG.STRING( FND_LOG.LEVEL_EXCEPTION,
3903 lc_mod_name||'others_exception',
3904 'OTHERS Exception');
3905 END IF;
3906 END process_issue_mtl_txns_lot_srl;
3907
3908 --
3909 -- Updates the material transaction lines with lot and serial numbers only
3910 -- Does NOT process the transaction lines
3911 --
3912 PROCEDURE update_mtl_txns_lot_srl
3913 (
3914 p_api_version_number IN NUMBER,
3915 p_init_msg_list IN VARCHAR2,
3916 p_commit IN VARCHAR2,
3917 p_validation_level IN NUMBER,
3918 x_return_status OUT NOCOPY VARCHAR2,
3919 x_msg_count OUT NOCOPY NUMBER,
3920 x_msg_data OUT NOCOPY VARCHAR2,
3921 p_mtl_txn_dtls_tbl IN MTL_TXN_DTLS_TBL_TYPE,
3922 p_transaction_header_id IN NUMBER
3923 )
3924 IS
3925 lc_api_name CONSTANT VARCHAR2(30) := 'UPDATE_MTL_TXNS_LOT_SRL';
3926 lc_api_version_number CONSTANT NUMBER := 1.0;
3927
3928 -- constants used for FND_LOG debug messages
3929 lc_mod_name VARCHAR2(2000) := 'csd.plsql.csd_hv_wip_job_pvt.update_mtl_txns_lot_srl';
3930
3931 lc_revision_controlled CONSTANT NUMBER := 2;
3932 lc_full_lot_control CONSTANT NUMBER := 2;
3933 lc_predefined_serial_control CONSTANT NUMBER := 2;
3934 lc_inven_rct_srl_control CONSTANT NUMBER := 5;
3935
3936 -- Records to hold mtl_transactions_interface data
3937 l_transactions_interface_rec mtl_transactions_interface%ROWTYPE;
3938 l_txn_lots_interface_rec mtl_transaction_lots_interface%ROWTYPE;
3939 l_srl_nmbrs_interface_rec mtl_serial_numbers_interface%ROWTYPE;
3940
3941 CURSOR get_mtl_header_id IS
3942 SELECT mtl_material_transactions_s.nextval from dual;
3943
3944 BEGIN
3945
3946 IF ( FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
3947 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE,
3948 lc_mod_name||'begin',
3949 'Entering private API update_mtl_txns_lot_srl' );
3950 END IF;
3951
3952 SAVEPOINT UPDATE_MTL_TXNS_LOT_SRL_PVT;
3953 -- Standard call to check for call compatibility.
3954 IF NOT FND_API.Compatible_API_Call
3955 (lc_api_version_number,
3956 p_api_version_number,
3957 lc_api_name,
3958 G_PKG_NAME)
3959 THEN
3960 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3961 END IF;
3962
3963 IF FND_API.to_boolean(p_init_msg_list) THEN
3964 FND_MSG_PUB.initialize;
3965 END IF;
3966
3967 x_return_status := FND_API.G_RET_STS_SUCCESS;
3968
3969 FOR mtl_ctr in p_mtl_txn_dtls_tbl.FIRST.. p_mtl_txn_dtls_tbl.LAST
3970 LOOP
3971 l_transactions_interface_rec.subinventory_code := p_mtl_txn_dtls_tbl(mtl_ctr).supply_subinventory;
3972 l_transactions_interface_rec.locator_id := p_mtl_txn_dtls_tbl(mtl_ctr).supply_locator_id;
3973 l_transactions_interface_rec.revision := p_mtl_txn_dtls_tbl(mtl_ctr).revision;
3974 l_transactions_interface_rec.transaction_interface_id := p_mtl_txn_dtls_tbl(mtl_ctr).transaction_interface_id;
3975 l_transactions_interface_rec.source_line_id := p_mtl_txn_dtls_tbl(mtl_ctr).operation_seq_num;
3976 l_transactions_interface_rec.reason_id := p_mtl_txn_dtls_tbl(mtl_ctr).reason_id; -- swai bug 6841113
3977
3978 --Update table mtl_transactions_interface
3979 IF ( FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
3980 FND_LOG.STRING( FND_LOG.LEVEL_EVENT,
3981 lc_mod_name||'beforecallupdtxnhdr',
3982 'Just before calling update_transactions_header');
3983 END IF;
3984
3985 update_transactions_header(p_transactions_interface_rec => l_transactions_interface_rec,
3986 x_return_status => x_return_status );
3987
3988 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
3989 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3990 END IF;
3991
3992 -- Check for Lot Control
3993 IF p_mtl_txn_dtls_tbl(mtl_ctr).lot_control_code = lc_full_lot_control THEN
3994 l_txn_lots_interface_rec.transaction_interface_id := l_transactions_interface_rec.transaction_interface_id;
3995 l_txn_lots_interface_rec.lot_number := p_mtl_txn_dtls_tbl(mtl_ctr).lot_number;
3996 l_txn_lots_interface_rec.transaction_quantity := p_mtl_txn_dtls_tbl(mtl_ctr).transaction_quantity;
3997
3998 IF p_mtl_txn_dtls_tbl(mtl_ctr).SERIAL_NUMBER_CONTROL_CODE in ( lc_predefined_serial_control , lc_inven_rct_srl_control ) THEN
3999 -- generate transaction_id
4000 open get_mtl_header_id;
4001 fetch get_mtl_header_id into l_txn_lots_interface_rec.serial_transaction_temp_id;
4002 close get_mtl_header_id;
4003
4004 l_srl_nmbrs_interface_rec.transaction_interface_id := l_txn_lots_interface_rec.serial_transaction_temp_id;
4005 l_srl_nmbrs_interface_rec.fm_serial_number := p_mtl_txn_dtls_tbl(mtl_ctr).serial_number;
4006
4007 IF ( FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
4008 FND_LOG.STRING(FND_LOG.LEVEL_EVENT,
4009 lc_mod_name||'beforecallinsertsrlnmbrs',
4010 'Just before calling insert_upd_serial_numbers');
4011 END IF;
4012
4013 insert_upd_serial_numbers(p_srl_nmbrs_interface_rec => l_srl_nmbrs_interface_rec,
4014 x_return_status => x_return_status);
4015
4016 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
4017 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4018 END IF;
4019 END IF;
4020
4021 IF ( FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
4022 FND_LOG.STRING(FND_LOG.LEVEL_EVENT,
4023 lc_mod_name||'beforecallinserttxnslots',
4024 'Just before calling insert_transaction_lots');
4025 END IF;
4026
4027 insert_transaction_lots(p_txn_lots_interface_rec => l_txn_lots_interface_rec,
4028 x_return_status => x_return_status );
4029
4030 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
4031 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4032 END IF;
4033 ELSE -- not lc_full_lot_control
4034 IF p_mtl_txn_dtls_tbl(mtl_ctr).SERIAL_NUMBER_CONTROL_CODE in ( lc_predefined_serial_control , lc_inven_rct_srl_control ) THEN
4035 l_srl_nmbrs_interface_rec.transaction_interface_id := l_transactions_interface_rec.transaction_interface_id;
4036 l_srl_nmbrs_interface_rec.fm_serial_number := p_mtl_txn_dtls_tbl(mtl_ctr).serial_number;
4037
4038 IF ( FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
4039 FND_LOG.STRING(FND_LOG.LEVEL_EVENT,
4040 lc_mod_name||'beforecallinsertsrlnbrs',
4041 'Just before calling insert_upd_serial_numbers');
4042 END IF;
4043
4044 insert_upd_serial_numbers(p_srl_nmbrs_interface_rec => l_srl_nmbrs_interface_rec,
4045 x_return_status => x_return_status );
4046
4047 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
4048 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4049 END IF;
4050 END IF;
4051 END IF; -- end lot control condition
4052 END LOOP;
4053
4054 -- Standard check for p_commit
4055 IF FND_API.to_Boolean( p_commit )
4056 THEN
4057 COMMIT WORK;
4058 END IF;
4059
4060 EXCEPTION
4061 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
4062 ROLLBACK to UPDATE_MTL_TXNS_LOT_SRL_PVT ;
4063 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4064
4065 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
4066 p_count => x_msg_count,
4067 p_data => x_msg_data);
4068
4069 IF ( FND_LOG.LEVEL_EXCEPTION >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
4070 FND_LOG.STRING( FND_LOG.LEVEL_EXCEPTION,
4071 lc_mod_name||'unx_exception',
4072 'G_EXC_UNEXPECTED_ERROR Exception');
4073 END IF;
4074
4075 WHEN FND_API.G_EXC_ERROR THEN
4076 ROLLBACK to UPDATE_MTL_TXNS_LOT_SRL_PVT ;
4077 x_return_status := FND_API.G_RET_STS_ERROR;
4078
4079 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
4080 p_count => x_msg_count,
4081 p_data => x_msg_data);
4082
4083 IF ( FND_LOG.LEVEL_ERROR >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
4084 FND_LOG.STRING( FND_LOG.LEVEL_ERROR,
4085 lc_mod_name||'exc_exception',
4086 'G_EXC_ERROR Exception');
4087 END IF;
4088
4089 WHEN OTHERS THEN
4090 ROLLBACK to UPDATE_MTL_TXNS_LOT_SRL_PVT ;
4091 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4092
4093 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
4094 -- Add Unexpected Error to Message List, here SQLERRM is used for
4095 -- getting the error
4096 FND_MSG_PUB.add_exc_msg(p_pkg_name => G_PKG_NAME,
4097 p_procedure_name => lc_api_name );
4098 END IF;
4099
4100 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
4101 p_count => x_msg_count,
4102 p_data => x_msg_data);
4103
4104 IF ( FND_LOG.LEVEL_EXCEPTION >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
4105 FND_LOG.STRING( FND_LOG.LEVEL_EXCEPTION,
4106 lc_mod_name||'others_exception',
4107 'OTHERS Exception');
4108 END IF;
4109 END update_mtl_txns_lot_srl;
4110
4111
4112 PROCEDURE process_transact_res_txn
4113 (
4114 p_api_version_number IN NUMBER,
4115 p_init_msg_list IN VARCHAR2,
4116 p_commit IN VARCHAR2,
4117 p_validation_level IN NUMBER,
4118 x_return_status OUT NOCOPY VARCHAR2,
4119 x_msg_count OUT NOCOPY NUMBER,
4120 x_msg_data OUT NOCOPY VARCHAR2,
4121 p_res_txn_dtls_tbl IN RES_TXN_DTLS_TBL_TYPE
4122 -- p_ro_quantity IN NUMBER
4123 )
4124 IS
4125
4126 lc_api_name CONSTANT VARCHAR2(30) := 'PROCESS_TRANSACT_RES_TXN';
4127 lc_api_version_number CONSTANT NUMBER := 1.0;
4128
4129 -- constants used for FND_LOG debug messages
4130
4131 lc_mod_name VARCHAR2(2000) := 'csd.plsql.csd_hv_wip_job_pvt.process_transact_res_txn';
4132
4133
4134 -- Constants Used for Inserting into wip_job_schedule_interface,
4135 -- and details interface tables
4136
4137 lc_non_std_update_load_type CONSTANT NUMBER := 3;
4138 lc_load_res_type CONSTANT NUMBER := 1;
4139 lc_substitution_change_type CONSTANT NUMBER := 3;
4140
4141
4142 -- Constants used for inserting into wip_cost_txn_interface
4143
4144 lc_res_transaction_type CONSTANT NUMBER := 1;
4145
4146
4147 -- Records to hold the Job header,details
4148 -- and wip_cost_txn_interface data
4149
4150 l_wip_cost_txn_interface_rec wip_cost_txn_interface%ROWTYPE;
4151 l_job_header_rec wip_job_schedule_interface%ROWTYPE;
4152 l_job_details_rec wip_job_dtls_interface%ROWTYPE;
4153
4154
4155 l_last_update_date DATE;
4156 l_last_updated_by NUMBER;
4157 l_last_update_login NUMBER;
4158
4159 l_required_quantity NUMBER;
4160
4161 l_wip_update_needed VARCHAR2(1) := 'F';
4162
4163 conversion_rate NUMBER;
4164 primary_qty NUMBER;
4165
4166
4167
4168 BEGIN
4169
4170 IF ( FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
4171 FND_LOG.STRING( FND_LOG.LEVEL_PROCEDURE,
4172 lc_mod_name||'begin',
4173 'Entering private API process_transact_res_txn' );
4174 END IF;
4175
4176 SAVEPOINT PROCESS_TRANSACT_RES_TXN_PVT;
4177 -- Standard call to check for call compatibility.
4178 IF NOT FND_API.Compatible_API_Call
4179 (lc_api_version_number,
4180 p_api_version_number,
4181 lc_api_name,
4182 G_PKG_NAME)
4183 THEN
4184 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4185 END IF;
4186
4187
4188 IF FND_API.to_boolean(p_init_msg_list) THEN
4189 FND_MSG_PUB.initialize;
4190 END IF;
4191
4192
4193
4194
4195 x_return_status := FND_API.G_RET_STS_SUCCESS;
4196
4197
4198 -- Populate the row who columns
4199
4200 l_last_update_date := SYSDATE;
4201 l_last_updated_by := fnd_global.user_id;
4202 l_last_update_login := fnd_global.login_id;
4203
4204
4205 -- Populate the constant values
4206
4207 l_job_header_rec.load_type := lc_non_std_update_load_type;
4208
4209 l_job_details_rec.completion_date := sysdate;
4210
4211 l_job_details_rec.load_type := lc_load_res_type;
4212
4213 l_job_details_rec.substitution_type := lc_substitution_change_type;
4214
4215
4216 -- l_job_details_rec.autocharge_type := fnd_profile.value('CSD_HV_ATCHG_TYP');
4217
4218 -- If autocharge_type is null, throw an error and return;
4219 -- Uncomment following later - once profiles are defined
4220 /* IF l_job_details_rec.autocharge_type is NULL THEN
4221
4222 FND_MESSAGE.SET_NAME('CSD','CSD_ATCHG_TYP_NULL');
4223 FND_MSG_PUB.ADD;
4224 RAISE FND_API.G_EXC_ERROR;
4225 end if;
4226
4227
4228 l_job_details_rec.basis_type := fnd_profile.value('CSD_HV_BASIS_TYP');
4229
4230 -- If basis_type is null, throw an error and return;
4231
4232 IF l_job_details_rec.basis_type is NULL THEN
4233
4234 FND_MESSAGE.SET_NAME('CSD','CSD_BASIS_TYP_NULL');
4235 FND_MSG_PUB.ADD;
4236 RAISE FND_API.G_EXC_ERROR;
4237 end if;
4238
4239 l_job_details_rec.scheduled_flag := fnd_profile.value('CSD_HV_SCD_FLG');
4240
4241 -- If scheduled_flag is null, throw an error and return;
4242
4243 IF l_job_details_rec.scheduled_flag is NULL THEN
4244
4245 FND_MESSAGE.SET_NAME('CSD','CSD_SCD_FLG_NULL');
4246 FND_MSG_PUB.ADD;
4247 RAISE FND_API.G_EXC_ERROR;
4248 end if;
4249
4250 l_job_details_rec.standard_rate_flag := fnd_profile.value('CSD_HV_STD_FLG');
4251
4252 -- If standard_rate_flag is null, throw an error and return;
4253
4254 IF l_job_details_rec.standard_rate_flag is NULL THEN
4255
4256 FND_MESSAGE.SET_NAME('CSD','CSD_STD_FLG_NULL');
4257 FND_MSG_PUB.ADD;
4258 RAISE FND_API.G_EXC_ERROR;
4259 end if; */
4260
4261 l_wip_cost_txn_interface_rec.transaction_date := sysdate;
4262 l_wip_cost_txn_interface_rec.transaction_type := lc_res_transaction_type;
4263
4264
4265 -- Get the Group_id to be used for WIP Mass Load,
4266
4267 SELECT wip_job_schedule_interface_s.NEXTVAL INTO l_job_header_rec.group_id FROM dual;
4268
4269 -- l_job_header_rec.group_id := l_job_header_rec.header_id;
4270
4271 l_job_details_rec.group_id := l_job_header_rec.group_id;
4272 -- l_job_details_rec.parent_header_id := l_job_header_rec.group_id;
4273
4274
4275
4276 FOR res_ctr in p_res_txn_dtls_tbl.FIRST.. p_res_txn_dtls_tbl.LAST
4277
4278 LOOP
4279
4280 l_wip_cost_txn_interface_rec.operation_seq_num := p_res_txn_dtls_tbl(res_ctr).operation_seq_num;
4281 l_wip_cost_txn_interface_rec.organization_id := p_res_txn_dtls_tbl(res_ctr).organization_id;
4282 l_wip_cost_txn_interface_rec.organization_code := p_res_txn_dtls_tbl(res_ctr).organization_code;
4283 l_wip_cost_txn_interface_rec.resource_seq_num := p_res_txn_dtls_tbl(res_ctr).resource_seq_num;
4284 l_wip_cost_txn_interface_rec.transaction_quantity := p_res_txn_dtls_tbl(res_ctr).transaction_quantity;
4285
4286 If l_wip_cost_txn_interface_rec.transaction_quantity = 0 then
4287 FND_MESSAGE.SET_NAME('CSD','CSD_TRX_QTY_ZERO');
4288 FND_MSG_PUB.ADD;
4289 RAISE FND_API.G_EXC_ERROR;
4290 end if;
4291
4292 l_wip_cost_txn_interface_rec.transaction_uom := p_res_txn_dtls_tbl(res_ctr).transaction_uom;
4293 l_wip_cost_txn_interface_rec.wip_entity_name := p_res_txn_dtls_tbl(res_ctr).wip_entity_name;
4294 l_wip_cost_txn_interface_rec.wip_entity_id := p_res_txn_dtls_tbl(res_ctr).wip_entity_id;
4295
4296 -- l_wip_cost_txn_interface_rec.employee_id := p_res_txn_dtls_tbl(res_ctr).employee_id;
4297
4298 l_wip_cost_txn_interface_rec.employee_id := p_res_txn_dtls_tbl(res_ctr).employee_id;
4299 l_wip_cost_txn_interface_rec.employee_num := p_res_txn_dtls_tbl(res_ctr).employee_num;
4300
4301 --insert into table wip_cost_txn_interface
4302
4303 IF ( FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
4304 FND_LOG.STRING( FND_LOG.LEVEL_EVENT,
4305 lc_mod_name||'beforecallinsertwipcosttxn',
4306 'Just before calling insert_wip_cost_txn');
4307 END IF;
4308
4309 -- get conversion rate based on UOM
4310 conversion_rate :=
4311 inv_convert.inv_um_convert(
4312 item_id => 0,
4313 precision => 38,
4314 from_quantity => 1,
4315 from_unit => p_res_txn_dtls_tbl(res_ctr).uom_code,
4316 to_unit => l_wip_cost_txn_interface_rec.transaction_uom ,
4317 from_name => NULL,
4318 to_name => NULL);
4319
4320
4321
4322 -- perform UOM conversion
4323 primary_qty := p_res_txn_dtls_tbl(res_ctr).transaction_quantity / conversion_rate;
4324 -- to_number(name_in(RESOURCE_TRANSACTIONS.APP_TRANSACTION_QUANTITY)) /
4325 -- res_transactions_uom.conversion_rate;
4326
4327
4328
4329 insert_wip_cost_txn( p_wip_cost_txn_interface_rec => l_wip_cost_txn_interface_rec,
4330 x_return_status => x_return_status );
4331
4332
4333 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
4334 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4335 END IF;
4336
4337
4338
4339
4340
4341
4342
4343 -- Here, check if required_quantity for the material is
4344 -- equal to (issued_quantity + transaction_quantity) ,
4345 -- Only if it is different, need to populate and call wip
4346 -- update program
4347
4348 l_required_quantity :=
4349 nvl(p_res_txn_dtls_tbl(res_ctr).applied_quantity, 0)+
4350 -- nvl(p_res_txn_dtls_tbl(res_ctr).required_quantity, 0)+
4351 primary_qty;
4352 -- p_res_txn_dtls_tbl(res_ctr).transaction_quantity +
4353 -- nvl(p_res_txn_dtls_tbl(res_ctr).pending_quantity, 0);
4354
4355 -- l_job_details_rec.required_quantity := 60;
4356
4357 If l_required_quantity <> p_res_txn_dtls_tbl(res_ctr).required_quantity THEN
4358 l_wip_update_needed := 'T' ;
4359
4360 --Commenting out as don't think this is needed
4361 -- Need to remove ro_quantity as well, later on if not neede
4362 -- l_job_details_rec.quantity_per_assembly := l_required_quantity / p_ro_quantity;
4363
4364 -- Get the Group_id to be used for WIP Mass Load,
4365
4366 SELECT wip_job_schedule_interface_s.NEXTVAL INTO l_job_header_rec.header_id FROM dual;
4367
4368 -- l_job_header_rec.group_id := l_job_header_rec.header_id;
4369
4370 -- l_job_details_rec.group_id := l_job_header_rec.group_id;
4371 l_job_details_rec.parent_header_id := l_job_header_rec.header_id;
4372
4373 l_job_header_rec.wip_entity_id := p_res_txn_dtls_tbl(res_ctr).wip_entity_id;
4374 l_job_header_rec.organization_id := p_res_txn_dtls_tbl(res_ctr).organization_id;
4375
4376 l_job_details_rec.resource_id_old := p_res_txn_dtls_tbl(res_ctr).resource_id;
4377 l_job_details_rec.resource_id_new := p_res_txn_dtls_tbl(res_ctr).resource_id;
4378
4379 l_job_details_rec.resource_seq_num := p_res_txn_dtls_tbl(res_ctr).resource_seq_num;
4380 l_job_details_rec.operation_seq_num := p_res_txn_dtls_tbl(res_ctr).operation_seq_num;
4381 l_job_details_rec.organization_id := p_res_txn_dtls_tbl(res_ctr).organization_id;
4382 -- l_job_details_rec.uom_code := p_res_txn_dtls_tbl(res_ctr).uom_code;
4383 If p_res_txn_dtls_tbl(res_ctr).basis_type = 1 then
4384 l_job_details_rec.usage_rate_or_amount := l_required_quantity / p_res_txn_dtls_tbl(res_ctr).op_scheduled_quantity ;
4385 else
4386 l_job_details_rec.usage_rate_or_amount := l_required_quantity;
4387 END IF;
4388 -- l_job_details_rec.usage_rate_or_amount := l_required_quantity / p_res_txn_dtls_tbl(res_ctr).job_quantity;
4389 l_job_details_rec.wip_entity_id := p_res_txn_dtls_tbl(res_ctr).wip_entity_id;
4390
4391
4392
4393 -- Call procedures to insert job header and job details information
4394 -- into wip interface tables
4395
4396 IF ( FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
4397 FND_LOG.STRING( FND_LOG.LEVEL_EVENT,
4398 lc_mod_name||'beforecallinsertjob',
4399 'Just before calling insert_job_header');
4400 END IF;
4401
4402
4403 insert_job_header( p_job_header_rec => l_job_header_rec,
4404 x_return_status => x_return_status );
4405
4406
4407 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
4408 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4409 END IF;
4410
4411
4412 IF ( FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
4413 FND_LOG.STRING( FND_LOG.LEVEL_EVENT,
4414 lc_mod_name||'beforecallinsertjobdtls',
4415 'Just before calling insert_job_details');
4416 END IF;
4417
4418
4419 insert_job_details( p_job_details_rec => l_job_details_rec,
4420 x_return_status => x_return_status );
4421
4422 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
4423 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4424 END IF;
4425
4426 END IF;
4427
4428
4429 ---- Update CSD_WIP_TRANSACTION_DETAILS rows to have null values
4430
4431 If p_res_txn_dtls_tbl(res_ctr).WIP_TRANSACTION_DETAIL_ID is not null then
4432
4433 IF ( FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
4434 FND_LOG.STRING( FND_LOG.LEVEL_EVENT,
4435 lc_mod_name||'beforecallupdaterow',
4436 'Just before calling CSD_WIP_TRANSACTION_DTLS_PKG.Delete_Row');
4437 END IF;
4438
4439 -- swai: bug 15955754 (FP of bug 14823164)
4440 -- 12.1.3+ adding DFFs - instead of deleting the row, update it
4441 -- so that the the DFFs are not deleted.
4442 -- null out transaction qty, uom
4443 -- table handler uses g_miss to indicate nulling out
4444 CSD_WIP_TRANSACTION_DTLS_PKG.Update_Row(
4445 p_WIP_TRANSACTION_DETAIL_ID => p_res_txn_dtls_tbl(res_ctr).WIP_TRANSACTION_DETAIL_ID
4446 ,p_CREATED_BY => null
4447 ,p_CREATION_DATE => null
4448 ,p_LAST_UPDATED_BY => l_last_updated_by
4449 ,p_LAST_UPDATE_DATE => l_last_update_date
4450 ,p_LAST_UPDATE_LOGIN => l_last_update_login
4451 ,p_INVENTORY_ITEM_ID => null
4452 ,p_WIP_ENTITY_ID => null
4453 ,p_OPERATION_SEQ_NUM => null
4454 ,p_RESOURCE_SEQ_NUM => null
4455 ,p_employee_id => null
4456 ,p_TRANSACTION_QUANTITY => FND_API.G_MISS_NUM
4457 ,p_TRANSACTION_UOM => FND_API.G_MISS_CHAR
4458 ,p_SERIAL_NUMBER => null
4459 ,p_REVISION => null
4460 ,p_REASON_ID => null
4461 ,p_BACKFLUSH_FLAG => null
4462 ,p_COUNT_POINT_TYPE => null
4463 ,p_DEPARTMENT_ID => null
4464 ,p_DESCRIPTION => null
4465 ,p_FIRST_UNIT_COMPLETION_DATE => null
4466 ,p_FIRST_UNIT_START_DATE => null
4467 ,p_LAST_UNIT_COMPLETION_DATE => null
4468 ,p_LAST_UNIT_START_DATE => null
4469 ,p_MINIMUM_TRANSFER_QUANTITY => null
4470 ,p_STANDARD_OPERATION_ID => null
4471 ,p_OBJECT_VERSION_NUMBER => p_res_txn_dtls_tbl(res_ctr).object_version_number
4472 ,p_CREATE_RO_FLAG => null
4473 );
4474
4475 /*
4476 CSD_WIP_TRANSACTION_DTLS_PKG.Delete_Row(
4477 p_WIP_TRANSACTION_DETAIL_ID => p_res_txn_dtls_tbl(res_ctr).WIP_TRANSACTION_DETAIL_ID );
4478 */
4479 end if;
4480
4481
4482 END LOOP;
4483
4484
4485 -- Call WIP Mass Load API
4486 -- Uncomment Later
4487
4488 IF l_wip_update_needed = 'T' THEN
4489
4490 BEGIN
4491
4492 WIP_MASSLOAD_PUB.massLoadJobs(p_groupID => l_job_header_rec.group_id,
4493 p_validationLevel => p_validation_level,
4494 p_commitFlag => 1, -- make it 0 later, once WIP works
4495 x_returnStatus => x_return_status,
4496 x_errorMsg => x_msg_data );
4497
4498 If ( ml_error_exists( l_job_header_rec.group_id ) or
4499 x_return_status <> FND_API.G_RET_STS_SUCCESS ) THEN
4500
4501 FND_MESSAGE.SET_NAME('CSD','CSD_RES_TXN_MASS_LD_FAILURE');
4502 FND_MSG_PUB.ADD;
4503 x_return_status := FND_API.G_RET_STS_ERROR;
4504
4505 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
4506 p_count => x_msg_count,
4507 p_data => x_msg_data);
4508
4509 RETURN;
4510 -- Need to rollback Raise exception -
4511 -- once commit is removed from above call
4512
4513 end if;
4514
4515 --bug#12316893
4516 IF (nvl(fnd_profile.value('MRP_DEBUG'),'Y') = 'N') THEN
4517 WIP_MASS_LOAD_PROCESSOR.Delete_Completed_Records(l_job_header_rec.group_id);
4518 End If;
4519 --bug#12316893
4520
4521
4522 EXCEPTION
4523 WHEN OTHERS THEN
4524
4525 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4526
4527 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
4528
4529 -- Add Unexpected Error to Message List, here SQLERRM is used for
4530 -- getting the error
4531
4532 FND_MSG_PUB.add_exc_msg(p_pkg_name => G_PKG_NAME,
4533 p_procedure_name => lc_api_name );
4534 END IF;
4535
4536 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
4537 p_count => x_msg_count,
4538 p_data => x_msg_data);
4539
4540 END;
4541
4542
4543 /* IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
4544 -- ROLLBACK to PROCESS_TRANSACT_RES_TXN_PVT ;
4545
4546 FND_MESSAGE.SET_NAME('CSD','CSD_RES_TXN_FAILURE');
4547 FND_MSG_PUB.ADD;
4548 RETURN; -- later - once wip works - can remove this
4549 -- RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4550 */
4551
4552
4553 /* IF ( FND_LOG.LEVEL_ERROR >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
4554 FND_LOG.STRING( FND_LOG.LEVEL_ERROR,
4555 lc_mod_name||'exc_exception',
4556 'G_EXC_ERROR Exception');
4557 END IF;
4558
4559 RETURN; */
4560
4561 -- END IF;
4562
4563 END IF;
4564
4565
4566 -- Standard check for p_commit
4567 IF FND_API.to_Boolean( p_commit )
4568 THEN
4569 COMMIT WORK;
4570 END IF;
4571
4572 EXCEPTION
4573 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
4574 ROLLBACK to PROCESS_TRANSACT_RES_TXN_PVT ;
4575 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4576
4577 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
4578 p_count => x_msg_count,
4579 p_data => x_msg_data);
4580
4581 IF ( FND_LOG.LEVEL_EXCEPTION >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
4582 FND_LOG.STRING( FND_LOG.LEVEL_EXCEPTION,
4583 lc_mod_name||'unx_exception',
4584 'G_EXC_UNEXPECTED_ERROR Exception');
4585 END IF;
4586
4587
4588 WHEN FND_API.G_EXC_ERROR THEN
4589 ROLLBACK to PROCESS_TRANSACT_RES_TXN_PVT ;
4590 x_return_status := FND_API.G_RET_STS_ERROR;
4591
4592
4593 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
4594 p_count => x_msg_count,
4595 p_data => x_msg_data);
4596
4597 IF ( FND_LOG.LEVEL_ERROR >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
4598 FND_LOG.STRING( FND_LOG.LEVEL_ERROR,
4599 lc_mod_name||'exc_exception',
4600 'G_EXC_ERROR Exception');
4601 END IF;
4602
4603 WHEN OTHERS THEN
4604 ROLLBACK to PROCESS_TRANSACT_RES_TXN_PVT ;
4605 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4606
4607 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
4608
4609 -- Add Unexpected Error to Message List, here SQLERRM is used for
4610 -- getting the error
4611
4612 FND_MSG_PUB.add_exc_msg(p_pkg_name => G_PKG_NAME,
4613 p_procedure_name => lc_api_name );
4614 END IF;
4615
4616 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
4617 p_count => x_msg_count,
4618 p_data => x_msg_data);
4619
4620 IF ( FND_LOG.LEVEL_EXCEPTION >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
4621 FND_LOG.STRING( FND_LOG.LEVEL_EXCEPTION,
4622 lc_mod_name||'others_exception',
4623 'OTHERS Exception');
4624 END IF;
4625
4626
4627
4628 END process_transact_res_txn;
4629
4630
4631
4632 PROCEDURE PROCESS_SAVE_MTL_TXN_DTLS
4633 (
4634 p_api_version_number IN NUMBER,
4635 p_init_msg_list IN VARCHAR2 ,
4636 p_commit IN VARCHAR2 ,
4637 p_validation_level IN NUMBER ,
4638 x_return_status OUT NOCOPY VARCHAR2,
4639 x_msg_count OUT NOCOPY NUMBER,
4640 x_msg_data OUT NOCOPY VARCHAR2,
4641 p_mtl_txn_dtls_tbl IN MTL_TXN_DTLS_TBL_TYPE,
4642 x_op_created OUT NOCOPY VARCHAR
4643 -- p_ro_quantity IN NUMBER
4644 )
4645 IS
4646 lc_api_name CONSTANT VARCHAR2(30) := 'PROCESS_SAVE_CSD_MTL_TXN_DTLS';
4647 lc_api_version_number CONSTANT NUMBER := 1.0;
4648
4649 -- constants used for FND_LOG debug messages
4650 lc_mod_name CONSTANT VARCHAR2(2000) := 'csd.plsql.csd_hv_wip_job_pvt.process_save_mtl_txn_dtls';
4651
4652 -- Constants Used for Inserting into wip_job_schedule_interface,
4653 -- These are the values needed for WIP Mass Load to pick up the records
4654
4655 -- Non Standard Update Discrete Job Load Type
4656 lc_non_std_update_load_type CONSTANT NUMBER := 3;
4657
4658
4659 lc_load_mtl_type CONSTANT NUMBER := 2;
4660
4661 lc_substitution_add_type CONSTANT NUMBER := 2;
4662 lc_substitution_change_type CONSTANT NUMBER := 3; -- yvchen: bug 12933419 allow update of wip mat reqs
4663 -- 11/7/05
4664 -- lc_mrp_net_flag CONSTANT NUMBER := 1;
4665 -- 11/7/05
4666 -- lc_push_wip_supply_type CONSTANT NUMBER := 1;
4667
4668
4669 -- Job Records to hold the Job header and details information
4670 l_job_header_rec wip_job_schedule_interface%ROWTYPE;
4671 l_job_details_rec wip_job_dtls_interface%ROWTYPE;
4672
4673
4674 l_creation_date DATE;
4675 l_last_update_date DATE;
4676 l_created_by NUMBER;
4677 l_created_by_name VARCHAr2(100);
4678 l_last_updated_by NUMBER;
4679 l_last_updated_by_name VARCHAR2(100);
4680 l_last_update_login NUMBER;
4681
4682
4683 l_mtl_load_type NUMBER;
4684 l_mrp_net_flag NUMBER;
4685 l_quantity_issued NUMBER :=0; -- yvchen: bug 12933419 reinstated for update mtl reqs
4686
4687 l_WIP_TRANSACTION_DETAIL_ID NUMBER;
4688
4689 l_job_quantity NUMBER;
4690
4691 l_op_seq_num NUMBER;
4692 l_op_exists VARCHAR2(10);
4693 l_op_dtls_tbl OP_DTLS_TBL_TYPE;
4694
4695 CURSOR get_job_quantity ( p_wip_entity_id NUMBER ) IS
4696 SELECT start_quantity from wip_discrete_jobs where
4697 wip_entity_id = p_wip_entity_id ;
4698
4699 CURSOR get_operation_exists(p_wip_entity_id NUMBER ) IS
4700 SELECT 'exists'
4701 from wip_operations
4702 where wip_entity_id = p_wip_entity_id
4703 and rownum = 1;
4704
4705 --bug#8465719 begin
4706 l_location_control_code NUMBER;
4707 l_location_subinv_control_code NUMBER;
4708 l_locator_controlled VARCHAR2(1) := 'F';
4709 l_locator_subinv_controlled VARCHAR2(1) := 'F';
4710
4711 lc_none_loc_contrl CONSTANT NUMBER :=1;
4712 lc_predfn_loc_cntrl CONSTANT NUMBER := 2;
4713 lc_dyn_loc_cntrl CONSTANT NUMBER := 3;
4714
4715 l_wip_supply_type NUMBER; --2 means assembly pull
4716 --3 means Operation Pull
4717 l_wip_supply_subinventory VARCHAR2(10);
4718 l_wip_supply_locator_id NUMBER;
4719
4720
4721
4722 CURSOR get_inv_location_control_code ( p_organization_id NUMBER,
4723 p_inventory_item_id NUMBER ) IS
4724 select location_control_code from mtl_system_items_b where
4725 organization_id = p_organization_id and
4726 inventory_item_id = p_inventory_item_id;
4727
4728
4729 CURSOR get_si_locator_control_code ( p_organization_id NUMBER,
4730 p_secondary_inventory_name VARCHAR2 ) IS
4731 SELECT locator_type from mtl_secondary_inventories where
4732 organization_id = p_organization_id and
4733 secondary_inventory_name = p_secondary_inventory_name;
4734
4735
4736 CURSOR get_wip_supply_info ( p_organization_id NUMBER,
4737 p_inventory_item_id NUMBER ) IS
4738 select wip_supply_type, wip_supply_subinventory, wip_supply_locator_id
4739 from mtl_system_items_b where
4740 organization_id = p_organization_id and
4741 inventory_item_id = p_inventory_item_id;
4742 --bug#8465719 end
4743
4744 -- yvchen: bug 12933419
4745 CURSOR get_qty_issued (p_inventory_item_id NUMBER,
4746 p_operation_seq_num NUMBER,
4747 p_wip_entity_id NUMBER,
4748 p_organization_id NUMBER) IS
4749 SELECT nvl(quantity_issued, 0)
4750 from wip_requirement_operations
4751 where inventory_item_id = p_inventory_item_id
4752 and operation_seq_num = p_operation_seq_num
4753 and wip_entity_id = p_wip_entity_id
4754 and organization_id = p_organization_id;
4755
4756 BEGIN
4757
4758 IF ( FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
4759 FND_LOG.STRING( FND_LOG.LEVEL_PROCEDURE,
4760 lc_mod_name||'begin',
4761 'Entering private API process_save_mtl_txn_dtls' );
4762 END IF;
4763
4764 -- Standard Start of API savepoint
4765 SAVEPOINT PROCESS_SAVE_MTL_TXN_DTLS_PVT;
4766 -- Standard call to check for call compatibility.
4767 IF NOT FND_API.Compatible_API_Call
4768 (lc_api_version_number,
4769 p_api_version_number,
4770 lc_api_name,
4771 G_PKG_NAME)
4772 THEN
4773 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4774 END IF;
4775
4776 -- Initialize message list if p_init_msg_list is set to TRUE
4777 IF FND_API.to_boolean(p_init_msg_list) THEN
4778 FND_MSG_PUB.initialize;
4779 END IF;
4780
4781
4782 x_return_status := FND_API.G_RET_STS_SUCCESS;
4783 x_op_created := FND_API.G_FALSE;
4784
4785 -- Populate the constant values
4786
4787 l_job_header_rec.load_type := lc_non_std_update_load_type;
4788
4789 l_job_details_rec.date_required := sysdate;
4790 l_job_details_rec.load_type := lc_load_mtl_type;
4791
4792 l_job_details_rec.substitution_type := lc_substitution_add_type;
4793
4794 -- 11/7/05
4795 -- l_job_details_rec.mrp_net_flag := lc_mrp_net_flag;
4796 l_job_details_rec.mrp_net_flag := null;
4797 -- 11/7/05
4798 -- l_job_details_rec.wip_supply_type := lc_push_wip_supply_type;
4799 l_job_details_rec.wip_supply_type := null;
4800
4801
4802 -- l_quantity_issued := 0;
4803
4804
4805 -- Populate the row who columns
4806
4807 l_creation_date := SYSDATE;
4808 l_last_update_date := SYSDATE;
4809 l_created_by := fnd_global.user_id;
4810 l_last_updated_by := fnd_global.user_id;
4811 l_last_update_login := fnd_global.login_id;
4812
4813
4814
4815
4816 FOR mtl_ctr in p_mtl_txn_dtls_tbl.FIRST.. p_mtl_txn_dtls_tbl.LAST
4817
4818 LOOP
4819 -- use l_op_seq_num throughout this loop, since op seq num may
4820 -- change if value 1 was originally passed in.
4821 l_op_seq_num := p_mtl_txn_dtls_tbl(mtl_ctr).operation_seq_num;
4822
4823 If p_mtl_txn_dtls_tbl(mtl_ctr).new_row = 'Y' then
4824 l_job_details_rec.substitution_type := lc_substitution_add_type; -- yvchen: bug 12933419
4825
4826 -- swai: check if there is an existing operation to add the material to.
4827 -- Otherwise, we will have to create an operation first.
4828 if (l_op_seq_num = 1) then
4829 if (p_mtl_txn_dtls_tbl(mtl_ctr).wip_entity_id is not null) then
4830 open get_operation_exists(p_mtl_txn_dtls_tbl(mtl_ctr).wip_entity_id);
4831 fetch get_operation_exists into l_op_exists;
4832 close get_operation_exists;
4833 end if;
4834 if (l_op_exists is null) then
4835 -- create operation, but only if default department is specified
4836 l_op_dtls_tbl(1).department_id := fnd_profile.value('CSD_DEF_HV_OP_DEPT');
4837 if (l_op_dtls_tbl(1).department_id is null) then
4838 -- No operations exist for the job and no default
4839 -- department has been specified, so throw an error.
4840 -- we cannot add the material to operation 1 since
4841 -- it would force a wip_supply_type of pull, which
4842 -- required backflush.
4843 FND_MESSAGE.SET_NAME('CSD','CSD_DEF_OP_DEPT_NULL');
4844 FND_MSG_PUB.ADD;
4845 RAISE FND_API.G_EXC_ERROR;
4846 else
4847 l_op_dtls_tbl(1).new_row := 'Y';
4848 l_op_dtls_tbl(1).wip_entity_id := p_mtl_txn_dtls_tbl(mtl_ctr).wip_entity_id;
4849 l_op_dtls_tbl(1).organization_id := p_mtl_txn_dtls_tbl(mtl_ctr).organization_id;
4850 l_op_dtls_tbl(1).operation_seq_num := 10; -- default operation seq 10
4851 l_op_dtls_tbl(1).backflush_flag := 2; -- default backflush
4852 l_op_dtls_tbl(1).count_point_type := 1; -- default count point
4853 l_op_dtls_tbl(1).first_unit_completion_date := sysdate;
4854 l_op_dtls_tbl(1).first_unit_start_date := sysdate;
4855 l_op_dtls_tbl(1).last_unit_completion_date := sysdate;
4856 l_op_dtls_tbl(1).last_unit_start_date := sysdate;
4857 l_op_dtls_tbl(1).minimum_transfer_quantity := 0;
4858
4859 PROCESS_SAVE_OP_DTLS
4860 (
4861 p_api_version_number => 1.0,
4862 p_init_msg_list => fnd_api.g_false,
4863 p_Commit => fnd_api.g_false,
4864 p_validation_level => p_validation_level,
4865 x_return_status => x_return_status,
4866 x_msg_count => x_msg_count,
4867 x_msg_data => x_msg_data,
4868 p_op_dtls_tbl => l_op_dtls_tbl
4869 );
4870 if (x_return_status = FND_API.G_RET_STS_SUCCESS) then
4871 l_op_seq_num := l_op_dtls_tbl(1).operation_seq_num;
4872 x_op_created := FND_API.G_TRUE;
4873 else
4874 FND_MESSAGE.SET_NAME('CSD','CSD_OP_AUTO_CREATE_FAILURE');
4875 FND_MSG_PUB.ADD;
4876 RAISE FND_API.G_EXC_ERROR;
4877 end if;
4878 end if; -- department profile
4879 end if; -- operation does not exist
4880 end if;
4881
4882
4883 -- Get the Group_id to be used for WIP Mass Load,
4884 SELECT wip_job_schedule_interface_s.NEXTVAL INTO l_job_header_rec.group_id FROM dual;
4885
4886
4887 -- get job_quantity
4888 open get_job_quantity ( p_mtl_txn_dtls_tbl(mtl_ctr).wip_entity_id);
4889 fetch get_job_quantity into l_job_quantity;
4890 close get_job_quantity;
4891
4892
4893 l_job_header_rec.header_id := l_job_header_rec.group_id;
4894 l_job_header_rec.wip_entity_id := p_mtl_txn_dtls_tbl(mtl_ctr).wip_entity_id;
4895 l_job_header_rec.organization_id := p_mtl_txn_dtls_tbl(mtl_ctr).organization_id;
4896
4897 l_job_details_rec.group_id := l_job_header_rec.group_id;
4898 l_job_details_rec.parent_header_id := l_job_header_rec.group_id;
4899 l_job_details_rec.inventory_item_id_new := p_mtl_txn_dtls_tbl(mtl_ctr).inventory_item_id;
4900 l_job_details_rec.operation_seq_num := l_op_seq_num; -- p_mtl_txn_dtls_tbl(mtl_ctr).operation_seq_num;
4901 l_job_details_rec.organization_id := p_mtl_txn_dtls_tbl(mtl_ctr).organization_id;
4902 l_job_details_rec.quantity_per_assembly := p_mtl_txn_dtls_tbl(mtl_ctr).transaction_quantity / l_job_quantity;
4903 l_job_details_rec.required_quantity := p_mtl_txn_dtls_tbl(mtl_ctr).transaction_quantity;
4904 l_job_details_rec.wip_entity_id := p_mtl_txn_dtls_tbl(mtl_ctr).wip_entity_id;
4905 l_job_details_rec.supply_subinventory := p_mtl_txn_dtls_tbl(mtl_ctr).supply_subinventory;
4906
4907
4908 --bug#8465719 begin
4909 l_job_details_rec.SUPPLY_LOCATOR_ID := p_mtl_txn_dtls_tbl(mtl_ctr).supply_locator_id;
4910
4911 --FND_LOG.STRING(FND_LOG.LEVEL_EVENT,lc_mod_name,'SUPPLY_LOCATOR_ID : '||p_mtl_txn_dtls_tbl(mtl_ctr).supply_locator_id);
4912 --FND_LOG.STRING(FND_LOG.LEVEL_EVENT,lc_mod_name,'supply_subinventory : '||p_mtl_txn_dtls_tbl(mtl_ctr).supply_subinventory);
4913 --FND_LOG.STRING(FND_LOG.LEVEL_EVENT,lc_mod_name,'CSD_DEF_HV_SUBINV : '||fnd_profile.value('CSD_DEF_HV_SUBINV'));
4914
4915
4916 if (p_mtl_txn_dtls_tbl(mtl_ctr).supply_locator_id is null) Then
4917
4918 open get_inv_location_control_code ( p_mtl_txn_dtls_tbl(mtl_ctr).organization_id ,
4919 p_mtl_txn_dtls_tbl(mtl_ctr).inventory_item_id ) ;
4920 fetch get_inv_location_control_code into l_location_control_code ;
4921 close get_inv_location_control_code;
4922
4923
4924 --FND_LOG.STRING(FND_LOG.LEVEL_EVENT,lc_mod_name,'l_location_control_code : '||l_location_control_code);
4925
4926 If l_location_control_code in ( lc_predfn_loc_cntrl ,
4927 lc_dyn_loc_cntrl ) THEN
4928 l_locator_controlled := 'T' ;
4929 end if;
4930
4931 open get_si_locator_control_code ( p_mtl_txn_dtls_tbl(mtl_ctr).organization_id ,
4932 p_mtl_txn_dtls_tbl(mtl_ctr).supply_subinventory ) ;
4933 fetch get_si_locator_control_code into l_location_subinv_control_code ;
4934 close get_si_locator_control_code;
4935
4936 if (l_location_subinv_control_code <> 1) then
4937 l_locator_subinv_controlled := 'T';
4938 end if;
4939
4940
4941 open get_wip_supply_info ( p_mtl_txn_dtls_tbl(mtl_ctr).organization_id ,
4942 p_mtl_txn_dtls_tbl(mtl_ctr).inventory_item_id ) ;
4943 fetch get_wip_supply_info into l_wip_supply_type, l_wip_supply_subinventory, l_wip_supply_locator_id;
4944 close get_wip_supply_info;
4945
4946 --FND_LOG.STRING(FND_LOG.LEVEL_EVENT,lc_mod_name,'l_wip_supply_subinventory : '||l_wip_supply_subinventory);
4947 --FND_LOG.STRING(FND_LOG.LEVEL_EVENT,lc_mod_name,'l_wip_supply_locator_id : '||l_wip_supply_locator_id);
4948 --FND_LOG.STRING(FND_LOG.LEVEL_EVENT,lc_mod_name,'l_locator_controlled : '||l_locator_controlled);
4949 --FND_LOG.STRING(FND_LOG.LEVEL_EVENT,lc_mod_name,'CSD_DEF_INV_LOCATOR : '||fnd_profile.value('CSD_DEF_INV_LOCATOR'));
4950 --wip_supply_type = 2 means assembly pull, 3 means operation pull
4951
4952 If ((l_locator_controlled = 'T' or l_locator_subinv_controlled = 'T') and (l_wip_supply_type = 2 or l_wip_supply_type = 3))
4953 THEN
4954 if (l_wip_supply_locator_id is not null) then
4955 --defaulted the subinventory and locator from the Organization item -->Work in Process --> Supply section
4956 --if the value is not set there, get it from depot CSD_DEF_INV_LOCATOR profile value
4957 l_job_details_rec.supply_subinventory := l_wip_supply_subinventory;
4958 l_job_details_rec.SUPPLY_LOCATOR_ID := l_wip_supply_locator_id;
4959 else
4960 l_job_details_rec.SUPPLY_LOCATOR_ID := fnd_profile.value('CSD_DEF_INV_LOCATOR');
4961 --FND_LOG.STRING(FND_LOG.LEVEL_EVENT,lc_mod_name,'SUPPLY_LOCATOR_ID : '||l_job_details_rec.SUPPLY_LOCATOR_ID);
4962 end if;
4963 end if;
4964
4965 end if;
4966 --bug#8465719 end
4967
4968
4969
4970 -- swai bug 13964903, FP of bug#13837341, subhat
4971 -- subinventory is only required when the supply type is operation pull(3) or assembly pull (2).
4972 If l_job_details_rec.supply_subinventory is NULL AND l_wip_supply_type IN (2,3) then
4973 FND_MESSAGE.SET_NAME('CSD','CSD_DEF_SUB_INV_NULL');
4974 FND_MSG_PUB.ADD;
4975 RAISE FND_API.G_EXC_ERROR;
4976 end if;
4977
4978
4979
4980 -- Call procedures to insert job header and job details information
4981 -- into wip interface tables
4982
4983 IF ( FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
4984 FND_LOG.STRING( FND_LOG.LEVEL_EVENT,
4985 lc_mod_name||'beforecallinsertjob',
4986 'Just before calling insert_job_header');
4987 END IF;
4988
4989
4990 insert_job_header( p_job_header_rec => l_job_header_rec,
4991 x_return_status => x_return_status );
4992
4993
4994 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
4995 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4996 END IF;
4997
4998
4999 IF ( FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
5000 FND_LOG.STRING( FND_LOG.LEVEL_EVENT,
5001 lc_mod_name||'beforecallinsertjobdtls',
5002 'Just before calling insert_job_details');
5003 END IF;
5004
5005
5006 insert_job_details( p_job_details_rec => l_job_details_rec,
5007 x_return_status => x_return_status );
5008
5009 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
5010 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5011 END IF;
5012
5013
5014
5015 -- Call WIP Mass Load API
5016
5017 IF ( FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
5018 FND_LOG.STRING( FND_LOG.LEVEL_EVENT,
5019 lc_mod_name||'beforecallwipmassload',
5020 'Just before calling WIP_MASSLOAD_PUB.massLoadJobs');
5021 END IF;
5022
5023 BEGIN
5024 WIP_MASSLOAD_PUB.massLoadJobs(p_groupID => l_job_header_rec.group_id,
5025 p_validationLevel => p_validation_level,
5026 p_commitFlag => 0,
5027 x_returnStatus => x_return_status,
5028 x_errorMsg => x_msg_data );
5029
5030 If ( ml_error_exists( l_job_header_rec.group_id ) or
5031 x_return_status <> FND_API.G_RET_STS_SUCCESS ) THEN
5032
5033 FND_MESSAGE.SET_NAME('CSD','CSD_MTL_ADD_MASS_LD_FAILURE');
5034 FND_MSG_PUB.ADD;
5035 x_return_status := FND_API.G_RET_STS_ERROR;
5036
5037 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
5038 p_count => x_msg_count,
5039 p_data => x_msg_data);
5040 -- Need to rollback Raise exception -
5041 -- once commit is removed from above call
5042 -- raise FND_API.G_EXC_ERROR;
5043 RETURN;
5044 end if;
5045
5046 --bug#12316893
5047 IF (nvl(fnd_profile.value('MRP_DEBUG'),'Y') = 'N') THEN
5048 WIP_MASS_LOAD_PROCESSOR.Delete_Completed_Records(l_job_header_rec.group_id);
5049 End If;
5050 --bug#12316893
5051
5052 EXCEPTION
5053 WHEN OTHERS THEN
5054 add_wip_interface_errors(l_job_header_rec.group_id,
5055 2 /* 2 = materials */);
5056
5057 -- when rollback for WIP works, remove x_return_status, count_and_get,
5058 -- and return then reinstate raise exception above
5059 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5060 /*
5061 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
5062 -- Add Unexpected Error to Message List, here SQLERRM is used for
5063 -- getting the error
5064
5065 FND_MSG_PUB.add_exc_msg(p_pkg_name => G_PKG_NAME,
5066 p_procedure_name => lc_api_name );
5067 END IF;
5068 */
5069 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
5070 p_count => x_msg_count,
5071 p_data => x_msg_data);
5072
5073 END;
5074
5075 /* yvchen: bug 12933419 allow update of wip material requirements
5076 -- for now, only allow update of quantity.
5077 -- subinventory and locator update not supported right now. */
5078
5079 else -- p_mtl_txn_dtls_tbl(mtl_ctr).new_row <> 'Y'
5080
5081 IF ( FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
5082 FND_LOG.STRING( FND_LOG.LEVEL_EVENT,
5083 lc_mod_name,
5084 'Updating material requirements');
5085 END IF;
5086
5087
5088 l_job_details_rec.substitution_type := lc_substitution_change_type;
5089
5090 -- Get the Group_id to be used for WIP Mass Load,
5091 SELECT wip_job_schedule_interface_s.NEXTVAL INTO l_job_header_rec.group_id FROM dual;
5092
5093 l_job_header_rec.header_id := l_job_header_rec.group_id;
5094 l_job_header_rec.wip_entity_id := p_mtl_txn_dtls_tbl(mtl_ctr).wip_entity_id;
5095 l_job_header_rec.organization_id := p_mtl_txn_dtls_tbl(mtl_ctr).organization_id;
5096
5097 l_job_details_rec.group_id := l_job_header_rec.group_id;
5098 l_job_details_rec.parent_header_id := l_job_header_rec.group_id; -- must be null since only detail recs updated
5099 l_job_details_rec.inventory_item_id_old := p_mtl_txn_dtls_tbl(mtl_ctr).inventory_item_id;
5100 l_job_details_rec.inventory_item_id_new := p_mtl_txn_dtls_tbl(mtl_ctr).inventory_item_id;
5101 l_job_details_rec.operation_seq_num := p_mtl_txn_dtls_tbl(mtl_ctr).operation_seq_num;
5102 l_job_details_rec.organization_id := p_mtl_txn_dtls_tbl(mtl_ctr).organization_id;
5103 l_job_details_rec.wip_entity_id := p_mtl_txn_dtls_tbl(mtl_ctr).wip_entity_id;
5104
5105
5106 -- Calculate required quantity
5107 -- get the qty already transacted. then add it to the transaction qty for total
5108 -- required qty.
5109 open get_qty_issued ( p_mtl_txn_dtls_tbl(mtl_ctr).inventory_item_id,
5110 p_mtl_txn_dtls_tbl(mtl_ctr).operation_seq_num,
5111 p_mtl_txn_dtls_tbl(mtl_ctr).wip_entity_id,
5112 p_mtl_txn_dtls_tbl(mtl_ctr).organization_id);
5113 fetch get_qty_issued into l_quantity_issued;
5114 close get_qty_issued;
5115
5116 l_job_details_rec.required_quantity := p_mtl_txn_dtls_tbl(mtl_ctr).transaction_quantity + l_quantity_issued;
5117
5118 -- Calculate qty per assembly (required field)
5119 open get_job_quantity ( p_mtl_txn_dtls_tbl(mtl_ctr).wip_entity_id);
5120 fetch get_job_quantity into l_job_quantity;
5121 close get_job_quantity;
5122 l_job_details_rec.quantity_per_assembly := l_job_details_rec.required_quantity / l_job_quantity;
5123
5124
5125 -- supply inventory: only update if it is not null. Do not allow nulling out of subinventory.
5126 if (p_mtl_txn_dtls_tbl(mtl_ctr).supply_subinventory is not null) then
5127 l_job_details_rec.supply_subinventory := p_mtl_txn_dtls_tbl(mtl_ctr).supply_subinventory;
5128 end if;
5129
5130 -- supply locator: only update if it is not null. Do not allow nulling out of locator.
5131 if (p_mtl_txn_dtls_tbl(mtl_ctr).supply_locator_id is not null) then
5132 l_job_details_rec.supply_locator_id := p_mtl_txn_dtls_tbl(mtl_ctr).supply_locator_id;
5133 end if;
5134
5135
5136 -- Call procedures to insert job header and job details information
5137 -- into wip interface tables
5138 IF ( FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
5139 FND_LOG.STRING( FND_LOG.LEVEL_EVENT, lc_mod_name||'beforecallinsertjob',
5140 'Just before calling insert_job_header');
5141 FND_LOG.STRING( FND_LOG.LEVEL_EVENT, lc_mod_name,
5142 'l_job_header_rec.header_id='||l_job_header_rec.header_id );
5143 FND_LOG.STRING( FND_LOG.LEVEL_EVENT, lc_mod_name,
5144 'l_job_header_rec.wip_entity_id='||l_job_header_rec.wip_entity_id );
5145 FND_LOG.STRING( FND_LOG.LEVEL_EVENT, lc_mod_name,
5146 'l_job_header_rec.organization_id='||l_job_header_rec.organization_id );
5147 FND_LOG.STRING( FND_LOG.LEVEL_EVENT, lc_mod_name,
5148 'l_job_details_rec.group_id='||l_job_details_rec.group_id );
5149 FND_LOG.STRING( FND_LOG.LEVEL_EVENT, lc_mod_name,
5150 'l_job_details_rec.parent_header_id='||l_job_details_rec.parent_header_id );
5151 FND_LOG.STRING( FND_LOG.LEVEL_EVENT, lc_mod_name,
5152 'l_job_details_rec.operation_seq_num='||l_job_details_rec.operation_seq_num );
5153 FND_LOG.STRING( FND_LOG.LEVEL_EVENT, lc_mod_name,
5154 'l_job_details_rec.organization_id='||l_job_details_rec.organization_id );
5155 FND_LOG.STRING( FND_LOG.LEVEL_EVENT, lc_mod_name,
5156 'l_job_details_rec.wip_entity_id='||l_job_details_rec.wip_entity_id );
5157 FND_LOG.STRING( FND_LOG.LEVEL_EVENT, lc_mod_name,
5158 'l_job_details_rec.inventory_item_id_old='||l_job_details_rec.inventory_item_id_old );
5159 FND_LOG.STRING( FND_LOG.LEVEL_EVENT, lc_mod_name,
5160 'l_job_details_rec.inventory_item_id_new='||l_job_details_rec.inventory_item_id_new );
5161 FND_LOG.STRING( FND_LOG.LEVEL_EVENT, lc_mod_name,
5162 'l_job_details_rec.required_quantity='||l_job_details_rec.required_quantity );
5163 FND_LOG.STRING( FND_LOG.LEVEL_EVENT, lc_mod_name,
5164 'l_job_details_rec.quantity_per_assembly='||l_job_details_rec.quantity_per_assembly );
5165 FND_LOG.STRING( FND_LOG.LEVEL_EVENT, lc_mod_name,
5166 'l_job_details_rec.supply_subinventory='||l_job_details_rec.supply_subinventory );
5167 FND_LOG.STRING( FND_LOG.LEVEL_EVENT, lc_mod_name,
5168 'l_job_details_rec.supply_locator_id='||l_job_details_rec.supply_locator_id );
5169 END IF;
5170
5171 insert_job_header( p_job_header_rec => l_job_header_rec,
5172 x_return_status => x_return_status );
5173
5174 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
5175 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5176 END IF;
5177
5178
5179 IF ( FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
5180 FND_LOG.STRING( FND_LOG.LEVEL_EVENT,
5181 lc_mod_name||'beforecallinsertjobdtls',
5182 'Just before calling insert_job_details');
5183 END IF;
5184
5185 insert_job_details( p_job_details_rec => l_job_details_rec,
5186 x_return_status => x_return_status );
5187
5188 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
5189 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5190 END IF;
5191
5192 IF ( FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
5193 FND_LOG.STRING( FND_LOG.LEVEL_EVENT,
5194 lc_mod_name||'beforecallwipmassload',
5195 'Just before calling WIP_MASSLOAD_PUB.massLoadJobs for group_id=l_job_header_rec.group_id');
5196 END IF;
5197
5198 -- Call WIP Mass Load API
5199 BEGIN
5200 WIP_MASSLOAD_PUB.massLoadJobs(p_groupID => l_job_header_rec.group_id,
5201 p_validationLevel => p_validation_level,
5202 p_commitFlag => 1, -- commit, so that user can correct errors if any
5203 x_returnStatus => x_return_status,
5204 x_errorMsg => x_msg_data );
5205
5206 If ( ml_error_exists( l_job_header_rec.group_id ) or
5207 x_return_status <> FND_API.G_RET_STS_SUCCESS ) THEN
5208
5209 IF ( FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
5210 FND_LOG.STRING( FND_LOG.LEVEL_EVENT,
5211 lc_mod_name,
5212 'Error occured during WIP_MASSLOAD_PUB.massLoadJobs');
5213 END IF;
5214
5215 FND_MESSAGE.SET_NAME('CSD','CSD_MTL_UPD_MASS_LD_FAILURE');
5216 FND_MSG_PUB.ADD;
5217 x_return_status := FND_API.G_RET_STS_ERROR;
5218 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
5219 p_count => x_msg_count,
5220 p_data => x_msg_data);
5221 -- do not return: keep going even if requirements cannot be saved,
5222 -- because wip transaction details can be updated.
5223 end if;
5224
5225 --bug#12316893
5226 IF (nvl(fnd_profile.value('MRP_DEBUG'),'Y') = 'N') THEN
5227 WIP_MASS_LOAD_PROCESSOR.Delete_Completed_Records(l_job_header_rec.group_id);
5228 End If;
5229 --bug#12316893
5230
5231 EXCEPTION
5232 WHEN OTHERS THEN
5233 IF ( FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
5234 FND_LOG.STRING( FND_LOG.LEVEL_EVENT,
5235 lc_mod_name||'exception',
5236 'WIP_MASSLOAD_PUB.massLoadJobs Others Exception');
5237 END IF;
5238
5239 add_wip_interface_errors(l_job_header_rec.group_id,
5240 2 /* 2 = materials */);
5241
5242 FND_MESSAGE.SET_NAME('CSD','CSD_MTL_UPD_MASS_LD_FAILURE');
5243 FND_MSG_PUB.ADD;
5244 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5245 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
5246 p_count => x_msg_count,
5247 p_data => x_msg_data);
5248 END;
5249 END IF; -- p_mtl_txn_dtls_tbl(mtl_ctr).new_row <> 'Y'
5250
5251 If p_mtl_txn_dtls_tbl(mtl_ctr).WIP_TRANSACTION_DETAIL_ID is null then
5252 IF ( FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
5253 FND_LOG.STRING( FND_LOG.LEVEL_EVENT,
5254 lc_mod_name||'beforecallinsertrow',
5255 'Just before calling CSD_WIP_TRANSACTION_DTLS_PKG.Insert_Row');
5256 END IF;
5257
5258 l_WIP_TRANSACTION_DETAIL_ID := null;
5259
5260 CSD_WIP_TRANSACTION_DTLS_PKG.Insert_Row(
5261 px_WIP_TRANSACTION_DETAIL_ID => l_WIP_TRANSACTION_DETAIL_ID
5262 ,p_CREATED_BY => l_created_by
5263 ,p_CREATION_DATE => l_creation_date
5264 ,p_LAST_UPDATED_BY => l_last_updated_by
5265 ,p_LAST_UPDATE_DATE => l_last_update_date
5266 ,p_LAST_UPDATE_LOGIN => l_last_update_login
5267 ,p_INVENTORY_ITEM_ID => p_mtl_txn_dtls_tbl(mtl_ctr).INVENTORY_ITEM_ID
5268 ,p_WIP_ENTITY_ID => p_mtl_txn_dtls_tbl(mtl_ctr).WIP_ENTITY_ID
5269 ,p_OPERATION_SEQ_NUM => l_op_seq_num -- p_mtl_txn_dtls_tbl(mtl_ctr).OPERATION_SEQ_NUM
5270 ,p_RESOURCE_SEQ_NUM => null
5271 ,p_employee_id => null
5272 ,p_TRANSACTION_QUANTITY => p_mtl_txn_dtls_tbl(mtl_ctr).TRANSACTION_QUANTITY
5273 ,p_TRANSACTION_UOM => p_mtl_txn_dtls_tbl(mtl_ctr).TRANSACTION_UOM
5274 ,p_SERIAL_NUMBER => p_mtl_txn_dtls_tbl(mtl_ctr).SERIAL_NUMBER
5275 ,p_REVISION => p_mtl_txn_dtls_tbl(mtl_ctr).REVISION -- swai: bug 6995498/7182047
5276 ,p_REASON_ID => p_mtl_txn_dtls_tbl(mtl_ctr).REASON_ID -- swai bug 6841113
5277 ,p_BACKFLUSH_FLAG => null
5278 ,p_COUNT_POINT_TYPE => null
5279 ,p_DEPARTMENT_ID => null
5280 ,p_DESCRIPTION => null
5281 ,p_FIRST_UNIT_COMPLETION_DATE => null
5282 ,p_FIRST_UNIT_START_DATE => null
5283 ,p_LAST_UNIT_COMPLETION_DATE => null
5284 ,p_LAST_UNIT_START_DATE => null
5285 ,p_MINIMUM_TRANSFER_QUANTITY => null
5286 ,p_STANDARD_OPERATION_ID => null
5287 -- yvchen: bug 13258460 - 12.1.3+ add DFF attributes
5288 ,p_ATTRIBUTE_CATEGORY => p_mtl_txn_dtls_tbl(mtl_ctr).ATTRIBUTE_CATEGORY
5289 ,p_ATTRIBUTE1 => p_mtl_txn_dtls_tbl(mtl_ctr).ATTRIBUTE1
5290 ,p_ATTRIBUTE2 => p_mtl_txn_dtls_tbl(mtl_ctr).ATTRIBUTE2
5291 ,p_ATTRIBUTE3 => p_mtl_txn_dtls_tbl(mtl_ctr).ATTRIBUTE3
5292 ,p_ATTRIBUTE4 => p_mtl_txn_dtls_tbl(mtl_ctr).ATTRIBUTE4
5293 ,p_ATTRIBUTE5 => p_mtl_txn_dtls_tbl(mtl_ctr).ATTRIBUTE5
5294 ,p_ATTRIBUTE6 => p_mtl_txn_dtls_tbl(mtl_ctr).ATTRIBUTE6
5295 ,p_ATTRIBUTE7 => p_mtl_txn_dtls_tbl(mtl_ctr).ATTRIBUTE7
5296 ,p_ATTRIBUTE8 => p_mtl_txn_dtls_tbl(mtl_ctr).ATTRIBUTE8
5297 ,p_ATTRIBUTE9 => p_mtl_txn_dtls_tbl(mtl_ctr).ATTRIBUTE9
5298 ,p_ATTRIBUTE10 => p_mtl_txn_dtls_tbl(mtl_ctr).ATTRIBUTE10
5299 ,p_ATTRIBUTE11 => p_mtl_txn_dtls_tbl(mtl_ctr).ATTRIBUTE11
5300 ,p_ATTRIBUTE12 => p_mtl_txn_dtls_tbl(mtl_ctr).ATTRIBUTE12
5301 ,p_ATTRIBUTE13 => p_mtl_txn_dtls_tbl(mtl_ctr).ATTRIBUTE13
5302 ,p_ATTRIBUTE14 => p_mtl_txn_dtls_tbl(mtl_ctr).ATTRIBUTE14
5303 ,p_ATTRIBUTE15 => p_mtl_txn_dtls_tbl(mtl_ctr).ATTRIBUTE15
5304 ,p_CREATE_RO_FLAG => p_mtl_txn_dtls_tbl(mtl_ctr).CREATE_RO_FLAG -- bug#13698799 auto create ro, parent ro
5305 );
5306
5307 else
5308
5309 IF ( FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
5310 FND_LOG.STRING( FND_LOG.LEVEL_EVENT,
5311 lc_mod_name||'beforecallupdaterow',
5312 'Just before calling CSD_WIP_TRANSACTION_DTLS_PKG.Update_Row');
5313 END IF;
5314
5315 CSD_WIP_TRANSACTION_DTLS_PKG.Update_Row(
5316 p_WIP_TRANSACTION_DETAIL_ID => p_mtl_txn_dtls_tbl(mtl_ctr).WIP_TRANSACTION_DETAIL_ID
5317 ,p_CREATED_BY => null
5318 ,p_CREATION_DATE => null
5319 ,p_LAST_UPDATED_BY => l_last_updated_by
5320 ,p_LAST_UPDATE_DATE => l_last_update_date
5321 ,p_LAST_UPDATE_LOGIN => l_last_update_login
5322 ,p_INVENTORY_ITEM_ID => null
5323 ,p_WIP_ENTITY_ID => null
5324 ,p_OPERATION_SEQ_NUM => null
5325 ,p_RESOURCE_SEQ_NUM => null
5326 ,p_employee_id => null
5327 ,p_TRANSACTION_QUANTITY => p_mtl_txn_dtls_tbl(mtl_ctr).TRANSACTION_QUANTITY
5328 ,p_TRANSACTION_UOM => p_mtl_txn_dtls_tbl(mtl_ctr).TRANSACTION_UOM
5329 ,p_SERIAL_NUMBER => nvl(p_mtl_txn_dtls_tbl(mtl_ctr).SERIAL_NUMBER, FND_API.G_MISS_CHAR)
5330 ,p_REVISION => nvl(p_mtl_txn_dtls_tbl(mtl_ctr).REVISION, FND_API.G_MISS_CHAR) -- swai: bug 6995498/7182047
5331 ,p_REASON_ID => nvl(p_mtl_txn_dtls_tbl(mtl_ctr).REASON_ID, FND_API.G_MISS_NUM)-- swai bug 6841113
5332 ,p_BACKFLUSH_FLAG => null
5333 ,p_COUNT_POINT_TYPE => null
5334 ,p_DEPARTMENT_ID => null
5335 ,p_DESCRIPTION => null
5336 ,p_FIRST_UNIT_COMPLETION_DATE => null
5337 ,p_FIRST_UNIT_START_DATE => null
5338 ,p_LAST_UNIT_COMPLETION_DATE => null
5339 ,p_LAST_UNIT_START_DATE => null
5340 ,p_MINIMUM_TRANSFER_QUANTITY => null
5341 ,p_STANDARD_OPERATION_ID => null
5342 ,p_OBJECT_VERSION_NUMBER => p_mtl_txn_dtls_tbl(mtl_ctr).object_version_number
5343 -- yvchen: bug 13258460 - 12.1.3+ add DFF attributes
5344 ,p_ATTRIBUTE_CATEGORY => nvl(p_mtl_txn_dtls_tbl(mtl_ctr).ATTRIBUTE_CATEGORY, FND_API.G_MISS_CHAR)
5345 ,p_ATTRIBUTE1 => nvl(p_mtl_txn_dtls_tbl(mtl_ctr).ATTRIBUTE1, FND_API.G_MISS_CHAR)
5346 ,p_ATTRIBUTE2 => nvl(p_mtl_txn_dtls_tbl(mtl_ctr).ATTRIBUTE2, FND_API.G_MISS_CHAR)
5347 ,p_ATTRIBUTE3 => nvl(p_mtl_txn_dtls_tbl(mtl_ctr).ATTRIBUTE3, FND_API.G_MISS_CHAR)
5348 ,p_ATTRIBUTE4 => nvl(p_mtl_txn_dtls_tbl(mtl_ctr).ATTRIBUTE4, FND_API.G_MISS_CHAR)
5349 ,p_ATTRIBUTE5 => nvl(p_mtl_txn_dtls_tbl(mtl_ctr).ATTRIBUTE5, FND_API.G_MISS_CHAR)
5350 ,p_ATTRIBUTE6 => nvl(p_mtl_txn_dtls_tbl(mtl_ctr).ATTRIBUTE6, FND_API.G_MISS_CHAR)
5351 ,p_ATTRIBUTE7 => nvl(p_mtl_txn_dtls_tbl(mtl_ctr).ATTRIBUTE7, FND_API.G_MISS_CHAR)
5352 ,p_ATTRIBUTE8 => nvl(p_mtl_txn_dtls_tbl(mtl_ctr).ATTRIBUTE8, FND_API.G_MISS_CHAR)
5353 ,p_ATTRIBUTE9 => nvl(p_mtl_txn_dtls_tbl(mtl_ctr).ATTRIBUTE9, FND_API.G_MISS_CHAR)
5354 ,p_ATTRIBUTE10 => nvl(p_mtl_txn_dtls_tbl(mtl_ctr).ATTRIBUTE10, FND_API.G_MISS_CHAR)
5355 ,p_ATTRIBUTE11 => nvl(p_mtl_txn_dtls_tbl(mtl_ctr).ATTRIBUTE11, FND_API.G_MISS_CHAR)
5356 ,p_ATTRIBUTE12 => nvl(p_mtl_txn_dtls_tbl(mtl_ctr).ATTRIBUTE12, FND_API.G_MISS_CHAR)
5357 ,p_ATTRIBUTE13 => nvl(p_mtl_txn_dtls_tbl(mtl_ctr).ATTRIBUTE13, FND_API.G_MISS_CHAR)
5358 ,p_ATTRIBUTE14 => nvl(p_mtl_txn_dtls_tbl(mtl_ctr).ATTRIBUTE14, FND_API.G_MISS_CHAR)
5359 ,p_ATTRIBUTE15 => nvl(p_mtl_txn_dtls_tbl(mtl_ctr).ATTRIBUTE15, FND_API.G_MISS_CHAR)
5360 ,p_CREATE_RO_FLAG => nvl(p_mtl_txn_dtls_tbl(mtl_ctr).CREATE_RO_FLAG, FND_API.G_MISS_CHAR) -- bug#13698799 auto create ro, parent ro
5361 );
5362
5363 end if;
5364
5365 END LOOP;
5366
5367 -- Standard check for p_commit
5368 IF FND_API.to_Boolean( p_commit )
5369 THEN
5370 COMMIT WORK;
5371 END IF;
5372
5373 EXCEPTION
5374 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
5375 ROLLBACK to PROCESS_SAVE_MTL_TXN_DTLS_PVT ;
5376 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5377
5378 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
5379 p_count => x_msg_count,
5380 p_data => x_msg_data);
5381
5382 IF ( FND_LOG.LEVEL_EXCEPTION >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
5383 FND_LOG.STRING( FND_LOG.LEVEL_EXCEPTION,
5384 lc_mod_name||'unx_exception',
5385 'G_EXC_UNEXPECTED_ERROR Exception');
5386 END IF;
5387
5388
5389 WHEN FND_API.G_EXC_ERROR THEN
5390 ROLLBACK to PROCESS_SAVE_MTL_TXN_DTLS_PVT ;
5391 x_return_status := FND_API.G_RET_STS_ERROR;
5392
5393
5394 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
5395 p_count => x_msg_count,
5396 p_data => x_msg_data);
5397
5398 IF ( FND_LOG.LEVEL_ERROR >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
5399 FND_LOG.STRING( FND_LOG.LEVEL_ERROR,
5400 lc_mod_name||'exc_exception',
5401 'G_EXC_ERROR Exception');
5402 END IF;
5403
5404 WHEN OTHERS THEN
5405 ROLLBACK to PROCESS_SAVE_MTL_TXN_DTLS_PVT ;
5406 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5407
5408 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
5409
5410 -- Add Unexpected Error to Message List, here SQLERRM is used for
5411 -- getting the error
5412
5413 FND_MSG_PUB.add_exc_msg(p_pkg_name => G_PKG_NAME,
5414 p_procedure_name => lc_api_name );
5415 END IF;
5416
5417 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
5418 p_count => x_msg_count,
5419 p_data => x_msg_data);
5420
5421 IF ( FND_LOG.LEVEL_EXCEPTION >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
5422 FND_LOG.STRING( FND_LOG.LEVEL_EXCEPTION,
5423 lc_mod_name||'others_exception',
5424 'OTHERS Exception');
5425 END IF;
5426
5427
5428
5429 END PROCESS_SAVE_MTL_TXN_DTLS;
5430
5431
5432
5433 PROCEDURE PROCESS_SAVE_RES_TXN_DTLS
5434 (
5435 p_api_version_number IN NUMBER,
5436 p_init_msg_list IN VARCHAR2,
5437 p_Commit IN VARCHAR2,
5438 p_validation_level IN NUMBER,
5439 x_return_status OUT NOCOPY VARCHAR2,
5440 x_msg_count OUT NOCOPY NUMBER,
5441 x_msg_data OUT NOCOPY VARCHAR2,
5442 p_res_txn_dtls_tbl IN res_TXN_DTLS_TBL_TYPE
5443 -- p_ro_quantity IN NUMBER
5444 )
5445 IS
5446 lc_api_name CONSTANT VARCHAR2(30) := 'PROCESS_SAVE_RES_TXN_DTLS';
5447 lc_api_version_number CONSTANT NUMBER := 1.0;
5448
5449 -- constants used for FND_LOG debug messages
5450
5451 lc_mod_name CONSTANT VARCHAR2(2000) := 'csd.plsql.csd_wip_job_pvt.insert_job_header.';
5452
5453
5454 -- Constants Used for Inserting into wip_job_schedule_interface,
5455 -- These are the values needed for WIP Mass Load to pick up the records
5456
5457 -- Non Standard Update Discrete Job Load Type
5458 lc_non_std_update_load_type CONSTANT NUMBER := 3;
5459
5460
5461 lc_load_res_type CONSTANT NUMBER := 1;
5462 lc_substitution_add_type CONSTANT NUMBER := 2;
5463
5464 -- 11/7/05
5465 -- lc_manual_autocharge_type CONSTANT NUMBER := 2;
5466 -- lc_item_basis_type CONSTANT NUMBER := 1;
5467 -- lc_no_scheduled_flag CONSTANT NUMBER := 2;
5468 -- lc_yes_standard_rate_flag CONSTANT NUMBER := 1;
5469
5470
5471 -- Job Records to hold the Job header and details information
5472
5473 l_job_header_rec wip_job_schedule_interface%ROWTYPE;
5474 l_job_details_rec wip_job_dtls_interface%ROWTYPE;
5475
5476
5477 l_creation_date DATE;
5478 l_last_update_date DATE;
5479 l_created_by NUMBER;
5480 l_created_by_name VARCHAr2(100);
5481 l_last_updated_by NUMBER;
5482 l_last_updated_by_name VARCHAR2(100);
5483 l_last_update_login NUMBER;
5484
5485
5486 l_WIP_TRANSACTION_DETAIL_ID NUMBER;
5487 -- l_validation_level NUMBER;
5488
5489 l_job_quantity NUMBER;
5490
5491 l_resource_seq_num NUMBER;
5492
5493
5494 CURSOR get_job_quantity ( p_wip_entity_id NUMBER ) IS
5495 SELECT start_quantity from wip_discrete_jobs where
5496 wip_entity_id = p_wip_entity_id ;
5497
5498 -- swai: bug 7017062 nvl the max(resource_seq_num)
5499 cursor get_next_resource_seq_num ( p_wip_entity_id NUMBER,
5500 p_operation_seq_num NUMBER ) IS
5501 select nvl(MAX(RESOURCE_SEQ_NUM),0)+ 10 from
5502 wip_operation_resources where wip_entity_id
5503 = p_wip_entity_id and operation_seq_num =
5504 p_operation_seq_num;
5505
5506
5507
5508
5509 BEGIN
5510
5511 IF ( FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
5512 FND_LOG.STRING( FND_LOG.LEVEL_PROCEDURE,
5513 lc_mod_name||'begin',
5514 'Entering private API process_save_res_txn_dtls' );
5515 END IF;
5516
5517 -- Standard Start of API savepoint
5518 SAVEPOINT PROCESS_SAVE_RES_TXN_DTLS_PVT;
5519 -- Standard call to check for call compatibility.
5520 IF NOT FND_API.Compatible_API_Call
5521 (lc_api_version_number,
5522 p_api_version_number,
5523 lc_api_name,
5524 G_PKG_NAME)
5525 THEN
5526 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5527 END IF;
5528
5529
5530 -- Initialize message list if p_init_msg_list is set to TRUE
5531 IF FND_API.to_boolean(p_init_msg_list) THEN
5532 FND_MSG_PUB.initialize;
5533 END IF;
5534
5535 x_return_status := FND_API.G_RET_STS_SUCCESS;
5536
5537
5538
5539 -- Populate the constant values
5540
5541 l_job_header_rec.load_type := lc_non_std_update_load_type;
5542
5543 l_job_details_rec.start_date := sysdate;
5544 l_job_details_rec.load_type := lc_load_res_type;
5545
5546 l_job_details_rec.substitution_type := lc_substitution_add_type;
5547
5548 -- l_job_details_rec.autocharge_type := lc_manual_autocharge_type;
5549 -- l_job_details_rec.basis_type := lc_item_basis_type;
5550 l_job_details_rec.completion_date := sysdate;
5551 -- l_job_details_rec.scheduled_flag := lc_no_scheduled_flag;
5552 -- l_job_details_rec.standard_rate_flag := lc_yes_standard_rate_flag;
5553
5554
5555
5556 -- Populate the row who columns
5557
5558 l_creation_date := SYSDATE;
5559 l_last_update_date := SYSDATE;
5560 l_created_by := fnd_global.user_id;
5561 l_last_updated_by := fnd_global.user_id;
5562 l_last_update_login := fnd_global.login_id;
5563
5564 FOR res_ctr in p_res_txn_dtls_tbl.FIRST.. p_res_txn_dtls_tbl.LAST
5565
5566 LOOP
5567
5568 l_resource_seq_num := p_res_txn_dtls_tbl(res_ctr).resource_seq_num;
5569
5570
5571 If p_res_txn_dtls_tbl(res_ctr).new_row = 'Y' then
5572
5573 -- Get the Group_id to be used for WIP Mass Load,
5574
5575 SELECT wip_job_schedule_interface_s.NEXTVAL INTO l_job_header_rec.group_id FROM dual;
5576
5577 -- get job_quantity
5578 open get_job_quantity ( p_res_txn_dtls_tbl(res_ctr).wip_entity_id);
5579 fetch get_job_quantity into l_job_quantity;
5580 close get_job_quantity;
5581
5582
5583
5584
5585 l_job_header_rec.header_id := l_job_header_rec.group_id;
5586 l_job_header_rec.wip_entity_id := p_res_txn_dtls_tbl(res_ctr).wip_entity_id;
5587 l_job_header_rec.organization_id := p_res_txn_dtls_tbl(res_ctr).organization_id;
5588
5589 l_job_details_rec.group_id := l_job_header_rec.group_id;
5590 l_job_details_rec.parent_header_id := l_job_header_rec.group_id;
5591 -- l_job_details_rec.resource_id_old := p_res_txn_dtls_tbl(res_ctr).resource_id;
5592
5593 l_job_details_rec.resource_id_new := p_res_txn_dtls_tbl(res_ctr).resource_id;
5594 l_job_details_rec.operation_seq_num := p_res_txn_dtls_tbl(res_ctr).operation_seq_num;
5595
5596
5597 open get_next_resource_seq_num ( p_res_txn_dtls_tbl(res_ctr).wip_entity_id,
5598 p_res_txn_dtls_tbl(res_ctr).operation_seq_num );
5599
5600 fetch get_next_resource_seq_num into l_job_details_rec.resource_seq_num;
5601
5602 close get_next_resource_seq_num;
5603
5604 l_resource_seq_num := l_job_details_rec.resource_seq_num;
5605
5606
5607
5608
5609 l_job_details_rec.organization_id := p_res_txn_dtls_tbl(res_ctr).organization_id;
5610 l_job_details_rec.uom_code := p_res_txn_dtls_tbl(res_ctr).transaction_uom;
5611 l_job_details_rec.usage_rate_or_amount := p_res_txn_dtls_tbl(res_ctr).transaction_quantity / l_job_quantity;
5612 l_job_details_rec.assigned_units := 1; --p_res_txn_dtls_tbl(res_ctr).transaction_quantity;
5613 l_job_details_rec.wip_entity_id := p_res_txn_dtls_tbl(res_ctr).wip_entity_id;
5614
5615
5616 -- Call procedures to insert job header and job details information
5617 -- into wip interface tables
5618
5619 IF ( FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
5620 FND_LOG.STRING( FND_LOG.LEVEL_EVENT,
5621 lc_mod_name||'beforecallinsertjob',
5622 'Just before calling insert_job_header');
5623 END IF;
5624
5625
5626 insert_job_header( p_job_header_rec => l_job_header_rec,
5627 x_return_status => x_return_status );
5628
5629
5630 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
5631 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5632 END IF;
5633
5634
5635 IF ( FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
5636 FND_LOG.STRING( FND_LOG.LEVEL_EVENT,
5637 lc_mod_name||'beforecallinsertjobdtls',
5638 'Just before calling insert_job_details');
5639 END IF;
5640
5641
5642 insert_job_details( p_job_details_rec => l_job_details_rec,
5643 x_return_status => x_return_status );
5644
5645 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
5646 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5647 END IF;
5648
5649
5650
5651 -- Call WIP Mass Load API
5652
5653 IF ( FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
5654 FND_LOG.STRING( FND_LOG.LEVEL_EVENT,
5655 lc_mod_name||'beforecallwipmassload',
5656 'Just before calling WIP_MASSLOAD_PUB.massLoadJobs');
5657 END IF;
5658
5659 BEGIN
5660 WIP_MASSLOAD_PUB.massLoadJobs(p_groupID => l_job_header_rec.group_id,
5661 p_validationLevel => p_validation_level,
5662 p_commitFlag => 0,
5663 x_returnStatus => x_return_status,
5664 x_errorMsg => x_msg_data );
5665
5666 If ( ml_error_exists( l_job_header_rec.group_id ) or
5667 x_return_status <> FND_API.G_RET_STS_SUCCESS ) THEN
5668
5669 FND_MESSAGE.SET_NAME('CSD','CSD_RES_ADD_MASS_LD_FAILURE');
5670 FND_MSG_PUB.ADD;
5671 x_return_status := FND_API.G_RET_STS_ERROR;
5672
5673 FND_MSG_PUB.count_and_get(p_encoded => FND_API.G_FALSE,
5674 p_count => x_msg_count,
5675 p_data => x_msg_data);
5676
5677 -- Need to rollback Raise exception -
5678 -- once commit is removed from above call
5679 -- raise FND_API.G_EXC_ERROR;
5680 RETURN;
5681 end if;
5682
5683 --bug#12316893
5684 IF (nvl(fnd_profile.value('MRP_DEBUG'),'Y') = 'N') THEN
5685 WIP_MASS_LOAD_PROCESSOR.Delete_Completed_Records(l_job_header_rec.group_id);
5686 End If;
5687 --bug#12316893
5688
5689
5690 EXCEPTION
5691 WHEN OTHERS THEN
5692 add_wip_interface_errors(l_job_header_rec.group_id,
5693 3 /* 3 = resources */);
5694 -- raise FND_API.G_EXC_UNEXPECTED_ERROR;
5695
5696 -- when rollback for WIP works, remove x_return_status, count_and_get,
5697 -- and return then reinstate raise exception above
5698 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5699 /*
5700 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
5701 -- Add Unexpected Error to Message List, here SQLERRM is used for
5702 -- getting the error
5703 FND_MSG_PUB.add_exc_msg(p_pkg_name => G_PKG_NAME,
5704 p_procedure_name => lc_api_name );
5705 END IF;
5706 */
5707 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
5708 p_count => x_msg_count,
5709 p_data => x_msg_data);
5710 return;
5711 END;
5712 end if;
5713
5714 If p_res_txn_dtls_tbl(res_ctr).WIP_TRANSACTION_DETAIL_ID is null then
5715
5716 IF ( FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
5717 FND_LOG.STRING( FND_LOG.LEVEL_EVENT,
5718 lc_mod_name||'beforecallinsertrow',
5719 'Just before calling CSD_WIP_TRANSACTION_DTLS_PKG.Insert_Row');
5720 END IF;
5721
5722 l_WIP_TRANSACTION_DETAIL_ID := null;
5723
5724 CSD_WIP_TRANSACTION_DTLS_PKG.Insert_Row(
5725 px_WIP_TRANSACTION_DETAIL_ID => l_WIP_TRANSACTION_DETAIL_ID
5726 ,p_CREATED_BY => l_created_by
5727 ,p_CREATION_DATE => l_creation_date
5728 ,p_LAST_UPDATED_BY => l_last_updated_by
5729 ,p_LAST_UPDATE_DATE => l_last_update_date
5730 ,p_LAST_UPDATE_LOGIN => l_last_update_login
5731 ,p_INVENTORY_ITEM_ID => null
5732 ,p_WIP_ENTITY_ID => p_res_txn_dtls_tbl(res_ctr).WIP_ENTITY_ID
5733 ,p_OPERATION_SEQ_NUM => p_res_txn_dtls_tbl(res_ctr).OPERATION_SEQ_NUM
5734 ,p_RESOURCE_SEQ_NUM => l_RESOURCE_SEQ_NUM
5735 ,p_employee_id => p_res_txn_dtls_tbl(res_ctr).employee_id
5736 ,p_TRANSACTION_QUANTITY => p_res_txn_dtls_tbl(res_ctr).TRANSACTION_QUANTITY
5737 ,p_TRANSACTION_UOM => p_res_txn_dtls_tbl(res_ctr).TRANSACTION_UOM
5738 ,p_SERIAL_NUMBER => NULL
5739 ,p_REVISION => NULL -- swai: bug 6995498/7182047
5740 ,p_REASON_ID => null -- swai bug 6841113
5741 ,p_BACKFLUSH_FLAG => null
5742 ,p_COUNT_POINT_TYPE => null
5743 ,p_DEPARTMENT_ID => null
5744 ,p_DESCRIPTION => null
5745 ,p_FIRST_UNIT_COMPLETION_DATE => null
5746 ,p_FIRST_UNIT_START_DATE => null
5747 ,p_LAST_UNIT_COMPLETION_DATE => null
5748 ,p_LAST_UNIT_START_DATE => null
5749 ,p_MINIMUM_TRANSFER_QUANTITY => null
5750 ,p_STANDARD_OPERATION_ID => null
5751 -- swai: bug 15955754, FP of bug 14823164 - 12.1.3+ add DFF attributes
5752 ,p_ATTRIBUTE_CATEGORY => p_res_txn_dtls_tbl(res_ctr).ATTRIBUTE_CATEGORY
5753 ,p_ATTRIBUTE1 => p_res_txn_dtls_tbl(res_ctr).ATTRIBUTE1
5754 ,p_ATTRIBUTE2 => p_res_txn_dtls_tbl(res_ctr).ATTRIBUTE2
5755 ,p_ATTRIBUTE3 => p_res_txn_dtls_tbl(res_ctr).ATTRIBUTE3
5756 ,p_ATTRIBUTE4 => p_res_txn_dtls_tbl(res_ctr).ATTRIBUTE4
5757 ,p_ATTRIBUTE5 => p_res_txn_dtls_tbl(res_ctr).ATTRIBUTE5
5758 ,p_ATTRIBUTE6 => p_res_txn_dtls_tbl(res_ctr).ATTRIBUTE6
5759 ,p_ATTRIBUTE7 => p_res_txn_dtls_tbl(res_ctr).ATTRIBUTE7
5760 ,p_ATTRIBUTE8 => p_res_txn_dtls_tbl(res_ctr).ATTRIBUTE8
5761 ,p_ATTRIBUTE9 => p_res_txn_dtls_tbl(res_ctr).ATTRIBUTE9
5762 ,p_ATTRIBUTE10 => p_res_txn_dtls_tbl(res_ctr).ATTRIBUTE10
5763 ,p_ATTRIBUTE11 => p_res_txn_dtls_tbl(res_ctr).ATTRIBUTE11
5764 ,p_ATTRIBUTE12 => p_res_txn_dtls_tbl(res_ctr).ATTRIBUTE12
5765 ,p_ATTRIBUTE13 => p_res_txn_dtls_tbl(res_ctr).ATTRIBUTE13
5766 ,p_ATTRIBUTE14 => p_res_txn_dtls_tbl(res_ctr).ATTRIBUTE14
5767 ,p_ATTRIBUTE15 => p_res_txn_dtls_tbl(res_ctr).ATTRIBUTE15
5768 ,p_CREATE_RO_FLAG => null -- bug#13698799 auto create ro, parent ro
5769 );
5770 else
5771
5772 IF ( FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
5773 FND_LOG.STRING( FND_LOG.LEVEL_EVENT,
5774 lc_mod_name||'beforecallupdaterow',
5775 'Just before calling CSD_WIP_TRANSACTION_DTLS_PKG.Update_Row');
5776 END IF;
5777
5778
5779 CSD_WIP_TRANSACTION_DTLS_PKG.Update_Row(
5780 p_WIP_TRANSACTION_DETAIL_ID => p_res_txn_dtls_tbl(res_ctr).WIP_TRANSACTION_DETAIL_ID
5781 ,p_CREATED_BY => null
5782 ,p_CREATION_DATE => null
5783 ,p_LAST_UPDATED_BY => l_last_updated_by
5784 ,p_LAST_UPDATE_DATE => l_last_update_date
5785 ,p_LAST_UPDATE_LOGIN => l_last_update_login
5786 ,p_INVENTORY_ITEM_ID => null
5787 ,p_WIP_ENTITY_ID => null
5788 ,p_OPERATION_SEQ_NUM => null
5789 ,p_RESOURCE_SEQ_NUM => null
5790 ,p_employee_id => nvl(p_res_txn_dtls_tbl(res_ctr).employee_id, FND_API.G_MISS_NUM)
5791 ,p_TRANSACTION_QUANTITY => p_res_txn_dtls_tbl(res_ctr).TRANSACTION_QUANTITY
5792 ,p_TRANSACTION_UOM => p_res_txn_dtls_tbl(res_ctr).TRANSACTION_UOM
5793 ,p_SERIAL_NUMBER => null
5794 ,p_REVISION => null -- swai: bug 6995498/7182047
5795 ,p_REASON_ID => null -- swai bug 6841113
5796 ,p_BACKFLUSH_FLAG => null
5797 ,p_COUNT_POINT_TYPE => null
5798 ,p_DEPARTMENT_ID => null
5799 ,p_DESCRIPTION => null
5800 ,p_FIRST_UNIT_COMPLETION_DATE => null
5801 ,p_FIRST_UNIT_START_DATE => null
5802 ,p_LAST_UNIT_COMPLETION_DATE => null
5803 ,p_LAST_UNIT_START_DATE => null
5804 ,p_MINIMUM_TRANSFER_QUANTITY => null
5805 ,p_STANDARD_OPERATION_ID => null
5806 ,p_OBJECT_VERSION_NUMBER => p_res_txn_dtls_tbl(res_ctr).object_version_number
5807 -- swai: bug 15955754, FP of bug 14823164 - 12.1.3+ add DFF attributes
5808 ,p_ATTRIBUTE_CATEGORY => nvl(p_res_txn_dtls_tbl(res_ctr).ATTRIBUTE_CATEGORY, FND_API.G_MISS_CHAR)
5809 ,p_ATTRIBUTE1 => nvl(p_res_txn_dtls_tbl(res_ctr).ATTRIBUTE1, FND_API.G_MISS_CHAR)
5810 ,p_ATTRIBUTE2 => nvl(p_res_txn_dtls_tbl(res_ctr).ATTRIBUTE2, FND_API.G_MISS_CHAR)
5811 ,p_ATTRIBUTE3 => nvl(p_res_txn_dtls_tbl(res_ctr).ATTRIBUTE3, FND_API.G_MISS_CHAR)
5812 ,p_ATTRIBUTE4 => nvl(p_res_txn_dtls_tbl(res_ctr).ATTRIBUTE4, FND_API.G_MISS_CHAR)
5813 ,p_ATTRIBUTE5 => nvl(p_res_txn_dtls_tbl(res_ctr).ATTRIBUTE5, FND_API.G_MISS_CHAR)
5814 ,p_ATTRIBUTE6 => nvl(p_res_txn_dtls_tbl(res_ctr).ATTRIBUTE6, FND_API.G_MISS_CHAR)
5815 ,p_ATTRIBUTE7 => nvl(p_res_txn_dtls_tbl(res_ctr).ATTRIBUTE7, FND_API.G_MISS_CHAR)
5816 ,p_ATTRIBUTE8 => nvl(p_res_txn_dtls_tbl(res_ctr).ATTRIBUTE8, FND_API.G_MISS_CHAR)
5817 ,p_ATTRIBUTE9 => nvl(p_res_txn_dtls_tbl(res_ctr).ATTRIBUTE9, FND_API.G_MISS_CHAR)
5818 ,p_ATTRIBUTE10 => nvl(p_res_txn_dtls_tbl(res_ctr).ATTRIBUTE10, FND_API.G_MISS_CHAR)
5819 ,p_ATTRIBUTE11 => nvl(p_res_txn_dtls_tbl(res_ctr).ATTRIBUTE11, FND_API.G_MISS_CHAR)
5820 ,p_ATTRIBUTE12 => nvl(p_res_txn_dtls_tbl(res_ctr).ATTRIBUTE12, FND_API.G_MISS_CHAR)
5821 ,p_ATTRIBUTE13 => nvl(p_res_txn_dtls_tbl(res_ctr).ATTRIBUTE13, FND_API.G_MISS_CHAR)
5822 ,p_ATTRIBUTE14 => nvl(p_res_txn_dtls_tbl(res_ctr).ATTRIBUTE14, FND_API.G_MISS_CHAR)
5823 ,p_ATTRIBUTE15 => nvl(p_res_txn_dtls_tbl(res_ctr).ATTRIBUTE15, FND_API.G_MISS_CHAR)
5824 ,p_CREATE_RO_FLAG => null --bug#13698799 auto create ro, parent ro
5825 );
5826
5827 end if;
5828
5829 END LOOP;
5830
5831 -- Standard check for p_commit
5832 IF FND_API.to_Boolean( p_commit )
5833 THEN
5834 COMMIT WORK;
5835 END IF;
5836
5837 EXCEPTION
5838 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
5839 ROLLBACK to PROCESS_SAVE_RES_TXN_DTLS_PVT ;
5840 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5841
5842 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
5843 p_count => x_msg_count,
5844 p_data => x_msg_data);
5845
5846 IF ( FND_LOG.LEVEL_EXCEPTION >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
5847 FND_LOG.STRING( FND_LOG.LEVEL_EXCEPTION,
5848 lc_mod_name||'unx_exception',
5849 'G_EXC_UNEXPECTED_ERROR Exception');
5850 END IF;
5851
5852
5853 WHEN FND_API.G_EXC_ERROR THEN
5854 ROLLBACK to PROCESS_SAVE_RES_TXN_DTLS_PVT ;
5855 x_return_status := FND_API.G_RET_STS_ERROR;
5856
5857
5858 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
5859 p_count => x_msg_count,
5860 p_data => x_msg_data);
5861
5862 IF ( FND_LOG.LEVEL_ERROR >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
5863 FND_LOG.STRING( FND_LOG.LEVEL_ERROR,
5864 lc_mod_name||'exc_exception',
5865 'G_EXC_ERROR Exception');
5866 END IF;
5867
5868 WHEN OTHERS THEN
5869 ROLLBACK to PROCESS_SAVE_RES_TXN_DTLS_PVT ;
5870 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5871
5872 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
5873
5874 -- Add Unexpected Error to Message List, here SQLERRM is used for
5875 -- getting the error
5876
5877 FND_MSG_PUB.add_exc_msg(p_pkg_name => G_PKG_NAME,
5878 p_procedure_name => lc_api_name );
5879 END IF;
5880
5881 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
5882 p_count => x_msg_count,
5883 p_data => x_msg_data);
5884
5885 IF ( FND_LOG.LEVEL_EXCEPTION >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
5886 FND_LOG.STRING( FND_LOG.LEVEL_EXCEPTION,
5887 lc_mod_name||'others_exception',
5888 'OTHERS Exception');
5889 END IF;
5890
5891
5892 END PROCESS_SAVE_RES_TXN_DTLS;
5893
5894
5895 PROCEDURE PROCESS_SAVE_OP_DTLS
5896 (
5897 p_api_version_number IN NUMBER,
5898 p_init_msg_list IN VARCHAR2,
5899 p_Commit IN VARCHAR2,
5900 p_validation_level IN NUMBER,
5901 x_return_status OUT NOCOPY VARCHAR2,
5902 x_msg_count OUT NOCOPY NUMBER,
5903 x_msg_data OUT NOCOPY VARCHAR2,
5904 p_op_dtls_tbl IN OP_DTLS_TBL_TYPE
5905 )
5906 IS
5907 lc_api_name CONSTANT VARCHAR2(30) := 'PROCESS_SAVE_OP_DTLS';
5908 lc_api_version_number CONSTANT NUMBER := 1.0;
5909
5910 -- constants used for FND_LOG debug messages
5911 lc_mod_name CONSTANT VARCHAR2(2000) := 'csd.plsql.csd_wip_job_pvt.process_save_op_dtls.';
5912
5913 -- Constants Used for Inserting into wip_job_schedule_interface,
5914 -- These are the values needed for WIP Mass Load to pick up the records
5915 lc_non_std_update_load_type CONSTANT NUMBER := 3; -- load type for update non standard discrete job
5916
5917 -- Constants Used for Inserting into wip_job_dtls_interface
5918 lc_load_op_type CONSTANT NUMBER := 3; -- load type for operations
5919 lc_substitution_add_type CONSTANT NUMBER := 2; -- indicates add record (vs. change=3 or delete=1)
5920 lc_substitution_change_type CONSTANT NUMBER := 3; -- indicates change record (vs. add=2 or delete=1)
5921 lc_process_validation_phase CONSTANT NUMBER := 2; -- must be 2 for WIP to pick up record
5922 lc_process_pending_status CONSTANT NUMBER := 1; -- must be 1 for WIP to pick up record
5923
5924 -- Job Records to hold the Job header and details information
5925 l_job_header_rec wip_job_schedule_interface%ROWTYPE;
5926 l_job_details_rec wip_job_dtls_interface%ROWTYPE;
5927
5928 -- variables for WHO columns
5929 l_creation_date DATE;
5930 l_last_update_date DATE;
5931 l_created_by NUMBER;
5932 l_last_updated_by NUMBER;
5933 l_last_update_login NUMBER;
5934
5935 -- primary key for CSD_WIP_TRANSACTION_DETAILS table
5936 l_wip_transaction_detail_id NUMBER;
5937
5938 BEGIN
5939
5940 IF ( FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
5941 FND_LOG.STRING( FND_LOG.LEVEL_PROCEDURE,
5942 lc_mod_name||'begin',
5943 'Entering private API process_save_op_dtls' );
5944 END IF;
5945
5946 -- Standard Start of API savepoint
5947 SAVEPOINT PROCESS_SAVE_OP_DTLS_PVT;
5948
5949 -- Standard call to check for call compatibility.
5950 IF NOT FND_API.Compatible_API_Call
5951 (lc_api_version_number,
5952 p_api_version_number,
5953 lc_api_name,
5954 G_PKG_NAME)
5955 THEN
5956 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5957 END IF;
5958
5959
5960 -- Initialize message list if p_init_msg_list is set to TRUE
5961 IF FND_API.to_boolean(p_init_msg_list) THEN
5962 FND_MSG_PUB.initialize;
5963 END IF;
5964
5965 x_return_status := FND_API.G_RET_STS_SUCCESS;
5966
5967 -- Populate the constant values for job header
5968 l_job_header_rec.load_type := lc_non_std_update_load_type;
5969
5970 -- Populate the constant values for job details
5971 l_job_details_rec.start_date := sysdate;
5972 l_job_details_rec.load_type := lc_load_op_type;
5973
5974 -- Get the data for the WHO columns
5975 l_creation_date := SYSDATE;
5976 l_last_update_date := SYSDATE;
5977 l_created_by := fnd_global.user_id;
5978 l_last_updated_by := fnd_global.user_id;
5979 l_last_update_login := fnd_global.login_id;
5980
5981 FOR op_ctr in p_op_dtls_tbl.FIRST.. p_op_dtls_tbl.LAST
5982 LOOP
5983 -- l_operation_seq_num := p_op_dtls_tbl(op_ctr).operation_seq_num;
5984
5985 IF p_op_dtls_tbl(op_ctr).operation_seq_num is not null THEN
5986 -- Get the Group_id to be used for WIP Mass Load,
5987
5988 SELECT wip_job_schedule_interface_s.NEXTVAL INTO l_job_header_rec.group_id FROM dual;
5989
5990 -- set job header info
5991 l_job_header_rec.header_id := l_job_header_rec.group_id;
5992 l_job_header_rec.wip_entity_id := p_op_dtls_tbl(op_ctr).wip_entity_id;
5993 l_job_header_rec.organization_id := p_op_dtls_tbl(op_ctr).organization_id;
5994
5995 -- set job details (operations) info - required columns in wip_job_dtls_interface table
5996 l_job_details_rec.group_id := l_job_header_rec.group_id;
5997 l_job_details_rec.parent_header_id := l_job_header_rec.group_id;
5998 l_job_details_rec.operation_seq_num := p_op_dtls_tbl(op_ctr).operation_seq_num;
5999 l_job_details_rec.backflush_flag := p_op_dtls_tbl(op_ctr).backflush_flag;
6000 l_job_details_rec.count_point_type := p_op_dtls_tbl(op_ctr).count_point_type;
6001 l_job_details_rec.first_unit_completion_date := p_op_dtls_tbl(op_ctr).first_unit_completion_date;
6002 l_job_details_rec.first_unit_start_date := p_op_dtls_tbl(op_ctr).first_unit_start_date;
6003 l_job_details_rec.last_unit_completion_date := p_op_dtls_tbl(op_ctr).last_unit_completion_date;
6004 l_job_details_rec.last_unit_start_date := p_op_dtls_tbl(op_ctr).last_unit_start_date;
6005 l_job_details_rec.minimum_transfer_quantity := p_op_dtls_tbl(op_ctr).minimum_transfer_quantity;
6006 l_job_details_rec.process_phase := lc_process_validation_phase;
6007 l_job_details_rec.process_status := lc_process_pending_status;
6008
6009 -- set job details (operations) info - optional columns in wip_job_dtls_interface table
6010 l_job_details_rec.description := p_op_dtls_tbl(op_ctr).description;
6011
6012 -- set job details (operations) info - not set in columns in wip_job_dtls_interface table
6013 l_job_details_rec.organization_id := p_op_dtls_tbl(op_ctr).organization_id;
6014 l_job_details_rec.wip_entity_id := p_op_dtls_tbl(op_ctr).wip_entity_id;
6015
6016 IF p_op_dtls_tbl(op_ctr).new_row = 'Y' THEN
6017 l_job_details_rec.substitution_type := lc_substitution_add_type;
6018 l_job_details_rec.department_id := p_op_dtls_tbl(op_ctr).department_id;
6019 l_job_details_rec.standard_operation_id := p_op_dtls_tbl(op_ctr).standard_operation_id;
6020 ELSE
6021 l_job_details_rec.substitution_type := lc_substitution_change_type;
6022 END IF;
6023
6024 -- Call procedures to insert job header and job details information
6025 -- into wip interface tables
6026 IF ( FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
6027 FND_LOG.STRING( FND_LOG.LEVEL_EVENT,
6028 lc_mod_name||'beforecallinsertjob',
6029 'Just before calling insert_job_header');
6030 END IF;
6031
6032 insert_job_header( p_job_header_rec => l_job_header_rec,
6033 x_return_status => x_return_status );
6034
6035 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
6036 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6037 END IF;
6038
6039 IF ( FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
6040 FND_LOG.STRING( FND_LOG.LEVEL_EVENT,
6041 lc_mod_name||'beforecallinsertjobdtls',
6042 'Just before calling insert_job_details');
6043 END IF;
6044
6045 insert_job_details( p_job_details_rec => l_job_details_rec,
6046 x_return_status => x_return_status );
6047
6048 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
6049 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6050 END IF;
6051
6052 -- Call WIP Mass Load API
6053 IF ( FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
6054 FND_LOG.STRING( FND_LOG.LEVEL_EVENT,
6055 lc_mod_name||'beforecallwipmassload',
6056 'Just before calling WIP_MASSLOAD_PUB.massLoadJobs');
6057 END IF;
6058
6059 BEGIN
6060 WIP_MASSLOAD_PUB.massLoadJobs(p_groupID => l_job_header_rec.group_id,
6061 p_validationLevel => p_validation_level,
6062 p_commitFlag => 0,
6063 x_returnStatus => x_return_status,
6064 x_errorMsg => x_msg_data );
6065
6066 If ( ml_error_exists( l_job_header_rec.group_id ) or
6067 x_return_status <> FND_API.G_RET_STS_SUCCESS ) THEN
6068
6069 FND_MESSAGE.SET_NAME('CSD','CSD_OP_ADD_MASS_LD_FAILURE');
6070 FND_MSG_PUB.ADD;
6071 x_return_status := FND_API.G_RET_STS_ERROR;
6072
6073 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
6074 p_count => x_msg_count,
6075 p_data => x_msg_data);
6076
6077 -- Need to rollback Raise exception -
6078 -- once commit is removed from above call
6079 -- raise FND_API.G_EXC_ERROR;
6080 RETURN;
6081 end if;
6082
6083 --bug#12316893
6084 IF (nvl(fnd_profile.value('MRP_DEBUG'),'Y') = 'N') THEN
6085 WIP_MASS_LOAD_PROCESSOR.Delete_Completed_Records(l_job_header_rec.group_id);
6086 End If;
6087 --bug#12316893
6088
6089 EXCEPTION
6090 WHEN OTHERS THEN
6091 add_wip_interface_errors(l_job_header_rec.group_id,
6092 1 /* 1 = operations */);
6093 -- raise FND_API.G_EXC_UNEXPECTED_ERROR;
6094
6095 -- when rollback for WIP works, remove x_return_status, count_and_get,
6096 -- and return then reinstate raise exception above
6097 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6098 /*
6099 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
6100
6101 -- Add Unexpected Error to Message List, here SQLERRM is used for
6102 -- getting the error
6103
6104 FND_MSG_PUB.add_exc_msg(p_pkg_name => G_PKG_NAME,
6105 p_procedure_name => lc_api_name );
6106 END IF;
6107 */
6108 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
6109 p_count => x_msg_count,
6110 p_data => x_msg_data);
6111 return;
6112 END;
6113 end if;
6114
6115 If p_op_dtls_tbl(op_ctr).WIP_TRANSACTION_DETAIL_ID is null then
6116 IF ( FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
6117 FND_LOG.STRING( FND_LOG.LEVEL_EVENT,
6118 lc_mod_name||'beforecallinsertrow',
6119 'Just before calling CSD_WIP_TRANSACTION_DTLS_PKG.Insert_Row');
6120 END IF;
6121
6122 l_WIP_TRANSACTION_DETAIL_ID := null;
6123
6124 CSD_WIP_TRANSACTION_DTLS_PKG.Insert_Row(
6125 px_WIP_TRANSACTION_DETAIL_ID => l_WIP_TRANSACTION_DETAIL_ID
6126 ,p_CREATED_BY => l_created_by
6127 ,p_CREATION_DATE => l_creation_date
6128 ,p_LAST_UPDATED_BY => l_last_updated_by
6129 ,p_LAST_UPDATE_DATE => l_last_update_date
6130 ,p_LAST_UPDATE_LOGIN => l_last_update_login
6131 ,p_INVENTORY_ITEM_ID => null
6132 ,p_WIP_ENTITY_ID => p_op_dtls_tbl(op_ctr).WIP_ENTITY_ID
6133 ,p_OPERATION_SEQ_NUM => p_op_dtls_tbl(op_ctr).OPERATION_SEQ_NUM
6134 ,p_RESOURCE_SEQ_NUM => null
6135 ,p_employee_id => null
6136 ,p_TRANSACTION_QUANTITY => null
6137 ,p_TRANSACTION_UOM => null
6138 ,p_SERIAL_NUMBER => NULL
6139 ,p_REVISION => NULL -- swai: bug 6995498/7182047
6140 ,p_REASON_ID => null -- swai bug 6841113
6141 ,p_BACKFLUSH_FLAG => p_op_dtls_tbl(op_ctr).BACKFLUSH_FLAG
6142 ,p_COUNT_POINT_TYPE => p_op_dtls_tbl(op_ctr).COUNT_POINT_TYPE
6143 ,p_DEPARTMENT_ID => p_op_dtls_tbl(op_ctr).DEPARTMENT_ID
6144 ,p_DESCRIPTION => p_op_dtls_tbl(op_ctr).DESCRIPTION
6145 ,p_FIRST_UNIT_COMPLETION_DATE => p_op_dtls_tbl(op_ctr).FIRST_UNIT_COMPLETION_DATE
6146 ,p_FIRST_UNIT_START_DATE => p_op_dtls_tbl(op_ctr).FIRST_UNIT_START_DATE
6147 ,p_LAST_UNIT_COMPLETION_DATE => p_op_dtls_tbl(op_ctr).LAST_UNIT_COMPLETION_DATE
6148 ,p_LAST_UNIT_START_DATE => p_op_dtls_tbl(op_ctr).LAST_UNIT_START_DATE
6149 ,p_MINIMUM_TRANSFER_QUANTITY => p_op_dtls_tbl(op_ctr).MINIMUM_TRANSFER_QUANTITY
6150 ,p_STANDARD_OPERATION_ID => p_op_dtls_tbl(op_ctr).STANDARD_OPERATION_ID
6151 -- yvchen: bug 13258460 - 12.1.3+ add DFF attributes
6152 ,p_ATTRIBUTE_CATEGORY => p_op_dtls_tbl(op_ctr).ATTRIBUTE_CATEGORY
6153 ,p_ATTRIBUTE1 => p_op_dtls_tbl(op_ctr).ATTRIBUTE1
6154 ,p_ATTRIBUTE2 => p_op_dtls_tbl(op_ctr).ATTRIBUTE2
6155 ,p_ATTRIBUTE3 => p_op_dtls_tbl(op_ctr).ATTRIBUTE3
6156 ,p_ATTRIBUTE4 => p_op_dtls_tbl(op_ctr).ATTRIBUTE4
6157 ,p_ATTRIBUTE5 => p_op_dtls_tbl(op_ctr).ATTRIBUTE5
6158 ,p_ATTRIBUTE6 => p_op_dtls_tbl(op_ctr).ATTRIBUTE6
6159 ,p_ATTRIBUTE7 => p_op_dtls_tbl(op_ctr).ATTRIBUTE7
6160 ,p_ATTRIBUTE8 => p_op_dtls_tbl(op_ctr).ATTRIBUTE8
6161 ,p_ATTRIBUTE9 => p_op_dtls_tbl(op_ctr).ATTRIBUTE9
6162 ,p_ATTRIBUTE10 => p_op_dtls_tbl(op_ctr).ATTRIBUTE10
6163 ,p_ATTRIBUTE11 => p_op_dtls_tbl(op_ctr).ATTRIBUTE11
6164 ,p_ATTRIBUTE12 => p_op_dtls_tbl(op_ctr).ATTRIBUTE12
6165 ,p_ATTRIBUTE13 => p_op_dtls_tbl(op_ctr).ATTRIBUTE13
6166 ,p_ATTRIBUTE14 => p_op_dtls_tbl(op_ctr).ATTRIBUTE14
6167 ,p_ATTRIBUTE15 => p_op_dtls_tbl(op_ctr).ATTRIBUTE15
6168 ,p_CREATE_RO_FLAG => NULL -- bug#13698799 auto create ro, parent ro
6169 );
6170
6171 else
6172 IF ( FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
6173 FND_LOG.STRING( FND_LOG.LEVEL_EVENT,
6174 lc_mod_name||'beforecallupdaterow',
6175 'Just before calling CSD_WIP_TRANSACTION_DTLS_PKG.Update_Row');
6176 END IF;
6177
6178 CSD_WIP_TRANSACTION_DTLS_PKG.Update_Row(
6179 p_WIP_TRANSACTION_DETAIL_ID => p_op_dtls_tbl(op_ctr).WIP_TRANSACTION_DETAIL_ID
6180 ,p_CREATED_BY => null
6181 ,p_CREATION_DATE => null
6182 ,p_LAST_UPDATED_BY => l_last_updated_by
6183 ,p_LAST_UPDATE_DATE => l_last_update_date
6184 ,p_LAST_UPDATE_LOGIN => l_last_update_login
6185 ,p_INVENTORY_ITEM_ID => null
6186 ,p_WIP_ENTITY_ID => null
6187 ,p_OPERATION_SEQ_NUM => null
6188 ,p_RESOURCE_SEQ_NUM => null
6189 ,p_employee_id => null
6190 ,p_TRANSACTION_QUANTITY => null
6191 ,p_TRANSACTION_UOM => null
6192 ,p_SERIAL_NUMBER => null
6193 ,p_REVISION => null -- swai: bug 6995498/7182047
6194 ,p_REASON_ID => null -- swai bug 6841113
6195 ,p_BACKFLUSH_FLAG => p_op_dtls_tbl(op_ctr).BACKFLUSH_FLAG
6196 ,p_COUNT_POINT_TYPE => p_op_dtls_tbl(op_ctr).COUNT_POINT_TYPE
6197 ,p_DEPARTMENT_ID => p_op_dtls_tbl(op_ctr).DEPARTMENT_ID
6198 ,p_DESCRIPTION => p_op_dtls_tbl(op_ctr).DESCRIPTION
6199 ,p_FIRST_UNIT_COMPLETION_DATE => p_op_dtls_tbl(op_ctr).FIRST_UNIT_COMPLETION_DATE
6200 ,p_FIRST_UNIT_START_DATE => p_op_dtls_tbl(op_ctr).FIRST_UNIT_START_DATE
6201 ,p_LAST_UNIT_COMPLETION_DATE => p_op_dtls_tbl(op_ctr).LAST_UNIT_COMPLETION_DATE
6202 ,p_LAST_UNIT_START_DATE => p_op_dtls_tbl(op_ctr).LAST_UNIT_START_DATE
6203 ,p_MINIMUM_TRANSFER_QUANTITY => p_op_dtls_tbl(op_ctr).MINIMUM_TRANSFER_QUANTITY
6204 ,p_STANDARD_OPERATION_ID => p_op_dtls_tbl(op_ctr).STANDARD_OPERATION_ID
6205 ,p_OBJECT_VERSION_NUMBER => p_op_dtls_tbl(op_ctr).object_version_number
6206 -- yvchen: bug 13258460 - 12.1.3+ add DFF attributes
6207 ,p_ATTRIBUTE_CATEGORY => nvl(p_op_dtls_tbl(op_ctr).ATTRIBUTE_CATEGORY, FND_API.G_MISS_CHAR)
6208 ,p_ATTRIBUTE1 => nvl(p_op_dtls_tbl(op_ctr).ATTRIBUTE1, FND_API.G_MISS_CHAR)
6209 ,p_ATTRIBUTE2 => nvl(p_op_dtls_tbl(op_ctr).ATTRIBUTE2, FND_API.G_MISS_CHAR)
6210 ,p_ATTRIBUTE3 => nvl(p_op_dtls_tbl(op_ctr).ATTRIBUTE3, FND_API.G_MISS_CHAR)
6211 ,p_ATTRIBUTE4 => nvl(p_op_dtls_tbl(op_ctr).ATTRIBUTE4, FND_API.G_MISS_CHAR)
6212 ,p_ATTRIBUTE5 => nvl(p_op_dtls_tbl(op_ctr).ATTRIBUTE5, FND_API.G_MISS_CHAR)
6213 ,p_ATTRIBUTE6 => nvl(p_op_dtls_tbl(op_ctr).ATTRIBUTE6, FND_API.G_MISS_CHAR)
6214 ,p_ATTRIBUTE7 => nvl(p_op_dtls_tbl(op_ctr).ATTRIBUTE7, FND_API.G_MISS_CHAR)
6215 ,p_ATTRIBUTE8 => nvl(p_op_dtls_tbl(op_ctr).ATTRIBUTE8, FND_API.G_MISS_CHAR)
6216 ,p_ATTRIBUTE9 => nvl(p_op_dtls_tbl(op_ctr).ATTRIBUTE9, FND_API.G_MISS_CHAR)
6217 ,p_ATTRIBUTE10 => nvl(p_op_dtls_tbl(op_ctr).ATTRIBUTE10, FND_API.G_MISS_CHAR)
6218 ,p_ATTRIBUTE11 => nvl(p_op_dtls_tbl(op_ctr).ATTRIBUTE11, FND_API.G_MISS_CHAR)
6219 ,p_ATTRIBUTE12 => nvl(p_op_dtls_tbl(op_ctr).ATTRIBUTE12, FND_API.G_MISS_CHAR)
6220 ,p_ATTRIBUTE13 => nvl(p_op_dtls_tbl(op_ctr).ATTRIBUTE13, FND_API.G_MISS_CHAR)
6221 ,p_ATTRIBUTE14 => nvl(p_op_dtls_tbl(op_ctr).ATTRIBUTE14, FND_API.G_MISS_CHAR)
6222 ,p_ATTRIBUTE15 => nvl(p_op_dtls_tbl(op_ctr).ATTRIBUTE15, FND_API.G_MISS_CHAR)
6223 ,p_CREATE_RO_FLAG => NULL --bug#13698799 auto create ro, parent ro
6224 );
6225
6226 end if;
6227 END LOOP;
6228
6229 -- Standard check for p_commit
6230 IF FND_API.to_Boolean( p_commit )
6231 THEN
6232 COMMIT WORK;
6233 END IF;
6234
6235 EXCEPTION
6236 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
6237 ROLLBACK to PROCESS_SAVE_OP_DTLS_PVT ;
6238 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6239
6240 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
6241 p_count => x_msg_count,
6242 p_data => x_msg_data);
6243
6244 IF ( FND_LOG.LEVEL_EXCEPTION >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
6245 FND_LOG.STRING( FND_LOG.LEVEL_EXCEPTION,
6246 lc_mod_name||'unx_exception',
6247 'G_EXC_UNEXPECTED_ERROR Exception');
6248 END IF;
6249
6250
6251 WHEN FND_API.G_EXC_ERROR THEN
6252 ROLLBACK to PROCESS_SAVE_OP_DTLS_PVT ;
6253 x_return_status := FND_API.G_RET_STS_ERROR;
6254
6255
6256 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
6257 p_count => x_msg_count,
6258 p_data => x_msg_data);
6259
6260 IF ( FND_LOG.LEVEL_ERROR >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
6261 FND_LOG.STRING( FND_LOG.LEVEL_ERROR,
6262 lc_mod_name||'exc_exception',
6263 'G_EXC_ERROR Exception');
6264 END IF;
6265
6266 WHEN OTHERS THEN
6267 ROLLBACK to PROCESS_SAVE_OP_DTLS_PVT ;
6268 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6269
6270 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
6271
6272 -- Add Unexpected Error to Message List, here SQLERRM is used for
6273 -- getting the error
6274
6275 FND_MSG_PUB.add_exc_msg(p_pkg_name => G_PKG_NAME,
6276 p_procedure_name => lc_api_name );
6277 END IF;
6278
6279 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
6280 p_count => x_msg_count,
6281 p_data => x_msg_data);
6282
6283 IF ( FND_LOG.LEVEL_EXCEPTION >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
6284 FND_LOG.STRING( FND_LOG.LEVEL_EXCEPTION,
6285 lc_mod_name||'others_exception',
6286 'OTHERS Exception');
6287 END IF;
6288 END PROCESS_SAVE_OP_DTLS;
6289
6290
6291 PROCEDURE create_wip_job
6292 (
6293 p_api_version_number IN NUMBER,
6294 p_init_msg_list IN VARCHAR2 ,
6295 p_commit IN VARCHAR2 ,
6296 p_validation_level IN NUMBER,
6297 x_return_status OUT NOCOPY VARCHAR2,
6298 x_msg_count OUT NOCOPY NUMBER,
6299 x_msg_data OUT NOCOPY VARCHAR2,
6300 x_job_name OUT NOCOPY VARCHAR2,
6301 p_repair_line_id IN NUMBER,
6302 p_repair_quantity IN NUMBER,
6303 p_inventory_item_Id IN NUMBER
6304 )
6305 IS
6306
6307 -- Job Record to hold the Job header, bills and routing information being inserted
6308 -- into wip_job_schedule_interface
6309
6310 l_job_header_rec wip_job_schedule_interface%ROWTYPE;
6311
6312 lc_api_name CONSTANT VARCHAR2(30) := 'CREATE_WIP_JOB';
6313 lc_api_version_number CONSTANT NUMBER := 1.0;
6314
6315 -- WIP Job Status Lookup Codes for Released and Unreleased status, --- The Lookup Type is WIP_JOB_STATUS
6316
6317 lc_released_status_code CONSTANT NUMBER := 3;
6318 lc_unreleased_status_code CONSTANT NUMBER := 1;
6319
6320 -- Non Standard Discrete Job Load Type
6321 lc_non_standard_load_type CONSTANT NUMBER := 4;
6322
6323
6324 -- COnstants used for FND_LOG debug messages
6325
6326 lc_mod_name CONSTANT VARCHAR2(2000) := 'csd.plsql.csd_hv_wip_job_pvt.create_wip_job';
6327
6328
6329
6330 l_user_id NUMBER;
6331 l_repair_xref_id NUMBER;
6332 l_rep_hist_id NUMBER;
6333
6334 l_job_prefix VARCHAR2(80);
6335 l_wip_entity_id NUMBER;
6336
6337
6338 --*****Below are the code to Default Repair Item as Material on Job**********
6339 l_default_ro_item VARCHAR2(1);
6340 -- l_wip_entity_id NUMBER;
6341 l_mtl_txn_dtls_tbl CSD_HV_WIP_JOB_PVT.MTL_TXN_DTLS_TBL_TYPE;
6342 l_op_created VARCHAR2(10);
6343 l_num_other_jobs NUMBER :=0; -- swai: bug 7477845/7483291
6344
6345
6346 CURSOR c_repair_line_info(p_repair_line_id IN NUMBER) IS
6347 select inventory_item_id, unit_of_measure, quantity, serial_number
6348 -- , inventory_org_id -- swai: bug 9954780
6349 from csd_repairs
6350 where repair_line_id = p_repair_line_id;
6351
6352 --bug#13472453
6353 CURSOR c_repair_project_info(p_repair_line_id IN NUMBER) IS
6354 select project_id, task_id, unit_number
6355 from csd_repairs
6356 where repair_line_id = p_repair_line_id;
6357
6358 l_org_id NUMBER;
6359 --bug#13472453
6360
6361 CURSOR c_count_material(p_wip_entity_id NUMBER, l_inventory_item_id NUMBER) IS
6362 select 'X'
6363 from wip_requirement_operations_v
6364 where wip_entity_id = p_wip_entity_id
6365 and inventory_item_id = l_inventory_item_id
6366 and rownum = 1;
6367
6368
6369 -- Cursor to select the item attributes serial control code and
6370 -- lot control code.
6371 CURSOR cur_get_item_attribs (
6372 p_org_id NUMBER,
6373 p_item_id NUMBER
6374 )
6375 IS
6376 SELECT serial_number_control_code
6377 FROM mtl_system_items
6378 WHERE organization_id = p_org_id AND inventory_item_id = p_item_id;
6379
6380
6381 Cursor c_get_serial_info(p_item_id number, p_serial_number varchar2, p_org_id number) is
6382 select current_status, current_subinventory_code from mtl_serial_numbers
6383 where inventory_item_id = p_item_id and serial_number = p_serial_number and current_organization_id = p_org_id;
6384
6385
6386 -- Cursor c_get_min_operation_seq(p_wip_entity_id number) is
6387 -- select min(operation_seq_num) from wip_operations_v where wip_entity_id = p_wip_entity_id;
6388
6389 l_inventory_item_id NUMBER;
6390 l_unit_of_measure VARCHAR2(3);
6391 l_quantity NUMBER;
6392 l_serial_number VARCHAR2(30);
6393 l_inventory_org_id NUMBER;
6394 l_subinventory VARCHAR2(30);
6395 l_dummy VARCHAR2(1) := null;
6396 l_serial_control_code NUMBER;
6397 l_current_status NUMBER;
6398 l_current_subinventory_code VARCHAR2(10);
6399 l_operation_seq_num NUMBER;
6400
6401 l_rule_input_rec CSD_RULES_ENGINE_PVT.CSD_RULE_INPUT_REC_TYPE;
6402 l_default_reason_id NUMBER;
6403 l_default_create_ro_flag VARCHAR2(1); -- bug#13868879 default create ro flag
6404 l_default_rule_id NUMBER;
6405 l_return_status VARCHAR2(1);
6406 l_msg_count NUMBER;
6407 l_msg_data VARCHAR2(2000);
6408
6409 BEGIN
6410
6411 IF ( FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
6412 FND_LOG.STRING( FND_LOG.LEVEL_PROCEDURE,
6413 lc_mod_name||'begin',
6414 'Entering Private API create_wip_job');
6415 END IF;
6416
6417 -- Standard Start of API savepoint
6418 SAVEPOINT CREATE_WIP_JOB_PVT;
6419 -- Standard call to check for call compatibility.
6420 IF NOT FND_API.Compatible_API_Call
6421 (lc_api_version_number,
6422 p_api_version_number,
6423 lc_api_name,
6424 G_PKG_NAME)
6425 THEN
6426 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6427 END IF;
6428
6429 -- Initialize message list if p_init_msg_list is set to TRUE
6430 IF FND_API.to_boolean(p_init_msg_list) THEN
6431 FND_MSG_PUB.initialize;
6432 END IF;
6433
6434 -- Initialize API return status to success
6435 x_return_status:=FND_API.G_RET_STS_SUCCESS;
6436
6437
6438 l_job_header_rec.organization_id :=
6439 fnd_profile.value('CSD_DEF_REP_INV_ORG');
6440
6441 -- l_job_header_rec.organization_id := 207;
6442
6443 IF l_job_header_rec.organization_id is NULL THEN
6444
6445 FND_MESSAGE.SET_NAME('CSD','CSD_DEF_REP_INV_NULL');
6446 FND_MSG_PUB.ADD;
6447 RAISE FND_API.G_EXC_ERROR;
6448 end if;
6449
6450
6451 l_job_prefix := fnd_profile.value('CSD_DEFAULT_JOB_PREFIX');
6452
6453 -- If l_job_prefix is null, throw an error and return;
6454
6455 -- l_job_prefix := 'SR';
6456
6457 IF l_job_prefix is NULL THEN
6458
6459 FND_MESSAGE.SET_NAME('CSD','CSD_JOB_PREFIX_NULL');
6460 FND_MSG_PUB.ADD;
6461 RAISE FND_API.G_EXC_ERROR;
6462 end if;
6463
6464
6465 --bug#13472453
6466 OPEN c_repair_project_info(p_repair_line_id);
6467 FETCH c_repair_project_info into
6468 l_job_header_rec.project_id,
6469 l_job_header_rec.task_id,
6470 l_job_header_rec.end_item_unit_number;
6471 CLOSE c_repair_project_info;
6472 --bug#13472453
6473
6474 l_job_header_rec.class_code :=
6475 fnd_profile.value('CSD_DEF_WIP_ACCOUNTING_CLASS');
6476
6477 -- l_job_header_rec.class_code := 'Rework';
6478
6479 IF l_job_header_rec.class_code is NULL THEN
6480
6481 FND_MESSAGE.SET_NAME('CSD','CSD_CLASS_CODE_NULL');
6482 FND_MSG_PUB.ADD;
6483 RAISE FND_API.G_EXC_ERROR;
6484 end if;
6485
6486
6487
6488 -- Assign the WIP Job Status lookup codes corresponding to Released -- and Unreleased Job status,
6489 -- to be passed for WIP Interface Table
6490
6491
6492 if fnd_profile.value('CSD_DEFAULT_JOB_STATUS') = 'RELEASED' then
6493
6494
6495 l_job_header_rec.status_type := lc_released_status_code ;
6496
6497 elsif nvl( fnd_profile.value('CSD_DEFAULT_JOB_STATUS'), 'UNRELEASED' ) = 'UNRELEASED' then
6498
6499 l_job_header_rec.status_type := lc_unreleased_status_code;
6500 end if;
6501
6502
6503 l_job_header_rec.load_type := lc_non_standard_load_type;
6504
6505
6506
6507 l_job_header_rec.first_unit_start_date := sysdate;
6508 l_job_header_rec.last_unit_completion_date := sysdate;
6509
6510
6511 l_job_header_rec.start_quantity := p_repair_quantity;
6512
6513 -- If the profile CSD: Default WIP MRP Net Qty to Zero is set to
6514 -- null / 'N' then net_quantity = start_quantity else if the
6515 -- profile is set to 'Y' then net_quantity = 0
6516 IF ( nvl(fnd_profile.value('CSD_WIP_MRP_NET_QTY'),'N') = 'N' ) THEN
6517 l_job_header_rec.net_quantity := p_repair_quantity;
6518 ELSIF ( fnd_profile.value('CSD_WIP_MRP_NET_QTY') = 'Y' ) THEN
6519 l_job_header_rec.net_quantity := 0;
6520 END IF;
6521
6522
6523 l_job_header_rec.primary_item_id :=
6524 p_inventory_item_id ;
6525
6526
6527 -- Get the Group_id to be used for WIP Create Job,
6528
6529 SELECT wip_job_schedule_interface_s.NEXTVAL INTO l_job_header_rec.group_id FROM dual;
6530
6531 -- nnadig bug 9263438
6532 -- interface id should use sequence number from wip_interface_s
6533 -- wip_job_schedule_interface_s is for wjsi.group_id, and wip_interface_s is for wjsi.interface_id.
6534 SELECT wip_interface_s.NEXTVAL INTO l_job_header_rec.interface_id FROM dual;
6535 --l_job_header_rec.interface_id := l_job_header_rec.group_id;
6536
6537 generate_job_name ( p_job_prefix =>l_job_prefix,
6538 p_organization_id => l_job_header_rec.organization_id,
6539 x_job_name => l_job_header_rec.job_name );
6540
6541
6542 x_job_name := l_job_header_rec.job_name;
6543
6544
6545 IF ( FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
6546 FND_LOG.STRING( FND_LOG.LEVEL_EVENT,
6547 lc_mod_name||'beforecallinsert',
6548 'Just before calling insert_job_header');
6549 END IF;
6550
6551 -- Call procedure to insert job header and bills, routing
6552 -- information
6553 -- into wip_job_schedule_interface table
6554
6555
6556 insert_job_header( p_job_header_rec =>
6557 l_job_header_rec,
6558 x_return_status =>
6559 x_return_status );
6560
6561
6562 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
6563 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6564 END IF;
6565
6566
6567 -- CALL WIP API to process records in wip interface table,
6568 --If API fails, Raise error, rollback and return
6569
6570 -- Call WIP Mass Load API
6571
6572 IF ( FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
6573 FND_LOG.STRING( FND_LOG.LEVEL_EVENT,
6574 lc_mod_name||'beforecallcreateonejob',
6575 'Just before calling WIP_MASSLOAD_PUB.createOneJob');
6576 END IF;
6577 -- dbms_output.put_line('Before calling createonejob');
6578
6579 --bug#13472453
6580 -- Set the Policy context as required for MOAC Uptake, Bug#4421242
6581 fnd_profile.get('ORG_ID', l_org_id);
6582 mo_global.set_policy_context('S',l_org_id);
6583
6584 WIP_MASSLOAD_PUB.createOneJob( p_interfaceID => l_job_header_rec.interface_id, --bug 9263438
6585 p_validationLevel => p_validation_level,
6586 x_wipEntityID => l_wip_entity_id,
6587 x_returnStatus => x_return_status,
6588 x_errorMsg => x_msg_data );
6589
6590 -- Change the Policy context back to multiple
6591 mo_global.set_policy_context('M',null);
6592 --bug#13472453
6593
6594 -- dbms_output.put_line('After calling createonejob');
6595
6596 If ( ml_error_exists( l_job_header_rec.group_id ) or
6597 x_return_status <> FND_API.G_RET_STS_SUCCESS ) THEN
6598
6599 -- ROLLBACK to CREATE_WIP_JOB_PVT ;
6600
6601
6602 FND_MESSAGE.SET_NAME('CSD','CSD_JOB_CREAT_FAILURE');
6603 FND_MSG_PUB.ADD;
6604 RAISE FND_API.G_EXC_ERROR;
6605
6606 -- Need to rollback Raise exception -
6607 -- once commit is removed from above call
6608
6609 end if;
6610
6611
6612 --bug#12316893
6613 COMMIT;
6614 CSD_WIP_JOB_PVT.Delete_Completed_Wip_Records(l_job_header_rec.interface_id);
6615 --bug#12316893
6616
6617
6618 CSD_WARRANTY_CONTRACT_PVT.Default_Warranty_Contract(
6619 P_Api_Version_Number => 1.0,
6620 P_Init_Msg_List => FND_API.G_FALSE,
6621 p_commit => FND_API.G_TRUE,
6622 p_validation_level => fnd_api.g_valid_level_none,
6623 P_Repair_Line_Id => p_repair_line_id,
6624 P_Wip_Entity_Id => l_wip_entity_id,
6625 X_Return_Status => x_return_status,
6626 X_Msg_Count => x_msg_count,
6627 X_Msg_Data => x_msg_data
6628 );
6629 IF NOT (x_return_status = Fnd_Api.G_RET_STS_SUCCESS)
6630 THEN
6631 RAISE Fnd_Api.G_EXC_ERROR;
6632 END IF;
6633
6634
6635
6636 --*****Below are the code to Default Repair Item as Material on Job**********
6637
6638 l_default_ro_item := nvl(FND_PROFILE.VALUE('CSD_DEFAULT_RO_ITEM_AS_MATERIAL_ON_JOB'), 'N');
6639 --taklam
6640 if (l_default_ro_item = 'Y') then
6641 -- swai: bug 7477845/7483291
6642 -- check if there another job existing for this RO. If so, do not default
6643 -- the RO item as a material. Must compare we.wip_entity_id since
6644 -- crj.wip_entity_id may be null (until wip_update is done).
6645 select count(*)
6646 into l_num_other_jobs
6647 from csd_repair_job_xref crj,
6648 wip_entities we
6649 where crj.job_name = we.wip_entity_name
6650 and crj.organization_id = we.organization_id
6651 and crj.repair_line_id = p_repair_line_id
6652 and we.wip_entity_id <> l_wip_entity_id;
6653
6654 if (l_num_other_jobs = 0) then
6655 OPEN c_repair_line_info(p_repair_line_id);
6656 FETCH c_repair_line_info into
6657 l_inventory_item_id,
6658 l_unit_of_measure,
6659 l_quantity,
6660 l_serial_number;
6661 -- l_inventory_org_id; -- swai: bug 9954780
6662 CLOSE c_repair_line_info;
6663 l_inventory_org_id := fnd_profile.value('CSD_DEF_REP_INV_ORG'); -- swai: bug 9954780
6664 l_subinventory := fnd_profile.value('CSD_DEF_HV_SUBINV');
6665
6666 --Get serial number control code and lot control code
6667 OPEN cur_get_item_attribs (l_inventory_org_id,
6668 l_inventory_item_id);
6669
6670 FETCH cur_get_item_attribs
6671 INTO l_serial_control_code;
6672 CLOSE cur_get_item_attribs;
6673
6674
6675 IF l_serial_control_code IN (2, 5) then
6676 OPEN c_get_serial_info (l_inventory_item_id, l_serial_number, l_inventory_org_id);
6677 FETCH c_get_serial_info
6678 INTO l_current_status,l_current_subinventory_code;
6679 CLOSE c_get_serial_info;
6680 --current status = 3 is valid serial number
6681 if (l_current_status = 3) then
6682 l_subinventory := l_current_subinventory_code;
6683 else
6684 l_serial_number := null;
6685 end if;
6686 else
6687 --don't pass the serial number, it is not valid serial number
6688 l_serial_number := null;
6689 end if;
6690
6691
6692 l_dummy := null;
6693 OPEN c_count_material(l_wip_entity_id, l_inventory_item_id);
6694 FETCH c_count_material into l_dummy;
6695 CLOSE c_count_material;
6696
6697
6698 if (l_dummy is null) then
6699 --Default Repair Item as Material on Job
6700 l_mtl_txn_dtls_tbl.delete;
6701
6702 l_mtl_txn_dtls_tbl(0).INVENTORY_ITEM_ID :=l_inventory_item_id;
6703 l_mtl_txn_dtls_tbl(0).WIP_ENTITY_ID :=l_wip_entity_id;
6704 l_mtl_txn_dtls_tbl(0).ORGANIZATION_ID :=l_inventory_org_id;
6705 l_mtl_txn_dtls_tbl(0).OPERATION_SEQ_NUM :=1;
6706 l_mtl_txn_dtls_tbl(0).TRANSACTION_QUANTITY :=l_quantity; --repair order qty
6707 l_mtl_txn_dtls_tbl(0).TRANSACTION_UOM :=l_unit_of_measure; --Repair order UOM
6708 l_mtl_txn_dtls_tbl(0).SERIAL_NUMBER :=l_serial_number;
6709 l_mtl_txn_dtls_tbl(0).SUPPLY_SUBINVENTORY :=l_subinventory;
6710 l_mtl_txn_dtls_tbl(0).OBJECT_VERSION_NUMBER := 1;
6711 l_mtl_txn_dtls_tbl(0).NEW_ROW := 'Y';
6712
6713 -- default the reason id
6714 l_rule_input_rec.repair_line_id := p_repair_line_id;
6715 l_rule_input_rec.wip_entity_id := l_wip_entity_id;
6716 l_rule_input_rec.wip_mtl_txn_item_id := l_mtl_txn_dtls_tbl(0).INVENTORY_ITEM_ID;
6717
6718 CSD_RULES_ENGINE_PVT.GET_DEFAULT_VALUE_FROM_RULE(
6719 p_api_version_number => 1.0,
6720 p_init_msg_list => csd_process_util.g_false,
6721 p_commit => csd_process_util.g_false,
6722 p_validation_level => csd_process_util.g_valid_level_full,
6723 p_entity_attribute_type => 'CSD_DEF_ENTITY_ATTR_WIP',
6724 p_entity_attribute_code => 'MTL_TXN_REASON_CODE',
6725 p_rule_input_rec => l_rule_input_rec,
6726 x_default_value => l_default_reason_id,
6727 x_rule_id => l_default_rule_id,
6728 x_return_status => l_return_status,
6729 x_msg_count => l_msg_count,
6730 x_msg_data => l_msg_data
6731 );
6732 IF (x_return_status <> FND_API.G_RET_STS_SUCCESS ) THEN
6733 FND_MESSAGE.SET_NAME('CSD','CSD_DEF_REASON_CODE_FAILURE');
6734 FND_MSG_PUB.ADD;
6735 RAISE FND_API.G_EXC_ERROR;
6736 END IF;
6737 if (l_default_rule_id is not null) then
6738 l_mtl_txn_dtls_tbl(0).REASON_ID := l_default_reason_id;
6739 l_rule_input_rec.WIP_MTL_DISP_CODE_ID := l_default_reason_id; -- bug#14155233 default service warranty
6740 end if;
6741
6742
6743 -- bug#13868879 default create ro flag
6744 CSD_RULES_ENGINE_PVT.GET_DEFAULT_VALUE_FROM_RULE(
6745 p_api_version_number => 1.0,
6746 p_init_msg_list => csd_process_util.g_false,
6747 p_commit => csd_process_util.g_false,
6748 p_validation_level => csd_process_util.g_valid_level_full,
6749 p_entity_attribute_type => 'CSD_DEF_ENTITY_ATTR_WIP',
6750 p_entity_attribute_code => 'CREATE_RO_FLAG',
6751 p_rule_input_rec => l_rule_input_rec,
6752 x_default_value => l_default_create_ro_flag,
6753 x_rule_id => l_default_rule_id,
6754 x_return_status => l_return_status,
6755 x_msg_count => l_msg_count,
6756 x_msg_data => l_msg_data
6757 );
6758 IF (x_return_status <> FND_API.G_RET_STS_SUCCESS ) THEN
6759 FND_MESSAGE.SET_NAME('CSD','CSD_DEF_CREATE_RO_FLAG_FAILURE');
6760 FND_MSG_PUB.ADD;
6761 RAISE FND_API.G_EXC_ERROR;
6762 END IF;
6763 if (l_default_rule_id is not null) then
6764 if l_default_create_ro_flag = 'Y' then
6765 l_mtl_txn_dtls_tbl(0).CREATE_RO_FLAG := fnd_api.g_true;
6766 else
6767 l_mtl_txn_dtls_tbl(0).CREATE_RO_FLAG := fnd_api.g_false;
6768 end if;
6769 end if;
6770
6771 end if;
6772 end if; -- swai: bug 7477845/7483291 num other jobs = 0
6773 end if;
6774 --*****End of the code to Default Repair Item as Material on Job**********
6775
6776 -- call API to create Repair Actuals header
6777 CSD_HV_WIP_JOB_PVT.PROCESS_SAVE_MTL_TXN_DTLS
6778 ( p_api_version_number => 1.0,
6779 p_init_msg_list => 'T',
6780 p_commit => 'F',
6781 p_validation_level => 1,
6782 p_mtl_txn_dtls_tbl => l_mtl_txn_dtls_tbl,
6783 x_op_created => l_op_created,
6784 x_return_status => x_return_status,
6785 x_msg_count => x_msg_count,
6786 x_msg_data => x_msg_data);
6787 IF NOT(x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
6788 FND_MESSAGE.SET_NAME('CSD','CSD_JOB_GEN_FAILURE');
6789 FND_MSG_PUB.ADD;
6790 RAISE FND_API.G_EXC_ERROR;
6791 END IF;
6792
6793
6794 /* IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
6795 ROLLBACK to CREATE_WIP_JOB_PVT ;
6796
6797
6798 FND_MESSAGE.SET_NAME('CSD','CSD_JOB_CREAT_FAILURE');
6799 FND_MSG_PUB.ADD;
6800 RAISE FND_API.G_EXC_UNEXPECTED_ERROR; */
6801
6802
6803 -- dbms_output.put_line('In Error');
6804
6805 /* IF ( FND_LOG.LEVEL_ERROR >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
6806 FND_LOG.STRING( FND_LOG.LEVEL_ERROR,
6807 lc_mod_name||'exc_exception',
6808 'G_EXC_ERROR Exception');
6809 END IF;
6810
6811 RETURN; */
6812
6813 -- END IF;
6814
6815
6816 -- call procedures to insert a row in csd_repair_job_xref
6817 -- and csd_repair_history tables for the job created.
6818
6819 L_user_id := fnd_global.user_id;
6820
6821 IF ( FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
6822 FND_LOG.STRING( FND_LOG.LEVEL_EVENT,
6823 lc_mod_name||'beforecallxrefwrite',
6824 'Just before calling csd_to_form_repair_job_xref.validate_and_write');
6825 END IF;
6826
6827
6828
6829 csd_to_form_repair_job_xref.validate_and_write(
6830 p_api_version_number => lc_api_version_number,
6831 p_init_msg_list => FND_API.G_FALSE,
6832 p_commit => FND_API.G_FALSE,
6833 p_validation_level => NULL,
6834 p_action_code => 0,
6835 px_repair_job_xref_id => l_repair_xref_id,
6836 p_created_by => l_user_id,
6837 p_creation_date => SYSDATE,
6838 p_last_updated_by => l_user_id,
6839 p_last_update_date => SYSDATE,
6840 p_last_update_login => l_user_id,
6841 p_repair_line_id => p_repair_line_id,
6842 p_wip_entity_id => l_wip_entity_id,
6843 p_group_id => l_job_header_rec.group_id,
6844 p_organization_id => l_job_header_rec.organization_id,
6845 p_quantity => p_repair_quantity,
6846 p_INVENTORY_ITEM_ID => l_job_header_rec.primary_item_id,
6847 p_ITEM_REVISION => null,
6848 p_OBJECT_VERSION_NUMBER => NULL,
6849 p_attribute_category => NULL,
6850 p_attribute1 => NULL,
6851 p_attribute2 => NULL,
6852 p_attribute3 => NULL,
6853 p_attribute4 => NULL,
6854 p_attribute5 => NULL,
6855 p_attribute6 => NULL,
6856 p_attribute7 => NULL,
6857 p_attribute8 => NULL,
6858 p_attribute9 => NULL,
6859 p_attribute10 => NULL,
6860 p_attribute11 => NULL,
6861 p_attribute12 => NULL,
6862 p_attribute13 => NULL,
6863 p_attribute14 => NULL,
6864 p_attribute15 => NULL,
6865 p_quantity_completed => NULL,
6866 p_job_name => l_job_header_rec.job_name,
6867 p_source_type_code => 'MANUAL', -- bug fix 5763350
6868 p_source_id1 => NULL,
6869 p_ro_service_code_id => NULL,
6870 x_return_status => x_return_status,
6871 x_msg_count => x_msg_count,
6872 x_msg_data => x_msg_data);
6873
6874
6875 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
6876 ROLLBACK to CREATE_WIP_JOB_PVT ;
6877
6878 IF ( FND_LOG.LEVEL_ERROR >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
6879 FND_LOG.STRING( FND_LOG.LEVEL_ERROR,
6880 lc_mod_name||'exc_exception',
6881 'G_EXC_ERROR Exception');
6882 END IF;
6883
6884 RETURN;
6885
6886 END IF;
6887
6888
6889 IF ( FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
6890 FND_LOG.STRING( FND_LOG.LEVEL_EVENT,
6891 lc_mod_name||'beforecallhistwrite',
6892 'Just before calling csd_to_form_repair_history.validate_and_write');
6893 END IF;
6894
6895
6896
6897 csd_to_form_repair_history.validate_and_write(
6898 p_api_version_number => lc_api_version_number,
6899 p_init_msg_list => FND_API.G_FALSE,
6900 p_commit => FND_API.G_FALSE,
6901 p_validation_level => NULL,
6902 p_action_code => 0,
6903 px_repair_history_id => l_rep_hist_id,
6904 p_OBJECT_VERSION_NUMBER => NULL,
6905 p_request_id => NULL,
6906 p_program_id => NULL,
6907 p_program_application_id => NULL,
6908 p_program_update_date => NULL,
6909 p_created_by => l_user_id,
6910 p_creation_date => SYSDATE,
6911 p_last_updated_by => l_user_id,
6912 p_last_update_date => SYSDATE,
6913 p_repair_line_id => p_repair_line_id,
6914 p_event_code => 'JS',
6915 p_event_date => SYSDATE,
6916 p_quantity => p_repair_quantity,
6917 p_paramn1 => l_wip_entity_id,
6918 p_paramn2 => l_job_header_rec.organization_id,
6919 p_paramn3 => NULL,
6920 p_paramn4 => NULL,
6921 p_paramn5 => p_repair_quantity,
6922 p_paramn6 => NULL,
6923 p_paramn8 => NULL,
6924 p_paramn9 => NULL,
6925 p_paramn10 => NULL,
6926 p_paramc1 => l_job_header_rec.job_name,
6927 p_paramc2 => NULL,
6928 p_paramc3 => NULL,
6929 p_paramc4 => NULL,
6930 p_paramc5 => NULL,
6931 p_paramc6 => NULL,
6932 p_paramc7 => NULL,
6933 p_paramc8 => NULL,
6934 p_paramc9 => NULL,
6935 p_paramc10 => NULL,
6936 p_paramd1 => NULL ,
6937 p_paramd2 => NULL ,
6938 p_paramd3 => NULL ,
6939 p_paramd4 => NULL ,
6940 p_paramd5 => SYSDATE,
6941 p_paramd6 => NULL ,
6942 p_paramd7 => NULL ,
6943 p_paramd8 => NULL ,
6944 p_paramd9 => NULL ,
6945 p_paramd10 => NULL ,
6946 p_attribute_category => NULL ,
6947 p_attribute1 => NULL ,
6948 p_attribute2 => NULL ,
6949 p_attribute3 => NULL ,
6950 p_attribute4 => NULL ,
6951 p_attribute5 => NULL ,
6952 p_attribute6 => NULL ,
6953 p_attribute7 => NULL ,
6954 p_attribute8 => NULL ,
6955 p_attribute9 => NULL ,
6956 p_attribute10 => NULL ,
6957 p_attribute11 => NULL ,
6958 p_attribute12 => NULL ,
6959 p_attribute13 => NULL ,
6960 p_attribute14 => NULL ,
6961 p_attribute15 => NULL ,
6962 p_last_update_login => l_user_id,
6963 x_return_status => x_return_status,
6964 x_msg_count => x_msg_count,
6965 x_msg_data => x_msg_data);
6966
6967 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
6968 ROLLBACK to CREATE_WIP_JOB_PVT ;
6969
6970 IF ( FND_LOG.LEVEL_ERROR >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
6971 FND_LOG.STRING( FND_LOG.LEVEL_ERROR,
6972 lc_mod_name||'exc_exception',
6973 'G_EXC_ERROR Exception');
6974 END IF;
6975
6976 RETURN;
6977
6978 END IF;
6979
6980 -- Standard check for p_commit
6981 IF FND_API.to_Boolean( p_commit )
6982 THEN
6983 COMMIT WORK;
6984 END IF;
6985
6986
6987 EXCEPTION
6988 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
6989 ROLLBACK to CREATE_WIP_JOB_PVT ;
6990 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6991
6992 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
6993 p_count => x_msg_count,
6994 p_data => x_msg_data);
6995
6996 IF ( FND_LOG.LEVEL_EXCEPTION >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
6997 FND_LOG.STRING( FND_LOG.LEVEL_EXCEPTION,
6998 lc_mod_name||'unx_exception',
6999 'G_EXC_UNEXPECTED_ERROR Exception');
7000 END IF;
7001
7002
7003 WHEN FND_API.G_EXC_ERROR THEN
7004 ROLLBACK to CREATE_WIP_JOB_PVT ;
7005 x_return_status := FND_API.G_RET_STS_ERROR;
7006
7007
7008 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
7009 p_count => x_msg_count,
7010 p_data => x_msg_data);
7011
7012 IF ( FND_LOG.LEVEL_ERROR >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
7013 FND_LOG.STRING( FND_LOG.LEVEL_ERROR,
7014 lc_mod_name||'exc_exception',
7015 'G_EXC_ERROR Exception');
7016 END IF;
7017
7018 WHEN OTHERS THEN
7019 ROLLBACK to CREATE_WIP_JOB_PVT ;
7020 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
7021
7022 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
7023
7024 -- Add Unexpected Error to Message List, here SQLERRM is used for
7025 -- getting the error
7026
7027 FND_MSG_PUB.add_exc_msg(p_pkg_name => G_PKG_NAME,
7028 p_procedure_name => lc_api_name );
7029 END IF;
7030
7031 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
7032 p_count => x_msg_count,
7033 p_data => x_msg_data);
7034
7035 IF ( FND_LOG.LEVEL_EXCEPTION >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
7036 FND_LOG.STRING( FND_LOG.LEVEL_EXCEPTION,
7037 lc_mod_name||'others_exception',
7038 'OTHERS Exception');
7039 END IF;
7040
7041
7042 END create_wip_job;
7043
7044
7045 PROCEDURE generate_wip_jobs_from_scs
7046 (
7047 p_api_version_number IN NUMBER,
7048 p_init_msg_list IN VARCHAR2 ,
7049 p_commit IN VARCHAR2 ,
7050 p_validation_level IN NUMBER,
7051 x_return_status OUT NOCOPY VARCHAR2,
7052 x_msg_count OUT NOCOPY NUMBER,
7053 x_msg_data OUT NOCOPY VARCHAR2,
7054 p_repair_line_id IN NUMBER,
7055 p_repair_quantity IN NUMBER,
7056 p_service_code_tbl IN service_code_tbl_type
7057 )
7058 IS
7059 -- Job Record to hold the Job header, bills and routing information being inserted
7060 -- into wip_job_schedule_interface
7061 l_job_header_rec wip_job_schedule_interface%ROWTYPE;
7062
7063 lc_api_name CONSTANT VARCHAR2(30) := 'GENERATE_WIP_JOBS_FROM_SCS';
7064 lc_api_version_number CONSTANT NUMBER := 1.0;
7065
7066 -- WIP Job Status Lookup Codes for Released and Unreleased status,
7067 -- The Lookup Type is WIP_JOB_STATUS
7068 lc_released_status_code CONSTANT NUMBER := 3;
7069 lc_unreleased_status_code CONSTANT NUMBER := 1;
7070
7071 -- Non Standard Discrete Job Load Type
7072 lc_non_standard_load_type CONSTANT NUMBER := 4;
7073
7074 lc_service_code CONSTANT VARCHAR2(30) := 'SERVICE_CODE';
7075
7076
7077 -- Constants used for FND_LOG debug messages
7078 lc_mod_name CONSTANT VARCHAR2(2000) := 'csd.plsql.csd_hv_wip_job_pvt.generate_wip_jobs_from_scs';
7079
7080 l_object_version_number NUMBER;
7081 l_user_id NUMBER;
7082 l_repair_xref_id NUMBER;
7083 l_rep_hist_id NUMBER;
7084 l_error_msg VARCHAR2(2000);
7085
7086 l_job_prefix VARCHAR2(80);
7087 l_wip_entity_id NUMBER;
7088
7089 -- swai: bug 5239301
7090 l_bills_routes_count NUMBER := 0;
7091 l_show_messages_flag VARCHAR2(1) := 'F';
7092 l_service_code VARCHAR2(30);
7093 -- end swai: bug 5239301
7094
7095 l_ro_service_code_rec CSD_RO_SERVICE_CODES_PVT.RO_SERVICE_CODE_REC_TYPE;
7096
7097 i NUMBER; -- counter for l_mtl_txn_dtls_tbl
7098 l_rule_input_rec CSD_RULES_ENGINE_PVT.CSD_RULE_INPUT_REC_TYPE;
7099 l_default_reason_id NUMBER;
7100 l_default_create_ro_flag VARCHAR2(1); -- bug#13868879 default create ro flag
7101 l_default_rule_id NUMBER;
7102 l_return_status VARCHAR2(1);
7103 l_msg_count NUMBER;
7104 l_msg_data VARCHAR2(2000);
7105
7106 CURSOR c_wip_mtl_requirements(p_wip_entity_id NUMBER) IS
7107 select inventory_item_id,
7108 organization_id,
7109 operation_seq_num,
7110 required_quantity,
7111 item_primary_uom_code,
7112 supply_subinventory
7113 from wip_requirement_operations_v
7114 where wip_entity_id = p_wip_entity_id;
7115
7116
7117 -- Counter used for populating l_x_job_bill_routing_tbl table with
7118 -- Bills and Routing information
7119 -- Also tracks the number of jobs being submitted
7120
7121 CURSOR c_get_bills_routes(c_p_service_code_id number, c_p_organization_id number )
7122 IS
7123 SELECT bom.assembly_item_id bom_reference_id,
7124 bom.alternate_bom_designator,
7125 bor.assembly_item_id routing_reference_id,
7126 bor.alternate_routing_designator,
7127 bor.completion_subinventory,
7128 bor. completion_locator_id
7129 FROM csd_sc_work_entities cscwe,
7130 bom_bill_of_materials bom , bom_operational_routings bor
7131 WHERE cscwe.service_code_id = c_p_service_code_id
7132 And cscwe.work_entity_type_code = 'BOM'
7133 and cscwe.work_entity_id3 = c_p_organization_id
7134 and cscwe.work_entity_id1 = bom.bill_sequence_id (+)
7135 and cscwe.work_entity_id2 = bor.routing_sequence_id (+);
7136
7137 -- swai: bug 5239301
7138 -- Cursor to get the service code details
7139 CURSOR c_get_service_code_details (c_p_service_code_id number)
7140 IS
7141 SELECT service_code
7142 FROM csd_service_codes_b
7143 WHERE service_code_id = c_p_service_code_id;
7144 -- end swai: bug 5239301
7145
7146
7147
7148 --*****Below are the code to Default Repair Item as Material on Job**********
7149 l_default_ro_item VARCHAR2(1);
7150 -- l_wip_entity_id NUMBER;
7151 l_mtl_txn_dtls_tbl CSD_HV_WIP_JOB_PVT.MTL_TXN_DTLS_TBL_TYPE;
7152 l_op_created VARCHAR2(10);
7153 l_num_other_jobs NUMBER :=0; -- swai: bug 7477845/7483291
7154
7155
7156 CURSOR c_repair_line_info(p_repair_line_id IN NUMBER) IS
7157 select inventory_item_id, unit_of_measure, quantity, serial_number
7158 --, inventory_org_id -- swai: bug 10137471
7159 from csd_repairs
7160 where repair_line_id = p_repair_line_id;
7161
7162 --bug#13472453
7163 CURSOR c_repair_project_info(p_repair_line_id IN NUMBER) IS
7164 select project_id, task_id, unit_number
7165 from csd_repairs
7166 where repair_line_id = p_repair_line_id;
7167
7168 l_org_id NUMBER;
7169 --bug#13472453
7170
7171 CURSOR c_count_material(p_wip_entity_id NUMBER, l_inventory_item_id NUMBER) IS
7172 select 'X'
7173 from wip_requirement_operations_v
7174 where wip_entity_id = p_wip_entity_id
7175 and inventory_item_id = l_inventory_item_id
7176 and rownum = 1;
7177
7178
7179 -- Cursor to select the item attributes serial control code and
7180 -- lot control code.
7181 CURSOR cur_get_item_attribs (
7182 p_org_id NUMBER,
7183 p_item_id NUMBER
7184 )
7185 IS
7186 SELECT serial_number_control_code
7187 FROM mtl_system_items
7188 WHERE organization_id = p_org_id AND inventory_item_id = p_item_id;
7189
7190
7191 Cursor c_get_serial_info(p_item_id number, p_serial_number varchar2, p_org_id number) is
7192 select current_status, current_subinventory_code from mtl_serial_numbers
7193 where inventory_item_id = p_item_id and serial_number = p_serial_number and current_organization_id = p_org_id;
7194
7195
7196 Cursor c_get_min_operation_seq(p_wip_entity_id number) is
7197 select min(operation_seq_num) from wip_operations_v where wip_entity_id = p_wip_entity_id;
7198
7199 l_inventory_item_id NUMBER;
7200 l_unit_of_measure VARCHAR2(3);
7201 l_quantity NUMBER;
7202 l_serial_number VARCHAR2(30);
7203 l_inventory_org_id NUMBER;
7204 l_subinventory VARCHAR2(30);
7205 l_dummy VARCHAR2(1) := null;
7206 l_serial_control_code NUMBER;
7207 l_current_status NUMBER;
7208 l_current_subinventory_code VARCHAR2(10);
7209 l_operation_seq_num NUMBER;
7210
7211
7212 BEGIN
7213
7214 IF ( FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
7215 FND_LOG.STRING( FND_LOG.LEVEL_PROCEDURE,
7216 lc_mod_name||'begin',
7217 'Entering Private API generate_wip_jobs_from_scs');
7218 END IF;
7219
7220 -- Standard Start of API savepoint
7221 SAVEPOINT GENERATE_WIP_JOBS_FROM_SCS_PVT;
7222 -- Standard call to check for call compatibility.
7223 IF NOT FND_API.Compatible_API_Call
7224 (lc_api_version_number,
7225 p_api_version_number,
7226 lc_api_name,
7227 G_PKG_NAME)
7228 THEN
7229 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
7230 END IF;
7231
7232 -- Initialize message list if p_init_msg_list is set to TRUE
7233 IF FND_API.to_boolean(p_init_msg_list) THEN
7234 FND_MSG_PUB.initialize;
7235 END IF;
7236
7237 -- Initialize API return status to success
7238 x_return_status:=FND_API.G_RET_STS_SUCCESS;
7239
7240 l_job_header_rec.organization_id :=
7241 fnd_profile.value('CSD_DEF_REP_INV_ORG');
7242
7243
7244 IF l_job_header_rec.organization_id is NULL THEN
7245
7246 FND_MESSAGE.SET_NAME('CSD','CSD_DEF_REP_INV_NULL');
7247 FND_MSG_PUB.ADD;
7248 RAISE FND_API.G_EXC_ERROR;
7249 END IF;
7250
7251 l_job_prefix := fnd_profile.value('CSD_DEFAULT_JOB_PREFIX');
7252
7253 -- If l_job_prefix is null, throw an error and return;
7254 IF l_job_prefix is NULL THEN
7255 FND_MESSAGE.SET_NAME('CSD','CSD_JOB_PREFIX_NULL');
7256 FND_MSG_PUB.ADD;
7257 RAISE FND_API.G_EXC_ERROR;
7258 END IF;
7259
7260 l_job_header_rec.class_code :=
7261 fnd_profile.value('CSD_DEF_WIP_ACCOUNTING_CLASS');
7262
7263 IF l_job_header_rec.class_code is NULL THEN
7264 FND_MESSAGE.SET_NAME('CSD','CSD_CLASS_CODE_NULL');
7265 FND_MSG_PUB.ADD;
7266 RAISE FND_API.G_EXC_ERROR;
7267 END IF;
7268
7269 -- Populate the Job Header Record
7270
7271 -- Assign the WIP Job Status lookup codes corresponding to Released
7272 -- and Unreleased Job status,
7273 -- to be passed for WIP Interface Table
7274
7275
7276 if fnd_profile.value('CSD_DEFAULT_JOB_STATUS') = 'RELEASED' then
7277 l_job_header_rec.status_type := lc_released_status_code ;
7278
7279 elsif nvl( fnd_profile.value('CSD_DEFAULT_JOB_STATUS'), 'UNRELEASED' ) = 'UNRELEASED' then
7280 l_job_header_rec.status_type := lc_unreleased_status_code;
7281 end if;
7282
7283
7284 l_job_header_rec.load_type := lc_non_standard_load_type;
7285 l_job_header_rec.first_unit_start_date := sysdate;
7286 l_job_header_rec.last_unit_completion_date := sysdate;
7287 l_job_header_rec.start_quantity := p_repair_quantity;
7288
7289
7290 --bug#13472453
7291 OPEN c_repair_project_info(p_repair_line_id);
7292 FETCH c_repair_project_info into
7293 l_job_header_rec.project_id,
7294 l_job_header_rec.task_id,
7295 l_job_header_rec.end_item_unit_number;
7296 CLOSE c_repair_project_info;
7297 --bug#13472453
7298
7299
7300 -- Fix for bug# 3109417
7301 -- If the profile CSD: Default WIP MRP Net Qty to Zero is set to
7302 -- null / 'N' then net_quantity = start_quantity else if the
7303 -- profile is set to 'Y' then net_quantity = 0
7304 IF ( nvl(fnd_profile.value('CSD_WIP_MRP_NET_QTY'),'N') = 'N' ) THEN
7305 l_job_header_rec.net_quantity := p_repair_quantity;
7306 ELSIF ( fnd_profile.value('CSD_WIP_MRP_NET_QTY') = 'Y' ) THEN
7307 l_job_header_rec.net_quantity := 0;
7308 END IF;
7309
7310 -- dbms_output.put_line('Before Loop');
7311 FOR sc_ctr in p_service_code_tbl.FIRST..
7312 p_service_code_tbl.LAST
7313
7314 LOOP
7315
7316 -- dbms_output.put_line('Inside Loop');
7317 l_job_header_rec.primary_item_id :=
7318 p_service_code_tbl(sc_ctr).inventory_item_id ;
7319
7320 l_bills_routes_count := 0; -- swai: bug 5239301
7321 FOR bills_routes_rec in c_get_bills_routes(
7322 p_service_code_tbl(sc_ctr).service_code_id, l_job_header_rec.organization_id )
7323 LOOP
7324 -- dbms_output.put_line('Inside 2nd loop');
7325
7326 l_bills_routes_count := l_bills_routes_count + 1; -- swai: bug 5239301
7327
7328 -- Populate the Bill and Routing information
7329 -- table. This is passed to the insert_job_header
7330 -- procedure
7331
7332 -- Get the Group_id to be used for WIP Create Job,
7333 SELECT wip_job_schedule_interface_s.NEXTVAL INTO l_job_header_rec.group_id FROM dual;
7334
7335 -- nnadig: bug 9263438
7336 -- interface id should use sequence number from wip_interface_s
7337 -- wip_job_schedule_interface_s is for wjsi.group_id, wip_interface_s is for wjsi.interface_id.
7338 SELECT wip_interface_s.NEXTVAL INTO l_job_header_rec.interface_id FROM dual;
7339
7340
7341 --l_job_header_rec.interface_id := l_job_header_rec.group_id;
7342
7343 l_job_header_rec.bom_reference_id := bills_routes_rec.bom_reference_id ;
7344 l_job_header_rec.routing_reference_id := bills_routes_rec.routing_reference_id ;
7345 l_job_header_rec. alternate_bom_designator:= bills_routes_rec. alternate_bom_designator;
7346 l_job_header_rec. alternate_routing_designator:= bills_routes_rec. alternate_routing_designator;
7347 l_job_header_rec.completion_subinventory := bills_routes_rec.completion_subinventory;
7348 l_job_header_rec.completion_locator_id := bills_routes_rec. completion_locator_id;
7349 generate_job_name ( p_job_prefix =>l_job_prefix,
7350 p_organization_id => l_job_header_rec.organization_id,
7351 x_job_name => l_job_header_rec.job_name );
7352 -- dbms_output.put_line('After generate job name');
7353
7354
7355 IF ( FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
7356 FND_LOG.STRING( FND_LOG.LEVEL_EVENT,
7357 lc_mod_name||'beforecallinsert',
7358 'Just before calling insert_job_header');
7359 END IF;
7360
7361 -- Call procedure to insert job header and bills, routing
7362 -- information into wip_job_schedule_interface table
7363
7364 insert_job_header( p_job_header_rec => l_job_header_rec,
7365 x_return_status => x_return_status );
7366
7367
7368 -- dbms_output.put_line('After insert_job_header');
7369
7370
7371 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
7372 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
7373 END IF;
7374
7375 -- CALL WIP API to process records in wip interface table,
7376 -- If API fails, Raise error, rollback and return
7377
7378 -- Call WIP Mass Load API
7379
7380 IF ( FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
7381 FND_LOG.STRING( FND_LOG.LEVEL_EVENT,
7382 lc_mod_name||'beforecallcreateonejob',
7383 'Just before calling WIP_MASSLOAD_PUB.createOneJob');
7384 END IF;
7385
7386 --bug#13472453
7387 -- Set the Policy context as required for MOAC Uptake, Bug#4421242
7388 fnd_profile.get('ORG_ID', l_org_id);
7389 mo_global.set_policy_context('S',l_org_id);
7390
7391 WIP_MASSLOAD_PUB.createOneJob( p_interfaceID => l_job_header_rec.interface_id, --bug 9263438
7392 p_validationLevel => p_validation_level,
7393 x_wipEntityID => l_wip_entity_id,
7394 x_returnStatus => x_return_status,
7395 x_errorMsg => x_msg_data );
7396
7397 -- Change the Policy context back to multiple
7398 mo_global.set_policy_context('M',null);
7399 --bug#13472453
7400
7401
7402 If ( ml_error_exists( l_job_header_rec.group_id ) or
7403 x_return_status <> FND_API.G_RET_STS_SUCCESS ) THEN
7404
7405 -- ROLLBACK to GENERATE_WIP_JOBS_FROM_SCS_PVT ;
7406
7407
7408 FND_MESSAGE.SET_NAME('CSD','CSD_JOB_GEN_FAILURE');
7409 FND_MSG_PUB.ADD;
7410 RAISE FND_API.G_EXC_ERROR;
7411
7412 -- Need to rollback Raise exception -
7413 -- once commit is removed from above call
7414
7415 end if;
7416
7417 --bug#12316893
7418 COMMIT;
7419 CSD_WIP_JOB_PVT.Delete_Completed_Wip_Records(l_job_header_rec.interface_id);
7420 --bug#12316893
7421
7422
7423 CSD_WARRANTY_CONTRACT_PVT.Default_Warranty_Contract(
7424 P_Api_Version_Number => 1.0,
7425 P_Init_Msg_List => FND_API.G_FALSE,
7426 p_commit => FND_API.G_TRUE,
7427 p_validation_level => fnd_api.g_valid_level_none,
7428 P_Repair_Line_Id => p_repair_line_id,
7429 P_Wip_Entity_Id => l_wip_entity_id,
7430 X_Return_Status => x_return_status,
7431 X_Msg_Count => x_msg_count,
7432 X_Msg_Data => x_msg_data
7433 );
7434 IF NOT (x_return_status = Fnd_Api.G_RET_STS_SUCCESS)
7435 THEN
7436 RAISE Fnd_Api.G_EXC_ERROR;
7437 END IF;
7438
7439
7440 /***************************************************************************
7441 12.2 Dev
7442 After job creation, query all the material requirements in order to
7443 default the material transaction reason code
7444 ***************************************************************************/
7445 l_mtl_txn_dtls_tbl.delete; --clear the table first
7446 i := 0; --initialize the index
7447 -- for each material requirement, update it
7448 FOR mtl_req in c_wip_mtl_requirements(l_wip_entity_id)
7449 LOOP
7450 l_mtl_txn_dtls_tbl(i).INVENTORY_ITEM_ID := mtl_req.inventory_item_id;
7451 l_mtl_txn_dtls_tbl(i).WIP_ENTITY_ID := l_wip_entity_id;
7452 l_mtl_txn_dtls_tbl(i).OBJECT_VERSION_NUMBER := 1;
7453 l_mtl_txn_dtls_tbl(i).NEW_ROW := 'N';
7454 l_mtl_txn_dtls_tbl(i).OPERATION_SEQ_NUM := mtl_req.operation_seq_num;
7455
7456 -- default the reason id
7457 l_rule_input_rec.repair_line_id := p_repair_line_id;
7458 l_rule_input_rec.wip_entity_id := l_wip_entity_id;
7459 l_rule_input_rec.wip_mtl_txn_item_id := l_mtl_txn_dtls_tbl(i).INVENTORY_ITEM_ID;
7460
7461 CSD_RULES_ENGINE_PVT.GET_DEFAULT_VALUE_FROM_RULE(
7462 p_api_version_number => 1.0,
7463 p_init_msg_list => csd_process_util.g_false,
7464 p_commit => csd_process_util.g_false,
7465 p_validation_level => csd_process_util.g_valid_level_full,
7466 p_entity_attribute_type => 'CSD_DEF_ENTITY_ATTR_WIP',
7467 p_entity_attribute_code => 'MTL_TXN_REASON_CODE',
7468 p_rule_input_rec => l_rule_input_rec,
7469 x_default_value => l_default_reason_id,
7470 x_rule_id => l_default_rule_id,
7471 x_return_status => l_return_status,
7472 x_msg_count => l_msg_count,
7473 x_msg_data => l_msg_data
7474 );
7475 IF (x_return_status <> FND_API.G_RET_STS_SUCCESS ) THEN
7476 FND_MESSAGE.SET_NAME('CSD','CSD_DEF_REASON_CODE_FAILURE');
7477 FND_MSG_PUB.ADD;
7478 RAISE FND_API.G_EXC_ERROR;
7479 END IF;
7480
7481 if (l_default_rule_id is not null) then
7482 l_mtl_txn_dtls_tbl(i).REASON_ID := l_default_reason_id;
7483 l_rule_input_rec.WIP_MTL_DISP_CODE_ID := l_default_reason_id; -- bug#14155233 default service warranty
7484 end if;
7485
7486 -- bug#13868879 default create ro flag
7487 CSD_RULES_ENGINE_PVT.GET_DEFAULT_VALUE_FROM_RULE(
7488 p_api_version_number => 1.0,
7489 p_init_msg_list => csd_process_util.g_false,
7490 p_commit => csd_process_util.g_false,
7491 p_validation_level => csd_process_util.g_valid_level_full,
7492 p_entity_attribute_type => 'CSD_DEF_ENTITY_ATTR_WIP',
7493 p_entity_attribute_code => 'CREATE_RO_FLAG',
7494 p_rule_input_rec => l_rule_input_rec,
7495 x_default_value => l_default_create_ro_flag,
7496 x_rule_id => l_default_rule_id,
7497 x_return_status => l_return_status,
7498 x_msg_count => l_msg_count,
7499 x_msg_data => l_msg_data
7500 );
7501 IF (x_return_status <> FND_API.G_RET_STS_SUCCESS ) THEN
7502 FND_MESSAGE.SET_NAME('CSD','CSD_DEF_CREATE_RO_FLAG_FAILURE');
7503 FND_MSG_PUB.ADD;
7504 RAISE FND_API.G_EXC_ERROR;
7505 END IF;
7506 if (l_default_rule_id is not null) then
7507 if l_default_create_ro_flag = 'Y' then
7508 l_mtl_txn_dtls_tbl(i).CREATE_RO_FLAG := fnd_api.g_true;
7509 else
7510 l_mtl_txn_dtls_tbl(i).CREATE_RO_FLAG := fnd_api.g_false;
7511 end if;
7512 end if;
7513
7514 -- increment the counter
7515 i := i+1;
7516 END LOOP;
7517
7518 --*****Below are the code to Default Repair Item as Material on Job**********
7519
7520 l_default_ro_item := nvl(FND_PROFILE.VALUE('CSD_DEFAULT_RO_ITEM_AS_MATERIAL_ON_JOB'), 'N');
7521 --taklam
7522 if (l_default_ro_item = 'Y') then
7523
7524 -- swai: bug 7477845/7483291
7525 -- check if there another job existing for this RO. If so, do not default
7526 -- the RO item as a material. Must compare we.wip_entity_id since
7527 -- crj.wip_entity_id may be null (until wip_update is done).
7528 select count(*)
7529 into l_num_other_jobs
7530 from csd_repair_job_xref crj,
7531 wip_entities we
7532 where crj.job_name = we.wip_entity_name
7533 and crj.organization_id = we.organization_id
7534 and crj.repair_line_id = p_repair_line_id
7535 and we.wip_entity_id <> l_wip_entity_id;
7536
7537 if (l_num_other_jobs = 0) then
7538 OPEN c_repair_line_info(p_repair_line_id);
7539 FETCH c_repair_line_info into
7540 l_inventory_item_id,
7541 l_unit_of_measure,
7542 l_quantity,
7543 l_serial_number;
7544 -- l_inventory_org_id; -- swai: bug 10137471
7545 CLOSE c_repair_line_info;
7546 l_inventory_org_id := fnd_profile.value('CSD_DEF_REP_INV_ORG'); -- swai: bug 10137471
7547 l_subinventory := fnd_profile.value('CSD_DEF_HV_SUBINV');
7548
7549 --Get serial number control code and lot control code
7550 OPEN cur_get_item_attribs (l_inventory_org_id,
7551 l_inventory_item_id);
7552
7553 FETCH cur_get_item_attribs
7554 INTO l_serial_control_code;
7555 CLOSE cur_get_item_attribs;
7556
7557
7558 IF l_serial_control_code IN (2, 5) then
7559 OPEN c_get_serial_info (l_inventory_item_id, l_serial_number, l_inventory_org_id);
7560 FETCH c_get_serial_info
7561 INTO l_current_status,l_current_subinventory_code;
7562 CLOSE c_get_serial_info;
7563 --current status = 3 is valid serial number
7564 if (l_current_status = 3) then
7565 l_subinventory := l_current_subinventory_code;
7566 else
7567 l_serial_number := null;
7568 end if;
7569 else
7570 --don't pass the serial number, it is not valid serial number
7571 l_serial_number := null;
7572 end if;
7573
7574
7575 l_dummy := null;
7576 OPEN c_count_material(l_wip_entity_id, l_inventory_item_id);
7577 FETCH c_count_material into l_dummy;
7578 CLOSE c_count_material;
7579
7580
7581 if (l_dummy is null) then
7582 --Default Repair Item as Material on Job
7583 -- l_mtl_txn_dtls_tbl.delete;
7584
7585 OPEN c_get_min_operation_seq(l_wip_entity_id);
7586 FETCH c_get_min_operation_seq into l_operation_seq_num;
7587 CLOSE c_get_min_operation_seq;
7588
7589 if (l_operation_seq_num is null) then
7590 l_operation_seq_num := 1;
7591 end if;
7592
7593 l_mtl_txn_dtls_tbl(i).INVENTORY_ITEM_ID :=l_inventory_item_id;
7594 l_mtl_txn_dtls_tbl(i).WIP_ENTITY_ID :=l_wip_entity_id;
7595 l_mtl_txn_dtls_tbl(i).ORGANIZATION_ID :=l_inventory_org_id;
7596 l_mtl_txn_dtls_tbl(i).OPERATION_SEQ_NUM :=l_operation_seq_num;
7597 l_mtl_txn_dtls_tbl(i).TRANSACTION_QUANTITY :=l_quantity; --repair order qty
7598 l_mtl_txn_dtls_tbl(i).TRANSACTION_UOM :=l_unit_of_measure; --Repair order UOM
7599 l_mtl_txn_dtls_tbl(i).SERIAL_NUMBER :=l_serial_number;
7600 l_mtl_txn_dtls_tbl(i).SUPPLY_SUBINVENTORY :=l_subinventory;
7601 l_mtl_txn_dtls_tbl(i).OBJECT_VERSION_NUMBER := 1;
7602 l_mtl_txn_dtls_tbl(i).NEW_ROW := 'Y';
7603
7604 -- default the reason id
7605 l_rule_input_rec.repair_line_id := p_repair_line_id;
7606 l_rule_input_rec.wip_entity_id := l_wip_entity_id;
7607 l_rule_input_rec.wip_mtl_txn_item_id := l_mtl_txn_dtls_tbl(i).INVENTORY_ITEM_ID;
7608
7609 CSD_RULES_ENGINE_PVT.GET_DEFAULT_VALUE_FROM_RULE(
7610 p_api_version_number => 1.0,
7611 p_init_msg_list => csd_process_util.g_false,
7612 p_commit => csd_process_util.g_false,
7613 p_validation_level => csd_process_util.g_valid_level_full,
7614 p_entity_attribute_type => 'CSD_DEF_ENTITY_ATTR_WIP',
7615 p_entity_attribute_code => 'MTL_TXN_REASON_CODE',
7616 p_rule_input_rec => l_rule_input_rec,
7617 x_default_value => l_default_reason_id,
7618 x_rule_id => l_default_rule_id,
7619 x_return_status => l_return_status,
7620 x_msg_count => l_msg_count,
7621 x_msg_data => l_msg_data
7622 );
7623 IF (x_return_status <> FND_API.G_RET_STS_SUCCESS ) THEN
7624 FND_MESSAGE.SET_NAME('CSD','CSD_DEF_REASON_CODE_FAILURE');
7625 FND_MSG_PUB.ADD;
7626 RAISE FND_API.G_EXC_ERROR;
7627 END IF;
7628 if (l_default_rule_id is not null) then
7629 l_mtl_txn_dtls_tbl(i).REASON_ID := l_default_reason_id;
7630 l_rule_input_rec.WIP_MTL_DISP_CODE_ID := l_default_reason_id; -- bug#14155233 default service warranty
7631 end if;
7632
7633 -- bug#13868879 default create ro flag
7634 CSD_RULES_ENGINE_PVT.GET_DEFAULT_VALUE_FROM_RULE(
7635 p_api_version_number => 1.0,
7636 p_init_msg_list => csd_process_util.g_false,
7637 p_commit => csd_process_util.g_false,
7638 p_validation_level => csd_process_util.g_valid_level_full,
7639 p_entity_attribute_type => 'CSD_DEF_ENTITY_ATTR_WIP',
7640 p_entity_attribute_code => 'CREATE_RO_FLAG',
7641 p_rule_input_rec => l_rule_input_rec,
7642 x_default_value => l_default_create_ro_flag,
7643 x_rule_id => l_default_rule_id,
7644 x_return_status => l_return_status,
7645 x_msg_count => l_msg_count,
7646 x_msg_data => l_msg_data
7647 );
7648 IF (x_return_status <> FND_API.G_RET_STS_SUCCESS ) THEN
7649 FND_MESSAGE.SET_NAME('CSD','CSD_DEF_CREATE_RO_FLAG_FAILURE');
7650 FND_MSG_PUB.ADD;
7651 RAISE FND_API.G_EXC_ERROR;
7652 END IF;
7653 if (l_default_rule_id is not null) then
7654 if l_default_create_ro_flag = 'Y' then
7655 l_mtl_txn_dtls_tbl(i).CREATE_RO_FLAG := fnd_api.g_true;
7656 else
7657 l_mtl_txn_dtls_tbl(i).CREATE_RO_FLAG := fnd_api.g_false;
7658 end if;
7659 end if;
7660
7661 end if;
7662 end if; -- swai: bug 7477845/7483291 l_num_other_jobs = 0
7663 end if;
7664
7665 --*****End of the code to Default Repair Item as Material on Job**********
7666
7667 if (l_mtl_txn_dtls_tbl.count) > 0 then
7668 CSD_HV_WIP_JOB_PVT.PROCESS_SAVE_MTL_TXN_DTLS
7669 (p_api_version_number => 1.0,
7670 p_init_msg_list => 'T',
7671 p_commit => 'F',
7672 p_validation_level => 1,
7673 p_mtl_txn_dtls_tbl => l_mtl_txn_dtls_tbl,
7674 x_op_created => l_op_created,
7675 x_return_status => x_return_status,
7676 x_msg_count => x_msg_count,
7677 x_msg_data => x_msg_data);
7678 IF NOT(x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
7679 FND_MESSAGE.SET_NAME('CSD','CSD_JOB_GEN_FAILURE');
7680 FND_MSG_PUB.ADD;
7681 RAISE FND_API.G_EXC_ERROR;
7682 END IF;
7683 End if;
7684
7685 -- dbms_output.put_line('After createOneJob');
7686
7687 -- call procedures to insert a row in csd_repair_job_xref
7688 -- and csd_repair_history tables for the job created.
7689
7690 l_user_id := fnd_global.user_id;
7691
7692 IF ( FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
7693 FND_LOG.STRING( FND_LOG.LEVEL_EVENT,
7694 lc_mod_name||'beforecallxrefwrite',
7695 'Just before calling csd_to_form_repair_job_xref.validate_and_write');
7696 END IF;
7697
7698 csd_to_form_repair_job_xref.validate_and_write(
7699 p_api_version_number => lc_api_version_number,
7700 p_init_msg_list => FND_API.G_FALSE,
7701 p_commit => FND_API.G_FALSE,
7702 p_validation_level => NULL,
7703 p_action_code => 0,
7704 px_repair_job_xref_id => l_repair_xref_id,
7705 p_created_by => l_user_id,
7706 p_creation_date => SYSDATE,
7707 p_last_updated_by => l_user_id,
7708 p_last_update_date => SYSDATE,
7709 p_last_update_login => l_user_id,
7710 p_repair_line_id => p_repair_line_id,
7711 p_wip_entity_id => l_wip_entity_id,
7712 p_group_id => l_job_header_rec.group_id,
7713 p_organization_id => l_job_header_rec.organization_id,
7714 p_quantity => p_repair_quantity,
7715 p_INVENTORY_ITEM_ID => l_job_header_rec.primary_item_id,
7716 p_ITEM_REVISION => null,
7717 p_OBJECT_VERSION_NUMBER => NULL,
7718 p_attribute_category => NULL,
7719 p_attribute1 => NULL,
7720 p_attribute2 => NULL,
7721 p_attribute3 => NULL,
7722 p_attribute4 => NULL,
7723 p_attribute5 => NULL,
7724 p_attribute6 => NULL,
7725 p_attribute7 => NULL,
7726 p_attribute8 => NULL,
7727 p_attribute9 => NULL,
7728 p_attribute10 => NULL,
7729 p_attribute11 => NULL,
7730 p_attribute12 => NULL,
7731 p_attribute13 => NULL,
7732 p_attribute14 => NULL,
7733 p_attribute15 => NULL,
7734 p_quantity_completed => NULL,
7735 p_job_name => l_job_header_rec.job_name,
7736 p_source_type_code => lc_service_code,
7737 p_source_id1 => p_service_code_tbl(sc_ctr).service_code_id,
7738 p_ro_service_code_id => p_service_code_tbl(sc_ctr).ro_service_code_id,
7739 x_return_status => x_return_status,
7740 x_msg_count => x_msg_count,
7741 x_msg_data => x_msg_data);
7742
7743 -- dbms_output.put_line('After call to csd_to_form_repair_job_xref.validate_and_write');
7744
7745
7746 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
7747 ROLLBACK to GENERATE_WIP_JOBS_FROM_SCS_PVT ;
7748 IF ( FND_LOG.LEVEL_ERROR >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
7749 FND_LOG.STRING( FND_LOG.LEVEL_ERROR,
7750 lc_mod_name||'exc_exception',
7751 'G_EXC_ERROR Exception');
7752 END IF;
7753 RETURN;
7754 END IF;
7755
7756 IF ( FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
7757 FND_LOG.STRING( FND_LOG.LEVEL_EVENT,
7758 lc_mod_name||'beforecallhistwrite',
7759 'Just before calling csd_to_form_repair_history.validate_and_write');
7760 END IF;
7761
7762 csd_to_form_repair_history.validate_and_write(
7763 p_api_version_number => lc_api_version_number,
7764 p_init_msg_list => FND_API.G_FALSE,
7765 p_commit => FND_API.G_FALSE,
7766 p_validation_level => NULL,
7767 p_action_code => 0,
7768 px_repair_history_id => l_rep_hist_id,
7769 p_OBJECT_VERSION_NUMBER => NULL,
7770 p_request_id => NULL,
7771 p_program_id => NULL,
7772 p_program_application_id => NULL,
7773 p_program_update_date => NULL,
7774 p_created_by => l_user_id,
7775 p_creation_date => SYSDATE,
7776 p_last_updated_by => l_user_id,
7777 p_last_update_date => SYSDATE,
7778 p_repair_line_id => p_repair_line_id,
7779 p_event_code => 'JS',
7780 p_event_date => SYSDATE,
7781 p_quantity => p_repair_quantity,
7782 p_paramn1 => l_wip_entity_id,
7783 p_paramn2 => l_job_header_rec.organization_id,
7784 p_paramn3 => NULL,
7785 p_paramn4 => NULL,
7786 p_paramn5 => p_repair_quantity,
7787 p_paramn6 => NULL,
7788 p_paramn8 => NULL,
7789 p_paramn9 => NULL,
7790 p_paramn10 => NULL,
7791 p_paramc1 => l_job_header_rec.job_name,
7792 p_paramc2 => NULL,
7793 p_paramc3 => NULL,
7794 p_paramc4 => NULL,
7795 p_paramc5 => NULL,
7796 p_paramc6 => NULL,
7797 p_paramc7 => NULL,
7798 p_paramc8 => NULL,
7799 p_paramc9 => NULL,
7800 p_paramc10 => NULL,
7801 p_paramd1 => NULL ,
7802 p_paramd2 => NULL ,
7803 p_paramd3 => NULL ,
7804 p_paramd4 => NULL ,
7805 p_paramd5 => SYSDATE,
7806 p_paramd6 => NULL ,
7807 p_paramd7 => NULL ,
7808 p_paramd8 => NULL ,
7809 p_paramd9 => NULL ,
7810 p_paramd10 => NULL ,
7811 p_attribute_category => NULL ,
7812 p_attribute1 => NULL ,
7813 p_attribute2 => NULL ,
7814 p_attribute3 => NULL ,
7815 p_attribute4 => NULL ,
7816 p_attribute5 => NULL ,
7817 p_attribute6 => NULL ,
7818 p_attribute7 => NULL ,
7819 p_attribute8 => NULL ,
7820 p_attribute9 => NULL ,
7821 p_attribute10 => NULL ,
7822 p_attribute11 => NULL ,
7823 p_attribute12 => NULL ,
7824 p_attribute13 => NULL ,
7825 p_attribute14 => NULL ,
7826 p_attribute15 => NULL ,
7827 p_last_update_login => l_user_id,
7828 x_return_status => x_return_status,
7829 x_msg_count => x_msg_count,
7830 x_msg_data => x_msg_data);
7831
7832 -- dbms_output.put_line('after call to csd_to_form_repair_history.validate_and_write');
7833
7834 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
7835 ROLLBACK to GENERATE_WIP_JOBS_FROM_SCS_PVT ;
7836 IF ( FND_LOG.LEVEL_ERROR >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
7837 FND_LOG.STRING( FND_LOG.LEVEL_ERROR,
7838 lc_mod_name||'exc_exception',
7839 'G_EXC_ERROR Exception');
7840 END IF;
7841 RETURN;
7842 END IF;
7843 END LOOP; -- bills and routes
7844
7845 -- swai: bug 5239301
7846 -- if there are no bills or routes for this service code, get the
7847 -- service code name and log a warning message
7848 if (l_bills_routes_count = 0) then
7849 l_show_messages_flag := 'T';
7850 open c_get_service_code_details(p_service_code_tbl(sc_ctr).service_code_id);
7851 fetch c_get_service_code_details into l_service_code;
7852 close c_get_service_code_details;
7853 FND_MESSAGE.SET_NAME('CSD', 'CSD_NO_BILLS_ROUTES_FOR_SC');
7854 FND_MESSAGE.set_token('SERVICE_CODE', l_service_code);
7855 FND_MSG_PUB.add_detail(p_message_type => FND_MSG_PUB.G_WARNING_MSG);
7856 end if;
7857 -- swai: end bug 5239301
7858
7859 l_ro_service_code_rec.ro_service_code_id := p_service_code_tbl(sc_ctr).ro_service_code_id;
7860 l_ro_service_code_rec.applied_to_work_flag := 'Y' ;
7861 l_ro_service_code_rec.object_version_number := p_service_code_tbl(sc_ctr).object_version_number;
7862
7863
7864 -- l_object_version_number := p_service_code_tbl(sc_ctr).object_version_number;
7865
7866 IF ( FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
7867 FND_LOG.STRING( FND_LOG.LEVEL_EVENT,
7868 lc_mod_name||'beforecallupdatesc',
7869 'Just before calling CSD_RO_SERVICE_CODES_PVT.Update_RO_Service_Code');
7870 END IF;
7871
7872
7873
7874 CSD_RO_SERVICE_CODES_PVT.Update_RO_Service_Code(
7875 p_api_version => lc_api_version_number,
7876 p_commit => FND_API.G_FALSE,
7877 p_init_msg_list => FND_API.G_FALSE,
7878 p_validation_level => 100,
7879 p_ro_service_code_rec => l_ro_service_code_rec,
7880 x_obj_ver_number => l_object_version_number,
7881 x_return_status => x_return_status,
7882 x_msg_count => x_msg_count,
7883 x_msg_data => x_msg_data ) ;
7884
7885
7886 -- dbms_output.put_line('after call to CSD_RO_SERVICE_CODES_PVT.Update_RO_Service_Code');
7887 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
7888 -- dbms_output.put_line('inside return status CSD_RO_SERVICE_CODES_PVT.Update_RO_Service_Code');
7889 ROLLBACK to GENERATE_WIP_JOBS_FROM_SCS_PVT ;
7890 IF ( FND_LOG.LEVEL_ERROR >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
7891 FND_LOG.STRING( FND_LOG.LEVEL_ERROR,
7892 lc_mod_name||'exc_exception',
7893 'G_EXC_ERROR Exception');
7894 END IF;
7895 RETURN;
7896 END IF;
7897
7898 END LOOP; -- service codes
7899
7900 -- swai: bug 5239301
7901 -- if there are messages to show, then set the return status in order
7902 -- to flag this, but do not rollback.
7903 if l_show_messages_flag = 'T' then
7904 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
7905 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
7906 p_count => x_msg_count,
7907 p_data => x_msg_data);
7908 end if;
7909 -- swai: end bug 5239301
7910
7911 -- Standard check for p_commit
7912 IF FND_API.to_Boolean( p_commit )
7913 THEN
7914 COMMIT WORK;
7915 END IF;
7916
7917
7918 EXCEPTION
7919 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
7920 ROLLBACK to GENERATE_WIP_JOBS_FROM_SCS_PVT ;
7921 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
7922
7923 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
7924 p_count => x_msg_count,
7925 p_data => x_msg_data);
7926
7927 IF ( FND_LOG.LEVEL_EXCEPTION >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
7928 FND_LOG.STRING( FND_LOG.LEVEL_EXCEPTION,
7929 lc_mod_name||'unx_exception',
7930 'G_EXC_UNEXPECTED_ERROR Exception');
7931 END IF;
7932
7933
7934 WHEN FND_API.G_EXC_ERROR THEN
7935 ROLLBACK to GENERATE_WIP_JOBS_FROM_SCS_PVT ;
7936 x_return_status := FND_API.G_RET_STS_ERROR;
7937
7938
7939 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
7940 p_count => x_msg_count,
7941 p_data => x_msg_data);
7942
7943 IF ( FND_LOG.LEVEL_ERROR >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
7944 FND_LOG.STRING( FND_LOG.LEVEL_ERROR,
7945 lc_mod_name||'exc_exception',
7946 'G_EXC_ERROR Exception');
7947 END IF;
7948
7949 WHEN OTHERS THEN
7950 ROLLBACK to GENERATE_WIP_JOBS_FROM_SCS_PVT ;
7951 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
7952
7953 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
7954
7955 -- Add Unexpected Error to Message List, here SQLERRM is used for
7956 -- getting the error
7957
7958 FND_MSG_PUB.add_exc_msg(p_pkg_name => G_PKG_NAME,
7959 p_procedure_name => lc_api_name );
7960 END IF;
7961
7962 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
7963 p_count => x_msg_count,
7964 p_data => x_msg_data);
7965
7966 IF ( FND_LOG.LEVEL_EXCEPTION >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
7967 FND_LOG.STRING( FND_LOG.LEVEL_EXCEPTION,
7968 lc_mod_name||'others_exception',
7969 'OTHERS Exception');
7970 END IF;
7971
7972
7973 END generate_wip_jobs_from_scs;
7974
7975 --
7976 -- swai: 12.1.2 Time clock functionality
7977 -- Auto-issues all material lines.
7978 -- If WIP entity id and operaion are specified, then only materials for
7979 -- that operation will be issued and repair line will be disregarded.
7980 -- Future functionality:
7981 -- If repair line id is specified without wip entity id and operation,
7982 -- then all materials for all jobs on that repair order will be issued.
7983 --
7984 PROCEDURE process_auto_issue_mtl_txn
7985 (
7986 p_api_version_number IN NUMBER,
7987 p_init_msg_list IN VARCHAR2,
7988 p_commit IN VARCHAR2,
7989 p_validation_level IN NUMBER,
7990 x_return_status OUT NOCOPY VARCHAR2,
7991 x_msg_count OUT NOCOPY NUMBER,
7992 x_msg_data OUT NOCOPY VARCHAR2,
7993 p_wip_entity_id IN NUMBER,
7994 p_operation_seq_num IN NUMBER,
7995 p_repair_line_id IN NUMBER,
7996 x_transaction_header_id OUT NOCOPY NUMBER
7997 ) IS
7998 -- constants used for FND_LOG debug messages
7999 lc_api_name CONSTANT VARCHAR2(30) := 'PROCESS_AUTO_ISSUE_MTL_TXN';
8000 lc_api_version_number CONSTANT NUMBER := 1.0;
8001 lc_mod_name VARCHAR2(2000) := 'csd.plsql.csd_hv_wip_job_pvt.process_auto_issue_mtl_txn';
8002
8003 CURSOR get_wip_operation_mtls (p_wip_entity_id number, p_operation_seq_num number) is
8004 SELECT * FROM
8005 ( SELECT
8006 CWTD.WIP_TRANSACTION_DETAIL_ID, -- wip_transaction_detail_id
8007 WRO.REQUIRED_QUANTITY, -- required_quantity
8008 DECODE(WRO.QUANTITY_ISSUED, 0, to_number(NULL),
8009 WRO.QUANTITY_ISSUED ) QUANTITY_ISSUED, -- issued_quantity
8010 wdj.start_quantity, -- job_quantity
8011 null OP_SCHEDULED_QUANTITY, -- op_scheduled_quantity
8012 WRO.INVENTORY_ITEM_ID, -- inventory_item_id
8013 WRO.WIP_ENTITY_ID, -- wip_entity_id
8014 WRO.ORGANIZATION_ID, -- organization_id
8015 WRO.OPERATION_SEQ_NUM, -- operation_seq_num
8016
8017 nvl( CWTD.TRANSACTION_QUANTITY,
8018 (WRO.REQUIRED_QUANTITY - WRO.QUANTITY_ISSUED )
8019 ) TRANSACTION_QUANTITY, -- transaction_quantity
8020 decode ( CWTD.TRANSACTION_QUANTITY, null, MSIK.PRIMARY_UOM_CODE,
8021 nvl ( CWTD.TRANSACTION_UOM , MSIK.PRIMARY_UOM_CODE) ) TRANSACTION_UOM, -- transaction_uom
8022 MSIK.PRIMARY_UOM_CODE ITEM_PRIMARY_UOM_CODE, -- uom_code
8023 CWTD.SERIAL_NUMBER, -- serial_number
8024 null, -- lot number
8025 CWTD.REVISION revision, -- revision
8026 MSIK.REVISION_QTY_CONTROL_CODE, -- revision_qty_control_code
8027 MSIK.SERIAL_NUMBER_CONTROL_CODE, -- serial_number_control_code
8028 MSIK.LOT_CONTROL_CODE, -- lot_control_code
8029 nvl ( WRO.supply_subinventory,
8030 decode ( fnd_profile.value('CSD_DEF_REP_INV_ORG') , WRO.ORGANIZATION_ID ,
8031 fnd_profile.value('CSD_DEF_HV_SUBINV') , null ) )
8032 subinventory_code, -- supply_subinventory
8033 WRO.supply_locator_id locator_id, -- supply_locator_id
8034 null transaction_interface_id, -- transaction_interface_id
8035 null object_version_number, -- object_version_number
8036 'N' new_row, -- new_row
8037 CWTD.reason_id -- reason_id
8038 -- yvchen: bug 13258460 - 12.1.3+ add DFF attributes
8039 , CWTD.attribute_category
8040 , CWTD.attribute1
8041 , CWTD.attribute2
8042 , CWTD.attribute3
8043 , CWTD.attribute4
8044 , CWTD.attribute5
8045 , CWTD.attribute6
8046 , CWTD.attribute7
8047 , CWTD.attribute8
8048 , CWTD.attribute9
8049 , CWTD.attribute10
8050 , CWTD.attribute11
8051 , CWTD.attribute12
8052 , CWTD.attribute13
8053 , CWTD.attribute14
8054 , CWTD.attribute15
8055 , CWTD.create_ro_flag --bug#13698799 auto create ro, parent ro
8056 FROM
8057 CSD_REPAIR_JOB_XREF CRJX,
8058 WIP_REQUIREMENT_OPERATIONS WRO,
8059 MTL_SYSTEM_ITEMS_KFV MSIK,
8060 WIP_ENTITIES WE,
8061 CSD_WIP_TRANSACTION_DETAILS CWTD,
8062 WIP_DISCRETE_JOBS WDJ,
8063 WIP_OPERATIONS WO,
8064 MTL_SERIAL_NUMBERS MSN,
8065 MTL_TRANSACTION_REASONS MTR
8066 WHERE
8067 CRJX.wip_entity_id = p_wip_entity_id
8068 AND WO.operation_seq_num = p_operation_seq_num
8069 AND CRJX.wip_entity_id = WRO.wip_entity_id
8070 AND WRO.INVENTORY_ITEM_ID = MSIK.INVENTORY_ITEM_ID
8071 AND WRO.ORGANIZATION_ID = MSIK.ORGANIZATION_ID
8072 AND WRO.WIP_ENTITY_ID = WE.WIP_ENTITY_ID
8073 AND WRO.WIP_ENTITY_ID = WDJ.WIP_ENTITY_ID
8074 AND WDJ.STATUS_TYPE <> 12
8075 AND CWTD.INVENTORY_ITEM_ID(+) = WRO.INVENTORY_ITEM_ID
8076 AND CWTD.WIP_ENTITY_ID(+) = WRO.WIP_ENTITY_ID
8077 AND CWTD.OPERATION_SEQ_NUM(+) = WRO.OPERATION_SEQ_NUM
8078 AND WRO.WIP_ENTITY_ID = WO.WIP_ENTITY_ID
8079 AND WRO.ORGANIZATION_ID = WO.ORGANIZATION_ID
8080 AND WRO.OPERATION_SEQ_NUM = WO.OPERATION_SEQ_NUM
8081 AND CWTD.SERIAL_NUMBER = MSN.SERIAL_NUMBER (+)
8082 AND CWTD.INVENTORY_ITEM_ID = MSN.INVENTORY_ITEM_ID (+)
8083 AND CWTD.REASON_ID = MTR.REASON_ID (+)
8084 )
8085 WHERE transaction_quantity <> 0;
8086
8087 -- local variables --
8088 l_mtl_txn_dtls_tbl MTL_TXN_DTLS_TBL_TYPE;
8089 BEGIN
8090
8091 IF ( FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
8092 FND_LOG.STRING( FND_LOG.LEVEL_PROCEDURE,
8093 lc_mod_name||'begin',
8094 'Entering private API process_issue_mtl_txn' );
8095 END IF;
8096
8097 SAVEPOINT PROCESS_AUTO_ISSUE_MTL_TXN_PVT;
8098
8099 -- Standard call to check for call compatibility.
8100 IF NOT FND_API.Compatible_API_Call (lc_api_version_number,
8101 p_api_version_number,
8102 lc_api_name,
8103 G_PKG_NAME)
8104 THEN
8105 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8106 END IF;
8107
8108
8109 IF FND_API.to_boolean(p_init_msg_list) THEN
8110 FND_MSG_PUB.initialize;
8111 END IF;
8112
8113 x_return_status := FND_API.G_RET_STS_SUCCESS;
8114
8115 open get_wip_operation_mtls(p_wip_entity_id, p_operation_seq_num);
8116 fetch get_wip_operation_mtls bulk collect into l_mtl_txn_dtls_tbl;
8117 close get_wip_operation_mtls;
8118 if (l_mtl_txn_dtls_tbl.count > 0) then
8119 process_issue_mtl_txn(
8120 p_api_version_number => p_api_version_number,
8121 p_init_msg_list => p_init_msg_list,
8122 p_commit => p_commit,
8123 p_validation_level => p_validation_level,
8124 x_return_status => x_return_status,
8125 x_msg_count => x_msg_count,
8126 x_msg_data => x_msg_data,
8127 p_mtl_txn_dtls_tbl => l_mtl_txn_dtls_tbl,
8128 x_transaction_header_id => x_transaction_header_id
8129 );
8130 end if;
8131
8132 -- Standard check for p_commit
8133 IF FND_API.to_Boolean( p_commit )
8134 THEN
8135 COMMIT WORK;
8136 END IF;
8137
8138
8139 EXCEPTION
8140 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
8141 ROLLBACK to PROCESS_AUTO_ISSUE_MTL_TXN_PVT ;
8142 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
8143
8144 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
8145 p_count => x_msg_count,
8146 p_data => x_msg_data);
8147
8148 IF ( FND_LOG.LEVEL_EXCEPTION >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
8149 FND_LOG.STRING( FND_LOG.LEVEL_EXCEPTION,
8150 lc_mod_name||'unx_exception',
8151 'G_EXC_UNEXPECTED_ERROR Exception');
8152 END IF;
8153
8154
8155 WHEN FND_API.G_EXC_ERROR THEN
8156 ROLLBACK to PROCESS_AUTO_ISSUE_MTL_TXN_PVT ;
8157 x_return_status := FND_API.G_RET_STS_ERROR;
8158
8159
8160 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
8161 p_count => x_msg_count,
8162 p_data => x_msg_data);
8163
8164 IF ( FND_LOG.LEVEL_ERROR >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
8165 FND_LOG.STRING( FND_LOG.LEVEL_ERROR,
8166 lc_mod_name||'exc_exception',
8167 'G_EXC_ERROR Exception');
8168 END IF;
8169
8170 WHEN OTHERS THEN
8171 ROLLBACK to PROCESS_AUTO_ISSUE_MTL_TXN_PVT ;
8172 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
8173
8174 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
8175
8176 -- Add Unexpected Error to Message List, here SQLERRM is used for
8177 -- getting the error
8178
8179 FND_MSG_PUB.add_exc_msg(p_pkg_name => G_PKG_NAME,
8180 p_procedure_name => lc_api_name );
8181 END IF;
8182
8183 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
8184 p_count => x_msg_count,
8185 p_data => x_msg_data);
8186
8187 IF ( FND_LOG.LEVEL_EXCEPTION >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
8188 FND_LOG.STRING( FND_LOG.LEVEL_EXCEPTION,
8189 lc_mod_name||'others_exception',
8190 'OTHERS Exception');
8191 END IF;
8192
8193 END process_auto_issue_mtl_txn;
8194
8195 --
8196 -- swai: 12.1.2 Time clock functionality
8197 -- Auto-transacts all resource lines.
8198 -- If WIP entity id and operaion are specified, then only resources for
8199 -- that operation will be issued and repair line will be disregarded.
8200 -- Future functionality:
8201 -- If repair line id is specified without wip entity id and operation,
8202 -- then all resources for all jobs on that repair order will be issued.
8203 --
8204 PROCEDURE process_auto_transact_res_txn
8205 (
8206 p_api_version_number IN NUMBER,
8207 p_init_msg_list IN VARCHAR2,
8208 p_commit IN VARCHAR2,
8209 p_validation_level IN NUMBER,
8210 x_return_status OUT NOCOPY VARCHAR2,
8211 x_msg_count OUT NOCOPY NUMBER,
8212 x_msg_data OUT NOCOPY VARCHAR2,
8213 p_wip_entity_id IN NUMBER,
8214 p_operation_seq_num IN NUMBER,
8215 p_repair_line_id IN NUMBER
8216 ) IS
8217 -- constants used for FND_LOG debug messages
8218 lc_api_name CONSTANT VARCHAR2(30) := 'PROCESS_AUTO_TRANSACT_RES_TXN';
8219 lc_api_version_number CONSTANT NUMBER := 1.0;
8220 lc_mod_name VARCHAR2(2000) := 'csd.plsql.csd_hv_wip_job_pvt.process_auto_transact_res_txn';
8221
8222 CURSOR get_wip_operation_res (p_wip_entity_id number, p_operation_seq_num number) is
8223 SELECT * FROM
8224 ( SELECT
8225 WTD.WIP_TRANSACTION_DETAIL_ID,
8226 ROUND(WOR.USAGE_RATE_OR_AMOUNT * DECODE(WOR.BASIS_TYPE,1, WO.SCHEDULED_QUANTITY,1), 6) required_quantity,
8227 decode (( WOR.APPLIED_RESOURCE_UNITS
8228 + csd_hv_wip_job_pvt.get_pending_quantity ( wor.wip_entity_id, wor.operation_seq_num, wor.resource_seq_num, WOR.UOM_CODE )
8229 ) , 0 , to_number(null) ,
8230 ( WOR.APPLIED_RESOURCE_UNITS
8231 + csd_hv_wip_job_pvt.get_pending_quantity ( wor.wip_entity_id, wor.operation_seq_num, wor.resource_seq_num, WOR.UOM_CODE )
8232 ) ) QUANTITY_APPLIED,
8233 null pending_quantity,
8234 wdj.start_quantity,
8235 wo.scheduled_quantity op_scheduled_quantity,
8236 wor.basis_type basis_type,
8237 wor.resource_id,
8238 WOR.RESOURCE_SEQ_NUM,
8239 WOR.WIP_ENTITY_ID,
8240 WOR.ORGANIZATION_ID,
8241 mp.organization_code,
8242 WOR.OPERATION_SEQ_NUM,
8243 nvl( WTD.TRANSACTION_QUANTITY,
8244 decode ( sign (( WOR.USAGE_RATE_OR_AMOUNT * DECODE(WOR.BASIS_TYPE,1, WO.SCHEDULED_QUANTITY,1) )
8245 - WOR.APPLIED_RESOURCE_UNITS
8246 - csd_hv_wip_job_pvt.get_pending_quantity ( wor.wip_entity_id, wor.operation_seq_num, wor.resource_seq_num, WOR.UOM_CODE )
8247 ) , 1 ,
8248 round ((( WOR.USAGE_RATE_OR_AMOUNT * DECODE(WOR.BASIS_TYPE,1, WO.SCHEDULED_QUANTITY,1) )
8249 - WOR.APPLIED_RESOURCE_UNITS
8250 - csd_hv_wip_job_pvt.get_pending_quantity ( wor.wip_entity_id, wor.operation_seq_num, wor.resource_seq_num, WOR.UOM_CODE )
8251 ), 6 ), 0 )
8252 ) TRANSACTION_QUANTITY,
8253 nvl ( WTD.TRANSACTION_UOM , WOR.UOM_CODE) transaction_uom, -- transaction uom
8254 WOR.UOM_CODE,
8255 WE.WIP_ENTITY_NAME,
8256 wtd.employee_id,
8257 papf.employee_number employee_num,
8258 wtd.object_version_number,
8259 'N' new_row,
8260 -- swai: bug 15955754 , FP of bug 14823164 - 12.1.3+ add DFF attributes
8261 WTD.attribute_category
8262 , WTD.attribute1
8263 , WTD.attribute2
8264 , WTD.attribute3
8265 , WTD.attribute4
8266 , WTD.attribute5
8267 , WTD.attribute6
8268 , WTD.attribute7
8269 , WTD.attribute8
8270 , WTD.attribute9
8271 , WTD.attribute10
8272 , WTD.attribute11
8273 , WTD.attribute12
8274 , WTD.attribute13
8275 , WTD.attribute14
8276 , WTD.attribute15
8277 FROM CSD_REPAIR_JOB_XREF CRJX,
8278 WIP_OPERATION_RESOURCES WOR,
8279 WIP_ENTITIES WE,
8280 CSD_WIP_TRANSACTION_DETAILS WTD,
8281 BOM_RESOURCES BR,
8282 wip_operations wo,
8283 WIP_DISCRETE_JOBS wdj,
8284 per_all_people_f papf,
8285 MTL_PARAMETERS MP
8286 WHERE CRJX.wip_entity_id = p_wip_entity_id
8287 AND WO.operation_seq_num = p_operation_seq_num
8288 AND CRJX.wip_entity_id = WOR.wip_entity_id
8289 AND WOR.WIP_ENTITY_ID = WE.WIP_ENTITY_ID
8290 AND WOR.WIP_ENTITY_ID = WDJ.WIP_ENTITY_ID
8291 AND WOR.RESOURCE_ID = BR.RESOURCE_ID
8292 AND WOR. WIP_ENTITY_ID = WTD. WIP_ENTITY_ID(+)
8293 AND WOR. OPERATION_SEQ_NUM = WTD. OPERATION_SEQ_NUM(+)
8294 AND WOR.RESOURCE_SEQ_NUM
8295 = WTD. RESOURCE_SEQ_NUM(+)
8296 AND wtd.employee_id = papf.person_id(+)
8297 AND trunc(sysdate) between nvl( papf.effective_start_date, sysdate-1)
8298 and nvl(papf.effective_end_date, sysdate)
8299 AND wor.organization_id = MP.ORGANIZATION_ID
8300 AND wdj.status_type <> 12
8301 AND WOR.WIP_ENTITY_ID = WO.WIP_ENTITY_ID
8302 AND WOR.OPERATION_SEQ_NUM = WO.OPERATION_SEQ_NUM
8303 AND WOR.ORGANIZATION_ID = WO.ORGANIZATION_ID
8304 AND NVL(WOR.REPETITIVE_SCHEDULE_ID,-1)=NVL(WO.REPETITIVE_SCHEDULE_ID,-1)
8305 )
8306 WHERE transaction_quantity <> 0;
8307
8308 -- local variables --
8309 l_res_txn_dtls_tbl RES_TXN_DTLS_TBL_TYPE;
8310
8311 BEGIN
8312
8313 IF ( FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
8314 FND_LOG.STRING( FND_LOG.LEVEL_PROCEDURE,
8315 lc_mod_name||'begin',
8316 'Entering private API process_auto_transact_res_txn' );
8317 END IF;
8318
8319 SAVEPOINT PROCESS_AUTO_TRANS_RES_TXN_PVT;
8320
8321 -- Standard call to check for call compatibility.
8322 IF NOT FND_API.Compatible_API_Call (lc_api_version_number,
8323 p_api_version_number,
8324 lc_api_name,
8325 G_PKG_NAME)
8326 THEN
8327 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8328 END IF;
8329
8330
8331 IF FND_API.to_boolean(p_init_msg_list) THEN
8332 FND_MSG_PUB.initialize;
8333 END IF;
8334
8335 x_return_status := FND_API.G_RET_STS_SUCCESS;
8336
8337 open get_wip_operation_res(p_wip_entity_id, p_operation_seq_num);
8338 fetch get_wip_operation_res bulk collect into l_res_txn_dtls_tbl;
8339 close get_wip_operation_res;
8340 if (l_res_txn_dtls_tbl.count > 0) then
8341 process_transact_res_txn(
8342 p_api_version_number => p_api_version_number,
8343 p_init_msg_list => p_init_msg_list,
8344 p_commit => p_commit,
8345 p_validation_level => p_validation_level,
8346 x_return_status => x_return_status,
8347 x_msg_count => x_msg_count,
8348 x_msg_data => x_msg_data,
8349 p_res_txn_dtls_tbl => l_res_txn_dtls_tbl
8350 );
8351 end if;
8352
8353 -- Standard check for p_commit
8354 IF FND_API.to_Boolean( p_commit )
8355 THEN
8356 COMMIT WORK;
8357 END IF;
8358
8359
8360 EXCEPTION
8361 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
8362 ROLLBACK to PROCESS_AUTO_TRANS_RES_TXN_PVT ;
8363 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
8364
8365 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
8366 p_count => x_msg_count,
8367 p_data => x_msg_data);
8368
8369 IF ( FND_LOG.LEVEL_EXCEPTION >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
8370 FND_LOG.STRING( FND_LOG.LEVEL_EXCEPTION,
8371 lc_mod_name||'unx_exception',
8372 'G_EXC_UNEXPECTED_ERROR Exception');
8373 END IF;
8374
8375
8376 WHEN FND_API.G_EXC_ERROR THEN
8377 ROLLBACK to PROCESS_AUTO_TRANS_RES_TXN_PVT ;
8378 x_return_status := FND_API.G_RET_STS_ERROR;
8379
8380
8381 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
8382 p_count => x_msg_count,
8383 p_data => x_msg_data);
8384
8385 IF ( FND_LOG.LEVEL_ERROR >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
8386 FND_LOG.STRING( FND_LOG.LEVEL_ERROR,
8387 lc_mod_name||'exc_exception',
8388 'G_EXC_ERROR Exception');
8389 END IF;
8390
8391 WHEN OTHERS THEN
8392 ROLLBACK to PROCESS_AUTO_TRANS_RES_TXN_PVT ;
8393 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
8394
8395 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
8396
8397 -- Add Unexpected Error to Message List, here SQLERRM is used for
8398 -- getting the error
8399
8400 FND_MSG_PUB.add_exc_msg(p_pkg_name => G_PKG_NAME,
8401 p_procedure_name => lc_api_name );
8402 END IF;
8403
8404 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
8405 p_count => x_msg_count,
8406 p_data => x_msg_data);
8407
8408 IF ( FND_LOG.LEVEL_EXCEPTION >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
8409 FND_LOG.STRING( FND_LOG.LEVEL_EXCEPTION,
8410 lc_mod_name||'others_exception',
8411 'OTHERS Exception');
8412 END IF;
8413
8414 END process_auto_transact_res_txn;
8415
8416 --
8417 -- swai: 12.1.2 Time clock functionality
8418 -- Auto-completes an operations
8419 -- If WIP entity id and operaion are specified, then only the spcified
8420 -- operation will be completed.
8421 -- Future functionality:
8422 -- If repair line id is specified without wip entity id and operation,
8423 -- then all operations on all jobs on that repair order will be completed.
8424 --
8425 PROCEDURE process_auto_oper_comp_txn
8426 (
8427 p_api_version_number IN NUMBER,
8428 p_init_msg_list IN VARCHAR2,
8429 p_commit IN VARCHAR2,
8430 p_validation_level IN NUMBER,
8431 x_return_status OUT NOCOPY VARCHAR2,
8432 x_msg_count OUT NOCOPY NUMBER,
8433 x_msg_data OUT NOCOPY VARCHAR2,
8434 p_wip_entity_id IN NUMBER,
8435 p_operation_seq_num IN NUMBER,
8436 p_repair_line_id IN NUMBER
8437
8438 ) IS
8439
8440 -- constants used for FND_LOG debug messages
8441 lc_api_name CONSTANT VARCHAR2(30) := 'PROCESS_AUTO_OPER_COMP_TXN';
8442 lc_api_version_number CONSTANT NUMBER := 1.0;
8443 lc_mod_name VARCHAR2(2000) := 'csd.plsql.csd_hv_wip_job_pvt.process_auto_oper_comp_txn';
8444
8445 CURSOR get_wip_operation (p_wip_entity_id number, p_operation_seq_num number) is
8446 SELECT
8447 we.wip_entity_name,
8448 crjx.organization_id,
8449 wo.operation_seq_num,
8450 wo.next_operation_seq_num,
8451 wo.quantity_in_queue, -- transaction_quantity
8452 msik.primary_uom_code, -- transaction_uom
8453 crjx.wip_entity_id
8454 FROM CSD_REPAIR_JOB_XREF CRJX,
8455 WIP_OPERATIONS WO,
8456 BOM_DEPARTMENTS BD,
8457 wip_discrete_jobs wdj,
8458 wip_entities we,
8459 mfg_lookups ml,
8460 mtl_system_items_kfv msik,
8461 csd_service_codes_vl cscv,
8462 csd_wip_transaction_details WTD,
8463 bom_standard_operations bso
8464 WHERE
8465 CRJX.wip_entity_id = p_wip_entity_id AND
8466 WO.operation_seq_num = p_operation_seq_num AND
8467 CRJX.wip_entity_id = WO.wip_entity_id(+) AND
8468 crjx.wip_entity_id = we.wip_entity_id AND
8469 crjx.wip_entity_id = wdj.wip_entity_id AND
8470 wdj.status_type = ml.lookup_code AND
8471 ml.lookup_type = 'WIP_JOB_STATUS' AND
8472 crjx.inventory_item_id = msik.inventory_item_id AND
8473 crjx.organization_id = msik.organization_id AND
8474 crjx.source_id1 = cscv.service_code_id (+) AND
8475 WO.DEPARTMENT_ID = BD.DEPARTMENT_ID(+) AND
8476 wdj.status_type <> 12 AND
8477 WO.wip_entity_id = WTD.WIP_ENTITY_ID(+) AND
8478 WO.operation_seq_num = WTD.operation_seq_num(+) AND
8479 WO.department_id = wtd.department_id(+) AND
8480 wo.standard_operation_id = bso.standard_operation_id(+) AND
8481 wo.quantity_completed <> wo.scheduled_quantity; -- only uncompleted operationss
8482
8483 -- local variables --
8484 l_mv_txn_dtls_tbl MV_TXN_DTLS_TBL_TYPE;
8485
8486 BEGIN
8487
8488 IF ( FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
8489 FND_LOG.STRING( FND_LOG.LEVEL_PROCEDURE,
8490 lc_mod_name||'begin',
8491 'Entering private API process_auto_oper_comp_txn' );
8492 END IF;
8493
8494 SAVEPOINT PROCESS_AUTO_OPER_COMP_TXN_PVT;
8495
8496 -- Standard call to check for call compatibility.
8497 IF NOT FND_API.Compatible_API_Call (lc_api_version_number,
8498 p_api_version_number,
8499 lc_api_name,
8500 G_PKG_NAME)
8501 THEN
8502 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8503 END IF;
8504
8505
8506 IF FND_API.to_boolean(p_init_msg_list) THEN
8507 FND_MSG_PUB.initialize;
8508 END IF;
8509
8510 x_return_status := FND_API.G_RET_STS_SUCCESS;
8511
8512 open get_wip_operation(p_wip_entity_id, p_operation_seq_num);
8513 fetch get_wip_operation bulk collect into l_mv_txn_dtls_tbl;
8514 close get_wip_operation;
8515 if (l_mv_txn_dtls_tbl.count > 0) then
8516 process_oper_comp_txn(
8517 p_api_version_number => p_api_version_number,
8518 p_init_msg_list => p_init_msg_list,
8519 p_commit => p_commit,
8520 p_validation_level => p_validation_level,
8521 x_return_status => x_return_status,
8522 x_msg_count => x_msg_count,
8523 x_msg_data => x_msg_data,
8524 p_mv_txn_dtls_tbl => l_mv_txn_dtls_tbl
8525 );
8526 end if;
8527
8528 -- Standard check for p_commit
8529 IF FND_API.to_Boolean( p_commit )
8530 THEN
8531 COMMIT WORK;
8532 END IF;
8533
8534
8535 EXCEPTION
8536 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
8537 ROLLBACK to PROCESS_AUTO_OPER_COMP_TXN_PVT ;
8538 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
8539
8540 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
8541 p_count => x_msg_count,
8542 p_data => x_msg_data);
8543
8544 IF ( FND_LOG.LEVEL_EXCEPTION >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
8545 FND_LOG.STRING( FND_LOG.LEVEL_EXCEPTION,
8546 lc_mod_name||'unx_exception',
8547 'G_EXC_UNEXPECTED_ERROR Exception');
8548 END IF;
8549
8550
8551 WHEN FND_API.G_EXC_ERROR THEN
8552 ROLLBACK to PROCESS_AUTO_OPER_COMP_TXN_PVT ;
8553 x_return_status := FND_API.G_RET_STS_ERROR;
8554
8555
8556 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
8557 p_count => x_msg_count,
8558 p_data => x_msg_data);
8559
8560 IF ( FND_LOG.LEVEL_ERROR >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
8561 FND_LOG.STRING( FND_LOG.LEVEL_ERROR,
8562 lc_mod_name||'exc_exception',
8563 'G_EXC_ERROR Exception');
8564 END IF;
8565
8566 WHEN OTHERS THEN
8567 ROLLBACK to PROCESS_AUTO_OPER_COMP_TXN_PVT ;
8568 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
8569
8570 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
8571
8572 -- Add Unexpected Error to Message List, here SQLERRM is used for
8573 -- getting the error
8574
8575 FND_MSG_PUB.add_exc_msg(p_pkg_name => G_PKG_NAME,
8576 p_procedure_name => lc_api_name );
8577 END IF;
8578
8579 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
8580 p_count => x_msg_count,
8581 p_data => x_msg_data);
8582
8583 IF ( FND_LOG.LEVEL_EXCEPTION >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
8584 FND_LOG.STRING( FND_LOG.LEVEL_EXCEPTION,
8585 lc_mod_name||'others_exception',
8586 'OTHERS Exception');
8587 END IF;
8588 END process_auto_oper_comp_txn;
8589
8590 --
8591 PROCEDURE process_time_clock_res_txn
8592 (
8593 p_api_version_number IN NUMBER,
8594 p_init_msg_list IN VARCHAR2,
8595 p_commit IN VARCHAR2,
8596 p_validation_level IN NUMBER,
8597 x_return_status OUT NOCOPY VARCHAR2,
8598 x_msg_count OUT NOCOPY NUMBER,
8599 x_msg_data OUT NOCOPY VARCHAR2,
8600 p_time_clock_entry_id IN NUMBER
8601 ) IS
8602 -- constants used for FND_LOG debug messages
8603 lc_api_name CONSTANT VARCHAR2(30) := 'PROCESS_TIME_CLOCK_RES_TXN';
8604 lc_api_version_number CONSTANT NUMBER := 1.0;
8605 lc_mod_name VARCHAR2(2000) := 'csd.plsql.csd_hv_wip_job_pvt.process_time_clock_res_txn';
8606
8607 l_wip_entity_id NUMBER;
8608 l_operation_seq_num NUMBER;
8609 l_employee_id NUMBER;
8610 l_resource_id NUMBER;
8611 l_clock_in_time DATE;
8612 l_clock_out_time DATE;
8613 l_res_txn_dtls_tbl RES_TXN_DTLS_TBL_TYPE;
8614 l_existing_res_txn RES_TXN_DTLS_REC_TYPE;
8615 l_clocked_time NUMBER;
8616 l_exists VARCHAR2(10);
8617 l_bom_hr_uom VARCHAR(15) := fnd_profile.value('BOM:HOUR_UOM_CODE'); -- yvchen: bug 13026808
8618
8619 cursor get_time_clock_entry is
8620 select wip_entity_id,
8621 operation_seq_num,
8622 employee_id,
8623 resource_id,
8624 clock_in_time,
8625 clock_out_time
8626 from csd_time_clock_entries
8627 where time_clock_entry_id = p_time_clock_entry_id;
8628
8629 cursor get_employee_num (p_organization_id NUMBER, p_employee_id NUMBER) is
8630 select employee_num
8631 from mtl_employees_current_view
8632 where organization_id = p_organization_id
8633 and employee_id = p_employee_id;
8634
8635 -- swai: bug 8923513
8636 -- validates the resource belongs to the same department as the operation
8637 cursor validate_op_res_dept (p_wip_entity_id NUMBER,
8638 p_operation_seq_num NUMBER,
8639 p_resource_id NUMBER) is
8640 SELECT
8641 'exists'
8642 FROM
8643 cst_activities cst,
8644 mtl_uom_conversions muc,
8645 bom_resources res,
8646 bom_department_resources bdr,
8647 bom_departments bd,
8648 mfg_lookups lup ,
8649 wip_operations wo
8650 WHERE nvl(res.disable_date, sysdate + 2) > sysdate
8651 and res.resource_id = bdr.resource_id
8652 and res.default_activity_id = cst.activity_id (+)
8653 and nvl(cst.organization_id(+), res.organization_id) = res.organization_id
8654 and nvl(cst.disable_date (+), sysdate + 2) > sysdate
8655 and res.unit_of_measure = muc.uom_code
8656 and muc.inventory_item_id = 0
8657 and lookup_type = 'BOM_AUTOCHARGE_TYPE'
8658 and lookup_code=nvl(res.autocharge_type,1)
8659 and bdr.department_id = bd.department_id
8660 and wo.department_id = bdr.department_id
8661 and res.organization_id = wo.organization_id
8662 and wo.wip_entity_id = p_wip_entity_id
8663 and wo.operation_seq_num = p_operation_seq_num
8664 and res.resource_id = p_resource_id
8665 and rownum = 1;
8666
8667 cursor get_resource_info (p_wip_entity_id NUMBER,
8668 p_operation_seq_num NUMBER,
8669 p_resource_id NUMBER) is
8670 SELECT
8671 WTD.WIP_TRANSACTION_DETAIL_ID,
8672 wor.resource_id,
8673 WOR.RESOURCE_SEQ_NUM,
8674 WOR.WIP_ENTITY_ID,
8675 WE.WIP_ENTITY_NAME,
8676 WOR.ORGANIZATION_ID,
8677 MP.ORGANIZATION_CODE,
8678 WOR.OPERATION_SEQ_NUM,
8679 WDJ.START_QUANTITY job_quantity,
8680 ROUND(WOR.USAGE_RATE_OR_AMOUNT * DECODE(WOR.BASIS_TYPE,1, WO.SCHEDULED_QUANTITY,1), 6) required_quantity,
8681 WO.SCHEDULED_QUANTITY op_scheduled_quantity,
8682 ROUND( decode (
8683 ( WOR.APPLIED_RESOURCE_UNITS
8684 + csd_hv_wip_job_pvt.get_pending_quantity ( wor.wip_entity_id,
8685 wor.operation_seq_num,
8686 wor.resource_seq_num,
8687 WOR.UOM_CODE ) ) , 0 ,
8688 to_number(null) ,
8689 ( WOR.APPLIED_RESOURCE_UNITS
8690 + csd_hv_wip_job_pvt.get_pending_quantity ( wor.wip_entity_id,
8691 wor.operation_seq_num,
8692 wor.resource_seq_num,
8693 WOR.UOM_CODE ) )
8694 ), 2
8695 ) APPLIED_QUANTITY, -- quantity applied
8696 NVL( WTD.TRANSACTION_QUANTITY,
8697 decode ( sign (( WOR.USAGE_RATE_OR_AMOUNT * DECODE(WOR.BASIS_TYPE,1, WO.SCHEDULED_QUANTITY,1) )
8698 - WOR.APPLIED_RESOURCE_UNITS
8699 - csd_hv_wip_job_pvt.get_pending_quantity ( wor.wip_entity_id, wor.operation_seq_num, wor.resource_seq_num, WOR.UOM_CODE )
8700 ) , 1 ,
8701 round ((( WOR.USAGE_RATE_OR_AMOUNT * DECODE(WOR.BASIS_TYPE,1, WO.SCHEDULED_QUANTITY,1) )
8702 - WOR.APPLIED_RESOURCE_UNITS
8703 - csd_hv_wip_job_pvt.get_pending_quantity ( wor.wip_entity_id, wor.operation_seq_num, wor.resource_seq_num, WOR.UOM_CODE )
8704 ), 6 ), 0 )
8705 ) TRANSACTION_QUANTITY,
8706 nvl ( WTD.TRANSACTION_UOM , WOR.UOM_CODE) transaction_uom, -- transaction uom
8707 WOR.UOM_CODE,
8708 wtd.employee_id,
8709 papf.employee_number employee_num,
8710 wor.basis_type basis_type,
8711 wtd.object_version_number,
8712 'N' new_row
8713 FROM CSD_REPAIR_JOB_XREF CRJX,
8714 WIP_OPERATION_RESOURCES WOR,
8715 WIP_ENTITIES WE,
8716 CSD_WIP_TRANSACTION_DETAILS WTD,
8717 BOM_RESOURCES BR,
8718 wip_operations wo,
8719 WIP_DISCRETE_JOBS wdj,
8720 per_all_people_f papf,
8721 MTL_PARAMETERS MP
8722 WHERE CRJX.wip_entity_id = p_wip_entity_id
8723 AND WO.operation_seq_num = p_operation_seq_num
8724 AND WOR.RESOURCE_ID = p_resource_id
8725 AND CRJX.wip_entity_id = WOR.wip_entity_id
8726 AND WOR.WIP_ENTITY_ID = WE.WIP_ENTITY_ID
8727 AND WOR.WIP_ENTITY_ID = WDJ.WIP_ENTITY_ID
8728 AND WOR.RESOURCE_ID = BR.RESOURCE_ID
8729 AND WOR. WIP_ENTITY_ID = WTD. WIP_ENTITY_ID(+)
8730 AND WOR. OPERATION_SEQ_NUM = WTD. OPERATION_SEQ_NUM(+)
8731 AND WOR.RESOURCE_SEQ_NUM
8732 = WTD. RESOURCE_SEQ_NUM(+)
8733 AND wtd.employee_id = papf.person_id(+)
8734 AND trunc(sysdate) between nvl( papf.effective_start_date, sysdate-1)
8735 and nvl(papf.effective_end_date, sysdate)
8736 AND wor.organization_id = MP.ORGANIZATION_ID
8737 AND wdj.status_type <> 12
8738 AND WOR.WIP_ENTITY_ID = WO.WIP_ENTITY_ID
8739 AND WOR.OPERATION_SEQ_NUM = WO.OPERATION_SEQ_NUM
8740 AND WOR.ORGANIZATION_ID = WO.ORGANIZATION_ID
8741 AND NVL(WOR.REPETITIVE_SCHEDULE_ID,-1)=NVL(WO.REPETITIVE_SCHEDULE_ID,-1);
8742
8743 BEGIN
8744
8745 IF ( FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
8746 FND_LOG.STRING( FND_LOG.LEVEL_PROCEDURE,
8747 lc_mod_name||'begin',
8748 'Entering private API process_time_clock_res_txn' );
8749 END IF;
8750
8751 SAVEPOINT PROCESS_TIME_CLOCK_RES_TXN_PVT;
8752
8753 -- Standard call to check for call compatibility.
8754 IF NOT FND_API.Compatible_API_Call (lc_api_version_number,
8755 p_api_version_number,
8756 lc_api_name,
8757 G_PKG_NAME)
8758 THEN
8759 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8760 END IF;
8761
8762
8763 IF FND_API.to_boolean(p_init_msg_list) THEN
8764 FND_MSG_PUB.initialize;
8765 END IF;
8766
8767 x_return_status := FND_API.G_RET_STS_SUCCESS;
8768
8769 open get_time_clock_entry;
8770 fetch get_time_clock_entry
8771 into l_wip_entity_id,
8772 l_operation_seq_num,
8773 l_employee_id,
8774 l_resource_id,
8775 l_clock_in_time,
8776 l_clock_out_time;
8777 close get_time_clock_entry;
8778
8779 if (l_resource_id is null) then
8780 l_resource_id := fnd_profile.value('CSD_DEF_HV_BOM_RESOURCE');-- get resource from profile value.
8781 if (l_resource_id is null) then
8782 FND_MESSAGE.SET_NAME('CSD', 'CSD_NO_DEF_HV_BOM_RESOURCE');
8783 FND_MSG_PUB.add_detail(p_message_type => FND_MSG_PUB.G_WARNING_MSG);
8784 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
8785 RETURN;
8786 else
8787 -- Bug 8923513: Validate the resource against the operation department
8788 -- if resource does not belong to department, throw error.
8789 open validate_op_res_dept (l_wip_entity_id, l_operation_seq_num, l_resource_id);
8790 fetch validate_op_res_dept into l_exists;
8791 close validate_op_res_dept;
8792
8793 if (l_exists is null) then
8794 FND_MESSAGE.SET_NAME('CSD', 'CSD_INVALID_DEF_HV_BOM_RES');
8795 FND_MSG_PUB.add_detail(p_message_type => FND_MSG_PUB.G_WARNING_MSG);
8796 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
8797 RETURN;
8798 end if;
8799 end if;
8800 end if;
8801
8802 -- query for existing resource transaction before transacting additional resources
8803 open get_resource_info (l_wip_entity_id, l_operation_seq_num, l_resource_id);
8804 fetch get_resource_info
8805 into l_existing_res_txn.wip_transaction_detail_id,
8806 l_existing_res_txn.resource_id,
8807 l_existing_res_txn.resource_seq_num,
8808 l_existing_res_txn.wip_entity_id,
8809 l_existing_res_txn.wip_entity_name,
8810 l_existing_res_txn.organization_id,
8811 l_existing_res_txn.organization_code,
8812 l_existing_res_txn.operation_seq_num,
8813 l_existing_res_txn.job_quantity,
8814 l_existing_res_txn.required_quantity,
8815 l_existing_res_txn.op_scheduled_quantity,
8816 l_existing_res_txn.applied_quantity,
8817 l_existing_res_txn.transaction_quantity,
8818 l_existing_res_txn.transaction_uom,
8819 l_existing_res_txn.uom_code,
8820 l_existing_res_txn.employee_id,
8821 l_existing_res_txn.employee_num,
8822 l_existing_res_txn.basis_type,
8823 l_existing_res_txn.object_version_number,
8824 l_existing_res_txn.new_row;
8825 close get_resource_info;
8826
8827 -- populate resource details table to create and/or transact
8828 l_clocked_time := l_clock_out_time - l_clock_in_time;
8829 -- yvchen: bug 13026808 - use BOM:HOUR_UOM_CODE profile if it is set. Otherwise use original code.
8830 if (l_bom_hr_uom is null) then
8831 l_res_txn_dtls_tbl(1).transaction_quantity := l_clocked_time;
8832 l_res_txn_dtls_tbl(1).transaction_uom := 'DAY';
8833 else
8834 l_res_txn_dtls_tbl(1).transaction_quantity := l_clocked_time*24;
8835 l_res_txn_dtls_tbl(1).transaction_uom := l_bom_hr_uom;
8836 end if;
8837 l_res_txn_dtls_tbl(1).wip_entity_id := l_wip_entity_id;
8838 l_res_txn_dtls_tbl(1).operation_seq_num := l_operation_seq_num;
8839 l_res_txn_dtls_tbl(1).employee_id := l_employee_id;
8840 l_res_txn_dtls_tbl(1).resource_id := l_resource_id;
8841 l_res_txn_dtls_tbl(1).organization_id := nvl(l_existing_res_txn.organization_id, fnd_profile.value('CSD_DEF_REP_INV_ORG'));
8842 l_res_txn_dtls_tbl(1).object_version_number := nvl(l_existing_res_txn.object_version_number, 1);
8843 l_res_txn_dtls_tbl(1).new_row := nvl(l_existing_res_txn.new_row, 'Y');
8844
8845 -- save the new/updated resource
8846 if (l_res_txn_dtls_tbl(1).new_row = 'Y') then
8847 PROCESS_SAVE_RES_TXN_DTLS
8848 (
8849 p_api_version_number => p_api_version_number,
8850 p_init_msg_list => p_init_msg_list,
8851 p_commit => p_commit,
8852 p_validation_level => p_validation_level,
8853 x_return_status => x_return_status,
8854 x_msg_count => x_msg_count,
8855 x_msg_data => x_msg_data,
8856 p_res_txn_dtls_tbl => l_res_txn_dtls_tbl
8857 );
8858 -- afer saving, requery to get latest info to transact,
8859 -- including wip_transaction_detail_id, object_version_number
8860 open get_resource_info (l_wip_entity_id, l_operation_seq_num, l_resource_id);
8861 fetch get_resource_info
8862 into l_res_txn_dtls_tbl(1).wip_transaction_detail_id,
8863 l_res_txn_dtls_tbl(1).resource_id,
8864 l_res_txn_dtls_tbl(1).resource_seq_num,
8865 l_res_txn_dtls_tbl(1).wip_entity_id,
8866 l_res_txn_dtls_tbl(1).wip_entity_name,
8867 l_res_txn_dtls_tbl(1).organization_id,
8868 l_res_txn_dtls_tbl(1).organization_code,
8869 l_res_txn_dtls_tbl(1).operation_seq_num,
8870 l_res_txn_dtls_tbl(1).job_quantity,
8871 l_res_txn_dtls_tbl(1).required_quantity,
8872 l_res_txn_dtls_tbl(1).op_scheduled_quantity,
8873 l_res_txn_dtls_tbl(1).applied_quantity,
8874 l_res_txn_dtls_tbl(1).transaction_quantity,
8875 l_res_txn_dtls_tbl(1).transaction_uom,
8876 l_res_txn_dtls_tbl(1).uom_code,
8877 l_res_txn_dtls_tbl(1).employee_id,
8878 l_res_txn_dtls_tbl(1).employee_num,
8879 l_res_txn_dtls_tbl(1).basis_type,
8880 l_res_txn_dtls_tbl(1).object_version_number,
8881 l_res_txn_dtls_tbl(1).new_row;
8882 close get_resource_info;
8883 else
8884 -- if transacting an existing resource, populate additional fields
8885 -- pass null for wip_transaction_detail_id because we do not want to
8886 -- transact the existing record
8887 l_res_txn_dtls_tbl(1).wip_transaction_detail_id := null;
8888 l_res_txn_dtls_tbl(1).resource_seq_num := l_existing_res_txn.resource_seq_num;
8889 l_res_txn_dtls_tbl(1).uom_code := nvl(l_existing_res_txn.transaction_uom,nvl(l_bom_hr_uom, 'DAY')); -- yvchen: bug 13026808
8890 l_res_txn_dtls_tbl(1).organization_code := l_existing_res_txn.organization_code;
8891 l_res_txn_dtls_tbl(1).wip_entity_name := l_existing_res_txn.wip_entity_name;
8892 l_res_txn_dtls_tbl(1).job_quantity := l_existing_res_txn.job_quantity;
8893 l_res_txn_dtls_tbl(1).required_quantity := l_existing_res_txn.required_quantity;
8894 l_res_txn_dtls_tbl(1).op_scheduled_quantity := l_existing_res_txn.op_scheduled_quantity;
8895 l_res_txn_dtls_tbl(1).applied_quantity := l_existing_res_txn.applied_quantity;
8896 l_res_txn_dtls_tbl(1).basis_type := l_existing_res_txn.basis_type;
8897 -- employee could be different from the one that was saved, so query it separately
8898 open get_employee_num (l_res_txn_dtls_tbl(1).organization_id, l_res_txn_dtls_tbl(1).employee_id);
8899 fetch get_employee_num
8900 into l_res_txn_dtls_tbl(1).employee_num;
8901 close get_employee_num;
8902 end if;
8903
8904 -- now, transact the resource
8905 process_transact_res_txn
8906 (
8907 p_api_version_number => p_api_version_number,
8908 p_init_msg_list => p_init_msg_list,
8909 p_commit => p_commit,
8910 p_validation_level => p_validation_level,
8911 x_return_status => x_return_status,
8912 x_msg_count => x_msg_count,
8913 x_msg_data => x_msg_data,
8914 p_res_txn_dtls_tbl => l_res_txn_dtls_tbl
8915 );
8916
8917 EXCEPTION
8918 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
8919 ROLLBACK to PROCESS_TIME_CLOCK_RES_TXN_PVT ;
8920 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
8921
8922 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
8923 p_count => x_msg_count,
8924 p_data => x_msg_data);
8925
8926 IF ( FND_LOG.LEVEL_EXCEPTION >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
8927 FND_LOG.STRING( FND_LOG.LEVEL_EXCEPTION,
8928 lc_mod_name||'unx_exception',
8929 'G_EXC_UNEXPECTED_ERROR Exception');
8930 END IF;
8931
8932
8933 WHEN FND_API.G_EXC_ERROR THEN
8934 ROLLBACK to PROCESS_TIME_CLOCK_RES_TXN_PVT ;
8935 x_return_status := FND_API.G_RET_STS_ERROR;
8936
8937
8938 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
8939 p_count => x_msg_count,
8940 p_data => x_msg_data);
8941
8942 IF ( FND_LOG.LEVEL_ERROR >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
8943 FND_LOG.STRING( FND_LOG.LEVEL_ERROR,
8944 lc_mod_name||'exc_exception',
8945 'G_EXC_ERROR Exception');
8946 END IF;
8947
8948 WHEN OTHERS THEN
8949 ROLLBACK to PROCESS_TIME_CLOCK_RES_TXN_PVT ;
8950 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
8951
8952 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
8953
8954 -- Add Unexpected Error to Message List, here SQLERRM is used for
8955 -- getting the error
8956
8957 FND_MSG_PUB.add_exc_msg(p_pkg_name => G_PKG_NAME,
8958 p_procedure_name => lc_api_name );
8959 END IF;
8960
8961 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
8962 p_count => x_msg_count,
8963 p_data => x_msg_data);
8964
8965 IF ( FND_LOG.LEVEL_EXCEPTION >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
8966 FND_LOG.STRING( FND_LOG.LEVEL_EXCEPTION,
8967 lc_mod_name||'others_exception',
8968 'OTHERS Exception');
8969 END IF;
8970 END process_time_clock_res_txn;
8971
8972 PROCEDURE process_comp_work_ro_status
8973 (
8974 p_api_version_number IN NUMBER,
8975 p_init_msg_list IN VARCHAR2,
8976 p_commit IN VARCHAR2,
8977 p_validation_level IN NUMBER,
8978 x_return_status OUT NOCOPY VARCHAR2,
8979 x_msg_count OUT NOCOPY NUMBER,
8980 x_msg_data OUT NOCOPY VARCHAR2,
8981 p_repair_line_id IN NUMBER,
8982 x_new_flow_status_code OUT NOCOPY VARCHAR2,
8983 x_new_ro_status_code OUT NOCOPY VARCHAR2
8984 ) IS
8985 -- constants used for FND_LOG debug messages
8986 lc_api_name CONSTANT VARCHAR2(30) := 'PROCESS_COMP_WORK_RO_STATUS';
8987 lc_api_version_number CONSTANT NUMBER := 1.0;
8988 lc_mod_name VARCHAR2(2000) := 'csd.plsql.csd_hv_wip_job_pvt.process_comp_work_ro_status';
8989
8990 cursor c_get_repair_info is
8991 select repair_type_id, flow_status_id, object_version_number
8992 from csd_repairs
8993 where repair_line_id = p_repair_line_id;
8994
8995 cursor c_get_to_flow_status_id is
8996 select flow_status_id
8997 from csd_flow_statuses_b
8998 where flow_status_code = fnd_profile.value('CSD_COMPLETE_WORK_RO_STATUS');
8999
9000 cursor c_get_repair_status is
9001 select flb.flow_status_code, dra.status
9002 from csd_repairs dra, csd_flow_statuses_b flb
9003 where dra.repair_line_id = p_repair_line_id
9004 and dra.flow_status_id = flb.flow_status_id;
9005
9006 --
9007 l_repair_type_id NUMBER;
9008 l_obj_ver_num NUMBER;
9009 lx_obj_ver_num NUMBER;
9010 l_fm_flow_status_id NUMBER;
9011 l_to_flow_status_id NUMBER;
9012
9013 BEGIN
9014 IF ( FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
9015 FND_LOG.STRING( FND_LOG.LEVEL_PROCEDURE,
9016 lc_mod_name||'begin',
9017 'Entering private API process_comp_work_ro_status' );
9018 END IF;
9019
9020 SAVEPOINT PROCESS_COMP_WORK_RO_STATUS;
9021
9022 -- Standard call to check for call compatibility.
9023 IF NOT FND_API.Compatible_API_Call (lc_api_version_number,
9024 p_api_version_number,
9025 lc_api_name,
9026 G_PKG_NAME)
9027 THEN
9028 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9029 END IF;
9030
9031
9032 IF FND_API.to_boolean(p_init_msg_list) THEN
9033 FND_MSG_PUB.initialize;
9034 END IF;
9035
9036 x_return_status := FND_API.G_RET_STS_SUCCESS;
9037
9038 -- get the repair order info in order to update flow status
9039 open c_get_repair_info;
9040 fetch c_get_repair_info
9041 into l_repair_type_id, l_fm_flow_status_id, l_obj_ver_num;
9042 close c_get_repair_info;
9043
9044 -- get the flow status id to change to, from profile option
9045 open c_get_to_flow_status_id;
9046 fetch c_get_to_flow_status_id
9047 into l_to_flow_status_id;
9048 close c_get_to_flow_status_id;
9049
9050
9051 csd_repairs_pvt.update_flow_status
9052 (
9053 p_api_version => p_api_version_number,
9054 p_commit => p_commit,
9055 p_init_msg_list => p_init_msg_list,
9056 p_validation_level => p_validation_level,
9057 x_return_status => x_return_status,
9058 x_msg_count => x_msg_count,
9059 x_msg_data => x_msg_data,
9060 p_repair_line_id => p_repair_line_id,
9061 p_repair_type_id => l_repair_type_id,
9062 p_from_flow_status_id => l_fm_flow_status_id,
9063 p_to_flow_status_id => l_to_flow_status_id,
9064 p_reason_code => null,
9065 p_comments => null,
9066 p_check_access_flag => 'Y',
9067 p_object_version_number => l_obj_ver_num,
9068 x_object_version_number => lx_obj_ver_num
9069 );
9070
9071 -- requery for the new flow status
9072 open c_get_repair_status;
9073 fetch c_get_repair_status
9074 into x_new_flow_status_code, x_new_ro_status_code;
9075 close c_get_repair_status;
9076
9077 -- Standard check for p_commit
9078 IF FND_API.to_Boolean( p_commit )
9079 THEN
9080 COMMIT WORK;
9081 END IF;
9082
9083 EXCEPTION
9084 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
9085 ROLLBACK to PROCESS_COMP_WORK_RO_STATUS ;
9086 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
9087
9088 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
9089 p_count => x_msg_count,
9090 p_data => x_msg_data);
9091
9092 IF ( FND_LOG.LEVEL_EXCEPTION >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
9093 FND_LOG.STRING( FND_LOG.LEVEL_EXCEPTION,
9094 lc_mod_name||'unx_exception',
9095 'G_EXC_UNEXPECTED_ERROR Exception');
9096 END IF;
9097
9098
9099 WHEN FND_API.G_EXC_ERROR THEN
9100 ROLLBACK to PROCESS_COMP_WORK_RO_STATUS ;
9101 x_return_status := FND_API.G_RET_STS_ERROR;
9102
9103
9104 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
9105 p_count => x_msg_count,
9106 p_data => x_msg_data);
9107
9108 IF ( FND_LOG.LEVEL_ERROR >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
9109 FND_LOG.STRING( FND_LOG.LEVEL_ERROR,
9110 lc_mod_name||'exc_exception',
9111 'G_EXC_ERROR Exception');
9112 END IF;
9113
9114 WHEN OTHERS THEN
9115 ROLLBACK to PROCESS_COMP_WORK_RO_STATUS ;
9116 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
9117
9118 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
9119
9120 -- Add Unexpected Error to Message List, here SQLERRM is used for
9121 -- getting the error
9122
9123 FND_MSG_PUB.add_exc_msg(p_pkg_name => G_PKG_NAME,
9124 p_procedure_name => lc_api_name );
9125 END IF;
9126
9127 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
9128 p_count => x_msg_count,
9129 p_data => x_msg_data);
9130
9131 IF ( FND_LOG.LEVEL_EXCEPTION >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
9132 FND_LOG.STRING( FND_LOG.LEVEL_EXCEPTION,
9133 lc_mod_name||'others_exception',
9134 'OTHERS Exception');
9135 END IF;
9136 END process_comp_work_ro_status;
9137
9138 /**
9139 * swai: 12.1.3
9140 * Deletes a saved material requirement that has not been transacted yet.
9141 * The following fields in p_mtl_txn_dtls are expected to be filled out:
9142 * wip_entity_id
9143 * organization_id
9144 * inventory_item_id
9145 * operation_seq_num
9146 * wip_transaction_detail_id (optional)
9147 */
9148 PROCEDURE process_delete_mtl_txn_dtl
9149 (
9150 p_api_version_number IN NUMBER,
9151 p_init_msg_list IN VARCHAR2 ,
9152 p_commit IN VARCHAR2 ,
9153 p_validation_level IN NUMBER ,
9154 x_return_status OUT NOCOPY VARCHAR2,
9155 x_msg_count OUT NOCOPY NUMBER,
9156 x_msg_data OUT NOCOPY VARCHAR2,
9157 p_mtl_txn_dtls IN MTL_TXN_DTLS_REC_TYPE
9158 )
9159 IS
9160 lc_api_name CONSTANT VARCHAR2(30) := 'PROCESS_DELETE_MTL_TXN_DTL';
9161 lc_api_version_number CONSTANT NUMBER := 1.0;
9162
9163 -- constants used for FND_LOG debug messages
9164 lc_mod_name CONSTANT VARCHAR2(2000) := 'csd.plsql.csd_hv_wip_job_pvt.process_delete_mtl_txn_dtl';
9165
9166 -- Constants Used for Inserting into wip_job_schedule_interface,
9167 -- These are the values needed for WIP Mass Load to pick up the records
9168
9169 -- Constants for WIP_JOB_SCHEDULE_INTERFACE table
9170 lc_non_std_update_load_type CONSTANT NUMBER := 3; -- update non-standard job
9171
9172 -- Constants for WIP_JOB_DTLS_INTERFACE table
9173 lc_load_mtl_type CONSTANT NUMBER := 2; -- material
9174 lc_substitution_del_type CONSTANT NUMBER := 1; -- delete
9175
9176
9177 -- Job Records to hold the Job header and details information
9178 l_job_header_rec wip_job_schedule_interface%ROWTYPE;
9179 l_job_details_rec wip_job_dtls_interface%ROWTYPE;
9180
9181 -- wip
9182 l_wip_transaction_detail_id NUMBER := NULL;
9183
9184 cursor c_get_wip_txn_detail_id is
9185 select wip_transaction_detail_id
9186 from csd_wip_transaction_details
9187 where wip_entity_id = p_mtl_txn_dtls.wip_entity_id
9188 and inventory_item_id = p_mtl_txn_dtls.inventory_item_id
9189 and operation_seq_num = p_mtl_txn_dtls.operation_seq_num;
9190
9191 BEGIN
9192
9193 IF ( FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
9194 FND_LOG.STRING( FND_LOG.LEVEL_PROCEDURE,
9195 lc_mod_name||'begin',
9196 'Entering private API process_delete_mtl_txn_dtl' );
9197 END IF;
9198
9199 -- Standard Start of API savepoint
9200 SAVEPOINT PROCESS_DELETE_MTL_TXN_DTL_PVT;
9201
9202 -- Standard call to check for call compatibility.
9203 IF NOT FND_API.Compatible_API_Call
9204 (lc_api_version_number,
9205 p_api_version_number,
9206 lc_api_name,
9207 G_PKG_NAME)
9208 THEN
9209 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9210 END IF;
9211
9212 -- Initialize message list if p_init_msg_list is set to TRUE
9213 IF FND_API.to_boolean(p_init_msg_list) THEN
9214 FND_MSG_PUB.initialize;
9215 END IF;
9216
9217
9218 x_return_status := FND_API.G_RET_STS_SUCCESS;
9219
9220 --
9221 -- populate l_job_header_rec values
9222 --
9223 SELECT wip_job_schedule_interface_s.NEXTVAL INTO l_job_header_rec.group_id FROM dual;
9224 l_job_header_rec.load_type := lc_non_std_update_load_type;
9225 l_job_header_rec.header_id := l_job_header_rec.group_id;
9226 l_job_header_rec.wip_entity_id := p_mtl_txn_dtls.wip_entity_id;
9227 l_job_header_rec.organization_id := p_mtl_txn_dtls.organization_id;
9228
9229 --
9230 -- populate l_job_details_rec values
9231 --
9232 l_job_details_rec.load_type := lc_load_mtl_type;
9233 l_job_details_rec.substitution_type := lc_substitution_del_type;
9234 l_job_details_rec.group_id := l_job_header_rec.group_id;
9235 l_job_details_rec.parent_header_id := l_job_header_rec.group_id;
9236
9237 l_job_details_rec.wip_entity_id := p_mtl_txn_dtls.wip_entity_id;
9238 l_job_details_rec.inventory_item_id_old := p_mtl_txn_dtls.inventory_item_id;
9239 l_job_details_rec.operation_seq_num := p_mtl_txn_dtls.operation_seq_num;
9240
9241 -- Call procedures to insert job header and job details information
9242 -- into wip interface tables
9243 IF ( FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
9244 FND_LOG.STRING( FND_LOG.LEVEL_EVENT,
9245 lc_mod_name||'beforecallinsertjob',
9246 'Just before calling insert_job_header');
9247 END IF;
9248
9249
9250 insert_job_header( p_job_header_rec => l_job_header_rec,
9251 x_return_status => x_return_status );
9252
9253
9254 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
9255 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9256 END IF;
9257
9258
9259 IF ( FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
9260 FND_LOG.STRING( FND_LOG.LEVEL_EVENT,
9261 lc_mod_name||'beforecallinsertjobdtls',
9262 'Just before calling insert_job_details');
9263 END IF;
9264
9265
9266 insert_job_details( p_job_details_rec => l_job_details_rec,
9267 x_return_status => x_return_status );
9268
9269 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
9270 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9271 END IF;
9272
9273
9274
9275 -- Call WIP Mass Load API
9276
9277 IF ( FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
9278 FND_LOG.STRING( FND_LOG.LEVEL_EVENT,
9279 lc_mod_name||'beforecallwipmassload',
9280 'Just before calling WIP_MASSLOAD_PUB.massLoadJobs');
9281 END IF;
9282
9283 BEGIN
9284 WIP_MASSLOAD_PUB.massLoadJobs(p_groupID => l_job_header_rec.group_id,
9285 p_validationLevel => p_validation_level,
9286 p_commitFlag => 0, -- do not commit right away
9287 x_returnStatus => x_return_status,
9288 x_errorMsg => x_msg_data );
9289
9290 If ( ml_error_exists( l_job_header_rec.group_id ) or
9291 x_return_status <> FND_API.G_RET_STS_SUCCESS ) THEN
9292
9293 FND_MESSAGE.SET_NAME('CSD','CSD_MTL_ADD_MASS_LD_FAILURE');
9294 FND_MSG_PUB.ADD;
9295 x_return_status := FND_API.G_RET_STS_ERROR;
9296
9297 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
9298 p_count => x_msg_count,
9299 p_data => x_msg_data);
9300 -- Need to rollback Raise exception -
9301 -- once commit is removed from above call
9302 -- raise FND_API.G_EXC_ERROR;
9303 RETURN;
9304 end if;
9305
9306 --bug#12316893
9307 IF (nvl(fnd_profile.value('MRP_DEBUG'),'Y') = 'N') THEN
9308 WIP_MASS_LOAD_PROCESSOR.Delete_Completed_Records(l_job_header_rec.group_id);
9309 End If;
9310 --bug#12316893
9311
9312 EXCEPTION
9313 WHEN OTHERS THEN
9314 add_wip_interface_errors(l_job_header_rec.group_id,
9315 2 /* 2 = materials */);
9316
9317 -- when rollback for WIP works, remove x_return_status, count_and_get,
9318 -- and return then reinstate raise exception above
9319 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
9320 /*
9321 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
9322 -- Add Unexpected Error to Message List, here SQLERRM is used for
9323 -- getting the error
9324
9325 FND_MSG_PUB.add_exc_msg(p_pkg_name => G_PKG_NAME,
9326 p_procedure_name => lc_api_name );
9327 END IF;
9328 */
9329 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
9330 p_count => x_msg_count,
9331 p_data => x_msg_data);
9332
9333 END;
9334 If p_mtl_txn_dtls.WIP_TRANSACTION_DETAIL_ID is null then
9335 -- query for wip_transaction_detail_id based on other fields
9336 open c_get_wip_txn_detail_id;
9337 fetch c_get_wip_txn_detail_id
9338 into l_wip_transaction_detail_id;
9339 close c_get_wip_txn_detail_id;
9340 else
9341 l_wip_transaction_detail_id := p_mtl_txn_dtls.WIP_TRANSACTION_DETAIL_ID;
9342 end if;
9343
9344 If l_wip_transaction_detail_id is not null then
9345 IF ( FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
9346 FND_LOG.STRING( FND_LOG.LEVEL_EVENT,
9347 lc_mod_name||'beforecallinsertrow',
9348 'Just before calling CSD_WIP_TRANSACTION_DTLS_PKG.Delete_Row');
9349 END IF;
9350
9351 CSD_WIP_TRANSACTION_DTLS_PKG.Delete_Row(
9352 p_WIP_TRANSACTION_DETAIL_ID => l_WIP_TRANSACTION_DETAIL_ID);
9353
9354 end if;
9355
9356 -- Standard check for p_commit
9357 IF FND_API.to_Boolean( p_commit ) THEN
9358 COMMIT WORK;
9359 END IF;
9360
9361 EXCEPTION
9362 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
9363 ROLLBACK to PROCESS_DELETE_MTL_TXN_DTL_PVT ;
9364 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
9365
9366 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
9367 p_count => x_msg_count,
9368 p_data => x_msg_data);
9369
9370 IF ( FND_LOG.LEVEL_EXCEPTION >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
9371 FND_LOG.STRING( FND_LOG.LEVEL_EXCEPTION,
9372 lc_mod_name||'unx_exception',
9373 'G_EXC_UNEXPECTED_ERROR Exception');
9374 END IF;
9375
9376
9377 WHEN FND_API.G_EXC_ERROR THEN
9378 ROLLBACK to PROCESS_DELETE_MTL_TXN_DTL_PVT ;
9379 x_return_status := FND_API.G_RET_STS_ERROR;
9380
9381
9382 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
9383 p_count => x_msg_count,
9384 p_data => x_msg_data);
9385
9386 IF ( FND_LOG.LEVEL_ERROR >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
9387 FND_LOG.STRING( FND_LOG.LEVEL_ERROR,
9388 lc_mod_name||'exc_exception',
9389 'G_EXC_ERROR Exception');
9390 END IF;
9391
9392 WHEN OTHERS THEN
9393 ROLLBACK to PROCESS_DELETE_MTL_TXN_DTL_PVT ;
9394 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
9395
9396 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
9397
9398 -- Add Unexpected Error to Message List, here SQLERRM is used for
9399 -- getting the error
9400
9401 FND_MSG_PUB.add_exc_msg(p_pkg_name => G_PKG_NAME,
9402 p_procedure_name => lc_api_name );
9403 END IF;
9404
9405 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
9406 p_count => x_msg_count,
9407 p_data => x_msg_data);
9408
9409 IF ( FND_LOG.LEVEL_EXCEPTION >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
9410 FND_LOG.STRING( FND_LOG.LEVEL_EXCEPTION,
9411 lc_mod_name||'others_exception',
9412 'OTHERS Exception');
9413 END IF;
9414
9415 END PROCESS_DELETE_MTL_TXN_DTL;
9416
9417
9418 /*
9419 * swai: 12.1.3+ - bug 13449544 (FP bug 13600173)
9420 * Calls new WIP API to determine whether or not an operation is deletable.
9421 * In addition, checks Time Clock to see if user has checked into the operation
9422 * and also checks Material transactions to see if user has transacted for
9423 * Returns 'Y' if WIP API returns true AND there are NO time clock entries AND
9424 * there are no Material transactions. Otherwise, returns 'N' for all
9425 * other cases.
9426 */
9427 FUNCTION is_delete_wip_op_valid
9428 (
9429 p_organization_id IN NUMBER,
9430 p_wip_entity_id IN NUMBER,
9431 p_operation_seq_num IN NUMBER
9432 ) RETURN VARCHAR2
9433 IS
9434 cursor c_get_ro_status is
9435 select csd.status
9436 from csd_repair_job_xref xref, csd_repairs csd
9437 where xref.wip_entity_id = p_wip_entity_id
9438 and xref.repair_line_id = csd.repair_line_id;
9439
9440 cursor c_time_clock_entries_exist is
9441 select 'exists' from csd_time_clock_entries
9442 where wip_entity_id = p_wip_entity_id
9443 and operation_seq_num = p_operation_seq_num
9444 and rownum = 1;
9445
9446 cursor c_mat_txn_exists is
9447 select 'exists'
9448 from WIP_REQUIREMENT_OPERATIONS wip
9449 where wip.wip_entity_id = p_wip_entity_id
9450 and wip.operation_seq_num = p_operation_seq_num
9451 and wip.quantity_issued > 0
9452 and rownum = 1;
9453
9454
9455 lc_mod_name CONSTANT VARCHAR2(2000) := 'csd.plsql.csd_hv_wip_job_pvt.is_delete_wip_op_valid';
9456 lc_valid CONSTANT VARCHAR2(1) := 'Y';
9457 lc_not_valid CONSTANT VARCHAR2(1) := 'N';
9458 l_return_status VARCHAR2(1);
9459 l_error_message VARCHAR2(2000);
9460 l_time_clock_entries_exist VARCHAR(10);
9461 l_mat_txn_exists VARCHAR2(10);
9462 l_ro_status VARCHAR2(1);
9463
9464 BEGIN
9465 open c_get_ro_status;
9466 fetch c_get_ro_status
9467 into l_ro_status;
9468 close c_get_ro_status;
9469
9470 IF (l_ro_status <> 'O') THEN
9471 IF ( FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
9472 FND_LOG.STRING( FND_LOG.LEVEL_PROCEDURE,
9473 lc_mod_name||'.begin',
9474 'Repair order is not open.' );
9475 END IF;
9476 return lc_not_valid;
9477 END IF;
9478
9479 IF ( FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
9480 FND_LOG.STRING( FND_LOG.LEVEL_PROCEDURE,
9481 lc_mod_name||'.begin',
9482 'Entering procedure is_delete_wip_op_valid' );
9483 END IF;
9484
9485 WIP_OPERATIONS_PKG.Valid_Op_Delete(p_organization_id => p_organization_id,
9486 p_wip_entity_id => p_wip_entity_id,
9487 p_operation_seq_num => p_operation_seq_num,
9488 x_return_status => l_return_status,
9489 x_error_message => l_error_message);
9490
9491 IF (l_return_status = FND_API.G_RET_STS_SUCCESS ) THEN
9492 IF ( FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
9493 FND_LOG.STRING( FND_LOG.LEVEL_PROCEDURE,
9494 lc_mod_name,
9495 'WIP_OPERATIONS_PKG.Valid_Op_Delete returned success.' );
9496 END IF;
9497
9498 open c_time_clock_entries_exist;
9499 fetch c_time_clock_entries_exist
9500 into l_time_clock_entries_exist;
9501 close c_time_clock_entries_exist;
9502
9503 IF (l_time_clock_entries_exist is null) THEN
9504 IF ( FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
9505 FND_LOG.STRING( FND_LOG.LEVEL_PROCEDURE,
9506 lc_mod_name,
9507 'No time clock entries exist. Continuing...' );
9508 END IF;
9509
9510 open c_mat_txn_exists;
9511 fetch c_mat_txn_exists
9512 into l_mat_txn_exists;
9513 close c_mat_txn_exists;
9514
9515 if (l_mat_txn_exists is not null) then
9516 IF ( FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
9517 FND_LOG.STRING( FND_LOG.LEVEL_PROCEDURE,
9518 lc_mod_name,
9519 'Materials have been issued for this operation. Returning N' );
9520 END IF;
9521 return lc_not_valid;
9522 end if;
9523
9524 return lc_valid;
9525
9526 ELSE
9527 IF ( FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
9528 FND_LOG.STRING( FND_LOG.LEVEL_PROCEDURE,
9529 lc_mod_name,
9530 'Time clock entries exist. Returning N' );
9531 END IF;
9532 return lc_not_valid;
9533 END IF;
9534 END IF;
9535
9536 IF ( FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
9537 FND_LOG.STRING( FND_LOG.LEVEL_PROCEDURE,
9538 lc_mod_name,
9539 'WIP_OPERATIONS_PKG.Valid_Op_Delete returned non-success value: ' || l_return_status );
9540 FND_LOG.STRING( FND_LOG.LEVEL_PROCEDURE,
9541 lc_mod_name,
9542 'WIP_OPERATIONS_PKG.Valid_Op_Delete returned error message: ' || l_error_message );
9543 END IF;
9544 return lc_not_valid;
9545
9546 EXCEPTION
9547 WHEN OTHERS THEN
9548 IF ( FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
9549 FND_LOG.STRING( FND_LOG.LEVEL_PROCEDURE,
9550 lc_mod_name,
9551 'WIP_OPERATIONS_PKG.Valid_Op_Delete threw exception');
9552 END IF;
9553
9554 return lc_not_valid;
9555
9556 END is_delete_wip_op_valid;
9557
9558 /* swai: 12.1.3+ - bug 13449544 (FP bug 13600173)
9559 * Delete an existing operation and its associated requirements.
9560 * The following fields in p_op_dtls are expected to be filled out:
9561 * wip_entity_id
9562 * organization_id
9563 * operation_seq_num
9564 */
9565 PROCEDURE process_delete_op_dtl
9566 (
9567 p_api_version_number IN NUMBER,
9568 p_init_msg_list IN VARCHAR2 ,
9569 p_commit IN VARCHAR2 ,
9570 p_validation_level IN NUMBER ,
9571 x_return_status OUT NOCOPY VARCHAR2,
9572 x_msg_count OUT NOCOPY NUMBER,
9573 x_msg_data OUT NOCOPY VARCHAR2,
9574 p_op_dtls IN OP_DTLS_REC_TYPE
9575 )
9576 IS
9577 lc_api_name CONSTANT VARCHAR2(30) := 'PROCESS_DELETE_OP_DTL';
9578 lc_api_version_number CONSTANT NUMBER := 1.0;
9579
9580 -- constants used for FND_LOG debug messages
9581 lc_mod_name CONSTANT VARCHAR2(2000) := 'csd.plsql.csd_hv_wip_job_pvt.process_delete_op_dtl';
9582
9583
9584 l_return_status VARCHAR2(1);
9585 l_error_message VARCHAR2(2000);
9586 l_first_operation NUMBER;
9587 l_required_quantity NUMBER;
9588 l_quantity_issued NUMBER;
9589 l_txn_detail_id NUMBER;
9590 l_obj_ver_num NUMBER;
9591
9592 cursor c_get_wip_txn_details is
9593 select wip_transaction_detail_id, inventory_item_id, resource_seq_num
9594 from csd_wip_transaction_details
9595 where wip_entity_id = p_op_dtls.wip_entity_id
9596 and operation_seq_num = p_op_dtls.operation_seq_num;
9597
9598 cursor c_get_material_req_details (p_operation_seq_num NUMBER,
9599 p_inventory_item_id NUMBER) is
9600 select csd.wip_transaction_detail_id,
9601 csd.object_version_number,
9602 wip.required_quantity,
9603 nvl(wip.quantity_issued, 0)
9604 from WIP_REQUIREMENT_OPERATIONS wip,
9605 CSD_WIP_TRANSACTION_DETAILS csd
9606 where wip.wip_entity_id = p_op_dtls.wip_entity_id
9607 and wip.operation_seq_num = p_operation_seq_num
9608 and wip.inventory_item_id = p_inventory_item_id
9609 and wip.wip_entity_id = csd.wip_entity_id
9610 and wip.operation_seq_num = csd.operation_seq_num
9611 and wip.inventory_item_id = csd.inventory_item_id;
9612
9613 cursor c_get_first_operation is
9614 select min(operation_seq_num)
9615 from wip_operations
9616 where wip_entity_id = p_op_dtls.wip_entity_id;
9617
9618 BEGIN
9619
9620 IF ( FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
9621 FND_LOG.STRING( FND_LOG.LEVEL_PROCEDURE,
9622 lc_mod_name||'begin',
9623 'Entering private API process_delete_op_dtl' );
9624 END IF;
9625
9626 -- Standard Start of API savepoint
9627 SAVEPOINT PROCESS_DELETE_op_dtl_PVT;
9628
9629 -- Standard call to check for call compatibility.
9630 IF NOT FND_API.Compatible_API_Call
9631 (lc_api_version_number,
9632 p_api_version_number,
9633 lc_api_name,
9634 G_PKG_NAME)
9635 THEN
9636 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9637 END IF;
9638
9639 -- Initialize message list if p_init_msg_list is set to TRUE
9640 IF FND_API.to_boolean(p_init_msg_list) THEN
9641 FND_MSG_PUB.initialize;
9642 END IF;
9643
9644
9645 x_return_status := FND_API.G_RET_STS_SUCCESS;
9646
9647 IF ( FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
9648 FND_LOG.STRING( FND_LOG.LEVEL_EVENT,
9649 lc_mod_name||'beforecallinsertjobdtls',
9650 'Just before calling WIP_OPERATIONS_PKG.Delete_Operation');
9651 END IF;
9652
9653
9654 WIP_OPERATIONS_PKG.Delete_Operation(p_organization_id => p_op_dtls.organization_id,
9655 p_wip_entity_id => p_op_dtls.wip_entity_id,
9656 p_operation_seq_num => p_op_dtls.operation_seq_num,
9657 x_return_status => l_return_status,
9658 x_error_message => l_error_message);
9659
9660 If (x_return_status <> FND_API.G_RET_STS_SUCCESS ) THEN
9661 IF ( FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
9662 FND_LOG.STRING( FND_LOG.LEVEL_EVENT,
9663 lc_mod_name,
9664 'Error during WIP_OPERATIONS_PKG.Delete_Operation: ' || l_error_message);
9665 END IF;
9666
9667 fnd_message.set_name('FND', 'FND_GENERIC_MESSAGE');
9668 fnd_message.set_token('MESSAGE', l_error_message);
9669 fnd_msg_pub.add;
9670 x_return_status := FND_API.G_RET_STS_ERROR;
9671
9672 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
9673 p_count => x_msg_count,
9674 p_data => x_msg_data);
9675 RETURN;
9676 end if;
9677
9678 /**
9679 * If we get this far, then WIP deletion was successful.
9680 * Now we need to delete any associated rows in csd_wip_transaction_details
9681 **/
9682
9683 -- Get the first operation seq number for the job, just in case we need it
9684 -- during looping through the wip txn details.
9685 l_first_operation := null;
9686 open c_get_first_operation;
9687 fetch c_get_first_operation into l_first_operation;
9688 close c_get_first_operation;
9689
9690 -- query for all wip_transaction_detail_ids that are associated with
9691 -- the deleted operation.
9692 FOR wip_txn_detail_rec in c_get_wip_txn_details
9693 LOOP
9694
9695 /***** MATERIAL REQUIREMENT *****/
9696 -- if the row being deleted is a material line, then we need to
9697 -- update the qty on the first operation, if one exists for it.
9698 if ((wip_txn_detail_rec.inventory_item_id is not null) and
9699 (wip_txn_detail_rec.resource_seq_num is null)) then
9700 -- If there is an existing material req on the first
9701 -- operation, then the material requirement quantities
9702 -- will get consolidated in WIP. So, we need to update
9703 -- Depot table as well.
9704 -- qty to transact = required_qty - transacted_qty
9705
9706 if (l_first_operation is not null) then
9707 l_txn_detail_id := null;
9708 l_required_quantity := null;
9709 l_quantity_issued := null;
9710 open c_get_material_req_details(l_first_operation, wip_txn_detail_rec.inventory_item_id);
9711 fetch c_get_material_req_details
9712 into l_txn_detail_id, l_obj_ver_num,
9713 l_required_quantity, l_quantity_issued;
9714 close c_get_material_req_details;
9715 if (l_required_quantity is not null) then
9716 IF ( FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
9717 FND_LOG.STRING( FND_LOG.LEVEL_EVENT,
9718 lc_mod_name,
9719 'Just before calling CSD_WIP_TRANSACTION_DTLS_PKG.Update_Row');
9720 END IF;
9721
9722 -- update the material transaction qty for the first operation on the job
9723 CSD_WIP_TRANSACTION_DTLS_PKG.Update_Row (
9724 p_WIP_TRANSACTION_DETAIL_ID => l_txn_detail_id
9725 ,p_CREATED_BY => null
9726 ,p_CREATION_DATE => null
9727 ,p_LAST_UPDATED_BY => fnd_global.user_id
9728 ,p_LAST_UPDATE_DATE => sysdate
9729 ,p_LAST_UPDATE_LOGIN => fnd_global.login_id
9730 ,p_INVENTORY_ITEM_ID => null
9731 ,p_WIP_ENTITY_ID => null
9732 ,p_OPERATION_SEQ_NUM => null
9733 ,p_RESOURCE_SEQ_NUM => null
9734 ,p_employee_id => null
9735 ,p_TRANSACTION_QUANTITY => l_required_quantity - l_quantity_issued
9736 ,p_TRANSACTION_UOM => null
9737 ,p_SERIAL_NUMBER => null
9738 ,p_REVISION => null
9739 ,p_REASON_ID => null
9740 ,p_BACKFLUSH_FLAG => null
9741 ,p_COUNT_POINT_TYPE => null
9742 ,p_DEPARTMENT_ID => null
9743 ,p_DESCRIPTION => null
9744 ,p_FIRST_UNIT_COMPLETION_DATE => null
9745 ,p_FIRST_UNIT_START_DATE => null
9746 ,p_LAST_UNIT_COMPLETION_DATE => null
9747 ,p_LAST_UNIT_START_DATE => null
9748 ,p_MINIMUM_TRANSFER_QUANTITY => null
9749 ,p_STANDARD_OPERATION_ID => null
9750 ,p_OBJECT_VERSION_NUMBER => l_obj_ver_num + 1
9751 ,p_ATTRIBUTE_CATEGORY => null
9752 ,p_ATTRIBUTE1 => null
9753 ,p_ATTRIBUTE2 => null
9754 ,p_ATTRIBUTE3 => null
9755 ,p_ATTRIBUTE4 => null
9756 ,p_ATTRIBUTE5 => null
9757 ,p_ATTRIBUTE6 => null
9758 ,p_ATTRIBUTE7 => null
9759 ,p_ATTRIBUTE8 => null
9760 ,p_ATTRIBUTE9 => null
9761 ,p_ATTRIBUTE10 => null
9762 ,p_ATTRIBUTE11 => null
9763 ,p_ATTRIBUTE12 => null
9764 ,p_ATTRIBUTE13 => null
9765 ,p_ATTRIBUTE14 => null
9766 ,p_ATTRIBUTE15 => null
9767 ,p_CREATE_RO_FLAG => null -- bug#13657187 auto create ro, parent ro
9768 );
9769 end if;
9770 end if;
9771 end if; -- if it is a material
9772
9773 /** DELETE CSD_WIP_TRANSACTION_DETAILS ROW for the deleted operation **/
9774 IF ( FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
9775 FND_LOG.STRING( FND_LOG.LEVEL_EVENT,
9776 lc_mod_name,
9777 'Just before calling CSD_WIP_TRANSACTION_DTLS_PKG.Delete_Row');
9778 END IF;
9779 -- remove the row in CSD table.
9780 -- should have been taken care of in WIP Delete_Operation API
9781 CSD_WIP_TRANSACTION_DTLS_PKG.Delete_Row(
9782 p_WIP_TRANSACTION_DETAIL_ID => wip_txn_detail_rec.WIP_TRANSACTION_DETAIL_ID);
9783
9784 END LOOP;
9785
9786 -- Standard check for p_commit
9787 IF FND_API.to_Boolean( p_commit ) THEN
9788 COMMIT WORK;
9789 END IF;
9790
9791 EXCEPTION
9792 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
9793 ROLLBACK to PROCESS_DELETE_OP_DTL_PVT ;
9794 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
9795
9796 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
9797 p_count => x_msg_count,
9798 p_data => x_msg_data);
9799
9800 IF ( FND_LOG.LEVEL_EXCEPTION >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
9801 FND_LOG.STRING( FND_LOG.LEVEL_EXCEPTION,
9802 lc_mod_name||'unx_exception',
9803 'G_EXC_UNEXPECTED_ERROR Exception');
9804 END IF;
9805
9806
9807 WHEN FND_API.G_EXC_ERROR THEN
9808 ROLLBACK to PROCESS_DELETE_op_dtl_PVT ;
9809 x_return_status := FND_API.G_RET_STS_ERROR;
9810
9811
9812 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
9813 p_count => x_msg_count,
9814 p_data => x_msg_data);
9815
9816 IF ( FND_LOG.LEVEL_ERROR >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
9817 FND_LOG.STRING( FND_LOG.LEVEL_ERROR,
9818 lc_mod_name||'exc_exception',
9819 'G_EXC_ERROR Exception');
9820 END IF;
9821
9822 WHEN OTHERS THEN
9823 ROLLBACK to PROCESS_DELETE_op_dtl_PVT ;
9824 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
9825
9826 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
9827
9828 -- Add Unexpected Error to Message List, here SQLERRM is used for
9829 -- getting the error
9830
9831 FND_MSG_PUB.add_exc_msg(p_pkg_name => G_PKG_NAME,
9832 p_procedure_name => lc_api_name );
9833 END IF;
9834
9835 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
9836 p_count => x_msg_count,
9837 p_data => x_msg_data);
9838
9839 IF ( FND_LOG.LEVEL_EXCEPTION >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
9840 FND_LOG.STRING( FND_LOG.LEVEL_EXCEPTION,
9841 lc_mod_name||'others_exception',
9842 'OTHERS Exception');
9843 END IF;
9844
9845 END PROCESS_DELETE_OP_DTL;
9846
9847 -- swai: bug 13820264, FP of bug#13797285, subhat
9848 PROCEDURE update_mat_issue_quantities
9849 (
9850 p_api_version_number IN NUMBER,
9851 p_init_msg_list IN VARCHAR2 ,
9852 p_commit IN VARCHAR2 ,
9853 p_validation_level IN NUMBER ,
9854 x_return_status OUT NOCOPY VARCHAR2,
9855 x_msg_count OUT NOCOPY NUMBER,
9856 x_msg_data OUT NOCOPY VARCHAR2,
9857 p_repair_line_id IN NUMBER DEFAULT NULL,
9858 p_wip_entity_id IN NUMBER DEFAULT NULL,
9859 p_wip_transaction_detail_id IN NUMBER DEFAULT NULL,
9860 p_transaction_type_id IN NUMBER DEFAULT NULL,
9861 p_quantity IN NUMBER DEFAULT NULL,
9862 p_exclude_closed_jobs IN VARCHAR2 DEFAULT 'Y',
9863 p_transaction_date_start IN DATE DEFAULT NULL,
9864 p_transaction_date_end IN DATE DEFAULT NULL
9865 )
9866 IS
9867 lc_api_name CONSTANT VARCHAR2(30) := 'PROCESS_DELETE_OP_DTL';
9868 lc_api_version_number CONSTANT NUMBER := 1.0;
9869 lc_mod_name CONSTANT VARCHAR2(60) := 'csd.plsql.csd_hv_wip_job_pvt.update_mat_issue_quantities';
9870 l_transaction_type_ids JTF_NUMBER_TABLE := JTF_NUMBER_TABLE();
9871 l_transaction_quantities JTF_NUMBER_TABLE := JTF_NUMBER_TABLE();
9872 l_wip_transaction_detail_ids JTF_NUMBER_TABLE := JTF_NUMBER_TABLE();
9873
9874 l_all_jobs sys_refcursor;
9875
9876
9877 BEGIN
9878
9879 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level )
9880 THEN
9881 fnd_log.string(fnd_log.level_statement,lc_mod_name||'begin','Entering private API' );
9882 END IF;
9883
9884 -- Standard call to check for call compatibility.
9885 IF NOT fnd_api.Compatible_API_Call
9886 (lc_api_version_number,
9887 p_api_version_number,
9888 lc_api_name,
9889 G_PKG_NAME)
9890 THEN
9891 RAISE fnd_api.g_exc_unexpected_error;
9892 END IF;
9893
9894 -- Initialize message list if p_init_msg_list is set to TRUE
9895 IF fnd_api.to_boolean(p_init_msg_list)
9896 THEN
9897 fnd_msg_pub.initialize;
9898 END IF;
9899
9900 x_return_status := fnd_api.g_ret_sts_success;
9901
9902 -- dump the input parameters.
9903
9904 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level )
9905 THEN
9906 fnd_log.string(fnd_log.level_statement,lc_mod_name,'API called with below parameters');
9907 fnd_log.string(fnd_log.level_statement,lc_mod_name,'p_repair_line_id => '||p_repair_line_id);
9908 fnd_log.string(fnd_log.level_statement,lc_mod_name,'p_wip_entity_id => '||p_wip_entity_id);
9909 fnd_log.string(fnd_log.level_statement,lc_mod_name,'p_wip_transaction_detail_id => '||p_wip_transaction_detail_id);
9910 fnd_log.string(fnd_log.level_statement,lc_mod_name,'p_transaction_type_id => '||p_transaction_type_id);
9911 fnd_log.string(fnd_log.level_statement,lc_mod_name,'p_quantity => '||p_quantity);
9912 fnd_log.string(fnd_log.level_statement,lc_mod_name,'p_exclude_closed_jobs => '||p_exclude_closed_jobs);
9913 fnd_log.string(fnd_log.level_statement,lc_mod_name,'p_transaction_date_start => '||p_transaction_date_start);
9914 fnd_log.string(fnd_log.level_statement,lc_mod_name,'p_transaction_date_end => '||p_transaction_date_start);
9915 END IF;
9916
9917 -- start processing.
9918 -- case#1. Best case. The wip transaction detail id and quantity and transaction type are provided.
9919 -- the best case cannot be probably met at this point since, HVR doesn't guarantee that rows will be
9920 -- present in the CSD table.
9921 -- when fnd_api.g_valid_level_full is passed in then we also verify if the total transacted material is
9922 -- greater than the quantity_issued.
9923
9924 IF p_wip_transaction_detail_id IS NOT NULL AND p_transaction_type_id IS NOT NULL AND p_quantity IS NOT NULL
9925 THEN
9926 IF p_validation_level = fnd_api.g_valid_level_none
9927 THEN
9928 IF p_transaction_type_id = 35
9929 THEN
9930 UPDATE csd_wip_transaction_details SET quantity_issued = (NVL(quantity_issued,0) + p_quantity)
9931 WHERE wip_transaction_detail_id = p_wip_transaction_detail_id;
9932
9933 ELSIF p_transaction_type_id = 43
9934 THEN
9935 UPDATE csd_wip_transaction_details SET quantity_recovered = (NVL(quantity_recovered,0) + p_quantity)
9936 WHERE wip_transaction_detail_id = p_wip_transaction_detail_id;
9937 END IF;
9938 ELSE
9939 IF p_transaction_type_id = 35
9940 THEN
9941 UPDATE csd_wip_transaction_details cwt SET cwt.quantity_issued = (NVL(cwt.quantity_issued,0) + p_quantity)
9942 WHERE cwt.wip_transaction_detail_id = p_wip_transaction_detail_id
9943 AND EXISTS (SELECT SUM(transaction_quantity)
9944 FROM mtl_material_transactions mmt,wip_requirement_operations wro
9945 WHERE mmt.inventory_item_id = cwt.inventory_item_id
9946 AND wro.wip_entity_id = cwt.wip_entity_id
9947 AND wro.inventory_item_id = cwt.inventory_item_id
9948 AND wro.organization_id = mmt.organization_id
9949 AND mmt.transaction_source_id = wro.wip_entity_id
9950 AND mmt.operation_seq_num = wro.operation_seq_num
9951 GROUP BY wro.inventory_item_id
9952 HAVING SUM(transaction_quantity) >= NVL(cwt.quantity_issued,0)+ p_quantity
9953 );
9954
9955
9956 ELSIF p_transaction_type_id = 43
9957 THEN
9958 UPDATE csd_wip_transaction_details cwt SET cwt.quantity_recovered = (NVL(cwt.quantity_recovered,0) + p_quantity)
9959 WHERE wip_transaction_detail_id = p_wip_transaction_detail_id
9960 AND EXISTS (SELECT SUM(transaction_quantity)
9961 FROM mtl_material_transactions mmt,wip_requirement_operations wro
9962 WHERE mmt.inventory_item_id = cwt.inventory_item_id
9963 AND wro.wip_entity_id = cwt.wip_entity_id
9964 AND wro.inventory_item_id = cwt.inventory_item_id
9965 AND wro.organization_id = mmt.organization_id
9966 AND mmt.transaction_source_id = wro.wip_entity_id
9967 AND mmt.operation_seq_num = wro.operation_seq_num
9968 GROUP BY wro.inventory_item_id
9969 HAVING SUM(transaction_quantity) >= NVL(cwt.quantity_recovered,0)+ p_quantity
9970 );
9971 END IF;
9972 END IF;
9973
9974 -- case#2.
9975 -- just keeping this place holder in case we get a case where we will have only p_wip_transaction_id
9976 -- not used now!.
9977 ELSIF p_wip_transaction_detail_id IS NOT NULL
9978 THEN
9979 NULL;
9980
9981 -- case#3. WIP entity id is provided.
9982 -- the second best case now!
9983 -- first we will synch up csd_wip_transaction_details with wip_requirement_operations.
9984 ELSIF p_wip_entity_id IS NOT NULL
9985 THEN
9986 handle_missing_mat_rqmts(p_wip_entity_id => p_wip_entity_id);
9987
9988 SELECT cwt.wip_transaction_detail_id,mmt.transaction_type_id,sum(mmt.transaction_quantity)
9989 BULK COLLECT INTO l_wip_transaction_detail_ids,l_transaction_type_ids,l_transaction_quantities
9990 FROM mtl_material_transactions mmt, wip_requirement_operations wro,
9991 csd_wip_transaction_details cwt
9992 WHERE cwt.wip_entity_id = p_wip_entity_id
9993 AND cwt.wip_entity_id = wro.wip_entity_id
9994 AND cwt.inventory_item_id = wro.inventory_item_id
9995 AND cwt.operation_seq_num = wro.operation_seq_num
9996 AND wro.inventory_item_id = mmt.inventory_item_id
9997 AND mmt.organization_id = mmt.organization_id
9998 AND mmt.transaction_source_id = wro.wip_entity_id
9999 AND mmt.operation_seq_num = wro.operation_seq_num
10000 GROUP BY cwt.wip_transaction_detail_id,mmt.transaction_type_id;
10001
10002
10003 FOR i IN 1 ..l_wip_transaction_detail_ids.COUNT
10004 LOOP
10005 IF l_transaction_type_ids(i) = 35
10006 THEN
10007 UPDATE csd_wip_transaction_details SET quantity_issued = l_transaction_quantities(i)
10008 WHERE wip_transaction_detail_id = l_wip_transaction_detail_ids(i);
10009
10010 ELSIF l_transaction_type_ids(i) = 43
10011 THEN
10012 UPDATE csd_wip_transaction_details SET quantity_recovered = l_transaction_quantities(i)
10013 WHERE wip_transaction_detail_id = l_wip_transaction_detail_ids(i);
10014 END IF;
10015 END LOOP;
10016
10017
10018 -- case#4. Process everything under the repair order.
10019 ELSIF p_repair_line_id IS NOT NULL
10020 THEN
10021 IF p_exclude_closed_jobs = 'N'
10022 THEN
10023 handle_missing_mat_rqmts(p_repair_line_id => p_repair_line_id);
10024
10025 SELECT cwt.wip_transaction_detail_id,mmt.transaction_type_id,sum(mmt.transaction_quantity)
10026 BULK COLLECT INTO l_wip_transaction_detail_ids,l_transaction_type_ids,l_transaction_quantities
10027 FROM mtl_material_transactions mmt, wip_requirement_operations wro,
10028 csd_wip_transaction_details cwt,csd_repair_job_xref crj
10029 WHERE crj.repair_line_id = p_repair_line_id
10030 AND cwt.wip_entity_id = crj.wip_entity_id
10031 AND cwt.wip_entity_id = wro.wip_entity_id
10032 AND cwt.inventory_item_id = wro.inventory_item_id
10033 AND cwt.operation_seq_num = wro.operation_seq_num
10034 AND wro.inventory_item_id = mmt.inventory_item_id
10035 AND wro.organization_id = mmt.organization_id
10036 AND mmt.transaction_source_id = wro.wip_entity_id
10037 AND mmt.operation_seq_num = wro.operation_seq_num
10038 GROUP BY cwt.wip_transaction_detail_id,mmt.transaction_type_id;
10039
10040 FOR i IN 1 ..l_wip_transaction_detail_ids.COUNT
10041 LOOP
10042 IF l_transaction_type_ids(i) = 35
10043 THEN
10044 UPDATE csd_wip_transaction_details SET quantity_issued = l_transaction_quantities(i)
10045 WHERE wip_transaction_detail_id = l_wip_transaction_detail_ids(i);
10046
10047 ELSIF l_transaction_type_ids(i) = 43
10048 THEN
10049 UPDATE csd_wip_transaction_details SET quantity_recovered = l_transaction_quantities(i)
10050 WHERE wip_transaction_detail_id = l_wip_transaction_detail_ids(i);
10051 END IF;
10052 END LOOP;
10053
10054
10055 ELSE
10056 handle_missing_mat_rqmts(p_repair_line_id => p_repair_line_id);
10057
10058 SELECT cwt.wip_transaction_detail_id,mmt.transaction_type_id,sum(mmt.transaction_quantity)
10059 BULK COLLECT INTO l_wip_transaction_detail_ids,l_transaction_type_ids,l_transaction_quantities
10060 from mtl_material_transactions mmt, wip_requirement_operations wro,
10061 csd_wip_transaction_details cwt,csd_repair_job_xref crj,wip_discrete_jobs wdj
10062 WHERE crj.repair_line_id = p_repair_line_id
10063 AND cwt.wip_entity_id = crj.wip_entity_id
10064 AND cwt.wip_entity_id = wro.wip_entity_id
10065 AND cwt.inventory_item_id = wro.inventory_item_id
10066 AND cwt.operation_seq_num = wro.operation_seq_num
10067 AND wro.inventory_item_id = mmt.inventory_item_id
10068 AND wro.organization_id = mmt.organization_id
10069 AND mmt.transaction_source_id = wro.wip_entity_id
10070 AND mmt.operation_seq_num = wro.operation_seq_num
10071 AND cwt.wip_entity_id = wdj.wip_entity_id
10072 AND wdj.status_type NOT IN (12,4,5)
10073 GROUP BY cwt.wip_transaction_detail_id,mmt.transaction_type_id;
10074
10075 FOR i IN 1 ..l_wip_transaction_detail_ids.COUNT
10076 LOOP
10077 IF l_transaction_type_ids(i) = 35
10078 THEN
10079 UPDATE csd_wip_transaction_details SET quantity_issued = l_transaction_quantities(i)
10080 WHERE wip_transaction_detail_id = l_wip_transaction_detail_ids(i);
10081
10082 ELSIF l_transaction_type_ids(i) = 43
10083 THEN
10084 UPDATE csd_wip_transaction_details SET quantity_recovered = l_transaction_quantities(i)
10085 WHERE wip_transaction_detail_id = l_wip_transaction_detail_ids(i);
10086 END IF;
10087 END LOOP;
10088
10089 END IF;
10090
10091 -- case 5. Update all the possible repair orders.
10092 ELSE
10093 handle_missing_mat_rqmts(p_start_txn_date => p_transaction_date_start,
10094 p_end_txn_date => NVL(p_transaction_date_end,SYSDATE)
10095 );
10096 IF p_transaction_date_start IS NULL
10097 THEN
10098 IF p_exclude_closed_jobs = 'N'
10099 THEN
10100 OPEN l_all_jobs FOR
10101 SELECT cwt.wip_transaction_detail_id,mmt.transaction_type_id,sum(mmt.transaction_quantity)
10102 FROM mtl_material_transactions mmt, wip_requirement_operations wro,
10103 csd_wip_transaction_details cwt
10104 WHERE cwt.wip_entity_id = wro.wip_entity_id
10105 AND cwt.inventory_item_id = wro.inventory_item_id
10106 AND cwt.operation_seq_num = wro.operation_seq_num
10107 AND wro.inventory_item_id = mmt.inventory_item_id
10108 AND wro.organization_id = mmt.organization_id
10109 AND mmt.transaction_source_id = wro.wip_entity_id
10110 AND mmt.operation_seq_num = wro.operation_seq_num
10111 GROUP BY cwt.wip_transaction_detail_id,mmt.transaction_type_id;
10112 LOOP
10113 FETCH l_all_jobs BULK COLLECT INTO l_wip_transaction_detail_ids,l_transaction_type_ids,l_transaction_quantities LIMIT 500;
10114 FOR i IN 1 ..l_wip_transaction_detail_ids.COUNT
10115 LOOP
10116 IF l_transaction_type_ids(i) = 35
10117 THEN
10118 UPDATE csd_wip_transaction_details SET quantity_issued = l_transaction_quantities(i)
10119 WHERE wip_transaction_detail_id = l_wip_transaction_detail_ids(i);
10120
10121 ELSIF l_transaction_type_ids(i) = 43
10122 THEN
10123 UPDATE csd_wip_transaction_details SET quantity_recovered = l_transaction_quantities(i)
10124 WHERE wip_transaction_detail_id = l_wip_transaction_detail_ids(i);
10125 END IF;
10126 END LOOP;
10127 EXIT WHEN l_all_jobs%NOTFOUND;
10128 END LOOP;
10129 CLOSE l_all_jobs;
10130 ELSE
10131 OPEN l_all_jobs FOR
10132 SELECT cwt.wip_transaction_detail_id,mmt.transaction_type_id,sum(mmt.transaction_quantity)
10133 FROM mtl_material_transactions mmt, wip_requirement_operations wro,
10134 csd_wip_transaction_details cwt,wip_discrete_jobs wdj
10135 WHERE cwt.wip_entity_id = wro.wip_entity_id
10136 AND cwt.inventory_item_id = wro.inventory_item_id
10137 AND cwt.operation_seq_num = wro.operation_seq_num
10138 AND wro.inventory_item_id = mmt.inventory_item_id
10139 AND wro.organization_id = mmt.organization_id
10140 AND mmt.transaction_source_id = wro.wip_entity_id
10141 AND mmt.operation_seq_num = wro.operation_seq_num
10142 AND cwt.wip_entity_id = wdj.wip_entity_id
10143 AND wdj.status_type NOT IN (12,4,5)
10144 GROUP BY cwt.wip_transaction_detail_id,mmt.transaction_type_id;
10145 LOOP
10146 FETCH l_all_jobs BULK COLLECT INTO l_wip_transaction_detail_ids,l_transaction_type_ids,l_transaction_quantities LIMIT 500;
10147 FOR i IN 1 ..l_wip_transaction_detail_ids.COUNT
10148 LOOP
10149 IF l_transaction_type_ids(i) = 35
10150 THEN
10151 UPDATE csd_wip_transaction_details SET quantity_issued = l_transaction_quantities(i)
10152 WHERE wip_transaction_detail_id = l_wip_transaction_detail_ids(i);
10153
10154 ELSIF l_transaction_type_ids(i) = 43
10155 THEN
10156 UPDATE csd_wip_transaction_details SET quantity_recovered = l_transaction_quantities(i)
10157 WHERE wip_transaction_detail_id = l_wip_transaction_detail_ids(i);
10158 END IF;
10159 END LOOP;
10160 EXIT WHEN l_all_jobs%NOTFOUND;
10161 END LOOP;
10162 CLOSE l_all_jobs;
10163 END IF;
10164
10165 ELSE
10166 IF p_exclude_closed_jobs = 'N'
10167 THEN
10168 OPEN l_all_jobs FOR
10169 SELECT cwt.wip_transaction_detail_id,mmt.transaction_type_id,sum(mmt.transaction_quantity)
10170 FROM mtl_material_transactions mmt, wip_requirement_operations wro,
10171 csd_wip_transaction_details cwt,wip_discrete_jobs wdj
10172 WHERE cwt.wip_entity_id = wro.wip_entity_id
10173 AND cwt.inventory_item_id = wro.inventory_item_id
10174 AND cwt.operation_seq_num = wro.operation_seq_num
10175 AND wro.inventory_item_id = mmt.inventory_item_id
10176 AND mmt.organization_id = mmt.organization_id
10177 AND mmt.transaction_source_id = wro.wip_entity_id
10178 AND cwt.wip_entity_id = wdj.wip_entity_id
10179 AND mmt.operation_seq_num = wro.operation_seq_num
10180 AND TRUNC(mmt.transaction_date) BETWEEN trunc(p_transaction_date_start) AND trunc(NVL(p_transaction_date_end,SYSDATE))
10181 GROUP BY cwt.wip_transaction_detail_id,mmt.transaction_type_id;
10182 LOOP
10183 FETCH l_all_jobs BULK COLLECT INTO l_wip_transaction_detail_ids,l_transaction_type_ids,l_transaction_quantities LIMIT 500;
10184 FOR i IN 1 ..l_wip_transaction_detail_ids.COUNT
10185 LOOP
10186 IF l_transaction_type_ids(i) = 35
10187 THEN
10188 UPDATE csd_wip_transaction_details SET quantity_issued = l_transaction_quantities(i)
10189 WHERE wip_transaction_detail_id = l_wip_transaction_detail_ids(i);
10190
10191 ELSIF l_transaction_type_ids(i) = 43
10192 THEN
10193 UPDATE csd_wip_transaction_details SET quantity_recovered = l_transaction_quantities(i)
10194 WHERE wip_transaction_detail_id = l_wip_transaction_detail_ids(i);
10195 END IF;
10196 END LOOP;
10197 EXIT WHEN l_all_jobs%NOTFOUND;
10198 END LOOP;
10199 CLOSE l_all_jobs;
10200
10201 ELSE
10202 OPEN l_all_jobs FOR
10203 SELECT cwt.wip_transaction_detail_id,mmt.transaction_type_id,sum(mmt.transaction_quantity)
10204 FROM mtl_material_transactions mmt, wip_requirement_operations wro,
10205 csd_wip_transaction_details cwt,wip_discrete_jobs wdj
10206 WHERE cwt.wip_entity_id = wro.wip_entity_id
10207 AND cwt.inventory_item_id = wro.inventory_item_id
10208 AND cwt.operation_seq_num = wro.operation_seq_num
10209 AND wro.inventory_item_id = mmt.inventory_item_id
10210 AND wro.organization_id = mmt.organization_id
10211 AND mmt.transaction_source_id = wro.wip_entity_id
10212 AND mmt.operation_seq_num = wro.operation_seq_num
10213 AND cwt.wip_entity_id = wdj.wip_entity_id
10214 AND wdj.status_type NOT IN (12,4,5)
10215 AND TRUNC(mmt.transaction_date) BETWEEN trunc(p_transaction_date_start) AND trunc(NVL(p_transaction_date_end,SYSDATE))
10216 GROUP BY cwt.wip_transaction_detail_id,mmt.transaction_type_id;
10217 LOOP
10218 FETCH l_all_jobs BULK COLLECT INTO l_wip_transaction_detail_ids,l_transaction_type_ids,l_transaction_quantities LIMIT 500;
10219 FOR i IN 1 ..l_wip_transaction_detail_ids.COUNT
10220 LOOP
10221 IF l_transaction_type_ids(i) = 35
10222 THEN
10223 UPDATE csd_wip_transaction_details SET quantity_issued = l_transaction_quantities(i)
10224 WHERE wip_transaction_detail_id = l_wip_transaction_detail_ids(i);
10225
10226 ELSIF l_transaction_type_ids(i) = 43
10227 THEN
10228 UPDATE csd_wip_transaction_details SET quantity_recovered = l_transaction_quantities(i)
10229 WHERE wip_transaction_detail_id = l_wip_transaction_detail_ids(i);
10230 END IF;
10231 END LOOP;
10232 EXIT WHEN l_all_jobs%NOTFOUND;
10233 END LOOP;
10234 CLOSE l_all_jobs;
10235 END IF;
10236 END IF;
10237 END IF;
10238
10239 END update_mat_issue_quantities;
10240
10241 -- swai: bug 13820264, FP of bug#13797285, subhat
10242 PROCEDURE update_mat_issue_quantities_cp
10243 (
10244 retcode OUT NOCOPY VARCHAR2,
10245 errbuf OUT NOCOPY VARCHAR2,
10246 p_repair_line_id IN NUMBER DEFAULT NULL,
10247 p_wip_entity_id IN NUMBER DEFAULT NULL,
10248 p_exclude_closed_jobs IN VARCHAR2 DEFAULT 'Y',
10249 p_transaction_date_start IN VARCHAR2 DEFAULT NULL,
10250 p_transaction_date_end IN VARCHAR2 DEFAULT NULL
10251 )
10252 IS
10253 x_return_status VARCHAR2(1);
10254 x_msg_count NUMBER;
10255 x_msg_data VARCHAR2(2000);
10256 l_txn_start_date DATE;
10257 l_txn_end_date DATE;
10258
10259 BEGIN
10260 IF p_transaction_date_start IS NOT NULL
10261 THEN
10262 l_txn_start_date := fnd_date.canonical_to_date(p_transaction_date_start);
10263 END IF;
10264
10265 IF p_transaction_date_end IS NOT NULL
10266 THEN
10267 l_txn_end_date := fnd_date.canonical_to_date(p_transaction_date_end);
10268 END IF;
10269
10270 retcode := 0;
10271 update_mat_issue_quantities
10272 (
10273 p_api_version_number => 1.0 ,
10274 p_init_msg_list => fnd_api.g_false ,
10275 p_commit => fnd_api.g_false ,
10276 p_validation_level => fnd_api.g_valid_level_none,
10277 x_return_status => x_return_status,
10278 x_msg_count => x_msg_count,
10279 x_msg_data => x_msg_data,
10280 p_repair_line_id => p_repair_line_id,
10281 p_wip_entity_id => p_wip_entity_id,
10282 p_wip_transaction_detail_id => NULL,
10283 p_transaction_type_id => NULL,
10284 p_quantity => NULL,
10285 p_exclude_closed_jobs => p_exclude_closed_jobs,
10286 p_transaction_date_start => l_txn_start_date,
10287 p_transaction_date_end => l_txn_end_date
10288 );
10289
10290 IF x_return_status <> fnd_api.g_ret_sts_success
10291 THEN
10292 retcode := 2;
10293 errbuf := x_msg_data;
10294 END IF;
10295 END update_mat_issue_quantities_cp;
10296
10297 -- swai: Bug 14804275 FP of bug 14752421 new procedure for creating estimates from wip
10298 /*--------------------------------------------------------------------*/
10299 /* procedure name: GENERATE_ESTIMATE_FROM_WIP */
10300 /* description : Creates estimate header and lines using data from */
10301 /* WIP jobs Materials and Labor can be either */
10302 /* requirements or transacted materials and labor, */
10303 /* depending on profile settings. This procedure calls */
10304 /* CSD_REPAIR_ESTIMATE_PVT.Import_Estimates_From_Wip */
10305 /* for the majority of the processing. */
10306 /* */
10307 /* Called from : Repair Technician portal */
10308 /* */
10309 /*--------------------------------------------------------------------*/
10310 PROCEDURE generate_estimate_from_wip
10311 (
10312 p_api_version_number IN NUMBER,
10313 p_init_msg_list IN VARCHAR2 ,
10314 p_commit IN VARCHAR2 ,
10315 p_validation_level IN NUMBER ,
10316 x_return_status OUT NOCOPY VARCHAR2,
10317 x_msg_count OUT NOCOPY NUMBER,
10318 x_msg_data OUT NOCOPY VARCHAR2,
10319 p_repair_line_id IN NUMBER
10320 ) IS
10321
10322 lc_debug_level CONSTANT NUMBER := FND_LOG.G_CURRENT_RUNTIME_LEVEL;
10323 lc_stat_level CONSTANT NUMBER := FND_LOG.LEVEL_STATEMENT;
10324 lc_proc_level CONSTANT NUMBER := FND_LOG.LEVEL_PROCEDURE;
10325 lc_event_level CONSTANT NUMBER := FND_LOG.LEVEL_EVENT;
10326 lc_excep_level CONSTANT NUMBER := FND_LOG.LEVEL_EXCEPTION;
10327 lc_error_level CONSTANT NUMBER := FND_LOG.LEVEL_ERROR;
10328 lc_unexp_level CONSTANT NUMBER := FND_LOG.LEVEL_UNEXPECTED;
10329
10330 lc_api_name CONSTANT VARCHAR2(30) := 'GENERATE_ESTIMATE_FROM_WIP';
10331 lc_api_version_number CONSTANT NUMBER := 1.0;
10332
10333 -- constants used for FND_LOG debug messages
10334 lc_mod_name VARCHAR2(2000) := 'csd.plsql.csd_hv_wip_job_pvt.generate_estimate_from_wip';
10335
10336 l_repair_type_id NUMBER;
10337 l_business_process_id NUMBER;
10338 l_currency_code VARCHAR2(3);
10339 l_incident_id NUMBER;
10340 l_organization_id NUMBER;
10341 l_warning_flag VARCHAR2(1);
10342
10343 BEGIN
10344 IF (lc_proc_level >= lc_debug_level) then
10345 FND_LOG.STRING( lc_proc_level,
10346 lc_mod_name||'begin',
10347 'Entering private API generate_estimate_from_wip' );
10348 END IF;
10349
10350 SAVEPOINT GENERATE_ESTIMATE_FROM_WIP;
10351
10352 -- Standard call to check for call compatibility.
10353 IF NOT FND_API.Compatible_API_Call(lc_api_version_number,
10354 p_api_version_number,
10355 lc_api_name,
10356 G_PKG_NAME) THEN
10357 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
10358 END IF;
10359
10360
10361 IF FND_API.to_boolean(p_init_msg_list) THEN
10362 FND_MSG_PUB.initialize;
10363 END IF;
10364
10365 -- initialize out params
10366 x_return_status := FND_API.G_RET_STS_SUCCESS;
10367
10368 -- Validate mandatory input parameters.
10369 if (lc_proc_level >= lc_debug_level) then
10370 FND_LOG.STRING(lc_proc_level, lc_mod_name,
10371 'Calling CSD_PROCESS_UTIL.Check_Reqd_Param for p_repair_line_id');
10372 end if;
10373
10374 CSD_PROCESS_UTIL.Check_Reqd_Param
10375 ( p_param_value => p_repair_line_id,
10376 p_param_name => 'REPAIR_LINE_ID',
10377 p_api_name => lc_api_name);
10378
10379 if (lc_stat_level >= lc_debug_level) then
10380 FND_LOG.STRING(lc_stat_level, lc_mod_name,
10381 'Done checking required params');
10382 end if;
10383
10384 select dra.repair_type_id,
10385 rt.business_process_id,
10386 dra.currency_code,
10387 dra.incident_id
10388 into l_repair_type_id,
10389 l_business_process_id,
10390 l_currency_code,
10391 l_incident_id
10392 from csd_repairs dra, csd_repair_types_b rt
10393 where rt.repair_type_id = dra.repair_type_id
10394 and repair_line_id = p_repair_line_id;
10395
10396 l_organization_id := fnd_profile.value('CSD_DEF_REP_INV_ORG');
10397
10398
10399 IF ( lc_event_level >= lc_debug_level ) then
10400 FND_LOG.STRING( lc_event_level,
10401 lc_mod_name,
10402 'Just before calling IMPORT_ESTIMATES_FROM_WIP');
10403 END IF;
10404
10405 CSD_REPAIR_ESTIMATE_PVT.Import_Estimates_From_Wip(
10406 p_api_version => 1.0,
10407 p_commit => FND_API.G_FALSE,
10408 p_init_msg_list =>FND_API.G_FALSE,
10409 p_validation_level => FND_API.G_VALID_LEVEL_FULL,
10410 x_return_status => x_return_status,
10411 x_msg_count => x_msg_count,
10412 x_msg_data => x_msg_data,
10413 p_repair_line_id => p_repair_line_id,
10414 p_repair_estimate_id => null,
10415 p_repair_type_id => l_repair_type_id,
10416 p_business_process_id => l_business_process_id,
10417 p_currency_code => l_currency_code,
10418 p_incident_id => l_incident_id,
10419 p_organization_id => l_organization_id,
10420 x_warning_flag => l_warning_flag );
10421
10422
10423 IF ((x_return_status <> FND_API.G_RET_STS_SUCCESS ) OR (l_warning_flag = FND_API.G_TRUE)) THEN
10424 FND_MESSAGE.SET_NAME('CSD','CSD_EST_WIP_IMPORT_FAILURE');
10425 FND_MSG_PUB.ADD;
10426 RAISE FND_API.G_EXC_ERROR;
10427 END IF;
10428
10429
10430 -- Standard check for p_commit
10431 IF FND_API.to_Boolean( p_commit )
10432 THEN
10433 COMMIT WORK;
10434 END IF;
10435
10436 EXCEPTION
10437 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
10438 ROLLBACK to GENERATE_ESTIMATE_FROM_WIP ;
10439 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
10440
10441 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
10442 p_count => x_msg_count,
10443 p_data => x_msg_data);
10444
10445 IF (lc_excep_level >= lc_debug_level ) then
10446 FND_LOG.STRING( lc_excep_level,
10447 lc_mod_name||'unx_exception',
10448 'G_EXC_UNEXPECTED_ERROR Exception');
10449 END IF;
10450
10451
10452 WHEN FND_API.G_EXC_ERROR THEN
10453 ROLLBACK to GENERATE_ESTIMATE_FROM_WIP ;
10454 x_return_status := FND_API.G_RET_STS_ERROR;
10455
10456
10457 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
10458 p_count => x_msg_count,
10459 p_data => x_msg_data);
10460
10461 IF ( lc_error_level >= lc_debug_level ) then
10462 FND_LOG.STRING( lc_error_level,
10463 lc_mod_name||'exc_exception',
10464 'G_EXC_ERROR Exception');
10465 END IF;
10466
10467 WHEN OTHERS THEN
10468 ROLLBACK to GENERATE_ESTIMATE_FROM_WIP ;
10469 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
10470
10471 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
10472 -- Add Unexpected Error to Message List, here SQLERRM is used for
10473 -- getting the error
10474 FND_MSG_PUB.add_exc_msg(p_pkg_name => G_PKG_NAME,
10475 p_procedure_name => lc_api_name );
10476 END IF;
10477
10478 FND_MSG_PUB.count_and_get( p_encoded => FND_API.G_FALSE,
10479 p_count => x_msg_count,
10480 p_data => x_msg_data);
10481
10482 IF ( lc_excep_level >= lc_debug_level) then
10483 FND_LOG.STRING( lc_excep_level,
10484 lc_mod_name||'others_exception',
10485 'OTHERS Exception');
10486 END IF;
10487 END generate_estimate_from_wip;
10488
10489 END CSD_HV_WIP_JOB_PVT;