DBA Data[Home] [Help]

PACKAGE BODY: APPS.WMS_RULE_18

Source


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