[Home] [Help]
PACKAGE BODY: APPS.INL_SHIPMENT_PVT
Source
1 PACKAGE BODY "INL_SHIPMENT_PVT" AS
2 /* $Header: INLVSHPB.pls 120.15.12010000.31 2009/02/09 12:47:11 acferrei ship $ */
3
4 TYPE rcv_header_interface_rec_type
5 IS
6 RECORD
7 (
8 header_interface_id NUMBER,
9 notice_creation_date DATE,
10 transaction_type VARCHAR2 (25),
11 processing_status_code VARCHAR2 (25),
12 receipt_source_code VARCHAR2 (25),
13 validation_flag VARCHAR2 (1),
14 ship_to_organization_id NUMBER,
15 vendor_id NUMBER,
16 vendor_site_id NUMBER,
17 group_id NUMBER,
18 shipment_num VARCHAR2 (30),
19 shipped_date DATE,
20 last_update_date DATE,
21 last_updated_by NUMBER,
22 creation_date DATE,
23 created_by NUMBER,
24 last_update_login NUMBER) ;
25 TYPE rcv_header_interface_tbl
26 IS
27 TABLE OF rcv_header_interface_rec_type INDEX BY BINARY_INTEGER;
28 rcv_header_interface rcv_header_interface_tbl;
29 TYPE rcv_trx_interface_rec_type
30 IS
31 RECORD
32 (
33 interface_transaction_id NUMBER,
34 transaction_type VARCHAR2 (25),
35 quantity NUMBER,
36 interface_source_code VARCHAR2 (30),
37 interface_source_line_id NUMBER,
38 transaction_date DATE,
39 processing_status_code VARCHAR2 (25),
40 processing_mode_code VARCHAR2 (25),
41 transaction_status_code VARCHAR2 (25),
42 receipt_source_code VARCHAR2 (25),
43 source_document_code VARCHAR2 (25),
44 validation_flag VARCHAR2 (1),
45 po_header_id NUMBER,
46 po_line_id NUMBER,
47 po_line_location_id NUMBER,
48 po_release_id NUMBER,
49 item_id NUMBER,
50 item_num VARCHAR2 (50),
51 item_description VARCHAR2 (240),
52 uom_code VARCHAR2 (3),
53 vendor_item_num VARCHAR2 (25),
54 vendor_id NUMBER,
55 vendor_site_id NUMBER,
56 ship_to_location_id NUMBER,
57 location_id NUMBER,
58 org_id NUMBER,
59 to_organization_id NUMBER,
60 group_id NUMBER,
61 lpn_group_id NUMBER,
62 header_interface_id NUMBER,
63 last_update_date DATE,
64 last_updated_by NUMBER,
65 creation_date DATE,
66 created_by NUMBER,
67 last_update_login NUMBER,
68 unit_landed_cost NUMBER) ;
69 TYPE rcv_trx_interface_tbl
70 IS
71 TABLE OF rcv_trx_interface_rec_type INDEX BY BINARY_INTEGER;
72 rcv_trx_interface rcv_trx_interface_tbl;
73 -- Utl name : Handle_ShipError
74 -- Type : Private
75 -- Function : Insert errors in INL_SHIP_HOLDS
76 -- Pre-reqs : None
77 -- Parameters :
78 -- IN : p_ship_header_id IN NUMBER ,
79 -- p_ship_line_id IN NUMBER,
80 -- p_charge_line_id IN NUMBER,
81 -- p_table_name IN VARCHAR2,
82 -- p_column_name IN VARCHAR2,
83 -- p_column_value IN VARCHAR2,
84 -- p_error_message IN VARCHAR2,
85 -- p_error_message_name IN VARCHAR2,
86 -- p_token1_name IN VARCHAR2,
87 -- p_token1_value IN VARCHAR2,
88 -- p_token2_name IN VARCHAR2,
89 -- p_token2_value IN VARCHAR2,
90 -- p_token3_name IN VARCHAR2,
91 -- p_token3_value IN VARCHAR2,
92 -- p_token4_name IN VARCHAR2,
93 -- p_token4_value IN VARCHAR2,
94 -- p_token5_name IN VARCHAR2,
95 -- p_token5_value IN VARCHAR2,
96 -- p_token6_name IN VARCHAR2,
97 -- p_token6_value IN VARCHAR2,
98 --
99 --
100 -- OUT x_return_status OUT NOCOPY VARCHAR2
101 --
102 -- Version : Current version 1.0
103 --
104 -- Notes :
105 PROCEDURE Handle_ShipError
106 (
107 p_ship_header_id IN NUMBER,
108 p_ship_line_id IN NUMBER,
109 p_charge_line_id IN NUMBER,
110 p_table_name IN VARCHAR2,
111 p_column_name IN VARCHAR2,
112 p_column_value IN VARCHAR2,
113 p_error_message IN VARCHAR2,
114 p_error_message_name IN VARCHAR2,
115 p_token1_name IN VARCHAR2,
116 p_token1_value IN VARCHAR2,
117 p_token2_name IN VARCHAR2,
118 p_token2_value IN VARCHAR2,
119 p_token3_name IN VARCHAR2,
120 p_token3_value IN VARCHAR2,
121 p_token4_name IN VARCHAR2,
122 p_token4_value IN VARCHAR2,
123 p_token5_name IN VARCHAR2,
124 p_token5_value IN VARCHAR2,
125 p_token6_name IN VARCHAR2,
126 p_token6_value IN VARCHAR2,
127 x_return_status OUT NOCOPY VARCHAR2)
128 IS
129 l_proc_name CONSTANT VARCHAR2 (30) := 'Handle_ShipError';
130 l_return_status VARCHAR2 (1) ;
131 l_msg_count NUMBER;
132 l_msg_data VARCHAR2 (2000) ;
133 l_debug_info VARCHAR2 (200) ;
134 BEGIN
135 -- Standard Beginning of Procedure/Function Logging
136 INL_LOGGING_PVT.Log_BeginProc ( p_module_name => g_module_name,
137 p_procedure_name => l_proc_name) ;
138 -- Initialize return status to success
139 x_return_status := FND_API.G_RET_STS_SUCCESS;
140 l_debug_info := 'Insert error details in inl_ship_holds.';
141 INL_LOGGING_PVT.Log_Statement (
142 p_module_name => g_module_name,
143 p_procedure_name => l_proc_name,
144 p_debug_info => l_debug_info
145 ) ;
146
147 INSERT
148 INTO inl_ship_holds
149 (
150 ship_hold_id ,
151 ship_header_id ,
152 ship_line_id ,
153 table_name ,
154 column_name ,
155 column_value ,
156 processing_date ,
157 error_message_name ,
158 error_message ,
159 token1_name ,
160 token1_value ,
161 token2_name ,
162 token2_value ,
163 token3_name ,
164 token3_value ,
165 token4_name ,
166 token4_value ,
167 token5_name ,
168 token5_value ,
169 token6_name ,
170 token6_value ,
171 created_by ,
172 creation_date ,
173 last_updated_by ,
174 last_update_date ,
175 last_update_login ,
176 program_id ,
177 program_application_id,
178 program_update_date ,
179 request_id
180 )
181 VALUES
182 (
183 inl_ship_holds_s.NEXTVAL ,
184 p_ship_header_id ,
185 p_ship_line_id ,
186 p_table_name ,
187 p_column_name ,
188 p_column_value ,
189 SYSDATE ,
190 p_error_message_name ,
191 p_error_message ,
192 p_token1_name ,
193 p_token1_value ,
194 p_token2_name ,
195 p_token2_value ,
196 p_token3_name ,
197 p_token3_value ,
198 p_token4_name ,
199 p_token4_value ,
200 p_token5_name ,
201 p_token5_value ,
202 p_token6_name ,
203 p_token6_value ,
204 fnd_global.user_id ,
205 SYSDATE ,
206 fnd_global.user_id ,
207 SYSDATE ,
208 fnd_global.user_id ,
209 fnd_global.conc_program_id,
210 fnd_global.prog_appl_id ,
211 SYSDATE ,
212 fnd_global.conc_request_id
213 ) ;
214 -- Standard End of Procedure/Function Logging
215 INL_LOGGING_PVT.Log_EndProc
216 (
217 p_module_name => g_module_name, p_procedure_name => l_proc_name
218 )
219 ;
220 EXCEPTION
221 WHEN FND_API.G_EXC_ERROR THEN
222 -- Standard Expected Error Logging
223 INL_LOGGING_PVT.Log_ExpecError
224 (
225 p_module_name => g_module_name, p_procedure_name => l_proc_name
226 )
227 ;
228 x_return_status := FND_API.G_RET_STS_ERROR;
229 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
230 -- Standard Unexpected Error Logging
231 INL_LOGGING_PVT.Log_UnexpecError
232 (
233 p_module_name => g_module_name, p_procedure_name => l_proc_name
234 )
235 ;
236 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
237 WHEN OTHERS THEN
238 -- Standard Unexpected Error Logging
239 INL_LOGGING_PVT.Log_UnexpecError
240 (
241 p_module_name => g_module_name, p_procedure_name => l_proc_name
242 )
243 ;
244 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
245 IF FND_MSG_PUB.Check_Msg_Level
246 (
247 p_message_level => FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR
248 )
249 THEN
250 FND_MSG_PUB.Add_Exc_Msg
251 (
252 p_pkg_name => g_pkg_name, p_procedure_name => l_proc_name
253 )
254 ;
255 END IF;
256 END Handle_ShipError;
257 -- Utility name : Reset_ShipError
258 -- Type : Private
259 -- Function : Delete previous errors for the current shipment
260 -- Pre-reqs : None
261 -- Parameters :
262 -- IN : p_ship_header_id IN NUMBER Required Id of Ship Header record
263 -- p_ship_line_id IN NUMBER Optional Id of Ship Line record
264 -- p_charge_line_id IN NUMBER Optional Id of Ship Line record
265 --
266 -- OUT x_return_status OUT NOCOPY VARCHAR2
267 --
268 -- Version : Current version 1.0
269 --
270 -- Notes :
271 PROCEDURE Reset_ShipError
272 (
273 p_ship_header_id IN NUMBER,
274 p_ship_line_id IN NUMBER,
275 p_charge_line_id IN NUMBER,
276 x_return_status OUT NOCOPY VARCHAR2
277 )
278 IS
279 l_proc_name CONSTANT VARCHAR2
280 (
281 30
282 )
283 := 'Reset_ShipError';
284 l_api_version CONSTANT NUMBER := 1.0;
285 l_return_status VARCHAR2
286 (
287 1
288 )
289 ;
290 l_msg_count NUMBER;
291 l_msg_data VARCHAR2
292 (
293 2000
294 )
295 ;
296 l_debug_info VARCHAR2
297 (
298 200
299 )
300 ;
301 BEGIN
302 -- Standard Beginning of Procedure/Function Logging
303 INL_LOGGING_PVT.Log_BeginProc
304 (
305 p_module_name => g_module_name, p_procedure_name => l_proc_name
306 )
307 ;
308 -- Initialize return status to success
309 x_return_status := FND_API.G_RET_STS_SUCCESS;
310 l_debug_info := 'Delete Errors from previous validation.';
311 INL_LOGGING_PVT.Log_Statement (
312 p_module_name => g_module_name,
313 p_procedure_name => l_proc_name,
314 p_debug_info => l_debug_info
315 ) ;
316
317 IF p_ship_line_id IS NULL AND p_charge_line_id IS NULL THEN
318 DELETE FROM inl_ship_holds WHERE ship_header_id = p_ship_header_id;
319 ELSE
320 IF p_ship_line_id IS NOT NULL THEN
321 DELETE
322 FROM inl_ship_holds
323 WHERE ship_header_id = p_ship_header_id
324 AND ship_line_id = p_ship_line_id;
325 END IF;
326 IF p_charge_line_id IS NOT NULL THEN
327 DELETE
328 FROM inl_ship_holds
329 WHERE ship_header_id = p_ship_header_id
330 AND ship_line_id = p_charge_line_id;
331 END IF;
332 END IF;
333 -- Standard End of Procedure/Function Logging
334 INL_LOGGING_PVT.Log_EndProc ( p_module_name => g_module_name,
335 p_procedure_name => l_proc_name) ;
336 EXCEPTION
337 WHEN FND_API.G_EXC_ERROR THEN
338 -- Standard Expected Error Logging
339 INL_LOGGING_PVT.Log_ExpecError ( p_module_name => g_module_name,
340 p_procedure_name => l_proc_name) ;
341 x_return_status := FND_API.G_RET_STS_ERROR;
342 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
343 -- Standard Unexpected Error Logging
344 INL_LOGGING_PVT.Log_UnexpecError ( p_module_name => g_module_name,
345 p_procedure_name => l_proc_name) ;
346 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
347 WHEN OTHERS THEN
348 -- Standard Unexpected Error Logging
349 INL_LOGGING_PVT.Log_UnexpecError ( p_module_name => g_module_name,
350 p_procedure_name => l_proc_name) ;
351 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
352 IF FND_MSG_PUB.Check_Msg_Level (p_message_level => FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
353 FND_MSG_PUB.Add_Exc_Msg ( p_pkg_name => g_pkg_name,
354 p_procedure_name => l_proc_name) ;
355 END IF;
356 END Reset_ShipError;
357
358 -- API name : Complete_Shipment
359 -- Type : Private
360 -- Function : Complete a given LCM Shipment.
361 -- Pre-reqs : None
362 -- Parameters :
363 -- IN : p_api_version IN NUMBER
364 -- p_init_msg_list IN VARCHAR2 Default = FND_API.G_FALSE
365 -- p_commit IN VARCHAR2 Default = FND_API.G_FALSE
366 -- p_ship_header_id IN NUMBER
367 -- p_pending_matching_flag IN VARCHAR2
368 -- p_organization_id IN NUMBER
369 --
370 -- OUT x_return_status OUT NOCOPY VARCHAR2
371 -- x_msg_count OUT NOCOPY NUMBER
372 -- x_msg_data OUT NOCOPY VARCHAR2
373 --
374 -- Version : Current version 1.0
375 --
376 -- Notes :
377 PROCEDURE Complete_Shipment (p_api_version IN NUMBER,
378 p_init_msg_list IN VARCHAR2 := FND_API.G_FALSE,
379 p_commit IN VARCHAR2 := FND_API.G_FALSE,
380 p_ship_header_id IN NUMBER,
381 p_pending_matching_flag IN VARCHAR2,
382 p_organization_id IN NUMBER,
383 x_return_status OUT NOCOPY VARCHAR2,
384 x_msg_count OUT NOCOPY NUMBER,
385 x_msg_data OUT NOCOPY VARCHAR2)
386 IS
387
388 l_api_name CONSTANT VARCHAR2 (30) := 'Complete_Shipment';
389 l_api_version CONSTANT NUMBER := 1.0;
390
391 l_msg_count NUMBER;
392 l_msg_data VARCHAR2 (2000);
393 l_ship_status VARCHAR2 (30) ;
394 l_exist_status NUMBER := 0;
395 l_return_status VARCHAR2 (1) ;
396 l_debug_info VARCHAR2 (200) ;
397
398 l_errbuf VARCHAR2 (240) ;
399 l_retcode NUMBER;
400 l_pre_receive VARCHAR2 (1);
401
402 BEGIN
403 INL_LOGGING_PVT.Log_BeginProc ( p_module_name => g_module_name,
404 p_procedure_name => l_api_name) ;
405 -- Standard Start of API savepoint
406 SAVEPOINT Complete_Shipment_PVT;
407 -- Initialize message list if p_init_msg_list is set to TRUE.
408 IF FND_API.to_Boolean (p_init_msg_list) THEN
409 FND_MSG_PUB.initialize;
410 END IF;
411 -- Check for call compatibility.
412 IF NOT FND_API.Compatible_API_Call ( p_current_version_number => l_api_version,
413 p_caller_version_number => p_api_version,
414 p_api_name => l_api_name,
415 p_pkg_name => G_PKG_NAME) THEN
416 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
417 END IF;
418
419 -- Initialize API return status to success
420 x_return_status := FND_API.G_RET_STS_SUCCESS;
421
422 -------------------------------------------------
423 -- Required steps only for NOT Pending Shipments
424 -------------------------------------------------
425 IF NVL (p_pending_matching_flag, 'N') = 'N' THEN
426 -- Check which scenario is setup in RCV
427 -- Parameters for the current Inventory Organization
428 SELECT pre_receive
429 INTO l_pre_receive
430 FROM rcv_parameters
431 WHERE organization_id = p_organization_id;
432
433 -- Pre-Receive scenario
434 IF (NVL (l_pre_receive, 'N') = 'Y') THEN
435 l_debug_info := 'Call INL_INTEGRATION_GRP.Export_toRCV';
436 INL_LOGGING_PVT.Log_Statement (
437 p_module_name => g_module_name,
438 p_procedure_name => l_api_name,
439 p_debug_info => l_debug_info
440 ) ;
441
442 -- Run integration procedure to transport LCM to RCV
443 INL_INTEGRATION_GRP.Export_toRCV (p_api_version => l_api_version,
444 p_init_msg_list => FND_API.G_FALSE,
445 p_commit => FND_API.G_FALSE,
446 p_ship_header_id => p_ship_header_id,
447 x_return_status => l_return_status,
448 x_msg_count => l_msg_count,
449 x_msg_data => l_msg_data);
450
451 -- If any errors happen abort the process.
452 IF l_return_status = FND_API.G_RET_STS_ERROR THEN
453 RAISE FND_API.G_EXC_ERROR;
454 ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
455 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
456 END IF;
457
458 -- Blackbox scenario
459 ELSIF (NVL (l_pre_receive, 'N') = 'N') THEN
460
461 l_debug_info := 'Call INL_INTEGRATION_GRP.Call_StampLC';
462 INL_LOGGING_PVT.Log_Statement (
463 p_module_name => g_module_name,
464 p_procedure_name => l_api_name,
465 p_debug_info => l_debug_info
466 ) ;
467
468 INL_INTEGRATION_GRP.Call_StampLC (p_api_version => l_api_version,
469 p_init_msg_list => FND_API.G_FALSE,
470 p_commit => FND_API.G_FALSE,
471 p_ship_header_id => p_ship_header_id,
472 x_return_status => l_return_status,
473 x_msg_count => l_msg_count,
474 x_msg_data => l_msg_data);
475
476 -- If any errors happen abort the process.
477 IF l_return_status = FND_API.G_RET_STS_ERROR THEN
478 RAISE FND_API.G_EXC_ERROR;
479 ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
480 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
481 END IF;
482 END IF;
483
484 ----------------------------------------------
485 -- Required step only for Pending Shipments
486 ----------------------------------------------
487 ELSIF NVL (p_pending_matching_flag, 'N') = 'Y' THEN
488 -- Run Create Costing Interfaces
489 l_debug_info := 'Run INL_INTEGRATION_GRP.Export_ToCST';
490 INL_LOGGING_PVT.Log_Statement (
491 p_module_name => g_module_name,
492 p_procedure_name => l_api_name,
493 p_debug_info => l_debug_info
494 ) ;
495
496 INL_INTEGRATION_GRP.Export_ToCST (p_api_version => 1.0,
497 p_init_msg_list => FND_API.G_FALSE,
498 p_commit => FND_API.G_FALSE,
499 p_ship_header_id => p_ship_header_id,
500 x_return_status => l_return_status,
501 x_msg_count => l_msg_count,
502 x_msg_data => l_msg_data) ;
503
504 -- If any errors happen abort the process.
505 IF l_return_status = FND_API.G_RET_STS_ERROR THEN
506 RAISE FND_API.G_EXC_ERROR;
507 ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
508 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
509 END IF;
510 END IF;
511
512 l_debug_info := 'Update the current INL_SHIP_HEADERS_ALL.ship_status_code to COMPLETED';
513 INL_LOGGING_PVT.Log_Statement (
514 p_module_name => g_module_name,
515 p_procedure_name => l_api_name,
516 p_debug_info => l_debug_info
517 ) ;
518
519 UPDATE inl_ship_headers
520 SET ship_status_code = 'COMPLETED',
521 last_updated_by = fnd_global.user_id,
522 last_update_date = SYSDATE
523 WHERE ship_header_id = p_ship_header_id;
524
525 -- Standard check of p_commit.
526 IF FND_API.To_Boolean (p_commit) THEN
527 COMMIT WORK;
528 END IF;
529 -- Standard call to get message count and if count is 1, get message info.
530 FND_MSG_PUB.Count_And_Get ( p_encoded => FND_API.g_false,
531 p_count => x_msg_count,
532 p_data => x_msg_data) ;
533 INL_LOGGING_PVT.Log_EndProc ( p_module_name => g_module_name,
534 p_procedure_name => l_api_name) ;
535 EXCEPTION
536 WHEN FND_API.G_EXC_ERROR THEN
537 INL_LOGGING_PVT.Log_ExpecError ( p_module_name => g_module_name,
538 p_procedure_name => l_api_name) ;
539 ROLLBACK TO Complete_Shipment_PVT;
540 x_return_status := FND_API.G_RET_STS_ERROR;
541 FND_MSG_PUB.Count_And_Get ( p_encoded => FND_API.g_false,
542 p_count => x_msg_count,
543 p_data => x_msg_data) ;
544 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
545 INL_LOGGING_PVT.Log_UnexpecError ( p_module_name => g_module_name,
546 p_procedure_name => l_api_name) ;
547 ROLLBACK TO Complete_Shipment_PVT;
548 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
549 FND_MSG_PUB.Count_And_Get ( p_encoded => FND_API.g_false,
550 p_count => x_msg_count,
551 p_data => x_msg_data) ;
552 WHEN OTHERS THEN
553 INL_LOGGING_PVT.Log_UnexpecError ( p_module_name => g_module_name,
554 p_procedure_name => l_api_name) ;
555 ROLLBACK TO Complete_Shipment_PVT;
556 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
557 IF FND_MSG_PUB.Check_Msg_Level (p_message_level => FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
558 FND_MSG_PUB.Add_Exc_Msg ( p_pkg_name => g_pkg_name,
559 p_procedure_name => l_api_name) ;
560 END IF;
561 FND_MSG_PUB.Count_And_Get ( p_encoded => FND_API.g_false,
562 p_count => x_msg_count,
563 p_data => x_msg_data) ;
564 END Complete_Shipment;
565
566 -- Utility name : Delete_Allocations
567 -- Type : Private
568 -- Function : Delete allocations from the previous landed cost calculation.
569 -- Pre-reqs : None
570 -- Parameters :
571 -- IN : p_ship_header_id IN NUMBER
572 -- OUT x_return_status OUT NOCOPY VARCHAR2
573 --
574 -- Version : Current version 1.0
575 --
576 -- Notes :
577 PROCEDURE Delete_Allocations
578 (
579 p_ship_header_id IN NUMBER,
580 x_return_status OUT NOCOPY VARCHAR2)
581 IS
582 l_proc_name CONSTANT VARCHAR2 (100) := 'Delete_Allocations ';
583 l_debug_info VARCHAR2 (200) ;
584 BEGIN
585 -- Verify if there is allocation for Shipment
586 DELETE
587 FROM inl_allocations cfa
588 WHERE cfa.ship_header_id = p_ship_header_id
589 AND NOT EXISTS
590 (
591 SELECT 'x'
592 FROM inl_allocations al1
593 WHERE al1.ship_header_id = cfa.ship_header_id
594 AND al1.adjustment_num > 0
595 AND ROWNUM < 2
596 ) ;
597
598 l_debug_info := 'deleted '||sql%ROWCOUNT||' allocations rows ';
599 INL_LOGGING_PVT.Log_Statement (
600 p_module_name => g_module_name,
601 p_procedure_name => l_proc_name,
602 p_debug_info => l_debug_info
603 ) ;
604
605 EXCEPTION
606 WHEN FND_API.G_EXC_ERROR THEN
607 x_return_status := FND_API.G_RET_STS_ERROR;
608 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
609 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
610 WHEN OTHERS THEN
611 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
612 IF FND_MSG_PUB.Check_Msg_Level (p_message_level => FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
613 FND_MSG_PUB.Add_Exc_Msg ( p_pkg_name => g_pkg_name,
614 p_procedure_name => l_proc_name) ;
615 END IF;
616 END Delete_Allocations;
617 -- API name : Set_ToRevalidate
618 -- Type : Private
619 -- Function : Set a given LCM Shipment to "Validation Required" status.
620 -- Pre-reqs : None
621 -- Parameters :
622 -- IN : p_api_version IN NUMBER Required
623 -- p_init_msg_list IN VARCHAR2 Optional Default = FND_API.G_FALSE
624 -- p_commit IN VARCHAR2 Optional Default = FND_API.G_FALSE
625 -- p_ship_header_id IN NUMBER Required
626 -- OUT x_msg_count OUT NOCOPY NUMBER
627 -- x_msg_data OUT NOCOPY VARCHAR2
628 -- x_return_status OUT NOCOPY VARCHAR2
629 --
630 -- Version : Current version 1.0
631 --
632 -- Notes :
633 PROCEDURE Set_ToRevalidate
634 (
635 p_api_version IN NUMBER,
636 p_init_msg_list IN VARCHAR2 := FND_API.G_FALSE,
637 p_commit IN VARCHAR2 := FND_API.G_FALSE,
638 p_ship_header_id IN NUMBER,
639 x_msg_count OUT NOCOPY NUMBER,
640 x_msg_data OUT NOCOPY VARCHAR2,
641 x_return_status OUT NOCOPY VARCHAR2)
642 IS
643 l_ship_status VARCHAR2 (30) ;
644 l_api_name CONSTANT VARCHAR2 (100) := 'Set_ToRevalidate';
645 l_api_version CONSTANT NUMBER := 1.0;
646 l_exist_event VARCHAR2 (5) ;
647 l_msg_data VARCHAR2 (200) ;
648 l_msg_count NUMBER;
649 l_return_status VARCHAR2 (1) ;
650 l_exist_status NUMBER := 0;
651 l_exist_calc NUMBER := 0;
652 l_debug_info VARCHAR2 (200) ;
653 BEGIN
654 INL_LOGGING_PVT.Log_BeginProc ( p_module_name => g_module_name,
655 p_procedure_name => l_api_name) ;
656 -- Standard Start of API savepoint
657 SAVEPOINT Set_ToRevalidate_PVT;
658 -- Initialize message list if p_init_msg_list is set to TRUE.
659 IF FND_API.to_Boolean (p_init_msg_list) THEN
660 FND_MSG_PUB.initialize;
661 END IF;
662 -- Check for call compatibility.
663 IF NOT FND_API.Compatible_API_Call ( p_current_version_number => l_api_version,
664 p_caller_version_number => p_api_version,
665 p_api_name => l_api_name,
666 p_pkg_name => G_PKG_NAME) THEN
667 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
668 END IF;
669 -- Initialize API return status to success
670 x_return_status := FND_API.G_RET_STS_SUCCESS;
671
672 SELECT sh.ship_status_code
673 INTO l_ship_status
674 FROM inl_ship_headers sh
675 WHERE sh.ship_header_id = p_ship_header_id;
676
677 INL_LOGGING_PVT.Log_Variable ( p_module_name => g_module_name,
678 p_procedure_name => l_api_name,
679 p_var_name => 'current Shipment status',
680 p_var_value => l_ship_status) ;
681 IF (l_ship_status = 'VALIDATED' OR l_ship_status = 'ON HOLD') THEN
682 Delete_Allocations (p_ship_header_id, l_return_status) ;
683 -- If any errors happen abort API.
684 IF l_return_status = FND_API.G_RET_STS_ERROR THEN
685 RAISE FND_API.G_EXC_ERROR;
686 ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
687 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
688 END IF;
689 -- Update Shipment status to VALIDATION REQ
690 UPDATE inl_ship_headers
691 SET ship_status_code = 'VALIDATION REQ'
692 WHERE ship_header_id = p_ship_header_id;
693 END IF;
694 -- Standard check of p_commit.
695 IF FND_API.To_Boolean (p_commit) THEN
696 COMMIT WORK;
697 END IF;
698 -- Standard call to get message count and if count is 1, get message info.
699 FND_MSG_PUB.Count_And_Get ( p_encoded => FND_API.g_false,
700 p_count => x_msg_count,
701 p_data => x_msg_data) ;
702 INL_LOGGING_PVT.Log_EndProc ( p_module_name => g_module_name,
703 p_procedure_name => l_api_name) ;
704 EXCEPTION
705 WHEN FND_API.G_EXC_ERROR THEN
706 l_debug_info := 'MSG: '||SQLERRM;
707 INL_LOGGING_PVT.Log_Statement (
708 p_module_name => g_module_name,
709 p_procedure_name => l_api_name,
710 p_debug_info => l_debug_info
711 ) ;
712
713 INL_LOGGING_PVT.Log_ExpecError ( p_module_name => g_module_name,
714 p_procedure_name => l_api_name) ;
715 ROLLBACK TO Set_ToRevalidate_PVT;
716 x_return_status := FND_API.G_RET_STS_ERROR;
717 FND_MSG_PUB.Count_And_Get ( p_encoded => FND_API.g_false,
718 p_count => x_msg_count,
719 p_data => x_msg_data) ;
720 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
721 l_debug_info := 'MSG: '||SQLERRM;
722 INL_LOGGING_PVT.Log_Statement (
723 p_module_name => g_module_name,
724 p_procedure_name => l_api_name,
725 p_debug_info => l_debug_info
726 ) ;
727
728 INL_LOGGING_PVT.Log_UnexpecError ( p_module_name => g_module_name,
729 p_procedure_name => l_api_name) ;
730 ROLLBACK TO Set_ToRevalidate_PVT;
731 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
732 FND_MSG_PUB.Count_And_Get ( p_encoded => FND_API.g_false,
733 p_count => x_msg_count,
734 p_data => x_msg_data) ;
735 WHEN OTHERS THEN
736 l_debug_info := 'MSG: '||SQLERRM;
737 INL_LOGGING_PVT.Log_Statement (
738 p_module_name => g_module_name,
739 p_procedure_name => l_api_name,
740 p_debug_info => l_debug_info
741 ) ;
742
743 INL_LOGGING_PVT.Log_UnexpecError ( p_module_name => g_module_name,
744 p_procedure_name => l_api_name) ;
745 ROLLBACK TO Set_ToRevalidate_PVT;
746 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
747 IF FND_MSG_PUB.Check_Msg_Level (p_message_level => FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
748 FND_MSG_PUB.Add_Exc_Msg ( p_pkg_name => g_pkg_name,
749 p_procedure_name => l_api_name) ;
750 END IF;
751 FND_MSG_PUB.Count_And_Get ( p_encoded => FND_API.g_false,
752 p_count => x_msg_count,
753 p_data => x_msg_data) ;
754 END Set_ToRevalidate;
755 -- Utility name : Has_ShipLine
756 -- Type : Private
757 -- Function : Checks if an LCM Shipment contains Shipment Lines
758 -- Pre-reqs : None
759 -- Parameters :
760 -- IN : p_ship_header_id IN NUMBER
761 --
762 -- Version : Current version 1.0
763 --
764 -- Notes :
765 FUNCTION Has_ShipLine
766 (
767 p_ship_header_id IN NUMBER)
768 RETURN BOOLEAN
769 IS
770 l_proc_name CONSTANT VARCHAR2 (30) := 'Has_ShipLine';
771 ac_lin NUMBER;
772 l_debug_info VARCHAR2 (200) ;
773 BEGIN
774 INL_LOGGING_PVT.Log_BeginProc ( p_module_name => g_module_name,
775 p_procedure_name => l_proc_name) ;
776 SELECT COUNT ( *)
777 INTO ac_lin
778 FROM inl_adj_ship_lines_v ol
779 WHERE ol.ship_header_id = p_ship_header_id
780 AND ROWNUM < 2;
781
782 INL_LOGGING_PVT.Log_EndProc ( p_module_name => g_module_name,
783 p_procedure_name => l_proc_name) ;
784 IF NVL (ac_lin, 0) > 0 THEN
785 RETURN TRUE;
786 ELSE
787 RETURN FALSE;
788 END IF;
789 END Has_ShipLine;
790
791 -- Utl name : Get_ShipHeadNum
792 -- Type : Private
793 -- Function : Get Shipment Number
794 -- Pre-reqs : None
795 -- Parameters :
796 -- IN : p_ship_header_id IN NUMBER
797 --
798 -- Version : Current version 1.0
799 --
800 -- Notes :
801 FUNCTION Get_ShipHeadNum
802 (
803 p_ship_header_id IN NUMBER)
804 RETURN VARCHAR2
805 IS
806 l_proc_name CONSTANT VARCHAR2 (30) := 'Get_ShipHeadNum';
807 l_ship_header_num VARCHAR2 (25) ;
808 l_debug_info VARCHAR2 (200) ;
809 BEGIN
810 INL_LOGGING_PVT.Log_BeginProc ( p_module_name => g_module_name,
811 p_procedure_name => l_proc_name) ;
812 BEGIN
813 SELECT ship_num
814 INTO l_ship_header_num
815 FROM inl_ship_headers
816 WHERE ship_header_id = p_ship_header_id;
817 EXCEPTION
818 WHEN NO_DATA_FOUND THEN
819 RETURN '';
820 END;
821 INL_LOGGING_PVT.Log_EndProc ( p_module_name => g_module_name,
822 p_procedure_name => l_proc_name) ;
823 RETURN l_ship_header_num;
824 END Get_ShipHeadNum;
825
826 -- Utl name : Get_ShipLineNum
827 -- Type : Private
828 -- Function : Get Shipment Line Number
829 -- Pre-reqs : None
830 -- Parameters :
831 -- IN : p_ship_line_id IN NUMBER
832 --
833 -- Version : Current version 1.0
834 --
835 -- Notes :
836 FUNCTION Get_ShipLineNum
837 (
838 p_ship_line_id IN NUMBER)
839 RETURN VARCHAR2
840 IS
841 l_proc_name CONSTANT VARCHAR2 (30) := 'Get_ShipLineNum';
842 l_ship_line_num VARCHAR2 (25) ;
843 l_debug_info VARCHAR2 (200) ;
844 BEGIN
845 INL_LOGGING_PVT.Log_BeginProc ( p_module_name => g_module_name,
846 p_procedure_name => l_proc_name) ;
847 BEGIN
848 SELECT ship_line_num
849 INTO l_ship_line_num
850 FROM inl_adj_ship_lines_v
851 WHERE NVL (parent_ship_line_id, ship_line_id) = p_ship_line_id;
852 EXCEPTION
853 WHEN NO_DATA_FOUND THEN
854 RETURN '';
855 END;
856 INL_LOGGING_PVT.Log_EndProc ( p_module_name => g_module_name,
857 p_procedure_name => l_proc_name) ;
858 RETURN TO_CHAR (l_ship_line_num) ;
859 END Get_ShipLineNum;
860
861 -- API name : Get_AvailableQty
862 -- Type : Private
863 -- Function : Encapsulate the logic to call RCV routines and return the Available and Tolerable quantities.
864 -- Pre-reqs : None
865 -- Parameters :
866 -- IN : p_api_version IN NUMBER Required
867 -- p_init_msg_list IN VARCHAR2 Optional Default = FND_API.G_FALSE
868 -- p_commit IN VARCHAR2 Optional Default = FND_API.G_FALSE
869 -- p_ship_line_src_code IN VARCHAR2
870 -- p_parent_id IN NUMBER
871 -- p_available_quantity IN OUT NOCOPY NUMBER
872 -- p_tolerable_quantity IN OUT NOCOPY NUMBER
873 -- p_unit_of_measure IN OUT NOCOPY VARCHAR2
874 -- OUT x_return_status OUT NOCOPY VARCHAR2
875 -- x_msg_count OUT NOCOPY NUMBER
876 -- x_msg_data OUT NOCOPY VARCHAR2
877 --
878 -- Version : Current version 1.0
879 --
880 -- Notes :
881 PROCEDURE Get_AvailableQty(p_api_version IN NUMBER,
882 p_init_msg_list IN VARCHAR2 := FND_API.G_FALSE,
883 p_commit IN VARCHAR2 := FND_API.G_FALSE,
884 p_ship_line_src_code IN VARCHAR2,
885 p_parent_id IN NUMBER,
886 p_available_quantity IN OUT NOCOPY NUMBER,
887 p_tolerable_quantity IN OUT NOCOPY NUMBER,
888 p_unit_of_measure IN OUT NOCOPY VARCHAR2,
889 x_return_status OUT NOCOPY VARCHAR2,
890 x_msg_count OUT NOCOPY NUMBER,
891 x_msg_data OUT NOCOPY VARCHAR2)
892 IS
893 CURSOR c_rcv_shipmt_lines IS
894 SELECT rsl.shipment_line_id,
895 rsl.item_id,
896 pll.unit_meas_lookup_code
897 FROM rcv_shipment_lines rsl,
898 po_line_locations_all pll
899 WHERE rsl.lcm_shipment_line_id IS NOT NULL
900 AND pll.line_location_id = rsl.po_line_location_id
901 AND rsl.po_line_location_id = p_parent_id
902 AND NOT EXISTS(SELECT 1
903 FROM rcv_transactions_interface rti
904 WHERE rti.shipment_line_id = rsl.shipment_line_id);
905
906 l_rcv_shipmt_lines c_rcv_shipmt_lines%ROWTYPE;
907
908 l_api_name CONSTANT VARCHAR2(30) := 'Get_AvailableQty';
909 l_api_version CONSTANT NUMBER := 1.0;
910 l_return_status VARCHAR2(1) ;
911 l_msg_count NUMBER;
912 l_msg_data VARCHAR2(2000);
913 l_debug_info VARCHAR2(200);
914
915 l_transaction_type VARCHAR2(100);
916 l_receipt_source_code VARCHAR2(100);
917 l_quantity_rsl NUMBER;
918 l_tolerable_quantity_rsl NUMBER;
919 l_secondary_available_qty_rsl NUMBER;
920 l_unit_of_measure_rsl VARCHAR2(30);
921 l_converted_qty_rsl NUMBER;
922 l_total_quantity_rsl NUMBER := 0;
923
924 BEGIN
925 -- Standard Beginning of Procedure/Function Logging
926 INL_LOGGING_PVT.Log_BeginProc ( p_module_name => g_module_name,
927 p_procedure_name => l_api_name) ;
928 -- Initialize message list if p_init_msg_list is set to TRUE.
929 IF FND_API.to_Boolean (p_init_msg_list) THEN
930 FND_MSG_PUB.initialize;
931 END IF;
932 -- Check for call compatibility.
933 IF NOT FND_API.Compatible_API_Call (l_api_version,
934 p_api_version,
935 l_api_name,
936 G_PKG_NAME) THEN
937 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
938 END IF;
939 -- Initialize API return status to success
940 x_return_status := FND_API.G_RET_STS_SUCCESS;
941
942 -- Define the transaction type and receipt source code
943 -- based the current Shipment Line Source Code.
944 IF p_ship_line_src_code = 'PO' THEN
945 l_transaction_type := 'RECEIVE';
946 l_receipt_source_code := 'VENDOR';
947 ELSIF p_ship_line_src_code = 'IR' THEN
948 l_transaction_type := 'RECEIVE';
949 l_receipt_source_code := 'INTERNAL ORDER';
950 ELSIF p_ship_line_src_code = 'RMA' THEN
951 l_transaction_type := 'RECEIVE';
952 l_receipt_source_code := 'CUSTOMER';
953 END IF;
954
955 -- Logging variables
956 INL_LOGGING_PVT.Log_Variable ( p_module_name => g_module_name,
957 p_procedure_name => l_api_name,
958 p_var_name => 'l_transaction_type',
959 p_var_value => l_transaction_type) ;
960 INL_LOGGING_PVT.Log_Variable ( p_module_name => g_module_name,
961 p_procedure_name => l_api_name,
962 p_var_name => 'l_receipt_source_code',
963 p_var_value => l_receipt_source_code) ;
964
965 l_debug_info := 'Call RCV_QUANTITIES_S.get_available_quantity - PLL';
966 INL_LOGGING_PVT.Log_Statement (p_module_name => g_module_name,
967 p_procedure_name => l_api_name,
968 p_debug_info => l_debug_info);
969
970 -- This call will return the available qty not considering qty on RSL.
971 RCV_QUANTITIES_S.get_available_quantity ( p_transaction_type => l_transaction_type,
972 p_parent_id => p_parent_id,
973 p_receipt_source_code => l_receipt_source_code,
974 p_parent_transaction_type => NULL,
975 p_grand_parent_id => NULL,
976 p_correction_type => NULL,
977 p_available_quantity => p_available_quantity,
978 p_tolerable_quantity => p_tolerable_quantity,
979 p_unit_of_measure => p_unit_of_measure);
980
981 -- Logging variables
982 INL_LOGGING_PVT.Log_Variable (p_module_name => g_module_name,
983 p_procedure_name => l_api_name,
984 p_var_name => 'p_available_quantity',
985 p_var_value => p_available_quantity);
986 INL_LOGGING_PVT.Log_Variable (p_module_name => g_module_name,
987 p_procedure_name => l_api_name,
988 p_var_name => 'p_tolerable_quantity',
989 p_var_value => p_tolerable_quantity);
990
991 -- Iterate through all RCV Shipment Lines based on a given PLL.
992 FOR l_rcv_shipmt_lines IN c_rcv_shipmt_lines
993 LOOP
994 l_debug_info := 'Call RCV_QUANTITIES_S.get_available_quantity - RSL';
995 INL_LOGGING_PVT.Log_Statement (p_module_name => g_module_name,
996 p_procedure_name => l_api_name,
997 p_debug_info => l_debug_info);
998
999 -- This call will return the quantity on RSL that should be deducted from the available quantity.
1000 RCV_QUANTITIES_S.get_available_quantity(p_transaction_type => 'RECEIVE',
1001 p_parent_id => l_rcv_shipmt_lines.shipment_line_id,
1002 p_receipt_source_code => 'INVENTORY',
1003 p_parent_transaction_type => NULL,
1004 p_grand_parent_id => NULL,
1005 p_correction_type => NULL,
1006 p_available_quantity => l_quantity_rsl,
1007 p_tolerable_quantity => l_tolerable_quantity_rsl,
1008 p_unit_of_measure => l_unit_of_measure_rsl,
1009 p_secondary_available_qty => l_secondary_available_qty_rsl);
1010
1011 -- Necessary convertion so that the available quantity can be calculated in the PO UOM.
1012 PO_UOM_S.uom_convert(l_quantity_rsl,
1013 l_unit_of_measure_rsl,
1014 l_rcv_shipmt_lines.item_id,
1015 l_rcv_shipmt_lines.unit_meas_lookup_code,
1016 l_converted_qty_rsl);
1017
1018 l_total_quantity_rsl := l_total_quantity_rsl + NVL(l_converted_qty_rsl,0);
1019 END LOOP;
1020
1021 -- Deduct from the current available qty the converted qty from RSL
1022 p_available_quantity := NVL(p_available_quantity,0) - l_total_quantity_rsl;
1023
1024 -- Deduct from the current tolerance the converted qty from RSL
1025 p_tolerable_quantity := NVL(p_tolerable_quantity,0) - l_total_quantity_rsl;
1026
1027 -- Just to prevent negative if this shipment has been over received. In this
1028 -- case, the available/tolerable quantities that needs to be passed back should be 0.
1029 IF p_available_quantity < 0 THEN
1030 p_available_quantity := 0;
1031 END IF;
1032
1033 IF p_tolerable_quantity < 0 THEN
1034 p_tolerable_quantity := 0;
1035 END IF;
1036
1037 INL_LOGGING_PVT.Log_Variable (p_module_name => g_module_name,
1038 p_procedure_name => l_api_name,
1039 p_var_name => 'p_available_quantity',
1040 p_var_value => p_available_quantity);
1041 INL_LOGGING_PVT.Log_Variable (p_module_name => g_module_name,
1042 p_procedure_name => l_api_name,
1043 p_var_name => 'p_tolerable_quantity',
1044 p_var_value => p_tolerable_quantity);
1045 INL_LOGGING_PVT.Log_Variable ( p_module_name => g_module_name,
1046 p_procedure_name => l_api_name,
1047 p_var_name => 'p_unit_of_measure',
1048 p_var_value => p_unit_of_measure) ;
1049
1050 -- Standard check of p_commit.
1051 IF FND_API.To_Boolean (p_commit) THEN
1052 COMMIT WORK;
1053 END IF;
1054
1055 -- Standard call to get message count and if count is 1, get message info.
1056 FND_MSG_PUB.Count_And_Get ( p_encoded => FND_API.g_false,
1057 p_count => x_msg_count,
1058 p_data => x_msg_data) ;
1059
1060 -- Standard End of Procedure/Function Logging
1061 INL_LOGGING_PVT.Log_EndProc ( p_module_name => g_module_name,
1062 p_procedure_name => l_api_name) ;
1063 EXCEPTION
1064 WHEN FND_API.G_EXC_ERROR THEN
1065 -- Standard Expected Error Logging
1066 INL_LOGGING_PVT.Log_ExpecError ( p_module_name => g_module_name,
1067 p_procedure_name => l_api_name) ;
1068 x_return_status := FND_API.G_RET_STS_ERROR;
1069 FND_MSG_PUB.Count_And_Get ( p_encoded => FND_API.g_false,
1070 p_count => x_msg_count,
1071 p_data => x_msg_data) ;
1072 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1073 -- Standard Unexpected Error Logging
1074 INL_LOGGING_PVT.Log_UnexpecError ( p_module_name => g_module_name,
1075 p_procedure_name => l_api_name) ;
1076 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1077 FND_MSG_PUB.Count_And_Get ( p_encoded => FND_API.g_false,
1078 p_count => x_msg_count,
1079 p_data => x_msg_data) ;
1080 WHEN OTHERS THEN
1081 -- Standard Unexpected Error Logging
1082 INL_LOGGING_PVT.Log_UnexpecError ( p_module_name => g_module_name,
1083 p_procedure_name => l_api_name) ;
1084 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
1085 IF FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
1086 FND_MSG_PUB.Add_Exc_Msg ( p_pkg_name => g_pkg_name,
1087 p_procedure_name => l_api_name) ;
1088 END IF;
1089 FND_MSG_PUB.Count_And_Get ( p_encoded => FND_API.g_false,
1090 p_count => x_msg_count,
1091 p_data => x_msg_data) ;
1092 END Get_AvailableQty;
1093
1094 -- Utility name : Check_AvailableQty
1095 -- Type : Private
1096 -- Function : Check whether Shipment Line Qty is compliant with the PO available Qty
1097 -- Pre-reqs : None
1098 -- Parameters :
1099 -- IN : p_primary_qty IN NUMBER
1100 -- p_sum_primary_qty IN NUMBER
1101 -- p_primary_uom_code IN VARCHAR2
1102 -- p_inventory_item_id IN NUMBER
1103 -- p_inv_org_id IN NUMBER
1104 -- p_ship_line_id IN NUMBER
1105 -- p_ship_line_num IN NUMBER
1106 -- p_ship_line_src_type_code IN VARCHAR2
1107 -- p_ship_line_src_id IN NUMBER
1108 -- p_same_shiph_id IN NUMBER
1109 -- p_ship_header_id IN NUMBER
1110 -- OUT x_return_status OUT NOCOPY VARCHAR2
1111 --
1112 -- Version : Current version 1.0
1113 --
1114 -- Notes :
1115 PROCEDURE Check_AvailableQty(p_primary_qty IN NUMBER,
1116 p_sum_primary_qty IN NUMBER,
1117 p_primary_uom_code IN VARCHAR2,
1118 p_inventory_item_id IN NUMBER,
1119 p_inv_org_id IN NUMBER,
1120 p_ship_line_id IN NUMBER,
1121 p_ship_line_num IN NUMBER,
1122 p_ship_line_src_type_code IN VARCHAR2,
1123 p_ship_line_src_id IN NUMBER,
1124 p_same_shiph_id IN NUMBER,
1125 p_ship_header_id IN NUMBER,
1126 x_return_status OUT NOCOPY VARCHAR2)
1127 IS
1128 l_proc_name CONSTANT VARCHAR2(30) := 'Check_AvailableQty';
1129 l_msg VARCHAR2(2000);
1130 l_debug_info VARCHAR2(200);
1131 l_msg_count NUMBER;
1132 l_msg_data VARCHAR2 (2000);
1133 l_acpt_qty VARCHAR2(1);
1134 l_return_status VARCHAR2 (1);
1135 l_error_message_name VARCHAR2(200);
1136 l_shipln_duplicated BOOLEAN := FALSE;
1137 x_uom_code VARCHAR2(3);
1138 x_available_quantity NUMBER;
1139 x_tolerable_quantity NUMBER;
1140 x_unit_of_measure VARCHAR2(100);
1141 x_qty_in_others_ops NUMBER;
1142 l_primary_uom_tl VARCHAR2(30);
1143
1144 BEGIN
1145 -- Standard Beginning of Procedure/Function Logging
1146 INL_LOGGING_PVT.Log_BeginProc (p_module_name => g_module_name,
1147 p_procedure_name => l_proc_name) ;
1148 -- Initialize API return status to success
1149 x_return_status := FND_API.G_RET_STS_SUCCESS;
1150 -- Check if primary qty is ZERO
1151 IF NVL (p_primary_qty, 0) = 0 THEN
1152 FND_MESSAGE.SET_NAME ('INL', 'INL_ERR_CHK_SHIP_LN_QTY_ZERO') ;
1153 FND_MESSAGE.SET_TOKEN ('SHIP_LINE_NUM', p_ship_line_num) ;
1154 FND_MSG_PUB.ADD;
1155 -- INCLUDE A LINE IN INL_SHIP_HOLdS
1156 Handle_ShipError ( p_ship_header_id => p_ship_header_id,
1157 p_ship_line_id => p_ship_line_id,
1158 p_charge_line_id => NULL,
1159 p_table_name => 'INL_SHIP_LINES',
1160 p_column_name => 'PRIMARY_QTY',
1161 p_column_value => 0,
1162 p_error_message => SUBSTR (FND_MSG_PUB.Get (p_msg_index => FND_MSG_PUB.Count_Msg (),
1163 p_encoded => FND_API.g_false), 1, 2000),
1164 p_error_message_name => 'INL_ERR_CHK_SHIP_LN_QTY_ZERO',
1165 p_token1_name => 'SHIP_LINE_NUM',
1166 p_token1_value => p_ship_line_num,
1167 p_token2_name => NULL,
1168 p_token2_value => NULL,
1169 p_token3_name => NULL,
1170 p_token3_value => NULL,
1171 p_token4_name => NULL,
1172 p_token4_value => NULL,
1173 p_token5_name => NULL,
1174 p_token5_value => NULL,
1175 p_token6_name => NULL,
1176 p_token6_value => NULL,
1177 x_return_status => l_return_status) ;
1178 -- If unexpected errors happen abort
1179 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1180 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1181 END IF;
1182 ELSE
1183 l_debug_info := 'INL_SHIPMENT_PVT.Get_AvailableQty';
1184 INL_LOGGING_PVT.Log_Statement ( p_module_name => g_module_name,
1185 p_procedure_name => l_proc_name,
1186 p_debug_info => l_debug_info ) ;
1187
1188 -- Get the PO Avaliable and Tolerable Quantities
1189 INL_SHIPMENT_PVT.Get_AvailableQty(p_api_version => 1.0,
1190 p_init_msg_list => FND_API.G_FALSE,
1191 p_commit => FND_API.G_FALSE,
1192 p_ship_line_src_code => p_ship_line_src_type_code,
1193 p_parent_id => p_ship_line_src_id,
1194 p_available_quantity => x_available_quantity,
1195 p_tolerable_quantity => x_tolerable_quantity,
1196 p_unit_of_measure => x_unit_of_measure,
1197 x_return_status => l_return_status,
1198 x_msg_count => l_msg_count,
1199 x_msg_data => l_msg_data);
1200
1201 INL_LOGGING_PVT.Log_Variable ( p_module_name => g_module_name,
1202 p_procedure_name => l_proc_name,
1203 p_var_name => 'x_available_quantity',
1204 p_var_value => x_available_quantity);
1205 INL_LOGGING_PVT.Log_Variable ( p_module_name => g_module_name,
1206 p_procedure_name => l_proc_name,
1207 p_var_name => l_debug_info,
1208 p_var_value => 'x_tolerable_quantity');
1209 INL_LOGGING_PVT.Log_Variable ( p_module_name => x_tolerable_quantity,
1210 p_procedure_name => l_proc_name,
1211 p_var_name => 'x_unit_of_measure',
1212 p_var_value => x_unit_of_measure);
1213 -- Get the UOM Code
1214 SELECT uom_code
1215 INTO x_uom_code
1216 FROM mtl_units_of_measure
1217 WHERE unit_of_measure = x_unit_of_measure;
1218
1219 INL_LOGGING_PVT.Log_Variable ( p_module_name => g_module_name,
1220 p_procedure_name => l_proc_name,
1221 p_var_name => 'x_uom_code',
1222 p_var_value => x_uom_code) ;
1223 INL_LOGGING_PVT.Log_Variable ( p_module_name => g_module_name,
1224 p_procedure_name => l_proc_name,
1225 p_var_name => 'p_primary_uom_code',
1226 p_var_value => p_primary_uom_code) ;
1227
1228 l_debug_info := 'If necessary, it converts the qty (INL_landedcost_pvt.Converted_Qty).';
1229 INL_LOGGING_PVT.Log_Statement ( p_module_name => g_module_name,
1230 p_procedure_name => l_proc_name,
1231 p_debug_info => l_debug_info ) ;
1232
1233 -- Convert to Primary Qty when Unit of Measure is different
1234 IF x_uom_code <> p_primary_uom_code THEN
1235 x_available_quantity := INL_LANDEDCOST_PVT.converted_qty ( p_organization_id => p_inv_org_id,
1236 p_inventory_item_id => p_inventory_item_id,
1237 p_qty => x_available_quantity,
1238 p_from_uom_code => x_uom_code,
1239 p_to_uom_code => p_primary_uom_code);
1240
1241 x_tolerable_quantity := INL_LANDEDCOST_PVT.converted_qty ( p_organization_id => p_inv_org_id,
1242 p_inventory_item_id => p_inventory_item_id,
1243 p_qty => x_tolerable_quantity,
1244 p_from_uom_code => x_uom_code,
1245 p_to_uom_code => p_primary_uom_code);
1246 END IF;
1247
1248 -- Validate the transaction primary qty with the tolerable qty
1249 IF p_primary_qty > x_tolerable_quantity OR p_sum_primary_qty > x_tolerable_quantity THEN
1250 l_acpt_qty := 'N';
1251 -- Check if the validation message should be handled as
1252 -- a duplicated (two or more lines with the same Line
1253 -- Location Id) or as a single Shipment Line
1254 IF (p_sum_primary_qty > p_primary_qty) THEN
1255 l_shipln_duplicated := TRUE;
1256 END IF;
1257 -- In Receiving (RCV_QUANTITIES_S) the rcv_exception_code is checked FOR POs only.
1258 IF p_ship_line_src_type_code = 'PO' THEN
1259 l_debug_info := 'Verify in po_line_locations_all the Over-Receipt Quantity Control Action';
1260 INL_LOGGING_PVT.Log_Statement (p_module_name => g_module_name,
1261 p_procedure_name => l_proc_name,
1262 p_debug_info => l_debug_info) ;
1263 SELECT DECODE (pll.qty_rcv_exception_code, 'NONE', 'Y', 'N')
1264 INTO l_acpt_qty
1265 FROM po_line_locations pll
1266 WHERE pll.line_location_id = p_ship_line_src_id;
1267 END IF;
1268 IF l_acpt_qty = 'N' THEN
1269 IF (l_shipln_duplicated = TRUE) THEN
1270 FND_MESSAGE.SET_NAME ('INL', 'INL_ERR_CHK_SHIP_LN_QTY_TOL_S') ;
1271 ELSE
1272 FND_MESSAGE.SET_NAME ('INL', 'INL_ERR_CHK_SHIP_LN_QTY_TOL') ;
1273 END IF;
1274
1275 -- Get the Primary Unit of Measure Description that will be
1276 -- used as the token for the over tolerance error message.
1277 SELECT unit_of_measure_tl
1278 INTO l_primary_uom_tl
1279 FROM mtl_units_of_measure_vl
1280 WHERE uom_code = p_primary_uom_code;
1281
1282 FND_MESSAGE.SET_TOKEN ('SHIP_LINE_NUM', p_ship_line_num) ;
1283 FND_MESSAGE.SET_TOKEN ('QTY', x_tolerable_quantity) ;
1284 FND_MESSAGE.SET_TOKEN ('UOM', l_primary_uom_tl) ;
1285 FND_MSG_PUB.ADD;
1286 -- INCLUDE A LINE IN INL_SHIP_HOLdS
1287 Handle_ShipError ( p_ship_header_id => p_ship_header_id,
1288 p_ship_line_id => p_ship_line_id,
1289 p_charge_line_id => NULL,
1290 p_table_name => 'INL_SHIP_LINES',
1291 p_column_name => 'PRIMARY_QTY',
1292 p_column_value => p_primary_qty,
1293 p_error_message => SUBSTR (FND_MSG_PUB.Get (p_msg_index => FND_MSG_PUB.Count_Msg (),
1294 p_encoded => FND_API.g_false), 1, 2000),
1295 p_error_message_name => l_error_message_name,
1296 p_token1_name => 'SHIP_LINE_NUM',
1297 p_token1_value => p_ship_line_num,
1298 p_token2_name => 'QTY',
1299 p_token2_value => x_tolerable_quantity,
1300 p_token3_name => 'UOM',
1301 p_token3_value => x_unit_of_measure,
1302 p_token4_name => NULL,
1303 p_token4_value => NULL,
1304 p_token5_name => NULL,
1305 p_token5_value => NULL,
1306 p_token6_name => NULL,
1307 p_token6_value => NULL,
1308 x_return_status => l_return_status) ;
1309 -- If unexpected errors happen abort
1310 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1311 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1312 END IF;
1313 END IF;
1314 ELSE
1315 -- Search for other Shipment lines in Validated Shipments
1316 -- with receipts for the same receipt_source_code and src_id
1317 SELECT NVL (SUM (sl.primary_qty), 0)
1318 INTO x_qty_in_others_ops
1319 FROM inl_ship_headers sh,
1320 inl_adj_ship_lines_v sl
1321 WHERE sl.ship_header_id = sh.ship_header_id
1322 AND NVL (sl.parent_ship_line_id, sl.ship_line_id) <> p_ship_line_id
1323 AND
1324 (
1325 sh.ship_status_code = 'VALIDATED'
1326 OR sh.ship_header_id = NVL (p_same_shiph_id, 9999999999)
1327 )
1328 AND sl.ship_line_src_type_code = p_ship_line_src_type_code
1329 AND sl.ship_line_source_id = p_ship_line_src_id;
1330
1331 INL_LOGGING_PVT.Log_Variable ( p_module_name => g_module_name,
1332 p_procedure_name => l_proc_name,
1333 p_var_name => 'x_qty_in_others_ops',
1334 p_var_value => x_qty_in_others_ops) ;
1335 IF x_qty_in_others_ops + p_primary_qty > x_tolerable_quantity THEN
1336 l_debug_info := 'x_qty_in_others_ops + p_primary_qty > x_tolerable_quantity';
1337 INL_LOGGING_PVT.Log_Statement ( p_module_name => g_module_name,
1338 p_procedure_name => l_proc_name,
1339 p_debug_info => l_debug_info) ;
1340 FOR c_ship_num IN
1341 (
1342 SELECT DISTINCT sh.ship_num
1343 FROM inl_ship_headers sh,
1344 inl_adj_ship_lines_v sl
1345 WHERE sl.ship_header_id = sh.ship_header_id
1346 AND NVL (sl.parent_ship_line_id, sl.ship_line_id) <> p_ship_line_id
1347 AND
1348 (
1349 sh.ship_status_code = 'VALIDATED'
1350 OR sh.ship_header_id = NVL (p_same_shiph_id, 9999999999)
1351 )
1352 AND sl.ship_line_src_type_code = p_ship_line_src_type_code
1353 AND sl. ship_line_source_id = p_ship_line_src_id
1354 ORDER BY sh.ship_num
1355 )
1356 LOOP
1357 l_msg := ', '||c_ship_num.ship_num;
1358 END LOOP;
1359 FND_MESSAGE.SET_NAME ('INL', 'INL_ERR_CHK_SHIP_LN_QTY_OTH_L') ;
1360 FND_MESSAGE.SET_TOKEN ('SRC_TYPE', p_ship_line_src_type_code) ;
1361 FND_MESSAGE.SET_TOKEN ('QTY', x_tolerable_quantity) ;
1362 FND_MESSAGE.SET_TOKEN ('UOM', x_unit_of_measure) ;
1363 FND_MESSAGE.SET_TOKEN ('SHIPHS', SUBSTR (l_msg, 3)) ;
1364 FND_MSG_PUB.ADD;
1365 --INCLUDE A LINE IN INL_SHIP_HOLdS
1366 Handle_ShipError ( p_ship_header_id => p_ship_header_id,
1367 p_ship_line_id => p_ship_line_id,
1368 p_charge_line_id => NULL,
1369 p_table_name => 'INL_SHIP_LINES',
1370 p_column_name => NULL,
1371 p_column_value => NULL,
1372 p_error_message => SUBSTR (FND_MSG_PUB.Get (p_msg_index => FND_MSG_PUB.Count_Msg (),
1373 p_encoded => FND_API.g_false), 1, 2000),
1374 p_error_message_name => 'INL_ERR_CHK_SHIP_LN_QTY_OTH_L',
1375 p_token1_name => 'SRC_TYPE',
1376 p_token1_value => p_ship_line_src_type_code,
1377 p_token2_name => 'QTY',
1378 p_token2_value => x_tolerable_quantity,
1379 p_token3_name => 'UOM',
1380 p_token3_value => x_unit_of_measure,
1381 p_token4_name => 'SHIPHS',
1382 p_token4_value => SUBSTR (l_msg, 3),
1383 p_token5_name => NULL,
1384 p_token5_value => NULL,
1385 p_token6_name => NULL,
1386 p_token6_value => NULL,
1387 x_return_status => l_return_status) ;
1388 END IF;
1389 END IF;
1390 END IF;
1391 INL_LOGGING_PVT.Log_EndProc ( p_module_name => g_module_name,
1392 p_procedure_name => l_proc_name) ;
1393 EXCEPTION
1394 WHEN FND_API.G_EXC_ERROR THEN
1395 x_return_status := FND_API.G_RET_STS_ERROR;
1396 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1397 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1398 WHEN OTHERS THEN
1399 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1400 IF FND_MSG_PUB.Check_Msg_Level (p_message_level => FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
1401 FND_MSG_PUB.Add_Exc_Msg ( p_pkg_name => g_pkg_name, p_procedure_name => l_proc_name) ;
1402 END IF;
1403 END Check_AvailableQty;
1404
1405 -- Utility name : Check_PoPriceTolerance
1406 -- Type : Private
1407 -- Function : Check whether Shipment Line Price is compliant with the PO
1408 -- Price Tolerance defined in the INL Setup Options
1409 -- Pre-reqs : None
1410 -- Parameters :
1411 -- IN : p_ship_header_id IN NUMBER
1412 -- p_ship_line_id IN NUMBER,
1413 -- p_organization_id IN NUMBER,
1414 -- p_ship_line_num IN NUMBER,
1415 -- p_ship_line_src_id IN NUMBER,
1416 -- p_pri_unit_price IN NUMBER,
1417 -- p_primary_uom_code IN VARCHAR2,
1418 -- p_currency_code IN VARCHAR2,
1419 -- p_currency_conversion_type IN VARCHAR2,
1420 -- p_currency_conversion_date IN DATE,
1421 -- p_currency_conversion_rate IN NUMBER,
1422 -- x_return_status OUT NOCOPY VARCHAR2
1423 --
1424 -- OUT x_return_status OUT NOCOPY VARCHAR2
1425 --
1426 -- Version : Current version 1.0
1427 --
1428 -- Notes :
1429 PROCEDURE Check_PoPriceTolerance(
1430 p_ship_header_id IN NUMBER,
1431 p_ship_line_id IN NUMBER,
1432 p_organization_id IN NUMBER,
1433 p_ship_line_num IN NUMBER,
1434 p_ship_line_src_id IN NUMBER,
1435 p_pri_unit_price IN NUMBER,
1436 p_primary_uom_code IN VARCHAR2, --BUG: 7670307
1437 p_currency_code IN VARCHAR2, --BUG: 7670307
1438 p_currency_conversion_type IN VARCHAR2, --BUG: 7670307
1439 p_currency_conversion_date IN DATE, --BUG: 7670307
1440 p_currency_conversion_rate IN NUMBER, --BUG: 7670307
1441 x_return_status OUT NOCOPY VARCHAR2
1442 ) IS
1443 l_proc_name CONSTANT VARCHAR2 (30) := 'Check_PoPriceTolerance';
1444 l_msg VARCHAR2 (2000) ;
1445 l_debug_info VARCHAR2 (200) ;
1446 l_return_status VARCHAR2 (1) ;
1447 l_po_price_toler_perc NUMBER;
1448 l_actual_price_dif NUMBER;
1449 l_tolerable_dif NUMBER;
1450 l_po_unit_price NUMBER;
1451 l_amount NUMBER;
1452 l_po_qty NUMBER;
1453 l_inventory_item_id NUMBER;
1454 l_po_currency_code VARCHAR2(15);
1455 l_po_currency_conversion_type VARCHAR2(30);
1456 l_po_currency_conversion_date DATE;
1457 l_po_currency_conversion_rate NUMBER;
1458 l_po_converted_price NUMBER;
1459 l_p_converted_PUP NUMBER;
1460 l_po_UOM_code VARCHAR2(30);
1461 BEGIN
1462 -- Standard Beginning of Procedure/Function Logging
1463 INL_LOGGING_PVT.Log_BeginProc ( p_module_name => g_module_name,
1464 p_procedure_name => l_proc_name) ;
1465 -- Initialize API return status to success
1466 x_return_status := FND_API.G_RET_STS_SUCCESS;
1467 -- Get the Price Tolerance from INL Setup Options
1468 SELECT po_price_toler_perc
1469 INTO l_po_price_toler_perc
1470 FROM inl_parameters
1471 WHERE organization_id = p_organization_id;
1472
1473 INL_LOGGING_PVT.Log_Variable (
1474 p_module_name => g_module_name,
1475 p_procedure_name => l_proc_name,
1476 p_var_name => 'l_po_price_toler_perc',
1477 p_var_value => l_po_price_toler_perc
1478 ) ;
1479 -- Get the PO Unit Price
1480 SELECT po.unit_price,
1481 po.currency_code, --BUG: 7670307
1482 po.currency_conversion_type, --BUG: 7670307
1483 po.currency_conversion_date, --BUG: 7670307
1484 po.currency_conversion_rate, --BUG: 7670307
1485 muom.uom_code, --BUG: 7670307
1486 po.ordered_qty,
1487 po.item_id
1488 INTO l_po_unit_price,
1489 l_po_currency_code,
1490 l_po_currency_conversion_type,
1491 l_po_currency_conversion_date,
1492 l_po_currency_conversion_rate,
1493 l_po_UOM_code,
1494 l_po_qty,
1495 l_inventory_item_id
1496 FROM inl_enter_receipts_po_v po, -- BUG: 8229331
1497 mtl_units_of_measure muom
1498 WHERE po.po_line_location_id = p_ship_line_src_id
1499 AND muom.unit_of_measure (+) = po.ordered_uom;
1500
1501
1502
1503 l_debug_info := 'Verifying if currecncy conversion is required. PO: '||l_po_currency_code ||'Shipment: '||p_currency_code;
1504 INL_LOGGING_PVT.Log_Statement (
1505 p_module_name => g_module_name,
1506 p_procedure_name => l_proc_name,
1507 p_debug_info => l_debug_info
1508 );
1509
1510 IF l_po_currency_code = p_currency_code THEN --BUG: 7670307
1511 l_po_converted_price := l_po_unit_price;
1512 l_p_converted_PUP := p_pri_unit_price;
1513 ELSE
1514 IF l_po_currency_conversion_rate IS NOT NULL THEN
1515 l_po_converted_price := l_po_unit_price * l_po_currency_conversion_rate;
1516 ELSE
1517 l_po_converted_price := l_po_unit_price;
1518 END IF;
1519 IF p_currency_conversion_rate IS NOT NULL THEN
1520 l_p_converted_PUP := p_pri_unit_price * p_currency_conversion_rate;
1521 ELSE
1522 l_p_converted_PUP := p_pri_unit_price;
1523 END IF;
1524 END IF;
1525
1526 l_debug_info := 'Verifying if UOM conversion is required. PO: '||l_po_UOM_code ||' Shipment: '||p_primary_uom_code;
1527 INL_LOGGING_PVT.Log_Statement (
1528 p_module_name => g_module_name,
1529 p_procedure_name => l_proc_name,
1530 p_debug_info => l_debug_info
1531 );
1532
1533 IF p_primary_uom_code <> l_po_UOM_code THEN --BUG: 7670307
1534 l_amount := l_po_converted_price * l_po_qty;
1535
1536 l_po_qty := INL_LANDEDCOST_PVT.Converted_Qty(
1537 p_organization_id => p_organization_id,
1538 p_inventory_item_id => l_inventory_item_id,
1539 p_qty => l_po_qty,
1540 p_from_uom_code => l_po_UOM_code,
1541 P_to_uom_code => p_primary_uom_code
1542 );
1543 l_po_converted_price := l_amount / l_po_qty;
1544 END IF;
1545
1546 -- When there is no tolerance defined in
1547 -- INL Setup Options for the current Inventory
1548 -- Organization, the Shipment Line price is validated
1549 -- to be the same price defined in PO.
1550 IF l_po_price_toler_perc IS NULL THEN
1551 IF (l_p_converted_PUP > l_po_converted_price) THEN
1552 FND_MESSAGE.SET_NAME ('INL', 'INL_ERR_NOT_DEF_PO_PRICE_TOLER') ;
1553 FND_MESSAGE.SET_TOKEN ('SHIPLN_NUM', p_ship_line_num) ;
1554 FND_MSG_PUB.ADD;
1555 -- INCLUDE A LINE IN INL_SHIP_HOLdS
1556
1557 Handle_ShipError ( p_ship_header_id => p_ship_header_id,
1558 p_ship_line_id => p_ship_line_id,
1559 p_charge_line_id => NULL,
1560 p_table_name => 'INL_SHIP_LINES',
1561 p_column_name => 'PRIMARY_UNIT_PRICE',
1562 p_column_value => 0,
1563 p_error_message => SUBSTR (FND_MSG_PUB.Get (p_msg_index => FND_MSG_PUB.Count_Msg (),
1564 p_encoded => FND_API.g_false), 1, 2000),
1565 p_error_message_name => 'INL_ERR_NOT_DEF_PO_PRICE_TOLER',
1566 p_token1_name => 'SHIPLN_NUM',
1567 p_token1_value => p_ship_line_num,
1568 p_token2_name => NULL,
1569 p_token2_value => NULL,
1570 p_token3_name => NULL,
1571 p_token3_value => NULL,
1572 p_token4_name => NULL,
1573 p_token4_value => NULL,
1574 p_token5_name => NULL,
1575 p_token5_value => NULL,
1576 p_token6_name => NULL,
1577 p_token6_value => NULL,
1578 x_return_status => l_return_status) ;
1579 END IF;
1580 -- Otherwise will check a unique Shipment Line Unit Price
1581 -- Check the actual difference against the tolerable difference
1582 ELSE
1583 l_actual_price_dif := NVL (l_p_converted_PUP, 0) - NVL (l_po_converted_price, 0) ;
1584 IF l_actual_price_dif > 0 THEN
1585 l_tolerable_dif := (l_po_converted_price / 100) * l_po_price_toler_perc;
1586 IF (l_actual_price_dif > l_tolerable_dif) THEN
1587 FND_MESSAGE.SET_NAME ('INL', 'INL_ERR_PO_PRICE_TOLER') ;
1588 FND_MESSAGE.SET_TOKEN ('SHIPLN_NUM', p_ship_line_num) ;
1589 FND_MESSAGE.SET_TOKEN ('TOLER', l_po_price_toler_perc) ;
1590 FND_MSG_PUB.ADD;
1591
1592 -- INCLUDE A LINE IN INL_SHIP_HOLdS
1593 Handle_ShipError ( p_ship_header_id => p_ship_header_id,
1594 p_ship_line_id => p_ship_line_id,
1595 p_charge_line_id => NULL,
1596 p_table_name => 'INL_SHIP_LINES',
1597 p_column_name => 'PRIMARY_UNIT_PRICE',
1598 p_column_value => 0,
1599 p_error_message => SUBSTR (FND_MSG_PUB.Get (p_msg_index => FND_MSG_PUB.Count_Msg (),
1600 p_encoded => FND_API.g_false), 1, 2000),
1601 p_error_message_name => 'INL_ERR_PO_PRICE_TOLER',
1602 p_token1_name => 'SHIPLN_NUM',
1603 p_token1_value => p_ship_line_num,
1604 p_token2_name => 'TOLER',
1605 p_token2_value => l_po_price_toler_perc,
1606 p_token3_name => NULL,
1607 p_token3_value => NULL,
1608 p_token4_name => NULL,
1609 p_token4_value => NULL,
1610 p_token5_name => NULL,
1611 p_token5_value => NULL,
1612 p_token6_name => NULL,
1613 p_token6_value => NULL,
1614 x_return_status => l_return_status) ;
1615 END IF;
1616 END IF;
1617 END IF;
1618 -- Standard End of Procedure/Function Logging
1619 INL_LOGGING_PVT.Log_EndProc ( p_module_name => g_module_name, p_procedure_name => l_proc_name) ;
1620 EXCEPTION
1621 WHEN FND_API.G_EXC_ERROR THEN
1622 x_return_status := FND_API.G_RET_STS_ERROR;
1623 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1624 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1625 WHEN OTHERS THEN
1626 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1627 IF FND_MSG_PUB.Check_Msg_Level (p_message_level => FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
1628 FND_MSG_PUB.Add_Exc_Msg ( p_pkg_name => g_pkg_name,
1629 p_procedure_name => l_proc_name) ;
1630 END IF;
1631 END Check_PoPriceTolerance;
1632
1633 -- API name : Check_PoTolerances
1634 -- Type : Private
1635 -- Function : API for PO Price and Quantity Tolerances validation.
1636 -- Pre-reqs : None
1637 -- Parameters :
1638 -- IN : p_api_version IN NUMBER Required
1639 -- p_init_msg_list IN VARCHAR2 Optional Default = FND_API.G_FALSE
1640 -- p_commit IN VARCHAR2 Optional Default = FND_API.G_FALSE
1641 -- p_ship_header_id IN NUMBER
1642 -- p_ship_line_id IN NUMBER
1643 -- p_organization_id IN NUMBER
1644 -- p_ship_line_num IN NUMBER
1645 -- p_ship_line_src_id IN NUMBER
1646 -- p_inventory_item_id IN NUMBER
1647 -- p_primary_qty IN NUMBER
1648 -- p_primary_uom_code IN VARCHAR2
1649 -- p_pri_unit_price IN NUMBER
1650 -- p_currency_code IN VARCHAR2,
1651 -- p_currency_conversion_type IN VARCHAR2,
1652 -- p_currency_conversion_date IN DATE,
1653 -- p_currency_conversion_rate IN NUMBER,
1654 --
1655 -- OUT x_return_status OUT NOCOPY VARCHAR2
1656 -- x_msg_count OUT NOCOPY NUMBER
1657 -- x_msg_data OUT NOCOPY VARCHAR2
1658 --
1659 -- Version : Current version 1.0
1660 --
1661 -- Notes :
1662 PROCEDURE Check_PoTolerances(
1663 p_api_version IN NUMBER,
1664 p_init_msg_list IN VARCHAR2 := FND_API.G_FALSE,
1665 p_commit IN VARCHAR2 := FND_API.G_FALSE,
1666 p_ship_header_id IN NUMBER,
1667 p_ship_line_id IN NUMBER,
1668 p_organization_id IN NUMBER,
1669 p_ship_line_num IN NUMBER,
1670 p_ship_line_src_id IN NUMBER,
1671 p_inventory_item_id IN NUMBER,
1672 p_primary_qty IN NUMBER,
1673 p_primary_uom_code IN VARCHAR2,
1674 p_pri_unit_price IN NUMBER,
1675 p_currency_code IN VARCHAR2, --BUG: 7670307
1676 p_currency_conversion_type IN VARCHAR2, --BUG: 7670307
1677 p_currency_conversion_date IN DATE, --BUG: 7670307
1678 p_currency_conversion_rate IN NUMBER, --BUG: 7670307
1679 x_return_status OUT NOCOPY VARCHAR2,
1680 x_msg_count OUT NOCOPY NUMBER,
1681 x_msg_data OUT NOCOPY VARCHAR2)
1682 IS
1683 l_api_name CONSTANT VARCHAR2 (30) := 'Check_PoTolerances';
1684 l_api_version CONSTANT NUMBER := 1.0;
1685 l_return_status VARCHAR2 (1);
1686 l_msg_count NUMBER;
1687 l_msg_data VARCHAR2 (2000);
1688 l_debug_info VARCHAR2 (200);
1689
1690 BEGIN
1691 -- Standard Beginning of Procedure/Function Logging
1692 INL_LOGGING_PVT.Log_BeginProc ( p_module_name => g_module_name,
1693 p_procedure_name => l_api_name) ;
1694 -- Standard Start of API savepoint
1695 SAVEPOINT Check_PoTolerances_PVT;
1696
1697 -- Initialize message list if p_init_msg_list is set to TRUE.
1698 IF FND_API.to_Boolean (p_init_msg_list) THEN
1699 FND_MSG_PUB.initialize;
1700 END IF;
1701
1702 -- Check for call compatibility.
1703 IF NOT FND_API.Compatible_API_Call (l_api_version,
1704 p_api_version,
1705 l_api_name,
1706 G_PKG_NAME) THEN
1707 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1708 END IF;
1709
1710 -- Initialize API return status to success
1711 x_return_status := FND_API.G_RET_STS_SUCCESS;
1712
1713 -- Validate PO Quantity Available
1714 l_debug_info := 'Call Check_AvailableQty';
1715 INL_LOGGING_PVT.Log_Statement (p_module_name => g_module_name,
1716 p_procedure_name => l_api_name,
1717 p_debug_info => l_debug_info) ;
1718
1719 Check_AvailableQty(p_primary_qty => p_primary_qty,
1720 p_sum_primary_qty => NULL,
1721 p_primary_uom_code => p_primary_uom_code,
1722 p_inventory_item_id => p_inventory_item_id,
1723 p_inv_org_id => p_organization_id,
1724 p_ship_line_id => p_ship_line_id,
1725 p_ship_line_num => p_ship_line_num,
1726 p_ship_line_src_type_code => 'PO',
1727 p_ship_line_src_id => p_ship_line_src_id,
1728 p_same_shiph_id => p_ship_header_id,
1729 p_ship_header_id => p_ship_header_id,
1730 x_return_status => l_return_status);
1731
1732 -- If any errors happen abort the process.
1733 IF l_return_status = FND_API.G_RET_STS_ERROR THEN
1734 RAISE FND_API.G_EXC_ERROR;
1735 ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
1736 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1737 END IF;
1738
1739 -- Standard call to get message count and if count is 1, get message info.
1740 FND_MSG_PUB.Count_And_Get ( p_encoded => FND_API.g_false,
1741 p_count => x_msg_count,
1742 p_data => x_msg_data) ;
1743
1744 IF x_msg_count = 0 THEN
1745 -- Validate PO Price Tolerance
1746 l_debug_info := 'Call Check_PoPriceTolerance';
1747 INL_LOGGING_PVT.Log_Statement (p_module_name => g_module_name,
1748 p_procedure_name => l_api_name,
1749 p_debug_info => l_debug_info) ;
1750
1751 Check_PoPriceTolerance(
1752 p_ship_header_id => p_ship_header_id,
1753 p_ship_line_id => p_ship_line_id,
1754 p_organization_id => p_organization_id,
1755 p_ship_line_num => p_ship_line_num,
1756 p_ship_line_src_id => p_ship_line_src_id,
1757 p_pri_unit_price => p_pri_unit_price,
1758 p_primary_uom_code => p_primary_uom_code, --BUG: 7670307
1759 p_currency_code => p_currency_code, --BUG: 7670307
1760 p_currency_conversion_type => p_currency_conversion_type, --BUG: 7670307
1761 p_currency_conversion_date => p_currency_conversion_date, --BUG: 7670307
1762 p_currency_conversion_rate => p_currency_conversion_rate, --BUG: 7670307
1763 x_return_status => l_return_status
1764 );
1765
1766 -- If any errors happen abort the process.
1767 IF l_return_status = FND_API.G_RET_STS_ERROR THEN
1768 RAISE FND_API.G_EXC_ERROR;
1769 ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
1770 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1771 END IF;
1772 END IF;
1773
1774 -- Standard check of p_commit.
1775 IF FND_API.To_Boolean (p_commit) THEN
1776 COMMIT WORK;
1777 END IF;
1778
1779 -- Standard call to get message count and if count is 1, get message info.
1780 FND_MSG_PUB.Count_And_Get ( p_encoded => FND_API.g_false,
1781 p_count => x_msg_count,
1782 p_data => x_msg_data) ;
1783
1784 -- Standard End of Procedure/Function Logging
1785 INL_LOGGING_PVT.Log_EndProc ( p_module_name => g_module_name,
1786 p_procedure_name => l_api_name) ;
1787 EXCEPTION
1788 WHEN FND_API.G_EXC_ERROR THEN
1789 -- Standard Expected Error Logging
1790 INL_LOGGING_PVT.Log_ExpecError ( p_module_name => g_module_name,
1791 p_procedure_name => l_api_name) ;
1792 ROLLBACK TO Check_PoTolerances_PVT;
1793 x_return_status := FND_API.G_RET_STS_ERROR;
1794 FND_MSG_PUB.Count_And_Get ( p_encoded => FND_API.g_false,
1795 p_count => x_msg_count,
1796 p_data => x_msg_data) ;
1797 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1798 -- Standard Unexpected Error Logging
1799 INL_LOGGING_PVT.Log_UnexpecError ( p_module_name => g_module_name,
1800 p_procedure_name => l_api_name) ;
1801 ROLLBACK TO Check_PoTolerances_PVT;
1802 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1803 FND_MSG_PUB.Count_And_Get ( p_encoded => FND_API.g_false,
1804 p_count => x_msg_count,
1805 p_data => x_msg_data) ;
1806 WHEN OTHERS THEN
1807 -- Standard Unexpected Error Logging
1808 INL_LOGGING_PVT.Log_UnexpecError ( p_module_name => g_module_name,
1809 p_procedure_name => l_api_name) ;
1810 ROLLBACK TO Check_PoTolerances_PVT;
1811 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
1812 IF FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
1813 FND_MSG_PUB.Add_Exc_Msg ( p_pkg_name => g_pkg_name,
1814 p_procedure_name => l_api_name) ;
1815 END IF;
1816 FND_MSG_PUB.Count_And_Get ( p_encoded => FND_API.g_false,
1817 p_count => x_msg_count,
1818 p_data => x_msg_data) ;
1819 END Check_PoTolerances;
1820
1821 -- Utility name : Validate_ChargeLine
1822 -- Type : Private
1823 -- Function : Validate Charge Line
1824 -- Pre-reqs : None
1825 -- Parameters :
1826 -- IN : p_ship_header_id IN NUMBER
1827 -- p_to_parent_table_name IN VARCHAR2
1828 -- p_to_parent_table_id IN NUMBER
1829 -- p_functional_currency_code IN VARCHAR2
1830 -- p_foreign_currency_flag IN VARCHAR2
1831 -- p_third_parties_allowed IN VARCHAR2
1832 --
1833 -- OUT : x_ch_line_tot_amt_func_curr OUT NOCOPY NUMBER
1834 -- x_return_status OUT NOCOPY VARCHAR2
1835 --
1836 -- Version : Current version 1.0
1837 --
1838 -- Notes :
1839 PROCEDURE Validate_ChargeLine (p_ship_header_id IN NUMBER,
1840 p_to_parent_table_name IN VARCHAR2,
1841 p_to_parent_table_id IN NUMBER,
1842 p_functional_currency_code IN VARCHAR2,
1843 p_foreign_currency_flag IN VARCHAR2,
1844 p_third_parties_allowed IN VARCHAR2,
1845 x_ch_line_tot_amt_func_curr OUT NOCOPY NUMBER,
1846 x_return_status OUT NOCOPY VARCHAR2)
1847 IS
1848
1849 l_proc_name CONSTANT VARCHAR2 (30) := 'Validate_ChargeLine';
1850 l_debug_info VARCHAR2 (200);
1851 l_return_status VARCHAR2 (1);
1852
1853 CURSOR c_ch_lines IS
1854 SELECT DECODE (cl.currency_code,
1855 p_functional_currency_code,
1856 cl.charge_amt,
1857 cl.charge_amt * cl.currency_conversion_rate) AS ch_line_amt_func_curr,
1858 cl.currency_code,
1859 cl.charge_line_id,
1860 cl.charge_line_num
1861 FROM inl_adj_charge_lines_v cl,
1862 inl_charge_line_types_vl clt ,
1863 inl_associations assoc
1864 WHERE clt.charge_line_type_id = cl.charge_line_type_id
1865 AND assoc.from_parent_table_name = 'INL_CHARGE_LINES'
1866 AND assoc.from_parent_table_id = NVL (cl.parent_charge_line_id, cl.charge_line_id)
1867 AND assoc.ship_header_id = p_ship_header_id
1868 AND assoc.to_parent_table_name = p_to_parent_table_name
1869 AND assoc.to_parent_table_id = p_to_parent_table_id
1870 ORDER BY cl.charge_line_num;
1871
1872 l_ch_lines_rec c_ch_lines%ROWTYPE;
1873
1874 BEGIN
1875 INL_LOGGING_PVT.Log_BeginProc ( p_module_name => g_module_name,
1876 p_procedure_name => l_proc_name) ;
1877
1878 x_return_status := FND_API.G_RET_STS_SUCCESS;
1879
1880 x_ch_line_tot_amt_func_curr := 0;
1881 FOR l_ch_lines_rec IN c_ch_lines
1882 LOOP
1883
1884 l_debug_info := 'Check Foreign Currency for Charge Line';
1885 INL_LOGGING_PVT.Log_Statement ( p_module_name => g_module_name,
1886 p_procedure_name => l_proc_name,
1887 p_debug_info => l_debug_info) ;
1888 IF l_ch_lines_rec.currency_code <> p_functional_currency_code AND p_foreign_currency_flag = 'N' THEN
1889 FND_MESSAGE.SET_NAME ('INL', 'INL_ERR_CHK_FRGN_CUR') ;
1890 FND_MESSAGE.SET_TOKEN ('CLNUM', l_ch_lines_rec.charge_line_num) ;
1891 FND_MSG_PUB.ADD;
1892 -- INCLUDE A LINE IN INL_SHIP_HOLdS
1893 Handle_ShipError ( p_ship_header_id => p_ship_header_id,
1894 p_ship_line_id => NULL,
1895 p_charge_line_id => l_ch_lines_rec.charge_line_id,
1896 p_table_name => 'INL_CHARGE_LINES',
1897 p_column_name => 'CURRENCY_CODE',
1898 p_column_value => l_ch_lines_rec.CURRENCY_CODE,
1899 p_error_message => SUBSTR (FND_MSG_PUB.Get (p_msg_index => FND_MSG_PUB.Count_Msg (),
1900 p_encoded => FND_API.g_false), 1, 2000),
1901 p_error_message_name => 'INL_ERR_CHK_FRGN_CUR',
1902 p_token1_name => 'CLNUM',
1903 p_token1_value => l_ch_lines_rec.charge_line_num,
1904 p_token2_name => NULL,
1905 p_token2_value => NULL,
1906 p_token3_name => NULL,
1907 p_token3_value => NULL,
1908 p_token4_name => NULL,
1909 p_token4_value => NULL,
1910 p_token5_name => NULL,
1911 p_token5_value => NULL,
1912 p_token6_name => NULL,
1913 p_token6_value => NULL,
1914 x_return_status => l_return_status) ;
1915 -- If unexpected errors happen abort
1916 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1917 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1918 END IF;
1919 END IF;
1920 -- the flag l_ch_lines_rec.dflt_charge_amt_flag has been removed from table, and the original pkg
1921 -- fas been changed without the if clause, this is a temporarily wrk proc that will replace the actual
1922 x_ch_line_tot_amt_func_curr := x_ch_line_tot_amt_func_curr + NVL (l_ch_lines_rec.ch_line_amt_func_curr, 0) ;
1923 END LOOP;
1924 INL_LOGGING_PVT.Log_EndProc ( p_module_name => g_module_name,
1925 p_procedure_name => l_proc_name) ;
1926 EXCEPTION
1927 WHEN FND_API.G_EXC_ERROR THEN
1928 -- Standard Expected Error Logging
1929 INL_LOGGING_PVT.Log_ExpecError ( p_module_name => g_module_name,
1930 p_procedure_name => l_proc_name) ;
1931 x_return_status := FND_API.G_RET_STS_ERROR;
1932 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1933 -- Standard Unexpected Error Logging
1934 INL_LOGGING_PVT.Log_UnexpecError ( p_module_name => g_module_name,
1935 p_procedure_name => l_proc_name) ;
1936 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1937 WHEN OTHERS THEN
1938 -- Standard Unexpected Error Logging
1939 INL_LOGGING_PVT.Log_UnexpecError ( p_module_name => g_module_name,
1940 p_procedure_name => l_proc_name) ;
1941 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1942 IF FND_MSG_PUB.Check_Msg_Level (p_message_level => FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
1943 FND_MSG_PUB.Add_Exc_Msg ( p_pkg_name => g_pkg_name,
1944 p_procedure_name => l_proc_name) ;
1945 END IF;
1946 END Validate_ChargeLine;
1947
1948 -- Utility name : Validate_ShipLine
1949 -- Type : Private
1950 -- Function : Validate Shipment Line
1951 -- Pre-reqs : None
1952 -- Parameters :
1953 -- IN : p_ship_header_id IN NUMBER
1954 -- p_ln_group_id IN NUMBER
1955 -- p_functional_currency_code IN VARCHAR2
1956 -- p_foreign_currency_flag IN VARCHAR2
1957 -- p_organization_id IN NUMBER
1958 -- p_country_code_location IN VARCHAR2
1959 -- p_third_parties_allowed IN VARCHAR2
1960 --
1961 -- OUT : x_return_status OUT NOCOPY VARCHAR2
1962 --
1963 -- Version : Current version 1.0
1964 --
1965 -- Notes :
1966 PROCEDURE Validate_ShipLine (p_ship_header_id IN NUMBER,
1967 p_ln_group_id IN NUMBER,
1968 p_functional_currency_code IN VARCHAR2,
1969 p_foreign_currency_flag IN VARCHAR2,
1970 p_organization_id IN NUMBER,
1971 p_country_code_location IN VARCHAR2,
1972 p_third_parties_allowed IN VARCHAR2,
1973 x_return_status OUT NOCOPY VARCHAR2)
1974 IS
1975
1976 l_proc_name CONSTANT VARCHAR2 (30) := 'Validate_ShipLine';
1977 l_return_status VARCHAR2 (1) := FND_API.G_RET_STS_SUCCESS;
1978 l_debug_info VARCHAR2 (200);
1979 l_ch_line_tot_amt_func_curr NUMBER;
1980 l_pre_receive VARCHAR2 (1) ;
1981
1982 CURSOR c_ship_lines IS
1983 SELECT ol.ship_line_id,
1984 ol.ship_line_num,
1985 ol.ship_line_src_type_code,
1986 ol.ship_line_source_id,
1987 ol.inventory_item_id,
1988 (SELECT SUM (a.primary_qty)
1989 FROM inl_adj_ship_lines_v a
1990 WHERE a.ship_header_id = ol.ship_header_id
1991 AND a.ship_line_source_id = ol.ship_line_source_id) AS sum_primary_qty,
1992 ol.primary_qty,
1993 ol.primary_unit_price,
1994 ol.primary_uom_code,
1995 ol.currency_code,
1996 ol.currency_conversion_type,
1997 ol.currency_conversion_date,
1998 ol.currency_conversion_rate,
1999 'INL_SHIP_LINES' to_parent_table_name
2000 FROM inl_adj_ship_lines_v ol,
2001 inl_ship_line_types_vl olt
2002 WHERE ol.ship_header_id = p_ship_header_id
2003 AND ol.ship_line_type_id = olt.ship_line_type_id
2004 AND ol.ship_line_group_id = p_ln_group_id
2005 ORDER BY ol.ship_line_num;
2006
2007 l_ship_lines_rec c_ship_lines%ROWTYPE;
2008
2009 BEGIN
2010 INL_LOGGING_PVT.Log_BeginProc ( p_module_name => g_module_name,
2011 p_procedure_name => l_proc_name) ;
2012
2013 x_return_status := FND_API.G_RET_STS_SUCCESS;
2014
2015 FOR l_ship_lines_rec IN c_ship_lines
2016 LOOP
2017 l_debug_info := 'Validate Charge Line. Call Validate_ChargeLine';
2018 INL_LOGGING_PVT.Log_Statement ( p_module_name => g_module_name,
2019 p_procedure_name => l_proc_name,
2020 p_debug_info => l_debug_info) ;
2021
2022 Validate_ChargeLine (p_ship_header_id => p_ship_header_id,
2023 p_to_parent_table_name => l_ship_lines_rec.to_parent_table_name,
2024 p_to_parent_table_id => l_ship_lines_rec.ship_line_id,
2025 p_functional_currency_code => p_functional_currency_code,
2026 p_foreign_currency_flag => p_foreign_currency_flag,
2027 p_third_parties_allowed => p_third_parties_allowed,
2028 x_ch_line_tot_amt_func_curr => l_ch_line_tot_amt_func_curr,
2029 x_return_status => l_return_status);
2030
2031 -- If unexpected errors happen abort API
2032 IF l_return_status = FND_API.G_RET_STS_ERROR THEN
2033 x_return_status := l_return_status;
2034 RAISE FND_API.G_EXC_ERROR;
2035 ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
2036 x_return_status := l_return_status;
2037 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2038 END IF;
2039
2040 l_debug_info := 'Getting which scenartio is setup in RCV Parameters. Pre_Receive or BlackBox';
2041 INL_LOGGING_PVT.Log_Statement ( p_module_name => g_module_name,
2042 p_procedure_name => l_proc_name,
2043 p_debug_info => l_debug_info) ;
2044 SELECT pre_receive
2045 INTO l_pre_receive
2046 FROM rcv_parameters
2047 WHERE organization_id = p_organization_id;
2048
2049 -- Just validate PO Available Qty for Pre-Receive scenario
2050 -- In Blackbox, RCV handles this validation
2051 IF (NVL (l_pre_receive, 'N') = 'Y') THEN
2052 l_debug_info := 'Call to Check_AvailableQty';
2053 INL_LOGGING_PVT.Log_Statement ( p_module_name => g_module_name,
2054 p_procedure_name => l_proc_name,
2055 p_debug_info => l_debug_info) ;
2056 Check_AvailableQty ( l_ship_lines_rec.primary_qty,
2057 l_ship_lines_rec.sum_primary_qty,
2058 l_ship_lines_rec.primary_uom_code,
2059 l_ship_lines_rec.inventory_item_id,
2060 p_organization_id,
2061 l_ship_lines_rec.ship_line_id,
2062 l_ship_lines_rec.ship_line_num,
2063 l_ship_lines_rec.ship_line_src_type_code,
2064 l_ship_lines_rec.ship_line_source_id,
2065 NULL,
2066 p_ship_header_id,
2067 l_return_status) ;
2068 -- If unexpected errors happen abort API
2069 IF l_return_status = FND_API.G_RET_STS_ERROR THEN
2070 x_return_status := l_return_status;
2071 RAISE FND_API.G_EXC_ERROR;
2072 ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
2073 x_return_status := l_return_status;
2074 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2075 END IF;
2076 END IF;
2077
2078 -- Required validation only for Source Type Code = PO
2079 IF l_ship_lines_rec.ship_line_src_type_code = 'PO' THEN
2080 l_debug_info := 'Call Check_PoPriceTolerance';
2081 INL_LOGGING_PVT.Log_Statement ( p_module_name => g_module_name,
2082 p_procedure_name => l_proc_name,
2083 p_debug_info => l_debug_info) ;
2084
2085 Check_PoPriceTolerance (
2086 p_ship_header_id => p_ship_header_id,
2087 p_ship_line_id => l_ship_lines_rec.ship_line_id,
2088 p_organization_id => p_organization_id,
2089 p_ship_line_num => l_ship_lines_rec.ship_line_num,
2090 p_ship_line_src_id => l_ship_lines_rec.ship_line_source_id,
2091 p_pri_unit_price => l_ship_lines_rec.primary_unit_price,
2092 p_primary_uom_code => l_ship_lines_rec.primary_uom_code,
2093 p_currency_code => l_ship_lines_rec.currency_code,
2094 p_currency_conversion_type => l_ship_lines_rec.currency_conversion_type,
2095 p_currency_conversion_date => l_ship_lines_rec.currency_conversion_date,
2096 p_currency_conversion_rate => l_ship_lines_rec.currency_conversion_rate,
2097 x_return_status => l_return_status
2098 ) ;
2099
2100 -- If unexpected errors happen abort API
2101 IF l_return_status = FND_API.G_RET_STS_ERROR THEN
2102 x_return_status := l_return_status;
2103 RAISE FND_API.G_EXC_ERROR;
2104 ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
2105 x_return_status := l_return_status;
2106 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2107 END IF;
2108 END IF;
2109 END LOOP;
2110
2111 INL_LOGGING_PVT.Log_EndProc ( p_module_name => g_module_name,
2112 p_procedure_name => l_proc_name) ;
2113 EXCEPTION
2114 WHEN FND_API.G_EXC_ERROR THEN
2115 -- Standard Expected Error Logging
2116 INL_LOGGING_PVT.Log_ExpecError ( p_module_name => g_module_name,
2117 p_procedure_name => l_proc_name) ;
2118 x_return_status := FND_API.G_RET_STS_ERROR;
2119 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2120 -- Standard Unexpected Error Logging
2121 INL_LOGGING_PVT.Log_UnexpecError ( p_module_name => g_module_name,
2122 p_procedure_name => l_proc_name) ;
2123 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2124 WHEN OTHERS THEN
2125 -- Standard Unexpected Error Logging
2126 INL_LOGGING_PVT.Log_UnexpecError ( p_module_name => g_module_name,
2127 p_procedure_name => l_proc_name) ;
2128 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2129 IF FND_MSG_PUB.Check_Msg_Level (p_message_level => FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
2130 FND_MSG_PUB.Add_Exc_Msg ( p_pkg_name => g_pkg_name,
2131 p_procedure_name => l_proc_name) ;
2132 END IF;
2133 END Validate_ShipLine;
2134
2135 -- Utility name : Validate_ShipHdr
2136 -- Type : Private
2137 -- Function : Validate Shipment Header
2138 -- Pre-reqs : None
2139 -- Parameters :
2140 -- IN : p_ship_header_id IN NUMBER
2141 -- OUT : x_return_status OUT NOCOPY VARCHAR2
2142 --
2143 -- Version : Current version 1.0
2144 --
2145 -- Notes :
2146 PROCEDURE Validate_ShipHdr (p_ship_header_id IN NUMBER,
2147 x_return_status OUT NOCOPY VARCHAR2)
2148 IS
2149
2150 l_proc_name CONSTANT VARCHAR2 (30) := 'Validate_ShipHdr';
2151
2152 l_return_status VARCHAR2 (1) := FND_API.G_RET_STS_SUCCESS;
2153 l_debug_info VARCHAR2 (200);
2154 l_ship_type_id NUMBER;
2155 l_ship_status VARCHAR2 (30);
2156 l_inv_org_id NUMBER;
2157 l_ship_date DATE;
2158 l_error_type VARCHAR2 (3);
2159 l_pending_matching_flag VARCHAR2 (1);
2160 l_sob_id NUMBER (15);
2161 l_comp_num VARCHAR2 (50) ;
2162 l_func_curr_code VARCHAR2 (15);
2163 l_ship_type_code VARCHAR2 (15);
2164 l_shipt_third_parties_allowed VARCHAR2 (1);
2165 l_in_adjust_flag VARCHAR2 (1);
2166 l_location_id NUMBER;
2167 l_error_message_name VARCHAR2 (200);
2168 l_error_token_name VARCHAR2 (200);
2169 l_country_code_location VARCHAR2 (100);
2170
2171 CURSOR c_ln_group IS
2172 SELECT ship_line_group_id
2173 FROM inl_ship_line_groups lg
2174 WHERE ship_header_id = p_ship_header_id
2175 ORDER BY ship_line_group_num;
2176
2177 BEGIN
2178 INL_LOGGING_PVT.Log_BeginProc ( p_module_name => g_module_name,
2179 p_procedure_name => l_proc_name) ;
2180
2181 x_return_status := FND_API.G_RET_STS_SUCCESS;
2182
2183 l_debug_info := 'Get Shipment Header and Shipment Type information';
2184 INL_LOGGING_PVT.Log_Statement ( p_module_name => g_module_name,
2185 p_procedure_name => l_proc_name,
2186 p_debug_info => l_debug_info) ;
2187 SELECT shipt.ship_type_id,
2188 shipt.ship_type_code,
2189 shipt.trd_pties_alwd_code,
2190 sh.ship_status_code,
2191 sh.organization_id,
2192 sh.location_id,
2193 sh.ship_date,
2194 sh.pending_matching_flag
2195 INTO l_ship_type_id,
2196 l_ship_type_code,
2197 l_shipt_third_parties_allowed,
2198 l_ship_status,
2199 l_inv_org_id,
2200 l_location_id,
2201 l_ship_date,
2202 l_pending_matching_flag
2203 FROM inl_ship_headers_all sh,
2204 inl_ship_types_vl shipt
2205 WHERE sh.ship_type_id = shipt.ship_type_id
2206 AND sh.ship_header_id = p_ship_header_id;
2207
2208 IF l_ship_status = 'COMPLETED' AND l_pending_matching_flag = 'Y' THEN
2209 l_in_adjust_flag := 'Y';
2210 ELSE
2211 l_in_adjust_flag := 'N';
2212 END IF;
2213
2214 l_debug_info := 'Get Set of Books by a given Inventory Organization';
2215 INL_LOGGING_PVT.Log_Statement ( p_module_name => g_module_name,
2216 p_procedure_name => l_proc_name,
2217 p_debug_info => l_debug_info) ;
2218 SELECT set_of_books_id
2219 INTO l_sob_id
2220 FROM org_organization_definitions ood
2221 WHERE organization_id = l_inv_org_id;
2222
2223 l_debug_info := 'Check Shipment Date against the Inventory Open Period';
2224 INL_LOGGING_PVT.Log_Statement ( p_module_name => g_module_name,
2225 p_procedure_name => l_proc_name,
2226 p_debug_info => l_debug_info) ;
2227
2228 IF Validate_InvOpenPeriod ( x_trx_date => TO_CHAR (l_ship_date, 'YYYY-MM-DD'),
2229 x_sob_id => l_sob_id,
2230 x_org_id => l_inv_org_id,
2231 x_return_status => l_return_status) = 'FALSE' THEN
2232 FND_MESSAGE.SET_NAME ('INL', 'INL_ERR_CHK_INV_SHIP_DATE') ;
2233 FND_MESSAGE.SET_TOKEN ('SHIP_DATE', TO_CHAR (l_ship_date)) ;
2234 FND_MSG_PUB.ADD;
2235
2236 l_debug_info := 'Transaction period is not open in Inventory.';
2237 INL_LOGGING_PVT.Log_Statement ( p_module_name => g_pkg_name,
2238 p_procedure_name => l_proc_name,
2239 p_debug_info => l_debug_info) ;
2240 INL_LOGGING_PVT.Log_Variable ( p_module_name => g_module_name,
2241 p_procedure_name => l_proc_name,
2242 p_var_name => 'l_ship_date',
2243 p_var_value => TO_CHAR (l_ship_date)) ;
2244
2245 -- INCLUDE A LINE IN INL_SHIP_HOLdS
2246 Handle_ShipError ( p_ship_header_id => p_ship_header_id,
2247 p_ship_line_id => NULL,
2248 p_charge_line_id => NULL,
2249 p_table_name => 'INL_SHIP_HEADERS',
2250 p_column_name => 'SHIP_DATE',
2251 p_column_value => TO_CHAR (l_ship_date),
2252 p_error_message => SUBSTR (FND_MSG_PUB.Get (p_msg_index => FND_MSG_PUB.Count_Msg (),
2253 p_encoded => FND_API.g_false), 1, 2000),
2254 p_error_message_name => 'INL_ERR_CHK_INV_SHIP_DATE',
2255 p_token1_name => 'SHIP_DATE',
2256 p_token1_value => TO_CHAR (l_ship_date),
2257 p_token2_name => NULL,
2258 p_token2_value => NULL,
2259 p_token3_name => NULL,
2260 p_token3_value => NULL,
2261 p_token4_name => NULL,
2262 p_token4_value => NULL,
2263 p_token5_name => NULL,
2264 p_token5_value => NULL,
2265 p_token6_name => NULL,
2266 p_token6_value => NULL,
2267 x_return_status => l_return_status) ;
2268 -- If unexpected errors happen abort
2269 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2270 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2271 END IF;
2272 END IF;
2273
2274 l_debug_info := 'Check if the current Shipment has Shipment Lines';
2275 INL_LOGGING_PVT.Log_Statement ( p_module_name => g_module_name,
2276 p_procedure_name => l_proc_name,
2277 p_debug_info => l_debug_info) ;
2278
2279 IF (NOT Has_ShipLine (p_ship_header_id)) THEN
2280 FND_MESSAGE.SET_NAME ('INL', 'INL_ERR_CHK_NO_SHIP_LN') ;
2281 FND_MSG_PUB.ADD;
2282 -- INCLUDE A LINE IN INL_SHIP_HOLdS
2283 Handle_ShipError ( p_ship_header_id => p_ship_header_id,
2284 p_ship_line_id => NULL,
2285 p_charge_line_id => NULL,
2286 p_table_name => 'INL_SHIP_HEADERS',
2287 p_column_name => 'SHIP_TYPE_ID',
2288 p_column_value => l_ship_type_id,
2289 p_error_message => SUBSTR (FND_MSG_PUB.Get (p_msg_index => FND_MSG_PUB.Count_Msg (),
2290 p_encoded => FND_API.g_false), 1, 2000),
2291 p_error_message_name => 'INL_ERR_CHK_NO_SHIP_LN',
2292 p_token1_name => NULL,
2293 p_token1_value => NULL,
2294 p_token2_name => NULL,
2295 p_token2_value => NULL,
2296 p_token3_name => NULL,
2297 p_token3_value => NULL,
2298 p_token4_name => NULL,
2299 p_token4_value => NULL,
2300 p_token5_name => NULL,
2301 p_token5_value => NULL,
2302 p_token6_name => NULL,
2303 p_token6_value => NULL,
2304 x_return_status => l_return_status) ;
2305 -- If unexpected errors happen abort
2306 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2307 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2308 END IF;
2309 ELSIF l_in_adjust_flag = 'N' THEN
2310 l_debug_info := 'Get the functional currency code';
2311 INL_LOGGING_PVT.Log_Statement ( p_module_name => g_pkg_name,
2312 p_procedure_name => l_proc_name,
2313 p_debug_info => l_debug_info) ;
2314 SELECT gsb.currency_code
2315 INTO l_func_curr_code
2316 FROM org_organization_definitions ood,
2317 gl_sets_of_books gsb
2318 WHERE gsb.set_of_books_id = ood.set_of_books_id
2319 AND organization_id = l_inv_org_id;
2320
2321 l_debug_info := 'Get Country from Location';
2322 INL_LOGGING_PVT.Log_Statement ( p_module_name => g_module_name,
2323 p_procedure_name => l_proc_name,
2324 p_debug_info => l_debug_info) ;
2325 SELECT country
2326 INTO l_country_code_location
2327 FROM hr_locations
2328 WHERE location_id = l_location_id;
2329
2330 FOR l_ln_group_rec IN c_ln_group
2331 LOOP
2332
2333 l_debug_info := 'Call Validate_ShipLine';
2334 INL_LOGGING_PVT.Log_Statement ( p_module_name => g_module_name,
2335 p_procedure_name => l_proc_name,
2336 p_debug_info => l_debug_info) ;
2337
2338 Validate_ShipLine ( p_ship_header_id => p_ship_header_id,
2339 p_ln_group_id => l_ln_group_rec.ship_line_group_id,
2340 p_functional_currency_code => l_func_curr_code,
2341 p_foreign_currency_flag => 'Y',
2342 p_organization_id => l_inv_org_id,
2343 p_country_code_location => l_country_code_location,
2344 p_third_parties_allowed => l_shipt_third_parties_allowed,
2345 x_return_status => l_return_status) ;
2346
2347 -- If unexpected errors happen abort API
2348 IF l_return_status = FND_API.G_RET_STS_ERROR THEN
2349 x_return_status := l_return_status;
2350 RAISE FND_API.G_EXC_ERROR;
2351 ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
2352 x_return_status := l_return_status;
2353 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2354 END IF;
2355 END LOOP;
2356 END IF;
2357 EXCEPTION
2358 WHEN FND_API.G_EXC_ERROR THEN
2359 -- Standard Expected Error Logging
2360 INL_LOGGING_PVT.Log_ExpecError ( p_module_name => g_module_name,
2361 p_procedure_name => l_proc_name) ;
2362 x_return_status := FND_API.G_RET_STS_ERROR;
2363 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2364 -- Standard Unexpected Error Logging
2365 INL_LOGGING_PVT.Log_UnexpecError ( p_module_name => g_module_name,
2366 p_procedure_name => l_proc_name) ;
2367 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2368 WHEN OTHERS THEN
2369 -- Standard Unexpected Error Logging
2370 INL_LOGGING_PVT.Log_UnexpecError ( p_module_name => g_module_name,
2371 p_procedure_name => l_proc_name) ;
2372 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2373 IF FND_MSG_PUB.Check_Msg_Level (p_message_level => FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
2374 FND_MSG_PUB.Add_Exc_Msg ( p_pkg_name => g_pkg_name, p_procedure_name => l_proc_name) ;
2375 END IF;
2376 END Validate_ShipHdr;
2377
2378 -- Utility name : Validate_InvOpenPeriod
2379 -- Type : Private
2380 -- Function : Check whether the Inventory Period is open
2381 -- Pre-reqs : None
2382 -- Parameters :
2383 -- IN : x_trx_date IN VARCHAR2
2384 -- x_sob_id IN NUMBER
2385 -- x_org_id IN NUMBER
2386 -- OUT : x_return_status IN OUT NOCOPY VARCHAR2
2387 --
2388 -- Version : Current version 1.0
2389 --
2390 -- Notes :
2391 FUNCTION Validate_InvOpenPeriod
2392 (
2393 x_trx_date IN VARCHAR2,
2394 x_sob_id IN NUMBER,
2395 x_org_id IN NUMBER,
2396 x_return_status IN OUT NOCOPY VARCHAR2)
2397 RETURN VARCHAR2
2398 IS
2399 l_proc_name VARCHAR2 (200) := 'Validate_InvOpenPeriod';
2400 l_boolean BOOLEAN;
2401 l_boolean_to_char VARCHAR2 (10) ;
2402 l_trx_date DATE;
2403 l_debug_info VARCHAR2 (400) ;
2404 BEGIN
2405 l_trx_date := TO_DATE (x_trx_date, 'YYYY-MM-DD') ;
2406 -- the x_return_status parameter mustn't been reseted
2407 INL_LOGGING_PVT.Log_BeginProc ( p_module_name => g_module_name,
2408 p_procedure_name => l_proc_name) ;
2409 -- information about the input parameters
2410 INL_LOGGING_PVT.Log_APICallIn ( p_module_name => g_module_name,
2411 p_procedure_name => l_proc_name,
2412 p_call_api_name => 'po_dates_s.val_open_period',
2413 p_in_param_name1 => 'x_trx_date',
2414 p_in_param_value1 => x_trx_date,
2415 p_in_param_name2 => 'x_sob_id',
2416 p_in_param_value2 => x_sob_id,
2417 p_in_param_name3 => 'x_org_id',
2418 p_in_param_value3 => x_org_id,
2419 p_in_param_name4 => 'x_return_status',
2420 p_in_param_value4 => x_return_status) ;
2421 -- Initialize API return status to success
2422 x_return_status := FND_API.G_RET_STS_SUCCESS;
2423 l_boolean := po_dates_s.val_open_period ( x_trx_date => l_trx_date,
2424 x_sob_id => x_sob_id,
2425 x_app_name => 'INV',
2426 x_org_id => x_org_id) ;
2427 IF l_boolean THEN
2428 l_boolean_to_char := 'TRUE';
2429 ELSE
2430 l_boolean_to_char := 'FALSE';
2431 END IF;
2432 -- information about the respose
2433 INL_LOGGING_PVT.Log_APICallIn ( p_module_name => g_module_name,
2434 p_procedure_name => l_proc_name,
2435 p_call_api_name => 'po_dates_s.val_open_period',
2436 p_in_param_name1 => 'l_boolean_to_char',
2437 p_in_param_value1 => l_boolean_to_char) ;
2438 INL_LOGGING_PVT.Log_EndProc ( p_module_name => g_module_name,
2439 p_procedure_name => l_proc_name) ;
2440 RETURN l_boolean_to_char;
2441 EXCEPTION
2442 WHEN FND_API.G_EXC_ERROR THEN
2443 -- Standard Expected Error Logging
2444 INL_LOGGING_PVT.Log_ExpecError ( p_module_name => g_module_name,
2445 p_procedure_name => l_proc_name) ;
2446 x_return_status := FND_API.G_RET_STS_ERROR;
2447 RETURN 'FALSE';
2448 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2449 -- Standard Unexpected Error Logging
2450 INL_LOGGING_PVT.Log_UnexpecError ( p_module_name => g_module_name,
2451 p_procedure_name => l_proc_name) ;
2452 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2453 RETURN 'FALSE';
2454 WHEN OTHERS THEN
2455 -- Standard Unexpected Error Logging
2456 INL_LOGGING_PVT.Log_UnexpecError ( p_module_name => g_module_name,
2457 p_procedure_name => l_proc_name) ;
2458 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2459 IF FND_MSG_PUB.Check_Msg_Level (p_message_level => FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
2460 FND_MSG_PUB.Add_Exc_Msg ( p_pkg_name => g_pkg_name, p_procedure_name => l_proc_name) ;
2461 END IF;
2462 RETURN 'FALSE';
2463 END Validate_InvOpenPeriod;
2464
2465 -- API name : Validate_Shipment
2466 -- Type : Private
2467 -- Function : Controls the validation of a given LCM Shipment.
2468 -- Pre-reqs : None
2469 -- Parameters :
2470 -- IN : p_api_version IN NUMBER
2471 -- p_init_msg_list IN VARCHAR2 FND_API.G_FALSE
2472 -- p_commit IN VARCHAR2 FND_API.G_FALSE
2473 -- p_validation_level IN NUMBER FND_API.G_VALID_LEVEL_FULL
2474 -- p_ship_header_id IN NUMBER
2475 --
2476 -- OUT x_return_status OUT NOCOPY VARCHAR2
2477 -- x_msg_count OUT NOCOPY NUMBER
2478 -- x_msg_data OUT NOCOPY VARCHAR2
2479 --
2480 -- Version : Current version 1.0
2481 --
2482 -- Notes :
2483 PROCEDURE Validate_Shipment (p_api_version IN NUMBER,
2484 p_init_msg_list IN VARCHAR2 := FND_API.G_FALSE,
2485 p_commit IN VARCHAR2 := FND_API.G_FALSE,
2486 p_validation_level IN NUMBER := FND_API.G_VALID_LEVEL_FULL,
2487 p_ship_header_id IN NUMBER,
2488 x_return_status OUT NOCOPY VARCHAR2,
2489 x_msg_count OUT NOCOPY NUMBER,
2490 x_msg_data OUT NOCOPY VARCHAR2)
2491 IS
2492
2493 l_api_name CONSTANT VARCHAR2 (30) := 'Validate_Shipment';
2494 l_api_version CONSTANT NUMBER := 1.0;
2495
2496 l_return_status VARCHAR2 (1) := FND_API.G_RET_STS_SUCCESS;
2497 l_ship_status VARCHAR2 (30) ;
2498 l_exist_event VARCHAR2 (5) ;
2499 l_exist_status NUMBER := 0;
2500 l_debug_info VARCHAR2 (200);
2501
2502 BEGIN
2503 INL_LOGGING_PVT.Log_BeginProc ( p_module_name => g_module_name,
2504 p_procedure_name => l_api_name) ;
2505
2506 -- Standard Start of API savepoint
2507 SAVEPOINT Validate_Shipment_PVT;
2508
2509 -- Initialize message list if p_init_msg_list is set to TRUE.
2510 IF FND_API.to_Boolean (p_init_msg_list) THEN
2511 FND_MSG_PUB.initialize;
2512 END IF;
2513
2514 -- Check for call compatibility.
2515 IF NOT FND_API.Compatible_API_Call ( p_current_version_number => l_api_version,
2516 p_caller_version_number => p_api_version,
2517 p_api_name => l_api_name,
2518 p_pkg_name => G_PKG_NAME) THEN
2519 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2520 END IF;
2521
2522 -- Initialize API return status to success
2523 x_return_status := FND_API.G_RET_STS_SUCCESS;
2524
2525 l_debug_info := 'Reset errors in inl_ship_holds table';
2526 INL_LOGGING_PVT.Log_Statement ( p_module_name => g_module_name,
2527 p_procedure_name => l_api_name,
2528 p_debug_info => l_debug_info) ;
2529 Reset_ShipError ( p_ship_header_id => p_ship_header_id,
2530 p_ship_line_id => NULL,
2531 p_charge_line_id => NULL,
2532 x_return_status => l_return_status) ;
2533
2534 -- If unexpected errors happen abort API
2535 IF l_return_status = FND_API.G_RET_STS_ERROR THEN
2536 x_return_status := l_return_status;
2537 RAISE FND_API.G_EXC_ERROR;
2538 ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
2539 x_return_status := l_return_status;
2540 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2541 END IF;
2542
2543 l_debug_info := 'Shipment Header validation';
2544 INL_LOGGING_PVT.Log_Statement ( p_module_name => g_pkg_name,
2545 p_procedure_name => l_api_name,
2546 p_debug_info => l_debug_info) ;
2547
2548 Validate_ShipHdr ( p_ship_header_id => p_ship_header_id,
2549 x_return_status => l_return_status) ;
2550
2551 -- If unexpected errors happen abort API
2552 IF l_return_status = FND_API.G_RET_STS_ERROR THEN
2553 x_return_status := l_return_status;
2554 RAISE FND_API.G_EXC_ERROR;
2555 ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
2556 x_return_status := l_return_status;
2557 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2558 END IF;
2559
2560 l_debug_info := 'fnd_msg_pub.count_msg';
2561 INL_LOGGING_PVT.Log_Variable ( p_module_name => g_module_name,
2562 p_procedure_name => l_api_name,
2563 p_var_name => l_debug_info,
2564 p_var_value => TO_CHAR (fnd_msg_pub.count_msg)) ;
2565
2566 IF (NVL (fnd_msg_pub.count_msg, 0) = 0) THEN
2567 SELECT ship_status_code
2568 INTO l_ship_status
2569 FROM inl_ship_headers
2570 WHERE ship_header_id = p_ship_header_id;
2571 IF l_ship_status <> 'COMPLETED' THEN
2572 l_debug_info := 'Update INL_SHIP_HEADERS_ALL.ship_status_code to VALIDATED';
2573 INL_LOGGING_PVT.Log_Statement ( p_module_name => g_module_name,
2574 p_procedure_name => l_api_name,
2575 p_debug_info => l_debug_info) ;
2576 UPDATE inl_ship_headers
2577 SET ship_status_code = 'VALIDATED',
2578 last_updated_by = fnd_global.user_id,
2579 last_update_date = SYSDATE
2580 WHERE ship_header_id = p_ship_header_id;
2581 END IF;
2582 ELSE
2583 l_debug_info := 'Update INL_SHIP_HEADERS_ALL.ship_status_code to ON HOLD';
2584 INL_LOGGING_PVT.Log_Statement ( p_module_name => g_module_name,
2585 p_procedure_name => l_api_name,
2586 p_debug_info => l_debug_info) ;
2587 UPDATE inl_ship_headers
2588 SET ship_status_code = 'ON HOLD',
2589 last_updated_by = fnd_global.user_id,
2590 last_update_date = SYSDATE
2591 WHERE ship_header_id = p_ship_header_id;
2592 END IF;
2593
2594 -- Standard check of p_commit.
2595 IF FND_API.To_Boolean (p_commit) THEN
2596 COMMIT WORK;
2597 END IF;
2598
2599 -- Standard call to get message count and if count is 1, get message info.
2600 FND_MSG_PUB.Count_And_Get ( p_encoded => FND_API.g_false,
2601 p_count => x_msg_count,
2602 p_data => x_msg_data) ;
2603
2604 INL_LOGGING_PVT.Log_EndProc ( p_module_name => g_module_name,
2605 p_procedure_name => l_api_name) ;
2606 EXCEPTION
2607 WHEN FND_API.G_EXC_ERROR THEN
2608 INL_LOGGING_PVT.Log_ExpecError ( p_module_name => g_module_name,
2609 p_procedure_name => l_api_name) ;
2610 ROLLBACK TO Validate_Shipment_PVT;
2611 x_return_status := FND_API.G_RET_STS_ERROR;
2612 FND_MSG_PUB.Count_And_Get ( p_encoded => FND_API.g_false,
2613 p_count => x_msg_count,
2614 p_data => x_msg_data) ;
2615 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2616 INL_LOGGING_PVT.Log_UnexpecError ( p_module_name => g_module_name,
2617 p_procedure_name => l_api_name) ;
2618 ROLLBACK TO Validate_Shipment_PVT;
2619 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2620 FND_MSG_PUB.Count_And_Get ( p_encoded => FND_API.g_false,
2621 p_count => x_msg_count,
2622 p_data => x_msg_data) ;
2623 WHEN OTHERS THEN
2624 INL_LOGGING_PVT.Log_UnexpecError ( p_module_name => g_module_name,
2625 p_procedure_name => l_api_name) ;
2626 ROLLBACK TO Validate_Shipment_PVT;
2627 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
2628 IF FND_MSG_PUB.Check_Msg_Level (p_message_level => FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
2629 FND_MSG_PUB.Add_Exc_Msg ( p_pkg_name => g_pkg_name,
2630 p_procedure_name => l_api_name) ;
2631 END IF;
2632 FND_MSG_PUB.Count_And_Get ( p_encoded => FND_API.g_false,
2633 p_count => x_msg_count,
2634 p_data => x_msg_data) ;
2635 END Validate_Shipment;
2636
2637 -- Utility name: Create_Assoc
2638 -- Type : Private
2639 -- Function : Create Associations
2640 -- Pre-reqs : None
2641 -- Parameters :
2642 -- IN : p_assoc IN inl_Assoc_tp
2643 -- p_from_parent_table_name IN VARCHAR2,
2644 -- p_new_line_id IN NUMBER, charge line at a highest level
2645 --
2646 -- OUT : x_return_status OUT NOCOPY VARCHAR2
2647 --
2648 -- Version : Current version 1.0
2649 --
2650 -- Notes :
2651 PROCEDURE Create_Assoc
2652 (
2653 p_Assoc IN inl_Assoc_tp,
2654 p_from_parent_table_name IN VARCHAR2,
2655 p_new_line_id IN NUMBER,
2656 x_return_status OUT NOCOPY VARCHAR2)
2657 IS
2658 l_proc_name CONSTANT VARCHAR2 (30) := 'Create_Assoc';
2659 l_return_status VARCHAR2 (1) ;
2660 l_debug_info VARCHAR2 (200) ;
2661 BEGIN
2662 -- Standard Beginning of Procedure/Function Logging
2663 INL_LOGGING_PVT.Log_BeginProc ( p_module_name => g_module_name,
2664 p_procedure_name => l_proc_name) ;
2665 -- Initialize return status to success
2666 x_return_status := FND_API.G_RET_STS_SUCCESS;
2667 l_debug_info := 'Insert in inl_associations.';
2668 INL_LOGGING_PVT.Log_Statement ( p_module_name => g_module_name,
2669 p_procedure_name => l_proc_name,
2670 p_debug_info => l_debug_info) ;
2671 l_debug_info := 'p_new_line_id';
2672 INL_LOGGING_PVT.Log_Variable ( p_module_name => g_module_name,
2673 p_procedure_name => l_proc_name,
2674 p_var_name => l_debug_info,
2675 p_var_value => TO_CHAR (p_new_line_id)) ;
2676
2677 INSERT
2678 INTO inl_associations (
2679 association_id, /* 01 */
2680 ship_header_id, /* 02 */
2681 from_parent_table_name, /* 03 */
2682 from_parent_table_id, /* 04 */
2683 to_parent_table_name, /* 05 */
2684 to_parent_table_id, /* 06 */
2685 allocation_basis, /* 07 */
2686 allocation_uom_code, /* 08 */
2687 created_by, /* 09 */
2688 creation_date, /* 10 */
2689 last_updated_by, /* 11 */
2690 last_update_date, /* 12 */
2691 last_update_login /* 13 */
2692 )
2693 VALUES (
2694 inl_associations_s.nextval, /* 01 */
2695 p_Assoc.ship_header_id, /* 02 */
2696 p_from_parent_table_name, /* 03 */
2697 p_new_line_id, /* 04 */
2698 p_Assoc.to_parent_table_name, /* 05 */
2699 p_Assoc.to_parent_table_id, /* 06 */
2700 p_Assoc.allocation_basis, /* 07 */
2701 p_Assoc.allocation_uom_code, /* 08 */
2702 fnd_global.user_id, /* 09 */
2703 sysdate, /* 10 */
2704 fnd_global.user_id, /* 11 */
2705 sysdate, /* 12 */
2706 fnd_global.user_id /* 13 */
2707 );
2708 -- Standard End of Procedure/Function Logging
2709 INL_LOGGING_PVT.Log_EndProc
2710 (
2711 p_module_name => g_module_name,
2712 p_procedure_name => l_proc_name
2713 )
2714 ;
2715 EXCEPTION
2716 WHEN FND_API.G_EXC_ERROR THEN
2717 -- Standard Expected Error Logging
2718 INL_LOGGING_PVT.Log_ExpecError
2719 (
2720 p_module_name => g_module_name,
2721 p_procedure_name => l_proc_name
2722 )
2723 ;
2724 x_return_status := FND_API.G_RET_STS_ERROR;
2725 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2726 -- Standard Unexpected Error Logging
2727 INL_LOGGING_PVT.Log_UnexpecError
2728 (
2729 p_module_name => g_module_name,
2730 p_procedure_name => l_proc_name
2731 )
2732 ;
2733 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2734 WHEN OTHERS THEN
2735 -- Standard Unexpected Error Logging
2736 INL_LOGGING_PVT.Log_UnexpecError
2737 (
2738 p_module_name => g_module_name,
2739 p_procedure_name => l_proc_name
2740 )
2741 ;
2742 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
2743 IF FND_MSG_PUB.Check_Msg_Level
2744 (
2745 p_message_level => FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR
2746 )
2747 THEN
2748 FND_MSG_PUB.Add_Exc_Msg
2749 (
2750 p_pkg_name => g_pkg_name,
2751 p_procedure_name => l_proc_name
2752 )
2753 ;
2754 END IF;
2755 END Create_Assoc;
2756
2757 -- Utility name: Create_TxLines
2758 -- Type : Private
2759 -- Function : Create Tax Lines
2760 -- Pre-reqs : None
2761 -- Parameters :
2762 -- IN : p_TxLn_Assoc IN inl_TxLn_Assoc_tp
2763 -- p_include_assoc IN VARCHAR2 := 'Y'
2764 -- p_adjustment_num IN NUMBER
2765 --
2766 -- OUT : x_new_tax_line_id OUT NOCOPY NUMBER,
2767 -- x_return_status OUT NOCOPY VARCHAR2
2768 --
2769 -- Version : Current version 1.0
2770 --
2771 -- Notes :
2772 PROCEDURE Create_TxLines
2773 (
2774 p_TxLn_Assoc IN inl_TxLn_Assoc_tp,
2775 p_include_assoc IN VARCHAR2 := 'Y',
2776 p_adjustment_num IN NUMBER,
2777 x_new_tax_line_id OUT NOCOPY NUMBER,
2778 x_return_status OUT NOCOPY VARCHAR2
2779 )
2780 IS
2781 l_proc_name CONSTANT VARCHAR2(30):= 'Create_TxLines';
2782 l_return_status VARCHAR2(1);
2783 l_debug_info VARCHAR2(200);
2784 l_tax_line_num NUMBER;
2785 l_adjustment_num NUMBER;
2786 BEGIN
2787 -- Standard Beginning of Procedure/Function Logging
2788 INL_LOGGING_PVT.Log_BeginProc (
2789 p_module_name => g_module_name,
2790 p_procedure_name => l_proc_name
2791 );
2792 -- Initialize return status to success
2793 x_return_status := FND_API.G_RET_STS_SUCCESS;
2794 --
2795 -- Get Max val to tax line num
2796 --
2797 IF p_TxLn_Assoc.tax_line_num IS NULL THEN
2798 l_debug_info := 'Get Max val from tax line num';
2799 INL_LOGGING_PVT.Log_Statement(
2800 p_module_name => g_module_name,
2801 p_procedure_name=> l_proc_name,
2802 p_debug_info => l_debug_info
2803 )
2804 ;
2805 SELECT NVL (MAX (tl.tax_line_num), 0) + 1
2806 INTO l_tax_line_num
2807 FROM inl_tax_lines tl
2808 WHERE NVL (tl.ship_header_id, 0) = NVL (p_TxLn_Assoc.inl_Assoc.ship_header_id, 0) ;
2809 ELSE
2810 l_tax_line_num := p_TxLn_Assoc.tax_line_num;
2811 END IF;
2812 --
2813 -- Get Val to adjustment num
2814 --
2815 IF p_TxLn_Assoc.adjustment_num IS NULL THEN
2816 l_debug_info := 'Set l_adjustment_num to p_adjustment_num';
2817 l_adjustment_num := p_adjustment_num;
2818 ELSE
2819 l_debug_info := 'Set l_adjustment_num to p_TxLn_Assoc.adjustment_num';
2820 l_adjustment_num := p_TxLn_Assoc.adjustment_num;
2821 END IF;
2822 INL_LOGGING_PVT.Log_Statement ( p_module_name => g_module_name,
2823 p_procedure_name => l_proc_name,
2824 p_debug_info => l_debug_info) ;
2825 --
2826 -- Get inl_tax_lines_s.nextval
2827 --
2828 l_debug_info := 'Get inl_tax_lines_s.nextval';
2829 INL_LOGGING_PVT.Log_Statement ( p_module_name => g_module_name,
2830 p_procedure_name => l_proc_name,
2831 p_debug_info => l_debug_info) ;
2832 SELECT inl_tax_lines_s.nextval
2833 INTO x_new_tax_line_id
2834 FROM dual;
2835 --
2836 -- include Tax Line record
2837 --
2838 l_debug_info := 'Including Tax Line record ';
2839 INL_LOGGING_PVT.Log_Statement ( p_module_name => g_module_name,
2840 p_procedure_name => l_proc_name,
2841 p_debug_info => l_debug_info) ;
2842 INSERT
2843 INTO inl_tax_lines (
2844 tax_line_id, /* 01 */
2845 tax_line_num, /* 02 */
2846 tax_code, /* 03 */
2847 ship_header_id, /* 04 */
2848 parent_tax_line_id, /* 05 */
2849 adjustment_num, /* 06 */
2850 match_id, /* 07 */
2851 match_amount_id, /* 08 */
2852 source_parent_table_name, /* 09 */
2853 source_parent_table_id, /* 10 */
2854 tax_amt, /* 11 */
2855 nrec_tax_amt, /* 12 */
2856 currency_code, /* 13 */
2857 currency_conversion_type, /* 14 */
2858 currency_conversion_date, /* 15 */
2859 currency_conversion_rate, /* 16 */
2860 tax_amt_included_flag, /* 17 */
2861 created_by, /* 18 */
2862 creation_date, /* 19 */
2863 last_updated_by, /* 20 */
2864 last_update_date, /* 21 */
2865 last_update_login /* 22 */
2866 )
2867 VALUES
2868 (
2869 x_new_tax_line_id, /* 01 */
2870 l_tax_line_num, /* 02 */
2871 p_TxLn_Assoc.tax_code, /* 03 */
2872 p_TxLn_Assoc.inl_Assoc.ship_header_id, /* 04 */
2873 p_TxLn_Assoc.parent_tax_line_id, /* 05 */
2874 l_adjustment_num, /* 06 */
2875 p_TxLn_Assoc.match_id, /* 07 */
2876 p_TxLn_Assoc.match_amount_id, /* 08 */
2877 p_TxLn_Assoc.source_parent_table_name, /* 09 */
2878 p_TxLn_Assoc.source_parent_table_id, /* 10 */
2879 p_TxLn_Assoc.matched_amt, /* 11 */
2880 p_TxLn_Assoc.nrec_tax_amt, /* 12 */
2881 p_TxLn_Assoc.currency_code, /* 13 */
2882 p_TxLn_Assoc.currency_conversion_type, /* 14 */
2883 p_TxLn_Assoc.currency_conversion_date, /* 15 */
2884 p_TxLn_Assoc.currency_conversion_rate, /* 16 */
2885 p_TxLn_Assoc.tax_amt_included_flag, /* 17 */
2886 fnd_global.user_id, /* 18 */
2887 sysdate, /* 19 */
2888 fnd_global.user_id, /* 20 */
2889 sysdate, /* 21 */
2890 fnd_global.user_id /* 22 */
2891 ) ;
2892
2893 IF p_include_assoc = 'Y' THEN
2894 Create_Assoc(
2895 p_Assoc => p_TxLn_Assoc.inl_Assoc,
2896 p_from_parent_table_name => 'INL_TAX_LINES',
2897 p_new_line_id => x_new_tax_line_id,
2898 x_return_status => l_return_status
2899 )
2900 ;
2901 IF l_return_status = FND_API.G_RET_STS_ERROR THEN
2902 RAISE FND_API.G_EXC_ERROR;
2903 ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
2904 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2905 END IF;
2906 END IF;
2907 -- Standard End of Procedure/Function Logging
2908 INL_LOGGING_PVT.Log_EndProc(
2909 p_module_name => g_module_name,
2910 p_procedure_name => l_proc_name
2911 );
2912 EXCEPTION
2913 WHEN FND_API.G_EXC_ERROR THEN
2914 -- Standard Expected Error Logging
2915 INL_LOGGING_PVT.Log_ExpecError(
2916 p_module_name => g_module_name,
2917 p_procedure_name => l_proc_name
2918 );
2919 x_return_status := FND_API.G_RET_STS_ERROR;
2920 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2921 -- Standard Unexpected Error Logging
2922 INL_LOGGING_PVT.Log_UnexpecError(
2923 p_module_name => g_module_name,
2924 p_procedure_name => l_proc_name
2925 );
2926 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2927 WHEN OTHERS THEN
2928 -- Standard Unexpected Error Logging
2929 INL_LOGGING_PVT.Log_UnexpecError(
2930 p_module_name => g_module_name,
2931 p_procedure_name => l_proc_name
2932 );
2933 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
2934 IF FND_MSG_PUB.Check_Msg_Level(
2935 p_message_level => FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR
2936 ) THEN
2937 FND_MSG_PUB.Add_Exc_Msg(
2938 p_pkg_name => g_pkg_name,
2939 p_procedure_name=> l_proc_name
2940 );
2941 END IF;
2942 END Create_TxLines;
2943
2944 -- Utility name: Zero_EstimTaxLines
2945 -- Type : Private
2946 -- Function : Create a Adj Tax Line with amt = 0
2947 -- Pre-reqs : None
2948 -- Parameters :
2949 -- IN : p_ship_header_id IN NUMBER, -- sent null to process only one component
2950 -- p_match_id IN NUMBER,
2951 -- p_comp_name IN VARCHAR2, -- name of the component to make tax = 0
2952 -- p_comp_id IN NUMBER, -- id of the component to make tax = 0
2953 -- p_tax_code IN VARCHAR2, -- IF NULL = ALL
2954 --
2955 -- OUT : x_return_status OUT NOCOPY VARCHAR2
2956 --
2957 -- Version : Current version 1.0
2958 --
2959 -- Notes :
2960 PROCEDURE Zero_EstimTaxLines (
2961 p_ship_header_id IN NUMBER,
2962 p_match_id IN NUMBER,
2963 p_comp_name IN VARCHAR2,
2964 p_comp_id IN VARCHAR2,
2965 p_tax_code IN VARCHAR2,
2966 p_adjustment_num IN NUMBER,
2967 x_return_status OUT NOCOPY VARCHAR2
2968 ) IS
2969 l_proc_name CONSTANT VARCHAR2(30) := 'Zero_EstimTaxLines';
2970 l_return_status VARCHAR2(1);
2971 l_debug_info VARCHAR2(200);
2972 CURSOR estimated_TL
2973 IS
2974 SELECT tl.tax_line_id ,
2975 tl.tax_line_num ,
2976 tl.tax_code ,
2977 tl.ship_header_id ,
2978 tl.parent_tax_line_id ,
2979 tl.adjustment_num ,
2980 tl.match_id ,
2981 tl.source_parent_table_name,
2982 tl.source_parent_table_id ,
2983 tl.tax_amt ,
2984 tl.nrec_tax_amt ,
2985 tl.currency_code ,
2986 tl.currency_conversion_type,
2987 tl.currency_conversion_date,
2988 tl.currency_conversion_rate,
2989 tl.tax_amt_included_flag
2990 FROM inl_adj_tax_lines_v tl
2991 WHERE tl.adjustment_num = 0
2992 AND tl.ship_header_id = p_ship_header_id
2993 AND
2994 (
2995 p_tax_code IS NULL
2996 OR tl.tax_code = p_tax_code
2997 )
2998
2999 UNION ALL
3000
3001 SELECT tl.tax_line_id ,
3002 tl.tax_line_num ,
3003 tl.tax_code ,
3004 tl.ship_header_id ,
3005 tl.parent_tax_line_id ,
3006 tl.adjustment_num ,
3007 tl.match_id ,
3008 tl.source_parent_table_name,
3009 tl.source_parent_table_id ,
3010 tl.tax_amt ,
3011 tl.nrec_tax_amt ,
3012 tl.currency_code ,
3013 tl.currency_conversion_type,
3014 tl.currency_conversion_date,
3015 tl.currency_conversion_rate,
3016 tl.tax_amt_included_flag
3017 FROM inl_adj_tax_lines_v tl
3018 WHERE p_ship_header_id IS NULL
3019 AND tl.adjustment_num = 0
3020 AND
3021 (
3022 p_tax_code IS NULL
3023 OR tl.tax_code = p_tax_code
3024 )
3025 AND EXISTS
3026 (
3027 SELECT 1
3028 FROM inl_associations assoc
3029 WHERE assoc.from_parent_table_name = 'INL_TAX_LINES'
3030 AND assoc.from_parent_table_id = tl.tax_line_id
3031 AND assoc.to_parent_table_name = p_comp_name
3032 AND assoc.to_parent_table_id = p_comp_id
3033 ) ;
3034
3035 TYPE est_TL_Type
3036 IS
3037 TABLE OF estimated_TL%ROWTYPE;
3038 C_est_TL est_TL_Type;
3039 l_TxLn_Assoc inl_TxLn_Assoc_tp;
3040 l_new_tax_line_id NUMBER;
3041 BEGIN
3042
3043 -- Standard Beginning of Procedure/Function Logging
3044 INL_LOGGING_PVT.Log_BeginProc (
3045 p_module_name => g_module_name,
3046 p_procedure_name => l_proc_name
3047 );
3048 -- Initialize return status to success
3049 x_return_status := FND_API.G_RET_STS_SUCCESS;
3050 l_debug_info := 'Getting existent estimated TaxLine.';
3051 INL_LOGGING_PVT.Log_Statement (
3052 p_module_name => g_module_name,
3053 p_procedure_name => l_proc_name,
3054 p_debug_info => l_debug_info
3055 ) ;
3056
3057 OPEN estimated_TL;
3058 FETCH estimated_TL BULK COLLECT INTO C_est_TL;
3059
3060 CLOSE estimated_TL;
3061 l_debug_info := C_est_TL.LAST||' lines have been retrieved.';
3062 INL_LOGGING_PVT.Log_Statement (
3063 p_module_name => g_module_name,
3064 p_procedure_name => l_proc_name,
3065 p_debug_info => l_debug_info
3066 ) ;
3067 IF NVL (C_est_TL.LAST, 0) > 0 THEN
3068 l_TxLn_Assoc.inl_Assoc.allocation_basis := NULL;
3069 l_TxLn_Assoc.inl_Assoc.allocation_uom_code := NULL;
3070 l_TxLn_Assoc.inl_Assoc.to_parent_table_name := NULL;
3071 l_TxLn_Assoc.inl_Assoc.to_parent_table_id := NULL;
3072 l_TxLn_Assoc.adjustment_num := p_adjustment_num;
3073 l_TxLn_Assoc.match_id := p_match_id;
3074 l_TxLn_Assoc.matched_amt := 0;
3075 l_TxLn_Assoc.nrec_tax_amt := 0;
3076 l_TxLn_Assoc.source_parent_table_name := 'INL_TAX_LINES';
3077 FOR i IN NVL (C_est_TL.FIRST, 0) ..NVL (C_est_TL.LAST, 0)
3078 LOOP
3079 l_TxLn_Assoc.inl_Assoc.ship_header_id := C_est_TL (i) .ship_header_id;
3080 l_TxLn_Assoc.tax_code := C_est_TL (i) .tax_code;
3081 l_TxLn_Assoc.tax_line_num := C_est_TL (i) .tax_line_num;
3082 l_TxLn_Assoc.parent_tax_line_id := C_est_TL (i) .tax_line_id;
3083 l_TxLn_Assoc.source_parent_table_id := C_est_TL (i) .tax_line_id; --Unique index U2 in INL_TAX_LINES
3084 l_TxLn_Assoc.currency_code := C_est_TL (i) .currency_code;
3085 l_TxLn_Assoc.currency_conversion_type := C_est_TL (i) .currency_conversion_type;
3086 l_TxLn_Assoc.currency_conversion_date := C_est_TL (i) .currency_conversion_date;
3087 l_TxLn_Assoc.currency_conversion_rate := C_est_TL (i) .currency_conversion_rate;
3088 l_TxLn_Assoc.tax_amt_included_flag := C_est_TL (i) .tax_amt_included_flag;
3089 -- Create_TxLines
3090 l_debug_info := 'Estimated Tax line found new with 0.';
3091 INL_LOGGING_PVT.Log_Statement (
3092 p_module_name => g_module_name,
3093 p_procedure_name => l_proc_name,
3094 p_debug_info => l_debug_info
3095 ) ;
3096 Create_TxLines (
3097 p_TxLn_Assoc => l_TxLn_Assoc,
3098 p_include_assoc => 'N',
3099 p_adjustment_num => p_adjustment_num,
3100 x_new_tax_line_id => l_new_tax_line_id,
3101 x_return_status => l_return_status
3102 ) ;
3103 IF l_return_status = FND_API.G_RET_STS_ERROR THEN
3104 RAISE FND_API.G_EXC_ERROR;
3105 ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
3106 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3107 END IF;
3108 END LOOP;
3109 END IF;
3110 -- Standard End of Procedure/Function Logging
3111 INL_LOGGING_PVT.Log_EndProc (
3112 p_module_name => g_module_name,
3113 p_procedure_name => l_proc_name
3114 ) ;
3115 EXCEPTION
3116 WHEN FND_API.G_EXC_ERROR THEN
3117 -- Standard Expected Error Logging
3118 INL_LOGGING_PVT.Log_ExpecError (
3119 p_module_name => g_module_name,
3120 p_procedure_name => l_proc_name
3121 ) ;
3122 x_return_status := FND_API.G_RET_STS_ERROR;
3123 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
3124 -- Standard Unexpected Error Logging
3125 INL_LOGGING_PVT.Log_UnexpecError (
3126 p_module_name => g_module_name,
3127 p_procedure_name => l_proc_name
3128 ) ;
3129 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3130 WHEN OTHERS THEN
3131 -- Standard Unexpected Error Logging
3132 INL_LOGGING_PVT.Log_UnexpecError (
3133 p_module_name => g_module_name,
3134 p_procedure_name => l_proc_name
3135 ) ;
3136 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
3137 IF FND_MSG_PUB.Check_Msg_Level (p_message_level => FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
3138 FND_MSG_PUB.Add_Exc_Msg (
3139 p_pkg_name => g_pkg_name,
3140 p_procedure_name => l_proc_name
3141 ) ;
3142 END IF;
3143 END Zero_EstimTaxLines;
3144
3145 ---
3146 ---
3147 -- API name : Adjust_ShipLines
3148 -- Type : Private
3149 -- Function : Create Adjustments for Shipment Lines
3150 -- Pre-reqs : None
3151 -- Parameters :
3152 -- IN : p_api_version IN NUMBER Required
3153 -- p_init_msg_list IN VARCHAR2 Optional Default = FND_API.G_FALSE
3154 -- p_commit IN VARCHAR2 Optional Default = FND_API.G_FALSE
3155 -- p_match_id IN NUMBER,
3156 -- p_adjustment_num IN NUMBER,
3157 -- OUT x_return_status OUT NOCOPY VARCHAR2
3158 -- x_msg_count OUT NOCOPY NUMBER
3159 -- x_msg_data OUT NOCOPY VARCHAR2
3160 --
3161 -- Version : Current version 1.0
3162 --
3163 -- Notes :
3164 PROCEDURE Adjust_ShipLines
3165 (
3166 p_api_version IN NUMBER,
3167 p_init_msg_list IN VARCHAR2 := FND_API.G_FALSE,
3168 p_commit IN VARCHAR2 := FND_API.G_FALSE,
3169 p_match_id IN NUMBER,
3170 p_adjustment_num IN NUMBER,
3171 x_return_status OUT NOCOPY VARCHAR2,
3172 x_msg_count OUT NOCOPY NUMBER,
3173 x_msg_data OUT NOCOPY VARCHAR2)
3174 IS
3175 -- Cursor to get previous matching values
3176 -- in order to calculate partial match
3177 CURSOR c_previous_matchings ( pc_ship_line_id IN NUMBER,
3178 -- pc_from_parent_table_name IN VARCHAR2,
3179 -- pc_from_parent_table_id IN NUMBER,
3180 -- pc_existing_match_info_flag IN VARCHAR2,
3181 pc_curr_match_id IN NUMBER, pc_to_currency_code IN VARCHAR2, pc_to_curr_conversion_type IN VARCHAR2, pc_to_curr_conversion_date IN DATE)
3182 IS
3183 SELECT mat.matched_qty,
3184 mat.match_id ,
3185 DECODE (pc_to_currency_code,
3186 mat.matched_curr_code,
3187 mat.matched_amt,
3188 inl_landedcost_pvt.Converted_Amt ( mat.matched_amt,
3189 mat.matched_curr_code,
3190 pc_to_currency_code,
3191 pc_to_curr_conversion_type,
3192 pc_to_curr_conversion_date)) matched_amt
3193 FROM inl_corr_matches_v mat
3194 WHERE mat.to_parent_table_name = 'INL_SHIP_LINES'
3195 AND mat.match_type_code = 'ITEM'
3196 AND mat.to_parent_table_id = pc_ship_line_id
3197 AND NOT EXISTS
3198 (
3199 SELECT 1
3200 FROM inl_corr_matches_v m2
3201 WHERE m2.from_parent_table_name = mat.from_parent_table_name
3202 AND m2.from_parent_table_id = mat.from_parent_table_id
3203 AND m2.match_id > mat.match_id
3204 )
3205 AND mat.match_id <> pc_curr_match_id
3206 ORDER BY match_id ;
3207
3208 l_prev_matchings_rec c_previous_matchings%ROWTYPE;
3209 l_api_name CONSTANT VARCHAR2 (30) := 'Adjust_ShipLines';
3210 l_api_version CONSTANT NUMBER := 1.0;
3211 l_return_status VARCHAR2 (1) ;
3212 l_next_adjust_num NUMBER;
3213 l_sum_adj_price NUMBER;
3214 l_shipl_qty_sub_match NUMBER;
3215 l_final_qty NUMBER;
3216 l_final_price NUMBER;
3217 l_sl_inv_item_id NUMBER;
3218 l_net_rcv_txn_qty NUMBER;
3219 l_shipl_unit_price NUMBER;
3220 l_to_ship_header_id NUMBER;
3221 l_to_ship_line_id NUMBER;
3222 l_matched_qty NUMBER;
3223 l_primary_qty NUMBER;
3224 l_primary_unit_price NUMBER;
3225 l_inv_org_id NUMBER;
3226 l_matched_uom_code VARCHAR2 (3) ;
3227 l_primary_uom_code VARCHAR2 (3) ;
3228 l_txn_uom_code VARCHAR2 (3) ; --BUG#7674121
3229 l_debug_info VARCHAR2 (240) ;
3230 l_replace_estim_qty_flag VARCHAR2 (1) ;
3231 l_ship_line_num NUMBER;
3232 l_ship_line_group_id NUMBER;
3233 l_matched_amt NUMBER;
3234 l_ship_line_curr_code VARCHAR2 (15) ;
3235 l_current_curr_code VARCHAR2 (15) ;
3236 l_current_curr_conv_type VARCHAR2 (15) ;
3237 l_current_curr_conv_date DATE;
3238 l_current_curr_conv_rate NUMBER;
3239 l_ori_unit_price NUMBER;
3240 l_existing_match_info_flag VARCHAR2 (1) ;
3241 l_curr_match_id NUMBER;
3242 l_from_parent_table_name VARCHAR2 (30) ;
3243 l_from_parent_table_id NUMBER;
3244 -- Bug #7702294
3245 l_rt_transaction_id NUMBER;
3246 l_rt_uom_code VARCHAR2(3);
3247 l_ordered_po_qty NUMBER;
3248 l_cancelled_po_qty NUMBER;
3249 l_received_po_qty NUMBER;
3250 l_corrected_po_qty NUMBER;
3251 l_delivered_po_qty NUMBER;
3252 l_rtv_po_qty NUMBER;
3253 l_billed_po_qty NUMBER;
3254 l_accepted_po_qty NUMBER;
3255 l_rejected_po_qty NUMBER;
3256 l_ordered_txn_qty NUMBER;
3257 l_cancelled_txn_qty NUMBER;
3258 l_received_txn_qty NUMBER;
3259 l_corrected_txn_qty NUMBER;
3260 l_delivered_txn_qty NUMBER;
3261 l_rtv_txn_qty NUMBER;
3262 l_billed_txn_qty NUMBER;
3263 l_accepted_txn_qty NUMBER;
3264 l_rejected_txn_qty NUMBER;
3265 -- Bug #7702294
3266
3267 BEGIN
3268 -- Standard Beginning of Procedure/Function Logging
3269 INL_LOGGING_PVT.Log_BeginProc (
3270 p_module_name => g_module_name,
3271 p_procedure_name => l_api_name
3272 ) ;
3273 -- Standard Start of API savepoint
3274 SAVEPOINT Adjust_ShipLines_PVT;
3275 -- Initialize message list if p_init_msg_list is set to TRUE.
3276 IF FND_API.to_Boolean (p_init_msg_list) THEN
3277 FND_MSG_PUB.initialize;
3278 END IF;
3279 -- Check for call compatibility.
3280 IF NOT FND_API.Compatible_API_Call (
3281 p_current_version_number => l_api_version,
3282 p_caller_version_number => p_api_version,
3283 p_api_name => l_api_name,
3284 p_pkg_name => g_pkg_name
3285 ) THEN
3286 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3287 END IF;
3288 -- Initialize API return status to success
3289 x_return_status := FND_API.G_RET_STS_SUCCESS;
3290 -- Getting Matching Data
3291 l_debug_info := 'Getting Matching Data';
3292 INL_LOGGING_PVT.Log_Statement (
3293 p_module_name => g_module_name,
3294 p_procedure_name => l_api_name,
3295 p_debug_info => l_debug_info
3296 ) ;
3297
3298 SELECT
3299 mat.ship_header_id , /* 01 */
3300 mat.to_parent_table_id, /* 02 */
3301 mat.matched_qty, /* 03 */
3302 mat.matched_uom_code, /* 04 */
3303 mat.replace_estim_qty_flag, /* 05 */
3304 mat.existing_match_info_flag, /* 06 */
3305 mat.matched_amt, /* 07 */
3306 -- sl.txn_qty, /* 08 */ -- Bug #7702294
3307 sl.primary_uom_code, /* 09a */
3308 sl.txn_uom_code, /* 09b */ --Bug #7674121
3309 sh.organization_id, /* 10 */
3310 sl.inventory_item_id, /* 11 */
3311 sl.ship_line_num, /* 12 */
3312 sl.ship_line_group_id, /* 13 */
3313 sl.currency_code, /* 14 */
3314 mat.matched_curr_code, /* 15 */
3315 NVL (mat.matched_curr_conversion_type, sl.currency_conversion_type), /* 16 */
3316 NVL (mat.matched_curr_conversion_date, sl.currency_conversion_date), /* 17 */
3317 sl.txn_unit_price, /* 18 */
3318 mat.from_parent_table_name, /* 19 */
3319 mat.from_parent_table_id, /* 20 */
3320 mat.match_id /* 21 */
3321 INTO
3322 l_to_ship_header_id , /* 01 */
3323 l_to_ship_line_id , /* 02 */
3324 l_matched_qty , /* 03 */
3325 l_matched_uom_code , /* 04 */
3326 l_replace_estim_qty_flag , /* 05 */
3327 l_existing_match_info_flag, /* 06 */
3328 l_matched_amt , /* 07 */
3329 -- l_net_rcv_txn_qty , /* 08 */ -- Bug #7702294
3330 l_primary_uom_code , /* 09a */
3331 l_txn_uom_code , /* 09b */ --Bug #7674121
3332 l_inv_org_id , /* 10 */
3333 l_sl_inv_item_id , /* 11 */
3334 l_ship_line_num , /* 12 */
3335 l_ship_line_group_id , /* 13 */
3336 l_ship_line_curr_code , /* 14 */
3337 l_current_curr_code , /* 15 */
3338 l_current_curr_conv_type , /* 16 */
3339 l_current_curr_conv_date , /* 17 */
3340 l_ori_unit_price , /* 18 */
3341 l_from_parent_table_name , /* 19 */
3342 l_from_parent_table_id , /* 20 */
3343 l_curr_match_id /* 21 */
3344 FROM inl_corr_matches_v mat,
3345 inl_ship_lines sl ,
3346 inl_ship_headers sh
3347 WHERE mat.match_id = p_match_id
3348 AND mat.to_parent_table_name = 'INL_SHIP_LINES'
3349 AND mat.adj_already_generated_flag = 'N'
3350 AND sl.ship_header_id = sh.ship_header_id
3351 AND sl.ship_line_id = mat.to_parent_table_id
3352 AND (mat.correction_match_id is null OR
3353 mat.correction_match_id = (select min(mat2.correction_match_id)
3354 FROM inl_corr_matches_v mat2
3355 WHERE mat2.match_id = p_match_id
3356 AND mat2.to_parent_table_name = 'INL_SHIP_LINES'
3357 AND mat2.adj_already_generated_flag = 'N'
3358 ));
3359
3360 -- Bug #7702294
3361 -- We should always consider the net rcv quantity, instead of the quantity of the
3362 -- last adjustment done in shipment line. That is because corrections/returns may have been done in RCV.
3363
3364 -- BUG #8235284
3365 SELECT rt.transaction_id,
3366 um.uom_code
3367 INTO l_rt_transaction_id,
3368 l_rt_uom_code
3369 FROM mtl_units_of_measure um,
3370 rcv_transactions rt,
3371 inl_ship_lines sl
3372 WHERE um.unit_of_measure = rt.unit_of_measure
3373 AND rt.destination_type_code = 'RECEIVING'
3374 AND rt.transaction_type = 'RECEIVE'
3375 AND rt.parent_transaction_id = -1
3376 AND rt.lcm_shipment_line_id = sl.ship_line_id
3377 AND rt.po_line_location_id = sl.ship_line_source_id
3378 AND sl.ship_line_src_type_code = 'PO'
3379 AND sl.ship_line_id = l_to_ship_line_id;
3380
3381 rcv_invoice_matching_sv.get_quantities
3382 (top_transaction_id => l_rt_transaction_id,
3383 ordered_po_qty => l_ordered_po_qty,
3384 cancelled_po_qty => l_cancelled_po_qty,
3385 received_po_qty => l_received_po_qty,
3386 corrected_po_qty => l_corrected_po_qty,
3387 delivered_po_qty => l_delivered_po_qty,
3388 rtv_po_qty => l_rtv_po_qty,
3389 billed_po_qty => l_billed_po_qty,
3390 accepted_po_qty => l_accepted_po_qty,
3391 rejected_po_qty => l_rejected_po_qty,
3392 ordered_txn_qty => l_ordered_txn_qty,
3393 cancelled_txn_qty => l_cancelled_txn_qty,
3394 received_txn_qty => l_received_txn_qty,
3395 corrected_txn_qty => l_corrected_txn_qty,
3396 delivered_txn_qty => l_delivered_txn_qty,
3397 rtv_txn_qty => l_rtv_txn_qty,
3398 billed_txn_qty => l_billed_txn_qty,
3399 accepted_txn_qty => l_accepted_txn_qty,
3400 rejected_txn_qty => l_rejected_txn_qty);
3401
3402 l_net_rcv_txn_qty := l_received_txn_qty + l_corrected_txn_qty - l_rtv_txn_qty;
3403
3404 l_debug_info := 'l_received_txn_qty';
3405 INL_LOGGING_PVT.Log_Variable ( p_module_name => g_module_name,
3406 p_procedure_name => l_api_name,
3407 p_var_name => l_debug_info,
3408 p_var_value => l_received_txn_qty);
3409
3410 l_debug_info := 'l_corrected_txn_qty';
3411 INL_LOGGING_PVT.Log_Variable ( p_module_name => g_module_name,
3412 p_procedure_name => l_api_name,
3413 p_var_name => l_debug_info,
3414 p_var_value => l_corrected_txn_qty);
3415
3416 l_debug_info := 'l_rtv_txn_qty';
3417 INL_LOGGING_PVT.Log_Variable ( p_module_name => g_module_name,
3418 p_procedure_name => l_api_name,
3419 p_var_name => l_debug_info,
3420 p_var_value => l_rtv_txn_qty);
3421
3422 l_debug_info := 'l_net_rcv_txn_qty';
3423 INL_LOGGING_PVT.Log_Variable ( p_module_name => g_module_name,
3424 p_procedure_name => l_api_name,
3425 p_var_name => l_debug_info,
3426 p_var_value => l_net_rcv_txn_qty);
3427
3428 -- Bug #7849658
3429 l_net_rcv_txn_qty := INL_LANDEDCOST_PVT.Converted_Qty (p_organization_id => l_inv_org_id,
3430 p_inventory_item_id => l_sl_inv_item_id,
3431 p_qty => l_net_rcv_txn_qty,
3432 p_from_uom_code => l_rt_uom_code,
3433 p_to_uom_code => l_txn_uom_code);
3434
3435 l_debug_info := 'l_net_rcv_txn_qty after UOM conversion';
3436 INL_LOGGING_PVT.Log_Variable ( p_module_name => g_module_name,
3437 p_procedure_name => l_api_name,
3438 p_var_name => l_debug_info,
3439 p_var_value => l_net_rcv_txn_qty);
3440
3441 -- Bug #7702294
3442
3443 IF l_current_curr_conv_type IS NOT NULL THEN
3444 l_shipl_unit_price := inl_landedcost_pvt.Converted_Amt ( l_ori_unit_price,
3445 l_ship_line_curr_code,
3446 l_current_curr_code,
3447 l_current_curr_conv_type,
3448 l_current_curr_conv_date,
3449 l_current_curr_conv_rate);
3450 ELSE
3451 l_shipl_unit_price := l_ori_unit_price;
3452 l_current_curr_conv_rate := NULL;
3453 END IF;
3454
3455 l_debug_info := 'l_to_ship_header_id';
3456 INL_LOGGING_PVT.Log_Variable ( p_module_name => g_module_name,
3457 p_procedure_name => l_api_name,
3458 p_var_name => l_debug_info,
3459 p_var_value => l_to_ship_header_id) ;
3460 l_debug_info := 'l_to_ship_line_id';
3461 INL_LOGGING_PVT.Log_Variable ( p_module_name => g_module_name,
3462 p_procedure_name => l_api_name,
3463 p_var_name => l_debug_info,
3464 p_var_value => l_to_ship_line_id) ;
3465 l_debug_info := 'l_matched_qty';
3466 INL_LOGGING_PVT.Log_Variable ( p_module_name => g_module_name,
3467 p_procedure_name => l_api_name,
3468 p_var_name => l_debug_info,
3469 p_var_value => l_matched_qty) ;
3470 l_debug_info := 'l_matched_uom_code';
3471 INL_LOGGING_PVT.Log_Variable ( p_module_name => g_module_name,
3472 p_procedure_name => l_api_name,
3473 p_var_name => l_debug_info,
3474 p_var_value => l_matched_uom_code) ;
3475 -- STEP 2: Get Estimated Shipment Line Data
3476 l_debug_info := 'Get Estimated Shipment Line Data';
3477 INL_LOGGING_PVT.Log_Statement ( p_module_name => g_module_name,
3478 p_procedure_name => l_api_name,
3479 p_debug_info => l_debug_info) ;
3480 l_debug_info := 'l_sl_inv_item_id';
3481 INL_LOGGING_PVT.Log_Variable ( p_module_name => g_module_name,
3482 p_procedure_name => l_api_name,
3483 p_var_name => l_debug_info,
3484 p_var_value => l_sl_inv_item_id) ;
3485 l_debug_info := 'l_net_rcv_txn_qty';
3486 INL_LOGGING_PVT.Log_Variable ( p_module_name => g_module_name,
3487 p_procedure_name => l_api_name,
3488 p_var_name => l_debug_info,
3489 p_var_value => l_net_rcv_txn_qty) ;
3490 l_debug_info := 'l_shipl_unit_price';
3491 INL_LOGGING_PVT.Log_Variable ( p_module_name => g_module_name,
3492 p_procedure_name => l_api_name,
3493 p_var_name => l_debug_info,
3494 p_var_value => l_shipl_unit_price) ;
3495 -- STEP 3: Get the Adjustment Number
3496 l_debug_info := 'Get the Adjustment Number';
3497 INL_LOGGING_PVT.Log_Statement ( p_module_name => g_module_name,
3498 p_procedure_name => l_api_name,
3499 p_debug_info => l_debug_info) ;
3500 l_next_adjust_num := p_adjustment_num;
3501 l_debug_info := 'l_next_adjust_num';
3502 INL_LOGGING_PVT.Log_Variable ( p_module_name => g_module_name,
3503 p_procedure_name => l_api_name,
3504 p_var_name => l_debug_info,
3505 p_var_value => l_next_adjust_num) ;
3506 -- STEP 4: Partial Matching handling
3507 --IF l_matched_qty < l_opl_txn_qty THEN
3508 --Calculate Partial Matching based on previous Adjustments
3509 l_debug_info := 'Calculate Partial Matching based on previous Adjustments';
3510 INL_LOGGING_PVT.Log_Statement (
3511 p_module_name => g_module_name,
3512 p_procedure_name => l_api_name,
3513 p_debug_info => l_debug_info
3514 );
3515 IF l_replace_estim_qty_flag = 'Y' THEN --Match from RCV
3516 l_debug_info := 'Getting the values from Adj';
3517 INL_LOGGING_PVT.Log_Statement (
3518 p_module_name => g_module_name,
3519 p_procedure_name => l_api_name,
3520 p_debug_info => l_debug_info
3521 );
3522 SELECT txn_unit_price,
3523 txn_qty ,
3524 primary_qty ,
3525 primary_unit_price
3526 INTO l_final_price,
3527 l_final_qty ,
3528 l_primary_qty ,
3529 l_primary_unit_price
3530 FROM inl_adj_ship_lines_v
3531 WHERE ship_header_id = l_to_ship_header_id
3532 AND ship_line_group_id = l_ship_line_group_id
3533 AND ship_line_num = l_ship_line_num;
3534
3535 l_final_price := l_matched_amt / l_matched_qty;
3536 l_debug_info := 'Setting the new quantity ';
3537 INL_LOGGING_PVT.Log_Statement (
3538 p_module_name => g_module_name,
3539 p_procedure_name => l_api_name,
3540 p_debug_info => l_debug_info
3541 ) ;
3542 IF l_final_qty = l_primary_qty THEN
3543 l_final_qty := l_matched_qty;
3544 l_primary_qty := l_matched_qty;
3545 l_primary_unit_price := l_final_price;
3546 ELSE
3547 l_final_qty := l_matched_qty;
3548 -- Getting Primary Quantity and Primary Unit Price
3549 l_primary_qty := INL_LANDEDCOST_PVT.Converted_Qty (
3550 p_organization_id => l_inv_org_id,
3551 p_inventory_item_id => l_sl_inv_item_id,
3552 p_qty => l_final_qty,
3553 p_from_uom_code => l_matched_uom_code,
3554 p_to_uom_code => l_primary_uom_code
3555 ) ;
3556 l_primary_unit_price := (l_final_qty * l_final_price) / l_primary_qty;
3557 END IF;
3558 ELSE
3559 l_debug_info := 'l_existing_match_info_flag';
3560 INL_LOGGING_PVT.Log_Variable (
3561 p_module_name => g_module_name,
3562 p_procedure_name => l_api_name,
3563 p_var_name => l_debug_info,
3564 p_var_value => l_existing_match_info_flag
3565 ) ;
3566
3567 FOR l_prev_matchings_rec IN c_previous_matchings (
3568 l_to_ship_line_id,
3569 l_curr_match_id,
3570 l_current_curr_code,
3571 l_current_curr_conv_type,
3572 l_current_curr_conv_date
3573 )
3574 LOOP
3575
3576 l_sum_adj_price := NVL (l_sum_adj_price, 0) + NVL(l_prev_matchings_rec.matched_amt,0);
3577 --shouldn't be consider IF NVL(l_prev_matchings_rec.matched_qty,0) > 0 THEN -- BUG#8198265
3578 l_final_qty := NVL (l_final_qty, 0) + NVL(l_prev_matchings_rec.matched_qty,0);
3579 --shouldn't be consider END IF;
3580
3581 END LOOP;
3582 -- Add the current transaction values to the calculation
3583 l_debug_info := 'Add the current transaction values to the calculation';
3584
3585 INL_LOGGING_PVT.Log_Statement (
3586 p_module_name => g_module_name,
3587 p_procedure_name => l_api_name,
3588 p_debug_info => l_debug_info
3589 ) ;
3590 --shouldn't be consider IF NVL(l_matched_qty,0) > 0 THEN -- BUG#8198265
3591 l_final_qty := NVL (l_final_qty, 0) + NVL (l_matched_qty, 0) ;
3592 --shouldn't be consider END IF;
3593 IF l_final_qty < 0 then
3594 l_final_qty := 0; -- BUG#8198265
3595 END IF;
3596 l_sum_adj_price := NVL (l_sum_adj_price, 0) + l_matched_amt;
3597 IF NVL (l_final_qty, 0) < NVL (l_net_rcv_txn_qty, 0) THEN -- BUG#8198265
3598 l_shipl_qty_sub_match := NVL (l_net_rcv_txn_qty, 0) - NVL (l_final_qty, 0) ;
3599 ELSE
3600 l_shipl_qty_sub_match := 0;
3601 END IF;
3602 l_sum_adj_price := NVL (l_sum_adj_price, 0) + (l_shipl_qty_sub_match * nvl(l_shipl_unit_price,0)) ;
3603 l_final_qty := NVL (l_final_qty, 0) + l_shipl_qty_sub_match;
3604 l_final_price := l_sum_adj_price / l_final_qty;
3605 --
3606 -- The code above this point should be review in order to verify the necessity of l_final_qty
3607 --
3608 l_final_qty := l_net_rcv_txn_qty; --BUG#8198265
3609 l_final_price := l_sum_adj_price / l_final_qty; --BUG#8198265
3610
3611
3612 l_debug_info := 'l_final_qty';
3613 INL_LOGGING_PVT.Log_Variable (
3614 p_module_name => g_module_name,
3615 p_procedure_name => l_api_name,
3616 p_var_name => l_debug_info,
3617 p_var_value => l_final_qty
3618 ) ;
3619 l_debug_info := 'l_final_price';
3620 INL_LOGGING_PVT.Log_Variable (
3621 p_module_name => g_module_name,
3622 p_procedure_name => l_api_name,
3623 p_var_name => l_debug_info,
3624 p_var_value => l_final_price
3625 ) ;
3626 IF l_matched_uom_code IS NULL THEN --BUG#7674121
3627 l_matched_uom_code := l_txn_uom_code; --BUG#7674121
3628 END IF;
3629 -- Verifying if UOM conversion are required
3630 IF l_primary_uom_code <> l_matched_uom_code THEN --BUG#7674121
3631 l_primary_qty := INL_LANDEDCOST_PVT.Converted_Qty (
3632 p_organization_id => l_inv_org_id,
3633 p_inventory_item_id => l_sl_inv_item_id,
3634 p_qty => l_final_qty,
3635 p_from_uom_code => l_matched_uom_code,
3636 p_to_uom_code => l_primary_uom_code) ;
3637 ELSE
3638 l_primary_qty := l_final_qty;
3639 END IF;
3640 l_primary_unit_price := (l_final_qty * l_final_price) / l_primary_qty;
3641 -- STEP 5: Copy Shipment Line from Estimated to Actual
3642 l_debug_info := 'Copy Shipment Line from Estimated to Actual';
3643 INL_LOGGING_PVT.Log_Statement (
3644 p_module_name => g_module_name,
3645 p_procedure_name => l_api_name,
3646 p_debug_info => l_debug_info
3647 ) ;
3648 END IF;
3649
3650 INSERT
3651 INTO inl_ship_lines_all
3652 (
3653 ship_header_id, /* 01 */
3654 ship_line_group_id, /* 02 */
3655 ship_line_id, /* 03 */
3656 ship_line_num, /* 04 */
3657 ship_line_type_id, /* 05 */
3658 ship_line_src_type_code, /* 06 */
3659 ship_line_source_id, /* 07 */
3660 parent_ship_line_id, /* 08 */
3661 adjustment_num, /* 09 */
3662 match_id, /* 10 */
3663 currency_code, /* 12 */
3664 currency_conversion_type, /* 13 */
3665 currency_conversion_date, /* 14 */
3666 currency_conversion_rate, /* 15 */
3667 inventory_item_id, /* 16 */
3668 txn_qty, /* 17 */
3669 txn_uom_code, /* 18 */
3670 txn_unit_price, /* 19 */
3671 primary_qty, /* 20 */
3672 primary_uom_code, /* 21 */
3673 primary_unit_price, /* 22 */
3674 secondary_qty, /* 23 */
3675 secondary_uom_code, /* 24 */
3676 secondary_unit_price, /* 25 */
3677 landed_cost_flag, /* 30 */
3678 allocation_enabled_flag, /* 31 */
3679 trx_business_category, /* 32 */
3680 intended_use, /* 33 */
3681 product_fiscal_class, /* 34 */
3682 product_category, /* 35 */
3683 product_type, /* 36 */
3684 user_def_fiscal_class, /* 37 */
3685 tax_classification_code, /* 38 */
3686 assessable_value, /* 39 */
3687 tax_already_calculated_flag,/* 40 */
3688 ship_from_party_id, /* 41 */
3689 ship_from_party_site_id, /* 42 */
3690 ship_to_organization_id, /* 43 */
3691 ship_to_location_id, /* 44 */
3692 bill_from_party_id, /* 45 */
3693 bill_from_party_site_id, /* 46 */
3694 bill_to_organization_id, /* 47 */
3695 bill_to_location_id, /* 48 */
3696 poa_party_id, /* 49 */
3697 poa_party_site_id, /* 50 */
3698 poo_organization_id, /* 51 */
3699 poo_location_id, /* 52 */
3700 org_id, /* 53 */
3701 created_by, /* 54 */
3702 creation_date, /* 55 */
3703 last_updated_by, /* 56 */
3704 last_update_date, /* 57 */
3705 last_update_login, /* 58 */
3706 program_id, /* 59 */
3707 program_update_date, /* 60 */
3708 program_application_id, /* 61 */
3709 request_id, /* 62 */
3710 attribute_category, /* 63 */
3711 attribute1, /* 64 */
3712 attribute2, /* 65 */
3713 attribute3, /* 66 */
3714 attribute4, /* 67 */
3715 attribute5, /* 68 */
3716 attribute6, /* 69 */
3717 attribute7, /* 70 */
3718 attribute8, /* 71 */
3719 attribute9, /* 72 */
3720 attribute10, /* 73 */
3721 attribute11, /* 74 */
3722 attribute12, /* 75 */
3723 attribute13, /* 76 */
3724 attribute14, /* 77 */
3725 attribute15 /* 78 */
3726 )
3727 SELECT sl.ship_header_id, /* 01 */
3728 sl.ship_line_group_id, /* 02 */
3729 inl_ship_lines_all_s.NEXTVAL, /* 03 */
3730 sl.ship_line_num, /* 04 */
3731 sl.ship_line_type_id, /* 05 */
3732 sl.ship_line_src_type_code, /* 06 */
3733 sl.ship_line_source_id, /* 07 */
3734 sl.ship_line_id, /* 08 */
3735 l_next_adjust_num, /* 09 */
3736 p_match_id, /* 10 */
3737 l_current_curr_code, /* 12 */
3738 l_current_curr_conv_type, /* 13 */
3739 l_current_curr_conv_date, /* 14 */
3740 l_current_curr_conv_rate, /* 15 */
3741 sl.inventory_item_id, /* 16 */
3742 l_final_qty, /* 17 */
3743 l_txn_uom_code, /* 18 */ --BUG#8198265
3744 l_final_price, /* 19 */
3745 l_primary_qty, /* 20 */
3746 l_primary_uom_code, /* 21 */ --BUG#8198265
3747 l_primary_unit_price, /* 22 */
3748 sl.secondary_qty, /* 23 */
3749 sl.secondary_uom_code, /* 24 */
3750 sl.secondary_unit_price, /* 25 */
3751 sl.landed_cost_flag, /* 30 */
3752 sl.allocation_enabled_flag, /* 31 */
3753 sl.trx_business_category, /* 32 */
3754 sl.intended_use, /* 33 */
3755 sl.product_fiscal_class, /* 34 */
3756 sl.product_category, /* 35 */
3757 sl.product_type, /* 36 */
3758 sl.user_def_fiscal_class, /* 37 */
3759 sl.tax_classification_code, /* 38 */
3760 sl.assessable_value, /* 39 */
3761 'N' , -- tax_already_calculated_flag/* 40 */
3762 sl.ship_from_party_id, /* 41 */
3763 sl.ship_from_party_site_id, /* 42 */
3764 sl.ship_to_organization_id, /* 43 */
3765 sl.ship_to_location_id, /* 44 */
3766 sl.bill_from_party_id, /* 45 */
3767 sl.bill_from_party_site_id, /* 46 */
3768 sl.bill_to_organization_id, /* 47 */
3769 sl.bill_to_location_id, /* 48 */
3770 sl.poa_party_id, /* 49 */
3771 sl.poa_party_site_id, /* 50 */
3772 sl.poo_organization_id, /* 51 */
3773 sl.poo_location_id, /* 52 */
3774 sl.org_id, /* 53 */
3775 sl.created_by, /* 54 */
3776 sl.creation_date, /* 55 */
3777 sl.last_updated_by, /* 56 */
3778 sl.last_update_date, /* 57 */
3779 sl.last_update_login, /* 58 */
3780 sl.program_id, /* 59 */
3781 sl.program_update_date, /* 60 */
3782 sl.program_application_id, /* 61 */
3783 sl.request_id, /* 62 */
3784 sl.attribute_category, /* 63 */
3785 sl.attribute1, /* 64 */
3786 sl.attribute2, /* 65 */
3787 sl.attribute3, /* 66 */
3788 sl.attribute4, /* 67 */
3789 sl.attribute5, /* 68 */
3790 sl.attribute6, /* 69 */
3791 sl.attribute7, /* 70 */
3792 sl.attribute8, /* 71 */
3793 sl.attribute9, /* 72 */
3794 sl.attribute10, /* 73 */
3795 sl.attribute11, /* 74 */
3796 sl.attribute12, /* 75 */
3797 sl.attribute13, /* 76 */
3798 sl.attribute14, /* 77 */
3799 sl.attribute15 /* 78 */
3800 FROM inl_ship_lines sl
3801 WHERE ship_line_id = l_to_ship_line_id;
3802 IF l_replace_estim_qty_flag = 'N' THEN --THIS TRANSACTION IS ABOUT AN ACTUAL VALUE
3803 -- IF SHIP LINE HAS ESTIMATED TAXES THEY WILL WILL BE = 0
3804 Zero_EstimTaxLines (
3805 p_ship_header_id => NULL,
3806 p_match_id => p_match_id,
3807 p_comp_name => 'INL_SHIP_LINES',
3808 p_comp_id => l_to_ship_line_id,
3809 p_tax_code => NULL,
3810 p_adjustment_num => p_adjustment_num,
3811 x_return_status => l_return_status
3812 ) ;
3813 IF l_return_status = FND_API.G_RET_STS_ERROR THEN
3814 RAISE FND_API.G_EXC_ERROR;
3815 ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
3816 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3817 END IF;
3818 END IF;
3819 -- Standard check of p_commit.
3820 IF FND_API.To_Boolean (p_commit) THEN
3821 COMMIT WORK;
3822 END IF;
3823 -- Standard call to get message count and if count is 1, get message info.
3824 FND_MSG_PUB.Count_And_Get (
3825 p_encoded => FND_API.g_false,
3826 p_count => x_msg_count,
3827 p_data => x_msg_data
3828 ) ;
3829 -- Standard End of Procedure/Function Logging
3830 INL_LOGGING_PVT.Log_EndProc (
3831 p_module_name => g_module_name,
3832 p_procedure_name => l_api_name
3833 ) ;
3834 EXCEPTION
3835 WHEN FND_API.G_EXC_ERROR THEN
3836 -- Standard Expected Error Logging
3837 INL_LOGGING_PVT.Log_ExpecError (
3838 p_module_name => g_module_name,
3839 p_procedure_name => l_api_name
3840 ) ;
3841 ROLLBACK TO Adjust_ShipLines_PVT;
3842 x_return_status := FND_API.G_RET_STS_ERROR;
3843 FND_MSG_PUB.Count_And_Get (
3844 p_encoded => FND_API.g_false,
3845 p_count => x_msg_count,
3846 p_data => x_msg_data
3847 ) ;
3848 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
3849 -- Standard Unexpected Error Logging
3850 INL_LOGGING_PVT.Log_UnexpecError (
3851 p_module_name => g_module_name,
3852 p_procedure_name => l_api_name
3853 ) ;
3854 ROLLBACK TO Adjust_ShipLines_PVT;
3855 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3856 FND_MSG_PUB.Count_And_Get (
3857 p_encoded => FND_API.g_false,
3858 p_count => x_msg_count,
3859 p_data => x_msg_data
3860 ) ;
3861 WHEN OTHERS THEN
3862 -- Standard Unexpected Error Logging
3863 INL_LOGGING_PVT.Log_UnexpecError (
3864 p_module_name => g_module_name,
3865 p_procedure_name => l_api_name
3866 ) ;
3867 ROLLBACK TO Adjust_ShipLines_PVT;
3868 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
3869 IF FND_MSG_PUB.Check_Msg_Level (p_message_level => FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
3870 FND_MSG_PUB.Add_Exc_Msg (
3871 p_pkg_name => g_pkg_name,
3872 p_procedure_name => l_api_name
3873 ) ;
3874 END IF;
3875 FND_MSG_PUB.Count_And_Get (
3876 p_encoded => FND_API.g_false,
3877 p_count => x_msg_count,
3878 p_data => x_msg_data
3879 ) ;
3880 END Adjust_ShipLines;
3881
3882 -- Utility name: Create_ChLines
3883 -- Type : Private
3884 -- Function : Create Charge Lines
3885 -- Pre-reqs : None
3886 -- Parameters :
3887 -- IN : p_ChLn_Assoc IN inl_ChLn_Assoc_tp
3888 -- p_include_assoc IN VARCHAR2 := 'Y'
3889 -- p_adjustment_num IN NUMBER
3890 --
3891 -- OUT : x_new_charge_line_id OUT NUMBER new charge line at a ship line level
3892 -- x_return_status OUT NOCOPY VARCHAR2
3893 --
3894 -- Version : Current version 1.0
3895 --
3896 -- Notes :
3897 PROCEDURE Create_ChLines(
3898 p_ChLn_Assoc IN inl_ChLn_Assoc_tp,
3899 p_include_assoc IN VARCHAR2 := 'Y',
3900 p_adjustment_num IN NUMBER,
3901 x_new_charge_line_id OUT NOCOPY NUMBER,
3902 x_return_status OUT NOCOPY VARCHAR2
3903 ) IS
3904 l_proc_name CONSTANT VARCHAR2 (30) := 'Create_ChLines';
3905 l_return_status VARCHAR2 (1) ;
3906 l_debug_info VARCHAR2 (200) ;
3907 l_charge_line_num NUMBER;
3908 l_adjustment_num NUMBER;
3909 BEGIN
3910 -- Standard Beginning of Procedure/Function Logging
3911 INL_LOGGING_PVT.Log_BeginProc ( p_module_name => g_module_name, p_procedure_name => l_proc_name) ;
3912 -- Initialize return status to success
3913 x_return_status := FND_API.G_RET_STS_SUCCESS;
3914 --
3915 -- Get Max val to charge line num
3916 --
3917 IF p_ChLn_Assoc.charge_line_num IS NULL THEN
3918 l_debug_info := 'Get Max val from charge line num';
3919 INL_LOGGING_PVT.Log_Statement (
3920 p_module_name => g_module_name,
3921 p_procedure_name => l_proc_name,
3922 p_debug_info => l_debug_info
3923 ) ;
3924 SELECT NVL (MAX (cl.charge_line_num), 0) + 1
3925 INTO l_charge_line_num
3926 FROM inl_charge_lines cl
3927 WHERE NVL (cl.parent_charge_line_id, cl.charge_line_id) IN
3928 (
3929 SELECT assoc.from_parent_table_id
3930 FROM inl_associations assoc
3931 WHERE assoc.from_parent_table_name = 'INL_CHARGE_LINES'
3932 AND assoc.ship_header_id = NVL (p_ChLn_Assoc.inl_Assoc.ship_header_id, 0)
3933 ) ;
3934 ELSE
3935 l_charge_line_num := p_ChLn_Assoc.charge_line_num;
3936 END IF;
3937 --
3938 -- Get Val to adjustment num
3939 --
3940 IF p_ChLn_Assoc.adjustment_num IS NULL THEN
3941 l_adjustment_num := p_adjustment_num;
3942 ELSE
3943 l_adjustment_num := p_ChLn_Assoc.adjustment_num;
3944 END IF;
3945 --
3946 -- Get inl_charge_lines_s.nextval
3947 --
3948 l_debug_info := 'Get inl_charge_lines_s.nextval';
3949 INL_LOGGING_PVT.Log_Statement (
3950 p_module_name => g_module_name,
3951 p_procedure_name => l_proc_name,
3952 p_debug_info => l_debug_info
3953 ) ;
3954 SELECT inl_charge_lines_s.nextval
3955 INTO x_new_charge_line_id FROM dual;
3956 --
3957 -- include Charge Line record
3958 --
3959 l_debug_info := 'Including Charge Line record ';
3960 INL_LOGGING_PVT.Log_Statement (
3961 p_module_name => g_module_name,
3962 p_procedure_name => l_proc_name,
3963 p_debug_info => l_debug_info
3964 ) ;
3965 INSERT
3966 INTO inl_charge_lines
3967 (
3968 charge_line_id, /* 01 */
3969 charge_line_num, /* 02 */
3970 charge_line_type_id, /* 03 */
3971 landed_cost_flag, /* 04 */
3972 parent_charge_line_id, /* 06 */
3973 adjustment_num, /* 07 */
3974 match_id, /* 08 */
3975 match_amount_id, /* 09 */
3976 charge_amt, /* 11 */
3977 currency_code, /* 12 */
3978 currency_conversion_type, /* 13 */
3979 currency_conversion_date, /* 14 */
3980 currency_conversion_rate, /* 15 */
3981 party_id, /* 16 */
3982 party_site_id, /* 17 */
3983 trx_business_category, /* 18 */
3984 intended_use, /* 19 */
3985 product_fiscal_class, /* 20 */
3986 product_category, /* 21 */
3987 product_type, /* 22 */
3988 user_def_fiscal_class, /* 23 */
3989 tax_classification_code, /* 24 */
3990 assessable_value, /* 25 */
3991 tax_already_calculated_flag, /* 26 */
3992 ship_from_party_id, /* 27 */
3993 ship_from_party_site_id, /* 28 */
3994 ship_to_organization_id, /* 29 */
3995 ship_to_location_id, /* 30 */
3996 bill_from_party_id, /* 31 */
3997 bill_from_party_site_id, /* 32 */
3998 bill_to_organization_id, /* 34 */
3999 bill_to_location_id, /* 34 */
4000 poa_party_id, /* 35 */
4001 poa_party_site_id, /* 36 */
4002 poo_organization_id, /* 37 */
4003 poo_location_id, /* 38 */
4004 created_by, /* 39 */
4005 creation_date, /* 40 */
4006 last_updated_by, /* 41 */
4007 last_update_date, /* 42 */
4008 last_update_login /* 43 */
4009 )
4010 VALUES
4011 (
4012 x_new_charge_line_id, /* 01 */
4013 l_charge_line_num, /* 02 */
4014 p_ChLn_Assoc.charge_line_type_id, /* 03 */
4015 p_ChLn_Assoc.landed_cost_flag, /* 04 */
4016 p_ChLn_Assoc.parent_charge_line_id, /* 06 */
4017 l_adjustment_num, /* 07 */
4018 p_ChLn_Assoc.match_id, /* 08 */
4019 p_ChLn_Assoc.match_amount_id, /* 09 */
4020 p_ChLn_Assoc.charge_amt, /* 11 */
4021 p_ChLn_Assoc.currency_code, /* 12 */
4022 p_ChLn_Assoc.currency_conversion_type, /* 13 */
4023 p_ChLn_Assoc.currency_conversion_date, /* 14 */
4024 p_ChLn_Assoc.currency_conversion_rate, /* 15 */
4025 p_ChLn_Assoc.party_id, /* 16 */
4026 p_ChLn_Assoc.party_site_id, /* 17 */
4027 p_ChLn_Assoc.trx_business_category, /* 18 */
4028 p_ChLn_Assoc.intended_use, /* 19 */
4029 p_ChLn_Assoc.product_fiscal_class, /* 20 */
4030 p_ChLn_Assoc.product_category, /* 21 */
4031 p_ChLn_Assoc.product_type, /* 22 */
4032 p_ChLn_Assoc.user_def_fiscal_class, /* 23 */
4033 p_ChLn_Assoc.tax_classification_code, /* 24 */
4034 p_ChLn_Assoc.assessable_value, /* 25 */
4035 p_ChLn_Assoc.tax_already_calculated_flag,/* 26 */
4036 p_ChLn_Assoc.ship_from_party_id, /* 27 */
4037 p_ChLn_Assoc.ship_from_party_site_id, /* 28 */
4038 p_ChLn_Assoc.ship_to_organization_id, /* 29 */
4039 p_ChLn_Assoc.ship_to_location_id, /* 30 */
4040 p_ChLn_Assoc.bill_from_party_id, /* 31 */
4041 p_ChLn_Assoc.bill_from_party_site_id, /* 32 */
4042 p_ChLn_Assoc.bill_to_organization_id, /* 33 */
4043 p_ChLn_Assoc.bill_to_location_id, /* 34 */
4044 p_ChLn_Assoc.poa_party_id, /* 35 */
4045 p_ChLn_Assoc.poa_party_site_id, /* 36 */
4046 p_ChLn_Assoc.poo_organization_id, /* 37 */
4047 p_ChLn_Assoc.poo_location_id, /* 38 */
4048 fnd_global.user_id, /* 39 */
4049 sysdate, /* 40 */
4050 fnd_global.user_id, /* 41 */
4051 sysdate, /* 42 */
4052 fnd_global.user_id /* 43 */
4053 ) ;
4054
4055 IF p_include_assoc = 'Y' THEN
4056 Create_Assoc (
4057 p_Assoc => p_ChLn_Assoc.inl_Assoc,
4058 p_from_parent_table_name => 'INL_CHARGE_LINES',
4059 p_new_line_id => x_new_charge_line_id,
4060 x_return_status => l_return_status
4061 );
4062 IF l_return_status = FND_API.G_RET_STS_ERROR THEN
4063 RAISE FND_API.G_EXC_ERROR;
4064 ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4065 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4066 END IF;
4067 END IF;
4068 -- Standard End of Procedure/Function Logging
4069 INL_LOGGING_PVT.Log_EndProc(
4070 p_module_name => g_module_name,
4071 p_procedure_name => l_proc_name
4072 );
4073 EXCEPTION
4074 WHEN FND_API.G_EXC_ERROR THEN
4075 -- Standard Expected Error Logging
4076 INL_LOGGING_PVT.Log_ExpecError(
4077 p_module_name => g_module_name,
4078 p_procedure_name => l_proc_name
4079 );
4080 x_return_status := FND_API.G_RET_STS_ERROR;
4081 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
4082 -- Standard Unexpected Error Logging
4083 INL_LOGGING_PVT.Log_UnexpecError(
4084 p_module_name => g_module_name,
4085 p_procedure_name => l_proc_name
4086 );
4087 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4088 WHEN OTHERS THEN
4089 -- Standard Unexpected Error Logging
4090 INL_LOGGING_PVT.Log_UnexpecError(
4091 p_module_name => g_module_name,
4092 p_procedure_name => l_proc_name
4093 );
4094 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
4095 IF FND_MSG_PUB.Check_Msg_Level(p_message_level => FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
4096 THEN
4097 FND_MSG_PUB.Add_Exc_Msg(
4098 p_pkg_name => g_pkg_name,
4099 p_procedure_name => l_proc_name
4100 );
4101 END IF;
4102 END Create_ChLines;
4103
4104 -- Utility name: Zero_EstimChargeLinesPerMatch
4105 -- Type : Private
4106 -- Function : bring to zero the estimated charge line
4107 -- Pre-reqs : None
4108 -- Parameters :
4109 -- IN : p_match_id IN NUMBER,
4110 -- p_match_Amount_id IN NUMBER,
4111 -- p_charge_line_type_id IN NUMBER,
4112 --
4113 -- OUT : x_return_status OUT NOCOPY VARCHAR2
4114 --
4115 -- Version : Current version 1.0
4116 --
4117 -- Notes :
4118 PROCEDURE Zero_EstimChargeLinesPerMatch (
4119 p_match_id IN NUMBER,
4120 p_match_Amount_id IN NUMBER,
4121 p_charge_line_type_id IN NUMBER,
4122 p_adjustment_num IN NUMBER,
4123 x_return_status OUT NOCOPY VARCHAR2
4124 ) IS
4125 l_proc_name CONSTANT VARCHAR2(30) := 'Zero_EstimChargeLinesPerMatch';
4126 l_return_status VARCHAR2(1);
4127 l_debug_info VARCHAR2(200);
4128
4129 CURSOR get_level
4130 IS
4131 SELECT
4132 assoc.to_parent_table_name,
4133 assoc.to_parent_table_id,
4134 assoc.ship_header_id
4135 FROM inl_associations assoc,
4136 inl_charge_lines cl
4137 WHERE assoc.from_parent_table_name = 'INL_CHARGE_LINES'
4138 AND assoc.from_parent_table_id = cl.charge_line_id
4139 AND cl.charge_line_type_id = p_charge_line_type_id
4140 AND EXISTS
4141 (SELECT 1
4142 FROM inl_matches m
4143 WHERE assoc.ship_header_id = m.ship_header_id
4144 AND
4145 ((p_match_id IS NOT NULL
4146 AND m.match_id = p_match_id )
4147 OR (p_match_Amount_id IS NOT NULL
4148 AND EXISTS (SELECT 1
4149 FROM inl_matches m2
4150 WHERE m2.match_id = m.match_id
4151 AND m2.match_Amount_id = p_match_Amount_id
4152 AND rownum <2)))
4153 AND rownum <2
4154 )
4155 UNION ALL
4156 SELECT
4157 m.to_parent_table_name,
4158 m.to_parent_table_id,
4159 m.ship_header_id
4160 FROM inl_matches m
4161 WHERE ((p_match_id IS NOT NULL
4162 AND m.match_id = p_match_id )
4163 OR
4164 (p_match_Amount_id IS NOT NULL
4165 AND EXISTS (SELECT 1
4166 FROM inl_matches m2
4167 WHERE m2.match_id = m.match_id
4168 AND m2.match_Amount_id = p_match_Amount_id
4169 AND rownum <2)))
4170 ;
4171
4172 TYPE get_level_Type
4173 IS
4174 TABLE OF get_level%ROWTYPE;
4175 C_get_level get_level_Type;
4176
4177 CURSOR estimated_CL (pc_level VARCHAR2)
4178 IS
4179 SELECT charge_line_num ,
4180 charge_line_type_id ,
4181 landed_cost_flag ,
4182 charge_line_id ,
4183 adjustment_num ,
4184 match_id ,
4185 currency_code ,
4186 currency_conversion_type ,
4187 currency_conversion_date ,
4188 currency_conversion_rate ,
4189 party_id ,
4190 party_site_id ,
4191 trx_business_category ,
4192 intended_use ,
4193 product_fiscal_class ,
4194 product_category ,
4195 product_type ,
4196 user_def_fiscal_class ,
4197 tax_classification_code ,
4198 tax_already_calculated_flag,
4199 ship_from_party_id ,
4200 ship_from_party_site_id ,
4201 ship_to_organization_id ,
4202 ship_to_location_id ,
4203 bill_from_party_id ,
4204 bill_from_party_site_id ,
4205 bill_to_organization_id ,
4206 bill_to_location_id ,
4207 poa_party_id ,
4208 poa_party_site_id ,
4209 poo_organization_id ,
4210 poo_location_id
4211 FROM inl_adj_charge_lines_v cl
4212 WHERE cl.adjustment_num = 0
4213 AND cl.charge_line_type_id = p_charge_line_type_id
4214 AND EXISTS
4215 (
4216 SELECT 1
4217 FROM inl_associations assoc
4218 WHERE assoc.from_parent_table_name = 'INL_CHARGE_LINES'
4219 AND assoc.from_parent_table_id = NVL (cl.parent_charge_line_id, cl.charge_line_id)
4220 AND (
4221 (
4222 pc_level = 'ALL'
4223 AND EXISTS (SELECT 1
4224 FROM inl_matches m
4225 WHERE m.ship_header_id = assoc.ship_header_id
4226 AND
4227 ((p_match_id IS NOT NULL
4228 AND m.match_id = p_match_id )
4229 OR (p_match_Amount_id IS NOT NULL
4230 AND EXISTS (SELECT 1
4231 FROM inl_matches m2
4232 WHERE m2.match_id = m.match_id
4233 AND m2.match_Amount_id = p_match_Amount_id
4234 AND rownum <2)))
4235 AND rownum <2
4236
4237 )
4238 )
4239 OR (pc_level = 'LINE'
4240 AND assoc.to_parent_table_name = 'INL_SHIP_LINES'
4241 AND EXISTS
4242 (SELECT 1
4243 FROM inl_matches m
4244 WHERE m.ship_header_id = assoc.ship_header_id
4245 AND m.to_parent_table_name = 'INL_SHIP_LINES'
4246 AND m.to_parent_table_id = assoc.to_parent_table_id
4247 AND
4248 ((p_match_id IS NOT NULL
4249 AND m.match_id = p_match_id )
4250 OR (p_match_Amount_id IS NOT NULL
4251 AND EXISTS (SELECT 1
4252 FROM inl_matches m2
4253 WHERE m2.match_id = m.match_id
4254 AND m2.match_Amount_id = p_match_Amount_id
4255 AND rownum <2)))
4256 AND rownum <2
4257 ) )
4258
4259 OR (pc_level = 'GROUP'
4260 AND assoc.to_parent_table_name IN ('INL_SHIP_LINES','INL_SHIP_LINE_GROUPS')
4261 AND EXISTS
4262 (SELECT 1
4263 FROM inl_matches m
4264 WHERE m.ship_header_id = assoc.ship_header_id
4265 AND (
4266 ( m.to_parent_table_name = assoc.to_parent_table_name
4267 AND m.to_parent_table_id = assoc.to_parent_table_id
4268 )
4269 OR
4270 (assoc.to_parent_table_name = 'INL_SHIP_LINES'
4271 AND EXISTS (
4272 select 1
4273 from inl_ship_lines sl
4274 where m.to_parent_table_name = 'INL_SHIP_LINE_GROUPS'
4275 AND sl.ship_line_group_id = m.to_parent_table_id
4276 )
4277 )
4278 OR
4279 (assoc.to_parent_table_name = 'INL_SHIP_LINE_GROUPS'
4280 AND EXISTS (
4281 select 1
4282 from inl_ship_lines sl
4283 where m.to_parent_table_name = 'INL_SHIP_LINES'
4284 AND sl.ship_line_id = m.to_parent_table_id
4285 AND sl.ship_line_group_id = assoc.to_parent_table_id
4286 )
4287 )
4288 )
4289 AND
4290 ((p_match_id IS NOT NULL
4291 AND m.match_id = p_match_id )
4292 OR (p_match_Amount_id IS NOT NULL
4293 AND EXISTS (SELECT 1
4294 FROM inl_matches m2
4295 WHERE m2.match_id = m.match_id
4296 AND m2.match_Amount_id = p_match_Amount_id
4297 AND rownum <2)))
4298 AND rownum <2
4299 )
4300 )
4301 )
4302 AND ROWNUM < 2
4303 )
4304
4305 ;
4306
4307 TYPE est_CL_Type
4308 IS
4309 TABLE OF estimated_CL%ROWTYPE;
4310 C_est_CL est_CL_Type;
4311
4312
4313 l_ChLn_Assoc inl_ChLn_Assoc_tp;
4314 l_new_charge_line_id NUMBER;
4315 l_level_charge_is_applied VARCHAR(5):= 'X';
4316 BEGIN
4317
4318 -- Standard Beginning of Procedure/Function Logging
4319 INL_LOGGING_PVT.Log_BeginProc (
4320 p_module_name => g_module_name,
4321 p_procedure_name => l_proc_name
4322 );
4323 -- Initialize return status to success
4324 x_return_status := FND_API.G_RET_STS_SUCCESS;
4325
4326 l_debug_info := 'Getting the maximum level where this charge_line_type_id is applied.';
4327 INL_LOGGING_PVT.Log_Statement (
4328 p_module_name => g_module_name,
4329 p_procedure_name => l_proc_name,
4330 p_debug_info => l_debug_info
4331 ) ;
4332
4333 OPEN get_level;
4334 FETCH get_level BULK COLLECT INTO C_get_level;
4335
4336 CLOSE get_level;
4337 l_debug_info := C_get_level.LAST||' lines have been retrieved.';
4338 INL_LOGGING_PVT.Log_Statement (
4339 p_module_name => g_module_name,
4340 p_procedure_name => l_proc_name,
4341 p_debug_info => l_debug_info
4342 ) ;
4343
4344 IF NVL (C_get_level.LAST, 0) > 0 THEN
4345 FOR i IN NVL (C_get_level.FIRST, 0) ..NVL (C_get_level.LAST, 0)
4346 LOOP
4347
4348 IF C_get_level(i).to_parent_table_name = 'INL_SHIP_LINES'
4349 THEN
4350 IF l_level_charge_is_applied NOT IN ('GROUP', 'ALL') THEN
4351 l_level_charge_is_applied:='LINE';
4352 END IF;
4353 ELSIF C_get_level(i).to_parent_table_name = 'INL_SHIP_LINE_GROUPS'
4354 THEN
4355 IF l_level_charge_is_applied <> 'ALL' THEN
4356 l_level_charge_is_applied:='GROUP';
4357 END IF;
4358 ELSE
4359 l_level_charge_is_applied:='ALL';
4360 END IF;
4361
4362 END LOOP;
4363 END IF;
4364
4365 l_debug_info :=
4366 'Created Charge Line with 0 for the existent estimated charge lines applied at level : '||l_level_charge_is_applied;
4367 INL_LOGGING_PVT.Log_Statement (
4368 p_module_name => g_module_name,
4369 p_procedure_name => l_proc_name,
4370 p_debug_info => l_debug_info
4371 ) ;
4372
4373 OPEN estimated_CL (l_level_charge_is_applied) ;
4374 FETCH estimated_CL BULK COLLECT INTO C_est_CL;
4375
4376 CLOSE estimated_CL;
4377 l_debug_info := C_est_CL.LAST||' lines have been retrieved.';
4378 INL_LOGGING_PVT.Log_Statement (
4379 p_module_name => g_module_name,
4380 p_procedure_name => l_proc_name,
4381 p_debug_info => l_debug_info
4382 ) ;
4383
4384 IF NVL (C_est_CL.LAST, 0) > 0 THEN
4385 l_ChLn_Assoc.inl_Assoc.allocation_basis := NULL;
4386 l_ChLn_Assoc.inl_Assoc.allocation_uom_code := NULL;
4387 l_ChLn_Assoc.inl_Assoc.to_parent_table_name := NULL;
4388 l_ChLn_Assoc.inl_Assoc.to_parent_table_id := NULL;
4389 l_ChLn_Assoc.adjustment_num := p_adjustment_num;
4390 l_ChLn_Assoc.match_id := p_match_id;
4391 l_ChLn_Assoc.match_amount_id := p_match_amount_id;
4392 l_ChLn_Assoc.charge_line_type_id := p_charge_line_type_id;
4393 l_ChLn_Assoc.charge_amt := 0;
4394 l_ChLn_Assoc.assessable_value := NULL;
4395 l_ChLn_Assoc.tax_already_calculated_flag := 'N';
4396 FOR i IN NVL (C_est_CL.FIRST, 0) ..NVL (C_est_CL.LAST, 0)
4397 LOOP
4398 l_ChLn_Assoc.charge_line_num := C_est_CL (i) .charge_line_num;
4399 l_ChLn_Assoc.landed_cost_flag := C_est_CL (i) .landed_cost_flag;
4400 l_ChLn_Assoc.parent_charge_line_id := C_est_CL (i) .charge_line_id;
4401 l_ChLn_Assoc.currency_code := C_est_CL (i) .currency_code;
4402 l_ChLn_Assoc.currency_conversion_type := C_est_CL (i) .currency_conversion_type;
4403 l_ChLn_Assoc.currency_conversion_date := C_est_CL (i) .currency_conversion_date;
4404 l_ChLn_Assoc.currency_conversion_rate := C_est_CL (i) .currency_conversion_rate;
4405 l_ChLn_Assoc.party_id := C_est_CL (i) .party_id;
4406 l_ChLn_Assoc.party_site_id := C_est_CL (i) .party_site_id;
4407 l_ChLn_Assoc.trx_business_category := C_est_CL (i) .trx_business_category;
4408 l_ChLn_Assoc.intended_use := C_est_CL (i) .intended_use;
4409 l_ChLn_Assoc.product_fiscal_class := C_est_CL (i) .product_fiscal_class;
4410 l_ChLn_Assoc.product_category := C_est_CL (i) .product_category;
4411 l_ChLn_Assoc.product_type := C_est_CL (i) .product_type;
4412 l_ChLn_Assoc.user_def_fiscal_class := C_est_CL (i) .user_def_fiscal_class;
4413 l_ChLn_Assoc.tax_classification_code := C_est_CL (i) .tax_classification_code;
4414 l_ChLn_Assoc.ship_from_party_id := C_est_CL (i) .ship_from_party_id;
4415 l_ChLn_Assoc.ship_from_party_site_id := C_est_CL (i) .ship_from_party_site_id;
4416 l_ChLn_Assoc.ship_to_organization_id := C_est_CL (i) .ship_to_organization_id;
4417 l_ChLn_Assoc.ship_to_location_id := C_est_CL (i) .ship_to_location_id;
4418 l_ChLn_Assoc.bill_from_party_id := C_est_CL (i) .bill_from_party_id;
4419 l_ChLn_Assoc.bill_from_party_site_id := C_est_CL (i) .bill_from_party_site_id;
4420 l_ChLn_Assoc.bill_to_organization_id := C_est_CL (i) .bill_to_organization_id;
4421 l_ChLn_Assoc.bill_to_location_id := C_est_CL (i) .bill_to_location_id;
4422 l_ChLn_Assoc.poa_party_id := C_est_CL (i) .poa_party_id;
4423 l_ChLn_Assoc.poa_party_site_id := C_est_CL (i) .poa_party_site_id;
4424 l_ChLn_Assoc.poo_organization_id := C_est_CL (i) .poo_organization_id;
4425 l_ChLn_Assoc.poo_location_id := C_est_CL (i) .poo_location_id;
4426 -- Create_ChLines
4427 l_debug_info := 'Create_ChLines';
4428 INL_LOGGING_PVT.Log_Statement (
4429 p_module_name => g_module_name,
4430 p_procedure_name => l_proc_name,
4431 p_debug_info => l_debug_info
4432 ) ;
4433
4434 Create_ChLines (
4435 p_ChLn_Assoc => l_ChLn_Assoc,
4436 p_include_assoc => 'N',
4437 p_adjustment_num => p_adjustment_num,
4438 x_new_charge_line_id => l_new_charge_line_id,
4439 x_return_status => l_return_status
4440 ) ;
4441 IF l_return_status = FND_API.G_RET_STS_ERROR THEN
4442 RAISE FND_API.G_EXC_ERROR;
4443 ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4444 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4445 END IF;
4446 -- TxLines
4447 l_debug_info := 'Amount = 0 for estimated taxes associated with estimated charge';
4448 INL_LOGGING_PVT.Log_Statement (
4449 p_module_name => g_module_name,
4450 p_procedure_name => l_proc_name,
4451 p_debug_info => l_debug_info
4452 ) ;
4453
4454 Zero_EstimTaxLines (
4455 p_ship_header_id => NULL,
4456 p_match_id => p_match_id,
4457 p_comp_name => 'INL_CHARGE_LINES',
4458 p_comp_id => C_est_CL (i) .charge_line_id,
4459 p_tax_code => NULL,
4460 p_adjustment_num => p_adjustment_num,
4461 x_return_status => l_return_status
4462 ) ;
4463 IF l_return_status = FND_API.G_RET_STS_ERROR THEN
4464 RAISE FND_API.G_EXC_ERROR;
4465 ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4466 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4467 END IF;
4468 END LOOP;
4469 END IF;
4470
4471 -- Standard End of Procedure/Function Logging
4472 INL_LOGGING_PVT.Log_EndProc (
4473 p_module_name => g_module_name,
4474 p_procedure_name => l_proc_name
4475 ) ;
4476 EXCEPTION
4477 WHEN FND_API.G_EXC_ERROR THEN
4478 -- Standard Expected Error Logging
4479 INL_LOGGING_PVT.Log_ExpecError (
4480 p_module_name => g_module_name,
4481 p_procedure_name => l_proc_name
4482 ) ;
4483 x_return_status := FND_API.G_RET_STS_ERROR;
4484 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
4485 -- Standard Unexpected Error Logging
4486 INL_LOGGING_PVT.Log_UnexpecError (
4487 p_module_name => g_module_name,
4488 p_procedure_name => l_proc_name
4489 ) ;
4490 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4491 WHEN OTHERS THEN
4492 -- Standard Unexpected Error Logging
4493 INL_LOGGING_PVT.Log_UnexpecError (
4494 p_module_name => g_module_name,
4495 p_procedure_name => l_proc_name
4496 ) ;
4497 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
4498 IF FND_MSG_PUB.Check_Msg_Level (p_message_level => FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
4499 FND_MSG_PUB.Add_Exc_Msg (
4500 p_pkg_name => g_pkg_name,
4501 p_procedure_name => l_proc_name
4502 ) ;
4503 END IF;
4504 END Zero_EstimChargeLinesPerMatch;
4505
4506 -- API name : Adjust_ChargeLines
4507 -- Type : Private
4508 -- Function : Create Adjustment Lines for Charge Lines
4509 -- Pre-reqs : None
4510 -- Parameters :
4511 -- IN : p_api_version IN NUMBER Required
4512 -- p_init_msg_list IN VARCHAR2 Optional Default = FND_API.G_FALSE
4513 -- p_commit IN VARCHAR2 Optional Default = FND_API.G_FALSE
4514 -- p_match_id IN NUMBER,
4515 -- p_adjustment_num IN NUMBER,
4516 -- OUT x_return_status OUT NOCOPY VARCHAR2
4517 -- x_msg_count OUT NOCOPY NUMBER
4518 -- x_msg_data OUT NOCOPY VARCHAR2
4519 --
4520 -- Version : Current version 1.0
4521 --
4522 -- Notes :
4523 PROCEDURE Adjust_ChargeLines (
4524 p_api_version IN NUMBER,
4525 p_init_msg_list IN VARCHAR2 := FND_API.G_FALSE,
4526 p_commit IN VARCHAR2 := FND_API.G_FALSE,
4527 p_match_id IN NUMBER,
4528 p_adjustment_num IN NUMBER,
4529 x_return_status OUT NOCOPY VARCHAR2,
4530 x_msg_count OUT NOCOPY NUMBER,
4531 x_msg_data OUT NOCOPY VARCHAR2
4532 ) IS
4533 l_api_name CONSTANT VARCHAR2 (30) := 'Adjust_ChargeLines';
4534 l_api_version CONSTANT NUMBER := 1.0;
4535 l_next_adjust_num NUMBER;
4536 l_debug_info VARCHAR2 (240) ;
4537 l_parent_charge_line_id NUMBER;
4538 l_return_status VARCHAR2 (1) ;
4539 l_new_charge_line_id NUMBER;
4540 l_ship_line_id NUMBER;
4541 l_ship_header_id NUMBER;
4542 l_matched_uom_code VARCHAR2 (30) ;
4543 l_matched_curr_code VARCHAR2 (15) ;
4544 l_matched_curr_conversion_type VARCHAR2 (30) ;
4545 l_matched_curr_conversion_date DATE;
4546 l_matched_curr_conversion_rate NUMBER;
4547 l_replace_estim_qty_flag VARCHAR2 (1) ;
4548 l_party_id NUMBER;
4549 l_party_site_id NUMBER;
4550 l_matched_amt NUMBER;
4551 l_mat_curr_code VARCHAR2 (15) ;
4552 l_corr_charge_line_id NUMBER;
4553 l_corr_charge_line_num NUMBER;
4554 l_corr_adj_num NUMBER;
4555 l_include_assoc VARCHAR2 (1) := 'Y';
4556 l_existing_match_info_flag VARCHAR2 (1) ;
4557 l_from_parent_table_name VARCHAR2 (30) ;
4558 l_charge_line_type_id NUMBER;
4559 l_from_parent_table_id NUMBER;
4560 l_to_parent_table_name VARCHAR2 (30) ;
4561 l_to_parent_table_id NUMBER;
4562 l_prev_adjustment_num NUMBER := NULL;
4563 l_ChLn_Assoc inl_ChLn_Assoc_tp;
4564 BEGIN
4565 -- Standard Beginning of Procedure/Function Logging
4566 INL_LOGGING_PVT.Log_BeginProc (p_module_name => g_module_name, p_procedure_name => l_api_name) ;
4567 -- Standard Start of API savepoint
4568 SAVEPOINT Adjust_ChargeLines_PVT;
4569 -- Initialize message list if p_init_msg_list is set to TRUE.
4570 IF FND_API.to_Boolean (p_init_msg_list) THEN
4571 FND_MSG_PUB.initialize;
4572 END IF;
4573 -- Check for call compatibility.
4574 IF NOT FND_API.Compatible_API_Call (p_current_version_number => l_api_version,
4575 p_caller_version_number => p_api_version,
4576 p_api_name => l_api_name,
4577 p_pkg_name => g_pkg_name) THEN
4578 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4579 END IF;
4580 -- Initialize API return status to success
4581 x_return_status := FND_API.G_RET_STS_SUCCESS;
4582 -- Getting the match information
4583 l_debug_info := 'Getting the match information';
4584 INL_LOGGING_PVT.Log_Statement (
4585 p_module_name => g_module_name,
4586 p_procedure_name => l_api_name,
4587 p_debug_info => l_debug_info
4588 ) ;
4589 SELECT m.to_parent_table_id ,
4590 m.from_parent_table_name ,
4591 m.from_parent_table_id ,
4592 m.to_parent_table_name ,
4593 m.to_parent_table_id ,
4594 m.matched_uom_code ,
4595 m.matched_amt ,
4596 m.replace_estim_qty_flag ,
4597 m.existing_match_info_flag ,
4598 m.party_id ,
4599 m.party_site_id ,
4600 m.charge_line_type_id ,
4601 m.matched_curr_code ,
4602 m.matched_curr_conversion_type,
4603 m.matched_curr_conversion_date,
4604 m.matched_curr_conversion_rate
4605 INTO l_ship_line_id ,
4606 l_from_parent_table_name ,
4607 l_from_parent_table_id ,
4608 l_to_parent_table_name ,
4609 l_to_parent_table_id ,
4610 l_matched_uom_code ,
4611 l_matched_amt ,
4612 l_replace_estim_qty_flag ,
4613 l_existing_match_info_flag ,
4614 l_party_id ,
4615 l_party_site_id ,
4616 l_charge_line_type_id ,
4617 l_matched_curr_code ,
4618 l_matched_curr_conversion_type,
4619 l_matched_curr_conversion_date,
4620 l_matched_curr_conversion_rate
4621 FROM inl_corr_matches_v m
4622 WHERE match_id = p_match_id;
4623 -- Getting the Ship information
4624 l_debug_info := 'Getting the ship line information';
4625 INL_LOGGING_PVT.Log_Statement (
4626 p_module_name => g_module_name,
4627 p_procedure_name => l_api_name,
4628 p_debug_info => l_debug_info
4629 ) ;
4630
4631 SELECT sl.ship_header_id
4632 INTO l_ship_header_id
4633 FROM inl_ship_lines sl
4634 WHERE sl.ship_line_id = l_ship_line_id;
4635
4636 l_debug_info := 'l_existing_match_info_flag';
4637 INL_LOGGING_PVT.Log_Variable (
4638 p_module_name => g_module_name,
4639 p_procedure_name => l_api_name,
4640 p_var_name => l_debug_info,
4641 p_var_value => l_existing_match_info_flag
4642 ) ;
4643 IF (l_existing_match_info_flag = 'Y') THEN
4644 -- Charge line has been processed
4645 l_debug_info := 'Existing match info flag';
4646 INL_LOGGING_PVT.Log_Statement (
4647 p_module_name => g_module_name,
4648 p_procedure_name => l_api_name,
4649 p_debug_info => l_debug_info
4650 ) ;
4651
4652 SELECT p_adjustment_num,
4653 cl.charge_line_id ,
4654 cl.charge_line_num
4655 INTO l_prev_adjustment_num ,
4656 l_ChLn_Assoc.parent_charge_line_id,
4657 l_ChLn_Assoc.charge_line_num
4658 FROM inl_matches m,
4659 inl_adj_charge_lines_v cl
4660 WHERE cl.match_id = m.match_id
4661 AND m.match_id <> p_match_id
4662 AND m.from_parent_table_name = l_from_parent_table_name
4663 AND m.from_parent_table_id = l_from_parent_table_id
4664 AND m.to_parent_table_name = l_to_parent_table_name
4665 AND m.to_parent_table_id = l_to_parent_table_id
4666 AND m.match_id =
4667 (
4668 SELECT MAX (m2.match_id)
4669 FROM inl_matches m2
4670 WHERE m2.from_parent_table_name = m.from_parent_table_name
4671 AND m2.from_parent_table_id = m.from_parent_table_id
4672 AND m2.to_parent_table_name = m.to_parent_table_name
4673 AND m2.to_parent_table_id = m.to_parent_table_id
4674 AND m2.match_id <> p_match_id
4675 )
4676 AND cl.charge_line_num =
4677 (
4678 SELECT MAX (cl1.charge_line_num)
4679 FROM inl_adj_charge_lines_v cl1
4680 WHERE cl1.match_id = m.match_id
4681 ) ;
4682 -- GROUP BY cl.charge_line_id, cl.adjustment_num;
4683 ELSE
4684 l_ChLn_Assoc.parent_charge_line_id := NULL;
4685 -- Getting the charge line to correction
4686 l_debug_info := 'Getting the charge line to correction';
4687 INL_LOGGING_PVT.Log_Statement (
4688 p_module_name => g_module_name,
4689 p_procedure_name => l_api_name,
4690 p_debug_info => l_debug_info
4691 ) ;
4692
4693 BEGIN
4694 SELECT cl.charge_line_id,
4695 cl.charge_line_num ,
4696 cl.adjustment_num
4697 INTO l_corr_charge_line_id,
4698 l_corr_charge_line_num ,
4699 l_corr_adj_num
4700 FROM inl_adj_charge_lines_v cl
4701 WHERE cl.match_id = p_match_id
4702 AND cl.charge_line_num =
4703 (
4704 SELECT MAX (cl1.charge_line_num)
4705 FROM inl_adj_charge_lines_v cl1
4706 WHERE cl1.match_id = p_match_id
4707 ) ;
4708 EXCEPTION
4709 WHEN NO_DATA_FOUND THEN
4710 NULL;
4711 END;
4712 IF (l_corr_charge_line_id IS NOT NULL AND l_corr_charge_line_num IS NOT NULL) THEN
4713 l_ChLn_Assoc.charge_line_num := l_corr_charge_line_num;
4714 l_ChLn_Assoc.parent_charge_line_id := l_corr_charge_line_id;
4715 l_debug_info := 'l_corr_charge_line_id';
4716 INL_LOGGING_PVT.Log_Variable (p_module_name => g_module_name, p_procedure_name => l_api_name, p_var_name => l_debug_info, p_var_value => l_corr_charge_line_id) ;
4717 ELSE
4718 l_ChLn_Assoc.charge_line_num := NULL;
4719 END IF;
4720 END IF;
4721 -- Handling estimated Charge Line and getting the parent_charge_line_id
4722 l_debug_info := 'Handling estimated Charge Line and getting the parent_charge_line_id';
4723 INL_LOGGING_PVT.Log_Statement (
4724 p_module_name => g_module_name,
4725 p_procedure_name => l_api_name,
4726 p_debug_info => l_debug_info
4727 ) ;
4728
4729 -- For now:
4730 -- 1) Create a new charge line ADJ 1 with the new actual value with no ADJ 0
4731 -- 2) For the estimated charge line create a new charge line ADJ 1 with amount = 0
4732 -- Getting information for the new charge line
4733 l_debug_info := 'All Matched Amounts :'||l_matched_amt;
4734 INL_LOGGING_PVT.Log_Statement (
4735 p_module_name => g_module_name,
4736 p_procedure_name => l_api_name,
4737 p_debug_info => l_debug_info
4738 ) ;
4739
4740 l_ChLn_Assoc.inl_Assoc.ship_header_id := l_ship_header_id;
4741 l_ChLn_Assoc.inl_Assoc.allocation_basis := 'VALUE';
4742 l_ChLn_Assoc.inl_Assoc.allocation_uom_code := NULL;
4743 l_ChLn_Assoc.inl_Assoc.to_parent_table_name := 'INL_SHIP_LINES';
4744 l_ChLn_Assoc.inl_Assoc.to_parent_table_id := l_to_parent_table_id;
4745 l_ChLn_Assoc.charge_line_type_id := l_charge_line_type_id;
4746 l_ChLn_Assoc.landed_cost_flag := 'Y';
4747 l_ChLn_Assoc.adjustment_num := l_prev_adjustment_num;
4748 l_ChLn_Assoc.match_id := p_match_id;
4749 l_ChLn_Assoc.charge_amt := l_matched_amt;
4750 l_ChLn_Assoc.currency_code := l_matched_curr_code;
4751 l_ChLn_Assoc.currency_conversion_type := l_matched_curr_conversion_type;
4752 l_ChLn_Assoc.currency_conversion_date := l_matched_curr_conversion_date;
4753 l_ChLn_Assoc.currency_conversion_rate := l_matched_curr_conversion_rate;
4754 l_ChLn_Assoc.party_id := l_party_id;
4755 l_ChLn_Assoc.party_site_id := l_party_site_id;
4756 l_ChLn_Assoc.trx_business_category := NULL;
4757 l_ChLn_Assoc.intended_use := NULL;
4758 l_ChLn_Assoc.product_fiscal_class := NULL;
4759 l_ChLn_Assoc.product_category := NULL;
4760 l_ChLn_Assoc.product_type := NULL;
4761 l_ChLn_Assoc.user_def_fiscal_class := NULL;
4762 l_ChLn_Assoc.tax_classification_code := NULL;
4763 l_ChLn_Assoc.assessable_value := NULL;
4764 l_ChLn_Assoc.tax_already_calculated_flag := 'N';
4765 l_ChLn_Assoc.ship_from_party_id := NULL;
4766 l_ChLn_Assoc.ship_from_party_site_id := NULL;
4767 l_ChLn_Assoc.ship_to_organization_id := NULL;
4768 l_ChLn_Assoc.ship_to_location_id := NULL;
4769 l_ChLn_Assoc.bill_from_party_id := NULL;
4770 l_ChLn_Assoc.bill_from_party_site_id := NULL;
4771 l_ChLn_Assoc.bill_to_organization_id := NULL;
4772 l_ChLn_Assoc.bill_to_location_id := NULL;
4773 l_ChLn_Assoc.poa_party_id := NULL;
4774 l_ChLn_Assoc.poa_party_site_id := NULL;
4775 l_ChLn_Assoc.poo_organization_id := NULL;
4776 l_ChLn_Assoc.poo_location_id := NULL;
4777 -- Create_ChLines
4778 l_debug_info := 'Create_ChLines';
4779 INL_LOGGING_PVT.Log_Statement (
4780 p_module_name => g_module_name,
4781 p_procedure_name => l_api_name,
4782 p_debug_info => l_debug_info
4783 ) ;
4784
4785 -- It does not create associations for corrections
4786 IF (l_ChLn_Assoc.parent_charge_line_id IS NOT NULL) THEN
4787 l_include_assoc := 'N';
4788 ELSE
4789 l_include_assoc := 'Y';
4790 END IF;
4791 -- Create_ChLines
4792 Create_ChLines (p_ChLn_Assoc => l_ChLn_Assoc,
4793 p_include_assoc => l_include_assoc,
4794 p_adjustment_num => p_adjustment_num,
4795 x_new_charge_line_id => l_new_charge_line_id,
4796 x_return_status => l_return_status) ;
4797 IF l_return_status = FND_API.G_RET_STS_ERROR THEN
4798 RAISE FND_API.G_EXC_ERROR;
4799 ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4800 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4801 END IF;
4802
4803 Zero_EstimChargeLinesPerMatch (
4804 p_match_id => p_match_id,
4805 p_match_Amount_id => null,
4806 p_charge_line_type_id=> l_charge_line_type_id,
4807 p_adjustment_num => p_adjustment_num,
4808 x_return_status => l_debug_info
4809 );
4810
4811 IF l_return_status = FND_API.G_RET_STS_ERROR THEN
4812 RAISE FND_API.G_EXC_ERROR;
4813 ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4814 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4815 END IF;
4816
4817
4818 -- Standard check of p_commit.
4819 IF FND_API.To_Boolean (p_commit) THEN
4820 COMMIT WORK;
4821 END IF;
4822 -- Standard call to get message count and if count is 1, get message info.
4823 FND_MSG_PUB.Count_And_Get ( p_encoded => FND_API.g_false, p_count => x_msg_count, p_data => x_msg_data) ;
4824 -- Standard End of Procedure/Function Logging
4825 INL_LOGGING_PVT.Log_EndProc ( p_module_name => g_module_name, p_procedure_name => l_api_name) ;
4826 EXCEPTION
4827 WHEN FND_API.G_EXC_ERROR THEN
4828 -- Standard Expected Error Logging
4829 INL_LOGGING_PVT.Log_ExpecError ( p_module_name => g_module_name, p_procedure_name => l_api_name) ;
4830 ROLLBACK TO Adjust_ChargeLines_PVT;
4831 x_return_status := FND_API.G_RET_STS_ERROR;
4832 FND_MSG_PUB.Count_And_Get ( p_encoded => FND_API.g_false, p_count => x_msg_count, p_data => x_msg_data) ;
4833 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
4834 -- Standard Unexpected Error Logging
4835 INL_LOGGING_PVT.Log_UnexpecError ( p_module_name => g_module_name, p_procedure_name => l_api_name) ;
4836 ROLLBACK TO Adjust_ChargeLines_PVT;
4837 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4838 FND_MSG_PUB.Count_And_Get ( p_encoded => FND_API.g_false, p_count => x_msg_count, p_data => x_msg_data) ;
4839 WHEN OTHERS THEN
4840 -- Standard Unexpected Error Logging
4841 INL_LOGGING_PVT.Log_UnexpecError ( p_module_name => g_module_name, p_procedure_name => l_api_name) ;
4842 ROLLBACK TO Adjust_ChargeLines_PVT;
4843 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
4844 IF FND_MSG_PUB.Check_Msg_Level (p_message_level => FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
4845 FND_MSG_PUB.Add_Exc_Msg ( p_pkg_name => g_pkg_name, p_procedure_name => l_api_name) ;
4846 END IF;
4847 FND_MSG_PUB.Count_And_Get ( p_encoded => FND_API.g_false, p_count => x_msg_count, p_data => x_msg_data) ;
4848 END Adjust_ChargeLines;
4849
4850 -- API name : Adjust_ChargeLines
4851 -- Type : Private
4852 -- Function : Create Adjustmens Charge Lines and their associations
4853 -- Pre-reqs : None
4854 -- Parameters :
4855 -- IN : p_api_version IN NUMBER Required
4856 -- p_init_msg_list IN VARCHAR2 Optional Default = FND_API.G_FALSE
4857 -- p_commit IN VARCHAR2 Optional Default = FND_API.G_FALSE
4858 -- p_match_amount_id IN NUMBER,
4859 -- p_adjustment_num IN NUMBER,
4860 -- OUT x_return_status OUT NOCOPY VARCHAR2
4861 -- x_msg_count OUT NOCOPY NUMBER
4862 -- x_msg_data OUT NOCOPY VARCHAR2
4863 --
4864 -- Version : Current version 1.0
4865 --
4866 -- Notes :
4867 PROCEDURE Adjust_ChargeLines
4868 (
4869 p_api_version IN NUMBER,
4870 p_init_msg_list IN VARCHAR2 := FND_API.G_FALSE,
4871 p_commit IN VARCHAR2 := FND_API.G_FALSE,
4872 p_match_amount_id IN NUMBER,
4873 p_adjustment_num IN NUMBER,
4874 x_return_status OUT NOCOPY VARCHAR2,
4875 x_msg_count OUT NOCOPY NUMBER,
4876 x_msg_data OUT NOCOPY VARCHAR2)
4877 IS
4878 l_api_name CONSTANT VARCHAR2 (30) := 'Adjust_ChargeLines-2';
4879 l_api_version CONSTANT NUMBER := 1.0;
4880 CURSOR c_matches_cl (p_match_amount_id NUMBER)
4881 IS
4882 SELECT m.match_id ,
4883 m.ship_header_id ,
4884 m.from_parent_table_name,
4885 m.from_parent_table_id ,
4886 m.to_parent_table_name ,
4887 m.to_parent_table_id
4888 FROM inl_corr_matches_v m
4889 WHERE m.match_amount_id = p_match_amount_id
4890 ORDER BY m.match_id;
4891
4892 TYPE c_matches_type
4893 IS
4894 TABLE OF c_matches_cl%ROWTYPE;
4895
4896 c_matches c_matches_type;
4897
4898 l_next_adjust_num NUMBER;
4899 l_debug_info VARCHAR2 (240) ;
4900 l_parent_charge_line_id NUMBER;
4901 l_return_status VARCHAR2 (1) ;
4902 l_new_charge_line_id NUMBER;
4903 l_ship_line_id NUMBER;
4904 l_ship_header_id NUMBER;
4905 l_matched_curr_code VARCHAR2 (15) ;
4906 l_matched_curr_conversion_type VARCHAR2 (30) ;
4907 l_matched_curr_conversion_date DATE;
4908 l_matched_curr_conversion_rate NUMBER;
4909 l_charge_line_type_id NUMBER;
4910 l_party_id NUMBER;
4911 l_party_site_id NUMBER;
4912 l_matched_amt NUMBER;
4913 l_mat_curr_code VARCHAR2 (15) ;
4914 l_allocation_basis VARCHAR2 (30) ;
4915 l_allocation_uom_code VARCHAR2 (30) ;
4916 l_corr_charge_line_id NUMBER;
4917 l_corr_charge_line_num NUMBER;
4918 l_corr_adj_num NUMBER;
4919 l_existing_match_info_flag VARCHAR2 (1) ;
4920 l_from_parent_table_name VARCHAR2 (30) ;
4921 l_from_parent_table_id NUMBER;
4922 l_to_parent_table_name VARCHAR2 (30) ;
4923 l_to_parent_table_id NUMBER;
4924 l_ChLn_Assoc inl_ChLn_Assoc_tp;
4925 l_AssocLn inl_Assoc_tp;
4926 BEGIN
4927 -- Standard Beginning of Procedure/Function Logging
4928 INL_LOGGING_PVT.Log_BeginProc (p_module_name => g_module_name, p_procedure_name => l_api_name) ;
4929 -- Standard Start of API savepoint
4930
4931 SAVEPOINT Adjust_ChargeLines_PVT;
4932 -- Initialize message list if p_init_msg_list is set to TRUE.
4933 IF FND_API.to_Boolean (p_init_msg_list) THEN
4934 FND_MSG_PUB.initialize;
4935 END IF;
4936 -- Check for call compatibility.
4937 IF NOT FND_API.Compatible_API_Call (p_current_version_number => l_api_version,
4938 p_caller_version_number => p_api_version,
4939 p_api_name => l_api_name,
4940 p_pkg_name => g_pkg_name) THEN
4941 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4942 END IF;
4943 -- Initialize API return status to success
4944 x_return_status := FND_API.G_RET_STS_SUCCESS;
4945 -- Getting the match information
4946 l_debug_info := 'Getting the match information';
4947 INL_LOGGING_PVT.Log_Statement (
4948 p_module_name => g_module_name,
4949 p_procedure_name => l_api_name,
4950 p_debug_info => l_debug_info
4951 ) ;
4952
4953 SELECT m.ship_header_id ,
4954 m.from_parent_table_name ,
4955 m.from_parent_table_id ,
4956 m.to_parent_table_name ,
4957 m.to_parent_table_id ,
4958 ma.matched_amt ,
4959 m.party_id ,
4960 m.party_site_id ,
4961 m.charge_line_type_id ,
4962 m.existing_match_info_flag ,
4963 ma.matched_curr_code ,
4964 ma.matched_curr_conversion_type,
4965 ma.matched_curr_conversion_date,
4966 ma.matched_curr_conversion_rate,
4967 clt.allocation_basis ,
4968 abv.base_uom_code
4969 INTO l_ship_header_id ,
4970 l_from_parent_table_name ,
4971 l_from_parent_table_id ,
4972 l_to_parent_table_name ,
4973 l_to_parent_table_id ,
4974 l_matched_amt ,
4975 l_party_id ,
4976 l_party_site_id ,
4977 l_charge_line_type_id ,
4978 l_existing_match_info_flag ,
4979 l_matched_curr_code ,
4980 l_matched_curr_conversion_type,
4981 l_matched_curr_conversion_date,
4982 l_matched_curr_conversion_rate,
4983 l_allocation_basis ,
4984 l_allocation_uom_code
4985 FROM inl_corr_match_amounts_v ma,
4986 inl_corr_matches_v m ,
4987 inl_charge_line_types_vl clt ,
4988 inl_allocation_basis_vl abv
4989 WHERE abv.allocation_basis_code = clt.allocation_basis
4990 AND clt.charge_line_type_id = m.charge_line_type_id
4991 AND m.match_amount_id = ma.match_amount_id
4992 AND ma.match_amount_id = p_match_amount_id
4993 AND ROWNUM = 1;
4994
4995 l_debug_info := 'l_existing_match_info_flag';
4996 INL_LOGGING_PVT.Log_Variable (p_module_name => g_module_name,
4997 p_procedure_name => l_api_name,
4998 p_var_name => l_debug_info,
4999 p_var_value => l_existing_match_info_flag) ;
5000
5001 IF (l_existing_match_info_flag = 'Y') THEN
5002 -- Charge has been already processed
5003 l_debug_info := 'Existing match info flag';
5004 INL_LOGGING_PVT.Log_Statement (
5005 p_module_name => g_module_name,
5006 p_procedure_name => l_api_name,
5007 p_debug_info => l_debug_info
5008 ) ;
5009
5010 SELECT p_adjustment_num,
5011 cl.charge_line_id ,
5012 cl.charge_line_num
5013 INTO l_ChLn_Assoc.adjustment_num ,
5014 l_ChLn_Assoc.parent_charge_line_id,
5015 l_ChLn_Assoc.charge_line_num
5016 FROM inl_matches m,
5017 inl_adj_charge_lines_v cl
5018 WHERE cl.match_amount_id = m.match_amount_id
5019 AND m.from_parent_table_name = l_from_parent_table_name
5020 AND m.from_parent_table_id = l_from_parent_table_id
5021 AND m.to_parent_table_name = l_to_parent_table_name
5022 AND m.to_parent_table_id = l_to_parent_table_id
5023 AND m.adj_already_generated_flag = 'Y'
5024 AND m.match_id =
5025 (
5026 SELECT MAX (m2.match_id)
5027 FROM inl_matches m2
5028 WHERE m2.from_parent_table_name = m.from_parent_table_name
5029 AND m2.from_parent_table_id = m.from_parent_table_id
5030 AND m2.to_parent_table_name = m.to_parent_table_name
5031 AND m2.to_parent_table_id = m.to_parent_table_id
5032 AND m2.adj_already_generated_flag = 'Y'
5033 )
5034 AND cl.charge_line_num =
5035 (
5036 SELECT MAX (cl1.charge_line_num)
5037 FROM inl_adj_charge_lines_v cl1
5038 WHERE cl1.match_amount_id = m.match_amount_id
5039 ) ;
5040 -- GROUP BY cl.charge_line_id, cl.adjustment_num;
5041 ELSE
5042 l_ChLn_Assoc.parent_charge_line_id := NULL;
5043 -- Getting the charge line to correction
5044 l_debug_info := 'Getting the charge line to correction';
5045 INL_LOGGING_PVT.Log_Statement (
5046 p_module_name => g_module_name,
5047 p_procedure_name => l_api_name,
5048 p_debug_info => l_debug_info
5049 ) ;
5050
5051 BEGIN
5052 SELECT cl.charge_line_id,
5053 cl.charge_line_num ,
5054 cl.adjustment_num
5055 INTO l_corr_charge_line_id,
5056 l_corr_charge_line_num ,
5057 l_corr_adj_num
5058 FROM inl_adj_charge_lines_v cl
5059 WHERE cl.match_amount_id = p_match_amount_id
5060 AND cl.charge_line_num =
5061 (
5062 SELECT MAX (cl1.charge_line_num)
5063 FROM inl_adj_charge_lines_v cl1
5064 WHERE cl1.match_amount_id = p_match_amount_id
5065 ) ;
5066 EXCEPTION
5067 WHEN NO_DATA_FOUND THEN
5068 NULL;
5069 END;
5070 -- Is a correction, necessary to create an adjustment
5071 IF (l_corr_charge_line_id IS NOT NULL AND l_corr_charge_line_num IS NOT NULL) THEN
5072 l_ChLn_Assoc.charge_line_num := l_corr_charge_line_num;
5073 l_ChLn_Assoc.parent_charge_line_id := l_corr_charge_line_id;
5074 l_ChLn_Assoc.adjustment_num := p_adjustment_num;
5075 l_debug_info := 'l_corr_charge_line_id';
5076 INL_LOGGING_PVT.Log_Variable (p_module_name => g_module_name,
5077 p_procedure_name => l_api_name,
5078 p_var_name => l_debug_info,
5079 p_var_value => l_corr_charge_line_id) ;
5080 ELSE
5081 l_ChLn_Assoc.charge_line_num := NULL;
5082 END IF;
5083 END IF;
5084 -- Handling estimated Charge Line and getting the parent_charge_line_id
5085 l_debug_info := 'Handling estimated Charge Line and getting the parent_charge_line_id';
5086 INL_LOGGING_PVT.Log_Statement (
5087 p_module_name => g_module_name,
5088 p_procedure_name => l_api_name,
5089 p_debug_info => l_debug_info
5090 ) ;
5091
5092 -- For now:
5093 -- 1) Create a new charge line ADJ 1 with the new actual value with no ADJ 0
5094 -- 2) For the estimated charge line create a new charge line ADJ 1 with amount = 0
5095 -- Getting information for the new charge line
5096 l_debug_info := 'All Matched Amounts :'||l_matched_amt;
5097 INL_LOGGING_PVT.Log_Statement (
5098 p_module_name => g_module_name,
5099 p_procedure_name => l_api_name,
5100 p_debug_info => l_debug_info
5101 ) ;
5102
5103 -- Creating a charge line
5104 l_ChLn_Assoc.inl_Assoc.ship_header_id := l_ship_header_id;
5105 l_ChLn_Assoc.charge_line_type_id := l_charge_line_type_id;
5106 l_ChLn_Assoc.landed_cost_flag := 'Y';
5107 l_ChLn_Assoc.match_amount_id := p_match_amount_id;
5108 l_ChLn_Assoc.charge_amt := l_matched_amt;
5109 l_ChLn_Assoc.currency_code := l_matched_curr_code;
5110 l_ChLn_Assoc.currency_conversion_type := l_matched_curr_conversion_type;
5111 l_ChLn_Assoc.currency_conversion_date := l_matched_curr_conversion_date;
5112 l_ChLn_Assoc.currency_conversion_rate := l_matched_curr_conversion_rate;
5113 l_ChLn_Assoc.party_id := l_party_id;
5114 l_ChLn_Assoc.party_site_id := l_party_site_id;
5115 l_ChLn_Assoc.trx_business_category := NULL;
5116 l_ChLn_Assoc.intended_use := NULL;
5117 l_ChLn_Assoc.product_fiscal_class := NULL;
5118 l_ChLn_Assoc.product_category := NULL;
5119 l_ChLn_Assoc.product_type := NULL;
5120 l_ChLn_Assoc.user_def_fiscal_class := NULL;
5121 l_ChLn_Assoc.tax_classification_code := NULL;
5122 l_ChLn_Assoc.assessable_value := NULL;
5123 l_ChLn_Assoc.tax_already_calculated_flag := 'N';
5124 l_ChLn_Assoc.ship_from_party_id := NULL;
5125 l_ChLn_Assoc.ship_from_party_site_id := NULL;
5126 l_ChLn_Assoc.ship_to_organization_id := NULL;
5127 l_ChLn_Assoc.ship_to_location_id := NULL;
5128 l_ChLn_Assoc.bill_from_party_id := NULL;
5129 l_ChLn_Assoc.bill_from_party_site_id := NULL;
5130 l_ChLn_Assoc.bill_to_organization_id := NULL;
5131 l_ChLn_Assoc.bill_to_location_id := NULL;
5132 l_ChLn_Assoc.poa_party_id := NULL;
5133 l_ChLn_Assoc.poa_party_site_id := NULL;
5134 l_ChLn_Assoc.poo_organization_id := NULL;
5135 l_ChLn_Assoc.poo_location_id := NULL;
5136 -- Create Charge Line
5137 l_debug_info := 'Create_ChLines from a match_amount_id';
5138 INL_LOGGING_PVT.Log_Statement (
5139 p_module_name => g_module_name,
5140 p_procedure_name => l_api_name,
5141 p_debug_info => l_debug_info
5142 ) ;
5143
5144 Create_ChLines (p_ChLn_Assoc => l_ChLn_Assoc,
5145 p_include_assoc => 'N',
5146 p_adjustment_num => p_adjustment_num,
5147 x_new_charge_line_id => l_new_charge_line_id,
5148 x_return_status => l_return_status) ;
5149 IF l_return_status = FND_API.G_RET_STS_ERROR THEN
5150 RAISE FND_API.G_EXC_ERROR;
5151 ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
5152 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5153 END IF;
5154 -- It does not create associations for corrections neither to updates
5155 IF (l_corr_charge_line_id IS NULL AND l_ChLn_Assoc.parent_charge_line_id IS NULL) THEN
5156 -- Create_associations for the match amount id
5157 l_debug_info := 'Create association lines to a match_amount_id';
5158 INL_LOGGING_PVT.Log_Statement (
5159 p_module_name => g_module_name,
5160 p_procedure_name => l_api_name,
5161 p_debug_info => l_debug_info
5162 ) ;
5163
5164 OPEN c_matches_cl (p_match_amount_id) ;
5165 FETCH c_matches_cl BULK COLLECT INTO c_matches;
5166
5167 CLOSE c_matches_cl;
5168 l_debug_info := c_matches.LAST||' match lines have been retrieved.';
5169 INL_LOGGING_PVT.Log_Statement (
5170 p_module_name => g_module_name,
5171 p_procedure_name => l_api_name,
5172 p_debug_info => l_debug_info
5173 ) ;
5174
5175 IF NVL (c_matches.LAST, 0) > 0 THEN
5176 FOR i IN NVL (c_matches.FIRST, 0) ..NVL (c_matches.LAST, 0)
5177 LOOP
5178 l_AssocLn.ship_header_id := l_ship_header_id;
5179 l_AssocLn.allocation_basis := l_allocation_basis;
5180 l_AssocLn.allocation_uom_code := l_allocation_uom_code;
5181 l_AssocLn.to_parent_table_name := c_matches (i) .to_parent_table_name;
5182 l_AssocLn.to_parent_table_id := c_matches (i) .to_parent_table_id;
5183 -- Create Association Line
5184 l_debug_info := 'Create association line for the charge';
5185 INL_LOGGING_PVT.Log_Statement (
5186 p_module_name => g_module_name,
5187 p_procedure_name => l_api_name,
5188 p_debug_info => l_debug_info
5189 ) ;
5190
5191 l_debug_info := 'Creating association for Charge Id: '|| c_matches (i) .to_parent_table_id;
5192 INL_LOGGING_PVT.Log_Variable (p_module_name => g_module_name,
5193 p_procedure_name => l_api_name,
5194 p_var_name => l_debug_info,
5195 p_var_value => c_matches (i) .to_parent_table_id) ;
5196 Create_Assoc (p_Assoc => l_AssocLn,
5197 p_from_parent_table_name => 'INL_CHARGE_LINES',
5198 p_new_line_id => l_new_charge_line_id,
5199 x_return_status => l_return_status) ;
5200 END LOOP;
5201 END IF;
5202 END IF;
5203
5204 Zero_EstimChargeLinesPerMatch (
5205 p_match_id => null,
5206 p_match_Amount_id => p_match_amount_id,
5207 p_charge_line_type_id=> l_charge_line_type_id,
5208 p_adjustment_num => p_adjustment_num,
5209 x_return_status => l_debug_info
5210 );
5211
5212 IF l_return_status = FND_API.G_RET_STS_ERROR THEN
5213 RAISE FND_API.G_EXC_ERROR;
5214 ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
5215 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5216 END IF;
5217
5218 -- Standard check of p_commit.
5219
5220 IF FND_API.To_Boolean (p_commit) THEN
5221 COMMIT WORK;
5222 END IF;
5223 -- Standard call to get message count and if count is 1, get message info.
5224 FND_MSG_PUB.Count_And_Get (p_encoded => FND_API.g_false, p_count => x_msg_count, p_data => x_msg_data) ;
5225 -- Standard End of Procedure/Function Logging
5226 INL_LOGGING_PVT.Log_EndProc (p_module_name => g_module_name, p_procedure_name => l_api_name) ;
5227 EXCEPTION
5228 WHEN FND_API.G_EXC_ERROR THEN
5229 -- Standard Expected Error Logging
5230 INL_LOGGING_PVT.Log_ExpecError (p_module_name => g_module_name, p_procedure_name => l_api_name) ;
5231 ROLLBACK TO Adjust_ChargeLines_PVT;
5232 x_return_status := FND_API.G_RET_STS_ERROR;
5233 FND_MSG_PUB.Count_And_Get (p_encoded => FND_API.g_false, p_count => x_msg_count, p_data => x_msg_data) ;
5234 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
5235 -- Standard Unexpected Error Logging
5236 INL_LOGGING_PVT.Log_UnexpecError (p_module_name => g_module_name, p_procedure_name => l_api_name) ;
5237 ROLLBACK TO Adjust_ChargeLines_PVT;
5238 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5239 FND_MSG_PUB.Count_And_Get (p_encoded => FND_API.g_false, p_count => x_msg_count, p_data => x_msg_data) ;
5240 WHEN OTHERS THEN
5241 -- Standard Unexpected Error Logging
5242 INL_LOGGING_PVT.Log_UnexpecError (p_module_name => g_module_name, p_procedure_name => l_api_name) ;
5243 ROLLBACK TO Adjust_ChargeLines_PVT;
5244 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
5245 IF FND_MSG_PUB.Check_Msg_Level (p_message_level => FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
5246 FND_MSG_PUB.Add_Exc_Msg (p_pkg_name => g_pkg_name, p_procedure_name => l_api_name) ;
5247 END IF;
5248 FND_MSG_PUB.Count_And_Get (p_encoded => FND_API.g_false, p_count => x_msg_count, p_data => x_msg_data) ;
5249 END Adjust_ChargeLines;
5250
5251 -- API name : Adjust_TaxLines
5252 -- Type : Private
5253 -- Function : Create Adjustment Lines for Charge Lines
5254 -- Pre-reqs : None
5255 -- Parameters :
5256 -- IN : p_api_version IN NUMBER Required
5257 -- p_init_msg_list IN VARCHAR2 Optional Default = FND_API.G_FALSE
5258 -- p_commit IN VARCHAR2 Optional Default = FND_API.G_FALSE
5259 -- p_match_id IN NUMBER,
5260 -- p_adjustment_num IN NUMBER,
5261 -- OUT x_return_status OUT NOCOPY VARCHAR2
5262 -- x_msg_count OUT NOCOPY NUMBER
5263 -- x_msg_data OUT NOCOPY VARCHAR2
5264 --
5265 -- Version : Current version 1.0
5266 --
5267 -- Notes :
5268 PROCEDURE Adjust_TaxLines
5269 (
5270 p_api_version IN NUMBER,
5271 p_init_msg_list IN VARCHAR2 := FND_API.G_FALSE,
5272 p_commit IN VARCHAR2 := FND_API.G_FALSE,
5273 p_match_id IN NUMBER,
5274 p_adjustment_num IN NUMBER,
5275 x_return_status OUT NOCOPY VARCHAR2,
5276 x_msg_count OUT NOCOPY NUMBER,
5277 x_msg_data OUT NOCOPY VARCHAR2)
5278 IS
5279 l_api_name CONSTANT VARCHAR2 (30) := 'Adjust_TaxLines';
5280 l_api_version CONSTANT NUMBER := 1.0;
5281 l_next_adjust_num NUMBER;
5282 l_debug_info VARCHAR2 (240) ;
5283 l_parent_tax_line_id NUMBER;
5284 l_return_status VARCHAR2 (1) ;
5285 l_table_id NUMBER;
5286 l_table_name VARCHAR2 (30) ;
5287 l_ship_header_id NUMBER;
5288 l_matched_curr_code VARCHAR2 (15) ;
5289 l_matched_curr_conversion_type VARCHAR2 (30) ;
5290 l_matched_curr_conversion_date DATE;
5291 l_matched_curr_conversion_rate NUMBER;
5292 l_mat_curr_code VARCHAR2 (15) ;
5293 l_TxLn_Assoc inl_TxLn_Assoc_tp;
5294 l_tax_code VARCHAR2 (30) ;
5295 l_matched_amt NUMBER;
5296 l_nrec_tax_amt NUMBER;
5297 l_include_assoc_flag VARCHAR2 (1) ;
5298 l_tax_amt_included_flag VARCHAR2 (1) ;
5299 l_from_parent_table_name VARCHAR2 (30) ;
5300 l_from_parent_table_id NUMBER;
5301 l_ship_line_id NUMBER;
5302 l_new_tax_line_id NUMBER;
5303 BEGIN
5304 -- Standard Beginning of Procedure/Function Logging
5305 INL_LOGGING_PVT.Log_BeginProc ( p_module_name => g_module_name, p_procedure_name => l_api_name) ;
5306 -- Standard Start of API savepoint
5307 SAVEPOINT Adjust_TaxLines_PVT;
5308 -- Initialize message list if p_init_msg_list is set to TRUE.
5309 IF FND_API.to_Boolean (p_init_msg_list) THEN
5310 FND_MSG_PUB.initialize;
5311 END IF;
5312 -- Check for call compatibility.
5313 IF NOT FND_API.Compatible_API_Call (p_current_version_number => l_api_version, p_caller_version_number => p_api_version, p_api_name => l_api_name, p_pkg_name => g_pkg_name) THEN
5314 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5315 END IF;
5316 -- Initialize API return status to success
5317 x_return_status := FND_API.G_RET_STS_SUCCESS;
5318 -- Getting the match information
5319 l_debug_info := 'Getting the match information';
5320 INL_LOGGING_PVT.Log_Statement (
5321 p_module_name => g_module_name,
5322 p_procedure_name => l_api_name,
5323 p_debug_info => l_debug_info
5324 ) ;
5325
5326 SELECT
5327 m.to_parent_table_name ,
5328 m.to_parent_table_id ,
5329 m.tax_code ,
5330 m.matched_amt ,
5331 m.nrec_tax_amt ,
5332 m.tax_amt_included_flag ,
5333 m.from_parent_table_name ,
5334 m.from_parent_table_id ,
5335 m.matched_curr_code ,
5336 m.matched_curr_conversion_type,
5337 m.matched_curr_conversion_date,
5338 m.matched_curr_conversion_rate,
5339 m.ship_header_id
5340 INTO
5341 l_table_name ,
5342 l_table_id ,
5343 l_tax_code ,
5344 l_matched_amt ,
5345 l_nrec_tax_amt ,
5346 l_tax_amt_included_flag ,
5347 l_from_parent_table_name ,
5348 l_from_parent_table_id ,
5349 l_matched_curr_code ,
5350 l_matched_curr_conversion_type,
5351 l_matched_curr_conversion_date,
5352 l_matched_curr_conversion_rate,
5353 l_ship_header_id
5354 FROM inl_corr_matches_v m
5355 WHERE match_id = p_match_id;
5356 -- Handling estimated tax Line and getting the parent_tax_line_id
5357 l_debug_info := 'Handling estimated tax Line and getting the parent_tax_line_id';
5358 INL_LOGGING_PVT.Log_Statement (
5359 p_module_name => g_module_name,
5360 p_procedure_name => l_api_name,
5361 p_debug_info => l_debug_info
5362 ) ;
5363 -- For now:
5364 -- 1) Create a new tax line ADJ 1 with the new actual value with no ADJ 0
5365 -- 2) For the estimated tax line create a new tax line ADJ 1 with amount = 0
5366 -- Getting information for the new tax line
5367 l_debug_info := 'All Amounts :'||l_matched_amt;
5368 INL_LOGGING_PVT.Log_Statement (
5369 p_module_name => g_module_name,
5370 p_procedure_name => l_api_name,
5371 p_debug_info => l_debug_info
5372 ) ;
5373
5374 l_TxLn_Assoc.inl_Assoc.to_parent_table_name := l_table_name;
5375 IF l_table_name = 'INL_SHIP_LINES' THEN
5376 l_TxLn_Assoc.inl_Assoc.to_parent_table_id := l_table_id;
5377 END IF;
5378
5379 -- l_TxLn_Assoc.adjustment_num := p_adjustment_num;
5380 SELECT NVL (MAX (adjustment_num), 0) + 1
5381 INTO l_TxLn_Assoc.adjustment_num
5382 FROM inl_tax_lines tx
5383 WHERE tx.source_parent_table_name = l_from_parent_table_name
5384 AND tx.source_parent_table_id = l_from_parent_table_id
5385 AND tx.ship_header_id = l_ship_header_id;
5386 IF l_TxLn_Assoc.adjustment_num > 1 THEN
5387 SELECT tax_line_num, tax_line_id
5388 INTO l_TxLn_Assoc.tax_line_num, l_TxLn_Assoc.parent_tax_line_id
5389 FROM inl_tax_lines tx
5390 WHERE tx.source_parent_table_name = l_from_parent_table_name
5391 AND tx.source_parent_table_id = l_from_parent_table_id
5392 AND tx.ship_header_id = l_ship_header_id
5393 AND adjustment_num =
5394 (
5395 SELECT MAX (tx1.adjustment_num)
5396 FROM inl_tax_lines tx1
5397 WHERE tx1.source_parent_table_name = tx.source_parent_table_name
5398 AND tx1.source_parent_table_id = tx.source_parent_table_id
5399 AND tx1.ship_header_id = l_ship_header_id
5400 ) ;
5401 ELSE
5402 l_TxLn_Assoc.tax_line_num := NULL;
5403 l_TxLn_Assoc.parent_tax_line_id := NULL;
5404 END IF;
5405 l_TxLn_Assoc.inl_Assoc.ship_header_id := l_ship_header_id;
5406 l_TxLn_Assoc.inl_Assoc.allocation_basis := 'VALUE';
5407 l_TxLn_Assoc.inl_Assoc.allocation_uom_code := NULL;
5408 l_TxLn_Assoc.tax_code := l_tax_code;
5409 l_TxLn_Assoc.match_id := p_match_id;
5410 l_TxLn_Assoc.matched_amt := l_matched_amt;
5411 l_TxLn_Assoc.nrec_tax_amt := l_nrec_tax_amt;
5412 l_TxLn_Assoc.source_parent_table_name := l_from_parent_table_name;
5413 l_TxLn_Assoc.source_parent_table_id := l_from_parent_table_id;
5414 l_TxLn_Assoc.currency_code := l_matched_curr_code;
5415 l_TxLn_Assoc.currency_conversion_type := l_matched_curr_conversion_type;
5416 l_TxLn_Assoc.currency_conversion_date := l_matched_curr_conversion_date;
5417 l_TxLn_Assoc.currency_conversion_rate := l_matched_curr_conversion_rate;
5418 l_TxLn_Assoc.tax_amt_included_flag := l_tax_amt_included_flag;
5419
5420 IF l_TxLn_Assoc.parent_tax_line_id IS NULL THEN
5421 l_include_assoc_flag:= 'Y';
5422 ELSE
5423 l_include_assoc_flag:= 'N';
5424 END IF;
5425
5426 -- Create_TxLines
5427 l_debug_info := 'Create_TxLines';
5428 INL_LOGGING_PVT.Log_Statement (
5429 p_module_name => g_module_name,
5430 p_procedure_name => l_api_name,
5431 p_debug_info => l_debug_info
5432 ) ;
5433
5434 Create_TxLines (
5435 p_TxLn_Assoc => l_TxLn_Assoc,
5436 p_include_assoc => l_include_assoc_flag,
5437 p_adjustment_num => p_adjustment_num,
5438 x_new_tax_line_id => l_new_tax_line_id,
5439 x_return_status => l_return_status) ;
5440 IF l_return_status = FND_API.G_RET_STS_ERROR THEN
5441 RAISE FND_API.G_EXC_ERROR;
5442 ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
5443 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5444 END IF;
5445 -- The estimated tax lines will made = 0 when as actual arrived on associated line
5446 -- i.e. when a charge became and actual value the estimated taxes will made 0 too
5447 -- Standard check of p_commit.
5448 IF FND_API.To_Boolean (p_commit) THEN
5449 COMMIT WORK;
5450 END IF;
5451 -- Standard call to get message count and if count is 1, get message info.
5452 FND_MSG_PUB.Count_And_Get ( p_encoded => FND_API.g_false, p_count => x_msg_count, p_data => x_msg_data) ;
5453 -- Standard End of Procedure/Function Logging
5454 INL_LOGGING_PVT.Log_EndProc ( p_module_name => g_module_name, p_procedure_name => l_api_name) ;
5455 EXCEPTION
5456 WHEN FND_API.G_EXC_ERROR THEN
5457 -- Standard Expected Error Logging
5458 INL_LOGGING_PVT.Log_ExpecError ( p_module_name => g_module_name, p_procedure_name => l_api_name) ;
5459 ROLLBACK TO Adjust_TaxLines_PVT;
5460 x_return_status := FND_API.G_RET_STS_ERROR;
5461 FND_MSG_PUB.Count_And_Get ( p_encoded => FND_API.g_false, p_count => x_msg_count, p_data => x_msg_data) ;
5462 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
5463 -- Standard Unexpected Error Logging
5464 INL_LOGGING_PVT.Log_UnexpecError ( p_module_name => g_module_name, p_procedure_name => l_api_name) ;
5465 ROLLBACK TO Adjust_TaxLines_PVT;
5466 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5467 FND_MSG_PUB.Count_And_Get ( p_encoded => FND_API.g_false, p_count => x_msg_count, p_data => x_msg_data) ;
5468 WHEN OTHERS THEN
5469 -- Standard Unexpected Error Logging
5470 INL_LOGGING_PVT.Log_UnexpecError ( p_module_name => g_module_name, p_procedure_name => l_api_name) ;
5471 ROLLBACK TO Adjust_TaxLines_PVT;
5472 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
5473 IF FND_MSG_PUB.Check_Msg_Level (p_message_level => FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
5474 FND_MSG_PUB.Add_Exc_Msg ( p_pkg_name => g_pkg_name, p_procedure_name => l_api_name) ;
5475 END IF;
5476 FND_MSG_PUB.Count_And_Get ( p_encoded => FND_API.g_false, p_count => x_msg_count, p_data => x_msg_data) ;
5477 END Adjust_TaxLines;
5478
5479 -- API name : Adjust_TaxLines
5480 -- Type : Private
5481 -- Function : Create Adjustment Lines for Charge Lines
5482 -- Pre-reqs : None
5483 -- Parameters :
5484 -- IN : p_api_version IN NUMBER Required
5485 -- p_init_msg_list IN VARCHAR2 Optional Default = FND_API.G_FALSE
5486 -- p_commit IN VARCHAR2 Optional Default = FND_API.G_FALSE
5487 -- p_match_amount_id IN NUMBER,
5488 -- p_adjustment_num IN NUMBER,
5489 -- OUT x_return_status OUT NOCOPY VARCHAR2
5490 -- x_msg_count OUT NOCOPY NUMBER
5491 -- x_msg_data OUT NOCOPY VARCHAR2
5492 --
5493 -- Version : Current version 1.0
5494 --
5495 -- Notes :
5496 PROCEDURE Adjust_TaxLines(
5497 p_api_version IN NUMBER,
5498 p_init_msg_list IN VARCHAR2 := FND_API.G_FALSE,
5499 p_commit IN VARCHAR2 := FND_API.G_FALSE,
5500 p_match_amount_id IN NUMBER,
5501 p_adjustment_num IN NUMBER,
5502 x_return_status OUT NOCOPY VARCHAR2,
5503 x_msg_count OUT NOCOPY NUMBER,
5504 x_msg_data OUT NOCOPY VARCHAR2
5505 ) IS
5506 l_api_name CONSTANT VARCHAR2 (30) := 'Adjust_TaxLines-2';
5507 l_api_version CONSTANT NUMBER := 1.0;
5508 l_debug_info VARCHAR2 (240) ;
5509 l_return_status VARCHAR2 (1) ;
5510 --
5511 CURSOR c_matches_tl (p_match_amount_id NUMBER)
5512 IS
5513 SELECT distinct
5514 m.to_parent_table_name,
5515 m.to_parent_table_id
5516 FROM inl_corr_matches_v m
5517 WHERE m.match_amount_id = p_match_amount_id;
5518
5519 TYPE c_matches_type
5520 IS
5521 TABLE OF c_matches_tl%ROWTYPE;
5522 c_matches c_matches_type;
5523
5524 l_TxLn_Assoc inl_TxLn_Assoc_tp;
5525 l_existing_match_info_flag VARCHAR2(1);
5526 l_charge_line_type_id NUMBER;
5527 l_new_tax_line_id NUMBER;
5528 BEGIN
5529 -- Standard Beginning of Procedure/Function Logging
5530 INL_LOGGING_PVT.Log_BeginProc ( p_module_name => g_module_name, p_procedure_name => l_api_name) ;
5531 -- Standard Start of API savepoint
5532
5533 SAVEPOINT Adjust_TaxLines_2_PVT;
5534 -- Initialize message list if p_init_msg_list is set to TRUE.
5535 IF FND_API.to_Boolean (p_init_msg_list) THEN
5536 FND_MSG_PUB.initialize;
5537 END IF;
5538 -- Check for call compatibility.
5539 IF NOT FND_API.Compatible_API_Call (p_current_version_number => l_api_version, p_caller_version_number => p_api_version, p_api_name => l_api_name, p_pkg_name => g_pkg_name) THEN
5540 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5541 END IF;
5542 -- Initialize API return status to success
5543 x_return_status := FND_API.G_RET_STS_SUCCESS;
5544
5545 -- Getting the matchAmount information
5546 l_debug_info := 'Getting the matchAmount information';
5547 INL_LOGGING_PVT.Log_Statement (
5548 p_module_name => g_module_name,
5549 p_procedure_name => l_api_name,
5550 p_debug_info => l_debug_info
5551 ) ;
5552
5553 SELECT
5554 ma.matched_amt tax_amt ,
5555 ma.matched_curr_code currency_code ,
5556 ma.matched_curr_conversion_type currency_conversion_type,
5557 ma.matched_curr_conversion_date currency_conversion_date,
5558 ma.matched_curr_conversion_rate currency_conversion_rate,
5559 --
5560 m.tax_code tax_code ,
5561 m.ship_header_id ship_header_id ,
5562 min(m.from_parent_table_name) source_parent_table_name,
5563 min(m.from_parent_table_id) source_parent_table_id ,
5564 sum(m.nrec_tax_amt) nrec_tax_amt ,
5565 m.tax_amt_included_flag tax_amt_included_flag ,
5566 m.charge_line_type_id charge_line_type_id ,
5567 --
5568 clt.allocation_basis allocation_basis ,
5569 abv.base_uom_code base_uom_code ,
5570 MAX(m.existing_match_info_flag) existing_match_info_flag
5571 INTO
5572 l_TxLn_Assoc.matched_amt ,
5573 l_TxLn_Assoc.currency_code ,
5574 l_TxLn_Assoc.currency_conversion_type ,
5575 l_TxLn_Assoc.currency_conversion_date ,
5576 l_TxLn_Assoc.currency_conversion_rate ,
5577 --
5578 l_TxLn_Assoc.tax_code ,
5579 l_TxLn_Assoc.inl_Assoc.ship_header_id ,
5580 l_TxLn_Assoc.source_parent_table_name ,
5581 l_TxLn_Assoc.source_parent_table_id ,
5582 l_TxLn_Assoc.nrec_tax_amt ,
5583 l_TxLn_Assoc.tax_amt_included_flag ,
5584 l_charge_line_type_id ,
5585 --
5586 l_TxLn_Assoc.inl_Assoc.allocation_basis,
5587 l_TxLn_Assoc.inl_Assoc.allocation_uom_code,
5588 l_existing_match_info_flag
5589 FROM
5590 inl_corr_match_amounts_v ma ,
5591 inl_matches m ,
5592 inl_charge_line_types_vl clt,
5593 inl_allocation_basis_vl abv
5594 WHERE
5595 abv.allocation_basis_code = clt.allocation_basis
5596 AND clt.charge_line_type_id = m.charge_line_type_id
5597 AND m.match_amount_id = ma.match_amount_id
5598 AND ma.match_amount_id = p_match_amount_id
5599 GROUP BY
5600 m.tax_code ,
5601 m.ship_header_id ,
5602 m.tax_amt_included_flag ,
5603 m.charge_line_type_id ,
5604 ma.matched_amt ,
5605 ma.matched_curr_code ,
5606 ma.matched_curr_conversion_type,
5607 ma.matched_curr_conversion_date,
5608 ma.matched_curr_conversion_rate,
5609 clt.allocation_basis ,
5610 abv.base_uom_code
5611 ;
5612
5613 l_debug_info := 'Verify Existing match info flag';
5614 INL_LOGGING_PVT.Log_Variable (p_module_name => g_module_name,
5615 p_procedure_name => l_api_name,
5616 p_var_name => l_debug_info,
5617 p_var_value => l_existing_match_info_flag) ;
5618 IF (l_existing_match_info_flag = 'Y') THEN
5619 -- Tax has been already processed
5620 l_debug_info := 'Existing match info flag';
5621 INL_LOGGING_PVT.Log_Statement (
5622 p_module_name => g_module_name,
5623 p_procedure_name => l_api_name,
5624 p_debug_info => l_debug_info
5625 ) ;
5626
5627 SELECT tl.tax_line_id, tl.tax_line_num
5628 INTO l_TxLn_Assoc.parent_tax_line_id, l_TxLn_Assoc.tax_line_num
5629 FROM inl_matches m,
5630 inl_adj_tax_lines_v tl
5631 WHERE m.from_parent_table_name = l_TxLn_Assoc.source_parent_table_name
5632 AND m.from_parent_table_id = l_TxLn_Assoc.source_parent_table_id
5633 AND m.match_id = (select max(m2.match_id)
5634 FROM inl_matches m2
5635 WHERE m2.from_parent_table_name = l_TxLn_Assoc.source_parent_table_name
5636 AND m2.from_parent_table_id = l_TxLn_Assoc.source_parent_table_id)
5637 AND tl.match_amount_id = m.match_amount_id;
5638 ELSE
5639 l_TxLn_Assoc.parent_tax_line_id := NULL;
5640 l_TxLn_Assoc.tax_line_num := NULL;
5641 END IF;
5642 l_TxLn_Assoc.match_id := NULL;
5643 l_TxLn_Assoc.match_amount_id := p_match_amount_id;
5644
5645 -- Create_TxLines
5646 l_debug_info := 'Create_TxLines';
5647 INL_LOGGING_PVT.Log_Statement (
5648 p_module_name => g_module_name,
5649 p_procedure_name => l_api_name,
5650 p_debug_info => l_debug_info
5651 ) ;
5652
5653 Create_TxLines (
5654 p_TxLn_Assoc => l_TxLn_Assoc,
5655 p_include_assoc => 'N',
5656 p_adjustment_num => p_adjustment_num,
5657 x_new_tax_line_id => l_new_tax_line_id,
5658 x_return_status => l_return_status) ;
5659 IF l_return_status = FND_API.G_RET_STS_ERROR THEN
5660 RAISE FND_API.G_EXC_ERROR;
5661 ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
5662 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5663 END IF;
5664
5665 -- It does not create associations for corrections neither to updates
5666 IF (l_existing_match_info_flag = 'N') THEN
5667 -- Create_associations for the match amount id
5668 l_debug_info := 'Create association lines to a match_amount_id';
5669 INL_LOGGING_PVT.Log_Statement (
5670 p_module_name => g_module_name,
5671 p_procedure_name => l_api_name,
5672 p_debug_info => l_debug_info
5673 ) ;
5674 OPEN c_matches_tl (p_match_amount_id) ;
5675 FETCH c_matches_tl BULK COLLECT INTO c_matches;
5676 CLOSE c_matches_tl;
5677 l_debug_info := c_matches.LAST||' match lines have been retrieved.';
5678 INL_LOGGING_PVT.Log_Statement (p_module_name => g_module_name, p_procedure_name => l_api_name, p_debug_info => l_debug_info) ;
5679 IF NVL (c_matches.LAST, 0) > 0 THEN
5680 FOR i IN NVL (c_matches.FIRST, 0) ..NVL (c_matches.LAST, 0)
5681 LOOP
5682 l_TxLn_Assoc.inl_Assoc.to_parent_table_name := c_matches(i).to_parent_table_name;
5683 l_TxLn_Assoc.inl_Assoc.to_parent_table_id := c_matches(i).to_parent_table_id;
5684 -- Create Association Line
5685 l_debug_info := 'Create association line for the charge';
5686 INL_LOGGING_PVT.Log_Statement (
5687 p_module_name => g_module_name,
5688 p_procedure_name => l_api_name,
5689 p_debug_info => l_debug_info
5690 ) ;
5691
5692 l_debug_info := 'Creating association for Charge Id: '|| c_matches (i) .to_parent_table_id;
5693 INL_LOGGING_PVT.Log_Variable (p_module_name => g_module_name,
5694 p_procedure_name => l_api_name,
5695 p_var_name => l_debug_info,
5696 p_var_value => c_matches (i) .to_parent_table_id) ;
5697 Create_Assoc (p_Assoc => l_TxLn_Assoc.inl_Assoc,
5698 p_from_parent_table_name => 'INL_TAX_LINES',
5699 p_new_line_id => l_new_tax_line_id,
5700 x_return_status => l_return_status) ;
5701 END LOOP;
5702 END IF;
5703 END IF;
5704
5705 -- The estimated tax lines will made = 0 when as actual arrived on associated line
5706 -- i.e. when a charge became and actual value the estimated taxes will made 0 too
5707 -- Standard check of p_commit.
5708 IF FND_API.To_Boolean (p_commit) THEN
5709 COMMIT WORK;
5710 END IF;
5711 -- Standard call to get message count and if count is 1, get message info.
5712 FND_MSG_PUB.Count_And_Get ( p_encoded => FND_API.g_false, p_count => x_msg_count, p_data => x_msg_data) ;
5713 -- Standard End of Procedure/Function Logging
5714 INL_LOGGING_PVT.Log_EndProc ( p_module_name => g_module_name, p_procedure_name => l_api_name) ;
5715 EXCEPTION
5716 WHEN FND_API.G_EXC_ERROR THEN
5717 -- Standard Expected Error Logging
5718 INL_LOGGING_PVT.Log_ExpecError ( p_module_name => g_module_name, p_procedure_name => l_api_name) ;
5719 ROLLBACK TO Adjust_TaxLines_2_PVT_PVT;
5720 x_return_status := FND_API.G_RET_STS_ERROR;
5721 FND_MSG_PUB.Count_And_Get ( p_encoded => FND_API.g_false, p_count => x_msg_count, p_data => x_msg_data) ;
5722 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
5723 -- Standard Unexpected Error Logging
5724 INL_LOGGING_PVT.Log_UnexpecError ( p_module_name => g_module_name, p_procedure_name => l_api_name) ;
5725 ROLLBACK TO Adjust_TaxLines_2_PVT_PVT;
5726 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5727 FND_MSG_PUB.Count_And_Get ( p_encoded => FND_API.g_false, p_count => x_msg_count, p_data => x_msg_data) ;
5728 WHEN OTHERS THEN
5729 -- Standard Unexpected Error Logging
5730 INL_LOGGING_PVT.Log_UnexpecError ( p_module_name => g_module_name, p_procedure_name => l_api_name) ;
5731 ROLLBACK TO Adjust_TaxLines_2_PVT;
5732 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
5733 IF FND_MSG_PUB.Check_Msg_Level (p_message_level => FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
5734 FND_MSG_PUB.Add_Exc_Msg ( p_pkg_name => g_pkg_name, p_procedure_name => l_api_name) ;
5735 END IF;
5736 FND_MSG_PUB.Count_And_Get ( p_encoded => FND_API.g_false, p_count => x_msg_count, p_data => x_msg_data) ;
5737 END Adjust_TaxLines;
5738
5739 -- API name : Adjust_Lines
5740 -- Type : Private
5741 -- Function : Manages the Creation of Adjustment Lines for Shipment Lines and Charge Lines
5742 -- Pre-reqs : None
5743 -- Parameters :
5744 -- IN : p_api_version IN NUMBER Required
5745 -- p_init_msg_list IN VARCHAR2 Optional Default = FND_API.G_FALSE
5746 -- p_commit IN VARCHAR2 Optional Default = FND_API.G_FALSE
5747 -- p_ship_header_id IN NUMBER,
5748 -- OUT x_return_status OUT NOCOPY VARCHAR2
5749 -- x_msg_count OUT NOCOPY NUMBER
5750 -- x_msg_data OUT NOCOPY VARCHAR2
5751 --
5752 -- Version : Current version 1.0
5753 --
5754 -- Notes :
5755 PROCEDURE Adjust_Lines
5756 (
5757 p_api_version IN NUMBER,
5758 p_init_msg_list IN VARCHAR2 := FND_API.G_FALSE,
5759 p_commit IN VARCHAR2 := FND_API.G_FALSE,
5760 p_ship_header_id IN NUMBER,
5761 x_return_status OUT NOCOPY VARCHAR2,
5762 x_msg_count OUT NOCOPY NUMBER,
5763 x_msg_data OUT NOCOPY VARCHAR2)
5764 IS
5765 l_api_name CONSTANT VARCHAR2 (30) := 'Adjust_Lines';
5766 l_api_version CONSTANT NUMBER := 1.0;
5767 l_return_status VARCHAR2 (1) ;
5768 l_msg_count NUMBER;
5769 l_msg_data VARCHAR2 (2000) ;
5770 l_debug_info VARCHAR2 (200) ;
5771 l_adjust_updt_flag BOOLEAN := False;
5772 l_adjustment_num NUMBER;
5773 CURSOR MATCH
5774 IS
5775 SELECT
5776 m.match_id ,
5777 m.correction_match_id ,
5778 m.match_amount_id ,
5779 m.match_type_code ,
5780 m.charge_line_type_id ,
5781 m.tax_code ,
5782 m.to_parent_table_name,
5783 m.to_parent_table_id
5784 FROM
5785 inl_charge_lines cl,
5786 inl_ship_lines sl ,
5787 inl_ship_headers sh ,
5788 inl_corr_matches_v m
5789 WHERE
5790 cl.charge_line_id (+) = DECODE (m.to_parent_table_name, 'INL_CHARGE_LINES', m.to_parent_table_id, NULL)
5791 AND sl.ship_line_id (+) = DECODE (m.to_parent_table_name, 'INL_SHIP_LINES', m.to_parent_table_id, NULL)
5792 AND sh.ship_header_id = m.ship_header_id
5793 AND m.ship_header_id = p_ship_header_id
5794 AND m.match_amount_id IS NULL
5795 AND m.match_type_code <> 'CORRECTION'
5796 AND NVL (m.adj_already_generated_flag, 'N') = 'N'
5797
5798 UNION
5799
5800 SELECT DISTINCT
5801 NULL AS match_id ,
5802 NULL AS correction_match_id ,
5803 m.match_amount_id AS match_amount_id ,
5804 m.match_type_code AS match_type_code ,
5805 NULL AS charge_line_type_id ,
5806 NULL AS tax_code ,
5807 NULL AS to_parent_table_name,
5808 NULL AS to_parent_table_id
5809 FROM
5810 inl_ship_headers sh,
5811 inl_corr_matches_v m
5812 WHERE
5813 sh.ship_header_id = m.ship_header_id
5814 AND m.ship_header_id = p_ship_header_id
5815 AND m.match_amount_id IS NOT NULL
5816 AND m.match_type_code <> 'CORRECTION'
5817 AND NVL (m.adj_already_generated_flag, 'N') = 'N'
5818 ORDER BY 1;
5819
5820 rec_match match%ROWTYPE;
5821 --
5822 -- Create Adjustments for Shipment Lines and Charge Lines
5823 --
5824 BEGIN
5825 -- Standard Beginning of Procedure/Function Logging
5826 INL_LOGGING_PVT.Log_BeginProc ( p_module_name => g_module_name, p_procedure_name => l_api_name) ;
5827 -- Standard Start of API savepoint
5828 SAVEPOINT Adjust_Lines_PVT;
5829 -- Initialize message list if p_init_msg_list is set to TRUE.
5830 IF FND_API.to_Boolean (p_init_msg_list) THEN
5831 FND_MSG_PUB.initialize;
5832 END IF;
5833 -- Check for call compatibility.
5834 IF NOT FND_API.Compatible_API_Call (p_current_version_number => l_api_version, p_caller_version_number => p_api_version, p_api_name => l_api_name, p_pkg_name => g_pkg_name) THEN
5835 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5836 END IF;
5837 -- Initialize API return status to success
5838 x_return_status := FND_API.G_RET_STS_SUCCESS;
5839 -- API Body
5840 BEGIN
5841 l_debug_info := 'Create Adjustments for Shipment Lines and Charge Lines';
5842 INL_LOGGING_PVT.Log_Statement (
5843 p_module_name => g_module_name,
5844 p_procedure_name => l_api_name,
5845 p_debug_info => l_debug_info
5846 ) ;
5847
5848 SELECT adjustment_num + 1
5849 INTO l_adjustment_num
5850 FROM inl_ship_headers
5851 WHERE ship_header_id = p_ship_header_id FOR UPDATE;
5852
5853 l_debug_info := 'l_adjustment_num';
5854 INL_LOGGING_PVT.Log_Variable (p_module_name => g_module_name, p_procedure_name => l_api_name, p_var_name => l_debug_info, p_var_value => TO_CHAR (l_adjustment_num)) ;
5855 OPEN MATCH;
5856 LOOP
5857 FETCH MATCH INTO rec_match;
5858 EXIT WHEN match%NOTFOUND;
5859
5860 l_debug_info := 'rec_match.match_id';
5861 INL_LOGGING_PVT.Log_Variable (
5862 p_module_name => g_module_name,
5863 p_procedure_name => l_api_name,
5864 p_var_name => l_debug_info,
5865 p_var_value => rec_match.match_id
5866 ) ;
5867 l_debug_info := 'rec_match.match_id';
5868 INL_LOGGING_PVT.Log_Variable (
5869 p_module_name => g_module_name,
5870 p_procedure_name => l_api_name,
5871 p_var_name => l_debug_info,
5872 p_var_value => rec_match.match_id
5873 ) ;
5874 l_debug_info := '(INL_SHIP_LINES) rec_match.to_parent_table_id';
5875 INL_LOGGING_PVT.Log_Variable (
5876 p_module_name => g_module_name,
5877 p_procedure_name => l_api_name,
5878 p_var_name => l_debug_info,
5879 p_var_value => TO_CHAR (rec_match.to_parent_table_id)
5880 ) ;
5881 IF rec_match.match_type_code = 'ITEM' THEN
5882 l_adjust_updt_flag := TRUE;
5883 Adjust_ShipLines (
5884 p_api_version => 1.0,
5885 p_init_msg_list => FND_API.G_FALSE,
5886 p_commit => FND_API.G_FALSE,
5887 p_match_id => rec_match.match_id,
5888 p_adjustment_num => l_adjustment_num,
5889 x_return_status => l_return_status,
5890 x_msg_count => l_msg_count,
5891 x_msg_data => l_msg_data
5892 ) ;
5893 ELSIF rec_match.match_type_code = 'CHARGE' AND rec_match.match_amount_id IS NULL THEN
5894 l_adjust_updt_flag := TRUE;
5895 Adjust_ChargeLines (
5896 p_api_version => 1.0,
5897 p_init_msg_list => FND_API.G_FALSE,
5898 p_commit => FND_API.G_FALSE,
5899 p_match_id => rec_match.match_id,
5900 p_adjustment_num => l_adjustment_num,
5901 x_return_status => l_return_status,
5902 x_msg_count => l_msg_count,
5903 x_msg_data => l_msg_data
5904 ) ;
5905 ELSIF rec_match.match_type_code = 'CHARGE' AND rec_match.match_amount_id IS NOT NULL THEN
5906 l_adjust_updt_flag := TRUE;
5907 Adjust_ChargeLines (
5908 p_api_version => 1.0,
5909 p_init_msg_list => FND_API.G_FALSE,
5910 p_commit => FND_API.G_FALSE,
5911 p_match_amount_id => rec_match.match_amount_id,
5912 p_adjustment_num => l_adjustment_num,
5913 x_return_status => l_return_status,
5914 x_msg_count => l_msg_count,
5915 x_msg_data => l_msg_data
5916 ) ;
5917 ELSIF rec_match.match_type_code = 'TAX' AND rec_match.match_amount_id IS NOT NULL THEN
5918 l_adjust_updt_flag := TRUE;
5919 Adjust_TaxLines (
5920 p_api_version => 1.0,
5921 p_init_msg_list => FND_API.G_FALSE,
5922 p_commit => FND_API.G_FALSE,
5923 p_match_amount_id => rec_match.match_amount_id,
5924 p_adjustment_num => l_adjustment_num,
5925 x_return_status => l_return_status,
5926 x_msg_count => l_msg_count,
5927 x_msg_data => l_msg_data
5928 ) ;
5929 ELSIF rec_match.match_type_code = 'TAX' THEN
5930 l_adjust_updt_flag := TRUE;
5931 Adjust_TaxLines (
5932 p_api_version => 1.0,
5933 p_init_msg_list => FND_API.G_FALSE,
5934 p_commit => FND_API.G_FALSE,
5935 p_match_id => rec_match.match_id,
5936 p_adjustment_num => l_adjustment_num,
5937 x_return_status => l_return_status,
5938 x_msg_count => l_msg_count,
5939 x_msg_data => l_msg_data
5940 ) ;
5941 END IF;
5942 -- If any errors happen abort API.
5943 IF l_return_status = FND_API.G_RET_STS_ERROR THEN
5944 RAISE FND_API.G_EXC_ERROR;
5945 ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
5946 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5947 END IF;
5948 -- Flag the matches that already generated ajustments
5949 UPDATE inl_matches m
5950 SET m.adj_already_generated_flag = 'Y' ,
5951 last_updated_by = fnd_global.user_id,
5952 last_update_date = SYSDATE
5953 WHERE m.match_id = NVL (rec_match.correction_match_id, rec_match.match_id)
5954 OR m.match_amount_id = rec_match.match_amount_id;
5955 END LOOP;
5956 CLOSE MATCH;
5957 l_debug_info := 'Update Shipment Header Adjustment Number';
5958 INL_LOGGING_PVT.Log_Statement (
5959 p_module_name => g_module_name,
5960 p_procedure_name => l_api_name,
5961 p_debug_info => l_debug_info
5962 ) ;
5963
5964 -- Update Shipment Header Adjustment Number
5965 IF l_adjust_updt_flag THEN
5966 UPDATE inl_ship_headers
5967 SET adjustment_num = l_adjustment_num
5968 WHERE ship_header_id = p_ship_header_id;
5969 END IF;
5970 END;
5971 -- End of API Body
5972 -- Standard check of p_commit.
5973 IF FND_API.To_Boolean (p_commit) THEN
5974 COMMIT WORK;
5975 END IF;
5976 -- Standard call to get message count and if count is 1, get message info.
5977 FND_MSG_PUB.Count_And_Get ( p_encoded => FND_API.g_false, p_count => x_msg_count, p_data => x_msg_data) ;
5978 -- Standard End of Procedure/Function Logging
5979 INL_LOGGING_PVT.Log_EndProc ( p_module_name => g_module_name, p_procedure_name => l_api_name) ;
5980 EXCEPTION
5981 WHEN FND_API.G_EXC_ERROR THEN
5982 -- Standard Expected Error Logging
5983 INL_LOGGING_PVT.Log_ExpecError ( p_module_name => g_module_name, p_procedure_name => l_api_name) ;
5984 ROLLBACK TO Adjust_Lines_PVT;
5985 x_return_status := FND_API.G_RET_STS_ERROR;
5986 FND_MSG_PUB.Count_And_Get ( p_encoded => FND_API.g_false, p_count => x_msg_count, p_data => x_msg_data) ;
5987 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
5988 -- Standard Unexpected Error Logging
5989 INL_LOGGING_PVT.Log_UnexpecError ( p_module_name => g_module_name, p_procedure_name => l_api_name) ;
5990 ROLLBACK TO Adjust_Lines_PVT;
5991 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5992 FND_MSG_PUB.Count_And_Get ( p_encoded => FND_API.g_false, p_count => x_msg_count, p_data => x_msg_data) ;
5993 WHEN OTHERS THEN
5994 -- Standard Unexpected Error Logging
5995 INL_LOGGING_PVT.Log_UnexpecError ( p_module_name => g_module_name, p_procedure_name => l_api_name) ;
5996 ROLLBACK TO Adjust_Lines_PVT;
5997 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
5998 IF FND_MSG_PUB.Check_Msg_Level (p_message_level => FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
5999 FND_MSG_PUB.Add_Exc_Msg ( p_pkg_name => g_pkg_name, p_procedure_name => l_api_name) ;
6000 END IF;
6001 FND_MSG_PUB.Count_And_Get ( p_encoded => FND_API.g_false, p_count => x_msg_count, p_data => x_msg_data) ;
6002 END Adjust_Lines;
6003
6004 -- API name : Get_1ary2aryQty
6005 -- Type : Private
6006 -- Function : Get uom_class, uom_code, qty for 1ary and 2ary UOM
6007 --
6008 -- Pre-reqs : None
6009 -- Parameters :
6010 -- IN : p_api_version IN NUMBER Required
6011 -- p_init_msg_list IN VARCHAR2 Optional Default = FND_API.G_FALSE
6012 -- p_commit IN VARCHAR2 Optional Default = FND_API.G_FALSE
6013 -- p_inventory_item_id IN NUMBER
6014 -- p_organization_id IN NUMBER
6015 -- p_uom_code IN VARCHAR2
6016 -- p_qty IN NUMBER
6017 -- OUT :
6018 -- x_1ary_uom_code OUT NOCOPY VARCHAR2
6019 -- x_1ary_qty OUT NOCOPY NUMBER,
6020 -- x_2ary_uom_code OUT NOCOPY VARCHAR2
6021 -- x_2ary_qty OUT NOCOPY NUMBER,
6022 -- x_return_status OUT NOCOPY VARCHAR2
6023 -- x_msg_count OUT NOCOPY NUMBER
6024 -- x_msg_data OUT NOCOPY VARCHAR2
6025 --
6026 --
6027 -- Version : Current version 1.0
6028 --
6029 -- Notes :
6030 PROCEDURE Get_1ary2aryQty
6031 (
6032 p_api_version IN NUMBER,
6033 p_init_msg_list IN VARCHAR2 := FND_API.G_FALSE,
6034 p_commit IN VARCHAR2 := FND_API.G_FALSE,
6035 p_inventory_item_id IN NUMBER,
6036 p_organization_id IN NUMBER,
6037 p_uom_code IN VARCHAR2,
6038 p_qty IN NUMBER,
6039 x_1ary_uom_code OUT NOCOPY VARCHAR2,
6040 x_1ary_qty OUT NOCOPY NUMBER,
6041 x_2ary_uom_code OUT NOCOPY VARCHAR2,
6042 x_2ary_qty OUT NOCOPY NUMBER,
6043 x_return_status OUT NOCOPY VARCHAR2,
6044 x_msg_count OUT NOCOPY NUMBER,
6045 x_msg_data OUT NOCOPY VARCHAR2)
6046 IS
6047 l_debug_info VARCHAR2 (240) ;
6048 l_api_name CONSTANT VARCHAR2 (30) := 'Get_1ary2aryQty';
6049 l_api_version CONSTANT NUMBER := 1.0;
6050 BEGIN
6051 INL_LOGGING_PVT.Log_BeginProc ( p_module_name => g_module_name, p_procedure_name => l_api_name) ;
6052 -- Standard Start of API savepoint
6053 SAVEPOINT Get_1ary2aryQty_PVT;
6054 -- Initialize message list if p_init_msg_list is set to TRUE.
6055 IF FND_API.to_Boolean (p_init_msg_list) THEN
6056 FND_MSG_PUB.initialize;
6057 END IF;
6058 -- Check for call compatibility.
6059 IF NOT FND_API.Compatible_API_Call (p_current_version_number => l_api_version, p_caller_version_number => p_api_version, p_api_name => l_api_name, p_pkg_name => g_pkg_name) THEN
6060 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6061 END IF;
6062 --
6063 -- Initialize return status to SUCCESS
6064 --
6065 x_return_status := FND_API.G_RET_STS_SUCCESS;
6066 l_debug_info := 'Getting 1ary and 2ary UOM Code from MTL tables';
6067 INL_LOGGING_PVT.Log_Statement (
6068 p_module_name => g_module_name,
6069 p_procedure_name => l_api_name,
6070 p_debug_info => l_debug_info
6071 ) ;
6072
6073 SELECT msi.primary_uom_code,
6074 msi.secondary_uom_code
6075 INTO x_1ary_uom_code,
6076 x_2ary_uom_code
6077 FROM mtl_system_items_vl msi
6078 WHERE msi.inventory_item_id = p_inventory_item_id
6079 AND msi.organization_id = p_organization_id;
6080
6081 l_debug_info := 'Have gotten from mtl_system_items_vl:';
6082 INL_LOGGING_PVT.Log_Statement (
6083 p_module_name => g_module_name,
6084 p_procedure_name => l_api_name,
6085 p_debug_info => l_debug_info
6086 ) ;
6087
6088 l_debug_info := 'x_1ary_uom_code';
6089 INL_LOGGING_PVT.Log_Variable (p_module_name => g_module_name, p_procedure_name => l_api_name, p_var_name => l_debug_info, p_var_value => x_1ary_uom_code) ;
6090 l_debug_info := 'x_2ary_uom_code';
6091 INL_LOGGING_PVT.Log_Variable (p_module_name => g_module_name, p_procedure_name => l_api_name, p_var_name => l_debug_info, p_var_value => x_2ary_uom_code) ;
6092 IF x_1ary_uom_code IS NOT NULL THEN
6093 l_debug_info := 'Doing the 1ary UOM convertion';
6094 INL_LOGGING_PVT.Log_Statement (
6095 p_module_name => g_module_name,
6096 p_procedure_name => l_api_name,
6097 p_debug_info => l_debug_info
6098 ) ;
6099
6100 inl_logging_pvt.Log_APICallIn (p_module_name => g_module_name,
6101 p_procedure_name => l_api_name,
6102 p_call_api_name => 'INL_LANDEDCOST_PVT.Converted_Qty',
6103 p_in_param_name1 => 'p_organization_id',
6104 p_in_param_value1 => p_organization_id,
6105 p_in_param_name2 => 'p_inventory_item_id',
6106 p_in_param_value2 => p_inventory_item_id,
6107 p_in_param_name3 => 'p_qty',
6108 p_in_param_value3 => p_qty,
6109 p_in_param_name4 => 'p_uom_code',
6110 p_in_param_value4 => p_uom_code,
6111 p_in_param_name5 => 'x_1ary_uom_code',
6112 p_in_param_value5 => x_1ary_uom_code,
6113 p_in_param_name6 => NULL,
6114 p_in_param_value6 => NULL,
6115 p_in_param_name7 => NULL,
6116 p_in_param_value7 => NULL,
6117 p_in_param_name8 => NULL,
6118 p_in_param_value8 => NULL,
6119 p_in_param_name9 => NULL,
6120 p_in_param_value9 => NULL,
6121 p_in_param_name10 => NULL,
6122 p_in_param_value10 => NULL) ;
6123 x_1ary_qty := INL_LANDEDCOST_PVT.Converted_Qty (p_organization_id => p_organization_id,
6124 p_inventory_item_id => p_inventory_item_id,
6125 p_qty => p_qty,
6126 p_from_uom_code => p_uom_code,
6127 P_to_uom_code => x_1ary_uom_code) ;
6128 l_debug_info := 'x_1ary_qty';
6129 INL_LOGGING_PVT.Log_Variable (p_module_name => g_module_name,
6130 p_procedure_name => l_api_name,
6131 p_var_name => l_debug_info,
6132 p_var_value => TO_CHAR (x_1ary_qty)) ;
6133 END IF;
6134 --==========
6135 IF x_2ary_uom_code IS NOT NULL THEN
6136 l_debug_info := 'Doing the 2ary UOM convertion';
6137 INL_LOGGING_PVT.Log_Statement (
6138 p_module_name => g_module_name,
6139 p_procedure_name => l_api_name,
6140 p_debug_info => l_debug_info
6141 ) ;
6142
6143 inl_logging_pvt.Log_APICallIn (p_module_name => g_module_name,
6144 p_procedure_name => l_api_name,
6145 p_call_api_name => 'INL_LANDEDCOST_PVT.Converted_Qty',
6146 p_in_param_name1 => 'p_organization_id',
6147 p_in_param_value1 => p_organization_id,
6148 p_in_param_name2 => 'p_inventory_item_id',
6149 p_in_param_value2 => p_inventory_item_id,
6150 p_in_param_name3 => 'p_qty',
6151 p_in_param_value3 => p_qty,
6152 p_in_param_name4 => 'p_uom_code',
6153 p_in_param_value4 => p_uom_code,
6154 p_in_param_name5 => 'x_2ary_uom_code',
6155 p_in_param_value5 => x_2ary_uom_code,
6156 p_in_param_name6 => NULL,
6157 p_in_param_value6 => NULL,
6158 p_in_param_name7 => NULL,
6159 p_in_param_value7 => NULL,
6160 p_in_param_name8 => NULL,
6161 p_in_param_value8 => NULL,
6162 p_in_param_name9 => NULL,
6163 p_in_param_value9 => NULL,
6164 p_in_param_name10 => NULL,
6165 p_in_param_value10 => NULL) ;
6166 x_2ary_qty := INL_LANDEDCOST_PVT.Converted_Qty (p_organization_id => p_organization_id,
6167 p_inventory_item_id => p_inventory_item_id,
6168 p_qty => p_qty,
6169 p_from_uom_code => p_uom_code,
6170 P_to_uom_code => x_2ary_uom_code) ;
6171 l_debug_info := 'x_2ary_qty';
6172 INL_LOGGING_PVT.Log_Variable (p_module_name => g_module_name,
6173 p_procedure_name => l_api_name,
6174 p_var_name => l_debug_info,
6175 p_var_value => TO_CHAR (x_2ary_qty)) ;
6176 END IF;
6177 --==========
6178 -- Standard check of p_commit.
6179 IF FND_API.To_Boolean (p_commit) THEN
6180 COMMIT WORK;
6181 END IF;
6182 -- Standard call to get message count and if count is 1, get message info.
6183 FND_MSG_PUB.Count_And_Get (p_encoded => FND_API.g_false, p_count => x_msg_count, p_data => x_msg_data) ;
6184 INL_LOGGING_PVT.Log_EndProc ( p_module_name => g_module_name, p_procedure_name => l_api_name) ;
6185 EXCEPTION
6186 WHEN FND_API.G_EXC_ERROR THEN
6187 INL_LOGGING_PVT.Log_ExpecError ( p_module_name => g_module_name, p_procedure_name => l_api_name) ;
6188 x_return_status := FND_API.G_RET_STS_ERROR;
6189 ROLLBACK TO Get_1ary2aryQty_PVT;
6190 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
6191 INL_LOGGING_PVT.Log_UnexpecError ( p_module_name => g_module_name, p_procedure_name => l_api_name) ;
6192 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6193 ROLLBACK TO Get_1ary2aryQty_PVT;
6194 WHEN OTHERS THEN
6195 INL_LOGGING_PVT.Log_UnexpecError ( p_module_name => g_module_name, p_procedure_name => l_api_name) ;
6196 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6197 ROLLBACK TO Get_1ary2aryQty_PVT;
6198 IF FND_MSG_PUB.Check_Msg_Level (p_message_level => FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
6199 FND_MSG_PUB.Add_Exc_Msg ( p_pkg_name => g_pkg_name, p_procedure_name => l_api_name) ;
6200 END IF;
6201 END Get_1ary2aryQty;
6202
6203 -- Utility name : Get_SrcAvailableQty
6204 -- Type : Public
6205 -- Function : Returns the available quantity for a given PLL
6206 -- Pre-reqs : None
6207 -- Parameters :
6208 -- IN : p_ship_line_src_type_code IN VARCHAR2
6209 -- p_parent_id IN NUMBER
6210 --
6211 -- Version : Current version 1.0
6212 --
6213 -- Notes :
6214 FUNCTION Get_SrcAvailableQty(p_ship_line_src_type_code IN VARCHAR2,
6215 p_parent_id IN NUMBER) RETURN NUMBER
6216 IS
6217 l_func_name CONSTANT VARCHAR2(30) := 'Get_SrcAvailableQty';
6218 l_debug_info VARCHAR2(200);
6219 l_return_status VARCHAR2(1);
6220 l_msg_count NUMBER;
6221 l_msg_data VARCHAR2(2000);
6222
6223 l_available_qty NUMBER;
6224 l_tolerable_quantity NUMBER;
6225 l_unit_of_measure VARCHAR2(30);
6226
6227 BEGIN
6228 -- Standard Beginning of Procedure/Function Logging
6229 INL_LOGGING_PVT.Log_BeginProc ( p_module_name => g_module_name,
6230 p_procedure_name => l_func_name) ;
6231
6232 -- Logging variables
6233 INL_LOGGING_PVT.Log_Variable ( p_module_name => g_module_name,
6234 p_procedure_name => l_func_name,
6235 p_var_name => 'p_ship_line_src_type_code',
6236 p_var_value => p_ship_line_src_type_code) ;
6237 INL_LOGGING_PVT.Log_Variable ( p_module_name => g_module_name,
6238 p_procedure_name => l_func_name,
6239 p_var_name => 'p_parent_id',
6240 p_var_value => p_parent_id) ;
6241
6242 l_debug_info := 'Call INL_SHIPMENT_PVT.Get_AvailableQty';
6243 INL_LOGGING_PVT.Log_Statement ( p_module_name => g_module_name,
6244 p_procedure_name => l_func_name,
6245 p_debug_info => l_debug_info) ;
6246
6247 INL_SHIPMENT_PVT.Get_AvailableQty(p_api_version => 1.0,
6248 p_init_msg_list => FND_API.G_FALSE,
6249 p_commit => FND_API.G_FALSE,
6250 p_ship_line_src_code => p_ship_line_src_type_code,
6251 p_parent_id => p_parent_id,
6252 p_available_quantity => l_available_qty,
6253 p_tolerable_quantity => l_tolerable_quantity,
6254 p_unit_of_measure => l_unit_of_measure,
6255 x_return_status => l_return_status,
6256 x_msg_count => l_msg_count,
6257 x_msg_data => l_msg_data);
6258
6259 INL_LOGGING_PVT.Log_Variable ( p_module_name => g_module_name,
6260 p_procedure_name => l_func_name,
6261 p_var_name => 'l_available_qty',
6262 p_var_value => l_available_qty) ;
6263 INL_LOGGING_PVT.Log_Variable ( p_module_name => g_module_name,
6264 p_procedure_name => l_func_name,
6265 p_var_name => 'l_tolerable_quantity',
6266 p_var_value => l_tolerable_quantity) ;
6267 INL_LOGGING_PVT.Log_Variable ( p_module_name => g_module_name,
6268 p_procedure_name => l_func_name,
6269 p_var_name => 'l_unit_of_measure',
6270 p_var_value => l_unit_of_measure) ;
6271
6272 -- Standard End of Procedure/Function Logging
6273 INL_LOGGING_PVT.Log_EndProc ( p_module_name => g_module_name,
6274 p_procedure_name => l_func_name) ;
6275 RETURN NVL(l_available_qty,0);
6276 END Get_SrcAvailableQty;
6277
6278 -- API name : ProcessAction
6279 -- Type : Private
6280 -- Function : Run all required steps to Complete a given LCM Shipment.
6281 -- Pre-reqs : None
6282 -- Parameters :
6283 -- IN : p_api_version IN NUMBER Required
6284 -- p_init_msg_list IN VARCHAR2 Optional Default = FND_API.G_FALSE
6285 -- p_commit IN VARCHAR2 Optional Default = FND_API.G_FALSE
6286 -- p_ship_header_id IN NUMBER
6287 -- p_task_code IN VARCHAR2
6288 -- OUT x_return_status OUT NOCOPY VARCHAR2
6289 -- x_msg_count OUT NOCOPY NUMBER
6290 -- x_msg_data OUT NOCOPY VARCHAR2
6291 --
6292 -- Version : Current version 1.0
6293 --
6294 -- Notes :
6295 PROCEDURE ProcessAction(p_api_version IN NUMBER,
6296 p_init_msg_list IN VARCHAR2 := FND_API.G_FALSE,
6297 p_commit IN VARCHAR2 := FND_API.G_FALSE,
6298 p_ship_header_id IN NUMBER,
6299 p_task_code IN VARCHAR2,
6300 x_return_status OUT NOCOPY VARCHAR2,
6301 x_msg_count OUT NOCOPY NUMBER,
6302 x_msg_data OUT NOCOPY VARCHAR2)
6303 IS
6304 l_api_name CONSTANT VARCHAR2 (30) := 'ProcessAction';
6305 l_api_version CONSTANT NUMBER := 1.0;
6306
6307 l_return_status VARCHAR2 (1) ;
6308 l_msg_count NUMBER;
6309 l_msg_data VARCHAR2 (2000);
6310 l_debug_info VARCHAR2 (200);
6311 l_pending_matching_flag VARCHAR2 (1) ;
6312 l_ship_status VARCHAR2 (30);
6313 l_msg_count_validate NUMBER;
6314 l_organization_id NUMBER;
6315
6316 BEGIN
6317 -- Standard Beginning of Procedure/Function Logging
6318 INL_LOGGING_PVT.Log_BeginProc ( p_module_name => g_module_name,
6319 p_procedure_name => l_api_name) ;
6320 -- Standard Start of API savepoint
6321 SAVEPOINT Run_Submit_PVT;
6322 -- Initialize message list if p_init_msg_list is set to TRUE.
6323 IF FND_API.to_Boolean (p_init_msg_list) THEN
6324 FND_MSG_PUB.initialize;
6325 END IF;
6326 -- Check for call compatibility.
6327 IF NOT FND_API.Compatible_API_Call (l_api_version,
6328 p_api_version,
6329 l_api_name,
6330 G_PKG_NAME) THEN
6331 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6332 END IF;
6333 -- Initialize API return status to success
6334 x_return_status := FND_API.G_RET_STS_SUCCESS;
6335 -- Get the Pending Match Flag and Organization Id
6336 l_debug_info := 'Get the Pending Match Flag and Organization Id';
6337 INL_LOGGING_PVT.Log_Statement (
6338 p_module_name => g_module_name,
6339 p_procedure_name => l_api_name,
6340 p_debug_info => l_debug_info
6341 ) ;
6342
6343 SELECT pending_matching_flag,
6344 organization_id
6345 INTO l_pending_matching_flag,
6346 l_organization_id
6347 FROM inl_ship_headers
6348 WHERE ship_header_id = p_ship_header_id;
6349
6350 INL_LOGGING_PVT.Log_Variable (p_module_name => g_module_name,
6351 p_procedure_name => l_api_name,
6352 p_var_name => 'l_pending_matching_flag',
6353 p_var_value => l_pending_matching_flag) ;
6354 INL_LOGGING_PVT.Log_Variable (p_module_name => g_module_name,
6355 p_procedure_name => l_api_name,
6356 p_var_name => 'l_organization_id',
6357 p_var_value => l_organization_id) ;
6358
6359 -- Run Adjust Lines for Pending Shipments
6360 IF l_pending_matching_flag = 'Y' THEN
6361 l_debug_info := 'Run INL_SHIPMENT_PVT_AC2.Adjust_Lines';
6362 INL_LOGGING_PVT.Log_Statement (
6363 p_module_name => g_module_name,
6364 p_procedure_name => l_api_name,
6365 p_debug_info => l_debug_info
6366 ) ;
6367
6368 Adjust_Lines (p_api_version => 1.0,
6369 p_init_msg_list => FND_API.G_FALSE,
6370 p_commit => FND_API.G_FALSE,
6371 p_ship_header_id => p_ship_header_id,
6372 x_return_status => l_return_status,
6373 x_msg_count => l_msg_count,
6374 x_msg_data => l_msg_data) ;
6375
6376 -- If any errors happen abort the process.
6377 IF l_return_status = FND_API.G_RET_STS_ERROR THEN
6378 RAISE FND_API.G_EXC_ERROR;
6379 ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
6380 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6381 END IF;
6382
6383 -- Update Pending Matching Flag if needed
6384 l_debug_info := 'Update PendingMatchingFlag';
6385 INL_LOGGING_PVT.Log_Statement (
6386 p_module_name => g_module_name,
6387 p_procedure_name => l_api_name,
6388 p_debug_info => l_debug_info
6389 ) ;
6390
6391 UPDATE inl_ship_headers
6392 SET pending_matching_flag = 'N',
6393 last_updated_by = fnd_global.user_id,
6394 last_update_date = SYSDATE,
6395 last_update_login = fnd_global.login_id
6396 WHERE ship_header_id = p_ship_header_id;
6397 END IF;
6398
6399 -- Run Generate Taxes Only for NOT Pending Shipments
6400
6401
6402 IF p_task_code >= '30' AND NVL(l_pending_matching_flag, 'N') = 'N' THEN
6403 l_debug_info := 'Run INL_TAX_PVT.Generate_Taxes';
6404 INL_LOGGING_PVT.Log_Statement (
6405 p_module_name => g_module_name,
6406 p_procedure_name => l_api_name,
6407 p_debug_info => l_debug_info
6408 ) ;
6409
6410 INL_TAX_PVT.Generate_Taxes (p_api_version => 1.0,
6411 p_init_msg_list => FND_API.G_FALSE,
6412 p_commit => FND_API.G_FALSE,
6413 p_ship_header_id => p_ship_header_id,
6414 x_return_status => l_return_status,
6415 x_msg_count => l_msg_count,
6416 x_msg_data => l_msg_data) ;
6417
6418 -- If any errors happen abort the process.
6419 IF l_return_status = FND_API.G_RET_STS_ERROR THEN
6420 RAISE FND_API.G_EXC_ERROR;
6421 ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
6422 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6423 END IF;
6424 END IF;
6425
6426 -- Run Validation only for NOT Pending Shipments
6427 IF p_task_code >= '40' AND NVL (l_pending_matching_flag, 'N') = 'N' THEN
6428 l_debug_info := 'Run INL_SHIPMENT_PVT_AC2.Validate_Shipment';
6429 INL_LOGGING_PVT.Log_Statement (
6430 p_module_name => g_module_name,
6431 p_procedure_name => l_api_name,
6432 p_debug_info => l_debug_info
6433 ) ;
6434
6435 l_msg_count_validate := NVL (fnd_msg_pub.Count_Msg (), 0) ;
6436
6437 Validate_Shipment (p_api_version => 1.0,
6438 p_init_msg_list => FND_API.G_FALSE,
6439 p_commit => FND_API.G_FALSE,
6440 p_validation_level => FND_API.G_VALID_LEVEL_FULL,
6441 p_ship_header_id => p_ship_header_id,
6442 x_return_status => l_return_status,
6443 x_msg_count => l_msg_count,
6444 x_msg_data => l_msg_data) ;
6445
6446 -- If any errors happen abort the process.
6447 IF l_return_status = FND_API.G_RET_STS_ERROR THEN
6448 RAISE FND_API.G_EXC_ERROR;
6449 ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
6450 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6451 END IF;
6452 l_msg_count_validate := NVL (l_msg_count, 0) - l_msg_count_validate;
6453 END IF;
6454
6455 ----------------------------------------------------------------------
6456 -- Actions for both Pending Shipments and Not Pending Shipments
6457 ----------------------------------------------------------------------
6458
6459 -- Run Landed Cost Calculation
6460 IF p_task_code >= '50' AND NVL (l_msg_count_validate, 0) = 0 THEN
6461 l_debug_info := 'Run INL_LANDEDCOST_PVT.Run_Calculation';
6462 INL_LOGGING_PVT.Log_Statement (
6463 p_module_name => g_module_name,
6464 p_procedure_name => l_api_name,
6465 p_debug_info => l_debug_info
6466 ) ;
6467
6468
6469 INL_LANDEDCOST_PVT.Run_Calculation (p_api_version => 1.0,
6470 p_init_msg_list => FND_API.G_FALSE,
6471 p_commit => FND_API.G_FALSE,
6472 p_validation_level => FND_API.G_VALID_LEVEL_FULL,
6473 p_ship_header_id => p_ship_header_id,
6474 p_calc_scope_code => 0,
6475 x_return_status => l_return_status,
6476 x_msg_count => l_msg_count,
6477 x_msg_data => l_msg_data) ;
6478
6479 -- If any errors happen abort the process.
6480 IF l_return_status = FND_API.G_RET_STS_ERROR THEN
6481 RAISE FND_API.G_EXC_ERROR;
6482 ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
6483 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6484 END IF;
6485 END IF;
6486
6487 -- Submit Shipment and call final integrations
6488 IF p_task_code >= '60' AND NVL (l_msg_count_validate, 0) = 0 THEN
6489 l_debug_info := 'Run INL_SHIPMENT_PVT_AC2.Complete_Shipment';
6490 INL_LOGGING_PVT.Log_Statement (
6491 p_module_name => g_module_name,
6492 p_procedure_name => l_api_name,
6493 p_debug_info => l_debug_info
6494 ) ;
6495
6496 Complete_Shipment (p_api_version => 1.0,
6497 p_init_msg_list => FND_API.G_FALSE,
6498 p_commit => FND_API.G_FALSE,
6499 p_ship_header_id => p_ship_header_id,
6500 p_pending_matching_flag => l_pending_matching_flag,
6501 p_organization_id => l_organization_id,
6502 x_return_status => l_return_status,
6503 x_msg_count => l_msg_count,
6504 x_msg_data => l_msg_data) ;
6505
6506 -- If any errors happen abort the process.
6507 IF l_return_status = FND_API.G_RET_STS_ERROR THEN
6508 RAISE FND_API.G_EXC_ERROR;
6509 ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
6510 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6511 END IF;
6512 END IF;
6513
6514 -- If any errors happen abort the process.
6515 IF l_return_status = FND_API.G_RET_STS_ERROR THEN
6516 RAISE FND_API.G_EXC_ERROR;
6517 ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
6518 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6519 END IF;
6520
6521 -- Standard check of p_commit.
6522 IF FND_API.To_Boolean (p_commit) THEN
6523 COMMIT WORK;
6524 END IF;
6525
6526 -- Standard call to get message count and if count is 1, get message info.
6527 FND_MSG_PUB.Count_And_Get ( p_encoded => FND_API.g_false,
6528 p_count => x_msg_count,
6529 p_data => x_msg_data) ;
6530
6531 -- Standard End of Procedure/Function Logging
6532 INL_LOGGING_PVT.Log_EndProc ( p_module_name => g_module_name,
6533 p_procedure_name => l_api_name) ;
6534 EXCEPTION
6535 WHEN FND_API.G_EXC_ERROR THEN
6536 -- Standard Expected Error Logging
6537 INL_LOGGING_PVT.Log_ExpecError ( p_module_name => g_module_name,
6538 p_procedure_name => l_api_name) ;
6539 ROLLBACK TO Run_Submit_PVT;
6540 x_return_status := FND_API.G_RET_STS_ERROR;
6541 FND_MSG_PUB.Count_And_Get ( p_encoded => FND_API.g_false,
6542 p_count => x_msg_count,
6543 p_data => x_msg_data) ;
6544 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
6545 -- Standard Unexpected Error Logging
6546 INL_LOGGING_PVT.Log_UnexpecError ( p_module_name => g_module_name,
6547 p_procedure_name => l_api_name) ;
6548 ROLLBACK TO Run_Submit_PVT;
6549 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6550 FND_MSG_PUB.Count_And_Get ( p_encoded => FND_API.g_false,
6551 p_count => x_msg_count,
6552 p_data => x_msg_data) ;
6553 WHEN OTHERS THEN
6554 -- Standard Unexpected Error Logging
6555 INL_LOGGING_PVT.Log_UnexpecError ( p_module_name => g_module_name,
6556 p_procedure_name => l_api_name) ;
6557 ROLLBACK TO Run_Submit_PVT;
6558 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
6559 IF FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
6560 FND_MSG_PUB.Add_Exc_Msg ( p_pkg_name => g_pkg_name,
6561 p_procedure_name => l_api_name) ;
6562 END IF;
6563 FND_MSG_PUB.Count_And_Get ( p_encoded => FND_API.g_false,
6564 p_count => x_msg_count,
6565 p_data => x_msg_data) ;
6566 END ProcessAction;
6567
6568 -- Utility name : Complete_PendingShipments
6569 -- Type : Private
6570 -- Function : This utility is called by an LCM Concurrent to process
6571 -- either a specific Pending Matching/Correction Shipment
6572 -- or ALL Pending Shipments.
6573 -- Pre-reqs : None
6574 -- Parameters :
6575 -- OUT errbuf OUT VARCHAR2
6576 -- retcode OUT VARCHAR2
6577 --
6578 -- IN p_organization_id IN NUMBER
6579 -- p_ship_header_id IN NUMBER
6580 --
6581 --
6582 -- Version : Current version 1.0
6583 --
6584 -- Notes :
6585 PROCEDURE Complete_PendingShipment (errbuf OUT NOCOPY VARCHAR2,
6586 retcode OUT NOCOPY VARCHAR2,
6587 p_organization_id IN NUMBER,
6588 p_ship_header_id IN NUMBER)
6589 IS
6590
6591 l_proc_name CONSTANT VARCHAR2 (30) := 'Complete_PendingShipment';
6592 l_return_status VARCHAR2 (1) := FND_API.G_RET_STS_SUCCESS;
6593 l_msg_count NUMBER;
6594 l_msg_data VARCHAR2 (2000) ;
6595 l_debug_info VARCHAR2 (200) ;
6596
6597 -- Cursor to get all Pending Shipments
6598 CURSOR c_pending_shipments IS
6599 SELECT ship_header_id
6600 FROM inl_ship_headers
6601 WHERE ship_status_code = 'COMPLETED'
6602 AND pending_matching_flag = 'Y'
6603 AND (p_organization_id IS NULL
6604 OR organization_id = p_organization_id);
6605
6606 l_pending_shipments_rec c_pending_shipments%ROWTYPE;
6607
6608 BEGIN
6609 -- Init conc. parameters
6610 errbuf := NULL;
6611 retcode := 0;
6612
6613 -- Standard Beginning of Procedure/Function Logging
6614 INL_LOGGING_PVT.Log_BeginProc ( p_module_name => g_module_name,
6615 p_procedure_name => l_proc_name) ;
6616
6617 -- Submit only the given Shipment
6618 IF p_ship_header_id IS NOT NULL THEN
6619 l_debug_info := 'Before runnig Submit process for the only Shipment Id: ' || p_ship_header_id;
6620 INL_LOGGING_PVT.Log_Statement (
6621 p_module_name => g_module_name,
6622 p_procedure_name => l_proc_name,
6623 p_debug_info => l_debug_info
6624 ) ;
6625
6626
6627 ProcessAction (p_api_version => 1.0,
6628 p_init_msg_list => FND_API.G_FALSE,
6629 p_commit => FND_API.G_FALSE,
6630 p_ship_header_id => p_ship_header_id,
6631 p_task_code => '60', -- Process until Submit task
6632 x_return_status => l_return_status,
6633 x_msg_count => l_msg_count,
6634 x_msg_data => l_msg_data) ;
6635
6636 -- Setting error bufer and return code
6637 IF l_msg_count = 1 THEN
6638 FND_FILE.PUT_LINE(FND_FILE.LOG, l_msg_data);
6639 retcode := 1;
6640 ELSIF l_msg_count > 1 THEN
6641 FND_FILE.PUT_LINE(FND_FILE.LOG, l_msg_count|| ' warnings found.' );
6642 FOR i IN 1 ..l_msg_count
6643 LOOP
6644 FND_FILE.PUT_LINE(FND_FILE.LOG,FND_MSG_PUB.get (i, FND_API.g_false) );
6645 END LOOP;
6646 retcode := 1;
6647 END IF;
6648
6649 -- If any errors happen abort the process.
6650 IF l_return_status = FND_API.G_RET_STS_ERROR THEN
6651 RAISE FND_API.G_EXC_ERROR;
6652 ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
6653 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6654 END IF;
6655 -- Submit ALL Pending Shipments
6656 ELSE
6657 OPEN c_pending_shipments;
6658 LOOP
6659 FETCH c_pending_shipments INTO l_pending_shipments_rec;
6660 EXIT
6661 WHEN c_pending_shipments%NOTFOUND;
6662 l_debug_info := 'Before runnig Submit process for the Shipment Id: ' || l_pending_shipments_rec.ship_header_id;
6663 INL_LOGGING_PVT.Log_Statement (
6664 p_module_name => g_module_name,
6665 p_procedure_name => l_proc_name,
6666 p_debug_info => l_debug_info
6667 ) ;
6668
6669 ProcessAction (p_api_version => 1.0,
6670 p_init_msg_list => FND_API.G_FALSE,
6671 p_commit => FND_API.G_FALSE,
6672 p_ship_header_id => l_pending_shipments_rec.ship_header_id,
6673 p_task_code => '60', -- Process until Submit task
6674 x_return_status => l_return_status,
6675 x_msg_count => l_msg_count,
6676 x_msg_data => l_msg_data) ;
6677
6678 -- Setting error bufer and return code
6679 IF l_msg_count = 1 THEN
6680 errbuf := l_msg_data;
6681 retcode := 1;
6682 ELSIF l_msg_count > 1 THEN
6683 errbuf := errbuf||' '||l_msg_count||' warnings found.'||FND_GLOBAL.local_chr (10) ;
6684 FOR i IN 1 ..l_msg_count
6685 LOOP
6686 errbuf := errbuf||FND_MSG_PUB.get (i, FND_API.g_false) ||FND_GLOBAL.local_chr (10) ;
6687 END LOOP;
6688 retcode := 1;
6689 END IF;
6690
6691 -- If any errors happen abort the process.
6692 IF l_return_status = FND_API.G_RET_STS_ERROR THEN
6693 RAISE FND_API.G_EXC_ERROR;
6694 ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
6695 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6696 END IF;
6697 END LOOP;
6698 CLOSE c_pending_shipments;
6699 END IF;
6700
6701 -- Standard End of Procedure/Function Logging
6702 INL_LOGGING_PVT.Log_EndProc ( p_module_name => g_module_name,
6703 p_procedure_name => l_proc_name) ;
6704 EXCEPTION
6705 WHEN FND_API.G_EXC_ERROR THEN
6706 -- Standard Expected Error Logging
6707 INL_logging_pvt.Log_ExpecError ( p_module_name => g_module_name,
6708 p_procedure_name => l_proc_name) ;
6709 retcode := 1;
6710 errbuf := errbuf ||' G_EXC_ERROR '||SQLERRM;
6711 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
6712 -- Standard Unexpected Error Logging
6713 INL_logging_pvt.Log_UnexpecError ( p_module_name => g_module_name,
6714 p_procedure_name => l_proc_name) ;
6715 retcode := 2;
6716 errbuf := errbuf ||' G_EXC_UNEXPECTED_ERROR '||SQLERRM;
6717 WHEN OTHERS THEN
6718 -- Standard Unexpected Error Logging
6719 INL_logging_pvt.Log_UnexpecError ( p_module_name => g_module_name,
6720 p_procedure_name => l_proc_name) ;
6721 retcode := 2;
6722 errbuf := errbuf ||' OTHERS '||SQLERRM;
6723 END Complete_PendingShipment;
6724
6725 -- Utility name : Update_PendingMatchingFlag
6726 -- Type : Private
6727 -- Function : This is the Table Handler to be used for updating
6728 -- the Pending Matching Flag for given Shipment Header.
6729 -- Pre-reqs : None
6730 -- Parameters :
6731 -- IN : p_ship_header_id IN NUMBER
6732 -- p_pending_matching_flag IN VARCHAR
6733 -- OUT x_return_status OUT NOCOPY VARCHAR2
6734 --
6735 -- Version : Current version 1.0
6736 --
6737 -- Notes :
6738 PROCEDURE Update_PendingMatchingFlag
6739 (
6740 p_ship_header_id IN NUMBER,
6741 p_pending_matching_flag IN VARCHAR,
6742 x_return_status OUT NOCOPY VARCHAR2)
6743 IS
6744 l_proc_name CONSTANT VARCHAR2 (100) := 'Update_PendingMatchingFlag';
6745 BEGIN
6746 INL_LOGGING_PVT.Log_BeginProc ( p_module_name => g_module_name, p_procedure_name => l_proc_name) ;
6747 -- Initialize API return status to success
6748 x_return_status := FND_API.G_RET_STS_SUCCESS;
6749 UPDATE inl_ship_headers
6750 SET pending_matching_flag = p_pending_matching_flag,
6751 created_by = fnd_global.user_id ,
6752 creation_date = SYSDATE ,
6753 last_updated_by = fnd_global.user_id ,
6754 last_update_date = SYSDATE ,
6755 last_update_login = fnd_global.login_id
6756 WHERE ship_header_id = p_ship_header_id;
6757
6758 INL_LOGGING_PVT.Log_EndProc ( p_module_name => g_module_name, p_procedure_name => l_proc_name) ;
6759 EXCEPTION
6760 WHEN FND_API.G_EXC_ERROR THEN
6761 -- Standard Expected Error Logging
6762 INL_LOGGING_PVT.Log_ExpecError ( p_module_name => g_module_name, p_procedure_name => l_proc_name) ;
6763 x_return_status := FND_API.G_RET_STS_ERROR;
6764 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
6765 -- Standard Unexpected Error Logging
6766 INL_LOGGING_PVT.Log_UnexpecError ( p_module_name => g_module_name, p_procedure_name => l_proc_name) ;
6767 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6768 WHEN OTHERS THEN
6769 -- Standard Unexpected Error Logging
6770 INL_LOGGING_PVT.Log_UnexpecError ( p_module_name => g_module_name, p_procedure_name => l_proc_name) ;
6771 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6772 IF FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
6773 FND_MSG_PUB.Add_Exc_Msg ( p_pkg_name => g_pkg_name, p_procedure_name => l_proc_name) ;
6774 END IF;
6775 END Update_PendingMatchingFlag;
6776 -- API name : Delete_ChargeAssoc
6777 -- Type : Private
6778 -- Function : Check shipments affected by a charge deletion
6779 -- or an association of charge deletion
6780 --
6781 -- Pre-reqs : None
6782 -- Parameters :
6783 -- IN :
6784 -- p_api_version IN NUMBER Required
6785 -- p_init_msg_list IN VARCHAR2 Optional Default = FND_API.G_FALSE
6786 -- p_commit IN VARCHAR2 Optional Default = FND_API.G_FALSE
6787 -- p_ship_header_id IN NUMBER
6788 -- p_charge_line_id IN NUMBER
6789 -- OUT :
6790 -- x_return_status OUT NOCOPY VARCHAR2
6791 -- x_msg_count OUT NOCOPY NUMBER
6792 -- x_msg_data OUT NOCOPY VARCHAR2
6793 --
6794 --
6795 -- Version : Current version 1.0
6796 --
6797 -- Notes :
6798 PROCEDURE Delete_ChargeAssoc
6799 (
6800 p_api_version IN NUMBER,
6801 p_init_msg_list IN VARCHAR2 := FND_API.G_FALSE,
6802 p_commit IN VARCHAR2 := FND_API.G_FALSE,
6803 p_ship_header_id IN NUMBER,
6804 p_charge_line_id IN NUMBER,
6805 x_return_status OUT NOCOPY VARCHAR2,
6806 x_msg_count OUT NOCOPY NUMBER,
6807 x_msg_data OUT NOCOPY VARCHAR2)
6808 IS
6809 l_api_name CONSTANT VARCHAR2 (30) := 'Delete_ChargeAssoc';
6810 l_api_version CONSTANT NUMBER := 1.0;
6811 l_debug_info VARCHAR2 (200) ;
6812 l_return_status VARCHAR2 (1) ;
6813 l_msg_count NUMBER;
6814 l_msg_data VARCHAR2 (2000) ;
6815 CURSOR c_affected_ship
6816 IS
6817 SELECT a.ship_header_id ,
6818 sh.ship_status_code ship_status,
6819 sh.pending_matching_flag
6820 FROM inl_associations a,
6821 inl_ship_headers sh
6822 WHERE sh.ship_header_id = a.ship_header_id
6823 AND a.from_parent_table_name = 'INL_CHARGE_LINES'
6824 AND a.from_parent_table_id = p_charge_line_id
6825 AND a.ship_header_id <> p_ship_header_id;
6826
6827 r_affected_ship c_affected_ship%ROWTYPE;
6828 BEGIN
6829 -- Standard Beginning of Procedure/Function Logging
6830 INL_LOGGING_PVT.Log_BeginProc ( p_module_name => g_module_name, p_procedure_name => l_api_name) ;
6831 -- Standard Start of API savepoint
6832 SAVEPOINT Delete_ChargeAssoc_PVT;
6833 -- Initialize message list if p_init_msg_list is set to TRUE.
6834 IF FND_API.to_Boolean (p_init_msg_list) THEN
6835 FND_MSG_PUB.initialize;
6836 END IF;
6837 -- Check for call compatibility.
6838 IF NOT FND_API.Compatible_API_Call (p_current_version_number => l_api_version, p_caller_version_number => p_api_version, p_api_name => l_api_name, p_pkg_name => g_pkg_name) THEN
6839 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6840 END IF;
6841 -- Initialize API return status to success
6842 x_return_status := FND_API.G_RET_STS_SUCCESS;
6843 -- API Body
6844 BEGIN
6845 OPEN c_affected_ship;
6846 LOOP
6847 FETCH c_affected_ship INTO r_affected_ship;
6848 EXIT
6849 WHEN c_affected_ship%NOTFOUND;
6850 INL_LOGGING_PVT.Log_Variable (p_module_name => g_module_name, p_procedure_name => l_api_name, p_var_name => 'ship_status', p_var_value => r_affected_ship.ship_status) ;
6851 IF (r_affected_ship.ship_status = 'VALIDATED') THEN
6852 Set_ToRevalidate (1.0, FND_API.G_FALSE, FND_API.G_FALSE, r_affected_ship.ship_header_id, l_msg_count, l_msg_data, l_return_status) ;
6853 -- If any errors happen abort the process.
6854 IF l_return_status = FND_API.G_RET_STS_ERROR THEN
6855 RAISE FND_API.G_EXC_ERROR;
6856 ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
6857 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6858 END IF;
6859 ELSIF (r_affected_ship.ship_status = 'COMPLETED') THEN
6860 Update_PendingMatchingFlag (r_affected_ship.ship_header_id, 'Y', l_return_status) ;
6861 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
6862 FND_MESSAGE.SET_NAME ('INL', 'INL_UNEXPECTED_ERR') ;
6863 FND_MSG_PUB.ADD;
6864 IF l_return_status = FND_API.G_RET_STS_ERROR THEN
6865 RAISE FND_API.G_EXC_ERROR;
6866 ELSE
6867 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6868 END IF;
6869 END IF;
6870 END IF;
6871 END LOOP;
6872 CLOSE c_affected_ship;
6873 END;
6874 -- Standard check of p_commit.
6875 IF FND_API.To_Boolean (p_commit) THEN
6876 COMMIT WORK;
6877 END IF;
6878 -- Standard call to get message count and if count is 1, get message info.
6879 FND_MSG_PUB.Count_And_Get ( p_encoded => FND_API.g_false, p_count => x_msg_count, p_data => x_msg_data) ;
6880 -- Standard End of Procedure/Function Logging
6881 INL_LOGGING_PVT.Log_EndProc ( p_module_name => g_module_name, p_procedure_name => l_api_name) ;
6882 EXCEPTION
6883 WHEN FND_API.G_EXC_ERROR THEN
6884 -- Standard Expected Error Logging
6885 INL_LOGGING_PVT.Log_ExpecError ( p_module_name => g_module_name, p_procedure_name => l_api_name) ;
6886 ROLLBACK TO Delete_ChargeAssoc_PVT;
6887 x_return_status := FND_API.G_RET_STS_ERROR;
6888 FND_MSG_PUB.Count_And_Get ( p_encoded => FND_API.g_false, p_count => x_msg_count, p_data => x_msg_data) ;
6889 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
6890 -- Standard Unexpected Error Logging
6891 INL_LOGGING_PVT.Log_UnexpecError ( p_module_name => g_module_name, p_procedure_name => l_api_name) ;
6892 ROLLBACK TO Delete_ChargeAssoc_PVT;
6893 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6894 FND_MSG_PUB.Count_And_Get ( p_encoded => FND_API.g_false, p_count => x_msg_count, p_data => x_msg_data) ;
6895 WHEN OTHERS THEN
6896 -- Standard Unexpected Error Logging
6897 INL_LOGGING_PVT.Log_UnexpecError ( p_module_name => g_module_name, p_procedure_name => l_api_name) ;
6898 ROLLBACK TO Delete_ChargeAssoc_PVT;
6899 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
6900 IF FND_MSG_PUB.Check_Msg_Level (p_message_level => FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
6901 FND_MSG_PUB.Add_Exc_Msg ( p_pkg_name => g_pkg_name, p_procedure_name => l_api_name) ;
6902 END IF;
6903 FND_MSG_PUB.Count_And_Get ( p_encoded => FND_API.g_false, p_count => x_msg_count, p_data => x_msg_data) ;
6904 END Delete_ChargeAssoc;
6905
6906 END INL_SHIPMENT_PVT;