[Home] [Help]
PACKAGE BODY: APPS.INV_MAINTAIN_RESERVATION_PUB
Source
1 PACKAGE BODY INV_MAINTAIN_RESERVATION_PUB AS
2 /* $Header: INVPMRVB.pls 120.26.12010000.3 2009/01/14 19:57:03 athammin ship $*/
3
4 g_dummy_sn_tbl inv_reservation_global.serial_number_tbl_type;
5
6 -- CodeReview.SU.03 Define a global variable for l_Debug
7 g_debug Number := Nvl(Fnd_Profile.Value('INV_DEBUG_TRACE'),0);
8
9
10 g_pkg_name CONSTANT VARCHAR2(30) := 'INV_MAINTAIN_RESERVATION_PUB';
11 g_version_printed BOOLEAN := FALSE;
12 -- Global Constants for variables used in FND Log
13 -- CodeReview.SU.01 : Commenting following constants
14 -- G_statement_level constant number := FND_LOG.LEVEL_STATEMENT;
15 -- G_procedure_level constant number := FND_LOG.LEVEL_PROCEDURE;
16 -- G_event_level constant number := FND_LOG.LEVEL_EVENT;
17 -- G_exception_level constant number := FND_LOG.LEVEL_EXCEPTION;
18 -- G_error_level constant number := FND_LOG.LEVEL_ERROR;
19 -- G_unexp_level constant number := FND_LOG.LEVEL_UNEXPECTED;
20 -- G_Current_Debug_Level Constant Number := Fnd_Log.G_CURRENT_RUNTIME_LEVEL;
21
22 -- Define a cursor ref variable
23 TYPE query_cur_ref_type IS REF CURSOR;
24
25
26 PROCEDURE mydebug (p_message IN VARCHAR2
27 ,p_module_name IN VARCHAR2
28 ,p_level IN NUMBER)
29 IS
30 BEGIN
31 IF g_version_printed THEN
32 inv_log_util.TRACE ('$Header: INVPMRVB.pls 120.26.12010000.3 2009/01/14 19:57:03 athammin ship $',g_pkg_name||'.'||p_module_name, p_level);
33 END IF;
34 inv_log_util.TRACE (p_message,g_pkg_name||'.'||p_module_name, p_level);
35
36 END mydebug;
37
38
39 /*-------------------------------------------------------------------------------------*/
40 /* Procedure Name: FND_LOG_DEBUG */
41 /* Description : Logs the debug message using fnd_log API's */
42 /* Called from : Called from API */
43 /* */
44 /* STANDARD PARAMETERS */
45 /* In Parameters : */
46 /* p_severity_level Required Severity level */
47 /* p_module_name Required Module name */
48 /* p_message Required Debug message that needs to be logged */
49 /* Output Parameters: */
50 /* NON-STANDARD PARAMETERS */
51 /* In Parameters */
52 /* Out parameters */
53 /* Change Hist : */
54 /*-------------------------------------------------------------------------------------*/
55
56
57 /*Procedure Fnd_Log_Debug
58 ( p_severity_level IN NUMBER,
59 p_module_name IN VARCHAR2,
60 p_message IN VARCHAR2) IS
61 BEGIN
62 -- CodeReview.SU.02 Replaced global variables with fnd_log constants
63 IF p_severity_level = Fnd_Log.Level_Statement THEN
64 IF ( Fnd_Log.Level_Statement >= Fnd_Log.G_Current_Runtime_Level) THEN
65 Fnd_Log.String(p_severity_level,p_module_name,p_message);
66 END IF;
67 ELSIF p_severity_level = Fnd_Log.Level_Procedure THEN
68 IF ( Fnd_Log.Level_procedure >= Fnd_Log.G_Current_Runtime_level) THEN
69 FND_LOG.STRING(p_severity_level,p_module_name,p_message);
70 END IF;
71 ELSIF p_severity_level = Fnd_Log.Level_Event THEN
72 IF ( Fnd_Log.Level_Event >= Fnd_Log.G_Current_Runtime_Level) THEN
73 FND_LOG.STRING(p_severity_level,p_module_name,p_message);
74 END IF;
75 ELSIF p_severity_level = Fnd_Log.Level_Exception THEN
76 IF ( Fnd_Log.Level_Exception >= Fnd_Log.G_current_Runtime_Level) Then
77 FND_LOG.STRING(p_severity_level,p_module_name,p_message);
78 END IF;
79 ELSIF p_severity_level = Fnd_Log.Level_Error THEN
80 IF ( Fnd_Log.Level_Error >= Fnd_Log.G_Current_Runtime_level) THEN
81 FND_LOG.STRING(p_severity_level,p_module_name,p_message);
82 END IF;
83 ELSIF p_severity_level = Fnd_Log.Level_UnExpected THEN
84 IF ( Fnd_Log.Level_Unexpected >= Fnd_Log.G_Current_Runtime_level) THEN
85 FND_LOG.STRING(p_severity_level,p_module_name,p_message);
86 END IF;
87 END IF;
88
89 END Fnd_Log_Debug;*/
90
91 -- Local procedures to check missing parameters
92 -- Check_Reqd_Param is overloaded procedures, one for each type of scalar variabls
93 -- like date, varchar2, number
94 PROCEDURE Check_Reqd_Param (
95 p_param_value IN NUMBER,
96 p_param_name IN VARCHAR2,
97 p_api_name IN VARCHAR2
98 )
99 IS
100 l_debug NUMBER;
101 c_api_name CONSTANT VARCHAR2(30) := 'Check_Reqd_Param';
102 BEGIN
103 IF (g_debug IS NULL) THEN
104 g_debug := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
105 END IF;
106
107 l_debug := g_debug;
108
109 IF (l_debug = 1) THEN
110 mydebug('Checking API ' || p_api_name || ' , ' || p_param_name || ': ' || p_param_value, c_api_name, 9);
111 END IF;
112
113 IF (NVL(p_param_value,FND_API.G_MISS_NUM) = FND_API.G_MISS_NUM) THEN
114 IF (l_debug = 1) THEN
115 mydebug('In ' || p_api_name || ', ' || p_param_name || ' is required parameter, value is g_miss_num', c_api_name, 9);
116 END IF;
117 FND_MESSAGE.SET_NAME('INV','INV_API_MISSING_PARAM');
118 FND_MESSAGE.SET_TOKEN('API_NAME',p_api_name);
119 FND_MESSAGE.SET_TOKEN('MISSING_PARAM',p_param_name);
120 FND_MSG_PUB.Add;
121 RAISE FND_API.G_EXC_ERROR;
122 END IF;
123 END Check_Reqd_Param;
124
125 PROCEDURE Check_Reqd_Param (
126 p_param_value IN VARCHAR2,
127 p_param_name IN VARCHAR2,
128 p_api_name IN VARCHAR2
129 )
130 IS
131 l_debug NUMBER;
132 c_api_name CONSTANT VARCHAR2(30) := 'Check_Reqd_Param';
133 BEGIN
134 IF (g_debug IS NULL) THEN
135 g_debug := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
136 END IF;
137
138 l_debug := g_debug;
139
140 IF (l_debug = 1) THEN
141 mydebug('Checking API ' || p_api_name || ' , ' || p_param_name || ': ' || p_param_value, c_api_name, 9);
142 END IF;
143
144 IF (NVL(p_param_value,FND_API.G_MISS_CHAR) = FND_API.G_MISS_CHAR) THEN
145 IF (l_debug = 1) THEN
146 mydebug('In ' || p_api_name || ', ' || p_param_name || ' is required parameter, value is g_miss_char', c_api_name, 9);
147 END IF;
148
149 -- New Message - 001
150 -- $MISSING_PARAM is a required parameter.
151 FND_MESSAGE.SET_NAME('INV','INV_API_MISSING_PARAM');
152 FND_MESSAGE.SET_TOKEN('API_NAME',p_api_name);
153 FND_MESSAGE.SET_TOKEN('MISSING_PARAM',p_param_name);
154 FND_MSG_PUB.Add;
155 RAISE FND_API.G_EXC_ERROR;
156 END IF;
157 END Check_Reqd_Param;
158
159 PROCEDURE Check_Reqd_Param (
160 p_param_value IN DATE,
161 p_param_name IN VARCHAR2,
162 p_api_name IN VARCHAR2
163 )
164 IS
165 l_debug NUMBER;
166 c_api_name CONSTANT VARCHAR2(30) := 'CHECK_REQD_PARAM';
167 BEGIN
168 IF (g_debug IS NULL) THEN
169 g_debug := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
170 END IF;
171
172 l_debug := g_debug;
173
174 IF (l_debug = 1) THEN
175 mydebug('Checking API ' || p_api_name || ' , ' || p_param_name || ': ' || TO_CHAR(p_param_value, 'YYYY-MM-DD:DD:SS'), c_api_name, 9);
176 END IF;
177
178 IF (NVL(p_param_value,FND_API.G_MISS_DATE) = FND_API.G_MISS_DATE) THEN
179 IF (l_debug = 1) THEN
180 mydebug('In ' || p_api_name || ', ' || p_param_name || ' is required parameter, value is g_miss_date', c_api_name, 9);
181 END IF;
182
183 FND_MESSAGE.SET_NAME('INV','INV_API_MISSING_PARAM');
184 FND_MESSAGE.SET_TOKEN('API_NAME',p_api_name);
185 FND_MESSAGE.SET_TOKEN('MISSING_PARAM',p_param_name);
186 FND_MSG_PUB.Add;
187 RAISE FND_API.G_EXC_ERROR;
188 END IF;
189 END Check_Reqd_Param;
190
191
192 -- procedure
193 -- reduce_reservation
194 --
195 -- description
196 -- api will handle changes to the resevationl record based on the changes to the supply or
197 -- demand record changes.
198 --
199 -- Input Paramters
200 -- p_api_version_number Number API version number (current version is 1.0 Standard in parameter)
201 -- p_Init_Msg_lst Varcahar2(1) (Flag for initialize message stack, standard input parameter)
202 -- p_Mtl_Maintain_Rsv_Tbl Inv_Reservations_Global.mtl_Maintain_rsv_tbl_type
203 -- p_Delete_Flag Varchar2(1) Accepted values 'Y', 'N' and Null. Null value is equivalent to 'N'
204 -- p_Sort_By_Criteria Number
205 --Out Parameters
206 -- x_Return_Status Varchar2(1) (Return Status of API, Standard out parameter)
207 -- x_Msg_Count Number (Message count from the stack, standard out parameter)
208 -- x_Msg_Data Varchar2(255) (Message from message stack, standard out parameter)
209 -- x_Quantity_Modified Number (Quantity that has been reduced or deleted by API)
210
211
212 Procedure reduce_reservation (
213 p_api_version_number in number,
214 p_init_msg_lst in varchar2,
215 x_return_status out nocopy varchar2,
216 x_msg_count out nocopy number,
217 x_msg_data out nocopy varchar2,
218 p_mtl_maintain_rsv_rec in inv_reservation_global.mtl_maintain_rsv_rec_type,
219 p_delete_flag in varchar2,
220 p_sort_by_criteria in number,
221 x_quantity_modified out nocopy number ) is
222
223 -- define constants for api version and api name
224 c_api_version_number constant number := 1.0;
225 c_api_name constant varchar2(30) := 'reduce_reservation';
226 c_module_name constant varchar2(2000) := 'inv.plsql.inv_maintain_reservations.reduce_reservation';
227 c_debug_enabled constant number := 1 ;
228 c_action_supply constant number := 0;
229 c_action_demand constant number := 1;
230 c_cancel_order_no constant number := inv_reservation_global.g_cancel_order_no ;
231
232 -- l_debug number := nvl(fnd_profile.value('inv_debug_trace'), 0);
233 l_fnd_log_message varchar2(2000);
234 l_rsv_rec inv_reservation_global.mtl_reservation_rec_type;
235 l_query_input inv_reservation_global.mtl_reservation_rec_type;
236 l_mtl_reservation_tbl inv_reservation_global.mtl_reservation_tbl_type ;
237 l_mtl_reservation_tbl_count number ;
238 l_sort_by_criteria number ;
239 l_error_code number ;
240
241 -- following variables for calling transfer reservation api
242 l_is_transfer_supply varchar2(1);
243 l_original_rsv_rec inv_reservation_global.mtl_reservation_rec_type;
244 -- convert_rsv_rec is used to convert expected_qty to primary_expected_uom_code
245 l_convert_rsv_rec inv_reservation_global.mtl_reservation_rec_type;
246 l_to_rsv_rec inv_reservation_global.mtl_reservation_rec_type;
247 l_original_serial_number inv_reservation_global.serial_number_tbl_type;
248 l_to_serial_number inv_reservation_global.serial_number_tbl_type;
249 l_reservation_id number ;
250 l_primary_uom_code varchar2(10);
251 l_primary_expected_qty number ;
252 l_to_primary_transaction_qty number;
253 l_sum_primary_reservation_qty number;
254 l_primary_need_reduced_qty number ;
255 l_from_primary_transaction_qty number;
256 l_msg_index_out number;
257 l_staged_rec_exists varchar2(1) ;
258
259 l_return_status varchar2(1) := fnd_api.g_ret_sts_success;
260 l_msg_count number;
261 l_msg_data varchar2(1000);
262 l_wip_entity_type_id number;
263 l_wip_job_type varchar2(15);
264 l_source_header_id number;
265
266 begin
267 -- call fnd_log api in the begining of the api
268 l_fnd_log_message := 'begining of procedure :';
269 -- fnd_log_debug(fnd_log.level_procedure,c_module_name, l_fnd_log_message );
270
271 -- log message in trace file
272 if g_debug= c_debug_enabled then
273 --codereview.su.04 : print package name once at the begning of api
274 g_version_printed := true ;
275 mydebug(l_fnd_log_message,c_api_name,9);
276 g_version_printed := false ;
277
278 end if;
279
280 -- initialize x_return_status variable to success in the begning of api
281 x_return_status := fnd_api.g_ret_sts_success;
282 -- standard call to check for call compatibility
283 if not fnd_api.compatible_api_call(c_api_version_number
284 , p_api_version_number
285 , c_api_name
286 , g_pkg_name
287 ) then
288 raise fnd_api.g_exc_unexpected_error;
289 end if;
290
291 -- initialize message list. null value for p_init_msg_lst variable will be treated as 'n'
292 -- codereview.su.05 remove nvl function
293 if fnd_api.to_boolean(p_init_msg_lst) then
294 fnd_msg_pub.initialize;
295 end if;
296
297 if (g_debug= c_debug_enabled) then
298 mydebug ('before checking for required parameters' ,c_api_name,1);
299 end if;
300
301 -- check for required parameters
302 -- action column is a required column
303 check_reqd_param (
304 p_param_value => p_mtl_maintain_rsv_rec.action,
305 p_param_name => 'p_mtl_maintain_rsv_rec.action',
306 p_api_name => c_api_name );
307
308 -- organization id is a required column
309 check_reqd_param (
310 p_param_value => p_mtl_maintain_rsv_rec.organization_id,
311 p_param_name => 'p_mtl_maintain_rsv_rec.organization_id',
312 p_api_name => c_api_name );
313
314 -- inventory item id is a required column
315 check_reqd_param (
316 p_param_value => p_mtl_maintain_rsv_rec.inventory_item_id,
317 p_param_name => 'p_mtl_maintain_rsv_rec.inventory_item_id',
318 p_api_name => c_api_name );
319
320
321 -- get wip entity type if the supply is wip
322 if (p_mtl_maintain_rsv_rec.action = c_action_supply) then
323 l_source_header_id := p_mtl_maintain_rsv_rec.supply_source_header_id;
324 elsif (p_mtl_maintain_rsv_rec.action = c_action_demand) then
325 l_source_header_id := p_mtl_maintain_rsv_rec.demand_source_header_id;
326 end if;
327
328 if (p_mtl_maintain_rsv_rec.supply_source_type_id = inv_reservation_global.g_source_type_wip) then
329 if (g_debug= c_debug_enabled) then
330 mydebug ('before calling get_wip_entity_type' , c_api_name, 9);
331 end if;
332 inv_reservation_pvt.get_wip_entity_type
333 ( p_api_version_number => 1.0
334 , p_init_msg_lst => fnd_api.g_false
335 , x_return_status => l_return_status
336 , x_msg_count => l_msg_count
337 , x_msg_data => l_msg_data
338 , p_organization_id => p_mtl_maintain_rsv_rec.organization_id
339 , p_item_id => p_mtl_maintain_rsv_rec.inventory_item_id
340 , p_source_type_id => null
341 , p_source_header_id => l_source_header_id
342 , p_source_line_id => null
343 , p_source_line_detail => null
344 , x_wip_entity_type => l_wip_entity_type_id
345 , x_wip_job_type => l_wip_job_type
346 );
347
348 if (g_debug = c_debug_enabled) then
349 mydebug('status return from get_wip_entity = ' || l_return_status, c_api_name, 9);
350 mydebug('l_wip_entity_type = ' || l_wip_entity_type_id, c_api_name, 9);
351 end if;
352 if (l_return_status = fnd_api.g_ret_sts_error) then
353 raise fnd_api.g_exc_error;
354 elsif (l_return_status = fnd_api.g_ret_sts_unexp_error) then
355 raise fnd_api.g_exc_unexpected_error;
356 end if;
357 end if;
358
359 if (g_debug = c_debug_enabled) then
360 mydebug('p_delete_flag = '|| p_delete_flag ,c_api_name,1);
361 mydebug('action = ' || p_mtl_maintain_rsv_rec.action, c_api_name,1);
362 end if;
363
364 if upper(nvl(p_delete_flag,'N')) = 'N' then
365 -- codereview.su.06. swap action types for sorting criteria
366 if p_mtl_maintain_rsv_rec.action = c_action_demand then
367 if p_sort_by_criteria is null then
368 l_sort_by_criteria := inv_reservation_global.g_query_supply_rcpt_date_asc;
369 else
370 l_sort_by_criteria := p_sort_by_criteria ;
371 end if;
372 elsif p_mtl_maintain_rsv_rec.action = c_action_supply then
373 if p_sort_by_criteria is null then
374 l_sort_by_criteria := inv_reservation_global.g_query_demand_ship_date_desc;
375 else
376 l_sort_by_criteria := p_sort_by_criteria ;
377 end if;
378 end if;
379 elsif upper(nvl(p_delete_flag,'N')) = 'Y' then
380 -- if delete flag is 'y' sort by criteria will be same as what user has passed.
381 l_sort_by_criteria := p_sort_by_criteria;
382 end if;
383
384 -- assign values to l_query_input record.
385 l_query_input.organization_id := p_mtl_maintain_rsv_rec.organization_id;
386 l_query_input.inventory_item_id := p_mtl_maintain_rsv_rec.inventory_item_id ;
387
388 if (g_debug = c_debug_enabled) then
389 mydebug('checking action ' ,c_api_name,1);
390 end if;
391
392 -- check if action to be performed on supply or demand
393 if p_mtl_maintain_rsv_rec.action = c_action_supply then
394 if (g_debug = c_debug_enabled) then
395 mydebug('action is supply' ,c_api_name,1);
396 mydebug('supply source type id = ' || p_mtl_maintain_rsv_rec.supply_source_type_id ,c_api_name,1);
397 end if;
398
399 -- if action is supply then supply attributes should be passed
400 -- confirm with vishy that this logic is correct
401 -- supply source type is required column
402 check_reqd_param (
403 p_param_value => p_mtl_maintain_rsv_rec.supply_source_type_id,
404 p_param_name => 'p_mtl_maintain_rsv_rec.supply_source_type_id',
405 p_api_name => c_api_name);
406
407 -- supply source header is required column
408 -- codereview.su.07. source_header_id is required for following source types
409 -- po, wip, int req, ext req, asn, intrasit
410 -- not required for inventory source type
411 if (p_mtl_maintain_rsv_rec.supply_source_type_id <> inv_reservation_global.g_source_type_inv) then
412 check_reqd_param (
413 p_param_value => p_mtl_maintain_rsv_rec.supply_source_header_id,
414 p_param_name => 'p_mtl_maintain_rsv_rec.supply_source_header',
415 p_api_name => c_api_name );
416 end if; -- check for supply source header id
417
418 -- suppply source line is required column
419 -- codereview.su.07. source_line_id is required for following source types
420 -- po, int req, ext req, asn, intrasit
421 -- not required for inventory,wip
422 if (p_mtl_maintain_rsv_rec.supply_source_type_id = inv_reservation_global.g_source_type_wip
423 and l_wip_entity_type_id in (inv_reservation_global.g_wip_source_type_batch,inv_reservation_global.g_wip_source_type_cmro)) then
424 check_reqd_param (
425 p_param_value => p_mtl_maintain_rsv_rec.supply_source_line_id,
426 p_param_name => 'p_mtl_maintain_rsv_rec.supply_source_line_id',
427 p_api_name => c_api_name );
428 elsif (p_mtl_maintain_rsv_rec.supply_source_type_id
429 not in
430 (inv_reservation_global.g_source_type_inv,
431 inv_reservation_global.g_source_type_wip,
432 inv_reservation_global.g_source_type_account,
433 inv_reservation_global.g_source_type_account_alias)) then
434 check_reqd_param (
435 p_param_value => p_mtl_maintain_rsv_rec.supply_source_line_id,
436 p_param_name => 'p_mtl_maintain_rsv_rec.supply_source_line_id',
437 p_api_name => c_api_name );
438
439 end if; -- check for supply source line id
440
441 -- suppply source line detail required column
442 -- codereview.su.07. source_line_detail is required for following source types
443 -- asn
444 if p_mtl_maintain_rsv_rec.supply_source_type_id = inv_reservation_global.g_source_type_asn then
445 check_reqd_param (
446 p_param_value => p_mtl_maintain_rsv_rec.supply_source_line_detail,
447 p_param_name => 'p_mtl_maintain_rsv_rec.supply_source_line_detail',
448 p_api_name => c_api_name );
449 end if; -- check for supply source line id
450
451 -- now assign values to l_query_input record
452 l_query_input.supply_source_type_id := p_mtl_maintain_rsv_rec.supply_source_type_id ;
453 l_query_input.supply_source_header_id := p_mtl_maintain_rsv_rec.supply_source_header_id ;
454 l_query_input.supply_source_line_id := p_mtl_maintain_rsv_rec.supply_source_line_id ;
455 -- codereview.su.08 : should pass supply source line detail value
456 l_query_input.supply_source_line_detail := p_mtl_maintain_rsv_rec.supply_source_line_detail ;
457
458 elsif p_mtl_maintain_rsv_rec.action = c_action_demand then
459 -- if action is demand then demand attributes should be passed
460 -- demand source type is required column
461 -- dbms_output.put_line('action is demand');
462 if (g_debug = c_debug_enabled) then
463 mydebug('action is demand' ,c_api_name,1);
464 end if;
465
466 check_reqd_param (
467 p_param_value => p_mtl_maintain_rsv_rec.demand_source_type_id,
468 p_param_name => 'p_mtl_maintain_rsv_rec.demand_source_type_id',
469 p_api_name => c_api_name );
470
471 -- demand source header is required column
472 -- codereview.su.07. source_header_id is not required for inv source types
473 if p_mtl_maintain_rsv_rec.demand_source_type_id <> inv_reservation_global.g_source_type_inv then
474 check_reqd_param (
475 p_param_value => p_mtl_maintain_rsv_rec.demand_source_header_id,
476 p_param_name => 'p_mtl_maintain_rsv_rec.demand_source_header',
477 p_api_name => c_api_name );
478 end if; -- check source header id
479
480 -- demandy source line is required column
481 -- codereview.su.07. demand_source_line_id is not required for inv source types
482 if (p_mtl_maintain_rsv_rec.demand_source_type_id = inv_reservation_global.g_source_type_wip
483 and l_wip_entity_type_id in (inv_reservation_global.g_wip_source_type_cmro,
484 inv_reservation_global.g_wip_source_type_batch)) then
485 check_reqd_param (
486 p_param_value => p_mtl_maintain_rsv_rec.demand_source_line_id,
487 p_param_name => 'p_mtl_maintain_rsv_rec.demand_source_line_id',
488 p_api_name => c_api_name );
489 elsif (p_mtl_maintain_rsv_rec.demand_source_type_id not in (inv_reservation_global.g_source_type_inv,inv_reservation_global.g_source_type_account, inv_reservation_global.g_source_type_account_alias)) then
490 check_reqd_param (
491 p_param_value => p_mtl_maintain_rsv_rec.demand_source_line_id,
492 p_param_name => 'p_mtl_maintain_rsv_rec.demand_source_line_id',
493 p_api_name => c_api_name );
494 end if; -- check demand source line id
495
496 -- now assign values to l_query_input record
497 l_query_input.demand_source_type_id := p_mtl_maintain_rsv_rec.demand_source_type_id ;
498 l_query_input.demand_source_header_id := p_mtl_maintain_rsv_rec.demand_source_header_id ;
499 l_query_input.demand_source_line_id := p_mtl_maintain_rsv_rec.demand_source_line_id ;
500 -- codereview.su.09 : should pass demand source line detail value
501 l_query_input.demand_source_line_detail := p_mtl_maintain_rsv_rec.demand_source_line_detail ;
502
503 else
504 if (g_debug = c_debug_enabled) then
505 mydebug('invalid param value' ,c_api_name,1);
506 end if;
507 -- new message 002
508 -- "invalid value for parameter $param_name : $param_value
509 fnd_message.set_name('inv','inv_api_invalid_param_value');
510 fnd_message.set_token('param_name','action');
511 fnd_message.set_token('param_value',p_mtl_maintain_rsv_rec.action);
512 fnd_msg_pub.add;
513 raise fnd_api.g_exc_error;
514
515 end if;
516 -- query the reservation records for supply based on sort by criteria passed by user.
517
518 if (g_debug= c_debug_enabled) then
519 mydebug ('calling query reservation' ,c_api_name,1);
520 end if;
521
522 IF (p_mtl_maintain_rsv_rec.project_id IS NOT NULL AND
523 p_mtl_maintain_rsv_rec.project_id <> fnd_api.g_miss_num) THEN
524 l_query_input.project_id := p_mtl_maintain_rsv_rec.project_id;
525 END IF;
526
527 IF (p_mtl_maintain_rsv_rec.task_id IS NOT NULL AND
528 p_mtl_maintain_rsv_rec.task_id<> fnd_api.g_miss_num) THEN
529 l_query_input.task_id := p_mtl_maintain_rsv_rec.task_id;
530 END IF;
531
532 inv_reservation_pvt.query_reservation(
533 p_api_version_number => 1.0,
534 p_init_msg_lst => p_init_msg_lst,
535 x_return_status => x_return_status,
536 x_msg_count => x_msg_count,
537 x_msg_data => x_msg_data,
538 p_query_input => l_query_input,
539 p_sort_by_req_date => p_sort_by_criteria,
540 p_cancel_order_mode => c_cancel_order_no,
541 x_mtl_reservation_tbl => l_mtl_reservation_tbl,
542 x_mtl_reservation_tbl_count => l_mtl_reservation_tbl_count,
543 x_error_code => l_error_code) ;
544
545 if (g_debug = c_debug_enabled) then
546 mydebug('return status after calling query reservations
547 '||x_return_status,c_api_name,1);
548 mydebug('totol number of records returned' ||
549 l_mtl_reservation_tbl_count, c_api_name,1);
550 end if;
551
552 -- check if query reservation has raised any errors, if so raise exception
553 if x_return_status = fnd_api.g_ret_sts_error then
554 l_fnd_log_message := 'error while calling query_reservation api :';
555 -- fnd_log_debug(fnd_log.level_error,c_module_name, l_fnd_log_message );
556
557 if g_debug= c_debug_enabled then
558 mydebug(l_fnd_log_message, c_api_name,9);
559 end if;
560
561 raise fnd_api.g_exc_error;
562 elsif x_return_status = fnd_api.g_ret_sts_unexp_error then
563 l_fnd_log_message := 'error while calling query_reservation api :';
564 -- fnd_log_debug(fnd_log.level_error,c_module_name, l_fnd_log_message );
565
566 if g_debug = c_debug_enabled then
567 mydebug(l_fnd_log_message, c_api_name,9);
568 end if;
569 raise fnd_api.g_exc_unexpected_error;
570 end if;
571
572 -- check if there are any records returned by query_reservation
573 if l_mtl_reservation_tbl_count <= 0 then
574 l_fnd_log_message := 'there are no records returned by query_reservation api' ;
575 -- fnd_log_debug(fnd_log.level_procedure,c_module_name, l_fnd_log_message );
576 if g_debug = c_debug_enabled then
577 mydebug(l_fnd_log_message, c_api_name,9);
578 end if;
579 if p_mtl_maintain_rsv_rec.action = c_action_supply then
580 l_fnd_log_message := 'reservation action type is supply' ;
581 -- fnd_log_debug(fnd_log.level_procedure,c_module_name, l_fnd_log_message );
582 if g_debug = c_debug_enabled then
583 mydebug(l_fnd_log_message, c_api_name,9);
584 end if;
585 l_fnd_log_message := 'supply source type id is :' || p_mtl_maintain_rsv_rec.supply_source_type_id ;
586 -- fnd_log_debug(fnd_log.level_procedure,c_module_name, l_fnd_log_message );
587 if g_debug= c_debug_enabled then
588 mydebug(l_fnd_log_message, c_api_name,9);
589 end if;
590 l_fnd_log_message := 'supply source header id is:'||p_mtl_maintain_rsv_rec.supply_source_header_id;
591 -- fnd_log_debug(fnd_log.level_procedure,c_module_name, l_fnd_log_message );
592 if g_debug= c_debug_enabled then
593 mydebug(l_fnd_log_message, c_api_name,9);
594 end if;
595 l_fnd_log_message := 'supply source line id is:'||p_mtl_maintain_rsv_rec.supply_source_line_id;
596 -- fnd_log_debug(fnd_log.level_procedure,c_module_name, l_fnd_log_message );
597 if g_debug= c_debug_enabled then
598 mydebug(l_fnd_log_message, c_api_name,9);
599 end if;
600 else
601 l_fnd_log_message := 'reservation action type is demand' ;
602 -- fnd_log_debug(fnd_log.level_procedure,c_module_name, l_fnd_log_message );
603 if g_debug= c_debug_enabled then
604 mydebug(l_fnd_log_message, c_api_name,9);
605 end if;
606 l_fnd_log_message := 'demand source type id is :' || p_mtl_maintain_rsv_rec.demand_source_type_id ;
607 -- fnd_log_debug(fnd_log.level_procedure,c_module_name, l_fnd_log_message );
608 if g_debug= c_debug_enabled then
609 mydebug(l_fnd_log_message, c_api_name,9);
610 end if;
611 l_fnd_log_message := 'demand source header id is:'||p_mtl_maintain_rsv_rec.demand_source_header_id;
612 -- fnd_log_debug(fnd_log.level_procedure,c_module_name, l_fnd_log_message );
613 if g_debug= c_debug_enabled then
614 mydebug(l_fnd_log_message, c_api_name,9);
615 end if;
616 l_fnd_log_message := 'demand source line id is:'||p_mtl_maintain_rsv_rec.demand_source_line_id;
617 -- fnd_log_debug(fnd_log.level_procedure,c_module_name, l_fnd_log_message );
618 if g_debug= c_debug_enabled then
619 mydebug(l_fnd_log_message, c_api_name,9);
620 end if;
621 end if;
622 -- new message 003 . this is a warning not an error message
623 -- "query reservation api returns no records"
624 fnd_message.set_name('inv','inv_qry_rsv_api_rtns_no_rec');
625 fnd_msg_pub.add;
626 return ;
627 end if;
628 -- dbms_output.put_line('checking delete flag status');
629 if upper(nvl(p_delete_flag,'N')) = 'Y' then
630 -- check if there are any reservation records with staged_flag as 'y'
631 -- if so, throw error
632 if (g_debug= c_debug_enabled) then
633 mydebug ('Inside delete flag is Y' ,c_api_name,1);
634 end if;
635
636 l_staged_rec_exists := 'N' ;
637 for i in 1..l_mtl_reservation_tbl_count loop
638 if l_mtl_reservation_tbl(i).supply_source_type_id
639 = inv_reservation_global.g_source_type_inv
640 and nvl(l_mtl_reservation_tbl(i).staged_flag, 'N') = 'Y' then
641 l_staged_rec_exists := 'Y' ;
642 if (g_debug= c_debug_enabled) then
643 mydebug ('Staged reservation exists' ,c_api_name,1);
644 end if;
645 exit ;
646 end if;
647 end loop ;
648 if l_staged_rec_exists = 'Y' then
649 -- new message 003 . this is a warning not an error message
650 -- "reservation can not be deleted as one or more reservation
651 -- records are in staged"
652 if (g_debug= c_debug_enabled) then
653 mydebug ('Staged reservation exists. Error out' ,c_api_name,1);
654 end if;
655 fnd_message.set_name('INV','INV_RSV_REC_IN_STAGING');
656 fnd_msg_pub.add;
657 raise fnd_api.g_exc_error;
658 end if;
659
660 -- dbms_output.put_line('delete flag is yes');
661 for i in 1..l_mtl_reservation_tbl_count loop
662 -- codereview.su.10 move it to begining of loop and assign record itself
663 l_original_rsv_rec := l_mtl_reservation_tbl(i) ;
664 if ( l_mtl_reservation_tbl(i).orig_supply_source_type_id
665 <> l_mtl_reservation_tbl(i).supply_source_type_id )
666 and l_mtl_reservation_tbl(i).supply_source_type_id = inv_reservation_global.g_source_type_asn then
667 l_original_rsv_rec.reservation_id :=
668 l_mtl_reservation_tbl(i).reservation_id ;
669 if (g_debug= c_debug_enabled) then
670 mydebug ('ASN reservation. Need to transfer to the
671 original supply' ,c_api_name,1);
672 end if;
673 if p_mtl_maintain_rsv_rec.action = c_action_supply then
674 l_to_rsv_rec.supply_source_type_id := inv_reservation_global.g_source_type_po ;
675 l_to_rsv_rec.supply_source_header_id := l_original_rsv_rec.supply_source_header_id;
676 l_to_rsv_rec.supply_source_line_id := l_original_rsv_rec.supply_source_line_id;
677 --codereview.su.11 assign supply_source_line_detail value too
678 l_to_rsv_rec.supply_source_line_detail := l_original_rsv_rec.supply_source_line_detail;
679 l_is_transfer_supply := fnd_api.g_true ;
680 -- codereview.su.12 comment out else statement. not required
681 /**************************
682 else
683 l_to_rsv_rec.demand_source_type_id := inv_reservation_global.g_source_type_po ;
684 l_to_rsv_rec.demand_source_header_id := l_original_rsv_rec.demand_source_header_id;
685 l_to_rsv_rec.demand_source_line_id := l_original_rsv_rec.demand_source_line_id;
686 l_to_rsv_rec.demand_source_delivery := null;
687 l_is_transfer_supply := fnd_api.g_false;
688 ***************************/
689 end if;
690 -- ignoring serial numbers assingment since serial numbers are not changed
691 -- reservation is transfered from one document type to another one.
692
693 -- call transfer reservation api and transfer reservation to po
694 if (g_debug= c_debug_enabled) then
695 mydebug ('Transferring reservation to the original supply' ,c_api_name,1);
696 mydebug ('Header:Line:Line Detail :' ||
697 l_to_rsv_rec.supply_source_header_id || ': ' ||
698 l_to_rsv_rec.supply_source_line_id || ': ' ||
699 l_to_rsv_rec.supply_source_line_detail,c_api_name,1);
700
701 end if;
702
703 inv_reservation_pvt.transfer_reservation (
704 p_api_version_number => 1.0 ,
705 p_init_msg_lst => fnd_api.g_false ,
706 x_return_status => x_return_status,
707 x_msg_count => x_msg_count,
708 x_msg_data => x_msg_data,
709 --p_is_transfer_supply => l_is_transfer_supply,
710 p_original_rsv_rec => l_original_rsv_rec ,
711 p_to_rsv_rec => l_to_rsv_rec ,
712 p_original_serial_number => l_original_serial_number,
713 -- p_to_serial_number => l_to_serial_number,
714 p_validation_flag => fnd_api.g_true ,
715 x_reservation_id => l_reservation_id ) ;
716 -- check if transfer reservation has raised any errors, if so raise exception
717 if (g_debug= c_debug_enabled) then
718 mydebug ('After calling transfer: ' || x_return_status ,c_api_name,1);
719 end if;
720 if x_return_status = fnd_api.g_ret_sts_error then
721 l_fnd_log_message := 'error while calling transfer_reservation api :';
722 -- fnd_log_debug(fnd_log.level_error,c_module_name, l_fnd_log_message );
723 if g_debug= c_debug_enabled then
724 mydebug(l_fnd_log_message, c_api_name,9);
725 end if;
726 raise fnd_api.g_exc_error;
727 elsif x_return_status = fnd_api.g_ret_sts_unexp_error then
728 l_fnd_log_message := 'error while calling transfer_reservation api :';
729 -- fnd_log_debug(fnd_log.level_error,c_module_name, l_fnd_log_message );
730 if g_debug= c_debug_enabled then
731 mydebug(l_fnd_log_message, c_api_name,9);
732 end if;
733 raise fnd_api.g_exc_unexpected_error;
734 elsif x_return_status = fnd_api.g_ret_sts_success then
735 l_fnd_log_message := 'calling transfer_reservation api was successful:';
736 -- fnd_log_debug(fnd_log.level_event,c_module_name, l_fnd_log_message );
737 if g_debug= c_debug_enabled then
738 mydebug(l_fnd_log_message, c_api_name,9);
739 end if;
740 end if;
741 ELSE -- not ASN
742 if (g_debug= c_debug_enabled) then
743 mydebug ('Deleting reservations, Delete flag: Y' ,c_api_name,1);
744 mydebug ('Header:Line:Line Detail :' ||
745 l_original_rsv_rec.supply_source_header_id || ': ' ||
746 l_original_rsv_rec.supply_source_line_id || ': ' ||
747 l_original_rsv_rec.supply_source_line_detail,c_api_name,1);
748 end if;
749 l_original_rsv_rec.reservation_id := l_mtl_reservation_tbl(i).reservation_id ;
750 -- delete reservation record
751 inv_reservation_pvt.delete_reservation(
752 p_api_version_number => 1.0 ,
753 p_init_msg_lst => fnd_api.g_false ,
754 x_return_status => x_return_status,
755 x_msg_count => x_msg_count,
756 x_msg_data => x_msg_data,
757 p_rsv_rec => l_original_rsv_rec ,
758 p_original_serial_number => l_original_serial_number,
759 p_validation_flag => fnd_api.g_true);
760
761 if (g_debug= c_debug_enabled) then
762 mydebug ('After calling delete: ' || x_return_status ,c_api_name,1);
763 end if;
764 -- check if delete reservation has raised any errors, if so raise exception
765 if x_return_status = fnd_api.g_ret_sts_error then
766 l_fnd_log_message := 'error while calling delete_reservation api :';
767 -- fnd_log_debug(fnd_log.level_error,c_module_name, l_fnd_log_message );
768 if g_debug= c_debug_enabled then
769 mydebug(l_fnd_log_message, c_api_name,9);
770 end if;
771 raise fnd_api.g_exc_error;
772 elsif x_return_status = fnd_api.g_ret_sts_unexp_error then
773 l_fnd_log_message := 'error while calling delete_reservation api :';
774 -- fnd_log_debug(fnd_log.level_error,c_module_name, l_fnd_log_message );
775 if g_debug= c_debug_enabled then
776 mydebug(l_fnd_log_message, c_api_name,9);
777 end if;
778 raise fnd_api.g_exc_unexpected_error;
779 elsif x_return_status = fnd_api.g_ret_sts_success then
780 l_fnd_log_message := 'calling delete_reservation api was successful:';
781 -- fnd_log_debug(fnd_log.level_event,c_module_name, l_fnd_log_message );
782 if g_debug= c_debug_enabled then
783 mydebug(l_fnd_log_message, c_api_name,9);
784 end if;
785 end if; -- end of checking return status
786 -- update quantity reduced variable
787 x_quantity_modified := x_quantity_modified + l_mtl_reservation_tbl(i).reservation_quantity ;
788 end if; -- end of checking original_source_type_id and source_type_id
789 end loop;
790 elsif upper(nvl(p_delete_flag,'N')) = 'N' then
791 -- check for expected quantity value
792 -- dbms_output.put_line('delete flag is no');
793 if (g_debug= c_debug_enabled) then
794 mydebug ('Expected qty: ' ||
795 Nvl(p_mtl_maintain_rsv_rec.expected_quantity,0)
796 ,c_api_name,1);
797 mydebug ('Expected qty uom: ' ||
798 p_mtl_maintain_rsv_rec.expected_quantity_uom
799 ,c_api_name,1);
800 mydebug ('To primary uom: ' || p_mtl_maintain_rsv_rec.to_primary_uom_code ,c_api_name,1);
801 end if;
802 if nvl(p_mtl_maintain_rsv_rec.expected_quantity,0) > 0 then
803 -- dbms_output.put_line('expected qty is > 0');
804 if p_mtl_maintain_rsv_rec.expected_quantity_uom is null or
805 p_mtl_maintain_rsv_rec.expected_quantity_uom = fnd_api.g_miss_char then
806 -- codereview.su.13. raise error
807 check_reqd_param
808 (
809 p_param_value => p_mtl_maintain_rsv_rec.expected_quantity_uom, p_param_name => 'p_mtl_maintain_rsv_rec.expected_quantity_uom',
810 p_api_name => c_api_name );
811 -- dbms_output.put_line('raising error as expected qty uom is null');
812 raise fnd_api.g_exc_error ;
813 -- commenting following lines
814 -- it is assumed that expected qty uom is same as primary qty uom
815 -- l_primary_expected_qty := p_mtl_maintain_rsv_rec.expected_quantity ;
816 else -- expected_quantity_uom is not null
817 -- dbms_output.put_line('expected qty uom is not null');
818 if p_mtl_maintain_rsv_rec.to_primary_uom_code is null or
819 p_mtl_maintain_rsv_rec.to_primary_uom_code = fnd_api.g_miss_char then
820 -- in such cases we will take primary uom code of the first record
821 -- and assuming that for all the records primary uom code will be same as
822 -- inventory_item_id and organization_id will be same
823 l_primary_uom_code := l_mtl_reservation_tbl(1).primary_uom_code ;
824 -- codereview.su.14 comment out follwing line.
825 else -- to_primary_uom_code is null
826 l_primary_uom_code := p_mtl_maintain_rsv_rec.to_primary_uom_code ;
827 -- su:06/15/2005
828 end if; -- to_primary_uom_code is null
829 if g_debug= c_debug_enabled then
830 mydebug('primary uom code: ' || l_primary_uom_code, c_api_name,9);
831 mydebug('primary expected qty : ' || l_primary_expected_qty, c_api_name,9);
832 end if;
833 IF p_mtl_maintain_rsv_rec.expected_quantity_uom <>
834 l_primary_uom_code THEN
835 -- dbms_output.put_line('expected qty uom is not equal to primary_uom_code');
836 l_primary_expected_qty := inv_convert.inv_um_convert
837 (
838 item_id => p_mtl_maintain_rsv_rec.inventory_item_id,
839 precision => null,
840 from_quantity => p_mtl_maintain_rsv_rec.expected_quantity,
841 from_unit => p_mtl_maintain_rsv_rec.expected_quantity_uom,
842 to_unit => p_mtl_maintain_rsv_rec.to_primary_uom_code,
843 from_name => null,
844 to_name => null );
845 l_fnd_log_message := 'after calling api inv_convert.inv_um_convert:';
846 -- fnd_log_debug(fnd_log.level_event,c_module_name, l_fnd_log_message );
847 if g_debug= c_debug_enabled then
848 mydebug(l_fnd_log_message, c_api_name,9);
849 mydebug('primary expected qty: ' || l_primary_expected_qty, c_api_name,9);
850 end if;
851
852 ELSE -- they are the same
853 l_primary_expected_qty := p_mtl_maintain_rsv_rec.expected_quantity ;
854 END IF; -- end of expected qty uom <> primary qty uom su:06/15
855 -- get sum of all primary reservation quantity
856 -- intialize sum of primary reservation qty
857 l_sum_primary_reservation_qty := 0 ;
858 for i in 1..l_mtl_reservation_tbl_count loop
859 l_sum_primary_reservation_qty := l_sum_primary_reservation_qty +
860 l_mtl_reservation_tbl(i).primary_reservation_quantity ;
861 end loop;
862
863 l_primary_need_reduced_qty :=
864 l_sum_primary_reservation_qty - l_primary_expected_qty;
865 if g_debug= c_debug_enabled THEN
866 mydebug('Expectd Qty is not null', c_api_name,9);
867 mydebug('Total reserved qty: ' ||
868 l_sum_primary_reservation_qty, c_api_name,9);
869 mydebug('To be reduced qty: ' ||
870 l_primary_need_reduced_qty, c_api_name,9);
871 END IF;
872 -- dbms_output.put_line('primary need reduced qty' || l_primary_need_reduced_qty );
873 -- dbms_output.put_line('sum primary reservation qty' || l_sum_primary_reservation_qty );
874 -- dbms_output.put_line('primary expected qty' || l_primary_expected_qty );
875 -- end if; commented by satish
876 -- end if; -- end of expected qty uom <> primary qty uom su:06/15
877 end if; -- end of expected_quantity_uom is not null
878 else -- expected_qty is zero or null
879 if g_debug= c_debug_enabled THEN
880 mydebug('Expectd Qty is null', c_api_name,9);
881 mydebug('from primary txn qty: ' ||
882 p_mtl_maintain_rsv_rec.from_primary_txn_quantity,
883 c_api_name,9);
884 mydebug('from primary uom code: ' ||
885 p_mtl_maintain_rsv_rec.from_primary_uom_code,
886 c_api_name,9);
887 mydebug('from txn uom code: ' ||
888 p_mtl_maintain_rsv_rec.from_transaction_uom_code,
889 c_api_name,9);
890
891 END IF;
892 if p_mtl_maintain_rsv_rec.from_primary_txn_quantity is null or
893 p_mtl_maintain_rsv_rec.from_primary_txn_quantity = fnd_api.g_miss_num then
894 --codereview.su.16 check if from_transaction_uom_code and from_primary_uom_code
895 -- is not null, if they are then raise error
896
897 -- from_primary_uom_code column is a required column
898 check_reqd_param
899 (
900 p_param_value => p_mtl_maintain_rsv_rec.from_primary_uom_code,
901 p_param_name => 'p_mtl_maintain_rsv_rec.from_primary_uom_code',
902 p_api_name => c_api_name );
903
904 -- from_transaction_uom_code column is a required column
905 check_reqd_param
906 (
907 p_param_value => p_mtl_maintain_rsv_rec.from_transaction_uom_code,
908 p_param_name => 'p_mtl_maintain_rsv_rec.from_transaction_uom_code',
909 p_api_name => c_api_name );
910
911 if p_mtl_maintain_rsv_rec.from_transaction_uom_code <>
912 p_mtl_maintain_rsv_rec.from_primary_uom_code then
913 --codereview.su.17
914 l_from_primary_transaction_qty :=
915 inv_convert.inv_um_convert
916 (
917 item_id => p_mtl_maintain_rsv_rec.inventory_item_id,
918 precision => null,
919 from_quantity => p_mtl_maintain_rsv_rec.from_transaction_quantity,
920 from_unit => p_mtl_maintain_rsv_rec.from_transaction_uom_code,
921 to_unit => p_mtl_maintain_rsv_rec.from_primary_uom_code,
922 from_name => null,
923 to_name => null );
924 l_fnd_log_message := 'after calling api inv_convert.inv_um_convert 02:';
925 -- fnd_log_debug(fnd_log.level_event,c_module_name, l_fnd_log_message );
926 if g_debug= c_debug_enabled then
927 mydebug(l_fnd_log_message, c_api_name,9);
928 mydebug('from primary txn qty' || l_from_primary_transaction_qty, c_api_name,9);
929 end if;
930
931 end if; --check for transaction uom code
932 else --
933 if g_debug= c_debug_enabled then
934 mydebug('txn uom same as primary uom', c_api_name,9);
935
936 end if;
937 l_from_primary_transaction_qty := p_mtl_maintain_rsv_rec.from_primary_txn_quantity ;
938 end if; -- from transaction uom code
939 -- now check to_transaction_qty
940 if g_debug= c_debug_enabled THEN
941 mydebug('to primary txn qty: ' ||
942 p_mtl_maintain_rsv_rec.to_primary_txn_quantity,
943 c_api_name,9);
944 mydebug('to primary uom code: ' ||
945 p_mtl_maintain_rsv_rec.to_primary_uom_code,
946 c_api_name,9);
947 mydebug('to txn uom code: ' ||
948 p_mtl_maintain_rsv_rec.to_transaction_uom_code,
949 c_api_name,9);
950
951 END IF;
952 if p_mtl_maintain_rsv_rec.to_primary_txn_quantity is null or
953 p_mtl_maintain_rsv_rec.to_primary_txn_quantity = fnd_api.g_miss_num then
954 -- to_primary_uom_code column is a required column
955 check_reqd_param
956 (
957 p_param_value => p_mtl_maintain_rsv_rec.to_primary_uom_code,
958 p_param_name => 'p_mtl_maintain_rsv_rec.to_primary_uom_code',
959 p_api_name => c_api_name );
960
961 -- to_transaction_uom_code column is a required column
962 check_reqd_param
963 (
964 p_param_value => p_mtl_maintain_rsv_rec.to_transaction_uom_code,
965 p_param_name => 'p_mtl_maintain_rsv_rec.to_transaction_uom_code',
966 p_api_name => c_api_name );
967
968 if p_mtl_maintain_rsv_rec.to_transaction_uom_code <>
969 p_mtl_maintain_rsv_rec.to_primary_uom_code then
970 l_to_primary_transaction_qty :=
971 inv_convert.inv_um_convert
972 (
973 item_id => p_mtl_maintain_rsv_rec.inventory_item_id,
974 precision => null,
975 from_quantity => p_mtl_maintain_rsv_rec.to_transaction_quantity,
976 from_unit => p_mtl_maintain_rsv_rec.to_transaction_uom_code,
977 to_unit => p_mtl_maintain_rsv_rec.to_primary_uom_code,
978 from_name => null,
979 to_name => null );
980 l_fnd_log_message := 'after calling api inv_convert.inv_um_convert 03:';
981 -- fnd_log_debug(fnd_log.level_event,c_module_name, l_fnd_log_message );
982 if g_debug= c_debug_enabled then
983 mydebug(l_fnd_log_message, c_api_name,9);
984 mydebug('After convert to primary txn qty: '|| l_to_primary_transaction_qty, c_api_name,9);
985 end if;
986
987 else -- to_transaction_uom_code <> to_primary_uom_code
988 --codereview.su.20 added else statement
989 if g_debug= c_debug_enabled then
990 mydebug('to txn uom same as to primary uom', c_api_name,9);
991
992 end if;
993 l_to_primary_transaction_qty := p_mtl_maintain_rsv_rec.to_primary_txn_quantity ;
994 end if; --to-transaction_uom_code <> to_primary_uom_code
995 end if; --check for transaction uom code
996
997 l_primary_need_reduced_qty := l_to_primary_transaction_qty -
998 l_from_primary_transaction_qty;
999 if g_debug= c_debug_enabled then
1000 mydebug('From primary txn qty' || l_from_primary_transaction_qty, c_api_name,9);
1001 mydebug('to primary txn qty' ||
1002 l_to_primary_transaction_qty, c_api_name,9);
1003 mydebug('Need to reduce qty' || l_primary_need_reduced_qty, c_api_name,9);
1004 end if;
1005 end if; -- end of checking expected_qty value
1006
1007 x_quantity_modified := 0;
1008 l_primary_need_reduced_qty := Nvl(l_primary_need_reduced_qty,0);
1009 -- loop through all the records
1010
1011 for i in 1..l_mtl_reservation_tbl_count loop
1012 -- dbms_output.put_line('looping through reservation records');
1013 if l_mtl_reservation_tbl(i).supply_source_type_id
1014 = inv_reservation_global.g_source_type_inv
1015 and nvl(l_mtl_reservation_tbl(i).staged_flag, 'N') = 'Y' then
1016 -- skip record
1017 -- dbms_output.put_line('skipping record');
1018 null;
1019 if g_debug= c_debug_enabled then
1020 mydebug('Skipped record as staged flag is null', c_api_name,9);
1021 END IF;
1022 else -- supply_souce_type is inv
1023 -- dbms_output.put_line('looping through reservation table');
1024 if l_primary_need_reduced_qty = 0 then
1025 exit;
1026 end if;
1027 -- dbms_output.put_line('primary need reduced qty := ' || l_primary_need_reduced_qty );
1028 -- added following line : su:06/15/05
1029 l_original_rsv_rec := l_mtl_reservation_tbl(i) ;
1030 IF g_debug= c_debug_enabled then
1031 mydebug('Reservation records primary reservation qty' ||
1032 l_mtl_reservation_tbl(i).primary_reservation_quantity,
1033 c_api_name,9);
1034 mydebug('l_primary_need_reduced_qty' || l_primary_need_reduced_qty, c_api_name,9);
1035 END IF;
1036
1037 IF Nvl(l_mtl_reservation_tbl(i).primary_reservation_quantity,0) > l_primary_need_reduced_qty then
1038 -- call update reservation api
1039 -- dbms_output.put_line('calling update reservation api');
1040 if p_mtl_maintain_rsv_rec.action = c_action_supply then
1041 l_to_rsv_rec.supply_source_type_id := l_mtl_reservation_tbl(i).supply_source_type_id ;
1042 l_to_rsv_rec.supply_source_header_id:= l_mtl_reservation_tbl(i).supply_source_header_id;
1043 l_to_rsv_rec.supply_source_line_id:= l_mtl_reservation_tbl(i).supply_source_line_id;
1044 l_to_rsv_rec.supply_source_line_detail:=
1045 l_mtl_reservation_tbl(i).supply_source_line_detail;
1046
1047 l_is_transfer_supply := fnd_api.g_true ;
1048 else
1049 l_to_rsv_rec.demand_source_type_id := l_mtl_reservation_tbl(i).demand_source_type_id ;
1050 l_to_rsv_rec.demand_source_header_id:= l_mtl_reservation_tbl(i).demand_source_header_id;
1051 l_to_rsv_rec.demand_source_line_id:= l_mtl_reservation_tbl(i).demand_source_line_id;
1052 l_to_rsv_rec.demand_source_delivery := null;
1053 l_is_transfer_supply := fnd_api.g_false;
1054 end if;
1055 l_to_rsv_rec.primary_reservation_quantity :=
1056 Nvl(l_mtl_reservation_tbl(i).primary_reservation_quantity,0) - l_primary_need_reduced_qty;
1057 IF g_debug= c_debug_enabled then
1058 mydebug('Update reservation', c_api_name,9);
1059 mydebug('Update qty' || l_primary_need_reduced_qty, c_api_name,9);
1060 END IF;
1061 inv_reservation_pvt.update_reservation
1062 (
1063 p_api_version_number => 1.0,
1064 p_init_msg_lst => fnd_api.g_false,
1065 x_return_status => x_return_status,
1066 x_msg_count => x_msg_count,
1067 x_msg_data => x_msg_data ,
1068 p_original_rsv_rec => l_original_rsv_rec,
1069 p_to_rsv_rec => l_to_rsv_rec,
1070 p_original_serial_number => l_original_serial_number,
1071 p_to_serial_number => l_to_serial_number,
1072 p_validation_flag => fnd_api.g_true ,
1073 p_check_availability => fnd_api.g_false );
1074
1075 -- check if delete reservation has raised any errors, if so raise exception
1076 if x_return_status = fnd_api.g_ret_sts_error then
1077 l_fnd_log_message := 'error while calling update reservation api 02:';
1078 -- fnd_log_debug(fnd_log.level_error,c_module_name, l_fnd_log_message );
1079 if g_debug= c_debug_enabled then
1080 mydebug(l_fnd_log_message, c_api_name,9);
1081 end if;
1082 raise fnd_api.g_exc_error;
1083 elsif x_return_status = fnd_api.g_ret_sts_unexp_error then
1084 l_fnd_log_message := 'error while calling update reservation api 02:';
1085 -- fnd_log_debug(fnd_log.level_error,c_module_name, l_fnd_log_message );
1086 if g_debug= c_debug_enabled then
1087 mydebug(l_fnd_log_message, c_api_name,9);
1088 end if;
1089 raise fnd_api.g_exc_unexpected_error;
1090 elsif x_return_status = fnd_api.g_ret_sts_success then
1091 l_fnd_log_message := 'calling update reservation api was successful -02:';
1092 -- fnd_log_debug(fnd_log.level_error,c_module_name, l_fnd_log_message );
1093 if g_debug= c_debug_enabled then
1094 mydebug(l_fnd_log_message, c_api_name,9);
1095 end if;
1096 end if;
1097 x_quantity_modified := x_quantity_modified + l_primary_need_reduced_qty ;
1098 l_primary_need_reduced_qty := 0;
1099
1100 ELSIF (Nvl(l_mtl_reservation_tbl(i).primary_reservation_quantity,0) <= l_primary_need_reduced_qty) THEN -- reservation_qty < primary_need_reduced_qty
1101 -- call delete reservation
1102 IF g_debug= c_debug_enabled then
1103 mydebug('Call delete reservation for reservation id' || l_mtl_reservation_tbl(i).reservation_id, c_api_name,9);
1104 END IF;
1105 l_original_rsv_rec.reservation_id := l_mtl_reservation_tbl(i).reservation_id ;
1106 -- not assigning any values to l_original_serial_number as it does not matter
1107 -- dbms_output.put_line('calling delete reservation api');
1108 inv_reservation_pvt.delete_reservation
1109 (
1110 p_api_version_number => 1.0,
1111 p_init_msg_lst => fnd_api.g_false,
1112 x_return_status => x_return_status,
1113 x_msg_count => x_msg_count,
1114 x_msg_data => x_msg_data ,
1115 p_rsv_rec => l_original_rsv_rec,
1116 p_original_serial_number => l_original_serial_number,
1117 p_validation_flag => fnd_api.g_true );
1118
1119 -- check if delete reservation has raised any errors, if so raise exception
1120 if x_return_status = fnd_api.g_ret_sts_error then
1121 l_fnd_log_message := 'error while calling delete reservation api 02:';
1122 -- fnd_log_debug(fnd_log.level_error,c_module_name, l_fnd_log_message );
1123 if g_debug= c_debug_enabled then
1124 mydebug(l_fnd_log_message, c_api_name,9);
1125 end if;
1126 raise fnd_api.g_exc_error;
1127 elsif x_return_status = fnd_api.g_ret_sts_unexp_error then
1128 l_fnd_log_message := 'error while calling delete reservation api 02:';
1129 ---- fnd_log_debug(fnd_log.level_error,c_module_name, l_fnd_log_message );
1130 if g_debug= c_debug_enabled then
1131 mydebug(l_fnd_log_message, c_api_name,9);
1132 end if;
1133 raise fnd_api.g_exc_unexpected_error;
1134 elsif x_return_status = fnd_api.g_ret_sts_success then
1135 l_fnd_log_message := 'calling delete reservation api was successful -02:';
1136 -- fnd_log_debug(fnd_log.level_error,c_module_name, l_fnd_log_message );
1137 if g_debug= c_debug_enabled then
1138 mydebug(l_fnd_log_message, c_api_name,9);
1139 end if;
1140 l_primary_need_reduced_qty := Nvl(l_primary_need_reduced_qty,0) -
1141 Nvl(l_mtl_reservation_tbl(i).primary_reservation_quantity,0) ;
1142 x_quantity_modified := x_quantity_modified +
1143 Nvl(l_mtl_reservation_tbl(i).primary_reservation_quantity,0) ;
1144 end if; -- end of checking return status
1145 end if; -- reservation_qty > primary_need_reduced_qty
1146 end if; -- if source type id = inv
1147 end loop ;
1148
1149 -- dbms_output.put_line('end of looping through reservation table');
1150 /*******satish01**
1151 else
1152 l_to_primary_transaction_qty := p_mtl_maintain_rsv_rec.to_primary_txn_quantity ;
1153 end if;
1154 -- moving this line up
1155 -- end if; -- end of checking expected_qty value
1156 **************satish ***/
1157 end if; -- p_delete_flag = y
1158
1159 -- call fnd_log api at the end of the api
1160 l_fnd_log_message := 'at the end of procedure :';
1161 -- -- fnd_log_debug(fnd_log.level_procedure,c_module_name, l_fnd_log_message );
1162
1163 if g_debug= c_debug_enabled then
1164 mydebug(l_fnd_log_message, c_api_name,9);
1165 end if;
1166 exception
1167 when fnd_api.g_exc_error then
1168 x_return_status := fnd_api.g_ret_sts_error;
1169
1170 -- get message count and data
1171 fnd_msg_pub.count_and_get
1172 ( p_count => x_msg_count
1173 , p_data => x_msg_data
1174 );
1175
1176 -- call fnd_log api at the end of the api
1177 l_fnd_log_message := 'when expected exception raised for procedure :' ;
1178 -- fnd_log_debug(fnd_log.level_error,c_module_name, l_fnd_log_message );
1179
1180 -- log message in trace file
1181 if g_debug= c_debug_enabled then
1182 mydebug(l_fnd_log_message,c_api_name,9);
1183 end if;
1184
1185 -- get messages from stack and log them in fnd tables
1186 if x_msg_count = 1 then
1187 -- fnd_log_debug(fnd_log.level_error,c_module_name, x_msg_data );
1188 -- log message in trace file
1189 if g_debug= c_debug_enabled then
1190 mydebug(l_fnd_log_message,c_api_name,9);
1191 end if;
1192 elsif x_msg_count > 1 then
1193 for i in 1..x_msg_count loop
1194 fnd_msg_pub.get
1195 (p_msg_index => i,
1196 p_encoded => 'f',
1197 p_data => l_fnd_log_message,
1198 p_msg_index_out => l_msg_index_out );
1199
1200 -- fnd_log_debug(fnd_log.level_error,c_module_name, l_fnd_log_message );
1201
1202 -- log message in trace file
1203 if g_debug= c_debug_enabled then
1204 mydebug(l_fnd_log_message,c_api_name,9);
1205 end if;
1206 end loop ;
1207 end if;
1208
1209
1210 when fnd_api.g_exc_unexpected_error then
1211 x_return_status := fnd_api.g_ret_sts_unexp_error ;
1212
1213 -- get message count and data
1214 fnd_msg_pub.count_and_get
1215 ( p_count => x_msg_count
1216 , p_data => x_msg_data
1217 );
1218 -- call fnd_log api at the end of the api
1219 l_fnd_log_message := 'when unexpected exception raised for procedure :';
1220 -- fnd_log_debug(fnd_log.level_error,c_module_name, l_fnd_log_message );
1221
1222 -- log message in trace file
1223 if g_debug= c_debug_enabled then
1224 mydebug(l_fnd_log_message,c_api_name,9);
1225 end if;
1226
1227 -- get messages from stack and log them in fnd tables
1228 if x_msg_count = 1 then
1229 -- fnd_log_debug(fnd_log.level_error,c_module_name, x_msg_data );
1230
1231 -- log message in trace file
1232 if g_debug= c_debug_enabled then
1233 mydebug(l_fnd_log_message,c_api_name,9);
1234 end if;
1235 elsif x_msg_count > 1 then
1236 for i in 1..x_msg_count loop
1237 fnd_msg_pub.get
1238 (p_msg_index => i,
1239 p_encoded => 'f',
1240 p_data => l_fnd_log_message,
1241 p_msg_index_out => l_msg_index_out );
1242
1243 -- fnd_log_debug(fnd_log.level_error,c_module_name, l_fnd_log_message );
1244
1245 -- log message in trace file
1246 if g_debug= c_debug_enabled then
1247 mydebug(l_fnd_log_message,c_api_name,9);
1248 end if;
1249 end loop ;
1250 end if;
1251
1252 when others then
1253 x_return_status := fnd_api.g_ret_sts_unexp_error ;
1254
1255 if fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error)
1256 then
1257 fnd_msg_pub.add_exc_msg
1258 ( g_pkg_name
1259 , c_api_name
1260 );
1261 end if;
1262
1263 -- get message count and data
1264 fnd_msg_pub.count_and_get
1265 ( p_count => x_msg_count
1266 , p_data => x_msg_data
1267 );
1268
1269 -- call fnd_log api at the end of the api
1270 l_fnd_log_message := 'when others exception raised for procedure :' || g_pkg_name || '.' || c_api_name ;
1271 -- fnd_log_debug(fnd_log.level_error,c_module_name, l_fnd_log_message );
1272
1273 -- log message in trace file
1274 if g_debug= c_debug_enabled then
1275 mydebug(l_fnd_log_message,c_api_name,9);
1276 end if;
1277
1278 -- get messages from stack and log them in fnd tables
1279 if x_msg_count = 1 then
1280 -- fnd_log_debug(fnd_log.level_error,c_module_name, x_msg_data );
1281
1282 -- log message in trace file
1283 if g_debug= c_debug_enabled then
1284 mydebug(l_fnd_log_message,c_api_name,9);
1285 end if;
1286 elsif x_msg_count > 1 then
1287 for i in 1..x_msg_count loop
1288 fnd_msg_pub.get
1289 (p_msg_index => i,
1290 p_encoded => 'f',
1291 p_data => l_fnd_log_message,
1292 p_msg_index_out => l_msg_index_out );
1293
1294 -- fnd_log_debug(fnd_log.level_error,c_module_name, l_fnd_log_message );
1295
1296 -- log message in trace file
1297 if g_debug= c_debug_enabled then
1298 mydebug(l_fnd_log_message,c_api_name,9);
1299 end if;
1300 end loop ;
1301 end if;
1302
1303 end reduce_reservation;
1304 --this procedure initializes the reservation record - only done when a new requisition reservation
1305 --is created
1306 --
1307 procedure build_res_rec (x_reservation_rec out nocopy inv_reservation_global.mtl_reservation_rec_type)
1308 is
1309
1310 -- define constants for api version and api name
1311 c_api_version_number constant number := 1.0;
1312 c_api_name constant varchar2(30) := 'build_res_rec';
1313 c_module_name constant varchar2(2000) := 'inv.plsql.inv_maintain_reservation_pub';
1314 c_debug_enabled constant number := 1 ;
1315 l_fnd_log_message varchar2(2000);
1316
1317 l_rsv inv_reservation_global.mtl_reservation_rec_type;
1318
1319 begin
1320 --this procedure initializes the mtl_reservation record
1321 l_fnd_log_message := 'begining of procedure :';
1322 -- dbms_output.put_line('begining of procedure');
1323 -- fnd_log_debug(fnd_log.level_procedure, c_module_name, l_fnd_log_message);
1324
1325 -- log message in trace file
1326 if g_debug= c_debug_enabled then
1327 g_version_printed := true ;
1328 mydebug(l_fnd_log_message,c_api_name,9);
1329 g_version_printed := false ;
1330 end if;
1331
1332 l_rsv.reservation_id := null;
1333 l_rsv.requirement_date := null;
1334 l_rsv.organization_id := null; -- org id
1335 l_rsv.inventory_item_id := null; -- item id
1336 l_rsv.demand_source_type_id :=
1337 inv_reservation_global.g_source_type_oe; -- order entry
1338 l_rsv.demand_source_name := null;
1339 l_rsv.demand_source_header_id := null; -- oe order number
1340 l_rsv.demand_source_line_id := null; -- oe order line number
1341 l_rsv.demand_source_delivery := null;
1342 l_rsv.primary_uom_code := null; --10
1343 l_rsv.primary_uom_id := null;
1344 l_rsv.reservation_uom_code := null;
1345 l_rsv.reservation_uom_id := null;
1346 l_rsv.reservation_quantity := null;
1347 l_rsv.primary_reservation_quantity := null; -- reservation quantity
1348
1349 l_rsv.detailed_quantity := null;
1350 l_rsv.secondary_uom_code := null;
1351 l_rsv.secondary_uom_id := null;
1352 l_rsv.secondary_reservation_quantity := null;
1353 l_rsv.secondary_detailed_quantity := null; --20
1354
1355 l_rsv.autodetail_group_id := null;
1356 l_rsv.external_source_code := null;
1357 l_rsv.external_source_line_id := null;
1358 l_rsv.supply_source_type_id :=
1359 inv_reservation_global.g_source_type_req;
1360 l_rsv.supply_source_header_id := null; -- po req header id
1361 l_rsv.supply_source_line_id := null; -- po req line id
1362 l_rsv.supply_source_name := null;
1363 l_rsv.supply_source_line_detail := null;
1364 l_rsv.revision := null;
1365 l_rsv.subinventory_code := null; --30
1366 l_rsv.subinventory_id := null;
1367 l_rsv.locator_id := null;
1368 l_rsv.lot_number := null;
1369 l_rsv.lot_number_id := null;
1370 l_rsv.pick_slip_number := null;
1371 l_rsv.lpn_id := null;
1372 l_rsv.attribute_category := null;
1373 l_rsv.attribute1 := null;
1374 l_rsv.attribute2 := null;
1375 l_rsv.attribute3 := null; --40
1376 l_rsv.attribute4 := null;
1377 l_rsv.attribute5 := null;
1378 l_rsv.attribute6 := null;
1379 l_rsv.attribute7 := null;
1380 l_rsv.attribute8 := null;
1381 l_rsv.attribute9 := null;
1382 l_rsv.attribute10 := null;
1383 l_rsv.attribute11 := null;
1384 l_rsv.attribute12 := null;
1385 l_rsv.attribute13 := null; --50
1386 l_rsv.attribute14 := null;
1387 l_rsv.attribute15 := null;
1388 l_rsv.ship_ready_flag := null;
1389 l_rsv.staged_flag := null;
1390
1391 l_rsv.crossdock_flag := null;
1392 l_rsv.crossdock_criteria_id := null;
1393 l_rsv.demand_source_line_detail := null;
1394 l_rsv.serial_reservation_quantity := null;
1395 l_rsv.supply_receipt_date := null;
1396 l_rsv.demand_ship_date := null; --60
1397 l_rsv.project_id := null;
1398 l_rsv.task_id := null;
1399 l_rsv.orig_supply_source_type_id := null;
1400 l_rsv.orig_supply_source_header_id := null;
1401 l_rsv.orig_supply_source_line_id := null;
1402 l_rsv.orig_supply_source_line_detail := null;
1403 l_rsv.orig_demand_source_type_id := null;
1404 l_rsv.orig_demand_source_header_id := null;
1405 l_rsv.orig_demand_source_line_id := null;
1406 l_rsv.orig_demand_source_line_detail := null; --70
1407 l_rsv.serial_number := null; --71
1408
1409 x_reservation_rec := l_rsv;
1410
1411 -- call fnd_log api at the end of the api
1412 l_fnd_log_message := 'at the end of procedure :';
1413 -- -- fnd_log_debug(fnd_log.level_procedure,c_module_name, l_fnd_log_message );
1414
1415 if g_debug= c_debug_enabled then
1416 mydebug(l_fnd_log_message, c_api_name,9);
1417 end if;
1418
1419 exception
1420 when others then
1421 l_fnd_log_message := 'when others exception raised for procedure :' || g_pkg_name || '.' || c_api_name ;
1422 -- fnd_log_debug(fnd_log.level_error,c_module_name, l_fnd_log_message );
1423
1424 -- log message in trace file
1425 if g_debug= c_debug_enabled then
1426 mydebug(l_fnd_log_message,c_api_name,9);
1427 end if;
1428 end;
1429
1430
1431 -- procedure create_res calls the inventory api create_reservation with the appropriate parameters
1432 --
1433 --
1434 procedure create_res
1435 (p_inventory_item_id in number
1436 ,p_organization_id in number
1437 ,p_demand_source_header_id in number
1438 ,p_demand_source_line_id in NUMBER
1439 ,p_supply_source_type_id IN NUMBER
1440 ,p_supply_source_header_id in number
1441 ,p_supply_source_line_id in number
1442 ,p_requirement_date in date
1443 ,p_reservation_quantity in number
1444 ,p_reservation_uom_code in varchar2
1445 ,p_project_id in number
1446 ,p_task_id in number
1447 ,x_msg_count out nocopy number
1448 ,x_msg_data out nocopy varchar2
1449 ,x_return_status out nocopy varchar2)
1450 is
1451
1452 -- define constants for api version and api name
1453 c_api_version_number constant number := 1.0;
1454 c_api_name constant varchar2(30) := 'create_res';
1455 c_module_name constant varchar2(2000) := 'inv.plsql.inv_maintain_reservation_pub.maintain_reservation';
1456 c_debug_enabled constant number := 1 ;
1457
1458 --l_debug number := nvl(fnd_profile.value('inv_debug_trace'), 0);
1459 l_fnd_log_message varchar2(2000);
1460 l_msg_index_out number;
1461
1462 l_rsv inv_reservation_global.mtl_reservation_rec_type;
1463 l_return_status varchar2(1);
1464 --l_msg_count number := 0;
1465 --l_msg_data varchar2(2000);
1466 l_qty number;
1467 l_second_qty number;
1468 l_rsv_id number;
1469 l_demand_source_type_id number;
1470 begin
1471 l_fnd_log_message := 'begining of procedure :';
1472 -- dbms_output.put_line('begining of procedure');
1473 -- fnd_log_debug(fnd_log.level_procedure, c_module_name, l_fnd_log_message);
1474
1475 -- log message in trace file
1476 if g_debug= c_debug_enabled then
1477 g_version_printed := true ;
1478 mydebug(l_fnd_log_message,c_api_name,9);
1479 g_version_printed := false ;
1480 end if;
1481
1482 -- bug 3600118: initialize return status variable
1483 l_return_status := fnd_api.g_ret_sts_success;
1484
1485 build_res_rec(x_reservation_rec =>l_rsv);
1486
1487 l_rsv.inventory_item_id := p_inventory_item_id;
1488 l_rsv.organization_id := p_organization_id;
1489 l_rsv.demand_source_header_id := p_demand_source_header_id;
1490 l_rsv.demand_source_line_id := p_demand_source_line_id;
1491 l_rsv.supply_source_header_id := p_supply_source_header_id;
1492 l_rsv.supply_source_line_id := p_supply_source_line_id;
1493 l_rsv.requirement_date := p_requirement_date;
1494 l_rsv.reservation_quantity := p_reservation_quantity;
1495 l_rsv.reservation_uom_code := p_reservation_uom_code;
1496 l_rsv.project_id := p_project_id;
1497 l_rsv.task_id := p_task_id;
1498 --
1499 --for internal sales order the demand source needs to be of type internal order
1500 --for creating a reservation. we removed the call to cto_util to remove the
1501 --dependency between po and cto
1502 -- l_source_document_type_id :=
1503 -- cto_utility_pk.get_source_document_id (plineid => p_demand_source_line_id );
1504
1505 if g_debug= c_debug_enabled then
1506 l_fnd_log_message := 'progress 100';
1507 mydebug(l_fnd_log_message,c_api_name,9);
1508 end if;
1509
1510 select decode (h.source_document_type_id, 10,
1511 inv_reservation_global.g_source_type_internal_ord,
1512 inv_reservation_global.g_source_type_oe )
1513 into l_demand_source_type_id
1514 from oe_order_headers_all h, oe_order_lines_all l
1515 where h.header_id = l.header_id
1516 and l.line_id = p_demand_source_line_id;
1517
1518 l_rsv.demand_source_type_id := l_demand_source_type_id;
1519 l_rsv.supply_source_type_id := p_supply_source_type_id;
1520
1521 if g_debug= c_debug_enabled then
1522 l_fnd_log_message := 'progress 200';
1523 mydebug(l_fnd_log_message,c_api_name,9);
1524 end if;
1525
1526 inv_reservation_pvt.create_reservation
1527 (
1528 p_api_version_number => 1.0
1529 , p_init_msg_lst => fnd_api.g_false
1530 , x_return_status => l_return_status
1531 , x_msg_count => x_msg_count
1532 , x_msg_data => x_msg_data
1533 , p_rsv_rec => l_rsv
1534 , p_serial_number => g_dummy_sn_tbl
1535 , x_serial_number => g_dummy_sn_tbl
1536 , p_partial_reservation_flag => fnd_api.g_true
1537 , p_force_reservation_flag => fnd_api.g_false
1538 , p_validation_flag => fnd_api.g_true
1539 --, p_validation_flag => fnd_api.g_false
1540 , x_quantity_reserved => l_qty
1541 , x_secondary_quantity_reserved => l_second_qty
1542 , x_reservation_id => l_rsv_id
1543 );
1544
1545 if g_debug= c_debug_enabled then
1546 l_fnd_log_message := 'l_return_status: '||l_return_status;
1547 mydebug(l_fnd_log_message,c_api_name,9);
1548 end if;
1549
1550 x_return_status := l_return_status;
1551
1552 if x_return_status = fnd_api.g_ret_sts_success then
1553 l_fnd_log_message := 'calling create_reservation api was successful ';
1554 -- fnd_log_debug(fnd_log.level_error,c_module_name, l_fnd_log_message );
1555 if g_debug= c_debug_enabled then
1556 mydebug(l_fnd_log_message, c_api_name,9);
1557 end if;
1558 else
1559 l_fnd_log_message := 'error while calling create_reservation api ';
1560 -- fnd_log_debug(fnd_log.level_error,c_module_name, l_fnd_log_message );
1561 if g_debug= c_debug_enabled then
1562 mydebug(l_fnd_log_message, c_api_name,9);
1563 end if;
1564 end if;
1565
1566 -- call fnd_log api at the end of the api
1567 l_fnd_log_message := 'at the end of procedure :';
1568 -- -- fnd_log_debug(fnd_log.level_procedure,c_module_name, l_fnd_log_message );
1569
1570 if g_debug= c_debug_enabled then
1571 mydebug(l_fnd_log_message, c_api_name,9);
1572 end if;
1573
1574 exception
1575 when fnd_api.g_exc_error then
1576 x_return_status := fnd_api.g_ret_sts_error;
1577
1578 -- get message count and data
1579 fnd_msg_pub.count_and_get
1580 ( p_count => x_msg_count
1581 , p_data => x_msg_data
1582 );
1583
1584 -- call fnd_log api at the end of the api
1585 l_fnd_log_message := 'when expected exception raised for procedure :' ;
1586 -- fnd_log_debug(fnd_log.level_error,c_module_name, l_fnd_log_message );
1587
1588 -- log message in trace file
1589 if g_debug= c_debug_enabled then
1590 mydebug(l_fnd_log_message,c_api_name,9);
1591 end if;
1592
1593 -- get messages from stack and log them in fnd tables
1594 if x_msg_count = 1 then
1595 -- fnd_log_debug(fnd_log.level_error,c_module_name, x_msg_data );
1596 -- log message in trace file
1597 if g_debug= c_debug_enabled then
1598 mydebug(l_fnd_log_message,c_api_name,9);
1599 end if;
1600 elsif x_msg_count > 1 then
1601 for i in 1..x_msg_count loop
1602 fnd_msg_pub.get
1603 (p_msg_index => i,
1604 p_encoded => 'f',
1605 p_data => l_fnd_log_message,
1606 p_msg_index_out => l_msg_index_out );
1607
1608 -- fnd_log_debug(fnd_log.level_error,c_module_name, l_fnd_log_message );
1609
1610 -- log message in trace file
1611 if g_debug= c_debug_enabled then
1612 mydebug(l_fnd_log_message,c_api_name,9);
1613 end if;
1614 end loop ;
1615 end if;
1616
1617
1618 when fnd_api.g_exc_unexpected_error then
1619 x_return_status := fnd_api.g_ret_sts_unexp_error ;
1620
1621 -- get message count and data
1622 fnd_msg_pub.count_and_get
1623 ( p_count => x_msg_count
1624 , p_data => x_msg_data
1625 );
1626 -- call fnd_log api at the end of the api
1627 l_fnd_log_message := 'when unexpected exception raised for procedure :';
1628 -- fnd_log_debug(fnd_log.level_error,c_module_name, l_fnd_log_message );
1629
1630 -- log message in trace file
1631 if g_debug= c_debug_enabled then
1632 mydebug(l_fnd_log_message,c_api_name,9);
1633 end if;
1634
1635 -- get messages from stack and log them in fnd tables
1636 if x_msg_count = 1 then
1637 -- fnd_log_debug(fnd_log.level_error,c_module_name, x_msg_data );
1638
1639 -- log message in trace file
1640 if g_debug= c_debug_enabled then
1641 mydebug(l_fnd_log_message,c_api_name,9);
1642 end if;
1643 elsif x_msg_count > 1 then
1644 for i in 1..x_msg_count loop
1645 fnd_msg_pub.get
1646 (p_msg_index => i,
1647 p_encoded => 'f',
1648 p_data => l_fnd_log_message,
1649 p_msg_index_out => l_msg_index_out );
1650
1651 -- fnd_log_debug(fnd_log.level_error,c_module_name, l_fnd_log_message );
1652
1653 -- log message in trace file
1654 if g_debug= c_debug_enabled then
1655 mydebug(l_fnd_log_message,c_api_name,9);
1656 end if;
1657 end loop ;
1658 end if;
1659
1660 when others then
1661 x_return_status := fnd_api.g_ret_sts_unexp_error ;
1662
1663 if fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error)
1664 then
1665 fnd_msg_pub.add_exc_msg
1666 ( g_pkg_name
1667 , c_api_name
1668 );
1669 END IF;
1670
1671 -- Get message count and data
1672 fnd_msg_pub.count_and_get
1673 ( p_count => x_msg_count
1674 , p_data => x_msg_data
1675 );
1676
1677 -- Call fnd_log api at the end of the API
1678 l_Fnd_Log_message := 'When Others exception raised for procedure :' || G_Pkg_Name || '.' || C_API_Name ;
1679 -- Fnd_Log_Debug(fnd_log.Level_Error,C_Module_name, l_Fnd_Log_Message );
1680
1681 -- Log message in trace file
1682 IF G_debug= C_Debug_Enabled THEN
1683 mydebug(l_Fnd_Log_Message,c_api_name,9);
1684 END IF;
1685
1686 -- Get messages from stack and log them in fnd tables
1687 If X_Msg_Count = 1 Then
1688 -- Fnd_Log_Debug(fnd_log.Level_Error,C_Module_name, X_Msg_Data );
1689
1690 -- Log message in trace file
1691 If G_debug= C_Debug_Enabled Then
1692 mydebug(l_Fnd_Log_Message,c_api_name,9);
1693 End If;
1694 Elsif X_Msg_Count > 1 Then
1695 For I In 1..X_Msg_Count Loop
1696 FND_MSG_PUB.Get
1697 (p_msg_index => i,
1698 p_encoded => 'F',
1699 p_data => l_Fnd_Log_Message,
1700 p_msg_index_out => l_msg_index_out );
1701
1702 -- Fnd_Log_Debug(fnd_log.Level_Error,C_Module_name, l_Fnd_Log_Message );
1703
1704 -- Log message in trace file
1705 IF G_debug= C_Debug_Enabled THEN
1706 mydebug(l_Fnd_Log_Message,c_api_name,9);
1707 END IF;
1708 End Loop ;
1709 End If;
1710 END;
1711
1712 --
1713 --this procedure calls inventory API query_reservation with the appropriate parameters
1714 --
1715 PROCEDURE QUERY_RES
1716 (p_supply_source_header_id IN NUMBER DEFAULT NULL
1717 ,p_supply_source_line_id IN NUMBER DEFAULT NULL
1718 ,p_supply_source_type_id IN NUMBER
1719 ,p_project_id IN NUMBER
1720 ,p_task_id IN NUMBER
1721 ,x_rsv_array OUT NOCOPY inv_reservation_global.mtl_reservation_tbl_type
1722 ,x_record_count OUT NOCOPY NUMBER
1723 ,x_msg_count OUT NOCOPY NUMBER
1724 ,x_msg_data OUT NOCOPY VARCHAR2
1725 ,x_return_status OUT NOCOPY VARCHAR2)
1726 IS
1727 -- Define Constants for API version and API name
1728 C_api_version_number CONSTANT NUMBER := 1.0;
1729 C_api_name CONSTANT VARCHAR2(30) := 'QUERY_RES';
1730 C_Module_Name Constant Varchar2(2000) := 'inv.plsql.inv_maintain_reservation_pub.maintain_reservation';
1731 C_Debug_Enabled Constant Number := 1 ;
1732
1733 --l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
1734 l_Fnd_Log_Message VARCHAR2(2000);
1735 l_Msg_Index_Out Number;
1736
1737 l_rsv_rec inv_reservation_global.mtl_reservation_rec_type;
1738 --l_msg_count NUMBER;
1739 --l_msg_data VARCHAR2(240);
1740 l_rsv_id NUMBER;
1741 l_return_status VARCHAR2(1);
1742 l_error_code NUMBER;
1743 l_rsv_array inv_reservation_global.mtl_reservation_tbl_type;
1744 l_record_count NUMBER;
1745 l_error_text VARCHAR2(2000);
1746 BEGIN
1747 l_Fnd_Log_message := 'Begining of procedure :';
1748 -- Dbms_output.Put_line('Begining Of Procedure');
1749 -- Fnd_Log_Debug(Fnd_Log.Level_Procedure, C_Module_name, l_Fnd_Log_Message);
1750
1751 -- Log message in trace file
1752 IF G_debug= C_Debug_Enabled THEN
1753 G_Version_Printed := TRUE ;
1754 mydebug(l_Fnd_Log_Message,c_api_name,9);
1755 G_Version_Printed := FALSE ;
1756 END IF;
1757
1758 -- Bug 3600118: Initialize return status variable
1759 l_return_status := FND_API.g_ret_sts_success;
1760
1761 IF p_supply_source_header_id is not null THEN
1762 l_rsv_rec.supply_source_header_id := p_supply_source_header_id; --supply header id
1763 END IF;
1764
1765 IF p_supply_source_line_id is not null THEN
1766 l_rsv_rec.supply_source_line_id := p_supply_source_line_id; -- supply line id
1767 END IF;
1768
1769 IF p_supply_source_type_id IS NULL THEN
1770 FND_MESSAGE.SET_NAME('INV','INV_API_NULL_SOURCE_TYPE_ID');
1771 FND_MSG_PUB.Add;
1772 RAISE fnd_api.g_exc_unexpected_error;
1773 ELSIF p_supply_source_type_id NOT IN
1774 (inv_reservation_global.g_source_type_po,
1775 inv_reservation_global.g_source_type_internal_req,
1776 inv_reservation_global.g_source_type_req) THEN
1777 FND_MESSAGE.SET_NAME('INV','INV_API_INVALID_SOURCE_TYPE_ID');
1778 FND_MSG_PUB.Add;
1779 RAISE fnd_api.g_exc_unexpected_error;
1780 END IF;
1781
1782 IF p_project_id is not null THEN
1783 l_rsv_rec.project_id := p_project_id; -- project id
1784 END IF;
1785
1786 IF p_task_id is not null THEN
1787 l_rsv_rec.task_id := p_task_id; -- task id
1788 END IF;
1789
1790 l_rsv_rec.supply_source_type_id := p_supply_source_type_id;
1791
1792 inv_reservation_pvt.query_reservation
1793 (
1794 p_api_version_number => 1.0
1795 , p_init_msg_lst => fnd_api.g_false
1796 , x_return_status => l_return_status
1797 , x_msg_count => x_msg_count
1798 , x_msg_data => x_msg_data
1799 , p_query_input => l_rsv_rec
1800 , p_lock_records => fnd_api.g_false
1801 , p_sort_by_req_date => inv_reservation_global.g_query_demand_ship_date_asc
1802 , p_cancel_order_mode => inv_reservation_global.g_cancel_order_no
1803 , x_mtl_reservation_tbl => l_rsv_array
1804 , x_mtl_reservation_tbl_count => l_record_count
1805 , x_error_code => l_error_code
1806 );
1807
1808 If g_debug= C_Debug_Enabled Then
1809 l_Fnd_Log_Message := 'l_return_status: '||l_return_status;
1810 mydebug(l_Fnd_Log_Message,c_api_name,9);
1811 End If;
1812
1813 x_return_status := l_return_status;
1814
1815 If x_return_status = fnd_api.g_ret_sts_success THEN
1816 l_Fnd_Log_message := 'Calling query_reservation API was successful ';
1817 -- Fnd_Log_Debug(fnd_log.Level_Error,C_Module_name, l_Fnd_Log_Message );
1818 x_rsv_array := l_rsv_array;
1819 x_record_count := l_record_count;
1820
1821 IF G_debug= C_Debug_Enabled THEN
1822 mydebug(l_Fnd_Log_Message, c_api_name,9);
1823 END IF;
1824 else
1825 l_Fnd_Log_message := 'Error while calling query_reservation API ';
1826 -- Fnd_Log_Debug(fnd_log.Level_Error,C_Module_name, l_Fnd_Log_Message );
1827 x_record_count := -1;
1828 IF G_debug= C_Debug_Enabled THEN
1829 mydebug(l_Fnd_Log_Message, c_api_name,9);
1830 END IF;
1831 end if;
1832
1833 -- Call fnd_log api at the end of the API
1834 l_Fnd_Log_message := 'At the end of procedure :';
1835 -- Fnd_Log_Debug(Fnd_Log.Level_Procedure,C_Module_name, l_Fnd_Log_Message );
1836
1837 IF G_debug= C_Debug_Enabled THEN
1838 mydebug(l_Fnd_Log_Message, c_api_name,9);
1839 END IF;
1840
1841
1842
1843 EXCEPTION
1844 WHEN fnd_api.g_exc_error THEN
1845 x_return_status := fnd_api.g_ret_sts_error;
1846 x_record_count := -1;
1847
1848 -- Get message count and data
1849 fnd_msg_pub.count_and_get
1850 ( p_count => x_msg_count
1851 , p_data => x_msg_data
1852 );
1853
1854 -- Call fnd_log api at the end of the API
1855 l_Fnd_Log_message := 'When Expected exception raised for procedure :' ;
1856 -- Fnd_Log_Debug(fnd_log.Level_Error,C_Module_name, l_Fnd_Log_Message );
1857
1858 -- Log message in trace file
1859 IF G_debug= C_Debug_Enabled THEN
1860 mydebug(l_Fnd_Log_Message,c_api_name,9);
1861 END IF;
1862
1863 -- Get messages from stack and log them in fnd tables
1864 If X_Msg_Count = 1 Then
1865 -- Fnd_Log_Debug(fnd_log.Level_Error,C_Module_name, X_Msg_Data );
1866 -- Log message in trace file
1867 If G_debug= C_Debug_Enabled THEN
1868 mydebug(l_Fnd_Log_Message,c_api_name,9);
1869 End If;
1870 Elsif x_msg_count > 1 Then
1871 For I In 1..X_Msg_Count Loop
1872 FND_MSG_PUB.Get
1873 (p_msg_index => i,
1874 p_encoded => 'F',
1875 p_data => l_Fnd_Log_Message,
1876 p_msg_index_out => l_msg_index_out );
1877
1878 -- Fnd_Log_Debug(fnd_log.Level_Error,C_Module_name, l_Fnd_Log_Message );
1879
1880 -- Log message in trace file
1881 IF G_debug= C_Debug_Enabled THEN
1882 mydebug(l_Fnd_Log_Message,c_api_name,9);
1883 END IF;
1884 End Loop ;
1885 End If;
1886
1887
1888 WHEN fnd_api.g_exc_unexpected_error THEN
1889 x_return_status := fnd_api.g_ret_sts_unexp_error ;
1890 x_record_count := -1;
1891
1892 -- Get message count and data
1893 fnd_msg_pub.count_and_get
1894 ( p_count => x_msg_count
1895 , p_data => x_msg_data
1896 );
1897 -- Call fnd_log api at the end of the API
1898 l_Fnd_Log_message := 'When unexpected exception raised for procedure :';
1899 -- Fnd_Log_Debug(fnd_log.Level_Error,C_Module_name, l_Fnd_Log_Message );
1900
1901 -- Log message in trace file
1902 IF G_debug= C_Debug_Enabled THEN
1903 mydebug(l_Fnd_Log_Message,c_api_name,9);
1904 END IF;
1905
1906 -- Get messages from stack and log them in fnd tables
1907 If X_Msg_Count = 1 Then
1908 -- Fnd_Log_Debug(fnd_log.Level_Error,C_Module_name, X_Msg_Data );
1909
1910 -- Log message in trace file
1911 IF G_debug= C_Debug_Enabled THEN
1912 mydebug(l_Fnd_Log_Message,c_api_name,9);
1913 END IF;
1914 Elsif X_Msg_Count > 1 Then
1915 For I In 1..X_Msg_Count Loop
1916 FND_MSG_PUB.Get
1917 (p_msg_index => i,
1918 p_encoded => 'F',
1919 p_data => l_Fnd_Log_Message,
1920 p_msg_index_out => l_msg_index_out );
1921
1922 -- Fnd_Log_Debug(fnd_log.Level_Error,C_Module_name, l_Fnd_Log_Message );
1923
1924 -- Log message in trace file
1925 IF G_debug= C_Debug_Enabled THEN
1926 mydebug(l_Fnd_Log_Message,c_api_name,9);
1927 END IF;
1928 End Loop ;
1929 End If;
1930
1931 WHEN OTHERS THEN
1932 x_return_status := fnd_api.g_ret_sts_unexp_error ;
1933 x_record_count := -1;
1934
1935 IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error)
1936 THEN
1937 fnd_msg_pub.add_exc_msg
1938 ( g_pkg_name
1939 , c_api_name
1940 );
1941 END IF;
1942
1943 -- Get message count and data
1944 fnd_msg_pub.count_and_get
1945 ( p_count => x_msg_count
1946 , p_data => x_msg_data
1947 );
1948
1949 -- Call fnd_log api at the end of the API
1950 l_Fnd_Log_message := 'When Others exception raised for procedure :' || G_Pkg_Name || '.' || C_API_Name ;
1951 -- Fnd_Log_Debug(fnd_log.Level_Error,C_Module_name, l_Fnd_Log_Message );
1952
1953 -- Log message in trace file
1954 IF G_debug= C_Debug_Enabled THEN
1955 mydebug(l_Fnd_Log_Message,c_api_name,9);
1956 END IF;
1957
1958 -- Get messages from stack and log them in fnd tables
1959 If X_Msg_Count = 1 Then
1960 -- Fnd_Log_Debug(fnd_log.Level_Error,C_Module_name, X_Msg_Data );
1961
1962 -- Log message in trace file
1963 If G_debug= C_Debug_Enabled Then
1964 mydebug(l_Fnd_Log_Message,c_api_name,9);
1965 End If;
1966 Elsif X_Msg_Count > 1 Then
1967 For I In 1..X_Msg_Count Loop
1968 FND_MSG_PUB.Get
1969 (p_msg_index => i,
1970 p_encoded => 'F',
1971 p_data => l_Fnd_Log_Message,
1972 p_msg_index_out => l_msg_index_out );
1973
1974 -- Fnd_Log_Debug(fnd_log.Level_Error,C_Module_name, l_Fnd_Log_Message );
1975
1976 -- Log message in trace file
1977 IF G_debug= C_Debug_Enabled THEN
1978 mydebug(l_Fnd_Log_Message,c_api_name,9);
1979 END IF;
1980 End Loop ;
1981 End If;
1982 END;
1983
1984
1985 --
1986 -- this procedure checks whether a reservation exists
1987 --
1988 FUNCTION EXISTS_RESERVATION( p_supply_source_header_id IN NUMBER DEFAULT NULL
1989 , p_supply_source_line_id IN NUMBER DEFAULT NULL
1990 , p_supply_source_type_id IN NUMBER DEFAULT inv_reservation_global.g_source_type_po)
1991
1992 RETURN BOOLEAN IS
1993 -- Define Constants for API version and API name
1994 C_api_version_number CONSTANT NUMBER := 1.0;
1995 C_api_name CONSTANT VARCHAR2(30) := 'EXISTS_RESERVATION';
1996 C_Module_Name Constant Varchar2(2000) := 'inv.plsql.inv_maintain_reservation_pub.maintain_reservation';
1997 C_Debug_Enabled Constant Number := 1 ;
1998
1999 --l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
2000 l_Fnd_Log_Message VARCHAR2(2000);
2001 l_Msg_Index_Out Number;
2002
2003 l_rsv_array inv_reservation_global.mtl_reservation_tbl_type;
2004 l_record_count NUMBER;
2005 l_msg_count NUMBER;
2006 l_msg_data VARCHAR2(2000);
2007 l_return_status VARCHAR2(1);
2008
2009 BEGIN
2010
2011 l_Fnd_Log_message := 'Begining of procedure :';
2012 -- Dbms_output.Put_line('Begining Of Procedure');
2013 -- Fnd_Log_Debug(Fnd_Log.Level_Procedure, C_Module_name, l_Fnd_Log_Message);
2014
2015 -- Log message in trace file
2016 IF G_debug= C_Debug_Enabled THEN
2017 G_Version_Printed := TRUE ;
2018 mydebug(l_Fnd_Log_Message,c_api_name,9);
2019 G_Version_Printed := FALSE ;
2020 END IF;
2021
2022 QUERY_RES
2023 ( p_supply_source_header_id => p_supply_source_header_id
2024 ,p_supply_source_line_id => p_supply_source_line_id
2025 ,p_supply_source_type_id => p_supply_source_type_id
2026 ,p_project_id => NULL
2027 ,p_task_id => NULL
2028 ,x_rsv_array => l_rsv_array
2029 ,x_record_count => l_record_count
2030 ,x_msg_count => l_msg_count
2031 ,x_msg_data => l_msg_data
2032 ,x_return_status => l_return_status);
2033
2034 If g_debug= C_Debug_Enabled Then
2035 l_Fnd_Log_Message := 'l_return_status: '||l_return_status;
2036 mydebug(l_Fnd_Log_Message,c_api_name,9);
2037 End If;
2038
2039
2040 If l_return_status = fnd_api.g_ret_sts_success THEN
2041 l_Fnd_Log_message := 'Calling QUERY_RES API was successful ';
2042 -- Fnd_Log_Debug(fnd_log.Level_Error,C_Module_name, l_Fnd_Log_Message );
2043 IF G_debug= C_Debug_Enabled THEN
2044 mydebug(l_Fnd_Log_Message, c_api_name,9);
2045 END IF;
2046
2047 IF l_record_count > 0 THEN
2048 return TRUE;
2049 ELSE
2050 return FALSE;
2051 END IF;
2052 --?? what should be returned if l_return_status is not 'S'.
2053 -- should we return fales. the reason is
2054 -- if a reservation is existing, .... then we think it is not,
2055 -- then we were trying to transfer from req to PO, which will fail.
2056 -- if a reservation is not existing, then no impact..
2057 -- or if we returns TRUE. THEN
2058 -- if a reservation exists, then no impact....
2059 -- if a reservation is not existing, then we will update the reservation...
2060 else
2061 l_Fnd_Log_message := 'Error while calling QUERY_RES API ';
2062 -- Fnd_Log_Debug(fnd_log.Level_Error,C_Module_name, l_Fnd_Log_Message );
2063 IF G_debug= C_Debug_Enabled THEN
2064 mydebug(l_Fnd_Log_Message, c_api_name,9);
2065 END IF;
2066 return FALSE;
2067 end if;
2068
2069 -- Call fnd_log api at the end of the API
2070 l_Fnd_Log_message := 'At the end of procedure :';
2071 -- Fnd_Log_Debug(Fnd_Log.Level_Procedure,C_Module_name, l_Fnd_Log_Message );
2072
2073 IF G_debug= C_Debug_Enabled THEN
2074 mydebug(l_Fnd_Log_Message, c_api_name,9);
2075 END IF;
2076
2077
2078 EXCEPTION
2079 WHEN OTHERS THEN
2080 l_Fnd_Log_message := 'OTHER exception happens when calling QUERY_RES API :';
2081 -- Fnd_Log_Debug(Fnd_Log.Level_Procedure,C_Module_name, l_Fnd_Log_Message );
2082
2083 IF G_debug= C_Debug_Enabled THEN
2084 mydebug(l_Fnd_Log_Message, c_api_name,9);
2085 END IF;
2086 return FALSE;
2087 END;
2088
2089
2090 -- this procedure finds the reservation on the requisition and returns the reservation records
2091 -- so far we should only have one record returned for gaven requisition_line_id.
2092 PROCEDURE GET_REQ_LINE_RES
2093 (
2094 p_req_line_id IN NUMBER
2095 ,p_project_id IN NUMBER
2096 ,p_task_id IN NUMBER
2097 ,x_res_array OUT NOCOPY inv_reservation_global.mtl_reservation_tbl_type
2098 ,x_record_count OUT NOCOPY NUMBER
2099 )
2100 IS
2101 -- Define Constants for API version and API name
2102 C_api_version_number CONSTANT NUMBER := 1.0;
2103 C_api_name CONSTANT VARCHAR2(30) := 'GET_REQ_LINE_RES';
2104 C_Module_Name Constant Varchar2(2000) := 'inv.plsql.inv_maintain_reservation_pub.maintain_reservation';
2105 C_Debug_Enabled Constant Number := 1 ;
2106
2107 --l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
2108 l_Fnd_Log_Message VARCHAR2(2000);
2109 l_Msg_Index_Out Number;
2110
2111 l_msg_count NUMBER;
2112 l_msg_data VARCHAR2(2000);
2113 l_record_count NUMBER;
2114 l_return_status VARCHAR2(1);
2115
2116 BEGIN
2117 -- this procedure checks whether a reservation exists on the req line
2118 -- if so, it returns the reservation record
2119
2120 l_Fnd_Log_message := 'Begining of procedure :';
2121 -- Dbms_output.Put_line('Begining Of Procedure');
2122 -- Fnd_Log_Debug(Fnd_Log.Level_Procedure, C_Module_name, l_Fnd_Log_Message);
2123
2124 -- Log message in trace file
2125 IF G_debug= C_Debug_Enabled THEN
2126 G_Version_Printed := TRUE ;
2127 mydebug(l_Fnd_Log_Message,c_api_name,9);
2128 G_Version_Printed := FALSE ;
2129 END IF;
2130
2131 -- Bug 3600118: Initialize return status variable
2132 --l_return_status := FND_API.g_ret_sts_success;
2133 --
2134 -- bug fix 2341308
2135 if p_req_line_id IS NULL then
2136 l_Fnd_Log_message := 'p_req_line_id is NULL :';
2137 IF G_debug= C_Debug_Enabled THEN
2138 mydebug(l_Fnd_Log_Message,c_api_name,9);
2139 END IF;
2140 x_record_count := -1;
2141 return;
2142 end if;
2143
2144
2145 QUERY_RES
2146 (p_supply_source_line_id => p_req_line_id
2147 ,p_supply_source_type_id => inv_reservation_global.g_source_type_req
2148 ,p_project_id => p_project_id
2149 ,p_task_id => p_task_id
2150 ,x_rsv_array => x_res_array
2151 ,x_record_count => l_record_count
2152 ,x_msg_count => l_msg_count
2153 ,x_msg_data => l_msg_data
2154 ,x_return_status => l_return_status);
2155
2156
2157 If g_debug= C_Debug_Enabled Then
2158 l_Fnd_Log_Message := 'l_return_status: '||l_return_status;
2159 mydebug(l_Fnd_Log_Message,c_api_name,9);
2160 End If;
2161
2162 If l_return_status = fnd_api.g_ret_sts_success THEN
2163 l_Fnd_Log_message := 'Calling QUERY_RES API was successful ';
2164 -- Fnd_Log_Debug(fnd_log.Level_Error,C_Module_name, l_Fnd_Log_Message );
2165 IF G_debug= C_Debug_Enabled THEN
2166 mydebug(l_Fnd_Log_Message, c_api_name,9);
2167 END IF;
2168 x_record_count := l_record_count;
2169 else
2170 l_Fnd_Log_message := 'Error while calling QUERY_RES API ';
2171 -- Fnd_Log_Debug(fnd_log.Level_Error,C_Module_name, l_Fnd_Log_Message );
2172 IF G_debug= C_Debug_Enabled THEN
2173 mydebug(l_Fnd_Log_Message, c_api_name,9);
2174 END IF;
2175 x_record_count := -1;
2176 end if;
2177
2178 -- Call fnd_log api at the end of the API
2179 l_Fnd_Log_message := 'At the end of procedure :';
2180 -- -- Fnd_Log_Debug(Fnd_Log.Level_Procedure,C_Module_name, l_Fnd_Log_Message );
2181
2182 IF G_debug= C_Debug_Enabled THEN
2183 mydebug(l_Fnd_Log_Message, c_api_name,9);
2184 END IF;
2185
2186 EXCEPTION
2187 WHEN OTHERS THEN
2188 x_record_count := -1;
2189 l_Fnd_Log_message := ' OTHER exceptions happens ';
2190 IF G_debug= C_Debug_Enabled THEN
2191 mydebug(l_Fnd_Log_Message, c_api_name,9);
2192 END IF;
2193 END;
2194
2195
2196 --
2197 -- this procedure calls the inventory API update_reservation with the appropriate parameters
2198 --
2199 PROCEDURE UPDATE_RES
2200 (p_supply_source_header_id IN NUMBER
2201 ,p_supply_source_line_id IN NUMBER
2202 ,p_supply_source_type_id IN NUMBER
2203 ,p_primary_uom_code IN VARCHAR2 DEFAULT NULL
2204 ,p_primary_reservation_quantity IN NUMBER
2205 ,p_reservation_id IN NUMBER
2206 ,p_project_id IN NUMBER
2207 ,p_task_id IN NUMBER
2208 ,x_msg_count OUT NOCOPY NUMBER
2209 ,x_msg_data OUT NOCOPY VARCHAR2
2210 ,x_return_status OUT NOCOPY VARCHAR2)
2211 IS
2212
2213 -- Define Constants for API version and API name
2214 C_api_version_number CONSTANT NUMBER := 1.0;
2215 C_api_name CONSTANT VARCHAR2(30) := 'UPDATE_RES';
2216 C_Module_Name Constant Varchar2(2000) := 'inv.plsql.inv_maintain_reservation_pub.maintain_reservation';
2217 C_Debug_Enabled Constant Number := 1 ;
2218
2219 --l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
2220 l_Fnd_Log_Message VARCHAR2(2000);
2221 l_Msg_Index_Out Number;
2222
2223 l_rsv inv_reservation_global.mtl_reservation_rec_type;
2224 l_rsv_new inv_reservation_global.mtl_reservation_rec_type;
2225 --l_msg_count NUMBER;
2226 --l_msg_data VARCHAR2(240);
2227 l_rsv_id NUMBER;
2228 l_return_status VARCHAR2(1);
2229 BEGIN
2230 l_Fnd_Log_message := 'Begining of procedure :';
2231 -- Dbms_output.Put_line('Begining Of Procedure');
2232 -- Fnd_Log_Debug(Fnd_Log.Level_Procedure, C_Module_name, l_Fnd_Log_Message);
2233
2234 -- Log message in trace file
2235 IF G_debug= C_Debug_Enabled THEN
2236 G_Version_Printed := TRUE ;
2237 mydebug(l_Fnd_Log_Message,c_api_name,9);
2238 G_Version_Printed := FALSE ;
2239 END IF;
2240
2241 -- Bug 3600118: Initialize return status variable
2242 l_return_status := FND_API.g_ret_sts_success;
2243
2244 -- find the existing reservation
2245 -- REQ or PO id's
2246 l_rsv.supply_source_header_id := p_supply_source_header_id;
2247 l_rsv.supply_source_line_id := p_supply_source_line_id;
2248 l_rsv.supply_source_type_id := p_supply_source_type_id;
2249 l_rsv.project_id := p_project_id;
2250 l_rsv.task_id := p_task_id;
2251
2252 IF p_reservation_id IS NOT NULL THEN
2253 l_rsv.reservation_id := p_reservation_id;
2254 END IF;
2255
2256 -- specify the new values
2257 l_rsv_new.primary_reservation_quantity := p_primary_reservation_quantity;
2258 --
2259 inv_reservation_pub.update_reservation
2260 (
2261 p_api_version_number => 1.0
2262 , p_init_msg_lst => fnd_api.g_false
2263 , x_return_status => l_return_status
2264 , x_msg_count => x_msg_count
2265 , x_msg_data => x_msg_data
2266 , p_original_rsv_rec => l_rsv
2267 , p_to_rsv_rec => l_rsv_new
2268 , p_original_serial_number => g_dummy_sn_tbl -- no serial contorl
2269 , p_to_serial_number => g_dummy_sn_tbl -- no serial control
2270 , p_validation_flag => fnd_api.g_true
2271 );
2272
2273 If g_debug= C_Debug_Enabled Then
2274 l_Fnd_Log_Message := 'l_return_status: '||l_return_status;
2275 mydebug(l_Fnd_Log_Message,c_api_name,9);
2276 End If;
2277
2278 x_return_status := l_return_status;
2279
2280 If x_return_status = fnd_api.g_ret_sts_success THEN
2281 l_Fnd_Log_message := 'Calling update_reservation API was successful ';
2282 -- Fnd_Log_Debug(fnd_log.Level_Error,C_Module_name, l_Fnd_Log_Message );
2283 IF G_debug= C_Debug_Enabled THEN
2284 mydebug(l_Fnd_Log_Message, c_api_name,9);
2285 END IF;
2286 else
2287 l_Fnd_Log_message := 'Error while calling update_reservation API ';
2288 -- Fnd_Log_Debug(fnd_log.Level_Error,C_Module_name, l_Fnd_Log_Message );
2289 IF G_debug= C_Debug_Enabled THEN
2290 mydebug(l_Fnd_Log_Message, c_api_name,9);
2291 END IF;
2292 end if;
2293
2294 -- Call fnd_log api at the end of the API
2295 l_Fnd_Log_message := 'At the end of procedure :';
2296 -- -- Fnd_Log_Debug(Fnd_Log.Level_Procedure,C_Module_name, l_Fnd_Log_Message );
2297
2298 IF G_debug= C_Debug_Enabled THEN
2299 mydebug(l_Fnd_Log_Message, c_api_name,9);
2300 END IF;
2301
2302
2303 EXCEPTION
2304 WHEN fnd_api.g_exc_error THEN
2305 x_return_status := fnd_api.g_ret_sts_error;
2306
2307 -- Get message count and data
2308 fnd_msg_pub.count_and_get
2309 ( p_count => x_msg_count
2310 , p_data => x_msg_data
2311 );
2312
2313 -- Call fnd_log api at the end of the API
2314 l_Fnd_Log_message := 'When Expected exception raised for procedure :' ;
2315 -- Fnd_Log_Debug(fnd_log.Level_Error,C_Module_name, l_Fnd_Log_Message );
2316
2317 -- Log message in trace file
2318 IF G_debug= C_Debug_Enabled THEN
2319 mydebug(l_Fnd_Log_Message,c_api_name,9);
2320 END IF;
2321
2322 -- Get messages from stack and log them in fnd tables
2323 If X_Msg_Count = 1 Then
2324 -- Fnd_Log_Debug(fnd_log.Level_Error,C_Module_name, X_Msg_Data );
2325 -- Log message in trace file
2326 If G_debug= C_Debug_Enabled THEN
2327 mydebug(l_Fnd_Log_Message,c_api_name,9);
2328 End If;
2329 Elsif x_msg_count > 1 Then
2330 For I In 1..X_Msg_Count Loop
2331 FND_MSG_PUB.Get
2332 (p_msg_index => i,
2333 p_encoded => 'F',
2334 p_data => l_Fnd_Log_Message,
2335 p_msg_index_out => l_msg_index_out );
2336
2337 -- Fnd_Log_Debug(fnd_log.Level_Error,C_Module_name, l_Fnd_Log_Message );
2338
2339 -- Log message in trace file
2340 IF G_debug= C_Debug_Enabled THEN
2341 mydebug(l_Fnd_Log_Message,c_api_name,9);
2342 END IF;
2343 End Loop ;
2344 End If;
2345
2346
2347 WHEN fnd_api.g_exc_unexpected_error THEN
2348 x_return_status := fnd_api.g_ret_sts_unexp_error ;
2349
2350 -- Get message count and data
2351 fnd_msg_pub.count_and_get
2352 ( p_count => x_msg_count
2353 , p_data => x_msg_data
2354 );
2355 -- Call fnd_log api at the end of the API
2356 l_Fnd_Log_message := 'When unexpected exception raised for procedure :';
2357 -- Fnd_Log_Debug(fnd_log.Level_Error,C_Module_name, l_Fnd_Log_Message );
2358
2359 -- Log message in trace file
2360 IF G_debug= C_Debug_Enabled THEN
2361 mydebug(l_Fnd_Log_Message,c_api_name,9);
2362 END IF;
2363
2364 -- Get messages from stack and log them in fnd tables
2365 If X_Msg_Count = 1 Then
2366 -- Fnd_Log_Debug(fnd_log.Level_Error,C_Module_name, X_Msg_Data );
2367
2368 -- Log message in trace file
2369 IF G_debug= C_Debug_Enabled THEN
2370 mydebug(l_Fnd_Log_Message,c_api_name,9);
2371 END IF;
2372 Elsif X_Msg_Count > 1 Then
2373 For I In 1..X_Msg_Count Loop
2374 FND_MSG_PUB.Get
2375 (p_msg_index => i,
2376 p_encoded => 'F',
2377 p_data => l_Fnd_Log_Message,
2378 p_msg_index_out => l_msg_index_out );
2379
2380 -- Fnd_Log_Debug(fnd_log.Level_Error,C_Module_name, l_Fnd_Log_Message );
2381
2382 -- Log message in trace file
2383 IF G_debug= C_Debug_Enabled THEN
2384 mydebug(l_Fnd_Log_Message,c_api_name,9);
2385 END IF;
2386 End Loop ;
2387 End If;
2388
2389 WHEN OTHERS THEN
2390 x_return_status := fnd_api.g_ret_sts_unexp_error ;
2391
2392 IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error)
2393 THEN
2394 fnd_msg_pub.add_exc_msg
2395 ( g_pkg_name
2396 , c_api_name
2397 );
2398 END IF;
2399
2400 -- Get message count and data
2401 fnd_msg_pub.count_and_get
2402 ( p_count => x_msg_count
2403 , p_data => x_msg_data
2404 );
2405
2406 -- Call fnd_log api at the end of the API
2407 l_Fnd_Log_message := 'When Others exception raised for procedure :' || G_Pkg_Name || '.' || C_API_Name ;
2408 -- Fnd_Log_Debug(fnd_log.Level_Error,C_Module_name, l_Fnd_Log_Message );
2409
2410 -- Log message in trace file
2411 IF G_debug= C_Debug_Enabled THEN
2412 mydebug(l_Fnd_Log_Message,c_api_name,9);
2413 END IF;
2414
2415 -- Get messages from stack and log them in fnd tables
2416 If X_Msg_Count = 1 Then
2417 -- Fnd_Log_Debug(fnd_log.Level_Error,C_Module_name, X_Msg_Data );
2418
2419 -- Log message in trace file
2420 If G_debug= C_Debug_Enabled Then
2421 mydebug(l_Fnd_Log_Message,c_api_name,9);
2422 End If;
2423 Elsif X_Msg_Count > 1 Then
2424 For I In 1..X_Msg_Count Loop
2425 FND_MSG_PUB.Get
2426 (p_msg_index => i,
2427 p_encoded => 'F',
2428 p_data => l_Fnd_Log_Message,
2429 p_msg_index_out => l_msg_index_out );
2430
2431 -- Fnd_Log_Debug(fnd_log.Level_Error,C_Module_name, l_Fnd_Log_Message );
2432
2433 -- Log message in trace file
2434 IF G_debug= C_Debug_Enabled THEN
2435 mydebug(l_Fnd_Log_Message,c_api_name,9);
2436 END IF;
2437 End Loop ;
2438 End If;
2439 END;
2440
2441
2442
2443 --
2444 -- this procedure calls the inventory API transfer_reservation with the appropriate parameters
2445 --
2446 PROCEDURE TRANSFER_RES
2447 (p_from_reservation_id IN NUMBER DEFAULT NULL
2448 ,p_from_source_header_id IN NUMBER DEFAULT NULL
2449 ,p_from_source_line_id IN NUMBER DEFAULT NULL
2450 ,p_supply_source_type_id IN NUMBER DEFAULT NULL
2451 ,p_to_source_header_id IN NUMBER DEFAULT NULL
2452 ,p_to_source_line_id IN NUMBER DEFAULT NULL
2453 ,p_to_supply_source_type_id IN NUMBER DEFAULT NULL
2454 ,p_subinventory_code IN VARCHAR2 DEFAULT NULL
2455 ,p_locator_id IN NUMBER DEFAULT NULL
2456 ,p_lot_number IN VARCHAR2 DEFAULT NULL
2457 ,p_revision IN VARCHAR2 DEFAULT NULL
2458 ,p_lpn_id IN VARCHAR2 DEFAULT NULL --#Bug3020166
2459 ,p_primary_uom_code IN VARCHAR2 DEFAULT NULL
2460 ,p_primary_res_quantity IN NUMBER DEFAULT NULL
2461 --,p_action IN VARCHAR2 DEFAULT NULL
2462 ,x_msg_count OUT NOCOPY NUMBER
2463 ,x_msg_data OUT NOCOPY VARCHAR2
2464 ,x_return_status OUT NOCOPY VARCHAR2)
2465 IS
2466
2467 -- Define Constants for API version and API name
2468 C_api_version_number CONSTANT NUMBER := 1.0;
2469 C_api_name CONSTANT VARCHAR2(30) := 'TRANSFER_RES';
2470 C_Module_Name Constant Varchar2(2000) := 'inv.plsql.inv_maintain_reservation_pub.maintain_reservation';
2471 C_Debug_Enabled Constant Number := 1 ;
2472
2473 --l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
2474 l_Fnd_Log_Message VARCHAR2(2000);
2475 l_Msg_Index_Out Number;
2476
2477 l_rsv inv_reservation_global.mtl_reservation_rec_type;
2478 l_rsv_new inv_reservation_global.mtl_reservation_rec_type;
2479 --l_msg_count NUMBER;
2480 --l_msg_data VARCHAR2(240);
2481 l_rsv_id NUMBER;
2482 l_return_status VARCHAR2(1);
2483 l_new_rsv_id NUMBER;
2484 BEGIN
2485 l_Fnd_Log_message := 'Begining of procedure :';
2486 -- Dbms_output.Put_line('Begining Of Procedure');
2487 -- Fnd_Log_Debug(Fnd_Log.Level_Procedure, C_Module_name, l_Fnd_Log_Message);
2488
2489 -- Log message in trace file
2490 IF G_debug= C_Debug_Enabled THEN
2491 G_Version_Printed := TRUE ;
2492 mydebug(l_Fnd_Log_Message,c_api_name,9);
2493 G_Version_Printed := FALSE ;
2494 END IF;
2495
2496 -- Bug 3600118: Initialize return status variable
2497 l_return_status := FND_API.g_ret_sts_success;
2498
2499 -- print out IN parameter values
2500 IF g_debug= C_Debug_Enabled THEN
2501 l_Fnd_Log_Message := 'p_from_reservation_id:' || p_from_reservation_id;
2502 mydebug(l_Fnd_Log_Message, c_api_name,9);
2503 l_Fnd_Log_Message := 'p_from_source_header_id:' || p_from_source_header_id;
2504 mydebug(l_Fnd_Log_Message, c_api_name,9);
2505 l_Fnd_Log_Message := 'p_from_source_line_id: ' || p_from_source_line_id;
2506 mydebug(l_Fnd_Log_Message, c_api_name,9);
2507 l_Fnd_Log_Message := 'p_supply_source_type_id :'||p_supply_source_type_id;
2508 mydebug(l_Fnd_Log_Message, c_api_name,9);
2509 l_Fnd_Log_Message := 'p_to_source_header_id :'||p_to_source_header_id;
2510 mydebug(l_Fnd_Log_Message, c_api_name,9);
2511 l_Fnd_Log_Message := 'p_to_source_line_id: '||p_to_source_line_id;
2512 mydebug(l_Fnd_Log_Message, c_api_name,9);
2513 l_Fnd_Log_Message := 'p_to_supply_source_type_id:'||p_to_supply_source_type_id;
2514 mydebug(l_Fnd_Log_Message, c_api_name,9);
2515 l_Fnd_Log_Message := 'p_subinventory_code:'||p_subinventory_code;
2516 mydebug(l_Fnd_Log_Message, c_api_name,9);
2517 l_Fnd_Log_Message := 'p_locator_id:'||p_locator_id;
2518 mydebug(l_Fnd_Log_Message, c_api_name,9);
2519 l_Fnd_Log_Message := 'p_lot_number:'||p_lot_number;
2520 mydebug(l_Fnd_Log_Message, c_api_name,9);
2521 l_Fnd_Log_Message := 'p_revision:'||p_revision;
2522 mydebug(l_Fnd_Log_Message, c_api_name,9);
2523 l_Fnd_Log_Message := 'p_lpn_id:'||p_lpn_id;
2524 mydebug(l_Fnd_Log_Message, c_api_name,9);
2525 l_Fnd_Log_Message := 'p_primary_uom_code: ' || p_primary_uom_code;
2526 mydebug(l_Fnd_Log_Message, c_api_name,9);
2527 l_Fnd_Log_Message := 'p_primary_res_quantity : '||p_primary_res_quantity;
2528 mydebug(l_Fnd_Log_Message, c_api_name,9);
2529 END IF;
2530
2531 -- REQ or PO id's
2532
2533 l_rsv.supply_source_header_id := p_from_source_header_id;
2534 l_rsv.supply_source_line_id := p_from_source_line_id ;
2535 l_rsv.supply_source_type_id := p_supply_source_type_id;
2536
2537 -- specify other new values if any
2538 l_rsv_new.supply_source_header_id := p_to_source_header_id;
2539 l_rsv_new.supply_source_line_id := p_to_source_line_id ;
2540 l_rsv_new.supply_source_type_id := p_to_supply_source_type_id;
2541 l_rsv_new.primary_reservation_quantity := p_primary_res_quantity;
2542 -- these values will be available for a transfer from PO to inventory (receipt)
2543
2544 IF p_from_reservation_id IS NOT NULL THEN
2545 l_rsv.reservation_id := p_from_reservation_id;
2546 END IF;
2547
2548 IF p_subinventory_code is not NULL THEN
2549 l_rsv_new.subinventory_code := p_subinventory_code;
2550 END IF;
2551
2552 IF p_locator_id is not NULL THEN
2553 l_rsv_new.locator_id := p_locator_id;
2554 END IF;
2555
2556 IF p_lot_number is not NULL THEN
2557 l_rsv_new.lot_number := p_lot_number;
2558 END IF;
2559
2560 IF p_revision is not NULL THEN
2561 l_rsv_new.revision := p_revision;
2562 END IF;
2563
2564 /*Bug 3020166 Assigning p_lpn_id got from rcv_transactions to the lpn_id in the
2565 record type */
2566 IF p_lpn_id is not NULL THEN
2567 l_rsv_new.lpn_id := p_lpn_id;
2568 END IF;
2569
2570 inv_reservation_pvt.transfer_reservation
2571 (
2572 p_api_version_number => 1.0
2573 , p_init_msg_lst => fnd_api.g_false
2574 , x_return_status => l_return_status
2575 , x_msg_count => x_msg_count
2576 , x_msg_data => x_msg_data
2577 --, p_is_transfer_supply => fnd_api.g_true
2578 , p_original_rsv_rec => l_rsv
2579 , p_to_rsv_rec => l_rsv_new
2580 , p_original_serial_number => g_dummy_sn_tbl -- no serial contorl
2581 -- , p_to_serial_number => g_dummy_sn_tbl -- no serial control
2582 , p_validation_flag => fnd_api.g_true
2583 , x_reservation_id => l_new_rsv_id
2584 );
2585
2586 If g_debug= C_Debug_Enabled Then
2587 l_Fnd_Log_Message := 'l_return_status: '||l_return_status;
2588 mydebug(l_Fnd_Log_Message,c_api_name,9);
2589 End If;
2590
2591 x_return_status := l_return_status;
2592
2593 If x_return_status = fnd_api.g_ret_sts_success THEN
2594 l_Fnd_Log_message := 'Calling transfer_reservation API was successful ';
2595 -- Fnd_Log_Debug(fnd_log.Level_Error,C_Module_name, l_Fnd_Log_Message );
2596 IF G_debug= C_Debug_Enabled THEN
2597 mydebug(l_Fnd_Log_Message, c_api_name,9);
2598 END IF;
2599 else
2600 l_Fnd_Log_message := 'Error while calling transfer_reservation API ';
2601 -- Fnd_Log_Debug(fnd_log.Level_Error,C_Module_name, l_Fnd_Log_Message );
2602 IF G_debug= C_Debug_Enabled THEN
2603 mydebug(l_Fnd_Log_Message, c_api_name,9);
2604 END IF;
2605 end if;
2606
2607 -- Call fnd_log api at the end of the API
2608 l_Fnd_Log_message := 'At the end of procedure :';
2609 -- -- Fnd_Log_Debug(Fnd_Log.Level_Procedure,C_Module_name, l_Fnd_Log_Message );
2610
2611 IF G_debug= C_Debug_Enabled THEN
2612 mydebug(l_Fnd_Log_Message, c_api_name,9);
2613 END IF;
2614
2615 EXCEPTION
2616 WHEN fnd_api.g_exc_error THEN
2617 x_return_status := fnd_api.g_ret_sts_error;
2618
2619 -- Get message count and data
2620 fnd_msg_pub.count_and_get
2621 ( p_count => x_msg_count
2622 , p_data => x_msg_data
2623 );
2624
2625 -- Call fnd_log api at the end of the API
2626 l_Fnd_Log_message := 'When Expected exception raised for procedure :' ;
2627 -- Fnd_Log_Debug(fnd_log.Level_Error,C_Module_name, l_Fnd_Log_Message );
2628
2629 -- Log message in trace file
2630 IF G_debug= C_Debug_Enabled THEN
2631 mydebug(l_Fnd_Log_Message,c_api_name,9);
2632 END IF;
2633
2634 -- Get messages from stack and log them in fnd tables
2635 If X_Msg_Count = 1 Then
2636 -- Fnd_Log_Debug(fnd_log.Level_Error,C_Module_name, X_Msg_Data );
2637 -- Log message in trace file
2638 If G_debug= C_Debug_Enabled THEN
2639 mydebug(l_Fnd_Log_Message,c_api_name,9);
2640 End If;
2641 Elsif x_msg_count > 1 Then
2642 For I In 1..X_Msg_Count Loop
2643 FND_MSG_PUB.Get
2644 (p_msg_index => i,
2645 p_encoded => 'F',
2646 p_data => l_Fnd_Log_Message,
2647 p_msg_index_out => l_msg_index_out );
2648
2649 -- Fnd_Log_Debug(fnd_log.Level_Error,C_Module_name, l_Fnd_Log_Message );
2650
2651 -- Log message in trace file
2652 IF G_debug= C_Debug_Enabled THEN
2653 mydebug(l_Fnd_Log_Message,c_api_name,9);
2654 END IF;
2655 End Loop ;
2656 End If;
2657
2658 WHEN fnd_api.g_exc_unexpected_error THEN
2659 x_return_status := fnd_api.g_ret_sts_unexp_error ;
2660
2661 -- Get message count and data
2662 fnd_msg_pub.count_and_get
2663 ( p_count => x_msg_count
2664 , p_data => x_msg_data
2665 );
2666 -- Call fnd_log api at the end of the API
2667 l_Fnd_Log_message := 'When unexpected exception raised for procedure :';
2668 -- Fnd_Log_Debug(fnd_log.Level_Error,C_Module_name, l_Fnd_Log_Message );
2669
2670 -- Log message in trace file
2671 IF G_debug= C_Debug_Enabled THEN
2672 mydebug(l_Fnd_Log_Message,c_api_name,9);
2673 END IF;
2674
2675 -- Get messages from stack and log them in fnd tables
2676 If X_Msg_Count = 1 Then
2677 -- Fnd_Log_Debug(fnd_log.Level_Error,C_Module_name, X_Msg_Data );
2678
2679 -- Log message in trace file
2680 IF G_debug= C_Debug_Enabled THEN
2681 mydebug(l_Fnd_Log_Message,c_api_name,9);
2682 END IF;
2683 Elsif X_Msg_Count > 1 Then
2684 For I In 1..X_Msg_Count Loop
2685 FND_MSG_PUB.Get
2686 (p_msg_index => i,
2687 p_encoded => 'F',
2688 p_data => l_Fnd_Log_Message,
2689 p_msg_index_out => l_msg_index_out );
2690
2691 -- Fnd_Log_Debug(fnd_log.Level_Error,C_Module_name, l_Fnd_Log_Message );
2692
2693 -- Log message in trace file
2694 IF G_debug= C_Debug_Enabled THEN
2695 mydebug(l_Fnd_Log_Message,c_api_name,9);
2696 END IF;
2697 End Loop ;
2698 End If;
2699
2700 WHEN OTHERS THEN
2701 x_return_status := fnd_api.g_ret_sts_unexp_error ;
2702
2703 IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error)
2704 THEN
2705 fnd_msg_pub.add_exc_msg
2706 ( g_pkg_name
2707 , c_api_name
2708 );
2709 END IF;
2710
2711 -- Get message count and data
2712 fnd_msg_pub.count_and_get
2713 ( p_count => x_msg_count
2714 , p_data => x_msg_data
2715 );
2716
2717 -- Call fnd_log api at the end of the API
2718 l_Fnd_Log_message := 'When Others exception raised for procedure :' || G_Pkg_Name || '.' || C_API_Name ;
2719 -- Fnd_Log_Debug(fnd_log.Level_Error,C_Module_name, l_Fnd_Log_Message );
2720
2721 -- Log message in trace file
2722 IF G_debug= C_Debug_Enabled THEN
2723 mydebug(l_Fnd_Log_Message,c_api_name,9);
2724 END IF;
2725
2726 -- Get messages from stack and log them in fnd tables
2727 If X_Msg_Count = 1 Then
2728 -- Fnd_Log_Debug(fnd_log.Level_Error,C_Module_name, X_Msg_Data );
2729
2730 -- Log message in trace file
2731 If G_debug= C_Debug_Enabled Then
2732 mydebug(l_Fnd_Log_Message,c_api_name,9);
2733 End If;
2734 Elsif X_Msg_Count > 1 Then
2735 For I In 1..X_Msg_Count Loop
2736 FND_MSG_PUB.Get
2737 (p_msg_index => i,
2738 p_encoded => 'F',
2739 p_data => l_Fnd_Log_Message,
2740 p_msg_index_out => l_msg_index_out );
2741
2742 -- Fnd_Log_Debug(fnd_log.Level_Error,C_Module_name, l_Fnd_Log_Message );
2743
2744 -- Log message in trace file
2745 IF G_debug= C_Debug_Enabled THEN
2746 mydebug(l_Fnd_Log_Message,c_api_name,9);
2747 END IF;
2748 End Loop ;
2749 End If;
2750 END;
2751
2752
2753 --
2754 -- this procedure calls inventory API delete_reservation with the appropriate parameters
2755 --
2756 PROCEDURE DELETE_RES
2757 (p_supply_source_header_id IN NUMBER DEFAULT NULL
2758 ,p_supply_source_line_id IN NUMBER DEFAULT NULL
2759 ,p_supply_source_type_id IN NUMBER DEFAULT NULL
2760 ,x_msg_count OUT NOCOPY NUMBER
2761 ,x_msg_data OUT NOCOPY VARCHAR2
2762 ,x_return_status OUT NOCOPY VARCHAR2)
2763 IS
2764 -- Define Constants for API version and API name
2765 C_api_version_number CONSTANT NUMBER := 1.0;
2766 C_api_name CONSTANT VARCHAR2(30) := 'DELETE_RES';
2767 C_Module_Name Constant Varchar2(2000) := 'inv.plsql.inv_maintain_reservation_pub.maintain_reservation';
2768 C_Debug_Enabled Constant Number := 1 ;
2769
2770 --l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
2771 l_Fnd_Log_Message VARCHAR2(2000);
2772 l_Msg_Index_Out Number;
2773
2774 l_rsv inv_reservation_global.mtl_reservation_rec_type;
2775 --l_msg_count NUMBER;
2776 --l_msg_data VARCHAR2(240);
2777 l_rsv_id NUMBER;
2778 --l_dummy_sn inv_reservation_global.serial_number_tbl_type;
2779 l_return_status VARCHAR2(1);
2780 BEGIN
2781 l_Fnd_Log_message := 'Begining of procedure :';
2782 -- Dbms_output.Put_line('Begining Of Procedure');
2783 -- Fnd_Log_Debug(Fnd_Log.Level_Procedure, C_Module_name, l_Fnd_Log_Message);
2784
2785 -- Log message in trace file
2786 IF G_debug= C_Debug_Enabled THEN
2787 G_Version_Printed := TRUE ;
2788 mydebug(l_Fnd_Log_Message,c_api_name,9);
2789 G_Version_Printed := FALSE ;
2790 END IF;
2791
2792 -- Bug 3600118: Initialize return status variable
2793 l_return_status := FND_API.g_ret_sts_success;
2794
2795 -- print out IN parameter values
2796 IF G_debug= C_Debug_Enabled THEN
2797 l_Fnd_Log_Message := 'p_supply_source_header_id: '|| p_supply_source_header_id;
2798 mydebug(l_Fnd_Log_Message, c_api_name,9);
2799 l_Fnd_Log_Message := 'p_supply_source_line_id: '|| p_supply_source_line_id;
2800 mydebug(l_Fnd_Log_Message, c_api_name,9);
2801 l_Fnd_Log_Message := 'p_supply_source_type_id: '|| p_supply_source_type_id;
2802 mydebug(l_Fnd_Log_Message, c_api_name,9);
2803 END IF;
2804
2805 -- REQ or PO id's
2806 l_rsv.supply_source_type_id := p_supply_source_type_id;
2807 IF p_supply_source_header_id IS NOT NULL THEN
2808 l_rsv.supply_source_header_id := p_supply_source_header_id;
2809 END IF;
2810
2811 IF p_supply_source_line_id IS NOT NULL THEN
2812 l_rsv.supply_source_line_id := p_supply_source_line_id;
2813 END IF;
2814 --
2815 inv_reservation_pub.delete_reservation
2816 (
2817 p_api_version_number => 1.0
2818 , p_init_msg_lst => fnd_api.g_false
2819 , x_return_status => l_return_status
2820 , x_msg_count => x_msg_count
2821 , x_msg_data => x_msg_data
2822 , p_rsv_rec => l_rsv
2823 , p_serial_number => g_dummy_sn_tbl
2824 );
2825
2826 If g_debug= C_Debug_Enabled Then
2827 l_Fnd_Log_Message := 'l_return_status: '||l_return_status;
2828 mydebug(l_Fnd_Log_Message,c_api_name,9);
2829 End If;
2830
2831 x_return_status := l_return_status;
2832
2833 If x_return_status = fnd_api.g_ret_sts_success THEN
2834 l_Fnd_Log_message := 'Calling delete_reservation API was successful ';
2835 -- Fnd_Log_Debug(fnd_log.Level_Error,C_Module_name, l_Fnd_Log_Message );
2836 IF G_debug= C_Debug_Enabled THEN
2837 mydebug(l_Fnd_Log_Message, c_api_name,9);
2838 END IF;
2839 else
2840 l_Fnd_Log_message := 'Error while calling delete_reservation API ';
2841 -- Fnd_Log_Debug(fnd_log.Level_Error,C_Module_name, l_Fnd_Log_Message );
2842 IF G_debug= C_Debug_Enabled THEN
2843 mydebug(l_Fnd_Log_Message, c_api_name,9);
2844 END IF;
2845 end if;
2846
2847 -- Call fnd_log api at the end of the API
2848 l_Fnd_Log_message := 'At the end of procedure :';
2849 -- -- Fnd_Log_Debug(Fnd_Log.Level_Procedure,C_Module_name, l_Fnd_Log_Message );
2850
2851 IF G_debug= C_Debug_Enabled THEN
2852 mydebug(l_Fnd_Log_Message, c_api_name,9);
2853 END IF;
2854 EXCEPTION
2855 WHEN fnd_api.g_exc_error THEN
2856 x_return_status := fnd_api.g_ret_sts_error;
2857
2858 -- Get message count and data
2859 fnd_msg_pub.count_and_get
2860 ( p_count => x_msg_count
2861 , p_data => x_msg_data
2862 );
2863
2864 -- Call fnd_log api at the end of the API
2865 l_Fnd_Log_message := 'When Expected exception raised for procedure :' ;
2866 -- Fnd_Log_Debug(fnd_log.Level_Error,C_Module_name, l_Fnd_Log_Message );
2867
2868 -- Log message in trace file
2869 IF G_debug= C_Debug_Enabled THEN
2870 mydebug(l_Fnd_Log_Message,c_api_name,9);
2871 END IF;
2872
2873 -- Get messages from stack and log them in fnd tables
2874 If X_Msg_Count = 1 Then
2875 -- Fnd_Log_Debug(fnd_log.Level_Error,C_Module_name, X_Msg_Data );
2876 -- Log message in trace file
2877 If G_debug= C_Debug_Enabled THEN
2878 mydebug(l_Fnd_Log_Message,c_api_name,9);
2879 End If;
2880 Elsif x_msg_count > 1 Then
2881 For I In 1..X_Msg_Count Loop
2882 FND_MSG_PUB.Get
2883 (p_msg_index => i,
2884 p_encoded => 'F',
2885 p_data => l_Fnd_Log_Message,
2886 p_msg_index_out => l_msg_index_out );
2887
2888 -- Fnd_Log_Debug(fnd_log.Level_Error,C_Module_name, l_Fnd_Log_Message );
2889
2890 -- Log message in trace file
2891 IF G_debug= C_Debug_Enabled THEN
2892 mydebug(l_Fnd_Log_Message,c_api_name,9);
2893 END IF;
2894 End Loop ;
2895 End If;
2896
2897 WHEN fnd_api.g_exc_unexpected_error THEN
2898 x_return_status := fnd_api.g_ret_sts_unexp_error ;
2899
2900 -- Get message count and data
2901 fnd_msg_pub.count_and_get
2902 ( p_count => x_msg_count
2903 , p_data => x_msg_data
2904 );
2905 -- Call fnd_log api at the end of the API
2906 l_Fnd_Log_message := 'When unexpected exception raised for procedure :';
2907 -- Fnd_Log_Debug(fnd_log.Level_Error,C_Module_name, l_Fnd_Log_Message );
2908
2909 -- Log message in trace file
2910 IF G_debug= C_Debug_Enabled THEN
2911 mydebug(l_Fnd_Log_Message,c_api_name,9);
2912 END IF;
2913
2914 -- Get messages from stack and log them in fnd tables
2915 If X_Msg_Count = 1 Then
2916 -- Fnd_Log_Debug(fnd_log.Level_Error,C_Module_name, X_Msg_Data );
2917
2918 -- Log message in trace file
2919 IF G_debug= C_Debug_Enabled THEN
2920 mydebug(l_Fnd_Log_Message,c_api_name,9);
2921 END IF;
2922 Elsif X_Msg_Count > 1 Then
2923 For I In 1..X_Msg_Count Loop
2924 FND_MSG_PUB.Get
2925 (p_msg_index => i,
2926 p_encoded => 'F',
2927 p_data => l_Fnd_Log_Message,
2928 p_msg_index_out => l_msg_index_out );
2929
2930 -- Fnd_Log_Debug(fnd_log.Level_Error,C_Module_name, l_Fnd_Log_Message );
2931
2932 -- Log message in trace file
2933 IF G_debug= C_Debug_Enabled THEN
2934 mydebug(l_Fnd_Log_Message,c_api_name,9);
2935 END IF;
2936 End Loop ;
2937 End If;
2938
2939 WHEN OTHERS THEN
2940 x_return_status := fnd_api.g_ret_sts_unexp_error ;
2941
2942 IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error)
2943 THEN
2944 fnd_msg_pub.add_exc_msg
2945 ( g_pkg_name
2946 , c_api_name
2947 );
2948 END IF;
2949
2950 -- Get message count and data
2951 fnd_msg_pub.count_and_get
2952 ( p_count => x_msg_count
2953 , p_data => x_msg_data
2954 );
2955
2956 -- Call fnd_log api at the end of the API
2957 l_Fnd_Log_message := 'When Others exception raised for procedure :' || G_Pkg_Name || '.' || C_API_Name ;
2958 -- Fnd_Log_Debug(fnd_log.Level_Error,C_Module_name, l_Fnd_Log_Message );
2959
2960 -- Log message in trace file
2961 IF G_debug= C_Debug_Enabled THEN
2962 mydebug(l_Fnd_Log_Message,c_api_name,9);
2963 END IF;
2964
2965 -- Get messages from stack and log them in fnd tables
2966 If X_Msg_Count = 1 Then
2967 -- Fnd_Log_Debug(fnd_log.Level_Error,C_Module_name, X_Msg_Data );
2968
2969 -- Log message in trace file
2970 If G_debug= C_Debug_Enabled Then
2971 mydebug(l_Fnd_Log_Message,c_api_name,9);
2972 End If;
2973 Elsif X_Msg_Count > 1 Then
2974 For I In 1..X_Msg_Count Loop
2975 FND_MSG_PUB.Get
2976 (p_msg_index => i,
2977 p_encoded => 'F',
2978 p_data => l_Fnd_Log_Message,
2979 p_msg_index_out => l_msg_index_out );
2980
2981 -- Fnd_Log_Debug(fnd_log.Level_Error,C_Module_name, l_Fnd_Log_Message );
2982
2983 -- Log message in trace file
2984 IF G_debug= C_Debug_Enabled THEN
2985 mydebug(l_Fnd_Log_Message,c_api_name,9);
2986 END IF;
2987 End Loop ;
2988 End If;
2989 END;
2990
2991 --BUG#3497445
2992 --Procedure below converts the PO Quantity and the Reservation Quantity as per
2993 --the quantity and UOM changes done at the PO_level without altering the PO UOM and the Reservation UOM.
2994
2995 PROCEDURE UOM_CONVERSION
2996 ( p_res_uom IN VARCHAR2 ,
2997 p_primary_uom IN VARCHAR2,
2998 p_po_qty IN NUMBER,
2999 p_po_line_id IN NUMBER,
3000 x_res_qty IN OUT NOCOPY NUMBER,
3001 x_po_primary_qty OUT NOCOPY NUMBER)
3002 IS
3003 -- Define Constants for API version and API name
3004 C_api_version_number CONSTANT NUMBER := 1.0;
3005 C_api_name CONSTANT VARCHAR2(30) := 'UOM_CONVERSION';
3006 C_Module_Name Constant Varchar2(2000) := 'inv.plsql.inv_maintain_reservation_pub.maintain_reservation';
3007 C_Debug_Enabled Constant Number := 1 ;
3008
3009 --l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
3010 l_fnd_log_message VARCHAR2(2000);
3011 l_Msg_Index_Out Number;
3012
3013 l_item_id NUMBER ;
3014 l_po_uom VARCHAR2(25);
3015 l_primary_meas VARCHAR2(25);
3016 l_res_meas VARCHAR2(25);
3017
3018 --Get the Primary UOM and the Reservation UOM,and quantities in PO and Reservation respectively.
3019 --Make comparisons of the three UOMs and calculate the primary_reservation_quantity and the reservation quantity.
3020
3021 BEGIN
3022 l_Fnd_Log_message := 'Begining of procedure :';
3023 -- Dbms_output.Put_line('Begining Of Procedure');
3024 -- Fnd_Log_Debug(Fnd_Log.Level_Procedure, C_Module_name, l_Fnd_Log_Message);
3025
3026 -- Log message in trace file
3027 IF G_debug= C_Debug_Enabled THEN
3028 G_Version_Printed := TRUE ;
3029 mydebug(l_Fnd_Log_Message,c_api_name,9);
3030 G_Version_Printed := FALSE ;
3031 END IF;
3032
3033 BEGIN
3034 SELECT item_id
3035 , unit_meas_lookup_code
3036 INTO l_item_id
3037 , l_po_uom
3038 FROM po_lines_all
3039 WHERE po_line_id= p_po_line_id;
3040
3041 SELECT unit_of_measure
3042 INTO l_primary_meas
3043 FROM mtl_units_of_measure
3044 WHERE uom_code = p_primary_uom;
3045
3046 SELECT unit_of_measure
3047 INTO l_res_meas
3048 FROM mtl_units_of_measure
3049 WHERE uom_code = p_res_uom;
3050
3051 EXCEPTION
3052 WHEN OTHERS THEN
3053 --po_message_s.sql_error('UOM_CONVERSION', '010', sqlcode);
3054 -- inv message....
3055 FND_MESSAGE.SET_NAME('INV','INV_RSV_UOM_CONVERSION');
3056 FND_MSG_PUB.Add;
3057 IF G_debug= C_Debug_Enabled THEN
3058 l_Fnd_Log_message := 'OTHERS exception happens when geting item_id, primary_uom, res_uom';
3059 mydebug(l_Fnd_Log_Message,c_api_name,9);
3060 END IF;
3061 RAISE;
3062 END;
3063
3064 IF G_debug= C_Debug_Enabled THEN
3065 l_Fnd_Log_message := 'l_item_id: '||l_item_id;
3066 mydebug(l_Fnd_Log_Message,c_api_name,9);
3067 l_Fnd_Log_message := 'l_primary_meas: '||l_primary_meas;
3068 mydebug(l_Fnd_Log_Message,c_api_name,9);
3069 l_Fnd_Log_message := 'l_res_meas: '||l_res_meas;
3070 mydebug(l_Fnd_Log_Message,c_api_name,9);
3071 END IF;
3072
3073 --Comparing if all three UOMs are same.
3074
3075 IF(l_po_uom=l_primary_meas AND l_res_meas = l_primary_meas ) THEN
3076 x_po_primary_qty:=p_po_qty;
3077 x_res_qty := p_po_qty;
3078 return;
3079 END IF;
3080
3081 --Compare the PO and the primary_uom and if different convert the PO quantity in its primary UOM
3082
3083 IF(l_po_uom <> l_primary_meas ) THEN
3084 -- remove the dependency on PO, changes to call inv_convert API
3085 /*po_uom_s.uom_convert(p_po_qty
3086 ,l_po_uom
3087 ,l_item_id
3088 ,l_primary_meas
3089 ,x_po_primary_qty);*/
3090
3091 x_po_primary_qty := inv_convert.inv_um_convert
3092 (
3093 item_id => l_item_id --number,
3094 ,precision => NULL --number,
3095 ,from_quantity => p_po_qty --number,
3096 ,from_unit => l_po_uom --varchar2,
3097 ,to_unit => l_primary_meas --varchar2,
3098 ,from_name => NULL --varchar2,
3099 ,to_name => NULL --varchar2
3100 );
3101 ELSE
3102 x_po_primary_qty := p_po_qty;
3103 END IF;
3104
3105 --Compare the PO UOM and Reservation UOM and if different convert the PO quantity in the Reservation UOM.
3106
3107 IF(l_po_uom <> l_res_meas) THEN
3108 --inv_convert.??
3109 /*po_uom_s.uom_convert(p_po_qty
3110 ,l_po_uom
3111 ,l_item_id
3112 ,l_res_meas
3113 ,x_res_qty);*/
3114 x_res_qty := inv_convert.inv_um_convert
3115 (
3116 item_id => l_item_id --number,
3117 ,precision => NULL --number,
3118 ,from_quantity => p_po_qty --number,
3119 ,from_unit => l_po_uom --varchar2,
3120 ,to_unit => l_res_meas --varchar2,
3121 ,from_name => NULL --varchar2,
3122 ,to_name => NULL --varchar2
3123 );
3124 ELSE
3125 x_res_qty := p_po_qty;
3126 END IF;
3127
3128 IF G_debug= C_Debug_Enabled THEN
3129 l_Fnd_Log_message := 'x_po_primary_qty :'|| x_po_primary_qty;
3130 mydebug(l_Fnd_Log_Message, c_api_name,9);
3131 l_Fnd_Log_message := 'x_res_qty :'|| x_res_qty;
3132 END IF;
3133
3134 -- Call fnd_log api at the end of the API
3135 l_Fnd_Log_message := 'At the end of procedure :';
3136 -- Fnd_Log_Debug(Fnd_Log.Level_Procedure,C_Module_name, l_Fnd_Log_Message );
3137
3138 IF G_debug= C_Debug_Enabled THEN
3139 mydebug(l_Fnd_Log_Message, c_api_name,9);
3140 END IF;
3141
3142 EXCEPTION
3143 WHEN OTHERS THEN
3144 IF G_debug= C_Debug_Enabled THEN
3145 l_Fnd_Log_message := 'OTHERS exception happens in uom_conversion';
3146 mydebug(l_Fnd_Log_Message,c_api_name,9);
3147 END IF;
3148 END UOM_CONVERSION;
3149 --BUG#3497445
3150
3151
3152
3153 -- Procedure
3154 -- MAINTAIN_RESERVATION
3155 --
3156 -- Description
3157 -- API will handle changes to the resevation record based on the action code.
3158 --
3159 -- Input Paramters
3160 -- p_api_version_number API version number (current version is 1.0 Standard in parameter)
3161 -- p_Init_Msg_lst Flag to determine to initialize message stack for API, standard input parameter
3162 -- p_header_id Purchase order header id or requisition header id
3163 -- p_line_id Purchase order line id or requisition line id
3164 -- p_line_location_id Purchase order shipment id
3165 -- p_distribution_id Purchase order distribution_id
3166 -- p_transaction_id Receiving transaction id
3167 -- p_ordered_quantity Ordered quantity from order entry form
3168 -- p_ordered_uom Ordered uom from order entry form
3169 -- p_action different action codes for po approve/delete, requisition approve/delete
3170 -- Output Parameters
3171 -- x_Return_Status Return Status of API, Standard out parameter
3172 -- x_Msg_Count Message count from the stack, standard out parameter
3173 -- x_Msg_Data Message from message stack, standard out parameter
3174
3175
3176 PROCEDURE MAINTAIN_RESERVATION
3177 (
3178 p_api_version_number IN NUMBER DEFAULT 1.0
3179 , p_init_msg_lst IN VARCHAR2 DEFAULT fnd_api.g_false
3180 , p_header_id IN NUMBER DEFAULT NULL
3181 , p_line_id IN NUMBER DEFAULT NULL
3182 , p_line_location_id IN NUMBER DEFAULT NULL
3183 , p_distribution_id IN NUMBER DEFAULT NULL
3184 , p_transaction_id IN NUMBER DEFAULT NULL
3185 , p_ordered_quantity IN NUMBER DEFAULT NULL
3186 , p_ordered_uom IN VARCHAR2 DEFAULT NULL
3187 , p_action IN VARCHAR2
3188 , x_return_status OUT NOCOPY VARCHAR2
3189 , x_msg_count OUT NOCOPY NUMBER
3190 , x_msg_data OUT NOCOPY VARCHAR2
3191 )
3192
3193 IS
3194
3195 --get the records to be processed from the po_requiusitions_interface table (for create reservations)
3196 --this gets the records inserted into the interface table by req import
3197 --and creates a resevation on the req
3198 --
3199 /* Bug 5520620: Added UNION clause to handle the master tables along with interface data*/
3200 CURSOR get_interface_records IS
3201 SELECT requisition_header_id
3202 , requisition_line_id
3203 , interface_source_line_id
3204 , need_by_date
3205 , item_id
3206 , destination_organization_id
3207 , uom_code
3208 , quantity
3209 , project_id
3210 , task_id
3211 , source_type_code
3212 FROM po_requisitions_interface
3213 WHERE requisition_header_id = p_header_id
3214 AND interface_source_code = 'CTO'
3215 UNION
3216 select prl.requisition_header_id
3217 , prl.requisition_line_id
3218 , interface_source_line_id
3219 , need_by_date
3220 , item_id
3221 , destination_organization_id
3222 , uom_code
3223 , quantity
3224 , project_id
3225 , task_id
3226 , source_type_code
3227 from po_requisition_lines_all prl, po_requisition_headers_all prh , po_req_distributions_all prd, mtl_units_of_measure muom
3228 where prh.requisition_header_id = p_header_id
3229 and prh.REQUISITION_HEADER_ID = prl.REQUISITION_HEADER_ID
3230 and prd.requisition_line_id = prl.requisition_line_id
3231 and nvl(prl.modified_by_agent_flag,'N') <> 'Y'
3232 AND muom.unit_of_measure= unit_meas_lookup_code
3233 and not exists (select null
3234 FROM po_requisitions_interface pri
3235 where pri.requisition_header_id = prh.requisition_header_id
3236 and pri.interface_source_code = 'CTO');
3237
3238
3239
3240 --get the sales order header for the sales order line
3241 --the interface table does not have the sales order header information
3242 --
3243 /* Bug 2693130: Changed the table name in the following cursor
3244 from 'oe_order_lines' to 'oe_order_lines_all' */
3245
3246 CURSOR get_sales_order_line(v_demand_line_id IN NUMBER) IS
3247 SELECT header_id
3248 , ordered_quantity
3249 , order_quantity_uom
3250 FROM oe_order_lines_all
3251 WHERE line_id = v_demand_line_id
3252 AND cancelled_flag = 'N';
3253
3254 --
3255 --get quantity that is already reserved against INV
3256 --this is subtracted from the sales order quantity which
3257 --will then be the quantity that is to be reserved
3258 --
3259
3260 CURSOR get_inv_res_qty(v_demand_header_id IN NUMBER,
3261 v_demand_line_id IN NUMBER) IS
3262 --SELECT sum(nvl(reservation_quantity,0))
3263 SELECT sum(nvl(primary_reservation_quantity,0)) sum_pri_res_qty, primary_uom_code
3264 FROM mtl_reservations
3265 WHERE demand_source_header_id = v_demand_header_id
3266 AND demand_source_line_id = v_demand_line_id
3267 AND demand_source_type_id in (inv_reservation_global.g_source_type_oe,
3268 inv_reservation_global.g_source_type_internal_ord)
3269 GROUP BY primary_uom_code;
3270 -- AND supply_source_type_id = inv_reservation_global.g_source_type_inv;
3271 -- comment out last restriction supply_source_type_id = inv_reservation_global.g_source_type_inv
3272 -- since starting from r12, we will start to open manual reservations for WIP job....
3273
3274
3275 /* Bug# 3085721, This Cursor will check if the reservation is already
3276 created for the Requisitions */
3277
3278 CURSOR get_res_exists(v_requisition_header_id IN NUMBER,
3279 v_requisition_line_id IN NUMBER) IS
3280 SELECT 'Exists'
3281 FROM mtl_reservations
3282 WHERE supply_source_header_id = v_requisition_header_id
3283 AND supply_source_line_id = v_requisition_line_id
3284 AND Supply_source_type_id=inv_reservation_global.g_source_type_req;
3285
3286 CURSOR get_po_shipment(v_po_header_id IN NUMBER) IS
3287 SELECT pll.po_header_id
3288 ,pll.po_line_id
3289 ,pll.line_location_id
3290 ,pll.ship_to_organization_id
3291 ,pl.item_id
3292 FROM po_line_locations_all pll
3293 ,po_lines_all pl
3294 WHERE pll.po_header_id = v_po_header_id
3295 AND pl.po_line_id = pll.po_line_id;
3296
3297
3298 CURSOR get_req_line_of_po_shipment(v_po_shipment_id IN NUMBER) IS
3299 SELECT b.requisition_line_id req_line_id
3300 , Nvl(b.project_id,-99) project_id
3301 , Nvl(b.task_id, -99) task_id
3302 -- , sum(a.quantity_ordered) quantity_ordered
3303 FROM po_distributions_all a
3304 , po_req_distributions_all b
3305 WHERE a.line_location_id = v_po_shipment_id
3306 AND a.req_distribution_id = b.distribution_id
3307 AND a.distribution_type <> 'AGREEMENT' --<Encumbrance FPJ>
3308 GROUP BY b.requisition_line_id
3309 , b.project_id
3310 , b.task_id;
3311
3312 CURSOR get_pt_count_po_shipment(v_po_shipment_id IN NUMBER) IS
3313 SELECT COUNT(min(po_distribution_id)) count
3314 FROM po_distributions_all pd
3315 WHERE pd.line_location_id = v_po_shipment_id
3316 GROUP BY project_id, task_id;
3317
3318 CURSOR get_proj_task_of_po_shipment(v_po_shipment_id IN NUMBER) IS
3319 SELECT Nvl(project_id, -99) project_id, Nvl(task_id, -99) task_id
3320 FROM po_distributions_all
3321 WHERE line_location_id = v_po_shipment_id
3322 GROUP BY project_id,task_id;
3323
3324 CURSOR get_po_res_qty(v_po_header_id IN NUMBER
3325 ,v_po_line_location_id IN NUMBER
3326 ,v_project_id IN NUMBER
3327 ,v_task_id IN NUMBER) IS
3328 SELECT reservation_uom_code
3329 , primary_uom_code
3330 , sum(nvl(primary_reservation_quantity,0)) primary_reservation_quantity
3331 FROM mtl_reservations
3332 WHERE supply_source_header_id = v_po_header_id
3333 AND supply_source_line_id = v_po_line_location_id
3334 AND supply_source_type_id = inv_reservation_global.g_source_type_po
3335 AND Nvl(project_id,-99) = nvl(v_project_id, -99)
3336 AND Nvl(task_id,-99) = nvl(v_task_id, -99)
3337 GROUP BY reservation_uom_code
3338 , primary_uom_code;
3339
3340
3341 CURSOR get_po_shipment_for_release(v_po_header_id IN NUMBER) IS
3342 SELECT pll.po_header_id
3343 , pll.po_line_id
3344 , pll.line_location_id
3345 , pll.ship_to_organization_id --?? is it correct org_id ??
3346 , pl.item_id
3347 FROM po_line_locations_all pll
3348 ,po_lines_all pl
3349 WHERE pll.po_release_id = v_po_header_id
3350 AND pll.po_line_id = pl.po_line_id;
3351
3352 --
3353 -- get requisition lines for the req header
3354 -- to delete the reservation on the req (remove req supply)
3355 --
3356 CURSOR get_req_hdr_lines (v_po_req_header_id IN NUMBER) IS
3357 SELECT requisition_line_id, source_type_code
3358 FROM po_requisition_lines_all --<Shared Proc FPJ>
3359 WHERE requisition_header_id = v_po_req_header_id;
3360
3361 --
3362 --get the PO header for the po line id that is cancelled
3363 --when po line is cancelled the reservations needs to be transferred back to the req or deleted
3364 --
3365 CURSOR get_po_header_id_line(v_po_line_id IN NUMBER) IS
3366 SELECT po_header_id
3367 FROM po_lines_all --<Shared Proc FPJ>
3368 WHERE po_line_id = v_po_line_id;
3369
3370
3371 --
3372 --get Distribution Records for the PO Line ID
3373 --when a PO line is cancelled the reservations needs to be transferred back to the req or deleted
3374 --
3375
3376 --BUG#3497445.Added po_line_id in the cursor below.
3377
3378 CURSOR get_line_loc_for_po_line (v_po_line_id IN NUMBER) IS
3379 SELECT pll.po_header_id
3380 , pll.po_line_id
3381 , pll.line_location_id
3382 , pll.ship_to_organization_id
3383 , pl.item_id
3384 , pll.quantity
3385 FROM po_line_locations_all pll, po_lines_all pl --<Shared Proc FPJ>
3386 WHERE pl.po_line_id = v_po_line_id
3387 AND pl.po_line_id = pll.po_line_id;
3388
3389 --
3390 --get PO Header ID for the PO Line Location ID
3391 --to Check whether reservation exists for the PO
3392 --
3393 CURSOR get_po_header_id_shipment (v_po_line_location_id IN NUMBER)IS
3394 SELECT po_header_id
3395 FROM po_line_locations_all --<Shared Proc FPJ>
3396 WHERE line_location_id = p_line_location_id;
3397
3398
3399 --
3400 --get Distribution Records for the PO Line Location ID
3401 --cancel shipment need to transfer reservation from PO to req or be deleted
3402 --
3403
3404 --BUG#3497445.In cursor below the po_line_id was also fetched for fetching the quantity and UOM from the PO Lines.
3405
3406 CURSOR get_line_loc_for_po_shipment (v_po_line_location_id IN NUMBER) IS
3407 SELECT pll.po_header_id
3408 , pll.po_line_id
3409 , pll.line_location_id
3410 , pll.ship_to_organization_id
3411 , pl.item_id
3412 , pll.quantity
3413 FROM po_line_locations_all pll, po_lines_all pl--<Shared Proc FPJ>
3414 WHERE pll.line_location_id = v_po_line_location_id AND
3415 pl.po_line_id = pll.po_line_id;
3416
3417 --
3418 --release ID will come as Header ID
3419 --get the po header id for the release
3420 --when a release is cancelled the reservations need to be transferred from the PO to the req or
3421 --deleted
3422 --
3423 CURSOR get_po_header_id_release (v_po_header_id IN NUMBER)IS
3424 SELECT po_header_id
3425 FROM po_releases_all --<Shared Proc FPJ>
3426 WHERE po_release_id = v_po_header_id;
3427 --
3428 --get Distribution Records for the PO Release ID
3429 --
3430
3431 --BUG#3497445.In cursor below the po_line_id was also fetched for fetching the quantity and UOM from the PO Lines.
3432
3433 CURSOR get_distr_for_po_release (v_po_header_id IN NUMBER) IS
3434 SELECT po_header_id
3435 , po_line_id
3436 , line_location_id
3437 , req_distribution_id
3438 , quantity_ordered
3439 FROM po_distributions_all --<Shared Proc FPJ>
3440 WHERE po_release_id = v_po_header_id;
3441
3442 CURSOR get_source_doc_code (v_transaction_id IN NUMBER) IS
3443 SELECT source_document_code, organization_id FROM rcv_transactions
3444 WHERE transaction_id = v_transaction_id;
3445
3446 CURSOR get_rcv_transaction (v_transaction_id IN NUMBER) IS
3447 SELECT decode(a.source_document_code,'PO'
3448 , decode(b.asn_line_flag, 'Y', 'ASN', 'PO'), a.source_document_code) supply_type
3449 , a.po_header_id, a.po_line_id
3450 , a.po_line_location_id
3451 , a.po_distribution_id
3452 , d.uom_code primary_unit_of_measure
3453 , a.primary_quantity
3454 , a.requisition_line_id
3455 , a.req_distribution_id
3456 , a.shipment_line_id
3457 , a.shipment_header_id
3458 , a.subinventory
3459 , a.locator_id
3460 , a.organization_id
3461 , a.lpn_id
3462 , b.item_revision
3463 , b.item_id
3464 , b.to_organization_id
3465 , c.project_id
3466 , c.task_id
3467 FROM rcv_transactions a
3468 , rcv_shipment_lines b
3469 , po_distributions_all c
3470 , mtl_units_of_measure d
3471 WHERE transaction_id = v_transaction_id
3472 AND a.shipment_line_id = b.shipment_line_id
3473 AND c.po_distribution_id = a.po_distribution_id
3474 AND c.po_header_id = a.po_header_id
3475 AND c.po_line_id = a.po_line_id
3476 AND c.line_location_id = a.po_line_location_id
3477 AND d.unit_of_measure = a.primary_unit_of_measure;
3478
3479 --Bug#3009495 Get the lot number for the delivered item
3480 CURSOR get_rcv_lot_number(v_shipment_line_id IN NUMBER) IS
3481 SELECT lot_num
3482 , primary_quantity
3483 FROM rcv_lot_transactions
3484 WHERE shipment_line_id = v_shipment_line_id;
3485
3486 -- Bug 5611560
3487 CURSOR get_rcv_txn_lot_number(v_shipment_line_id IN NUMBER, v_transaction_id IN NUMBER) IS
3488 SELECT lot_num
3489 , primary_quantity
3490 FROM rcv_lot_transactions
3491 WHERE shipment_line_id = v_shipment_line_id
3492 AND transaction_id = v_transaction_id;
3493
3494 CURSOR get_rcv_transaction_asn(v_transaction_id IN NUMBER) IS
3495 SELECT a.po_header_id
3496 , a.po_line_id
3497 , a.po_line_location_id
3498 , a.po_distribution_id
3499 , d.uom_code primary_unit_of_measure
3500 , a.primary_quantity
3501 , a.shipment_line_id
3502 , a.subinventory
3503 , a.locator_id
3504 , a.organization_id
3505 , a.lpn_id
3506 , b.item_revision
3507 , b.item_id
3508 , b.to_organization_id
3509 , c.project_id
3510 , c.task_id
3511 FROM rcv_transactions a
3512 , rcv_shipment_lines b
3513 , po_distributions_all c
3514 , mtl_units_of_measure d
3515 WHERE a.transaction_id = v_transaction_id
3516 AND a.source_document_code = 'PO'
3517 AND b.shipment_line_id = a.shipment_line_id
3518 AND b.asn_line_flag = 'Y'
3519 AND c.po_distribution_id = a.po_distribution_id
3520 AND c.po_header_id = a.po_header_id
3521 AND c.po_line_id = a.po_line_id
3522 AND c.line_location_id = a.po_line_location_id
3523 AND d.unit_of_measure = a.primary_unit_of_measure;
3524
3525
3526 CURSOR get_rcv_txn_int_req(v_transaction_id IN NUMBER) IS
3527
3528 SELECT a.requisition_line_id
3529 , e.uom_code primary_unit_of_measure
3530 , a.primary_quantity
3531 , a.shipment_line_id
3532 , a.subinventory
3533 , a.locator_id
3534 , a.organization_id
3535 , a.lpn_id
3536 , b.item_revision
3537 , b.item_id
3538 , b.to_organization_id
3539 , c.project_id
3540 , c.task_id
3541 , d.requisition_header_id
3542 FROM rcv_transactions a
3543 , rcv_shipment_lines b
3544 , po_req_distributions_all c
3545 , po_requisition_lines_all d
3546 , mtl_units_of_measure e
3547 WHERE a.transaction_id = v_transaction_id
3548 AND a.source_document_code = 'REQ'
3549 AND b.shipment_line_id = a.shipment_line_id
3550 AND c.distribution_id = a.req_distribution_id
3551 AND c.requisition_line_id = a.requisition_line_id
3552 AND d.requisition_line_id = c.requisition_line_id
3553 AND e.unit_of_measure = a.primary_unit_of_measure;
3554
3555
3556 --are we sure the req_distribution_id is populated in rcv_transactions ???
3557
3558 -- Define Constants for API version and API name
3559 C_api_version_number CONSTANT NUMBER := 1.0;
3560 C_api_name CONSTANT VARCHAR2(30) := 'Maintain_Reservation';
3561 C_Module_Name Constant Varchar2(2000) := 'inv.plsql.inv_maintain_reservation.Maintain_Reservation';
3562 C_Debug_Enabled Constant Number := 1 ;
3563
3564 --l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
3565 l_Fnd_Log_Message VARCHAR2(2000);
3566
3567 l_return_status VARCHAR2(1);
3568 l_reservation_quantity NUMBER;
3569 l_demand_header_id NUMBER;
3570 l_ordered_quantity NUMBER;
3571 l_exist_inv_res_qty NUMBER;
3572 l_temp_res_qty NUMBER;
3573 l_lead_time NUMBER; -- Bug# 2984835.
3574 l_res_exists VARCHAR2(10); -- Bug# 3085721.
3575
3576 l_rsv_rec inv_reservation_global.mtl_reservation_rec_type;
3577 l_rsv_array inv_reservation_global.mtl_reservation_tbl_type;
3578
3579 l_record_count NUMBER;
3580 l_qty_avail_to_reserve NUMBER;
3581 l_qty_avail NUMBER;
3582 l_po_primary_qty NUMBER;
3583 l_primary_res_quantity NUMBER;
3584 l_po_header_id NUMBER;
3585 l_record_index NUMBER;
3586 l_primary_quantity NUMBER;
3587 l_supply_source_type_id NUMBER;
3588 l_source_type_code VARCHAR2(25);
3589
3590 --l_msg_count NUMBER;
3591 --l_msg_data VARCHAR2(2000);
3592 l_msg_index_out NUMBER;
3593 l_org_id NUMBER;
3594
3595 l_item_revision VARCHAR2(3);
3596 l_revision_control_code NUMBER;
3597 l_lot_control_code NUMBER;
3598
3599 l_quantity_modified NUMBER;
3600
3601 --interface_record get_interface_records%ROWTYPE;
3602 sales_order_record get_sales_order_line%ROWTYPE;
3603 get_inv_res_qty_rec get_inv_res_qty%ROWTYPE;
3604
3605 get_po_shipment_rec get_po_shipment%ROWTYPE;
3606 get_req_line_po_shipment_rec get_req_line_of_po_shipment%ROWTYPE;
3607 get_pt_count_po_shipment_rec get_pt_count_po_shipment%ROWTYPE;
3608 get_pt_po_shipment_rec get_proj_task_of_po_shipment%ROWTYPE;
3609
3610 l_mtl_maint_rsv_rec inv_reservation_global.mtl_maintain_rsv_rec_type;
3611
3612 get_po_res_qty_rec get_po_res_qty%ROWTYPE;
3613 get_po_shipment_rel_rec get_po_shipment_for_release%ROWTYPE;
3614 get_req_hdr_lines_rec get_req_hdr_lines%ROWTYPE;
3615 -- get_distr_rec get_distr_for_po_line%ROWTYPE;
3616 get_line_loc_rec get_line_loc_for_po_line%ROWTYPE;
3617 get_rcv_lot_number_rec GET_RCV_LOT_NUMBER%ROWTYPE;
3618
3619 get_rcv_transaction_rec get_rcv_transaction%ROWTYPE;
3620 get_rcv_transaction_asn_rec get_rcv_transaction_asn%ROWTYPE;
3621 get_rcv_txn_int_req_rec get_rcv_txn_int_req%ROWTYPE;
3622 p_mtl_maintain_rsv_rec inv_reservation_global.mtl_maintain_rsv_rec_type;
3623 get_source_doc_code_rec get_source_doc_code%ROWTYPE;
3624 l_delete_flag VARCHAR2(1);
3625 l_sort_by_criteria Number;
3626 --l_transaction_id NUMBER;
3627 --Bug 5253916: For update so qty
3628 l_organization_id NUMBER;
3629 l_inventory_item_id NUMBER;
3630 l_primary_res_qty NUMBER;
3631 l_req_unit_meas VARCHAR2(25);
3632 l_req_qty NUMBER;
3633
3634 --Bug# 2984835.
3635 CURSOR get_lead_time (v_item_id IN NUMBER
3636 ,v_org_id IN NUMBER) IS
3637 SELECT POSTPROCESSING_LEAD_TIME
3638 FROM MTL_SYSTEM_ITEMS
3639 WHERE INVENTORY_ITEM_ID = v_item_id
3640 AND ORGANIZATION_ID = v_org_id;
3641
3642 BEGIN
3643
3644 l_Fnd_Log_message := 'Begining of procedure :';
3645
3646 -- Log message in trace file
3647 IF g_debug= C_Debug_Enabled THEN
3648 g_Version_Printed := TRUE ;
3649 mydebug(l_Fnd_Log_Message,c_api_name,9);
3650 g_Version_Printed := FALSE ;
3651 END IF;
3652
3653 -- Bug 3600118: Initialize return status variable
3654 l_return_status := FND_API.g_ret_sts_success;
3655
3656 -- print out all the IN paramter values
3657 IF g_debug= C_Debug_Enabled THEN
3658 l_Fnd_Log_Message := 'p_header_id : '|| p_header_id ;
3659 mydebug(l_Fnd_Log_Message, c_api_name,9);
3660 l_Fnd_Log_Message := 'p_line_id : '|| p_line_id ;
3661 mydebug(l_Fnd_Log_Message, c_api_name,9);
3662 l_Fnd_Log_Message := 'p_line_location_id : '|| p_line_location_id ;
3663 mydebug(l_Fnd_Log_Message, c_api_name,9);
3664 -- l_Fnd_Log_Message := 'p_distribution_id : '|| p_distribution_id ;
3665 mydebug(l_Fnd_Log_Message, c_api_name,9);
3666 l_Fnd_Log_Message := 'p_transaction_id : '|| p_transaction_id ;
3667 mydebug(l_Fnd_Log_Message, c_api_name,9);
3668 l_Fnd_Log_Message := 'p_ordered_quantity : '|| p_ordered_quantity ;
3669 mydebug(l_Fnd_Log_Message, c_api_name,9);
3670 l_Fnd_Log_Message := 'p_ordered_uom : '|| p_ordered_uom ;
3671 mydebug(l_Fnd_Log_Message, c_api_name,9);
3672 l_Fnd_Log_Message := 'p_action : '|| p_action ;
3673 mydebug(l_Fnd_Log_Message, c_api_name,9);
3674 END IF;
3675
3676 IF p_action IS NULL
3677 OR LTRIM(p_action) = '' THEN
3678 IF g_debug = C_Debug_Enabled THEN
3679 l_Fnd_Log_Message := 'Null action code';
3680 mydebug(l_Fnd_Log_Message, c_api_name,9);
3681 END IF;
3682 RAISE fnd_api.g_exc_unexpected_error;
3683 END IF;
3684
3685 IF upper(p_action) = 'APPROVE_REQ_SUPPLY' THEN
3686 --replace with FOR Loops
3687 --OPEN get_interface_records;
3688 --null;
3689
3690 IF g_debug = C_Debug_Enabled THEN
3691 l_Fnd_Log_Message := 'Approve Req Supply ';
3692 mydebug(l_Fnd_Log_Message, c_api_name,9);
3693 END IF;
3694
3695 FOR interface_record_rec IN get_interface_records LOOP
3696
3697 -- get the records after req import runs - to create reservation on the req
3698
3699 --FETCH get_interface_records into interface_record;
3700 --EXIT WHEN get_interface_records%NOTFOUND;
3701
3702 l_reservation_quantity := interface_record_rec.quantity;
3703
3704 OPEN get_sales_order_line(interface_record_rec.interface_source_line_id);
3705
3706 IF g_debug= C_Debug_Enabled THEN
3707 l_Fnd_Log_Message := 'interface_source_line_id: '||interface_record_rec.interface_source_line_id;
3708 mydebug(l_Fnd_Log_Message, c_api_name,9);
3709 END IF;
3710
3711 FETCH get_sales_order_line INTO sales_order_record;
3712 EXIT WHEN get_sales_order_line%NOTFOUND;
3713 --CLOSE get_sales_order_line;
3714
3715 l_demand_header_id := oe_header_util.get_mtl_sales_order_id(sales_order_record.header_id);
3716 l_ordered_quantity := sales_order_record.ordered_quantity;
3717
3718 IF g_debug= C_Debug_Enabled THEN
3719 l_Fnd_Log_Message := 'l_ordered_quantity :'||l_ordered_quantity;
3720 mydebug(l_Fnd_Log_Message, c_api_name,9);
3721 END IF;
3722 --
3723 OPEN get_inv_res_qty(l_demand_header_id
3724 , interface_record_rec.interface_source_line_id);
3725 --
3726 --FETCH get_inv_res_qty INTO l_exist_inv_res_qty;
3727 FETCH get_inv_res_qty INTO get_inv_res_qty_rec;
3728 --CLOSE get_inv_res_qty;
3729
3730 IF g_debug= C_Debug_Enabled THEN
3731 l_Fnd_Log_Message := 'sales_order_record.order_quantity_uom: '||sales_order_record.order_quantity_uom;
3732 mydebug(l_Fnd_Log_Message, c_api_name,9);
3733 l_Fnd_Log_Message := 'l_ordered_quantity: '||l_ordered_quantity;
3734 mydebug(l_Fnd_Log_Message, c_api_name,9);
3735 l_Fnd_Log_Message := 'get_inv_res_qty_rec.sum_pri_res_qty: '||get_inv_res_qty_rec.sum_pri_res_qty;
3736 mydebug(l_Fnd_Log_Message, c_api_name,9);
3737 l_Fnd_Log_Message := 'get_inv_res_qty_rec.primary_uom_code: '||get_inv_res_qty_rec.primary_uom_code;
3738 mydebug(l_Fnd_Log_Message, c_api_name,9);
3739 END IF;
3740
3741 IF sales_order_record.order_quantity_uom = get_inv_res_qty_rec.primary_uom_code THEN
3742 l_exist_inv_res_qty := get_inv_res_qty_rec.sum_pri_res_qty;
3743 ELSE
3744 l_exist_inv_res_qty := inv_convert.inv_um_convert
3745 (
3746 item_id => interface_record_rec.item_id --number,
3747 ,precision => NULL --number,
3748 ,from_quantity => get_inv_res_qty_rec.sum_pri_res_qty --number,
3749 ,from_unit => get_inv_res_qty_rec.primary_uom_code --varchar2,
3750 ,to_unit => sales_order_record.order_quantity_uom --varchar2,
3751 ,from_name => NULL --varchar2,
3752 ,to_name => NULL --varchar2
3753 );
3754 END IF;
3755
3756 CLOSE get_inv_res_qty;
3757 CLOSE get_sales_order_line;
3758 --
3759 -- calculate the actual quantity to be reserved;
3760 --
3761 -- SELECT nvl((l_ordered_quantity - nvl(l_exist_inv_res_qty,0)),l_ordered_quantity)
3762 --INTO l_temp_res_qty
3763 --FROM DUAL;
3764
3765 l_temp_res_qty := nvl((l_ordered_quantity - nvl(l_exist_inv_res_qty,0)),l_ordered_quantity);
3766 --
3767 IF nvl(l_temp_res_qty,0) < nvl(l_reservation_quantity,0) THEN
3768 l_reservation_quantity := l_temp_res_qty;
3769 END IF;
3770 --
3771
3772 /* Bug# 2984835,
3773 In maintain reservation we need to pass need_by_date+post-process-lead-time
3774 to the reservation routine. This is a part of the Bug fix done in
3775 Bug# 2931808 */
3776
3777 IF g_debug= C_Debug_Enabled THEN
3778 l_Fnd_Log_Message := 'l_reservation_quantity: '||l_reservation_quantity;
3779 mydebug(l_Fnd_Log_Message, c_api_name,9);
3780 END IF;
3781
3782 --
3783 IF interface_record_rec.item_id is not NULL then
3784 OPEN get_lead_time (interface_record_rec.item_id
3785 ,interface_record_rec.destination_organization_id);
3786 FETCH get_lead_time INTO l_lead_time;
3787 CLOSE get_lead_time;
3788 END IF;
3789 --
3790 /* Bug# 3085721, If Encumbrance is ON the supply Code will be called twice.
3791 This creates 2 Resevations records. To avoid this we check if the
3792 reservation already exists we do not create reservation */
3793
3794
3795 OPEN get_res_exists(interface_record_rec.requisition_header_id,
3796 interface_record_rec.requisition_line_id);
3797 FETCH get_res_exists INTO l_res_exists;
3798 IF g_debug= C_Debug_Enabled THEN
3799 l_Fnd_Log_Message := 'progress 600 ';
3800 mydebug(l_Fnd_Log_Message, c_api_name,9);
3801 END IF;
3802 IF get_res_exists%NOTFOUND THEN
3803 IF g_debug= C_Debug_Enabled THEN
3804 l_Fnd_Log_Message := 'reservation is not existing ';
3805 mydebug(l_Fnd_Log_Message, c_api_name,9);
3806 END IF;
3807 -- Get the source_type_code to determine the requistion type
3808 IF Upper(interface_record_rec.source_type_code) = 'INVENTORY' THEN
3809 l_supply_source_type_id := inv_reservation_global.g_source_type_internal_req;
3810 else
3811 l_supply_source_type_id := inv_reservation_global.g_source_type_req;
3812 END IF;
3813
3814 CREATE_RES
3815 ( p_inventory_item_id => interface_record_rec.item_id
3816 ,p_organization_id => interface_record_rec.destination_organization_id
3817 ,p_demand_source_header_id => l_demand_header_id
3818 ,p_demand_source_line_id => interface_record_rec.interface_source_line_id
3819 ,p_supply_source_type_id => l_supply_source_type_id
3820 ,p_supply_source_header_id => p_header_id
3821 ,p_supply_source_line_id => interface_record_rec.requisition_line_id
3822 ,p_requirement_date => interface_record_rec.need_by_date + nvl(l_lead_time,0)
3823 ,p_reservation_quantity => l_reservation_quantity
3824 ,p_reservation_uom_code => interface_record_rec.uom_code
3825 ,p_project_id => interface_record_rec.project_id
3826 ,p_task_id => interface_record_rec.task_id
3827 ,x_msg_count => x_msg_count
3828 ,x_msg_data => x_msg_data
3829 ,x_return_status => l_return_status);
3830
3831 IF g_debug= C_Debug_Enabled THEN
3832 l_Fnd_Log_Message := 'calling create_res :l_return_status: '|| l_return_status;
3833 mydebug(l_Fnd_Log_Message, c_api_name,9);
3834 END IF;
3835
3836 x_return_status := l_return_status;
3837
3838 If x_return_status = fnd_api.g_ret_sts_success THEN
3839 l_Fnd_Log_message := 'Calling CREATE_RES API was successful ';
3840 -- Fnd_Log_Debug(fnd_log.Level_Error,C_Module_name, l_Fnd_Log_Message );
3841 IF G_debug= C_Debug_Enabled THEN
3842 mydebug(l_Fnd_Log_Message, c_api_name,9);
3843 END IF;
3844 else
3845 l_Fnd_Log_message := 'Error while calling CREATE_RES API ';
3846 -- Fnd_Log_Debug(fnd_log.Level_Error,C_Module_name, l_Fnd_Log_Message );
3847 IF G_debug= C_Debug_Enabled THEN
3848 mydebug(l_Fnd_Log_Message, c_api_name,9);
3849 END IF;
3850 end if;
3851
3852 END IF;
3853 CLOSE get_res_exists;
3854
3855 END LOOP; -- get interface_records
3856 --CLOSE get_interface_records;
3857
3858 IF g_debug= C_Debug_Enabled THEN
3859 l_Fnd_Log_Message := 'progress 800 ';
3860 mydebug(l_Fnd_Log_Message, c_api_name,9);
3861 END IF;
3862
3863 ELSIF upper(p_action) = 'APPROVE_PO_SUPPLY' THEN
3864 --IF upper(p_action) = 'APPROVE_PO_SUPPLY' THEN
3865 IF g_debug= C_Debug_Enabled THEN
3866 l_Fnd_Log_Message := 'Inside of APPROVE_PO_SUPPLY ';
3867 mydebug(l_Fnd_Log_Message, c_api_name,9);
3868 END IF;
3869
3870 IF NOT EXISTS_RESERVATION(p_supply_source_header_id => p_header_id) THEN
3871 -- normal path taken when a PO is approved and there is no reservation on the PO
3872 --
3873
3874 IF g_debug= C_Debug_Enabled THEN
3875 l_Fnd_Log_Message := 'Inside no reservations. p_header_id: '||p_header_id;
3876 mydebug(l_Fnd_Log_Message, c_api_name,9);
3877 l_Fnd_Log_Message := 'No reservation existing for PO, normal path taken when a PO is approved ';
3878 mydebug(l_Fnd_Log_Message, c_api_name,9);
3879 END IF;
3880
3881 OPEN get_po_shipment(p_header_id);
3882 LOOP
3883 FETCH get_po_shipment INTO get_po_shipment_rec;
3884 EXIT WHEN get_po_shipment%NOTFOUND;
3885
3886 IF g_debug= C_Debug_Enabled THEN
3887 l_Fnd_Log_Message := 'get_po_shipment_rec.line_location_id: '||get_po_shipment_rec.line_location_id;
3888 mydebug(l_Fnd_Log_Message, c_api_name,9);
3889 END IF;
3890
3891 OPEN get_req_line_of_po_shipment(get_po_shipment_rec.line_location_id);
3892 LOOP
3893 FETCH get_req_line_of_po_shipment INTO get_req_line_po_shipment_rec;
3894 EXIT WHEN get_req_line_of_po_shipment%NOTFOUND;
3895
3896 IF g_debug= C_Debug_Enabled THEN
3897 l_Fnd_Log_Message := 'Before get_req_line_po_shipment_rec.project_id: '||get_req_line_po_shipment_rec.project_id;
3898 mydebug(l_Fnd_Log_Message, c_api_name,9);
3899 l_Fnd_Log_Message := 'before get_req_line_po_shipment_rec.task_id: '||get_req_line_po_shipment_rec.task_id;
3900 mydebug(l_Fnd_Log_Message, c_api_name,9);
3901 END IF;
3902
3903 IF (get_req_line_po_shipment_rec.project_id = -99) THEN
3904 get_req_line_po_shipment_rec.project_id := NULL;
3905 END IF;
3906 IF (get_req_line_po_shipment_rec.task_id = -99) THEN
3907 get_req_line_po_shipment_rec.task_id := NULL;
3908 END IF;
3909
3910 IF g_debug= C_Debug_Enabled THEN
3911 l_Fnd_Log_Message := 'after get_req_line_po_shipment_rec.project_id: '||get_req_line_po_shipment_rec.project_id;
3912 mydebug(l_Fnd_Log_Message, c_api_name,9);
3913 l_Fnd_Log_Message := 'after get_req_line_po_shipment_rec.task_id: '||get_req_line_po_shipment_rec.task_id;
3914 mydebug(l_Fnd_Log_Message, c_api_name,9);
3915 END IF;
3916 --IF (get_req_line_po_shipment_rec.project_id IS NOT NULL
3917 -- OR
3918 -- get_req_line_po_shipment_rec.task_id IS NOT NULL) THEN
3919
3920 INV_RESERVATION_AVAIL_PVT.available_supply_to_reserve
3921 (
3922 x_return_status =>l_return_status --OUT NOCOPY VARCHAR2
3923 , x_msg_count =>x_msg_count --OUT NOCOPY NUMBER
3924 , x_msg_data =>x_msg_data --OUT NOCOPY VARCHAR2
3925 , p_organization_id =>get_po_shipment_rec.ship_to_organization_id--IN NUMBER default null
3926 , p_item_id =>get_po_shipment_rec.item_id --IN NUMBER default null
3927 , p_supply_source_type_id =>inv_reservation_global.g_source_type_po --IN NUMBER
3928 , p_supply_source_header_id =>p_header_id --IN NUMBER
3929 , p_supply_source_line_id =>get_po_shipment_rec.line_location_id --IN NUMBER
3930 , p_project_id =>get_req_line_po_shipment_rec.project_id--IN NUMBER default null
3931 , p_task_id =>get_req_line_po_shipment_rec.task_id --IN NUMBER default null
3932 , x_qty_available_to_reserve =>l_qty_avail_to_reserve --OUT NOCOPY NUMBER
3933 , x_qty_available =>l_qty_avail --OUT NOCOPY NUMBER
3934 );
3935
3936 IF g_debug= C_Debug_Enabled THEN
3937 l_Fnd_Log_Message := 'l_qty_avail_to_reserve: '|| l_qty_avail_to_reserve;
3938 mydebug(l_Fnd_Log_Message, c_api_name,9);
3939 l_Fnd_Log_Message := 'l_qty_avail: '|| l_qty_avail;
3940 mydebug(l_Fnd_Log_Message, c_api_name,9);
3941 END IF;
3942
3943 -- check to see if reservation exist on the req line
3944 -- Under normal circumstances, there will be a reservation on a req-line
3945 --
3946 get_req_line_res
3947 (p_req_line_id =>get_req_line_po_shipment_rec.req_line_id,
3948 p_project_id =>get_req_line_po_shipment_rec.project_id,
3949 p_task_id =>get_req_line_po_shipment_rec.task_id,
3950 x_res_array =>l_rsv_array,
3951 x_record_count =>l_record_count);
3952
3953 IF g_debug= C_Debug_Enabled THEN
3954 l_Fnd_Log_Message := 'l_record_count: '|| l_record_count;
3955 mydebug(l_Fnd_Log_Message, c_api_name,9);
3956 END IF;
3957
3958 IF l_record_count > 0 THEN
3959 -- we should not compare a req_line reservation_qty with po_shipment_order_qty
3960 -- since po shipment can comparise of multi req_line....
3961 -- also there is no manual reservation against external req.,
3962 -- so available_to_reserve qty should be the same as ordered_qty
3963 -- plus there is no reservation for this PO
3964 -- this is first time for PO approve. before PO approve, we can not
3965 -- create manual reservation against non-approved PO
3966 -- only when PO approved, system created reservation plus manual reservation
3967 -- can be created against this approved PO.
3968 l_rsv_rec := l_rsv_array(1);
3969 -- since l_qty_avail_to_reserve is already in primary_uom, there is
3970 -- no need to convert.
3971 /*uom_conversion(l_rsv_rec.reservation_uom_code
3972 ,l_rsv_rec.primary_uom_code
3973 ,l_qty_avail_to_reserve
3974 ,get_po_shipment_rec.po_line_id
3975 ,l_reservation_quantity
3976 ,l_po_primary_qty); */
3977
3978 if (l_rsv_rec.primary_reservation_quantity > l_qty_avail_to_reserve) THEN
3979 IF g_debug= C_Debug_Enabled THEN
3980 l_Fnd_Log_Message := 'calling update_res API ';
3981 mydebug(l_Fnd_Log_Message, c_api_name,9);
3982 END IF;
3983
3984 update_res
3985 (p_supply_source_header_id => l_rsv_rec.supply_source_header_id
3986 ,p_supply_source_line_id => l_rsv_rec.supply_source_line_id
3987 ,p_supply_source_type_id => inv_reservation_global.g_source_type_req
3988 ,p_primary_reservation_quantity => l_qty_avail_to_reserve
3989 ,p_project_id => get_req_line_po_shipment_rec.project_id
3990 ,p_task_id => get_req_line_po_shipment_rec.task_id
3991 ,p_reservation_id => l_rsv_rec.reservation_id
3992 ,x_msg_count => x_msg_count
3993 ,x_msg_data => x_msg_data
3994 ,x_return_status => l_return_status);
3995 end if;
3996
3997
3998 --BUG#3497445.The l_po_primary_qty calculated from the UOM_conversion call is used below.
3999
4000 l_primary_res_quantity := least(l_rsv_rec.primary_reservation_quantity,
4001 l_qty_avail_to_reserve);
4002 IF g_debug= C_Debug_Enabled THEN
4003 l_Fnd_Log_Message := 'l_primary_res_quantity: '|| l_primary_res_quantity;
4004 mydebug(l_Fnd_Log_Message, c_api_name,9);
4005 END IF;
4006
4007 IF g_debug= C_Debug_Enabled THEN
4008 l_Fnd_Log_Message := 'calling transfer reservation for, From req line id: '||l_rsv_rec.supply_source_line_id || ' to po shipment line id: ' || get_po_shipment_rec.line_location_id;
4009 mydebug(l_Fnd_Log_Message, c_api_name,9);
4010 END IF;
4011
4012 -- calling transfer_res with project_id, task_id
4013 TRANSFER_RES
4014 (p_from_reservation_id =>l_rsv_rec.reservation_id
4015 ,p_from_source_header_id =>l_rsv_rec.supply_source_header_id
4016 ,p_from_source_line_id =>l_rsv_rec.supply_source_line_id
4017 ,p_supply_source_type_id =>inv_reservation_global.g_source_type_req
4018 ,p_to_source_header_id =>p_header_id
4019 ,p_to_source_line_id =>get_po_shipment_rec.line_location_id
4020 ,p_to_supply_source_type_id =>inv_reservation_global.g_source_type_po
4021 ,p_primary_uom_code =>l_rsv_rec.primary_uom_code
4022 ,p_primary_res_quantity =>l_primary_res_quantity
4023 ,x_msg_count => x_msg_count
4024 ,x_msg_data => x_msg_data
4025 ,x_return_status =>l_return_status);
4026
4027 IF g_debug= C_Debug_Enabled THEN
4028 l_Fnd_Log_Message := 'after calling transfer_res. The l_return_status : '||l_return_status;
4029 mydebug(l_Fnd_Log_Message, c_api_name,9);
4030 END IF;
4031
4032 ELSE -- if did not have any req reservation existing
4033 FND_MESSAGE.SET_NAME('INV','INV_API_NO_RSV_EXIST');
4034 FND_MSG_PUB.Add;
4035 l_Fnd_Log_Message := 'calling get_req_line_res, no reservation records';
4036 mydebug(l_Fnd_Log_Message, c_api_name,9);
4037 END IF; -- record_count
4038
4039 END LOOP;
4040 CLOSE get_req_line_of_po_shipment;
4041
4042 END LOOP;
4043 CLOSE get_po_shipment;
4044
4045 ELSE
4046 -- reservation exists, means that
4047 -- new req lines were added to an already approved PO
4048 -- and therefore reservations need to be transferred from req-line to PO
4049 IF g_debug= C_Debug_Enabled THEN
4050 l_Fnd_Log_Message := 'reservation existing for PO ';
4051 mydebug(l_Fnd_Log_Message, c_api_name,9);
4052 END IF;
4053 OPEN get_po_shipment(p_header_id);
4054 LOOP
4055 FETCH get_po_shipment INTO get_po_shipment_rec;
4056 EXIT WHEN get_po_shipment%NOTFOUND;
4057
4058 IF g_debug= C_Debug_Enabled THEN
4059 l_Fnd_Log_Message := 'get_po_shipment_rec.line_location_id: '||get_po_shipment_rec.line_location_id;
4060 mydebug(l_Fnd_Log_Message, c_api_name,9);
4061 END IF;
4062 OPEN get_req_line_of_po_shipment(get_po_shipment_rec.line_location_id);
4063 LOOP
4064 FETCH get_req_line_of_po_shipment INTO get_req_line_po_shipment_rec;
4065 EXIT WHEN get_req_line_of_po_shipment%NOTFOUND;
4066
4067 IF g_debug= C_Debug_Enabled THEN
4068 l_Fnd_Log_Message := 'before calling get_req_line_res... ';
4069 mydebug(l_Fnd_Log_Message, c_api_name,9);
4070 END IF;
4071 get_req_line_res(p_req_line_id =>get_req_line_po_shipment_rec.req_line_id,
4072 p_project_id =>get_req_line_po_shipment_rec.project_id,
4073 p_task_id =>get_req_line_po_shipment_rec.task_id,
4074 x_res_array =>l_rsv_array,
4075 x_record_count =>l_record_count);
4076
4077 IF g_debug= C_Debug_Enabled THEN
4078 l_Fnd_Log_Message := 'after calling get_req_line_res,l_record_count: '|| l_record_count;
4079 mydebug(l_Fnd_Log_Message, c_api_name,9);
4080 END IF;
4081
4082 IF l_record_count > 0 THEN
4083 l_rsv_rec := l_rsv_array(1);
4084
4085 IF g_debug= C_Debug_Enabled THEN
4086 l_Fnd_Log_Message := 'calling transfer_res with following IN values:';
4087 mydebug(l_Fnd_Log_Message, c_api_name,9);
4088 END IF;
4089 TRANSFER_RES
4090 (p_from_reservation_id =>l_rsv_rec.reservation_id
4091 ,p_from_source_header_id =>l_rsv_rec.supply_source_header_id
4092 ,p_from_source_line_id =>l_rsv_rec.supply_source_line_id
4093 ,p_supply_source_type_id =>inv_reservation_global.g_source_type_req
4094 ,p_to_source_header_id =>p_header_id
4095 ,p_to_source_line_id =>get_po_shipment_rec.line_location_id
4096 ,p_to_supply_source_type_id =>inv_reservation_global.g_source_type_po
4097 ,p_primary_uom_code =>l_rsv_rec.primary_uom_code
4098 ,p_primary_res_quantity =>l_rsv_rec.primary_reservation_quantity
4099 ,x_msg_count =>x_msg_count
4100 ,x_msg_data =>x_msg_data
4101 ,x_return_status =>l_return_status);
4102 IF g_debug= C_Debug_Enabled THEN
4103 l_Fnd_Log_Message := 'after calling transfer_res. The l_return_status : '||l_return_status;
4104 mydebug(l_Fnd_Log_Message, c_api_name,9);
4105 END IF;
4106 ELSE
4107 FND_MESSAGE.SET_NAME('INV','INV_API_NO_RSV_EXIST');
4108 FND_MSG_PUB.Add;
4109 l_Fnd_Log_Message := 'calling get_req_line_res, no reservation records';
4110 mydebug(l_Fnd_Log_Message, c_api_name,9);
4111 END IF;
4112
4113 END LOOP;
4114 CLOSE get_req_line_of_po_shipment;
4115
4116 OPEN get_pt_count_po_shipment(get_po_shipment_rec.line_location_id);
4117 FETCH get_pt_count_po_shipment into get_pt_count_po_shipment_rec;
4118 CLOSE get_pt_count_po_shipment;
4119
4120 IF g_debug= C_Debug_Enabled THEN
4121 l_Fnd_Log_Message := ' get_pt_count_po_shipment_rec.count : '||get_pt_count_po_shipment_rec.count;
4122 mydebug(l_Fnd_Log_Message, c_api_name,9);
4123 END IF;
4124
4125 IF get_pt_count_po_shipment_rec.count > 1 THEN -- multiple project/task
4126
4127 IF g_debug= C_Debug_Enabled THEN
4128 l_Fnd_Log_Message := 'Multiple project/task... ';
4129 l_Fnd_Log_Message := 'get_po_shipment_rec.org_id:'||get_po_shipment_rec.ship_to_organization_id;
4130 mydebug(l_Fnd_Log_Message, c_api_name,9);
4131 END IF;
4132
4133 IF (inv_install.adv_inv_installed(get_po_shipment_rec.ship_to_organization_id)) THEN
4134 -- is wms org
4135 -- delete all the reservations for this shipment
4136 -- log message
4137 IF g_debug= C_Debug_Enabled THEN
4138 l_Fnd_Log_Message := 'Organization is wms org. calling delete_res API with IN parameters';
4139 mydebug(l_Fnd_Log_Message, c_api_name,9);
4140 END IF;
4141 -- Call reduce reservations instead of delete
4142 -- reservations
4143 -- Call the reduce reservations API by setting the
4144 -- delete_flag to yes. delete all reservations for that
4145 -- supply line.
4146 -- calling reduce_reservation API
4147 l_delete_flag := 'Y';
4148 l_sort_by_criteria := inv_reservation_global.g_query_demand_ship_date_desc;
4149 l_mtl_maint_rsv_rec.action := 0;--supply is reduced
4150 l_mtl_maint_rsv_rec.organization_id :=
4151 get_po_shipment_rec.ship_to_organization_id;
4152 l_mtl_maint_rsv_rec.inventory_item_id :=
4153 get_po_shipment_rec.item_id;
4154 l_mtl_maint_rsv_rec.supply_source_type_id:= inv_reservation_global.g_source_type_po;
4155 l_mtl_maint_rsv_rec.supply_source_header_id := p_header_id;
4156 l_mtl_maint_rsv_rec.supply_source_line_id :=
4157 get_po_shipment_rec.line_location_id;
4158 --l_mtl_maint_rsv_rec.supply_source_line_detail := NULL;
4159
4160 reduce_reservation
4161 (
4162 p_api_version_number => 1.0
4163 , p_init_msg_lst => fnd_api.g_false
4164 , x_return_status => l_return_status
4165 , x_msg_count => x_msg_count
4166 , x_msg_data => x_msg_data
4167 , p_mtl_maintain_rsv_rec => l_mtl_maint_rsv_rec
4168 , p_delete_flag => l_delete_flag
4169 , p_sort_by_criteria => l_sort_by_criteria
4170 , x_quantity_modified => l_quantity_modified);
4171 IF g_debug= C_Debug_Enabled THEN
4172 mydebug ('Return Status after calling reduce reservations: '|| l_return_status, c_api_name,9);
4173 END IF;
4174
4175 IF l_return_status = fnd_api.g_ret_sts_error THEN
4176
4177 IF g_debug= C_Debug_Enabled THEN
4178 mydebug('Raising expected error'||l_return_status, c_api_name,9);
4179 END IF;
4180 RAISE fnd_api.g_exc_error;
4181
4182 ELSIF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
4183
4184 IF g_debug= C_Debug_Enabled THEN
4185 mydebug('Rasing Unexpected error'||l_return_status, c_api_name,9);
4186 END IF;
4187 RAISE fnd_api.g_exc_unexpected_error;
4188
4189 END IF;
4190 /***** Call reduce reservations instead of delete reservations
4191 DELETE_RES
4192 (p_supply_source_header_id => p_header_id
4193 ,p_supply_source_line_id => get_po_shipment_rec.line_location_id
4194 ,p_supply_source_type_id => inv_reservation_global.g_source_type_po
4195 ,x_msg_count => x_msg_count
4196 ,x_msg_data => x_msg_data
4197 ,x_return_status => l_return_status);
4198 IF g_debug= C_Debug_Enabled THEN
4199 l_Fnd_Log_Message := 'l_return_status: '||l_return_status;
4200 END IF;
4201 End comment*******/
4202 END IF;
4203 END IF;
4204
4205 IF g_debug= C_Debug_Enabled THEN
4206 mydebug('Line location id' || get_po_shipment_rec.line_location_id, c_api_name,9);
4207 END IF;
4208 OPEN get_proj_task_of_po_shipment(get_po_shipment_rec.line_location_id);
4209 LOOP
4210 FETCH get_proj_task_of_po_shipment INTO
4211 get_pt_po_shipment_rec;
4212 EXIT WHEN get_proj_task_of_po_shipment%NOTFOUND;
4213
4214 IF g_debug= C_Debug_Enabled THEN
4215 mydebug('Inside project/task loop', c_api_name,9);
4216 END IF;
4217 IF g_debug= C_Debug_Enabled THEN
4218 mydebug('Project Id: '|| get_pt_po_shipment_rec.project_id, c_api_name,9);
4219 mydebug('Task Id: '|| get_pt_po_shipment_rec.task_id, c_api_name,9);
4220 END IF;
4221
4222
4223 IF (get_pt_po_shipment_rec.project_id = -99) THEN
4224 get_pt_po_shipment_rec.project_id := NULL;
4225 END IF;
4226 IF (get_pt_po_shipment_rec.task_id = -99) THEN
4227 get_pt_po_shipment_rec.task_id := NULL;
4228 END IF;
4229 INV_RESERVATION_AVAIL_PVT.available_supply_to_reserve
4230 (
4231 x_return_status => l_return_status
4232 , x_msg_count => x_msg_count
4233 , x_msg_data => x_msg_data
4234 , p_organization_id => get_po_shipment_rec.ship_to_organization_id
4235 , p_item_id => get_po_shipment_rec.item_id
4236 , p_supply_source_type_id => inv_reservation_global.g_source_type_po
4237 , p_supply_source_header_id => p_header_id
4238 , p_supply_source_line_id => get_po_shipment_rec.line_location_id
4239 , p_project_id => get_pt_po_shipment_rec.project_id
4240 , p_task_id => get_pt_po_shipment_rec.task_id
4241 , x_qty_available_to_reserve => l_qty_avail_to_reserve
4242 , x_qty_available => l_qty_avail
4243 );
4244
4245
4246 OPEN get_po_res_qty
4247 (p_header_id
4248 ,get_po_shipment_rec.line_location_id
4249 ,get_pt_po_shipment_rec.project_id
4250 ,get_pt_po_shipment_rec.task_id);
4251 FETCH get_po_res_qty INTO get_po_res_qty_rec ;
4252 CLOSE get_po_res_qty ;
4253
4254 IF g_debug= C_Debug_Enabled THEN
4255 mydebug('Qty available: '|| l_qty_avail, c_api_name,9);
4256 mydebug('Qty available to reserve: '|| l_qty_avail_to_reserve, c_api_name,9);
4257 mydebug('Qty reserved qty: '|| get_po_res_qty_rec.primary_reservation_quantity, c_api_name,9);
4258 END IF;
4259 IF get_po_res_qty_rec.primary_reservation_quantity > 0 THEN
4260 -- since l_qty_avail_to_reserve is already in primary uom,
4261 -- there is no need to convert it again
4262 -- comment out the following uom convertion
4263 /*uom_conversion(get_po_res_qty_rec.reservation_uom_code
4264 ,get_po_res_qty_rec.primary_uom_code
4265 ,l_qty_avail_to_reserve
4266 ,get_po_shipment_rec.po_line_id
4267 ,l_reservation_quantity
4268 ,l_po_primary_qty);*/
4269
4270 IF (get_po_res_qty_rec.primary_reservation_quantity > l_qty_avail) THEN
4271 -- calling reduce_reservation API
4272 l_mtl_maint_rsv_rec.action := 0;--supply is reduced
4273 l_sort_by_criteria := inv_reservation_global.g_query_demand_ship_date_desc;
4274 l_mtl_maint_rsv_rec.organization_id :=
4275 get_po_shipment_rec.ship_to_organization_id;
4276 l_mtl_maint_rsv_rec.inventory_item_id :=
4277 get_po_shipment_rec.item_id;
4278 l_mtl_maint_rsv_rec.supply_source_type_id:= inv_reservation_global.g_source_type_po;
4279 l_mtl_maint_rsv_rec.supply_source_header_id := p_header_id;
4280 l_mtl_maint_rsv_rec.supply_source_line_id := get_po_shipment_rec.line_location_id;
4281 -- l_mtl_maint_rsv_rec.supply_source_line_detail := NULL;
4282 --l_mtl_maint_rsv_rec.expected_quantity := get_po_res_qty_rec.primary_reservation_quantity - l_qty_avail_to_reserve;
4283 l_mtl_maint_rsv_rec.expected_quantity := l_qty_avail;
4284 l_mtl_maint_rsv_rec.expected_quantity_uom :=
4285 get_po_res_qty_rec.primary_uom_code;
4286 l_mtl_maint_rsv_rec.project_id :=
4287 get_pt_po_shipment_rec.project_id;
4288 l_mtl_maint_rsv_rec.task_id := get_pt_po_shipment_rec.task_id;
4289
4290 reduce_reservation
4291 (
4292 p_api_version_number => 1.0
4293 , p_init_msg_lst => fnd_api.g_false
4294 , x_return_status => l_return_status
4295 , x_msg_count => x_msg_count
4296 , x_msg_data => x_msg_data
4297 , p_mtl_maintain_rsv_rec => l_mtl_maint_rsv_rec
4298 , p_delete_flag => 'N'
4299 , p_sort_by_criteria => l_sort_by_criteria
4300 , x_quantity_modified => l_quantity_modified);
4301
4302 IF g_debug= C_Debug_Enabled THEN
4303 mydebug ('Return Status after calling reduce reservations: '|| l_return_status, c_api_name,9);
4304 END IF;
4305
4306 IF l_return_status = fnd_api.g_ret_sts_error THEN
4307
4308 IF g_debug= C_Debug_Enabled THEN
4309 mydebug('Raising expected error'||l_return_status, c_api_name,9);
4310 END IF;
4311 RAISE fnd_api.g_exc_error;
4312
4313 ELSIF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
4314
4315 IF g_debug= C_Debug_Enabled THEN
4316 mydebug('Rasing Unexpected error'||l_return_status, c_api_name,9);
4317 END IF;
4318 RAISE fnd_api.g_exc_unexpected_error;
4319
4320 END IF;
4321
4322 END IF;
4323 END IF; -- > 0
4324
4325 END LOOP;
4326 CLOSE get_proj_task_of_po_shipment;
4327
4328 END LOOP;
4329 CLOSE get_po_shipment;
4330 END IF; -- if not_exist()
4331 ELSIF upper(p_action) = 'DELIVER_TO_INVENTORY' THEN
4332 IF g_debug= C_Debug_Enabled THEN
4333 l_Fnd_Log_Message := 'Deliver To Inventory. p_transaction_id : '||p_transaction_id;
4334 mydebug(l_Fnd_Log_Message, c_api_name,9);
4335 END IF;
4336
4337 -- IF p_transaction_id IS NULL THEN
4338 -- l_transaction_id := p_header_id;
4339 -- ELSE
4340 -- l_transaction_id := p_transaction_id;
4341 -- END IF;
4342
4343 IF (p_transaction_id IS NULL) THEN
4344 FND_MESSAGE.SET_NAME('INV','INV_INVALID_TRANSACTION_ID');
4345 FND_MSG_PUB.ADD;
4346 RAISE fnd_api.g_exc_error;
4347 END IF;
4348
4349 OPEN get_source_doc_code(p_transaction_id);
4350 FETCH get_source_doc_code INTO get_source_doc_code_rec;
4351
4352 --IF g_debug= C_Debug_Enabled THEN
4353 -- l_Fnd_Log_Message := 'p_transaction_id : '|| l_transaction_id;
4354 -- mydebug(l_Fnd_Log_Message, c_api_name,9);
4355 -- END IF;
4356
4357 IF g_debug= C_Debug_Enabled THEN
4358 l_Fnd_Log_Message := 'get_source_doc_code_rec.organization_id : '||get_source_doc_code_rec.organization_id;
4359 mydebug(l_Fnd_Log_Message, c_api_name,9);
4360 END IF;
4361
4362 IF (get_source_doc_code_rec.organization_id IS NULL) THEN
4363 IF g_debug= C_Debug_Enabled THEN
4364 mydebug('Could not find the organization for the transaction id:' || p_transaction_id, c_api_name,9);
4365 END IF;
4366 RAISE fnd_api.g_exc_error;
4367 END IF;
4368
4369 IF (inv_install.adv_inv_installed(get_source_doc_code_rec.organization_id)) THEN
4370 -- wms org
4371 -- return
4372 IF g_debug= C_Debug_Enabled THEN
4373 l_Fnd_Log_Message := 'it is WMS organization, return.';
4374 mydebug(l_Fnd_Log_Message, c_api_name,9);
4375 END IF;
4376
4377 IF get_source_doc_code%isopen THEN
4378 CLOSE get_source_doc_code;
4379 END if;
4380
4381 RETURN;
4382 ELSE
4383
4384 IF g_debug= C_Debug_Enabled THEN
4385 l_Fnd_Log_Message := 'it is Inventory organization';
4386 mydebug(l_Fnd_Log_Message, c_api_name,9);
4387 l_Fnd_Log_Message := 'get_source_doc_code_rec.source_document_code :'|| get_source_doc_code_rec.source_document_code;
4388 mydebug(l_Fnd_Log_Message, c_api_name,9);
4389 END IF;
4390
4391 IF (get_source_doc_code_rec.source_document_code = 'PO') THEN
4392 OPEN get_rcv_transaction(p_transaction_id);
4393 FETCH get_rcv_transaction into get_rcv_transaction_rec;
4394 --CLOSE get_rcv_transaction;
4395
4396 IF get_rcv_transaction_rec.supply_type = 'PO' THEN
4397
4398 IF g_debug= C_Debug_Enabled THEN
4399 l_Fnd_Log_Message := 'DTI. supply_type is PO';
4400 mydebug(l_Fnd_Log_Message, c_api_name,9);
4401 END IF;
4402 IF get_rcv_transaction%FOUND THEN
4403
4404 IF g_debug= C_Debug_Enabled THEN
4405 l_Fnd_Log_Message := 'get_rcv_transaction_rec.item_revision: '||get_rcv_transaction_rec.item_revision;
4406 mydebug(l_Fnd_Log_Message, c_api_name,9);
4407 END IF;
4408 IF get_rcv_transaction_rec.item_revision is NULL then
4409 IF g_debug= C_Debug_Enabled THEN
4410 l_Fnd_Log_Message := 'get_rcv_transaction_rec.item_revision is NULL ';
4411 mydebug(l_Fnd_Log_Message, c_api_name,9);
4412 END IF;
4413
4414 BEGIN
4415 SELECT max(mir.revision)
4416 INTO l_item_revision
4417 FROM mtl_system_items msi
4418 , mtl_item_revisions mir
4419 WHERE msi.inventory_item_id = get_rcv_transaction_rec.item_id
4420 AND msi.organization_id = get_rcv_transaction_rec.organization_id
4421 AND msi.revision_qty_control_code = 2
4422 AND mir.organization_id = msi.organization_id
4423 AND msi.inventory_item_id = msi.inventory_item_id
4424 AND mir.effectivity_date in
4425 (SELECT MAX(mir2.effectivity_date)
4426 FROM mtl_item_revisions mir2
4427 WHERE mir2.organization_id = get_rcv_transaction_rec.organization_id
4428 AND mir2.inventory_item_id = get_rcv_transaction_rec.item_id
4429 AND mir2.effectivity_date <= SYSDATE
4430 AND mir2.implementation_date is not NULL);
4431
4432
4433 get_rcv_transaction_rec.item_revision := l_item_revision;
4434
4435 EXCEPTION
4436 when others then
4437 l_item_revision := NULL;
4438 get_rcv_transaction_rec.item_revision := NULL;
4439 END;
4440
4441 IF g_debug= C_Debug_Enabled THEN
4442 l_Fnd_Log_Message := 'l_item_revision :'||l_item_revision;
4443 mydebug(l_Fnd_Log_Message, c_api_name,9);
4444 END IF;
4445
4446 ELSE
4447 /* Begin Bug 3688014 : If the rcv_shipment_lines contains a item revision
4448 for a non-revision controlled item, we should pass a NULL
4449 item revision to inventory so that supply gets updated accordingly.
4450 */
4451
4452 IF g_debug= C_Debug_Enabled THEN
4453 l_Fnd_Log_Message := 'get_rcv_transaction_rec.item_revision is NOT NULL ';
4454 mydebug(l_Fnd_Log_Message, c_api_name,9);
4455 END IF;
4456
4457 BEGIN
4458
4459 SELECT msi.revision_qty_control_code
4460 INTO l_revision_control_code
4461 FROM mtl_system_items_b msi
4462 WHERE msi.inventory_item_id = get_rcv_transaction_rec.item_id
4463 AND msi.organization_id = get_rcv_transaction_rec.organization_id;
4464
4465 IF l_revision_control_code = 1 THEN
4466 get_rcv_transaction_rec.item_revision := NULL;
4467 END IF;
4468
4469 EXCEPTION
4470 WHEN others THEN
4471 get_rcv_transaction_rec.item_revision := NULL;
4472 END;
4473
4474 IF g_debug= C_Debug_Enabled THEN
4475 l_Fnd_Log_Message := 'l_revision_control_code : '|| l_revision_control_code;
4476 mydebug(l_Fnd_Log_Message, c_api_name,9);
4477 END IF;
4478
4479 /* End Bug 3688014 */
4480
4481 END IF; --get_rcv_transaction_rec.item_revision is NULL
4482
4483 --Bug#3009495.If item is lot controlled then we will derive the lot number
4484 --from the rcv_lot_transactions.
4485 get_rcv_lot_number_rec.lot_num := NULL;
4486 --IF get_shipment_lines%FOUND THEN
4487
4488 --Bug 7559682 Error performing deliver transaction for Direct Items in EAM workorder
4489 --having destination type as shop floor. Modified the code block to include MSI query
4490 BEGIN
4491 select nvl(lot_control_code,1)
4492 into l_lot_control_code
4493 from mtl_system_items
4494 where organization_id = get_rcv_transaction_rec.to_organization_id
4495 and inventory_item_id = get_rcv_transaction_rec.item_id ;
4496
4497 IF (l_lot_control_code = 2) THEN
4498 --Begin --commented for bug 7559682
4499 -- 5611560 New cursor is opened and fetcched.
4500 OPEN get_rcv_txn_lot_number(get_rcv_transaction_rec.shipment_line_id,p_transaction_id);
4501 FETCH get_rcv_txn_lot_number INTO get_rcv_lot_number_rec;
4502 END IF;
4503
4504 EXCEPTION
4505 WHEN OTHERS THEN
4506 get_rcv_lot_number_rec.lot_num := NULL;
4507 l_lot_control_code := 1;
4508 -- END; --commented for bug 7559682
4509
4510 --End If; --commented for bug 7559682
4511 END;
4512 -- End If; -- End Bug#3009495
4513
4514 IF g_debug= C_Debug_Enabled THEN
4515 l_Fnd_Log_Message := 'Calling query_res with following IN paramter values: ';
4516 mydebug(l_Fnd_Log_Message, c_api_name,9);
4517 l_Fnd_Log_Message := 'p_supply_source_header_id :' || get_rcv_transaction_rec.po_header_id;
4518 mydebug(l_Fnd_Log_Message, c_api_name,9);
4519 l_Fnd_Log_Message := 'p_supply_source_line_id : '|| get_rcv_transaction_rec.po_line_location_id;
4520 mydebug(l_Fnd_Log_Message, c_api_name,9);
4521 l_Fnd_Log_Message := 'p_supply_source_type_id : '|| inv_reservation_global.g_source_type_po;
4522 mydebug(l_Fnd_Log_Message, c_api_name,9);
4523 l_Fnd_Log_Message := 'p_project_id : '|| get_rcv_transaction_rec.project_id;
4524 mydebug(l_Fnd_Log_Message, c_api_name,9);
4525 l_Fnd_Log_Message := 'p_task_id: '||get_rcv_transaction_rec.task_id;
4526 mydebug(l_Fnd_Log_Message, c_api_name,9);
4527 END IF;
4528 query_res(p_supply_source_header_id => get_rcv_transaction_rec.po_header_id
4529 ,p_supply_source_line_id => get_rcv_transaction_rec.po_line_location_id
4530 ,p_supply_source_type_id => inv_reservation_global.g_source_type_po
4531 ,p_project_id => get_rcv_transaction_rec.project_id
4532 ,p_task_id => get_rcv_transaction_rec.task_id
4533 ,x_rsv_array => l_rsv_array
4534 ,x_record_count => l_record_count
4535 ,x_msg_count => x_msg_count
4536 ,x_msg_data => x_msg_data
4537 ,x_return_status => l_return_status);
4538
4539 IF g_debug= C_Debug_Enabled THEN
4540 l_Fnd_Log_Message := 'l_record_count: '||l_record_count;
4541 mydebug(l_Fnd_Log_Message, c_api_name,9);
4542 l_Fnd_Log_Message := 'l_return_status: '||l_return_status;
4543 mydebug(l_Fnd_Log_Message, c_api_name,9);
4544 END IF;
4545 IF l_record_count > 0 THEN
4546 l_record_index := 1;
4547
4548 LOOP
4549 EXIT WHEN get_rcv_transaction_rec.primary_quantity = 0;
4550 IF g_debug= C_Debug_Enabled THEN
4551 l_Fnd_Log_Message := 'get_rcv_transaction_rec.primary_quantity: '||get_rcv_transaction_rec.primary_quantity;
4552 mydebug(l_Fnd_Log_Message, c_api_name,9);
4553 END IF;
4554 IF l_record_index <= l_record_count THEN
4555 IF g_debug= C_Debug_Enabled THEN
4556 l_Fnd_Log_Message := 'l_record_index: '||l_record_index;
4557 mydebug(l_Fnd_Log_Message, c_api_name,9);
4558 l_Fnd_Log_Message := 'l_rsv_array(l_record_index).primary_reservation_quantity:'||l_rsv_array(l_record_index).primary_reservation_quantity;
4559 mydebug(l_Fnd_Log_Message, c_api_name,9);
4560 l_Fnd_Log_Message := 'calling transfer_res with folling IN paramter values:';
4561 mydebug(l_Fnd_Log_Message, c_api_name,9);
4562
4563 END IF;
4564
4565 -- 4891711 use lot level quantities where lot control is appropriate
4566 IF l_rsv_array(l_record_index).primary_reservation_quantity
4567 > NVL(get_rcv_lot_number_rec.primary_quantity,get_rcv_transaction_rec.primary_quantity) THEN
4568 TRANSFER_RES
4569 (p_from_reservation_id => l_rsv_array(l_record_index).reservation_id
4570 , p_from_source_header_id => get_rcv_transaction_rec.po_header_id
4571 ,p_from_source_line_id => get_rcv_transaction_rec.po_line_location_id
4572 ,p_supply_source_type_id => inv_reservation_global.g_source_type_po
4573 ,p_to_supply_source_type_id => inv_reservation_global.g_source_type_inv
4574 ,p_subinventory_code => get_rcv_transaction_rec.subinventory
4575 ,p_locator_id => get_rcv_transaction_rec.locator_id
4576 ,p_lot_number => NVL(get_rcv_lot_number_rec.lot_num, NULL)
4577 ,p_revision => get_rcv_transaction_rec.item_revision
4578 ,p_lpn_id => get_rcv_transaction_rec.lpn_id
4579 ,p_primary_uom_code => get_rcv_transaction_rec.primary_unit_of_measure
4580 ,p_primary_res_quantity => NVL(get_rcv_lot_number_rec.primary_quantity,get_rcv_transaction_rec.primary_quantity)
4581 ,x_msg_count => x_msg_count
4582 ,x_msg_data => x_msg_data
4583 ,x_return_status => l_return_status);
4584 --get_rcv_transaction_rec.primary_quantity := 0;
4585
4586 get_rcv_transaction_rec.primary_quantity := get_rcv_transaction_rec.primary_quantity
4587 - NVL(get_rcv_lot_number_rec.primary_quantity,get_rcv_transaction_rec.primary_quantity);
4588
4589 -- Bug 5611560 *** Possible case of split reservation .
4590 -- Set the Remaining reservation Quantity which is still can be transferred.
4591 -- The Lot can be fully satisfied by the Reservation so Set the Lot qty as Zero.
4592
4593 l_rsv_array(l_record_index).primary_reservation_quantity :=
4594 l_rsv_array(l_record_index).primary_reservation_quantity
4595 - NVL(get_rcv_lot_number_rec.primary_quantity,
4596 get_rcv_transaction_rec.primary_quantity
4597 );
4598
4599 IF (l_lot_control_code = 2) then
4600 get_rcv_lot_number_rec.primary_quantity := 0;
4601 END IF;
4602
4603 IF g_debug= C_Debug_Enabled THEN
4604 l_Fnd_Log_Message := 'Remaining reserv Qty := '||
4605 l_rsv_array(l_record_index).primary_reservation_quantity;
4606 mydebug(l_Fnd_Log_Message, c_api_name,9);
4607 END IF;
4608
4609 ELSE
4610 TRANSFER_RES
4611 (p_from_reservation_id => l_rsv_array(l_record_index).reservation_id
4612 ,p_from_source_header_id => get_rcv_transaction_rec.po_header_id
4613 ,p_from_source_line_id => get_rcv_transaction_rec.po_line_location_id
4614 ,p_supply_source_type_id => inv_reservation_global.g_source_type_po
4615 ,p_to_supply_source_type_id => inv_reservation_global.g_source_type_inv
4616 ,p_subinventory_code => get_rcv_transaction_rec.subinventory
4617 ,p_locator_id => get_rcv_transaction_rec.locator_id
4618 ,p_lot_number => NVL(get_rcv_lot_number_rec.lot_num, NULL)
4619 ,p_revision => get_rcv_transaction_rec.item_revision
4620 ,p_lpn_id => get_rcv_transaction_rec.lpn_id
4621 ,p_primary_uom_code => get_rcv_transaction_rec.primary_unit_of_measure
4622 ,p_primary_res_quantity => l_rsv_array(l_record_index).primary_reservation_quantity
4623 ,x_msg_count => x_msg_count
4624 ,x_msg_data => x_msg_data
4625 ,x_return_status => l_return_status);
4626
4627 get_rcv_transaction_rec.primary_quantity := get_rcv_transaction_rec.primary_quantity
4628 - l_rsv_array(l_record_index).primary_reservation_quantity;
4629
4630 -- Bug 5611560. reservation is fully consumed. So Set the
4631 -- Remaining resesrvation for this row as zero .
4632 -- Also Reduce the Lot Qty by the Reservation Qty transferred to Inv the same way
4633 -- as done above for delivered qty.
4634
4635 IF (l_lot_control_code = 2) then
4636
4637 get_rcv_lot_number_rec.primary_quantity := get_rcv_lot_number_rec.primary_quantity
4638 - l_rsv_array(l_record_index).primary_reservation_quantity;
4639
4640 IF g_debug= C_Debug_Enabled THEN
4641 l_Fnd_Log_Message := 'Remaining lot Qty := '||
4642 get_rcv_lot_number_rec.primary_quantity;
4643 mydebug(l_Fnd_Log_Message, c_api_name,9);
4644 END IF;
4645 END IF;
4646
4647 l_rsv_array(l_record_index).primary_reservation_quantity := 0;
4648
4649 IF g_debug= C_Debug_Enabled THEN
4650 l_Fnd_Log_Message := 'Reservation Transfered completely for this Line';
4651 mydebug(l_Fnd_Log_Message, c_api_name,9);
4652 END IF;
4653
4654 END IF;
4655
4656 IF g_debug= C_Debug_Enabled THEN
4657 l_Fnd_Log_Message := 'l_return_status:'||l_return_status;
4658 mydebug(l_Fnd_Log_Message, c_api_name,9);
4659 END IF;
4660 ELSE
4661 IF g_debug= C_Debug_Enabled THEN
4662 l_Fnd_Log_Message := 'l_record_index >
4663 l_record_count. more received than
4664 reserved. l_record_count :' ||
4665 l_record_count || ' l_record_index: '
4666 || l_record_index;
4667 mydebug(l_Fnd_Log_Message,
4668 c_api_name,9);
4669 END IF;
4670 EXIT;
4671 END IF; -- res_qty > received_qty
4672 -- 4891711 BEGIN need lot level looping
4673
4674 -- 5611560
4675 -- Changed the Logic so that when reservation qty is set as zero the index is increased
4676 -- Also when there is no more Lot rows just exit from the Loop;
4677 --
4678 IF (l_lot_control_code = 2) then
4679 Begin
4680 IF get_rcv_lot_number_rec.primary_quantity = 0 then
4681 FETCH get_rcv_txn_lot_number INTO get_rcv_lot_number_rec;
4682 IF get_rcv_txn_lot_number%NOTFOUND THEN
4683 CLOSE get_rcv_txn_lot_number;
4684 --l_record_index := l_record_index + 1;
4685 -- No Need to Loop again Just Return from here.
4686 EXIT;
4687 END IF;
4688 END IF;
4689 END;
4690 END IF;
4691
4692 -- Bug 5611560
4693 -- Increase the Index when no more reservation qty to be transfered.
4694 IF ( l_rsv_array(l_record_index).primary_reservation_quantity = 0 ) THEN
4695 l_record_index := l_record_index + 1;
4696 End If;
4697
4698 -- 4891711 END
4699
4700 END LOOP;
4701 ELSE -- l_record_count = 0
4702 -- there is no reservation existing
4703 -- log messeage
4704 IF g_debug= C_Debug_Enabled THEN
4705 l_Fnd_Log_Message := 'l_return_status:'||l_return_status;
4706 mydebug(l_Fnd_Log_Message, c_api_name,9);
4707 END IF;
4708
4709 END IF; -- l_record_count > 0
4710
4711 END IF; -- get_rcv_transaction%found
4712
4713 ELSIF get_rcv_transaction_rec.supply_type = 'ASN' THEN
4714 IF g_debug= C_Debug_Enabled THEN
4715 mydebug( 'DTI. ASN.', c_api_name,9);
4716 END IF;
4717 OPEN get_rcv_transaction_asn(p_transaction_id);
4718 FETCH get_rcv_transaction_asn into get_rcv_transaction_asn_rec;
4719 --CLOSE get_rcv_transaction_asn;
4720
4721 IF get_rcv_transaction_asn%FOUND THEN
4722
4723 IF get_rcv_transaction_asn_rec.item_revision is NULL then
4724
4725 BEGIN
4726 SELECT max(mir.revision)
4727 INTO l_item_revision
4728 FROM mtl_system_items msi
4729 , mtl_item_revisions mir
4730 WHERE msi.inventory_item_id = get_rcv_transaction_asn_rec.item_id
4731 AND msi.organization_id = get_rcv_transaction_asn_rec.organization_id
4732 AND msi.revision_qty_control_code = 2
4733 AND mir.organization_id = msi.organization_id
4734 AND msi.inventory_item_id = msi.inventory_item_id
4735 AND mir.effectivity_date in
4736 (SELECT MAX(mir2.effectivity_date)
4737 FROM mtl_item_revisions mir2
4738 WHERE mir2.organization_id = get_rcv_transaction_asn_rec.organization_id
4739 AND mir2.inventory_item_id = get_rcv_transaction_asn_rec.item_id
4740 AND mir2.effectivity_date <= SYSDATE
4741 AND mir2.implementation_date is not NULL);
4742
4743
4744 get_rcv_transaction_rec.item_revision := l_item_revision;
4745
4746 EXCEPTION when others then
4747 l_item_revision := NULL;
4748 get_rcv_transaction_rec.item_revision := NULL;
4749 END;
4750
4751 ELSE
4752 /* Begin Bug 3688014 : If the rcv_shipment_lines contains a item revision
4753 for a non-revision controlled item, we should pass a NULL
4754 item revision to inventory so that supply gets updated accordingly.
4755 */
4756 BEGIN
4757
4758 SELECT msi.revision_qty_control_code
4759 INTO l_revision_control_code
4760 FROM mtl_system_items_b msi
4761 WHERE msi.inventory_item_id = get_rcv_transaction_asn_rec.item_id
4762 AND msi.organization_id = get_rcv_transaction_asn_rec.organization_id;
4763
4764 IF l_revision_control_code = 1 THEN
4765 get_rcv_transaction_asn_rec.item_revision := NULL;
4766 END IF;
4767
4768 EXCEPTION
4769 WHEN others THEN
4770 get_rcv_transaction_asn_rec.item_revision := NULL;
4771 END;
4772
4773 /* End Bug 3688014 */
4774
4775 END IF; --get_rcv_transaction_asn_rec.item_revision is NULL
4776
4777
4778 --Bug#3009495.If item is lot controlled then we will derive the lot number
4779 --from the rcv_lot_transactions.
4780 get_rcv_lot_number_rec.lot_num := NULL;
4781 --IF get_shipment_lines%FOUND THEN
4782
4783 --Bug 7559682 Error performing deliver transaction for Direct Items in EAM workorder
4784 --having destination type as shop floor. Modified the code block to include MSI query
4785 BEGIN
4786 select nvl(lot_control_code,1)
4787 into l_lot_control_code
4788 from mtl_system_items
4789 where organization_id = get_rcv_transaction_rec.to_organization_id
4790 and inventory_item_id = get_rcv_transaction_rec.item_id ;
4791
4792 IF (l_lot_control_code = 2) THEN
4793 --Begin --commented for bug 7559682
4794 -- 5611560 New cursor is opened and fetched.
4795 OPEN get_rcv_txn_lot_number(get_rcv_transaction_rec.shipment_line_id,p_transaction_id);
4796 FETCH get_rcv_txn_lot_number INTO get_rcv_lot_number_rec;
4797 END IF;
4798
4799 EXCEPTION
4800 WHEN OTHERS THEN
4801 get_rcv_lot_number_rec.lot_num := NULL;
4802 l_lot_control_code := 1;
4803 -- END; --commented for bug 7559682
4804
4805 --End If; --commented for bug 7559682
4806 END;
4807 -- End If; -- End Bug#3009495
4808
4809 query_res
4810 (p_supply_source_header_id => get_rcv_transaction_asn_rec.po_header_id
4811 ,p_supply_source_line_id => get_rcv_transaction_asn_rec.po_line_location_id
4812 ,p_supply_source_type_id => inv_reservation_global.g_source_type_po
4813 ,p_project_id => get_rcv_transaction_asn_rec.project_id
4814 ,p_task_id => get_rcv_transaction_asn_rec.task_id
4815 ,x_rsv_array => l_rsv_array
4816 ,x_record_count => l_record_count
4817 ,x_msg_count => x_msg_count
4818 ,x_msg_data => x_msg_data
4819 ,x_return_status => l_return_status);
4820
4821
4822 IF l_record_count > 0 THEN
4823 IF (get_rcv_transaction_asn_rec.primary_unit_of_measure <> l_rsv_array(1).primary_uom_code) THEN
4824
4825 l_primary_quantity := inv_convert.inv_um_convert
4826 (
4827 item_id => get_rcv_transaction_asn_rec.item_id,
4828 precision => NULL,
4829 from_quantity => get_rcv_transaction_asn_rec.primary_quantity,
4830 from_unit => get_rcv_transaction_asn_rec.primary_unit_of_measure,
4831 to_unit => l_rsv_array(1).primary_uom_code,
4832 from_name => NULL,
4833 to_name => NULL);
4834
4835 get_rcv_transaction_asn_rec.primary_quantity := l_primary_quantity;
4836
4837 END IF;
4838
4839 l_record_index := 1;
4840
4841 LOOP
4842
4843 EXIT WHEN get_rcv_transaction_asn_rec.primary_quantity = 0;
4844
4845 IF l_record_index <= l_record_count THEN
4846
4847 IF l_rsv_array(l_record_index).primary_reservation_quantity > get_rcv_transaction_asn_rec.primary_quantity THEN
4848 TRANSFER_RES
4849 (p_from_reservation_id => l_rsv_array(l_record_index).reservation_id
4850 , p_from_source_header_id => get_rcv_transaction_asn_rec.po_header_id
4851 ,p_from_source_line_id => get_rcv_transaction_asn_rec.po_line_location_id
4852 ,p_supply_source_type_id => inv_reservation_global.g_source_type_po
4853 ,p_to_supply_source_type_id => inv_reservation_global.g_source_type_inv
4854 ,p_subinventory_code => get_rcv_transaction_rec.subinventory
4855 ,p_locator_id => get_rcv_transaction_rec.locator_id
4856 ,p_lot_number => NVL(get_rcv_lot_number_rec.lot_num, NULL)
4857 ,p_revision => get_rcv_transaction_asn_rec.item_revision
4858 ,p_lpn_id => get_rcv_transaction_asn_rec.lpn_id
4859 ,p_primary_uom_code => get_rcv_transaction_asn_rec.primary_unit_of_measure
4860 ,p_primary_res_quantity => get_rcv_transaction_asn_rec.primary_quantity
4861 --,p_action => l_action it is never used. I remove it from procedure transfer_res
4862 ,x_msg_count => x_msg_count
4863 ,x_msg_data => x_msg_data
4864 ,x_return_status => l_return_status);
4865 get_rcv_transaction_asn_rec.primary_quantity := 0;
4866 ELSE
4867 TRANSFER_RES
4868 (p_from_reservation_id => l_rsv_array(l_record_index).reservation_id
4869 ,p_from_source_header_id => get_rcv_transaction_asn_rec.po_header_id
4870 ,p_from_source_line_id => get_rcv_transaction_asn_rec.po_line_location_id
4871 ,p_supply_source_type_id => inv_reservation_global.g_source_type_po
4872 ,p_to_supply_source_type_id => inv_reservation_global.g_source_type_inv
4873 ,p_subinventory_code => get_rcv_transaction_asn_rec.subinventory
4874 ,p_locator_id => get_rcv_transaction_asn_rec.locator_id
4875 ,p_lot_number => NVL(get_rcv_lot_number_rec.lot_num, NULL)
4876 ,p_revision => get_rcv_transaction_asn_rec.item_revision
4877 ,p_lpn_id => get_rcv_transaction_asn_rec.lpn_id
4878 ,p_primary_uom_code => get_rcv_transaction_asn_rec.primary_unit_of_measure
4879 ,p_primary_res_quantity => l_rsv_array(l_record_index).primary_reservation_quantity
4880 -- ,p_action IN VARCHAR2 DEFAULT NULL
4881 ,x_msg_count => x_msg_count
4882 ,x_msg_data => x_msg_data
4883 ,x_return_status => l_return_status);
4884 get_rcv_transaction_asn_rec.primary_quantity := get_rcv_transaction_asn_rec.primary_quantity
4885 - l_rsv_array(l_record_index).primary_reservation_quantity;
4886 END IF;
4887 ELSE
4888 -- raise error: since received more qty than reserved qty ??
4889 IF g_debug= C_Debug_Enabled THEN
4890 l_Fnd_Log_Message := 'l_record_index >
4891 l_record_count. more received than
4892 reserved. l_record_count :' ||
4893 l_record_count || ' l_record_index: '
4894 || l_record_index;
4895 mydebug(l_Fnd_Log_Message, c_api_name,9);
4896 END IF;
4897 EXIT;
4898 END IF; -- res_qty > received_qty
4899 l_record_index := l_record_index + 1;
4900
4901 END LOOP;
4902 ELSE -- l_record_count = 0
4903 -- there is no reservation existing
4904 -- log messeage
4905 IF g_debug= C_Debug_Enabled THEN
4906 l_Fnd_Log_Message := 'l_return_status:'||l_return_status;
4907 mydebug(l_Fnd_Log_Message, c_api_name,9);
4908 END IF;
4909 END IF; -- l_record_count > 0
4910 END IF; -- %FOUND
4911 CLOSE get_rcv_transaction_asn;
4912 END IF;
4913
4914 ELSIF get_source_doc_code_rec.source_document_code = 'REQ' THEN
4915 IF g_debug= C_Debug_Enabled THEN
4916 mydebug( 'DTI. Requisition.', c_api_name,9);
4917 END IF;
4918 OPEN get_rcv_txn_int_req(p_transaction_id);
4919 FETCH get_rcv_txn_int_req into get_rcv_txn_int_req_rec;
4920 --CLOSE get_rcv_txn_int_req;
4921
4922 IF get_rcv_txn_int_req%FOUND THEN
4923
4924 IF g_debug= C_Debug_Enabled THEN
4925 mydebug( 'Item revision' || get_rcv_txn_int_req_rec.item_revision, c_api_name,9);
4926 END IF;
4927 IF get_rcv_txn_int_req_rec.item_revision is NULL then
4928
4929 BEGIN
4930 SELECT max(mir.revision)
4931 INTO l_item_revision
4932 FROM mtl_system_items msi
4933 , mtl_item_revisions mir
4934 WHERE msi.inventory_item_id = get_rcv_txn_int_req_rec.item_id
4935 AND msi.organization_id = get_rcv_txn_int_req_rec.organization_id
4936 AND msi.revision_qty_control_code = 2
4937 AND mir.organization_id = msi.organization_id
4938 AND msi.inventory_item_id = msi.inventory_item_id
4939 AND mir.effectivity_date in
4940 (SELECT MAX(mir2.effectivity_date)
4941 FROM mtl_item_revisions mir2
4942 WHERE mir2.organization_id = get_rcv_txn_int_req_rec.organization_id
4943 AND mir2.inventory_item_id = get_rcv_txn_int_req_rec.item_id
4944 AND mir2.effectivity_date <= SYSDATE
4945 AND mir2.implementation_date is not NULL);
4946
4947
4948 get_rcv_txn_int_req_rec.item_revision := l_item_revision;
4949
4950 EXCEPTION when others then
4951 l_item_revision := NULL;
4952 END;
4953
4954 ELSE
4955 IF g_debug= C_Debug_Enabled THEN
4956 mydebug( 'Inside rev not null', c_api_name,9);
4957 mydebug( 'Item id :' || get_rcv_txn_int_req_rec.item_id, c_api_name,9);
4958 mydebug( 'Org :' || get_rcv_txn_int_req_rec.organization_id, c_api_name,9);
4959 END IF;
4960 /* Begin Bug 3688014 : If the rcv_shipment_lines contains a item revision
4961 for a non-revision controlled item, we should pass a NULL
4962 item revision to inventory so that supply gets updated accordingly.
4963 */
4964 --Bug 5147013: Changed the cursor name to get the
4965 -- item and org from the correct one.
4966 BEGIN
4967 SELECT msi.revision_qty_control_code
4968 INTO l_revision_control_code
4969 FROM mtl_system_items_b msi
4970 WHERE msi.inventory_item_id = get_rcv_txn_int_req_rec.item_id
4971 AND msi.organization_id = get_rcv_txn_int_req_rec.organization_id;
4972
4973 IF g_debug= C_Debug_Enabled THEN
4974 mydebug( 'rev control is: ' || l_revision_control_code, c_api_name,9);
4975 END IF;
4976 IF l_revision_control_code = 1 THEN
4977 get_rcv_txn_int_req_rec.item_revision := NULL;
4978 END IF;
4979
4980 EXCEPTION
4981 WHEN no_data_found THEN
4982 get_rcv_txn_int_req_rec.item_revision := NULL;
4983 WHEN OTHERS THEN
4984 get_rcv_txn_int_req_rec.item_revision := NULL;
4985 END;
4986
4987 /* End Bug 3688014 */
4988
4989 END IF; --get_rcv_txn_req_rec.item_revision is NULL
4990
4991
4992 --Bug#3009495.If item is lot controlled then we will derive the lot number
4993 --from the rcv_lot_transactions.
4994 get_rcv_lot_number_rec.lot_num := NULL;
4995 --IF get_shipment_lines%FOUND THEN
4996
4997 --Bug 7559682 Error performing deliver transaction for Direct Items in EAM workorder
4998 --having destination type as shop floor. Modified the code block to include MSI query
4999 BEGIN
5000 select nvl(lot_control_code,1)
5001 into l_lot_control_code
5002 from mtl_system_items
5003 where organization_id = get_rcv_transaction_rec.to_organization_id
5004 and inventory_item_id = get_rcv_transaction_rec.item_id ;
5005
5006 IF (l_lot_control_code = 2) THEN
5007 --Begin --commented for bug 7559682
5008 -- 5611560 New cursor is opened and fetched.
5009 OPEN get_rcv_txn_lot_number(get_rcv_transaction_rec.shipment_line_id,p_transaction_id);
5010 FETCH get_rcv_txn_lot_number INTO get_rcv_lot_number_rec;
5011 END IF;
5012
5013 EXCEPTION
5014 WHEN OTHERS THEN
5015 get_rcv_lot_number_rec.lot_num := NULL;
5016 l_lot_control_code := 1;
5017 -- END; --commented for bug 7559682
5018
5019 --End If; --commented for bug 7559682
5020 END;
5021 -- End If; -- End Bug#3009495
5022
5023 query_res
5024 (p_supply_source_header_id => get_rcv_txn_int_req_rec.requisition_header_id
5025 ,p_supply_source_line_id => get_rcv_txn_int_req_rec.requisition_line_id
5026 ,p_supply_source_type_id => inv_reservation_global.g_source_type_internal_req
5027 ,p_project_id => get_rcv_txn_int_req_rec.project_id
5028 ,p_task_id => get_rcv_txn_int_req_rec.task_id
5029 ,x_rsv_array => l_rsv_array
5030 ,x_record_count => l_record_count
5031 ,x_msg_count => x_msg_count
5032 ,x_msg_data => x_msg_data
5033 ,x_return_status => l_return_status);
5034
5035 IF l_record_count > 0 THEN
5036 IF (get_rcv_txn_int_req_rec.primary_unit_of_measure <> l_rsv_array(1).primary_uom_code) THEN
5037
5038 l_primary_quantity := inv_convert.inv_um_convert
5039 (
5040 item_id => get_rcv_txn_int_req_rec.item_id,
5041 precision => NULL,
5042 from_quantity => get_rcv_txn_int_req_rec.primary_quantity,
5043 from_unit => get_rcv_txn_int_req_rec.primary_unit_of_measure,
5044 to_unit => l_rsv_array(1).primary_uom_code,
5045 from_name => NULL,
5046 to_name => NULL);
5047
5048 get_rcv_txn_int_req_rec.primary_quantity := l_primary_quantity;
5049
5050 END IF;
5051
5052 l_record_index := 1;
5053
5054 LOOP
5055
5056 EXIT WHEN get_rcv_txn_int_req_rec.primary_quantity = 0;
5057
5058 IF l_record_index <= l_record_count THEN
5059
5060 IF l_rsv_array(l_record_index).primary_reservation_quantity > get_rcv_txn_int_req_rec.primary_quantity THEN
5061 TRANSFER_RES
5062 (p_from_reservation_id => l_rsv_array(l_record_index).reservation_id
5063 ,p_from_source_header_id => get_rcv_txn_int_req_rec.requisition_header_id
5064 ,p_from_source_line_id => get_rcv_txn_int_req_rec.requisition_line_id
5065 ,p_supply_source_type_id => inv_reservation_global.g_source_type_internal_req
5066 ,p_to_supply_source_type_id => inv_reservation_global.g_source_type_inv
5067 ,p_subinventory_code => get_rcv_txn_int_req_rec.subinventory
5068 ,p_locator_id => get_rcv_txn_int_req_rec.locator_id
5069 ,p_lot_number => NVL(get_rcv_lot_number_rec.lot_num, NULL)
5070 ,p_revision => get_rcv_txn_int_req_rec.item_revision
5071 ,p_lpn_id => get_rcv_txn_int_req_rec.lpn_id
5072 ,p_primary_uom_code => get_rcv_txn_int_req_rec.primary_unit_of_measure
5073 ,p_primary_res_quantity => get_rcv_txn_int_req_rec.primary_quantity
5074 --,p_action => l_action it is never used. I remove it from procedure transfer_res
5075 ,x_msg_count => x_msg_count
5076 ,x_msg_data => x_msg_data
5077 ,x_return_status => l_return_status);
5078 get_rcv_txn_int_req_rec.primary_quantity := 0;
5079 ELSE
5080 TRANSFER_RES
5081 (p_from_reservation_id => l_rsv_array(l_record_index).reservation_id
5082 ,p_from_source_header_id => get_rcv_txn_int_req_rec.requisition_header_id
5083 ,p_from_source_line_id => get_rcv_txn_int_req_rec.requisition_line_id
5084 ,p_supply_source_type_id => inv_reservation_global.g_source_type_internal_req
5085 ,p_to_supply_source_type_id => inv_reservation_global.g_source_type_inv
5086 ,p_subinventory_code => get_rcv_txn_int_req_rec.subinventory
5087 ,p_locator_id => get_rcv_txn_int_req_rec.locator_id
5088 ,p_lot_number => NVL(get_rcv_lot_number_rec.lot_num, NULL)
5089 ,p_revision => get_rcv_txn_int_req_rec.item_revision
5090 ,p_lpn_id => get_rcv_txn_int_req_rec.lpn_id
5091 ,p_primary_uom_code => get_rcv_txn_int_req_rec.primary_unit_of_measure
5092 ,p_primary_res_quantity => l_rsv_array(l_record_index).primary_reservation_quantity
5093 -- ,p_action IN VARCHAR2 DEFAULT NULL
5094 ,x_msg_count => x_msg_count
5095 ,x_msg_data => x_msg_data
5096 ,x_return_status => l_return_status);
5097 get_rcv_txn_int_req_rec.primary_quantity := get_rcv_txn_int_req_rec.primary_quantity
5098 - l_rsv_array(l_record_index).primary_reservation_quantity;
5099 END IF;
5100 ELSE
5101 -- raise error: since received more qty than reserved qty ??
5102 IF g_debug= C_Debug_Enabled THEN
5103 l_Fnd_Log_Message := 'l_record_index >
5104 l_record_count. more received than
5105 reserved. l_record_count :' ||
5106 l_record_count || ' l_record_index: '
5107 || l_record_index;
5108 mydebug(l_Fnd_Log_Message, c_api_name,9);
5109 END IF;
5110 EXIT;
5111 END IF; -- res_qty > received_qty
5112 l_record_index := l_record_index + 1;
5113
5114 END LOOP;
5115 ELSE -- l_record_count = 0
5116 -- there is no reservation existing
5117 -- log messeage
5118 IF g_debug= C_Debug_Enabled THEN
5119 l_Fnd_Log_Message := 'l_return_status:'||l_return_status;
5120 mydebug(l_Fnd_Log_Message, c_api_name,9);
5121 END IF;
5122 END IF; -- l_record_count > 0
5123 END IF; -- %FOUND
5124 CLOSE get_rcv_txn_int_req;
5125 ELSE
5126 -- do nothing. DO not support reservations for In-transit shipments in inventory orgs
5127 -- log message
5128 IF g_debug= C_Debug_Enabled THEN
5129 mydebug( 'Other source type. Do not support: ' || get_source_doc_code_rec.source_document_code, c_api_name,9);
5130 END IF;
5131 NULL;
5132 END IF; -- if supply_type = 'PO'
5133
5134 END IF; -- if wms org
5135
5136
5137 -- 5611560
5138 IF get_rcv_txn_lot_number%ISOPEN THEN
5139 CLOSE get_rcv_txn_lot_number;
5140 END IF;
5141
5142 IF get_rcv_lot_number%ISOPEN THEN
5143 CLOSE get_rcv_lot_number;
5144 END IF;
5145
5146 IF get_rcv_transaction%ISOPEN THEN
5147 CLOSE get_rcv_transaction;
5148 END IF;
5149
5150 IF get_source_doc_code%isopen THEN
5151 CLOSE get_source_doc_code;
5152 END IF;
5153
5154 ELSIF upper(p_action) = 'APPROVE_BLANKET_RELEASE_SUPPLY' THEN
5155 IF g_debug= C_Debug_Enabled THEN
5156 mydebug( 'Approve Blanket Release Supply.', c_api_name,9);
5157 END IF;
5158
5159 OPEN get_po_shipment_for_release(p_header_id);
5160 LOOP
5161 FETCH get_po_shipment_for_release INTO get_po_shipment_rel_rec;
5162 EXIT WHEN get_po_shipment_for_release%NOTFOUND;
5163
5164 IF g_debug= C_Debug_Enabled THEN
5165 mydebug( 'get_po_shipment_rel_rec.line_location_id: '||get_po_shipment_rel_rec.line_location_id, c_api_name,9);
5166 END IF;
5167
5168 IF NOT EXISTS_RESERVATION(p_supply_source_line_id => get_po_shipment_rel_rec.line_location_id) THEN
5169
5170 IF g_debug= C_Debug_Enabled THEN
5171 mydebug( 'No reservations exist for blanket release', c_api_name,9);
5172 END IF;
5173
5174 OPEN get_req_line_of_po_shipment(get_po_shipment_rel_rec.line_location_id);
5175 LOOP
5176 FETCH get_req_line_of_po_shipment INTO get_req_line_po_shipment_rec;
5177 EXIT WHEN get_req_line_of_po_shipment%NOTFOUND;
5178
5179 IF g_debug= C_Debug_Enabled THEN
5180 l_Fnd_Log_Message := 'Before get_req_line_po_shipment_rec.project_id: '||get_req_line_po_shipment_rec.project_id;
5181 mydebug(l_Fnd_Log_Message, c_api_name,9);
5182 l_Fnd_Log_Message := 'before get_req_line_po_shipment_rec.task_id: '||get_req_line_po_shipment_rec.task_id;
5183 mydebug(l_Fnd_Log_Message, c_api_name,9);
5184 END IF;
5185
5186 IF (get_req_line_po_shipment_rec.project_id = -99) THEN
5187 get_req_line_po_shipment_rec.project_id := NULL;
5188 END IF;
5189 IF (get_req_line_po_shipment_rec.task_id = -99) THEN
5190 get_req_line_po_shipment_rec.task_id := NULL;
5191 END IF;
5192
5193 IF g_debug= C_Debug_Enabled THEN
5194 l_Fnd_Log_Message := 'after get_req_line_po_shipment_rec.project_id: '||get_req_line_po_shipment_rec.project_id;
5195 mydebug(l_Fnd_Log_Message, c_api_name,9);
5196 l_Fnd_Log_Message := 'after get_req_line_po_shipment_rec.task_id: '||get_req_line_po_shipment_rec.task_id;
5197 mydebug(l_Fnd_Log_Message, c_api_name,9);
5198 END IF;
5199
5200 -- IF (get_req_line_po_shipment_rec.project_id IS NOT NULL
5201 -- OR
5202 -- get_req_line_po_shipment_rec.task_id IS NOT NULL) THEN
5203
5204 IF g_debug= C_Debug_Enabled THEN
5205 l_Fnd_Log_Message := 'get_req_line_po_shipment_rec.project_id or task_id is not null. Calling availibitly API';
5206 mydebug(l_Fnd_Log_Message, c_api_name,9);
5207 END IF;
5208
5209 INV_RESERVATION_AVAIL_PVT.available_supply_to_reserve
5210 (
5211 x_return_status =>l_return_status
5212 , x_msg_count =>x_msg_count
5213 , x_msg_data =>x_msg_data
5214 , p_organization_id =>get_po_shipment_rel_rec.ship_to_organization_id
5215 , p_item_id =>get_po_shipment_rel_rec.item_id
5216 , p_supply_source_type_id =>inv_reservation_global.g_source_type_po
5217 , p_supply_source_header_id =>get_po_shipment_rel_rec.po_header_id
5218 , p_supply_source_line_id =>get_po_shipment_rel_rec.line_location_id
5219 , p_project_id =>get_req_line_po_shipment_rec.project_id
5220 , p_task_id =>get_req_line_po_shipment_rec.task_id
5221 , x_qty_available_to_reserve =>l_qty_avail_to_reserve
5222 , x_qty_available =>l_qty_avail
5223 );
5224
5225 IF g_debug= C_Debug_Enabled THEN
5226 l_Fnd_Log_Message := 'l_qty_avail_to_reserve: '|| l_qty_avail_to_reserve;
5227 mydebug(l_Fnd_Log_Message, c_api_name,9);
5228 l_Fnd_Log_Message := 'l_qty_avail: '|| l_qty_avail;
5229 mydebug(l_Fnd_Log_Message, c_api_name,9);
5230 END IF;
5231
5232 get_req_line_res
5233 ( p_req_line_id =>get_req_line_po_shipment_rec.req_line_id
5234 ,p_project_id =>get_req_line_po_shipment_rec.project_id
5235 ,p_task_id =>get_req_line_po_shipment_rec.task_id
5236 ,x_res_array =>l_rsv_array
5237 ,x_record_count =>l_record_count);
5238
5239 IF g_debug= C_Debug_Enabled THEN
5240 l_Fnd_Log_Message := 'l_record_count: '|| l_record_count;
5241 mydebug(l_Fnd_Log_Message, c_api_name,9);
5242 END IF;
5243
5244 IF l_record_count > 0 THEN
5245 l_rsv_rec := l_rsv_array(1);
5246 /*
5247 uom_conversion(l_rsv_rec.reservation_uom_code
5248 ,l_rsv_rec.primary_uom_code
5249 ,get_req_line_po_shipment_rec.quantity_ordered
5250 ,get_po_shipment_rel_rec.po_line_id
5251 ,l_reservation_quantity
5252 ,l_po_primary_qty); */
5253
5254 IF (l_rsv_rec.primary_reservation_quantity > l_qty_avail_to_reserve) THEN
5255 update_res
5256 (p_supply_source_header_id => l_rsv_rec.supply_source_header_id
5257 ,p_supply_source_line_id => l_rsv_rec.supply_source_line_id
5258 ,p_supply_source_type_id => inv_reservation_global.g_source_type_req
5259 ,p_primary_reservation_quantity => l_qty_avail_to_reserve
5260 ,p_project_id => get_req_line_po_shipment_rec.project_id
5261 ,p_task_id => get_req_line_po_shipment_rec.task_id
5262 ,p_reservation_id => l_rsv_rec.reservation_id
5263 ,x_msg_count => x_msg_count
5264 ,x_msg_data => x_msg_data
5265 ,x_return_status => l_return_status);
5266 END IF;
5267
5268 --BUG#3497445.The l_po_primary_qty calculated from the UOM_conversion call is used below.
5269
5270 l_primary_res_quantity := least(l_rsv_rec.primary_reservation_quantity, l_qty_avail_to_reserve);
5271
5272 IF g_debug= C_Debug_Enabled THEN
5273 l_Fnd_Log_Message := 'l_primary_res_quantity: '|| l_primary_res_quantity;
5274 mydebug(l_Fnd_Log_Message, c_api_name,9);
5275 END IF;
5276
5277 IF g_debug= C_Debug_Enabled THEN
5278 l_Fnd_Log_Message := 'calling transfer reservation for, From req line id: '||l_rsv_rec.supply_source_line_id || ' to po shipment line id: ' || get_po_shipment_rel_rec.line_location_id;
5279 mydebug(l_Fnd_Log_Message, c_api_name,9);
5280 END IF;
5281
5282 TRANSFER_RES
5283 (p_from_reservation_id =>l_rsv_rec.reservation_id
5284 ,p_from_source_header_id =>l_rsv_rec.supply_source_header_id
5285 ,p_from_source_line_id =>l_rsv_rec.supply_source_line_id
5286 ,p_supply_source_type_id =>inv_reservation_global.g_source_type_req
5287 ,p_to_source_header_id =>get_po_shipment_rel_rec.po_header_id
5288 ,p_to_source_line_id =>get_po_shipment_rel_rec.line_location_id
5289 ,p_to_supply_source_type_id =>inv_reservation_global.g_source_type_po
5290 ,p_primary_uom_code =>l_rsv_rec.primary_uom_code
5291 ,p_primary_res_quantity =>l_primary_res_quantity
5292 ,x_msg_count =>x_msg_count
5293 ,x_msg_data =>x_msg_data
5294 ,x_return_status =>l_return_status);
5295 IF g_debug= C_Debug_Enabled THEN
5296 l_Fnd_Log_Message := 'after calling transfer_res. The l_return_status : '||l_return_status;
5297 mydebug(l_Fnd_Log_Message, c_api_name,9);
5298 END IF;
5299
5300 ELSE -- if did not have any req reservation existing
5301 IF g_debug= C_Debug_Enabled THEN
5302 FND_MESSAGE.SET_NAME('INV','INV_API_NO_RSV_EXIST');
5303 FND_MSG_PUB.Add;
5304 l_Fnd_Log_Message := 'l_record_count < 0';
5305 mydebug(l_Fnd_Log_Message, c_api_name,9);
5306 END IF;
5307 END IF; -- record_count
5308 END LOOP;
5309 CLOSE get_req_line_of_po_shipment;
5310
5311 ELSE
5312 -- Reservation exists for Blanket PO - update reservation if quantity
5313 -- is decreased on the PO
5314 -- get the existing reservation quantity and compare it with the quantity on the PO
5315 --
5316 IF g_debug= C_Debug_Enabled THEN
5317 l_Fnd_Log_Message := 'Reservation existing for Blanket release ';
5318 mydebug(l_Fnd_Log_Message, c_api_name,9);
5319 END IF;
5320
5321 OPEN get_pt_count_po_shipment(get_po_shipment_rel_rec.line_location_id);
5322 FETCH get_pt_count_po_shipment INTO get_pt_count_po_shipment_rec;
5323 CLOSE get_pt_count_po_shipment;
5324
5325 IF g_debug= C_Debug_Enabled THEN
5326 l_Fnd_Log_Message := ' get_pt_count_po_shipment_rec.count : '||get_pt_count_po_shipment_rec.count;
5327 mydebug(l_Fnd_Log_Message, c_api_name,9);
5328 END IF;
5329
5330 IF get_pt_count_po_shipment_rec.count > 1 THEN -- multiple project/task
5331
5332 IF g_debug= C_Debug_Enabled THEN
5333 l_Fnd_Log_Message := 'Multiple project/task... ';
5334 l_Fnd_Log_Message := 'get_po_shipment_rel_rec.ship_to_org_id:'||get_po_shipment_rec.ship_to_organization_id;
5335 mydebug(l_Fnd_Log_Message, c_api_name,9);
5336 END IF;
5337
5338 IF (inv_install.adv_inv_installed(get_po_shipment_rel_rec.ship_to_organization_id)) THEN
5339 -- is wms org
5340 -- delete all the reservations for this shipment
5341 -- log message
5342 -- Commenting out the delete reservation call. Call
5343 -- reduce reservations instead
5344 -- DELETE_RES
5345 -- (p_supply_source_header_id => get_po_shipment_rel_rec.po_header_id
5346 -- ,p_supply_source_line_id => get_po_shipment_rel_rec.line_location_id
5347 --,p_supply_source_type_id => inv_reservation_global.g_source_type_po
5348 -- ,x_msg_count => x_msg_count
5349 -- ,x_msg_data => x_msg_data
5350 -- ,x_return_status => l_return_status);
5351 -- Call reduce reservations instead of delete
5352 -- reservations
5353 -- Call the reduce reservations API by setting the
5354 -- delete_flag to yes. delete all reservations for that
5355 -- supply line.
5356 -- calling reduce_reservation API
5357 l_delete_flag := 'Y';
5358 l_sort_by_criteria := inv_reservation_global.g_query_demand_ship_date_desc;
5359 l_mtl_maint_rsv_rec.action := 0;--supply is reduced
5360 l_mtl_maint_rsv_rec.organization_id :=
5361 get_po_shipment_rel_rec.ship_to_organization_id;
5362 l_mtl_maint_rsv_rec.inventory_item_id :=
5363 get_po_shipment_rel_rec.item_id;
5364 l_mtl_maint_rsv_rec.supply_source_type_id:= inv_reservation_global.g_source_type_po;
5365 l_mtl_maint_rsv_rec.supply_source_header_id := get_po_shipment_rel_rec.po_header_id;
5366 l_mtl_maint_rsv_rec.supply_source_line_id :=
5367 get_po_shipment_rel_rec.line_location_id;
5368 -- l_mtl_maint_rsv_rec.supply_source_line_detail := NULL;
5369
5370 reduce_reservation
5371 (
5372 p_api_version_number => 1.0
5373 , p_init_msg_lst => fnd_api.g_false
5374 , x_return_status => l_return_status
5375 , x_msg_count => x_msg_count
5376 , x_msg_data => x_msg_data
5377 , p_mtl_maintain_rsv_rec => l_mtl_maint_rsv_rec
5378 , p_delete_flag => l_delete_flag
5379 , p_sort_by_criteria => l_sort_by_criteria
5380 , x_quantity_modified => l_quantity_modified);
5381 IF g_debug= C_Debug_Enabled THEN
5382 mydebug ('Return Status after calling reduce reservations: '|| l_return_status, c_api_name,9);
5383 END IF;
5384
5385 IF l_return_status = fnd_api.g_ret_sts_error THEN
5386
5387 IF g_debug= C_Debug_Enabled THEN
5388 mydebug('Raising expected error'||l_return_status, c_api_name,9);
5389 END IF;
5390 RAISE fnd_api.g_exc_error;
5391
5392 ELSIF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
5393
5394 IF g_debug= C_Debug_Enabled THEN
5395 mydebug('Rasing Unexpected error'||l_return_status, c_api_name,9);
5396 END IF;
5397 RAISE fnd_api.g_exc_unexpected_error;
5398
5399 END IF;
5400 END IF;
5401 END IF;
5402 -- ELSE -- inv org
5403 -- working through each project and task
5404 OPEN get_proj_task_of_po_shipment(get_po_shipment_rel_rec.line_location_id);
5405 LOOP
5406 FETCH get_proj_task_of_po_shipment INTO
5407 get_pt_po_shipment_rec;
5408
5409 EXIT WHEN get_proj_task_of_po_shipment%NOTFOUND;
5410
5411 IF g_debug= C_Debug_Enabled THEN
5412 mydebug('Inside project/task loop', c_api_name,9);
5413 END IF;
5414 IF g_debug= C_Debug_Enabled THEN
5415 mydebug('Project Id: '|| get_pt_po_shipment_rec.project_id, c_api_name,9);
5416 mydebug('Task Id: '|| get_pt_po_shipment_rec.task_id, c_api_name,9);
5417 END IF;
5418
5419 IF (get_pt_po_shipment_rec.project_id = -99) THEN
5420 get_pt_po_shipment_rec.project_id := NULL;
5421 END IF;
5422 IF (get_pt_po_shipment_rec.task_id = -99) THEN
5423 get_pt_po_shipment_rec.task_id := NULL;
5424 END IF;
5425
5426 INV_RESERVATION_AVAIL_PVT.available_supply_to_reserve
5427 (
5428 x_return_status => l_return_status --OUT NOCOPY VARCHAR2
5429 , x_msg_count => x_msg_count --OUT NOCOPY NUMBER
5430 , x_msg_data => x_msg_data --OUT NOCOPY VARCHAR2
5431 , p_organization_id => get_po_shipment_rel_rec.ship_to_organization_id--IN NUMBER default null
5432 , p_item_id => get_po_shipment_rel_rec.item_id--IN NUMBER default null
5433 , p_supply_source_type_id => inv_reservation_global.g_source_type_po --IN NUMBER
5434 , p_supply_source_header_id => get_po_shipment_rel_rec.po_header_id --IN NUMBER ?? how do we query for blank PO
5435 , p_supply_source_line_id => get_po_shipment_rel_rec.line_location_id --IN NUMBER
5436 , p_project_id => get_pt_po_shipment_rec.project_id--IN NUMBER default null
5437 , p_task_id => get_pt_po_shipment_rec.task_id --IN NUMBER default null
5438 , x_qty_available_to_reserve => l_qty_avail_to_reserve --OUT NOCOPY NUMBER
5439 , x_qty_available => l_qty_avail --OUT NOCOPY NUMBER
5440 );
5441
5442 OPEN get_po_res_qty
5443 (get_po_shipment_rel_rec.po_header_id
5444 ,get_po_shipment_rel_rec.line_location_id
5445 ,get_pt_po_shipment_rec.project_id
5446 ,get_pt_po_shipment_rec.task_id);
5447 FETCH get_po_res_qty INTO get_po_res_qty_rec ;
5448 CLOSE get_po_res_qty ;
5449
5450 IF g_debug= C_Debug_Enabled THEN
5451 mydebug('Qty available: '|| l_qty_avail, c_api_name,9);
5452 mydebug('Qty available to reserve: '|| l_qty_avail_to_reserve, c_api_name,9);
5453 mydebug('Qty reserved qty: '|| get_po_res_qty_rec.primary_reservation_quantity, c_api_name,9);
5454 END IF;
5455
5456 IF get_po_res_qty_rec.primary_reservation_quantity > 0 THEN
5457 /* uom_conversion(get_po_res_qty_rec.reservation_uom_code
5458 ,get_po_res_qty_rec.primary_uom_code
5459 ,l_qty_avail_to_reserve
5460 ,get_po_shipment_rel_rec.po_line_id
5461 ,l_reservation_quantity
5462 ,l_po_primary_qty);*/
5463 IF (get_po_res_qty_rec.primary_reservation_quantity > l_qty_avail) THEN
5464 -- calling reduce_reservation API get_pt_po_shipment_rec
5465 l_mtl_maint_rsv_rec.action := 0;--supply is reduced
5466 l_sort_by_criteria := inv_reservation_global.g_query_demand_ship_date_desc;
5467 l_mtl_maint_rsv_rec.organization_id
5468 := get_po_shipment_rel_rec.ship_to_organization_id;
5469 l_mtl_maint_rsv_rec.inventory_item_id := get_po_shipment_rel_rec.item_id;
5470
5471 l_mtl_maint_rsv_rec.supply_source_type_id:= inv_reservation_global.g_source_type_po;
5472 l_mtl_maint_rsv_rec.supply_source_header_id := get_po_shipment_rel_rec.po_header_id;
5473 l_mtl_maint_rsv_rec.supply_source_line_id := get_po_shipment_rel_rec.line_location_id;
5474 -- l_mtl_maint_rsv_rec.supply_source_line_detail := NULL;
5475 --l_mtl_maint_rsv_rec.expected_quantity :=
5476 -- get_po_res_qty_rec.primary_reservation_quantity - l_qty_avail_to_reserve;
5477 l_mtl_maint_rsv_rec.expected_quantity := l_qty_avail;
5478 l_mtl_maint_rsv_rec.expected_quantity_uom := get_po_res_qty_rec.primary_uom_code;
5479 l_mtl_maint_rsv_rec.project_id := get_pt_po_shipment_rec.project_id;
5480 l_mtl_maint_rsv_rec.task_id := get_pt_po_shipment_rec.task_id;
5481
5482 reduce_reservation
5483 (
5484 p_API_Version_Number => 1.0
5485 , p_Init_Msg_Lst => fnd_api.g_false
5486 , x_Return_Status => l_return_status
5487 , x_Msg_Count => x_msg_count
5488 , x_Msg_Data => x_msg_data
5489 , p_Mtl_Maintain_Rsv_rec=> l_mtl_maint_rsv_rec
5490 , p_Delete_Flag => 'N'
5491 , p_Sort_By_Criteria => NULL
5492 , x_Quantity_Modified => l_quantity_modified);
5493
5494 IF g_debug= C_Debug_Enabled THEN
5495 mydebug ('Return Status after calling reduce reservations: '|| l_return_status, c_api_name,9);
5496 END IF;
5497
5498 IF l_return_status = fnd_api.g_ret_sts_error THEN
5499
5500 IF g_debug= C_Debug_Enabled THEN
5501 mydebug('Raising expected error'||l_return_status, c_api_name,9);
5502 END IF;
5503 RAISE fnd_api.g_exc_error;
5504
5505 ELSIF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
5506
5507 IF g_debug= C_Debug_Enabled THEN
5508 mydebug('Rasing Unexpected error'||l_return_status, c_api_name,9);
5509 END IF;
5510 RAISE fnd_api.g_exc_unexpected_error;
5511
5512 END IF;
5513
5514 END IF;
5515 END IF;
5516
5517 END LOOP;
5518 CLOSE get_proj_task_of_po_shipment;
5519 END IF;
5520 END LOOP;
5521 CLOSE get_po_shipment_for_release;
5522
5523 ELSIF upper(p_action) = 'REMOVE_REQ_SUPPLY' THEN
5524 OPEN get_req_hdr_lines (p_header_id);
5525 --
5526 IF g_debug= C_Debug_Enabled THEN
5527 mydebug ('Remove req supply. req header:'|| p_header_id ,c_api_name,9);
5528 END IF;
5529 LOOP
5530 --
5531 FETCH get_req_hdr_lines INTO get_req_hdr_lines_rec;
5532 EXIT WHEN get_req_hdr_lines%NOTFOUND;
5533
5534 IF g_debug= C_Debug_Enabled THEN
5535 mydebug ('Removing req supply for req line :'|| get_req_hdr_lines_rec.requisition_line_id , c_api_name,9);
5536 END IF;
5537
5538 IF Upper(get_req_hdr_lines_rec.source_type_code) = 'INVENTORY' THEN
5539 l_supply_source_type_id := inv_reservation_global.g_source_type_internal_req;
5540 else
5541 l_supply_source_type_id := inv_reservation_global.g_source_type_req;
5542 END IF;
5543
5544 IF EXISTS_RESERVATION(p_supply_source_header_id => p_header_id,
5545 p_supply_source_line_id => get_req_hdr_lines_rec.requisition_line_id,
5546 p_supply_source_type_id => l_supply_source_type_id) THEN
5547 DELETE_RES
5548 (p_supply_source_header_id => p_header_id
5549 ,p_supply_source_line_id => get_req_hdr_lines_rec.requisition_line_id
5550 ,p_supply_source_type_id => l_supply_source_type_id
5551 ,x_msg_count => x_msg_count
5552 ,x_msg_data => x_msg_data
5553 ,x_return_status => l_return_status);
5554 END IF;
5555 END LOOP; --get_req_hdr_lines
5556
5557 ELSIF upper(p_action) = 'REMOVE_REQ_LINE_SUPPLY' THEN
5558 --delete the reservation on the req
5559 --
5560 IF g_debug= C_Debug_Enabled THEN
5561 mydebug ('Remove req line supply. req line:'|| p_line_id ,c_api_name,9);
5562 END IF;
5563
5564 BEGIN
5565 SELECT source_type_code INTO l_source_type_code FROM
5566 po_requisition_lines_all WHERE requisition_line_id = p_line_id;
5567
5568 EXCEPTION
5569 WHEN no_data_found THEN
5570 IF g_debug= C_Debug_Enabled THEN
5571 mydebug ('Cannot find the source type code for req line' || p_line_id,c_api_name,9);
5572 END IF;
5573 END;
5574
5575
5576 IF Upper(l_source_type_code) = 'INVENTORY' THEN
5577 l_supply_source_type_id := inv_reservation_global.g_source_type_internal_req;
5578 else
5579 l_supply_source_type_id := inv_reservation_global.g_source_type_req;
5580 END IF;
5581
5582 IF EXISTS_RESERVATION(p_supply_source_line_id => p_line_id,
5583 p_supply_source_type_id => l_supply_source_type_id) THEN
5584 DELETE_RES
5585 (p_supply_source_line_id => p_line_id
5586 ,p_supply_source_type_id => l_supply_source_type_id
5587 ,x_msg_count => x_msg_count
5588 ,x_msg_data => x_msg_data
5589 ,x_return_status => l_return_status);
5590 END IF;
5591
5592 ELSIF upper(p_action) = 'CANCEL_PO_SUPPLY' THEN
5593
5594 -- If Reservation Exists, then delete them and never transfer back to requistion
5595 -- since when PO is cancelled, associated req got
5596 -- cancelled too.
5597 IF g_debug= C_Debug_Enabled THEN
5598 mydebug ('Cancel PO supply. Supply header: '|| p_header_id ,c_api_name,9);
5599 END IF;
5600 IF EXISTS_RESERVATION(p_supply_source_header_id => p_header_id) THEN
5601
5602 --reservation should be deleted
5603 OPEN get_po_shipment(p_header_id);
5604 LOOP
5605
5606 FETCH get_po_shipment INTO get_po_shipment_rec;
5607 EXIT WHEN get_po_shipment%NOTFOUND;
5608
5609 --DELETE_RES (p_supply_source_header_id => p_header_id
5610 -- ,p_supply_source_line_id => get_po_shipment_rec.line_location_id
5611 -- ,p_supply_source_type_id => inv_reservation_global.g_source_type_po
5612 -- ,x_msg_count => x_msg_count
5613 -- ,x_msg_data => x_msg_data
5614 -- ,x_return_status => l_return_status);
5615 IF g_debug= C_Debug_Enabled THEN
5616 mydebug ('Removing po line location. po line loc.:'|| get_po_shipment_rec.line_location_id,c_api_name,9);
5617 END IF;
5618 l_delete_flag := 'Y';
5619 l_sort_by_criteria := inv_reservation_global.g_query_demand_ship_date_desc;
5620 l_mtl_maint_rsv_rec.action := 0;--supply is reduced
5621 l_mtl_maint_rsv_rec.organization_id :=
5622 get_po_shipment_rec.ship_to_organization_id;
5623 l_mtl_maint_rsv_rec.inventory_item_id :=
5624 get_po_shipment_rec.item_id;
5625 l_mtl_maint_rsv_rec.supply_source_type_id:= inv_reservation_global.g_source_type_po;
5626 l_mtl_maint_rsv_rec.supply_source_header_id := p_header_id;
5627 l_mtl_maint_rsv_rec.supply_source_line_id :=
5628 get_po_shipment_rec.line_location_id;
5629 -- l_mtl_maint_rsv_rec.supply_source_line_detail := NULL;
5630
5631 reduce_reservation
5632 (
5633 p_api_version_number => 1.0
5634 , p_init_msg_lst => fnd_api.g_false
5635 , x_return_status => l_return_status
5636 , x_msg_count => x_msg_count
5637 , x_msg_data => x_msg_data
5638 , p_mtl_maintain_rsv_rec => l_mtl_maint_rsv_rec
5639 , p_delete_flag => l_delete_flag
5640 , p_sort_by_criteria => l_sort_by_criteria
5641 , x_quantity_modified => l_quantity_modified);
5642 IF g_debug= C_Debug_Enabled THEN
5643 mydebug ('Return Status after calling reduce reservations: '|| l_return_status, c_api_name,9);
5644 END IF;
5645
5646 IF l_return_status = fnd_api.g_ret_sts_error THEN
5647
5648 IF g_debug= C_Debug_Enabled THEN
5649 mydebug('Raising expected error'||l_return_status, c_api_name,9);
5650 END IF;
5651 RAISE fnd_api.g_exc_error;
5652
5653 ELSIF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
5654
5655 IF g_debug= C_Debug_Enabled THEN
5656 mydebug('Rasing Unexpected error'||l_return_status, c_api_name,9);
5657 END IF;
5658 RAISE fnd_api.g_exc_unexpected_error;
5659
5660 END IF;
5661 END LOOP; --get_distr
5662
5663 END IF; --Reservation Exists
5664
5665 ELSIF upper(p_action) = 'CANCEL_PO_LINE' THEN
5666 OPEN get_po_header_id_line (p_line_id);
5667 FETCH get_po_header_id_line INTO l_po_header_id;
5668 CLOSE get_po_header_id_line;
5669
5670 IF g_debug= C_Debug_Enabled THEN
5671 mydebug ('Cancel PO line. PO line.: '|| p_line_id,c_api_name,9);
5672 END IF;
5673 -- If Reservation Exists for the PO, then proceed to check whether
5674 -- the existing Reservation needs to be transferred to Requisition
5675 -- Since Reservation is on the PO and PO Distribution, PO Reservation is
5676 -- checked even when the Line is Cancelled
5677 IF EXISTS_RESERVATION(p_supply_source_header_id => l_po_header_id) THEN
5678
5679 --delete the reservation
5680 OPEN get_line_loc_for_po_line(p_line_id);
5681 LOOP
5682 FETCH get_line_loc_for_po_line INTO get_line_loc_rec;
5683 EXIT WHEN get_line_loc_for_po_line%NOTFOUND;
5684
5685 -- DELETE_RES (p_supply_source_header_id => l_po_header_id
5686 -- ,p_supply_source_line_id => get_distr_rec.line_location_id
5687 -- ,p_supply_source_type_id => inv_reservation_global.g_source_type_po
5688 -- ,x_msg_count => x_msg_count
5689 -- ,x_msg_data => x_msg_data
5690 -- ,x_return_status => l_return_status);
5691 IF g_debug= C_Debug_Enabled THEN
5692 mydebug ('Cancel line.Removing po line location. po line loc.:'|| get_line_loc_rec.line_location_id,c_api_name,9);
5693 END IF;
5694
5695 l_delete_flag := 'Y';
5696 l_sort_by_criteria := inv_reservation_global.g_query_demand_ship_date_desc;
5697 l_mtl_maint_rsv_rec.action := 0;--supply is reduced
5698 l_mtl_maint_rsv_rec.organization_id :=
5699 get_line_loc_rec.ship_to_organization_id;
5700 l_mtl_maint_rsv_rec.inventory_item_id :=
5701 get_line_loc_rec.item_id;
5702 l_mtl_maint_rsv_rec.supply_source_type_id:= inv_reservation_global.g_source_type_po;
5703 l_mtl_maint_rsv_rec.supply_source_header_id := l_po_header_id;
5704 l_mtl_maint_rsv_rec.supply_source_line_id :=
5705 get_line_loc_rec.line_location_id;
5706 -- l_mtl_maint_rsv_rec.supply_source_line_detail := NULL;
5707
5708 reduce_reservation
5709 (
5710 p_api_version_number => 1.0
5711 , p_init_msg_lst => fnd_api.g_false
5712 , x_return_status => l_return_status
5713 , x_msg_count => x_msg_count
5714 , x_msg_data => x_msg_data
5715 , p_mtl_maintain_rsv_rec => l_mtl_maint_rsv_rec
5716 , p_delete_flag => l_delete_flag
5717 , p_sort_by_criteria => l_sort_by_criteria
5718 , x_quantity_modified => l_quantity_modified);
5719 IF g_debug= C_Debug_Enabled THEN
5720 mydebug ('Return Status after calling reduce reservations: '|| l_return_status, c_api_name,9);
5721 END IF;
5722
5723 IF l_return_status = fnd_api.g_ret_sts_error THEN
5724
5725 IF g_debug= C_Debug_Enabled THEN
5726 mydebug('Raising expected error'||l_return_status, c_api_name,9);
5727 END IF;
5728 RAISE fnd_api.g_exc_error;
5729
5730 ELSIF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
5731
5732 IF g_debug= C_Debug_Enabled THEN
5733 mydebug('Rasing Unexpected error'||l_return_status, c_api_name,9);
5734 END IF;
5735 RAISE fnd_api.g_exc_unexpected_error;
5736
5737 END IF;
5738 END LOOP;
5739 END IF; --Reservation Exists
5740
5741 ELSIF upper(p_action) = 'CANCEL_PO_SHIPMENT' THEN
5742 --OPEN get_po_header_id_shipment(p_line_location_id);
5743 --FETCH get_po_header_id_shipment INTO l_po_header_id;
5744 --CLOSE get_po_header_id_shipment;
5745
5746 IF g_debug= C_Debug_Enabled THEN
5747 mydebug ('Cancel PO Shipment.Removing po line location. po line loc.:'|| p_line_location_id,c_api_name,9);
5748 END IF;
5749 -- If Reservation Exists for the PO, then proceed to check whether
5750 -- the existing Reservation needs to be transferred to Requisition
5751 -- Since Reservation is on the PO and PO Distribution, PO Reservation is
5752 -- checked even when the Line is Cancelled
5753 IF exists_reservation(p_supply_source_line_id => p_line_location_id) THEN
5754
5755 -- OPEN get_distr_for_po_shipment(p_line_location_id);
5756 --
5757 -- LOOP
5758 -- FETCH get_distr_for_po_shipment INTO get_distr_rec;
5759 -- EXIT WHEN get_distr_for_po_shipment%NOTFOUND;
5760 --
5761 -- DELETE_RES (p_supply_source_header_id => l_po_header_id
5762 -- ,p_supply_source_line_id => get_distr_rec.line_location_id
5763 -- ,p_supply_source_type_id => inv_reservation_global.g_source_type_po--
5764 -- ,x_msg_count => x_msg_count
5765 ---- ,x_msg_data => x_msg_data
5766 -- ,x_return_status => l_return_status);
5767 --
5768 -- END LOOP; -- get_distr
5769
5770 OPEN get_line_loc_for_po_shipment(p_line_location_id);
5771 FETCH get_line_loc_for_po_shipment INTO get_line_loc_rec;
5772 CLOSE get_line_loc_for_po_shipment;
5773
5774 l_delete_flag := 'Y';
5775 l_sort_by_criteria := inv_reservation_global.g_query_demand_ship_date_desc;
5776 l_mtl_maint_rsv_rec.action := 0;--supply is reduced
5777 l_mtl_maint_rsv_rec.organization_id :=
5778 get_line_loc_rec.ship_to_organization_id;
5779 l_mtl_maint_rsv_rec.inventory_item_id :=
5780 get_line_loc_rec.item_id;
5781 l_mtl_maint_rsv_rec.supply_source_type_id:= inv_reservation_global.g_source_type_po;
5782 l_mtl_maint_rsv_rec.supply_source_header_id := get_line_loc_rec.po_header_id;
5783 l_mtl_maint_rsv_rec.supply_source_line_id := p_line_location_id;
5784 -- l_mtl_maint_rsv_rec.supply_source_line_detail := NULL;
5785
5786 reduce_reservation
5787 (
5788 p_api_version_number => 1.0
5789 , p_init_msg_lst => fnd_api.g_false
5790 , x_return_status => l_return_status
5791 , x_msg_count => x_msg_count
5792 , x_msg_data => x_msg_data
5793 , p_mtl_maintain_rsv_rec => l_mtl_maint_rsv_rec
5794 , p_delete_flag => l_delete_flag
5795 , p_sort_by_criteria => l_sort_by_criteria
5796 , x_quantity_modified => l_quantity_modified);
5797 IF g_debug= C_Debug_Enabled THEN
5798 mydebug ('Return Status after calling reduce reservations: '|| l_return_status, c_api_name,9);
5799 END IF;
5800
5801 IF l_return_status = fnd_api.g_ret_sts_error THEN
5802
5803 IF g_debug= C_Debug_Enabled THEN
5804 mydebug('Raising expected error'||l_return_status, c_api_name,9);
5805 END IF;
5806 RAISE fnd_api.g_exc_error;
5807
5808 ELSIF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
5809
5810 IF g_debug= C_Debug_Enabled THEN
5811 mydebug('Rasing Unexpected error'||l_return_status, c_api_name,9);
5812 END IF;
5813 RAISE fnd_api.g_exc_unexpected_error;
5814
5815 END IF;
5816
5817 END IF; --Reservation Exists
5818
5819 ELSIF upper(p_action) = 'CANCEL_BLANKET_RELEASE' THEN
5820 OPEN get_po_header_id_release(p_header_id); -- p_header_id is po_release_id
5821 FETCH get_po_header_id_release INTO l_po_header_id;
5822 CLOSE get_po_header_id_release;
5823
5824 IF g_debug= C_Debug_Enabled THEN
5825 mydebug ('Cancel Blanket Release. po header id. :'|| l_po_header_id,c_api_name,9);
5826 END IF;
5827 -- If Reservation Exists for the PO, then proceed to check whether
5828 -- the existing Reservation needs to be transferred to Requisition
5829 -- Since Reservation is on the PO and PO Distribution, PO Reservation is
5830 -- checked even when the Release is Cancelled
5831 --
5832 IF exists_reservation(p_supply_source_header_id => l_po_header_id) THEN
5833
5834 --delete the reservation
5835 -- OPEN get_distr_for_po_release(p_header_id);
5836 --LOOP
5837 -- FETCH get_distr_for_po_release INTO get_distr_rec;
5838 -- EXIT WHEN get_distr_for_po_release%NOTFOUND;
5839
5840 -- DELETE_RES ( p_supply_source_header_id => l_po_header_id
5841 -- ,p_supply_source_line_id => get_distr_rec.line_location_id
5842 -- ,p_supply_source_type_id => inv_reservation_global.g_source_type_po
5843 -- ,x_msg_count => x_msg_count
5844 -- ,x_msg_data => x_msg_data
5845 -- ,x_return_status => l_return_status);
5846
5847 --END LOOP; --get_distr_for_po_release
5848
5849 --reservation should be deleted
5850
5851 OPEN get_po_shipment(p_header_id);
5852 LOOP
5853 FETCH get_po_shipment INTO get_po_shipment_rec;
5854 EXIT WHEN get_po_shipment%NOTFOUND;
5855
5856 --DELETE_RES (p_supply_source_header_id => p_header_id
5857 -- ,p_supply_source_line_id => get_po_shipment_rec.line_location_id
5858 -- ,p_supply_source_type_id => inv_reservation_global.g_source_type_po
5859 -- ,x_msg_count => x_msg_count
5860 -- ,x_msg_data => x_msg_data
5861 -- ,x_return_status => l_return_status);
5862 IF g_debug= C_Debug_Enabled THEN
5863 mydebug ('Removing po line location. po line loc.:'|| get_po_shipment_rec.line_location_id,c_api_name,9);
5864 END IF;
5865
5866 l_delete_flag := 'Y';
5867 l_sort_by_criteria := inv_reservation_global.g_query_demand_ship_date_desc;
5868 l_mtl_maint_rsv_rec.action := 0;--supply is reduced
5869 l_mtl_maint_rsv_rec.organization_id :=
5870 get_po_shipment_rec.ship_to_organization_id;
5871 l_mtl_maint_rsv_rec.inventory_item_id :=
5872 get_po_shipment_rec.item_id;
5873 l_mtl_maint_rsv_rec.supply_source_type_id:= inv_reservation_global.g_source_type_po;
5874 l_mtl_maint_rsv_rec.supply_source_header_id := l_po_header_id;
5875 l_mtl_maint_rsv_rec.supply_source_line_id :=
5876 get_po_shipment_rec.line_location_id;
5877 -- l_mtl_maint_rsv_rec.supply_source_line_detail := NULL;
5878
5879 reduce_reservation
5880 (
5881 p_api_version_number => 1.0
5882 , p_init_msg_lst => fnd_api.g_false
5883 , x_return_status => l_return_status
5884 , x_msg_count => x_msg_count
5885 , x_msg_data => x_msg_data
5886 , p_mtl_maintain_rsv_rec => l_mtl_maint_rsv_rec
5887 , p_delete_flag => l_delete_flag
5888 , p_sort_by_criteria => l_sort_by_criteria
5889 , x_quantity_modified => l_quantity_modified);
5890 IF g_debug= C_Debug_Enabled THEN
5891 mydebug ('Return Status after calling reduce reservations: '|| l_return_status, c_api_name,9);
5892 END IF;
5893
5894 IF l_return_status = fnd_api.g_ret_sts_error THEN
5895
5896 IF g_debug= C_Debug_Enabled THEN
5897 mydebug('Raising expected error'||l_return_status, c_api_name,9);
5898 END IF;
5899 RAISE fnd_api.g_exc_error;
5900
5901 ELSIF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
5902
5903 IF g_debug= C_Debug_Enabled THEN
5904 mydebug('Rasing Unexpected error'||l_return_status, c_api_name,9);
5905 END IF;
5906 RAISE fnd_api.g_exc_unexpected_error;
5907
5908 END IF;
5909 END LOOP; --get_distr
5910
5911 END IF; --Reservation Exists
5912 --
5913 ELSIF upper(p_action) = 'CANCEL_BLANKET_SHIPMENT' THEN
5914
5915 -- OPEN get_po_header_id_shipment(p_line_location_id);
5916 -- FETCH get_po_header_id_shipment INTO l_po_header_id;
5917 -- CLOSE get_po_header_id_shipment;
5918
5919 -- If Reservation Exists for the PO, then proceed to check whether
5920 -- the existing Reservation needs to be transferred to Requisition
5921 -- Since Reservation is on the PO and PO Distribution, PO Reservation is
5922 -- checked even when the Line is Cancelled
5923 IF g_debug= C_Debug_Enabled THEN
5924 mydebug ('Cancel Blanket Shipment. po line location id. :'|| p_line_location_id,c_api_name,9);
5925 END IF;
5926
5927 IF exists_reservation(p_supply_source_line_id => p_line_location_id) THEN
5928
5929 -- OPEN get_distr_for_po_shipment(p_line_location_id);
5930 -- LOOP
5931 -- FETCH get_distr_for_po_shipment INTO get_distr_rec;
5932 -- EXIT WHEN get_distr_for_po_shipment%NOTFOUND;
5933
5934 -- DELETE_RES (p_supply_source_header_id => l_po_header_id
5935 -- ,p_supply_source_line_id => get_distr_rec.line_location_id
5936 -- ,p_supply_source_type_id => inv_reservation_global.g_source_type_po
5937 -- ,x_msg_count => x_msg_count
5938 -- ,x_msg_data => x_msg_data
5939 -- ,x_return_status => l_return_status);
5940 --
5941 -- END LOOP; -- get_distr
5942
5943 OPEN get_line_loc_for_po_shipment(p_line_location_id);
5944 FETCH get_line_loc_for_po_shipment INTO get_line_loc_rec;
5945 CLOSE get_line_loc_for_po_shipment;
5946
5947 l_delete_flag := 'Y';
5948 l_sort_by_criteria := inv_reservation_global.g_query_demand_ship_date_desc;
5949 l_mtl_maint_rsv_rec.action := 0;--supply is reduced
5950 l_mtl_maint_rsv_rec.organization_id :=
5951 get_line_loc_rec.ship_to_organization_id;
5952 l_mtl_maint_rsv_rec.inventory_item_id :=
5953 get_line_loc_rec.item_id;
5954 l_mtl_maint_rsv_rec.supply_source_type_id:= inv_reservation_global.g_source_type_po;
5955 l_mtl_maint_rsv_rec.supply_source_header_id := get_line_loc_rec.po_header_id;
5956 l_mtl_maint_rsv_rec.supply_source_line_id := p_line_location_id;
5957 -- l_mtl_maint_rsv_rec.supply_source_line_detail := NULL;
5958
5959 reduce_reservation
5960 (
5961 p_api_version_number => 1.0
5962 , p_init_msg_lst => fnd_api.g_false
5963 , x_return_status => l_return_status
5964 , x_msg_count => x_msg_count
5965 , x_msg_data => x_msg_data
5966 , p_mtl_maintain_rsv_rec => l_mtl_maint_rsv_rec
5967 , p_delete_flag => l_delete_flag
5968 , p_sort_by_criteria => l_sort_by_criteria
5969 , x_quantity_modified => l_quantity_modified);
5970 IF g_debug= C_Debug_Enabled THEN
5971 mydebug ('Return Status after calling reduce reservations: '|| l_return_status, c_api_name,9);
5972 END IF;
5973
5974 IF l_return_status = fnd_api.g_ret_sts_error THEN
5975
5976 IF g_debug= C_Debug_Enabled THEN
5977 mydebug('Raising expected error'||l_return_status, c_api_name,9);
5978 END IF;
5979 RAISE fnd_api.g_exc_error;
5980
5981 ELSIF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
5982
5983 IF g_debug= C_Debug_Enabled THEN
5984 mydebug('Rasing Unexpected error'||l_return_status, c_api_name,9);
5985 END IF;
5986 RAISE fnd_api.g_exc_unexpected_error;
5987
5988 END IF;
5989
5990 END IF; --Reservation Exists
5991
5992 -- Bug 5253916: For update so quantity
5993
5994 ELSIF upper(p_action) = 'UPDATE_SO_QUANTITY' THEN
5995 --reduce the reservation on the req by the ordered quantity
5996 IF g_debug= C_Debug_Enabled THEN
5997 mydebug ('Inside update so qty. req line:'|| p_line_id ,c_api_name,9);
5998 END IF;
5999
6000 -- Check to see if there are any reservations for this requsition
6001 -- line.
6002
6003 BEGIN
6004 SELECT Nvl(SUM(primary_reservation_quantity),0) INTO
6005 l_primary_res_qty FROM mtl_reservations
6006 WHERE supply_source_type_id =
6007 inv_reservation_global.g_source_type_internal_req AND
6008 supply_source_header_id = p_header_id AND
6009 supply_source_line_id = p_line_id;
6010 EXCEPTION
6011 WHEN no_data_found THEN
6012 IF g_debug= C_Debug_Enabled THEN
6013 mydebug ('No reservation records found for req line id. req line:'|| p_line_id ,c_api_name,9);
6014 END IF;
6015 END;
6016
6017 IF l_primary_res_qty > 0 THEN
6018 -- reservations found
6019 -- get the req line information.
6020 BEGIN
6021 --bug #5498904 replaced org_id with destination_organization_id
6022 SELECT destination_organization_id, item_id, unit_meas_lookup_code, quantity INTO
6023 l_organization_id,
6024 l_inventory_item_id,
6025 l_req_unit_meas, l_req_qty FROM
6026 po_requisition_lines_all WHERE requisition_line_id = p_line_id;
6027 EXCEPTION
6028 WHEN no_data_found THEN
6029 IF g_debug= C_Debug_Enabled THEN
6030 mydebug ('No records found for req line id. req line:'|| p_line_id ,c_api_name,9);
6031 END IF;
6032 END;
6033
6034 IF (p_ordered_quantity = 0) THEN
6035 -- delete all reservations for that req line
6036 -- calling reduce_reservation API
6037 l_delete_flag := 'Y';
6038 l_sort_by_criteria := inv_reservation_global.g_query_demand_ship_date_desc;
6039 l_mtl_maint_rsv_rec.action := 0;--supply is reduced
6040 l_mtl_maint_rsv_rec.organization_id := l_organization_id;
6041 l_mtl_maint_rsv_rec.inventory_item_id := l_inventory_item_id;
6042 --bug #5498904 populated l_mtl_maint_rsv_rec.supply_source_type_id
6043 l_mtl_maint_rsv_rec.supply_source_type_id := inv_reservation_global.g_source_type_internal_req;
6044 l_supply_source_type_id := inv_reservation_global.g_source_type_internal_req;
6045 l_mtl_maint_rsv_rec.supply_source_header_id := p_header_id;
6046 l_mtl_maint_rsv_rec.supply_source_line_id := p_line_id;
6047 -- l_mtl_maint_rsv_rec.supply_source_line_detail := NULL;
6048
6049 reduce_reservation
6050 (
6051 p_api_version_number => 1.0
6052 , p_init_msg_lst => fnd_api.g_false
6053 , x_return_status => l_return_status
6054 , x_msg_count => x_msg_count
6055 , x_msg_data => x_msg_data
6056 , p_mtl_maintain_rsv_rec => l_mtl_maint_rsv_rec
6057 , p_delete_flag => l_delete_flag
6058 , p_sort_by_criteria => l_sort_by_criteria
6059 , x_quantity_modified => l_quantity_modified);
6060 IF g_debug= C_Debug_Enabled THEN
6061 mydebug ('Return Status after calling reduce reservations: '|| l_return_status, c_api_name,9);
6062 mydebug ('Expected qty: '|| p_ordered_quantity, c_api_name,9);
6063 mydebug ('Modified qty: '|| l_quantity_modified, c_api_name,9);
6064 END IF;
6065
6066 IF l_return_status = fnd_api.g_ret_sts_error THEN
6067
6068 IF g_debug= C_Debug_Enabled THEN
6069 mydebug('Raising expected error'||l_return_status, c_api_name,9);
6070 END IF;
6071 RAISE fnd_api.g_exc_error;
6072
6073 ELSIF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
6074
6075 IF g_debug= C_Debug_Enabled THEN
6076 mydebug('Rasing Unexpected error'||l_return_status, c_api_name,9);
6077 END IF;
6078 RAISE fnd_api.g_exc_unexpected_error;
6079
6080 END IF;
6081
6082 ELSE
6083 -- reduce the reservations to the ordered qty
6084 -- Set the source type as internal req
6085
6086 l_mtl_maint_rsv_rec.action := 0;--supply is reduced
6087 l_sort_by_criteria := inv_reservation_global.g_query_demand_ship_date_desc;
6088 l_mtl_maint_rsv_rec.organization_id := l_organization_id;
6089 l_mtl_maint_rsv_rec.inventory_item_id := l_inventory_item_id;
6090 --bug #5498904 populated l_mtl_maint_rsv_rec.supply_source_type_id
6091 l_mtl_maint_rsv_rec.supply_source_type_id := inv_reservation_global.g_source_type_internal_req;
6092 l_supply_source_type_id := inv_reservation_global.g_source_type_internal_req;
6093 l_mtl_maint_rsv_rec.supply_source_header_id := p_header_id;
6094 l_mtl_maint_rsv_rec.supply_source_line_id := p_line_id;
6095 -- l_mtl_maint_rsv_rec.supply_source_line_detail := NULL;
6096 l_mtl_maint_rsv_rec.expected_quantity := p_ordered_quantity;
6097 l_mtl_maint_rsv_rec.expected_quantity_uom := p_ordered_uom;
6098
6099 reduce_reservation
6100 (
6101 p_api_version_number => 1.0
6102 , p_init_msg_lst => fnd_api.g_false
6103 , x_return_status => l_return_status
6104 , x_msg_count => x_msg_count
6105 , x_msg_data => x_msg_data
6106 , p_mtl_maintain_rsv_rec => l_mtl_maint_rsv_rec
6107 , p_delete_flag => 'N'
6108 , p_sort_by_criteria => l_sort_by_criteria
6109 , x_quantity_modified => l_quantity_modified);
6110
6111 IF g_debug= C_Debug_Enabled THEN
6112 mydebug ('Return Status after calling reduce reservations: '|| l_return_status, c_api_name,9);
6113 mydebug ('Expected qty: '|| p_ordered_quantity, c_api_name,9);
6114 mydebug ('Modified qty: '|| l_quantity_modified, c_api_name,9);
6115 END IF;
6116
6117 IF l_return_status = fnd_api.g_ret_sts_error THEN
6118
6119 IF g_debug= C_Debug_Enabled THEN
6120 mydebug('Raising expected error'||l_return_status, c_api_name,9);
6121 END IF;
6122 RAISE fnd_api.g_exc_error;
6123
6124 ELSIF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
6125
6126 IF g_debug= C_Debug_Enabled THEN
6127 mydebug('Rasing Unexpected error'||l_return_status, c_api_name,9);
6128 END IF;
6129 RAISE fnd_api.g_exc_unexpected_error;
6130
6131 END IF;
6132 END IF; -- ordered qty
6133
6134 END IF; -- reservation records found
6135 ELSE
6136 -- all other actions do nothing ....for now
6137 NULL;
6138
6139 END IF;
6140
6141
6142 If g_debug= C_Debug_Enabled Then
6143 l_Fnd_Log_Message := 'l_return_status: '||l_return_status;
6144 mydebug(l_Fnd_Log_Message,c_api_name,9);
6145 End If;
6146
6147 x_return_status := l_return_status;
6148
6149 If x_return_status = fnd_api.g_ret_sts_success THEN
6150 l_Fnd_Log_message := 'Calling maintain_reservation API was successful ';
6151 -- Fnd_Log_Debug(fnd_log.Level_Error,C_Module_name, l_Fnd_Log_Message );
6152 IF G_debug= C_Debug_Enabled THEN
6153 mydebug(l_Fnd_Log_Message, c_api_name,9);
6154 END IF;
6155 else
6156 l_Fnd_Log_message := 'Error while calling maintain_reservation API ';
6157 -- Fnd_Log_Debug(fnd_log.Level_Error,C_Module_name, l_Fnd_Log_Message );
6158 IF G_debug= C_Debug_Enabled THEN
6159 mydebug(l_Fnd_Log_Message, c_api_name,9);
6160 END IF;
6161 end if;
6162
6163 -- Call fnd_log api at the end of the API
6164 l_Fnd_Log_message := 'At the end of procedure :';
6165 -- Fnd_Log_Debug(Fnd_Log.Level_Procedure,C_Module_name, l_Fnd_Log_Message );
6166
6167 IF G_debug= C_Debug_Enabled THEN
6168 mydebug(l_Fnd_Log_Message, c_api_name,9);
6169 END IF;
6170
6171 --
6172 EXCEPTION
6173 WHEN fnd_api.g_exc_error THEN
6174 x_return_status := fnd_api.g_ret_sts_error;
6175
6176 -- Get message count and data
6177 fnd_msg_pub.count_and_get
6178 ( p_count => x_msg_count
6179 , p_data => x_msg_data
6180 );
6181
6182 -- Call fnd_log api at the end of the API
6183 l_Fnd_Log_message := 'When Expected exception raised for procedure :' ;
6184 -- Fnd_Log_Debug(fnd_log.Level_Error,C_Module_name, l_Fnd_Log_Message );
6185
6186 -- Log message in trace file
6187 IF G_debug= C_Debug_Enabled THEN
6188 mydebug(l_Fnd_Log_Message,c_api_name,9);
6189 END IF;
6190
6191 -- Get messages from stack and log them in fnd tables
6192 If X_Msg_Count = 1 Then
6193 -- Fnd_Log_Debug(fnd_log.Level_Error,C_Module_name, X_Msg_Data );
6194 -- Log message in trace file
6195 If G_debug= C_Debug_Enabled THEN
6196 mydebug(l_Fnd_Log_Message,c_api_name,9);
6197 End If;
6198 Elsif x_msg_count > 1 Then
6199 For I In 1..X_Msg_Count Loop
6200 FND_MSG_PUB.Get
6201 (p_msg_index => i,
6202 p_encoded => 'F',
6203 p_data => l_Fnd_Log_Message,
6204 p_msg_index_out => l_msg_index_out );
6205
6206 -- Fnd_Log_Debug(fnd_log.Level_Error,C_Module_name, l_Fnd_Log_Message );
6207
6208 -- Log message in trace file
6209 IF G_debug= C_Debug_Enabled THEN
6210 mydebug(l_Fnd_Log_Message,c_api_name,9);
6211 END IF;
6212 End Loop ;
6213 End If;
6214
6215 WHEN fnd_api.g_exc_unexpected_error THEN
6216 x_return_status := fnd_api.g_ret_sts_unexp_error ;
6217
6218 -- Get message count and data
6219 fnd_msg_pub.count_and_get
6220 ( p_count => x_msg_count
6221 , p_data => x_msg_data
6222 );
6223 -- Call fnd_log api at the end of the API
6224 l_Fnd_Log_message := 'When unexpected exception raised for procedure :';
6225 -- Fnd_Log_Debug(fnd_log.Level_Error,C_Module_name, l_Fnd_Log_Message );
6226
6227 -- Log message in trace file
6228 IF G_debug= C_Debug_Enabled THEN
6229 mydebug(l_Fnd_Log_Message,c_api_name,9);
6230 END IF;
6231
6232 -- Get messages from stack and log them in fnd tables
6233 If X_Msg_Count = 1 Then
6234 -- Fnd_Log_Debug(fnd_log.Level_Error,C_Module_name, X_Msg_Data );
6235
6236 -- Log message in trace file
6237 IF G_debug= C_Debug_Enabled THEN
6238 mydebug(l_Fnd_Log_Message,c_api_name,9);
6239 END IF;
6240 Elsif X_Msg_Count > 1 Then
6241 For I In 1..X_Msg_Count Loop
6242 FND_MSG_PUB.Get
6243 (p_msg_index => i,
6244 p_encoded => 'F',
6245 p_data => l_Fnd_Log_Message,
6246 p_msg_index_out => l_msg_index_out );
6247
6248 -- Fnd_Log_Debug(fnd_log.Level_Error,C_Module_name, l_Fnd_Log_Message );
6249
6250 -- Log message in trace file
6251 IF G_debug= C_Debug_Enabled THEN
6252 mydebug(l_Fnd_Log_Message,c_api_name,9);
6253 END IF;
6254 End Loop ;
6255 End If;
6256
6257 WHEN OTHERS THEN
6258 x_return_status := fnd_api.g_ret_sts_unexp_error ;
6259
6260 IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error)
6261 THEN
6262 fnd_msg_pub.add_exc_msg
6263 ( g_pkg_name
6264 , c_api_name
6265 );
6266 END IF;
6267
6268 -- Get message count and data
6269 fnd_msg_pub.count_and_get
6270 ( p_count => x_msg_count
6271 , p_data => x_msg_data
6272 );
6273
6274 -- Call fnd_log api at the end of the API
6275 l_Fnd_Log_message := 'When Others exception raised for procedure :' || G_Pkg_Name || '.' || C_API_Name ;
6276 -- Fnd_Log_Debug(fnd_log.Level_Error,C_Module_name, l_Fnd_Log_Message );
6277
6278 -- Log message in trace file
6279 IF G_debug= C_Debug_Enabled THEN
6280 mydebug(l_Fnd_Log_Message,c_api_name,9);
6281 END IF;
6282
6283 -- Get messages from stack and log them in fnd tables
6284 If X_Msg_Count = 1 Then
6285 -- Fnd_Log_Debug(fnd_log.Level_Error,C_Module_name, X_Msg_Data );
6286
6287 -- Log message in trace file
6288 If G_debug= C_Debug_Enabled Then
6289 mydebug(l_Fnd_Log_Message,c_api_name,9);
6290 End If;
6291 Elsif X_Msg_Count > 1 Then
6292 For I In 1..X_Msg_Count Loop
6293 FND_MSG_PUB.Get
6294 (p_msg_index => i,
6295 p_encoded => 'F',
6296 p_data => l_Fnd_Log_Message,
6297 p_msg_index_out => l_msg_index_out );
6298
6299 -- Fnd_Log_Debug(fnd_log.Level_Error,C_Module_name, l_Fnd_Log_Message );
6300
6301 -- Log message in trace file
6302 IF G_debug= C_Debug_Enabled THEN
6303 mydebug(l_Fnd_Log_Message,c_api_name,9);
6304 END IF;
6305 End Loop ;
6306 End If;
6307
6308 END MAINTAIN_RESERVATION;
6309
6310
6311 END INV_MAINTAIN_RESERVATION_PUB;