1 PACKAGE BODY RCV_AccrualAccounting_GRP AS
2 /* $Header: RCVGCSTB.pls 120.5.12010000.2 2008/12/26 14:32:45 mpuranik ship $ */
3
4 G_PKG_NAME CONSTANT VARCHAR2(30) := 'RCV_AccrualAcct_GRP';
5 --G_DEBUG CONSTANT VARCHAR2(1) := NVL(FND_PROFILE.VALUE('AFLOG_ENABLED'),'N');
6 G_LOG_LEVEL CONSTANT NUMBER := FND_LOG.G_CURRENT_RUNTIME_LEVEL;
7 G_LOG_HEAD CONSTANT VARCHAR2(40) := 'po.plsql.'||G_PKG_NAME;
8
9 -- Start of comments
10 -- API name : Create_AccountingEvents
11 -- Type : Group
12 -- Function : To seed accounting events for receiving transactions,
13 -- retroactive price adjustments and global procurement.
14 -- Pre-reqs :
15 -- Parameters :
16 -- IN : p_api_version IN NUMBER Required
17 -- p_init_msg_list IN VARCHAR2 Optional
18 -- Default = FND_API.G_FALSE
19 -- p_commit IN VARCHAR2 Optional
20 -- Default = FND_API.G_FALSE
21 -- p_validation_level IN NUMBER Optional
22 -- Default = FND_API.G_VALID_LEVEL_FULL
23 -- p_source_type IN VARCHAR2 Required
24 -- Valid values : "RECEIVING", "RETROPRICE"
25 --
26 -- The following parameters are required for a source type
27 -- of "RECEIVING"
28 -- p_rcv_transaction_id IN NUMBER Optional
29 -- p_direct_delivery_flag IN VARCHAR2 Optional
30 --
31 -- The following parameters are required for a source type
32 -- of "RETROPRICE"
33 -- p_po_header_id IN NUMBER Optional
34 -- p_po_release_id IN NUMBER Optional
35 -- p_po_line_id IN NUMBER Optional
36 -- p_po_line_location_id IN NUMBER Optional
37 -- p_old_po_price IN NUMBER Optional
38 -- p_new_po_price IN NUMBER Optional
39 --
40 -- The following parameters have been obsoleted. AP will call
41 -- the Create_InterCompanyEvents to seed IC events.
42 -- p_invoice_dist_id_tbl IN NUMBER_TBL Optional
43 --
44 -- OUT : x_return_status OUT VARCHAR2(1)
45 -- x_msg_count OUT NUMBER
46 -- x_msg_data OUT VARCHAR2(2000)
47 -- Version :
48 -- Initial version 1.0
49 --
50 -- Notes : This API creates all Receiving related accounting events in
51 -- RCV_ACCOUNTING_EVENTS. For online accruals, it also generates
52 -- the accounting entries for the event.
53 -- This API is called from :
54 -- 1. The Receiving Transaction Processor for each transaction in
55 -- RCV_Transactions.
56 -- 2. The PO Approvals Process for retroactive price changes.
57 -- 3. Accounts Payables during Invoice Validation phase for period
58 -- end accruals.
59 -- Depending on the calling process, there are three valid source types:
60 -- 'RECEIVING' when called by Receiving
61 -- 'RETROPRICE' when called by PO for retroactive price changes
62 --
63 -- End of comments
64 -------------------------------------------------------------------------------
65 PROCEDURE Create_AccountingEvents(
66 p_api_version IN NUMBER,
67 p_init_msg_list IN VARCHAR2,
68 p_commit IN VARCHAR2,
69 p_validation_level IN NUMBER,
70 x_return_status OUT NOCOPY VARCHAR2,
71 x_msg_count OUT NOCOPY NUMBER,
72 x_msg_data OUT NOCOPY VARCHAR2,
73
74 p_source_type IN VARCHAR2, /*RECEIVING, RETROPRICE*/
75
76 /* The following parameters are only required for source type of Receiving */
77 p_rcv_transaction_id IN NUMBER,
78 p_direct_delivery_flag IN VARCHAR2,
79
80 /* The following parameters are only required for source type of RetroPrice*/
81 p_po_header_id IN NUMBER,
82 p_po_release_id IN NUMBER,
83 p_po_line_id IN NUMBER,
84 p_po_line_location_id IN NUMBER,
85 p_old_po_price IN NUMBER,
86 p_new_po_price IN NUMBER,
87
88 /* The following parameter has been obsoleted. AP will instead call the
89 Create_IntercompanyEvents to seed IC events. */
90 p_invoice_distribution_id IN NUMBER
91 )
92 IS
93 l_api_name CONSTANT VARCHAR2(30) := 'Create_AccountingEvents';
94 l_api_version CONSTANT NUMBER := 1.0;
95
96 l_return_status VARCHAR2(1);
97 l_msg_count NUMBER := 0;
98 l_msg_data VARCHAR2(8000);
99 l_stmt_num NUMBER := 0;
100 l_api_message VARCHAR2(1000);
101
102 l_inv_dist_id NUMBER;
103 l_user_id NUMBER := -1;
104 l_org_id NUMBER := 0;
105 l_resp_id NUMBER := 0;
106 l_resp_appl_id NUMBER := 0;
107 l_rae_count NUMBER := 0;
108 l_process_enabled_flag mtl_parameters.process_enabled_flag%TYPE; /* INVCONV ANTHIYAG Bug#5529309 18-Sep-2006 */
109 l_lcm_enabled VARCHAR2(1);
110
111 l_full_name CONSTANT VARCHAR2(60) := g_pkg_name || '.' || l_api_name;
112 l_module constant varchar2(60) := 'po.plsql.'||l_full_name;
113
114 l_uLog CONSTANT BOOLEAN := fnd_log.level_unexpected >= g_log_level AND
115 fnd_log.TEST(fnd_log.level_unexpected, l_module);
116 l_errorLog constant boolean := l_uLog and (FND_LOG.LEVEL_ERROR >= G_LOG_LEVEL);
117 l_eventLog constant boolean := l_errorLog and (FND_LOG.LEVEL_EVENT >= G_LOG_LEVEL);
118 l_pLog constant boolean := l_eventLog and (FND_LOG.LEVEL_PROCEDURE >= G_LOG_LEVEL);
119 l_sLog constant boolean := l_pLog and (FND_LOG.LEVEL_STATEMENT >= G_LOG_LEVEL);
120
121
122 BEGIN
123 l_return_status := fnd_api.g_ret_sts_success;
124
125 -- Standard start of API savepoint
126 SAVEPOINT Create_AccountingEvents_GRP;
127
128 l_stmt_num := 0;
129
130 IF l_pLog THEN
131 IF (FND_LOG.G_CURRENT_RUNTIME_LEVEL <= FND_LOG.LEVEL_PROCEDURE) THEN
132 FND_LOG.string(FND_LOG.LEVEL_PROCEDURE,G_LOG_HEAD || '.'||l_api_name||'.begin'
133 ,'Create_AccountingEvents <<');
134 END IF;
135 END IF;
136
137 -- Standard call to check for call compatibility
138 IF NOT FND_API.Compatible_API_Call (
139 l_api_version,
140 p_api_version,
141 l_api_name,
142 G_PKG_NAME ) THEN
143 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
144 END IF;
145
146 -- Initialize message list if p_init_msg_list is set to TRUE
147 IF FND_API.to_Boolean(p_init_msg_list) THEN
148 FND_MSG_PUB.initialize;
149 END IF;
150
151 -- Initialize API return status to success
152 x_return_status := FND_API.G_RET_STS_SUCCESS;
153
154 FND_PROFILE.get('USER_ID',l_user_id);
155 FND_PROFILE.get('ORG_ID',l_org_id);
156 FND_PROFILE.get('RESP_ID',l_resp_id);
157 FND_PROFILE.get('RESP_APPL_ID',l_resp_appl_id);
158
159 l_api_message := 'Create_ReceivingEvents User ID :'||l_user_id||
160 ' Org ID :' || l_org_id||
161 ' Resp_ID : '||l_resp_id||
162 ' Resp_appl_ID : '||l_resp_appl_id;
163
164
165 IF l_sLog THEN
166 IF (FND_LOG.G_CURRENT_RUNTIME_LEVEL <= FND_LOG.LEVEL_STATEMENT) THEN
167 FND_LOG.string(FND_LOG.LEVEL_STATEMENT,G_LOG_HEAD||'.'||l_api_name||'.'||l_stmt_num
168 ,l_api_message);
169 END IF;
170 END IF;
171
172 /* INVCONV ANTHIYAG Bug#5529309 18-Sep-2006 Start */
173 BEGIN
174 SELECT nvl(b.process_enabled_flag, 'N')
175 INTO l_process_enabled_flag
176 FROM po_line_locations_all a,
177 mtl_parameters b
178 WHERE a.line_location_id = p_po_line_location_id
179 AND b.organization_id = a.ship_to_organization_id;
180 EXCEPTION
181 WHEN OTHERS THEN
182 l_process_enabled_flag := 'N';
183 END;
184
185 IF nvl(l_process_enabled_flag, 'N') = 'Y' THEN
186
187 IF l_sLog THEN
188 l_api_message := ' Txn Info: po_line_location_id => ' || p_po_line_location_id ||
189 ' rcv_transaction_id => ' || p_rcv_transaction_id;
190 IF (FND_LOG.G_CURRENT_RUNTIME_LEVEL <= FND_LOG.LEVEL_STATEMENT) THEN
191 FND_LOG.string(FND_LOG.LEVEL_STATEMENT,G_LOG_HEAD||'.'||l_api_name||'.'||l_stmt_num
192 ,'Inv Org is Process Org. Skipping Processing.');
193 FND_LOG.string(FND_LOG.LEVEL_STATEMENT,G_LOG_HEAD||'.'||l_api_name||'.'||l_stmt_num
194 ,l_api_message);
195 END IF;
196 END IF;
197
198 x_return_status := l_return_status;
199 x_msg_data := NULL;
200 x_msg_count := l_msg_count;
201 RETURN;
202
203 ELSE
204 IF l_sLog THEN
205 IF (FND_LOG.G_CURRENT_RUNTIME_LEVEL <= FND_LOG.LEVEL_STATEMENT) THEN
206 FND_LOG.string(FND_LOG.LEVEL_STATEMENT,G_LOG_HEAD||'.'||l_api_name||'.'||l_stmt_num
207 ,'Inv Org is Discrete Org. Proceeding further...');
208 END IF;
209 END IF;
210
211 END IF;
212 /* INVCONV ANTHIYAG Bug#5529309 18-Sep-2006 End */
213
214 -- If Invalid user_id is stamped, exit
215 IF l_user_id = -1 THEN
216 FND_MESSAGE.set_name('PO','INVALID_USER_ID');
217 FND_MSG_pub.add;
218 IF l_errorLog THEN
219 IF (FND_LOG.G_CURRENT_RUNTIME_LEVEL <= FND_LOG.LEVEL_ERROR) THEN
220 FND_LOG.message(FND_LOG.LEVEL_ERROR,G_LOG_HEAD || '.'||l_api_name||l_stmt_num,FALSE);
221 END IF;
222 END IF;
223 RAISE FND_API.g_exc_error;
224 END IF;
225
226 IF UPPER(p_source_type) = 'RECEIVING' THEN
227 l_stmt_num := 100;
228 IF l_eventLog THEN
229 IF (FND_LOG.G_CURRENT_RUNTIME_LEVEL <= FND_LOG.LEVEL_EVENT) THEN
230 FND_LOG.string(FND_LOG.LEVEL_EVENT,G_LOG_HEAD||'.'||l_api_name||'.'||l_stmt_num
231 ,'Creating Receiving Event');
232 END IF;
233 END IF;
234 IF l_sLog THEN
235 IF (FND_LOG.G_CURRENT_RUNTIME_LEVEL <= FND_LOG.LEVEL_STATEMENT) THEN
236 FND_LOG.string(FND_LOG.LEVEL_STATEMENT,G_LOG_HEAD||'.'||l_api_name||'.'||l_stmt_num
237 ,'rcv_transaction_id : '||p_rcv_transaction_id);
238 END IF;
239 END IF;
240
241 -- Bug #4267722. Validate transaction_id passed in by Receiving.
242 l_stmt_num := 110;
243 SELECT count(*)
244 INTO l_rae_count
245 FROM rcv_accounting_events RAE
246 WHERE rcv_transaction_id = p_rcv_transaction_id;
247
248 IF l_rae_count <> 0 THEN
249 l_api_message := 'Invalid transaction. Accounting events have already been generated for transaction : '||
250 p_rcv_transaction_id;
251 IF l_uLog THEN
252 IF (FND_LOG.G_CURRENT_RUNTIME_LEVEL <= FND_LOG.LEVEL_UNEXPECTED) THEN
253 FND_LOG.string(FND_LOG.LEVEL_UNEXPECTED,G_LOG_HEAD || '.'||l_api_name||l_stmt_num
254 ,'Create_AccountingEvents : '||l_stmt_num||' : '||l_api_message);
255 END IF;
256 END IF;
257 RAISE FND_API.g_exc_unexpected_error;
258 END IF;
259
260 l_stmt_num := 120;
261 RCV_AccEvents_PVT.Create_ReceivingEvents(
262 p_api_version => 1.0,
263 x_return_status => l_return_status,
264 x_msg_count => l_msg_count,
265 x_msg_data => l_msg_data,
266 p_rcv_transaction_id => p_rcv_transaction_id,
267 p_direct_delivery_flag => p_direct_delivery_flag );
268 ELSIF UPPER(p_source_type) = 'RETROPRICE' THEN
269
270 /* LCM project */
271 l_stmt_num := 130;
272 SELECT lcm_flag
273 INTO l_lcm_enabled
274 FROM po_line_locations_all
275 WHERE line_location_id = p_po_line_location_id;
276
277 l_stmt_num := 140;
278 IF l_lcm_enabled = 'Y' THEN
279
280 l_stmt_num := 150;
281 FND_MESSAGE.SET_NAME('BOM', 'CST_RETRO_PRC_IN_LCM_SHIP');
282 FND_MSG_PUB.ADD;
283
284 IF l_errorLog THEN
285 IF (FND_LOG.G_CURRENT_RUNTIME_LEVEL <= FND_LOG.LEVEL_ERROR) THEN
286 FND_LOG.message(FND_LOG.LEVEL_ERROR,l_module,FALSE);
287 END IF;
288 END IF;
289 RAISE FND_API.g_exc_error;
290
291 END IF;
292
293 l_stmt_num := 200;
294 IF l_eventLog THEN
295 IF (FND_LOG.G_CURRENT_RUNTIME_LEVEL <= FND_LOG.LEVEL_EVENT) THEN
296 FND_LOG.string(FND_LOG.LEVEL_EVENT,G_LOG_HEAD||'.'||l_api_name||'.'||l_stmt_num
297 ,'Creating Adjust Event');
298 END IF;
299 END IF;
300 IF l_sLog THEN
301 IF (FND_LOG.G_CURRENT_RUNTIME_LEVEL <= FND_LOG.LEVEL_STATEMENT) THEN
302 FND_LOG.string(FND_LOG.LEVEL_STATEMENT,G_LOG_HEAD||'.'||l_api_name||'.'||l_stmt_num
303 ,'po_header_id : '||p_po_header_id||
304 ' po_release_id : '||p_po_release_id||
305 ' p_po_line_id : '||p_po_line_id||
306 ' p_po_line_location_id : '||p_po_line_location_id||
307 ' p_old_po_price : '||p_old_po_price||
308 ' p_new_po_price : '||p_new_po_price);
309 END IF;
310 END IF;
311
312 RCV_AccEvents_PVT.Create_AdjustEvents(
313 p_api_version => 1.0,
314 x_return_status => l_return_status,
315 x_msg_count => l_msg_count,
316 x_msg_data => l_msg_data,
317 p_po_header_id => p_po_header_id,
318 p_po_release_id => p_po_release_id,
319 p_po_line_id => p_po_line_id,
320 p_po_line_location_id => p_po_line_location_id,
321 p_old_po_price => p_old_po_price,
322 p_new_po_price => p_new_po_price);
323
324 ELSE
325 FND_MESSAGE.set_name('PO','INVALID_EVENT_SOURCE_TYPE');
326 FND_MSG_pub.add;
327 IF l_errorLog THEN
328 IF (FND_LOG.G_CURRENT_RUNTIME_LEVEL <= FND_LOG.LEVEL_ERROR) THEN
329 FND_LOG.message(FND_LOG.LEVEL_ERROR,G_LOG_HEAD || '.'||l_api_name||l_stmt_num,FALSE);
330 END IF;
331 END IF;
332 RAISE FND_API.g_exc_error;
333 END IF;
334
335 IF l_return_status <> FND_API.g_ret_sts_success THEN
336 l_api_message := 'Error creating event';
337 IF l_uLog THEN
338 IF (FND_LOG.G_CURRENT_RUNTIME_LEVEL <= FND_LOG.LEVEL_UNEXPECTED) THEN
339 FND_LOG.string(FND_LOG.LEVEL_UNEXPECTED,G_LOG_HEAD || '.'||l_api_name||l_stmt_num
340 ,'Create_AccountingEvents : '||l_stmt_num||' : '||l_api_message);
341 END IF;
342 END IF;
343 RAISE FND_API.g_exc_unexpected_error;
344 END IF;
345
346 --- Standard check of p_commit
347 IF FND_API.to_Boolean(p_commit) THEN
348 COMMIT WORK;
349 END IF;
350
351 -- Standard Call to get message count and if count = 1, get message info
352 FND_MSG_PUB.Count_And_Get (
353 p_count => x_msg_count,
354 p_data => x_msg_data );
355
356 IF l_pLog THEN
357 IF (FND_LOG.G_CURRENT_RUNTIME_LEVEL <= FND_LOG.LEVEL_PROCEDURE) THEN
358 FND_LOG.string(FND_LOG.LEVEL_PROCEDURE,G_LOG_HEAD || '.'||l_api_name||'.end'
359 ,'Create_AccountingEvents >>');
360 END IF;
361 END IF;
362
363
364 EXCEPTION
365 WHEN FND_API.g_exc_error THEN
366 ROLLBACK TO Create_AccountingEvents_GRP;
367 x_return_status := FND_API.g_ret_sts_error;
368 FND_MSG_PUB.count_and_get
369 ( p_count => x_msg_count
370 , p_data => x_msg_data
371 );
372
373 WHEN FND_API.g_exc_unexpected_error THEN
374 ROLLBACK TO Create_AccountingEvents_GRP;
375 x_return_status := FND_API.g_ret_sts_unexp_error ;
376 FND_MSG_PUB.count_and_get
377 ( p_count => x_msg_count
378 , p_data => x_msg_data
379 );
380
381 WHEN OTHERS THEN
382 ROLLBACK TO Create_AccountingEvents_GRP;
383 x_return_status := fnd_api.g_ret_sts_unexp_error ;
384
385 IF l_uLog THEN
386 IF (FND_LOG.G_CURRENT_RUNTIME_LEVEL <= FND_LOG.LEVEL_UNEXPECTED) THEN
387 FND_LOG.string(FND_LOG.LEVEL_UNEXPECTED,G_LOG_HEAD || '.'||l_api_name||l_stmt_num
388 ,'Create_AccountingEvents : '||l_stmt_num||' : '||substr(SQLERRM,1,200));
389 END IF;
390 END IF;
391
392 IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error)
393 THEN
394 FND_MSG_PUB.add_exc_msg
395 ( G_PKG_NAME,
396 l_api_name || 'Statement -'||to_char(l_stmt_num)
397 );
398 END IF;
399 FND_MSG_PUB.count_and_get
400 ( p_count => x_msg_count
401 , p_data => x_msg_data
402 );
403 END Create_AccountingEvents;
404 ---------------------------------------------------------------------------
405 -- This Procedure just calls the one above without a gl_group_id
406 -- This is left in place to avoid patching dependencies with Receiving
407 -- during R12. Please remove this procedure before R12 release
408 ---------------------------------------------------------------------------
409
410 PROCEDURE Create_AccountingEvents(
411 p_api_version IN NUMBER,
412 p_init_msg_list IN VARCHAR2,
413 p_commit IN VARCHAR2,
414 p_validation_level IN NUMBER,
415 x_return_status OUT NOCOPY VARCHAR2,
416 x_msg_count OUT NOCOPY NUMBER,
417 x_msg_data OUT NOCOPY VARCHAR2,
418
419 p_source_type IN VARCHAR2,
420 p_rcv_transaction_id IN NUMBER,
421 p_direct_delivery_flag IN VARCHAR2,
422
423 p_gl_group_id IN NUMBER,
424
425 p_po_header_id IN NUMBER,
426 p_po_release_id IN NUMBER,
427 p_po_line_id IN NUMBER,
428 p_po_line_location_id IN NUMBER,
429 p_old_po_price IN NUMBER,
430 p_new_po_price IN NUMBER,
431
432 p_invoice_distribution_id IN NUMBER
433 )
434 IS
435
436 BEGIN
437
438 Create_AccountingEvents (
439 p_api_version => p_api_version,
440 p_init_msg_list => p_init_msg_list,
441 p_commit => p_commit,
442 p_validation_level => p_validation_level,
443 x_return_status => x_return_status,
444 x_msg_count => x_msg_count,
445 x_msg_data => x_msg_data,
446 p_source_type => p_source_type,
447 p_rcv_transaction_id => p_rcv_transaction_id,
448 p_direct_delivery_flag => p_direct_delivery_flag,
449 p_po_header_id => p_po_header_id,
450 p_po_release_id => p_po_release_id,
451 p_po_line_id => p_po_line_id,
452 p_po_line_location_id => p_po_line_location_id,
453 p_old_po_price => p_old_po_price,
454 p_new_po_price => p_new_po_price,
455 p_invoice_distribution_id => p_invoice_distribution_id);
456
457
458 END Create_AccountingEvents;
459
460 -- Start of comments
461 -- API name : Create_InterCompanyEvents
462 -- Type : Group
463 -- Function : To seed accounting Intercompany events for period end accruals.
464 -- When Invoice is matched to PO and validated, IC events will be
465 -- seeded for Global Procurement scenarios.
466 -- Pre-reqs :
467 -- Parameters :
468 -- IN : p_api_version IN NUMBER Required
469 -- p_init_msg_list IN VARCHAR2 Optional
470 -- Default = FND_API.G_FALSE
471 -- p_commit IN VARCHAR2 Optional
472 -- Default = FND_API.G_FALSE
473 -- p_validation_level IN NUMBER Optional
474 -- Default = FND_API.G_VALID_LEVEL_FULL
475 --
476 -- p_invoice_dist_id_tbl IN NUMBER_TBL Required
477 --
478 -- OUT : x_return_status OUT VARCHAR2(1)
479 -- x_msg_count OUT NUMBER
480 -- x_msg_data OUT VARCHAR2(2000)
481 -- Version :
482 -- Initial version 1.0
483 --
484 -- Notes : This API seeds Intercompany events for period end accruals.
485 -- When Invoice is matched to PO and validated, AP will call this
486 -- this API for period end accruals. If Invoice is for a global
487 -- procurement scenario, this API will seed Intercompany events in
488 -- RCV_ACCOUNTING_EVENTS. The intercompany invoicing program will
489 -- later use these events to create intercompany invoices.
490 --
491 -- This API is called from :
492 -- 1. Accounts Payables during Invoice Validation phase for period
493 -- end accruals.
494 -- Start of comments
495 PROCEDURE Create_InterCompanyEvents(
496 p_api_version IN NUMBER,
497 p_init_msg_list IN VARCHAR2 := FND_API.G_FALSE,
498 p_commit IN VARCHAR2 := FND_API.G_FALSE,
499 p_validation_level IN NUMBER := FND_API.G_VALID_LEVEL_FULL,
500 x_return_status OUT NOCOPY VARCHAR2,
501 x_msg_count OUT NOCOPY NUMBER,
502 x_msg_data OUT NOCOPY VARCHAR2,
503
504 p_invoice_dist_id_tbl IN NUMBER_TBL
505 )
506
507 IS
508 l_api_name CONSTANT VARCHAR2(30) := 'Create_InterCompanyEvents';
509 l_api_version CONSTANT NUMBER := 1.0;
510
511 l_return_status VARCHAR2(1);
512 l_msg_count NUMBER := 0;
513 l_msg_data VARCHAR2(8000);
514 l_stmt_num NUMBER := 0;
515 l_api_message VARCHAR2(1000);
516
517 l_inv_dist_id NUMBER;
518
519 l_full_name CONSTANT VARCHAR2(60) := g_pkg_name || '.' || l_api_name;
520 l_module constant varchar2(60) := 'po.plsql.'||l_full_name;
521
522 l_uLog CONSTANT BOOLEAN := fnd_log.level_unexpected >= g_log_level AND
523 fnd_log.TEST(fnd_log.level_unexpected, l_module);
524 l_eventLog constant boolean := l_uLog and (FND_LOG.LEVEL_EVENT >= G_LOG_LEVEL);
525 l_pLog constant boolean := l_eventLog and (FND_LOG.LEVEL_PROCEDURE >= G_LOG_LEVEL);
526 l_sLog constant boolean := l_pLog and (FND_LOG.LEVEL_STATEMENT >= G_LOG_LEVEL);
527 --BUG#6167988
528 l_cnt NUMBER := 0;
529
530 BEGIN
531 l_return_status := fnd_api.g_ret_sts_success;
532 -- Standard start of API savepoint
533 SAVEPOINT Create_InterCompanyEvents_GRP;
534
535 l_stmt_num := 0;
536
537 IF l_pLog THEN
538 IF (FND_LOG.G_CURRENT_RUNTIME_LEVEL <= FND_LOG.LEVEL_PROCEDURE) THEN
539 FND_LOG.string(FND_LOG.LEVEL_PROCEDURE,G_LOG_HEAD || '.'||l_api_name||'.begin'
540 ,'Create_InterCompanyEvents <<');
541 END IF;
542 END IF;
543
544 -- Standard call to check for call compatibility
545 IF NOT FND_API.Compatible_API_Call (
546 l_api_version,
547 p_api_version,
548 l_api_name,
549 G_PKG_NAME ) THEN
550 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
551 END IF;
552
553 -- Initialize message list if p_init_msg_list is set to TRUE
554 IF FND_API.to_Boolean(p_init_msg_list) THEN
555 FND_MSG_PUB.initialize;
556 END IF;
557
558 -- Initialize API return status to success
559 x_return_status := FND_API.G_RET_STS_SUCCESS;
560
561 l_stmt_num := 10;
562 IF l_eventLog THEN
563 IF (FND_LOG.G_CURRENT_RUNTIME_LEVEL <= FND_LOG.LEVEL_EVENT) THEN
564 FND_LOG.string(FND_LOG.LEVEL_EVENT,G_LOG_HEAD||'.'||l_api_name||'.'||l_stmt_num
565 ,'Creating Intercompany Event');
566 END IF;
567 END IF;
568
569
570
571 --BUG#6167988
572 l_cnt := p_invoice_dist_id_tbl.COUNT;
573
574 IF l_eventLog THEN
575 FND_LOG.string(FND_LOG.LEVEL_EVENT,G_LOG_HEAD||'.'||l_api_name||'.'||l_stmt_num,
576 'DEBUG p_invoice_dist_id_tbl.COUNT: '||l_cnt);
577 END IF;
578
579
580 IF l_cnt > 0 THEN
581
582 FOR l_counter IN p_invoice_dist_id_tbl.FIRST..p_invoice_dist_id_tbl.LAST LOOP
583 l_inv_dist_id := p_invoice_dist_id_tbl(l_counter);
584
585 IF l_sLog THEN
586 IF (FND_LOG.G_CURRENT_RUNTIME_LEVEL <= FND_LOG.LEVEL_STATEMENT) THEN
587 FND_LOG.string(FND_LOG.LEVEL_STATEMENT,G_LOG_HEAD||'.'||l_api_name||'.'||l_stmt_num
588 ,'invoice_distribution_id : '|| l_inv_dist_id);
589 END IF;
590 END IF;
591
592 l_stmt_num := 20;
593 RCV_AccEvents_PVT.Create_ICEvents(
594 p_api_version => 1.0,
595 x_return_status => l_return_status,
596 x_msg_count => l_msg_count,
597 x_msg_data => l_msg_data,
598 p_invoice_distribution_id => l_inv_dist_id);
599 IF l_return_status <> FND_API.g_ret_sts_success THEN
600 l_api_message := 'Error creating IC event';
601 IF l_uLog THEN
602 IF (FND_LOG.G_CURRENT_RUNTIME_LEVEL <= FND_LOG.LEVEL_UNEXPECTED) THEN
603 FND_LOG.string(FND_LOG.LEVEL_UNEXPECTED,G_LOG_HEAD || '.'||l_api_name||l_stmt_num
604 ,'Create_InterCompanyEvents : '||l_stmt_num||' : '||l_api_message);
605 END IF;
606 END IF;
607 RAISE FND_API.g_exc_unexpected_error;
608 END IF;
609 END LOOP;
610
611 END IF;
612
613 --- Standard check of p_commit
614 IF FND_API.to_Boolean(p_commit) THEN
615 COMMIT WORK;
616 END IF;
617
618
619 -- Standard Call to get message count and if count = 1, get message info
620 FND_MSG_PUB.Count_And_Get (
621 p_count => x_msg_count,
622 p_data => x_msg_data );
623
624 IF l_pLog THEN
625 IF (FND_LOG.G_CURRENT_RUNTIME_LEVEL <= FND_LOG.LEVEL_PROCEDURE) THEN
626 FND_LOG.string(FND_LOG.LEVEL_PROCEDURE,G_LOG_HEAD || '.'||l_api_name||'.end'
627 ,'Create_InterCompanyEvents >>');
628 END IF;
629 END IF;
630
631
632 EXCEPTION
633 WHEN FND_API.g_exc_error THEN
634 ROLLBACK TO Create_InterCompanyEvents_GRP;
635 x_return_status := FND_API.g_ret_sts_error;
636 FND_MSG_PUB.count_and_get
637 ( p_count => x_msg_count
638 , p_data => x_msg_data
639 );
640
641 WHEN FND_API.g_exc_unexpected_error THEN
642 ROLLBACK TO Create_InterCompanyEvents_GRP;
643 x_return_status := FND_API.g_ret_sts_unexp_error ;
644 FND_MSG_PUB.count_and_get
645 ( p_count => x_msg_count
646 , p_data => x_msg_data
647 );
648
649 WHEN OTHERS THEN
650 ROLLBACK TO Create_InterCompanyEvents_GRP;
651 x_return_status := fnd_api.g_ret_sts_unexp_error ;
652
653 IF l_uLog THEN
654 IF (FND_LOG.G_CURRENT_RUNTIME_LEVEL <= FND_LOG.LEVEL_UNEXPECTED) THEN
655 FND_LOG.string(FND_LOG.LEVEL_UNEXPECTED,G_LOG_HEAD || '.'||l_api_name||l_stmt_num
656 ,'Create_InterCompanyEvents : '||l_stmt_num||' : '||substr(SQLERRM,1,200));
657 END IF;
658 END IF;
659
660 IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error)
661 THEN
662 FND_MSG_PUB.add_exc_msg
663 ( G_PKG_NAME,
664 l_api_name || 'Statement -'||to_char(l_stmt_num)
665 );
666 END IF;
667 FND_MSG_PUB.count_and_get
668 ( p_count => x_msg_count
669 , p_data => x_msg_data
670 );
671 END Create_InterCompanyEvents;
672
673 -- Start of comments
674 -- API name : Get_InvTransactionInfo
675 -- Type : Private
676 -- Pre-reqs :
677 -- Function : To return the transfer price and distribution account in
678 -- global procurement and drop shipment scenarios.
679 -- Parameters :
680 -- IN : p_api_version IN NUMBER Required
681 -- p_init_msg_list IN VARCHAR2 Optional
682 -- Default = FND_API.G_FALSE
683 -- p_commit IN VARCHAR2 Optional
684 -- Default = FND_API.G_FALSE
685 -- p_validation_level IN NUMBER Optional
686 -- Default = FND_API.G_VALID_LEVEL_FULL
687 -- p_rcv_transaction_id IN NUMBER Required
688 --
689 -- OUT : x_return_status OUT VARCHAR2(1)
690 -- x_msg_count OUT NUMBER
691 -- x_msg_data OUT VARCHAR2(2000)
692 -- x_intercompany_pricing_option OUT NUMBER
693 -- x_currency_code OUT VARCHAR2
694 -- x_currency_conversion_rate OUT NUMBER
695 -- x_currency_conversion_date OUT DATE
696 -- x_currency_conversion_type OUT VARCHAR2(30)
697 -- x_distribution_acct_id OUT NUMBER
698 -- Version :
699 -- Initial version 1.0
700 --
701 -- Notes :
702 -- This API is called by the receiving transaction processor for Deliver, RTR
703 -- and Corrections to Deliver/RTR transactions, to determine if the price to be
704 -- stamped on MMTT is the PO price or the transfer price. This API returns a
705 -- flag to indicate if transfer price is to be used. If the intercompany_pricing_option
706 -- is set to 2, the transfer price and the corresponding currency code,
707 -- currency conversion rate, date and type are returned.
708 -- The transfer price is returned in the transaction UOM.
709 -- If the returned intercompany_pricing_option is 1, the Receiving transaction
710 -- Processor should stamp the PO price as usual.
711 --
712 -- This API also returns the distribution account for External Drop Shipments
713 -- when the new accounting flag is checked. If the returned distribution account
714 -- is -1, the Receiving transaction processor should stamp the MMTT transaction
715 -- with the Receiving Inspection account as usual.
716 -- Otherwise, it should stamp the returned Clearing Account.
717 --
718 -- End of comments
719 -------------------------------------------------------------------------------
720 PROCEDURE Get_InvTransactionInfo(
721 p_api_version IN NUMBER,
722 p_init_msg_list IN VARCHAR2,
723 p_commit IN VARCHAR2,
724 p_validation_level IN VARCHAR2,
725 x_return_status OUT NOCOPY VARCHAR2,
726 x_msg_count OUT NOCOPY NUMBER,
727 x_msg_data OUT NOCOPY VARCHAR2,
728
729 p_rcv_transaction_id IN NUMBER,
730
731 x_intercompany_pricing_option OUT NOCOPY NUMBER,
732 x_transfer_price OUT NOCOPY NUMBER,
733 x_currency_code OUT NOCOPY VARCHAR2,
734 x_currency_conversion_rate OUT NOCOPY NUMBER,
735 x_currency_conversion_date OUT NOCOPY DATE,
736 x_currency_conversion_type OUT NOCOPY VARCHAR2,
737 x_distribution_acct_id OUT NOCOPY NUMBER
738 )
739 IS
740 l_api_name CONSTANT VARCHAR2(30) := 'Get_InvTransactionInfo';
741 l_api_version CONSTANT NUMBER := 1.0;
742
743 l_return_status VARCHAR2(1);
744 l_msg_count NUMBER := 0;
745 l_msg_data VARCHAR2(8000);
746 l_stmt_num NUMBER := 0;
747 l_api_message VARCHAR2(1000);
748
749 l_full_name CONSTANT VARCHAR2(60) := g_pkg_name || '.' || l_api_name;
750 l_module constant varchar2(60) := 'po.plsql.'||l_full_name;
751
752 l_uLog CONSTANT BOOLEAN := fnd_log.level_unexpected >= g_log_level AND
753 fnd_log.TEST(fnd_log.level_unexpected, l_module);
754 l_pLog constant boolean := l_uLog and (FND_LOG.LEVEL_PROCEDURE >= G_LOG_LEVEL);
755
756 BEGIN
757 l_return_status := fnd_api.g_ret_sts_success;
758 -- Standard start of API savepoint
759 SAVEPOINT Get_InvTransactionInfo_GRP;
760
761 l_stmt_num := 0;
762
763 IF l_pLog THEN
764 IF (FND_LOG.G_CURRENT_RUNTIME_LEVEL <= FND_LOG.LEVEL_PROCEDURE) THEN
765 FND_LOG.string(FND_LOG.LEVEL_PROCEDURE,G_LOG_HEAD || '.'||l_api_name||'.begin'
766 ,'Get_InvTransactionInfo <<');
767 END IF;
768 END IF;
769
770 -- Standard call to check for call compatibility
771 IF NOT FND_API.Compatible_API_Call (
772 l_api_version,
773 p_api_version,
774 l_api_name,
775 G_PKG_NAME ) THEN
776 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
777 END IF;
778
779 -- Initialize message list if p_init_msg_list is set to TRUE
780 IF FND_API.to_Boolean(p_init_msg_list) THEN
781 FND_MSG_PUB.initialize;
782 END IF;
783
784 -- Initialize API return status to success
785 x_return_status := FND_API.G_RET_STS_SUCCESS;
786
787 --- Initialize Output Variables
788 x_intercompany_pricing_option := 1;
789 x_distribution_acct_id := -1;
790
791 l_stmt_num := 10;
792 RCV_AccEvents_PVT.Get_InvTransactionInfo(
793 p_api_version => 1.0,
794 x_return_status => l_return_status,
795 x_msg_count => l_msg_count,
796 x_msg_data => l_msg_data,
797 p_rcv_transaction_id => p_rcv_transaction_id,
798 x_intercompany_pricing_option => x_intercompany_pricing_option,
799 x_transfer_price => x_transfer_price,
800 x_currency_code => x_currency_code,
801 x_currency_conversion_rate => x_currency_conversion_rate,
802 x_currency_conversion_date => x_currency_conversion_date,
803 x_currency_conversion_type => x_currency_conversion_type,
804 x_distribution_acct_id => x_distribution_acct_id);
805
806 --- Standard check of p_commit
807 IF FND_API.to_Boolean(p_commit) THEN
808 COMMIT WORK;
809 END IF;
810
811 -- Standard Call to get message count and if count = 1, get message info
812 FND_MSG_PUB.Count_And_Get (
813 p_count => x_msg_count,
814 p_data => x_msg_data );
815
816 IF l_pLog THEN
817 IF (FND_LOG.G_CURRENT_RUNTIME_LEVEL <= FND_LOG.LEVEL_PROCEDURE) THEN
818 FND_LOG.string(FND_LOG.LEVEL_PROCEDURE,G_LOG_HEAD || '.'||l_api_name||'.end'
819 ,'Get_InvTransactionInfo >>');
820 END IF;
821 END IF;
822
823 EXCEPTION
824 WHEN FND_API.g_exc_error THEN
825 ROLLBACK TO Get_InvTransactionInfo_GRP;
826 x_return_status := FND_API.g_ret_sts_error;
827 FND_MSG_PUB.count_and_get
828 ( p_count => x_msg_count
829 , p_data => x_msg_data
830 );
831
832 WHEN FND_API.g_exc_unexpected_error THEN
833 ROLLBACK TO Get_InvTransactionInfo_GRP;
834 x_return_status := FND_API.g_ret_sts_unexp_error ;
835 FND_MSG_PUB.count_and_get
836 ( p_count => x_msg_count
837 , p_data => x_msg_data
838 );
839
840 WHEN OTHERS THEN
841 ROLLBACK TO Get_InvTransactionInfo_GRP;
842 x_return_status := fnd_api.g_ret_sts_unexp_error ;
843
844 IF l_uLog THEN
845 IF (FND_LOG.G_CURRENT_RUNTIME_LEVEL <= FND_LOG.LEVEL_UNEXPECTED) THEN
846 FND_LOG.string(FND_LOG.LEVEL_UNEXPECTED,G_LOG_HEAD || '.'||l_api_name||'.'||l_stmt_num
847 ,'Get_InvTransactionInfo : '||l_stmt_num||' : '||substr(SQLERRM,1,200));
848 END IF;
849 END IF;
850
851 IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error)
852 THEN
853 FND_MSG_PUB.add_exc_msg
854 ( G_PKG_NAME,
855 l_api_name || 'Statement -'||to_char(l_stmt_num)
856 );
857 END IF;
858 FND_MSG_PUB.count_and_get
859 ( p_count => x_msg_count
860 , p_data => x_msg_data
861 );
862
863
864 END Get_InvTransactionInfo;
865
866 END RCV_AccrualAccounting_GRP;