DBA Data[Home] [Help]

PACKAGE BODY: APPS.WMS_RULE_16

Source


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