[Home] [Help]
PACKAGE BODY: APPS.GMI_PICK_RELEASE_PVT
Source
1 PACKAGE BODY GMI_Pick_Release_PVT AS
2 /* $Header: GMIVPKRB.pls 120.0 2005/05/25 16:00:43 appldev noship $ */
3 /* +=========================================================================+
4 | Copyright (c) 2000 Oracle Corporation |
5 | TVP, Reading, England |
6 | All rights reserved |
7 +=========================================================================+
8 | FILENAME |
9 | GMIVPKRB.pls |
10 | |
11 | DESCRIPTION |
12 | This package contains public procedures relating to GMI |
13 | Pick Release process. |
14 | |
15 | - Process_Line |
16 | |
17 | |
18 | HISTORY |
19 | 03-May-2000 odaboval Created |
20 | |
21 +=========================================================================+
22 API Name : GMI_Pick_Release_PVT
23 Type : Global
24 -
25 Pre-reqs : N/A
26 Parameters: Per function
27
28 Current Vers : 1.0
29 */
30
31
32 G_PKG_NAME CONSTANT VARCHAR2(30) := 'GMI_Pick_Release_PVT';
33
34 PROCEDURE Process_Line
35 (
36 p_api_version IN NUMBER
37 , p_validation_flag IN VARCHAR2 DEFAULT FND_API.G_TRUE
38 , p_commit IN VARCHAR2 DEFAULT FND_API.G_FALSE
39 , p_mo_hdr_rec IN GMI_Move_Order_Global.mo_hdr_rec
40 , p_mo_line_rec IN GMI_Move_Order_Global.mo_line_rec
41 , p_grouping_rule_id IN NUMBER
42 , p_print_mode IN VARCHAR2
43 , p_allow_partial_pick IN VARCHAR2 DEFAULT FND_API.G_TRUE
44 , p_allow_delete IN VARCHAR2 DEFAULT NULL
45 , x_detail_rec_count OUT NOCOPY NUMBER
46 , x_return_status OUT NOCOPY VARCHAR2
47 , x_msg_count OUT NOCOPY NUMBER
48 , x_msg_data OUT NOCOPY VARCHAR2
49 ) IS
50
51 /* Define local variables */
52 l_api_version CONSTANT NUMBER := 1.0;
53 l_api_name CONSTANT VARCHAR2(30) := 'Process_Line';
54
55 l_qry_rsv_rec inv_reservation_global.mtl_reservation_rec_type;
56
57 l_pick_slip_mode VARCHAR2(1);
58
59 l_mo_line_rec GMI_Move_Order_Global.mo_line_rec;
60 l_demand_info wsh_inv_delivery_details_v%ROWTYPE;
61 l_reservable_type NUMBER;
62 l_sub_reservable_type NUMBER;
63 l_demand_source_type NUMBER;
64 l_mso_header_id NUMBER;
65 l_quantity_detailed NUMBER;
66 l_allocated_transactions NUMBER;
67
68 l_api_error_code NUMBER;
69 l_api_error_msg VARCHAR2(100);
70
71 /* Define local cursors */
72 CURSOR c_mtl_items( org_id IN NUMBER
73 , item_id IN NUMBER) IS
74 SELECT reservable_type
75 FROM mtl_system_items
76 WHERE inventory_item_id = item_id
77 AND organization_id = org_id;
78
79 CURSOR c_second_inventory( org_id IN NUMBER
80 , subinv_code IN VARCHAR2) IS
81 SELECT reservable_type
82 FROM mtl_secondary_inventories
83 WHERE organization_id = org_id
84 AND secondary_inventory_name = subinv_code;
85
86 CURSOR c_transaction_type( txn_type_id IN NUMBER) IS
87 SELECT t.transaction_source_type_id
88 FROM mtl_transaction_types t, mtl_txn_source_types st
89 WHERE t.transaction_source_type_id = st.transaction_source_type_id
90 AND t.transaction_type_id = txn_type_id;
91 CURSOR c_get_delivery_detail IS
92 SELECT delivery_detail_id
93 , requested_quantity
94 , requested_quantity2
95 , source_line_id
96 FROM wsh_delivery_details
97 WHERE move_order_line_id = p_mo_line_rec.line_id
98 AND released_status = 'S';
99
100 CURSOR c_get_trans_for_del(source_line_id NUMBER
101 , delivery_detail_id NUMBER) IS
102 SELECT nvl(sum(abs(trans_qty)), 0), nvl(sum(abs(trans_qty2)),0)
103 FROM ic_tran_pnd
104 WHERE line_id = source_line_id
105 AND line_detail_id = delivery_detail_id
106 AND delete_mark = 0 ;
107
108
109 CURSOR c_get_trans_id IS
110 SELECT trans_id, line_id
111 FROM ic_tran_pnd
112 WHERE line_id = p_mo_line_rec.txn_source_line_id
113 AND line_detail_id IN (
114 SELECT delivery_detail_id
115 FROM wsh_delivery_details
116 WHERE move_order_line_id = p_mo_line_rec.line_id
117 AND source_line_id = p_mo_line_rec.txn_source_line_id
118 AND released_status IN ('R', 'S'))
119 AND doc_type = 'OMSO'
120 AND delete_mark = 0
121 AND staged_ind = 0
122 AND completed_ind = 0
123 AND (lot_id >0 OR location <> 'l_IC$DEFAULT_LOCT');
124
125 ic_tran_tbl_row c_get_trans_id%ROWTYPE;
126
127
128 l_del_trans_qty NUMBER;
129 l_del_trans_qty2 NUMBER;
130 l_trans_id NUMBER;
131 l_tran_rec GMI_TRANS_ENGINE_PUB.ictran_rec;
132 l_tran_row IC_TRAN_PND%ROWTYPE;
133 l_p_allow_delete VARCHAR2(3);
134
135 l_IC$DEFAULT_LOCT VARCHAR2(255)DEFAULT NVL(FND_PROFILE.VALUE('IC$DEFAULT_LOCT'),' ') ;
136 l_GML$DEL_ALC_BEFORE_AUTO VARCHAR2(255) DEFAULT NVL(FND_PROFILE.VALUE('GML$DEL_ALC_BEFORE_AUTO'),' ') ;
137
138
139 BEGIN
140 gmi_reservation_util.println('Value of p_grouping_rule_idp_grouping_rule_id in process_line is '||p_grouping_rule_id);
141 GMI_Reservation_Util.PrintLn('Entering_GMI_Pick_Release_PVT.');
142
143 SAVEPOINT Process_Line_PVT;
144 /* Standard Call to check for call compatibility */
145 IF NOT fnd_api.Compatible_API_Call(l_api_version
146 , p_api_version
147 , l_api_name
148 , G_PKG_NAME) THEN
149 RAISE FND_API.g_exc_unexpected_error;
150 END IF;
151
152 /* Initialize API return status to success */
153 x_return_status := FND_API.g_ret_sts_success;
154
155 --==================================================================
156
157 l_p_allow_delete := p_allow_delete;
158 GMI_Reservation_Util.PrintLn('l_p_allow_delete = ' || l_p_allow_delete);
159
160 GMI_Reservation_Util.PrintLn('l_IC$DEFAULT_LOCT = ' || l_IC$DEFAULT_LOCT) ;
161 GMI_Reservation_Util.PrintLn('l_GML$DEL_ALC_BEFORE_AUTO = ' || l_GML$DEL_ALC_BEFORE_AUTO) ;
162
163 IF (UPPER(l_p_allow_delete) = 'YES')
164 OR (l_p_allow_delete IS NULL AND UPPER(l_GML$DEL_ALC_BEFORE_AUTO) = 'YES')
165 THEN
166
167 OPEN c_get_trans_id;
168 FETCH c_get_trans_id INTO ic_tran_tbl_row;
169 IF (c_get_trans_id%FOUND) THEN
170 WHILE c_get_trans_id%FOUND LOOP
171
172 l_tran_rec.trans_id := ic_tran_tbl_row.trans_id;
173
174 GMI_Reservation_Util.PrintLn('l_tran_rec.trans_id = ' || l_tran_rec.trans_id);
175
176 GMI_TRANS_ENGINE_PUB.delete_pending_transaction
177 ( 1
178 , FND_API.G_FALSE
179 , FND_API.G_FALSE
180 , FND_API.G_VALID_LEVEL_FULL
181 , l_tran_rec
182 , l_tran_row
183 , x_return_status
184 , x_msg_count
185 , x_msg_data
186 );
187
188 GMI_Reservation_Util.PrintLn('return from DELETE PENDING TRANS x_return_status = ' || x_return_status);
189
190 IF x_return_status <> FND_API.G_RET_STS_SUCCESS
191 THEN
192 GMI_RESERVATION_UTIL.PrintLn('Error returned by Delete_Pending_Transaction');
193 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
194 END IF;
195 FETCH c_get_trans_id INTO ic_tran_tbl_row;
196 END LOOP;
197 CLOSE c_get_trans_id;
198 END IF;
199 END IF ;
200 GMI_Reservation_Util.PrintLn('outside of lizloop');
201
202 --==================================================================
203
204
205 /* Return success immediately if the line is already fully detailed */
206 IF NVL(p_mo_line_rec.quantity_detailed, 0) >= NVL(p_mo_line_rec.quantity, 0) THEN
207 GMI_Reservation_Util.PrintLn('Exiting_GMI_Pick_Release_PVT. fully detailed no Error');
208 /* odab removed it in order to get the x_detail_rec_count */
209 /* odab return; */
210 /* NEED TO put it back ( for performance) */
211 END IF;
212
213 /* Override the printing mode to deferred if allow partial pick is false. */
214 /* Otherwise set it based on the parameter passed in. */
215 -- Bug 1717145, 2-Apr-2001, odaboval, set the print_mode
216 IF (p_allow_partial_pick = FND_API.G_FALSE)
217 THEN
218 l_pick_slip_mode := 'E';
219 ELSE
220 l_pick_slip_mode := p_print_mode;
221 END IF;
222
223 GMI_Reservation_Util.PrintLn('Entering_GMI_Pick_Release_PVT. Before Set_Org_Client_Info, ps_mode='||l_pick_slip_mode);
224 inv_project.set_org_client_info(x_return_status, p_mo_line_Rec.organization_id);
225
226 GMI_Reservation_Util.PrintLn('GMI_Pick_Release_PVT. Before Get_Delivery_Details');
227 /* Determine the demand source and delivery information for the given line. */
228 GMI_Pick_Release_Util.Get_Delivery_Details(
229 p_mo_line_id => p_mo_line_rec.line_id
230 , x_inv_delivery_details => l_demand_info
231 , x_return_status => x_return_status
232 , x_msg_count => x_msg_count
233 , x_msg_data => x_msg_data);
234
235 GMI_Reservation_Util.PrintLn('GMI_Pick_Release_PVT. To find : Item='||p_mo_line_rec.inventory_item_id||', org_id='||p_mo_line_rec.organization_id);
236 OPEN c_mtl_items( p_mo_line_rec.organization_id
237 , p_mo_line_rec.inventory_item_id);
238 FETCH c_mtl_items
239 INTO l_reservable_type;
240
241 IF ( c_mtl_items%NOTFOUND )
242 THEN
243 FND_MESSAGE.SET_NAME('GMI','INV_ITEM_NOTFOUND');
244 FND_MESSAGE.Set_Token('ORGANIZATION_ID', p_mo_line_rec.organization_id);
245 FND_MESSAGE.Set_Token('INVENTORY_ITEM_ID', p_mo_line_rec.inventory_item_id);
246 FND_MSG_PUB.Add;
247 RAISE FND_API.G_EXC_ERROR;
248 END IF;
249 CLOSE c_mtl_items;
250
251 GMI_Reservation_Util.PrintLn('GMI_Pick_Release_PVT. To find : SecondInventory, from_subInv_code='||p_mo_line_rec.from_subinventory_code);
252
253 IF ( p_mo_line_rec.from_subinventory_code is not NULL )
254 THEN
255 OPEN c_second_inventory( p_mo_line_rec.organization_id
256 , p_mo_line_rec.from_subinventory_code);
257 FETCH c_second_inventory
258 INTO l_sub_reservable_type;
259
260 IF ( c_second_inventory%NOTFOUND )
261 THEN
262 FND_MESSAGE.SET_NAME('GMI','INV_DELIV_INFO_MISSING');
263 FND_MESSAGE.Set_Token('ORGANIZATION_ID', p_mo_line_rec.organization_id);
264 FND_MESSAGE.Set_Token('FROM_SUBINVENTORY_CODE', p_mo_line_rec.from_subinventory_code);
265 FND_MSG_PUB.Add;
266 RAISE FND_API.G_EXC_ERROR;
267 END IF;
268 CLOSE c_second_inventory;
269 END IF;
270
271 GMI_Reservation_Util.PrintLn('GMI_Pick_Release_PVT. To find : TransactionType, TransactionType='||p_mo_line_rec.transaction_type_id);
272
273 OPEN c_transaction_type(p_mo_line_rec.transaction_type_id);
274 FETCH c_transaction_type
275 INTO l_demand_source_type;
276
277 IF ( c_transaction_type%NOTFOUND )
278 THEN
279 FND_MESSAGE.set_name('GMI', 'INV_INT_TXN_CODE');
280 FND_MESSAGE.Set_Token('TRANSACTION_TYPE_ID', p_mo_line_rec.transaction_type_id);
281 FND_MSG_PUB.add;
282 RAISE FND_API.G_EXC_ERROR;
283 END IF;
284 CLOSE c_transaction_type;
285
286 GMI_Reservation_Util.PrintLn('GMI_Pick_Release_PVT. Transaction Type found!');
287
288 /* Compute the MTL_SALES_ORDERS header ID to use when dealing with reservations.*/
289 l_mso_header_id := INV_SALESORDER.GET_SALESORDER_FOR_OEHEADER(l_demand_info.oe_header_id);
290 IF ( l_mso_header_id IS NULL ) THEN
291 FND_MESSAGE.SET_NAME('GMI','INV_COULD_NOT_GET_MSO_HEADER');
292 FND_MESSAGE.Set_Token('OE_HEADER_ID', l_demand_info.oe_header_id);
293 FND_MSG_PUB.Add;
294 RAISE FND_API.G_EXC_ERROR;
295 END IF;
296
297 /* find out the corresponding delivery detail id to fill in ic_tran_pnd */
298 /* this could result more than 1 delivery, need to do a loop for the deliveries */
299
300 GMI_Reservation_Util.PrintLn('p_mo_line_rec.unit_number is ' || p_mo_line_Rec.unit_number);
301 /* Retrieve reservation information for that demand source */
302 /* only if the item is reservable */
303 IF( l_reservable_type = 1 AND nvl(l_sub_reservable_type, 1) = 1 )
304 THEN
305 FOR delivery IN c_get_delivery_detail LOOP
306 GMI_Reservation_Util.PrintLn('(opm_dbg) Realloc reservation info for demand source :');
307 l_qry_rsv_rec.organization_id := p_mo_line_rec.organization_id;
308 l_qry_rsv_rec.inventory_item_id := p_mo_line_rec.inventory_item_id;
309 l_qry_rsv_rec.demand_source_type_id := l_demand_source_type;
310 l_qry_rsv_rec.demand_source_header_id := l_mso_header_id;
311 l_qry_rsv_rec.demand_source_line_id := l_demand_info.oe_line_id;
312 l_qry_rsv_rec.supply_source_type_id := FND_API.G_MISS_NUM;
313 l_qry_rsv_rec.reservation_uom_code := p_mo_line_rec.uom_code;
314 /* B1800659 */
315 --l_qry_rsv_rec.reservation_quantity := nvl(p_mo_line_rec.quantity,0)
316 -- - nvl(p_mo_line_rec.quantity_delivered,0);
317 --l_qry_rsv_rec.attribute2 := p_mo_line_rec.secondary_quantity;
318 -- - nvl(p_mo_line_rec.secondary_quantity_delivered,0);
319 l_qry_rsv_rec.requirement_date := p_mo_line_rec.date_required;
320 /* using mo line quanity may not be correct if there are more than 1 delivery
321 for the mo line */
322 OPEN c_get_trans_for_del(delivery.source_line_id, delivery.delivery_detail_id);
323 Fetch c_get_trans_for_del INTO l_del_trans_qty,l_del_trans_qty2;
324 Close c_get_trans_for_del;
325
326 l_qry_rsv_rec.reservation_quantity := delivery.requested_quantity
327 - l_del_trans_qty;
328 l_qry_rsv_rec.attribute1 := p_mo_line_rec.qc_grade;
329 l_qry_rsv_rec.attribute2 := delivery.requested_quantity2
330 - l_del_trans_qty2;
331 l_qry_rsv_rec.attribute3 := p_mo_line_rec.secondary_uom_code;
332 l_qry_rsv_rec.attribute4 := delivery.delivery_detail_id;
333 IF l_qry_rsv_rec.reservation_quantity < 0 THEN
334 l_qry_rsv_rec.reservation_quantity := 0;
335 l_qry_rsv_rec.attribute2 := 0;
336 END IF;
337
338 GMI_Reservation_Util.PrintLn('(opm_dbg) organization_id='||l_qry_rsv_rec.organization_id);
339 GMI_Reservation_Util.PrintLn('(opm_dbg) inv_item_id='||l_qry_rsv_rec.inventory_item_id);
340 GMI_Reservation_Util.PrintLn('(opm_dbg) source_header_id='||l_qry_rsv_rec.demand_source_header_id);
341 GMI_Reservation_Util.PrintLn('(opm_dbg) source_line_id='||l_qry_rsv_rec.demand_source_line_id);
342 GMI_Reservation_Util.PrintLn('(opm_dbg) Res_UOM_code='||l_qry_rsv_rec.reservation_uom_code);
343 GMI_Reservation_Util.PrintLn('(opm_dbg) Shedule_ship_date='||l_qry_rsv_rec.requirement_date);
344
345 GMI_Reservation_Util.PrintLn('UOM_CODE='||p_mo_line_rec.uom_code);
346 GMI_Reservation_Util.PrintLn('SO line qty='||p_mo_line_rec.quantity);
347 GMI_Reservation_Util.PrintLn(' attribute1='||l_qry_rsv_rec.attribute1);
348 GMI_Reservation_Util.PrintLn(' attribute2='||l_qry_rsv_rec.attribute2);
349 GMI_Reservation_Util.PrintLn(' attribute3='||l_qry_rsv_rec.attribute3);
350 GMI_Reservation_Util.PrintLn(' attribute4='||l_qry_rsv_rec.attribute4);
351
352 /* l_qry_rsv_rec.ship_ready_flag := 2; -- only records which are not ship ready */
353
354 GMI_Reservation_Util.Reallocate(
355 p_query_input => l_qry_rsv_rec
356 , x_allocated_trans => l_allocated_transactions
357 , x_allocated_qty => l_quantity_detailed
358 , x_return_status => x_return_status
359 , x_msg_count => x_msg_count
360 , x_msg_data => x_msg_data);
361
362 /* Return an error if the Reallocation call failed */
363 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
364 ROLLBACK TO Process_Line_PVT;
365 FND_MESSAGE.SET_NAME('GMI','GMI_ERROR');
366 FND_MESSAGE.Set_Token('BY_PROC', 'GMI_Reservation_Util.Reallocate');
367 FND_MESSAGE.Set_Token('WHERE', 'GMI_Pick_Release_PVT.Process_Line');
368 FND_MSG_PUB.Add;
369 RAISE FND_API.G_EXC_ERROR;
370 END IF;
371 END LOOP;
372 END IF; /* The item is reservable */
373
374 /* ============================================================================ */
375 /* Once the Reallocation done, need to update the MO_Line with the new detailed_qty */
376 /* ============================================================================ */
377 /* Update the detailed quantity (and if possible, the sourcing information) */
378 /* of the Move Order Line */
379 /* If the move order line is not fully detailed, update the */
380 /* return status as appropriate. */
381 GMI_Reservation_Util.PrintLn('ictrans count='||GMI_Reservation_Util.ic_tran_rec_tbl.COUNT);
382 GMI_Reservation_Util.PrintLn('qty detailed='||l_quantity_detailed);
383 GMI_Reservation_Util.PrintLn('mo_line.primary_qty='||p_mo_line_rec.primary_quantity);
384 /* I think that I don't have to return an error when I can't Pick Full !!! (odab) */
385 /* IF l_quantity_detailed < p_mo_line_rec.primary_quantity THEN */
386 /* GMI_Reservation_Util.PrintLn('qty detailed < mo_line.primary_qty : Couldnt Pick Full'); */
387 /* ROLLBACK TO Process_Line_PVT; */
388 /* FND_MESSAGE.SET_NAME('INV','INV_COULD_NOT_PICK_FULL'); */
389 /* FND_MSG_PUB.Add; */
390 /* RAISE fnd_api.g_exc_unexpected_error; */
391 /* END IF; */
392
393 /* ============================================================================ */
394 /* Set the returned values : */
395 /* ============================================================================ */
396
397 /* -1 : The Default Lot row, which is not encounted */
398 x_detail_rec_count := l_allocated_transactions ;
399
400 l_mo_line_rec := p_mo_line_rec;
401 l_mo_line_rec.quantity_detailed := nvl(l_quantity_detailed, 0) + NVL(l_mo_line_rec.quantity_delivered, 0);
402 l_mo_line_rec.txn_source_id := l_mso_header_id;
403 l_mo_line_rec.txn_source_line_id := l_demand_info.oe_line_id;
404
405 gmi_reservation_util.println('Value of p_grouping_rule_id in Process Line before update_row is '||p_grouping_rule_id);
406 GMI_Reservation_Util.PrintLn('calling GMI_Move_Order_line_UTIL.Update_Row');
407 GMI_Move_Order_Line_UTIL.Update_Row(l_mo_line_rec);
408
409 gmi_reservation_util.println('Value of p_grouping_rule_id in process_line before calling Create_Pick_Slip_and_Print is '||p_grouping_rule_id);
410 /* =======================================================================================*/
411 /* Pick Slip (data + printing) */
412 /* ======================================================================================= */
413 GMI_Pick_Release_Util.Create_Pick_Slip_and_Print(
414 p_mo_line_rec => l_mo_line_rec
415 , p_inv_delivery_details => l_demand_info
416 , p_pick_slip_mode => l_pick_slip_mode
417 , p_grouping_rule_id => p_grouping_rule_id
418 , x_return_status => x_return_status
419 , x_msg_count => x_msg_count
420 , x_msg_data => x_msg_data);
421
422 /* , p_allow_partial_pick => p_allow_partial_pick */
423
424 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
425 ROLLBACK TO Process_Line_PVT;
426 FND_MESSAGE.SET_NAME('GMI','GMI_ERROR');
427 FND_MESSAGE.Set_Token('BY_PROC', 'GMI_Pick_Release_Util.Create_Pick_Slip_and_Print');
428 FND_MESSAGE.Set_Token('WHERE', 'GMI_Pick_Release_PVT.Process_Line');
429 FND_MSG_PUB.Add;
430 RAISE FND_API.G_EXC_ERROR;
431 END IF;
432
433
434 GMI_Reservation_Util.PrintLn('In the end of GMI_Pick_Release_PVT.Process_Line : NO Error, detail_rec_count='||x_detail_rec_count);
435
436
437 EXCEPTION
438 WHEN FND_API.G_EXC_ERROR THEN
439 x_return_status := FND_API.G_RET_STS_ERROR;
440
441 /* Get message count and data */
442 FND_MSG_PUB.count_and_get
443 ( p_count => x_msg_count
444 , p_data => x_msg_data
445 );
446
447
448 WHEN OTHERS THEN
449 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
450
451 FND_MSG_PUB.Add_Exc_Msg ( G_PKG_NAME
452 , l_api_name
453 );
454
455 /* Get message count and data */
456 FND_MSG_Pub.Count_and_Get
457 ( p_count => x_msg_count
458 , p_data => x_msg_data
459 );
460
461
462 END Process_Line;
463
464 END GMI_Pick_Release_PVT;