[Home] [Help]
PACKAGE BODY: APPS.RCV_ACCEVENTS_PVT
Source
1 PACKAGE BODY RCV_AccEvents_PVT AS
2 /* $Header: RCVVRAEB.pls 120.6.12010000.2 2008/11/10 14:40:32 mpuranik ship $ */
3
4 G_PKG_NAME CONSTANT VARCHAR2(30) := 'RCV_AccEvents_PVT';
5 G_DEBUG CONSTANT VARCHAR2(1) := NVL(FND_PROFILE.VALUE('AFLOG_ENABLED'),'N');
6 G_LOG_HEAD CONSTANT VARCHAR2(40) := 'po.plsql.'||G_PKG_NAME;
7
8 -- Start of comments
9 -- API name : Create_ReceivingEvents
10 -- Type : Private
11 -- Function : To seed accounting events for receiving transactions
12 -- Pre-reqs :
13 -- Parameters :
14 -- IN : p_api_version IN NUMBER Required
15 -- p_init_msg_list IN VARCHAR2 Optional
16 -- Default = FND_API.G_FALSE
17 -- p_commit IN VARCHAR2 Optional
18 -- Default = FND_API.G_FALSE
19 -- p_validation_level IN NUMBER Optional
20 -- Default = FND_API.G_VALID_LEVEL_FULL
21 -- p_rcv_transaction_id IN NUMBER Optional
22 -- p_direct_delivery_flag IN VARCHAR2 Required
23 --
24 -- OUT : x_return_status OUT VARCHAR2(1)
25 -- x_msg_count OUT NUMBER
26 -- x_msg_data OUT VARCHAR2(2000)
27 -- Version :
28 -- Initial version 1.0
29 --
30 -- Notes : This API creates all accounting events for receiving transactions
31 -- in RCV_ACCOUNTING_EVENTS. For online accruals, it also generates
32 -- the accounting entries for the event.
33 --
34 -- End of comments
35 -------------------------------------------------------------------------------
36 PROCEDURE Create_ReceivingEvents(
37 p_api_version IN NUMBER,
38 p_init_msg_list IN VARCHAR2 ,
39 p_commit IN VARCHAR2 ,
40 p_validation_level IN NUMBER ,
41 x_return_status OUT NOCOPY VARCHAR2,
42 x_msg_count OUT NOCOPY NUMBER,
43 x_msg_data OUT NOCOPY VARCHAR2,
44
45 p_rcv_transaction_id IN NUMBER,
46 p_direct_delivery_flag IN VARCHAR2
47 ) IS
48 l_api_name CONSTANT VARCHAR2(30) := 'Create_ReceivingEvent';
49 l_api_version CONSTANT NUMBER := 1.0;
50
51 l_return_status VARCHAR2(1) := fnd_api.g_ret_sts_success;
52 l_msg_count NUMBER := 0;
53 l_msg_data VARCHAR2(8000) := '';
54 l_stmt_num NUMBER := 0;
55 l_api_message VARCHAR2(1000);
56
57 l_err_num NUMBER;
58 l_err_code VARCHAR2(240);
59 l_err_msg VARCHAR2(240);
60 l_return_code NUMBER;
61
62 l_consigned_flag RCV_TRANSACTIONS.consigned_flag%TYPE;
63 l_source_doc_code RCV_TRANSACTIONS.source_document_code%TYPE;
64 l_transaction_type RCV_TRANSACTIONS.transaction_type%TYPE;
65 l_parent_trx_id RCV_TRANSACTIONS.transaction_id%TYPE;
66 l_parent_trx_type RCV_TRANSACTIONS.transaction_type%TYPE;
67 l_grparent_trx_id RCV_TRANSACTIONS.transaction_id%TYPE;
68 l_grparent_trx_type RCV_TRANSACTIONS.transaction_type%TYPE;
69 l_po_header_id PO_HEADERS_ALL.po_header_id%TYPE;
70
71 -- 12i Complex Work Procurement -------------------------------------------
72 l_po_line_location_id PO_LINE_LOCATIONS_ALL.line_location_id%TYPE;
73 l_shipment_type PO_LINE_LOCATIONS_ALL.shipment_type%TYPE;
74 ---------------------------------------------------------------------------
75
76 l_opm_flag NUMBER;
77 l_cr_flag BOOLEAN;
78 l_user_id NUMBER;
79
80
81 BEGIN
82 -- Standard start of API savepoint
83 SAVEPOINT Create_ReceivingEvents_PVT;
84
85 l_stmt_num := 0;
86
87 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
88 FND_LOG.string(FND_LOG.LEVEL_PROCEDURE,G_LOG_HEAD || '.'||l_api_name||'.begin'
89 ,'Create_ReceivingEvents <<');
90 END IF;
91
92 -- Standard call to check for call compatibility
93 IF NOT FND_API.Compatible_API_Call (
94 l_api_version,
95 p_api_version,
96 l_api_name,
97 G_PKG_NAME ) THEN
98 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
99 END IF;
100
101 -- Initialize message list if p_init_msg_list is set to TRUE
102 IF FND_API.to_Boolean(p_init_msg_list) THEN
103 FND_MSG_PUB.initialize;
104 END IF;
105
106 -- Initialize API return status to success
107 x_return_status := FND_API.G_RET_STS_SUCCESS;
108
109 l_stmt_num := 20;
110 -- Check if accrual is disabled.
111 l_return_code := CSTRVHKS.disable_accrual(l_err_num,
112 l_err_code,
113 l_err_msg);
114 IF(l_return_code = -999) THEN
115 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_ERROR >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
116 FND_LOG.message(FND_LOG.LEVEL_ERROR,G_LOG_HEAD || '.'||l_api_name||l_stmt_num,FALSE);
117 END IF;
118 RAISE FND_API.g_exc_unexpected_error;
119 ELSIF (l_return_code = 1) THEN
120 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
121 FND_LOG.string(FND_LOG.LEVEL_STATEMENT,G_LOG_HEAD||'.'||l_api_name||'.'||l_stmt_num
122 ,'Accrual has been disabled.');
123 END IF;
124 return;
125 END IF;
126
127
128 -- If OPM PO and Common Purchasing is installed, we do not do any
129 -- accounting.
130 l_stmt_num := 30;
131 l_opm_flag := GML_OPM_PO.check_opm_po(l_po_header_id);
132
133 l_stmt_num := 40;
134 l_cr_flag := GML_PO_FOR_PROCESS.check_po_for_proc;
135
136 IF (l_opm_flag = 1 AND l_cr_flag = FALSE) THEN
137 return;
138 END IF;
139
140 l_stmt_num := 50;
141 SELECT RT.consigned_flag,
142 RT.source_document_code,
143 RT.transaction_type,
144 RT.parent_transaction_id,
145 RT.po_header_id,
146 RT.po_line_location_id --12i Complex Work Procurement
147 INTO l_consigned_flag,
148 l_source_doc_code,
149 l_transaction_type,
150 l_parent_trx_id,
151 l_po_header_id,
152 l_po_line_location_id --12i Complex Work Procurement
153 FROM rcv_transactions RT
154 WHERE transaction_id = p_rcv_transaction_id;
155
156 -- If receiving transaction is for a REQ, or an RMA, we do not
157 -- do not do any accounting.
158 IF(l_source_doc_code <> 'PO') THEN
159 return;
160 END IF;
161
162 IF(l_transaction_type IN ('UNORDERED','ACCEPT','REJECT','TRANSFER')) THEN
163 return;
164 END IF;
165
166 IF(l_parent_trx_id NOT IN (0,-1)) THEN
167 l_stmt_num := 60;
168 -- Get Parent Transaction Type
169 SELECT transaction_type, parent_transaction_id
170 INTO l_parent_trx_type, l_grparent_trx_id
171 FROM rcv_transactions
172 WHERE transaction_id = l_parent_trx_id;
173
174 IF(l_grparent_trx_id NOT IN (0,-1)) THEN
175 l_stmt_num := 70;
176 -- Get Grand Parent Transaction Type
177 SELECT transaction_type
178 INTO l_grparent_trx_type
179 FROM rcv_transactions
180 WHERE transaction_id = l_grparent_trx_id;
181 END IF;
182 END IF;
183
184 IF((l_transaction_type = 'CORRECT' OR l_transaction_type = 'RETURN TO VENDOR') AND
185 (l_parent_trx_type = 'UNORDERED')) THEN
186 return;
187 END IF;
188
189 IF((l_transaction_type = 'CORRECT') AND
190 (l_parent_trx_type = 'RETURN TO VENDOR') AND
191 (l_grparent_trx_type = 'UNORDERED')) THEN
192 return;
193 END IF;
194
195 -- R12: Complex Work Procurement
196 -- Exclude any transactions whose POLL.shipment_type = 'PREPAYMENT'.
197 SELECT shipment_type
198 INTO l_shipment_type
199 FROM po_line_locations
200 WHERE line_location_id = l_po_line_location_id;
201
202 IF (l_shipment_type = 'PREPAYMENT') THEN
203 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
204 FND_LOG.string(FND_LOG.LEVEL_STATEMENT,G_LOG_HEAD || '.'||l_api_name,
205 'Shipment Type is Prepayment. No Receive Events created');
206 END IF;
207 return;
208 END IF;
209
210 IF((l_transaction_type = 'RECEIVE') OR
211 (l_transaction_type = 'MATCH') OR
212 (l_transaction_type = 'CORRECT' AND l_parent_trx_type = 'RECEIVE') OR
213 (l_transaction_type = 'CORRECT' AND l_parent_trx_type = 'MATCH')) THEN
214 l_stmt_num := 80;
215 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
216 FND_LOG.string(FND_LOG.LEVEL_EVENT,G_LOG_HEAD||'.'||l_api_name||'.'||l_stmt_num
217 ,'Creating Events For RECEIVE transaction');
218 END IF;
219
220 RCV_AccEvents_PVT.Create_ReceiveEvents(
221 p_api_version => 1.0,
222 x_return_status => l_return_status,
223 x_msg_count => l_msg_count,
224 x_msg_data => l_msg_data,
225 p_rcv_transaction_id => p_rcv_transaction_id,
226 p_direct_delivery_flag => p_direct_delivery_flag );
227 ELSIF((l_transaction_type = 'DELIVER')OR
228 (l_transaction_type = 'CORRECT' AND l_parent_trx_type = 'DELIVER')) THEN
229 l_stmt_num := 90;
230 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
231 FND_LOG.string(FND_LOG.LEVEL_EVENT,G_LOG_HEAD||'.'||l_api_name||'.'||l_stmt_num
232 ,'Creating Events For DELIVER transaction');
233 END IF;
234
235 RCV_AccEvents_PVT.Create_DeliverEvents(
236 p_api_version => 1.0,
237 x_return_status => l_return_status,
238 x_msg_count => l_msg_count,
239 x_msg_data => l_msg_data,
240 p_rcv_transaction_id => p_rcv_transaction_id,
241 p_direct_delivery_flag => p_direct_delivery_flag );
242
243 ELSIF ((l_transaction_type = 'RETURN TO RECEIVING') OR
244 (l_transaction_type = 'CORRECT' AND l_parent_trx_type = 'RETURN TO RECEIVING')) THEN
245 l_stmt_num := 100;
246 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
247 FND_LOG.string(FND_LOG.LEVEL_EVENT,G_LOG_HEAD||'.'||l_api_name||'.'||l_stmt_num
248 ,'Creating Events For RETURN TO RECEIVING transaction');
249 END IF;
250
251 RCV_AccEvents_PVT.Create_RTREvents(
252 p_api_version => 1.0,
253 x_return_status => l_return_status,
254 x_msg_count => l_msg_count,
255 x_msg_data => l_msg_data,
256 p_rcv_transaction_id => p_rcv_transaction_id,
257 p_direct_delivery_flag => p_direct_delivery_flag );
258 ELSIF ((l_transaction_type = 'RETURN TO VENDOR') OR
259 (l_transaction_type = 'CORRECT' AND l_parent_trx_type = 'RETURN TO VENDOR')) THEN
260 l_stmt_num := 110;
261 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
262 FND_LOG.string(FND_LOG.LEVEL_EVENT,G_LOG_HEAD||'.'||l_api_name||'.'||l_stmt_num
263 ,'Creating Events For RETURN TO VENDOR transaction');
264 END IF;
265
266 RCV_AccEvents_PVT.Create_RTVEvents(
267 p_api_version => 1.0,
268 x_return_status => l_return_status,
269 x_msg_count => l_msg_count,
270 x_msg_data => l_msg_data,
271 p_rcv_transaction_id => p_rcv_transaction_id,
272 p_direct_delivery_flag => p_direct_delivery_flag );
273 END IF;
274
275 IF l_return_status <> FND_API.g_ret_sts_success THEN
276 l_api_message := 'Error creating event';
277 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_UNEXPECTED >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
278 FND_LOG.string(FND_LOG.LEVEL_UNEXPECTED,G_LOG_HEAD || '.'||l_api_name||l_stmt_num
279 ,'Create_ReceivingEvents : '||l_stmt_num||' : '||l_api_message);
280 END IF;
281 RAISE FND_API.g_exc_unexpected_error;
282 END IF;
283
284
285 l_stmt_num := 120;
286 --- Standard check of p_commit
287 IF FND_API.to_Boolean(p_commit) THEN
288 COMMIT WORK;
289 END IF;
290
291 -- Standard Call to get message count and if count = 1, get message info
292 FND_MSG_PUB.Count_And_Get (
293 p_count => x_msg_count,
294 p_data => x_msg_data );
295
296 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
297 FND_LOG.string(FND_LOG.LEVEL_PROCEDURE,G_LOG_HEAD || '.'||l_api_name||'.end'
298 ,'Create_ReceivingEvents>>');
299 END IF;
300
301 EXCEPTION
302 WHEN FND_API.g_exc_error THEN
303 ROLLBACK TO Create_ReceivingEvents_PVT;
304 x_return_status := FND_API.g_ret_sts_error;
305 FND_MSG_PUB.count_and_get
306 ( p_count => x_msg_count
307 , p_data => x_msg_data
308 );
309 WHEN FND_API.g_exc_unexpected_error THEN
310 ROLLBACK TO Create_ReceivingEvents_PVT;
311 x_return_status := FND_API.g_ret_sts_unexp_error ;
312 FND_MSG_PUB.count_and_get
313 ( p_count => x_msg_count
314 , p_data => x_msg_data
315 );
316
317 WHEN OTHERS THEN
318 ROLLBACK TO Create_ReceivingEvents_PVT;
319 x_return_status := fnd_api.g_ret_sts_unexp_error ;
320
321 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_UNEXPECTED >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
322 FND_LOG.string(FND_LOG.LEVEL_UNEXPECTED,G_LOG_HEAD || '.'||l_api_name||l_stmt_num
323 ,'Create_ReceivingEvents : '||l_stmt_num||' : '||substr(SQLERRM,1,200));
324 END IF;
325
326 IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error)
327 THEN
328 FND_MSG_PUB.add_exc_msg
329 ( G_PKG_NAME,
330 l_api_name || 'Statement -'||to_char(l_stmt_num)
331 );
332 END IF;
333 FND_MSG_PUB.count_and_get
334 ( p_count => x_msg_count
335 , p_data => x_msg_data
336 );
337
338 END Create_ReceivingEvents;
339
340
341
342 -- API name : Create_AdjustEvents
343 -- Type : Private
344 -- Function : To seed accounting events for retroactive price adjustments.
345 -- Pre-reqs :
346 -- Parameters :
347 -- IN : p_api_version IN NUMBER Required
348 -- p_init_msg_list IN VARCHAR2 Optional
349 -- Default = FND_API.G_FALSE
350 -- p_commit IN VARCHAR2 Optional
351 -- Default = FND_API.G_FALSE
352 -- p_validation_level IN NUMBER Optional
353 -- Default = FND_API.G_VALID_LEVEL_FULL
354 -- p_po_header_id IN NUMBER Required
355 -- p_po_release_id IN NUMBER Optional
356 -- p_po_line_id IN NUMBER Optional
357 -- p_po_line_location_id IN NUMBER Required
358 -- p_old_po_price IN NUMBER Required
359 -- p_new_po_price IN NUMBER Required
360 --
361 -- OUT : x_return_status OUT VARCHAR2(1)
362 -- x_msg_count OUT NUMBER
363 -- x_msg_data OUT VARCHAR2(2000)
364 -- Version :
365 -- Initial version 1.0
366 --
367 -- Notes : This API creates all accounting events for retroactive price adjustments
368 -- in RCV_ACCOUNTING_EVENTS. For online accruals, it also generates
369 -- the accounting entries for the event.
370 --
371 -- End of comments
372 -------------------------------------------------------------------------------
373 PROCEDURE Create_AdjustEvents(
374 p_api_version IN NUMBER,
375 p_init_msg_list IN VARCHAR2,
376 p_commit IN VARCHAR2,
377 p_validation_level IN NUMBER,
378 x_return_status OUT NOCOPY VARCHAR2,
379 x_msg_count OUT NOCOPY NUMBER,
380 x_msg_data OUT NOCOPY VARCHAR2,
381
382 p_po_header_id IN NUMBER,
383 p_po_release_id IN NUMBER,
384 p_po_line_id IN NUMBER,
385 p_po_line_location_id IN NUMBER,
386 p_old_po_price IN NUMBER,
387 p_new_po_price IN NUMBER
388
389 ) IS
390 l_api_name CONSTANT VARCHAR2(30) := 'Create_AdjustEvents';
391 l_api_version CONSTANT NUMBER := 1.0;
392
393 l_return_status VARCHAR2(1) := fnd_api.g_ret_sts_success;
394 l_msg_count NUMBER := 0;
395 l_msg_data VARCHAR2(8000) := '';
396 l_stmt_num NUMBER := 0;
397 l_api_message VARCHAR2(1000);
398
399 l_rcv_event RCV_SeedEvents_PVT.rcv_event_rec_type;
400 l_rcv_events_tbl RCV_SeedEvents_PVT.rcv_event_tbl_type;
401 l_rae_count NUMBER;
402
403 -- 12i Complex Work Procurement------------------------------------
404 l_matching_basis PO_LINE_LOCATIONS.matching_basis%TYPE;
405 l_shipment_type PO_LINE_LOCATIONS.shipment_type%TYPE;
406 -------------------------------------------------------------------
407 l_proc_operating_unit NUMBER;
408 l_po_distribution_id NUMBER;
409 l_organization_id NUMBER;
410 l_rcv_quantity NUMBER := 0;
411 l_delived_quantity NUMBER := 0;
412
413 l_trx_flow_header_id NUMBER := NULL;
414 l_drop_ship_flag NUMBER := NULL;
415 l_opm_flag NUMBER;
416 l_cr_flag BOOLEAN;
417
418
419 -- Cursor to get all parent receive transactions
420 -- for a given po_header or po_release
421
422 CURSOR c_parent_receive_txns_csr IS
423 SELECT transaction_id, organization_id
424 FROM rcv_transactions
425 WHERE ( ( transaction_type = 'RECEIVE'
426 and parent_transaction_id = -1 )
427 or
428 transaction_type = 'MATCH' )
429 AND NVL(consigned_flag,'N') <> 'Y'
430 AND po_header_id = p_po_header_id
431 AND po_line_location_id = p_po_line_location_id
432 AND NVL(po_release_id, -1) = NVL(p_po_release_id, -1);
433
434 -- Cursor to get all deliver transactions for
435 -- a parent receive transaction.
436
437 CURSOR c_deliver_txns_csr (l_par_txn IN NUMBER) IS
438 SELECT transaction_id, po_distribution_id
439 FROM rcv_transactions
440 WHERE transaction_type = 'DELIVER'
441 START WITH transaction_id = l_par_txn
442 CONNECT BY parent_transaction_id = prior transaction_id;
443
444 -- Cursor to get all distributions corresponding
445 -- to a po_line_location.
446 -- The PO line location corresponds to the parent rcv_transaction
447
448 CURSOR c_po_dists_csr (l_rcv_txn IN NUMBER) IS
449 SELECT POD.po_distribution_id
450 FROM po_distributions POD,
451 po_line_locations POLL,
452 rcv_transactions RT
453 WHERE POD.line_location_id = POLL.line_location_id
454 AND POLL.line_location_id = RT.po_line_location_id
455 AND RT.transaction_id = l_rcv_txn;
456
457
458 BEGIN
459
460 -- Standard start of API savepoint
461 SAVEPOINT Create_AdjustEvents_PVT;
462
463 l_stmt_num := 0;
464
465 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
466 FND_LOG.string(FND_LOG.LEVEL_PROCEDURE,G_LOG_HEAD || '.'||l_api_name||'.begin'
467 ,'Create_AdjustEvent <<');
468 END IF;
469
470 -- Standard call to check for call compatibility
471 IF NOT FND_API.Compatible_API_Call (
472 l_api_version,
473 p_api_version,
474 l_api_name,
475 G_PKG_NAME ) THEN
476 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
477 END IF;
478
479 -- Initialize message list if p_init_msg_list is set to TRUE
480 IF FND_API.to_Boolean(p_init_msg_list) THEN
481 FND_MSG_PUB.initialize;
482
483 END IF;
484 -- Initialize API return status to success
485 x_return_status := FND_API.G_RET_STS_SUCCESS;
486
487 -- If the old and new price are the same, return
488 IF p_old_po_price = p_new_po_price THEN
489 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
490 FND_LOG.string(FND_LOG.LEVEL_STATEMENT,G_LOG_HEAD || '.'||l_api_name,
491 'Old and New Prices are same. No Adjust Events created');
492 END IF;
493 RETURN;
494 END IF;
495
496 -- If OPM PO and Common Purchasing is installed, we do not do any
497 -- accounting.
498 l_stmt_num := 5;
499 l_opm_flag := GML_OPM_PO.check_opm_po(p_po_header_id);
500
501 l_stmt_num := 10;
502 l_cr_flag := GML_PO_FOR_PROCESS.check_po_for_proc;
503
504 IF (l_opm_flag = 1 AND l_cr_flag = FALSE) THEN
505 return;
506 END IF;
507
508 l_stmt_num := 20;
509
510 -- Get Matching Basis and Shipment Type
511 SELECT POLL.matching_basis, POLL.shipment_type
512 INTO l_matching_basis, l_shipment_type
513 FROM po_line_locations POLL
514 WHERE POLL.line_location_id = p_po_line_location_id;
515
516 l_stmt_num := 30;
517
518 -- If Line Type is Service (matching basis = AMOUNT), then return without doing anything
519 IF (l_matching_basis is not null and l_matching_basis = 'AMOUNT') THEN
520 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
521 FND_LOG.string(FND_LOG.LEVEL_STATEMENT,G_LOG_HEAD || '.'||l_api_name,
522 'Service Line Type. No Adjust Events created');
523 END IF;
524 return;
525 END IF;
526
527 l_stmt_num := 35;
528
529 -- If Shipment Type is Prepayment, then return without doing anything
530 IF (l_shipment_type = 'PREPAYMENT') THEN
531 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
532 FND_LOG.string(FND_LOG.LEVEL_STATEMENT,G_LOG_HEAD || '.'||l_api_name,
533 'Shipment Type is Prepayment. No Adjust Events created');
534 END IF;
535 return;
536 END IF;
537
538 l_stmt_num := 40;
539
540 -- Get Procuring operating unit
541 SELECT org_id
542 INTO l_proc_operating_unit
543 FROM po_headers
544 WHERE po_header_id = p_po_header_id;
545
546
547 -- Loop Through all Parent Transactions
548
549 FOR c_par_txn IN c_parent_receive_txns_csr LOOP
550
551 -- Get the Organization in which event is to be seeded
552 -- Get the row in RAE with the RCV_TRANSACTION as that of the parent txn
553 -- and procurement_org_flag = 'Y'
554
555 l_stmt_num := 50;
556
557 SELECT count(*)
558 INTO l_rae_count
559 FROM rcv_accounting_events
560 WHERE rcv_transaction_id = c_par_txn.transaction_id;
561
562 IF l_rae_count > 0 THEN
563
564 -- Rownum check is there since there might be multiple events in
565 -- RAE for a particular Receive transaction in RCV_TRANSACTIONS
566
567 l_stmt_num := 60;
568
569 SELECT RAE.organization_id, RAE.trx_flow_header_id, NVL(RT.dropship_type_code,3)
570 INTO l_organization_id, l_trx_flow_header_id,l_drop_ship_flag
571 FROM rcv_accounting_events RAE,
572 rcv_transactions RT
573 WHERE RAE.rcv_transaction_id = c_par_txn.transaction_id
574 AND RT.transaction_id = RAE.rcv_transaction_id
575 AND RAE.procurement_org_flag = 'Y'
576 AND rownum = 1;
577 ELSE
578 l_organization_id := c_par_txn.organization_id;
579 END IF;
580
581
582 -- One event is seeded per PO distribution
583 -- If RCV_TRANSACTIONS has the po_distribution_id populated, we
584 -- use that. Otherwise, we use cursor c_po_dists_csr to seed as many events
585 -- as the number of distributions for the line_location
586
587 l_stmt_num := 70;
588
589 SELECT nvl(po_distribution_id, -1)
590 INTO l_po_distribution_id
591 FROM rcv_transactions
592 WHERE transaction_id = c_par_txn.transaction_id;
593
594
595 IF l_po_distribution_id <> -1 THEN
596
597 l_stmt_num := 80;
598
599 RCV_SeedEvents_PVT.Seed_RAEEvent(
600 p_api_version => 1.0,
601 x_return_status => l_return_status,
602 x_msg_count => l_msg_count,
603 x_msg_data => l_msg_data,
604 p_event_source => 'RETROPRICE',
605 p_event_type_id => RCV_SeedEvents_PVT.ADJUST_RECEIVE,
606 p_rcv_transaction_id => c_par_txn.transaction_id,
607 p_inv_distribution_id => NULL,
608 p_po_distribution_id => l_po_distribution_id,
609 p_direct_delivery_flag => NULL,
610 p_cross_ou_flag => NULL,
611 p_procurement_org_flag => 'Y',
612 p_ship_to_org_flag => NULL,
613 p_drop_ship_flag => l_drop_ship_flag,
614 p_org_id => l_proc_operating_unit,
615 p_organization_id => l_organization_id,
616 p_transfer_org_id => NULL,
617 p_transfer_organization_id => NULL,
618 p_trx_flow_header_id => l_trx_flow_header_id,
619 p_transaction_forward_flow_rec => NULL,
620 p_transaction_reverse_flow_rec => NULL,
621 p_unit_price => p_new_po_price,
622 p_prior_unit_price => p_old_po_price,
623 /* Support for Landed Cost Management */
624 p_lcm_flag => 'N',
625 x_rcv_event => l_rcv_event);
626
627 -- Suppose there is no net quantity for this receipt (all received quantity has been
628 -- returned), there is no need to seed an event, since there is no accrual to adjust.
629 -- If transaction quantity is 0, the Seed_RAEEvent API will return a warning. In the
630 -- case of Adjust events, this warning is normal and should be ignored.
631 IF (l_return_status = FND_API.G_RET_STS_SUCCESS) THEN
632 l_rcv_events_tbl(l_rcv_events_tbl.count + 1) := l_rcv_event;
633 ELSIF (l_return_status <> 'W') THEN
634 l_api_message := 'Error seeding event';
635 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_UNEXPECTED >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
636 FND_LOG.string(FND_LOG.LEVEL_UNEXPECTED,G_LOG_HEAD || '.'||l_api_name||l_stmt_num
637 ,'Create_AdjustEvents : '||l_stmt_num||' : '||l_api_message);
638 END IF;
639 RAISE FND_API.g_exc_unexpected_error;
640 END IF;
641
642 ELSE
643
644 FOR c_po_dist IN c_po_dists_csr (c_par_txn.transaction_id) LOOP
645 l_stmt_num := 90;
646
647 RCV_SeedEvents_PVT.Seed_RAEEvent(
648 p_api_version => 1.0,
649 x_return_status => l_return_status,
650 x_msg_count => l_msg_count,
651 x_msg_data => l_msg_data,
652 p_event_source => 'RETROPRICE',
653 p_event_type_id => RCV_SeedEvents_PVT.ADJUST_RECEIVE,
654 p_rcv_transaction_id => c_par_txn.transaction_id,
655 p_inv_distribution_id => NULL,
656 p_po_distribution_id => c_po_dist.po_distribution_id,
657 p_direct_delivery_flag => NULL,
658 p_cross_ou_flag => NULL,
659 p_procurement_org_flag => 'Y',
660 p_ship_to_org_flag => NULL,
661 p_drop_ship_flag => l_drop_ship_flag,
662 p_org_id => l_proc_operating_unit,
663 p_organization_id => l_organization_id,
664 p_transfer_org_id => NULL,
665 p_transfer_organization_id => NULL,
666 p_trx_flow_header_id => l_trx_flow_header_id,
667 p_transaction_forward_flow_rec => NULL,
668 p_transaction_reverse_flow_rec => NULL,
669 p_unit_price => p_new_po_price,
670 p_prior_unit_price => p_old_po_price,
671 /* Support for Landed Cost Management */
672 p_lcm_flag => 'N',
673 x_rcv_event => l_rcv_event);
674
675 -- Suppose there is no net quantity for this receipt (all received quantity has been
676 -- returned), there is no need to seed an event, since there is no accrual to adjust.
677 -- If transaction quantity is 0, the Seed_RAEEvent API will return a warning. In the
678 -- case of Adjust events, this warning is normal and should be ignored.
679 IF (l_return_status = FND_API.G_RET_STS_SUCCESS) THEN
680 l_rcv_events_tbl(l_rcv_events_tbl.count + 1) := l_rcv_event;
681 ELSIF (l_return_status <> 'W') THEN
682 l_api_message := 'Error seeding event';
683 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_UNEXPECTED >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
684 FND_LOG.string(FND_LOG.LEVEL_UNEXPECTED,G_LOG_HEAD || '.'||l_api_name||l_stmt_num
685 ,'Create_AdjustEvents : '||l_stmt_num||' : '||l_api_message);
686 END IF;
687 RAISE FND_API.g_exc_unexpected_error;
688 END IF;
689 END LOOP;
690
691 END IF;
692
693 -- Adjust Deliver events are not created for global procurement scenarios.
694 IF (l_trx_flow_header_id IS NULL AND (l_drop_ship_flag IS NULL or l_drop_ship_flag NOT IN (1,2))) THEN
695
696 l_stmt_num := 100;
697
698 FOR c_del_txn IN c_deliver_txns_csr(c_par_txn.transaction_id) LOOP
699 RCV_SeedEvents_PVT.Seed_RAEEvent(
700 p_api_version => 1.0,
701 x_return_status => l_return_status,
702 x_msg_count => l_msg_count,
703 x_msg_data => l_msg_data,
704 p_event_source => 'RETROPRICE',
705 p_event_type_id => RCV_SeedEvents_PVT.ADJUST_DELIVER,
706 p_rcv_transaction_id => c_del_txn.transaction_id,
707 p_inv_distribution_id => NULL,
708 p_po_distribution_id => c_del_txn.po_distribution_id,
709 p_direct_delivery_flag => NULL,
710 p_cross_ou_flag => NULL,
711 p_procurement_org_flag => 'Y',
712 p_ship_to_org_flag => NULL,
713 p_drop_ship_flag => l_drop_ship_flag,
714 p_org_id => l_proc_operating_unit,
715 p_organization_id => l_organization_id,
716 p_transfer_org_id => NULL,
717 p_transfer_organization_id => NULL,
718 p_trx_flow_header_id => l_trx_flow_header_id,
719 p_transaction_forward_flow_rec => NULL,
720 p_transaction_reverse_flow_rec => NULL,
721 p_unit_price => p_new_po_price,
722 p_prior_unit_price => p_old_po_price,
723 /* Support for Landed Cost Management */
724 p_lcm_flag => 'N',
725 x_rcv_event => l_rcv_event);
726
727 -- Suppose there is no net quantity for this deliver (all delivered quantity has been
728 -- returned), there is no need to seed an event, since there is no accrual to adjust.
729 -- If transaction quantity is 0, the Seed_RAEEvent API will return a warning. In the
730 -- case of Adjust events, this warning is normal and should be ignored.
731 IF (l_return_status = FND_API.G_RET_STS_SUCCESS) THEN
732 l_rcv_events_tbl(l_rcv_events_tbl.count + 1) := l_rcv_event;
733 ELSIF (l_return_status <> 'W') THEN
734 l_api_message := 'Error seeding event';
735 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_UNEXPECTED >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
736 FND_LOG.string(FND_LOG.LEVEL_UNEXPECTED,G_LOG_HEAD || '.'||l_api_name||l_stmt_num
737 ,'Create_AdjustEvents : '||l_stmt_num||' : '||l_api_message);
738 END IF;
739 RAISE FND_API.g_exc_unexpected_error;
740 END IF;
741
742 END LOOP; -- C_DEL_TXN
743
744 END IF; -- If Trx Flow does not exist
745
746 END LOOP; -- C_PAR_TXNS
747
748
749 IF (l_rcv_events_tbl.count > 0) THEN
750 -- Insert events into RCV_Accounting_Events
751 l_stmt_num := 110;
752 RCV_SeedEvents_PVT.Insert_RAEEvents(
753 p_api_version => 1.0,
754 x_return_status => l_return_status,
755 x_msg_count => l_msg_count,
756 x_msg_data => l_msg_data,
757 p_rcv_events_tbl => l_rcv_events_tbl,
758 /* Support for Landed Cost Management */
759 p_lcm_flag => 'N');
760
761 IF l_return_status <> FND_API.g_ret_sts_success THEN
762 l_api_message := 'Error inserting events into RAE';
763 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_UNEXPECTED >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
764 FND_LOG.string(FND_LOG.LEVEL_UNEXPECTED,G_LOG_HEAD || '.'||l_api_name||l_stmt_num
765 ,'Create_AdjustEvents : '||l_stmt_num||' : '||l_api_message);
766 END IF;
767 RAISE FND_API.g_exc_unexpected_error;
768 END IF;
769 END IF;
770
771
772 --- Standard check of p_commit
773 IF FND_API.to_Boolean(p_commit) THEN
774 COMMIT WORK;
775 END IF;
776
777 -- Standard Call to get message count and if count = 1, get message info
778 FND_MSG_PUB.Count_And_Get (
779 p_count => x_msg_count,
780 p_data => x_msg_data );
781
782 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
783 FND_LOG.string(FND_LOG.LEVEL_PROCEDURE,G_LOG_HEAD || '.'||l_api_name||'.end'
784 ,'Create_AdjustEvents >>');
785 END IF;
786
787 EXCEPTION
788 WHEN FND_API.g_exc_error THEN
789 ROLLBACK TO Create_AdjustEvents_PVT;
790 x_return_status := FND_API.g_ret_sts_error;
791 FND_MSG_PUB.count_and_get
792 ( p_count => x_msg_count
793 , p_data => x_msg_data
794 );
795 WHEN FND_API.g_exc_unexpected_error THEN
796 ROLLBACK TO Create_AdjustEvents_PVT;
797 x_return_status := FND_API.g_ret_sts_unexp_error ;
798 FND_MSG_PUB.count_and_get
799 ( p_count => x_msg_count
800 , p_data => x_msg_data
801 );
802
803 WHEN OTHERS THEN
804 ROLLBACK TO Create_AdjustEvents_PVT;
805 x_return_status := fnd_api.g_ret_sts_unexp_error ;
806
807 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_UNEXPECTED >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
808 FND_LOG.string(FND_LOG.LEVEL_UNEXPECTED,G_LOG_HEAD || '.'||l_api_name||l_stmt_num
809 ,'Create_AdjustEvent : '||l_stmt_num||' : '||substr(SQLERRM,1,200));
810 END IF;
811
812 IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error)
813 THEN
814 FND_MSG_PUB.add_exc_msg
815 ( G_PKG_NAME,
816 l_api_name || 'Statement -'||to_char(l_stmt_num)
817 );
818 END IF;
819 FND_MSG_PUB.count_and_get
820 ( p_count => x_msg_count
821 , p_data => x_msg_data
822 );
823
824 END Create_AdjustEvents;
825
826 -- Start of comments
827 -- API name : Create_ICEvents
828 -- Type : Private
829 -- Function : To seed Intercompany events for period end AP line matches.
830 -- Pre-reqs :
831 -- Parameters :
832 -- IN : p_api_version IN NUMBER Required
833 -- p_init_msg_list IN VARCHAR2 Optional
834 -- Default = FND_API.G_FALSE
835 -- p_commit IN VARCHAR2 Optional
836 -- Default = FND_API.G_FALSE
837 -- p_validation_level IN NUMBER Optional
838 -- Default = FND_API.G_VALID_LEVEL_FULL
839 -- p_invoice_distribution_id IN NUMBER Required
840 --
841 -- OUT : x_return_status OUT VARCHAR2(1)
842 -- x_msg_count OUT NUMBER
843 -- x_msg_data OUT VARCHAR2(2000)
844 -- Version :
845 -- Initial version 1.0
846 --
847 -- Notes : This API creates inter-company accounting events for AP line matches
848 -- in RCV_ACCOUNTING_EVENTS.
849 --
850 -- End of comments
851 -------------------------------------------------------------------------------
852 PROCEDURE Create_ICEvents(
853 p_api_version IN NUMBER,
854 p_init_msg_list IN VARCHAR2,
855 p_commit IN VARCHAR2,
856 p_validation_level IN NUMBER,
857 x_return_status OUT NOCOPY VARCHAR2,
858 x_msg_count OUT NOCOPY NUMBER,
859 x_msg_data OUT NOCOPY VARCHAR2,
860
861 p_invoice_distribution_id IN NUMBER
862 )IS
863 l_api_name CONSTANT VARCHAR2(30) := 'Create_ICEvents';
864 l_api_version CONSTANT NUMBER := 1.0;
865
866 l_return_status VARCHAR2(1) := fnd_api.g_ret_sts_success;
867 l_msg_count NUMBER := 0;
868 l_msg_data VARCHAR2(8000) := '';
869 l_stmt_num NUMBER := 0;
870 l_api_message VARCHAR2(1000);
871
872 l_rcv_event RCV_SeedEvents_PVT.rcv_event_rec_type;
873 l_rcv_events_tbl RCV_SeedEvents_PVT.rcv_event_tbl_type;
874 l_event_type_id NUMBER;
875
876 l_transaction_flows_tbl INV_TRANSACTION_FLOW_PUB.g_transaction_flow_tbl_type;
877 l_transaction_forward_flow_rec INV_TRANSACTION_FLOW_PUB.mtl_transaction_flow_rec_type;
878 l_transaction_reverse_flow_rec INV_TRANSACTION_FLOW_PUB.mtl_transaction_flow_rec_type;
879 l_trx_flow_exists_flag NUMBER := 0;
880 l_trx_flow_ctr NUMBER := 0;
881
882 l_po_header_id NUMBER;
883 l_po_distribution_id NUMBER;
884 l_po_org_id NUMBER;
885 l_rcv_organization_id NUMBER;
886 l_transfer_organization_id NUMBER;
887 l_rcv_org_id NUMBER;
888 l_org_id NUMBER;
889 l_event_date DATE;
890 l_drop_ship_flag NUMBER;
891 l_destination_type VARCHAR(25);
892 l_category_id NUMBER;
893 l_project_id NUMBER;
894 l_cross_ou_flag VARCHAR2(1);
895 l_accrual_flag VARCHAR2(1);
896 l_counter NUMBER;
897 l_procurement_org_flag VARCHAR2(1);
898 l_quantity_invoiced NUMBER;
899 l_order_type_lookup_code PO_LINES.ORDER_TYPE_LOOKUP_CODE%TYPE;
900 l_inv_amount NUMBER;
901 l_price_correction_flag VARCHAR2(1) := 'N';
902
903 l_qualifier_code_tbl INV_TRANSACTION_FLOW_PUB.NUMBER_TBL;
904 l_qualifier_value_tbl INV_TRANSACTION_FLOW_PUB.NUMBER_TBL;
905
906
907 BEGIN
908 -- Standard start of API savepoint
909 SAVEPOINT Create_ICEvents_PVT;
910
911 l_stmt_num := 0;
912
913 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
914 FND_LOG.string(FND_LOG.LEVEL_PROCEDURE,G_LOG_HEAD || '.'||l_api_name||'.begin'
915 ,'Create_ICEvents <<');
916 END IF;
917
918 -- Standard call to check for call compatibility
919 IF NOT FND_API.Compatible_API_Call (
920 l_api_version,
921 p_api_version,
922 l_api_name,
923 G_PKG_NAME ) THEN
924 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
925 END IF;
926
927 -- Initialize message list if p_init_msg_list is set to TRUE
928 IF FND_API.to_Boolean(p_init_msg_list) THEN
929 FND_MSG_PUB.initialize;
930 END IF;
931
932 -- Initialize API return status to success
933 x_return_status := FND_API.G_RET_STS_SUCCESS;
934
935 -- Stubbing out the code since AP will no longer be calling our API for period-end
936 -- accruals. This is due to changes to the design for global procurement using
937 -- period end accruals. Due to various constraints, it was decided that we will not
938 -- support period end accruals for global procurement. This check will be enforced
939 -- at the document level.
940
941 -- Standard Call to get message count and if count = 1, get message info
942 FND_MSG_PUB.Count_And_Get (
943 p_count => x_msg_count,
944 p_data => x_msg_data );
945
946 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
947 FND_LOG.string(FND_LOG.LEVEL_PROCEDURE,G_LOG_HEAD || '.'||l_api_name||'.end'
948 ,'Create_ICEvents >>');
949 END IF;
950
951 EXCEPTION
952 WHEN FND_API.g_exc_error THEN
953 ROLLBACK TO Create_ICEvents_PVT;
954 x_return_status := FND_API.g_ret_sts_error;
955 FND_MSG_PUB.count_and_get
956 ( p_count => x_msg_count
957 , p_data => x_msg_data
958 );
959 WHEN FND_API.g_exc_unexpected_error THEN
960 ROLLBACK TO Create_ICEvents_PVT;
961 x_return_status := FND_API.g_ret_sts_unexp_error ;
962 FND_MSG_PUB.count_and_get
963 ( p_count => x_msg_count
964 , p_data => x_msg_data
965 );
966
967 WHEN OTHERS THEN
968 ROLLBACK TO Create_ICEvents_PVT;
969 x_return_status := fnd_api.g_ret_sts_unexp_error ;
970
971 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_UNEXPECTED >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
972 FND_LOG.string(FND_LOG.LEVEL_UNEXPECTED,G_LOG_HEAD || '.'||l_api_name||l_stmt_num
973 ,'Create_ICEvents : '||l_stmt_num||' : '||substr(SQLERRM,1,200));
974 END IF;
975
976 IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error)
977 THEN
978 FND_MSG_PUB.add_exc_msg
979 ( G_PKG_NAME,
980 l_api_name || 'Statement -'||to_char(l_stmt_num)
981 );
982 END IF;
983 FND_MSG_PUB.count_and_get
984 ( p_count => x_msg_count
985 , p_data => x_msg_data
986 );
987
988 END Create_ICEvents;
989
990 -- Start of comments
991 -- API name : Create_ReceiveEvents
992 -- Type : Private
993 -- Function : To seed accounting events for RECEIVE transactions.
994 -- Pre-reqs :
995 -- Parameters :
996 -- IN : p_api_version IN NUMBER Required
997 -- p_init_msg_list IN VARCHAR2 Optional
998 -- Default = FND_API.G_FALSE
999 -- p_commit IN VARCHAR2 Optional
1000 -- Default = FND_API.G_FALSE
1001 -- p_validation_level IN NUMBER Optional
1002 -- Default = FND_API.G_VALID_LEVEL_FULL
1003 -- p_rcv_transaction_id IN NUMBER Required
1004 -- p_direct_delivery_flag IN VARCHAR2 Optional
1005 --
1006 -- OUT : x_return_status OUT VARCHAR2(1)
1007 -- x_msg_count OUT NUMBER
1008 -- x_msg_data OUT VARCHAR2(2000)
1009 -- Version :
1010 -- Initial version 1.0
1011 --
1012 -- Notes : This API creates all accounting events for RECEIVE transactions
1013 -- in RCV_ACCOUNTING_EVENTS.
1014 --
1015 -- End of comments
1016 -------------------------------------------------------------------------------
1017 PROCEDURE Create_ReceiveEvents(
1018 p_api_version IN NUMBER,
1019 p_init_msg_list IN VARCHAR2 ,
1020 p_commit IN VARCHAR2 ,
1021 p_validation_level IN NUMBER ,
1022 x_return_status OUT NOCOPY VARCHAR2,
1023 x_msg_count OUT NOCOPY NUMBER,
1024 x_msg_data OUT NOCOPY VARCHAR2,
1025
1026 p_rcv_transaction_id IN NUMBER,
1027 p_direct_delivery_flag IN VARCHAR2
1028 ) IS
1029 l_api_name CONSTANT VARCHAR2(30) := 'Create_ReceiveEvents';
1030 l_api_version CONSTANT NUMBER := 1.0;
1031
1032 l_return_status VARCHAR2(1) := fnd_api.g_ret_sts_success;
1033 l_msg_count NUMBER := 0;
1034 l_msg_data VARCHAR2(8000) := '';
1035 l_stmt_num NUMBER := 0;
1036 l_api_message VARCHAR2(1000);
1037
1038 l_rcv_event RCV_SeedEvents_PVT.rcv_event_rec_type;
1039 l_rcv_events_tbl RCV_SeedEvents_PVT.rcv_event_tbl_type;
1040 l_event_type_id NUMBER;
1041
1042
1043 l_transaction_flows_tbl INV_TRANSACTION_FLOW_PUB.g_transaction_flow_tbl_type;
1044 l_transaction_forward_flow_rec INV_TRANSACTION_FLOW_PUB.mtl_transaction_flow_rec_type;
1045 l_transaction_reverse_flow_rec INV_TRANSACTION_FLOW_PUB.mtl_transaction_flow_rec_type;
1046 l_trx_flow_exists_flag NUMBER := 0;
1047 l_trx_flow_ctr NUMBER := 0;
1048
1049
1050 l_po_header_id NUMBER;
1051 l_po_line_id NUMBER;
1052 l_po_line_location_id NUMBER;
1053 l_po_distribution_id NUMBER;
1054 l_po_org_id NUMBER;
1055 l_po_sob_id NUMBER;
1056 l_rcv_organization_id NUMBER;
1057 l_rcv_org_id NUMBER;
1058 l_rcv_sob_id NUMBER;
1059 l_org_id NUMBER;
1060 l_transfer_org_id NUMBER;
1061 l_transfer_organization_id NUMBER;
1062 l_rcv_trx_date DATE;
1063 l_drop_ship_flag NUMBER;
1064 l_destination_type VARCHAR(25);
1065 l_item_id NUMBER;
1066 l_category_id NUMBER;
1067 l_project_id NUMBER;
1068 l_cross_ou_flag VARCHAR2(1);
1069 l_accrual_flag VARCHAR2(1);
1070 l_counter NUMBER;
1071 l_procurement_org_flag VARCHAR2(1);
1072 l_trx_flow_header_id NUMBER;
1073 l_po_document_type_code PO_HEADERS_ALL.type_lookup_code%TYPE;
1074 l_is_shared_proc VARCHAR2(1);
1075 /* Support for Landed Cost Management */
1076 l_lcm_flag VARCHAR2(1);
1077
1078 l_qualifier_code_tbl INV_TRANSACTION_FLOW_PUB.NUMBER_TBL;
1079 l_qualifier_value_tbl INV_TRANSACTION_FLOW_PUB.NUMBER_TBL;
1080
1081 CURSOR c_po_distributions_csr(p_po_distribution_id NUMBER, p_po_line_location_id NUMBER) IS
1082 SELECT po_distribution_id,destination_type_code, project_id
1083 FROM po_distributions POD
1084 WHERE POD.po_distribution_id = NVL(p_po_distribution_id,POD.po_distribution_id)
1085 AND POD.line_location_id = p_po_line_location_id;
1086
1087 BEGIN
1088 -- Standard start of API savepoint
1089 SAVEPOINT Create_ReceiveEvents_PVT;
1090
1091 l_stmt_num := 0;
1092
1093 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
1094 FND_LOG.string(FND_LOG.LEVEL_PROCEDURE,G_LOG_HEAD || '.'||l_api_name||'.begin'
1095 ,'Create_ReceiveEvents <<');
1096 END IF;
1097
1098 -- Standard call to check for call compatibility
1099 IF NOT FND_API.Compatible_API_Call (
1100 l_api_version,
1101 p_api_version,
1102 l_api_name,
1103 G_PKG_NAME ) THEN
1104 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1105 END IF;
1106
1107 -- Initialize message list if p_init_msg_list is set to TRUE
1108 IF FND_API.to_Boolean(p_init_msg_list) THEN
1109 FND_MSG_PUB.initialize;
1110 END IF;
1111
1112 -- Initialize API return status to success
1113 x_return_status := FND_API.G_RET_STS_SUCCESS;
1114
1115 l_stmt_num := 20;
1116 SELECT
1117 RT.po_header_id,
1118 RT.po_line_id,
1119 RT.po_line_location_id,
1120 RT.po_distribution_id,
1121 RT.transaction_date,
1122 nvl(RT.dropship_type_code,3),
1123 POH.org_id,
1124 POLL.ship_to_organization_id,
1125 POL.item_id,
1126 POL.category_id,
1127 POL.project_id,
1128 nvl(POLL.accrue_on_receipt_flag,'N'),
1129 POH.type_lookup_code,
1130 /* Support for Landed Cost Management */
1131 nvl(POLL.lcm_flag, 'N')
1132 INTO l_po_header_id,
1133 l_po_line_id,
1134 l_po_line_location_id,
1135 l_po_distribution_id,
1136 l_rcv_trx_date,
1137 l_drop_ship_flag,
1138 l_po_org_id,
1139 l_rcv_organization_id,
1140 l_item_id,
1141 l_category_id,
1142 l_project_id,
1143 l_accrual_flag,
1144 l_po_document_type_code,
1145 /* Support for Landed Cost Management */
1146 l_lcm_flag
1147 FROM po_headers POH,
1148 po_line_locations POLL,
1149 po_lines POL,
1150 rcv_transactions RT
1151 WHERE RT.transaction_id = p_rcv_transaction_id
1152 AND POH.po_header_id = RT.po_header_id
1153 AND POLL.line_location_id = RT.po_line_location_id
1154 AND POL.po_line_id = RT.po_line_id;
1155
1156 l_stmt_num := 30;
1157 -- Get Receiving Operating Unit
1158 SELECT operating_unit, ledger_id
1159 INTO l_rcv_org_id, l_rcv_sob_id
1160 FROM cst_acct_info_v
1161 WHERE organization_id = l_rcv_organization_id;
1162
1163 l_stmt_num := 35;
1164 -- Get PO SOB
1165 SELECT set_of_books_id
1166 INTO l_po_sob_id
1167 FROM financials_system_parameters;
1168
1169
1170
1171 l_stmt_num := 40;
1172 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
1173 l_api_message := 'Creating Receive Events : RCV Transaction ID : ' || p_rcv_transaction_id ||
1174 ', PO Header ID : ' || l_po_header_id ||
1175 ', PO Line ID : ' || l_po_line_id ||
1176 ', PO Line Location ID : ' || l_po_line_location_id ||
1177 ', PO Dist ID : ' || l_po_distribution_id ||
1178 ', Transaction Date : '|| l_rcv_trx_date ||
1179 ', Drop Ship Flag : '|| l_drop_ship_flag ||
1180 ', PO Org ID : ' || l_po_org_id ||
1181 ', PO SOB ID : ' || l_po_sob_id ||
1182 ', RCV Organization ID : '|| l_rcv_organization_id ||
1183 ', RCV Org ID : '|| l_rcv_org_id ||
1184 ', RCV SOB ID : ' || l_rcv_sob_id ||
1185 ', Category ID : ' || l_category_id ||
1186 ', Accrual Flag : ' || l_accrual_flag ;
1187
1188 FND_LOG.string(FND_LOG.LEVEL_STATEMENT,G_LOG_HEAD || '.'||l_api_name||'.'||l_stmt_num
1189 ,l_api_message);
1190 END IF;
1191
1192 IF(l_po_org_id = l_rcv_org_id) THEN
1193 l_cross_ou_flag := 'N';
1194 ELSE
1195 l_cross_ou_flag := 'Y';
1196
1197 /* For 11i10, the only supported qualifier is category id. */
1198 l_qualifier_code_tbl(l_qualifier_code_tbl.count+1) := INV_TRANSACTION_FLOW_PUB.G_QUALIFIER_CODE;
1199 l_qualifier_value_tbl(l_qualifier_value_tbl.count+1) := l_category_id;
1200
1201 l_stmt_num := 50;
1202 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
1203 l_api_message := 'Getting Procurement Transaction Flow :'||
1204 'l_po_org_id : '||l_po_org_id||
1205 ' l_rcv_org_id : '||l_rcv_org_id||
1206 ' l_rcv_organization_id : '||l_rcv_organization_id;
1207
1208 FND_LOG.string(FND_LOG.LEVEL_STATEMENT,G_LOG_HEAD || '.'||l_api_name||'.'||l_stmt_num
1209 ,l_api_message);
1210 END IF;
1211
1212 INV_TRANSACTION_FLOW_PUB.GET_TRANSACTION_FLOW(
1213 x_return_status => l_return_status,
1214 x_msg_data => l_msg_data,
1215 x_msg_count => l_msg_count,
1216 x_transaction_flows_tbl => l_transaction_flows_tbl,
1217 p_api_version => 1.0,
1218 p_start_operating_unit => l_po_org_id,
1219 p_end_operating_unit => l_rcv_org_id,
1220 p_flow_type => INV_TRANSACTION_FLOW_PUB.G_PROCURING_FLOW_TYPE,
1221 p_organization_id => l_rcv_organization_id,
1222 p_qualifier_code_tbl => l_qualifier_code_tbl,
1223 p_qualifier_value_tbl => l_qualifier_value_tbl,
1224 p_transaction_date => l_rcv_trx_date,
1225 p_get_default_cost_group=> 'N');
1226
1227 IF (l_return_status = FND_API.g_ret_sts_success) THEN
1228 l_trx_flow_exists_flag := 1;
1229 l_trx_flow_header_id := l_transaction_flows_tbl(l_transaction_flows_tbl.FIRST).header_id;
1230 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
1231 FND_LOG.string(FND_LOG.LEVEL_EVENT,G_LOG_HEAD||'.'||l_api_name||'.'||l_stmt_num
1232 ,'Transaction Flow exists');
1233 END IF;
1234
1235 -- Return Status of 'W' indicates that no transaction flow exists.
1236 ELSIF (l_return_status = 'W') THEN
1237 l_trx_flow_exists_flag := 0;
1238 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
1239 FND_LOG.string(FND_LOG.LEVEL_EVENT,G_LOG_HEAD||'.'||l_api_name||'.'||l_stmt_num
1240 ,'Transaction Flow does not exist');
1241 END IF;
1242
1243 -- If transaction flow does not exist, but the PO crosses multiple
1244 -- sets of books, error out the transaction.
1245 IF(l_po_sob_id <> l_rcv_sob_id) THEN
1246 l_api_message := 'Transaction Flow does not exist';
1247 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_UNEXPECTED >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
1248 FND_LOG.string(FND_LOG.LEVEL_UNEXPECTED,G_LOG_HEAD || '.'||l_api_name||l_stmt_num
1249 ,'Create_ReceiveEvents : '||l_stmt_num||' : '||l_api_message);
1250 END IF;
1251 RAISE FND_API.g_exc_unexpected_error;
1252 END IF;
1253
1254 ELSE
1255 l_api_message := 'Error occurred in Transaction Flow API';
1256 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_UNEXPECTED >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
1257 FND_LOG.string(FND_LOG.LEVEL_UNEXPECTED,G_LOG_HEAD || '.'||l_api_name||l_stmt_num
1258 ,'Create_ReceiveEvents : '||l_stmt_num||' : '||l_api_message);
1259 END IF;
1260 RAISE FND_API.g_exc_unexpected_error;
1261 END IF; -- IF l_return_status
1262 END IF; -- IF l_po_org_id
1263
1264
1265 -- For the receive transaction, the PO distribution may not be available in the
1266 -- case of Standard Receipt. Hence perform all steps for each applicable distribution.
1267 -- If distribution is not available the quantity will be prorated. Furthermore, if
1268 -- there is a project on any of the distributions, and the destination_type_code is
1269 -- expense, the transaction flow should be ignored for just that distribution.
1270 FOR rec_pod IN c_po_distributions_csr(l_po_distribution_id, l_po_line_location_id) LOOP
1271
1272 l_stmt_num := 60;
1273 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
1274 l_api_message := 'Creating Receive Events : '||
1275 'po_distribution_id : '||rec_pod.po_distribution_id||
1276 ' destination_type_code : '||rec_pod.destination_type_code||
1277 ' project_id : '||rec_pod.project_id;
1278 FND_LOG.string(FND_LOG.LEVEL_STATEMENT,G_LOG_HEAD || '.'||l_api_name||'.'||l_stmt_num
1279 ,l_api_message);
1280 END IF;
1281
1282
1283 l_procurement_org_flag := 'Y';
1284 -- Bug #5880899. PO does not support centralized procurement for Blankets.
1285 -- Call PO API to verify centralized procurement is supported for this document type.
1286 IF (l_trx_flow_exists_flag = 1) THEN
1287 l_stmt_num := 45;
1288 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
1289 l_api_message := 'Checking if this is a shared proc scenario :'||
1290 ' l_po_document_type_code : '||l_po_document_type_code||
1291 ' l_po_org_id : '||l_po_org_id||
1292 ' l_rcv_org_id : '||l_rcv_org_id||
1293 ' l_rcv_organization_id : '||l_rcv_organization_id||
1294 ' l_trx_flow_header_id : '||l_trx_flow_header_id;
1295
1296 FND_LOG.string(FND_LOG.LEVEL_STATEMENT,G_LOG_HEAD || '.'||l_api_name||'.'||l_stmt_num
1297 ,l_api_message);
1298 END IF;
1299
1300 PO_SHARED_PROC_GRP.check_shared_proc_scenario
1301 (
1302 p_api_version =>1.0,
1303 p_init_msg_list =>FND_API.G_FALSE,
1304 x_return_status =>l_return_status,
1305 p_destination_type_code =>rec_pod.destination_type_code,
1306 p_document_type_code =>l_po_document_type_code,
1307 p_project_id =>rec_pod.project_id,
1308 p_purchasing_ou_id =>l_po_org_id,
1309 p_ship_to_inv_org_id =>l_rcv_organization_id,
1310 p_transaction_flow_header_id =>l_trx_flow_header_id,
1311 x_is_shared_proc_scenario =>l_is_shared_proc
1312 );
1313
1314 IF l_return_status <> FND_API.g_ret_sts_success THEN
1315 l_api_message := 'Error in API PO_SHARED_PROC_GRP.check_shared_proc_scenario';
1316 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_UNEXPECTED >=
1317 FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
1318 FND_LOG.string(FND_LOG.LEVEL_UNEXPECTED,G_LOG_HEAD || '.'||l_api_name||l_stmt_num
1319 ,'Create_ReceiveEvents : '||l_stmt_num||' : '||l_api_message);
1320 END IF;
1321 RAISE FND_API.g_exc_unexpected_error;
1322 END IF;
1323
1324 IF l_is_shared_proc IS NULL OR l_is_shared_proc = 'N' THEN
1325 l_is_shared_proc := 'N';
1326 l_trx_flow_exists_flag := 0;
1327 l_trx_flow_header_id := NULL;
1328 END IF;
1329
1330 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
1331 l_api_message := 'Returned from check_shared_proc_scenario :'||
1332 ' l_is_shared_proc :'|| l_is_shared_proc;
1333 FND_LOG.string(FND_LOG.LEVEL_STATEMENT,G_LOG_HEAD || '.'||l_api_name||'.'||l_stmt_num
1334 ,l_api_message);
1335 END IF;
1336 END IF;
1337
1338
1339 -- For POs with destination type of expense, when there is a project on the
1340 -- POD, we should not look for transaction flow. This is because PA,(which transfers
1341 -- costs to Projects for expense destinations), is currently not supporting global
1342 -- procurement.
1343 IF((l_trx_flow_exists_flag = 1) AND
1344 (rec_pod.project_id is NULL OR rec_pod.destination_type_code <> 'EXPENSE')AND
1345 (l_is_shared_proc = 'Y')) THEN
1346
1347 l_trx_flow_ctr := l_transaction_flows_tbl.COUNT;
1348
1349 -- Create Logical Receive transactions in each intermediate organization.
1350 FOR l_counter IN l_transaction_flows_tbl.FIRST..l_transaction_flows_tbl.LAST LOOP
1351
1352 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
1353 FND_LOG.string(FND_LOG.LEVEL_EVENT,G_LOG_HEAD||'.'||l_api_name||'.'||l_stmt_num
1354 ,'Seeding Logical Receive in RAE');
1355 END IF;
1356
1357
1358 l_stmt_num := 70;
1359 -- l_transaction_forward_flow_rec contains the transaction flow record
1360 -- where the org_id is the from_org_id.
1361 -- l_transaction_reverse_flow_rec contains the transaction flow record
1362 -- where the org_id is the to_org_id.
1363 -- Need to pass both to the Seed_RAE procedure because transfer_price is based
1364 -- on the reverse flow record and some accounts are based on the forward flow
1365
1366 l_transaction_forward_flow_rec := l_transaction_flows_tbl(l_counter);
1367 IF(l_counter = l_transaction_flows_tbl.FIRST) THEN
1368 l_transaction_reverse_flow_rec := NULL;
1369 l_transfer_org_id := NULL;
1370 l_transfer_organization_id := NULL;
1371 ELSE
1372 l_transaction_reverse_flow_rec := l_transaction_flows_tbl(l_counter - 1);
1373 l_transfer_org_id := l_transaction_reverse_flow_rec.from_org_id;
1374 l_transfer_organization_id := l_transaction_reverse_flow_rec.from_organization_id;
1375 END IF;
1376
1377
1378 l_stmt_num := 80;
1379 RCV_SeedEvents_PVT.Seed_RAEEvent(
1380 p_api_version => 1.0,
1381 x_return_status => l_return_status,
1382 x_msg_count => l_msg_count,
1383 x_msg_data => l_msg_data,
1384 p_event_source => 'RECEIVING',
1385 p_event_type_id => RCV_SeedEvents_PVT.LOGICAL_RECEIVE,
1386 p_rcv_transaction_id => p_rcv_transaction_id,
1387 p_inv_distribution_id => NULL,
1388 p_po_distribution_id => rec_pod.po_distribution_id,
1389 p_direct_delivery_flag => p_direct_delivery_flag,
1390 p_cross_ou_flag => l_cross_ou_flag,
1391 p_procurement_org_flag => l_procurement_org_flag,
1392 p_ship_to_org_flag => 'N',
1393 p_drop_ship_flag => l_drop_ship_flag,
1394 p_org_id => l_transaction_flows_tbl(l_counter).from_org_id,
1395 p_organization_id => l_transaction_flows_tbl(l_counter).from_organization_id,
1396 p_transfer_org_id => l_transfer_org_id,
1397 p_transfer_organization_id => l_transfer_organization_id,
1398 p_trx_flow_header_id => l_trx_flow_header_id,
1399 p_transaction_forward_flow_rec => l_transaction_forward_flow_rec,
1400 p_transaction_reverse_flow_rec => l_transaction_reverse_flow_rec,
1401 p_unit_price => NULL,
1402 p_prior_unit_price => NULL,
1403 /* Support for Landed Cost Management */
1404 p_lcm_flag => l_lcm_flag,
1405 x_rcv_event => l_rcv_event);
1406
1407 IF l_return_status <> FND_API.g_ret_sts_success THEN
1408 l_api_message := 'Error creating event';
1409 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_UNEXPECTED >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
1410 FND_LOG.string(FND_LOG.LEVEL_UNEXPECTED,G_LOG_HEAD || '.'||l_api_name||l_stmt_num
1411 ,'Create_ReceiveEvents : '||l_stmt_num||' : '||l_api_message);
1412 END IF;
1413 RAISE FND_API.g_exc_unexpected_error;
1414 END IF;
1415
1416 l_rcv_events_tbl(l_rcv_events_tbl.count + 1) := l_rcv_event;
1417
1418 -- For one-time items, if online accruals is used, seed IC Invoice event.
1419 -- For Shop Floor destination types, always seed IC Invoice events.
1420 IF((l_item_id is NULL and l_accrual_flag = 'Y') OR
1421 (rec_pod.destination_type_code = 'SHOP FLOOR')) THEN
1422 l_stmt_num := 90;
1423 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
1424 FND_LOG.string(FND_LOG.LEVEL_EVENT,G_LOG_HEAD||'.'||l_api_name||'.'||l_stmt_num
1425 ,'Seeding Invoice Match in RAE');
1426 END IF;
1427
1428 RCV_SeedEvents_PVT.Seed_RAEEvent(
1429 p_api_version => 1.0,
1430 x_return_status => l_return_status,
1431 x_msg_count => l_msg_count,
1432 x_msg_data => l_msg_data,
1433 p_event_source => 'RECEIVING',
1434 p_event_type_id => RCV_SeedEvents_PVT.INTERCOMPANY_INVOICE,
1435 p_rcv_transaction_id => p_rcv_transaction_id,
1436 p_inv_distribution_id => NULL,
1437 p_po_distribution_id => rec_pod.po_distribution_id,
1438 p_direct_delivery_flag => p_direct_delivery_flag,
1439 p_cross_ou_flag => l_cross_ou_flag,
1440 p_procurement_org_flag => l_procurement_org_flag,
1441 p_ship_to_org_flag => 'N',
1442 p_drop_ship_flag => l_drop_ship_flag,
1443 p_org_id => l_transaction_flows_tbl(l_counter).from_org_id,
1444 p_organization_id => l_transaction_flows_tbl(l_counter).from_organization_id,
1445 p_transfer_org_id => l_transaction_flows_tbl(l_counter).to_org_id,
1446 p_transfer_organization_id => l_transaction_flows_tbl(l_counter).to_organization_id,
1447 p_trx_flow_header_id => l_trx_flow_header_id,
1448 p_transaction_forward_flow_rec => l_transaction_forward_flow_rec,
1449 p_transaction_reverse_flow_rec => l_transaction_reverse_flow_rec,
1450 p_unit_price => NULL,
1451 p_prior_unit_price => NULL,
1452 /* Support for Landed Cost Management */
1453 p_lcm_flag => l_lcm_flag,
1454 x_rcv_event => l_rcv_event);
1455
1456 IF l_return_status <> FND_API.g_ret_sts_success THEN
1457 l_api_message := 'Error creating event';
1458 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_UNEXPECTED >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
1459 FND_LOG.string(FND_LOG.LEVEL_UNEXPECTED,G_LOG_HEAD || '.'||l_api_name||l_stmt_num
1460 ,'Create_ReceiveEvents : '||l_stmt_num||' : '||l_api_message);
1461 END IF;
1462 RAISE FND_API.g_exc_unexpected_error;
1463 END IF;
1464
1465 l_rcv_events_tbl(l_rcv_events_tbl.count + 1) := l_rcv_event;
1466 END IF;
1467
1468 l_procurement_org_flag := 'N';
1469 END LOOP;
1470 END IF;
1471
1472 l_stmt_num := 100;
1473 IF (l_trx_flow_exists_flag = 1) THEN
1474 l_transaction_forward_flow_rec := NULL;
1475 l_transaction_reverse_flow_rec := l_transaction_flows_tbl(l_trx_flow_ctr);
1476 l_org_id := l_transaction_flows_tbl(l_trx_flow_ctr).to_org_id;
1477 l_transfer_org_id := l_transaction_flows_tbl(l_trx_flow_ctr).from_org_id;
1478 l_transfer_organization_id := l_transaction_reverse_flow_rec.from_organization_id;
1479 ELSE
1480 l_transaction_forward_flow_rec := NULL;
1481 l_transaction_reverse_flow_rec := NULL;
1482 l_org_id := l_po_org_id;
1483 l_transfer_org_id := NULL;
1484 l_transfer_organization_id := NULL;
1485 END IF;
1486
1487 l_stmt_num := 110;
1488
1489 -- If drop ship flag is 1(drop ship with new accounting) OR 2(drop ship with old accounting),
1490 -- then create a LOGICAL RECEIVE and use the clearing account. It drop ship flag is 3 (not a
1491 -- drop ship), then create a RECEIVE event
1492 IF (l_drop_ship_flag IN (1,2)) THEN
1493 -- This is a pure (external) drop ship scenario. Seed a LOGICAL_RECEIVE event in the receiving org.
1494 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
1495 FND_LOG.string(FND_LOG.LEVEL_EVENT,G_LOG_HEAD||'.'||l_api_name||'.'||l_stmt_num
1496 ,'Drop Ship : Seeding Logical Receive in RAE');
1497 END IF;
1498
1499 l_stmt_num := 120;
1500 RCV_SeedEvents_PVT.Seed_RAEEvent(
1501 p_api_version => 1.0,
1502 x_return_status => l_return_status,
1503 x_msg_count => l_msg_count,
1504 x_msg_data => l_msg_data,
1505 p_event_source => 'RECEIVING',
1506 p_event_type_id => RCV_SeedEvents_PVT.LOGICAL_RECEIVE,
1507 p_rcv_transaction_id => p_rcv_transaction_id,
1508 p_inv_distribution_id => NULL,
1509 p_po_distribution_id => rec_pod.po_distribution_id,
1510 p_direct_delivery_flag => p_direct_delivery_flag,
1511 p_cross_ou_flag => l_cross_ou_flag,
1512 p_procurement_org_flag => l_procurement_org_flag,
1513 p_ship_to_org_flag => 'Y',
1514 p_drop_ship_flag => l_drop_ship_flag,
1515 p_org_id => l_org_id,
1516 p_organization_id => l_rcv_organization_id,
1517 p_transfer_org_id => l_transfer_org_id,
1518 p_transfer_organization_id => l_transfer_organization_id,
1519 p_trx_flow_header_id => l_trx_flow_header_id,
1520 p_transaction_forward_flow_rec => l_transaction_forward_flow_rec,
1521 p_transaction_reverse_flow_rec => l_transaction_reverse_flow_rec,
1522 p_unit_price => NULL,
1523 p_prior_unit_price => NULL,
1524 /* Support for Landed Cost Management */
1525 p_lcm_flag => l_lcm_flag,
1526 x_rcv_event => l_rcv_event);
1527 IF l_return_status <> FND_API.g_ret_sts_success THEN
1528 l_api_message := 'Error creating event';
1529 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_UNEXPECTED >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
1530 FND_LOG.string(FND_LOG.LEVEL_UNEXPECTED,G_LOG_HEAD || '.'||l_api_name||l_stmt_num
1531 ,'Create_ReceiveEvents : '||l_stmt_num||' : '||l_api_message);
1532 END IF;
1533 RAISE FND_API.g_exc_unexpected_error;
1534 END IF;
1535
1536 l_rcv_events_tbl(l_rcv_events_tbl.count + 1) := l_rcv_event;
1537
1538 ELSE
1539
1540 l_stmt_num := 130;
1541 SELECT decode(RT.transaction_type,'CORRECT',RCV_SeedEvents_PVT.CORRECT,
1542 RCV_SeedEvents_PVT.RECEIVE)
1543 INTO l_event_type_id
1544 FROM rcv_Transactions RT
1545 WHERE transaction_id = p_rcv_transaction_id;
1546
1547 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
1548 FND_LOG.string(FND_LOG.LEVEL_EVENT,G_LOG_HEAD||'.'||l_api_name||'.'||l_stmt_num
1549 ,'Not Drop Ship : Seeding Receive in RAE');
1550 END IF;
1551
1552 l_stmt_num := 140;
1553 RCV_SeedEvents_PVT.Seed_RAEEvent(
1554 p_api_version => 1.0,
1555 x_return_status => l_return_status,
1556 x_msg_count => l_msg_count,
1557 x_msg_data => l_msg_data,
1558 p_event_source => 'RECEIVING',
1559 p_event_type_id => l_event_type_id,
1560 p_rcv_transaction_id => p_rcv_transaction_id,
1561 p_inv_distribution_id => NULL,
1562 p_po_distribution_id => rec_pod.po_distribution_id,
1563 p_direct_delivery_flag => p_direct_delivery_flag,
1564 p_cross_ou_flag => l_cross_ou_flag,
1565 p_procurement_org_flag => l_procurement_org_flag,
1566 p_ship_to_org_flag => 'Y',
1567 p_drop_ship_flag => l_drop_ship_flag,
1568 p_org_id => l_org_id,
1569 p_organization_id => l_rcv_organization_id,
1570 p_transfer_org_id => l_transfer_org_id,
1571 p_transfer_organization_id => l_transfer_organization_id,
1572 p_trx_flow_header_id => l_trx_flow_header_id,
1573 p_transaction_forward_flow_rec => l_transaction_forward_flow_rec,
1574 p_transaction_reverse_flow_rec => l_transaction_reverse_flow_rec,
1575 p_unit_price => NULL,
1576 p_prior_unit_price => NULL,
1577 /* Support for Landed Cost Management */
1578 p_lcm_flag => l_lcm_flag,
1579 x_rcv_event => l_rcv_event);
1580 IF l_return_status <> FND_API.g_ret_sts_success THEN
1581 l_api_message := 'Error creating event';
1582 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_UNEXPECTED >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
1583 FND_LOG.string(FND_LOG.LEVEL_UNEXPECTED,G_LOG_HEAD || '.'||l_api_name||l_stmt_num
1584 ,'Create_ReceiveEvents : '||l_stmt_num||' : '||l_api_message);
1585 END IF;
1586 RAISE FND_API.g_exc_unexpected_error;
1587 END IF;
1588
1589 l_rcv_events_tbl(l_rcv_events_tbl.count + 1) := l_rcv_event;
1590
1591 END IF;
1592 END LOOP;
1593
1594 l_stmt_num := 150;
1595 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
1596 FND_LOG.string(FND_LOG.LEVEL_EVENT,G_LOG_HEAD||'.'||l_api_name||'.'||l_stmt_num
1597 ,'Inserting events into RAE');
1598 END IF;
1599 RCV_SeedEvents_PVT.Insert_RAEEvents(
1600 p_api_version => 1.0,
1601 x_return_status => l_return_status,
1602 x_msg_count => l_msg_count,
1603 x_msg_data => l_msg_data,
1604 p_rcv_events_tbl => l_rcv_events_tbl,
1605 /* Support for Landed Cost Management */
1606 p_lcm_flag => l_lcm_flag);
1607 IF l_return_status <> FND_API.g_ret_sts_success THEN
1608 l_api_message := 'Error inserting events into RAE';
1609 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_UNEXPECTED >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
1610 FND_LOG.string(FND_LOG.LEVEL_UNEXPECTED,G_LOG_HEAD || '.'||l_api_name||l_stmt_num
1611 ,'Create_ReceiveEvents : '||l_stmt_num||' : '||l_api_message);
1612 END IF;
1613 RAISE FND_API.g_exc_unexpected_error;
1614 END IF;
1615
1616 IF(l_trx_flow_exists_flag = 1 AND l_item_id IS NOT NULL) THEN
1617 l_stmt_num := 160;
1618 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
1619 FND_LOG.string(FND_LOG.LEVEL_EVENT,G_LOG_HEAD||'.'||l_api_name||'.'||l_stmt_num
1620 ,'Inserting events into MMT');
1621 END IF;
1622 RCV_SeedEvents_PVT.Insert_MMTEvents(
1623 p_api_version => 1.0,
1624 x_return_status => l_return_status,
1625 x_msg_count => l_msg_count,
1626 x_msg_data => l_msg_data,
1627 p_rcv_events_tbl => l_rcv_events_tbl);
1628 IF l_return_status <> FND_API.g_ret_sts_success THEN
1629 l_api_message := 'Error inserting events into MMT';
1630 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_UNEXPECTED >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
1631 FND_LOG.string(FND_LOG.LEVEL_UNEXPECTED,G_LOG_HEAD || '.'||l_api_name||l_stmt_num
1632 ,'Create_ReceiveEvents : '||l_stmt_num||' : '||l_api_message);
1633 END IF;
1634 RAISE FND_API.g_exc_unexpected_error;
1635 END IF;
1636 END IF;
1637
1638
1639 --- Standard check of p_commit
1640 IF FND_API.to_Boolean(p_commit) THEN
1641 COMMIT WORK;
1642 END IF;
1643
1644 -- Standard Call to get message count and if count = 1, get message info
1645 FND_MSG_PUB.Count_And_Get (
1646 p_count => x_msg_count,
1647 p_data => x_msg_data );
1648
1649 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
1650 FND_LOG.string(FND_LOG.LEVEL_PROCEDURE,G_LOG_HEAD || '.'||l_api_name||'.end'
1651 ,'Create_ReceiveEvents >>');
1652 END IF;
1653
1654 EXCEPTION
1655 WHEN FND_API.g_exc_error THEN
1656 ROLLBACK TO Create_ReceiveEvents_PVT;
1657 x_return_status := FND_API.g_ret_sts_error;
1658 FND_MSG_PUB.count_and_get
1659 ( p_count => x_msg_count
1660 , p_data => x_msg_data
1661 );
1662 WHEN FND_API.g_exc_unexpected_error THEN
1663 ROLLBACK TO Create_ReceiveEvents_PVT;
1664 x_return_status := FND_API.g_ret_sts_unexp_error ;
1665 FND_MSG_PUB.count_and_get
1666 ( p_count => x_msg_count
1667 , p_data => x_msg_data
1668 );
1669
1670 WHEN OTHERS THEN
1671 ROLLBACK TO Create_ReceiveEvents_PVT;
1672 x_return_status := fnd_api.g_ret_sts_unexp_error ;
1673
1674 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_UNEXPECTED >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
1675 FND_LOG.string(FND_LOG.LEVEL_UNEXPECTED,G_LOG_HEAD || '.'||l_api_name||l_stmt_num
1676 ,'Create_ReceiveEvents : '||l_stmt_num||' : '||substr(SQLERRM,1,200));
1677 END IF;
1678
1679 IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error)
1680 THEN
1681 FND_MSG_PUB.add_exc_msg
1682 ( G_PKG_NAME,
1683 l_api_name || 'Statement -'||to_char(l_stmt_num)
1684 );
1685 END IF;
1686 FND_MSG_PUB.count_and_get
1687 ( p_count => x_msg_count
1688 , p_data => x_msg_data
1689 );
1690
1691 END Create_ReceiveEvents;
1692
1693
1694
1695 -- API name : Create_DeliverEvents
1696 -- Type : Private
1697 -- Function : To seed accounting events for DELIVER transactions.
1698 -- Pre-reqs :
1699 -- Parameters :
1700 -- IN : p_api_version IN NUMBER Required
1701 -- p_init_msg_list IN VARCHAR2 Optional
1702 -- Default = FND_API.G_FALSE
1703 -- p_commit IN VARCHAR2 Optional
1704 -- Default = FND_API.G_FALSE
1705 -- p_validation_level IN NUMBER Optional
1706 -- Default = FND_API.G_VALID_LEVEL_FULL
1707 -- p_rcv_transaction_id IN NUMBER Required
1708 -- p_direct_delivery_flag IN VARCHAR2 Optional
1709 --
1710 -- OUT : x_return_status OUT VARCHAR2(1)
1711 -- x_msg_count OUT NUMBER
1712 -- x_msg_data OUT VARCHAR2(2000)
1713 -- Version :
1714 -- Initial version 1.0
1715 --
1716 --
1717 -- Notes : This API creates all accounting events for DELIVER transactions
1718 -- in RCV_ACCOUNTING_EVENTS.
1719 --
1720 -- End of comments
1721 -------------------------------------------------------------------------------
1722 PROCEDURE Create_DeliverEvents(
1723 p_api_version IN NUMBER,
1724 p_init_msg_list IN VARCHAR2,
1725 p_commit IN VARCHAR2,
1726 p_validation_level IN NUMBER,
1727 x_return_status OUT NOCOPY VARCHAR2,
1728 x_msg_count OUT NOCOPY NUMBER,
1729 x_msg_data OUT NOCOPY VARCHAR2,
1730
1731 p_rcv_transaction_id IN NUMBER,
1732 p_direct_delivery_flag IN VARCHAR2
1733 ) IS
1734 l_api_name CONSTANT VARCHAR2(30) := 'Create_DeliverEvents';
1735 l_api_version CONSTANT NUMBER := 1.0;
1736
1737 l_return_status VARCHAR2(1) := fnd_api.g_ret_sts_success;
1738 l_msg_count NUMBER := 0;
1739 l_msg_data VARCHAR2(8000) := '';
1740 l_stmt_num NUMBER := 0;
1741 l_api_message VARCHAR2(1000);
1742
1743 l_rcv_event RCV_SeedEvents_PVT.rcv_event_rec_type;
1744 l_rcv_events_tbl RCV_SeedEvents_PVT.rcv_event_tbl_type;
1745 l_event_type_id NUMBER;
1746
1747 l_transaction_flows_tbl INV_TRANSACTION_FLOW_PUB.g_transaction_flow_tbl_type;
1748 l_transaction_reverse_flow_rec INV_TRANSACTION_FLOW_PUB.mtl_transaction_flow_rec_type := NULL;
1749 l_trx_flow_exists_flag NUMBER := 0;
1750 l_trx_flow_ctr NUMBER := 0;
1751
1752 l_po_header_id NUMBER;
1753 l_po_distribution_id NUMBER;
1754 l_po_org_id NUMBER;
1755 l_po_sob_id NUMBER;
1756 l_rcv_organization_id NUMBER;
1757 l_rcv_org_id NUMBER;
1758 l_transfer_org_id NUMBER := NULL;
1759 l_transfer_organization_id NUMBER := NULL;
1760 l_rcv_sob_id NUMBER;
1761 l_rcv_trx_date DATE;
1762 l_drop_ship_flag NUMBER;
1763 l_destination_type VARCHAR(25);
1764 l_category_id NUMBER;
1765 l_project_id NUMBER;
1766 l_cross_ou_flag VARCHAR2(1) := 'N';
1767 l_accrual_flag VARCHAR2(1) := 'N';
1768 l_procurement_org_flag VARCHAR2(1) := 'Y';
1769 l_trx_flow_header_id NUMBER;
1770 l_qualifier_code_tbl INV_TRANSACTION_FLOW_PUB.NUMBER_TBL;
1771 l_qualifier_value_tbl INV_TRANSACTION_FLOW_PUB.NUMBER_TBL;
1772 l_encumbrance_flag VARCHAR2(1);
1773 l_ussgl_option VARCHAR2(1);
1774 l_po_document_type_code PO_HEADERS_ALL.type_lookup_code%TYPE;
1775 l_is_shared_proc VARCHAR2(1);
1776 /* Support for Landed Cost Management */
1777 l_lcm_flag VARCHAR2(1);
1778
1779 BEGIN
1780 -- Standard start of API savepoint
1781 SAVEPOINT Create_DeliverEvents_PVT;
1782
1783 l_stmt_num := 0;
1784
1785 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
1786 FND_LOG.string(FND_LOG.LEVEL_PROCEDURE,G_LOG_HEAD || '.'||l_api_name||'.begin'
1787 ,'Create_DeliverEvents <<');
1788 END IF;
1789
1790 -- Standard call to check for call compatibility
1791 IF NOT FND_API.Compatible_API_Call (
1792 l_api_version,
1793 p_api_version,
1794 l_api_name,
1795 G_PKG_NAME ) THEN
1796 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1797 END IF;
1798
1799 -- Initialize message list if p_init_msg_list is set to TRUE
1800 IF FND_API.to_Boolean(p_init_msg_list) THEN
1801 FND_MSG_PUB.initialize;
1802 END IF;
1803
1804 -- Initialize API return status to success
1805 x_return_status := FND_API.G_RET_STS_SUCCESS;
1806
1807 -- Unlike for Receive transactions, for Deliver transactions, the po_distribution_id
1808 -- is always available.
1809 l_stmt_num := 20;
1810 SELECT
1811 RT.po_header_id,
1812 RT.po_distribution_id,
1813 POD.destination_type_code,
1814 RT.transaction_date,
1815 nvl(RT.dropship_type_code,3),
1816 POH.org_id,
1817 POLL.ship_to_organization_id,
1818 POL.category_id,
1819 POL.project_id,
1820 nvl(POLL.accrue_on_receipt_flag,'N'),
1821 POH.type_lookup_code,
1822 /* Support for Landed Cost Management */
1823 NVL(POLL.lcm_flag,'N')
1824 INTO l_po_header_id,
1825 l_po_distribution_id,
1826 l_destination_type,
1827 l_rcv_trx_date,
1828 l_drop_ship_flag,
1829 l_po_org_id,
1830 l_rcv_organization_id,
1831 l_category_id,
1832 l_project_id,
1833 l_accrual_flag,
1834 l_po_document_type_code,
1835 /* Support for Landed Cost Management */
1836 l_lcm_flag
1837 FROM po_headers POH,
1838 po_line_locations POLL,
1839 po_lines POL,
1840 po_distributions POD,
1841 rcv_transactions RT
1842 WHERE RT.transaction_id = p_rcv_transaction_id
1843 AND POH.po_header_id = RT.po_header_id
1844 AND POLL.line_location_id = RT.po_line_location_id
1845 AND POL.po_line_id = RT.po_line_id
1846 AND POD.po_distribution_id = RT.po_distribution_id;
1847
1848 l_stmt_num := 30;
1849
1850 -- Get Receiving Operating Unit and SOB
1851 SELECT operating_unit, ledger_id
1852 INTO l_rcv_org_id, l_rcv_sob_id
1853 FROM cst_acct_info_v
1854 WHERE organization_id = l_rcv_organization_id;
1855
1856 l_stmt_num := 35;
1857 -- Get PO SOB
1858 SELECT set_of_books_id
1859 INTO l_po_sob_id
1860 FROM financials_system_parameters;
1861
1862 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
1863 l_api_message := 'Creating Deliver Events : RCV Transaction ID : ' || p_rcv_transaction_id ||
1864 ', PO Header ID : ' || l_po_header_id ||
1865 ', PO Dist ID : ' || l_po_distribution_id ||
1866 ', Destination Type : '|| l_destination_type ||
1867 ', Transaction Date : '|| l_rcv_trx_date ||
1868 ', Drop Ship Flag : '|| l_drop_ship_flag ||
1869 ', PO Org ID : ' || l_po_org_id ||
1870 ', RCV Organization ID : '|| l_rcv_organization_id ||
1871 ', RCV Org ID : '|| l_rcv_org_id ||
1872 ', Project ID : '|| l_project_id ||
1873 ', Category ID : ' || l_category_id ||
1874 ', Accrual Flag : ' || l_accrual_flag ;
1875
1876 FND_LOG.string(FND_LOG.LEVEL_STATEMENT,G_LOG_HEAD || '.'||l_api_name||'.'||l_stmt_num
1877 ,l_api_message);
1878 END IF;
1879
1880 -- Only create events for Deliver transactions for expense destination types. Other
1881 -- destination types do not have any accounting implications in the Receiving sub-ledger.
1882 IF (l_destination_type <> 'EXPENSE') THEN
1883 return;
1884 END IF;
1885
1886 IF(l_po_org_id <> l_rcv_org_id) THEN
1887 l_cross_ou_flag := 'Y';
1888 END IF;
1889
1890 -- Get transaction flow when procuring and receiving operating units are different.
1891 -- However, for POs with destination type of expense, when there is a project on the
1892 -- PO, we should not look for transaction flow. This is because PA,(which transfers
1893 -- costs to Projects for expense destinations), is currently not supporting global
1894 -- procurement.
1895 IF(l_cross_ou_flag = 'Y' AND l_project_id is NULL) THEN
1896
1897 /* For 11i10, the only supported qualifier is category id. */
1898 l_qualifier_code_tbl(l_qualifier_code_tbl.count+1) := INV_TRANSACTION_FLOW_PUB.G_QUALIFIER_CODE;
1899 l_qualifier_value_tbl(l_qualifier_value_tbl.count+1) := l_category_id;
1900
1901 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
1902 l_api_message := 'Getting Procurement Transaction Flow :'||
1903 'l_po_org_id : '||l_po_org_id||
1904 ' l_rcv_org_id : '||l_rcv_org_id||
1905 ' l_rcv_organization_id : '||l_rcv_organization_id;
1906
1907 FND_LOG.string(FND_LOG.LEVEL_STATEMENT,G_LOG_HEAD || '.'||l_api_name||'.'||l_stmt_num
1908 ,l_api_message);
1909 END IF;
1910
1911
1912 INV_TRANSACTION_FLOW_PUB.GET_TRANSACTION_FLOW(
1913 x_return_status => l_return_status,
1914 x_msg_data => l_msg_data,
1915 x_msg_count => l_msg_count,
1916 x_transaction_flows_tbl => l_transaction_flows_tbl,
1917 p_api_version => 1.0,
1918 p_start_operating_unit => l_po_org_id,
1919 p_end_operating_unit => l_rcv_org_id,
1920 p_flow_type => INV_TRANSACTION_FLOW_PUB.G_PROCURING_FLOW_TYPE,
1921 p_organization_id => l_rcv_organization_id,
1922 p_qualifier_code_tbl => l_qualifier_code_tbl,
1923 p_qualifier_value_tbl => l_qualifier_value_tbl,
1924 p_transaction_date => l_rcv_trx_date,
1925 p_get_default_cost_group=> 'N');
1926 IF (l_return_status = FND_API.g_ret_sts_success) THEN
1927 l_procurement_org_flag := 'N';
1928 l_trx_flow_exists_flag := 1;
1929 l_trx_flow_header_id := l_transaction_flows_tbl(l_transaction_flows_tbl.FIRST).header_id;
1930 l_trx_flow_ctr := l_transaction_flows_tbl.COUNT;
1931 l_transaction_reverse_flow_rec := l_transaction_flows_tbl(l_trx_flow_ctr);
1932 l_transfer_org_id := l_transaction_reverse_flow_rec.from_org_id;
1933 l_transfer_organization_id := l_transaction_reverse_flow_rec.from_organization_id;
1934
1935
1936 -- Bug #5880899. PO does not support centralized procurement for Blankets.
1937 -- Call PO API to verify centralized procurement is supported for this document type.
1938 l_stmt_num := 45;
1939 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
1940 l_api_message := 'Checking if this is a shared proc scenario :'||
1941 ' l_po_document_type_code : '||l_po_document_type_code||
1942 ' l_po_org_id : '||l_po_org_id||
1943 ' l_rcv_org_id : '||l_rcv_org_id||
1944 ' l_rcv_organization_id : '||l_rcv_organization_id||
1945 ' l_trx_flow_header_id : '||l_trx_flow_header_id;
1946
1947 FND_LOG.string(FND_LOG.LEVEL_STATEMENT,G_LOG_HEAD || '.'||l_api_name||'.'||l_stmt_num
1948 ,l_api_message);
1949 END IF;
1950
1951 PO_SHARED_PROC_GRP.check_shared_proc_scenario
1952 (
1953 p_api_version =>1.0,
1954 p_init_msg_list =>FND_API.G_FALSE,
1955 x_return_status =>l_return_status,
1956 p_destination_type_code =>l_destination_type,
1957 p_document_type_code =>l_po_document_type_code,
1958 p_project_id =>l_project_id,
1959 p_purchasing_ou_id =>l_po_org_id,
1960 p_ship_to_inv_org_id =>l_rcv_organization_id,
1961 p_transaction_flow_header_id =>l_trx_flow_header_id,
1962 x_is_shared_proc_scenario =>l_is_shared_proc
1963 );
1964
1965 IF l_return_status <> FND_API.g_ret_sts_success THEN
1966 l_api_message := 'Error in API PO_SHARED_PROC_GRP.check_shared_proc_scenario';
1967 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_UNEXPECTED >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
1968 FND_LOG.string(FND_LOG.LEVEL_UNEXPECTED,G_LOG_HEAD || '.'||l_api_name||l_stmt_num
1969 ,'Create_ReceiveEvents : '||l_stmt_num||' : '||l_api_message);
1970 END IF;
1971 RAISE FND_API.g_exc_unexpected_error;
1972 END IF;
1973
1974 IF l_is_shared_proc IS NULL OR l_is_shared_proc = 'N' THEN
1975 l_is_shared_proc := 'N';
1976 l_trx_flow_exists_flag := 0;
1977 l_trx_flow_header_id := NULL;
1978 END IF;
1979
1980 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
1981 l_api_message := 'Returned from check_shared_proc_scenario :'||
1982 ' l_is_shared_proc :'|| l_is_shared_proc;
1983 FND_LOG.string(FND_LOG.LEVEL_STATEMENT,G_LOG_HEAD || '.'||l_api_name||'.'||l_stmt_num
1984 ,l_api_message);
1985 END IF;
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001 ELSIF (l_return_status = 'W') THEN
2002 l_trx_flow_exists_flag := 0;
2003 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
2004 FND_LOG.string(FND_LOG.LEVEL_EVENT,G_LOG_HEAD||'.'||l_api_name||'.'||l_stmt_num
2005 ,'Transaction Flow does not exist');
2006 END IF;
2007
2008 -- If transaction flow does not exist, but the PO crosses multiple
2009 -- sets of books, error out the transaction.
2010 IF(l_po_sob_id <> l_rcv_sob_id) THEN
2011 l_api_message := 'Transaction Flow does not exist';
2012 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_UNEXPECTED >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
2013 FND_LOG.string(FND_LOG.LEVEL_UNEXPECTED,G_LOG_HEAD || '.'||l_api_name||l_stmt_num
2014 ,'Create_DeliverEvents : '||l_stmt_num||' : '||l_api_message);
2015 END IF;
2016 RAISE FND_API.g_exc_unexpected_error;
2017 END IF;
2018
2019 ELSE
2020 l_api_message := 'Error occurred in Transaction Flow API';
2021 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_UNEXPECTED >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
2022 FND_LOG.string(FND_LOG.LEVEL_UNEXPECTED,G_LOG_HEAD || '.'||l_api_name||l_stmt_num
2023 ,'Create_DeliverEvents : '||l_stmt_num||' : '||l_api_message);
2024 END IF;
2025 RAISE FND_API.g_exc_unexpected_error;
2026 END IF;
2027 END IF;
2028
2029 l_stmt_num := 50;
2030 SELECT decode(RT.transaction_type,'CORRECT',RCV_SeedEvents_PVT.CORRECT,
2031 RCV_SeedEvents_PVT.DELIVER)
2032 INTO l_event_type_id
2033 FROM rcv_Transactions RT
2034 WHERE transaction_id = p_rcv_transaction_id;
2035
2036 l_stmt_num := 60;
2037 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
2038 FND_LOG.string(FND_LOG.LEVEL_EVENT,G_LOG_HEAD||'.'||l_api_name||'.'||l_stmt_num
2039 ,'Seeding Deliver Event');
2040 END IF;
2041
2042 RCV_SeedEvents_PVT.Seed_RAEEvent(
2043 p_api_version => 1.0,
2044 x_return_status => l_return_status,
2045 x_msg_count => l_msg_count,
2046 x_msg_data => l_msg_data,
2047 p_event_source => 'RECEIVING',
2048 p_event_type_id => l_event_type_id,
2049 p_rcv_transaction_id => p_rcv_transaction_id,
2050 p_inv_distribution_id => NULL,
2051 p_po_distribution_id => l_po_distribution_id,
2052 p_direct_delivery_flag => p_direct_delivery_flag,
2053 p_cross_ou_flag => l_cross_ou_flag,
2054 p_procurement_org_flag => l_procurement_org_flag,
2055 p_ship_to_org_flag => 'Y',
2056 p_drop_ship_flag => l_drop_ship_flag,
2057 p_org_id => l_rcv_org_id,
2058 p_organization_id => l_rcv_organization_id,
2059 p_transfer_org_id => l_transfer_org_id,
2060 p_transfer_organization_id => l_transfer_organization_id,
2061 p_trx_flow_header_id => l_trx_flow_header_id,
2062 p_transaction_forward_flow_rec => NULL,
2063 p_transaction_reverse_flow_rec => l_transaction_reverse_flow_rec,
2064 p_unit_price => NULL,
2065 p_prior_unit_price => NULL,
2066 /* Support for Landed Cost Management */
2067 p_lcm_flag => l_lcm_flag,
2068 x_rcv_event => l_rcv_event);
2069
2070 IF l_return_status <> FND_API.g_ret_sts_success THEN
2071 l_api_message := 'Error creating event';
2072 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_UNEXPECTED >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
2073 FND_LOG.string(FND_LOG.LEVEL_UNEXPECTED,G_LOG_HEAD || '.'||l_api_name||l_stmt_num
2074 ,'Create_DeliverEvents : '||l_stmt_num||' : '||l_api_message);
2075 END IF;
2076 RAISE FND_API.g_exc_unexpected_error;
2077 END IF;
2078 l_rcv_events_tbl(l_rcv_events_tbl.count + 1) := l_rcv_event;
2079
2080 -- Encumbrance cannot be enabled for global procurement scenarios.
2081 IF l_trx_flow_exists_flag = 0 THEN
2082 l_stmt_num := 70;
2083 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
2084 FND_LOG.string(FND_LOG.LEVEL_EVENT,G_LOG_HEAD||'.'||l_api_name||'.'||l_stmt_num
2085 ,'Checking if encumbrance events need to be seeded.');
2086 END IF;
2087 RCV_SeedEvents_PVT.Check_EncumbranceFlag(
2088 p_api_version => 1.0,
2089 x_return_status => l_return_status,
2090 x_msg_count => l_msg_count,
2091 x_msg_data => l_msg_data,
2092 p_rcv_sob_id => l_rcv_sob_id,
2093 x_encumbrance_flag => l_encumbrance_flag,
2094 x_ussgl_option => l_ussgl_option);
2095 IF l_return_status <> FND_API.g_ret_sts_success THEN
2096 l_api_message := 'Error in checking for encumbrance flag ';
2097 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_UNEXPECTED >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
2098 FND_LOG.string(FND_LOG.LEVEL_UNEXPECTED,G_LOG_HEAD || '.'||l_api_name||l_stmt_num
2099 ,'Create_DeliverEvents : '||l_stmt_num||' : '||l_api_message);
2100 END IF;
2101 RAISE FND_API.g_exc_unexpected_error;
2102 END IF;
2103
2104 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
2105 l_api_message := 'Encumbrance Flag : '||l_encumbrance_flag;
2106 FND_LOG.string(FND_LOG.LEVEL_STATEMENT,G_LOG_HEAD||'.'||l_api_name||'.'||l_stmt_num
2107 ,l_api_message);
2108 END IF;
2109
2110 IF(l_encumbrance_flag = 'Y') THEN
2111 l_stmt_num := 80;
2112 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
2113 FND_LOG.string(FND_LOG.LEVEL_EVENT,G_LOG_HEAD||'.'||l_api_name||'.'||l_stmt_num
2114 ,'Seeding Encumbrance Reversal Event');
2115 END IF;
2116
2117
2118 RCV_SeedEvents_PVT.Seed_RAEEvent(
2119 p_api_version => 1.0,
2120 x_return_status => l_return_status,
2121 x_msg_count => l_msg_count,
2122 x_msg_data => l_msg_data,
2123 p_event_source => 'RECEIVING',
2124 p_event_type_id => RCV_SeedEvents_PVT.ENCUMBRANCE_REVERSAL,
2125 p_rcv_transaction_id => p_rcv_transaction_id,
2126 p_inv_distribution_id => NULL,
2127 p_po_distribution_id => l_po_distribution_id,
2128 p_direct_delivery_flag => p_direct_delivery_flag,
2129 p_cross_ou_flag => l_cross_ou_flag,
2130 p_procurement_org_flag => l_procurement_org_flag,
2131 p_ship_to_org_flag => 'Y',
2132 p_drop_ship_flag => l_drop_ship_flag,
2133 p_org_id => l_rcv_org_id,
2134 p_organization_id => l_rcv_organization_id,
2135 p_transfer_org_id => NULL,
2136 p_transfer_organization_id => NULL,
2137 p_transaction_forward_flow_rec => NULL,
2138 p_transaction_reverse_flow_rec => l_transaction_reverse_flow_rec,
2139 p_unit_price => NULL,
2140 p_prior_unit_price => NULL,
2141 /* Support for Landed Cost Management */
2142 p_lcm_flag => l_lcm_flag,
2143 x_rcv_event => l_rcv_event);
2144
2145
2146 /* Bug #3333610. In the case of encumbrance reversals, the quantity to unencumber
2147 may turn out to be zero if the quantity delivered is greater than the quantity
2148 ordered. In such a situation, we should not error out the event. */
2149 IF l_return_status = FND_API.g_ret_sts_success THEN
2150 l_rcv_events_tbl(l_rcv_events_tbl.count + 1) := l_rcv_event;
2151 ELSIF l_return_status <> 'W' THEN
2152 l_api_message := 'Error in seeding encumbrance reversal event';
2153 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_UNEXPECTED >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
2154 FND_LOG.string(FND_LOG.LEVEL_UNEXPECTED,G_LOG_HEAD || '.'||l_api_name||l_stmt_num
2155 ,'Create_DeliverEvents : '||l_stmt_num||' : '||l_api_message);
2156 END IF;
2157 RAISE FND_API.g_exc_unexpected_error;
2158 END IF;
2159 END IF;
2160 END IF;
2161
2162 l_stmt_num := 90;
2163 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
2164 FND_LOG.string(FND_LOG.LEVEL_EVENT,G_LOG_HEAD||'.'||l_api_name||'.'||l_stmt_num
2165 ,'Inserting events into RAE');
2166 END IF;
2167 RCV_SeedEvents_PVT.Insert_RAEEvents(
2168 p_api_version => 1.0,
2169 x_return_status => l_return_status,
2170 x_msg_count => l_msg_count,
2171 x_msg_data => l_msg_data,
2172 p_rcv_events_tbl => l_rcv_events_tbl,
2173 /* Support for Landed Cost Management */
2174 p_lcm_flag => l_lcm_flag);
2175 IF l_return_status <> FND_API.g_ret_sts_success THEN
2176 l_api_message := 'Error inserting events into RAE';
2177 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_UNEXPECTED >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
2178 FND_LOG.string(FND_LOG.LEVEL_UNEXPECTED,G_LOG_HEAD || '.'||l_api_name||l_stmt_num
2179 ,'Create_DeliverEvents : '||l_stmt_num||' : '||l_api_message);
2180 END IF;
2181 RAISE FND_API.g_exc_unexpected_error;
2182 END IF;
2183
2184
2185
2186 --- Standard check of p_commit
2187 IF FND_API.to_Boolean(p_commit) THEN
2188 COMMIT WORK;
2189 END IF;
2190
2191 -- Standard Call to get message count and if count = 1, get message info
2192 FND_MSG_PUB.Count_And_Get (
2193 p_count => x_msg_count,
2194 p_data => x_msg_data );
2195
2196 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
2197 FND_LOG.string(FND_LOG.LEVEL_PROCEDURE,G_LOG_HEAD || '.'||l_api_name||'.end'
2198 ,'Create_DeliverEvents >>');
2199 END IF;
2200
2201
2202 EXCEPTION
2203 WHEN FND_API.g_exc_error THEN
2204 ROLLBACK TO Create_DeliverEvents_PVT;
2205 x_return_status := FND_API.g_ret_sts_error;
2206 FND_MSG_PUB.count_and_get
2207 ( p_count => x_msg_count
2208 , p_data => x_msg_data
2209 );
2210 WHEN FND_API.g_exc_unexpected_error THEN
2211 ROLLBACK TO Create_DeliverEvents_PVT;
2212 x_return_status := FND_API.g_ret_sts_unexp_error ;
2213 FND_MSG_PUB.count_and_get
2214 ( p_count => x_msg_count
2215 , p_data => x_msg_data
2216 );
2217
2218 WHEN OTHERS THEN
2219 ROLLBACK TO Create_DeliverEvents_PVT;
2220 x_return_status := fnd_api.g_ret_sts_unexp_error ;
2221
2222 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_UNEXPECTED >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
2223 FND_LOG.string(FND_LOG.LEVEL_UNEXPECTED,G_LOG_HEAD || '.'||l_api_name||l_stmt_num
2224 ,'Create_DeliverEvents : '||l_stmt_num||' : '||substr(SQLERRM,1,200));
2225 END IF;
2226
2227 IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error)
2228 THEN
2229 FND_MSG_PUB.add_exc_msg
2230 ( G_PKG_NAME,
2231 l_api_name || 'Statement -'||to_char(l_stmt_num)
2232 );
2233 END IF;
2234 FND_MSG_PUB.count_and_get
2235 ( p_count => x_msg_count
2236 , p_data => x_msg_data
2237 );
2238
2239 END Create_DeliverEvents;
2240
2241
2242 -- Start of comments
2243 -- API name : Create_RTREvents
2244 -- Type : Private
2245 -- Function : To seed accounting events for RETURN TO RECEIVING transactions.
2246 -- Pre-reqs :
2247 -- Parameters :
2248 -- IN : p_api_version IN NUMBER Required
2249 -- p_init_msg_list IN VARCHAR2 Optional
2250 -- Default = FND_API.G_FALSE
2251 -- p_commit IN VARCHAR2 Optional
2252 -- Default = FND_API.G_FALSE
2253 -- p_validation_level IN NUMBER Optional
2254 -- Default = FND_API.G_VALID_LEVEL_FULL
2255 -- p_rcv_transaction_id IN NUMBER Required
2256 -- p_direct_delivery_flag IN VARCHAR2 Optional
2257 --
2258 -- OUT : x_return_status OUT VARCHAR2(1)
2259 -- x_msg_count OUT NUMBER
2260 -- x_msg_data OUT VARCHAR2(2000)
2261 -- Version :
2262 -- Initial version 1.0
2263 --
2264 --
2265 -- Notes : This API creates all accounting events for RETURN TO RECEIVING transactions
2266 -- in RCV_ACCOUNTING_EVENTS.
2267 --
2268 -- End of comments
2269 PROCEDURE Create_RTREvents(
2270 p_api_version IN NUMBER,
2271 p_init_msg_list IN VARCHAR2,
2272 p_commit IN VARCHAR2,
2273 p_validation_level IN NUMBER,
2274 x_return_status OUT NOCOPY VARCHAR2,
2275 x_msg_count OUT NOCOPY NUMBER,
2276 x_msg_data OUT NOCOPY VARCHAR2,
2277
2278 p_rcv_transaction_id IN NUMBER,
2279 p_direct_delivery_flag IN VARCHAR2
2280 ) IS
2281 l_api_name CONSTANT VARCHAR2(30) := 'Create_RTREvents';
2282 l_api_version CONSTANT NUMBER := 1.0;
2283
2284 l_return_status VARCHAR2(1) := fnd_api.g_ret_sts_success;
2285 l_msg_count NUMBER := 0;
2286 l_msg_data VARCHAR2(8000) := '';
2287 l_stmt_num NUMBER := 0;
2288 l_api_message VARCHAR2(1000);
2289
2290 l_rcv_event RCV_SeedEvents_PVT.rcv_event_rec_type;
2291 l_rcv_events_tbl RCV_SeedEvents_PVT.rcv_event_tbl_type;
2292 l_event_type_id NUMBER;
2293
2294 l_transaction_flows_tbl INV_TRANSACTION_FLOW_PUB.g_transaction_flow_tbl_type;
2295 l_transaction_reverse_flow_rec INV_TRANSACTION_FLOW_PUB.mtl_transaction_flow_rec_type := NULL;
2296 l_trx_flow_exists_flag NUMBER := 0;
2297 l_trx_flow_ctr NUMBER := 0;
2298
2299 l_po_header_id NUMBER;
2300 l_po_distribution_id NUMBER;
2301 l_po_org_id NUMBER;
2302 l_po_sob_id NUMBER;
2303 l_rcv_organization_id NUMBER;
2304 l_rcv_org_id NUMBER;
2305 l_transfer_org_id NUMBER := NULL;
2306 l_transfer_organization_id NUMBER := NULL;
2307 l_rcv_sob_id NUMBER;
2308 l_rcv_trx_date DATE;
2309 l_drop_ship_flag NUMBER;
2310 l_destination_type VARCHAR(25);
2311 l_category_id NUMBER;
2312 l_project_id NUMBER;
2313 l_cross_ou_flag VARCHAR2(1) := 'N';
2314 l_accrual_flag VARCHAR2(1) := 'N';
2315 l_procurement_org_flag VARCHAR2(1) := 'Y';
2316 l_trx_flow_header_id NUMBER;
2317 l_qualifier_code_tbl INV_TRANSACTION_FLOW_PUB.NUMBER_TBL;
2318 l_qualifier_value_tbl INV_TRANSACTION_FLOW_PUB.NUMBER_TBL;
2319 l_encumbrance_flag VARCHAR2(1);
2320 l_ussgl_option VARCHAR2(1);
2321 l_po_document_type_code PO_HEADERS_ALL.type_lookup_code%TYPE;
2322 l_is_shared_proc VARCHAR2(1);
2323 /* Support for Landed Cost Management */
2324 l_lcm_flag VARCHAR2(1);
2325 BEGIN
2326 -- Standard start of API savepoint
2327 SAVEPOINT Create_RTREvents_PVT;
2328
2329 l_stmt_num := 0;
2330
2331 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
2332 FND_LOG.string(FND_LOG.LEVEL_PROCEDURE,G_LOG_HEAD || '.'||l_api_name||'.begin'
2333 ,'Create_RTREvents <<');
2334 END IF;
2335
2336 -- Standard call to check for call compatibility
2337 IF NOT FND_API.Compatible_API_Call (
2338 l_api_version,
2339 p_api_version,
2340 l_api_name,
2341 G_PKG_NAME ) THEN
2342 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2343 END IF;
2344
2345 -- Initialize message list if p_init_msg_list is set to TRUE
2346 IF FND_API.to_Boolean(p_init_msg_list) THEN
2347 FND_MSG_PUB.initialize;
2348 END IF;
2349
2350 -- Initialize API return status to success
2351 x_return_status := FND_API.G_RET_STS_SUCCESS;
2352
2353 -- Unlike for RTV transactions, for RTR transactions, the po_distribution_id
2354 -- is always available.
2355 l_stmt_num := 20;
2356 SELECT
2357 RT.po_header_id,
2358 RT.po_distribution_id,
2359 POD.destination_type_code,
2360 RT.transaction_date,
2361 nvl(RT.dropship_type_code,3),
2362 POH.org_id,
2363 POLL.ship_to_organization_id,
2364 POL.category_id,
2365 POL.project_id,
2366 nvl(POLL.accrue_on_receipt_flag,'N'),
2367 POH.type_lookup_code,
2368 /* Support for Landed Cost Management */
2369 nvl(POLL.lcm_flag, 'N')
2370 INTO l_po_header_id,
2371 l_po_distribution_id,
2372 l_destination_type,
2373 l_rcv_trx_date,
2374 l_drop_ship_flag,
2375 l_po_org_id,
2376 l_rcv_organization_id,
2377 l_category_id,
2378 l_project_id,
2379 l_accrual_flag,
2380 l_po_document_type_code,
2381 /* Support for Landed Cost Management */
2382 l_lcm_flag
2383 FROM po_headers POH,
2384 po_line_locations POLL,
2385 po_lines POL,
2386 po_distributions POD,
2387 rcv_transactions RT
2388 WHERE RT.transaction_id = p_rcv_transaction_id
2389 AND POH.po_header_id = RT.po_header_id
2390 AND POLL.line_location_id = RT.po_line_location_id
2391 AND POL.po_line_id = RT.po_line_id
2392 AND POD.po_distribution_id = RT.po_distribution_id;
2393
2394 l_stmt_num := 30;
2395
2396 -- Get Receiving Operating Unit and SOB
2397 SELECT operating_unit, ledger_id
2398 INTO l_rcv_org_id, l_rcv_sob_id
2399 FROM cst_acct_info_v
2400 WHERE organization_id = l_rcv_organization_id;
2401
2402 l_stmt_num := 35;
2403 -- Get PO SOB
2404 SELECT set_of_books_id
2405 INTO l_po_sob_id
2406 FROM financials_system_parameters;
2407
2408
2409 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
2410 l_api_message := 'Creating RTR Events : RCV Transaction ID : ' || p_rcv_transaction_id ||
2411 ', PO Header ID : ' || l_po_header_id ||
2412 ', PO Dist ID : ' || l_po_distribution_id ||
2413 ', Destination Type : '|| l_destination_type ||
2414 ', Transaction Date : '|| l_rcv_trx_date ||
2415 ', Drop Ship Flag : '|| l_drop_ship_flag ||
2416 ', PO Org ID : ' || l_po_org_id ||
2417 ', PO SOB ID : ' || l_po_sob_id ||
2418 ', RCV Organization ID : '|| l_rcv_organization_id ||
2419 ', RCV Org ID : '|| l_rcv_org_id ||
2420 ', RCV SOB ID : ' || l_rcv_sob_id ||
2421 ', Project ID : '|| l_project_id ||
2422 ', Category ID : ' || l_category_id ||
2423 ', Accrual Flag : ' || l_accrual_flag ;
2424
2425 FND_LOG.string(FND_LOG.LEVEL_STATEMENT,G_LOG_HEAD || '.'||l_api_name||'.'||l_stmt_num
2426 ,l_api_message);
2427 END IF;
2428
2429 -- Only create events for RTR transactions for expense destination types. Other
2430 -- destination types do not have any accounting implications in the Receiving sub-ledger.
2431 IF (l_destination_type <> 'EXPENSE') THEN
2432 return;
2433 END IF;
2434
2435 IF(l_po_org_id <> l_rcv_org_id) THEN
2436 l_cross_ou_flag := 'Y';
2437 END IF;
2438
2439 -- Get transaction flow when procuring and receiving operating units are different.
2440 -- However, for POs with destination type of expense, when there is a project on the
2441 -- PO, we should not look for transaction flow. This is because PA,(which transfers
2442 -- costs to Projects for expense destinations), is currently not supporting global
2443 -- procurement.
2444 IF(l_cross_ou_flag = 'Y' AND l_project_id is NULL) THEN
2445
2446 /* For 11i10, the only supported qualifier is category id. */
2447 l_qualifier_code_tbl(l_qualifier_code_tbl.count+1) := INV_TRANSACTION_FLOW_PUB.G_QUALIFIER_CODE;
2448 l_qualifier_value_tbl(l_qualifier_value_tbl.count+1) := l_category_id;
2449
2450 l_stmt_num := 40;
2451 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
2452 l_api_message := 'Getting Procurement Transaction Flow :'||
2453 'l_po_org_id : '||l_po_org_id||
2454 ' l_rcv_org_id : '||l_rcv_org_id||
2455 ' l_rcv_organization_id : '||l_rcv_organization_id;
2456
2457 FND_LOG.string(FND_LOG.LEVEL_STATEMENT,G_LOG_HEAD || '.'||l_api_name||'.'||l_stmt_num
2458 ,l_api_message);
2459 END IF;
2460
2461 INV_TRANSACTION_FLOW_PUB.GET_TRANSACTION_FLOW(
2462 x_return_status => l_return_status,
2463 x_msg_data => l_msg_data,
2464 x_msg_count => l_msg_count,
2465 x_transaction_flows_tbl => l_transaction_flows_tbl,
2466 p_api_version => 1.0,
2467 p_start_operating_unit => l_po_org_id,
2468 p_end_operating_unit => l_rcv_org_id,
2469 p_flow_type => INV_TRANSACTION_FLOW_PUB.G_PROCURING_FLOW_TYPE,
2470 p_organization_id => l_rcv_organization_id,
2471 p_qualifier_code_tbl => l_qualifier_code_tbl,
2472 p_qualifier_value_tbl => l_qualifier_value_tbl,
2473 p_transaction_date => l_rcv_trx_date,
2474 p_get_default_cost_group=> 'N');
2475 IF (l_return_status = FND_API.g_ret_sts_success) THEN
2476 l_procurement_org_flag := 'N';
2477 l_trx_flow_exists_flag := 1;
2478 l_trx_flow_header_id := l_transaction_flows_tbl(l_transaction_flows_tbl.FIRST).header_id;
2479 l_trx_flow_ctr := l_transaction_flows_tbl.COUNT;
2480 l_transaction_reverse_flow_rec := l_transaction_flows_tbl(l_trx_flow_ctr);
2481 l_transfer_org_id := l_transaction_reverse_flow_rec.from_org_id;
2482 l_transfer_organization_id := l_transaction_reverse_flow_rec.from_organization_id;
2483
2484
2485
2486 -- Bug #5880899. PO does not support centralized procurement for Blankets.
2487 -- Call PO API to verify centralized procurement is supported for this document type.
2488 l_stmt_num := 45;
2489 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
2490 l_api_message := 'Checking if this is a shared proc scenario :'||
2491 ' l_po_document_type_code : '||l_po_document_type_code||
2492 ' l_po_org_id : '||l_po_org_id||
2493 ' l_rcv_org_id : '||l_rcv_org_id||
2494 ' l_rcv_organization_id : '||l_rcv_organization_id||
2495 ' l_trx_flow_header_id : '||l_trx_flow_header_id;
2496
2497 FND_LOG.string(FND_LOG.LEVEL_STATEMENT,G_LOG_HEAD || '.'||l_api_name||'.'||l_stmt_num
2498 ,l_api_message);
2499 END IF;
2500
2501 PO_SHARED_PROC_GRP.check_shared_proc_scenario
2502 (
2503 p_api_version =>1.0,
2504 p_init_msg_list =>FND_API.G_FALSE,
2505 x_return_status =>l_return_status,
2506 p_destination_type_code =>l_destination_type,
2507 p_document_type_code =>l_po_document_type_code,
2508 p_project_id =>l_project_id,
2509 p_purchasing_ou_id =>l_po_org_id,
2510 p_ship_to_inv_org_id =>l_rcv_organization_id,
2511 p_transaction_flow_header_id =>l_trx_flow_header_id,
2512 x_is_shared_proc_scenario =>l_is_shared_proc
2513 );
2514
2515 IF l_return_status <> FND_API.g_ret_sts_success THEN
2516 l_api_message := 'Error in API PO_SHARED_PROC_GRP.check_shared_proc_scenario';
2517 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_UNEXPECTED >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
2518 FND_LOG.string(FND_LOG.LEVEL_UNEXPECTED,G_LOG_HEAD || '.'||l_api_name||l_stmt_num
2519 ,'Create_ReceiveEvents : '||l_stmt_num||' : '||l_api_message);
2520 END IF;
2521 RAISE FND_API.g_exc_unexpected_error;
2522 END IF;
2523
2524 IF l_is_shared_proc IS NULL OR l_is_shared_proc = 'N' THEN
2525 l_is_shared_proc := 'N';
2526 l_trx_flow_exists_flag := 0;
2527 l_trx_flow_header_id := NULL;
2528 END IF;
2529
2530 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
2531 l_api_message := 'Returned from check_shared_proc_scenario :'||
2532 ' l_is_shared_proc :'|| l_is_shared_proc;
2533 FND_LOG.string(FND_LOG.LEVEL_STATEMENT,G_LOG_HEAD || '.'||l_api_name||'.'||l_stmt_num
2534 ,l_api_message);
2535 END IF;
2536
2537
2538
2539 ELSIF (l_return_status = 'W') THEN
2540 l_trx_flow_exists_flag := 0;
2541 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
2542 FND_LOG.string(FND_LOG.LEVEL_EVENT,G_LOG_HEAD||'.'||l_api_name||'.'||l_stmt_num
2543 ,'Transaction Flow does not exist');
2544 END IF;
2545
2546 -- If transaction flow does not exist, but the PO crosses multiple
2547 -- sets of books, error out the transaction.
2548 IF(l_po_sob_id <> l_rcv_sob_id) THEN
2549 l_api_message := 'Transaction Flow does not exist';
2550 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_UNEXPECTED >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
2551 FND_LOG.string(FND_LOG.LEVEL_UNEXPECTED,G_LOG_HEAD || '.'||l_api_name||l_stmt_num
2552 ,'Create_RTREvents : '||l_stmt_num||' : '||l_api_message);
2553 END IF;
2554 RAISE FND_API.g_exc_unexpected_error;
2555 END IF;
2556
2557 ELSE
2558 l_api_message := 'Error occurred in Transaction Flow API';
2559 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_UNEXPECTED >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
2560 FND_LOG.string(FND_LOG.LEVEL_UNEXPECTED,G_LOG_HEAD || '.'||l_api_name||l_stmt_num
2561 ,'Create_RTREvents : '||l_stmt_num||' : '||l_api_message);
2562 END IF;
2563 RAISE FND_API.g_exc_unexpected_error;
2564 END IF;
2565 END IF;
2566
2567 l_stmt_num := 50;
2568 SELECT decode(RT.transaction_type,'CORRECT',RCV_SeedEvents_PVT.CORRECT,
2569 RCV_SeedEvents_PVT.RETURN_TO_RECEIVING)
2570 INTO l_event_type_id
2571 FROM rcv_Transactions RT
2572 WHERE transaction_id = p_rcv_transaction_id;
2573
2574 l_stmt_num := 60;
2575 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
2576 FND_LOG.string(FND_LOG.LEVEL_EVENT,G_LOG_HEAD||'.'||l_api_name||'.'||l_stmt_num
2577 ,'Seeding RTR Event');
2578 END IF;
2579
2580 RCV_SeedEvents_PVT.Seed_RAEEvent(
2581 p_api_version => 1.0,
2582 x_return_status => l_return_status,
2583 x_msg_count => l_msg_count,
2584 x_msg_data => l_msg_data,
2585 p_event_source => 'RECEIVING',
2586 p_event_type_id => l_event_type_id,
2587 p_rcv_transaction_id => p_rcv_transaction_id,
2588 p_inv_distribution_id => NULL,
2589 p_po_distribution_id => l_po_distribution_id,
2590 p_direct_delivery_flag => p_direct_delivery_flag,
2591 p_cross_ou_flag => l_cross_ou_flag,
2592 p_procurement_org_flag => l_procurement_org_flag,
2593 p_ship_to_org_flag => 'Y',
2594 p_drop_ship_flag => l_drop_ship_flag,
2595 p_org_id => l_rcv_org_id,
2596 p_organization_id => l_rcv_organization_id,
2597 p_transfer_org_id => l_transfer_org_id,
2598 p_transfer_organization_id => l_transfer_organization_id,
2599 p_trx_flow_header_id => l_trx_flow_header_id,
2600 p_transaction_forward_flow_rec => NULL,
2601 p_transaction_reverse_flow_rec => l_transaction_reverse_flow_rec,
2602 p_unit_price => NULL,
2603 p_prior_unit_price => NULL,
2604 /* Support for Landed Cost Management */
2605 p_lcm_flag => l_lcm_flag,
2606 x_rcv_event => l_rcv_event);
2607
2608 l_rcv_events_tbl(l_rcv_events_tbl.count + 1) := l_rcv_event;
2609
2610
2611 IF l_return_status <> FND_API.g_ret_sts_success THEN
2612 l_api_message := 'Error creating event';
2613 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_UNEXPECTED >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
2614 FND_LOG.string(FND_LOG.LEVEL_UNEXPECTED,G_LOG_HEAD || '.'||l_api_name||l_stmt_num
2615 ,'Create_RTREvents : '||l_stmt_num||' : '||l_api_message);
2616 END IF;
2617 RAISE FND_API.g_exc_unexpected_error;
2618 END IF;
2619
2620 IF l_trx_flow_exists_flag = 0 THEN
2621 l_stmt_num := 70;
2622 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
2623 FND_LOG.string(FND_LOG.LEVEL_EVENT,G_LOG_HEAD||'.'||l_api_name||'.'||l_stmt_num
2624 ,'Checking if encumbrance events need to be seeded.');
2625 END IF;
2626 RCV_SeedEvents_PVT.Check_EncumbranceFlag(
2627 p_api_version => 1.0,
2628 x_return_status => l_return_status,
2629 x_msg_count => l_msg_count,
2630 x_msg_data => l_msg_data,
2631 p_rcv_sob_id => l_rcv_sob_id,
2632 x_encumbrance_flag => l_encumbrance_flag,
2633 x_ussgl_option => l_ussgl_option);
2634 IF l_return_status <> FND_API.g_ret_sts_success THEN
2635 l_api_message := 'Error in checking for encumbrance flag ';
2636 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_UNEXPECTED >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
2637 FND_LOG.string(FND_LOG.LEVEL_UNEXPECTED,G_LOG_HEAD || '.'||l_api_name||l_stmt_num
2638 ,'Create_RTREvents : '||l_stmt_num||' : '||l_api_message);
2639 END IF;
2640 RAISE FND_API.g_exc_unexpected_error;
2641 END IF;
2642
2643 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
2644 l_api_message := 'Encumbrance Flag : '||l_encumbrance_flag;
2645 FND_LOG.string(FND_LOG.LEVEL_STATEMENT,G_LOG_HEAD||'.'||l_api_name||'.'||l_stmt_num
2646 ,l_api_message);
2647 END IF;
2648
2649 IF(l_encumbrance_flag = 'Y') THEN
2650 l_stmt_num := 80;
2651 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
2652 FND_LOG.string(FND_LOG.LEVEL_EVENT,G_LOG_HEAD||'.'||l_api_name||'.'||l_stmt_num
2653 ,'Seeding Encumbrance Reversal Event');
2654 END IF;
2655
2656
2657 RCV_SeedEvents_PVT.Seed_RAEEvent(
2658 p_api_version => 1.0,
2659 x_return_status => l_return_status,
2660 x_msg_count => l_msg_count,
2661 x_msg_data => l_msg_data,
2662 p_event_source => 'RECEIVING',
2663 p_event_type_id => RCV_SeedEvents_PVT.ENCUMBRANCE_REVERSAL,
2664 p_rcv_transaction_id => p_rcv_transaction_id,
2665 p_inv_distribution_id => NULL,
2666 p_po_distribution_id => l_po_distribution_id,
2667 p_direct_delivery_flag => p_direct_delivery_flag,
2668 p_cross_ou_flag => l_cross_ou_flag,
2669 p_procurement_org_flag => l_procurement_org_flag,
2670 p_ship_to_org_flag => 'Y',
2671 p_drop_ship_flag => l_drop_ship_flag,
2672 p_org_id => l_rcv_org_id,
2673 p_organization_id => l_rcv_organization_id,
2674 p_transfer_org_id => NULL,
2675 p_transfer_organization_id => NULL,
2676 p_transaction_forward_flow_rec => NULL,
2677 p_transaction_reverse_flow_rec => l_transaction_reverse_flow_rec,
2678 p_unit_price => NULL,
2679 p_prior_unit_price => NULL,
2680 /* Support for Landed Cost Management */
2681 p_lcm_flag => l_lcm_flag,
2682 x_rcv_event => l_rcv_event);
2683
2684 /* Bug #3333610. In the case of encumbrance reversals, the quantity to unencumber
2685 may turn out to be zero if the quantity delivered is greater than the quantity
2686 ordered. In such a situation, we should not error out the event. */
2687 IF l_return_status = FND_API.g_ret_sts_success THEN
2688 l_rcv_events_tbl(l_rcv_events_tbl.count + 1) := l_rcv_event;
2689 ELSIF l_return_status <> 'W' THEN
2690 l_api_message := 'Error in seeding encumbrance reversal event';
2691 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_UNEXPECTED >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
2692 FND_LOG.string(FND_LOG.LEVEL_UNEXPECTED,G_LOG_HEAD || '.'||l_api_name||l_stmt_num
2693 ,'Create_RTREvents : '||l_stmt_num||' : '||l_api_message);
2694 END IF;
2695 RAISE FND_API.g_exc_unexpected_error;
2696 END IF;
2697 END IF;
2698 END IF;
2699
2700 l_stmt_num := 90;
2701 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
2702 FND_LOG.string(FND_LOG.LEVEL_EVENT,G_LOG_HEAD||'.'||l_api_name||'.'||l_stmt_num
2703 ,'Inserting events into RAE');
2704 END IF;
2705 RCV_SeedEvents_PVT.Insert_RAEEvents(
2706 p_api_version => 1.0,
2707 x_return_status => l_return_status,
2708 x_msg_count => l_msg_count,
2709 x_msg_data => l_msg_data,
2710 p_rcv_events_tbl => l_rcv_events_tbl,
2711 /* Support for Landed Cost Management */
2712 p_lcm_flag => l_lcm_flag);
2713 IF l_return_status <> FND_API.g_ret_sts_success THEN
2714 l_api_message := 'Error inserting events into RAE';
2715 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_UNEXPECTED >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
2716 FND_LOG.string(FND_LOG.LEVEL_UNEXPECTED,G_LOG_HEAD || '.'||l_api_name||l_stmt_num
2717 ,'Create_RTREvents : '||l_stmt_num||' : '||l_api_message);
2718 END IF;
2719 RAISE FND_API.g_exc_unexpected_error;
2720 END IF;
2721
2722 -- Standard check of p_commit
2723 IF FND_API.to_Boolean(p_commit) THEN
2724 COMMIT WORK;
2725 END IF;
2726
2727 -- Standard Call to get message count and if count = 1, get message info
2728 FND_MSG_PUB.Count_And_Get (
2729 p_count => x_msg_count,
2730 p_data => x_msg_data );
2731
2732 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
2733 FND_LOG.string(FND_LOG.LEVEL_PROCEDURE,G_LOG_HEAD || '.'||l_api_name||'.end'
2734 ,'Create_RTREvents >>');
2735 END IF;
2736
2737
2738 EXCEPTION
2739 WHEN FND_API.g_exc_error THEN
2740 ROLLBACK TO Create_RTREvents_PVT;
2741 x_return_status := FND_API.g_ret_sts_error;
2742 FND_MSG_PUB.count_and_get
2743 ( p_count => x_msg_count
2744 , p_data => x_msg_data
2745 );
2746 WHEN FND_API.g_exc_unexpected_error THEN
2747 ROLLBACK TO Create_RTREvents_PVT;
2748 x_return_status := FND_API.g_ret_sts_unexp_error ;
2749 FND_MSG_PUB.count_and_get
2750 ( p_count => x_msg_count
2751 , p_data => x_msg_data
2752 );
2753
2754 WHEN OTHERS THEN
2755 ROLLBACK TO Create_RTREvents_PVT;
2756 x_return_status := fnd_api.g_ret_sts_unexp_error ;
2757
2758 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_UNEXPECTED >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
2759 FND_LOG.string(FND_LOG.LEVEL_UNEXPECTED,G_LOG_HEAD || '.'||l_api_name||l_stmt_num
2760 ,'Create_RTREvents : '||l_stmt_num||' : '||substr(SQLERRM,1,200));
2761 END IF;
2762
2763 IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error)
2764 THEN
2765 FND_MSG_PUB.add_exc_msg
2766 ( G_PKG_NAME,
2767 l_api_name || 'Statement -'||to_char(l_stmt_num)
2768 );
2769 END IF;
2770 FND_MSG_PUB.count_and_get
2771 ( p_count => x_msg_count
2772 , p_data => x_msg_data
2773 );
2774
2775 END Create_RTREvents;
2776
2777
2778 -- Start of comments
2779 -- API name : Create_RTVEvents
2780 -- Type : Private
2781 -- Function : To seed accounting events for RETURN TO VENDOR transactions.
2782 -- Pre-reqs :
2783 -- Parameters :
2784 -- IN : p_api_version IN NUMBER Required
2785 -- p_init_msg_list IN VARCHAR2 Optional
2786 -- Default = FND_API.G_FALSE
2787 -- p_commit IN VARCHAR2 Optional
2788 -- Default = FND_API.G_FALSE
2789 -- p_validation_level IN NUMBER Optional
2790 -- Default = FND_API.G_VALID_LEVEL_FULL
2791 -- p_rcv_transaction_id IN NUMBER Required
2792 -- p_direct_delivery_flag IN VARCHAR2 Optional
2793 --
2794 -- OUT : x_return_status OUT VARCHAR2(1)
2795 -- x_msg_count OUT NUMBER
2796 -- x_msg_data OUT VARCHAR2(2000)
2797 -- Version :
2798 -- Initial version 1.0
2799 --
2800 --
2801 -- Notes : This API creates all accounting events for RETURN TO VENDOR transactions
2802 -- in RCV_ACCOUNTING_EVENTS.
2803 --
2804 -- End of comments
2805 PROCEDURE Create_RTVEvents(
2806 p_api_version IN NUMBER,
2807 p_init_msg_list IN VARCHAR2,
2808 p_commit IN VARCHAR2,
2809 p_validation_level IN NUMBER,
2810 x_return_status OUT NOCOPY VARCHAR2,
2811 x_msg_count OUT NOCOPY NUMBER,
2812 x_msg_data OUT NOCOPY VARCHAR2,
2813
2814 p_rcv_transaction_id IN NUMBER,
2815 p_direct_delivery_flag IN VARCHAR2
2816 ) IS
2817 l_api_name CONSTANT VARCHAR2(30) := 'Create_RTVEvents';
2818 l_api_version CONSTANT NUMBER := 1.0;
2819
2820 l_return_status VARCHAR2(1) := fnd_api.g_ret_sts_success;
2821 l_msg_count NUMBER := 0;
2822 l_msg_data VARCHAR2(8000) := '';
2823 l_stmt_num NUMBER := 0;
2824 l_api_message VARCHAR2(1000);
2825
2826 l_rcv_event RCV_SeedEvents_PVT.rcv_event_rec_type;
2827 l_rcv_events_tbl RCV_SeedEvents_PVT.rcv_event_tbl_type;
2828 l_event_type_id NUMBER;
2829
2830
2831 l_transaction_flows_tbl INV_TRANSACTION_FLOW_PUB.g_transaction_flow_tbl_type;
2832 l_transaction_forward_flow_rec INV_TRANSACTION_FLOW_PUB.mtl_transaction_flow_rec_type;
2833 l_transaction_reverse_flow_rec INV_TRANSACTION_FLOW_PUB.mtl_transaction_flow_rec_type;
2834 l_trx_flow_exists_flag NUMBER := 0;
2835 l_trx_flow_ctr NUMBER := 0;
2836
2837
2838 l_po_header_id NUMBER;
2839 l_po_line_id NUMBER;
2840 l_po_line_location_id NUMBER;
2841 l_po_distribution_id NUMBER;
2842 l_po_org_id NUMBER;
2843 l_po_sob_id NUMBER;
2844 l_rcv_organization_id NUMBER;
2845 l_rcv_org_id NUMBER;
2846 l_rcv_sob_id NUMBER;
2847 l_org_id NUMBER;
2848 l_transfer_org_id NUMBER;
2849 l_transfer_organization_id NUMBER;
2850 l_rcv_trx_date DATE;
2851 l_drop_ship_flag NUMBER;
2852 l_destination_type VARCHAR(25);
2853 l_item_id NUMBER;
2854 l_category_id NUMBER;
2855 l_project_id NUMBER;
2856 l_cross_ou_flag VARCHAR2(1);
2857 l_accrual_flag VARCHAR2(1);
2858 l_counter NUMBER;
2859 l_procurement_org_flag VARCHAR2(1);
2860 l_trx_flow_header_id NUMBER;
2861
2862
2863 l_po_document_type_code PO_HEADERS_ALL.type_lookup_code%TYPE;
2864 l_is_shared_proc VARCHAR2(1);
2865 /* Support for Landed Cost Management */
2866 l_lcm_flag VARCHAR2(1);
2867
2868 l_qualifier_code_tbl INV_TRANSACTION_FLOW_PUB.NUMBER_TBL;
2869 l_qualifier_value_tbl INV_TRANSACTION_FLOW_PUB.NUMBER_TBL;
2870
2871 CURSOR c_po_distributions_csr(p_po_distribution_id NUMBER, p_po_line_location_id NUMBER) IS
2872 SELECT po_distribution_id,destination_type_code, project_id
2873 FROM po_distributions POD
2874 WHERE POD.po_distribution_id = NVL(p_po_distribution_id,POD.po_distribution_id)
2875 AND POD.line_location_id = p_po_line_location_id;
2876
2877
2878 BEGIN
2879 -- Standard start of API savepoint
2880 SAVEPOINT Create_RTVEvents_PVT;
2881
2882 l_stmt_num := 0;
2883
2884 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
2885 FND_LOG.string(FND_LOG.LEVEL_PROCEDURE,G_LOG_HEAD || '.'||l_api_name||'.begin'
2886 ,'Create_RTVEvents <<');
2887 END IF;
2888
2889 -- Standard call to check for call compatibility
2890 IF NOT FND_API.Compatible_API_Call (
2891 l_api_version,
2892 p_api_version,
2893 l_api_name,
2894 G_PKG_NAME ) THEN
2895 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2896 END IF;
2897
2898 -- Initialize message list if p_init_msg_list is set to TRUE
2899 IF FND_API.to_Boolean(p_init_msg_list) THEN
2900 FND_MSG_PUB.initialize;
2901 END IF;
2902
2903 -- Initialize API return status to success
2904 x_return_status := FND_API.G_RET_STS_SUCCESS;
2905
2906 l_stmt_num := 20;
2907 SELECT
2908 RT.po_header_id,
2909 RT.po_line_id,
2910 RT.po_line_location_id,
2911 RT.po_distribution_id,
2912 RT.transaction_date,
2913 nvl(RT.dropship_type_code,3),
2914 POH.org_id,
2915 POLL.ship_to_organization_id,
2916 POL.item_id,
2917 POL.category_id,
2918 POL.project_id,
2919 nvl(POLL.accrue_on_receipt_flag,'N'),
2920 POH.type_lookup_code,
2921 /* Support for Landed Cost Management */
2922 nvl(POLL.lcm_flag, 'N')
2923 INTO l_po_header_id,
2924 l_po_line_id,
2925 l_po_line_location_id,
2926 l_po_distribution_id,
2927 l_rcv_trx_date,
2928 l_drop_ship_flag,
2929 l_po_org_id,
2930 l_rcv_organization_id,
2931 l_item_id,
2932 l_category_id,
2933 l_project_id,
2934 l_accrual_flag,
2935 l_po_document_type_code,
2936 /* Support for Landed Cost Management */
2937 l_lcm_flag
2938 FROM po_headers POH,
2939 po_line_locations POLL,
2940 po_lines POL,
2941 rcv_transactions RT
2942 WHERE RT.transaction_id = p_rcv_transaction_id
2943 AND POH.po_header_id = RT.po_header_id
2944 AND POLL.line_location_id = RT.po_line_location_id
2945 AND POL.po_line_id = RT.po_line_id;
2946
2947 l_stmt_num := 30;
2948 -- Get Receiving Operating Unit
2949 SELECT operating_unit, ledger_id
2950 INTO l_rcv_org_id, l_rcv_sob_id
2951 FROM cst_acct_info_v
2952 WHERE organization_id = l_rcv_organization_id;
2953
2954 l_stmt_num := 35;
2955 -- Get PO SOB
2956 SELECT set_of_books_id
2957 INTO l_po_sob_id
2958 FROM financials_system_parameters;
2959
2960 l_stmt_num := 40;
2961 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
2962 l_api_message := 'Creating RTV Events : RCV Transaction ID : ' || p_rcv_transaction_id ||
2963 ', PO Header ID : ' || l_po_header_id ||
2964 ', PO Line ID : ' || l_po_line_id ||
2965 ', PO Line Location ID : ' || l_po_line_location_id ||
2966 ', PO Dist ID : ' || l_po_distribution_id ||
2967 ', Transaction Date : '|| l_rcv_trx_date ||
2968 ', Drop Ship Flag : '|| l_drop_ship_flag ||
2969 ', PO Org ID : ' || l_po_org_id ||
2970 ', PO SOB ID : ' || l_po_sob_id ||
2971 ', RCV Organization ID : '|| l_rcv_organization_id ||
2972 ', RCV Org ID : '|| l_rcv_org_id ||
2973 ', RCV SOB ID : ' || l_rcv_sob_id ||
2974 ', Category ID : ' || l_category_id ||
2975 ', Accrual Flag : ' || l_accrual_flag ;
2976
2977 FND_LOG.string(FND_LOG.LEVEL_STATEMENT,G_LOG_HEAD || '.'||l_api_name||'.'||l_stmt_num
2978 ,l_api_message);
2979 END IF;
2980
2981 IF(l_po_org_id = l_rcv_org_id) THEN
2982 l_cross_ou_flag := 'N';
2983 ELSE
2984 l_cross_ou_flag := 'Y';
2985
2986 /* For 11i10, the only supported qualifier is category id. */
2987 l_qualifier_code_tbl(l_qualifier_code_tbl.count+1) := INV_TRANSACTION_FLOW_PUB.G_QUALIFIER_CODE;
2988 l_qualifier_value_tbl(l_qualifier_value_tbl.count+1) := l_category_id;
2989
2990
2991 l_stmt_num := 50;
2992 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
2993 l_api_message := 'Getting Procurement Transaction Flow :'||
2994 'l_po_org_id : '||l_po_org_id||
2995 ' l_rcv_org_id : '||l_rcv_org_id||
2996 ' l_rcv_organization_id : '||l_rcv_organization_id;
2997
2998 FND_LOG.string(FND_LOG.LEVEL_STATEMENT,G_LOG_HEAD || '.'||l_api_name||'.'||l_stmt_num
2999 ,l_api_message);
3000 END IF;
3001
3002 INV_TRANSACTION_FLOW_PUB.GET_TRANSACTION_FLOW(
3003 x_return_status => l_return_status,
3004 x_msg_data => l_msg_data,
3005 x_msg_count => l_msg_count,
3006 x_transaction_flows_tbl => l_transaction_flows_tbl,
3007 p_api_version => 1.0,
3008 p_start_operating_unit => l_po_org_id,
3009 p_end_operating_unit => l_rcv_org_id,
3010 p_flow_type => INV_TRANSACTION_FLOW_PUB.G_PROCURING_FLOW_TYPE,
3011 p_organization_id => l_rcv_organization_id,
3012 p_qualifier_code_tbl => l_qualifier_code_tbl,
3013 p_qualifier_value_tbl => l_qualifier_value_tbl,
3014 p_transaction_date => l_rcv_trx_date,
3015 p_get_default_cost_group=> 'N');
3016
3017 IF (l_return_status = FND_API.g_ret_sts_success) THEN
3018 l_trx_flow_exists_flag := 1;
3019 l_trx_flow_header_id := l_transaction_flows_tbl(l_transaction_flows_tbl.FIRST).header_id;
3020 -- Return Status of 'W' indicates that no transaction flow exists.
3021 ELSIF (l_return_status = 'W') THEN
3022 l_trx_flow_exists_flag := 0;
3023 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
3024 FND_LOG.string(FND_LOG.LEVEL_EVENT,G_LOG_HEAD||'.'||l_api_name||'.'||l_stmt_num
3025 ,'Transaction Flow does not exist');
3026 END IF;
3027
3028 -- If transaction flow does not exist, but the PO crosses multiple
3029 -- sets of books, error out the transaction.
3030 IF(l_po_sob_id <> l_rcv_sob_id) THEN
3031 l_api_message := 'Transaction Flow does not exist';
3032 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_UNEXPECTED >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
3033 FND_LOG.string(FND_LOG.LEVEL_UNEXPECTED,G_LOG_HEAD || '.'||l_api_name||l_stmt_num
3034 ,'Create_RTVEvents : '||l_stmt_num||' : '||l_api_message);
3035 END IF;
3036 RAISE FND_API.g_exc_unexpected_error;
3037 END IF;
3038
3039 ELSE
3040 l_api_message := 'Error occurred in Transaction Flow API';
3041 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_UNEXPECTED >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
3042 FND_LOG.string(FND_LOG.LEVEL_UNEXPECTED,G_LOG_HEAD || '.'||l_api_name||l_stmt_num
3043 ,'Create_RTVEvents : '||l_stmt_num||' : '||l_api_message);
3044 END IF;
3045 RAISE FND_API.g_exc_unexpected_error;
3046 END IF; -- IF l_return_status
3047 END IF; -- IF l_po_org_id
3048
3049
3050 -- For the RTV transaction, the PO distribution may not be available in the
3051 -- case of Standard Receipt. Hence perform all steps for each applicable distribution.
3052 -- If distribution is not available the quantity will be prorated. Furthermore, if
3053 -- there is a project on any of the distributions, and the destination_type_code is
3054 -- expense, the transaction flow should be ignored for just that distribution.
3055 FOR rec_pod IN c_po_distributions_csr(l_po_distribution_id, l_po_line_location_id) LOOP
3056
3057 l_stmt_num := 50;
3058
3059 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
3060 l_api_message := 'Creating Events : '||
3061 'po_distribution_id : '||rec_pod.po_distribution_id||
3062 ' destination_type_code : '||rec_pod.destination_type_code||
3063 ' project_id : '||rec_pod.project_id;
3064 FND_LOG.string(FND_LOG.LEVEL_STATEMENT,G_LOG_HEAD || '.'||l_api_name||'.'||l_stmt_num
3065 ,l_api_message);
3066 END IF;
3067
3068
3069 l_procurement_org_flag := 'Y';
3070
3071 -- Bug #5880899. PO does not support centralized procurement for Blankets.
3072 -- Call PO API to verify centralized procurement is supported for this document type.
3073 IF (l_trx_flow_exists_flag = 1) THEN
3074 l_stmt_num := 45;
3075 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
3076 l_api_message := 'Checking if this is a shared proc scenario :'||
3077 ' l_po_document_type_code : '||l_po_document_type_code||
3078 ' l_po_org_id : '||l_po_org_id||
3079 ' l_rcv_org_id : '||l_rcv_org_id||
3080 ' l_rcv_organization_id : '||l_rcv_organization_id||
3081 ' l_trx_flow_header_id : '||l_trx_flow_header_id;
3082
3083 FND_LOG.string(FND_LOG.LEVEL_STATEMENT,G_LOG_HEAD || '.'||l_api_name||'.'||l_stmt_num
3084 ,l_api_message);
3085 END IF;
3086
3087 PO_SHARED_PROC_GRP.check_shared_proc_scenario
3088 (
3089 p_api_version =>1.0,
3090 p_init_msg_list =>FND_API.G_FALSE,
3091 x_return_status =>l_return_status,
3092 p_destination_type_code =>rec_pod.destination_type_code,
3093 p_document_type_code =>l_po_document_type_code,
3094 p_project_id =>rec_pod.project_id,
3095 p_purchasing_ou_id =>l_po_org_id,
3096 p_ship_to_inv_org_id =>l_rcv_organization_id,
3097 p_transaction_flow_header_id =>l_trx_flow_header_id,
3098 x_is_shared_proc_scenario =>l_is_shared_proc
3099 );
3100
3101 IF l_return_status <> FND_API.g_ret_sts_success THEN
3102 l_api_message := 'Error in API PO_SHARED_PROC_GRP.check_shared_proc_scenario';
3103 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_UNEXPECTED >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
3104 FND_LOG.string(FND_LOG.LEVEL_UNEXPECTED,G_LOG_HEAD || '.'||l_api_name||l_stmt_num
3105 ,'Create_ReceiveEvents : '||l_stmt_num||' : '||l_api_message);
3106 END IF;
3107 RAISE FND_API.g_exc_unexpected_error;
3108 END IF;
3109
3110 IF l_is_shared_proc IS NULL OR l_is_shared_proc = 'N' THEN
3111 l_is_shared_proc := 'N';
3112 l_trx_flow_exists_flag := 0;
3113 l_trx_flow_header_id := NULL;
3114 END IF;
3115
3116
3117 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
3118 l_api_message := 'Returned from check_shared_proc_scenario :'||
3119 ' l_is_shared_proc :'|| l_is_shared_proc;
3120 FND_LOG.string(FND_LOG.LEVEL_STATEMENT,G_LOG_HEAD || '.'||l_api_name||'.'||l_stmt_num
3121 ,l_api_message);
3122 END IF;
3123 END IF;
3124
3125 -- For POs with destination type of expense, when there is a project on the
3126 -- POD, we should not look for transaction flow. This is because PA,(which transfers
3127 -- costs to Projects for expense destinations), is currently not supporting global
3128 -- procurement.
3129 IF((l_trx_flow_exists_flag = 1) AND
3130 (rec_pod.project_id is NULL OR rec_pod.destination_type_code <> 'EXPENSE')AND
3131 (l_is_shared_proc = 'Y')) THEN
3132
3133 l_trx_flow_ctr := l_transaction_flows_tbl.COUNT;
3134 -- Create Logical RTV transactions in each intermediate organization.
3135 FOR l_counter IN l_transaction_flows_tbl.FIRST..l_transaction_flows_tbl.LAST LOOP
3136
3137 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
3138 FND_LOG.string(FND_LOG.LEVEL_EVENT,G_LOG_HEAD||'.'||l_api_name||'.'||l_stmt_num
3139 ,'Seeding Logical RTV in RAE');
3140 END IF;
3141
3142 l_stmt_num := 60;
3143 -- l_transaction_forward_flow_rec contains the transaction flow record
3144 -- where the org_id is the from_org_id.
3145 -- l_transaction_reverse_flow_rec contains the transaction flow record
3146 -- where the org_id is the to_org_id.
3147 -- Need to pass both to the Seed_RAE procedure because transfer_price is based
3148 -- on the reverse flow record and some accounts are based on the forward flow
3149
3150 l_transaction_forward_flow_rec := l_transaction_flows_tbl(l_counter);
3151 IF(l_counter = l_transaction_flows_tbl.FIRST) THEN
3152 l_transaction_reverse_flow_rec := NULL;
3153 l_transfer_org_id := NULL;
3154 l_transfer_organization_id := NULL;
3155 ELSE
3156 l_transaction_reverse_flow_rec := l_transaction_flows_tbl(l_counter - 1);
3157 l_transfer_org_id := l_transaction_reverse_flow_rec.from_org_id;
3158 l_transfer_organization_id := l_transaction_reverse_flow_rec.from_organization_id;
3159 END IF;
3160
3161 RCV_SeedEvents_PVT.Seed_RAEEvent(
3162 p_api_version => 1.0,
3163 x_return_status => l_return_status,
3164 x_msg_count => l_msg_count,
3165 x_msg_data => l_msg_data,
3166 p_event_source => 'RECEIVING',
3167 p_event_type_id => RCV_SeedEvents_PVT.LOGICAL_RETURN_TO_VENDOR,
3168 p_rcv_transaction_id => p_rcv_transaction_id,
3169 p_inv_distribution_id => NULL,
3170 p_po_distribution_id => rec_pod.po_distribution_id,
3171 p_direct_delivery_flag => p_direct_delivery_flag,
3172 p_cross_ou_flag => l_cross_ou_flag,
3173 p_procurement_org_flag => l_procurement_org_flag,
3174 p_ship_to_org_flag => 'N',
3175 p_drop_ship_flag => l_drop_ship_flag,
3176 p_org_id => l_transaction_flows_tbl(l_counter).from_org_id,
3177 p_organization_id => l_transaction_flows_tbl(l_counter).from_organization_id,
3178 p_transfer_org_id => l_transfer_org_id,
3179 p_transfer_organization_id => l_transfer_organization_id,
3180 p_trx_flow_header_id => l_trx_flow_header_id,
3181 p_transaction_forward_flow_rec => l_transaction_forward_flow_rec,
3182 p_transaction_reverse_flow_rec => l_transaction_reverse_flow_rec,
3183 p_unit_price => NULL,
3184 p_prior_unit_price => NULL,
3185 /* Support for Landed Cost Management */
3186 p_lcm_flag => l_lcm_flag,
3187 x_rcv_event => l_rcv_event);
3188
3189 IF l_return_status <> FND_API.g_ret_sts_success THEN
3190 l_api_message := 'Error creating event';
3191 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_UNEXPECTED >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
3192 FND_LOG.string(FND_LOG.LEVEL_UNEXPECTED,G_LOG_HEAD || '.'||l_api_name||l_stmt_num
3193 ,'Create_RTVEvents : '||l_stmt_num||' : '||l_api_message);
3194 END IF;
3195 RAISE FND_API.g_exc_unexpected_error;
3196 END IF;
3197
3198 l_rcv_events_tbl(l_rcv_events_tbl.count + 1) := l_rcv_event;
3199
3200 -- For one-time items, if online accruals is used, seed IC Invoice event.
3201 -- For Shop Floor destination types, always seed IC Invoice events.
3202 IF((l_item_id is NULL and l_accrual_flag = 'Y')OR
3203 (rec_pod.destination_type_code = 'SHOP FLOOR')) THEN
3204 l_stmt_num := 70;
3205 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
3206 FND_LOG.string(FND_LOG.LEVEL_EVENT,G_LOG_HEAD||'.'||l_api_name||'.'||l_stmt_num
3207 ,'Seeding Invoice Match in RAE');
3208 END IF;
3209
3210 RCV_SeedEvents_PVT.Seed_RAEEvent(
3211 p_api_version => 1.0,
3212 x_return_status => l_return_status,
3213 x_msg_count => l_msg_count,
3214 x_msg_data => l_msg_data,
3215 p_event_source => 'RECEIVING',
3216 p_event_type_id => RCV_SeedEvents_PVT.INTERCOMPANY_REVERSAL,
3217 p_rcv_transaction_id => p_rcv_transaction_id,
3218 p_inv_distribution_id => NULL,
3219 p_po_distribution_id => rec_pod.po_distribution_id,
3220 p_direct_delivery_flag => p_direct_delivery_flag,
3221 p_cross_ou_flag => l_cross_ou_flag,
3222 p_procurement_org_flag => l_procurement_org_flag,
3223 p_ship_to_org_flag => 'N',
3224 p_drop_ship_flag => l_drop_ship_flag,
3225 p_org_id => l_transaction_flows_tbl(l_counter).from_org_id,
3226 p_organization_id => l_transaction_flows_tbl(l_counter).from_organization_id,
3227 p_transfer_org_id => l_transaction_flows_tbl(l_counter).to_org_id,
3228 p_transfer_organization_id => l_transaction_flows_tbl(l_counter).to_organization_id,
3229 p_trx_flow_header_id => l_trx_flow_header_id,
3230 p_transaction_forward_flow_rec => l_transaction_forward_flow_rec,
3231 p_transaction_reverse_flow_rec => l_transaction_reverse_flow_rec,
3232 p_unit_price => NULL,
3233 p_prior_unit_price => NULL,
3234 /* Support for Landed Cost Management */
3235 p_lcm_flag => l_lcm_flag,
3236 x_rcv_event => l_rcv_event);
3237
3238 IF l_return_status <> FND_API.g_ret_sts_success THEN
3239 l_api_message := 'Error creating event';
3240 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_UNEXPECTED >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
3241 FND_LOG.string(FND_LOG.LEVEL_UNEXPECTED,G_LOG_HEAD || '.'||l_api_name||l_stmt_num
3242 ,'Create_RTVEvents : '||l_stmt_num||' : '||l_api_message);
3243 END IF;
3244 RAISE FND_API.g_exc_unexpected_error;
3245 END IF;
3246
3247 l_rcv_events_tbl(l_rcv_events_tbl.count + 1) := l_rcv_event;
3248 END IF;
3249
3250 l_procurement_org_flag := 'N';
3251 END LOOP;
3252 END IF;
3253
3254 l_stmt_num := 80;
3255 IF (l_trx_flow_exists_flag = 1) THEN
3256 l_transaction_forward_flow_rec := NULL;
3257 l_transaction_reverse_flow_rec := l_transaction_flows_tbl(l_trx_flow_ctr);
3258 l_org_id := l_transaction_flows_tbl(l_trx_flow_ctr).to_org_id;
3259 l_transfer_org_id := l_transaction_flows_tbl(l_trx_flow_ctr).from_org_id;
3260 l_transfer_organization_id := l_transaction_reverse_flow_rec.from_organization_id;
3261 ELSE
3262 l_transaction_forward_flow_rec := NULL;
3263 l_transaction_reverse_flow_rec := NULL;
3264 l_org_id := l_po_org_id;
3265 l_transfer_org_id := NULL;
3266 l_transfer_organization_id := NULL;
3267 END IF;
3268
3269 l_stmt_num := 90;
3270
3271 -- The drop ship flag is not applicable in the case of returns. There will always
3272 -- be a physical receipt in the procuring org.
3273 l_stmt_num := 110;
3274 SELECT decode(RT.transaction_type,'CORRECT',RCV_SeedEvents_PVT.CORRECT,
3275 RCV_SeedEvents_PVT.RETURN_TO_VENDOR)
3276 INTO l_event_type_id
3277 FROM rcv_Transactions RT
3278 WHERE transaction_id = p_rcv_transaction_id;
3279
3280 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
3281 FND_LOG.string(FND_LOG.LEVEL_EVENT,G_LOG_HEAD||'.'||l_api_name||'.'||l_stmt_num
3282 ,'Seeding RTV in RAE');
3283 END IF;
3284
3285 l_stmt_num := 120;
3286 RCV_SeedEvents_PVT.Seed_RAEEvent(
3287 p_api_version => 1.0,
3288 x_return_status => l_return_status,
3289 x_msg_count => l_msg_count,
3290 x_msg_data => l_msg_data,
3291 p_event_source => 'RECEIVING',
3292 p_event_type_id => l_event_type_id,
3293 p_rcv_transaction_id => p_rcv_transaction_id,
3294 p_inv_distribution_id => NULL,
3295 p_po_distribution_id => rec_pod.po_distribution_id,
3296 p_direct_delivery_flag => p_direct_delivery_flag,
3297 p_cross_ou_flag => l_cross_ou_flag,
3298 p_procurement_org_flag => l_procurement_org_flag,
3299 p_ship_to_org_flag => 'Y',
3300 p_drop_ship_flag => l_drop_ship_flag,
3301 p_org_id => l_org_id,
3302 p_organization_id => l_rcv_organization_id,
3303 p_transfer_org_id => l_transfer_org_id,
3304 p_transfer_organization_id => l_transfer_organization_id,
3305 p_trx_flow_header_id => l_trx_flow_header_id,
3306 p_transaction_forward_flow_rec => l_transaction_forward_flow_rec,
3307 p_transaction_reverse_flow_rec => l_transaction_reverse_flow_rec,
3308 p_unit_price => NULL,
3309 p_prior_unit_price => NULL,
3310 /* Support for Landed Cost Management */
3311 p_lcm_flag => l_lcm_flag,
3312 x_rcv_event => l_rcv_event);
3313 IF l_return_status <> FND_API.g_ret_sts_success THEN
3314 l_api_message := 'Error creating event';
3315 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_UNEXPECTED >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
3316 FND_LOG.string(FND_LOG.LEVEL_UNEXPECTED,G_LOG_HEAD || '.'||l_api_name||l_stmt_num
3317 ,'Create_RTVEvents : '||l_stmt_num||' : '||l_api_message);
3318 END IF;
3319 RAISE FND_API.g_exc_unexpected_error;
3320 END IF;
3321
3322 l_rcv_events_tbl(l_rcv_events_tbl.count + 1) := l_rcv_event;
3323
3324 END LOOP;
3325
3326 l_stmt_num := 130;
3327 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
3328 FND_LOG.string(FND_LOG.LEVEL_EVENT,G_LOG_HEAD||'.'||l_api_name||'.'||l_stmt_num
3329 ,'Inserting events into RAE');
3330 END IF;
3331 RCV_SeedEvents_PVT.Insert_RAEEvents(
3332 p_api_version => 1.0,
3333 x_return_status => l_return_status,
3334 x_msg_count => l_msg_count,
3335 x_msg_data => l_msg_data,
3336 p_rcv_events_tbl => l_rcv_events_tbl,
3337 /* Support for Landed Cost Management */
3338 p_lcm_flag => l_lcm_flag);
3339 IF l_return_status <> FND_API.g_ret_sts_success THEN
3340 l_api_message := 'Error inserting events into RAE';
3341 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_UNEXPECTED >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
3342 FND_LOG.string(FND_LOG.LEVEL_UNEXPECTED,G_LOG_HEAD || '.'||l_api_name||l_stmt_num
3343 ,'Create_RTVEvents : '||l_stmt_num||' : '||l_api_message);
3344 END IF;
3345 RAISE FND_API.g_exc_unexpected_error;
3346 END IF;
3347
3348 IF(l_trx_flow_exists_flag = 1 and l_item_id IS NOT NULL) THEN
3349 l_stmt_num := 140;
3350 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
3351 FND_LOG.string(FND_LOG.LEVEL_EVENT,G_LOG_HEAD||'.'||l_api_name||'.'||l_stmt_num
3352 ,'Inserting events into MMT');
3353 END IF;
3354 RCV_SeedEvents_PVT.Insert_MMTEvents(
3355 p_api_version => 1.0,
3356 x_return_status => l_return_status,
3357 x_msg_count => l_msg_count,
3358 x_msg_data => l_msg_data,
3359 p_rcv_events_tbl => l_rcv_events_tbl);
3360 IF l_return_status <> FND_API.g_ret_sts_success THEN
3361 l_api_message := 'Error inserting events into MMT';
3362 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_UNEXPECTED >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
3363 FND_LOG.string(FND_LOG.LEVEL_UNEXPECTED,G_LOG_HEAD || '.'||l_api_name||l_stmt_num
3364 ,'Create_RTVEvents : '||l_stmt_num||' : '||l_api_message);
3365 END IF;
3366 RAISE FND_API.g_exc_unexpected_error;
3367 END IF;
3368 END IF;
3369
3370 -- Standard check of p_commit
3371 IF FND_API.to_Boolean(p_commit) THEN
3372 COMMIT WORK;
3373 END IF;
3374
3375 -- Standard Call to get message count and if count = 1, get message info
3376 FND_MSG_PUB.Count_And_Get (
3377 p_count => x_msg_count,
3378 p_data => x_msg_data );
3379
3380 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
3381 FND_LOG.string(FND_LOG.LEVEL_PROCEDURE,G_LOG_HEAD || '.'||l_api_name||'.end'
3382 ,'Create_RTVEvents >>');
3383 END IF;
3384
3385
3386 EXCEPTION
3387 WHEN FND_API.g_exc_error THEN
3388 ROLLBACK TO Create_RTVEvents_PVT;
3389 x_return_status := FND_API.g_ret_sts_error;
3390 FND_MSG_PUB.count_and_get
3391 ( p_count => x_msg_count
3392 , p_data => x_msg_data
3393 );
3394 WHEN FND_API.g_exc_unexpected_error THEN
3395 ROLLBACK TO Create_RTVEvents_PVT;
3396 x_return_status := FND_API.g_ret_sts_unexp_error ;
3397 FND_MSG_PUB.count_and_get
3398 ( p_count => x_msg_count
3399 , p_data => x_msg_data
3400 );
3401
3402 WHEN OTHERS THEN
3403 ROLLBACK TO Create_RTVEvents_PVT;
3404 x_return_status := fnd_api.g_ret_sts_unexp_error ;
3405
3406 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_UNEXPECTED >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
3407 FND_LOG.string(FND_LOG.LEVEL_UNEXPECTED,G_LOG_HEAD || '.'||l_api_name||l_stmt_num
3408 ,'Create_RTVEvents : '||l_stmt_num||' : '||substr(SQLERRM,1,200));
3409 END IF;
3410
3411 IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error)
3412 THEN
3413 FND_MSG_PUB.add_exc_msg
3414 ( G_PKG_NAME,
3415 l_api_name || 'Statement -'||to_char(l_stmt_num)
3416 );
3417 END IF;
3418 FND_MSG_PUB.count_and_get
3419 ( p_count => x_msg_count
3420 , p_data => x_msg_data
3421 );
3422
3423 END Create_RTVEvents;
3424
3425 -- Start of comments
3426 -- API name : Get_InvTransactionInfo
3427 -- Type : Private
3428 -- Pre-reqs :
3429 -- Function : To return the transfer price and distribution account in
3430 -- global procurement and drop shipment scenarios.
3431 -- Parameters :
3432 -- IN : p_api_version IN NUMBER Required
3433 -- p_init_msg_list IN VARCHAR2 Optional
3434 -- Default = FND_API.G_FALSE
3435 -- p_commit IN VARCHAR2 Optional
3436 -- Default = FND_API.G_FALSE
3437 -- p_validation_level IN NUMBER Optional
3438 -- Default = FND_API.G_VALID_LEVEL_FULL
3439 -- p_rcv_transaction_id IN NUMBER Required
3440 --
3441 -- OUT : x_return_status OUT VARCHAR2(1)
3442 -- x_msg_count OUT NUMBER
3443 -- x_msg_data OUT VARCHAR2(2000)
3444 -- x_intercompany_pricing_option OUT NUMBER
3445 -- x_currency_code OUT VARCHAR2
3446 -- x_currency_conversion_rate OUT NUMBER
3447 -- x_currency_conversion_date OUT DATE
3448 -- x_currency_conversion_type OUT VARCHAR2(30)
3449 -- x_distribution_acct_id OUT NUMBER
3450 -- Version :
3451 -- Initial version 1.0
3452 --
3453 -- Notes :
3454 -- This API is called by the receiving transaction processor for Deliver, RTR
3455 -- and Corrections to Deliver/RTR transactions, to determine if the price to be
3456 -- stamped on MMTT is the PO price or the transfer price. This API returns a
3457 -- flag to indicate if transfer price is to be used. If this flag is set to 'Y',
3458 -- the transfer price and the corresponding currency code are returned. The
3459 -- transfer price is returned in the transaction UOM.
3460 -- If the returned transfer price flag is 'N', the Receiving transaction
3461 -- Processor should stamp the PO price as usual.
3462 --
3463 -- This API also returns the distribution account for External Drop Shipments
3464 -- when the new accounting flag is checked. If the returned distribution account
3465 -- is -1, the Receiving transaction processor should stamp the MMTT transaction
3466 -- with the Receiving Inspection account as usual.
3467 -- Otherwise, it should stamp the returned Clearing Account.
3468 --
3469 -- End of comments
3470 -------------------------------------------------------------------------------
3471 PROCEDURE Get_InvTransactionInfo(
3472 p_api_version IN NUMBER,
3473 p_init_msg_list IN VARCHAR2,
3474 p_commit IN VARCHAR2,
3475 p_validation_level IN VARCHAR2,
3476 x_return_status OUT NOCOPY VARCHAR2,
3477 x_msg_count OUT NOCOPY NUMBER,
3478 x_msg_data OUT NOCOPY VARCHAR2,
3479
3480 p_rcv_transaction_id IN NUMBER,
3481
3482 x_intercompany_pricing_option OUT NOCOPY NUMBER,
3483 x_transfer_price OUT NOCOPY NUMBER,
3484 x_currency_code OUT NOCOPY VARCHAR2,
3485 x_currency_conversion_rate OUT NOCOPY NUMBER,
3486 x_currency_conversion_date OUT NOCOPY DATE,
3487 x_currency_conversion_type OUT NOCOPY VARCHAR2,
3488 x_distribution_acct_id OUT NOCOPY NUMBER
3489 )IS
3490 l_api_name CONSTANT VARCHAR2(30) := 'Get_InvTransactionInfo';
3491 l_api_version CONSTANT NUMBER := 1.0;
3492
3493 l_return_status VARCHAR2(1) := fnd_api.g_ret_sts_success;
3494 l_msg_count NUMBER := 0;
3495 l_msg_data VARCHAR2(8000) := '';
3496 l_stmt_num NUMBER := 0;
3497 l_api_message VARCHAR2(1000);
3498
3499 l_transaction_flows_tbl INV_TRANSACTION_FLOW_PUB.g_transaction_flow_tbl_type;
3500 l_consigned_flag RCV_TRANSACTIONS.consigned_flag%TYPE;
3501 l_source_doc_code RCV_TRANSACTIONS.source_document_code%TYPE;
3502 l_transaction_type RCV_TRANSACTIONS.transaction_type%TYPE;
3503 l_parent_trx_id RCV_TRANSACTIONS.transaction_id%TYPE;
3504 l_parent_trx_type RCV_TRANSACTIONS.transaction_type%TYPE;
3505 l_po_header_id NUMBER;
3506 l_po_distribution_id NUMBER;
3507 l_po_line_id NUMBER;
3508 l_po_line_location_id NUMBER;
3509 l_po_org_id NUMBER;
3510 l_po_sob_id NUMBER;
3511 l_rcv_organization_id NUMBER;
3512 l_rcv_org_id NUMBER;
3513 l_rcv_sob_id NUMBER;
3514 l_org_id NUMBER;
3515 l_rcv_trx_date DATE;
3516 l_drop_ship_flag NUMBER;
3517 l_destination_type VARCHAR(25);
3518 l_item_id NUMBER;
3519 l_category_id NUMBER;
3520 l_project_id NUMBER;
3521 l_cross_ou_flag VARCHAR2(1);
3522 l_accrual_flag VARCHAR2(1);
3523 l_counter NUMBER;
3524 l_procurement_org_flag VARCHAR2(1);
3525
3526 l_qualifier_code_tbl INV_TRANSACTION_FLOW_PUB.NUMBER_TBL;
3527 l_qualifier_value_tbl INV_TRANSACTION_FLOW_PUB.NUMBER_TBL;
3528
3529 l_rcv_event RCV_SeedEvents_PVT.rcv_event_rec_type;
3530 l_ic_pricing_option NUMBER := 1;
3531 l_unit_price NUMBER := 0;
3532 l_unit_landed_cost NUMBER := NULL;
3533 l_currency_code VARCHAR2(15) := NULL;
3534 l_currency_conversion_rate NUMBER;
3535 l_currency_conversion_date DATE;
3536 l_currency_conversion_type VARCHAR2(30);
3537 l_clearing_acct_id NUMBER := -1;
3538
3539 l_incr_transfer_price NUMBER := 0;
3540 l_incr_currency_code VARCHAR2(15) := NULL;
3541 /* Support for Landed Cost Management */
3542 l_lcm_flag VARCHAR2(1);
3543
3544
3545 BEGIN
3546 -- Standard start of API savepoint
3547 SAVEPOINT Get_InvTransactionInfo_PVT;
3548
3549 l_stmt_num := 0;
3550
3551 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
3552 FND_LOG.string(FND_LOG.LEVEL_PROCEDURE,G_LOG_HEAD || '.'||l_api_name||'.begin'
3553 ,'Get_InvTransactionInfo <<');
3554 END IF;
3555
3556 -- Standard call to check for call compatibility
3557 IF NOT FND_API.Compatible_API_Call (
3558 l_api_version,
3559 p_api_version,
3560 l_api_name,
3561 G_PKG_NAME ) THEN
3562 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3563 END IF;
3564
3565 -- Initialize message list if p_init_msg_list is set to TRUE
3566 IF FND_API.to_Boolean(p_init_msg_list) THEN
3567 FND_MSG_PUB.initialize;
3568 END IF;
3569
3570 -- Initialize API return status to success
3571 x_return_status := FND_API.G_RET_STS_SUCCESS;
3572
3573 -- Initialize return variables
3574 x_intercompany_pricing_option := 1;
3575 x_transfer_price := 0;
3576 x_distribution_acct_id := -1;
3577
3578 l_stmt_num := 10;
3579
3580 SELECT
3581 RT.consigned_flag,
3582 RT.source_document_code,
3583 RT.transaction_type,
3584 RT.parent_transaction_id,
3585 RT.po_header_id,
3586 RT.po_line_id,
3587 RT.po_line_location_id,
3588 RT.po_distribution_id,
3589 POD.destination_type_code,
3590 RT.transaction_date,
3591 nvl(RT.dropship_type_code,3),
3592 POH.org_id,
3593 POLL.ship_to_organization_id,
3594 POL.item_id,
3595 POL.category_id,
3596 POL.project_id,
3597 nvl(POLL.accrue_on_receipt_flag,'N'),
3598 /* Support for Landed Cost Management */
3599 nvl(POLL.lcm_flag, 'N')
3600 INTO l_consigned_flag,
3601 l_source_doc_code,
3602 l_transaction_type,
3603 l_parent_trx_id,
3604 l_po_header_id,
3605 l_po_line_id,
3606 l_po_line_location_id,
3607 l_po_distribution_id,
3608 l_destination_type,
3609 l_rcv_trx_date,
3610 l_drop_ship_flag,
3611 l_po_org_id,
3612 l_rcv_organization_id,
3613 l_item_id,
3614 l_category_id,
3615 l_project_id,
3616 l_accrual_flag,
3617 /* Support for Landed Cost Management */
3618 l_lcm_flag
3619 FROM po_headers POH,
3620 po_line_locations POLL,
3621 po_lines POL,
3622 po_distributions POD,
3623 rcv_transactions RT
3624 WHERE RT.transaction_id = p_rcv_transaction_id
3625 AND POH.po_header_id = RT.po_header_id
3626 AND POLL.line_location_id = RT.po_line_location_id
3627 AND POL.po_line_id = RT.po_line_id
3628 AND POD.po_distribution_id = RT.po_distribution_id;
3629
3630 -- If receiving transaction is for a REQ, or an RMA, we do not
3631 -- do not do any accounting.
3632 -- If consigned receipt, we do not do any accounting.
3633 IF(l_source_doc_code <> 'PO' OR l_consigned_flag = 'Y') THEN
3634 return;
3635 END IF;
3636
3637 IF(l_transaction_type = 'CORRECT') THEN
3638 l_stmt_num := 20;
3639 SELECT transaction_type
3640 INTO l_parent_trx_type
3641 FROM rcv_transactions PARENT
3642 WHERE PARENT.transaction_id = l_parent_trx_id;
3643 END IF;
3644
3645 -- This API is only applicable for Deliver/RTR transactions or corrections to deliver/RTR
3646 -- transactions.
3647 IF(l_transaction_type NOT IN ('DELIVER','RETURN TO RECEIVING') AND
3648 (l_transaction_type <> 'CORRECT'
3649 OR l_parent_trx_type NOT IN ('DELIVER','RETURN TO RECEIVING'))) THEN
3650 return;
3651 END IF;
3652
3653 l_stmt_num := 30;
3654
3655 -- Get Receiving Operating Unit
3656 SELECT operating_unit, ledger_id
3657 INTO l_rcv_org_id, l_rcv_sob_id
3658 FROM cst_acct_info_v
3659 WHERE organization_id = l_rcv_organization_id;
3660
3661 -- Get PO SOB
3662 SELECT set_of_books_id
3663 INTO l_po_sob_id
3664 FROM financials_system_parameters;
3665
3666 l_stmt_num := 40;
3667
3668 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
3669 l_api_message := 'Getting InvTransactionInfor : RCV Transaction ID : ' || p_rcv_transaction_id ||
3670 ', PO Header ID : ' || l_po_header_id ||
3671 ', PO Dist ID : ' || l_po_distribution_id ||
3672 ', Destination Type : '|| l_destination_type ||
3673 ', Transaction Date : '|| l_rcv_trx_date ||
3674 ', Drop Ship Flag : '|| l_drop_ship_flag ||
3675 ', PO Org ID : ' || l_po_org_id ||
3676 ', RCV Organization ID : '|| l_rcv_organization_id ||
3677 ', RCV Org ID : '|| l_rcv_org_id ||
3678 ', Project ID : '|| l_project_id ||
3679 ', Category ID : ' || l_category_id ||
3680 ', Accrual Flag : ' || l_accrual_flag ;
3681
3682 FND_LOG.string(FND_LOG.LEVEL_STATEMENT,G_LOG_HEAD || '.'||l_api_name||'.'||l_stmt_num
3683 ,l_api_message);
3684 END IF;
3685
3686 -- Get transaction flow when procuring and receiving operating units are different.
3687 -- However, for POs with destination type of expense, when there is a project on the
3688 -- PO, we should not look for transaction flow. This is because PA,(which transfers
3689 -- costs to Projects for expense destinations), is currently not supporting global
3690 -- procurement.
3691 IF((l_po_org_id = l_rcv_org_id) OR
3692 (l_project_id is NOT NULL AND l_destination_type = 'EXPENSE') OR
3693 (l_item_id IS NULL)
3694 ) THEN
3695 l_ic_pricing_option := 1;
3696 ELSE
3697
3698 /* For 11i10, the only supported qualifier is category id. */
3699 l_qualifier_code_tbl(l_qualifier_code_tbl.count+1) := INV_TRANSACTION_FLOW_PUB.G_QUALIFIER_CODE;
3700 l_qualifier_value_tbl(l_qualifier_value_tbl.count+1) := l_category_id;
3701
3702 l_stmt_num := 50;
3703 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
3704 l_api_message := 'Getting Procurement Transaction Flow :'||
3705 'l_po_org_id : '||l_po_org_id||
3706 ' l_rcv_org_id : '||l_rcv_org_id||
3707 ' l_rcv_organization_id : '||l_rcv_organization_id;
3708
3709 FND_LOG.string(FND_LOG.LEVEL_STATEMENT,G_LOG_HEAD || '.'||l_api_name||'.'||l_stmt_num
3710 ,l_api_message);
3711 END IF;
3712
3713 INV_TRANSACTION_FLOW_PUB.GET_TRANSACTION_FLOW(
3714 x_return_status => l_return_status,
3715 x_msg_data => l_msg_data,
3716 x_msg_count => l_msg_count,
3717 x_transaction_flows_tbl => l_transaction_flows_tbl,
3718 p_api_version => 1.0,
3719 p_start_operating_unit => l_po_org_id,
3720 p_end_operating_unit => l_rcv_org_id,
3721 p_flow_type => INV_TRANSACTION_FLOW_PUB.G_PROCURING_FLOW_TYPE,
3722 p_organization_id => l_rcv_organization_id,
3723 p_qualifier_code_tbl => l_qualifier_code_tbl,
3724 p_qualifier_value_tbl => l_qualifier_value_tbl,
3725 p_transaction_date => l_rcv_trx_date,
3726 p_get_default_cost_group=> 'N');
3727
3728 IF (l_return_status = FND_API.g_ret_sts_success) THEN
3729 -- Populate dummy l_rcv_event record to pass to Get_UnitPrice function.
3730 l_counter := l_transaction_flows_tbl.COUNT;
3731 l_rcv_event.trx_flow_header_id := l_transaction_flows_tbl(l_counter).header_id;
3732 l_rcv_event.destination_type_code := l_destination_type;
3733 l_rcv_event.procurement_org_flag := 'N';
3734 l_rcv_event.drop_ship_flag := l_drop_ship_flag;
3735 l_rcv_event.item_id := l_item_id;
3736 l_rcv_event.org_id := l_rcv_org_id;
3737 l_rcv_event.transfer_org_id := l_transaction_flows_tbl(l_counter).from_org_id;
3738 l_rcv_event.organization_id := l_rcv_organization_id;
3739 l_rcv_event.transfer_organization_id := l_transaction_flows_tbl(l_counter).from_organization_id;
3740 l_rcv_event.rcv_transaction_id := p_rcv_transaction_id;
3741 l_rcv_event.transaction_date := l_rcv_trx_date;
3742 l_rcv_event.event_source := 'RECEIVING';
3743 l_rcv_event.po_header_id := l_po_header_id;
3744 l_rcv_event.po_line_id := l_po_line_id;
3745 l_rcv_event.po_distribution_id := l_po_distribution_id;
3746 l_rcv_event.po_line_location_id := l_po_line_location_id;
3747 l_rcv_event.set_of_books_id := l_rcv_sob_id;
3748
3749 l_stmt_num := 60;
3750 RCV_SeedEvents_PVT.Get_UnitPrice( p_api_version => l_api_version,
3751 x_return_status => l_return_status,
3752 x_msg_count => l_msg_count,
3753 x_msg_data => l_msg_data,
3754 p_rcv_event => l_rcv_event,
3755 p_asset_item_pricing_option =>
3756 l_transaction_flows_tbl(l_counter).asset_item_pricing_option,
3757 p_expense_item_pricing_option =>
3758 l_transaction_flows_tbl(l_counter).expense_item_pricing_option,
3759 /* Support for Landed Cost Management */
3760 p_lcm_flag => l_lcm_flag,
3761 x_intercompany_pricing_option => l_ic_pricing_option,
3762 x_unit_price => l_unit_price,
3763 x_unit_landed_cost => l_unit_landed_cost,
3764 x_currency_code => l_currency_code,
3765 x_incr_transfer_price => l_incr_transfer_price,
3766 x_incr_currency_code => l_incr_currency_code);
3767 IF l_return_status <> FND_API.g_ret_sts_success THEN
3768 l_api_message := 'Error getting unit price';
3769 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_UNEXPECTED >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
3770 FND_LOG.string(FND_LOG.LEVEL_UNEXPECTED,G_LOG_HEAD || '.'||l_api_name||l_stmt_num
3771 ,'Get_InvInfo : '||l_stmt_num||' : '||l_api_message);
3772 END IF;
3773 RAISE FND_API.g_exc_unexpected_error;
3774 END IF;
3775
3776 l_rcv_event.currency_code := l_currency_code;
3777
3778 IF (l_ic_pricing_option = 2) THEN
3779 x_transfer_price := l_unit_price;
3780 x_currency_code := l_currency_code;
3781
3782 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
3783 FND_LOG.string(FND_LOG.LEVEL_EVENT,G_LOG_HEAD||'.'||l_api_name||'.'||l_stmt_num
3784 ,'Getting Currency Information');
3785 END IF;
3786 l_stmt_num :=70;
3787 RCV_SeedEvents_PVT.Get_Currency(
3788 p_api_version => l_api_version,
3789 x_return_status => l_return_status,
3790 x_msg_count => l_msg_count,
3791 x_msg_data => l_msg_data,
3792 p_rcv_event => l_rcv_event,
3793 x_currency_code => l_currency_code,
3794 x_currency_conversion_rate => l_currency_conversion_rate,
3795 x_currency_conversion_date => l_currency_conversion_date,
3796 x_currency_conversion_type => l_currency_conversion_type);
3797
3798 IF l_return_status <> FND_API.g_ret_sts_success THEN
3799 l_api_message := 'Error Getting Currency';
3800 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_UNEXPECTED >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
3801 FND_LOG.string(FND_LOG.LEVEL_UNEXPECTED,G_LOG_HEAD || '.'||l_api_name||l_stmt_num
3802 ,'Seed_RAEEvent : '||l_stmt_num||' : '||l_api_message);
3803 END IF;
3804 RAISE FND_API.g_exc_unexpected_error;
3805 END IF;
3806 END IF;
3807 ELSIF(l_return_status = FND_API.g_ret_sts_error) THEN
3808 l_api_message := 'Error occurred in Transaction Flow API';
3809 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_UNEXPECTED >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
3810 FND_LOG.string(FND_LOG.LEVEL_UNEXPECTED,G_LOG_HEAD || '.'||l_api_name||l_stmt_num
3811 ,'Get_InvTransaction_Info : '||l_stmt_num||' : '||l_api_message);
3812 END IF;
3813 RAISE FND_API.g_exc_unexpected_error;
3814 END IF;
3815 END IF;
3816
3817 IF(l_drop_ship_flag IN (1,2)) THEN
3818 l_stmt_num := 80;
3819 SELECT nvl(clearing_account_id, receiving_account_id)
3820 INTO l_clearing_acct_id
3821 FROM rcv_parameters
3822 WHERE organization_id = l_rcv_organization_id;
3823
3824 x_distribution_acct_id := l_clearing_acct_id;
3825 END IF;
3826
3827 l_stmt_num := 90;
3828 x_intercompany_pricing_option := l_ic_pricing_option;
3829 IF (l_ic_pricing_option = 2) THEN
3830 x_transfer_price := l_unit_price;
3831 x_currency_code := l_currency_code;
3832 x_currency_conversion_rate := l_currency_conversion_rate;
3833 x_currency_conversion_date := l_currency_conversion_date;
3834 x_currency_conversion_type := l_currency_conversion_type;
3835 END IF;
3836
3837 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
3838 l_api_message := 'x_intercompany_pricing_option : '||x_intercompany_pricing_option||
3839 'x_transfer_price : '||x_transfer_price||
3840 'x_currency_code : '||x_currency_code||
3841 'x_currency_conversion_rate : '||x_currency_conversion_rate||
3842 'x_currency_conversion_date : '||x_currency_conversion_date||
3843 'x_currency_conversion_type : '||x_currency_conversion_type||
3844 'x_distribution_acct_id : '||x_distribution_acct_id;
3845
3846 FND_LOG.string(FND_LOG.LEVEL_STATEMENT,G_LOG_HEAD || '.'||l_api_name||'.'||l_stmt_num
3847 ,l_api_message);
3848 END IF;
3849
3850 --- Standard check of p_commit
3851 IF FND_API.to_Boolean(p_commit) THEN
3852 COMMIT WORK;
3853 END IF;
3854
3855 -- Standard Call to get message count and if count = 1, get message info
3856 FND_MSG_PUB.Count_And_Get (
3857 p_count => x_msg_count,
3858 p_data => x_msg_data );
3859
3860 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
3861 FND_LOG.string(FND_LOG.LEVEL_PROCEDURE,G_LOG_HEAD || '.'||l_api_name||'.end'
3862 ,'Get_InvTransactionInfo >>');
3863 END IF;
3864
3865
3866 EXCEPTION
3867 WHEN FND_API.g_exc_error THEN
3868 ROLLBACK TO Get_InvTransactionInfo_PVT;
3869 x_return_status := FND_API.g_ret_sts_error;
3870 FND_MSG_PUB.count_and_get
3871 ( p_count => x_msg_count
3872 , p_data => x_msg_data
3873 );
3874 WHEN FND_API.g_exc_unexpected_error THEN
3875 ROLLBACK TO Get_InvTransactionInfo_PVT;
3876 x_return_status := FND_API.g_ret_sts_unexp_error ;
3877 FND_MSG_PUB.count_and_get
3878 ( p_count => x_msg_count
3879 , p_data => x_msg_data
3880 );
3881
3882 WHEN OTHERS THEN
3883 ROLLBACK TO Get_InvTransactionInfo_PVT;
3884 x_return_status := fnd_api.g_ret_sts_unexp_error ;
3885
3886 IF G_DEBUG = 'Y' AND FND_LOG.LEVEL_UNEXPECTED >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
3887 FND_LOG.string(FND_LOG.LEVEL_UNEXPECTED,G_LOG_HEAD || '.'||l_api_name||l_stmt_num
3888 ,'Get_InvTransactionInfo : '||l_stmt_num||' : '||substr(SQLERRM,1,200));
3889 END IF;
3890
3891 IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error)
3892 THEN
3893 FND_MSG_PUB.add_exc_msg
3894 ( G_PKG_NAME,
3895 l_api_name || 'Statement -'||to_char(l_stmt_num)
3896 );
3897 END IF;
3898 FND_MSG_PUB.count_and_get
3899 ( p_count => x_msg_count
3900 , p_data => x_msg_data
3901 );
3902
3903 END Get_InvTransactionInfo;
3904
3905
3906 END RCV_AccEvents_PVT;