[Home] [Help]
PACKAGE BODY: APPS.WIP_MOVPROC_PRIV
Source
1 PACKAGE BODY wip_movProc_priv AS
2 /* $Header: wipmovpb.pls 120.52.12010000.2 2008/09/02 21:53:58 hliew ship $*/
3
4 TYPE move_profile_rec_t IS RECORD(
5 child_txn_id NUMBER,
6 cmp_txn_id NUMBER,
7 org_id NUMBER,
8 wip_id NUMBER,
9 entity_type NUMBER,
10 fmOp NUMBER,
11 fmStep NUMBER,
12 toOp NUMBER,
13 toStep NUMBER,
14 scrapTxn NUMBER, -- Scrap txn?
15 easyComplete NUMBER, -- Completion txn?
16 easyReturn NUMBER, -- Return txn?
17 jobTxn NUMBER, -- Any move txns on a job?
18 scheTxn NUMBER, -- Any move txns on a schedule?
19 rsrcItem NUMBER, -- Existence of auto resource per item?
20 rsrcLot NUMBER, -- Existence of auto resource per lot?
21 poReqItem NUMBER, -- Existence of po requisition per item?
22 poReqLot NUMBER); -- Existence of po requisition per lot?
23
24 TYPE group_rec_t IS RECORD(
25 group_id NUMBER,
26 assy_header_id NUMBER, -- Assembly header ID
27 mtl_header_id NUMBER, -- Material header ID (component)
28 move_mode NUMBER, -- Move processing mode
29 bf_mode NUMBER, -- Backflush processing mode
30 mtl_mode NUMBER, -- Material processing mode
31 txn_date DATE, -- Transactions date
32 process_phase NUMBER,
33 process_status NUMBER,
34 time_out NUMBER, -- Processing time out in seconds
35 intf_tbl_name VARCHAR2(240), -- Interface table name
36 user_id NUMBER,
37 login_id NUMBER,
38 request_id NUMBER,
39 application_id NUMBER,
40 program_id NUMBER,
41 move_profile move_profile_rec_t,
42 seq_move NUMBER); -- Sequencing move or not
43
44 -- this record used to store all necessary info need to change in
45 -- wip_operations for repetitive schedule allocation
46 TYPE update_rsa_rec_t IS RECORD(scheID NUMBER,
47 scheQty NUMBER,
48 loginID NUMBER,
49 reqID NUMBER,
50 appID NUMBER,
51 progID NUMBER,
52 createdBy NUMBER,
53 updatedBy NUMBER,
54 orgID NUMBER,
55 wipID NUMBER,
56 fmOp NUMBER,
57 fmStep NUMBER,
58 toOp NUMBER,
59 toStep NUMBER);
60 TYPE update_rsa_tbl_t IS TABLE OF update_rsa_rec_t INDEX BY binary_integer;
61 TVE_NO_MOVE_ALLOC CONSTANT NUMBER := -5; -- Cannot execute move allocation
62 TVE_OVERCOMPLETION_MISMATCH CONSTANT NUMBER := -6; -- Cannot execute move alloc
63
64 -- transaction_source_type_id used to insert into MMTT
65 TPS_INV_JOB_OR_SCHED CONSTANT NUMBER := 5;
66
67 /*****************************************************************************
68 * This procedure will be used to backflush assembly pull component for
69 * EZ Completion an EZ Return transaction.
70 ****************************************************************************/
71 PROCEDURE backflush_assy_pull(p_gib IN OUT NOCOPY group_rec_t,
72 p_move_txn_id IN NUMBER,
73 p_entity_type IN NUMBER) IS
74
75 CURSOR c_repAssembly IS
76 SELECT mmt.completion_transaction_id cpl_txn_id,
77 mmt.transaction_action_id txn_action_id,
78 mmt.transaction_source_id txn_src_id,
79 mmt.repetitive_line_id rep_line_id,
80 mmt.organization_id org_id,
81 mmt.transaction_date txn_date,
82 ABS(mmt.primary_quantity) primary_qty,
83 mmt.reason_id reason_id,
84 mmt.transaction_reference reference,
85 /* Fixed bug 4628893 */
86 mmt.move_transaction_id move_txn_id,
87 wmti.transaction_type txn_type
88 FROM mtl_material_transactions mmt,
89 wip_move_txn_interface wmti
90 /* Bug 4891549 - Modified where clause to improve performance. */
91 WHERE mmt.transaction_source_type_id = TPS_INV_JOB_OR_SCHED
92 AND mmt.transaction_source_id = wmti.wip_entity_id
93 AND mmt.organization_id = wmti.organization_id
94 /* End fix for bug 4891549 */
95 AND mmt.move_transaction_id = wmti.transaction_id
96 AND wmti.transaction_id = p_move_txn_id /* Fixed bug 4916939 */
97 AND wmti.group_id = p_gib.group_id
98 AND wmti.entity_type = WIP_CONSTANTS.REPETITIVE
99 AND wmti.transaction_date = mmt.transaction_date /*Bug 5581147 - Added to improve selectivity*/
100 AND mmt.transaction_action_id IN (WIP_CONSTANTS.RETASSY_ACTION,
101 WIP_CONSTANTS.CPLASSY_ACTION);
102
103 CURSOR c_discAssembly IS
104 SELECT mmt.completion_transaction_id cpl_txn_id,
105 mmt.transaction_action_id txn_action_id,
106 mmt.transaction_source_id txn_src_id,
107 mmt.organization_id org_id,
108 mmt.transaction_date txn_date,
109 ABS(mmt.primary_quantity) primary_qty,
110 wmti.entity_type entity_type,
111 mmt.reason_id reason_id,
112 mmt.transaction_reference reference,
113 /* Fixed bug 4628893 */
114 mmt.move_transaction_id move_txn_id,
115 wmti.transaction_type txn_type
116 FROM mtl_material_transactions mmt,
117 wip_move_txn_interface wmti
118 /* Bug 4891549 - Modified where clause to improve performance. */
119 WHERE mmt.transaction_source_type_id = TPS_INV_JOB_OR_SCHED
120 AND mmt.transaction_source_id = wmti.wip_entity_id
121 AND mmt.organization_id = wmti.organization_id
122 /* End fix for bug 4891549 */
123 AND mmt.move_transaction_id = wmti.transaction_id
124 AND wmti.transaction_id = p_move_txn_id /* Fixed bug 4916939 */
125 AND wmti.group_id = p_gib.group_id
126 AND wmti.transaction_date = mmt.transaction_date /*Bug 5581147 - Added to improve selectivity*/
127 AND wmti.entity_type = WIP_CONSTANTS.DISCRETE
128 AND mmt.transaction_action_id IN (WIP_CONSTANTS.RETASSY_ACTION,
129 WIP_CONSTANTS.CPLASSY_ACTION);
130
131 CURSOR c_OSFMAssembly IS
132 SELECT mmt.completion_transaction_id cpl_txn_id,
133 mmt.transaction_action_id txn_action_id,
134 mmt.transaction_source_id txn_src_id,
135 mmt.organization_id org_id,
136 mmt.transaction_date txn_date,
137 ABS(mmt.primary_quantity) primary_qty,
138 wmti.entity_type entity_type,
139 mmt.reason_id reason_id,
140 mmt.transaction_reference reference,
141 /* Fixed bug 4628893 */
142 mmt.move_transaction_id move_txn_id,
143 wmti.transaction_type txn_type,
144 /* Fixed bug 5014211 */
145 wmti.fm_operation_seq_num fm_op,
146 wmti.fm_intraoperation_step_type fm_step,
147 wmti.to_operation_seq_num to_op,
148 wmti.to_intraoperation_step_type to_step
149 /* End fix of bug 5014211 */
150 FROM mtl_material_transactions mmt,
151 wip_move_txn_interface wmti
152 /* Bug 4891549 - Modified where clause to improve performance. */
153 WHERE mmt.transaction_source_type_id = TPS_INV_JOB_OR_SCHED
154 AND mmt.transaction_source_id = wmti.wip_entity_id
155 AND mmt.organization_id = wmti.organization_id
156 /* End fix for bug 4891549 */
157 AND mmt.move_transaction_id = wmti.transaction_id
158 AND wmti.transaction_id = p_move_txn_id /* Fixed bug 4916939 */
159 AND wmti.group_id = p_gib.group_id
160 AND wmti.transaction_date = mmt.transaction_date /*Bug 5581147 - Added to improve selectivity*/
161 AND wmti.entity_type = WIP_CONSTANTS.LOTBASED
162 AND mmt.transaction_action_id IN (WIP_CONSTANTS.RETASSY_ACTION,
163 WIP_CONSTANTS.CPLASSY_ACTION);
164
165 l_repAssembly c_repAssembly%ROWTYPE;
166 l_discAssembly c_discAssembly%ROWTYPE;
167 l_OSFMAssembly c_OSFMAssembly%ROWTYPE;
168 l_params wip_logger.param_tbl_t;
169 l_returnStatus VARCHAR2(1);
170 l_errMsg VARCHAR(240);
171 l_msg VARCHAR(240);
172 l_logLevel NUMBER := fnd_log.g_current_runtime_level;
173 l_bf_required NUMBER; -- throw away value
174 l_ls_required NUMBER;
175 -- New variable to pass to OSFM new backflush API.
176 l_error_msg VARCHAR2(1000);
177 l_error_count NUMBER;
178 BEGIN
179 -- write parameter value to log file
180 IF (l_logLevel <= wip_constants.trace_logging) THEN
181 l_params(1).paramName := 'p_group_id';
182 l_params(1).paramValue := p_gib.group_id;
183 l_params(2).paramName := 'p_mtl_header_id';
184 l_params(2).paramValue := p_gib.mtl_header_id;
185 l_params(3).paramName := 'p_mtl_mode';
186 l_params(3).paramValue := p_gib.mtl_mode;
187 /* Fixed bug 4916939 */
188 l_params(4).paramName := 'p_move_txn_id';
189 l_params(4).paramValue := p_move_txn_id;
190 l_params(5).paramName := 'p_entity_type';
191 l_params(5).paramValue := p_entity_type;
192
193 wip_logger.entryPoint(p_procName =>'wip_movProc_priv.backflush_assy_pull',
194 p_params => l_params,
195 x_returnStatus => l_returnStatus);
196 END IF;
197 IF(p_entity_type = WIP_CONSTANTS.REPETITIVE) THEN
198 FOR l_repAssembly IN c_repAssembly LOOP
199 wip_bflProc_priv.backflush(
200 p_wipEntityID => l_repAssembly.txn_src_id,
201 p_orgID => l_repAssembly.org_id,
202 p_primaryQty => l_repAssembly.primary_qty,
203 p_txnDate => l_repAssembly.txn_date,
204 p_txnHdrID => p_gib.mtl_header_id,
205 -- Fixed bug 5056289. Pass move_id as a batch_id because we want
206 -- inventory to fail only components related to a specific move record.
207 p_batchID => p_move_txn_id,
208 p_txnType => l_repAssembly.txn_type,
209 p_entityType => WIP_CONSTANTS.REPETITIVE,
210 p_tblName => WIP_CONSTANTS.MTI_TBL,
211 p_lineID => l_repAssembly.rep_line_id,
212 p_cplTxnID => l_repAssembly.cpl_txn_id,
213 -- Fixed bug 5014211. Stamp move_transaction_id for assembly
214 -- pull components so that we will have a link if component
215 -- records fail inventory validation.
216 p_movTxnID => l_repAssembly.move_txn_id,
217 -- End fix of 5014211.
218 p_fmMoveProcessor => WIP_CONSTANTS.YES,
219 p_mtlTxnMode => p_gib.mtl_mode,
220 p_reasonID => l_repAssembly.reason_id,
221 p_reference => l_repAssembly.reference,
222 -- Set lock_flag to 1 to prevent inventory worker pick up the record.
223 -- Need this change because we will commit after each TM call.
224 p_lockFlag => WIP_CONSTANTS.YES,
225 x_lotSerRequired => l_ls_required,
226 x_bfRequired => l_bf_required,
227 x_returnStatus => l_returnStatus);
228
229 IF(l_returnStatus <> fnd_api.g_ret_sts_success) THEN
230 raise fnd_api.g_exc_unexpected_error;
231 ELSE
232 IF(l_ls_required = WIP_CONSTANTS.YES) THEN
233 -- If we need to gather more lot/serial, error out because
234 -- we cannot gather lot/serial for background transaction.
235 fnd_message.set_name('WIP', 'WIP_NO_LOT_SER_COMP_BKGND');
236 fnd_msg_pub.add;
237 raise fnd_api.g_exc_unexpected_error;
238 END IF;
239 END IF; -- check return status
240 END LOOP; -- repetitive schedule
241 ELSIF(p_entity_type = WIP_CONSTANTS.DISCRETE) THEN
242 FOR l_discAssembly IN c_discAssembly LOOP
243 wip_bflProc_priv.backflush(
244 p_wipEntityID => l_discAssembly.txn_src_id,
245 p_orgID => l_discAssembly.org_id,
246 p_primaryQty => l_discAssembly.primary_qty,
247 p_txnDate => l_discAssembly.txn_date,
248 p_txnHdrID => p_gib.mtl_header_id,
249 -- Fixed bug 5056289. Pass move_id as a batch_id because we want
250 -- inventory to fail only components related to a specific move record.
251 p_batchID => p_move_txn_id,
252 p_txnType => l_discAssembly.txn_type,
253 p_entityType => l_discAssembly.entity_type,
254 p_tblName => WIP_CONSTANTS.MTI_TBL,
255 p_cplTxnID => l_discAssembly.cpl_txn_id,
256 -- Fixed bug 5014211. Stamp move_transaction_id for assembly
257 -- pull components so that we will have a link if component
258 -- records fail inventory validation.
259 p_movTxnID => l_discAssembly.move_txn_id,
260 -- End fix of 5014211.
261 p_fmMoveProcessor => WIP_CONSTANTS.YES,
262 p_mtlTxnMode => p_gib.mtl_mode,
263 p_reasonID => l_discAssembly.reason_id,
264 p_reference => l_discAssembly.reference,
265 -- Set lock_flag to 1 to prevent inventory worker pick up the record.
266 -- Need this change because we will commit after each TM call.
267 p_lockFlag => WIP_CONSTANTS.YES,
268 x_lotSerRequired => l_ls_required,
269 x_bfRequired => l_bf_required,
270 x_returnStatus => l_returnStatus);
271
272 IF(l_returnStatus <> fnd_api.g_ret_sts_success) THEN
273 raise fnd_api.g_exc_unexpected_error;
274 ELSE
275 IF(l_ls_required = WIP_CONSTANTS.YES) THEN
276 -- If we need to gather more lot/serial, error out because
277 -- we cannot gather lot/serial for background transaction.
278 fnd_message.set_name('WIP', 'WIP_NO_LOT_SER_COMP_BKGND');
279 fnd_msg_pub.add;
280 raise fnd_api.g_exc_unexpected_error;
281 END IF;
282 END IF; -- check return status
283 END LOOP; -- Discrete
284 ELSIF(p_entity_type = WIP_CONSTANTS.LOTBASED) THEN
285 FOR l_OSFMAssembly IN c_OSFMAssembly LOOP
286 wsm_serial_support_grp.backflush_comp(
287 p_wipEntityID => l_OSFMAssembly.txn_src_id,
288 p_orgID => l_OSFMAssembly.org_id,
289 p_primaryQty => l_OSFMAssembly.primary_qty,
290 p_txnDate => l_OSFMAssembly.txn_date,
291 p_txnHdrID => p_gib.mtl_header_id,
292 p_txnType => l_OSFMAssembly.txn_type,
293 -- Fixed bug 5014211. Stamp move_transaction_id for assembly
294 -- pull components so that we will have a link if component
295 -- records fail inventory validation.
296 p_fmOp => l_OSFMAssembly.fm_op,
297 p_fmStep => l_OSFMAssembly.fm_step,
298 p_toOp => l_OSFMAssembly.to_op,
299 p_toStep => l_OSFMAssembly.to_step,
300 p_movTxnID => l_OSFMAssembly.move_txn_id,
301 -- End fix of 5014211.
302 p_cplTxnID => l_OSFMAssembly.cpl_txn_id,
303 p_mtlTxnMode => p_gib.mtl_mode,
304 p_reasonID => l_OSFMAssembly.reason_id,
305 p_reference => l_OSFMAssembly.reference,
306 p_init_msg_list => fnd_api.g_true,
307 x_lotSerRequired => l_ls_required,
308 x_returnStatus => l_returnStatus,
309 x_error_msg => l_error_msg, -- throw away value
310 x_error_count => l_error_count); -- throw away value
311
312 IF(l_returnStatus <> fnd_api.g_ret_sts_success) THEN
313 raise fnd_api.g_exc_unexpected_error;
314 ELSE
315 IF(l_ls_required = WIP_CONSTANTS.YES) THEN
316 -- If we need to gather more lot/serial, error out because
317 -- we cannot gather lot/serial for background transaction.
318 fnd_message.set_name('WIP', 'WIP_NO_LOT_SER_COMP_BKGND');
319 fnd_msg_pub.add;
320 raise fnd_api.g_exc_unexpected_error;
321 END IF;
322 END IF; -- check return status
323 END LOOP; -- OSFM
324 END IF; -- entity_type check
325 -- write to the log file
326 IF (l_logLevel <= wip_constants.trace_logging) THEN
327 wip_logger.exitPoint(p_procName => 'wip_movProc_priv.backflush_assy_pull',
328 p_procReturnStatus => 'S',
329 p_msg => 'procedure complete',
330 x_returnStatus => l_returnStatus);
331 END IF;
332 END backflush_assy_pull;
333
334
335 /*****************************************************************************
336 * This procedure will delete record from MTI and MTLI if the components fail
337 * inventory validation. It will also update a corresponding move record to
338 * error status.
339 ****************************************************************************/
340 PROCEDURE component_cleanup(p_mtl_header_id IN NUMBER,
341 p_group_id IN NUMBER) IS
342
343 l_params wip_logger.param_tbl_t;
344 l_returnStatus VARCHAR(1);
345 l_msg VARCHAR(240);
346 l_logLevel NUMBER := fnd_log.g_current_runtime_level;
347 BEGIN
348 -- write parameter value to log file
349 IF (l_logLevel <= wip_constants.trace_logging) THEN
350 l_params(1).paramName := 'p_mtl_header_id';
351 l_params(1).paramValue := p_mtl_header_id;
352 l_params(2).paramName := 'p_group_id';
353 l_params(2).paramValue := p_group_id;
354 wip_logger.entryPoint(p_procName =>'wip_movProc_priv.component_cleanup',
355 p_params => l_params,
356 x_returnStatus => l_returnStatus);
357 END IF;
358 -- Update status of move record to error if components fail inventory
359 -- validation.
360 UPDATE wip_move_txn_interface wmti
361 SET wmti.process_status = WIP_CONSTANTS.ERROR
362 WHERE wmti.group_id = p_group_id
363 AND EXISTS
364 (SELECT 1
365 FROM mtl_transactions_interface mti
366 WHERE mti.transaction_header_id = p_mtl_header_id
367 AND mti.move_transaction_id = wmti.transaction_id
368 AND mti.error_explanation IS NOT NULL);
369
370 IF (l_logLevel <= wip_constants.full_logging) THEN
371 fnd_message.set_name('WIP', 'WIP_UPDATED_ROWS');
372 fnd_message.set_token('ENTITY1', SQL%ROWCOUNT);
373 fnd_message.set_token('ENTITY2', 'WIP_MOVE_TXN_INTERFACE');
374 l_msg := fnd_message.get;
375 wip_logger.log(p_msg => l_msg,
376 x_returnStatus => l_returnStatus);
377 END IF;
378
379 -- Delete error records from MTLI
380 DELETE FROM mtl_transaction_lots_interface mtli
381 WHERE mtli.transaction_interface_id IN
382 (SELECT mti.transaction_interface_id
383 FROM mtl_transactions_interface mti
384 WHERE mti.transaction_header_id = p_mtl_header_id);
385
386 IF (l_logLevel <= wip_constants.full_logging) THEN
387 l_msg := SQL%ROWCOUNT ||
388 ' rows deleted from mtl_transaction_lots_interface';
389 wip_logger.log(p_msg => l_msg,
390 x_returnStatus => l_returnStatus);
391 END IF;
392
393 -- Delete error records from MTI
394 DELETE FROM mtl_transactions_interface
395 WHERE transaction_header_id = p_mtl_header_id;
396
397 IF (l_logLevel <= wip_constants.full_logging) THEN
398 l_msg := SQL%ROWCOUNT ||
399 ' rows deleted from mtl_transactions_interface';
400 wip_logger.log(p_msg => l_msg,
401 x_returnStatus => l_returnStatus);
402 END IF;
403
404 l_returnStatus := fnd_api.g_ret_sts_success;
405 IF (l_logLevel <= wip_constants.trace_logging) THEN
406 wip_logger.exitPoint(p_procName => 'wip_movProc_priv.component_cleanup',
407 p_procReturnStatus => l_returnStatus,
408 p_msg => 'procedure complete',
409 x_returnStatus => l_returnStatus);
410 END IF;
411
412 END component_cleanup;
413
414
415 /*****************************************************************************
416 * This is an autonomous procedure that will move an error message from MTI to
417 * WMTI.
418 ****************************************************************************/
419 PROCEDURE write_mtl_error(p_move_id NUMBER,
420 p_error_msg VARCHAR2,
421 p_last_update_date DATE,
422 p_last_updated_by NUMBER,
423 p_creation_date DATE,
424 p_created_by NUMBER,
425 p_last_update_login NUMBER,
426 p_request_id NUMBER,
427 p_program_application_id NUMBER,
428 p_program_id NUMBER,
429 p_program_update_date DATE) IS
430
431 PRAGMA AUTONOMOUS_TRANSACTION;
432
433 BEGIN
434
435 INSERT INTO wip_txn_interface_errors
436 (transaction_id,
437 error_column,
438 error_message,
439 last_update_date,
440 last_updated_by,
441 creation_date,
442 created_by,
443 last_update_login,
444 request_id,
445 program_application_id,
446 program_id,
447 program_update_date
448 )
449 VALUES(p_move_id, -- transaction_id
450 NULL, -- error_column
451 p_error_msg, -- error_message
452 p_last_update_date,
453 p_last_updated_by,
454 p_creation_date,
455 p_created_by,
456 p_last_update_login,
457 p_request_id,
458 p_program_application_id,
459 p_program_id,
460 p_program_update_date);
461
462 COMMIT;
463 END write_mtl_error;
464
465 /*****************************************************************************
466 * This procedure will be used to record error messages from
467 * MTL_TRANSACTIONS_INTERFACE into WIP_TXN_INTERFACE_ERRORS
468 ****************************************************************************/
469 PROCEDURE write_mtl_errors(p_mtl_header_id IN NUMBER) IS
470
471 CURSOR c_mtl_errors IS
472 SELECT mti.move_transaction_id,
473 substrb(msik.concatenated_segments || ':' ||
474 mti.error_explanation,1,240) error_msg, -- error_message
475 mti.last_update_date,
476 mti.last_updated_by,
477 mti.creation_date,
478 mti.created_by,
479 mti.last_update_login,
480 mti.request_id,
481 mti.program_application_id,
482 mti.program_id,
483 mti.program_update_date
484 FROM mtl_transactions_interface mti,
485 mtl_system_items_kfv msik
486 WHERE mti.transaction_header_id = p_mtl_header_id
487 AND mti.inventory_item_id = msik.inventory_item_id
488 AND mti.organization_id = msik.organization_id
489 AND mti.error_explanation IS NOT NULL;
490
491 l_mtl_errors c_mtl_errors%ROWTYPE;
492 l_params wip_logger.param_tbl_t;
493 l_returnStatus VARCHAR(1);
494 l_errMsg VARCHAR2(240);
495 l_logLevel NUMBER := fnd_log.g_current_runtime_level;
496 l_count NUMBER;
497 BEGIN
498 -- write parameter value to log file
499 IF (l_logLevel <= wip_constants.trace_logging) THEN
500 l_params(1).paramName := 'p_mtl_header_id';
501 l_params(1).paramValue := p_mtl_header_id;
502 wip_logger.entryPoint(p_procName =>'wip_movProc_priv.write_mtl_errors',
503 p_params => l_params,
504 x_returnStatus => l_returnStatus);
505 END IF;
506 l_count := 0;
507 FOR l_mtl_errors IN c_mtl_errors LOOP
508 l_count := l_count + 1;
509 write_mtl_error(
510 p_move_id => l_mtl_errors.move_transaction_id,
511 p_error_msg => l_mtl_errors.error_msg,
512 p_last_update_date => l_mtl_errors.last_update_date,
513 p_last_updated_by => l_mtl_errors.last_updated_by,
514 p_creation_date => l_mtl_errors.creation_date,
515 p_created_by => l_mtl_errors.created_by,
516 p_last_update_login => l_mtl_errors.last_update_login,
517 p_request_id => l_mtl_errors.request_id,
518 p_program_application_id => l_mtl_errors.program_application_id,
519 p_program_id => l_mtl_errors.program_id,
520 p_program_update_date => l_mtl_errors.program_update_date);
521 END LOOP;
522 -- Clear inventory message from the stack because inventory always put
523 -- quantity tree error into message stack, but did not error out the
524 -- transactions. This will mislead both customer and developer if transaction
525 -- fail inventory validation code.
526 fnd_msg_pub.initialize;
527
528 IF (l_logLevel <= wip_constants.full_logging) THEN
529 wip_logger.log(p_msg => l_count || ' records inserted',
530 x_returnStatus => l_returnStatus);
531 END IF;
532
533 l_returnStatus := fnd_api.g_ret_sts_success;
534 IF (l_logLevel <= wip_constants.trace_logging) THEN
535 wip_logger.exitPoint(p_procName => 'wip_movProc_priv.write_mtl_errors',
536 p_procReturnStatus => l_returnStatus,
537 p_msg => 'procedure complete',
538 x_returnStatus => l_returnStatus);
539 END IF;
540 EXCEPTION
541 WHEN others THEN
542 l_returnStatus := fnd_api.g_ret_sts_unexp_error;
543 l_errMsg := 'unexpected error: ' || SQLERRM || 'SQLCODE = ' || SQLCODE;
544
545 IF (l_logLevel <= wip_constants.trace_logging) THEN
546 wip_logger.exitPoint(p_procName => 'wip_movProc_priv.write_mtl_errors',
547 p_procReturnStatus => l_returnStatus,
548 p_msg => l_errMsg,
549 x_returnStatus => l_returnStatus);
550 END IF;
551 fnd_message.set_name('FND', 'FND_GENERIC_MESSAGE');
552 fnd_message.set_token('MESSAGE', l_errMsg);
553 fnd_msg_pub.add;
554 END write_mtl_errors;
555
556 /*****************************************************************************
557 * This procedure is equivalent to witpslw_lock_wipops in wiltps.ppc
558 * This procedure is used to lock a record in WIP_OPERATIONS
559 ****************************************************************************/
560 PROCEDURE lock_wipops(p_gib IN group_rec_t,
561 x_returnStatus OUT NOCOPY VARCHAR2) IS
562
563 CURSOR c_wipops(p_group_id NUMBER,
564 p_txn_date DATE) IS
565 SELECT wop.wip_entity_id,
566 wop.operation_seq_num,
567 wop.organization_id,
568 wop.repetitive_schedule_id
569 FROM wip_operations wop,
570 wip_repetitive_schedules wrs,
571 wip_move_txn_interface wmti
572 WHERE wop.organization_id = wmti.organization_id
573 AND wop.wip_entity_id = wmti.wip_entity_id
574 AND wmti.group_id = p_group_id
575 AND TRUNC(wmti.transaction_date) = TRUNC(p_txn_date)
576 AND wmti.process_phase = WIP_CONSTANTS.MOVE_PROC
577 AND wmti.process_status = WIP_CONSTANTS.RUNNING
578 AND ((wop.operation_seq_num BETWEEN
579 wmti.fm_operation_seq_num AND wmti.to_operation_seq_num)
580 OR (wop.operation_seq_num BETWEEN
581 wmti.to_operation_seq_num AND wmti.fm_operation_seq_num))
582 AND wop.organization_id = wrs.organization_id (+)
583 AND wop.repetitive_schedule_id = wrs.repetitive_schedule_id(+)
584 AND NVL(wrs.status_type,-999) IN (-999, WIP_CONSTANTS.RELEASED,
585 WIP_CONSTANTS.COMP_CHRG)
586 AND (( wmti.line_id = wrs.line_id
587 AND wmti.line_id IS NOT NULL
588 AND wop.repetitive_schedule_id IS NOT NULL)
589 OR (wmti.line_id IS NULL))
590 FOR UPDATE OF wop.quantity_completed NOWAIT;
591
592 l_wipops c_wipops%ROWTYPE;
593 l_returnStatus VARCHAR(1);
594 l_errMsg VARCHAR2(240);
595 l_params wip_logger.param_tbl_t;
596 l_logLevel NUMBER := fnd_log.g_current_runtime_level;
597
598 BEGIN
599 -- write parameter value to log file
600 IF (l_logLevel <= wip_constants.trace_logging) THEN
601 l_params(1).paramName := 'p_group_id';
602 l_params(1).paramValue := p_gib.group_id;
603 l_params(2).paramName := 'p_txn_date';
604 l_params(2).paramValue := p_gib.txn_date;
605 wip_logger.entryPoint(p_procName => 'wip_movProc_priv.lock_wipops',
606 p_params => l_params,
607 x_returnStatus => l_returnStatus);
608 END IF;
609
610 OPEN c_wipops(p_group_id => p_gib.group_id,
611 p_txn_date => p_gib.txn_date);
612
613 IF(c_wipops%ISOPEN) THEN
614 CLOSE c_wipops;
615 END IF;
616 x_returnStatus := fnd_api.g_ret_sts_success;
617
618 -- write to the log file
619 IF (l_logLevel <= wip_constants.trace_logging) THEN
620 wip_logger.exitPoint(p_procName => 'wip_movProc_priv.lock_wipops',
621 p_procReturnStatus => x_returnStatus,
622 p_msg => 'procedure complete',
623 x_returnStatus => l_returnStatus);
624 END IF;
625
626 EXCEPTION
627 WHEN wip_constants.records_locked THEN
628 IF(c_wipops%ISOPEN) THEN
629 CLOSE c_wipops;
630 END IF;
631 x_returnStatus := fnd_api.g_ret_sts_unexp_error;
632 l_errMsg := 'Unable to lock the record in wip_operations';
633
634 IF (l_logLevel <= wip_constants.trace_logging) THEN
635 wip_logger.exitPoint(p_procName => 'wip_movProc_priv.lock_wipops',
636 p_procReturnStatus => x_returnStatus,
637 p_msg => l_errMsg,
638 x_returnStatus => l_returnStatus);
639 END IF;
640 fnd_message.set_name('INV','INV_WIP_WORK_ORDER_LOCKED');
641 fnd_msg_pub.add;
642
643 WHEN others THEN
644 IF(c_wipops%ISOPEN) THEN
645 CLOSE c_wipops;
646 END IF;
647 x_returnStatus := fnd_api.g_ret_sts_unexp_error;
648 l_errMsg := 'unexpected error: ' || SQLERRM || 'SQLCODE = ' || SQLCODE;
649
650 IF (l_logLevel <= wip_constants.trace_logging) THEN
651 wip_logger.exitPoint(p_procName => 'wip_movProc_priv.lock_wipops',
652 p_procReturnStatus => x_returnStatus,
653 p_msg => l_errMsg,
654 x_returnStatus => l_returnStatus);
655 END IF;
656 fnd_message.set_name('FND', 'FND_GENERIC_MESSAGE');
657 fnd_message.set_token('MESSAGE', l_errMsg);
658 fnd_msg_pub.add;
659 END lock_wipops;
660
661 /*****************************************************************************
662 * This procedure is equivalent to witpssa_sched_alloc in wiltps.ppc
663 * This procedure is used to allocate quantity to multiple reptitive schedule
664 * it work for both regular and over move transaction
665 ****************************************************************************/
666 PROCEDURE schedule_alloc(p_org_id IN NUMBER,
667 p_wip_id IN NUMBER,
668 p_line_id IN NUMBER,
669 p_quantity IN NUMBER,
670 p_fm_op IN NUMBER,
671 p_fm_step IN NUMBER,
672 p_to_op IN NUMBER,
673 p_to_step IN NUMBER,
674 p_oc_txn_type IN NUMBER,
675 p_txnType IN NUMBER,
676 p_fm_form IN NUMBER,
677 p_comp_alloc IN NUMBER,
678 p_txn_date IN DATE, /* bug 5373061 */
679 x_proc_status OUT NOCOPY NUMBER,
680 x_sche_count OUT NOCOPY NUMBER,
681 x_rsa OUT NOCOPY rsa_tbl_t,
682 x_returnStatus OUT NOCOPY VARCHAR2) IS
683
684 /* Fix for bug 5373061: Added date_released condition to allocate back-dated
685 transactions correctly */
686 CURSOR c_rsa(p_forward NUMBER) IS
687 SELECT wrs.repetitive_schedule_id scheID,
688 (wo2.quantity_waiting_to_move - NVL(SUM(wmat.primary_quantity),0))
689 toMoveQty,
690 (wrs.quantity_completed + NVL(SUM(wmat.primary_quantity),0))
691 completedQty,
692 wo1.operation_seq_num op_seq,
693 wo1.quantity_in_queue queue_qty,
694 wo1.quantity_running run_qty,
695 wo1.quantity_waiting_to_move tomove_qty,
696 wo1.quantity_rejected reject_qty,
697 wo1.quantity_scrapped scrap_qty
698 FROM wip_operations wo1,
699 wip_operations wo2,
700 wip_repetitive_schedules wrs,
701 wip_mtl_allocations_temp wmat
702 WHERE wrs.repetitive_schedule_id = wmat.repetitive_schedule_id(+)
703 AND wrs.organization_id = wmat.organization_id(+)
704 AND wrs.organization_id = wo1.organization_id
705 AND wrs.wip_entity_id = wo1.wip_entity_id
706 AND wrs.repetitive_schedule_id = wo1.repetitive_schedule_id
707 AND wo1.operation_seq_num = p_fm_op
708 AND wrs.organization_id = wo2.organization_id
709 AND wrs.wip_entity_id = wo2.wip_entity_id
710 AND wrs.repetitive_schedule_id = wo2.repetitive_schedule_id
711 AND wo2.operation_seq_num = p_to_op
712 AND wrs.organization_id = p_org_id
713 AND wrs.wip_entity_id = p_wip_id
714 AND wrs.line_id = p_line_id
715 AND wrs.status_type in (WIP_CONSTANTS.RELEASED, WIP_CONSTANTS.COMP_CHRG)
716 AND wrs.date_released < p_txn_date
717 GROUP BY wrs.repetitive_schedule_id,
718 wo2.quantity_waiting_to_move,
719 wrs.quantity_completed,
720 wo1.operation_seq_num,
721 wo1.quantity_in_queue,
722 wo1.quantity_running,
723 wo1.quantity_waiting_to_move,
724 wo1.quantity_rejected,
725 wo1.quantity_scrapped,
726 wo1.first_unit_start_date,
727 wrs.first_unit_start_date
728 ORDER BY DECODE(p_forward,
729 WIP_CONSTANTS.YES,NVL(wo1.first_unit_start_date,
730 wrs.first_unit_start_date), -- no routing
731 NULL) ASC,
732 DECODE(p_forward,
733 WIP_CONSTANTS.NO, NVL(wo1.first_unit_start_date,
734 wrs.first_unit_start_date), -- no routing
735 NULL) DESC;
736
737 l_rsa c_rsa%ROWTYPE;
738 l_params wip_logger.param_tbl_t;
739 l_returnStatus VARCHAR(1);
740 l_errMsg VARCHAR2(240);
741 l_forward NUMBER;
742 l_cur_qty NUMBER;
743 l_scheID NUMBER;
744 l_quantity NUMBER := p_quantity;
745 l_recordFound NUMBER := 0;
746 l_need_more BOOLEAN := TRUE;
747 l_dummy NUMBER := 0;
748 l_logLevel NUMBER := fnd_log.g_current_runtime_level;
749
750 BEGIN
751 -- write parameter value to log file
752 IF (l_logLevel <= wip_constants.trace_logging) THEN
753 l_params(1).paramName := 'p_org_id';
754 l_params(1).paramValue := p_org_id;
755 l_params(2).paramName := 'p_wip_id';
756 l_params(2).paramValue := p_wip_id;
757 l_params(3).paramName := 'p_line_id';
758 l_params(3).paramValue := p_line_id;
759 l_params(4).paramName := 'p_quantity';
760 l_params(4).paramValue := p_quantity;
761 l_params(5).paramName := 'p_fm_op';
762 l_params(5).paramValue := p_fm_op;
763 l_params(6).paramName := 'p_fm_step';
764 l_params(6).paramValue := p_fm_step;
765 l_params(7).paramName := 'p_to_op';
766 l_params(7).paramValue := p_to_op;
767 l_params(8).paramName := 'p_to_step';
768 l_params(8).paramValue := p_to_step;
769 l_params(9).paramName := 'p_oc_txn_type';
770 l_params(9).paramValue := p_oc_txn_type;
771 l_params(10).paramName := 'p_txnType';
772 l_params(10).paramValue := p_txnType;
773 l_params(11).paramName := 'p_fm_form';
774 l_params(11).paramValue := p_fm_form;
775 l_params(12).paramName := 'p_comp_alloc';
776 l_params(12).paramValue := p_comp_alloc;
777 wip_logger.entryPoint(p_procName => 'wip_movProc_priv.schedule_alloc',
778 p_params => l_params,
779 x_returnStatus => l_returnStatus);
780 END IF;
781
782 -- initialize x_sche_count
783 x_sche_count := 0;
784
785 IF(p_fm_op < p_to_op) OR
786 (p_fm_op = p_to_op AND p_fm_step <= p_to_step) THEN
787 l_forward := WIP_CONSTANTS.YES;
788 ELSE
789 l_forward := WIP_CONSTANTS.NO;
790 END IF;
791
792 OPEN c_rsa(l_forward);
793 WHILE l_need_more LOOP
794 FETCH c_rsa INTO l_rsa;
795
796 IF(c_rsa%NOTFOUND) THEN
797 GOTO no_data;
798 ELSE
799 l_recordFound := l_recordFound + 1;
800 l_scheID := l_rsa.scheID;
801
802 IF(p_txnType = WIP_CONSTANTS.RET_TXN AND
803 p_fm_form = WIP_CONSTANTS.YES) THEN
804 l_cur_qty := l_rsa.completedQty;
805 ELSE
806 IF (p_fm_step = WIP_CONSTANTS.QUEUE) THEN
807 l_cur_qty := NVL(l_rsa.queue_qty, 0);
808 ELSIF (p_fm_step = WIP_CONSTANTS.RUN) THEN
809 l_cur_qty := NVL(l_rsa.run_qty, 0);
810 ELSIF (p_fm_step = WIP_CONSTANTS.TOMOVE) THEN
811 l_cur_qty := NVL(l_rsa.tomove_qty, 0);
812 ELSIF (p_fm_step = WIP_CONSTANTS.REJECT) THEN
813 l_cur_qty := NVL(l_rsa.reject_qty, 0);
814 ELSIF (p_fm_step = WIP_CONSTANTS.SCRAP) THEN
815 l_cur_qty := NVL(l_rsa.scrap_qty, 0);
816 END IF;
817
818 IF (p_comp_alloc = WIP_CONSTANTS.YES) THEN
819 -- completion allocation from Tomove of the last op. This logic
820 -- will be used in completion part of EZ Completion transactions
821 l_cur_qty := l_cur_qty + l_rsa.toMoveQty;
822 END IF;
823 END IF; -- Return transactions from form
824
825 IF (p_oc_txn_type = WIP_CONSTANTS.child_txn) THEN
826 NULL; -- just allocate everything to the last schedule
827 ELSE
828 IF (l_cur_qty > 0) THEN
829 l_quantity := l_quantity - l_cur_qty;
830 IF (l_quantity <= 0) THEN
831 l_cur_qty := l_cur_qty + l_quantity;
832 l_need_more := FALSE;
833 END IF;
834 -- increase schedule count by 1 IF found record
835 x_sche_count := x_sche_count + 1;
836 x_rsa(x_sche_count).scheID := l_scheID;
837 x_rsa(x_sche_count).scheQty := l_cur_qty;
838 END IF; -- l_cur_qty > 0
839 END IF; -- child txn
840 END IF; -- c_rsa%NOTFOUND
841 END LOOP; -- while
842
843 IF(p_oc_txn_type = WIP_CONSTANTS.parent_txn) THEN
844 -- IF parent and came here, it means that the whole quantity was
845 -- fulfilled without needing overcompletion. In that case it must be
846 -- an error
847 x_proc_status := TVE_OVERCOMPLETION_MISMATCH;
848 l_errMsg := 'Overcompletion mismatch';
849 raise fnd_api.g_exc_unexpected_error;
850 END IF;
851
852 -- for parent transaction, it always come here because the available
853 -- qty is not enough. Child transaction also come here
854 <<no_data>>
855
856 IF (l_recordFound = 0) THEN -- no schedule found
857 l_errMsg := 'No repetitive schedule found';
858 raise fnd_api.g_exc_unexpected_error;
859 ELSIF((p_oc_txn_type = WIP_CONSTANTS.parent_txn OR
860 (p_txnType = WIP_CONSTANTS.RET_TXN AND
861 p_fm_form = WIP_CONSTANTS.YES)) AND
862 l_quantity > 0) THEN
863 -- parent may have some allocation already made or none
864 IF (x_sche_count = 0) THEN -- no allocation made yet
865 x_sche_count := 1;
866 x_rsa(x_sche_count).scheID := l_scheID;
867 x_rsa(x_sche_count).scheQty := l_quantity;
868 ELSE
869 IF (x_rsa(x_sche_count).scheID = l_scheID) THEN
870 -- there is an allocation made to the last schedule already
871 x_rsa(x_sche_count).scheQty := x_rsa(x_sche_count).scheQty +
872 l_quantity;
873 ELSE
874 -- all allocation were made to schedules other than the last schedule
875 x_sche_count := x_sche_count + 1;
876 x_rsa(x_sche_count).scheID := l_scheID;
877 x_rsa(x_sche_count).scheQty := l_quantity;
878 END IF;
879 END IF; -- x_sche_count = 0
880 ELSIF(p_oc_txn_type = WIP_CONSTANTS.child_txn) THEN
881 -- no allocation should be there yet
882 x_sche_count := 1;
883 x_rsa(x_sche_count).scheID := l_scheID;
884 x_rsa(x_sche_count).scheQty := l_quantity;
885
886 ELSE -- IF normal txn
887 IF(p_fm_form = WIP_CONSTANTS.YES) THEN
888 -- skip this validation if call from from because there may be
889 -- a case that completed quantity is negative for repetitive
890 NULL;
891 ELSE
892 IF(l_quantity > 0) THEN
893 -- user insert incorrect value for normal transaction txn qty must
894 -- be less than or equal to available qty
895 x_proc_status := TVE_NO_MOVE_ALLOC;
896 l_errMsg := 'Not enough qty to move';
897 raise fnd_api.g_exc_unexpected_error;
898 END IF;
899 END IF;
900 END IF; -- no schedule found
901
902 IF(c_rsa%ISOPEN) THEN
903 CLOSE c_rsa;
904 END IF;
905 x_returnStatus := fnd_api.g_ret_sts_success;
906 x_proc_status := WIP_CONSTANTS.RUNNING;
907 -- write to the log file
908 IF (l_logLevel <= wip_constants.trace_logging) THEN
909 wip_logger.exitPoint(p_procName => 'wip_movProc_priv.schedule_alloc',
910 p_procReturnStatus => x_returnStatus,
911 p_msg => 'procedure complete',
912 x_returnStatus => l_returnStatus);
913 END IF;
914
915 EXCEPTION
916 WHEN fnd_api.g_exc_unexpected_error THEN
917 IF(c_rsa%ISOPEN) THEN
918 CLOSE c_rsa;
919 END IF;
920 x_returnStatus := fnd_api.g_ret_sts_unexp_error;
921
922 IF (l_logLevel <= wip_constants.trace_logging) THEN
923 wip_logger.exitPoint(p_procName => 'wip_movProc_priv.schedule_alloc',
924 p_procReturnStatus => x_returnStatus,
925 p_msg => l_errMsg,
926 x_returnStatus => l_returnStatus);
927 END IF;
928
929 /* Fix for bug 5373061: Passed missing token */
930 fnd_message.set_name('WIP','WIP_INT_ERROR_NO_SCHED');
931 fnd_message.set_token('ROUTINE', 'wip_movProc_priv.schedule_alloc');
932 fnd_msg_pub.add;
933
934 WHEN others THEN
935 IF(c_rsa%ISOPEN) THEN
936 CLOSE c_rsa;
937 END IF;
938 x_returnStatus := fnd_api.g_ret_sts_unexp_error;
939 x_proc_status := WIP_CONSTANTS.ERROR;
940 l_errMsg := 'unexpected error: ' || SQLERRM || 'SQLCODE = ' || SQLCODE;
941
942 IF (l_logLevel <= wip_constants.trace_logging) THEN
943 wip_logger.exitPoint(p_procName => 'wip_movProc_priv.schedule_alloc',
944 p_procReturnStatus => x_returnStatus,
945 p_msg => l_errMsg,
946 x_returnStatus => l_returnStatus);
947 END IF;
948 fnd_message.set_name('FND', 'FND_GENERIC_MESSAGE');
949 fnd_message.set_token('MESSAGE', l_errMsg);
950 fnd_msg_pub.add;
951 END schedule_alloc;
952
953 /*****************************************************************************
954 * This procedure is equivalent to witoc_insert_alloc_child in wiltps.ppc
955 * This procedure is used to insert child record into WIP_MOVE_TXN_INTERFACE
956 * and WIP_MOVE_TXN_ALLOCATIONS
957 ****************************************************************************/
958 PROCEDURE insert_alloc_child(p_org_id IN NUMBER,
959 p_scheID IN NUMBER,
960 p_oc_pri_qty IN NUMBER,
961 p_parent_txn_id IN NUMBER,
962 p_gib IN OUT NOCOPY group_rec_t,
963 x_oc_fm_op OUT NOCOPY NUMBER,
964 x_returnStatus OUT NOCOPY VARCHAR2) IS
965
966 l_params wip_logger.param_tbl_t;
967 l_returnStatus VARCHAR(1);
968 l_errMsg VARCHAR2(240);
969 l_msgData VARCHAR2(240);
970 l_first_op_code VARCHAR2(4);
971 l_first_dept_code VARCHAR2(10);
972 l_first_dept_id NUMBER := 0;
973 l_first_op_seq_num NUMBER := 0;
974 l_oc_txn_id NUMBER := 0;
975 l_logLevel NUMBER := fnd_log.g_current_runtime_level;
976
977 BEGIN
978 -- write parameter value to log file
979 IF (l_logLevel <= wip_constants.trace_logging) THEN
980 l_params(1).paramName := 'p_org_id';
981 l_params(1).paramValue := p_org_id;
982 l_params(2).paramName := 'p_scheID';
983 l_params(2).paramValue := p_scheID;
984 l_params(3).paramName := 'p_oc_pri_qty';
985 l_params(3).paramValue := p_oc_pri_qty;
986 l_params(4).paramName := 'p_parent_txn_id';
987 l_params(4).paramValue := p_parent_txn_id;
988 l_params(5).paramName := 'child_txn_id';
989 l_params(5).paramValue := p_gib.move_profile.child_txn_id;
990 wip_logger.entryPoint(p_procName => 'wip_movProc_priv.insert_alloc_child',
991 p_params => l_params,
992 x_returnStatus => l_returnStatus);
993 END IF;
994
995 -- call PL/SQL api to insert to WMTI
996 WIP_OVERCOMPLETION.insert_child_move_txn
997 (p_primary_quantity => p_oc_pri_qty,
998 p_parent_txn_id => p_parent_txn_id,
999 -- pass move_profile equal to background so that it will always insert
1000 -- parent group_id to child group_id
1001 p_move_profile => WIP_CONSTANTS.BACKGROUND,
1002 p_sched_id => p_scheID,
1003 p_user_id => p_gib.user_id,
1004 p_login_id => p_gib.login_id,
1005 p_req_id => p_gib.request_id,
1006 p_appl_id => p_gib.application_id,
1007 p_prog_id => p_gib.program_id,
1008 p_child_txn_id => p_gib.move_profile.child_txn_id,
1009 p_oc_txn_id => l_oc_txn_id,
1010 p_first_operation_seq_num => l_first_op_seq_num,
1011 p_first_operation_code => l_first_op_code,
1012 p_first_department_id => l_first_dept_id,
1013 p_first_department_code => l_first_dept_code,
1014 p_err_mesg => l_msgData);
1015
1016 IF(p_gib.move_profile.child_txn_id IS NULL) THEN
1017 l_errMsg := 'WIP_OVERCOMPLETION.insert_child_move_txn failed';
1018 raise fnd_api.g_exc_unexpected_error;
1019 END IF;
1020
1021 IF(l_first_op_seq_num IS NOT NULL) THEN
1022 x_oc_fm_op := l_first_op_seq_num;
1023 ELSE
1024 l_errMsg := 'wip_operations_INFO.first_operation failed';
1025 raise fnd_api.g_exc_unexpected_error;
1026 END IF;
1027
1028 IF(p_scheID > 0) THEN
1029 -- this is a repetitvie schedule, hence must insert allocation records
1030 -- to wip_move_txn_allocations as well
1031 INSERT INTO wip_move_txn_allocations
1032 (transaction_id,
1033 repetitive_schedule_id,
1034 organization_id,
1035 last_update_date,
1036 last_updated_by,
1037 creation_date,
1038 created_by,
1039 last_update_login,
1040 request_id,
1041 program_application_id,
1042 program_id,
1043 program_update_date,
1044 transaction_quantity,
1045 primary_quantity)
1046 (SELECT p_gib.move_profile.child_txn_id,
1047 repetitive_schedule_id,
1048 organization_id,
1049 SYSDATE, /* last_update_date, */
1050 last_updated_by,
1051 SYSDATE, /* creation_date */
1052 created_by,
1053 last_update_login,
1054 request_id,
1055 program_application_id,
1056 program_id,
1057 SYSDATE, /* program_update_date */
1058 p_oc_pri_qty,
1059 p_oc_pri_qty
1060 FROM wip_move_txn_allocations wmta
1061 WHERE wmta.transaction_id = p_parent_txn_id
1062 AND wmta.organization_id = p_org_id
1063 AND wmta.repetitive_schedule_id =
1064 (SELECT MAX(wmta1.repetitive_schedule_id)
1065 FROM wip_move_txn_allocations wmta1
1066 WHERE wmta1.transaction_id = wmta.transaction_id
1067 AND wmta1.organization_id = wmta.organization_id));
1068 END IF; -- p_scheID > 0
1069 x_returnStatus := fnd_api.g_ret_sts_success;
1070
1071 -- write to the log file
1072 IF (l_logLevel <= wip_constants.trace_logging) THEN
1073 wip_logger.exitPoint(p_procName => 'wip_movProc_priv.insert_alloc_child',
1074 p_procReturnStatus => x_returnStatus,
1075 p_msg => 'procedure complete',
1076 x_returnStatus => l_returnStatus);
1077 END IF;
1078
1079 EXCEPTION
1080 WHEN fnd_api.g_exc_unexpected_error THEN
1081
1082 x_returnStatus := fnd_api.g_ret_sts_unexp_error;
1083
1084 IF (l_logLevel <= wip_constants.trace_logging) THEN
1085 wip_logger.exitPoint(p_procName => 'wip_movProc_priv.insert_alloc_child',
1086 p_procReturnStatus => x_returnStatus,
1087 p_msg => l_errMsg,
1088 x_returnStatus => l_returnStatus);
1089 END IF;
1090
1091 fnd_message.set_name('FND', 'FND_GENERIC_MESSAGE');
1092 fnd_message.set_token('MESSAGE', l_msgData);
1093 fnd_msg_pub.add;
1094
1095 WHEN others THEN
1096 x_returnStatus := fnd_api.g_ret_sts_unexp_error;
1097 l_errMsg := 'unexpected error: ' || SQLERRM || 'SQLCODE = ' || SQLCODE;
1098
1099 IF (l_logLevel <= wip_constants.trace_logging) THEN
1100 wip_logger.exitPoint(p_procName => 'wip_movProc_priv.insert_alloc_child',
1101 p_procReturnStatus => x_returnStatus,
1102 p_msg => l_errMsg,
1103 x_returnStatus => l_returnStatus);
1104 END IF;
1105 fnd_message.set_name('FND', 'FND_GENERIC_MESSAGE');
1106 fnd_message.set_token('MESSAGE', l_errMsg);
1107 fnd_msg_pub.add;
1108 END insert_alloc_child;
1109
1110 /*****************************************************************************
1111 * This procedure is equivalent to wip_update_wo_rs in wiltps.ppc
1112 * This procedure is used to update WIP_OPERATIONS table for repetitive sche
1113 ****************************************************************************/
1114 PROCEDURE update_wo_rs(p_scheCount IN NUMBER,
1115 p_rsa_rec IN update_rsa_tbl_t,
1116 p_txn_date IN DATE,
1117 x_returnStatus OUT NOCOPY VARCHAR2) IS
1118
1119 l_params wip_logger.param_tbl_t;
1120 l_returnStatus VARCHAR(1);
1121 l_errMsg VARCHAR2(240);
1122 l_logLevel NUMBER := fnd_log.g_current_runtime_level;
1123 l_forward_move NUMBER;
1124 BEGIN
1125 FOR i IN 1..p_scheCount LOOP
1126 -- write parameter value to log file
1127 IF (l_logLevel <= wip_constants.trace_logging) THEN
1128 l_params(1).paramName := 'p_scheID';
1129 l_params(1).paramValue := p_rsa_rec(i).scheID;
1130 l_params(2).paramName := 'p_scheQty';
1131 l_params(2).paramValue := p_rsa_rec(i).scheQty;
1132 l_params(3).paramName := 'p_scheCount';
1133 l_params(3).paramValue := p_scheCount;
1134 l_params(4).paramName := 'p_wip_id';
1135 l_params(4).paramValue := p_rsa_rec(i).wipID;
1136 l_params(5).paramName := 'p_org_id';
1137 l_params(5).paramValue := p_rsa_rec(i).orgID;
1138 l_params(6).paramName := 'p_fm_op';
1139 l_params(6).paramValue := p_rsa_rec(i).fmOp;
1140 l_params(7).paramName := 'p_fm_step';
1141 l_params(7).paramValue := p_rsa_rec(i).fmStep;
1142 l_params(8).paramName := 'p_to_op';
1143 l_params(8).paramValue := p_rsa_rec(i).toOp;
1144 l_params(9).paramName := 'p_to_step';
1145 l_params(9).paramValue := p_rsa_rec(i).toStep;
1146 l_params(10).paramName := 'p_txn_date';
1147 l_params(10).paramValue := p_txn_date;
1148 wip_logger.entryPoint(p_procName => 'wip_movProc_priv.update_wo_rs',
1149 p_params => l_params,
1150 x_returnStatus => l_returnStatus);
1151 END IF;
1152
1153 END LOOP;
1154
1155 FOR i IN 1..p_scheCount LOOP
1156
1157 UPDATE wip_operations wop
1158 SET (date_last_moved,
1159 last_updated_by,
1160 last_update_date,
1161 last_update_login,
1162 request_id,
1163 program_application_id,
1164 program_id,
1165 program_update_date,
1166 quantity_in_queue,
1167 quantity_running,
1168 quantity_waiting_to_move,
1169 quantity_rejected,
1170 quantity_scrapped) =
1171
1172 (SELECT DECODE(wop.operation_seq_num, p_rsa_rec(i).fmOp,
1173 p_txn_date,wop.date_last_moved),
1174 p_rsa_rec(i).updatedBy,
1175 SYSDATE,
1176 DECODE(p_rsa_rec(i).loginID, -1, NULL,p_rsa_rec(i).loginID),
1177 DECODE(p_rsa_rec(i).reqID, -1, NULL, p_rsa_rec(i).reqID),
1178 DECODE(p_rsa_rec(i).appID, -1, NULL, p_rsa_rec(i).appID),
1179 DECODE(p_rsa_rec(i).progID, -1, NULL, p_rsa_rec(i).progID),
1180 DECODE(p_rsa_rec(i).reqID, -1, NULL, SYSDATE),
1181 wop.quantity_in_queue + SUM(
1182 DECODE(wop.operation_seq_num, p_rsa_rec(i).fmOp,
1183 -1 * DECODE(p_rsa_rec(i).fmStep,
1184 1, ROUND(p_rsa_rec(i).scheQty,
1185 WIP_CONSTANTS.INV_MAX_PRECISION),0),0) +
1186 DECODE(wop.operation_seq_num, p_rsa_rec(i).toOp,
1187 DECODE(p_rsa_rec(i).toStep,
1188 1, ROUND(p_rsa_rec(i).scheQty,
1189 WIP_CONSTANTS.INV_MAX_PRECISION), 0), 0)),
1190 wop.quantity_running + SUM(
1191 DECODE(wop.operation_seq_num, p_rsa_rec(i).fmOp,
1192 -1 * DECODE(p_rsa_rec(i).fmStep,
1193 2, ROUND(p_rsa_rec(i).scheQty,
1194 WIP_CONSTANTS.INV_MAX_PRECISION),0),0) +
1195 DECODE(wop.operation_seq_num, p_rsa_rec(i).toOp,
1196 DECODE(p_rsa_rec(i).toStep,
1197 2, ROUND(p_rsa_rec(i).scheQty,
1198 WIP_CONSTANTS.INV_MAX_PRECISION), 0), 0)),
1199 wop.quantity_waiting_to_move + SUM(
1200 DECODE(wop.operation_seq_num, p_rsa_rec(i).fmOp,
1201 -1 * DECODE(p_rsa_rec(i).fmStep,
1202 3, ROUND(p_rsa_rec(i).scheQty,
1203 WIP_CONSTANTS.INV_MAX_PRECISION),0),0) +
1204 DECODE(wop.operation_seq_num, p_rsa_rec(i).toOp,
1205 DECODE(p_rsa_rec(i).toStep,
1206 3, ROUND(p_rsa_rec(i).scheQty,
1207 WIP_CONSTANTS.INV_MAX_PRECISION), 0), 0)),
1208 wop.quantity_rejected + SUM(
1209 DECODE(wop.operation_seq_num, p_rsa_rec(i).fmOp,
1210 -1*DECODE(p_rsa_rec(i).fmStep,
1211 4, ROUND(p_rsa_rec(i).scheQty,
1212 WIP_CONSTANTS.INV_MAX_PRECISION), 0), 0) +
1213 DECODE(wop.operation_seq_num, p_rsa_rec(i).toOp,
1214 DECODE(p_rsa_rec(i).toStep,
1215 4, ROUND(p_rsa_rec(i).scheQty,
1216 WIP_CONSTANTS.INV_MAX_PRECISION), 0), 0)),
1217 wop.quantity_scrapped + SUM(
1218 DECODE(wop.operation_seq_num, p_rsa_rec(i).fmOp,
1219 -1*DECODE(p_rsa_rec(i).fmStep,
1220 5, ROUND(p_rsa_rec(i).scheQty,
1221 WIP_CONSTANTS.INV_MAX_PRECISION), 0), 0) +
1222 DECODE(wop.operation_seq_num, p_rsa_rec(i).toOp,
1223 DECODE(p_rsa_rec(i).toStep,
1224 5, ROUND(p_rsa_rec(i).scheQty,
1225 WIP_CONSTANTS.INV_MAX_PRECISION), 0), 0))
1226 FROM wip_operations wop1
1227 WHERE wop1.rowid = wop.rowid
1228 AND wop1.organization_id = p_rsa_rec(i).orgID
1229 AND wop1.wip_entity_id = p_rsa_rec(i).wipID
1230 AND wop1.repetitive_schedule_id = p_rsa_rec(i).scheID
1231 AND (wop1.operation_seq_num = p_rsa_rec(i).fmOp
1232 OR wop1.operation_seq_num = p_rsa_rec(i).toOp))
1233 WHERE wop.rowid IN
1234 (SELECT wop2.rowid
1235 FROM wip_operations wop2
1236 WHERE wop2.organization_id = p_rsa_rec(i).orgID
1237 AND wop2.wip_entity_id = p_rsa_rec(i).wipID
1238 AND wop2.repetitive_schedule_id = p_rsa_rec(i).scheID
1239 AND (wop2.operation_seq_num = p_rsa_rec(i).fmOp
1240 OR wop2.operation_seq_num = p_rsa_rec(i).toOp));
1241
1242 /* Enhancement 2864382*/
1243 IF(p_rsa_rec(i).fmStep = WIP_CONSTANTS.SCRAP AND p_rsa_rec(i).toStep = WIP_CONSTANTS.SCRAP) THEN
1244 l_forward_move := WIP_CONSTANTS.NO;
1245 IF(p_rsa_rec(i).fmOp < p_rsa_rec(i).toOp) THEN
1246 l_forward_move := WIP_CONSTANTS.YES;
1247 END IF;
1248
1249 UPDATE WIP_OPERATIONS wop
1250 SET wop.cumulative_scrap_quantity = wop.cumulative_scrap_quantity +
1251 DECODE(l_forward_move,
1252 WIP_CONSTANTS.YES,p_rsa_rec(i).scheQty,
1253 WIP_CONSTANTS.NO,-1 * p_rsa_rec(i).scheQty,
1254 0)
1255 WHERE wop.rowid in
1256 (SELECT wop1.rowid
1257 FROM WIP_OPERATIONS wop1
1258 WHERE wop1.organization_id = p_rsa_rec(i).orgID
1259 AND wop1.wip_entity_id = p_rsa_rec(i).wipID
1260 AND wop1.repetitive_schedule_id = p_rsa_rec(i).scheID
1261 AND wop1.operation_seq_num > LEAST(p_rsa_rec(i).fmOp,p_rsa_rec(i).toOp)
1262 AND wop1.operation_seq_num <= GREATEST(p_rsa_rec(i).fmOp,p_rsa_rec(i).toOp));
1263 ELSIF(p_rsa_rec(i).fmStep=WIP_CONSTANTS.SCRAP OR p_rsa_rec(i).toStep=WIP_CONSTANTS.SCRAP) THEN
1264 UPDATE WIP_OPERATIONS wop
1265 SET wop.cumulative_scrap_quantity = wop.cumulative_scrap_quantity +
1266 DECODE(p_rsa_rec(i).toStep,
1267 WIP_CONSTANTS.SCRAP,p_rsa_rec(i).scheQty,
1268 0) +
1269 DECODE(p_rsa_rec(i).fmStep,
1270 WIP_CONSTANTS.SCRAP,-1*p_rsa_rec(i).scheQty,
1271 0)
1272 WHERE wop.rowid in
1273 (SELECT wop1.rowid
1274 FROM WIP_OPERATIONS wop1
1275 WHERE wop1.organization_id = p_rsa_rec(i).orgID
1276 AND wop1.wip_entity_id = p_rsa_rec(i).wipID
1277 AND wop1.repetitive_schedule_id = p_rsa_rec(i).scheID
1278 AND wop1.operation_seq_num > DECODE(p_rsa_rec(i).fmStep,
1279 WIP_CONSTANTS.SCRAP,p_rsa_rec(i).fmOp,
1280 p_rsa_rec(i).toOp));
1281 END IF;
1282
1283
1284 END LOOP; -- END for loop
1285
1286 x_returnStatus := fnd_api.g_ret_sts_success;
1287
1288 -- write to the log file
1289 IF (l_logLevel <= wip_constants.trace_logging) THEN
1290 wip_logger.exitPoint(p_procName => 'wip_movProc_priv.update_wo_rs',
1291 p_procReturnStatus => x_returnStatus,
1292 p_msg => 'procedure complete',
1293 x_returnStatus => l_returnStatus);
1294 END IF;
1295
1296 EXCEPTION
1297 WHEN others THEN
1298 x_returnStatus := fnd_api.g_ret_sts_unexp_error;
1299 l_errMsg := 'unexpected error: ' || SQLERRM || 'SQLCODE = ' || SQLCODE;
1300
1301 IF (l_logLevel <= wip_constants.trace_logging) THEN
1302 wip_logger.exitPoint(p_procName => 'wip_movProc_priv.update_wo_rs',
1303 p_procReturnStatus => x_returnStatus,
1304 p_msg => l_errMsg,
1305 x_returnStatus => l_returnStatus);
1306 END IF;
1307 fnd_message.set_name('FND', 'FND_GENERIC_MESSAGE');
1308 fnd_message.set_token('MESSAGE', l_errMsg);
1309 fnd_msg_pub.add;
1310 END update_wo_rs;
1311
1312
1313 /*****************************************************************************
1314 * This procedure is equivalent to witoc_update_wo in wiltps5.ppc
1315 * This procedure is used to update qty in the queue step of the from
1316 * operatio for child move txns.
1317 ****************************************************************************/
1318 PROCEDURE update_wipops(p_txn_id IN NUMBER,
1319 p_gib IN group_rec_t,
1320 x_returnStatus OUT NOCOPY VARCHAR2) IS
1321
1322 l_params wip_logger.param_tbl_t;
1323 l_returnStatus VARCHAR2(1);
1324 l_errMsg VARCHAR2(240);
1325 l_logLevel NUMBER := fnd_log.g_current_runtime_level;
1326
1327 BEGIN
1328 -- write parameter values to log file
1329 IF (l_logLevel <= wip_constants.trace_logging) THEN
1330 l_params(1).paramName := 'p_txn_id';
1331 l_params(1).paramValue := p_txn_id;
1332 l_params(2).paramName := 'p_group_id';
1333 l_params(2).paramValue := p_gib.group_id;
1334 l_params(3).paramName := 'p_txn_date';
1335 l_params(3).paramValue := p_gib.txn_date;
1336 wip_logger.entryPoint(p_procName => 'wip_movProc_priv.update_wipops',
1337 p_params => l_params,
1338 x_returnStatus => l_returnStatus);
1339 END IF;
1340
1341 UPDATE wip_operations wop
1342 SET (quantity_in_queue,
1343 last_updated_by,
1344 last_update_date,
1345 last_update_login,
1346 request_id,
1347 program_application_id,
1348 program_id,
1349 program_update_date
1350 ) =
1351 (SELECT wop.quantity_in_queue + wmti1.primary_quantity,
1352 p_gib.user_id,
1353 SYSDATE,
1354 DECODE(p_gib.login_id, -1, NULL, p_gib.login_id),
1355 DECODE(p_gib.request_id, -1, NULL, p_gib.request_id),
1356 DECODE(p_gib.application_id, -1, NULL, p_gib.application_id),
1357 DECODE(p_gib.program_id, -1, NULL, p_gib.program_id),
1358 DECODE(p_gib.request_id, -1, NULL, SYSDATE)
1359 FROM wip_operations wop1,
1360 wip_move_txn_interface wmti1,
1361 wip_move_txn_allocations wma1
1362 WHERE wop1.rowid = wop.rowid
1363 -- The WO rows to be updated are identIFied by the rowids.
1364 -- For each such row, go back and sum the quantities from WMTI
1365 AND wmti1.group_id = p_gib.group_id
1366 AND TRUNC(wmti1.transaction_date) = TRUNC(p_gib.txn_date)
1367 AND wmti1.transaction_id = p_txn_id
1368 AND wop1.wip_entity_id = wmti1.wip_entity_id
1369 AND wop1.organization_id = wmti1.organization_id
1370 AND wop1.operation_seq_num = wmti1.fm_operation_seq_num
1371 AND wmti1.organization_id = wma1.organization_id (+)
1372 AND wmti1.transaction_id = wma1.transaction_id (+)
1373 AND NVL(wma1.repetitive_schedule_id,0) =
1374 NVL(wop1.repetitive_schedule_id,0))
1375 -- the select below must return just 1 row. When Online, group_id
1376 -- is the same as transaction_id. When in BG, THEN the transaction_id
1377 -- must be passed.
1378 WHERE wop.rowid =
1379 (SELECT wop2.rowid
1380 FROM wip_operations wop2,
1381 wip_move_txn_interface wmti2,
1382 wip_move_txn_allocations wma2
1383 WHERE wmti2.group_id = p_gib.group_id
1384 AND TRUNC(wmti2.transaction_date) = TRUNC(p_gib.txn_date)
1385 AND wmti2.transaction_id = p_txn_id
1386 -- Picked a Move txn
1387 AND wop2.wip_entity_id = wmti2.wip_entity_id
1388 AND wop2.organization_id = wmti2.organization_id
1389 AND wop2.operation_seq_num = wmti2.fm_operation_seq_num
1390 AND wmti2.organization_id = wma2.organization_id (+)
1391 AND wmti2.transaction_id = wma2.transaction_id (+)
1392 AND NVL(wma2.repetitive_schedule_id,0) =
1393 NVL(wop2.repetitive_schedule_id,0));
1394 -- Picked the row corresponding to the txn. 1 each for such txns
1395 -- Rowids can be duplicate because there might be 2 wmti records with
1396 -- the same fm_op
1397
1398 x_returnStatus := fnd_api.g_ret_sts_success;
1399
1400 -- write to the log file
1401 IF (l_logLevel <= wip_constants.trace_logging) THEN
1402 wip_logger.exitPoint(p_procName => 'wip_movProc_priv.update_wipops',
1403 p_procReturnStatus => x_returnStatus,
1404 p_msg => 'procedure complete',
1405 x_returnStatus => l_returnStatus);
1406 END IF;
1407
1408 EXCEPTION
1409 WHEN OTHERS THEN
1410 x_returnStatus := fnd_api.g_ret_sts_unexp_error;
1411 l_errMsg := 'unexpected error: ' || SQLERRM || 'SQLCODE = ' || SQLCODE;
1412
1413 IF (l_logLevel <= wip_constants.trace_logging) THEN
1414 wip_logger.exitPoint(p_procName => 'wip_movProc_priv.update_wipops',
1415 p_procReturnStatus => x_returnStatus,
1416 p_msg => l_errMsg,
1417 x_returnStatus => l_returnStatus);
1418 END IF;
1419 fnd_message.set_name('FND', 'FND_GENERIC_MESSAGE');
1420 fnd_message.set_token('MESSAGE', l_errMsg);
1421 fnd_msg_pub.add;
1422 END update_wipops;
1423
1424 /*****************************************************************************
1425 * This procedure is equivalent to witpsma_move_alloc in wiltps.ppc
1426 * This procedure is used to allocate repetitive schedule.
1427 * Need to check the negative quantities and make sure schedule is still
1428 * Released.
1429 ****************************************************************************/
1430 PROCEDURE rep_move_alloc(p_gib IN OUT NOCOPY group_rec_t,
1431 x_returnStatus OUT NOCOPY VARCHAR2) IS
1432
1433 CURSOR c_rs_txn(p_timeout NUMBER,
1434 p_group_id NUMBER,
1435 p_txn_date DATE) IS
1436
1437 SELECT created_by,
1438 last_updated_by last_upd_by,
1439 transaction_id txn_id,
1440 organization_id org_id,
1441 wip_entity_id wip_id,
1442 line_id,
1443 transaction_uom txn_uom,
1444 transaction_quantity txn_qty,
1445 primary_quantity primary_qty,
1446 fm_operation_seq_num fm_op,
1447 fm_intraoperation_step_type fm_step,
1448 to_operation_seq_num to_op,
1449 to_intraoperation_step_type to_step,
1450 DECODE(SIGN(86400*(SYSDATE - creation_date) - p_timeout),
1451 1,1,0,0,-1,0) past_timeout,
1452 NVL(overcompletion_primary_qty,0) oc_pri_qty,
1453 DECODE(NVL(overcompletion_primary_qty,-1),
1454 -1,DECODE(NVL(overcompletion_transaction_id,-1),
1455 -1,WIP_CONSTANTS.normal_txn,
1456 WIP_CONSTANTS.child_txn),
1457 WIP_CONSTANTS.parent_txn) oc_txn_type,
1458 transaction_type txn_type,
1459 transaction_date txn_date
1460 FROM wip_move_txn_interface
1461 WHERE group_id = p_group_id
1462 AND TRUNC(transaction_date) = TRUNC(p_txn_date)
1463 AND process_phase = WIP_CONSTANTS.MOVE_PROC
1464 AND process_status = WIP_CONSTANTS.RUNNING
1465 AND entity_type = WIP_CONSTANTS.REPETITIVE
1466 ORDER BY transaction_date, organization_id, wip_entity_id, line_id,
1467 fm_operation_seq_num, to_operation_seq_num,
1468 fm_intraoperation_step_type, to_intraoperation_step_type,
1469 creation_date;
1470
1471 l_rs_txn c_rs_txn%ROWTYPE;
1472 l_params wip_logger.param_tbl_t;
1473 l_rsa rsa_tbl_t;
1474 l_update_rsa update_rsa_tbl_t;
1475 l_returnStatus VARCHAR(1);
1476 l_errMsg VARCHAR2(240);
1477 l_msg VARCHAR(2000);
1478 l_sche_count NUMBER;
1479 l_oc_fm_op NUMBER;
1480 l_rec_count NUMBER :=0;
1481 l_proc_status NUMBER;
1482 l_logLevel NUMBER := fnd_log.g_current_runtime_level;
1483 l_msg_data VARCHAR2(2000);
1484 l_propagate_job_change_to_po NUMBER;
1485 BEGIN
1486 -- write parameter value to log file
1487 IF (l_logLevel <= wip_constants.trace_logging) THEN
1488 l_params(1).paramName := 'p_group_id';
1489 l_params(1).paramValue := p_gib.group_id;
1490 l_params(2).paramName := 'p_timeout';
1491 l_params(2).paramValue := p_gib.time_out;
1492 l_params(3).paramName := 'p_txn_date';
1493 l_params(3).paramValue := p_gib.txn_date;
1494 l_params(4).paramName := 'p_login_id';
1495 l_params(4).paramValue := p_gib.login_id;
1496 l_params(5).paramName := 'p_request_id';
1497 l_params(5).paramValue := p_gib.request_id;
1498 l_params(6).paramName := 'p_application_id';
1499 l_params(6).paramValue := p_gib.application_id;
1500 l_params(7).paramName := 'p_program_id';
1501 l_params(7).paramValue := p_gib.program_id;
1502 l_params(8).paramName := 'p_move_mode';
1503 l_params(8).paramValue := p_gib.move_mode;
1504 l_params(9).paramName := 'p_backflush_mode';
1505 l_params(9).paramValue := p_gib.bf_mode;
1506 wip_logger.entryPoint(p_procName => 'wip_movProc_priv.rep_move_alloc',
1507 p_params => l_params,
1508 x_returnStatus => l_returnStatus);
1509 END IF;
1510
1511 OPEN c_rs_txn(p_timeout => p_gib.time_out,
1512 p_group_id => p_gib.group_id,
1513 p_txn_date => p_gib.txn_date);
1514 LOOP
1515 BEGIN
1516 FETCH c_rs_txn INTO l_rs_txn;
1517
1518 IF(c_rs_txn%NOTFOUND) THEN
1519 GOTO END_loop;
1520 ELSE
1521 l_rec_count := l_rec_count + 1;
1522 -- call schedule to allocate qty to schedule
1523 schedule_alloc(p_org_id => l_rs_txn.org_id,
1524 p_wip_id => l_rs_txn.wip_id,
1525 p_line_id => l_rs_txn.line_id ,
1526 p_quantity => l_rs_txn.primary_qty,
1527 p_fm_op => l_rs_txn.fm_op,
1528 p_fm_step => l_rs_txn.fm_step,
1529 p_to_op => l_rs_txn.to_op,
1530 p_to_step => l_rs_txn.to_step,
1531 p_oc_txn_type => l_rs_txn.oc_txn_type,
1532 p_txnType => l_rs_txn.txn_type,
1533 p_fm_form => WIP_CONSTANTS.NO,
1534 p_comp_alloc => WIP_CONSTANTS.NO,
1535 p_txn_date => l_rs_txn.txn_date, /* Bug 5373061 */
1536 x_proc_status => l_proc_status,
1537 x_sche_count => l_sche_count,
1538 x_rsa => l_rsa,
1539 x_returnStatus => x_returnStatus);
1540 IF (l_logLevel <= wip_constants.full_logging) THEN
1541 wip_logger.log(p_msg => 'l_proc_status = ' || l_proc_status,
1542 x_returnStatus => l_returnStatus);
1543 wip_logger.log(p_msg => 'l_sche_count = ' || l_sche_count,
1544 x_returnStatus => l_returnStatus);
1545 END IF;
1546
1547 IF(l_proc_status = WIP_CONSTANTS.RUNNING) THEN
1548
1549 FOR i IN 1..l_sche_count LOOP
1550 INSERT INTO wip_move_txn_allocations
1551 (transaction_id,
1552 repetitive_schedule_id,
1553 organization_id,
1554 last_update_date,
1555 last_updated_by,
1556 creation_date,
1557 created_by,
1558 last_update_login,
1559 request_id,
1560 program_application_id,
1561 program_id,
1562 program_update_date,
1563 transaction_quantity,
1564 primary_quantity)
1565 VALUES(l_rs_txn.txn_id,
1566 l_rsa(i).scheID,
1567 l_rs_txn.org_id,
1568 SYSDATE,
1569 l_rs_txn.last_upd_by,
1570 SYSDATE,
1571 l_rs_txn.created_by, -- Fix for bug 5195072
1572 DECODE(p_gib.login_id,-1,NULL,p_gib.login_id),
1573 DECODE(p_gib.request_id,-1,NULL,p_gib.request_id),
1574 DECODE(p_gib.application_id,-1,NULL,p_gib.application_id),
1575 DECODE(p_gib.program_id,-1,NULL,p_gib.program_id),
1576 DECODE(p_gib.request_id,-1,NULL,SYSDATE),
1577 l_rs_txn.txn_qty * l_rsa(i).scheQty /
1578 l_rs_txn.primary_qty, -- transaction_quantity
1579 ROUND(l_rsa(i).scheQty,
1580 WIP_CONSTANTS.INV_MAX_PRECISION)); -- primary_quantity
1581 END LOOP; --END for loop
1582
1583 IF(l_rs_txn.oc_txn_type = WIP_CONSTANTS.child_txn) THEN
1584
1585 -- update qty in the queue step of the from operation
1586 -- for child move txns.
1587 update_wipops(p_txn_id => l_rs_txn.txn_id,
1588 p_gib => p_gib,
1589 x_returnStatus => x_returnStatus);
1590
1591 IF (x_returnStatus <> fnd_api.g_ret_sts_success) THEN
1592 l_errMsg := 'wip_movProc_priv.update_wipops failed';
1593 raise fnd_api.g_exc_unexpected_error;
1594 END IF;
1595
1596 END IF; -- child txns
1597
1598 IF(l_rs_txn.oc_txn_type = WIP_CONSTANTS.parent_txn) THEN
1599 -- all procedure in this loop is pretty much for child record
1600 -- IF it is over completion/move txn, insert child record to WMTI
1601 insert_alloc_child(p_org_id => l_rs_txn.org_id,
1602 p_scheID => l_rsa(1).scheID,
1603 p_oc_pri_qty => l_rs_txn.oc_pri_qty,
1604 p_parent_txn_id => l_rs_txn.txn_id,
1605 p_gib => p_gib,
1606 x_oc_fm_op => l_oc_fm_op,
1607 x_returnStatus => x_returnStatus);
1608
1609 IF (x_returnStatus <> fnd_api.g_ret_sts_success) THEN
1610
1611 IF (l_rs_txn.past_timeout = 0) THEN -- not time out yet
1612 UPDATE wip_move_txn_interface
1613 SET process_status = WIP_CONSTANTS.PENDING,
1614 group_id = NULL,
1615 transaction_id = NULL
1616 WHERE transaction_id = l_rs_txn.txn_id
1617 AND group_id = p_gib.group_id;
1618 END IF; -- time out check
1619
1620 l_errMsg := 'wip_movProc_priv.insert_alloc_child failed';
1621 raise fnd_api.g_exc_unexpected_error;
1622
1623 ELSE -- insert child success
1624 -- insert assemblies in the queue of the first operation after
1625 -- the child record is inserted
1626 update_wipops(p_txn_id => p_gib.move_profile.child_txn_id,
1627 p_gib => p_gib,
1628 x_returnStatus => x_returnStatus);
1629
1630 IF (x_returnStatus <> fnd_api.g_ret_sts_success) THEN
1631 l_errMsg := 'wip_movProc_priv.update_wipops failed';
1632 raise fnd_api.g_exc_unexpected_error;
1633 END IF;
1634
1635 -- prepare data before calling update_wo_rs
1636 l_update_rsa(1).scheID := l_rsa(l_sche_count).scheID;
1637 l_update_rsa(1).scheQty := l_rs_txn.oc_pri_qty;
1638 l_update_rsa(1).loginID := p_gib.login_id;
1639 l_update_rsa(1).reqID := p_gib.request_id;
1640 l_update_rsa(1).appID := p_gib.application_id;
1641 l_update_rsa(1).progID := p_gib.program_id;
1642 l_update_rsa(1).createdBy := l_rs_txn.created_by;
1643 l_update_rsa(1).updatedBy := l_rs_txn.last_upd_by;
1644 l_update_rsa(1).orgID := l_rs_txn.org_id;
1645 l_update_rsa(1).wipID := l_rs_txn.wip_id;
1646 l_update_rsa(1).fmOp := l_oc_fm_op;
1647 l_update_rsa(1).toOp := l_rs_txn.fm_op;
1648 l_update_rsa(1).fmStep := WIP_CONSTANTS.QUEUE;
1649 l_update_rsa(1).toStep := l_rs_txn.fm_step;
1650
1651 update_wo_rs(p_scheCount => 1,
1652 p_rsa_rec => l_update_rsa,
1653 p_txn_date => l_rs_txn.txn_date,
1654 x_returnStatus => x_returnStatus);
1655
1656 IF (x_returnStatus <> fnd_api.g_ret_sts_success) THEN
1657 l_errMsg := 'wip_movProc_priv.update_wo_rs failed';
1658 raise fnd_api.g_exc_unexpected_error;
1659 END IF;
1660 END IF; -- insert_alloc_child check
1661
1662 IF(l_rs_txn.oc_pri_qty <> 0 AND
1663 po_code_release_grp.Current_Release >=
1664 po_code_release_grp.PRC_11i_Family_Pack_J) THEN
1665
1666 SELECT propagate_job_change_to_po
1667 INTO l_propagate_job_change_to_po
1668 FROM wip_parameters
1669 WHERE organization_id = l_rs_txn.org_id;
1670
1671 IF(l_propagate_job_change_to_po = WIP_CONSTANTS.YES) THEN
1672 wip_osp.updatePOReqQuantity(
1673 p_job_id => l_rs_txn.wip_id,
1674 p_repetitive_id => l_rsa(1).scheID,
1675 p_org_id => l_rs_txn.org_id,
1676 p_changed_qty => l_rs_txn.oc_pri_qty,
1677 /* Fix for Bug#4746495. PO linked to current Operation should
1678 * not be updated. Only future PO should be updated.
1679 */
1680 p_fm_op => l_rs_txn.fm_op,
1681 x_return_status => x_returnStatus);
1682
1683 IF(x_returnStatus <> fnd_api.g_ret_sts_success) THEN
1684 l_errMsg := 'wip_osp.updatePOReqQuantity failed';
1685 raise fnd_api.g_exc_unexpected_error;
1686 END IF; -- l_return_status
1687 END IF; -- l_propagate_job_change_to_po = WIP_CONSTANTS.YES
1688 END IF; -- l_rs_txn.oc_pri_qty <> 0 and customer have PO FPJ
1689 END IF; -- IF parent_txn
1690
1691 -- prepare data before calling update_wo_rs
1692 FOR i IN 1..l_sche_count LOOP
1693 l_update_rsa(i).scheID := l_rsa(i).scheID;
1694 l_update_rsa(i).scheQty := l_rsa(i).scheQty;
1695 l_update_rsa(i).loginID := p_gib.login_id;
1696 l_update_rsa(i).reqID := p_gib.request_id;
1697 l_update_rsa(i).appID := p_gib.application_id;
1698 l_update_rsa(i).progID := p_gib.program_id;
1699 l_update_rsa(i).createdBy := l_rs_txn.created_by;
1700 l_update_rsa(i).updatedBy := l_rs_txn.last_upd_by;
1701 l_update_rsa(i).orgID := l_rs_txn.org_id;
1702 l_update_rsa(i).wipID := l_rs_txn.wip_id;
1703 l_update_rsa(i).fmOp := l_rs_txn.fm_op;
1704 l_update_rsa(i).toOp := l_rs_txn.to_op;
1705 l_update_rsa(i).fmStep := l_rs_txn.fm_step;
1706 l_update_rsa(i).toStep := l_rs_txn.to_step ;
1707 END LOOP;
1708 -- update wip_operations
1709 update_wo_rs(p_scheCount => l_sche_count,
1710 p_rsa_rec => l_update_rsa,
1711 p_txn_date => l_rs_txn.txn_date,
1712 x_returnStatus => x_returnStatus);
1713
1714 IF (x_returnStatus <> fnd_api.g_ret_sts_success) THEN
1715 l_errMsg := 'wip_movProc_priv.update_wo_rs failed';
1716 raise fnd_api.g_exc_unexpected_error;
1717 END IF;
1718
1719 ELSIF(l_proc_status = TVE_OVERCOMPLETION_MISMATCH OR
1720 l_proc_status = TVE_NO_MOVE_ALLOC) THEN
1721
1722 IF(p_gib.move_mode = WIP_CONSTANTS.BACKGROUND) THEN
1723 IF (l_rs_txn.past_timeout = 0) THEN -- not time out yet
1724 UPDATE wip_move_txn_interface
1725 SET process_status = WIP_CONSTANTS.PENDING,
1726 group_id = NULL,
1727 transaction_id = NULL
1728 WHERE transaction_id = l_rs_txn.txn_id
1729 AND group_id = p_gib.group_id;
1730 END IF; -- time out check
1731 END IF; -- BACKGROUND check
1732
1733 IF(l_proc_status = TVE_OVERCOMPLETION_MISMATCH) THEN
1734 fnd_message.set_name('WIP', 'WIP_OVERCOMPLETION_MISMATCH');
1735 fnd_msg_pub.add;
1736 l_errMsg := 'parent txn is not really overcompletion txn';
1737 raise fnd_api.g_exc_unexpected_error;
1738 ELSE
1739 fnd_message.set_name('WIP', 'WIP_LESS_OR_EQUAL');
1740 fnd_message.set_token('ENTITY1', 'transaction quantity');
1741 fnd_message.set_token('ENTITY2', 'quantity available to move');
1742 fnd_msg_pub.add;
1743 l_errMsg := 'available qty is not enough to fullfill move txn';
1744 raise fnd_api.g_exc_unexpected_error;
1745 END IF;
1746
1747 ELSIF(l_proc_status = WIP_CONSTANTS.ERROR) THEN
1748
1749 -- update move_interface table
1750 UPDATE wip_move_txn_interface
1751 SET process_status = WIP_CONSTANTS.ERROR
1752 WHERE transaction_id = l_rs_txn.txn_id
1753 AND group_id = p_gib.group_id;
1754
1755 l_errMsg := 'wip_movProc_priv.schedule_alloc failed';
1756 raise fnd_api.g_exc_unexpected_error;
1757
1758 END IF; -- process_status
1759
1760 END IF; -- c_rs_txn%NOTFOUND
1761 -- Fixed bug 4324706. Reset p_gib.move_profile.child_txn_id to null
1762 -- to prevent child move record got inserted with the same transaction_id.
1763 p_gib.move_profile.child_txn_id := null;
1764 -- Fixed bug 4406536. We should error out only problematic record and
1765 -- continue to process next record.
1766 EXCEPTION
1767 WHEN fnd_api.g_exc_unexpected_error THEN
1768 IF(p_gib.move_mode = WIP_CONSTANTS.BACKGROUND) THEN
1769 IF (l_rs_txn.past_timeout = 0) THEN -- not time out yet
1770 UPDATE wip_move_txn_interface
1771 SET process_status = WIP_CONSTANTS.PENDING,
1772 group_id = NULL,
1773 transaction_id = NULL
1774 WHERE transaction_id = l_rs_txn.txn_id
1775 AND group_id = p_gib.group_id;
1776 ELSE -- already time out
1777 UPDATE wip_move_txn_interface
1778 SET process_status = WIP_CONSTANTS.ERROR
1779 WHERE transaction_id = l_rs_txn.txn_id
1780 AND group_id = p_gib.group_id;
1781
1782 -- Get error from message stack
1783 wip_utilities.get_message_stack(p_msg =>l_msg);
1784 IF(l_msg IS NULL) THEN
1785 -- initialize message to something because we cannot insert
1786 -- null into WIP_TXN_INTERFACE_ERRORS
1787 fnd_message.set_name('WIP', 'WIP_SOME_RECORDS_ERROR');
1788 l_msg := fnd_message.get;
1789 END IF;
1790
1791 INSERT INTO WIP_TXN_INTERFACE_ERRORS
1792 (transaction_id,
1793 error_column,
1794 error_message,
1795 last_update_date,
1796 last_updated_by,
1797 creation_date,
1798 created_by,
1799 last_update_login,
1800 request_id,
1801 program_application_id,
1802 program_id,
1803 program_update_date)
1804 SELECT wmti.transaction_id,
1805 'TRANSACTION_QUANTITY', -- error_column
1806 substrb(l_msg,1,240), -- error_message
1807 SYSDATE, -- last_update_date
1808 wmti.last_updated_by, -- last_update_by
1809 SYSDATE, -- creation_date
1810 wmti.created_by, -- created_by
1811 p_gib.login_id,
1812 p_gib.request_id,
1813 p_gib.application_id,
1814 p_gib.program_id,
1815 SYSDATE -- program_update_date
1816 FROM wip_move_txn_interface wmti
1817 WHERE wmti.transaction_id = l_rs_txn.txn_id
1818 AND wmti.group_id = p_gib.group_id;
1819 END IF; -- time out check
1820 ELSE--Online processing
1821 --Bug 5210073: Raise an exception to rollback the changes in online mode.
1822 raise fnd_api.g_exc_unexpected_error;
1823 END IF; -- background check
1824 END;
1825 END LOOP;
1826
1827 <<END_loop>>
1828 IF (l_rec_count = 0) THEN -- no record found
1829 l_errMsg := 'No reptitive move record found';
1830 raise fnd_api.g_exc_unexpected_error;
1831
1832 ELSE
1833 IF(c_rs_txn%ISOPEN) THEN
1834 CLOSE c_rs_txn;
1835 END IF;
1836 x_returnStatus := fnd_api.g_ret_sts_success;
1837
1838 -- write to the log file
1839 IF (l_logLevel <= wip_constants.trace_logging) THEN
1840 wip_logger.exitPoint(p_procName => 'wip_movProc_priv.rep_move_alloc',
1841 p_procReturnStatus => x_returnStatus,
1842 p_msg => 'procedure complete',
1843 x_returnStatus => l_returnStatus);
1844 END IF;
1845
1846 END IF;
1847
1848 EXCEPTION
1849
1850 WHEN fnd_api.g_exc_unexpected_error THEN
1851 IF(c_rs_txn%ISOPEN) THEN
1852 CLOSE c_rs_txn;
1853 END IF;
1854 x_returnStatus := fnd_api.g_ret_sts_unexp_error;
1855
1856 IF (l_logLevel <= wip_constants.trace_logging) THEN
1857 wip_logger.exitPoint(p_procName => 'wip_movProc_priv.rep_move_alloc',
1858 p_procReturnStatus => x_returnStatus,
1859 p_msg => l_errMsg,
1860 x_returnStatus => l_returnStatus);
1861 END IF;
1862 WHEN others THEN
1863 IF(c_rs_txn%ISOPEN) THEN
1864 CLOSE c_rs_txn;
1865 END IF;
1866 x_returnStatus := fnd_api.g_ret_sts_unexp_error;
1867 l_errMsg := 'unexpected error: ' || SQLERRM || 'SQLCODE = ' || SQLCODE;
1868
1869 IF (l_logLevel <= wip_constants.trace_logging) THEN
1870 wip_logger.exitPoint(p_procName => 'wip_movProc_priv.rep_move_alloc',
1871 p_procReturnStatus => x_returnStatus,
1872 p_msg => l_errMsg,
1873 x_returnStatus => l_returnStatus);
1874 END IF;
1875 fnd_message.set_name('FND', 'FND_GENERIC_MESSAGE');
1876 fnd_message.set_token('MESSAGE', l_errMsg);
1877 fnd_msg_pub.add;
1878 END rep_move_alloc;
1879
1880 /*****************************************************************************
1881 * This procedure is equivalent to wip_update_wo_dj in wiltps.ppc
1882 * This procedure is used to update WIP_OPERATIONS table for discrete and
1883 * lotbased jobs.
1884 ****************************************************************************/
1885 PROCEDURE update_wo_dj(p_fm_op IN NUMBER,
1886 p_fm_step IN NUMBER,
1887 p_to_op IN NUMBER,
1888 p_to_step IN NUMBER,
1889 p_qty IN NUMBER,
1890 p_org_id IN NUMBER,
1891 p_wip_id IN NUMBER,
1892 p_txn_date IN DATE,
1893 p_gib IN group_rec_t,
1894 x_returnStatus OUT NOCOPY VARCHAR2) IS
1895
1896 l_params wip_logger.param_tbl_t;
1897 l_returnStatus VARCHAR(1);
1898 l_errMsg VARCHAR2(240);
1899 l_logLevel NUMBER := fnd_log.g_current_runtime_level;
1900 l_forward_move NUMBER;
1901
1902 BEGIN
1903 -- write parameter value to log file
1904 IF (l_logLevel <= wip_constants.trace_logging) THEN
1905 l_params(1).paramName := 'p_txn_date';
1906 l_params(1).paramValue := p_txn_date;
1907 l_params(2).paramName := 'p_fm_op';
1908 l_params(2).paramValue := p_fm_op;
1909 l_params(3).paramName := 'p_fm_step';
1910 l_params(3).paramValue := p_fm_step;
1911 l_params(4).paramName := 'p_to_op';
1912 l_params(4).paramValue := p_to_op;
1913 l_params(5).paramName := 'p_to_step';
1914 l_params(5).paramValue := p_to_step;
1915 l_params(6).paramName := 'p_qty';
1916 l_params(6).paramValue := p_qty;
1917 l_params(7).paramName := 'p_org_id';
1918 l_params(7).paramValue := p_org_id;
1919 l_params(8).paramName := 'p_wip_id';
1920 l_params(8).paramValue := p_wip_id;
1921 wip_logger.entryPoint(p_procName => 'wip_movProc_priv.update_wo_dj',
1922 p_params => l_params,
1923 x_returnStatus => l_returnStatus);
1924 END IF;
1925
1926 UPDATE wip_operations wop
1927 SET (date_last_moved,
1928 last_updated_by,
1929 last_update_date,
1930 last_update_login,
1931 request_id,
1932 program_application_id,
1933 program_id,
1934 program_update_date,
1935 quantity_in_queue,
1936 quantity_running,
1937 quantity_waiting_to_move,
1938 quantity_rejected,
1939 quantity_scrapped) =
1940
1941 (SELECT DECODE(wop.operation_seq_num,
1942 p_fm_op,p_txn_date, wop.date_last_moved),
1943 p_gib.user_id,
1944 SYSDATE,
1945 DECODE(p_gib.login_id,-1,NULL,p_gib.login_id),
1946 DECODE(p_gib.request_id,-1,NULL,p_gib.request_id),
1947 DECODE(p_gib.application_id,-1,NULL,p_gib.application_id),
1948 DECODE(p_gib.program_id,-1,NULL,p_gib.program_id),
1949 DECODE(p_gib.request_id,-1,NULL,SYSDATE),
1950 wop.quantity_in_queue + SUM(
1951 DECODE(wop.operation_seq_num,
1952 p_fm_op, -1 * DECODE(p_fm_step,
1953 1,ROUND(p_qty,
1954 WIP_CONSTANTS.INV_MAX_PRECISION),
1955 0),
1956 0) +
1957 DECODE(wop.operation_seq_num,
1958 p_to_op,DECODE(p_to_step,
1959 1,ROUND(p_qty,WIP_CONSTANTS.INV_MAX_PRECISION),
1960 0),
1961 0)),
1962 wop.quantity_running + SUM(
1963 DECODE(wop.operation_seq_num,
1964 p_fm_op, -1 * DECODE(p_fm_step,
1965 2,ROUND(p_qty,
1966 WIP_CONSTANTS.INV_MAX_PRECISION),
1967 0),
1968 0) +
1969 DECODE(wop.operation_seq_num,
1970 p_to_op,DECODE(p_to_step,
1971 2,ROUND(p_qty,WIP_CONSTANTS.INV_MAX_PRECISION),
1972 0),
1973 0)),
1974 wop.quantity_waiting_to_move + SUM(
1975 DECODE(wop.operation_seq_num,
1976 p_fm_op, -1 * DECODE(p_fm_step,
1977 3,ROUND(p_qty,
1978 WIP_CONSTANTS.INV_MAX_PRECISION),
1979 0),
1980 0) +
1981 DECODE(wop.operation_seq_num,
1982 p_to_op,DECODE(p_to_step,
1983 3,ROUND(p_qty,WIP_CONSTANTS.INV_MAX_PRECISION),
1984 0),
1985 0)),
1986 wop.quantity_rejected + SUM(
1987 DECODE(wop.operation_seq_num,
1988 p_fm_op,-1 * DECODE(p_fm_step,
1989 4,ROUND(p_qty,
1990 WIP_CONSTANTS.INV_MAX_PRECISION),
1991 0),
1992 0) +
1993 DECODE(wop.operation_seq_num,
1994 p_to_op,DECODE(p_to_step,
1995 4,ROUND(p_qty,WIP_CONSTANTS.INV_MAX_PRECISION),
1996 0),
1997 0)),
1998 wop.quantity_scrapped + SUM(
1999 DECODE(wop.operation_seq_num,
2000 p_fm_op,-1 * DECODE(p_fm_step,
2001 5,ROUND(p_qty,
2002 WIP_CONSTANTS.INV_MAX_PRECISION),
2003 0),
2004 0) +
2005 DECODE(wop.operation_seq_num,
2006 p_to_op,DECODE(p_to_step,
2007 5,ROUND(p_qty,WIP_CONSTANTS.INV_MAX_PRECISION),
2008 0),
2009 0))
2010 FROM wip_operations wop1
2011 WHERE wop1.rowid = wop.rowid
2012 AND wop1.organization_id = p_org_id
2013 AND wop1.wip_entity_id = p_wip_id
2014 AND (wop1.operation_seq_num = p_fm_op
2015 OR wop1.operation_seq_num = p_to_op))
2016 WHERE wop.rowid IN
2017 (SELECT wop2.rowid
2018 FROM wip_operations wop2
2019 WHERE wop2.organization_id = p_org_id
2020 AND wop2.wip_entity_id = p_wip_id
2021 AND (wop2.operation_seq_num = p_fm_op
2022 OR wop2.operation_seq_num = p_to_op));
2023
2024 /*Enh#2864382.Update wip_operations.cumulative_scrap_quantity after each
2025 scrap or return from scrap txn*/
2026 IF(p_fm_step = WIP_CONSTANTS.SCRAP AND p_to_step = WIP_CONSTANTS.SCRAP) THEN
2027 l_forward_move := WIP_CONSTANTS.NO;
2028 IF(p_fm_op<p_to_op) THEN
2029 l_forward_move := WIP_CONSTANTS.YES;
2030 END IF;
2031
2032 UPDATE WIP_OPERATIONS wo
2033 SET wo.cumulative_scrap_quantity = wo.cumulative_scrap_quantity +
2034 DECODE(l_forward_move,
2035 WIP_CONSTANTS.YES, -1*p_qty,
2036 WIP_CONSTANTS.NO, p_qty,
2037 0)
2038 WHERE wo.rowid in
2039 ( SELECT wo1.rowid
2040 FROM WIP_OPERATIONS wo1
2041 WHERE wo1.organization_id = p_org_id
2042 AND wo1.wip_entity_id = p_wip_id
2043 AND wo1.operation_seq_num > LEAST(p_fm_op,p_to_op)
2044 AND wo1.operation_seq_num <= GREATEST(p_fm_op,p_to_op));
2045 ELSIF(p_fm_step=WIP_CONSTANTS.SCRAP OR p_to_step=WIP_CONSTANTS.SCRAP)THEN
2046 UPDATE WIP_OPERATIONS wo
2047 SET wo.cumulative_scrap_quantity = wo.cumulative_scrap_quantity +
2048 DECODE(p_to_step,
2049 WIP_CONSTANTS.SCRAP,p_qty,
2050 0) +
2051 DECODE(p_fm_step,
2052 WIP_CONSTANTS.SCRAP,-1*p_qty,
2053 0)
2054 WHERE wo.rowid in
2055 (SELECT wo1.rowid
2056 FROM WIP_OPERATIONS wo1
2057 WHERE wo1.organization_id = p_org_id
2058 AND wo1.wip_entity_id = p_wip_id
2059 AND wo1.operation_seq_num > DECODE(p_fm_step,
2060 WIP_CONSTANTS.SCRAP,p_fm_op,
2061 p_to_op));
2062 END IF;
2063
2064 x_returnStatus := fnd_api.g_ret_sts_success;
2065
2066 -- write to the log file
2067 IF (l_logLevel <= wip_constants.trace_logging) THEN
2068 wip_logger.exitPoint(p_procName => 'wip_movProc_priv.update_wo_dj',
2069 p_procReturnStatus => x_returnStatus,
2070 p_msg => 'procedure complete',
2071 x_returnStatus => l_returnStatus);
2072 END IF;
2073
2074 EXCEPTION
2075 WHEN others THEN
2076 x_returnStatus := fnd_api.g_ret_sts_unexp_error;
2077 l_errMsg := 'unexpected error: ' || SQLERRM || 'SQLCODE = ' || SQLCODE;
2078
2079 IF (l_logLevel <= wip_constants.trace_logging) THEN
2080 wip_logger.exitPoint(p_procName => 'wip_movProc_priv.update_wo_dj',
2081 p_procReturnStatus => x_returnStatus,
2082 p_msg => l_errMsg,
2083 x_returnStatus => l_returnStatus);
2084 END IF;
2085 fnd_message.set_name('FND', 'FND_GENERIC_MESSAGE');
2086 fnd_message.set_token('MESSAGE', l_errMsg);
2087 fnd_msg_pub.add;
2088 END update_wo_dj;
2089
2090 /*****************************************************************************
2091 * This procedure is equivalent to witpssq_step_qtys_dj in wiltps.ppc
2092 * This procedure is used to check whether the quantity is enough to move or
2093 * not. IF it is enough, update WIP_OPERATIONS.
2094 ****************************************************************************/
2095 PROCEDURE check_qty_dj(p_gib IN OUT NOCOPY group_rec_t,
2096 x_returnStatus OUT NOCOPY VARCHAR2) IS
2097
2098 CURSOR c_dj_txn(p_timeout NUMBER,
2099 p_group_id NUMBER,
2100 p_txn_date DATE) IS
2101
2102 SELECT wmti.transaction_id txn_id,
2103 wmti.organization_id org_id,
2104 wmti.wip_entity_id wip_id,
2105 wmti.primary_quantity qty,
2106 wmti.fm_operation_seq_num fm_op,
2107 wmti.fm_intraoperation_step_type fm_step,
2108 wmti.to_operation_seq_num to_op,
2109 wmti.to_intraoperation_step_type to_step,
2110 DECODE(SIGN(86400*(SYSDATE - wmti.creation_date) - p_timeout),
2111 1,1,0) past_timeout,
2112 NVL(wmti.overcompletion_primary_qty,0) oc_pri_qty,
2113 DECODE(NVL(wmti.overcompletion_primary_qty,-1),
2114 -1,DECODE(NVL(wmti.overcompletion_transaction_id,-1),
2115 -1,WIP_CONSTANTS.normal_txn, WIP_CONSTANTS.child_txn)
2116 ,WIP_CONSTANTS.parent_txn) oc_txn_type,
2117 -- new columns added for serial location check
2118 wmti.transaction_type txn_type,
2119 wmti.primary_item_id item_id,
2120 NVL(wdj.serialization_start_op, 0) sn_start_op,
2121 wmti.transaction_date txn_date
2122 FROM wip_move_txn_interface wmti,
2123 wip_discrete_jobs wdj
2124 WHERE wmti.wip_entity_id = wdj.wip_entity_id
2125 AND wmti.group_id = p_group_id
2126 AND TRUNC(wmti.transaction_date) = TRUNC(p_txn_date)
2127 AND wmti.process_phase = WIP_CONSTANTS.MOVE_PROC
2128 AND wmti.process_status = WIP_CONSTANTS.RUNNING
2129 /* Now checks for lotbased entity type also */
2130 AND (wmti.entity_type = WIP_CONSTANTS.DISCRETE
2131 OR wmti.entity_type = WIP_CONSTANTS.LOTBASED)
2132 ORDER BY wmti.transaction_date,
2133 wmti.organization_id,
2134 wmti.wip_entity_id,
2135 wmti.processing_order,
2136 wmti.fm_operation_seq_num,
2137 wmti.to_operation_seq_num,
2138 wmti.fm_intraoperation_step_type,
2139 wmti.to_intraoperation_step_type,
2140 wmti.creation_date;
2141
2142 CURSOR c_ser_loc(p_start_op NUMBER,
2143 p_move_id NUMBER) IS
2144
2145 SELECT msn.serial_number serial,
2146 NVL(msn.operation_seq_num, p_start_op) sn_op,
2147 NVL(msn.intraoperation_step_type, WIP_CONSTANTS.QUEUE) sn_step
2148 FROM mtl_serial_numbers msn,
2149 wip_serial_move_interface wsmi,
2150 wip_move_txn_interface wmti
2151 WHERE msn.inventory_item_id = wmti.primary_item_id
2152 AND msn.current_organization_id = wmti.organization_id
2153 -- msn.wip_entity_id will be null after complete to inventory. Need this
2154 -- check to support return transaction.
2155 AND (msn.wip_entity_id is null OR
2156 msn.wip_entity_id = wmti.wip_entity_id)
2157 AND msn.serial_number = wsmi.assembly_serial_number
2158 AND wmti.transaction_id = wsmi.transaction_id
2159 AND wmti.transaction_id = p_move_id
2160 AND wmti.group_id = p_gib.group_id;
2161
2162 l_dj_txn c_dj_txn%ROWTYPE;
2163 l_ser_loc c_ser_loc%ROWTYPE;
2164 l_params wip_logger.param_tbl_t;
2165 l_returnStatus VARCHAR(1);
2166 l_errMsg VARCHAR2(240);
2167 l_msg VARCHAR(2000);
2168 l_rec_count NUMBER :=0;
2169 l_queue_qty NUMBER;
2170 l_run_qty NUMBER;
2171 l_tomove_qty NUMBER;
2172 l_reject_qty NUMBER;
2173 l_scrap_qty NUMBER;
2174 l_oc_fm_op NUMBER;
2175 -- Fixed bug 4406536. We should initialized l_notenough at the beginning of
2176 -- for loop, not the declaration part.
2177 -- l_notenough BOOLEAN := FALSE;
2178 l_notenough BOOLEAN;
2179 l_logLevel NUMBER := fnd_log.g_current_runtime_level;
2180 -- new variables added for serial location check
2181 l_opSeq NUMBER;
2182 l_step NUMBER;
2183 l_msg_data VARCHAR2(2000);
2184 l_propagate_job_change_to_po NUMBER;
2185 BEGIN
2186 -- write parameter value to log file
2187 IF (l_logLevel <= wip_constants.trace_logging) THEN
2188 l_params(1).paramName := 'p_group_id';
2189 l_params(1).paramValue := p_gib.group_id;
2190 l_params(2).paramName := 'p_timeout';
2191 l_params(2).paramValue := p_gib.time_out;
2192 l_params(3).paramName := 'p_txn_date';
2193 l_params(3).paramValue := p_gib.txn_date;
2194 l_params(4).paramName := 'p_move_mode';
2195 l_params(4).paramValue := p_gib.move_mode;
2196 wip_logger.entryPoint(p_procName => 'wip_movProc_priv.check_qty_dj',
2197 p_params => l_params,
2198 x_returnStatus => l_returnStatus);
2199 END IF;
2200
2201 OPEN c_dj_txn(p_timeout => p_gib.time_out,
2202 p_group_id => p_gib.group_id,
2203 p_txn_date => p_gib.txn_date);
2204 LOOP
2205 BEGIN
2206 FETCH c_dj_txn INTO l_dj_txn;
2207 IF(c_dj_txn%NOTFOUND) THEN
2208 GOTO end_loop;
2209 ELSE
2210 l_rec_count := l_rec_count + 1;
2211 -- Fixed bug 4406536. We should initialized l_notenough at the beginning
2212 -- of for loop, not the declaration part.
2213 l_notenough := FALSE;
2214 -- validate serial location if serialized job, and serialized move
2215 IF(l_dj_txn.sn_start_op <> 0 AND
2216 l_dj_txn.fm_op >= l_dj_txn.sn_start_op AND
2217 l_dj_txn.to_op >= l_dj_txn.sn_start_op) THEN
2218 -- Only check serial locationtion if transaction_type is either
2219 -- Move or Move and Complete. We already check that serial has valid
2220 -- status to do Return and Move in Move Validation code, so no need to
2221 -- check serial location because both MSN.OPERATION_SEQ_NUM and
2222 -- MSN.INTRAOPERATION_STEP_TYPE will be null, anyway.
2223 FOR l_ser_loc IN c_ser_loc(p_start_op => l_dj_txn.sn_start_op,
2224 p_move_id => l_dj_txn.txn_id) LOOP
2225
2226 -- get MSN.OPERATION_SEQ_NUM and MSN.INTRAOPERATION_STEP_TYPE
2227
2228 IF(l_dj_txn.txn_type IN (WIP_CONSTANTS.COMP_TXN,
2229 WIP_CONSTANTS.MOVE_TXN) AND
2230 (l_ser_loc.sn_op <> l_dj_txn.fm_op OR
2231 l_ser_loc.sn_step <> l_dj_txn.fm_step)) THEN
2232 fnd_message.set_name('WIP', 'WIP_SERIAL_LOCATION_MISSMATCH');
2233 fnd_msg_pub.add;
2234 l_errMsg := 'current serial location missmatch';
2235 raise fnd_api.g_exc_unexpected_error;
2236 ELSE -- serial location is valid to move
2237 -- If user move back to Queue of serialization start op, we clear
2238 -- operation_seq_num and intraoperation_step_type in MSNT
2239 IF (l_dj_txn.to_op = l_dj_txn.sn_start_op AND
2240 l_dj_txn.to_step = WIP_CONSTANTS.QUEUE) THEN
2241 l_opSeq := null;
2242 l_step := null;
2243 ELSE
2244 l_opSeq := l_dj_txn.to_op;
2245 l_step := l_dj_txn.to_step;
2246 END IF;
2247 -- update current serial location to WMTI.TO_OPERATION_SEQ_NUM and
2248 -- WMTI.INTRAOPERATION_STEP_TYPE
2249 wip_utilities.update_serial(
2250 p_serial_number => l_ser_loc.serial,
2251 p_inventory_item_id => l_dj_txn.item_id,
2252 p_organization_id => l_dj_txn.org_id,
2253 p_wip_entity_id => l_dj_txn.wip_id,
2254 p_line_mark_id => null,
2255 p_operation_seq_num => l_opSeq,
2256 p_intraoperation_step_type => l_step,
2257 x_return_status => l_returnStatus);
2258
2259 IF(l_returnStatus <> fnd_api.g_ret_sts_success) THEN
2260 l_errMsg := 'wip_utilities.update_serial failed';
2261 raise fnd_api.g_exc_unexpected_error;
2262 END IF;
2263 END IF; -- IF(l_dj_txn.txn_type
2264 END LOOP; -- l_ser_loc IN c_ser_loc
2265 END IF; -- serialized move
2266
2267 SELECT wop.quantity_in_queue,
2268 wop.quantity_running,
2269 wop.quantity_waiting_to_move,
2270 wop.quantity_rejected,
2271 wop.quantity_scrapped
2272 INTO l_queue_qty,
2273 l_run_qty,
2274 l_tomove_qty,
2275 l_reject_qty,
2276 l_scrap_qty
2277 FROM wip_operations wop
2278 WHERE wop.organization_id = l_dj_txn.org_id
2279 AND wop.wip_entity_id = l_dj_txn.wip_id
2280 AND wop.operation_seq_num = l_dj_txn.fm_op;
2281
2282 IF(l_dj_txn.oc_txn_type = WIP_CONSTANTS.child_txn) THEN
2283 -- update qty in queue step for child txn
2284 update_wipops(p_txn_id => l_dj_txn.txn_id,
2285 p_gib => p_gib,
2286 x_returnStatus => x_returnStatus);
2287
2288 IF(x_returnStatus <> fnd_api.g_ret_sts_success) THEN
2289 l_errMsg := 'wip_movProc_priv.update_wipops failed';
2290 raise fnd_api.g_exc_unexpected_error;
2291 END IF; -- check return status
2292
2293 ELSE -- IF it is parent or normal txn, validate qty
2294
2295 IF(l_dj_txn.fm_step = WIP_CONSTANTS.QUEUE) THEN
2296 IF(l_dj_txn.qty > l_queue_qty + l_dj_txn.oc_pri_qty + 0.00001) THEN
2297 l_notenough := TRUE;
2298 END IF;
2299 ELSIF(l_dj_txn.fm_step = WIP_CONSTANTS.RUN) THEN
2300 IF(l_dj_txn.qty > l_run_qty + l_dj_txn.oc_pri_qty + 0.00001) THEN
2301 l_notenough := TRUE;
2302 END IF;
2303 ELSIF(l_dj_txn.fm_step = WIP_CONSTANTS.TOMOVE) THEN
2304 IF(l_dj_txn.qty > l_tomove_qty + l_dj_txn.oc_pri_qty + 0.00001) THEN
2305 l_notenough := TRUE;
2306 END IF;
2307 ELSIF(l_dj_txn.fm_step = WIP_CONSTANTS.REJECT) THEN
2308 IF(l_dj_txn.qty > l_reject_qty + l_dj_txn.oc_pri_qty + 0.00001) THEN
2309 l_notenough := TRUE;
2310 END IF;
2311 ELSIF(l_dj_txn.fm_step = WIP_CONSTANTS.SCRAP) THEN
2312 IF(l_dj_txn.qty > l_scrap_qty + l_dj_txn.oc_pri_qty + 0.00001) THEN
2313 l_notenough := TRUE;
2314 END IF;
2315 END IF; -- fm_step check
2316 END IF; -- child txn check
2317
2318 IF(l_notenough) THEN
2319 IF(p_gib.move_mode = WIP_CONSTANTS.BACKGROUND) THEN
2320 IF (l_dj_txn.past_timeout = 0) THEN -- not time out yet
2321 UPDATE wip_move_txn_interface
2322 SET process_status = WIP_CONSTANTS.PENDING,
2323 group_id = NULL,
2324 transaction_id = NULL
2325 WHERE transaction_id = l_dj_txn.txn_id
2326 AND group_id = p_gib.group_id;
2327 END IF; -- time out check
2328 END IF; -- BACKGROUND check
2329 fnd_message.set_name('WIP', 'WIP_LESS_OR_EQUAL');
2330 fnd_message.set_token('ENTITY1', 'transaction quantity');
2331 fnd_message.set_token('ENTITY2', 'quantity available to move');
2332 fnd_msg_pub.add;
2333 l_errMsg := 'available qty is not enough to fullfill move txn';
2334 raise fnd_api.g_exc_unexpected_error;
2335 ELSE -- enough qty to move
2336 IF(l_dj_txn.oc_txn_type = WIP_CONSTANTS.parent_txn) THEN
2337
2338 -- all procedure in this loop is pretty much for child record
2339 -- IF it is over completion/move txn, insert child record to WMTI
2340 insert_alloc_child(p_org_id => l_dj_txn.org_id,
2341 p_scheID => -1,
2342 p_oc_pri_qty => l_dj_txn.oc_pri_qty,
2343 p_parent_txn_id => l_dj_txn.txn_id,
2344 p_gib => p_gib,
2345 x_oc_fm_op => l_oc_fm_op,
2346 x_returnStatus => x_returnStatus);
2347
2348 IF (x_returnStatus <> fnd_api.g_ret_sts_success) THEN
2349 IF (l_dj_txn.past_timeout = 0) THEN -- not time out yet
2350 UPDATE wip_move_txn_interface
2351 SET process_status = WIP_CONSTANTS.PENDING,
2352 group_id = NULL,
2353 transaction_id = NULL
2354 WHERE transaction_id = l_dj_txn.txn_id
2355 AND group_id = p_gib.group_id;
2356 END IF; -- time out check
2357
2358 l_errMsg := 'wip_movProc_priv.insert_alloc_child failed';
2359 raise fnd_api.g_exc_unexpected_error;
2360
2361 ELSE -- insert child success
2362 -- insert assemblies in the queue of the first operation after
2363 -- the child record is inserted
2364 update_wipops(p_txn_id => p_gib.move_profile.child_txn_id,
2365 p_gib => p_gib,
2366 x_returnStatus => x_returnStatus);
2367
2368 IF (x_returnStatus <> fnd_api.g_ret_sts_success) THEN
2369 l_errMsg := 'wip_movProc_priv.update_wipops failed';
2370 raise fnd_api.g_exc_unexpected_error;
2371 END IF;
2372
2373 -- update wip_operations for child move txns
2374 update_wo_dj(p_gib => p_gib,
2375 p_fm_op => l_oc_fm_op,
2376 p_fm_step => WIP_CONSTANTS.QUEUE,
2377 p_to_op => l_dj_txn.fm_op,
2378 p_to_step => l_dj_txn.fm_step,
2379 p_qty => l_dj_txn.oc_pri_qty,
2380 p_org_id => l_dj_txn.org_id,
2381 p_wip_id => l_dj_txn.wip_id,
2382 p_txn_date => l_dj_txn.txn_date,
2383 x_returnStatus => x_returnStatus);
2384
2385 IF (x_returnStatus <> fnd_api.g_ret_sts_success) THEN
2386 l_errMsg := 'wip_movProc_priv.update_wo_dj failed';
2387 raise fnd_api.g_exc_unexpected_error;
2388 END IF;
2389 END IF; -- insert_alloc_child check
2390
2391 -- Increase PO/requisition quantity if overmove
2392 IF(l_dj_txn.oc_pri_qty <> 0 AND
2393 po_code_release_grp.Current_Release >=
2394 po_code_release_grp.PRC_11i_Family_Pack_J) THEN
2395
2396 SELECT propagate_job_change_to_po
2397 INTO l_propagate_job_change_to_po
2398 FROM wip_parameters
2399 WHERE organization_id = l_dj_txn.org_id;
2400
2401 IF(l_propagate_job_change_to_po = WIP_CONSTANTS.YES) THEN
2402 wip_osp.updatePOReqQuantity(
2403 p_job_id => l_dj_txn.wip_id,
2404 p_org_id => l_dj_txn.org_id,
2405 p_changed_qty => l_dj_txn.oc_pri_qty,
2406 /* Fix for Bug#4746495. PO linked to current Operation should
2407 * not be updated. Only future PO should be updated.
2408 */
2409 p_fm_op => l_dj_txn.fm_op,
2410 x_return_status => x_returnStatus);
2411
2412 IF(x_returnStatus <> fnd_api.g_ret_sts_success) THEN
2413 l_errMsg := 'wip_osp.updatePOReqQuantity failed';
2414 raise fnd_api.g_exc_unexpected_error;
2415 END IF; -- x_returnStatus
2416 END IF; -- l_propagate_job_change_to_po = WIP_CONSTANTS.YES
2417 END IF; -- l_dj_txn.oc_pri_qty <> 0 and customer have PO FPJ
2418 END IF; -- IF parent_txn
2419
2420 -- update wip_operations for parent and normal move txns
2421 update_wo_dj(p_gib => p_gib,
2422 p_fm_op => l_dj_txn.fm_op,
2423 p_fm_step => l_dj_txn.fm_step,
2424 p_to_op => l_dj_txn.to_op,
2425 p_to_step => l_dj_txn.to_step,
2426 p_qty => l_dj_txn.qty,
2427 p_org_id => l_dj_txn.org_id,
2428 p_wip_id => l_dj_txn.wip_id,
2429 p_txn_date => l_dj_txn.txn_date,
2430 x_returnStatus => x_returnStatus);
2431
2432 IF (x_returnStatus <> fnd_api.g_ret_sts_success) THEN
2433 l_errMsg := 'wip_movProc_priv.update_wo_dj failed';
2434 raise fnd_api.g_exc_unexpected_error;
2435 END IF;
2436
2437 END IF; -- check enough qty
2438
2439 END IF; --c_dj_txn%NOTFOUND
2440 -- Fixed bug 4324706. Reset p_gib.move_profile.child_txn_id to null
2441 -- to prevent child move record got inserted with the same transaction_id.
2442 p_gib.move_profile.child_txn_id := null;
2443 -- Fixed bug 4406536. We should error out only problematic record and
2444 -- continue to process next record.
2445 EXCEPTION
2446 WHEN fnd_api.g_exc_unexpected_error THEN
2447 IF(p_gib.move_mode = WIP_CONSTANTS.BACKGROUND) THEN
2448 IF (l_dj_txn.past_timeout = 0) THEN -- not time out yet
2449 UPDATE wip_move_txn_interface
2450 SET process_status = WIP_CONSTANTS.PENDING,
2451 group_id = NULL,
2452 transaction_id = NULL
2453 WHERE transaction_id = l_dj_txn.txn_id
2454 AND group_id = p_gib.group_id;
2455 ELSE -- already time out
2456 UPDATE wip_move_txn_interface
2457 SET process_status = WIP_CONSTANTS.ERROR
2458 WHERE transaction_id = l_dj_txn.txn_id
2459 AND group_id = p_gib.group_id;
2460 -- Get error from message stack
2461 wip_utilities.get_message_stack(p_msg =>l_msg);
2462 IF(l_msg IS NULL) THEN
2463 -- initialize message to something because we cannot insert
2464 -- null into WIP_TXN_INTERFACE_ERRORS
2465 fnd_message.set_name('WIP', 'WIP_SOME_RECORDS_ERROR');
2466 l_msg := fnd_message.get;
2467 END IF;
2468
2469 INSERT INTO WIP_TXN_INTERFACE_ERRORS
2470 (transaction_id,
2471 error_column,
2472 error_message,
2473 last_update_date,
2474 last_updated_by,
2475 creation_date,
2476 created_by,
2477 last_update_login,
2478 request_id,
2479 program_application_id,
2480 program_id,
2481 program_update_date)
2482 SELECT wmti.transaction_id,
2483 'TRANSACTION_QUANTITY', -- error_column
2484 substrb(l_msg,1,240), -- error_message
2485 SYSDATE, -- last_update_date
2486 wmti.last_updated_by, -- last_update_by
2487 SYSDATE, -- creation_date
2488 wmti.created_by, -- created_by
2489 p_gib.login_id,
2490 p_gib.request_id,
2491 p_gib.application_id,
2492 p_gib.program_id,
2493 SYSDATE -- program_update_date
2494 FROM wip_move_txn_interface wmti
2495 WHERE wmti.transaction_id = l_dj_txn.txn_id
2496 AND wmti.group_id = p_gib.group_id;
2497 END IF; -- time out check
2498 ELSE--Online processing
2499 --Bug 5210073: Raise an exception to rollback the changes in online mode.
2500 raise fnd_api.g_exc_unexpected_error;
2501 END IF; -- background check
2502 END;
2503 END LOOP; -- c_dj_txn
2504
2505 <<end_loop>>
2506 IF(c_dj_txn%ISOPEN) THEN
2507 CLOSE c_dj_txn;
2508 END IF;
2509 x_returnStatus := fnd_api.g_ret_sts_success;
2510
2511 -- write to the log file
2512 IF (l_logLevel <= wip_constants.trace_logging) THEN
2513 wip_logger.exitPoint(p_procName => 'wip_movProc_priv.check_qty_dj',
2514 p_procReturnStatus => x_returnStatus,
2515 p_msg => 'procedure complete',
2516 x_returnStatus => l_returnStatus);
2517 END IF;
2518
2519 EXCEPTION
2520
2521 WHEN fnd_api.g_exc_unexpected_error THEN
2522 IF(c_dj_txn%ISOPEN) THEN
2523 CLOSE c_dj_txn;
2524 END IF;
2525 x_returnStatus := fnd_api.g_ret_sts_unexp_error;
2526
2527 IF (l_logLevel <= wip_constants.trace_logging) THEN
2528 wip_logger.exitPoint(p_procName => 'wip_movProc_priv.check_qty_dj',
2529 p_procReturnStatus => x_returnStatus,
2530 p_msg => l_errMsg,
2531 x_returnStatus => l_returnStatus);
2532 END IF;
2533
2534 WHEN others THEN
2535 IF(c_dj_txn%ISOPEN) THEN
2536 CLOSE c_dj_txn;
2537 END IF;
2538 x_returnStatus := fnd_api.g_ret_sts_unexp_error;
2539 l_errMsg := 'unexpected error: ' || SQLERRM || 'SQLCODE = ' || SQLCODE;
2540
2541 IF (l_logLevel <= wip_constants.trace_logging) THEN
2542 wip_logger.exitPoint(p_procName => 'wip_movProc_priv.check_qty_dj',
2543 p_procReturnStatus => x_returnStatus,
2544 p_msg => l_errMsg,
2545 x_returnStatus => l_returnStatus);
2546 END IF;
2547 fnd_message.set_name('FND', 'FND_GENERIC_MESSAGE');
2548 fnd_message.set_token('MESSAGE', l_errMsg);
2549 fnd_msg_pub.add;
2550 END check_qty_dj;
2551
2552 /*****************************************************************************
2553 * This procedure is equivalent to witvemp_move_profile in wiltve.ppc
2554 * This procedure is used to get move profile
2555 ****************************************************************************/
2556 PROCEDURE get_move_profile(p_gib IN OUT NOCOPY group_rec_t,
2557 x_returnStatus OUT NOCOPY VARCHAR2) IS
2558
2559 l_params wip_logger.param_tbl_t;
2560 l_returnStatus VARCHAR(1);
2561 l_errMsg VARCHAR2(240);
2562 l_mv_item NUMBER;
2563 l_mv_lot NUMBER;
2564 l_po_item NUMBER;
2565 l_po_lot NUMBER;
2566 l_completion NUMBER;
2567 l_return NUMBER;
2568 l_move move_profile_rec_t;
2569 l_logLevel NUMBER := fnd_log.g_current_runtime_level;
2570
2571 BEGIN
2572 -- initialize l_move
2573 l_move := p_gib.move_profile;
2574
2575 -- write parameter value to log file
2576 IF (l_logLevel <= wip_constants.trace_logging) THEN
2577 l_params(1).paramName := 'p_group_id';
2578 l_params(1).paramValue := p_gib.group_id;
2579 l_params(2).paramName := 'p_txn_date';
2580 l_params(2).paramValue := p_gib.txn_date;
2581 l_params(3).paramName := 'p_move_mode';
2582 l_params(3).paramValue := p_gib.move_mode;
2583 l_params(4).paramName := 'org_id';
2584 l_params(4).paramValue := l_move.org_id;
2585 l_params(5).paramName := 'wip_id';
2586 l_params(5).paramValue := l_move.wip_id;
2587 l_params(6).paramName := 'fmOp';
2588 l_params(6).paramValue := l_move.fmOp;
2589 l_params(7).paramName := 'fmStep';
2590 l_params(7).paramValue := l_move.fmStep;
2591 l_params(8).paramName := 'toOp';
2592 l_params(8).paramValue := l_move.toOp;
2593 l_params(9).paramName := 'toStep';
2594 l_params(9).paramValue := l_move.toStep;
2595 l_params(10).paramName := 'scrapTxn';
2596 l_params(10).paramValue := l_move.scrapTxn;
2597 l_params(11).paramName := 'easyComplete';
2598 l_params(11).paramValue := l_move.easyComplete;
2599 l_params(12).paramName := 'easyReturn';
2600 l_params(12).paramValue := l_move.easyReturn;
2601 l_params(13).paramName := 'jobTxn';
2602 l_params(13).paramValue := l_move.jobTxn;
2603 l_params(14).paramName := 'scheTxn';
2604 l_params(14).paramValue := l_move.scheTxn;
2605 l_params(15).paramName := 'rsrcItem';
2606 l_params(15).paramValue := l_move.rsrcItem;
2607 l_params(16).paramName := 'rsrcLot';
2608 l_params(16).paramValue := l_move.rsrcLot;
2609 l_params(17).paramName := 'poReqItem';
2610 l_params(17).paramValue := l_move.poReqItem;
2611 l_params(18).paramName := 'poRegLot';
2612 l_params(18).paramValue := l_move.poReqLot;
2613 wip_logger.entryPoint(p_procName => 'wip_movProc_priv.get_move_profile',
2614 p_params => l_params,
2615 x_returnStatus => l_returnStatus);
2616 END IF;
2617
2618 IF(p_gib.move_mode = WIP_CONSTANTS.ONLINE) THEN
2619
2620 /* Fix for FP bug 5246228 base bug 5227706:
2621 * Modified following query to consider autocharge
2622 * resources in previous operation for overcompletion cases */
2623 SELECT SUM(DECODE(basis_type,1,DECODE(autocharge_type,1,1,0),0)),
2624 SUM(DECODE(basis_type,2,DECODE(autocharge_type,1,1,0),0)),
2625 SUM(DECODE(to_intraoperation_step_type,1,DECODE(basis_type,1,
2626 DECODE(autocharge_type,3,1,4,1,0),0))),
2627 SUM(DECODE(to_intraoperation_step_type,1,DECODE(basis_type,2,
2628 DECODE(autocharge_type,3,1,4,1,0),0)))
2629 INTO l_mv_item,
2630 l_mv_lot,
2631 l_po_item,
2632 l_po_lot
2633 FROM wip_move_txn_interface wmti,
2634 wip_operation_resources wor
2635 WHERE wmti.transaction_id = p_gib.group_id
2636 AND wmti.group_id = p_gib.group_id
2637 AND wor.organization_id = l_move.org_id
2638 AND wor.wip_entity_id = l_move.wip_id
2639 AND ((wmti.overcompletion_primary_qty IS NULL
2640 AND (wor.operation_seq_num BETWEEN l_move.fmOp AND l_move.toOp
2641 OR
2642 wor.operation_seq_num BETWEEN l_move.toOp AND l_move.fmOp))
2643 OR wor.operation_seq_num <= l_move.toOp);
2644 /* Fix for Bug#5552530, which is an FP of Bug#5509016.
2645 Changed < to <= in above condition */
2646
2647 ELSE -- move_mode is background
2648
2649 SELECT SUM(DECODE(transaction_type, WIP_CONSTANTS.COMP_TXN, 1, 0)),
2650 SUM(DECODE(transaction_type, WIP_CONSTANTS.RET_TXN, 1, 0))
2651 INTO l_completion,
2652 l_return
2653 FROM wip_move_txn_interface wmti
2654 WHERE wmti.group_id = p_gib.group_id
2655 AND TRUNC(wmti.transaction_date) = TRUNC(p_gib.txn_date)
2656 AND wmti.process_phase = WIP_CONSTANTS.MOVE_PROC
2657 AND wmti.process_status = WIP_CONSTANTS.RUNNING;
2658
2659 -- set completion and return flag
2660 IF(l_completion > 0) THEN
2661 l_move.easyComplete := WIP_CONSTANTS.YES;
2662 ELSE
2663 l_move.easyComplete := WIP_CONSTANTS.NO;
2664 END IF;
2665
2666 IF(l_return > 0) THEN
2667 l_move.easyReturn := WIP_CONSTANTS.YES;
2668 ELSE
2669 l_move.easyReturn := WIP_CONSTANTS.NO;
2670 END IF;
2671 /* Fix for bug 3902908: Added hints as per suggestion of appsperf team. */
2672 /* Fix for FP bug 5246228 base bug 5227706: Modified following query to consider autocharge
2673 resources in previous operation for overcompletion cases */
2674 SELECT /*+ leading(wti) use_nl(wti wor) index(wor WIP_OPERATION_RESOURCES_U1) */
2675 SUM(DECODE(basis_type,1,DECODE(autocharge_type,1,1,0),0)),
2676 SUM(DECODE(basis_type,2,DECODE(autocharge_type,1,1,0),0)),
2677 SUM(DECODE(to_intraoperation_step_type,1,DECODE(basis_type,1,
2678 DECODE(autocharge_type,3,1,4,1,0),0))),
2679 SUM(DECODE(to_intraoperation_step_type,1,DECODE(basis_type,2,
2680 DECODE(autocharge_type,3,1,4,1,0),0)))
2681 INTO l_mv_item,
2682 l_mv_lot,
2683 l_po_item,
2684 l_po_lot
2685 FROM wip_move_txn_interface wmti,
2686 wip_operation_resources wor
2687 WHERE wmti.group_id = p_gib.group_id
2688 AND TRUNC(wmti.transaction_date) = TRUNC(p_gib.txn_date)
2689 AND wmti.process_phase = WIP_CONSTANTS.MOVE_PROC
2690 AND wmti.process_status = WIP_CONSTANTS.RUNNING
2691 AND wor.organization_id = wmti.organization_id
2692 AND wor.wip_entity_id = wmti.wip_entity_id
2693 AND ((wmti.overcompletion_primary_qty IS NULL
2694 AND (wor.operation_seq_num BETWEEN wmti.fm_operation_seq_num
2695 AND wmti.to_operation_seq_num
2696 OR
2697 wor.operation_seq_num BETWEEN wmti.to_operation_seq_num
2698 AND wmti.fm_operation_seq_num))
2699 OR wor.operation_seq_num <= wmti.to_operation_seq_num);
2700 /* Fix for Bug#5552530, which is an FP of Bug#5509016.
2701 Changed < to <= in above condition */
2702
2703 END IF; -- move_mode is online
2704
2705 -- set the rest of move_profile flag
2706 IF(l_mv_item > 0) THEN -- auto resource per item
2707 l_move.rsrcItem := WIP_CONSTANTS.YES;
2708 ELSE
2709 l_move.rsrcItem := WIP_CONSTANTS.NO;
2710 END IF;
2711
2712 IF(l_mv_lot > 0) THEN -- auto resource per lot
2713 l_move.rsrcLot := WIP_CONSTANTS.YES;
2714 ELSE
2715 l_move.rsrcLot := WIP_CONSTANTS.NO;
2716 END IF;
2717
2718 IF(l_po_item > 0) THEN -- po requisition per item
2719 l_move.poReqItem := WIP_CONSTANTS.YES;
2720 ELSE
2721 l_move.poReqItem := WIP_CONSTANTS.NO;
2722 END IF;
2723
2724 IF(l_po_lot > 0) THEN -- po requisition per lot
2725 l_move.poReqLot := WIP_CONSTANTS.YES;
2726 ELSE
2727 l_move.poReqLot := WIP_CONSTANTS.NO;
2728 END IF;
2729
2730 -- return move profile back
2731 p_gib.move_profile := l_move;
2732
2733 x_returnStatus := fnd_api.g_ret_sts_success;
2734
2735 -- write to the log file
2736 IF (l_logLevel <= wip_constants.trace_logging) THEN
2737 wip_logger.exitPoint(p_procName => 'wip_movProc_priv.get_move_profile',
2738 p_procReturnStatus => x_returnStatus,
2739 p_msg => 'procedure complete',
2740 x_returnStatus => l_returnStatus);
2741 END IF;
2742
2743 EXCEPTION
2744 WHEN others THEN
2745 x_returnStatus := fnd_api.g_ret_sts_unexp_error;
2746 l_errMsg := 'unexpected error: ' || SQLERRM || 'SQLCODE = ' || SQLCODE;
2747
2748 IF (l_logLevel <= wip_constants.trace_logging) THEN
2749 wip_logger.exitPoint(p_procName => 'wip_movProc_priv.get_move_profile',
2750 p_procReturnStatus => x_returnStatus,
2751 p_msg => l_errMsg,
2752 x_returnStatus => l_returnStatus);
2753 END IF;
2754 fnd_message.set_name('FND', 'FND_GENERIC_MESSAGE');
2755 fnd_message.set_token('MESSAGE', l_errMsg);
2756 fnd_msg_pub.add;
2757 END get_move_profile;
2758
2759 /*****************************************************************************
2760 * This procedure is equivalent to witpsth_txn_history in wiltps5.ppc
2761 * This procedure is used to insert history move records into
2762 * WIP_MOVE_TRANSACTIONS.
2763 ****************************************************************************/
2764 PROCEDURE insert_txn_history(p_gib IN group_rec_t,
2765 x_returnStatus OUT NOCOPY VARCHAR2) IS
2766
2767 l_params wip_logger.param_tbl_t;
2768 l_returnStatus VARCHAR(1);
2769 l_msg VARCHAR(240);
2770 l_errMsg VARCHAR2(240);
2771 l_logLevel NUMBER := fnd_log.g_current_runtime_level;
2772
2773 BEGIN
2774 -- write parameter value to log file
2775 IF (l_logLevel <= wip_constants.trace_logging) THEN
2776 l_params(1).paramName := 'p_group_id';
2777 l_params(1).paramValue := p_gib.group_id;
2778 l_params(2).paramName := 'p_txn_date';
2779 l_params(2).paramValue := p_gib.txn_date;
2780 wip_logger.entryPoint(p_procName => 'wip_movProc_priv.insert_txn_history',
2781 p_params => l_params,
2782 x_returnStatus => l_returnStatus);
2783 END IF;
2784
2785 -- insert history serial move record into WIP_SERIAL_MOVE_TRANSACTIONS
2786 INSERT INTO wip_serial_move_transactions
2787 (transaction_id,
2788 assembly_serial_number,
2789 creation_date,
2790 created_by,
2791 created_by_name,
2792 last_update_date,
2793 last_updated_by,
2794 last_updated_by_name,
2795 last_update_login,
2796 request_id,
2797 program_application_id,
2798 program_id,
2799 program_update_date,
2800 -- Add this column for OSFM serial support project.
2801 gen_object_id
2802 )
2803 SELECT wsmi.transaction_id,
2804 wsmi.assembly_serial_number,
2805 wsmi.creation_date,
2806 wsmi.created_by,
2807 wsmi.created_by_name,
2808 wsmi.last_update_date,
2809 wsmi.last_updated_by,
2810 wsmi.last_updated_by_name,
2811 wsmi.last_update_login,
2812 wsmi.request_id,
2813 wsmi.program_application_id,
2814 wsmi.program_id,
2815 wsmi.program_update_date,
2816 -- Add this column for OSFM serial support project.
2817 wsmi.gen_object_id
2818 FROM wip_serial_move_interface wsmi,
2819 wip_move_txn_interface wmti
2820 WHERE wsmi.transaction_id = wmti.transaction_id
2821 AND wmti.group_id = p_gib.group_id
2822 AND TRUNC(wmti.transaction_date) = TRUNC(p_gib.txn_date)
2823 AND wmti.process_phase = WIP_CONSTANTS.MOVE_PROC
2824 AND wmti.process_status = WIP_CONSTANTS.RUNNING;
2825
2826 -- IF debug message level = 2, write statement below to log file
2827 IF (l_logLevel <= wip_constants.full_logging) THEN
2828 fnd_message.set_name('WIP', 'WIP_INSERTED_ROWS');
2829 fnd_message.set_token('ENTITY1', SQL%ROWCOUNT);
2830 fnd_message.set_token('ENTITY2', 'WIP_SERIAL_MOVE_TRANSACTIONS');
2831 l_msg := fnd_message.get;
2832 wip_logger.log(p_msg => l_msg,
2833 x_returnStatus => l_returnStatus);
2834 END IF;
2835
2836 -- insert history move record into WIP_MOVE_TRANSACTIONS
2837 -- Discrete/OSFM
2838 INSERT INTO wip_move_transactions
2839 (transaction_id,
2840 last_updated_by,
2841 last_update_date,
2842 last_update_login,
2843 created_by,
2844 creation_date,
2845 request_id,
2846 program_application_id,
2847 program_id,
2848 program_update_date,
2849 group_id,
2850 source_code,
2851 source_line_id,
2852 organization_id,
2853 wip_entity_id,
2854 primary_item_id,
2855 line_id,
2856 transaction_date,
2857 acct_period_id,
2858 fm_operation_seq_num,
2859 fm_operation_code,
2860 fm_department_id,
2861 fm_intraoperation_step_type,
2862 to_operation_seq_num,
2863 to_operation_code,
2864 to_department_id,
2865 to_intraoperation_step_type,
2866 transaction_quantity,
2867 transaction_uom,
2868 primary_quantity,
2869 primary_uom,
2870 reason_id,
2871 reference,
2872 scrap_account_id,
2873 attribute_category,
2874 attribute1,
2875 attribute2,
2876 attribute3,
2877 attribute4,
2878 attribute5,
2879 attribute6,
2880 attribute7,
2881 attribute8,
2882 attribute9,
2883 attribute10,
2884 attribute11,
2885 attribute12,
2886 attribute13,
2887 attribute14,
2888 attribute15,
2889 qa_collection_id,
2890 overcompletion_transaction_qty,
2891 overcompletion_primary_qty,
2892 overcompletion_transaction_id,
2893 job_quantity_snapshot,
2894 batch_id,
2895 employee_id,
2896 completed_instructions
2897 )
2898 SELECT wmti.transaction_id,
2899 wmti.last_updated_by, -- last_updated_by --Fix for bug 5195072
2900 SYSDATE, -- last_update_date
2901 DECODE(p_gib.login_id,
2902 -1,NULL,p_gib.login_id), -- last_update_login
2903 wmti.created_by, -- created_by --Fix for bug 5195072
2904 SYSDATE, -- creation_date
2905 DECODE(p_gib.request_id,-1,NULL,p_gib.request_id),
2906 DECODE(p_gib.application_id,-1,NULL,p_gib.application_id),
2907 DECODE(p_gib.program_id,-1,NULL,p_gib.program_id),
2908 DECODE(p_gib.request_id,
2909 -1,NULL,SYSDATE), -- program_update_date
2910 p_gib.group_id,
2911 wmti.source_code,
2912 wmti.source_line_id,
2913 wmti.organization_id,
2914 wmti.wip_entity_id,
2915 wmti.primary_item_id,
2916 wmti.line_id,
2917 wmti.transaction_date,
2918 wmti.acct_period_id,
2919 wmti.fm_operation_seq_num,
2920 wmti.fm_operation_code,
2921 wmti.fm_department_id,
2922 wmti.fm_intraoperation_step_type,
2923 wmti.to_operation_seq_num,
2924 wmti.to_operation_code,
2925 wmti.to_department_id,
2926 wmti.to_intraoperation_step_type,
2927 wmti.transaction_quantity,
2928 wmti.transaction_uom,
2929 wmti.primary_quantity,
2930 wmti.primary_uom,
2931 wmti.reason_id,
2932 wmti.reference,
2933 wmti.scrap_account_id,
2934 wmti.attribute_category,
2935 wmti.attribute1,
2936 wmti.attribute2,
2937 wmti.attribute3,
2938 wmti.attribute4,
2939 wmti.attribute5,
2940 wmti.attribute6,
2941 wmti.attribute7,
2942 wmti.attribute8,
2943 wmti.attribute9,
2944 wmti.attribute10,
2945 wmti.attribute11,
2946 wmti.attribute12,
2947 wmti.attribute13,
2948 wmti.attribute14,
2949 wmti.attribute15,
2950 wmti.qa_collection_id,
2951 wmti.overcompletion_transaction_qty,
2952 wmti.overcompletion_primary_qty,
2953 wmti.overcompletion_transaction_id,
2954 wdj.start_quantity,
2955 wmti.batch_id,
2956 wmti.employee_id,
2957 wmti.completed_instructions
2958 FROM wip_move_txn_interface wmti,
2959 wip_discrete_jobs wdj
2960 WHERE wmti.group_id = p_gib.group_id
2961 AND TRUNC(wmti.transaction_date) = TRUNC(p_gib.txn_date)
2962 AND wmti.process_phase = WIP_CONSTANTS.MOVE_PROC
2963 AND wmti.process_status = WIP_CONSTANTS.RUNNING
2964 AND wmti.entity_type IN (WIP_CONSTANTS.DISCRETE,
2965 WIP_CONSTANTS.LOTBASED)
2966 AND wdj.wip_entity_id = wmti.wip_entity_id
2967 AND wdj.organization_id = wmti.organization_id;
2968
2969 -- IF debug message level = 2, write statement below to log file
2970 IF (l_logLevel <= wip_constants.full_logging) THEN
2971 fnd_message.set_name('WIP', 'WIP_INSERTED_ROWS');
2972 fnd_message.set_token('ENTITY1', SQL%ROWCOUNT);
2973 fnd_message.set_token('ENTITY2', 'WIP_MOVE_TRANSACTIONS');
2974 l_msg := fnd_message.get;
2975 wip_logger.log(p_msg => l_msg,
2976 x_returnStatus => l_returnStatus);
2977 END IF;
2978
2979 -- Repetitive Schedule
2980 INSERT INTO wip_move_transactions
2981 (transaction_id,
2982 last_updated_by,
2983 last_update_date,
2984 last_update_login,
2985 created_by,
2986 creation_date,
2987 request_id,
2988 program_application_id,
2989 program_id,
2990 program_update_date,
2991 group_id,
2992 source_code,
2993 source_line_id,
2994 organization_id,
2995 wip_entity_id,
2996 primary_item_id,
2997 line_id,
2998 transaction_date,
2999 acct_period_id,
3000 fm_operation_seq_num,
3001 fm_operation_code,
3002 fm_department_id,
3003 fm_intraoperation_step_type,
3004 to_operation_seq_num,
3005 to_operation_code,
3006 to_department_id,
3007 to_intraoperation_step_type,
3008 transaction_quantity,
3009 transaction_uom,
3010 primary_quantity,
3011 primary_uom,
3012 reason_id,
3013 reference,
3014 scrap_account_id,
3015 attribute_category,
3016 attribute1,
3017 attribute2,
3018 attribute3,
3019 attribute4,
3020 attribute5,
3021 attribute6,
3022 attribute7,
3023 attribute8,
3024 attribute9,
3025 attribute10,
3026 attribute11,
3027 attribute12,
3028 attribute13,
3029 attribute14,
3030 attribute15,
3031 qa_collection_id,
3032 overcompletion_transaction_qty,
3033 overcompletion_primary_qty,
3034 overcompletion_transaction_id
3035 )
3036 SELECT wmti.transaction_id,
3037 wmti.last_updated_by, -- last_updated_by --Fix for bug 5195072
3038 SYSDATE, -- last_update_date
3039 DECODE(p_gib.login_id,
3040 -1,NULL,p_gib.login_id), -- last_update_login
3041 wmti.created_by, -- created_by --Fix for bug 5195072
3042 SYSDATE, -- creation_date
3043 DECODE(p_gib.request_id,-1,NULL,p_gib.request_id),
3044 DECODE(p_gib.application_id,-1,NULL,p_gib.application_id),
3045 DECODE(p_gib.program_id,-1,NULL,p_gib.program_id),
3046 DECODE(p_gib.request_id,
3047 -1,NULL,SYSDATE), -- program_update_date
3048 p_gib.group_id,
3049 wmti.source_code,
3050 wmti.source_line_id,
3051 wmti.organization_id,
3052 wmti.wip_entity_id,
3053 wmti.primary_item_id,
3054 wmti.line_id,
3055 wmti.transaction_date,
3056 wmti.acct_period_id,
3057 wmti.fm_operation_seq_num,
3058 wmti.fm_operation_code,
3059 wmti.fm_department_id,
3060 wmti.fm_intraoperation_step_type,
3061 wmti.to_operation_seq_num,
3062 wmti.to_operation_code,
3063 wmti.to_department_id,
3064 wmti.to_intraoperation_step_type,
3065 wmti.transaction_quantity,
3066 wmti.transaction_uom,
3067 wmti.primary_quantity,
3068 wmti.primary_uom,
3069 wmti.reason_id,
3070 wmti.reference,
3071 wmti.scrap_account_id,
3072 wmti.attribute_category,
3073 wmti.attribute1,
3074 wmti.attribute2,
3075 wmti.attribute3,
3076 wmti.attribute4,
3077 wmti.attribute5,
3078 wmti.attribute6,
3079 wmti.attribute7,
3080 wmti.attribute8,
3081 wmti.attribute9,
3082 wmti.attribute10,
3083 wmti.attribute11,
3084 wmti.attribute12,
3085 wmti.attribute13,
3086 wmti.attribute14,
3087 wmti.attribute15,
3088 wmti.qa_collection_id,
3089 wmti.overcompletion_transaction_qty,
3090 wmti.overcompletion_primary_qty,
3091 wmti.overcompletion_transaction_id
3092 FROM wip_move_txn_interface wmti
3093 WHERE wmti.group_id = p_gib.group_id
3094 AND TRUNC(wmti.transaction_date) = TRUNC(p_gib.txn_date)
3095 AND wmti.process_phase = WIP_CONSTANTS.MOVE_PROC
3096 AND wmti.process_status = WIP_CONSTANTS.RUNNING
3097 AND wmti.entity_type = WIP_CONSTANTS.REPETITIVE;
3098
3099 -- IF debug message level = 2, write statement below to log file
3100 IF (l_logLevel <= wip_constants.full_logging) THEN
3101 fnd_message.set_name('WIP', 'WIP_INSERTED_ROWS');
3102 fnd_message.set_token('ENTITY1', SQL%ROWCOUNT);
3103 fnd_message.set_token('ENTITY2', 'WIP_MOVE_TRANSACTIONS');
3104 l_msg := fnd_message.get;
3105 wip_logger.log(p_msg => l_msg,
3106 x_returnStatus => l_returnStatus);
3107 END IF;
3108
3109 x_returnStatus := fnd_api.g_ret_sts_success;
3110
3111 -- write to the log file
3112 IF (l_logLevel <= wip_constants.trace_logging) THEN
3113 wip_logger.exitPoint(p_procName => 'wip_movProc_priv.insert_txn_history',
3114 p_procReturnStatus => x_returnStatus,
3115 p_msg => 'procedure complete',
3116 x_returnStatus => l_returnStatus);
3117 END IF;
3118
3119 EXCEPTION
3120 WHEN others THEN
3121 x_returnStatus := fnd_api.g_ret_sts_unexp_error;
3122 l_errMsg := 'unexpected error: ' || SQLERRM || 'SQLCODE = ' || SQLCODE;
3123
3124 IF (l_logLevel <= wip_constants.trace_logging) THEN
3125 wip_logger.exitPoint(p_procName => 'wip_movProc_priv.insert_txn_history',
3126 p_procReturnStatus => x_returnStatus,
3127 p_msg => l_errMsg,
3128 x_returnStatus => l_returnStatus);
3129 END IF;
3130 fnd_message.set_name('FND', 'FND_GENERIC_MESSAGE');
3131 fnd_message.set_token('MESSAGE', l_errMsg);
3132 fnd_msg_pub.add;
3133 END insert_txn_history;
3134
3135 /*****************************************************************************
3136 * This procedure is equivalent to witoc_delete_child in wiltps5.ppc
3137 * This procedure is used to delete child record from WIP_MOVE_TXN_INTERFACE
3138 * table where the child rows have fm_op and to_op to be the first operation
3139 * and the step types to be Queue
3140 ****************************************************************************/
3141 PROCEDURE delete_child_txn(p_gib IN group_rec_t,
3142 x_returnStatus OUT NOCOPY VARCHAR2) IS
3143
3144 l_params wip_logger.param_tbl_t;
3145 l_returnStatus VARCHAR(1);
3146 l_errMsg VARCHAR2(240);
3147 l_outcome NUMBER := -1;
3148 l_logLevel NUMBER := fnd_log.g_current_runtime_level;
3149
3150 BEGIN
3151 -- write parameter value to log file
3152 IF (l_logLevel <= wip_constants.trace_logging) THEN
3153 l_params(1).paramName := 'p_group_id';
3154 l_params(1).paramValue := p_gib.group_id;
3155 l_params(2).paramName := 'p_txn_date';
3156 l_params(2).paramValue := p_gib.txn_date;
3157 wip_logger.entryPoint(p_procName => 'wip_movProc_priv.delete_child_txn',
3158 p_params => l_params,
3159 x_returnStatus => l_returnStatus);
3160 END IF;
3161
3162 -- delete child records from WIP
3163 DELETE FROM wip_move_txn_interface wmti
3164 WHERE wmti.group_id = p_gib.group_id
3165 AND TRUNC(wmti.transaction_date) = TRUNC(p_gib.txn_date)
3166 AND wmti.process_phase = WIP_CONSTANTS.MOVE_PROC
3167 AND wmti.process_status = WIP_CONSTANTS.RUNNING
3168 AND wmti.overcompletion_transaction_id IS NOT NULL
3169 AND wmti.overcompletion_primary_qty IS NULL
3170 AND wmti.fm_operation_seq_num = wmti.to_operation_seq_num
3171 AND wmti.fm_intraoperation_step_type =
3172 wmti.to_intraoperation_step_type
3173 AND wmti.fm_intraoperation_step_type = WIP_CONSTANTS.QUEUE;
3174
3175 x_returnStatus := fnd_api.g_ret_sts_success;
3176
3177 -- write to the log file
3178 IF (l_logLevel <= wip_constants.trace_logging) THEN
3179 wip_logger.exitPoint(p_procName => 'wip_movProc_priv.delete_child_txn',
3180 p_procReturnStatus => x_returnStatus,
3181 p_msg => 'procedure complete',
3182 x_returnStatus => l_returnStatus);
3183 END IF;
3184
3185 EXCEPTION
3186 WHEN others THEN
3187 x_returnStatus := fnd_api.g_ret_sts_unexp_error;
3188 l_errMsg := 'unexpected error: ' || SQLERRM || 'SQLCODE = ' || SQLCODE;
3189 IF (l_logLevel <= wip_constants.trace_logging) THEN
3190 wip_logger.exitPoint(p_procName => 'wip_movProc_priv.delete_child_txn',
3191 p_procReturnStatus => x_returnStatus,
3192 p_msg => l_errMsg,
3193 x_returnStatus => l_returnStatus);
3194 END IF;
3195 fnd_message.set_name('FND', 'FND_GENERIC_MESSAGE');
3196 fnd_message.set_token('MESSAGE', l_errMsg);
3197 fnd_msg_pub.add;
3198 END delete_child_txn;
3199
3200 /*****************************************************************************
3201 * This procedure is equivalent to witpsar_auto_resources in wiltps2.ppc
3202 * This procedure is used to insert auto-resources associated with move txn
3203 * This procedure insert the record into WIP_COST_TXN_INTERFACE and
3204 * WIP_TXN_ALLOCATIONS IF needed
3205 ****************************************************************************/
3206 PROCEDURE insert_auto_resource(p_gib IN group_rec_t,
3207 x_returnStatus OUT NOCOPY VARCHAR2) IS
3208
3209 l_params wip_logger.param_tbl_t;
3210 l_returnStatus VARCHAR(1);
3211 l_msg VARCHAR(240);
3212 l_errMsg VARCHAR2(240);
3213 l_move move_profile_rec_t;
3214 l_logLevel NUMBER := fnd_log.g_current_runtime_level;
3215
3216 BEGIN
3217 l_move := p_gib.move_profile;
3218
3219 -- write parameter value to log file
3220 IF (l_logLevel <= wip_constants.trace_logging) THEN
3221 l_params(1).paramName := 'p_group_id';
3222 l_params(1).paramValue := p_gib.group_id;
3223 l_params(2).paramName := 'p_txn_date';
3224 l_params(2).paramValue := p_gib.txn_date;
3225 l_params(3).paramName := 'org_id';
3226 l_params(3).paramValue := l_move.org_id;
3227 l_params(4).paramName := 'wip_id';
3228 l_params(4).paramValue := l_move.wip_id;
3229 l_params(5).paramName := 'fmOp';
3230 l_params(5).paramValue := l_move.fmOp;
3231 l_params(6).paramName := 'fmStep';
3232 l_params(6).paramValue := l_move.fmStep;
3233 l_params(7).paramName := 'toOp';
3234 l_params(7).paramValue := l_move.toOp;
3235 l_params(8).paramName := 'toStep';
3236 l_params(8).paramValue := l_move.toStep;
3237 l_params(9).paramName := 'scrapTxn';
3238 l_params(9).paramValue := l_move.scrapTxn;
3239 l_params(10).paramName := 'easyComplete';
3240 l_params(10).paramValue := l_move.easyComplete;
3241 l_params(11).paramName := 'easyReturn';
3242 l_params(11).paramValue := l_move.easyReturn;
3243 l_params(12).paramName := 'jobTxn';
3244 l_params(12).paramValue := l_move.jobTxn;
3245 l_params(13).paramName := 'scheTxn';
3246 l_params(13).paramValue := l_move.scheTxn;
3247 l_params(14).paramName := 'rsrcItem';
3248 l_params(14).paramValue := l_move.rsrcItem;
3249 l_params(15).paramName := 'rsrcLot';
3250 l_params(15).paramValue := l_move.rsrcLot;
3251 l_params(16).paramName := 'poReqItem';
3252 l_params(16).paramValue := l_move.poReqItem;
3253 l_params(17).paramName := 'poRegLot';
3254 l_params(17).paramValue := l_move.poReqLot;
3255 wip_logger.entryPoint(p_procName =>'wip_movProc_priv.insert_auto_resource',
3256 p_params => l_params,
3257 x_returnStatus => l_returnStatus);
3258 END IF;
3259
3260 -- Per item basis type for discrete jobs
3261 IF(l_move.jobTxn = WIP_CONSTANTS.YES AND
3262 l_move.rsrcItem = WIP_CONSTANTS.YES) THEN
3263 /* Fix for bug 4036149: Added leading hint to drive from the table
3264 wip_move_txn_interface to improve performance */
3265 INSERT INTO wip_cost_txn_interface
3266 (transaction_id,
3267 last_update_date,
3268 last_updated_by,
3269 last_updated_by_name,
3270 creation_date,
3271 created_by,
3272 created_by_name,
3273 last_update_login,
3274 request_id,
3275 program_application_id,
3276 program_id,
3277 program_update_date,
3278 group_id,
3279 source_code,
3280 source_line_id,
3281 process_phase,
3282 process_status,
3283 transaction_type,
3284 organization_id,
3285 organization_code,
3286 wip_entity_id,
3287 entity_type,
3288 primary_item_id,
3289 line_id,
3290 line_code,
3291 transaction_date,
3292 acct_period_id,
3293 operation_seq_num,
3294 department_id,
3295 department_code,
3296 employee_id,
3297 resource_seq_num,
3298 resource_id,
3299 resource_code,
3300 phantom_flag,
3301 usage_rate_or_amount,
3302 basis_type,
3303 autocharge_type,
3304 standard_rate_flag,
3305 transaction_quantity,
3306 transaction_uom,
3307 primary_quantity,
3308 primary_uom,
3309 actual_resource_rate,
3310 activity_id,
3311 activity_name,
3312 reason_id,
3313 reason_name,
3314 reference,
3315 move_transaction_id,
3316 po_header_id,
3317 po_line_id,
3318 repetitive_schedule_id,
3319 project_id,
3320 task_id
3321 )
3322 SELECT /*+ leading(wmti) */
3323 NULL, -- transaction_id
3324 SYSDATE, -- last_update_date
3325 wmti.last_updated_by, -- last_updated_by --Fix for bug 5195072
3326 wmti.last_updated_by_name, -- last_updated_by_name --fix for bug 5195072
3327 SYSDATE, -- creation_date
3328 wmti.created_by, -- created_by --Fix for bug 5195072
3329 wmti.created_by_name, -- created_by_name --Fix for bug 5195072
3330 DECODE(p_gib.login_id,-1,NULL,p_gib.login_id),
3331 DECODE(p_gib.request_id,-1,NULL,p_gib.request_id),
3332 DECODE(p_gib.application_id,-1,NULL,p_gib.application_id),
3333 DECODE(p_gib.program_id,-1,NULL,p_gib.program_id),
3334 DECODE(p_gib.request_id,-1,NULL,SYSDATE), -- program_update_date
3335 p_gib.group_id,
3336 wmti.source_code,
3337 wmti.source_line_id,
3338 WIP_CONSTANTS.RES_PROC, -- process_phase
3339 WIP_CONSTANTS.PENDING, -- process_status
3340 WIP_CONSTANTS.RES_TXN, -- transaction_type
3341 wmti.organization_id,
3342 wmti.organization_code,
3343 wmti.wip_entity_id,
3344 wmti.entity_type,
3345 wmti.primary_item_id,
3346 wmti.line_id,
3347 wmti.line_code,
3348 wmti.transaction_date,
3349 wmti.acct_period_id,
3350 wop.operation_seq_num,
3351 NVL(wor.department_id, wop.department_id),
3352 bd.department_code,
3353 NULL, -- employee_id
3354 wor.resource_seq_num,
3355 wor.resource_id,
3356 br.resource_code,
3357 wor.phantom_flag,
3358 wor.usage_rate_or_amount,
3359 wor.basis_type,
3360 wor.autocharge_type,
3361 wor.standard_rate_flag,
3362 wor.usage_rate_or_amount * NVL(wmti.primary_quantity *
3363 DECODE(
3364 SIGN(wmti.to_operation_seq_num - wmti.fm_operation_seq_num),
3365 0,DECODE(SIGN(wmti.fm_intraoperation_step_type -
3366 WIP_CONSTANTS.RUN),
3367 0,DECODE(SIGN(wmti.to_intraoperation_step_type -
3368 WIP_CONSTANTS.RUN),1,1,-1),
3369 -1,DECODE(SIGN(wmti.to_intraoperation_step_type -
3370 WIP_CONSTANTS.RUN),1,1,-1),
3371 1,-1),
3372 1, 1,
3373 -1,-1),
3374 0), -- transaction_quantity
3375 wor.uom_code, -- transaction_uom
3376 wor.usage_rate_or_amount * NVL(wmti.primary_quantity *
3377 DECODE(
3378 SIGN(wmti.to_operation_seq_num - wmti.fm_operation_seq_num),
3379 0,DECODE(SIGN(wmti.fm_intraoperation_step_type -
3380 WIP_CONSTANTS.RUN),
3381 0,DECODE(SIGN(wmti.to_intraoperation_step_type -
3382 WIP_CONSTANTS.RUN),1,1,-1),
3383 -1,DECODE(SIGN(wmti.to_intraoperation_step_type -
3384 WIP_CONSTANTS.RUN),1,1,-1),
3385 1,-1),
3386 1, 1,
3387 -1,-1),
3388 0), -- primary_quantity
3389 wor.uom_code, -- primary_uom
3390 NULL, -- actual_resource_rate
3391 wor.activity_id,
3392 ca.activity, -- activity_name
3393 wmti.reason_id,
3394 wmti.reason_name,
3395 wmti.reference,
3396 wmti.transaction_id, -- move_transaction_id
3397 NULL, -- po_header_id
3398 NULL, -- po_line_id
3399 NULL, -- repetitive_schedule_id
3400 wdj.project_id,
3401 wdj.task_id
3402 FROM bom_departments bd,
3403 bom_resources br,
3404 cst_activities ca,
3405 wip_operation_resources wor,
3406 wip_discrete_jobs wdj,
3407 wip_operations wop,
3408 wip_move_txn_interface wmti
3409 WHERE wmti.group_id = p_gib.group_id
3410 AND TRUNC(wmti.transaction_date) = TRUNC(p_gib.txn_date)
3411 AND wmti.process_phase = WIP_CONSTANTS.MOVE_PROC
3412 AND wmti.process_status = WIP_CONSTANTS.RUNNING
3413 AND (wmti.entity_type = WIP_CONSTANTS.DISCRETE
3414 OR wmti.entity_type = WIP_CONSTANTS.LOTBASED) /* WSM */
3415 AND wop.organization_id = wmti.organization_id
3416 AND wop.wip_entity_id = wmti.wip_entity_id
3417 AND wop.organization_id = wor.organization_id
3418 AND wop.wip_entity_id = wor.wip_entity_id
3419 AND wop.operation_seq_num = wor.operation_seq_num
3420 /* added for OSFM jump enhancement 2541431 */
3421 AND NVL(wop.skip_flag, WIP_CONSTANTS.NO) <> WIP_CONSTANTS.YES
3422 AND wor.autocharge_type = WIP_CONSTANTS.WIP_MOVE
3423 AND wor.basis_type = WIP_CONSTANTS.PER_ITEM
3424 AND wop.organization_id = bd.organization_id
3425 AND NVL(wor.department_id, wop.department_id) = bd.department_id
3426 AND wor.organization_id = br.organization_id
3427 AND wor.resource_id = br.resource_id
3428 AND wor.usage_rate_or_amount <> 0
3429 AND wor.activity_id = ca.activity_id (+)
3430 AND wdj.wip_entity_id = wmti.wip_entity_id
3431 AND wdj.organization_id = wmti.organization_id
3432 AND (
3433 (wop.operation_seq_num >= wmti.fm_operation_seq_num
3434 + DECODE(SIGN(wmti.fm_intraoperation_step_type -
3435 WIP_CONSTANTS.RUN), 1,1,0)
3436 AND wop.operation_seq_num < wmti.to_operation_seq_num
3437 + DECODE(SIGN(wmti.to_intraoperation_step_type -
3438 WIP_CONSTANTS.RUN),1,1,0)
3439 AND (wmti.to_operation_seq_num > wmti.fm_operation_seq_num
3440 OR (wmti.to_operation_seq_num = wmti.fm_operation_seq_num
3441 AND wmti.fm_intraoperation_step_type <= WIP_CONSTANTS.RUN
3442 AND wmti.to_intraoperation_step_type > WIP_CONSTANTS.RUN))
3443 AND (wop.count_point_type < WIP_CONSTANTS.NO_MANUAL
3444 OR wop.operation_seq_num = wmti.fm_operation_seq_num
3445 OR (wop.operation_seq_num = wmti.to_operation_seq_num
3446 AND wmti.to_intraoperation_step_type >
3447 WIP_CONSTANTS.RUN)))
3448 OR
3449 (wop.operation_seq_num < wmti.fm_operation_seq_num
3450 + DECODE(SIGN(wmti.fm_intraoperation_step_type -
3451 WIP_CONSTANTS.RUN),1,1,0)
3452 AND wop.operation_seq_num >= wmti.to_operation_seq_num
3453 + DECODE(SIGN(wmti.to_intraoperation_step_type -
3454 WIP_CONSTANTS.RUN),1,1,0)
3455 AND (wmti.fm_operation_seq_num > wmti.to_operation_seq_num
3456 OR (wmti.fm_operation_seq_num = wmti.to_operation_seq_num
3457 AND wmti.to_intraoperation_step_type <= WIP_CONSTANTS.RUN
3458 AND wmti.fm_intraoperation_step_type > WIP_CONSTANTS.RUN))
3459 AND (wop.count_point_type < WIP_CONSTANTS.NO_MANUAL
3460 OR wop.operation_seq_num = wmti.to_operation_seq_num
3461 OR (wop.operation_seq_num = wmti.fm_operation_seq_num
3462 AND wmti.fm_intraoperation_step_type >
3463 WIP_CONSTANTS.RUN)))
3464 );
3465
3466 -- IF debug message level = 2, write statement below to log file
3467 IF (l_logLevel <= wip_constants.full_logging) THEN
3468 fnd_message.set_name('WIP', 'WIP_INSERTED_ROWS');
3469 fnd_message.set_token('ENTITY1', SQL%ROWCOUNT);
3470 fnd_message.set_token('ENTITY2', 'WIP_COST_TXN_INTERFACE');
3471 l_msg := fnd_message.get;
3472 wip_logger.log(p_msg => l_msg,
3473 x_returnStatus => l_returnStatus);
3474 END IF;
3475
3476 END IF; -- Per item basis type for discrete jobs
3477
3478 -- Per item basis type for repetitive schedule
3479 IF(l_move.scheTxn = WIP_CONSTANTS.YES AND
3480 l_move.rsrcItem = WIP_CONSTANTS.YES) THEN
3481
3482 INSERT INTO wip_cost_txn_interface
3483 (transaction_id,
3484 last_update_date,
3485 last_updated_by,
3486 last_updated_by_name,
3487 creation_date,
3488 created_by,
3489 created_by_name,
3490 last_update_login,
3491 request_id,
3492 program_application_id,
3493 program_id,
3494 program_update_date,
3495 group_id,
3496 source_code,
3497 source_line_id,
3498 process_phase,
3499 process_status,
3500 transaction_type,
3501 organization_id,
3502 organization_code,
3503 wip_entity_id,
3504 entity_type,
3505 primary_item_id,
3506 line_id,
3507 line_code,
3508 transaction_date,
3509 acct_period_id,
3510 operation_seq_num,
3511 department_id,
3512 department_code,
3513 employee_id,
3514 resource_seq_num,
3515 resource_id,
3516 resource_code,
3517 phantom_flag,
3518 usage_rate_or_amount,
3519 basis_type,
3520 autocharge_type,
3521 standard_rate_flag,
3522 transaction_quantity,
3523 transaction_uom,
3524 primary_quantity,
3525 primary_uom,
3526 actual_resource_rate,
3527 activity_id,
3528 activity_name,
3529 reason_id,
3530 reason_name,
3531 reference,
3532 move_transaction_id,
3533 po_header_id,
3534 po_line_id,
3535 repetitive_schedule_id
3536 )
3537 SELECT NULL, -- transaction_id
3538 SYSDATE, -- last_update_date
3539 MAX(wmti.last_updated_by), -- last_updated_by --Fix for bug 5195072
3540 MAX(wmti.last_updated_by_name), -- last_updated_by_name --Fix for bug 5195072
3541 SYSDATE, -- creation_date
3542 MAX(wmti.created_by), -- created_by -- Fix for bug 5195072
3543 MAX(wmti.created_by_name), -- created_by_name --Fix for bug 5195072
3544 DECODE(p_gib.login_id,-1,NULL,p_gib.login_id),
3545 DECODE(p_gib.request_id,-1,NULL,p_gib.request_id),
3546 DECODE(p_gib.application_id,-1,NULL,p_gib.application_id),
3547 DECODE(p_gib.program_id,-1,NULL,p_gib.program_id),
3548 DECODE(p_gib.request_id,-1,NULL,SYSDATE), -- program_update_date
3549 p_gib.group_id,
3550 MAX(wmti.source_code),
3551 MAX(wmti.source_line_id),
3552 WIP_CONSTANTS.RES_PROC, -- process_phase
3553 WIP_CONSTANTS.PENDING, -- process_status
3554 WIP_CONSTANTS.RES_TXN, -- transaction_type
3555 wmti.organization_id,
3556 MAX(wmti.organization_code),
3557 wmti.wip_entity_id,
3558 MAX(wmti.entity_type),
3559 MAX(wmti.primary_item_id),
3560 wmti.line_id,
3561 MAX(wmti.line_code),
3562 MAX(wmti.transaction_date),
3563 MAX(wmti.acct_period_id),
3564 wop.operation_seq_num,
3565 NVL(MAX(wor.department_id), MAX(wop.department_id)),
3566 MAX(bd.department_code),
3567 NULL, -- employee_id
3568 wor.resource_seq_num,
3569 wor.resource_id,
3570 MAX(br.resource_code),
3571 MAX(wor.phantom_flag),
3572 wor.usage_rate_or_amount,
3573 MAX(wor.basis_type),
3574 MAX(wor.autocharge_type),
3575 wor.standard_rate_flag,
3576 SUM(wor.usage_rate_or_amount * NVL(wma.primary_quantity *
3577 DECODE(
3578 SIGN(wmti.to_operation_seq_num-wmti.fm_operation_seq_num),
3579 0, DECODE(SIGN(wmti.fm_intraoperation_step_type -
3580 WIP_CONSTANTS.RUN),
3581 0,DECODE(SIGN(wmti.to_intraoperation_step_type -
3582 WIP_CONSTANTS.RUN),1,1,-1),
3583 -1,DECODE(SIGN(wmti.to_intraoperation_step_type -
3584 WIP_CONSTANTS.RUN),1,1,-1),
3585 1,-1),
3586 1, 1,
3587 -1,-1)
3588 ,0)), -- transaction_quantity
3589 MAX(wor.uom_code), -- transaction_uom
3590 SUM(wor.usage_rate_or_amount * NVL(wma.primary_quantity *
3591 DECODE(
3592 SIGN(wmti.to_operation_seq_num-wmti.fm_operation_seq_num),
3593 0, DECODE(SIGN(wmti.fm_intraoperation_step_type -
3594 WIP_CONSTANTS.RUN),
3595 0,DECODE(SIGN(wmti.to_intraoperation_step_type -
3596 WIP_CONSTANTS.RUN),1,1,-1),
3597 -1,DECODE(SIGN(wmti.to_intraoperation_step_type -
3598 WIP_CONSTANTS.RUN),1,1,-1),
3599 1,-1),
3600 1, 1,
3601 -1,-1)
3602 ,0)), -- primary_quantity
3603 MAX(wor.uom_code), -- primary_uom
3604 NULL, -- acutual_resource_rate
3605 wor.activity_id,
3606 MAX(ca.activity), -- activity_name
3607 MAX(wmti.reason_id),
3608 MAX(wmti.reason_name),
3609 MAX(wmti.reference),
3610 MAX(wmti.transaction_id), -- move_transaction_id
3611 NULL, -- po_header_id
3612 NULL, -- po_line_id
3613 NULL -- repetitive_schedule_id
3614 FROM bom_departments bd,
3615 bom_resources br,
3616 cst_activities ca,
3617 wip_operation_resources wor,
3618 wip_move_txn_allocations wma,
3619 wip_operations wop,
3620 wip_move_txn_interface wmti
3621 WHERE wmti.group_id = p_gib.group_id
3622 AND TRUNC(wmti.transaction_date) = TRUNC(p_gib.txn_date)
3623 AND wmti.process_phase = WIP_CONSTANTS.MOVE_PROC
3624 AND wmti.process_status = WIP_CONSTANTS.RUNNING
3625 AND wmti.entity_type = WIP_CONSTANTS.REPETITIVE
3626 AND wop.organization_id = wmti.organization_id
3627 AND wop.wip_entity_id = wmti.wip_entity_id
3628 AND wop.wip_entity_id = wor.wip_entity_id
3629 AND wop.operation_seq_num = wor.operation_seq_num
3630 AND wop.organization_id = wor.organization_id
3631 AND wop.repetitive_schedule_id = wma.repetitive_schedule_id
3632 AND wor.repetitive_schedule_id = wma.repetitive_schedule_id
3633 AND wmti.organization_id = wma.organization_id
3634 AND wmti.transaction_id = wma.transaction_id
3635 AND wor.autocharge_type = WIP_CONSTANTS.WIP_MOVE
3636 AND wor.basis_type = WIP_CONSTANTS.PER_ITEM
3637 AND wop.organization_id = bd.organization_id
3638 AND NVL(wor.department_id, wop.department_id) = bd.department_id
3639 AND wor.organization_id = br.organization_id
3640 AND wor.resource_id = br.resource_id
3641 AND wor.usage_rate_or_amount <> 0
3642 AND wor.activity_id = ca.activity_id (+)
3643 AND (
3644 (wop.operation_seq_num >= wmti.fm_operation_seq_num
3645 + DECODE(SIGN(wmti.fm_intraoperation_step_type -
3646 WIP_CONSTANTS.RUN),1,1,0)
3647 AND wop.operation_seq_num < wmti.to_operation_seq_num
3648 + DECODE(SIGN(wmti.to_intraoperation_step_type -
3649 WIP_CONSTANTS.RUN),1,1,0)
3650 AND (wmti.to_operation_seq_num > wmti.fm_operation_seq_num
3651 OR (wmti.to_operation_seq_num = wmti.fm_operation_seq_num
3652 AND wmti.fm_intraoperation_step_type <= WIP_CONSTANTS.RUN
3653 AND wmti.to_intraoperation_step_type > WIP_CONSTANTS.RUN))
3654 AND (wop.count_point_type < WIP_CONSTANTS.NO_MANUAL
3655 OR wop.operation_seq_num = wmti.fm_operation_seq_num
3656 OR (wop.operation_seq_num = wmti.to_operation_seq_num
3657 AND wmti.to_intraoperation_step_type >
3658 WIP_CONSTANTS.RUN)))
3659 OR
3660 (wop.operation_seq_num < wmti.fm_operation_seq_num
3661 + DECODE(SIGN(wmti.fm_intraoperation_step_type -
3662 WIP_CONSTANTS.RUN),1,1,0)
3663 AND wop.operation_seq_num >= wmti.to_operation_seq_num
3664 + DECODE(SIGN(wmti.to_intraoperation_step_type -
3665 WIP_CONSTANTS.RUN),1,1,0)
3666 AND (wmti.fm_operation_seq_num > wmti.to_operation_seq_num
3667 OR (wmti.fm_operation_seq_num = wmti.to_operation_seq_num
3668 AND wmti.to_intraoperation_step_type <= WIP_CONSTANTS.RUN
3669 AND wmti.fm_intraoperation_step_type > WIP_CONSTANTS.RUN))
3670 AND (wop.count_point_type < WIP_CONSTANTS.NO_MANUAL
3671 OR wop.operation_seq_num = wmti.to_operation_seq_num
3672 OR (wop.operation_seq_num = wmti.fm_operation_seq_num
3673 AND wmti.fm_intraoperation_step_type >
3674 WIP_CONSTANTS.RUN))))
3675 GROUP BY wmti.organization_id,
3676 wmti.wip_entity_id,
3677 wmti.line_id,
3678 wop.operation_seq_num,
3679 wor.resource_seq_num,
3680 wor.resource_id,
3681 wor.activity_id,
3682 wor.standard_rate_flag,
3683 wor.usage_rate_or_amount,
3684 wmti.transaction_id;
3685
3686 -- IF debug message level = 2, write statement below to log file
3687 IF (l_logLevel <= wip_constants.full_logging) THEN
3688 fnd_message.set_name('WIP', 'WIP_INSERTED_ROWS');
3689 fnd_message.set_token('ENTITY1', SQL%ROWCOUNT);
3690 fnd_message.set_token('ENTITY2', 'WIP_COST_TXN_INTERFACE');
3691 l_msg := fnd_message.get;
3692 wip_logger.log(p_msg => l_msg,
3693 x_returnStatus => l_returnStatus);
3694 END IF;
3695
3696 END IF; -- Per item basis type for repetitive schedule
3697
3698 /*------------------------------------------------------------+
3699 | Per order basis type for discrete jobs
3700 department_id cannot be changed so we can take the MAX,
3701 also columns such as usage_rate_or_amount are not part of
3702 the transaction they are looked up in wip_operation_resources
3703 +------------------------------------------------------------*/
3704 IF(l_move.jobTxn = WIP_CONSTANTS.YES AND
3705 l_move.rsrcLot = WIP_CONSTANTS.YES) THEN
3706
3707 INSERT INTO wip_cost_txn_interface
3708 (transaction_id,
3709 last_update_date,
3710 last_updated_by,
3711 last_updated_by_name,
3712 creation_date,
3713 created_by,
3714 created_by_name,
3715 last_update_login,
3716 request_id,
3717 program_application_id,
3718 program_id,
3719 program_update_date,
3720 group_id,
3721 source_code,
3722 source_line_id,
3723 process_phase,
3724 process_status,
3725 transaction_type,
3726 organization_id,
3727 organization_code,
3728 wip_entity_id,
3729 entity_type,
3730 primary_item_id,
3731 line_id,
3732 line_code,
3733 transaction_date,
3734 acct_period_id,
3735 operation_seq_num,
3736 department_id,
3737 department_code,
3738 employee_id,
3739 resource_seq_num,
3740 resource_id,
3741 resource_code,
3742 phantom_flag,
3743 usage_rate_or_amount,
3744 basis_type,
3745 autocharge_type,
3746 standard_rate_flag,
3747 transaction_quantity,
3748 transaction_uom,
3749 primary_quantity,
3750 primary_uom,
3751 actual_resource_rate,
3752 activity_id,
3753 activity_name,
3754 reason_id,
3755 reason_name,
3756 reference,
3757 move_transaction_id,
3758 po_header_id,
3759 po_line_id,
3760 repetitive_schedule_id,
3761 project_id,
3762 task_id
3763 )
3764 SELECT NULL, -- transaction_id
3765 SYSDATE, -- last_update_date
3766 MAX(wmti.last_updated_by), -- last_updated_by --Fix for bug 5195072
3767 MAX(wmti.last_updated_by_name), -- last_updated_by_name --Fix for bug 5195072
3768 SYSDATE, -- creation_date
3769 MAX(wmti.created_by), -- created_by --Fix for bug 5195072
3770 MAX(wmti.created_by_name), -- created_by_name --Fix for bug 5195072
3771 DECODE(p_gib.login_id,-1,NULL,p_gib.login_id),
3772 DECODE(p_gib.request_id,-1,NULL,p_gib.request_id),
3773 DECODE(p_gib.application_id,-1,NULL,p_gib.application_id),
3774 DECODE(p_gib.program_id,-1,NULL,p_gib.program_id),
3775 DECODE(p_gib.request_id,-1,NULL,SYSDATE), -- program_update_date
3776 p_gib.group_id,
3777 MAX(wmti.source_code), -- source_code
3778 -- Fixed bug 2465148
3779 MAX(wmti.source_line_id), -- source_line_id
3780 WIP_CONSTANTS.RES_PROC, -- process_phase
3781 WIP_CONSTANTS.PENDING, -- process_status
3782 WIP_CONSTANTS.RES_TXN, -- transaction_type
3783 wop.organization_id,
3784 MAX(wmti.organization_code),
3785 wop.wip_entity_id,
3786 MAX(entity_type),
3787 MAX(wmti.primary_item_id),
3788 MAX(wmti.line_id),
3789 MAX(wmti.line_code),
3790 MAX(wmti.transaction_date),
3791 MAX(wmti.acct_period_id),
3792 wop.operation_seq_num,
3793 NVL(MAX(wor.department_id), MAX(wop.department_id)),
3794 MAX(bd.department_code),
3795 NULL, -- employee_id
3796 wor.resource_seq_num,
3797 MAX(wor.resource_id),
3798 MAX(br.resource_code),
3799 MAX(wor.phantom_flag),
3800 MAX(wor.usage_rate_or_amount),
3801 MAX(wor.basis_type),
3802 MAX(wor.autocharge_type),
3803 MAX(wor.standard_rate_flag),
3804 MAX(wor.usage_rate_or_amount) * -- transaction_quantity
3805 DECODE(SIGN(MAX(wop.quantity_completed) +
3806 NVL(SUM(wmti.primary_quantity *
3807 DECODE(SIGN(wmti.to_operation_seq_num -
3808 wmti.fm_operation_seq_num),
3809 0,DECODE(SIGN(wmti.fm_intraoperation_step_type -
3810 WIP_CONSTANTS.RUN),
3811 0,DECODE(SIGN(wmti.to_intraoperation_step_type -
3812 WIP_CONSTANTS.RUN),1,1,-1),
3813 -1,DECODE(SIGN(wmti.to_intraoperation_step_type -
3814 WIP_CONSTANTS.RUN),1,1,-1),
3815 1,-1),
3816 1, 1,
3817 -1,-1)
3818 ),0)), -- NVL
3819 0, DECODE(SIGN(MAX(wop.quantity_completed)),1,-1,0),
3820 1, DECODE(SIGN(MAX(wop.quantity_completed)),1,0,1),
3821 -1, DECODE(SIGN(MAX(wop.quantity_completed)),1,-1,0)),
3822 MAX(wor.uom_code), -- transaction_uom
3823 MAX(wor.usage_rate_or_amount) * -- primary_quantity
3824 DECODE(SIGN(MAX(wop.quantity_completed) +
3825 NVL(SUM(wmti.primary_quantity *
3826 DECODE(SIGN(wmti.to_operation_seq_num -
3827 wmti.fm_operation_seq_num),
3828 0,DECODE(SIGN(wmti.fm_intraoperation_step_type -
3829 WIP_CONSTANTS.RUN),
3830 0,DECODE(SIGN(wmti.to_intraoperation_step_type -
3831 WIP_CONSTANTS.RUN),1,1,-1),
3832 -1,DECODE(SIGN(wmti.to_intraoperation_step_type -
3833 WIP_CONSTANTS.RUN),1,1,-1),
3834 1,-1),
3835 1, 1,
3836 -1,-1)
3837 ),0)), -- NVL
3838 0, DECODE(SIGN(MAX(wop.quantity_completed)),1,-1,0),
3839 1, DECODE(SIGN(MAX(wop.quantity_completed)),1,0,1),
3840 -1, DECODE(SIGN(MAX(wop.quantity_completed)),1,-1,0)),
3841 MAX(wor.uom_code), -- primary_uom
3842 NULL, -- actual_resource_rate
3843 MAX(wor.activity_id),
3844 MAX(ca.activity), -- activity_name
3845 NULL, -- reason_id
3846 NULL, -- reason_name
3847 -- Fixed bug 2506653
3848 MAX(wmti.reference), -- reference
3849 MAX(wmti.transaction_id), -- move_transaction_id
3850 NULL, -- po_header_id
3851 NULL, -- po_line_id
3852 NULL, -- repetitive_schedule_id
3853 MAX(wdj.project_id),
3854 MAX(wdj.task_id)
3855 FROM bom_departments bd,
3856 bom_resources br,
3857 cst_activities ca,
3858 wip_operation_resources wor,
3859 wip_discrete_jobs wdj,
3860 wip_operations wop,
3861 wip_move_txn_interface wmti
3862 WHERE wmti.group_id = p_gib.group_id
3863 AND TRUNC(wmti.transaction_date) = TRUNC(p_gib.txn_date)
3864 AND wmti.process_phase = WIP_CONSTANTS.MOVE_PROC
3865 AND wmti.process_status = WIP_CONSTANTS.RUNNING
3866 AND (wmti.entity_type = WIP_CONSTANTS.DISCRETE
3867 OR wmti.entity_type = WIP_CONSTANTS.LOTBASED) /* WSM */
3868 AND wop.organization_id = wmti.organization_id
3869 AND wop.wip_entity_id = wmti.wip_entity_id
3870 AND wop.wip_entity_id = wor.wip_entity_id
3871 AND wop.operation_seq_num = wor.operation_seq_num
3872 /* added for OSFM jump enhancement 2541431 */
3873 AND NVL(wop.skip_flag, WIP_CONSTANTS.NO) <> WIP_CONSTANTS.YES
3874 AND wop.organization_id = wor.organization_id
3875 AND wor.autocharge_type = WIP_CONSTANTS.WIP_MOVE
3876 AND wor.basis_type = WIP_CONSTANTS.PER_LOT
3877 AND wop.organization_id = bd.organization_id
3878 AND NVL(wor.department_id, wop.department_id) = bd.department_id
3879 AND wor.organization_id = br.organization_id
3880 AND wor.resource_id = br.resource_id
3881 AND wor.usage_rate_or_amount <> 0
3882 AND wor.activity_id = ca.activity_id (+)
3883 AND wdj.wip_entity_id = wmti.wip_entity_id
3884 AND wdj.organization_id = wmti.organization_id
3885 AND (
3886 (wop.operation_seq_num >= wmti.fm_operation_seq_num
3887 + DECODE(SIGN(wmti.fm_intraoperation_step_type -
3888 WIP_CONSTANTS.RUN),1,1,0)
3889 AND wop.operation_seq_num < wmti.to_operation_seq_num
3890 + DECODE(SIGN(wmti.to_intraoperation_step_type -
3891 WIP_CONSTANTS.RUN),1,1,0)
3892 AND (wmti.to_operation_seq_num > wmti.fm_operation_seq_num
3893 OR (wmti.to_operation_seq_num = wmti.fm_operation_seq_num
3894 AND wmti.fm_intraoperation_step_type <= WIP_CONSTANTS.RUN
3895 AND wmti.to_intraoperation_step_type > WIP_CONSTANTS.RUN))
3896 AND (wop.count_point_type < WIP_CONSTANTS.NO_MANUAL
3897 OR wop.operation_seq_num = wmti.fm_operation_seq_num
3898 OR (wop.operation_seq_num = wmti.to_operation_seq_num
3899 AND wmti.to_intraoperation_step_type >
3900 WIP_CONSTANTS.RUN)))
3901 OR
3902 (wop.operation_seq_num < wmti.fm_operation_seq_num
3903 + DECODE(SIGN(wmti.fm_intraoperation_step_type -
3904 WIP_CONSTANTS.RUN),1,1,0)
3905 AND wop.operation_seq_num >= wmti.to_operation_seq_num
3906 + DECODE(SIGN(wmti.to_intraoperation_step_type -
3907 WIP_CONSTANTS.RUN),1,1,0)
3908 AND (wmti.fm_operation_seq_num > wmti.to_operation_seq_num
3909 OR (wmti.fm_operation_seq_num = wmti.to_operation_seq_num
3910 AND wmti.to_intraoperation_step_type <= WIP_CONSTANTS.RUN
3911 AND wmti.fm_intraoperation_step_type > WIP_CONSTANTS.RUN))
3912 AND (wop.count_point_type < WIP_CONSTANTS.NO_MANUAL
3913 OR wop.operation_seq_num = wmti.to_operation_seq_num
3914 OR (wop.operation_seq_num = wmti.fm_operation_seq_num
3915 AND wmti.fm_intraoperation_step_type >
3916 WIP_CONSTANTS.RUN))))
3917 GROUP BY wop.organization_id,
3918 wop.wip_entity_id,
3919 wop.operation_seq_num,
3920 wor.resource_seq_num
3921 HAVING 0 <>
3922 DECODE(SIGN(MAX(wop.quantity_completed) +
3923 NVL(SUM(wmti.primary_quantity *
3924 DECODE(SIGN(wmti.to_operation_seq_num -
3925 wmti.fm_operation_seq_num),
3926 0,DECODE(SIGN(wmti.fm_intraoperation_step_type -
3927 WIP_CONSTANTS.RUN),
3928 0,DECODE(SIGN(wmti.to_intraoperation_step_type -
3929 WIP_CONSTANTS.RUN),1,1,-1),
3930 -1,DECODE(SIGN(wmti.to_intraoperation_step_type -
3931 WIP_CONSTANTS.RUN),1,1,-1),
3932 1,-1),
3933 1, 1,
3934 -1,-1)
3935 ),0)), -- NVL
3936 0, DECODE(SIGN(MAX(wop.quantity_completed)),1,-1,0),
3937 1, DECODE(SIGN(MAX(wop.quantity_completed)),1,0,1),
3938 -1, DECODE(SIGN(MAX(wop.quantity_completed)),1,-1,0));
3939
3940 -- IF debug message level = 2, write statement below to log file
3941 IF (l_logLevel <= wip_constants.full_logging) THEN
3942 fnd_message.set_name('WIP', 'WIP_INSERTED_ROWS');
3943 fnd_message.set_token('ENTITY1', SQL%ROWCOUNT);
3944 fnd_message.set_token('ENTITY2', 'WIP_COST_TXN_INTERFACE');
3945 l_msg := fnd_message.get;
3946 wip_logger.log(p_msg => l_msg,
3947 x_returnStatus => l_returnStatus);
3948 END IF;
3949
3950 END IF; -- Per order basis type for discrete jobs
3951
3952 -- Per order basis type for repetitive
3953 IF(l_move.scheTxn = WIP_CONSTANTS.YES AND
3954 l_move.rsrcLot = WIP_CONSTANTS.YES) THEN
3955
3956 INSERT INTO wip_cost_txn_interface
3957 (transaction_id,
3958 last_update_date,
3959 last_updated_by,
3960 last_updated_by_name,
3961 creation_date,
3962 created_by,
3963 created_by_name,
3964 last_update_login,
3965 request_id,
3966 program_application_id,
3967 program_id,
3968 program_update_date,
3969 group_id,
3970 source_code,
3971 source_line_id,
3972 process_phase,
3973 process_status,
3974 transaction_type,
3975 organization_id,
3976 organization_code,
3977 wip_entity_id,
3978 entity_type,
3979 primary_item_id,
3980 line_id,
3981 line_code,
3982 transaction_date,
3983 acct_period_id,
3984 operation_seq_num,
3985 department_id,
3986 department_code,
3987 employee_id,
3988 resource_seq_num,
3989 resource_id,
3990 resource_code,
3991 phantom_flag,
3992 usage_rate_or_amount,
3993 basis_type,
3994 autocharge_type,
3995 standard_rate_flag,
3996 transaction_quantity,
3997 transaction_uom,
3998 primary_quantity,
3999 primary_uom,
4000 actual_resource_rate,
4001 activity_id,
4002 activity_name,
4003 reason_id,
4004 reason_name,
4005 reference,
4006 move_transaction_id,
4007 po_header_id,
4008 po_line_id,
4009 repetitive_schedule_id
4010 )
4011 SELECT NULL, -- transaction_id
4012 SYSDATE, -- last_update_date
4013 MAX(wmti.last_updated_by), -- last_updated_by --Fix for bug 5195072
4014 MAX(wmti.last_updated_by_name), -- last_updated_by_name --Fix for bug 5195072
4015 SYSDATE, -- creation_date
4016 MAX(wmti.created_by), -- created_by --Fix for bug 5195072
4017 MAX(wmti.created_by_name), -- created_by_name --Fix for bug 5195072
4018 DECODE(p_gib.login_id,-1,NULL,p_gib.login_id),
4019 DECODE(p_gib.request_id,-1,NULL,p_gib.request_id),
4020 DECODE(p_gib.application_id,-1,NULL,p_gib.application_id),
4021 DECODE(p_gib.program_id,-1,NULL,p_gib.program_id),
4022 DECODE(p_gib.request_id,-1,NULL,SYSDATE), -- program_update_date
4023 p_gib.group_id,
4024 MAX(wmti.source_code), -- source_code
4025 -- Fixed bug 2465148
4026 MAX(wmti.source_line_id), -- source_line_id
4027 WIP_CONSTANTS.RES_PROC, -- process_phase
4028 WIP_CONSTANTS.PENDING, -- process_status
4029 WIP_CONSTANTS.RES_TXN, -- transaction_type
4030 wop.organization_id,
4031 MAX(wmti.organization_code),
4032 wop.wip_entity_id,
4033 MAX(entity_type),
4034 MAX(wmti.primary_item_id),
4035 wmti.line_id,
4036 MAX(wmti.line_code),
4037 MAX(wmti.transaction_date),
4038 MAX(wmti.acct_period_id),
4039 wop.operation_seq_num,
4040 NVL(MAX(wor.department_id), MAX(wop.department_id)),
4041 MAX(bd.department_code),
4042 NULL, -- employee_id
4043 wor.resource_seq_num,
4044 wor.resource_id,
4045 MAX(br.resource_code),
4046 MAX(wor.phantom_flag),
4047 wor.usage_rate_or_amount,
4048 MAX(wor.basis_type),
4049 MAX(wor.autocharge_type),
4050 wor.standard_rate_flag,
4051 1, -- transaction_quantity
4052 MAX(wor.uom_code), -- transaction_uom
4053 1, -- primary_quantity
4054 MAX(wor.uom_code), -- primary_uom
4055 NULL, -- actual_resource_rate
4056 wor.activity_id,
4057 MAX(ca.activity), -- activity_name
4058 NULL, -- reason_id
4059 NULL, -- reason_name
4060 -- Fixed bug 2506653
4061 MAX(wmti.reference), -- reference
4062 MAX(wmti.transaction_id), -- move_transaction_id
4063 NULL, -- po_header_id
4064 NULL, -- po_line_id
4065 wma.repetitive_schedule_id
4066 FROM bom_departments bd,
4067 bom_resources br,
4068 cst_activities ca,
4069 wip_operation_resources wor,
4070 wip_move_txn_allocations wma,
4071 wip_operations wop,
4072 wip_move_txn_interface wmti
4073 WHERE wmti.group_id = p_gib.group_id
4074 AND TRUNC(wmti.transaction_date) = TRUNC(p_gib.txn_date)
4075 AND wmti.process_phase = WIP_CONSTANTS.MOVE_PROC
4076 AND wmti.process_status = WIP_CONSTANTS.RUNNING
4077 AND wmti.entity_type = WIP_CONSTANTS.REPETITIVE
4078 AND wop.organization_id = wmti.organization_id
4079 AND wop.wip_entity_id = wmti.wip_entity_id
4080 AND wop.wip_entity_id = wor.wip_entity_id
4081 AND wop.operation_seq_num = wor.operation_seq_num
4082 AND wop.organization_id = wor.organization_id
4083 AND wop.repetitive_schedule_id = wma.repetitive_schedule_id
4084 AND wor.repetitive_schedule_id = wma.repetitive_schedule_id
4085 AND wmti.organization_id = wma.organization_id
4086 AND wmti.transaction_id = wma.transaction_id
4087 AND wor.autocharge_type = WIP_CONSTANTS.WIP_MOVE
4088 AND wor.basis_type = WIP_CONSTANTS.PER_LOT
4089 AND wop.organization_id = bd.organization_id
4090 AND NVL(wor.department_id, wop.department_id) = bd.department_id
4091 AND wor.organization_id = br.organization_id
4092 AND wor.resource_id = br.resource_id
4093 AND wor.usage_rate_or_amount <> 0
4094 AND wor.activity_id = ca.activity_id (+)
4095 AND (
4096 (wop.operation_seq_num >= wmti.fm_operation_seq_num
4097 + DECODE(SIGN(wmti.fm_intraoperation_step_type -
4098 WIP_CONSTANTS.RUN),1,1,0)
4099 AND wop.operation_seq_num < wmti.to_operation_seq_num
4100 + DECODE(SIGN(wmti.to_intraoperation_step_type -
4101 WIP_CONSTANTS.RUN),1,1,0)
4102 AND (wmti.to_operation_seq_num > wmti.fm_operation_seq_num
4103 OR (wmti.to_operation_seq_num = wmti.fm_operation_seq_num
4104 AND wmti.fm_intraoperation_step_type <= WIP_CONSTANTS.RUN
4105 AND wmti.to_intraoperation_step_type > WIP_CONSTANTS.RUN))
4106 AND (wop.count_point_type < WIP_CONSTANTS.NO_MANUAL
4107 OR wop.operation_seq_num = wmti.fm_operation_seq_num
4108 OR (wop.operation_seq_num = wmti.to_operation_seq_num
4109 AND wmti.to_intraoperation_step_type >
4110 WIP_CONSTANTS.RUN)))
4111 OR
4112 (wop.operation_seq_num < wmti.fm_operation_seq_num
4113 + DECODE(SIGN(wmti.fm_intraoperation_step_type -
4114 WIP_CONSTANTS.RUN),1,1,0)
4115 AND wop.operation_seq_num >= wmti.to_operation_seq_num
4116 + DECODE(SIGN(wmti.to_intraoperation_step_type -
4117 WIP_CONSTANTS.RUN),1,1,0)
4118 AND (wmti.fm_operation_seq_num > wmti.to_operation_seq_num
4119 OR (wmti.fm_operation_seq_num = wmti.to_operation_seq_num
4120 AND wmti.to_intraoperation_step_type <= WIP_CONSTANTS.RUN
4121 AND wmti.fm_intraoperation_step_type > WIP_CONSTANTS.RUN))
4122 AND (wop.count_point_type < WIP_CONSTANTS.NO_MANUAL
4123 OR wop.operation_seq_num = wmti.to_operation_seq_num
4124 OR (wop.operation_seq_num = wmti.fm_operation_seq_num
4125 AND wmti.fm_intraoperation_step_type >
4126 WIP_CONSTANTS.RUN))))
4127 GROUP BY wop.organization_id,
4128 wop.wip_entity_id,
4129 wmti.line_id,
4130 wma.repetitive_schedule_id,
4131 wop.operation_seq_num,
4132 wor.resource_seq_num,
4133 wor.resource_id,
4134 wor.activity_id,
4135 wor.standard_rate_flag,
4136 wor.usage_rate_or_amount
4137 HAVING 0 <>
4138 DECODE(SIGN(MAX(wop.quantity_completed) + NVL(SUM(
4139 wma.primary_quantity *
4140 DECODE(SIGN(wmti.to_operation_seq_num -
4141 wmti.fm_operation_seq_num),
4142 0,DECODE(SIGN(wmti.fm_intraoperation_step_type -
4143 WIP_CONSTANTS.RUN),
4144 0,DECODE(SIGN(wmti.to_intraoperation_step_type -
4145 WIP_CONSTANTS.RUN),1,1,-1),
4146 -1,DECODE(SIGN(wmti.to_intraoperation_step_type -
4147 WIP_CONSTANTS.RUN),1,1,-1),
4148 1,-1),
4149 1, 1,
4150 -1,-1)
4151 ),0)), -- NVL
4152 0, DECODE(SIGN(MAX(wop.quantity_completed)),1,-1,0),
4153 1, DECODE(SIGN(MAX(wop.quantity_completed)),1,0,1),
4154 -1, DECODE(SIGN(MAX(wop.quantity_completed)),1,-1,0));
4155
4156 -- IF debug message level = 2, write statement below to log file
4157 IF (l_logLevel <= wip_constants.full_logging) THEN
4158 fnd_message.set_name('WIP', 'WIP_INSERTED_ROWS');
4159 fnd_message.set_token('ENTITY1', SQL%ROWCOUNT);
4160 fnd_message.set_token('ENTITY2', 'WIP_COST_TXN_INTERFACE');
4161 l_msg := fnd_message.get;
4162 wip_logger.log(p_msg => l_msg,
4163 x_returnStatus => l_returnStatus);
4164 END IF;
4165
4166 END IF; -- Per order basis type for repetitive
4167
4168 -- IF resource per item or resource per lot, set transaction_id
4169 IF(l_move.rsrcItem = WIP_CONSTANTS.YES OR
4170 l_move.rsrcLot = WIP_CONSTANTS.YES) THEN
4171
4172 /*------------------------------------------------------------+
4173 | Generate transaction_id for WIP_TXN_ALLOCATIONS |
4174 +------------------------------------------------------------*/
4175 UPDATE wip_cost_txn_interface
4176 SET transaction_id = wip_transactions_s.nextval
4177 WHERE group_id = p_gib.group_id
4178 AND TRUNC(transaction_date) = TRUNC(p_gib.txn_date)
4179 AND transaction_type = WIP_CONSTANTS.RES_TXN;
4180
4181 -- IF debug message level = 2, write statement below to log file
4182 IF (l_logLevel <= wip_constants.full_logging) THEN
4183 fnd_message.set_name('WIP', 'WIP_UPDATED_ROWS');
4184 fnd_message.set_token('ENTITY1', SQL%ROWCOUNT);
4185 fnd_message.set_token('ENTITY2', 'WIP_COST_TXN_INTERFACE');
4186 l_msg := fnd_message.get;
4187 wip_logger.log(p_msg => l_msg,
4188 x_returnStatus => l_returnStatus);
4189 END IF;
4190
4191 END IF; -- Either resource per item or resource per lot
4192
4193 -- Per order basis type for repetitive
4194 IF(l_move.scheTxn = WIP_CONSTANTS.YES AND
4195 l_move.rsrcLot = WIP_CONSTANTS.YES) THEN
4196
4197 /*------------------------------------------------------------+
4198 | Insert into cost allocations for repetitive schedules |
4199 | per lot
4200 +------------------------------------------------------------*/
4201
4202 /*------------------------------------------------------------+
4203 | Columns to insert into WIP_TXN_ALLOCATIONS |
4204 | |
4205 | transaction_id, |
4206 | repetitive_schedule_id, organization_id, |
4207 | last_update_date, last_updated_by, creation_date, |
4208 | created_by, last_update_login, request_id, |
4209 | program_application_id, program_id, program_update_date, |
4210 | transaction_quantity, |
4211 | primary_quantity, |
4212 | |
4213 +------------------------------------------------------------*/
4214 INSERT INTO wip_txn_allocations
4215 (transaction_id,
4216 repetitive_schedule_id,
4217 organization_id,
4218 last_update_date,
4219 last_updated_by,
4220 creation_date,
4221 created_by,
4222 last_update_login,
4223 request_id,
4224 program_application_id,
4225 program_id,
4226 program_update_date,
4227 transaction_quantity,
4228 primary_quantity
4229 )
4230 SELECT wci.transaction_id,
4231 wma.repetitive_schedule_id,
4232 MAX(wmti.organization_id),
4233 SYSDATE, -- last_update_date
4234 MAX(wmti.last_updated_by), -- last_updated_by --Fix for bug 5195072
4235 SYSDATE, -- creation_date
4236 MAX(wmti.created_by), -- created_by --Fix for bug 5195072
4237 DECODE(p_gib.login_id,-1,NULL,p_gib.login_id),
4238 DECODE(p_gib.request_id,-1,NULL,p_gib.request_id),
4239 DECODE(p_gib.application_id,-1,NULL,p_gib.application_id),
4240 DECODE(p_gib.program_id,-1,NULL,p_gib.program_id),
4241 DECODE(p_gib.request_id,-1,NULL,SYSDATE), -- program_update_date
4242 MAX(wor.usage_rate_or_amount) * -- transaction_quantity
4243 DECODE(SIGN(MAX(wop.quantity_completed) +
4244 NVL(SUM(wma.primary_quantity *
4245 DECODE(SIGN(wmti.to_operation_seq_num -
4246 wmti.fm_operation_seq_num),
4247 0,DECODE(SIGN(wmti.fm_intraoperation_step_type -
4248 WIP_CONSTANTS.RUN),
4249 0,DECODE(SIGN(wmti.to_intraoperation_step_type -
4250 WIP_CONSTANTS.RUN),1,1,-1),
4251 -1,DECODE(SIGN(wmti.to_intraoperation_step_type -
4252 WIP_CONSTANTS.RUN),1,1,-1),
4253 1,-1),
4254 1, 1,
4255 -1,-1)
4256 ),0)), -- NVL
4257 0, DECODE(SIGN(MAX(wop.quantity_completed)),1,-1,0),
4258 1, DECODE(SIGN(MAX(wop.quantity_completed)),1,0,1),
4259 -1, DECODE(SIGN(MAX(wop.quantity_completed)),1,-1,0)),
4260 MAX(wor.usage_rate_or_amount) * -- primary_quantity
4261 DECODE(SIGN(MAX(wop.quantity_completed) +
4262 NVL(SUM(wma.primary_quantity *
4263 DECODE(SIGN(wmti.to_operation_seq_num -
4264 wmti.fm_operation_seq_num),
4265 0,DECODE(SIGN(wmti.fm_intraoperation_step_type -
4266 WIP_CONSTANTS.RUN),
4267 0,DECODE(SIGN(wmti.to_intraoperation_step_type -
4268 WIP_CONSTANTS.RUN),1,1,-1),
4269 -1,DECODE(SIGN(wmti.to_intraoperation_step_type -
4270 WIP_CONSTANTS.RUN),1,1,-1),
4271 1,-1),
4272 1, 1,
4273 -1,-1)
4274 ),0)), -- NVL
4275 0, DECODE(SIGN(MAX(wop.quantity_completed)),1,-1,0),
4276 1, DECODE(SIGN(MAX(wop.quantity_completed)),1,0,1),
4277 -1, DECODE(SIGN(MAX(wop.quantity_completed)),1,-1,0))
4278
4279 FROM wip_operation_resources wor,
4280 wip_operations wop,
4281 wip_move_txn_allocations wma,
4282 wip_cost_txn_interface wci,
4283 wip_move_txn_interface wmti
4284 WHERE wmti.group_id = p_gib.group_id
4285 AND TRUNC(wmti.transaction_date) = TRUNC(p_gib.txn_date)
4286 AND wmti.process_phase = WIP_CONSTANTS.MOVE_PROC
4287 AND wmti.process_status = WIP_CONSTANTS.RUNNING
4288 AND wmti.entity_type = WIP_CONSTANTS.REPETITIVE
4289 AND wmti.group_id = wci.group_id
4290 AND wci.organization_id = wmti.organization_id
4291 AND wci.wip_entity_id = wmti.wip_entity_id
4292 AND wci.operation_seq_num = wop.operation_seq_num
4293 AND wci.basis_type = WIP_CONSTANTS.PER_LOT
4294 AND wci.transaction_type = WIP_CONSTANTS.RES_TXN
4295 AND wop.repetitive_schedule_id = wor.repetitive_schedule_id
4296 AND wci.organization_id = wor.organization_id
4297 AND wci.wip_entity_id = wor.wip_entity_id
4298 AND wci.operation_seq_num = wor.operation_seq_num
4299 AND wci.resource_seq_num = wor.resource_seq_num
4300 AND wci.resource_id = wor.resource_id
4301 AND wci.standard_rate_flag = wor.standard_rate_flag
4302 AND wci.usage_rate_or_amount = wor.usage_rate_or_amount
4303 AND NVL(wci.activity_id, -1) = NVL(wor.activity_id, -1)
4304 AND wor.autocharge_type = WIP_CONSTANTS.WIP_MOVE
4305 AND wor.basis_type = WIP_CONSTANTS.PER_LOT
4306 AND wop.organization_id = wmti.organization_id
4307 AND wop.wip_entity_id = wmti.wip_entity_id
4308 AND wop.repetitive_schedule_id = wma.repetitive_schedule_id
4309 AND wmti.organization_id = wma.organization_id
4310 AND wmti.transaction_id = wma.transaction_id
4311 AND wci.repetitive_schedule_id = wma.repetitive_schedule_id
4312 GROUP BY wci.transaction_id,
4313 wma.repetitive_schedule_id;
4314
4315 -- IF debug message level = 2, write statement below to log file
4316 IF (l_logLevel <= wip_constants.full_logging) THEN
4317 fnd_message.set_name('WIP', 'WIP_INSERTED_ROWS');
4318 fnd_message.set_token('ENTITY1', SQL%ROWCOUNT);
4319 fnd_message.set_token('ENTITY2', 'WIP_TXN_ALLOCATIONS');
4320 l_msg := fnd_message.get;
4321 wip_logger.log(p_msg => l_msg,
4322 x_returnStatus => l_returnStatus);
4323 END IF;
4324
4325 END IF; -- Per order basis type for repetitive
4326
4327 x_returnStatus := fnd_api.g_ret_sts_success;
4328
4329 -- write to the log file
4330 IF (l_logLevel <= wip_constants.trace_logging) THEN
4331 wip_logger.exitPoint(p_procName => 'wip_movProc_priv.insert_auto_resource',
4332 p_procReturnStatus => x_returnStatus,
4333 p_msg => 'procedure complete',
4334 x_returnStatus => l_returnStatus);
4335 END IF;
4336
4337 EXCEPTION
4338 WHEN others THEN
4339 x_returnStatus := fnd_api.g_ret_sts_unexp_error;
4340 l_errMsg := 'unexpected error: ' || SQLERRM || 'SQLCODE = ' || SQLCODE;
4341
4342 IF (l_logLevel <= wip_constants.trace_logging) THEN
4343 wip_logger.exitPoint(p_procName=>'wip_movProc_priv.insert_auto_resource',
4344 p_procReturnStatus => x_returnStatus,
4345 p_msg => l_errMsg,
4346 x_returnStatus => l_returnStatus);
4347 END IF;
4348 fnd_message.set_name('FND', 'FND_GENERIC_MESSAGE');
4349 fnd_message.set_token('MESSAGE', l_errMsg);
4350 fnd_msg_pub.add;
4351 END insert_auto_resource;
4352
4353 /*****************************************************************************
4354 * This procedure is equivalent to wipiara in wiltca.ppc
4355 * This procedure is used to allocate per-item auto-resouce according to the
4356 * material allocation in the coresponding move transactions.
4357 * This procedure insert the record into WIP_TXN_ALLOCATIONS
4358 * This procedure must be called only after move allocation is successfully
4359 * completed
4360 ****************************************************************************/
4361 PROCEDURE insert_txn_alloc(p_gib IN group_rec_t,
4362 x_returnStatus OUT NOCOPY VARCHAR2) IS
4363
4364 l_params wip_logger.param_tbl_t;
4365 l_returnStatus VARCHAR(1);
4366 l_msg VARCHAR(240);
4367 l_errMsg VARCHAR2(240);
4368 l_logLevel NUMBER := fnd_log.g_current_runtime_level;
4369
4370 BEGIN
4371 -- write parameter value to log file
4372 IF (l_logLevel <= wip_constants.trace_logging) THEN
4373 l_params(1).paramName := 'p_group_id';
4374 l_params(1).paramValue := p_gib.group_id;
4375 wip_logger.entryPoint(p_procName =>'wip_movProc_priv.insert_txn_alloc',
4376 p_params => l_params,
4377 x_returnStatus => l_returnStatus);
4378 END IF;
4379
4380 /*---------------------------------------------------------------------+
4381 For each pENDing automatic per-item resource transaction in the group,
4382 the allocator uses the transaction associated material allocation in
4383 WIP_MOVE_TXN_ALLOCATION to insert one or more allocation records into
4384 WIP_TXN_ALLOCATIONS.
4385 +--------------------------------------------------------------------*/
4386 INSERT INTO wip_txn_allocations
4387 (transaction_id,
4388 repetitive_schedule_id,
4389 organization_id,
4390 last_update_date,
4391 last_updated_by,
4392 creation_date,
4393 created_by,
4394 last_update_login,
4395 request_id,
4396 program_application_id,
4397 program_id,
4398 program_update_date,
4399 transaction_quantity,
4400 primary_quantity
4401 )
4402 SELECT wcti.transaction_id,
4403 wmta.repetitive_schedule_id,
4404 wcti.organization_id,
4405 SYSDATE, -- last_update_date
4406 wcti.last_updated_by,
4407 SYSDATE, -- creation_date
4408 wcti.created_by,
4409 wcti.last_update_login,
4410 wcti.request_id,
4411 wcti.program_application_id,
4412 wcti.program_id,
4413 SYSDATE, -- program_update_date
4414 wmta.transaction_quantity * wor.usage_rate_or_amount
4415 * DECODE(SIGN(wmti.to_operation_seq_num -
4416 wmti.fm_operation_seq_num),
4417 0, DECODE(SIGN(wmti.fm_intraoperation_step_type -
4418 WIP_CONSTANTS.RUN),
4419 1, -1, DECODE(SIGN(wmti.to_intraoperation_step_type -
4420 WIP_CONSTANTS.RUN),1, 1, -1)),
4421 1, 1,
4422 -1,-1), -- transaction_quantity
4423 wmta.primary_quantity * wor.usage_rate_or_amount
4424 * DECODE(SIGN(wmti.to_operation_seq_num -
4425 wmti.fm_operation_seq_num),
4426 0, DECODE(SIGN(wmti.fm_intraoperation_step_type -
4427 WIP_CONSTANTS.RUN),
4428 1, -1, DECODE(SIGN(wmti.to_intraoperation_step_type -
4429 WIP_CONSTANTS.RUN),1, 1, -1)),
4430 1, 1,
4431 -1,-1) -- primary_quantity
4432 FROM wip_operation_resources wor,
4433 wip_move_txn_allocations wmta,
4434 wip_move_txn_interface wmti,
4435 wip_cost_txn_interface wcti
4436 WHERE wcti.group_id = p_gib.group_id
4437 AND wcti.process_phase = WIP_CONSTANTS.RES_PROC
4438 AND wcti.process_status = WIP_CONSTANTS.PENDING
4439 AND wcti.transaction_type = WIP_CONSTANTS.RES_TXN
4440 AND wcti.move_transaction_id IS NOT NULL /* Automatic resource */
4441 AND wcti.entity_type = WIP_CONSTANTS.REPETITIVE
4442 AND wcti.basis_type = WIP_CONSTANTS.PER_ITEM
4443 AND wcti.group_id = wmti.group_id /* Bug 938039, 979553*/
4444 AND wcti.move_transaction_id = wmti.transaction_id
4445 AND wcti.move_transaction_id = wmta.transaction_id
4446 AND wcti.organization_id = wmta.organization_id
4447 AND wor.organization_id = wcti.organization_id
4448 AND wor.wip_entity_id = wcti.wip_entity_id
4449 AND wor.repetitive_schedule_id = wmta.repetitive_schedule_id
4450 AND wor.operation_seq_num = wcti.operation_seq_num
4451 AND wor.resource_seq_num = wcti.resource_seq_num
4452 AND wor.resource_id = wcti.resource_id
4453 AND NVL(wor.activity_id, -1) = NVL(wcti.activity_id, -1)
4454 AND wor.standard_rate_flag = wcti.standard_rate_flag
4455 AND wor.usage_rate_or_amount = wcti.usage_rate_or_amount;
4456
4457 -- IF debug message level = 2, write statement below to log file
4458 IF (l_logLevel <= wip_constants.full_logging) THEN
4459 fnd_message.set_name('WIP', 'WIP_INSERTED_ROWS');
4460 fnd_message.set_token('ENTITY1', SQL%ROWCOUNT);
4461 fnd_message.set_token('ENTITY2', 'WIP_TXN_ALLOCATIONS');
4462 l_msg := fnd_message.get;
4463 wip_logger.log(p_msg => l_msg,
4464 x_returnStatus => l_returnStatus);
4465 END IF;
4466
4467 x_returnStatus := fnd_api.g_ret_sts_success;
4468
4469 -- write to the log file
4470 IF (l_logLevel <= wip_constants.trace_logging) THEN
4471 wip_logger.exitPoint(p_procName => 'wip_movProc_priv.insert_txn_alloc',
4472 p_procReturnStatus => x_returnStatus,
4473 p_msg => 'procedure complete',
4474 x_returnStatus => l_returnStatus);
4475 END IF;
4476
4477 EXCEPTION
4478 WHEN others THEN
4479 x_returnStatus := fnd_api.g_ret_sts_unexp_error;
4480 l_errMsg := 'unexpected error: ' || SQLERRM || 'SQLCODE = ' || SQLCODE;
4481
4482 IF (l_logLevel <= wip_constants.trace_logging) THEN
4483 wip_logger.exitPoint(p_procName=>'wip_movProc_priv.insert_txn_alloc',
4484 p_procReturnStatus => x_returnStatus,
4485 p_msg => l_errMsg,
4486 x_returnStatus => l_returnStatus);
4487 END IF;
4488 fnd_message.set_name('FND', 'FND_GENERIC_MESSAGE');
4489 fnd_message.set_token('MESSAGE', l_errMsg);
4490 fnd_msg_pub.add;
4491 END insert_txn_alloc;
4492
4493 /*****************************************************************************
4494 * This procedure is equivalent to witpsdo_dept_overheads in wiltps3.ppc
4495 * This procedure is used to insert department overhead info into
4496 * WIP_COST_TXN_INTERFACE and WIP_TXN_ALLOCATIONS IF needed
4497 ****************************************************************************/
4498 PROCEDURE insert_dept_overhead(p_gib IN group_rec_t,
4499 x_returnStatus OUT NOCOPY VARCHAR2) IS
4500
4501 l_params wip_logger.param_tbl_t;
4502 l_returnStatus VARCHAR(1);
4503 l_msg VARCHAR(240);
4504 l_errMsg VARCHAR2(240);
4505 l_move move_profile_rec_t;
4506 l_logLevel NUMBER := fnd_log.g_current_runtime_level;
4507
4508 BEGIN
4509 l_move := p_gib.move_profile;
4510
4511 -- write parameter value to log file
4512 IF (l_logLevel <= wip_constants.trace_logging) THEN
4513 l_params(1).paramName := 'p_group_id';
4514 l_params(1).paramValue := p_gib.group_id;
4515 l_params(2).paramName := 'p_txn_date';
4516 l_params(2).paramValue := p_gib.txn_date;
4517 l_params(3).paramName := 'org_id';
4518 l_params(3).paramValue := l_move.org_id;
4519 l_params(4).paramName := 'wip_id';
4520 l_params(4).paramValue := l_move.wip_id;
4521 l_params(5).paramName := 'fmOp';
4522 l_params(5).paramValue := l_move.fmOp;
4523 l_params(6).paramName := 'fmStep';
4524 l_params(6).paramValue := l_move.fmStep;
4525 l_params(7).paramName := 'toOp';
4526 l_params(7).paramValue := l_move.toOp;
4527 l_params(8).paramName := 'toStep';
4528 l_params(8).paramValue := l_move.toStep;
4529 l_params(9).paramName := 'scrapTxn';
4530 l_params(9).paramValue := l_move.scrapTxn;
4531 l_params(10).paramName := 'easyComplete';
4532 l_params(10).paramValue := l_move.easyComplete;
4533 l_params(11).paramName := 'easyReturn';
4534 l_params(11).paramValue := l_move.easyReturn;
4535 l_params(12).paramName := 'jobTxn';
4536 l_params(12).paramValue := l_move.jobTxn;
4537 l_params(13).paramName := 'scheTxn';
4538 l_params(13).paramValue := l_move.scheTxn;
4539 l_params(14).paramName := 'rsrcItem';
4540 l_params(14).paramValue := l_move.rsrcItem;
4541 l_params(15).paramName := 'rsrcLot';
4542 l_params(15).paramValue := l_move.rsrcLot;
4543 l_params(16).paramName := 'poReqItem';
4544 l_params(16).paramValue := l_move.poReqItem;
4545 l_params(17).paramName := 'poRegLot';
4546 l_params(17).paramValue := l_move.poReqLot;
4547 wip_logger.entryPoint(p_procName =>'wip_movProc_priv.insert_dept_overhead',
4548 p_params => l_params,
4549 x_returnStatus => l_returnStatus);
4550 END IF;
4551
4552 -- Per item basis type for discrete jobs
4553 IF(l_move.jobTxn = WIP_CONSTANTS.YES) THEN
4554
4555 INSERT INTO wip_cost_txn_interface
4556 (transaction_id,
4557 last_update_date,
4558 last_updated_by,
4559 last_updated_by_name,
4560 creation_date,
4561 created_by,
4562 created_by_name,
4563 last_update_login,
4564 request_id,
4565 program_application_id,
4566 program_id,
4567 program_update_date,
4568 group_id,
4569 source_code,
4570 source_line_id,
4571 process_phase,
4572 process_status,
4573 transaction_type,
4574 organization_id,
4575 organization_code,
4576 wip_entity_id,
4577 entity_type,
4578 primary_item_id,
4579 line_id,
4580 line_code,
4581 transaction_date,
4582 acct_period_id,
4583 operation_seq_num,
4584 department_id,
4585 department_code,
4586 employee_id,
4587 resource_seq_num,
4588 resource_id,
4589 resource_code,
4590 phantom_flag,
4591 usage_rate_or_amount,
4592 basis_type,
4593 autocharge_type,
4594 standard_rate_flag,
4595 transaction_quantity,
4596 transaction_uom,
4597 primary_quantity,
4598 primary_uom,
4599 actual_resource_rate,
4600 activity_id,
4601 activity_name,
4602 reason_id,
4603 reason_name,
4604 reference,
4605 move_transaction_id,
4606 po_header_id,
4607 po_line_id,
4608 repetitive_schedule_id,
4609 project_id,
4610 task_id
4611 )
4612 SELECT NULL, -- transaction_id
4613 SYSDATE, -- last_update_date
4614 MAX(wmti.last_updated_by), -- last_updated_by --Fix for bug 5195072
4615 MAX(wmti.last_updated_by_name),-- last_updated_by_name --Fix for bug 5195072
4616 SYSDATE, -- creation_date
4617 MAX(wmti.created_by), -- created_by --Fix for bug 5195072
4618 MAX(wmti.created_by_name), -- created_by_name --Fix for bug 5195072
4619 DECODE(p_gib.login_id,-1,NULL,p_gib.login_id),
4620 DECODE(p_gib.request_id,-1,NULL,p_gib.request_id),
4621 DECODE(p_gib.application_id,-1,NULL,p_gib.application_id),
4622 DECODE(p_gib.program_id,-1,NULL,p_gib.program_id),
4623 DECODE(p_gib.request_id,-1,NULL,SYSDATE), -- program_update_date
4624 p_gib.group_id,
4625 MAX(wmti.source_code),
4626 MAX(wmti.source_line_id),
4627 WIP_CONSTANTS.RES_PROC, -- process_phase
4628 WIP_CONSTANTS.PENDING, -- process_status
4629 WIP_CONSTANTS.OVHD_TXN, -- transaction_type
4630 MAX(wmti.organization_id),
4631 MAX(wmti.organization_code),
4632 MAX(wmti.wip_entity_id),
4633 MAX(wmti.entity_type),
4634 MAX(wmti.primary_item_id),
4635 MAX(wmti.line_id),
4636 MAX(wmti.line_code),
4637 MAX(wmti.transaction_date),
4638 MAX(wmti.acct_period_id),
4639 wop.operation_seq_num,
4640 NVL(wor.department_id, wop.department_id),
4641 MAX(bd.department_code),
4642 NULL, -- employee_id
4643 NULL, -- resource_seq_num
4644 NULL, -- resource_id
4645 NULL, -- resource_code
4646 MAX(wor.phantom_flag),
4647 NULL, -- usage_rate_or_amount
4648 WIP_CONSTANTS.PER_ITEM, -- basis_type
4649 WIP_CONSTANTS.WIP_MOVE, -- autocharge_type
4650 NULL, -- standard_rate_flag
4651 MAX(NVL(DECODE(wor.phantom_flag, 1, wro.quantity_per_assembly, 1)
4652 * wmti.primary_quantity *
4653 DECODE(SIGN(wmti.to_operation_seq_num -
4654 wmti.fm_operation_seq_num),
4655 0,DECODE(SIGN(wmti.fm_intraoperation_step_type -
4656 WIP_CONSTANTS.RUN),
4657 0,DECODE(SIGN(wmti.to_intraoperation_step_type -
4658 WIP_CONSTANTS.RUN),1,1,-1),
4659 -1,DECODE(SIGN(wmti.to_intraoperation_step_type -
4660 WIP_CONSTANTS.RUN),1,1,-1),
4661 1,-1),
4662 1, 1,
4663 -1,-1)
4664 ,0)), -- transaction_quantity
4665 MAX(wmti.primary_uom), -- transaction_uom
4666 MAX(NVL(DECODE(wor.phantom_flag, 1, wro.quantity_per_assembly, 1)
4667 * wmti.primary_quantity *
4668 DECODE(SIGN(wmti.to_operation_seq_num -
4669 wmti.fm_operation_seq_num),
4670 0,DECODE(SIGN(wmti.fm_intraoperation_step_type -
4671 WIP_CONSTANTS.RUN),
4672 0,DECODE(SIGN(wmti.to_intraoperation_step_type -
4673 WIP_CONSTANTS.RUN),1,1,-1),
4674 -1,DECODE(SIGN(wmti.to_intraoperation_step_type -
4675 WIP_CONSTANTS.RUN),1,1,-1),
4676 1,-1),
4677 1, 1,
4678 -1,-1)
4679 ,0)), -- primary_quantity
4680 MAX(wmti.primary_uom), -- primary_uom
4681 NULL, -- actual_resource_rate
4682 NULL, -- activity_id
4683 NULL, -- activity_name
4684 MAX(wmti.reason_id),
4685 MAX(wmti.reason_name),
4686 MAX(wmti.reference),
4687 MAX(wmti.transaction_id), -- move_transaction_id
4688 NULL, -- po_header_id
4689 NULL, -- po_line_id
4690 NULL, -- repetitive_schedule_id
4691 MAX(wdj.project_id),
4692 MAX(wdj.task_id)
4693 FROM bom_departments bd,
4694 wip_operations wop,
4695 wip_operation_resources wor,
4696 wip_discrete_jobs wdj,
4697 wip_move_txn_interface wmti,
4698 wip_requirement_operations WRO
4699 WHERE wmti.group_id = p_gib.group_id
4700 AND TRUNC(wmti.transaction_date) = TRUNC(p_gib.txn_date)
4701 AND wdj.wip_entity_id = wmti.wip_entity_id
4702 AND wdj.organization_id = wmti.organization_id
4703 AND wmti.process_phase = WIP_CONSTANTS.MOVE_PROC
4704 AND wmti.process_status = WIP_CONSTANTS.RUNNING
4705 AND (wmti.entity_type = WIP_CONSTANTS.DISCRETE
4706 OR wmti.entity_type = WIP_CONSTANTS.LOTBASED)/* WSM */
4707 AND wop.organization_id = wmti.organization_id
4708 AND wop.wip_entity_id = wmti.wip_entity_id
4709 AND wop.organization_id = bd.organization_id
4710 AND NVL(wor.department_id, wop.department_id) = bd.department_id
4711 AND wop.organization_id = wor.organization_id(+)
4712 AND wop.wip_entity_id = wor.wip_entity_id(+)
4713 AND wop.operation_seq_num = wor.operation_seq_num(+)
4714 /* added for OSFM jump enhancement 2541431 */
4715 AND NVL(wop.skip_flag, WIP_CONSTANTS.NO) <> WIP_CONSTANTS.YES
4716 AND wor.wip_entity_id = wro.wip_entity_id (+)
4717 AND wor.organization_id = wro.organization_id (+)
4718 /* Fixed bug 3881663. Op seq in wro is a negative number,
4719 * but op seq in wor is a positive number.*/
4720 AND -wor.operation_seq_num = wro.operation_seq_num (+)
4721 AND wor.phantom_item_id = wro.inventory_item_id (+)
4722 /*bug 3930251 -> insert into WCTI only if there are records in CDO)*/
4723 AND EXISTS
4724 ( SELECT 1 FROM cst_department_overheads cdo
4725 WHERE cdo.organization_id = bd.organization_id
4726 AND cdo.department_id = bd.department_id
4727 )
4728 AND (
4729 (wop.operation_seq_num >= wmti.fm_operation_seq_num
4730 + DECODE(SIGN(wmti.fm_intraoperation_step_type -
4731 WIP_CONSTANTS.RUN),1,1,0)
4732 AND wop.operation_seq_num < wmti.to_operation_seq_num
4733 + DECODE(SIGN(wmti.to_intraoperation_step_type -
4734 WIP_CONSTANTS.RUN),1,1,0)
4735 AND(wmti.to_operation_seq_num > wmti.fm_operation_seq_num
4736 OR (wmti.to_operation_seq_num = wmti.fm_operation_seq_num
4737 AND wmti.fm_intraoperation_step_type <= WIP_CONSTANTS.RUN
4738 AND wmti.to_intraoperation_step_type > WIP_CONSTANTS.RUN))
4739 AND (wop.count_point_type < WIP_CONSTANTS.NO_MANUAL
4740 OR wop.operation_seq_num = wmti.fm_operation_seq_num
4741 OR (wop.operation_seq_num = wmti.to_operation_seq_num
4742 AND wmti.to_intraoperation_step_type >
4743 WIP_CONSTANTS.RUN)))
4744 OR
4745 (wop.operation_seq_num < wmti.fm_operation_seq_num
4746 + DECODE(SIGN(wmti.fm_intraoperation_step_type -
4747 WIP_CONSTANTS.RUN),1,1,0)
4748 AND wop.operation_seq_num >= wmti.to_operation_seq_num
4749 + DECODE(SIGN(wmti.to_intraoperation_step_type -
4750 WIP_CONSTANTS.RUN),1,1,0)
4751 AND (wmti.fm_operation_seq_num > wmti.to_operation_seq_num
4752 OR (wmti.fm_operation_seq_num = wmti.to_operation_seq_num
4753 AND wmti.to_intraoperation_step_type <= WIP_CONSTANTS.RUN
4754 AND wmti.fm_intraoperation_step_type > WIP_CONSTANTS.RUN))
4755 AND (wop.count_point_type < WIP_CONSTANTS.NO_MANUAL
4756 OR wop.operation_seq_num = wmti.to_operation_seq_num
4757 OR (wop.operation_seq_num = wmti.fm_operation_seq_num
4758 AND wmti.fm_intraoperation_step_type >
4759 WIP_CONSTANTS.RUN))))
4760 GROUP BY wop.wip_entity_id,
4761 wop.operation_seq_num,
4762 wor.department_id,/*Fixed bug 2834503*/
4763 wop.department_id,
4764 wor.phantom_item_id,
4765 wor.phantom_op_seq_num,
4766 wmti.transaction_id; /* 2821017 */
4767
4768 -- IF debug message level = 2, write statement below to log file
4769 IF (l_logLevel <= wip_constants.full_logging) THEN
4770 fnd_message.set_name('WIP', 'WIP_INSERTED_ROWS');
4771 fnd_message.set_token('ENTITY1', SQL%ROWCOUNT);
4772 fnd_message.set_token('ENTITY2', 'WIP_COST_TXN_INTERFACE');
4773 l_msg := fnd_message.get;
4774 wip_logger.log(p_msg => l_msg,
4775 x_returnStatus => l_returnStatus);
4776 END IF;
4777
4778 END IF; --Per item basis type for discrete jobs
4779
4780 -- Per item basis type for repetitive schedule
4781 IF(l_move.scheTxn = WIP_CONSTANTS.YES) THEN
4782
4783 INSERT INTO wip_cost_txn_interface
4784 (transaction_id,
4785 last_update_date,
4786 last_updated_by,
4787 last_updated_by_name,
4788 creation_date,
4789 created_by,
4790 created_by_name,
4791 last_update_login,
4792 request_id,
4793 program_application_id,
4794 program_id,
4795 program_update_date,
4796 group_id,
4797 source_code,
4798 source_line_id,
4799 process_phase,
4800 process_status,
4801 transaction_type,
4802 organization_id,
4803 organization_code,
4804 wip_entity_id,
4805 entity_type,
4806 primary_item_id,
4807 line_id,
4808 line_code,
4809 transaction_date,
4810 acct_period_id,
4811 operation_seq_num,
4812 department_id,
4813 department_code,
4814 employee_id,
4815 resource_seq_num,
4816 resource_id,
4817 resource_code,
4818 phantom_flag,
4819 usage_rate_or_amount,
4820 basis_type,
4821 autocharge_type,
4822 standard_rate_flag,
4823 transaction_quantity,
4824 transaction_uom,
4825 primary_quantity,
4826 primary_uom,
4827 actual_resource_rate,
4828 activity_id,
4829 activity_name,
4830 reason_id,
4831 reason_name,
4832 reference,
4833 move_transaction_id,
4834 po_header_id,
4835 po_line_id,
4836 repetitive_schedule_id
4837 )
4838 SELECT NULL, -- transaction_id
4839 SYSDATE, -- last_update_date
4840 MAX(wmti.last_updated_by), -- last_updated_by --Fix for bug 5195072
4841 MAX(wmti.last_updated_by_name), -- last_updated_by_name --Fix for bug 5195072
4842 SYSDATE, -- creation_date
4843 MAX(wmti.created_by), -- created_by --Fix for bug 5195072
4844 MAX(wmti.created_by_name), -- created_by_name --Fix for bug 5195072
4845 DECODE(p_gib.login_id,-1,NULL,p_gib.login_id),
4846 DECODE(p_gib.request_id,-1,NULL,p_gib.request_id),
4847 DECODE(p_gib.application_id,-1,NULL,p_gib.application_id),
4848 DECODE(p_gib.program_id,-1,NULL,p_gib.program_id),
4849 DECODE(p_gib.request_id,-1,NULL,SYSDATE), -- program_update_date
4850 p_gib.group_id,
4851 MAX(wmti.source_code),
4852 MAX(wmti.source_line_id),
4853 WIP_CONSTANTS.RES_PROC, -- process_phase
4854 WIP_CONSTANTS.PENDING, -- process_status
4855 WIP_CONSTANTS.OVHD_TXN, -- transaction_type
4856 wmti.organization_id,
4857 MAX(wmti.organization_code),
4858 wmti.wip_entity_id,
4859 MAX(wmti.entity_type),
4860 MAX(wmti.primary_item_id),
4861 wmti.line_id,
4862 MAX(wmti.line_code),
4863 MAX(wmti.transaction_date),
4864 MAX(wmti.acct_period_id),
4865 wor.operation_seq_num,
4866 NVL(wor.department_id, wop.department_id),
4867 MAX(bd.department_code),
4868 NULL, -- employee_id
4869 NULL, -- resource_seq_num
4870 NULL, -- resource_id
4871 NULL, -- resource_code
4872 max(wor.phantom_flag),
4873 NULL, -- usage_rate_or_amount
4874 WIP_CONSTANTS.PER_ITEM, -- basis_type
4875 WIP_CONSTANTS.WIP_MOVE, -- autocharge_type
4876 NULL, -- standard_rate_flag
4877 SUM(NVL(wma.primary_quantity *
4878 DECODE(SIGN(wmti.to_operation_seq_num -
4879 wmti.fm_operation_seq_num),
4880 0,DECODE(SIGN(wmti.fm_intraoperation_step_type -
4881 WIP_CONSTANTS.RUN),
4882 0,DECODE(SIGN(wmti.to_intraoperation_step_type -
4883 WIP_CONSTANTS.RUN),1,1,-1),
4884 -1,DECODE(SIGN(wmti.to_intraoperation_step_type -
4885 WIP_CONSTANTS.RUN),1,1,-1),
4886 1,-1),
4887 1, 1,
4888 -1,-1)
4889 ,0)), -- transaction_quantity
4890 MAX(wmti.primary_uom), -- transaction_uom
4891 SUM(NVL(wma.primary_quantity *
4892 DECODE(SIGN(wmti.to_operation_seq_num -
4893 wmti.fm_operation_seq_num),
4894 0,DECODE(SIGN(wmti.fm_intraoperation_step_type -
4895 WIP_CONSTANTS.RUN),
4896 0,DECODE(SIGN(wmti.to_intraoperation_step_type -
4897 WIP_CONSTANTS.RUN),1,1,-1),
4898 -1,DECODE(SIGN(wmti.to_intraoperation_step_type -
4899 WIP_CONSTANTS.RUN),1,1,-1),
4900 1,-1),
4901 1, 1,
4902 -1,-1)
4903 ,0)), -- primary_quantity
4904 MAX(wmti.primary_uom), -- primary_uom
4905 NULL, -- actual_resource_rate
4906 NULL, -- activity_id
4907 NULL, -- activity_name
4908 MAX(wmti.reason_id),
4909 MAX(wmti.reason_name),
4910 MAX(wmti.reference),
4911 MAX(wmti.transaction_id), -- move_transaction_id
4912 NULL, -- po_header_id
4913 NULL, -- po_line_id
4914 NULL -- repetitive_schedule_id
4915 FROM bom_departments bd,
4916 wip_move_txn_allocations wma,
4917 wip_operations wop,
4918 wip_move_txn_interface wmti,
4919 wip_operation_resources wor
4920 WHERE wmti.group_id = p_gib.group_id
4921 AND TRUNC(wmti.transaction_date) = TRUNC(p_gib.txn_date)
4922 AND wmti.process_phase = WIP_CONSTANTS.MOVE_PROC
4923 AND wmti.process_status = WIP_CONSTANTS.RUNNING
4924 AND wmti.entity_type = WIP_CONSTANTS.REPETITIVE
4925 AND wop.organization_id = wmti.organization_id
4926 AND wop.wip_entity_id = wmti.wip_entity_id
4927 AND wmti.organization_id = wma.organization_id
4928 AND wmti.transaction_id = wma.transaction_id
4929 AND wop.repetitive_schedule_id = wma.repetitive_schedule_id
4930 AND wop.organization_id = bd.organization_id
4931 AND NVL(wor.department_id, wop.department_id) = bd.department_id
4932 AND wor.organization_id = wop.organization_id
4933 AND wor.wip_entity_id = wop.wip_entity_id
4934 AND wor.operation_seq_num = wop.operation_seq_num
4935 AND wor.repetitive_schedule_id = wop.repetitive_schedule_id
4936 AND (
4937 (wop.operation_seq_num >= wmti.fm_operation_seq_num
4938 + DECODE(SIGN(wmti.fm_intraoperation_step_type -
4939 WIP_CONSTANTS.RUN),1,1,0)
4940 AND wop.operation_seq_num < wmti.to_operation_seq_num
4941 + DECODE(SIGN(wmti.to_intraoperation_step_type -
4942 WIP_CONSTANTS.RUN),1,1,0)
4943 AND (wmti.to_operation_seq_num > wmti.fm_operation_seq_num
4944 OR (wmti.to_operation_seq_num = wmti.fm_operation_seq_num
4945 AND wmti.fm_intraoperation_step_type <= WIP_CONSTANTS.RUN
4946 AND wmti.to_intraoperation_step_type > WIP_CONSTANTS.RUN))
4947 AND (wop.count_point_type < WIP_CONSTANTS.NO_MANUAL
4948 OR wop.operation_seq_num = wmti.fm_operation_seq_num
4949 OR (wop.operation_seq_num = wmti.to_operation_seq_num
4950 AND wmti.to_intraoperation_step_type >
4951 WIP_CONSTANTS.RUN)))
4952 OR
4953 (wop.operation_seq_num < wmti.fm_operation_seq_num
4954 + DECODE(SIGN(wmti.fm_intraoperation_step_type -
4955 WIP_CONSTANTS.RUN),1,1,0)
4956 AND wop.operation_seq_num >= wmti.to_operation_seq_num
4957 + DECODE(SIGN(wmti.to_intraoperation_step_type -
4958 WIP_CONSTANTS.RUN),1,1,0)
4959 AND (wmti.fm_operation_seq_num > wmti.to_operation_seq_num
4960 OR (wmti.fm_operation_seq_num = wmti.to_operation_seq_num
4961 AND wmti.to_intraoperation_step_type <= WIP_CONSTANTS.RUN
4962 AND wmti.fm_intraoperation_step_type > WIP_CONSTANTS.RUN))
4963 AND (wop.count_point_type < WIP_CONSTANTS.NO_MANUAL
4964 OR wop.operation_seq_num = wmti.to_operation_seq_num
4965 OR (wop.operation_seq_num = wmti.fm_operation_seq_num
4966 AND wmti.fm_intraoperation_step_type >
4967 WIP_CONSTANTS.RUN))))
4968 GROUP BY wmti.organization_id,
4969 wmti.wip_entity_id,
4970 wmti.line_id,
4971 wor.operation_seq_num,
4972 wmti.transaction_id,
4973 wor.department_id, /*fixed bug 2834503*/
4974 wop.department_id,
4975 wor.phantom_item_id,
4976 wor.phantom_op_seq_num;
4977
4978 -- IF debug message level = 2, write statement below to log file
4979 IF (l_logLevel <= wip_constants.full_logging) THEN
4980 fnd_message.set_name('WIP', 'WIP_INSERTED_ROWS');
4981 fnd_message.set_token('ENTITY1', SQL%ROWCOUNT);
4982 fnd_message.set_token('ENTITY2', 'WIP_COST_TXN_INTERFACE');
4983 l_msg := fnd_message.get;
4984 wip_logger.log(p_msg => l_msg,
4985 x_returnStatus => l_returnStatus);
4986 END IF;
4987
4988 END IF; -- Per item basis type for repetitive schedule
4989
4990 /*-----------------------------------------------------------------------+
4991 | Per order basis type for discrete jobs
4992 +-----------------------------------------------------------------------*/
4993 /* Grouping wmti.source_line_id, wmti.source_code, wmti.primary_uom
4994 | wmti.reason_id, wmti.reference may not make sense since they are
4995 | tied to the transaction_id. NULL them out [24-JUL-92, John, Djuki.
4996 | We have more than one record per op_seq because of quantity_completed
4997 +----------------------------------------------------------------------*/
4998 IF(l_move.jobTxn = WIP_CONSTANTS.YES) THEN
4999
5000 INSERT INTO wip_cost_txn_interface
5001 (transaction_id,
5002 last_update_date,
5003 last_updated_by,
5004 last_updated_by_name,
5005 creation_date,
5006 created_by,
5007 created_by_name,
5008 last_update_login,
5009 request_id,
5010 program_application_id,
5011 program_id,
5012 program_update_date,
5013 group_id,
5014 source_code,
5015 source_line_id,
5016 process_phase,
5017 process_status,
5018 transaction_type,
5019 organization_id,
5020 organization_code,
5021 wip_entity_id,
5022 entity_type,
5023 primary_item_id,
5024 line_id,
5025 line_code,
5026 transaction_date,
5027 acct_period_id,
5028 operation_seq_num,
5029 department_id,
5030 department_code,
5031 employee_id,
5032 resource_seq_num,
5033 resource_id,
5034 resource_code,
5035 phantom_flag,
5036 usage_rate_or_amount,
5037 basis_type,
5038 autocharge_type,
5039 standard_rate_flag,
5040 transaction_quantity,
5041 transaction_uom,
5042 primary_quantity,
5043 primary_uom,
5044 actual_resource_rate,
5045 activity_id,
5046 activity_name,
5047 reason_id,
5048 reason_name,
5049 reference,
5050 move_transaction_id,
5051 po_header_id,
5052 po_line_id,
5053 repetitive_schedule_id,
5054 project_id,
5055 task_id
5056 )
5057 SELECT NULL, -- transaction_id
5058 SYSDATE, -- last_update_date
5059 MAX(wmti.last_updated_by), -- last_updated_by --Fix for bug 5195072
5060 MAX(wmti.last_updated_by_name), -- last_updated_by_name --Fix for bug 5195072
5061 SYSDATE, -- creation_date
5062 MAX(wmti.created_by), -- created_by --Fix for bug 5195072
5063 MAX(wmti.created_by_name), -- created_by_name --Fix for bug 5195072
5064 DECODE(p_gib.login_id,-1,NULL,p_gib.login_id),
5065 DECODE(p_gib.request_id,-1,NULL,p_gib.request_id),
5066 DECODE(p_gib.application_id,-1,NULL,p_gib.application_id),
5067 DECODE(p_gib.program_id,-1,NULL,p_gib.program_id),
5068 DECODE(p_gib.request_id,-1,NULL,SYSDATE), -- program_update_date
5069 p_gib.group_id,
5070 MAX(wmti.source_code), -- source_code
5071 MAX(wmti.source_line_id), -- source_line_id
5072 WIP_CONSTANTS.RES_PROC, -- process_phase
5073 WIP_CONSTANTS.PENDING, -- process_status
5074 WIP_CONSTANTS.OVHD_TXN, -- transaction_type
5075 wmti.organization_id,
5076 MAX(wmti.organization_code),
5077 wmti.wip_entity_id,
5078 MAX(entity_type),
5079 MAX(wmti.primary_item_id),
5080 MAX(wmti.line_id),
5081 MAX(wmti.line_code),
5082 MAX(wmti.transaction_date),
5083 MAX(wmti.acct_period_id),
5084 wop.operation_seq_num,
5085 NVL(wor.department_id, wop.department_id) ,
5086 MAX(bd.department_code),
5087 NULL, -- employee_id
5088 NULL, -- resource_seq_num
5089 NULL, -- resource_id
5090 NULL, -- resource_code
5091 MAX(wor.phantom_flag),
5092 NULL, -- usage_rate_or_amount
5093 WIP_CONSTANTS.PER_LOT, -- basis_type
5094 WIP_CONSTANTS.WIP_MOVE, -- autocharge_type
5095 NULL, -- standard_rate_flag
5096 DECODE(SIGN(MAX(wop.quantity_completed) +
5097 /* Fixed bug 3740010 change from "NVL(SUM(wmti.primary_quantity"
5098 * to "NVL(MAX(wmti.primary_quantity" because there may be
5099 * multiple resources per operation.
5100 */
5101 NVL(MAX(wmti.primary_quantity *
5102 DECODE(SIGN(wmti.to_operation_seq_num -
5103 wmti.fm_operation_seq_num),
5104 0,DECODE(SIGN(wmti.fm_intraoperation_step_type -
5105 WIP_CONSTANTS.RUN),
5106 0,DECODE(SIGN(wmti.to_intraoperation_step_type -
5107 WIP_CONSTANTS.RUN),1,1,-1),
5108 -1,DECODE(SIGN(wmti.to_intraoperation_step_type -
5109 WIP_CONSTANTS.RUN),1,1,-1),
5110 1,-1),
5111 1, 1,
5112 -1,-1)
5113 ),0)), -- transaction_quantity
5114 0, DECODE(SIGN(MAX(wop.quantity_completed)),1,-1,0),
5115 1, DECODE(SIGN(MAX(wop.quantity_completed)),1,0,1),
5116 -1, DECODE(SIGN(MAX(wop.quantity_completed)),1,-1,0)),
5117 MAX(wmti.primary_uom), -- transaction_uom
5118 DECODE(SIGN(MAX(wop.quantity_completed) +
5119 /* Fixed bug 3740010 change from "NVL(SUM(wmti.primary_quantity"
5120 * to "NVL(MAX(wmti.primary_quantity" because there may be
5121 * multiple resources per operation.
5122 */
5123 NVL(MAX(wmti.primary_quantity *
5124 DECODE(SIGN(wmti.to_operation_seq_num -
5125 wmti.fm_operation_seq_num),
5126 0,DECODE(SIGN(wmti.fm_intraoperation_step_type -
5127 WIP_CONSTANTS.RUN),
5128 0,DECODE(SIGN(wmti.to_intraoperation_step_type -
5129 WIP_CONSTANTS.RUN),1,1,-1),
5130 -1,DECODE(SIGN(wmti.to_intraoperation_step_type -
5131 WIP_CONSTANTS.RUN),1,1,-1),
5132 1,-1),
5133 1, 1,
5134 -1,-1)
5135 ),0)), -- primary_quantity
5136 0, DECODE(SIGN(MAX(wop.quantity_completed)),1,-1,0),
5137 1, DECODE(SIGN(MAX(wop.quantity_completed)),1,0,1),
5138 -1, DECODE(SIGN(MAX(wop.quantity_completed)),1,-1,0)),
5139 MAX(wmti.primary_uom), -- primary_uom
5140 NULL, -- actual_resource_rate
5141 NULL, -- activity_id
5142 NULL, -- activity_name
5143 NULL, -- reason_id
5144 NULL, -- reason_name
5145 NULL, -- reference
5146 MAX(wmti.transaction_id), -- move_transaction_id
5147 NULL, -- po_header_id
5148 NULL, -- po_line_id
5149 NULL, -- repetitive_schedule_id
5150 MAX(wdj.project_id),
5151 MAX(wdj.task_id)
5152 FROM bom_departments bd,
5153 wip_operations wop,
5154 wip_operation_resources wor,
5155 wip_discrete_jobs wdj,
5156 wip_move_txn_interface wmti
5157 WHERE wmti.group_id = p_gib.group_id
5158 AND TRUNC(wmti.transaction_date) = TRUNC(p_gib.txn_date)
5159 AND wmti.process_phase = WIP_CONSTANTS.MOVE_PROC
5160 AND wmti.process_status = WIP_CONSTANTS.RUNNING
5161 AND (wmti.entity_type = WIP_CONSTANTS.DISCRETE
5162 OR wmti.entity_type = WIP_CONSTANTS.LOTBASED) /* WSM */
5163 AND wdj.wip_entity_id = wmti.wip_entity_id
5164 AND wdj.organization_id = wmti.organization_id
5165 AND wop.organization_id = wmti.organization_id
5166 AND wop.wip_entity_id = wmti.wip_entity_id
5167 AND wop.organization_id = bd.organization_id
5168 AND NVL(wor.department_id, wop.department_id) = bd.department_id
5169 AND wop.organization_id = wor.organization_id(+)
5170 AND wop.wip_entity_id = wor.wip_entity_id(+)
5171 AND wop.operation_seq_num = wor.operation_seq_num(+)
5172 /* added for OSFM jump enhancement 2541431 */
5173 AND NVL(wop.skip_flag, WIP_CONSTANTS.NO) <> WIP_CONSTANTS.YES
5174 /*bug 3930251 -> insert into WCTI only if there are records in CDO)*/
5175 AND EXISTS
5176 ( SELECT 1 FROM cst_department_overheads cdo
5177 WHERE cdo.organization_id = bd.organization_id
5178 AND cdo.department_id = bd.department_id
5179 )
5180 AND (
5181 (wop.operation_seq_num >= wmti.fm_operation_seq_num
5182 + DECODE(SIGN(wmti.fm_intraoperation_step_type -
5183 WIP_CONSTANTS.RUN),1,1,0)
5184 AND wop.operation_seq_num < wmti.to_operation_seq_num
5185 + DECODE(SIGN(wmti.to_intraoperation_step_type -
5186 WIP_CONSTANTS.RUN),1,1,0)
5187 AND (wmti.to_operation_seq_num > wmti.fm_operation_seq_num
5188 OR (wmti.to_operation_seq_num = wmti.fm_operation_seq_num
5189 AND wmti.fm_intraoperation_step_type <= WIP_CONSTANTS.RUN
5190 AND wmti.to_intraoperation_step_type > WIP_CONSTANTS.RUN))
5191 AND (wop.count_point_type < WIP_CONSTANTS.NO_MANUAL
5192 OR wop.operation_seq_num = wmti.fm_operation_seq_num
5193 OR (wop.operation_seq_num = wmti.to_operation_seq_num
5194 AND wmti.to_intraoperation_step_type >
5195 WIP_CONSTANTS.RUN)))
5196 OR
5197 (wop.operation_seq_num < wmti.fm_operation_seq_num
5198 + DECODE(SIGN(wmti.fm_intraoperation_step_type -
5199 WIP_CONSTANTS.RUN),1,1,0)
5200 AND wop.operation_seq_num >= wmti.to_operation_seq_num
5201 + DECODE(SIGN(wmti.to_intraoperation_step_type -
5202 WIP_CONSTANTS.RUN),1,1,0)
5203 AND (wmti.fm_operation_seq_num > wmti.to_operation_seq_num
5204 OR (wmti.fm_operation_seq_num = wmti.to_operation_seq_num
5205 AND wmti.to_intraoperation_step_type <= WIP_CONSTANTS.RUN
5206 AND wmti.fm_intraoperation_step_type > WIP_CONSTANTS.RUN))
5207 AND (wop.count_point_type < WIP_CONSTANTS.NO_MANUAL
5208 OR wop.operation_seq_num = wmti.to_operation_seq_num
5209 OR (wop.operation_seq_num = wmti.fm_operation_seq_num
5210 AND wmti.fm_intraoperation_step_type >
5211 WIP_CONSTANTS.RUN))))
5212 GROUP BY wmti.organization_id,
5213 wmti.wip_entity_id,
5214 wop.operation_seq_num,
5215 wor.phantom_item_id, --Bug 5213164:Added to take care of multiple phantoms
5216 wor.phantom_op_seq_num, --Bug 5213164
5217 wor.department_id, /*fixed bug 2834503*/
5218 wop.department_id
5219 HAVING 0 <>
5220 DECODE(SIGN(MAX(wop.quantity_completed) +
5221 /* Fixed bug 3740010 change from "NVL(SUM(wmti.primary_quantity"
5222 * to "NVL(MAX(wmti.primary_quantity" because there may be
5223 * multiple resources per operation.
5224 */
5225 NVL(MAX(wmti.primary_quantity *
5226 DECODE(SIGN(wmti.to_operation_seq_num -
5227 wmti.fm_operation_seq_num),
5228 0,DECODE(SIGN(wmti.fm_intraoperation_step_type -
5229 WIP_CONSTANTS.RUN),
5230 0,DECODE(SIGN(wmti.to_intraoperation_step_type -
5231 WIP_CONSTANTS.RUN),1,1,-1),
5232 -1,DECODE(SIGN(wmti.to_intraoperation_step_type -
5233 WIP_CONSTANTS.RUN),1,1,-1),
5234 1,-1),
5235 1, 1,
5236 -1,-1)
5237 ),0)), -- NVL
5238 0, DECODE(SIGN(MAX(wop.quantity_completed)),1,-1,0),
5239 1, DECODE(sign(MAX(wop.quantity_completed)),1,0,1),
5240 -1, DECODE(sign(MAX(wop.quantity_completed)),1,-1,0));
5241
5242 -- IF debug message level = 2, write statement below to log file
5243 IF (l_logLevel <= wip_constants.full_logging) THEN
5244 fnd_message.set_name('WIP', 'WIP_INSERTED_ROWS');
5245 fnd_message.set_token('ENTITY1', SQL%ROWCOUNT);
5246 fnd_message.set_token('ENTITY2', 'WIP_COST_TXN_INTERFACE');
5247 l_msg := fnd_message.get;
5248 wip_logger.log(p_msg => l_msg,
5249 x_returnStatus => l_returnStatus);
5250 END IF;
5251
5252 END IF; -- Per order basis type for discrete jobs
5253
5254 -- Per order basis type for repetitive
5255 IF(l_move.scheTxn = WIP_CONSTANTS.YES) THEN
5256
5257 INSERT INTO wip_cost_txn_interface
5258 (transaction_id,
5259 last_update_date,
5260 last_updated_by,
5261 last_updated_by_name,
5262 creation_date,
5263 created_by,
5264 created_by_name,
5265 last_update_login,
5266 request_id,
5267 program_application_id,
5268 program_id,
5269 program_update_date,
5270 group_id,
5271 source_code,
5272 source_line_id,
5273 process_phase,
5274 process_status,
5275 transaction_type,
5276 organization_id,
5277 organization_code,
5278 wip_entity_id,
5279 entity_type,
5280 primary_item_id,
5281 line_id,
5282 line_code,
5283 transaction_date,
5284 acct_period_id,
5285 operation_seq_num,
5286 department_id,
5287 department_code,
5288 employee_id,
5289 resource_seq_num,
5290 resource_id,
5291 resource_code,
5292 phantom_flag,
5293 usage_rate_or_amount,
5294 basis_type,
5295 autocharge_type,
5296 standard_rate_flag,
5297 transaction_quantity,
5298 transaction_uom,
5299 primary_quantity,
5300 primary_uom,
5301 actual_resource_rate,
5302 activity_id,
5303 activity_name,
5304 reason_id,
5305 reason_name,
5306 reference,
5307 move_transaction_id,
5308 po_header_id,
5309 po_line_id,
5310 repetitive_schedule_id
5311 )
5312 SELECT NULL, -- transaction_id
5313 SYSDATE, -- last_update_date
5314 MAX(wmti.last_updated_by), -- last_updated_by --Fix for bug 5195072
5315 MAX(wmti.last_updated_by_name), -- last_updated_by_name --Fix for bug 5195072
5316 SYSDATE, -- creation_date
5317 MAX(wmti.created_by), -- created_by --Fix for bug 5195072
5318 MAX(wmti.created_by_name), -- created_by_name --Fix for bug 5195072
5319 DECODE(p_gib.login_id,-1,NULL,p_gib.login_id),
5320 DECODE(p_gib.request_id,-1,NULL,p_gib.request_id),
5321 DECODE(p_gib.application_id,-1,NULL,p_gib.application_id),
5322 DECODE(p_gib.program_id,-1,NULL,p_gib.program_id),
5323 DECODE(p_gib.request_id,-1,NULL,SYSDATE), -- program_update_date
5324 p_gib.group_id,
5325 MAX(wmti.source_code), -- source_code
5326 -- Fixed bug 2465148
5327 MAX(wmti.source_line_id), -- source_line_id
5328 WIP_CONSTANTS.RES_PROC, -- process_phase
5329 WIP_CONSTANTS.PENDING, -- process_status
5330 WIP_CONSTANTS.OVHD_TXN, -- transaction_type
5331 wmti.organization_id,
5332 MAX(wmti.organization_code),
5333 wmti.wip_entity_id,
5334 MAX(entity_type),
5335 MAX(wmti.primary_item_id),
5336 wmti.line_id,
5337 MAX(wmti.line_code),
5338 MAX(wmti.transaction_date),
5339 MAX(wmti.acct_period_id),
5340 wor.operation_seq_num,
5341 NVL(wor.department_id, wop.department_id),
5342 MAX(bd.department_code),
5343 NULL, -- employee_id
5344 NULL, -- resource_seq_num
5345 NULL, -- resource_id
5346 NULL, -- resource_code
5347 MAX(wor.phantom_flag),
5348 NULL, -- usage_rate_or_amount
5349 WIP_CONSTANTS.PER_LOT, -- basis_type
5350 WIP_CONSTANTS.WIP_MOVE, -- autocharge_type
5351 NULL, -- standard_rate_flag
5352 1, -- transaction_quantity
5353 MAX(wmti.primary_uom), -- transaction_uom
5354 1, -- primary_quantity
5355 MAX(wmti.primary_uom), -- primary_uom
5356 NULL, -- actual_resource_rate
5357 NULL, -- activity_id
5358 NULL, -- activity_name
5359 NULL, -- reason_id
5360 NULL, -- reason_name
5361 -- Fixed bug 2506653
5362 MAX(wmti.reference), -- reference
5363 MAX(wmti.transaction_id), -- move_transaction_id
5364 NULL, -- po_header_id
5365 NULL, -- po_line_id
5366 wma.repetitive_schedule_id
5367 FROM bom_departments bd,
5368 wip_move_txn_allocations wma,
5369 wip_operations wop,
5370 wip_move_txn_interface wmti,
5371 wip_operation_resources wor
5372 WHERE wmti.group_id = p_gib.group_id
5373 AND TRUNC(wmti.transaction_date) = TRUNC(p_gib.txn_date)
5374 AND wmti.process_phase = WIP_CONSTANTS.MOVE_PROC
5375 AND wmti.process_status = WIP_CONSTANTS.RUNNING
5376 AND wmti.entity_type = WIP_CONSTANTS.REPETITIVE
5377 AND wop.organization_id = wmti.organization_id
5378 AND wop.wip_entity_id = wmti.wip_entity_id
5379 AND wop.repetitive_schedule_id = wma.repetitive_schedule_id
5380 AND wmti.organization_id = wma.organization_id
5381 AND wmti.transaction_id = wma.transaction_id
5382 AND wop.organization_id = bd.organization_id
5383 AND NVL(wor.department_id, wop.department_id) = bd.department_id
5384 AND wor.organization_id = wop.organization_id
5385 AND wor.wip_entity_id = wop.wip_entity_id
5386 AND wor.operation_seq_num = wop.operation_seq_num
5387 AND wor.repetitive_schedule_id = wop.repetitive_schedule_id
5388 AND (
5389 (wop.operation_seq_num >= wmti.fm_operation_seq_num
5390 + DECODE(SIGN(wmti.fm_intraoperation_step_type -
5391 WIP_CONSTANTS.RUN),1,1,0)
5392 AND wop.operation_seq_num < wmti.to_operation_seq_num
5393 + DECODE(SIGN(wmti.to_intraoperation_step_type -
5394 WIP_CONSTANTS.RUN),1,1,0)
5395 AND (wmti.to_operation_seq_num > wmti.fm_operation_seq_num
5396 OR (wmti.to_operation_seq_num = wmti.fm_operation_seq_num
5397 AND wmti.fm_intraoperation_step_type <= WIP_CONSTANTS.RUN
5398 AND wmti.to_intraoperation_step_type > WIP_CONSTANTS.RUN))
5399 AND (wop.count_point_type < WIP_CONSTANTS.NO_MANUAL
5400 OR wop.operation_seq_num = wmti.fm_operation_seq_num
5401 OR (wop.operation_seq_num = wmti.to_operation_seq_num
5402 AND wmti.to_intraoperation_step_type >
5403 WIP_CONSTANTS.RUN)))
5404 OR
5405 (wop.operation_seq_num < wmti.fm_operation_seq_num
5406 + DECODE(SIGN(wmti.fm_intraoperation_step_type -
5407 WIP_CONSTANTS.RUN),1,1,0)
5408 AND wop.operation_seq_num >= wmti.to_operation_seq_num
5409 + DECODE(SIGN(wmti.to_intraoperation_step_type -
5410 WIP_CONSTANTS.RUN),1,1,0)
5411 AND (wmti.fm_operation_seq_num > wmti.to_operation_seq_num
5412 OR (wmti.fm_operation_seq_num = wmti.to_operation_seq_num
5413 AND wmti.to_intraoperation_step_type <= WIP_CONSTANTS.RUN
5414 AND wmti.fm_intraoperation_step_type > WIP_CONSTANTS.RUN))
5415 AND (wop.count_point_type < WIP_CONSTANTS.NO_MANUAL
5416 OR wop.operation_seq_num = wmti.to_operation_seq_num
5417 OR (wop.operation_seq_num = wmti.fm_operation_seq_num
5418 AND wmti.fm_intraoperation_step_type >
5419 WIP_CONSTANTS.RUN))))
5420 GROUP BY wmti.organization_id,
5421 wmti.wip_entity_id,
5422 wmti.line_id,
5423 wma.repetitive_schedule_id,
5424 wor.operation_seq_num,
5425 wor.department_id, /*fixed bug 2834503*/
5426 wop.department_id,
5427 wor.phantom_item_id,
5428 wor.phantom_op_seq_num
5429 HAVING 0 <>
5430 DECODE(SIGN(MAX(wop.quantity_completed) +
5431 NVL(SUM(wma.primary_quantity *
5432 DECODE(SIGN(wmti.to_operation_seq_num -
5433 wmti.fm_operation_seq_num),
5434 0,DECODE(SIGN(wmti.fm_intraoperation_step_type -
5435 WIP_CONSTANTS.RUN),
5436 0,DECODE(SIGN(wmti.to_intraoperation_step_type -
5437 WIP_CONSTANTS.RUN),1,1,-1),
5438 -1,DECODE(SIGN(wmti.to_intraoperation_step_type -
5439 WIP_CONSTANTS.RUN),1,1,-1),
5440 1,-1),
5441 1, 1,
5442 -1,-1)
5443 ),0)),
5444 0, DECODE(SIGN(MAX(wop.quantity_completed)),1,-1,0),
5445 1, DECODE(sign(MAX(wop.quantity_completed)),1,0,1),
5446 -1, DECODE(sign(MAX(wop.quantity_completed)),1,-1,0));
5447
5448 -- IF debug message level = 2, write statement below to log file
5449 IF (l_logLevel <= wip_constants.full_logging) THEN
5450 fnd_message.set_name('WIP', 'WIP_INSERTED_ROWS');
5451 fnd_message.set_token('ENTITY1', SQL%ROWCOUNT);
5452 fnd_message.set_token('ENTITY2', 'WIP_COST_TXN_INTERFACE');
5453 l_msg := fnd_message.get;
5454 wip_logger.log(p_msg => l_msg,
5455 x_returnStatus => l_returnStatus);
5456 END IF;
5457
5458 END IF; -- Per order basis type for repetitive
5459
5460
5461 /*------------------------------------------------------------+
5462 | Generate transaction_id for WIP_TXN_ALLOCATIONS |
5463 +------------------------------------------------------------*/
5464 UPDATE wip_cost_txn_interface
5465 SET transaction_id = wip_transactions_s.nextval
5466 WHERE group_id = p_gib.group_id
5467 AND TRUNC(transaction_date) = TRUNC(p_gib.txn_date)
5468 AND transaction_type = WIP_CONSTANTS.OVHD_TXN;
5469
5470 -- IF debug message level = 2, write statement below to log file
5471 IF (l_logLevel <= wip_constants.full_logging) THEN
5472 fnd_message.set_name('WIP', 'WIP_UPDATED_ROWS');
5473 fnd_message.set_token('ENTITY1', SQL%ROWCOUNT);
5474 fnd_message.set_token('ENTITY2', 'WIP_COST_TXN_INTERFACE');
5475 l_msg := fnd_message.get;
5476 wip_logger.log(p_msg => l_msg,
5477 x_returnStatus => l_returnStatus);
5478 END IF;
5479
5480 -- For repetitive
5481 IF(l_move.scheTxn = WIP_CONSTANTS.YES) THEN
5482
5483 /*------------------------------------------------------------+
5484 | Insert into cost allocations for repetitive schedules |
5485 | per lot
5486 +------------------------------------------------------------*/
5487
5488 /*------------------------------------------------------------+
5489 | Columns to insert into WIP_TXN_ALLOCATIONS |
5490 | |
5491 | transaction_id, |
5492 | repetitive_schedule_id, organization_id, |
5493 | last_update_date, last_updated_by, creation_date, |
5494 | created_by, last_update_login, request_id, |
5495 | program_application_id, program_id, program_update_date, |
5496 | transaction_quantity, |
5497 | primary_quantity, |
5498 | |
5499 +------------------------------------------------------------*/
5500 INSERT INTO wip_txn_allocations
5501 (transaction_id,
5502 repetitive_schedule_id,
5503 organization_id,
5504 last_update_date,
5505 last_updated_by,
5506 creation_date,
5507 created_by,
5508 last_update_login,
5509 request_id,
5510 program_application_id,
5511 program_id,
5512 program_update_date,
5513 transaction_quantity,
5514 primary_quantity
5515 )
5516 SELECT wci.transaction_id,
5517 wma.repetitive_schedule_id,
5518 MAX(wmti.organization_id),
5519 SYSDATE, -- last_update_date
5520 MAX(wmti.last_updated_by), -- last_updated_by --Fix for bug 5195072
5521 SYSDATE, -- creation_date
5522 MAX(wmti.created_by), -- created_by --Fix for bug 5195072
5523 DECODE(p_gib.login_id,-1,NULL,p_gib.login_id),
5524 DECODE(p_gib.request_id,-1,NULL,p_gib.request_id),
5525 DECODE(p_gib.application_id,-1,NULL,p_gib.application_id),
5526 DECODE(p_gib.program_id,-1,NULL,p_gib.program_id),
5527 DECODE(p_gib.request_id,-1,NULL,SYSDATE), -- program_update_date
5528 DECODE(SIGN(MAX(wop.quantity_completed) +
5529 NVL(SUM(wma.primary_quantity *
5530 DECODE(SIGN(wmti.to_operation_seq_num -
5531 wmti.fm_operation_seq_num),
5532 0,DECODE(SIGN(wmti.fm_intraoperation_step_type -
5533 WIP_CONSTANTS.RUN),
5534 0,DECODE(SIGN(wmti.to_intraoperation_step_type -
5535 WIP_CONSTANTS.RUN),1,1,-1),
5536 -1,DECODE(SIGN(wmti.to_intraoperation_step_type -
5537 WIP_CONSTANTS.RUN),1,1,-1),
5538 1,-1),
5539 1, 1,
5540 -1,-1)
5541 ),0)), -- transaction_quantity
5542 0, DECODE(SIGN(MAX(wop.quantity_completed)),1,-1,0),
5543 1, DECODE(SIGN(MAX(wop.quantity_completed)),1,0,1),
5544 -1, DECODE(SIGN(MAX(wop.quantity_completed)),1,-1,0)),
5545 DECODE(SIGN(MAX(wop.quantity_completed) +
5546 NVL(SUM(wma.primary_quantity *
5547 DECODE(SIGN(wmti.to_operation_seq_num -
5548 wmti.fm_operation_seq_num),
5549 0,DECODE(SIGN(wmti.fm_intraoperation_step_type -
5550 WIP_CONSTANTS.RUN),
5551 0,DECODE(SIGN(wmti.to_intraoperation_step_type -
5552 WIP_CONSTANTS.RUN),1,1,-1),
5553 -1,DECODE(SIGN(wmti.to_intraoperation_step_type -
5554 WIP_CONSTANTS.RUN),1,1,-1),
5555 1,-1),
5556 1, 1,
5557 -1,-1)
5558 ),0)), -- primary_quantity
5559 0, DECODE(SIGN(MAX(wop.quantity_completed)),1,-1,0),
5560 1, DECODE(SIGN(MAX(wop.quantity_completed)),1,0,1),
5561 -1, DECODE(SIGN(MAX(wop.quantity_completed)),1,-1,0))
5562 FROM wip_move_txn_allocations wma,
5563 wip_operations wop,
5564 wip_cost_txn_interface wci,
5565 wip_move_txn_interface wmti
5566 WHERE wmti.group_id = p_gib.group_id
5567 AND TRUNC(wmti.transaction_date) = TRUNC(p_gib.txn_date)
5568 AND wmti.process_phase = WIP_CONSTANTS.MOVE_PROC
5569 AND wmti.process_status = WIP_CONSTANTS.RUNNING
5570 AND wmti.entity_type = WIP_CONSTANTS.REPETITIVE
5571 AND wmti.group_id = wci.group_id
5572 AND wci.organization_id = wmti.organization_id
5573 AND wci.wip_entity_id = wmti.wip_entity_id
5574 AND wci.operation_seq_num = wop.operation_seq_num
5575 AND wci.basis_type = WIP_CONSTANTS.PER_LOT
5576 AND wci.transaction_type = WIP_CONSTANTS.OVHD_TXN
5577 AND wop.organization_id = wmti.organization_id
5578 AND wop.wip_entity_id = wmti.wip_entity_id
5579 AND wop.repetitive_schedule_id = wma.repetitive_schedule_id
5580 AND wmti.organization_id = wma.organization_id
5581 AND wmti.transaction_id = wma.transaction_id
5582 AND wci.repetitive_schedule_id = wma.repetitive_schedule_id
5583 GROUP BY wci.transaction_id,
5584 wma.repetitive_schedule_id;
5585
5586 -- IF debug message level = 2, write statement below to log file
5587 IF (l_logLevel <= wip_constants.full_logging) THEN
5588 fnd_message.set_name('WIP', 'WIP_INSERTED_ROWS');
5589 fnd_message.set_token('ENTITY1', SQL%ROWCOUNT);
5590 fnd_message.set_token('ENTITY2', 'WIP_TXN_ALLOCATIONS');
5591 l_msg := fnd_message.get;
5592 wip_logger.log(p_msg => l_msg,
5593 x_returnStatus => l_returnStatus);
5594 END IF;
5595
5596 END IF; -- For repetitive
5597
5598 x_returnStatus := fnd_api.g_ret_sts_success;
5599
5600 -- write to the log file
5601 IF (l_logLevel <= wip_constants.trace_logging) THEN
5602 wip_logger.exitPoint(p_procName => 'wip_movProc_priv.insert_dept_overhead',
5603 p_procReturnStatus => x_returnStatus,
5604 p_msg => 'procedure complete',
5605 x_returnStatus => l_returnStatus);
5606 END IF;
5607
5608 EXCEPTION
5609 WHEN others THEN
5610 x_returnStatus := fnd_api.g_ret_sts_unexp_error;
5611 l_errMsg := 'unexpected error: ' || SQLERRM || 'SQLCODE = ' || SQLCODE;
5612
5613 IF (l_logLevel <= wip_constants.trace_logging) THEN
5614 wip_logger.exitPoint(p_procName=>'wip_movProc_priv.insert_dept_overhead',
5615 p_procReturnStatus => x_returnStatus,
5616 p_msg => l_errMsg,
5617 x_returnStatus => l_returnStatus);
5618 END IF;
5619 fnd_message.set_name('FND', 'FND_GENERIC_MESSAGE');
5620 fnd_message.set_token('MESSAGE', l_errMsg);
5621 fnd_msg_pub.add;
5622 END insert_dept_overhead;
5623
5624 /*****************************************************************************
5625 * This procedure is equivalent to witpsrt_release_cost_txns in wiltps3.ppc
5626 * This procedure is used to set group_id in wip_cost_txn_interface to be NULL
5627 * so that Costing Manager will pick up the records.
5628 ****************************************************************************/
5629 PROCEDURE release_cost_txn(p_gib IN group_rec_t,
5630 x_returnStatus OUT NOCOPY VARCHAR2) IS
5631
5632 l_params wip_logger.param_tbl_t;
5633 l_returnStatus VARCHAR(1);
5634 l_msg VARCHAR(240);
5635 l_errMsg VARCHAR2(240);
5636 l_logLevel NUMBER := fnd_log.g_current_runtime_level;
5637
5638 BEGIN
5639 -- write parameter value to log file
5640 IF (l_logLevel <= wip_constants.trace_logging) THEN
5641 l_params(1).paramName := 'p_group_id';
5642 l_params(1).paramValue := p_gib.group_id;
5643 l_params(2).paramName := 'p_txn_date';
5644 l_params(2).paramValue := p_gib.txn_date;
5645 wip_logger.entryPoint(p_procName =>'wip_movProc_priv.release_cost_txn',
5646 p_params => l_params,
5647 x_returnStatus => l_returnStatus);
5648 END IF;
5649
5650 UPDATE wip_cost_txn_interface
5651 SET group_id = NULL
5652 WHERE group_id = p_gib.group_id
5653 AND TRUNC(transaction_date) = TRUNC(p_gib.txn_date);
5654
5655 -- IF debug message level = 2, write statement below to log file
5656 IF (l_logLevel <= wip_constants.full_logging) THEN
5657 fnd_message.set_name('WIP', 'WIP_UPDATED_ROWS');
5658 fnd_message.set_token('ENTITY1', SQL%ROWCOUNT);
5659 fnd_message.set_token('ENTITY2', 'WIP_COST_TXN_INTERFACE');
5660 l_msg := fnd_message.get;
5661 wip_logger.log(p_msg => l_msg,
5662 x_returnStatus => l_returnStatus);
5663 END IF;
5664
5665 x_returnStatus := fnd_api.g_ret_sts_success;
5666
5667 -- write to the log file
5668 IF (l_logLevel <= wip_constants.trace_logging) THEN
5669 wip_logger.exitPoint(p_procName => 'wip_movProc_priv.release_cost_txn',
5670 p_procReturnStatus => x_returnStatus,
5671 p_msg => 'procedure complete',
5672 x_returnStatus => l_returnStatus);
5673 END IF;
5674
5675 EXCEPTION
5676 WHEN others THEN
5677 x_returnStatus := fnd_api.g_ret_sts_unexp_error;
5678 l_errMsg := 'unexpected error: ' || SQLERRM || 'SQLCODE = ' || SQLCODE;
5679
5680 IF (l_logLevel <= wip_constants.trace_logging) THEN
5681 wip_logger.exitPoint(p_procName=>'wip_movProc_priv.release_cost_txn',
5682 p_procReturnStatus => x_returnStatus,
5683 p_msg => l_errMsg,
5684 x_returnStatus => l_returnStatus);
5685 END IF;
5686 fnd_message.set_name('FND', 'FND_GENERIC_MESSAGE');
5687 fnd_message.set_token('MESSAGE', l_errMsg);
5688 fnd_msg_pub.add;
5689 END release_cost_txn;
5690
5691 /*****************************************************************************
5692 * This procedure is equivalent to witpspr_po_req in wiltps4.ppc
5693 * This procedure is used to insert purchase order requisition into
5694 * PO_REQUISITIONS_INTERFACE_ALL
5695 * NOTES:
5696 * IF the purchase item lead time falls outside of BOM_CALENDAR_DATES
5697 * THEN no PO req will be created
5698 ****************************************************************************/
5699 PROCEDURE insert_po_req(p_gib IN group_rec_t,
5700 x_returnStatus OUT NOCOPY VARCHAR2) IS
5701
5702 CURSOR c_additional_reqs(p_group_id NUMBER) IS
5703 SELECT distinct wmti.wip_entity_id wip_id,
5704 wmti.repetitive_schedule_id rep_sched_id,
5705 wmti.organization_id org_id,
5706 wo.operation_seq_num op_seq_num,
5707 wmti.overcompletion_primary_qty oc_qty
5708 FROM wip_move_txn_interface wmti,
5709 wip_operations wo,
5710 wip_operation_resources wor,
5711 wip_discrete_jobs wdj
5712 WHERE wmti.group_id = p_group_id
5713 AND wmti.process_phase = WIP_CONSTANTS.MOVE_PROC
5714 AND wmti.process_status = WIP_CONSTANTS.RUNNING
5715 AND wmti.overcompletion_transaction_qty IS NOT NULL
5716 AND wdj.wip_entity_id = wmti.wip_entity_id
5717 AND wdj.organization_id = wmti.organization_id
5718 AND wdj.po_creation_time = WIP_CONSTANTS.AT_JOB_SCHEDULE_RELEASE
5719 AND wo.wip_entity_id = wmti.wip_entity_id
5720 AND wo.organization_id = wmti.organization_id
5721 AND wo.operation_seq_num > wmti.fm_operation_seq_num
5722 AND wo.count_point_type <> WIP_CONSTANTS.NO_MANUAL
5723 AND wor.wip_entity_id = wo.wip_entity_id
5724 AND wor.organization_id = wo.organization_id
5725 AND wor.operation_seq_num = wo.operation_seq_num
5726 AND wor.autocharge_type in (WIP_CONSTANTS.PO_RECEIPT,
5727 WIP_CONSTANTS.PO_MOVE)
5728 AND wor.basis_type = WIP_CONSTANTS.PER_ITEM
5729
5730 UNION
5731
5732 SELECT distinct wmti.wip_entity_id wip_id,
5733 wmti.repetitive_schedule_id rep_sched_id,
5734 wmti.organization_id org_id,
5735 wo.operation_seq_num op_seq_num,
5736 wmti.overcompletion_primary_qty oc_qty
5737 FROM wip_move_txn_interface wmti,
5738 wip_operations wo,
5739 wip_operation_resources wor,
5740 wip_repetitive_schedules wrs
5741 WHERE wmti.group_id = p_group_id
5742 AND wmti.process_phase = WIP_CONSTANTS.MOVE_PROC
5743 AND wmti.process_status = WIP_CONSTANTS.RUNNING
5744 AND wmti.overcompletion_transaction_qty IS NOT NULL
5745 AND wrs.wip_entity_id = wmti.wip_entity_id
5746 AND wrs.repetitive_schedule_id = wmti.repetitive_schedule_id
5747 AND wrs.organization_id = wmti.organization_id
5748 AND wrs.po_creation_time = WIP_CONSTANTS.AT_JOB_SCHEDULE_RELEASE
5749 AND wo.wip_entity_id = wmti.wip_entity_id
5750 AND wo.repetitive_schedule_id = wmti.repetitive_schedule_id
5751 AND wo.organization_id = wmti.organization_id
5752 AND wo.operation_seq_num > wmti.fm_operation_seq_num
5753 AND wo.count_point_type <> WIP_CONSTANTS.NO_MANUAL
5754 AND wor.wip_entity_id = wo.wip_entity_id
5755 AND wor.organization_id = wo.organization_id
5756 AND wor.repetitive_schedule_id = wmti.repetitive_schedule_id
5757 AND wor.operation_seq_num = wo.operation_seq_num
5758 AND wor.autocharge_type in (WIP_CONSTANTS.PO_RECEIPT,
5759 WIP_CONSTANTS.PO_MOVE)
5760 AND wor.basis_type = WIP_CONSTANTS.PER_ITEM ;
5761
5762
5763 l_params wip_logger.param_tbl_t;
5764 l_returnStatus VARCHAR(1);
5765 l_msg VARCHAR(240);
5766 l_errMsg VARCHAR2(240);
5767 l_additional_reqs c_additional_reqs%ROWTYPE;
5768 l_move move_profile_rec_t;
5769 l_logLevel NUMBER := fnd_log.g_current_runtime_level;
5770
5771 BEGIN
5772 l_move := p_gib.move_profile;
5773
5774 -- write parameter value to log file
5775 IF (l_logLevel <= wip_constants.trace_logging) THEN
5776 l_params(1).paramName := 'p_group_id';
5777 l_params(1).paramValue := p_gib.group_id;
5778 l_params(2).paramName := 'p_txn_date';
5779 l_params(2).paramValue := p_gib.txn_date;
5780 l_params(3).paramName := 'org_id';
5781 l_params(3).paramValue := l_move.org_id;
5782 l_params(4).paramName := 'wip_id';
5783 l_params(4).paramValue := l_move.wip_id;
5784 l_params(5).paramName := 'fmOp';
5785 l_params(5).paramValue := l_move.fmOp;
5786 l_params(6).paramName := 'fmStep';
5787 l_params(6).paramValue := l_move.fmStep;
5788 l_params(7).paramName := 'toOp';
5789 l_params(7).paramValue := l_move.toOp;
5790 l_params(8).paramName := 'toStep';
5791 l_params(8).paramValue := l_move.toStep;
5792 l_params(9).paramName := 'scrapTxn';
5793 l_params(9).paramValue := l_move.scrapTxn;
5794 l_params(10).paramName := 'easyComplete';
5795 l_params(10).paramValue := l_move.easyComplete;
5796 l_params(11).paramName := 'easyReturn';
5797 l_params(11).paramValue := l_move.easyReturn;
5798 l_params(12).paramName := 'jobTxn';
5799 l_params(12).paramValue := l_move.jobTxn;
5800 l_params(13).paramName := 'scheTxn';
5801 l_params(13).paramValue := l_move.scheTxn;
5802 l_params(14).paramName := 'rsrcItem';
5803 l_params(14).paramValue := l_move.rsrcItem;
5804 l_params(15).paramName := 'rsrcLot';
5805 l_params(15).paramValue := l_move.rsrcLot;
5806 l_params(16).paramName := 'poReqItem';
5807 l_params(16).paramValue := l_move.poReqItem;
5808 l_params(17).paramName := 'poRegLot';
5809 l_params(17).paramValue := l_move.poReqLot;
5810
5811 wip_logger.entryPoint(p_procName =>'wip_movProc_priv.insert_po_req',
5812 p_params => l_params,
5813 x_returnStatus => l_returnStatus);
5814 END IF;
5815
5816 /*------------------------------------------------------------+
5817 | Insert into PO_REQUISITIONS_INTERFACE_ALL table for per item for jobs
5818 +------------------------------------------------------------*/
5819 IF(l_move.jobTxn = WIP_CONSTANTS.YES AND
5820 l_move.poReqItem = WIP_CONSTANTS.YES) THEN
5821
5822 -- Fixed bug 5144659. Insert into po_requisitions_interface_all instead of
5823 -- po_requisitions_interface as part of MOAC change.
5824 INSERT INTO po_requisitions_interface_all
5825 (last_update_date,
5826 last_updated_by,
5827 creation_date,
5828 created_by,
5829 last_update_login,
5830 request_id,
5831 program_application_id,
5832 program_id,
5833 program_update_date,
5834 org_id, /* Operating unit org */
5835 preparer_id,
5836 interface_source_code,
5837 authorization_status,
5838 source_type_code,
5839 destination_organization_id,
5840 destination_type_code,
5841 item_id,
5842 item_revision,
5843 uom_code,
5844 quantity,
5845 line_type_id,
5846 charge_account_id,
5847 deliver_to_location_id,
5848 deliver_to_requestor_id,
5849 wip_entity_id,
5850 wip_line_id,
5851 wip_operation_seq_num,
5852 wip_resource_seq_num,
5853 bom_resource_id,
5854 wip_repetitive_schedule_id,
5855 need_by_date,
5856 autosource_flag,
5857 group_code,
5858 suggested_buyer_id,
5859 project_id,
5860 task_id,
5861 project_accounting_context
5862 )
5863 SELECT /*bugfix 5345712 : performance fix. removed hint */
5864 SYSDATE, -- last_update_date
5865 wmti.last_updated_by, -- last_updated_by --Fix for bug 5195072
5866 SYSDATE, -- creation_date
5867 wmti.created_by, -- created_by --Fix for bug 5195072
5868 DECODE(p_gib.login_id,-1,NULL,p_gib.login_id),
5869 DECODE(p_gib.request_id,-1,NULL,p_gib.request_id),
5870 DECODE(p_gib.application_id,-1,NULL,p_gib.application_id),
5871 DECODE(p_gib.program_id,-1,NULL,p_gib.program_id),
5872 DECODE(p_gib.request_id,-1,NULL,SYSDATE), -- program_update_date
5873 to_number(hoi.org_information3), -- ou_org_id
5874 fu.employee_id, -- preparer_id
5875 'WIP', -- interface_source_code
5876 'APPROVED', -- authorization_status
5877 'VENDOR', -- source_type_code
5878 wor.organization_id, -- destination_organization_id
5879 'SHOP FLOOR', -- destination_type_code
5880 br.purchase_item_id, -- item_id
5881 DECODE(msi.revision_qty_control_code, -- item_revision
5882 1, NULL,
5883 2, DECODE(br.purchase_item_id,
5884 wdj.primary_item_id, wdj.bom_revision,
5885 BOM_revisions.GET_ITEM_REVISION_FN
5886 ('EXCLUDE_OPEN_HOLD', -- eco_status
5887 'ALL', -- examine_type
5888 br.ORGANIZATION_ID, -- org_id
5889 br.purchase_item_id, -- item_id
5890 wdj.scheduled_start_date -- rev_date
5891 ))), /* Fixed Bug# 1623063 */
5892 msi.primary_uom_code, -- uom_code
5893 DECODE(msi.outside_operation_uom_type, -- quantity
5894 'RESOURCE',ROUND(wor.usage_rate_or_amount*wmti.primary_quantity,
5895 WIP_CONSTANTS.INV_MAX_PRECISION),
5896 'ASSEMBLY',wmti.primary_quantity),
5897 3, -- line_type_id
5898 wdj.outside_processing_account, -- charge_account_id
5899 bd.location_id, -- deliver_to_location_id
5900 fu.employee_id, -- deliver_to_requestor_id
5901 wor.wip_entity_id,
5902 wmti.line_id,
5903 wor.operation_seq_num,
5904 wor.resource_seq_num,
5905 wor.resource_id,
5906 wor.repetitive_schedule_id,
5907 /* Bug 4398047 commented following portion of the sql
5908 DECODE(wmti.entity_type, -- Fix for 2374334
5909 WIP_CONSTANTS.LOTBASED, bcd1.calendar_date, */
5910 (bcd3.calendar_date +
5911 (DECODE(wo1.next_operation_seq_num,
5912 NULL, wo1.last_unit_completion_date,
5913 wo2.first_unit_start_date) -
5914 TRUNC(DECODE(wo1.next_operation_seq_num,
5915 NULL, wo1.last_unit_completion_date,
5916 wo2.first_unit_start_date)))), -- need_by_date /* Bug 4398047 removed one matching bracket for decode */
5917 'Y', -- autosource_flag
5918 NULL, -- group_code
5919 msi.buyer_id, -- suggested_buyer_id
5920 wdj.project_id,
5921 wdj.task_id,
5922 DECODE(wdj.project_id,NULL,NULL,'Y')-- project_accounting_context
5923 FROM /* bugfix 5129403: modified the order in the from clause */
5924 wip_move_txn_interface wmti,
5925 wip_operation_resources wor,
5926 bom_resources br,
5927 mtl_system_items msi,
5928 mtl_parameters mp,
5929 -- bom_calendar_dates bcd2, Bug 4398047 join to bcd2 not required
5930 bom_calendar_dates bcd4,
5931 -- bom_calendar_dates bcd1, Bug 4398047 join to bcd1 not required
5932 bom_calendar_dates bcd3,
5933 fnd_user fu,
5934 bom_departments bd,
5935 hr_organization_information hoi,
5936 wip_discrete_jobs wdj,
5937 wip_operations wo1,
5938 wip_operations wo2
5939 WHERE wmti.group_id = p_gib.group_id
5940 AND TRUNC(wmti.transaction_date) = TRUNC(p_gib.txn_date)
5941 AND wmti.process_phase = WIP_CONSTANTS.MOVE_PROC
5942 AND wmti.process_status = WIP_CONSTANTS.RUNNING
5943 AND (wmti.entity_type = WIP_CONSTANTS.DISCRETE
5944 OR wmti.entity_type = WIP_CONSTANTS.LOTBASED) /* WSM */
5945 AND (wmti.overcompletion_transaction_id IS NULL
5946 OR ( wmti.overcompletion_transaction_id IS NOT NULL
5947 AND wmti.overcompletion_transaction_qty IS NOT NULL))
5948 --Bugfix 6679124: Join to wor using wdj rather than wmti to get better execution plan.
5949 -- AND wmti.organization_id = wor.organization_id
5950 -- AND wmti.wip_entity_id = wor.wip_entity_id
5951 AND wdj.organization_id = wor.organization_id --6679124
5952 AND wdj.wip_entity_id = wor.wip_entity_id -- 6679124
5953 AND wmti.to_operation_seq_num = wor.operation_seq_num
5954 AND wmti.fm_operation_seq_num < wmti.to_operation_seq_num
5955 AND wmti.to_intraoperation_step_type = WIP_CONSTANTS.QUEUE
5956 AND wo1.organization_id = wmti.organization_id
5957 AND wo1.wip_entity_id = wmti.wip_entity_id
5958 AND wo1.operation_seq_num = wmti.to_operation_seq_num
5959 AND wo2.organization_id = wo1.organization_id
5960 AND wo2.wip_entity_id = wo1.wip_entity_id
5961 -- Fixed bug 2259661
5962 -- AND ((wor.autocharge_type = WIP_CONSTANTS.PO_RECEIPT
5963 -- AND wo2.operation_seq_num = wmti.to_operation_seq_num)
5964 -- OR (wor.autocharge_type = WIP_CONSTANTS.PO_MOVE
5965 AND ((wor.autocharge_type IN (WIP_CONSTANTS.PO_RECEIPT,
5966 WIP_CONSTANTS.PO_MOVE))
5967 AND ((wo1.next_operation_seq_num IS NOT NULL
5968 AND wo1.next_operation_seq_num = wo2.operation_seq_num)
5969 OR (wo1.next_operation_seq_num IS NULL
5970 AND wo2.operation_seq_num = wmti.to_operation_seq_num)))
5971 AND wdj.organization_id = wmti.organization_id
5972 AND wdj.wip_entity_id = wmti.wip_entity_id
5973 AND (wdj.po_creation_time = WIP_CONSTANTS.AT_OPERATION
5974 OR (wo1.count_point_type = WIP_CONSTANTS.NO_MANUAL
5975 AND wdj.po_creation_time <> WIP_CONSTANTS.MANUAL_CREATION))
5976 AND wor.basis_type = WIP_CONSTANTS.PER_ITEM
5977 AND wor.organization_id = br.organization_id
5978 AND wor.resource_id = br.resource_id
5979 AND br.organization_id = msi.organization_id
5980 AND br.purchase_item_id = msi.inventory_item_id
5981 AND wmti.created_by = fu.user_id
5982 AND wmti.organization_id = bd.organization_id
5983 /* Fix for bug 3609023: Corrected condition to ensure we insert
5984 correct deliver_to_location_id for PO_RECEIPT */
5985 AND ((wor.autocharge_type = WIP_CONSTANTS.PO_RECEIPT AND
5986 wo1.department_id = bd.department_id)
5987 OR
5988 (wor.autocharge_type = WIP_CONSTANTS.PO_MOVE AND
5989 wo2.department_id = bd.department_id))
5990 AND mp.organization_id = wmti.organization_id
5991 AND hoi.organization_id = wmti.organization_id
5992 AND hoi.org_information_context = 'Accounting Information'
5993 /*Bug 4398047 commenting out following portion of the sql
5994 AND bcd2.calendar_code = mp.calendar_code -- Fix for Bug#2374334
5995 AND bcd2.exception_set_id = mp.calendar_exception_set_id
5996 AND bcd2.calendar_date = trunc(SYSDATE)
5997 AND bcd1.calendar_code = mp.calendar_code
5998 AND bcd1.exception_set_id = mp.calendar_exception_set_id
5999 AND bcd1.seq_num = (bcd2.next_seq_num +
6000 CEIL(NVL(msi.preprocessing_lead_time,0) +
6001 NVL(msi.fixed_lead_time,0) +
6002 (NVL(msi.variable_lead_time,0) *
6003 DECODE(msi.outside_operation_uom_type,
6004 'RESOURCE',
6005 wor.usage_rate_or_amount * wmti.primary_quantity,
6006 'ASSEMBLY',
6007 wmti.primary_quantity
6008 )
6009 ) +
6010 NVL(msi.postprocessing_lead_time,0))) Bug 4398047 end of commented portion of sql */
6011 -- consider post processing lead time before inserting need-by-date
6012 AND bcd4.calendar_code = mp.calendar_code
6013 AND bcd4.exception_set_id = mp.calendar_exception_set_id
6014 AND bcd4.calendar_date =
6015 TRUNC(DECODE(wo1.next_operation_seq_num,
6016 NULL, wo1.last_unit_completion_date,
6017 wo2.first_unit_start_date))
6018 AND bcd3.calendar_code = mp.calendar_code
6019 AND bcd3.exception_set_id = mp.calendar_exception_set_id
6020 AND bcd3.seq_num = (bcd4.next_seq_num -
6021 CEIL(NVL(msi.postprocessing_lead_time,0)));
6022 -- IF debug message level = 2, write statement below to log file
6023 IF (l_logLevel <= wip_constants.full_logging) THEN
6024 fnd_message.set_name('WIP', 'WIP_INSERTED_ROWS');
6025 fnd_message.set_token('ENTITY1', SQL%ROWCOUNT);
6026 fnd_message.set_token('ENTITY2', 'PO_REQUISITIONS_INTERFACE_ALL');
6027 l_msg := fnd_message.get;
6028 wip_logger.log(p_msg => l_msg,
6029 x_returnStatus => l_returnStatus);
6030 END IF;
6031
6032 END IF; -- po requisition per item for jobs
6033
6034 /*------------------------------------------------------------+
6035 |Insert into po_req interface table for per item for schedule
6036 +------------------------------------------------------------*/
6037 IF(l_move.scheTxn = WIP_CONSTANTS.YES AND
6038 l_move.poReqItem = WIP_CONSTANTS.YES) THEN
6039 -- Fixed bug 5144659. Insert into po_requisitions_interface_all instead of
6040 -- po_requisitions_interface as part of MOAC change.
6041 INSERT INTO po_requisitions_interface_all
6042 (last_update_date,
6043 last_updated_by,
6044 creation_date,
6045 created_by,
6046 last_update_login,
6047 request_id,
6048 program_application_id,
6049 program_id,
6050 program_update_date,
6051 org_id, /* Operating unit org */
6052 preparer_id,
6053 interface_source_code,
6054 authorization_status,
6055 source_type_code,
6056 destination_organization_id,
6057 destination_type_code,
6058 item_id,
6059 item_revision,
6060 uom_code,
6061 quantity,
6062 line_type_id,
6063 charge_account_id,
6064 deliver_to_location_id,
6065 deliver_to_requestor_id,
6066 wip_entity_id,
6067 wip_line_id,
6068 wip_operation_seq_num,
6069 wip_resource_seq_num,
6070 bom_resource_id,
6071 wip_repetitive_schedule_id,
6072 need_by_date,
6073 autosource_flag,
6074 group_code,
6075 suggested_buyer_id
6076 )
6077 SELECT SYSDATE, -- last_update_date
6078 wmti.last_updated_by, -- last_updated_by --Fix for bug 5195072
6079 SYSDATE, -- creation_date
6080 wmti.created_by, -- created_by --Fix for bug 5195072
6081 DECODE(p_gib.login_id,-1,NULL,p_gib.login_id),
6082 DECODE(p_gib.request_id,-1,NULL,p_gib.request_id),
6083 DECODE(p_gib.application_id,-1,NULL,p_gib.application_id),
6084 DECODE(p_gib.program_id,-1,NULL,p_gib.program_id),
6085 DECODE(p_gib.request_id,-1,NULL,SYSDATE), -- program_update_date
6086 to_number(hoi.org_information3), -- ou_org_id
6087 fu.employee_id, -- preparer_id
6088 'WIP', -- interface_source_code
6089 'APPROVED', -- authorization_status
6090 'VENDOR', -- source_type_code
6091 wor.organization_id, -- destination_organization_id
6092 'SHOP FLOOR', -- destination_type_code
6093 br.purchase_item_id, -- item_id
6094 DECODE(msi.revision_qty_control_code, -- item_revision
6095 1, NULL,
6096 2, DECODE(br.purchase_item_id,
6097 we.primary_item_id, wrs.bom_revision,
6098 BOM_revisions.GET_ITEM_REVISION_FN
6099 ('EXCLUDE_OPEN_HOLD', -- eco_status
6100 'ALL', -- examine_type
6101 br.ORGANIZATION_ID, -- org_id
6102 br.purchase_item_id, -- item_id
6103 wrs.first_unit_start_date -- rev_date
6104 ))), /* Fixed Bug# 1623063 */
6105 msi.primary_uom_code, -- uom_code
6106 DECODE(msi.outside_operation_uom_type, -- quantity
6107 'RESOURCE',ROUND(wor.usage_rate_or_amount *wma.primary_quantity,
6108 WIP_CONSTANTS.INV_MAX_PRECISION),
6109 'ASSEMBLY',wma.primary_quantity),
6110 3, -- line_type_id
6111 wrs.outside_processing_account,-- charge_account_id
6112 bd.location_id, -- deliver_to_location_id
6113 fu.employee_id, -- deliver_to_requestor_id
6114 wor.wip_entity_id,
6115 wmti.line_id,
6116 wor.operation_seq_num,
6117 wor.resource_seq_num,
6118 wor.resource_id,
6119 wor.repetitive_schedule_id,
6120 /* consider post processing lead time before inserting need-by-date */
6121 (bcd1.calendar_date +
6122 (DECODE(wo1.next_operation_seq_num,
6123 NULL, wo1.last_unit_completion_date,
6124 wo2.first_unit_start_date) -
6125 TRUNC(DECODE(wo1.next_operation_seq_num,
6126 NULL, wo1.last_unit_completion_date,
6127 wo2.first_unit_start_date)))), -- need_by_date
6128 'Y', -- autosource_flag
6129 NULL, -- group_code
6130 msi.buyer_id -- suggested_buyer_id
6131 FROM bom_resources br,
6132 bom_departments bd,
6133 bom_calendar_dates bcd1,
6134 bom_calendar_dates bcd2,
6135 fnd_user fu,
6136 mtl_system_items msi,
6137 mtl_parameters mp,
6138 hr_organization_information hoi,
6139 wip_entities we,
6140 wip_repetitive_schedules wrs,
6141 wip_operation_resources wor,
6142 wip_operations wo1,
6143 wip_operations wo2,
6144 wip_move_txn_allocations wma,
6145 wip_move_txn_interface wmti
6146 WHERE wmti.group_id = p_gib.group_id
6147 AND TRUNC(wmti.transaction_date) = TRUNC(p_gib.txn_date)
6148 AND wmti.process_phase = WIP_CONSTANTS.MOVE_PROC
6149 AND wmti.process_status = WIP_CONSTANTS.RUNNING
6150 AND wmti.entity_type = WIP_CONSTANTS.REPETITIVE
6151 AND (wmti.overcompletion_transaction_id IS NULL
6152 OR ( wmti.overcompletion_transaction_id IS NOT NULL
6153 AND wmti.overcompletion_transaction_qty IS NOT NULL))
6154 AND wmti.organization_id = wor.organization_id
6155 AND wmti.wip_entity_id = wor.wip_entity_id
6156 AND wmti.to_operation_seq_num = wor.operation_seq_num
6157 AND wor.repetitive_schedule_id = wma.repetitive_schedule_id
6158 AND wmti.organization_id = wma.organization_id
6159 AND wmti.transaction_id = wma.transaction_id
6160 AND wmti.fm_operation_seq_num < wmti.to_operation_seq_num
6161 AND wmti.to_intraoperation_step_type = WIP_CONSTANTS.QUEUE
6162 AND wrs.organization_id = wor.organization_id
6163 AND wrs.repetitive_schedule_id = wor.repetitive_schedule_id
6164 AND (wrs.po_creation_time = WIP_CONSTANTS.AT_OPERATION
6165 OR (wo1.count_point_type = WIP_CONSTANTS.NO_MANUAL
6166 AND wrs.po_creation_time <> WIP_CONSTANTS.MANUAL_CREATION))
6167 AND wo1.organization_id = wmti.organization_id
6168 AND wo1.wip_entity_id = wmti.wip_entity_id
6169 AND wo1.operation_seq_num = wmti.to_operation_seq_num
6170 AND wo1.repetitive_schedule_id = wor.repetitive_schedule_id
6171 AND wo2.organization_id = wo1.organization_id
6172 AND wo2.wip_entity_id = wo1.wip_entity_id
6173 AND wo2.repetitive_schedule_id = wo1.repetitive_schedule_id
6174 -- Fixed bug 2259661
6175 -- AND ((wor.autocharge_type = WIP_CONSTANTS.PO_RECEIPT
6176 -- AND wo2.operation_seq_num = wmti.to_operation_seq_num)
6177 -- OR (wor.autocharge_type = WIP_CONSTANTS.PO_MOVE
6178 AND ((wor.autocharge_type IN (WIP_CONSTANTS.PO_RECEIPT,
6179 WIP_CONSTANTS.PO_MOVE))
6180 AND ((wo1.next_operation_seq_num IS NOT NULL
6181 AND wo1.next_operation_seq_num = wo2.operation_seq_num)
6182 OR (wo1.next_operation_seq_num IS NULL
6183 AND wo2.operation_seq_num = wmti.to_operation_seq_num)))
6184 AND wor.basis_type = WIP_CONSTANTS.PER_ITEM
6185 AND wor.organization_id = br.organization_id
6186 AND wor.resource_id = br.resource_id
6187 AND br.organization_id = msi.organization_id
6188 AND br.purchase_item_id = msi.inventory_item_id
6189 AND wmti.created_by = fu.user_id
6190 AND wmti.organization_id = bd.organization_id
6191 /* Fix for bug 3609023: Corrected condition to ensure we insert
6192 correct deliver_to_location_id for PO_RECEIPT */
6193 AND ((wor.autocharge_type = WIP_CONSTANTS.PO_RECEIPT AND
6194 wo1.department_id = bd.department_id)
6195 OR
6196 (wor.autocharge_type = WIP_CONSTANTS.PO_MOVE AND
6197 wo2.department_id = bd.department_id))
6198 AND mp.organization_id = wmti.organization_id
6199 AND hoi.organization_id = wmti.organization_id
6200 AND hoi.org_information_context = 'Accounting Information'
6201 AND we.wip_entity_id = wrs.wip_entity_id
6202 AND we.organization_id = wrs.organization_id
6203 -- consider post processing lead time before inserting need-by-date
6204 AND bcd2.calendar_code = mp.calendar_code
6205 AND bcd2.exception_set_id = mp.calendar_exception_set_id
6206 AND bcd2.calendar_date =
6207 TRUNC(DECODE(wo1.next_operation_seq_num,
6208 NULL, wo1.last_unit_completion_date,
6209 wo2.first_unit_start_date))
6210 AND bcd1.calendar_code = mp.calendar_code
6211 AND bcd1.exception_set_id = mp.calendar_exception_set_id
6212 AND bcd1.seq_num = (bcd2.next_seq_num -
6213 CEIL(NVL(msi.postprocessing_lead_time,0)));
6214
6215 -- IF debug message level = 2, write statement below to log file
6216 IF (l_logLevel <= wip_constants.full_logging) THEN
6217 fnd_message.set_name('WIP', 'WIP_INSERTED_ROWS');
6218 fnd_message.set_token('ENTITY1', SQL%ROWCOUNT);
6219 fnd_message.set_token('ENTITY2', 'PO_REQUISITIONS_INTERFACE_ALL');
6220 l_msg := fnd_message.get;
6221 wip_logger.log(p_msg => l_msg,
6222 x_returnStatus => l_returnStatus);
6223 END IF;
6224
6225 END IF; -- po requisition per item for schedule
6226
6227 /*------------------------------------------------------------+
6228 | Insert into po_req interface table for per lot for job
6229 +------------------------------------------------------------*/
6230 IF(l_move.jobTxn = WIP_CONSTANTS.YES AND
6231 l_move.poReqLot = WIP_CONSTANTS.YES) THEN
6232 -- Fixed bug 5144659. Insert into po_requisitions_interface_all instead of
6233 -- po_requisitions_interface as part of MOAC change.
6234 INSERT INTO po_requisitions_interface_all
6235 (last_update_date,
6236 last_updated_by,
6237 creation_date,
6238 created_by,
6239 last_update_login,
6240 request_id,
6241 program_application_id,
6242 program_id,
6243 program_update_date,
6244 org_id, /* Operating unit org */
6245 preparer_id,
6246 interface_source_code,
6247 authorization_status,
6248 source_type_code,
6249 destination_organization_id,
6250 destination_type_code,
6251 item_id,
6252 item_revision,
6253 uom_code,
6254 quantity,
6255 line_type_id,
6256 charge_account_id,
6257 deliver_to_location_id,
6258 deliver_to_requestor_id,
6259 wip_entity_id,
6260 wip_line_id,
6261 wip_operation_seq_num,
6262 wip_resource_seq_num,
6263 bom_resource_id,
6264 wip_repetitive_schedule_id,
6265 need_by_date,
6266 autosource_flag,
6267 group_code,
6268 suggested_buyer_id,
6269 project_id,
6270 task_id,
6271 project_accounting_context
6272 )
6273 SELECT /* bugfix 5250067 performance fix. removed hint */
6274 SYSDATE, -- last_update_date
6275 MAX(wmti.last_updated_by), -- last_updated_by --Fix for bug 5195072
6276 SYSDATE, -- creation_date
6277 MAX(wmti.created_by), -- created_by --Fix for bug 5195072
6278 DECODE(p_gib.login_id,-1,NULL,p_gib.login_id),
6279 DECODE(p_gib.request_id,-1,NULL,p_gib.request_id),
6280 DECODE(p_gib.application_id,-1,NULL,p_gib.application_id),
6281 DECODE(p_gib.program_id,-1,NULL,p_gib.program_id),
6282 DECODE(p_gib.request_id,-1,NULL,SYSDATE), -- program_update_date
6283 MAX(to_number(hoi.org_information3)), -- ou_org_id
6284 MAX(fu.employee_id), -- preparer_id
6285 'WIP', -- interface_source_code
6286 'APPROVED', -- authorization_status
6287 'VENDOR', -- source_type_code
6288 wor.organization_id, -- destination_organization_id
6289 'SHOP FLOOR', -- destination_type_code
6290 MAX(br.purchase_item_id), -- item_id
6291 DECODE(max(msi.revision_qty_control_code), -- item_revision
6292 1, NULL,
6293 2, DECODE(MAX(br.purchase_item_id),
6294 MAX(wdj.primary_item_id), MAX(wdj.bom_revision),
6295 MAX(BOM_revisions.GET_ITEM_REVISION_FN
6296 ('EXCLUDE_OPEN_HOLD', -- eco_status
6297 'ALL', -- examine_type
6298 br.ORGANIZATION_ID, -- org_id
6299 br.purchase_item_id, -- item_id
6300 wdj.scheduled_start_date -- rev_date
6301 )))), /* Fixed Bug# 1623063 */
6302 MAX(msi.primary_uom_code), -- uom_code
6303 DECODE(MAX(msi.outside_operation_uom_type), -- quantity
6304 'RESOURCE',MAX(ROUND(wor.usage_rate_or_amount,
6305 WIP_CONSTANTS.INV_MAX_PRECISION)),
6306 'ASSEMBLY', 1),
6307 3, -- line_type_id
6308 MAX(wdj.outside_processing_account), -- charge_account_id
6309 MAX(bd.location_id), -- deliver_to_location_id
6310 MAX(fu.employee_id), -- deliver_to_requestor_id
6311 wor.wip_entity_id,
6312 MAX(wmti.line_id),
6313 wor.operation_seq_num,
6314 wor.resource_seq_num,
6315 MAX(wor.resource_id),
6316 wor.repetitive_schedule_id,
6317 /* Bug 4398047 commenting out this portion of the sql
6318 DECODE(MAX(wmti.entity_type), -- Fix for 2374334
6319 WIP_CONSTANTS.LOTBASED, MAX(bcd1.calendar_date),*/
6320 (MAX(bcd3.calendar_date) +
6321 (DECODE(MAX(wo1.next_operation_seq_num),
6322 NULL, MAX(wo1.last_unit_completion_date),
6323 MAX(wo2.first_unit_start_date)) -
6324 TRUNC(DECODE(MAX(wo1.next_operation_seq_num),
6325 NULL, MAX(wo1.last_unit_completion_date),
6326 MAX(wo2.first_unit_start_date))))), -- need_by_date /* Bug 4398047 removed one matching bracket */
6327 'Y', -- autosource_flag
6328 NULL, -- group_code
6329 MAX(msi.buyer_id), -- suggested_buyer_id
6330 wdj.project_id,
6331 wdj.task_id,
6332 DECODE(wdj.project_id,NULL,NULL,'Y')-- project_accounting_context
6333 FROM /* bugfix 5129403: modified the order in the from clause */
6334 wip_move_txn_interface wmti,
6335 wip_operation_resources wor,
6336 bom_resources br,
6337 mtl_system_items msi,
6338 mtl_parameters mp,
6339 -- bom_calendar_dates bcd2, Bug 4398047 join no longer required
6340 bom_calendar_dates bcd4,
6341 -- bom_calendar_dates bcd1, Bug 4398047 join no longer required
6342 bom_calendar_dates bcd3,
6343 fnd_user fu,
6344 bom_departments bd,
6345 hr_organization_information hoi,
6346 wip_discrete_jobs wdj,
6347 wip_operations wo1,
6348 wip_operations wo2
6349 WHERE wmti.group_id = p_gib.group_id
6350 AND TRUNC(wmti.transaction_date) = TRUNC(p_gib.txn_date)
6351 AND wmti.process_phase = WIP_CONSTANTS.MOVE_PROC
6352 AND wmti.process_status = WIP_CONSTANTS.RUNNING
6353 AND (wmti.entity_type = WIP_CONSTANTS.DISCRETE
6354 OR wmti.entity_type = WIP_CONSTANTS.LOTBASED)/* WSM */
6355 AND (wmti.overcompletion_transaction_id IS NULL
6356 OR ( wmti.overcompletion_transaction_id IS NOT NULL
6357 AND wmti.overcompletion_transaction_qty IS NOT NULL))
6358 -- Bugfix 6679124: Join to wor using wdj rather than wmti to get better execution plan
6359 -- AND wmti.organization_id = wor.organization_id
6360 -- AND wmti.wip_entity_id = wor.wip_entity_id
6361 AND wdj.organization_id = wor.organization_id --6679124
6362 AND wdj.wip_entity_id = wor.wip_entity_id -- 6679124
6363 AND wmti.to_operation_seq_num = wor.operation_seq_num
6364 AND wmti.fm_operation_seq_num < wmti.to_operation_seq_num
6365 AND wmti.to_intraoperation_step_type = WIP_CONSTANTS.QUEUE
6366 AND wo1.organization_id = wmti.organization_id
6367 AND wo1.wip_entity_id = wmti.wip_entity_id
6368 AND wo1.operation_seq_num = wmti.to_operation_seq_num
6369 AND wo2.organization_id = wo1.organization_id
6370 AND wo2.wip_entity_id = wo1.wip_entity_id
6371 -- Fixed bug 2259661
6372 -- AND ((wor.autocharge_type = WIP_CONSTANTS.PO_RECEIPT
6373 -- AND wo2.operation_seq_num = wmti.to_operation_seq_num)
6374 -- OR (wor.autocharge_type = WIP_CONSTANTS.PO_MOVE
6375 AND ((wor.autocharge_type IN (WIP_CONSTANTS.PO_RECEIPT,
6376 WIP_CONSTANTS.PO_MOVE))
6377 AND ((wo1.next_operation_seq_num IS NOT NULL
6378 AND wo1.next_operation_seq_num = wo2.operation_seq_num)
6379 OR (wo1.next_operation_seq_num IS NULL
6380 AND wo2.operation_seq_num = wmti.to_operation_seq_num)))
6381 AND wdj.organization_id = wmti.organization_id
6382 AND wdj.wip_entity_id = wmti.wip_entity_id
6383 AND (wdj.po_creation_time = WIP_CONSTANTS.AT_OPERATION
6384 OR (wo1.count_point_type = WIP_CONSTANTS.NO_MANUAL
6385 AND wdj.po_creation_time <> WIP_CONSTANTS.MANUAL_CREATION))
6386 AND wor.basis_type = WIP_CONSTANTS.PER_LOT
6387 AND wor.organization_id = br.organization_id
6388 AND wor.resource_id = br.resource_id
6389 AND br.organization_id = msi.organization_id
6390 AND br.purchase_item_id = msi.inventory_item_id
6391 AND wmti.created_by = fu.user_id
6392 AND wmti.organization_id = bd.organization_id
6393 /* Fix for bug 3609023: Corrected condition to ensure we insert
6394 correct deliver_to_location_id for PO_RECEIPT */
6395 AND ((wor.autocharge_type = WIP_CONSTANTS.PO_RECEIPT AND
6396 wo1.department_id = bd.department_id)
6397 OR
6398 (wor.autocharge_type = WIP_CONSTANTS.PO_MOVE AND
6399 wo2.department_id = bd.department_id))
6400 AND mp.organization_id = wmti.organization_id
6401 AND hoi.organization_id = wmti.organization_id
6402 AND hoi.org_information_context = 'Accounting Information'
6403 /* Bug 4398047 removing the following portion of the sql
6404 AND bcd2.calendar_code = mp.calendar_code -- Fix for Bug#2374334
6405 AND bcd2.exception_set_id = mp.calendar_exception_set_id
6406 AND bcd2.calendar_date = trunc(SYSDATE)
6407 AND bcd1.calendar_code = mp.calendar_code
6408 AND bcd1.exception_set_id = mp.calendar_exception_set_id
6409 AND bcd1.seq_num = (bcd2.next_seq_num +
6410 CEIL(NVL(msi.preprocessing_lead_time,0) + NVL(msi.fixed_lead_time,0) +
6411 (NVL(msi.variable_lead_time,0) *
6412 DECODE(msi.outside_operation_uom_type,
6413 'RESOURCE',
6414 wor.usage_rate_or_amount,
6415 'ASSEMBLY',
6416 1
6417 )
6418 )
6419 +
6420 NVL(msi.postprocessing_lead_time,0))) Bug 4398047 end of commenting */
6421 -- consider post processing lead time before inserting need-by-date
6422 AND bcd4.calendar_code = mp.calendar_code
6423 AND bcd4.exception_set_id = mp.calendar_exception_set_id
6424 AND bcd4.calendar_date =
6425 TRUNC(DECODE(wo1.next_operation_seq_num,
6426 NULL, wo1.last_unit_completion_date,
6427 wo2.first_unit_start_date))
6428 AND bcd3.calendar_code = mp.calendar_code
6429 AND bcd3.exception_set_id = mp.calendar_exception_set_id
6430 AND bcd3.seq_num = (bcd4.next_seq_num -
6431 CEIL(NVL(msi.postprocessing_lead_time,0)))
6432 GROUP BY wor.organization_id,
6433 wor.wip_entity_id,
6434 wor.repetitive_schedule_id,
6435 wor.operation_seq_num,
6436 wor.resource_seq_num,
6437 wdj.project_id,
6438 wdj.task_id
6439 HAVING 1 =
6440 DECODE(SIGN(MAX(wo1.quantity_in_queue) -
6441 SUM(wmti.primary_quantity)),
6442 0, DECODE(SIGN(MAX(wo1.quantity_running +
6443 wo1.quantity_waiting_to_move +
6444 wo1.quantity_rejected +
6445 wo1.quantity_scrapped)),
6446 0, DECODE(SIGN(MAX(wo1.quantity_completed)),0,1,0),
6447 1, 0),
6448 1, 0);
6449
6450 -- IF debug message level = 2, write statement below to log file
6451 IF (l_logLevel <= wip_constants.full_logging) THEN
6452 fnd_message.set_name('WIP', 'WIP_INSERTED_ROWS');
6453 fnd_message.set_token('ENTITY1', SQL%ROWCOUNT);
6454 fnd_message.set_token('ENTITY2', 'PO_REQUISITIONS_INTERFACE_ALL');
6455 l_msg := fnd_message.get;
6456 wip_logger.log(p_msg => l_msg,
6457 x_returnStatus => l_returnStatus);
6458 END IF;
6459
6460 END IF; -- po requisition per lot for job
6461
6462 /*------------------------------------------------------------+
6463 | Insert into po_req interface table for per lot for schedule
6464 +------------------------------------------------------------*/
6465 IF(l_move.scheTxn = WIP_CONSTANTS.YES AND
6466 l_move.poReqLot = WIP_CONSTANTS.YES) THEN
6467 -- Fixed bug 5144659. Insert into po_requisitions_interface_all instead of
6468 -- po_requisitions_interface as part of MOAC change.
6469 INSERT INTO po_requisitions_interface_all
6470 (last_update_date,
6471 last_updated_by,
6472 creation_date,
6473 created_by,
6474 last_update_login,
6475 request_id,
6476 program_application_id,
6477 program_id,
6478 program_update_date,
6479 org_id, /* Operating unit org */
6480 preparer_id,
6481 interface_source_code,
6482 authorization_status,
6483 source_type_code,
6484 destination_organization_id,
6485 destination_type_code,
6486 item_id,
6487 item_revision,
6488 uom_code,
6489 quantity,
6490 line_type_id,
6491 charge_account_id,
6492 deliver_to_location_id,
6493 deliver_to_requestor_id,
6494 wip_entity_id,
6495 wip_line_id,
6496 wip_operation_seq_num,
6497 wip_resource_seq_num,
6498 bom_resource_id,
6499 wip_repetitive_schedule_id,
6500 need_by_date,
6501 autosource_flag,
6502 group_code,
6503 suggested_buyer_id
6504 )
6505 SELECT SYSDATE, -- last_update_date
6506 MAX(wmti.last_updated_by), -- last_updated_by --Fix for bug 5195072
6507 SYSDATE, -- creation_date
6508 MAX(wmti.created_by), -- created_by --Fix for bug 5195072
6509 DECODE(p_gib.login_id,-1,NULL,p_gib.login_id),
6510 DECODE(p_gib.request_id,-1,NULL,p_gib.request_id),
6511 DECODE(p_gib.application_id,-1,NULL,p_gib.application_id),
6512 DECODE(p_gib.program_id,-1,NULL,p_gib.program_id),
6513 DECODE(p_gib.request_id,-1,NULL,SYSDATE), -- program_update_date
6514 MAX(to_number(hoi.org_information3)), -- ou_org_id
6515 MAX(fu.employee_id), -- preparer_id
6516 'WIP', -- interface_source_code
6517 'APPROVED', -- authorization_status
6518 'VENDOR', -- source_type_code
6519 wor.organization_id, -- destination_organization_id
6520 'SHOP FLOOR', -- destination_type_code
6521 MAX(br.purchase_item_id), -- item_id
6522 DECODE(MAX(msi.revision_qty_control_code), -- item_revision
6523 1, NULL,
6524 2, DECODE(MAX(br.purchase_item_id),
6525 MAX(we.primary_item_id), MAX(wrs.bom_revision),
6526 MAX(BOM_revisions.GET_ITEM_REVISION_FN
6527 ('EXCLUDE_OPEN_HOLD', -- eco_status
6528 'ALL', -- examine_type
6529 br.ORGANIZATION_ID, -- org_id
6530 br.purchase_item_id, -- item_id
6531 wrs.first_unit_start_date -- rev_date
6532 )))), /* Fixed Bug# 1623063 */
6533 MAX(msi.primary_uom_code), -- uom_code
6534 DECODE(MAX(msi.outside_operation_uom_type), -- quantity
6535 'RESOURCE',MAX(ROUND(wor.usage_rate_or_amount,
6536 WIP_CONSTANTS.INV_MAX_PRECISION)),
6537 'ASSEMBLY', 1),
6538 3, -- line_type_id
6539 MAX(wrs.outside_processing_account), -- charge_account_id
6540 MAX(bd.location_id), -- deliver_to_location_id
6541 MAX(fu.employee_id), -- deliver_to_requestor_id
6542 wor.wip_entity_id,
6543 MAX(wmti.line_id),
6544 wor.operation_seq_num,
6545 wor.resource_seq_num,
6546 MAX(wor.resource_id),
6547 wor.repetitive_schedule_id,
6548 (MAX(bcd1.calendar_date) +
6549 (DECODE(MAX(wo1.next_operation_seq_num),
6550 NULL, MAX(wo1.last_unit_completion_date),
6551 MAX(wo2.first_unit_start_date)) -
6552 TRUNC(DECODE(MAX(wo1.next_operation_seq_num),
6553 NULL, MAX(wo1.last_unit_completion_date),
6554 MAX(wo2.first_unit_start_date))))), -- need_by_date
6555 'Y', -- autosource_flag
6556 NULL, -- group_code
6557 MAX(msi.buyer_id) -- suggested_buyer_id
6558 FROM bom_departments bd,
6559 bom_resources br,
6560 bom_calendar_dates bcd1,
6561 bom_calendar_dates bcd2,
6562 fnd_user fu,
6563 mtl_item_revisions mir,
6564 mtl_system_items msi,
6565 mtl_parameters mp,
6566 hr_organization_information hoi,
6567 wip_operation_resources wor,
6568 wip_repetitive_schedules wrs,
6569 wip_entities we,
6570 wip_operations wo1,
6571 wip_operations wo2,
6572 wip_move_txn_allocations wma,
6573 wip_move_txn_interface wmti
6574 WHERE wmti.group_id = p_gib.group_id
6575 AND TRUNC(wmti.transaction_date) = TRUNC(p_gib.txn_date)
6576 AND wmti.process_phase = WIP_CONSTANTS.MOVE_PROC
6577 AND wmti.process_status = WIP_CONSTANTS.RUNNING
6578 AND wmti.entity_type = WIP_CONSTANTS.REPETITIVE
6579 AND (wmti.overcompletion_transaction_id IS NULL
6580 OR ( wmti.overcompletion_transaction_id IS NOT NULL
6581 AND wmti.overcompletion_transaction_qty IS NOT NULL))
6582 AND wmti.organization_id = wor.organization_id
6583 AND wmti.wip_entity_id = wor.wip_entity_id
6584 AND wmti.to_operation_seq_num = wor.operation_seq_num
6585 AND wor.repetitive_schedule_id = wma.repetitive_schedule_id
6586 AND wmti.organization_id = wma.organization_id
6587 AND wmti.transaction_id = wma.transaction_id
6588 AND wmti.fm_operation_seq_num < wmti.to_operation_seq_num
6589 AND wmti.to_intraoperation_step_type = WIP_CONSTANTS.QUEUE
6590 AND wrs.organization_id = wor.organization_id
6591 AND wrs.repetitive_schedule_id = wor.repetitive_schedule_id
6592 AND (wrs.po_creation_time = WIP_CONSTANTS.AT_OPERATION
6593 OR (wo1.count_point_type = WIP_CONSTANTS.NO_MANUAL
6594 AND wrs.po_creation_time <> WIP_CONSTANTS.MANUAL_CREATION))
6595 AND wo1.organization_id = wmti.organization_id
6596 AND wo1.wip_entity_id = wmti.wip_entity_id
6597 AND wo1.repetitive_schedule_id = wor.repetitive_schedule_id
6598 AND wo1.operation_seq_num = wmti.to_operation_seq_num
6599 AND wo2.organization_id = wo1.organization_id
6600 AND wo2.wip_entity_id = wo1.wip_entity_id
6601 AND wo2.repetitive_schedule_id = wo1.repetitive_schedule_id
6602 -- Fixed bug 2259661
6603 -- AND ((wor.autocharge_type = WIP_CONSTANTS.PO_RECEIPT
6604 -- AND wo2.operation_seq_num = wmti.to_operation_seq_num)
6605 -- OR (wor.autocharge_type = WIP_CONSTANTS.PO_MOVE
6606 AND ((wor.autocharge_type IN (WIP_CONSTANTS.PO_RECEIPT,
6607 WIP_CONSTANTS.PO_MOVE))
6608 AND ((wo1.next_operation_seq_num IS NOT NULL
6609 AND wo1.next_operation_seq_num = wo2.operation_seq_num)
6610 OR (wo1.next_operation_seq_num IS NULL
6611 AND wo2.operation_seq_num = wmti.to_operation_seq_num)))
6612 AND wor.basis_type = WIP_CONSTANTS.PER_LOT
6613 AND wor.organization_id = br.organization_id
6614 AND wor.resource_id = br.resource_id
6615 AND br.organization_id = msi.organization_id
6616 AND br.purchase_item_id = msi.inventory_item_id
6617 AND wmti.created_by = fu.user_id
6618 AND wmti.organization_id = bd.organization_id
6619 /* Fix for bug 3609023: Corrected condition to ensure we insert
6620 correct deliver_to_location_id for PO_RECEIPT */
6621 AND ((wor.autocharge_type = WIP_CONSTANTS.PO_RECEIPT AND
6622 wo1.department_id = bd.department_id)
6623 OR
6624 (wor.autocharge_type = WIP_CONSTANTS.PO_MOVE AND
6625 wo2.department_id = bd.department_id))
6626 AND mp.organization_id = wmti.organization_id
6627 AND hoi.organization_id = wmti.organization_id
6628 AND hoi.org_information_context = 'Accounting Information'
6629 AND we.wip_entity_id = wrs.wip_entity_id
6630 AND we.organization_id = wrs.organization_id
6631 AND mir.inventory_item_id = msi.inventory_item_id
6632 AND mir.organization_id = msi.organization_id
6633 AND mir.revision =
6634 (SELECT MAX(revision)
6635 FROM mtl_item_revisions mir1,
6636 eng_revised_items eri
6637 WHERE mir1.inventory_item_id = mir.inventory_item_id
6638 AND mir1.organization_id = mir.organization_id
6639 AND mir1.effectivity_date <= wmti.transaction_date
6640 AND mir1.revised_item_sequence_id =
6641 eri.revised_item_sequence_id(+)
6642 AND nvl(eri.status_type,0) not in (1,2)
6643 )
6644 -- consider post processing lead time before inserting need-by-date
6645 AND bcd2.calendar_code = mp.calendar_code
6646 AND bcd2.exception_set_id = mp.calendar_exception_set_id
6647 AND bcd2.calendar_date =
6648 TRUNC(DECODE (wo1.next_operation_seq_num,
6649 NULL, wo1.last_unit_completion_date,
6650 wo2.first_unit_start_date))
6651 AND bcd1.calendar_code = mp.calendar_code
6652 AND bcd1.exception_set_id = mp.calendar_exception_set_id
6653 AND bcd1.seq_num = (bcd2.next_seq_num -
6654 CEIL(NVL(msi.postprocessing_lead_time,0)))
6655 GROUP BY wor.organization_id,
6656 wor.wip_entity_id,
6657 wor.repetitive_schedule_id,
6658 wor.operation_seq_num,
6659 wor.resource_seq_num
6660 HAVING 1 =
6661 DECODE(SIGN(MAX(wo1.quantity_in_queue) -
6662 SUM(wma.primary_quantity)),
6663 0, DECODE(SIGN(MAX(wo1.quantity_running +
6664 wo1.quantity_waiting_to_move +
6665 wo1.quantity_rejected +
6666 wo1.quantity_scrapped)),
6667 0, DECODE(SIGN(MAX(wo1.quantity_completed)),0,1,0),
6668 1, 0),
6669 1, 0);
6670
6671 -- IF debug message level = 2, write statement below to log file
6672 IF (l_logLevel <= wip_constants.full_logging) THEN
6673 fnd_message.set_name('WIP', 'WIP_INSERTED_ROWS');
6674 fnd_message.set_token('ENTITY1', SQL%ROWCOUNT);
6675 fnd_message.set_token('ENTITY2', 'PO_REQUISITIONS_INTERFACE_ALL');
6676 l_msg := fnd_message.get;
6677 wip_logger.log(p_msg => l_msg,
6678 x_returnStatus => l_returnStatus);
6679 END IF;
6680 END IF; -- po requisition per lot for schedule
6681
6682 IF(po_code_release_grp.Current_Release <
6683 po_code_release_grp.PRC_11i_Family_Pack_J) THEN
6684 -- Only cut new requisition if customer do not have PO patchset J,
6685 -- otherwise, try to update PO/requisition instead
6686 OPEN c_additional_reqs(p_group_id => p_gib.group_id);
6687 /* for overcompletions - create new reqs for subsequent operations IF
6688 an overmove has occurred */
6689 LOOP
6690 FETCH c_additional_reqs INTO l_additional_reqs;
6691 EXIT WHEN c_additional_reqs%NOTFOUND;
6692 -- call PL/SQL API to create additional_req
6693 wip_osp.create_additional_req
6694 (p_wip_entity_id => l_additional_reqs.wip_id,
6695 p_organization_id => l_additional_reqs.org_id,
6696 p_repetitive_schedule_id => l_additional_reqs.rep_sched_id,
6697 p_added_quantity => l_additional_reqs.oc_qty,
6698 p_op_seq => l_additional_reqs.op_seq_num);
6699 END LOOP;
6700 IF(c_additional_reqs%ISOPEN) THEN
6701 CLOSE c_additional_reqs;
6702 END IF;
6703 END IF; -- check PO patchset
6704 x_returnStatus := fnd_api.g_ret_sts_success;
6705
6706 -- write to the log file
6707 IF (l_logLevel <= wip_constants.trace_logging) THEN
6708 wip_logger.exitPoint(p_procName => 'wip_movProc_priv.insert_po_req',
6709 p_procReturnStatus => x_returnStatus,
6710 p_msg => 'procedure complete',
6711 x_returnStatus => l_returnStatus);
6712 END IF;
6713
6714 EXCEPTION
6715 WHEN others THEN
6716 IF(c_additional_reqs%ISOPEN) THEN
6717 CLOSE c_additional_reqs;
6718 END IF;
6719 x_returnStatus := fnd_api.g_ret_sts_unexp_error;
6720 l_errMsg := 'unexpected error: ' || SQLERRM || 'SQLCODE = ' || SQLCODE;
6721
6722 IF (l_logLevel <= wip_constants.trace_logging) THEN
6723 wip_logger.exitPoint(p_procName=>'wip_movProc_priv.insert_po_req',
6724 p_procReturnStatus => x_returnStatus,
6725 p_msg => l_errMsg,
6726 x_returnStatus => l_returnStatus);
6727 END IF;
6728 fnd_message.set_name('FND', 'FND_GENERIC_MESSAGE');
6729 fnd_message.set_token('MESSAGE', l_errMsg);
6730 fnd_msg_pub.add;
6731 END insert_po_req;
6732
6733 /*****************************************************************************
6734 * This procedure is equivalent to wip_startwf in wiltps4.ppc
6735 * This procedure is used to start workflow for OSP stuff
6736 ****************************************************************************/
6737 PROCEDURE start_workflow(p_gib IN group_rec_t,
6738 x_returnStatus OUT NOCOPY VARCHAR2) IS
6739
6740 CURSOR c_wmti_txn(p_group_id NUMBER,
6741 p_txn_date DATE) IS
6742 SELECT wmti.transaction_id txn_id,
6743 wmti.wip_entity_id wip_id,
6744 wmti.repetitive_schedule_id sched_id,
6745 wmti.organization_id org_id,
6746 wmti.primary_quantity pri_qty,
6747 muom.unit_of_measure pri_uom,
6748 wmti.to_operation_seq_num op_seq_num,
6749 wor.autocharge_type autocharge_type
6750 FROM bom_resources br,
6751 mtl_units_of_measure muom,
6752 wip_operation_resources wor,
6753 wip_operations wo,
6754 wip_move_txn_interface wmti
6755 WHERE wmti.group_id = p_group_id
6756 AND wmti.process_phase = WIP_CONSTANTS.MOVE_PROC
6757 AND wmti.process_status = WIP_CONSTANTS.RUNNING
6758 AND TRUNC(wmti.transaction_date)= TRUNC(p_txn_date)
6759 AND (wmti.fm_operation_seq_num < wmti.to_operation_seq_num
6760 OR (wmti.fm_operation_seq_num = wmti.to_operation_seq_num
6761 AND wmti.fm_intraoperation_step_type <
6762 wmti.to_intraoperation_step_type))
6763 AND wmti.to_intraoperation_step_type = WIP_CONSTANTS.QUEUE
6764 AND muom.uom_code = wmti.primary_uom
6765 AND wo.wip_entity_id = wmti.wip_entity_id
6766 AND wo.organization_id = wmti.organization_id
6767 AND NVL(wo.repetitive_schedule_id, -1) =
6768 NVL(wmti.repetitive_schedule_id, -1)
6769 AND wo.operation_seq_num = wmti.to_operation_seq_num
6770 AND NOT EXISTS
6771 (SELECT 'EXISTS'
6772 FROM po_distributions_all pd,
6773 po_line_locations_all ps
6774 WHERE pd.wip_entity_id = wo.wip_entity_id
6775 AND NVL(pd.wip_repetitive_schedule_id, -1) =
6776 NVL(wo.repetitive_schedule_id, -1)
6777 AND pd.wip_operation_seq_num = wo.previous_operation_seq_num
6778 AND ps.line_location_id = pd.line_location_id
6779 AND ps.ship_to_location_id IN
6780 (SELECT location_id
6781 FROM po_location_associations_all
6782 WHERE vENDor_id IS NOT NULL
6783 AND vENDor_site_id IS NOT NULL))
6784 AND wor.wip_entity_id = wo.wip_entity_id
6785 AND wor.organization_id = wo.organization_id
6786 AND NVL(wor.repetitive_schedule_id, -1) =
6787 NVL(wo.repetitive_schedule_id, -1)
6788 AND wor.operation_seq_num = wo.operation_seq_num
6789 AND wor.autocharge_type in(WIP_CONSTANTS.PO_MOVE, --Fix for 2393550
6790 WIP_CONSTANTS.PO_RECEIPT)
6791 AND br.resource_id = wor.resource_id
6792 AND br.organization_id = wor.organization_id
6793 AND br.purchase_item_id IS NOT NULL;
6794
6795 l_params wip_logger.param_tbl_t;
6796 l_returnStatus VARCHAR(1);
6797 l_errMsg VARCHAR2(240);
6798 l_wmti_txn c_wmti_txn%ROWTYPE;
6799 l_itemkey VARCHAR2(80) := NULL;
6800 l_logLevel NUMBER := fnd_log.g_current_runtime_level;
6801 l_success NUMBER := 0;
6802 l_org_id number;
6803 l_ou_id number;
6804 l_org_acct_ctxt VARCHAR2(30):= 'Accounting Information';
6805
6806 -- new parameter used to determine whether we have to launch "Req Import"
6807 -- concurrent program or not
6808 l_osp_exist NUMBER := WIP_CONSTANTS.NO;
6809 l_launch_req_import NUMBER := WIP_CONSTANTS.YES;
6810 BEGIN
6811 -- write parameter value to log file
6812 IF (l_logLevel <= wip_constants.trace_logging) THEN
6813 l_params(1).paramName := 'p_group_id';
6814 l_params(1).paramValue := p_gib.group_id;
6815 l_params(2).paramName := 'p_txn_date';
6816 l_params(2).paramValue := p_gib.txn_date;
6817 wip_logger.entryPoint(p_procName =>'wip_movProc_priv.start_workflow',
6818 p_params => l_params,
6819 x_returnStatus => l_returnStatus);
6820 END IF;
6821 OPEN c_wmti_txn(p_group_id => p_gib.group_id,
6822 p_txn_date => p_gib.txn_date);
6823 LOOP
6824 FETCH c_wmti_txn INTO l_wmti_txn;
6825 EXIT WHEN c_wmti_txn%NOTFOUND;
6826
6827 l_osp_exist := WIP_CONSTANTS.YES;
6828 l_org_id := l_wmti_txn.org_id;
6829
6830 IF(l_wmti_txn.autocharge_type = WIP_CONSTANTS.PO_MOVE) THEN
6831 -- Launch workflow only for PO_MOVE
6832 -- call PL/SQL API to start workflow
6833
6834 -- Fixed bug 5333089. Need to set org context before launching workflow
6835 -- because Req Import need this information.
6836 -- get the OU, set context for MOAC. Need to set it for each PO Move
6837 -- record found.
6838 select to_number(ORG_INFORMATION3) into l_ou_id
6839 from HR_ORGANIZATION_INFORMATION
6840 where ORGANIZATION_ID = l_org_id
6841 and ORG_INFORMATION_CONTEXT = l_org_acct_ctxt;
6842 FND_REQUEST.SET_ORG_ID (l_ou_id);
6843
6844 wip_osp_shp_i_wf.StartWFProcess
6845 (p_itemtype => 'WIPISHPW',
6846 p_itemkey => l_itemkey,
6847 p_workflow_process => 'INTERMEDIATE_SHIP',
6848 p_wip_entity_id => l_wmti_txn.wip_id,
6849 p_rep_sched_id => l_wmti_txn.sched_id,
6850 p_organization_id => l_wmti_txn.org_id,
6851 p_primary_qty => l_wmti_txn.pri_qty,
6852 p_primary_uom => l_wmti_txn.pri_uom,
6853 p_op_seq_num => l_wmti_txn.op_seq_num);
6854
6855 IF l_itemkey IS NOT NULL THEN
6856 UPDATE wip_move_transactions
6857 SET wf_itemtype = 'WIPISHPW',
6858 wf_itemkey = l_itemkey
6859 WHERE transaction_id = l_wmti_txn.txn_id;
6860 END IF;
6861 -- No need to lauch "Req Import" again if we already laucned the workflow
6862 -- because "Req Import" is part of the workflow itself.
6863 l_launch_req_import := WIP_CONSTANTS.NO;
6864 -- Fix for Bug#4369684. Need to reassign to null for multiple OSP Move.
6865 l_itemkey := NULL;
6866 END IF; -- PO_MOVE
6867 END LOOP;
6868
6869 -- If OSP item exists, and there is no workflow launch yet, we have to launch
6870 -- "Req Import" concurrent program
6871 IF(l_osp_exist = WIP_CONSTANTS.YES AND
6872 l_launch_req_import = WIP_CONSTANTS.YES) THEN
6873
6874 -- get the OU, set context for MOAC
6875 select to_number(ORG_INFORMATION3) into l_ou_id
6876 from HR_ORGANIZATION_INFORMATION
6877 where ORGANIZATION_ID = l_org_id
6878 and ORG_INFORMATION_CONTEXT = l_org_acct_ctxt;
6879 FND_REQUEST.SET_ORG_ID (l_ou_id);
6880
6881 l_success := fnd_request.submit_request(
6882 'PO', 'REQIMPORT', NULL, NULL, FALSE,'WIP', NULL, 'ITEM',
6883 NULL ,'N', 'Y' , chr(0), NULL, NULL, NULL,
6884 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
6885 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
6886 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
6887 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
6888 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
6889 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
6890 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
6891 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
6892 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
6893 ) ;
6894 -- We can just ignore the return status
6895 END IF; -- all OSP are PO_RECEIPT
6896
6897 IF(c_wmti_txn%ISOPEN) THEN
6898 CLOSE c_wmti_txn;
6899 END IF;
6900 x_returnStatus := fnd_api.g_ret_sts_success;
6901 -- write to the log file
6902 IF (l_logLevel <= wip_constants.trace_logging) THEN
6903 wip_logger.exitPoint(p_procName => 'wip_movProc_priv.start_workflow',
6904 p_procReturnStatus => x_returnStatus,
6905 p_msg => 'procedure complete',
6906 x_returnStatus => l_returnStatus);
6907 END IF;
6908
6909 EXCEPTION
6910
6911 WHEN others THEN
6912 IF(c_wmti_txn%ISOPEN) THEN
6913 CLOSE c_wmti_txn;
6914 END IF;
6915 x_returnStatus := fnd_api.g_ret_sts_unexp_error;
6916 l_errMsg := 'unexpected error: ' || SQLERRM || 'SQLCODE = ' || SQLCODE;
6917
6918 IF (l_logLevel <= wip_constants.trace_logging) THEN
6919 wip_logger.exitPoint(p_procName=>'wip_movProc_priv.start_workflow',
6920 p_procReturnStatus => x_returnStatus,
6921 p_msg => l_errMsg,
6922 x_returnStatus => l_returnStatus);
6923 END IF;
6924 fnd_message.set_name('FND', 'FND_GENERIC_MESSAGE');
6925 fnd_message.set_token('MESSAGE', l_errMsg);
6926 fnd_msg_pub.add;
6927 END start_workflow;
6928
6929 /*****************************************************************************
6930 * This procedure is equivalent to witpsuc_op_units_complete in wiltps5.ppc
6931 * This procedure is used to update operation unit complete in
6932 * WIP_OPERATIONS
6933 ****************************************************************************/
6934 PROCEDURE update_complete_qty(p_gib IN group_rec_t,
6935 p_txn_id IN NUMBER := NULL,
6936 x_returnStatus OUT NOCOPY VARCHAR2) IS
6937
6938 l_params wip_logger.param_tbl_t;
6939 l_returnStatus VARCHAR(1);
6940 l_msg VARCHAR(240);
6941 l_errMsg VARCHAR2(240);
6942 l_logLevel NUMBER := fnd_log.g_current_runtime_level;
6943
6944 BEGIN
6945 -- write parameter value to log file
6946 IF (l_logLevel <= wip_constants.trace_logging) THEN
6947 l_params(1).paramName := 'p_group_id';
6948 l_params(1).paramValue := p_gib.group_id;
6949 l_params(2).paramName := 'p_txn_date';
6950 l_params(2).paramValue := p_gib.txn_date;
6951 l_params(3).paramName := 'p_txn_id';
6952 l_params(3).paramValue := p_txn_id;
6953 wip_logger.entryPoint(p_procName =>'wip_movProc_priv.update_complete_qty',
6954 p_params => l_params,
6955 x_returnStatus => l_returnStatus);
6956 END IF;
6957
6958 /*------------------------------------------------------------+
6959 | Update quantity_completed
6960 +------------------------------------------------------------*/
6961 UPDATE wip_operations wop
6962 SET (quantity_completed,
6963 last_updated_by,
6964 last_update_date,
6965 last_update_login,
6966 request_id,
6967 program_application_id,
6968 program_id,
6969 program_update_date
6970 ) =
6971 (SELECT decode(wop.repetitive_schedule_id,null, /* Bugfix 6333820 FP for 5987013: decode between 4081320 fix (for discrete) and original code (for repetitive) to allow negative quantity_completed for repetitive and rail at 0 for discrete */
6972 greatest(0, wop.quantity_completed + -- added greatest function to fix FP bug 4081320
6973 NVL(SUM(NVL(wma1.primary_quantity, wmti.primary_quantity) *
6974 DECODE(SIGN(wmti.to_operation_seq_num -
6975 wmti.fm_operation_seq_num),
6976 0,DECODE(SIGN(wmti.fm_intraoperation_step_type -
6977 WIP_CONSTANTS.RUN),
6978 0,DECODE(SIGN(wmti.to_intraoperation_step_type -
6979 WIP_CONSTANTS.RUN),1,1,-1),
6980 -1,DECODE(SIGN(wmti.to_intraoperation_step_type -
6981 WIP_CONSTANTS.RUN),1,1,-1),
6982 1,-1),
6983 1, 1,
6984 -1,-1)
6985 ),0)), /* for discrete */
6986 wop.quantity_completed + -- added greatest function to fix FP bug 4081320
6987 NVL(SUM(NVL(wma1.primary_quantity, wmti.primary_quantity) *
6988 DECODE(SIGN(wmti.to_operation_seq_num -
6989 wmti.fm_operation_seq_num),
6990 0,DECODE(SIGN(wmti.fm_intraoperation_step_type -
6991 WIP_CONSTANTS.RUN),
6992 0,DECODE(SIGN(wmti.to_intraoperation_step_type -
6993 WIP_CONSTANTS.RUN),1,1,-1),
6994 -1,DECODE(SIGN(wmti.to_intraoperation_step_type -
6995 WIP_CONSTANTS.RUN),1,1,-1),
6996 1,-1),
6997 1, 1,
6998 -1,-1)
6999 ),0) /* for repetitive */
7000 ), -- quantity_completed
7001 MAX(wmti.last_updated_by),
7002 SYSDATE, -- last_update_date
7003 DECODE(p_gib.login_id,-1,NULL,p_gib.login_id),
7004 DECODE(p_gib.request_id,-1,NULL,p_gib.request_id),
7005 DECODE(p_gib.application_id,-1,NULL,p_gib.application_id),
7006 DECODE(p_gib.program_id,-1,NULL,p_gib.program_id),
7007 DECODE(p_gib.request_id,-1,NULL,SYSDATE)-- program_update_date
7008 FROM wip_operations wop1,
7009 wip_move_txn_allocations wma1,
7010 wip_move_txn_interface wmti
7011 WHERE wop1.rowid = wop.rowid
7012 AND wmti.group_id = p_gib.group_id
7013 AND (p_txn_id IS NULL OR wmti.transaction_id = p_txn_id)
7014 AND TRUNC(wmti.transaction_date) = TRUNC(p_gib.txn_date)
7015 AND wmti.process_phase = WIP_CONSTANTS.MOVE_PROC
7016 AND wmti.process_status = WIP_CONSTANTS.RUNNING
7017 AND wop1.organization_id = wmti.organization_id
7018 AND wop1.wip_entity_id = wmti.wip_entity_id
7019 AND wmti.organization_id = wma1.organization_id (+)
7020 AND wmti.transaction_id = wma1.transaction_id (+)
7021 AND NVL(wma1.repetitive_schedule_id,0) =
7022 NVL(wop1.repetitive_schedule_id,0)
7023 AND ((wop1.operation_seq_num >= wmti.fm_operation_seq_num
7024 + DECODE(SIGN(wmti.fm_intraoperation_step_type -
7025 WIP_CONSTANTS.RUN),1,1,0)
7026 AND wop1.operation_seq_num < wmti.to_operation_seq_num
7027 + DECODE(SIGN(wmti.to_intraoperation_step_type -
7028 WIP_CONSTANTS.RUN),1,1,0)
7029 AND (wmti.to_operation_seq_num > wmti.fm_operation_seq_num
7030 OR (wmti.to_operation_seq_num = wmti.fm_operation_seq_num
7031 AND wmti.fm_intraoperation_step_type <= WIP_CONSTANTS.RUN
7032 AND wmti.to_intraoperation_step_type > WIP_CONSTANTS.RUN))
7033 AND (wop1.count_point_type < WIP_CONSTANTS.NO_MANUAL
7034 OR wop1.operation_seq_num = wmti.fm_operation_seq_num
7035 OR (wop1.operation_seq_num = wmti.to_operation_seq_num
7036 AND wmti.to_intraoperation_step_type > WIP_CONSTANTS.RUN)))
7037 OR
7038 (wop1.operation_seq_num < wmti.fm_operation_seq_num
7039 + DECODE(SIGN(wmti.fm_intraoperation_step_type -
7040 WIP_CONSTANTS.RUN),1,1,0)
7041 AND wop1.operation_seq_num >= wmti.to_operation_seq_num
7042 + DECODE(SIGN(wmti.to_intraoperation_step_type -
7043 WIP_CONSTANTS.RUN),1,1,0)
7044 AND (wmti.fm_operation_seq_num > wmti.to_operation_seq_num
7045 OR (wmti.fm_operation_seq_num = wmti.to_operation_seq_num
7046 AND wmti.to_intraoperation_step_type <= WIP_CONSTANTS.RUN
7047 AND wmti.fm_intraoperation_step_type > WIP_CONSTANTS.RUN))
7048 AND (wop1.count_point_type < WIP_CONSTANTS.NO_MANUAL
7049 OR (wop1.operation_seq_num = wmti.to_operation_seq_num
7050 /*fix bug 1834450*/ AND wop1.count_point_type < WIP_CONSTANTS.NO_MANUAL )
7051 OR (wop1.operation_seq_num = wmti.fm_operation_seq_num
7052 AND wmti.fm_intraoperation_step_type > WIP_CONSTANTS.RUN)))
7053 ))
7054 WHERE wop.rowid IN
7055 (SELECT wop2.rowid
7056 FROM wip_operations wop2,
7057 wip_move_txn_allocations wma2,
7058 wip_move_txn_interface wmti
7059 WHERE wop2.organization_id = wmti.organization_id
7060 AND wmti.group_id = p_gib.group_id
7061 AND (p_txn_id IS NULL OR wmti.transaction_id = p_txn_id)
7062 AND TRUNC(wmti.transaction_date) = TRUNC(p_gib.txn_date)
7063 AND wmti.process_phase = WIP_CONSTANTS.MOVE_PROC
7064 AND wmti.process_status = WIP_CONSTANTS.RUNNING
7065 AND wop2.organization_id = wmti.organization_id
7066 AND wop2.wip_entity_id = wmti.wip_entity_id
7067 AND wmti.organization_id = wma2.organization_id (+)
7068 AND wmti.transaction_id = wma2.transaction_id (+)
7069 AND NVL(wma2.repetitive_schedule_id,0) =
7070 NVL(wop2.repetitive_schedule_id,0)
7071 AND ((wop2.operation_seq_num >= wmti.fm_operation_seq_num
7072 + DECODE(SIGN(wmti.fm_intraoperation_step_type -
7073 WIP_CONSTANTS.RUN),1,1,0)
7074 AND wop2.operation_seq_num < wmti.to_operation_seq_num
7075 + DECODE(SIGN(wmti.to_intraoperation_step_type -
7076 WIP_CONSTANTS.RUN),1,1,0)
7077 AND (wmti.to_operation_seq_num > wmti.fm_operation_seq_num
7078 OR (wmti.to_operation_seq_num = wmti.fm_operation_seq_num
7079 AND wmti.fm_intraoperation_step_type <= WIP_CONSTANTS.RUN
7080 AND wmti.to_intraoperation_step_type > WIP_CONSTANTS.RUN))
7081 AND (wop2.count_point_type < WIP_CONSTANTS.NO_MANUAL
7082 OR wop2.operation_seq_num = wmti.fm_operation_seq_num
7083 OR (wop2.operation_seq_num = wmti.to_operation_seq_num
7084 AND wmti.to_intraoperation_step_type > WIP_CONSTANTS.RUN)))
7085 OR
7086 (wop2.operation_seq_num < wmti.fm_operation_seq_num
7087 + DECODE(SIGN(wmti.fm_intraoperation_step_type -
7088 WIP_CONSTANTS.RUN),1,1,0)
7089 AND wop2.operation_seq_num >= wmti.to_operation_seq_num
7090 + DECODE(SIGN(wmti.to_intraoperation_step_type -
7091 WIP_CONSTANTS.RUN),1,1,0)
7092 AND (wmti.fm_operation_seq_num > wmti.to_operation_seq_num
7093 OR (wmti.fm_operation_seq_num = wmti.to_operation_seq_num
7094 AND wmti.to_intraoperation_step_type <= WIP_CONSTANTS.RUN
7095 AND wmti.fm_intraoperation_step_type > WIP_CONSTANTS.RUN))
7096 AND (wop2.count_point_type < WIP_CONSTANTS.NO_MANUAL
7097 OR (wop2.operation_seq_num = wmti.to_operation_seq_num
7098 /*fix bug 1834450*/ AND wop2.count_point_type < WIP_CONSTANTS.NO_MANUAL)
7099 OR (wop2.operation_seq_num = wmti.fm_operation_seq_num
7100 AND wmti.fm_intraoperation_step_type > WIP_CONSTANTS.RUN)))
7101 ));
7102
7103 -- IF debug message level = 2, write statement below to log file
7104 IF (l_logLevel <= wip_constants.full_logging) THEN
7105 fnd_message.set_name('WIP', 'WIP_UPDATED_ROWS');
7106 fnd_message.set_token('ENTITY1', SQL%ROWCOUNT);
7107 fnd_message.set_token('ENTITY2', 'WIP_OPERATIONS');
7108 l_msg := fnd_message.get;
7109 wip_logger.log(p_msg => l_msg,
7110 x_returnStatus => l_returnStatus);
7111 END IF;
7112
7113 x_returnStatus := fnd_api.g_ret_sts_success;
7114
7115 -- write to the log file
7116 IF (l_logLevel <= wip_constants.trace_logging) THEN
7117 wip_logger.exitPoint(p_procName => 'wip_movProc_priv.update_complete_qty',
7118 p_procReturnStatus => x_returnStatus,
7119 p_msg => 'procedure complete',
7120 x_returnStatus => l_returnStatus);
7121 END IF;
7122
7123 EXCEPTION
7124 WHEN others THEN
7125 x_returnStatus := fnd_api.g_ret_sts_unexp_error;
7126 l_errMsg := 'unexpected error: ' || SQLERRM || 'SQLCODE = ' || SQLCODE;
7127
7128 IF (l_logLevel <= wip_constants.trace_logging) THEN
7129 wip_logger.exitPoint(p_procName=>'wip_movProc_priv.update_complete_qty',
7130 p_procReturnStatus => x_returnStatus,
7131 p_msg => l_errMsg,
7132 x_returnStatus => l_returnStatus);
7133 END IF;
7134 fnd_message.set_name('FND', 'FND_GENERIC_MESSAGE');
7135 fnd_message.set_token('MESSAGE', l_errMsg);
7136 fnd_msg_pub.add;
7137 END update_complete_qty;
7138
7139 /*****************************************************************************
7140 * This procedure is equivalent to wit_op_snapshot in wiltps5.ppc
7141 * This procedure is used to call Costing snapshot CSTACOSN.op_snapshot
7142 ****************************************************************************/
7143 PROCEDURE op_snapshot(p_mtl_temp_id IN NUMBER,
7144 x_returnStatus OUT NOCOPY VARCHAR2) IS
7145
7146 l_params wip_logger.param_tbl_t;
7147 l_returnStatus VARCHAR(1);
7148 l_returnValue NUMBER;
7149 l_msgCount NUMBER;
7150 l_errCode VARCHAR(240);
7151 l_errMsg VARCHAR(240);
7152 l_logLevel NUMBER := fnd_log.g_current_runtime_level;
7153
7154 BEGIN
7155 -- write parameter value to log file
7156 IF (l_logLevel <= wip_constants.trace_logging) THEN
7157 l_params(1).paramName := 'p_mtl_temp_id';
7158 l_params(1).paramValue := p_mtl_temp_id;
7159 wip_logger.entryPoint(p_procName =>'wip_movProc_priv.op_snapshot',
7160 p_params => l_params,
7161 x_returnStatus => l_returnStatus);
7162 END IF;
7163
7164 l_returnValue := CSTACOSN.op_snapshot
7165 (i_txn_temp_id => p_mtl_temp_id,
7166 err_num => l_msgCount,
7167 err_code => l_errCode,
7168 err_msg => l_errMsg);
7169 IF(l_returnValue <> 1) THEN
7170 l_errMsg := 'CSTACOSN.op_snapshot failed';
7171 raise fnd_api.g_exc_unexpected_error;
7172 END IF;
7173
7174 x_returnStatus := fnd_api.g_ret_sts_success;
7175
7176 -- write to the log file
7177 IF (l_logLevel <= wip_constants.trace_logging) THEN
7178 wip_logger.exitPoint(p_procName => 'wip_movProc_priv.op_snapshot',
7179 p_procReturnStatus => x_returnStatus,
7180 p_msg => 'procedure complete',
7181 x_returnStatus => l_returnStatus);
7182 END IF;
7183
7184 EXCEPTION
7185 WHEN fnd_api.g_exc_unexpected_error THEN
7186 x_returnStatus := fnd_api.g_ret_sts_unexp_error;
7187
7188 IF (l_logLevel <= wip_constants.trace_logging) THEN
7189 wip_logger.exitPoint(p_procName => 'wip_movProc_priv.op_snapshot',
7190 p_procReturnStatus => x_returnStatus,
7191 p_msg => l_errMsg,
7192 x_returnStatus => l_returnStatus);
7193 END IF;
7194
7195 fnd_message.set_name('CST', l_errCode);
7196 fnd_msg_pub.add;
7197
7198 WHEN others THEN
7199 x_returnStatus := fnd_api.g_ret_sts_unexp_error;
7200 l_errMsg := 'unexpected error: ' || SQLERRM || 'SQLCODE = ' || SQLCODE;
7201
7202 IF (l_logLevel <= wip_constants.trace_logging) THEN
7203 wip_logger.exitPoint(p_procName=>'wip_movProc_priv.op_snapshot',
7204 p_procReturnStatus => x_returnStatus,
7205 p_msg => l_errMsg,
7206 x_returnStatus => l_returnStatus);
7207 END IF;
7208 fnd_message.set_name('FND', 'FND_GENERIC_MESSAGE');
7209 fnd_message.set_token('MESSAGE', l_errMsg);
7210 fnd_msg_pub.add;
7211 END op_snapshot;
7212
7213 /*****************************************************************************
7214 * This procedure is equivalent to wit_snapshot_online in wiltps5.ppc
7215 * This procedure is used to call Costing snapshot
7216 ****************************************************************************/
7217 PROCEDURE snapshot_online(p_mtl_header_id IN NUMBER,
7218 p_org_id IN NUMBER,
7219 p_txn_type IN NUMBER,
7220 p_txn_type_id IN NUMBER,
7221 p_txn_action_id IN NUMBER,
7222 x_returnStatus OUT NOCOPY VARCHAR2) IS
7223
7224 CURSOR c_mmtt IS
7225 SELECT transaction_temp_id mtl_temp_id
7226 FROM mtl_material_transactions_temp
7227 WHERE transaction_header_id = p_mtl_header_id
7228 AND transaction_action_id = p_txn_action_id
7229 AND transaction_type_id = p_txn_type_id
7230 AND transaction_source_type_id = TPS_INV_JOB_OR_SCHED
7231 AND (wip_entity_type = WIP_CONSTANTS.DISCRETE
7232 OR wip_entity_type = WIP_CONSTANTS.LOTBASED); /*WSM */
7233
7234 l_params wip_logger.param_tbl_t;
7235 l_returnStatus VARCHAR(1);
7236 l_errMsg VARCHAR(240);
7237 l_pri_cost_method NUMBER;
7238 l_mandatory_scrap_flag NUMBER;
7239 l_mmtt c_mmtt%ROWTYPE;
7240 l_logLevel NUMBER := fnd_log.g_current_runtime_level;
7241
7242 BEGIN
7243 -- write parameter value to log file
7244 IF (l_logLevel <= wip_constants.trace_logging) THEN
7245 l_params(1).paramName := 'p_mtl_header_id';
7246 l_params(1).paramValue := p_mtl_header_id;
7247 l_params(2).paramName := 'p_org_id';
7248 l_params(2).paramValue := p_org_id;
7249 l_params(3).paramName := 'p_txn_type';
7250 l_params(3).paramValue := p_txn_type;
7251 l_params(4).paramName := 'p_txn_type_id';
7252 l_params(4).paramValue := p_txn_type_id;
7253 l_params(5).paramName := 'p_txn_action_id';
7254 l_params(5).paramValue := p_txn_action_id;
7255 wip_logger.entryPoint(p_procName =>'wip_movProc_priv.snapshot_online',
7256 p_params => l_params,
7257 x_returnStatus => l_returnStatus);
7258 END IF;
7259
7260 -- get primary cost method
7261 SELECT mp.primary_cost_method
7262 INTO l_pri_cost_method
7263 FROM mtl_parameters mp
7264 WHERE mp.organization_id = p_org_id;
7265
7266 -- get mandatoty scrap flag
7267 SELECT wp.mandatory_scrap_flag
7268 INTO l_mandatory_scrap_flag
7269 FROM wip_parameters wp
7270 WHERE wp.organization_id = p_org_id;
7271
7272 IF((l_pri_cost_method = WIP_CONSTANTS.COST_AVG OR
7273 l_pri_cost_method = WIP_CONSTANTS.COST_FIFO OR
7274 l_pri_cost_method = WIP_CONSTANTS.COST_LIFO)
7275 AND
7276 (p_txn_type = WIP_CONSTANTS.COMP_TXN OR
7277 p_txn_type = WIP_CONSTANTS.RET_TXN OR
7278 p_txn_type = WIP_CONSTANTS.MOVE_TXN)) THEN
7279
7280 -- Fix bug 2369642
7281 --(p_txn_type = WIP_CONSTANTS.MOVE_TXN AND
7282 -- l_mandatory_scrap_flag = WIP_CONSTANTS.YES))) THEN
7283
7284 UPDATE mtl_material_transactions_temp
7285 SET transaction_temp_id = mtl_material_transactions_s.nextval
7286 WHERE transaction_header_id = p_mtl_header_id
7287 AND transaction_temp_id IS NULL
7288 AND transaction_action_id = p_txn_action_id
7289 AND transaction_type_id = p_txn_type_id
7290 AND transaction_source_type_id = TPS_INV_JOB_OR_SCHED
7291 AND (wip_entity_type = WIP_CONSTANTS.DISCRETE
7292 OR wip_entity_type = WIP_CONSTANTS.LOTBASED); /*WSM*/
7293
7294 FOR l_mmtt IN c_mmtt LOOP
7295 op_snapshot(p_mtl_temp_id => l_mmtt.mtl_temp_id,
7296 x_returnStatus => x_returnStatus);
7297
7298 IF(x_returnStatus <> fnd_api.g_ret_sts_success) THEN
7299 l_errMsg := 'wip_movProc_priv.op_snapshot failed';
7300 raise fnd_api.g_exc_unexpected_error;
7301 END IF; -- check return status
7302 END LOOP; -- END for loop
7303 END IF;
7304
7305 x_returnStatus := fnd_api.g_ret_sts_success;
7306
7307 -- write to the log file
7308 IF (l_logLevel <= wip_constants.trace_logging) THEN
7309 wip_logger.exitPoint(p_procName => 'wip_movProc_priv.snapshot_online',
7310 p_procReturnStatus => x_returnStatus,
7311 p_msg => 'procedure complete',
7312 x_returnStatus => l_returnStatus);
7313 END IF;
7314
7315 EXCEPTION
7316 WHEN fnd_api.g_exc_unexpected_error THEN
7317 x_returnStatus := fnd_api.g_ret_sts_unexp_error;
7318
7319 IF (l_logLevel <= wip_constants.trace_logging) THEN
7320 wip_logger.exitPoint(p_procName => 'wip_movProc_priv.snapshot_online',
7321 p_procReturnStatus => x_returnStatus,
7322 p_msg => l_errMsg,
7323 x_returnStatus => l_returnStatus);
7324 END IF;
7325
7326 WHEN others THEN
7327 x_returnStatus := fnd_api.g_ret_sts_unexp_error;
7328 l_errMsg := 'unexpected error: ' || SQLERRM || 'SQLCODE = ' || SQLCODE;
7329
7330 IF (l_logLevel <= wip_constants.trace_logging) THEN
7331 wip_logger.exitPoint(p_procName=>'wip_movProc_priv.snapshot_online',
7332 p_procReturnStatus => x_returnStatus,
7333 p_msg => l_errMsg,
7334 x_returnStatus => l_returnStatus);
7335 END IF;
7336 fnd_message.set_name('FND', 'FND_GENERIC_MESSAGE');
7337 fnd_message.set_token('MESSAGE', l_errMsg);
7338 fnd_msg_pub.add;
7339 END snapshot_online;
7340
7341 /*****************************************************************************
7342 * This procedure is equivalent to wit_snapshot_background in wiltps5.ppc
7343 * This procedure is used to call Costing snapshot
7344 ****************************************************************************/
7345 PROCEDURE snapshot_background(p_group_id IN NUMBER,
7346 p_txn_id IN NUMBER := NULL,
7347 p_txn_date IN DATE,
7348 x_returnStatus OUT NOCOPY VARCHAR2) IS
7349
7350 /* Fixed Bug# 1480410 -
7351 Added source_code field in following cursor.
7352 --
7353 This is applicable for only Average Costing case
7354 --
7355
7356 The original condition was treating records inserted from the receiving
7357 transactions for osp item as records inserted from the open interface
7358 process and thus validating against cst_comp_snap_temp table and erroring
7359 out as there is no record. This fix would treat records inserted into
7360 wip_move_txn_interface by receiving transaction as created from the WIP
7361 and thus will create a record in the cst_comp_snap_temp.
7362 */
7363
7364 CURSOR c_txns IS
7365 SELECT wmti.transaction_id txn_id,
7366 mmtt.transaction_temp_id mtl_temp_id,
7367 DECODE(NVL(wmti.source_line_id,-1),
7368 -1, 2,
7369 1) load_from_interface,
7370 DECODE(NVL(wmti.source_code,'WIP'),
7371 'WIP', -1,
7372 'RCV', -1,
7373 1) source_code,
7374 MMTT.PRIMARY_QUANTITY primary_quantity
7375 FROM wip_move_txn_interface wmti,
7376 mtl_material_transactions_temp mmtt,
7377 mtl_parameters mp
7378 WHERE wmti.group_id = p_group_id
7379 AND (p_txn_id IS NULL OR wmti.transaction_id = p_txn_id)
7380 AND TRUNC(wmti.transaction_date) = TRUNC(p_txn_date)
7381 AND wmti.process_phase = WIP_CONSTANTS.MOVE_PROC
7382 AND wmti.process_status = WIP_CONSTANTS.RUNNING
7383 AND mmtt.move_transaction_id = wmti.transaction_id
7384 /* Improve performance */
7385 AND mmtt.organization_id = wmti.organization_id
7386 AND mmtt.transaction_source_id = wmti.wip_entity_id
7387 AND mmtt.transaction_source_type_id = TPS_INV_JOB_OR_SCHED
7388 /* End Improve performance */
7389 AND mmtt.wip_entity_type IN (WIP_CONSTANTS.DISCRETE,
7390 WIP_CONSTANTS.LOTBASED) /*WSM */
7391 -- Fixed bug2515712 (do not insert component related record)
7392 AND mmtt.transaction_action_id IN (WIP_CONSTANTS.SCRASSY_ACTION,
7393 WIP_CONSTANTS.RETASSY_ACTION,
7394 WIP_CONSTANTS.CPLASSY_ACTION)
7395 AND mp.organization_id = wmti.organization_id
7396 AND mp.primary_cost_method IN (WIP_CONSTANTS.COST_AVG,
7397 WIP_CONSTANTS.COST_FIFO,
7398 WIP_CONSTANTS.COST_LIFO)
7399 AND (((wmti.fm_intraoperation_step_type = WIP_CONSTANTS.SCRAP
7400 OR wmti.to_intraoperation_step_type = WIP_CONSTANTS.SCRAP)
7401 AND wmti.scrap_account_id IS NOT NULL)
7402 -- Fix bug 2369642
7403 -- AND wp.mandatory_scrap_flag = WIP_CONSTANTS.YES)
7404 OR
7405 (wmti.transaction_type IN (WIP_CONSTANTS.COMP_TXN,
7406 WIP_CONSTANTS.RET_TXN)));
7407
7408 l_params wip_logger.param_tbl_t;
7409 l_returnStatus VARCHAR(1);
7410 l_errMsg VARCHAR(240);
7411 l_errCode VARCHAR(240);
7412 l_txns c_txns%ROWTYPE;
7413 l_num_snapshot NUMBER;
7414 l_returnValue NUMBER;
7415 l_interface_table NUMBER;
7416 l_msgCount NUMBER;
7417 l_logLevel NUMBER := fnd_log.g_current_runtime_level;
7418
7419 BEGIN
7420 -- write parameter value to log file
7421 IF (l_logLevel <= wip_constants.trace_logging) THEN
7422 l_params(1).paramName := 'p_group_id';
7423 l_params(1).paramValue := p_group_id;
7424 l_params(2).paramName := 'p_txn_date';
7425 l_params(2).paramValue := p_txn_date;
7426 l_params(3).paramName := 'p_txn_id';
7427 l_params(3).paramValue := p_txn_id;
7428 wip_logger.entryPoint(p_procName =>'wip_movProc_priv.snapshot_background',
7429 p_params => l_params,
7430 x_returnStatus => l_returnStatus);
7431 END IF;
7432
7433 -- check for snapshot transactions through the interface
7434 SELECT COUNT(*)
7435 INTO l_num_snapshot
7436 FROM wip_move_txn_interface wmti,
7437 mtl_parameters mp
7438 -- wip_parameters wp
7439 WHERE wmti.group_id = p_group_id
7440 AND wmti.process_phase = WIP_CONSTANTS.MOVE_PROC
7441 AND wmti.process_status = WIP_CONSTANTS.RUNNING
7442 AND wmti.organization_id = mp.organization_id
7443 AND mp.primary_cost_method IN (WIP_CONSTANTS.COST_AVG,
7444 WIP_CONSTANTS.COST_FIFO,
7445 WIP_CONSTANTS.COST_LIFO)
7446 --AND wp.organization_id = wmti.organization_id
7447 AND (((wmti.fm_intraoperation_step_type = WIP_CONSTANTS.SCRAP
7448 OR wmti.to_intraoperation_step_type = WIP_CONSTANTS.SCRAP)
7449 AND wmti.scrap_account_id IS NOT NULL)
7450 -- AND wp.mandatory_scrap_flag = WIP_CONSTANTS.YES)
7451 OR
7452 (wmti.transaction_type IN (WIP_CONSTANTS.COMP_TXN,
7453 WIP_CONSTANTS.RET_TXN)));
7454
7455 IF(l_num_snapshot = 0) THEN
7456 GOTO END_txn;
7457 END IF;
7458
7459 UPDATE mtl_material_transactions_temp mmtt1
7460 SET mmtt1.transaction_temp_id = mtl_material_transactions_s.nextval
7461 WHERE mmtt1.rowid IN
7462 (SELECT mmtt1.rowid
7463 FROM wip_move_txn_interface wmti,
7464 -- wip_parameters wp,
7465 mtl_parameters mp,
7466 mtl_material_transactions_temp mmtt2
7467 WHERE wmti.group_id = p_group_id
7468 AND TRUNC(wmti.transaction_date) = TRUNC(p_txn_date)
7469 AND wmti.process_phase = WIP_CONSTANTS.MOVE_PROC
7470 AND wmti.process_status = WIP_CONSTANTS.RUNNING
7471 AND mmtt2.organization_id = wmti.organization_id
7472 AND mmtt2.transaction_source_id = wmti.wip_entity_id
7473 AND mmtt2.transaction_source_type_id = TPS_INV_JOB_OR_SCHED
7474 -- AND wp.organization_id = wmti.organization_id
7475 AND mp.organization_id = wmti.organization_id
7476 AND mp.primary_cost_method IN (WIP_CONSTANTS.COST_AVG,
7477 WIP_CONSTANTS.COST_FIFO,
7478 WIP_CONSTANTS.COST_LIFO)
7479 AND (((wmti.fm_intraoperation_step_type = WIP_CONSTANTS.SCRAP
7480 OR wmti.to_intraoperation_step_type = WIP_CONSTANTS.SCRAP)
7481 AND wmti.scrap_account_id IS NOT NULL)
7482 -- AND wp.mandatory_scrap_flag = WIP_CONSTANTS.YES)
7483 OR
7484 (wmti.transaction_type IN (WIP_CONSTANTS.COMP_TXN,
7485 WIP_CONSTANTS.RET_TXN))))
7486 AND mmtt1.transaction_source_type_id = TPS_INV_JOB_OR_SCHED
7487 AND mmtt1.transaction_temp_id IS NULL;
7488
7489 l_interface_table := 2; -- MOVE_TXN_INTERFACE
7490
7491 FOR l_txns IN c_txns LOOP
7492 IF(l_txns.load_from_interface = 1 AND
7493 l_txns.source_code = 1) THEN
7494 l_returnValue := CSTPACMS.validate_move_snap_to_temp
7495 (l_txn_interface_id => l_txns.txn_id,
7496 l_txn_temp_id => l_txns.mtl_temp_id,
7497 l_interface_table => l_interface_table,
7498 l_primary_quantity => l_txns.primary_quantity,
7499 err_num => l_msgCount,
7500 err_code => l_errCode,
7501 err_msg => l_errMsg);
7502
7503 IF(l_returnValue <> 1) THEN
7504 fnd_message.set_name('CST', l_errCode);
7505 fnd_msg_pub.add;
7506 l_errMsg := 'CSTACOSN.validate_move_snap_to_temp failed';
7507 raise fnd_api.g_exc_unexpected_error;
7508 END IF; -- check return status
7509 ELSE
7510 op_snapshot(p_mtl_temp_id => l_txns.mtl_temp_id,
7511 x_returnStatus => x_returnStatus);
7512
7513 IF(x_returnStatus <> fnd_api.g_ret_sts_success) THEN
7514 l_errMsg := 'wip_movProc_priv.op_snapshot failed';
7515 raise fnd_api.g_exc_unexpected_error;
7516 END IF; -- check return status
7517 END IF; -- check load from interface and source code
7518 END LOOP;
7519
7520 <<END_txn>>
7521 x_returnStatus := fnd_api.g_ret_sts_success;
7522
7523 -- write to the log file
7524 IF (l_logLevel <= wip_constants.trace_logging) THEN
7525 wip_logger.exitPoint(p_procName => 'wip_movProc_priv.snapshot_background',
7526 p_procReturnStatus => x_returnStatus,
7527 p_msg => 'procedure complete',
7528 x_returnStatus => l_returnStatus);
7529 END IF;
7530
7531 EXCEPTION
7532 WHEN fnd_api.g_exc_unexpected_error THEN
7533 x_returnStatus := fnd_api.g_ret_sts_unexp_error;
7534
7535 IF (l_logLevel <= wip_constants.trace_logging) THEN
7536 wip_logger.exitPoint(p_procName =>'wip_movProc_priv.snapshot_background',
7537 p_procReturnStatus => x_returnStatus,
7538 p_msg => l_errMsg,
7539 x_returnStatus => l_returnStatus);
7540 END IF;
7541
7542 WHEN others THEN
7543 x_returnStatus := fnd_api.g_ret_sts_unexp_error;
7544 l_errMsg := 'unexpected error: ' || SQLERRM || 'SQLCODE = ' || SQLCODE;
7545
7546 IF (l_logLevel <= wip_constants.trace_logging) THEN
7547 wip_logger.exitPoint(p_procName=>'wip_movProc_priv.snapshot_background',
7548 p_procReturnStatus => x_returnStatus,
7549 p_msg => l_errMsg,
7550 x_returnStatus => l_returnStatus);
7551 END IF;
7552 fnd_message.set_name('FND', 'FND_GENERIC_MESSAGE');
7553 fnd_message.set_token('MESSAGE', l_errMsg);
7554 fnd_msg_pub.add;
7555 END snapshot_background;
7556
7557 /*****************************************************************************
7558 * This procedure will be used to update quantity_completed, and take snapshot
7559 * of wip_operations if applicable(LIFO, FIFO, and average costing)
7560 ****************************************************************************/
7561 PROCEDURE update_wo_and_snapshot(p_gib IN group_rec_t,
7562 x_returnStatus OUT NOCOPY VARCHAR2) IS
7563 CURSOR c_move_rec IS
7564 SELECT wmti.transaction_id txn_id
7565 FROM wip_move_txn_interface wmti
7566 WHERE wmti.group_id = p_gib.group_id
7567 AND TRUNC(wmti.transaction_date) = TRUNC(p_gib.txn_date)
7568 AND wmti.process_phase = WIP_CONSTANTS.MOVE_PROC
7569 AND wmti.process_status = WIP_CONSTANTS.RUNNING
7570 ORDER BY wmti.transaction_date;
7571
7572 l_move_rec c_move_rec%ROWTYPE;
7573 l_returnStatus VARCHAR(1);
7574 l_errMsg VARCHAR(240);
7575 l_params wip_logger.param_tbl_t;
7576 l_logLevel NUMBER := fnd_log.g_current_runtime_level;
7577 BEGIN
7578 IF (l_logLevel <= wip_constants.trace_logging) THEN
7579 l_params(1).paramName := 'p_gib.group_id';
7580 l_params(1).paramValue := p_gib.group_id;
7581 l_params(2).paramName := 'p_gib.txn_date';
7582 l_params(2).paramValue := p_gib.txn_date;
7583 l_params(3).paramName := 'p_gib.seq_move';
7584 l_params(3).paramValue := p_gib.seq_move;
7585 wip_logger.entryPoint(p_procName =>'wip_movProc_priv.update_wo_and_snapshot',
7586 p_params => l_params,
7587 x_returnStatus => l_returnStatus);
7588 END IF;
7589
7590 IF(p_gib.seq_move = WIP_CONSTANTS.YES) THEN
7591 -- update quantity_completed and take snapshot one record at a time
7592 FOR l_move_rec IN c_move_rec LOOP
7593 update_complete_qty(p_gib => p_gib,
7594 p_txn_id => l_move_rec.txn_id,
7595 x_returnStatus => x_returnStatus);
7596
7597 IF(x_returnStatus <> fnd_api.g_ret_sts_success) THEN
7598 l_errMsg := 'wip_movProc_priv.update_complete_qty failed';
7599 raise fnd_api.g_exc_unexpected_error;
7600 END IF; -- check return status
7601
7602 snapshot_background(p_group_id => p_gib.group_id,
7603 p_txn_id => l_move_rec.txn_id,
7604 p_txn_date => p_gib.txn_date,
7605 x_returnStatus => x_returnStatus);
7606
7607 IF(x_returnStatus <> fnd_api.g_ret_sts_success) THEN
7608 l_errMsg := 'wip_movProc_priv.snapshot_background failed';
7609 raise fnd_api.g_exc_unexpected_error;
7610 END IF; -- check return status
7611 END LOOP;
7612 ELSE
7613 -- update quantity_completed and take snapshot for the whole group
7614 update_complete_qty(p_gib => p_gib,
7615 x_returnStatus => x_returnStatus);
7616
7617 IF(x_returnStatus <> fnd_api.g_ret_sts_success) THEN
7618 l_errMsg := 'wip_movProc_priv.update_complete_qty failed';
7619 raise fnd_api.g_exc_unexpected_error;
7620 END IF; -- check return status
7621
7622 snapshot_background(p_group_id => p_gib.group_id,
7623 p_txn_date => p_gib.txn_date,
7624 x_returnStatus => x_returnStatus);
7625
7626 IF(x_returnStatus <> fnd_api.g_ret_sts_success) THEN
7627 l_errMsg := 'wip_movProc_priv.snapshot_background failed';
7628 raise fnd_api.g_exc_unexpected_error;
7629 END IF; -- check return status
7630 END IF;
7631
7632 x_returnStatus := fnd_api.g_ret_sts_success;
7633 -- write to the log file
7634 IF (l_logLevel <= wip_constants.trace_logging) THEN
7635 wip_logger.exitPoint(p_procName =>'wip_movProc_priv.update_wo_and_snapshot',
7636 p_procReturnStatus => x_returnStatus,
7637 p_msg => 'procedure complete',
7638 x_returnStatus => l_returnStatus);
7639 END IF;
7640 EXCEPTION
7641 WHEN fnd_api.g_exc_unexpected_error THEN
7642 x_returnStatus := fnd_api.g_ret_sts_unexp_error;
7643 IF (l_logLevel <= wip_constants.trace_logging) THEN
7644 wip_logger.exitPoint(p_procName =>'wip_movProc_priv.update_wo_and_snapshot',
7645 p_procReturnStatus => x_returnStatus,
7646 p_msg => l_errMsg,
7647 x_returnStatus => l_returnStatus);
7648 END IF;
7649
7650 WHEN others THEN
7651 x_returnStatus := fnd_api.g_ret_sts_unexp_error;
7652 l_errMsg := 'unexpected error: ' || SQLERRM || 'SQLCODE = ' || SQLCODE;
7653
7654 IF (l_logLevel <= wip_constants.trace_logging) THEN
7655 wip_logger.exitPoint(p_procName=>'wip_movProc_priv.update_wo_and_snapshot',
7656 p_procReturnStatus => x_returnStatus,
7657 p_msg => l_errMsg,
7658 x_returnStatus => l_returnStatus);
7659 END IF;
7660 fnd_message.set_name('FND', 'FND_GENERIC_MESSAGE');
7661 fnd_message.set_token('MESSAGE', l_errMsg);
7662 fnd_msg_pub.add;
7663 END update_wo_and_snapshot;
7664
7665 /*****************************************************************************
7666 * This procedure is equivalent to witpsst_scrap_txns in wiltps5.ppc
7667 * This procedure is used to update scrap quantity in WIP_DISCRETE_JOBS for
7668 * discrete and OSFM jobs, and WIP_REPETITIVE_SCHEDULES for repetitive
7669 * schedules.
7670 * This procedure also insert into MTL_MATERIAL_TRANSACTIONS_TEMP for costing
7671 * purpose IF the user provide scrap account.
7672 ****************************************************************************/
7673 PROCEDURE scrap_txns(p_gib IN OUT NOCOPY group_rec_t,
7674 x_returnStatus OUT NOCOPY VARCHAR2) IS
7675
7676 CURSOR c_mtl_alloc IS
7677 SELECT wmti.transaction_id txn_id,
7678 wmti.organization_id org_id,
7679 mmtt.material_allocation_temp_id alloc_id
7680 FROM wip_move_txn_interface wmti,
7681 mtl_material_transactions_temp mmtt
7682 WHERE wmti.transaction_id = mmtt.move_transaction_id
7683 /* Improve performance */
7684 AND mmtt.organization_id = wmti.organization_id
7685 AND mmtt.transaction_source_id = wmti.wip_entity_id
7686 AND mmtt.transaction_source_type_id = TPS_INV_JOB_OR_SCHED
7687 /* End Improve performance */
7688 AND wmti.group_id = p_gib.group_id
7689 AND TRUNC(wmti.transaction_date) = TRUNC(p_gib.txn_date)
7690 AND wmti.process_phase = WIP_CONSTANTS.MOVE_PROC
7691 AND wmti.process_status = WIP_CONSTANTS.RUNNING
7692 AND wmti.entity_type = WIP_CONSTANTS.REPETITIVE
7693 AND wmti.scrap_account_id IS NOT NULL
7694 AND (wmti.fm_intraoperation_step_type = WIP_CONSTANTS.SCRAP OR
7695 wmti.to_intraoperation_step_type = WIP_CONSTANTS.SCRAP);
7696
7697 CURSOR c_update_po IS
7698 SELECT wmti.wip_entity_id job_id,
7699 DECODE(wmti.entity_type,
7700 WIP_CONSTANTS.REPETITIVE, wmta.repetitive_schedule_id,
7701 NULL) rep_id,
7702 wmti.organization_id org_id,
7703 DECODE (wmti.fm_intraoperation_step_type,
7704 WIP_CONSTANTS.SCRAP,DECODE(wmti.entity_type,
7705 WIP_CONSTANTS.REPETITIVE,wmta.primary_quantity,
7706 wmti.primary_quantity),
7707 -1 * DECODE(wmti.entity_type,
7708 WIP_CONSTANTS.REPETITIVE, wmta.primary_quantity,
7709 wmti.primary_quantity)) changed_qty,
7710 GREATEST(wmti.fm_operation_seq_num, wmti.to_operation_seq_num) fm_op
7711 FROM wip_move_txn_interface wmti,
7712 wip_move_txn_allocations wmta,
7713 wip_parameters mp
7714 WHERE wmti.transaction_id = wmta.transaction_id (+)
7715 AND wmti.organization_id = wmta.organization_id (+)
7716 AND wmti.group_id = p_gib.group_id
7717 AND TRUNC(wmti.transaction_date) = TRUNC(p_gib.txn_date)
7718 AND wmti.process_phase = WIP_CONSTANTS.MOVE_PROC
7719 AND wmti.process_status = WIP_CONSTANTS.RUNNING
7720 AND (wmti.fm_intraoperation_step_type = WIP_CONSTANTS.SCRAP OR
7721 wmti.to_intraoperation_step_type = WIP_CONSTANTS.SCRAP)
7722 AND NOT(wmti.fm_intraoperation_step_type = WIP_CONSTANTS.SCRAP AND
7723 wmti.to_intraoperation_step_type = WIP_CONSTANTS.SCRAP)
7724 AND mp.organization_id = wmti.organization_id
7725 AND mp.propagate_job_change_to_po = WIP_CONSTANTS.YES;
7726
7727
7728 l_params wip_logger.param_tbl_t;
7729 l_mtl_alloc c_mtl_alloc%ROWTYPE;
7730 l_returnStatus VARCHAR(1);
7731 l_msg_count NUMBER;
7732 l_msg_data VARCHAR2(2000);
7733 l_errMsg VARCHAR(240);
7734 l_msg VARCHAR(2000);
7735 l_scrap_flag NUMBER := -1;
7736 l_step NUMBER;
7737 l_transaction_mode NUMBER;
7738 l_move move_profile_rec_t;
7739 l_logLevel NUMBER := fnd_log.g_current_runtime_level;
7740 l_update_po c_update_po%ROWTYPE;
7741 BEGIN
7742 l_move := p_gib.move_profile;
7743
7744 -- write parameter value to log file
7745 IF (l_logLevel <= wip_constants.trace_logging) THEN
7746 l_params(1).paramName := 'p_group_id';
7747 l_params(1).paramValue := p_gib.group_id;
7748 l_params(2).paramName := 'p_txn_date';
7749 l_params(2).paramValue := p_gib.txn_date;
7750 l_params(3).paramName := 'org_id';
7751 l_params(3).paramValue := l_move.org_id;
7752 l_params(4).paramName := 'wip_id';
7753 l_params(4).paramValue := l_move.wip_id;
7754 l_params(5).paramName := 'fmOp';
7755 l_params(5).paramValue := l_move.fmOp;
7756 l_params(6).paramName := 'fmStep';
7757 l_params(6).paramValue := l_move.fmStep;
7758 l_params(7).paramName := 'toOp';
7759 l_params(7).paramValue := l_move.toOp;
7760 l_params(8).paramName := 'toStep';
7761 l_params(8).paramValue := l_move.toStep;
7762 l_params(9).paramName := 'scrapTxn';
7763 l_params(9).paramValue := l_move.scrapTxn;
7764 l_params(10).paramName := 'easyComplete';
7765 l_params(10).paramValue := l_move.easyComplete;
7766 l_params(11).paramName := 'easyReturn';
7767 l_params(11).paramValue := l_move.easyReturn;
7768 l_params(12).paramName := 'jobTxn';
7769 l_params(12).paramValue := l_move.jobTxn;
7770 l_params(13).paramName := 'scheTxn';
7771 l_params(13).paramValue := l_move.scheTxn;
7772 l_params(14).paramName := 'rsrcItem';
7773 l_params(14).paramValue := l_move.rsrcItem;
7774 l_params(15).paramName := 'rsrcLot';
7775 l_params(15).paramValue := l_move.rsrcLot;
7776 l_params(16).paramName := 'poReqItem';
7777 l_params(16).paramValue := l_move.poReqItem;
7778 l_params(17).paramName := 'poRegLot';
7779 l_params(17).paramValue := l_move.poReqLot;
7780 l_params(18).paramName := 'p_mtl_header_id';
7781 l_params(18).paramValue := p_gib.mtl_header_id;
7782 l_params(19).paramName := 'p_move_mode';
7783 l_params(19).paramValue := p_gib.move_mode;
7784 l_params(20).paramName := 'p_mtl_mode';
7785 l_params(20).paramValue := p_gib.mtl_mode;
7786 wip_logger.entryPoint(p_procName =>'wip_movProc_priv.scrap_txns',
7787 p_params => l_params,
7788 x_returnStatus => l_returnStatus);
7789 END IF;
7790
7791 -- Any scrap transaction?
7792 IF(l_move.scrapTxn <> WIP_CONSTANTS.YES AND
7793 l_move.scrapTxn <> WIP_CONSTANTS.NO) THEN -- Indeterminate
7794
7795 SELECT COUNT(1)
7796 INTO l_scrap_flag
7797 FROM wip_move_txn_interface
7798 WHERE group_id = p_gib.group_id
7799 AND TRUNC(transaction_date) = TRUNC(p_gib.txn_date)
7800 AND process_phase = WIP_CONSTANTS.MOVE_PROC
7801 AND process_status = WIP_CONSTANTS.RUNNING
7802 AND (fm_intraoperation_step_type = WIP_CONSTANTS.SCRAP
7803 OR to_intraoperation_step_type = WIP_CONSTANTS.SCRAP);
7804
7805 IF (l_scrap_flag > 0) THEN
7806 l_move.scrapTxn := WIP_CONSTANTS.YES;
7807 ELSE
7808 l_move.scrapTxn := WIP_CONSTANTS.NO;
7809 END IF;
7810
7811 END IF; -- scrap txn indeterminate
7812
7813 -- Scrap transaction
7814 IF(l_move.scrapTxn = WIP_CONSTANTS.YES) THEN
7815 /*------------------------------------------------------------+
7816 | Update scrap quantity for discrete jobs
7817 +------------------------------------------------------------*/
7818 IF(l_move.jobTxn = WIP_CONSTANTS.YES) THEN
7819
7820 /** 3050846 **/
7821 wip_so_reservations.scrap_txn_relieve_rsv ( p_group_id => p_gib.group_id,
7822 x_return_status => l_returnstatus,
7823 x_msg_count => l_msg_count,
7824 x_msg_data => l_msg_data
7825 );
7826 IF (l_returnstatus <> fnd_api.g_ret_sts_success) THEN
7827 IF (l_returnstatus = fnd_api.g_ret_sts_error) THEN
7828 fnd_msg_pub.count_and_get(
7829 p_encoded => fnd_api.g_false,
7830 p_count => l_msg_count,
7831 p_data => l_errmsg);
7832 RAISE fnd_api.g_exc_error;
7833 ELSE
7834 fnd_msg_pub.count_and_get(
7835 p_encoded => fnd_api.g_false,
7836 p_count => l_msg_count,
7837 p_data => l_errmsg);
7838
7839 RAISE fnd_api.g_exc_unexpected_error;
7840 END IF;
7841 END IF;
7842
7843
7844
7845 /** 3050846 **/
7846
7847 UPDATE wip_discrete_jobs wdj
7848 SET (quantity_scrapped,
7849 last_updated_by,
7850 last_update_date,
7851 last_update_login,
7852 request_id,
7853 program_application_id,
7854 program_id,
7855 program_update_date
7856 ) =
7857 (SELECT wdj.quantity_scrapped -- quantity_scrapped
7858 + SUM(DECODE(wmti.to_intraoperation_step_type,
7859 WIP_CONSTANTS.SCRAP, wmti.primary_quantity,0)
7860 - DECODE(wmti.fm_intraoperation_step_type,
7861 WIP_CONSTANTS.SCRAP,wmti.primary_quantity,0)),
7862 MAX(wmti.last_updated_by),
7863 SYSDATE, -- last_update_date
7864 DECODE(p_gib.login_id,-1,NULL,p_gib.login_id),
7865 DECODE(p_gib.request_id,-1,NULL,p_gib.request_id),
7866 DECODE(p_gib.application_id,-1,NULL,p_gib.application_id),
7867 DECODE(p_gib.program_id,-1,NULL,p_gib.program_id),
7868 DECODE(p_gib.request_id,
7869 -1,NULL,SYSDATE)-- program_update_date
7870 FROM wip_discrete_jobs wdj1, wip_move_txn_interface wmti
7871 WHERE wdj1.rowid = wdj.rowid
7872 AND wmti.group_id = p_gib.group_id
7873 AND TRUNC(wmti.transaction_date) = TRUNC(p_gib.txn_date)
7874 AND wmti.process_phase = WIP_CONSTANTS.MOVE_PROC
7875 AND wmti.process_status = WIP_CONSTANTS.RUNNING
7876 AND wmti.organization_id = wdj1.organization_id
7877 AND wmti.wip_entity_id = wdj1.wip_entity_id
7878 AND (wmti.entity_type = WIP_CONSTANTS.DISCRETE
7879 OR wmti.entity_type = WIP_CONSTANTS.LOTBASED)/*WSM */
7880 AND (wmti.fm_intraoperation_step_type = WIP_CONSTANTS.SCRAP
7881 OR wmti.to_intraoperation_step_type = WIP_CONSTANTS.SCRAP)
7882 )
7883 WHERE wdj.rowid IN
7884 (SELECT wdj2.rowid
7885 FROM wip_discrete_jobs wdj2,
7886 wip_move_txn_interface wmti
7887 WHERE wmti.group_id = p_gib.group_id
7888 AND TRUNC(wmti.transaction_date) = TRUNC(p_gib.txn_date)
7889 AND wmti.process_phase = WIP_CONSTANTS.MOVE_PROC
7890 AND wmti.process_status = WIP_CONSTANTS.RUNNING
7891 AND wmti.organization_id = wdj2.organization_id
7892 AND wmti.wip_entity_id = wdj2.wip_entity_id
7893 AND (wmti.entity_type = WIP_CONSTANTS.DISCRETE
7894 OR wmti.entity_type = WIP_CONSTANTS.LOTBASED)/* WSM*/
7895 AND (wmti.fm_intraoperation_step_type = WIP_CONSTANTS.SCRAP
7896 OR wmti.to_intraoperation_step_type = WIP_CONSTANTS.SCRAP)
7897 );
7898 /* Now we will also update the column status_type to "Complete" IF
7899 these scrap completions will finish off the remaining quantity to be
7900 completed, or update it to "Released" IF moving these assemblies back
7901 from Scrap will re-release a completed job. We will also update the
7902 date_completed IF necessary. See wiltct.ppc for a similar change.
7903 rkaiser, 7/15/98 */
7904
7905 UPDATE wip_discrete_jobs wdj
7906 SET (status_type,
7907 date_completed
7908 ) =
7909 (SELECT WIP_CONSTANTS.COMP_CHRG, -- status_type
7910 SYSDATE -- date_completed
7911 FROM DUAL)
7912 WHERE wdj.rowid IN
7913 (SELECT wdj2.rowid
7914 FROM wip_discrete_jobs wdj2,
7915 wip_move_txn_interface wmti
7916 WHERE wmti.group_id = p_gib.group_id
7917 AND TRUNC(wmti.transaction_date) = TRUNC(p_gib.txn_date)
7918 AND wmti.process_phase = WIP_CONSTANTS.MOVE_PROC
7919 AND wmti.process_status = WIP_CONSTANTS.RUNNING
7920 AND wmti.organization_id = wdj2.organization_id
7921 AND wmti.wip_entity_id = wdj2.wip_entity_id
7922 AND (wmti.entity_type = WIP_CONSTANTS.DISCRETE
7923 OR wmti.entity_type = WIP_CONSTANTS.LOTBASED)/*WSM */
7924 AND (wmti.fm_intraoperation_step_type = WIP_CONSTANTS.SCRAP
7925 OR wmti.to_intraoperation_step_type = WIP_CONSTANTS.SCRAP)
7926 AND (wdj2.start_quantity - wdj2.quantity_completed -
7927 wdj2.quantity_scrapped) <= 0);
7928
7929 UPDATE wip_discrete_jobs wdj
7930 SET status_type = WIP_CONSTANTS.RELEASED,
7931 /*bug 3933240 -> nullify date_completed while changing the status of job to
7932 released */
7933 date_completed = null
7934 WHERE wdj.rowid IN
7935 (SELECT wdj2.rowid
7936 FROM wip_discrete_jobs wdj2,
7937 wip_move_txn_interface wmti
7938 WHERE wmti.group_id = p_gib.group_id
7939 AND TRUNC(wmti.transaction_date) = TRUNC(p_gib.txn_date)
7940 AND wmti.process_phase = WIP_CONSTANTS.MOVE_PROC
7941 AND wmti.process_status = WIP_CONSTANTS.RUNNING
7942 AND wmti.organization_id = wdj2.organization_id
7943 AND wmti.wip_entity_id = wdj2.wip_entity_id
7944 AND (wmti.entity_type = WIP_CONSTANTS.DISCRETE
7945 OR wmti.entity_type = WIP_CONSTANTS.LOTBASED)/* WSM*/
7946 AND (wmti.fm_intraoperation_step_type = WIP_CONSTANTS.SCRAP
7947 OR wmti.to_intraoperation_step_type = WIP_CONSTANTS.SCRAP)
7948 AND (wdj2.start_quantity - wdj2.quantity_completed -
7949 wdj2.quantity_scrapped) > 0);
7950
7951 -- IF debug message level = 2, write statement below to log file
7952 IF (l_logLevel <= wip_constants.full_logging) THEN
7953 fnd_message.set_name('WIP', 'WIP_UPDATED_ROWS');
7954 fnd_message.set_token('ENTITY1', SQL%ROWCOUNT);
7955 fnd_message.set_token('ENTITY2', 'WIP_DISCRETE_JOBS');
7956 l_msg := fnd_message.get;
7957 wip_logger.log(p_msg => l_msg,
7958 x_returnStatus => l_returnStatus);
7959 END IF;
7960 END IF; -- END job transactions
7961
7962 /*------------------------------------------------------------+
7963 | Update scrap quantity for repetitive schedule
7964 +------------------------------------------------------------*/
7965 IF(l_move.scheTxn = WIP_CONSTANTS.YES) THEN
7966 /*------------------------------------------------------------------+
7967 | For repetitive schedules, we do not set the date_closed, since this
7968 | is only done manually, via the form. It is not set automatically for
7969 | regular completions, so we will not set it here. rkaiser
7970 +------------------------------------------------------------------*/
7971 UPDATE wip_repetitive_schedules wrs
7972 SET (status_type) =
7973 (SELECT DECODE(SIGN(
7974 (wrs.daily_production_rate * wrs.processing_work_days -
7975 wrs.quantity_completed) -
7976 SUM(NVL(wo.quantity_scrapped, 0))),
7977 1, WIP_CONSTANTS.RELEASED,
7978 WIP_CONSTANTS.COMP_CHRG)
7979 FROM wip_operations wo
7980 WHERE wo.organization_id = wrs.organization_id
7981 AND wo.repetitive_schedule_id = wrs.repetitive_schedule_id)
7982 WHERE wrs.status_type IN (WIP_CONSTANTS.RELEASED,
7983 WIP_CONSTANTS.COMP_CHRG)
7984 AND wrs.rowid IN
7985 (SELECT wrs2.rowid
7986 FROM wip_repetitive_schedules wrs2,
7987 wip_move_txn_interface wmti
7988 WHERE wmti.group_id = p_gib.group_id
7989 AND TRUNC(wmti.transaction_date) = TRUNC(p_gib.txn_date)
7990 AND wmti.process_phase = WIP_CONSTANTS.MOVE_PROC
7991 AND wmti.process_status = WIP_CONSTANTS.RUNNING
7992 AND wmti.entity_type = WIP_CONSTANTS.REPETITIVE
7993 AND wrs2.wip_entity_id = wmti.wip_entity_id
7994 AND wrs2.organization_id = wmti.organization_id
7995 AND wrs2.line_id = wmti.line_id
7996 AND (wmti.fm_intraoperation_step_type = WIP_CONSTANTS.SCRAP
7997 OR wmti.to_intraoperation_step_type = WIP_CONSTANTS.SCRAP));
7998
7999 -- IF debug message level = 2, write statement below to log file
8000 IF (l_logLevel <= wip_constants.full_logging) THEN
8001 fnd_message.set_name('WIP', 'WIP_UPDATED_ROWS');
8002 fnd_message.set_token('ENTITY1', SQL%ROWCOUNT);
8003 fnd_message.set_token('ENTITY2', 'WIP_REPETITIVE_SCHEDULES');
8004 l_msg := fnd_message.get;
8005 wip_logger.log(p_msg => l_msg,
8006 x_returnStatus => l_returnStatus);
8007 END IF;
8008 END IF; -- END repetitive schedule transactions
8009
8010 /* Generate a mtl txn header id IF one has not already been generated */
8011 IF(p_gib.mtl_header_id IS NULL OR
8012 p_gib.mtl_header_id = -1) THEN
8013 SELECT mtl_material_transactions_s.nextval
8014 INTO p_gib.mtl_header_id
8015 FROM DUAL;
8016 END IF;
8017
8018 -- initialize transaction mode
8019 IF(p_gib.move_mode = WIP_CONSTANTS.ONLINE AND
8020 p_gib.mtl_mode = WIP_CONSTANTS.ONLINE) THEN
8021 l_transaction_mode := WIP_CONSTANTS.ONLINE;
8022 ELSE
8023 l_transaction_mode := WIP_CONSTANTS.BACKGROUND;
8024 END IF;
8025
8026 FOR l_step IN WIP_CONSTANTS.QUEUE..WIP_CONSTANTS.RUN LOOP
8027
8028 -- Discrete and Lotbased jobs
8029 IF(l_move.jobTxn = WIP_CONSTANTS.YES) THEN
8030 INSERT INTO mtl_material_transactions_temp
8031 (last_updated_by,
8032 last_update_date,
8033 last_update_login,
8034 created_by,
8035 creation_date,
8036 request_id,
8037 program_application_id,
8038 program_id,
8039 program_update_date,
8040 transaction_header_id,
8041 transaction_temp_id,
8042 source_code,
8043 source_line_id,
8044 transaction_mode,
8045 inventory_item_id,
8046 revision,
8047 organization_id,
8048 transaction_quantity,
8049 transaction_uom,
8050 primary_quantity,
8051 transaction_source_type_id,
8052 transaction_source_id,
8053 transaction_action_id,
8054 transaction_type_id,
8055 transaction_date,
8056 acct_period_id,
8057 distribution_account_id,
8058 transaction_cost,
8059 transaction_reference,
8060 reason_id,
8061 wip_entity_type,
8062 schedule_id,
8063 repetitive_line_id,
8064 operation_seq_num,
8065 move_transaction_id,
8066 process_flag,
8067 lock_flag,
8068 posting_flag,
8069 source_project_id,
8070 source_task_id,
8071 transaction_batch_id,
8072 qa_collection_id, /*Added for Bug 7136450 (FP of 7126588 )*/
8073 transaction_batch_seq
8074 )
8075 SELECT wmti.last_updated_by, -- last_updated_by --Fix for bug 5195072
8076 SYSDATE, -- last_update_date
8077 DECODE(p_gib.login_id,-1,NULL,p_gib.login_id),
8078 wmti.created_by, -- created_by --Fix for bug 5195072
8079 SYSDATE, -- creation_date
8080 DECODE(p_gib.request_id,-1,NULL,p_gib.request_id),
8081 DECODE(p_gib.application_id,-1,NULL,p_gib.application_id),
8082 DECODE(p_gib.program_id,-1,NULL,p_gib.program_id),
8083 DECODE(p_gib.request_id,
8084 -1,NULL,SYSDATE), -- program_update_date
8085 p_gib.mtl_header_id, -- transaction_header_id
8086 mtl_material_transactions_s.nextval, -- transaction_temp_id
8087 wmti.source_code,
8088 wmti.source_line_id,
8089 l_transaction_mode, -- transaction_mode
8090 wmti.primary_item_id, -- inventory_item_id
8091 -- Fixed bug 2387630
8092 DECODE(msi.revision_qty_control_code,
8093 WIP_CONSTANTS.REV, NVL(wdj.bom_revision,
8094 bom_revisions.get_item_revision_fn
8095 ('EXCLUDE_OPEN_HOLD', -- eco_status
8096 'ALL', -- examine_type
8097 wmti.organization_id, -- org_id
8098 wmti.primary_item_id, -- item_id
8099 wmti.transaction_date -- rev_date
8100 )),
8101 NULL), -- revision
8102 wmti.organization_id,
8103 DECODE(l_step, -- transaction_quantity
8104 WIP_CONSTANTS.QUEUE, -1 * wmti.transaction_quantity,
8105 wmti.transaction_quantity),
8106 wmti.transaction_uom, -- transaction_uom
8107 DECODE(l_step, -- primary_quantity
8108 WIP_CONSTANTS.QUEUE, -1 * wmti.primary_quantity,
8109 wmti.primary_quantity),
8110 TPS_INV_JOB_OR_SCHED, -- transaction_source_type_id
8111 wmti.wip_entity_id, -- transaction_source_id
8112 WIP_CONSTANTS.SCRASSY_ACTION, -- transaction_action_id
8113 WIP_CONSTANTS.SCRASSY_TYPE, -- transaction_type_id
8114 wmti.transaction_date,
8115 wmti.acct_period_id,
8116 wmti.scrap_account_id, -- distribution_account_id
8117 NULL, -- transaction_cost
8118 wmti.reference,
8119 wmti.reason_id,
8120 wmti.entity_type, -- wip_entity_type
8121 NULL, -- schedule_id
8122 wmti.line_id, -- repetitive_line_id
8123 DECODE(l_step, -- operation_seq_num
8124 WIP_CONSTANTS.QUEUE, wmti.fm_operation_seq_num,
8125 wmti.to_operation_seq_num),
8126 wmti.transaction_id, -- move_transaction_id
8127 'Y', -- process_flag
8128 'N', -- lock_flag
8129 'Y', -- posting_flag
8130 wdj.project_id,
8131 wdj.task_id,
8132 p_gib.mtl_header_id, -- transaction_batch_id
8133 wmti.qa_collection_id, /*Added for Bug 7136450 (FP of 7126588 )*/
8134 WIP_CONSTANTS.ASSY_BATCH_SEQ -- transaction_batch_seq
8135 FROM wip_move_txn_interface wmti,
8136 mtl_system_items msi,
8137 wip_discrete_jobs wdj
8138 WHERE wmti.group_id = p_gib.group_id
8139 AND TRUNC(wmti.transaction_date) = TRUNC(p_gib.txn_date)
8140 AND wmti.process_phase = WIP_CONSTANTS.MOVE_PROC
8141 AND wmti.process_status = WIP_CONSTANTS.RUNNING
8142 AND wmti.scrap_account_id IS NOT NULL
8143 AND (wmti.entity_type = WIP_CONSTANTS.DISCRETE
8144 OR wmti.entity_type = WIP_CONSTANTS.LOTBASED)/*WSM*/
8145 AND wdj.wip_entity_id = wmti.wip_entity_id
8146 AND wdj.organization_id = wmti.organization_id
8147 AND DECODE(l_step,
8148 WIP_CONSTANTS.QUEUE, wmti.fm_intraoperation_step_type,
8149 wmti.to_intraoperation_step_type) = WIP_CONSTANTS.SCRAP
8150 AND msi.organization_id = wmti.organization_id
8151 AND msi.inventory_item_id = wmti.primary_item_id;
8152
8153 -- IF debug message level = 2, write statement below to log file
8154 IF (l_logLevel <= wip_constants.full_logging) THEN
8155 fnd_message.set_name('WIP', 'WIP_INSERTED_ROWS');
8156 fnd_message.set_token('ENTITY1', SQL%ROWCOUNT);
8157 fnd_message.set_token('ENTITY2', 'MTL_MATERIAL_TRANSACTIONS_TEMP');
8158 l_msg := fnd_message.get;
8159 wip_logger.log(p_msg => l_msg,
8160 x_returnStatus => l_returnStatus);
8161 END IF;
8162
8163 END IF; -- discrete jobs
8164
8165 -- Repetitive schedules
8166 IF(l_move.scheTxn = WIP_CONSTANTS.YES) THEN
8167
8168 INSERT INTO mtl_material_transactions_temp
8169 (material_allocation_temp_id,
8170 last_updated_by,
8171 last_update_date,
8172 last_update_login,
8173 created_by,
8174 creation_date,
8175 request_id,
8176 program_application_id,
8177 program_id,
8178 program_update_date,
8179 transaction_header_id,
8180 transaction_temp_id,
8181 source_code,
8182 source_line_id,
8183 transaction_mode,
8184 inventory_item_id,
8185 revision,
8186 organization_id,
8187 transaction_quantity,
8188 transaction_uom,
8189 primary_quantity,
8190 transaction_source_type_id,
8191 transaction_source_id,
8192 transaction_action_id,
8193 transaction_type_id,
8194 transaction_date,
8195 acct_period_id,
8196 distribution_account_id,
8197 transaction_cost,
8198 transaction_reference,
8199 reason_id,
8200 wip_entity_type,
8201 schedule_id,
8202 repetitive_line_id,
8203 operation_seq_num,
8204 move_transaction_id,
8205 process_flag,
8206 lock_flag,
8207 posting_flag,
8208 transaction_batch_id,
8209 transaction_batch_seq
8210 )
8211 SELECT mtl_material_transactions_s.nextval, -- material_alloc_id
8212 wmti.last_updated_by, -- last_updated_by --Fix for bug 5195072
8213 SYSDATE, -- last_update_date
8214 DECODE(p_gib.login_id,-1,NULL,p_gib.login_id),
8215 wmti.created_by, -- created_by --Fix for bug 5195072
8216 SYSDATE, -- creation_date
8217 DECODE(p_gib.request_id,-1,NULL,p_gib.request_id),
8218 DECODE(p_gib.application_id,-1,NULL,p_gib.application_id),
8219 DECODE(p_gib.program_id,-1,NULL,p_gib.program_id),
8220 DECODE(p_gib.request_id,
8221 -1,NULL,SYSDATE), -- program_update_date
8222 p_gib.mtl_header_id, -- transaction_header_id
8223 mtl_material_transactions_s.nextval, -- transaction_temp_id
8224 wmti.source_code,
8225 wmti.source_line_id,
8226 l_transaction_mode, -- transaction_mode
8227 wmti.primary_item_id, -- inventory_item_id
8228 -- Fixed bug 2387630
8229 DECODE(msi.revision_qty_control_code, -- revision
8230 WIP_CONSTANTS.REV, NVL(wrs.bom_revision,
8231 bom_revisions.get_item_revision_fn
8232 ('EXCLUDE_OPEN_HOLD', -- eco_status
8233 'ALL', -- examine_type
8234 wmti.organization_id, -- org_id
8235 wmti.primary_item_id, -- item_id
8236 wmti.transaction_date -- rev_date
8237 )),
8238 NULL),
8239 wmti.organization_id,
8240 DECODE(l_step, -- transaction_quantity
8241 WIP_CONSTANTS.QUEUE, -1 * wmti.transaction_quantity,
8242 wmti.transaction_quantity),
8243 wmti.transaction_uom,
8244 DECODE(l_step, -- primary_quantity
8245 WIP_CONSTANTS.QUEUE, -1 * wmti.primary_quantity,
8246 wmti.primary_quantity),
8247 TPS_INV_JOB_OR_SCHED, -- transaction_source_type_id
8248 wmti.wip_entity_id, -- transaction_source_id
8249 WIP_CONSTANTS.SCRASSY_ACTION, -- transaction_action_id
8250 WIP_CONSTANTS.SCRASSY_TYPE, -- transaction_type_id
8251 wmti.transaction_date,
8252 wmti.acct_period_id,
8253 wmti.scrap_account_id, -- distribution_account_id
8254 NULL, -- transaction_cost
8255 wmti.reference,
8256 wmti.reason_id,
8257 wmti.entity_type, -- wip_entity_type
8258 NULL, -- schedule_id
8259 wmti.line_id, -- repetitive_line_id
8260 DECODE(l_step, -- operation_seq_num
8261 WIP_CONSTANTS.QUEUE, wmti.fm_operation_seq_num,
8262 wmti.to_operation_seq_num),
8263 wmti.transaction_id, -- move_transaction_id
8264 'Y', -- process_flag
8265 'N', -- lock_flag
8266 'Y', -- posting_flag
8267 p_gib.mtl_header_id, -- transaction_batch_id
8268 WIP_CONSTANTS.ASSY_BATCH_SEQ -- transaction_batch_seq
8269 FROM wip_move_txn_interface wmti,
8270 mtl_system_items msi,
8271 wip_repetitive_schedules wrs
8272 WHERE wmti.group_id = p_gib.group_id
8273 AND TRUNC(wmti.transaction_date) = TRUNC(p_gib.txn_date)
8274 AND wmti.process_phase = WIP_CONSTANTS.MOVE_PROC
8275 AND wmti.process_status = WIP_CONSTANTS.RUNNING
8276 AND wmti.scrap_account_id IS NOT NULL
8277 AND wmti.entity_type = WIP_CONSTANTS.REPETITIVE
8278 AND wrs.wip_entity_id = wmti.wip_entity_id
8279 AND wrs.organization_id = wmti.organization_id
8280 AND wrs.line_id = wmti.line_id
8281 AND wrs.repetitive_schedule_id = wmti.repetitive_schedule_id
8282 AND DECODE(l_step,
8283 WIP_CONSTANTS.QUEUE, wmti.fm_intraoperation_step_type,
8284 wmti.to_intraoperation_step_type) = WIP_CONSTANTS.SCRAP
8285 AND msi.organization_id = wmti.organization_id
8286 AND msi.inventory_item_id = wmti.primary_item_id;
8287
8288 -- IF debug message level = 2, write statement below to log file
8289 IF (l_logLevel <= wip_constants.full_logging) THEN
8290 fnd_message.set_name('WIP', 'WIP_INSERTED_ROWS');
8291 fnd_message.set_token('ENTITY1', SQL%ROWCOUNT);
8292 fnd_message.set_token('ENTITY2', 'MTL_MATERIAL_TRANSACTIONS_TEMP');
8293 l_msg := fnd_message.get;
8294 wip_logger.log(p_msg => l_msg,
8295 x_returnStatus => l_returnStatus);
8296 END IF;
8297 END IF; -- Repetitive schedules
8298 END LOOP; -- FOR l_step
8299
8300 IF(l_move.jobTxn = WIP_CONSTANTS.YES) THEN
8301 /* Call snapshot for Discrete jobs and only in Avg costing Org. */
8302 IF(p_gib.move_mode = WIP_CONSTANTS.ONLINE) THEN
8303 snapshot_online(p_mtl_header_id => p_gib.mtl_header_id,
8304 p_org_id => l_move.org_id,
8305 p_txn_type => WIP_CONSTANTS.MOVE_TXN,
8306 p_txn_type_id => WIP_CONSTANTS.SCRASSY_TYPE,
8307 p_txn_action_id => WIP_CONSTANTS.SCRASSY_ACTION,
8308 x_returnStatus => x_returnStatus);
8309
8310 IF(x_returnStatus <> fnd_api.g_ret_sts_success) THEN
8311 l_errMsg := 'wip_movProc_priv.snapshot_online failed';
8312 raise fnd_api.g_exc_unexpected_error;
8313 END IF; -- check return status
8314 END IF; -- move mode check
8315 END IF; -- IF job txns
8316 END IF; -- scrap transactions
8317
8318 -- Update PO quantity for scrap transactions
8319 IF (po_code_release_grp.Current_Release >=
8320 po_code_release_grp.PRC_11i_Family_Pack_J) THEN
8321 FOR l_update_po IN c_update_po LOOP
8322 wip_osp.updatePOReqQuantity(
8323 p_job_id => l_update_po.job_id,
8324 p_repetitive_id => l_update_po.rep_id,
8325 p_org_id => l_update_po.org_id,
8326 p_changed_qty => l_update_po.changed_qty,
8327 p_fm_op => l_update_po.fm_op,
8328 /* Fix for Bug#4734309 */
8329 p_is_scrap_txn => WIP_CONSTANTS.YES,
8330 x_return_status => x_returnStatus);
8331
8332 IF(x_returnStatus <> fnd_api.g_ret_sts_success) THEN
8333 l_errMsg := 'wip_osp.updatePOReqQuantity failed';
8334 raise fnd_api.g_exc_unexpected_error;
8335 END IF;
8336 END LOOP;
8337 END IF; -- have PO patchset J onward
8338
8339
8340 -- assign l_move back to move profile
8341 p_gib.move_profile := l_move;
8342 x_returnStatus := fnd_api.g_ret_sts_success;
8343
8344 -- write to the log file
8345 IF (l_logLevel <= wip_constants.trace_logging) THEN
8346 wip_logger.exitPoint(p_procName => 'wip_movProc_priv.scrap_txns',
8347 p_procReturnStatus => x_returnStatus,
8348 p_msg => 'procedure complete',
8349 x_returnStatus => l_returnStatus);
8350 END IF;
8351
8352 EXCEPTION
8353 WHEN fnd_api.g_exc_unexpected_error THEN
8354 x_returnStatus := fnd_api.g_ret_sts_unexp_error;
8355 IF (l_logLevel <= wip_constants.trace_logging) THEN
8356 wip_logger.exitPoint(p_procName =>'wip_movProc_priv.scrap_txns',
8357 p_procReturnStatus => x_returnStatus,
8358 p_msg => l_errMsg,
8359 x_returnStatus => l_returnStatus);
8360 END IF;
8361
8362 WHEN others THEN
8363 x_returnStatus := fnd_api.g_ret_sts_unexp_error;
8364 l_errMsg := 'unexpected error: ' || SQLERRM || 'SQLCODE = ' || SQLCODE;
8365
8366 IF (l_logLevel <= wip_constants.trace_logging) THEN
8367 wip_logger.exitPoint(p_procName=>'wip_movProc_priv.scrap_txns',
8368 p_procReturnStatus => x_returnStatus,
8369 p_msg => l_errMsg,
8370 x_returnStatus => l_returnStatus);
8371 END IF;
8372 fnd_message.set_name('FND', 'FND_GENERIC_MESSAGE');
8373 fnd_message.set_token('MESSAGE', l_errMsg);
8374 fnd_msg_pub.add;
8375 END scrap_txns;
8376
8377 /*****************************************************************************
8378 * This procedure is equivalent to witpscp_completion in wiltps5.ppc
8379 * This procedure is used to do easy completion and easy return
8380 * This procedure insert into MTL_MATERIAL_TRANSACTIONS_TEMP and
8381 * MTL_TRANSACTION_LOTS_TEMP
8382 ****************************************************************************/
8383 PROCEDURE ez_completion(p_gib IN OUT NOCOPY group_rec_t,
8384 p_txn_type IN NUMBER,
8385 x_returnStatus OUT NOCOPY VARCHAR2) IS
8386
8387 CURSOR c_repAssembly(p_header_id NUMBER) IS
8388 SELECT completion_transaction_id cpl_txn_id,
8389 transaction_action_id txn_action_id,
8390 transaction_source_id txn_src_id,
8391 repetitive_line_id rep_line_id,
8392 organization_id org_id,
8393 transaction_date txn_date,
8394 ABS(primary_quantity) primary_qty,
8395 reason_id reason_id,
8396 transaction_reference reference
8397 FROM mtl_material_transactions_temp
8398 WHERE transaction_header_id = p_header_id
8399 AND wip_entity_type = WIP_CONSTANTS.REPETITIVE
8400 AND transaction_action_id IN (WIP_CONSTANTS.RETASSY_ACTION,
8401 WIP_CONSTANTS.CPLASSY_ACTION);
8402
8403 l_repAssembly c_repAssembly%ROWTYPE;
8404 l_params wip_logger.param_tbl_t;
8405 l_returnStatus VARCHAR(1);
8406 l_errMsg VARCHAR(240);
8407 l_msg VARCHAR(240);
8408 l_step NUMBER;
8409 l_transaction_mode NUMBER;
8410 l_txn_action_id NUMBER;
8411 l_txn_type_id NUMBER;
8412 l_txn_direction NUMBER;
8413 l_mti_lot_rec NUMBER; -- number of record under lot control
8414 l_mti_ser_rec NUMBER; -- number of record under serial control
8415 l_move move_profile_rec_t;
8416 l_logLevel NUMBER := fnd_log.g_current_runtime_level;
8417 l_bf_required NUMBER; -- throw away value
8418 l_ls_required NUMBER;
8419 l_addMsgToStack VARCHAR2(1);
8420 BEGIN
8421 l_move := p_gib.move_profile;
8422
8423 -- write parameter value to log file
8424 IF (l_logLevel <= wip_constants.trace_logging) THEN
8425 l_params(1).paramName := 'p_group_id';
8426 l_params(1).paramValue := p_gib.group_id;
8427 l_params(2).paramName := 'p_txn_date';
8428 l_params(2).paramValue := p_gib.txn_date;
8429 l_params(3).paramName := 'org_id';
8430 l_params(3).paramValue := l_move.org_id;
8431 l_params(4).paramName := 'wip_id';
8432 l_params(4).paramValue := l_move.wip_id;
8433 l_params(5).paramName := 'fmOp';
8434 l_params(5).paramValue := l_move.fmOp;
8435 l_params(6).paramName := 'fmStep';
8436 l_params(6).paramValue := l_move.fmStep;
8437 l_params(7).paramName := 'toOp';
8438 l_params(7).paramValue := l_move.toOp;
8439 l_params(8).paramName := 'toStep';
8440 l_params(8).paramValue := l_move.toStep;
8441 l_params(9).paramName := 'scrapTxn';
8442 l_params(9).paramValue := l_move.scrapTxn;
8443 l_params(10).paramName := 'easyComplete';
8444 l_params(10).paramValue := l_move.easyComplete;
8445 l_params(11).paramName := 'easyReturn';
8446 l_params(11).paramValue := l_move.easyReturn;
8447 l_params(12).paramName := 'jobTxn';
8448 l_params(12).paramValue := l_move.jobTxn;
8449 l_params(13).paramName := 'scheTxn';
8450 l_params(13).paramValue := l_move.scheTxn;
8451 l_params(14).paramName := 'rsrcItem';
8452 l_params(14).paramValue := l_move.rsrcItem;
8453 l_params(15).paramName := 'rsrcLot';
8454 l_params(15).paramValue := l_move.rsrcLot;
8455 l_params(16).paramName := 'poReqItem';
8456 l_params(16).paramValue := l_move.poReqItem;
8457 l_params(17).paramName := 'poRegLot';
8458 l_params(17).paramValue := l_move.poReqLot;
8459 l_params(18).paramName := 'p_mtl_header_id';
8460 l_params(18).paramValue := p_gib.mtl_header_id;
8461 l_params(19).paramName := 'p_move_mode';
8462 l_params(19).paramValue := p_gib.move_mode;
8463 l_params(20).paramName := 'p_mtl_mode';
8464 l_params(20).paramValue := p_gib.mtl_mode;
8465 l_params(21).paramName := 'p_txn_type';
8466 l_params(21).paramValue := p_txn_type;
8467 l_params(22).paramName := 'p_assy_header_id';
8468 l_params(22).paramValue := p_gib.assy_header_id;
8469
8470 wip_logger.entryPoint(p_procName =>'wip_movProc_priv.ez_completion',
8471 p_params => l_params,
8472 x_returnStatus => l_returnStatus);
8473 END IF;
8474
8475 /* Generate a mtl txn header id IF one has not already been generated */
8476 IF(p_gib.mtl_header_id IS NULL OR
8477 p_gib.mtl_header_id = -1) THEN
8478 SELECT mtl_material_transactions_s.nextval
8479 INTO p_gib.mtl_header_id
8480 FROM DUAL;
8481 END IF;
8482
8483 IF(p_gib.assy_header_id IS NULL OR
8484 p_gib.assy_header_id = -1) THEN
8485 -- Generate new header ID for assembly records because we want inventory
8486 -- to process assembly records, but not component records.
8487 SELECT mtl_material_transactions_s.nextval
8488 INTO p_gib.assy_header_id
8489 FROM DUAL;
8490 END IF;
8491
8492 /* set transaction type */
8493 IF (p_txn_type = WIP_CONSTANTS.RET_TXN) THEN
8494 l_txn_action_id := WIP_CONSTANTS.RETASSY_ACTION;
8495 l_txn_type_id := WIP_CONSTANTS.RETASSY_TYPE;
8496 l_txn_direction := -1;
8497 ELSE
8498 l_txn_action_id := WIP_CONSTANTS.CPLASSY_ACTION;
8499 l_txn_type_id := WIP_CONSTANTS.CPLASSY_TYPE;
8500 l_txn_direction := 1;
8501 END IF;
8502
8503 -- initialize transaction mode
8504 IF(p_gib.move_mode = WIP_CONSTANTS.ONLINE AND
8505 p_gib.mtl_mode = WIP_CONSTANTS.ONLINE) THEN
8506 l_transaction_mode := WIP_CONSTANTS.ONLINE;
8507 ELSE
8508 l_transaction_mode := WIP_CONSTANTS.BACKGROUND;
8509 END IF;
8510
8511 /*------------------------------------------------------------+
8512 | Insert completion transaction record |
8513 +------------------------------------------------------------*/
8514 IF(l_move.jobTxn = WIP_CONSTANTS.YES) THEN
8515 INSERT INTO mtl_transactions_interface
8516 (last_updated_by,
8517 last_update_date,
8518 last_update_login,
8519 created_by,
8520 creation_date,
8521 request_id,
8522 program_application_id,
8523 program_id,
8524 program_update_date,
8525 transaction_header_id,
8526 source_code,
8527 completion_transaction_id,
8528 move_transaction_id,
8529 inventory_item_id,
8530 subinventory_code,
8531 locator_id,
8532 transaction_quantity,
8533 transaction_uom,
8534 primary_quantity,
8535 transaction_date,
8536 organization_id,
8537 acct_period_id,
8538 transaction_action_id,
8539 transaction_source_id,
8540 transaction_source_type_id,
8541 transaction_type_id,
8542 wip_entity_type,
8543 repetitive_line_id,
8544 transaction_reference,
8545 operation_seq_num,
8546 reason_id,
8547 revision,
8548 kanban_card_id,
8549 source_project_id,
8550 source_task_id,
8551 transaction_mode,
8552 process_flag,
8553 -- lock_flag,
8554 -- posting_flag,
8555 -- item_lot_control_code,
8556 -- item_serial_control_code,
8557 -- project_id,
8558 -- task_id,
8559 source_header_id,
8560 source_line_id,
8561 transaction_batch_id,
8562 transaction_batch_seq,
8563 transaction_interface_id,
8564 -- populate this value for EZ completion/return because material
8565 -- processor need this value to enable quality
8566 qa_collection_id
8567 )
8568 SELECT wmti.last_updated_by, -- last_update_by --Fix for bug 5195072
8569 SYSDATE, -- last_update_date
8570 DECODE(p_gib.login_id, -1, NULL, p_gib.login_id),
8571 wmti.created_by, -- created_by --Fix for bug 5195072
8572 SYSDATE, -- creation_date
8573 DECODE(p_gib.request_id, -1, NULL, p_gib.request_id),
8574 DECODE(p_gib.application_id, -1, NULL, p_gib.application_id),
8575 DECODE(p_gib.program_id, -1, NULL, p_gib.program_id),
8576 DECODE(p_gib.request_id,
8577 -1, NULL, SYSDATE), -- program_update_date
8578 p_gib.assy_header_id, -- transaction_header_id
8579 'WIP Completion', -- source_code
8580 NVL(p_gib.move_profile.cmp_txn_id,-- completion_transaction_id
8581 mtl_material_transactions_s.nextval),
8582 wmti.transaction_id, -- move_transaction_id
8583 wmti.primary_item_id, -- inventory_item_id
8584 wdj.completion_subinventory, -- subinventory_code
8585 wdj.completion_locator_id, -- locator_id
8586 l_txn_direction * wmti.transaction_quantity,-- transaction_qty
8587 wmti.transaction_uom, -- transaction_uom
8588 l_txn_direction * wmti.primary_quantity, -- primary_quantity
8589 wmti.transaction_date,
8590 wmti.organization_id,
8591 wmti.acct_period_id,
8592 l_txn_action_id, -- transaction_action_id
8593 wmti.wip_entity_id, -- transaction_source_id
8594 TPS_INV_JOB_OR_SCHED, -- transaction_source_type_id
8595 l_txn_type_id, -- transaction_type_id
8596 wmti.entity_type, -- wip_entity_type
8597 wmti.line_id, -- repetitive_line_id
8598 wmti.reference, -- transaction_reference
8599 wop.operation_seq_num,
8600 wmti.reason_id,
8601 -- Fixed bug 2387630
8602 DECODE(msi.revision_qty_control_code, -- revision
8603 WIP_CONSTANTS.REV, NVL(wdj.bom_revision,
8604 bom_revisions.get_item_revision_fn
8605 ('EXCLUDE_OPEN_HOLD', -- eco_status
8606 'ALL', -- examine_type
8607 wmti.organization_id, -- org_id
8608 wmti.primary_item_id, -- item_id
8609 wmti.transaction_date -- rev_date
8610 )),
8611 NULL),
8612 DECODE(l_txn_direction, -- kanban_card_id
8613 -1,NULL,wdj.kanban_card_id),
8614 wdj.project_id, -- source_project_id
8615 wdj.task_id, -- source_task_id
8616 l_transaction_mode, -- transaction_mode
8617 WIP_CONSTANTS.MTI_INVENTORY, -- process_flag for WIP
8618 -- 'N', -- lock_flag
8619 -- 'Y', -- posting_flag
8620 -- msi.lot_control_code, -- item_lot_control_code
8621 -- msi.serial_number_control_code,-- item_serial_control_code
8622 -- mil.project_id, -- project_id
8623 -- mil.task_id, -- task_id
8624 wmti.wip_entity_id, -- source_header_id
8625 wop.operation_seq_num, -- source_line_id
8626 p_gib.assy_header_id, -- transaction_batch_id
8627 WIP_CONSTANTS.ASSY_BATCH_SEQ,-- transaction_batch_seq
8628 mtl_material_transactions_s.nextval, -- transaction_interface_id
8629 -- populate this value for EZ completion/return because
8630 -- material processor need this value to enable quality
8631 wmti.qa_collection_id
8632 FROM wip_move_txn_interface wmti,
8633 mtl_item_locations mil,
8634 wip_operations wop,
8635 mtl_system_items msi,
8636 wip_discrete_jobs wdj
8637 WHERE wmti.group_id = p_gib.group_id
8638 AND TRUNC(wmti.transaction_date) = TRUNC(p_gib.txn_date)
8639 AND wmti.process_phase = WIP_CONSTANTS.MOVE_PROC
8640 AND wmti.process_status = WIP_CONSTANTS.RUNNING
8641 AND wmti.transaction_type = p_txn_type
8642 AND (wmti.entity_type = WIP_CONSTANTS.DISCRETE
8643 OR wmti.entity_type = WIP_CONSTANTS.LOTBASED)/*WSM*/
8644 AND wdj.wip_entity_id = wmti.wip_entity_id
8645 AND wdj.organization_id = wmti.organization_id
8646 AND wop.organization_id = wmti.organization_id
8647 AND wop.wip_entity_id = wmti.wip_entity_id
8648 AND NVL(wop.repetitive_schedule_id,-1) =
8649 NVL(wmti.repetitive_schedule_id,-1)
8650 AND wop.next_operation_seq_num IS NULL
8651 AND msi.organization_id = wmti.organization_id
8652 AND msi.inventory_item_id = wmti.primary_item_id
8653 AND wdj.completion_locator_id = mil.inventory_location_id (+)
8654 AND wdj.organization_id = mil.organization_id (+);
8655
8656 END IF; -- discrete jobs
8657
8658 IF(l_move.scheTxn = WIP_CONSTANTS.YES) THEN
8659
8660 INSERT INTO mtl_transactions_interface
8661 (last_updated_by,
8662 last_update_date,
8663 last_update_login,
8664 created_by,
8665 creation_date,
8666 request_id,
8667 program_application_id,
8668 program_id,
8669 program_update_date,
8670 transaction_header_id,
8671 source_code,
8672 completion_transaction_id,
8673 move_transaction_id,
8674 inventory_item_id,
8675 subinventory_code,
8676 locator_id,
8677 transaction_quantity,
8678 transaction_uom,
8679 primary_quantity,
8680 transaction_date,
8681 organization_id,
8682 acct_period_id,
8683 transaction_action_id,
8684 transaction_source_id,
8685 transaction_source_type_id,
8686 transaction_type_id,
8687 wip_entity_type,
8688 repetitive_line_id,
8689 transaction_reference,
8690 operation_seq_num,
8691 reason_id,
8692 revision,
8693 transaction_mode,
8694 process_flag,
8695 -- lock_flag,
8696 -- posting_flag,
8697 -- item_lot_control_code,
8698 -- item_serial_control_code,
8699 source_header_id,
8700 source_line_id,
8701 transaction_batch_id,
8702 transaction_batch_seq,
8703 transaction_interface_id,
8704 -- populate this value for EZ completion/return because material
8705 -- processor need this value to enable quality
8706 qa_collection_id
8707 )
8708 SELECT wmti.last_updated_by, -- last_update_by --Fix for bug 5195072
8709 SYSDATE, -- last_update_date
8710 DECODE(p_gib.login_id, -1, NULL, p_gib.login_id),
8711 wmti.created_by, -- created_by --Fix for bug 5195072
8712 SYSDATE, -- creation_date
8713 DECODE(p_gib.request_id, -1, NULL, p_gib.request_id),
8714 DECODE(p_gib.application_id, -1, NULL, p_gib.application_id),
8715 DECODE(p_gib.program_id, -1, NULL, p_gib.program_id),
8716 DECODE(p_gib.request_id,
8717 -1, NULL, SYSDATE), -- program_update_date
8718 p_gib.assy_header_id, -- transaction_header_id
8719 'WIP Completion', -- source_code
8720 NVL(p_gib.move_profile.cmp_txn_id, -- completion_transaction_id
8721 mtl_material_transactions_s.nextval),
8722 wmti.transaction_id, -- move_transaction_id
8723 wmti.primary_item_id, -- inventory_item_id
8724 wri.completion_subinventory,-- subinventory_code
8725 wri.completion_locator_id, -- locator_id
8726 l_txn_direction * wmti.transaction_quantity, -- transaction_qty
8727 wmti.transaction_uom, -- transaction_uom
8728 l_txn_direction * wmti.primary_quantity, -- primary_quantity
8729 wmti.transaction_date,
8730 wmti.organization_id,
8731 wmti.acct_period_id,
8732 l_txn_action_id, -- transaction_action_id
8733 wmti.wip_entity_id, -- transaction_source_id
8734 TPS_INV_JOB_OR_SCHED, -- trsnsaction_source_type_id
8735 l_txn_type_id, -- transaction_type_id
8736 wmti.entity_type,
8737 wmti.line_id, -- repetitive_line_id
8738 wmti.reference, -- transaction_reference
8739 wop.operation_seq_num,
8740 wmti.reason_id,
8741 -- Fixed bug 2387630
8742 DECODE(msi.revision_qty_control_code, -- revision
8743 WIP_CONSTANTS.REV, NVL(wrs.bom_revision,
8744 bom_revisions.get_item_revision_fn
8745 ('EXCLUDE_OPEN_HOLD', -- eco_status
8746 'ALL', -- examine_type
8747 wmti.organization_id, -- org_id
8748 wmti.primary_item_id, -- item_id
8749 wmti.transaction_date -- rev_date
8750 )),
8751 NULL),
8752 l_transaction_mode, -- transaction_mode
8753 WIP_CONSTANTS.MTI_INVENTORY, -- process_flag for WIP
8754 -- 'N', -- lock_flag
8755 -- 'Y', -- posting_flag
8756 -- msi.lot_control_code, -- item_lot_control_code
8757 -- msi.serial_number_control_code, -- item_serial_control_code
8758 wmti.wip_entity_id, -- source_header_id
8759 wop.operation_seq_num, -- source_line_id
8760 p_gib.assy_header_id, -- transaction_batch_id
8761 WIP_CONSTANTS.ASSY_BATCH_SEQ, -- transaction_batch_seq
8762 mtl_material_transactions_s.nextval, -- transaction_interface_id
8763 -- populate this value for EZ completion/return because
8764 -- material processor need this value to enable quality
8765 wmti.qa_collection_id
8766 FROM wip_move_txn_interface wmti,
8767 wip_operations wop,
8768 mtl_system_items msi,
8769 wip_repetitive_schedules wrs,
8770 wip_repetitive_items wri
8771 WHERE wmti.group_id = p_gib.group_id
8772 AND TRUNC(wmti.transaction_date) = TRUNC(p_gib.txn_date)
8773 AND wmti.process_phase = WIP_CONSTANTS.MOVE_PROC
8774 AND wmti.process_status = WIP_CONSTANTS.RUNNING
8775 AND wmti.transaction_type = p_txn_type
8776 AND wmti.entity_type = WIP_CONSTANTS.REPETITIVE
8777 AND wrs.wip_entity_id = wmti.wip_entity_id
8778 AND wrs.organization_id = wmti.organization_id
8779 AND wrs.line_id = wmti.line_id
8780 AND wrs.repetitive_schedule_id = wmti.repetitive_schedule_id
8781 AND wri.organization_id = wmti.organization_id
8782 AND wri.wip_entity_id = wmti.wip_entity_id
8783 AND wri.line_id = wmti.line_id
8784 AND wop.organization_id = wmti.organization_id
8785 AND wop.wip_entity_id = wmti.wip_entity_id
8786 AND NVL(wop.repetitive_schedule_id,-1) =
8787 NVL(wmti.repetitive_schedule_id,-1)
8788 AND wop.next_operation_seq_num IS NULL
8789 AND msi.organization_id = wmti.organization_id
8790 AND msi.inventory_item_id = wmti.primary_item_id;
8791 END IF; -- Repetitive schedules
8792
8793 -- IF debug message level = 2, write statement below to log file
8794 IF (l_logLevel <= wip_constants.full_logging) THEN
8795 fnd_message.set_name('WIP', 'WIP_INSERTED_ROWS');
8796 fnd_message.set_token('ENTITY1', SQL%ROWCOUNT);
8797 fnd_message.set_token('ENTITY2', 'MTL_TRANSACTIONS_INTERFACE');
8798 l_msg := fnd_message.get;
8799 wip_logger.log(p_msg => l_msg,
8800 x_returnStatus => l_returnStatus);
8801 END IF;
8802
8803 /* Only allow lot control for discrete/OSFM jobs */
8804 IF(l_move.jobTxn = WIP_CONSTANTS.YES) THEN
8805
8806 SELECT COUNT(*)
8807 INTO l_mti_lot_rec
8808 FROM mtl_transactions_interface mti,
8809 mtl_system_items msi
8810 WHERE mti.organization_id = msi.organization_id
8811 AND mti.inventory_item_id = msi.inventory_item_id
8812 AND mti.transaction_header_id = p_gib.assy_header_id
8813 AND mti.transaction_action_id = l_txn_action_id
8814 AND mti.transaction_type_id = l_txn_type_id
8815 AND mti.transaction_source_type_id = TPS_INV_JOB_OR_SCHED
8816 AND mti.wip_entity_type IN (WIP_CONSTANTS.DISCRETE,
8817 WIP_CONSTANTS.LOTBASED) /*WSM*/
8818 AND msi.lot_control_code = WIP_CONSTANTS.LOT;
8819
8820 -- IF debug message level = 2, write statement below to log file
8821 IF (l_logLevel <= wip_constants.full_logging) THEN
8822 l_msg := 'No. of records in mti updated for lot controlled ' ||
8823 'assemblies : ' || l_mti_lot_rec;
8824 wip_logger.log(p_msg => l_msg,
8825 x_returnStatus => l_returnStatus);
8826 END IF;
8827
8828 /* IF records under lot control THEN continue */
8829 IF(l_mti_lot_rec > 0) THEN
8830 /* Insert lot records into lot interface table */
8831 /*----------------------------------------------------------------------
8832 |The NOT EXISTS statement in the where clause is added for fixing
8833 | bug 1813824. Duplicate records could be inserted in the following
8834 | senario. The first around, the first record get inserted into mtt
8835 | and THEN temp id is update for that record, so one record get
8836 | inserted into mtlt. The second round, the second record get inserted
8837 | into mtt and temp id is THEN updated accordingly. But when doing the
8838 | insertion, since the where clause is not selective enough, the record
8839 | that is inserted into mtlt for the first record is inserted again.
8840 | Since there is no other way to indicate that the corresponding record
8841 | in mtlt is already inserted for record in mtt and the fact that
8842 | we only insert one row into mtlt here for one row in mtt, we could
8843 | add a NOT EXISTS statment to prevent duplicate record being inserted
8844 +---------------------------------------------------------------------*/
8845 INSERT INTO mtl_transaction_lots_interface
8846 (transaction_interface_id,
8847 lot_number,
8848 primary_quantity,
8849 transaction_quantity,
8850 lot_expiration_date,
8851 creation_date,
8852 created_by,
8853 last_update_date,
8854 last_updated_by,
8855 last_update_login,
8856 serial_transaction_temp_id
8857 )
8858 SELECT mti.transaction_interface_id,
8859 wdj.lot_number,
8860 mti.primary_quantity,
8861 mti.transaction_quantity,
8862 NULL, -- lot_expiration_date
8863 mti.creation_date,
8864 mti.created_by,
8865 mti.last_update_date,
8866 mti.last_updated_by,
8867 mti.last_update_login,
8868 DECODE(msi.serial_number_control_code,
8869 WIP_CONSTANTS.FULL_SN, mtl_material_transactions_s.nextval,
8870 WIP_CONSTANTS.DYN_RCV_SN,mtl_material_transactions_s.nextval,
8871 NULL)
8872 FROM mtl_transactions_interface mti,
8873 mtl_system_items msi,
8874 wip_discrete_jobs wdj
8875 WHERE mti.organization_id = msi.organization_id
8876 AND mti.inventory_item_id = msi.inventory_item_id
8877 AND mti.transaction_header_id = p_gib.assy_header_id
8878 AND mti.transaction_action_id = l_txn_action_id
8879 AND mti.transaction_type_id = l_txn_type_id
8880 AND mti.transaction_source_type_id = TPS_INV_JOB_OR_SCHED
8881 AND mti.wip_entity_type IN (WIP_CONSTANTS.DISCRETE,
8882 WIP_CONSTANTS.LOTBASED)/*WSM */
8883 AND msi.lot_control_code = WIP_CONSTANTS.LOT
8884 AND mti.organization_id = wdj.organization_id
8885 AND mti.transaction_source_id = wdj.wip_entity_id
8886 AND NOT EXISTS
8887 (SELECT 1
8888 FROM mtl_transaction_lots_interface mtli
8889 WHERE mtli.transaction_interface_id =
8890 mti.transaction_interface_id);
8891
8892 -- IF debug message level = 2, write statement below to log file
8893 IF (l_logLevel <= wip_constants.full_logging) THEN
8894 fnd_message.set_name('WIP', 'WIP_INSERTED_ROWS');
8895 fnd_message.set_token('ENTITY1', SQL%ROWCOUNT);
8896 fnd_message.set_token('ENTITY2', 'MTL_TRANSACTION_LOTS_INTERFACE');
8897 l_msg := fnd_message.get;
8898 wip_logger.log(p_msg => l_msg,
8899 x_returnStatus => l_returnStatus);
8900 END IF;
8901
8902 /* Update lot records with an expiration date */
8903 /* Use expiration date in MTL_LOT_NUMBERS. */
8904 /* IF no expiration date THEN calculate based on SHELF_LIFE_DAYS */
8905
8906 UPDATE mtl_transaction_lots_interface mtli
8907 SET lot_expiration_date =
8908 (SELECT MIN(mln.expiration_date)
8909 FROM mtl_transactions_interface mti,
8910 mtl_system_items msi,
8911 mtl_lot_numbers mln
8912 WHERE mti.organization_id = msi.organization_id
8913 AND mti.inventory_item_id = msi.inventory_item_id
8914 AND mti.transaction_header_id = p_gib.assy_header_id
8915 AND mti.transaction_action_id = l_txn_action_id
8916 AND mti.transaction_type_id = l_txn_type_id
8917 AND mti.transaction_source_type_id = TPS_INV_JOB_OR_SCHED
8918 AND mti.wip_entity_type IN (WIP_CONSTANTS.DISCRETE,
8919 WIP_CONSTANTS.LOTBASED)/*WSM */
8920 AND msi.lot_control_code = WIP_CONSTANTS.LOT
8921 AND mln.lot_number = mtli.lot_number
8922 AND mln.inventory_item_id = mti.inventory_item_id
8923 AND mln.organization_id = mti.organization_id)
8924 WHERE mtli.transaction_interface_id IN
8925 (SELECT mti.transaction_interface_id
8926 FROM mtl_transactions_interface mti,
8927 mtl_system_items msi
8928 WHERE mti.organization_id = msi.organization_id
8929 AND mti.inventory_item_id = msi.inventory_item_id
8930 AND mti.transaction_header_id = p_gib.assy_header_id
8931 AND mti.transaction_action_id = l_txn_action_id
8932 AND mti.transaction_type_id = l_txn_type_id
8933 AND mti.transaction_source_type_id = TPS_INV_JOB_OR_SCHED
8934 AND mti.wip_entity_type IN (WIP_CONSTANTS.DISCRETE,
8935 WIP_CONSTANTS.LOTBASED)/* WSM */
8936 AND msi.lot_control_code = WIP_CONSTANTS.LOT);
8937
8938 -- IF debug message level = 2, write statement below to log file
8939 IF (l_logLevel <= wip_constants.full_logging) THEN
8940 fnd_message.set_name('WIP', 'WIP_UPDATED_ROWS');
8941 fnd_message.set_token('ENTITY1', SQL%ROWCOUNT);
8942 fnd_message.set_token('ENTITY2', 'MTL_TRANSACTION_LOTS_INTERFACE');
8943 l_msg := fnd_message.get;
8944 wip_logger.log(p_msg => l_msg,
8945 x_returnStatus => l_returnStatus);
8946 END IF;
8947
8948 /* IF Exp date null in MTL_LOT_NUMBERS should I leave it null */
8949 /* Or should I just decode based on exp date null in the temp table? */
8950 /* Removed group by and modIFied select and where conditions to avoid
8951 oracle error 1427. See bugs 866408 and 938422. */
8952 UPDATE mtl_transaction_lots_interface mtli
8953 SET lot_expiration_date =
8954 (SELECT mti.transaction_date + NVL(msi.shelf_life_days,0)
8955 FROM mtl_transactions_interface mti,
8956 mtl_system_items msi
8957 WHERE mti.transaction_header_id = p_gib.assy_header_id
8958 AND mti.transaction_action_id = l_txn_action_id
8959 AND mti.transaction_type_id = l_txn_type_id
8960 AND mti.transaction_source_type_id = TPS_INV_JOB_OR_SCHED
8961 AND mti.wip_entity_type IN (WIP_CONSTANTS.DISCRETE,
8962 WIP_CONSTANTS.LOTBASED) /*WSM */
8963 AND msi.lot_control_code = WIP_CONSTANTS.LOT
8964 AND msi.organization_id = mti.organization_id
8965 AND msi.inventory_item_id = mti.inventory_item_id
8966 AND msi.shelf_life_code = WIP_CONSTANTS.SHELF_LIFE
8967 AND mtli.transaction_interface_id =
8968 mti.transaction_interface_id)
8969 WHERE mtli.lot_expiration_date IS NULL
8970 AND mtli.transaction_interface_id IN
8971 (SELECT mti.transaction_interface_id
8972 FROM mtl_transactions_interface mti,
8973 mtl_system_items msi
8974 WHERE mti.organization_id = msi.organization_id
8975 AND mti.inventory_item_id = msi.inventory_item_id
8976 AND mti.transaction_header_id = p_gib.assy_header_id
8977 AND mti.transaction_action_id = l_txn_action_id
8978 AND mti.transaction_type_id = l_txn_type_id
8979 AND mti.transaction_source_type_id = TPS_INV_JOB_OR_SCHED
8980 AND mti.wip_entity_type IN (WIP_CONSTANTS.DISCRETE,
8981 WIP_CONSTANTS.LOTBASED)/* WSM */
8982 AND msi.lot_control_code = WIP_CONSTANTS.LOT);
8983
8984 -- IF debug message level = 2, write statement below to log file
8985 IF (l_logLevel <= wip_constants.full_logging) THEN
8986 fnd_message.set_name('WIP', 'WIP_UPDATED_ROWS');
8987 fnd_message.set_token('ENTITY1', SQL%ROWCOUNT);
8988 fnd_message.set_token('ENTITY2', 'MTL_TRANSACTION_LOTS_INTERFACE');
8989 l_msg := fnd_message.get;
8990 wip_logger.log(p_msg => l_msg,
8991 x_returnStatus => l_returnStatus);
8992 END IF;
8993
8994 END IF; -- (l_mti_lot_rec > 0)
8995 END IF; -- Discrete and Lotbased jobs
8996
8997 SELECT COUNT(*)
8998 INTO l_mti_ser_rec
8999 FROM mtl_transactions_interface mti,
9000 mtl_system_items msi
9001 WHERE mti.organization_id = msi.organization_id
9002 AND mti.inventory_item_id = msi.inventory_item_id
9003 AND mti.transaction_header_id = p_gib.assy_header_id
9004 AND mti.transaction_action_id = l_txn_action_id
9005 AND mti.transaction_type_id = l_txn_type_id
9006 AND mti.transaction_source_type_id = TPS_INV_JOB_OR_SCHED
9007 AND mti.wip_entity_type IN (WIP_CONSTANTS.DISCRETE,
9008 WIP_CONSTANTS.LOTBASED) /*WSM*/
9009 AND msi.serial_number_control_code IN (WIP_CONSTANTS.FULL_SN,
9010 WIP_CONSTANTS.DYN_RCV_SN);
9011
9012 -- IF debug message level = 2, write statement below to log file
9013 IF (l_logLevel <= wip_constants.full_logging) THEN
9014 l_msg := 'No. of records in mti updated for serial controlled ' ||
9015 'assemblies : ' || l_mti_ser_rec;
9016 wip_logger.log(p_msg => l_msg,
9017 x_returnStatus => l_returnStatus);
9018 END IF;
9019
9020 /* IF records under serial control THEN continue */
9021 IF(l_mti_ser_rec > 0) THEN
9022 /* Insert serial records into serial interface table */
9023
9024 INSERT INTO mtl_serial_numbers_interface
9025 (transaction_interface_id,
9026 creation_date,
9027 created_by,
9028 last_update_date,
9029 last_updated_by,
9030 last_update_login,
9031 fm_serial_number,
9032 to_serial_number
9033 )
9034 SELECT DECODE(msi.lot_control_code,
9035 WIP_CONSTANTS.LOT, mtli.serial_transaction_temp_id,
9036 mti.transaction_interface_id),
9037 mti.creation_date,
9038 mti.created_by,
9039 mti.last_update_date,
9040 mti.last_updated_by,
9041 mti.last_update_login,
9042 wsmi.assembly_serial_number,
9043 wsmi.assembly_serial_number
9044 FROM mtl_transactions_interface mti,
9045 mtl_system_items msi,
9046 mtl_transaction_lots_interface mtli,
9047 wip_serial_move_interface wsmi
9048 WHERE mti.organization_id = msi.organization_id
9049 AND mti.inventory_item_id = msi.inventory_item_id
9050 AND mti.transaction_header_id = p_gib.assy_header_id
9051 AND mti.transaction_action_id = l_txn_action_id
9052 AND mti.transaction_type_id = l_txn_type_id
9053 AND mti.transaction_source_type_id = TPS_INV_JOB_OR_SCHED
9054 AND mti.wip_entity_type IN (WIP_CONSTANTS.DISCRETE,
9055 WIP_CONSTANTS.LOTBASED)/*WSM */
9056 AND msi.serial_number_control_code IN (WIP_CONSTANTS.FULL_SN,
9057 WIP_CONSTANTS.DYN_RCV_SN)
9058 AND mti.transaction_interface_id = mtli.transaction_interface_id(+)
9059 AND mti.move_transaction_id = wsmi.transaction_id;
9060
9061 -- IF debug message level = 2, write statement below to log file
9062 IF (l_logLevel <= wip_constants.full_logging) THEN
9063 fnd_message.set_name('WIP', 'WIP_INSERTED_ROWS');
9064 fnd_message.set_token('ENTITY1', SQL%ROWCOUNT);
9065 fnd_message.set_token('ENTITY2', 'MTL_SERIAL_NUMBERS_INTERFACE');
9066 l_msg := fnd_message.get;
9067 wip_logger.log(p_msg => l_msg,
9068 x_returnStatus => l_returnStatus);
9069 END IF;
9070 END IF; -- Discrete or OSFM jobs
9071
9072 IF(p_gib.move_mode = WIP_CONSTANTS.ONLINE) THEN
9073 l_addMsgToStack := fnd_api.g_true;
9074 ELSE
9075 -- Message stack is only useful for online transaction. For background,
9076 -- we never used message stack.
9077 l_addMsgToStack := fnd_api.g_false;
9078 END IF;
9079 -- Move all assembly records from mti to mmtt
9080 wip_mtlTempProc_priv.validateInterfaceTxns(
9081 p_txnHdrID => p_gib.assy_header_id,
9082 p_addMsgToStack => l_addMsgToStack,
9083 p_rollbackOnErr => fnd_api.g_false,
9084 x_returnStatus => x_returnStatus);
9085
9086 IF(x_returnStatus <> fnd_api.g_ret_sts_success) THEN
9087 --FP bug 5752485 (base bug 4128207) Added the IF condition below since write_mtl_errors
9088 --is not applicable for ONLINE completions. Otherwise the fnd_msg_pub stack is initialized
9089 --inside write_mtl_errors which suppresses messages to be shown to the user in the UI
9090 IF (l_transaction_mode <> WIP_CONSTANTS.ONLINE) THEN
9091 -- write mtl error message into WIP_TXN_INTERFACE_ERRORS
9092 write_mtl_errors(p_mtl_header_id => p_gib.assy_header_id);
9093 END IF;
9094 l_errMsg := 'wip_mtlTempProc_priv.validateInterfaceTxns failed' ||
9095 ' (assembly records)' ;
9096 raise fnd_api.g_exc_unexpected_error;
9097 END IF;
9098
9099 FOR l_repAssembly IN c_repAssembly(p_header_id => p_gib.assy_header_id) LOOP
9100 -- Preallocate if repetitive schedule. This API will allocate primary
9101 -- quantity to appropriate schedules.
9102 wip_cplProc_priv.preAllocateSchedules(
9103 p_txnHdrID => p_gib.assy_header_id,
9104 p_cplTxnID => l_repAssembly.cpl_txn_id,
9105 p_txnActionID => l_repAssembly.txn_action_id,
9106 p_wipEntityID => l_repAssembly.txn_src_id,
9107 p_repLineID => l_repAssembly.rep_line_id,
9108 p_tblName => WIP_CONSTANTS.MMTT_TBL,
9109 p_endDebug => fnd_api.g_false,
9110 x_returnStatus => x_returnStatus);
9111
9112 IF(x_returnStatus <> fnd_api.g_ret_sts_success) THEN
9113 l_errMsg := 'wip_cplProc_priv.preAllocateSchedules failed' ;
9114 raise fnd_api.g_exc_unexpected_error;
9115 END IF;
9116 END LOOP;
9117
9118 IF(p_gib.move_mode = WIP_CONSTANTS.ONLINE) THEN
9119 snapshot_online(p_mtl_header_id => p_gib.assy_header_id,
9120 p_org_id => l_move.org_id,
9121 p_txn_type => p_txn_type,
9122 p_txn_type_id => l_txn_type_id,
9123 p_txn_action_id => l_txn_action_id,
9124 x_returnStatus => x_returnStatus);
9125
9126 IF(x_returnStatus <> fnd_api.g_ret_sts_success) THEN
9127 l_errMsg := 'wip_movProc_priv.snapshot_online failed';
9128 raise fnd_api.g_exc_unexpected_error;
9129 END IF; -- check return status
9130 ELSE -- move is background
9131 IF(p_txn_type = WIP_CONSTANTS.RET_TXN) THEN
9132 snapshot_background(p_group_id => p_gib.group_id,
9133 p_txn_date => p_gib.txn_date,
9134 x_returnStatus => x_returnStatus);
9135
9136 IF(x_returnStatus <> fnd_api.g_ret_sts_success) THEN
9137 l_errMsg := 'wip_movProc_priv.snapshot_background failed';
9138 raise fnd_api.g_exc_unexpected_error;
9139 END IF; -- check return status
9140 END IF; -- return transaction
9141 END IF; -- move mode check
9142
9143 x_returnStatus := fnd_api.g_ret_sts_success;
9144
9145 -- write to the log file
9146 IF (l_logLevel <= wip_constants.trace_logging) THEN
9147 wip_logger.exitPoint(p_procName => 'wip_movProc_priv.ez_completion',
9148 p_procReturnStatus => x_returnStatus,
9149 p_msg => 'procedure complete',
9150 x_returnStatus => l_returnStatus);
9151 END IF;
9152
9153 EXCEPTION
9154 WHEN fnd_api.g_exc_unexpected_error THEN
9155 x_returnStatus := fnd_api.g_ret_sts_unexp_error;
9156 IF (l_logLevel <= wip_constants.trace_logging) THEN
9157 wip_logger.exitPoint(p_procName =>'wip_movProc_priv.ez_completion',
9158 p_procReturnStatus => x_returnStatus,
9159 p_msg => l_errMsg,
9160 x_returnStatus => l_returnStatus);
9161 END IF;
9162
9163 WHEN others THEN
9164 x_returnStatus := fnd_api.g_ret_sts_unexp_error;
9165 l_errMsg := 'unexpected error: ' || SQLERRM || 'SQLCODE = ' || SQLCODE;
9166
9167 IF (l_logLevel <= wip_constants.trace_logging) THEN
9168 wip_logger.exitPoint(p_procName=>'wip_movProc_priv.ez_completion',
9169 p_procReturnStatus => x_returnStatus,
9170 p_msg => l_errMsg,
9171 x_returnStatus => l_returnStatus);
9172 END IF;
9173 fnd_message.set_name('FND', 'FND_GENERIC_MESSAGE');
9174 fnd_message.set_token('MESSAGE', l_errMsg);
9175 fnd_msg_pub.add;
9176 END ez_completion;
9177
9178 /*****************************************************************************
9179 * This procedure is equivalent to witoc_update_wro in wiltps5.ppc
9180 * This update statement in this procedure is equivalent to the one in
9181 * WIP_OVERCOMPLETION.update_wip_req_operations. This procedure is used to
9182 * update WIP_REQUIREMENT_OPERATIONS table
9183 ****************************************************************************/
9184 PROCEDURE update_wro(p_gib IN group_rec_t,
9185 x_returnStatus OUT NOCOPY VARCHAR2) IS
9186
9187 l_params wip_logger.param_tbl_t;
9188 l_returnStatus VARCHAR(1);
9189 l_errMsg VARCHAR2(240);
9190 l_logLevel NUMBER := fnd_log.g_current_runtime_level;
9191
9192 BEGIN
9193 IF (l_logLevel <= wip_constants.trace_logging) THEN
9194 l_params(1).paramName := 'p_group_id';
9195 l_params(1).paramValue := p_gib.group_id;
9196 l_params(2).paramName := 'p_txn_date';
9197 l_params(2).paramValue := p_gib.txn_date;
9198 wip_logger.entryPoint(p_procName =>'wip_movProc_priv.update_wro',
9199 p_params => l_params,
9200 x_returnStatus => l_returnStatus);
9201 END IF;
9202
9203 UPDATE wip_requirement_operations wro
9204 SET (wro.required_quantity,
9205 last_updated_by,
9206 last_update_date,
9207 last_update_login,
9208 request_id,
9209 program_application_id,
9210 program_id,
9211 program_update_date) =
9212 (SELECT MIN(required_quantity) + (NVL(SUM(
9213 NVL(wma1.primary_quantity, wmti1.primary_quantity)),0)
9214 --Bug 5476966:Division by yield is added.
9215 * MIN(quantity_per_assembly)/min(nvl(component_yield_factor,
9216 1))),
9217 p_gib.user_id,
9218 SYSDATE,
9219 DECODE(p_gib.login_id,-1,NULL,p_gib.login_id),
9220 DECODE(p_gib.request_id,-1,NULL,p_gib.request_id),
9221 DECODE(p_gib.application_id,-1,NULL,p_gib.application_id),
9222 DECODE(p_gib.program_id,-1,NULL,p_gib.program_id),
9223 DECODE(p_gib.request_id,-1,NULL,SYSDATE)
9224 FROM wip_requirement_operations wro1,
9225 wip_move_txn_interface wmti1,
9226 wip_move_txn_allocations wma1
9227 WHERE wro1.rowid = wro.rowid
9228 -- The WO rows to be updated are identIFied by the rowids.
9229 -- For each such row, go back and sum the quantities from WMTI
9230 AND wmti1.group_id = p_gib.group_id
9231 AND wmti1.process_phase = WIP_CONSTANTS.MOVE_PROC
9232 AND wmti1.process_status = WIP_CONSTANTS.RUNNING
9233 AND TRUNC(wmti1.transaction_date) = TRUNC(p_gib.txn_date)
9234 AND wmti1.overcompletion_transaction_id IS NOT NULL
9235 AND wmti1.overcompletion_primary_qty IS NULL
9236 AND wro1.wip_entity_id = wmti1.wip_entity_id
9237 AND wro1.organization_id = wmti1.organization_id
9238 AND wmti1.organization_id = wma1.organization_id (+)
9239 AND wmti1.transaction_id = wma1.transaction_id (+)
9240 AND NVL(wma1.repetitive_schedule_id,0)
9241 = NVL(wro1.repetitive_schedule_id,0)
9242 )
9243 WHERE wro.rowid in
9244 (SELECT wro2.rowid
9245 FROM wip_requirement_operations wro2,
9246 wip_move_txn_interface wmti2,
9247 wip_move_txn_allocations wma2
9248 WHERE wmti2.group_id = p_gib.group_id
9249 AND wmti2.process_phase = WIP_CONSTANTS.MOVE_PROC
9250 AND wmti2.process_status = WIP_CONSTANTS.RUNNING
9251 AND TRUNC(wmti2.transaction_date) = TRUNC(p_gib.txn_date)
9252 AND wmti2.overcompletion_transaction_id IS NOT NULL
9253 AND wmti2.overcompletion_primary_qty IS NULL
9254 -- Picked a Move txn
9255 AND wro2.wip_entity_id = wmti2.wip_entity_id
9256 AND wro2.organization_id = wmti2.organization_id
9257 AND wmti2.organization_id = wma2.organization_id (+)
9258 AND wmti2.transaction_id = wma2.transaction_id (+)
9259 AND NVL(wma2.repetitive_schedule_id,0)
9260 = NVL(wro2.repetitive_schedule_id,0))
9261 AND nvl(wro.basis_type,1) <> WIP_CONSTANTS.LOT_BASED_MTL; /* LBM Project */
9262
9263 x_returnStatus := fnd_api.g_ret_sts_success;
9264
9265 -- write to the log file
9266 IF (l_logLevel <= wip_constants.trace_logging) THEN
9267 wip_logger.exitPoint(p_procName => 'wip_movProc_priv.update_wro',
9268 p_procReturnStatus => x_returnStatus,
9269 p_msg => 'procedure complete',
9270 x_returnStatus => l_returnStatus);
9271 END IF;
9272
9273 EXCEPTION
9274 WHEN others THEN
9275 x_returnStatus := fnd_api.g_ret_sts_unexp_error;
9276 l_errMsg := 'unexpected error: ' || SQLERRM || 'SQLCODE = ' || SQLCODE;
9277
9278 IF (l_logLevel <= wip_constants.trace_logging) THEN
9279 wip_logger.exitPoint(p_procName=>'wip_movProc_priv.update_wro',
9280 p_procReturnStatus => x_returnStatus,
9281 p_msg => l_errMsg,
9282 x_returnStatus => l_returnStatus);
9283 END IF;
9284 fnd_message.set_name('FND', 'FND_GENERIC_MESSAGE');
9285 fnd_message.set_token('MESSAGE', l_errMsg);
9286 fnd_msg_pub.add;
9287 END update_wro;
9288
9289 /*****************************************************************************
9290 * This procedure is equivalent to wiltps in wiltps5.ppc
9291 * This is the main api to do move transactions
9292 ****************************************************************************/
9293
9294 PROCEDURE move_txns(p_gib IN OUT NOCOPY group_rec_t,
9295 x_returnStatus OUT NOCOPY VARCHAR2) IS
9296
9297 l_params wip_logger.param_tbl_t;
9298 l_returnStatus VARCHAR(1);
9299 l_errMsg VARCHAR(240);
9300 l_move move_profile_rec_t;
9301 l_po BOOLEAN;
9302 l_poStatus VARCHAR(1);
9303 l_poIndustry VARCHAR(1);
9304 l_poSchema VARCHAR(10);
9305 l_logLevel NUMBER := fnd_log.g_current_runtime_level;
9306
9307 BEGIN
9308 l_move := p_gib.move_profile;
9309
9310 IF (l_logLevel <= wip_constants.trace_logging) THEN
9311 l_params(1).paramName := 'p_group_id';
9312 l_params(1).paramValue := p_gib.group_id;
9313 l_params(2).paramName := 'p_mtl_header_id';
9314 l_params(2).paramValue := p_gib.mtl_header_id;
9315 l_params(3).paramName := 'p_move_mode';
9316 l_params(3).paramValue := p_gib.move_mode;
9317 l_params(4).paramName := 'p_bf_mode';
9318 l_params(4).paramValue := p_gib.bf_mode;
9319 l_params(5).paramName := 'p_mtl_mode';
9320 l_params(5).paramValue := p_gib.mtl_mode;
9321 l_params(6).paramName := 'p_txn_date';
9322 l_params(6).paramValue := p_gib.txn_date;
9323 l_params(7).paramName := 'p_process_phase';
9324 l_params(7).paramValue := p_gib.process_phase;
9325 l_params(8).paramName := 'p_process_status';
9326 l_params(8).paramValue := p_gib.process_status;
9327 l_params(9).paramName := 'p_time_out';
9328 l_params(9).paramValue := p_gib.time_out;
9329 l_params(10).paramName := 'p_intf_tbl_name';
9330 l_params(10).paramValue := p_gib.intf_tbl_name;
9331 l_params(11).paramName := 'p_user_id';
9332 l_params(11).paramValue := p_gib.user_id;
9333 l_params(12).paramName := 'p_login_id';
9334 l_params(12).paramValue := p_gib.login_id;
9335 l_params(13).paramName := 'p_request_id';
9336 l_params(13).paramValue := p_gib.request_id;
9337 l_params(14).paramName := 'p_application_id';
9338 l_params(14).paramValue := p_gib.application_id;
9339 l_params(15).paramName := 'p_program_id';
9340 l_params(15).paramValue := p_gib.program_id;
9341 l_params(16).paramName := 'p_org_id';
9342 l_params(16).paramValue := l_move.org_id;
9343 l_params(17).paramName := 'p_wip_id';
9344 l_params(17).paramValue := l_move.wip_id;
9345 l_params(18).paramName := 'p_entity_type';
9346 l_params(18).paramValue := l_move.entity_type;
9347 l_params(19).paramName := 'p_fmOp';
9348 l_params(19).paramValue := l_move.fmOp;
9349 l_params(20).paramName := 'p_fmStep';
9350 l_params(20).paramValue := l_move.fmStep;
9351 l_params(21).paramName := 'p_toOp';
9352 l_params(21).paramValue := l_move.toOp;
9353 l_params(22).paramName := 'p_toStep';
9354 l_params(22).paramValue := l_move.toStep;
9355 l_params(23).paramName := 'p_scrapTxn';
9356 l_params(23).paramValue := l_move.scrapTxn;
9357 l_params(24).paramName := 'p_easyComplete';
9358 l_params(24).paramValue := l_move.easyComplete;
9359 l_params(25).paramName := 'p_easyReturn';
9360 l_params(25).paramValue := l_move.easyReturn;
9361 l_params(26).paramName := 'p_jobTxn';
9362 l_params(26).paramValue := l_move.jobTxn;
9363 l_params(27).paramName := 'p_scheTxn';
9364 l_params(27).paramValue := l_move.scheTxn;
9365 l_params(28).paramName := 'p_rsrcItem';
9366 l_params(28).paramValue := l_move.rsrcItem;
9367 l_params(29).paramName := 'p_rsrcLot';
9368 l_params(29).paramValue := l_move.rsrcLot;
9369 l_params(30).paramName := 'p_poReqItem';
9370 l_params(30).paramValue := l_move.poReqItem;
9371 l_params(31).paramName := 'p_poReqLot';
9372 l_params(31).paramValue := l_move.poReqLot;
9373 wip_logger.entryPoint(p_procName =>'wip_movProc_priv.move_txns',
9374 p_params => l_params,
9375 x_returnStatus => l_returnStatus);
9376 END IF;
9377
9378 -- Lock record in WIP_OPERATIONS table
9379 lock_wipops(p_gib => p_gib,
9380 x_returnStatus => x_returnStatus);
9381
9382 IF(x_returnStatus <> fnd_api.g_ret_sts_success) THEN
9383 l_errMsg := 'wip_movProc_priv.lock_wipops failed';
9384 raise fnd_api.g_exc_unexpected_error;
9385 END IF; -- check return status
9386
9387 -- Call repetitive allocatioin for repetitive schedule
9388 IF(l_move.scheTxn = WIP_CONSTANTS.YES) THEN
9389 rep_move_alloc(p_gib => p_gib,
9390 x_returnStatus => x_returnStatus);
9391
9392 IF(x_returnStatus <> fnd_api.g_ret_sts_success) THEN
9393 l_errMsg := 'wip_movProc_priv.rep_move_alloc failed';
9394 raise fnd_api.g_exc_unexpected_error;
9395 END IF; -- check return status
9396 END IF; -- check repetitive schedules
9397
9398 -- Check for the step unit quantities for discrete and OSFM jobs
9399 IF(l_move.jobTxn = WIP_CONSTANTS.YES) THEN
9400 check_qty_dj(p_gib => p_gib,
9401 x_returnStatus => x_returnStatus);
9402
9403 IF(x_returnStatus <> fnd_api.g_ret_sts_success) THEN
9404 l_errMsg := 'wip_movProc_priv.check_qty_dj failed';
9405 raise fnd_api.g_exc_unexpected_error;
9406 END IF; -- check return status
9407 END IF; -- check discrete and OSFM jobs
9408
9409 -- Lock record in WIP_OPERATIONS table
9410 -- Update the WRO quantities for the Overcompletion
9411 update_wro(p_gib => p_gib,
9412 x_returnStatus => x_returnStatus);
9413
9414 IF(x_returnStatus <> fnd_api.g_ret_sts_success) THEN
9415 l_errMsg := 'wip_movProc_priv.update_wro failed';
9416 raise fnd_api.g_exc_unexpected_error;
9417 END IF; -- check return status
9418
9419 -- Record move transactions history in WIP_MOVE_TRANSACTIONS
9420 insert_txn_history(p_gib => p_gib,
9421 x_returnStatus => x_returnStatus);
9422
9423 IF(x_returnStatus <> fnd_api.g_ret_sts_success) THEN
9424 l_errMsg := 'wip_movProc_priv.insert_txn_history failed';
9425 raise fnd_api.g_exc_unexpected_error;
9426 END IF; -- check return status
9427
9428 -- Delete child record (overmove/overcompletion/overreturn)
9429 delete_child_txn(p_gib => p_gib,
9430 x_returnStatus => x_returnStatus);
9431
9432 -- Delete child record (overmove/overcompletion/overreturn)
9433 IF(x_returnStatus <> fnd_api.g_ret_sts_success) THEN
9434 l_errMsg := 'wip_movProc_priv.delete_child_txn failed';
9435 raise fnd_api.g_exc_unexpected_error;
9436 END IF; -- check return status
9437
9438 -- Delete child record (overmove/overcompletion/overreturn)
9439 -- Insert auto-resources associated with move
9440 -- (insert into WIP_COST_TXN_INTERFACE)
9441 insert_auto_resource(p_gib => p_gib,
9442 x_returnStatus => x_returnStatus);
9443
9444 IF(x_returnStatus <> fnd_api.g_ret_sts_success) THEN
9445 l_errMsg := 'wip_movProc_priv.insert_auto_resource failed';
9446 raise fnd_api.g_exc_unexpected_error;
9447 END IF; -- check return status
9448
9449 -- Only call the cost allocation IF schedule transactions and auto resource
9450 -- per item exist (insert into WIP_TXN_ALLOCATIONS)
9451 IF(l_move.scheTxn = WIP_CONSTANTS.YES AND
9452 l_move.rsrcItem = WIP_CONSTANTS.YES) THEN
9453
9454 insert_txn_alloc(p_gib => p_gib,
9455 x_returnStatus => x_returnStatus);
9456
9457 IF(x_returnStatus <> fnd_api.g_ret_sts_success) THEN
9458 l_errMsg := 'wip_movProc_priv.insert_txn_alloc failed';
9459 raise fnd_api.g_exc_unexpected_error;
9460 END IF; -- check return status
9461 END IF; -- repetitive schedule and resource per item exist
9462
9463 -- Insert department overhead into WIP_COST_TXN_INTERFACE
9464 insert_dept_overhead(p_gib => p_gib,
9465 x_returnStatus => x_returnStatus);
9466
9467 IF(x_returnStatus <> fnd_api.g_ret_sts_success) THEN
9468 l_errMsg := 'wip_movProc_priv.insert_dept_overhead failed';
9469 raise fnd_api.g_exc_unexpected_error;
9470 END IF; -- check return status
9471
9472 -- Release costing transactions
9473 release_cost_txn(p_gib => p_gib,
9474 x_returnStatus => x_returnStatus);
9475
9476 IF(x_returnStatus <> fnd_api.g_ret_sts_success) THEN
9477 l_errMsg := 'wip_movProc_priv.release_cost_txn failed';
9478 raise fnd_api.g_exc_unexpected_error;
9479 END IF; -- check return status
9480
9481 -- IF PO installed and PO, insert PO info into PO_REQUISITIONS_INTERFACE_ALL
9482 l_po := fnd_installation.get_app_info
9483 (application_short_name => 'PO',
9484 status => l_poStatus,
9485 industry => l_poIndustry,
9486 oracle_schema => l_poSchema);
9487
9488 IF(l_po = FALSE) THEN -- there is an error calling fnd_installion package
9489 l_errMsg := 'fnd_installation.get_app_info failed';
9490 raise fnd_api.g_exc_unexpected_error;
9491 ELSE -- no error
9492 IF(l_poStatus = 'I') THEN -- IF PO installed, insert PO info
9493 insert_po_req(p_gib => p_gib,
9494 x_returnStatus => x_returnStatus);
9495
9496 IF(x_returnStatus <> fnd_api.g_ret_sts_success) THEN
9497 l_errMsg := 'wip_movProc_priv.insert_po_req failed';
9498 raise fnd_api.g_exc_unexpected_error;
9499 END IF; -- check return status
9500 END IF;
9501 END IF;
9502
9503 IF(p_gib.move_mode = WIP_CONSTANTS.ONLINE) THEN
9504 -- Only update quantity_completed if online. For background, we will update
9505 -- quantity completed in update_wo_and_snapshot
9506 update_complete_qty(p_gib => p_gib,
9507 x_returnStatus => x_returnStatus);
9508
9509 IF(x_returnStatus <> fnd_api.g_ret_sts_success) THEN
9510 l_errMsg := 'wip_movProc_priv.update_complete_qty failed';
9511 raise fnd_api.g_exc_unexpected_error;
9512 END IF; -- check return status
9513 END IF;
9514
9515 -- Update scrap quantity in WIP_DISCRETE_JOBS and insert into MMTT IF
9516 -- scrap account provided
9517 scrap_txns(p_gib => p_gib,
9518 x_returnStatus => x_returnStatus);
9519
9520 IF(x_returnStatus <> fnd_api.g_ret_sts_success) THEN
9521 l_errMsg := 'wip_movProc_priv.scrap_txns failed';
9522 raise fnd_api.g_exc_unexpected_error;
9523 END IF; -- check return status
9524
9525 -- Start workflow for OSP stuff
9526 start_workflow(p_gib => p_gib,
9527 x_returnStatus => x_returnStatus);
9528
9529 IF(x_returnStatus <> fnd_api.g_ret_sts_success) THEN
9530 l_errMsg := 'wip_movProc_priv.start_workflow failed';
9531 raise fnd_api.g_exc_unexpected_error;
9532 END IF; -- check return status
9533
9534 x_returnStatus := fnd_api.g_ret_sts_success;
9535
9536 -- write to the log file
9537 IF (l_logLevel <= wip_constants.trace_logging) THEN
9538 wip_logger.exitPoint(p_procName => 'wip_movProc_priv.move_txns',
9539 p_procReturnStatus => x_returnStatus,
9540 p_msg => 'procedure complete',
9541 x_returnStatus => l_returnStatus);
9542 END IF;
9543
9544 EXCEPTION
9545 WHEN fnd_api.g_exc_unexpected_error THEN
9546 x_returnStatus := fnd_api.g_ret_sts_unexp_error;
9547 IF (l_logLevel <= wip_constants.trace_logging) THEN
9548 wip_logger.exitPoint(p_procName =>'wip_movProc_priv.move_txns',
9549 p_procReturnStatus => x_returnStatus,
9550 p_msg => l_errMsg,
9551 x_returnStatus => l_returnStatus);
9552 END IF;
9553
9554 WHEN others THEN
9555 x_returnStatus := fnd_api.g_ret_sts_unexp_error;
9556 l_errMsg := 'unexpected error: ' || SQLERRM || 'SQLCODE = ' || SQLCODE;
9557
9558 IF (l_logLevel <= wip_constants.trace_logging) THEN
9559 wip_logger.exitPoint(p_procName=>'wip_movProc_priv.move_txns',
9560 p_procReturnStatus => x_returnStatus,
9561 p_msg => l_errMsg,
9562 x_returnStatus => l_returnStatus);
9563 END IF;
9564 fnd_message.set_name('FND', 'FND_GENERIC_MESSAGE');
9565 fnd_message.set_token('MESSAGE', l_errMsg);
9566 fnd_msg_pub.add;
9567 END move_txns;
9568
9569 /*****************************************************************************
9570 * This procedure is equivalent to SF_MOVE in wiutps.ppc + EASY_COMPLETE in
9571 * wiutez.ppc for ON-LINE transactions. It is also equivalent to wiltws in
9572 * wiltws.ppc for BACKGROUND transactions.
9573 *
9574 * This is the main api to do move, scrap, easy complete, and easy return.
9575 ****************************************************************************/
9576
9577 PROCEDURE processIntf(p_group_id IN NUMBER,
9578 p_proc_phase IN NUMBER,
9579 p_time_out IN NUMBER,
9580 p_move_mode IN NUMBER,
9581 p_bf_mode IN NUMBER,
9582 p_mtl_mode IN NUMBER,
9583 p_ENDDebug IN VARCHAR2,
9584 p_initMsgList IN VARCHAR2,
9585 p_insertAssy IN VARCHAR2,
9586 p_do_backflush IN VARCHAR2,
9587 p_child_txn_id IN NUMBER := NULL,
9588 p_assy_header_id IN NUMBER := NULL,
9589 p_mtl_header_id IN NUMBER := NULL,
9590 p_cmp_txn_id IN NUMBER := NULL,
9591 p_seq_move IN NUMBER := NULL,
9592 -- Fixed bug 4361566.
9593 p_allow_partial_commit IN NUMBER := NULL,
9594 x_returnStatus OUT NOCOPY VARCHAR2) IS
9595
9596 CURSOR c_backflush(p_txn_date DATE) IS
9597 SELECT wmti.wip_entity_id wip_id,
9598 wmti.organization_id org_id,
9599 wmti.transaction_date txn_date,
9600 wmti.primary_quantity primary_qty,
9601 wmti.transaction_type txn_type,
9602 wmti.entity_type ent_type,
9603 wmti.line_id line_id,
9604 wmti.fm_operation_seq_num fm_op,
9605 wmti.to_operation_seq_num to_op,
9606 wmti.fm_intraoperation_step_type fm_step,
9607 wmti.to_intraoperation_step_type to_step,
9608 wmti.transaction_id txn_id,
9609 wmti.reason_id reason_id,
9610 wmti.reference reference
9611 FROM wip_move_txn_interface wmti
9612 WHERE wmti.group_id = p_group_id
9613 AND TRUNC(wmti.transaction_date)= TRUNC(p_txn_date)
9614 AND wmti.process_phase = WIP_CONSTANTS.BF_SETUP
9615 AND wmti.process_status = WIP_CONSTANTS.RUNNING;
9616
9617 CURSOR c_move_online IS
9618 SELECT NVL(last_updated_by, -1) user_id,
9619 NVL(last_update_login, -1) login_id,
9620 NVL(request_id, -1) req_id,
9621 NVL(program_application_id, -1) appl_id,
9622 NVL(program_id, -1) prog_id,
9623 transaction_type txn_type,
9624 organization_id org_id,
9625 wip_entity_id wip_id,
9626 entity_type,
9627 transaction_date txn_date,
9628 process_status proc_status,
9629 fm_operation_seq_num fm_op,
9630 fm_intraoperation_step_type fm_step,
9631 to_operation_seq_num to_op,
9632 to_intraoperation_step_type to_step
9633 FROM wip_move_txn_interface
9634 WHERE group_id = p_group_id
9635 /* Comment out the check below because UI may need to use validation logic */
9636 -- AND process_phase = WIP_CONSTANTS.MOVE_PROC
9637 AND process_status = WIP_CONSTANTS.RUNNING;
9638
9639 CURSOR c_qa_id(p_txn_date DATE) IS
9640 SELECT qa_collection_id
9641 FROM wip_move_txn_interface
9642 WHERE group_id = p_group_id
9643 AND process_phase = WIP_CONSTANTS.MOVE_PROC
9644 AND process_status = WIP_CONSTANTS.RUNNING
9645 AND TRUNC(transaction_date)= TRUNC(p_txn_date)
9646 -- Only enable QA for move, scrap and reject. For EZ completion/return,
9647 -- material processor will call it.
9648 AND transaction_type = WIP_CONSTANTS.MOVE_TXN
9649 AND qa_collection_id IS NOT NULL;
9650
9651 CURSOR c_txn_date IS
9652 SELECT DISTINCT TRUNC(transaction_date)
9653 FROM wip_move_txn_interface
9654 WHERE group_id = p_group_id
9655 AND process_status = WIP_CONSTANTS.RUNNING;
9656
9657 l_gib group_rec_t;
9658 l_move_online c_move_online%ROWTYPE;
9659 l_backflush c_backflush%ROWTYPE;
9660 l_params wip_logger.param_tbl_t;
9661 l_returnStatus VARCHAR(1);
9662 l_errMsg VARCHAR(2000);
9663 l_msg VARCHAR(240);
9664 l_bf_mode NUMBER;
9665 l_mtl_mode NUMBER;
9666 l_job NUMBER;
9667 l_sche NUMBER;
9668 l_qa_collection_id NUMBER;
9669 l_err_record NUMBER := 0;
9670 l_txn_tmp_id NUMBER;
9671 l_msgCount NUMBER;
9672 l_MMTT_record NUMBER;
9673 l_returnCode NUMBER;
9674 l_first_bf_op NUMBER := -1;
9675 l_last_bf_op NUMBER := -1;
9676 l_bf_qty NUMBER;
9677 l_forward NUMBER;
9678 l_mov_txn_id NUMBER;
9679 l_logLevel NUMBER := fnd_log.g_current_runtime_level;
9680 l_bf_required NUMBER; -- throw away value
9681 l_ls_required NUMBER;
9682 -- New variable to pass to OSFM new backflush API.
9683 l_error_msg VARCHAR2(1000);
9684 l_error_count NUMBER;
9685 -- Fixed bug 4361566
9686 l_return_hdr_id NUMBER := -1;
9687 BEGIN
9688
9689 IF(fnd_api.to_boolean(p_initMsgList)) THEN
9690 fnd_msg_pub.initialize;
9691 END IF;
9692
9693 IF (l_logLevel <= wip_constants.trace_logging) THEN
9694 l_params(1).paramName := 'p_group_id';
9695 l_params(1).paramValue := p_group_id;
9696 l_params(2).paramName := 'p_child_txn_id';
9697 l_params(2).paramValue := p_child_txn_id;
9698 l_params(3).paramName := 'p_mtl_header_id';
9699 l_params(3).paramValue := p_mtl_header_id;
9700 l_params(4).paramName := 'p_proc_phase';
9701 l_params(4).paramValue := p_proc_phase;
9702 l_params(5).paramName := 'p_time_out';
9703 l_params(5).paramValue := p_time_out;
9704 l_params(6).paramName := 'p_move_mode';
9705 l_params(6).paramValue := p_move_mode;
9706 l_params(7).paramName := 'p_bf_mode';
9707 l_params(7).paramValue := p_bf_mode;
9708 l_params(8).paramName := 'p_mtl_mode';
9709 l_params(8).paramValue := p_mtl_mode;
9710 l_params(9).paramName := 'p_insertAssy';
9711 l_params(9).paramValue := p_insertAssy;
9712 l_params(10).paramName := 'p_do_backflush';
9713 l_params(10).paramValue := p_do_backflush;
9714 l_params(11).paramName := 'p_cmp_txn_id';
9715 l_params(11).paramValue := p_cmp_txn_id;
9716 l_params(11).paramName := 'p_seq_move';
9717 l_params(11).paramValue := p_seq_move;
9718 l_params(12).paramName := 'p_assy_header_id';
9719 l_params(12).paramValue := p_assy_header_id;
9720 l_params(13).paramName := 'p_allow_partial_commit';
9721 l_params(13).paramValue := p_allow_partial_commit;
9722
9723 wip_logger.entryPoint(p_procName =>'wip_movProc_priv.processIntf',
9724 p_params => l_params,
9725 x_returnStatus => l_returnStatus);
9726 END IF;
9727
9728 IF(p_move_mode = WIP_CONSTANTS.ONLINE) THEN
9729
9730 -- this cursor suppose to return only one record because transaction_id
9731 -- is primary_key
9732 FOR l_move_online IN c_move_online LOOP
9733
9734 -- initialize value for l_move
9735 l_gib.move_profile.child_txn_id := p_child_txn_id;
9736 l_gib.move_profile.cmp_txn_id := p_cmp_txn_id;
9737 l_gib.move_profile.org_id := l_move_online.org_id;
9738 l_gib.move_profile.wip_id := l_move_online.wip_id;
9739 l_gib.move_profile.entity_type := l_move_online.entity_type;
9740 l_gib.move_profile.fmOp := l_move_online.fm_op;
9741 l_gib.move_profile.fmStep := l_move_online.fm_step;
9742 l_gib.move_profile.toOp := l_move_online.to_op;
9743 l_gib.move_profile.toStep := l_move_online.to_step;
9744
9745 IF(l_move_online.txn_type = WIP_CONSTANTS.COMP_TXN) THEN
9746 l_gib.move_profile.easyComplete := WIP_CONSTANTS.YES;
9747 ELSE
9748 l_gib.move_profile.easyComplete := WIP_CONSTANTS.NO;
9749 END IF;
9750
9751 IF(l_move_online.txn_type = WIP_CONSTANTS.RET_TXN) THEN
9752 l_gib.move_profile.easyReturn := WIP_CONSTANTS.YES;
9753 ELSE
9754 l_gib.move_profile.easyReturn := WIP_CONSTANTS.NO;
9755 END IF;
9756
9757 IF(l_move_online.entity_type = WIP_CONSTANTS.DISCRETE OR
9758 l_move_online.entity_type = WIP_CONSTANTS.LOTBASED) THEN
9759 l_gib.move_profile.jobTxn := WIP_CONSTANTS.YES;
9760 ELSE
9761 l_gib.move_profile.jobTxn := WIP_CONSTANTS.NO;
9762 END IF;
9763
9764 IF(l_move_online.entity_type = WIP_CONSTANTS.REPETITIVE) THEN
9765 l_gib.move_profile.scheTxn := WIP_CONSTANTS.YES;
9766 ELSE
9767 l_gib.move_profile.scheTxn := WIP_CONSTANTS.NO;
9768 END IF;
9769 -- the others 4 parameters will be initialized in get_move_profile()
9770 -- rsrcItem, rsrcLot, poReqItem, poReqLot
9771
9772 -- initialize value for l_gib
9773 l_gib.group_id := p_group_id;
9774 l_gib.assy_header_id := p_assy_header_id;
9775 l_gib.mtl_header_id := p_mtl_header_id;
9776 l_gib.move_mode := WIP_CONSTANTS.ONLINE;
9777 l_gib.bf_mode := p_bf_mode; -- l_bf_mode;
9778 l_gib.mtl_mode := p_mtl_mode; -- l_mtl_mode;
9779 l_gib.process_phase := WIP_CONSTANTS.MOVE_PROC;
9780 l_gib.process_status := WIP_CONSTANTS.RUNNING;
9781 l_gib.time_out := p_time_out;
9782 l_gib.intf_tbl_name := 'WIP_MOVE_TXN_INTERFACE';
9783 l_gib.user_id := l_move_online.user_id;
9784 l_gib.login_id := l_move_online.login_id;
9785 l_gib.request_id := l_move_online.req_id;
9786 l_gib.application_id := l_move_online.appl_id;
9787 l_gib.program_id := l_move_online.prog_id;
9788 l_gib.seq_move := WIP_CONSTANTS.NO;
9789 END LOOP; -- c_move_online
9790 ELSE -- move mode is background
9791 l_gib.group_id := p_group_id;
9792 l_gib.assy_header_id := p_assy_header_id;
9793 l_gib.mtl_header_id := p_mtl_header_id;
9794 l_gib.move_mode := WIP_CONSTANTS.BACKGROUND;
9795 l_gib.bf_mode := p_bf_mode; -- l_bf_mode;
9796 l_gib.mtl_mode := p_mtl_mode; -- l_mtl_mode;
9797 l_gib.process_phase := p_proc_phase;
9798 l_gib.process_status := WIP_CONSTANTS.RUNNING;
9799 l_gib.time_out := p_time_out;
9800 l_gib.intf_tbl_name := 'WIP_MOVE_TXN_INTERFACE';
9801 l_gib.user_id := fnd_global.user_id;
9802 l_gib.login_id := fnd_global.conc_login_id;
9803 l_gib.request_id := fnd_global.conc_request_id;
9804 l_gib.application_id := fnd_global.prog_appl_id;
9805 l_gib.program_id := fnd_global.conc_program_id;
9806 l_gib.seq_move := NVL(p_seq_move, WIP_CONSTANTS.NO);
9807 END IF; -- move is online
9808
9809 IF(p_proc_phase = WIP_CONSTANTS.MOVE_VAL) THEN
9810 /*----------------+
9811 | Move Validation |
9812 +-----------------*/
9813 -- derive and validate all necessary info
9814 wip_move_validator.validate(p_group_id => p_group_id,
9815 p_initMsgList => fnd_api.g_true);
9816
9817 -- There is no return status from this routine. IF some record error out,
9818 -- just neglect it and continue validating other records. The error record
9819 -- will have process_status in WIP_MOVE_TXN_INTERFACE equal to (3) or
9820 -- WIP_CONSTANTS.ERROR, and those error records will not be picked up by
9821 -- move_txns. The error message also show up in WIP_TXN_INTERFACE_ERRORS
9822 END IF; -- Move Validation
9823
9824 OPEN c_txn_date;
9825 LOOP
9826 BEGIN
9827 FETCH c_txn_date INTO l_gib.txn_date;
9828 EXIT WHEN c_txn_date%NOTFOUND;
9829 SAVEPOINT s_move_proc;
9830 IF(p_proc_phase = WIP_CONSTANTS.MOVE_VAL OR
9831 p_proc_phase = WIP_CONSTANTS.MOVE_PROC) THEN
9832
9833 IF(p_move_mode = WIP_CONSTANTS.BACKGROUND) THEN
9834
9835 SELECT SUM(DECODE(entity_type,
9836 WIP_CONSTANTS.DISCRETE, 1,
9837 WIP_CONSTANTS.LOTBASED, 1,
9838 0)),
9839 SUM(DECODE(entity_type,WIP_CONSTANTS.REPETITIVE,1,0))
9840 INTO l_job,
9841 l_sche
9842 FROM wip_move_txn_interface wmti
9843 WHERE wmti.group_id = l_gib.group_id
9844 AND TRUNC(transaction_date)= TRUNC(l_gib.txn_date)
9845 AND process_phase = WIP_CONSTANTS.MOVE_PROC
9846 AND process_status = WIP_CONSTANTS.RUNNING;
9847
9848 IF(l_job > 0 AND l_sche > 0) THEN
9849 l_gib.move_profile.jobTxn := WIP_CONSTANTS.YES;
9850 l_gib.move_profile.scheTxn := WIP_CONSTANTS.YES;
9851 ELSIF(l_job > 0) THEN
9852 l_gib.move_profile.entity_type := WIP_CONSTANTS.DISCRETE;
9853 l_gib.move_profile.jobTxn := WIP_CONSTANTS.YES;
9854 l_gib.move_profile.scheTxn := WIP_CONSTANTS.NO;
9855 ELSIF(l_sche > 0) THEN
9856 l_gib.move_profile.entity_type := WIP_CONSTANTS.REPETITIVE;
9857 l_gib.move_profile.jobTxn := WIP_CONSTANTS.NO;
9858 l_gib.move_profile.scheTxn := WIP_CONSTANTS.YES;
9859 END IF; -- move profile check
9860 -- the others 6 parameters will be initialized in get_move_profile()
9861 -- rsrcItem, rsrcLot, poReqItem, poReqLot, easyComplete, easyReturn
9862 END IF; -- Background transactions
9863
9864 /* get profile of this group of transactions */
9865 get_move_profile(p_gib => l_gib,
9866 x_returnStatus => x_returnStatus);
9867
9868 IF(x_returnStatus <> fnd_api.g_ret_sts_success) THEN
9869 l_errMsg := 'wip_movProc_priv.get_move_profile failed';
9870 raise fnd_api.g_exc_unexpected_error;
9871 END IF; -- check return status
9872
9873 -- check IF easy return txns
9874 IF(l_gib.move_profile.easyReturn = WIP_CONSTANTS.YES) THEN
9875 IF(p_insertAssy = fnd_api.g_true) THEN
9876 ez_completion(p_gib => l_gib,
9877 p_txn_type => WIP_CONSTANTS.RET_TXN,
9878 x_returnStatus => x_returnStatus);
9879
9880 IF(x_returnStatus <> fnd_api.g_ret_sts_success) THEN
9881 l_errMsg := 'wip_movProc_priv.ez_completion (return) failed';
9882 raise fnd_api.g_exc_unexpected_error;
9883 END IF; -- check return status
9884 ELSE /* Bug fix 5026797 (base 4901865) - Assembly completion/return transaction through Discrete Workstation are
9885 processed with p_insertAssy = fnd_api.g_false. Added the following call to snapshot
9886 for assembly return transaction.*/
9887 snapshot_online(p_mtl_header_id => l_gib.assy_header_id,
9888 p_org_id => l_gib.move_profile.org_id,
9889 p_txn_type => WIP_CONSTANTS.RET_TXN,
9890 p_txn_type_id => WIP_CONSTANTS.RETASSY_TYPE,
9891 p_txn_action_id => WIP_CONSTANTS.RETASSY_ACTION,
9892 x_returnStatus => x_returnStatus);
9893
9894 IF(x_returnStatus <> fnd_api.g_ret_sts_success) THEN
9895 l_errMsg := 'wip_movProc_priv.snapshot_online (return) failed';
9896 raise fnd_api.g_exc_unexpected_error;
9897 END IF; -- check return status
9898 END IF; -- p_insertAssy = fnd_api.g_true
9899 /* End of bug fix 5026797 */
9900
9901 IF(l_gib.assy_header_id IS NOT NULL AND
9902 l_gib.assy_header_id <> -1) THEN
9903 -- Process assembly return record
9904 wip_mtlTempProc_priv.processTemp
9905 (p_initMsgList => fnd_api.g_true,
9906 p_txnHdrID => l_gib.assy_header_id,
9907 p_txnMode => WIP_CONSTANTS.ONLINE,
9908 x_returnStatus => x_returnStatus,
9909 x_errorMsg => l_errMsg);
9910
9911 IF(x_returnStatus <> fnd_api.g_ret_sts_success) THEN
9912 fnd_message.set_name('FND', 'FND_GENERIC_MESSAGE');
9913 fnd_message.set_token('MESSAGE', l_errMsg);
9914 fnd_msg_pub.add;
9915 l_errMsg := 'wip_mtlTempProc_priv.processTemp failed' ;
9916 raise fnd_api.g_exc_unexpected_error;
9917 END IF;
9918 l_return_hdr_id := l_gib.assy_header_id;
9919 -- reset l_gib.assy_header_id to null
9920 l_gib.assy_header_id := null;
9921 END IF; -- check l_gib.assy_header_id
9922 END IF; -- easy return txn
9923
9924 -- initialize scrap txns to be indeterminate
9925 l_gib.move_profile.scrapTxn := -1;
9926
9927 -- call main move processor
9928 move_txns(p_gib => l_gib,
9929 x_returnStatus => x_returnStatus);
9930
9931 IF(x_returnStatus <> fnd_api.g_ret_sts_success) THEN
9932 l_errMsg := 'wip_movProc_priv.move_txns failed';
9933 raise fnd_api.g_exc_unexpected_error;
9934 END IF; -- check return status
9935
9936 -- check IF easy completion txns
9937 IF(l_gib.move_profile.easyComplete = WIP_CONSTANTS.YES) THEN
9938 IF( p_insertAssy = fnd_api.g_true) THEN
9939 ez_completion(p_gib => l_gib,
9940 p_txn_type => WIP_CONSTANTS.COMP_TXN,
9941 x_returnStatus => x_returnStatus);
9942
9943 IF(x_returnStatus <> fnd_api.g_ret_sts_success) THEN
9944 l_errMsg := 'wip_movProc_priv.ez_completion (complete) failed';
9945 raise fnd_api.g_exc_unexpected_error;
9946 END IF; -- check return status
9947 ELSE /* Bug fix 5026797 (base 4901865) - Assembly completion/return transaction through Discrete Workstation are
9948 processed with p_insertAssy = fnd_api.g_false. Added the following call to snapshot for assembly completion transaction.*/
9949 snapshot_online(p_mtl_header_id => l_gib.assy_header_id,
9950 p_org_id => l_gib.move_profile.org_id,
9951 p_txn_type => WIP_CONSTANTS.COMP_TXN,
9952 p_txn_type_id => WIP_CONSTANTS.CPLASSY_TYPE,
9953 p_txn_action_id => WIP_CONSTANTS.CPLASSY_ACTION,
9954 x_returnStatus => x_returnStatus);
9955
9956 IF(x_returnStatus <> fnd_api.g_ret_sts_success) THEN
9957 l_errMsg := 'wip_movProc_priv.snapshot_online(complete) failed';
9958 raise fnd_api.g_exc_unexpected_error;
9959 END IF; -- check return status
9960 END IF; -- p_insertAssy = fnd_api.g_true
9961 /* End of bug fix 5026797 */
9962 END IF; -- easy complete txn
9963
9964 -- update completed quantity and take snapshot before calling inventory
9965 -- to process aseembly completion record
9966 IF(l_gib.move_mode = WIP_CONSTANTS.BACKGROUND) THEN
9967 update_wo_and_snapshot(p_gib => l_gib,
9968 x_returnStatus => x_returnStatus);
9969 IF(x_returnStatus <> fnd_api.g_ret_sts_success) THEN
9970 l_errMsg := 'wip_movProc_priv.update_wo_and_snapshot';
9971 raise fnd_api.g_exc_unexpected_error;
9972 END IF; -- check return status
9973 END IF;
9974
9975 /* call qualtiy to enable results */
9976 OPEN c_qa_id(p_txn_date => l_gib.txn_date);
9977 LOOP
9978 FETCH c_qa_id INTO l_qa_collection_id;
9979 EXIT WHEN c_qa_id%NOTFOUND;
9980
9981 QA_RESULT_GRP.ENABLE(
9982 p_api_version => 1.0,
9983 p_init_msg_list => fnd_api.g_true,
9984 p_commit => fnd_api.g_false,
9985 p_validation_level => 0,
9986 p_collection_id => l_qa_collection_id,
9987 p_return_status => x_returnStatus,
9988 p_msg_count => l_msgCount,
9989 p_msg_data => l_errMsg);
9990
9991 IF(x_returnStatus <> fnd_api.g_ret_sts_success) THEN
9992 fnd_message.set_name('FND', 'FND_GENERIC_MESSAGE');
9993 fnd_message.set_token('MESSAGE', l_errMsg);
9994 fnd_msg_pub.add;
9995 l_errMsg := 'QA Failed. Collection ID:' || l_qa_collection_id;
9996 raise fnd_api.g_exc_unexpected_error;
9997 END IF;
9998 END LOOP; -- c_qa_id FETCH
9999
10000 CLOSE c_qa_id; /* Bug 4204892 - Close the cursor c_qa_id to avoid ORA-6511. */
10001
10002 IF (l_logLevel <= wip_constants.full_logging) THEN
10003 wip_logger.log(p_msg => 'QA enable success',
10004 x_returnStatus => l_returnStatus);
10005 END IF;
10006
10007 UPDATE wip_move_txn_interface
10008 SET process_phase = WIP_CONSTANTS.BF_SETUP
10009 WHERE group_id = p_group_id
10010 AND process_phase = WIP_CONSTANTS.MOVE_PROC
10011 AND process_status = WIP_CONSTANTS.RUNNING
10012 AND TRUNC(transaction_date) = TRUNC(l_gib.txn_date);
10013
10014 -- IF debug message level = 2, write statement below to log file
10015 IF (l_logLevel <= wip_constants.full_logging) THEN
10016 fnd_message.set_name('WIP', 'WIP_UPDATED_ROWS');
10017 fnd_message.set_token('ENTITY1', SQL%ROWCOUNT);
10018 fnd_message.set_token('ENTITY2', 'WIP_MOVE_TXN_INTERFACE');
10019 l_msg := fnd_message.get;
10020 wip_logger.log(p_msg => l_msg,
10021 x_returnStatus => l_returnStatus);
10022 END IF;
10023
10024 IF(p_allow_partial_commit = WIP_CONSTANTS.YES) THEN
10025 IF(l_gib.assy_header_id IS NOT NULL AND
10026 l_gib.assy_header_id <> -1) THEN
10027 -- Update lock_flag to 'Y' to prevent inventory worker pick up these
10028 -- records. After we commit, assembly completion record will be in
10029 -- MMTT. There is a slim chance that inventory worker may pick up
10030 -- these records after we commit, and before we call processTemp.
10031 UPDATE mtl_material_transactions_temp
10032 SET lock_flag ='Y'
10033 WHERE transaction_header_id = l_gib.assy_header_id;
10034 END IF;
10035 -- Fixed bug 4361566. Commit to prevent dead lock from calling
10036 -- inventory TM mulitple times in the same commit cycle.
10037 COMMIT;
10038 IF(l_return_hdr_id IS NOT NULL AND l_return_hdr_id <> -1) THEN
10039 -- Release user lock on assembly return records per inventory
10040 -- request.
10041 inv_table_lock_pvt.release_locks(p_header_id => l_return_hdr_id);
10042 END IF;
10043 -- Set savepoint again because commit will clear savepoint.
10044 SAVEPOINT s_move_proc;
10045 END IF;
10046
10047 -- Calling inventory to process assembly completion records.
10048 IF(l_gib.assy_header_id IS NOT NULL AND
10049 l_gib.assy_header_id <> -1) THEN
10050 -- Process assembly completion record
10051 wip_mtlTempProc_priv.processTemp
10052 (p_initMsgList => fnd_api.g_true,
10053 p_txnHdrID => l_gib.assy_header_id,
10054 p_txnMode => WIP_CONSTANTS.ONLINE,
10055 x_returnStatus => x_returnStatus,
10056 x_errorMsg => l_errMsg);
10057
10058 IF(x_returnStatus <> fnd_api.g_ret_sts_success) THEN
10059 fnd_message.set_name('FND', 'FND_GENERIC_MESSAGE');
10060 fnd_message.set_token('MESSAGE', l_errMsg);
10061 fnd_msg_pub.add;
10062 l_errMsg := 'wip_mtlTempProc_priv.processTemp failed' ;
10063 raise fnd_api.g_exc_unexpected_error;
10064 END IF;
10065 END IF; -- check l_gib.assy_header_id
10066
10067 IF(p_allow_partial_commit = WIP_CONSTANTS.YES) THEN
10068 -- Fixed bug 4361566. Commit to prevent dead lock from calling
10069 -- inventory TM mulitple times in the same commit cycle.
10070 COMMIT;
10071 IF(l_gib.assy_header_id IS NOT NULL AND
10072 l_gib.assy_header_id <> -1) THEN
10073 -- Release user lock on assembly completion records per inventory
10074 -- request.
10075 inv_table_lock_pvt.release_locks(p_header_id => l_gib.assy_header_id);
10076 END IF;
10077 -- Set savepoint again because commit will clear savepoint.
10078 SAVEPOINT s_move_proc;
10079 END IF;
10080
10081 END IF; -- Move Processing
10082
10083 /* Backflush processing */
10084 IF(p_proc_phase = WIP_CONSTANTS.MOVE_VAL OR
10085 p_proc_phase = WIP_CONSTANTS.MOVE_PROC OR
10086 p_proc_phase = WIP_CONSTANTS.BF_SETUP) THEN
10087
10088 IF(l_gib.bf_mode = WIP_CONSTANTS.ONLINE) THEN
10089 IF(p_do_backflush = fnd_api.g_true) THEN
10090 IF(l_gib.mtl_header_id IS NULL OR
10091 l_gib.mtl_header_id = -1) THEN
10092 SELECT mtl_material_transactions_s.nextval
10093 INTO l_gib.mtl_header_id
10094 FROM DUAL;
10095 END IF;
10096
10097 -- backflush operation pull, and assembly pull for scrap.
10098 OPEN c_backflush(p_txn_date => l_gib.txn_date);
10099 LOOP
10100 FETCH c_backflush INTO l_backflush;
10101 EXIT WHEN c_backflush%NOTFOUND;
10102 BEGIN
10103 SAVEPOINT s_backflush_proc;
10104 /* Changes for bug 4916939 */
10105 -- Backflush assembly pull component for EZ Completion and
10106 -- EZ Return
10107 backflush_assy_pull(p_gib => l_gib,
10108 p_move_txn_id => l_backflush.txn_id,
10109 p_entity_type => l_backflush.ent_type);
10110 /* End changes for bug 4916939 */
10111 -- Call OSFM new backflush API for OSFM job.
10112 IF(l_backflush.ent_type = WIP_CONSTANTS.LOTBASED) THEN
10113 wsm_serial_support_grp.backflush_comp(
10114 p_wipEntityID => l_backflush.wip_id,
10115 p_orgID => l_backflush.org_id,
10116 p_primaryQty => l_backflush.primary_qty,
10117 p_txnDate => l_backflush.txn_date,
10118 p_txnHdrID => l_gib.mtl_header_id,
10119 p_txnType => l_backflush.txn_type,
10120 p_fmOp => l_backflush.fm_op,
10121 p_fmStep => l_backflush.fm_step,
10122 p_toOp => l_backflush.to_op,
10123 p_toStep => l_backflush.to_step,
10124 p_movTxnID => l_backflush.txn_id,
10125 p_mtlTxnMode => l_gib.mtl_mode,
10126 p_reasonID => l_backflush.reason_id,
10127 p_reference => l_backflush.reference,
10128 p_init_msg_list => fnd_api.g_true,
10129 x_lotSerRequired => l_ls_required,
10130 x_returnStatus => l_returnStatus,
10131 x_error_msg => l_error_msg, -- throw away value
10132 x_error_count => l_error_count); -- throw away value
10133
10134 IF(l_returnStatus <> fnd_api.g_ret_sts_success) THEN
10135 l_errMsg := 'wsm_serial_support_grp.backflush_comp failed' ;
10136 raise fnd_api.g_exc_unexpected_error;
10137 ELSE
10138 IF(l_ls_required = WIP_CONSTANTS.YES) THEN
10139 -- If we need to gather more lot/serial, error out because
10140 -- we cannot gather lot/serial for background transaction.
10141 fnd_message.set_name('WIP', 'WIP_NO_LOT_SER_COMP_BKGND');
10142 fnd_msg_pub.add;
10143 raise fnd_api.g_exc_unexpected_error;
10144 END IF;
10145 END IF; -- check return status
10146 ELSE -- discrete job or repetitive schedule
10147 wip_bflProc_priv.backflush(
10148 p_wipEntityID => l_backflush.wip_id,
10149 p_orgID => l_backflush.org_id,
10150 p_primaryQty => l_backflush.primary_qty,
10151 p_txnDate => l_backflush.txn_date,
10152 p_txnHdrID => l_gib.mtl_header_id,
10153 -- Fixed bug 5056289. Pass move_id as a batch_id because we want
10154 -- inventory to fail only components related to a specific move record.
10155 p_batchID => l_backflush.txn_id,
10156 p_txnType => l_backflush.txn_type,
10157 p_entityType => l_backflush.ent_type,
10158 p_tblName => WIP_CONSTANTS.MTI_TBL,
10159 p_lineID => l_backflush.line_id,
10160 p_fmOp => l_backflush.fm_op,
10161 p_fmStep => l_backflush.fm_step,
10162 p_toOp => l_backflush.to_op,
10163 p_toStep => l_backflush.to_step,
10164 p_movTxnID => l_backflush.txn_id,
10165 p_fmMoveProcessor => WIP_CONSTANTS.YES,
10166 p_mtlTxnMode => l_gib.mtl_mode,
10167 p_reasonID => l_backflush.reason_id,
10168 p_reference => l_backflush.reference,
10169 x_lotSerRequired => l_ls_required,
10170 x_bfRequired => l_bf_required,
10171 x_returnStatus => l_returnStatus);
10172
10173 IF(l_returnStatus <> fnd_api.g_ret_sts_success) THEN
10174 l_errMsg := 'wip_bflProc_priv.backflush failed' ;
10175 raise fnd_api.g_exc_unexpected_error;
10176 ELSE
10177 IF(l_ls_required = WIP_CONSTANTS.YES) THEN
10178 -- If we need to gather more lot/serial, error out because
10179 -- we cannot gather lot/serial for background transaction.
10180 fnd_message.set_name('WIP', 'WIP_NO_LOT_SER_COMP_BKGND');
10181 fnd_msg_pub.add;
10182 raise fnd_api.g_exc_unexpected_error;
10183 END IF;
10184 END IF; -- check return status
10185 END IF; -- check entity type
10186 EXCEPTION
10187 WHEN fnd_api.g_exc_unexpected_error THEN
10188 ROLLBACK TO SAVEPOINT s_backflush_proc;
10189 wip_utilities.get_message_stack(p_msg =>l_errMsg);
10190 IF(l_errMsg IS NULL) THEN
10191 -- initialize message to something because we cannot
10192 -- insert null into WIP_TXN_INTERFACE_ERRORS
10193 fnd_message.set_name('WIP', 'WIP_SOME_RECORDS_ERROR');
10194 l_errMsg := fnd_message.get;
10195 END IF;
10196 IF(p_move_mode = WIP_CONSTANTS.BACKGROUND) THEN
10197 /* Update process status to error */
10198 UPDATE wip_move_txn_interface
10199 SET process_status = WIP_CONSTANTS.ERROR
10200 WHERE group_id = p_group_id
10201 AND process_status = WIP_CONSTANTS.RUNNING
10202 AND transaction_id = l_backflush.txn_id;
10203
10204 /* insert error messages */
10205 INSERT INTO wip_txn_interface_errors
10206 (transaction_id,
10207 error_column,
10208 error_message,
10209 last_update_date,
10210 last_updated_by,
10211 creation_date,
10212 created_by,
10213 last_update_login,
10214 request_id,
10215 program_application_id,
10216 program_id,
10217 program_update_date
10218 )
10219 SELECT wmti.transaction_id,
10220 NULL, -- error_column
10221 substrb(l_errMsg,1,240), -- error_message
10222 SYSDATE, -- last_update_date
10223 l_gib.user_id, -- last_update_by
10224 SYSDATE, -- creation_date
10225 l_gib.user_id, -- created_by
10226 l_gib.login_id,
10227 l_gib.request_id,
10228 l_gib.application_id,
10229 l_gib.program_id,
10230 SYSDATE -- program_update_date
10231 FROM wip_move_txn_interface wmti
10232 WHERE wmti.group_id = p_group_id
10233 AND transaction_id = l_backflush.txn_id;
10234
10235 ELSE -- move mode is online, write to log file
10236 IF(x_returnStatus = fnd_api.g_ret_sts_error) THEN
10237 -- let the user know that more lot/serial info required
10238 x_returnStatus := fnd_api.g_ret_sts_error;
10239 END IF;
10240 IF (l_logLevel <= wip_constants.trace_logging) THEN
10241 l_errMsg := 'move_txn_id: ' || l_backflush.txn_id ||
10242 ' failed because ' || l_errMsg;
10243 wip_logger.log(p_msg => l_errMsg,
10244 x_returnStatus => l_returnStatus);
10245 END IF;
10246 END IF;
10247 END;
10248 /* End of Changes for bug 4628893 */
10249 END LOOP; -- c_backflush
10250
10251 CLOSE c_backflush; /* Bug 4204892 - Close the cursor c_backflush to avoid ORA-6511. */
10252
10253 -- Move assembly pull and operation pull records from mti to mmtt
10254 -- pass fnd_api.g_false to p_addMsgToStack because we never used
10255 -- message stack for background transaction. Moreover, this will
10256 -- improve performance if there are lots of errors.
10257 wip_mtlTempProc_priv.validateInterfaceTxns(
10258 p_txnHdrID => l_gib.mtl_header_id,
10259 p_addMsgToStack => fnd_api.g_false,
10260 p_rollbackOnErr => fnd_api.g_false,
10261 x_returnStatus => x_returnStatus);
10262
10263 IF(x_returnStatus <> fnd_api.g_ret_sts_success) THEN
10264 -- write error into WIP_TXN_INTERFACE_ERRORS
10265 write_mtl_errors(p_mtl_header_id => l_gib.mtl_header_id);
10266 IF (l_logLevel <= wip_constants.full_logging) THEN
10267 l_errMsg := 'wip_mtlTempProc_priv.validateInterfaceTxns failed'||
10268 ' (component records)' ;
10269 wip_logger.log(p_msg => l_errMsg,
10270 x_returnStatus => l_returnStatus);
10271 END IF;
10272 -- Fixed bug 5056289. We will not raise exception because we still
10273 -- want to process the components that pass validation.
10274 -- raise fnd_api.g_exc_unexpected_error;
10275
10276 -- Call component_cleanup to set the status of corresponding move
10277 -- records to error and delete error records from MTI and MTLI.
10278 component_cleanup(p_mtl_header_id => l_gib.mtl_header_id,
10279 p_group_id => p_group_id);
10280
10281 END IF;
10282 END IF; -- p_do_backflush
10283 /*---------------------+
10284 | Inventory processing |
10285 +---------------------*/
10286 SELECT count(*)
10287 INTO l_MMTT_record
10288 FROM mtl_material_transactions_temp
10289 WHERE transaction_header_id = l_gib.mtl_header_id;
10290
10291 IF(l_MMTT_record > 0 AND
10292 l_gib.mtl_mode <> WIP_CONSTANTS.NO_PROCESSING) THEN
10293 -- Call material processor to process backflush components, and
10294 -- scrap assembly.
10295 wip_mtlTempProc_priv.processTemp
10296 (p_initMsgList => fnd_api.g_true,
10297 p_txnHdrID => l_gib.mtl_header_id,
10298 p_txnMode => l_gib.mtl_mode,
10299 x_returnStatus => x_returnStatus,
10300 x_errorMsg => l_errMsg);
10301
10302 IF(x_returnStatus <> fnd_api.g_ret_sts_success) THEN
10303 fnd_message.set_name('FND', 'FND_GENERIC_MESSAGE');
10304 fnd_message.set_token('MESSAGE', l_errMsg);
10305 fnd_msg_pub.add;
10306 l_errMsg := 'wip_mtlTempProc_priv.processTemp failed' ;
10307 raise fnd_api.g_exc_unexpected_error;
10308 END IF;
10309 END IF; -- there is the records in MMTT with this header_id
10310 ELSE -- backflush is background
10311 UPDATE wip_move_txn_interface
10312 SET group_id = NULL,
10313 process_phase = WIP_CONSTANTS.BF_SETUP,
10314 process_status = WIP_CONSTANTS.PENDING
10315 WHERE group_id = p_group_id
10316 AND process_status = WIP_CONSTANTS.RUNNING;
10317 END IF; -- backflush is online
10318 END IF; -- Backflush Setup
10319
10320 IF(p_allow_partial_commit = WIP_CONSTANTS.YES) THEN
10321 -- Fixed bug 4361566. Commit to prevent dead lock from calling
10322 -- inventory TM mulitple times in the same commit cycle.
10323 COMMIT;
10324 IF(l_MMTT_record > 0 AND
10325 l_gib.mtl_mode <> WIP_CONSTANTS.NO_PROCESSING) THEN
10326 -- Release user lock on backflush records per inventory request.
10327 inv_table_lock_pvt.release_locks(p_header_id => l_gib.mtl_header_id);
10328 END IF;
10329 -- Set savepoint again because commit will clear savepoint.
10330 SAVEPOINT s_move_proc;
10331 END IF;
10332
10333 -- initialize transaction_header_id for each group on each day
10334 l_gib.mtl_header_id := -1;
10335
10336 EXCEPTION
10337
10338 WHEN fnd_api.g_exc_unexpected_error THEN
10339
10340 IF(p_move_mode = WIP_CONSTANTS.BACKGROUND) THEN
10341
10342 ROLLBACK TO SAVEPOINT s_move_proc;
10343 /* Update process status to error */
10344 UPDATE wip_move_txn_interface
10345 SET process_status = WIP_CONSTANTS.ERROR
10346 WHERE group_id = p_group_id
10347 AND process_status = WIP_CONSTANTS.RUNNING
10348 AND TRUNC(transaction_date)= TRUNC(l_gib.txn_date);
10349
10350 wip_utilities.get_message_stack(p_msg =>l_errMsg);
10351 IF(l_errMsg IS NULL) THEN
10352 -- initialize message to something because we cannot insert null
10353 -- into WIP_TXN_INTERFACE_ERRORS
10354 fnd_message.set_name('WIP', 'WIP_SOME_RECORDS_ERROR');
10355 l_errMsg := fnd_message.get;
10356 END IF;
10357
10358 /* insert error messages */
10359 INSERT INTO wip_txn_interface_errors
10360 (transaction_id,
10361 error_column,
10362 error_message,
10363 last_update_date,
10364 last_updated_by,
10365 creation_date,
10366 created_by,
10367 last_update_login,
10368 request_id,
10369 program_application_id,
10370 program_id,
10371 program_update_date
10372 )
10373 SELECT wmti.transaction_id,
10374 NULL, -- error_column
10375 substrb(l_errMsg,1,240), -- error_message
10376 SYSDATE, -- last_update_date
10377 l_gib.user_id, -- last_update_by
10378 SYSDATE, -- creation_date
10379 l_gib.user_id, -- created_by
10380 l_gib.login_id,
10381 l_gib.request_id,
10382 l_gib.application_id,
10383 l_gib.program_id,
10384 SYSDATE -- program_update_date
10385 FROM wip_move_txn_interface wmti
10386 WHERE wmti.group_id = p_group_id
10387 AND TRUNC(wmti.transaction_date) = TRUNC(l_gib.txn_date)
10388 AND NOT EXISTS (SELECT 1
10389 FROM wip_txn_interface_errors wtie
10390 WHERE wtie.transaction_id = wmti.transaction_id);
10391
10392 ELSE -- move mode is online, write to log file
10393 IF(x_returnStatus = fnd_api.g_ret_sts_error) THEN
10394 -- let the user know that more lot/serial info required
10395 x_returnStatus := fnd_api.g_ret_sts_error;
10396 ELSE
10397 ROLLBACK TO SAVEPOINT s_move_proc;
10398 x_returnStatus := fnd_api.g_ret_sts_unexp_error;
10399 END IF;
10400 IF (l_logLevel <= wip_constants.trace_logging) THEN
10401 wip_logger.exitPoint(p_procName =>'wip_movProc_priv.processIntf',
10402 p_procReturnStatus => x_returnStatus,
10403 p_msg => l_errMsg,
10404 x_returnStatus => l_returnStatus);
10405 END IF;
10406 -- close log file
10407 IF (p_ENDDebug = fnd_api.g_true) THEN
10408 wip_logger.cleanUp(x_returnStatus => l_returnStatus);
10409 END IF;
10410 GOTO END_program;
10411 END IF; -- move mode is background
10412
10413 WHEN others THEN
10414 ROLLBACK TO SAVEPOINT s_move_proc;
10415 IF(p_move_mode = WIP_CONSTANTS.BACKGROUND) THEN
10416
10417 /* Update process status to error */
10418 UPDATE wip_move_txn_interface
10419 SET process_status = WIP_CONSTANTS.ERROR
10420 WHERE group_id = p_group_id
10421 AND process_status = WIP_CONSTANTS.RUNNING
10422 AND TRUNC(transaction_date)= TRUNC(l_gib.txn_date);
10423
10424 l_errMsg := 'unexpected error: ' || SQLERRM;
10425
10426 /* insert error messages */
10427 INSERT INTO wip_txn_interface_errors
10428 (transaction_id,
10429 error_column,
10430 error_message,
10431 last_update_date,
10432 last_updated_by,
10433 creation_date,
10434 created_by,
10435 last_update_login,
10436 request_id,
10437 program_application_id,
10438 program_id,
10439 program_update_date
10440 )
10441 SELECT wmti.transaction_id,
10442 NULL, -- error_column
10443 substrb(l_errMsg,1,240), -- error_message
10444 SYSDATE, -- last_update_date
10445 l_gib.user_id, -- last_update_by
10446 SYSDATE, -- creation_date
10447 l_gib.user_id, -- created_by
10448 l_gib.login_id,
10449 l_gib.request_id,
10450 l_gib.application_id,
10451 l_gib.program_id,
10452 SYSDATE -- program_update_date
10453 FROM wip_move_txn_interface wmti
10454 WHERE wmti.group_id = p_group_id
10455 AND TRUNC(wmti.transaction_date) = TRUNC(l_gib.txn_date)
10456 AND NOT EXISTS (SELECT 1
10457 FROM wip_txn_interface_errors wtie
10458 WHERE wtie.transaction_id = wmti.transaction_id);
10459 ELSE -- move mode is online
10460 x_returnStatus := fnd_api.g_ret_sts_unexp_error;
10461 IF (l_logLevel <= wip_constants.trace_logging) THEN
10462 wip_logger.exitPoint(p_procName=>'wip_movProc_priv.processIntf',
10463 p_procReturnStatus => x_returnStatus,
10464 p_msg => 'unexpected error: ' || SQLERRM,
10465 x_returnStatus => l_returnStatus);
10466 END IF;
10467 -- close log file
10468 IF (p_ENDDebug = fnd_api.g_true) THEN
10469 wip_logger.cleanUp(x_returnStatus => l_returnStatus);
10470 END IF;
10471 GOTO END_program;
10472 END IF; -- move mode is background
10473 END;
10474
10475 END LOOP; -- c_txn_date FETCH
10476 /*---------------------------------------------------------------------+
10477 | Set group_mark_id to wip_entity_id for Return and Move transactions |
10478 +---------------------------------------------------------------------*/
10479 UPDATE mtl_serial_numbers msn1
10480 SET msn1.group_mark_id = msn1.wip_entity_id
10481 WHERE msn1.gen_object_id =
10482 (SELECT msn2.gen_object_id
10483 FROM wip_move_txn_interface wmti,
10484 wip_serial_move_interface wsmi,
10485 mtl_serial_numbers msn2
10486 WHERE wmti.transaction_id = wsmi.transaction_id
10487 AND wsmi.assembly_serial_number = msn2.serial_number
10488 AND wmti.primary_item_id = msn2.inventory_item_id
10489 AND wmti.organization_id = msn2.current_organization_id
10490 AND wmti.wip_entity_id = msn2.wip_entity_id
10491 AND msn2.group_mark_id IS NULL
10492 AND wmti.group_id = p_group_id
10493 AND wmti.process_phase = WIP_CONSTANTS.BF_SETUP
10494 AND wmti.process_status = WIP_CONSTANTS.RUNNING
10495 AND wmti.transaction_type = WIP_CONSTANTS.RET_TXN);
10496
10497 /*--------------------------------------+
10498 | Delete serial move interface records |
10499 +--------------------------------------*/
10500 DELETE FROM wip_serial_move_interface
10501 WHERE transaction_id IN
10502 (SELECT transaction_id
10503 FROM wip_move_txn_interface
10504 WHERE group_id = p_group_id
10505 AND process_phase = WIP_CONSTANTS.BF_SETUP
10506 AND process_status = WIP_CONSTANTS.RUNNING);
10507
10508 /*-------------------------------+
10509 | Delete move interface records |
10510 +-------------------------------*/
10511 DELETE FROM wip_move_txn_interface
10512 WHERE group_id = p_group_id
10513 AND process_phase = WIP_CONSTANTS.BF_SETUP
10514 AND process_status = WIP_CONSTANTS.RUNNING;
10515
10516 /*--------------------------------+
10517 | check for failed transactions |
10518 +--------------------------------*/
10519 SELECT COUNT(1)
10520 INTO l_err_record
10521 FROM WIP_MOVE_TXN_INTERFACE
10522 WHERE GROUP_ID = p_group_id
10523 AND process_status in (WIP_CONSTANTS.ERROR, WIP_CONSTANTS.RUNNING);
10524
10525 IF(l_err_record > 0) THEN
10526 /*===========================================================*/
10527 /* transactions in current group left in interface table - */
10528 /* worker exit with warning signal */
10529 /*===========================================================*/
10530 x_returnStatus := fnd_api.g_ret_sts_unexp_error;
10531 -- Fixed bug 5355443. We should not always put WIP_SOME_RECORDS_ERROR in
10532 -- the message stack because this API will be called for both online and
10533 -- background transaction. However, WIP_SOME_RECORDS_ERROR is only
10534 -- applicable for background transaction.
10535 --fnd_message.set_name('WIP', 'WIP_SOME_RECORDS_ERROR');
10536 --fnd_msg_pub.add;
10537 IF (l_logLevel <= wip_constants.trace_logging) THEN
10538 wip_logger.exitPoint(p_procName => 'wip_movProc_priv.processIntf',
10539 p_procReturnStatus => x_returnStatus,
10540 p_msg => 'some records error out',
10541 x_returnStatus => l_returnStatus);
10542 END IF;
10543 -- close log file
10544 IF (p_ENDDebug = fnd_api.g_true) THEN
10545 wip_logger.cleanUp(x_returnStatus => l_returnStatus);
10546 END IF;
10547 /*Bug 5727221 (FP of 5580093): Mobile WIP Transaction seems to be leaving
10548 transaction in WMTI in some exception case. However there is no error
10549 message propagated back to UI. As a result transaction goes through fine
10550 with no UI error but record remains in WMTI. x_returnStatus is changed
10551 to sucess by cleanup procedure after closing file . Hence repopulate
10552 x_returnStatus to error again */
10553 x_returnStatus := fnd_api.g_ret_sts_unexp_error;
10554 ELSE
10555 x_returnStatus := fnd_api.g_ret_sts_success;
10556 IF (l_logLevel <= wip_constants.trace_logging) THEN
10557 wip_logger.exitPoint(p_procName => 'wip_movProc_priv.processIntf',
10558 p_procReturnStatus => x_returnStatus,
10559 p_msg => 'no record in this group error out',
10560 x_returnStatus => l_returnStatus);
10561 END IF;
10562 -- close log file
10563 IF (p_ENDDebug = fnd_api.g_true) THEN
10564 wip_logger.cleanUp(x_returnStatus => l_returnStatus);
10565 END IF;
10566 END IF;
10567
10568 <<END_program>>
10569 IF(c_backflush%ISOPEN) THEN
10570 CLOSE c_backflush;
10571 END IF;
10572 IF (c_qa_id%ISOPEN) THEN
10573 CLOSE c_qa_id;
10574 END IF;
10575 IF (c_txn_date%ISOPEN) THEN
10576 CLOSE c_txn_date;
10577 END IF;
10578 END processIntf;
10579
10580 PROCEDURE move_worker(errbuf OUT NOCOPY VARCHAR2,
10581 retcode OUT NOCOPY NUMBER,
10582 p_group_id IN NUMBER,
10583 p_proc_phase IN NUMBER,
10584 p_time_out IN NUMBER,
10585 p_seq_move IN NUMBER) IS
10586
10587 l_returnStatus VARCHAR2(1);
10588 BEGIN
10589 retcode := 0; -- success
10590 /* Set process phase to 'Running' */
10591 UPDATE wip_move_txn_interface
10592 SET process_status = WIP_CONSTANTS.RUNNING,
10593 last_update_date = SYSDATE,
10594 last_update_login = fnd_global.conc_login_id,
10595 request_id = fnd_global.conc_request_id,
10596 program_application_id = fnd_global.prog_appl_id,
10597 program_id = fnd_global.conc_program_id,
10598 program_update_date = SYSDATE
10599 WHERE group_id = p_group_id;
10600
10601 -- Fixed bug 4361566. Set global variable to let inventory know that they
10602 -- should not delete lock record from their temp table. These lock records
10603 -- will be deleted when wip call inv_table_lock_pvt.release_locks.
10604 WIP_CONSTANTS.WIP_MOVE_WORKER := 'Y';
10605
10606 wip_movProc_priv.processIntf
10607 (p_group_id => p_group_id,
10608 p_proc_phase => p_proc_phase,
10609 p_time_out => p_time_out,
10610 p_move_mode => WIP_CONSTANTS.BACKGROUND,
10611 p_bf_mode => WIP_CONSTANTS.ONLINE,
10612 p_mtl_mode => WIP_CONSTANTS.ONLINE,
10613 p_endDebug => FND_API.G_TRUE,
10614 p_initMsgList => FND_API.G_TRUE,
10615 p_insertAssy => FND_API.G_TRUE,
10616 p_do_backflush => FND_API.G_TRUE,
10617 p_seq_move => p_seq_move,
10618 p_allow_partial_commit => WIP_CONSTANTS.YES, -- Fixed bug 4361566.
10619 x_returnStatus => l_returnStatus);
10620
10621 -- Fixed bug 4361566. Reset global variable WIP_MOVE_WORKER to its original
10622 -- value.
10623 WIP_CONSTANTS.WIP_MOVE_WORKER := 'N';
10624
10625 IF(l_returnStatus <> fnd_api.g_ret_sts_success) THEN
10626 retcode := 2; -- error
10627 -- Fixed bug 5355443. Since WIP_SOME_RECORDS_ERROR message is only
10628 -- applicable to background transaction, we should set error message here
10629 -- instead of wip_movProc_priv.processIntf().
10630 --wip_utilities.get_message_stack(p_msg =>errbuf);
10631 fnd_message.set_name('WIP', 'WIP_SOME_RECORDS_ERROR');
10632 errbuf := fnd_message.get;
10633 END IF;
10634 COMMIT; -- To prevent Move Worker concurrent program rollback.
10635 EXCEPTION
10636 WHEN others THEN
10637 retcode := 2; -- error
10638 errbuf := SQLERRM;
10639 END move_worker;
10640
10641 PROCEDURE repetitive_scrap(p_tmp_id IN NUMBER,
10642 x_returnStatus OUT NOCOPY VARCHAR2) IS
10643
10644 l_params wip_logger.param_tbl_t;
10645 l_returnStatus VARCHAR2(1);
10646 l_msg VARCHAR(240);
10647 l_logLevel NUMBER := fnd_log.g_current_runtime_level;
10648 BEGIN
10649 -- write parameter value to log file
10650 IF (l_logLevel <= wip_constants.trace_logging) THEN
10651 l_params(1).paramName := 'p_tmp_id';
10652 l_params(1).paramValue := p_tmp_id;
10653 wip_logger.entryPoint(p_procName => 'wip_movProc_priv.repetitive_scrap',
10654 p_params => l_params,
10655 x_returnStatus => l_returnStatus);
10656 END IF;
10657 -- insert into mtl_material_txn_allocations for repetitive schedule
10658 INSERT INTO mtl_material_txn_allocations
10659 (transaction_id,
10660 repetitive_schedule_id,
10661 organization_id,
10662 last_update_date,
10663 last_updated_by,
10664 creation_date,
10665 created_by,
10666 last_update_login,
10667 request_id,
10668 program_application_id,
10669 program_id,
10670 program_update_date,
10671 primary_quantity,
10672 transaction_quantity,
10673 transaction_date
10674 )
10675 SELECT mmtt.material_allocation_temp_id, -- transaction_id
10676 wmta.repetitive_schedule_id,
10677 wmta.organization_id,
10678 SYSDATE, -- last_update_date
10679 wmta.last_updated_by,
10680 SYSDATE, -- creation_date
10681 wmta.created_by,
10682 wmta.last_update_login,
10683 wmta.request_id,
10684 wmta.program_application_id,
10685 wmta.program_id,
10686 wmta.program_update_date,
10687 wmta.primary_quantity *
10688 sign(mmtt.primary_quantity), -- primary_quantity
10689 wmta.transaction_quantity *
10690 sign(mmtt.transaction_quantity), -- transaction_quantity
10691 wmti.transaction_date
10692 FROM wip_move_txn_allocations wmta,
10693 wip_move_txn_interface wmti,
10694 mtl_material_transactions_temp mmtt
10695 WHERE wmti.transaction_id = wmta.transaction_id
10696 AND wmti.organization_id = wmta.organization_id
10697 AND wmti.transaction_id = mmtt.move_transaction_id
10698 AND mmtt.transaction_temp_id = p_tmp_id
10699 AND mmtt.transaction_action_id = WIP_CONSTANTS.SCRASSY_ACTION;
10700
10701 -- IF debug message level = 2, write statement below to log file
10702 IF (l_logLevel <= wip_constants.full_logging) THEN
10703 fnd_message.set_name('WIP', 'WIP_INSERTED_ROWS');
10704 fnd_message.set_token('ENTITY1', SQL%ROWCOUNT);
10705 fnd_message.set_token('ENTITY2', 'MTL_MATERIAL_TXN_ALLOCATIONS');
10706 l_msg := fnd_message.get;
10707 wip_logger.log(p_msg => l_msg,
10708 x_returnStatus => l_returnStatus);
10709 END IF;
10710 x_returnStatus := fnd_api.g_ret_sts_success;
10711
10712 EXCEPTION
10713 WHEN others THEN
10714 x_returnStatus := fnd_api.g_ret_sts_unexp_error;
10715 l_msg := 'unexpected error: ' || SQLERRM || 'SQLCODE = ' || SQLCODE;
10716
10717 IF (l_logLevel <= wip_constants.trace_logging) THEN
10718 wip_logger.exitPoint(p_procName=>'wip_movProc_priv.repetitive_scrap',
10719 p_procReturnStatus => x_returnStatus,
10720 p_msg => l_msg,
10721 x_returnStatus => l_returnStatus);
10722 END IF;
10723 fnd_message.set_name('FND', 'FND_GENERIC_MESSAGE');
10724 fnd_message.set_token('MESSAGE', l_msg);
10725 fnd_msg_pub.add;
10726 END repetitive_scrap;
10727
10728 /*****************************************************************************
10729 * This procedure will be used by WIP OA Transaction page to insert record
10730 * into WIP_MOVE_TXN_INTERFACE.
10731 ****************************************************************************/
10732 PROCEDURE insert_record(p_transaction_id IN NUMBER,
10733 p_last_update_date IN DATE,
10734 p_last_updated_by IN NUMBER,
10735 p_last_updated_by_name IN VARCHAR2,
10736 p_creation_date IN DATE,
10737 p_created_by IN NUMBER,
10738 p_created_by_name IN VARCHAR2,
10739 p_last_update_login IN NUMBER,
10740 p_request_id IN NUMBER,
10741 p_program_application_id IN NUMBER,
10742 p_program_id IN NUMBER,
10743 p_program_update_date IN DATE,
10744 p_group_id IN NUMBER,
10745 p_source_code IN VARCHAR2,
10746 p_source_line_id IN NUMBER,
10747 p_process_phase IN NUMBER,
10748 p_process_status IN NUMBER,
10749 p_transaction_type IN NUMBER,
10750 p_organization_id IN NUMBER,
10751 p_organization_code IN VARCHAR2,
10752 p_wip_entity_id IN NUMBER,
10753 p_wip_entity_name IN VARCHAR2,
10754 p_entity_type IN NUMBER,
10755 p_primary_item_id IN NUMBER,
10756 p_line_id IN NUMBER,
10757 p_line_code IN VARCHAR2,
10758 p_repetitive_schedule_id IN NUMBER,
10759 p_transaction_date IN DATE,
10760 p_acct_period_id IN NUMBER,
10761 p_fm_operation_seq_num IN NUMBER,
10762 p_fm_operation_code IN VARCHAR2,
10763 p_fm_department_id IN NUMBER,
10764 p_fm_department_code IN VARCHAR2,
10765 p_fm_intraoperation_step_type IN NUMBER,
10766 p_to_operation_seq_num IN NUMBER,
10767 p_to_operation_code IN VARCHAR2,
10768 p_to_department_id IN NUMBER,
10769 p_to_department_code IN VARCHAR2,
10770 p_to_intraoperation_step_type IN NUMBER,
10771 p_transaction_quantity IN NUMBER,
10772 p_transaction_uom IN VARCHAR2,
10773 p_primary_quantity IN NUMBER,
10774 p_primary_uom IN VARCHAR2,
10775 p_scrap_account_id IN NUMBER,
10776 p_reason_id IN NUMBER,
10777 p_reason_name IN VARCHAR2,
10778 p_reference IN VARCHAR2,
10779 p_attribute_category IN VARCHAR2,
10780 p_attribute1 IN VARCHAR2,
10781 p_attribute2 IN VARCHAR2,
10782 p_attribute3 IN VARCHAR2,
10783 p_attribute4 IN VARCHAR2,
10784 p_attribute5 IN VARCHAR2,
10785 p_attribute6 IN VARCHAR2,
10786 p_attribute7 IN VARCHAR2,
10787 p_attribute8 IN VARCHAR2,
10788 p_attribute9 IN VARCHAR2,
10789 p_attribute10 IN VARCHAR2,
10790 p_attribute11 IN VARCHAR2,
10791 p_attribute12 IN VARCHAR2,
10792 p_attribute13 IN VARCHAR2,
10793 p_attribute14 IN VARCHAR2,
10794 p_attribute15 IN VARCHAR2,
10795 p_qa_collection_id IN NUMBER,
10796 p_kanban_card_id IN NUMBER,
10797 p_oc_transaction_qty IN NUMBER,
10798 p_oc_primary_qty IN NUMBER,
10799 p_oc_transaction_id IN NUMBER,
10800 p_xml_document_id IN VARCHAR2,
10801 p_processing_order IN NUMBER,
10802 p_batch_id IN NUMBER,
10803 p_employee_id IN NUMBER,
10804 p_completed_instructions IN NUMBER) IS
10805 BEGIN
10806 INSERT INTO wip_move_txn_interface
10807 (transaction_id,
10808 last_update_date,
10809 last_updated_by,
10810 last_updated_by_name,
10811 creation_date,
10812 created_by,
10813 created_by_name,
10814 last_update_login,
10815 request_id,
10816 program_application_id,
10817 program_id,
10818 program_update_date,
10819 group_id,
10820 source_code,
10821 source_line_id,
10822 process_phase,
10823 process_status,
10824 transaction_type,
10825 organization_id,
10826 organization_code,
10827 wip_entity_id,
10828 wip_entity_name,
10829 entity_type,
10830 primary_item_id,
10831 line_id,
10832 line_code,
10833 repetitive_schedule_id,
10834 transaction_date,
10835 acct_period_id,
10836 fm_operation_seq_num,
10837 fm_operation_code,
10838 fm_department_id,
10839 fm_department_code,
10840 fm_intraoperation_step_type,
10841 to_operation_seq_num,
10842 to_operation_code,
10843 to_department_id,
10844 to_department_code,
10845 to_intraoperation_step_type,
10846 transaction_quantity,
10847 transaction_uom,
10848 primary_quantity,
10849 primary_uom,
10850 scrap_account_id,
10851 reason_id,
10852 reason_name,
10853 reference,
10854 attribute_category,
10855 attribute1,
10856 attribute2,
10857 attribute3,
10858 attribute4,
10859 attribute5,
10860 attribute6,
10861 attribute7,
10862 attribute8,
10863 attribute9,
10864 attribute10,
10865 attribute11,
10866 attribute12,
10867 attribute13,
10868 attribute14,
10869 attribute15,
10870 qa_collection_id,
10871 kanban_card_id,
10872 overcompletion_transaction_qty,
10873 overcompletion_primary_qty,
10874 overcompletion_transaction_id,
10875 xml_document_id,
10876 processing_order,
10877 batch_id,
10878 employee_id,
10879 completed_instructions)
10880 VALUES
10881 (p_transaction_id,
10882 p_last_update_date,
10883 p_last_updated_by,
10884 p_last_updated_by_name,
10885 p_creation_date,
10886 p_created_by,
10887 p_created_by_name,
10888 p_last_update_login,
10889 p_request_id,
10890 p_program_application_id,
10891 p_program_id,
10892 p_program_update_date,
10893 p_group_id,
10894 p_source_code,
10895 p_source_line_id,
10896 p_process_phase,
10897 p_process_status,
10898 p_transaction_type,
10899 p_organization_id,
10900 p_organization_code,
10901 p_wip_entity_id,
10902 p_wip_entity_name,
10903 p_entity_type,
10904 p_primary_item_id,
10905 p_line_id,
10906 p_line_code,
10907 p_repetitive_schedule_id,
10908 p_transaction_date,
10909 p_acct_period_id,
10910 p_fm_operation_seq_num,
10911 p_fm_operation_code,
10912 p_fm_department_id,
10913 p_fm_department_code,
10914 p_fm_intraoperation_step_type,
10915 p_to_operation_seq_num,
10916 p_to_operation_code,
10917 p_to_department_id,
10918 p_to_department_code,
10919 p_to_intraoperation_step_type,
10920 p_transaction_quantity,
10921 p_transaction_uom,
10922 p_primary_quantity,
10923 p_primary_uom,
10924 p_scrap_account_id,
10925 p_reason_id,
10926 p_reason_name,
10927 p_reference,
10928 p_attribute_category,
10929 p_attribute1,
10930 p_attribute2,
10931 p_attribute3,
10932 p_attribute4,
10933 p_attribute5,
10934 p_attribute6,
10935 p_attribute7,
10936 p_attribute8,
10937 p_attribute9,
10938 p_attribute10,
10939 p_attribute11,
10940 p_attribute12,
10941 p_attribute13,
10942 p_attribute14,
10943 p_attribute15,
10944 p_qa_collection_id,
10945 p_kanban_card_id,
10946 p_oc_transaction_qty,
10947 p_oc_primary_qty,
10948 p_oc_transaction_id,
10949 p_xml_document_id,
10950 p_processing_order,
10951 p_batch_id,
10952 p_employee_id,
10953 p_completed_instructions);
10954
10955 END insert_record;
10956
10957 PROCEDURE processOATxn(p_group_id IN NUMBER,
10958 p_child_txn_id IN NUMBER,
10959 p_mtl_header_id IN NUMBER,
10960 p_do_backflush IN VARCHAR2,
10961 p_assySerial IN VARCHAR2:= NULL,
10962 p_print_label IN NUMBER default null, /* VJ Label Printing */
10963 x_returnStatus OUT NOCOPY VARCHAR2) IS
10964
10965 CURSOR c_errors IS
10966 SELECT wtie.error_column,
10967 wtie.error_message
10968 FROM wip_txn_interface_errors wtie,
10969 wip_move_txn_interface wmti
10970 WHERE wtie.transaction_id = wmti.transaction_id
10971 AND wmti.group_id = p_group_id;
10972
10973 CURSOR c_move_records IS
10974 SELECT wmt.wip_entity_id wip_id,
10975 wmt.fm_operation_seq_num fm_op,
10976 wmt.to_operation_seq_num to_op
10977 FROM wip_move_transactions wmt
10978 WHERE wmt.transaction_id = p_group_id;
10979
10980 l_log_level NUMBER := fnd_log.g_current_runtime_level;
10981 l_error_msg VARCHAR2(1000);
10982 l_process_phase VARCHAR2(3);
10983 l_return_status VARCHAR(1);
10984 l_errors c_errors%ROWTYPE;
10985 l_move_records c_move_records%ROWTYPE;
10986 l_params wip_logger.param_tbl_t;
10987 l_msg_count NUMBER; /* VJ Label Printing */
10988 l_msg_stack VARCHAR2(2000); /* VJ Label Printing */
10989
10990 BEGIN
10991
10992 /* Fix for bug 5518780. Initialize msg stack here instead of exception handler
10993 so that messages from INV are not deleted */
10994 fnd_msg_pub.initialize;
10995
10996 l_process_phase := '1';
10997 IF (l_log_level <= wip_constants.trace_logging) THEN
10998 l_params(1).paramName := 'p_group_id';
10999 l_params(1).paramValue := p_group_id;
11000 l_params(2).paramName := 'p_child_txn_id';
11001 l_params(2).paramValue := p_child_txn_id;
11002 l_params(3).paramName := 'p_mtl_header_id';
11003 l_params(3).paramValue := p_mtl_header_id;
11004 l_params(4).paramName := 'p_do_backflush';
11005 l_params(4).paramValue := p_do_backflush;
11006 l_params(5).paramName := 'p_assySerial';
11007 l_params(5).paramValue := p_assySerial;
11008 l_params(6).paramName := 'p_print_label'; /* VJ Label Printing */
11009 l_params(6).paramValue := p_print_label; /* VJ Label Printing */
11010
11011 wip_logger.entryPoint(p_procName => 'wip_movProc_priv.processOATxn',
11012 p_params => l_params,
11013 x_returnStatus => l_return_status);
11014 END IF;
11015 l_process_phase := '2';
11016 SAVEPOINT s_oa_txn_proc;
11017
11018 IF(p_assySerial IS NOT NULL) THEN
11019 -- serial txns, so need to insert record into WIP_SERIAL_MOVE_INTERFACE too
11020 IF(wma_move.insertSerial(groupID => p_group_id,
11021 transactionID => p_group_id,
11022 serialNumber => p_assySerial,
11023 errMessage => l_error_msg) = FALSE) THEN
11024 -- insert statement error out
11025 raise fnd_api.g_exc_unexpected_error;
11026 END IF;
11027 END IF; -- from serialized page
11028 l_process_phase := '2.5';
11029 -- Validate and move records from MTI to MMTT. This will move both assembly
11030 -- and component records because we use the same header Id.
11031 wip_mtlTempProc_priv.validateInterfaceTxns(
11032 p_txnHdrID => p_mtl_header_id,
11033 p_addMsgToStack => fnd_api.g_true, -- So that we can display to user
11034 p_rollbackOnErr => fnd_api.g_false,
11035 x_returnStatus => x_returnStatus);
11036
11037 IF(x_returnStatus <> fnd_api.g_ret_sts_success) THEN
11038 raise fnd_api.g_exc_unexpected_error;
11039 END IF;
11040 l_process_phase := '3';
11041
11042 -- Perform some validations that have not done in the UI
11043 wip_move_validator.validateOATxn(p_group_id => p_group_id);
11044 l_process_phase := '4';
11045
11046 -- Process move and material records.
11047 wip_movProc_priv.processIntf
11048 (p_group_id => p_group_id,
11049 p_child_txn_id => p_child_txn_id,
11050 p_mtl_header_id => p_mtl_header_id,
11051 p_assy_header_id => p_mtl_header_id,
11052 p_proc_phase => WIP_CONSTANTS.MOVE_PROC,
11053 p_time_out => 0,
11054 p_move_mode => WIP_CONSTANTS.ONLINE,
11055 p_bf_mode => WIP_CONSTANTS.ONLINE,
11056 p_mtl_mode => WIP_CONSTANTS.ONLINE,
11057 p_endDebug => FND_API.G_FALSE,
11058 p_initMsgList => FND_API.G_TRUE,
11059 p_insertAssy => FND_API.G_FALSE,
11060 p_do_backflush => p_do_backflush,
11061 x_returnStatus => x_returnStatus);
11062
11063 IF(x_returnStatus <> fnd_api.g_ret_sts_success) THEN
11064 l_process_phase := '5';
11065 raise fnd_api.g_exc_unexpected_error;
11066 ELSE
11067 l_process_phase := '6';
11068 -- If move success, call time entry API to clock off operator if there
11069 -- is no quantity left at the operation.
11070 FOR l_move_records IN c_move_records LOOP
11071 wip_ws_time_entry.process_time_records_move(
11072 p_wip_entity_id => l_move_records.wip_id,
11073 p_from_op => l_move_records.fm_op,
11074 p_to_op => l_move_records.to_op);
11075 END LOOP;
11076 l_process_phase := '7';
11077 END IF;
11078
11079 /* Start: VJ Label Printing */
11080 IF (p_print_label = 1) THEN
11081 wip_utilities.print_move_txn_label(p_txn_id => p_group_id,
11082 x_status => l_return_status,
11083 x_msg_count => l_msg_count,
11084 x_msg => l_error_msg);
11085 -- do not error out if label printing, only put warning message in log
11086 IF(l_return_status <> fnd_api.g_ret_sts_success) THEN
11087 wip_utilities.get_message_stack(p_msg => l_msg_stack);
11088 IF (l_log_level <= wip_constants.full_logging) THEN
11089 wip_logger.log(p_msg => 'An error has occurred with label printing.\n' ||
11090 'The following error has occurred during ' ||
11091 'printing: ' || l_msg_stack || '\n' ||
11092 'Please check the Inventory log file for more ' ||
11093 'information.',
11094 x_returnStatus =>l_return_status);
11095 END IF;
11096 END IF;
11097 END IF;
11098 l_process_phase := '8';
11099 /* End: VJ Label Printing */
11100
11101 x_returnStatus := fnd_api.g_ret_sts_success;
11102
11103 -- write to the log file
11104 IF (l_log_level <= wip_constants.trace_logging) THEN
11105 wip_logger.exitPoint(p_procName => 'wip_movProc_priv.processOATxn',
11106 p_procReturnStatus => x_returnStatus,
11107 p_msg => 'procedure complete',
11108 x_returnStatus => l_return_status);
11109 END IF;
11110 -- close log file
11111 wip_logger.cleanUp(x_returnStatus => l_return_status);
11112 EXCEPTION
11113 WHEN fnd_api.g_exc_unexpected_error THEN
11114 -- Fixed bug 5518780. We should not clear message from the stack.
11115 -- If it fails inventory validation, no error will be recorded in WTIE.
11116 -- Instead, error message will be put in message stack.
11117 -- fnd_msg_pub.initialize;
11118 FOR l_errors IN c_errors LOOP
11119 fnd_message.set_name('FND', 'FND_GENERIC_MESSAGE');
11120 fnd_message.set_token('MESSAGE', l_errors.error_message);
11121 fnd_msg_pub.add;
11122 END LOOP;
11123 ROLLBACK TO SAVEPOINT s_oa_txn_proc;
11124 x_returnStatus := fnd_api.g_ret_sts_error;
11125 IF (l_log_level <= wip_constants.trace_logging) THEN
11126 wip_logger.exitPoint(p_procName => 'wip_movProc_priv.processOATxn',
11127 p_procReturnStatus => x_returnStatus,
11128 p_msg => 'wip_movProc_priv.processOATxn failed : '
11129 || l_process_phase,
11130 x_returnStatus => l_return_status);
11131 END IF;
11132 -- close log file
11133 wip_logger.cleanUp(x_returnStatus => l_return_status);
11134 WHEN others THEN
11135 ROLLBACK TO SAVEPOINT s_oa_txn_proc;
11136 x_returnStatus := fnd_api.g_ret_sts_error;
11137 l_error_msg := ' unexpected error: ' || SQLERRM || 'SQLCODE = ' || SQLCODE;
11138
11139 fnd_message.set_name('FND', 'FND_GENERIC_MESSAGE');
11140 fnd_message.set_token('MESSAGE', l_error_msg);
11141 fnd_msg_pub.add;
11142
11143 IF (l_log_level <= wip_constants.trace_logging) THEN
11144 wip_logger.exitPoint(p_procName => 'wip_movProc_priv.processOATxn',
11145 p_procReturnStatus => x_returnStatus,
11146 p_msg => l_error_msg || ' : ' || l_process_phase,
11147 x_returnStatus => l_return_status);
11148 END IF;
11149 -- close log file
11150 wip_logger.cleanUp(x_returnStatus => l_return_status);
11151 END processOATxn;
11152 END wip_movProc_priv;