DBA Data[Home] [Help]

PACKAGE BODY: APPS.WMS_WAVEPLAN_TASKS_PVT

Source


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