DBA Data[Home] [Help]
Skip to content

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 				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 ,mln.EXPIRATION_DATE||base.DATE_RECEIVED order_by_string
82  from MTL_LOT_NUMBERS mln
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)
148  and mptdtv.PP_TRANSACTION_TEMP_ID = g_pp_transaction_temp_id
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)
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 mln.ORGANIZATION_ID (+) = base.ORGANIZATION_ID
151 and mln.INVENTORY_ITEM_ID (+) = base.INVENTORY_ITEM_ID
152 and mln.LOT_NUMBER (+) = base.LOT_NUMBER
153  and mlna.ORGANIZATION_ID (+) = base.ORGANIZATION_ID 
154  and mlna.INVENTORY_ITEM_ID (+) = base.INVENTORY_ITEM_ID 
155  and mlna.LOT_NUMBER (+) = base.LOT_NUMBER 
156  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,mln.EXPIRATION_DATE asc
157 ,base.DATE_RECEIVED asc
158 ,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 ,mln.EXPIRATION_DATE||base.DATE_RECEIVED order_by_string
175  from MTL_LOT_NUMBERS mln
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 mln.ORGANIZATION_ID (+) = base.ORGANIZATION_ID
247 and mln.INVENTORY_ITEM_ID (+) = base.INVENTORY_ITEM_ID
248 and mln.LOT_NUMBER (+) = base.LOT_NUMBER
249  and mlna.ORGANIZATION_ID (+) = base.ORGANIZATION_ID 
250  and mlna.INVENTORY_ITEM_ID (+) = base.INVENTORY_ITEM_ID 
251  and mlna.LOT_NUMBER (+) = base.LOT_NUMBER 
252  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
253 ,base.INVENTORY_ITEM_ID
254 ,base.REVISION
255 ,base.LOT_NUMBER
256 ,base.LOT_EXPIRATION_DATE
257 ,base.SUBINVENTORY_CODE
258 ,base.LOCATOR_ID
259 ,base.COST_GROUP_ID
260 ,base.PROJECT_ID
261 ,base.TASK_ID
262 ,base.UOM_CODE
263 ,base.GRADE_CODE
264 ,mln.EXPIRATION_DATE,base.DATE_RECEIVED,base.SERIAL_NUMBER,base.CONVERSION_RATE
265 ,mln.EXPIRATION_DATE||base.DATE_RECEIVED
266  order by decode(base.project_id,g_project_id,1,NULL,2,3) asc,mln.EXPIRATION_DATE asc
267 ,base.DATE_RECEIVED asc
268 ,base.SERIAL_NUMBER asc,base.CONVERSION_RATE desc
269 ;
270      Elsif (g_serial_control = 1) AND  (g_detail_serial = 4) THEN
271            OPEN p_cursor FOR select base.REVISION
272 ,base.LOT_NUMBER
273 ,base.LOT_EXPIRATION_DATE
274 ,base.SUBINVENTORY_CODE
275 ,base.LOCATOR_ID
276 ,base.COST_GROUP_ID
277 ,base.UOM_CODE
278 ,decode(g_lpn_id, -9999, NULL, g_lpn_id) LPN_ID
279 ,NULL SERIAL_NUMBER
280 ,sum(base.primary_quantity) 
281 ,sum(base.secondary_quantity) 
282 ,base.grade_code 
283 ,NULL consist_string
284 ,mln.EXPIRATION_DATE||base.DATE_RECEIVED order_by_string
285  from MTL_LOT_NUMBERS mln
286 ,
287  MTL_LOT_NUMBERS mlna , 
288 WMS_TRX_DETAILS_TMP_V mptdtv
289 ,(
290          select  msn.current_organization_id organization_id
291           ,msn.inventory_item_id
292           ,msn.revision
293           ,msn.lot_number
294           ,lot.expiration_date lot_expiration_date
295           ,msn.current_subinventory_code subinventory_code
296           ,msn.current_locator_id locator_id
297           ,msn.cost_group_id
298 	   ,msn.status_id   --added status_id
299           ,msn.serial_number
300           ,msn.initialization_date date_received
301           ,1 primary_quantity
302           ,null secondary_quantity                            -- new
303           ,lot.grade_code grade_code                          -- new
304           ,sub.reservable_type
305           ,nvl(loc.reservable_type,1)  locreservable          -- Bug 6719290
306           ,nvl(lot.reservable_type,1)  lotreservable          -- Bug 6719290
307           ,nvl(loc.pick_uom_code, sub.pick_uom_code) uom_code
308           ,WMS_Rule_PVT.GetConversionRate(
309                nvl(loc.pick_uom_code, sub.pick_uom_code)
310               ,msn.current_organization_id
311               ,msn.inventory_item_id) conversion_rate
312           ,msn.lpn_id lpn_id
313           ,loc.project_id project_id
314           ,loc.task_id task_id
315                 ,NULL locator_inventory_item_id
316                 ,NULL empty_flag
317                 ,NULL location_current_units
318            from  mtl_serial_numbers msn
319           ,mtl_secondary_inventories sub
320           ,mtl_item_locations loc
321           ,mtl_lot_numbers lot
322           where msn.current_status = 3
323             and decode(g_unit_number, '-9999', 'a', '-7777', nvl(msn.end_item_unit_number, '-7777'), msn.end_item_unit_number) =
324             decode(g_unit_number, '-9999', 'a', g_unit_number)
325             and (msn.group_mark_id IS NULL or msn.group_mark_id = -1)
326             and (g_detail_serial = 4
327                 OR(g_detail_any_serial = 1
328              OR (g_from_serial_number <= msn.serial_number
329                 AND lengthb(g_from_serial_number) = lengthb(msn.serial_number)
330                 AND g_to_serial_number >=  msn.serial_number
331                       AND lengthb(g_to_serial_number) = lengthb(msn.serial_number)
332                 )))
333             and sub.organization_id = msn.current_organization_id
334             and sub.secondary_inventory_name = msn.current_subinventory_code
335             and loc.organization_id (+)= msn.current_organization_id
336             and loc.inventory_location_id (+)= msn.current_locator_id
337             and lot.organization_id (+)= msn.current_organization_id
338             and lot.inventory_Item_id (+)= msn.inventory_item_id
339             and lot.lot_number (+)= msn.lot_number
340              )base
341  where base.ORGANIZATION_ID = g_organization_id
342 and base.INVENTORY_ITEM_ID = g_inventory_item_id
343  and decode(g_subinventory_code, '-9999', 'a', base.SUBINVENTORY_CODE) = decode(g_subinventory_code, '-9999', 'a', g_subinventory_code)
344  and decode(g_subinventory_code, '-9999', base.RESERVABLE_TYPE, 1) = 1
345  and decode(g_locator_id, -9999, 1, base.locator_id) = decode(g_locator_id,-9999, 1, g_locator_id)
346  and decode(g_revision, '-99', 'a', base.REVISION) = decode(g_revision, '-99', 'a', g_revision)
347  and decode(g_lot_number, '-9999', 'a', base.LOT_NUMBER) = decode(g_lot_number, '-9999', 'a', g_lot_number)
348  and decode(g_lpn_id, -9999, 1, base.lpn_id) = decode(g_lpn_id, -9999, 1, g_lpn_id)
349  and decode(g_cost_group_id, -9999, 1, base.cost_group_id) = decode(g_cost_group_id, -9999, 1, g_cost_group_id)
350  and mptdtv.PP_TRANSACTION_TEMP_ID = g_pp_transaction_temp_id
351  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
352 and mln.ORGANIZATION_ID (+) = base.ORGANIZATION_ID
353 and mln.INVENTORY_ITEM_ID (+) = base.INVENTORY_ITEM_ID
354 and mln.LOT_NUMBER (+) = base.LOT_NUMBER
355  and mlna.ORGANIZATION_ID (+) = base.ORGANIZATION_ID 
356  and mlna.INVENTORY_ITEM_ID (+) = base.INVENTORY_ITEM_ID 
357  and mlna.LOT_NUMBER (+) = base.LOT_NUMBER 
358  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
359 ,base.INVENTORY_ITEM_ID
360 ,base.REVISION
361 ,base.LOT_NUMBER
362 ,base.LOT_EXPIRATION_DATE
363 ,base.SUBINVENTORY_CODE
364 ,base.LOCATOR_ID
365 ,base.COST_GROUP_ID
366 ,base.PROJECT_ID
367 ,base.TASK_ID
368 ,base.UOM_CODE
369 ,base.GRADE_CODE
370 ,mln.EXPIRATION_DATE,base.DATE_RECEIVED,base.SERIAL_NUMBER,base.CONVERSION_RATE
371 ,mln.EXPIRATION_DATE||base.DATE_RECEIVED
372  order by decode(base.project_id,g_project_id,1,NULL,2,3) asc,mln.EXPIRATION_DATE asc
373 ,base.DATE_RECEIVED asc
374 ,base.SERIAL_NUMBER asc,base.CONVERSION_RATE desc
375 ;
376 
377      Elsif ((g_serial_control <> 1) OR (g_detail_serial = 0)) THEN
378        OPEN p_cursor FOR select base.REVISION
379 ,base.LOT_NUMBER
380 ,base.LOT_EXPIRATION_DATE
381 ,base.SUBINVENTORY_CODE
382 ,base.LOCATOR_ID
383 ,base.COST_GROUP_ID
384 ,base.UOM_CODE
385 ,decode(g_lpn_id, -9999, NULL, g_lpn_id) LPN_ID
386 ,NULL SERIAL_NUMBER
387 ,sum(base.primary_quantity) 
388 ,sum(base.secondary_quantity) 
389 ,base.grade_code 
390 ,NULL consist_string
391 ,mln.EXPIRATION_DATE||base.DATE_RECEIVED order_by_string
392  from MTL_LOT_NUMBERS mln
393 ,
394  MTL_LOT_NUMBERS mlna , 
395 WMS_TRX_DETAILS_TMP_V mptdtv
396 ,(
397 SELECT x.organization_id       organization_id     
398   ,x.inventory_item_id         inventory_item_id   
399   ,x.revision                  revision            
400   ,x.lot_number                lot_number          
401   ,x.lot_expiration_date       lot_expiration_date 
402   ,x.subinventory_code         subinventory_code   
403   ,x.locator_id                locator_id          
404   ,x.cost_group_id             cost_group_id       
405   ,x.status_id                 status_id       
406   ,NULL                        serial_number       
407   ,x.lpn_id                    lpn_id              
408   ,x.project_id                project_id          
409   ,x.task_id                   task_id             
410   ,x.date_received             date_received       
411   ,x.primary_quantity          primary_quantity    
412   ,x.secondary_quantity          secondary_quantity    
413   ,x.grade_code                  grade_code            
414   ,x.reservable_type           reservable_type     
415   ,x.locreservable             locreservable 
416   ,x.lotreservable             lotreservable 
417   ,NVL(loc.pick_uom_code,sub.pick_uom_code) uom_code
418   ,WMS_Rule_PVT.GetConversionRate(                 
419        NVL(loc.pick_uom_code, sub.pick_uom_code)   
420        ,x.organization_id            
421        ,x.inventory_item_id) conversion_rate       
422   ,NULL locator_inventory_item_id                  
423   ,NULL empty_flag                                 
424   ,NULL location_current_units                     
425 FROM (
426    select  x.organization_id
427           ,x.inventory_item_id
428           ,x.revision
429           ,x.lot_number
430           ,lot.expiration_date lot_expiration_date
431           ,x.subinventory_code
432           ,sub.reservable_type
433 	  ,nvl(x.reservable_type,1)   locreservable                          -- Bug 6719290
434 	  ,nvl(lot.reservable_type,1) lotreservable                          -- Bug 6719290
435           ,x.locator_id
436           ,x.cost_group_id
437 	  ,x.status_id		--added status_id
438           ,x.date_received date_received
439           ,x.primary_quantity primary_quantity
440           ,x.secondary_quantity       secondary_quantity            -- new
441           ,lot.grade_code             grade_code                    -- new
442           ,x.lpn_id lpn_id
443           ,x.project_id project_id
444           ,x.task_id task_id
445      from
446           (SELECT
447              moq.organization_id
448             ,moq.inventory_item_id
449             ,moq.revision
450             ,moq.lot_number
451             ,moq.subinventory_code
452             ,moq.locator_id
453             ,moq.cost_group_id
454 	    ,moq.status_id		--added status_id
455 	    ,mils.reservable_type                                  -- Bug 6719290
456             ,min(NVL(moq.orig_date_received,
457                  moq.date_received)) date_received
458             ,sum(moq.primary_transaction_quantity) primary_quantity
459             ,sum(moq.secondary_transaction_quantity) secondary_quantity   -- new
460             ,moq.lpn_id lpn_id
461             ,decode(mils.project_id, mils.project_id, moq.project_id) project_id
462             ,decode(mils.task_id, mils.task_id, moq.task_id) task_id
463           FROM
464             mtl_onhand_quantities_detail moq,mtl_item_locations mils
465           WHERE
466                moq.organization_id = g_organization_id
467            AND moq.inventory_item_id = g_inventory_item_id
468            AND moq.organization_id = mils.organization_id (+)
469            AND moq.subinventory_code = mils.subinventory_code (+)
470            AND moq.locator_id = mils.inventory_location_id (+)
471           GROUP BY
472                moq.organization_id, moq.inventory_item_id
473 	      ,moq.date_received --bug 6648984
474               ,moq.revision, moq.lot_number
475               ,moq.subinventory_code, moq.locator_id		--added status_id
476               ,moq.cost_group_id,moq.status_id, mils.reservable_type, moq.lpn_id         -- Bug 6719290
477               ,decode(mils.project_id, mils.project_id, moq.project_id)
478               ,decode(mils.task_id, mils.task_id, moq.task_id)
479 	  HAVING
480 	       sum(moq.primary_transaction_quantity) > 0 -- high volume project 8546026
481           ) x
482           ,mtl_secondary_inventories sub
483           ,mtl_lot_numbers lot
484     where
485 --    x.primary_quantity > 0 and   -- high volume project 8546026
486           x.organization_id = sub.organization_id
487       and x.subinventory_code = sub.secondary_inventory_name
488       and x.organization_id = lot.organization_id (+)
489       and x.inventory_item_id = lot.inventory_item_id (+)
490       and x.lot_number = lot.lot_number (+)
491      ) x                                           
492     ,mtl_secondary_inventories sub                 
493     ,mtl_item_locations loc                        
494 WHERE x.organization_id = loc.organization_id (+)  
495    AND x.locator_id = loc.inventory_location_id (+)
496    AND sub.organization_id = x.organization_id     
497    AND sub.secondary_inventory_name = x.subinventory_code 
498 ) base
499  where base.ORGANIZATION_ID = g_organization_id
500 and base.INVENTORY_ITEM_ID = g_inventory_item_id
501  and decode(g_subinventory_code, '-9999', 'a', base.SUBINVENTORY_CODE) = decode(g_subinventory_code, '-9999', 'a', g_subinventory_code)
502  and decode(g_subinventory_code, '-9999', base.RESERVABLE_TYPE, 1) = 1
503  and decode(g_locator_id, -9999, 1, base.locator_id) = decode(g_locator_id,-9999, 1, g_locator_id)
504  and decode(g_revision, '-99', 'a', base.REVISION) = decode(g_revision, '-99', 'a', g_revision)
505  and decode(g_lot_number, '-9999', 'a', base.LOT_NUMBER) = decode(g_lot_number, '-9999', 'a', g_lot_number)
506  and decode(g_lpn_id, -9999, 1, base.lpn_id) = decode(g_lpn_id, -9999, 1, g_lpn_id)
507  and decode(g_cost_group_id, -9999, 1, base.cost_group_id) = decode(g_cost_group_id, -9999, 1, g_cost_group_id)
508  and mptdtv.PP_TRANSACTION_TEMP_ID = g_pp_transaction_temp_id
509  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
510 and mln.ORGANIZATION_ID (+) = base.ORGANIZATION_ID
511 and mln.INVENTORY_ITEM_ID (+) = base.INVENTORY_ITEM_ID
512 and mln.LOT_NUMBER (+) = base.LOT_NUMBER
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 ,mln.EXPIRATION_DATE,base.DATE_RECEIVED,base.SERIAL_NUMBER,base.CONVERSION_RATE
529 ,mln.EXPIRATION_DATE||base.DATE_RECEIVED
530  order by decode(base.project_id,g_project_id,1,NULL,2,3) asc,mln.EXPIRATION_DATE asc
531 ,base.DATE_RECEIVED asc
532 ,base.SERIAL_NUMBER asc,base.CONVERSION_RATE desc
533 ;
534      END IF;
535 
536     x_result :=1;
537 
538    END open_curs;
539 
540    PROCEDURE fetch_one_row(
541                         p_cursor   IN WMS_RULE_PVT.cv_pick_type,
542                         x_revision OUT NOCOPY VARCHAR2,
543                         x_lot_number OUT NOCOPY VARCHAR2,
544                         x_lot_expiration_date OUT NOCOPY DATE,
545                         x_subinventory_code OUT NOCOPY VARCHAR2,
546                         x_locator_id OUT NOCOPY NUMBER,
547                         x_cost_group_id OUT NOCOPY NUMBER,
548                         x_uom_code OUT NOCOPY VARCHAR2,
549                         x_lpn_id OUT NOCOPY NUMBER,
550                         x_serial_number OUT NOCOPY VARCHAR2,
551                         x_possible_quantity OUT NOCOPY NUMBER,
552                         x_sec_possible_quantity  OUT NOCOPY NUMBER,
553                         x_grade_code             OUT NOCOPY VARCHAR2,
554                         x_consist_string  OUT NOCOPY VARCHAR2,
555                         x_order_by_string OUT NOCOPY VARCHAR2,
556                         x_return_status OUT NOCOPY NUMBER) IS
557 
558 
559    BEGIN
560            IF (p_cursor%ISOPEN) THEN
561 
562                FETCH p_cursor INTO
563                x_revision
564                , x_lot_number
565                , x_lot_expiration_date
566                , x_subinventory_code
567                , x_locator_id
568                , x_cost_group_id
569                , x_uom_code
570                , x_lpn_id
571                , x_serial_number
572                , x_possible_quantity
573                , x_sec_possible_quantity
574                , x_grade_code
575                , x_consist_string
576                , x_order_by_string;
577                IF p_cursor%FOUND THEN
578                   x_return_status :=1;
579                ELSE
580                   x_return_status :=0;
581                END IF;
582             ELSE
583                x_return_status:=0;
584             END IF;
585 
586 
587    END fetch_one_row;
588 
589    PROCEDURE close_curs( p_cursor IN WMS_RULE_PVT.cv_pick_type) IS
590    BEGIN
591         if (p_cursor%ISOPEN) THEN
592             CLOSE p_cursor;
593         END IF;
594    END close_curs;
595 
596    -- LG convergence new procedure for the new manual picking select screen
597    PROCEDURE fetch_available_rows(
598       p_cursor   IN WMS_RULE_PVT.cv_pick_type,
599       x_return_status OUT NOCOPY NUMBER) IS
600 
601     /* Fix for Bug#8360804 . Added temp variable of type available_inventory_tbl */
602 
603      l_available_inv_tbl WMS_SEARCH_ORDER_GLOBALS_PVT.available_inventory_tbl;
604      l_count number ;
605 
606 
607    BEGIN
608            IF (p_cursor%ISOPEN) THEN
609 
610               /* Fix for bug#8360804. Collect into temp variable and then add it to g_available_inv_tbl */
611 
612                FETCH p_cursor bulk collect INTO l_available_inv_tbl;
613 
614                IF p_cursor%FOUND THEN
615                   x_return_status :=1;
616                ELSE
617                   x_return_status :=0;
618                END IF;
619 
620                IF (WMS_SEARCH_ORDER_GLOBALS_PVT.g_available_inv_tbl.exists(1)) THEN
621 
622                   l_count := WMS_SEARCH_ORDER_GLOBALS_PVT.g_available_inv_tbl.LAST ;
623 
624                   FOR i in l_available_inv_tbl.FIRST..l_available_inv_tbl.LAST LOOP
625                     l_count := l_count + 1 ;
626                     WMS_SEARCH_ORDER_GLOBALS_PVT.g_available_inv_tbl(l_count) := l_available_inv_tbl(i) ;
627                   END LOOP ;
628 
629                ELSE
630                    WMS_SEARCH_ORDER_GLOBALS_PVT.g_available_inv_tbl := l_available_inv_tbl ;
631                END IF ;
632             ELSE
633                x_return_status:=0;
634             END IF;
635 
636 
637    END fetch_available_rows;
638 
639    -- end LG convergence
640 
641    END WMS_RULE_1;