[Home] [Help]
PACKAGE BODY: APPS.WMS_CONTAINER_PVT
Source
1 PACKAGE BODY WMS_CONTAINER_PVT AS
2 /* $Header: WMSVCNTB.pls 120.79.12020000.13 2013/04/29 05:10:40 ssrikaku ship $ */
3
4 -- Global constant holding the package name
5 g_pkg_name CONSTANT VARCHAR2(30) := 'WMS_CONTAINER_PVT';
6 g_pkg_version CONSTANT VARCHAR2(100) := '$Header: WMSVCNTB.pls 120.79.12020000.13 2013/04/29 05:10:40 ssrikaku ship $';
7
8 -- Various debug levels
9 G_ERROR CONSTANT NUMBER := 1;
10 G_INFO CONSTANT NUMBER := 5;
11 G_MESSAGE CONSTANT NUMBER := 9;
12
13 G_NULL_NUM CONSTANT NUMBER := -9;
14 G_NULL_CHAR CONSTANT VARCHAR2(1) := '@';
15 G_PRECISION CONSTANT NUMBER := 5;
16
17 -- package level debug variable
18 g_progress VARCHAR(500) := 'none';
19 g_lock_handle VARCHAR2(128) :=''; -- 16284527
20
21 -- Types used by Convert_UOM
22 TYPE to_uom_code_tb IS TABLE OF NUMBER INDEX BY VARCHAR2(3);
23 TYPE from_uom_code_tb IS TABLE OF to_uom_code_tb INDEX BY VARCHAR2(3);
24 TYPE item_uom_conversion_tb IS TABLE OF from_uom_code_tb INDEX BY BINARY_INTEGER;
25 g_item_uom_conversion_tb item_uom_conversion_tb;
26 g_item_uom_conversion_tb_cnt NUMBER := 0;
27
28 g_client_rec inv_cache.ct_rec_type; -- Added For LSP Project, bug 9087971
29
30 PROCEDURE mdebug(msg IN VARCHAR2, LEVEL NUMBER := G_MESSAGE) IS
31 BEGIN
32 --DBMS_OUTPUT.put_line(msg);
33 INV_TRX_UTIL_PUB.TRACE(msg, g_pkg_name, LEVEL);
34 END;
35
36 FUNCTION Convert_UOM (
37 p_inventory_item_id IN NUMBER
38 , p_fm_quantity IN NUMBER
39 , p_fm_uom IN VARCHAR2
40 , p_to_uom IN VARCHAR2
41 , p_mode IN VARCHAR2 := null
42 ) RETURN NUMBER
43 IS
44 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
45
46 l_conversion_rate NUMBER;
47 l_inventory_item_id NUMBER;
48
49 BEGIN
50 g_progress := 'Entered Convert_UOM';
51
52 -- IF to_uom is the same as from_uom, Return from quantity
53 IF p_fm_uom = p_to_uom THEN
54 RETURN p_fm_quantity;
55 ELSE
56 --- Bug 5507188
57 --- l_inventory_item_id := NVL(l_inventory_item_id, 0);
58 l_inventory_item_id := NVL(p_inventory_item_id, 0);
59 --- End bug 5507188
60
61 -- Need to convert fm_qty
62 g_progress := 'First check whether the convesrion rate has been cached';
63 IF ( g_item_uom_conversion_tb.EXISTS(l_inventory_item_id) AND
64 g_item_uom_conversion_tb(l_inventory_item_id).EXISTS(p_fm_uom) AND
65 g_item_uom_conversion_tb(l_inventory_item_id)(p_fm_uom).EXISTS(p_to_uom) )
66 THEN
67 g_progress := 'Conversion rate is cached so just use the value';
68 RETURN p_fm_quantity * g_item_uom_conversion_tb(l_inventory_item_id)(p_fm_uom)(p_to_uom);
69 ELSE
70 -- conversion rate is not cached
71 g_progress := 'Call convert API and store the value';
72 inv_convert.inv_um_conversion (
73 from_unit => p_fm_uom
74 , to_unit => p_to_uom
75 , item_id => l_inventory_item_id
76 , uom_rate => l_conversion_rate );
77
78 IF ( l_conversion_rate > 0 ) THEN
79 g_progress := 'Store the conversion rate';
80 g_item_uom_conversion_tb(l_inventory_item_id)(p_fm_uom)(p_to_uom) := l_conversion_rate;
81 g_item_uom_conversion_tb(l_inventory_item_id)(p_to_uom)(p_fm_uom) := 1 / l_conversion_rate;
82 g_item_uom_conversion_tb_cnt := g_item_uom_conversion_tb_cnt + 1;
83
84 g_progress := 'Need to purge table after a certain number of records';
85 IF ( g_item_uom_conversion_tb_cnt > 1000 ) THEN
86 g_item_uom_conversion_tb.delete;
87 g_item_uom_conversion_tb_cnt := 0;
88 END IF;
89
90 RETURN p_fm_quantity * l_conversion_rate;
91 ELSE -- Can not convert
92 IF ( l_debug = 1 ) THEN
93 mdebug('No coversion rate between '||p_fm_uom||' and '||p_to_uom||' mode='||p_mode, G_ERROR);
94 END IF;
95 fnd_message.set_name('INV', 'INV_UOM_CONVERSION_ERROR');
96 fnd_message.set_token('uom1', p_fm_uom);
97 fnd_message.set_token('uom2', p_to_uom);
98 fnd_message.set_token('module', g_pkg_name);
99 fnd_msg_pub.ADD;
100
101 IF ( p_mode = G_NO_CONV_RETURN_NULL ) THEN
102 RETURN NULL;
103 ELSIF ( p_mode = G_NO_CONV_RETURN_ZERO ) THEN
104 RETURN 0;
105 ELSE -- Normal converstion error
106 fnd_msg_pub.ADD;
107 RAISE fnd_api.g_exc_error;
108 END IF;
109 END IF;
110 END IF; -- IF cache exists
111 END IF; -- IF p_fm_uom = p_to_uom
112 END Convert_UOM;
113
114 -- ----------------------------------------------------------------------------------
115 -- ----------------------------------------------------------------------------------
116
117 PROCEDURE Get_Update_LPN_Start_Num (
118 p_org_id IN NUMBER
119 , p_qty IN NUMBER
120 , x_curr_seq OUT NOCOPY NUMBER
121 ) IS PRAGMA AUTONOMOUS_TRANSACTION;
122 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
123 l_lpn_start_num NUMBER:=0;
124
125 BEGIN
126 --Creating an overloaded procedure so that the select of the
127 --starting number and the update happens with the same autonomous transaction
128 -- If the org default lpn starting number was used, we will need to update
129 -- that value so that the same number will not be used again the next time
130 -- Generate_LPN is called for that org
131
132 SELECT lpn_starting_number INTO l_lpn_start_num
133 FROM mtl_parameters
134 WHERE organization_id=p_org_id
135 FOR UPDATE;
136
137 UPDATE MTL_PARAMETERS
138 SET lpn_starting_number = l_lpn_start_num+p_qty,
139 last_update_date = SYSDATE,
140 last_updated_by = FND_GLOBAL.USER_ID
141 WHERE organization_id = p_org_id;
142
143 x_curr_seq:=l_lpn_start_num;
144
145 COMMIT;
146 END Get_Update_LPN_Start_Num;
147
148 -- ----------------------------------------------------------------------------------
149 -- ----------------------------------------------------------------------------------
150 -- 1 = Resides in Inventory
151 -- 2 = Resides in WIP
152 -- 3 = Resides in Receiving
153 -- 4 = Issued out of Stores
154 -- 5 = Pre-generated
155 -- 6 = Resides in intransit
156 -- 7 = Resides at vendor site
157 -- 8 = Packing context, used as a temporary context value
158 -- when the user wants to reassociate the LPN with a
159 -- different license plate number and/or container item ID
160 -- 9 = Loaded for shipment
161 -- 10 = Prepack of WIP
162 -- 11 = LPN Picked
163 -- 12 = Loaded in staging: Temporary context for staged (picked) LPNs
164
165 FUNCTION Valid_Context_Change (
166 p_caller VARCHAR
167 , p_old_context NUMBER
168 , p_new_context NUMBER
169 ) RETURN BOOLEAN IS
170
171 l_lookup_meaning MFG_LOOKUPS.MEANING%TYPE;
172
173 BEGIN
174 IF ( p_old_context = LPN_CONTEXT_INV ) THEN
175 IF ( p_new_context IN(1, 2, 3, 4, 5, 6, 8, 11) ) THEN
176 RETURN TRUE;
177 END IF;
178 ELSIF ( p_old_context = LPN_CONTEXT_WIP ) THEN
179 IF ( p_new_context IN(1, 2, 5, 11 ) ) THEN
180 RETURN TRUE;
181 END IF;
182 ELSIF ( p_old_context = LPN_CONTEXT_RCV ) THEN
183 IF ( p_new_context IN(1, 3, 4, 5, 11) ) THEN
184 RETURN TRUE;
185 END IF;
186 ELSIF ( p_old_context = LPN_CONTEXT_STORES ) THEN
187 IF ( p_new_context IN(4, 6) ) THEN
188 RETURN TRUE;
189 END IF;
190 ELSIF ( p_old_context = LPN_CONTEXT_PREGENERATED ) THEN
191 IF ( p_new_context IN(1, 2, 3, 4, 5, 6, 7, 8, 9, 11) ) THEN
192 RETURN TRUE;
193 END IF;
194 ELSIF ( p_old_context = LPN_CONTEXT_INTRANSIT ) THEN
195 IF ( p_new_context IN(1, 3, 5, 6, 11) ) THEN
196 RETURN TRUE;
197 END IF;
198 ELSIF ( p_old_context = LPN_CONTEXT_VENDOR ) THEN
199 IF ( p_new_context IN(1, 3, 5, 7) ) THEN
200 RETURN TRUE;
201 END IF;
202 ELSIF ( p_old_context = LPN_CONTEXT_PACKING ) THEN
203 IF ( p_new_context IN(1, 5, 8, 11) ) THEN
204 RETURN TRUE;
205 END IF;
206 ELSIF ( p_old_context = LPN_LOADED_FOR_SHIPMENT ) THEN
207 IF ( p_new_context IN(1, 4, 5, 6, 9, 11) ) THEN
208 RETURN TRUE;
209 END IF;
210 ELSIF ( p_old_context = LPN_PREPACK_FOR_WIP ) THEN
211 IF ( p_new_context IN(1, 2, 5, 10) ) THEN
212 RETURN TRUE;
213 END IF;
214 ELSIF ( p_old_context = LPN_CONTEXT_PICKED ) THEN
215 IF ( p_new_context IN(1, 4, 5, 6, 9, 11, 12) ) THEN
216 RETURN TRUE;
217 END IF;
218 ELSIF ( p_old_context = LPN_LOADED_IN_STAGE ) THEN
219 IF ( p_new_context IN(4, 5, 6, 11, 12) ) THEN --8454203 -- Added context 5 for Bug 10083600
220 RETURN TRUE;
221 END IF;
222 END IF;
223
224 -- If haven't returned true must be disallowed context change
225 -- return false and add error message
226 fnd_message.set_name('INV', 'WMS_CONTEXT_CHANGE_ERR');
227
228 SELECT meaning
229 INTO l_lookup_meaning
230 FROM mfg_lookups
231 WHERE lookup_type = 'WMS_LPN_CONTEXT'
232 AND lookup_code = p_old_context;
233 fnd_message.set_token('CONTEXT1', l_lookup_meaning);
234
235 SELECT meaning
236 INTO l_lookup_meaning
237 FROM mfg_lookups
238 WHERE lookup_type = 'WMS_LPN_CONTEXT'
239 AND lookup_code = p_new_context;
240 fnd_message.set_token('CONTEXT2', l_lookup_meaning);
241
242 fnd_msg_pub.ADD;
243 RAISE fnd_api.g_exc_error;
244 RETURN FALSE;
245 END Valid_Context_Change;
246
247 -- ----------------------------------------------------------------------------------
248 -- ----------------------------------------------------------------------------------
249
250 PROCEDURE To_LPNBulkRecType (
251 p_lpn_table IN WMS_Data_Type_Definitions_PUB.LPNTableType
252 , p_table_first IN NUMBER
253 , p_table_last IN NUMBER
254 , p_record_last IN NUMBER
255 , x_lpn_bulk_rec IN OUT NOCOPY LPNBulkRecType
256 ) IS
257 l_table_first NUMBER;
258 l_table_last NUMBER;
259 l_rec_last NUMBER;
260
261 BEGIN
262 IF ( p_lpn_table.first IS NOT NULL ) THEN
263 l_table_first := NVL(p_table_first, p_lpn_table.first);
264 l_table_last := NVL(p_table_last, p_lpn_table.last);
265 l_rec_last := NVL(p_record_last, NVL(x_lpn_bulk_rec.lpn_id.last, p_lpn_table.first - 1));
266
267 FOR i IN l_table_first .. l_table_last LOOP
268 l_rec_last := l_rec_last + 1;
269
270 x_lpn_bulk_rec.lpn_id(l_rec_last) := p_lpn_table(i).lpn_id;
271 x_lpn_bulk_rec.license_plate_number(l_rec_last) := p_lpn_table(i).license_plate_number;
272 x_lpn_bulk_rec.parent_lpn_id(l_rec_last) := p_lpn_table(i).parent_lpn_id;
273 x_lpn_bulk_rec.outermost_lpn_id(l_rec_last) := p_lpn_table(i).outermost_lpn_id;
274 x_lpn_bulk_rec.lpn_context(l_rec_last) := p_lpn_table(i).lpn_context;
275
276 x_lpn_bulk_rec.organization_id(l_rec_last) := p_lpn_table(i).organization_id;
277 x_lpn_bulk_rec.subinventory_code(l_rec_last) := p_lpn_table(i).subinventory_code;
278 x_lpn_bulk_rec.locator_id(l_rec_last) := p_lpn_table(i).locator_id;
279
280 x_lpn_bulk_rec.inventory_item_id(l_rec_last) := p_lpn_table(i).inventory_item_id;
281 x_lpn_bulk_rec.revision(l_rec_last) := p_lpn_table(i).revision;
282 x_lpn_bulk_rec.lot_number(l_rec_last) := p_lpn_table(i).lot_number;
283 x_lpn_bulk_rec.serial_number(l_rec_last) := p_lpn_table(i).serial_number;
284 x_lpn_bulk_rec.cost_group_id(l_rec_last) := p_lpn_table(i).cost_group_id;
285
286 x_lpn_bulk_rec.tare_weight_uom_code(l_rec_last) := p_lpn_table(i).tare_weight_uom_code;
287 x_lpn_bulk_rec.tare_weight(l_rec_last) := p_lpn_table(i).tare_weight;
288 x_lpn_bulk_rec.gross_weight_uom_code(l_rec_last) := p_lpn_table(i).gross_weight_uom_code;
289 x_lpn_bulk_rec.gross_weight(l_rec_last) := p_lpn_table(i).gross_weight;
290 x_lpn_bulk_rec.container_volume_uom(l_rec_last) := p_lpn_table(i).container_volume_uom;
291 x_lpn_bulk_rec.container_volume(l_rec_last) := p_lpn_table(i).container_volume;
292 x_lpn_bulk_rec.content_volume_uom_code(l_rec_last) := p_lpn_table(i).content_volume_uom_code;
293 x_lpn_bulk_rec.content_volume(l_rec_last) := p_lpn_table(i).content_volume;
294
295 x_lpn_bulk_rec.source_type_id(l_rec_last) := p_lpn_table(i).source_type_id;
296 x_lpn_bulk_rec.source_header_id(l_rec_last) := p_lpn_table(i).source_header_id;
297 x_lpn_bulk_rec.source_line_id(l_rec_last) := p_lpn_table(i).source_line_id;
298 x_lpn_bulk_rec.source_line_detail_id(l_rec_last) := p_lpn_table(i).source_line_detail_id;
299 x_lpn_bulk_rec.source_name(l_rec_last) := p_lpn_table(i).source_name;
300 x_lpn_bulk_rec.source_transaction_id(l_rec_last) := p_lpn_table(i).source_transaction_id;
301 x_lpn_bulk_rec.reference_id(l_rec_last) := p_lpn_table(i).reference_id;
302
303 x_lpn_bulk_rec.attribute_category(l_rec_last) := p_lpn_table(i).attribute_category;
304 x_lpn_bulk_rec.attribute1(l_rec_last) := p_lpn_table(i).attribute1;
305 x_lpn_bulk_rec.attribute2(l_rec_last) := p_lpn_table(i).attribute2;
306 x_lpn_bulk_rec.attribute3(l_rec_last) := p_lpn_table(i).attribute3;
307 x_lpn_bulk_rec.attribute4(l_rec_last) := p_lpn_table(i).attribute4;
308 x_lpn_bulk_rec.attribute5(l_rec_last) := p_lpn_table(i).attribute5;
309 x_lpn_bulk_rec.attribute6(l_rec_last) := p_lpn_table(i).attribute6;
310 x_lpn_bulk_rec.attribute7(l_rec_last) := p_lpn_table(i).attribute7;
311 x_lpn_bulk_rec.attribute8(l_rec_last) := p_lpn_table(i).attribute8;
312 x_lpn_bulk_rec.attribute9(l_rec_last) := p_lpn_table(i).attribute9;
313 x_lpn_bulk_rec.attribute10(l_rec_last) := p_lpn_table(i).attribute10;
314 x_lpn_bulk_rec.attribute11(l_rec_last) := p_lpn_table(i).attribute11;
315 x_lpn_bulk_rec.attribute12(l_rec_last) := p_lpn_table(i).attribute12;
316 x_lpn_bulk_rec.attribute13(l_rec_last) := p_lpn_table(i).attribute13;
317 x_lpn_bulk_rec.attribute14(l_rec_last) := p_lpn_table(i).attribute14;
318 x_lpn_bulk_rec.attribute15(l_rec_last) := p_lpn_table(i).attribute15;
319 END LOOP;
320 END IF;
321 END To_LPNBulkRecType;
322
323 -- ----------------------------------------------------------------------------------
324 -- ----------------------------------------------------------------------------------
325
326 FUNCTION To_LPNBulkRecType (
327 p_lpn_table IN WMS_Data_Type_Definitions_PUB.LPNTableType
328 )
329 RETURN LPNBulkRecType
330 IS
331 l_lpn_bulk_rec LPNBulkRecType;
332
333 BEGIN
334 To_LPNBulkRecType (
335 p_lpn_table => p_lpn_table
336 , p_table_first => null
337 , p_table_last => null
338 , p_record_last => null
339 , x_lpn_bulk_rec => l_lpn_bulk_rec );
340
341 RETURN l_lpn_bulk_rec;
342 END To_LPNBulkRecType;
343
344 FUNCTION To_DeliveryDetailsRecType (
345 p_lpn_record IN WMS_Data_Type_Definitions_PUB.LPNRecordType
346 )
347 RETURN WSH_Glbl_Var_Strct_GRP.Delivery_Details_Rec_Type IS
348
349 l_debug NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
350 l_wsh_dd_rec WSH_Glbl_Var_Strct_GRP.Delivery_Details_Rec_Type;
351
352 BEGIN
353
354 l_wsh_dd_rec.lpn_id := p_lpn_record.lpn_id;
355 l_wsh_dd_rec.container_name := p_lpn_record.license_plate_number;
356 l_wsh_dd_rec.inventory_item_id := p_lpn_record.inventory_item_id;
357
358 l_wsh_dd_rec.organization_id := p_lpn_record.organization_id;
359 l_wsh_dd_rec.subinventory := p_lpn_record.subinventory_code;
360 l_wsh_dd_rec.locator_id := p_lpn_record.locator_id;
361
362 l_wsh_dd_rec.gross_weight := p_lpn_record.gross_weight;
363 l_wsh_dd_rec.weight_uom_code := p_lpn_record.gross_weight_uom_code;
364
365 l_wsh_dd_rec.filled_volume := p_lpn_record.content_volume;
366 l_wsh_dd_rec.volume_uom_code := p_lpn_record.content_volume_uom_code;
367
368 -- Need to caclcuate this net_weight = gross_weight - tare_weight
369 IF ( NVL(p_lpn_record.tare_weight, 0) = 0 OR p_lpn_record.tare_weight_uom_code IS NULL ) THEN
370 l_wsh_dd_rec.net_weight := p_lpn_record.gross_weight;
371 ELSIF ( NVL(p_lpn_record.gross_weight, 0) = 0 OR p_lpn_record.gross_weight_uom_code IS NULL ) THEN
372 l_wsh_dd_rec.net_weight := 0;
373 l_wsh_dd_rec.weight_uom_code := p_lpn_record.tare_weight_uom_code;
374 ELSIF ( p_lpn_record.tare_weight_uom_code = p_lpn_record.gross_weight_uom_code ) THEN
375 l_wsh_dd_rec.net_weight := p_lpn_record.gross_weight - p_lpn_record.tare_weight;
376 ELSE -- Both are not null but with different UOMs need to convert
377 l_wsh_dd_rec.net_weight := Convert_UOM(p_lpn_record.inventory_item_id, p_lpn_record.tare_weight, p_lpn_record.tare_weight_uom_code, p_lpn_record.gross_weight_uom_code);
378 l_wsh_dd_rec.net_weight := p_lpn_record.gross_weight - l_wsh_dd_rec.net_weight;
379 END IF;
380
381 IF ( l_wsh_dd_rec.net_weight < 0 ) THEN
382 l_wsh_dd_rec.net_weight := 0;
383 END IF;
384
385 -- Need to convert container volume into the content volume uom for shipping
386 IF ( NVL(p_lpn_record.container_volume, -1) <= 0 OR p_lpn_record.container_volume_uom IS NULL ) THEN
387 --l_wsh_dd_rec.volume := NULL; --16013313
388 --IF p_lpn_record.inventory_item_id is null THEN --10138886 (condition is not required here, because there is an outer if) --16013313
389 l_wsh_dd_rec.volume := p_lpn_record.content_volume;
390 -- END IF; --16013313
391 ELSIF ( p_lpn_record.container_volume_uom = NVL(p_lpn_record.content_volume_uom_code, p_lpn_record.container_volume_uom) ) THEN
392 l_wsh_dd_rec.volume := p_lpn_record.container_volume;
393 l_wsh_dd_rec.volume_uom_code := p_lpn_record.container_volume_uom;
394 ELSE
395 l_wsh_dd_rec.volume := Convert_UOM(p_lpn_record.inventory_item_id, p_lpn_record.container_volume, p_lpn_record.container_volume_uom, p_lpn_record.content_volume_uom_code);
396 END IF;
397
398 IF ( l_debug = 1 ) THEN
399 mdebug('ddrectype lpnid='||l_wsh_dd_rec.lpn_id||' lpn='||l_wsh_dd_rec.container_name||' itm='||l_wsh_dd_rec.inventory_item_id||' org='||l_wsh_dd_rec.organization_id||' sub='||l_wsh_dd_rec.subinventory||' loc='||l_wsh_dd_rec.locator_id, G_INFO);
400 mdebug('gwt='||l_wsh_dd_rec.gross_weight||' nwt='||l_wsh_dd_rec.net_weight||' wuom='||l_wsh_dd_rec.weight_uom_code||' fvol='||l_wsh_dd_rec.filled_volume||' vol='||l_wsh_dd_rec.volume||' vuom='||l_wsh_dd_rec.volume_uom_code, G_INFO);
401 END IF;
402
403 RETURN l_wsh_dd_rec;
404 END To_DeliveryDetailsRecType;
405
406 -- ----------------------------------------------------------------------------------
407 -- ----------------------------------------------------------------------------------
408
409 PROCEDURE Get_Greater_Qty (
410 p_debug IN NUMBER
411 , p_inventory_item_id IN NUMBER
412 , p_quantity1 IN NUMBER
413 , p_quantity1_uom IN VARCHAR2
414 , p_quantity2 IN NUMBER
415 , p_quantity2_uom IN VARCHAR2
416 , x_greater_qty OUT NOCOPY NUMBER
417 , x_greater_qty_uom OUT NOCOPY VARCHAR2
418 ) IS
419 l_api_name CONSTANT VARCHAR2(30) := 'Get_Greater_Qty';
420
421 BEGIN
422 IF ( NVL(p_quantity1, 0) = 0 OR p_quantity1_uom IS NULL ) THEN
423 x_greater_qty := p_quantity2;
424 x_greater_qty_uom := p_quantity2_uom;
425 ELSIF ( NVL(p_quantity2, 0) = 0 OR p_quantity2_uom IS NULL ) THEN
426 x_greater_qty := p_quantity1;
427 x_greater_qty_uom := p_quantity1_uom;
428 ELSIF ( p_quantity1_uom = p_quantity2_uom ) THEN
429 x_greater_qty := GREATEST(p_quantity1, p_quantity2);
430 x_greater_qty_uom := p_quantity2_uom;
431 ELSE -- Both are not null but with different UOMs need to convert
432 x_greater_qty_uom := p_quantity2_uom;
433
434 x_greater_qty := Convert_UOM(p_inventory_item_id, p_quantity1, p_quantity1_uom, x_greater_qty_uom);
435 x_greater_qty := GREATEST(x_greater_qty, p_quantity2);
436 END IF;
437
438 IF (p_debug = 1) THEN
439 mdebug('x_greater_qty='||x_greater_qty||' x_greater_qty_uom='||x_greater_qty_uom, G_INFO);
440 END IF;
441 END Get_Greater_Qty;
442
443 -- ----------------------------------------------------------------------------------
444 -- ----------------------------------------------------------------------------------
445
446 PROCEDURE Calc_Vol_Change (
447 p_debug IN NUMBER
448 , p_old_lpn IN WMS_Data_Type_Definitions_PUB.LPNRecordType
449 , p_new_lpn IN WMS_Data_Type_Definitions_PUB.LPNRecordType
450 , p_volume_change OUT NOCOPY NUMBER
451 , p_volume_uom_change OUT NOCOPY VARCHAR2
452 ) IS
453 l_api_name CONSTANT VARCHAR2(30) := 'Calc_Vol_Change';
454 l_progress VARCHAR2(500) := 'Entered API';
455
456 l_old_max_volume NUMBER;
457 l_old_max_volume_uom VARCHAR2(3);
458 l_new_max_volume NUMBER;
459 l_new_max_volume_uom VARCHAR2(3);
460
461 BEGIN
462 l_progress := 'Calculate the greater for old container/content volume';
463 -- First determine which was greater before update, container or content
464 Get_Greater_Qty (
465 p_debug => p_debug
466 , p_inventory_item_id => p_old_lpn.inventory_item_id
467 , p_quantity1 => p_old_lpn.container_volume
468 , p_quantity1_uom => p_old_lpn.container_volume_uom
469 , p_quantity2 => p_old_lpn.content_volume
470 , p_quantity2_uom => p_old_lpn.content_volume_uom_code
471 , x_greater_qty => l_old_max_volume
472 , x_greater_qty_uom => l_old_max_volume_uom );
473
474 IF (p_debug = 1) THEN
475 mdebug('old max vol='||l_old_max_volume||' old max vol uom='||l_old_max_volume_uom, G_INFO);
476 END IF;
477
478 Get_Greater_Qty (
479 p_debug => p_debug
480 , p_inventory_item_id => p_new_lpn.inventory_item_id
481 , p_quantity1 => p_new_lpn.container_volume
482 , p_quantity1_uom => p_new_lpn.container_volume_uom
483 , p_quantity2 => p_new_lpn.content_volume
484 , p_quantity2_uom => p_new_lpn.content_volume_uom_code
485 , x_greater_qty => l_new_max_volume
486 , x_greater_qty_uom => l_new_max_volume_uom );
487
488 IF (p_debug = 1) THEN
489 mdebug('new max vol='||l_new_max_volume||' new max vol uom='||l_new_max_volume_uom, G_INFO);
490 END IF;
491
492 -- Now we need to compare the difference between the greatest of the new and old
493 -- volumes to get the change in volume
494 -- again if the lpn is newly packed, then just use the new value
495 IF ( (p_old_lpn.parent_lpn_id IS NULL AND p_new_lpn.parent_lpn_id IS NOT NULL) OR
496 NVL(l_old_max_volume, 0) = 0 OR l_old_max_volume_uom IS NULL ) THEN
497 p_volume_change := l_new_max_volume;
498 p_volume_uom_change := l_new_max_volume_uom;
499 ELSIF ( NVL(l_new_max_volume, 0) = 0 OR l_new_max_volume_uom IS NULL ) THEN
500 p_volume_change := 0 - l_old_max_volume;
501 p_volume_uom_change := l_old_max_volume_uom;
502 ELSIF ( l_old_max_volume_uom = l_new_max_volume_uom ) THEN
503 p_volume_change := l_new_max_volume - l_old_max_volume;
504 p_volume_uom_change := l_new_max_volume_uom;
505 ELSE -- Both are not null but with different UOMs need to convert
506 l_old_max_volume := Convert_UOM(p_new_lpn.inventory_item_id, l_old_max_volume, l_old_max_volume_uom, l_new_max_volume_uom);
507 -- Change old max volume uom just for completeness sake
508 l_old_max_volume_uom := l_new_max_volume_uom;
509
510 p_volume_change := l_new_max_volume - l_old_max_volume;
511 p_volume_uom_change := l_new_max_volume_uom;
512 END IF;
513
514 IF (p_debug = 1) THEN
515 mdebug('change vol='||p_volume_change||' change vuom='||p_volume_uom_change, G_INFO);
516 END IF;
517 END;
518
519 --Bug 4144326. Added the following procedure.
520 --This procedure has to be called with the LPN before updating the attributes.
521 --This procedure will calculate the change in weight and volume for the LPN
522 --and update the Locator capacity with the difference.
523 PROCEDURE Update_Locator_Capacity (
524 x_return_status OUT NOCOPY VARCHAR2
525 , x_msg_count OUT NOCOPY NUMBER
526 , x_msg_data OUT NOCOPY VARCHAR2
527 , p_organization_id IN NUMBER
528 , p_subinventory IN VARCHAR2
529 , p_locator_id IN NUMBER
530 , p_weight_change IN NUMBER
531 , p_weight_uom_change IN VARCHAR2
532 , p_volume_change IN NUMBER
533 , p_volume_uom_change IN VARCHAR2
534 ) IS
535
536 l_api_name CONSTANT VARCHAR2(30) := 'Update_Locator_Capacity';
537 l_debug NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
538 wtdiff NUMBER := 0;
539 voldiff NUMBER := 0;
540 l_loc_wt_uom VARCHAR2(3);
541 l_loc_vol_uom VARCHAR2(3);
542
543 BEGIN
544 -- Standard Start of API savepoint
545 SAVEPOINT WMS_Update_Locator_Capacity;
546
547 x_return_status := fnd_api.g_ret_sts_success ; --set to Success by default.
548
549 IF (l_debug = 1) THEN
550 mdebug(l_api_name|| ' Entered ' ||g_pkg_version, 1);
551 mdebug('orgid='||p_organization_id||' sub='||p_subinventory||' loc='||p_locator_id||' wt='||p_weight_change||' wuom='||p_weight_uom_change||' vol='||p_volume_change||' vuom='||p_volume_uom_change, G_INFO);
552 END IF;
553
554
555 -- Bug 5150314, LPNs in non wms orgs may not have sub and loc info
556 -- bypass the update in this case
557 IF ( p_subinventory IS NOT NULL AND p_locator_id IS NOT NULL ) THEN
558 g_progress := 'Get UOM for Weight and volume of Locator';
559
560 -- Get locator information from cache
561 /*IF NOT ( INV_Cache.set_to_locator( p_locator_id ) THEN
562 --set_to_locator not implemented
563 END IF;*/
564
565 SELECT mil.location_weight_uom_code
566 , mil.volume_uom_code
567 INTO l_loc_wt_uom
568 , l_loc_vol_uom
569 FROM mtl_item_locations mil
570 WHERE mil.organization_id = p_organization_id
571 AND mil.subinventory_code = p_subinventory
572 AND mil.inventory_location_id = p_locator_id;
573
574 IF (l_debug = 1) THEN
575 mdebug('Got locator uoms location_weight_uom_code='||l_loc_wt_uom||' volume_uom_code='||l_loc_vol_uom, G_INFO);
576 END IF;
577
578 -- Find out the weight difference
579 IF ( l_loc_wt_uom IS NOT NULL ) THEN
580 IF ( NVL(p_weight_change, 0) <> 0 AND p_weight_uom_change IS NOT NULL ) THEN
581 g_progress := 'Convert change in weight to locator weight uom';
582 wtdiff := Convert_UOM (
583 p_inventory_item_id => 0
584 , p_fm_quantity => p_weight_change
585 , p_fm_uom => p_weight_uom_change
586 , p_to_uom => l_loc_wt_uom );
587 END IF;
588 END IF;
589
590 -- Find out the volume difference
591 IF ( l_loc_vol_uom IS NOT NULL ) THEN
592 IF ( NVL(p_volume_change, 0) <> 0 AND p_volume_uom_change IS NOT NULL) THEN
593 g_progress := 'Convert change in volume to locator volume uom';
594 voldiff := Convert_UOM (
595 p_inventory_item_id => 0
596 , p_fm_quantity => p_volume_change
597 , p_fm_uom => p_volume_uom_change
598 , p_to_uom => l_loc_vol_uom );
599 END IF;
600 END IF;
601 END IF;
602
603 IF (l_debug = 1) THEN
604 mdebug('wtdiff='||wtdiff||' voldiff='||voldiff, G_INFO);
605 END IF;
606
607 IF ( wtdiff <> 0 OR voldiff <> 0 ) THEN
608 g_progress := 'Update Locator capacity';
609
610 UPDATE mtl_item_locations mil
611 SET current_weight = nvl(current_weight,0) + wtdiff
612 , available_weight = nvl(available_weight,0) - wtdiff
613 , current_cubic_area = nvl(current_cubic_area,0) + voldiff
614 , available_cubic_area = nvl(available_cubic_area,0) - voldiff
615 WHERE mil.organization_id = p_organization_id
616 AND mil.subinventory_code = p_subinventory
617 AND mil.inventory_location_id = p_locator_id;
618 END IF;
619 EXCEPTION
620 WHEN OTHERS THEN
621 IF (l_debug = 1) THEN
622 mdebug(l_api_name ||' Error g_progress= '||g_progress, 1);
623 IF ( SQLCODE IS NOT NULL ) THEN
624 mdebug('SQL error: ' || SQLERRM(SQLCODE), 1);
625 END IF;
626 END IF;
627
628 ROLLBACK TO WMS_Update_Locator_Capacity;
629 x_return_status := fnd_api.g_ret_sts_unexp_error;
630 FND_MSG_PUB.Count_And_Get(p_count => x_msg_count, p_data => x_msg_data);
631 END Update_Locator_Capacity;
632
633
634 -- ======================================================================
635 -- FUNCTION Generate_Check_Digit
636 -- ======================================================================
637 -- Purpose
638 -- Generate the Check Digit for LPN using Modulo 10 Check Digit Algorithm
639 -- 1. Consider the right most digit of the code to be in an 'even'
640 -- position and assign odd/even to each character moving from right to
641 -- left.
642 -- 2. Sum the digits in all odd positions
643 -- 3. Sum the digits in all even positions and multiply the result by 3 .
644 -- 4. Sum the totals calculated in steps 2 and 3.
645 -- 5. The Check digit is the number which, when added to the totals
646 -- calculated in step 4, result in a number evenly divisible by 10.
647
648 -- Input Parameters
649 -- P_lpn_str (Required)
650 --
651 -- Output value :
652 -- Valid single check digit .
653 --
654
655 FUNCTION Generate_Check_Digit( p_debug NUMBER, p_lpn_str IN VARCHAR2 )
656
657 RETURN NUMBER
658 IS
659 l_api_name CONSTANT VARCHAR2(30) := 'Generate_Check_Digit';
660
661 L NUMBER;
662 I NUMBER;
663 l_evensum NUMBER := 0;
664 l_oddsum NUMBER := 0;
665 l_total NUMBER := 0;
666 l_checkdigit NUMBER := 0;
667 l_remainder NUMBER := 0;
668
669 l_length NUMBER;
670 l_lpn_str varchar2(255);
671 BEGIN
672 IF ( p_debug = 1 ) THEN
673 mdebug('p_lpn_str : ' || p_lpn_str, G_INFO);
674 END IF;
675
676 L := 0;
677 l_lpn_str := rtrim(p_lpn_str);
678 l_length := LENGTH(l_lpn_str);
679
680 FOR I IN REVERSE 1..l_length
681 LOOP
682 -- mdebug('l_lpn_str(' || I || ') : ' || to_number(substr(l_lpn_str,I,1)), G_INFO);
683 IF (mod(L,2) = 0) THEN
684 l_Evensum := l_Evensum + to_number(substr(l_lpn_str,I,1));
685 ELSE
686 l_Oddsum := l_Oddsum + to_number(substr(l_lpn_str,I,1));
687 END IF;
688 L := L + 1;
689 END LOOP;
690
691 l_Evensum := l_Evensum * 3;
692 l_Total := l_Evensum + l_Oddsum;
693 l_remainder := mod(l_total,10);
694
695 IF ( p_debug = 1 ) THEN
696 mdebug('l_total:' || l_total || ' l_remainder : ' || l_remainder, G_INFO);
697 END IF;
698
699 IF (l_remainder > 0) THEN
700 l_checkdigit := 10 - l_remainder;
701 END IF;
702
703 IF ( p_debug = 1 ) THEN
704 mdebug('l_checkdigit : ' || l_checkdigit, G_INFO);
705 END IF;
706
707 RETURN l_checkdigit;
708 END Generate_Check_Digit;
709
710
711 -- ----------------------------------------------------------------------------------
712 -- Added For LSP Project, bug 9087971
713 -- ----------------------------------------------------------------------------------
714 -- ======================================================================
715 -- PROCEDURE set_client_info
716 -- ======================================================================
717 -- Purpose
718 -- Following procedure will accept the client code of the item
719 -- and set the client record in global variable g_client_rec of this package.
720
721 -- Input Parameters
722 -- p_client_code client code of the item
723 --
724 -- Output value :
725 -- x_ret_status Return Status
726 --
727
728 PROCEDURE set_client_info
729 (
730 p_client_code IN VARCHAR2,
731 x_ret_status OUT NOCOPY VARCHAR2
732 ) IS
733 l_api_name CONSTANT VARCHAR2(30) := 'set_client_info';
734 l_debug NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
735 l_client_id NUMBER;
736 l_client_rec inv_cache.ct_rec_type;
737 BEGIN
738 SELECT client_id INTO l_client_id
739 FROM MTL_CLIENT_PARAMETERS
740 WHERE client_code = p_client_code;
741
742 inv_cache.get_client_default_parameters
743 ( p_client_id => l_client_id,
744 x_return_status => x_ret_status,
745 x_client_parameters_rec => l_client_rec
746 );
747
748 IF x_ret_status = fnd_api.g_ret_sts_success THEN
749 g_client_rec := l_client_rec;
750 END IF;
751 EXCEPTION
752 WHEN OTHERS THEN
753 x_ret_status := fnd_api.g_ret_sts_error;
754 IF (l_debug = 1) THEN
755 mdebug(l_api_name ||' Error SQL error: '|| SQLERRM(SQLCODE), G_ERROR);
756 END IF;
757 END;
758
759 -- ----------------------------------------------------------------------------------
760 -- ----------------------------------------------------------------------------------
761
762 PROCEDURE Create_LPNs (
763 p_api_version IN NUMBER
764 , p_init_msg_list IN VARCHAR2
765 , p_commit IN VARCHAR2
766 , x_return_status OUT NOCOPY VARCHAR2
767 , x_msg_count OUT NOCOPY NUMBER
768 , x_msg_data OUT NOCOPY VARCHAR2
769 , p_caller IN VARCHAR2
770 , p_lpn_table IN OUT NOCOPY WMS_Data_Type_Definitions_PUB.LPNTableType
771 ) IS
772 l_api_name CONSTANT VARCHAR2(30) := 'Create_LPNs';
773 l_api_version CONSTANT NUMBER := 1.0;
774 l_debug NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
775 l_progress VARCHAR2(500) := 'Entered API';
776 l_msgdata VARCHAR2(1000);
777
778 l_lpn_bulk_rec LPNBulkRecType;
779
780 l_user_id NUMBER;
781 l_request_id NUMBER;
782
783 l_label_status VARCHAR2(300);
784 l_dummy_num NUMBER;
785
786 -- Variables for call to Print_Label
787 l_input_param_tbl inv_label.input_parameter_rec_type;
788 l_return_status VARCHAR2(30);
789
790 -- Variables used for Creating LPNs in shipping
791 l_detail_info_tab WSH_GLBL_VAR_STRCT_GRP.delivery_details_Attr_tbl_Type;
792 l_IN_rec WSH_GLBL_VAR_STRCT_GRP.detailInRecType;
793 l_OUT_rec WSH_GLBL_VAR_STRCT_GRP.detailOutRecType;
794
795 BEGIN
796 -- Standard Start of API savepoint
797 SAVEPOINT CREATE_LPNS_PVT;
798
799 -- Standard call to check for call compatibility.
800 IF NOT fnd_api.compatible_api_call(l_api_version, p_api_version, l_api_name, g_pkg_name) THEN
801 fnd_message.set_name('WMS', 'WMS_CONT_INCOMPATIBLE_API_CALL');
802 fnd_msg_pub.ADD;
803 RAISE fnd_api.g_exc_unexpected_error;
804 END IF;
805
806 -- Initialize message list if p_init_msg_list is set to TRUE.
807 IF fnd_api.to_boolean(p_init_msg_list) THEN
808 fnd_msg_pub.initialize;
809 END IF;
810
811 -- Initialize API return status to success
812 x_return_status := fnd_api.g_ret_sts_success;
813
814 -- API body
815 IF (l_debug = 1) THEN
816 mdebug(l_api_name || ' Entered ' || g_pkg_version, 1);
817 mdebug('ver='||p_api_version||' initmsg='||p_init_msg_list||' commit='||p_commit||' caller='||p_caller||' tabcnt='||p_lpn_table.last, G_INFO);
818 END IF;
819
820 l_progress := 'Getting any profile user values';
821
822 SELECT fnd_global.user_id
823 , FND_PROFILE.value('CONC_REQUEST_ID')
824 INTO l_user_id
825 , l_request_id
826 FROM DUAL;
827
828 IF (l_debug = 1) THEN
829 mdebug('Got profile info user_id='||l_user_id||' request_id='||l_request_id , G_INFO);
830 END IF;
831
832 l_progress := 'Validation for each LPN in record';
833
834 FOR i IN p_lpn_table.first .. p_lpn_table.last LOOP
835 IF ( l_debug = 1 ) THEN
836 mdebug('lpn='||p_lpn_table(i).license_plate_number||' org='||p_lpn_table(i).organization_id||' sub='||p_lpn_table(i).subinventory_code||' loc='||p_lpn_table(i).locator_id||' ctx='||p_lpn_table(i).lpn_context||
837 ' itm='||p_lpn_table(i).inventory_item_id||' plpn='||p_lpn_table(i).parent_lpn_id||' olpn='||p_lpn_table(i).outermost_lpn_id, G_INFO);
838 mdebug('gwt='||p_lpn_table(i).gross_weight||' gwuom='||p_lpn_table(i).gross_weight_uom_code||' twt='||p_lpn_table(i).tare_weight_uom_code|| ' twuom='||p_lpn_table(i).tare_weight_uom_code||
839 ' ctrvuom='||p_lpn_table(i).container_volume_uom||' ctrvol='||p_lpn_table(i).container_volume||' cntvuom='||p_lpn_table(i).content_volume_uom_code||' cntvol='||p_lpn_table(i).content_volume, G_INFO);
840 END IF;
841
842 -- Organization is required. Make sure that it is populated
843 IF ( p_lpn_table(i).organization_id IS NULL ) THEN
844 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_ORG');
845 fnd_msg_pub.ADD;
846 RAISE fnd_api.g_exc_error;
847 END IF;
848
849 IF ( p_lpn_table(i).inventory_item_id IS NOT NULL) THEN
850 l_progress := 'Calling INV_CACHE.Set_Item_Rec to get item values';
851
852 IF ( inv_cache.set_item_rec(
853 p_organization_id => p_lpn_table(i).organization_id
854 , p_item_id => p_lpn_table(i).inventory_item_id ) )
855 THEN
856 IF (l_debug = 1) THEN
857 mdebug('Got Item info citm='||inv_cache.item_rec.container_item_flag||' snctl='||inv_cache.item_rec.serial_number_control_code, G_INFO);
858 mdebug('wuom='||inv_cache.item_rec.weight_uom_code||' wt='||inv_cache.item_rec.unit_weight||' vuom='||inv_cache.item_rec.volume_uom_code||' vol='||inv_cache.item_rec.unit_volume, G_INFO);
859 END IF;
860
861 IF ( inv_cache.item_rec.container_item_flag = 'N' ) THEN
862 IF (l_debug = 1) THEN
863 mdebug(p_lpn_table(i).inventory_item_id || ' is not a container', 1);
864 END IF;
865 fnd_message.set_name('WMS', 'WMS_ITEM_NOT_CONTAINER');
866 fnd_message.set_token('ITEM', inv_cache.item_rec.segment1);
867 fnd_msg_pub.ADD;
868 RAISE fnd_api.g_exc_error;
869 END IF;
870
871 p_lpn_table(i).tare_weight_uom_code := inv_cache.item_rec.weight_uom_code;
872 p_lpn_table(i).tare_weight := inv_cache.item_rec.unit_weight;
873 p_lpn_table(i).container_volume_uom := inv_cache.item_rec.volume_uom_code;
874 p_lpn_table(i).container_volume := inv_cache.item_rec.unit_volume;
875 ELSE
876 l_progress := 'Error calling INV_CACHE.Set_Item_Rec for orgid'||p_lpn_table(i).organization_id||' item id='||p_lpn_table(i).inventory_item_id;
877 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_ITEM');
878 fnd_msg_pub.ADD;
879 RAISE fnd_api.g_exc_error;
880 END IF;
881 END IF;
882
883 -- LPN Context cannot be null
884 p_lpn_table(i).lpn_context := NVL(p_lpn_table(i).lpn_context, WMS_CONTAINER_PUB.LPN_CONTEXT_PREGENERATED);
885
886 -- If context is pregenerated, do not allow sub and loc info
887 IF ( p_lpn_table(i).lpn_context = WMS_CONTAINER_PUB.LPN_CONTEXT_PREGENERATED ) THEN
888 p_lpn_table(i).subinventory_code := NULL;
889 p_lpn_table(i).locator_id := NULL;
890 END IF;
891
892 --Check LPN for leading or trailing spaces if they exist
893 p_lpn_table(i).license_plate_number := RTRIM(LTRIM(p_lpn_table(i).license_plate_number,' '),' ');
894
895 IF ( length(p_lpn_table(i).license_plate_number) = 0 ) THEN
896 IF (l_debug = 1) THEN
897 mdebug(' LPN name parameter consists of only spaces cannot create', G_ERROR);
898 END IF;
899 fnd_message.set_name('WMS', 'WMS_LPN_INAPPROPRIATE_SPACES');
900 fnd_msg_pub.ADD;
901 RAISE FND_API.G_EXC_ERROR;
902 END IF;
903
904 SELECT wms_license_plate_numbers_s1.NEXTVAL
905 INTO p_lpn_table(i).lpn_id
906 FROM DUAL;
907
908 IF (l_debug = 1) THEN
909 mdebug('Created lpn_id='||p_lpn_table(i).lpn_id||' for LPN '||p_lpn_table(i).license_plate_number, G_INFO);
910 END IF;
911
912 p_lpn_table(i).outermost_lpn_id := p_lpn_table(i).lpn_id;
913
914 l_progress := 'Passed validation inserting into bulk table';
915
916 To_LPNBulkRecType(
917 p_lpn_table => p_lpn_table
918 , p_table_first => i
919 , p_table_last => i
920 , p_record_last => l_lpn_bulk_rec.lpn_id.last
921 , x_lpn_bulk_rec => l_lpn_bulk_rec );
922
923 -- Insert into label printing table
924 l_input_param_tbl(i).lpn_id := p_lpn_table(i).lpn_id;
925
926 -- If caller is shipping we need to put LPNs in WDD as well
927 -- since they are in WDD, we will need to default the LPNs to picked
928 IF ( p_caller like 'WSH%' ) THEN
929 l_detail_info_tab(i).lpn_id := p_lpn_table(i).lpn_id;
930 l_detail_info_tab(i).container_name := p_lpn_table(i).license_plate_number;
931 l_detail_info_tab(i).organization_id := p_lpn_table(i).organization_id;
932 l_detail_info_tab(i).subinventory := p_lpn_table(i).subinventory_code;
933 l_detail_info_tab(i).locator_id := p_lpn_table(i).locator_id;
934 l_detail_info_tab(i).inventory_item_id := p_lpn_table(i).inventory_item_id;
935
936 l_detail_info_tab(i).net_weight := p_lpn_table(i).tare_weight;
937 l_detail_info_tab(i).gross_weight := p_lpn_table(i).tare_weight;
938 l_detail_info_tab(i).weight_uom_code := p_lpn_table(i).tare_weight_uom_code;
939
940 l_detail_info_tab(i).filled_volume := NULL;
941 l_detail_info_tab(i).volume := p_lpn_table(i).container_volume;
942 l_detail_info_tab(i).volume_uom_code := p_lpn_table(i).container_volume_uom;
943 END IF;
944 END LOOP;
945
946 -- Insert the newly created lpn id/license plate number record into the table
947 BEGIN
948 IF (l_debug = 1) THEN
949 mdebug('Bulk insert LPNs in WLPN: '||to_char(l_lpn_bulk_rec.lpn_id.first)||'-'||to_char(l_lpn_bulk_rec.lpn_id.last), G_INFO);
950 END IF;
951
952 FORALL j IN l_lpn_bulk_rec.lpn_id.first..l_lpn_bulk_rec.lpn_id.last
953 INSERT INTO wms_license_plate_numbers (
954 last_update_date
955 , last_updated_by
956 , creation_date
957 , created_by
958 , request_id
959
960 , lpn_id
961 , license_plate_number
962 , parent_lpn_id
963 , outermost_lpn_id
964 , lpn_context
965 , sealed_status
966
967 , organization_id
968 , subinventory_code
969 , locator_id
970
971 , inventory_item_id
972 , revision
973 , lot_number
974 , serial_number
975 , cost_group_id
976
977 , tare_weight_uom_code
978 , tare_weight
979 , gross_weight_uom_code
980 , gross_weight
981 , container_volume_uom
982 , container_volume
983 , content_volume_uom_code
984 , content_volume
985
986 , source_type_id
987 , source_header_id
988 , source_line_id
989 , source_line_detail_id
990 , source_name
991 )
992 VALUES (
993 SYSDATE
994 , l_user_id
995 , SYSDATE
996 , l_user_id
997 , l_request_id
998
999 , l_lpn_bulk_rec.lpn_id(j)
1000 , l_lpn_bulk_rec.license_plate_number(j)
1001 , l_lpn_bulk_rec.parent_lpn_id(j)
1002 , l_lpn_bulk_rec.outermost_lpn_id(j)
1003 , l_lpn_bulk_rec.lpn_context(j)
1004 , 2 --sealed_status
1005
1006 , l_lpn_bulk_rec.organization_id(j)
1007 , l_lpn_bulk_rec.subinventory_code(j)
1008 , l_lpn_bulk_rec.locator_id(j)
1009
1010 , l_lpn_bulk_rec.inventory_item_id(j)
1011 , l_lpn_bulk_rec.revision(j)
1012 , l_lpn_bulk_rec.lot_number(j)
1013 , l_lpn_bulk_rec.serial_number(j)
1014 , l_lpn_bulk_rec.cost_group_id(j)
1015
1016 , l_lpn_bulk_rec.tare_weight_uom_code(j)
1017 , l_lpn_bulk_rec.tare_weight(j)
1018 , l_lpn_bulk_rec.tare_weight_uom_code(j)
1019 , l_lpn_bulk_rec.tare_weight(j)
1020 , l_lpn_bulk_rec.container_volume_uom(j)
1021 , l_lpn_bulk_rec.container_volume(j)
1022 , l_lpn_bulk_rec.content_volume_uom_code(j)
1023 , NULL --content_volume
1024
1025 , l_lpn_bulk_rec.source_type_id(j)
1026 , l_lpn_bulk_rec.source_header_id(j)
1027 , l_lpn_bulk_rec.source_line_id(j)
1028 , l_lpn_bulk_rec.source_line_detail_id(j)
1029 , l_lpn_bulk_rec.source_name(j)
1030 );
1031 IF (l_debug = 1) THEN
1032 mdebug('Bulk insert LPNs in WLPN done count='||SQL%ROWCOUNT, G_INFO);
1033 END IF;
1034 EXCEPTION
1035 WHEN OTHERS THEN
1036 IF (l_debug = 1) THEN
1037 mdebug('Insert into WLPN failed SQL error: '|| SQLERRM(SQLCODE), G_ERROR);
1038 END IF;
1039
1040 IF ( SQLCODE = 00001 ) THEN
1041 FOR k IN l_lpn_bulk_rec.lpn_id.first..l_lpn_bulk_rec.lpn_id.last LOOP
1042 --l_progress := 'Validate if LPN already exists in the system';
1043 BEGIN
1044 SELECT 1 INTO l_dummy_num
1045 FROM wms_license_plate_numbers
1046 WHERE license_plate_number = l_lpn_bulk_rec.license_plate_number(k);
1047
1048 IF ( l_debug = 1 ) THEN
1049 mdebug('LPN '||l_lpn_bulk_rec.license_plate_number(k)||' already exists, cannot create it', G_ERROR);
1050 END IF;
1051 fnd_message.set_name('WMS', 'WMS_CONT_DUPLICATE_LPN');
1052 fnd_message.set_token('LPN', l_lpn_bulk_rec.license_plate_number(k));
1053 fnd_msg_pub.ADD;
1054 RAISE fnd_api.g_exc_error;
1055 EXCEPTION
1056 WHEN NO_DATA_FOUND THEN
1057 NULL;
1058 END;
1059 END LOOP;
1060 END IF;
1061
1062 l_progress := 'Could not find reason for LPN insert failure. Give generic failure msg';
1063 fnd_message.set_name('WMS', 'WMS_LPN_NOTGEN');
1064 fnd_msg_pub.ADD;
1065 RAISE fnd_api.g_exc_error;
1066 END;
1067
1068 l_progress := 'Create LPN call to label printing';
1069
1070 BEGIN
1071 inv_label.print_label (
1072 p_api_version => 1.0
1073 , x_return_status => l_return_status
1074 , x_msg_count => x_msg_count
1075 , x_msg_data => x_msg_data
1076 , x_label_status => l_label_status
1077 , p_print_mode => 2
1078 , p_business_flow_code => 16
1079 , p_input_param_rec => l_input_param_tbl );
1080
1081 IF ( l_return_status <> fnd_api.g_ret_sts_success ) THEN
1082 IF (l_debug = 1) THEN
1083 mdebug('failed to print labels in create_lpns', G_ERROR);
1084 END IF;
1085 fnd_message.set_name('WMS', 'WMS_PRINT_LABEL_FAIL');
1086 fnd_msg_pub.ADD;
1087 END IF;
1088 EXCEPTION
1089 WHEN OTHERS THEN
1090 IF (l_debug = 1) THEN
1091 mdebug('Exception occured while calling print_label in create_lpns', G_ERROR);
1092 END IF;
1093 fnd_message.set_name('WMS', 'WMS_PRINT_LABEL_FAIL');
1094 fnd_msg_pub.ADD;
1095 END;
1096
1097 l_progress := 'Call shipping with new LPNs in need be';
1098 IF ( l_detail_info_tab.last > 0 )THEN
1099 IF (l_debug = 1) THEN
1100 mdebug('Calling Create_Update_Containers size='||l_detail_info_tab.last, G_INFO);
1101 END IF;
1102
1103 l_IN_rec.caller := 'WMS';
1104 l_IN_rec.action_code := 'CREATE';
1105
1106 WSH_WMS_LPN_GRP.Create_Update_Containers (
1107 p_api_version => 1.0
1108 , p_init_msg_list => fnd_api.g_false
1109 , p_commit => fnd_api.g_false
1110 , x_return_status => x_return_status
1111 , x_msg_count => x_msg_count
1112 , x_msg_data => x_msg_data
1113 , p_detail_info_tab => l_detail_info_tab
1114 , p_IN_rec => l_IN_rec
1115 , x_OUT_rec => l_OUT_rec );
1116
1117 IF ( x_return_status <> fnd_api.g_ret_sts_success ) THEN
1118 IF (l_debug = 1) THEN
1119 mdebug('Create_Update_Containers Failed', G_ERROR);
1120 END IF;
1121 RAISE fnd_api.g_exc_error;
1122 ELSIF ( l_debug = 1 ) THEN
1123 mdebug('Done with Create_Update_Containers', G_INFO);
1124 END IF;
1125 END IF;
1126
1127 l_progress := 'End of API body';
1128
1129 -- Standard check of p_commit.
1130 IF fnd_api.to_boolean(p_commit) THEN
1131 COMMIT WORK;
1132 END IF;
1133
1134 -- Standard call to get message count and data
1135 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
1136 EXCEPTION
1137 WHEN FND_API.G_EXC_ERROR THEN
1138 x_return_status := fnd_api.g_ret_sts_error;
1139 FND_MSG_PUB.Count_And_Get(p_count => x_msg_count, p_data => x_msg_data);
1140 IF (l_debug = 1) THEN
1141 FOR i in 1..x_msg_count LOOP
1142 l_msgdata := substr(l_msgdata||' | '||substr(fnd_msg_pub.get(x_msg_count-i+1, 'F'), 0, 200),1,2000);
1143 END LOOP;
1144 mdebug(l_api_name ||' Error progress='||l_progress||' SQL error: '|| SQLERRM(SQLCODE), G_ERROR);
1145 mdebug('msg: '||l_msgdata, G_ERROR);
1146 END IF;
1147 ROLLBACK TO CREATE_LPNS_PVT;
1148
1149 -- Failed to generate remove lpn_ids from table
1150 FOR i IN p_lpn_table.first .. p_lpn_table.last LOOP
1151 p_lpn_table(i).lpn_id := NULL;
1152 END LOOP;
1153 WHEN OTHERS THEN
1154 x_return_status := fnd_api.g_ret_sts_unexp_error;
1155 fnd_message.set_name('WMS', 'WMS_LPN_NOTGEN');
1156 fnd_msg_pub.ADD;
1157 FND_MSG_PUB.Count_And_Get(p_count => x_msg_count, p_data => x_msg_data);
1158 IF (l_debug = 1) THEN
1159 mdebug(l_api_name ||' Error progress='||l_progress||' SQL error: '|| SQLERRM(SQLCODE), G_ERROR);
1160 END IF;
1161 ROLLBACK TO CREATE_LPNS_PVT;
1162
1163 -- Failed to generate remove lpn_ids from table
1164 FOR i IN p_lpn_table.first .. p_lpn_table.last LOOP
1165 p_lpn_table(i).lpn_id := NULL;
1166 END LOOP;
1167 END Create_LPNs;
1168
1169 -- ----------------------------------------------------------------------------------
1170 -- ----------------------------------------------------------------------------------
1171
1172 PROCEDURE Auto_Create_LPNs (
1173 p_api_version IN NUMBER
1174 , p_init_msg_list IN VARCHAR2
1175 , p_commit IN VARCHAR2
1176 , x_return_status OUT NOCOPY VARCHAR2
1177 , x_msg_count OUT NOCOPY NUMBER
1178 , x_msg_data OUT NOCOPY VARCHAR2
1179 , p_caller IN VARCHAR2
1180 , p_quantity IN NUMBER
1181 , p_lpn_prefix IN VARCHAR2
1182 , p_lpn_suffix IN VARCHAR2
1183 , p_starting_number IN NUMBER
1184 , p_total_lpn_length IN NUMBER
1185 , p_ucc_128_suffix_flag IN VARCHAR2
1186 , p_lpn_attributes IN WMS_Data_Type_Definitions_PUB.LPNRecordType
1187 , p_serial_ranges IN WMS_Data_Type_Definitions_PUB.SerialRangeTableType
1188 , x_created_lpns OUT NOCOPY WMS_Data_Type_Definitions_PUB.LPNTableType
1189 ) IS
1190
1191 BEGIN
1192 Auto_Create_LPNs (
1193 p_api_version => p_api_version
1194 , p_init_msg_list => p_init_msg_list
1195 , p_commit => p_commit
1196 , x_return_status => x_return_status
1197 , x_msg_count => x_msg_count
1198 , x_msg_data => x_msg_data
1199 , p_caller => p_caller
1200 , p_quantity => p_quantity
1201 , p_lpn_prefix => p_lpn_prefix
1202 , p_lpn_suffix => p_lpn_suffix
1203 , p_starting_number => p_starting_number
1204 , p_total_lpn_length => p_total_lpn_length
1205 , p_ucc_128_suffix_flag => p_ucc_128_suffix_flag
1206 , p_lpn_attributes => p_lpn_attributes
1207 , p_serial_ranges => p_serial_ranges
1208 , x_created_lpns => x_created_lpns
1209 , p_client_code => NULL
1210 );
1211 END Auto_Create_LPNs;
1212
1213 -- ----------------------------------------------------------------------------------
1214 -- Added For LSP Project, bug 9087971
1215 -- ----------------------------------------------------------------------------------
1216
1217 PROCEDURE Get_Upd_Client_LPN_Start_Num (
1218 p_client_id IN NUMBER
1219 , p_qty IN NUMBER
1220 , x_curr_seq OUT NOCOPY NUMBER
1221 ) IS PRAGMA AUTONOMOUS_TRANSACTION;
1222 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
1223 l_lpn_start_num NUMBER:=0;
1224
1225 BEGIN
1226
1227 SELECT lpn_starting_number INTO l_lpn_start_num
1228 FROM mtl_client_parameters
1229 WHERE client_id = p_client_id
1230 FOR UPDATE;
1231
1232 UPDATE mtl_client_parameters
1233 SET lpn_starting_number = l_lpn_start_num+p_qty,
1234 last_update_date = SYSDATE,
1235 last_updated_by = FND_GLOBAL.USER_ID
1236 WHERE client_id = p_client_id;
1237
1238 x_curr_seq:=l_lpn_start_num;
1239
1240 COMMIT;
1241 END Get_Upd_Client_LPN_Start_Num;
1242
1243
1244 -- ----------------------------------------------------------------------------------
1245 -- Added For LSP Project, bug 9087971
1246 -- Overloaded procedure for LSPs with additional parameter as p_client_code.
1247 -- ----------------------------------------------------------------------------------
1248
1249 PROCEDURE Auto_Create_LPNs (
1250 p_api_version IN NUMBER
1251 , p_init_msg_list IN VARCHAR2
1252 , p_commit IN VARCHAR2
1253 , x_return_status OUT NOCOPY VARCHAR2
1254 , x_msg_count OUT NOCOPY NUMBER
1255 , x_msg_data OUT NOCOPY VARCHAR2
1256 , p_caller IN VARCHAR2
1257 , p_quantity IN NUMBER
1258 , p_lpn_prefix IN VARCHAR2
1259 , p_lpn_suffix IN VARCHAR2
1260 , p_starting_number IN NUMBER
1261 , p_total_lpn_length IN NUMBER
1262 , p_ucc_128_suffix_flag IN VARCHAR2
1263 , p_lpn_attributes IN WMS_Data_Type_Definitions_PUB.LPNRecordType
1264 , p_serial_ranges IN WMS_Data_Type_Definitions_PUB.SerialRangeTableType
1265 , x_created_lpns OUT NOCOPY WMS_Data_Type_Definitions_PUB.LPNTableType
1266 , p_client_code IN VARCHAR2 -- Adding for LSP, bug 9087971
1267 ) IS
1268 l_api_name CONSTANT VARCHAR2(30) := 'Auto_Create_LPNs New';
1269 l_api_version CONSTANT NUMBER := 1.0;
1270 l_debug NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
1271 l_progress VARCHAR2(500) := 'Entered API';
1272 l_msgdata VARCHAR2(1000);
1273
1274 -- Constants used for LPN processing
1275 l_from_user CONSTANT NUMBER := 1;
1276 l_from_db_seq CONSTANT NUMBER := 2;
1277 l_from_org CONSTANT NUMBER := 3;
1278 l_from_client CONSTANT NUMBER := 4;
1279 l_lpn_tab WMS_Data_Type_Definitions_PUB.LPNTableType;
1280 l_serial_rec WMS_Data_Type_Definitions_PUB.SerialRangeRecordType;
1281
1282 -- Local copies of input params that may need update from defaults
1283 l_quantity NUMBER := p_quantity ;
1284 l_lpn_prefix VARCHAR2(50) := p_lpn_prefix;
1285 l_lpn_suffix VARCHAR2(50) := p_lpn_suffix;
1286 l_total_lpn_length NUMBER := p_total_lpn_length;
1287 l_ucc_128_suffix_flag VARCHAR2(1) := p_ucc_128_suffix_flag;
1288 l_client_code VARCHAR2(40) := p_client_code; -- Increased the size to 40 for Bug 9575186
1289 l_ret_status VARCHAR2(1);
1290 -- Variable used to creaate LPN name
1291 l_seq_source NUMBER;
1292 l_loop_cnt NUMBER;
1293 l_lpn_cnt NUMBER;
1294 l_curr_seq NUMBER;
1295 l_last_org_seq NUMBER;
1296 l_last_client_seq NUMBER;
1297 l_lpn_seq_length NUMBER;
1298 l_dummy_number NUMBER;
1299
1300 -- Varibles used for Serial processing
1301 l_current_serial VARCHAR2(30);
1302 l_current_number NUMBER;
1303 l_padded_length NUMBER;
1304
1305 l_lsp_installed NUMBER := NVL(FND_PROFILE.VALUE('WMS_DEPLOYMENT_MODE'),1); --Added for LSPs, bug 9087971
1306
1307 BEGIN
1308 -- Standard Start of API savepoint
1309 SAVEPOINT AUTO_CREATE_LPNS_PVT;
1310
1311 -- Standard call to check for call compatibility.
1312 IF NOT fnd_api.compatible_api_call(l_api_version, p_api_version, l_api_name, g_pkg_name) THEN
1313 fnd_message.set_name('WMS', 'WMS_CONT_INCOMPATIBLE_API_CALL');
1314 fnd_msg_pub.ADD;
1315 RAISE fnd_api.g_exc_unexpected_error;
1316 END IF;
1317
1318 -- Initialize message list if p_init_msg_list is set to TRUE.
1319 IF fnd_api.to_boolean(p_init_msg_list) THEN
1320 fnd_msg_pub.initialize;
1321 END IF;
1322
1323 -- Initialize API return status to success
1324 x_return_status := fnd_api.g_ret_sts_success;
1325
1326 -- API body
1327 IF (l_debug = 1) THEN
1328 mdebug(l_api_name || ' Entered ' || g_pkg_version, 1);
1329 mdebug('ver='||p_api_version||' initmsg='||p_init_msg_list||' commit='||p_commit||' caller='||p_caller, G_INFO);
1330 mdebug('org='||p_lpn_attributes.organization_id||' sub='||p_lpn_attributes.subinventory_code||' loc='||p_lpn_attributes.locator_id||' itm='||p_lpn_attributes.inventory_item_id||' pfx='||p_lpn_prefix||' sfx='||p_lpn_suffix||
1331 ' snum='||p_starting_number||' qty='||p_quantity||' ctx='||p_lpn_attributes.lpn_context||' lgth='||p_total_lpn_length||' ucc='||p_ucc_128_suffix_flag, G_INFO);
1332 mdebug('srctype='||p_lpn_attributes.source_type_id|| ' l_client_code=' || l_client_code||' srchdr='||p_lpn_attributes.source_header_id||' srcln='||p_lpn_attributes.source_line_id||' trxid='||p_lpn_attributes.source_transaction_id, G_INFO);
1333 END IF;
1334
1335 l_progress := 'Validate quantity';
1336 IF ( NVL(p_quantity, -1) < 0 ) THEN
1337 fnd_message.set_name('WMS', 'WMS_INVALID_QTY');
1338 fnd_msg_pub.ADD;
1339 RAISE fnd_api.g_exc_error;
1340 END IF;
1341
1342 l_progress := 'Validate Organization ID';
1343
1344 IF ( NOT Inv_Cache.set_org_rec( p_organization_id => p_lpn_attributes.organization_id ) )THEN
1345 IF (l_debug = 1) THEN
1346 mdebug(p_lpn_attributes.organization_id||' is an invalid organization id', G_ERROR);
1347 END IF;
1348 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_ORG');
1349 fnd_msg_pub.ADD;
1350 RAISE fnd_api.g_exc_error;
1351 END IF;
1352
1353
1354 l_progress := 'Validate Client Code';
1355
1356 IF (l_lsp_installed = 3 AND l_client_code IS NOT NULL) THEN
1357 set_client_info (p_client_code => l_client_code,
1358 x_ret_status => l_ret_status);
1359 IF (l_ret_status <> fnd_api.g_ret_sts_success )THEN
1360 IF (l_debug = 1) THEN
1361 mdebug(l_client_code||' is an invalid client code', G_ERROR);
1362 END IF;
1363 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_CLIENT');
1364 fnd_msg_pub.ADD;
1365 RAISE fnd_api.g_exc_error;
1366 END IF;
1367 END IF;
1368
1369
1370 IF (l_debug = 1) THEN
1371 mdebug('Got org info pfx='||inv_cache.org_rec.lpn_prefix||' sfx='||inv_cache.org_rec.lpn_suffix||' seq='||inv_cache.org_rec.lpn_starting_number||' lgth='||inv_cache.org_rec.total_lpn_length||' ucc='||inv_cache.org_rec.ucc_128_suffix_flag, 5);
1372 END IF;
1373
1374 IF ( p_lpn_attributes.inventory_item_id IS NOT NULL) THEN
1375 l_progress := 'Validate Container Item';
1376
1377 IF ( inv_cache.set_item_rec(
1378 p_organization_id => p_lpn_attributes.organization_id
1379 , p_item_id => p_lpn_attributes.inventory_item_id ) )
1380 THEN
1381 IF (l_debug = 1) THEN
1382 mdebug('Itm info citm='||inv_cache.item_rec.container_item_flag||' snctl='||inv_cache.item_rec.serial_number_control_code, G_INFO);
1383 END IF;
1384
1385 IF ( inv_cache.item_rec.container_item_flag = 'N' ) THEN
1386 IF (l_debug = 1) THEN
1387 mdebug(p_lpn_attributes.inventory_item_id|| ' is not a container', G_ERROR);
1388 END IF;
1389 fnd_message.set_name('WMS', 'WMS_ITEM_NOT_CONTAINER');
1390 fnd_message.set_token('ITEM', inv_cache.item_rec.segment1);
1391 fnd_msg_pub.ADD;
1392 RAISE fnd_api.g_exc_error;
1393 END IF;
1394 ELSE
1395 l_progress := 'Error calling INV_CACHE.Set_Item_Rec for orgid'||p_lpn_attributes.organization_id||' item id='||p_lpn_attributes.inventory_item_id;
1396 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_ITEM');
1397 fnd_msg_pub.ADD;
1398 RAISE fnd_api.g_exc_error;
1399 END IF;
1400 END IF;
1401
1402 l_progress := 'Determine the source for LPN seq starting number';
1403
1404 IF ( p_starting_number IS NOT NULL ) THEN
1405 IF ( p_starting_number < 0 ) THEN
1406 IF (l_debug = 1) THEN
1407 mdebug(p_starting_number || ' is an invalid start num', G_ERROR);
1408 END IF;
1409 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_START_NUM');
1410 fnd_msg_pub.ADD;
1411 RAISE fnd_api.g_exc_error;
1412 END IF;
1413
1414 l_seq_source := l_from_user;
1415 l_curr_seq := p_starting_number;
1416
1417 ELSIF ( l_lsp_installed = 3 AND l_client_code IS NOT NULL AND g_client_rec.client_rec.lpn_starting_number IS NOT NULL ) THEN
1418 l_seq_source := l_from_client;
1419 l_curr_seq := null;
1420
1421 ELSIF ( inv_cache.org_rec.lpn_starting_number IS NOT NULL ) THEN
1422 l_seq_source := l_from_org;
1423 l_curr_seq := null;
1424 ELSE
1425 -- neither defined at org level or user level use db seq
1426 l_seq_source := l_from_db_seq;
1427 END IF;
1428
1429 l_progress := 'UCC128 validation';
1430 -- If any user defined values are not given, use values defined
1431 -- at the organization level
1432
1433 IF ( l_ucc_128_suffix_flag IS NULL ) THEN
1434 IF (l_seq_source = l_from_client) THEN
1435 l_ucc_128_suffix_flag := g_client_rec.client_rec.ucc_128_suffix_flag;
1436 ELSE
1437 l_ucc_128_suffix_flag := inv_cache.org_rec.ucc_128_suffix_flag;
1438 END IF;
1439 END IF;
1440
1441 IF ( l_lpn_prefix = FND_API.G_MISS_CHAR ) THEN
1442 l_lpn_prefix := NULL;
1443 ELSE
1444 IF (l_seq_source = l_from_client) THEN
1445 l_lpn_prefix := NVL(l_lpn_prefix, g_client_rec.client_rec.lpn_prefix);
1446 ELSE
1447 l_lpn_prefix := NVL(l_lpn_prefix, inv_cache.org_rec.lpn_prefix);
1448 END IF;
1449 END IF;
1450
1451 IF ( l_lpn_suffix = FND_API.G_MISS_CHAR ) THEN
1452 l_lpn_suffix := NULL;
1453 ELSE
1454 IF (l_seq_source = l_from_client) THEN
1455 l_lpn_suffix := NVL(l_lpn_suffix, g_client_rec.client_rec.lpn_suffix );
1456 ELSE
1457 l_lpn_suffix := NVL(l_lpn_suffix, inv_cache.org_rec.lpn_suffix );
1458 END IF;
1459 END IF;
1460
1461 IF ( l_total_lpn_length = FND_API.G_MISS_NUM ) THEN
1462 l_total_lpn_length := NULL;
1463 ELSE
1464 IF (l_seq_source = l_from_client) THEN
1465 l_total_lpn_length := NVL(l_total_lpn_length, g_client_rec.client_rec.total_lpn_length);
1466 ELSE
1467 l_total_lpn_length := NVL(l_total_lpn_length, inv_cache.org_rec.total_lpn_length);
1468 END IF;
1469 END IF;
1470
1471 IF ( l_ucc_128_suffix_flag = 'Y' ) THEN
1472 BEGIN
1473 l_dummy_number := to_number(l_lpn_prefix);
1474 EXCEPTION
1475 WHEN OTHERS THEN
1476 IF (l_debug = 1) THEN
1477 mdebug('LPN prefix is invalid: ' || l_lpn_prefix, G_ERROR);
1478 END IF;
1479 fnd_message.set_name('INV', 'INV_INTEGER_GREATER_THAN_0');
1480 fnd_message.set_token('ENTITY1','INV_LPN_PREFIX');
1481 fnd_msg_pub.ADD;
1482 RAISE fnd_api.g_exc_error;
1483 END;
1484 END IF;
1485
1486 IF ( l_total_lpn_length IS NOT NULL ) THEN
1487 l_lpn_seq_length := l_total_lpn_length - NVL(LENGTH(l_lpn_prefix), 0);
1488
1489 -- UCC128 uses a check digit in place of suffix. subtract one for that digit
1490 IF ( l_ucc_128_suffix_flag = 'Y' ) THEN
1491 l_lpn_seq_length := l_lpn_seq_length - 1;
1492 ELSE
1493 l_lpn_seq_length := l_lpn_seq_length - NVL(LENGTH(l_lpn_suffix), 0);
1494 END IF;
1495
1496 IF ( l_lpn_seq_length <= 0 ) THEN
1497 IF (l_debug = 1) THEN
1498 mdebug('total length '||l_total_lpn_length||' less than sum length of prefix '||l_lpn_prefix||' and suffix '||l_lpn_suffix, G_ERROR);
1499 END IF;
1500 fnd_message.set_name('WMS', 'WMS_LPN_TOTAL_LENGTH_INVALID');
1501 fnd_msg_pub.ADD;
1502 RAISE fnd_api.g_exc_error;
1503 END IF;
1504 ELSE
1505 l_lpn_seq_length := 0;
1506 END IF;
1507
1508 l_progress := 'Checking for serial numbers';
1509
1510 IF ( p_serial_ranges.last > 0 AND p_serial_ranges(1).fm_serial_number IS NOT NULL ) THEN
1511 -- Check that item is under serial control
1512 IF ( p_lpn_attributes.inventory_item_id IS NULL OR inv_cache.item_rec.serial_number_control_code = 1 ) THEN
1513 IF (l_debug = 1) THEN
1514 mdebug('Item '||inv_cache.item_rec.inventory_item_id||' is not serial controlled', G_ERROR);
1515 END IF;
1516 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_SER');
1517 fnd_msg_pub.ADD;
1518 RAISE fnd_api.g_exc_error;
1519 END IF;
1520
1521 -- For now only support a single range of serial numbers
1522 l_serial_rec.fm_serial_number := p_serial_ranges(1).fm_serial_number;
1523 l_serial_rec.to_serial_number := NVL(p_serial_ranges(1).to_serial_number, p_serial_ranges(1).fm_serial_number);
1524 l_current_serial := l_serial_rec.fm_serial_number;
1525
1526 l_progress := 'Call this API to inv_serial_info';
1527
1528 IF ( NOT mtl_serial_check.inv_serial_info (
1529 p_from_serial_number => l_serial_rec.fm_serial_number
1530 , p_to_serial_number => l_serial_rec.to_serial_number
1531 , x_prefix => l_serial_rec.prefix
1532 , x_quantity => l_serial_rec.quantity
1533 , x_from_number => l_serial_rec.fm_number
1534 , x_to_number => l_serial_rec.to_number
1535 , x_errorcode => l_dummy_number ) )
1536 THEN
1537 IF (l_debug = 1) THEN
1538 mdebug(l_serial_rec.to_serial_number||' failed INV_Serial_Info x_errorcode='||l_dummy_number, G_ERROR);
1539 END IF;
1540 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_SER');
1541 fnd_msg_pub.ADD;
1542 RAISE fnd_api.g_exc_error;
1543 END IF;
1544
1545 -- Quantity of LPNs will be determined by serial range
1546 l_quantity := l_serial_rec.quantity;
1547 l_current_serial := l_serial_rec.fm_serial_number;
1548 l_current_number := l_serial_rec.fm_number;
1549
1550 IF (l_debug = 1) THEN
1551 mdebug('SN info qty='||l_quantity||' pfx='||l_serial_rec.prefix||' fm#='||l_serial_rec.fm_number||' to#='||l_serial_rec.to_number, G_INFO);
1552 END IF;
1553 ELSE
1554 l_current_serial := NULL;
1555 END IF;
1556
1557 IF (l_debug = 1) THEN
1558 mdebug('prefix='||l_lpn_prefix||' suffix='||l_lpn_suffix||' seq='||l_curr_seq||' suffix flag='||l_ucc_128_suffix_flag, G_INFO);
1559 END IF;
1560
1561 l_loop_cnt := 1;
1562 l_lpn_cnt := 1;
1563
1564 WHILE ( l_lpn_cnt <= l_quantity ) LOOP
1565
1566 IF ( l_seq_source = l_from_db_seq ) THEN
1567 SELECT wms_license_plate_numbers_s2.NEXTVAL
1568 INTO l_curr_seq
1569 FROM DUAL;
1570 ELSIF ( l_seq_source = l_from_client ) THEN
1571 -- If taken from client parameters make sure the new seq is within the range
1572 -- already allocated, if not will need to allocate more
1573 IF ( l_curr_seq IS NULL OR l_curr_seq = l_last_client_seq ) THEN
1574 Get_Upd_Client_LPN_Start_Num (
1575 p_client_id => g_client_rec.client_rec.client_id
1576 , p_qty => l_quantity - l_lpn_cnt + 1
1577 , x_curr_seq => l_curr_seq );
1578
1579 -- Keep track of the last sequence fetched from the org params
1580 l_last_client_seq := l_curr_seq + l_quantity - l_lpn_cnt + 1;
1581 IF (l_debug = 1) THEN
1582 mdebug('Got seq from client curr_seq='||l_curr_seq||' l_last_client_seq='||l_last_client_seq, G_INFO);
1583 END IF;
1584 END IF;
1585 ELSIF ( l_seq_source = l_from_org ) THEN
1586 -- If taken from org parameters make sure the new seq is within the range
1587 -- already allocated, if not will need to allocate more
1588 IF ( l_curr_seq IS NULL OR l_curr_seq = l_last_org_seq ) THEN
1589 Get_Update_LPN_Start_Num (
1590 p_org_id => p_lpn_attributes.organization_id
1591 , p_qty => l_quantity - l_lpn_cnt + 1
1592 , x_curr_seq => l_curr_seq );
1593
1594 -- Keep track of the last sequence fetched from the org params
1595 l_last_org_seq := l_curr_seq + l_quantity - l_lpn_cnt + 1;
1596 IF (l_debug = 1) THEN
1597 mdebug('Got seq from org curr_seq='||l_curr_seq||' last_org_seq='||l_last_org_seq, G_INFO);
1598 END IF;
1599 END IF;
1600 END IF;
1601
1602 -- Generate a valid license plate number
1603 l_lpn_tab(l_lpn_cnt).license_plate_number := l_lpn_prefix || LPAD(l_curr_seq, GREATEST(length(l_curr_seq), l_lpn_seq_length), '0');
1604
1605 IF ( l_ucc_128_suffix_flag = 'Y' ) THEN
1606 l_progress := 'Call api to calculate and append check digit to end of LPN';
1607 l_lpn_tab(l_lpn_cnt).license_plate_number := l_lpn_tab(l_lpn_cnt).license_plate_number || Generate_Check_Digit(l_debug, l_lpn_tab(l_lpn_cnt).license_plate_number);
1608 ELSE
1609 l_progress := 'Not UCC128 LPN normal LPN name generatation';
1610 l_lpn_tab(l_lpn_cnt).license_plate_number := l_lpn_tab(l_lpn_cnt).license_plate_number || l_lpn_suffix;
1611 END IF;
1612
1613 l_progress := 'Check that new LPN does not alreay exist in WLPN';
1614
1615 BEGIN
1616 SELECT 1
1617 INTO l_dummy_number
1618 FROM WMS_LICENSE_PLATE_NUMBERS
1619 WHERE license_plate_number = l_lpn_tab(l_lpn_cnt).license_plate_number;
1620 EXCEPTION
1621 WHEN NO_DATA_FOUND THEN
1622 l_dummy_number := 2;
1623 END;
1624
1625 IF ( l_dummy_number <> 1 ) THEN
1626 l_progress := 'LPN does not exist yet insert into LPN table';
1627
1628 -- Validate LPN total length if total length is passed.
1629 IF ( l_total_lpn_length < length(l_lpn_tab(l_lpn_cnt).license_plate_number) ) THEN
1630 IF (l_debug = 1) THEN
1631 mdebug('LPN name '||l_lpn_tab(l_lpn_cnt).license_plate_number||' exceeds total length '||l_total_lpn_length, G_ERROR);
1632 END IF;
1633 fnd_message.set_name('WMS', 'WMS_LPN_TOTAL_LENGTH_INVALID');
1634 fnd_msg_pub.ADD;
1635 RAISE fnd_api.g_exc_error;
1636 END IF;
1637
1638 l_progress := 'Insert the newly created lpn id/license plate number record into the table';
1639
1640 l_lpn_tab(l_lpn_cnt).lpn_context := p_lpn_attributes.lpn_context;
1641 l_lpn_tab(l_lpn_cnt).organization_id := p_lpn_attributes.organization_id;
1642 l_lpn_tab(l_lpn_cnt).subinventory_code := p_lpn_attributes.subinventory_code;
1643 l_lpn_tab(l_lpn_cnt).locator_id := p_lpn_attributes.locator_id;
1644
1645 l_lpn_tab(l_lpn_cnt).inventory_item_id := p_lpn_attributes.inventory_item_id;
1646 l_lpn_tab(l_lpn_cnt).revision := p_lpn_attributes.revision;
1647 l_lpn_tab(l_lpn_cnt).lot_number := p_lpn_attributes.lot_number;
1648 l_lpn_tab(l_lpn_cnt).serial_number := l_current_serial;
1649 l_lpn_tab(l_lpn_cnt).cost_group_id := p_lpn_attributes.cost_group_id;
1650
1651 l_lpn_tab(l_lpn_cnt).source_type_id := p_lpn_attributes.source_type_id;
1652 l_lpn_tab(l_lpn_cnt).source_header_id := p_lpn_attributes.source_header_id;
1653 l_lpn_tab(l_lpn_cnt).source_line_id := p_lpn_attributes.source_line_id;
1654 l_lpn_tab(l_lpn_cnt).source_line_detail_id := p_lpn_attributes.source_line_detail_id;
1655 l_lpn_tab(l_lpn_cnt).source_name := p_lpn_attributes.source_name;
1656 l_lpn_tab(l_lpn_cnt).source_transaction_id := p_lpn_attributes.source_transaction_id;
1657
1658 IF (l_debug = 1) THEN
1659 mdebug('Created LPN name '||l_lpn_tab(l_lpn_cnt).license_plate_number||' lpn_cnt='||l_lpn_cnt||' curr_seq='||l_curr_seq||' loop_cnt='||l_loop_cnt, G_INFO);
1660 END IF;
1661
1662 l_progress := 'Increment the current serial number';
1663
1664 IF ( l_current_serial IS NOT NULL ) THEN
1665 l_padded_length := LENGTH(l_current_serial) - LENGTH(l_current_number);
1666 l_current_number := l_current_number + 1;
1667
1668 -- See bug 2375043 for info on why this is done
1669 IF ( l_serial_rec.prefix IS NOT NULL ) THEN
1670 l_current_serial := RPAD(l_serial_rec.prefix, l_padded_length, '0') || l_current_number;
1671 ELSE
1672 l_current_serial := RPAD('@',l_padded_length+1,'0') || l_current_number;
1673 l_current_serial := Substr(l_current_serial,2);
1674 END IF;
1675 END IF;
1676
1677 l_progress := 'Done creating LPN name increment counter';
1678 l_lpn_cnt := l_lpn_cnt + 1;
1679 ELSE -- LPN already exists in WLPN
1680 IF ( l_seq_source = l_from_user ) THEN
1681 IF ( l_debug = 1 ) THEN
1682 mdebug('Cannot generate LPNs with user defined starting number', G_ERROR);
1683 END IF;
1684 fnd_message.set_name('WMS', 'WMS_CONT_DUPLICATE_LPN');
1685 fnd_message.set_token('LPN', l_lpn_tab(l_lpn_cnt).license_plate_number);
1686 fnd_msg_pub.ADD;
1687 RAISE fnd_api.g_exc_error;
1688 ELSIF ( l_loop_cnt > l_quantity + 1000 ) THEN
1689 IF ( l_debug = 1 ) THEN
1690 mdebug('Cannot find valid LPN sequence after 1000 Attempts', G_ERROR);
1691 END IF;
1692 fnd_message.set_name('WMS', 'WMS_GEN_LPN_LOOP_ERR');
1693 fnd_message.set_token('NUM', '1000');
1694 fnd_msg_pub.ADD;
1695 RAISE fnd_api.g_exc_error;
1696 ELSIF ( l_debug = 1 ) THEN
1697 mdebug('LPN '||l_lpn_tab(l_lpn_cnt).license_plate_number||' already exists trying new sequence', G_INFO);
1698 END IF;
1699 END IF;
1700
1701 -- If LPN sequence is not taken from DB, need to incrament manually
1702 l_curr_seq := l_curr_seq + 1;
1703
1704 -- Keep track of total number of loops done to avoid infinite loop
1705 l_loop_cnt := l_loop_cnt + 1;
1706 END LOOP;
1707
1708 l_progress := 'Call Create_LPNs number of rec='||l_lpn_tab.last;
1709
1710 Create_LPNs (
1711 p_api_version => p_api_version
1712 , p_init_msg_list => fnd_api.g_false
1713 , p_commit => fnd_api.g_false
1714 , x_return_status => x_return_status
1715 , x_msg_count => x_msg_count
1716 , x_msg_data => x_msg_data
1717 , p_caller => p_caller
1718 , p_lpn_table => l_lpn_tab );
1719
1720 IF ( x_return_status <> fnd_api.g_ret_sts_success ) THEN
1721 IF (l_debug = 1) THEN
1722 mdebug('Create_LPNs failed', G_ERROR);
1723 END IF;
1724 RAISE fnd_api.g_exc_error;
1725 END IF;
1726
1727 x_created_lpns := l_lpn_tab;
1728
1729 -- Standard check of p_commit.
1730 IF fnd_api.to_boolean(p_commit) THEN
1731 COMMIT WORK;
1732 END IF;
1733
1734 -- Standard call to get message count and data
1735 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
1736 EXCEPTION
1737 WHEN FND_API.G_EXC_ERROR THEN
1738 x_return_status := fnd_api.g_ret_sts_error;
1739 FND_MSG_PUB.Count_And_Get(p_count => x_msg_count, p_data => x_msg_data);
1740 IF (l_debug = 1) THEN
1741 FOR i in 1..x_msg_count LOOP
1742 l_msgdata := substr(l_msgdata||' | '||substr(fnd_msg_pub.get(x_msg_count-i+1, 'F'), 0, 200),1,2000);
1743 END LOOP;
1744 mdebug(l_api_name ||' Error progress='||l_progress||' SQL error: '|| SQLERRM(SQLCODE), G_ERROR);
1745 mdebug('msg: '||l_msgdata, G_ERROR);
1746 END IF;
1747 ROLLBACK TO AUTO_CREATE_LPNS_PVT;
1748 WHEN OTHERS THEN
1749 x_return_status := fnd_api.g_ret_sts_unexp_error;
1750 fnd_message.set_name('WMS', 'WMS_LPN_GENERATION_FAIL');
1751 fnd_msg_pub.ADD;
1752 FND_MSG_PUB.Count_And_Get(p_count => x_msg_count, p_data => x_msg_data);
1753 IF (l_debug = 1) THEN
1754 mdebug(l_api_name ||' Error progress='||l_progress||' SQL error: '|| SQLERRM(SQLCODE), G_ERROR);
1755 END IF;
1756 ROLLBACK TO AUTO_CREATE_LPNS_PVT;
1757 END Auto_Create_LPNs;
1758
1759
1760
1761
1762 -- ----------------------------------------------------------------------------------
1763 -- ----------------------------------------------------------------------------------
1764
1765 PROCEDURE Modify_LPNs (
1766 p_api_version IN NUMBER
1767 , p_init_msg_list IN VARCHAR2
1768 , p_commit IN VARCHAR2
1769 , x_return_status OUT NOCOPY VARCHAR2
1770 , x_msg_count OUT NOCOPY NUMBER
1771 , x_msg_data OUT NOCOPY VARCHAR2
1772 , p_caller IN VARCHAR2
1773 , p_lpn_table IN WMS_Data_Type_Definitions_PUB.LPNTableType
1774 ) IS
1775 l_api_name CONSTANT VARCHAR2(30) := 'Modify_LPNs';
1776 l_api_version CONSTANT NUMBER := 1.0;
1777 l_debug NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
1778 l_progress VARCHAR2(500) := 'Entered API';
1779 l_msgdata VARCHAR2(1000);
1780 l_delivery_id NUMBER ; --7119011
1781 l_status_code VARCHAR2(2) := 'OP'; --7119011 / 7603755
1782 l_return_status VARCHAR2(2); --7119011
1783
1784 CURSOR nested_parent_lpn_cursor (p_parent_lpn_id NUMBER) IS
1785 SELECT lpn_id
1786 , license_plate_number
1787 , parent_lpn_id
1788 , outermost_lpn_id
1789 , lpn_context
1790
1791 , organization_id
1792 , subinventory_code
1793 , locator_id
1794
1795 , inventory_item_id
1796 , revision
1797 , lot_number
1798 , serial_number
1799 , cost_group_id
1800
1801 , tare_weight_uom_code
1802 , tare_weight
1803 , gross_weight_uom_code
1804 , gross_weight
1805 , container_volume_uom
1806 , container_volume
1807 , content_volume_uom_code
1808 , content_volume
1809
1810 , source_type_id
1811 , source_header_id
1812 , source_line_id
1813 , source_line_detail_id
1814 , source_name
1815
1816 , attribute_category
1817 , attribute1
1818 , attribute2
1819 , attribute3
1820 , attribute4
1821 , attribute5
1822 , attribute6
1823 , attribute7
1824 , attribute8
1825 , attribute9
1826 , attribute10
1827 , attribute11
1828 , attribute12
1829 , attribute13
1830 , attribute14
1831 , attribute15
1832 FROM wms_license_plate_numbers
1833 START WITH lpn_id = p_parent_lpn_id
1834 CONNECT BY lpn_id = PRIOR parent_lpn_id
1835 FOR UPDATE NOWAIT;
1836
1837 CURSOR nested_child_lpn_cursor (p_lpn_id NUMBER) IS
1838 SELECT /*+ optimizer_features_enable('10.2.0.2') */ lpn_id -- added hint for bug 12885396
1839 , license_plate_number
1840 , parent_lpn_id
1841 , outermost_lpn_id
1842 , lpn_context
1843
1844 , organization_id
1845 , subinventory_code
1846 , locator_id
1847
1848 , inventory_item_id
1849 , revision
1850 , lot_number
1851 , serial_number
1852 , cost_group_id
1853
1854 , tare_weight_uom_code
1855 , tare_weight
1856 , gross_weight_uom_code
1857 , gross_weight
1858 , container_volume_uom
1859 , container_volume
1860 , content_volume_uom_code
1861 , content_volume
1862
1863 , source_type_id
1864 , source_header_id
1865 , source_line_id
1866 , source_line_detail_id
1867 , source_name
1868
1869 , attribute_category
1870 , attribute1
1871 , attribute2
1872 , attribute3
1873 , attribute4
1874 , attribute5
1875 , attribute6
1876 , attribute7
1877 , attribute8
1878 , attribute9
1879 , attribute10
1880 , attribute11
1881 , attribute12
1882 , attribute13
1883 , attribute14
1884 , attribute15
1885 FROM wms_license_plate_numbers
1886 START WITH parent_lpn_id = p_lpn_id
1887 CONNECT BY parent_lpn_id = PRIOR lpn_id
1888 FOR UPDATE NOWAIT;
1889
1890 --Bug #3516547
1891 CURSOR lpn_item_control_cursor (p_old_org_id NUMBER, p_new_org_id NUMBER, p_outermost_lpn_id NUMBER) IS
1892 SELECT wlc.rowid
1893 , wlc.inventory_item_id
1894 , msi.primary_uom_code
1895 , msi.serial_number_control_code
1896 , msi.lot_control_code
1897 , msi.revision_qty_control_code
1898 FROM wms_license_plate_numbers wlpn
1899 , wms_lpn_contents wlc
1900 , mtl_system_items msi
1901 WHERE wlpn.organization_id = p_old_org_id
1902 AND wlpn.outermost_lpn_id = p_outermost_lpn_id
1903 AND wlc.parent_lpn_id = wlpn.lpn_id
1904 AND msi.inventory_item_id = wlc.inventory_item_id
1905 AND msi.organization_id = p_new_org_id
1906 ORDER BY wlc.inventory_item_id;
1907 --End of changes for Bug #3516547
1908
1909 -- Types needed for WSH_WMS_LPN_GRP.Create_Update_Containers
1910 wsh_update_tbl WSH_Glbl_Var_Strct_GRP.delivery_details_Attr_tbl_Type;
1911 wsh_create_tbl WSH_Glbl_Var_Strct_GRP.delivery_details_Attr_tbl_Type;
1912 l_IN_rec WSH_GLBL_VAR_STRCT_GRP.detailInRecType;
1913 l_OUT_rec WSH_GLBL_VAR_STRCT_GRP.detailOutRecType;
1914
1915 -- Types needed for WSH_WMS_LPN_GRP.Delivery_Detail_Action
1916 l_wsh_del_det_id_tbl wsh_util_core.id_tab_type;
1917 l_wsh_action_prms WSH_GLBL_VAR_STRCT_GRP.dd_action_parameters_rec_type;
1918 l_wsh_defaults WSH_GLBL_VAR_STRCT_GRP.dd_default_parameters_rec_type;
1919 l_wsh_action_out_rec WSH_GLBL_VAR_STRCT_GRP.dd_action_out_rec_type;
1920
1921 -- Types needed for WSH_WMS_LPN_GRP.Delivery_Detail_Action
1922 -- Need 2 different tables one for lpns that need to be unpacked one for
1923 -- lpns thatn need to be deleted
1924 l_wsh_unpack_lpn_id_tbl wsh_util_core.id_tab_type;
1925 l_wsh_delete_lpn_id_tbl wsh_util_core.id_tab_type;
1926
1927 -- Variables used to store LPN information
1928 l_lpn_ids WMS_Data_Type_Definitions_PUB.NumberTableType;
1929 l_outer_lpn_ids WMS_Data_Type_Definitions_PUB.NumberTableType;
1930
1931 l_lpn_tab_i NUMBER;
1932 l_tmp_i NUMBER;
1933 l_dummy_num NUMBER;
1934
1935 l_tmp_new WMS_Data_Type_Definitions_PUB.LPNRecordType;
1936 l_tmp_old WMS_Data_Type_Definitions_PUB.LPNRecordType;
1937 l_new WMS_Data_Type_Definitions_PUB.LPNRecordType;
1938 l_old WMS_Data_Type_Definitions_PUB.LPNRecordType;
1939 l_lpns WMS_Data_Type_Definitions_PUB.LPNTableType;
1940 l_outer_lpns WMS_Data_Type_Definitions_PUB.LPNTableType;
1941 l_lpn_bulk_rec LPNBulkRecType;
1942
1943 -- Temp variables needed for wt/vol calculation
1944 l_change_in_gross_weight NUMBER;
1945 l_change_in_gross_weight_uom VARCHAR2(3);
1946
1947 l_change_in_weight NUMBER; --Added for Bug#6504032
1948 l_change_in_weight_uom VARCHAR2(3); --Added for Bug#6504032
1949
1950 -- bug5404902 added to store tare weight change
1951 l_change_in_tare_weight NUMBER;
1952 l_change_in_tare_weight_uom VARCHAR2(3);
1953 l_outer_lpn_tare_change NUMBER;
1954
1955 l_change_in_volume NUMBER;
1956 l_change_in_volume_uom VARCHAR2(3);
1957
1958 --Flag added to identify LPN context change from 'Loaded to Truck' to
1959 --'Defined but not used' which is only for Internal Orders
1960 --Bug number 5639121
1961 l_internal_order_flag NUMBER := 0;
1962 --Bug 8693053
1963 honor_case_pick_count NUMBER := 0;
1964
1965 BEGIN
1966 -- Standard Start of API savepoint
1967 SAVEPOINT MODIFY_LPNS_PVT;
1968
1969 -- Standard call to check for call compatibility.
1970 IF NOT fnd_api.compatible_api_call(l_api_version, p_api_version, l_api_name, g_pkg_name) THEN
1971 fnd_message.set_name('WMS', 'WMS_CONT_INCOMPATIBLE_API_CALL');
1972 fnd_msg_pub.ADD;
1973 RAISE fnd_api.g_exc_unexpected_error;
1974 END IF;
1975
1976 -- Initialize message list if p_init_msg_list is set to TRUE.
1977 IF fnd_api.to_boolean(p_init_msg_list) THEN
1978 fnd_msg_pub.initialize;
1979 END IF;
1980
1981 -- Initialize API return status to success
1982 x_return_status := fnd_api.g_ret_sts_success;
1983
1984 -- API body
1985 IF (l_debug = 1) THEN
1986 mdebug(l_api_name || ' Entered ' || g_pkg_version, 1);
1987 mdebug('ver='||p_api_version||' initmsg='||p_init_msg_list||' commit='||p_commit||' caller='||p_caller||' tabfst='||p_lpn_table.first||' tablst='||p_lpn_table.last, G_INFO);
1988 END IF;
1989
1990 FOR lpn_tbl_cnt IN p_lpn_table.first .. p_lpn_table.last LOOP
1991 IF (l_debug = 1) THEN
1992 l_old := p_lpn_table(lpn_tbl_cnt);
1993
1994 l_old.lpn_id := l_old.lpn_id;
1995 l_old.license_plate_number := l_old.license_plate_number;
1996 l_old.parent_lpn_id := substr(l_old.parent_lpn_id, 1, 10);
1997 l_old.outermost_lpn_id := l_old.outermost_lpn_id;
1998 l_old.lpn_context := l_old.lpn_context;
1999
2000 l_old.organization_id := l_old.organization_id;
2001 l_old.subinventory_code := substr(l_old.subinventory_code, 1, 10);
2002 l_old.locator_id := substr(l_old.locator_id, 1, 10);
2003
2004 l_old.inventory_item_id := substr(l_old.inventory_item_id, 1, 10);
2005 l_old.revision := substr(l_old.revision, 1, 10);
2006 l_old.lot_number := substr(l_old.lot_number, 1, 10);
2007 l_old.serial_number := substr(l_old.serial_number, 1, 10);
2008 l_old.cost_group_id := substr(l_old.cost_group_id, 1, 10);
2009
2010 l_old.tare_weight_uom_code := substr(l_old.tare_weight_uom_code, 1, 10);
2011 l_old.tare_weight := substr(l_old.tare_weight, 1, 10);
2012 l_old.gross_weight_uom_code := substr(l_old.gross_weight_uom_code, 1, 10);
2013 l_old.gross_weight := substr(l_old.gross_weight, 1, 10);
2014 l_old.container_volume_uom := substr(l_old.container_volume_uom, 1, 10);
2015 l_old.container_volume := substr(l_old.container_volume, 1, 10);
2016 l_old.content_volume_uom_code := substr(l_old.content_volume_uom_code, 1, 10);
2017 l_old.content_volume := substr(l_old.content_volume, 1, 10);
2018
2019 l_old.source_type_id := substr(l_old.source_type_id, 1, 10);
2020 l_old.source_header_id := substr(l_old.source_header_id, 1, 10);
2021 l_old.source_line_id := substr(l_old.source_line_id, 1, 10);
2022 l_old.source_line_detail_id := substr(l_old.source_line_detail_id, 1, 10);
2023 l_old.source_name := l_old.source_name;
2024
2025 l_old.attribute_category := substr(l_old.attribute_category, 1, 10);
2026 l_old.attribute1 := substr(l_old.attribute1, 1, 10);
2027 l_old.attribute2 := substr(l_old.attribute2, 1, 10);
2028 l_old.attribute3 := substr(l_old.attribute3, 1, 10);
2029 l_old.attribute4 := substr(l_old.attribute4, 1, 10);
2030 l_old.attribute5 := substr(l_old.attribute5, 1, 10);
2031 l_old.attribute6 := substr(l_old.attribute6, 1, 10);
2032 l_old.attribute7 := substr(l_old.attribute7, 1, 10);
2033 l_old.attribute8 := substr(l_old.attribute8, 1, 10);
2034 l_old.attribute9 := substr(l_old.attribute9, 1, 10);
2035 l_old.attribute10 := substr(l_old.attribute10, 1, 10);
2036 l_old.attribute11 := substr(l_old.attribute11, 1, 10);
2037 l_old.attribute12 := substr(l_old.attribute12, 1, 10);
2038 l_old.attribute13 := substr(l_old.attribute13, 1, 10);
2039 l_old.attribute14 := substr(l_old.attribute14, 1, 10);
2040 l_old.attribute15 := substr(l_old.attribute15, 1, 10);
2041
2042 mdebug('-------------------------------------------------');
2043 mdebug('Values passed by caller to be updated l_lpn_tab_i='||l_lpn_tab_i||' lpn_tbl_cnt='||lpn_tbl_cnt, G_INFO);
2044 mdebug('lpnid='||l_old.lpn_id||' lpn='||l_old.license_plate_number||' ctx='||l_old.lpn_context||' plpn='||l_old.parent_lpn_id||' olpn='||l_old.outermost_lpn_id||' itm='||l_old.inventory_item_id||' rev='||l_old.revision, G_INFO);
2045 mdebug('lot='||l_old.lot_number||' sn='||l_old.serial_number||' cg='||l_old.cost_group_id||' org='||l_old.organization_id||' sub='||l_old.subinventory_code||' loc='||l_old.locator_id, G_INFO);
2046 mdebug('twt='||l_old.tare_weight||' twuom='||l_old.tare_weight_uom_code||' gwt='||l_old.gross_weight||' gwuom='||l_old.gross_weight_uom_code||
2047 ' ctrvol='||l_old.container_volume||' ctrvoluom='||l_old.container_volume_uom||' ctnvol='||l_old.content_volume||' ctvuom='||l_old.content_volume_uom_code, G_INFO);
2048 mdebug('stype='||l_old.source_type_id||' shdr='||l_old.source_header_id||' srcln='||l_old.source_line_id||' srclndt='||l_old.source_line_detail_id||' srcnm='||l_old.source_name, G_INFO);
2049 --mdebug('reuse='||l_old.lpn_reusability||' hom='||l_old.homogeneous_container||' stat='||l_old.status_id ||' seal='||l_old.sealed_status, G_INFO);
2050 mdebug('acat='||l_old.attribute_category||' a1='||l_old.attribute1||' a2='||l_old.attribute2||' a3='||l_old.attribute3||' a4='||l_old.attribute4||' a5='||l_old.attribute5||' a6='||l_old.attribute6||' a7='||l_old.attribute7, G_INFO);
2051 mdebug('a8='||l_old.attribute8||' a9='||l_old.attribute9||' a10='||l_old.attribute10||' a11='||l_old.attribute11||' a12='||l_old.attribute12||' a13='||l_old.attribute13||' a14='||l_old.attribute14||' a15='||l_old.attribute15, G_INFO);
2052 mdebug('-------------------------------------------------');
2053 END IF;
2054
2055 l_progress := 'Validate and massage data given by user lpnid='||p_lpn_table(lpn_tbl_cnt).lpn_id;
2056
2057 -- General validations for data protection
2058 IF ( p_lpn_table(lpn_tbl_cnt).outermost_lpn_id IS NOT NULL ) THEN
2059 -- Specific validations of attributes limited to certain callers
2060 IF ( NVL(p_caller, G_NULL_CHAR) <> 'WMS_PackUnpack_Container' ) THEN
2061 l_progress := 'Updating outermost_lpn_id is restricted to PackUnpack_Container API';
2062 fnd_message.set_name('WMS', 'WMS_UPDATE_LPN_ATTR_ERR');
2063 fnd_message.set_token('ATTR', 'outermost_lpn_id');
2064 fnd_msg_pub.ADD;
2065 RAISE fnd_api.g_exc_error;
2066 END IF;
2067 END IF;
2068
2069 l_progress := 'Done with general validation';
2070
2071 IF ( l_lpn_ids.exists(p_lpn_table(lpn_tbl_cnt).lpn_id) ) THEN
2072 IF (l_debug = 1) THEN
2073 mdebug('LPN attributes already exist in table lpnid='||p_lpn_table(lpn_tbl_cnt).lpn_id, G_INFO);
2074 END IF;
2075 l_lpn_tab_i := l_lpn_ids(p_lpn_table(lpn_tbl_cnt).lpn_id);
2076 l_old := l_lpns(l_lpn_tab_i);
2077 ELSE
2078 IF (l_debug = 1) THEN
2079 mdebug('Retrieve attributes of LPN lpnid='||p_lpn_table(lpn_tbl_cnt).lpn_id, G_INFO);
2080 END IF;
2081 l_lpn_tab_i := NULL;
2082
2083 BEGIN
2084 SELECT lpn_id
2085 , license_plate_number
2086 , parent_lpn_id
2087 , outermost_lpn_id
2088 , lpn_context
2089
2090 , organization_id
2091 , subinventory_code
2092 , locator_id
2093
2094 , inventory_item_id
2095 , revision
2096 , lot_number
2097 , serial_number
2098 , cost_group_id
2099
2100 , tare_weight_uom_code
2101 , tare_weight
2102 , gross_weight_uom_code
2103 , gross_weight
2104 , container_volume_uom
2105 , container_volume
2106 , content_volume_uom_code
2107 , content_volume
2108
2109 , source_type_id
2110 , source_header_id
2111 , source_line_id
2112 , source_line_detail_id
2113 , source_name
2114
2115 , attribute_category
2116 , attribute1
2117 , attribute2
2118 , attribute3
2119 , attribute4
2120 , attribute5
2121 , attribute6
2122 , attribute7
2123 , attribute8
2124 , attribute9
2125 , attribute10
2126 , attribute11
2127 , attribute12
2128 , attribute13
2129 , attribute14
2130 , attribute15
2131 INTO l_old.lpn_id
2132 , l_old.license_plate_number
2133 , l_old.parent_lpn_id
2134 , l_old.outermost_lpn_id
2135 , l_old.lpn_context
2136
2137 , l_old.organization_id
2138 , l_old.subinventory_code
2139 , l_old.locator_id
2140
2141 , l_old.inventory_item_id
2142 , l_old.revision
2143 , l_old.lot_number
2144 , l_old.serial_number
2145 , l_old.cost_group_id
2146
2147 , l_old.tare_weight_uom_code
2148 , l_old.tare_weight
2149 , l_old.gross_weight_uom_code
2150 , l_old.gross_weight
2151 , l_old.container_volume_uom
2152 , l_old.container_volume
2153 , l_old.content_volume_uom_code
2154 , l_old.content_volume
2155
2156 , l_old.source_type_id
2157 , l_old.source_header_id
2158 , l_old.source_line_id
2159 , l_old.source_line_detail_id
2160 , l_old.source_name
2161
2162 , l_old.attribute_category
2163 , l_old.attribute1
2164 , l_old.attribute2
2165 , l_old.attribute3
2166 , l_old.attribute4
2167 , l_old.attribute5
2168 , l_old.attribute6
2169 , l_old.attribute7
2170 , l_old.attribute8
2171 , l_old.attribute9
2172 , l_old.attribute10
2173 , l_old.attribute11
2174 , l_old.attribute12
2175 , l_old.attribute13
2176 , l_old.attribute14
2177 , l_old.attribute15
2178 FROM wms_license_plate_numbers
2179 WHERE lpn_id = p_lpn_table(lpn_tbl_cnt).lpn_id;
2180 EXCEPTION
2181 WHEN NO_DATA_FOUND THEN
2182 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_LPN');
2183 fnd_msg_pub.ADD;
2184 RAISE fnd_api.g_exc_error;
2185 END;
2186
2187 l_progress := 'Done getting LPN attributes, Add LPN to hash table';
2188 END IF;
2189
2190 -- Store Original attributes
2191 l_new := l_old;
2192
2193 IF (l_debug = 1) THEN
2194 mdebug('Old values from LPN to be updated l_lpn_tab_i='||l_lpn_tab_i||' lpn_tbl_cnt='||lpn_tbl_cnt, G_INFO);
2195 mdebug('lpnid='||l_old.lpn_id||' lpn='||l_old.license_plate_number||' ctx='||l_old.lpn_context||' plpn='||l_old.parent_lpn_id||' olpn='||l_old.outermost_lpn_id||' itm='||l_old.inventory_item_id||' rev='||l_old.revision, G_INFO);
2196 mdebug('lot='||l_old.lot_number||' sn='||l_old.serial_number||' cg='||l_old.cost_group_id||' org='||l_old.organization_id||' sub='||l_old.subinventory_code||' loc='||l_old.locator_id, G_INFO);
2197 mdebug('twt='||l_old.tare_weight||' twuom='||l_old.tare_weight_uom_code||' gwt='||l_old.gross_weight||' gwuom='||l_old.gross_weight_uom_code||
2198 ' ctrvol='||l_old.container_volume||' ctrvoluom='||l_old.container_volume_uom||' ctnvol='||l_old.content_volume||' ctvuom='||l_old.content_volume_uom_code, G_INFO);
2199 mdebug('stype='||l_old.source_type_id||' shdr='||l_old.source_header_id||' srcln='||l_old.source_line_id||' srclndt='||l_old.source_line_detail_id||' srcnm='||l_old.source_name, G_INFO);
2200 --mdebug('reuse='||l_old.lpn_reusability||' hom='||l_old.homogeneous_container||' stat='||l_old.status_id ||' seal='||l_old.sealed_status, G_INFO);
2201 mdebug('acat='||l_old.attribute_category||' a1='||l_old.attribute1||' a2='||l_old.attribute2||' a3='||l_old.attribute3||' a4='||l_old.attribute4||' a5='||l_old.attribute5||' a6='||l_old.attribute6||' a7='||l_old.attribute7, G_INFO);
2202 mdebug('a8='||l_old.attribute8||' a9='||l_old.attribute9||' a10='||l_old.attribute10||' a11='||l_old.attribute11||' a12='||l_old.attribute12||' a13='||l_old.attribute13||' a14='||l_old.attribute14||' a15='||l_old.attribute15, G_INFO);
2203 END IF;
2204
2205 l_progress := 'Start of section to massage data';
2206
2207 -- List of attributes that pertain to the LPN itself and not to the
2208 -- entire hierarchy
2209 IF ( p_lpn_table(lpn_tbl_cnt).license_plate_number <> NVL(l_old.license_plate_number, FND_API.G_MISS_CHAR) OR
2210 p_lpn_table(lpn_tbl_cnt).parent_lpn_id <> NVL(l_old.parent_lpn_id, FND_API.G_MISS_NUM) OR
2211 Nvl(p_lpn_table(lpn_tbl_cnt).inventory_item_id,0)<> NVL(l_old.inventory_item_id, FND_API.G_MISS_NUM) OR --Bug#6504032 Added nvl condition
2212 p_lpn_table(lpn_tbl_cnt).revision <> NVL(l_old.revision, FND_API.G_MISS_CHAR) OR
2213 p_lpn_table(lpn_tbl_cnt).lot_number <> NVL(l_old.lot_number, FND_API.G_MISS_CHAR) OR
2214 p_lpn_table(lpn_tbl_cnt).serial_number <> NVL(l_old.serial_number, FND_API.G_MISS_CHAR) OR
2215 p_lpn_table(lpn_tbl_cnt).cost_group_id <> NVL(l_old.cost_group_id, FND_API.G_MISS_NUM) OR
2216 p_lpn_table(lpn_tbl_cnt).tare_weight_uom_code <> NVL(l_old.tare_weight_uom_code, FND_API.G_MISS_CHAR) OR
2217 p_lpn_table(lpn_tbl_cnt).tare_weight <> NVL(l_old.tare_weight, FND_API.G_MISS_NUM) OR
2218 p_lpn_table(lpn_tbl_cnt).gross_weight_uom_code <> NVL(l_old.gross_weight_uom_code, FND_API.G_MISS_CHAR) OR
2219 p_lpn_table(lpn_tbl_cnt).gross_weight <> NVL(l_old.gross_weight, FND_API.G_MISS_NUM) OR
2220 p_lpn_table(lpn_tbl_cnt).container_volume_uom <> NVL(l_old.container_volume_uom, FND_API.G_MISS_CHAR) OR
2221 p_lpn_table(lpn_tbl_cnt).container_volume <> NVL(l_old.container_volume, FND_API.G_MISS_NUM) OR
2222 p_lpn_table(lpn_tbl_cnt).content_volume_uom_code <> NVL(l_old.content_volume_uom_code, FND_API.G_MISS_CHAR) OR
2223 p_lpn_table(lpn_tbl_cnt).content_volume <> NVL(l_old.content_volume, FND_API.G_MISS_NUM) OR
2224 p_lpn_table(lpn_tbl_cnt).attribute_category <> NVL(l_old.attribute_category, FND_API.G_MISS_CHAR) OR
2225 p_lpn_table(lpn_tbl_cnt).attribute1 <> NVL(l_old.attribute1, FND_API.G_MISS_CHAR) OR
2226 p_lpn_table(lpn_tbl_cnt).attribute2 <> NVL(l_old.attribute2, FND_API.G_MISS_CHAR) OR
2227 p_lpn_table(lpn_tbl_cnt).attribute3 <> NVL(l_old.attribute3, FND_API.G_MISS_CHAR) OR
2228 p_lpn_table(lpn_tbl_cnt).attribute4 <> NVL(l_old.attribute4, FND_API.G_MISS_CHAR) OR
2229 p_lpn_table(lpn_tbl_cnt).attribute5 <> NVL(l_old.attribute5, FND_API.G_MISS_CHAR) OR
2230 p_lpn_table(lpn_tbl_cnt).attribute6 <> NVL(l_old.attribute6, FND_API.G_MISS_CHAR) OR
2231 p_lpn_table(lpn_tbl_cnt).attribute7 <> NVL(l_old.attribute7, FND_API.G_MISS_CHAR) OR
2232 p_lpn_table(lpn_tbl_cnt).attribute8 <> NVL(l_old.attribute8, FND_API.G_MISS_CHAR) OR
2233 p_lpn_table(lpn_tbl_cnt).attribute9 <> NVL(l_old.attribute9, FND_API.G_MISS_CHAR) OR
2234 p_lpn_table(lpn_tbl_cnt).attribute10 <> NVL(l_old.attribute10, FND_API.G_MISS_CHAR) OR
2235 p_lpn_table(lpn_tbl_cnt).attribute11 <> NVL(l_old.attribute11, FND_API.G_MISS_CHAR) OR
2236 p_lpn_table(lpn_tbl_cnt).attribute12 <> NVL(l_old.attribute12, FND_API.G_MISS_CHAR) OR
2237 p_lpn_table(lpn_tbl_cnt).attribute13 <> NVL(l_old.attribute13, FND_API.G_MISS_CHAR) OR
2238 p_lpn_table(lpn_tbl_cnt).attribute14 <> NVL(l_old.attribute14, FND_API.G_MISS_CHAR) OR
2239 p_lpn_table(lpn_tbl_cnt).attribute15 <> NVL(l_old.attribute15, FND_API.G_MISS_CHAR) )
2240 THEN
2241 l_progress := 'Initialize temp variables used for each loop';
2242 l_change_in_gross_weight := 0;
2243 l_change_in_gross_weight_uom := NULL;
2244 l_change_in_tare_weight := 0;
2245 l_change_in_tare_weight_uom := NULL;
2246 l_change_in_volume := 0;
2247 l_change_in_volume_uom := NULL;
2248
2249 -- If this LPN has not been updated, create record
2250 IF ( l_lpn_tab_i IS NULL ) THEN
2251 l_lpn_tab_i := NVL(l_lpns.last, 0) + 1;
2252 l_lpns(l_lpn_tab_i) := l_old;
2253 l_lpn_ids(p_lpn_table(lpn_tbl_cnt).lpn_id) := l_lpn_tab_i;
2254 END IF;
2255
2256 IF (l_debug = 1) THEN
2257 mdebug('Need to update based on lpn_id l_lpn_tab_i='||l_lpn_tab_i, G_INFO);
2258 END IF;
2259
2260 l_progress := 'License Plate Number';
2261 IF ( p_lpn_table(lpn_tbl_cnt).license_plate_number <> l_old.license_plate_number ) THEN
2262 l_progress := 'Validate Organization ID';
2263
2264 IF ( NOT Inv_Cache.set_org_rec( p_organization_id => NVL(p_lpn_table(lpn_tbl_cnt).organization_id, l_old.organization_id)) )THEN
2265 IF (l_debug = 1) THEN
2266 mdebug(NVL(p_lpn_table(lpn_tbl_cnt).organization_id, l_old.organization_id)||' is an invalid organization id', G_ERROR);
2267 END IF;
2268 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_ORG');
2269 fnd_msg_pub.ADD;
2270 RAISE fnd_api.g_exc_error;
2271 END IF;
2272
2273 IF (l_debug = 1) THEN
2274 mdebug('Got org info wms_enabled='||inv_cache.org_rec.wms_enabled_flag, 5);
2275 END IF;
2276
2277 IF ( inv_cache.org_rec.wms_enabled_flag = 'Y' ) THEN
2278 -- License Plate Number cannot be updated in a WMS organziation
2279 fnd_message.set_name('WMS', 'WMS_UPDATE_LPN_ATTR_ERR');
2280 fnd_message.set_token('ATTR', 'License Plate Number');
2281 fnd_msg_pub.ADD;
2282 RAISE fnd_api.g_exc_error;
2283 ELSE
2284 l_new.license_plate_number := p_lpn_table(lpn_tbl_cnt).license_plate_number;
2285 END IF;
2286 END IF;
2287
2288 l_progress := 'Validate container item';
2289 IF ( (p_lpn_table(lpn_tbl_cnt).inventory_item_id IS NOT NULL)
2290 AND (Nvl(p_lpn_table(lpn_tbl_cnt).inventory_item_id,G_NULL_NUM) <> NVL(l_old.inventory_item_id, G_NULL_NUM)) ) THEN --Bug#6504032 Modified IF condition and commented following code
2291 -- Can change an LPNs existing container item for context 1 and 5 LPNs
2292 /*IF NOT ( l_old.lpn_context = lpn_context_pregenerated OR l_old.inventory_item_id IS NULL ) THEN
2293 IF (l_debug = 1) THEN
2294 mdebug(' LPN is not empty or already is assigned cannot update container item ctx='||l_old.lpn_context, G_ERROR);
2295 END IF;
2296 fnd_message.set_name('WMS', 'WMS_UPDATE_CONTAINER_ITEM_ERR');
2297 fnd_msg_pub.ADD;
2298
2299 IF ( l_old.lpn_context <> lpn_context_pregenerated ) THEN
2300 fnd_message.set_name('WMS', 'WMS_LPN_NOT_EMPTY');
2301 fnd_msg_pub.ADD;
2302 END IF;
2303 RAISE fnd_api.g_exc_error;
2304 END IF;*/
2305
2306 l_progress := 'Calling INV_CACHE.Set_Item_Rec to get item values';
2307 IF ( inv_cache.set_item_rec(
2308 p_organization_id => NVL(p_lpn_table(lpn_tbl_cnt).organization_id, l_old.organization_id)
2309 , p_item_id => p_lpn_table(lpn_tbl_cnt).inventory_item_id ) )
2310 THEN
2311 IF (l_debug = 1) THEN
2312 mdebug('Got Item info citm='||inv_cache.item_rec.container_item_flag||' snctl='||inv_cache.item_rec.serial_number_control_code, G_INFO);
2313 mdebug('wuom='||inv_cache.item_rec.weight_uom_code||' wt='||inv_cache.item_rec.unit_weight||' vuom='||inv_cache.item_rec.volume_uom_code||' vol='||inv_cache.item_rec.unit_volume, G_INFO);
2314 END IF;
2315
2316 IF ( inv_cache.item_rec.container_item_flag = 'N' ) THEN
2317 IF (l_debug = 1) THEN
2318 mdebug(p_lpn_table(lpn_tbl_cnt).inventory_item_id || ' is not a container', 1);
2319 END IF;
2320 fnd_message.set_name('WMS', 'WMS_ITEM_NOT_CONTAINER');
2321 fnd_message.set_token('ITEM', inv_cache.item_rec.segment1);
2322 fnd_msg_pub.ADD;
2323 RAISE fnd_api.g_exc_error;
2324 END IF;
2325 ELSE
2326 l_progress := 'Error calling INV_CACHE.Set_Item_Rec for orgid='||NVL(p_lpn_table(lpn_tbl_cnt).organization_id, l_old.organization_id)||' item id='||p_lpn_table(lpn_tbl_cnt).inventory_item_id;
2327 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_ITEM');
2328 fnd_msg_pub.ADD;
2329 RAISE fnd_api.g_exc_error;
2330 END IF;
2331
2332 -- Container item is valid, change container item
2333 l_new.inventory_item_id := p_lpn_table(lpn_tbl_cnt).inventory_item_id;
2334 END IF;
2335
2336 -- bug5404902 changed l_change_in_gross_weight(_uom) to l_change_in_tare_weight(_uom)
2337 l_progress := 'Tare weight';
2338 IF ( p_lpn_table(lpn_tbl_cnt).tare_weight = FND_API.G_MISS_NUM OR p_lpn_table(lpn_tbl_cnt).tare_weight_uom_code = FND_API.G_MISS_CHAR ) THEN
2339 l_new.tare_weight := NULL;
2340 l_new.tare_weight_uom_code := NULL;
2341
2342 IF ( NVL(l_old.tare_weight, 0) <> 0 AND l_old.tare_weight_uom_code IS NOT NULL ) THEN
2343 l_change_in_tare_weight := 0 - l_old.tare_weight;
2344 l_change_in_tare_weight_uom := l_old.tare_weight_uom_code;
2345 END IF;
2346 ELSIF ( p_lpn_table(lpn_tbl_cnt).tare_weight IS NOT NULL AND p_lpn_table(lpn_tbl_cnt).tare_weight_uom_code IS NOT NULL ) THEN
2347 -- Check that value is not negative. If it is, floor at zero
2348 IF ( p_lpn_table(lpn_tbl_cnt).tare_weight < 0 ) THEN
2349 l_new.tare_weight := 0;
2350 ELSE
2351 l_new.tare_weight := p_lpn_table(lpn_tbl_cnt).tare_weight;
2352 END IF;
2353
2354 l_new.tare_weight_uom_code := p_lpn_table(lpn_tbl_cnt).tare_weight_uom_code;
2355
2356 IF ( NVL(l_old.tare_weight,0) <> 0 AND l_old.tare_weight_uom_code IS NOT NULL ) THEN
2357 l_change_in_tare_weight_uom := l_old.tare_weight_uom_code;
2358 l_change_in_tare_weight := Convert_UOM(l_new.inventory_item_id, l_new.tare_weight, l_new.tare_weight_uom_code, l_change_in_tare_weight_uom, G_NO_CONV_RETURN_NULL);
2359 l_change_in_tare_weight := l_change_in_tare_weight - l_old.tare_weight;
2360 ELSE
2361 l_change_in_tare_weight := l_new.tare_weight;
2362 l_change_in_tare_weight_uom := l_new.tare_weight_uom_code;
2363 END IF;
2364 ELSIF ( p_lpn_table(lpn_tbl_cnt).inventory_item_id IS NOT NULL
2365 AND (Nvl(p_lpn_table(lpn_tbl_cnt).inventory_item_id,G_NULL_NUM) <> Nvl(l_old.inventory_item_id,G_NULL_NUM)) ) THEN --Bug#6504032 Modified this ELSIF to allow modifying and attaching container
2366 IF ( l_old.inventory_item_id IS NOT NULL ) THEN
2367 IF (inv_cache.set_item_rec(
2368 p_organization_id => NVL(p_lpn_table(lpn_tbl_cnt).organization_id, l_old.organization_id)
2369 , p_item_id => l_old.inventory_item_id ))
2370 THEN
2371 IF (l_debug = 1) THEN
2372 mdebug('Got Old Item info citm='||inv_cache.item_rec.container_item_flag||' snctl='||inv_cache.item_rec.serial_number_control_code, G_INFO);
2373 mdebug('wuom='||inv_cache.item_rec.weight_uom_code||' wt='||inv_cache.item_rec.unit_weight||' vuom='||inv_cache.item_rec.volume_uom_code||' vol='||inv_cache.item_rec.unit_volume, G_INFO);
2374 END IF;
2375 ELSE
2376 l_progress := 'Error calling INV_CACHE.Set_Item_Rec for orgid='||NVL(p_lpn_table(lpn_tbl_cnt).organization_id, l_old.organization_id)||' item id='||l_old.inventory_item_id;
2377 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_ITEM');
2378 fnd_msg_pub.ADD;
2379 RAISE fnd_api.g_exc_error;
2380 END IF;
2381 IF ( inv_cache.item_rec.unit_weight IS NOT NULL AND
2382 inv_cache.item_rec.weight_uom_code IS NOT NULL ) THEN
2383
2384 IF ( NVL(l_old.tare_weight, 0) = 0 OR l_old.tare_weight_uom_code IS NULL ) THEN
2385 l_new.tare_weight := 0;
2386 l_new.tare_weight_uom_code := NULL;
2387 ELSIF ( l_old.tare_weight_uom_code = inv_cache.item_rec.weight_uom_code ) THEN
2388 l_new.tare_weight := l_old.tare_weight - inv_cache.item_rec.unit_weight;
2389 l_old.tare_weight := l_old.tare_weight - inv_cache.item_rec.unit_weight;
2390 l_new.tare_weight_uom_code := l_old.tare_weight_uom_code;
2391 ELSE -- Both are not null but with different UOMs need to convert
2392 l_new.tare_weight := Convert_UOM(inv_cache.item_rec.inventory_item_id, inv_cache.item_rec.unit_weight, inv_cache.item_rec.weight_uom_code, l_old.tare_weight_uom_code, G_NO_CONV_RETURN_NULL);
2393
2394 l_new.tare_weight := l_old.tare_weight - l_new.tare_weight;
2395 l_old.tare_weight := l_old.tare_weight - inv_cache.item_rec.unit_weight;
2396 l_new.tare_weight_uom_code := l_old.tare_weight_uom_code;
2397 END IF;
2398
2399 l_change_in_tare_weight := 0-inv_cache.item_rec.unit_weight;
2400 l_change_in_tare_weight_uom := l_old.tare_weight_uom_code;
2401 END IF;
2402 END IF;
2403 IF ( inv_cache.set_item_rec(
2404 p_organization_id => NVL(p_lpn_table(lpn_tbl_cnt).organization_id, l_old.organization_id)
2405 , p_item_id => p_lpn_table(lpn_tbl_cnt).inventory_item_id ) )
2406 THEN
2407 IF (l_debug = 1) THEN
2408 mdebug('Got Item info citm='||inv_cache.item_rec.container_item_flag||' snctl='||inv_cache.item_rec.serial_number_control_code, G_INFO);
2409 mdebug('wuom='||inv_cache.item_rec.weight_uom_code||' wt='||inv_cache.item_rec.unit_weight||' vuom='||inv_cache.item_rec.volume_uom_code||' vol='||inv_cache.item_rec.unit_volume, G_INFO);
2410 END IF;
2411 ELSE
2412 l_progress := 'Error calling INV_CACHE.Set_Item_Rec for orgid='||NVL(p_lpn_table(lpn_tbl_cnt).organization_id, l_old.organization_id)||' item id='||p_lpn_table(lpn_tbl_cnt).inventory_item_id;
2413 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_ITEM');
2414 fnd_msg_pub.ADD;
2415 RAISE fnd_api.g_exc_error;
2416 END IF;
2417 IF ( inv_cache.item_rec.unit_weight IS NOT NULL AND
2418 inv_cache.item_rec.weight_uom_code IS NOT NULL ) THEN
2419
2420 IF ( NVL(l_old.tare_weight, 0) = 0 OR l_old.tare_weight_uom_code IS NULL ) THEN
2421 l_new.tare_weight := inv_cache.item_rec.unit_weight;
2422 l_new.tare_weight_uom_code := inv_cache.item_rec.weight_uom_code;
2423 ELSIF ( l_old.tare_weight_uom_code = inv_cache.item_rec.weight_uom_code ) THEN
2424 l_new.tare_weight := l_new.tare_weight + inv_cache.item_rec.unit_weight;
2425 l_new.tare_weight_uom_code := l_old.tare_weight_uom_code;
2426 ELSE -- Both are not null but with different UOMs need to convert
2427 l_new.tare_weight := Convert_UOM(inv_cache.item_rec.inventory_item_id, inv_cache.item_rec.unit_weight, inv_cache.item_rec.weight_uom_code, l_old.tare_weight_uom_code, G_NO_CONV_RETURN_NULL);
2428
2429 l_new.tare_weight := l_new.tare_weight + l_old.tare_weight;
2430 l_new.tare_weight_uom_code := l_old.tare_weight_uom_code;
2431 END IF;
2432
2433 -- bug5404902 now that we are just adding the container item unit weight to the
2434 -- existing tare, change in tare is just the container item unit weight
2435 l_change_in_tare_weight := l_change_in_tare_weight + inv_cache.item_rec.unit_weight;
2436 l_change_in_tare_weight_uom := inv_cache.item_rec.weight_uom_code;
2437 END IF;
2438 ELSIF ( p_lpn_table(lpn_tbl_cnt).inventory_item_id IS NULL ----Bug#6504032 Added this ELSIF to take care of container removal
2439 AND l_old.inventory_item_id IS NOT NULL
2440 AND l_old.lpn_context IN (1,5)
2441 AND p_caller = 'UpdateLPNPage' ) THEN
2442 IF (inv_cache.set_item_rec(
2443 p_organization_id => NVL(p_lpn_table(lpn_tbl_cnt).organization_id, l_old.organization_id)
2444 , p_item_id => l_old.inventory_item_id ))
2445 THEN
2446 IF (l_debug = 1) THEN
2447 mdebug('Got Old Item info citm='||inv_cache.item_rec.container_item_flag||' snctl='||inv_cache.item_rec.serial_number_control_code, G_INFO);
2448 mdebug('wuom='||inv_cache.item_rec.weight_uom_code||' wt='||inv_cache.item_rec.unit_weight||' vuom='||inv_cache.item_rec.volume_uom_code||' vol='||inv_cache.item_rec.unit_volume, G_INFO);
2449 END IF;
2450 ELSE
2451 l_progress := 'Error calling INV_CACHE.Set_Item_Rec for orgid='||NVL(p_lpn_table(lpn_tbl_cnt).organization_id, l_old.organization_id)||' item id='||p_lpn_table(lpn_tbl_cnt).inventory_item_id;
2452 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_ITEM');
2453 fnd_msg_pub.ADD;
2454 RAISE fnd_api.g_exc_error;
2455 END IF;
2456
2457 IF (inv_cache.item_rec.unit_weight IS NOT NULL AND
2458 inv_cache.item_rec.weight_uom_code IS NOT NULL ) THEN
2459
2460 IF ( NVL(l_old.tare_weight, 0) = 0 OR l_old.tare_weight_uom_code IS NULL ) THEN
2461 l_new.tare_weight := 0;
2462 l_new.tare_weight_uom_code := NULL;
2463 ELSIF ( l_old.tare_weight_uom_code = inv_cache.item_rec.weight_uom_code ) THEN
2464 l_new.tare_weight := l_old.tare_weight - inv_cache.item_rec.unit_weight;
2465 l_new.tare_weight_uom_code := l_old.tare_weight_uom_code;
2466 ELSE -- Both are not null but with different UOMs need to convert
2467 l_new.tare_weight := Convert_UOM(inv_cache.item_rec.inventory_item_id, inv_cache.item_rec.unit_weight, inv_cache.item_rec.weight_uom_code, l_old.tare_weight_uom_code, G_NO_CONV_RETURN_NULL);
2468
2469 l_new.tare_weight := l_old.tare_weight - l_new.tare_weight;
2470 l_new.tare_weight_uom_code := l_old.tare_weight_uom_code;
2471 END IF;
2472
2473 l_change_in_tare_weight := 0-inv_cache.item_rec.unit_weight;
2474 l_change_in_tare_weight_uom := l_old.tare_weight_uom_code;
2475 END IF;
2476 l_new.inventory_item_id := NULL;
2477 l_new.container_volume := NULL;
2478 l_new.container_volume_uom := NULL;
2479 END IF;
2480
2481 l_progress := 'Gross Weight';
2482 IF ( p_lpn_table(lpn_tbl_cnt).gross_weight = FND_API.G_MISS_NUM OR p_lpn_table(lpn_tbl_cnt).gross_weight_uom_code = FND_API.G_MISS_CHAR ) THEN
2483 l_new.gross_weight := NULL;
2484 l_new.gross_weight_uom_code := NULL;
2485 ELSIF ( p_lpn_table(lpn_tbl_cnt).gross_weight IS NOT NULL AND p_lpn_table(lpn_tbl_cnt).gross_weight_uom_code IS NOT NULL ) THEN
2486 -- Check that value is not negative. If it is, floor at zero
2487 IF ( p_lpn_table(lpn_tbl_cnt).gross_weight < 0 ) THEN
2488 l_new.gross_weight := 0;
2489 ELSE
2490 l_new.gross_weight := p_lpn_table(lpn_tbl_cnt).gross_weight;
2491 END IF;
2492 l_new.gross_weight_uom_code := p_lpn_table(lpn_tbl_cnt).gross_weight_uom_code;
2493 END IF;
2494
2495 --Bug#6504032 Separated calculation of change in Gr Wt due to container association
2496 IF ( p_caller = 'UpdateLPNPage' ) THEN
2497 IF ( NVL(l_new.gross_weight, 0) = 0 OR l_new.gross_weight_uom_code IS NULL ) THEN
2498 l_change_in_weight := 0 - l_old.gross_weight;
2499 l_change_in_weight_uom := l_old.gross_weight_uom_code;
2500 ELSIF ( NVL(l_old.gross_weight, 0) = 0 OR l_old.gross_weight_uom_code IS NULL ) THEN
2501 l_change_in_weight := l_new.gross_weight;
2502 l_change_in_weight_uom := l_new.gross_weight_uom_code;
2503 ELSIF ( l_old.gross_weight_uom_code = l_new.gross_weight_uom_code ) THEN
2504 l_change_in_weight := l_new.gross_weight - l_old.gross_weight;
2505 l_change_in_weight_uom := l_old.gross_weight_uom_code;
2506 ELSE -- Both are not null but with different UOMs need to convert
2507 l_change_in_weight_uom := l_old.gross_weight_uom_code;
2508
2509 l_change_in_weight := Convert_UOM(l_new.inventory_item_id, l_new.gross_weight, l_new.gross_weight_uom_code, l_change_in_weight_uom, G_NO_CONV_RETURN_NULL);
2510 l_change_in_weight := l_change_in_weight - l_old.gross_weight;
2511 END IF;
2512
2513 /*Bug#6845814 If there is a change in gross weight, it will be a change in tare weight. */
2514 IF ( l_change_in_weight <> 0
2515 AND p_caller='UpdateLPNPage'
2516 --AND NVL(p_lpn_table(lpn_tbl_cnt).inventory_item_id ,G_NULL_NUM) = G_NULL_NUM
2517 ) THEN
2518 IF (l_new.tare_weight_uom_code IS NOT NULL ) THEN
2519 IF ( l_change_in_weight_uom <> l_new.tare_weight_uom_code ) THEN
2520 l_new.tare_weight := NVL( l_new.tare_weight,0) + inv_convert.inv_um_convert(
2521 l_new.inventory_item_id,
2522 6,
2523 l_change_in_weight,
2524 l_change_in_weight_uom ,
2525 l_new.tare_weight_uom_code
2526 ,NULL,NULL);
2527 ELSE
2528 l_new.tare_weight := NVL( l_new.tare_weight,0) + l_change_in_weight ;
2529 END IF;
2530 ELSE --l_new.tare_weight_uom_code IS NULL
2531 l_new.tare_weight := l_change_in_weight ;
2532 l_new.tare_weight_uom_code := NVL( l_change_in_weight_uom , l_new.gross_weight_uom_code );
2533 END IF;
2534
2535 IF (l_new.tare_weight <= 0 ) THEN
2536 l_new.tare_weight := 0 ;
2537 l_new.tare_weight_uom_code := NULL ;
2538 END IF;
2539 END IF;
2540 END IF;
2541
2542 /*Bug7529224 moved code that adds change in tare weight into gross wt to down */
2543 IF (l_debug = 1) THEN
2544 mdebug('After gr wt calc ,l_change_in_tare_weight:'||l_change_in_tare_weight ,G_INFO );
2545 END IF;
2546
2547 l_progress := 'Container Volume';
2548 IF ( p_lpn_table(lpn_tbl_cnt).container_volume = FND_API.G_MISS_NUM OR p_lpn_table(lpn_tbl_cnt).container_volume_uom = FND_API.G_MISS_CHAR ) THEN
2549 l_new.container_volume := NULL;
2550 l_new.container_volume_uom := NULL;
2551 ELSIF ( p_lpn_table(lpn_tbl_cnt).container_volume IS NOT NULL AND p_lpn_table(lpn_tbl_cnt).container_volume_uom IS NOT NULL ) THEN
2552 -- Check that value is not negative. If it is, floor at zero
2553 IF ( p_lpn_table(lpn_tbl_cnt).container_volume < 0 ) THEN
2554 l_new.container_volume := 0;
2555 ELSE
2556 l_new.container_volume := p_lpn_table(lpn_tbl_cnt).container_volume;
2557 END IF;
2558
2559 l_new.container_volume_uom := p_lpn_table(lpn_tbl_cnt).container_volume_uom;
2560 ELSIF ( p_lpn_table(lpn_tbl_cnt).inventory_item_id IS NOT NULL ) THEN
2561 -- use new container item tare weight and uom if values are not defined yet
2562 --IF ( l_old.container_volume IS NULL OR l_old.container_volume_uom IS NULL ) THEN --Bug#6504032 Commented this IF as container can be updated now
2563 l_new.container_volume := inv_cache.item_rec.unit_volume;
2564 l_new.container_volume_uom := inv_cache.item_rec.volume_uom_code;
2565 --END IF;
2566 END IF;
2567
2568 l_progress := 'Content Volume';
2569 IF ( p_lpn_table(lpn_tbl_cnt).content_volume = FND_API.G_MISS_NUM OR p_lpn_table(lpn_tbl_cnt).content_volume_uom_code = FND_API.G_MISS_CHAR ) THEN
2570 l_new.content_volume := NULL;
2571 l_new.content_volume_uom_code := NULL;
2572 ELSIF ( p_lpn_table(lpn_tbl_cnt).content_volume IS NOT NULL AND p_lpn_table(lpn_tbl_cnt).content_volume_uom_code IS NOT NULL ) THEN
2573 -- Check that value is not negative. If it is, floor at zero
2574 IF ( p_lpn_table(lpn_tbl_cnt).content_volume < 0 ) THEN
2575 l_new.content_volume := 0;
2576 ELSE
2577 l_new.content_volume := p_lpn_table(lpn_tbl_cnt).content_volume;
2578 END IF;
2579
2580 l_new.content_volume_uom_code := p_lpn_table(lpn_tbl_cnt).content_volume_uom_code;
2581 END IF;
2582
2583 /* Not sure if we need to support this
2584 l_progress := 'Status ID?';
2585 IF ( p_lpn_table(lpn_tbl_cnt).status_id = FND_API.G_MISS_NUM ) THEN
2586 l_new.status_id := NULL;
2587 ELSIF ( p_lpn_table(lpn_tbl_cnt).status_id IS NOT NULL ) THEN
2588 l_new.status_id := p_lpn_table(lpn_tbl_cnt).status_id;
2589 END IF;*/
2590
2591 l_progress := 'Update attribute_category';
2592 IF ( p_lpn_table(lpn_tbl_cnt).attribute_category = FND_API.G_MISS_CHAR ) THEN
2593 l_new.attribute_category := NULL;
2594 ELSIF ( p_lpn_table(lpn_tbl_cnt).attribute_category IS NOT NULL ) THEN
2595 l_new.attribute_category := p_lpn_table(lpn_tbl_cnt).attribute_category;
2596 END IF;
2597
2598 l_progress := 'Update attribute1';
2599 IF ( p_lpn_table(lpn_tbl_cnt).attribute1 = FND_API.G_MISS_CHAR ) THEN
2600 l_new.attribute1 := NULL;
2601 ELSIF ( p_lpn_table(lpn_tbl_cnt).attribute1 IS NOT NULL ) THEN
2602 l_new.attribute1 := p_lpn_table(lpn_tbl_cnt).attribute1;
2603 END IF;
2604
2605 l_progress := 'Update attribute2';
2606 IF ( p_lpn_table(lpn_tbl_cnt).attribute2 = FND_API.G_MISS_CHAR ) THEN
2607 l_new.attribute2 := NULL;
2608 ELSIF ( p_lpn_table(lpn_tbl_cnt).attribute2 IS NOT NULL ) THEN
2609 l_new.attribute2 := p_lpn_table(lpn_tbl_cnt).attribute2;
2610 END IF;
2611
2612 l_progress := 'Update attribute3';
2613 IF ( p_lpn_table(lpn_tbl_cnt).attribute3 = FND_API.G_MISS_CHAR ) THEN
2614 l_new.attribute3 := NULL;
2615 ELSIF ( p_lpn_table(lpn_tbl_cnt).attribute3 IS NOT NULL ) THEN
2616 l_new.attribute3 := p_lpn_table(lpn_tbl_cnt).attribute3;
2617 END IF;
2618
2619 l_progress := 'Update attribute4';
2620 IF ( p_lpn_table(lpn_tbl_cnt).attribute4 = FND_API.G_MISS_CHAR ) THEN
2621 l_new.attribute4 := NULL;
2622 ELSIF ( p_lpn_table(lpn_tbl_cnt).attribute4 IS NOT NULL ) THEN
2623 l_new.attribute4 := p_lpn_table(lpn_tbl_cnt).attribute4;
2624 END IF;
2625
2626 l_progress := 'Update attribute5';
2627 IF ( p_lpn_table(lpn_tbl_cnt).attribute5 = FND_API.G_MISS_CHAR ) THEN
2628 l_new.attribute5 := NULL;
2629 ELSIF ( p_lpn_table(lpn_tbl_cnt).attribute5 IS NOT NULL ) THEN
2630 l_new.attribute5 := p_lpn_table(lpn_tbl_cnt).attribute5;
2631 END IF;
2632
2633 l_progress := 'Update attribute6';
2634 IF ( p_lpn_table(lpn_tbl_cnt).attribute6 = FND_API.G_MISS_CHAR ) THEN
2635 l_new.attribute6 := NULL;
2636 ELSIF ( p_lpn_table(lpn_tbl_cnt).attribute6 IS NOT NULL ) THEN
2637 l_new.attribute6 := p_lpn_table(lpn_tbl_cnt).attribute6;
2638 END IF;
2639
2640 l_progress := 'Update attribute7';
2641 IF ( p_lpn_table(lpn_tbl_cnt).attribute7 = FND_API.G_MISS_CHAR ) THEN
2642 l_new.attribute7 := NULL;
2643 ELSIF ( p_lpn_table(lpn_tbl_cnt).attribute7 IS NOT NULL ) THEN
2644 l_new.attribute7 := p_lpn_table(lpn_tbl_cnt).attribute7;
2645 END IF;
2646
2647 l_progress := 'Update attribute8';
2648 IF ( p_lpn_table(lpn_tbl_cnt).attribute8 = FND_API.G_MISS_CHAR ) THEN
2649 l_new.attribute8 := NULL;
2650 ELSIF ( p_lpn_table(lpn_tbl_cnt).attribute8 IS NOT NULL ) THEN
2651 l_new.attribute8 := p_lpn_table(lpn_tbl_cnt).attribute8;
2652 END IF;
2653
2654 l_progress := 'Update attribute9';
2655 IF ( p_lpn_table(lpn_tbl_cnt).attribute9 = FND_API.G_MISS_CHAR ) THEN
2656 l_new.attribute9 := NULL;
2657 ELSIF ( p_lpn_table(lpn_tbl_cnt).attribute9 IS NOT NULL ) THEN
2658 l_new.attribute9 := p_lpn_table(lpn_tbl_cnt).attribute9;
2659 END IF;
2660
2661 l_progress := 'Update attribute10';
2662 IF ( p_lpn_table(lpn_tbl_cnt).attribute10 = FND_API.G_MISS_CHAR ) THEN
2663 l_new.attribute10 := NULL;
2664 ELSIF ( p_lpn_table(lpn_tbl_cnt).attribute10 IS NOT NULL ) THEN
2665 l_new.attribute10 := p_lpn_table(lpn_tbl_cnt).attribute10;
2666 END IF;
2667
2668 l_progress := 'Update attribute11';
2669 IF ( p_lpn_table(lpn_tbl_cnt).attribute11 = FND_API.G_MISS_CHAR ) THEN
2670 l_new.attribute11 := NULL;
2671 ELSIF ( p_lpn_table(lpn_tbl_cnt).attribute11 IS NOT NULL ) THEN
2672 l_new.attribute11 := p_lpn_table(lpn_tbl_cnt).attribute11;
2673 END IF;
2674
2675 l_progress := 'Update attribute12';
2676 IF ( p_lpn_table(lpn_tbl_cnt).attribute12 = FND_API.G_MISS_CHAR ) THEN
2677 l_new.attribute12 := NULL;
2678 ELSIF ( p_lpn_table(lpn_tbl_cnt).attribute12 IS NOT NULL ) THEN
2679 l_new.attribute12 := p_lpn_table(lpn_tbl_cnt).attribute12;
2680 END IF;
2681
2682 l_progress := 'Update attribute13';
2683 IF ( p_lpn_table(lpn_tbl_cnt).attribute13 = FND_API.G_MISS_CHAR ) THEN
2684 l_new.attribute13 := NULL;
2685 ELSIF ( p_lpn_table(lpn_tbl_cnt).attribute13 IS NOT NULL ) THEN
2686 l_new.attribute13 := p_lpn_table(lpn_tbl_cnt).attribute13;
2687 END IF;
2688
2689 l_progress := 'Update attribute14';
2690 IF ( p_lpn_table(lpn_tbl_cnt).attribute14 = FND_API.G_MISS_CHAR ) THEN
2691 l_new.attribute14 := NULL;
2692 ELSIF ( p_lpn_table(lpn_tbl_cnt).attribute14 IS NOT NULL ) THEN
2693 l_new.attribute14 := p_lpn_table(lpn_tbl_cnt).attribute14;
2694 END IF;
2695
2696 l_progress := 'Update attribute15';
2697 IF ( p_lpn_table(lpn_tbl_cnt).attribute15 = FND_API.G_MISS_CHAR ) THEN
2698 l_new.attribute15 := NULL;
2699 ELSIF ( p_lpn_table(lpn_tbl_cnt).attribute15 IS NOT NULL ) THEN
2700 l_new.attribute15 := p_lpn_table(lpn_tbl_cnt).attribute15;
2701 END IF;
2702
2703 l_progress := 'Parent LPN';
2704 IF ( p_lpn_table(lpn_tbl_cnt).parent_lpn_id IS NOT NULL ) THEN
2705 IF ( NVL(p_caller, G_NULL_CHAR) <> 'WMS_PackUnpack_Container' ) THEN
2706 l_progress := 'Updating parent_lpn_id is retructed to PackUnpack_Container API';
2707 fnd_message.set_name('WMS', 'WMS_UPDATE_LPN_ATTR_ERR');
2708 fnd_message.set_token('ATTR', 'parent_lpn_id');
2709 fnd_msg_pub.ADD;
2710 RAISE fnd_api.g_exc_error;
2711 ELSIF ( p_lpn_table(lpn_tbl_cnt).parent_lpn_id = FND_API.G_MISS_NUM ) THEN
2712 -- UNPACKING LPN
2713 l_new.parent_lpn_id := NULL;
2714 l_new.outermost_lpn_id := l_new.lpn_id;
2715 ELSIF ( l_old.parent_lpn_id IS NOT NULL ) THEN
2716 -- Nesting an lpn that is already nested not allowed in a single
2717 -- operaiton. Must unpack LPN before packing into new LPN
2718 fnd_message.set_name('WMS', 'WMS_LPN_ALREADY_NESTED_ERR');
2719 fnd_msg_pub.ADD;
2720 RAISE fnd_api.g_exc_error;
2721 ELSE
2722 -- PACKING LPN
2723 l_new.parent_lpn_id := p_lpn_table(lpn_tbl_cnt).parent_lpn_id;
2724
2725 -- Need to populate new outermost lpn id
2726 IF ( p_lpn_table(lpn_tbl_cnt).outermost_lpn_id IS NOT NULL ) THEN
2727 l_new.outermost_lpn_id := p_lpn_table(lpn_tbl_cnt).outermost_lpn_id;
2728 ELSIF ( l_lpn_ids.exists(l_new.parent_lpn_id) ) THEN
2729 l_new.outermost_lpn_id := l_lpns(l_lpn_ids(l_new.parent_lpn_id)).outermost_lpn_id;
2730 ELSE -- not in table just get from db
2731 l_progress := 'Getting outermost_lpn_id for plpnid='||l_new.parent_lpn_id;
2732 SELECT outermost_lpn_id
2733 INTO l_new.outermost_lpn_id
2734 FROM wms_license_plate_numbers
2735 WHERE lpn_id = l_new.parent_lpn_id;
2736 END IF;
2737 END IF;
2738 END IF;
2739
2740 l_progress := 'Done with section that deals with LPN itself';
2741
2742 /************************************************************/
2743 /* Calculate changes to weight and volume */
2744 /* */
2745 /************************************************************/
2746 l_progress := 'Calculate total change in gross weight';
2747
2748 IF ( NVL(l_new.gross_weight, 0) = 0 OR l_new.gross_weight_uom_code IS NULL ) THEN
2749 l_change_in_gross_weight := 0 - l_old.gross_weight;
2750 l_change_in_gross_weight_uom := l_old.gross_weight_uom_code;
2751 ELSIF ( NVL(l_old.gross_weight, 0) = 0 OR l_old.gross_weight_uom_code IS NULL ) THEN
2752 l_change_in_gross_weight := l_new.gross_weight;
2753 l_change_in_gross_weight_uom := l_new.gross_weight_uom_code;
2754 ELSIF ( l_old.gross_weight_uom_code = l_new.gross_weight_uom_code ) THEN
2755 l_change_in_gross_weight := l_new.gross_weight - l_old.gross_weight;
2756 l_change_in_gross_weight_uom := l_old.gross_weight_uom_code;
2757 ELSE -- Both are not null but with different UOMs need to convert
2758 l_change_in_gross_weight_uom := l_old.gross_weight_uom_code;
2759
2760 l_change_in_gross_weight := Convert_UOM(l_new.inventory_item_id, l_new.gross_weight, l_new.gross_weight_uom_code, l_change_in_gross_weight_uom, G_NO_CONV_RETURN_NULL);
2761 l_change_in_gross_weight := l_change_in_gross_weight - l_old.gross_weight;
2762 END IF;
2763
2764 IF (l_debug = 1) THEN
2765 mdebug('after total change in gr wt ,l_new.gross_weight:'||l_new.gross_weight,G_INFO );
2766 mdebug('l_change_in_gross_weight:'||l_change_in_gross_weight,G_INFO );
2767 END if;
2768
2769 /*Bug#7529224. Moved the code here otherwise change in tare wt is added twice*/
2770 IF ( NVL(l_change_in_tare_weight, 0) <> 0 AND l_change_in_tare_weight_uom IS NOT NULL
2771 AND l_change_in_gross_weight = 0 )
2772 THEN
2773 -- bug5404902 changed l_change_in_gross_weight(_uom) to l_change_in_tare_weight(_uom)
2774 -- If tare weight has changed need to add the difference to gross
2775 IF ( NVL(l_old.gross_weight, 0) = 0 OR l_old.gross_weight_uom_code IS NULL ) THEN
2776 l_new.gross_weight := l_new.tare_weight;
2777 l_new.gross_weight_uom_code := l_new.tare_weight_uom_code;
2778 ELSIF ( l_old.gross_weight_uom_code = l_change_in_gross_weight_uom ) THEN
2779 l_new.gross_weight := l_new.gross_weight + l_change_in_tare_weight;
2780 l_new.gross_weight_uom_code := l_old.gross_weight_uom_code;
2781 ELSE -- Both are not null but with different UOMs need to convert
2782 -- bug5404902 intentionally used l_change_in_gross_weight to store conversion value
2783 -- so that l_change_in_tare_weight can maintain it's original UOM
2784 -- Marker
2785 l_change_in_gross_weight := Convert_UOM(l_new.inventory_item_id, l_change_in_tare_weight, l_change_in_tare_weight_uom, l_new.gross_weight_uom_code, G_NO_CONV_RETURN_ZERO);
2786 l_change_in_gross_weight_uom := l_new.gross_weight_uom_code;
2787
2788 l_new.gross_weight := l_new.gross_weight + l_change_in_tare_weight;
2789 END IF;
2790 END IF;
2791
2792 IF (l_debug = 1) THEN
2793 mdebug('After adding change in tare weight l_new.gross_weight:'||l_new.gross_weight,G_INFO );
2794 end if;
2795 /*Bug#7529224 End*/
2796
2797 IF (l_debug = 1) THEN
2798 mdebug('change wt='||l_change_in_gross_weight||' change wuom='||l_change_in_gross_weight_uom, G_INFO);
2799 mdebug('After all calc, l_new.gross_weight:'||l_new.gross_weight,G_INFO );
2800 mdebug('New item='||p_lpn_table(lpn_tbl_cnt).inventory_item_id ||',old item='||l_old.inventory_item_id,G_INFO);
2801 END IF;
2802
2803 l_progress := 'Call helper procedure to calculate change in volume';
2804 Calc_Vol_Change (
2805 p_debug => l_debug
2806 , p_old_lpn => l_old
2807 , p_new_lpn => l_new
2808 , p_volume_change => l_change_in_volume
2809 , p_volume_uom_change => l_change_in_volume_uom );
2810
2811 -- bug 4144326 When there is a change in wt/vol need to update locator capacity.
2812 -- Only for explicit update transactions. Not for TM invoked updates.
2813 /*IF ( NVL(p_caller, G_NULL_CHAR) <> 'WMS_PackUnpack_Container' AND
2814 NVL(p_caller, G_NULL_CHAR) <> 'INV_TRNSACTION' )
2815 THEN*/
2816 IF ( NVL(p_caller, G_NULL_CHAR) not in ('WMS_PackUnpack_Container', 'INV_TRNSACTION') ) THEN
2817 l_progress := 'Calling Update_Locator_Capacity';
2818
2819 Update_Locator_Capacity (
2820 x_return_status => x_return_status
2821 , x_msg_count => x_msg_count
2822 , x_msg_data => x_msg_data
2823 , p_organization_id => l_new.organization_id
2824 , p_subinventory => l_new.subinventory_code
2825 , p_locator_id => l_new.locator_id
2826 , p_weight_change => l_change_in_gross_weight
2827 , p_weight_uom_change => l_change_in_gross_weight_uom
2828 , p_volume_change => l_change_in_volume
2829 , p_volume_uom_change => l_change_in_volume_uom
2830 );
2831
2832 IF ( x_return_status <> fnd_api.g_ret_sts_success) THEN
2833 IF (l_debug = 1) THEN
2834 mdebug('Call to WMS_CONTAINER_PVT.Update_Locator_capacity failed !!!');
2835 END IF;
2836 END IF;
2837 END IF;
2838 /*ELSE
2839 l_progress := 'No change is weight/vol of lpn, set vars to null';
2840
2841 l_change_in_gross_weight := null;
2842 l_change_in_gross_weight_uom := null;
2843 l_change_in_volume := null;
2844 l_change_in_volume_uom := null;
2845 END IF;*/
2846
2847 /************************************************************/
2848 /* Changes that only pertain to LPNs nested inside this LPN */
2849 /* Update child LPNs */
2850 /************************************************************/
2851 IF ( l_old.outermost_lpn_id <> l_new.outermost_lpn_id ) THEN
2852 IF ( l_old.lpn_id = l_old.outermost_lpn_id ) THEN
2853 -- This LPN was the outermost can update based on outermost LPN column
2854
2855 IF ( l_outer_lpn_ids.exists(l_old.outermost_lpn_id) ) THEN
2856 l_tmp_i := l_outer_lpn_ids(l_old.outermost_lpn_id);
2857 IF (l_debug = 1) THEN
2858 mdebug('LPN old outer already exist in table l_tmp_i='||l_tmp_i, G_INFO);
2859 END IF;
2860 ELSE
2861 l_tmp_i := NVL(l_outer_lpns.last, 0) + 1;
2862 l_outer_lpn_ids(l_old.outermost_lpn_id) := l_tmp_i;
2863 l_outer_lpns(l_tmp_i).reference_id := l_old.outermost_lpn_id;
2864
2865 IF (l_debug = 1) THEN
2866 mdebug('Create old outer entry in outer table l_tmp_i='||l_tmp_i, G_INFO);
2867 END IF;
2868 END IF;
2869
2870 l_outer_lpns(l_tmp_i).outermost_lpn_id := l_new.outermost_lpn_id;
2871 l_outer_lpns(l_tmp_i).organization_id := l_new.organization_id;
2872 l_outer_lpns(l_tmp_i).subinventory_code := l_new.subinventory_code;
2873 l_outer_lpns(l_tmp_i).locator_id := l_new.locator_id;
2874 l_outer_lpns(l_tmp_i).lpn_context := l_new.lpn_context;
2875 l_outer_lpns(l_tmp_i).source_type_id := l_new.source_type_id;
2876 l_outer_lpns(l_tmp_i).source_header_id := l_new.source_header_id;
2877 l_outer_lpns(l_tmp_i).source_line_id := l_new.source_line_id;
2878 l_outer_lpns(l_tmp_i).source_line_detail_id := l_new.source_line_detail_id;
2879 l_outer_lpns(l_tmp_i).source_name := l_new.source_name;
2880 ELSE
2881 -- LPN an inner LPN. Need to update child lpns
2882 FOR child_lpn_rec IN nested_child_lpn_cursor( l_old.lpn_id ) LOOP
2883 IF (l_debug = 1) THEN
2884 mdebug('Got child lpn lpnid='||child_lpn_rec.lpn_id, G_INFO);
2885 END IF;
2886
2887 IF ( l_lpn_ids.exists(child_lpn_rec.lpn_id) ) THEN
2888 l_progress := 'LPN attributes already exist in table';
2889 l_tmp_i := l_lpn_ids(child_lpn_rec.lpn_id);
2890
2891 IF (l_debug = 1) THEN
2892 mdebug('LPN attributes already exist in table lpnid='||l_old.lpn_id||' plpn='||l_old.parent_lpn_id||' olpn='||l_old.outermost_lpn_id, G_INFO);
2893 END IF;
2894 ELSE
2895 l_progress := 'Does not already exist in table get from rec';
2896 l_tmp_i := NVL(l_lpns.last, 0) + 1;
2897 l_lpn_ids(child_lpn_rec.lpn_id) := l_tmp_i;
2898
2899 -- Add attributes from rec type to table of lpns
2900 l_lpns(l_tmp_i).lpn_id := child_lpn_rec.lpn_id;
2901 l_lpns(l_tmp_i).license_plate_number := child_lpn_rec.license_plate_number;
2902 l_lpns(l_tmp_i).parent_lpn_id := child_lpn_rec.parent_lpn_id;
2903 l_lpns(l_tmp_i).outermost_lpn_id := child_lpn_rec.outermost_lpn_id;
2904 l_lpns(l_tmp_i).lpn_context := child_lpn_rec.lpn_context;
2905
2906 l_lpns(l_tmp_i).organization_id := child_lpn_rec.organization_id;
2907 l_lpns(l_tmp_i).subinventory_code := child_lpn_rec.subinventory_code;
2908 l_lpns(l_tmp_i).locator_id := child_lpn_rec.locator_id;
2909
2910 l_lpns(l_tmp_i).inventory_item_id := child_lpn_rec.inventory_item_id;
2911 l_lpns(l_tmp_i).revision := child_lpn_rec.revision;
2912 l_lpns(l_tmp_i).lot_number := child_lpn_rec.lot_number;
2913 l_lpns(l_tmp_i).serial_number := child_lpn_rec.serial_number;
2914 l_lpns(l_tmp_i).cost_group_id := child_lpn_rec.cost_group_id;
2915
2916 l_lpns(l_tmp_i).tare_weight_uom_code := child_lpn_rec.tare_weight_uom_code;
2917 l_lpns(l_tmp_i).tare_weight := child_lpn_rec.tare_weight;
2918 l_lpns(l_tmp_i).gross_weight_uom_code := child_lpn_rec.gross_weight_uom_code;
2919 l_lpns(l_tmp_i).gross_weight := child_lpn_rec.gross_weight;
2920 l_lpns(l_tmp_i).container_volume_uom := child_lpn_rec.container_volume_uom;
2921 l_lpns(l_tmp_i).container_volume := child_lpn_rec.container_volume;
2922 l_lpns(l_tmp_i).content_volume_uom_code := child_lpn_rec.content_volume_uom_code;
2923 l_lpns(l_tmp_i).content_volume := child_lpn_rec.content_volume;
2924
2925 l_lpns(l_tmp_i).source_type_id := child_lpn_rec.source_type_id;
2926 l_lpns(l_tmp_i).source_header_id := child_lpn_rec.source_header_id;
2927 l_lpns(l_tmp_i).source_line_id := child_lpn_rec.source_line_id;
2928 l_lpns(l_tmp_i).source_line_detail_id := child_lpn_rec.source_line_detail_id;
2929 l_lpns(l_tmp_i).source_name := child_lpn_rec.source_name;
2930
2931 l_lpns(l_tmp_i).attribute_category := child_lpn_rec.attribute_category;
2932 l_lpns(l_tmp_i).attribute1 := child_lpn_rec.attribute1;
2933 l_lpns(l_tmp_i).attribute2 := child_lpn_rec.attribute2;
2934 l_lpns(l_tmp_i).attribute3 := child_lpn_rec.attribute3;
2935 l_lpns(l_tmp_i).attribute4 := child_lpn_rec.attribute4;
2936 l_lpns(l_tmp_i).attribute5 := child_lpn_rec.attribute5;
2937 l_lpns(l_tmp_i).attribute6 := child_lpn_rec.attribute6;
2938 l_lpns(l_tmp_i).attribute7 := child_lpn_rec.attribute7;
2939 l_lpns(l_tmp_i).attribute8 := child_lpn_rec.attribute8;
2940 l_lpns(l_tmp_i).attribute9 := child_lpn_rec.attribute9;
2941 l_lpns(l_tmp_i).attribute10 := child_lpn_rec.attribute10;
2942 l_lpns(l_tmp_i).attribute11 := child_lpn_rec.attribute11;
2943 l_lpns(l_tmp_i).attribute12 := child_lpn_rec.attribute12;
2944 l_lpns(l_tmp_i).attribute13 := child_lpn_rec.attribute13;
2945 l_lpns(l_tmp_i).attribute14 := child_lpn_rec.attribute14;
2946 l_lpns(l_tmp_i).attribute15 := child_lpn_rec.attribute15;
2947
2948 IF (l_debug = 1) THEN
2949 mdebug('Retrieve attr from rec lpnid='||l_lpns(l_tmp_i).lpn_id||' plpn='||l_lpns(l_tmp_i).parent_lpn_id||' olpn='||l_lpns(l_tmp_i).outermost_lpn_id, G_INFO);
2950 END IF;
2951 END IF;
2952
2953 -- Child LPN record may have already been processed, so there is the possiblity
2954 -- that it is no longer has the same parent lpn. If not then, it is no longer
2955 -- part of this hierarchy, so skip update
2956 IF ( l_lpns(l_tmp_i).parent_lpn_id = child_lpn_rec.parent_lpn_id ) THEN
2957 IF (l_debug = 1) THEN
2958 mdebug('Update values to be inline with new outermost lpn l_tmp_i='||l_tmp_i, G_INFO);
2959 END IF;
2960
2961 -- Values that need updating in child LPNs
2962 l_lpns(l_tmp_i).outermost_lpn_id := l_new.outermost_lpn_id;
2963 ELSIF ( l_debug = 1) THEN
2964 mdebug('Child LPNs parent lpn is not the same skip new='||l_lpns(l_tmp_i).parent_lpn_id||' old='||child_lpn_rec.parent_lpn_id, G_INFO);
2965 END IF;
2966 END LOOP;
2967 END IF;
2968 END IF;
2969
2970 /*****************************************************************/
2971 /* Changes that only pertain to LPNs in which this LPN is packed */
2972 /* Update Parent LPNs */
2973 /*****************************************************************/
2974 IF ( l_old.parent_lpn_id = l_new.parent_lpn_id ) THEN
2975
2976 -- List of attributes that affect parent LPNs. Only if there is a change in
2977 -- these should we open cursor for parent LPNs
2978 -- bug5404902 added change in tare weight to condition
2979 IF ( NVL(l_change_in_gross_weight, 0) <> 0 OR
2980 NVL(l_change_in_tare_weight, 0) <> 0 OR
2981 NVL(l_change_in_volume, 0) <> 0 )
2982 THEN
2983
2984 -- If The LPN has a parent and there is a change in weight or volume, cycle through
2985 -- parent LPNs and update their weights and volumes as well
2986 FOR parent_lpn_rec IN nested_parent_lpn_cursor( NVL(l_old.parent_lpn_id, l_new.parent_lpn_id) ) LOOP
2987 IF (l_debug = 1) THEN
2988 mdebug('Got parent lpn lpnid='||parent_lpn_rec.lpn_id, G_INFO);
2989 END IF;
2990
2991 IF ( l_lpn_ids.exists(parent_lpn_rec.lpn_id) ) THEN
2992 l_progress := 'LPN attributes already exist in table';
2993 l_tmp_i := l_lpn_ids(parent_lpn_rec.lpn_id);
2994 l_tmp_old := l_lpns(l_tmp_i);
2995
2996 IF (l_debug = 1) THEN
2997 mdebug('LPN attributes already exist in table lpnid='||l_tmp_old.lpn_id||' gwuom='||l_tmp_old.gross_weight_uom_code||' gwt='||l_tmp_old.gross_weight||
2998 ' vuom='||l_tmp_old.content_volume_uom_code||' vol='||l_tmp_old.content_volume||' twuom='||l_tmp_old.tare_weight_uom_code||' twt='||l_tmp_old.tare_weight, G_INFO);
2999 END IF;
3000 ELSE
3001 l_progress := 'Does not already exist in table get from rec';
3002 l_tmp_i := l_lpns.last + 1;
3003 l_lpn_ids(parent_lpn_rec.lpn_id) := l_tmp_i;
3004
3005 -- Add attributes from rec type to table of lpns
3006 l_tmp_old.lpn_id := parent_lpn_rec.lpn_id;
3007 l_tmp_old.license_plate_number := parent_lpn_rec.license_plate_number;
3008 l_tmp_old.parent_lpn_id := parent_lpn_rec.parent_lpn_id;
3009 l_tmp_old.outermost_lpn_id := parent_lpn_rec.outermost_lpn_id;
3010 l_tmp_old.lpn_context := parent_lpn_rec.lpn_context;
3011
3012 l_tmp_old.organization_id := parent_lpn_rec.organization_id;
3013 l_tmp_old.subinventory_code := parent_lpn_rec.subinventory_code;
3014 l_tmp_old.locator_id := parent_lpn_rec.locator_id;
3015
3016 l_tmp_old.inventory_item_id := parent_lpn_rec.inventory_item_id;
3017 l_tmp_old.revision := parent_lpn_rec.revision;
3018 l_tmp_old.lot_number := parent_lpn_rec.lot_number;
3019 l_tmp_old.serial_number := parent_lpn_rec.serial_number;
3020 l_tmp_old.cost_group_id := parent_lpn_rec.cost_group_id;
3021
3022 l_tmp_old.tare_weight_uom_code := parent_lpn_rec.tare_weight_uom_code;
3023 l_tmp_old.tare_weight := parent_lpn_rec.tare_weight;
3024 l_tmp_old.gross_weight_uom_code := parent_lpn_rec.gross_weight_uom_code;
3025 l_tmp_old.gross_weight := parent_lpn_rec.gross_weight;
3026 l_tmp_old.container_volume_uom := parent_lpn_rec.container_volume_uom;
3027 l_tmp_old.container_volume := parent_lpn_rec.container_volume;
3028 l_tmp_old.content_volume_uom_code := parent_lpn_rec.content_volume_uom_code;
3029 l_tmp_old.content_volume := parent_lpn_rec.content_volume;
3030
3031 l_tmp_old.source_type_id := parent_lpn_rec.source_type_id;
3032 l_tmp_old.source_header_id := parent_lpn_rec.source_header_id;
3033 l_tmp_old.source_line_id := parent_lpn_rec.source_line_id;
3034 l_tmp_old.source_line_detail_id := parent_lpn_rec.source_line_detail_id;
3035 l_tmp_old.source_name := parent_lpn_rec.source_name;
3036
3037 l_tmp_old.attribute_category := parent_lpn_rec.attribute_category;
3038 l_tmp_old.attribute1 := parent_lpn_rec.attribute1;
3039 l_tmp_old.attribute2 := parent_lpn_rec.attribute2;
3040 l_tmp_old.attribute3 := parent_lpn_rec.attribute3;
3041 l_tmp_old.attribute4 := parent_lpn_rec.attribute4;
3042 l_tmp_old.attribute5 := parent_lpn_rec.attribute5;
3043 l_tmp_old.attribute6 := parent_lpn_rec.attribute6;
3044 l_tmp_old.attribute7 := parent_lpn_rec.attribute7;
3045 l_tmp_old.attribute8 := parent_lpn_rec.attribute8;
3046 l_tmp_old.attribute9 := parent_lpn_rec.attribute9;
3047 l_tmp_old.attribute10 := parent_lpn_rec.attribute10;
3048 l_tmp_old.attribute11 := parent_lpn_rec.attribute11;
3049 l_tmp_old.attribute12 := parent_lpn_rec.attribute12;
3050 l_tmp_old.attribute13 := parent_lpn_rec.attribute13;
3051 l_tmp_old.attribute14 := parent_lpn_rec.attribute14;
3052 l_tmp_old.attribute15 := parent_lpn_rec.attribute15;
3053
3054 IF (l_debug = 1) THEN
3055 mdebug('Retrieve attr from rec lpnid='||l_tmp_old.lpn_id||' gwuom='||l_tmp_old.gross_weight_uom_code||' gwt='||l_tmp_old.gross_weight||' twuom='||l_tmp_old.tare_weight_uom_code||' twt='||l_tmp_old.tare_weight, G_INFO);
3056 mdebug('cntvuom='||l_tmp_old.content_volume_uom_code||' cntvol='||l_tmp_old.content_volume||' ctrvuom='||l_tmp_old.container_volume_uom||' ctrvol='||l_tmp_old.container_volume, G_INFO);
3057 END IF;
3058 END IF;
3059
3060 -- Add all attibutes to new lpn record
3061 l_tmp_new := l_tmp_old;
3062
3063 --8447369 start
3064 IF ( inv_cache.set_item_rec(
3065 p_organization_id => l_tmp_old.organization_id
3066 , p_item_id => l_tmp_old.inventory_item_id ) ) THEN
3067
3068 mdebug('Found parent lpn item details', G_INFO);
3069
3070 ELSE
3071 l_progress := 'Error calling INV_CACHE.Set_Item_Rec for orgid'||l_tmp_old.organization_id ||' item id='||l_tmp_old.inventory_item_id;
3072 mdebug('Did not find parent lpn item details', G_INFO);
3073
3074 END IF;
3075 --8447369 end
3076
3077 -- Update parent lpns gross weight
3078 IF ( NVL(l_change_in_gross_weight, 0) <> 0 AND l_change_in_gross_weight_uom IS NOT NULL ) THEN
3079 l_progress := 'Update parent LPN gross weight';
3080
3081 IF ( NVL(l_tmp_new.gross_weight, 0) = 0 OR l_tmp_new.gross_weight_uom_code IS NULL ) THEN
3082 l_tmp_new.gross_weight := l_change_in_gross_weight;
3083 l_tmp_new.gross_weight_uom_code := l_change_in_gross_weight_uom;
3084 ELSIF ( l_tmp_new.gross_weight_uom_code = l_change_in_gross_weight_uom ) THEN
3085 l_tmp_new.gross_weight := l_tmp_new.gross_weight + l_change_in_gross_weight;
3086 ELSE
3087 -- Both are not null but with different UOMs need to convert
3088 l_change_in_gross_weight := Convert_UOM(l_tmp_new.inventory_item_id, l_change_in_gross_weight, l_change_in_gross_weight_uom, l_tmp_new.gross_weight_uom_code, G_NO_CONV_RETURN_ZERO);
3089 l_change_in_gross_weight_uom := l_tmp_new.gross_weight_uom_code;
3090 l_tmp_new.gross_weight := l_tmp_new.gross_weight + l_change_in_gross_weight;
3091 END IF;
3092
3093 IF ( l_tmp_new.gross_weight < 0 ) THEN
3094 l_tmp_new.gross_weight := 0;
3095 END IF;
3096 END IF;
3097
3098 --8447369 start
3099 IF (inv_cache.item_rec.weight_uom_code IS NOT NULL ) THEN
3100 IF (l_tmp_new.gross_weight_uom_code <> inv_cache.item_rec.weight_uom_code ) THEN
3101 l_tmp_new.gross_weight := Convert_UOM(
3102 p_inventory_item_id => l_tmp_old.inventory_item_id
3103 , p_fm_quantity => l_tmp_new.gross_weight
3104 , p_fm_uom => l_tmp_new.gross_weight_uom_code
3105 , p_to_uom => inv_cache.item_rec.weight_uom_code
3106 , p_mode => G_NO_CONV_RETURN_ZERO );
3107 l_tmp_new.gross_weight_uom_code := inv_cache.item_rec.weight_uom_code;
3108 END IF;
3109 END IF;
3110 mdebug('after conv l_tmp_new.gross_weight' || l_tmp_new.gross_weight, G_INFO);
3111 mdebug('after conv l_tmp_new.gross_weight_uom_code' || l_tmp_new.gross_weight_uom_code, G_INFO);
3112
3113 --8447369 end
3114
3115 --16719248 Begin
3116 IF ( NVL(l_change_in_tare_weight, 0) <> 0 AND l_change_in_tare_weight_uom IS NOT NULL ) THEN
3117 IF ( NVL(l_tmp_new.gross_weight, 0) = 0 OR l_tmp_new.gross_weight_uom_code IS NULL ) THEN
3118 l_tmp_new.gross_weight := l_change_in_tare_weight;
3119 l_tmp_new.gross_weight_uom_code := l_change_in_tare_weight_uom;
3120 ELSIF ( l_tmp_new.gross_weight_uom_code = l_change_in_tare_weight_uom ) THEN
3121 l_tmp_new.gross_weight := l_tmp_new.gross_weight + l_change_in_tare_weight;
3122 ELSE
3123 -- Both are not null but with different UOMs need to convert
3124 l_outer_lpn_tare_change := convert_uom(l_tmp_new.inventory_item_id, l_change_in_tare_weight, l_change_in_tare_weight_uom, l_tmp_new.gross_weight_uom_code, G_NO_CONV_RETURN_ZERO);
3125 l_tmp_new.gross_weight := l_tmp_new.gross_weight + l_outer_lpn_tare_change;
3126 END IF;
3127
3128 IF (l_tmp_new.gross_weight < 0 ) THEN
3129 l_tmp_new.gross_weight := 0;
3130 END IF;
3131 IF (l_debug = 1) THEN
3132 mdebug('The new gross wt of outer LPN including inner LPN tare change is l_tmp_new.gross_weight:'||l_tmp_new.gross_weight,G_INFO );
3133 END IF;
3134 END IF;
3135 --16719248 End
3136
3137 -- bug5404902 add section just like above for tare weight
3138 -- Update parent lpns tare weight
3139 IF ( NVL(l_change_in_tare_weight, 0) <> 0 AND l_change_in_tare_weight_uom IS NOT NULL ) THEN
3140 l_progress := 'Update parent LPN tare weight';
3141
3142 IF ( NVL(l_tmp_new.tare_weight, 0) = 0 OR l_tmp_new.tare_weight_uom_code IS NULL ) THEN
3143 l_tmp_new.tare_weight := l_change_in_tare_weight;
3144 l_tmp_new.tare_weight_uom_code := l_change_in_tare_weight_uom;
3145 ELSIF ( l_tmp_new.tare_weight_uom_code = l_change_in_tare_weight_uom ) THEN
3146 l_tmp_new.tare_weight := l_tmp_new.tare_weight + l_change_in_tare_weight;
3147 ELSE
3148 -- Both are not null but with different UOMs need to convert
3149 l_change_in_tare_weight := Convert_UOM(l_tmp_new.inventory_item_id, l_change_in_tare_weight, l_change_in_tare_weight_uom, l_tmp_new.tare_weight_uom_code, G_NO_CONV_RETURN_ZERO);
3150 l_change_in_tare_weight_uom := l_tmp_new.tare_weight_uom_code;
3151 l_tmp_new.tare_weight := l_tmp_new.tare_weight + l_change_in_tare_weight;
3152 END IF;
3153
3154 IF ( l_tmp_new.tare_weight < 0 ) THEN
3155 l_tmp_new.tare_weight := 0;
3156 END IF;
3157 END IF;
3158
3159 --8447369 start
3160 IF (inv_cache.item_rec.weight_uom_code IS NOT NULL ) THEN
3161 IF (l_tmp_new.tare_weight_uom_code <> inv_cache.item_rec.weight_uom_code ) THEN
3162 l_tmp_new.tare_weight := Convert_UOM(
3163 p_inventory_item_id => l_tmp_old.inventory_item_id
3164 , p_fm_quantity => l_tmp_new.tare_weight
3165 , p_fm_uom => l_tmp_new.tare_weight_uom_code
3166 , p_to_uom => inv_cache.item_rec.weight_uom_code
3167 , p_mode => G_NO_CONV_RETURN_ZERO );
3168 l_tmp_new.tare_weight_uom_code := inv_cache.item_rec.weight_uom_code ;
3169 END IF;
3170 END IF;
3171 mdebug(' after conv l_tmp_new.tare_weight' || l_tmp_new.tare_weight, G_INFO);
3172 mdebug(' after conv l_tmp_new.tare_weight_uom_code' || l_tmp_new.tare_weight_uom_code, G_INFO);
3173 --8447369 end
3174
3175
3176 IF ( NVL(l_change_in_volume, 0) <> 0 AND l_change_in_volume_uom IS NOT NULL ) THEN
3177 -- Update parent lpns content volume
3178 IF ( NVL(l_tmp_old.content_volume, 0) = 0 OR l_tmp_old.content_volume_uom_code IS NULL ) THEN
3179 l_tmp_new.content_volume := l_change_in_volume;
3180 l_tmp_new.content_volume_uom_code := l_change_in_volume_uom;
3181 ELSIF ( l_tmp_old.content_volume_uom_code = l_change_in_volume_uom ) THEN
3182 l_tmp_new.content_volume := l_tmp_new.content_volume + l_change_in_volume;
3183 ELSE
3184 -- Both are not null but with different UOMs need to convert
3185 l_change_in_volume := Convert_UOM(l_tmp_new.inventory_item_id, l_change_in_volume, l_change_in_volume_uom, l_tmp_old.content_volume_uom_code, G_NO_CONV_RETURN_ZERO);
3186 l_change_in_volume_uom := l_tmp_old.content_volume_uom_code;
3187 l_tmp_new.content_volume := l_tmp_old.content_volume + l_change_in_volume;
3188 END IF;
3189
3190 -- If this LPN is with within another LPN then need to recalculate the change in
3191 -- volume since content volume used to add to it's parent may be based on the
3192 -- container item, not the contents. If no container item is defined then no need
3193 -- recalculate.
3194 IF ( l_tmp_new.parent_lpn_id IS NOT NULL AND
3195 NVL(l_tmp_old.container_volume, 0) <> 0 AND l_tmp_old.container_volume_uom IS NOT NULL )
3196 THEN
3197 l_progress := 'Call helper procedure to calculate change in parent volume';
3198 Calc_Vol_Change (
3199 p_debug => l_debug
3200 , p_old_lpn => l_tmp_old
3201 , p_new_lpn => l_tmp_new
3202 , p_volume_change => l_change_in_volume
3203 , p_volume_uom_change => l_change_in_volume_uom );
3204 END IF;
3205
3206 IF ( l_tmp_new.content_volume < 0 ) THEN
3207 l_tmp_new.content_volume := 0;
3208 END IF;
3209 END IF;
3210
3211 --Bug 8693053
3212 SELECT count (*) into honor_case_pick_count
3213 FROM mtl_material_transactions_temp mmtt, wms_user_task_type_attributes wutta
3214 WHERE mmtt.standard_operation_id = wutta.user_task_type_id
3215 AND mmtt.organization_id = wutta.organization_id
3216 AND mmtt.transfer_lpn_id = l_old.lpn_id
3217 AND honor_case_pick_flag = 'Y';
3218
3219 -- Done calculating changes for this LPN
3220 l_lpns(l_tmp_i) := l_tmp_new;
3221
3222 IF (l_debug = 1) THEN
3223 mdebug('New values for parent LPN lpnid='||l_tmp_new.lpn_id||' gwuom='||l_tmp_new.gross_weight_uom_code||' gwt='||l_tmp_new.gross_weight||' twuom='||l_tmp_new.tare_weight_uom_code||' twt='||l_tmp_new.tare_weight, G_INFO);
3224 mdebug('cntvuom='||l_tmp_new.content_volume_uom_code||' cntvol='||l_tmp_new.content_volume||' ctrvuom='||l_tmp_new.container_volume_uom||' ctrvol='||l_tmp_new.container_volume, G_INFO);
3225 mdebug('l_tmp_new.lpn_context '|| l_tmp_new.lpn_context || 'LPN_CONTEXT_PICKED '|| LPN_CONTEXT_PICKED, G_INFO);
3226 mdebug('ll_old.lpn_id '|| l_old.lpn_id, G_INFO);
3227 mdebug('honor_case_pick_count '|| honor_case_pick_count, G_INFO);
3228 END IF;
3229
3230 --Bug 8693053 If honorCasePick is enabled for the task, then we need not update the parentLPN
3231 IF honor_case_pick_count <= 0 THEN
3232
3233 IF ( l_tmp_new.lpn_context = LPN_CONTEXT_PICKED ) THEN
3234 -- Need to call shipping to update this LPNs wt and vol
3235 wsh_update_tbl(NVL(wsh_update_tbl.last, 0) + 1) := To_DeliveryDetailsRecType(l_tmp_new);
3236 END IF;
3237 END IF;
3238
3239 -- If there is no more change in weight of volume exit loop
3240 IF ( NVL(l_change_in_gross_weight, 0) = 0 AND NVL(l_change_in_volume, 0) = 0 ) THEN
3241 EXIT;
3242 END IF;
3243 END LOOP;
3244 l_progress := 'Done updating nest lpn wt/vol';
3245 END IF;
3246 -- Else this is the outermost lpn, no need recalculate change in volume
3247 END IF;
3248
3249 l_progress := 'Done updating based in lpn_id';
3250 l_lpns(l_lpn_tab_i) := l_new;
3251 END IF; -- End of section that pertains to the LPN itself
3252
3253 /************************************************************/
3254 /* Changes that only pertain to Update of entire heirarchy */
3255 /* Update or all lpns with same outermost LPN */
3256 /************************************************************/
3257 l_progress := 'Do updates that effect entire heirarcy';
3258 IF ( p_lpn_table(lpn_tbl_cnt).organization_id <> l_old.organization_id OR
3259 p_lpn_table(lpn_tbl_cnt).subinventory_code <> NVL(l_old.subinventory_code, G_NULL_CHAR) OR
3260 p_lpn_table(lpn_tbl_cnt).locator_id <> NVL(l_old.locator_id, G_NULL_NUM) OR
3261 p_lpn_table(lpn_tbl_cnt).lpn_context <> NVL(l_old.lpn_context, G_NULL_NUM) OR
3262 p_lpn_table(lpn_tbl_cnt).source_type_id <> NVL(l_old.source_type_id, G_NULL_NUM) OR
3263 p_lpn_table(lpn_tbl_cnt).source_header_id <> NVL(l_old.source_header_id, G_NULL_NUM) OR
3264 p_lpn_table(lpn_tbl_cnt).source_line_id <> NVL(l_old.source_line_id, G_NULL_NUM) OR
3265 p_lpn_table(lpn_tbl_cnt).source_line_detail_id <> NVL(l_old.source_line_detail_id , G_NULL_NUM)OR
3266 p_lpn_table(lpn_tbl_cnt).source_name <> NVL(l_old.source_name, G_NULL_CHAR) )
3267 THEN
3268 l_progress := 'Organization';
3269 IF ( p_lpn_table(lpn_tbl_cnt).organization_id = FND_API.G_MISS_NUM ) THEN
3270 l_progress := 'organization_id cannot be made null';
3271 fnd_message.set_name('WMS', 'WMS_UPDATE_LPN_ATTR_ERR');
3272 fnd_message.set_token('ATTR', 'organization_id');
3273 fnd_msg_pub.ADD;
3274 RAISE fnd_api.g_exc_error;
3275 ELSIF ( p_lpn_table(lpn_tbl_cnt).organization_id <> l_old.organization_id ) THEN
3276 l_new.organization_id := p_lpn_table(lpn_tbl_cnt).organization_id;
3277
3278 --Bug # 3516547
3279 --Added code to make sure that the Revision/Lot number/Serial Summary Entry are
3280 --updated from WLC in case of a transfer to an org that doesnt have those controls
3281 --for the item.
3282 FOR new_org IN lpn_item_control_cursor ( l_old.organization_id,
3283 l_new.organization_id,
3284 l_new.outermost_lpn_id )
3285 LOOP
3286 l_progress := 'Find the primary uom code for this item in the source org';
3287
3288 IF ( NOT inv_cache.set_item_rec(
3289 p_organization_id => l_old.organization_id
3290 , p_item_id => new_org.inventory_item_id ) )
3291 THEN
3292 l_progress := 'Error calling INV_CACHE.Set_Item_Rec for orgid='||l_old.organization_id||' item id='||new_org.inventory_item_id;
3293 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_ITEM');
3294 fnd_msg_pub.ADD;
3295 RAISE fnd_api.g_exc_error;
3296 END IF;
3297
3298 IF (l_debug = 1) THEN
3299 mdebug('Got WLC for orgxfer itm='||new_org.inventory_item_id||' oldpuom='||inv_cache.item_rec.primary_uom_code||' newpuom='||new_org.primary_uom_code||
3300 ' sctl='||new_org.serial_number_control_code||' lctl='||new_org.lot_control_code||' rctl='||new_org.revision_qty_control_code, G_INFO);
3301 END IF;
3302
3303 UPDATE wms_lpn_contents wlc
3304 SET wlc.last_update_date = SYSDATE
3305 , wlc.last_updated_by = fnd_global.user_id
3306 , wlc.organization_id = l_new.organization_id
3307 , wlc.serial_summary_entry = DECODE (new_org.serial_number_control_code,1,2,6,2,wlc.serial_summary_entry)
3308 , wlc.serial_number = DECODE (new_org.serial_number_control_code,1,NULL,6,NULL,wlc.serial_number)
3309 , wlc.lot_number = DECODE (new_org.lot_control_code,1,NULL,wlc.lot_number)
3310 , wlc.revision = DECODE (new_org.revision_qty_control_code,1,NULL,wlc.revision)
3311 , wlc.primary_quantity = Round(Convert_UOM(new_org.inventory_item_id, primary_quantity, inv_cache.item_rec.primary_uom_code, new_org.primary_uom_code), 5) --13591755 added for GRUPO
3312 WHERE rowid = new_org.rowid;
3313 END LOOP;
3314 END IF;
3315
3316 l_progress := 'Subiventory';
3317 IF ( p_lpn_table(lpn_tbl_cnt).subinventory_code = FND_API.G_MISS_CHAR ) THEN
3318 l_new.subinventory_code := NULL;
3319 ELSIF ( p_lpn_table(lpn_tbl_cnt).subinventory_code IS NOT NULL ) THEN
3320 l_new.subinventory_code := p_lpn_table(lpn_tbl_cnt).subinventory_code;
3321 END IF;
3322
3323 l_progress := 'Locator';
3324 IF ( p_lpn_table(lpn_tbl_cnt).locator_id = FND_API.G_MISS_NUM ) THEN
3325 l_new.locator_id := NULL;
3326 ELSIF ( p_lpn_table(lpn_tbl_cnt).locator_id IS NOT NULL ) THEN
3327 l_new.locator_id := p_lpn_table(lpn_tbl_cnt).locator_id;
3328 END IF;
3329
3330 l_progress := 'source_type_id';
3331 IF ( p_lpn_table(lpn_tbl_cnt).source_type_id = FND_API.G_MISS_NUM ) THEN
3332 l_new.source_type_id := NULL;
3333 ELSIF ( p_lpn_table(lpn_tbl_cnt).source_type_id IS NOT NULL ) THEN
3334 l_new.source_type_id := p_lpn_table(lpn_tbl_cnt).source_type_id;
3335 END IF;
3336
3337 l_progress := 'source_header_id';
3338 IF ( p_lpn_table(lpn_tbl_cnt).source_header_id = FND_API.G_MISS_NUM ) THEN
3339 l_new.source_header_id := NULL;
3340 ELSIF ( p_lpn_table(lpn_tbl_cnt).source_header_id IS NOT NULL ) THEN
3341 l_new.source_header_id := p_lpn_table(lpn_tbl_cnt).source_header_id;
3342 END IF;
3343
3344 l_progress := 'source_line_id';
3345 IF ( p_lpn_table(lpn_tbl_cnt).source_line_id = FND_API.G_MISS_NUM ) THEN
3346 l_new.source_line_id := NULL;
3347 ELSIF ( p_lpn_table(lpn_tbl_cnt).source_line_id IS NOT NULL ) THEN
3348 l_new.source_line_id := p_lpn_table(lpn_tbl_cnt).source_line_id;
3349 END IF;
3350
3351 l_progress := 'source_line_detail_id';
3352 IF ( p_lpn_table(lpn_tbl_cnt).source_line_detail_id = FND_API.G_MISS_NUM ) THEN
3353 l_new.source_line_detail_id := NULL;
3354 ELSIF ( p_lpn_table(lpn_tbl_cnt).source_line_detail_id IS NOT NULL ) THEN
3355 l_new.source_line_detail_id := p_lpn_table(lpn_tbl_cnt).source_line_detail_id;
3356 END IF;
3357
3358 l_progress := 'source_name';
3359 IF ( p_lpn_table(lpn_tbl_cnt).source_name = FND_API.G_MISS_CHAR ) THEN
3360 l_new.source_name := NULL;
3361 ELSIF ( p_lpn_table(lpn_tbl_cnt).source_name IS NOT NULL ) THEN
3362 l_new.source_name := p_lpn_table(lpn_tbl_cnt).source_name;
3363 END IF;
3364
3365 l_progress := 'Context';
3366 -- Must to context after sub and loc!
3367 IF ( p_lpn_table(lpn_tbl_cnt).lpn_context = FND_API.G_MISS_NUM ) THEN
3368 l_progress := 'LPN context cannot be made null';
3369 fnd_message.set_name('WMS', 'WMS_UPDATE_LPN_ATTR_ERR');
3370 fnd_message.set_token('ATTR', 'lpn_context');
3371 fnd_msg_pub.ADD;
3372 RAISE fnd_api.g_exc_error;
3373 ELSIF ( p_lpn_table(lpn_tbl_cnt).lpn_context <> l_old.lpn_context ) THEN
3374 l_new.lpn_context := p_lpn_table(lpn_tbl_cnt).lpn_context;
3375
3376 l_progress := 'Call API to validate context change';
3377 IF ( NOT Valid_Context_Change(p_caller, l_old.lpn_context, l_new.lpn_context) ) THEN
3378 l_progress := 'Failed Valid_Context_Change check';
3379 RAISE fnd_api.g_exc_error;
3380 END IF;
3381
3382 IF ( l_new.lpn_context = LPN_CONTEXT_STORES OR
3383 l_new.lpn_context = LPN_CONTEXT_PREGENERATED OR
3384 l_new.lpn_context = LPN_CONTEXT_INTRANSIT )
3385 THEN
3386 -- LPNs not in warehouse, cannot have location
3387 l_new.subinventory_code := NULL;
3388 l_new.locator_id := NULL;
3389 END IF;
3390 END IF;
3391
3392 l_progress := 'Add new record to update outermost lpn table to be updated';
3393 IF ( l_outer_lpn_ids.exists(l_new.outermost_lpn_id) ) THEN
3394 l_tmp_i := l_outer_lpn_ids(l_new.outermost_lpn_id);
3395 IF (l_debug = 1) THEN
3396 mdebug('LPN new outer already exist in table l_tmp_i='||l_tmp_i, G_INFO);
3397 END IF;
3398 ELSE
3399 l_tmp_i := NVL(l_outer_lpns.last, 0) + 1;
3400 l_outer_lpn_ids(l_new.outermost_lpn_id) := l_tmp_i;
3401 l_outer_lpns(l_tmp_i).reference_id := l_new.outermost_lpn_id;
3402
3403 IF (l_debug = 1) THEN
3404 mdebug('Create new outer entry in outer table l_tmp_i='||l_tmp_i, G_INFO);
3405 END IF;
3406 END IF;
3407
3408 l_outer_lpns(l_tmp_i).outermost_lpn_id := l_new.outermost_lpn_id;
3409 l_outer_lpns(l_tmp_i).organization_id := l_new.organization_id;
3410 l_outer_lpns(l_tmp_i).subinventory_code := l_new.subinventory_code;
3411 l_outer_lpns(l_tmp_i).locator_id := l_new.locator_id;
3412 l_outer_lpns(l_tmp_i).lpn_context := l_new.lpn_context;
3413 l_outer_lpns(l_tmp_i).source_type_id := l_new.source_type_id;
3414 l_outer_lpns(l_tmp_i).source_header_id := l_new.source_header_id;
3415 l_outer_lpns(l_tmp_i).source_line_id := l_new.source_line_id;
3416 l_outer_lpns(l_tmp_i).source_line_detail_id := l_new.source_line_detail_id;
3417 l_outer_lpns(l_tmp_i).source_name := l_new.source_name;
3418 END IF;
3419
3420 IF (l_debug = 1) THEN
3421 mdebug('New values from LPN updated l_lpn_tab_i='||l_lpn_tab_i||' lpn_tbl_cnt='||lpn_tbl_cnt, G_INFO);
3422 mdebug('lpnid='||l_new.lpn_id||' lpn='||l_new.license_plate_number||' ctx='||l_new.lpn_context||' plpn='||l_new.parent_lpn_id||' olpn='||l_new.outermost_lpn_id||' itm='||l_new.inventory_item_id||' rev='||l_new.revision, G_INFO);
3423 mdebug('lot='||l_new.lot_number||' sn='||l_new.serial_number||' cg='||l_new.cost_group_id||' org='||l_new.organization_id||' sub='||l_new.subinventory_code||' loc='||l_new.locator_id, G_INFO);
3424 mdebug('twt='||l_new.tare_weight||' twuom='||l_new.tare_weight_uom_code||' gwt='||l_new.gross_weight||' gwuom='||l_new.gross_weight_uom_code||
3425 ' ctrvol='||l_new.container_volume||' ctrvoluom='||l_new.container_volume_uom||' ctnvol='||l_new.content_volume||' ctvuom='||l_new.content_volume_uom_code, G_INFO);
3426 mdebug('stype='||l_new.source_type_id||' shdr='||l_new.source_header_id||' srcln='||l_new.source_line_id||' srclndt='||l_new.source_line_detail_id||' srcnm='||l_new.source_name, G_INFO);
3427 --mdebug('reuse='||l_new.lpn_reusability||' hom='||l_new.homogeneous_container||' stat='||l_new.status_id ||' seal='||l_new.sealed_status, G_INFO);
3428 mdebug('acat='||l_new.attribute_category||' a1='||l_new.attribute1||' a2='||l_new.attribute2||' a3='||l_new.attribute3||' a4='||l_new.attribute4||' a5='||l_new.attribute5||' a6='||l_new.attribute6||' a7='||l_new.attribute7, G_INFO);
3429 mdebug('a8='||l_new.attribute8||' a9='||l_new.attribute9||' a10='||l_new.attribute10||' a11='||l_new.attribute11||' a12='||l_new.attribute12||' a13='||l_new.attribute13||' a14='||l_new.attribute14||' a15='||l_new.attribute15, G_INFO);
3430 END IF;
3431
3432 -- Bug 5639121
3433 -- Check to find whether flow is for Internal Order
3434 -- LPN Context changes from 'Loaded to Truck' to "defined but not used'
3435 -- for Internal Orders only
3436 IF ( l_old.lpn_context = LPN_LOADED_FOR_SHIPMENT and l_new.lpn_context = LPN_CONTEXT_PREGENERATED ) THEN
3437 l_internal_order_flag := 1;
3438 END IF;
3439
3440 -- Bug 5246192
3441 -- when shipping a LPN for an internal requisition with direct routing,
3442 -- the .LPN's context is changed from Picked to Resides in Inventory in a different org
3443 -- In that case, the LPN should not be removed from WDD in the source org
3444 -- Add addition where clause that only when context is changed in the same org,
3445 -- then remove LPN from the WDD.
3446 -- Bug 7119011
3447
3448 BEGIN
3449
3450 select nvl(wda.delivery_id,999) into l_delivery_id
3451 from wsh_delivery_details wdd, wsh_delivery_assignments wda
3452 WHERE wda.delivery_detail_id(+) = wdd.delivery_detail_id AND ROWNUM < 2
3453 AND wdd.lpn_id IN
3454 ( select wlpn.lpn_id
3455 from wms_license_plate_numbers wlpn
3456 where wlpn.outermost_lpn_id = p_lpn_table(1).lpn_id);
3457
3458 IF (l_delivery_id <> 999) THEN
3459
3460 WSH_UTIL_CORE.GET_DELIVERY_STATUS(
3461 p_entity_type => 'DELIVERY'
3462 ,p_entity_id => l_delivery_id
3463 ,x_status_code => l_status_code
3464 ,x_return_status => l_return_status);
3465
3466 END IF ;
3467
3468 EXCEPTION
3469 WHEN NO_DATA_FOUND THEN
3470 IF ( l_debug = 1 ) THEN
3471 mdebug('There are no deliveries ', G_ERROR);
3472 END IF;
3473 END;
3474
3475 IF ( (l_old.lpn_context = LPN_CONTEXT_PICKED OR l_old.lpn_context = LPN_LOADED_FOR_SHIPMENT) AND
3476 (l_new.lpn_context = LPN_CONTEXT_INV OR l_new.lpn_context = LPN_CONTEXT_PREGENERATED) AND
3477 (l_old.organization_id = l_new.organization_id) -- Bug 5246192
3478 AND (l_internal_order_flag = 0) AND (NVL(l_status_code,'OP') <>'CL')) -- Bug 7603755
3479 THEN
3480 IF ( l_old.parent_lpn_id IS NOT NULL ) THEN
3481 -- Add this LPN to table so that it can be unpacked in WDD before deletion
3482 -- No need to specify parent LPN, shipping will derrive this
3483 l_wsh_unpack_lpn_id_tbl(NVL(l_wsh_unpack_lpn_id_tbl.last, 0) + 1) := l_old.lpn_id;
3484 END IF;
3485
3486 -- Add this LPN to table so that it can be deleted from WDD
3487 -- No need to specify parent LPN, shipping will derrive this
3488 l_wsh_delete_lpn_id_tbl(NVL(l_wsh_delete_lpn_id_tbl.last, 0) + 1) := l_old.lpn_id;
3489
3490 ELSIF ( l_old.lpn_context = LPN_CONTEXT_PICKED AND l_new.lpn_context = LPN_CONTEXT_PICKED) THEN
3491 IF ( NVL(l_old.inventory_item_id, G_NULL_NUM) <> NVL(l_new.inventory_item_id, G_NULL_NUM) OR
3492 NVL(l_old.tare_weight, G_NULL_NUM) <> NVL(l_new.tare_weight, G_NULL_NUM) OR
3493 NVL(l_old.tare_weight_uom_code, G_NULL_CHAR) <> NVL(l_new.tare_weight_uom_code, G_NULL_CHAR) OR
3494 NVL(l_old.gross_weight, G_NULL_NUM) <> NVL(l_new.gross_weight, G_NULL_NUM) OR
3495 NVL(l_old.gross_weight_uom_code, G_NULL_CHAR) <> NVL(l_new.gross_weight_uom_code, G_NULL_CHAR) OR
3496 NVL(l_old.container_volume, G_NULL_NUM) <> NVL(l_new.container_volume, G_NULL_NUM) OR
3497 NVL(l_old.container_volume_uom, G_NULL_CHAR) <> NVL(l_new.container_volume_uom, G_NULL_CHAR) OR
3498 NVL(l_old.content_volume, G_NULL_NUM) <> NVL(l_new.content_volume, G_NULL_NUM) OR
3499 NVL(l_old.content_volume_uom_code, G_NULL_CHAR) <> NVL(l_new.content_volume_uom_code, G_NULL_CHAR) )
3500 THEN
3501 -- If some attribute that shipping cares about has been changed
3502 -- Need to call shipping to update this LPNs attributes
3503 wsh_update_tbl(NVL(wsh_update_tbl.last, 0) + 1) := To_DeliveryDetailsRecType(l_new);
3504 ELSIF ( NVL(l_old.subinventory_code, G_NULL_CHAR) <> NVL(l_new.subinventory_code, G_NULL_CHAR) OR
3505 NVL(l_old.locator_id, G_NULL_NUM) <> NVL(l_new.locator_id, G_NULL_NUM) )
3506 THEN
3507 -- If any of the following attributes were changed need to inform shipping
3508 -- add record to call WSH_WMS_LPN_GRP.create_update_containers
3509 l_tmp_i := NVL(wsh_update_tbl.last, 0) + 1;
3510
3511 wsh_update_tbl(l_tmp_i).organization_id := l_new.organization_id;
3512 wsh_update_tbl(l_tmp_i).lpn_id := l_new.outermost_lpn_id;
3513 wsh_update_tbl(l_tmp_i).container_name := l_new.license_plate_number;
3514 wsh_update_tbl(l_tmp_i).subinventory := l_new.subinventory_code;
3515 wsh_update_tbl(l_tmp_i).locator_id := l_new.locator_id;
3516 END IF;
3517 ELSIF ( l_old.lpn_context <> LPN_CONTEXT_PICKED AND l_new.lpn_context = LPN_CONTEXT_PICKED ) THEN
3518 -- Need to call shipping to create this record
3519 wsh_create_tbl(NVL(wsh_create_tbl.last, 0) + 1) := To_DeliveryDetailsRecType(l_new);
3520 END IF;
3521
3522
3523 IF ( wsh_create_tbl.last > 0 ) THEN
3524 IF (l_debug = 1) THEN
3525 mdebug('Calling WSH API to create WDD count='||wsh_create_tbl.last, G_INFO);
3526 END IF;
3527
3528 l_IN_rec.caller := 'WMS';
3529 l_IN_rec.action_code := 'CREATE';
3530
3531 WSH_WMS_LPN_GRP.Create_Update_Containers (
3532 p_api_version => 1.0
3533 , p_init_msg_list => fnd_api.g_false
3534 , p_commit => fnd_api.g_false
3535 , x_return_status => x_return_status
3536 , x_msg_count => x_msg_count
3537 , x_msg_data => x_msg_data
3538 , p_detail_info_tab => wsh_create_tbl
3539 , p_IN_rec => l_IN_rec
3540 , x_OUT_rec => l_OUT_rec );
3541
3542 IF ( x_return_status <> fnd_api.g_ret_sts_success ) THEN
3543 IF (l_debug = 1) THEN
3544 mdebug('Create_Update_Containers Failed, May alreade exist in WDD, Try update instead', G_ERROR);
3545 FOR i in 1..x_msg_count LOOP
3546 l_msgdata := substr(l_msgdata||' | '||substr(fnd_msg_pub.get(x_msg_count-i+1, 'F'), 0, 200),1,2000);
3547 END LOOP;
3548 mdebug('msg: '||l_msgdata, G_ERROR);
3549 END IF;
3550 l_IN_rec.action_code := 'UPDATE';
3551
3552 WSH_WMS_LPN_GRP.Create_Update_Containers (
3553 p_api_version => 1.0
3554 , p_init_msg_list => fnd_api.g_false
3555 , p_commit => fnd_api.g_false
3556 , x_return_status => x_return_status
3557 , x_msg_count => x_msg_count
3558 , x_msg_data => x_msg_data
3559 , p_detail_info_tab => wsh_create_tbl
3560 , p_IN_rec => l_IN_rec
3561 , x_OUT_rec => l_OUT_rec );
3562 END IF;
3563
3564 IF ( x_return_status <> fnd_api.g_ret_sts_success ) THEN
3565 IF (l_debug = 1) THEN
3566 mdebug('WSH Create Containers Failed', G_ERROR);
3567 END IF;
3568 RAISE fnd_api.g_exc_error;
3569 ELSIF ( l_debug = 1 ) THEN
3570 mdebug('Done with Create_Update_Containers', G_INFO);
3571 END IF;
3572
3573 -- Once Create is done need to clear table
3574 wsh_create_tbl.delete;
3575 END IF;
3576
3577 -- Call Update shipping on an per record basis
3578 IF ( wsh_update_tbl.last > 0 ) THEN
3579 IF (l_debug = 1) THEN
3580 mdebug('Calling WSH API to update WDD count='||wsh_update_tbl.last, G_INFO);
3581 END IF;
3582
3583 l_IN_rec.caller := 'WMS';
3584 l_IN_rec.action_code := 'UPDATE';
3585
3586 WSH_WMS_LPN_GRP.Create_Update_Containers (
3587 p_api_version => 1.0
3588 , p_init_msg_list => fnd_api.g_false
3589 , p_commit => fnd_api.g_false
3590 , x_return_status => x_return_status
3591 , x_msg_count => x_msg_count
3592 , x_msg_data => x_msg_data
3593 , p_detail_info_tab => wsh_update_tbl
3594 , p_IN_rec => l_IN_rec
3595 , x_OUT_rec => l_OUT_rec );
3596
3597 IF ( x_return_status <> fnd_api.g_ret_sts_success ) THEN
3598 IF (l_debug = 1) THEN
3599 mdebug('Create_Update_Containers Failed, Might not yet exist in WDD, Try create instead', G_ERROR);
3600 FOR i in 1..x_msg_count LOOP
3601 l_msgdata := substr(l_msgdata||' | '||substr(fnd_msg_pub.get(x_msg_count-i+1, 'F'), 0, 200),1,2000);
3602 END LOOP;
3603 mdebug('msg: '||l_msgdata, G_ERROR);
3604 END IF;
3605 l_IN_rec.action_code := 'CREATE';
3606
3607 WSH_WMS_LPN_GRP.Create_Update_Containers (
3608 p_api_version => 1.0
3609 , p_init_msg_list => fnd_api.g_false
3610 , p_commit => fnd_api.g_false
3611 , x_return_status => x_return_status
3612 , x_msg_count => x_msg_count
3613 , x_msg_data => x_msg_data
3614 , p_detail_info_tab => wsh_update_tbl
3615 , p_IN_rec => l_IN_rec
3616 , x_OUT_rec => l_OUT_rec );
3617 END IF;
3618
3619 IF ( x_return_status <> fnd_api.g_ret_sts_success ) THEN
3620 IF (l_debug = 1) THEN
3621 mdebug('WSH Update Containers Failed', G_ERROR);
3622 END IF;
3623 RAISE fnd_api.g_exc_error;
3624 ELSIF ( l_debug = 1 ) THEN
3625 mdebug('Done with Create_Update_Containers', G_INFO);
3626 END IF;
3627
3628 -- Once update is done need to clear table
3629 wsh_update_tbl.delete;
3630 END IF;
3631
3632 IF (l_debug = 1) THEN
3633 mdebug('Done processing lpn_id='||l_old.lpn_id, G_INFO);
3634 END IF;
3635 END LOOP;
3636
3637 l_progress := 'Done with data handling, transfer to LPN bulk record of tables';
3638
3639 IF ( l_wsh_unpack_lpn_id_tbl.last > 0 ) THEN
3640 IF (l_debug = 1) THEN
3641 mdebug('Call to WSH Delivery_Detail_Action unpack LPNs before becoming pregenerated: '||l_wsh_unpack_lpn_id_tbl.first||'-'||l_wsh_unpack_lpn_id_tbl.last, G_INFO);
3642 END IF;
3643
3644 l_wsh_action_prms.caller := 'WMS';
3645 l_wsh_action_prms.action_code := 'UNPACK';
3646
3647 WSH_WMS_LPN_GRP.Delivery_Detail_Action (
3648 p_api_version_number => 1.0
3649 , p_init_msg_list => fnd_api.g_false
3650 , p_commit => fnd_api.g_false
3651 , x_return_status => x_return_status
3652 , x_msg_count => x_msg_count
3653 , x_msg_data => x_msg_data
3654 , p_lpn_id_tbl => l_wsh_unpack_lpn_id_tbl
3655 , p_del_det_id_tbl => l_wsh_del_det_id_tbl
3656 , p_action_prms => l_wsh_action_prms
3657 , x_defaults => l_wsh_defaults
3658 , x_action_out_rec => l_wsh_action_out_rec );
3659
3660 IF (x_return_status <> fnd_api.g_ret_sts_success) THEN
3661 l_progress := 'Delivery_Detail_Action failed';
3662 --RAISE fnd_api.g_exc_error;
3663
3664 IF ( x_return_status = fnd_api.g_ret_sts_error ) THEN
3665 RAISE fnd_api.g_exc_error;
3666 ELSIF ( l_debug = 1 ) THEN
3667 mdebug('x_return_status='||x_return_status, G_INFO);
3668 END IF;
3669 ELSIF (l_debug = 1) THEN
3670 mdebug('Done with call to WSH Create_Update_Containers', G_INFO);
3671 END IF;
3672
3673 -- Clear used parameters for completeness
3674 l_wsh_action_prms.caller := NULL;
3675 l_wsh_action_prms.action_code := NULL;
3676 l_wsh_unpack_lpn_id_tbl.delete;
3677 END IF;
3678
3679 IF ( l_wsh_delete_lpn_id_tbl.last > 0 ) THEN
3680 IF (l_debug = 1) THEN
3681 mdebug('Calling WSH API to remove LPN from WDD: '||l_wsh_delete_lpn_id_tbl.first||'-'||l_wsh_delete_lpn_id_tbl.last, G_INFO);
3682 END IF;
3683
3684 l_wsh_action_prms.caller := 'WMS';
3685 l_wsh_action_prms.action_code := 'DELETE';
3686
3687 WSH_WMS_LPN_GRP.Delivery_Detail_Action (
3688 p_api_version_number => 1.0
3689 , p_init_msg_list => fnd_api.g_false
3690 , p_commit => fnd_api.g_false
3691 , x_return_status => x_return_status
3692 , x_msg_count => x_msg_count
3693 , x_msg_data => x_msg_data
3694 , p_lpn_id_tbl => l_wsh_delete_lpn_id_tbl
3695 , p_del_det_id_tbl => l_wsh_del_det_id_tbl
3696 , p_action_prms => l_wsh_action_prms
3697 , x_defaults => l_wsh_defaults
3698 , x_action_out_rec => l_wsh_action_out_rec );
3699
3700 IF ( x_return_status <> fnd_api.g_ret_sts_success ) THEN
3701 IF (l_debug = 1) THEN
3702 mdebug('Delivery_Detail_Action Not Successful', G_ERROR);
3703 END IF;
3704
3705 IF ( x_return_status = fnd_api.g_ret_sts_error ) THEN
3706 RAISE fnd_api.g_exc_error;
3707 ELSIF ( l_debug = 1 ) THEN
3708 mdebug('x_return_status='||x_return_status, G_INFO);
3709 END IF;
3710 ELSIF ( l_debug = 1 ) THEN
3711 mdebug('Done with Delivery_Detail_Action', G_INFO);
3712 END IF;
3713
3714 -- Clear parameters used
3715 l_wsh_action_prms.caller := NULL;
3716 l_wsh_action_prms.action_code := NULL;
3717 l_wsh_delete_lpn_id_tbl.delete;
3718 END IF;
3719
3720 IF ( l_lpns.last > 0 ) THEN
3721 l_progress := 'Update LPNs last='||l_outer_lpns.last;
3722 l_lpn_bulk_rec := To_LPNBulkRecType(l_lpns);
3723
3724 IF (l_debug = 1) THEN
3725 mdebug('Bulk Update LPNs in WLPN: '||l_lpn_bulk_rec.lpn_id.first||'-'||l_lpn_bulk_rec.lpn_id.last, G_INFO);
3726
3727 /*(FOR bulk_i IN l_lpn_bulk_rec.outermost_lpn_id.first .. l_lpn_bulk_rec.outermost_lpn_id.last LOOP
3728 mdebug('lpn_id='|| l_lpn_bulk_rec.lpn_id(bulk_i));
3729 END LOOP;*/
3730 END IF;
3731
3732 BEGIN
3733 FORALL bulk_i IN l_lpn_bulk_rec.lpn_id.first .. l_lpn_bulk_rec.lpn_id.last
3734 UPDATE wms_license_plate_numbers wlpn
3735 SET last_update_date = SYSDATE
3736 , last_updated_by = fnd_global.user_id
3737 , organization_id = l_lpn_bulk_rec.organization_id(bulk_i)
3738 , license_plate_number = l_lpn_bulk_rec.license_plate_number(bulk_i)
3739 , parent_lpn_id = l_lpn_bulk_rec.parent_lpn_id(bulk_i)
3740 , outermost_lpn_id = l_lpn_bulk_rec.outermost_lpn_id(bulk_i)
3741 , inventory_item_id = l_lpn_bulk_rec.inventory_item_id(bulk_i)
3742 , subinventory_code = l_lpn_bulk_rec.subinventory_code(bulk_i)
3743 , locator_id = l_lpn_bulk_rec.locator_id(bulk_i)
3744 , tare_weight = l_lpn_bulk_rec.tare_weight(bulk_i)
3745 , tare_weight_uom_code = l_lpn_bulk_rec.tare_weight_uom_code(bulk_i)
3746 , gross_weight_uom_code = l_lpn_bulk_rec.gross_weight_uom_code(bulk_i)
3747 , gross_weight = l_lpn_bulk_rec.gross_weight(bulk_i)
3748 , container_volume = l_lpn_bulk_rec.container_volume(bulk_i)
3749 , container_volume_uom = l_lpn_bulk_rec.container_volume_uom(bulk_i)
3750 , content_volume_uom_code = l_lpn_bulk_rec.content_volume_uom_code(bulk_i)
3751 , content_volume = l_lpn_bulk_rec.content_volume(bulk_i)
3752 --, status_id = l_lpn_bulk_rec.status_id(bulk_i)
3753 , lpn_context = l_lpn_bulk_rec.lpn_context(bulk_i)
3754 --, sealed_status = l_lpn_bulk_rec.sealed_status(bulk_i)
3755 , attribute_category = l_lpn_bulk_rec.attribute_category(bulk_i)
3756 , attribute1 = l_lpn_bulk_rec.attribute1(bulk_i)
3757 , attribute2 = l_lpn_bulk_rec.attribute2(bulk_i)
3758 , attribute3 = l_lpn_bulk_rec.attribute3(bulk_i)
3759 , attribute4 = l_lpn_bulk_rec.attribute4(bulk_i)
3760 , attribute5 = l_lpn_bulk_rec.attribute5(bulk_i)
3761 , attribute6 = l_lpn_bulk_rec.attribute6(bulk_i)
3762 , attribute7 = l_lpn_bulk_rec.attribute7(bulk_i)
3763 , attribute8 = l_lpn_bulk_rec.attribute8(bulk_i)
3764 , attribute9 = l_lpn_bulk_rec.attribute9(bulk_i)
3765 , attribute10 = l_lpn_bulk_rec.attribute10(bulk_i)
3766 , attribute11 = l_lpn_bulk_rec.attribute11(bulk_i)
3767 , attribute12 = l_lpn_bulk_rec.attribute12(bulk_i)
3768 , attribute13 = l_lpn_bulk_rec.attribute13(bulk_i)
3769 , attribute14 = l_lpn_bulk_rec.attribute14(bulk_i)
3770 , attribute15 = l_lpn_bulk_rec.attribute15(bulk_i)
3771 , source_type_id = l_lpn_bulk_rec.source_type_id(bulk_i)
3772 , source_header_id = l_lpn_bulk_rec.source_header_id(bulk_i)
3773 , source_line_id = l_lpn_bulk_rec.source_line_id(bulk_i)
3774 , source_line_detail_id = l_lpn_bulk_rec.source_line_detail_id(bulk_i)
3775 , source_name = l_lpn_bulk_rec.source_name(bulk_i)
3776 WHERE lpn_id = l_lpn_bulk_rec.lpn_id(bulk_i);
3777 EXCEPTION
3778 WHEN DUP_VAL_ON_INDEX THEN
3779 IF ( l_debug = 1 ) THEN
3780 mdebug('Bulk Update WLPN failed uniqueness constraint', G_ERROR);
3781 END IF;
3782
3783 FOR bulk_i IN l_lpn_bulk_rec.lpn_id.first..l_lpn_bulk_rec.lpn_id.last LOOP
3784 BEGIN
3785 SELECT 1 INTO l_dummy_num
3786 FROM wms_license_plate_numbers
3787 WHERE license_plate_number = l_lpn_bulk_rec.license_plate_number(bulk_i);
3788
3789 IF ( l_debug = 1 ) THEN
3790 mdebug('LPN '||l_lpn_bulk_rec.license_plate_number(bulk_i)||' already exists, cannot update another LPN with this name', G_ERROR);
3791 END IF;
3792 fnd_message.set_name('WMS', 'WMS_CONT_DUPLICATE_LPN');
3793 fnd_message.set_token('LPN', l_lpn_bulk_rec.license_plate_number(bulk_i));
3794 fnd_msg_pub.ADD;
3795 RAISE fnd_api.g_exc_error;
3796 EXCEPTION
3797 WHEN NO_DATA_FOUND THEN
3798 NULL;
3799 END;
3800 END LOOP;
3801 END;
3802
3803 IF (l_debug = 1) THEN
3804 mdebug('Bulk Updated WLPN count='||SQL%ROWCOUNT, G_INFO);
3805 END IF;
3806 END IF;
3807
3808 IF ( l_outer_lpns.last > 0 ) THEN
3809 l_progress := 'Update outermost LPNs last='||l_outer_lpns.last;
3810 l_lpn_bulk_rec := To_LPNBulkRecType(l_outer_lpns);
3811
3812 IF (l_debug = 1) THEN
3813 mdebug('Bulk Update outermost LPNs in WLPN: '||l_lpn_bulk_rec.lpn_id.first||'-'||l_lpn_bulk_rec.lpn_id.last, G_INFO);
3814
3815 /*FOR bulk_i IN l_lpn_bulk_rec.outermost_lpn_id.first .. l_lpn_bulk_rec.outermost_lpn_id.last LOOP
3816 mdebug('reference_id ='|| l_lpn_bulk_rec.reference_id(bulk_i));
3817 END LOOP;*/
3818 END IF;
3819
3820 FORALL bulk_i IN l_lpn_bulk_rec.outermost_lpn_id.first .. l_lpn_bulk_rec.outermost_lpn_id.last
3821 UPDATE wms_license_plate_numbers wlpn
3822 SET last_update_date = SYSDATE
3823 , last_updated_by = fnd_global.user_id
3824 , outermost_lpn_id = l_lpn_bulk_rec.outermost_lpn_id(bulk_i)
3825 , organization_id = l_lpn_bulk_rec.organization_id(bulk_i)
3826 , subinventory_code = l_lpn_bulk_rec.subinventory_code(bulk_i)
3827 , locator_id = l_lpn_bulk_rec.locator_id(bulk_i)
3828 , lpn_context = l_lpn_bulk_rec.lpn_context(bulk_i)
3829 , source_type_id = l_lpn_bulk_rec.source_type_id(bulk_i)
3830 , source_header_id = l_lpn_bulk_rec.source_header_id(bulk_i)
3831 , source_line_id = l_lpn_bulk_rec.source_line_id(bulk_i)
3832 , source_line_detail_id = l_lpn_bulk_rec.source_line_detail_id(bulk_i)
3833 , source_name = l_lpn_bulk_rec.source_name(bulk_i)
3834 WHERE outermost_lpn_id = l_lpn_bulk_rec.reference_id(bulk_i);
3835
3836 IF (l_debug = 1) THEN
3837 mdebug('Bulk Updated outermost WLPN count='||SQL%ROWCOUNT, G_INFO);
3838 END IF;
3839 END IF;
3840
3841 -- Standard check of p_commit.
3842 IF fnd_api.to_boolean(p_commit) THEN
3843 COMMIT WORK;
3844 END IF;
3845
3846 -- Standard call to get message count and data
3847 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
3848 EXCEPTION
3849 WHEN FND_API.G_EXC_ERROR THEN
3850 x_return_status := fnd_api.g_ret_sts_error;
3851 FND_MSG_PUB.Count_And_Get(p_count => x_msg_count, p_data => x_msg_data);
3852 IF (l_debug = 1) THEN
3853 FOR i in 1..x_msg_count LOOP
3854 l_msgdata := substr(l_msgdata||' | '||substr(fnd_msg_pub.get(x_msg_count-i+1, 'F'), 0, 200),1,2000);
3855 END LOOP;
3856 mdebug(l_api_name ||' Error progress='||l_progress||' SQL error: '|| SQLERRM(SQLCODE), G_ERROR);
3857 mdebug('msg: '||l_msgdata, G_ERROR);
3858 END IF;
3859 ROLLBACK TO MODIFY_LPNS_PVT;
3860 --WHEN NOWAIT THEN
3861 -- x_return_status := fnd_api.g_ret_sts_unexp_error;
3862 WHEN OTHERS THEN
3863 x_return_status := fnd_api.g_ret_sts_unexp_error;
3864 fnd_message.set_name('WMS', 'WMS_UPDATE_LPN_FAILED');
3865 fnd_msg_pub.ADD;
3866 FND_MSG_PUB.Count_And_Get(p_count => x_msg_count, p_data => x_msg_data);
3867 IF (l_debug = 1) THEN
3868 mdebug(l_api_name ||' Error progress='||l_progress||' SQL error: '|| SQLERRM(SQLCODE), G_ERROR);
3869 END IF;
3870 ROLLBACK TO MODIFY_LPNS_PVT;
3871 END Modify_LPNs;
3872
3873 -- ----------------------------------------------------------------------------------
3874 -- ----------------------------------------------------------------------------------
3875
3876 PROCEDURE Generate_LPN_CP (
3877 errbuf OUT NOCOPY VARCHAR2
3878 , retcode OUT NOCOPY NUMBER
3879 , p_api_version IN NUMBER
3880 , p_organization_id IN NUMBER
3881 , p_container_item_id IN NUMBER := NULL
3882 , p_revision IN VARCHAR2 := NULL
3883 , p_lot_number IN VARCHAR2 := NULL
3884 , p_from_serial_number IN VARCHAR2 := NULL
3885 , p_to_serial_number IN VARCHAR2 := NULL
3886 , p_subinventory IN VARCHAR2 := NULL
3887 , p_locator_id IN NUMBER := NULL
3888 , p_org_parameters IN NUMBER
3889 , p_parm_dummy_1 IN VARCHAR2
3890 , p_total_length IN NUMBER
3891 , p_lpn_prefix IN VARCHAR2 := NULL
3892 , p_starting_num IN NUMBER := NULL
3893 , p_ucc_128_suffix_flag IN NUMBER
3894 , p_parm_dummy_2 IN VARCHAR2
3895 , p_lpn_suffix IN VARCHAR2 := NULL
3896 , p_quantity IN NUMBER := 1
3897 , p_source IN NUMBER := LPN_CONTEXT_PREGENERATED
3898 , p_cost_group_id IN NUMBER := NULL
3899 ) IS
3900 BEGIN
3901 Generate_LPN_CP (
3902 errbuf => errbuf
3903 , retcode => retcode
3904 , p_api_version => p_api_version
3905 , p_organization_id => p_organization_id
3906 , p_container_item_id => p_container_item_id
3907 , p_revision => p_revision
3908 , p_lot_number => p_lot_number
3909 , p_from_serial_number => p_from_serial_number
3910 , p_to_serial_number => p_to_serial_number
3911 , p_subinventory => p_subinventory
3912 , p_locator_id => p_locator_id
3913 , p_org_parameters => p_org_parameters
3914 , p_parm_dummy_1 => p_parm_dummy_1
3915 , p_total_length => p_total_length
3916 , p_lpn_prefix => p_lpn_prefix
3917 , p_starting_num => p_starting_num
3918 , p_ucc_128_suffix_flag => p_ucc_128_suffix_flag
3919 , p_parm_dummy_2 => p_parm_dummy_2
3920 , p_lpn_suffix => p_lpn_suffix
3921 , p_quantity => p_quantity
3922 , p_source => p_source
3923 , p_cost_group_id => p_cost_group_id
3924 , p_client_code => NULL
3925 );
3926 END;
3927
3928 ------------------------------------------------------------------------
3929 -- Added For LSP Project, bug 9087971
3930 -- Overloaded Procedure added for LSPs with additional parameter as p_client_code
3931 ------------------------------------------------------------------------
3932 PROCEDURE Generate_LPN_CP (
3933 errbuf OUT NOCOPY VARCHAR2
3934 , retcode OUT NOCOPY NUMBER
3935 , p_api_version IN NUMBER
3936 , p_organization_id IN NUMBER
3937 , p_container_item_id IN NUMBER := NULL
3938 , p_revision IN VARCHAR2 := NULL
3939 , p_lot_number IN VARCHAR2 := NULL
3940 , p_from_serial_number IN VARCHAR2 := NULL
3941 , p_to_serial_number IN VARCHAR2 := NULL
3942 , p_subinventory IN VARCHAR2 := NULL
3943 , p_locator_id IN NUMBER := NULL
3944 , p_org_parameters IN NUMBER
3945 , p_parm_dummy_1 IN VARCHAR2
3946 , p_total_length IN NUMBER
3947 , p_lpn_prefix IN VARCHAR2 := NULL
3948 , p_starting_num IN NUMBER := NULL
3949 , p_ucc_128_suffix_flag IN NUMBER
3950 , p_parm_dummy_2 IN VARCHAR2
3951 , p_lpn_suffix IN VARCHAR2 := NULL
3952 , p_quantity IN NUMBER := 1
3953 , p_source IN NUMBER := LPN_CONTEXT_PREGENERATED
3954 , p_cost_group_id IN NUMBER := NULL
3955 , p_client_code IN VARCHAR2 -- Adding for LSP, bug 9087971
3956 ) IS
3957 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
3958 x_return_status VARCHAR2(4);
3959 x_msg_count NUMBER;
3960 x_msg_data VARCHAR2(300);
3961 ret BOOLEAN;
3962
3963 l_ucc_128_suffix_flag VARCHAR2(1);
3964 l_lpn_prefix VARCHAR2(50);
3965 l_lpn_suffix VARCHAR2(50);
3966 l_wms_org_flag BOOLEAN;
3967
3968 l_lpn_att_rec WMS_Data_Type_Definitions_PUB.LPNRecordType;
3969 l_serial_tbl WMS_Data_Type_Definitions_PUB.SerialRangeTableType;
3970 l_gen_lpn_tbl WMS_Data_Type_Definitions_PUB.LPNTableType;
3971
3972 BEGIN
3973 IF (l_debug = 1) THEN
3974 mdebug('Generate_LPN_CP Entered '|| g_pkg_version, 1);
3975 mdebug('orgid=' ||p_organization_id||' sub='||p_subinventory||' loc='||p_locator_id||' orgparam='||p_org_parameters||' src=' ||p_source, G_INFO);
3976 mdebug('cntitemid=' ||p_container_item_id|| ' rev=' ||p_revision||' lot='||p_lot_number||' fmsn='||p_from_serial_number||' tosn='||p_to_serial_number||' cg='||p_cost_group_id, G_INFO);
3977 mdebug('prefix='||p_lpn_prefix||' suffix='|| p_lpn_suffix ||' strtnum='||p_starting_num ||' qty='||p_quantity||' lgth='||p_total_length||' ucc='||p_ucc_128_suffix_flag, G_INFO);
3978 END IF;
3979
3980 -- Bug 5144565 Check if the organization is a WMS organization
3981 l_wms_org_flag := wms_install.check_install (
3982 x_return_status => x_return_status
3983 , x_msg_count => x_msg_count
3984 , x_msg_data => x_msg_data
3985 , p_organization_id => p_organization_id );
3986 IF ( x_return_status <> fnd_api.g_ret_sts_success ) THEN
3987 IF ( l_debug = 1 ) THEN
3988 mdebug('Call to wms_install.check_install failed:' ||x_msg_data, 1);
3989 END IF;
3990 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3991 END IF;
3992
3993 IF ( NOT l_wms_org_flag ) THEN
3994 IF ( l_debug = 1 ) THEN
3995 mdebug('Generate License Plate concurrent program is only available for WMS enabled organizations', 1);
3996 END IF;
3997 fnd_message.set_name('WMS', 'WMS_ONLY_FUNCTIONALITY');
3998 fnd_msg_pub.ADD;
3999 RAISE fnd_api.g_exc_error;
4000 END IF;
4001
4002 --7270863 the condition IF ( l_ucc_128_suffix_flag IS NULL ) will be successful now if l_ucc_128_suffix_flag value is null in Auto_Create_LPNs
4003 --'N' will be passed only if it is having some values(2) other than 1
4004 IF ( p_ucc_128_suffix_flag = 1 ) THEN
4005 l_ucc_128_suffix_flag := 'Y';
4006 ELSIF p_ucc_128_suffix_flag is NOT NULL THEN --7270863
4007 l_ucc_128_suffix_flag := 'N';
4008 END IF;
4009
4010 -- Bug 4691144 If the default from org parameters is set to 'no'
4011 -- Set prefix and suffix to NULL.
4012 IF ( p_org_parameters = 2 ) THEN
4013 IF ( p_lpn_prefix IS NULL ) THEN
4014 l_lpn_prefix := FND_API.G_MISS_CHAR;
4015 ELSE
4016 l_lpn_prefix := p_lpn_prefix;
4017 END IF;
4018
4019 IF ( p_lpn_suffix IS NULL ) THEN
4020 l_lpn_suffix := FND_API.G_MISS_CHAR;
4021 ELSE
4022 l_lpn_suffix := p_lpn_suffix;
4023 END IF;
4024 END IF;
4025
4026 l_lpn_att_rec.lpn_context := p_source;
4027 l_lpn_att_rec.organization_id := p_organization_id;
4028 l_lpn_att_rec.subinventory_code := p_subinventory;
4029 l_lpn_att_rec.locator_id := p_locator_id;
4030 l_lpn_att_rec.inventory_item_id := p_container_item_id;
4031 l_lpn_att_rec.revision := p_revision;
4032 l_lpn_att_rec.lot_number := p_lot_number;
4033 l_lpn_att_rec.cost_group_id := p_cost_group_id;
4034
4035 l_serial_tbl(1).fm_serial_number := p_from_serial_number;
4036 l_serial_tbl(1).to_serial_number := p_to_serial_number;
4037
4038 Auto_Create_LPNs (
4039 p_api_version => p_api_version
4040 , p_init_msg_list => fnd_api.g_false
4041 , p_commit => fnd_api.g_false
4042 , x_return_status => x_return_status
4043 , x_msg_count => x_msg_count
4044 , x_msg_data => x_msg_data
4045 , p_caller => 'WMS_Generate_LPN_CP'
4046 , p_quantity => p_quantity
4047 , p_lpn_prefix => l_lpn_prefix
4048 , p_lpn_suffix => l_lpn_suffix
4049 , p_starting_number => p_starting_num
4050 , p_total_lpn_length => p_total_length
4051 , p_ucc_128_suffix_flag => l_ucc_128_suffix_flag
4052 , p_lpn_attributes => l_lpn_att_rec
4053 , p_serial_ranges => l_serial_tbl
4054 , x_created_lpns => l_gen_lpn_tbl
4055 , p_client_code => p_client_code );-- Adding for LSP, bug 9087971
4056
4057 IF (x_return_status = fnd_api.g_ret_sts_success) THEN
4058 ret := fnd_concurrent.set_completion_status('NORMAL', x_msg_data);
4059 retcode := 0;
4060 ELSE
4061 ret := fnd_concurrent.set_completion_status('ERROR', x_msg_data);
4062 retcode := 2;
4063 errbuf := x_msg_data;
4064 END IF;
4065 END;
4066
4067
4068
4069 /*********************************************************************************
4070 * Generate_LPN()
4071 *
4072 *********************************************************************************/
4073 PROCEDURE Generate_LPN (
4074 p_api_version IN NUMBER
4075 , p_init_msg_list IN VARCHAR2 := fnd_api.g_false
4076 , p_commit IN VARCHAR2 := fnd_api.g_false
4077 , p_validation_level IN NUMBER := fnd_api.g_valid_level_full
4078 , x_return_status OUT NOCOPY VARCHAR2
4079 , x_msg_count OUT NOCOPY NUMBER
4080 , x_msg_data OUT NOCOPY VARCHAR2
4081 , p_organization_id IN NUMBER
4082 , p_container_item_id IN NUMBER := NULL
4083 , p_revision IN VARCHAR2 := NULL
4084 , p_lot_number IN VARCHAR2 := NULL
4085 , p_from_serial_number IN VARCHAR2 := NULL
4086 , p_to_serial_number IN VARCHAR2 := NULL
4087 , p_subinventory IN VARCHAR2 := NULL
4088 , p_locator_id IN NUMBER := NULL
4089 , p_lpn_prefix IN VARCHAR2 := NULL
4090 , p_lpn_suffix IN VARCHAR2 := NULL
4091 , p_starting_num IN NUMBER := NULL
4092 , p_quantity IN NUMBER := 1
4093 , p_source IN NUMBER := LPN_CONTEXT_PREGENERATED
4094 , p_cost_group_id IN NUMBER := NULL
4095 , p_source_type_id IN NUMBER := NULL
4096 , p_source_header_id IN NUMBER := NULL
4097 , p_source_name IN VARCHAR2 := NULL
4098 , p_source_line_id IN NUMBER := NULL
4099 , p_source_line_detail_id IN NUMBER := NULL
4100 , p_lpn_id_out OUT NOCOPY NUMBER
4101 , p_lpn_out OUT NOCOPY VARCHAR2
4102 , p_process_id OUT NOCOPY NUMBER
4103 , p_total_length IN NUMBER := NULL
4104 , p_ucc_128_suffix_flag IN NUMBER := 2
4105 ) IS
4106 BEGIN
4107 Generate_LPN (
4108 p_api_version => p_api_version
4109 , p_init_msg_list => p_init_msg_list
4110 , p_commit => p_commit
4111 , p_validation_level => p_validation_level
4112 , x_return_status => x_return_status
4113 , x_msg_count => x_msg_count
4114 , x_msg_data => x_msg_data
4115 , p_organization_id => p_organization_id
4116 , p_container_item_id => p_container_item_id
4117 , p_revision => p_revision
4118 , p_lot_number => p_lot_number
4119 , p_from_serial_number => p_from_serial_number
4120 , p_to_serial_number => p_to_serial_number
4121 , p_subinventory => p_subinventory
4122 , p_locator_id => p_locator_id
4123 , p_lpn_prefix => p_lpn_prefix
4124 , p_lpn_suffix => p_lpn_suffix
4125 , p_starting_num => p_starting_num
4126 , p_quantity => p_quantity
4127 , p_source => p_source
4128 , p_cost_group_id => p_cost_group_id
4129 , p_source_type_id => p_source_type_id
4130 , p_source_header_id => p_source_header_id
4131 , p_source_name => p_source_name
4132 , p_source_line_id => p_source_line_id
4133 , p_source_line_detail_id => p_source_line_detail_id
4134 , p_lpn_id_out => p_lpn_id_out
4135 , p_lpn_out => p_lpn_out
4136 , p_process_id => p_process_id
4137 , p_total_length => p_total_length
4138 , p_ucc_128_suffix_flag => p_ucc_128_suffix_flag
4139 , p_client_code => NULL
4140 );
4141 END Generate_LPN;
4142
4143 /*********************************************************************************
4144 * Generate_LPN()
4145 * Added for LSP Project, bug 9087971
4146 * Overloaded for LSPs
4147 *********************************************************************************/
4148 PROCEDURE Generate_LPN (
4149 p_api_version IN NUMBER
4150 , p_init_msg_list IN VARCHAR2 := fnd_api.g_false
4151 , p_commit IN VARCHAR2 := fnd_api.g_false
4152 , p_validation_level IN NUMBER := fnd_api.g_valid_level_full
4153 , x_return_status OUT NOCOPY VARCHAR2
4154 , x_msg_count OUT NOCOPY NUMBER
4155 , x_msg_data OUT NOCOPY VARCHAR2
4156 , p_organization_id IN NUMBER
4157 , p_container_item_id IN NUMBER := NULL
4158 , p_revision IN VARCHAR2 := NULL
4159 , p_lot_number IN VARCHAR2 := NULL
4160 , p_from_serial_number IN VARCHAR2 := NULL
4161 , p_to_serial_number IN VARCHAR2 := NULL
4162 , p_subinventory IN VARCHAR2 := NULL
4163 , p_locator_id IN NUMBER := NULL
4164 , p_lpn_prefix IN VARCHAR2 := NULL
4165 , p_lpn_suffix IN VARCHAR2 := NULL
4166 , p_starting_num IN NUMBER := NULL
4167 , p_quantity IN NUMBER := 1
4168 , p_source IN NUMBER := LPN_CONTEXT_PREGENERATED
4169 , p_cost_group_id IN NUMBER := NULL
4170 , p_source_type_id IN NUMBER := NULL
4171 , p_source_header_id IN NUMBER := NULL
4172 , p_source_name IN VARCHAR2 := NULL
4173 , p_source_line_id IN NUMBER := NULL
4174 , p_source_line_detail_id IN NUMBER := NULL
4175 , p_lpn_id_out OUT NOCOPY NUMBER
4176 , p_lpn_out OUT NOCOPY VARCHAR2
4177 , p_process_id OUT NOCOPY NUMBER
4178 , p_total_length IN NUMBER := NULL
4179 , p_ucc_128_suffix_flag IN NUMBER := 2
4180 , p_client_code IN VARCHAR2 -- Adding for LSP, bug 9087971
4181 ) IS
4182 l_api_name CONSTANT VARCHAR2(30) := 'Generate_LPN New';
4183 l_api_version CONSTANT NUMBER := 1.0;
4184 l_debug NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
4185 l_progress VARCHAR2(10) := '0';
4186
4187 l_ucc_128_suffix_flag VARCHAR2(1);
4188 l_lpn_att_rec WMS_Data_Type_Definitions_PUB.LPNRecordType;
4189 l_serial_tbl WMS_Data_Type_Definitions_PUB.SerialRangeTableType;
4190 l_gen_lpn_tbl WMS_Data_Type_Definitions_PUB.LPNTableType;
4191 l_lpn_bulk_rec LPNBulkRecType;
4192
4193 BEGIN
4194 SAVEPOINT GENERATE_LPN_PVT;
4195
4196 IF (l_debug = 1) THEN
4197 mdebug(l_api_name|| ' Entered '|| g_pkg_version, 1);
4198 mdebug('orgid=' ||p_organization_id|| ' sub=' ||p_subinventory|| ' loc=' ||p_locator_id|| ' src=' ||p_source, G_INFO);
4199 mdebug('cntitemid=' ||p_container_item_id|| ' rev=' ||p_revision|| ' lot=' ||p_lot_number|| ' fmsn=' ||p_from_serial_number|| ' tosn=' ||p_to_serial_number|| ' cstgrp=' ||p_cost_group_id, G_INFO);
4200 mdebug('prefix=' ||p_lpn_prefix|| ' suffix=' || p_lpn_suffix || ' strtnum=' ||p_starting_num || ' qty=' ||p_quantity);
4201 --mdebug('scrtype=' ||p_source_type_id|| ' srchdr=' ||p_source_header_id|| ' srcname=' ||p_source_name|| ' srcln=' ||p_source_line_id||' srclndet='||p_source_line_detail_id, G_INFO);
4202 --mdebug('p_total_length='||p_total_length||', p_ucc_128_suf='||p_ucc_128_suffix_flag);
4203 END IF;
4204
4205 -- Standard call to check for call compatibility.
4206 IF NOT fnd_api.compatible_api_call(l_api_version, p_api_version, l_api_name, g_pkg_name) THEN
4207 fnd_message.set_name('WMS', 'WMS_CONT_INCOMPATIBLE_API_CALL');
4208 fnd_msg_pub.ADD;
4209 RAISE fnd_api.g_exc_unexpected_error;
4210 END IF;
4211
4212 -- Initialize message list if p_init_msg_list is set to TRUE.
4213 IF fnd_api.to_boolean(p_init_msg_list) THEN
4214 fnd_msg_pub.initialize;
4215 END IF;
4216
4217 -- Initialize API return status to success
4218 x_return_status := fnd_api.g_ret_sts_success;
4219
4220 l_lpn_att_rec.lpn_context := p_source;
4221 l_lpn_att_rec.organization_id := p_organization_id;
4222 l_lpn_att_rec.subinventory_code := p_subinventory;
4223 l_lpn_att_rec.locator_id := p_locator_id;
4224 l_lpn_att_rec.inventory_item_id := p_container_item_id;
4225 l_lpn_att_rec.revision := p_revision;
4226 l_lpn_att_rec.lot_number := p_lot_number;
4227 l_lpn_att_rec.cost_group_id := p_cost_group_id;
4228 l_lpn_att_rec.source_type_id := p_source_type_id;
4229 l_lpn_att_rec.source_header_id := p_source_header_id;
4230 l_lpn_att_rec.source_name := p_source_name;
4231 l_lpn_att_rec.source_line_id := p_source_line_id;
4232 l_lpn_att_rec.source_line_detail_id := p_source_line_detail_id;
4233
4234 l_serial_tbl(1).fm_serial_number := p_from_serial_number;
4235 l_serial_tbl(1).to_serial_number := p_to_serial_number;
4236
4237
4238 IF ( p_ucc_128_suffix_flag = 1 ) THEN
4239 l_ucc_128_suffix_flag := 'Y';
4240 ELSIF p_ucc_128_suffix_flag is NOT NULL THEN
4241 l_ucc_128_suffix_flag := 'N';
4242 END IF;
4243
4244 Auto_Create_LPNs (
4245 p_api_version => p_api_version
4246 , p_init_msg_list => fnd_api.g_false
4247 , p_commit => fnd_api.g_false
4248 , x_return_status => x_return_status
4249 , x_msg_count => x_msg_count
4250 , x_msg_data => x_msg_data
4251 , p_caller => 'Generate_LPN'
4252 , p_quantity => p_quantity
4253 , p_lpn_prefix => p_lpn_prefix
4254 , p_lpn_suffix => p_lpn_suffix
4255 , p_starting_number => p_starting_num
4256 , p_total_lpn_length => p_total_length
4257 , p_ucc_128_suffix_flag => l_ucc_128_suffix_flag
4258 , p_lpn_attributes => l_lpn_att_rec
4259 , p_serial_ranges => l_serial_tbl
4260 , x_created_lpns => l_gen_lpn_tbl
4261 , p_client_code => p_client_code );-- Adding for LSP, bug 9087971
4262
4263 IF ( x_return_status = fnd_api.g_ret_sts_success ) THEN
4264 IF ( p_quantity = 1 ) THEN
4265 p_lpn_id_out := l_gen_lpn_tbl(1).lpn_id;
4266 p_lpn_out := l_gen_lpn_tbl(1).license_plate_number;
4267 ELSE
4268 -- More than one LPN was requested to be generated
4269 -- Generate a process ID number to tell which LPN's were generated
4270 SELECT wms_lpn_process_temp_s.NEXTVAL
4271 INTO p_process_id
4272 FROM DUAL;
4273
4274 -- transfer to LPN bulk record of tables
4275 l_lpn_bulk_rec := To_LPNBulkRecType(l_gen_lpn_tbl);
4276
4277 IF ( l_debug = 1 ) THEN
4278 mdebug('Inser into the WMS_LPN_PROCESS_TEMP procid='||p_process_id||' '||l_lpn_bulk_rec.lpn_id.first||'-'||l_lpn_bulk_rec.lpn_id.last , G_INFO);
4279 END IF;
4280
4281 FORALL i in l_lpn_bulk_rec.lpn_id.first .. l_lpn_bulk_rec.lpn_id.last
4282 INSERT INTO wms_lpn_process_temp (
4283 process_id
4284 , lpn_id )
4285 VALUES (
4286 p_process_id
4287 , l_lpn_bulk_rec.lpn_id(i) );
4288 END IF;
4289 ELSE
4290 RAISE fnd_api.g_exc_error;
4291 END IF;
4292
4293 -- Standard check of p_commit.
4294 IF fnd_api.to_boolean(p_commit) THEN
4295 COMMIT WORK;
4296 END IF;
4297
4298 -- Standard call to get message count and if count is 1,
4299 -- get message info.
4300 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
4301 EXCEPTION
4302 WHEN fnd_api.g_exc_error THEN
4303 --fnd_message.set_name('WMS', 'WMS_LPN_GENERATION_FAIL');
4304 --fnd_msg_pub.ADD;
4305 ROLLBACK TO GENERATE_LPN_PVT;
4306 x_return_status := fnd_api.g_ret_sts_error;
4307 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
4308 WHEN fnd_api.g_exc_unexpected_error THEN
4309 fnd_message.set_name('WMS', 'WMS_LPN_GENERATION_FAIL');
4310 fnd_msg_pub.ADD;
4311 ROLLBACK TO GENERATE_LPN_PVT;
4312 x_return_status := fnd_api.g_ret_sts_unexp_error;
4313 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
4314 WHEN OTHERS THEN
4315 fnd_message.set_name('WMS', 'WMS_LPN_GENERATION_FAIL');
4316 fnd_msg_pub.ADD;
4317 ROLLBACK TO GENERATE_LPN_PVT;
4318 x_return_status := fnd_api.g_ret_sts_unexp_error;
4319
4320 IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error) THEN
4321 fnd_msg_pub.add_exc_msg(g_pkg_name, l_api_name);
4322 END IF;
4323
4324 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
4325 END Generate_LPN;
4326
4327 -- ----------------------------------------------------------------------------------
4328 -- ----------------------------------------------------------------------------------
4329 PROCEDURE associate_lpn(
4330 p_api_version IN NUMBER,
4331 p_init_msg_list IN VARCHAR2 := fnd_api.g_false,
4332 p_commit IN VARCHAR2 := fnd_api.g_false,
4333 p_validation_level IN NUMBER := fnd_api.g_valid_level_full,
4334 x_return_status OUT NOCOPY VARCHAR2,
4335 x_msg_count OUT NOCOPY NUMBER,
4336 x_msg_data OUT NOCOPY VARCHAR2,
4337 p_lpn_id IN NUMBER,
4338 p_container_item_id IN NUMBER,
4339 p_lot_number IN VARCHAR2 := NULL,
4340 p_revision IN VARCHAR2 := NULL,
4341 p_serial_number IN VARCHAR2 := NULL,
4342 p_organization_id IN NUMBER,
4343 p_subinventory IN VARCHAR2 := NULL,
4344 p_locator_id IN NUMBER := NULL,
4345 p_cost_group_id IN NUMBER := NULL,
4346 p_source_type_id IN NUMBER := NULL,
4347 p_source_header_id IN NUMBER := NULL,
4348 p_source_name IN VARCHAR2 := NULL,
4349 p_source_line_id IN NUMBER := NULL,
4350 p_source_line_detail_id IN NUMBER := NULL
4351 ) IS
4352 l_api_name CONSTANT VARCHAR2(30) := 'Associate_LPN';
4353 l_api_version CONSTANT NUMBER := 1.0;
4354 l_debug NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
4355
4356 l_lpn_tbl WMS_Data_Type_Definitions_PUB.LPNTableType;
4357 BEGIN
4358 -- Standard Start of API savepoint
4359 SAVEPOINT ASSOCIATE_LPN_PVT;
4360
4361 -- Standard call to check for call compatibility.
4362 IF NOT fnd_api.compatible_api_call(l_api_version, p_api_version, l_api_name, g_pkg_name) THEN
4363 fnd_message.set_name('WMS', 'WMS_CONT_INCOMPATIBLE_API_CALL');
4364 fnd_msg_pub.ADD;
4365 RAISE fnd_api.g_exc_unexpected_error;
4366 END IF;
4367
4368 -- Initialize message list if p_init_msg_list is set to TRUE.
4369 IF fnd_api.to_boolean(p_init_msg_list) THEN
4370 fnd_msg_pub.initialize;
4371 END IF;
4372
4373 -- Initialize API return status to success
4374 x_return_status := fnd_api.g_ret_sts_success;
4375
4376 -- API body
4377 IF (l_debug = 1) THEN
4378 mdebug(l_api_name || ' Entered ' || g_pkg_version, 1);
4379 mdebug('orgid=' ||p_organization_id|| ' sub=' ||p_subinventory|| ' loc=' ||p_locator_id|| ' lpnid=' ||p_lpn_id, G_INFO);
4380 mdebug('itemid=' ||p_container_item_id|| ' rev=' ||p_revision|| ' lot=' ||p_lot_number|| ' sn=' ||p_serial_number, G_INFO);
4381 mdebug('cg=' ||p_cost_group_id|| ' srctype=' ||p_source_type_id||' srchdr='||p_source_header_id||' srcln='||p_source_line_id, G_INFO);
4382 END IF;
4383
4384 l_lpn_tbl(1).lpn_id := p_lpn_id;
4385 l_lpn_tbl(1).organization_id := p_organization_id;
4386 l_lpn_tbl(1).subinventory_code := p_subinventory;
4387 l_lpn_tbl(1).locator_id := p_locator_id;
4388
4389 l_lpn_tbl(1).inventory_item_id := p_container_item_id;
4390 l_lpn_tbl(1).lot_number := p_lot_number;
4391 l_lpn_tbl(1).revision := p_revision;
4392 l_lpn_tbl(1).serial_number := p_serial_number;
4393 l_lpn_tbl(1).cost_group_id := p_cost_group_id;
4394
4395 l_lpn_tbl(1).source_type_id := p_source_type_id;
4396 l_lpn_tbl(1).source_header_id := p_source_header_id;
4397 l_lpn_tbl(1).source_name := p_source_name;
4398 l_lpn_tbl(1).source_line_id := p_source_line_id;
4399 l_lpn_tbl(1).source_line_detail_id := p_source_line_detail_id;
4400
4401 Modify_LPNs (
4402 p_api_version => 1.0
4403 , p_init_msg_list => fnd_api.g_false
4404 , p_commit => fnd_api.g_false
4405 , x_return_status => x_return_status
4406 , x_msg_count => x_msg_count
4407 , x_msg_data => x_msg_data
4408 , p_caller => l_api_name
4409 , p_lpn_table => l_lpn_tbl );
4410
4411 IF (x_return_status <> fnd_api.g_ret_sts_success) THEN
4412 IF ( l_debug = 1 ) THEN
4413 mdebug('Modify_LPNs failed', G_ERROR);
4414 END IF;
4415 RAISE fnd_api.g_exc_error;
4416 END IF;
4417
4418 -- End of API body
4419
4420 -- Standard check of p_commit.
4421 IF fnd_api.to_boolean(p_commit) THEN
4422 COMMIT WORK;
4423 END IF;
4424
4425 -- Standard call to get message count and if count is 1,
4426 -- get message info.
4427 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
4428 EXCEPTION
4429 WHEN fnd_api.g_exc_error THEN
4430 ROLLBACK TO ASSOCIATE_LPN_PVT;
4431 x_return_status := fnd_api.g_ret_sts_error;
4432 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
4433 WHEN fnd_api.g_exc_unexpected_error THEN
4434 ROLLBACK TO ASSOCIATE_LPN_PVT;
4435 x_return_status := fnd_api.g_ret_sts_unexp_error;
4436 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
4437 WHEN OTHERS THEN
4438 ROLLBACK TO ASSOCIATE_LPN_PVT;
4439 x_return_status := fnd_api.g_ret_sts_unexp_error;
4440
4441 IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error) THEN
4442 fnd_msg_pub.add_exc_msg(g_pkg_name, l_api_name);
4443 END IF;
4444
4445 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
4446 END associate_lpn;
4447
4448 -- ----------------------------------------------------------------------------------
4449 -- ----------------------------------------------------------------------------------
4450
4451 PROCEDURE Create_LPN (
4452 p_api_version IN NUMBER
4453 , p_init_msg_list IN VARCHAR2 := fnd_api.g_false
4454 , p_commit IN VARCHAR2 := fnd_api.g_false
4455 , p_validation_level IN NUMBER := fnd_api.g_valid_level_full
4456 , x_return_status OUT NOCOPY VARCHAR2
4457 , x_msg_count OUT NOCOPY NUMBER
4458 , x_msg_data OUT NOCOPY VARCHAR2
4459 , p_lpn IN VARCHAR2
4460 , p_organization_id IN NUMBER
4461 , p_container_item_id IN NUMBER := NULL
4462 , p_lot_number IN VARCHAR2 := NULL
4463 , p_revision IN VARCHAR2 := NULL
4464 , p_serial_number IN VARCHAR2 := NULL
4465 , p_subinventory IN VARCHAR2 := NULL
4466 , p_locator_id IN NUMBER := NULL
4467 , p_source IN NUMBER := LPN_CONTEXT_PREGENERATED
4468 , p_cost_group_id IN NUMBER := NULL
4469 , p_parent_lpn_id IN NUMBER := NULL
4470 , p_source_type_id IN NUMBER := NULL
4471 , p_source_header_id IN NUMBER := NULL
4472 , p_source_name IN VARCHAR2 := NULL
4473 , p_source_line_id IN NUMBER := NULL
4474 , p_source_line_detail_id IN NUMBER := NULL
4475 , x_lpn_id OUT NOCOPY NUMBER
4476 ) IS
4477 l_api_name CONSTANT VARCHAR2(30) := 'Create_LPN';
4478 l_api_version CONSTANT NUMBER := 1.0;
4479 l_debug NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
4480 l_progress VARCHAR2(10) := '0';
4481 l_msgdata VARCHAR2(1000);
4482
4483 l_lpn_tbl WMS_Data_Type_Definitions_PUB.LPNTableType;
4484
4485 BEGIN
4486 -- Standard Start of API savepoint
4487 SAVEPOINT CREATE_LPN_PVT;
4488
4489 -- Standard call to check for call compatibility.
4490 IF NOT fnd_api.compatible_api_call(l_api_version, p_api_version, l_api_name, g_pkg_name) THEN
4491 fnd_message.set_name('WMS', 'WMS_CONT_INCOMPATIBLE_API_CALL');
4492 fnd_msg_pub.ADD;
4493 RAISE fnd_api.g_exc_unexpected_error;
4494 END IF;
4495
4496 -- Initialize message list if p_init_msg_list is set to TRUE.
4497 IF fnd_api.to_boolean(p_init_msg_list) THEN
4498 fnd_msg_pub.initialize;
4499 END IF;
4500
4501 -- Initialize API return status to success
4502 x_return_status := fnd_api.g_ret_sts_success;
4503
4504 -- API body
4505 IF (l_debug = 1) THEN
4506 mdebug(l_api_name || ' Entered ' || g_pkg_version, 1);
4507 mdebug('orgid=' ||p_organization_id|| ' sub=' ||p_subinventory|| ' loc=' ||p_locator_id|| ' lpn=' ||p_lpn|| ' src=' ||p_source, G_INFO);
4508 mdebug('cntitemid=' ||p_container_item_id|| ' rev=' ||p_revision|| ' lot=' ||p_lot_number|| ' sn=' ||p_serial_number|| ' cstgrp=' ||p_cost_group_id, G_INFO);
4509 mdebug('prntlpnid=' ||p_parent_lpn_id|| ' scrtype=' ||p_source_type_id|| ' srchdr=' ||p_source_header_id|| ' srcname=' ||p_source_name|| ' srcln=' ||p_source_line_id||' srclndet='||p_source_line_detail_id, G_INFO);
4510 END IF;
4511
4512 l_lpn_tbl(1).license_plate_number := p_lpn;
4513 l_lpn_tbl(1).organization_id := p_organization_id;
4514 l_lpn_tbl(1).inventory_item_id := p_container_item_id;
4515 l_lpn_tbl(1).lot_number := p_lot_number;
4516 l_lpn_tbl(1).revision := p_revision;
4517 l_lpn_tbl(1).serial_number := p_serial_number;
4518 l_lpn_tbl(1).subinventory_code := p_subinventory;
4519 l_lpn_tbl(1).locator_id := p_locator_id;
4520 l_lpn_tbl(1).lpn_context := p_source;
4521 l_lpn_tbl(1).cost_group_id := p_cost_group_id;
4522 --l_lpn_tbl(1).parent_lpn_id := p_parent_lpn_id;
4523 l_lpn_tbl(1).source_type_id := p_source_type_id;
4524 l_lpn_tbl(1).source_header_id := p_source_header_id;
4525 l_lpn_tbl(1).source_name := p_source_name;
4526 l_lpn_tbl(1).source_line_id := p_source_line_id;
4527 l_lpn_tbl(1).source_line_detail_id := p_source_line_detail_id;
4528
4529 Create_LPNs (
4530 p_api_version => p_api_version
4531 , p_init_msg_list => fnd_api.g_false
4532 , p_commit => fnd_api.g_false
4533 , x_return_status => x_return_status
4534 , x_msg_count => x_msg_count
4535 , x_msg_data => x_msg_data
4536 , p_caller => l_api_name
4537 , p_lpn_table => l_lpn_tbl );
4538
4539 IF ( x_return_status = fnd_api.g_ret_sts_success ) THEN
4540 x_lpn_id := l_lpn_tbl(1).lpn_id;
4541 ELSE
4542 RAISE fnd_api.g_exc_error;
4543 END IF;
4544
4545 -- Standard check of p_commit.
4546 IF fnd_api.to_boolean(p_commit) THEN
4547 COMMIT WORK;
4548 END IF;
4549
4550 -- Standard call to get message count and if count is 1,
4551 -- get message info.
4552 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
4553 EXCEPTION
4554 WHEN FND_API.G_EXC_ERROR THEN
4555 x_return_status := fnd_api.g_ret_sts_error;
4556 FND_MSG_PUB.Count_And_Get(p_count => x_msg_count, p_data => x_msg_data);
4557 IF (l_debug = 1) THEN
4558 FOR i in 1..x_msg_count LOOP
4559 l_msgdata := substr(l_msgdata||' | '||substr(fnd_msg_pub.get(x_msg_count-i+1, 'F'), 0, 200),1,2000);
4560 END LOOP;
4561 mdebug(l_api_name ||' Error progress= '||l_progress||'SQL error: '|| SQLERRM(SQLCODE), G_ERROR);
4562 mdebug('msg: '||l_msgdata, G_ERROR);
4563 END IF;
4564 ROLLBACK TO CREATE_LPN_PVT;
4565 WHEN OTHERS THEN
4566 x_return_status := fnd_api.g_ret_sts_unexp_error;
4567 FND_MSG_PUB.Count_And_Get(p_count => x_msg_count, p_data => x_msg_data);
4568 IF (l_debug = 1) THEN
4569 mdebug(l_api_name ||' Error progress= '||l_progress||'SQL error: '|| SQLERRM(SQLCODE), G_ERROR);
4570 END IF;
4571 ROLLBACK TO CREATE_LPN_PVT;
4572 END Create_LPN;
4573
4574 -- ----------------------------------------------------------------------------------
4575 -- ----------------------------------------------------------------------------------
4576
4577 PROCEDURE PackUnpack_Container(
4578 p_api_version IN NUMBER
4579 , p_init_msg_list IN VARCHAR2 := fnd_api.g_false
4580 , p_commit IN VARCHAR2 := fnd_api.g_false
4581 , p_validation_level IN NUMBER := fnd_api.g_valid_level_full
4582 , x_return_status OUT NOCOPY VARCHAR2
4583 , x_msg_count OUT NOCOPY NUMBER
4584 , x_msg_data OUT NOCOPY VARCHAR2
4585 , p_lpn_id IN NUMBER
4586 , p_content_lpn_id IN NUMBER := NULL
4587 , p_content_item_id IN NUMBER := NULL
4588 , p_content_item_desc IN VARCHAR2 := NULL
4589 , p_revision IN VARCHAR2 := NULL
4590 , p_lot_number IN VARCHAR2 := NULL
4591 , p_from_serial_number IN VARCHAR2 := NULL
4592 , p_to_serial_number IN VARCHAR2 := NULL
4593 , p_quantity IN NUMBER := 1
4594 , p_uom IN VARCHAR2 := NULL
4595 , p_sec_quantity IN NUMBER := NULL -- INVCONV kkillams
4596 , p_sec_uom IN VARCHAR2 := NULL -- INVCONV kkillams
4597 , p_organization_id IN NUMBER
4598 , p_subinventory IN VARCHAR2 := NULL
4599 , p_locator_id IN NUMBER := NULL
4600 , p_enforce_wv_constraints IN NUMBER := 2
4601 , p_operation IN NUMBER
4602 , p_cost_group_id IN NUMBER := NULL
4603 , p_source_type_id IN NUMBER := NULL
4604 , p_source_header_id IN NUMBER := NULL
4605 , p_source_name IN VARCHAR2 := NULL
4606 , p_source_line_id IN NUMBER := NULL
4607 , p_source_line_detail_id IN NUMBER := NULL
4608 , p_unpack_all IN NUMBER := 2
4609 , p_auto_unnest_empty_lpns IN NUMBER := 1
4610 , p_ignore_item_controls IN NUMBER := 2
4611 , p_primary_quantity IN NUMBER := NULL
4612 , p_caller IN VARCHAR2 := NULL
4613 , p_source_transaction_id IN NUMBER := NULL
4614 ) IS
4615 l_api_name CONSTANT VARCHAR2(30) := 'PackUnpack_Container';
4616 l_api_version CONSTANT NUMBER := 1.0;
4617 l_debug NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
4618 l_request_id NUMBER := FND_PROFILE.value('CONC_REQUEST_ID');
4619 l_progress VARCHAR2(100) := '0';
4620 l_msgdata VARCHAR2(1000);
4621
4622 -- Constants defined for transaction types
4623 L_PACK CONSTANT NUMBER := 1;
4624 L_UNPACK CONSTANT NUMBER := 2;
4625 L_CORRECT CONSTANT NUMBER := 3;
4626 L_UNPACK_ALL CONSTANT NUMBER := 4;
4627
4628 -- Types needed for WSH_WMS_LPN_GRP.Delivery_Detail_Action
4629 l_wsh_lpn_id_tbl wsh_util_core.id_tab_type;
4630 l_wsh_del_det_id_tbl wsh_util_core.id_tab_type;
4631 l_wsh_action_prms WSH_GLBL_VAR_STRCT_GRP.dd_action_parameters_rec_type;
4632 l_wsh_defaults WSH_GLBL_VAR_STRCT_GRP.dd_default_parameters_rec_type;
4633 l_wsh_action_out_rec WSH_GLBL_VAR_STRCT_GRP.dd_action_out_rec_type;
4634
4635 l_lpn_tbl WMS_Data_Type_Definitions_PUB.LPNTableType;
4636 l_new WMS_Data_Type_Definitions_PUB.LPNRecordType;
4637 l_cont_new WMS_Data_Type_Definitions_PUB.LPNRecordType;
4638
4639 l_tmp_bulk_lpns LPNBulkRecType;
4640 l_tmp_i NUMBER;
4641
4642 l_lpn WMS_CONTAINER_PUB.LPN;
4643 l_content_lpn WMS_CONTAINER_PUB.LPN;
4644 l_wt_vol_new WMS_CONTAINER_PUB.LPN;
4645
4646 l_result NUMBER;
4647 l_serial_summary_entry NUMBER := 2;
4648
4649 l_subinventory VARCHAR(30);
4650 l_locator_id NUMBER;
4651
4652 l_prefix VARCHAR2(30);
4653 l_from_number NUMBER;
4654 l_to_number NUMBER;
4655 l_errorcode NUMBER;
4656
4657 l_converted_quantity NUMBER;
4658 l_sec_converted_quantity NUMBER; --INVCONV kkillams
4659 l_lpn_is_empty NUMBER := 0;
4660
4661 l_operation_mode NUMBER;
4662 l_quantity NUMBER;
4663 l_primary_quantity NUMBER;
4664 l_item_quantity NUMBER;
4665 l_serial_quantity NUMBER;
4666 l_uom_priority VARCHAR2(3);
4667
4668 l_change_in_gross_weight NUMBER;
4669 l_change_in_gross_weight_uom VARCHAR2(3);
4670 l_change_in_tare_weight NUMBER;
4671 l_change_in_tare_weight_uom VARCHAR(3);
4672 l_change_in_volume NUMBER;
4673 l_change_in_volume_uom VARCHAR2(3);
4674
4675 CURSOR nested_children_cursor(p_outer_lpn_id NUMBER) IS
4676 SELECT lpn_id
4677 FROM wms_license_plate_numbers
4678 START WITH lpn_id = p_outer_lpn_id
4679 CONNECT BY parent_lpn_id = PRIOR lpn_id;
4680
4681 CURSOR nested_parent_cursor(p_child_lpn_id NUMBER) IS
4682 SELECT organization_id, parent_lpn_id, lpn_id, inventory_item_id,
4683 tare_weight, tare_weight_uom_code, gross_weight, gross_weight_uom_code,
4684 container_volume, container_volume_uom, content_volume, content_volume_uom_code
4685 FROM wms_license_plate_numbers
4686 START WITH lpn_id = p_child_lpn_id
4687 CONNECT BY lpn_id = PRIOR parent_lpn_id;
4688
4689 empty_lpn_rec nested_parent_cursor%ROWTYPE;
4690
4691 CURSOR existing_record_cursor( p_context NUMBER, p_serial_summary_entry NUMBER ) IS
4692 SELECT wlc.rowid
4693 , wlc.primary_quantity
4694 , wlc.quantity
4695 , wlc.uom_code
4696 , wlc.cost_group_id
4697 , wlc.secondary_quantity --INVCONV kkillams
4698 , wlc.secondary_uom_code --INVCONV kkillams
4699 FROM wms_lpn_contents wlc
4700 WHERE wlc.parent_lpn_id = p_lpn_id
4701 AND wlc.organization_id = p_organization_id
4702 AND wlc.uom_code = p_uom
4703 AND wlc.inventory_item_id = p_content_item_id
4704 AND NVL(wlc.revision, G_NULL_CHAR) = NVL(p_revision, G_NULL_CHAR)
4705 AND NVL(wlc.lot_number, G_NULL_CHAR) = NVL(p_lot_number, G_NULL_CHAR)
4706 AND NVL(wlc.source_type_id, G_NULL_NUM) = NVL(p_source_type_id, G_NULL_NUM)
4707 AND NVL(wlc.source_header_id, G_NULL_NUM) = NVL(p_source_header_id, G_NULL_NUM)
4708 AND NVL(wlc.source_line_id, G_NULL_NUM) = NVL(p_source_line_id, G_NULL_NUM)
4709 AND NVL(wlc.source_line_detail_id, G_NULL_NUM) = NVL(p_source_line_detail_id, G_NULL_NUM)
4710 AND NVL(wlc.source_name, G_NULL_CHAR) = NVL(p_source_name, G_NULL_CHAR)
4711 AND NVL(wlc.serial_summary_entry, 2) = p_serial_summary_entry;
4712
4713 l_existing_record_cursor existing_record_cursor%ROWTYPE;
4714
4715 CURSOR existing_unpack_record_cursor( p_serial_summary_entry NUMBER, p_uom_code VARCHAR2 ) IS
4716 SELECT wlc.rowid
4717 , wlc.primary_quantity
4718 , wlc.quantity
4719 , wlc.uom_code
4720 , wlc.lot_number
4721 , wlc.serial_summary_entry
4722 , wlc.secondary_quantity --INVCONV kkillams
4723 , wlc.secondary_uom_code --INVCONV kkillams
4724 FROM wms_lpn_contents wlc
4725 WHERE wlc.parent_lpn_id = p_lpn_id
4726 AND wlc.organization_id = p_organization_id
4727 AND wlc.inventory_item_id = p_content_item_id
4728 AND wlc.uom_code = NVL(p_uom_code, wlc.uom_code)
4729 AND NVL(wlc.revision, G_NULL_CHAR) = NVL(p_revision, G_NULL_CHAR)
4730 AND NVL(wlc.lot_number, G_NULL_CHAR) = NVL(DECODE(p_serial_summary_entry, NULL, wlc.lot_number, p_lot_number), G_NULL_CHAR)
4731 AND NVL(wlc.source_type_id, G_NULL_NUM) = NVL(p_source_type_id, NVL(wlc.source_type_id, G_NULL_NUM))
4732 AND NVL(wlc.source_header_id, G_NULL_NUM) = NVL(p_source_header_id, NVL(wlc.source_header_id, G_NULL_NUM))
4733 AND NVL(wlc.source_line_id, G_NULL_NUM) = NVL(p_source_line_id, NVL(wlc.source_line_id, G_NULL_NUM))
4734 AND NVL(wlc.source_line_detail_id, G_NULL_NUM) = NVL(p_source_line_detail_id, NVL(wlc.source_line_detail_id, G_NULL_NUM))
4735 AND NVL(wlc.source_name, G_NULL_CHAR) = NVL(p_source_name, NVL(wlc.source_name, G_NULL_CHAR))
4736 AND NVL(wlc.serial_summary_entry, 2) = NVL(p_serial_summary_entry, NVL(wlc.serial_summary_entry, 2))
4737 AND (NVL(wlc.source_name, G_NULL_CHAR) NOT IN ('RETURN TO VENDOR', 'RETURN TO RECEIVING', 'RETURN TO CUSTOMER')
4738 OR NVL(p_source_name, G_NULL_CHAR) IN ('RETURN TO VENDOR', 'RETURN TO RECEIVING', 'RETURN TO CUSTOMER')
4739 )
4740 ORDER BY wlc.lot_number, wlc.source_type_id DESC, wlc.source_header_id DESC, wlc.source_line_id DESC, wlc.source_line_detail_id DESC, wlc.source_name DESC;
4741
4742 l_temp_record existing_unpack_record_cursor%ROWTYPE;
4743
4744 CURSOR one_time_item_cursor IS
4745 SELECT rowid
4746 , primary_quantity
4747 , quantity
4748 , secondary_quantity --INVCONV kkillams
4749 FROM wms_lpn_contents
4750 WHERE parent_lpn_id = p_lpn_id
4751 AND organization_id = p_organization_id
4752 AND item_description = p_content_item_desc
4753 AND NVL(cost_group_id, G_NULL_NUM) = NVL(p_cost_group_id, G_NULL_NUM)
4754 AND NVL(serial_summary_entry, 2) = l_serial_summary_entry;
4755
4756 l_one_time_item_rec one_time_item_cursor%ROWTYPE;
4757
4758 CURSOR nested_container_cursor IS
4759 SELECT rowid
4760 , lpn_id
4761 , organization_id
4762 , inventory_item_id
4763 , tare_weight
4764 , tare_weight_uom_code
4765 FROM wms_license_plate_numbers
4766 START WITH lpn_id = p_lpn_id
4767 CONNECT BY parent_lpn_id = PRIOR lpn_id;
4768
4769 --13535759
4770 --This Cursor gets all the LPNs in the Parent Heirarchy
4771 CURSOR get_all_parents IS
4772 SELECT lpn_id
4773 FROM wms_license_plate_numbers
4774 START WITH lpn_id = p_lpn_id
4775 CONNECT BY lpn_id = PRIOR parent_lpn_id;
4776 --13535759
4777
4778 BEGIN
4779 -- Standard Start of API savepoint
4780 SAVEPOINT PACKUNPACK_CONTAINER;
4781
4782 -- Standard call to check for call compatibility.
4783 IF NOT fnd_api.compatible_api_call(l_api_version, p_api_version, l_api_name, g_pkg_name) THEN
4784 fnd_message.set_name('WMS', 'WMS_CONT_INCOMPATIBLE_API_CALL');
4785 fnd_msg_pub.ADD;
4786 RAISE fnd_api.g_exc_unexpected_error;
4787 END IF;
4788
4789 -- Initialize message list if p_init_msg_list is set to TRUE.
4790 IF fnd_api.to_boolean(p_init_msg_list) THEN
4791 fnd_msg_pub.initialize;
4792 END IF;
4793
4794 -- Initialize API return status to success
4795 x_return_status := fnd_api.g_ret_sts_success;
4796
4797 IF ( l_debug = 1 ) THEN
4798 mdebug(l_api_name || ' Entered ' || g_pkg_version, 1);
4799 mdebug('orgid='||p_organization_id||' sub='||p_subinventory||' loc='||p_locator_id||' lpnid='||p_lpn_id||' cntlpn='||p_content_lpn_id||' enfrc='||p_enforce_wv_constraints, G_INFO);
4800 mdebug('itemid='||p_content_item_id||' rev='||p_revision||' lot='||p_lot_number||' fmsn='||p_from_serial_number||' tosn='||p_to_serial_number||' itmds='||p_content_item_desc, G_INFO);
4801 mdebug('qty='||p_quantity||' uom='||p_uom||' cg='||p_cost_group_id||' oper='||p_operation||' upkall='||p_unpack_all||' unnst='||p_auto_unnest_empty_lpns||' ign='||p_ignore_item_controls, G_INFO);
4802 mdebug('styp='||p_source_type_id||' shdr='||p_source_header_id||' sln='||p_source_line_id||' slndt='||p_source_line_detail_id||' snm='||p_source_name, G_INFO);
4803 mdebug('secondary quantity='||p_sec_quantity||' secondary uom='||p_sec_uom); --INVCONV kkillams
4804 END IF;
4805
4806 -- Need to do this to support old legacy parameter
4807 IF ( p_unpack_all = 1 ) THEN
4808 l_operation_mode := L_UNPACK_ALL;
4809 ELSE
4810 l_operation_mode := p_operation;
4811 END IF;
4812
4813 IF ( p_from_serial_number IS NOT NULL ) THEN
4814 l_serial_summary_entry := 1;
4815 ELSE
4816 l_serial_summary_entry := 2;
4817 END IF;
4818
4819 l_progress := 'Retrieve valuse for parent LPN';
4820
4821 l_lpn.lpn_id := p_lpn_id;
4822 l_lpn.license_plate_number := NULL;
4823 l_result := WMS_CONTAINER_PVT.validate_lpn(l_lpn, 1);
4824
4825 IF (l_result = inv_validate.f) THEN
4826 IF (l_debug = 1) THEN
4827 mdebug(p_lpn_id || 'is an invalid lpn_id', G_ERROR);
4828 END IF;
4829 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_LPN');
4830 fnd_msg_pub.ADD;
4831 RAISE fnd_api.g_exc_error;
4832 END IF;
4833
4834 IF (l_debug = 1) THEN
4835 mdebug('lpn='||l_lpn.license_plate_number||' org='||l_lpn.organization_id||' sub='||l_lpn.subinventory_code||' loc='||l_lpn.locator_id||' ctx='||l_lpn.lpn_context, G_MESSAGE);
4836 mdebug('lpnid='||l_lpn.lpn_id||' lpn='||l_lpn.license_plate_number||' ctx='||l_lpn.lpn_context||' plpn='||l_lpn.parent_lpn_id||' olpn='||l_lpn.outermost_lpn_id||' itm='||l_lpn.inventory_item_id||' rev='||l_lpn.revision, G_INFO);
4837 mdebug('lot='||l_lpn.lot_number||' sn='||l_lpn.serial_number||' cg='||l_lpn.cost_group_id||' org='||l_lpn.organization_id||' sub='||l_lpn.subinventory_code||' loc='||l_lpn.locator_id||' gwuom='||l_lpn.gross_weight_uom_code, G_INFO);
4838 mdebug('gwt='||l_lpn.gross_weight||' vuom='||l_lpn.content_volume_uom_code||' vol='||l_lpn.content_volume||' twuom='||l_lpn.tare_weight_uom_code||' twt='||l_lpn.tare_weight||' stype='||l_lpn.source_type_id, G_INFO);
4839 mdebug('shdr='||l_lpn.source_header_id||' srcln='||l_lpn.source_line_id||' srclndt='||l_lpn.source_line_detail_id||' srcnm='||l_lpn.source_name||' stat='|| l_lpn.status_id ||' seal='||l_lpn.sealed_status, G_INFO);
4840 END IF;
4841
4842 -- Validate that LPN is in correct organzation
4843 IF ( p_organization_id <> l_lpn.organization_id ) THEN
4844 l_progress := 'Org passed by user does not match org on LPN';
4845 fnd_message.set_name('WMS', 'WMS_LPN_DIFF_ORG_ERR');
4846 fnd_message.set_token('LPN', l_lpn.license_plate_number);
4847 fnd_msg_pub.ADD;
4848 RAISE fnd_api.g_exc_error;
4849 END IF;
4850
4851 -- Validate quantities
4852 IF ( NVL(p_quantity, 0) < 0 OR NVL(p_primary_quantity, 0) < 0 ) THEN
4853 l_progress := 'cannot pass negitive qty to this API';
4854 fnd_message.set_name('WMS', 'WMS_CONT_NEG_QTY');
4855 fnd_msg_pub.ADD;
4856 RAISE fnd_api.g_exc_error;
4857 END IF;
4858
4859 IF ( p_content_lpn_id IS NOT NULL ) THEN
4860 l_progress := 'Validate Content LPN';
4861 l_content_lpn.lpn_id := p_content_lpn_id;
4862 l_result := WMS_CONTAINER_PVT.validate_lpn(l_content_lpn);
4863
4864 IF (l_result = inv_validate.f) THEN
4865 IF (l_debug = 1) THEN
4866 mdebug(p_lpn_id || 'is an invalid lpn_id', G_ERROR);
4867 END IF;
4868 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_CONTENT_LPN');
4869 fnd_msg_pub.ADD;
4870 RAISE fnd_api.g_exc_error;
4871 END IF;
4872
4873 IF (l_debug = 1) THEN
4874 mdebug('cntlpn='||l_content_lpn.license_plate_number||' org='||l_content_lpn.organization_id||' sub='||l_content_lpn.subinventory_code||' loc='||l_content_lpn.locator_id||' ctx='||l_content_lpn.lpn_context, G_MESSAGE);
4875 mdebug('lpnid='||l_content_lpn.lpn_id||' lpn='||l_content_lpn.license_plate_number||' ctx='||l_content_lpn.lpn_context||' plpn='||l_content_lpn.parent_lpn_id||' olpn='||l_content_lpn.outermost_lpn_id, G_INFO);
4876 mdebug('itm='||l_content_lpn.inventory_item_id||' rev='||l_content_lpn.revision||' lot='||l_content_lpn.lot_number||' sn='||l_content_lpn.serial_number||' cg='||l_content_lpn.cost_group_id||' org='||l_content_lpn.organization_id, G_INFO);
4877 mdebug('sub='||l_content_lpn.subinventory_code||' loc='||l_content_lpn.locator_id||' gwuom='||l_content_lpn.gross_weight_uom_code||' gwt='||l_content_lpn.gross_weight||' vuom='||l_content_lpn.content_volume_uom_code, G_INFO);
4878 mdebug('vol='||l_content_lpn.content_volume||' twuom='||l_content_lpn.tare_weight_uom_code||' twt='||l_content_lpn.tare_weight||' stype='||l_content_lpn.source_type_id||' shdr='||l_content_lpn.source_header_id, G_INFO);
4879 mdebug('srcln='||l_content_lpn.source_line_id||' srclndt='||l_content_lpn.source_line_detail_id||' srcnm='||l_content_lpn.source_name||' stat='||l_content_lpn.status_id, G_INFO);
4880 END IF;
4881
4882 -- Check that the content lpn is in fact stored within the given parent lpn
4883 -- Do this check only for the unpack operation
4884 IF ( l_operation_mode = L_UNPACK ) THEN
4885 IF (l_content_lpn.parent_lpn_id <> l_lpn.lpn_id) THEN
4886 IF (l_debug = 1) THEN
4887 mdebug('content lpn not in parent lpn', G_ERROR);
4888 END IF;
4889 fnd_message.set_name('WMS', 'WMS_CONT_LPN_NOT_IN_LPN');
4890 fnd_msg_pub.ADD;
4891 RAISE fnd_api.g_exc_error;
4892 END IF;
4893 END IF;
4894
4895 --13535759
4896 IF (( l_operation_mode = L_PACK ) AND (p_content_lpn_id IS NOT NULL)) THEN
4897 FOR c_get_parents IN get_all_parents
4898 LOOP
4899 IF c_get_parents.lpn_id = l_content_lpn.lpn_id
4900 THEN
4901 IF (l_debug = 1) THEN
4902 mdebug('Content LPN '||l_content_lpn.license_plate_number||' is in the Parent Heirarchy of the Parent LPN(To LPN) '||l_lpn.license_plate_number, G_ERROR);
4903 END IF;
4904 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_LPN');
4905 fnd_msg_pub.ADD;
4906 RAISE fnd_api.g_exc_error;
4907 END IF;
4908 END LOOP;
4909 END IF;
4910 --13535759
4911
4912 l_quantity := 1;
4913 l_primary_quantity := 1;
4914 ELSIF ( p_content_item_id IS NOT NULL ) THEN
4915 l_progress := 'Calling INV_CACHE.Set_Item_Rec to get item values';
4916
4917 IF ( inv_cache.set_item_rec(
4918 p_organization_id => p_organization_id
4919 , p_item_id => p_content_item_id ) )
4920 THEN
4921 IF (l_debug = 1) THEN
4922 mdebug('Got Item info puom='||inv_cache.item_rec.primary_uom_code||' snctl='||inv_cache.item_rec.serial_number_control_code, G_INFO);
4923 mdebug('wuom='||inv_cache.item_rec.weight_uom_code||' wt='||inv_cache.item_rec.unit_weight||' vuom='||inv_cache.item_rec.volume_uom_code||' vol='||inv_cache.item_rec.unit_volume, G_INFO);
4924 END IF;
4925 ELSE
4926 l_progress := 'Error calling INV_CACHE.Set_Item_Rec for orgid'||p_organization_id||' item id='||p_content_item_id;
4927 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_ITEM');
4928 fnd_msg_pub.ADD;
4929 RAISE fnd_api.g_exc_error;
4930 END IF;
4931
4932 IF ( p_primary_quantity IS NULL ) THEN
4933 IF ( p_uom = inv_cache.item_rec.primary_uom_code ) THEN
4934 l_primary_quantity := p_quantity;
4935 ELSE
4936 l_primary_quantity := Round(Convert_UOM(p_content_item_id, p_quantity, p_uom, inv_cache.item_rec.primary_uom_code), 5); --13591755 added for GRUPO
4937 END IF;
4938 ELSE
4939 l_primary_quantity := p_primary_quantity;
4940 END IF;
4941
4942 l_quantity := p_quantity;
4943
4944 IF (l_debug = 1) THEN
4945 mdebug('l_quantity='||l_quantity||' l_primary_quantity='||l_primary_quantity, G_INFO);
4946 END IF;
4947 ELSIF ( l_operation_mode <> L_UNPACK_ALL ) THEN
4948 -- Unpack all transaction does not need a content lpn/item every other transaction should however.
4949 l_progress := 'Either an item or a content lpn must be specified';
4950 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_ITEM');
4951 fnd_msg_pub.ADD;
4952 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_CONTENT_LPN');
4953 fnd_msg_pub.ADD;
4954 RAISE fnd_api.g_exc_error;
4955 END IF;
4956
4957 -- Parse Serials with out validation
4958 -- Sub and locator might not be given in the case of pre-packing
4959 IF (p_content_item_id IS NOT NULL) THEN
4960 /* Toshiba Fix */
4961 IF ( inv_cache.item_rec.serial_number_control_code NOT IN (1) ) THEN
4962 IF ((p_from_serial_number IS NOT NULL) AND (p_to_serial_number IS NOT NULL)) THEN
4963 l_progress := 'Call this API to parse sn '||p_from_serial_number||'-'||p_to_serial_number;
4964
4965 IF (NOT mtl_serial_check.inv_serial_info(p_from_serial_number, p_to_serial_number, l_prefix, l_quantity, l_from_number, l_to_number, l_errorcode)) THEN
4966 IF (l_debug = 1) THEN
4967 mdebug('Invalid serial number in range', G_ERROR);
4968 END IF;
4969 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_SER');
4970 fnd_msg_pub.ADD;
4971 RAISE fnd_api.g_exc_error;
4972 END IF;
4973
4974 l_progress := 'Done with call to parse sn';
4975 IF (l_debug = 1) THEN
4976 mdebug('Parse SN done prefix='||l_prefix||' qty='||l_quantity||' fmnum='||l_from_number||' tonum='||l_to_number, G_MESSAGE);
4977 END IF;
4978
4979 -- bug5025225 transaction of serial items assumed to be in primary UOM
4980 -- must assign value to primary quantity.
4981 l_primary_quantity := l_quantity;
4982
4983 -- Check that in the case of a range of serial numbers, that the
4984 -- inputted p_quantity equals the amount of items in the serial range.
4985 IF (p_quantity IS NOT NULL) THEN
4986 IF (p_quantity <> l_quantity) THEN
4987 IF (l_debug = 1) THEN
4988 mdebug('Serial range quantity '||l_quantity||' not the same as given qty '||p_quantity, G_ERROR);
4989 END IF;
4990 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_X_QTY');
4991 fnd_msg_pub.ADD;
4992 RAISE fnd_api.g_exc_error;
4993 END IF;
4994 END IF;
4995 END IF;
4996 END IF;
4997 END IF;
4998
4999 l_progress := 'Figure out what subinventory we are trying to pack into';
5000 IF ( p_subinventory IS NULL ) THEN
5001 IF ( l_lpn.subinventory_code IS NOT NULL ) THEN
5002 l_subinventory := l_lpn.subinventory_code;
5003 l_locator_id := l_lpn.locator_id;
5004 ELSIF ( l_content_lpn.subinventory_code IS NOT NULL ) THEN
5005 l_subinventory := l_content_lpn.subinventory_code;
5006 l_locator_id := l_content_lpn.locator_id;
5007 ELSIF ( l_lpn.lpn_context IN (LPN_CONTEXT_INV, LPN_CONTEXT_PICKED) ) THEN
5008 IF (l_debug = 1) THEN
5009 mdebug('No sub and loc info found' , 1);
5010 END IF;
5011 FND_MESSAGE.SET_NAME('WMS', 'WMS_LPN_SUBLOC_MISS');
5012 FND_MSG_PUB.ADD;
5013 RAISE FND_API.G_EXC_ERROR;
5014 END IF;
5015 ELSE
5016 l_subinventory := p_subinventory;
5017 l_locator_id := p_locator_id;
5018 END IF;
5019
5020 IF ( l_subinventory IS NOT NULL ) THEN
5021 l_progress := 'Calling Inv_Cache.Set_Tosub_Rec to get sub';
5022 IF ( NOT inv_cache.set_tosub_rec(p_organization_id, l_subinventory) ) THEN
5023 l_progress := 'Failed to find subinventory org='||p_organization_id||' sub='||l_subinventory;
5024 FND_MESSAGE.SET_NAME('INV', 'INVALID_SUB');
5025 FND_MSG_PUB.ADD;
5026 RAISE FND_API.G_EXC_ERROR;
5027 END IF;
5028 END IF;
5029
5030 IF ( p_subinventory IS NOT NULL AND NVL(inv_cache.tosub_rec.lpn_controlled_flag, 2) = 1 ) THEN
5031 -- subinventory and location infromation was passed validate against lpn
5032 IF ( p_subinventory <> NVL(l_lpn.subinventory_code, l_content_lpn.subinventory_code) OR
5033 p_locator_id <> NVL(l_lpn.locator_id, l_content_lpn.locator_id ) ) THEN
5034 IF (l_debug = 1) THEN
5035 mdebug('LPN was found to be in a different sub/loc than what user specified' , 1);
5036 mdebug('lpn sub=' || l_lpn.subinventory_code ||' lpn loc=' || l_lpn.locator_id, 1);
5037 END IF;
5038 -- Recieving LPNs may have Rcv locations on them but. Allow the location
5039 -- to be different
5040 IF ( l_lpn.lpn_context <> LPN_CONTEXT_RCV ) THEN
5041 FND_MESSAGE.SET_NAME('WMS', 'WMS_LPN_SUBLOC_MISMATCH');
5042 FND_MSG_PUB.ADD;
5043 RAISE FND_API.G_EXC_ERROR;
5044 END IF;
5045 END IF;
5046 END IF;
5047
5048 /*** Packing or Adjust Operation ***/
5049 IF ( l_operation_mode = L_PACK OR l_operation_mode = L_CORRECT ) THEN
5050 -- Check that in case of a pack, the destination subinventory
5051 -- is an LPN enabled/controlled subinventory otherwise fail.
5052 IF ( l_subinventory IS NOT NULL AND NVL(inv_cache.tosub_rec.lpn_controlled_flag, 2) <> 1 ) THEN
5053 fnd_message.set_name('WMS', 'WMS_CONT_NON_LPN_SUB');
5054 fnd_msg_pub.ADD;
5055 RAISE fnd_api.g_exc_error;
5056 END IF;
5057
5058 IF ( p_content_lpn_id IS NOT NULL AND p_content_item_id IS NULL ) THEN
5059 l_progress := 'Packing a LPN into another LPN';
5060
5061 -- Update content LPN parent lpn to be null
5062 l_cont_new.lpn_id := p_content_lpn_id;
5063 l_cont_new.parent_lpn_id := l_lpn.lpn_id;
5064 l_cont_new.outermost_lpn_id := l_lpn.outermost_lpn_id;
5065 l_cont_new.source_type_id := p_source_type_id;
5066 l_cont_new.source_header_id := p_source_header_id;
5067 l_cont_new.source_line_id := p_source_line_id;
5068 l_cont_new.source_line_detail_id := p_source_line_detail_id;
5069 l_cont_new.source_name := p_source_name;
5070
5071 -- If the LPN has no sub or loc information, it will take on the values of the packed item.
5072
5073 IF ( l_lpn.subinventory_code IS NULL ) THEN
5074 IF (l_debug = 1) THEN
5075 mdebug('Xfer LPN has no sub lpnctx='||l_lpn.lpn_context||' clpn sub='||l_content_lpn.subinventory_code||' loc='||l_content_lpn.locator_id||' ctx='||l_content_lpn.lpn_context, G_MESSAGE);
5076 END IF;
5077 -- Update the local LPN variable
5078 l_new.lpn_id := l_lpn.lpn_id;
5079 l_new.subinventory_code := l_subinventory;
5080 l_new.locator_id := l_locator_id;
5081
5082 IF ( l_lpn.lpn_context = LPN_CONTEXT_PREGENERATED ) THEN
5083 -- If pregenerated take context of the content LPN
5084 l_new.lpn_context := l_content_lpn.lpn_context;
5085 END IF;
5086 ELSIF ( l_lpn.subinventory_code <> l_content_lpn.subinventory_code OR
5087 l_lpn.locator_id <> l_content_lpn.locator_id ) THEN
5088 -- Check if the content LPN's sub and loc are the same as the parent lpn
5089
5090 IF (l_debug = 1) THEN
5091 mdebug('parent lpn sub '|| l_lpn.subinventory_code || ' or loc ' || l_lpn.locator_id, G_ERROR);
5092 mdebug('differs from content item sub '|| l_lpn.subinventory_code || ' or loc ' || l_lpn.locator_id, G_ERROR);
5093 END IF;
5094 fnd_message.set_name('WMS', 'WMS_CONT_MISMATCHED_SUB_LOC');
5095 fnd_msg_pub.ADD;
5096 RAISE fnd_api.g_exc_error;
5097 END IF;
5098
5099 -- Only if there is a difference in location, update nested
5100 -- lpns/items/serials with the new location
5101 IF ( l_lpn.organization_id <> l_content_lpn.organization_id OR
5102 l_lpn.subinventory_code <> l_content_lpn.subinventory_code OR
5103 l_lpn.locator_id <> l_content_lpn.locator_id )
5104 THEN
5105 l_tmp_bulk_lpns.lpn_id.delete;
5106
5107 OPEN nested_children_cursor(l_content_lpn.outermost_lpn_id);
5108
5109 FETCH nested_children_cursor
5110 BULK COLLECT INTO l_tmp_bulk_lpns.lpn_id;
5111
5112 IF (l_debug = 1) THEN
5113 mdebug('Bulk update child LPN WLC/MSN: '||l_tmp_bulk_lpns.lpn_id.first||'-'||l_tmp_bulk_lpns.lpn_id.last, G_INFO);
5114 END IF;
5115
5116 -- Update the location information for the packed items
5117 IF ( l_lpn.organization_id <> l_content_lpn.organization_id) THEN
5118 FORALL bulk_i IN l_tmp_bulk_lpns.lpn_id.first .. l_tmp_bulk_lpns.lpn_id.last
5119 UPDATE wms_lpn_contents
5120 SET organization_id = l_lpn.organization_id
5121 , last_update_date = SYSDATE
5122 , last_updated_by = fnd_global.user_id
5123 , request_id = l_request_id
5124 WHERE parent_lpn_id = l_tmp_bulk_lpns.lpn_id(bulk_i);
5125
5126 IF (l_debug = 1) THEN
5127 mdebug('Bulk updated org in WLC cnt='||SQL%ROWCOUNT, G_INFO);
5128 END IF;
5129 END IF;
5130
5131 -- Update the location information for serialized packed items
5132 FORALL bulk_i IN l_tmp_bulk_lpns.lpn_id.first .. l_tmp_bulk_lpns.lpn_id.last
5133 UPDATE mtl_serial_numbers
5134 SET current_organization_id = l_lpn.organization_id
5135 , current_subinventory_code = l_lpn.subinventory_code
5136 , current_locator_id = l_lpn.locator_id
5137 , last_update_date = SYSDATE
5138 , last_updated_by = fnd_global.user_id
5139 WHERE lpn_id = l_tmp_bulk_lpns.lpn_id(bulk_i);
5140
5141 IF (l_debug = 1) THEN
5142 mdebug('Bulk updated org/sub/loc in MSN cnt='||SQL%ROWCOUNT, G_INFO);
5143 END IF;
5144
5145 CLOSE nested_children_cursor;
5146 END IF;
5147
5148 -- Update the location information for the nested child containers
5149 l_progress := 'Pack LPN: Need to update parent lpns weight and volume';
5150 l_wt_vol_new := l_lpn;
5151 l_change_in_gross_weight := l_content_lpn.gross_weight;
5152 l_change_in_gross_weight_uom := l_content_lpn.gross_weight_uom_code;
5153 -- bug5404902 Added to update tare weight of parent
5154 l_change_in_tare_weight := l_content_lpn.tare_weight;
5155 l_change_in_tare_weight_uom := l_content_lpn.tare_weight_uom_code;
5156
5157 -- Need to find if the container of content volume is greater and increment parent
5158 -- LPNs content volume by that amount
5159 Get_Greater_Qty (
5160 p_debug => l_debug
5161 , p_inventory_item_id => l_content_lpn.inventory_item_id
5162 , p_quantity1 => l_content_lpn.container_volume
5163 , p_quantity1_uom => l_content_lpn.container_volume_uom
5164 , p_quantity2 => l_content_lpn.content_volume
5165 , p_quantity2_uom => l_content_lpn.content_volume_uom_code
5166 , x_greater_qty => l_change_in_volume
5167 , x_greater_qty_uom => l_change_in_volume_uom );
5168
5169 ELSIF ( p_content_lpn_id IS NULL AND p_content_item_id IS NOT NULL ) THEN
5170 l_progress := 'Packing a non-container item item_id='|| p_content_item_id;
5171
5172 -- If the LPN has no sub or loc information, it will take on the values of the packed item.
5173 IF (l_lpn.subinventory_code IS NULL AND
5174 (p_subinventory IS NOT NULL OR p_locator_id IS NOT NULL))
5175 THEN
5176 l_progress := 'LPN has no loc info, setting to values passed in by api';
5177 l_new.lpn_id := l_lpn.lpn_id;
5178 l_new.subinventory_code := p_subinventory;
5179 l_new.locator_id := p_locator_id;
5180 END IF;
5181
5182 -- If item is serail controlled update MSN
5183 IF ( p_from_serial_number IS NOT NULL ) THEN
5184 l_progress := 'Packing serialized items sn '||p_from_serial_number||'-'||p_to_serial_number;
5185
5186 -- Serialized item packed LPN information are stored in the serial numbers table
5187 -- Also update the cost group field since it is not guaranteed that the serial number will
5188 -- have that value stamped
5189 UPDATE mtl_serial_numbers
5190 SET lpn_id = p_lpn_id
5191 , cost_group_id = p_cost_group_id
5192 , last_update_date = SYSDATE
5193 , last_updated_by = fnd_global.user_id
5194 , last_txn_source_type_id = DECODE(last_txn_source_type_id, 5, 5, p_source_type_id)--8687722
5195 , last_txn_source_id = p_source_header_id
5196 , last_txn_source_name = p_source_name
5197 , revision = DECODE(current_status, 3, revision, p_revision)
5198 , lot_number = DECODE(current_status, 3, lot_number, p_lot_number)
5199 WHERE inventory_item_id = p_content_item_id
5200 AND current_organization_id = p_organization_id
5201 AND length(serial_number) = length(p_from_serial_number)
5202 AND serial_number BETWEEN p_from_serial_number AND NVL(p_to_serial_number, p_from_serial_number);
5203
5204 l_serial_quantity := SQL%ROWCOUNT;
5205
5206 IF (l_debug = 1) THEN
5207 mdebug('Packed serials cnt='||l_serial_quantity, G_INFO);
5208 END IF;
5209
5210 -- Check that in the case of a range of serial numbers, that the
5211 -- inputted p_quantity equals the amount of items in the serial range.
5212 IF ( p_quantity IS NOT NULL ) THEN
5213 IF ( l_serial_quantity <> l_primary_quantity ) THEN
5214 l_progress := 'Serial range quantity '||l_serial_quantity||' not the same as given qty '||l_primary_quantity;
5215 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_X_QTY');
5216 fnd_msg_pub.ADD;
5217 RAISE fnd_api.g_exc_error;
5218 END IF;
5219 END IF;
5220 END IF;
5221
5222 -- Keep track of change in quantity since in case of correction
5223 -- it will be the difference of existing quantity and new quantity
5224 l_item_quantity := l_primary_quantity;
5225
5226 OPEN existing_record_cursor(l_lpn.lpn_context, l_serial_summary_entry);
5227
5228 FETCH existing_record_cursor INTO l_existing_record_cursor;
5229
5230 IF ( existing_record_cursor%FOUND ) THEN
5231 IF (l_debug = 1) THEN
5232 mdebug('Got WLC rec pqty='||l_existing_record_cursor.primary_quantity||' qty='||l_existing_record_cursor.quantity||' uom='||l_existing_record_cursor.uom_code||' cg='||l_existing_record_cursor.cost_group_id, G_INFO);
5233 END IF;
5234
5235 -- Validate that if the same item (as the passed-in item p_content_item_id)
5236 -- exists on the destination LPN (p_lpn_id) at the top level (not in a child LPN),
5237 -- their cost groups are the same.
5238 IF ( p_validation_level = fnd_api.g_valid_level_full ) THEN
5239 IF ( l_serial_summary_entry <> 1 AND p_cost_group_id <> l_existing_record_cursor.cost_group_id ) THEN
5240 IF (l_debug = 1) THEN
5241 mdebug('Cost Group Violation during packing cg='||l_existing_record_cursor.cost_group_id||' already exists in lpn', G_ERROR);
5242 END IF;
5243 fnd_message.set_name('WMS', 'WMS_CONT_DIFF_CST_GRPS');
5244 fnd_msg_pub.ADD;
5245 RAISE fnd_api.g_exc_error;
5246 END IF;
5247 END IF;
5248
5249 --INCONV kkillams
5250 IF p_sec_uom IS NOT NULL THEN
5251 l_sec_converted_quantity := inv_convert.inv_um_convert(p_content_item_id,
5252 g_precision,
5253 l_existing_record_cursor.secondary_quantity,
5254 l_existing_record_cursor.secondary_uom_code,
5255 p_sec_uom,
5256 NULL,
5257 NULL);
5258 IF ( l_sec_converted_quantity < 0 ) THEN
5259 fnd_message.set_name('INV', 'INV_UOM_CONVERSION_ERROR');
5260 fnd_message.set_token('uom1', l_existing_record_cursor.secondary_uom_code);
5261 fnd_message.set_token('uom2', p_sec_uom);
5262 fnd_message.set_token('module', l_api_name);
5263 fnd_msg_pub.ADD;
5264 RAISE fnd_api.g_exc_error;
5265 END IF;
5266 END IF;
5267 --INCONV kkillams
5268
5269 l_progress := 'Updating existing item row in WLC for pack';
5270 /* fix for bug 2949825 */
5271 IF ( l_operation_mode = L_CORRECT ) THEN
5272 UPDATE wms_lpn_contents
5273 SET last_update_date = SYSDATE
5274 , last_updated_by = fnd_global.user_id
5275 , request_id = l_request_id
5276 , quantity = l_quantity
5277 , uom_code = p_uom
5278 , primary_quantity = l_primary_quantity
5279 WHERE rowid = l_existing_record_cursor.rowid;
5280
5281 -- To calculate wt and volume changes need the difference in quantity
5282 l_item_quantity := l_primary_quantity - l_existing_record_cursor.primary_quantity;
5283 ELSE
5284 UPDATE WMS_LPN_CONTENTS
5285 SET last_update_date = SYSDATE
5286 , last_updated_by = FND_GLOBAL.USER_ID
5287 , request_id = l_request_id
5288 , quantity = quantity + l_quantity
5289 , uom_code = p_uom
5290 , primary_quantity = primary_quantity + round(l_primary_quantity,5)
5291 , secondary_quantity = CASE WHEN p_sec_uom IS NOT NULL THEN l_sec_converted_quantity + p_sec_quantity
5292 ELSE secondary_quantity END --INVCONV kkillams
5293 WHERE rowid = l_existing_record_cursor.rowid;
5294 END IF;
5295 ELSE
5296 IF (l_debug = 1) THEN
5297 mdebug('Inserting new item row into WLC');
5298 END IF;
5299
5300 -- bug 9695128
5301 -- Quantity columns should be rounded to 5 decimals to avoid rounding errors
5302 l_quantity := round(l_quantity,g_precision);
5303 l_primary_quantity := round(l_primary_quantity,g_precision);
5304
5305 INSERT INTO wms_lpn_contents (
5306 last_update_date
5307 , last_updated_by
5308 , creation_date
5309 , created_by
5310 , request_id
5311 , lpn_content_id
5312 , parent_lpn_id
5313 , organization_id
5314 , inventory_item_id
5315 , item_description
5316 , revision
5317 , lot_number
5318 , quantity
5319 , uom_code
5320 , primary_quantity
5321 , cost_group_id
5322 , source_type_id
5323 , source_header_id
5324 , source_line_id
5325 , source_line_detail_id
5326 , source_name
5327 , serial_summary_entry
5328 , secondary_quantity
5329 , secondary_uom_code)
5330 VALUES (
5331 SYSDATE
5332 , fnd_global.user_id
5333 , SYSDATE
5334 , fnd_global.user_id
5335 , l_request_id
5336 , wms_lpn_contents_s.NEXTVAL
5337 , p_lpn_id
5338 , p_organization_id
5339 , p_content_item_id
5340 , p_content_item_desc
5341 , p_revision
5342 , p_lot_number
5343 , l_quantity
5344 , p_uom
5345 , l_primary_quantity
5346 , p_cost_group_id
5347 , p_source_type_id
5348 , p_source_header_id
5349 , p_source_line_id
5350 , p_source_line_detail_id
5351 , p_source_name
5352 , l_serial_summary_entry
5353 , round(p_sec_quantity,g_precision) --INVCONV kkillams
5354 , p_sec_uom --INVCONV kkillams
5355 );
5356 END IF;
5357
5358 CLOSE existing_record_cursor;
5359
5360 l_progress := 'Pack item: Need to update parent lpns weight and volume';
5361 l_wt_vol_new := l_lpn;
5362 l_change_in_gross_weight := l_item_quantity * inv_cache.item_rec.unit_weight;
5363 l_change_in_gross_weight_uom := inv_cache.item_rec.weight_uom_code;
5364 l_change_in_volume := l_item_quantity * inv_cache.item_rec.unit_volume;
5365 l_change_in_volume_uom := inv_cache.item_rec.volume_uom_code;
5366 ELSE /** Packing a one time item **/
5367 -- If the LPN has no sub or loc information, it will take on the
5368 -- values of the packed item.
5369 IF (l_lpn.subinventory_code IS NULL AND
5370 (p_subinventory IS NOT NULL OR p_locator_id IS NOT NULL))
5371 THEN
5372 l_new.lpn_id := p_lpn_id;
5373 l_new.subinventory_code := p_subinventory;
5374 l_new.locator_id := p_locator_id;
5375 END IF;
5376
5377 /* Pack the one time item */
5378 OPEN one_time_item_cursor;
5379 FETCH one_time_item_cursor INTO l_one_time_item_rec;
5380
5381 IF one_time_item_cursor%NOTFOUND THEN
5382 INSERT INTO wms_lpn_contents (
5383 last_update_date
5384 , last_updated_by
5385 , creation_date
5386 , created_by
5387 , request_id
5388 , lpn_content_id
5389 , parent_lpn_id
5390 , organization_id
5391 , inventory_item_id
5392 , item_description
5393 , revision
5394 , lot_number
5395 , serial_number
5396 , quantity
5397 , uom_code
5398 , primary_quantity
5399 , cost_group_id
5400 , source_type_id
5401 , source_header_id
5402 , source_line_id
5403 , source_line_detail_id
5404 , source_name
5405 , serial_summary_entry
5406 , secondary_quantity
5407 , secondary_uom_code
5408 )
5409 VALUES (
5410 SYSDATE
5411 , fnd_global.user_id
5412 , SYSDATE
5413 , fnd_global.user_id
5414 , l_request_id
5415 , WMS_LPN_CONTENTS_S.NEXTVAL
5416 , p_lpn_id
5417 , p_organization_id
5418 , p_content_item_id
5419 , p_content_item_desc
5420 , p_revision
5421 , p_lot_number
5422 , p_from_serial_number
5423 , l_quantity
5424 , p_uom
5425 , l_primary_quantity
5426 , p_cost_group_id
5427 , p_source_type_id
5428 , p_source_header_id
5429 , p_source_line_id
5430 , p_source_line_detail_id
5431 , p_source_name
5432 , 2
5433 , p_sec_quantity --INVCONV kkillams
5434 , p_sec_uom --INVCONV kkillams
5435 );
5436 ELSE
5437 UPDATE wms_lpn_contents
5438 SET last_update_date = SYSDATE
5439 , last_updated_by = fnd_global.user_id
5440 , request_id = l_request_id
5441 , quantity = NVL(l_one_time_item_rec.quantity, 1) + NVL(l_quantity, 1)
5442 , uom_code = p_uom
5443 , source_type_id = p_source_type_id
5444 , source_header_id = p_source_header_id
5445 , source_line_id = p_source_line_id
5446 , source_line_detail_id = p_source_line_detail_id
5447 , source_name = p_source_name
5448 , secondary_quantity = CASE WHEN p_sec_uom IS NOT NULL THEN NVL(l_one_time_item_rec.secondary_quantity, 1) +
5449 inv_convert.inv_um_convert(inventory_item_id
5450 ,g_precision
5451 ,NVL(l_quantity,1)
5452 ,p_uom
5453 ,p_sec_uom
5454 ,NULL
5455 ,NULL)
5456 ELSE secondary_quantity END --INVCONV kkillams
5457 , secondary_uom_code = p_sec_uom --INVCONV kkillams
5458 WHERE rowid = l_one_time_item_rec.rowid;
5459 END IF;
5460
5461 CLOSE one_time_item_cursor;
5462
5463 END IF;
5464 ELSIF ( l_operation_mode = L_UNPACK ) THEN /*** Unpacking Operation ***/
5465 IF ( p_content_lpn_id IS NOT NULL AND p_content_item_id IS NULL ) THEN
5466 -- Update content LPN parent lpn to be null
5467 l_cont_new.lpn_id := p_content_lpn_id;
5468 l_cont_new.parent_lpn_id := FND_API.G_MISS_NUM;
5469 l_cont_new.outermost_lpn_id := p_content_lpn_id;
5470
5471 /* Bug 2308339: Update the Organization, Sub, Locator only if Sub is LPN Controlled */
5472 IF( l_subinventory IS NOT NULL AND NVL(inv_cache.tosub_rec.lpn_controlled_flag, 2) = 1 ) THEN
5473 FOR l_child_lpn IN nested_children_cursor(p_content_lpn_id) LOOP
5474 -- Only if there is a difference in location, update nested
5475 -- lpns/items/serials with the new location
5476 IF ( l_content_lpn.organization_id <> p_organization_id OR
5477 l_content_lpn.subinventory_code <> l_subinventory OR
5478 l_content_lpn.locator_id <> l_locator_id ) THEN
5479 -- Update the location information for the packed items
5480 IF ( l_content_lpn.organization_id <> p_organization_id ) THEN
5481 UPDATE wms_lpn_contents
5482 SET organization_id = p_organization_id
5483 , last_update_date = SYSDATE
5484 , last_updated_by = fnd_global.user_id
5485 , request_id = l_request_id
5486 WHERE organization_id = l_content_lpn.organization_id
5487 AND parent_lpn_id = l_child_lpn.lpn_id;
5488 END IF;
5489
5490 -- Update the location information for serialized packed items
5491 UPDATE mtl_serial_numbers
5492 SET current_organization_id = p_organization_id
5493 , current_subinventory_code = l_subinventory
5494 , current_locator_id = l_locator_id
5495 , last_update_date = SYSDATE
5496 , last_updated_by = fnd_global.user_id
5497 WHERE current_organization_id = l_content_lpn.organization_id
5498 AND lpn_id = l_child_lpn.lpn_id;
5499 END IF;
5500 END LOOP;
5501
5502 -- Update the location information for the nested child containers
5503 l_cont_new.organization_id := p_organization_id;
5504 l_cont_new.subinventory_code := l_subinventory;
5505 l_cont_new.locator_id := l_locator_id;
5506 END IF;
5507
5508 -- Check to see if there are any items or child containers in soruce LPN
5509 IF ( NVL(p_auto_unnest_empty_lpns, 1) = 1 AND l_lpn_is_empty = 0 ) THEN
5510 BEGIN
5511 SELECT 0 INTO l_lpn_is_empty
5512 FROM dual
5513 WHERE EXISTS (
5514 SELECT 1 FROM wms_lpn_contents
5515 WHERE organization_id = p_organization_id
5516 AND parent_lpn_id = l_lpn.lpn_id )
5517 OR EXISTS (
5518 SELECT 1 FROM wms_license_plate_numbers
5519 WHERE organization_id = p_organization_id
5520 AND parent_lpn_id = l_lpn.lpn_id
5521 AND lpn_id <> l_content_lpn.lpn_id );
5522 EXCEPTION
5523 WHEN NO_DATA_FOUND THEN
5524 l_lpn_is_empty := 1;
5525 END;
5526 END IF;
5527
5528 -- If the source LPN is not empty then the update weight and volume of source LPN
5529 -- Otherwise this calculation is irrelevant since the lpn will become pregenerated
5530 IF ( l_lpn_is_empty <> 1 ) THEN
5531 l_progress := 'Unpack LPN: Need to update parent lpns weight and volume';
5532 l_wt_vol_new := l_lpn;
5533 l_change_in_gross_weight := -1 * l_content_lpn.gross_weight;
5534 l_change_in_gross_weight_uom := l_content_lpn.gross_weight_uom_code;
5535 -- bug5404902 Added to update tare weight of parent
5536 l_change_in_tare_weight := -1 * l_content_lpn.tare_weight;
5537 l_change_in_tare_weight_uom := l_content_lpn.tare_weight_uom_code;
5538
5539 -- Need to find if the container of content volume is greater and decrement parent
5540 -- LPNs content volume by that amount
5541 Get_Greater_Qty (
5542 p_debug => l_debug
5543 , p_inventory_item_id => l_content_lpn.inventory_item_id
5544 , p_quantity1 => l_content_lpn.container_volume
5545 , p_quantity1_uom => l_content_lpn.container_volume_uom
5546 , p_quantity2 => l_content_lpn.content_volume
5547 , p_quantity2_uom => l_content_lpn.content_volume_uom_code
5548 , x_greater_qty => l_change_in_volume
5549 , x_greater_qty_uom => l_change_in_volume_uom );
5550
5551 -- Unpack need change value to negative
5552 l_change_in_volume := -1 * l_change_in_volume;
5553 END IF;
5554 ELSIF ((p_content_lpn_id IS NULL) AND (p_content_item_id IS NOT NULL)) THEN
5555 l_progress := 'Unpacking item from LPN';
5556
5557 IF ((p_from_serial_number IS NOT NULL)AND (p_to_serial_number IS NOT NULL)) THEN
5558 l_progress := 'Unacking serialized items sn '||p_from_serial_number||'-'||p_to_serial_number;
5559
5560 -- Serialized item packed LPN information are stored
5561 -- in the serial numbers table
5562 UPDATE mtl_serial_numbers
5563 SET lpn_id = NULL
5564 , last_update_date = SYSDATE
5565 , last_updated_by = fnd_global.user_id
5566 WHERE inventory_item_id = p_content_item_id
5567 AND current_organization_id = p_organization_id
5568 AND length(serial_number) = length(p_from_serial_number)
5569 AND serial_number BETWEEN p_from_serial_number AND NVL(p_to_serial_number, p_from_serial_number);
5570
5571 IF (l_debug = 1) THEN
5572 mdebug('Unpacked serials cnt='||SQL%ROWCOUNT, G_INFO);
5573 END IF;
5574 END IF;
5575
5576 -- If serial numbers were passed to API remove contents from serial summary entries in WLC
5577 IF ( p_ignore_item_controls = 1 ) THEN
5578 l_serial_summary_entry := NULL;
5579 END IF;
5580
5581 -- Use l_item_quantity to remember how much qty needs to be decremented
5582 l_item_quantity := l_primary_quantity;
5583 l_uom_priority := p_uom;
5584
5585 l_progress := 'Opening existing_unpack_record_cursor serentry='||l_serial_summary_entry||' uom='||l_uom_priority;
5586 OPEN existing_unpack_record_cursor(l_serial_summary_entry, l_uom_priority);
5587
5588 LOOP
5589 FETCH existing_unpack_record_cursor INTO l_temp_record;
5590
5591 IF ( existing_unpack_record_cursor%FOUND ) THEN
5592 IF (l_debug = 1) THEN
5593 mdebug('Got WLC rec pqty='||l_temp_record.primary_quantity||' qty='||l_temp_record.quantity||' uom='||l_temp_record.uom_code||' lot='||l_temp_record.lot_number||' snsum='||l_temp_record.serial_summary_entry, G_INFO);
5594 END IF;
5595
5596 IF ( l_temp_record.primary_quantity IS NULL ) THEN
5597 l_temp_record.primary_quantity := Round(Convert_UOM(
5598 p_content_item_id
5599 , l_temp_record.quantity
5600 , l_temp_record.uom_code
5601 , inv_cache.item_rec.primary_uom_code), 5); --13591755 added for GRUPO
5602
5603 IF (l_debug = 1) THEN
5604 mdebug('Converted WLC pri qty='||l_temp_record.primary_quantity, G_INFO);
5605 END IF;
5606 END IF;
5607
5608 IF (l_debug = 1) THEN
5609 mdebug('p_sec_uom ='||p_sec_uom, G_INFO);
5610 mdebug('l_temp_record.secondary_uom_code ='||l_temp_record.secondary_uom_code, G_INFO);
5611 END IF;
5612 --INCONV kkillams
5613
5614 -- Bug 7665639 rework
5615
5616 IF (p_sec_uom IS NOT NULL )
5617 AND (p_sec_uom <> l_temp_record.secondary_uom_code) THEN
5618 l_sec_converted_quantity := inv_convert.inv_um_convert(p_content_item_id,
5619 g_precision,
5620 l_temp_record.secondary_quantity,
5621 l_temp_record.secondary_uom_code,
5622 p_sec_uom,
5623 NULL,
5624 NULL);
5625 IF (l_debug = 1) THEN
5626 mdebug('l_sec_converted_quantity ='||l_sec_converted_quantity, G_INFO);
5627 END IF;
5628
5629 IF ( l_sec_converted_quantity < 0 ) THEN
5630 fnd_message.set_name('INV', 'INV_UOM_CONVERSION_ERROR');
5631 fnd_message.set_token('uom1', l_temp_record.secondary_uom_code);
5632 fnd_message.set_token('uom2', p_sec_uom);
5633 fnd_message.set_token('module', l_api_name);
5634 fnd_msg_pub.ADD;
5635 RAISE fnd_api.g_exc_error;
5636 END IF;
5637 else -- Bug 7665639 rework added else condition
5638 l_sec_converted_quantity := l_temp_record.secondary_quantity;
5639
5640 END IF;
5641
5642
5643 IF (l_debug = 1) THEN
5644 mdebug('l_item_quantity ='||l_item_quantity, G_INFO);
5645 mdebug('l_temp_record.primary_quantity ='||l_temp_record.primary_quantity, G_INFO);
5646 mdebug('l_temp_record.uom_code ='||l_temp_record.uom_code, G_INFO);
5647 mdebug('inv_cache.item_rec.primary_uom_code ='||inv_cache.item_rec.primary_uom_code, G_INFO);
5648 END IF;
5649
5650 --INCONV kkillams
5651
5652 IF ( round(l_item_quantity, g_precision) < round(l_temp_record.primary_quantity, g_precision) ) THEN
5653 IF inv_cache.item_rec.tracking_quantity_ind = 'PS' THEN -- 16466243
5654
5655 UPDATE wms_lpn_contents
5656 SET last_update_date = SYSDATE
5657 , last_updated_by = fnd_global.user_id
5658 , request_id = l_request_id
5659 , quantity = (CASE WHEN uom_code = inv_cache.item_rec.primary_uom_code
5660 THEN Round((primary_quantity - l_item_quantity), 5)
5661 ELSE
5662 CASE WHEN uom_code = Nvl(SECONDARY_UOM_CODE,'@@@')
5663 THEN Round((secondary_quantity - p_sec_quantity), 5)
5664 ELSE quantity - Round(Convert_UOM(
5665 p_content_item_id
5666 , l_item_quantity
5667 , inv_cache.item_rec.primary_uom_code
5668 , l_temp_record.uom_code), 5)
5669 END
5670 END )
5671 , primary_quantity = Round((primary_quantity - l_item_quantity), 5)
5672 , secondary_quantity = CASE WHEN p_sec_uom IS NOT NULL
5673 THEN Round((secondary_quantity - p_sec_quantity), 5)
5674 ELSE secondary_quantity END
5675 , secondary_uom_code = p_sec_uom
5676 WHERE rowid = l_temp_record.rowid;
5677
5678 ELSE -- 16466243
5679 IF ( l_temp_record.uom_code <> inv_cache.item_rec.primary_uom_code ) THEN
5680 l_converted_quantity := Round(Convert_UOM(
5681 p_content_item_id
5682 , l_item_quantity
5683 , inv_cache.item_rec.primary_uom_code
5684 , l_temp_record.uom_code), 5); --13591755 added for GRUPO
5685 ELSE
5686 l_converted_quantity := l_item_quantity;
5687 END IF;
5688
5689 IF (l_debug = 1) THEN
5690 mdebug('l_converted_quantity ='||l_converted_quantity, G_INFO);
5691 END IF;
5692 --Bug#8526734,no need to use std conversion everytime.Also added lot_number in case p_sec_quantity is null
5693 -- Decrement unpack quantity from contents and break loop
5694 UPDATE wms_lpn_contents
5695 SET last_update_date = SYSDATE
5696 , last_updated_by = fnd_global.user_id
5697 , request_id = l_request_id
5698 , quantity = quantity - l_converted_quantity
5699 , primary_quantity = primary_quantity - l_item_quantity
5700 , secondary_quantity = CASE WHEN p_sec_uom IS NOT NULL
5701 THEN (secondary_quantity - p_sec_quantity) -- bug 8671025
5702 ELSE secondary_quantity END --INVCONV kkillams
5703 , secondary_uom_code = p_sec_uom
5704 WHERE rowid = l_temp_record.rowid;
5705 END IF; -- 16466243
5706
5707 EXIT;
5708 ELSIF ( round(l_item_quantity, g_precision) >= round(l_temp_record.primary_quantity, g_precision) ) THEN
5709 mdebug('Delete column from content table and decrement total unpack quantity', G_INFO);
5710 DELETE FROM wms_lpn_contents
5711 WHERE rowid = l_temp_record.rowid;
5712
5713 l_item_quantity := l_item_quantity - l_temp_record.primary_quantity;
5714 l_item_quantity := round(l_item_quantity,g_precision);-- round the quantity to 5 decimal places to avoid errors, bug 9695128
5715
5716 EXIT WHEN l_item_quantity <= 0;
5717 END IF;
5718 ELSIF ( l_uom_priority IS NOT NULL ) THEN
5719 IF (l_debug = 1) THEN
5720 mdebug('Not enough to unpack in trx uom='||l_uom_priority, G_ERROR);
5721 END IF;
5722 l_uom_priority := NULL;
5723 CLOSE existing_unpack_record_cursor;
5724 OPEN existing_unpack_record_cursor(l_serial_summary_entry, l_uom_priority);
5725 ELSIF ( l_item_quantity = l_primary_quantity ) THEN
5726 IF (l_debug = 1) THEN
5727 mdebug('Content item not found to unpack', G_ERROR);
5728 END IF;
5729 fnd_message.set_name('WMS', 'WMS_CONT_ITEM_NOT_FOUND');
5730 fnd_msg_pub.ADD;
5731 RAISE fnd_api.g_exc_error;
5732 ELSE
5733 IF (l_debug = 1) THEN
5734 mdebug('Not enough to upack, qty found='||l_item_quantity, G_ERROR);
5735 END IF;
5736 fnd_message.set_name('WMS', 'WMS_CONT_NOT_ENOUGH_TO_UNPACK');
5737 fnd_msg_pub.ADD;
5738 RAISE fnd_api.g_exc_error;
5739 END IF;
5740 END LOOP;
5741 CLOSE existing_unpack_record_cursor;
5742
5743 -- Check to see if there are any items or child containers in soruce LPN
5744 IF ( NVL(p_auto_unnest_empty_lpns, 1) = 1 AND l_lpn_is_empty = 0 ) THEN
5745 BEGIN
5746 SELECT 0 INTO l_lpn_is_empty
5747 FROM dual
5748 WHERE EXISTS (
5749 SELECT 1 FROM wms_lpn_contents
5750 WHERE organization_id = p_organization_id
5751 AND parent_lpn_id = l_lpn.lpn_id )
5752 OR EXISTS (
5753 SELECT 1 FROM wms_license_plate_numbers
5754 WHERE organization_id = p_organization_id
5755 AND parent_lpn_id = l_lpn.lpn_id );
5756 EXCEPTION
5757 WHEN NO_DATA_FOUND THEN
5758 l_lpn_is_empty := 1;
5759 END;
5760 END IF;
5761
5762 -- If the source LPN is not empty then the update weight and volume of source LPN
5763 -- Otherwise this calculation is irrelevant since the lpn will become pregenerated
5764 IF ( l_lpn_is_empty <> 1 ) THEN
5765 l_progress := 'Unpack item: Need to update parent lpns weight and volume';
5766 l_wt_vol_new := l_lpn;
5767 l_change_in_gross_weight := -1 * l_primary_quantity * inv_cache.item_rec.unit_weight;
5768 l_change_in_gross_weight_uom := inv_cache.item_rec.weight_uom_code;
5769 l_change_in_volume := -1 * l_primary_quantity * inv_cache.item_rec.unit_volume;
5770 l_change_in_volume_uom := inv_cache.item_rec.volume_uom_code;
5771 END IF;
5772 ELSIF (p_content_item_desc IS NOT NULL) THEN /*Unpacking a one time item*/
5773 OPEN one_time_item_cursor;
5774 FETCH one_time_item_cursor INTO l_one_time_item_rec;
5775
5776 IF one_time_item_cursor%FOUND THEN
5777 IF ( l_quantity < l_one_time_item_rec.quantity ) THEN
5778 UPDATE wms_lpn_contents
5779 SET last_update_date = SYSDATE
5780 , last_updated_by = fnd_global.user_id
5781 , request_id = l_request_id
5782 , quantity = (l_one_time_item_rec.quantity - l_quantity)
5783 , uom_code = p_uom
5784 WHERE rowid = l_one_time_item_rec.rowid;
5785 ELSIF ( l_quantity = l_one_time_item_rec.quantity ) THEN
5786 DELETE FROM wms_lpn_contents
5787 WHERE rowid = l_one_time_item_rec.rowid;
5788 ELSE
5789 IF (l_debug = 1) THEN
5790 mdebug('Not enough of this onetime item to unpack', G_ERROR);
5791 END IF;
5792 fnd_message.set_name('WMS', 'WMS_CONT_NOT_ENOUGH_TO_UNPACK');
5793 fnd_msg_pub.ADD;
5794 RAISE fnd_api.g_exc_error;
5795 END IF;
5796 ELSE
5797 IF (l_debug = 1) THEN
5798 mdebug('No one time items exits', G_ERROR);
5799 END IF;
5800 fnd_message.set_name('WMS', 'WMS_CONT_NO_ONE_TIME_ITEM');
5801 fnd_msg_pub.ADD;
5802 RAISE fnd_api.g_exc_error;
5803 END IF;
5804 END IF;
5805 ELSIF ( l_operation_mode = L_UNPACK_ALL ) THEN /*** Unpack All Operation ***/
5806 -- This lpn will be empty, need to check parent lpns to see if they also will
5807 -- be empty. if so, they will need to be made defined but not used.
5808 l_lpn_is_empty := 1;
5809 l_tmp_bulk_lpns.lpn_id.delete;
5810
5811 -- Update the information for the child containers
5812 FOR l_child_lpn IN nested_container_cursor LOOP
5813 IF (l_debug = 1) THEN
5814 mdebug('Unpacking all for child lpn='||l_child_lpn.lpn_id, G_INFO);
5815 END IF;
5816
5817 l_tmp_i := NVL(l_lpn_tbl.last, 0) + 1;
5818
5819 -- bug5404902 section for making tare via MSI
5820 IF ( l_child_lpn.inventory_item_id IS NOT NULL ) THEN
5821 SELECT unit_weight
5822 , weight_uom_code
5823 INTO l_lpn_tbl(l_tmp_i).tare_weight
5824 , l_lpn_tbl(l_tmp_i).tare_weight_uom_code
5825 FROM mtl_system_items
5826 WHERE organization_id = l_child_lpn.organization_id
5827 AND inventory_item_id = l_child_lpn.inventory_item_id;
5828 ELSE
5829 -- if there isn't a container item, empty lpns will have undefined
5830 -- tare weight
5831 l_lpn_tbl(l_tmp_i).tare_weight := fnd_api.g_miss_num;
5832 l_lpn_tbl(l_tmp_i).tare_weight_uom_code := fnd_api.g_miss_char;
5833 END IF;
5834
5835 l_lpn_tbl(l_tmp_i).lpn_id := l_child_lpn.lpn_id;
5836 l_lpn_tbl(l_tmp_i).organization_id := p_organization_id;
5837 l_lpn_tbl(l_tmp_i).subinventory_code := fnd_api.g_miss_char;
5838 l_lpn_tbl(l_tmp_i).locator_id := fnd_api.g_miss_num;
5839 l_lpn_tbl(l_tmp_i).parent_lpn_id := fnd_api.g_miss_num;
5840 l_lpn_tbl(l_tmp_i).content_volume := fnd_api.g_miss_num;
5841 l_lpn_tbl(l_tmp_i).content_volume_uom_code := fnd_api.g_miss_char;
5842 -- bug5404902 changed l_child_lpn to l_lpn_tbl(l_tmp_i) since it represents
5843 -- the container items original unit weight
5844 l_lpn_tbl(l_tmp_i).gross_weight := NVL(l_lpn_tbl(l_tmp_i).tare_weight, fnd_api.g_miss_num);
5845 l_lpn_tbl(l_tmp_i).gross_weight_uom_code := NVL(l_lpn_tbl(l_tmp_i).tare_weight_uom_code, fnd_api.g_miss_char);
5846 l_lpn_tbl(l_tmp_i).outermost_lpn_id := l_child_lpn.lpn_id;
5847 l_lpn_tbl(l_tmp_i).lpn_context := LPN_CONTEXT_PREGENERATED;
5848
5849 l_progress := 'Add child LPN to bulk rec to delete contents';
5850 l_tmp_bulk_lpns.lpn_id(NVL(l_tmp_bulk_lpns.lpn_id.last, 0) + 1) := l_child_lpn.lpn_id;
5851 END LOOP;
5852
5853 IF (l_debug = 1) THEN
5854 mdebug('Bulk Delete/Update LPNs in WLC/MSN: '||l_tmp_bulk_lpns.lpn_id.first||'-'||l_tmp_bulk_lpns.lpn_id.last, G_INFO);
5855 END IF;
5856
5857 -- Remove the records for the packed items
5858 FORALL bulk_i IN l_tmp_bulk_lpns.lpn_id.first .. l_tmp_bulk_lpns.lpn_id.last
5859 DELETE FROM wms_lpn_contents
5860 WHERE parent_lpn_id = l_tmp_bulk_lpns.lpn_id(bulk_i);
5861
5862 IF (l_debug = 1) THEN
5863 mdebug('Bulk delete from WLC cnt='||SQL%ROWCOUNT, G_INFO);
5864 END IF;
5865
5866 -- Update the information for serialized packed items
5867 FORALL bulk_i IN l_tmp_bulk_lpns.lpn_id.first .. l_tmp_bulk_lpns.lpn_id.last
5868 UPDATE mtl_serial_numbers
5869 SET last_update_date = SYSDATE
5870 , last_updated_by = fnd_global.user_id
5871 , lpn_id = NULL
5872 WHERE lpn_id = l_tmp_bulk_lpns.lpn_id(bulk_i);
5873
5874 IF (l_debug = 1) THEN
5875 mdebug('Bulk update MSN cnt='||SQL%ROWCOUNT, G_INFO);
5876 END IF;
5877 END IF;
5878
5879 IF ( l_lpn_is_empty = 1 ) THEN
5880 -- bug5404902 added org and item
5881 empty_lpn_rec.organization_id := l_lpn.organization_id;
5882 empty_lpn_rec.inventory_item_id := l_lpn.inventory_item_id;
5883 empty_lpn_rec.lpn_id := l_lpn.lpn_id;
5884 empty_lpn_rec.parent_lpn_id := l_lpn.parent_lpn_id;
5885 empty_lpn_rec.gross_weight := l_lpn.gross_weight;
5886 empty_lpn_rec.gross_weight_uom_code := l_lpn.gross_weight_uom_code;
5887 -- bug5404902 added
5888 empty_lpn_rec.tare_weight := l_lpn.tare_weight;
5889 empty_lpn_rec.tare_weight_uom_code := l_lpn.tare_weight_uom_code;
5890 empty_lpn_rec.container_volume := l_lpn.container_volume;
5891 empty_lpn_rec.container_volume_uom := l_lpn.container_volume_uom;
5892 empty_lpn_rec.content_volume := l_lpn.content_volume;
5893 empty_lpn_rec.content_volume_uom_code := l_lpn.content_volume_uom_code;
5894
5895 -- Since source lpn is being unnested, it may cause parent lpn to be empty and cause a chain reaction
5896 -- or parent LPNs to become pregenerated. Loop through parents until an unempty one is found
5897 LOOP
5898 IF (l_debug = 1) THEN
5899 mdebug('lpn_id='||empty_lpn_rec.lpn_id||' is empty, making pregenerated plpnid='||empty_lpn_rec.parent_lpn_id||' empty='||l_lpn_is_empty, G_MESSAGE);
5900 END IF;
5901
5902 l_tmp_i := NVL(l_lpn_tbl.last, 0) + 1;
5903
5904 -- bug5404902 section for making tare via MSI
5905 IF ( empty_lpn_rec.inventory_item_id IS NOT NULL ) THEN
5906 SELECT unit_weight
5907 , weight_uom_code
5908 INTO l_lpn_tbl(l_tmp_i).tare_weight
5909 , l_lpn_tbl(l_tmp_i).tare_weight_uom_code
5910 FROM mtl_system_items
5911 WHERE organization_id = empty_lpn_rec.organization_id
5912 AND inventory_item_id = empty_lpn_rec.inventory_item_id;
5913 ELSE
5914 -- if there isn't a container item, empty lpns will have undefined
5915 -- tare weight
5916 l_lpn_tbl(l_tmp_i).tare_weight := fnd_api.g_miss_num;
5917 l_lpn_tbl(l_tmp_i).tare_weight_uom_code := fnd_api.g_miss_char;
5918 END IF;
5919
5920 l_lpn_tbl(l_tmp_i).lpn_id := empty_lpn_rec.lpn_id;
5921 l_lpn_tbl(l_tmp_i).subinventory_code := fnd_api.g_miss_char;
5922 l_lpn_tbl(l_tmp_i).locator_id := fnd_api.g_miss_num;
5923 l_lpn_tbl(l_tmp_i).parent_lpn_id := fnd_api.g_miss_num;
5924 l_lpn_tbl(l_tmp_i).content_volume := fnd_api.g_miss_num;
5925 l_lpn_tbl(l_tmp_i).content_volume_uom_code := fnd_api.g_miss_char;
5926 -- bug5404902 changed empty_lpn_rec to l_lpn_tbl(l_tmp_i) since it represents
5927 -- the container items original unit weight
5928 l_lpn_tbl(l_tmp_i).gross_weight := NVL(l_lpn_tbl(l_tmp_i).tare_weight, fnd_api.g_miss_num);
5929 l_lpn_tbl(l_tmp_i).gross_weight_uom_code := NVL(l_lpn_tbl(l_tmp_i).tare_weight_uom_code, fnd_api.g_miss_char);
5930 l_lpn_tbl(l_tmp_i).outermost_lpn_id := empty_lpn_rec.lpn_id;
5931 IF (l_lpn.lpn_context = LPN_CONTEXT_STORES ) THEN --12363213,keep issued out LPN as it is.
5932 l_lpn_tbl(l_tmp_i).lpn_context := LPN_CONTEXT_STORES ;
5933 ELSE
5934 l_lpn_tbl(l_tmp_i).lpn_context := LPN_CONTEXT_PREGENERATED;
5935 END IF;
5936
5937 IF ( empty_lpn_rec.parent_lpn_id IS NOT NULL ) THEN
5938 BEGIN
5939 SELECT 0 INTO l_lpn_is_empty
5940 FROM dual
5941 WHERE EXISTS (
5942 -- Check to make sure that the parent lpn has no items in it
5943 SELECT 1 FROM wms_lpn_contents
5944 WHERE organization_id = p_organization_id
5945 AND parent_lpn_id = empty_lpn_rec.parent_lpn_id )
5946 OR EXISTS (
5947 -- Check to make sure that the parent lpn has no lpns in it
5948 -- Ignore the child lpn that will become pregenerated later since
5949 -- we already know it will unpacked from the parent
5950 SELECT 1 FROM wms_license_plate_numbers
5951 WHERE organization_id = p_organization_id
5952 AND parent_lpn_id = empty_lpn_rec.parent_lpn_id
5953 AND lpn_id <> empty_lpn_rec.lpn_id );
5954 EXCEPTION
5955 WHEN NO_DATA_FOUND THEN
5956 l_lpn_is_empty := 1;
5957 END;
5958
5959 -- If lpn has any weight in it, it needs to be decremented from the the parent lpn
5960 IF ( l_lpn_is_empty <> 1 ) THEN
5961 l_progress := 'UPDATE Wt and Vol when making to auto unnest empty LPNs';
5962
5963 l_change_in_gross_weight := -1 * empty_lpn_rec.gross_weight;
5964 l_change_in_gross_weight_uom := empty_lpn_rec.gross_weight_uom_code;
5965 -- bug5404902 added
5966 l_change_in_tare_weight := -1 * empty_lpn_rec.tare_weight;
5967 l_change_in_tare_weight_uom := empty_lpn_rec.tare_weight_uom_code;
5968
5969 -- Need to find if the container of content volume is greater and decrement parent
5970 -- LPNs content volume by that amount
5971 Get_Greater_Qty (
5972 p_debug => l_debug
5973 , p_inventory_item_id => empty_lpn_rec.inventory_item_id
5974 , p_quantity1 => empty_lpn_rec.container_volume
5975 , p_quantity1_uom => empty_lpn_rec.container_volume_uom
5976 , p_quantity2 => empty_lpn_rec.content_volume
5977 , p_quantity2_uom => empty_lpn_rec.content_volume_uom_code
5978 , x_greater_qty => l_change_in_volume
5979 , x_greater_qty_uom => l_change_in_volume_uom );
5980
5981 -- Unpack need change value to negative
5982 l_change_in_volume := -1 * l_change_in_volume;
5983
5984 IF ( nested_parent_cursor%ISOPEN ) THEN
5985 FETCH nested_parent_cursor INTO empty_lpn_rec;
5986 l_wt_vol_new.lpn_id := empty_lpn_rec.lpn_id;
5987 l_wt_vol_new.inventory_item_id := empty_lpn_rec.inventory_item_id;
5988 l_wt_vol_new.gross_weight := empty_lpn_rec.gross_weight;
5989 l_wt_vol_new.gross_weight_uom_code := empty_lpn_rec.gross_weight_uom_code;
5990 l_wt_vol_new.tare_weight := empty_lpn_rec.tare_weight;
5991 l_wt_vol_new.tare_weight_uom_code := empty_lpn_rec.tare_weight_uom_code;
5992 l_wt_vol_new.content_volume := empty_lpn_rec.content_volume;
5993 l_wt_vol_new.content_volume_uom_code := empty_lpn_rec.content_volume_uom_code;
5994 ELSE -- Need to get lpn_information of parent_lpn
5995 SELECT lpn_id
5996 , inventory_item_id
5997 , gross_weight
5998 , gross_weight_uom_code
5999 , tare_weight
6000 , tare_weight_uom_code
6001 , content_volume
6002 , content_volume_uom_code
6003 INTO l_wt_vol_new.lpn_id
6004 , l_wt_vol_new.inventory_item_id
6005 , l_wt_vol_new.gross_weight
6006 , l_wt_vol_new.gross_weight_uom_code
6007 , l_wt_vol_new.tare_weight
6008 , l_wt_vol_new.tare_weight_uom_code
6009 , l_wt_vol_new.content_volume
6010 , l_wt_vol_new.content_volume_uom_code
6011 FROM wms_license_plate_numbers
6012 WHERE lpn_id = empty_lpn_rec.parent_lpn_id;
6013 END IF;
6014 END IF;
6015 END IF;
6016
6017 -- If parent lpn is not empty or doesn't exist, We are at the end.
6018 IF ( empty_lpn_rec.parent_lpn_id IS NULL OR l_lpn_is_empty = 0 ) THEN
6019 EXIT;
6020 ELSIF ( NOT nested_parent_cursor%ISOPEN ) THEN
6021 OPEN nested_parent_cursor(l_lpn.parent_lpn_id);
6022 END IF;
6023
6024 FETCH nested_parent_cursor INTO empty_lpn_rec;
6025 EXIT WHEN nested_parent_cursor%NOTFOUND;
6026 END LOOP;
6027
6028 IF ( nested_parent_cursor%ISOPEN ) THEN
6029 CLOSE nested_parent_cursor;
6030 END IF;
6031 END IF;
6032
6033 IF (l_debug = 1) THEN
6034 mdebug('lpn_id='||l_wt_vol_new.lpn_id||' change_gwt='||l_change_in_gross_weight||' change_gwt_uom='||l_change_in_gross_weight_uom||
6035 ' change_twt='||l_change_in_tare_weight||' change_twt_uom='||l_change_in_tare_weight_uom||' change_vol='||l_change_in_volume||' change_vol_uom='||l_change_in_volume_uom, G_INFO);
6036 END IF;
6037
6038 -- If a item or LPN was packed or unpacked from the parent_lpn (p_lpn). And it
6039 -- had a weight of volume. need to recalculate the weight and volume of the
6040 -- parent LPN
6041 -- bug5404902 add section for tare weight
6042 IF ( (NVL(l_change_in_gross_weight, 0) <> 0 AND l_change_in_gross_weight_uom IS NOT NULL)OR
6043 (NVL(l_change_in_tare_weight, 0) <> 0 AND l_change_in_tare_weight_uom IS NOT NULL)OR
6044 (NVL(l_change_in_volume, 0) <> 0 AND l_change_in_volume_uom IS NOT NULL) )
6045 THEN
6046 l_progress := 'calculate any change in weight and volume';
6047
6048 IF ( NVL(l_change_in_gross_weight, 0) = 0 OR l_change_in_gross_weight_uom IS NULL ) THEN
6049 -- Item/LPN weight not defined, no change in LPN weight
6050 l_wt_vol_new.gross_weight := NULL;
6051 l_wt_vol_new.gross_weight_uom_code := NULL;
6052 ELSIF ( NVL(l_wt_vol_new.gross_weight, 0) = 0 OR l_wt_vol_new.gross_weight_uom_code IS NULL ) THEN
6053 -- LPN has no gross weight, if packing assign total item/LPN weight to gross
6054 -- if unpacking, no change, since weight cannot go negative
6055 IF ( l_change_in_gross_weight > 0 ) THEN
6056 l_wt_vol_new.gross_weight := l_change_in_gross_weight;
6057 l_wt_vol_new.gross_weight_uom_code := l_change_in_gross_weight_uom;
6058 END IF;
6059 ELSIF ( l_wt_vol_new.gross_weight_uom_code = l_change_in_gross_weight_uom ) THEN
6060 -- Same uom, can simply add the two values
6061 l_wt_vol_new.gross_weight := l_wt_vol_new.gross_weight + l_change_in_gross_weight;
6062 ELSE
6063 -- Both are not null but with different UOMs need to convert
6064 -- If cannot covert uom, ignore the change in volume
6065 IF ( inv_cache.item_rec.weight_uom_code IS NOT NULL) THEN
6066 IF (l_change_in_gross_weight_uom <> inv_cache.item_rec.weight_uom_code) THEN --8447369 added condition
6067 l_change_in_gross_weight := Convert_UOM(
6068 p_inventory_item_id => l_lpn.inventory_item_id
6069 , p_fm_quantity => l_change_in_gross_weight
6070 , p_fm_uom => l_change_in_gross_weight_uom
6071 , p_to_uom => inv_cache.item_rec.weight_uom_code
6072 , p_mode => G_NO_CONV_RETURN_ZERO );
6073 END IF;
6074
6075 IF (l_wt_vol_new.gross_weight_uom_code <> inv_cache.item_rec.weight_uom_code ) THEN --8447369 added condition
6076 l_wt_vol_new.gross_weight := Convert_UOM(
6077 p_inventory_item_id => l_lpn.inventory_item_id
6078 , p_fm_quantity => l_wt_vol_new.gross_weight
6079 , p_fm_uom => l_wt_vol_new.gross_weight_uom_code
6080 , p_to_uom => inv_cache.item_rec.weight_uom_code
6081 , p_mode => G_NO_CONV_RETURN_ZERO );
6082 l_wt_vol_new.gross_weight_uom_code := inv_cache.item_rec.weight_uom_code ;
6083 END IF;
6084 ELSE
6085 l_change_in_gross_weight := Convert_UOM(
6086 p_inventory_item_id => l_lpn.inventory_item_id
6087 , p_fm_quantity => l_change_in_gross_weight
6088 , p_fm_uom => l_change_in_gross_weight_uom
6089 , p_to_uom => l_wt_vol_new.gross_weight_uom_code
6090 , p_mode => G_NO_CONV_RETURN_ZERO );
6091
6092 END IF;
6093
6094 l_wt_vol_new.gross_weight := l_wt_vol_new.gross_weight + l_change_in_gross_weight;
6095 END IF;
6096
6097 IF ( l_wt_vol_new.gross_weight < 0 ) THEN
6098 l_wt_vol_new.gross_weight := 0;
6099 END IF;
6100
6101 -- bug5404902 added section for tare weight
6102 l_progress := 'Calculate changes in tare weight';
6103
6104 IF ( NVL(l_change_in_tare_weight, 0) = 0 OR l_change_in_tare_weight_uom IS NULL ) THEN
6105 -- Child LPN tare weight not defined, no change in tare weight
6106 mdebug('l_wt_vol_new.tare_weight_uom_code'|| l_wt_vol_new.tare_weight_uom_code, G_INFO);
6107 -- 8447369 Added If condition
6108 IF (inv_cache.item_rec.weight_uom_code IS NOT NULL AND NVL(l_wt_vol_new.tare_weight, 0) <> 0 AND l_wt_vol_new.tare_weight_uom_code <> inv_cache.item_rec.weight_uom_code) THEN
6109 l_wt_vol_new.tare_weight := Convert_UOM(
6110 p_inventory_item_id => l_lpn.inventory_item_id
6111 , p_fm_quantity => l_wt_vol_new.tare_weight
6112 , p_fm_uom => l_wt_vol_new.tare_weight_uom_code
6113 , p_to_uom => inv_cache.item_rec.weight_uom_code
6114 , p_mode => G_NO_CONV_RETURN_ZERO );
6115
6116 l_wt_vol_new.tare_weight_uom_code := inv_cache.item_rec.weight_uom_code;
6117 ELSE
6118 l_wt_vol_new.tare_weight := NULL;
6119 l_wt_vol_new.tare_weight_uom_code := NULL;
6120 END IF;
6121 ELSIF ( NVL(l_wt_vol_new.tare_weight, 0) = 0 OR l_wt_vol_new.tare_weight_uom_code IS NULL ) THEN
6122 -- LPN has no tare weight, if packing assign total child LPN tare weight to parent LPN tare
6123 -- if unpacking, no change, since weight cannot go negative
6124 IF ( l_change_in_tare_weight > 0 ) THEN
6125 l_wt_vol_new.tare_weight := l_change_in_tare_weight;
6126 l_wt_vol_new.tare_weight_uom_code := l_change_in_tare_weight_uom;
6127 END IF;
6128 ELSIF ( l_wt_vol_new.tare_weight_uom_code = l_change_in_tare_weight_uom ) THEN
6129 -- Same uom, can simply add the two values
6130 l_wt_vol_new.tare_weight := l_wt_vol_new.tare_weight + l_change_in_tare_weight;
6131 ELSE
6132 -- Both are not null but with different UOMs need to convert
6133 -- If cannot covert uom, ignore the change in volume
6134 l_change_in_tare_weight := Convert_UOM(
6135 p_inventory_item_id => l_lpn.inventory_item_id
6136 , p_fm_quantity => l_change_in_tare_weight
6137 , p_fm_uom => l_change_in_tare_weight_uom
6138 , p_to_uom => l_wt_vol_new.tare_weight_uom_code
6139 , p_mode => G_NO_CONV_RETURN_ZERO );
6140
6141 l_wt_vol_new.tare_weight := l_wt_vol_new.tare_weight + l_change_in_tare_weight;
6142 END IF;
6143
6144 IF ( l_wt_vol_new.tare_weight < 0 ) THEN
6145 l_wt_vol_new.tare_weight := 0;
6146 END IF;
6147
6148 l_progress := 'Calculate changes in volume';
6149
6150 IF ( NVL(l_change_in_volume, 0) = 0 OR l_change_in_volume_uom IS NULL ) THEN
6151 -- Item/LPN volume not defined, no change in LPN volume
6152 l_wt_vol_new.content_volume := NULL;
6153 l_wt_vol_new.content_volume_uom_code := NULL;
6154 ELSIF ( NVL(l_wt_vol_new.content_volume, 0) = 0 OR l_wt_vol_new.content_volume_uom_code IS NULL ) THEN
6155 -- LPN has no content volume, if packing assign total item/LPN volume to gross
6156 -- if unpacking, no change, since volume cannot go negative
6157 IF ( l_change_in_volume > 0 ) THEN
6158 l_wt_vol_new.content_volume := l_change_in_volume;
6159 l_wt_vol_new.content_volume_uom_code := l_change_in_volume_uom;
6160 END IF;
6161 ELSIF ( l_wt_vol_new.content_volume_uom_code = l_change_in_volume_uom ) THEN
6162 -- Same uom, can simply add the two values
6163 l_wt_vol_new.content_volume := l_wt_vol_new.content_volume + l_change_in_volume;
6164 ELSE
6165 -- Both are not null but with different UOMs need to convert
6166 -- If cannot covert uom, ignore the change in volume
6167 l_change_in_volume := Convert_UOM(
6168 p_inventory_item_id => l_lpn.inventory_item_id
6169 , p_fm_quantity => l_change_in_volume
6170 , p_fm_uom => l_change_in_volume_uom
6171 , p_to_uom => l_wt_vol_new.content_volume_uom_code
6172 , p_mode => G_NO_CONV_RETURN_ZERO );
6173
6174 l_wt_vol_new.content_volume := l_wt_vol_new.content_volume + l_change_in_volume;
6175 l_change_in_volume_uom := l_wt_vol_new.content_volume_uom_code;
6176 END IF;
6177
6178 IF ( l_new.content_volume < 0 ) THEN
6179 l_wt_vol_new.content_volume := 0;
6180 END IF;
6181
6182 -- bug5404902 added tare weight
6183 IF ( l_new.lpn_id = l_wt_vol_new.lpn_id ) THEN
6184 l_new.gross_weight := l_wt_vol_new.gross_weight;
6185 l_new.gross_weight_uom_code := l_wt_vol_new.gross_weight_uom_code;
6186 l_new.tare_weight := l_wt_vol_new.tare_weight;
6187 l_new.tare_weight_uom_code := l_wt_vol_new.tare_weight_uom_code;
6188 l_new.content_volume := l_wt_vol_new.content_volume;
6189 l_new.content_volume_uom_code := l_wt_vol_new.content_volume_uom_code;
6190 ELSE -- Not the immediate parent, create a new record
6191 l_tmp_i := NVL(l_lpn_tbl.last, 0) + 1;
6192 l_lpn_tbl(l_tmp_i).lpn_id := l_wt_vol_new.lpn_id;
6193 l_lpn_tbl(l_tmp_i).gross_weight := l_wt_vol_new.gross_weight;
6194 l_lpn_tbl(l_tmp_i).gross_weight_uom_code := l_wt_vol_new.gross_weight_uom_code;
6195 l_lpn_tbl(l_tmp_i).tare_weight := l_wt_vol_new.tare_weight;
6196 l_lpn_tbl(l_tmp_i).tare_weight_uom_code := l_wt_vol_new.tare_weight_uom_code;
6197 l_lpn_tbl(l_tmp_i).content_volume := l_wt_vol_new.content_volume;
6198 l_lpn_tbl(l_tmp_i).content_volume_uom_code := l_wt_vol_new.content_volume_uom_code;
6199 END IF;
6200 END IF;
6201
6202 -- IF both LPNs are picked and doing an unpack, need to update nested LPN structure in WDD
6203 IF ( p_lpn_id IS NOT NULL AND p_content_lpn_id IS NOT NULL AND l_operation_mode = L_UNPACK AND
6204 l_lpn.lpn_context = LPN_CONTEXT_PICKED AND l_content_lpn.lpn_context = LPN_CONTEXT_PICKED )
6205 THEN
6206 IF (l_debug = 1) THEN
6207 mdebug('Call to WSH Delivery_Detail_Action to unpack LPN heirarchy', G_INFO);
6208 END IF;
6209
6210 l_wsh_action_prms.caller := 'WMS';
6211 l_wsh_action_prms.action_code := 'UNPACK';
6212 l_wsh_action_prms.lpn_rec.organization_id := l_lpn.organization_id;
6213 l_wsh_action_prms.lpn_rec.lpn_id := l_lpn.lpn_id;
6214 l_wsh_action_prms.lpn_rec.container_name := l_lpn.license_plate_number;
6215 l_wsh_lpn_id_tbl(1) := p_content_lpn_id;
6216
6217 WSH_WMS_LPN_GRP.Delivery_Detail_Action (
6218 p_api_version_number => 1.0
6219 , p_init_msg_list => fnd_api.g_false
6220 , p_commit => fnd_api.g_false
6221 , x_return_status => x_return_status
6222 , x_msg_count => x_msg_count
6223 , x_msg_data => x_msg_data
6224 , p_lpn_id_tbl => l_wsh_lpn_id_tbl
6225 , p_del_det_id_tbl => l_wsh_del_det_id_tbl
6226 , p_action_prms => l_wsh_action_prms
6227 , x_defaults => l_wsh_defaults
6228 , x_action_out_rec => l_wsh_action_out_rec );
6229
6230 IF (x_return_status <> fnd_api.g_ret_sts_success) THEN
6231 l_progress := 'Delivery_Detail_Action failed';
6232 RAISE fnd_api.g_exc_error;
6233 ELSIF (l_debug = 1) THEN
6234 mdebug('Done with call to WSH Create_Update_Containers', G_INFO);
6235 END IF;
6236 END IF;
6237
6238 -- If there were any changes made to the parent LPN, add this to the lpn table
6239 -- to have WLPN be updated by modify_lpns
6240 IF ( l_new.lpn_id IS NOT NULL ) THEN
6241 l_lpn_tbl(NVL(l_lpn_tbl.last, 0) + 1) := l_new;
6242 END IF;
6243
6244 -- If there were any changes made to the content LPN, add this to the lpn table
6245 -- to have WLPN be updated by modify_lpns
6246 IF ( l_cont_new.lpn_id IS NOT NULL ) THEN
6247 l_lpn_tbl(NVL(l_lpn_tbl.last, 0) + 1) := l_cont_new;
6248 END IF;
6249
6250 -- Call Modify_LPNs API to update WLPN
6251 IF ( l_lpn_tbl.last > 0 ) THEN
6252 IF (l_debug = 1) THEN
6253 mdebug('Call to Modify_LPNs first='||l_lpn_tbl.first||' last='||l_lpn_tbl.last, G_INFO);
6254 END IF;
6255
6256 Modify_LPNs (
6257 p_api_version => 1.0
6258 , p_init_msg_list => fnd_api.g_false
6259 , p_commit => fnd_api.g_false
6260 , x_return_status => x_return_status
6261 , x_msg_count => x_msg_count
6262 , x_msg_data => x_msg_data
6263 , p_caller => 'WMS_PackUnpack_Container'
6264 , p_lpn_table => l_lpn_tbl );
6265
6266 IF (x_return_status <> fnd_api.g_ret_sts_success) THEN
6267 l_progress := 'Modify_LPNs failed';
6268 RAISE fnd_api.g_exc_error;
6269 END IF;
6270 END IF;
6271
6272 -- IF both LPNs are picked then need to update nested LPN structure
6273 IF ( p_lpn_id IS NOT NULL AND p_content_lpn_id IS NOT NULL AND l_operation_mode = L_PACK AND
6274 NVL(l_new.lpn_context, l_lpn.lpn_context) = LPN_CONTEXT_PICKED AND
6275 NVL(l_cont_new.lpn_context, l_content_lpn.lpn_context) = LPN_CONTEXT_PICKED )
6276 THEN
6277 IF (l_debug = 1) THEN
6278 mdebug('Call to WSH Delivery_Detail_Action to pack LPN heirarchy', G_INFO);
6279 END IF;
6280
6281 l_wsh_action_prms.caller := 'WMS';
6282 l_wsh_action_prms.action_code := 'PACK';
6283 l_wsh_action_prms.lpn_rec.organization_id := l_lpn.organization_id;
6284 l_wsh_action_prms.lpn_rec.lpn_id := l_lpn.lpn_id;
6285 l_wsh_action_prms.lpn_rec.container_name := l_lpn.license_plate_number;
6286 l_wsh_lpn_id_tbl(1) := p_content_lpn_id;
6287
6288 WSH_WMS_LPN_GRP.Delivery_Detail_Action (
6289 p_api_version_number => 1.0
6290 , p_init_msg_list => fnd_api.g_false
6291 , p_commit => fnd_api.g_false
6292 , x_return_status => x_return_status
6293 , x_msg_count => x_msg_count
6294 , x_msg_data => x_msg_data
6295 , p_lpn_id_tbl => l_wsh_lpn_id_tbl
6296 , p_del_det_id_tbl => l_wsh_del_det_id_tbl
6297 , p_action_prms => l_wsh_action_prms
6298 , x_defaults => l_wsh_defaults
6299 , x_action_out_rec => l_wsh_action_out_rec );
6300
6301 IF (x_return_status <> fnd_api.g_ret_sts_success) THEN
6302 l_progress := 'Delivery_Detail_Action failed';
6303 RAISE fnd_api.g_exc_error;
6304 ELSIF (l_debug = 1) THEN
6305 mdebug('Done with call to WSH Create_Update_Containers', G_INFO);
6306 END IF;
6307 END IF;
6308
6309 l_progress := 'Inserting record into WLH';
6310 INSERT INTO wms_lpn_histories (
6311 lpn_history_id
6312 , caller
6313 , source_transaction_id
6314 , parent_lpn_id
6315 , parent_license_plate_number
6316 , lpn_id
6317 , license_plate_number
6318 , inventory_item_id
6319 , item_description
6320 , revision
6321 , lot_number
6322 , serial_number
6323 , to_serial_number
6324 , quantity
6325 , uom_code
6326 , organization_id
6327 , subinventory_code
6328 , locator_id
6329 , lpn_context
6330 , status_id
6331 , sealed_status
6332 , operation_mode
6333 , last_update_date
6334 , last_updated_by
6335 , creation_date
6336 , created_by
6337 , cost_group_id
6338 , outermost_lpn_id
6339 , source_type_id
6340 , source_header_id
6341 , source_line_id
6342 , source_line_detail_id
6343 , source_name
6344 , secondary_quantity
6345 , secondary_uom_code
6346 )
6347 VALUES (
6348 WMS_LPN_HISTORIES_S.NEXTVAL
6349 , p_caller
6350 , p_source_transaction_id
6351 , p_lpn_id
6352 , l_lpn.license_plate_number
6353 , p_content_lpn_id
6354 , l_content_lpn.license_plate_number
6355 , p_content_item_id
6356 , p_content_item_desc
6357 , p_revision
6358 , p_lot_number
6359 , p_from_serial_number
6360 , p_to_serial_number
6361 , l_quantity
6362 , p_uom
6363 , p_organization_id
6364 , p_subinventory
6365 , p_locator_id
6366 , NVL(l_new.lpn_context, l_lpn.lpn_context)
6367 , l_lpn.status_id
6368 , l_lpn.sealed_status
6369 , l_operation_mode
6370 , SYSDATE
6371 , fnd_global.user_id
6372 , SYSDATE
6373 , fnd_global.user_id
6374 , p_cost_group_id
6375 , DECODE(l_new.outermost_lpn_id, fnd_api.g_miss_num, NULL, NVL(l_new.outermost_lpn_id, l_lpn.outermost_lpn_id))
6376 , NVL(p_source_type_id, l_lpn.source_type_id)
6377 , NVL(p_source_header_id, l_lpn.source_header_id)
6378 , NVL(p_source_line_id, l_lpn.source_line_id)
6379 , NVL(p_source_line_detail_id, l_lpn.source_line_detail_id)
6380 , NVL(p_source_name, l_lpn.source_name)
6381 , p_sec_quantity --INVCONV kkillams
6382 , p_sec_uom --INVCONV kkillams
6383 );
6384
6385 -- Standard check of p_commit.
6386 IF fnd_api.to_boolean(p_commit) THEN
6387 COMMIT WORK;
6388 END IF;
6389
6390 IF ( l_debug = 1 ) THEN
6391 mdebug(l_api_name||' Exited', 1);
6392 END IF;
6393
6394 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
6395 EXCEPTION
6396 WHEN FND_API.G_EXC_ERROR THEN
6397 ROLLBACK TO PACKUNPACK_CONTAINER;
6398 x_return_status := fnd_api.g_ret_sts_error;
6399 FND_MSG_PUB.Count_And_Get(p_count => x_msg_count, p_data => x_msg_data);
6400
6401 IF (l_debug = 1) THEN
6402 mdebug(l_api_name ||' Exc err prog='||l_progress||' SQL err: '|| SQLERRM(SQLCODE), 1);
6403 FOR i in 1..x_msg_count LOOP
6404 l_msgdata := substr(l_msgdata||' | '||substr(fnd_msg_pub.get(x_msg_count-i+1, 'F'), 0, 200),1,2000);
6405 END LOOP;
6406 mdebug('msg: '||l_msgdata, 1);
6407 END IF;
6408 WHEN OTHERS THEN
6409 ROLLBACK TO PACKUNPACK_CONTAINER;
6410 x_return_status := fnd_api.g_ret_sts_unexp_error;
6411 FND_MSG_PUB.Count_And_Get(p_count => x_msg_count, p_data => x_msg_data);
6412 IF (l_debug = 1) THEN
6413 mdebug(l_api_name ||' Unexp err prog='||l_progress||' SQL err: '|| SQLERRM(SQLCODE), 1);
6414 END IF;
6415 END PackUnpack_Container;
6416
6417 -- ----------------------------------------------------------------------------------
6418 -- ----------------------------------------------------------------------------------
6419
6420 PROCEDURE Modify_LPN (
6421 p_api_version IN NUMBER
6422 , p_init_msg_list IN VARCHAR2 := fnd_api.g_false
6423 , p_commit IN VARCHAR2 := fnd_api.g_false
6424 , p_validation_level IN NUMBER := fnd_api.g_valid_level_full
6425 , x_return_status OUT NOCOPY VARCHAR2
6426 , x_msg_count OUT NOCOPY NUMBER
6427 , x_msg_data OUT NOCOPY VARCHAR2
6428 , p_lpn IN WMS_CONTAINER_PUB.LPN
6429 , p_caller IN VARCHAR2 := NULL
6430 ) IS
6431 l_api_name CONSTANT VARCHAR2(30) := 'Modify_LPN';
6432 l_api_version CONSTANT NUMBER := 1.0;
6433
6434 l_lpn_table WMS_Data_Type_Definitions_PUB.LPNTableType;
6435
6436 BEGIN
6437
6438 l_lpn_table(1).lpn_id := p_lpn.lpn_id;
6439 l_lpn_table(1).license_plate_number := p_lpn.license_plate_number;
6440 l_lpn_table(1).parent_lpn_id := p_lpn.parent_lpn_id;
6441 l_lpn_table(1).outermost_lpn_id := p_lpn.outermost_lpn_id;
6442 l_lpn_table(1).lpn_context := p_lpn.lpn_context;
6443
6444 l_lpn_table(1).organization_id := p_lpn.organization_id;
6445 l_lpn_table(1).subinventory_code := p_lpn.subinventory_code;
6446 l_lpn_table(1).locator_id := p_lpn.locator_id;
6447
6448 l_lpn_table(1).inventory_item_id := p_lpn.inventory_item_id;
6449 l_lpn_table(1).revision := p_lpn.revision;
6450 l_lpn_table(1).lot_number := p_lpn.lot_number;
6451 l_lpn_table(1).serial_number := p_lpn.serial_number;
6452 l_lpn_table(1).cost_group_id := p_lpn.cost_group_id;
6453
6454 l_lpn_table(1).tare_weight_uom_code := p_lpn.tare_weight_uom_code;
6455 l_lpn_table(1).tare_weight := p_lpn.tare_weight;
6456 l_lpn_table(1).gross_weight_uom_code := p_lpn.gross_weight_uom_code;
6457 l_lpn_table(1).gross_weight := p_lpn.gross_weight;
6458 l_lpn_table(1).container_volume_uom := p_lpn.container_volume_uom;
6459 l_lpn_table(1).container_volume := p_lpn.container_volume;
6460 l_lpn_table(1).content_volume_uom_code := p_lpn.content_volume_uom_code;
6461 l_lpn_table(1).content_volume := p_lpn.content_volume;
6462
6463 l_lpn_table(1).source_type_id := p_lpn.source_type_id;
6464 l_lpn_table(1).source_header_id := p_lpn.source_header_id;
6465 l_lpn_table(1).source_line_id := p_lpn.source_line_id;
6466 l_lpn_table(1).source_line_detail_id := p_lpn.source_line_detail_id;
6467 l_lpn_table(1).source_name := p_lpn.source_name;
6468
6469 l_lpn_table(1).attribute_category := p_lpn.attribute_category;
6470 l_lpn_table(1).attribute1 := p_lpn.attribute1;
6471 l_lpn_table(1).attribute2 := p_lpn.attribute2;
6472 l_lpn_table(1).attribute3 := p_lpn.attribute3;
6473 l_lpn_table(1).attribute4 := p_lpn.attribute4;
6474 l_lpn_table(1).attribute5 := p_lpn.attribute5;
6475 l_lpn_table(1).attribute6 := p_lpn.attribute6;
6476 l_lpn_table(1).attribute7 := p_lpn.attribute7;
6477 l_lpn_table(1).attribute8 := p_lpn.attribute8;
6478 l_lpn_table(1).attribute9 := p_lpn.attribute9;
6479 l_lpn_table(1).attribute10 := p_lpn.attribute10;
6480 l_lpn_table(1).attribute11 := p_lpn.attribute11;
6481 l_lpn_table(1).attribute12 := p_lpn.attribute12;
6482 l_lpn_table(1).attribute13 := p_lpn.attribute13;
6483 l_lpn_table(1).attribute14 := p_lpn.attribute14;
6484 l_lpn_table(1).attribute15 := p_lpn.attribute15;
6485
6486 Modify_LPNs (
6487 p_api_version => p_api_version
6488 , p_init_msg_list => p_init_msg_list
6489 , p_commit => p_commit
6490 , x_return_status => x_return_status
6491 , x_msg_count => x_msg_count
6492 , x_msg_data => x_msg_data
6493 , p_caller => p_caller
6494 , p_lpn_table => l_lpn_table );
6495
6496 END Modify_LPN;
6497
6498 -- ----------------------------------------------------------------------------------
6499 -- ----------------------------------------------------------------------------------
6500
6501 PROCEDURE Modify_LPN_Wrapper(
6502 p_api_version IN NUMBER
6503 , p_init_msg_list IN VARCHAR2 := fnd_api.g_false
6504 , p_commit IN VARCHAR2 := fnd_api.g_false
6505 , p_validation_level IN NUMBER := fnd_api.g_valid_level_full
6506 , x_return_status OUT NOCOPY VARCHAR2
6507 , x_msg_count OUT NOCOPY NUMBER
6508 , x_msg_data OUT NOCOPY VARCHAR2
6509 , p_lpn_id IN NUMBER
6510 , p_license_plate_number IN VARCHAR2 := NULL
6511 , p_inventory_item_id IN NUMBER := NULL
6512 , p_weight_uom_code IN VARCHAR2 := NULL
6513 , p_gross_weight IN NUMBER := NULL
6514 , p_volume_uom_code IN VARCHAR2 := NULL
6515 , p_content_volume IN NUMBER := NULL
6516 , p_status_id IN NUMBER := NULL
6517 , p_lpn_context IN NUMBER := NULL
6518 , p_sealed_status IN NUMBER := NULL
6519 , p_organization_id IN NUMBER := NULL
6520 , p_subinventory IN VARCHAR := NULL
6521 , p_locator_id IN NUMBER := NULL
6522 , p_source_type_id IN NUMBER := NULL
6523 , p_source_header_id IN NUMBER := NULL
6524 , p_source_name IN VARCHAR2 := NULL
6525 , p_source_line_id IN NUMBER := NULL
6526 , p_source_line_detail_id IN NUMBER := NULL
6527 , p_caller IN VARCHAR2 := NULL
6528 ) IS
6529 l_api_name CONSTANT VARCHAR2(30) := 'Modify_LPN_Wrapper';
6530 l_api_version CONSTANT NUMBER := 1.0;
6531 l_debug NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
6532 l_progress VARCHAR2(10) := '0';
6533 l_msgdata VARCHAR2(1000);
6534
6535 l_lpn WMS_Data_Type_Definitions_PUB.LPNTableType;
6536
6537 BEGIN
6538 -- Standard Start of API savepoint
6539 SAVEPOINT MODIFY_LPN_WRAPPER_PVT;
6540
6541 -- Standard call to check for call compatibility.
6542 IF NOT fnd_api.compatible_api_call(l_api_version, p_api_version, l_api_name, g_pkg_name) THEN
6543 fnd_message.set_name('WMS', 'WMS_CONT_INCOMPATIBLE_API_CALL');
6544 fnd_msg_pub.ADD;
6545 RAISE fnd_api.g_exc_unexpected_error;
6546 END IF;
6547
6548 -- Initialize message list if p_init_msg_list is set to TRUE.
6549 IF fnd_api.to_boolean(p_init_msg_list) THEN
6550 fnd_msg_pub.initialize;
6551 END IF;
6552
6553 -- Initialize API return status to success
6554 x_return_status := fnd_api.g_ret_sts_success;
6555
6556 IF (l_debug = 1) THEN
6557 mdebug(l_api_name|| ' Entered '|| g_pkg_version, 1);
6558 END IF;
6559
6560 l_lpn(1).lpn_id := p_lpn_id;
6561 l_lpn(1).license_plate_number := p_license_plate_number;
6562 l_lpn(1).inventory_item_id := p_inventory_item_id;
6563 l_lpn(1).gross_weight_uom_code := p_weight_uom_code;
6564 l_lpn(1).gross_weight := p_gross_weight;
6565 l_lpn(1).content_volume_uom_code := p_volume_uom_code;
6566 l_lpn(1).content_volume := p_content_volume;
6567 --l_lpn(1).status_id := p_status_id;
6568 l_lpn(1).lpn_context := p_lpn_context;
6569 --l_lpn(1).sealed_status := p_sealed_status;
6570 l_lpn(1).organization_id := p_organization_id;
6571 l_lpn(1).subinventory_code := p_subinventory;
6572 l_lpn(1).locator_id := p_locator_id;
6573 l_lpn(1).source_type_id := p_source_type_id;
6574 l_lpn(1).source_header_id := p_source_header_id;
6575 l_lpn(1).source_line_id := p_source_line_id;
6576 l_lpn(1).source_line_detail_id := p_source_line_detail_id;
6577 l_lpn(1).source_name := p_source_name;
6578
6579 l_progress := '100';
6580 Modify_LPNs (
6581 p_api_version => p_api_version
6582 , p_init_msg_list => p_init_msg_list
6583 , p_commit => p_commit
6584 , x_return_status => x_return_status
6585 , x_msg_count => x_msg_count
6586 , x_msg_data => x_msg_data
6587 , p_caller => p_caller
6588 , p_lpn_table => l_lpn );
6589
6590 l_progress := '200';
6591 IF (x_return_status <> fnd_api.g_ret_sts_success) THEN
6592 -- Modify LPN should put the appropriate error message in the stack
6593 RAISE fnd_api.g_exc_error;
6594 END IF;
6595
6596 -- Standard check of p_commit.
6597 IF fnd_api.to_boolean(p_commit) THEN
6598 COMMIT WORK;
6599 END IF;
6600
6601 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
6602 EXCEPTION
6603 WHEN fnd_api.g_exc_error THEN
6604 ROLLBACK TO MODIFY_LPN_WRAPPER_PVT;
6605 x_return_status := fnd_api.g_ret_sts_error;
6606 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
6607 WHEN OTHERS THEN
6608 ROLLBACK TO MODIFY_LPN_WRAPPER_PVT;
6609 x_return_status := fnd_api.g_ret_sts_unexp_error;
6610
6611 IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error) THEN
6612 fnd_msg_pub.add_exc_msg(g_pkg_name, l_api_name);
6613 END IF;
6614
6615 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
6616 IF (l_debug = 1) THEN
6617 mdebug(l_api_name ||' Error progress= '||l_progress||'SQL error: '|| SQLERRM(SQLCODE), G_ERROR);
6618 END IF;
6619 END Modify_LPN_Wrapper;
6620
6621 -- ----------------------------------------------------------------------------------
6622 -- ----------------------------------------------------------------------------------
6623
6624 PROCEDURE Validate_Update_Wt_Volume (
6625 p_api_version IN NUMBER
6626 , p_init_msg_list IN VARCHAR2 := fnd_api.g_false
6627 , p_commit IN VARCHAR2 := fnd_api.g_false
6628 , x_return_status OUT NOCOPY VARCHAR2
6629 , x_msg_count OUT NOCOPY NUMBER
6630 , x_msg_data OUT NOCOPY VARCHAR2
6631 , p_lpn_id IN NUMBER
6632 , p_content_lpn_id IN VARCHAR2 := NULL
6633 , p_content_item_id IN NUMBER := NULL
6634 , p_quantity IN NUMBER := NULL
6635 , p_uom IN VARCHAR2 := NULL
6636 , p_organization_id IN NUMBER := NULL
6637 , p_enforce_wv_constraints IN NUMBER := 2
6638 , p_operation IN NUMBER
6639 , p_action IN NUMBER
6640 , x_valid_operation OUT NOCOPY NUMBER
6641 ) IS
6642 l_api_name CONSTANT VARCHAR2(30) := 'Validate_Update_Wt_Volume';
6643 l_api_version CONSTANT NUMBER := 1.0;
6644 l_debug NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
6645 l_progress VARCHAR2(10) := '0';
6646
6647 BEGIN
6648 -- Initialize API return status to success
6649 x_return_status := FND_API.G_RET_STS_SUCCESS;
6650
6651 END Validate_Update_Wt_Volume;
6652
6653 -- ----------------------------------------------------------------------------------
6654 -- ----------------------------------------------------------------------------------
6655
6656 PROCEDURE Container_Required_Qty(
6657 p_api_version IN NUMBER
6658 , p_init_msg_list IN VARCHAR2 := fnd_api.g_false
6659 , p_commit IN VARCHAR2 := fnd_api.g_false
6660 , x_return_status OUT NOCOPY VARCHAR2
6661 , x_msg_count OUT NOCOPY NUMBER
6662 , x_msg_data OUT NOCOPY VARCHAR2
6663 , p_source_item_id IN NUMBER
6664 , p_source_qty IN NUMBER
6665 , p_source_qty_uom IN VARCHAR2
6666 , p_qty_per_cont IN NUMBER := NULL
6667 , p_qty_per_cont_uom IN VARCHAR2 := NULL
6668 , p_organization_id IN NUMBER
6669 , p_dest_cont_item_id IN OUT NOCOPY NUMBER
6670 , p_qty_required OUT NOCOPY NUMBER
6671 ) IS
6672 l_api_name CONSTANT VARCHAR2(30) := 'Container_Required_Qty';
6673 l_api_version CONSTANT NUMBER := 1.0;
6674 l_source_item INV_Validate.ITEM;
6675 l_dest_cont_item INV_Validate.ITEM;
6676 l_cont_item INV_Validate.ITEM;
6677 l_org INV_Validate.ORG;
6678 l_result NUMBER;
6679 l_max_load_quantity NUMBER;
6680 l_qty_per_cont NUMBER;
6681 l_curr_min_container NUMBER;
6682 l_curr_min_value NUMBER;
6683 l_curr_load_quantity NUMBER;
6684 l_temp_min_value NUMBER;
6685 l_temp_value NUMBER;
6686 l_temp_load_quantity NUMBER;
6687 CURSOR max_load_cursor IS
6688 SELECT max_load_quantity
6689 FROM WSH_CONTAINER_ITEMS
6690 WHERE master_organization_id = p_organization_id
6691 AND container_item_id = p_dest_cont_item_id
6692 AND load_item_id = p_source_item_id;
6693
6694 CURSOR container_items_cursor IS
6695 SELECT container_item_id, max_load_quantity, preferred_flag
6696 FROM WSH_CONTAINER_ITEMS
6697 WHERE master_organization_id = p_organization_id
6698 AND load_item_id = p_source_item_id
6699 AND container_item_id IN
6700 (SELECT inventory_item_id
6701 FROM MTL_SYSTEM_ITEMS
6702 WHERE mtl_transactions_enabled_flag = 'Y'
6703 AND container_item_flag = 'Y'
6704 AND organization_id = p_organization_id);
6705
6706 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
6707 BEGIN
6708 -- Standard Start of API savepoint
6709 SAVEPOINT CONTAINER_REQUIRED_QTY_PVT;
6710 -- Standard call to check for call compatibility.
6711 IF NOT FND_API.Compatible_API_Call ( l_api_version ,
6712 p_api_version ,
6713 l_api_name ,
6714 G_PKG_NAME )
6715 THEN
6716 FND_MESSAGE.SET_NAME('WMS', 'WMS_CONT_INCOMPATIBLE_API_CALL');
6717 FND_MSG_PUB.ADD;
6718 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6719 END IF;
6720 -- Initialize message list if p_init_msg_list is set to TRUE.
6721 IF FND_API.to_Boolean( p_init_msg_list ) THEN
6722 FND_MSG_PUB.initialize;
6723 END IF;
6724 -- Initialize API return status to success
6725 x_return_status := FND_API.G_RET_STS_SUCCESS;
6726
6727 -- API body
6728
6729 /* Validate Organization ID */
6730 l_org.organization_id := p_organization_id;
6731 l_result := INV_Validate.Organization(l_org);
6732 IF (l_result = INV_Validate.F) THEN
6733 FND_MESSAGE.SET_NAME('WMS', 'WMS_CONT_INVALID_ORG');
6734 FND_MSG_PUB.ADD;
6735 RAISE FND_API.G_EXC_ERROR;
6736 END IF;
6737
6738 /* Validate Source item */
6739 l_source_item.inventory_item_id := p_source_item_id;
6740 l_result := INV_Validate.inventory_item(l_source_item, l_org);
6741 IF (l_result = INV_Validate.F) THEN
6742 FND_MESSAGE.SET_NAME('WMS', 'WMS_CONT_INVALID_ITEM');
6743 FND_MSG_PUB.ADD;
6744 RAISE FND_API.G_EXC_ERROR;
6745 END IF;
6746
6747 /* Validate Source Quantity */
6748 IF ((p_source_qty IS NULL) OR (p_source_qty <= 0)) THEN
6749 FND_MESSAGE.SET_NAME('WMS', 'WMS_CONT_INVALID_SRC_QTY');
6750 FND_MSG_PUB.ADD;
6751 RAISE FND_API.G_EXC_ERROR;
6752 END IF;
6753
6754 /* Validate Source UOM */
6755 l_result := INV_Validate.Uom(p_source_qty_uom, l_org, l_source_item);
6756 IF (l_result = INV_Validate.F) THEN
6757 FND_MESSAGE.SET_NAME('WMS', 'WMS_CONT_INVALID_SRC_UOM');
6758 FND_MSG_PUB.ADD;
6759 RAISE FND_API.G_EXC_ERROR;
6760 END IF;
6761
6762 /* Validate Quantity Per Container */
6763 IF (p_qty_per_cont IS NOT NULL) THEN
6764 IF (p_qty_per_cont <= 0) THEN
6765 FND_MESSAGE.SET_NAME('WMS', 'WMS_CONT_INVLD_QTY_PER_CONT');
6766 FND_MSG_PUB.ADD;
6767 RAISE FND_API.G_EXC_ERROR;
6768 END IF;
6769 END IF;
6770
6771 /* Validate Quantity Per Container UOM */
6772 IF (p_qty_per_cont IS NOT NULL) THEN
6773 l_result := INV_Validate.Uom(p_qty_per_cont_uom, l_org, l_source_item);
6774 IF (l_result = INV_Validate.F) THEN
6775 FND_MESSAGE.SET_NAME('WMS', 'WMS_CONT_INVLD_QTY_PER_UOM');
6776 FND_MSG_PUB.ADD;
6777 RAISE FND_API.G_EXC_ERROR;
6778 END IF;
6779 END IF;
6780
6781 /* Validate Destination container item */
6782 IF (p_dest_cont_item_id IS NOT NULL) THEN
6783 l_dest_cont_item.inventory_item_id := p_dest_cont_item_id;
6784 l_result := INV_Validate.inventory_item(l_dest_cont_item, l_org);
6785 IF (l_result = INV_Validate.F) THEN
6786 FND_MESSAGE.SET_NAME('WMS', 'WMS_CONT_INVALID_CONT_ITEM');
6787 FND_MSG_PUB.ADD;
6788 RAISE FND_API.G_EXC_ERROR;
6789 ELSIF (l_dest_cont_item.container_item_flag = 'N') THEN
6790 FND_MESSAGE.SET_NAME('WMS', 'WMS_CONT_ITEM_NOT_A_CONT');
6791 FND_MSG_PUB.ADD;
6792 RAISE FND_API.G_EXC_ERROR;
6793 END IF;
6794 END IF;
6795 /* End of input validation */
6796
6797 IF (p_dest_cont_item_id IS NOT NULL) THEN
6798 /* Extract or calculate the value of l_max_load_quantity */
6799 OPEN max_load_cursor;
6800 FETCH max_load_cursor INTO l_max_load_quantity;
6801 IF max_load_cursor%NOTFOUND THEN
6802 /* Need to calculate this value based on weight and volume constraints */
6803 -- Check that the source item contains all the physical item information
6804 -- needed for calculation of l_max_load_quantity
6805 IF ((l_source_item.unit_weight IS NULL) OR
6806 (l_source_item.weight_uom_code IS NULL) OR
6807 (l_source_item.unit_volume IS NULL) OR
6808 (l_source_item.volume_uom_code IS NULL)) THEN
6809 FND_MESSAGE.SET_NAME('WMS', 'WMS_CONT_NOT_ENOUGH_INFO');
6810 FND_MSG_PUB.ADD;
6811 RAISE FND_API.G_EXC_ERROR;
6812 END IF;
6813
6814 /* Volume constraint */
6815 l_temp_value := Convert_UOM(
6816 l_source_item.inventory_item_id
6817 , l_source_item.unit_volume
6818 , l_source_item.volume_uom_code
6819 , l_dest_cont_item.volume_uom_code);
6820
6821 IF (l_dest_cont_item.internal_volume IS NOT NULL) THEN
6822 -- Check that the source item's unit volume is less than or
6823 -- equal to the destination container item's internal volume
6824 IF (l_temp_value <= l_dest_cont_item.internal_volume) THEN
6825 l_max_load_quantity := FLOOR(l_dest_cont_item.internal_volume/l_temp_value);
6826 ELSE
6827 FND_MESSAGE.SET_NAME('WMS', 'WMS_CONT_ITEM_TOO_LARGE');
6828 FND_MSG_PUB.ADD;
6829 RAISE FND_API.G_EXC_ERROR;
6830 END IF;
6831 END IF;
6832 /* Weight constraint */
6833 l_temp_value := Convert_UOM(
6834 l_source_item.inventory_item_id
6835 , l_source_item.unit_weight
6836 , l_source_item.weight_uom_code
6837 , l_dest_cont_item.weight_uom_code);
6838
6839 /* Select the most constraining value for l_max_load_quantity */
6840 IF (l_dest_cont_item.maximum_load_weight IS NOT NULL) THEN
6841 -- Check that the source item's unit weight is less than or
6842 -- equal to the destination container item's maximum load weight
6843 IF (l_temp_value <= l_dest_cont_item.maximum_load_weight) THEN
6844 IF (l_max_load_quantity > FLOOR (l_dest_cont_item.maximum_load_weight /
6845 l_temp_value)) THEN
6846 l_max_load_quantity := FLOOR (l_dest_cont_item.maximum_load_weight /
6847 l_temp_value);
6848 END IF;
6849 ELSE
6850 FND_MESSAGE.SET_NAME('WMS', 'WMS_CONT_ITEM_TOO_LARGE');
6851 FND_MSG_PUB.ADD;
6852 RAISE FND_API.G_EXC_ERROR;
6853 END IF;
6854 END IF;
6855 END IF;
6856 CLOSE max_load_cursor;
6857
6858 /* Convert l_max_load_quantity into the same UOM as p_source_qty_uom */
6859 IF (l_max_load_quantity IS NOT NULL) THEN
6860 l_max_load_quantity := Convert_UOM(
6861 l_source_item.inventory_item_id
6862 , l_max_load_quantity
6863 , l_source_item.primary_uom_code
6864 , p_source_qty_uom);
6865 END IF;
6866
6867 /* Calculate the required number of containers needed to store the items */
6868 IF ((p_qty_per_cont IS NOT NULL) AND (l_max_load_quantity IS NOT NULL)) THEN
6869 l_qty_per_cont := Convert_UOM(
6870 l_source_item.inventory_item_id
6871 , p_qty_per_cont
6872 , p_qty_per_cont_uom
6873 , p_source_qty_uom);
6874
6875 IF (l_qty_per_cont > l_max_load_quantity) THEN
6876 FND_MESSAGE.SET_NAME('WMS', 'WMS_CONT_OVERPACKED_OPERATION');
6877 FND_MSG_PUB.ADD;
6878 RAISE FND_API.G_EXC_ERROR;
6879 ELSE
6880 p_qty_required := CEIL(p_source_qty/l_qty_per_cont);
6881 END IF;
6882 ELSIF ((p_qty_per_cont IS NULL) AND (l_max_load_quantity IS NOT NULL)) THEN
6883 p_qty_required := CEIL(p_source_qty/l_max_load_quantity);
6884 ELSE
6885 -- If the destination container item contains no internal volume or maximum
6886 -- load weight restriction values, assume that it has infinite capacity
6887 FND_MESSAGE.SET_NAME('WMS', 'WMS_CONT_NO_RESTRICTIONS_FND');
6888 -- FND_MESSAGE.SHOW;
6889 p_qty_required := 1;
6890 END IF;
6891
6892 ELSE /* No container item was given */
6893 l_curr_min_container := 0;
6894 -- Search through all the containers in WSH_CONTAINER_ITEMS table which can store
6895 -- the given load_item_id
6896 FOR v_container_item IN container_items_cursor LOOP
6897 /* Get the item information for the current container item being considered */
6898 l_cont_item.inventory_item_id := v_container_item.container_item_id;
6899 l_result := INV_Validate.inventory_item(l_cont_item, l_org);
6900 IF (l_result = INV_Validate.F) THEN
6901 FND_MESSAGE.SET_NAME('WMS', 'WMS_CONT_INVALID_CONT_ITEM');
6902 FND_MSG_PUB.ADD;
6903 RAISE FND_API.G_EXC_ERROR;
6904 END IF;
6905
6906 /* Get the max load quantity for that given container */
6907 l_temp_load_quantity := Convert_UOM (
6908 l_source_item.inventory_item_id
6909 , v_container_item.max_load_quantity
6910 , l_source_item.primary_uom_code
6911 , p_source_qty_uom);
6912
6913 -- Calculate the min value, i.e. how much space is empty in the final container
6914 -- used to store the items in units of the source item's uom
6915 l_temp_min_value := l_temp_load_quantity - MOD(p_source_qty, l_temp_load_quantity);
6916
6917 -- If ther preferred container flag is set for this container load relationship
6918 -- Use it reguardless of it's min value
6919 IF ( v_container_item.preferred_flag = 'Y' ) THEN
6920 l_curr_min_container := v_container_item.container_item_id;
6921 l_curr_load_quantity := l_temp_load_quantity;
6922 EXIT;
6923 -- Compare the min value for this container with the best one found so far
6924 ELSIF ((l_curr_min_container = 0) OR (l_temp_min_value < l_curr_min_value)) THEN
6925 l_curr_min_value := l_temp_min_value;
6926 l_curr_min_container := v_container_item.container_item_id;
6927 l_curr_load_quantity := l_temp_load_quantity;
6928 -- If the min values are the same, then choose the container which can hold
6929 -- more of the source item, i.e. has a higher load quantity
6930 ELSIF (l_temp_min_value = l_curr_min_value) THEN
6931 IF (l_temp_load_quantity > l_curr_load_quantity) THEN
6932 l_curr_min_value := l_temp_min_value;
6933 l_curr_min_container := v_container_item.container_item_id;
6934 l_curr_load_quantity := l_temp_load_quantity;
6935 END IF;
6936 END IF;
6937 END LOOP;
6938 /* No containers were found that can store the source item */
6939 IF (l_curr_min_container = 0) THEN
6940 p_qty_required := 0;
6941 FND_MESSAGE.SET_NAME('WMS', 'WMS_CONT_NO_CONTAINER_FOUND');
6942 FND_MSG_PUB.ADD;
6943 RAISE FND_API.G_EXC_ERROR;
6944 ELSE
6945 /* Valid container found. Store this information in the output parameters */
6946 p_dest_cont_item_id := l_curr_min_container;
6947 p_qty_required := CEIL(p_source_qty / l_curr_load_quantity);
6948 END IF;
6949 END IF;
6950 -- End of API body
6951
6952 -- Standard check of p_commit.
6953 IF FND_API.To_Boolean( p_commit ) THEN
6954 COMMIT WORK;
6955 END IF;
6956 -- Standard call to get message count and if count is 1,
6957 -- get message info.
6958 FND_MSG_PUB.Count_And_Get
6959 ( p_count => x_msg_count,
6960 p_data => x_msg_data
6961 );
6962 EXCEPTION
6963 WHEN FND_API.G_EXC_ERROR THEN
6964 ROLLBACK TO CONTAINER_REQUIRED_QTY_PVT;
6965 x_return_status := FND_API.G_RET_STS_ERROR;
6966 FND_MSG_PUB.Count_And_Get
6967 ( p_count => x_msg_count,
6968 p_data => x_msg_data
6969 );
6970 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
6971 ROLLBACK TO CONTAINER_REQUIRED_QTY_PVT;
6972 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6973 FND_MSG_PUB.Count_And_Get
6974 ( p_count => x_msg_count,
6975 p_data => x_msg_data
6976 );
6977 WHEN OTHERS THEN
6978 ROLLBACK TO CONTAINER_REQUIRED_QTY_PVT;
6979 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6980 IF FND_MSG_PUB.Check_Msg_Level
6981 (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
6982 THEN
6983 FND_MSG_PUB.Add_Exc_Msg
6984 ( G_PKG_NAME ,
6985 l_api_name
6986 );
6987 END IF;
6988 FND_MSG_PUB.Count_And_Get
6989 ( p_count => x_msg_count,
6990 p_data => x_msg_data
6991 );
6992 END Container_Required_Qty;
6993
6994 -- ----------------------------------------------------------------------------------
6995 -- ----------------------------------------------------------------------------------
6996
6997 PROCEDURE Prepack_LPN_CP (
6998 ERRBUF OUT NOCOPY VARCHAR2
6999 , RETCODE OUT NOCOPY NUMBER
7000 , p_api_version IN NUMBER
7001 , p_organization_id IN NUMBER
7002 , p_subinventory IN VARCHAR2 := NULL
7003 , p_locator_id IN NUMBER := NULL
7004 , p_inventory_item_id IN NUMBER
7005 , p_revision IN VARCHAR2 := NULL
7006 , p_lot_number IN VARCHAR2 := NULL
7007 , p_quantity IN NUMBER
7008 , p_uom IN VARCHAR2
7009 , p_source IN NUMBER
7010 , p_serial_number_from IN VARCHAR2 := NULL
7011 , p_serial_number_to IN VARCHAR2 := NULL
7012 , p_container_item_id IN NUMBER := NULL
7013 , p_cont_revision IN VARCHAR2 := NULL
7014 , p_cont_lot_number IN VARCHAR2 := NULL
7015 , p_cont_serial_number_from IN VARCHAR2 := NULL
7016 , p_cont_serial_number_to IN VARCHAR2 := NULL
7017 , p_lpn_sealed_flag IN NUMBER := NULL
7018 , p_print_label IN NUMBER := NULL
7019 , p_print_content_report IN NUMBER := NULL
7020 , p_packaging_level IN NUMBER := -1
7021 , p_sec_quantity IN NUMBER := NULL --INVCONV kkillams
7022 , p_sec_uom IN VARCHAR2 := NULL --INVCONV kkillams
7023 ) IS
7024 l_api_name CONSTANT VARCHAR2(30) := 'Prepack_LPN_CP';
7025 l_api_version CONSTANT NUMBER := 1.0;
7026
7027 l_result NUMBER;
7028 x_return_status VARCHAR2(4);
7029 x_msg_count NUMBER;
7030 x_msg_data VARCHAR2(300);
7031 ret BOOLEAN;
7032 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
7033
7034 BEGIN
7035 -- Standard Start of API savepoint
7036 SAVEPOINT PREPACK_LPN_CP_PVT;
7037
7038 -- Standard call to check for call compatibility.
7039 IF NOT fnd_api.compatible_api_call(l_api_version, p_api_version, l_api_name, g_pkg_name) THEN
7040 fnd_message.set_name('WMS', 'WMS_CONT_INCOMPATIBLE_API_CALL');
7041 fnd_msg_pub.ADD;
7042 RAISE fnd_api.g_exc_unexpected_error;
7043 END IF;
7044
7045 -- Initialize API return status to success
7046 x_return_status := fnd_api.g_ret_sts_success;
7047
7048 -- Call Prepack LPN
7049 Prepack_LPN(
7050 p_api_version=> p_api_version,
7051 --p_init_msg_list=> := fnd_api.g_false,
7052 --p_commit=> fnd_api.g_false;,
7053 x_return_status=> x_return_status,
7054 x_msg_count=> x_msg_count,
7055 x_msg_data=> x_msg_data,
7056 p_organization_id=> p_organization_id,
7057 p_subinventory=> p_subinventory,
7058 p_locator_id=> p_locator_id,
7059 p_inventory_item_id=> p_inventory_item_id,
7060 p_revision=> p_revision,
7061 p_lot_number=> p_lot_number,
7062 p_quantity=> p_quantity,
7063 p_uom=> p_uom,
7064 p_source=> p_source,
7065 p_serial_number_from=> p_serial_number_from,
7066 p_serial_number_to=> p_serial_number_to,
7067 p_container_item_id=> p_container_item_id,
7068 p_cont_revision=> p_cont_revision,
7069 p_cont_lot_number=> p_cont_lot_number,
7070 p_cont_serial_number_from=> p_cont_serial_number_from,
7071 p_cont_serial_number_to=> p_cont_serial_number_to,
7072 p_lpn_sealed_flag=> p_lpn_sealed_flag,
7073 p_print_label=> p_print_label,
7074 p_print_content_report=> p_print_content_report,
7075 p_packaging_level=>p_packaging_level,
7076 p_sec_quantity => p_sec_quantity, --INVCONV kkillams
7077 p_sec_uom => p_sec_uom --INVCONV kkillams
7078 );
7079
7080 IF (x_return_status = fnd_api.g_ret_sts_success) THEN
7081 ret := fnd_concurrent.set_completion_status('NORMAL', x_msg_data);
7082 retcode := 0;
7083 ELSE
7084 ret := fnd_concurrent.set_completion_status('ERROR', x_msg_data);
7085 retcode := 2;
7086 errbuf := x_msg_data;
7087 END IF;
7088
7089 -- Standard call to get message count and if count is 1,
7090 -- get message info.
7091 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
7092 EXCEPTION
7093 WHEN fnd_api.g_exc_error THEN
7094 ROLLBACK TO PREPACK_LPN_CP_PVT;
7095 x_return_status := fnd_api.g_ret_sts_error;
7096 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
7097 WHEN fnd_api.g_exc_unexpected_error THEN
7098 ROLLBACK TO PREPACK_LPN_CP_PVT;
7099 x_return_status := fnd_api.g_ret_sts_unexp_error;
7100 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
7101 WHEN OTHERS THEN
7102 ROLLBACK TO PREPACK_LPN_CP_PVT;
7103 x_return_status := fnd_api.g_ret_sts_unexp_error;
7104
7105 IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error) THEN
7106 fnd_msg_pub.add_exc_msg(g_pkg_name, l_api_name);
7107 END IF;
7108
7109 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
7110 END prepack_lpn_cp;
7111
7112 -- ----------------------------------------------------------------------------------
7113 -- ----------------------------------------------------------------------------------
7114
7115 PROCEDURE Prepack_LPN(
7116 p_api_version IN NUMBER
7117 , p_init_msg_list IN VARCHAR2 := fnd_api.g_false
7118 , p_commit IN VARCHAR2 := fnd_api.g_false
7119 , x_return_status OUT NOCOPY VARCHAR2
7120 , x_msg_count OUT NOCOPY NUMBER
7121 , x_msg_data OUT NOCOPY VARCHAR2
7122 , p_organization_id IN NUMBER
7123 , p_subinventory IN VARCHAR2 := NULL
7124 , p_locator_id IN NUMBER := NULL
7125 , p_inventory_item_id IN NUMBER
7126 , p_revision IN VARCHAR2 := NULL
7127 , p_lot_number IN VARCHAR2 := NULL
7128 , p_quantity IN NUMBER
7129 , p_uom IN VARCHAR2
7130 , p_source IN NUMBER
7131 , p_serial_number_from IN VARCHAR2 := NULL
7132 , p_serial_number_to IN VARCHAR2 := NULL
7133 , p_container_item_id IN NUMBER := NULL
7134 , p_cont_revision IN VARCHAR2 := NULL
7135 , p_cont_lot_number IN VARCHAR2 := NULL
7136 , p_cont_serial_number_from IN VARCHAR2 := NULL
7137 , p_cont_serial_number_to IN VARCHAR2 := NULL
7138 , p_lpn_sealed_flag IN NUMBER := NULL
7139 , p_print_label IN NUMBER := NULL
7140 , p_print_content_report IN NUMBER := NULL
7141 , p_packaging_level IN NUMBER := -1
7142 , p_sec_quantity IN NUMBER := NULL --INVCONV kkillams
7143 , p_sec_uom IN VARCHAR2 := NULL --INVCONV kkillams
7144 ) IS
7145 l_api_name CONSTANT VARCHAR2(30) := 'Prepack_LPN';
7146 l_api_version CONSTANT NUMBER := 1.0;
7147 l_debug NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
7148 l_progress VARCHAR2(10) := '0';
7149
7150 l_result NUMBER;
7151 l_container_item_id NUMBER := p_container_item_id;
7152 l_max_load_quantity NUMBER;
7153 l_quantity NUMBER;
7154 l_sec_quantity NUMBER; -- INVCONV kkillams
7155 l_primary_quantity NUMBER;
7156 l_lot_number VARCHAR2(30) := p_lot_number;
7157 l_uom VARCHAR(30) := p_uom;
7158 l_lpn_source NUMBER := p_source;
7159 l_sec_pack_quantity NUMBER; -- INVCONV kkillams
7160 l_sec_uom VARCHAR(3); -- INVCONV kkillams
7161 l_pack_quantity NUMBER;
7162 l_lpn_quantity NUMBER;
7163 l_process_id NUMBER;
7164 l_lpn_to_pack NUMBER;
7165 l_lpn_sealed_flag NUMBER := 2;
7166 l_print_label NUMBER := 2;
7167 l_print_content_report NUMBER := 2;
7168 l_serial_number_from VARCHAR2(30) := NULL;
7169 l_serial_number_to VARCHAR2(30) := NULL;
7170 l_serial_suffix_current NUMBER;
7171 l_serial_def_flag BOOLEAN := FALSE;
7172 l_serial_prefix VARCHAR2(30);
7173 l_serial_suffix_from NUMBER;
7174 l_serial_suffix_to NUMBER;
7175 l_serial_qty_btwn NUMBER;
7176 l_serial_suffix_length NUMBER := 0;
7177 temp NUMBER;
7178 l_cont_serial_number_from VARCHAR2(30) := NULL;
7179 l_cont_serial_number_to VARCHAR2(30) := NULL;
7180 l_cont_serial_suffix_current NUMBER;
7181 l_cont_serial_def_flag BOOLEAN := FALSE;
7182 l_cont_serial_prefix VARCHAR2(30);
7183 l_cont_serial_suffix_from NUMBER;
7184 l_cont_serial_suffix_to NUMBER;
7185 l_cont_serial_qty_btwn NUMBER;
7186 l_cont_serial_suffix_length NUMBER := 0;
7187 l_current_serial VARCHAR2(30);
7188 l_lpn_id_out NUMBER;
7189 l_lpn_out VARCHAR2(30);
7190 x_error_code NUMBER;
7191 x_proc_msg VARCHAR2(2000);
7192 x_xml_file VARCHAR2(30);
7193 l_trx_tmp_id NUMBER;
7194 l_trx_header_id NUMBER;
7195 l_ser_trx_id NUMBER := NULL;
7196 l_primary_uom VARCHAR2(4);
7197 l_lot_control_code NUMBER;
7198
7199 l_label_status VARCHAR2(300);
7200 l_input_param_tbl inv_label.input_parameter_rec_type;
7201 l_input_param_rec mtl_material_transactions_temp%ROWTYPE;
7202 l_counter NUMBER := 1; -- Counter variable initialized to 1
7203 l_qty NUMBER := 0;
7204 error_msg VARCHAR2(2000);
7205
7206 CURSOR container_load IS
7207 SELECT max_load_quantity
7208 FROM wsh_container_items
7209 WHERE load_item_id = p_inventory_item_id
7210 AND container_item_id = p_container_item_id
7211 AND master_organization_id = p_organization_id
7212 AND ROWNUM < 2;
7213
7214 CURSOR container_lpn IS
7215 SELECT lpn_id
7216 FROM wms_lpn_process_temp
7217 WHERE process_id = l_process_id;
7218
7219 CURSOR cartonization_cursor IS
7220 SELECT mmtt.cartonization_id,
7221 mmtt.transaction_quantity,
7222 mmtt.primary_quantity,
7223 mmtt.transaction_uom,
7224 mtlt.lot_number,
7225 NVL(msnt1.fm_serial_number, msnt2.fm_serial_number),
7226 NVL(msnt1.to_serial_number, msnt2.to_serial_number)
7227 , mmtt.secondary_transaction_quantity --INVCONV kkillams
7228 , mmtt.secondary_uom_code --INVCONV kkillams
7229 FROM mtl_material_transactions_temp mmtt, mtl_transaction_lots_temp mtlt, mtl_serial_numbers_temp msnt1, mtl_serial_numbers_temp msnt2
7230 WHERE mmtt.organization_id = p_organization_id
7231 AND mmtt.transaction_header_id = l_trx_header_id
7232 AND mtlt.transaction_temp_id(+) = mmtt.transaction_temp_id
7233 AND msnt1.transaction_temp_id(+) = mtlt.serial_transaction_temp_id
7234 AND msnt2.transaction_temp_id(+) = mmtt.transaction_temp_id;
7235
7236 BEGIN
7237 -- Standard Start of API savepoint
7238 SAVEPOINT prepack_lpn_pub;
7239
7240 -- Standard call to check for call compatibility.
7241 IF NOT fnd_api.compatible_api_call(l_api_version, p_api_version, l_api_name, g_pkg_name) THEN
7242 fnd_message.set_name('WMS', 'WMS_CONT_INCOMPATIBLE_API_CALL');
7243 fnd_msg_pub.ADD;
7244 RAISE fnd_api.g_exc_unexpected_error;
7245 END IF;
7246
7247 -- Initialize message list if p_init_msg_list is set to TRUE.
7248 IF fnd_api.to_boolean(p_init_msg_list) THEN
7249 fnd_msg_pub.initialize;
7250 END IF;
7251
7252 -- Initialize API return status to success
7253 --x_return_status := FND_API.G_RET_STS_SUCCESS;
7254
7255 -- API body
7256 IF (l_debug = 1) THEN
7257 mdebug(l_api_name || ' Entered ' || g_pkg_version, 1);
7258 mdebug('orgid=' ||p_organization_id|| ' sub=' ||p_subinventory|| ' loc=' ||p_locator_id|| ' qty=' ||p_quantity|| ' uom=' ||p_uom|| ' src=' ||p_source||' lvl='||p_packaging_level, G_INFO);
7259 mdebug('itemid=' ||p_inventory_item_id|| ' rev=' ||p_revision|| ' lot=' ||p_lot_number|| ' fmsn=' ||p_serial_number_from|| ' tosn=' ||p_serial_number_to, G_INFO);
7260 mdebug('citemid=' ||p_container_item_id|| ' crev=' ||p_cont_revision|| ' clot=' ||p_cont_lot_number|| ' cfmsn=' ||p_cont_serial_number_from|| ' ctosn=' ||p_cont_serial_number_to, G_INFO);
7261 END IF;
7262
7263 -- Find primary UOM for this item
7264 SELECT primary_uom_code, lot_control_code
7265 INTO l_primary_uom, l_lot_control_code
7266 FROM mtl_system_items
7267 WHERE organization_id = p_organization_id
7268 AND inventory_item_id = p_inventory_item_id;
7269
7270 IF ( p_source = LPN_CONTEXT_WIP ) THEN
7271 -- WIP needs a different context for generate lpns than what is given.
7272 l_lpn_source := LPN_PREPACK_FOR_WIP;
7273
7274 -- If lot controlled item in WIP and no lot is given generate a new lot for item
7275 IF ( l_lot_control_code = 2 AND p_lot_number IS NULL ) THEN
7276 l_lot_number := INV_LOT_API_PUB.Auto_Gen_Lot (
7277 p_api_version => 1.0
7278 , x_return_status => x_return_status
7279 , x_msg_count => x_msg_count
7280 , x_msg_data => x_msg_data
7281 , p_org_id => p_organization_id
7282 , p_inventory_item_id => p_inventory_item_id );
7283
7284 IF ( x_error_code <> 0 ) THEN
7285 IF (l_debug = 1) THEN
7286 mdebug('auto_gen_lot failed', G_ERROR);
7287 END IF;
7288 RAISE fnd_api.g_exc_error;
7289 END IF;
7290
7291 IF (l_debug = 1) THEN
7292 mdebug('lot number generated: '|| l_lot_number);
7293 END IF;
7294 END IF;
7295 END IF;
7296
7297 -- If a container item has been specified, find quantity of
7298 -- items that can be contained in each.
7299 IF (p_container_item_id IS NOT NULL) THEN
7300 FOR l_temp_rec IN container_load LOOP
7301 l_max_load_quantity := l_temp_rec.max_load_quantity;
7302 END LOOP;
7303
7304 IF (l_debug = 1) THEN
7305 mdebug('max load qty '|| TO_CHAR(l_max_load_quantity), G_INFO);
7306 END IF;
7307
7308 -- If no item container relationship exists assume container
7309 -- has infinite quanitiy and specify only one LPN, else
7310 -- calculate the number of containers need to prepack items
7311 IF (l_max_load_quantity IS NULL) THEN
7312 /* Generate only one LPN */
7313 l_lpn_quantity := 1;
7314 l_max_load_quantity := p_quantity;
7315 IF (l_debug = 1) THEN
7316 mdebug('Container_Required_Qty default '|| TO_CHAR(l_lpn_quantity), G_INFO);
7317 END IF;
7318 ELSE
7319 /* Calculate number of LPNs required */
7320 Container_Required_Qty(
7321 p_api_version=> 1.0,
7322 p_init_msg_list=> fnd_api.g_false,
7323 p_commit=> fnd_api.g_false,
7324 x_return_status=> x_return_status,
7325 x_msg_count=> x_msg_count,
7326 x_msg_data=> x_msg_data,
7327 p_source_item_id=> p_inventory_item_id,
7328 p_source_qty=> p_quantity,
7329 p_source_qty_uom=> p_uom,
7330 p_organization_id=> p_organization_id,
7331 p_dest_cont_item_id=> l_container_item_id,
7332 p_qty_required=> l_lpn_quantity
7333 );
7334
7335 IF (x_return_status <> fnd_api.g_ret_sts_success) THEN
7336 IF (l_debug = 1) THEN
7337 mdebug('calc lpn failed'|| x_msg_data, G_ERROR);
7338 END IF;
7339 fnd_message.set_name('WMS', 'WMS_CONT_QTY_ERROR');
7340 fnd_msg_pub.ADD;
7341 RAISE fnd_api.g_exc_unexpected_error;
7342 END IF;
7343
7344 IF (l_debug = 1) THEN
7345 mdebug('Container_Required_Qty '|| TO_CHAR(l_lpn_quantity), G_INFO);
7346 END IF;
7347 END IF;
7348
7349 Generate_LPN (
7350 p_api_version => p_api_version
7351 , p_init_msg_list => fnd_api.g_false
7352 , p_commit => fnd_api.g_false
7353 , x_return_status => x_return_status
7354 , x_msg_count => x_msg_count
7355 , x_msg_data => x_msg_data
7356 , p_organization_id => p_organization_id
7357 , p_container_item_id => l_container_item_id
7358 , p_revision => p_cont_revision
7359 , p_lot_number => p_cont_lot_number
7360 , p_from_serial_number => l_cont_serial_number_from
7361 , p_to_serial_number => l_cont_serial_number_to
7362 , p_quantity => l_lpn_quantity
7363 , p_process_id => l_process_id
7364 , p_lpn_id_out => l_lpn_id_out
7365 , p_lpn_out => l_lpn_out
7366 , p_source => l_lpn_source );
7367
7368 IF (x_return_status <> fnd_api.g_ret_sts_success) THEN
7369 IF (l_debug = 1) THEN
7370 mdebug('failed to generate lpn '|| x_msg_data, 1);
7371 END IF;
7372 fnd_message.set_name('WMS', 'WMS_LPN_GENERATION_FAIL');
7373 fnd_msg_pub.ADD;
7374 RAISE fnd_api.g_exc_unexpected_error;
7375 END IF;
7376
7377 IF (l_debug = 1) THEN
7378 mdebug('Process Id '|| TO_CHAR(l_process_id), G_INFO);
7379 END IF;
7380
7381 SELECT COUNT(*)
7382 INTO temp
7383 FROM wms_lpn_process_temp
7384 WHERE process_id = l_process_id;
7385
7386 IF (l_debug = 1) THEN
7387 mdebug('num lpn created: '|| TO_CHAR(temp), G_INFO);
7388 END IF;
7389 ELSE
7390 IF (l_debug = 1) THEN
7391 mdebug(' No container item specified ', G_MESSAGE);
7392 END IF;
7393 -- No container type specified, use cartonization API to find containers
7394 -- Convert transaction quantity to primary quantity
7395 l_primary_quantity := Round(Convert_UOM(p_inventory_item_id, p_quantity, p_uom, l_primary_uom), 5); --13591755 added for GRUPO
7396
7397 IF (l_debug = 1) THEN
7398 mdebug('using cartonization api', G_MESSAGE);
7399 END IF;
7400
7401 SELECT mtl_material_transactions_s.NEXTVAL
7402 INTO l_trx_header_id
7403 FROM DUAL;
7404
7405 IF (l_debug = 1) THEN
7406 mdebug('trx header id for cartonization created: '|| TO_CHAR(l_trx_header_id), G_INFO);
7407 END IF;
7408 x_error_code := inv_trx_util_pub.insert_line_trx(
7409 p_trx_hdr_id=> l_trx_header_id,
7410 p_item_id=> p_inventory_item_id,
7411 p_revision=> p_revision,
7412 p_org_id=> p_organization_id,
7413 p_trx_action_id=> inv_globals.g_action_containerpack,
7414 p_subinv_code=> p_subinventory,
7415 p_tosubinv_code=> NULL,
7416 p_locator_id=> p_locator_id,
7417 p_tolocator_id=> NULL,
7418 p_xfr_org_id=> NULL,
7419 p_trx_type_id=> inv_globals.g_type_container_pack,
7420 p_trx_src_type_id=> inv_globals.g_sourcetype_inventory,
7421 p_trx_qty=> p_quantity,
7422 p_pri_qty=> l_primary_quantity,
7423 p_uom=> p_uom,
7424 p_date=> SYSDATE,
7425 p_reason_id=> NULL,
7426 p_user_id=> fnd_global.user_id,
7427 p_frt_code=> NULL,
7428 p_ship_num=> NULL,
7429 p_dist_id=> NULL,
7430 p_way_bill=> NULL,
7431 p_exp_arr=> NULL,
7432 p_cost_group=> NULL,
7433 p_from_lpn_id=> NULL,
7434 p_cnt_lpn_id=> NULL,
7435 --p_xfr_lpn_id => l_lpn_to_pack,
7436 x_trx_tmp_id=> l_trx_tmp_id,
7437 x_proc_msg=> x_proc_msg,
7438 p_secondary_trx_qty =>p_sec_quantity, --INVCONV kkillams
7439 p_secondary_uom =>p_sec_uom --INVCONV kkillams
7440 );
7441
7442 IF (x_error_code <> 0) THEN
7443 IF (l_debug = 1) THEN
7444 mdebug('failed INSERT_LINE_TRX '|| x_error_code, 1);
7445 mdebug('error msg: '|| x_proc_msg, 1);
7446 END IF;
7447 fnd_message.set_name('WMS', 'WMS_INSERT_LINE_TRX_FAIL');
7448 fnd_msg_pub.ADD;
7449 RAISE fnd_api.g_exc_unexpected_error;
7450 END IF;
7451
7452 IF (l_debug = 1) THEN
7453 mdebug('trx temp id created: '|| TO_CHAR(l_trx_tmp_id), G_INFO);
7454 END IF;
7455
7456 IF ( x_error_code = 0 AND l_lot_number IS NOT NULL ) THEN
7457 IF (l_debug = 1) THEN
7458 mdebug('Insert lot entry in MTL_LOT_NUMBER_TEMP lot='|| l_lot_number, G_INFO);
7459 END IF;
7460 x_error_code := inv_trx_util_pub.insert_lot_trx(
7461 p_trx_tmp_id=> l_trx_tmp_id,
7462 p_user_id=> fnd_global.user_id,
7463 p_lot_number=> l_lot_number,
7464 p_trx_qty=> p_quantity,
7465 p_pri_qty=> l_primary_quantity,
7466 p_secondary_qty =>p_sec_quantity, --INVCONV kkillams
7467 p_secondary_uom =>p_sec_uom, --INVCONV kkillams
7468 x_ser_trx_id=> l_ser_trx_id,
7469 x_proc_msg=> x_proc_msg
7470 );
7471
7472 IF (x_error_code <> 0) THEN
7473 IF (l_debug = 1) THEN
7474 mdebug('failed INSERT_LOT_TRX lot='||l_lot_number||' '||x_error_code, G_ERROR);
7475 mdebug('error msg: '|| x_proc_msg, G_ERROR);
7476 END IF;
7477 fnd_message.set_name('WMS', 'WMS_INSERT_LOT_TRX_FAIL');
7478 fnd_msg_pub.ADD;
7479 RAISE fnd_api.g_exc_unexpected_error;
7480 END IF;
7481 END IF;
7482
7483 IF ( x_error_code = 0 AND l_serial_number_from IS NOT NULL ) THEN
7484 IF (l_ser_trx_id IS NOT NULL) THEN
7485 l_trx_tmp_id := l_ser_trx_id;
7486 END IF;
7487
7488 IF (l_debug = 1) THEN
7489 mdebug('inserting serials '|| l_serial_number_from || '-' || l_serial_number_to || ' into mmtt', G_INFO);
7490 mdebug('with l_trx_tmp_id='|| l_trx_tmp_id, G_INFO);
7491 END IF;
7492 --Insert serials into MTL_SERIAL_NUMBERS_TEMP
7493 x_error_code := inv_trx_util_pub.insert_ser_trx(
7494 p_trx_tmp_id=> l_trx_tmp_id,
7495 p_user_id=> fnd_global.user_id,
7496 p_fm_ser_num=> l_serial_number_from,
7497 p_to_ser_num=> l_serial_number_to,
7498 x_proc_msg=> x_proc_msg
7499 );
7500
7501 IF (x_error_code <> 0) THEN
7502 IF (l_debug = 1) THEN
7503 mdebug('failed INSERT_SER_TRX '|| x_error_code, G_ERROR);
7504 mdebug('error msg: '|| x_proc_msg, G_ERROR);
7505 END IF;
7506 fnd_message.set_name('WMS', 'WMS_INSERT_SER_TRX_FAIL');
7507 fnd_msg_pub.ADD;
7508 RAISE fnd_api.g_exc_unexpected_error;
7509 END IF;
7510 END IF;
7511
7512 IF (l_debug = 1) THEN
7513 mdebug('Calling cartonization', 9);
7514 END IF;
7515
7516 WMS_CARTNZN_WRAP.Cartonize (
7517 p_api_version => 1.0
7518 , p_init_msg_list => fnd_api.g_false
7519 , p_commit => fnd_api.g_false
7520 , x_return_status => x_return_status
7521 , x_msg_count => x_msg_count
7522 , x_msg_data => x_msg_data
7523 , p_org_id => p_organization_id
7524 , p_transaction_header_id => l_trx_header_id
7525 , p_stop_level => p_packaging_level
7526 , p_packaging_mode => WMS_CARTNZN_WRAP.PREPACK_PKG_MODE );
7527
7528 IF (x_return_status = fnd_api.g_ret_sts_error) THEN
7529 IF (l_debug = 1) THEN
7530 mdebug('Error in calling Cartonization'|| x_msg_data, 1);
7531 END IF;
7532 RAISE fnd_api.g_exc_error;
7533 ELSIF (x_return_status = fnd_api.g_ret_sts_unexp_error) THEN
7534 IF (l_debug = 1) THEN
7535 mdebug('Unexpectied error in calling Cartonization'|| x_msg_data, 1);
7536 END IF;
7537 RAISE fnd_api.g_exc_unexpected_error;
7538 ELSIF (x_return_status <> fnd_api.g_ret_sts_success) THEN
7539 IF (l_debug = 1) THEN
7540 mdebug('Undefined error in calling Cartonization'|| x_msg_data, 1);
7541 END IF;
7542 RAISE fnd_api.g_exc_unexpected_error;
7543 END IF;
7544
7545 IF (l_debug = 1) THEN
7546 mdebug('cartonization api done');
7547 END IF;
7548 -- Cartonization does label printing disable pack label printing
7549 l_print_label := 2;
7550
7551 -- Generate a process ID number to to insert LPNs into process temp table
7552 SELECT wms_lpn_process_temp_s.NEXTVAL
7553 INTO l_process_id
7554 FROM DUAL;
7555
7556 IF (l_debug = 1) THEN
7557 mdebug('created process id: '|| l_process_id, G_INFO);
7558 END IF;
7559 END IF;
7560
7561 --Could be useful later
7562 /*IF ( l_container_item.serial_number_control_code = 2 AND p_source IN (2,3) ) THEN
7563 -- Serials need to be dymanically generated for LPNs
7564 x_error_code := INV_SERIAL_NUMBER_PUB.GENERATE_SERIALS
7565 (p_org_id => p_organization_id,
7566 p_item_id => p_container_item_id,
7567 p_qty => l_lpn_quantity,
7568 p_wip_id => NULL,
7569 p_rev => p_cont_revision,
7570 p_lot => p_cont_lot_number,
7571 x_start_ser => l_cont_serial_number_from,
7572 x_end_ser => l_cont_serial_number_to,
7573 x_proc_msg => x_msg_data);
7574
7575 IF x_error_code <> 0 THEN
7576 IF (l_debug = 1) THEN
7577 mdebug('failed genreate serials ' || TO_CHAR(x_error_code));
7578 END IF;
7579 FND_MESSAGE.SET_NAME('WMS', 'WMS_CONT_INVALID_SER');
7580 FND_MSG_PUB.ADD;
7581 RAISE FND_API.G_EXC_ERROR;
7582 ELSE
7583 IF (l_debug = 1) THEN
7584 mdebug('genreated serials ' || l_cont_serial_number_from || ' - ' || l_cont_serial_number_to);
7585 END IF;
7586 END IF;
7587 END IF;*/
7588
7589 -- put total quantity into temp variable
7590 l_quantity := p_quantity;
7591 l_sec_quantity := p_sec_quantity; --INVCONV kkillams
7592
7593 IF l_serial_def_flag THEN
7594 l_serial_suffix_current := l_serial_suffix_from - 1;
7595 ELSE
7596 l_serial_number_from := NULL;
7597 l_serial_number_to := NULL;
7598 END IF;
7599
7600 -- Open Cursor
7601 IF (p_container_item_id IS NULL) THEN
7602 OPEN cartonization_cursor;
7603 ELSE
7604 OPEN container_lpn;
7605 END IF;
7606
7607 -- Pack and Change Context of LPN
7608 --FOR container_rec IN container_lpn
7609 LOOP
7610 IF (p_container_item_id IS NULL) THEN
7611 FETCH cartonization_cursor INTO l_lpn_to_pack, l_pack_quantity, l_primary_quantity,
7612 l_uom, l_lot_number, l_serial_number_from, l_serial_number_to,
7613 l_sec_pack_quantity,l_sec_uom; --INVCONV kkillams
7614 EXIT WHEN cartonization_cursor%NOTFOUND;
7615
7616 -- Cartonization created LPNs, lpn_context must be set before packing
7617 IF (l_debug = 1) THEN
7618 mdebug('setting lpn id= ' || l_lpn_to_pack || ' to context ' || l_lpn_source, G_INFO);
7619 END IF;
7620 -- Bug5659809: update last_update_date and last_update_by as well
7621 UPDATE wms_license_plate_numbers
7622 SET lpn_context = l_lpn_source
7623 , last_update_date = SYSDATE
7624 , last_updated_by = fnd_global.user_id
7625 WHERE lpn_id = l_lpn_to_pack;
7626 ELSE
7627 FETCH container_lpn INTO l_lpn_to_pack;
7628 EXIT WHEN container_lpn%NOTFOUND;
7629
7630 -- Pack the lesser of the maximum container load or remaining item quantity
7631 IF l_quantity < l_max_load_quantity THEN
7632 l_pack_quantity := l_quantity;
7633 l_sec_pack_quantity := l_sec_quantity; -- INVCONV kkillams
7634 ELSE
7635 l_pack_quantity := l_max_load_quantity;
7636 l_sec_pack_quantity := inv_convert.inv_um_convert(p_inventory_item_id,
7637 g_precision,
7638 l_max_load_quantity,
7639 p_uom,
7640 p_sec_uom,
7641 NULL,
7642 NULL); --INVCONV KKILLAMS
7643 l_quantity := l_quantity - l_max_load_quantity;
7644 END IF;
7645
7646 -- Not using cartonization. Need to convert pack quantity to a primary quantity
7647 l_primary_quantity := Round(Convert_UOM(p_inventory_item_id, l_pack_quantity, p_uom, l_primary_uom), 5); --13591755 added for GRUPO
7648
7649 -- set next group of serials to be packed.
7650 IF l_serial_def_flag THEN
7651 l_serial_suffix_from := l_serial_suffix_current + 1;
7652 --l_serial_suffix_current := l_serial_suffix_current + least(l_max_load_quantity, l_quantity);
7653 l_serial_suffix_current := l_serial_suffix_current + l_primary_quantity;
7654 l_serial_number_from := l_serial_prefix || LPAD(TO_CHAR(l_serial_suffix_from), l_serial_suffix_length, '0');
7655 l_serial_number_to := l_serial_prefix || LPAD(TO_CHAR(l_serial_suffix_current), l_serial_suffix_length, '0');
7656 END IF;
7657 END IF;
7658
7659 IF (l_lpn_to_pack IS NULL) THEN
7660 IF (l_debug = 1) THEN
7661 mdebug('cartonize failed: No LPN Specified in row', G_ERROR);
7662 END IF;
7663 fnd_message.set_name('WMS', 'WMS_CARTONIZE_ERROR');
7664 fnd_msg_pub.ADD;
7665 --COMMIT;
7666 RAISE fnd_api.g_exc_unexpected_error;
7667 END IF;
7668
7669 IF (l_debug = 1) THEN
7670 mdebug('packing lpn='|| l_lpn_to_pack || ' with qty=' || l_primary_quantity || ' ' ||l_primary_uom);
7671 mdebug('with lot='|| l_lot_number || ' serials=' || l_serial_number_from || '-' || l_serial_number_to);
7672 END IF;
7673
7674 --If an invenotory prepack, insert trx in mtl_material_transactions_temp table
7675 IF (p_source = 1) THEN
7676 -- if inventory prepack, trx header id required
7677 SELECT mtl_material_transactions_s.NEXTVAL
7678 INTO l_trx_header_id
7679 FROM DUAL;
7680
7681 IF (l_debug = 1) THEN
7682 mdebug('trx header id created: '|| TO_CHAR(l_trx_header_id), G_INFO);
7683 END IF;
7684
7685 IF (l_debug = 1) THEN
7686 mdebug('packing lpn: '|| TO_CHAR(l_lpn_to_pack) || ' with qty ' || TO_CHAR(l_primary_quantity));
7687 END IF;
7688 x_error_code := inv_trx_util_pub.insert_line_trx(
7689 p_trx_hdr_id=> l_trx_header_id,
7690 p_item_id=> p_inventory_item_id,
7691 p_revision=> p_revision,
7692 p_org_id=> p_organization_id,
7693 p_trx_action_id=> inv_globals.g_action_containerpack,
7694 p_subinv_code=> p_subinventory,
7695 p_tosubinv_code=> NULL,
7696 p_locator_id=> p_locator_id,
7697 p_tolocator_id=> NULL,
7698 p_xfr_org_id=> NULL,
7699 p_trx_type_id=> inv_globals.g_type_container_pack,
7700 p_trx_src_type_id=> inv_globals.g_sourcetype_inventory,
7701 p_trx_qty=> l_pack_quantity,
7702 p_pri_qty=> l_primary_quantity,
7703 p_uom=> l_primary_uom,
7704 p_date=> SYSDATE,
7705 p_reason_id=> NULL,
7706 p_user_id=> fnd_global.user_id,
7707 p_frt_code=> NULL,
7708 p_ship_num=> NULL,
7709 p_dist_id=> NULL,
7710 p_way_bill=> NULL,
7711 p_exp_arr=> NULL,
7712 p_cost_group=> NULL,
7713 p_from_lpn_id=> NULL,
7714 p_cnt_lpn_id=> NULL,
7715 p_xfr_lpn_id=> l_lpn_to_pack,
7716 x_trx_tmp_id=> l_trx_tmp_id,
7717 x_proc_msg=> x_proc_msg,
7718 p_secondary_trx_qty =>l_sec_pack_quantity, --INVCONV kkillams
7719 p_secondary_uom =>l_sec_uom --INVCONV kkillams
7720 );
7721
7722 IF (x_error_code <> 0) THEN
7723 IF (l_debug = 1) THEN
7724 mdebug('failed INSERT_LINE_TRX '|| x_error_code, G_ERROR);
7725 mdebug('error msg: '|| x_proc_msg, 1);
7726 END IF;
7727 fnd_message.set_name('WMS', 'WMS_INSERT_LINE_TRX_FAIL');
7728 fnd_msg_pub.ADD;
7729 RAISE fnd_api.g_exc_unexpected_error;
7730 END IF;
7731
7732 IF (l_debug = 1) THEN
7733 mdebug('trx temp id created: '|| TO_CHAR(l_trx_tmp_id), G_INFO);
7734 END IF;
7735
7736 IF ( x_error_code = 0 AND l_lot_number IS NOT NULL ) THEN
7737 IF (l_debug = 1) THEN
7738 mdebug('Insert lot entry in MTL_LOT_NUMBER_TEMP lot='|| l_lot_number, G_INFO);
7739 END IF;
7740 x_error_code := inv_trx_util_pub.insert_lot_trx(
7741 p_trx_tmp_id=> l_trx_tmp_id,
7742 p_user_id=> fnd_global.user_id,
7743 p_lot_number=> l_lot_number,
7744 p_trx_qty=> l_primary_quantity,
7745 p_pri_qty=> l_primary_quantity,
7746 p_secondary_qty => l_sec_pack_quantity, --INVCONV kkillams
7747 p_secondary_uom =>l_sec_uom, --INVCONV kkillams
7748 x_ser_trx_id=> l_ser_trx_id,
7749 x_proc_msg=> x_proc_msg
7750 );
7751
7752 IF (x_error_code <> 0) THEN
7753 IF (l_debug = 1) THEN
7754 mdebug('failed INSERT_LOT_TRX '|| x_error_code, 1);
7755 mdebug('error msg: '|| x_proc_msg, 1);
7756 END IF;
7757 fnd_message.set_name('WMS', 'WMS_INSERT_LOT_TRX_FAIL');
7758 fnd_msg_pub.ADD;
7759 RAISE fnd_api.g_exc_unexpected_error;
7760 END IF;
7761 END IF;
7762
7763 IF ( x_error_code = 0 AND l_serial_number_from IS NOT NULL ) THEN
7764 IF (l_ser_trx_id IS NOT NULL) THEN
7765 l_trx_tmp_id := l_ser_trx_id;
7766 END IF;
7767 IF (l_debug = 1) THEN
7768 mdebug('inserting serials '|| l_serial_number_from || '-' || l_serial_number_to || ' into mmtt', G_INFO);
7769 mdebug('with l_trx_tmp_id='|| l_trx_tmp_id, G_INFO);
7770 END IF;
7771 x_error_code := inv_trx_util_pub.insert_ser_trx(
7772 p_trx_tmp_id=> l_trx_tmp_id,
7773 p_user_id=> fnd_global.user_id,
7774 p_fm_ser_num=> l_serial_number_from,
7775 p_to_ser_num=> l_serial_number_to,
7776 x_proc_msg=> x_proc_msg
7777 );
7778
7779 IF (x_error_code <> 0) THEN
7780 IF (l_debug = 1) THEN
7781 mdebug('failed INSERT_SER_TRX '|| x_error_code, 1);
7782 mdebug('error msg: '|| x_proc_msg, 1);
7783 END IF;
7784 fnd_message.set_name('WMS', 'WMS_INSERT_SER_TRX_FAIL');
7785 fnd_msg_pub.ADD;
7786 RAISE fnd_api.g_exc_unexpected_error;
7787 END IF;
7788 END IF;
7789
7790 --Call LPN Transaction API
7791 IF (l_debug = 1) THEN
7792 mdebug('calling process lpn trx');
7793 END IF;
7794 x_error_code := inv_lpn_trx_pub.process_lpn_trx(p_trx_hdr_id => l_trx_header_id, p_commit => fnd_api.g_false, x_proc_msg => error_msg, p_business_flow_code => 20);
7795
7796 IF (x_error_code <> 0) THEN
7797 IF (l_debug = 1) THEN
7798 mdebug('failed PROCESS_LPN_TRX '|| x_error_code, 1);
7799 mdebug('error msg: '|| error_msg, G_ERROR);
7800 END IF;
7801 fnd_message.set_name('WMS', 'WMS_PROCESS_LPN_TRX_FAIL');
7802 fnd_msg_pub.ADD;
7803 RAISE fnd_api.g_exc_unexpected_error;
7804 END IF;
7805
7806 IF (l_debug = 1) THEN
7807 mdebug('Packed LPN_ID '|| TO_CHAR(l_lpn_to_pack), G_INFO);
7808 END IF;
7809 ELSE --Source is WIP or Rec do pack w/o trx manager
7810 IF (l_debug = 1) THEN
7811 mdebug('packing lpn: '|| l_lpn_to_pack || ' with qty ' || l_primary_quantity ||' '|| l_primary_uom, G_INFO);
7812 END IF;
7813
7814 PackUnpack_Container(
7815 p_api_version=> 1.0,
7816 p_init_msg_list=> fnd_api.g_false,
7817 p_commit=> fnd_api.g_false,
7818 p_validation_level=> fnd_api.g_valid_level_none,
7819 x_return_status=> x_return_status,
7820 x_msg_count=> x_msg_count,
7821 x_msg_data=> x_msg_data,
7822 p_lpn_id=> l_lpn_to_pack,
7823 p_content_item_id=> p_inventory_item_id,
7824 p_revision=> p_revision,
7825 p_lot_number=> l_lot_number,
7826 p_from_serial_number=> l_serial_number_from,
7827 p_to_serial_number=> l_serial_number_to,
7828 p_quantity=> l_primary_quantity,
7829 p_uom=> l_primary_uom,
7830 p_organization_id=> p_organization_id,
7831 p_operation=> 1 );
7832
7833 IF (x_return_status <> fnd_api.g_ret_sts_success) THEN
7834 IF (l_debug = 1) THEN
7835 mdebug('failed to pack lpn: '|| TO_CHAR(l_lpn_to_pack), G_ERROR);
7836 END IF;
7837 fnd_message.set_name('WMS', 'WMS_PACK_CONTAINER_FAIL');
7838 fnd_message.set_token('lpn', TO_CHAR(l_lpn_to_pack));
7839 fnd_msg_pub.ADD;
7840 --RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
7841 ELSE
7842 IF (l_debug = 1) THEN
7843 mdebug('packed lpn: '|| l_lpn_to_pack || ' with qty ' || l_primary_quantity, G_INFO);
7844 END IF;
7845 END IF;
7846 END IF;
7847
7848 IF (p_container_item_id IS NULL) THEN
7849 -- Insert the LPN created into the WMS_LPN_PROCESS_TEMP table
7850 IF (l_debug = 1) THEN
7851 mdebug('making insert to temp table', G_MESSAGE);
7852 END IF;
7853 INSERT INTO wms_lpn_process_temp ( process_id, lpn_id )
7854 VALUES ( l_process_id, l_lpn_to_pack);
7855 ELSE
7856 --Not through cartonization, need to insert Row for label printing
7857 l_input_param_rec.lpn_id := l_lpn_to_pack;
7858 l_input_param_tbl(l_counter) := l_input_param_rec;
7859 l_counter := l_counter + 1;
7860 END IF;
7861
7862 IF (l_lpn_sealed_flag = 1) THEN
7863 IF (l_debug = 1) THEN
7864 mdebug('Sealing LPN', G_MESSAGE);
7865 END IF;
7866 modify_lpn_wrapper(
7867 p_api_version=> 1.0,
7868 p_init_msg_list=> fnd_api.g_false,
7869 p_commit=> fnd_api.g_false,
7870 x_return_status=> x_return_status,
7871 x_msg_count=> x_msg_count,
7872 x_msg_data=> x_msg_data,
7873 p_lpn_id=> l_lpn_to_pack,
7874 p_sealed_status=> 1 );
7875
7876 IF (x_return_status <> fnd_api.g_ret_sts_success) THEN
7877 IF (l_debug = 1) THEN
7878 mdebug('failed to seal lpn: '|| TO_CHAR(l_lpn_to_pack), G_ERROR);
7879 END IF;
7880 fnd_message.set_name('WMS', 'WMS_PACK_CONTAINER_FAIL');
7881 fnd_msg_pub.ADD;
7882 RAISE fnd_api.g_exc_unexpected_error;
7883 END IF;
7884 END IF;
7885 END LOOP;
7886
7887 IF (l_debug = 1) THEN
7888 mdebug('done with loop', G_MESSAGE);
7889 END IF;
7890
7891 -- Label printing call with cartonization flow must be made if cartonization was used
7892 IF (p_container_item_id IS NULL) THEN
7893 inv_label.print_label (
7894 x_return_status => x_return_status
7895 , x_msg_count => x_msg_count
7896 , x_msg_data => x_msg_data
7897 , x_label_status => l_label_status
7898 , p_api_version => 1.0
7899 , p_print_mode => 1
7900 , p_business_flow_code => 22
7901 , p_transaction_id => WMS_CARTNZN_WRAP.get_lpns_generated_tb);
7902
7903 IF (x_return_status <> fnd_api.g_ret_sts_success) THEN
7904 IF (l_debug = 1) THEN
7905 mdebug('**Error in Cartonization Label Printing :'||x_return_status,1);
7906 END IF;
7907 RAISE FND_API.G_EXC_ERROR;
7908 END if;
7909 END IF;
7910
7911 IF (l_print_label = 1) THEN
7912 -- Print LPN Labels
7913 IF (l_debug = 1) THEN
7914 mdebug('Calling Print label api');
7915 END IF;
7916 inv_label.print_label(
7917 x_return_status=> x_return_status,
7918 x_msg_count=> x_msg_count,
7919 x_msg_data=> x_msg_data,
7920 x_label_status=> l_label_status,
7921 p_api_version=> 1.0,
7922 p_print_mode=> 2,
7923 p_business_flow_code=> 20,
7924 p_input_param_rec=> l_input_param_tbl
7925 );
7926
7927 IF (x_return_status <> fnd_api.g_ret_sts_success) THEN
7928 IF (l_debug = 1) THEN
7929 mdebug('failed to print labels', 1);
7930 END IF;
7931 fnd_message.set_name('WMS', 'WMS_PRINT_LABEL_FAIL');
7932 fnd_msg_pub.ADD;
7933 --RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
7934 END IF;
7935 END IF;
7936
7937 -- Close cursor
7938 IF (p_container_item_id IS NULL) THEN
7939 CLOSE cartonization_cursor;
7940 ELSE
7941 CLOSE container_lpn;
7942 END IF;
7943
7944 -- Delete lpn entries from temp table
7945 DELETE FROM wms_lpn_process_temp
7946 WHERE process_id = l_process_id;
7947
7948 -- Delete lpn entries from temp table
7949 IF (p_container_item_id IS NULL) THEN
7950 DELETE FROM mtl_material_transactions_temp
7951 WHERE transaction_header_id = l_trx_header_id;
7952 END IF;
7953
7954 -- End of API body
7955
7956 -- Standard check of p_commit.
7957 IF fnd_api.to_boolean(p_commit) THEN
7958 COMMIT WORK;
7959 END IF;
7960
7961 -- Standard call to get message count and if count is 1,
7962 -- get message info.
7963 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
7964 EXCEPTION
7965 WHEN fnd_api.g_exc_error THEN
7966 IF (l_debug = 1) THEN
7967 mdebug('Execution Error', 1);
7968 END IF;
7969 ROLLBACK TO prepack_lpn_pub;
7970 x_return_status := fnd_api.g_ret_sts_error;
7971 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
7972 WHEN fnd_api.g_exc_unexpected_error THEN
7973 IF (l_debug = 1) THEN
7974 mdebug('Unexpected Execution Error', 1);
7975 END IF;
7976 ROLLBACK TO prepack_lpn_pub;
7977 x_return_status := fnd_api.g_ret_sts_unexp_error;
7978 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
7979 WHEN OTHERS THEN
7980 IF (l_debug = 1) THEN
7981 mdebug('others error', 1);
7982 END IF;
7983 ROLLBACK TO prepack_lpn_pub;
7984 x_return_status := fnd_api.g_ret_sts_error;
7985 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
7986 END Prepack_LPN;
7987
7988 -- ----------------------------------------------------------------------------------
7989 -- ----------------------------------------------------------------------------------
7990
7991 PROCEDURE Pack_Prepack_Container(
7992 p_api_version IN NUMBER
7993 , p_init_msg_list IN VARCHAR2 := fnd_api.g_false
7994 , p_commit IN VARCHAR2 := fnd_api.g_false
7995 , p_validation_level IN NUMBER := fnd_api.g_valid_level_full
7996 , x_return_status OUT NOCOPY VARCHAR2
7997 , x_msg_count OUT NOCOPY NUMBER
7998 , x_msg_data OUT NOCOPY VARCHAR2
7999 , p_lpn_id IN NUMBER
8000 , p_content_item_id IN NUMBER := NULL
8001 , p_revision IN VARCHAR2 := NULL
8002 , p_lot_number IN VARCHAR2 := NULL
8003 , p_from_serial_number IN VARCHAR2 := NULL
8004 , p_to_serial_number IN VARCHAR2 := NULL
8005 , p_quantity IN NUMBER := 1
8006 , p_uom IN VARCHAR2 := NULL
8007 , p_organization_id IN NUMBER
8008 , p_operation IN NUMBER
8009 , p_source_type_id IN NUMBER := NULL
8010 ) IS
8011 l_api_name CONSTANT VARCHAR2(30) := 'Pack_Prepack_Container';
8012 l_api_version CONSTANT NUMBER := 1.0;
8013 l_debug NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
8014 l_progress VARCHAR2(10) := '0';
8015
8016 l_current_serial VARCHAR2(30):= p_from_serial_number;
8017 l_prefix VARCHAR2(30);
8018 l_quantity NUMBER;
8019 l_from_number NUMBER;
8020 l_to_number NUMBER;
8021 l_length NUMBER;
8022 l_errorcode NUMBER;
8023
8024 l_padded_length NUMBER;
8025 l_current_number NUMBER;
8026 BEGIN
8027 -- Standard Start of API savepoint
8028 SAVEPOINT PACK_PREPACK_CONTAINER;
8029
8030 -- Standard call to check for call compatibility.
8031 IF NOT fnd_api.compatible_api_call(l_api_version, p_api_version, l_api_name, g_pkg_name) THEN
8032 fnd_message.set_name('WMS', 'WMS_CONT_INCOMPATIBLE_API_CALL');
8033 fnd_msg_pub.ADD;
8034 RAISE fnd_api.g_exc_unexpected_error;
8035 END IF;
8036
8037 -- Initialize message list if p_init_msg_list is set to TRUE.
8038 IF fnd_api.to_boolean(p_init_msg_list) THEN
8039 fnd_msg_pub.initialize;
8040 END IF;
8041
8042 -- Initialize API return status to success
8043 x_return_status := fnd_api.g_ret_sts_success;
8044
8045 -- API body
8046 IF (l_debug = 1) THEN
8047 mdebug(l_api_name || ' Entered ' || g_pkg_version, 1);
8048 mdebug('lpnid=' ||p_lpn_id|| ' orgid=' ||p_organization_id||' itemid=' ||p_content_item_id, G_INFO);
8049 mdebug('rev=' ||p_revision|| ' lot=' ||p_lot_number|| ' fmsn=' ||p_from_serial_number|| ' tosn=' ||p_to_serial_number, G_INFO);
8050 mdebug('qty=' ||p_quantity|| ' uom=' ||p_uom|| ' oper=' ||p_operation|| ' srctype=' ||p_source_type_id, G_INFO);
8051 END IF;
8052
8053 IF ( p_content_item_id IS NOT NULL ) THEN
8054 IF ( p_from_serial_number IS NOT NULL AND p_to_serial_number IS NOT NULL ) THEN
8055 -- Packing range serialized items
8056 -- Call this API to parse the serial numbers into prefixes and numbers
8057 IF (NOT mtl_serial_check.inv_serial_info(p_from_serial_number, p_to_serial_number, l_prefix, l_quantity, l_from_number, l_to_number, l_errorcode)) THEN
8058 IF (l_debug = 1) THEN
8059 mdebug('Invalid serial number given in range', 1);
8060 END IF;
8061 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_SER');
8062 fnd_msg_pub.ADD;
8063 RAISE fnd_api.g_exc_error;
8064 END IF;
8065
8066 -- Initialize the current pointer variables
8067 l_current_serial := p_from_serial_number;
8068 l_current_number := l_from_number;
8069
8070 LOOP
8071 -- Serialized item packed LPN information are stored
8072 -- in the serial numbers table
8073 -- Also update the cost group field since it is not
8074 -- guaranteed that the serial number will have that value stamped
8075 -- if serial status is not resides in store (3), update lot and rev
8076 UPDATE mtl_serial_numbers
8077 SET lpn_id = p_lpn_id,
8078 last_update_date = SYSDATE,
8079 last_updated_by = fnd_global.user_id,
8080 last_txn_source_type_id = p_source_type_id,
8081 revision = DECODE(current_status, 3, revision, p_revision),
8082 lot_number = DECODE(current_status, 3, lot_number, p_lot_number)
8083 WHERE inventory_item_id = p_content_item_id
8084 AND serial_number = l_current_serial
8085 AND current_organization_id = p_organization_id;
8086
8087 EXIT WHEN l_current_serial = p_to_serial_number;
8088 /* Increment the current serial number */
8089 l_current_number := l_current_number + 1;
8090 l_padded_length := l_length - LENGTH(l_current_number);
8091
8092 IF l_prefix IS NOT NULL THEN
8093 l_current_serial := RPAD(l_prefix, l_padded_length, '0') || l_current_number;
8094 ELSE
8095 l_current_serial := Rpad('@',l_padded_length+1,'0') || l_current_number;
8096 l_current_serial := Substr(l_current_serial,2);
8097 END IF;
8098 -- Bug 2375043
8099 --l_current_serial := RPAD(l_prefix, l_padded_length, '0') || l_current_number;
8100 END LOOP;
8101
8102 UPDATE wms_lpn_contents
8103 SET last_update_date = SYSDATE,
8104 last_updated_by = fnd_global.user_id,
8105 serial_summary_entry = 1,
8106 source_type_id = p_source_type_id
8107 WHERE parent_lpn_id = p_lpn_id
8108 AND organization_id = p_organization_id
8109 AND inventory_item_id = p_content_item_id
8110 AND NVL(revision, G_NULL_CHAR) = NVL(p_revision, G_NULL_CHAR)
8111 AND NVL(lot_number, G_NULL_CHAR) = NVL(p_lot_number, G_NULL_CHAR);
8112
8113 UPDATE wms_license_plate_numbers
8114 SET last_update_date = SYSDATE,
8115 last_updated_by = fnd_global.user_id,
8116 lpn_context = LPN_CONTEXT_WIP
8117 WHERE lpn_id = p_lpn_id
8118 AND organization_id = p_organization_id;
8119 END IF;
8120 END IF;
8121 -- End of API body
8122
8123 -- Standard check of p_commit.
8124 IF fnd_api.to_boolean(p_commit) THEN
8125 COMMIT WORK;
8126 END IF;
8127
8128 -- Standard call to get message count and if count is 1,
8129 -- get message info.
8130 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
8131 EXCEPTION
8132 WHEN fnd_api.g_exc_error THEN
8133 ROLLBACK TO PACK_PREPACK_CONTAINER;
8134 x_return_status := fnd_api.g_ret_sts_error;
8135 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
8136 WHEN fnd_api.g_exc_unexpected_error THEN
8137 ROLLBACK TO PACK_PREPACK_CONTAINER;
8138 x_return_status := fnd_api.g_ret_sts_unexp_error;
8139 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
8140 WHEN OTHERS THEN
8141 ROLLBACK TO PACK_PREPACK_CONTAINER;
8142 x_return_status := fnd_api.g_ret_sts_unexp_error;
8143
8144 IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error) THEN
8145 fnd_msg_pub.add_exc_msg(g_pkg_name, l_api_name);
8146 END IF;
8147
8148 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
8149 END Pack_Prepack_Container;
8150
8151 -- ----------------------------------------------------------------------------------
8152 -- ----------------------------------------------------------------------------------
8153
8154 PROCEDURE Explode_LPN (
8155 p_api_version IN NUMBER
8156 , p_init_msg_list IN VARCHAR2 := fnd_api.g_false
8157 , p_commit IN VARCHAR2 := fnd_api.g_false
8158 , x_return_status OUT NOCOPY VARCHAR2
8159 , x_msg_count OUT NOCOPY NUMBER
8160 , x_msg_data OUT NOCOPY VARCHAR2
8161 , p_lpn_id IN NUMBER
8162 , p_explosion_level IN NUMBER := 0
8163 , x_content_tbl OUT NOCOPY WMS_CONTAINER_PUB.WMS_Container_Tbl_Type
8164 ) IS
8165 l_api_name CONSTANT VARCHAR2(30) := 'Explode_LPN';
8166 l_api_version CONSTANT NUMBER := 1.0;
8167 l_debug NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
8168 l_progress VARCHAR2(10) := '0';
8169 l_msgdata VARCHAR2(1000);
8170
8171 l_counter NUMBER := 1; -- Counter variable initialized to 1
8172 l_current_lpn NUMBER;
8173 l_temp_uom_code VARCHAR2(3);
8174 l_container_content_rec WMS_CONTAINER_PUB.WMS_Container_Content_Rec_Type;
8175
8176 CURSOR nested_lpn_cursor IS
8177 SELECT lpn_id, parent_lpn_id, inventory_item_id, organization_id,
8178 revision, lot_number, serial_number, cost_group_id
8179 FROM WMS_LICENSE_PLATE_NUMBERS
8180 WHERE Level <= p_explosion_level
8181 START WITH lpn_id = p_lpn_id
8182 CONNECT BY parent_lpn_id = PRIOR lpn_id;
8183
8184 CURSOR all_nested_lpn_cursor IS
8185 SELECT lpn_id, parent_lpn_id, inventory_item_id, organization_id,
8186 revision, lot_number, serial_number, cost_group_id
8187 FROM WMS_LICENSE_PLATE_NUMBERS
8188 START WITH lpn_id = p_lpn_id
8189 CONNECT BY parent_lpn_id = PRIOR lpn_id;
8190
8191 CURSOR lpn_contents_cursor IS
8192 SELECT parent_lpn_id, inventory_item_id, item_description,
8193 organization_id, revision, lot_number,
8194 serial_number, quantity, uom_code, cost_group_id,
8195 secondary_quantity, secondary_uom_code --INVCONV kkillams
8196 , primary_quantity --16445970
8197 FROM WMS_LPN_CONTENTS
8198 WHERE parent_lpn_id = l_current_lpn
8199 AND NVL(serial_summary_entry, 2) = 2;
8200
8201 CURSOR lpn_serial_contents_cursor IS
8202 SELECT inventory_item_id, current_organization_id, lpn_id,
8203 revision, lot_number, serial_number, cost_group_id
8204 FROM MTL_SERIAL_NUMBERS
8205 WHERE lpn_id = l_current_lpn
8206 -- bug 5103594, added the Order By clause
8207 ORDER BY inventory_item_id, revision, lot_number, serial_number;
8208
8209 BEGIN
8210 -- Standard Start of API savepoint
8211 SAVEPOINT EXPLODE_LPN;
8212
8213 IF (l_debug = 1) THEN
8214 mdebug(l_api_name || ' Entered ' || g_pkg_version, 1);
8215 mdebug('ver='||p_api_version||' initmsg='||p_init_msg_list||' commit='||p_commit||' lpn='||p_lpn_id||' explvl='||p_explosion_level, G_INFO);
8216 END IF;
8217
8218 -- Standard call to check for call compatibility.
8219 IF NOT fnd_api.compatible_api_call(l_api_version, p_api_version, l_api_name, g_pkg_name) THEN
8220 fnd_message.set_name('WMS', 'WMS_CONT_INCOMPATIBLE_API_CALL');
8221 fnd_msg_pub.ADD;
8222 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8223 END IF;
8224
8225 -- Initialize message list if p_init_msg_list is set to TRUE.
8226 IF FND_API.to_Boolean( p_init_msg_list ) THEN
8227 FND_MSG_PUB.initialize;
8228 END IF;
8229
8230 -- Initialize API return status to success
8231 x_return_status := FND_API.G_RET_STS_SUCCESS;
8232
8233 -- API body
8234 IF (p_explosion_level = 0) THEN
8235 /* Use the cursor that searches through all levels in the parent child relationship */
8236 FOR v_lpn_id IN all_nested_lpn_cursor LOOP
8237 l_current_lpn := v_lpn_id.lpn_id;
8238
8239 /* Store the lpn information also from license plate numbers table */
8240 l_container_content_rec.parent_lpn_id := v_lpn_id.parent_lpn_id;
8241 l_container_content_rec.content_lpn_id := v_lpn_id.lpn_id;
8242 l_container_content_rec.content_item_id := v_lpn_id.inventory_item_id;
8243 l_container_content_rec.content_description := NULL;
8244 l_container_content_rec.content_type := '2';
8245 l_container_content_rec.organization_id := v_lpn_id.organization_id;
8246 l_container_content_rec.revision := v_lpn_id.revision;
8247 l_container_content_rec.lot_number := v_lpn_id.lot_number;
8248 l_container_content_rec.serial_number := v_lpn_id.serial_number;
8249 l_container_content_rec.quantity := 1;
8250 l_container_content_rec.uom := NULL;
8251 l_container_content_rec.cost_group_id := v_lpn_id.cost_group_id;
8252
8253 x_content_tbl(l_counter) := l_container_content_rec;
8254 l_counter := l_counter + 1;
8255
8256 /* Store all the item information from the lpn contents table */
8257 FOR v_lpn_content IN lpn_contents_cursor LOOP
8258 l_container_content_rec.parent_lpn_id := v_lpn_content.parent_lpn_id;
8259 l_container_content_rec.content_lpn_id := NULL;
8260 l_container_content_rec.content_item_id := v_lpn_content.inventory_item_id;
8261 l_container_content_rec.content_description := v_lpn_content.item_description;
8262 IF (v_lpn_content.inventory_item_id IS NOT NULL) THEN
8263 l_container_content_rec.content_type := '1';
8264 ELSE
8265 l_container_content_rec.content_type := '3';
8266 END IF;
8267 l_container_content_rec.organization_id := v_lpn_content.organization_id;
8268 l_container_content_rec.revision := v_lpn_content.revision;
8269 l_container_content_rec.lot_number := v_lpn_content.lot_number;
8270 l_container_content_rec.serial_number := v_lpn_content.serial_number;
8271 l_container_content_rec.quantity := v_lpn_content.quantity;
8272 l_container_content_rec.uom := v_lpn_content.uom_code;
8273 l_container_content_rec.cost_group_id := v_lpn_content.cost_group_id;
8274 l_container_content_rec.sec_quantity := v_lpn_content.secondary_quantity; --INVCONV kkillams
8275 l_container_content_rec.sec_uom := v_lpn_content.secondary_uom_code; --INVCONV kkillams
8276 l_container_content_rec.primary_quantity := v_lpn_content.primary_quantity; --16445970
8277 x_content_tbl(l_counter) := l_container_content_rec;
8278 l_counter := l_counter + 1;
8279 END LOOP;
8280
8281 -- Store all the serialized item information from the serial
8282 -- numbers table
8283 FOR v_lpn_serial_content IN lpn_serial_contents_cursor LOOP
8284 /* Get the primary UOM for the serialized item */
8285 SELECT primary_uom_code
8286 INTO l_temp_uom_code
8287 FROM mtl_system_items
8288 WHERE inventory_item_id = v_lpn_serial_content.inventory_item_id
8289 AND organization_id = v_lpn_serial_content.current_organization_id;
8290
8291 l_container_content_rec.parent_lpn_id := v_lpn_serial_content.lpn_id;
8292 l_container_content_rec.content_lpn_id := NULL;
8293 l_container_content_rec.content_item_id := v_lpn_serial_content.inventory_item_id;
8294 l_container_content_rec.content_description := NULL;
8295 l_container_content_rec.content_type := '1';
8296 l_container_content_rec.organization_id := v_lpn_serial_content.current_organization_id;
8297 l_container_content_rec.revision := v_lpn_serial_content.revision;
8298 l_container_content_rec.lot_number := v_lpn_serial_content.lot_number;
8299 l_container_content_rec.serial_number := v_lpn_serial_content.serial_number;
8300 l_container_content_rec.quantity := 1;
8301 l_container_content_rec.primary_quantity := 1; --16683864
8302 l_container_content_rec.uom := l_temp_uom_code;
8303 l_container_content_rec.cost_group_id := v_lpn_serial_content.cost_group_id;
8304
8305 x_content_tbl(l_counter) := l_container_content_rec;
8306 l_counter := l_counter + 1;
8307 END LOOP;
8308 END LOOP;
8309 ELSE
8310 /* Use the cursor that searches only a specified number of levels */
8311 FOR v_lpn_id IN nested_lpn_cursor LOOP
8312 l_current_lpn := v_lpn_id.lpn_id;
8313
8314 /* Store the lpn information also from license plate numbers table */
8315 l_container_content_rec.parent_lpn_id := v_lpn_id.parent_lpn_id;
8316 l_container_content_rec.content_lpn_id := v_lpn_id.lpn_id;
8317 l_container_content_rec.content_item_id := v_lpn_id.inventory_item_id;
8318 l_container_content_rec.content_description := NULL;
8319 l_container_content_rec.content_type := '2';
8320 l_container_content_rec.organization_id := v_lpn_id.organization_id;
8321 l_container_content_rec.revision := v_lpn_id.revision;
8322 l_container_content_rec.lot_number := v_lpn_id.lot_number;
8323 l_container_content_rec.serial_number := v_lpn_id.serial_number;
8324 l_container_content_rec.quantity := 1;
8325 l_container_content_rec.uom := NULL;
8326 l_container_content_rec.cost_group_id := v_lpn_id.cost_group_id;
8327
8328 x_content_tbl(l_counter) := l_container_content_rec;
8329 l_counter := l_counter + 1;
8330
8331 /* Store all the item information from the lpn contents table */
8332 FOR v_lpn_content IN lpn_contents_cursor LOOP
8333 l_container_content_rec.parent_lpn_id := v_lpn_content.parent_lpn_id;
8334 l_container_content_rec.content_lpn_id := NULL;
8335 l_container_content_rec.content_item_id := v_lpn_content.inventory_item_id;
8336 l_container_content_rec.content_description := v_lpn_content.item_description;
8337 IF (v_lpn_content.inventory_item_id IS NOT NULL) THEN
8338 l_container_content_rec.content_type := '1';
8339 ELSE
8340 l_container_content_rec.content_type := '3';
8341 END IF;
8342 l_container_content_rec.organization_id := v_lpn_content.organization_id;
8343 l_container_content_rec.revision := v_lpn_content.revision;
8344 l_container_content_rec.lot_number := v_lpn_content.lot_number;
8345 l_container_content_rec.serial_number := v_lpn_content.serial_number;
8346 l_container_content_rec.quantity := v_lpn_content.quantity;
8347 l_container_content_rec.uom := v_lpn_content.uom_code;
8348 l_container_content_rec.cost_group_id := v_lpn_content.cost_group_id;
8349 l_container_content_rec.sec_quantity := v_lpn_content.secondary_quantity; --INVCONV kkillams
8350 l_container_content_rec.sec_uom := v_lpn_content.secondary_uom_code; --INVCONV kkillams
8351 l_container_content_rec.primary_quantity := v_lpn_content.primary_quantity; --16445970
8352
8353 x_content_tbl(l_counter) := l_container_content_rec;
8354 l_counter := l_counter + 1;
8355 END LOOP;
8356
8357 -- Store all the serialized item information from the serial
8358 -- numbers table
8359 FOR v_lpn_serial_content IN lpn_serial_contents_cursor LOOP
8360 /* Get the primary UOM for the serialized item */
8361 SELECT primary_uom_code
8362 INTO l_temp_uom_code
8363 FROM mtl_system_items
8364 WHERE inventory_item_id = v_lpn_serial_content.inventory_item_id
8365 AND organization_id = v_lpn_serial_content.current_organization_id;
8366
8367 l_container_content_rec.parent_lpn_id := v_lpn_serial_content.lpn_id;
8368 l_container_content_rec.content_lpn_id := NULL;
8369 l_container_content_rec.content_item_id := v_lpn_serial_content.inventory_item_id;
8370 l_container_content_rec.content_description := NULL;
8371 l_container_content_rec.content_type := '1';
8372 l_container_content_rec.organization_id := v_lpn_serial_content.current_organization_id;
8373 l_container_content_rec.revision := v_lpn_serial_content.revision;
8374 l_container_content_rec.lot_number := v_lpn_serial_content.lot_number;
8375 l_container_content_rec.serial_number := v_lpn_serial_content.serial_number;
8376 l_container_content_rec.quantity := 1;
8377 l_container_content_rec.primary_quantity := 1; --16683864
8378 l_container_content_rec.uom := l_temp_uom_code;
8379 l_container_content_rec.cost_group_id := v_lpn_serial_content.cost_group_id;
8380
8381 x_content_tbl(l_counter) := l_container_content_rec;
8382 l_counter := l_counter + 1;
8383 END LOOP;
8384 END LOOP;
8385 END IF;
8386 -- End of API body
8387
8388 IF (l_debug = 1) THEN
8389 mdebug(l_api_name || ' Exit x_content_tbl count=' ||x_content_tbl.last, G_INFO);
8390 END IF;
8391
8392 -- Standard check of p_commit.
8393 IF FND_API.To_Boolean( p_commit ) THEN
8394 COMMIT WORK;
8395 END IF;
8396
8397 -- Standard call to get message count and if count is 1,
8398 -- get message info.
8399 FND_MSG_PUB.Count_And_Get( p_count => x_msg_count, p_data => x_msg_data );
8400 EXCEPTION
8401 WHEN FND_API.G_EXC_ERROR THEN
8402 ROLLBACK TO EXPLODE_LPN;
8403 x_return_status := FND_API.G_RET_STS_ERROR;
8404 FND_MSG_PUB.Count_And_Get( p_count => x_msg_count, p_data => x_msg_data );
8405
8406 IF (l_debug = 1) THEN
8407 mdebug(l_api_name ||' Exc err prog='||g_progress||' SQL err: '|| SQLERRM(SQLCODE), 1);
8408 FOR i in 1..x_msg_count LOOP
8409 l_msgdata := substr(l_msgdata||' | '||substr(fnd_msg_pub.get(x_msg_count-i+1, 'F'), 0, 200),1,2000);
8410 END LOOP;
8411 mdebug('msg: '||l_msgdata, 1);
8412 END IF;
8413 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
8414 ROLLBACK TO EXPLODE_LPN;
8415 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
8416 FND_MSG_PUB.Count_And_Get( p_count => x_msg_count, p_data => x_msg_data );
8417
8418 IF (l_debug = 1) THEN
8419 mdebug(l_api_name ||' Unexp err prog='||g_progress||' SQL err: '|| SQLERRM(SQLCODE), 1);
8420 FOR i in 1..x_msg_count LOOP
8421 l_msgdata := substr(l_msgdata||' | '||substr(fnd_msg_pub.get(x_msg_count-i+1, 'F'), 0, 200),1,2000);
8422 END LOOP;
8423 mdebug('msg: '||l_msgdata, 1);
8424 END IF;
8425 WHEN OTHERS THEN
8426 ROLLBACK TO EXPLODE_LPN;
8427 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
8428
8429 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
8430 FND_MSG_PUB.Add_Exc_Msg(G_PKG_NAME, l_api_name);
8431 END IF;
8432
8433 FND_MSG_PUB.Count_And_Get( p_count => x_msg_count, p_data => x_msg_data );
8434
8435 IF (l_debug = 1) THEN
8436 mdebug(l_api_name ||' Others err prog='||g_progress||' SQL err: '|| SQLERRM(SQLCODE), 1);
8437 FOR i in 1..x_msg_count LOOP
8438 l_msgdata := substr(l_msgdata||' | '||substr(fnd_msg_pub.get(x_msg_count-i+1, 'F'), 0, 200),1,2000);
8439 END LOOP;
8440 mdebug('msg: '||l_msgdata, 1);
8441 END IF;
8442 END Explode_LPN;
8443
8444 -- ----------------------------------------------------------------------------------
8445 -- ----------------------------------------------------------------------------------
8446
8447 FUNCTION Validate_LPN (
8448 p_lpn IN OUT nocopy WMS_CONTAINER_PUB.LPN
8449 , p_lock IN NUMBER := 2
8450 ) RETURN NUMBER IS
8451 l_api_name CONSTANT VARCHAR2(30) := 'Validate_LPN';
8452 l_api_version CONSTANT NUMBER := 1.0;
8453 l_debug NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
8454 l_progress VARCHAR2(10) := '0';
8455
8456 BEGIN
8457 /* Check that either an lpn id or license plate number was given */
8458 IF ((p_lpn.lpn_id IS NULL OR p_lpn.lpn_id = FND_API.G_MISS_NUM) AND
8459 (p_lpn.license_plate_number IS NULL OR
8460 p_lpn.license_plate_number = FND_API.G_MISS_CHAR)) THEN
8461 RETURN F;
8462 END IF;
8463
8464 /* Search the table for an entry that matches the given input(s) */
8465 IF (p_lpn.license_plate_number IS NULL OR
8466 p_lpn.license_plate_number = FND_API.G_MISS_CHAR)
8467 THEN
8468 IF ( p_lock = 1 ) THEN
8469 SELECT *
8470 INTO p_lpn
8471 FROM WMS_LICENSE_PLATE_NUMBERS
8472 WHERE LPN_ID = p_lpn.lpn_id
8473 FOR UPDATE;
8474 ELSE
8475 SELECT *
8476 INTO p_lpn
8477 FROM WMS_LICENSE_PLATE_NUMBERS
8478 WHERE LPN_ID = p_lpn.lpn_id;
8479 END IF;
8480
8481 RETURN T;
8482 ELSIF (p_lpn.lpn_id IS NULL OR p_lpn.lpn_id = FND_API.G_MISS_NUM) THEN
8483 IF ( p_lock = 1 ) THEN
8484 SELECT *
8485 INTO p_lpn
8486 FROM WMS_LICENSE_PLATE_NUMBERS
8487 WHERE LICENSE_PLATE_NUMBER = p_lpn.license_plate_number
8488 FOR UPDATE;
8489 ELSE
8490 SELECT *
8491 INTO p_lpn
8492 FROM WMS_LICENSE_PLATE_NUMBERS
8493 WHERE LICENSE_PLATE_NUMBER = p_lpn.license_plate_number;
8494 END IF;
8495
8496 RETURN T;
8497 ELSE
8498 IF ( p_lock = 1 ) THEN
8499 SELECT *
8500 INTO p_lpn
8501 FROM WMS_LICENSE_PLATE_NUMBERS
8502 WHERE LPN_ID = p_lpn.lpn_id
8503 AND LICENSE_PLATE_NUMBER = p_lpn.license_plate_number
8504 FOR UPDATE;
8505 ELSE
8506 SELECT *
8507 INTO p_lpn
8508 FROM WMS_LICENSE_PLATE_NUMBERS
8509 WHERE LPN_ID = p_lpn.lpn_id
8510 AND LICENSE_PLATE_NUMBER = p_lpn.license_plate_number;
8511 END IF;
8512
8513 RETURN T;
8514 END IF;
8515 EXCEPTION
8516 WHEN NO_DATA_FOUND OR TOO_MANY_ROWS THEN
8517 RETURN F;
8518 WHEN OTHERS THEN
8519 RETURN F;
8520 END Validate_LPN;
8521
8522 -- ----------------------------------------------------------------------------------
8523 -- ----------------------------------------------------------------------------------
8524
8525 FUNCTION Validate_LPN (
8526 p_organization_id IN NUMBER
8527 , p_lpn_id IN NUMBER
8528 , p_validation_type IN VARCHAR2
8529 ) RETURN NUMBER IS
8530 l_api_name CONSTANT VARCHAR2(30) := 'Validate_LPN';
8531 l_api_version CONSTANT NUMBER := 1.0;
8532 l_debug NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
8533 l_progress VARCHAR2(10) := '0';
8534
8535 CURSOR Nested_LPN_Cursor IS
8536 SELECT lpn_id, lpn_context
8537 FROM wms_license_plate_numbers
8538 WHERE outermost_lpn_id = p_lpn_id;
8539
8540 lpn_rec Nested_LPN_Cursor%ROWTYPE;
8541 l_lpn_is_valid NUMBER := WMS_CONTAINER_PVT.F;
8542 l_parent_lpn_id NUMBER;
8543 BEGIN
8544 IF (l_debug = 1) THEN
8545 mdebug(l_api_name || ' Entered ' || g_pkg_version, 1);
8546 mdebug('orgid=' ||p_organization_id||' lpnid='||p_lpn_id||' type='||p_validation_type, G_MESSAGE);
8547 END IF;
8548
8549 IF ( p_validation_type = WMS_CONTAINER_PVT.G_RECONFIGURE_LPN OR
8550 p_validation_type = WMS_CONTAINER_PVT.G_NO_ONHAND_EXISTS ) THEN
8551 l_progress := '100';
8552 -- Check if the lpn_id entered is the outermost
8553 BEGIN
8554 SELECT parent_lpn_id INTO l_parent_lpn_id
8555 FROM wms_license_plate_numbers
8556 WHERE organization_id = p_organization_id
8557 AND lpn_id = p_lpn_id;
8558 EXCEPTION
8559 WHEN NO_DATA_FOUND THEN
8560 IF ( l_debug = 1 ) THEN
8561 mdebug('lpnid='||p_lpn_id|| ' does not exist', G_ERROR);
8562 END IF;
8563 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_LPN');
8564 fnd_msg_pub.ADD;
8565 RETURN WMS_CONTAINER_PVT.F;
8566 END;
8567
8568 l_progress := '110';
8569 IF ( l_parent_lpn_id IS NOT NULL ) THEN
8570 IF ( l_debug = 1 ) THEN
8571 mdebug('lpnid='||p_lpn_id|| ' is not the outermost LPN', G_ERROR);
8572 END IF;
8573 fnd_message.set_name('WMS', 'WMS_LPN_NOT_OUTERMOST');
8574 fnd_msg_pub.ADD;
8575 RETURN WMS_CONTAINER_PVT.F;
8576 END IF;
8577 END IF;
8578
8579 l_progress := '200';
8580 OPEN Nested_LPN_Cursor;
8581 FETCH Nested_LPN_Cursor INTO lpn_rec;
8582
8583 l_progress := '210';
8584 IF ( Nested_LPN_Cursor%FOUND ) THEN
8585 l_lpn_is_valid := WMS_CONTAINER_PVT.T;
8586 l_progress := '220';
8587 WHILE ( l_lpn_is_valid = WMS_CONTAINER_PVT.T AND Nested_LPN_Cursor%FOUND ) LOOP
8588 IF ( p_validation_type = WMS_CONTAINER_PVT.G_RECONFIGURE_LPN ) THEN
8589 -- Check if the lpn is on a reservation
8590 IF(lpn_rec.lpn_context <> 11) THEN --BUG13627343
8591 BEGIN
8592 SELECT WMS_CONTAINER_PVT.F
8593 INTO l_lpn_is_valid
8594 FROM mtl_reservations
8595 WHERE organization_id = p_organization_id
8596 AND lpn_id = lpn_rec.lpn_id
8597 AND rownum < 2;
8598 IF ( l_debug = 1 ) THEN
8599 mdebug('lpnid='||lpn_rec.lpn_id|| ' is reserved', G_ERROR);
8600 END IF;
8601 fnd_message.set_name('INV', 'INV_LPN_RESERVED');
8602 fnd_msg_pub.ADD;
8603 EXIT;
8604 EXCEPTION
8605 WHEN NO_DATA_FOUND THEN
8606 NULL; --no rows fround everything is okay
8607 END;
8608 ELSE --BUG13627343
8609 IF ( l_debug = 1 ) THEN
8610 mdebug('lpnid='||lpn_rec.lpn_id|| ' is staged', G_INFO);
8611 END IF;
8612 END IF;
8613
8614 -- check to see if there are pending transactions or the
8615 -- lpn has been allocatied
8616 BEGIN
8617 SELECT WMS_CONTAINER_PVT.F
8618 INTO l_lpn_is_valid
8619 FROM mtl_material_transactions_temp
8620 WHERE organization_id = p_organization_id
8621 AND ( ALLOCATED_LPN_ID = lpn_rec.lpn_id OR
8622 lpn_id = lpn_rec.lpn_id OR
8623 content_lpn_id = lpn_rec.lpn_id OR
8624 transfer_lpn_id = lpn_rec.lpn_id )
8625 AND rownum < 2;
8626 IF ( l_debug = 1 ) THEN
8627 mdebug('lpnid='||lpn_rec.lpn_id||' is in a pending MMTT transaction', G_ERROR);
8628 END IF;
8629 fnd_message.set_name('WMS', 'INV_PART_OF_PENDING_TXN');
8630 fnd_message.set_token('ENTITY1','INV_LPN');
8631 fnd_msg_pub.ADD;
8632 EXIT;
8633 EXCEPTION
8634 WHEN NO_DATA_FOUND THEN
8635 NULL; --no rows fround everything is okay
8636 END;
8637 END IF;
8638
8639 IF ( p_validation_type = WMS_CONTAINER_PVT.G_NO_ONHAND_EXISTS ) THEN
8640 -- check to see if there is any onhand quantity associated with lpn
8641 BEGIN
8642 SELECT WMS_CONTAINER_PVT.F
8643 INTO l_lpn_is_valid
8644 FROM mtl_onhand_quantities_detail
8645 WHERE organization_id = p_organization_id
8646 AND lpn_id = lpn_rec.lpn_id
8647 AND rownum < 2;
8648 IF ( l_debug = 1 ) THEN
8649 mdebug('lpnid='||lpn_rec.lpn_id||' has onhand associated with it', G_ERROR);
8650 END IF;
8651 fnd_message.set_name('WMS', 'WMS_CONT_NON_EMPTY_LPN');
8652 fnd_msg_pub.ADD;
8653 EXIT;
8654 EXCEPTION
8655 WHEN NO_DATA_FOUND THEN
8656 NULL; --no rows fround everything is okay
8657 END;
8658
8659 --check to see if there are any serial numbers associated with lpn
8660 BEGIN
8661 SELECT WMS_CONTAINER_PVT.F
8662 INTO l_lpn_is_valid
8663 FROM mtl_serial_numbers
8664 WHERE current_organization_id = p_organization_id
8665 AND lpn_id = lpn_rec.lpn_id
8666 AND rownum < 2;
8667 IF ( l_debug = 1 ) THEN
8668 mdebug('lpnid='||lpn_rec.lpn_id|| ' has serial numbers associated with it', G_ERROR);
8669 END IF;
8670 fnd_message.set_name('WMS', 'WMS_CONT_NON_EMPTY_LPN');
8671 fnd_msg_pub.ADD;
8672 EXIT;
8673 EXCEPTION
8674 WHEN NO_DATA_FOUND THEN
8675 NULL; --no rows fround everything is okay
8676 END;
8677 END IF;
8678 FETCH Nested_LPN_Cursor INTO lpn_rec;
8679 END LOOP;
8680 END IF;
8681 l_progress := '300';
8682 CLOSE Nested_LPN_Cursor;
8683
8684 IF ( l_debug = 1 ) THEN
8685 mdebug(l_api_name || ' Exited return='||l_lpn_is_valid, 1);
8686 END IF;
8687 RETURN l_lpn_is_valid;
8688 EXCEPTION
8689 WHEN OTHERS THEN
8690 IF (l_debug = 1) THEN
8691 mdebug(l_api_name ||' Error progress= '||l_progress||'SQL error: '|| SQLERRM(SQLCODE), G_ERROR);
8692 END IF;
8693 RETURN WMS_CONTAINER_PVT.F;
8694 END Validate_LPN;
8695
8696 -- ----------------------------------------------------------------------------------
8697 -- ----------------------------------------------------------------------------------
8698
8699 PROCEDURE Merge_Up_LPN (
8700 p_api_version IN NUMBER
8701 , p_init_msg_list IN VARCHAR2 := fnd_api.g_false
8702 , p_commit IN VARCHAR2 := fnd_api.g_false
8703 , x_return_status OUT NOCOPY VARCHAR2
8704 , x_msg_count OUT NOCOPY NUMBER
8705 , x_msg_data OUT NOCOPY VARCHAR2
8706 , p_organization_id IN NUMBER
8707 , p_outermost_lpn_id IN NUMBER
8708 ) IS
8709 l_api_name CONSTANT VARCHAR2(30) := 'Merge_Up_LPN';
8710 l_api_version CONSTANT NUMBER := 1.0;
8711 l_debug NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
8712 l_progress VARCHAR2(10) := '0';
8713
8714 l_contents_tbl WMS_CONTAINER_PUB.WMS_CONTAINER_TBL_TYPE;
8715 l_return_status NUMBER;
8716 l_trx_tmp_id NUMBER;
8717 l_ser_tmp_id NUMBER;
8718 l_trx_hdr_id NUMBER;
8719 l_converted_qty NUMBER;
8720 l_primary_uom VARCHAR2(3);
8721
8722 l_insert_item_rec BOOLEAN := FALSE;
8723 l_insert_lot_rec BOOLEAN := FALSE;
8724 l_insert_ser_rec BOOLEAN := FALSE;
8725
8726 -- Variables for call to Inv_Serial_Info
8727 l_range_is_done BOOLEAN := FALSE;
8728 l_serial_def_flag BOOLEAN;
8729 l_serial_prefix VARCHAR2(30);
8730 l_fm_serial VARCHAR2(30);
8731 l_to_serial VARCHAR2(30);
8732 l_serial_suffix NUMBER;
8733 l_serial_suffix_length NUMBER := 0;
8734 l_temp_num NUMBER;
8735 v_acct_period_id NUMBER;
8736 v_open_past_period BOOLEAN := FALSE;
8737 l_label_status VARCHAR2(100);
8738 l_label_return VARCHAR2(1);
8739
8740 CURSOR Nested_LPN_cur IS
8741 SELECT lpn_id, lpn_context, subinventory_code, locator_id, parent_lpn_id
8742 FROM wms_license_plate_numbers
8743 WHERE lpn_id <> p_outermost_lpn_id
8744 START WITH lpn_id = p_outermost_lpn_id
8745 CONNECT BY parent_lpn_id = PRIOR lpn_id;
8746
8747 CURSOR LPN_item_cur (p_parent_lpn_id NUMBER) IS
8748 SELECT inventory_item_id, quantity, uom_code, revision, lot_number, quantity lot_quantity,
8749 cost_group_id, serial_summary_entry
8750 ,secondary_quantity, secondary_uom_code --INVCONV kkillams
8751 FROM wms_lpn_contents
8752 WHERE organization_id = p_organization_id
8753 AND parent_lpn_id = p_parent_lpn_id
8754 ORDER BY inventory_item_id, revision, cost_group_id, lot_number;
8755
8756 l_crnt_item_rec LPN_item_cur%ROWTYPE;
8757 l_next_item_rec LPN_item_cur%ROWTYPE;
8758
8759 CURSOR LPN_serial_cur (p_lpn_id NUMBER, p_item_id NUMBER, p_revision VARCHAR2, p_lot_number VARCHAR2) IS
8760 SELECT serial_number
8761 FROM mtl_serial_numbers
8762 WHERE current_organization_id = p_organization_id
8763 AND inventory_item_id = p_item_id
8764 AND lpn_id = p_lpn_id
8765 AND NVL(revision, '@') = NVL(p_revision, '@')
8766 AND NVL(lot_number, '@') = NVL(p_lot_number, '@');
8767
8768 l_crnt_ser_rec LPN_serial_cur%ROWTYPE;
8769
8770 BEGIN
8771 -- Standard Start of API savepoint
8772 SAVEPOINT MERGE_UP_LPN;
8773
8774 -- Initialize message list if p_init_msg_list is set to TRUE.
8775 IF fnd_api.to_boolean(p_init_msg_list) THEN
8776 fnd_msg_pub.initialize;
8777 END IF;
8778
8779 -- Initialize API return status to success
8780 x_return_status := FND_API.G_RET_STS_SUCCESS;
8781
8782 IF (l_debug = 1) THEN
8783 mdebug(l_api_name || ' Entered ' || g_pkg_version, 1);
8784 mdebug('orgid=' ||p_organization_id||' lpnid='||p_outermost_lpn_id, G_MESSAGE);
8785 END IF;
8786
8787 -- get the account period ID
8788 invttmtx.tdatechk(p_organization_id, SYSDATE, v_acct_period_id, v_open_past_period);
8789
8790 SELECT mtl_material_transactions_s.nextval
8791 INTO l_trx_hdr_id
8792 FROM DUAL;
8793
8794 FOR Nested_LPN_rec IN Nested_LPN_cur LOOP
8795 -- Insert an 'UNPACK' transaction of child LPN from parent LPN into
8796 -- MTL_MATERIAL_TRANSACTIONS_TEMP using standard MMTT insert API
8797 l_return_status := INV_TRX_UTIL_PUB.INSERT_LINE_TRX (
8798 p_trx_hdr_id => l_trx_hdr_id
8799 , p_item_id => -1
8800 , p_org_id => p_organization_id
8801 , p_subinv_code => Nested_LPN_rec.subinventory_code
8802 , p_locator_id => Nested_LPN_rec.locator_id
8803 , p_trx_src_type_id => INV_GLOBALS.G_SourceType_Inventory
8804 , p_trx_action_id => INV_GLOBALS.G_Action_ContainerUnPack
8805 , p_trx_type_id => INV_GLOBALS.G_TYPE_CONTAINER_UNPACK
8806 , p_trx_qty => 1
8807 , p_pri_qty => 1
8808 , p_uom => 'Ea'
8809 , p_date => SYSDATE
8810 , p_user_id => fnd_global.user_id
8811 , p_from_lpn_id => Nested_LPN_rec.parent_lpn_id
8812 , p_cnt_lpn_id => Nested_LPN_rec.lpn_id
8813 , x_trx_tmp_id => l_trx_tmp_id
8814 , x_proc_msg => x_msg_data );
8815 IF ( l_return_status <> 0) THEN
8816 IF (l_debug = 1) THEN
8817 mdebug('Insert_Line_Trx failed :'||x_msg_data, 1);
8818 END IF;
8819 RAISE FND_API.G_EXC_ERROR;
8820 END IF;
8821
8822 IF (l_debug = 1) THEN
8823 mdebug('Inserted unpack hdrid='||l_trx_hdr_id||' tempid='||l_trx_tmp_id||' lpn='||Nested_LPN_rec.lpn_id||' parlpn='|| Nested_LPN_rec.parent_lpn_id, 4);
8824 END IF;
8825
8826 OPEN LPN_item_cur( Nested_LPN_rec.lpn_id );
8827 FETCH LPN_item_cur INTO l_next_item_rec;
8828
8829 IF ( LPN_item_cur%FOUND ) THEN
8830 -- Create new trx temp id
8831 SELECT mtl_material_transactions_s.nextval
8832 INTO l_trx_tmp_id
8833 FROM DUAL;
8834
8835 -- Find the primary uom
8836 SELECT primary_uom_code
8837 INTO l_primary_uom
8838 FROM mtl_system_items
8839 WHERE organization_id = p_organization_id
8840 AND inventory_item_id = l_next_item_rec.inventory_item_id;
8841
8842 LOOP
8843 l_crnt_item_rec := l_next_item_rec;
8844 EXIT WHEN l_crnt_item_rec.inventory_item_id IS NULL;
8845 FETCH LPN_item_cur INTO l_next_item_rec;
8846
8847 IF ( LPN_item_cur%NOTFOUND ) THEN
8848 l_next_item_rec.inventory_item_id := NULL;
8849 l_next_item_rec.revision := NULL;
8850 END IF;
8851
8852 IF (l_debug = 1) THEN
8853 mdebug('critm='||l_crnt_item_rec.inventory_item_id||' rv='||l_crnt_item_rec.revision||' lot='||l_crnt_item_rec.lot_number||' qty='||l_crnt_item_rec.quantity||' uom='||l_crnt_item_rec.uom_code||' lqty='||l_crnt_item_rec.lot_quantity);
8854 mdebug('sec uom='||l_crnt_item_rec.secondary_uom_code||' sec qty='||l_crnt_item_rec.secondary_quantity, 4);
8855 mdebug('nxitm='||l_next_item_rec.inventory_item_id||' rv='||l_next_item_rec.revision||' lot='||l_next_item_rec.lot_number||' qty='||l_next_item_rec.quantity||' uom='||l_next_item_rec.uom_code||' lqty='||l_next_item_rec.lot_quantity);
8856 mdebug('sec uom='||l_next_item_rec.secondary_uom_code||' sec qty='||l_next_item_rec.secondary_quantity, 4);
8857 END IF;
8858
8859 IF ( l_crnt_item_rec.inventory_item_id = l_next_item_rec.inventory_item_id AND
8860 NVL(l_crnt_item_rec.revision, '@') = NVL(l_next_item_rec.revision, '@') AND
8861 NVL(l_crnt_item_rec.cost_group_id, -9) = NVL(l_next_item_rec.cost_group_id, -9) ) THEN
8862 -- Will be adding quantities, make sure the uoms are the same
8863 IF ( l_crnt_item_rec.uom_code <> l_next_item_rec.uom_code ) THEN
8864 l_next_item_rec.quantity := Round(Convert_UOM(l_crnt_item_rec.inventory_item_id, l_next_item_rec.quantity, l_next_item_rec.uom_code, l_next_item_rec.uom_code), 5);
8865 l_next_item_rec.uom_code := l_crnt_item_rec.uom_code;
8866 END IF;
8867 -- These to records can go into the same MMTT line add the quantities
8868 l_next_item_rec.quantity := l_next_item_rec.quantity + l_crnt_item_rec.quantity;
8869
8870 IF ( l_crnt_item_rec.lot_number = l_next_item_rec.lot_number ) THEN
8871 l_next_item_rec.lot_quantity := l_next_item_rec.quantity + l_crnt_item_rec.lot_quantity;
8872 ELSIF ( l_crnt_item_rec.lot_number IS NOT NULL ) THEN
8873 l_insert_lot_rec := TRUE;
8874 END IF;
8875 ELSE -- Different item/rev need to make MMTT
8876 l_insert_item_rec := TRUE;
8877 -- If lot controlled, will need to insert lot record too
8878 IF ( l_crnt_item_rec.lot_number IS NOT NULL ) THEN
8879 l_insert_lot_rec := TRUE;
8880 ELSIF ( l_crnt_item_rec.serial_summary_entry = 1 ) THEN
8881 l_insert_ser_rec := TRUE;
8882 l_ser_tmp_id := l_trx_tmp_id;
8883 END IF;
8884 END IF;
8885
8886 IF ( l_insert_lot_rec ) THEN
8887 IF ( l_crnt_item_rec.uom_code <> l_primary_uom ) THEN
8888 l_converted_qty := Round(Convert_UOM(l_crnt_item_rec.inventory_item_id, l_crnt_item_rec.quantity, l_crnt_item_rec.uom_code, l_primary_uom), 5); --13591755 added for GRUPO
8889 ELSE
8890 l_converted_qty := l_crnt_item_rec.lot_quantity;
8891 END IF;
8892 -- Insert record into MTL_TRANSACTIONS_LOTS_TEMP
8893 l_return_status := INV_TRX_UTIL_PUB.Insert_Lot_Trx(
8894 p_trx_tmp_id => l_trx_tmp_id
8895 , p_user_id => fnd_global.user_id
8896 , p_lot_number => l_crnt_item_rec.lot_number
8897 , p_trx_qty => l_crnt_item_rec.lot_quantity
8898 , p_pri_qty => l_converted_qty
8899 , p_secondary_qty => l_crnt_item_rec.secondary_quantity --INVCONV kkillams
8900 , p_secondary_uom => l_crnt_item_rec.secondary_uom_code --INVCONV kkillams
8901 , x_ser_trx_id => l_ser_tmp_id
8902 , x_proc_msg => x_msg_data );
8903 IF ( l_return_status <> 0 ) THEN
8904 IF (l_debug = 1) THEN
8905 mdebug('Insert_Lot_Trx failed :'||x_msg_data, 1);
8906 END IF;
8907 RAISE FND_API.G_EXC_ERROR;
8908 END IF;
8909
8910 IF (l_debug = 1) THEN
8911 mdebug('Inserted lot tempid='||l_trx_tmp_id||' lot='||l_crnt_item_rec.lot_number||' qty='||l_crnt_item_rec.lot_quantity||' stmpid='||l_ser_tmp_id, 4);
8912 END IF;
8913
8914 -- May need to insert serials if item is serial controlled
8915 IF ( l_crnt_item_rec.serial_summary_entry = 1 ) THEN
8916 l_insert_ser_rec := TRUE;
8917 END IF;
8918 l_insert_lot_rec := FALSE;
8919 END IF;
8920
8921 -- Insert record into MTL_SERIAL_NUMBERS_TEMP
8922 IF ( l_insert_ser_rec ) THEN
8923 OPEN LPN_serial_cur(Nested_LPN_rec.lpn_id, l_crnt_item_rec.inventory_item_id,
8924 l_crnt_item_rec.revision, l_crnt_item_rec.lot_number);
8925 FETCH LPN_serial_cur INTO l_crnt_ser_rec;
8926 l_fm_serial:= l_crnt_ser_rec.serial_number;
8927 l_to_serial:= l_crnt_ser_rec.serial_number;
8928 LOOP
8929 FETCH LPN_serial_cur INTO l_crnt_ser_rec;
8930 IF (l_debug = 1) THEN
8931 mdebug('current serial='||l_crnt_ser_rec.serial_number, 4);
8932 END IF;
8933
8934 -- Algorithm to try and flatten serial ranges as much as possible
8935 IF ( LPN_serial_cur%FOUND AND l_serial_prefix IS NULL ) THEN
8936 l_serial_def_flag := MTL_SERIAL_CHECK.Inv_Serial_Info(
8937 l_fm_serial, l_to_serial, l_serial_prefix,
8938 l_temp_num, l_serial_suffix, l_serial_suffix, l_return_status);
8939 IF ( l_return_status <> 0 ) THEN
8940 IF (l_debug = 1) THEN
8941 mdebug('Inv_Serial_Info failed', 1);
8942 END IF;
8943 FND_MESSAGE.SET_NAME('WMS', 'WMS_CONT_INVALID_SER');
8944 FND_MSG_PUB.ADD;
8945 RAISE FND_API.G_EXC_ERROR;
8946 END IF;
8947 -- calculate the length of the serial number suffix
8948 l_serial_suffix_length := LENGTH(l_fm_serial) - LENGTH(l_serial_prefix);
8949 l_serial_suffix := l_serial_suffix + 1;
8950
8951 IF (l_debug = 1) THEN
8952 mdebug('New prefix='||l_serial_prefix||' suffix='||l_serial_suffix||' sfxlgth='||l_serial_suffix_length, 1);
8953 END IF;
8954 END IF;
8955
8956 IF ( l_crnt_ser_rec.serial_number = l_serial_prefix||LPAD(TO_CHAR(l_serial_suffix), l_serial_suffix_length, '0') ) THEN
8957 -- The serials are contiguous, set l_to_serial to new serial
8958 l_to_serial := l_crnt_ser_rec.serial_number;
8959 l_serial_suffix := l_serial_suffix + 1;
8960 ELSE
8961 l_range_is_done := TRUE;
8962 END IF;
8963
8964 mdebug('expected next sn='||l_serial_prefix||LPAD(TO_CHAR(l_serial_suffix), l_serial_suffix_length, '0'), 1);
8965
8966 IF ( l_range_is_done OR LPN_serial_cur%NOTFOUND ) THEN
8967 IF (l_debug = 1) THEN
8968 mdebug('Insert ser tempid='||l_ser_tmp_id||' fmsn='||l_fm_serial||' tosn='||l_to_serial, 4);
8969 END IF;
8970 -- Range finished or last serial processed, insert serial with API and reset from serial
8971 l_return_status := INV_TRX_UTIL_PUB.Insert_Ser_Trx (
8972 p_trx_tmp_id => l_ser_tmp_id
8973 , p_user_id => fnd_global.user_id
8974 , p_fm_ser_num => l_fm_serial
8975 , p_to_ser_num => l_to_serial
8976 , x_proc_msg => x_msg_data );
8977 IF ( l_return_status <> 0 ) THEN
8978 IF (l_debug = 1) THEN
8979 mdebug('Insert_Ser_Trx failed :'||x_msg_data, 1);
8980 END IF;
8981 RAISE FND_API.G_EXC_ERROR;
8982 END IF;
8983 -- reset serial variables
8984 l_fm_serial:= l_crnt_ser_rec.serial_number;
8985 l_to_serial:= l_crnt_ser_rec.serial_number;
8986 l_serial_prefix := NULL;
8987 l_range_is_done := FALSE;
8988 END IF;
8989
8990 EXIT WHEN LPN_serial_cur%NOTFOUND;
8991 END LOOP;
8992 CLOSE LPN_serial_cur;
8993 -- Reset serial variables
8994 l_insert_ser_rec := FALSE;
8995 END IF;
8996
8997 IF ( l_insert_item_rec ) THEN
8998 IF (l_debug = 1) THEN
8999 mdebug('Insert split tmpid='||l_trx_tmp_id||' plpn='||Nested_LPN_rec.parent_lpn_id||' itm='||l_crnt_item_rec.inventory_item_id||' rev='||l_crnt_item_rec.revision||' qty='||l_crnt_item_rec.quantity||' cg='||l_crnt_item_rec.cost_group_id, 4);
9000 END IF;
9001
9002 IF ( l_crnt_item_rec.uom_code <> l_primary_uom ) THEN
9003 l_converted_qty := Round(Convert_UOM(l_crnt_item_rec.inventory_item_id, l_crnt_item_rec.quantity, l_crnt_item_rec.uom_code, l_primary_uom), 5); --13591755 added for GRUPO
9004 ELSE
9005 l_converted_qty := l_crnt_item_rec.quantity;
9006 END IF;
9007
9008 -- MTL_MATERIAL_TRANSACTIONS_TEMP cannot use API because
9009 -- need to use sepecific transaction temp id
9010 INSERT INTO mtl_material_transactions_temp (
9011 transaction_header_id
9012 , transaction_temp_id
9013 , process_flag
9014 , posting_flag --Added for the bug 15900513
9015 , creation_date
9016 , created_by
9017 , last_update_date
9018 , last_updated_by
9019 , last_update_login
9020 , transaction_date
9021 , organization_id
9022 , subinventory_code
9023 , locator_id
9024 , inventory_item_id
9025 , revision
9026 , cost_group_id
9027 , transaction_source_type_id
9028 , transaction_action_id
9029 , transaction_type_id
9030 , transaction_quantity
9031 , primary_quantity
9032 , transaction_uom
9033 , lpn_id
9034 , transfer_lpn_id
9035 , acct_period_id
9036 , secondary_transaction_quantity --INCONV kkillams
9037 , secondary_uom_code --INCONV kkillamsb
9038 ) VALUES (
9039 l_trx_hdr_id
9040 , l_trx_tmp_id
9041 , 'Y'
9042 ,'Y' --Added for the bug 15900513
9043 , SYSDATE
9044 , fnd_global.user_id
9045 , SYSDATE
9046 , fnd_global.user_id
9047 , fnd_global.user_id
9048 , SYSDATE
9049 , p_organization_id
9050 , Nested_LPN_rec.subinventory_code
9051 , Nested_LPN_rec.locator_id
9052 , l_crnt_item_rec.inventory_item_id
9053 , l_crnt_item_rec.revision
9054 , l_crnt_item_rec.cost_group_id
9055 , INV_GLOBALS.G_SourceType_Inventory
9056 , INV_GLOBALS.G_Action_ContainerSplit
9057 , INV_GLOBALS.G_TYPE_CONTAINER_SPLIT
9058 , l_crnt_item_rec.quantity
9059 , l_converted_qty
9060 , l_crnt_item_rec.uom_code
9061 , Nested_LPN_rec.lpn_id
9062 , p_outermost_lpn_id
9063 , v_acct_period_id
9064 , l_crnt_item_rec.secondary_quantity --INCONV kkillams
9065 , l_crnt_item_rec.secondary_uom_code --INCONV kkillams
9066 );
9067
9068 -- Done with this item/revision/costgroup combo need new trx temp id
9069 SELECT mtl_material_transactions_s.nextval
9070 INTO l_trx_tmp_id
9071 FROM DUAL;
9072
9073 -- If next record is for a new item need to find the primary uom
9074 IF ( l_crnt_item_rec.inventory_item_id <> l_next_item_rec.inventory_item_id ) THEN
9075 SELECT primary_uom_code
9076 INTO l_primary_uom
9077 FROM mtl_system_items
9078 WHERE organization_id = p_organization_id
9079 AND inventory_item_id = l_next_item_rec.inventory_item_id; --bug12692678 change from l_crnt_item_rec to l_next_item_rec
9080 END IF;
9081 l_insert_item_rec := FALSE;
9082 END IF;
9083 END LOOP;
9084 END IF;
9085 CLOSE LPN_item_cur;
9086 END LOOP; -- Nested_LPN_cur
9087
9088 IF (l_debug = 1) THEN
9089 mdebug('Call to TM hdrid='||l_trx_hdr_id, 4);
9090 END IF;
9091 l_return_status := INV_LPN_TRX_PUB.PROCESS_LPN_TRX (
9092 p_trx_hdr_id => l_trx_hdr_id
9093 , x_proc_msg => x_msg_data
9094 , p_proc_mode => 1
9095 , p_atomic => fnd_api.g_true );
9096 IF ( l_return_status <> 0 ) THEN
9097 IF (l_debug = 1) THEN
9098 mdebug('PROCESS_LPN_TRX Failed msg: '||x_msg_data, 1);
9099 END IF;
9100 RAISE fnd_api.g_exc_error;
9101 END IF;
9102
9103 INV_LABEL.PRINT_LABEL_MANUAL_WRAP(
9104 x_return_status => l_label_return
9105 , x_msg_count => x_msg_count
9106 , x_msg_data => x_msg_data
9107 , x_label_status => l_label_status
9108 , p_business_flow_code => 36
9109 , p_lpn_id => p_outermost_lpn_id );
9110
9111 IF ( l_debug = 1 ) THEN
9112 mdebug('Called INV_LABEL.PRINT_LABEL, return_status='||l_label_return||' label stat='||l_label_status, 1);
9113 END IF;
9114
9115 -- Standard check of p_commit.
9116 IF FND_API.To_Boolean( p_commit ) THEN
9117 COMMIT WORK;
9118 END IF;
9119
9120 FND_MSG_PUB.Count_And_Get( p_count => x_msg_count, p_data => x_msg_data );
9121 EXCEPTION
9122 WHEN OTHERS THEN
9123 IF (l_debug = 1) THEN
9124 mdebug(l_api_name ||' Error l_progress=' || l_progress, 1);
9125 IF ( SQLCODE IS NOT NULL ) THEN
9126 mdebug('SQL error: ' || SQLERRM(SQLCODE), 1);
9127 END IF;
9128 END IF;
9129
9130 ROLLBACK TO MERGE_UP_LPN;
9131 x_return_status := fnd_api.g_ret_sts_error;
9132 fnd_message.set_name('WMS', 'WMS_API_FAILURE');
9133 fnd_msg_pub.ADD;
9134 FND_MSG_PUB.Count_And_Get(p_count => x_msg_count, p_data => x_msg_data);
9135 END Merge_Up_LPN;
9136
9137 -- ----------------------------------------------------------------------------------
9138 -- ----------------------------------------------------------------------------------
9139
9140 PROCEDURE Break_Down_LPN(
9141 p_api_version IN NUMBER
9142 , p_init_msg_list IN VARCHAR2 := fnd_api.g_false
9143 , p_commit IN VARCHAR2 := fnd_api.g_false
9144 , x_return_status OUT NOCOPY VARCHAR2
9145 , x_msg_count OUT NOCOPY NUMBER
9146 , x_msg_data OUT NOCOPY VARCHAR2
9147 , p_organization_id IN NUMBER
9148 , p_outermost_lpn_id IN NUMBER
9149 ) IS
9150 l_api_name CONSTANT VARCHAR2(30) := 'Break_Down_LPN';
9151 l_api_version CONSTANT NUMBER := 1.0;
9152 l_debug NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
9153 l_progress VARCHAR2(10) := '0';
9154
9155 CURSOR nested_lpn_cursor IS
9156 SELECT rowid, lpn_id, parent_lpn_id, subinventory_code, locator_id
9157 FROM WMS_LICENSE_PLATE_NUMBERS
9158 WHERE lpn_id <> p_outermost_lpn_id
9159 START WITH lpn_id = p_outermost_lpn_id
9160 CONNECT BY parent_lpn_id = PRIOR lpn_id;
9161
9162 l_return_status NUMBER;
9163 l_trx_tmp_id NUMBER;
9164 l_trx_hdr_id NUMBER;
9165 l_label_count NUMBER := 1;
9166 l_label_status VARCHAR2(100);
9167 l_label_return VARCHAR2(1);
9168 l_input_param_rec_tbl INV_LABEL.input_parameter_rec_type;
9169
9170 BEGIN
9171 -- Standard Start of API savepoint
9172 SAVEPOINT BREAK_DOWN_LPN;
9173
9174 -- Standard call to check for call compatibility.
9175 IF NOT fnd_api.compatible_api_call(l_api_version, p_api_version, l_api_name, g_pkg_name) THEN
9176 fnd_message.set_name('WMS', 'WMS_CONT_INCOMPATIBLE_API_CALL');
9177 fnd_msg_pub.ADD;
9178 RAISE fnd_api.g_exc_unexpected_error;
9179 END IF;
9180
9181 -- Initialize message list if p_init_msg_list is set to TRUE.
9182 IF fnd_api.to_boolean(p_init_msg_list) THEN
9183 fnd_msg_pub.initialize;
9184 END IF;
9185
9186 -- Initialize API return status to success
9187 x_return_status := FND_API.G_RET_STS_SUCCESS;
9188
9189 IF (l_debug = 1) THEN
9190 mdebug(l_api_name || ' Entered ' || g_pkg_version, 1);
9191 mdebug('orgid=' ||p_organization_id||' lpnid='||p_outermost_lpn_id, G_MESSAGE);
9192 END IF;
9193
9194 SELECT mtl_material_transactions_s.nextval
9195 INTO l_trx_hdr_id
9196 FROM DUAL;
9197
9198 --Every nested lpn will need to be deconsolidated from the outermost lpn,
9199 FOR lpn_rec IN nested_lpn_cursor LOOP
9200 -- Insert an 'UNPACK' transaction of child LPN from parent LPN into
9201 -- MTL_MATERIAL_TRANSACTIONS_TEMP using standard MMTT insert API
9202 l_return_status := INV_TRX_UTIL_PUB.INSERT_LINE_TRX (
9203 p_trx_hdr_id => l_trx_hdr_id
9204 , p_item_id => -1
9205 , p_org_id => p_organization_id
9206 , p_subinv_code => lpn_rec.subinventory_code
9207 , p_locator_id => lpn_rec.locator_id
9208 , p_trx_src_type_id => INV_GLOBALS.G_SourceType_Inventory
9209 , p_trx_action_id => INV_GLOBALS.G_Action_ContainerUnPack
9210 , p_trx_type_id => INV_GLOBALS.G_TYPE_CONTAINER_UNPACK
9211 , p_trx_qty => 1
9212 , p_pri_qty => 1
9213 , p_uom => 'Ea'
9214 , p_date => SYSDATE
9215 , p_user_id => fnd_global.user_id
9216 , p_from_lpn_id => lpn_rec.parent_lpn_id
9217 , p_cnt_lpn_id => lpn_rec.lpn_id
9218 , x_trx_tmp_id => l_trx_tmp_id
9219 , x_proc_msg => x_msg_data );
9220 IF (l_debug = 1) THEN
9221 mdebug('Inserted unpack tempid='||l_trx_tmp_id||' lpn='||lpn_rec.lpn_id||' parlpn='|| lpn_rec.parent_lpn_id, 4);
9222 END IF;
9223 -- Add entry for this lpn to print label
9224 l_input_param_rec_tbl(l_label_count).lpn_id := lpn_rec.lpn_id;
9225 l_label_count := l_label_count + 1;
9226 END LOOP;
9227
9228 IF (l_debug = 1) THEN
9229 mdebug('Call to TM hdrid='||l_trx_hdr_id, 4);
9230 END IF;
9231 l_return_status := INV_LPN_TRX_PUB.PROCESS_LPN_TRX (
9232 p_trx_hdr_id => l_trx_hdr_id
9233 , x_proc_msg => x_msg_data
9234 , p_proc_mode => 1
9235 , p_atomic => fnd_api.g_true );
9236 IF ( l_return_status <> 0 ) THEN
9237 IF (l_debug = 1) THEN
9238 mdebug('PROCESS_LPN_TRX Failed msg: '||x_msg_data, 1);
9239 END IF;
9240 RAISE fnd_api.g_exc_error;
9241 END IF;
9242
9243 -- Add entry for this lpn to print label for outermost lpn
9244 l_input_param_rec_tbl(l_label_count).lpn_id := p_outermost_lpn_id;
9245
9246 INV_LABEL.PRINT_LABEL (
9247 x_return_status => l_label_return
9248 , x_msg_count => x_msg_count
9249 , x_msg_data => x_msg_data
9250 , x_label_status => l_label_status
9251 , p_api_version => 1.0
9252 , p_print_mode => 2
9253 , p_business_flow_code => 36
9254 , p_input_param_rec => l_input_param_rec_tbl ) ;
9255
9256 IF ( l_debug = 1 ) THEN
9257 mdebug('Called INV_LABEL.PRINT_LABEL, return_status='||l_label_return||' label stat='||l_label_status, 1);
9258 END IF;
9259
9260 -- Standard check of p_commit.
9261 IF FND_API.To_Boolean( p_commit ) THEN
9262 COMMIT WORK;
9263 END IF;
9264
9265 FND_MSG_PUB.Count_And_Get( p_count => x_msg_count, p_data => x_msg_data );
9266 EXCEPTION
9267 WHEN OTHERS THEN
9268 IF (l_debug = 1) THEN
9269 mdebug(l_api_name ||' Error l_progress=' || l_progress, 1);
9270 IF ( SQLCODE IS NOT NULL ) THEN
9271 mdebug('SQL error: ' || SQLERRM(SQLCODE), 1);
9272 END IF;
9273 END IF;
9274
9275 ROLLBACK TO BREAK_DOWN_LPN;
9276 x_return_status := fnd_api.g_ret_sts_error;
9277 fnd_message.set_name('WMS', 'WMS_API_FAILURE');
9278 fnd_msg_pub.ADD;
9279 FND_MSG_PUB.Count_And_Get(p_count => x_msg_count, p_data => x_msg_data);
9280 END Break_Down_LPN;
9281
9282 -- ----------------------------------------------------------------------------------
9283 -- ----------------------------------------------------------------------------------
9284
9285 PROCEDURE Initialize_LPN (
9286 p_api_version IN NUMBER
9287 , p_init_msg_list IN VARCHAR2 := fnd_api.g_false
9288 , p_commit IN VARCHAR2 := fnd_api.g_false
9289 , x_return_status OUT NOCOPY VARCHAR2
9290 , x_msg_count OUT NOCOPY NUMBER
9291 , x_msg_data OUT NOCOPY VARCHAR2
9292 , p_organization_id IN NUMBER
9293 , p_outermost_lpn_id IN NUMBER
9294 )IS
9295 l_api_name CONSTANT VARCHAR2(30) := 'Initialize_LPNs';
9296 l_api_version CONSTANT NUMBER := 1.0;
9297 l_debug NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
9298 l_progress VARCHAR2(10) := '0';
9299
9300 CURSOR nested_lpn_cursor IS
9301 SELECT rowid, lpn_id
9302 FROM wms_license_plate_numbers
9303 WHERE organization_id = p_organization_id
9304 AND outermost_lpn_id = p_outermost_lpn_id;
9305
9306 BEGIN
9307 -- Standard Start of API savepoint
9308 SAVEPOINT INITIALIZE_LPN;
9309
9310 -- Standard call to check for call compatibility.
9311 IF NOT fnd_api.compatible_api_call(l_api_version, p_api_version, l_api_name, g_pkg_name) THEN
9312 fnd_message.set_name('WMS', 'WMS_CONT_INCOMPATIBLE_API_CALL');
9313 fnd_msg_pub.ADD;
9314 RAISE fnd_api.g_exc_unexpected_error;
9315 END IF;
9316
9317 -- Initialize message list if p_init_msg_list is set to TRUE.
9318 IF fnd_api.to_boolean(p_init_msg_list) THEN
9319 fnd_msg_pub.initialize;
9320 END IF;
9321
9322 -- Initialize API return status to success
9323 x_return_status := FND_API.G_RET_STS_SUCCESS;
9324
9325 IF (l_debug = 1) THEN
9326 mdebug(l_api_name || ' Entered ' || g_pkg_version, 1);
9327 mdebug('orgid=' ||p_organization_id||' lpnid='||p_outermost_lpn_id, G_MESSAGE);
9328 END IF;
9329
9330 FOR lpn_rec IN nested_lpn_cursor LOOP
9331 IF (l_debug = 1) THEN
9332 mdebug('Initializing LPN with lpnid='||lpn_rec.lpn_id, G_MESSAGE);
9333 END IF;
9334
9335 -- Remove all contents from WLC
9336 DELETE FROM wms_lpn_contents
9337 WHERE parent_lpn_id = lpn_rec.lpn_id;
9338
9339 -- Reset lpn properties to pregenerated
9340 UPDATE wms_license_plate_numbers
9341 SET lpn_context = LPN_CONTEXT_PREGENERATED
9342 , subinventory_code = NULL
9343 , locator_id = NULL
9344 , parent_lpn_id = NULL
9345 , outermost_lpn_id = lpn_id
9346 , content_volume = NULL
9347 , content_volume_uom_code = NULL
9348 , gross_weight = tare_weight
9349 , gross_weight_uom_code = tare_weight_uom_code
9350 , last_update_date = SYSDATE
9351 , last_updated_by = fnd_global.user_id
9352 WHERE rowid = lpn_rec.rowid;
9353 END LOOP;
9354
9355 -- Standard check of p_commit.
9356 IF FND_API.To_Boolean( p_commit ) THEN
9357 COMMIT WORK;
9358 END IF;
9359
9360 FND_MSG_PUB.Count_And_Get( p_count => x_msg_count, p_data => x_msg_data );
9361 EXCEPTION
9362 WHEN OTHERS THEN
9363 IF (l_debug = 1) THEN
9364 mdebug(l_api_name ||' Error l_progress=' || l_progress, 1);
9365 IF ( SQLCODE IS NOT NULL ) THEN
9366 mdebug('SQL error: ' || SQLERRM(SQLCODE), 1);
9367 END IF;
9368 END IF;
9369
9370 ROLLBACK TO INITIALIZE_LPN;
9371 x_return_status := fnd_api.g_ret_sts_error;
9372 FND_MSG_PUB.Count_And_Get(p_count => x_msg_count, p_data => x_msg_data);
9373 END Initialize_LPN;
9374
9375 -- ----------------------------------------------------------------------------------
9376 -- ----------------------------------------------------------------------------------
9377
9378 PROCEDURE plan_delivery(p_lpn_id IN NUMBER,
9379 x_return_status OUT nocopy VARCHAR2,
9380 x_msg_data OUT nocopy VARCHAR2,
9381 x_msg_count OUT nocopy NUMBER) IS
9382
9383 l_action_prms wsh_interface_ext_grp.del_action_parameters_rectype;
9384 l_delivery_id_tab wsh_util_core.id_tab_type;
9385 l_delivery_out_rec wsh_interface_ext_grp.del_action_out_rec_type;
9386 l_delivery_id NUMBER;
9387
9388 l_return_status VARCHAR2(1);
9389 l_msg_count NUMBER;
9390 l_msg_data VARCHAR2(2000);
9391 l_debug NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
9392 BEGIN
9393
9394 SELECT wda.delivery_id
9395 INTO l_delivery_id
9396 FROM wsh_delivery_details_ob_grp_v wdd,
9397 wsh_delivery_assignments wda
9398 WHERE wdd.lpn_id IN (SELECT lpn_id FROM wms_license_plate_numbers
9399 WHERE outermost_lpn_id = (SELECT outermost_lpn_id
9400 FROM wms_license_plate_numbers
9401 WHERE lpn_id = p_lpn_id)
9402 AND lpn_context = 11)
9403 AND wdd.released_status = 'X' -- For LPN reuse ER : 6845650
9404 AND wda.parent_delivery_detail_id = wdd.delivery_detail_id
9405 AND ROWNUM = 1;
9406
9407 IF l_delivery_id IS NOT NULL THEN
9408 l_action_prms.caller := 'WMS_DLMG';
9409 l_action_prms.event := wsh_interface_ext_grp.g_start_of_packing;
9410 l_action_prms.action_code := 'ADJUST-PLANNED-FLAG';
9411
9412 l_delivery_id_tab(1) := l_delivery_id;
9413
9414 wsh_interface_ext_grp.delivery_action
9415 (p_api_version_number => 1.0,
9416 p_init_msg_list => fnd_api.g_false,
9417 p_commit => fnd_api.g_false,
9418 p_action_prms => l_action_prms,
9419 p_delivery_id_tab => l_delivery_id_tab,
9420 x_delivery_out_rec => l_delivery_out_rec,
9421 x_return_status => l_return_status,
9422 x_msg_count => l_msg_count,
9423 x_msg_data => l_msg_data);
9424
9425 IF x_return_status = 'E' THEN
9426 RAISE fnd_api.g_exc_error;
9427 ELSIF x_return_status = 'U' THEN
9428 RAISE fnd_api.g_exc_unexpected_error;
9429 END IF;
9430 END IF;
9431
9432 x_return_status := 'S';
9433
9434 EXCEPTION
9435 WHEN fnd_api.g_exc_error THEN
9436 x_return_status := 'E';
9437 mdebug('Plan Delivery: Error: E', 1);
9438 WHEN fnd_api.g_exc_unexpected_error THEN
9439 x_return_status := 'U';
9440 mdebug('Plan Delivery: Error: U', 1);
9441 WHEN OTHERS THEN
9442 x_return_status := 'U';
9443 IF (l_debug = 1) THEN
9444 mdebug('Plan Delivery: Error: ' || Sqlerrm, 1);
9445 END IF;
9446 END plan_delivery;
9447
9448
9449 -------------------------------------------------
9450 -- Added for LSP Project, bug 9087971
9451 -- NAME
9452 -- PROCEDURE get_item_from_lpn
9453 -------------------------------------------------
9454 -- Purpose
9455 -- Following procedure will get the concatenated item segments from the given LPN.
9456 --
9457 -- Input Parameters
9458 -- p_org Organization ID
9459 -- p_lpn_id LPN ID
9460 -- p_lpn_context Context of the LPN
9461 --
9462 -- Output Parameters
9463 -- x_item Item name
9464
9465 PROCEDURE get_item_from_lpn
9466 (
9467 p_org IN NUMBER,
9468 p_lpn_id IN NUMBER,
9469 p_lpn_context IN NUMBER,
9470 x_item OUT NOCOPY VARCHAR2 )
9471 IS
9472 l_api_name CONSTANT VARCHAR2(30) := 'get_item_from_lpn';
9473 l_debug NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
9474 l_lpn_context NUMBER;
9475 l_concatenated_segments mtl_system_items_b_kfv.concatenated_segments%TYPE;
9476 BEGIN
9477
9478 IF (l_debug = 1) THEN
9479 mdebug(' p_org : ' || p_org || ' p_lpn_id : ' || p_lpn_id || ' p_lpn_context : ' || p_lpn_context, G_INFO);
9480 END IF;
9481
9482 if p_lpn_context is null THEN
9483 SELECT lpn_context INTO l_lpn_context
9484 FROM wms_license_plate_numbers
9485 WHERE lpn_id = p_lpn_id
9486 AND organization_id = p_org;
9487 else
9488 l_lpn_context := p_lpn_context;
9489 end if;
9490
9491
9492 IF l_lpn_context = 8 THEN
9493 SELECT msikfv.concatenated_segments
9494 INTO l_concatenated_segments
9495 FROM mtl_material_transactions_temp mmtt,
9496 mtl_system_items_b_kfv msikfv
9497 WHERE transfer_lpn_id IN
9498 (SELECT lpn_id
9499 FROM wms_license_plate_numbers
9500 START WITH lpn_id = p_lpn_id
9501 CONNECT BY PRIOR lpn_id = parent_lpn_id
9502 )
9503 AND mmtt.inventory_item_id = msikfv.inventory_item_id
9504 AND mmtt.organization_id = msikfv.organization_id
9505 AND msikfv.organization_id = p_org
9506 AND rownum = 1;
9507 ELSE
9508 SELECT msikfv.concatenated_segments
9509 INTO l_concatenated_segments
9510 FROM WMS_LPN_CONTENTS wlc,
9511 mtl_system_items_b_kfv msikfv
9512 WHERE wlc.parent_lpn_id IN
9513 (SELECT lpn_id
9514 FROM wms_license_plate_numbers
9515 START WITH lpn_id = p_lpn_id
9516 CONNECT BY PRIOR lpn_id = parent_lpn_id
9517 )
9518 AND wlc.inventory_item_id = msikfv.inventory_item_id
9519 AND wlc.organization_id = msikfv.organization_id
9520 AND msikfv.organization_id = p_org
9521 AND rownum = 1;
9522 END IF;
9523
9524 x_item := l_concatenated_segments;
9525
9526 IF (l_debug = 1) THEN
9527 mdebug(' l_concatenated_segments : ' || l_concatenated_segments, G_INFO);
9528 END IF;
9529
9530 EXCEPTION
9531 WHEN OTHERS THEN
9532 IF (l_debug = 1) THEN
9533 mdebug(l_api_name ||' Error SQL error: '|| SQLERRM(SQLCODE), G_ERROR);
9534 END IF;
9535 END get_item_from_lpn;
9536
9537 -- 16284527 add
9538 FUNCTION get_lock_handle( p_type_name IN VARCHAR2 ) RETURN VARCHAR2
9539 IS
9540 PRAGMA AUTONOMOUS_TRANSACTION;
9541 l_lock_handle VARCHAR2(128);
9542 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
9543
9544 BEGIN
9545 IF (l_debug = 1) THEN
9546 mdebug('get lock handler ' ||p_type_name,4);
9547 END IF;
9548 dbms_lock.allocate_unique( lockname => p_type_name ,lockhandle => l_lock_handle);
9549 RETURN l_lock_handle;
9550 END get_lock_handle;
9551
9552 PROCEDURE lock_org_lpn
9553 (
9554 p_lpn_id IN NUMBER,
9555 p_org_id IN NUMBER,
9556 x_err_code OUT NOCOPY NUMBER,
9557 x_err_msg OUT NOCOPY VARCHAR2
9558 ) IS
9559 l_lock_handle VARCHAR2(128);
9560 L_OUTER_LPN_ID NUMBER;
9561 l_type_name varchar2(100);
9562 l_lpn_name varchar2(100);
9563 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
9564
9565 BEGIN
9566
9567 SELECT OUTERMOST_LPN_ID, LICENSE_PLATE_NUMBER
9568 INTO L_OUTER_LPN_ID, L_LPN_NAME
9569 FROM WMS_LICENSE_PLATE_NUMBERS
9570 WHERE LPN_ID = P_LPN_ID;
9571
9572 L_TYPE_NAME := 'ORGLPNLCK####'||L_OUTER_LPN_ID || '####' || P_ORG_ID;
9573
9574 IF(l_debug = 1) THEN
9575 mdebug('lock_org_lpn:||L_TYPE_NAME : '||L_TYPE_NAME,4);
9576 END IF;
9577
9578 l_lock_handle :=get_lock_handle(L_TYPE_NAME);
9579
9580 IF(l_debug = 1) THEN
9581 mdebug('Got the lockhandle : '||l_lock_handle,4);
9582 END IF;
9583
9584 x_err_code := dbms_lock.request(lockhandle => l_lock_handle ,
9585 lockmode => dbms_lock.x_mode ,
9586 timeout => 1 ,
9587 release_on_commit => TRUE);
9588
9589 IF(l_debug = 1) THEN
9590 mdebug('after dbms_lock.request execution completed x_err_code'||x_err_code,4);
9591 END IF;
9592
9593 IF (x_err_code = 0 ) THEN
9594 g_lock_handle := l_lock_handle;
9595 ELSE
9596 fnd_msg_pub.Initialize;
9597 fnd_message.set_name('WSH', 'WSH_TP_F_NO_LOCK_LPN_CONTENTS');
9598 FND_MESSAGE.SET_TOKEN('CONTAINER_NAME', l_lpn_name);
9599 fnd_msg_pub.ADD;
9600 END IF;
9601
9602 IF(l_debug = 1) THEN
9603 mdebug('before exiting lock_org_lpn x_err_code' ||x_err_code,4);
9604 END IF;
9605 EXCEPTION
9606
9607 WHEN no_data_found THEN
9608 -- need not raise any error for this. Just return -1 so that the lock would not be taken.
9609 x_err_code := -1;
9610
9611 WHEN OTHERS THEN
9612 x_err_code := SQLCODE;
9613 x_err_msg := SUBSTR('Error in lock_org_lpn: '|| SQLERRM, 1, 2000);
9614 IF(l_debug = 1) THEN
9615 mdebug('OTHERS x_err_code'||x_err_code,1);
9616 mdebug('OTHERS x_err_msg'||x_err_msg,1);
9617 END IF;
9618 END lock_org_lpn;
9619
9620 -- 16284527 add
9621
9622
9623 -- End of package
9624 END WMS_CONTAINER_PVT;