[Home] [Help]
PACKAGE BODY: APPS.WMS_WAVEPLAN_TASKS_PVT
Source
1 PACKAGE BODY wms_waveplan_tasks_pvt AS
2 /* $Header: WMSVTKPB.pls 120.45.12010000.3 2008/10/08 10:40:15 satishku ship $ */
3 --
4 g_record_count NUMBER;
5 -- Messages
6 g_task_updated wms_waveplan_tasks_temp.error%TYPE;
7 g_task_saved wms_waveplan_tasks_temp.error%TYPE;
8 g_cannot_update_putaway wms_waveplan_tasks_temp.error%TYPE;
9 g_cannot_update_staging_move wms_waveplan_tasks_temp.error%TYPE;
10 g_cannot_unrelease_cc wms_waveplan_tasks_temp.error%TYPE;
11 g_summarized_time wms_waveplan_tasks_temp.error%TYPE;
12 g_cannot_summarize_time wms_waveplan_tasks_temp.error%TYPE;
13 g_time_uom_error wms_waveplan_tasks_temp.error%TYPE;
14 g_summarized_volume wms_waveplan_tasks_temp.error%TYPE;
15 g_cannot_summarize_vol wms_waveplan_tasks_temp.error%TYPE;
16 g_vol_uom_error wms_waveplan_tasks_temp.error%TYPE;
17 g_no_item_vol wms_waveplan_tasks_temp.error%TYPE;
18 g_summarized_weight wms_waveplan_tasks_temp.error%TYPE;
19 g_cannot_summarize_wt wms_waveplan_tasks_temp.error%TYPE;
20 g_wt_uom_error wms_waveplan_tasks_temp.error%TYPE;
21 g_no_item_wt wms_waveplan_tasks_temp.error%TYPE;
22 g_plan_cancelled wms_waveplan_tasks_temp.error%TYPE;
23 -- Global variables to determine if a column is visible or not
24 g_allocated_lpn_visible jtf_custom_grid_cols.visible_flag%TYPE;
25 g_assembly_visible jtf_custom_grid_cols.visible_flag%TYPE;
26 g_carrier_visible jtf_custom_grid_cols.visible_flag%TYPE;
27 g_cartonization_lpn_visible jtf_custom_grid_cols.visible_flag%TYPE;
28 g_container_item_visible jtf_custom_grid_cols.visible_flag%TYPE;
29 g_content_lpn_visible jtf_custom_grid_cols.visible_flag%TYPE;
30 g_customer_visible jtf_custom_grid_cols.visible_flag%TYPE;
31 g_delivery_visible jtf_custom_grid_cols.visible_flag%TYPE;
32 g_department_visible jtf_custom_grid_cols.visible_flag%TYPE;
33 g_line_visible jtf_custom_grid_cols.visible_flag%TYPE;
34 g_line_number_visible jtf_custom_grid_cols.visible_flag%TYPE;
35 g_machine_resource_visible jtf_custom_grid_cols.visible_flag%TYPE;
36 g_person_visible jtf_custom_grid_cols.visible_flag%TYPE;
37 g_person_resource_visible jtf_custom_grid_cols.visible_flag%TYPE;
38 g_ship_method_visible jtf_custom_grid_cols.visible_flag%TYPE;
39 g_ship_to_country_visible jtf_custom_grid_cols.visible_flag%TYPE;
40 g_ship_to_postal_code_visible jtf_custom_grid_cols.visible_flag%TYPE;
41 g_ship_to_state_visible jtf_custom_grid_cols.visible_flag%TYPE;
42 g_source_header_visible jtf_custom_grid_cols.visible_flag%TYPE;
43 g_status_visible jtf_custom_grid_cols.visible_flag%TYPE;
44 g_task_type_visible jtf_custom_grid_cols.visible_flag%TYPE;
45 g_to_locator_visible jtf_custom_grid_cols.visible_flag%TYPE;
46 g_to_lpn_visible jtf_custom_grid_cols.visible_flag%TYPE;
47 g_to_organization_code_visible jtf_custom_grid_cols.visible_flag%TYPE;
48 g_transaction_action_visible jtf_custom_grid_cols.visible_flag%TYPE;
49 g_txn_source_type_visible jtf_custom_grid_cols.visible_flag%TYPE;
50 g_operation_plan_visible jtf_custom_grid_cols.visible_flag%TYPE;
51 g_user_task_type_visible jtf_custom_grid_cols.visible_flag%TYPE;
52 g_num_of_child_tasks_visible jtf_custom_grid_cols.visible_flag%TYPE;
53 --bug: 4510849
54 g_picked_lpn_visible jtf_custom_grid_cols.visible_flag%TYPE;
55 g_loaded_lpn_visible jtf_custom_grid_cols.visible_flag%TYPE;
56 g_drop_lpn_visible jtf_custom_grid_cols.visible_flag%TYPE;
57 --Changed
58 g_op_plan_instance_id_visible jtf_custom_grid_cols.visible_flag%TYPE;
59 g_operation_sequence_visible jtf_custom_grid_cols.visible_flag%TYPE;
60 --end of change
61 g_from_lpn_visible jtf_custom_grid_cols.visible_flag%TYPE;
62
63 g_project_enabled_organization VARCHAR2 (1);
64 g_rows_marked BOOLEAN := FALSE;
65 g_final_query VARCHAR2 (10000);
66 i NUMBER := 1;
67
68 PROCEDURE DEBUG (
69 p_message VARCHAR2,
70 p_module VARCHAR2 DEFAULT 'Task Planning'
71 )
72 IS
73 l_counter NUMBER := 1;
74
75 --PRAGMA AUTONOMOUS_TRANSACTION;
76 BEGIN
77 WHILE l_counter < LENGTH (p_message)
78 LOOP
79 inv_log_util.TRACE (SUBSTR (p_message, l_counter, 80), p_module);
80 l_counter := l_counter + 80;
81 END LOOP;
82
83 /*INSERT INTO my_temp_table VALUES (p_message,i);
84 i := i+1;
85 COMMIT;*/
86
87 RETURN;
88 END;
89
90 PROCEDURE wwtt_dump
91 IS
92 l_debug NUMBER := NVL (fnd_profile.VALUE ('INV_DEBUG_TRACE'), 0);
93 CURSOR cur_wwtt
94 IS
95 SELECT transaction_temp_id, task_id, is_modified, status_id,
96 status_id_original, person_id, person_id_original, priority,
97 priority_original
98 FROM wms_waveplan_tasks_temp
99 WHERE is_modified = 'Y';
100 BEGIN
101 IF l_debug = 1 then
102 FOR rec_wwtt IN cur_wwtt
103 LOOP
104 DEBUG ('TRANSACTION_TEMP_ID: ' || rec_wwtt.transaction_temp_id);
105 DEBUG ('TASK_ID: ' || rec_wwtt.task_id);
106 DEBUG ('IS_MODIFIED: ' || rec_wwtt.is_modified);
107 DEBUG ('STATUS_ID: ' || rec_wwtt.status_id);
108 DEBUG ('STATUS_ID_ORIGINAL: ' || rec_wwtt.status_id_original);
109 DEBUG ('PERSON_ID: ' || rec_wwtt.person_id);
110 DEBUG ('PERSON_ID_ORIGINAL: ' || rec_wwtt.person_id_original);
111 DEBUG ('PRIORITY: ' || rec_wwtt.priority);
112 DEBUG ('PRIORITY_ORIGINAL: ' || rec_wwtt.priority_original);
113 END LOOP;
114 END IF;
115 END;
116
117 --Procedures for labor estimations
118 PROCEDURE mark_rows (
119 p_transaction_temp_id IN wms_waveplan_tasks_pvt.transaction_temp_table_type,
120 p_task_type_id IN wms_waveplan_tasks_pvt.task_type_id_table_type,
121 x_return_status OUT NOCOPY VARCHAR2
122 )
123 IS
124 BEGIN
125 x_return_status := 'S';
126 FORALL i IN p_transaction_temp_id.FIRST .. p_transaction_temp_id.LAST
127 UPDATE wms_waveplan_tasks_temp
128 SET RESULT = DECODE (RESULT, NULL, 'X', 'S', 'Y', 'E', 'Z')
129 WHERE transaction_temp_id = p_transaction_temp_id (i)
130 AND task_type_id = p_task_type_id (i);
131 g_rows_marked := TRUE;
132 EXCEPTION
133 WHEN OTHERS
134 THEN
135 DEBUG (SQLERRM, 'Task_planning.mark_rows');
136 x_return_status := 'U';
137 END mark_rows;
138
139 PROCEDURE unmark_rows
140 IS
141 BEGIN
142 IF g_rows_marked
143 THEN
144 UPDATE wms_waveplan_tasks_temp
145 SET RESULT =
146 DECODE (RESULT,
147 'Y', 'S',
148 'Z', 'E',
149 'X', NULL,
150 RESULT
151 )
152 WHERE RESULT IN ('X', 'Y', 'Z');
153
154 g_rows_marked := FALSE;
155 END IF;
156 END;
157
158 -- This procedure populates the global variables that store information if a column
159 -- is visible or not.
160 -- We will use these globals to determine if certain columns that are not
161 -- populated by the base query need to be populated by subsequent queries
162 PROCEDURE find_visible_columns
163 IS
164 TYPE visible_columns_type IS TABLE OF jtf_custom_grid_cols.visible_flag%TYPE;
165
166 visible_columns visible_columns_type;
167 l_user_id NUMBER;
168 BEGIN
169 fnd_profile.get ('USER_ID', l_user_id);
170
171 SELECT NVL (jcgc.visible_flag, jgc.visible_flag)
172 BULK COLLECT INTO visible_columns
173 FROM jtf_grid_cols_b jgc, jtf_custom_grid_cols jcgc
174 WHERE jgc.grid_datasource_name = jcgc.grid_datasource_name(+)
175 AND jgc.grid_col_alias = jcgc.grid_col_alias(+)
176 AND jgc.grid_datasource_name = 'WMS_WAVEPLAN_TASKS'
177 AND jcgc.created_by(+) = l_user_id
178 AND jgc.grid_col_alias IN
179 ('ALLOCATED_LPN',
180 'ASSEMBLY',
181 'CARRIER',
182 'CARTONIZATION_LPN',
183 'CONTAINER_ITEM',
184 'CONTENT_LPN',
185 'CUSTOMER',
186 'DELIVERY',
187 'DEPARTMENT',
188 'DROP_LPN', --bug 4510849
189 'FROM_LPN',
190 'LINE',
191 'LINE_NUMBER',
192 'LOADED_LPN', --bug 4510849
193 'MACHINE_RESOURCE_CODE',
194 'NUM_OF_CHILD_TASKS',
195 'OPERATION_PLAN',
196 'OPERATION_SEQUENCE',
197 'OP_PLAN_INSTANCE_ID',
198 'PERSON',
199 'PERSON_RESOURCE_CODE',
200 'PICKED_LPN', --bug 4510849
201 'SHIP_METHOD',
202 'SHIP_TO_COUNTRY',
203 'SHIP_TO_POSTAL_CODE',
204 'SHIP_TO_STATE',
205 'SOURCE_HEADER',
206 'STATUS',
207 'TASK_TYPE',
208 'TO_LOCATOR',
209 'TO_LPN',
210 'TO_ORGANIZATION_CODE',
211 'TRANSACTION_SOURCE_TYPE',
212 'USER_TASK_TYPE'
213 )
214 ORDER BY NVL (jcgc.grid_col_alias, jgc.grid_col_alias);
215
216 g_allocated_lpn_visible := visible_columns (1);
217 g_assembly_visible := visible_columns (2);
218 g_carrier_visible := visible_columns (3);
219 g_cartonization_lpn_visible := visible_columns (4);
220 g_container_item_visible := visible_columns (5);
221 g_content_lpn_visible := visible_columns (6);
222 g_customer_visible := visible_columns (7);
223 g_delivery_visible := visible_columns (8);
224 g_department_visible := visible_columns (9);
225 g_drop_lpn_visible := visible_columns(10); --bug 4510849
226 g_from_lpn_visible := visible_columns(11);
227 g_line_visible := visible_columns(12);
228 g_line_number_visible := visible_columns (13);
229 g_loaded_lpn_visible := visible_columns(14); --bug 4510849
230 g_machine_resource_visible := visible_columns (15);
231 g_num_of_child_tasks_visible := visible_columns (16);
232 g_operation_plan_visible := visible_columns (17);
233 g_operation_sequence_visible := visible_columns (18);
234 g_op_plan_instance_id_visible := visible_columns (19);
235 g_person_visible := visible_columns (20);
236 g_person_resource_visible := visible_columns (21);
237 g_picked_lpn_visible := visible_columns(22); --bug 4510849
238 g_ship_method_visible := visible_columns (23);
239 g_ship_to_country_visible := visible_columns (24);
240 g_ship_to_postal_code_visible := visible_columns (25);
241 g_ship_to_state_visible := visible_columns (26);
242 g_source_header_visible := visible_columns (27);
243 g_status_visible := visible_columns (28);
244 g_task_type_visible := visible_columns (29);
245 g_to_locator_visible := visible_columns (30);
246 g_to_lpn_visible := visible_columns (31);
247 g_to_organization_code_visible := visible_columns (32);
248 g_txn_source_type_visible := visible_columns (33);
249 g_user_task_type_visible := visible_columns (34);
250
251 wms_plan_tasks_pvt.g_allocated_lpn_visible := g_allocated_lpn_visible;
252 wms_plan_tasks_pvt.g_assembly_visible := g_assembly_visible;
253 wms_plan_tasks_pvt.g_carrier_visible := g_carrier_visible;
254 wms_plan_tasks_pvt.g_cartonization_lpn_visible :=
255 g_cartonization_lpn_visible;
256 wms_plan_tasks_pvt.g_container_item_visible := g_container_item_visible;
257 wms_plan_tasks_pvt.g_content_lpn_visible := g_content_lpn_visible;
258 wms_plan_tasks_pvt.g_customer_visible := g_customer_visible;
259 wms_plan_tasks_pvt.g_delivery_visible := g_delivery_visible;
260 wms_plan_tasks_pvt.g_department_visible := g_department_visible;
261 wms_plan_tasks_pvt.g_from_lpn_visible := g_from_lpn_visible;
262 wms_plan_tasks_pvt.g_line_visible := g_line_visible;
263 wms_plan_tasks_pvt.g_line_number_visible := g_line_number_visible;
264 wms_plan_tasks_pvt.g_machine_resource_visible :=
265 g_machine_resource_visible;
266 wms_plan_tasks_pvt.g_num_of_child_tasks_visible :=
267 g_num_of_child_tasks_visible;
268 wms_plan_tasks_pvt.g_operation_plan_visible := g_operation_plan_visible;
269 wms_plan_tasks_pvt.g_operation_sequence_visible := g_operation_sequence_visible;
270 wms_plan_tasks_pvt.g_op_plan_instance_id_visible :=
271 g_op_plan_instance_id_visible;
272 wms_plan_tasks_pvt.g_person_visible := g_person_visible;
273 wms_plan_tasks_pvt.g_person_resource_visible :=
274 g_person_resource_visible;
275 wms_plan_tasks_pvt.g_ship_method_visible := g_ship_method_visible;
276 wms_plan_tasks_pvt.g_ship_to_country_visible :=
277 g_ship_to_country_visible;
278 wms_plan_tasks_pvt.g_ship_to_postal_code_visible :=
279 g_ship_to_postal_code_visible;
280 wms_plan_tasks_pvt.g_ship_to_state_visible := g_ship_to_state_visible;
281 wms_plan_tasks_pvt.g_source_header_visible := g_source_header_visible;
282 wms_plan_tasks_pvt.g_status_visible := g_status_visible;
283 wms_plan_tasks_pvt.g_task_type_visible := g_task_type_visible;
284 wms_plan_tasks_pvt.g_to_locator_visible := g_to_locator_visible;
285 wms_plan_tasks_pvt.g_to_lpn_visible := g_to_lpn_visible;
286 wms_plan_tasks_pvt.g_to_organization_code_visible :=
287 g_to_organization_code_visible;
288 wms_plan_tasks_pvt.g_txn_source_type_visible :=
289 g_txn_source_type_visible;
290 wms_plan_tasks_pvt.g_user_task_type_visible := g_user_task_type_visible;
291 END;
292
293 PROCEDURE set_status_codes
294 IS
295 BEGIN
296 SELECT REPLACE (meaning, '''', ''''''), meaning
297 BULK COLLECT INTO g_status_codes, g_status_codes_orig
298 FROM mfg_lookups
299 WHERE lookup_type = 'WMS_TASK_STATUS'
300 ORDER BY lookup_code;
301 END;
302
303 PROCEDURE set_task_type
304 IS
305 BEGIN
306 SELECT REPLACE (meaning, '''', ''''''), meaning
307 BULK COLLECT INTO g_task_types, g_task_types_orig
308 FROM mfg_lookups
309 WHERE lookup_type = 'WMS_TASK_TYPES'
310 ORDER BY lookup_code;
311 END;
312
313 --Change
314 PROCEDURE set_plan_task_types
315 IS
316 BEGIN
317 SELECT REPLACE (meaning, '''', '''''')
318 BULK COLLECT INTO g_plan_task_types
319 FROM mfg_lookups
320 WHERE lookup_type = 'WMS_PLAN_TASK_TYPES'
321 ORDER BY lookup_code;
322 END set_plan_task_types;
323
324 PROCEDURE set_plan_status_codes
325 IS
326 BEGIN
327 SELECT REPLACE (meaning, '''', '''''')
328 BULK COLLECT INTO g_plan_status_codes
329 FROM mfg_lookups
330 WHERE lookup_type = 'WMS_OP_PLAN_INSTANCE_STATUS'
331 ORDER BY lookup_code;
332 END;
333
334 --End of Change
335 PROCEDURE set_project_locators (p_organization_id NUMBER)
336 IS
337 BEGIN
338 IF g_project_enabled_organization IS NULL
339 THEN
340 SELECT DECODE (project_reference_enabled, 1, 'Y', 'N')
341 INTO g_project_enabled_organization
342 FROM mtl_parameters
343 WHERE organization_id = p_organization_id;
344 END IF;
345
346 IF g_project_enabled_organization = 'Y'
347 THEN
348 UPDATE wms_waveplan_tasks_temp wwtt
349 SET LOCATOR =
350 inv_project.get_locator (wwtt.locator_id,
351 wwtt.organization_id
352 )
353 WHERE LOCATOR IS NULL;
354
355 IF g_to_locator_visible = 'T'
356 THEN
357 UPDATE wms_waveplan_tasks_temp wwtt
358 SET to_locator =
359 inv_project.get_locator (wwtt.to_locator_id,
360 wwtt.organization_id
361 )
362 WHERE to_locator IS NULL;
363 END IF;
364 END IF;
365 END;
366
367 PROCEDURE set_inbound_source_header_line
368 IS
369 TYPE source_header_type IS TABLE OF wms_waveplan_tasks_temp.source_header%TYPE;
370
371 TYPE line_number_type IS TABLE OF wms_waveplan_tasks_temp.line_number%TYPE;
372
373 TYPE temp_id_type IS TABLE OF wms_waveplan_tasks_temp.transaction_temp_id%TYPE;
374
375 TYPE task_type_id_type IS TABLE OF wms_waveplan_tasks_temp.task_type_id%TYPE;
376
377 l_source_header source_header_type;
378 l_line_number line_number_type;
379 l_temp_id temp_id_type;
380 l_task_type_id task_type_id_type;
381 BEGIN
382 SELECT ph.segment1, pl.line_num, wwtt.transaction_temp_id,
383 wwtt.task_type_id
384 BULK COLLECT INTO l_source_header, l_line_number, l_temp_id,
385 l_task_type_id
386 FROM po_line_locations_all pll,
387 po_headers_all ph,
388 po_lines_all pl,
389 wms_waveplan_tasks_temp wwtt
390 WHERE pll.line_location_id = wwtt.reference_id
391 AND pll.po_line_id = pl.po_line_id
392 AND ph.po_header_id = pl.po_header_id
393 AND wwtt.REFERENCE = 'PO_LINE_LOCATION_ID'
394 AND wwtt.source_header IS NULL
395 AND wwtt.reference_id IS NOT NULL;
396
397 IF l_temp_id.COUNT > 0
398 THEN
399 FORALL i IN l_temp_id.FIRST .. l_temp_id.LAST
400 UPDATE wms_waveplan_tasks_temp wwtt
401 SET source_header = l_source_header (i),
402 line_number = l_line_number (i)
403 WHERE wwtt.transaction_temp_id = l_temp_id (i)
404 AND wwtt.task_type_id = l_task_type_id (i);
405 END IF;
406
407 SELECT ooh.order_number, ool.line_number, wwtt.transaction_temp_id,
408 wwtt.task_type_id
409 BULK COLLECT INTO l_source_header, l_line_number, l_temp_id,
410 l_task_type_id
411 FROM oe_order_lines_all ool,
412 oe_order_headers_all ooh,
413 wms_waveplan_tasks_temp wwtt
414 WHERE ool.line_id = wwtt.reference_id
415 AND ooh.header_id = ool.header_id
416 AND wwtt.REFERENCE = 'ORDER_LINE_ID'
417 AND wwtt.source_header IS NULL
418 AND wwtt.reference_id IS NOT NULL;
419
420 IF l_temp_id.COUNT > 0
421 THEN
422 FORALL i IN l_temp_id.FIRST .. l_temp_id.LAST
423 UPDATE wms_waveplan_tasks_temp wwtt
424 SET source_header = l_source_header (i),
425 line_number = l_line_number (i)
426 WHERE wwtt.transaction_temp_id = l_temp_id (i)
427 AND wwtt.task_type_id = l_task_type_id (i);
428 END IF;
429
430 SELECT DECODE (rsl.requisition_line_id,
431 NULL, rsh.shipment_num,
432 prh.segment1
433 ),
434 DECODE (rsl.requisition_line_id,
435 NULL, rsl.line_num,
436 prl.line_num
437 ),
438 wwtt.transaction_temp_id, wwtt.task_type_id
439 BULK COLLECT INTO l_source_header,
440 l_line_number,
441 l_temp_id, l_task_type_id
442 -- MOAC po_requisition_headers and
443 -- po_requisition_lines switched to use _ALL tables
444 FROM po_requisition_headers_all prh,
445 po_requisition_lines_all prl,
446 rcv_shipment_lines rsl,
447 rcv_shipment_headers rsh,
448 wms_waveplan_tasks_temp wwtt
449 WHERE rsl.shipment_line_id = wwtt.reference_id
450 AND prh.requisition_header_id(+) = prl.requisition_header_id
451 AND rsl.requisition_line_id = prl.requisition_line_id(+)
452 AND rsl.shipment_header_id = rsh.shipment_header_id
453 AND wwtt.REFERENCE = 'SHIPMENT_LINE_ID'
454 AND wwtt.source_header IS NULL
455 AND wwtt.reference_id IS NOT NULL;
456
457 IF l_temp_id.COUNT > 0
458 THEN
459 FORALL i IN l_temp_id.FIRST .. l_temp_id.LAST
460 UPDATE wms_waveplan_tasks_temp wwtt
461 SET source_header = l_source_header (i),
462 line_number = l_line_number (i)
463 WHERE wwtt.transaction_temp_id = l_temp_id (i)
464 AND wwtt.task_type_id = l_task_type_id (i);
465 END IF;
466 END;
467
468 --Patchset J Bulk Picking Enhancement
469 --This procedure calcuate the number of children task
470 --associated with parent tasks
471 PROCEDURE set_num_of_child_tasks
472 IS
473 l_debug NUMBER
474 := NVL (fnd_profile.VALUE ('INV_DEBUG_TRACE'), 0);
475 l_progress NUMBER;
476
477 TYPE num_of_child_tasks_type IS TABLE OF wms_waveplan_tasks_temp.num_of_child_tasks%TYPE;
478
479 l_num_of_child_tasks_tbl num_of_child_tasks_type;
480 l_parent_temp_ids_tbl wms_waveplan_tasks_pvt.transaction_temp_table_type;
481 BEGIN
482 IF l_debug = 1
483 THEN
484 DEBUG ( 'set_num_of_child_tasks entered '
485 || TO_CHAR (SYSDATE, 'YYYY-MM-DD HH:DD:SS'),
486 'WMS_WAVEPLAN_TASKS_PVT'
487 );
488 END IF;
489
490 l_progress := 10;
491
492 --MMTT used to get children task.
493 --wwtt used to get the parent task.
494 SELECT COUNT (1), wwtt.transaction_temp_id
495 BULK COLLECT INTO l_num_of_child_tasks_tbl, l_parent_temp_ids_tbl
496 FROM wms_waveplan_tasks_temp wwtt,
497 mtl_material_transactions_temp mmtt
498 WHERE wwtt.transaction_temp_id = mmtt.parent_line_id
499 AND wwtt.transaction_temp_id <> mmtt.transaction_temp_id
500 GROUP BY wwtt.transaction_temp_id;
501
502 l_progress := 20;
503
504 IF l_num_of_child_tasks_tbl.COUNT > 0
505 THEN
506 l_progress := 30;
507 FORALL i IN l_num_of_child_tasks_tbl.FIRST .. l_num_of_child_tasks_tbl.LAST
508 UPDATE wms_waveplan_tasks_temp wwtt
509 SET wwtt.num_of_child_tasks = l_num_of_child_tasks_tbl (i)
510 WHERE wwtt.transaction_temp_id = l_parent_temp_ids_tbl (i);
511 l_progress := 40;
512 END IF;
513
514 l_progress := 50;
515
516 IF l_debug = 1
517 THEN
518 DEBUG ( 'set_num_of_child_tasks exited '
519 || TO_CHAR (SYSDATE, 'YYYY-MM-DD HH:DD:SS'),
520 'WMS_WAVEPLAN_TASKS_PVT'
521 );
522 END IF;
523 EXCEPTION
524 WHEN NO_DATA_FOUND
525 THEN --no parent bulk task
526 IF l_debug = 1
527 THEN
528 DEBUG
529 ( 'set_num_of_child_tasks no_data_found after l_progress '
530 || l_progress,
531 'WMS_WAVEPLAN_TASKS_PVT'
532 );
533
534 IF l_progress = 10
535 THEN
536 DEBUG
537 ( 'set_num_of_child_tasks exited normally with no parent '
538 || 'task found '
539 || TO_CHAR (SYSDATE, 'YYYY-MM-DD HH:DD:SS'),
540 'WMS_WAVEPLAN_TASKS_PVT'
541 );
542 END IF;
543 END IF;
544 WHEN OTHERS
545 THEN
546 IF l_debug = 1
547 THEN
548 DEBUG
549 ( 'set_num_of_child_tasks OTHERS exception after l_progress '
550 || l_progress,
551 'WMS_WAVEPLAN_TASKS_PVT'
552 );
553 END IF;
554 END set_num_of_child_tasks;
555
556 /*Added procedure set_picking_lpns for bug 4510849*/
557
558 PROCEDURE set_picking_lpns(p_is_loaded BOOLEAN,
559 p_is_completed BOOLEAN) IS
560 BEGIN
561
562 IF p_is_completed THEN
563 -- Completed Tasks
564 IF g_picked_lpn_visible = 'T' OR g_loaded_lpn_visible = 'T' OR g_drop_lpn_visible = 'T' THEN
565 UPDATE wms_waveplan_tasks_temp
566 -- transfer_lpn_id would be null if it is loaded into the same lpn as that of picked.
567 SET picked_lpn_id = NVL(from_lpn_id, content_lpn_id),
568 loaded_lpn_id = Nvl(to_lpn_id, Nvl(from_lpn_id, content_lpn_id))
569 WHERE task_type_id IN (1, 4, 5, 6)
570 AND status_id = 6;
571 END IF;
572
573 IF g_picked_lpn_visible = 'T' THEN
574 UPDATE wms_waveplan_tasks_temp
575 SET picked_lpn = (SELECT license_plate_number FROM wms_license_plate_numbers WHERE lpn_id = picked_lpn_id)
576 WHERE picked_lpn_id IS NOT NULL
577 AND task_type_id IN (1, 4, 5, 6)
578 AND status_id = 6;
579 END IF;
580
581 IF g_loaded_lpn_visible = 'T' THEN
582 UPDATE wms_waveplan_tasks_temp
583 SET loaded_lpn = (SELECT license_plate_number FROM wms_license_plate_numbers WHERE lpn_id = loaded_lpn_id)
584 WHERE loaded_lpn_id IS NOT NULL
585 AND task_type_id IN (1, 4, 5, 6)
586 AND status_id = 6;
587 END IF;
588
589 IF g_drop_lpn_visible = 'T' THEN
590 UPDATE wms_waveplan_tasks_temp wstt
591 SET drop_lpn = Nvl((select license_plate_number
592 FROM wms_license_plate_numbers wlpn, mtl_material_transactions mmt
593 WHERE wlpn.lpn_id = mmt.transfer_lpn_id
594 AND mmt.transaction_action_id = 50
595 AND mmt.transaction_set_id = wstt.transaction_set_id
596 AND mmt.transaction_quantity > 0),
597 loaded_lpn)
598 WHERE task_type_id IN (1, 4, 5, 6)
599 AND status_id = 6;
600 END IF;
601 END IF;
602
603 IF p_is_loaded THEN
604 -- Loaded Tasks
605 IF g_picked_lpn_visible = 'T' OR g_loaded_lpn_visible = 'T' THEN
606 UPDATE wms_waveplan_tasks_temp
607 -- transfer_lpn_id would be null if it is loaded into the same lpn as that of picked.
608 SET picked_lpn_id = Nvl(from_lpn_id, content_lpn_id),
609 loaded_lpn_id = to_lpn_id
610 WHERE task_type_id IN (1, 4, 5, 6)
611 AND status_id = 4;
612 END IF;
613
614 IF g_picked_lpn_visible = 'T' THEN
615 UPDATE wms_waveplan_tasks_temp
616 SET picked_lpn = (SELECT license_plate_number FROM wms_license_plate_numbers WHERE lpn_id = picked_lpn_id)
617 WHERE picked_lpn_id IS NOT NULL
618 AND task_type_id IN (1, 4, 5, 6)
619 AND status_id = 4;
620 END IF;
621
622 IF g_loaded_lpn_visible = 'T' THEN
623 UPDATE wms_waveplan_tasks_temp
624 SET loaded_lpn = (SELECT license_plate_number FROM wms_license_plate_numbers WHERE lpn_id = loaded_lpn_id)
625 WHERE loaded_lpn_id IS NOT NULL
626 AND task_type_id IN (1, 4, 5, 6)
627 AND status_id = 4;
628 END IF;
629 END IF;
630 END set_picking_lpns;
631
632 FUNCTION get_generic_insert (
633 p_is_unreleased BOOLEAN DEFAULT FALSE,
634 p_is_pending BOOLEAN DEFAULT FALSE,
635 p_is_queued BOOLEAN DEFAULT FALSE,
636 p_is_dispatched BOOLEAN DEFAULT FALSE,
637 p_is_active BOOLEAN DEFAULT FALSE,
638 p_is_loaded BOOLEAN DEFAULT FALSE,
639 p_is_completed BOOLEAN DEFAULT FALSE
640 )
641 RETURN VARCHAR2
642 IS
643 l_insert_generic VARCHAR2 (2000);
644 l_join_wdt BOOLEAN;
645 BEGIN
646 IF (p_is_unreleased OR p_is_pending)
647 AND NOT (p_is_queued OR p_is_dispatched OR p_is_loaded OR p_is_active
648 )
649 THEN
650 -- Query records present only in MMTT
651 l_join_wdt := FALSE;
652 ELSIF (p_is_unreleased OR p_is_pending)
653 AND (p_is_queued OR p_is_dispatched OR p_is_loaded OR p_is_active
654 )
655 THEN
656 -- Query records present only in MMTT as well as those in both MMTT and WDT
657 l_join_wdt := TRUE;
658 ELSIF NOT (p_is_unreleased OR p_is_pending)
659 AND ( p_is_queued
660 OR p_is_dispatched
661 OR p_is_loaded
662 OR p_is_active
663 OR p_is_completed
664 )
665 THEN
666 -- Query records present both in MMTT and WDT
667 l_join_wdt := TRUE;
668 END IF;
669
670 l_insert_generic := 'INSERT INTO wms_waveplan_tasks_temp( ';
671 /* Patchset J - ATF - we have to insert expansion_code, plans_tasks also
672 * into the temp table
673 */
674 l_insert_generic := l_insert_generic || 'expansion_code';
675 l_insert_generic := l_insert_generic || ', plans_tasks';
676 l_insert_generic := l_insert_generic || ', transaction_temp_id ';
677 --Patchset J Bulk Picking Enhancement. Always include parent_line_id in wwtt,
678 --not just when querying for non-completed tasks. Because now
679 --we are showing completed parent tasks, which we weren't showing before.
680 --Thus, we need a link between completed parents and children
681 l_insert_generic := l_insert_generic || ', parent_line_id ';
682 l_insert_generic := l_insert_generic || ', inventory_item_id ';
683 l_insert_generic := l_insert_generic || ', item ';
684 l_insert_generic := l_insert_generic || ', item_description ';
685 l_insert_generic := l_insert_generic || ', unit_weight ';
686 l_insert_generic := l_insert_generic || ', weight_uom_code ';
687 l_insert_generic := l_insert_generic || ', unit_volume ';
688 l_insert_generic := l_insert_generic || ', volume_uom_code ';
689 l_insert_generic := l_insert_generic || ', organization_id ';
690 l_insert_generic := l_insert_generic || ', revision ';
691 l_insert_generic := l_insert_generic || ', subinventory ';
692 l_insert_generic := l_insert_generic || ', locator_id ';
693 l_insert_generic := l_insert_generic || ', locator ';
694 l_insert_generic := l_insert_generic || ', status_id ';
695 l_insert_generic := l_insert_generic || ', status_id_original ';
696 l_insert_generic := l_insert_generic || ', status ';
697 l_insert_generic := l_insert_generic || ', transaction_type_id ';
698 l_insert_generic := l_insert_generic || ', transaction_action_id ';
699 l_insert_generic := l_insert_generic || ', transaction_source_type_id ';
700
701 IF g_txn_source_type_visible = 'T'
702 THEN
703 l_insert_generic := l_insert_generic || ', transaction_source_type ';
704 END IF;
705
706 l_insert_generic := l_insert_generic || ', transaction_source_id ';
707 l_insert_generic := l_insert_generic || ', transaction_source_line_id ';
708 l_insert_generic := l_insert_generic || ', to_organization_id ';
709
710 IF g_to_organization_code_visible = 'T'
711 THEN
712 l_insert_generic := l_insert_generic || ', to_organization_code ';
713 END IF;
714
715 l_insert_generic := l_insert_generic || ', to_subinventory ';
716 l_insert_generic := l_insert_generic || ', to_locator_id ';
717
718 IF g_to_locator_visible = 'T'
719 THEN
720 l_insert_generic := l_insert_generic || ', to_locator ';
721 END IF;
722
723 l_insert_generic := l_insert_generic || ', transaction_uom ';
724 l_insert_generic := l_insert_generic || ', transaction_quantity ';
725 l_insert_generic := l_insert_generic || ', user_task_type_id ';
726
727 IF g_user_task_type_visible = 'T'
728 THEN
729 l_insert_generic := l_insert_generic || ', user_task_type ';
730 END IF;
731
732 l_insert_generic := l_insert_generic || ', move_order_line_id ';
733 l_insert_generic := l_insert_generic || ', pick_slip_number ';
734 l_insert_generic := l_insert_generic || ', cartonization_id ';
735
736 IF g_cartonization_lpn_visible = 'T'
737 THEN --AND NOT p_is_completed THEN
738 l_insert_generic := l_insert_generic || ', cartonization_lpn ';
739 END IF;
740
741 l_insert_generic := l_insert_generic || ', allocated_lpn_id ';
742
743 IF g_allocated_lpn_visible = 'T' /*AND NOT p_is_completed*/
744 THEN
745 l_insert_generic := l_insert_generic || ', allocated_lpn ';
746 END IF;
747
748 l_insert_generic := l_insert_generic || ', container_item_id ';
749
750 IF g_container_item_visible = 'T' /*AND NOT p_is_completed*/
751 THEN
752 l_insert_generic := l_insert_generic || ', container_item ';
753 END IF;
754
755 l_insert_generic := l_insert_generic || ', from_lpn_id ';
756
757 IF g_from_lpn_visible = 'T'
758 THEN
759 l_insert_generic := l_insert_generic || ', from_lpn ';
760 END IF;
761
762 l_insert_generic := l_insert_generic || ', content_lpn_id ';
763
764 IF g_content_lpn_visible = 'T'
765 THEN
766 l_insert_generic := l_insert_generic || ', content_lpn ';
767 END IF;
768
769 l_insert_generic := l_insert_generic || ', to_lpn_id ';
770
771 IF g_to_lpn_visible = 'T'
772 THEN
773 l_insert_generic := l_insert_generic || ', to_lpn ';
774 END IF;
775
776 l_insert_generic := l_insert_generic || ', mmtt_last_update_date ';
777 l_insert_generic := l_insert_generic || ', mmtt_last_updated_by ';
778 l_insert_generic := l_insert_generic || ', priority ';
779 l_insert_generic := l_insert_generic || ', priority_original ';
780 l_insert_generic := l_insert_generic || ', task_type_id ';
781 l_insert_generic := l_insert_generic || ', task_type ';
782 l_insert_generic := l_insert_generic || ', creation_time ';
783 l_insert_generic := l_insert_generic || ', operation_plan_id ';
784
785 IF g_operation_plan_visible = 'T'
786 THEN
787 l_insert_generic := l_insert_generic || ', operation_plan ';
788 END IF;
789
790 IF g_operation_sequence_visible = 'T' THEN
791 l_insert_generic := l_insert_generic || ', operation_sequence ';
792 END IF;
793
794 l_insert_generic := l_insert_generic || ', op_plan_instance_id ';
795
796 IF l_join_wdt
797 THEN
798 l_insert_generic := l_insert_generic || ', task_id ';
799 l_insert_generic := l_insert_generic || ', person_id ';
800 l_insert_generic := l_insert_generic || ', person_id_original ';
801
802 IF g_person_visible = 'T'
803 THEN
804 l_insert_generic := l_insert_generic || ', person ';
805 END IF;
806
807 l_insert_generic := l_insert_generic || ', effective_start_date ';
808 l_insert_generic := l_insert_generic || ', effective_end_date ';
809 l_insert_generic := l_insert_generic || ', person_resource_id ';
810
811 IF g_person_resource_visible = 'T'
812 THEN
813 l_insert_generic := l_insert_generic || ', person_resource_code ';
814 END IF;
815
816 l_insert_generic := l_insert_generic || ', machine_resource_id ';
817
818 IF g_machine_resource_visible = 'T'
819 THEN
820 l_insert_generic :=
821 l_insert_generic || ', machine_resource_code ';
822 END IF;
823
824 l_insert_generic := l_insert_generic || ', equipment_instance ';
825 l_insert_generic := l_insert_generic || ', dispatched_time ';
826 l_insert_generic := l_insert_generic || ', loaded_time ';
827 l_insert_generic := l_insert_generic || ', drop_off_time ';
828 l_insert_generic := l_insert_generic || ', wdt_last_update_date ';
829 l_insert_generic := l_insert_generic || ', wdt_last_updated_by ';
830 END IF;
831
832 l_insert_generic := l_insert_generic || ', is_modified ';
833 -- Bug #4141928
834 l_insert_generic := l_insert_generic || ', secondary_transaction_uom ';
835 l_insert_generic := l_insert_generic || ', secondary_transaction_quantity ';
836
837 IF p_is_completed THEN --bug 4510849
838 IF NOT (wms_plan_tasks_pvt.g_include_inbound OR wms_plan_tasks_pvt.g_include_crossdock) THEN /* Bug 4047985 */
839 l_insert_generic := l_insert_generic || ', transaction_set_id ';
840 END IF; /* End of Bug 4047985 */
841 END IF;
842
843 RETURN l_insert_generic;
844 END;
845
846 FUNCTION get_generic_select (
847 p_is_unreleased BOOLEAN DEFAULT FALSE,
848 p_is_pending BOOLEAN DEFAULT FALSE,
849 p_is_queued BOOLEAN DEFAULT FALSE,
850 p_is_dispatched BOOLEAN DEFAULT FALSE,
851 p_is_active BOOLEAN DEFAULT FALSE,
852 p_is_loaded BOOLEAN DEFAULT FALSE,
853 p_is_completed BOOLEAN DEFAULT FALSE,
854 p_populate_merged_tasks BOOLEAN DEFAULT FALSE
855 )
856 RETURN VARCHAR2
857 IS
858 l_select_generic VARCHAR2 (4000);
859 l_join_wdt BOOLEAN;
860 BEGIN
861 IF NOT p_is_completed
862 THEN
863
864 IF (p_is_unreleased OR p_is_pending)
865 AND NOT (p_is_queued OR p_is_dispatched OR p_is_loaded
866 OR p_is_active
867 )
868 THEN
869 -- Query records present only in MMTT
870 l_join_wdt := FALSE;
871 ELSIF (p_is_unreleased OR p_is_pending)
872 AND (p_is_queued OR p_is_dispatched OR p_is_loaded
873 OR p_is_active
874 )
875 THEN
876 -- Query records present only in MMTT as well as those in both MMTT and WDT
877 l_join_wdt := TRUE;
878 ELSIF NOT (p_is_unreleased OR p_is_pending)
879 AND (p_is_queued OR p_is_dispatched OR p_is_loaded
880 OR p_is_active
881 )
882 THEN
883 -- Query records present both in MMTT and WDT
884 l_join_wdt := TRUE;
885 END IF;
886
887 -- Build the generic select section of the query
888 l_select_generic := 'SELECT ';
889 l_select_generic := l_select_generic || 'null, '; -- expansion_code
890 l_select_generic :=
891 l_select_generic
892 || 'decode(mmtt.parent_line_id,'
893 || ' null,decode(mmtt.operation_plan_id,null,'''
894 || g_plan_task_types (1)
895 || ''','
896 || ' decode(mmtt.transaction_action_id,28,'''
897 || g_plan_task_types(1)
898 || ''','
899 || ' decode(mmtt.transaction_source_type_id, 5, '''
900 || g_plan_task_types(1)
901 || ''','
902 || ' 13, decode(mmtt.transaction_type_id,51,'''
903 || g_plan_task_types(1)
904 || ''','''
905 || g_plan_task_types(3)
906 || ''' )))), '
907 || ' mmtt.transaction_temp_id, '''
908 || g_plan_task_types (4)
909 || ''','''
910 || g_plan_task_types (2)
911 || '''),';
912
913 --planned task only since won't show non-completed bulk children
914 l_select_generic := l_select_generic || 'mmtt.transaction_temp_id, ';
915 --transaction_temp_id
916 l_select_generic := l_select_generic || 'mmtt.parent_line_id, ';
917 --parent_line_id
918 l_select_generic := l_select_generic || 'mmtt.inventory_item_id, ';
919 --inventory_item_id
920 l_select_generic :=
921 l_select_generic || 'msiv.concatenated_segments, ';
922 --item
923 l_select_generic := l_select_generic || 'msiv.description, ';
924 --item description
925 l_select_generic := l_select_generic || 'msiv.unit_weight, ';
926 --unit_weight
927 l_select_generic := l_select_generic || 'msiv.weight_uom_code, ';
928 --weight_uom_code
929 l_select_generic := l_select_generic || 'msiv.unit_volume, ';
930 --unit_volume
931 l_select_generic := l_select_generic || 'msiv.volume_uom_code, ';
932 --volume_uom_code
933 l_select_generic := l_select_generic || 'mmtt.organization_id, ';
934 --organization_id
935 l_select_generic := l_select_generic || 'mmtt.revision, '; --revision
936 l_select_generic := l_select_generic || 'mmtt.subinventory_code, ';
937 --subinventory
938 l_select_generic := l_select_generic || 'mmtt.locator_id, ';
939 --locator_id
940 --locator
941 l_select_generic :=
942 l_select_generic
943 || 'decode(milv.segment19, null, milv.concatenated_segments, null), ';
944
945 IF l_join_wdt
946 THEN
947 --status_id
948 l_select_generic :=
949 l_select_generic
950 || 'decode(wdt.status, null, nvl(mmtt.wms_task_status, 1), wdt.status), ';
951 --status_id_original
952 l_select_generic :=
953 l_select_generic
954 || 'decode(wdt.status, null, nvl(mmtt.wms_task_status, 1), wdt.status), ';
955 --status
956 l_select_generic :=
957 l_select_generic
958 || 'decode(decode(wdt.status, null, nvl(mmtt.wms_task_status, 1), wdt.status),'
959 || '1, '''
960 || g_status_codes (1)
961 || ''', 2, '''
962 || g_status_codes (2)
963 || ''', 3, '''
964 || g_status_codes (3)
965 || ''', 4, '''
966 || g_status_codes (4)
967 || ''', 5, '''
968 || g_status_codes (5)
969 || ''', 6, '''
970 || g_status_codes (6)
971 || ''', 7, '''
972 || g_status_codes (7)
973 || ''', 8, '''
974 || g_status_codes (8)
975 || ''', '
976 || '9, '''
977 || g_status_codes (9)
978 || '''), ';
979 ELSE
980 --status_id
981 l_select_generic :=
982 l_select_generic || 'nvl(mmtt.wms_task_status, 1), ';
983 --status_id_original
984 l_select_generic :=
985 l_select_generic || 'nvl(mmtt.wms_task_status, 1), ';
986 --status
987 l_select_generic :=
988 l_select_generic
989 || 'decode(nvl(mmtt.wms_task_status, 1),'
990 || '1, '''
991 || g_status_codes (1)
992 || ''', 8, '''
993 || g_status_codes (8)
994 || '''), ';
995 END IF;
996
997 l_select_generic := l_select_generic || 'mmtt.transaction_type_id, ';
998 --transaction_type_id
999 l_select_generic :=
1000 l_select_generic || 'mmtt.transaction_action_id, ';
1001 --transaction_action_id
1002 l_select_generic :=
1003 l_select_generic || 'mmtt.transaction_source_type_id, ';
1004 --transaction_source_type_id
1005
1006 IF g_txn_source_type_visible = 'T'
1007 THEN
1008 l_select_generic :=
1009 l_select_generic || 'mtst.transaction_source_type_name, ';
1010 --transaction_source_type
1011 END IF;
1012
1013 l_select_generic :=
1014 l_select_generic || 'mmtt.transaction_source_id, ';
1015 --transaction_source_id
1016 l_select_generic := l_select_generic || 'mmtt.trx_source_line_id, ';
1017 --transaction_source_line_id
1018 l_select_generic :=
1019 l_select_generic || 'mmtt.transfer_organization, ';
1020 --to_organization_id
1021
1022 IF g_to_organization_code_visible = 'T'
1023 THEN
1024 l_select_generic := l_select_generic || 'mp1.organization_code, ';
1025 --to_organization_id
1026 END IF;
1027
1028 l_select_generic :=
1029 l_select_generic || 'mmtt.transfer_subinventory, ';
1030 --to_subinventory
1031 l_select_generic := l_select_generic || 'mmtt.transfer_to_location, ';
1032 --to_locator_id
1033
1034 IF g_to_locator_visible = 'T'
1035 THEN
1036 --to_locator_id
1037 l_select_generic :=
1038 l_select_generic
1039 || 'decode(milv1.segment19, null, milv1.concatenated_segments, null), ';
1040 END IF;
1041
1042 l_select_generic := l_select_generic || 'mmtt.transaction_uom, ';
1043 --transaction_uom
1044 l_select_generic := l_select_generic || 'mmtt.transaction_quantity, ';
1045 --transaction_quantity
1046 l_select_generic :=
1047 l_select_generic || 'mmtt.standard_operation_id, ';
1048 --user_task_type_id
1049
1050 IF g_user_task_type_visible = 'T'
1051 THEN
1052 l_select_generic := l_select_generic || 'bso.operation_code, ';
1053 --user_task_type
1054 END IF;
1055
1056 IF NOT p_populate_merged_tasks
1057 THEN
1058 l_select_generic :=
1059 l_select_generic || 'mmtt.move_order_line_id, ';
1060 --move_order_line_id
1061 --Change
1062 l_select_generic := l_select_generic || 'mmtt.pick_slip_number, ';
1063 --pick_slip_number
1064 -- End of Change
1065 ELSE
1066 l_select_generic := l_select_generic || 'to_number(null), ';
1067 --move_order_line_id
1068 --Change
1069 l_select_generic := l_select_generic || 'to_number(null), ';
1070 --pick_slip_number
1071 -- End of Change
1072 END IF;
1073
1074 --Change
1075 /*IF NOT p_populate_merged_tasks THEN
1076 l_select_generic := l_select_generic || 'mmtt.pick_slip_number, '; --pick_slip_number
1077 ELSE
1078 l_select_generic := l_select_generic || 'to_number(null), '; --pick_slip_number
1079 END IF;*/
1080 --End of change
1081 l_select_generic := l_select_generic || 'mmtt.cartonization_id, ';
1082 --cartonization_id
1083
1084 IF g_cartonization_lpn_visible = 'T'
1085 THEN
1086 l_select_generic :=
1087 l_select_generic || 'wlpn2.license_plate_number, ';
1088 --cartonization_lpn
1089 END IF;
1090
1091 l_select_generic := l_select_generic || 'mmtt.allocated_lpn_id, ';
1092 --allocated_lpn_id
1093
1094 IF g_allocated_lpn_visible = 'T'
1095 THEN
1096 l_select_generic :=
1097 l_select_generic || 'wlpn1.license_plate_number, ';
1098 --allocated_lpn
1099 END IF;
1100
1101 l_select_generic := l_select_generic || 'mmtt.container_item_id, ';
1102 --container_item_id
1103
1104 IF g_container_item_visible = 'T'
1105 THEN
1106 l_select_generic :=
1107 l_select_generic || 'msiv1.concatenated_segments, ';
1108 --container_item
1109 END IF;
1110
1111 l_select_generic := l_select_generic || 'mmtt.lpn_id, ';
1112 --from_lpn_id
1113
1114 IF g_from_lpn_visible = 'T'
1115 THEN
1116 l_select_generic :=
1117 l_select_generic || 'wlpn5.license_plate_number, ';
1118 --from_lpn
1119 END IF;
1120
1121 l_select_generic := l_select_generic || 'mmtt.content_lpn_id, ';
1122 --content_lpn_id
1123
1124 IF g_content_lpn_visible = 'T'
1125 THEN
1126 l_select_generic :=
1127 l_select_generic || 'wlpn3.license_plate_number, ';
1128 --content_lpn
1129 END IF;
1130
1131 l_select_generic := l_select_generic || 'mmtt.transfer_lpn_id, ';
1132 --to_lpn_id
1133
1134 IF g_to_lpn_visible = 'T'
1135 THEN
1136 l_select_generic :=
1137 l_select_generic || 'wlpn4.license_plate_number, ';
1138 --to_lpn
1139 END IF;
1140
1141 l_select_generic := l_select_generic || 'mmtt.last_update_date, ';
1142 --mmtt_last_update_date
1143 l_select_generic := l_select_generic || 'mmtt.last_updated_by, ';
1144 --mmtt_last_updated_by
1145 l_select_generic := l_select_generic || 'mmtt.task_priority, ';
1146 --priority
1147 l_select_generic := l_select_generic || 'mmtt.task_priority, ';
1148 --priority_original
1149 l_select_generic := l_select_generic || 'mmtt.wms_task_type, ';
1150 --task_type_id
1151 --task_type
1152 l_select_generic :=
1153 l_select_generic
1154 || 'decode(mmtt.wms_task_type,'
1155 || '1, '''
1156 || g_task_types (1)
1157 || ''', 2, '''
1158 || g_task_types (2)
1159 || ''', 3, '''
1160 || g_task_types (3)
1161 || ''', 4, '''
1162 || g_task_types (4)
1163 || ''', 5, '''
1164 || g_task_types (5)
1165 || ''', 6, '''
1166 || g_task_types (6)
1167 || ''', 7, '''
1168 || g_task_types (7)
1169 || ''', 8, '''
1170 || g_task_types (8)
1171 || '''), ';
1172 l_select_generic := l_select_generic || 'mmtt.creation_date, ';
1173 --creation_time
1174 l_select_generic := l_select_generic || 'mmtt.operation_plan_id, ';
1175 --operation_plan_id
1176
1177 IF g_operation_plan_visible = 'T'
1178 THEN
1179 l_select_generic :=
1180 l_select_generic || 'wop.operation_plan_name, ';
1181 --operation_plan
1182 END IF;
1183
1184 --IF g_op_plan_instance_id_visible = 'T' THEN
1185 IF wms_plan_tasks_pvt.g_query_planned_tasks = TRUE
1186 THEN
1187 IF g_operation_sequence_visible = 'T' THEN
1188 l_select_generic := l_select_generic || 'wooi.operation_sequence, '; --operation_sequence
1189 END IF;
1190
1191 l_select_generic :=
1192 l_select_generic || 'wooi.op_plan_instance_id, ';
1193 --op_plan_instance_id
1194 ELSE
1195 IF g_operation_sequence_visible = 'T' THEN
1196 l_select_generic := l_select_generic || 'to_number(null), '; --operation_sequence
1197 END IF;
1198
1199 l_select_generic := l_select_generic || 'to_number(null), ';
1200 --op_plan_instance_id
1201 END IF;
1202
1203 -- END IF;
1204 IF l_join_wdt
1205 THEN
1206 l_select_generic := l_select_generic || 'wdt.task_id, ';
1207 --task_id
1208 l_select_generic := l_select_generic || 'wdt.person_id, ';
1209 --person_id
1210 l_select_generic := l_select_generic || 'wdt.person_id, ';
1211 --person_id_original
1212
1213 IF g_person_visible = 'T'
1214 THEN
1215 l_select_generic := l_select_generic || 'pap.full_name, ';
1216 --person_id
1217 END IF;
1218
1219 l_select_generic :=
1220 l_select_generic || 'wdt.effective_start_date, ';
1221 --effective_start_date
1222 l_select_generic := l_select_generic || 'wdt.effective_end_date, ';
1223 --effective_end_date
1224 l_select_generic := l_select_generic || 'wdt.person_resource_id, ';
1225 --person_resource_id
1226
1227 IF g_person_resource_visible = 'T'
1228 THEN
1229 l_select_generic := l_select_generic || 'br1.resource_code, ';
1230 --person_resource_code
1231 END IF;
1232
1233 l_select_generic :=
1234 l_select_generic || 'wdt.machine_resource_id, ';
1235 --machine_resource_id
1236
1237 IF g_machine_resource_visible = 'T'
1238 THEN
1239 l_select_generic := l_select_generic || 'br2.resource_code, ';
1240 --machine_resource_code
1241 END IF;
1242
1243 l_select_generic := l_select_generic || 'wdt.equipment_instance, ';
1244 --equipment_instance
1245 l_select_generic := l_select_generic || 'wdt.dispatched_time, ';
1246 --dispatched_time
1247 l_select_generic := l_select_generic || 'wdt.loaded_time, ';
1248 --loaded_time
1249 l_select_generic := l_select_generic || 'wdt.drop_off_time, ';
1250 --drop_off_time
1251 l_select_generic := l_select_generic || 'wdt.last_update_date, ';
1252 --wdt_last_update_date
1253 l_select_generic := l_select_generic || 'wdt.last_updated_by, ';
1254 --wdt_last_updated_by
1255 -- Bug #3754781 -1 line, +1 line
1256 --ELSIF wms_plan_tasks_pvt.g_include_inbound
1257 ELSIF wms_plan_tasks_pvt.g_inbound_cycle
1258 THEN
1259 l_select_generic :=
1260 l_select_generic
1261 || 'to_number(null), ' /*task_id*/
1262 || 'to_number(null), ' /*person_id*/
1263 || 'to_number(null), '; --person_id_original
1264
1265 IF g_person_visible = 'T'
1266 THEN
1267 l_select_generic := l_select_generic || 'NULL, ';
1268 --person_id
1269 END IF;
1270
1271 l_select_generic :=
1272 l_select_generic
1273 || 'TO_DATE(NULL), ' /*effective_start_date*/
1274 || 'TO_DATE(NULL), ' /*effective_end_date*/
1275 || 'TO_NUMBER(NULL), '; --person_resource_id
1276
1277 IF g_person_resource_visible = 'T'
1278 THEN
1279 l_select_generic := l_select_generic || 'NULL, ';
1280 --person_resource_code
1281 END IF;
1282
1283 l_select_generic := l_select_generic || 'TO_NUMBER(NULL), ';
1284 --machine_resource_id
1285
1286 IF g_machine_resource_visible = 'T'
1287 THEN
1288 l_select_generic := l_select_generic || 'NULL, ';
1289 --machine_resource_code
1290 END IF;
1291
1292 l_select_generic := l_select_generic || 'NULL, ';
1293 --equipment_instance
1294 l_select_generic := l_select_generic || 'TO_DATE(NULL), ';
1295 --dispatched_time
1296 l_select_generic := l_select_generic || 'TO_DATE(NULL), ';
1297 --loaded_time
1298 l_select_generic := l_select_generic || 'TO_DATE(NULL), ';
1299 --drop_off_time
1300 l_select_generic := l_select_generic || 'TO_DATE(NULL), ';
1301 --wdt_last_update_date
1302 l_select_generic := l_select_generic || 'TO_NUMBER(NULL), ';
1303 --wdt_last_updated_by
1304 END IF;
1305
1306 l_select_generic := l_select_generic || '''N'', '; --is_modified
1307 -- Bug #4141928
1308 l_select_generic := l_select_generic || 'mmtt.secondary_uom_code, ';
1309 --sec_transaction_uom
1310 l_select_generic :=
1311 l_select_generic || 'mmtt.secondary_transaction_quantity ';
1312 --sec_transaction_quantity
1313
1314 RETURN l_select_generic;
1315 ELSIF (p_is_completed AND NOT p_populate_merged_tasks)
1316 THEN
1317 -- Build the generic select section of the query
1318 l_select_generic := 'SELECT ';
1319 l_select_generic := l_select_generic || 'null, '; -- expansion_code
1320 l_select_generic :=
1321 l_select_generic
1322 || 'decode(wdth.is_parent,'
1323 || '''Y'', decode(wdth.transaction_action_id,28,'''
1324 || g_plan_task_types (4)
1325 || ''','
1326 || 'decode(wdth.transaction_source_type_id,'
1327 || '5,decode(wdth.transaction_type_id,35,'''
1328 || g_plan_task_types (4)
1329 || ''','''
1330 || g_plan_task_types (3)
1331 || '''),'
1332 || '13, decode(wdth.transaction_type_id,51,'''
1333 || g_plan_task_types (4)
1334 || ''','''
1335 || g_plan_task_types (3)
1336 || '''),'''
1337 || g_plan_task_types (3)
1338 || ''')),'
1339 || 'decode(wdth.parent_transaction_id,null,''' --'N' or null
1340 || g_plan_task_types(1)
1341 || ''','
1342 || 'decode(wdth.transaction_action_id,28,'''
1343 || g_plan_task_types(5)
1344 || ''','
1345 || 'decode(wdth.transaction_source_type_id,'
1346 || '5,decode(wdth.transaction_type_id,35,'''
1347 || g_plan_task_types (5)
1348 || ''','''
1349 || g_plan_task_types (2)
1350 || '''),'
1351 || '13, decode(wdth.transaction_type_id,51,'''
1352 || g_plan_task_types (5)
1353 || ''','''
1354 || g_plan_task_types (2)
1355 || '''),'''
1356 || g_plan_task_types (2)
1357 || ''')))),'; --plan task
1358 l_select_generic := l_select_generic || 'mmt.transaction_id, ';
1359 --transaction_temp_id
1360 l_select_generic := l_select_generic || 'wdth.parent_transaction_id,';
1361 --parent_line_id
1362 l_select_generic := l_select_generic || 'mmt.inventory_item_id, ';
1363 --inventory_item_id
1364 l_select_generic :=
1365 l_select_generic || 'msiv.concatenated_segments, ';
1366 --item
1367 l_select_generic := l_select_generic || 'msiv.description, ';
1368 --item description
1369 l_select_generic := l_select_generic || 'msiv.unit_weight, ';
1370 --unit_weight
1371 l_select_generic := l_select_generic || 'msiv.weight_uom_code, ';
1372 --weight_uom_code
1373 l_select_generic := l_select_generic || 'msiv.unit_volume, ';
1374 --unit_volume
1375 l_select_generic := l_select_generic || 'msiv.volume_uom_code, ';
1376 --volume_uom_code
1377 l_select_generic := l_select_generic || 'mmt.organization_id, ';
1378 --organization_id
1379 l_select_generic := l_select_generic || 'mmt.revision, '; --revision
1380 l_select_generic := l_select_generic || 'mmt.subinventory_code, ';
1381 --subinventory
1382 l_select_generic := l_select_generic || 'mmt.locator_id, ';
1383 --locator_id
1384 --locator
1385 l_select_generic :=
1386 l_select_generic
1387 || 'decode(milv.segment19, null, milv.concatenated_segments, null), ';
1388 l_select_generic := l_select_generic || '6, '; --status_id
1389 l_select_generic := l_select_generic || '6, '; --status_id_original
1390 l_select_generic :=
1391 l_select_generic || '''' || g_status_codes (6)
1392 || ''', '; --status
1393 l_select_generic := l_select_generic || 'mmt.transaction_type_id, ';
1394 --transaction_type_id
1395 l_select_generic := l_select_generic || 'mmt.transaction_action_id, ';
1396 --transaction_action_id
1397 l_select_generic :=
1398 l_select_generic || 'mmt.transaction_source_type_id, ';
1399 --transaction_source_type_id
1400
1401 IF g_txn_source_type_visible = 'T'
1402 THEN
1403 l_select_generic :=
1404 l_select_generic || 'mtst.transaction_source_type_name, ';
1405 --transaction_source_type
1406 END IF;
1407
1408 l_select_generic := l_select_generic || 'mmt.transaction_source_id, ';
1409 --transaction_source_id
1410 l_select_generic := l_select_generic || 'mmt.trx_source_line_id, ';
1411 --transaction_source_line_id
1412 l_select_generic :=
1413 l_select_generic || 'mmt.transfer_organization_id, ';
1414 --to_organization_id
1415
1416 IF g_to_organization_code_visible = 'T'
1417 THEN
1418 l_select_generic := l_select_generic || 'mp1.organization_code, ';
1419 --to_organization_id
1420 END IF;
1421
1422 l_select_generic := l_select_generic || 'mmt.transfer_subinventory, ';
1423 --to_subinventory
1424 l_select_generic := l_select_generic || 'mmt.transfer_locator_id, ';
1425 --to_locator_id
1426
1427 IF g_to_locator_visible = 'T'
1428 THEN
1429 --to locator
1430 l_select_generic :=
1431 l_select_generic
1432 || 'decode(milv1.segment19, null, milv1.concatenated_segments, null), ';
1433 END IF;
1434
1435 l_select_generic := l_select_generic || 'mmt.transaction_uom, ';
1436 --transaction_uom
1437 l_select_generic :=
1438 l_select_generic || 'abs(mmt.transaction_quantity), ';
1439 --transaction_quantity
1440 l_select_generic := l_select_generic || 'wdth.user_task_type, ';
1441 --user_task_type_id
1442
1443 IF g_user_task_type_visible = 'T'
1444 THEN
1445 l_select_generic := l_select_generic || 'bso.operation_code, ';
1446 --user_task_type
1447 END IF;
1448
1449 l_select_generic := l_select_generic || 'mmt.move_order_line_id, ';
1450 --move_order_line_id
1451 l_select_generic := l_select_generic || 'mmt.pick_slip_number, ';
1452 --pick_slip_number
1453 l_select_generic := l_select_generic || 'to_number(null), ';
1454 --cartonization_id
1455 IF g_cartonization_lpn_visible = 'T' THEN
1456 l_select_generic := l_select_generic || 'null, '; --cartonization_lpn
1457 END IF;
1458 l_select_generic := l_select_generic || 'to_number(null), ';
1459 --allocated_lpn_id
1460 IF g_allocated_lpn_visible = 'T' THEN
1461 l_select_generic := l_select_generic || 'null, ';
1462 --allocated_lpn
1463 END IF;
1464 l_select_generic := l_select_generic || 'to_number(null), ';
1465 --container_item_id
1466 IF g_container_item_visible = 'T' THEN
1467 l_select_generic := l_select_generic || 'null, '; /*container item */
1468 end if;
1469
1470 l_select_generic := l_select_generic || 'mmt.lpn_id, ';
1471 --from_lpn_id
1472
1473 IF g_from_lpn_visible = 'T'
1474 THEN
1475 l_select_generic :=
1476 l_select_generic || 'wlpn5.license_plate_number, ';
1477 --from_lpn
1478 END IF;
1479
1480 l_select_generic := l_select_generic || 'mmt.content_lpn_id, ';
1481 --content_lpn_id
1482
1483 IF g_content_lpn_visible = 'T'
1484 THEN
1485 l_select_generic :=
1486 l_select_generic || 'wlpn3.license_plate_number, ';
1487 --content_lpn
1488 END IF;
1489
1490 l_select_generic := l_select_generic || 'mmt.transfer_lpn_id, ';
1491 --to_lpn_id
1492
1493 IF g_to_lpn_visible = 'T'
1494 THEN
1495 l_select_generic :=
1496 l_select_generic || 'wlpn4.license_plate_number, ';
1497 --to_lpn
1498 END IF;
1499
1500 l_select_generic := l_select_generic || 'to_date(null), ';
1501 --mmt_last_update_date
1502 l_select_generic := l_select_generic || 'to_number(null), ';
1503 --mmt_last_updated_by
1504 l_select_generic := l_select_generic || 'wdth.priority, '; --priority
1505 l_select_generic := l_select_generic || 'wdth.priority, ';
1506 --priority_original
1507 l_select_generic := l_select_generic || 'wdth.task_type, ';
1508 --task_type_id
1509 --task_type
1510 l_select_generic :=
1511 l_select_generic
1512 || 'decode(wdth.task_type,'
1513 || '1, '''
1514 || g_task_types (1)
1515 || ''', 2, '''
1516 || g_task_types (2)
1517 || ''', 3, '''
1518 || g_task_types (3)
1519 || ''', 4, '''
1520 || g_task_types (4)
1521 || ''', 5, '''
1522 || g_task_types (5)
1523 || ''', 6, '''
1524 || g_task_types (6)
1525 || ''', 7, '''
1526 || g_task_types (7)
1527 || '''), ';
1528 l_select_generic := l_select_generic || 'to_date(null), ';
1529 --creation_time
1530 l_select_generic := l_select_generic || 'wdth.operation_plan_id, ';
1531 --operation_plan_id
1532
1533 IF g_operation_plan_visible = 'T'
1534 THEN
1535 l_select_generic :=
1536 l_select_generic || 'wop.operation_plan_name, ';
1537 --operation_plan
1538 END IF;
1539
1540 IF g_operation_sequence_visible = 'T' THEN
1541 IF wms_plan_tasks_pvt.g_query_planned_tasks = TRUE THEN
1542 l_select_generic := l_select_generic || 'to_number(null), ';--operation_sequence
1543 ELSE
1544 l_select_generic := l_select_generic || 'to_number(null), ';--operation_sequence
1545 END IF;
1546 END IF;
1547
1548 -- IF g_op_plan_instance_id_visible = 'T' THEN
1549 l_select_generic := l_select_generic || 'wdth.op_plan_instance_id, ';
1550 --op_plan_instance_id
1551
1552 --END IF;
1553 l_select_generic := l_select_generic || 'wdth.task_id, '; --task_id
1554 l_select_generic := l_select_generic || 'wdth.person_id, ';
1555 --person_id
1556 l_select_generic := l_select_generic || 'wdth.person_id, ';
1557 --person_id_original
1558
1559 IF g_person_visible = 'T'
1560 THEN
1561 l_select_generic := l_select_generic || 'pap.full_name, ';
1562 --person_id
1563 END IF;
1564
1565 l_select_generic := l_select_generic || 'wdth.effective_start_date, ';
1566 --effective_start_date
1567 l_select_generic := l_select_generic || 'wdth.effective_end_date, ';
1568 --effective_end_date
1569 l_select_generic := l_select_generic || 'wdth.person_resource_id, ';
1570 --person_resource_id
1571
1572 IF g_person_resource_visible = 'T'
1573 THEN
1574 l_select_generic := l_select_generic || 'br1.resource_code, ';
1575 --person_resource_code
1576 END IF;
1577
1578 l_select_generic := l_select_generic || 'wdth.machine_resource_id, ';
1579 --machine_resource_id
1580
1581 IF g_machine_resource_visible = 'T'
1582 THEN
1583 l_select_generic := l_select_generic || 'br2.resource_code, ';
1584 --machine_resource_code
1585 END IF;
1586
1587 l_select_generic := l_select_generic || 'wdth.equipment_instance, ';
1588 --equipment_instance
1589 l_select_generic := l_select_generic || 'wdth.dispatched_time, ';
1590 --dispatched_time
1591 l_select_generic := l_select_generic || 'wdth.loaded_time, ';
1592 --loaded_time
1593 l_select_generic := l_select_generic || 'wdth.drop_off_time, ';
1594 --drop_off_time
1595 l_select_generic := l_select_generic || 'to_date(null), ';
1596 --wdt_last_update_date
1597 l_select_generic := l_select_generic || 'to_number(null), ';
1598 --wdt_last_updated_by
1599 l_select_generic := l_select_generic || '''N'', '; --is_modified
1600
1601 -- bug #5163661
1602 IF NOT (wms_plan_tasks_pvt.g_include_inbound OR wms_plan_tasks_pvt.g_include_crossdock) THEN
1603 -- Bug #4141928
1604 l_select_generic := l_select_generic || 'mmt.secondary_uom_code, ';
1605 --sec_transaction_uom
1606 l_select_generic :=
1607 l_select_generic || 'abs(mmt.secondary_transaction_quantity), ';
1608 --sec_transaction_quantity
1609
1610 l_select_generic := l_select_generic || 'mmt.transaction_set_id ';
1611 -- bug 4510849
1612 ELSE
1613 -- Bug #4141928
1614 l_select_generic := l_select_generic || 'mmt.secondary_uom_code, ';
1615 --sec_transaction_uom
1616 l_select_generic :=
1617 l_select_generic || 'abs(mmt.secondary_transaction_quantity) ';
1618 --sec_transaction_quantity
1619 END IF;
1620
1621 RETURN l_select_generic;
1622 ELSE --p_is_completed and p_populate_merged_tasks
1623 --Patchset J Bulk Picking Enhancement
1624 --We are now showing completed parent tasks since completed parent
1625 --tasks will now be stored in wdth. However, since it still will
1626 --not be in mmt, we can only query from wdth when querying for
1627 --completed parent tasks.
1628
1629 -- Build the generic select section of the query
1630 l_select_generic := 'SELECT ';
1631 l_select_generic := l_select_generic || 'null, '; -- expansion_code
1632 l_select_generic :=
1633 l_select_generic
1634 || 'decode(wdth.is_parent,'
1635 || '''N'', decode(wdth.operation_plan_id,null, decode(wdth.parent_transaction_id,null,'''
1636 || g_plan_task_types (1)
1637 || ''','''
1638 || g_plan_task_types (5)
1639 || '''),'''
1640 || g_plan_task_types (2)
1641 || '''), '
1642 || 'decode(wdth.transaction_action_id,28,'''
1643 || g_plan_task_types (4)
1644 || ''','
1645 || 'decode(wdth.transaction_source_type_id,'
1646 || '5,decode(wdth.transaction_type_id,35,'''
1647 || g_plan_task_types (4)
1648 || ''','''
1649 || g_plan_task_types (3)
1650 || '''),'
1651 || '13, decode(wdth.transaction_type_id,51,'''
1652 || g_plan_task_types (4)
1653 || ''','''
1654 || g_plan_task_types (3)
1655 || '''),'''
1656 || g_plan_task_types (3)
1657 || '''))),'; --plan_task
1658 l_select_generic := l_select_generic || 'wdth.transaction_id, ';
1659 --transaction_temp_id
1660 l_select_generic := l_select_generic || 'wdth.parent_transaction_id,';
1661 --parent_line_id
1662 l_select_generic := l_select_generic || 'wdth.inventory_item_id, ';
1663 --inventory_item_id
1664 l_select_generic :=
1665 l_select_generic || 'msiv.concatenated_segments, ';
1666 --item
1667 l_select_generic := l_select_generic || 'msiv.description, ';
1668 --item description
1669 l_select_generic := l_select_generic || 'msiv.unit_weight, ';
1670 --unit_weight
1671 l_select_generic := l_select_generic || 'msiv.weight_uom_code, ';
1672 --weight_uom_code
1673 l_select_generic := l_select_generic || 'msiv.unit_volume, ';
1674 --unit_volume
1675 l_select_generic := l_select_generic || 'msiv.volume_uom_code, ';
1676 --volume_uom_code
1677 l_select_generic := l_select_generic || 'wdth.organization_id, ';
1678 --organization_id
1679 l_select_generic := l_select_generic || 'wdth.revision, '; --revision
1680 l_select_generic :=
1681 l_select_generic || 'wdth.source_subinventory_code, ';
1682 --subinventory
1683 l_select_generic := l_select_generic || 'wdth.source_locator_id, ';
1684 --locator_id
1685 --locator
1686 l_select_generic :=
1687 l_select_generic
1688 || 'decode(milv.segment19, null, milv.concatenated_segments, null), ';
1689 l_select_generic := l_select_generic || '6, '; --status_id
1690 l_select_generic := l_select_generic || '6, '; --status_id_original
1691 l_select_generic :=
1692 l_select_generic || '''' || g_status_codes (6)
1693 || ''', '; --status
1694 l_select_generic := l_select_generic || 'wdth.transaction_type_id, ';
1695 --transaction_type_id
1696 l_select_generic :=
1697 l_select_generic || 'wdth.transaction_action_id, ';
1698 --transaction_action_id
1699 l_select_generic :=
1700 l_select_generic || 'wdth.transaction_source_type_id, ';
1701 --transaction_source_type_id
1702
1703 IF g_txn_source_type_visible = 'T'
1704 THEN
1705 l_select_generic :=
1706 l_select_generic || 'mtst.transaction_source_type_name, ';
1707 --transaction_source_type
1708 END IF;
1709
1710 l_select_generic := l_select_generic || 'to_number(null), ';
1711 --transaction_source_id
1712 l_select_generic := l_select_generic || 'to_number(null), ';
1713 --transaction_source_line_id
1714 l_select_generic :=
1715 l_select_generic || 'wdth.transfer_organization_id, ';
1716 --to_organization_id
1717
1718 IF g_to_organization_code_visible = 'T'
1719 THEN
1720 l_select_generic := l_select_generic || 'mp1.organization_code, ';
1721 --to_organization_id
1722 END IF;
1723
1724 l_select_generic := l_select_generic || 'null, '; --to_subinventory
1725 l_select_generic := l_select_generic || 'to_number(null), ';
1726 --to_locator_id
1727
1728 IF g_to_locator_visible = 'T'
1729 THEN
1730 --to locator
1731 l_select_generic := l_select_generic || 'null, ';
1732 END IF;
1733
1734 l_select_generic := l_select_generic || 'wdth.transaction_uom_code, ';
1735 --transaction_uom
1736 l_select_generic := l_select_generic || 'to_number(null), ';
1737 --transaction_quantity
1738 l_select_generic := l_select_generic || 'wdth.user_task_type, ';
1739 --user_task_type_id
1740
1741 IF g_user_task_type_visible = 'T'
1742 THEN
1743 l_select_generic := l_select_generic || 'bso.operation_code, ';
1744 --user_task_type
1745 END IF;
1746
1747 l_select_generic := l_select_generic || 'to_number(null), ';
1748 --move_order_line_id
1749 l_select_generic := l_select_generic || 'to_number(null), ';
1750 --pick_slip_number
1751 l_select_generic := l_select_generic || 'to_number(null), ';
1752 --cartonization_id
1753 IF g_cartonization_lpn_visible = 'T' THEN
1754 l_select_generic := l_select_generic || 'null, '; --cartonization_lpn
1755 END IF;
1756 l_select_generic := l_select_generic || 'to_number(null), ';
1757 --allocated_lpn_id
1758 IF g_allocated_lpn_visible = 'T' THEN
1759 l_select_generic := l_select_generic || 'null, ';
1760 END IF;
1761
1762 l_select_generic := l_select_generic || 'to_number(null), ';
1763 --container_item_id
1764 IF g_container_item_visible = 'T' THEN
1765 l_select_generic := l_select_generic || 'null, ';
1766 END IF;
1767
1768
1769 l_select_generic := l_select_generic || 'wdth.lpn_id, ';
1770 --from_lpn_id
1771
1772 IF g_from_lpn_visible = 'T'
1773 THEN
1774 l_select_generic :=
1775 l_select_generic || 'wlpn5.license_plate_number, ';
1776 --from_lpn
1777 END IF;
1778
1779 l_select_generic := l_select_generic || 'wdth.content_lpn_id, ';
1780 --content_lpn_id
1781
1782 IF g_content_lpn_visible = 'T'
1783 THEN
1784 l_select_generic :=
1785 l_select_generic || 'wlpn3.license_plate_number, ';
1786 --content_lpn
1787 END IF;
1788
1789 l_select_generic := l_select_generic || 'wdth.transfer_lpn_id, ';
1790 --to_lpn_id
1791
1792 IF g_to_lpn_visible = 'T'
1793 THEN
1794 l_select_generic :=
1795 l_select_generic || 'wlpn4.license_plate_number, ';
1796 --to_lpn
1797 END IF;
1798
1799 l_select_generic := l_select_generic || 'to_date(null), ';
1800 --mmt_last_update_date
1801 l_select_generic := l_select_generic || 'to_number(null), ';
1802 --mmt_last_updated_by
1803 l_select_generic := l_select_generic || 'wdth.priority, '; --priority
1804 l_select_generic := l_select_generic || 'wdth.priority, ';
1805 --priority_original
1806 l_select_generic := l_select_generic || 'wdth.task_type, ';
1807 --task_type_id
1808 --task_type
1809 l_select_generic :=
1810 l_select_generic
1811 || 'decode(wdth.task_type,'
1812 || '1, '''
1813 || g_task_types (1)
1814 || ''', 2, '''
1815 || g_task_types (2)
1816 || ''', 3, '''
1817 || g_task_types (3)
1818 || ''', 4, '''
1819 || g_task_types (4)
1820 || ''', 5, '''
1821 || g_task_types (5)
1822 || ''', 6, '''
1823 || g_task_types (6)
1824 || ''', 7, '''
1825 || g_task_types (7)
1826 || ''', 8, '''
1827 || g_task_types (8)
1828 || '''), ';
1829 l_select_generic := l_select_generic || 'to_date(null), ';
1830 --creation_time
1831 l_select_generic := l_select_generic || 'wdth.operation_plan_id, ';
1832 --operation_plan_id
1833
1834 IF g_operation_plan_visible = 'T'
1835 THEN
1836 l_select_generic :=
1837 l_select_generic || 'wop.operation_plan_name, ';
1838 --operation_plan
1839 END IF;
1840
1841 IF g_operation_sequence_visible = 'T' THEN
1842 l_select_generic := l_select_generic || 'to_number(null), '; --operation_sequence
1843 END IF;
1844
1845 -- IF g_op_plan_instance_id_visible = 'T' THEN
1846 l_select_generic := l_select_generic || 'wdth.op_plan_instance_id, ';
1847 --op_plan_instance_id
1848
1849 --END IF;
1850 l_select_generic := l_select_generic || 'wdth.task_id, '; --task_id
1851 l_select_generic := l_select_generic || 'wdth.person_id, ';
1852 --person_id
1853 l_select_generic := l_select_generic || 'wdth.person_id, ';
1854 --person_id_original
1855
1856 IF g_person_visible = 'T'
1857 THEN
1858 l_select_generic := l_select_generic || 'pap.full_name, ';
1859 --person_id
1860 END IF;
1861
1862 l_select_generic := l_select_generic || 'wdth.effective_start_date, ';
1863 --effective_start_date
1864 l_select_generic := l_select_generic || 'wdth.effective_end_date, ';
1865 --effective_end_date
1866 l_select_generic := l_select_generic || 'wdth.person_resource_id, ';
1867 --person_resource_id
1868
1869 IF g_person_resource_visible = 'T'
1870 THEN
1871 l_select_generic := l_select_generic || 'br1.resource_code, ';
1872 --person_resource_code
1873 END IF;
1874
1875 l_select_generic := l_select_generic || 'wdth.machine_resource_id, ';
1876 --machine_resource_id
1877
1878 IF g_machine_resource_visible = 'T'
1879 THEN
1880 l_select_generic := l_select_generic || 'br2.resource_code, ';
1881 --machine_resource_code
1882 END IF;
1883
1884 l_select_generic := l_select_generic || 'wdth.equipment_instance, ';
1885 --equipment_instance
1886 l_select_generic := l_select_generic || 'wdth.dispatched_time, ';
1887 --dispatched_time
1888 l_select_generic := l_select_generic || 'wdth.loaded_time, ';
1889 --loaded_time
1890 l_select_generic := l_select_generic || 'wdth.drop_off_time, ';
1891 --drop_off_time
1892 l_select_generic := l_select_generic || 'to_date(null), ';
1893 --wdt_last_update_date
1894 l_select_generic := l_select_generic || 'to_number(null), ';
1895 --wdt_last_updated_by
1896 l_select_generic := l_select_generic || '''N'', '; --is_modified
1897
1898 -- bug #5163661
1899 IF NOT (wms_plan_tasks_pvt.g_include_inbound OR wms_plan_tasks_pvt.g_include_crossdock) THEN
1900 -- Bug #4141928
1901 l_select_generic := l_select_generic || 'wdth.secondary_transaction_uom_code, ';
1902 --sec_transaction_uom
1903 l_select_generic := l_select_generic || 'to_number(null), ';
1904 --sec_transaction_quantity
1905 l_select_generic := l_select_generic || 'mmt.transaction_set_id ';
1906 -- bug 4510849
1907 ELSE
1908 -- Bug #4141928
1909 l_select_generic := l_select_generic || 'wdth.secondary_transaction_uom_code, ';
1910 --sec_transaction_uom
1911 l_select_generic := l_select_generic || 'to_number(null) ';
1912 --sec_transaction_quantity
1913 END IF;
1914 RETURN l_select_generic;
1915 END IF;
1916 END get_generic_select;
1917
1918 FUNCTION get_generic_from (
1919 p_is_queued BOOLEAN DEFAULT FALSE,
1920 p_is_dispatched BOOLEAN DEFAULT FALSE,
1921 p_is_active BOOLEAN DEFAULT FALSE,
1922 p_is_loaded BOOLEAN DEFAULT FALSE,
1923 p_is_completed BOOLEAN DEFAULT FALSE,
1924 p_item_category_id NUMBER DEFAULT NULL,
1925 p_category_set_id NUMBER DEFAULT NULL,
1926 p_populate_merged_tasks BOOLEAN DEFAULT FALSE
1927 )
1928 RETURN VARCHAR2
1929 IS
1930 l_from_generic VARCHAR2 (2000);
1931 BEGIN
1932 -- Build the generic from section of the query
1933 l_from_generic := ' FROM ';
1934
1935 IF NOT p_is_completed
1936 THEN
1937 l_from_generic :=
1938 l_from_generic || 'mtl_material_transactions_temp mmtt ';
1939
1940 --IF g_op_plan_instance_id_visible = 'T' AND
1941 IF wms_plan_tasks_pvt.g_query_planned_tasks = TRUE
1942 THEN
1943 l_from_generic :=
1944 l_from_generic || ', wms_op_operation_instances wooi';
1945 END IF;
1946
1947 IF p_is_queued OR p_is_dispatched OR p_is_loaded OR p_is_active
1948 THEN
1949 l_from_generic := l_from_generic || ', wms_dispatched_tasks wdt ';
1950 END IF;
1951 ELSE -- if p_is_completed then
1952 --Patchset J Bulk Picking Enhancement
1953 --Only include mmt if not querying for completed parent tasks
1954 --because completed parent tasks are not in mmt
1955 IF NOT p_populate_merged_tasks
1956 THEN
1957 l_from_generic :=
1958 l_from_generic || 'mtl_material_transactions mmt, ';
1959 END IF;
1960
1961 l_from_generic :=
1962 l_from_generic || 'wms_dispatched_tasks_history wdth';
1963 /*IF g_operation_sequence_visible = 'T' AND wms_plan_tasks_pvt.g_query_planned_tasks = TRUE THEN
1964 l_from_generic :=
1965 l_from_generic || 'wms_op_opertn_instances_hist wooih';
1966 END IF; */
1967
1968
1969 END IF;
1970
1971 IF p_populate_merged_tasks
1972 THEN
1973 l_from_generic :=
1974 l_from_generic
1975 || ', (select distinct parent_line_id from wms_waveplan_tasks_temp where task_type_id <> 3) wwtt';
1976 END IF;
1977
1978 l_from_generic := l_from_generic || ', mtl_system_items_kfv msiv ';
1979 l_from_generic := l_from_generic || ', mtl_item_locations_kfv milv ';
1980
1981 IF p_item_category_id IS NOT NULL OR p_category_set_id IS NOT NULL
1982 THEN
1983 l_from_generic := l_from_generic || ', mtl_item_categories mic ';
1984 END IF;
1985
1986 IF g_allocated_lpn_visible = 'T' AND NOT p_is_completed
1987 THEN
1988 l_from_generic :=
1989 l_from_generic || ', wms_license_plate_numbers wlpn1 ';
1990 END IF;
1991
1992 IF g_cartonization_lpn_visible = 'T' AND NOT p_is_completed
1993 THEN
1994 l_from_generic :=
1995 l_from_generic || ', wms_license_plate_numbers wlpn2 ';
1996 END IF;
1997
1998 IF g_container_item_visible = 'T' AND NOT p_is_completed
1999 THEN
2000 l_from_generic := l_from_generic || ', mtl_system_items_kfv msiv1 ';
2001 END IF;
2002
2003 IF g_from_lpn_visible = 'T'
2004 THEN
2005 l_from_generic :=
2006 l_from_generic || ', wms_license_plate_numbers wlpn5 ';
2007 END IF;
2008
2009 IF g_content_lpn_visible = 'T'
2010 THEN
2011 l_from_generic :=
2012 l_from_generic || ', wms_license_plate_numbers wlpn3 ';
2013 END IF;
2014
2015 IF g_to_lpn_visible = 'T'
2016 THEN
2017 l_from_generic :=
2018 l_from_generic || ', wms_license_plate_numbers wlpn4 ';
2019 END IF;
2020
2021 IF g_user_task_type_visible = 'T'
2022 THEN
2023 l_from_generic := l_from_generic || ', bom_standard_operations bso ';
2024 END IF;
2025
2026 IF g_to_organization_code_visible = 'T'
2027 THEN
2028 l_from_generic := l_from_generic || ', mtl_parameters mp1 ';
2029 END IF;
2030
2031 IF g_to_locator_visible = 'T'
2032 AND NOT (p_populate_merged_tasks AND p_is_completed)
2033 THEN
2034 --Change
2035 --AND NOT p_populate_merged_tasks THEN
2036 --End of change
2037 l_from_generic :=
2038 l_from_generic || ', mtl_item_locations_kfv milv1 ';
2039 END IF;
2040
2041 IF g_txn_source_type_visible = 'T'
2042 THEN
2043 l_from_generic := l_from_generic || ', mtl_txn_source_types mtst ';
2044 END IF;
2045
2046 IF g_operation_plan_visible = 'T'
2047 THEN
2048 l_from_generic := l_from_generic || ', wms_op_plans_vl wop ';
2049 END IF;
2050
2051 IF ( p_is_queued
2052 OR p_is_dispatched
2053 OR p_is_loaded
2054 OR p_is_active
2055 OR p_is_completed
2056 )
2057 THEN
2058 IF g_person_resource_visible = 'T'
2059 THEN
2060 l_from_generic := l_from_generic || ', bom_resources br1 ';
2061 END IF;
2062
2063 IF g_machine_resource_visible = 'T'
2064 THEN
2065 l_from_generic := l_from_generic || ', bom_resources br2 ';
2066 END IF;
2067
2068 IF g_person_visible = 'T'
2069 THEN
2070 l_from_generic := l_from_generic || ', per_all_people_f pap ';
2071 END IF;
2072 END IF;
2073
2074 RETURN l_from_generic;
2075 END get_generic_from;
2076
2077 FUNCTION get_generic_where (
2078 p_add BOOLEAN DEFAULT FALSE,
2079 p_organization_id NUMBER DEFAULT NULL,
2080 p_subinventory_code VARCHAR2 DEFAULT NULL,
2081 p_locator_id NUMBER DEFAULT NULL,
2082 p_to_subinventory_code VARCHAR2 DEFAULT NULL,
2083 p_to_locator_id NUMBER DEFAULT NULL,
2084 p_inventory_item_id NUMBER DEFAULT NULL,
2085 p_category_set_id NUMBER DEFAULT NULL,
2086 p_item_category_id NUMBER DEFAULT NULL,
2087 p_person_id NUMBER DEFAULT NULL,
2088 p_person_resource_id NUMBER DEFAULT NULL,
2089 p_equipment_type_id NUMBER DEFAULT NULL,
2090 p_machine_resource_id NUMBER DEFAULT NULL,
2091 p_machine_instance VARCHAR2 DEFAULT NULL,
2092 p_user_task_type_id NUMBER DEFAULT NULL,
2093 p_from_task_quantity NUMBER DEFAULT NULL,
2094 p_to_task_quantity NUMBER DEFAULT NULL,
2095 p_from_task_priority NUMBER DEFAULT NULL,
2096 p_to_task_priority NUMBER DEFAULT NULL,
2097 p_from_creation_date DATE DEFAULT NULL,
2098 p_to_creation_date DATE DEFAULT NULL,
2099 p_include_cycle_count BOOLEAN DEFAULT FALSE,
2100 p_is_unreleased BOOLEAN DEFAULT FALSE,
2101 p_is_pending BOOLEAN DEFAULT FALSE,
2102 p_is_queued BOOLEAN DEFAULT FALSE,
2103 p_is_dispatched BOOLEAN DEFAULT FALSE,
2104 p_is_active BOOLEAN DEFAULT FALSE,
2105 p_is_loaded BOOLEAN DEFAULT FALSE,
2106 p_is_completed BOOLEAN DEFAULT FALSE,
2107 p_populate_merged_tasks BOOLEAN DEFAULT FALSE,
2108 p_outbound_tasks_cycle BOOLEAN DEFAULT FALSE, -- bug #4661615
2109 -- R12 : Additional Query Criteria
2110 p_item_type_code VARCHAR2 DEFAULT NULL,
2111 p_age_uom_code VARCHAR2 DEFAULT NULL,
2112 p_age_min NUMBER DEFAULT NULL,
2113 p_age_max NUMBER DEFAULT NULL
2114 -- R12 : Additional Query Criteria
2115 )
2116 RETURN VARCHAR2
2117 IS
2118 l_where_generic VARCHAR2 (4000);
2119 l_debug NUMBER := NVL (fnd_profile.VALUE ('INV_DEBUG_TRACE'), 0);
2120 --R12: Additional Query criteria
2121 --Age UOM conversion factor
2122 n VARCHAR2 (10);
2123 BEGIN
2124 IF l_debug = 1 then
2125 IF p_outbound_tasks_cycle THEN
2126 debug('p_outbound_tasks_cycle : true');
2127 ELSE
2128 debug('p_outbound_tasks_cycle : false');
2129 END IF;
2130 END IF;
2131
2132 IF NOT p_is_completed
2133 THEN
2134 -- Build the generic where section of the query
2135 IF p_add
2136 THEN
2137 l_where_generic :=
2138 'WHERE NOT exists (SELECT 1 FROM wms_waveplan_tasks_temp ';
2139 l_where_generic :=
2140 l_where_generic
2141 || 'WHERE transaction_temp_id = mmtt.transaction_temp_id ';
2142 l_where_generic := l_where_generic || 'AND task_type_id <> 3) ';
2143 ELSE
2144 l_where_generic := 'WHERE 1=1 ';
2145 END IF;
2146
2147 --IF g_op_plan_instance_id_visible = 'T' AND
2148 IF wms_plan_tasks_pvt.g_query_planned_tasks
2149 THEN
2150 l_where_generic :=
2151 l_where_generic
2152 || ' AND mmtt.transaction_temp_id = wooi.source_task_id (+) ';
2153 END IF;
2154
2155 IF (p_is_unreleased OR p_is_pending)
2156 AND NOT (p_is_queued OR p_is_dispatched OR p_is_loaded
2157 OR p_is_active
2158 )
2159 THEN
2160
2161 -- bug #4459382
2162 -- retrive no pending/unreleased tasks if employee criterion is given
2163 IF p_person_id IS NOT NULL OR
2164 p_person_resource_id IS NOT NULL OR
2165 p_equipment_type_id IS NOT NULL OR
2166 p_machine_resource_id IS NOT NULL OR
2167 p_machine_instance IS NOT NULL
2168 THEN
2169 l_where_generic := l_where_generic || 'AND 1 = 2 ';
2170 END IF;
2171
2172 -- Query records present only in MMTT
2173 IF p_is_unreleased AND NOT p_is_pending
2174 THEN
2175 l_where_generic :=
2176 l_where_generic || 'AND nvl(mmtt.wms_task_status, 1) = 8 ';
2177 ELSIF NOT p_is_unreleased AND p_is_pending
2178 THEN
2179 l_where_generic :=
2180 l_where_generic || 'AND nvl(mmtt.wms_task_status, 1) = 1 ';
2181 END IF;
2182
2183 IF p_is_pending
2184 THEN
2185 l_where_generic :=
2186 l_where_generic
2187 || 'AND NOT EXISTS (SELECT 1 FROM wms_dispatched_tasks ';
2188 l_where_generic :=
2189 l_where_generic
2190 || ' WHERE transaction_temp_id = mmtt.transaction_temp_id) ';
2191 END IF;
2192 ELSIF (p_is_unreleased OR p_is_pending)
2193 AND (p_is_queued OR p_is_dispatched OR p_is_loaded
2194 OR p_is_active
2195 )
2196 THEN
2197 -- Query records present only in MMTT as well as those in both MMTT and WDT
2198 l_where_generic :=
2199 l_where_generic
2200 || 'AND mmtt.transaction_temp_id = wdt.transaction_temp_id(+) ';
2201 l_where_generic :=
2202 l_where_generic
2203 || 'AND decode(wdt.status, null, nvl(mmtt.wms_task_status, 1), wdt.status) in ( ';
2204
2205 IF p_is_unreleased
2206 THEN
2207 l_where_generic := l_where_generic || '8';
2208 END IF;
2209
2210 IF p_is_pending
2211 THEN
2212 IF p_is_unreleased
2213 THEN
2214 l_where_generic := l_where_generic || ', 1';
2215 ELSE
2216 l_where_generic := l_where_generic || '1';
2217 END IF;
2218 END IF;
2219
2220 IF p_is_queued
2221 THEN
2222 IF p_is_unreleased OR p_is_pending
2223 THEN
2224 l_where_generic := l_where_generic || ', 2';
2225 ELSE
2226 l_where_generic := l_where_generic || '2';
2227 END IF;
2228 END IF;
2229
2230 IF p_is_dispatched
2231 THEN
2232 IF p_is_unreleased OR p_is_pending OR p_is_queued
2233 THEN
2234 l_where_generic := l_where_generic || ', 3';
2235 ELSE
2236 l_where_generic := l_where_generic || '3';
2237 END IF;
2238 END IF;
2239
2240 IF p_is_loaded
2241 THEN
2242 IF p_is_unreleased
2243 OR p_is_pending
2244 OR p_is_queued
2245 OR p_is_dispatched
2246 THEN
2247 l_where_generic := l_where_generic || ', 4';
2248 ELSE
2249 l_where_generic := l_where_generic || '4';
2250 END IF;
2251 END IF;
2252
2253 IF p_is_active
2254 THEN
2255 IF p_is_unreleased
2256 OR p_is_pending
2257 OR p_is_queued
2258 OR p_is_dispatched
2259 OR p_is_loaded
2260 THEN
2261 l_where_generic := l_where_generic || ', 9';
2262 ELSE
2263 l_where_generic := l_where_generic || '9';
2264 END IF;
2265 END IF;
2266
2267 l_where_generic := l_where_generic || ') ';
2268
2269 IF g_person_resource_visible = 'T'
2270 THEN
2271 l_where_generic :=
2272 l_where_generic
2273 || 'AND wdt.person_resource_id = br1.resource_id(+) ';
2274 END IF;
2275
2276 IF g_machine_resource_visible = 'T'
2277 THEN
2278 l_where_generic :=
2279 l_where_generic
2280 || 'AND wdt.machine_resource_id = br2.resource_id(+) ';
2281 END IF;
2282
2283 IF g_person_visible = 'T'
2284 THEN
2285 l_where_generic :=
2286 l_where_generic || 'AND wdt.person_id = pap.person_id(+) ';
2287 l_where_generic :=
2288 l_where_generic
2289 || 'AND wdt.effective_start_date >= pap.effective_start_date(+) ';
2290 l_where_generic :=
2291 l_where_generic
2292 || 'AND wdt.effective_end_date <= pap.effective_end_date(+) ';
2293 END IF;
2294
2295 -- Bug #4459382
2296 -- Add the employee criteria to the where clause
2297
2298 IF p_person_id IS NOT NULL
2299 THEN
2300 l_where_generic :=
2301 l_where_generic || 'AND wdt.person_id(+) = :person_id '; /* Bug 5446146 */
2302 END IF;
2303
2304 IF p_person_resource_id IS NOT NULL
2305 THEN
2306 l_where_generic :=
2307 l_where_generic
2308 || 'AND wdt.person_resource_id(+) = :person_resource_id ';
2309 END IF;
2310
2311 IF p_equipment_type_id IS NOT NULL
2312 THEN
2313 l_where_generic :=
2314 l_where_generic
2315 || 'AND wdt.equipment_id(+) = :equipment_type_id ';
2316 END IF;
2317
2318 IF p_machine_resource_id IS NOT NULL
2319 THEN
2320 l_where_generic :=
2321 l_where_generic
2322 || 'AND wdt.machine_resource_id(+) = :machine_resource_id ';
2323 END IF;
2324
2325 IF p_machine_instance IS NOT NULL
2326 THEN
2327 l_where_generic :=
2328 l_where_generic
2329 || 'AND wdt.equipment_instance(+) = :machine_instance ';
2330 END IF;
2331
2332 ELSIF NOT (p_is_unreleased OR p_is_pending)
2333 AND (p_is_queued OR p_is_dispatched OR p_is_loaded
2334 OR p_is_active
2335 )
2336 THEN
2337 -- Query records present both in MMTT and WDT
2338 l_where_generic :=
2339 l_where_generic
2340 || 'AND mmtt.transaction_temp_id = wdt.transaction_temp_id ';
2341 l_where_generic := l_where_generic || 'AND wdt.status in ( ';
2342
2343 IF p_is_queued
2344 THEN
2345 l_where_generic := l_where_generic || '2';
2346 END IF;
2347
2348 IF p_is_dispatched
2349 THEN
2350 IF p_is_queued
2351 THEN
2352 l_where_generic := l_where_generic || ', 3';
2353 ELSE
2354 l_where_generic := l_where_generic || '3';
2355 END IF;
2356 END IF;
2357
2358 IF p_is_loaded
2359 THEN
2360 IF p_is_queued OR p_is_dispatched
2361 THEN
2362 l_where_generic := l_where_generic || ', 4';
2363 ELSE
2364 l_where_generic := l_where_generic || '4';
2365 END IF;
2366 END IF;
2367
2368 IF p_is_active
2369 THEN
2370 IF p_is_queued OR p_is_dispatched OR p_is_loaded
2371 THEN
2372 l_where_generic := l_where_generic || ', 9';
2373 ELSE
2374 l_where_generic := l_where_generic || '9';
2375 END IF;
2376 END IF;
2377
2378 l_where_generic := l_where_generic || ') ';
2379
2380 IF g_person_resource_visible = 'T'
2381 THEN
2382 l_where_generic :=
2383 l_where_generic
2384 || 'AND wdt.person_resource_id = br1.resource_id(+) ';
2385 END IF;
2386
2387 IF g_machine_resource_visible = 'T'
2388 THEN
2389 l_where_generic :=
2390 l_where_generic
2391 || 'AND wdt.machine_resource_id = br2.resource_id(+) ';
2392 END IF;
2393
2394 IF g_person_visible = 'T'
2395 THEN
2396 l_where_generic :=
2397 l_where_generic || 'AND wdt.person_id = pap.person_id(+) ';
2398 l_where_generic :=
2399 l_where_generic
2400 || 'AND wdt.effective_start_date >= pap.effective_start_date(+) ';
2401 l_where_generic :=
2402 l_where_generic
2403 || 'AND wdt.effective_end_date <= pap.effective_end_date(+) ';
2404 END IF;
2405
2406 -- Bug #4459382
2407 -- Add the employee criteria to the where clause
2408
2409 IF p_person_id IS NOT NULL
2410 THEN
2411 l_where_generic :=
2412 l_where_generic || 'AND wdt.person_id(+) = :person_id ';
2413 END IF;
2414
2415 IF p_person_resource_id IS NOT NULL
2416 THEN
2417 l_where_generic :=
2418 l_where_generic
2419 || 'AND wdt.person_resource_id(+) = :person_resource_id ';
2420 END IF;
2421
2422 IF p_equipment_type_id IS NOT NULL
2423 THEN
2424 l_where_generic :=
2425 l_where_generic
2426 || 'AND wdt.equipment_id(+) = :equipment_type_id ';
2427 END IF;
2428
2429 IF p_machine_resource_id IS NOT NULL
2430 THEN
2431 l_where_generic :=
2432 l_where_generic
2433 || 'AND wdt.machine_resource_id(+) = :machine_resource_id ';
2434 END IF;
2435
2436 IF p_machine_instance IS NOT NULL
2437 THEN
2438 l_where_generic :=
2439 l_where_generic
2440 || 'AND wdt.equipment_instance(+) = :machine_instance ';
2441 END IF;
2442
2443 END IF;
2444
2445 IF p_populate_merged_tasks
2446 THEN
2447 l_where_generic :=
2448 l_where_generic
2449 || 'AND mmtt.transaction_temp_id = wwtt.parent_line_id ';
2450 END IF;
2451
2452 l_where_generic :=
2453 l_where_generic
2454 || 'AND mmtt.organization_id = msiv.organization_id ';
2455 l_where_generic :=
2456 l_where_generic
2457 || 'AND mmtt.inventory_item_id = msiv.inventory_item_id ';
2458 l_where_generic :=
2459 l_where_generic
2460 || 'AND mmtt.organization_id = milv.organization_id(+) ';
2461 l_where_generic :=
2462 l_where_generic
2463 || 'AND mmtt.locator_id = milv.inventory_location_id(+) ';
2464
2465 IF g_to_organization_code_visible = 'T'
2466 THEN
2467 l_where_generic :=
2468 l_where_generic
2469 || 'AND mmtt.transfer_organization = mp1.organization_id(+) ';
2470 END IF;
2471
2472 IF g_to_locator_visible = 'T'
2473 THEN
2474 --Bug 2838178
2475 l_where_generic :=
2476 l_where_generic
2477 || 'AND milv1.organization_id(+) = nvl(mmtt.transfer_organization,mmtt.organization_id) ';
2478 l_where_generic :=
2479 l_where_generic
2480 || 'AND mmtt.transfer_subinventory = milv1.subinventory_code(+) ';
2481 l_where_generic :=
2482 l_where_generic
2483 || 'AND mmtt.transfer_to_location = milv1.inventory_location_id(+) ';
2484 END IF;
2485
2486 IF g_txn_source_type_visible = 'T'
2487 THEN
2488 l_where_generic :=
2489 l_where_generic
2490 || 'AND mmtt.transaction_source_type_id = mtst.transaction_source_type_id ';
2491 END IF;
2492
2493 IF g_allocated_lpn_visible = 'T'
2494 THEN
2495 l_where_generic :=
2496 l_where_generic
2497 || 'AND mmtt.allocated_lpn_id = wlpn1.lpn_id(+) ';
2498 END IF;
2499
2500 IF g_cartonization_lpn_visible = 'T'
2501 THEN
2502 l_where_generic :=
2503 l_where_generic
2504 || 'AND mmtt.cartonization_id = wlpn2.lpn_id(+) ';
2505 END IF;
2506
2507 IF g_container_item_visible = 'T'
2508 THEN
2509 l_where_generic :=
2510 l_where_generic
2511 || 'AND mmtt.container_item_id = msiv1.inventory_item_id(+) ';
2512 l_where_generic :=
2513 l_where_generic
2514 || 'AND mmtt.organization_id = msiv1.organization_id(+) ';
2515 END IF;
2516
2517 IF g_from_lpn_visible = 'T'
2518 THEN
2519 l_where_generic :=
2520 l_where_generic
2521 || 'AND mmtt.lpn_id = wlpn5.lpn_id(+) ';
2522 END IF;
2523
2524 IF g_content_lpn_visible = 'T'
2525 THEN
2526 l_where_generic :=
2527 l_where_generic
2528 || 'AND mmtt.content_lpn_id = wlpn3.lpn_id(+) ';
2529 END IF;
2530
2531 IF g_to_lpn_visible = 'T'
2532 THEN
2533 l_where_generic :=
2534 l_where_generic
2535 || 'AND mmtt.transfer_lpn_id = wlpn4.lpn_id(+) ';
2536 END IF;
2537
2538 IF g_user_task_type_visible = 'T'
2539 THEN
2540 l_where_generic :=
2541 l_where_generic
2542 || 'AND mmtt.standard_operation_id = bso.standard_operation_id(+) ';
2543 l_where_generic :=
2544 l_where_generic
2545 || 'AND mmtt.organization_id = bso.organization_id(+) ';
2546 END IF;
2547
2548 IF g_operation_plan_visible = 'T'
2549 THEN
2550 l_where_generic :=
2551 l_where_generic
2552 || 'AND mmtt.operation_plan_id = wop.operation_plan_id(+) ';
2553 END IF;
2554
2555 IF p_organization_id IS NOT NULL
2556 THEN
2557 l_where_generic :=
2558 l_where_generic || 'AND mmtt.organization_id = :org_id ';
2559 END IF;
2560
2561 IF p_subinventory_code IS NOT NULL
2562 THEN
2563 l_where_generic :=
2564 l_where_generic || 'AND mmtt.subinventory_code = :sub_code ';
2565 END IF;
2566
2567 IF p_locator_id IS NOT NULL
2568 THEN
2569 l_where_generic :=
2570 l_where_generic || 'AND mmtt.locator_id = :loc_id ';
2571 END IF;
2572
2573 IF p_to_subinventory_code IS NOT NULL
2574 THEN
2575 l_where_generic :=
2576 l_where_generic
2577 || 'AND mmtt.transfer_subinventory = :to_sub_code ';
2578 END IF;
2579
2580 IF p_to_locator_id IS NOT NULL
2581 THEN
2582 l_where_generic :=
2583 l_where_generic
2584 || 'AND mmtt.transfer_to_location = :to_loc_id ';
2585 END IF;
2586
2587 IF p_inventory_item_id IS NOT NULL
2588 THEN
2589 l_where_generic :=
2590 l_where_generic || 'AND mmtt.inventory_item_id = :item_id ';
2591 END IF;
2592 -- R12 : Additional Query Criteria using item type
2593 IF p_item_type_code IS NOT NULL
2594 THEN
2595 l_where_generic :=
2596 l_where_generic || 'AND msiv.item_type = :item_type_code ';
2597 END IF;
2598
2599
2600 IF p_category_set_id IS NOT NULL
2601 THEN
2602 l_where_generic :=
2603 l_where_generic
2604 || 'AND mic.category_set_id = :category_set_id ';
2605 END IF;
2606
2607 IF p_item_category_id IS NOT NULL
2608 THEN
2609 l_where_generic :=
2610 l_where_generic
2611 || 'AND mmtt.inventory_item_id = mic.inventory_item_id ';
2612 l_where_generic :=
2613 l_where_generic || 'AND mic.category_id = :item_category_id ';
2614 l_where_generic :=
2615 l_where_generic
2616 || 'AND mic.organization_id = mmtt.organization_id ';
2617 END IF;
2618
2619 IF p_user_task_type_id IS NOT NULL
2620 THEN
2621 l_where_generic :=
2622 l_where_generic
2623 || 'AND nvl(mmtt.standard_operation_id,:user_task_type_id) = :user_task_type_id '; /* Bug 5446146 */
2624 END IF;
2625
2626 IF p_from_task_quantity IS NOT NULL
2627 THEN
2628 l_where_generic :=
2629 l_where_generic
2630 || 'AND mmtt.transaction_quantity >= :from_task_quantity ';
2631 END IF;
2632
2633 IF p_to_task_quantity IS NOT NULL
2634 THEN
2635 l_where_generic :=
2636 l_where_generic
2637 || 'AND mmtt.transaction_quantity <= :to_task_quantity ';
2638 END IF;
2639
2640 IF p_from_task_priority IS NOT NULL
2641 THEN
2642 l_where_generic :=
2643 l_where_generic
2644 || 'AND mmtt.task_priority >= :from_task_priority ';
2645 END IF;
2646
2647 IF p_to_task_priority IS NOT NULL
2648 THEN
2649 l_where_generic :=
2650 l_where_generic
2651 || 'AND mmtt.task_priority <= :to_task_priority ';
2652 END IF;
2653
2654 IF p_from_creation_date IS NOT NULL
2655 THEN
2656 l_where_generic :=
2657 l_where_generic
2658 -- || 'AND mmtt.creation_date >= :from_creation_date '; --commented in 6868286
2659 || 'AND TRUNC(mmtt.creation_date) >= TRUNC(:from_creation_date) '; --added in 6868286
2660 END IF;
2661
2662 IF p_to_creation_date IS NOT NULL
2663 THEN
2664 l_where_generic :=
2665 l_where_generic
2666 -- || 'AND mmtt.creation_date <= :to_creation_date '; --commented in 6868286
2667 || 'AND TRUNC(mmtt.creation_date) <= TRUNC(:to_creation_date) '; --added in 6868286
2668 END IF;
2669
2670 -- R12: Additional Query criteria using age of the task
2671 IF p_age_uom_code IS NOT NULL
2672 THEN
2673
2674 IF p_age_uom_code = 2 THEN -- Minutes
2675 n := '*(24 * 60)';
2676 ELSIF p_age_uom_code = 3 THEN -- Hours
2677 n := '*(24)';
2678 ELSIF p_age_uom_code = 4 THEN -- Days
2679 n := '*(1)';
2680 ELSIF p_age_uom_code = 5 THEN -- Weeks
2681 n := '/(7)';
2682 ELSIF p_age_uom_code = 6 THEN -- Months
2683 n := '/(7 * 31)';
2684 END IF;
2685
2686 IF p_age_min IS NOT NULL
2687 THEN
2688 l_where_generic :=
2689 l_where_generic
2690 || 'AND (sysdate - mmtt.creation_date)'||n||' >= :age_min ';
2691 END IF;
2692
2693 IF p_age_max IS NOT NULL
2694 THEN
2695 l_where_generic :=
2696 l_where_generic
2697 || 'AND (sysdate - mmtt.creation_date)'||n||' <= :age_max ';
2698 END IF;
2699 END IF;
2700
2701 ELSIF (p_is_completed AND NOT p_populate_merged_tasks)
2702 THEN
2703 IF p_add
2704 THEN
2705 l_where_generic :=
2706 'WHERE NOT exists (SELECT 1 FROM wms_waveplan_tasks_temp ';
2707 l_where_generic :=
2708 l_where_generic
2709 || 'WHERE transaction_temp_id = mmt.transaction_id) ';
2710 ELSE
2711 l_where_generic := 'WHERE 1=1 ';
2712 END IF;
2713
2714 IF NOT p_include_cycle_count
2715 THEN
2716 l_where_generic :=
2717 l_where_generic
2718 || 'AND decode(mmt.transfer_transaction_id, null, 0, mmt.transaction_quantity) <= 0 ';
2719 END IF;
2720
2721 /**With ATF changes the source_document_id of WDTH maps to transaction_set_id of MMT.
2722 * Hence changing the join here. Since we support pre-Patchset J records, we use NVL
2723 * to retain the earlier join. Also in Patchset J, this is only done for Inbound
2724 * specific transactions. With ATF changes for Outbound and Warehousing we would
2725 * just need to remove the If condition.Hence leaving it in generic_where
2726 */
2727
2728 IF wms_plan_tasks_pvt.g_from_inbound THEN
2729
2730 l_where_generic := l_where_generic ||
2731 ' AND mmt.transaction_set_id = nvl(wdth.source_document_id,wdth.transaction_id) ';
2732 wms_plan_tasks_pvt.g_from_inbound := FALSE;
2733 ELSE
2734 l_where_generic :=
2735 l_where_generic
2736 || 'AND mmt.transaction_set_id = wdth.transaction_id ';
2737
2738
2739 END IF;
2740 l_where_generic :=
2741 l_where_generic
2742 || 'AND nvl(mmt.transaction_batch_id, -1) = decode(wdth.task_type, ';
2743 l_where_generic :=
2744 l_where_generic || ' 2, nvl(mmt.transaction_batch_id, -1), ';
2745 l_where_generic :=
2746 l_where_generic || ' 3, nvl(mmt.transaction_batch_id, -1), ';
2747 l_where_generic :=
2748 l_where_generic || ' decode(wdth.transaction_batch_id, ';
2749 l_where_generic :=
2750 l_where_generic
2751 || ' -999,nvl(mmt.transaction_batch_id,-1), nvl(wdth.transaction_batch_id, nvl(mmt.transaction_batch_id,-1) ))) '; /* Bug 5553303 */
2752 l_where_generic :=
2753 l_where_generic
2754 || 'AND nvl(mmt.transaction_batch_seq, -1) = decode(wdth.task_type, ';
2755 l_where_generic :=
2756 l_where_generic || ' 2, nvl(mmt.transaction_batch_seq, -1), ';
2757 l_where_generic :=
2758 l_where_generic || ' 3, nvl(mmt.transaction_batch_seq, -1), ';
2759 l_where_generic :=
2760 l_where_generic
2761 || 'decode(wdth.transaction_batch_seq, -999,nvl(mmt.transaction_batch_seq,-1),nvl(wdth.transaction_batch_seq, nvl(mmt.transaction_batch_seq,-1) ))) '; /* Bug 5553303 */
2762 l_where_generic :=
2763 l_where_generic
2764 || 'AND mmt.organization_id = msiv.organization_id ';
2765 l_where_generic :=
2766 l_where_generic
2767 || 'AND mmt.inventory_item_id = msiv.inventory_item_id ';
2768
2769
2770 IF p_outbound_tasks_cycle THEN -- bug #4661615
2771 if l_debug = 1 then
2772 debug(' get_gen_where : p_outbound_tasks_cycle = true' );
2773 end if;
2774 l_where_generic :=
2775 l_where_generic
2776 || 'AND mmt.organization_id = milv.organization_id ';
2777 l_where_generic :=
2778 l_where_generic
2779 || 'AND mmt.locator_id = milv.inventory_location_id ';
2780 ELSE
2781 if l_debug = 1 then
2782 debug(' get_gen_where : p_outbound_tasks_cycle = false' );
2783 end if;
2784 l_where_generic :=
2785 l_where_generic
2786 || 'AND mmt.organization_id = milv.organization_id(+) ';
2787 l_where_generic :=
2788 l_where_generic
2789 || 'AND mmt.locator_id = milv.inventory_location_id(+) ';
2790 END IF;
2791
2792
2793 IF g_to_organization_code_visible = 'T'
2794 THEN
2795 IF p_outbound_tasks_cycle THEN -- bug #4661615
2796 l_where_generic :=
2797 l_where_generic
2798 || 'AND mmt.transfer_organization_id = mp1.organization_id ';
2799 ELSE
2800 l_where_generic :=
2801 l_where_generic
2802 || 'AND mmt.transfer_organization_id = mp1.organization_id(+) ';
2803 END IF;
2804 END IF;
2805
2806 IF g_to_locator_visible = 'T' -- bug #4661615
2807 THEN
2808 IF p_outbound_tasks_cycle THEN
2809 l_where_generic :=
2810 l_where_generic
2811 || 'AND mmt.transfer_organization_id = milv1.organization_id ';
2812 l_where_generic :=
2813 l_where_generic
2814 || 'AND mmt.transfer_locator_id = milv1.inventory_location_id ';
2815 ELSE
2816 l_where_generic :=
2817 l_where_generic
2818 || 'AND mmt.transfer_organization_id = milv1.organization_id(+) ';
2819 l_where_generic :=
2820 l_where_generic
2821 || 'AND mmt.transfer_locator_id = milv1.inventory_location_id(+) ';
2822 END IF;
2823 END IF;
2824
2825 IF g_txn_source_type_visible = 'T'
2826 THEN
2827 l_where_generic :=
2828 l_where_generic
2829 || 'AND mmt.transaction_source_type_id = mtst.transaction_source_type_id ';
2830 END IF;
2831
2832 IF g_person_resource_visible = 'T'
2833 THEN
2834 l_where_generic :=
2835 l_where_generic
2836 || 'AND wdth.person_resource_id = br1.resource_id(+) ';
2837 END IF;
2838
2839 IF g_machine_resource_visible = 'T'
2840 THEN
2841 l_where_generic :=
2842 l_where_generic
2843 || 'AND wdth.machine_resource_id = br2.resource_id(+) ';
2844 END IF;
2845
2846 IF g_person_visible = 'T'
2847 THEN
2848 l_where_generic :=
2849 l_where_generic || 'AND wdth.person_id = pap.person_id ';
2850 l_where_generic :=
2851 l_where_generic
2852 || 'AND trunc(wdth.effective_start_date) >= trunc(pap.effective_start_date) '; /* Bug 5697014 */
2853 l_where_generic :=
2854 l_where_generic
2855 || 'AND trunc(wdth.effective_end_date) <= trunc(pap.effective_end_date) '; /* Bug 5697014 */
2856 END IF;
2857
2858 IF g_from_lpn_visible = 'T'
2859 THEN
2860 l_where_generic :=
2861 l_where_generic || 'AND mmt.lpn_id = wlpn5.lpn_id(+) ';
2862 END IF;
2863
2864 IF g_content_lpn_visible = 'T'
2865 THEN
2866 l_where_generic :=
2867 l_where_generic || 'AND mmt.content_lpn_id = wlpn3.lpn_id(+) ';
2868 END IF;
2869
2870 IF g_to_lpn_visible = 'T'
2871 THEN
2872 l_where_generic :=
2873 l_where_generic
2874 || 'AND mmt.transfer_lpn_id = wlpn4.lpn_id(+) ';
2875 END IF;
2876
2877 IF g_user_task_type_visible = 'T'
2878 THEN
2879 l_where_generic :=
2880 l_where_generic
2881 || 'AND wdth.user_task_type = bso.standard_operation_id(+) ';
2882 l_where_generic :=
2883 l_where_generic
2884 || 'AND wdth.organization_id = bso.organization_id(+) ';
2885 END IF;
2886
2887 IF g_operation_plan_visible = 'T'
2888 THEN
2889 l_where_generic :=
2890 l_where_generic
2891 || 'AND wdth.operation_plan_id = wop.operation_plan_id(+) ';
2892 END IF;
2893
2894 IF p_organization_id IS NOT NULL
2895 THEN
2896 l_where_generic :=
2897 l_where_generic || 'AND mmt.organization_id = :org_id ';
2898 END IF;
2899
2900 IF p_subinventory_code IS NOT NULL
2901 THEN
2902 l_where_generic :=
2903 l_where_generic || 'AND mmt.subinventory_code = :sub_code ';
2904 END IF;
2905
2906 IF p_locator_id IS NOT NULL
2907 THEN
2908 l_where_generic :=
2909 l_where_generic || 'AND mmt.locator_id = :loc_id ';
2910 END IF;
2911
2912 IF p_to_subinventory_code IS NOT NULL
2913 THEN
2914 l_where_generic :=
2915 l_where_generic
2916 || 'AND mmt.transfer_subinventory = :to_sub_code ';
2917 END IF;
2918
2919 IF p_to_locator_id IS NOT NULL
2920 THEN
2921 l_where_generic :=
2922 l_where_generic || 'AND mmt.transfer_locator_id = :to_loc_id ';
2923 END IF;
2924
2925 IF p_inventory_item_id IS NOT NULL
2926 THEN
2927 l_where_generic :=
2928 l_where_generic || 'AND mmt.inventory_item_id = :item_id ';
2929 END IF;
2930
2931 -- R12 : Additional Query Criteria using item type
2932 IF p_item_type_code IS NOT NULL
2933 THEN
2934 l_where_generic :=
2935 l_where_generic || 'AND msiv.item_type = :item_type_code ';
2936 END IF;
2937
2938 IF p_category_set_id IS NOT NULL
2939 THEN
2940 l_where_generic :=
2941 l_where_generic
2942 || 'AND mic.category_set_id = :category_set_id ';
2943 END IF;
2944
2945 IF p_item_category_id IS NOT NULL
2946 THEN
2947 l_where_generic :=
2948 l_where_generic
2949 || 'AND mmt.inventory_item_id = mic.inventory_item_id ';
2950 l_where_generic :=
2951 l_where_generic || 'AND mic.category_id = :item_category_id ';
2952 l_where_generic :=
2953 l_where_generic
2954 || 'AND mic.organization_id = mmt.organization_id ';
2955 END IF;
2956
2957 IF p_person_id IS NOT NULL
2958 THEN
2959 l_where_generic :=
2960 l_where_generic || 'AND wdth.person_id = :person_id ';
2961 END IF;
2962
2963 IF p_person_resource_id IS NOT NULL
2964 THEN
2965 l_where_generic :=
2966 l_where_generic
2967 || 'AND wdth.person_resource_id = :person_resource_id ';
2968 END IF;
2969
2970 IF p_machine_resource_id IS NOT NULL
2971 THEN
2972 l_where_generic :=
2973 l_where_generic
2974 || 'AND wdth.machine_resource_id = :machine_resource_id ';
2975 END IF;
2976
2977 IF p_equipment_type_id IS NOT NULL
2978 THEN
2979 l_where_generic :=
2980 l_where_generic
2981 || 'AND wdth.equipment_id = :equipment_type_id ';
2982 END IF;
2983
2984 IF p_machine_instance IS NOT NULL
2985 THEN
2986 l_where_generic :=
2987 l_where_generic
2988 || 'AND wdth.equipment_instance = :machine_instance ';
2989 END IF;
2990
2991 IF p_user_task_type_id IS NOT NULL
2992 THEN
2993 l_where_generic :=
2994 l_where_generic
2995 || 'AND wdth.user_task_type = :user_task_type_id ';
2996 END IF;
2997
2998 IF p_from_task_priority IS NOT NULL
2999 THEN
3000 l_where_generic :=
3001 l_where_generic
3002 || 'AND mmtt.task_priority >= :from_task_priority ';
3003 END IF;
3004
3005 IF p_to_task_priority IS NOT NULL
3006 THEN
3007 l_where_generic :=
3008 l_where_generic
3009 || 'AND mmtt.task_priority <= :to_task_priority ';
3010 END IF;
3011
3012 IF p_from_task_quantity IS NOT NULL
3013 THEN
3014 l_where_generic :=
3015 l_where_generic
3016 || 'AND mmt.transaction_quantity >= :from_task_quantity ';
3017 END IF;
3018
3019 IF p_to_task_quantity IS NOT NULL
3020 THEN
3021 l_where_generic :=
3022 l_where_generic
3023 || 'AND mmt.transaction_quantity <= :to_task_quantity ';
3024 END IF;
3025
3026 IF p_from_task_priority IS NOT NULL
3027 THEN
3028 l_where_generic :=
3029 l_where_generic || 'AND wdth.priority >= :from_task_priority ';
3030 END IF;
3031
3032 IF p_to_task_priority IS NOT NULL
3033 THEN
3034 l_where_generic :=
3035 l_where_generic || 'AND wdth.priority <= :to_task_priority ';
3036 END IF;
3037
3038 IF p_from_creation_date IS NOT NULL
3039 THEN
3040 l_where_generic :=
3041 l_where_generic
3042 || 'AND TRUNC(mmt.transaction_date) >= TRUNC(:from_creation_date)';--Added TRUNC in bug 6854145
3043 END IF;
3044
3045 IF p_to_creation_date IS NOT NULL
3046 THEN
3047 l_where_generic :=
3048 l_where_generic
3049 || 'AND TRUNC(mmt.transaction_date) <= TRUNC(:to_creation_date) ';--Added TRUNC in bug 6854145
3050 END IF;
3051
3052 -- R12: Additional Query criteria using age of the task
3053 IF p_age_uom_code IS NOT NULL
3054 THEN
3055
3056 IF p_age_uom_code = 2 THEN -- Minutes
3057 n := '*(24 * 60)';
3058 ELSIF p_age_uom_code = 3 THEN -- Hours
3059 n := '*(24)';
3060 ELSIF p_age_uom_code = 4 THEN -- Days
3061 n := '*(1)';
3062 ELSIF p_age_uom_code = 5 THEN -- Weeks
3063 n := '/(7)';
3064 ELSIF p_age_uom_code = 6 THEN -- Months
3065 n := '/(7 * 31)';
3066 END IF;
3067
3068 IF p_age_min IS NOT NULL
3069 THEN
3070 l_where_generic :=
3071 l_where_generic
3072 || 'AND (sysdate - mmtt.creation_date)'||n||' >= :age_min ';
3073 END IF;
3074
3075 IF p_age_max IS NOT NULL
3076 THEN
3077 l_where_generic :=
3078 l_where_generic
3079 || 'AND (sysdate - mmtt.creation_date)'||n||' <= :age_max ';
3080 END IF;
3081 END IF;
3082 ELSIF (p_is_completed AND p_populate_merged_tasks)
3083 THEN
3084 --Patchset J Bulk Pick Enhancement
3085 --Querying for completed parent tasks. Thus only use wdth and not mmt
3086 --Completed parent only comes up if query criteria match one of its
3087 --completed children.
3088 IF p_add
3089 THEN
3090 l_where_generic :=
3091 'WHERE NOT exists (SELECT 1 FROM wms_waveplan_tasks_temp ';
3092 l_where_generic :=
3093 l_where_generic
3094 || 'WHERE transaction_temp_id = wdth.transaction_id) ';
3095 ELSE
3096 l_where_generic := 'WHERE 1=1 ';
3097 END IF;
3098
3099 --Assumption with this join:
3100 --wwtt contain completed children that have been queried up and need
3101 --to find the parent. Thus we use the children to find the wdth
3102 --parent record.
3103 l_where_generic :=
3104 l_where_generic
3105 || 'AND wdth.transaction_id = wwtt.parent_line_id ';
3106 l_where_generic :=
3107 l_where_generic
3108 || 'AND wdth.organization_id = msiv.organization_id ';
3109 l_where_generic :=
3110 l_where_generic
3111 || 'AND wdth.inventory_item_id = msiv.inventory_item_id ';
3112 l_where_generic :=
3113 l_where_generic
3114 || 'AND wdth.organization_id = milv.organization_id(+) ';
3115 l_where_generic :=
3116 l_where_generic
3117 || 'AND wdth.source_locator_id = milv.inventory_location_id(+) ';
3118
3119 IF g_to_organization_code_visible = 'T'
3120 THEN
3121 l_where_generic :=
3122 l_where_generic
3123 || 'AND wdth.transfer_organization_id = mp1.organization_id(+) ';
3124 END IF;
3125
3126 IF g_txn_source_type_visible = 'T'
3127 THEN
3128 l_where_generic :=
3129 l_where_generic
3130 || 'AND wdth.transaction_source_type_id = mtst.transaction_source_type_id ';
3131 END IF;
3132
3133 IF g_person_resource_visible = 'T'
3134 THEN
3135 l_where_generic :=
3136 l_where_generic
3137 || 'AND wdth.person_resource_id = br1.resource_id(+) ';
3138 END IF;
3139
3140 IF g_machine_resource_visible = 'T'
3141 THEN
3142 l_where_generic :=
3143 l_where_generic
3144 || 'AND wdth.machine_resource_id = br2.resource_id(+) ';
3145 END IF;
3146
3147 IF g_person_visible = 'T'
3148 THEN
3149 l_where_generic :=
3150 l_where_generic || 'AND wdth.person_id = pap.person_id ';
3151 l_where_generic :=
3152 l_where_generic
3153 || 'AND trunc(wdth.effective_start_date) >= trunc(pap.effective_start_date) '; /* Bug 5697014 */
3154 l_where_generic :=
3155 l_where_generic
3156 || 'AND trunc(wdth.effective_end_date) <= trunc(pap.effective_end_date) '; /* Bug 5697014 */
3157 END IF;
3158
3159 IF g_from_lpn_visible = 'T'
3160 THEN
3161 l_where_generic :=
3162 l_where_generic || 'AND wdth.lpn_id = wlpn5.lpn_id(+) ';
3163 END IF;
3164
3165 IF g_content_lpn_visible = 'T'
3166 THEN
3167 l_where_generic :=
3168 l_where_generic
3169 || 'AND wdth.content_lpn_id = wlpn3.lpn_id(+) ';
3170 END IF;
3171
3172 IF g_to_lpn_visible = 'T'
3173 THEN
3174 l_where_generic :=
3175 l_where_generic
3176 || 'AND wdth.transfer_lpn_id = wlpn4.lpn_id(+) ';
3177 END IF;
3178
3179 IF g_user_task_type_visible = 'T'
3180 THEN
3181 l_where_generic :=
3182 l_where_generic
3183 || 'AND wdth.user_task_type = bso.standard_operation_id(+) ';
3184 l_where_generic :=
3185 l_where_generic
3186 || 'AND wdth.organization_id = bso.organization_id(+) ';
3187 END IF;
3188
3189 IF g_operation_plan_visible = 'T'
3190 THEN
3191 l_where_generic :=
3192 l_where_generic
3193 || 'AND wdth.operation_plan_id = wop.operation_plan_id(+) ';
3194 END IF;
3195
3196 IF p_organization_id IS NOT NULL
3197 THEN
3198 l_where_generic :=
3199 l_where_generic || 'AND wdth.organization_id = :org_id ';
3200 END IF;
3201
3202 IF p_category_set_id IS NOT NULL
3203 THEN
3204 l_where_generic :=
3205 l_where_generic
3206 || 'AND mic.category_set_id = :category_set_id ';
3207 END IF;
3208
3209 IF p_item_category_id IS NOT NULL
3210 THEN
3211 l_where_generic :=
3212 l_where_generic
3213 || 'AND wdth.inventory_item_id = mic.inventory_item_id ';
3214 l_where_generic :=
3215 l_where_generic || 'AND mic.category_id = :item_category_id ';
3216 l_where_generic :=
3217 l_where_generic
3218 || 'AND mic.organization_id = wdth.organization_id ';
3219 END IF;
3220 END IF;
3221 if l_debug = 1 then
3222 debug (l_where_generic);
3223 end if;
3224 RETURN l_where_generic;
3225 END get_generic_where;
3226
3227 --The procedure deals with parent and children tasks.
3228 --It was already existing when this file was first created.
3229 --Enhancements done for Bulk Picking in patchset J:
3230 --1. We needed to show completed children for Active parents (partially
3231 -- completed). Before patchset J, children are not shown anytime parent
3232 -- is shown. This is done by deleting only non-completed children
3233 --2. Added condition transaction_action_id = 28 and check for WIP task everywhere since we now
3234 -- support ATF which also uses parent_line_id column. This condition
3235 -- will select or delete only bulk pick related tasks
3236 --3. Added a new out parameter to return the number of non-completed
3237 -- parent tasks that was inserted. Use to determine if need to
3238 -- calculate number of children
3239 PROCEDURE populate_merged_tasks (
3240 p_is_unreleased BOOLEAN DEFAULT FALSE,
3241 p_is_pending BOOLEAN DEFAULT FALSE,
3242 p_is_queued BOOLEAN DEFAULT FALSE,
3243 p_is_dispatched BOOLEAN DEFAULT FALSE,
3244 p_is_active BOOLEAN DEFAULT FALSE,
3245 p_is_loaded BOOLEAN DEFAULT FALSE,
3246 p_is_completed BOOLEAN DEFAULT FALSE,
3247 p_from_task_quantity NUMBER DEFAULT NULL,
3248 p_to_task_quantity NUMBER DEFAULT NULL,
3249 p_person_id NUMBER DEFAULT NULL, /* Bug 5446146 */
3250 p_person_resource_id NUMBER DEFAULT NULL,
3251 p_equipment_type_id NUMBER DEFAULT NULL,
3252 p_machine_resource_id NUMBER DEFAULT NULL,
3253 p_machine_instance VARCHAR2 DEFAULT NULL,
3254 p_user_task_type_id NUMBER DEFAULT NULL, /* End of Bug 5446146 */
3255 x_non_complete_parent OUT NOCOPY NUMBER
3256 )
3257 IS
3258 l_insert_query VARCHAR2 (2000);
3259 l_select_generic VARCHAR2 (3000);
3260 l_from_generic VARCHAR2 (2000);
3261 l_where_generic VARCHAR2 (5000);
3262 l_query VARCHAR2 (10000);
3263 l_query_handle NUMBER; -- Handle for the dynamic sql
3264 l_query_count NUMBER;
3265 BEGIN
3266 -- If no tasks have been queried up, there is no need to populate merged tasks
3267 IF g_record_count = 0
3268 THEN
3269 RETURN;
3270 END IF;
3271
3272 -- Delete all the parent records that have been queries up
3273 DELETE FROM wms_waveplan_tasks_temp
3274 WHERE task_type_id <> 3
3275 AND transaction_temp_id IN (
3276 SELECT parent_line_id
3277 FROM wms_waveplan_tasks_temp
3278 WHERE parent_line_id IS NOT NULL
3279 AND task_type_id <> 3
3280 --Change
3281 --Check for outbound and wip tasks below
3282 AND ( transaction_action_id = 28
3283 OR ( transaction_source_type_id = 5
3284 AND transaction_type_id = 35
3285 )
3286 OR ( transaction_source_type_id = 13
3287 AND transaction_type_id = 51
3288 )
3289 ));
3290
3291 --End of change
3292 l_query_count := SQL%ROWCOUNT;
3293 g_record_count := g_record_count - l_query_count;
3294 l_query_count := 0;
3295
3296 --get the number of children tasks queried up
3297 BEGIN
3298 SELECT 1
3299 INTO l_query_count
3300 FROM DUAL
3301 WHERE EXISTS (
3302 SELECT parent_line_id
3303 FROM wms_waveplan_tasks_temp
3304 WHERE parent_line_id IS NOT NULL
3305 AND task_type_id <> 3
3306 --Change
3307 --check for outbound and wip tasks below
3308 AND ( transaction_action_id = 28
3309 OR ( transaction_source_type_id = 5
3310 AND transaction_type_id = 35
3311 )
3312 OR ( transaction_source_type_id = 13
3313 AND transaction_type_id = 51
3314 )
3315 ));
3316 --End of change
3317 EXCEPTION
3318 WHEN NO_DATA_FOUND
3319 THEN
3320 NULL;
3321 END;
3322
3323 IF (l_query_count > 0)
3324 AND ( p_is_unreleased
3325 OR p_is_pending
3326 OR p_is_queued
3327 OR p_is_dispatched
3328 OR p_is_active
3329 OR p_is_loaded
3330 )
3331 THEN
3332 -- Insert merged tasks into the temp table
3333 l_insert_query :=
3334 get_generic_insert (p_is_unreleased => p_is_unreleased,
3335 p_is_pending => p_is_pending,
3336 p_is_queued => p_is_queued,
3337 p_is_dispatched => p_is_dispatched,
3338 p_is_active => p_is_active,
3339 p_is_loaded => p_is_loaded,
3340 p_is_completed => FALSE
3341 );
3342 l_insert_query := l_insert_query || ') ';
3343 l_select_generic :=
3344 get_generic_select (p_is_unreleased => p_is_unreleased,
3345 p_is_pending => p_is_pending,
3346 p_is_queued => p_is_queued,
3347 p_is_dispatched => p_is_dispatched,
3348 p_is_active => p_is_active,
3349 p_is_loaded => p_is_loaded,
3350 p_is_completed => FALSE,
3351 p_populate_merged_tasks => TRUE
3352 );
3353 l_from_generic :=
3354 get_generic_from (p_is_queued => p_is_queued,
3355 p_is_dispatched => p_is_dispatched,
3356 p_is_active => p_is_active,
3357 p_is_loaded => p_is_loaded,
3358 p_is_completed => FALSE,
3359 p_populate_merged_tasks => TRUE
3360 );
3361 l_where_generic :=
3362 get_generic_where (p_from_task_quantity => p_from_task_quantity,
3363 p_to_task_quantity => p_to_task_quantity,
3364 p_is_unreleased => p_is_unreleased,
3365 p_is_pending => p_is_pending,
3366 p_is_queued => p_is_queued,
3367 p_is_dispatched => p_is_dispatched,
3368 p_is_active => p_is_active,
3369 p_is_loaded => p_is_loaded,
3370 p_is_completed => FALSE,
3371 p_populate_merged_tasks => TRUE
3372 );
3373
3374 /* Bug 5446146 Filter the bulk tasks based on the employee, Role, etc */
3375 IF p_person_id IS NOT NULL THEN
3376 l_where_generic := l_where_generic || ' AND wdt.person_id = :person_id ';
3377 END IF;
3378
3379 IF p_person_resource_id IS NOT NULL THEN
3380 l_where_generic := l_where_generic || 'AND wdt.person_resource_id = :person_resource_id ';
3381 END IF;
3382
3383 IF p_equipment_type_id IS NOT NULL THEN
3384 l_where_generic := l_where_generic || 'AND wdt.equipment_id = :equipment_type_id ';
3385 END IF;
3386
3387 IF p_machine_resource_id IS NOT NULL THEN
3388 l_where_generic := l_where_generic || 'AND wdt.machine_resource_id = :machine_resource_id ';
3389 END IF;
3390
3391 IF p_machine_instance IS NOT NULL THEN
3392 l_where_generic := l_where_generic || 'AND wdt.equipment_instance = :machine_instance ';
3393 END IF;
3394
3395 IF p_user_task_type_id IS NOT NULL THEN
3396 l_where_generic := l_where_generic || 'AND mmtt.standard_operation_id = :user_task_type_id ';
3397 END IF;
3398 /* End of Bug 5446146 */
3399
3400 -- Concatenate the different sections of the query
3401 l_query :=
3402 l_insert_query
3403 || l_select_generic
3404 || l_from_generic
3405 || l_where_generic;
3406 -- Parse, Bind and Execute the dynamic query
3407 l_query_handle := DBMS_SQL.open_cursor;
3408 DBMS_SQL.parse (l_query_handle, l_query, DBMS_SQL.native);
3409
3410 IF p_from_task_quantity IS NOT NULL
3411 THEN
3412 DBMS_SQL.bind_variable (l_query_handle,
3413 'from_task_quantity',
3414 p_from_task_quantity
3415 );
3416 END IF;
3417
3418 IF p_to_task_quantity IS NOT NULL
3419 THEN
3420 DBMS_SQL.bind_variable (l_query_handle,
3421 'to_task_quantity',
3422 p_to_task_quantity
3423 );
3424 END IF;
3425
3426 /* Bug 5446146 */
3427 IF p_person_id IS NOT NULL THEN
3428 DBMS_SQL.bind_variable (l_query_handle,
3429 'person_id',
3430 p_person_id);
3431 END IF;
3432
3433 IF p_person_resource_id IS NOT NULL THEN
3434 DBMS_SQL.bind_variable (l_query_handle,
3435 'person_resource_id',
3436 p_person_resource_id);
3437 END IF;
3438
3439 IF p_equipment_type_id IS NOT NULL THEN
3440 DBMS_SQL.bind_variable (l_query_handle,
3441 'equipment_type_id',
3442 p_equipment_type_id
3443 );
3444 END IF;
3445
3446 IF p_machine_resource_id IS NOT NULL THEN
3447 DBMS_SQL.bind_variable (l_query_handle,
3448 'machine_resource_id',
3449 p_machine_resource_id
3450 );
3451 END IF;
3452
3453 IF p_machine_instance IS NOT NULL THEN
3454 DBMS_SQL.bind_variable (l_query_handle,
3455 'machine_instance',
3456 p_machine_instance
3457 );
3458 END IF;
3459
3460 IF p_user_task_type_id IS NOT NULL
3461 THEN
3462 DBMS_SQL.bind_variable (l_query_handle,
3463 'user_task_type_id',
3464 p_user_task_type_id
3465 );
3466 END IF;
3467 /* End of Bug 5446146 */
3468
3469 l_query_count := DBMS_SQL.EXECUTE (l_query_handle);
3470 g_record_count := g_record_count + l_query_count;
3471 x_non_complete_parent := l_query_count;
3472 DBMS_SQL.close_cursor(l_query_handle);
3473
3474 -- Delete the child tasks from the temp table
3475 --Bulk Picking Enhancement:
3476 --Added the condition status_id <> 6 because we want to show
3477 --completed children associated with a partially completed(Active) parent
3478 DELETE FROM wms_waveplan_tasks_temp
3479 WHERE parent_line_id IS NOT NULL
3480 AND status_id <> 6
3481 --Change
3482 --check for outbound and wip tasks below
3483 AND ( transaction_action_id = 28
3484 OR ( transaction_source_type_id = 5
3485 AND transaction_type_id = 35
3486 )
3487 OR ( transaction_source_type_id = 13
3488 AND transaction_type_id = 51
3489 )
3490 )
3491 AND parent_line_id <> transaction_temp_id;
3492 -- exclude the parent lines
3493
3494 -- this is only useful for patchset J, jali changed.
3495 --End of change
3496 l_query_count := SQL%ROWCOUNT;
3497 g_record_count := g_record_count - l_query_count;
3498 END IF;
3499
3500 --get the number of completed children tasks queried up
3501 l_query_count := 0;
3502
3503 BEGIN
3504 SELECT 1
3505 INTO l_query_count
3506 FROM DUAL
3507 WHERE EXISTS (
3508 SELECT parent_line_id
3509 FROM wms_waveplan_tasks_temp
3510 WHERE parent_line_id IS NOT NULL
3511 AND task_type_id <> 3
3512 --Change
3513 --check for outbound and wip tasks below
3514 AND ( transaction_action_id = 28
3515 OR ( transaction_source_type_id = 5
3516 AND transaction_type_id = 35
3517 )
3518 OR ( transaction_source_type_id = 13
3519 AND transaction_type_id = 51
3520 )
3521 )
3522 --End of change
3523 AND status_id = 6);
3524 EXCEPTION
3525 WHEN NO_DATA_FOUND
3526 THEN
3527 --no completed children. no need to find parents
3528 RETURN;
3529 END;
3530
3531 --Changes
3532 --Changed all p_ params to FALSE in the following block of code
3533
3534 --Find completed parent of completed children
3535 IF l_query_count > 0
3536 THEN
3537 l_insert_query :=
3538 get_generic_insert (p_is_unreleased => FALSE
3539 --p_is_unreleased,
3540 ,
3541 p_is_pending => FALSE --p_is_pending,
3542 ,
3543 p_is_queued => FALSE --p_is_queued,
3544 ,
3545 p_is_dispatched => FALSE
3546 --p_is_dispatched,
3547 ,
3548 p_is_active => FALSE --p_is_active,
3549 ,
3550 p_is_loaded => FALSE --p_is_loaded,
3551 ,
3552 p_is_completed => TRUE
3553 );
3554 l_insert_query := l_insert_query || ') ';
3555 l_select_generic :=
3556 get_generic_select (p_is_unreleased => FALSE
3557 --p_is_unreleased,
3558 ,
3559 p_is_pending => FALSE
3560 --p_is_pending,
3561 ,
3562 p_is_queued => FALSE
3563 --p_is_queued,
3564 ,
3565 p_is_dispatched => FALSE
3566 --p_is_dispatched,
3567 ,
3568 p_is_active => FALSE
3569 --p_is_active,
3570 ,
3571 p_is_loaded => FALSE
3572 --p_is_loaded,
3573 ,
3574 p_is_completed => TRUE,
3575 p_populate_merged_tasks => TRUE
3576 );
3577 l_from_generic :=
3578 get_generic_from (p_is_queued => FALSE
3579 --p_is_queued,
3580 ,
3581 p_is_dispatched => FALSE
3582 --p_is_dispatched,
3583 ,
3584 p_is_active => FALSE
3585 --p_is_active,
3586 ,
3587 p_is_loaded => FALSE
3588 --p_is_loaded,
3589 ,
3590 p_is_completed => TRUE,
3591 p_populate_merged_tasks => TRUE
3592 );
3593 l_where_generic :=
3594 get_generic_where (p_is_unreleased => FALSE
3595 --p_is_unreleased,
3596 ,
3597 p_is_pending => FALSE
3598 --p_is_pending,
3599 ,
3600 p_is_queued => FALSE
3601 --p_is_queued,
3602 ,
3603 p_is_dispatched => FALSE
3604 --p_is_dispatched,
3605 ,
3606 p_is_active => FALSE
3607 --p_is_active,
3608 ,
3609 p_is_loaded => FALSE
3610 --p_is_loaded,
3611 ,
3612 p_is_completed => TRUE,
3613 p_populate_merged_tasks => TRUE
3614 );
3615 --End of Changes
3616
3617 --Changes
3618 --Assumption with this join:
3619 --wwtt contain completed children that have been queried up and need
3620 --to find the parent. Thus we use the children to find the wdth
3621 --parent record.
3622 l_where_generic :=
3623 l_where_generic
3624 || ' AND wdth.transaction_id = wwtt.parent_line_id ';
3625 --End of Changes
3626
3627 -- Concatenate the different sections of the query
3628 l_query :=
3629 l_insert_query
3630 || l_select_generic
3631 || l_from_generic
3632 || l_where_generic;
3633 -- Parse, Bind and Execute the dynamic query
3634 l_query_handle := DBMS_SQL.open_cursor;
3635 DBMS_SQL.parse (l_query_handle, l_query, DBMS_SQL.native);
3636 l_query_count := DBMS_SQL.EXECUTE (l_query_handle);
3637 g_record_count := g_record_count + l_query_count;
3638 DBMS_SQL.close_cursor(l_query_handle);
3639 END IF;
3640 EXCEPTION
3641 WHEN OTHERS THEN -- Bug 4150145
3642 IF dbms_sql.is_open(l_query_handle) THEN
3643 DBMS_SQL.close_cursor(l_query_handle);
3644 END IF;
3645 debug(Sqlerrm, 'Task_planning.populate_merged_tasks');
3646 END populate_merged_tasks;
3647
3648 PROCEDURE query_outbound_tasks (
3649 p_add BOOLEAN DEFAULT FALSE,
3650 p_organization_id NUMBER DEFAULT NULL,
3651 p_subinventory_code VARCHAR2 DEFAULT NULL,
3652 p_locator_id NUMBER DEFAULT NULL,
3653 p_to_subinventory_code VARCHAR2 DEFAULT NULL,
3654 p_to_locator_id NUMBER DEFAULT NULL,
3655 p_inventory_item_id NUMBER DEFAULT NULL,
3656 p_category_set_id NUMBER DEFAULT NULL,
3657 p_item_category_id NUMBER DEFAULT NULL,
3658 p_person_id NUMBER DEFAULT NULL,
3659 p_person_resource_id NUMBER DEFAULT NULL,
3660 p_equipment_type_id NUMBER DEFAULT NULL,
3661 p_machine_resource_id NUMBER DEFAULT NULL,
3662 p_machine_instance VARCHAR2 DEFAULT NULL,
3663 p_user_task_type_id NUMBER DEFAULT NULL,
3664 p_from_task_quantity NUMBER DEFAULT NULL,
3665 p_to_task_quantity NUMBER DEFAULT NULL,
3666 p_from_task_priority NUMBER DEFAULT NULL,
3667 p_to_task_priority NUMBER DEFAULT NULL,
3668 p_from_creation_date DATE DEFAULT NULL,
3669 p_to_creation_date DATE DEFAULT NULL,
3670 p_is_unreleased BOOLEAN DEFAULT FALSE,
3671 p_is_pending BOOLEAN DEFAULT FALSE,
3672 p_is_queued BOOLEAN DEFAULT FALSE,
3673 p_is_dispatched BOOLEAN DEFAULT FALSE,
3674 p_is_active BOOLEAN DEFAULT FALSE,
3675 p_is_loaded BOOLEAN DEFAULT FALSE,
3676 p_is_completed BOOLEAN DEFAULT FALSE,
3677 p_include_sales_orders BOOLEAN DEFAULT TRUE,
3678 p_include_internal_orders BOOLEAN DEFAULT TRUE,
3679 p_from_sales_order_id NUMBER DEFAULT NULL,
3680 p_to_sales_order_id NUMBER DEFAULT NULL,
3681 p_from_pick_slip_number NUMBER DEFAULT NULL,
3682 p_to_pick_slip_number NUMBER DEFAULT NULL,
3683 p_customer_id NUMBER DEFAULT NULL,
3684 p_customer_category VARCHAR2 DEFAULT NULL,
3685 p_delivery_id NUMBER DEFAULT NULL,
3686 p_carrier_id NUMBER DEFAULT NULL,
3687 p_ship_method VARCHAR2 DEFAULT NULL,
3688 p_shipment_priority VARCHAR2 DEFAULT NULL,
3689 p_trip_id NUMBER DEFAULT NULL,
3690 p_from_shipment_date DATE DEFAULT NULL,
3691 p_to_shipment_date DATE DEFAULT NULL,
3692 p_ship_to_state VARCHAR2 DEFAULT NULL,
3693 p_ship_to_country VARCHAR2 DEFAULT NULL,
3694 p_ship_to_postal_code VARCHAR2 DEFAULT NULL,
3695 p_from_number_of_order_lines NUMBER DEFAULT NULL,
3696 p_to_number_of_order_lines NUMBER DEFAULT NULL,
3697 -- R12 : Additional Query Criteria
3698 p_item_type_code VARCHAR2 DEFAULT NULL,
3699 p_age_uom_code VARCHAR2 DEFAULT NULL,
3700 p_age_min NUMBER DEFAULT NULL,
3701 p_age_max NUMBER DEFAULT NULL,
3702 p_order_type_id NUMBER DEFAULT NULL,
3703 p_time_till_shipment_uom_code VARCHAR2 DEFAULT NULL,
3704 p_time_till_shipment NUMBER DEFAULT NULL,
3705 p_time_till_appt_uom_code VARCHAR2 DEFAULT NULL,
3706 p_time_till_appt NUMBER DEFAULT NULL,
3707 p_summary_mode NUMBER DEFAULT 0
3708 -- R12 : Additional Query Criteria
3709 )
3710 IS
3711 l_insert_query VARCHAR2 (3000);
3712 l_select_generic VARCHAR2 (4000);
3713 l_select_outbound VARCHAR2 (4000);
3714 l_from_generic VARCHAR2 (2000);
3715 l_where_generic VARCHAR2 (5000);
3716 l_from_outbound VARCHAR2 (2000);
3717 l_where_outbound VARCHAR2 (4000);
3718 l_query VARCHAR2 (10000);
3719 l_query_handle NUMBER; -- Handle for the dynamic sql
3720 l_query_count NUMBER;
3721 l_loop_start NUMBER;
3722 l_loop_end NUMBER;
3723 l_is_unreleased BOOLEAN;
3724 l_is_pending BOOLEAN;
3725 l_is_queued BOOLEAN;
3726 l_is_dispatched BOOLEAN;
3727 l_is_active BOOLEAN;
3728 l_is_loaded BOOLEAN;
3729 l_is_completed BOOLEAN;
3730 l_outbound_tasks_cycle BOOLEAN; -- bug #4661615
3731 l_wms_task_type NUMBER; -- for bug 5129375
3732 l_task_count NUMBER;
3733
3734 l_is_range_so BOOLEAN;/*added for 3455109*/
3735 l_from_tonum_mso_seg1 varchar2(40);--3455109
3736 l_to_tonum_mso_seg1 varchar2(40); -- 3455109
3737 l_from_mso_seg2 VARCHAR2(150);--need tocheck the corrrect size from mso 3455109
3738 l_to_mso_seg2 VARCHAR2(150);--3455109
3739 l_from_mso_seg1 varchar2(40);--3455109 used for non range query no need to do lpad/to_number
3740 --R12: Additional Query criteria
3741 --Age UOM conversion factor
3742 n VARCHAR2 (10);
3743
3744 l_debug NUMBER
3745 := NVL (fnd_profile.VALUE ('INV_DEBUG_TRACE'), 0);
3746
3747 BEGIN
3748
3749 if (p_from_sales_order_id = p_to_sales_order_id) then
3750 l_is_range_so := FALSE;
3751 else/*range so is TRUE if from or to is null or form<> to*/
3752 l_is_range_so := TRUE;
3753 end if;
3754 if P_from_sales_order_id is not null then
3755 select lpad(segment1,40), segment2,segment1
3756 INTO l_from_tonum_mso_seg1,l_from_mso_seg2,l_from_mso_seg1
3757 from mtl_sales_orders
3758 WHERE sales_order_id = p_from_sales_order_id;
3759 end if;
3760 IF(l_is_range_so) THEN
3761 /* Its a range...Query for details of to sales order */
3762 if P_to_sales_order_id is not null then
3763 select lpad(segment1,40), segment2
3764 INTO l_to_tonum_mso_seg1,l_to_mso_seg2
3765 from mtl_sales_orders
3766 WHERE sales_order_id = p_to_sales_order_id;
3767 end if;/*added the above code to get the values since we are not going to join with mso 3455109*/
3768 ELSE
3769 l_to_tonum_mso_seg1 := l_from_tonum_mso_seg1;
3770 l_to_mso_seg2 := l_from_mso_seg2;
3771 END IF;
3772
3773 /* DEBUG('l_from_tonum_mso_seg1 '|| l_from_tonum_mso_seg1);
3774 DEBUG('l_from_mso_seg2 '|| l_from_mso_seg2);
3775 DEBUG('l_from_mso_seg1 '|| l_from_mso_seg1);
3776 DEBUG('l_to_tonum_mso_seg1 '|| l_to_tonum_mso_seg1);
3777 DEBUG('l_to_mso_seg2 '|| l_to_mso_seg2);*/
3778
3779
3780 IF p_is_completed
3781 THEN
3782
3783 l_loop_end := 2;
3784 ELSE
3785
3786 l_loop_end := 1;
3787 END IF;
3788
3789 IF p_is_unreleased
3790 OR p_is_pending
3791 OR p_is_queued
3792 OR p_is_dispatched
3793 OR p_is_active
3794 OR p_is_loaded
3795 THEN
3796
3797 l_loop_start := 1;
3798 ELSE
3799
3800 l_loop_start := 2;
3801 END IF;
3802
3803 if l_debug = 1 then
3804 IF p_is_unreleased THEN
3805 debug('unreleased');
3806 END IF;
3807
3808 IF p_is_pending THEN
3809 debug('pending');
3810 END IF;
3811
3812 IF p_is_queued THEN
3813 debug('queued');
3814 END IF;
3815
3816 IF p_is_dispatched THEN
3817 debug('dispatched');
3818 END IF;
3819
3820 IF p_is_active THEN
3821 debug('active');
3822 END IF;
3823
3824 IF p_is_loaded THEN
3825 debug('loaded');
3826 END IF;
3827
3828 DEBUG('p_is_pending : ' || l_loop_start);
3829 DEBUG('p_is_pending : ' || l_loop_end);
3830 end if;
3831
3832 FOR i IN l_loop_start .. l_loop_end
3833 LOOP
3834 --debug(' i ' || i);
3835 l_insert_query := NULL;
3836 l_select_generic := NULL;
3837 l_select_outbound := NULL;
3838 l_from_generic := NULL;
3839 l_from_outbound := NULL;
3840 l_where_generic := NULL;
3841 l_where_outbound := NULL;
3842
3843 IF i = 1
3844 THEN -- Non completed tasks iteration
3845 if l_debug = 1 then
3846 DEBUG('non completed tasks iteration');
3847 end if;
3848 l_is_unreleased := p_is_unreleased;
3849 l_is_pending := p_is_pending;
3850 l_is_queued := p_is_queued;
3851 l_is_dispatched := p_is_dispatched;
3852 l_is_active := p_is_active;
3853 l_is_loaded := p_is_loaded;
3854 l_is_completed := FALSE;
3855 l_outbound_tasks_cycle := TRUE; -- bug #4661615
3856 ELSE -- Completed tasks
3857 if l_debug = 1 then
3858 DEBUG('completed tasks iteration');
3859 end if;
3860 l_is_unreleased := FALSE;
3861 l_is_pending := FALSE;
3862 l_is_queued := FALSE;
3863 l_is_dispatched := FALSE;
3864 l_is_active := FALSE;
3865 l_is_loaded := FALSE;
3866 l_is_completed := p_is_completed;
3867 l_outbound_tasks_cycle := TRUE; -- bug #4661615
3868 END IF;
3869
3870 -- Insert section
3871 IF p_summary_mode = 1 THEN -- only for query mode
3872 IF i = 1 THEN
3873 l_select_generic := ' SELECT mmtt.wms_task_type, count(*) ';
3874 ELSE
3875 l_select_generic := ' SELECT wdth.task_type, count(*) ';
3876 END IF;
3877 ELSE
3878 l_insert_query :=
3879 get_generic_insert (p_is_unreleased => l_is_unreleased,
3880 p_is_pending => l_is_pending,
3881 p_is_queued => l_is_queued,
3882 p_is_dispatched => l_is_dispatched,
3883 p_is_active => l_is_active,
3884 p_is_loaded => l_is_loaded,
3885 p_is_completed => l_is_completed
3886 );
3887 l_insert_query := l_insert_query || ', customer_id ';
3888
3889 IF g_customer_visible = 'T'
3890 THEN
3891 l_insert_query := l_insert_query || ', customer ';
3892 END IF;
3893
3894 l_insert_query := l_insert_query || ', ship_to_location_id ';
3895
3896 IF g_ship_to_country_visible = 'T'
3897 OR g_ship_to_state_visible = 'T'
3898 OR g_ship_to_postal_code_visible = 'T'
3899 THEN
3900 l_insert_query := l_insert_query || ', ship_to_country ';
3901 l_insert_query := l_insert_query || ', ship_to_state ';
3902 l_insert_query := l_insert_query || ', ship_to_postal_code ';
3903 END IF;
3904
3905 IF g_delivery_visible = 'T'
3906 THEN
3907 l_insert_query := l_insert_query || ', delivery ';
3908 END IF;
3909
3910 IF g_ship_method_visible = 'T'
3911 THEN
3912 l_insert_query := l_insert_query || ', ship_method ';
3913 END IF;
3914
3915 l_insert_query := l_insert_query || ', carrier_id ';
3916
3917 IF g_carrier_visible = 'T'
3918 THEN
3919 l_insert_query := l_insert_query || ', carrier ';
3920 END IF;
3921
3922 l_insert_query := l_insert_query || ', shipment_date ';
3923 l_insert_query := l_insert_query || ', shipment_priority ';
3924 l_insert_query := l_insert_query || ', source_header ';
3925 l_insert_query := l_insert_query || ', line_number ';
3926 if WMS_CONTROL.G_CURRENT_RELEASE_LEVEL >= 120001 then
3927 -- For R12.1 OTM integration project
3928 l_insert_query := l_insert_query || ', load_seq_number ';
3929 end if;
3930 l_insert_query := l_insert_query || ') ';
3931 l_select_generic :=
3932 get_generic_select (p_is_unreleased => l_is_unreleased,
3933 p_is_pending => l_is_pending,
3934 p_is_queued => l_is_queued,
3935 p_is_dispatched => l_is_dispatched,
3936 p_is_active => l_is_active,
3937 p_is_loaded => l_is_loaded,
3938 p_is_completed => l_is_completed
3939 );
3940 l_select_outbound := ', wdd.customer_id '; --customer_id
3941
3942 IF g_customer_visible = 'T'
3943 THEN
3944 l_select_outbound := l_select_outbound || ', substr( hp.party_name, 1, 50 ) ';
3945 --customer
3946 END IF;
3947
3948 l_select_outbound :=
3949 l_select_outbound || ', wdd.ship_to_location_id ';
3950 --ship_to_location_id
3951
3952 IF g_ship_to_country_visible = 'T'
3953 OR g_ship_to_state_visible = 'T'
3954 OR g_ship_to_postal_code_visible = 'T'
3955 THEN
3956 l_select_outbound := l_select_outbound || ', hl.country ';
3957 --ship_to_country
3958 l_select_outbound := l_select_outbound || ', hl.state ';
3959 --ship_to_state
3960 l_select_outbound := l_select_outbound || ', hl.postal_code ';
3961 --ship_to_postal_code
3962 END IF;
3963
3964 IF g_delivery_visible = 'T'
3965 THEN
3966 l_select_outbound := l_select_outbound || ', wnd.name ';
3967 --delivery
3968 END IF;
3969
3970 IF g_ship_method_visible = 'T' and g_delivery_visible = 'T' THEN
3971 -- 4629955 l_select_outbound := l_select_outbound || ', flv.meaning ';
3972 -- ship_method
3973 l_select_outbound :=l_select_outbound || ', INV_SHIPPING_TRANSACTION_PUB.GET_SHIPMETHOD_MEANING(decode(wda.delivery_id,NULL,wdd.ship_method_code,decode(wnd.ship_method_code,NULL,wdd.ship_method_code,wnd.ship_method_code)))'; -- 4629955
3974 --Bug#6954042
3975 ELSIF g_ship_method_visible = 'T' and g_delivery_visible = 'F' THEN
3976 l_select_outbound :=l_select_outbound || ', INV_SHIPPING_TRANSACTION_PUB.GET_SHIPMETHOD_MEANING(wdd.ship_method_code)';
3977 ELSIF g_ship_method_visible = 'F' and g_delivery_visible = 'T' THEN
3978 NULL;
3979 ELSIF g_ship_method_visible = 'F' and g_delivery_visible = 'F' THEN
3980 NULL;
3981 --Bug#6954042
3982 END IF;
3983
3984 -- 4629955 l_select_outbound := l_select_outbound || ', wdd.carrier_id ';
3985 --carrier_id
3986 --Bug#6954042
3987 --l_select_outbound := l_select_outbound || ', Decode(wda.delivery_id, NULL, wdd.carrier_id, Decode(wnd.carrier_id,NULL, wdd.carrier_id, wnd.carrier_id))';
3988 IF g_delivery_visible = 'T'
3989 THEN
3990 l_select_outbound := l_select_outbound || ', Decode(wda.delivery_id, NULL, wdd.carrier_id, Decode(wnd.carrier_id,NULL, wdd.carrier_id, wnd.carrier_id))';
3991 ELSE
3992 l_select_outbound := l_select_outbound || ', wdd.carrier_id ';
3993 END IF;
3994 --Bug#6954042
3995
3996 IF g_carrier_visible = 'T' and g_delivery_visible = 'T'
3997 THEN
3998 --4629955 l_select_outbound := l_select_outbound || ', wc.freight_code ';
3999 --carrier
4000 l_select_outbound := l_select_outbound || ',INV_SHIPPING_TRANSACTION_PUB.GET_FREIGHT_CODE(Decode(wda.delivery_id,NULL,wdd.carrier_id,Decode(wnd.carrier_id,NULL,wdd.carrier_id,wnd.carrier_id)))';
4001 --Bug#6954042
4002 ELSIF g_carrier_visible = 'T' and g_delivery_visible = 'F' THEN
4003 l_select_outbound := l_select_outbound || ', INV_SHIPPING_TRANSACTION_PUB.GET_FREIGHT_CODE(wdd.carrier_id)';
4004 ELSIF g_carrier_visible = 'F' and g_delivery_visible = 'T' THEN
4005 NULL;
4006 ELSIF g_carrier_visible = 'F' and g_delivery_visible = 'F' THEN
4007 NULL;
4008 --Bug#6954042
4009 END IF;
4010
4011 l_select_outbound := l_select_outbound || ', wdd.date_scheduled ';
4012 --shipment_date
4013 l_select_outbound :=
4014 l_select_outbound || ', wdd.shipment_priority_code ';
4015 --shipment_priority
4016 l_select_outbound :=
4017 l_select_outbound || ', wdd.source_header_number ';
4018 --source_header
4019 l_select_outbound := l_select_outbound || ', wdd.source_line_number ';
4020 --line_number
4021 if WMS_CONTROL.G_CURRENT_RELEASE_LEVEL >= 120001 then
4022 -- For R12.1 OTM integration project
4023 l_select_outbound := l_select_outbound || ', wdd.load_seq_number ';
4024 -- load_seq_number
4025 end if;
4026 END IF;
4027
4028 l_from_generic :=
4029 get_generic_from (p_is_queued => l_is_queued,
4030 p_is_dispatched => l_is_dispatched,
4031 p_is_active => l_is_active,
4032 p_is_loaded => l_is_loaded,
4033 p_is_completed => l_is_completed,
4034 p_item_category_id => p_item_category_id,
4035 p_category_set_id => p_category_set_id
4036 );
4037 l_where_generic :=
4038 get_generic_where
4039 (p_add => p_add,
4040 p_organization_id => p_organization_id,
4041 p_subinventory_code => p_subinventory_code,
4042 p_locator_id => p_locator_id,
4043 p_to_subinventory_code => p_to_subinventory_code,
4044 p_to_locator_id => p_to_locator_id,
4045 p_inventory_item_id => p_inventory_item_id,
4046 p_category_set_id => p_category_set_id,
4047 p_item_category_id => p_item_category_id,
4048 p_person_id => p_person_id,
4049 p_person_resource_id => p_person_resource_id,
4050 p_equipment_type_id => p_equipment_type_id,
4051 p_machine_resource_id => p_machine_resource_id,
4052 p_machine_instance => p_machine_instance,
4053 p_user_task_type_id => p_user_task_type_id,
4054 p_from_task_quantity => p_from_task_quantity,
4055 p_to_task_quantity => p_to_task_quantity,
4056 p_from_task_priority => p_from_task_priority,
4057 p_to_task_priority => p_to_task_priority,
4058 p_from_creation_date => p_from_creation_date,
4059 p_to_creation_date => p_to_creation_date,
4060 p_is_unreleased => l_is_unreleased,
4061 p_is_pending => l_is_pending,
4062 p_is_queued => l_is_queued,
4063 p_is_dispatched => l_is_dispatched,
4064 p_is_active => l_is_active,
4065 p_is_loaded => l_is_loaded,
4066 p_is_completed => l_is_completed,
4067 p_outbound_tasks_cycle => l_outbound_tasks_cycle, -- bug #4661615
4068 -- R12: Additional query criteria
4069 p_item_type_code => p_item_type_code,
4070 p_age_uom_code => p_age_uom_code,
4071 p_age_min => p_age_min,
4072 p_age_max => p_age_max
4073 );
4074 -- Build the outbound from section of the query
4075 --Change
4076 --l_from_outbound := ', wsh_delivery_details wdd ';
4077 l_from_outbound := ', wsh_delivery_details_ob_grp_v wdd ';
4078
4079 -- End of change
4080
4081 if (i =1) then/*3455109 we will no longer use mso for completed tasks*/
4082 IF p_from_sales_order_id IS NOT NULL
4083 THEN
4084 l_from_outbound := l_from_outbound || ', mtl_sales_orders mso1 ';
4085 END IF;
4086
4087 IF p_to_sales_order_id IS NOT NULL
4088 THEN
4089 l_from_outbound := l_from_outbound || ', mtl_sales_orders mso2 ';
4090 END IF;
4091 END IF;
4092
4093 IF g_customer_visible = 'T' OR p_customer_category IS NOT NULL
4094 THEN
4095 l_from_outbound := l_from_outbound || ', hz_parties hp ';
4096 l_from_outbound := l_from_outbound || ', hz_cust_accounts hca ';
4097 END IF;
4098
4099 --Start of fix for 4629955
4100 /* IF g_carrier_visible = 'T'
4101 THEN
4102 l_from_outbound := l_from_outbound || ', wsh_carriers wc ';
4103 END IF;
4104
4105 IF g_ship_method_visible = 'T'
4106 THEN
4107 l_from_outbound :=
4108 l_from_outbound || ', fnd_lookup_values_vl flv ';
4109 END IF;
4110 */
4111 --End of fix for 4629955
4112
4113 IF p_trip_id IS NOT NULL
4114 THEN
4115 --Change
4116 /*l_from_outbound := l_from_outbound || ', wsh_trips wt, wsh_trip_stops wts ';
4117 l_from_outbound := l_from_outbound || ', wsh_delivery_legs wdl, wsh_new_deliveries wnd ';
4118 l_from_outbound := l_from_outbound || ', wsh_delivery_assignments wda '; */
4119 l_from_outbound :=
4120 l_from_outbound
4121 || ', wsh_trips_ob_grp_v wt, wsh_trip_stops_ob_grp_v wts ';
4122 l_from_outbound :=
4123 l_from_outbound
4124 || ', wsh_delivery_legs_ob_grp_v wdl, wsh_new_deliveries_ob_grp_v wnd ';
4125 l_from_outbound :=
4126 l_from_outbound || ', wsh_delivery_assignments wda ';
4127 --End of change
4128 ELSIF p_delivery_id IS NOT NULL
4129 THEN
4130 l_from_outbound :=
4131 l_from_outbound || ', wsh_delivery_assignments wda ';
4132 END IF;
4133
4134 IF g_delivery_visible = 'T' AND p_trip_id IS NULL
4135 THEN
4136 --Change
4137 --l_from_outbound := l_from_outbound || ', wsh_new_deliveries wnd ';
4138 l_from_outbound :=
4139 l_from_outbound || ', wsh_new_deliveries_ob_grp_v wnd ';
4140
4141 -- End of change
4142 IF p_delivery_id IS NULL
4143 THEN
4144 l_from_outbound :=
4145 l_from_outbound || ', wsh_delivery_assignments wda ';
4146 END IF;
4147 END IF;
4148
4149 IF p_ship_to_state IS NOT NULL
4150 OR p_ship_to_country IS NOT NULL
4151 OR p_ship_to_postal_code IS NOT NULL
4152 OR g_ship_to_country_visible = 'T'
4153 OR g_ship_to_state_visible = 'T'
4154 OR g_ship_to_postal_code_visible = 'T'
4155 THEN
4156 l_from_outbound := l_from_outbound || ', hz_locations hl ';
4157 END IF;
4158
4159 IF p_from_number_of_order_lines IS NOT NULL
4160 OR p_to_number_of_order_lines IS NOT NULL
4161 THEN
4162 l_from_outbound :=
4163 l_from_outbound
4164 || ', (SELECT COUNT(line_id) line_sum, header_id FROM oe_order_lines_all ';
4165
4166 IF p_customer_id IS NOT NULL
4167 THEN
4168 l_from_outbound :=
4169 l_from_outbound || ' WHERE sold_to_org_id = :customer_id ';
4170 END IF;
4171
4172 l_from_outbound :=
4173 l_from_outbound || ' GROUP BY header_id) oolac ';
4174 END IF;
4175
4176 IF i = 1
4177 THEN -- Non Completed tasks
4178 -- Build the outbound where section of the query
4179 l_where_outbound := 'AND mmtt.transaction_action_id = 28 ';
4180
4181 IF (p_include_internal_orders AND NOT p_include_sales_orders
4182 )
4183 OR (NOT p_include_internal_orders AND p_include_sales_orders)
4184 THEN
4185 l_where_outbound :=
4186 l_where_outbound
4187 || 'AND mmtt.transaction_source_type_id = :source_type_id ';
4188 END IF;
4189
4190 IF p_from_sales_order_id IS NOT NULL
4191 THEN
4192 l_where_outbound :=
4193 l_where_outbound
4194 || 'AND mso1.sales_order_id = :from_sales_order_id ';
4195 l_where_outbound :=
4196 l_where_outbound
4197 || 'AND to_number(wdd.source_header_number) >= to_number(mso1.segment1) ';
4198 l_where_outbound :=
4199 l_where_outbound
4200 || 'AND wdd.source_header_type_name >= mso1.segment2 ';
4201 END IF;
4202
4203 IF p_to_sales_order_id IS NOT NULL
4204 THEN
4205 l_where_outbound :=
4206 l_where_outbound
4207 || 'AND mso2.sales_order_id = :to_sales_order_id ';
4208 l_where_outbound :=
4209 l_where_outbound
4210 || 'AND to_number(wdd.source_header_number) <= to_number(mso2.segment1) ';
4211 l_where_outbound :=
4212 l_where_outbound
4213 || 'AND wdd.source_header_type_name <= mso2.segment2 ';
4214 END IF;
4215
4216 IF p_from_pick_slip_number IS NOT NULL
4217 THEN
4218 l_where_outbound :=
4219 l_where_outbound
4220 || 'AND mmtt.pick_slip_number >= :from_pick_slip_number ';
4221 END IF;
4222
4223 IF p_to_pick_slip_number IS NOT NULL
4224 THEN
4225 l_where_outbound :=
4226 l_where_outbound
4227 || 'AND mmtt.pick_slip_number <= :to_pick_slip_number ';
4228 END IF;
4229
4230 l_where_outbound := l_where_outbound || 'AND mmtt.move_order_line_id = wdd.move_order_line_id ';
4231 l_where_outbound := l_where_outbound || 'AND wdd.delivery_detail_id = (select delivery_detail_id from wsh_delivery_details_ob_grp_v ';
4232 l_where_outbound := l_where_outbound || ' where mmtt.trx_source_line_id = source_line_id ';
4233 l_where_outbound := l_where_outbound || ' and mmtt.move_order_line_id = move_order_line_id ';
4234 l_where_outbound := l_where_outbound || ' and rownum < 2) ';
4235 ELSE -- Completed tasks
4236 -- Build the outbound where section of the query
4237 l_where_outbound := 'AND mmt.transaction_action_id = 28 ';
4238
4239 IF (p_include_internal_orders AND NOT p_include_sales_orders
4240 )
4241 OR (NOT p_include_internal_orders AND p_include_sales_orders)
4242 THEN
4243 l_where_outbound :=
4244 l_where_outbound
4245 || 'AND mmt.transaction_source_type_id = :source_type_id ';
4246 END IF;
4247
4248 /*Logic if L_is_range_so then we need to add the greater than or less
4249 than but change it to bind rather than from mso 3455109 else use equals*/
4250 IF(l_is_range_so) then
4251 IF p_from_sales_order_id IS NOT NULL
4252 THEN
4253 -- 3455109 l_where_outbound := l_where_outbound || 'AND mso1.sales_order_id = :from_sales_order_id ';
4254 l_where_outbound := l_where_outbound || ' AND lpad(wdd.source_header_number,40) >= :l_from_tonum_mso_seg1 ';
4255 l_where_outbound := l_where_outbound || ' AND wdd.source_header_type_name >= :l_from_mso_seg2 ';
4256 END IF;
4257
4258 IF p_to_sales_order_id IS NOT NULL
4259 THEN
4260 -- 3455109 l_where_outbound := l_where_outbound || 'AND mso2.sales_order_id = :to_sales_order_id ';
4261 l_where_outbound := l_where_outbound || 'AND lpad(wdd.source_header_number,40) <= :l_to_tonum_mso_seg1 ';
4262 l_where_outbound := l_where_outbound || 'AND wdd.source_header_type_name <= :l_to_mso_seg2 ';
4263 END IF;
4264 ELSE
4265 l_where_outbound := l_where_outbound || 'AND (wdd.source_header_number) = :l_from_mso_seg1 ';
4266 l_where_outbound := l_where_outbound || 'AND wdd.source_header_type_name = :l_from_mso_seg2 ';
4267 END IF;/*end of range or not range so 3455109*/
4268
4269
4270
4271 IF p_from_pick_slip_number IS NOT NULL
4272 THEN
4273 l_where_outbound := l_where_outbound || 'AND mmt.pick_slip_number >= :from_pick_slip_number ';
4274 END IF;
4275
4276 IF p_to_pick_slip_number IS NOT NULL
4277 THEN
4278 l_where_outbound := l_where_outbound || 'AND mmt.pick_slip_number <= :to_pick_slip_number ';
4279 END IF;
4280
4281 -- bug #4661615
4282 /* Bug 5601349 Commented the below lines, hence reverted the changes done in 4661615 */
4283 /*
4284 l_where_outbound := l_where_outbound || 'AND wdd.released_status IN (''Y'', ''C'') ';
4285 l_where_outbound := l_where_outbound || 'AND wdd.container_flag = ''N'' ';
4286 l_where_outbound := l_where_outbound || 'AND wdd.move_order_line_id = mmt.move_order_line_id ';
4287
4288 -- Following two lines are added for Bugfix #4891668
4289 l_where_outbound := l_where_outbound || 'AND wdd.transaction_id = mmt.transaction_id ';
4290 l_where_outbound := l_where_outbound || 'AND wdd.source_line_id = mmt.trx_source_line_id '; */
4291 /* End of Bug 5601349 */
4292
4293 -- This code does not add any restrictions since the join
4294 -- between move order line and source line id are already done
4295 -- outside this subquery. This is redundant code.
4296 /* l_where_outbound := l_where_outbound || 'AND EXISTS ( SELECT 1 ';
4297 l_where_outbound := l_where_outbound || ' FROM wsh_delivery_details wdd2 ';
4298 l_where_outbound := l_where_outbound || ' WHERE mmt.trx_source_line_id = wdd2.source_line_id ';
4299 l_where_outbound := l_where_outbound || ' AND wdd2.delivery_detail_id = wdd.delivery_detail_id ) ';
4300 */
4301 -- End of Code Bugfix #4891668
4302
4303 l_where_outbound := l_where_outbound || ' and mmt.transaction_id = wdd.transaction_id '; -- for bug 5933053
4304
4305 /* Bug 5601349 */
4306 /* These lines were commented out in bug fix of 4661615 */
4307 l_where_outbound := l_where_outbound || 'AND wdd.delivery_detail_id = (select delivery_detail_id from wsh_delivery_details ';
4308 l_where_outbound := l_where_outbound || ' where mmt.trx_source_line_id = source_line_id ';
4309 l_where_outbound := l_where_outbound || ' and mmt.transaction_id = transaction_id '; /* Added in Bug Fix 5601349 */
4310 -- bug 3781535
4311 l_where_outbound := l_where_outbound || ' and released_status in (''Y'', ''C'') ';
4312 -- bug 3888926, 3896871
4313 l_where_outbound := l_where_outbound || ' and container_flag = ''N'' ';
4314 l_where_outbound := l_where_outbound || ' and move_order_line_id = mmt.move_order_line_id ';
4315 l_where_outbound := l_where_outbound || ' and rownum < 2) ';
4316 /* End of Bug 5601349 */
4317
4318 END IF;
4319
4320 IF p_customer_id IS NOT NULL
4321 THEN
4322 l_where_outbound :=
4323 l_where_outbound || 'AND wdd.customer_id = :customer_id ';
4324 END IF;
4325
4326 IF g_customer_visible = 'T' OR p_customer_category IS NOT NULL
4327 THEN
4328 l_where_outbound :=
4329 l_where_outbound || 'AND hca.party_id = hp.party_id ';
4330
4331 l_where_outbound :=
4332 l_where_outbound || 'AND wdd.customer_id = hca.cust_account_id ';
4333 /* Bug 6069381:wdd.customer_id is not always same as hp.party_id.
4334 It is same as hca.cust_account_id and that is take care in the
4335 above statement.*/
4336 /*l_where_outbound :=
4337 l_where_outbound || 'AND wdd.customer_id = hp.party_id ';*/
4338
4339 IF p_customer_category IS NOT NULL
4340 THEN
4341 l_where_outbound :=
4342 l_where_outbound
4343 || 'AND hca.customer_class_code = :customer_category ';
4344 END IF;
4345 END IF;
4346
4347 --Start of fix for 4629955
4348 /* IF g_carrier_visible = 'T'
4349 THEN
4350 l_where_outbound :=
4351 l_where_outbound || 'AND wdd.carrier_id = wc.carrier_id(+) ';
4352 END IF;
4353
4354 IF g_ship_method_visible = 'T'
4355 THEN
4356 l_where_outbound :=
4357 l_where_outbound
4358 || 'AND flv.lookup_code(+) = wdd.ship_method_code ';
4359 l_where_outbound :=
4360 l_where_outbound || 'AND flv.lookup_type(+) = ''SHIP_METHOD'' ';
4361 l_where_outbound :=
4362 l_where_outbound
4363 || 'AND nvl(flv.start_date_active(+), sysdate) <= sysdate ';
4364 l_where_outbound :=
4365 l_where_outbound
4366 || 'AND nvl(flv.end_date_active(+), sysdate) >= sysdate ';
4367 l_where_outbound :=
4368 l_where_outbound || 'AND flv.view_application_id(+) = 3 ';
4369 END IF;
4370 */
4371 -- End of fix for 4629955
4372
4373 IF p_carrier_id IS NOT NULL --bugfix 4629955
4374 THEN
4375 l_where_outbound :=
4376 l_where_outbound || 'AND nvl(wnd.carrier_id,wdd.carrier_id) = :carrier_id ';
4377 END IF;
4378
4379 IF p_ship_method IS NOT NULL --bugfix 4629955
4380 THEN
4381 l_where_outbound :=
4382 l_where_outbound || 'AND nvl(wnd.ship_method_code,wdd.ship_method_code) = :ship_method ';
4383 END IF;
4384
4385 IF p_order_type_id IS NOT NULL
4386 THEN
4387 l_where_outbound :=
4388 l_where_outbound || 'AND wdd.source_header_type_id = :p_order_type_id ';
4389 END IF;
4390
4391 IF p_shipment_priority IS NOT NULL
4392 THEN
4393 l_where_outbound :=
4394 l_where_outbound
4395 || 'AND wdd.shipment_priority_code = :shipment_priority ';
4396 END IF;
4397
4398 IF p_from_shipment_date IS NOT NULL
4399 THEN
4400 l_where_outbound :=
4401 l_where_outbound
4402 || 'AND wdd.date_scheduled >= :from_shipment_date ';
4403 END IF;
4404
4405 IF p_to_shipment_date IS NOT NULL
4406 THEN
4407 l_where_outbound :=
4408 l_where_outbound
4409 || 'AND wdd.date_scheduled <= :to_shipment_date ';
4410 END IF;
4411
4412 -- R12: Additional Query criteria using age of the task
4413 IF p_time_till_shipment_uom_code IS NOT NULL
4414 THEN
4415
4416 IF p_time_till_shipment_uom_code = 2 THEN -- Minutes
4417 n := '*(24 * 60)';
4418 ELSIF p_time_till_shipment_uom_code = 3 THEN -- Hours
4419 n := '*(24)';
4420 ELSIF p_time_till_shipment_uom_code = 4 THEN -- Days
4421 n := '*(1)';
4422 ELSIF p_time_till_shipment_uom_code = 5 THEN -- Weeks
4423 n := '/(7)';
4424 ELSIF p_time_till_shipment_uom_code = 6 THEN -- Months
4425 n := '/(7 * 31)';
4426 END IF;
4427
4428 IF p_time_till_shipment IS NOT NULL
4429 THEN
4430 l_where_generic :=
4431 l_where_generic
4432 || 'AND (wdd.date_scheduled - sysdate)'||n||' BETWEEN 0 AND :p_time_till_shipment ';
4433 END IF;
4434 END IF;
4435
4436 IF p_trip_id IS NOT NULL OR p_delivery_id IS NOT NULL
4437 THEN
4438 IF p_trip_id IS NOT NULL
4439 THEN
4440 l_where_outbound :=
4441 l_where_outbound || 'AND wt.trip_id = :trip_id ';
4442 l_where_outbound :=
4443 l_where_outbound || 'AND wt.trip_id = wts.trip_id ';
4444 l_where_outbound :=
4445 l_where_outbound
4446 || 'AND wdl.pick_up_stop_id = wts.stop_id ';
4447 l_where_outbound :=
4448 l_where_outbound
4449 || 'AND wnd.delivery_id = wdl.delivery_id ';
4450 l_where_outbound :=
4451 l_where_outbound
4452 || 'AND wnd.delivery_id = wda.delivery_id ';
4453 END IF;
4454
4455 l_where_outbound :=
4456 l_where_outbound
4457 || 'AND wdd.delivery_detail_id = wda.delivery_detail_id ';
4458
4459 IF p_delivery_id IS NOT NULL
4460 THEN
4461 l_where_outbound :=
4462 l_where_outbound || 'AND wda.delivery_id = :delivery_id ';
4463 END IF;
4464 END IF;
4465
4466 IF g_delivery_visible = 'T' AND p_trip_id IS NULL
4467 THEN
4468 IF p_delivery_id IS NULL
4469 THEN
4470 l_where_outbound :=
4471 l_where_outbound
4472 || 'AND wdd.delivery_detail_id = wda.delivery_detail_id(+) ';
4473 END IF;
4474
4475 l_where_outbound :=
4476 l_where_outbound || 'AND wnd.delivery_id(+) = wda.delivery_id ';
4477 END IF;
4478
4479 IF p_ship_to_state IS NOT NULL
4480 OR p_ship_to_country IS NOT NULL
4481 OR p_ship_to_postal_code IS NOT NULL
4482 OR g_ship_to_country_visible = 'T'
4483 OR g_ship_to_state_visible = 'T'
4484 OR g_ship_to_postal_code_visible = 'T'
4485 THEN
4486 l_where_outbound :=
4487 l_where_outbound
4488 || 'AND wdd.ship_to_location_id = hl.location_id ';
4489
4490 IF p_ship_to_state IS NOT NULL
4491 THEN
4492 l_where_outbound :=
4493 l_where_outbound || 'AND hl.state = :ship_to_state ';
4494 END IF;
4495
4496 IF p_ship_to_country IS NOT NULL
4497 THEN
4498 l_where_outbound :=
4499 l_where_outbound || 'AND hl.country = :ship_to_country ';
4500 END IF;
4501
4502 IF p_ship_to_postal_code IS NOT NULL
4503 THEN
4504 l_where_outbound :=
4505 l_where_outbound
4506 || 'AND hl.postal_code = :ship_to_postal_code ';
4507 END IF;
4508 END IF;
4509
4510 IF p_from_number_of_order_lines IS NOT NULL
4511 OR p_to_number_of_order_lines IS NOT NULL
4512 THEN
4513 IF p_from_number_of_order_lines IS NOT NULL
4514 THEN
4515 l_where_outbound :=
4516 l_where_outbound
4517 || 'AND oolac.line_sum >= :from_number_of_order_lines ';
4518 END IF;
4519
4520 IF p_to_number_of_order_lines IS NOT NULL
4521 THEN
4522 l_where_outbound :=
4523 l_where_outbound
4524 || 'AND oolac.line_sum <= :to_number_of_order_lines ';
4525 END IF;
4526
4527 l_where_outbound :=
4528 l_where_outbound
4529 || 'AND oolac.header_id = wdd.source_header_id ';
4530 END IF;
4531
4532 -- R12: Additional Query criteria using time till dock door appointment
4533 IF p_time_till_appt_uom_code IS NOT NULL
4534 THEN
4535
4536 IF p_time_till_appt_uom_code = 2 THEN -- Minutes
4537 n := '*(24 * 60)';
4538 ELSIF p_time_till_appt_uom_code = 3 THEN -- Hours
4539 n := '*(24)';
4540 ELSIF p_time_till_appt_uom_code = 4 THEN -- Days
4541 n := '*(1)';
4542 ELSIF p_time_till_appt_uom_code = 5 THEN -- Weeks
4543 n := '/(7)';
4544 ELSIF p_time_till_appt_uom_code = 6 THEN -- Months
4545 n := '/(7 * 31)';
4546 END IF;
4547
4548 IF p_time_till_appt IS NOT NULL
4549 THEN
4550 l_where_generic :=
4551 l_where_generic
4552 || 'AND EXISTS (SELECT 1 FROM '||
4553 'WMS_DOCK_APPOINTMENTS_B WDAB, '||
4554 'WSH_DELIVERY_LEGS WDL '||
4555 'WHERE '||
4556 'WDAB.TRIP_STOP = WDL.PICK_UP_STOP_ID AND '||
4557 'WDL.DELIVERY_ID = WDA.DELIVERY_ID AND '||
4558 'WDAB.APPOINTMENT_TYPE = 2 AND '|| -- OUTBOUND appt
4559 '(WDAB.START_TIME - sysdate)'||n||' BETWEEN 0 AND :p_time_till_appt) ';
4560
4561 END IF;
4562 END IF;
4563
4564 IF p_summary_mode = 1 THEN
4565 IF i = 1 THEN
4566 l_where_outbound := l_where_outbound || ' GROUP BY mmtt.wms_task_type ';
4567 ELSE
4568 l_where_outbound := l_where_outbound || ' GROUP BY wdth.task_type ';
4569 END IF;
4570 END IF;
4571 -- Execute the Outbound query
4572
4573 -- Concatenate the different sections of the query
4574 l_query :=
4575 l_insert_query
4576 || l_select_generic
4577 || l_select_outbound
4578 || l_from_generic
4579 || l_from_outbound
4580 || l_where_generic
4581 || l_where_outbound;
4582 -- Parse, Bind and Execute the dynamic query
4583
4584 IF l_debug = 1 then
4585 debug('l_query ' || l_query,'query_outbound_tasks');
4586 END IF;
4587
4588 l_query_handle := DBMS_SQL.open_cursor;
4589 DBMS_SQL.parse (l_query_handle, l_query, DBMS_SQL.native);
4590
4591 IF p_organization_id IS NOT NULL
4592 THEN
4593 DBMS_SQL.bind_variable (l_query_handle,
4594 'org_id',
4595 p_organization_id
4596 );
4597 END IF;
4598
4599 IF p_subinventory_code IS NOT NULL
4600 THEN
4601 DBMS_SQL.bind_variable (l_query_handle,
4602 'sub_code',
4603 p_subinventory_code
4604 );
4605 END IF;
4606
4607 IF p_locator_id IS NOT NULL
4608 THEN
4609 DBMS_SQL.bind_variable (l_query_handle, 'loc_id', p_locator_id);
4610 END IF;
4611
4612 IF p_to_subinventory_code IS NOT NULL
4613 THEN
4614 DBMS_SQL.bind_variable (l_query_handle,
4615 'to_sub_code',
4616 p_to_subinventory_code
4617 );
4618 END IF;
4619
4620 IF p_to_locator_id IS NOT NULL
4621 THEN
4622 DBMS_SQL.bind_variable (l_query_handle,
4623 'to_loc_id',
4624 p_to_locator_id
4625 );
4626 END IF;
4627
4628 IF p_inventory_item_id IS NOT NULL
4629 THEN
4630 DBMS_SQL.bind_variable (l_query_handle,
4631 'item_id',
4632 p_inventory_item_id
4633 );
4634 END IF;
4635
4636 -- R12 : Additional Query Criteria using item type
4637 IF p_item_type_code IS NOT NULL
4638 THEN
4639 DBMS_SQL.bind_variable (l_query_handle,
4640 'item_type_code',
4641 p_item_type_code
4642 );
4643 END IF;
4644
4645 IF p_category_set_id IS NOT NULL
4646 THEN
4647 DBMS_SQL.bind_variable (l_query_handle,
4648 'category_set_id',
4649 p_category_set_id
4650 );
4651 END IF;
4652
4653 IF p_item_category_id IS NOT NULL
4654 THEN
4655 DBMS_SQL.bind_variable (l_query_handle,
4656 'item_category_id',
4657 p_item_category_id
4658 );
4659 END IF;
4660
4661 -- Bug #4459382
4662 -- Bind the employee criterion only if its not pending/unreleased tasks case
4663 IF (i=1 AND (p_is_queued OR p_is_dispatched OR p_is_loaded OR p_is_active))
4664 OR
4665 (i=2 AND (p_is_completed OR p_is_queued OR p_is_dispatched OR p_is_loaded OR p_is_active))
4666 THEN
4667
4668 IF p_person_id IS NOT NULL
4669 THEN
4670 DBMS_SQL.bind_variable (l_query_handle, 'person_id', p_person_id);
4671 END IF;
4672
4673 IF p_person_resource_id IS NOT NULL
4674 THEN
4675 DBMS_SQL.bind_variable (l_query_handle,
4676 'person_resource_id',
4677 p_person_resource_id
4678 );
4679 END IF;
4680
4681 IF p_equipment_type_id IS NOT NULL
4682 THEN
4683 DBMS_SQL.bind_variable (l_query_handle,
4684 'equipment_type_id',
4685 p_equipment_type_id
4686 );
4687 END IF;
4688
4689 IF p_machine_resource_id IS NOT NULL
4690 THEN
4691 DBMS_SQL.bind_variable (l_query_handle,
4692 'machine_resource_id',
4693 p_machine_resource_id
4694 );
4695 END IF;
4696
4697 IF p_machine_instance IS NOT NULL
4698 THEN
4699 DBMS_SQL.bind_variable (l_query_handle,
4700 'machine_instance',
4701 p_machine_instance
4702 );
4703 END IF;
4704 END IF;--4459382
4705
4706 IF p_user_task_type_id IS NOT NULL
4707 THEN
4708 DBMS_SQL.bind_variable (l_query_handle,
4709 'user_task_type_id',
4710 p_user_task_type_id
4711 );
4712 END IF;
4713
4714 IF p_from_task_quantity IS NOT NULL
4715 THEN
4716 DBMS_SQL.bind_variable (l_query_handle,
4717 'from_task_quantity',
4718 p_from_task_quantity
4719 );
4720 END IF;
4721
4722 IF p_to_task_quantity IS NOT NULL
4723 THEN
4724 DBMS_SQL.bind_variable (l_query_handle,
4725 'to_task_quantity',
4726 p_to_task_quantity
4727 );
4728 END IF;
4729
4730 IF p_from_task_priority IS NOT NULL
4731 THEN
4732 DBMS_SQL.bind_variable (l_query_handle,
4733 'from_task_priority',
4734 p_from_task_priority
4735 );
4736 END IF;
4737
4738 IF p_to_task_priority IS NOT NULL
4739 THEN
4740 DBMS_SQL.bind_variable (l_query_handle,
4741 'to_task_priority',
4742 p_to_task_priority
4743 );
4744 END IF;
4745
4746 IF p_from_creation_date IS NOT NULL
4747 THEN
4748 DBMS_SQL.bind_variable (l_query_handle,
4749 'from_creation_date',
4750 -- p_from_creation_date --commented in 6868286
4751 TRUNC(p_from_creation_date) --added in 6868286
4752 );
4753 END IF;
4754
4755 IF p_to_creation_date IS NOT NULL
4756 THEN
4757 DBMS_SQL.bind_variable (l_query_handle,
4758 'to_creation_date',
4759 --p_to_creation_date --commented in 6868286
4760 TRUNC(p_to_creation_date) --added in 6868286
4761 );
4762 END IF;
4763
4764 -- R12: Additional Query criteria using age of the task
4765 IF p_age_uom_code IS NOT NULL
4766 THEN
4767
4768 IF p_age_min IS NOT NULL
4769 THEN
4770 DBMS_SQL.bind_variable (l_query_handle,
4771 'age_min',
4772 p_age_min
4773 );
4774 END IF;
4775
4776 IF p_age_max IS NOT NULL
4777 THEN
4778 DBMS_SQL.bind_variable (l_query_handle,
4779 'age_max',
4780 p_age_max
4781 );
4782
4783 END IF;
4784 END IF;
4785
4786 IF p_include_internal_orders AND NOT p_include_sales_orders
4787 THEN
4788 DBMS_SQL.bind_variable (l_query_handle, 'source_type_id', 8);
4789 ELSIF NOT p_include_internal_orders AND p_include_sales_orders
4790 THEN
4791 DBMS_SQL.bind_variable (l_query_handle, 'source_type_id', 2);
4792 END IF;
4793
4794 /*added if else for 3455109 since we are changing the query also need to change binds if its for completed task*/
4795 IF (i=1) /*old code*/ then
4796
4797 IF p_from_sales_order_id IS NOT NULL
4798 THEN
4799 DBMS_SQL.bind_variable (l_query_handle,
4800 'from_sales_order_id',
4801 p_from_sales_order_id
4802 );
4803 END IF;
4804
4805 IF p_to_sales_order_id IS NOT NULL
4806 THEN
4807 DBMS_SQL.bind_variable (l_query_handle,
4808 'to_sales_order_id',
4809 p_to_sales_order_id
4810 );
4811 END IF;
4812 ELSE --completed tasks
4813 IF(l_is_range_so) then
4814 IF p_from_sales_order_id IS NOT NULL THEN
4815 --3240261 dbms_sql.bind_variable(l_query_handle, 'from_sales_order_id', p_from_sales_order_id);
4816 dbms_sql.bind_variable(l_query_handle,'l_from_tonum_mso_seg1',l_from_tonum_mso_seg1);--added for 3455109
4817 dbms_sql.bind_variable(l_query_handle,'l_from_mso_seg2',l_from_mso_seg2);--3455109
4818 END IF;
4819
4820 IF p_to_sales_order_id IS NOT NULL THEN
4821 --3420261 dbms_sql.bind_variable(l_query_handle, 'to_sales_order_id', p_to_sales_order_id);
4822 dbms_sql.bind_variable(l_query_handle,'l_to_tonum_mso_seg1',l_to_tonum_mso_seg1);
4823 dbms_sql.bind_variable(l_query_handle,'l_to_mso_seg2',l_to_mso_seg2);
4824 END IF;
4825 ELSE
4826 dbms_sql.bind_variable(l_query_handle,'l_from_mso_seg1',l_from_mso_seg1);
4827 dbms_sql.bind_variable(l_query_handle,'l_from_mso_seg2',l_from_mso_seg2);
4828 END IF;--end of range or not range so
4829 END IF;--end of copleted or not completed task 3455109
4830
4831 IF p_from_pick_slip_number IS NOT NULL
4832 THEN
4833 DBMS_SQL.bind_variable (l_query_handle,
4834 'from_pick_slip_number',
4835 p_from_pick_slip_number
4836 );
4837 END IF;
4838
4839 IF p_to_pick_slip_number IS NOT NULL
4840 THEN
4841 DBMS_SQL.bind_variable (l_query_handle,
4842 'to_pick_slip_number',
4843 p_to_pick_slip_number
4844 );
4845 END IF;
4846
4847 IF p_customer_id IS NOT NULL
4848 THEN
4849 DBMS_SQL.bind_variable (l_query_handle,
4850 'customer_id',
4851 p_customer_id
4852 );
4853 END IF;
4854
4855 IF p_customer_category IS NOT NULL
4856 THEN
4857 DBMS_SQL.bind_variable (l_query_handle,
4858 'customer_category',
4859 p_customer_category
4860 );
4861 END IF;
4862
4863 IF p_trip_id IS NOT NULL
4864 THEN
4865 DBMS_SQL.bind_variable (l_query_handle, 'trip_id', p_trip_id);
4866 END IF;
4867
4868 IF p_delivery_id IS NOT NULL
4869 THEN
4870 DBMS_SQL.bind_variable (l_query_handle,
4871 'delivery_id',
4872 p_delivery_id
4873 );
4874 END IF;
4875
4876 IF p_carrier_id IS NOT NULL
4877 THEN
4878 DBMS_SQL.bind_variable (l_query_handle,
4879 'carrier_id',
4880 p_carrier_id
4881 );
4882 END IF;
4883
4884 IF p_ship_method IS NOT NULL
4885 THEN
4886 DBMS_SQL.bind_variable (l_query_handle,
4887 'ship_method',
4888 p_ship_method
4889 );
4890 END IF;
4891
4892 IF p_order_type_id IS NOT NULL
4893 THEN
4894 DBMS_SQL.bind_variable (l_query_handle,
4895 'p_order_type_id',
4896 p_order_type_id
4897 );
4898 END IF;
4899
4900 IF p_shipment_priority IS NOT NULL
4901 THEN
4902 DBMS_SQL.bind_variable (l_query_handle,
4903 'shipment_priority',
4904 p_shipment_priority
4905 );
4906 END IF;
4907
4908 IF p_from_shipment_date IS NOT NULL
4909 THEN
4910 DBMS_SQL.bind_variable (l_query_handle,
4911 'from_shipment_date',
4912 p_from_shipment_date
4913 );
4914 END IF;
4915
4916 IF p_to_shipment_date IS NOT NULL
4917 THEN
4918 DBMS_SQL.bind_variable (l_query_handle,
4919 'to_shipment_date',
4920 p_to_shipment_date
4921 );
4922 END IF;
4923
4924 IF p_time_till_shipment IS NOT NULL AND p_time_till_shipment_uom_code IS NOT NULL
4925 THEN
4926 DBMS_SQL.bind_variable (l_query_handle,
4927 'p_time_till_shipment',
4928 p_time_till_shipment
4929 );
4930 END IF;
4931
4932 IF p_time_till_appt IS NOT NULL AND p_time_till_appt_uom_code IS NOT NULL
4933 THEN
4934 DBMS_SQL.bind_variable (l_query_handle,
4935 'p_time_till_appt',
4936 p_time_till_appt
4937 );
4938 END IF;
4939
4940
4941 IF p_ship_to_state IS NOT NULL
4942 THEN
4943 DBMS_SQL.bind_variable (l_query_handle,
4944 'ship_to_state',
4945 p_ship_to_state
4946 );
4947 END IF;
4948
4949 IF p_ship_to_country IS NOT NULL
4950 THEN
4951 DBMS_SQL.bind_variable (l_query_handle,
4952 'ship_to_country',
4953 p_ship_to_country
4954 );
4955 END IF;
4956
4957 IF p_ship_to_postal_code IS NOT NULL
4958 THEN
4959 DBMS_SQL.bind_variable (l_query_handle,
4960 'ship_to_postal_code',
4961 p_ship_to_postal_code
4962 );
4963 END IF;
4964
4965 IF p_from_number_of_order_lines IS NOT NULL
4966 THEN
4967 DBMS_SQL.bind_variable (l_query_handle,
4968 'from_number_of_order_lines',
4969 p_from_number_of_order_lines
4970 );
4971 END IF;
4972
4973 IF p_to_number_of_order_lines IS NOT NULL
4974 THEN
4975 DBMS_SQL.bind_variable (l_query_handle,
4976 'to_number_of_order_lines',
4977 p_to_number_of_order_lines
4978 );
4979 END IF;
4980
4981 IF p_summary_mode = 1 THEN
4982 DBMS_SQL.DEFINE_COLUMN(l_query_handle, 1, l_wms_task_type);
4983 DBMS_SQL.DEFINE_COLUMN(l_query_handle, 2, l_task_count);
4984 END IF;
4985
4986 l_query_count := DBMS_SQL.EXECUTE (l_query_handle);
4987 g_record_count := g_record_count + l_query_count;
4988
4989 IF p_summary_mode = 1 THEN -- fetch the rows and put them into the global tables
4990 LOOP
4991 IF DBMS_SQL.FETCH_ROWS(l_query_handle)>0 THEN
4992 DBMS_SQL.COLUMN_VALUE(l_query_handle, 1, l_wms_task_type);
4993 DBMS_SQL.COLUMN_VALUE(l_query_handle, 2, l_task_count);
4994 g_wms_task_summary_tbl(l_wms_task_type).wms_task_type := l_wms_task_type;
4995 g_wms_task_summary_tbl(l_wms_task_type).task_count := g_wms_task_summary_tbl(l_wms_task_type).task_count + l_task_count;
4996 IF l_debug = 1 then
4997 debug('Task Type :' || g_wms_task_summary_tbl(l_wms_task_type).wms_task_type, 'query_outbound_tasks');
4998 debug('TaskCount :' || g_wms_task_summary_tbl(l_wms_task_type).task_count, 'query_outbound_tasks');
4999 END IF;
5000 ELSE
5001 EXIT; -- no more rows returned from dynamic SQL
5002 END IF;
5003 END LOOP;
5004 END IF;
5005 DBMS_SQL.close_cursor(l_query_handle);
5006 END LOOP;
5007 EXCEPTION
5008 WHEN OTHERS THEN -- Bug 4150145
5009 IF dbms_sql.is_open(l_query_handle) THEN
5010 DBMS_SQL.close_cursor(l_query_handle);
5011 END IF;
5012 DEBUG (SQLERRM, 'Task_planning.query_outbound_tasks');
5013 END query_outbound_tasks;
5014
5015 PROCEDURE query_inbound_tasks (
5016 p_add BOOLEAN DEFAULT FALSE,
5017 p_organization_id NUMBER DEFAULT NULL,
5018 p_subinventory_code VARCHAR2 DEFAULT NULL,
5019 p_locator_id NUMBER DEFAULT NULL,
5020 p_to_subinventory_code VARCHAR2 DEFAULT NULL,
5021 p_to_locator_id NUMBER DEFAULT NULL,
5022 p_inventory_item_id NUMBER DEFAULT NULL,
5023 p_category_set_id NUMBER DEFAULT NULL,
5024 p_item_category_id NUMBER DEFAULT NULL,
5025 p_person_id NUMBER DEFAULT NULL,
5026 p_person_resource_id NUMBER DEFAULT NULL,
5027 p_equipment_type_id NUMBER DEFAULT NULL,
5028 p_machine_resource_id NUMBER DEFAULT NULL,
5029 p_machine_instance VARCHAR2 DEFAULT NULL,
5030 p_user_task_type_id NUMBER DEFAULT NULL,
5031 p_from_task_quantity NUMBER DEFAULT NULL,
5032 p_to_task_quantity NUMBER DEFAULT NULL,
5033 p_from_task_priority NUMBER DEFAULT NULL,
5034 p_to_task_priority NUMBER DEFAULT NULL,
5035 p_from_creation_date DATE DEFAULT NULL,
5036 p_to_creation_date DATE DEFAULT NULL,
5037 p_is_pending BOOLEAN DEFAULT FALSE,
5038 p_is_loaded BOOLEAN DEFAULT FALSE,
5039 p_is_completed BOOLEAN DEFAULT FALSE,
5040 p_from_po_header_id NUMBER DEFAULT NULL,
5041 p_to_po_header_id NUMBER DEFAULT NULL,
5042 p_from_rma_header_id NUMBER DEFAULT NULL,
5043 p_to_rma_header_id NUMBER DEFAULT NULL,
5044 p_from_requisition_header_id NUMBER DEFAULT NULL,
5045 p_to_requisition_header_id NUMBER DEFAULT NULL,
5046 p_from_shipment_number VARCHAR2 DEFAULT NULL,
5047 p_to_shipment_number VARCHAR2 DEFAULT NULL,
5048 -- R12 : Additional Query Criteria
5049 p_item_type_code VARCHAR2 DEFAULT NULL,
5050 p_age_uom_code VARCHAR2 DEFAULT NULL,
5051 p_age_min NUMBER DEFAULT NULL,
5052 p_age_max NUMBER DEFAULT NULL,
5053 p_summary_mode NUMBER DEFAULT 0
5054 -- R12 : Additional Query Criteria
5055 )
5056 IS
5057 l_insert_query VARCHAR2 (4000);
5058 l_select_generic VARCHAR2 (4000);
5059 l_from_generic VARCHAR2 (2000);
5060 l_where_generic VARCHAR2 (5000);
5061 l_from_inbound VARCHAR2 (2000);
5062 l_where_inbound VARCHAR2 (4000);
5063 l_query VARCHAR2 (10000);
5064 l_query_handle NUMBER; -- Handle for the dynamic sql
5065 l_query_count NUMBER;
5066 l_loop_start NUMBER;
5067 l_loop_end NUMBER;
5068 l_is_pending BOOLEAN;
5069 l_is_loaded BOOLEAN;
5070 l_is_completed BOOLEAN;
5071 l_wms_task_type NUMBER;
5072 l_task_count NUMBER;
5073 BEGIN
5074 -- Inbound tasks currently cannot have priorities or user task types. If user wants to
5075 -- query up tasks with certain priorities or user task types, we should not query inbound tasks.
5076 IF p_from_task_priority IS NOT NULL
5077 OR p_to_task_priority IS NOT NULL
5078 OR p_user_task_type_id IS NOT NULL
5079 THEN
5080 RETURN;
5081 END IF;
5082
5083 IF p_is_completed
5084 THEN
5085 l_loop_end := 2;
5086 ELSE
5087 l_loop_end := 1;
5088 END IF;
5089
5090 IF p_is_pending OR p_is_loaded
5091 THEN
5092 l_loop_start := 1;
5093 ELSE
5094 l_loop_start := 2;
5095 END IF;
5096
5097 FOR i IN l_loop_start .. l_loop_end
5098 LOOP
5099 l_insert_query := NULL;
5100 l_select_generic := NULL;
5101 l_from_generic := NULL;
5102 l_from_inbound := NULL;
5103 l_where_generic := NULL;
5104 l_where_inbound := NULL;
5105
5106 IF i = 1
5107 THEN -- Non completed tasks iteration
5108 l_is_pending := p_is_pending;
5109 l_is_loaded := p_is_loaded;
5110 l_is_completed := FALSE;
5111 ELSE -- Completed tasks
5112 l_is_pending := FALSE;
5113 l_is_loaded := FALSE;
5114 l_is_completed := p_is_completed;
5115 END IF;
5116
5117 -- Insert section
5118 IF p_summary_mode = 1 THEN
5119 IF i=1 THEN
5120 l_select_generic := ' SELECT mmtt.wms_task_type, count(*) ';
5121 ELSE
5122 l_select_generic := ' SELECT wdth.task_type, count(*) ';
5123 END IF;
5124 ELSE
5125 l_insert_query :=
5126 get_generic_insert (p_is_pending => l_is_pending,
5127 p_is_loaded => l_is_loaded,
5128 p_is_completed => l_is_completed
5129 );
5130 -- Inbound specific inserts
5131 l_insert_query := l_insert_query || ', reference_id ';
5132 l_insert_query := l_insert_query || ', reference ';
5133
5134 IF p_from_po_header_id IS NOT NULL
5135 OR p_to_po_header_id IS NOT NULL
5136 OR p_from_rma_header_id IS NOT NULL
5137 OR p_to_rma_header_id IS NOT NULL
5138 OR p_from_requisition_header_id IS NOT NULL
5139 OR p_to_requisition_header_id IS NOT NULL
5140 THEN
5141 l_insert_query := l_insert_query || ', source_header ';
5142 l_insert_query := l_insert_query || ', line_number ';
5143 END IF;
5144
5145 l_insert_query := l_insert_query || ') ';
5146 l_select_generic :=
5147 get_generic_select (p_is_pending => l_is_pending,
5148 p_is_loaded => l_is_loaded,
5149 p_is_completed => l_is_completed
5150 );
5151
5152 IF i = 1
5153 THEN
5154 l_select_generic := l_select_generic || ', mtrl.reference_id ';
5155 -- reference_id
5156 l_select_generic := l_select_generic || ', mtrl.reference ';
5157 -- reference
5158 ELSE
5159 -- reference
5160 l_select_generic :=
5161 l_select_generic || ', decode(rt.source_document_code, ';
5162 l_select_generic :=
5163 l_select_generic || '''INVENTORY'', rt.shipment_line_id, ';
5164 l_select_generic :=
5165 l_select_generic || '''PO'', rt.po_line_location_id, ';
5166 l_select_generic :=
5167 l_select_generic || '''REQ'', rt.shipment_line_id, ';
5168 l_select_generic :=
5169 l_select_generic || '''RMA'', rt.oe_order_line_id) ';
5170 -- reference_id
5171 l_select_generic :=
5172 l_select_generic || ', decode(rt.source_document_code, ';
5173 l_select_generic :=
5174 l_select_generic || '''INVENTORY'', ''SHIPMENT_LINE_ID'', ';
5175 l_select_generic :=
5176 l_select_generic || '''PO'', ''PO_LINE_LOCATION_ID'', ';
5177 l_select_generic :=
5178 l_select_generic || '''REQ'', ''SHIPMENT_LINE_ID'', ';
5179 l_select_generic :=
5180 l_select_generic || '''RMA'', ''ORDER_LINE_ID'') ';
5181 END IF;
5182
5183 IF p_from_po_header_id IS NOT NULL OR p_to_po_header_id IS NOT NULL
5184 THEN
5185 l_select_generic := l_select_generic || ', ph.segment1 ';
5186 -- source_header
5187 l_select_generic := l_select_generic || ', pl.line_num ';
5188 -- line_number
5189 ELSIF p_from_rma_header_id IS NOT NULL
5190 OR p_to_rma_header_id IS NOT NULL
5191 THEN
5192 l_select_generic := l_select_generic || ', ooh.order_number ';
5193 -- source_header
5194 l_select_generic := l_select_generic || ', ool.line_number ';
5195 -- line_number
5196 ELSIF p_from_requisition_header_id IS NOT NULL
5197 OR p_to_requisition_header_id IS NOT NULL
5198 THEN
5199 l_select_generic := l_select_generic || ', prh.segment1 ';
5200 -- source_header
5201 l_select_generic := l_select_generic || ', prl.line_num ';
5202 -- line_number
5203 END IF;
5204 END IF; -- p_summary_code check
5205
5206 -- Inbound secific selects, should map to the columns additionally selected above
5207 l_from_generic :=
5208 get_generic_from (p_is_loaded => l_is_loaded,
5209 p_is_completed => l_is_completed,
5210 p_item_category_id => p_item_category_id,
5211 p_category_set_id => p_category_set_id
5212 );
5213
5214 IF p_from_po_header_id IS NOT NULL OR p_to_po_header_id IS NOT NULL
5215 THEN
5216 IF i = 1
5217 THEN
5218 l_from_generic :=
5219 l_from_generic || ', po_line_locations_all pll';
5220 END IF;
5221
5222 l_from_generic := l_from_generic || ', po_headers_all ph';
5223 l_from_generic := l_from_generic || ', po_lines_all pl';
5224 ELSIF p_from_rma_header_id IS NOT NULL
5225 OR p_to_rma_header_id IS NOT NULL
5226 THEN
5227 l_from_generic := l_from_generic || ', oe_order_headers_all ooh';
5228 l_from_generic := l_from_generic || ', oe_order_lines_all ool';
5229 ELSIF p_from_requisition_header_id IS NOT NULL
5230 OR p_to_requisition_header_id IS NOT NULL
5231 THEN
5232 l_from_generic := l_from_generic || ', rcv_shipment_headers rsh';
5233 l_from_generic := l_from_generic || ', rcv_shipment_lines rsl';
5234 l_from_generic :=
5235 l_from_generic || ', po_requisition_headers_all prh';
5236 l_from_generic := l_from_generic || ', po_requisition_lines_all prl';
5237 ELSIF p_from_shipment_number IS NOT NULL
5238 OR p_to_shipment_number IS NOT NULL
5239 THEN
5240 l_from_generic := l_from_generic || ', rcv_shipment_headers rsh';
5241 l_from_generic := l_from_generic || ', rcv_shipment_lines rsl';
5242 END IF;
5243
5244 IF i = 1
5245 THEN
5246 l_from_generic :=
5247 l_from_generic || ', mtl_txn_request_headers mtrh ';
5248 l_from_generic :=
5249 l_from_generic || ', mtl_txn_request_lines mtrl ';
5250 ELSE
5251 l_from_generic := l_from_generic || ', rcv_transactions rt ';
5252 END IF;
5253
5254 l_where_generic :=
5255 get_generic_where
5256 (p_add => p_add,
5257 p_organization_id => p_organization_id,
5258 p_subinventory_code => p_subinventory_code,
5259 p_locator_id => p_locator_id,
5260 p_to_subinventory_code => p_to_subinventory_code,
5261 p_to_locator_id => p_to_locator_id,
5262 p_inventory_item_id => p_inventory_item_id,
5263 p_category_set_id => p_category_set_id,
5264 p_item_category_id => p_item_category_id,
5265 p_person_id => p_person_id,
5266 p_person_resource_id => p_person_resource_id,
5267 p_equipment_type_id => p_equipment_type_id,
5268 p_machine_resource_id => p_machine_resource_id,
5269 p_machine_instance => p_machine_instance,
5270 p_from_task_quantity => p_from_task_quantity,
5271 p_to_task_quantity => p_to_task_quantity,
5272 p_from_creation_date => p_from_creation_date,
5273 p_to_creation_date => p_to_creation_date,
5274 p_is_pending => l_is_pending,
5275 p_is_loaded => l_is_loaded,
5276 p_is_completed => l_is_completed,
5277 -- R12: Additional query criteria
5278 p_item_type_code => p_item_type_code,
5279 p_age_uom_code => p_age_uom_code,
5280 p_age_min => p_age_min,
5281 p_age_max => p_age_max
5282 );
5283
5284 IF i = 1
5285 THEN
5286 l_where_generic :=
5287 l_where_generic || ' AND mtrh.header_id = mtrl.header_id ';
5288 l_where_generic :=
5289 l_where_generic || ' AND mtrh.move_order_type = 6 ';
5290 l_where_generic :=
5291 l_where_generic
5292 || ' AND mmtt.move_order_line_id = mtrl.line_id ';
5293
5294 IF NOT ( p_from_po_header_id IS NOT NULL
5295 OR p_to_po_header_id IS NOT NULL
5296 OR p_from_rma_header_id IS NOT NULL
5297 OR p_to_rma_header_id IS NOT NULL
5298 OR p_from_requisition_header_id IS NOT NULL
5299 OR p_to_requisition_header_id IS NOT NULL
5300 )
5301 THEN
5302 l_where_generic :=
5303 l_where_generic
5304 || ' AND mtrl.reference in (''PO_LINE_LOCATION_ID'', ''ORDER_LINE_ID'', ''SHIPMENT_LINE_ID'') ';
5305 END IF;
5306 ELSE
5307 l_where_generic :=
5308 l_where_generic
5309 || ' AND mmt.rcv_transaction_id = rt.transaction_id ';
5310 END IF;
5311
5312 -- Build the inbound section(FROM and WHERE) of the query
5313 IF p_from_po_header_id IS NOT NULL OR p_to_po_header_id IS NOT NULL
5314 THEN
5315 l_where_inbound :=
5316 l_where_inbound || ' AND pl.po_header_id = ph.po_header_id ';
5317
5318 IF i = 1
5319 THEN
5320 l_where_inbound :=
5321 l_where_inbound || ' AND pll.po_line_id = pl.po_line_id ';
5322 l_where_inbound :=
5323 l_where_inbound
5324 || ' AND pll.line_location_id = mtrl.reference_id ';
5325 l_where_inbound :=
5326 l_where_inbound
5327 || ' AND mtrl.reference = ''PO_LINE_LOCATION_ID'' ';
5328
5329 IF p_from_po_header_id IS NOT NULL
5330 THEN
5331 l_where_inbound :=
5332 l_where_inbound
5333 || 'AND pll.po_header_id >= :from_po_header_id ';
5334 END IF;
5335
5336 IF p_to_po_header_id IS NOT NULL
5337 THEN
5338 l_where_inbound :=
5339 l_where_inbound
5340 || 'AND pll.po_header_id <= :to_po_header_id ';
5341 END IF;
5342 ELSE
5343 l_where_inbound :=
5344 l_where_inbound || ' AND rt.po_line_id = pl.po_line_id ';
5345
5346 IF p_from_po_header_id IS NOT NULL
5347 THEN
5348 l_where_inbound :=
5349 l_where_inbound
5350 || 'AND rt.po_header_id >= :from_po_header_id ';
5351 END IF;
5352
5353 IF p_to_po_header_id IS NOT NULL
5354 THEN
5355 l_where_inbound :=
5356 l_where_inbound
5357 || 'AND rt.po_header_id <= :to_po_header_id ';
5358 END IF;
5359 END IF;
5360 ELSIF p_from_rma_header_id IS NOT NULL
5361 OR p_to_rma_header_id IS NOT NULL
5362 THEN
5363 l_where_generic :=
5364 l_where_generic || ' AND ooh.header_id = ool.header_id ';
5365
5366 IF i = 1
5367 THEN
5368 l_where_generic :=
5369 l_where_generic || ' AND mtrl.reference_id = ool.line_id ';
5370 l_where_inbound :=
5371 l_where_inbound
5372 || ' AND mtrl.reference = ''ORDER_LINE_ID'' ';
5373
5374 IF p_from_rma_header_id IS NOT NULL
5375 THEN
5376 l_where_inbound :=
5377 l_where_inbound
5378 || 'AND ooh.header_id >= :from_rma_header_id ';
5379 END IF;
5380
5381 IF p_to_rma_header_id IS NOT NULL
5382 THEN
5383 l_where_inbound :=
5384 l_where_inbound
5385 || 'AND ooh.header_id <= :to_rma_header_id ';
5386 END IF;
5387 ELSE
5388 l_where_generic :=
5389 l_where_generic
5390 || ' AND rt.oe_order_line_id = ool.line_id ';
5391
5392 IF p_from_rma_header_id IS NOT NULL
5393 THEN
5394 l_where_inbound :=
5395 l_where_inbound
5396 || 'AND rt.oe_order_header_id >= :from_rma_header_id ';
5397 END IF;
5398
5399 IF p_to_rma_header_id IS NOT NULL
5400 THEN
5401 l_where_inbound :=
5402 l_where_inbound
5403 || 'AND rt.oe_order_header_id <= :to_rma_header_id ';
5404 END IF;
5405 END IF;
5406 ELSIF p_from_requisition_header_id IS NOT NULL
5407 OR p_to_requisition_header_id IS NOT NULL
5408 THEN
5409 l_where_inbound :=
5410 l_where_inbound
5411 || ' AND rsl.requisition_line_id = prl.requisition_line_id ';
5412 l_where_generic :=
5413 l_where_generic
5414 || ' AND rsh.shipment_header_id = rsl.shipment_header_id ';
5415 l_where_generic :=
5416 l_where_generic
5417 || ' AND prh.requisition_header_id = prl.requisition_header_id ';
5418
5419 IF i = 1
5420 THEN
5421 l_where_inbound :=
5422 l_where_inbound
5423 || ' AND mtrl.reference_id = rsl.shipment_line_id ';
5424 l_where_inbound :=
5425 l_where_inbound
5426 || ' AND mtrl.reference = ''SHIPMENT_LINE_ID'' ';
5427
5428 IF p_from_requisition_header_id IS NOT NULL
5429 THEN
5430 l_where_inbound :=
5431 l_where_inbound
5432 || 'AND prh.requisition_header_id >= :from_requisition_header_id ';
5433 END IF;
5434
5435 IF p_to_requisition_header_id IS NOT NULL
5436 THEN
5437 l_where_inbound :=
5438 l_where_inbound
5439 || 'AND prh.requisition_header_id <= :to_requisition_header_id ';
5440 END IF;
5441 ELSE
5442 l_where_inbound :=
5443 l_where_inbound
5444 || ' AND rt.shipment_line_id = rsl.shipment_line_id ';
5445
5446 IF p_from_requisition_header_id IS NOT NULL
5447 THEN
5448 l_where_inbound :=
5449 l_where_inbound
5450 || 'AND prh.requisition_header_id >= :from_requisition_header_id ';
5451 END IF;
5452
5453 IF p_to_requisition_header_id IS NOT NULL
5454 THEN
5455 l_where_inbound :=
5456 l_where_inbound
5457 || 'AND prh.requisition_header_id <= :to_requisition_header_id ';
5458 END IF;
5459 END IF;
5460 ELSIF p_from_shipment_number IS NOT NULL
5461 OR p_to_shipment_number IS NOT NULL
5462 THEN
5463 l_where_inbound :=
5464 l_where_inbound
5465 || ' AND rsh.shipment_header_id = rsl.shipment_header_id ';
5466 l_where_inbound :=
5467 l_where_inbound || ' AND rsl.requisition_line_id IS NULL ';
5468
5469 IF i = 1
5470 THEN
5471 l_where_inbound :=
5472 l_where_inbound
5473 || ' AND mtrl.reference_id = rsl.shipment_line_id ';
5474 l_where_inbound :=
5475 l_where_inbound
5476 || ' AND mtrl.reference = ''SHIPMENT_LINE_ID'' ';
5477 ELSE
5478 l_where_inbound :=
5479 l_where_inbound
5480 || ' AND rsh.shipment_header_id = rt.shipment_header_id ';
5481 l_where_inbound :=
5482 l_where_inbound
5483 || ' AND rsl.shipment_line_id = rt.shipment_line_id ';
5484 l_where_inbound :=
5485 l_where_inbound || ' AND rt.po_line_id IS NULL ';
5486 l_where_inbound :=
5487 l_where_inbound || ' AND rt.oe_order_header_id IS NULL ';
5488 END IF;
5489
5490 IF p_from_shipment_number IS NOT NULL
5491 THEN
5492 l_where_inbound :=
5493 l_where_inbound
5494 || ' AND rsh.shipment_num >= :from_shipment_number ';
5495 END IF;
5496
5497 IF p_to_shipment_number IS NOT NULL
5498 THEN
5499 l_where_inbound :=
5500 l_where_inbound
5501 || ' AND rsh.shipment_num <= :to_shipment_number ';
5502 END IF;
5503 END IF;
5504
5505 IF p_summary_mode = 1 THEN
5506 IF i = 1 THEN
5507 l_where_inbound := l_where_inbound || ' GROUP BY mmtt.wms_task_type ';
5508 ELSE
5509 l_where_inbound := l_where_inbound || ' GROUP BY wdth.task_type ';
5510 END IF;
5511 END IF;
5512
5513 -- Execute the Inbound query
5514
5515 -- Concatenate the different sections of the query
5516 l_query :=
5517 l_insert_query
5518 || l_select_generic
5519 || l_from_generic
5520 || l_from_inbound
5521 || l_where_generic
5522 || l_where_inbound;
5523 -- Parse, Bind and Execute the dynamic query
5524 l_query_handle := DBMS_SQL.open_cursor;
5525 DBMS_SQL.parse (l_query_handle, l_query, DBMS_SQL.native);
5526
5527 --generic bind variables
5528 IF p_organization_id IS NOT NULL
5529 THEN
5530 DBMS_SQL.bind_variable (l_query_handle,
5531 'org_id',
5532 p_organization_id
5533 );
5534 END IF;
5535
5536 IF p_subinventory_code IS NOT NULL
5537 THEN
5538 DBMS_SQL.bind_variable (l_query_handle,
5539 'sub_code',
5540 p_subinventory_code
5541 );
5542 END IF;
5543
5544 IF p_locator_id IS NOT NULL
5545 THEN
5546 DBMS_SQL.bind_variable (l_query_handle, 'loc_id', p_locator_id);
5547 END IF;
5548
5549 IF p_to_subinventory_code IS NOT NULL
5550 THEN
5551 DBMS_SQL.bind_variable (l_query_handle,
5552 'to_sub_code',
5553 p_to_subinventory_code
5554 );
5555 END IF;
5556
5557 IF p_to_locator_id IS NOT NULL
5558 THEN
5559 DBMS_SQL.bind_variable (l_query_handle,
5560 'to_loc_id',
5561 p_to_locator_id
5562 );
5563 END IF;
5564
5565 IF p_inventory_item_id IS NOT NULL
5566 THEN
5567 DBMS_SQL.bind_variable (l_query_handle,
5568 'item_id',
5569 p_inventory_item_id
5570 );
5571 END IF;
5572
5573 -- R12 : Additional Query Criteria using item type
5574 IF p_item_type_code IS NOT NULL
5575 THEN
5576 DBMS_SQL.bind_variable (l_query_handle,
5577 'item_type_code',
5578 p_item_type_code
5579 );
5580 END IF;
5581
5582
5583 IF p_category_set_id IS NOT NULL
5584 THEN
5585 DBMS_SQL.bind_variable (l_query_handle,
5586 'category_set_id',
5587 p_category_set_id
5588 );
5589 END IF;
5590
5591 IF p_item_category_id IS NOT NULL
5592 THEN
5593 DBMS_SQL.bind_variable (l_query_handle,
5594 'item_category_id',
5595 p_item_category_id
5596 );
5597 END IF;
5598
5599 IF p_person_id IS NOT NULL
5600 THEN
5601 DBMS_SQL.bind_variable (l_query_handle, 'person_id', p_person_id);
5602 END IF;
5603
5604 IF p_person_resource_id IS NOT NULL
5605 THEN
5606 DBMS_SQL.bind_variable (l_query_handle,
5607 'person_resource_id',
5608 p_person_resource_id
5609 );
5610 END IF;
5611
5612 IF p_equipment_type_id IS NOT NULL
5613 THEN
5614 DBMS_SQL.bind_variable (l_query_handle,
5615 'equipment_type_id',
5616 p_equipment_type_id
5617 );
5618 END IF;
5619
5620 IF p_machine_resource_id IS NOT NULL
5621 THEN
5622 DBMS_SQL.bind_variable (l_query_handle,
5623 'machine_resource_id',
5624 p_machine_resource_id
5625 );
5626 END IF;
5627
5628 IF p_machine_instance IS NOT NULL
5629 THEN
5630 DBMS_SQL.bind_variable (l_query_handle,
5631 'machine_instance',
5632 p_machine_instance
5633 );
5634 END IF;
5635
5636 IF p_from_task_quantity IS NOT NULL
5637 THEN
5638 DBMS_SQL.bind_variable (l_query_handle,
5639 'from_task_quantity',
5640 p_from_task_quantity
5641 );
5642 END IF;
5643
5644 IF p_to_task_quantity IS NOT NULL
5645 THEN
5646 DBMS_SQL.bind_variable (l_query_handle,
5647 'to_task_quantity',
5648 p_to_task_quantity
5649 );
5650 END IF;
5651
5652 IF p_from_creation_date IS NOT NULL
5653 THEN
5654 DBMS_SQL.bind_variable (l_query_handle,
5655 'from_creation_date',
5656 p_from_creation_date
5657 );
5658 END IF;
5659
5660 IF p_to_creation_date IS NOT NULL
5661 THEN
5662 DBMS_SQL.bind_variable (l_query_handle,
5663 'to_creation_date',
5664 p_to_creation_date
5665 );
5666 END IF;
5667
5668 -- R12: Additional Query criteria using age of the task
5669 IF p_age_uom_code IS NOT NULL
5670 THEN
5671
5672 IF p_age_min IS NOT NULL
5673 THEN
5674 DBMS_SQL.bind_variable (l_query_handle,
5675 'age_min',
5676 p_age_min
5677 );
5678 END IF;
5679
5680 IF p_age_max IS NOT NULL
5681 THEN
5682 DBMS_SQL.bind_variable (l_query_handle,
5683 'age_max',
5684 p_age_max
5685 );
5686
5687 END IF;
5688 END IF;
5689
5690 --Inbound specifc bind variables
5691 IF p_from_po_header_id IS NOT NULL
5692 THEN
5693 DBMS_SQL.bind_variable (l_query_handle,
5694 'from_po_header_id',
5695 p_from_po_header_id
5696 );
5697 END IF;
5698
5699 IF p_to_po_header_id IS NOT NULL
5700 THEN
5701 DBMS_SQL.bind_variable (l_query_handle,
5702 'to_po_header_id',
5703 p_to_po_header_id
5704 );
5705 END IF;
5706
5707 IF p_from_rma_header_id IS NOT NULL
5708 THEN
5709 DBMS_SQL.bind_variable (l_query_handle,
5710 'from_rma_header_id',
5711 p_from_rma_header_id
5712 );
5713 END IF;
5714
5715 IF p_to_rma_header_id IS NOT NULL
5716 THEN
5717 DBMS_SQL.bind_variable (l_query_handle,
5718 'to_rma_header_id',
5719 p_to_rma_header_id
5720 );
5721 END IF;
5722
5723 IF p_from_requisition_header_id IS NOT NULL
5724 THEN
5725 DBMS_SQL.bind_variable (l_query_handle,
5726 'from_requisition_header_id',
5727 p_from_requisition_header_id
5728 );
5729 END IF;
5730
5731 IF p_to_requisition_header_id IS NOT NULL
5732 THEN
5733 DBMS_SQL.bind_variable (l_query_handle,
5734 'to_requisition_header_id',
5735 p_to_requisition_header_id
5736 );
5737 END IF;
5738
5739 IF p_from_shipment_number IS NOT NULL
5740 THEN
5741 DBMS_SQL.bind_variable (l_query_handle,
5742 'from_shipment_number',
5743 p_from_shipment_number
5744 );
5745 END IF;
5746
5747 IF p_to_shipment_number IS NOT NULL
5748 THEN
5749 DBMS_SQL.bind_variable (l_query_handle,
5750 'to_shipment_number',
5751 p_to_shipment_number
5752 );
5753 END IF;
5754
5755 IF p_summary_mode = 1 THEN
5756 DBMS_SQL.DEFINE_COLUMN(l_query_handle, 1, l_wms_task_type);
5757 DBMS_SQL.DEFINE_COLUMN(l_query_handle, 2, l_task_count);
5758 END IF;
5759
5760 --execute the query
5761 l_query_count := DBMS_SQL.EXECUTE (l_query_handle);
5762 g_record_count := g_record_count + l_query_count;
5763
5764 IF p_summary_mode = 1 THEN -- fetch the rows and put them into the global tables
5765 LOOP
5766 IF DBMS_SQL.FETCH_ROWS(l_query_handle)>0 THEN
5767 DBMS_SQL.COLUMN_VALUE(l_query_handle, 1, l_wms_task_type);
5768 DBMS_SQL.COLUMN_VALUE(l_query_handle, 2, l_task_count);
5769 g_wms_task_summary_tbl(l_wms_task_type).wms_task_type := l_wms_task_type;
5770 g_wms_task_summary_tbl(l_wms_task_type).task_count := g_wms_task_summary_tbl(l_wms_task_type).task_count + l_task_count;
5771 ELSE
5772 EXIT; -- no more rows returned from dynamic SQL
5773 END IF;
5774 END LOOP;
5775 END IF;
5776
5777 DBMS_SQL.close_cursor(l_query_handle);
5778 END LOOP;
5779
5780 IF (g_source_header_visible = 'T' OR g_line_number_visible = 'T')
5781 AND p_from_po_header_id IS NULL
5782 AND p_to_po_header_id IS NULL
5783 AND p_from_rma_header_id IS NULL
5784 AND p_to_rma_header_id IS NULL
5785 AND p_from_requisition_header_id IS NULL
5786 AND p_to_requisition_header_id IS NULL
5787 THEN
5788 set_inbound_source_header_line;
5789 END IF;
5790 EXCEPTION
5791 WHEN OTHERS THEN -- Bug 4150145
5792 IF dbms_sql.is_open(l_query_handle) THEN
5793 dbms_sql.close_cursor(l_query_handle);
5794 END IF;
5795 DEBUG (SQLERRM, 'Task_planning.query_inbound_tasks');
5796 END query_inbound_tasks;
5797
5798 PROCEDURE query_manufacturing_tasks (
5799 p_add BOOLEAN DEFAULT FALSE,
5800 p_organization_id NUMBER DEFAULT NULL,
5801 p_subinventory_code VARCHAR2 DEFAULT NULL,
5802 p_locator_id NUMBER DEFAULT NULL,
5803 p_to_subinventory_code VARCHAR2 DEFAULT NULL,
5804 p_to_locator_id NUMBER DEFAULT NULL,
5805 p_inventory_item_id NUMBER DEFAULT NULL,
5806 p_category_set_id NUMBER DEFAULT NULL,
5807 p_item_category_id NUMBER DEFAULT NULL,
5808 p_person_id NUMBER DEFAULT NULL,
5809 p_person_resource_id NUMBER DEFAULT NULL,
5810 p_equipment_type_id NUMBER DEFAULT NULL,
5811 p_machine_resource_id NUMBER DEFAULT NULL,
5812 p_machine_instance VARCHAR2 DEFAULT NULL,
5813 p_user_task_type_id NUMBER DEFAULT NULL,
5814 p_from_task_quantity NUMBER DEFAULT NULL,
5815 p_to_task_quantity NUMBER DEFAULT NULL,
5816 p_from_task_priority NUMBER DEFAULT NULL,
5817 p_to_task_priority NUMBER DEFAULT NULL,
5818 p_from_creation_date DATE DEFAULT NULL,
5819 p_to_creation_date DATE DEFAULT NULL,
5820 p_is_unreleased BOOLEAN DEFAULT FALSE,
5821 p_is_pending BOOLEAN DEFAULT FALSE,
5822 p_is_queued BOOLEAN DEFAULT FALSE,
5823 p_is_dispatched BOOLEAN DEFAULT FALSE,
5824 p_is_active BOOLEAN DEFAULT FALSE,
5825 p_is_loaded BOOLEAN DEFAULT FALSE,
5826 p_is_completed BOOLEAN DEFAULT FALSE,
5827 p_manufacturing_type VARCHAR2 DEFAULT NULL,
5828 p_from_job VARCHAR2 DEFAULT NULL,
5829 p_to_job VARCHAR2 DEFAULT NULL,
5830 p_assembly_id NUMBER DEFAULT NULL,
5831 p_from_start_date DATE DEFAULT NULL,
5832 p_to_start_date DATE DEFAULT NULL,
5833 p_from_line VARCHAR2 DEFAULT NULL,
5834 p_to_line VARCHAR2 DEFAULT NULL,
5835 p_department_id NUMBER DEFAULT NULL,
5836 -- R12 : Additional Query Criteria
5837 p_item_type_code VARCHAR2 DEFAULT NULL,
5838 p_age_uom_code VARCHAR2 DEFAULT NULL,
5839 p_age_min NUMBER DEFAULT NULL,
5840 p_age_max NUMBER DEFAULT NULL,
5841 p_summary_mode NUMBER DEFAULT 0
5842 -- R12 : Additional Query Criteria
5843 )
5844 IS
5845 l_query VARCHAR2 (10000);
5846 l_insert_query VARCHAR2 (3000);
5847 l_select_manufacturing VARCHAR2 (3000);
5848 l_from_manufacturing VARCHAR2 (3000);
5849 l_where_manufacturing VARCHAR2 (4000);
5850 l_select_generic VARCHAR2 (3000);
5851 l_from_generic VARCHAR2 (3000);
5852 l_where_generic VARCHAR2 (5000);
5853 l_query_handle NUMBER; -- Handle for the dynamic sql
5854 l_query_count NUMBER;
5855 l_loop_start NUMBER;
5856 l_loop_end NUMBER;
5857 l_is_unreleased BOOLEAN;
5858 l_is_pending BOOLEAN;
5859 l_is_queued BOOLEAN;
5860 l_is_dispatched BOOLEAN;
5861 l_is_active BOOLEAN;
5862 l_is_loaded BOOLEAN;
5863 l_is_completed BOOLEAN;
5864 l_wms_task_type NUMBER; -- for bug 5129375
5865 l_task_count NUMBER;
5866 l_debug NUMBER
5867 := NVL (fnd_profile.VALUE ('INV_DEBUG_TRACE'), 0);
5868 BEGIN
5869 IF p_is_completed THEN
5870
5871 /*Bug 3627575:Setting the variable to true for Inbound queries*/
5872 wms_plan_tasks_pvt.g_from_inbound :=TRUE;
5873
5874 l_loop_end := 2;
5875 ELSE
5876 l_loop_end := 1;
5877 END IF;
5878
5879 IF p_is_unreleased
5880 OR p_is_pending
5881 OR p_is_queued
5882 OR p_is_dispatched
5883 OR p_is_active
5884 OR p_is_loaded
5885 THEN
5886 l_loop_start := 1;
5887 ELSE
5888 l_loop_start := 2;
5889 END IF;
5890
5891 FOR i IN l_loop_start .. l_loop_end
5892 LOOP
5893 l_insert_query := NULL;
5894 l_select_generic := NULL;
5895 l_select_manufacturing := NULL;
5896 l_from_generic := NULL;
5897 l_from_manufacturing := NULL;
5898 l_where_generic := NULL;
5899 l_where_manufacturing := NULL;
5900
5901 IF i = 1
5902 THEN -- Non completed tasks iteration
5903 l_is_unreleased := p_is_unreleased;
5904 l_is_pending := p_is_pending;
5905 l_is_queued := p_is_queued;
5906 l_is_dispatched := p_is_dispatched;
5907 l_is_active := p_is_active;
5908 l_is_loaded := p_is_loaded;
5909 l_is_completed := FALSE;
5910 ELSE -- Completed tasks
5911 l_is_unreleased := FALSE;
5912 l_is_pending := FALSE;
5913 l_is_queued := FALSE;
5914 l_is_dispatched := FALSE;
5915 l_is_active := FALSE;
5916 l_is_loaded := FALSE;
5917 l_is_completed := p_is_completed;
5918 END IF;
5919
5920 -- Insert section
5921 IF p_summary_mode = 1 THEN -- only for query mode
5922 IF i = 1 THEN
5923 l_select_generic := ' SELECT mmtt.wms_task_type, count(*) ';
5924 ELSE
5925 l_select_generic := ' SELECT wdth.task_type, count(*) ';
5926 END IF;
5927 ELSE
5928 l_insert_query :=
5929 get_generic_insert (p_is_unreleased => l_is_unreleased,
5930 p_is_pending => l_is_pending,
5931 p_is_queued => l_is_queued,
5932 p_is_dispatched => l_is_dispatched,
5933 p_is_active => l_is_active,
5934 p_is_loaded => l_is_loaded,
5935 p_is_completed => l_is_completed
5936 );
5937
5938 -- Manufacturing specific insert
5939 IF g_assembly_visible = 'T' OR p_assembly_id IS NOT NULL
5940 THEN
5941 l_insert_query := l_insert_query || ', assembly_id ';
5942
5943 IF g_assembly_visible = 'T'
5944 THEN
5945 l_insert_query := l_insert_query || ', assembly ';
5946 END IF;
5947 END IF;
5948
5949 IF g_line_visible = 'T'
5950 OR p_from_line IS NOT NULL
5951 OR p_to_line IS NOT NULL
5952 THEN
5953 l_insert_query := l_insert_query || ', line_id ';
5954 l_insert_query := l_insert_query || ', line ';
5955 END IF;
5956
5957 IF g_department_visible = 'T' OR p_department_id IS NOT NULL
5958 THEN
5959 l_insert_query := l_insert_query || ', department_id ';
5960
5961 IF g_department_visible = 'T'
5962 THEN
5963 l_insert_query := l_insert_query || ', department ';
5964 END IF;
5965 END IF;
5966
5967 IF g_source_header_visible = 'T'
5968 OR p_from_job IS NOT NULL
5969 OR p_to_job IS NOT NULL
5970 THEN
5971 l_insert_query := l_insert_query || ', source_header ';
5972 END IF;
5973
5974 l_insert_query := l_insert_query || ', wip_entity_type ';
5975 l_insert_query := l_insert_query || ', wip_entity_id ';
5976 /* Navin INV_Convergence_Gme_Wms_TD REPLACED: l_insert_query := l_insert_query || ') '; */
5977 IF p_manufacturing_type = '10' /* Batch*/ THEN
5978 l_insert_query := l_insert_query || ', primary_product ';
5979 l_insert_query := l_insert_query || ') ';
5980 ELSE
5981 l_insert_query := l_insert_query || ') ';
5982 END IF;
5983 -- Generic select
5984 l_select_generic :=
5985 get_generic_select (p_is_unreleased => l_is_unreleased,
5986 p_is_pending => l_is_pending,
5987 p_is_queued => l_is_queued,
5988 p_is_dispatched => l_is_dispatched,
5989 p_is_active => l_is_active,
5990 p_is_loaded => l_is_loaded,
5991 p_is_completed => l_is_completed
5992 );
5993 END IF;
5994 -- Generic from
5995 l_from_generic :=
5996 get_generic_from (p_is_queued => l_is_queued,
5997 p_is_dispatched => l_is_dispatched,
5998 p_is_active => l_is_active,
5999 p_is_loaded => l_is_loaded,
6000 p_is_completed => l_is_completed,
6001 p_item_category_id => p_item_category_id,
6002 p_category_set_id => p_category_set_id
6003 );
6004 --Generic Where
6005 l_where_generic :=
6006 get_generic_where
6007 (p_add => p_add,
6008 p_organization_id => p_organization_id,
6009 p_subinventory_code => p_subinventory_code,
6010 p_locator_id => p_locator_id,
6011 p_to_subinventory_code => p_to_subinventory_code,
6012 p_to_locator_id => p_to_locator_id,
6013 p_inventory_item_id => p_inventory_item_id,
6014 p_category_set_id => p_category_set_id,
6015 p_item_category_id => p_item_category_id,
6016 p_person_id => p_person_id,
6017 p_person_resource_id => p_person_resource_id,
6018 p_equipment_type_id => p_equipment_type_id,
6019 p_machine_resource_id => p_machine_resource_id,
6020 p_machine_instance => p_machine_instance,
6021 p_user_task_type_id => p_user_task_type_id,
6022 p_from_task_quantity => p_from_task_quantity,
6023 p_to_task_quantity => p_to_task_quantity,
6024 p_from_task_priority => p_from_task_priority,
6025 p_to_task_priority => p_to_task_priority,
6026 p_from_creation_date => p_from_creation_date,
6027 p_to_creation_date => p_to_creation_date,
6028 p_is_unreleased => l_is_unreleased,
6029 p_is_pending => l_is_pending,
6030 p_is_queued => l_is_queued,
6031 p_is_dispatched => l_is_dispatched,
6032 p_is_active => l_is_active,
6033 p_is_loaded => l_is_loaded,
6034 p_is_completed => l_is_completed,
6035 -- R12: Additional query criteria
6036 p_item_type_code => p_item_type_code,
6037 p_age_uom_code => p_age_uom_code,
6038 p_age_min => p_age_min,
6039 p_age_max => p_age_max
6040 );
6041
6042 -- Build the manufacturing section(FROM and WHERE) of the query
6043 IF p_manufacturing_type IS NOT NULL
6044 THEN
6045 l_from_manufacturing := ', mtl_txn_request_lines mtrl ';
6046
6047 IF i = 1
6048 THEN
6049 l_where_manufacturing :=
6050 ' and mmtt.move_order_line_id = mtrl.line_id ';
6051 ELSE
6052 l_where_manufacturing :=
6053 ' and mmt.move_order_line_id = mtrl.line_id ';
6054 END IF;
6055
6056 l_where_manufacturing :=
6057 l_where_manufacturing
6058 || ' and mtrl.transaction_source_type_id in (5,13) ';
6059 l_where_manufacturing :=
6060 l_where_manufacturing
6061 || ' and mtrl.transaction_type_id in (35,51) ';
6062 END IF;
6063
6064 IF p_manufacturing_type = '1'
6065 THEN --job
6066 IF g_assembly_visible = 'T' OR p_assembly_id IS NOT NULL
6067 THEN
6068 l_select_manufacturing := ', wdj.primary_item_id ';
6069 -- assembly_id
6070
6071 IF g_assembly_visible = 'T'
6072 THEN
6073 l_select_manufacturing :=
6074 l_select_manufacturing
6075 || ', msiv2.concatenated_segments '; -- assembly
6076 END IF;
6077 END IF;
6078
6079 IF g_line_visible = 'T'
6080 OR p_from_line IS NOT NULL
6081 OR p_to_line IS NOT NULL
6082 THEN
6083 l_select_manufacturing :=
6084 l_select_manufacturing || ', wl.line_id ';
6085 -- line_id
6086 l_select_manufacturing :=
6087 l_select_manufacturing || ', wl.line_code ';
6088 -- line
6089 END IF;
6090
6091 IF g_department_visible = 'T' OR p_department_id IS NOT NULL
6092 THEN
6093 l_select_manufacturing :=
6094 l_select_manufacturing || ', wro.department_id ';
6095 -- department_id
6096
6097 IF g_department_visible = 'T'
6098 THEN
6099 l_select_manufacturing :=
6100 l_select_manufacturing || ', bd.department_code ';
6101 -- department
6102 END IF;
6103 END IF;
6104
6105 IF g_source_header_visible = 'T'
6106 OR p_from_job IS NOT NULL
6107 OR p_to_job IS NOT NULL
6108 THEN
6109 l_select_manufacturing :=
6110 l_select_manufacturing || ', we.wip_entity_name ';
6111 -- source header
6112 END IF;
6113
6114 l_select_manufacturing :=
6115 l_select_manufacturing || ', to_number(1) ';
6116 -- manufacturing_type
6117 l_select_manufacturing :=
6118 l_select_manufacturing || ', wdj.wip_entity_id ';
6119 -- wip_entity_id
6120 l_from_manufacturing :=
6121 l_from_manufacturing || ', wip_discrete_jobs wdj ';
6122
6123 IF g_assembly_visible = 'T'
6124 THEN
6125 l_from_manufacturing :=
6126 l_from_manufacturing || ', mtl_system_items_kfv msiv2 ';
6127 END IF;
6128
6129 IF g_department_visible = 'T'
6130 THEN
6131 l_from_manufacturing :=
6132 l_from_manufacturing || ', bom_departments bd ';
6133 END IF;
6134
6135 l_where_manufacturing :=
6136 l_where_manufacturing
6137 || ' and mtrl.txn_source_id = wdj.wip_entity_id ';
6138
6139 IF g_assembly_visible = 'T'
6140 THEN
6141 l_where_manufacturing :=
6142 l_where_manufacturing
6143 || ' and wdj.primary_item_id = msiv2.inventory_item_id(+) ';
6144 l_where_manufacturing :=
6145 l_where_manufacturing
6146 || ' and wdj.organization_id = msiv2.organization_id(+) ';
6147 END IF;
6148
6149 IF g_source_header_visible = 'T'
6150 OR p_from_job IS NOT NULL
6151 OR p_to_job IS NOT NULL
6152 THEN
6153 l_from_manufacturing :=
6154 l_from_manufacturing || ', wip_entities we ';
6155 l_where_manufacturing :=
6156 l_where_manufacturing
6157 || ' and wdj.wip_entity_id = we.wip_entity_id ';
6158 l_where_manufacturing :=
6159 l_where_manufacturing
6160 || ' and wdj.organization_id = we.organization_id ';
6161
6162 IF p_from_job IS NOT NULL
6163 THEN
6164 l_where_manufacturing :=
6165 l_where_manufacturing
6166 || ' and we.wip_entity_name >= :from_job ';
6167 END IF;
6168
6169 IF p_to_job IS NOT NULL
6170 THEN
6171 l_where_manufacturing :=
6172 l_where_manufacturing
6173 || ' and we.wip_entity_name <= :to_job ';
6174 END IF;
6175 END IF;
6176
6177 IF p_assembly_id IS NOT NULL
6178 THEN
6179 l_where_manufacturing :=
6180 l_where_manufacturing
6181 || ' and wdj.primary_item_id = :assembly_id ';
6182 END IF;
6183
6184 IF p_from_start_date IS NOT NULL
6185 THEN
6186 l_where_manufacturing :=
6187 l_where_manufacturing
6188 || ' and wdj.scheduled_start_date >= :from_start_date ';
6189 END IF;
6190
6191 IF p_to_start_date IS NOT NULL
6192 THEN
6193 l_where_manufacturing :=
6194 l_where_manufacturing
6195 || ' and wdj.scheduled_start_date <= :to_start_date ';
6196 END IF;
6197
6198 IF g_line_visible = 'T'
6199 OR p_from_line IS NOT NULL
6200 OR p_to_line IS NOT NULL
6201 THEN
6202 l_from_manufacturing :=
6203 l_from_manufacturing || ' , wip_lines wl ';
6204 l_where_manufacturing :=
6205 l_where_manufacturing
6206 || ' and wdj.line_id = wl.line_id(+) ';
6207 l_where_manufacturing :=
6208 l_where_manufacturing
6209 || ' and wdj.organization_id = wl.organization_id(+) ';
6210
6211 IF p_from_line IS NOT NULL
6212 THEN
6213 l_where_manufacturing :=
6214 l_where_manufacturing
6215 || ' and wl.line_code >= :from_line ';
6216 END IF;
6217
6218 IF p_to_line IS NOT NULL
6219 THEN
6220 l_where_manufacturing :=
6221 l_where_manufacturing
6222 || ' and wl.line_code <= :to_line ';
6223 END IF;
6224 END IF;
6225
6226 IF g_department_visible = 'T' OR p_department_id IS NOT NULL
6227 THEN
6228 l_from_manufacturing :=
6229 l_from_manufacturing
6230 || ' , wip_requirement_operations wro ';
6231 l_where_manufacturing :=
6232 l_where_manufacturing
6233 || ' and mtrl.txn_source_line_id = wro.operation_seq_num ';
6234 l_where_manufacturing :=
6235 l_where_manufacturing
6236 || ' and mtrl.inventory_item_id = wro.inventory_item_id ';
6237 l_where_manufacturing :=
6238 l_where_manufacturing
6239 || ' and wdj.wip_entity_id = wro.wip_entity_id ';
6240 l_where_manufacturing :=
6241 l_where_manufacturing
6242 || ' and wdj.organization_id = wro.organization_id ';
6243
6244 IF p_department_id IS NOT NULL
6245 THEN
6246 l_where_manufacturing :=
6247 l_where_manufacturing
6248 || ' and wro.department_id = :dept_id ';
6249 END IF;
6250
6251 IF g_department_visible = 'T'
6252 THEN
6253 l_where_manufacturing :=
6254 l_where_manufacturing
6255 || ' and wro.department_id = bd.department_id(+) ';
6256 l_where_manufacturing :=
6257 l_where_manufacturing
6258 || ' and wro.organization_id = bd.organization_id(+) ';
6259 END IF;
6260 END IF;
6261 ELSIF p_manufacturing_type = '2'
6262 THEN --Flow schedule
6263 IF g_assembly_visible = 'T' OR p_assembly_id IS NOT NULL
6264 THEN
6265 l_select_manufacturing := ', wfs.primary_item_id ';
6266 -- assembly_id
6267
6268 IF g_assembly_visible = 'T'
6269 THEN
6270 l_select_manufacturing :=
6271 l_select_manufacturing
6272 || ', msiv2.concatenated_segments '; -- assembly
6273 END IF;
6274 END IF;
6275
6276 IF g_line_visible = 'T'
6277 OR p_from_line IS NOT NULL
6278 OR p_to_line IS NOT NULL
6279 THEN
6280 l_select_manufacturing :=
6281 l_select_manufacturing || ', wl.line_id ';
6282 -- line_id
6283 l_select_manufacturing :=
6284 l_select_manufacturing || ', wl.line_code ';
6285 -- line
6286 END IF;
6287
6288 IF g_department_visible = 'T' OR p_department_id IS NOT NULL
6289 THEN
6290 l_select_manufacturing :=
6291 l_select_manufacturing || ', bos.department_id ';
6292 -- department_id
6293
6294 IF g_department_visible = 'T'
6295 THEN
6296 l_select_manufacturing :=
6297 l_select_manufacturing || ', bd.department_code ';
6298 -- department
6299 END IF;
6300 END IF;
6301
6302 IF g_source_header_visible = 'T'
6303 OR p_from_job IS NOT NULL
6304 OR p_to_job IS NOT NULL
6305 THEN
6306 l_select_manufacturing :=
6307 l_select_manufacturing || ', wfs.schedule_number ';
6308 -- source header
6309 END IF;
6310
6311 l_select_manufacturing :=
6312 l_select_manufacturing || ',to_number(2) ';
6313 -- manufacturing_type
6314 l_select_manufacturing :=
6315 l_select_manufacturing || ', wfs.wip_entity_id ';
6316 -- wip_entity_id
6317 l_from_manufacturing :=
6318 l_from_manufacturing || ' , wip_flow_schedules wfs ';
6319 l_from_manufacturing :=
6320 l_from_manufacturing || ' , bom_operational_routings bor ';
6321 l_from_manufacturing :=
6322 l_from_manufacturing || ' , bom_operation_sequences bos ';
6323
6324 IF g_assembly_visible = 'T'
6325 THEN
6326 l_from_manufacturing :=
6327 l_from_manufacturing || ', mtl_system_items_kfv msiv2 ';
6328 END IF;
6329
6330 IF g_department_visible = 'T'
6331 THEN
6332 l_from_manufacturing :=
6333 l_from_manufacturing || ', bom_departments bd ';
6334 END IF;
6335
6336 l_where_manufacturing :=
6337 l_where_manufacturing
6338 || ' and mtrl.txn_source_id = wfs.wip_entity_id ';
6339 l_where_manufacturing :=
6340 l_where_manufacturing
6341 || ' and mtrl.organization_id = wfs.organization_id ';
6342 l_where_manufacturing :=
6343 l_where_manufacturing
6344 || ' and ( (mtrl.txn_source_line_id = bos.operation_seq_num) or (mtrl.txn_source_line_id = 1) ) ';
6345 l_where_manufacturing :=
6346 l_where_manufacturing
6347 || ' and (wfs.alternate_routing_designator = bor.alternate_routing_designator ';
6348 l_where_manufacturing :=
6349 l_where_manufacturing
6350 || ' OR (wfs.alternate_routing_designator is null AND bor.alternate_routing_designator is null)) ';
6351 l_where_manufacturing :=
6352 l_where_manufacturing
6353 || ' and wfs.organization_id = bor.organization_id ';
6354 l_where_manufacturing :=
6355 l_where_manufacturing
6356 || ' and wfs.primary_item_id = bor.assembly_item_id ';
6357 l_where_manufacturing :=
6358 l_where_manufacturing
6359 || ' and bor.routing_sequence_id = bos.routing_sequence_id ';
6360 l_where_manufacturing :=
6361 l_where_manufacturing || ' and bos.operation_type = 1 ';
6362
6363 IF g_assembly_visible = 'T'
6364 THEN
6365 l_where_manufacturing :=
6366 l_where_manufacturing
6367 || ' and wfs.primary_item_id = msiv2.inventory_item_id ';
6368 l_where_manufacturing :=
6369 l_where_manufacturing
6370 || ' and mtrl.organization_id = msiv2.organization_id ';
6371 END IF;
6372
6373 IF p_from_job IS NOT NULL OR p_to_job IS NOT NULL
6374 THEN
6375 IF p_from_job IS NOT NULL
6376 THEN
6377 l_where_manufacturing :=
6378 l_where_manufacturing
6379 || ' and wfs.schedule_number >= :from_job ';
6380 END IF;
6381
6382 IF p_to_job IS NOT NULL
6383 THEN
6384 l_where_manufacturing :=
6385 l_where_manufacturing
6386 || ' and wfs.schedule_number <= :to_job ';
6387 END IF;
6388 END IF;
6389
6390 IF p_assembly_id IS NOT NULL
6391 THEN
6392 l_where_manufacturing :=
6393 l_where_manufacturing
6394 || ' and wfs.primary_item_id = :assembly_id ';
6395 END IF;
6396
6397 IF p_from_start_date IS NOT NULL
6398 THEN
6399 l_where_manufacturing :=
6400 l_where_manufacturing
6401 || ' and wfs.scheduled_start_date >= :from_start_date ';
6402 END IF;
6403
6404 IF p_to_start_date IS NOT NULL
6405 THEN
6406 l_where_manufacturing :=
6407 l_where_manufacturing
6408 || ' and wfs.scheduled_start_date <= :to_start_date ';
6409 END IF;
6410
6411 IF g_line_visible = 'T'
6412 OR p_from_line IS NOT NULL
6413 OR p_to_line IS NOT NULL
6414 THEN
6415 l_from_manufacturing :=
6416 l_from_manufacturing || ' , wip_lines wl ';
6417 l_where_manufacturing :=
6418 l_where_manufacturing || ' and wfs.line_id = wl.line_id ';
6419 l_where_manufacturing :=
6420 l_where_manufacturing
6421 || ' and wfs.organization_id = wl.organization_id ';
6422
6423 IF p_from_line IS NOT NULL
6424 THEN
6425 l_where_manufacturing :=
6426 l_where_manufacturing
6427 || ' and wl.line_code >= :from_line ';
6428 END IF;
6429
6430 IF p_to_line IS NOT NULL
6431 THEN
6432 l_where_manufacturing :=
6433 l_where_manufacturing
6434 || ' and wl.line_code <= :to_line ';
6435 END IF;
6436 END IF;
6437
6438 IF g_department_visible = 'T' OR p_department_id IS NOT NULL
6439 THEN
6440 IF p_department_id IS NOT NULL
6441 THEN
6442 l_where_manufacturing :=
6443 l_where_manufacturing
6444 || ' and bos.department_id = :dept_id ';
6445 END IF;
6446
6447 IF g_department_visible = 'T'
6448 THEN
6449 l_where_manufacturing :=
6450 l_where_manufacturing
6451 || ' and bos.department_id = bd.department_id ';
6452 END IF;
6453 END IF;
6454 ELSIF p_manufacturing_type = '3'
6455 THEN --repetitive schedule
6456 IF g_assembly_visible = 'T' OR p_assembly_id IS NOT NULL
6457 THEN
6458 l_select_manufacturing := ', wri.primary_item_id ';
6459 -- assembly_id
6460
6461 IF g_assembly_visible = 'T'
6462 THEN
6463 l_select_manufacturing :=
6464 l_select_manufacturing
6465 || ', msiv2.concatenated_segments '; -- assembly
6466 END IF;
6467 END IF;
6468
6469 IF g_line_visible = 'T'
6470 OR p_from_line IS NOT NULL
6471 OR p_to_line IS NOT NULL
6472 THEN
6473 l_select_manufacturing :=
6474 l_select_manufacturing || ', wl.line_id ';
6475 -- line_id
6476 l_select_manufacturing :=
6477 l_select_manufacturing || ', wl.line_code ';
6478 -- line
6479 END IF;
6480
6481 IF g_department_visible = 'T' OR p_department_id IS NOT NULL
6482 THEN
6483 l_select_manufacturing :=
6484 l_select_manufacturing || ', wro.department_id ';
6485 -- department_id
6486
6487 IF g_department_visible = 'T'
6488 THEN
6489 l_select_manufacturing :=
6490 l_select_manufacturing || ', bd.department_code ';
6491 -- department
6492 END IF;
6493 END IF;
6494
6495 IF g_source_header_visible = 'T'
6496 THEN
6497 l_select_manufacturing :=
6498 l_select_manufacturing || ', we.wip_entity_name ';
6499 -- source header
6500 END IF;
6501
6502 l_select_manufacturing :=
6503 l_select_manufacturing || ', to_number(3) ';
6504 -- manufacturing_type
6505 l_select_manufacturing :=
6506 l_select_manufacturing || ', wrs.wip_entity_id ';
6507 -- wip_entity_id
6508 l_from_manufacturing :=
6509 l_from_manufacturing || ', wip_repetitive_schedules wrs ';
6510 l_from_manufacturing :=
6511 l_from_manufacturing || ', wip_requirement_operations wro ';
6512
6513 IF g_assembly_visible = 'T'
6514 THEN
6515 l_from_manufacturing :=
6516 l_from_manufacturing || ', mtl_system_items_kfv msiv2 ';
6517 END IF;
6518
6519 IF g_department_visible = 'T'
6520 THEN
6521 l_from_manufacturing :=
6522 l_from_manufacturing || ', bom_departments bd ';
6523 END IF;
6524
6525 IF g_source_header_visible = 'T'
6526 THEN
6527 l_from_manufacturing :=
6528 l_from_manufacturing || ', wip_entities we ';
6529 END IF;
6530
6531 l_where_manufacturing :=
6532 l_where_manufacturing
6533 || ' and wro.wip_entity_id = wrs.wip_entity_id ';
6534 l_where_manufacturing :=
6535 l_where_manufacturing
6536 || ' and wro.organization_id = wrs.organization_id ';
6537 l_where_manufacturing :=
6538 l_where_manufacturing
6539 || ' and wro.repetitive_schedule_id = wrs.repetitive_schedule_id ';
6540 l_where_manufacturing :=
6541 l_where_manufacturing
6542 || ' and mtrl.TXN_SOURCE_LINE_ID = wro.OPERATION_SEQ_NUM ';
6543 l_where_manufacturing :=
6544 l_where_manufacturing
6545 || ' and mtrl.inventory_item_id = wro.inventory_item_id ';
6546 l_where_manufacturing :=
6547 l_where_manufacturing
6548 || ' and mtrl.txn_source_id = wrs.wip_entity_id ';
6549 l_where_manufacturing :=
6550 l_where_manufacturing
6551 || ' and mtrl.reference_id = wrs.repetitive_schedule_id ';
6552
6553 IF g_assembly_visible = 'T'
6554 THEN
6555 l_where_manufacturing :=
6556 l_where_manufacturing
6557 || ' and wri.primary_item_id = msiv2.inventory_item_id ';
6558 l_where_manufacturing :=
6559 l_where_manufacturing
6560 || ' and mtrl.organization_id = msiv2.organization_id ';
6561 END IF;
6562
6563 IF g_source_header_visible = 'T'
6564 THEN
6565 l_where_manufacturing :=
6566 l_where_manufacturing
6567 || ' and wro.wip_entity_id = we.wip_entity_id ';
6568 END IF;
6569
6570 -- for repetitive schedule we can't give job
6571 IF g_assembly_visible = 'T' OR p_assembly_id IS NOT NULL
6572 THEN
6573 l_from_manufacturing :=
6574 l_from_manufacturing || ' , wip_repetitive_items wri ';
6575 l_where_manufacturing :=
6576 l_where_manufacturing
6577 || ' and wrs.wip_entity_id = wri.wip_entity_id ';
6578 l_where_manufacturing :=
6579 l_where_manufacturing || ' and wrs.line_id = wri.line_id ';
6580 l_where_manufacturing :=
6581 l_where_manufacturing
6582 || ' and wrs.organization_id = wri.organization_id ';
6583
6584 IF p_assembly_id IS NOT NULL
6585 THEN
6586 l_where_manufacturing :=
6587 l_where_manufacturing
6588 || ' and wri.primary_item_id = :assembly_id ';
6589 END IF;
6590 END IF;
6591
6592 IF p_from_start_date IS NOT NULL
6593 THEN
6594 l_where_manufacturing :=
6595 l_where_manufacturing
6596 || ' and wrs.first_unit_start_date >= :from_start_date ';
6597 END IF;
6598
6599 IF p_to_start_date IS NOT NULL
6600 THEN
6601 l_where_manufacturing :=
6602 l_where_manufacturing
6603 || ' and wrs.first_unit_start_date <= :to_start_date ';
6604 END IF;
6605
6606 IF g_line_visible = 'T'
6607 OR p_from_line IS NOT NULL
6608 OR p_to_line IS NOT NULL
6609 THEN
6610 l_from_manufacturing :=
6611 l_from_manufacturing || ' , wip_lines wl ';
6612 l_where_manufacturing :=
6613 l_where_manufacturing || ' and wrs.line_id = wl.line_id ';
6614 l_where_manufacturing :=
6615 l_where_manufacturing
6616 || ' and wrs.organization_id = wl.organization_id ';
6617
6618 IF p_from_line IS NOT NULL
6619 THEN
6620 l_where_manufacturing :=
6621 l_where_manufacturing
6622 || ' and wl.line_code >= :from_line ';
6623 END IF;
6624
6625 IF p_to_line IS NOT NULL
6626 THEN
6627 l_where_manufacturing :=
6628 l_where_manufacturing
6629 || ' and wl.line_code <= :to_line ';
6630 END IF;
6631 END IF;
6632
6633 IF g_department_visible = 'T' OR p_department_id IS NOT NULL
6634 THEN
6635 IF p_department_id IS NOT NULL
6636 THEN
6637 l_where_manufacturing :=
6638 l_where_manufacturing
6639 || ' and wro.department_id = :dept_id ';
6640 END IF;
6641
6642 IF g_department_visible = 'T'
6643 THEN
6644 l_where_manufacturing :=
6645 l_where_manufacturing
6646 || ' and wro.department_id = bd.department_id(+) ';
6647 l_where_manufacturing :=
6648 l_where_manufacturing
6649 || ' and wro.organization_id = bd.organization_id(+) ';
6650 END IF;
6651 END IF;
6652 /* Navin INV_Convergence_Gme_Wms_TD Added condition for OPM Batch. */
6653 ELSIF p_manufacturing_type = '10' /* OPM Batch */
6654 THEN
6655 IF g_assembly_visible = 'T' OR p_assembly_id IS NOT NULL
6656 THEN
6657 l_select_manufacturing := ', TO_NUMBER (NULL) '; -- Inventory item Identifier
6658 -- for the assembly the job creates
6659 -- assembly_id
6660 IF g_assembly_visible = 'T'
6661 THEN
6662 l_select_manufacturing :=
6663 l_select_manufacturing
6664 || ', NULL '; -- assembly
6665 END IF;
6666 END IF;
6667
6668 IF g_line_visible = 'T'
6669 OR p_from_line IS NOT NULL
6670 OR p_to_line IS NOT NULL
6671 THEN
6672 l_select_manufacturing :=
6673 l_select_manufacturing || ', TO_NUMBER (NULL) ';
6674 -- line_id
6675 l_select_manufacturing :=
6676 l_select_manufacturing || ', NULL ';
6677 -- line
6678 END IF;
6679
6680 IF g_department_visible = 'T' OR p_department_id IS NOT NULL
6681 THEN
6682 l_select_manufacturing :=
6683 l_select_manufacturing || ', TO_NUMBER (NULL) ';
6684 -- department_id
6685
6686 IF g_department_visible = 'T'
6687 THEN
6688 l_select_manufacturing :=
6689 l_select_manufacturing || ', NULL ';
6690 -- department
6691 END IF;
6692 END IF;
6693
6694 IF g_source_header_visible = 'T'
6695 OR p_from_job IS NOT NULL
6696 OR p_to_job IS NOT NULL
6697 THEN
6698 l_select_manufacturing :=
6699 l_select_manufacturing || ', h.batch_no ';
6700 -- source header
6701 END IF;
6702
6703 l_select_manufacturing :=
6704 l_select_manufacturing || ', to_number(10) ';
6705 -- manufacturing_type
6706 l_select_manufacturing :=
6707 l_select_manufacturing || ', h.batch_id ';
6708 -- wip_entity_id
6709
6710 IF g_assembly_visible = 'T'
6711 THEN
6712 l_select_manufacturing :=
6713 l_select_manufacturing || ', msiv2.concatenated_segments ';
6714 -- product
6715 END IF;
6716
6717 l_from_manufacturing :=
6718 l_from_manufacturing || ', gme_batch_header h ';
6719
6720 IF g_assembly_visible = 'T'
6721 THEN
6722 l_from_manufacturing :=
6723 l_from_manufacturing || ', mtl_system_items_kfv msiv2 ';
6724 l_from_manufacturing :=
6725 l_from_manufacturing || ', gmd_recipe_validity_rules val ';
6726 END IF;
6727
6728 l_where_manufacturing :=
6729 l_where_manufacturing
6730 || ' and mtrl.txn_source_id = h.batch_id ';
6731
6732
6733 IF g_assembly_visible = 'T'
6734 THEN
6735 l_where_manufacturing :=
6736 l_where_manufacturing
6737 || ' and h.recipe_validity_rule_id = val.recipe_validity_rule_id ';
6738 /* Bug#5020669 svgonugu added val.organization_id IS NULL condition to consider validity rules
6739 which are for all orgs */
6740 l_where_manufacturing :=
6741 l_where_manufacturing
6742 || ' and (val.organization_id IS NULL OR h.organization_id = val.organization_id) ';
6743 l_where_manufacturing :=
6744 l_where_manufacturing
6745 || ' and val.inventory_item_id = msiv2.inventory_item_id ';
6746 /* Bug#5020669 svgonugu added val.organization_id IS NULL condition to consider validity rules
6747 which are for all orgs */
6748 l_where_manufacturing :=
6749 l_where_manufacturing
6750 || ' and (val.organization_id IS NULL OR val.organization_id = msiv2.organization_id) ';
6751 /* Bug#5300219 nsinghi. Added this where condition. */
6752 l_where_manufacturing :=
6753 l_where_manufacturing
6754 || ' and h.organization_id = msiv2.organization_id ';
6755 END IF;
6756
6757 IF g_source_header_visible = 'T'
6758 OR p_from_job IS NOT NULL
6759 OR p_to_job IS NOT NULL
6760 THEN
6761
6762 IF p_from_job IS NOT NULL
6763 THEN
6764 --Siva added lpad to fetch the batches with the given range
6765 l_where_manufacturing :=
6766 l_where_manufacturing
6767 || ' and lpad(h.batch_no,32,''0'') >= lpad(:from_job,32,''0'') ';
6768 END IF;
6769
6770 IF p_to_job IS NOT NULL
6771 THEN
6772 --Siva added lpad to fetch the batches with the given range
6773 l_where_manufacturing :=
6774 l_where_manufacturing
6775 || ' and lpad(h.batch_no,32,''0'') <= lpad(:to_job,32,''0'') ';
6776 END IF;
6777 END IF;
6778
6779 -- Navin Added for Primary Product filter:
6780 IF p_assembly_id IS NOT NULL
6781 THEN
6782 l_where_manufacturing :=
6783 l_where_manufacturing
6784 || ' and val.inventory_item_id = :assembly_id '; -- p_manufacturing_type = '10' Batch
6785 END IF;
6786
6787 IF p_from_start_date IS NOT NULL
6788 THEN
6789 l_where_manufacturing :=
6790 l_where_manufacturing
6791 || ' and h.actual_start_date >= :from_start_date ';
6792 END IF;
6793
6794 IF p_to_start_date IS NOT NULL
6795 THEN
6796 l_where_manufacturing :=
6797 l_where_manufacturing
6798 || ' and h.actual_start_date <= :to_start_date ';
6799 END IF;
6800 ELSIF p_manufacturing_type IS NULL
6801 THEN --type is null
6802 RETURN;
6803 END IF; --manufacturing_type
6804
6805 -- Execute the Manufacturing query
6806 IF p_summary_mode = 1 THEN
6807 l_select_manufacturing := NULL; -- for summary mode we wont need the manufacturing related data
6808 IF i = 1 THEN
6809 l_where_manufacturing := l_where_manufacturing || ' GROUP BY mmtt.wms_task_type ';
6810 ELSE
6811 l_where_manufacturing := l_where_manufacturing || ' GROUP BY wdt_task_type ';
6812 END IF;
6813 END IF;
6814 -- Concatenate the different sections of the query
6815 l_query :=
6816 l_insert_query
6817 || l_select_generic
6818 || l_select_manufacturing
6819 || l_from_generic
6820 || l_from_manufacturing
6821 || l_where_generic
6822 || l_where_manufacturing;
6823 -- Parse, Bind and Execute the dynamic query
6824 debug('l_query: ' || l_query,'query_manufacturing_tasks');
6825 l_query_handle := DBMS_SQL.open_cursor;
6826 DBMS_SQL.parse (l_query_handle, l_query, DBMS_SQL.native);
6827
6828 --generic bind variables
6829 IF p_organization_id IS NOT NULL
6830 THEN
6831 DBMS_SQL.bind_variable (l_query_handle,
6832 'org_id',
6833 p_organization_id
6834 );
6835 END IF;
6836
6837 IF p_subinventory_code IS NOT NULL
6838 THEN
6839 DBMS_SQL.bind_variable (l_query_handle,
6840 'sub_code',
6841 p_subinventory_code
6842 );
6843 END IF;
6844
6845 IF p_locator_id IS NOT NULL
6846 THEN
6847 DBMS_SQL.bind_variable (l_query_handle, 'loc_id', p_locator_id);
6848 END IF;
6849
6850 IF p_to_subinventory_code IS NOT NULL
6851 THEN
6852 DBMS_SQL.bind_variable (l_query_handle,
6853 'to_sub_code',
6854 p_to_subinventory_code
6855 );
6856 END IF;
6857
6858 IF p_to_locator_id IS NOT NULL
6859 THEN
6860 DBMS_SQL.bind_variable (l_query_handle,
6861 'to_loc_id',
6862 p_to_locator_id
6863 );
6864 END IF;
6865
6866 IF p_inventory_item_id IS NOT NULL
6867 THEN
6868 DBMS_SQL.bind_variable (l_query_handle,
6869 'item_id',
6870 p_inventory_item_id
6871 );
6872 END IF;
6873
6874 -- R12 : Additional Query Criteria using item type
6875 IF p_item_type_code IS NOT NULL
6876 THEN
6877 DBMS_SQL.bind_variable (l_query_handle,
6878 'item_type_code',
6879 p_item_type_code
6880 );
6881 END IF;
6882
6883
6884 IF p_category_set_id IS NOT NULL
6885 THEN
6886 DBMS_SQL.bind_variable (l_query_handle,
6887 'category_set_id',
6888 p_category_set_id
6889 );
6890 END IF;
6891
6892 IF p_item_category_id IS NOT NULL
6893 THEN
6894 DBMS_SQL.bind_variable (l_query_handle,
6895 'item_category_id',
6896 p_item_category_id
6897 );
6898 END IF;
6899
6900 IF p_person_id IS NOT NULL
6901 THEN
6902 DBMS_SQL.bind_variable (l_query_handle, 'person_id', p_person_id);
6903 END IF;
6904
6905 IF p_person_resource_id IS NOT NULL
6906 THEN
6907 DBMS_SQL.bind_variable (l_query_handle,
6908 'person_resource_id',
6909 p_person_resource_id
6910 );
6911 END IF;
6912
6913 IF p_equipment_type_id IS NOT NULL
6914 THEN
6915 DBMS_SQL.bind_variable (l_query_handle,
6916 'equipment_type_id',
6917 p_equipment_type_id
6918 );
6919 END IF;
6920
6921 IF p_machine_resource_id IS NOT NULL
6922 THEN
6923 DBMS_SQL.bind_variable (l_query_handle,
6924 'machine_resource_id',
6925 p_machine_resource_id
6926 );
6927 END IF;
6928
6929 IF p_machine_instance IS NOT NULL
6930 THEN
6931 DBMS_SQL.bind_variable (l_query_handle,
6932 'machine_instance',
6933 p_machine_instance
6934 );
6935 END IF;
6936
6937 IF p_user_task_type_id IS NOT NULL
6938 THEN
6939 DBMS_SQL.bind_variable (l_query_handle,
6940 'user_task_type_id',
6941 p_user_task_type_id
6942 );
6943 END IF;
6944
6945 IF p_from_task_quantity IS NOT NULL
6946 THEN
6947 DBMS_SQL.bind_variable (l_query_handle,
6948 'from_task_quantity',
6949 p_from_task_quantity
6950 );
6951 END IF;
6952
6953 IF p_to_task_quantity IS NOT NULL
6954 THEN
6955 DBMS_SQL.bind_variable (l_query_handle,
6956 'to_task_quantity',
6957 p_to_task_quantity
6958 );
6959 END IF;
6960
6961 IF p_from_task_priority IS NOT NULL
6962 THEN
6963 DBMS_SQL.bind_variable (l_query_handle,
6964 'from_task_priority',
6965 p_from_task_priority
6966 );
6967 END IF;
6968
6969 IF p_to_task_priority IS NOT NULL
6970 THEN
6971 DBMS_SQL.bind_variable (l_query_handle,
6972 'to_task_priority',
6973 p_to_task_priority
6974 );
6975 END IF;
6976
6977 IF p_from_creation_date IS NOT NULL
6978 THEN
6979 DBMS_SQL.bind_variable (l_query_handle,
6980 'from_creation_date',
6981 p_from_creation_date
6982 );
6983 END IF;
6984
6985 IF p_to_creation_date IS NOT NULL
6986 THEN
6987 DBMS_SQL.bind_variable (l_query_handle,
6988 'to_creation_date',
6989 p_to_creation_date
6990 );
6991 END IF;
6992
6993 -- R12: Additional Query criteria using age of the task
6994 IF p_age_uom_code IS NOT NULL
6995 THEN
6996
6997 IF p_age_min IS NOT NULL
6998 THEN
6999 DBMS_SQL.bind_variable (l_query_handle,
7000 'age_min',
7001 p_age_min
7002 );
7003 END IF;
7004
7005 IF p_age_max IS NOT NULL
7006 THEN
7007 DBMS_SQL.bind_variable (l_query_handle,
7008 'age_max',
7009 p_age_max
7010 );
7011
7012 END IF;
7013 END IF;
7014
7015 -- Manufacturing query specific bind variables
7016 IF p_from_job IS NOT NULL
7017 THEN
7018 DBMS_SQL.bind_variable (l_query_handle, 'from_job', p_from_job);
7019 END IF;
7020
7021 IF p_to_job IS NOT NULL
7022 THEN
7023 DBMS_SQL.bind_variable (l_query_handle, 'to_job', p_to_job);
7024 END IF;
7025
7026 IF p_assembly_id IS NOT NULL
7027 THEN
7028 DBMS_SQL.bind_variable (l_query_handle,
7029 'assembly_id',
7030 p_assembly_id
7031 );
7032 END IF;
7033
7034 IF p_from_start_date IS NOT NULL
7035 THEN
7036 DBMS_SQL.bind_variable (l_query_handle,
7037 'from_start_date',
7038 p_from_start_date
7039 );
7040 END IF;
7041
7042 IF p_to_start_date IS NOT NULL
7043 THEN
7044 DBMS_SQL.bind_variable (l_query_handle,
7045 'to_start_date',
7046 p_to_start_date
7047 );
7048 END IF;
7049
7050 IF p_from_line IS NOT NULL
7051 THEN
7052 DBMS_SQL.bind_variable (l_query_handle, 'from_line', p_from_line);
7053 END IF;
7054
7055 IF p_to_line IS NOT NULL
7056 THEN
7057 DBMS_SQL.bind_variable (l_query_handle, 'to_line', p_to_line);
7058 END IF;
7059
7060 IF p_department_id IS NOT NULL
7061 THEN
7062 DBMS_SQL.bind_variable (l_query_handle,
7063 'dept_id',
7064 p_department_id
7065 );
7066 END IF;
7067
7068 IF p_summary_mode = 1 THEN
7069 DBMS_SQL.DEFINE_COLUMN(l_query_handle, 1, l_wms_task_type);
7070 DBMS_SQL.DEFINE_COLUMN(l_query_handle, 2, l_task_count);
7071 END IF;
7072
7073 --mfg_query
7074 l_query_count := DBMS_SQL.EXECUTE (l_query_handle);
7075
7076 IF p_summary_mode = 1 THEN -- fetch the rows and put them into the global tables
7077 LOOP
7078 IF DBMS_SQL.FETCH_ROWS(l_query_handle)>0 THEN
7079 DBMS_SQL.COLUMN_VALUE(l_query_handle, 1, l_wms_task_type);
7080 DBMS_SQL.COLUMN_VALUE(l_query_handle, 2, l_task_count);
7081 g_wms_task_summary_tbl(l_wms_task_type).wms_task_type := l_wms_task_type;
7082 g_wms_task_summary_tbl(l_wms_task_type).task_count := g_wms_task_summary_tbl(l_wms_task_type).task_count + l_task_count;
7083 IF l_debug = 1 then
7084 debug('Task Type :' || g_wms_task_summary_tbl(l_wms_task_type).wms_task_type, 'query_manufacturing_tasks');
7085 debug('TaskCount :' || g_wms_task_summary_tbl(l_wms_task_type).task_count, 'query_manufacturing_tasks');
7086 END IF;
7087 ELSE
7088 EXIT; -- no more rows returned from dynamic SQL
7089 END IF;
7090 END LOOP;
7091 END IF;
7092 g_record_count := g_record_count + l_query_count;
7093 DBMS_SQL.close_cursor(l_query_handle);
7094 END LOOP;
7095 EXCEPTION
7096 WHEN OTHERS THEN -- Bug 4150145
7097 IF dbms_sql.is_open(l_query_handle) THEN
7098 dbms_sql.close_cursor(l_query_handle);
7099 END IF;
7100 DEBUG (SQLERRM, 'Task_planning.query_manufacturing_tasks');
7101 END query_manufacturing_tasks;
7102
7103 PROCEDURE query_cycle_count_tasks (
7104 p_add BOOLEAN DEFAULT FALSE,
7105 p_organization_id NUMBER DEFAULT NULL,
7106 p_subinventory_code VARCHAR2 DEFAULT NULL,
7107 p_locator_id NUMBER DEFAULT NULL,
7108 p_to_subinventory_code VARCHAR2 DEFAULT NULL,
7109 p_to_locator_id NUMBER DEFAULT NULL,
7110 p_inventory_item_id NUMBER DEFAULT NULL,
7111 p_category_set_id NUMBER DEFAULT NULL,
7112 p_item_category_id NUMBER DEFAULT NULL,
7113 p_person_id NUMBER DEFAULT NULL,
7114 p_person_resource_id NUMBER DEFAULT NULL,
7115 p_equipment_type_id NUMBER DEFAULT NULL,
7116 p_machine_resource_id NUMBER DEFAULT NULL,
7117 p_machine_instance VARCHAR2 DEFAULT NULL,
7118 p_user_task_type_id NUMBER DEFAULT NULL,
7119 p_from_task_quantity NUMBER DEFAULT NULL,
7120 p_to_task_quantity NUMBER DEFAULT NULL,
7121 p_from_task_priority NUMBER DEFAULT NULL,
7122 p_to_task_priority NUMBER DEFAULT NULL,
7123 p_from_creation_date DATE DEFAULT NULL,
7124 p_to_creation_date DATE DEFAULT NULL,
7125 p_cycle_count_name VARCHAR2 DEFAULT NULL,
7126 p_is_pending BOOLEAN DEFAULT FALSE,
7127 p_is_queued BOOLEAN DEFAULT FALSE,
7128 p_is_dispatched BOOLEAN DEFAULT FALSE,
7129 p_is_active BOOLEAN DEFAULT FALSE,
7130 p_is_completed BOOLEAN DEFAULT FALSE,
7131 -- R12 : Additional Query Criteria
7132 p_item_type_code VARCHAR2 DEFAULT NULL,
7133 p_age_uom_code VARCHAR2 DEFAULT NULL,
7134 p_age_min NUMBER DEFAULT NULL,
7135 p_age_max NUMBER DEFAULT NULL,
7136 p_summary_mode NUMBER DEFAULT 0
7137 -- R12 : Additional Query Criteria
7138 )
7139 IS
7140 l_join_wdt BOOLEAN;
7141 l_select_cc VARCHAR2 (4000);
7142 l_insert_cc VARCHAR2 (4000);
7143 l_from_cc VARCHAR2 (2000);
7144 l_where_cc VARCHAR2 (4000);
7145 l_group_by_cc VARCHAR2 (4000);
7146 l_query VARCHAR2 (10000);
7147 l_query_handle NUMBER; -- Handle for the dynamic sql
7148 l_query_count NUMBER;
7149 l_loop_start NUMBER;
7150 l_loop_end NUMBER;
7151 l_wms_task_type NUMBER; -- for bug 5129375
7152 l_task_count NUMBER;
7153 --R12: Additional Query criteria
7154 --Age UOM conversion factor
7155 n VARCHAR2 (10);
7156 l_debug NUMBER
7157 := NVL (fnd_profile.VALUE ('INV_DEBUG_TRACE'), 0);
7158 BEGIN
7159 -- Cycle tasks currently cannot have priorities, quantities or dest sub/loc. If user wants to
7160 -- query up tasks with certain priorities, quantities or dest sub/loc, we should not
7161 -- query cycle count tasks.
7162 IF p_from_task_priority IS NOT NULL
7163 OR p_to_task_priority IS NOT NULL
7164 OR p_from_task_quantity IS NOT NULL
7165 OR p_to_task_quantity IS NOT NULL
7166 OR p_to_subinventory_code IS NOT NULL
7167 OR p_to_locator_id IS NOT NULL
7168 THEN
7169 RETURN;
7170 END IF;
7171
7172 IF p_is_pending OR p_is_queued OR p_is_dispatched OR p_is_active
7173 THEN
7174 l_loop_start := 1;
7175 ELSE
7176 l_loop_start := 2;
7177 END IF;
7178
7179 IF p_is_completed
7180 THEN
7181 l_loop_end := 2;
7182 ELSE
7183 l_loop_end := 1;
7184 END IF;
7185
7186 FOR i IN l_loop_start .. l_loop_end
7187 LOOP
7188 l_insert_cc := NULL;
7189 l_select_cc := NULL;
7190 l_from_cc := NULL;
7191 l_where_cc := NULL;
7192
7193 IF i = 1
7194 THEN
7195 IF (p_is_pending)
7196 AND NOT (p_is_queued OR p_is_dispatched OR p_is_active)
7197 THEN
7198 -- Query records present only in MMTT
7199 l_join_wdt := FALSE;
7200 ELSIF p_is_pending
7201 AND (p_is_queued OR p_is_dispatched OR p_is_active)
7202 THEN
7203 -- Query records present only in MMTT as well as those in both MMTT and WDT
7204 l_join_wdt := TRUE;
7205 ELSIF NOT p_is_pending
7206 AND (p_is_queued OR p_is_dispatched OR p_is_active)
7207 THEN
7208 -- Query records present both in MMTT and WDT
7209 l_join_wdt := TRUE;
7210 END IF;
7211 ELSIF i = 2
7212 THEN -- Completed tasks
7213 l_join_wdt := TRUE;
7214 END IF;
7215
7216 l_insert_cc := 'INSERT INTO wms_waveplan_tasks_temp( ';
7217 l_insert_cc := l_insert_cc || 'transaction_temp_id ';
7218 l_insert_cc := l_insert_cc || ', inventory_item_id ';
7219 l_insert_cc := l_insert_cc || ', item ';
7220 l_insert_cc := l_insert_cc || ', organization_id ';
7221 l_insert_cc := l_insert_cc || ', revision ';
7222 l_insert_cc := l_insert_cc || ', subinventory ';
7223 l_insert_cc := l_insert_cc || ', locator_id ';
7224 l_insert_cc := l_insert_cc || ', locator ';
7225 l_insert_cc := l_insert_cc || ', status_id ';
7226 l_insert_cc := l_insert_cc || ', status_id_original ';
7227 l_insert_cc := l_insert_cc || ', status ';
7228 l_insert_cc := l_insert_cc || ', transaction_action_id ';
7229 l_insert_cc := l_insert_cc || ', transaction_source_type_id ';
7230
7231 IF g_txn_source_type_visible = 'T'
7232 THEN
7233 l_insert_cc := l_insert_cc || ', transaction_source_type ';
7234 END IF;
7235
7236 l_insert_cc := l_insert_cc || ', user_task_type_id ';
7237
7238 IF g_user_task_type_visible = 'T'
7239 THEN
7240 l_insert_cc := l_insert_cc || ', user_task_type ';
7241 END IF;
7242
7243 l_insert_cc := l_insert_cc || ', mmtt_last_update_date ';
7244 l_insert_cc := l_insert_cc || ', mmtt_last_updated_by ';
7245 l_insert_cc := l_insert_cc || ', priority ';
7246 l_insert_cc := l_insert_cc || ', priority_original ';
7247 l_insert_cc := l_insert_cc || ', task_type_id ';
7248 l_insert_cc := l_insert_cc || ', task_type ';
7249 l_insert_cc := l_insert_cc || ', creation_time ';
7250
7251 IF l_join_wdt
7252 THEN
7253 l_insert_cc := l_insert_cc || ', task_id ';
7254 l_insert_cc := l_insert_cc || ', person_id ';
7255 l_insert_cc := l_insert_cc || ', person_id_original ';
7256
7257 IF g_person_visible = 'T'
7258 THEN
7259 l_insert_cc := l_insert_cc || ', person ';
7260 END IF;
7261
7262 l_insert_cc := l_insert_cc || ', effective_start_date ';
7263 l_insert_cc := l_insert_cc || ', effective_end_date ';
7264 l_insert_cc := l_insert_cc || ', person_resource_id ';
7265
7266 IF g_person_resource_visible = 'T'
7267 THEN
7268 l_insert_cc := l_insert_cc || ', person_resource_code ';
7269 END IF;
7270
7271 l_insert_cc := l_insert_cc || ', machine_resource_id ';
7272
7273 IF g_machine_resource_visible = 'T'
7274 THEN
7275 l_insert_cc := l_insert_cc || ', machine_resource_code ';
7276 END IF;
7277
7278 l_insert_cc := l_insert_cc || ', equipment_instance ';
7279 l_insert_cc := l_insert_cc || ', dispatched_time ';
7280 l_insert_cc := l_insert_cc || ', loaded_time ';
7281 l_insert_cc := l_insert_cc || ', drop_off_time ';
7282 l_insert_cc := l_insert_cc || ', wdt_last_update_date ';
7283 l_insert_cc := l_insert_cc || ', wdt_last_updated_by ';
7284 END IF;
7285
7286 l_insert_cc := l_insert_cc || ', is_modified ';
7287
7288 IF g_source_header_visible = 'T' OR p_cycle_count_name IS NOT NULL
7289 THEN
7290 l_insert_cc := l_insert_cc || ', source_header ';
7291 END IF;
7292
7293 l_insert_cc := l_insert_cc || ') ';
7294 -- Build the generic select section of the query
7295 l_select_cc := 'SELECT ';
7296 l_group_by_cc := ' GROUP BY ';
7297
7298 l_select_cc := l_select_cc || 'MIN(mcce.cycle_count_entry_id), ';
7299 --transaction_temp_id
7300 l_select_cc := l_select_cc || 'mcce.inventory_item_id, ';
7301 l_group_by_cc := l_group_by_cc || 'mcce.inventory_item_id, ';
7302 --inventory_item_id
7303 l_select_cc := l_select_cc || 'msiv.concatenated_segments, '; --item
7304 l_group_by_cc := l_group_by_cc || 'msiv.concatenated_segments, ';
7305
7306 l_select_cc := l_select_cc || 'mcce.organization_id, ';
7307 --organization_id
7308 l_group_by_cc := l_group_by_cc || 'mcce.organization_id, ';
7309
7310 l_select_cc := l_select_cc || 'mcce.revision, '; --revision
7311 l_group_by_cc := l_group_by_cc || 'mcce.revision, ';
7312
7313 l_select_cc := l_select_cc || 'mcce.subinventory, '; --subinventory
7314 l_group_by_cc := l_group_by_cc || 'mcce.subinventory, ';
7315
7316 l_select_cc := l_select_cc || 'mcce.locator_id, '; --locator_id
7317 l_group_by_cc := l_group_by_cc || 'mcce.locator_id, ';
7318
7319 --locator
7320 l_select_cc :=
7321 l_select_cc
7322 || 'decode(milv.segment19, null, milv.concatenated_segments, null), ';
7323 l_group_by_cc :=
7324 l_group_by_cc
7325 || 'decode(milv.segment19, null, milv.concatenated_segments, null), ';
7326
7327 IF i = 1
7328 THEN
7329 IF l_join_wdt
7330 THEN
7331 --status_id
7332 l_select_cc :=
7333 l_select_cc || 'decode(wdt.status, null, 1, wdt.status), ';
7334 l_group_by_cc :=
7335 l_group_by_cc || 'decode(wdt.status, null, 1, wdt.status), ';
7336
7337 --status_id_original
7338 l_select_cc :=
7339 l_select_cc || 'decode(wdt.status, null, 1, wdt.status), ';
7340 l_group_by_cc :=
7341 l_group_by_cc || 'decode(wdt.status, null, 1, wdt.status), ';
7342
7343 --status
7344 l_select_cc :=
7345 l_select_cc
7346 || 'decode(decode(wdt.status, null, 1, wdt.status),'
7347 || '1, '''
7348 || g_status_codes (1)
7349 || ''', 2, '''
7350 || g_status_codes (2)
7351 || ''', 3, '''
7352 || g_status_codes (3)
7353 || ''', 4, '''
7354 || g_status_codes (4)
7355 || ''', 5, '''
7356 || g_status_codes (5)
7357 || ''', 6, '''
7358 || g_status_codes (6)
7359 || ''', 7, '''
7360 || g_status_codes (7)
7361 || ''', 8, '''
7362 || g_status_codes (8)
7363 || ''', '
7364 || '9, '''
7365 || g_status_codes (9)
7366 || '''), ';
7367 l_group_by_cc :=
7368 l_group_by_cc
7369 || 'decode(decode(wdt.status, null, 1, wdt.status),'
7370 || '1, '''
7371 || g_status_codes (1)
7372 || ''', 2, '''
7373 || g_status_codes (2)
7374 || ''', 3, '''
7375 || g_status_codes (3)
7376 || ''', 4, '''
7377 || g_status_codes (4)
7378 || ''', 5, '''
7379 || g_status_codes (5)
7380 || ''', 6, '''
7381 || g_status_codes (6)
7382 || ''', 7, '''
7383 || g_status_codes (7)
7384 || ''', 8, '''
7385 || g_status_codes (8)
7386 || ''', '
7387 || '9, '''
7388 || g_status_codes (9)
7389 || '''), ';
7390
7391 ELSE
7392 --status_id
7393 l_select_cc := l_select_cc || '1, ';
7394 --status_id_original
7395 l_select_cc := l_select_cc || '1, ';
7396 --status
7397 l_select_cc :=
7398 l_select_cc || '''' || g_status_codes (1)
7399 || ''', ';
7400 END IF;
7401 ELSIF i = 2
7402 THEN
7403 l_select_cc := l_select_cc || '6, '; --status_id
7404 l_select_cc := l_select_cc || '6, '; --status_id_original
7405 l_select_cc := l_select_cc || '''' || g_status_codes (6)
7406 || ''', '; --status
7407 END IF;
7408
7409 l_select_cc := l_select_cc || '4, '; --transaction_action_id
7410 l_select_cc := l_select_cc || '9, '; --transaction_source_type_id
7411
7412 IF g_txn_source_type_visible = 'T'
7413 THEN
7414 l_select_cc :=
7415 l_select_cc || 'mtst.transaction_source_type_name, ';
7416
7417 l_group_by_cc :=
7418 l_group_by_cc || 'mtst.transaction_source_type_name, '; --transaction_source_type
7419 END IF;
7420
7421 l_select_cc := l_select_cc || 'mcce.standard_operation_id, ';
7422 l_group_by_cc := l_group_by_cc || 'mcce.standard_operation_id, ';
7423 --user_task_type_id
7424
7425 IF g_user_task_type_visible = 'T'
7426 THEN
7427 l_select_cc := l_select_cc || 'bso.operation_code, ';
7428 l_group_by_cc := l_group_by_cc || 'bso.operation_code, ';
7429 --user_task_type
7430 END IF;
7431
7432 l_select_cc := l_select_cc || 'mcce.last_update_date, ';
7433 --mmtt_last_update_date
7434 l_group_by_cc := l_group_by_cc || 'mcce.last_update_date, ';
7435
7436 l_select_cc := l_select_cc || 'mcce.last_updated_by, ';
7437 --mmtt_last_updated_by
7438 l_group_by_cc := l_group_by_cc || 'mcce.last_updated_by, ';
7439
7440 l_select_cc := l_select_cc || 'mcce.task_priority, '; --priority
7441 l_group_by_cc := l_group_by_cc || 'mcce.task_priority, ';
7442
7443 l_select_cc := l_select_cc || 'mcce.task_priority, ';
7444 --priority_original
7445 l_group_by_cc := l_group_by_cc || 'mcce.task_priority, ';
7446
7447 l_select_cc := l_select_cc || '3, '; --task_type_id
7448 l_select_cc := l_select_cc || '''' || g_task_types (3) || ''', ';
7449 --task_type
7450 l_select_cc := l_select_cc || 'mcce.creation_date, '; --creation_time
7451 l_group_by_cc := l_group_by_cc || 'mcce.creation_date, ';
7452
7453 IF l_join_wdt
7454 THEN
7455 l_select_cc := l_select_cc || 'wdt.task_id, '; --task_id
7456 l_group_by_cc := l_group_by_cc || 'wdt.task_id, ';
7457 l_select_cc := l_select_cc || 'wdt.person_id, '; --person_id
7458 l_group_by_cc := l_group_by_cc || 'wdt.person_id, ';
7459 l_select_cc := l_select_cc || 'wdt.person_id, ';
7460 --person_id_original
7461 l_group_by_cc := l_group_by_cc || 'wdt.person_id, ';
7462
7463 IF g_person_visible = 'T'
7464 THEN
7465 l_select_cc := l_select_cc || 'pap.full_name, '; --person_id
7466 l_group_by_cc := l_group_by_cc || 'pap.full_name, ';
7467 END IF;
7468
7469 l_select_cc := l_select_cc || 'wdt.effective_start_date, ';
7470 --effective_start_date
7471 l_group_by_cc := l_group_by_cc || 'wdt.effective_start_date, ';
7472 l_select_cc := l_select_cc || 'wdt.effective_end_date, ';
7473 --effective_end_date
7474 l_group_by_cc := l_group_by_cc || 'wdt.effective_end_date, ';
7475 l_select_cc := l_select_cc || 'wdt.person_resource_id, ';
7476 --person_resource_id
7477 l_group_by_cc := l_group_by_cc || 'wdt.person_resource_id, ';
7478
7479 IF g_person_resource_visible = 'T'
7480 THEN
7481 l_select_cc := l_select_cc || 'br1.resource_code, ';
7482 --person_resource_code
7483 l_group_by_cc := l_group_by_cc || 'br1.resource_code, ';
7484 END IF;
7485
7486 l_select_cc := l_select_cc || 'wdt.machine_resource_id, ';
7487 --machine_resource_id
7488 l_group_by_cc := l_group_by_cc || 'wdt.machine_resource_id, ';
7489
7490 IF g_machine_resource_visible = 'T'
7491 THEN
7492 l_select_cc := l_select_cc || 'br2.resource_code, ';
7493 --machine_resource_code
7494 l_group_by_cc := l_group_by_cc || 'br2.resource_code, ';
7495 END IF;
7496
7497 l_select_cc := l_select_cc || 'wdt.equipment_instance, ';
7498 --equipment_instance
7499 l_select_cc := l_select_cc || 'wdt.dispatched_time, ';
7500 --dispatched_time
7501 l_select_cc := l_select_cc || 'wdt.loaded_time, '; --loaded_time
7502 l_select_cc := l_select_cc || 'wdt.drop_off_time, ';
7503 --drop_off_time
7504 l_select_cc := l_select_cc || 'wdt.last_update_date, ';
7505 --wdt_last_update_date
7506 l_select_cc := l_select_cc || 'wdt.last_updated_by, ';
7507 --wdt_last_updated_by
7508
7509 l_group_by_cc := l_group_by_cc || 'wdt.equipment_instance, ';
7510 --equipment_instance
7511 l_group_by_cc := l_group_by_cc || 'wdt.dispatched_time, ';
7512 --dispatched_time
7513 l_group_by_cc := l_group_by_cc || 'wdt.loaded_time, '; --loaded_time
7514 l_group_by_cc := l_group_by_cc || 'wdt.drop_off_time, ';
7515 --drop_off_time
7516 l_group_by_cc := l_group_by_cc || 'wdt.last_update_date, ';
7517 --wdt_last_update_date
7518 l_group_by_cc := l_group_by_cc || 'wdt.last_updated_by, ';
7519 --wdt_last_updated_by
7520 END IF;
7521
7522 l_select_cc := l_select_cc || '''N'' '; -- is_modified
7523
7524 IF g_source_header_visible = 'T' OR p_cycle_count_name IS NOT NULL
7525 THEN
7526 l_select_cc := l_select_cc || ', mcch.cycle_count_header_name ';
7527 --source header
7528 l_group_by_cc := l_group_by_cc || 'mcch.cycle_count_header_name ';
7529 END IF;
7530
7531 -- Build the generic from section of the query
7532 l_from_cc := ' FROM ';
7533 l_from_cc := l_from_cc || ' mtl_system_items_kfv msiv ';
7534 l_from_cc := l_from_cc || ', mtl_item_locations_kfv milv ';
7535 l_from_cc := l_from_cc || ', mtl_cycle_count_entries mcce ';
7536
7537 /*Bug 3856227 -Added the table mtl_cycle_count_headers in the from clause
7538 if the task is of status pending, queued, dispatched, active
7539 or if the cycle count name is not null.*/
7540 IF i=1 THEN
7541 l_from_cc := l_from_cc || ', mtl_cycle_count_headers mcch ' ;
7542 ELSIF i=2 THEN
7543 IF g_source_header_visible = 'T' OR p_cycle_count_name IS NOT NULL THEN
7544 l_from_cc := l_from_cc || ', mtl_cycle_count_headers mcch ' ;
7545 END IF;
7546 END IF;
7547 -- End of fix for Bug 3856227
7548
7549 IF l_join_wdt
7550 THEN
7551 IF i = 1
7552 THEN
7553 l_from_cc := l_from_cc || ', wms_dispatched_tasks wdt ';
7554 ELSIF i = 2
7555 THEN
7556 l_from_cc :=
7557 l_from_cc || ', wms_dispatched_tasks_history wdt ';
7558 END IF;
7559 END IF;
7560
7561 IF p_item_category_id IS NOT NULL OR p_category_set_id IS NOT NULL
7562 THEN
7563 l_from_cc := l_from_cc || ', mtl_item_categories mic ';
7564 END IF;
7565
7566 IF g_user_task_type_visible = 'T'
7567 THEN
7568 l_from_cc := l_from_cc || ', bom_standard_operations bso ';
7569 END IF;
7570
7571 IF g_txn_source_type_visible = 'T'
7572 THEN
7573 l_from_cc := l_from_cc || ', mtl_txn_source_types mtst ';
7574 END IF;
7575
7576 IF (i = 1 AND (p_is_queued OR p_is_dispatched OR p_is_active))
7577 OR (i = 2 AND p_is_completed)
7578 THEN
7579 IF g_person_resource_visible = 'T'
7580 THEN
7581 l_from_cc := l_from_cc || ', bom_resources br1 ';
7582 END IF;
7583
7584 IF g_machine_resource_visible = 'T'
7585 THEN
7586 l_from_cc := l_from_cc || ', bom_resources br2 ';
7587 END IF;
7588
7589 IF g_person_visible = 'T'
7590 THEN
7591 l_from_cc := l_from_cc || ', per_all_people_f pap ';
7592 END IF;
7593 END IF;
7594
7595 -- Build the generic where section of the query
7596 IF p_add
7597 THEN
7598 l_where_cc :=
7599 'WHERE NOT exists (SELECT 1 FROM wms_waveplan_tasks_temp ';
7600 l_where_cc :=
7601 l_where_cc
7602 || 'WHERE transaction_temp_id = mcce.cycle_count_entry_id ';
7603 l_where_cc := l_where_cc || 'AND task_type_id = 3) ';
7604 ELSE
7605 l_where_cc := 'WHERE 1=1 ';
7606 END IF;
7607
7608 IF i = 1
7609 THEN
7610 IF p_is_pending
7611 AND NOT (p_is_queued OR p_is_dispatched OR p_is_active)
7612 THEN
7613 -- Query records present only in MCCE
7614 IF p_is_pending
7615 THEN
7616 l_where_cc :=
7617 l_where_cc
7618 || 'AND NOT EXISTS (SELECT 1 FROM wms_dispatched_tasks ';
7619 l_where_cc :=
7620 l_where_cc
7621 || ' WHERE transaction_temp_id = mcce.cycle_count_entry_id) ';
7622 END IF;
7623 ELSIF p_is_pending
7624 AND (p_is_queued OR p_is_dispatched OR p_is_active)
7625 THEN
7626 -- Query records present only in MCCE as well as those in both MCCE and WDT
7627 l_where_cc :=
7628 l_where_cc
7629 || 'AND mcce.cycle_count_entry_id = wdt.transaction_temp_id(+) ';
7630 l_where_cc :=
7631 l_where_cc
7632 || 'AND decode(wdt.status, null, 1, wdt.status) in ( ';
7633
7634 IF p_is_pending
7635 THEN
7636 l_where_cc := l_where_cc || '1';
7637 END IF;
7638
7639 IF p_is_queued
7640 THEN
7641 IF p_is_pending
7642 THEN
7643 l_where_cc := l_where_cc || ', 2';
7644 ELSE
7645 l_where_cc := l_where_cc || '2';
7646 END IF;
7647 END IF;
7648
7649 IF p_is_dispatched
7650 THEN
7651 IF p_is_pending OR p_is_queued
7652 THEN
7653 l_where_cc := l_where_cc || ', 3';
7654 ELSE
7655 l_where_cc := l_where_cc || '3';
7656 END IF;
7657 END IF;
7658
7659 IF p_is_active
7660 THEN
7661 IF p_is_pending OR p_is_queued OR p_is_dispatched
7662 THEN
7663 l_where_cc := l_where_cc || ', 9';
7664 ELSE
7665 l_where_cc := l_where_cc || '9';
7666 END IF;
7667 END IF;
7668
7669 l_where_cc := l_where_cc || ') ';
7670
7671 IF g_person_resource_visible = 'T'
7672 THEN
7673 l_where_cc :=
7674 l_where_cc
7675 || 'AND wdt.person_resource_id = br1.resource_id(+) ';
7676 END IF;
7677
7678 IF g_machine_resource_visible = 'T'
7679 THEN
7680 l_where_cc :=
7681 l_where_cc
7682 || 'AND wdt.machine_resource_id = br2.resource_id(+) ';
7683 END IF;
7684
7685 IF g_person_visible = 'T'
7686 THEN
7687 l_where_cc :=
7688 l_where_cc || 'AND wdt.person_id = pap.person_id(+) ';
7689 l_where_cc :=
7690 l_where_cc
7691 || 'AND wdt.effective_start_date >= pap.effective_start_date(+) ';
7692 l_where_cc :=
7693 l_where_cc
7694 || 'AND wdt.effective_end_date <= pap.effective_end_date(+) ';
7695 END IF;
7696 ELSIF NOT p_is_pending
7697 AND (p_is_queued OR p_is_dispatched OR p_is_active)
7698 THEN
7699 -- Query records present both in MMTT and WDT
7700 l_where_cc :=
7701 l_where_cc
7702 || 'AND mcce.cycle_count_entry_id = wdt.transaction_temp_id ';
7703 l_where_cc := l_where_cc || 'AND wdt.task_type = 3 ';
7704 -- cycle count task
7705 l_where_cc := l_where_cc || 'AND wdt.status in ( ';
7706
7707 IF p_is_queued
7708 THEN
7709 l_where_cc := l_where_cc || '2';
7710 END IF;
7711
7712 IF p_is_dispatched
7713 THEN
7714 IF p_is_queued
7715 THEN
7716 l_where_cc := l_where_cc || ', 3';
7717 ELSE
7718 l_where_cc := l_where_cc || '3';
7719 END IF;
7720 END IF;
7721
7722 IF p_is_active
7723 THEN
7724 IF p_is_queued OR p_is_dispatched
7725 THEN
7726 l_where_cc := l_where_cc || ', 9';
7727 ELSE
7728 l_where_cc := l_where_cc || '9';
7729 END IF;
7730 END IF;
7731
7732 l_where_cc := l_where_cc || ') ';
7733
7734 IF g_person_resource_visible = 'T'
7735 THEN
7736 l_where_cc :=
7737 l_where_cc
7738 || 'AND wdt.person_resource_id = br1.resource_id ';
7739 END IF;
7740
7741 IF g_machine_resource_visible = 'T'
7742 THEN
7743 l_where_cc :=
7744 l_where_cc
7745 || 'AND wdt.machine_resource_id = br2.resource_id(+) ';
7746 END IF;
7747
7748 IF g_person_visible = 'T'
7749 THEN
7750 l_where_cc :=
7751 l_where_cc || 'AND wdt.person_id = pap.person_id ';
7752 l_where_cc :=
7753 l_where_cc
7754 || 'AND wdt.effective_start_date >= pap.effective_start_date ';
7755 l_where_cc :=
7756 l_where_cc
7757 || 'AND wdt.effective_end_date <= pap.effective_end_date ';
7758 END IF;
7759 END IF;
7760 ELSIF i = 2
7761 THEN
7762 l_where_cc :=
7763 l_where_cc
7764 || 'AND mcce.cycle_count_entry_id = wdt.transaction_id ';
7765 l_where_cc :=
7766 l_where_cc
7767 || 'AND wdt.task_type = 3 ';
7768
7769 IF g_person_resource_visible = 'T'
7770 THEN
7771 l_where_cc :=
7772 l_where_cc
7773 || 'AND wdt.person_resource_id = br1.resource_id ';
7774 END IF;
7775
7776 IF g_machine_resource_visible = 'T'
7777 THEN
7778 l_where_cc :=
7779 l_where_cc
7780 || 'AND wdt.machine_resource_id = br2.resource_id(+) ';
7781 END IF;
7782
7783 IF g_person_visible = 'T'
7784 THEN
7785 l_where_cc :=
7786 l_where_cc || 'AND wdt.person_id = pap.person_id ';
7787 l_where_cc :=
7788 l_where_cc
7789 || 'AND wdt.effective_start_date >= pap.effective_start_date ';
7790 l_where_cc :=
7791 l_where_cc
7792 || 'AND wdt.effective_end_date <= pap.effective_end_date ';
7793 END IF;
7794 END IF;
7795
7796 IF i = 1
7797 THEN
7798 -- Bug #3732568. Added Rejected status counts (4) in the NOT IN list.
7799 l_where_cc := l_where_cc || 'AND mcce.entry_status_code not in (2,4, 5) '; -- 3620782
7800
7801 -- Bug 3856227-Added the following for pending, queued, active, dispatched tasks considering the disable date of the cycle count .
7802 -- Bug 5519506- Added trunc to the comparision for disbale date to both sides.
7803 l_where_cc := l_where_cc || 'AND mcce.cycle_count_header_id = mcch.cycle_count_header_id ' ;
7804 l_where_cc := l_where_cc || 'AND trunc(nvl(mcch.disable_date,sysdate+1)) > trunc(sysdate) ' ;
7805 -- End of fix for Bug 3856227.
7806 ELSIF i = 2
7807 THEN
7808 -- Bug #3732568. Added Rejected status counts (4) in the NOT IN list.
7809 l_where_cc := l_where_cc || 'AND mcce.entry_status_code in (2,4, 5) '; -- 3620782
7810
7811 --Bug 3856227 - Handled the condition for cycle count name entered
7812 IF g_source_header_visible = 'T' OR p_cycle_count_name IS NOT NULL THEN
7813 l_where_cc := l_where_cc || 'AND mcce.cycle_count_header_id = mcch.cycle_count_header_id ' ;
7814 END IF;
7815 -- End of fix for Bug 3856227.
7816 END IF;
7817
7818 l_where_cc :=
7819 l_where_cc || 'AND mcce.organization_id = msiv.organization_id ';
7820 l_where_cc :=
7821 l_where_cc
7822 || 'AND mcce.inventory_item_id = msiv.inventory_item_id ';
7823 l_where_cc :=
7824 l_where_cc
7825 || 'AND mcce.organization_id = milv.organization_id(+) ';
7826 l_where_cc :=
7827 l_where_cc
7828 || 'AND mcce.locator_id = milv.inventory_location_id(+) ';
7829
7830 IF g_txn_source_type_visible = 'T'
7831 THEN
7832 l_where_cc :=
7833 l_where_cc || 'AND mtst.transaction_source_type_id = 9 ';
7834 END IF;
7835
7836 IF g_user_task_type_visible = 'T'
7837 THEN
7838 l_where_cc :=
7839 l_where_cc
7840 || 'AND mcce.standard_operation_id = bso.standard_operation_id(+) ';
7841 END IF;
7842
7843 IF p_organization_id IS NOT NULL
7844 THEN
7845 l_where_cc := l_where_cc || 'AND mcce.organization_id = :org_id ';
7846 END IF;
7847
7848 IF p_subinventory_code IS NOT NULL
7849 THEN
7850 l_where_cc :=
7851 --l_where_cc || 'AND mcce.subinventory_code = :sub_code ';
7852 --Bug 6688574 :Column in mcce is subinventory.
7853 l_where_cc || 'AND mcce.subinventory = :sub_code ';
7854 END IF;
7855
7856 IF p_locator_id IS NOT NULL
7857 THEN
7858 l_where_cc := l_where_cc || 'AND mcce.locator_id = :loc_id ';
7859 END IF;
7860
7861 IF p_inventory_item_id IS NOT NULL
7862 THEN
7863 l_where_cc :=
7864 l_where_cc || 'AND mcce.inventory_item_id = :item_id ';
7865 END IF;
7866
7867 -- R12 : Additional Query Criteria using item type
7868 IF p_item_type_code IS NOT NULL
7869 THEN
7870 l_where_cc :=
7871 l_where_cc || 'AND msiv.item_type = :item_type_code ';
7872 END IF;
7873
7874 IF p_category_set_id IS NOT NULL
7875 THEN
7876 l_where_cc :=
7877 l_where_cc || 'AND mic.category_set_id = :category_set_id ';
7878 END IF;
7879
7880 IF p_item_category_id IS NOT NULL
7881 THEN
7882 l_where_cc :=
7883 l_where_cc
7884 || 'AND mcce.organization_id = mic.organization_id ';
7885 l_where_cc :=
7886 l_where_cc
7887 || 'AND mcce.inventory_item_id = mic.inventory_item_id ';
7888 l_where_cc :=
7889 l_where_cc || 'AND mic.category_id = :item_category_id ';
7890 END IF;
7891
7892 IF p_person_id IS NOT NULL
7893 THEN
7894 l_where_cc := l_where_cc || 'AND wdt.person_id = :person_id ';
7895 END IF;
7896
7897 IF p_person_resource_id IS NOT NULL
7898 THEN
7899 l_where_cc :=
7900 l_where_cc
7901 || 'AND wdt.person_resource_id = :person_resource_id ';
7902 END IF;
7903
7904 IF p_equipment_type_id IS NOT NULL
7905 THEN
7906 l_where_cc :=
7907 l_where_cc || 'AND wdt.equipment_id = :equipment_type_id ';
7908 END IF;
7909
7910 IF p_machine_resource_id IS NOT NULL
7911 THEN
7912 l_where_cc :=
7913 l_where_cc
7914 || 'AND wdt.machine_resource_id = :machine_resource_id ';
7915 END IF;
7916
7917 IF p_machine_instance IS NOT NULL
7918 THEN
7919 l_where_cc :=
7920 l_where_cc
7921 || 'AND wdt.equipment_instance = :machine_instance ';
7922 END IF;
7923
7924 IF p_user_task_type_id IS NOT NULL
7925 THEN
7926 l_where_cc :=
7927 l_where_cc
7928 || 'AND mcce.standard_operation_id = :user_task_type_id ';
7929 END IF;
7930
7931 IF p_from_task_priority IS NOT NULL
7932 THEN
7933 l_where_cc :=
7934 l_where_cc || 'AND mcce.task_priority >= :from_task_priority ';
7935 END IF;
7936
7937 IF p_to_task_priority IS NOT NULL
7938 THEN
7939 l_where_cc :=
7940 l_where_cc || 'AND mcce.task_priority <= :to_task_priority ';
7941 END IF;
7942
7943 IF p_from_creation_date IS NOT NULL
7944 THEN
7945 l_where_cc :=
7946 l_where_cc || 'AND mcce.creation_date >= :from_creation_date ';
7947 END IF;
7948
7949 IF p_to_creation_date IS NOT NULL
7950 THEN
7951 l_where_cc :=
7952 l_where_cc || 'AND mcce.creation_date <= :to_creation_date ';
7953 END IF;
7954
7955 -- R12: Additional Query criteria using age of the task
7956 IF p_age_uom_code IS NOT NULL
7957 THEN
7958
7959 IF p_age_uom_code = 2 THEN -- Minutes
7960 n := '*(24 * 60)';
7961 ELSIF p_age_uom_code = 3 THEN -- Hours
7962 n := '*(24)';
7963 ELSIF p_age_uom_code = 4 THEN -- Days
7964 n := '*(1)';
7965 ELSIF p_age_uom_code = 5 THEN -- Weeks
7966 n := '/(7)';
7967 ELSIF p_age_uom_code = 6 THEN -- Months
7968 n := '/(7 * 31)';
7969 END IF;
7970
7971 IF p_age_min IS NOT NULL
7972 THEN
7973 l_where_cc :=
7974 l_where_cc
7975 || 'AND (sysdate - mcce.creation_date)'||n||' >= :age_min ';
7976 END IF;
7977
7978 IF p_age_max IS NOT NULL
7979 THEN
7980 l_where_cc :=
7981 l_where_cc
7982 || 'AND (sysdate - mcce.creation_date)'||n||' <= :age_max ';
7983 END IF;
7984 END IF;
7985
7986
7987 IF g_source_header_visible = 'T' OR p_cycle_count_name IS NOT NULL
7988 THEN
7989 /* Bug 3856227 - Commented the from and where clause.
7990 Already Handled in the from and where condition in the fix for the bug.
7991
7992 l_from_cc := l_from_cc || ',mtl_cycle_count_headers mcch ';
7993 l_where_cc :=
7994 l_where_cc
7995 || ' and mcce.cycle_count_header_id = mcch.cycle_count_header_id '; */
7996 -- End of fix for Bug 3856227
7997
7998 IF p_cycle_count_name IS NOT NULL
7999 THEN
8000 l_where_cc :=
8001 l_where_cc
8002 || ' and mcch.cycle_count_header_name = :cc_header_name ';
8003 END IF;
8004 END IF;
8005
8006 -- Execute the Cycle Count query
8007
8008 -- Concatenate the different sections of the query
8009 IF p_summary_mode = 0 THEN
8010 l_query := l_insert_cc || l_select_cc || l_from_cc || l_where_cc || l_group_by_cc ;
8011 ELSE
8012 l_query := l_select_cc || l_from_cc || l_where_cc || l_group_by_cc ;
8013 END IF;
8014
8015 -- Parse, Bind and Execute the dynamic query
8016 l_query_handle := DBMS_SQL.open_cursor;
8017 DBMS_SQL.parse (l_query_handle, l_query, DBMS_SQL.native);
8018
8019 --generic bind variables
8020 IF p_organization_id IS NOT NULL
8021 THEN
8022 DBMS_SQL.bind_variable (l_query_handle,
8023 'org_id',
8024 p_organization_id
8025 );
8026 END IF;
8027
8028 IF p_subinventory_code IS NOT NULL
8029 THEN
8030 DBMS_SQL.bind_variable (l_query_handle,
8031 'sub_code',
8032 p_subinventory_code
8033 );
8034 END IF;
8035
8036 IF p_locator_id IS NOT NULL
8037 THEN
8038 DBMS_SQL.bind_variable (l_query_handle, 'loc_id', p_locator_id);
8039 END IF;
8040
8041 IF p_inventory_item_id IS NOT NULL
8042 THEN
8043 DBMS_SQL.bind_variable (l_query_handle,
8044 'item_id',
8045 p_inventory_item_id
8046 );
8047 END IF;
8048
8049 -- R12 : Additional Query Criteria using item type
8050 IF p_item_type_code IS NOT NULL
8051 THEN
8052 DBMS_SQL.bind_variable (l_query_handle,
8053 'item_type_code',
8054 p_item_type_code
8055 );
8056 END IF;
8057
8058
8059 IF p_category_set_id IS NOT NULL
8060 THEN
8061 DBMS_SQL.bind_variable (l_query_handle,
8062 'category_set_id',
8063 p_category_set_id
8064 );
8065 END IF;
8066
8067 IF p_item_category_id IS NOT NULL
8068 THEN
8069 DBMS_SQL.bind_variable (l_query_handle,
8070 'item_category_id',
8071 p_item_category_id
8072 );
8073 END IF;
8074
8075 IF p_person_id IS NOT NULL
8076 THEN
8077 DBMS_SQL.bind_variable (l_query_handle, 'person_id', p_person_id);
8078 END IF;
8079
8080 IF p_person_resource_id IS NOT NULL
8081 THEN
8082 DBMS_SQL.bind_variable (l_query_handle,
8083 'person_resource_id',
8084 p_person_resource_id
8085 );
8086 END IF;
8087
8088 IF p_equipment_type_id IS NOT NULL
8089 THEN
8090 DBMS_SQL.bind_variable (l_query_handle,
8091 'equipment_type_id',
8092 p_equipment_type_id
8093 );
8094 END IF;
8095
8096 IF p_machine_resource_id IS NOT NULL
8097 THEN
8098 DBMS_SQL.bind_variable (l_query_handle,
8099 'machine_resource_id',
8100 p_machine_resource_id
8101 );
8102 END IF;
8103
8104 IF p_machine_instance IS NOT NULL
8105 THEN
8106 DBMS_SQL.bind_variable (l_query_handle,
8107 'machine_instance',
8108 p_machine_instance
8109 );
8110 END IF;
8111
8112 IF p_user_task_type_id IS NOT NULL
8113 THEN
8114 DBMS_SQL.bind_variable (l_query_handle,
8115 'user_task_type_id',
8116 p_user_task_type_id
8117 );
8118 END IF;
8119
8120 IF p_from_task_priority IS NOT NULL
8121 THEN
8122 DBMS_SQL.bind_variable (l_query_handle,
8123 'from_task_priority',
8124 p_from_task_priority
8125 );
8126 END IF;
8127
8128 IF p_to_task_priority IS NOT NULL
8129 THEN
8130 DBMS_SQL.bind_variable (l_query_handle,
8131 'to_task_priority',
8132 p_to_task_priority
8133 );
8134 END IF;
8135
8136 IF p_from_creation_date IS NOT NULL
8137 THEN
8138 DBMS_SQL.bind_variable (l_query_handle,
8139 'from_creation_date',
8140 p_from_creation_date
8141 );
8142 END IF;
8143
8144 IF p_to_creation_date IS NOT NULL
8145 THEN
8146 DBMS_SQL.bind_variable (l_query_handle,
8147 'to_creation_date',
8148 p_to_creation_date
8149 );
8150 END IF;
8151
8152 -- R12: Additional Query criteria using age of the task
8153 IF p_age_uom_code IS NOT NULL
8154 THEN
8155
8156 IF p_age_min IS NOT NULL
8157 THEN
8158 DBMS_SQL.bind_variable (l_query_handle,
8159 'age_min',
8160 p_age_min
8161 );
8162 END IF;
8163
8164 IF p_age_max IS NOT NULL
8165 THEN
8166 DBMS_SQL.bind_variable (l_query_handle,
8167 'age_max',
8168 p_age_max
8169 );
8170
8171 END IF;
8172 END IF;
8173
8174 --Cycle count specifc bind variables
8175 IF p_cycle_count_name IS NOT NULL
8176 THEN
8177 DBMS_SQL.bind_variable (l_query_handle,
8178 'cc_header_name',
8179 p_cycle_count_name
8180 );
8181 END IF;
8182
8183
8184 --execute the query
8185 l_query_count := DBMS_SQL.EXECUTE (l_query_handle);
8186 g_record_count := g_record_count + l_query_count;
8187
8188 IF p_summary_mode = 1 THEN
8189 LOOP
8190 IF DBMS_SQL.FETCH_ROWS(l_query_handle) = 0 THEN
8191 EXIT;
8192 END IF;
8193 END LOOP;
8194 g_wms_task_summary_tbl(wms_waveplan_tasks_pvt.g_task_type_cycle_count).wms_task_type := wms_waveplan_tasks_pvt.g_task_type_cycle_count;
8195 g_wms_task_summary_tbl(wms_waveplan_tasks_pvt.g_task_type_cycle_count).task_count := g_wms_task_summary_tbl(wms_waveplan_tasks_pvt.g_task_type_cycle_count).task_count + dbms_sql.last_row_count;
8196 IF l_debug = 1 THEN
8197 debug(' Query :' || l_query , 'query_cc_tasks');
8198 debug('Task Type :' || g_wms_task_summary_tbl(wms_waveplan_tasks_pvt.g_task_type_cycle_count).wms_task_type, 'query_cycle_count_tasks');
8199 debug('TaskCount :' || g_wms_task_summary_tbl(wms_waveplan_tasks_pvt.g_task_type_cycle_count).task_count, 'query_cycle_count_tasks');
8200 END IF;
8201 END IF;
8202
8203 DBMS_SQL.close_cursor(l_query_handle);
8204 END LOOP;
8205 EXCEPTION
8206 WHEN OTHERS THEN -- Bug 4150145
8207 IF dbms_sql.is_open(l_query_handle) THEN
8208 dbms_sql.close_cursor(l_query_handle);
8209 END IF;
8210 DEBUG (SQLERRM, 'Task_planning.query_cycle_count_tasks');
8211 END query_cycle_count_tasks;
8212
8213 PROCEDURE query_mo_tasks (
8214 p_add BOOLEAN DEFAULT FALSE,
8215 p_organization_id NUMBER DEFAULT NULL,
8216 p_subinventory_code VARCHAR2 DEFAULT NULL,
8217 p_locator_id NUMBER DEFAULT NULL,
8218 p_to_subinventory_code VARCHAR2 DEFAULT NULL,
8219 p_to_locator_id NUMBER DEFAULT NULL,
8220 p_inventory_item_id NUMBER DEFAULT NULL,
8221 p_category_set_id NUMBER DEFAULT NULL,
8222 p_item_category_id NUMBER DEFAULT NULL,
8223 p_person_id NUMBER DEFAULT NULL,
8224 p_person_resource_id NUMBER DEFAULT NULL,
8225 p_equipment_type_id NUMBER DEFAULT NULL,
8226 p_machine_resource_id NUMBER DEFAULT NULL,
8227 p_machine_instance VARCHAR2 DEFAULT NULL,
8228 p_user_task_type_id NUMBER DEFAULT NULL,
8229 p_from_task_quantity NUMBER DEFAULT NULL,
8230 p_to_task_quantity NUMBER DEFAULT NULL,
8231 p_from_task_priority NUMBER DEFAULT NULL,
8232 p_to_task_priority NUMBER DEFAULT NULL,
8233 p_from_creation_date DATE DEFAULT NULL,
8234 p_to_creation_date DATE DEFAULT NULL,
8235 p_is_unreleased BOOLEAN DEFAULT FALSE,
8236 p_is_pending BOOLEAN DEFAULT FALSE,
8237 p_is_queued BOOLEAN DEFAULT FALSE,
8238 p_is_dispatched BOOLEAN DEFAULT FALSE,
8239 p_is_active BOOLEAN DEFAULT FALSE,
8240 p_is_loaded BOOLEAN DEFAULT FALSE,
8241 p_is_completed BOOLEAN DEFAULT FALSE,
8242 p_include_replenishment BOOLEAN DEFAULT FALSE,
8243 p_from_replenishment_mo VARCHAR2 DEFAULT NULL,
8244 p_to_replenishment_mo VARCHAR2 DEFAULT NULL,
8245 p_include_mo_issue BOOLEAN DEFAULT FALSE,
8246 p_include_mo_transfer BOOLEAN DEFAULT FALSE,
8247 p_from_transfer_issue_mo VARCHAR2 DEFAULT NULL,
8248 p_to_transfer_issue_mo VARCHAR2 DEFAULT NULL,
8249 p_include_lpn_putaway BOOLEAN DEFAULT FALSE,
8250 -- R12 : Additional Query Criteria
8251 p_item_type_code VARCHAR2 DEFAULT NULL,
8252 p_age_uom_code VARCHAR2 DEFAULT NULL,
8253 p_age_min NUMBER DEFAULT NULL,
8254 p_age_max NUMBER DEFAULT NULL,
8255 p_summary_mode NUMBER DEFAULT 0
8256 -- R12 : Additional Query Criteria
8257
8258 )
8259 IS
8260 l_insert_query VARCHAR2 (4000);
8261 l_select_generic VARCHAR2 (4000);
8262 l_select_repl VARCHAR2 (4000);
8263 l_from_generic VARCHAR2 (2000);
8264 l_where_generic VARCHAR2 (5000);
8265 l_from_repl VARCHAR2 (2000);
8266 l_where_repl VARCHAR2 (4000);
8267 l_query VARCHAR2 (10000);
8268 l_query_handle NUMBER; -- Handle for the dynamic sql
8269 l_query_count NUMBER;
8270 l_loop_start NUMBER;
8271 l_loop_end NUMBER;
8272 l_is_unreleased BOOLEAN;
8273 l_is_pending BOOLEAN;
8274 l_is_queued BOOLEAN;
8275 l_is_dispatched BOOLEAN;
8276 l_is_active BOOLEAN;
8277 l_is_loaded BOOLEAN;
8278 l_is_completed BOOLEAN;
8279 l_wms_task_type NUMBER; -- for bug 5129375
8280 l_task_count NUMBER;
8281 l_debug NUMBER
8282 := NVL (fnd_profile.VALUE ('INV_DEBUG_TRACE'), 0);
8283 BEGIN
8284 IF p_is_completed THEN
8285
8286 /*Bug 3627575:Setting the variable to true for Inbound queries*/
8287 wms_plan_tasks_pvt.g_from_inbound :=TRUE;
8288 l_loop_end := 2;
8289 ELSE
8290 l_loop_end := 1;
8291 END IF;
8292
8293 IF p_is_unreleased
8294 OR p_is_pending
8295 OR p_is_queued
8296 OR p_is_dispatched
8297 OR p_is_active
8298 OR p_is_loaded
8299 THEN
8300 l_loop_start := 1;
8301 ELSE
8302 l_loop_start := 2;
8303 END IF;
8304
8305 FOR i IN l_loop_start .. l_loop_end
8306 LOOP
8307 l_insert_query := NULL;
8308 l_select_generic := NULL;
8309 l_select_repl := NULL;
8310 l_from_generic := NULL;
8311 l_from_repl := NULL;
8312 l_where_generic := NULL;
8313 l_where_repl := NULL;
8314
8315 IF i = 1
8316 THEN -- Non completed tasks iteration
8317 l_is_unreleased := p_is_unreleased;
8318 l_is_pending := p_is_pending;
8319 l_is_queued := p_is_queued;
8320 l_is_dispatched := p_is_dispatched;
8321 l_is_active := p_is_active;
8322 l_is_loaded := p_is_loaded;
8323 l_is_completed := FALSE;
8324 ELSE -- Completed tasks
8325 l_is_unreleased := FALSE;
8326 l_is_pending := FALSE;
8327 l_is_queued := FALSE;
8328 l_is_dispatched := FALSE;
8329 l_is_active := FALSE;
8330 l_is_loaded := FALSE;
8331 l_is_completed := p_is_completed;
8332 END IF;
8333
8334 -- Insert section
8335 IF p_summary_mode = 1 THEN -- only for query mode
8336 IF i = 1 THEN
8337 l_select_generic := ' SELECT mmtt.wms_task_type, count(*) ';
8338 ELSE
8339 l_select_generic := ' SELECT wdth.task_type, count(*) ';
8340 END IF;
8341 ELSE
8342 l_insert_query :=
8343 get_generic_insert (p_is_unreleased => l_is_unreleased,
8344 p_is_pending => l_is_pending,
8345 p_is_queued => l_is_queued,
8346 p_is_dispatched => l_is_dispatched,
8347 p_is_active => l_is_active,
8348 p_is_loaded => l_is_loaded,
8349 p_is_completed => l_is_completed
8350 );
8351 -- Replenishment specific inserts
8352 l_insert_query := l_insert_query || ', source_header ';
8353 --source_header
8354 l_insert_query := l_insert_query || ', line_number '; --line_number
8355 l_insert_query := l_insert_query || ') ';
8356 l_select_generic :=
8357 get_generic_select (p_is_unreleased => l_is_unreleased,
8358 p_is_pending => l_is_pending,
8359 p_is_queued => l_is_queued,
8360 p_is_dispatched => l_is_dispatched,
8361 p_is_active => l_is_active,
8362 p_is_loaded => l_is_loaded,
8363 p_is_completed => l_is_completed
8364 );
8365 -- Replenishment secific selects, should map to the columns additionally selecteda above
8366 l_select_repl := ', mtrh.request_number '; --source_header
8367 l_select_repl := l_select_repl || ', mtrl.line_number ';
8368 --line_number
8369 END IF;
8370 -- Generic from
8371 l_from_generic :=
8372 get_generic_from (p_is_queued => l_is_queued,
8373 p_is_dispatched => l_is_dispatched,
8374 p_is_active => l_is_active,
8375 p_is_loaded => l_is_loaded,
8376 p_is_completed => l_is_completed,
8377 p_item_category_id => p_item_category_id,
8378 p_category_set_id => p_category_set_id
8379 );
8380 --Generic Where
8381 l_where_generic :=
8382 get_generic_where
8383 (p_add => p_add,
8384 p_organization_id => p_organization_id,
8385 p_subinventory_code => p_subinventory_code,
8386 p_locator_id => p_locator_id,
8387 p_to_subinventory_code => p_to_subinventory_code,
8388 p_to_locator_id => p_to_locator_id,
8389 p_inventory_item_id => p_inventory_item_id,
8390 p_category_set_id => p_category_set_id,
8391 p_item_category_id => p_item_category_id,
8392 p_person_id => p_person_id,
8393 p_person_resource_id => p_person_resource_id,
8394 p_equipment_type_id => p_equipment_type_id,
8395 p_machine_resource_id => p_machine_resource_id,
8396 p_machine_instance => p_machine_instance,
8397 p_user_task_type_id => p_user_task_type_id,
8398 p_from_task_quantity => p_from_task_quantity,
8399 p_to_task_quantity => p_to_task_quantity,
8400 p_from_task_priority => p_from_task_priority,
8401 p_to_task_priority => p_to_task_priority,
8402 p_from_creation_date => p_from_creation_date,
8403 p_to_creation_date => p_to_creation_date,
8404 p_is_unreleased => l_is_unreleased,
8405 p_is_pending => l_is_pending,
8406 p_is_queued => l_is_queued,
8407 p_is_dispatched => l_is_dispatched,
8408 p_is_active => l_is_active,
8409 p_is_loaded => l_is_loaded,
8410 p_is_completed => l_is_completed,
8411 -- R12: Additional query criteria
8412 p_item_type_code => p_item_type_code,
8413 p_age_uom_code => p_age_uom_code,
8414 p_age_min => p_age_min,
8415 p_age_max => p_age_max
8416 );
8417 l_from_repl := ' , mtl_txn_request_headers mtrh';
8418 l_from_repl := l_from_repl || ' , mtl_txn_request_lines mtrl ';
8419 l_where_repl :=
8420 l_where_repl || ' and mtrl.header_id = mtrh.header_id ';
8421
8422 IF i = 1
8423 THEN
8424 l_where_repl :=
8425 l_where_repl || ' and mtrl.line_id = mmtt.trx_source_line_id ';
8426 l_where_repl :=
8427 l_where_repl || ' and mmtt.transaction_source_type_id = 4 ';
8428 ELSE
8429 l_where_repl :=
8430 l_where_repl || ' and mtrl.line_id = mmt.trx_source_line_id ';
8431 l_where_repl :=
8432 l_where_repl || ' and mmt.transaction_source_type_id = 4 ';
8433 /* Bug 5688998 */
8434 l_where_repl :=
8435 l_where_repl || ' and mtrl.line_id = wdth.move_order_line_id(+) ';
8436 /* End of Big 5688998 */
8437 END IF;
8438
8439 IF p_include_replenishment
8440 OR p_include_mo_issue
8441 OR p_include_mo_transfer
8442 OR p_include_lpn_putaway
8443 THEN
8444 IF p_include_replenishment
8445 THEN
8446 l_where_repl :=
8447 l_where_repl || ' and (mtrh.move_order_type = 2';
8448
8449 IF p_from_replenishment_mo IS NOT NULL
8450 THEN
8451 l_where_repl :=
8452 l_where_repl
8453 || ' and mtrh.request_number >= :from_replenishment_mo ';
8454 END IF;
8455
8456 IF p_to_replenishment_mo IS NOT NULL
8457 THEN
8458 l_where_repl :=
8459 l_where_repl
8460 || ' and mtrh.request_number <= :to_replenishment_mo ';
8461 END IF;
8462 END IF;
8463
8464 IF p_include_mo_issue OR p_include_mo_transfer
8465 THEN
8466 IF p_include_replenishment
8467 THEN
8468 l_where_repl := l_where_repl || ' OR ';
8469 ELSE
8470 l_where_repl := l_where_repl || ' AND (';
8471 END IF;
8472
8473 l_where_repl := l_where_repl || ' mtrh.move_order_type = 1 ';
8474
8475 IF p_from_transfer_issue_mo IS NOT NULL
8476 THEN
8477 l_where_repl :=
8478 l_where_repl
8479 || ' and mtrh.request_number >= :from_transfer_issue_mo ';
8480 END IF;
8481
8482 IF p_to_transfer_issue_mo IS NOT NULL
8483 THEN
8484 l_where_repl :=
8485 l_where_repl
8486 || ' and mtrh.request_number <= :to_transfer_issue_mo ';
8487 END IF;
8488 END IF;
8489
8490 IF p_include_lpn_putaway
8491 THEN
8492 IF p_include_replenishment
8493 OR p_include_mo_transfer
8494 OR p_include_mo_issue
8495 THEN
8496 l_where_repl := l_where_repl || ' OR ';
8497 ELSE
8498 l_where_repl := l_where_repl || ' AND (';
8499 END IF;
8500
8501 l_where_repl := l_where_repl || ' (mtrh.move_order_type = 6 ';
8502 l_where_repl := l_where_repl || ' AND mtrl.reference is NULL) ';
8503 END IF;
8504
8505 l_where_repl := l_where_repl || ' ) ';
8506
8507 IF p_include_replenishment OR p_include_mo_transfer
8508 THEN
8509 IF i = 1
8510 THEN
8511 l_where_repl :=
8512 l_where_repl || ' and (mmtt.transaction_action_id = 2 ';
8513 ELSE
8514 l_where_repl :=
8515 l_where_repl || ' and (mmt.transaction_action_id = 2 ';
8516 END IF;
8517 END IF;
8518
8519 IF p_include_mo_issue
8520 THEN
8521 IF p_include_replenishment OR p_include_mo_transfer
8522 THEN
8523 IF i = 1
8524 THEN
8525 l_where_repl :=
8526 l_where_repl
8527 || ' OR mmtt.transaction_action_id = 1) ';
8528 ELSE
8529 l_where_repl :=
8530 l_where_repl || ' OR mmt.transaction_action_id = 1) ';
8531 END IF;
8532 ELSE
8533 IF i = 1
8534 THEN
8535 l_where_repl :=
8536 l_where_repl
8537 || ' AND (mmtt.transaction_action_id = 1)';
8538 ELSE
8539 l_where_repl :=
8540 l_where_repl
8541 || ' AND (mmt.transaction_action_id = 1)';
8542 END IF;
8543 END IF;
8544 ELSE
8545 IF p_include_replenishment OR p_include_mo_transfer
8546 THEN
8547 l_where_repl := l_where_repl || ')';
8548 END IF;
8549 END IF;
8550 END IF;
8551
8552 IF p_summary_mode = 1 THEN
8553 IF i = 1 THEN
8554 l_where_repl := l_where_repl || ' GROUP BY mmtt.wms_task_type ';
8555 ELSE
8556 l_where_repl := l_where_repl || ' GROUP BY wdth.task_type ';
8557 END IF;
8558 END IF;
8559
8560 -- Execute the query
8561
8562 -- Concatenate the different sections of the query
8563 l_query :=
8564 l_insert_query
8565 || l_select_generic
8566 || l_select_repl
8567 || l_from_generic
8568 || l_from_repl
8569 || l_where_generic
8570 || l_where_repl;
8571 -- Parse, Bind and Execute the dynamic query
8572 if l_debug = 1 then
8573 debug('MO Tasks Query ' || l_query,'query_mo_tasks');
8574 end if;
8575 l_query_handle := DBMS_SQL.open_cursor;
8576 DBMS_SQL.parse (l_query_handle, l_query, DBMS_SQL.native);
8577
8578 --generic bind variables
8579 IF p_organization_id IS NOT NULL
8580 THEN
8581 DBMS_SQL.bind_variable (l_query_handle,
8582 'org_id',
8583 p_organization_id
8584 );
8585 END IF;
8586
8587 IF p_subinventory_code IS NOT NULL
8588 THEN
8589 DBMS_SQL.bind_variable (l_query_handle,
8590 'sub_code',
8591 p_subinventory_code
8592 );
8593 END IF;
8594
8595 IF p_locator_id IS NOT NULL
8596 THEN
8597 DBMS_SQL.bind_variable (l_query_handle, 'loc_id', p_locator_id);
8598 END IF;
8599
8600 IF p_to_subinventory_code IS NOT NULL
8601 THEN
8602 DBMS_SQL.bind_variable (l_query_handle,
8603 'to_sub_code',
8604 p_to_subinventory_code
8605 );
8606 END IF;
8607
8608 IF p_to_locator_id IS NOT NULL
8609 THEN
8610 DBMS_SQL.bind_variable (l_query_handle,
8611 'to_loc_id',
8612 p_to_locator_id
8613 );
8614 END IF;
8615
8616 IF p_category_set_id IS NOT NULL
8617 THEN
8618 DBMS_SQL.bind_variable (l_query_handle,
8619 'category_set_id',
8620 p_category_set_id
8621 );
8622 END IF;
8623
8624 IF p_inventory_item_id IS NOT NULL
8625 THEN
8626 DBMS_SQL.bind_variable (l_query_handle,
8627 'item_id',
8628 p_inventory_item_id
8629 );
8630 END IF;
8631
8632 -- R12 : Additional Query Criteria using item type
8633 IF p_item_type_code IS NOT NULL
8634 THEN
8635 DBMS_SQL.bind_variable (l_query_handle,
8636 'item_type_code',
8637 p_item_type_code
8638 );
8639 END IF;
8640
8641
8642 IF p_item_category_id IS NOT NULL
8643 THEN
8644 DBMS_SQL.bind_variable (l_query_handle,
8645 'item_category_id',
8646 p_item_category_id
8647 );
8648 END IF;
8649
8650 IF p_person_id IS NOT NULL
8651 THEN
8652 DBMS_SQL.bind_variable (l_query_handle, 'person_id', p_person_id);
8653 END IF;
8654
8655 IF p_person_resource_id IS NOT NULL
8656 THEN
8657 DBMS_SQL.bind_variable (l_query_handle,
8658 'person_resource_id',
8659 p_person_resource_id
8660 );
8661 END IF;
8662
8663 IF p_equipment_type_id IS NOT NULL
8664 THEN
8665 DBMS_SQL.bind_variable (l_query_handle,
8666 'equipment_type_id',
8667 p_equipment_type_id
8668 );
8669 END IF;
8670
8671 IF p_machine_resource_id IS NOT NULL
8672 THEN
8673 DBMS_SQL.bind_variable (l_query_handle,
8674 'machine_resource_id',
8675 p_machine_resource_id
8676 );
8677 END IF;
8678
8679 IF p_machine_instance IS NOT NULL
8680 THEN
8681 DBMS_SQL.bind_variable (l_query_handle,
8682 'machine_instance',
8683 p_machine_instance
8684 );
8685 END IF;
8686
8687 IF p_user_task_type_id IS NOT NULL
8688 THEN
8689 DBMS_SQL.bind_variable (l_query_handle,
8690 'user_task_type_id',
8691 p_user_task_type_id
8692 );
8693 END IF;
8694
8695 IF p_from_task_quantity IS NOT NULL
8696 THEN
8697 DBMS_SQL.bind_variable (l_query_handle,
8698 'from_task_quantity',
8699 p_from_task_quantity
8700 );
8701 END IF;
8702
8703 IF p_to_task_quantity IS NOT NULL
8704 THEN
8705 DBMS_SQL.bind_variable (l_query_handle,
8706 'to_task_quantity',
8707 p_to_task_quantity
8708 );
8709 END IF;
8710
8711 IF p_from_task_priority IS NOT NULL
8712 THEN
8713 DBMS_SQL.bind_variable (l_query_handle,
8714 'from_task_priority',
8715 p_from_task_priority
8716 );
8717 END IF;
8718
8719 IF p_to_task_priority IS NOT NULL
8720 THEN
8721 DBMS_SQL.bind_variable (l_query_handle,
8722 'to_task_priority',
8723 p_to_task_priority
8724 );
8725 END IF;
8726
8727 IF p_from_creation_date IS NOT NULL
8728 THEN
8729 DBMS_SQL.bind_variable (l_query_handle,
8730 'from_creation_date',
8731 p_from_creation_date
8732 );
8733 END IF;
8734
8735 IF p_to_creation_date IS NOT NULL
8736 THEN
8737 DBMS_SQL.bind_variable (l_query_handle,
8738 'to_creation_date',
8739 p_to_creation_date
8740 );
8741 END IF;
8742
8743 -- R12: Additional Query criteria using age of the task
8744 IF p_age_uom_code IS NOT NULL
8745 THEN
8746
8747 IF p_age_min IS NOT NULL
8748 THEN
8749 DBMS_SQL.bind_variable (l_query_handle,
8750 'age_min',
8751 p_age_min
8752 );
8753 END IF;
8754
8755 IF p_age_max IS NOT NULL
8756 THEN
8757 DBMS_SQL.bind_variable (l_query_handle,
8758 'age_max',
8759 p_age_max
8760 );
8761
8762 END IF;
8763 END IF;
8764
8765 IF p_from_replenishment_mo IS NOT NULL
8766 THEN
8767 DBMS_SQL.bind_variable (l_query_handle,
8768 'from_replenishment_mo',
8769 p_from_replenishment_mo
8770 );
8771 END IF;
8772
8773 IF p_to_replenishment_mo IS NOT NULL
8774 THEN
8775 DBMS_SQL.bind_variable (l_query_handle,
8776 'to_replenishment_mo',
8777 p_to_replenishment_mo
8778 );
8779 END IF;
8780
8781 IF p_from_transfer_issue_mo IS NOT NULL
8782 THEN
8783 DBMS_SQL.bind_variable (l_query_handle,
8784 'from_transfer_issue_mo',
8785 p_from_transfer_issue_mo
8786 );
8787 END IF;
8788
8789 IF p_to_transfer_issue_mo IS NOT NULL
8790 THEN
8791 DBMS_SQL.bind_variable (l_query_handle,
8792 'to_transfer_issue_mo',
8793 p_to_transfer_issue_mo
8794 );
8795 END IF;
8796
8797 IF p_summary_mode = 1 THEN
8798 DBMS_SQL.DEFINE_COLUMN(l_query_handle, 1, l_wms_task_type);
8799 DBMS_SQL.DEFINE_COLUMN(l_query_handle, 2, l_task_count);
8800 END IF;
8801
8802 --execute the replenishment query
8803 l_query_count := DBMS_SQL.EXECUTE (l_query_handle);
8804 g_record_count := g_record_count + l_query_count;
8805
8806 IF p_summary_mode = 1 THEN -- fetch the rows and put them into the global tables
8807 LOOP
8808 IF DBMS_SQL.FETCH_ROWS(l_query_handle)>0 THEN
8809 DBMS_SQL.COLUMN_VALUE(l_query_handle, 1, l_wms_task_type);
8810 DBMS_SQL.COLUMN_VALUE(l_query_handle, 2, l_task_count);
8811 g_wms_task_summary_tbl(l_wms_task_type).wms_task_type := l_wms_task_type;
8812 g_wms_task_summary_tbl(l_wms_task_type).task_count := g_wms_task_summary_tbl(l_wms_task_type).task_count + l_task_count;
8813 IF l_debug = 1 THEN
8814 debug('Task Type :' || g_wms_task_summary_tbl(l_wms_task_type).wms_task_type, 'query_mo_tasks');
8815 debug('TaskCount :' || g_wms_task_summary_tbl(l_wms_task_type).task_count, 'query_mo_tasks');
8816 END IF;
8817 ELSE
8818 EXIT; -- no more rows returned from dynamic SQL
8819 END IF;
8820 END LOOP;
8821 END IF;
8822 DBMS_SQL.close_cursor(l_query_handle);
8823 END LOOP;
8824 EXCEPTION
8825 WHEN OTHERS THEN -- Bug 4150145
8826 IF dbms_sql.is_open(l_query_handle) THEN
8827 dbms_sql.close_cursor(l_query_handle);
8828 END IF;
8829 DEBUG (SQLERRM, 'Task_planning.query_mo_tasks');
8830 END query_mo_tasks;
8831
8832 PROCEDURE query_move_tasks (
8833 p_add BOOLEAN DEFAULT FALSE,
8834 p_organization_id NUMBER DEFAULT NULL,
8835 p_subinventory_code VARCHAR2 DEFAULT NULL,
8836 p_locator_id NUMBER DEFAULT NULL,
8837 p_to_subinventory_code VARCHAR2 DEFAULT NULL,
8838 p_to_locator_id NUMBER DEFAULT NULL,
8839 p_inventory_item_id NUMBER DEFAULT NULL,
8840 p_category_set_id NUMBER DEFAULT NULL,
8841 p_item_category_id NUMBER DEFAULT NULL,
8842 p_person_id NUMBER DEFAULT NULL,
8843 p_person_resource_id NUMBER DEFAULT NULL,
8844 p_equipment_type_id NUMBER DEFAULT NULL,
8845 p_machine_resource_id NUMBER DEFAULT NULL,
8846 p_machine_instance VARCHAR2 DEFAULT NULL,
8847 p_user_task_type_id NUMBER DEFAULT NULL,
8848 p_from_task_quantity NUMBER DEFAULT NULL,
8849 p_to_task_quantity NUMBER DEFAULT NULL,
8850 p_from_task_priority NUMBER DEFAULT NULL,
8851 p_to_task_priority NUMBER DEFAULT NULL,
8852 p_from_creation_date DATE DEFAULT NULL,
8853 p_to_creation_date DATE DEFAULT NULL,
8854 p_include_staging_move BOOLEAN DEFAULT FALSE,
8855 p_include_inventory_move BOOLEAN DEFAULT FALSE,
8856 p_is_unreleased BOOLEAN DEFAULT FALSE,
8857 p_is_pending BOOLEAN DEFAULT FALSE,
8858 p_is_queued BOOLEAN DEFAULT FALSE,
8859 p_is_dispatched BOOLEAN DEFAULT FALSE,
8860 p_is_active BOOLEAN DEFAULT FALSE,
8861 p_is_loaded BOOLEAN DEFAULT FALSE,
8862 p_is_completed BOOLEAN DEFAULT FALSE,
8863 -- R12 : Additional Query Criteria
8864 p_item_type_code VARCHAR2 DEFAULT NULL,
8865 p_age_uom_code VARCHAR2 DEFAULT NULL,
8866 p_age_min NUMBER DEFAULT NULL,
8867 p_age_max NUMBER DEFAULT NULL
8868 -- R12 : Additional Query Criteria
8869 )
8870 IS
8871 l_insert_query VARCHAR2 (4000);
8872 l_select_generic VARCHAR2 (4000);
8873 l_select_repl VARCHAR2 (4000);
8874 l_from_generic VARCHAR2 (2000);
8875 l_where_generic VARCHAR2 (5000);
8876 l_query VARCHAR2 (10000);
8877 l_query_handle NUMBER; -- Handle for the dynamic sql
8878 l_query_count NUMBER;
8879 l_loop_start NUMBER;
8880 l_loop_end NUMBER;
8881
8882 l_is_unreleased BOOLEAN;
8883 l_is_pending BOOLEAN;
8884 l_is_queued BOOLEAN;
8885 l_is_dispatched BOOLEAN;
8886 l_is_active BOOLEAN;
8887 l_is_loaded BOOLEAN;
8888 l_is_completed BOOLEAN;
8889 l_debug NUMBER := NVL (fnd_profile.VALUE ('INV_DEBUG_TRACE'), 0);
8890
8891 BEGIN
8892 IF p_is_completed
8893 THEN
8894 l_loop_end := 2;
8895 ELSE
8896 l_loop_end := 1;
8897 END IF;
8898
8899 IF p_is_pending OR p_is_loaded
8900 THEN
8901 l_loop_start := 1;
8902 ELSE
8903 l_loop_start := 2;
8904 END IF;
8905
8906 FOR i IN l_loop_start .. l_loop_end
8907 LOOP
8908 l_insert_query := NULL;
8909 l_select_generic := NULL;
8910 l_from_generic := NULL;
8911 l_where_generic := NULL;
8912
8913 IF i = 1
8914 THEN -- Non completed tasks iteration
8915 l_is_unreleased := p_is_unreleased;
8916 l_is_queued := p_is_queued;
8917 l_is_dispatched := p_is_dispatched;
8918 l_is_active := p_is_active;
8919 l_is_pending := p_is_pending;
8920 l_is_loaded := p_is_loaded;
8921 l_is_completed := FALSE;
8922 ELSE -- Completed tasks
8923 l_is_unreleased := FALSE;
8924 l_is_queued := FALSE;
8925 l_is_dispatched := FALSE;
8926 l_is_active := FALSE;
8927 l_is_pending := FALSE;
8928 l_is_loaded := FALSE;
8929 l_is_completed := p_is_completed;
8930 END IF;
8931
8932 -- Insert section
8933 l_insert_query :=
8934 get_generic_insert (p_is_unreleased => l_is_unreleased,
8935 p_is_pending => l_is_pending,
8936 p_is_queued => l_is_queued,
8937 p_is_dispatched => l_is_dispatched,
8938 p_is_active => l_is_active,
8939 p_is_loaded => l_is_loaded,
8940 p_is_completed => l_is_completed
8941 );
8942 l_insert_query := l_insert_query || ') ';
8943 l_select_generic :=
8944 get_generic_select (p_is_unreleased => l_is_unreleased,
8945 p_is_pending => l_is_pending,
8946 p_is_queued => l_is_queued,
8947 p_is_dispatched => l_is_dispatched,
8948 p_is_active => l_is_active,
8949 p_is_loaded => l_is_loaded,
8950 p_is_completed => l_is_completed
8951 );
8952 -- Generic from
8953 l_from_generic :=
8954 get_generic_from ( p_is_queued => l_is_queued,
8955 p_is_dispatched => l_is_dispatched,
8956 p_is_active => l_is_active,
8957 p_is_loaded => l_is_loaded,
8958 p_is_completed => l_is_completed,
8959 p_item_category_id => p_item_category_id,
8960 p_category_set_id => p_category_set_id
8961 );
8962 --Generic Where
8963 l_where_generic :=
8964 get_generic_where
8965 (p_add => p_add,
8966 p_organization_id => p_organization_id,
8967 p_subinventory_code => p_subinventory_code,
8968 p_locator_id => p_locator_id,
8969 p_to_subinventory_code => p_to_subinventory_code,
8970 p_to_locator_id => p_to_locator_id,
8971 p_inventory_item_id => p_inventory_item_id,
8972 p_category_set_id => p_category_set_id,
8973 p_item_category_id => p_item_category_id,
8974 p_person_id => p_person_id,
8975 p_person_resource_id => p_person_resource_id,
8976 p_equipment_type_id => p_equipment_type_id,
8977 p_machine_resource_id => p_machine_resource_id,
8978 p_machine_instance => p_machine_instance,
8979 p_user_task_type_id => p_user_task_type_id,
8980 p_from_task_quantity => p_from_task_quantity,
8981 p_to_task_quantity => p_to_task_quantity,
8982 p_from_task_priority => p_from_task_priority,
8983 p_to_task_priority => p_to_task_priority,
8984 p_from_creation_date => p_from_creation_date,
8985 p_to_creation_date => p_to_creation_date,
8986 p_is_unreleased => l_is_unreleased,
8987 p_is_pending => l_is_pending,
8988 p_is_queued => l_is_queued,
8989 p_is_dispatched => l_is_dispatched,
8990 p_is_active => l_is_active,
8991 p_is_loaded => l_is_loaded,
8992 p_is_completed => l_is_completed,
8993 -- R12: Additional query criteria
8994 p_item_type_code => p_item_type_code,
8995 p_age_uom_code => p_age_uom_code,
8996 p_age_min => p_age_min,
8997 p_age_max => p_age_max
8998 );
8999
9000 IF p_include_staging_move AND NOT p_include_inventory_move
9001 THEN
9002 IF i = 1
9003 THEN
9004 l_where_generic :=
9005 l_where_generic || ' and mmtt.wms_task_type = 7 ';
9006 ELSE
9007 l_where_generic :=
9008 l_where_generic || ' and wdth.task_type = 7 ';
9009 END IF;
9010 ELSIF NOT p_include_staging_move AND p_include_inventory_move
9011 THEN
9012 IF i = 1
9013 THEN
9014 l_where_generic :=
9015 l_where_generic || ' and mmtt.wms_task_type = 4 ';
9016 l_where_generic :=
9017 l_where_generic || ' and mmtt.transaction_action_id = 2 ';
9018 l_where_generic :=
9019 l_where_generic
9020 || ' and mmtt.transaction_source_type_id = 13 ';
9021 ELSE
9022 l_where_generic :=
9023 l_where_generic || ' and wdth.task_type = 4 ';
9024 l_where_generic :=
9025 l_where_generic || ' and mmt.transaction_action_id = 2 ';
9026 l_where_generic :=
9027 l_where_generic
9028 || ' and mmt.transaction_source_type_id = 13 ';
9029 END IF;
9030 ELSIF p_include_staging_move AND p_include_inventory_move
9031 THEN
9032 IF i = 1
9033 THEN
9034 l_where_generic :=
9035 l_where_generic || ' and ((mmtt.wms_task_type = 7) or ';
9036 l_where_generic :=
9037 l_where_generic || ' (mmtt.wms_task_type = 4 ';
9038 l_where_generic :=
9039 l_where_generic || ' and mmtt.transaction_action_id = 2 ';
9040 l_where_generic :=
9041 l_where_generic
9042 || ' and mmtt.transaction_source_type_id = 13)) ';
9043 ELSE
9044 l_where_generic :=
9045 l_where_generic || ' and ((wdth.task_type = 7) or ';
9046 l_where_generic := l_where_generic || ' (wdth.task_type = 4 ';
9047 l_where_generic :=
9048 l_where_generic || ' and mmt.transaction_action_id = 2 ';
9049 l_where_generic :=
9050 l_where_generic
9051 || ' and mmt.transaction_source_type_id = 13)) ';
9052 END IF;
9053 END IF;
9054
9055 -- Execute the query
9056
9057 -- Concatenate the different sections of the query
9058 l_query :=
9059 l_insert_query
9060 || l_select_generic
9061 || l_from_generic
9062 || l_where_generic;
9063 -- Parse, Bind and Execute the dynamic query
9064 if l_debug = 1 then
9065 debug('MO Tasks Query ' || l_query,'query_move_tasks');
9066 end if;
9067 l_query_handle := DBMS_SQL.open_cursor;
9068 DBMS_SQL.parse (l_query_handle, l_query, DBMS_SQL.native);
9069
9070 --generic bind variables
9071 IF p_organization_id IS NOT NULL
9072 THEN
9073 DBMS_SQL.bind_variable (l_query_handle,
9074 'org_id',
9075 p_organization_id
9076 );
9077 END IF;
9078
9079 IF p_subinventory_code IS NOT NULL
9080 THEN
9081 DBMS_SQL.bind_variable (l_query_handle,
9082 'sub_code',
9083 p_subinventory_code
9084 );
9085 END IF;
9086
9087 IF p_locator_id IS NOT NULL
9088 THEN
9089 DBMS_SQL.bind_variable (l_query_handle, 'loc_id', p_locator_id);
9090 END IF;
9091
9092 IF p_to_subinventory_code IS NOT NULL
9093 THEN
9094 DBMS_SQL.bind_variable (l_query_handle,
9095 'to_sub_code',
9096 p_to_subinventory_code
9097 );
9098 END IF;
9099
9100 IF p_to_locator_id IS NOT NULL
9101 THEN
9102 DBMS_SQL.bind_variable (l_query_handle,
9103 'to_loc_id',
9104 p_to_locator_id
9105 );
9106 END IF;
9107
9108 IF p_category_set_id IS NOT NULL
9109 THEN
9110 DBMS_SQL.bind_variable (l_query_handle,
9111 'category_set_id',
9112 p_category_set_id
9113 );
9114 END IF;
9115
9116 IF p_inventory_item_id IS NOT NULL
9117 THEN
9118 DBMS_SQL.bind_variable (l_query_handle,
9119 'item_id',
9120 p_inventory_item_id
9121 );
9122 END IF;
9123
9124 -- R12 : Additional Query Criteria using item type
9125 IF p_item_type_code IS NOT NULL
9126 THEN
9127 DBMS_SQL.bind_variable (l_query_handle,
9128 'item_type_code',
9129 p_item_type_code
9130 );
9131 END IF;
9132
9133
9134 IF p_item_category_id IS NOT NULL
9135 THEN
9136 DBMS_SQL.bind_variable (l_query_handle,
9137 'item_category_id',
9138 p_item_category_id
9139 );
9140 END IF;
9141
9142 IF p_person_id IS NOT NULL
9143 THEN
9144 DBMS_SQL.bind_variable (l_query_handle, 'person_id', p_person_id);
9145 END IF;
9146
9147 IF p_person_resource_id IS NOT NULL
9148 THEN
9149 DBMS_SQL.bind_variable (l_query_handle,
9150 'person_resource_id',
9151 p_person_resource_id
9152 );
9153 END IF;
9154
9155 IF p_equipment_type_id IS NOT NULL
9156 THEN
9157 DBMS_SQL.bind_variable (l_query_handle,
9158 'equipment_type_id',
9159 p_equipment_type_id
9160 );
9161 END IF;
9162
9163 IF p_machine_resource_id IS NOT NULL
9164 THEN
9165 DBMS_SQL.bind_variable (l_query_handle,
9166 'machine_resource_id',
9167 p_machine_resource_id
9168 );
9169 END IF;
9170
9171 IF p_machine_instance IS NOT NULL
9172 THEN
9173 DBMS_SQL.bind_variable (l_query_handle,
9174 'machine_instance',
9175 p_machine_instance
9176 );
9177 END IF;
9178
9179 IF p_user_task_type_id IS NOT NULL
9180 THEN
9181 DBMS_SQL.bind_variable (l_query_handle,
9182 'user_task_type_id',
9183 p_user_task_type_id
9184 );
9185 END IF;
9186
9187 IF p_from_task_quantity IS NOT NULL
9188 THEN
9189 DBMS_SQL.bind_variable (l_query_handle,
9190 'from_task_quantity',
9191 p_from_task_quantity
9192 );
9193 END IF;
9194
9195 IF p_to_task_quantity IS NOT NULL
9196 THEN
9197 DBMS_SQL.bind_variable (l_query_handle,
9198 'to_task_quantity',
9199 p_to_task_quantity
9200 );
9201 END IF;
9202
9203 IF p_from_task_priority IS NOT NULL
9204 THEN
9205 DBMS_SQL.bind_variable (l_query_handle,
9206 'from_task_priority',
9207 p_from_task_priority
9208 );
9209 END IF;
9210
9211 IF p_to_task_priority IS NOT NULL
9212 THEN
9213 DBMS_SQL.bind_variable (l_query_handle,
9214 'to_task_priority',
9215 p_to_task_priority
9216 );
9217 END IF;
9218
9219 IF p_from_creation_date IS NOT NULL
9220 THEN
9221 DBMS_SQL.bind_variable (l_query_handle,
9222 'from_creation_date',
9223 p_from_creation_date
9224 );
9225 END IF;
9226
9227 IF p_to_creation_date IS NOT NULL
9228 THEN
9229 DBMS_SQL.bind_variable (l_query_handle,
9230 'to_creation_date',
9231 p_to_creation_date
9232 );
9233 END IF;
9234
9235 -- R12: Additional Query criteria using age of the task
9236 IF p_age_uom_code IS NOT NULL
9237 THEN
9238
9239 IF p_age_min IS NOT NULL
9240 THEN
9241 DBMS_SQL.bind_variable (l_query_handle,
9242 'age_min',
9243 p_age_min
9244 );
9245 END IF;
9246
9247 IF p_age_max IS NOT NULL
9248 THEN
9249 DBMS_SQL.bind_variable (l_query_handle,
9250 'age_max',
9251 p_age_max
9252 );
9253
9254 END IF;
9255 END IF;
9256
9257 --execute the replenishment query
9258 l_query_count := DBMS_SQL.EXECUTE (l_query_handle);
9259 g_record_count := g_record_count + l_query_count;
9260 DBMS_SQL.close_cursor(l_query_handle);
9261 END LOOP;
9262 EXCEPTION
9263 WHEN OTHERS THEN -- Bug 4150145
9264 IF dbms_sql.is_open(l_query_handle) THEN
9265 dbms_sql.close_cursor(l_query_handle);
9266 END IF;
9267 DEBUG (SQLERRM, 'Task_planning.query_mo_tasks');
9268 END query_move_tasks;
9269
9270 -- Prodedure query_tasks
9271 -- Input: Parameters that define the kind of task
9272 -- Output: This procedure populates the global temp table
9273 -- wms_waveplan_tasks_temp based on the input parameters.
9274 PROCEDURE query_tasks (
9275 p_add BOOLEAN DEFAULT FALSE,
9276 p_organization_id NUMBER DEFAULT NULL,
9277 p_subinventory_code VARCHAR2 DEFAULT NULL,
9278 p_locator_id NUMBER DEFAULT NULL,
9279 p_to_subinventory_code VARCHAR2 DEFAULT NULL,
9280 p_to_locator_id NUMBER DEFAULT NULL,
9281 p_inventory_item_id NUMBER DEFAULT NULL,
9282 p_category_set_id NUMBER DEFAULT NULL,
9283 p_item_category_id NUMBER DEFAULT NULL,
9284 p_person_id NUMBER DEFAULT NULL,
9285 p_person_resource_id NUMBER DEFAULT NULL,
9286 p_equipment_type_id NUMBER DEFAULT NULL,
9287 p_machine_resource_id NUMBER DEFAULT NULL,
9288 p_machine_instance VARCHAR2 DEFAULT NULL,
9289 p_user_task_type_id NUMBER DEFAULT NULL,
9290 p_from_task_quantity NUMBER DEFAULT NULL,
9291 p_to_task_quantity NUMBER DEFAULT NULL,
9292 p_from_task_priority NUMBER DEFAULT NULL,
9293 p_to_task_priority NUMBER DEFAULT NULL,
9294 p_from_creation_date DATE DEFAULT NULL,
9295 p_to_creation_date DATE DEFAULT NULL,
9296 p_is_unreleased BOOLEAN DEFAULT FALSE,
9297 p_is_pending BOOLEAN DEFAULT FALSE,
9298 p_is_queued BOOLEAN DEFAULT FALSE,
9299 p_is_dispatched BOOLEAN DEFAULT FALSE,
9300 p_is_active BOOLEAN DEFAULT FALSE,
9301 p_is_loaded BOOLEAN DEFAULT FALSE,
9302 p_is_completed BOOLEAN DEFAULT FALSE,
9303 p_include_inbound BOOLEAN DEFAULT FALSE,
9304 p_include_outbound BOOLEAN DEFAULT FALSE,
9305 p_include_crossdock BOOLEAN DEFAULT FALSE,
9306 p_include_manufacturing BOOLEAN DEFAULT FALSE,
9307 p_include_warehousing BOOLEAN DEFAULT FALSE,
9308 p_from_po_header_id NUMBER DEFAULT NULL,
9309 p_to_po_header_id NUMBER DEFAULT NULL,
9310 p_from_purchase_order VARCHAR2 DEFAULT NULL,
9311 p_to_purchase_order VARCHAR2 DEFAULT NULL,
9312 p_from_rma_header_id NUMBER DEFAULT NULL,
9313 p_to_rma_header_id NUMBER DEFAULT NULL,
9314 p_from_rma VARCHAR2 DEFAULT NULL,
9315 p_to_rma VARCHAR2 DEFAULT NULL,
9316 p_from_requisition_header_id NUMBER DEFAULT NULL,
9317 p_to_requisition_header_id NUMBER DEFAULT NULL,
9318 p_from_requisition VARCHAR2 DEFAULT NULL,
9319 p_to_requisition VARCHAR2 DEFAULT NULL,
9320 p_from_shipment_number VARCHAR2 DEFAULT NULL,
9321 p_to_shipment_number VARCHAR2 DEFAULT NULL,
9322 p_include_sales_orders BOOLEAN DEFAULT TRUE,
9323 p_include_internal_orders BOOLEAN DEFAULT TRUE,
9324 p_from_sales_order_id NUMBER DEFAULT NULL,
9325 p_to_sales_order_id NUMBER DEFAULT NULL,
9326 p_from_pick_slip_number NUMBER DEFAULT NULL,
9327 p_to_pick_slip_number NUMBER DEFAULT NULL,
9328 p_customer_id NUMBER DEFAULT NULL,
9329 p_customer_category VARCHAR2 DEFAULT NULL,
9330 p_delivery_id NUMBER DEFAULT NULL,
9331 p_carrier_id NUMBER DEFAULT NULL,
9332 p_ship_method VARCHAR2 DEFAULT NULL,
9333 p_shipment_priority VARCHAR2 DEFAULT NULL,
9334 p_trip_id NUMBER DEFAULT NULL,
9335 p_from_shipment_date DATE DEFAULT NULL,
9336 p_to_shipment_date DATE DEFAULT NULL,
9337 p_ship_to_state VARCHAR2 DEFAULT NULL,
9338 p_ship_to_country VARCHAR2 DEFAULT NULL,
9339 p_ship_to_postal_code VARCHAR2 DEFAULT NULL,
9340 p_from_number_of_order_lines NUMBER DEFAULT NULL,
9341 p_to_number_of_order_lines NUMBER DEFAULT NULL,
9342 p_manufacturing_type VARCHAR2 DEFAULT NULL,
9343 p_from_job VARCHAR2 DEFAULT NULL,
9344 p_to_job VARCHAR2 DEFAULT NULL,
9345 p_assembly_id NUMBER DEFAULT NULL,
9346 p_from_start_date DATE DEFAULT NULL,
9347 p_to_start_date DATE DEFAULT NULL,
9348 p_from_line VARCHAR2 DEFAULT NULL,
9349 p_to_line VARCHAR2 DEFAULT NULL,
9350 p_department_id NUMBER DEFAULT NULL,
9351 p_include_replenishment BOOLEAN DEFAULT TRUE,
9352 p_from_replenishment_mo VARCHAR2 DEFAULT NULL,
9353 p_to_replenishment_mo VARCHAR2 DEFAULT NULL,
9354 p_include_mo_transfer BOOLEAN DEFAULT TRUE,
9355 p_include_mo_issue BOOLEAN DEFAULT TRUE,
9356 p_from_transfer_issue_mo VARCHAR2 DEFAULT NULL,
9357 p_to_transfer_issue_mo VARCHAR2 DEFAULT NULL,
9358 p_include_lpn_putaway BOOLEAN DEFAULT TRUE,
9359 p_include_staging_move BOOLEAN DEFAULT FALSE,
9360 p_include_cycle_count BOOLEAN DEFAULT TRUE,
9361 p_cycle_count_name VARCHAR2 DEFAULT NULL,
9362 x_record_count OUT NOCOPY NUMBER,
9363 x_return_status OUT NOCOPY VARCHAR2,
9364 x_msg_data OUT NOCOPY VARCHAR2,
9365 x_msg_count OUT NOCOPY NUMBER,
9366 p_query_independent_tasks BOOLEAN DEFAULT TRUE,
9367 p_query_planned_tasks BOOLEAN DEFAULT TRUE,
9368 p_is_pending_plan BOOLEAN DEFAULT FALSE,
9369 p_is_inprogress_plan BOOLEAN DEFAULT FALSE,
9370 p_is_completed_plan BOOLEAN DEFAULT FALSE,
9371 p_is_cancelled_plan BOOLEAN DEFAULT FALSE,
9372 p_is_aborted_plan BOOLEAN DEFAULT FALSE,
9373 p_activity_id NUMBER DEFAULT NULL,
9374 p_plan_type_id NUMBER DEFAULT NULL,
9375 p_op_plan_id NUMBER DEFAULT NULL,
9376 -- R12 : Additional Query Criteria
9377 p_item_type_code VARCHAR2 DEFAULT NULL,
9378 p_age_uom_code VARCHAR2 DEFAULT NULL,
9379 p_age_min NUMBER DEFAULT NULL,
9380 p_age_max NUMBER DEFAULT NULL,
9381 p_order_type_id NUMBER DEFAULT NULL,
9382 p_time_till_shipment_uom_code VARCHAR2 DEFAULT NULL,
9383 p_time_till_shipment NUMBER DEFAULT NULL,
9384 p_time_till_appt_uom_code VARCHAR2 DEFAULT NULL,
9385 p_time_till_appt NUMBER DEFAULT NULL,
9386 p_summary_mode NUMBER DEFAULT 0
9387 -- R12 : Additional Query Criteria
9388 )
9389 IS
9390 l_parent_inserted NUMBER := 0;
9391 l_is_pending BOOLEAN := p_is_pending;
9392 l_debug NUMBER := NVL (fnd_profile.VALUE ('INV_DEBUG_TRACE'), 0);
9393 BEGIN
9394 x_return_status := 'S';
9395
9396 -- Delete any existing records in the temp table
9397 IF NOT p_add
9398 THEN
9399 wms_plan_tasks_pvt.clear_globals ();
9400
9401 DELETE FROM wms_waveplan_tasks_temp;
9402
9403 g_record_count := 0;
9404 END IF;
9405
9406 -- Populate the globals storing the status codes
9407 IF g_status_codes.COUNT = 0
9408 THEN
9409 set_status_codes;
9410 END IF;
9411
9412 -- Populate the globals storing the task types
9413 IF g_task_types.COUNT = 0
9414 THEN
9415 set_task_type;
9416 END IF;
9417
9418 --Change
9419 --Patchset J
9420 --Populate the globals storing plan task types
9421 IF g_plan_task_types.COUNT = 0
9422 THEN
9423 set_plan_task_types;
9424 END IF;
9425
9426 --End of change
9427
9428 -- Populate the globals storing the plan status codes
9429 IF g_plan_status_codes.COUNT = 0
9430 THEN
9431 set_plan_status_codes;
9432 END IF;
9433
9434 -- Populate the globals storing the visible attribute of columns
9435 IF g_allocated_lpn_visible IS NULL
9436 THEN
9437 find_visible_columns;
9438 END IF;
9439
9440 -- initialize the global summary table
9441 IF NOT p_add THEN
9442 FOR i IN 1..8 LOOP
9443 g_wms_task_summary_tbl(i).wms_task_type := i;
9444 g_wms_task_summary_tbl(i).task_count := 0;
9445 END LOOP;
9446 END IF;
9447
9448 wms_plan_tasks_pvt.set_globals
9449 (p_organization_id => p_organization_id,
9450 p_subinventory_code => p_subinventory_code,
9451 p_locator_id => p_locator_id,
9452 p_to_subinventory_code => p_to_subinventory_code,
9453 p_to_locator_id => p_to_locator_id,
9454 p_inventory_item_id => p_inventory_item_id,
9455 p_category_set_id => p_category_set_id,
9456 p_item_category_id => p_item_category_id,
9457 p_person_id => p_person_id,
9458 p_person_resource_id => p_person_resource_id,
9459 p_equipment_type_id => p_equipment_type_id,
9460 p_machine_resource_id => p_machine_resource_id,
9461 p_machine_instance => p_machine_instance,
9462 p_user_task_type_id => p_user_task_type_id,
9463 p_from_task_quantity => p_from_task_quantity,
9464 p_to_task_quantity => p_to_task_quantity,
9465 p_from_task_priority => p_from_task_priority,
9466 p_to_task_priority => p_to_task_priority,
9467 p_from_creation_date => p_from_creation_date,
9468 p_to_creation_date => p_to_creation_date,
9469 p_is_unreleased_task => p_is_unreleased,
9470 p_is_pending_task => p_is_pending,
9471 p_is_queued_task => p_is_queued,
9472 p_is_dispatched_task => p_is_dispatched,
9473 p_is_active_task => p_is_active,
9474 p_is_loaded_task => p_is_loaded,
9475 p_is_completed_task => p_is_completed,
9476 p_include_inbound => p_include_inbound,
9477 p_include_outbound => p_include_outbound,
9478 p_include_crossdock => p_include_crossdock,
9479 p_include_manufacturing => p_include_manufacturing,
9480 p_include_warehousing => p_include_warehousing,
9481 p_from_po_header_id => p_from_po_header_id,
9482 p_to_po_header_id => p_to_po_header_id,
9483 p_from_purchase_order => p_from_purchase_order,
9484 p_to_purchase_order => p_to_purchase_order,
9485 p_from_rma_header_id => p_from_rma_header_id,
9486 p_to_rma_header_id => p_to_rma_header_id,
9487 p_from_rma => p_from_rma,
9488 p_to_rma => p_to_rma,
9489 p_from_requisition_header_id => p_from_requisition_header_id,
9490 p_to_requisition_header_id => p_to_requisition_header_id,
9491 p_from_requisition => p_from_requisition,
9492 p_to_requisition => p_to_requisition,
9493 p_from_shipment_number => p_from_shipment_number,
9494 p_to_shipment_number => p_to_shipment_number,
9495 p_include_sales_orders => p_include_sales_orders,
9496 p_include_internal_orders => p_include_internal_orders,
9497 p_from_sales_order_id => p_from_sales_order_id,
9498 p_to_sales_order_id => p_to_sales_order_id,
9499 p_from_pick_slip_number => p_from_pick_slip_number,
9500 p_to_pick_slip_number => p_to_pick_slip_number,
9501 p_customer_id => p_customer_id,
9502 p_customer_category => p_customer_category,
9503 p_delivery_id => p_delivery_id,
9504 p_carrier_id => p_carrier_id,
9505 p_ship_method => p_ship_method,
9506 p_shipment_priority => p_shipment_priority,
9507 p_trip_id => p_trip_id,
9508 p_from_shipment_date => p_from_shipment_date,
9509 p_to_shipment_date => p_to_shipment_date,
9510 p_ship_to_state => p_ship_to_state,
9511 p_ship_to_country => p_ship_to_country,
9512 p_ship_to_postal_code => p_ship_to_postal_code,
9513 p_from_number_of_order_lines => p_from_number_of_order_lines,
9514 p_to_number_of_order_lines => p_to_number_of_order_lines,
9515 p_manufacturing_type => p_manufacturing_type,
9516 p_from_job => p_from_job,
9517 p_to_job => p_to_job,
9518 p_assembly_id => p_assembly_id,
9519 p_from_start_date => p_from_start_date,
9520 p_to_start_date => p_to_start_date,
9521 p_from_line => p_from_line,
9522 p_to_line => p_to_line,
9523 p_department_id => p_department_id,
9524 p_include_replenishment => p_include_replenishment,
9525 p_from_replenishment_mo => p_from_replenishment_mo,
9526 p_to_replenishment_mo => p_to_replenishment_mo,
9527 p_include_mo_transfer => p_include_mo_transfer,
9528 p_include_mo_issue => p_include_mo_issue,
9529 p_from_transfer_issue_mo => p_from_transfer_issue_mo,
9530 p_to_transfer_issue_mo => p_to_transfer_issue_mo,
9531 p_include_lpn_putaway => p_include_lpn_putaway,
9532 p_include_staging_move => p_include_staging_move,
9533 p_include_cycle_count => p_include_cycle_count,
9534 p_cycle_count_name => p_cycle_count_name,
9535 p_query_independent_tasks => p_query_independent_tasks,
9536 p_query_planned_tasks => p_query_planned_tasks,
9537 p_is_pending_plan => p_is_pending_plan,
9538 p_is_inprogress_plan => p_is_inprogress_plan,
9539 p_is_completed_plan => p_is_completed_plan,
9540 p_is_cancelled_plan => p_is_cancelled_plan,
9541 p_is_aborted_plan => p_is_aborted_plan,
9542 p_activity_id => p_activity_id,
9543 p_plan_type_id => p_plan_type_id,
9544 p_op_plan_id => p_op_plan_id
9545 );
9546
9547 IF p_include_inbound OR p_include_crossdock
9548 THEN
9549 /* Patchset J - ATF: Call the new procedure
9550 wms_plan_tasks_pvt.query_inbound_plan_tasks
9551 */
9552 DEBUG ('calling wms_plan_tasks_pvt.query_inbound_plan_tasks',
9553 'query_tasks'
9554 );
9555 wms_plan_tasks_pvt.query_inbound_plan_tasks (x_return_status,p_summary_mode);
9556 g_record_count :=
9557 g_record_count + wms_plan_tasks_pvt.g_plans_tasks_record_count;
9558 END IF;
9559
9560 IF p_include_outbound
9561 THEN
9562 --Need the pending status checked to ensure
9563 --children tasks are always fetched. We need the children tasks
9564 --to successfully fetch the parents.
9565 --If p_is_pending isn't checked, children tasks won't be returned,
9566 --which means parents tasks won't be fetched either.
9567 IF NOT p_is_pending THEN
9568 l_is_pending := TRUE;
9569 END IF;
9570 query_outbound_tasks
9571 (p_add => p_add,
9572 p_organization_id => p_organization_id,
9573 p_subinventory_code => p_subinventory_code,
9574 p_locator_id => p_locator_id,
9575 p_to_subinventory_code => p_to_subinventory_code,
9576 p_to_locator_id => p_to_locator_id,
9577 p_inventory_item_id => p_inventory_item_id,
9578 p_category_set_id => p_category_set_id,
9579 p_item_category_id => p_item_category_id,
9580 p_person_id => p_person_id,
9581 p_person_resource_id => p_person_resource_id,
9582 p_equipment_type_id => p_equipment_type_id,
9583 p_machine_resource_id => p_machine_resource_id,
9584 p_machine_instance => p_machine_instance,
9585 p_user_task_type_id => p_user_task_type_id,
9586 p_from_task_quantity => p_from_task_quantity,
9587 p_to_task_quantity => p_to_task_quantity,
9588 p_from_task_priority => p_from_task_priority,
9589 p_to_task_priority => p_to_task_priority,
9590 p_from_creation_date => p_from_creation_date,
9591 p_to_creation_date => p_to_creation_date,
9592 p_is_unreleased => p_is_unreleased,
9593 p_is_pending => l_is_pending,
9594 p_is_queued => p_is_queued,
9595 p_is_dispatched => p_is_dispatched,
9596 p_is_active => p_is_active,
9597 p_is_loaded => p_is_loaded,
9598 p_is_completed => p_is_completed,
9599 p_include_internal_orders => p_include_internal_orders,
9600 p_include_sales_orders => p_include_sales_orders,
9601 p_from_sales_order_id => p_from_sales_order_id,
9602 p_to_sales_order_id => p_to_sales_order_id,
9603 p_from_pick_slip_number => p_from_pick_slip_number,
9604 p_to_pick_slip_number => p_to_pick_slip_number,
9605 p_customer_id => p_customer_id,
9606 p_customer_category => p_customer_category,
9607 p_delivery_id => p_delivery_id,
9608 p_carrier_id => p_carrier_id,
9609 p_ship_method => p_ship_method,
9610 p_shipment_priority => p_shipment_priority,
9611 p_trip_id => p_trip_id,
9612 p_from_shipment_date => p_from_shipment_date,
9613 p_to_shipment_date => p_to_shipment_date,
9614 p_ship_to_state => p_ship_to_state,
9615 p_ship_to_country => p_ship_to_country,
9616 p_ship_to_postal_code => p_ship_to_postal_code,
9617 p_from_number_of_order_lines => p_from_number_of_order_lines,
9618 p_to_number_of_order_lines => p_to_number_of_order_lines,
9619 -- R12: Additional query criteria
9620 p_item_type_code => p_item_type_code,
9621 p_age_uom_code => p_age_uom_code,
9622 p_age_min => p_age_min,
9623 p_age_max => p_age_max,
9624 p_order_type_id => p_order_type_id,
9625 p_time_till_shipment_uom_code => p_time_till_shipment_uom_code,
9626 p_time_till_shipment => p_time_till_shipment,
9627 p_time_till_appt_uom_code => p_time_till_appt_uom_code,
9628 p_time_till_appt => p_time_till_appt,
9629 p_summary_mode => p_summary_mode
9630 );
9631 END IF;
9632
9633 IF p_include_manufacturing
9634 THEN
9635 query_manufacturing_tasks
9636 (p_add => p_add,
9637 p_organization_id => p_organization_id,
9638 p_subinventory_code => p_subinventory_code,
9639 p_locator_id => p_locator_id,
9640 p_to_subinventory_code => p_to_subinventory_code,
9641 p_to_locator_id => p_to_locator_id,
9642 p_inventory_item_id => p_inventory_item_id,
9643 p_category_set_id => p_category_set_id,
9644 p_item_category_id => p_item_category_id,
9645 p_person_id => p_person_id,
9646 p_person_resource_id => p_person_resource_id,
9647 p_equipment_type_id => p_equipment_type_id,
9648 p_machine_resource_id => p_machine_resource_id,
9649 p_machine_instance => p_machine_instance,
9650 p_user_task_type_id => p_user_task_type_id,
9651 p_from_task_quantity => p_from_task_quantity,
9652 p_to_task_quantity => p_to_task_quantity,
9653 p_from_task_priority => p_from_task_priority,
9654 p_to_task_priority => p_to_task_priority,
9655 p_from_creation_date => p_from_creation_date,
9656 p_to_creation_date => p_to_creation_date,
9657 p_is_unreleased => p_is_unreleased,
9658 p_is_pending => p_is_pending,
9659 p_is_queued => p_is_queued,
9660 p_is_dispatched => p_is_dispatched,
9661 p_is_active => p_is_active,
9662 p_is_loaded => p_is_loaded,
9663 p_is_completed => p_is_completed,
9664 p_manufacturing_type => p_manufacturing_type,
9665 p_from_job => p_from_job,
9666 p_to_job => p_to_job,
9667 p_assembly_id => p_assembly_id,
9668 p_from_start_date => p_from_start_date,
9669 p_to_start_date => p_to_start_date,
9670 p_from_line => p_from_line,
9671 p_to_line => p_to_line,
9672 p_department_id => p_department_id,
9673 -- R12: Additional query criteria
9674 p_item_type_code => p_item_type_code,
9675 p_age_uom_code => p_age_uom_code,
9676 p_age_min => p_age_min,
9677 p_age_max => p_age_max,
9678 p_summary_mode => p_summary_mode
9679 );
9680 END IF;
9681
9682 IF p_include_warehousing
9683 THEN
9684 -- Check for the replenishment, move order issuem, moxfer and cycle count tasks
9685 IF p_include_replenishment
9686 OR p_include_mo_issue
9687 OR p_include_mo_transfer
9688 THEN
9689 query_mo_tasks
9690 (p_add => p_add,
9691 p_organization_id => p_organization_id,
9692 p_subinventory_code => p_subinventory_code,
9693 p_locator_id => p_locator_id,
9694 p_to_subinventory_code => p_to_subinventory_code,
9695 p_to_locator_id => p_to_locator_id,
9696 p_inventory_item_id => p_inventory_item_id,
9697 p_category_set_id => p_category_set_id,
9698 p_item_category_id => p_item_category_id,
9699 p_person_id => p_person_id,
9700 p_person_resource_id => p_person_resource_id,
9701 p_equipment_type_id => p_equipment_type_id,
9702 p_machine_resource_id => p_machine_resource_id,
9703 p_machine_instance => p_machine_instance,
9704 p_user_task_type_id => p_user_task_type_id,
9705 p_from_task_quantity => p_from_task_quantity,
9706 p_to_task_quantity => p_to_task_quantity,
9707 p_from_task_priority => p_from_task_priority,
9708 p_to_task_priority => p_to_task_priority,
9709 p_from_creation_date => p_from_creation_date,
9710 p_to_creation_date => p_to_creation_date,
9711 p_is_unreleased => p_is_unreleased,
9712 p_is_pending => p_is_pending,
9713 p_is_queued => p_is_queued,
9714 p_is_dispatched => p_is_dispatched,
9715 p_is_active => p_is_active,
9716 p_is_loaded => p_is_loaded,
9717 p_is_completed => p_is_completed,
9718 p_include_replenishment => p_include_replenishment,
9719 p_from_replenishment_mo => p_from_replenishment_mo,
9720 p_to_replenishment_mo => p_to_replenishment_mo,
9721 p_include_mo_issue => p_include_mo_issue,
9722 p_include_mo_transfer => p_include_mo_transfer,
9723 p_from_transfer_issue_mo => p_from_transfer_issue_mo,
9724 p_to_transfer_issue_mo => p_to_transfer_issue_mo,
9725 p_include_lpn_putaway => p_include_lpn_putaway,
9726 -- R12: Additional query criteria
9727 p_item_type_code => p_item_type_code,
9728 p_age_uom_code => p_age_uom_code,
9729 p_age_min => p_age_min,
9730 p_age_max => p_age_max,
9731 p_summary_mode => p_summary_mode
9732 );
9733 END IF;
9734
9735 IF p_include_staging_move OR p_include_lpn_putaway
9736 THEN
9737 query_move_tasks
9738 (p_add => p_add,
9739 p_organization_id => p_organization_id,
9740 p_subinventory_code => p_subinventory_code,
9741 p_locator_id => p_locator_id,
9742 p_to_subinventory_code => p_to_subinventory_code,
9743 p_to_locator_id => p_to_locator_id,
9744 p_inventory_item_id => p_inventory_item_id,
9745 p_category_set_id => p_category_set_id,
9746 p_item_category_id => p_item_category_id,
9747 p_person_id => p_person_id,
9748 p_person_resource_id => p_person_resource_id,
9749 p_equipment_type_id => p_equipment_type_id,
9750 p_machine_resource_id => p_machine_resource_id,
9751 p_machine_instance => p_machine_instance,
9752 p_user_task_type_id => p_user_task_type_id,
9753 p_from_task_quantity => p_from_task_quantity,
9754 p_to_task_quantity => p_to_task_quantity,
9755 p_from_task_priority => p_from_task_priority,
9756 p_to_task_priority => p_to_task_priority,
9757 p_from_creation_date => p_from_creation_date,
9758 p_to_creation_date => p_to_creation_date,
9759 p_include_staging_move => p_include_staging_move,
9760 p_include_inventory_move => p_include_lpn_putaway,
9761 p_is_unreleased => p_is_unreleased,
9762 p_is_pending => p_is_pending,
9763 p_is_queued => p_is_queued,
9764 p_is_dispatched => p_is_dispatched,
9765 p_is_active => p_is_active,
9766 p_is_loaded => p_is_loaded,
9767 p_is_completed => p_is_completed,
9768 -- R12: Additional query criteria
9769 p_item_type_code => p_item_type_code,
9770 p_age_uom_code => p_age_uom_code,
9771 p_age_min => p_age_min,
9772 p_age_max => p_age_max
9773 );
9774 END IF;
9775
9776 IF p_include_cycle_count
9777 THEN
9778 query_cycle_count_tasks
9779 (p_add => p_add,
9780 p_organization_id => p_organization_id,
9781 p_subinventory_code => p_subinventory_code,
9782 p_locator_id => p_locator_id,
9783 p_to_subinventory_code => p_to_subinventory_code,
9784 p_to_locator_id => p_to_locator_id,
9785 p_inventory_item_id => p_inventory_item_id,
9786 p_category_set_id => p_category_set_id,
9787 p_item_category_id => p_item_category_id,
9788 p_person_id => p_person_id,
9789 p_person_resource_id => p_person_resource_id,
9790 p_equipment_type_id => p_equipment_type_id,
9791 p_machine_resource_id => p_machine_resource_id,
9792 p_machine_instance => p_machine_instance,
9793 p_user_task_type_id => p_user_task_type_id,
9794 p_from_task_quantity => p_from_task_quantity,
9795 p_to_task_quantity => p_to_task_quantity,
9796 p_from_task_priority => p_from_task_priority,
9797 p_to_task_priority => p_to_task_priority,
9798 p_from_creation_date => p_from_creation_date,
9799 p_to_creation_date => p_to_creation_date,
9800 p_cycle_count_name => p_cycle_count_name,
9801 p_is_pending => p_is_pending,
9802 p_is_queued => p_is_queued,
9803 p_is_dispatched => p_is_dispatched,
9804 p_is_active => p_is_active,
9805 p_is_completed => p_is_completed,
9806 -- R12: Additional query criteria
9807 p_item_type_code => p_item_type_code,
9808 p_age_uom_code => p_age_uom_code,
9809 p_age_min => p_age_min,
9810 p_age_max => p_age_max,
9811 p_summary_mode => p_summary_mode
9812 );
9813 END IF;
9814 END IF;
9815
9816 IF p_include_outbound
9817 OR p_include_manufacturing
9818 OR ( p_include_warehousing
9819 AND ( p_include_replenishment
9820 OR p_include_mo_transfer
9821 OR p_include_mo_issue
9822 )
9823 )
9824 THEN
9825
9826 populate_merged_tasks (p_is_unreleased => p_is_unreleased,
9827 p_is_pending => p_is_pending,
9828 p_is_queued => p_is_queued,
9829 p_is_dispatched => p_is_dispatched,
9830 p_is_active => p_is_active,
9831 p_is_loaded => p_is_loaded,
9832 p_is_completed => p_is_completed,
9833 p_from_task_quantity => p_from_task_quantity,
9834 p_to_task_quantity => p_to_task_quantity,
9835 p_person_id => p_person_id, /* Bug 5446146 */
9836 p_person_resource_id => p_person_resource_id,
9837 p_equipment_type_id => p_equipment_type_id,
9838 p_machine_resource_id => p_machine_resource_id,
9839 p_machine_instance => p_machine_instance,
9840 p_user_task_type_id => p_user_task_type_id, /* End of Bug 5446146 */
9841 x_non_complete_parent => l_parent_inserted
9842 );
9843
9844 /* Bug 5446146 - If Employee is entered and both queued and pending is checked, show only queued tasks
9845 as Employee does not hold good for Pending tasks. Hence delete the unwanted records from WWTT */
9846 IF ( p_is_queued OR p_is_dispatched OR p_is_active OR p_is_loaded OR p_is_completed
9847 AND ( p_is_pending OR p_is_unreleased ) ) AND ( p_person_id IS NOT NULL OR
9848 p_person_resource_id IS NOT NULL OR
9849 p_equipment_type_id IS NOT NULL OR
9850 p_machine_resource_id IS NOT NULL OR
9851 p_machine_instance IS NOT NULL )
9852 THEN
9853 IF (p_is_pending) THEN
9854 l_is_pending := FALSE;
9855 ELSE
9856 l_is_pending := TRUE;
9857 END IF;
9858 END IF;
9859 /* End of Bug 5446146 */
9860
9861 --Unwanted Pending tasks may have been returned since we always
9862 --queried outbound pending tasks to ensure children tasks are returned.
9863 --Below is to delete those from the temp table.
9864 IF l_is_pending <> p_is_pending THEN
9865 IF l_debug = 1 THEN
9866 debug('Done populating merged tasks. Delete unwanted tasks','query_tasks');
9867 END IF;
9868
9869 DELETE FROM wms_waveplan_tasks_temp
9870 WHERE status_id = 1;
9871
9872 g_wms_task_summary_tbl(g_task_type_pick).task_count := g_wms_task_summary_tbl(g_task_type_pick).task_count - SQL%ROWCOUNT; --subtract the same from the summary information
9873 g_record_count := g_record_count - SQL%ROWCOUNT;
9874 END IF;
9875
9876 IF l_debug = 1 THEN
9877 FOR i IN 1..8 LOOP
9878 debug('Task type :' || g_wms_task_summary_tbl(i).wms_task_type, 'query_tasks');
9879 debug('TaskCount :' || g_wms_task_summary_tbl(i).task_count, 'query_tasks');
9880 END LOOP;
9881 END IF;
9882
9883
9884 /* Bug - 5446146 If a user task type has been entered, delete the records which are not associated with a user task type */
9885 IF p_user_task_type_id IS NOT NULL THEN
9886
9887 DELETE FROM wms_waveplan_tasks_temp
9888 WHERE user_task_type_id IS NULL;
9889
9890 g_record_count := g_record_count - SQL%ROWCOUNT;
9891 END IF;
9892 /* End of Bug 5446146 */
9893
9894 --Patchset J bulk picking enhancement
9895 --Bulk pick only apply to outbound and manufacturing
9896 IF g_num_of_child_tasks_visible = 'T' AND l_parent_inserted > 0
9897 THEN
9898 --calculate number of children associated with parent tasks
9899 set_num_of_child_tasks;
9900 END IF;
9901 END IF;
9902
9903 -- Populate the locator names for project locators
9904 set_project_locators (p_organization_id => p_organization_id);
9905 --bug: 4510849
9906 IF p_include_outbound OR p_include_replenishment OR p_include_mo_issue OR p_include_mo_transfer THEN
9907 IF p_is_loaded OR p_is_completed THEN
9908 set_picking_lpns(p_is_loaded => p_is_loaded, p_is_completed => p_is_completed);
9909 END IF;
9910 END IF;
9911 x_record_count := g_record_count;
9912 EXCEPTION
9913 WHEN OTHERS
9914 THEN
9915 x_return_status := 'U';
9916 x_msg_data := SQLERRM;
9917 END query_tasks;
9918
9919 FUNCTION getforcesignonflagvalue (
9920 p_transaction_temp_id IN mtl_material_transactions_temp.transaction_temp_id%TYPE,
9921 p_device_id OUT NOCOPY NUMBER
9922 )
9923 RETURN VARCHAR2
9924 IS
9925 l_force_sign_on wms_devices_b.force_sign_on_flag%TYPE;
9926 BEGIN
9927 SELECT wms_task_dispatch_device.get_eligible_device
9928 (mmtt.organization_id,
9929 mmtt.subinventory_code,
9930 mmtt.locator_id
9931 )
9932 INTO p_device_id
9933 FROM mtl_material_transactions_temp mmtt
9934 WHERE mmtt.transaction_temp_id = p_transaction_temp_id;
9935
9936 SELECT force_sign_on_flag
9937 INTO l_force_sign_on
9938 FROM wms_devices_b
9939 WHERE device_id = p_device_id;
9940
9941 DEBUG ('l_force_sign_on : ' || l_force_sign_on, ' FOrce Sign On :');
9942 RETURN l_force_sign_on;
9943 EXCEPTION
9944 WHEN OTHERS
9945 THEN
9946 RETURN 'N';
9947 END;
9948
9949
9950 PROCEDURE update_task (
9951 p_transaction_temp_id IN wms_waveplan_tasks_pvt.transaction_temp_table_type,
9952 p_task_type_id IN wms_waveplan_tasks_pvt.task_type_id_table_type,
9953 p_employee IN VARCHAR2,
9954 p_employee_id IN NUMBER,
9955 p_user_task_type IN VARCHAR2,
9956 p_user_task_type_id IN NUMBER,
9957 p_effective_start_date IN DATE,
9958 p_effective_end_date IN DATE,
9959 p_person_resource_id IN NUMBER,
9960 p_person_resource_code IN VARCHAR2,
9961 p_force_employee_change IN BOOLEAN,
9962 p_to_status IN VARCHAR2,
9963 p_to_status_id IN NUMBER,
9964 p_update_priority_type IN VARCHAR2,
9965 p_update_priority IN NUMBER,
9966 p_clear_priority IN VARCHAR2,
9967 x_result OUT NOCOPY wms_waveplan_tasks_pvt.result_table_type,
9968 x_message OUT NOCOPY wms_waveplan_tasks_pvt.message_table_type,
9969 x_task_id OUT NOCOPY wms_waveplan_tasks_pvt.task_id_table_type,
9970 x_return_status OUT NOCOPY VARCHAR2,
9971 x_return_msg OUT NOCOPY VARCHAR2,
9972 x_msg_count OUT NOCOPY NUMBER
9973 )
9974 IS
9975 l_task_id NUMBER;
9976 l_index NUMBER;
9977 l_message wms_waveplan_tasks_temp.error%TYPE;
9978 l_debug NUMBER := NVL (fnd_profile.VALUE ('INV_DEBUG_TRACE'), 0);
9979
9980 TYPE status_table_type IS TABLE OF wms_waveplan_tasks_temp.status%TYPE;
9981
9982 l_transaction_temp_ids wms_waveplan_tasks_pvt.transaction_temp_table_type;
9983 l_task_type_ids wms_waveplan_tasks_pvt.task_type_id_table_type;
9984 l_statuses status_table_type;
9985 l_messages wms_waveplan_tasks_pvt.message_table_type;
9986 l_transaction_temp_ids_temp wms_waveplan_tasks_pvt.transaction_temp_table_type;
9987 l_device_id NUMBER;
9988 BEGIN
9989 IF g_cannot_update_putaway IS NULL
9990 THEN
9991 fnd_message.set_name ('WMS', 'WMS_CANNOT_UPDATE_PUTAWAY_TASK');
9992 g_cannot_update_putaway := fnd_message.get;
9993 fnd_message.set_name ('WMS', 'WMS_CANNOT_UPDATE_STAGING_MOVE');
9994 g_cannot_update_staging_move := fnd_message.get;
9995 fnd_message.set_name ('WMS', 'WMS_TASK_UPDATED');
9996 g_task_updated := fnd_message.get;
9997 fnd_message.set_name ('WMS', 'WMS_CANNOT_UNRELEASE_CC');
9998 g_cannot_unrelease_cc := fnd_message.get;
9999 END IF;
10000
10001 FORALL i IN p_transaction_temp_id.FIRST .. p_transaction_temp_id.LAST
10002 UPDATE wms_waveplan_tasks_temp
10003 SET RESULT = 'X'
10004 WHERE transaction_temp_id = p_transaction_temp_id (i)
10005 AND task_type_id = p_task_type_id (i);
10006
10007 -- Validations
10008
10009 -- 1 Pick
10010 -- 2 Putaway
10011 -- 3 Cycle Count
10012 -- 4 Replenish
10013 -- 5 Move Order Transfer
10014 -- 6 Move Order Issue
10015 -- 7 Staging Move
10016
10017 -- Cannot update putaway tasks or staging moves
10018 UPDATE wms_waveplan_tasks_temp
10019 SET RESULT = 'E',
10020 error =
10021 DECODE (task_type_id,
10022 2, g_cannot_update_putaway,
10023 7, g_cannot_update_staging_move
10024 )
10025 WHERE RESULT = 'X' AND task_type_id IN (2, 7);
10026
10027 -- Cannot set cycle count tasks to unreleased
10028 IF p_to_status_id = 8
10029 THEN
10030 UPDATE wms_waveplan_tasks_temp
10031 SET RESULT = 'E',
10032 error = g_cannot_unrelease_cc
10033 WHERE RESULT = 'X' AND task_type_id = 3;
10034 END IF;
10035
10036 -- Invalid status changes
10037 IF p_to_status_id IS NOT NULL
10038 THEN
10039 SELECT transaction_temp_id, task_type_id, status
10040 BULK COLLECT INTO l_transaction_temp_ids, l_task_type_ids, l_statuses
10041 FROM wms_waveplan_tasks_temp
10042 WHERE RESULT = 'X'
10043 AND NOT ( (status_id = 8 AND p_to_status_id IN (1, 2)
10044 ) -- Unreleased to pending or queued
10045 OR (status_id = 1 AND p_to_status_id IN (2, 8)
10046 ) -- Pending to queued or unreleased
10047 OR (status_id = 2 AND p_to_status_id IN (1, 8)
10048 ) -- Queued to pending or unreleased
10049 OR (status_id = 9 AND p_to_status_id IN (1, 8)
10050 ) -- R12:Active to Pending or unreleased
10051 OR (status_id = 3 AND p_to_status_id IN (1, 8)
10052 ) -- R12:Dispatched to Pending or unreleased
10053 OR (status_id = p_to_status_id)
10054 ); -- No Status Change
10055
10056 IF l_transaction_temp_ids.COUNT > 0
10057 THEN
10058 FOR i IN
10059 l_transaction_temp_ids.FIRST .. l_transaction_temp_ids.LAST
10060 LOOP
10061 fnd_message.set_name ('WMS', 'WMS_CANNOT_UPDATE_STATUS');
10062 fnd_message.set_token ('FROM_STATUS', l_statuses (i));
10063 fnd_message.set_token ('TO_STATUS', p_to_status);
10064 l_messages (i) := fnd_message.get;
10065 END LOOP;
10066
10067 FORALL i IN l_transaction_temp_ids.FIRST .. l_transaction_temp_ids.LAST
10068 UPDATE wms_waveplan_tasks_temp
10069 SET RESULT = 'E',
10070 error = l_messages (i)
10071 WHERE transaction_temp_id = l_transaction_temp_ids (i)
10072 AND task_type_id = l_task_type_ids (i);
10073 END IF;
10074
10075 IF p_to_status_id IN (1, 8) THEN
10076
10077 -- if the original task status is dispatched, check if any of the tasks belonging to
10078 -- this group is active
10079
10080 --BUG: 4707588
10081 SELECT wwtt.transaction_temp_id, wwtt.task_type_id, wwtt.status
10082 BULK COLLECT INTO l_transaction_temp_ids, l_task_type_ids, l_statuses
10083 FROM wms_waveplan_tasks_temp wwtt, mtl_material_transactions_temp mmtt, WMS_DISPATCHED_TASKS wdt
10084 WHERE wwtt.transaction_temp_id = wdt.transaction_temp_id AND
10085 wwtt.transaction_temp_id = mmtt.transaction_temp_id AND
10086 wwtt.RESULT = 'X' AND
10087 wwtt.status_id = 3 AND
10088 EXISTS ( SELECT 1 FROM WMS_DISPATCHED_TASKS wdt2
10089 WHERE wdt2.person_id = wwtt.person_id AND
10090 wdt2.status = 9 AND
10091 wdt2.task_method IS NOT NULL AND
10092 wdt2.transaction_temp_id IN( SELECT transaction_temp_id FROM mtl_material_transactions_temp mmtt1
10093 WHERE DECODE(wdt.TASK_METHOD,
10094 'CARTON', mmtt1.cartonization_id,
10095 'PICK_SLIP', mmtt1.pick_slip_number,
10096 'DISCRETE', mmtt1.pick_slip_number,
10097 mmtt1.transaction_source_id) = DECODE(wdt.TASK_METHOD,
10098 'CARTON', mmtt.cartonization_id,
10099 'PICK_SLIP', mmtt.pick_slip_number,
10100 'DISCRETE', mmtt.pick_slip_number,
10101 mmtt.transaction_source_id))
10102 );
10103 IF l_transaction_temp_ids.COUNT > 0
10104 THEN
10105 --BUG: 4707588 (Picking message from msg dictionary)
10106 FOR i IN
10107 l_transaction_temp_ids.FIRST .. l_transaction_temp_ids.LAST
10108 LOOP
10109 fnd_message.set_name ('WMS', 'WMS_GROUP_TASKS_CANNOT_UPDATE');
10110 l_messages (i) := fnd_message.get;
10111 END LOOP;
10112
10113
10114 FORALL i IN l_transaction_temp_ids.FIRST .. l_transaction_temp_ids.LAST
10115 UPDATE wms_waveplan_tasks_temp
10116 SET RESULT = 'E',
10117 error = 'This group of tasks is currently being worked, cannot change status'
10118 WHERE transaction_temp_id = l_transaction_temp_ids (i)
10119 AND task_type_id = l_task_type_ids (i);
10120 END IF;
10121
10122 -- if the original task status is Active, check if the user whom the task is assigned is
10123 -- logged on to the system
10124 SELECT transaction_temp_id, task_type_id, status
10125 BULK COLLECT INTO l_transaction_temp_ids, l_task_type_ids, l_statuses
10126 FROM wms_waveplan_tasks_temp wwtt
10127 WHERE RESULT = 'X' AND
10128 status_id = 9 AND
10129 EXISTS ( SELECT 1 FROM MTL_MOBILE_LOGIN_HIST MMLH, WMS_DISPATCHED_TASKS WDT
10130 WHERE WDT.TRANSACTION_TEMP_ID = WWTT.TRANSACTION_TEMP_ID AND
10131 MMLH.USER_ID = WDT.LAST_UPDATED_BY AND
10132 MMLH.LOGOFF_DATE IS NULL AND
10133 MMLH.EVENT_MESSAGE IS NULL
10134 );
10135
10136 IF l_transaction_temp_ids.COUNT > 0
10137 THEN
10138 FORALL i IN l_transaction_temp_ids.FIRST .. l_transaction_temp_ids.LAST
10139 UPDATE wms_waveplan_tasks_temp
10140 SET RESULT = 'E',
10141 error = 'This task is currently being worked, cannot change status'
10142 WHERE transaction_temp_id = l_transaction_temp_ids (i)
10143 AND task_type_id = l_task_type_ids (i);
10144 END IF;
10145
10146 END IF;
10147
10148 END IF;
10149
10150 -- Employee eligibility validation
10151 IF p_employee_id IS NOT NULL AND NOT p_force_employee_change
10152 THEN
10153 fnd_message.set_name ('WMS', 'WMS_CANNOT_UPDATE_EMPLOYEE');
10154 fnd_message.set_token ('EMPLOYEE', p_employee);
10155 l_message := fnd_message.get;
10156
10157 UPDATE wms_waveplan_tasks_temp wwtt
10158 SET RESULT = 'E',
10159 error = l_message
10160 WHERE RESULT = 'X'
10161 AND NOT EXISTS (
10162 SELECT 1
10163 FROM bom_std_op_resources bsor,
10164 bom_resource_employees bre
10165 WHERE wwtt.user_task_type_id = bsor.standard_operation_id
10166 AND bsor.resource_id = bre.resource_id
10167 AND bre.person_id = p_employee_id);
10168
10169 --j Develop
10170 SELECT transaction_temp_id
10171 BULK COLLECT INTO l_transaction_temp_ids_temp
10172 FROM wms_waveplan_tasks_temp
10173 WHERE RESULT = 'X';
10174
10175 IF (l_transaction_temp_ids_temp.COUNT > 0)
10176 THEN
10177 FOR i IN
10178 l_transaction_temp_ids_temp.FIRST .. l_transaction_temp_ids_temp.LAST
10179 LOOP
10180 IF (getforcesignonflagvalue (l_transaction_temp_ids_temp (i),
10181 l_device_id
10182 ) = 'Y'
10183 )
10184 THEN
10185 fnd_message.set_name ('WMS', 'WMS_CANNOT_UPDATE_EMPLOYEE');
10186 fnd_message.set_token ('EMPLOYEE', p_employee);
10187 l_message := fnd_message.get;
10188 if l_debug = 1 then
10189 DEBUG ('l_device_id : ' || l_device_id, ' Update_TAsk :');
10190 DEBUG (' p_employee_id : ' || p_employee_id,
10191 ' Update_TAsk :'
10192 );
10193 end if;
10194
10195 UPDATE wms_waveplan_tasks_temp wwtt
10196 SET RESULT = 'E',
10197 error = l_message
10198 WHERE transaction_temp_id = l_transaction_temp_ids_temp (i)
10199 AND NOT EXISTS (
10200 SELECT 1
10201 FROM wms_device_assignment_temp
10202 WHERE device_id = l_device_id
10203 AND employee_id = p_employee_id);
10204 END IF;
10205 END LOOP;
10206 END IF;
10207 -- End of J Develop
10208 END IF;
10209
10210 UPDATE wms_waveplan_tasks_temp wwtt
10211 SET person_resource_id =
10212 (SELECT bre.resource_id
10213 FROM bom_std_op_resources bsor, bom_resource_employees bre
10214 WHERE wwtt.user_task_type_id = bsor.standard_operation_id
10215 AND bsor.resource_id = bre.resource_id
10216 AND bre.person_id = wwtt.person_id
10217 AND ROWNUM < 2)
10218 WHERE RESULT = 'X';
10219
10220 IF p_user_task_type_id IS NOT NULL
10221 THEN
10222 -- R12: Can update User Task Type if task is dispatched, active IF
10223 -- Dispatched or Active tasks are in the process of getting updated to pending or Unreleased
10224 IF p_to_status_id IS NOT NULL THEN
10225 UPDATE wms_waveplan_tasks_temp wwtt
10226 SET RESULT = 'E',
10227 error = l_message
10228 WHERE RESULT = 'X' AND (status_id NOT IN (1, 2, 3, 8, 9) AND p_to_status_id IN (1, 8))
10229 RETURNING transaction_temp_id, task_type_id, status
10230 BULK COLLECT INTO l_transaction_temp_ids, l_task_type_ids, l_statuses;
10231 ELSE
10232 -- R12: Cannot update User Task Type if task is dispatched, active or loaded IF
10233 -- Dispatched or Active tasks are NOT in the process of getting updated to pending or Unreleased
10234 UPDATE wms_waveplan_tasks_temp wwtt
10235 SET RESULT = 'E',
10236 error = l_message
10237 WHERE RESULT = 'X' AND status_id NOT IN (1, 8)
10238 RETURNING transaction_temp_id, task_type_id, status
10239 BULK COLLECT INTO l_transaction_temp_ids, l_task_type_ids, l_statuses;
10240 END IF;
10241
10242 IF l_transaction_temp_ids.COUNT > 0
10243 THEN
10244 FOR i IN
10245 l_transaction_temp_ids.FIRST .. l_transaction_temp_ids.LAST
10246 LOOP
10247 fnd_message.set_name ('WMS', 'WMS_CANNOT_UPDATE_USER_TASK_TYPE');
10248 fnd_message.set_token ('STATUS', l_statuses (i));
10249 l_messages (i) := fnd_message.get;
10250 END LOOP;
10251
10252 FORALL i IN l_transaction_temp_ids.FIRST .. l_transaction_temp_ids.LAST
10253 UPDATE wms_waveplan_tasks_temp
10254 SET RESULT = 'E',
10255 error = l_messages (i)
10256 WHERE transaction_temp_id = l_transaction_temp_ids (i)
10257 AND task_type_id = l_task_type_ids (i);
10258 END IF;
10259 END IF;
10260
10261
10262 IF (p_update_priority_type IS NOT NULL AND p_update_priority IS NOT NULL) OR p_clear_priority = 'Y'
10263 THEN
10264 -- R12: Can update priority if task is dispatched, active IF
10265 -- Dispatched or Active tasks are in the process of getting updated to pending or Unreleased
10266 IF p_to_status_id IS NOT NULL THEN
10267 UPDATE wms_waveplan_tasks_temp wwtt
10268 SET RESULT = 'E',
10269 error = l_message
10270 WHERE RESULT = 'X' AND (status_id NOT IN (1, 2, 3, 8, 9) AND p_to_status_id IN (1, 8))
10271 RETURNING transaction_temp_id, task_type_id, status
10272 BULK COLLECT INTO l_transaction_temp_ids, l_task_type_ids, l_statuses;
10273 ELSE
10274 -- R12: Cannot update priority if task is dispatched, active or loaded IF
10275 -- Dispatched or Active tasks are NOT in the process of getting updated to pending or Unreleased
10276 UPDATE wms_waveplan_tasks_temp wwtt
10277 SET RESULT = 'E',
10278 error = l_message
10279 WHERE RESULT = 'X' AND status_id NOT IN (1, 2, 8)
10280 RETURNING transaction_temp_id, task_type_id, status
10281 BULK COLLECT INTO l_transaction_temp_ids, l_task_type_ids, l_statuses;
10282 END IF;
10283
10284 IF l_transaction_temp_ids.COUNT > 0
10285 THEN
10286 FOR i IN
10287 l_transaction_temp_ids.FIRST .. l_transaction_temp_ids.LAST
10288 LOOP
10289 fnd_message.set_name ('WMS', 'WMS_CANNOT_UPDATE_PRIORITY');
10290 fnd_message.set_token ('STATUS', l_statuses (i));
10291 l_messages (i) := fnd_message.get;
10292 END LOOP;
10293
10294 FORALL i IN l_transaction_temp_ids.FIRST .. l_transaction_temp_ids.LAST
10295 UPDATE wms_waveplan_tasks_temp
10296 SET RESULT = 'E',
10297 error = l_messages (i)
10298 WHERE transaction_temp_id = l_transaction_temp_ids (i)
10299 AND task_type_id = l_task_type_ids (i);
10300 END IF;
10301 END IF;
10302
10303 -- If changing status to Queued
10304 IF p_to_status_id = 2
10305 THEN
10306 UPDATE wms_waveplan_tasks_temp
10307 SET task_id = NVL (task_id, wms_dispatched_tasks_s.NEXTVAL),
10308 status = p_to_status,
10309 status_id = p_to_status_id,
10310 priority =
10311 DECODE (p_clear_priority,
10312 'Y', NULL,
10313 DECODE(p_update_priority_type,
10314 'I', NVL(priority,0) + p_update_priority, -- R12: Increment priority
10315 'D', DECODE(SIGN(NVL(priority,0) - p_update_priority),-- R12: Decrement priority
10316 -1, 0,
10317 +1, NVL(priority,0) - p_update_priority,
10318 0, 0),
10319 'S', NVL(p_update_priority, priority), -- R12: Set priority
10320 priority)
10321 ),
10322 person = p_employee,
10323 person_id = p_employee_id,
10324 effective_start_date = p_effective_start_date,
10325 effective_end_date = p_effective_end_date,
10326 person_resource_code = p_person_resource_code,
10327 person_resource_id = p_person_resource_id,
10328 RESULT = 'S',
10329 error = g_task_updated,
10330 is_modified = 'Y'
10331 WHERE RESULT = 'X';
10332 ELSE
10333 if l_debug = 1 then
10334 DEBUG ('Else Part ______________________: ', ' Update_TAsk :');
10335 end if;
10336 UPDATE wms_waveplan_tasks_temp
10337 SET task_id = DECODE (p_to_status_id, 1, NULL, 8, NULL, task_id),
10338 status = NVL (p_to_status, status),
10339 status_id = NVL (p_to_status_id, status_id),
10340 user_task_type = NVL (p_user_task_type, user_task_type), -- R12: Assign User Task Type
10341 user_task_type_id = NVL (p_user_task_type_id, user_task_type_id),-- R12: Assign User Task Type
10342 priority =
10343 DECODE (p_clear_priority,
10344 'Y', NULL,
10345 DECODE(p_update_priority_type,
10346 'I', NVL(priority,0) + p_update_priority, -- R12: Increment priority
10347 'D', DECODE(SIGN(NVL(priority,0) - p_update_priority),-- R12: Decrement priority
10348 -1, 0,
10349 +1, NVL(priority,0) - p_update_priority,
10350 0, 0),
10351 'S', NVL(p_update_priority, priority), -- R12: Set Constant priority value
10352 priority)
10353 ),
10354 person = DECODE (p_to_status_id, 1, NULL, 8, NULL, person),
10355 person_id =
10356 DECODE (p_to_status_id,
10357 1, NULL,
10358 8, NULL,
10359 person_id
10360 ),
10361 effective_start_date =
10362 DECODE (p_to_status_id,
10363 1, NULL,
10364 8, NULL,
10365 effective_start_date
10366 ),
10367 effective_end_date =
10368 DECODE (p_to_status_id,
10369 1, NULL,
10370 8, NULL,
10371 effective_end_date
10372 ),
10373 person_resource_code =
10374 DECODE (p_to_status_id,
10375 1, NULL,
10376 8, NULL,
10377 person_resource_code
10378 ),
10379 person_resource_id =
10380 DECODE (p_person_resource_id,
10381 1, NULL,
10382 8, NULL,
10383 person_resource_id
10384 ),
10385 RESULT = 'S',
10386 error = g_task_updated,
10387 is_modified = 'Y'
10388 WHERE RESULT = 'X';
10389
10390 if l_debug = 1 then
10391 DEBUG ('Else Part : ________________2' || SQL%ROWCOUNT,
10392 ' Update_TAsk :'
10393 );
10394 end if;
10395 END IF;
10396
10397 FORALL i IN p_transaction_temp_id.FIRST .. p_transaction_temp_id.LAST
10398 UPDATE wms_waveplan_tasks_temp
10399 SET RESULT = RESULT
10400 WHERE transaction_temp_id = p_transaction_temp_id (i)
10401 AND task_type_id = p_task_type_id (i)
10402 RETURNING task_id, RESULT, error
10403 BULK COLLECT INTO x_task_id, x_result, x_message;
10404 x_return_status := 'S';
10405 EXCEPTION
10406 WHEN OTHERS
10407 THEN
10408 x_return_status := 'U';
10409 x_return_msg := SQLERRM;
10410 DEBUG ('Sql Error: ' || SQLERRM, 'Task Planning.Task Update');
10411 END update_task;
10412
10413 PROCEDURE cancel_task (
10414 p_transaction_temp_id IN wms_waveplan_tasks_pvt.transaction_temp_table_type,
10415 p_task_type_id IN wms_waveplan_tasks_pvt.task_type_id_table_type,
10416 p_is_crossdock IN BOOLEAN DEFAULT FALSE, /* Bug 5623122 */
10417 x_result OUT NOCOPY wms_waveplan_tasks_pvt.result_table_type,
10418 x_message OUT NOCOPY wms_waveplan_tasks_pvt.message_table_type,
10419 x_task_id OUT NOCOPY wms_waveplan_tasks_pvt.task_id_table_type,
10420 x_return_status OUT NOCOPY VARCHAR2,
10421 x_return_msg OUT NOCOPY VARCHAR2,
10422 x_msg_count OUT NOCOPY NUMBER
10423 )
10424 IS
10425 l_task_id NUMBER;
10426 l_index NUMBER;
10427 l_message wms_waveplan_tasks_temp.error%TYPE;
10428
10429 TYPE status_table_type IS TABLE OF wms_waveplan_tasks_temp.status%TYPE;
10430
10431 l_transaction_temp_ids wms_waveplan_tasks_pvt.transaction_temp_table_type;
10432 l_task_type_ids wms_waveplan_tasks_pvt.task_type_id_table_type;
10433 l_statuses status_table_type;
10434 l_messages wms_waveplan_tasks_pvt.message_table_type;
10435 l_transaction_temp_ids_temp wms_waveplan_tasks_pvt.transaction_temp_table_type;
10436 BEGIN
10437
10438 /*IF g_cannot_update_putaway IS NULL
10439 THEN
10440 fnd_message.set_name ('WMS', 'WMS_CANNOT_UPDATE_PUTAWAY_TASK');
10441 g_cannot_update_putaway := fnd_message.get;
10442 fnd_message.set_name ('WMS', 'WMS_CANNOT_UPDATE_STAGING_MOVE');
10443 g_cannot_update_staging_move := fnd_message.get;
10444 fnd_message.set_name ('WMS', 'WMS_TASK_UPDATED');
10445 g_task_updated := fnd_message.get;
10446 fnd_message.set_name ('WMS', 'WMS_CANNOT_UNRELEASE_CC');
10447 g_cannot_unrelease_cc := fnd_message.get;
10448 END IF;*/
10449
10450
10451 FORALL i IN p_transaction_temp_id.FIRST .. p_transaction_temp_id.LAST
10452 UPDATE wms_waveplan_tasks_temp
10453 SET RESULT = 'X'
10454 WHERE transaction_temp_id = p_transaction_temp_id (i)
10455 AND task_type_id = p_task_type_id (i);
10456
10457 -- Validations
10458 -- 1 Pick
10459 -- 2 Putaway
10460 -- 3 Cycle Count
10461 -- 4 Replenish
10462 -- 5 Move Order Transfer
10463 -- 6 Move Order Issue
10464 -- 7 Staging Move
10465
10466 -- Cannot update the following :
10467 UPDATE wms_waveplan_tasks_temp
10468 SET RESULT = 'E',
10469 error =
10470 DECODE (task_type_id,
10471 1, 'Can not cancel pick task',
10472 3, 'Can not cancel cycle count task',
10473 4, 'Can not cancel replenish task',
10474 5, 'Can not cancel move order transfer task',
10475 6, 'Can not cancel move order issue task',
10476 7, 'Can not cancel staging move task'
10477 )
10478 WHERE RESULT = 'X' AND task_type_id <> 2;
10479
10480 /* Bug 5623122 */
10481 -- Cannot update Putaway tasks
10482 IF NOT p_is_crossdock THEN
10483 UPDATE wms_waveplan_tasks_temp
10484 SET RESULT = 'E',
10485 error =
10486 DECODE (task_type_id,
10487 2, 'Can not cancel putaway task'
10488 )
10489 WHERE RESULT = 'X' AND task_type_id = 2;
10490 END IF;
10491 /* End of Bug 5623122 */
10492
10493 -- cannot update completed tasks
10494 UPDATE wms_waveplan_tasks_temp
10495 SET RESULT = 'E',
10496 error = 'Can not cancel completed tasks'
10497 WHERE RESULT = 'X' AND status_id = 6;
10498
10499 UPDATE wms_waveplan_tasks_temp
10500 SET status_id = 12,
10501 status = g_status_codes(12),
10502 is_modified = 'Y',
10503 RESULT = 'S',
10504 error = 'Task Canceled'
10505 WHERE RESULT = 'X';
10506
10507 FORALL i IN p_transaction_temp_id.FIRST .. p_transaction_temp_id.LAST
10508 UPDATE wms_waveplan_tasks_temp
10509 SET RESULT = RESULT
10510 WHERE transaction_temp_id = p_transaction_temp_id (i)
10511 AND task_type_id = p_task_type_id (i)
10512 RETURNING task_id, RESULT, error
10513 BULK COLLECT INTO x_task_id, x_result, x_message;
10514 x_return_status := 'S';
10515 EXCEPTION
10516 WHEN OTHERS
10517 THEN
10518 x_return_status := 'U';
10519 x_return_msg := SQLERRM;
10520 DEBUG ('Sql Error: ' || SQLERRM, 'Task Planning.Cancel Task');
10521 END cancel_task;
10522
10523 PROCEDURE remove_tasks (
10524 p_transaction_temp_id IN wms_waveplan_tasks_pvt.transaction_temp_table_type,
10525 x_record_count OUT NOCOPY NUMBER,
10526 x_return_status OUT NOCOPY VARCHAR2,
10527 x_msg_data OUT NOCOPY VARCHAR2
10528 )
10529 IS
10530 l_removed_count NUMBER := 0;
10531 BEGIN
10532 x_return_status := 'S';
10533 FORALL i IN p_transaction_temp_id.FIRST .. p_transaction_temp_id.LAST
10534 DELETE FROM wms_waveplan_tasks_temp
10535 WHERE transaction_temp_id = p_transaction_temp_id (i);
10536 l_removed_count := SQL%ROWCOUNT;
10537 g_record_count := g_record_count - l_removed_count;
10538 x_record_count := g_record_count;
10539 EXCEPTION
10540 WHEN OTHERS
10541 THEN
10542 x_return_status := 'U';
10543 x_msg_data := SQLERRM;
10544 END remove_tasks;
10545
10546 PROCEDURE save_tasks (
10547 p_task_action VARCHAR2,
10548 p_commit BOOLEAN,
10549 p_user_id NUMBER,
10550 p_login_id NUMBER,
10551 x_save_count OUT NOCOPY NUMBER,
10552 x_return_status OUT NOCOPY VARCHAR2,
10553 x_msg_data OUT NOCOPY VARCHAR2,
10554 x_msg_count OUT NOCOPY NUMBER
10555 )
10556 IS
10557 TYPE transaction_temp_id_table_type IS TABLE OF mtl_material_transactions_temp.transaction_temp_id%TYPE
10558 INDEX BY BINARY_INTEGER;
10559
10560 TYPE wms_task_status_table_type IS TABLE OF mtl_material_transactions_temp.wms_task_status%TYPE
10561 INDEX BY BINARY_INTEGER;
10562
10563 TYPE task_priority_table_type IS TABLE OF mtl_material_transactions_temp.task_priority%TYPE
10564 INDEX BY BINARY_INTEGER;
10565
10566 TYPE person_id_table_type IS TABLE OF wms_dispatched_tasks.person_id%TYPE
10567 INDEX BY BINARY_INTEGER;
10568
10569 TYPE person_resource_id_table_type IS TABLE OF wms_dispatched_tasks.person_resource_id%TYPE /* Bug 5630187 */
10570 INDEX BY BINARY_INTEGER;
10571
10572 TYPE effective_start_date IS TABLE OF wms_dispatched_tasks.effective_start_date%TYPE
10573 INDEX BY BINARY_INTEGER;
10574
10575 TYPE effective_end_date IS TABLE OF wms_dispatched_tasks.effective_end_date%TYPE
10576 INDEX BY BINARY_INTEGER;
10577
10578 TYPE task_type_id IS TABLE OF wms_waveplan_tasks_temp.task_type_id%TYPE
10579 INDEX BY BINARY_INTEGER;
10580
10581 TYPE user_task_type_id IS TABLE OF wms_waveplan_tasks_temp.user_task_type_id%TYPE -- R12: Update User Task Type Id
10582 INDEX BY BINARY_INTEGER;
10583
10584 l_transaction_temp_id_table transaction_temp_id_table_type;
10585 l_wms_task_status_table wms_task_status_table_type;
10586 l_task_priority_table task_priority_table_type;
10587 l_person_id_table person_id_table_type;
10588 l_person_resource_id_table person_resource_id_table_type; /* Bug 5630187 */
10589 l_effective_start_date_table effective_start_date;
10590 l_effective_end_date_table effective_end_date;
10591 l_task_type_id task_type_id;
10592 l_user_task_type_id user_task_type_id; -- R12: Update User Task Type Id
10593 l_error_message VARCHAR2 (120);
10594 l_update_date DATE;
10595 l_non_cycle_count_number NUMBER := 0;
10596 l_cycle_count_number NUMBER := 0;
10597 l_children_task_count NUMBER := 0;
10598 l_debug NUMBER := NVL (fnd_profile.VALUE ('INV_DEBUG_TRACE'), 0);
10599
10600 CURSOR cur_wwtt
10601 IS
10602 SELECT transaction_temp_id, task_type_id, mmtt_last_updated_by,
10603 mmtt_last_update_date, wdt_last_updated_by,
10604 wdt_last_update_date, person_id, person_id_original,person_resource_id,/* Bug 5630187 - Added person_resource_id */
10605 effective_start_date, effective_end_date, status_id,
10606 status_id_original, priority, priority_original, user_task_type_id, num_of_child_tasks -- R12: Added User Task Type Id
10607 FROM wms_waveplan_tasks_temp wwtt
10608 WHERE wwtt.is_modified = 'Y';
10609
10610 --Patchset J: Bulk picking
10611 --Get the transaction_temp_id of the children tasks
10612 CURSOR bulk_children_tasks_cur(trx_temp_id NUMBER)
10613 IS
10614 SELECT transaction_temp_id
10615 FROM mtl_material_transactions_temp
10616 WHERE parent_line_id = trx_temp_id
10617 AND transaction_temp_id <> trx_temp_id
10618 FOR UPDATE nowait;
10619 --end bulk picking
10620
10621 i NUMBER;
10622 record_locked EXCEPTION;
10623 PRAGMA EXCEPTION_INIT (record_locked, -54);
10624 BEGIN
10625 x_return_status := 'S';
10626 x_save_count := 0;
10627 SAVEPOINT save_tasks;
10628 wwtt_dump;
10629 i := 1;
10630
10631 IF p_task_action = 'U' THEN -- Update tasks
10632
10633 FOR rec_wwtt IN cur_wwtt
10634 LOOP
10635 BEGIN
10636 IF rec_wwtt.task_type_id IN (2, 8) AND rec_wwtt.status_id = 12 THEN
10637 if l_debug = 1 then
10638 DEBUG ('Cancelled Plan');
10639 end if;
10640
10641 x_save_count := x_save_count + 1;
10642 if l_debug = 1 then
10643 DEBUG ('no of records saved are' || x_save_count);
10644 end if;
10645
10646 IF g_plan_cancelled IS NULL THEN
10647 fnd_message.set_name ('WMS', 'WMS_PLAN_CANCELLED');
10648 g_plan_cancelled := fnd_message.get;
10649 END IF;
10650
10651
10652 UPDATE wms_waveplan_tasks_temp
10653 SET is_modified = 'N',
10654 RESULT = 'S',
10655 error = g_plan_cancelled
10656 WHERE transaction_temp_id = rec_wwtt.transaction_temp_id;
10657
10658 END IF;
10659
10660 if l_debug = 1 then
10661 DEBUG ('In the wwtt for loop');
10662 end if;
10663
10664 IF rec_wwtt.task_type_id <> 3
10665 THEN
10666 SELECT mmtt.transaction_temp_id
10667 INTO l_transaction_temp_id_table (i)
10668 FROM mtl_material_transactions_temp mmtt,
10669 wms_dispatched_tasks wdt
10670 WHERE mmtt.transaction_temp_id =
10671 rec_wwtt.transaction_temp_id
10672 AND mmtt.transaction_temp_id = wdt.transaction_temp_id(+)
10673 AND mmtt.wms_task_type = wdt.task_type(+)
10674 AND DECODE (wdt.status,
10675 NULL, NVL (mmtt.wms_task_status, 1),
10676 wdt.status
10677 ) = NVL (rec_wwtt.status_id_original, -1)
10678 AND NVL (mmtt.task_priority, -1) =
10679 NVL (rec_wwtt.priority_original,
10680 -1)
10681 AND NVL (wdt.person_id, -1) =
10682 NVL (rec_wwtt.person_id_original,
10683 -1)
10684 AND mmtt.last_updated_by = rec_wwtt.mmtt_last_updated_by
10685 AND mmtt.last_update_date =
10686 rec_wwtt.mmtt_last_update_date
10687 AND NVL (wdt.last_updated_by, -1) =
10688 NVL (rec_wwtt.wdt_last_updated_by,
10689 -1)
10690 AND ( wdt.last_update_date =
10691 rec_wwtt.wdt_last_update_date
10692 OR ( wdt.last_update_date IS NULL
10693 AND rec_wwtt.wdt_last_update_date IS NULL
10694 )
10695 )
10696 FOR UPDATE NOWAIT;
10697
10698 l_non_cycle_count_number := l_non_cycle_count_number + 1;
10699 ELSE
10700 SELECT mcce.cycle_count_entry_id
10701 INTO l_transaction_temp_id_table (i)
10702 FROM mtl_cycle_count_entries mcce,
10703 wms_dispatched_tasks wdt
10704 WHERE mcce.cycle_count_entry_id =
10705 rec_wwtt.transaction_temp_id
10706 AND mcce.cycle_count_entry_id = wdt.transaction_temp_id(+)
10707 AND 3 = wdt.task_type(+)
10708 AND DECODE (wdt.status, NULL, 1, wdt.status) =
10709 NVL (rec_wwtt.status_id_original,
10710 -1)
10711 AND NVL (mcce.task_priority, -1) =
10712 NVL (rec_wwtt.priority_original,
10713 -1)
10714 AND NVL (wdt.person_id, -1) =
10715 NVL (rec_wwtt.person_id_original,
10716 -1)
10717 AND mcce.last_updated_by = rec_wwtt.mmtt_last_updated_by
10718 AND mcce.last_update_date =
10719 rec_wwtt.mmtt_last_update_date
10720 AND NVL (wdt.last_updated_by, -1) =
10721 NVL (rec_wwtt.wdt_last_updated_by,
10722 -1)
10723 AND ( wdt.last_update_date =
10724 rec_wwtt.wdt_last_update_date
10725 OR ( wdt.last_update_date IS NULL
10726 AND rec_wwtt.wdt_last_update_date IS NULL
10727 )
10728 )
10729 FOR UPDATE NOWAIT;
10730
10731 l_cycle_count_number := l_cycle_count_number + 1;
10732 END IF;
10733
10734 l_wms_task_status_table (i) := rec_wwtt.status_id;
10735 l_task_priority_table (i) := rec_wwtt.priority;
10736 l_person_id_table (i) := rec_wwtt.person_id;
10737 l_person_resource_id_table (i) := rec_wwtt.person_resource_id;
10738 l_effective_start_date_table (i) := sysdate ; -- rec_wwtt.effective_start_date; --bug#6409956
10739 l_effective_end_date_table (i) := sysdate ; --rec_wwtt.effective_end_date; --bug#6409956
10740 l_task_type_id (i) := rec_wwtt.task_type_id;
10741 l_user_task_type_id (i) := rec_wwtt.user_task_type_id; -- R12: Update User Task Type Id
10742 i := i + 1;
10743
10744 --Patchset J bulk picking
10745 --If updating a bulk tasks, update the children tasks also.
10746 --Condition to check if it's a bulk task is with the
10747 --num_of_child_task column.
10748 --Bulk task should always have children tasks
10749 IF rec_wwtt.num_of_child_tasks IS NOT NULL
10750 AND rec_wwtt.num_of_child_tasks > 0 THEN
10751 FOR bulk_children IN bulk_children_tasks_cur(l_transaction_temp_id_table(i-1))
10752 LOOP
10753 l_transaction_temp_id_table(i) :=
10754 bulk_children.transaction_temp_id;
10755
10756 l_wms_task_status_table (i) := rec_wwtt.status_id;
10757 l_task_priority_table (i) := rec_wwtt.priority;
10758 l_person_id_table (i) := rec_wwtt.person_id;
10759 l_person_resource_id_table (i) := rec_wwtt.person_resource_id;
10760 l_effective_start_date_table (i) := sysdate ; -- rec_wwtt.effective_start_date; --bug#6409956
10761 l_effective_end_date_table (i) := sysdate ; --rec_wwtt.effective_end_date; --bug#6409956
10762 l_task_type_id (i) := rec_wwtt.task_type_id;
10763 l_user_task_type_id (i) := rec_wwtt.user_task_type_id; -- R12: Update User Task Type Id
10764 i := i + 1;
10765 l_children_task_count := l_children_task_count + 1;
10766 END LOOP;
10767 END IF;
10768 --/bulk picking
10769 EXCEPTION
10770 WHEN record_locked
10771 THEN
10772 NULL;
10773 WHEN NO_DATA_FOUND
10774 THEN
10775 NULL;
10776 END;
10777 END LOOP;
10778
10779 x_save_count := x_save_count + l_transaction_temp_id_table.COUNT - l_children_task_count;
10780
10781 if l_debug = 1 then
10782 DEBUG ('Save Count is ' || x_save_count);
10783 end if;
10784
10785 -- IF l_transaction_temp_id_table.COUNT > 0 THEN
10786 IF x_save_count > 0
10787 THEN
10788 if l_debug = 1 then
10789 DEBUG ('Save Count is ' || x_save_count);
10790 end if;
10791
10792 IF l_non_cycle_count_number > 0
10793 THEN
10794 FORALL i IN l_transaction_temp_id_table.FIRST .. l_transaction_temp_id_table.LAST
10795 UPDATE mtl_material_transactions_temp
10796 SET wms_task_status =
10797 DECODE (l_wms_task_status_table (i),
10798 8, 8,
10799 1, 1,
10800 NULL
10801 ),
10802 task_priority = l_task_priority_table (i),
10803 last_update_date = SYSDATE,
10804 last_updated_by = p_user_id,
10805 last_update_login = p_login_id,
10806 standard_operation_id = l_user_task_type_id (i)
10807 WHERE transaction_temp_id = l_transaction_temp_id_table (i) -- R12: Update User Task Type Id
10808 AND l_task_type_id (i) <> 3;
10809 if l_debug = 1 then
10810 DEBUG ('No of records updated are-777 ' || SQL%ROWCOUNT);
10811 end if;
10812 END IF;
10813
10814 IF l_cycle_count_number > 0 THEN
10815 FORALL i IN l_transaction_temp_id_table.FIRST .. l_transaction_temp_id_table.LAST
10816 UPDATE mtl_cycle_count_entries
10817 SET task_priority = l_task_priority_table (i),
10818 last_update_date = SYSDATE,
10819 last_updated_by = p_user_id,
10820 last_update_login = p_login_id,
10821 standard_operation_id = l_user_task_type_id (i) -- R12: Update User Task Type Id
10822 WHERE cycle_count_entry_id = l_transaction_temp_id_table (i)
10823 AND l_task_type_id (i) = 3;
10824 if l_debug = 1 then
10825 DEBUG ('No of records updated are-666 ' || SQL%ROWCOUNT);
10826 end if;
10827 END IF;
10828
10829 -- Delete WDT line for tasks that were queued but now are pending or unreleased
10830 DELETE wms_dispatched_tasks wdt
10831 WHERE wdt.status IN (2, 3, 9) -- R12: Delete the Active or Dispatched tasks which were updated to pending/Unreleased
10832 AND wdt.transaction_temp_id IN (
10833 SELECT transaction_temp_id
10834 FROM wms_waveplan_tasks_temp wwtt
10835 WHERE wwtt.status_id IN (1, 8)
10836 AND wwtt.is_modified = 'Y');
10837 if l_debug = 1 then
10838 DEBUG ('No of records deleted are-555 ' || SQL%ROWCOUNT);
10839 end if;
10840
10841 l_update_date := SYSDATE;
10842 if l_debug = 1 then
10843 DEBUG ('inserting into WDT ' || x_save_count);
10844 end if;
10845
10846 -- Insert into WDT tasks that have become queued from pending or unreleased
10847 INSERT INTO wms_dispatched_tasks
10848 (task_id, transaction_temp_id, organization_id,
10849 user_task_type, person_id, effective_start_date,
10850 effective_end_date, person_resource_id,
10851 machine_resource_id, status, dispatched_time,
10852 last_update_date, last_updated_by, creation_date,
10853 created_by, last_update_login, task_type, priority,
10854 move_order_line_id, operation_plan_id, transfer_lpn_id)
10855 (SELECT wwtt.task_id, wwtt.transaction_temp_id,
10856 wwtt.organization_id, NVL (wwtt.user_task_type_id, 0),
10857 wwtt.person_id,sysdate, sysdate , /*bug#6409956.replaced effective dates by sysdate */
10858 wwtt.person_resource_id, NULL, 2, -- Queued
10859 NULL, l_update_date, p_user_id, l_update_date, p_user_id,
10860 p_login_id, wwtt.task_type_id, wwtt.priority,
10861 wwtt.move_order_line_id, wwtt.operation_plan_id,
10862 wwtt.to_lpn_id
10863 FROM wms_waveplan_tasks_temp wwtt
10864 WHERE wwtt.status_id = 2
10865 AND wwtt.status_id_original IN (1, 8)
10866 AND wwtt.is_modified = 'Y'
10867 AND NOT EXISTS (
10868 SELECT 1
10869 FROM wms_dispatched_tasks wdt
10870 WHERE wdt.transaction_temp_id =
10871 wwtt.transaction_temp_id));
10872 if l_debug = 1 then
10873 DEBUG ('No of records inserted are-444 ' || SQL%ROWCOUNT);
10874 end if;
10875 -- forall i IN l_transaction_temp_id_table.first..l_transaction_temp_id_table.last
10876 FORALL i IN 1 .. l_transaction_temp_id_table.COUNT
10877 UPDATE wms_dispatched_tasks
10878 SET person_id = l_person_id_table (i),
10879 person_resource_id = l_person_resource_id_table (i),
10880 effective_start_date = l_effective_start_date_table (i),
10881 effective_end_date = l_effective_end_date_table (i),
10882 priority = l_task_priority_table (i),
10883 last_update_date = l_update_date,
10884 last_updated_by = p_user_id,
10885 last_update_login = p_login_id
10886 WHERE transaction_temp_id = l_transaction_temp_id_table (i);
10887 if l_debug = 1 then
10888 DEBUG ('No of records updated are-333 ' || SQL%ROWCOUNT);
10889 DEBUG ('Commiting ');
10890 end if;
10891
10892 /* Bug 5507934 - Placed at the end of the procedure*/
10893 /*IF p_commit
10894 THEN
10895 DEBUG ('Commiting the record');
10896 COMMIT;
10897 END IF;*/
10898 /* End Bug 5507934 */
10899
10900 IF g_task_saved IS NULL
10901 THEN
10902 fnd_message.set_name ('WMS', 'WMS_TASK_SAVED');
10903 g_task_saved := fnd_message.get;
10904 END IF;
10905
10906 -- forall i IN l_transaction_temp_id_table.first..l_transaction_temp_id_table.last
10907 FORALL i IN 1 .. l_transaction_temp_id_table.COUNT
10908 UPDATE wms_waveplan_tasks_temp
10909 SET RESULT = 'S',
10910 error = g_task_saved,
10911 is_modified = 'N',
10912 person_id_original = l_person_id_table (i),
10913 status_id_original = l_wms_task_status_table (i),
10914 priority_original = l_task_priority_table (i),
10915 mmtt_last_updated_by = p_user_id,
10916 mmtt_last_update_date = l_update_date,
10917 wdt_last_updated_by =
10918 DECODE (l_wms_task_status_table (i),
10919 1, NULL,
10920 8, NULL,
10921 p_user_id
10922 ),
10923 wdt_last_update_date =
10924 TO_DATE (DECODE (l_wms_task_status_table (i),
10925 1, NULL,
10926 8, NULL,
10927 TO_CHAR (l_update_date,
10928 'DD-MON-YY HH24:MI:SS'
10929 )
10930 ),
10931 'DD-MON-YY HH24:MI:SS'
10932 )
10933 WHERE transaction_temp_id = l_transaction_temp_id_table (i);
10934 if l_debug = 1 then
10935 DEBUG ('No of records updated are-222 ' || SQL%ROWCOUNT);
10936 end if;
10937 END IF; -- count > 0
10938
10939 ELSIF p_task_action = 'C' THEN -- cancel tasks
10940
10941 FOR rec_wwtt IN cur_wwtt
10942 LOOP
10943 IF rec_wwtt.task_type_id = 2 AND rec_wwtt.status_id = 12 THEN
10944
10945 WMS_Cross_Dock_Pvt.cancel_crossdock_task(
10946 p_transaction_temp_id => rec_wwtt.transaction_temp_id
10947 , x_return_status => x_return_status
10948 , x_msg_data => x_msg_data
10949 , x_msg_count => x_msg_count
10950 );
10951 IF x_return_status = fnd_api.g_ret_sts_success THEN
10952 UPDATE wms_waveplan_tasks_temp
10953 SET RESULT = 'S',
10954 error = 'Task Cancelled',
10955 is_modified = 'N'
10956 WHERE transaction_temp_id = rec_wwtt.transaction_temp_id;
10957 x_save_count := x_save_count + 1;
10958 END IF;
10959
10960 END IF;
10961 END LOOP;
10962 END IF;
10963
10964 fnd_message.set_name ('FND', 'FORM_RECORD_CHANGED');
10965 l_error_message := fnd_message.get;
10966
10967 UPDATE wms_waveplan_tasks_temp
10968 SET RESULT = 'E',
10969 error = l_error_message
10970 WHERE is_modified = 'Y';
10971
10972 if l_debug = 1 then
10973 DEBUG ('No of records updated are-111 ' || SQL%ROWCOUNT);
10974 end if;
10975
10976 /* Bug 5507934 */
10977 IF p_commit
10978 THEN
10979 if l_debug = 1 then
10980 DEBUG ('Commiting the record');
10981 end if;
10982 COMMIT;
10983 END IF;
10984 /* End of 5507934 */
10985 EXCEPTION
10986 WHEN OTHERS
10987 THEN
10988 ROLLBACK TO save_tasks;
10989 x_return_status := 'U';
10990 x_msg_data := SQLERRM;
10991 DEBUG ('SQL error: ' || SQLERRM, 'Task Planning.Save Tasks');
10992 END;
10993
10994 -- This procedure will populate the required data for the performance chart
10995 PROCEDURE get_status_dist (
10996 x_status_chart_data OUT NOCOPY cb_chart_status_tbl_type,
10997 x_status_data_count OUT NOCOPY NUMBER,
10998 x_return_status OUT NOCOPY VARCHAR2,
10999 x_msg_count OUT NOCOPY NUMBER,
11000 x_msg_data OUT NOCOPY VARCHAR2,
11001 p_task_type_id IN NUMBER DEFAULT NULL
11002 )
11003 IS
11004 CURSOR status_cursor
11005 IS
11006 SELECT status_id, COUNT (*) task_count
11007 FROM wms_waveplan_tasks_temp
11008 WHERE task_type_id = NVL (p_task_type_id, task_type_id)
11009 GROUP BY status_id;
11010
11011 l_loop_index NUMBER;
11012 BEGIN
11013 -- Get all of the lookup values for the status code
11014 -- There are 7, 1-Pending, 2-Queued, 3-Dispatched, 4-Loaded , 5 -errored, 6-Completed, 7-Hold
11015 -- 8-Unreleased, 9-Active, 10-Suspended
11016 IF g_status_codes_orig.COUNT = 0
11017 THEN
11018 set_status_codes;
11019 END IF;
11020
11021 x_status_data_count := 0;
11022 l_loop_index := 0;
11023
11024 FOR c1 IN status_cursor
11025 LOOP
11026 l_loop_index := l_loop_index + 1;
11027 x_status_chart_data (l_loop_index).status :=
11028 g_status_codes_orig (c1.status_id);
11029 x_status_chart_data (l_loop_index).task_count := c1.task_count;
11030 END LOOP;
11031
11032 x_status_data_count := l_loop_index;
11033 x_return_status := fnd_api.g_ret_sts_success;
11034 EXCEPTION
11035 WHEN OTHERS
11036 THEN
11037 x_return_status := fnd_api.g_ret_sts_unexp_error;
11038 DEBUG (SQLERRM, 'Task_planning.get_status_dist');
11039 END get_status_dist;
11040
11041 -- This procedure will populate the required data for the performance chart
11042 PROCEDURE get_type_dist (
11043 x_type_chart_data OUT NOCOPY cb_chart_type_tbl_type,
11044 x_type_data_count OUT NOCOPY NUMBER,
11045 x_return_status OUT NOCOPY VARCHAR2,
11046 x_msg_count OUT NOCOPY NUMBER,
11047 x_msg_data OUT NOCOPY VARCHAR2,
11048 p_task_type_id IN NUMBER DEFAULT NULL
11049 )
11050 IS
11051 CURSOR type_cursor
11052 IS
11053 SELECT task_type_id, COUNT (*) task_count
11054 FROM wms_waveplan_tasks_temp
11055 WHERE task_type_id = NVL (p_task_type_id, task_type_id)
11056 GROUP BY task_type_id;
11057
11058 l_loop_index NUMBER;
11059 BEGIN
11060 -- Get all of the lookup values for the task type description
11061 -- There should be only 6, 1-Pick, 2-Putaway, 3-Cycle Count, 4-Replenish 5-MOXfer 6-MOIssue
11062 IF g_task_types_orig.COUNT = 0
11063 THEN
11064 set_task_type;
11065 END IF;
11066
11067 x_type_data_count := 0;
11068 l_loop_index := 0;
11069
11070 FOR c1 IN type_cursor
11071 LOOP
11072 l_loop_index := l_loop_index + 1;
11073 x_type_chart_data (l_loop_index).TYPE :=
11074 g_task_types_orig (c1.task_type_id);
11075 x_type_chart_data (l_loop_index).task_count := c1.task_count;
11076 END LOOP;
11077
11078 x_type_data_count := l_loop_index;
11079 x_return_status := fnd_api.g_ret_sts_success;
11080 EXCEPTION
11081 WHEN OTHERS
11082 THEN
11083 x_return_status := fnd_api.g_ret_sts_unexp_error;
11084 DEBUG (SQLERRM, 'Task_planning.get_type_dist');
11085 END get_type_dist;
11086
11087 PROCEDURE calculate_summary (
11088 p_calculate_time IN BOOLEAN DEFAULT FALSE,
11089 p_time_per_task IN wms_waveplan_tasks_pvt.time_per_task_table_type,
11090 p_time_per_task_uom IN wms_waveplan_tasks_pvt.time_uom_table_type,
11091 p_time_uom_code IN VARCHAR2 DEFAULT NULL,
11092 p_time_uom IN VARCHAR2 DEFAULT NULL,
11093 p_calculate_volume IN BOOLEAN DEFAULT FALSE,
11094 p_volume_uom_code IN VARCHAR2 DEFAULT NULL,
11095 p_volume_uom IN VARCHAR2 DEFAULT NULL,
11096 p_calculate_weight IN BOOLEAN DEFAULT FALSE,
11097 p_weight_uom_code IN VARCHAR2 DEFAULT NULL,
11098 p_weight_uom IN VARCHAR2 DEFAULT NULL,
11099 x_total_tasks OUT NOCOPY NUMBER,
11100 x_total_time OUT NOCOPY NUMBER,
11101 x_total_weight OUT NOCOPY NUMBER,
11102 x_total_volume OUT NOCOPY NUMBER,
11103 x_return_status OUT NOCOPY VARCHAR2,
11104 x_msg_data OUT NOCOPY VARCHAR2,
11105 x_msg_count OUT NOCOPY NUMBER
11106 )
11107 IS
11108 TYPE user_task_type_id_type IS TABLE OF wms_waveplan_tasks_temp.user_task_type_id%TYPE
11109 INDEX BY BINARY_INTEGER;
11110
11111 TYPE time_type IS TABLE OF wms_waveplan_tasks_temp.time_estimate%TYPE
11112 INDEX BY BINARY_INTEGER;
11113
11114 TYPE volume_type IS TABLE OF wms_waveplan_tasks_temp.unit_volume%TYPE
11115 INDEX BY BINARY_INTEGER;
11116
11117 TYPE weight_type IS TABLE OF wms_waveplan_tasks_temp.unit_weight%TYPE
11118 INDEX BY BINARY_INTEGER;
11119
11120 TYPE volume_uom_type IS TABLE OF wms_waveplan_tasks_temp.volume_uom_code%TYPE
11121 INDEX BY BINARY_INTEGER;
11122
11123 TYPE weight_uom_type IS TABLE OF wms_waveplan_tasks_temp.weight_uom_code%TYPE
11124 INDEX BY BINARY_INTEGER;
11125
11126 TYPE item_id_type IS TABLE OF wms_waveplan_tasks_temp.inventory_item_id%TYPE
11127 INDEX BY BINARY_INTEGER;
11128
11129 TYPE quantity_type IS TABLE OF wms_waveplan_tasks_temp.transaction_quantity%TYPE
11130 INDEX BY BINARY_INTEGER;
11131
11132 TYPE result_type IS TABLE OF wms_waveplan_tasks_temp.RESULT%TYPE
11133 INDEX BY BINARY_INTEGER;
11134
11135 TYPE ERROR_TYPE IS TABLE OF wms_waveplan_tasks_temp.error%TYPE
11136 INDEX BY BINARY_INTEGER;
11137
11138 l_user_task_type_id user_task_type_id_type;
11139 l_time time_type;
11140 l_volume volume_type;
11141 l_volume_uom_code volume_uom_type;
11142 l_weight weight_type;
11143 l_weight_uom_code weight_uom_type;
11144 l_inventory_item_id item_id_type;
11145 l_quantity quantity_type;
11146 l_result result_type;
11147 l_error ERROR_TYPE;
11148 l_transaction_temp_id transaction_temp_table_type;
11149 l_task_type_id task_type_id_table_type;
11150 BEGIN
11151 IF p_calculate_time OR p_calculate_weight OR p_calculate_volume
11152 THEN
11153 SELECT transaction_temp_id, task_type_id, user_task_type_id,
11154 unit_volume, volume_uom_code, unit_weight, weight_uom_code,
11155 inventory_item_id, transaction_quantity
11156 BULK COLLECT INTO l_transaction_temp_id, l_task_type_id, l_user_task_type_id,
11157 l_volume, l_volume_uom_code, l_weight, l_weight_uom_code,
11158 l_inventory_item_id, l_quantity
11159 FROM wms_waveplan_tasks_temp
11160 WHERE RESULT IN ('X', 'Y', 'Z');
11161
11162 x_total_tasks := l_transaction_temp_id.COUNT;
11163
11164 IF p_calculate_time
11165 THEN
11166 x_total_time := 0;
11167 END IF;
11168
11169 IF p_calculate_weight
11170 THEN
11171 x_total_weight := 0;
11172 END IF;
11173
11174 IF p_calculate_volume
11175 THEN
11176 x_total_volume := 0;
11177 END IF;
11178
11179 FOR i IN 1 .. l_transaction_temp_id.COUNT
11180 LOOP
11181 l_result (i) := 'S';
11182 l_time (i) := NULL;
11183 l_error (i) := NULL;
11184
11185 IF p_calculate_time AND l_user_task_type_id (i) IS NOT NULL
11186 THEN
11187 IF p_time_per_task_uom.EXISTS ((l_user_task_type_id (i)))
11188 THEN
11189 IF NVL (p_time_per_task_uom (l_user_task_type_id (i)),
11190 '@@@'
11191 ) <> p_time_uom_code
11192 THEN
11193 l_time (i) :=
11194 inv_convert.inv_um_convert
11195 (item_id => l_inventory_item_id (i),
11196 PRECISION => NULL,
11197 from_quantity => p_time_per_task
11198 (l_user_task_type_id
11199 (i)
11200 ),
11201 from_unit => p_time_per_task_uom
11202 (l_user_task_type_id
11203 (i)
11204 ),
11205 to_unit => p_time_uom_code,
11206 from_name => NULL,
11207 to_name => NULL
11208 );
11209
11210 IF l_time (i) = -99999
11211 THEN
11212 l_time (i) := NULL;
11213 l_result (i) := 'E';
11214
11215 IF g_time_uom_error IS NULL
11216 THEN
11217 fnd_message.set_name ('WMS', 'WMS_TIME_UOM_ERROR');
11218 g_time_uom_error := fnd_message.get;
11219 END IF;
11220
11221 IF g_cannot_summarize_time IS NULL
11222 THEN
11223 fnd_message.set_name ('WMS',
11224 'WMS_CANNOT_SUMMARIZE_TIME'
11225 );
11226 g_cannot_summarize_time := fnd_message.get;
11227 END IF;
11228
11229 l_error (i) :=
11230 SUBSTR ( l_error (i)
11231 || g_time_uom_error
11232 || g_cannot_summarize_time,
11233 1,
11234 240
11235 );
11236 ELSE
11237 IF g_summarized_time IS NULL
11238 THEN
11239 fnd_message.set_name ('WMS',
11240 'WMS_SUMMARIZED_TIME');
11241 g_summarized_time := fnd_message.get;
11242 END IF;
11243
11244 l_error (i) :=
11245 SUBSTR (l_error (i) || g_summarized_time, 1,
11246 240);
11247 END IF; -- UOM converted?
11248 ELSE
11249 IF g_summarized_time IS NULL
11250 THEN
11251 fnd_message.set_name ('WMS', 'WMS_SUMMARIZED_TIME');
11252 g_summarized_time := fnd_message.get;
11253 END IF;
11254
11255 l_error (i) :=
11256 SUBSTR (l_error (i) || g_summarized_time, 1,
11257 240);
11258 l_time (i) := p_time_per_task (l_user_task_type_id (i));
11259 END IF; -- UOM is different?
11260
11261 x_total_time := x_total_time + NVL (l_time (i), 0);
11262 ELSE
11263 IF g_cannot_summarize_time IS NULL
11264 THEN
11265 fnd_message.set_name ('WMS',
11266 'WMS_CANNOT_SUMMARIZE_TIME');
11267 g_cannot_summarize_time := fnd_message.get;
11268 END IF;
11269
11270 l_error (i) :=
11271 SUBSTR (l_error (i) || g_cannot_summarize_time, 1,
11272 240);
11273 l_result (i) := 'E';
11274 END IF;
11275 ELSIF p_calculate_time AND l_user_task_type_id (i) IS NULL
11276 THEN
11277 IF g_cannot_summarize_time IS NULL
11278 THEN
11279 fnd_message.set_name ('WMS', 'WMS_CANNOT_SUMMARIZE_TIME');
11280 g_cannot_summarize_time := fnd_message.get;
11281 END IF;
11282
11283 l_error (i) :=
11284 SUBSTR (l_error (i) || g_cannot_summarize_time, 1,
11285 240);
11286 l_result (i) := 'E';
11287 END IF;
11288
11289 IF p_calculate_volume
11290 THEN
11291 IF l_volume (i) IS NULL
11292 THEN
11293 IF g_no_item_vol IS NULL
11294 THEN
11295 fnd_message.set_name ('WMS', 'WMS_NO_ITEM_VOL');
11296 g_no_item_vol := fnd_message.get;
11297 END IF;
11298
11299 IF g_cannot_summarize_vol IS NULL
11300 THEN
11301 fnd_message.set_name ('WMS', 'WMS_CANNOT_SUMMARIZE_VOL');
11302 g_cannot_summarize_vol := fnd_message.get;
11303 END IF;
11304
11305 l_result (i) := 'E';
11306 l_error (i) :=
11307 SUBSTR ( l_error (i)
11308 || g_no_item_vol
11309 || g_cannot_summarize_vol,
11310 1,
11311 240
11312 );
11313 ELSE
11314 IF NVL (l_volume_uom_code (i), '@@@') <> p_volume_uom_code
11315 THEN
11316 l_volume (i) :=
11317 inv_convert.inv_um_convert
11318 (item_id => l_inventory_item_id
11319 (i),
11320 PRECISION => NULL,
11321 from_quantity => l_quantity
11322 (i)
11323 * l_volume
11324 (i),
11325 from_unit => l_volume_uom_code
11326 (i),
11327 to_unit => p_volume_uom_code,
11328 from_name => NULL,
11329 to_name => NULL
11330 );
11331
11332 IF l_volume (i) = -99999
11333 THEN
11334 l_volume (i) := NULL;
11335 l_result (i) := 'E';
11336
11337 IF g_vol_uom_error IS NULL
11338 THEN
11339 fnd_message.set_name ('WMS', 'WMS_VOL_UOM_ERROR');
11340 g_vol_uom_error := fnd_message.get;
11341 END IF;
11342
11343 IF g_cannot_summarize_vol IS NULL
11344 THEN
11345 fnd_message.set_name ('WMS',
11346 'WMS_CANNOT_SUMMARIZE_VOL'
11347 );
11348 g_cannot_summarize_vol := fnd_message.get;
11349 END IF;
11350
11351 l_error (i) :=
11352 SUBSTR ( l_error (i)
11353 || g_vol_uom_error
11354 || g_cannot_summarize_vol,
11355 1,
11356 240
11357 );
11358 ELSE
11359 IF g_summarized_volume IS NULL
11360 THEN
11361 fnd_message.set_name ('WMS',
11362 'WMS_SUMMARIZED_VOLUME'
11363 );
11364 g_summarized_volume := fnd_message.get;
11365 END IF;
11366
11367 l_error (i) :=
11368 SUBSTR (l_error (i) || g_summarized_volume, 1,
11369 240);
11370 END IF;
11371 ELSE
11372 IF g_summarized_volume IS NULL
11373 THEN
11374 fnd_message.set_name ('WMS', 'WMS_SUMMARIZED_VOLUME');
11375 g_summarized_volume := fnd_message.get;
11376 END IF;
11377
11378 l_error (i) :=
11379 SUBSTR (l_error (i) || g_summarized_volume, 1,
11380 240);
11381 l_volume (i) := l_quantity (i) * l_volume (i);
11382 END IF;
11383
11384 x_total_volume := x_total_volume + NVL (l_volume (i), 0);
11385 END IF;
11386 ELSE -- Calculate Volume
11387 l_volume (i) := NULL;
11388 END IF;
11389
11390 IF p_calculate_weight
11391 THEN
11392 IF l_weight (i) IS NULL
11393 THEN
11394 IF g_no_item_wt IS NULL
11395 THEN
11396 fnd_message.set_name ('WMS', 'WMS_NO_ITEM_WT');
11397 g_no_item_wt := fnd_message.get;
11398 END IF;
11399
11400 IF g_cannot_summarize_wt IS NULL
11401 THEN
11402 fnd_message.set_name ('WMS', 'WMS_CANNOT_SUMMARIZE_WT');
11403 g_cannot_summarize_wt := fnd_message.get;
11404 END IF;
11405
11406 l_result (i) := 'E';
11407 l_error (i) :=
11408 SUBSTR ( l_error (i)
11409 || g_no_item_wt
11410 || g_cannot_summarize_wt,
11411 1,
11412 240
11413 );
11414 ELSE
11415 IF l_weight (i) IS NOT NULL
11416 AND NVL (l_weight_uom_code (i), '@@@') <>
11417 p_weight_uom_code
11418 THEN
11419 l_weight (i) :=
11420 inv_convert.inv_um_convert
11421 (item_id => l_inventory_item_id
11422 (i),
11423 PRECISION => NULL,
11424 from_quantity => l_quantity
11425 (i)
11426 * l_weight
11427 (i),
11428 from_unit => l_weight_uom_code
11429 (i),
11430 to_unit => p_weight_uom_code,
11431 from_name => NULL,
11432 to_name => NULL
11433 );
11434
11435 IF l_weight (i) = -99999
11436 THEN
11437 l_weight (i) := NULL;
11438 l_result (i) := 'E';
11439
11440 IF g_wt_uom_error IS NULL
11441 THEN
11442 fnd_message.set_name ('WMS', 'WMS_WT_UOM_ERROR');
11443 g_wt_uom_error := fnd_message.get;
11444 END IF;
11445
11446 IF g_cannot_summarize_wt IS NULL
11447 THEN
11448 fnd_message.set_name ('WMS',
11449 'WMS_CANNOT_SUMMARIZE_WT'
11450 );
11451 g_cannot_summarize_wt := fnd_message.get;
11452 END IF;
11453
11454 l_error (i) :=
11455 SUBSTR ( l_error (i)
11456 || g_wt_uom_error
11457 || g_cannot_summarize_wt,
11458 1,
11459 240
11460 );
11461 ELSE
11462 IF g_summarized_weight IS NULL
11463 THEN
11464 fnd_message.set_name ('WMS',
11465 'WMS_SUMMARIZED_WEIGHT'
11466 );
11467 g_summarized_weight := fnd_message.get;
11468 END IF;
11469
11470 l_error (i) :=
11471 SUBSTR (l_error (i) || g_summarized_weight, 1,
11472 240);
11473 END IF;
11474 ELSE
11475 IF g_summarized_weight IS NULL
11476 THEN
11477 fnd_message.set_name ('WMS', 'WMS_SUMMARIZED_WEIGHT');
11478 g_summarized_weight := fnd_message.get;
11479 END IF;
11480
11481 l_error (i) :=
11482 SUBSTR (l_error (i) || g_summarized_weight, 1,
11483 240);
11484 l_weight (i) := l_quantity (i) * l_weight (i);
11485 END IF;
11486
11487 x_total_weight := x_total_weight + NVL (l_weight (i), 0);
11488 END IF;
11489 ELSE -- compute weight
11490 l_weight (i) := NULL;
11491 END IF;
11492 END LOOP;
11493
11494 FORALL i IN l_transaction_temp_id.FIRST .. l_transaction_temp_id.LAST
11495 UPDATE wms_waveplan_tasks_temp
11496 SET time_estimate = l_time (i),
11497 display_weight = l_weight (i),
11498 display_volume = l_volume (i)
11499 WHERE transaction_temp_id = l_transaction_temp_id (i)
11500 AND task_type_id = l_task_type_id (i);
11501 END IF;
11502
11503 DELETE FROM wms_waveplan_summary_temp;
11504
11505 INSERT INTO wms_waveplan_summary_temp
11506 (task_type_id, task_type, task_type_description,
11507 total_tasks, total_time, time_uom, weight, weight_uom,
11508 volume, volume_uom, organization_id)
11509 SELECT wwtt.user_task_type_id, bso.operation_code,
11510 bso.operation_description, COUNT (*),
11511 ROUND (SUM (wwtt.time_estimate), 1), p_time_uom,
11512 ROUND (SUM (wwtt.display_weight), 1), p_weight_uom,
11513 ROUND (SUM (wwtt.display_volume), 1), p_volume_uom,
11514 wwtt.organization_id
11515 FROM wms_waveplan_tasks_temp wwtt, bom_standard_operations bso
11516 WHERE wwtt.RESULT IN ('X', 'Y', 'Z')
11517 AND wwtt.user_task_type_id = bso.standard_operation_id(+)
11518 AND wwtt.organization_id = bso.organization_id(+)
11519 GROUP BY wwtt.user_task_type_id,
11520 bso.operation_code,
11521 bso.operation_description,
11522 wwtt.organization_id;
11523
11524 FORALL i IN l_transaction_temp_id.FIRST .. l_transaction_temp_id.LAST
11525 UPDATE wms_waveplan_tasks_temp
11526 SET RESULT = l_result (i),
11527 error = l_error (i)
11528 WHERE transaction_temp_id = l_transaction_temp_id (i)
11529 AND task_type_id = l_task_type_id (i);
11530 x_total_time := ROUND (x_total_time, 2);
11531 x_total_volume := ROUND (x_total_volume, 2);
11532 x_total_weight := ROUND (x_total_weight, 2);
11533 g_rows_marked := FALSE;
11534 END;
11535
11536 PROCEDURE cancel_plans (
11537 x_return_status OUT NOCOPY VARCHAR2,
11538 x_ret_code OUT NOCOPY wms_waveplan_tasks_pvt.message_table_type,
11539 p_transaction_temp_table wms_waveplan_tasks_pvt.transaction_temp_table_type
11540 )
11541 IS
11542 l_transaction_temp_id wms_waveplan_tasks_temp.transaction_temp_id%TYPE;
11543 l_return_status VARCHAR2 (1);
11544 l_msg_data VARCHAR2 (2000);
11545 l_msg_count NUMBER;
11546 l_error_code NUMBER;
11547 l_cancel_plan BOOLEAN;
11548 l_debug NUMBER := NVL (fnd_profile.VALUE ('INV_DEBUG_TRACE'), 0);
11549 BEGIN
11550
11551 FOR i IN 1 .. p_transaction_temp_table.COUNT
11552 LOOP
11553 BEGIN
11554
11555 SELECT transaction_temp_id
11556 INTO l_transaction_temp_id
11557 FROM wms_waveplan_tasks_temp
11558 WHERE parent_line_id = p_transaction_temp_table (i)
11559 AND status = 'Pending';
11560
11561 l_cancel_plan := TRUE;
11562 EXCEPTION
11563 WHEN NO_DATA_FOUND THEN
11564 if l_debug = 1 then
11565 debug('Pending Task record does not exists..');
11566 end if;
11567 l_cancel_plan := FALSE;
11568 END;
11569
11570
11571 IF l_cancel_plan THEN
11572
11573 --call the runtime api to cancel the plan
11574 if l_debug = 1 then
11575 DEBUG ('calling wms_atf_runtime_pub_apis.cancel_operation_plan ');
11576 DEBUG ( 'p_source_task_id '
11577 || l_transaction_temp_id
11578 || ' p_activity_type_id 1'
11579 );
11580 end if;
11581 wms_atf_runtime_pub_apis.cancel_operation_plan
11582 (x_return_status => l_return_status,
11583 x_msg_data => l_msg_data,
11584 x_msg_count => l_msg_count,
11585 x_error_code => l_error_code,
11586 p_source_task_id => l_transaction_temp_id,
11587 p_activity_type_id => 1
11588 );
11589 if l_debug = 1 then
11590 DEBUG ('ret status from atf cancel ' || l_return_status);
11591 end if;
11592
11593 IF l_return_status = fnd_api.g_ret_sts_success
11594 THEN
11595 x_ret_code (i) := fnd_api.g_ret_sts_success;
11596 if l_debug = 1 then
11597 DEBUG ('success for ' || i || ' ' || x_ret_code (i));
11598 end if;
11599 ELSE
11600 x_ret_code (i) := l_msg_data;
11601 if l_debug = 1 then
11602 DEBUG ('failure for ' || i || ' ' || l_msg_data);
11603 end if;
11604 END IF;
11605 ELSE
11606 fnd_message.set_name('WMS','WMS_CANCEL_FAILED');
11607 x_ret_code(i) := fnd_message.get;
11608 END IF;
11609
11610 END LOOP;
11611
11612 FORALL i IN 1 .. p_transaction_temp_table.COUNT
11613
11614 UPDATE wms_waveplan_tasks_temp
11615 SET is_modified = 'Y',
11616 status_id = 12,
11617 status = g_status_codes(12)
11618 WHERE transaction_temp_id = p_transaction_temp_table (i)
11619 AND x_ret_code (i) = fnd_api.g_ret_sts_success;
11620
11621 if l_debug = 1 then
11622 DEBUG ('No of records updated are' || SQL%ROWCOUNT);
11623 end if;
11624
11625 FORALL j IN 1..p_transaction_temp_table.COUNT
11626 DELETE FROM wms_waveplan_tasks_temp
11627 WHERE parent_line_id = p_transaction_temp_table (j)
11628 AND status_id = 1
11629 AND x_ret_code (j) = fnd_api.g_ret_sts_success;
11630
11631 if l_debug = 1 then
11632 DEBUG ('No of records deleted are' || SQL%ROWCOUNT);
11633 end if;
11634
11635 x_return_status := fnd_api.g_ret_sts_success;
11636 EXCEPTION
11637 WHEN OTHERS
11638 THEN
11639 DEBUG ('other exception in cancel_plans ' || SQLERRM);
11640 x_return_status := fnd_api.g_ret_sts_unexp_error;
11641 END cancel_plans;
11642
11643
11644 FUNCTION get_final_query
11645 RETURN VARCHAR2
11646 IS
11647 BEGIN
11648 RETURN g_final_query;
11649 END get_final_query;
11650
11651 FUNCTION get_task_summary
11652 RETURN wms_task_summary_tbl_type
11653 IS
11654 BEGIN
11655 RETURN g_wms_task_summary_tbl;
11656 END get_task_summary;
11657
11658 PROCEDURE set_task_summary(p_wms_task_summary_tbl wms_task_summary_tbl_type)
11659 IS
11660 BEGIN
11661 g_wms_task_summary_tbl := p_wms_task_summary_tbl;
11662 END set_task_summary;
11663
11664 END wms_waveplan_tasks_pvt;