[Home] [Help]
PACKAGE BODY: APPS.INL_MATCH_GRP
Source
1 PACKAGE BODY INL_MATCH_GRP AS
2 /* $Header: INLGMATB.pls 120.31.12020000.3 2012/11/21 19:07:14 aicosta ship $ */
3
4 -- API name : Create_MatchIntLines
5 -- Type : Private
6 -- Function : Create Matching Lines
7 -- Pre-reqs : None
8 -- Parameters :
9 -- IN : p_api_version IN NUMBER
10 -- p_init_msg_list IN VARCHAR2 := FND_API.G_FALSE
11 -- p_commit IN VARCHAR2 := FND_API.G_FALSE
12 -- p_matches_int_tbl IN OUT NOCOPY inl_matches_type_tbl
13 --
14 -- OUT : x_return_status OUT NOCOPY VARCHAR2
15 -- x_msg_count OUT NOCOPY NUMBER
16 -- x_msg_data OUT NOCOPY VARCHAR2
17 --
18 -- Version : Current version 1.0
19 --
20 -- Notes :
21 PROCEDURE Create_MatchIntLines(
22 p_api_version IN NUMBER,
23 p_init_msg_list IN VARCHAR2 := FND_API.G_FALSE,
24 p_commit IN VARCHAR2 := FND_API.G_FALSE,
25 p_matches_int_tbl IN OUT NOCOPY inl_matches_int_type_tbl,
26 x_return_status OUT NOCOPY VARCHAR2,
27 x_msg_count OUT NOCOPY NUMBER,
28 x_msg_data OUT NOCOPY VARCHAR2
29 ) IS
30
31 l_api_name CONSTANT VARCHAR2(30) := 'Create_MatchIntLines';
32 l_api_version CONSTANT NUMBER := 1.0;
33
34 l_debug_info VARCHAR2(2000);
35 l_return_status VARCHAR2(1);
36 l_match_id NUMBER;
37 l_aux NUMBER;
38 l_group_id NUMBER;
39 l_parent_match_id NUMBER;
40 l_current_reversal_flag VARCHAR2(1); --Bug#14604983
41
42 BEGIN
43 -- Standard Beginning of Procedure/Function Logging
44 INL_LOGGING_PVT.Log_BeginProc (
45 p_module_name => g_module_name,
46 p_procedure_name => l_api_name
47 );
48
49 -- Standard Start of API savepoint
50 SAVEPOINT Create_MatchIntLines_GRP;
51
52 -- Initialize message list if p_init_msg_list is set to TRUE.
53 IF FND_API.to_Boolean( p_init_msg_list ) THEN
54 FND_MSG_PUB.initialize;
55 END IF;
56
57 -- Check for call compatibility.
58 IF NOT FND_API.Compatible_API_Call (
59 p_current_version_number => l_api_version,
60 p_caller_version_number => p_api_version,
61 p_api_name => l_api_name,
62 p_pkg_name => g_pkg_name)
63 THEN
64 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
65 END IF;
66
67 -- Initialize API return status to success
68 x_return_status := FND_API.G_RET_STS_SUCCESS;
69
70 IF NVL(p_matches_int_tbl.LAST,0) > 0 THEN
71 FOR i IN NVL(p_matches_int_tbl.FIRST,0)..NVL(p_matches_int_tbl.LAST,0) LOOP
72 SELECT inl_matches_int_s.NEXTVAL
73 INTO p_matches_int_tbl(i).match_int_id
74 FROM dual;
75 IF l_group_id IS NULL
76 OR NVL(p_matches_int_tbl(i).reversal_flag,'N') <> NVL(l_current_reversal_flag,'N') --Bug#14604983
77 THEN
78 l_group_id := p_matches_int_tbl(i).match_int_id;
79 l_current_reversal_flag := NVL(p_matches_int_tbl(i).reversal_flag,'N'); --Bug#14604983
80 END IF;
81
82 l_debug_info := 'Next Match_id';
83 INL_LOGGING_PVT.Log_Variable (
84 p_module_name => g_module_name,
85 p_procedure_name => l_api_name,
86 p_var_name => l_debug_info,
87 p_var_value => p_matches_int_tbl(i).match_id
88 );
89 -- Insert Match Line
90
91 INSERT INTO inl_matches_int (
92 match_int_id , /* 01 */
93 adj_group_date , /* 01A*/ -- OPM Integration
94 group_id , /* 02 */
95 processing_status_code , /* 03 */
96 transaction_type , /* 04 */
97 match_type_code , /* 05 */
98 from_parent_table_name , /* 07 */
99 from_parent_table_id , /* 08 */
100 to_parent_table_name , /* 08 */
101 to_parent_table_id , /* 09 */
102 matched_qty , /* 11 */
103 matched_uom_code , /* 12 */
104 matched_amt , /* 13 */
105 matched_curr_code , /* 14 */
106 matched_curr_conversion_type , /* 15 */
107 matched_curr_conversion_date , /* 16 */
108 matched_curr_conversion_rate , /* 17 */
109 replace_estim_qty_flag , /* 18 */
110 charge_line_type_id , /* 19 */
111 party_id , /* 20 */
112 party_number , /* 21 */
113 party_site_id , /* 22 */
114 party_site_number , /* 23 */
115 tax_code , /* 24 */
116 nrec_tax_amt , /* 25 */
117 tax_amt_included_flag , /* 26 */
118 match_amounts_flag , /* 28 */
119 created_by , /* 29 */
120 creation_date , /* 30 */
121 last_updated_by , /* 31 */
122 last_update_date , /* 32 */
123 last_update_login , /* 33 */
124 request_id , /* 34 */
125 program_id , /* 35 */
126 program_application_id , /* 36 */
127 program_update_date /* 37 */
128 )
129 VALUES (
130 p_matches_int_tbl(i).match_int_id , /* 01 */
131 p_matches_int_tbl(i).adj_group_date , /* 01A*/ -- OPM Integration
132 l_group_id , /* 02 */
133 'PENDING' , /* 03 */
134 'CREATE' , /* 04 */
135 p_matches_int_tbl(i).match_type_code , /* 05 */
136 p_matches_int_tbl(i).from_parent_table_name , /* 07 */
137 p_matches_int_tbl(i).from_parent_table_id , /* 08 */
138 p_matches_int_tbl(i).to_parent_table_name , /* 08 */
139 p_matches_int_tbl(i).to_parent_table_id , /* 09 */
140 p_matches_int_tbl(i).matched_qty , /* 11 */
141 p_matches_int_tbl(i).matched_uom_code , /* 12 */
142 p_matches_int_tbl(i).matched_amt , /* 13 */
143 p_matches_int_tbl(i).matched_curr_code , /* 14 */
144 p_matches_int_tbl(i).matched_curr_conversion_type , /* 15 */
145 p_matches_int_tbl(i).matched_curr_conversion_date , /* 16 */
146 p_matches_int_tbl(i).matched_curr_conversion_rate , /* 17 */
147 p_matches_int_tbl(i).replace_estim_qty_flag , /* 18 */
148 p_matches_int_tbl(i).charge_line_type_id , /* 19 */
149 p_matches_int_tbl(i).party_id , /* 20 */
150 NULL , /* 21 */
151 p_matches_int_tbl(i).party_site_id , /* 22 */
152 NULL , /* 23 */
153 p_matches_int_tbl(i).tax_code , /* 24 */
154 p_matches_int_tbl(i).nrec_tax_amt , /* 25 */
155 p_matches_int_tbl(i).tax_amt_included_flag , /* 26 */
156 p_matches_int_tbl(i).match_amounts_flag , /* 28 */
157 fnd_global.user_id , /* 29 */
158 SYSDATE , /* 30 */
159 fnd_global.user_id , /* 31 */
160 SYSDATE , /* 32 */
161 fnd_global.login_id , /* 33 */
162 fnd_global.conc_request_id , /* 34 */
163 fnd_global.conc_program_id , /* 35 */
164 fnd_global.prog_appl_id , /* 36 */
165 SYSDATE /* 37 */
166 );
167 END LOOP;
168 END IF;
169
170 -- If any errors happen abort API.
171 IF l_return_status = FND_API.G_RET_STS_ERROR THEN
172 RAISE FND_API.G_EXC_ERROR;
173 ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
174 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
175 END IF;
176
177 -- Standard check of p_commit.
178 IF FND_API.To_Boolean( p_commit ) THEN
179 COMMIT WORK;
180 END IF;
181
182 -- Standard call to get message count and if count is 1, get message info.
183 FND_MSG_PUB.Count_And_Get(
184 p_encoded => FND_API.g_false,
185 p_count => x_msg_count,
186 p_data => x_msg_data
187 );
188
189 -- Standard End of Procedure/Function Logging
190 INL_logging_pvt.Log_EndProc (
191 p_module_name => g_module_name,
192 p_procedure_name => l_api_name
193 );
194 EXCEPTION
195 WHEN FND_API.G_EXC_ERROR THEN
196 -- Standard Expected Error Logging
197 INL_LOGGING_PVT.Log_ExpecError (
198 p_module_name => g_module_name,
199 p_procedure_name => l_api_name
200 );
201 ROLLBACK TO Create_MatchIntLines_GRP;
202 x_return_status := FND_API.G_RET_STS_ERROR;
203 FND_MSG_PUB.Count_And_Get(
204 p_encoded => FND_API.g_false,
205 p_count => x_msg_count,
206 p_data => x_msg_data
207 );
208 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
209 -- Standard Unexpected Error Logging
210 INL_LOGGING_PVT.Log_UnexpecError (
211 p_module_name => g_module_name,
212 p_procedure_name => l_api_name
213 );
214 ROLLBACK TO Create_MatchIntLines_GRP;
215 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
216 FND_MSG_PUB.Count_And_Get(
217 p_encoded => FND_API.g_false,
218 p_count => x_msg_count,
219 p_data => x_msg_data
220 );
221 WHEN OTHERS THEN
222 -- Standard Unexpected Error Logging
223 INL_LOGGING_PVT.Log_UnexpecError (
224 p_module_name => g_module_name,
225 p_procedure_name => l_api_name
226 );
227 ROLLBACK TO Create_MatchIntLines_GRP;
228 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
229 IF FND_MSG_PUB.Check_Msg_Level(p_message_level=>FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)THEN
230 FND_MSG_PUB.Add_Exc_Msg(
231 p_pkg_name => g_pkg_name,
232 p_procedure_name => l_api_name
233 );
234 END IF;
235 FND_MSG_PUB.Count_And_Get(
236 p_encoded => FND_API.g_false,
237 p_count => x_msg_count,
238 p_data => x_msg_data
239 );
240 END Create_MatchIntLines;
241
242
243 /*=======================================
244 |
245 | Matches From Payables
246 |
247 \=======================================*/
248
249 -- Api name : Create_MatchesFromAP
250 -- Type : Group
251 -- Function : Create matches in LCM for actuals captured from a given AP Invoice.
252 -- Pre-reqs : None
253 -- Parameters :
254 -- IN : p_api_version IN NUMBER
255 -- p_init_msg_list IN VARCHAR2 := FND_API.G_FALSE
256 -- p_commit IN NUMBER := FND_API.G_FALSE
257 -- p_invoice_id IN NUMBER
258 --
259 -- OUT : x_return_status OUT NOCOPY VARCHAR2
260 -- x_msg_count OUT NOCOPY NUMBER
261 -- x_msg_data OUT NOCOPY VARCHAR2
262 --
263 -- Version : Current version 1.0
264 --
265 PROCEDURE Create_MatchesFromAP(p_api_version IN NUMBER,
266 p_init_msg_list IN VARCHAR2 := FND_API.G_FALSE,
267 p_commit IN VARCHAR2 := FND_API.G_FALSE,
268 p_invoice_id IN NUMBER,
269 p_match_status_flag IN VARCHAR2 := 'S', --Bug#14604983
270 x_return_status OUT NOCOPY VARCHAR2,
271 x_msg_count OUT NOCOPY NUMBER,
272 x_msg_data OUT NOCOPY VARCHAR2)
273 IS
274
275 l_api_name CONSTANT VARCHAR2(30) := 'Create_MatchesFromAP';
276 l_api_version CONSTANT NUMBER := 1.0;
277
278 l_return_status VARCHAR2(1);
279 l_msg_count NUMBER;
280 l_msg_data VARCHAR2(2000);
281 l_debug_info VARCHAR2(200);
282 l_distr_amount NUMBER;
283 l_quantity_invoiced NUMBER;
284 l_line_amount NUMBER;
285 l_par_cost_factor_id NUMBER;
286 l_par_line_type_lookup_code VARCHAR2(25);
287
288 -- This cursor if for retrieving Invoice information at Invoice
289 -- Distribution level to be sent to LCM.
290
291 -- It retrives AP Distribution lines that would affect "ITEM", "CHARGE" and "TAX" lines in LCM,
292 -- including their corrections.
293
294 -- The invoice line types we are handling for LCM integration are the
295 -- following: 'ITEM', 'MISCELLANEOUS', 'FREIGHT', 'TAX'.
296
297 -- Although there are other invoice line types such as 'RETAINAGE RELEASE',
298 -- 'AWT','RETROTAX','PREPAY', the invoice line types above are the ones
299 -- that appear in the Invoices form, when we are creating invoices.
300
301 CURSOR c_distr (p_sysdate date) IS
302 SELECT decode(NVL(l.corrected_inv_id, 0), 0, decode(l.line_type_lookup_code,'ITEM','ITEM', 'TAX', 'TAX', 'CHARGE'), 'CORRECTION') line_type,
303 decode(NVL(l.corrected_inv_id, 0), 0, NULL, decode(l.line_type_lookup_code,'ITEM','ITEM', 'TAX', 'TAX', 'CHARGE')) correction_type,
304 d.amount distr_amount,
305 d.corrected_invoice_dist_id corrected_invoice_dist_id,
306 d.invoice_distribution_id invoice_distribution_id,
307 d.invoice_id invoice_id,
308 d.line_type_lookup_code line_type_lookup_code,
309 d.parent_reversal_id parent_reversal_id,
310 d.dist_match_type dist_match_type,
311 d.charge_applicable_to_dist_id,
312 NVL(l.rcv_transaction_id,d.rcv_transaction_id) rcv_transaction_id, --BUG#8485279
313 -- l.rcv_transaction_id rcv_transaction_id,
314 muom.uom_code uom_code,
315 i.invoice_currency_code curr_code,
316 i.exchange_rate curr_rate,
317 i.exchange_rate_type curr_type,
318 i.exchange_date curr_date,
319 i.party_id party_id,
320 i.party_site_id party_site_id,
321 decode(l.line_type_lookup_code, 'TAX', l.quantity_invoiced, d.quantity_invoiced) quantity_invoiced,
322 l.cost_factor_id cost_factor_id,
323 l.tax tax_code,
324 decode(l.line_type_lookup_code, 'TAX', decode(d.tax_recoverable_flag,'Y',0,d.amount), NULL) nrec_tax_amt,
325 decode(l.line_type_lookup_code, 'TAX', 'N', NULL) tax_amt_included_flag,
326 d.accounting_date accounting_date, -- LCM-OPM Integration Send to OPM as transaction date
327 NVL(d.reversal_flag,'N') reversal_flag, --Bug#14604983
328 count(*) over () count_recs --Bug#14604983
329 FROM rcv_transactions rt,
330 ap_invoice_distributions d,
331 ap_invoices i,
332 ap_invoice_lines l,
333 mtl_units_of_measure muom
334 WHERE l.line_type_lookup_code IN ('ITEM', 'MISCELLANEOUS', 'FREIGHT', 'TAX')
335 AND d.match_status_flag = p_match_status_flag --Bug#14604983
336 AND rt.lcm_shipment_line_id IS NOT NULL
337 AND muom.unit_of_measure (+) = d.matched_uom_lookup_code
338 AND d.invoice_id = l.invoice_id
339 AND d.invoice_line_number = l.line_number
340 AND rt.transaction_id = NVL(l.rcv_transaction_id,d.rcv_transaction_id) --BUG#8485279
341 AND l.invoice_id = i.invoice_id
342 AND d.invoice_id = p_invoice_id
343 ORDER BY NVL(d.reversal_flag,'N'), invoice_distribution_id; --Bug#14604983
344
345 c_distr_rec c_distr%ROWTYPE;
346 l_matches_int_tbl inl_matches_int_type_tbl;
347 i NUMBER;
348 l_invoices_with_charge_tbl inl_int_tbl;
349 l_count_invoices_with_charge NUMBER:=1;
350 l_sysdate date := trunc(sysdate);
351 l_count_to_match_amt NUMBER;
352 BEGIN
353
354 -- Standard Beginning of Procedure/Function Logging
355 INL_LOGGING_PVT.Log_BeginProc (
356 p_module_name => g_module_name,
357 p_procedure_name => l_api_name
358 );
359
360 l_debug_info := 'Begining Create_MatchesFromAP';
361 INL_LOGGING_PVT.Log_Statement (
362 p_module_name => g_module_name,
363 p_procedure_name => l_api_name,
364 p_debug_info => l_debug_info
365 );
366
367 -- Standard Start of API savepoint
368 SAVEPOINT Create_MatchesFromAP_GRP;
369
370 -- Initialize message list if p_init_msg_list is set to TRUE.
371 IF FND_API.to_Boolean( p_init_msg_list ) THEN
372 FND_MSG_PUB.initialize;
373 END IF;
374
375 -- Check for call compatibility.
376 IF NOT FND_API.Compatible_API_Call (
377 p_current_version_number => l_api_version,
378 p_caller_version_number => p_api_version,
379 p_api_name => l_api_name,
380 p_pkg_name => g_pkg_name)
381 THEN
382 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
383 END IF;
384
385 -- Initialize API return status to success
386 x_return_status := FND_API.G_RET_STS_SUCCESS;
387
388 i := 0;
389 -- Getting AP Distribution Lines
390 l_debug_info := 'Getting AP Distribution Lines';
391 INL_LOGGING_PVT.Log_Statement (
392 p_module_name => g_module_name,
393 p_procedure_name => l_api_name,
394 p_debug_info => l_debug_info
395 );
396 FOR c_distr_rec IN c_distr(l_sysdate) LOOP
397 i := i + 1;
398
399 l_debug_info := 'c_distr_rec.line_type_lookup_code: ' || c_distr_rec.line_type_lookup_code||' : '||c_distr_rec.count_recs; --Bug#14604983
400 INL_LOGGING_PVT.Log_Statement (
401 p_module_name => g_module_name,
402 p_procedure_name => l_api_name,
403 p_debug_info => l_debug_info
404 );
405
406 -- Distribution
407 IF c_distr_rec.line_type_lookup_code = 'ITEM' AND c_distr_rec.parent_reversal_id IS NOT NULL THEN
408 l_distr_amount := c_distr_rec.distr_amount * -1;
409 l_quantity_invoiced := c_distr_rec.quantity_invoiced * -1;
410 l_line_amount := c_distr_rec.distr_amount * -1;
411 ELSE
412 l_distr_amount := c_distr_rec.distr_amount;
413 l_quantity_invoiced := c_distr_rec.quantity_invoiced;
414 l_line_amount := c_distr_rec.distr_amount;
415 END IF;
416
417 l_debug_info := 'Invoice Distribution id('||i||'): '||c_distr_rec.invoice_distribution_id;
418 INL_LOGGING_PVT.Log_Statement (
419 p_module_name => g_module_name,
420 p_procedure_name => l_api_name,
421 p_debug_info => l_debug_info
422 );
423
424 l_matches_int_tbl(i).from_parent_table_name := 'AP_INVOICE_DISTRIBUTIONS';
425 l_matches_int_tbl(i).from_parent_table_id := c_distr_rec.invoice_distribution_id;
426 l_matches_int_tbl(i).adj_group_date := c_distr_rec.accounting_date;
427
428 -- In order to make the Create Adjust process less
429 -- complex, the correction match should use the same
430 -- currency that is used by the corrected match.
431 -- Although the match represents the new amount of the line and not the variation inl_matches_int will have the variation.
432 IF c_distr_rec.line_type = 'CORRECTION'
433 AND (c_distr_rec.dist_match_type <> 'NOT_MATCHED'
434 OR c_distr_rec.correction_type = 'ITEM')
435 THEN
436 -- Correction
437 l_debug_info := 'It is a correction. Type: '||c_distr_rec.correction_type;
438 INL_LOGGING_PVT.Log_Statement (
439 p_module_name => g_module_name,
440 p_procedure_name => l_api_name,
441 p_debug_info => l_debug_info
442 );
443
444 l_matches_int_tbl(i).to_parent_table_name := 'AP_INVOICE_DISTRIBUTIONS';
445 l_matches_int_tbl(i).to_parent_table_id := c_distr_rec.corrected_invoice_dist_id;
446 ELSE
447 l_debug_info := 'It is not a correction.';
448 INL_LOGGING_PVT.Log_Statement (
449 p_module_name => g_module_name,
450 p_procedure_name => l_api_name,
451 p_debug_info => l_debug_info
452 );
453
454 l_matches_int_tbl(i).to_parent_table_name := 'RCV_TRANSACTIONS';
455 l_matches_int_tbl(i).to_parent_table_id := c_distr_rec.rcv_transaction_id;
456
457 END IF;
458
459 IF c_distr_rec.line_type = 'ITEM' OR c_distr_rec.correction_type = 'ITEM' THEN
460 -- The distribution cursor does not get IPV lines
461 -- To get the exact qty and amt we access the ap_invoice_lines
462 l_matches_int_tbl(i).charge_line_type_id := NULL;
463 l_matches_int_tbl(i).matched_qty := l_quantity_invoiced; --c_distr_rec.quantity_invoiced;
464 l_matches_int_tbl(i).matched_uom_code := c_distr_rec.uom_code;
465 l_matches_int_tbl(i).matched_amt := l_line_amount; --c_distr_rec.distr_amount;
466 l_matches_int_tbl(i).tax_code := NULL;
467 l_matches_int_tbl(i).nrec_tax_amt := NULL;
468 l_matches_int_tbl(i).tax_amt_included_flag := NULL;
469 l_matches_int_tbl(i).party_id := NULL;
470 l_matches_int_tbl(i).party_site_id := NULL;
471 ELSE
472 l_matches_int_tbl(i).matched_qty := NULL;
473
474 l_debug_info := 'c_distr_rec.line_type';
475 INL_LOGGING_PVT.Log_Variable (
476 p_module_name => g_module_name,
477 p_procedure_name => l_api_name,
478 p_var_name => l_debug_info,
479 p_var_value => c_distr_rec.line_type
480 );
481
482 l_debug_info := 'c_distr_rec.correction_type';
483 INL_LOGGING_PVT.Log_Variable (
484 p_module_name => g_module_name,
485 p_procedure_name => l_api_name,
486 p_var_name => l_debug_info,
487 p_var_value => c_distr_rec.correction_type
488 );
489 SELECT count(*)
490 INTO l_count_to_match_amt
491 FROM ap_invoice_lines_all l
492 WHERE l.invoice_id = p_invoice_id
493 AND l.line_type_lookup_code <> 'ITEM';
494
495 IF l_count_to_match_amt < 2 THEN
496 l_matches_int_tbl(i).match_amounts_flag := 'N';
497 ELSE
498 l_matches_int_tbl(i).match_amounts_flag := 'Y';
499 END IF;
500
501 IF c_distr_rec.line_type = 'CHARGE' OR c_distr_rec.correction_type = 'CHARGE' THEN
502
503 l_debug_info := 'l_count_invoices_with_charge';
504 INL_LOGGING_PVT.Log_Variable (
505 p_module_name => g_module_name,
506 p_procedure_name => l_api_name,
507 p_var_name => l_debug_info,
508 p_var_value => l_count_invoices_with_charge
509 );
510
511 l_matches_int_tbl(i).party_id := c_distr_rec.party_id;
512 l_matches_int_tbl(i).party_site_id := c_distr_rec.party_site_id;
513 l_matches_int_tbl(i).charge_line_type_id := c_distr_rec.cost_factor_id;
514 l_matches_int_tbl(i).matched_amt := l_distr_amount; --c_distr_rec.distr_amount;
515 l_matches_int_tbl(i).tax_code := NULL;
516 l_matches_int_tbl(i).nrec_tax_amt := NULL;
517 l_matches_int_tbl(i).tax_amt_included_flag := NULL;
518 ELSE
519 l_debug_info := 'c_distr_rec.charge_applicable_to_dist_id';
520 INL_LOGGING_PVT.Log_Variable (
521 p_module_name => g_module_name,
522 p_procedure_name => l_api_name,
523 p_var_name => l_debug_info,
524 p_var_value => c_distr_rec.charge_applicable_to_dist_id
525 );
526 l_debug_info := 'c_distr_rec.invoice_id';
527 INL_LOGGING_PVT.Log_Variable (
528 p_module_name => g_module_name,
529 p_procedure_name => l_api_name,
530 p_var_name => l_debug_info,
531 p_var_value => c_distr_rec.invoice_id
532 );
533 -- Gets the "parent" cost factor and line_type_lookup_code
534 -- in order to identify whether or not a given Charge that
535 -- has taxes, should keep in LCM the same cost factor
536 -- defined in its Invoice
537 SELECT ail.cost_factor_id,
538 ail.line_type_lookup_code
539 INTO l_par_cost_factor_id,
540 l_par_line_type_lookup_code
541 FROM ap_invoice_distributions aid,
542 ap_invoice_lines ail
543 WHERE aid.invoice_id = ail.invoice_id
544 AND aid.invoice_line_number = ail.line_number
545 AND aid.invoice_distribution_id = c_distr_rec.charge_applicable_to_dist_id
546 AND aid.invoice_id = c_distr_rec.invoice_id;
547
548 IF l_par_line_type_lookup_code IN ('MISCELLANEOUS', 'FREIGHT') THEN
549 l_matches_int_tbl(i).charge_line_type_id := l_par_cost_factor_id;
550 ELSE
551 l_matches_int_tbl(i).charge_line_type_id := NULL;
552 l_matches_int_tbl(i).match_amounts_flag := 'N';
553 END IF;
554
555 l_matches_int_tbl(i).party_id := NULL;
556 l_matches_int_tbl(i).party_site_id := NULL;
557 l_matches_int_tbl(i).matched_amt := l_distr_amount; --c_distr_rec.distr_amount;
558 l_matches_int_tbl(i).tax_code := c_distr_rec.tax_code;
559 l_matches_int_tbl(i).nrec_tax_amt := c_distr_rec.nrec_tax_amt;
560 l_matches_int_tbl(i).tax_amt_included_flag := c_distr_rec.tax_amt_included_flag;
561 END IF;
562 END IF;
563
564 IF c_distr_rec.line_type = 'CORRECTION'
565 AND c_distr_rec.dist_match_type = 'NOT_MATCHED'
566 AND c_distr_rec.correction_type <> 'ITEM'
567 THEN
568 l_matches_int_tbl(i).match_type_code := c_distr_rec.correction_type;
569 ELSE
570 l_matches_int_tbl(i).match_type_code := c_distr_rec.line_type;
571 END IF;
572 l_matches_int_tbl(i).matched_curr_code := c_distr_rec.curr_code;
573 l_matches_int_tbl(i).matched_curr_conversion_type := c_distr_rec.curr_type;
574 l_matches_int_tbl(i).matched_curr_conversion_date := c_distr_rec.curr_date;
575 l_matches_int_tbl(i).matched_curr_conversion_rate := c_distr_rec.curr_rate;
576 l_matches_int_tbl(i).reversal_flag := c_distr_rec.reversal_flag;--Bug#14604983
577 l_debug_info := 'End Loop';
578 INL_LOGGING_PVT.Log_Statement (
579 p_module_name => g_module_name,
580 p_procedure_name => l_api_name,
581 p_debug_info => l_debug_info
582 );
583
584 END LOOP;
585
586 l_debug_info := 'Call Create_MatchIntLines ';
587 INL_LOGGING_PVT.Log_Statement (
588 p_module_name => g_module_name,
589 p_procedure_name => l_api_name,
590 p_debug_info => l_debug_info
591 );
592 IF NVL(l_matches_int_tbl.LAST,0) > 0 THEN
593 -- Call Create_MatchIntLines to create Matches and
594 -- set Pending Matching Flag to 'Y' in Shipment Header.
595 Create_MatchIntLines(
596 p_api_version => 1.0,
597 p_init_msg_list => FND_API.G_FALSE,
598 p_commit => FND_API.G_FALSE,
599 p_matches_int_tbl => l_matches_int_tbl,
600 x_return_status => l_return_status,
601 x_msg_count => l_msg_count,
602 x_msg_data => l_msg_data
603 );
604
605 END IF;
606
607 -- If any errors happen abort the process.
608 IF l_return_status = FND_API.G_RET_STS_ERROR THEN
609 RAISE FND_API.G_EXC_ERROR;
610 ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
611 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
612 END IF;
613
614 -- Standard check of p_commit.
615 IF FND_API.To_Boolean( p_commit ) THEN
616 COMMIT WORK;
617 END IF;
618
619 -- Standard call to get message count and if count is 1, get message info.
620 FND_MSG_PUB.Count_And_Get(
621 p_encoded => FND_API.g_false,
622 p_count => x_msg_count,
623 p_data => x_msg_data
624 );
625
626 -- Standard End of Procedure/Function Logging
627 INL_logging_pvt.Log_EndProc (
628 p_module_name => g_module_name,
629 p_procedure_name => l_api_name
630 );
631 EXCEPTION
632 WHEN FND_API.G_EXC_ERROR THEN
633 -- Standard Expected Error Logging
634 INL_LOGGING_PVT.Log_ExpecError (
635 p_module_name => g_module_name,
636 p_procedure_name => l_api_name
637 );
638 ROLLBACK TO Create_MatchesFromAP_GRP;
639 x_return_status := FND_API.G_RET_STS_ERROR;
640 FND_MSG_PUB.Count_And_Get(
641 p_encoded => FND_API.g_false,
642 p_count => x_msg_count,
643 p_data => x_msg_data
644 );
645 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
646 -- Standard Unexpected Error Logging
647 INL_LOGGING_PVT.Log_UnexpecError (
648 p_module_name => g_module_name,
649 p_procedure_name => l_api_name
650 );
651 ROLLBACK TO Create_MatchesFromAP_GRP;
652 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
653
654 FND_MSG_PUB.Count_And_Get(
655 p_encoded => FND_API.g_false,
656 p_count => x_msg_count,
657 p_data => x_msg_data
658 );
659 WHEN OTHERS THEN
660 -- Standard Unexpected Error Logging
661 INL_LOGGING_PVT.Log_UnexpecError (
662 p_module_name => g_module_name,
663 p_procedure_name => l_api_name
664 );
665 ROLLBACK TO Create_MatchesFromAP_GRP;
666 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
667 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
668 THEN
669 FND_MSG_PUB.Add_Exc_Msg(
670 p_pkg_name => g_pkg_name,
671 p_procedure_name => l_api_name
672 );
673 END IF;
674 FND_MSG_PUB.Count_And_Get(
675 p_encoded => FND_API.g_false,
676 p_count => x_msg_count,
677 p_data => x_msg_data
678 );
679 END Create_MatchesFromAP;
680
681 END INL_MATCH_GRP;