DBA Data[Home] [Help]

PACKAGE BODY: APPS.WMS_RULE_1

Source


1 PACKAGE BODY WMS_RULE_1 AS
2 
3      PROCEDURE open_curs
4         (
5                 p_cursor                IN OUT NOCOPY WMS_RULE_PVT.cv_pick_type,
6                 p_organization_id   IN NUMBER,
7                 p_inventory_item_id   IN NUMBER,
8                 p_transaction_type_id   IN NUMBER,
9                 p_revision    IN VARCHAR2,
10                 p_lot_number    IN VARCHAR2,
11                 p_subinventory_code IN VARCHAR2,
12                 p_locator_id    IN NUMBER,
13                 p_cost_group_id   IN NUMBER,
14                 p_pp_transaction_temp_id IN NUMBER,
15                 p_serial_controlled IN NUMBER,
16                 p_detail_serial   IN NUMBER,
17                 p_detail_any_serial IN NUMBER,
18                 p_from_serial_number  IN VARCHAR2,
19                 p_to_serial_number  IN VARCHAR2,
20                 p_unit_number   IN VARCHAR2,
21                 p_lpn_id    IN NUMBER,
22                 p_project_id    IN NUMBER,
23                 p_task_id   IN NUMBER,
24                 x_result    OUT NOCOPY NUMBER
25         ) IS
26                 g_organization_id             NUMBER;
27                 g_inventory_item_id           NUMBER;
28                 g_transaction_type_id         NUMBER;
29                 g_revision                    VARCHAR2(3);
30                 g_lot_number                  VARCHAR2(80);
31                 g_subinventory_code           VARCHAR2(10);
32                 g_locator_id                  NUMBER;
33                 g_cost_group_id               NUMBER;
34                 g_pp_transaction_temp_id      NUMBER;
35                 g_serial_control              NUMBER;
36                 g_detail_serial               NUMBER;
37                 g_detail_any_serial           NUMBER;
38                 g_from_serial_number          VARCHAR2(30);
39                 g_to_serial_number            VARCHAR2(30);
40                 g_unit_number                 VARCHAR2(30);
41                 g_lpn_id                      NUMBER;
42                 g_project_id                  NUMBER;
43                 g_task_id                     NUMBER;
44 
45 
46     BEGIN
47       g_organization_id :=p_organization_id;
48       g_inventory_item_id := p_inventory_item_id;
49       g_transaction_type_id := p_transaction_type_id;
50       g_revision := p_revision;
51       g_lot_number := p_lot_number;
52       g_subinventory_code :=p_subinventory_code;
53       g_locator_id := p_locator_id;
54       g_cost_group_id := p_cost_group_id;
55       g_pp_transaction_temp_id := p_pp_transaction_temp_id;
56       g_serial_control:= p_serial_controlled;
57       g_detail_serial := p_detail_serial;
58       g_detail_any_serial := p_detail_any_serial;
59       g_from_serial_number := p_from_serial_number;
60       g_to_serial_number := p_to_serial_number;
61       g_unit_number := p_unit_number;
62       g_lpn_id := p_lpn_id;
63       g_project_id := p_project_id;
64       g_task_id := p_task_id;
65 
66      IF (g_serial_control = 1)    AND (g_detail_serial in (1,2)) THEN
67          OPEN p_cursor FOR select base.REVISION
68 ,base.LOT_NUMBER
69 ,base.LOT_EXPIRATION_DATE
70 ,base.SUBINVENTORY_CODE
71 ,base.LOCATOR_ID
72 ,base.COST_GROUP_ID
73 ,base.UOM_CODE
74 ,decode(g_lpn_id, -9999, NULL, g_lpn_id) LPN_ID
75 ,base.SERIAL_NUMBER
76 ,base.primary_quantity 
77 ,base.secondary_quantity 
78 ,base.grade_code 
79 ,NULL consist_string
80 ,mln.EXPIRATION_DATE||base.DATE_RECEIVED order_by_string
81  from MTL_LOT_NUMBERS mln
82 ,WMS_TRX_DETAILS_TMP_V mptdtv
83 ,(
84    select  msn.current_organization_id organization_id
85     ,msn.inventory_item_id
86     ,msn.revision
87     ,msn.lot_number
88     ,lot.expiration_date lot_expiration_date
89     ,msn.current_subinventory_code subinventory_code
90     ,msn.current_locator_id locator_id
91     ,msn.cost_group_id
92     ,msn.status_id   --added status_id
93     ,msn.serial_number
94     ,msn.initialization_date date_received
95     ,1 primary_quantity
96     ,null secondary_quantity                            -- new
97     ,lot.grade_code grade_code                          -- new
98     ,sub.reservable_type
99     ,nvl(loc.reservable_type,1)  locreservable          -- Bug 6719290
100     ,nvl(lot.reservable_type,1)  lotreservable          -- Bug 6719290
101     ,nvl(loc.pick_uom_code, sub.pick_uom_code) uom_code
102     ,WMS_Rule_PVT.GetConversionRate(
103          nvl(loc.pick_uom_code, sub.pick_uom_code)
104         ,msn.current_organization_id
105         ,msn.inventory_item_id) conversion_rate
106     ,msn.lpn_id lpn_id
107     ,loc.project_id project_id
108     ,loc.task_id task_id
109           ,NULL locator_inventory_item_id
110           ,NULL empty_flag
111           ,NULL location_current_units
112    from  mtl_serial_numbers msn
113     ,mtl_secondary_inventories sub
114     ,mtl_item_locations loc
115     ,mtl_lot_numbers lot
116    where msn.current_status = 3
117       and decode(g_unit_number, '-9999', 'a', '-7777', nvl(msn.end_item_unit_number, '-7777'), msn.end_item_unit_number) =
118       decode(g_unit_number, '-9999', 'a', g_unit_number)
119       and (msn.group_mark_id IS NULL or msn.group_mark_id = -1)
120       --and (g_detail_serial IN ( 1,2)
121         and ( g_detail_any_serial = 2   or   (g_detail_any_serial = 1
122             and g_from_serial_number <= msn.serial_number
123             and lengthb(g_from_serial_number) = lengthb(msn.serial_number)
124             and g_to_serial_number >=  msn.serial_number
125             and lengthb(g_to_serial_number) = lengthb(msn.serial_number))
126              or ( g_from_serial_number is null or g_to_serial_number is null)
127           )
128       and sub.organization_id = msn.current_organization_id
129       and sub.secondary_inventory_name = msn.current_subinventory_code
130       and loc.organization_id (+)= msn.current_organization_id
131       and loc.inventory_location_id (+)= msn.current_locator_id
132       and lot.organization_id (+)= msn.current_organization_id
133       and lot.inventory_Item_id (+)= msn.inventory_item_id
134       and lot.lot_number (+)= msn.lot_number
135      )base
136  where base.ORGANIZATION_ID = g_organization_id
137 and base.INVENTORY_ITEM_ID = g_inventory_item_id
138  and decode(g_subinventory_code, '-9999', 'a', base.SUBINVENTORY_CODE) = decode(g_subinventory_code, '-9999', 'a', g_subinventory_code)
139  and  ((exists (select 1 from mtl_parameters where organization_id = g_organization_id and default_status_id is not null )  AND exists(select 1 from mtl_material_statuses where status_id = base.STATUS_ID AND RESERVABLE_TYPE = 1)) OR (NOT exists(select 1 from mtl_parameters where organization_id = g_organization_id and default_status_id is not NULL)  and decode(g_subinventory_code, '-9999', base.RESERVABLE_TYPE, 1) = 1))
140  and decode(g_locator_id, -9999, 1, base.locator_id) = decode(g_locator_id,-9999, 1, g_locator_id)
141  and decode(g_revision, '-99', 'a', base.REVISION) = decode(g_revision, '-99', 'a', g_revision)
142  and decode(g_lot_number, '-9999', 'a', base.LOT_NUMBER) = decode(g_lot_number, '-9999', 'a', g_lot_number)
143  and decode(g_lpn_id, -9999, 1, base.lpn_id) = decode(g_lpn_id, -9999, 1, g_lpn_id)
144  and decode(g_cost_group_id, -9999, 1, base.cost_group_id) = decode(g_cost_group_id, -9999, 1, g_cost_group_id)
145  and (decode(g_project_id, -9999, -1, base.project_id) = decode(g_project_id, -9999, -1, g_project_id) OR ( g_project_id = -7777  and base.project_id IS NULL)) 
146  and (g_project_id = -9999 OR nvl(base.task_id, -9999) = g_task_id OR (g_task_id = -7777 and base.task_id IS NULL))
147  and mptdtv.PP_TRANSACTION_TEMP_ID = g_pp_transaction_temp_id
148 and mln.ORGANIZATION_ID (+) = base.ORGANIZATION_ID
149 and mln.INVENTORY_ITEM_ID (+) = base.INVENTORY_ITEM_ID
150 and mln.LOT_NUMBER (+) = base.LOT_NUMBER
151  order by mln.EXPIRATION_DATE asc
152 ,base.DATE_RECEIVED asc
153 ,base.CONVERSION_RATE desc
154 ;
155      Elsif (g_serial_control = 1) AND (g_detail_serial = 3) THEN
156         OPEN p_cursor FOR select base.REVISION
157 ,base.LOT_NUMBER
158 ,base.LOT_EXPIRATION_DATE
159 ,base.SUBINVENTORY_CODE
160 ,base.LOCATOR_ID
161 ,base.COST_GROUP_ID
162 ,base.UOM_CODE
163 ,decode(g_lpn_id, -9999, NULL, g_lpn_id) LPN_ID
164 ,NULL SERIAL_NUMBER
165 ,sum(base.primary_quantity) 
166 ,sum(base.secondary_quantity) 
167 ,base.grade_code 
168 ,NULL consist_string
169 ,mln.EXPIRATION_DATE||base.DATE_RECEIVED order_by_string
170  from MTL_LOT_NUMBERS mln
171 ,WMS_TRX_DETAILS_TMP_V mptdtv
172 ,(
173     select  msn.current_organization_id organization_id
174      ,msn.inventory_item_id
175      ,msn.revision
176      ,msn.lot_number
177      ,lot.expiration_date lot_expiration_date
178      ,msn.current_subinventory_code subinventory_code
179      ,msn.current_locator_id locator_id
180      ,msn.cost_group_id
181      ,msn.status_id	--added status_id
182      ,msn.serial_number
183      ,msn.initialization_date date_received
184      ,1 primary_quantity
185      ,null secondary_quantity                            -- new
186      ,lot.grade_code grade_code                          -- new
187      ,sub.reservable_type
188      ,nvl(loc.reservable_type,1)   locreservable                -- Bug 6719290
189      ,nvl(lot.reservable_type,1)   lotreservable                -- Bug 6719290
190      ,nvl(loc.pick_uom_code, sub.pick_uom_code) uom_code
191      ,WMS_Rule_PVT.GetConversionRate(
192           nvl(loc.pick_uom_code, sub.pick_uom_code)
193          ,msn.current_organization_id
194          ,msn.inventory_item_id) conversion_rate
195      ,msn.lpn_id lpn_id
196      ,loc.project_id project_id
197      ,loc.task_id task_id
198            ,NULL locator_inventory_item_id
199            ,NULL empty_flag
200            ,NULL location_current_units
201       from  mtl_serial_numbers msn
202      ,mtl_secondary_inventories sub
203      ,mtl_item_locations loc
204      ,mtl_lot_numbers lot
205     where msn.current_status = 3
206        and decode(g_unit_number, '-9999', 'a', '-7777', nvl(msn.end_item_unit_number, '-7777'), msn.end_item_unit_number) =
207        decode(g_unit_number, '-9999', 'a', g_unit_number)
208        and (msn.group_mark_id IS NULL or msn.group_mark_id = -1)
209        and (g_detail_serial = 3
210            OR(g_detail_any_serial = 1
211         OR (g_from_serial_number <= msn.serial_number
212            AND lengthb(g_from_serial_number) = lengthb(msn.serial_number)
213            AND g_to_serial_number >=  msn.serial_number
214                  AND lengthb(g_to_serial_number) = lengthb(msn.serial_number)
215            )))
216        and sub.organization_id = msn.current_organization_id
217        and sub.secondary_inventory_name = msn.current_subinventory_code
218        and loc.organization_id (+)= msn.current_organization_id
219        and loc.inventory_location_id (+)= msn.current_locator_id
220        and lot.organization_id (+)= msn.current_organization_id
221        and lot.inventory_Item_id (+)= msn.inventory_item_id
222        and lot.lot_number (+)= msn.lot_number
223        and inv_detail_util_pvt.is_serial_trx_allowed(
224                                         g_transaction_type_id
225                                         ,msn.current_organization_id
226                                         ,msn.inventory_item_id
227                                         ,msn.status_id) = 'Y' )base
228  where base.ORGANIZATION_ID = g_organization_id
229 and base.INVENTORY_ITEM_ID = g_inventory_item_id
230  and decode(g_subinventory_code, '-9999', 'a', base.SUBINVENTORY_CODE) = decode(g_subinventory_code, '-9999', 'a', g_subinventory_code)
231  and  ((exists (select 1 from mtl_parameters where organization_id = g_organization_id and default_status_id is not null )  AND exists(select 1 from mtl_material_statuses where status_id = base.STATUS_ID AND RESERVABLE_TYPE = 1)) OR (NOT exists(select 1 from mtl_parameters where organization_id = g_organization_id and default_status_id is not NULL)  and decode(g_subinventory_code, '-9999', base.RESERVABLE_TYPE, 1) = 1))
232  and decode(g_locator_id, -9999, 1, base.locator_id) = decode(g_locator_id,-9999, 1, g_locator_id)
233  and decode(g_revision, '-99', 'a', base.REVISION) = decode(g_revision, '-99', 'a', g_revision)
234  and decode(g_lot_number, '-9999', 'a', base.LOT_NUMBER) = decode(g_lot_number, '-9999', 'a', g_lot_number)
235  and decode(g_lpn_id, -9999, 1, base.lpn_id) = decode(g_lpn_id, -9999, 1, g_lpn_id)
236  and decode(g_cost_group_id, -9999, 1, base.cost_group_id) = decode(g_cost_group_id, -9999, 1, g_cost_group_id)
237  and (decode(g_project_id, -9999, -1, base.project_id) = decode(g_project_id, -9999, -1, g_project_id) OR ( g_project_id = -7777  and base.project_id IS NULL)) 
238  and (g_project_id = -9999 OR nvl(base.task_id, -9999) = g_task_id OR (g_task_id = -7777 and base.task_id IS NULL))
239  and mptdtv.PP_TRANSACTION_TEMP_ID = g_pp_transaction_temp_id
240 and mln.ORGANIZATION_ID (+) = base.ORGANIZATION_ID
241 and mln.INVENTORY_ITEM_ID (+) = base.INVENTORY_ITEM_ID
242 and mln.LOT_NUMBER (+) = base.LOT_NUMBER
243  group by base.ORGANIZATION_ID
244 ,base.INVENTORY_ITEM_ID
245 ,base.REVISION
246 ,base.LOT_NUMBER
247 ,base.LOT_EXPIRATION_DATE
248 ,base.SUBINVENTORY_CODE
249 ,base.LOCATOR_ID
250 ,base.COST_GROUP_ID
251 ,base.PROJECT_ID
252 ,base.TASK_ID
253 ,base.UOM_CODE
254 ,base.GRADE_CODE
255 ,mln.EXPIRATION_DATE,base.DATE_RECEIVED,base.CONVERSION_RATE
256 ,mln.EXPIRATION_DATE||base.DATE_RECEIVED
257  order by mln.EXPIRATION_DATE asc
258 ,base.DATE_RECEIVED asc
259 ,base.CONVERSION_RATE desc
260 ;
261      Elsif (g_serial_control = 1) AND  (g_detail_serial = 4) THEN
262            OPEN p_cursor FOR select base.REVISION
263 ,base.LOT_NUMBER
264 ,base.LOT_EXPIRATION_DATE
265 ,base.SUBINVENTORY_CODE
266 ,base.LOCATOR_ID
267 ,base.COST_GROUP_ID
268 ,base.UOM_CODE
269 ,decode(g_lpn_id, -9999, NULL, g_lpn_id) LPN_ID
270 ,NULL SERIAL_NUMBER
271 ,sum(base.primary_quantity) 
272 ,sum(base.secondary_quantity) 
273 ,base.grade_code 
274 ,NULL consist_string
275 ,mln.EXPIRATION_DATE||base.DATE_RECEIVED order_by_string
276  from MTL_LOT_NUMBERS mln
277 ,WMS_TRX_DETAILS_TMP_V mptdtv
278 ,(
279          select  msn.current_organization_id organization_id
280           ,msn.inventory_item_id
281           ,msn.revision
282           ,msn.lot_number
283           ,lot.expiration_date lot_expiration_date
284           ,msn.current_subinventory_code subinventory_code
285           ,msn.current_locator_id locator_id
286           ,msn.cost_group_id
287 	   ,msn.status_id   --added status_id
288           ,msn.serial_number
289           ,msn.initialization_date date_received
290           ,1 primary_quantity
291           ,null secondary_quantity                            -- new
292           ,lot.grade_code grade_code                          -- new
293           ,sub.reservable_type
294           ,nvl(loc.reservable_type,1)  locreservable          -- Bug 6719290
295           ,nvl(lot.reservable_type,1)  lotreservable          -- Bug 6719290
296           ,nvl(loc.pick_uom_code, sub.pick_uom_code) uom_code
297           ,WMS_Rule_PVT.GetConversionRate(
298                nvl(loc.pick_uom_code, sub.pick_uom_code)
299               ,msn.current_organization_id
300               ,msn.inventory_item_id) conversion_rate
301           ,msn.lpn_id lpn_id
302           ,loc.project_id project_id
303           ,loc.task_id task_id
304                 ,NULL locator_inventory_item_id
305                 ,NULL empty_flag
306                 ,NULL location_current_units
307            from  mtl_serial_numbers msn
308           ,mtl_secondary_inventories sub
309           ,mtl_item_locations loc
310           ,mtl_lot_numbers lot
311           where msn.current_status = 3
312             and decode(g_unit_number, '-9999', 'a', '-7777', nvl(msn.end_item_unit_number, '-7777'), msn.end_item_unit_number) =
313             decode(g_unit_number, '-9999', 'a', g_unit_number)
314             and (msn.group_mark_id IS NULL or msn.group_mark_id = -1)
315             and (g_detail_serial = 4
316                 OR(g_detail_any_serial = 1
317              OR (g_from_serial_number <= msn.serial_number
318                 AND lengthb(g_from_serial_number) = lengthb(msn.serial_number)
319                 AND g_to_serial_number >=  msn.serial_number
320                       AND lengthb(g_to_serial_number) = lengthb(msn.serial_number)
321                 )))
322             and sub.organization_id = msn.current_organization_id
323             and sub.secondary_inventory_name = msn.current_subinventory_code
327             and lot.inventory_Item_id (+)= msn.inventory_item_id
324             and loc.organization_id (+)= msn.current_organization_id
325             and loc.inventory_location_id (+)= msn.current_locator_id
326             and lot.organization_id (+)= msn.current_organization_id
328             and lot.lot_number (+)= msn.lot_number
329              )base
330  where base.ORGANIZATION_ID = g_organization_id
331 and base.INVENTORY_ITEM_ID = g_inventory_item_id
332  and decode(g_subinventory_code, '-9999', 'a', base.SUBINVENTORY_CODE) = decode(g_subinventory_code, '-9999', 'a', g_subinventory_code)
333  and  ((exists (select 1 from mtl_parameters where organization_id = g_organization_id and default_status_id is not null )  AND exists(select 1 from mtl_material_statuses where status_id = base.STATUS_ID AND RESERVABLE_TYPE = 1)) OR (NOT exists(select 1 from mtl_parameters where organization_id = g_organization_id and default_status_id is not NULL)  and decode(g_subinventory_code, '-9999', base.RESERVABLE_TYPE, 1) = 1))
334  and decode(g_locator_id, -9999, 1, base.locator_id) = decode(g_locator_id,-9999, 1, g_locator_id)
335  and decode(g_revision, '-99', 'a', base.REVISION) = decode(g_revision, '-99', 'a', g_revision)
336  and decode(g_lot_number, '-9999', 'a', base.LOT_NUMBER) = decode(g_lot_number, '-9999', 'a', g_lot_number)
337  and decode(g_lpn_id, -9999, 1, base.lpn_id) = decode(g_lpn_id, -9999, 1, g_lpn_id)
338  and decode(g_cost_group_id, -9999, 1, base.cost_group_id) = decode(g_cost_group_id, -9999, 1, g_cost_group_id)
339  and (decode(g_project_id, -9999, -1, base.project_id) = decode(g_project_id, -9999, -1, g_project_id) OR ( g_project_id = -7777  and base.project_id IS NULL)) 
340  and (g_project_id = -9999 OR nvl(base.task_id, -9999) = g_task_id OR (g_task_id = -7777 and base.task_id IS NULL))
341  and mptdtv.PP_TRANSACTION_TEMP_ID = g_pp_transaction_temp_id
342 and mln.ORGANIZATION_ID (+) = base.ORGANIZATION_ID
343 and mln.INVENTORY_ITEM_ID (+) = base.INVENTORY_ITEM_ID
344 and mln.LOT_NUMBER (+) = base.LOT_NUMBER
345  group by base.ORGANIZATION_ID
346 ,base.INVENTORY_ITEM_ID
347 ,base.REVISION
348 ,base.LOT_NUMBER
349 ,base.LOT_EXPIRATION_DATE
350 ,base.SUBINVENTORY_CODE
351 ,base.LOCATOR_ID
352 ,base.COST_GROUP_ID
353 ,base.PROJECT_ID
354 ,base.TASK_ID
355 ,base.UOM_CODE
356 ,base.GRADE_CODE
357 ,mln.EXPIRATION_DATE,base.DATE_RECEIVED,base.CONVERSION_RATE
358 ,mln.EXPIRATION_DATE||base.DATE_RECEIVED
359  order by mln.EXPIRATION_DATE asc
360 ,base.DATE_RECEIVED asc
361 ,base.CONVERSION_RATE desc
362 ;
363 
364      Elsif ((g_serial_control <> 1) OR (g_detail_serial = 0)) THEN
365        OPEN p_cursor FOR select base.REVISION
366 ,base.LOT_NUMBER
367 ,base.LOT_EXPIRATION_DATE
368 ,base.SUBINVENTORY_CODE
369 ,base.LOCATOR_ID
370 ,base.COST_GROUP_ID
371 ,base.UOM_CODE
372 ,decode(g_lpn_id, -9999, NULL, g_lpn_id) LPN_ID
373 ,NULL SERIAL_NUMBER
374 ,sum(base.primary_quantity) 
375 ,sum(base.secondary_quantity) 
376 ,base.grade_code 
377 ,NULL consist_string
378 ,mln.EXPIRATION_DATE||base.DATE_RECEIVED order_by_string
379  from MTL_LOT_NUMBERS mln
380 ,WMS_TRX_DETAILS_TMP_V mptdtv
381 ,(
382 SELECT x.organization_id       organization_id     
383   ,x.inventory_item_id         inventory_item_id   
384   ,x.revision                  revision            
385   ,x.lot_number                lot_number          
386   ,x.lot_expiration_date       lot_expiration_date 
387   ,x.subinventory_code         subinventory_code   
388   ,x.locator_id                locator_id          
389   ,x.cost_group_id             cost_group_id       
390   ,x.status_id                 status_id       
391   ,NULL                        serial_number       
392   ,x.lpn_id                    lpn_id              
393   ,x.project_id                project_id          
394   ,x.task_id                   task_id             
395   ,x.date_received             date_received       
396   ,x.primary_quantity          primary_quantity    
397   ,x.secondary_quantity          secondary_quantity    
398   ,x.grade_code                  grade_code            
399   ,x.reservable_type           reservable_type     
400   ,x.locreservable             locreservable 
401   ,x.lotreservable             lotreservable 
402   ,NVL(loc.pick_uom_code,sub.pick_uom_code) uom_code
403   ,WMS_Rule_PVT.GetConversionRate(                 
404        NVL(loc.pick_uom_code, sub.pick_uom_code)   
405        ,x.organization_id            
406        ,x.inventory_item_id) conversion_rate       
407   ,NULL locator_inventory_item_id                  
408   ,NULL empty_flag                                 
409   ,NULL location_current_units                     
410 FROM (
411    select  x.organization_id
412           ,x.inventory_item_id
413           ,x.revision
414           ,x.lot_number
415           ,lot.expiration_date lot_expiration_date
416           ,x.subinventory_code
417           ,sub.reservable_type
418 	  ,nvl(x.reservable_type,1)   locreservable                          -- Bug 6719290
419 	  ,nvl(lot.reservable_type,1) lotreservable                          -- Bug 6719290
420           ,x.locator_id
421           ,x.cost_group_id
422 	  ,x.status_id		--added status_id
423           ,x.date_received date_received
424           ,x.primary_quantity primary_quantity
425           ,x.secondary_quantity       secondary_quantity            -- new
426           ,lot.grade_code             grade_code                    -- new
427           ,x.lpn_id lpn_id
428           ,x.project_id project_id
432              moq.organization_id
429           ,x.task_id task_id
430      from
431           (SELECT
433             ,moq.inventory_item_id
434             ,moq.revision
435             ,moq.lot_number
436             ,moq.subinventory_code
437             ,moq.locator_id
438             ,moq.cost_group_id
439 	    ,moq.status_id		--added status_id
440 	    ,mils.reservable_type                                  -- Bug 6719290
441             ,min(NVL(moq.orig_date_received,
442                  moq.date_received)) date_received
443             ,sum(moq.primary_transaction_quantity) primary_quantity
444             ,sum(moq.secondary_transaction_quantity) secondary_quantity   -- new
445             ,moq.lpn_id lpn_id
446             ,decode(mils.project_id, mils.project_id, moq.project_id) project_id
447             ,decode(mils.task_id, mils.task_id, moq.task_id) task_id
448           FROM
449             mtl_onhand_quantities_detail moq,mtl_item_locations mils
450           WHERE
451                moq.organization_id = g_organization_id
452            AND moq.inventory_item_id = g_inventory_item_id
453            AND moq.organization_id = mils.organization_id (+)
454            AND moq.subinventory_code = mils.subinventory_code (+)
455            AND moq.locator_id = mils.inventory_location_id (+)
456           GROUP BY
457                moq.organization_id, moq.inventory_item_id
458               ,moq.revision, moq.lot_number
459               ,moq.subinventory_code, moq.locator_id		--added status_id
460               ,moq.cost_group_id,moq.status_id, mils.reservable_type, moq.lpn_id         -- Bug 6719290
461               ,decode(mils.project_id, mils.project_id, moq.project_id)
462               ,decode(mils.task_id, mils.task_id, moq.task_id)
463           ) x
464           ,mtl_secondary_inventories sub
465           ,mtl_lot_numbers lot
466     where x.primary_quantity > 0
467       and x.organization_id = sub.organization_id
468       and x.subinventory_code = sub.secondary_inventory_name
469       and x.organization_id = lot.organization_id (+)
470       and x.inventory_item_id = lot.inventory_item_id (+)
471       and x.lot_number = lot.lot_number (+)
472      ) x                                           
473     ,mtl_secondary_inventories sub                 
474     ,mtl_item_locations loc                        
475 WHERE x.organization_id = loc.organization_id (+)  
476    AND x.locator_id = loc.inventory_location_id (+)
477    AND sub.organization_id = x.organization_id     
478    AND sub.secondary_inventory_name = x.subinventory_code 
479 ) base
480  where base.ORGANIZATION_ID = g_organization_id
481 and base.INVENTORY_ITEM_ID = g_inventory_item_id
482  and decode(g_subinventory_code, '-9999', 'a', base.SUBINVENTORY_CODE) = decode(g_subinventory_code, '-9999', 'a', g_subinventory_code)
483  and  ((exists (select 1 from mtl_parameters where organization_id = g_organization_id and default_status_id is not null )  AND exists(select 1 from mtl_material_statuses where status_id = base.STATUS_ID AND RESERVABLE_TYPE = 1)) OR (NOT exists(select 1 from mtl_parameters where organization_id = g_organization_id and default_status_id is not NULL)  and decode(g_subinventory_code, '-9999', base.RESERVABLE_TYPE, 1) = 1))
484  and decode(g_locator_id, -9999, 1, base.locator_id) = decode(g_locator_id,-9999, 1, g_locator_id)
485  and decode(g_revision, '-99', 'a', base.REVISION) = decode(g_revision, '-99', 'a', g_revision)
486  and decode(g_lot_number, '-9999', 'a', base.LOT_NUMBER) = decode(g_lot_number, '-9999', 'a', g_lot_number)
487  and decode(g_lpn_id, -9999, 1, base.lpn_id) = decode(g_lpn_id, -9999, 1, g_lpn_id)
488  and decode(g_cost_group_id, -9999, 1, base.cost_group_id) = decode(g_cost_group_id, -9999, 1, g_cost_group_id)
489  and (decode(g_project_id, -9999, -1, base.project_id) = decode(g_project_id, -9999, -1, g_project_id) OR ( g_project_id = -7777  and base.project_id IS NULL)) 
490  and (g_project_id = -9999 OR nvl(base.task_id, -9999) = g_task_id OR (g_task_id = -7777 and base.task_id IS NULL))
491  and mptdtv.PP_TRANSACTION_TEMP_ID = g_pp_transaction_temp_id
492 and mln.ORGANIZATION_ID (+) = base.ORGANIZATION_ID
493 and mln.INVENTORY_ITEM_ID (+) = base.INVENTORY_ITEM_ID
494 and mln.LOT_NUMBER (+) = base.LOT_NUMBER
495 group by base.ORGANIZATION_ID
496 ,base.INVENTORY_ITEM_ID
497 ,base.REVISION
498 ,base.LOT_NUMBER
499 ,base.LOT_EXPIRATION_DATE
500 ,base.SUBINVENTORY_CODE
501 ,base.LOCATOR_ID
502 ,base.COST_GROUP_ID
503 ,base.PROJECT_ID
504 ,base.TASK_ID
505 ,base.UOM_CODE
506 ,base.GRADE_CODE
507 ,mln.EXPIRATION_DATE,base.DATE_RECEIVED,base.CONVERSION_RATE
508 ,mln.EXPIRATION_DATE||base.DATE_RECEIVED
509  order by mln.EXPIRATION_DATE asc
510 ,base.DATE_RECEIVED asc
511 ,base.CONVERSION_RATE desc
512 ;
513      END IF;
514 
515     x_result :=1;
516 
517    END open_curs;
518 
519    PROCEDURE fetch_one_row(
520                         p_cursor   IN WMS_RULE_PVT.cv_pick_type,
521                         x_revision OUT NOCOPY VARCHAR2,
522                         x_lot_number OUT NOCOPY VARCHAR2,
523                         x_lot_expiration_date OUT NOCOPY DATE,
524                         x_subinventory_code OUT NOCOPY VARCHAR2,
525                         x_locator_id OUT NOCOPY NUMBER,
526                         x_cost_group_id OUT NOCOPY NUMBER,
527                         x_uom_code OUT NOCOPY VARCHAR2,
528                         x_lpn_id OUT NOCOPY NUMBER,
529                         x_serial_number OUT NOCOPY VARCHAR2,
530                         x_possible_quantity OUT NOCOPY NUMBER,
531                         x_sec_possible_quantity  OUT NOCOPY NUMBER,
532                         x_grade_code             OUT NOCOPY VARCHAR2,
533                         x_consist_string  OUT NOCOPY VARCHAR2,
534                         x_order_by_string OUT NOCOPY VARCHAR2,
535                         x_return_status OUT NOCOPY NUMBER) IS
536 
537 
538    BEGIN
539            IF (p_cursor%ISOPEN) THEN
540 
541                FETCH p_cursor INTO
542                x_revision
543                , x_lot_number
544                , x_lot_expiration_date
545                , x_subinventory_code
546                , x_locator_id
547                , x_cost_group_id
548                , x_uom_code
549                , x_lpn_id
550                , x_serial_number
551                , x_possible_quantity
552                , x_sec_possible_quantity
553                , x_grade_code
554                , x_consist_string
555                , x_order_by_string;
556                IF p_cursor%FOUND THEN
557                   x_return_status :=1;
558                ELSE
559                   x_return_status :=0;
560                END IF;
561             ELSE
562                x_return_status:=0;
563             END IF;
564 
565 
566    END fetch_one_row;
567 
568    PROCEDURE close_curs( p_cursor IN WMS_RULE_PVT.cv_pick_type) IS
569    BEGIN
570         if (p_cursor%ISOPEN) THEN
571             CLOSE p_cursor;
572         END IF;
573    END close_curs;
574 
575    -- LG convergence new procedure for the new manual picking select screen
576    PROCEDURE fetch_available_rows(
577       p_cursor   IN WMS_RULE_PVT.cv_pick_type,
578       x_return_status OUT NOCOPY NUMBER) IS
579 
580 
581    BEGIN
582            IF (p_cursor%ISOPEN) THEN
583 
584                FETCH p_cursor bulk collect INTO
585                  WMS_SEARCH_ORDER_GLOBALS_PVT.g_available_inv_tbl;
586                IF p_cursor%FOUND THEN
587                   x_return_status :=1;
588                ELSE
589                   x_return_status :=0;
590                END IF;
591             ELSE
592                x_return_status:=0;
593             END IF;
594 
595 
596    END fetch_available_rows;
597 
598    -- end LG convergence
599 
600    END WMS_RULE_1;