[Home] [Help]
PACKAGE BODY: APPS.OZF_PRE_PROCESS_PVT
Source
1 PACKAGE BODY OZF_PRE_PROCESS_PVT AS
2 /* $Header: ozfvprsb.pls 120.28.12010000.2 2008/08/14 21:29:35 julou ship $ */
3 -- Start of Comments
4 -- Package name : ozf_pre_process_pvt
5 -- Purpose :
6 -- History : 09-OCT-2003 vansub Created
7 -- NOTE :
8 -- End of Comments
9
10 G_PKG_NAME CONSTANT VARCHAR2(30):= 'ozf_pre_process_pvt';
11 G_FILE_NAME CONSTANT VARCHAR2(12) := 'ozfvprsb.pls';
12
13 OZF_DEBUG_HIGH_ON CONSTANT BOOLEAN := FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.g_msg_lvl_debug_high);
14 OZF_DEBUG_LOW_ON CONSTANT BOOLEAN := FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.g_msg_lvl_debug_low);
15 OZF_UNEXP_ERROR CONSTANT BOOLEAN := FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.g_msg_lvl_unexp_error);
16 OZF_ERROR CONSTANT BOOLEAN := FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.g_msg_lvl_error);
17
18 -- Processing global variables
19 G_BATCH_STATUS VARCHAR2(30) := NULL;
20 G_BATCH_CURRENCY_CODE VARCHAR2(30) := NULL;
21 G_INVENTORY_TRACKING_FLAG VARCHAR2(1) := NULL;
22 G_ADMIN_EMAIL VARCHAR2(100);
23
24 G_DQM_CONTACT_RULE NUMBER := FND_PROFILE.value('OZF_RESALE_CONTACT_DQM_RULE');
25 G_DQM_PARTY_RULE NUMBER := FND_PROFILE.value('OZF_RESALE_PARTY_DQM_RULE');
26 G_DQM_PARTY_SITE_RULE NUMBER := FND_PROFILE.value('OZF_RESALE_PARTY_SITE_DQM_RULE');
27 G_ITEM_ORG_ID NUMBER := FND_PROFILE.value('AMS_ITEM_ORGANIZATION_ID');
28 G_DEFAULT_ORG_ID NUMBER := FND_PROFILE.value('DEFAULT_ORG_ID');
29
30 -- Private Procedure
31 PROCEDURE Number_Mapping_Required(
32 p_internal_code_tbl IN NUMBER_TABLE,
33 x_mapping_flag OUT NOCOPY VARCHAR2
34 );
35
36 FUNCTION set_line_status(
37 p_count IN NUMBER,
38 p_status_code IN VARCHAR2
39 ) RETURN VARCHAR2_TABLE;
40
41 PROCEDURE Mapping_Required(
42 p_internal_code_tbl IN VARCHAR2_TABLE,
43 p_external_code_tbl IN VARCHAR2_TABLE,
44 x_mapping_flag OUT NOCOPY VARCHAR2
45 );
46
47 --
48 PROCEDURE process_xmlgt_inbwf
49 (
50 itemtype IN VARCHAR2,
51 itemkey IN VARCHAR2,
52 actid IN NUMBER,
53 funcmode IN VARCHAR2,
54 resultout IN OUT NOCOPY VARCHAR2
55 )
56 IS
57 l_api_name CONSTANT VARCHAR2(30) := 'process_xmlgt_inbwf';
58 l_api_version_number CONSTANT NUMBER := 1.0;
59
60 l_resultout VARCHAR2(30);
61 l_batch_id NUMBER;
62 l_return_status VARCHAR2(1);
63 l_msg_count NUMBER;
64 l_msg_data VARCHAR2(2000);
65 l_batch_status VARCHAR2(30);
66 BEGIN
67 IF OZF_DEBUG_HIGH_ON THEN
68 ozf_utility_pvt.debug_message('In: ' || l_api_name || ' Funcmode: ' || funcmode);
69 END IF;
70
71 IF (funcmode = 'RUN') THEN
72
73 IF itemtype = g_xml_import_workflow THEN
74
75 l_batch_id := wf_engine.GetItemAttrText(itemtype => itemtype,
76 itemkey => itemkey,
77 aname => 'PARAMETER1');
78
79 ELSIF itemtype = g_data_process_workflow THEN
80
81 l_batch_id := wf_engine.GetItemAttrText(itemtype => itemtype,
82 itemkey => itemkey,
83 aname => 'OZF_RESALE_BATCH_ID');
84
85 END IF;
86
87 IF OZF_DEBUG_LOW_ON THEN
88 ozf_utility_pvt.debug_message('Batch ID '|| l_batch_id);
89 END IF;
90
91 IF l_batch_id IS NOT NULL THEN
92
93 resale_pre_process
94 (
95 p_api_version_number => 1.0,
96 p_init_msg_list => FND_API.G_FALSE,
97 p_commit => FND_API.G_FALSE,
98 p_validation_level => FND_API.G_VALID_LEVEL_FULL,
99 p_batch_id => l_batch_id,
100 x_batch_status => l_batch_status,
101 x_return_status => l_return_status,
102 x_msg_count => l_msg_count,
103 x_msg_data => l_msg_data
104 );
105
106 IF OZF_DEBUG_LOW_ON THEN
107 ozf_utility_pvt.debug_message('Pre Process is complete '||l_return_status);
108 END IF;
109
110 IF l_return_status <> FND_API.G_RET_STS_SUCCESS then
111 l_resultout := 'COMPLETE:ERROR';
112 IF itemtype = g_xml_import_workflow THEN
113 wf_engine.SetItemAttrText(itemtype => itemtype,
114 itemkey => itemkey,
115 aname => 'ECX_ADMINISTRATOR',
116 avalue => G_ADMIN_EMAIL );
117 ELSIF itemtype = g_data_process_workflow THEN
118 wf_engine.SetItemAttrText(itemtype => itemtype,
119 itemkey => itemkey,
120 aname => 'WF_ADMINISTRATOR',
121 avalue => G_ADMIN_EMAIL );
122 END IF;
123 ELSE
124 IF l_batch_status IS NOT NULL THEN
125 IF l_batch_status <> 'OPEN' THEN
126 l_resultout := 'COMPLETE:ERROR';
127 ELSE
128 l_resultout := 'COMPLETE:SUCCESS';
129 END IF;
130 END IF;
131 END IF;
132 ELSE
133 l_resultout := 'COMPLETE:SUCCESS';
134 END IF;
135
136 ELSIF (funcmode = 'CANCEL') THEN
137 l_resultout := 'COMPLETE';
138
139 ELSIF (funcmode in ('RESPOND', 'FORWARD', 'TRANSFER')) THEN
140 l_resultout := 'COMPLETE';
141
142 ELSIF (funcmode = 'TIMEOUT') THEN
143 l_resultout := 'COMPLETE';
144
145 END IF;
146
147 resultout := l_resultout;
148
149 EXCEPTION
150 WHEN FND_API.G_EXC_ERROR THEN
151 fnd_msg_pub.Count_And_Get(
152 p_encoded => FND_API.G_TRUE
153 ,p_count => l_msg_count
154 ,p_data => l_msg_data);
155
156 wf_core.context(G_PKG_NAME, l_api_name,l_msg_data);
157 raise;
158 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
159 fnd_msg_pub.Count_And_Get(
160 p_encoded => FND_API.G_TRUE
161 ,p_count => l_msg_count
162 ,p_data => l_msg_data);
163
164 wf_core.context(G_PKG_NAME, l_api_name,l_msg_data);
165 raise;
166 WHEN OTHERS THEN
167 fnd_msg_pub.Count_And_Get(
168 p_encoded => FND_API.G_TRUE
169 ,p_count => l_msg_count
170 ,p_data => l_msg_data);
171
172 wf_core.context(G_PKG_NAME, l_api_name,l_msg_data);
173 raise;
174 END process_xmlgt_inbwf;
175
176 PROCEDURE webadi_import (
177 p_batch_number IN VARCHAR2,
178 x_return_status OUT NOCOPY VARCHAR2
179 )
180 IS
181 l_api_name CONSTANT VARCHAR2(30) := 'webadi_import';
182 l_api_version_number CONSTANT NUMBER := 1.0;
183
184 l_msg_count NUMBER;
185 l_msg_data VARCHAR2(32000);
186 l_batch_id NUMBER;
187 l_batch_status VARCHAR2(30);
188
189 CURSOR get_batch_id (pc_batch_no VARCHAR2)
190 IS
191 select resale_batch_id
192 from ozf_resale_batches
193 where batch_number = pc_batch_no;
194
195 BEGIN
196 IF OZF_DEBUG_HIGH_ON THEN
197 ozf_utility_pvt.debug_message('Private API: ' || l_api_name || ': start');
198 END IF;
199
200 x_return_status := FND_API.G_RET_STS_SUCCESS;
201 IF p_batch_number IS NOT NULL THEN
202
203 OPEN get_batch_id (p_batch_number);
204 FETCH get_batch_id INTO l_batch_id;
205 CLOSE get_batch_id;
206
207 IF l_batch_id IS NOT NULL THEN
208
209 resale_pre_process
210 (
211 p_api_version_number => 1.0,
212 p_init_msg_list => FND_API.G_FALSE,
213 p_commit => FND_API.G_FALSE,
214 p_validation_level => FND_API.G_VALID_LEVEL_FULL,
215 p_batch_id => l_batch_id,
216 x_batch_status => l_batch_status,
217 x_return_status => x_return_status,
218 x_msg_count => l_msg_count,
219 x_msg_data => l_msg_data
220 );
221
222 IF OZF_DEBUG_LOW_ON THEN
223 ozf_utility_pvt.debug_message('Pre Process is complete '|| x_return_status);
224 END IF;
225
226 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
227 RAISE FND_API.G_EXC_ERROR;
228 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
229 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
230 END IF;
231 IF x_return_status = FND_API.G_RET_STS_SUCCESS THEN
232 IF l_batch_status = g_batch_open THEN
233
234 -- Call Data Processing Event
235 raise_event
236 (
237 p_batch_id => l_batch_id,
238 p_event_name => g_webadi_data_process_event,
239 x_return_status => x_return_status
240 );
241 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
242 RAISE FND_API.G_EXC_ERROR;
243 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
244 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
245 END IF;
246 END IF;
247 END IF;
248
249 END IF; -- l_batch_id is not null
250
251 END IF; -- p_batch_number is not null
252
253 IF OZF_DEBUG_HIGH_ON THEN
254 ozf_utility_pvt.debug_message('Private API: ' || l_api_name || ': end');
255 END IF;
256
257 EXCEPTION
258 WHEN FND_API.G_EXC_ERROR THEN
259 x_return_status := FND_API.G_RET_STS_ERROR;
260 -- Standard call to get message count and if count=1, get the message
261 FND_MSG_PUB.Count_And_Get (
262 p_encoded => FND_API.G_FALSE,
263 p_count => l_msg_count,
264 p_data => l_msg_data
265 );
266 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
267 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
268 -- Standard call to get message count and if count=1, get the message
269 FND_MSG_PUB.Count_And_Get (
270 p_encoded => FND_API.G_FALSE,
271 p_count => l_msg_count,
272 p_data => l_msg_data
273 );
274 WHEN OTHERS THEN
275 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
276 IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
277 THEN
278 FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
279 END IF;
280 -- Standard call to get message count and if count=1, get the message
281 FND_MSG_PUB.Count_And_Get (
282 p_encoded => FND_API.G_FALSE,
283 p_count => l_msg_count,
284 p_data => l_msg_data
285 );
286
287 END Webadi_import;
288
289 PROCEDURE Resale_Pre_Process (
290 p_api_version_number IN NUMBER,
291 p_init_msg_list IN VARCHAR2 := FND_API.G_FALSE,
292 p_commit IN VARCHAR2 := FND_API.G_FALSE,
293 p_validation_level IN NUMBER := FND_API.G_VALID_LEVEL_FULL,
294 p_batch_id IN NUMBER,
295 x_batch_status OUT NOCOPY VARCHAR2,
296 x_return_status OUT NOCOPY VARCHAR2,
297 x_msg_count OUT NOCOPY NUMBER,
298 x_msg_data OUT NOCOPY VARCHAR2
299 )
300 IS
301 l_api_name CONSTANT VARCHAR2(30) := 'resale_pre_process';
302 l_api_version_number CONSTANT NUMBER := 1.0;
303
304 l_resale_batch_rec ozf_resale_batches_all%rowtype;
305 l_line_record resale_line_int_rec_type;
306
307 l_status VARCHAR2(30) := NULL;
308 l_dispute_reason VARCHAR2(100);
309 l_batch_org_id NUMBER;
310 l_org_id NUMBER;
311
312 CURSOR get_count (pc_batch_id IN NUMBER) IS
313 SELECT COUNT(DECODE(b.status_code, 'DISPUTED', 1, NULL)),
314 COUNT(b.status_code)
315 FROM ozf_resale_batches_all a
316 , ozf_resale_lines_int_all b
317 WHERE a.resale_batch_id = b.resale_batch_id
318 AND a.resale_batch_id = pc_batch_id;
319
320 CURSOR get_batch_org(cv_resale_batch_id IN NUMBER) IS
321 SELECT org_id
322 FROM ozf_resale_batches_all
323 WHERE resale_batch_id = cv_resale_batch_id;
324
325 BEGIN
326
327 --SAVEPOINT resale_pre_process;
328
329 -- Standard call to check for call compatibility.
330 IF NOT FND_API.Compatible_API_Call ( l_api_version_number,
331 p_api_version_number,
332 l_api_name,
333 G_PKG_NAME)
334 THEN
335 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
336 END IF;
337
338 -- Initialize message list if p_init_msg_list is set to TRUE.
339 IF FND_API.to_Boolean( p_init_msg_list )
340 THEN
341 FND_MSG_PUB.initialize;
342 END IF;
343
344 IF OZF_DEBUG_HIGH_ON THEN
345 ozf_utility_pvt.debug_message('Private API: ' || l_api_name || ': start');
346 END IF;
347
348 -- Initialize API return status to SUCCESS
349 x_return_status := FND_API.G_RET_STS_SUCCESS;
350
351 -- R12 MOAC Enhancement (+)
352 OPEN get_batch_org(p_batch_id);
353 FETCH get_batch_org INTO l_batch_org_id;
354 CLOSE get_batch_org;
355
356 l_org_id := MO_GLOBAL.get_valid_org(l_batch_org_id);
357
358 IF l_org_id IS NULL THEN
359 x_return_status := FND_API.G_RET_STS_ERROR;
360 RAISE FND_API.G_EXC_ERROR;
361 END IF;
362
363 MO_GLOBAL.set_policy_context('S', l_org_id);
364 -- R12 MOAC Enhancement (-)
365
366
367 -- Delete logs from previous runs
368 OZF_RESALE_COMMON_PVT.Delete_Log(
369 p_api_version => 1.0
370 ,p_init_msg_list => FND_API.G_FALSE
371 ,p_commit => FND_API.G_FALSE
372 ,p_validation_level => FND_API.G_VALID_LEVEL_FULL
373 ,p_resale_batch_id => p_batch_id
374 ,x_return_status => x_return_status
375 ,x_msg_count => x_msg_count
376 ,x_msg_data => x_msg_data
377 );
378 IF x_return_status = FND_API.g_ret_sts_error THEN
379 RAISE FND_API.g_exc_error;
380 ELSIF x_return_status = FND_API.g_ret_sts_unexp_error THEN
381 RAISE FND_API.g_exc_unexpected_error;
382 END IF;
383
384 -- Validates and Updates Ozf_Resale_Batches_all
385 Batch_Update
386 ( p_api_version_number => 1.0,
387 p_init_msg_list => FND_API.G_FALSE,
388 p_commit => FND_API.G_FALSE,
389 p_validation_level => FND_API.G_VALID_LEVEL_FULL,
390 p_batch_id => p_batch_id,
391 x_resale_batch_rec => l_resale_batch_rec,
392 x_return_status => x_return_status,
393 x_msg_count => x_msg_count,
394 x_msg_data => x_msg_data
395 );
396 --
400 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
397 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
398 RAISE FND_API.G_EXC_ERROR;
399 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
401 END IF;
402 --
403 IF l_resale_batch_rec.resale_batch_id IS NOT NULL THEN
404 -- Validates and Updates Ozf_Resale_Lines_Int_All
405 Lines_Update
406 (
407 p_batch_id => p_batch_id,
408 px_batch_record => l_resale_batch_rec,
409 x_return_status => x_return_status,
410 x_msg_count => x_msg_count,
411 x_msg_data => x_msg_data
412 );
413 --
414 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
415 RAISE FND_API.G_EXC_ERROR;
416 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
417 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
418 END IF;
419 --
420 -- Final Checking of mandatory items
421 IF l_resale_batch_rec.batch_type IS NULL THEN
422 l_resale_batch_rec.batch_type := ozf_resale_common_pvt.G_TRACING;
423 END IF;
424 IF l_resale_batch_rec.status_code IS NULL THEN
425 l_resale_batch_rec.status_code := g_batch_open;
426 END IF;
427
428 OPEN get_count(p_batch_id);
429 FETCH get_count INTO l_resale_batch_rec.lines_disputed
430 , l_resale_batch_rec.batch_count;
431 CLOSE get_count;
432
433 IF l_resale_batch_rec.lines_disputed > 0 THEN
434 l_resale_batch_rec.status_code := g_batch_disputed;
435 ELSE
436 l_resale_batch_rec.status_code := g_batch_open;
437 END IF;
438
439 -- [BEGIN OF BUG 4301466 FIXING]
440 /*
441 IF l_resale_batch_rec.lines_disputed > 0 THEN
442 l_resale_batch_rec.status_code := g_batch_disputed;
443 ELSE
444 l_resale_batch_rec.status_code := g_batch_open;
445 END IF;
446 */
447 IF l_resale_batch_rec.lines_disputed = l_resale_batch_rec.batch_count THEN
448 l_resale_batch_rec.status_code := g_batch_disputed;
449 ELSE
450 l_resale_batch_rec.status_code := g_batch_open;
451 END IF;
452 -- [END OF BUG 4301466 FIXING]
453
454 x_batch_status := l_resale_batch_rec.status_code;
455 -- Batch is updated with all the derived values OR status as 'REJECTED'
456 -- -----------------------------------------------------------------
457 Update_interface_batch
458 ( p_api_version_number => 1.0,
459 p_init_msg_list => FND_API.G_FALSE,
460 P_Commit => FND_API.G_FALSE,
461 p_validation_level => FND_API.G_VALID_LEVEL_FULL,
462 p_int_batch_rec => l_resale_batch_rec,
463 x_return_status => x_return_status,
464 x_msg_count => x_msg_count,
465 x_msg_data => x_msg_data
466 );
467 --
468 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
469 RAISE FND_API.G_EXC_ERROR;
470 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
471 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
472 END IF;
473
474 END IF;
475 x_batch_status := l_resale_batch_rec.status_code;
476
477 -- Standard check for p_commit
478 IF FND_API.to_Boolean( p_commit )
479 THEN
480 COMMIT WORK;
481 END IF;
482
483 -- Debug Message
484 IF OZF_DEBUG_HIGH_ON THEN
485 ozf_utility_pvt.debug_message('Private API: ' || l_api_name || ': end');
486 END IF;
487
488 -- Standard call to get message count and if count is 1, get message info.
489 FND_MSG_PUB.Count_And_Get
490 (p_count => x_msg_count,
491 p_data => x_msg_data
492 );
493
494 EXCEPTION
495 WHEN FND_API.G_EXC_ERROR THEN
496 --ROLLBACK TO resale_pre_process;
497 x_return_status := FND_API.G_RET_STS_ERROR;
498 x_batch_status := OZF_RESALE_COMMON_PVT.G_BATCH_DISPUTED;
499 Update ozf_resale_batches
500 SET status_code = OZF_RESALE_COMMON_PVT.G_BATCH_DISPUTED
501 WHERE resale_batch_id = p_batch_id;
502
503 -- Standard call to get message count and if count=1, get the message
504 FND_MSG_PUB.Count_And_Get (
505 p_encoded => FND_API.G_FALSE,
506 p_count => x_msg_count,
507 p_data => x_msg_data);
508 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
509 --ROLLBACK TO resale_pre_process;
510 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
511 x_batch_status := OZF_RESALE_COMMON_PVT.G_BATCH_DISPUTED;
512 Update ozf_resale_batches
513 SET status_code = OZF_RESALE_COMMON_PVT.G_BATCH_DISPUTED
514 WHERE resale_batch_id = p_batch_id;
515
516 -- Standard call to get message count and if count=1, get the message
517 FND_MSG_PUB.Count_And_Get (
518 p_encoded => FND_API.G_FALSE,
519 p_count => x_msg_count,
520 p_data => x_msg_data);
521 WHEN OTHERS THEN
522 --ROLLBACK TO resale_pre_process;
523 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
524 x_batch_status := OZF_RESALE_COMMON_PVT.G_BATCH_DISPUTED;
525 Update ozf_resale_batches
526 SET status_code = OZF_RESALE_COMMON_PVT.G_BATCH_DISPUTED
530 THEN
527 WHERE resale_batch_id = p_batch_id;
528
529 IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
531 FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
532 END IF;
533 -- Standard call to get message count and if count=1, get the message
534 FND_MSG_PUB.Count_And_Get (
535 p_encoded => FND_API.G_FALSE,
536 p_count => x_msg_count,
537 p_data => x_msg_data);
538
539 END Resale_pre_process;
540
541 PROCEDURE Batch_Update (
542 p_api_version_number IN NUMBER,
543 p_init_msg_list IN VARCHAR2 := FND_API.G_FALSE,
544 p_commit IN VARCHAR2 := FND_API.G_FALSE,
545 p_validation_level IN NUMBER := FND_API.G_VALID_LEVEL_FULL,
546 p_batch_id IN NUMBER,
547 x_resale_batch_rec OUT NOCOPY ozf_resale_batches_all%rowtype,
548 x_return_status OUT NOCOPY VARCHAR2,
549 x_msg_count OUT NOCOPY NUMBER,
550 x_msg_data OUT NOCOPY VARCHAR2
551 )
552 IS
553 l_api_name CONSTANT VARCHAR2(30) := 'Batch_Update';
554 l_api_version_number CONSTANT NUMBER := 1.0;
555
556 l_resale_batch_rec ozf_resale_batches_all%rowtype;
557 l_msg_count NUMBER;
558 l_msg_data VARCHAR2(32000);
559 l_batch_status VARCHAR2(30);
560
561 BEGIN
562 IF OZF_DEBUG_HIGH_ON THEN
563 ozf_utility_pvt.debug_message('Private API: ' || l_api_name || ': start');
564 END IF;
565
566 x_return_status := FND_API.G_RET_STS_SUCCESS;
567 --
568 -- Fetch the Batch Record for the given Batch ID
569 -- -----------------------------------------------------------------
570 Batch_Fetch
571 ( p_batch_id => p_batch_id,
572 x_resale_batch_rec => l_resale_batch_rec,
573 x_return_status => x_return_status
574 );
575 --
576 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
577 RAISE FND_API.G_EXC_ERROR;
578 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
579 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
580 END IF;
581 --
582 --
583 -- Validate the Batch for the required values
584 -- -----------------------------------------------------------------
585 IF l_resale_batch_rec.resale_batch_id IS NOT NULL THEN
586 Validate_Batch(
587 p_api_version_number => 1.0,
588 p_init_msg_list => FND_API.G_FALSE,
589 p_commit => FND_API.G_FALSE,
590 p_validation_level => FND_API.G_VALID_LEVEL_FULL,
591 p_resale_batch_rec => l_resale_batch_rec,
592 x_batch_status => l_batch_status,
593 x_return_status => x_return_status,
594 x_msg_count => l_msg_count,
595 x_msg_data => l_msg_data
596 );
597 IF OZF_DEBUG_LOW_ON THEN
598 ozf_utility_pvt.debug_message('Batch Status from Validate Batch ' || l_batch_status);
599 END IF;
600 --
601 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
602 RAISE FND_API.G_EXC_ERROR;
603 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
604 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
605 END IF;
606 --
607 --
608 -- If the required values are null then the batch is rejected OR
609 -- if all the values are present the defaulting rules are
610 -- applied to the batch in Batch_Defaulting
611 -- -----------------------------------------------------------------
612
613 IF l_batch_status = G_BATCH_REJECTED THEN
614 l_resale_batch_rec.status_code := G_BATCH_REJECTED;
615 G_BATCH_STATUS := g_batch_rejected;
616 ELSE
617 l_resale_batch_rec.status_code := l_batch_status;
618 Batch_Defaulting
619 ( p_api_version_number => 1.0,
620 p_init_msg_list => FND_API.G_FALSE,
621 p_commit => FND_API.G_FALSE,
622 p_validation_level => FND_API.G_VALID_LEVEL_FULL,
623 px_resale_batch_rec => l_resale_batch_rec,
624 x_return_status => x_return_status,
625 x_msg_count => l_msg_count,
626 x_msg_data => l_msg_data
627 );
628 --
629 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
630 RAISE FND_API.G_EXC_ERROR;
631 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
632 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
633 END IF;
634 --
635 END IF; -- l_batch_status = G_BATCH_REJECTED
636 x_resale_batch_rec := l_resale_batch_rec;
637 ELSE
638 x_resale_batch_rec := NULL;
639 END IF;
640
641 IF OZF_DEBUG_HIGH_ON THEN
642 ozf_utility_pvt.debug_message('Private API: ' || l_api_name || ': End');
643 END IF;
644 EXCEPTION
645 WHEN FND_API.G_EXC_ERROR THEN
646 x_return_status := FND_API.G_RET_STS_ERROR;
647 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
648 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
649 WHEN OTHERS THEN
650 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
651 IF OZF_UNEXP_ERROR THEN
652 FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
653 END IF;
657 (
654 END Batch_Update;
655
656 PROCEDURE Batch_Fetch
658 p_batch_id IN NUMBER,
659 x_resale_batch_rec OUT NOCOPY ozf_resale_batches_all%rowtype,
660 x_return_status OUT NOCOPY VARCHAR2
661 )
662 IS
663
664 l_api_name CONSTANT VARCHAR2(30) := 'Batch_Fetch';
665 l_api_version_number CONSTANT NUMBER := 1.0;
666
667 CURSOR csr_get_batch_info(cv_batch_id NUMBER)
668 IS
669 SELECT *
670 FROM ozf_resale_batches_all
671 WHERE resale_batch_id = cv_batch_id;
672
673 CURSOR get_ecx_party_id ( pc_party_site NUMBER)
674 IS
675 SELECT party_id
676 , party_site_id
677 , company_admin_email
678 FROM ecx_tp_headers_v
679 WHERE party_site_id = pc_party_site
680 UNION
681 SELECT party_id
682 , party_site_id
683 , company_admin_email
684 FROM ecx_tp_headers_v hdr
685 , ecx_tp_details_v dtl
686 WHERE hdr.tp_header_id = dtl.tp_header_id
687 AND source_tp_location_code = to_char(pc_party_site);
688
689 time NUMBER;
690 l_partner_party_id NUMBER;
691 l_party_site_id NUMBER;
692 l_admin_email VARCHAR2(3000);
693
694 BEGIN
695 IF OZF_DEBUG_HIGH_ON THEN
696 ozf_utility_pvt.debug_message('Private API: ' || l_api_name || ': Start');
697 END IF;
698
699 x_return_status := FND_API.G_RET_STS_SUCCESS;
700
701 -- Fetch the batch record
702 IF OZF_DEBUG_LOW_ON THEN
703 ozf_utility_pvt.debug_message('p_batch_id ' || p_batch_id );
704 END IF;
705
706 OPEN csr_get_batch_info ( p_batch_id);
707 FETCH csr_get_batch_info INTO x_resale_batch_rec;
708
709 IF OZF_DEBUG_LOW_ON THEN
710 ozf_utility_pvt.debug_message('after batch fetch');
711 END IF;
712
713 IF csr_get_batch_info%NOTFOUND THEN
714 IF OZF_DEBUG_LOW_ON THEN
715 ozf_utility_pvt.debug_message('No records found');
716 END IF;
717
718 insert_resale_log(
719 p_id_value => p_batch_id,
720 p_id_type => 'BATCH',
721 p_error_code => 'OZF_BATCH_RECORD_EMPTY',
722 p_column_name => NULL,
723 p_column_value => NULL,
724 x_return_status => x_return_status
725 );
726 IF OZF_DEBUG_LOW_ON THEN
727 ozf_utility_pvt.debug_message('x_return_status from insert resale log' ||x_return_status );
728 END IF;
729
730 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
731 RAISE FND_API.G_EXC_ERROR;
732 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
733 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
734 END IF;
735 x_resale_batch_rec := NULL;
736 END IF;
737 CLOSE csr_get_batch_info;
738
739 -- Users may not be giving party id while submitting XML Message
740 -- And the location code they give is also may be Trading Partner's Party Site ID
741 -- OR it could be User defined Location Code, in that case based on
742 -- location code trading partner party id and party site id are retrieved from
743 -- Trading Partner Header
744 IF OZF_DEBUG_LOW_ON THEN
745 ozf_utility_pvt.debug_message('ECX fetch');
746 ozf_utility_pvt.debug_message('x_resale_batch_rec.partner_site_id'||x_resale_batch_rec.partner_site_id);
747 END IF;
748
749 OPEN get_ecx_party_id (x_resale_batch_rec.partner_site_id);
750 FETCH get_ecx_party_id
751 INTO l_partner_party_id,l_party_site_id, l_admin_email;
752 CLOSE get_ecx_party_id;
753
754 IF OZF_DEBUG_LOW_ON THEN
755 ozf_utility_pvt.debug_message('Trading Partner Party ID'||l_partner_party_id);
756 ozf_utility_pvt.debug_message('Trading Partner Site ID'||l_party_site_id);
757 ozf_utility_pvt.debug_message('Admin Email'||l_admin_email);
758 END IF;
759
760 IF x_resale_batch_rec.partner_party_id IS NULL THEN
761 x_resale_batch_rec.partner_party_id := l_partner_party_id;
762 x_resale_batch_rec.partner_site_id := l_party_site_id;
763 G_ADMIN_EMAIL := l_admin_email;
764 END IF;
765
766 IF OZF_DEBUG_LOW_ON THEN
767 ozf_utility_pvt.debug_message('Private API: ' || l_api_name || ': End');
768 END IF;
769
770 EXCEPTION
771 WHEN FND_API.G_EXC_ERROR THEN
772 x_return_status := FND_API.G_RET_STS_ERROR;
773 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
774 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
775 WHEN OTHERS THEN
776 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
777 IF OZF_UNEXP_ERROR THEN
778 FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
779 END IF;
780 END Batch_Fetch;
781
782 PROCEDURE Validate_Batch
783 (
784 p_api_version_number IN NUMBER,
785 p_init_msg_list IN VARCHAR2 := FND_API.G_FALSE,
786 p_commit IN VARCHAR2 := FND_API.G_FALSE,
787 p_validation_level IN NUMBER := FND_API.G_VALID_LEVEL_FULL,
788 p_resale_batch_rec IN ozf_resale_batches_all%rowtype,
789 x_batch_status OUT NOCOPY VARCHAR2,
790 x_return_status OUT NOCOPY VARCHAR2,
791 x_msg_count OUT NOCOPY NUMBER,
792 x_msg_data OUT NOCOPY VARCHAR2
793 )
794 IS
795 l_api_name CONSTANT VARCHAR2(30) := 'Validate_Batch';
799 IS
796 l_api_version_number CONSTANT NUMBER := 1.0;
797
798 CURSOR chk_cust_account ( pc_account_id NUMBER)
800 SELECT 'X'
801 FROM hz_cust_accounts
802 WHERE cust_account_id = pc_account_id;
803
804 l_chk_flag VARCHAR2(1) := NULL;
805 time NUMBER;
806 BEGIN
807 IF OZF_DEBUG_LOW_ON THEN
808 ozf_utility_pvt.debug_message('Private API: ' || l_api_name || ': Start');
809 END IF;
810
811 -- ========================================================================
812 -- NULL Checks
813 -- ========================================================================
814
815 -- Partner id is null
816 IF OZF_DEBUG_LOW_ON THEN
817 time := DBMS_UTILITY.GET_TIME;
818 ozf_utility_pvt.debug_message('Start Time (in Seconds) in '|| l_api_name || ' '|| time/100);
819 END IF;
820
821 IF p_resale_batch_rec.partner_party_id IS NULL THEN
822 IF p_resale_batch_rec.partner_cust_account_id IS NULL THEN
823
824 IF OZF_DEBUG_LOW_ON THEN
825 ozf_utility_pvt.debug_message ( 'Partner Party ID is null ');
826 END IF;
827
828 insert_resale_log
829 (p_id_value => p_resale_batch_rec.resale_batch_id,
830 p_id_type => 'BATCH',
831 p_error_code => 'OZF_BATCH_PARTNER_NULL',
832 p_column_name => NULL,
833 p_column_value => NULL,
834 x_return_status => x_return_status);
835
836 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
837 RAISE FND_API.G_EXC_ERROR;
838 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
839 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
840 END IF;
841
842 x_batch_status := 'REJECTED';
843 END IF;
844 END IF; -- l_partner_party_id is null
845
846 -- Report Start Date is null
847 IF OZF_DEBUG_LOW_ON THEN
848 ozf_utility_pvt.debug_message ( 'Report Start Date '||p_resale_batch_rec.report_start_date);
849 END IF;
850
851 IF (x_batch_status IS NULL OR x_batch_status <> G_BATCH_REJECTED )
852 AND p_resale_batch_rec.report_start_date IS NULL THEN
853
854 IF OZF_DEBUG_LOW_ON THEN
855 ozf_utility_pvt.debug_message ( 'Report Start Date is null ');
856 END IF;
857
858 insert_resale_log
859 ( p_id_value => p_resale_batch_rec.resale_batch_id,
860 p_id_type => 'BATCH',
861 p_error_code => 'OZF_REPORT_START_DATE_NULL',
862 p_column_name => NULL,
863 p_column_value => NULL,
864 x_return_status => x_return_status
865 );
866 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
867 RAISE FND_API.G_EXC_ERROR;
868 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
869 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
870 END IF;
871
872 x_batch_status := 'REJECTED';
873
874 END IF; -- Report Start Date null
875
876 -- Report End Date is null
877 IF OZF_DEBUG_LOW_ON THEN
878 ozf_utility_pvt.debug_message ( 'Report End Date '||p_resale_batch_rec.report_end_date);
879 END IF;
880
881 IF (x_batch_status IS NULL OR x_batch_status <> G_BATCH_REJECTED )
882 AND p_resale_batch_rec.report_end_date IS NULL THEN
883
884 IF OZF_DEBUG_LOW_ON THEN
885 ozf_utility_pvt.debug_message ( 'Report End Date is null ');
886 END IF;
887
888 insert_resale_log
889 (p_id_value => p_resale_batch_rec.resale_batch_id,
890 p_id_type => 'BATCH',
891 p_error_code => 'OZF_REPORT_END_DATE_NULL',
892 p_column_name => NULL,
893 p_column_value => NULL,
894 x_return_status => x_return_status
895 );
896 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
897 RAISE FND_API.G_EXC_ERROR;
898 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
899 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
900 END IF;
901
902 x_batch_status := 'REJECTED';
903
904 END IF; -- Report End Date null
905
906 -- Report Start Date and End Date range check
907 IF ( x_batch_status IS NULL OR x_batch_status <> G_BATCH_REJECTED )
908 AND p_resale_batch_rec.report_start_date IS NOT NULL
909 AND p_resale_batch_rec.report_end_date IS NOT NULL
910 AND p_resale_batch_rec.report_start_date > p_resale_batch_rec.report_end_date
911 THEN
912 IF OZF_DEBUG_LOW_ON THEN
913 ozf_utility_pvt.debug_message ( 'Report start date is less than Report end date ');
914 END IF;
915 insert_resale_log
916 (p_id_value => p_resale_batch_rec.resale_batch_id,
917 p_id_type => 'BATCH',
918 p_error_code => 'OZF_RESALE_WNG_DATE_RANGE',
919 p_column_name => 'REPORT_END_DATE',
920 p_column_value => p_resale_batch_rec.report_end_date,
921 x_return_status => x_return_status
922 );
923 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
924 RAISE FND_API.G_EXC_ERROR;
925 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
926 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
927 END IF;
928
929 x_batch_status := 'REJECTED';
933 -- ========================================================================
930
931 END IF; -- Date Check
932
934 -- Validitity Checks
935 -- ========================================================================
936
937 -- Partner Cust Account ID Validity Check
938
939 IF (x_batch_status IS NULL OR x_batch_status <> G_BATCH_REJECTED )
940 AND p_resale_batch_rec.partner_cust_account_id IS NOT NULL
941 THEN
942
943 OPEN chk_cust_account ( p_resale_batch_rec.partner_cust_account_id );
944 FETCH chk_cust_account INTO l_chk_flag;
945 CLOSE chk_cust_account;
946
947 IF l_chk_flag IS NULL THEN
948 IF OZF_DEBUG_LOW_ON THEN
949 ozf_utility_pvt.debug_message ( 'Partner Customer Account ID is invalid ');
950 END IF;
951
952 insert_resale_log
953 (p_id_value => p_resale_batch_rec.resale_batch_id,
954 p_id_type => 'BATCH',
955 p_error_code => 'OZF_BATCH_PARTNER_ERR',
956 p_column_name => 'PARTNER_CUST_ACCOUNT_ID',
957 p_column_value => p_resale_batch_rec.partner_cust_account_id,
958 x_return_status => x_return_status
959 );
960
961 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
962 RAISE FND_API.G_EXC_ERROR;
963 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
964 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
965 END IF;
966
967 x_batch_status := 'REJECTED';
968 END IF; -- l_chk_flag is NULL
969
970 END IF; -- partner_cust_account_id NOT NULL
971
972 -- Batch Type OR Transaction Type Code is null
973 IF (x_batch_status IS NULL OR x_batch_status <> G_BATCH_REJECTED )
974 AND p_resale_batch_rec.transaction_type_code IS NULL
975 AND p_resale_batch_rec.batch_type IS NULL THEN
976 --
977 IF OZF_DEBUG_LOW_ON THEN
978 ozf_utility_pvt.debug_message ( 'Batch Type and transaction_type_code is null ');
979 END IF;
980
981 insert_resale_log
982 (p_id_value => p_resale_batch_rec.resale_batch_id,
983 p_id_type => 'BATCH',
984 p_error_code => 'OZF_BATCH_TYPE_NULL',
985 p_column_name => 'BATCH_TYPE',
986 p_column_value => p_resale_batch_rec.batch_type,
987 x_return_status => x_return_status
988 );
989
990 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
991 RAISE FND_API.G_EXC_ERROR;
992 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
993 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
994 END IF;
995
996 x_batch_status := 'REJECTED';
997 END IF;
998
999 IF x_batch_status IS NULL OR x_batch_status <> G_BATCH_REJECTED THEN
1000 x_batch_status := g_batch_open;
1001 END IF;
1002
1003 -- Debug Message
1004 IF OZF_DEBUG_LOW_ON THEN
1005 ozf_utility_pvt.debug_message('End Time (in Seconds) in '|| l_api_name || ' '|| (DBMS_UTILITY.GET_TIME - time)/100);
1006 END IF;
1007 IF OZF_DEBUG_HIGH_ON THEN
1008 ozf_utility_pvt.debug_message(l_api_name||': End');
1009 END IF;
1010 EXCEPTION
1011 WHEN FND_API.G_EXC_ERROR THEN
1012 x_return_status := FND_API.G_RET_STS_ERROR;
1013 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1014 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1015 WHEN OTHERS THEN
1016 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1017 IF OZF_UNEXP_ERROR THEN
1018 FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
1019 END IF;
1020 END Validate_Batch;
1021
1022 PROCEDURE Batch_Defaulting
1023 (
1024 p_api_version_number IN NUMBER,
1025 p_init_msg_list IN VARCHAR2 := FND_API.G_FALSE,
1026 p_commit IN VARCHAR2 := FND_API.G_FALSE,
1027 p_validation_level IN NUMBER := FND_API.G_VALID_LEVEL_FULL,
1028 px_resale_batch_rec IN OUT NOCOPY ozf_resale_batches_all%rowtype,
1029 x_return_status OUT NOCOPY VARCHAR2,
1030 x_msg_count OUT NOCOPY NUMBER,
1031 x_msg_data OUT NOCOPY VARCHAR2
1032 )
1033 IS
1034 l_api_name CONSTANT VARCHAR2(30) := 'Batch_Defaulting';
1035 l_api_version_number CONSTANT NUMBER := 1.0;
1036
1037 CURSOR get_partner_id(pc_party_id NUMBER)
1038 IS
1039 SELECT pvpp.partner_id
1040 FROM pv_partner_profiles pvpp
1041 WHERE pvpp.partner_party_id = pc_party_id;
1042
1043 CURSOR get_partner_party_id ( pc_account_id NUMBER )
1044 IS
1045 SELECT party_id
1046 FROM hz_cust_accounts
1047 WHERE cust_account_id = pc_account_id;
1048
1049 l_party_contact_id NUMBER;
1050 l_party_id NUMBER;
1051 l_party_site_id NUMBER;
1052 l_resale_batch_rec ozf_resale_batches_all%rowtype := px_resale_batch_rec;
1053 l_partner_cntct_rec party_cntct_rec_type;
1054 l_partner_rec party_rec_type;
1055 l_dqm_contact_rule VARCHAR2(100);
1056
1057 BEGIN
1058 IF OZF_DEBUG_HIGH_ON THEN
1059 ozf_utility_pvt.debug_message('Private API: ' || l_api_name || ': Start');
1060 END IF;
1061 --
1062 -- Transaction Type Defaulting
1063 -- -----------------------------------------------------------------
1064 IF px_resale_batch_rec.transaction_type_code IS NULL THEN
1065 -- derive if null based on batch type (will happen when loaded from WebADI)
1066 IF px_resale_batch_rec.batch_type IS NOT NULL THEN
1067 IF px_resale_batch_rec.batch_type = OZF_RESALE_COMMON_PVT.G_CHARGEBACK THEN
1068 l_resale_batch_rec.transaction_type_code := g_req_for_credit;
1069 ELSIF px_resale_batch_rec.batch_type = OZF_RESALE_COMMON_PVT.G_SPECIAL_PRICING THEN
1070 l_resale_batch_rec.transaction_type_code := g_resale;
1071 ELSIF px_resale_batch_rec.batch_type = OZF_RESALE_COMMON_PVT.G_TRACING THEN
1072 l_resale_batch_rec.transaction_type_code := g_product_transfer;
1073 END IF;
1074 END IF;
1075 IF OZF_DEBUG_LOW_ON THEN
1076 ozf_utility_pvt.debug_message ( 'Batch Type is '|| l_resale_batch_rec.batch_type);
1077 END IF;
1078 ELSE
1079 --
1080 -- Batch Type Defaulting
1081 -- -----------------------------------------------------------------
1082 IF px_resale_batch_rec.batch_type IS NULL THEN
1083 IF px_resale_batch_rec.transaction_type_code = g_req_for_credit THEN
1084 l_resale_batch_rec.batch_type := OZF_RESALE_COMMON_PVT.G_CHARGEBACK;
1085 ELSIF px_resale_batch_rec.transaction_type_code = g_resale THEN
1086 l_resale_batch_rec.batch_type := OZF_RESALE_COMMON_PVT.G_SPECIAL_PRICING;
1087 ELSIF px_resale_batch_rec.transaction_type_code = g_product_transfer THEN
1088 l_resale_batch_rec.batch_type := OZF_RESALE_COMMON_PVT.G_TRACING;
1089 END IF;
1090 END IF;
1091 IF OZF_DEBUG_LOW_ON THEN
1092 ozf_utility_pvt.debug_message ( 'transaction_type_code is '|| l_resale_batch_rec.transaction_type_code);
1093 END IF;
1094 END IF;
1095
1096 --
1097 -- Report Date Defaulting
1098 -- -----------------------------------------------------------------
1099 IF px_resale_batch_rec.report_date IS NULL THEN
1100 l_resale_batch_rec.report_date := TO_DATE(TO_CHAR(SYSDATE,'MM/DD/YYYY'),'MM/DD/YYYY');
1101 END IF;
1102 IF OZF_DEBUG_LOW_ON THEN
1103 ozf_utility_pvt.debug_message ( 'Report Date is '|| l_resale_batch_rec.report_date);
1104 END IF;
1105 --
1106 -- Transaction Purpose Code Defaulting
1107 -- -----------------------------------------------------------------
1108 IF px_resale_batch_rec.transaction_purpose_code IS NULL THEN
1109 l_resale_batch_rec.transaction_purpose_code := g_original;
1110 END IF;
1111 IF OZF_DEBUG_LOW_ON THEN
1112 ozf_utility_pvt.debug_message ( 'transaction_purpose_code is '|| l_resale_batch_rec.transaction_purpose_code);
1113 END IF;
1114 --
1115 -- Partner Type Defaulting
1116 -- -----------------------------------------------------------------
1117 IF px_resale_batch_rec.partner_type IS NULL THEN
1118 l_resale_batch_rec.partner_type := g_distributor;
1119 END IF;
1120 IF OZF_DEBUG_LOW_ON THEN
1121 ozf_utility_pvt.debug_message ( 'partner_type is '|| l_resale_batch_rec.partner_type);
1122 END IF;
1123
1124 IF px_resale_batch_rec.batch_count IS NULL THEN
1125 l_resale_batch_rec.batch_count := 0;
1126 END IF;
1127 --
1128 -- Cust Account ID Derivation
1129 -- -----------------------------------------------------------------
1130 IF px_resale_batch_rec.partner_cust_account_id IS NULL THEN
1131 IF px_resale_batch_rec.partner_party_id IS NOT NULL THEN
1132
1133 Get_Customer_Accnt_Id
1134 (
1135 p_party_id => px_resale_batch_rec.partner_party_id,
1136 p_party_site_id => px_resale_batch_rec.partner_site_id,
1137 x_return_status => x_return_status,
1138 x_cust_acct_id => l_resale_batch_rec.partner_cust_account_id
1139 );
1140 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
1141 RAISE FND_API.G_EXC_ERROR;
1142 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
1143 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1144 END IF;
1145 IF OZF_DEBUG_LOW_ON THEN
1146 ozf_utility_pvt.debug_message ( 'partner_cust_account_id is '|| l_resale_batch_rec.partner_cust_account_id);
1147 END IF;
1148 END IF;
1149
1150 ELSE
1151 IF px_resale_batch_rec.partner_party_id IS NULL THEN
1152 OPEN get_partner_party_id (px_resale_batch_rec.partner_cust_account_id);
1153 FETCH get_partner_party_id INTO l_resale_batch_rec.partner_party_id;
1154 CLOSE get_partner_party_id;
1155 END IF;
1156 END IF;
1157
1158 OPEN get_partner_id (px_resale_batch_rec.partner_party_id);
1159 FETCH get_partner_id INTO l_resale_batch_rec.partner_id;
1160 CLOSE get_partner_id;
1161
1162 IF OZF_DEBUG_LOW_ON THEN
1163 ozf_utility_pvt.debug_message ( 'partner_id is '|| l_resale_batch_rec.partner_id);
1164 END IF;
1165 --
1166 -- Contact Party ID derivation from DQM
1167 -- -----------------------------------------------------------------
1168
1169 IF ( l_resale_batch_rec.partner_party_id IS NOT NULL
1170 OR px_resale_batch_rec.partner_party_id IS NOT NULL
1171 )
1172 AND
1173 ( px_resale_batch_rec.partner_contact_party_id IS NULL
1174 -- [BEGIN OF BUG 4355728 FIXING]
1175 AND px_resale_batch_rec.partner_contact_name IS NOT NULL
1176 -- [END OF BUG 4355728 FIXING]
1177 ) THEN
1178 IF px_resale_batch_rec.partner_party_id IS NOT NULL THEN
1179 l_partner_rec.party_id := px_resale_batch_rec.partner_party_id;
1180 ELSIF l_resale_batch_rec.partner_party_id IS NOT NULL THEN
1181 l_partner_rec.party_id := l_resale_batch_rec.partner_party_id;
1182 END IF;
1183 l_partner_cntct_rec.contact_name := px_resale_batch_rec.partner_contact_name;
1184 l_partner_cntct_rec.party_email_id := px_resale_batch_rec.partner_email;
1185 l_partner_cntct_rec.party_phone := px_resale_batch_rec.partner_phone;
1186 l_partner_cntct_rec.party_fax := px_resale_batch_rec.partner_fax;
1187 l_dqm_contact_rule := G_DQM_CONTACT_RULE; --fnd_profile.value('OZF_RESALE_CONTACT_DQM_RULE');
1188 IF OZF_DEBUG_LOW_ON THEN
1189 ozf_utility_pvt.debug_message ( 'DQM Contact Rule '|| l_dqm_contact_rule);
1190 END IF;
1191 IF l_dqm_contact_rule IS NOT NULL THEN
1192
1193 l_partner_cntct_rec.contact_rule_name := l_dqm_contact_rule;
1194 IF OZF_DEBUG_LOW_ON THEN
1195 ozf_utility_pvt.debug_message ( 'DQM Contact Rule '|| l_partner_cntct_rec.contact_rule_name);
1196 END IF;
1197 IF l_partner_cntct_rec.contact_name IS NOT NULL THEN
1198
1199 DQM_Processing (
1200 p_api_version_number => 1.0,
1201 p_init_msg_list => FND_API.G_FALSE,
1202 P_Commit => FND_API.G_FALSE,
1203 p_validation_level => FND_API.G_VALID_LEVEL_FULL,
1204 p_party_rec => l_partner_rec,
1205 p_party_site_rec => NULL,
1206 p_contact_rec => l_partner_cntct_rec,
1207 x_party_id => l_party_id,
1208 x_party_site_id => l_party_site_id,
1209 x_party_contact_id => l_party_contact_id,
1210 x_return_status => x_return_status,
1211 x_msg_count => x_msg_count,
1212 x_msg_data => x_msg_data);
1213
1214 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
1215 insert_resale_log
1216 (p_id_value => px_resale_batch_rec.resale_batch_id,
1217 p_id_type => 'BATCH',
1218 p_error_code => 'OZF_DQM_PROCESS_ERROR',
1219 p_column_name => 'P_PARTNER_CONTACT_NAME',
1220 p_column_value => px_resale_batch_rec.batch_type,
1221 x_return_status => x_return_status
1222 );
1223
1224 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
1225 RAISE FND_API.G_EXC_ERROR;
1226 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
1227 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1228 END IF;
1229 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
1230 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1231 END IF;
1232
1233 IF l_party_contact_id IS NULL THEN
1234 l_resale_batch_rec.partner_contact_party_id := l_party_contact_id;
1235 ELSE
1236 IF OZF_DEBUG_LOW_ON THEN
1237 ozf_utility_pvt.debug_message('DQM did not return any contacts ' );
1238 END IF;
1239 END IF;
1240
1241 ELSE
1242 IF OZF_DEBUG_LOW_ON THEN
1243 ozf_utility_pvt.debug_message('Partner Contact name is null ' );
1244 END IF;
1245 END IF; --l_partner_cntct_rec.contact_name
1246 ELSE
1247 IF OZF_DEBUG_LOW_ON THEN
1248 ozf_utility_pvt.debug_message('DQM rules are not setup ' );
1249 END IF;
1250 END IF;
1251 END IF; -- px_resale_batch_rec.partner_contact_party_id
1252
1253 --
1254 -- Status Defaulting
1255 -- -----------------------------------------------------------------
1256 IF l_resale_batch_rec.status_code = 'NEW'
1257 OR l_resale_batch_rec.status_code IS NULL THEN
1258 l_resale_batch_rec.status_code := 'OPEN';
1259 END IF;
1260 IF OZF_DEBUG_LOW_ON THEN
1261 ozf_utility_pvt.debug_message ( 'Status Code '|| l_resale_batch_rec.status_code);
1262 END IF;
1263
1264 --
1265 -- Org ID Defaulting
1266 -- -----------------------------------------------------------------
1267
1268 IF l_resale_batch_rec.org_id IS NULL THEN
1269 l_resale_batch_rec.org_id := G_DEFAULT_ORG_ID; --FND_PROFILE.value('DEFAULT_ORG_ID');
1270 END IF;
1271 IF OZF_DEBUG_LOW_ON THEN
1272 ozf_utility_pvt.debug_message ( 'Org ID '|| l_resale_batch_rec.org_id);
1273 END IF;
1274 -- Derived Record Assignment
1275 -- -----------------------------------------------------------------
1276 px_resale_batch_rec := l_resale_batch_rec;
1277
1278 g_batch_currency_code := l_resale_batch_rec.currency_code;
1279
1280 -- Debug Message
1281 IF OZF_DEBUG_HIGH_ON THEN
1282 ozf_utility_pvt.debug_message(l_api_name||': End');
1283 END IF;
1284
1285 --Standard call to get message count AND IF count=1, get the message
1286 FND_MSG_PUB.Count_And_Get (
1287 p_encoded => FND_API.G_FALSE,
1288 p_count => x_msg_count,
1289 p_data => x_msg_data
1290 );
1291 --
1292 EXCEPTION
1293 WHEN FND_API.G_EXC_ERROR THEN
1294 x_return_status := FND_API.G_RET_STS_ERROR;
1295 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1296 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1297 WHEN OTHERS THEN
1298 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1299 IF OZF_UNEXP_ERROR THEN
1300 FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
1301 END IF;
1302 END Batch_Defaulting;
1303
1304
1305 PROCEDURE Lines_Update
1306 (
1307 p_batch_id IN NUMBER,
1308 px_batch_record IN OUT NOCOPY ozf_resale_batches_all%rowtype,
1309 x_return_status OUT NOCOPY VARCHAR2,
1310 x_msg_data OUT NOCOPY VARCHAR2,
1311 x_msg_count OUT NOCOPY NUMBER
1312 )
1313 IS
1314
1315 l_api_name CONSTANT VARCHAR2(30) := 'Lines_Update';
1316 l_api_version_number CONSTANT NUMBER := 1.0;
1317
1318 CURSOR csr_get_line_info(cv_batch_id NUMBER)
1319 IS
1320 SELECT resale_line_int_id
1321 , object_version_number
1322 , resale_batch_id
1323 , status_code
1324 , resale_transfer_type
1325 , product_transfer_movement_type
1326 , tracing_flag
1327 , ship_from_cust_account_id
1328 , ship_from_site_id
1329 , ship_from_party_name
1330 , ship_from_location
1331 , ship_from_address
1332 , ship_from_city
1333 , ship_from_state
1334 , ship_from_postal_code
1335 , ship_from_country
1336 , ship_from_contact_party_id
1337 , ship_from_contact_name
1338 , ship_from_email
1339 , ship_from_fax
1340 , ship_from_phone
1341 , sold_from_cust_account_id
1342 , sold_from_site_id
1343 , sold_from_party_name
1344 , sold_from_location
1345 , sold_from_address
1346 , sold_from_city
1347 , sold_from_state
1348 , sold_from_postal_code
1349 , sold_from_country
1350 , sold_from_contact_party_id
1351 , sold_from_contact_name
1352 , sold_from_email
1353 , sold_from_phone
1354 , sold_from_fax
1355 , bill_to_cust_account_id
1356 , bill_to_site_use_id
1357 , bill_to_party_id
1358 , bill_to_party_site_id
1359 , bill_to_party_name
1360 , bill_to_duns_number
1361 , bill_to_location
1362 , bill_to_address
1363 , bill_to_city
1364 , bill_to_state
1365 , bill_to_postal_code
1366 , bill_to_country
1367 , bill_to_contact_party_id
1368 , bill_to_contact_name
1369 , bill_to_email
1370 , bill_to_phone
1371 , bill_to_fax
1372 , ship_to_cust_account_id
1373 , ship_to_site_use_id
1374 , ship_to_party_id
1375 , ship_to_party_site_id
1376 , ship_to_party_name
1377 , ship_to_duns_number
1378 , ship_to_location
1379 , ship_to_address
1380 , ship_to_city
1381 , ship_to_country
1382 , ship_to_postal_code
1383 , ship_to_state
1384 , ship_to_contact_party_id
1385 , ship_to_contact_name
1386 , ship_to_email
1387 , ship_to_phone
1388 , ship_to_fax
1389 , end_cust_party_id
1390 , end_cust_site_use_id
1391 , end_cust_site_use_code
1392 , end_cust_party_site_id
1393 , end_cust_party_name
1394 , end_cust_location
1395 , end_cust_address
1396 , end_cust_city
1397 , end_cust_state
1398 , end_cust_postal_code
1399 , end_cust_country
1400 , end_cust_contact_party_id
1401 , end_cust_contact_name
1402 , end_cust_email
1403 , end_cust_phone
1404 , end_cust_fax
1405 , direct_customer_flag
1406 , order_type_id
1407 , order_type
1408 , order_category
1409 , agreement_type
1410 , agreement_id
1411 , agreement_name
1412 , agreement_price
1413 , agreement_uom_code
1414 , corrected_agreement_id
1415 , corrected_agreement_name
1416 , price_list_id
1417 , orig_system_currency_code
1418 , orig_system_selling_price
1419 , orig_system_quantity
1420 , orig_system_uom
1421 , orig_system_purchase_uom
1422 , orig_system_purchase_curr
1423 , orig_system_purchase_price
1424 , orig_system_purchase_quantity
1425 , orig_system_agreement_uom
1426 , orig_system_agreement_name
1427 , orig_system_agreement_type
1428 , orig_system_agreement_curr
1429 , orig_system_agreement_price
1430 , orig_system_agreement_quantity
1431 , orig_system_item_number
1432 , currency_code
1433 , exchange_rate_type
1434 , exchange_rate_date
1435 , exchange_rate
1436 , order_number
1437 , date_ordered
1438 , claimed_amount
1439 , total_claimed_amount
1440 , purchase_price
1441 , acctd_purchase_price
1442 , purchase_uom_code
1443 , selling_price
1444 , acctd_selling_price
1445 , uom_code
1446 , quantity
1447 , inventory_item_id
1448 , item_number
1449 , dispute_code
1450 , data_source_code
1451 , org_id
1452 , response_code
1453 FROM ozf_resale_lines_int
1454 WHERE resale_batch_id = cv_batch_id
1455 -- AND status_code IN ('NEW', 'OPEN', 'DUPLICATED', 'DISPUTED', 'PROCESSED')
1456 --------------------------------------------------------------
1457 -- We're going to process all the lines regardless of the status
1458 -- Since there is no closed line, we don't need status code clause
1459 --------------------------------------------------------------
1460 ORDER BY resale_line_int_id;
1461
1462 l_line_record resale_line_int_rec_type;
1463 l_array_size NUMBER DEFAULT 10;
1464 l_done BOOLEAN;
1465 l_cnt NUMBER DEFAULT 0;
1466 l_line_count NUMBER;
1467
1468 BEGIN
1469 IF OZF_DEBUG_HIGH_ON THEN
1470 ozf_utility_pvt.debug_message('Private API: ' || l_api_name || ': Start');
1471 END IF;
1472 x_return_status := FND_API.G_RET_STS_SUCCESS;
1473 OPEN csr_get_line_info ( p_batch_id);
1474 LOOP
1475 -- bulk fetch the lines data
1476 FETCH csr_get_line_info
1477 BULK COLLECT INTO l_line_record.resale_line_int_id
1478 , l_line_record.object_version_number
1479 , l_line_record.resale_batch_id
1480 , l_line_record.status_code
1481 , l_line_record.resale_transfer_type
1482 , l_line_record.product_transfer_movement_type
1483 , l_line_record.tracing_flag
1484 , l_line_record.ship_from_cust_account_id
1485 , l_line_record.ship_from_site_id
1486 , l_line_record.ship_from_party_name
1487 , l_line_record.ship_from_location
1488 , l_line_record.ship_from_address
1489 , l_line_record.ship_from_city
1490 , l_line_record.ship_from_state
1491 , l_line_record.ship_from_postal_code
1492 , l_line_record.ship_from_country
1493 , l_line_record.ship_from_contact_party_id
1494 , l_line_record.ship_from_contact_name
1495 , l_line_record.ship_from_email
1496 , l_line_record.ship_from_fax
1497 , l_line_record.ship_from_phone
1498 , l_line_record.sold_from_cust_account_id
1499 , l_line_record.sold_from_site_id
1500 , l_line_record.sold_from_party_name
1501 , l_line_record.sold_from_location
1502 , l_line_record.sold_from_address
1503 , l_line_record.sold_from_city
1504 , l_line_record.sold_from_state
1505 , l_line_record.sold_from_postal_code
1506 , l_line_record.sold_from_country
1507 , l_line_record.sold_from_contact_party_id
1508 , l_line_record.sold_from_contact_name
1509 , l_line_record.sold_from_email
1510 , l_line_record.sold_from_phone
1511 , l_line_record.sold_from_fax
1512 , l_line_record.bill_to_cust_account_id
1513 , l_line_record.bill_to_site_use_id
1514 , l_line_record.bill_to_party_id
1515 , l_line_record.bill_to_party_site_id
1516 , l_line_record.bill_to_party_name
1517 , l_line_record.bill_to_duns_number
1518 , l_line_record.bill_to_location
1519 , l_line_record.bill_to_address
1520 , l_line_record.bill_to_city
1521 , l_line_record.bill_to_state
1522 , l_line_record.bill_to_postal_code
1523 , l_line_record.bill_to_country
1524 , l_line_record.bill_to_contact_party_id
1525 , l_line_record.bill_to_contact_name
1526 , l_line_record.bill_to_email
1527 , l_line_record.bill_to_phone
1528 , l_line_record.bill_to_fax
1529 , l_line_record.ship_to_cust_account_id
1530 , l_line_record.ship_to_site_use_id
1531 , l_line_record.ship_to_party_id
1532 , l_line_record.ship_to_party_site_id
1533 , l_line_record.ship_to_party_name
1534 , l_line_record.ship_to_duns_number
1535 , l_line_record.ship_to_location
1536 , l_line_record.ship_to_address
1537 , l_line_record.ship_to_city
1538 , l_line_record.ship_to_country
1539 , l_line_record.ship_to_postal_code
1540 , l_line_record.ship_to_state
1541 , l_line_record.ship_to_contact_party_id
1542 , l_line_record.ship_to_contact_name
1543 , l_line_record.ship_to_email
1544 , l_line_record.ship_to_phone
1545 , l_line_record.ship_to_fax
1546 , l_line_record.end_cust_party_id
1547 , l_line_record.end_cust_site_use_id
1548 , l_line_record.end_cust_site_use_code
1549 , l_line_record.end_cust_party_site_id
1550 , l_line_record.end_cust_party_name
1551 , l_line_record.end_cust_location
1552 , l_line_record.end_cust_address
1553 , l_line_record.end_cust_city
1554 , l_line_record.end_cust_state
1555 , l_line_record.end_cust_postal_code
1556 , l_line_record.end_cust_country
1557 , l_line_record.end_cust_contact_party_id
1558 , l_line_record.end_cust_contact_name
1559 , l_line_record.end_cust_email
1560 , l_line_record.end_cust_phone
1561 , l_line_record.end_cust_fax
1562 , l_line_record.direct_customer_flag
1563 , l_line_record.order_type_id
1564 , l_line_record.order_type
1565 , l_line_record.order_category
1566 , l_line_record.agreement_type
1567 , l_line_record.agreement_id
1568 , l_line_record.agreement_name
1569 , l_line_record.agreement_price
1570 , l_line_record.agreement_uom_code
1571 , l_line_record.corrected_agreement_id
1572 , l_line_record.corrected_agreement_name
1573 , l_line_record.price_list_id
1574 , l_line_record.orig_system_currency_code
1575 , l_line_record.orig_system_selling_price
1576 , l_line_record.orig_system_quantity
1577 , l_line_record.orig_system_uom
1578 , l_line_record.orig_system_purchase_uom
1579 , l_line_record.orig_system_purchase_curr
1580 , l_line_record.orig_system_purchase_price
1581 , l_line_record.orig_system_purchase_quantity
1582 , l_line_record.orig_system_agreement_uom
1583 , l_line_record.orig_system_agreement_name
1584 , l_line_record.orig_system_agreement_type
1585 , l_line_record.orig_system_agreement_curr
1586 , l_line_record.orig_system_agreement_price
1587 , l_line_record.orig_system_agreement_quantity
1588 , l_line_record.orig_system_item_number
1589 , l_line_record.currency_code
1590 , l_line_record.exchange_rate_type
1591 , l_line_record.exchange_rate_date
1592 , l_line_record.exchange_rate
1593 , l_line_record.order_number
1594 , l_line_record.date_ordered
1595 , l_line_record.claimed_amount
1596 , l_line_record.total_claimed_amount
1597 , l_line_record.purchase_price
1598 , l_line_record.acctd_purchase_price
1599 , l_line_record.purchase_uom_code
1600 , l_line_record.selling_price
1601 , l_line_record.acctd_selling_price
1602 , l_line_record.uom_code
1603 , l_line_record.quantity
1604 , l_line_record.inventory_item_id
1605 , l_line_record.item_number
1606 , l_line_record.dispute_code
1607 , l_line_record.data_source_code
1608 , l_line_record.org_id
1609 , l_line_record.response_code
1610 LIMIT l_array_size;
1611 l_done := csr_get_line_info%notfound;
1612 l_cnt := l_cnt + l_line_record.resale_line_int_id.count;
1613 l_line_count := l_line_record.resale_line_int_id.count;
1614
1615 -- if the batch status is rejected, update all line status to Rejected
1616 -- without processing
1617
1618 IF l_cnt = 0 OR px_batch_record.status_code = g_batch_rejected THEN
1619 l_line_record.status_code := set_line_status
1620 ( l_line_count
1621 ,'REJECTED');
1622 IF l_cnt = 0 THEN
1623 px_batch_record.status_code := g_batch_rejected;
1624 END IF;
1625 ELSE
1626 -- Initialize line status to 'OPEN' for all the lines
1627 l_line_record.status_code := set_line_status
1628 ( l_line_count
1629 ,'OPEN');
1630 -- Process the lines
1631 Lines_Process
1632 (
1633 p_line_count => l_line_record.resale_line_int_id.count,
1634 px_batch_record => px_batch_record,
1635 px_line_record => l_line_record,
1636 x_return_status => x_return_status,
1637 x_msg_count => x_msg_count,
1638 x_msg_data => x_msg_data
1639 );
1640 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
1641 RAISE FND_API.G_EXC_ERROR;
1642 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
1643 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1644 END IF;
1645
1646 END IF;
1647
1648 -- Bulk update the lines with processed values
1649 Lines_Bulk_Update
1650 (
1651 p_batch_id => p_batch_id,
1652 p_line_record => l_line_record,
1653 x_return_status => x_return_status
1654 );
1655 EXIT WHEN (l_done);
1656 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
1657 RAISE FND_API.G_EXC_ERROR;
1658 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
1659 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1660 END IF;
1661 END LOOP;
1662 CLOSE csr_get_line_info;
1663 -- Total Line Count
1664 /* IF px_batch_record.batch_count IS NULL
1665 OR px_batch_record.batch_count = 0 THEN
1666 px_batch_record.batch_count := l_cnt;
1667 ELSE
1668 IF px_batch_record.batch_set_id_code = 'WEBADI' THEN
1669 IF l_cnt > 0 THEN
1670 px_batch_record.batch_count := px_batch_record.batch_count + l_cnt;
1671 END IF;
1672 ELSE
1673 px_batch_record.batch_count := l_cnt;
1674 END IF;
1675 END IF; */
1676 -- Setting Dispute Status and Disputed Line Count
1677 /* IF G_DISPUTED_LINE_COUNT > 0 THEN
1678 px_batch_record.status_code := g_batch_disputed;
1679 px_batch_record.lines_disputed := g_disputed_line_count;
1680 END IF;
1681 -- if the processed lines is equal to number of lines fetched then set the batch status to
1682 -- 'OPEN'
1683 IF G_LINES_PROCESSED = l_cnt THEN
1684 px_batch_record.status_code := g_batch_open;
1685 END IF; */
1686 IF OZF_DEBUG_LOW_ON THEN
1687 ozf_utility_pvt.debug_message('Total Line Count '|| l_cnt);
1688 END IF;
1689 IF OZF_DEBUG_HIGH_ON THEN
1690 ozf_utility_pvt.debug_message('Private API: ' || l_api_name || ': End');
1691 END IF;
1692 EXCEPTION
1693 WHEN FND_API.G_EXC_ERROR THEN
1694 x_return_status := FND_API.G_RET_STS_ERROR;
1695 -- Standard call to get message count and if count=1, get the message
1696 FND_MSG_PUB.Count_And_Get (
1697 p_encoded => FND_API.G_FALSE,
1698 p_count => x_msg_count,
1699 p_data => x_msg_data
1700 );
1701 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1702 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1703 -- Standard call to get message count and if count=1, get the message
1704 FND_MSG_PUB.Count_And_Get (
1705 p_encoded => FND_API.G_FALSE,
1706 p_count => x_msg_count,
1707 p_data => x_msg_data
1708 );
1709 WHEN OTHERS THEN
1710
1711 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1712 IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
1713 THEN
1714 FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
1715 END IF;
1716 -- Standard call to get message count and if count=1, get the message
1717 FND_MSG_PUB.Count_And_Get (
1718 p_encoded => FND_API.G_FALSE,
1719 p_count => x_msg_count,
1720 p_data => x_msg_data
1721 );
1722 END Lines_Update;
1723
1724 PROCEDURE Lines_Process
1725 (
1726 p_line_count IN NUMBER,
1727 px_batch_record IN OUT NOCOPY ozf_resale_batches_all%rowtype,
1728 px_line_record IN OUT NOCOPY resale_line_int_rec_type,
1729 x_return_status OUT NOCOPY VARCHAR2,
1730 x_msg_data OUT NOCOPY VARCHAR2,
1731 x_msg_count OUT NOCOPY NUMBER
1732 )
1733 IS
1734 l_api_name CONSTANT VARCHAR2(30) := 'Lines_Process';
1735 l_api_version_number CONSTANT NUMBER := 1.0;
1736
1737 BEGIN
1738 IF OZF_DEBUG_HIGH_ON THEN
1739 ozf_utility_pvt.debug_message('Private API: ' || l_api_name || ' start');
1740 END IF;
1741 IF FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
1742 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE, 'ozf.idsm.workflow.preprocess.lines_process',
1743 'Private API: ' || l_api_name || ' start');
1744 END IF;
1745
1746 x_return_status := FND_API.G_RET_STS_SUCCESS;
1747
1748 -- julou 6165855: changed the order of Code_ID_Mapping and Line_Defaulting
1749 -- Apply the defaulting rules to the line
1750 Line_Defaulting(
1751 p_line_count => p_line_count,
1752 px_line_record => px_line_record,
1753 x_return_status => x_return_status);
1754
1755 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
1756 RAISE FND_API.G_EXC_ERROR;
1757 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
1758 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1759 END IF;
1760
1761 -- For all the external codes get the internal code
1762 Code_ID_Mapping(
1763 p_batch_record => px_batch_record,
1764 px_line_record => px_line_record,
1765 x_return_status => x_return_status,
1766 x_msg_count => x_msg_count,
1767 x_msg_data => x_msg_data);
1768
1769 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
1770 RAISE FND_API.G_EXC_ERROR;
1771 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
1772 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1773 END IF;
1774
1775 -- Validate the line with supplied values
1776 Line_Validations(
1777 p_line_count => p_line_count,
1778 px_batch_record => px_batch_record,
1779 px_line_record => px_line_record,
1780 x_return_status => x_return_status);
1781
1782 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
1783 RAISE FND_API.G_EXC_ERROR;
1784 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
1785 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1786 END IF;
1787
1788 IF OZF_DEBUG_HIGH_ON THEN
1789 ozf_utility_pvt.debug_message('Private API: ' || l_api_name || ' end');
1790 END IF;
1791 IF FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL THEN
1792 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE, 'ozf.idsm.workflow.preprocess.lines_process',
1793 'Private API: ' || l_api_name || ' end');
1794 END IF;
1795
1796 EXCEPTION
1797 WHEN FND_API.G_EXC_ERROR THEN
1798 x_return_status := FND_API.G_RET_STS_ERROR;
1799 -- Standard call to get message count and if count=1, get the message
1800 FND_MSG_PUB.Count_And_Get (
1801 p_encoded => FND_API.G_FALSE,
1802 p_count => x_msg_count,
1803 p_data => x_msg_data
1804 );
1805 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1806 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1807 -- Standard call to get message count and if count=1, get the message
1808 FND_MSG_PUB.Count_And_Get (
1809 p_encoded => FND_API.G_FALSE,
1810 p_count => x_msg_count,
1811 p_data => x_msg_data
1812 );
1813 WHEN OTHERS THEN
1814
1815 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1816 IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
1817 THEN
1818 FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
1819 END IF;
1820 -- Standard call to get message count and if count=1, get the message
1821 FND_MSG_PUB.Count_And_Get (
1822 p_encoded => FND_API.G_FALSE,
1823 p_count => x_msg_count,
1824 p_data => x_msg_data
1825 );
1826 END Lines_Process;
1827
1828 PROCEDURE Lines_Bulk_Update
1829 (
1830 p_batch_id IN NUMBER,
1831 p_line_record IN resale_line_int_rec_type,
1832 x_return_status OUT NOCOPY VARCHAR2
1833 )
1834 IS
1835 l_api_name CONSTANT VARCHAR2(30) := 'Lines_Bulk_Update';
1836 l_api_version_number CONSTANT NUMBER := 1.0;
1837
1838 cnt NUMBER := 0;
1839
1840 BEGIN
1841 IF OZF_DEBUG_LOW_ON THEN
1842 ozf_utility_pvt.debug_message('Private API: ' || l_api_name || ': start');
1843 END IF;
1844
1845 x_return_status := FND_API.G_RET_STS_SUCCESS;
1846
1847 IF OZF_DEBUG_LOW_ON THEN
1848 ozf_utility_pvt.debug_message('Batch ID ' || p_batch_id);
1849 ozf_utility_pvt.debug_message('Line Count in line bulk update ' || p_line_record.resale_line_int_id.COUNT);
1850 END IF;
1851
1852 FORALL i IN 1 .. p_line_record.resale_line_int_id.COUNT
1853 UPDATE ozf_resale_lines_int_all
1854 SET object_version_number = p_line_record.object_version_number(i)
1855 , resale_batch_id = p_line_record.resale_batch_id(i)
1856 , status_code = p_line_record.status_code(i)
1857 , resale_transfer_type = p_line_record.resale_transfer_type(i)
1858 , product_transfer_movement_type= p_line_record.product_transfer_movement_type(i)
1859 , tracing_flag = p_line_record.tracing_flag(i)
1860 , ship_from_cust_account_id = p_line_record.ship_from_cust_account_id(i)
1861 , ship_from_site_id = p_line_record.ship_from_site_id(i)
1862 , ship_from_party_name = p_line_record.ship_from_party_name(i)
1863 , ship_from_location = p_line_record.ship_from_location(i)
1864 , ship_from_address = p_line_record.ship_from_address(i)
1865 , ship_from_city = p_line_record.ship_from_city(i)
1866 , ship_from_state = p_line_record.ship_from_state(i)
1867 , ship_from_postal_code = p_line_record.ship_from_postal_code(i)
1868 , ship_from_country = p_line_record.ship_from_country(i)
1869 , ship_from_contact_party_id = p_line_record.ship_from_contact_party_id(i)
1870 , ship_from_contact_name = p_line_record.ship_from_contact_name(i)
1871 , ship_from_email = p_line_record.ship_from_email(i)
1872 , ship_from_fax = p_line_record.ship_from_fax(i)
1873 , ship_from_phone = p_line_record.ship_from_phone(i)
1874 , sold_from_cust_account_id = p_line_record.sold_from_cust_account_id(i)
1875 , sold_from_site_id = p_line_record.sold_from_site_id(i)
1876 , sold_from_party_name = p_line_record.sold_from_party_name(i)
1877 , sold_from_location = p_line_record.sold_from_location(i)
1878 , sold_from_address = p_line_record.sold_from_address(i)
1879 , sold_from_city = p_line_record.sold_from_city(i)
1880 , sold_from_state = p_line_record.sold_from_state(i)
1881 , sold_from_postal_code = p_line_record.sold_from_postal_code(i)
1882 , sold_from_country = p_line_record.sold_from_country(i)
1883 , sold_from_contact_party_id = p_line_record.sold_from_contact_party_id(i)
1884 , sold_from_contact_name = p_line_record.sold_from_contact_name(i)
1885 , sold_from_email = p_line_record.sold_from_email(i)
1886 , sold_from_phone = p_line_record.sold_from_phone(i)
1887 , sold_from_fax = p_line_record.sold_from_fax(i)
1888 , bill_to_cust_account_id = p_line_record.bill_to_cust_account_id(i)
1889 , bill_to_site_use_id = p_line_record.bill_to_site_use_id(i)
1890 , bill_to_party_id = p_line_record.bill_to_party_id(i)
1891 , bill_to_party_site_id = p_line_record.bill_to_party_site_id(i)
1892 , bill_to_party_name = p_line_record.bill_to_party_name(i)
1893 , bill_to_duns_number = p_line_record.bill_to_duns_number(i)
1894 , bill_to_location = p_line_record.bill_to_location(i)
1895 , bill_to_address = p_line_record.bill_to_address(i)
1896 , bill_to_city = p_line_record.bill_to_city(i)
1897 , bill_to_state = p_line_record.bill_to_state(i)
1898 , bill_to_postal_code = p_line_record.bill_to_postal_code(i)
1899 , bill_to_country = p_line_record.bill_to_country(i)
1900 , bill_to_contact_party_id = p_line_record.bill_to_contact_party_id(i)
1901 , bill_to_contact_name = p_line_record.bill_to_contact_name(i)
1902 , bill_to_email = p_line_record.bill_to_email(i)
1903 , bill_to_phone = p_line_record.bill_to_phone(i)
1904 , bill_to_fax = p_line_record.bill_to_fax(i)
1905 , ship_to_cust_account_id = p_line_record.ship_to_cust_account_id(i)
1906 , ship_to_site_use_id = p_line_record.ship_to_site_use_id(i)
1907 , ship_to_party_id = p_line_record.ship_to_party_id(i)
1908 , ship_to_party_site_id = p_line_record.ship_to_party_site_id(i)
1909 , ship_to_party_name = p_line_record.ship_to_party_name(i)
1910 , ship_to_duns_number = p_line_record.ship_to_duns_number(i)
1911 , ship_to_location = p_line_record.ship_to_location(i)
1912 , ship_to_address = p_line_record.ship_to_address(i)
1913 , ship_to_city = p_line_record.ship_to_city(i)
1914 , ship_to_country = p_line_record.ship_to_country(i)
1915 , ship_to_postal_code = p_line_record.ship_to_postal_code(i)
1916 , ship_to_state = p_line_record.ship_to_state(i)
1917 , ship_to_contact_party_id = p_line_record.ship_to_contact_party_id(i)
1918 , ship_to_contact_name = p_line_record.ship_to_contact_name(i)
1919 , ship_to_email = p_line_record.ship_to_email(i)
1920 , ship_to_phone = p_line_record.ship_to_phone(i)
1921 , ship_to_fax = p_line_record.ship_to_fax(i)
1922 , end_cust_party_id = p_line_record.end_cust_party_id(i)
1923 , end_cust_site_use_id = p_line_record.end_cust_site_use_id(i)
1924 , end_cust_site_use_code = p_line_record.end_cust_site_use_code(i)
1925 , end_cust_party_site_id = p_line_record.end_cust_party_site_id(i)
1926 , end_cust_party_name = p_line_record.end_cust_party_name(i)
1927 , end_cust_location = p_line_record.end_cust_location(i)
1928 , end_cust_address = p_line_record.end_cust_address(i)
1929 , end_cust_city = p_line_record.end_cust_city(i)
1930 , end_cust_state = p_line_record.end_cust_state(i)
1931 , end_cust_postal_code = p_line_record.end_cust_postal_code(i)
1932 , end_cust_country = p_line_record.end_cust_country(i)
1933 , end_cust_contact_party_id = p_line_record.end_cust_contact_party_id(i)
1934 , end_cust_contact_name = p_line_record.end_cust_contact_name(i)
1935 , end_cust_email = p_line_record.end_cust_email(i)
1936 , end_cust_phone = p_line_record.end_cust_phone(i)
1937 , end_cust_fax = p_line_record.end_cust_fax(i)
1938 , direct_customer_flag = p_line_record.direct_customer_flag(i)
1939 , order_type_id = p_line_record.order_type_id(i)
1940 , order_type = p_line_record.order_type(i)
1941 , order_category = p_line_record.order_category(i)
1942 , agreement_type = p_line_record.agreement_type(i)
1943 , agreement_id = p_line_record.agreement_id(i)
1944 , agreement_name = p_line_record.agreement_name(i)
1945 , agreement_price = p_line_record.agreement_price(i)
1946 , agreement_uom_code = p_line_record.agreement_uom_code(i)
1947 , corrected_agreement_id = p_line_record.corrected_agreement_id(i)
1948 , corrected_agreement_name = p_line_record.corrected_agreement_name(i)
1949 , price_list_id = p_line_record.price_list_id(i)
1950 , orig_system_currency_code = p_line_record.orig_system_currency_code(i)
1951 , orig_system_selling_price = p_line_record.orig_system_selling_price(i)
1952 , orig_system_quantity = p_line_record.orig_system_quantity(i)
1953 , orig_system_uom = p_line_record.orig_system_uom(i)
1954 , orig_system_purchase_uom = p_line_record.orig_system_purchase_uom(i)
1955 , orig_system_purchase_curr = p_line_record.orig_system_purchase_curr(i)
1956 , orig_system_purchase_price = p_line_record.orig_system_purchase_price(i)
1957 , orig_system_purchase_quantity = p_line_record.orig_system_purchase_quantity(i)
1958 , orig_system_agreement_uom = p_line_record.orig_system_agreement_uom(i)
1959 , orig_system_agreement_name = p_line_record.orig_system_agreement_name(i)
1960 , orig_system_agreement_type = p_line_record.orig_system_agreement_type(i)
1961 , orig_system_agreement_curr = p_line_record.orig_system_agreement_curr(i)
1962 , orig_system_agreement_price = p_line_record.orig_system_agreement_price(i)
1963 , orig_system_agreement_quantity= p_line_record.orig_system_agreement_quantity(i)
1964 , orig_system_item_number = p_line_record.orig_system_item_number(i)
1965 , currency_code = p_line_record.currency_code(i)
1966 , exchange_rate_type = p_line_record.exchange_rate_type(i)
1967 , exchange_rate = p_line_record.exchange_rate(i)
1968 , order_number = p_line_record.order_number(i)
1969 , date_ordered = p_line_record.date_ordered(i)
1970 , claimed_amount = p_line_record.claimed_amount(i)
1971 , total_claimed_amount = p_line_record.total_claimed_amount(i)
1972 , purchase_price = p_line_record.purchase_price(i)
1973 , acctd_purchase_price = p_line_record.acctd_purchase_price(i)
1974 , purchase_uom_code = p_line_record.purchase_uom_code(i)
1975 , selling_price = p_line_record.selling_price(i)
1976 , acctd_selling_price = p_line_record.acctd_selling_price(i)
1977 , uom_code = p_line_record.uom_code(i)
1978 , quantity = p_line_record.quantity(i)
1979 , inventory_item_id = p_line_record.inventory_item_id(i)
1980 , item_number = p_line_record.item_number(i)
1981 , dispute_code = p_line_record.dispute_code(i)
1982 , data_source_code = p_line_record.data_source_code(i)
1983 , org_id = p_line_record.org_id(i)
1984 , response_code = p_line_record.response_code(i)
1985 WHERE resale_batch_id = p_batch_id
1986 AND resale_line_int_id = p_line_record.resale_line_int_id(i);
1987
1988 IF OZF_DEBUG_HIGH_ON THEN
1989 ozf_utility_pvt.debug_message('SQL%RowCount ' || SQL%ROWCOUNT);
1990 ozf_utility_pvt.debug_message('Private API: ' || l_api_name || ' end');
1991 END IF;
1992 EXCEPTION
1993 WHEN FND_API.G_EXC_ERROR THEN
1994 x_return_status := FND_API.G_RET_STS_ERROR;
1995 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1996 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1997 WHEN OTHERS THEN
1998 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1999 IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
2000 THEN
2001 FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
2002 END IF;
2003 END Lines_Bulk_Update;
2004
2005 PROCEDURE Line_Defaulting
2006 (
2007 p_line_count IN NUMBER,
2008 px_line_record IN OUT NOCOPY resale_line_int_rec_type,
2009 x_return_status OUT NOCOPY VARCHAR2
2010 )
2011 IS
2012 l_api_name CONSTANT VARCHAR2(30) := 'Line_Defaulting';
2013 l_api_version_number CONSTANT NUMBER := 1.0;
2014
2015 l_batch_type VARCHAR2(30);
2016
2017 BEGIN
2018 IF OZF_DEBUG_HIGH_ON THEN
2019 ozf_utility_pvt.debug_message('Private API: ' || l_api_name || ' start');
2020 END IF;
2021
2022 x_return_status := FND_API.G_RET_STS_SUCCESS;
2023
2024 -- Inventory Tracking Flag
2025
2026 OPEN OZF_RESALE_COMMON_PVT.g_inventory_tracking_csr;
2027 FETCH OZF_RESALE_COMMON_PVT.g_inventory_tracking_csr INTO g_inventory_tracking_flag;
2028 CLOSE OZF_RESALE_COMMON_PVT.g_inventory_tracking_csr;
2029 IF g_inventory_tracking_flag IS NULL THEN
2030 g_inventory_tracking_flag := 'F';
2031 END IF;
2032
2033 IF OZF_DEBUG_LOW_ON THEN
2034 ozf_utility_pvt.debug_message('Inventory Tracking Flag ' || g_inventory_tracking_flag);
2035 END IF;
2036 -- Derive the currency from batch if the line currency is null
2037 -- and the purchase price and selling price is dervied by applying the
2038 -- currency conversion if the currencies are different for purchase, agreement and selling price
2039
2040 Line_Currency_Price_Derivation
2041 (
2042 p_line_count => p_line_count,
2043 px_line_record => px_line_record,
2044 x_return_status => x_return_status
2045 );
2046
2047 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
2048 RAISE FND_API.G_EXC_ERROR;
2049 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
2050 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2051 END IF;
2052
2053 IF p_line_count > 0 THEN
2054 OPEN OZF_RESALE_COMMON_PVT.g_batch_type_csr(px_line_record.resale_batch_id(1));
2055 FETCH OZF_RESALE_COMMON_PVT.g_batch_type_csr INTO l_batch_type;
2056 CLOSE OZF_RESALE_COMMON_PVT.g_batch_type_csr;
2057
2058 FOR i IN 1 .. p_line_count
2059 LOOP
2060
2061 -- Derive ORG ID
2062 IF px_line_record.org_id(i) IS NULL THEN
2063 px_line_record.org_id(i) := G_DEFAULT_ORG_ID; --FND_PROFILE.value('DEFAULT_ORG_ID');
2064 END IF;
2065 -- Derive Quantity from External Quantity
2066 IF px_line_record.quantity(i) IS NULL THEN
2067 IF px_line_record.orig_system_quantity(i) IS NOT NULL THEN
2068 px_line_record.quantity(i) := px_line_record.orig_system_quantity(i);
2069 END IF;
2070 END IF;
2071 -- Derive Product Transfer Movement Type from Order Category OR Quantity
2072 IF px_line_record.product_transfer_movement_type(i) IS NULL THEN
2073 IF px_line_record.order_category(i) IS NOT NULL THEN
2074 IF px_line_record.order_category(i) = 'ORDER' THEN
2075 px_line_record.product_transfer_movement_type(i) := g_mvmt_dist_to_cust;
2076 ELSIF px_line_record.order_category(i) = 'RETURN' THEN
2077 px_line_record.product_transfer_movement_type(i) := g_mvmt_cust_to_dist;
2078 END IF;
2079 ELSE
2080 IF px_line_record.quantity(i) < 0 THEN
2081 px_line_record.product_transfer_movement_type(i) := g_mvmt_cust_to_dist;
2082 ELSE
2083 px_line_record.product_transfer_movement_type(i) := g_mvmt_dist_to_cust;
2084 END IF;
2085 END IF; -- sign(p_quantity(i)) = -1
2086 END IF;
2087 IF OZF_DEBUG_LOW_ON THEN
2088 ozf_utility_pvt.debug_message('Movement Type ' || px_line_record.product_transfer_movement_type(i));
2089 END IF;
2090
2091 -- Derive Resale Transfer Type
2092
2093 IF px_line_record.resale_transfer_type(i) IS NULL THEN
2094 -- BUG 4558568 (+)
2095 IF SIGN(px_line_record.quantity(i)) = -1 AND
2096 px_line_record.product_transfer_movement_type(i) = g_mvmt_cust_to_dist THEN
2097 px_line_record.resale_transfer_type(i) := g_tsfr_return;
2098 ELSE
2099 -- BUG 4558568 (-)
2100 IF px_line_record.agreement_name(i) IS NOT NULL
2101 OR px_line_record.agreement_id(i) IS NOT NULL THEN
2102 px_line_record.resale_transfer_type(i) := g_tsfr_ship_debit_sale;
2103 ELSE
2104 IF px_line_record.product_transfer_movement_type(i)
2105 IN (g_mvmt_tsfr_in,g_mvmt_tsfr_out) THEN
2106 px_line_record.resale_transfer_type(i) := g_tsfr_inter_branch;
2107 ELSIF px_line_record.product_transfer_movement_type(i) = g_mvmt_cust_to_dist THEN
2108 px_line_record.resale_transfer_type(i) := g_tsfr_return;
2109 ELSIF px_line_record.product_transfer_movement_type(i) = g_mvmt_dist_to_cust THEN
2110 px_line_record.resale_transfer_type(i) := g_tsfr_stock_sale;
2111 END IF; -- px_line_record.product_transfer_movement_type
2112 END IF; -- p_agreement_name(i) IS NOT NULL
2113 END IF;
2114 END IF; -- px_line_record.resale_transfer_type(i) IS NULL
2115
2116 IF OZF_DEBUG_LOW_ON THEN
2117 ozf_utility_pvt.debug_message('resale_transfer_type' || px_line_record.resale_transfer_type(i));
2118 END IF;
2119
2120 -- Derive Order Category
2121
2122 IF px_line_record.order_category(i) IS NULL THEN
2123 IF px_line_record.product_transfer_movement_type(i) = g_mvmt_cust_to_dist THEN
2124 px_line_record.order_category(i) := 'RETURN';
2125 ELSIF px_line_record.product_transfer_movement_type(i) = g_mvmt_dist_to_cust THEN
2126 px_line_record.order_category(i) := 'ORDER';
2127 END IF;
2128
2129 END IF;
2130
2131 IF OZF_DEBUG_LOW_ON THEN
2132 ozf_utility_pvt.debug_message('order_category' || px_line_record.order_category(i));
2133 END IF;
2134
2135 OPEN OZF_RESALE_COMMON_PVT.g_batch_type_csr(px_line_record.resale_batch_id(i));
2136 FETCH OZF_RESALE_COMMON_PVT.g_batch_type_csr INTO l_batch_type;
2137 CLOSE OZF_RESALE_COMMON_PVT.g_batch_type_csr;
2138
2139 IF l_batch_type = 'TP_ACCRUAL' THEN
2140 IF px_line_record.agreement_type(i) IS NULL AND px_line_record.agreement_id(i) IS NULL AND px_line_record.price_list_id(i) IS NULL THEN
2141 px_line_record.price_list_id(i) := FND_PROFILE.value('OZF_TP_ACCRUAL_PRICE_LIST');
2142 END IF;
2143 END IF;
2144
2145 IF px_line_record.price_list_id(i) IS NOT NULL AND
2146 px_line_record.agreement_id(i) IS NULL THEN
2147 px_line_record.agreement_type(i) := 'PL';
2148 px_line_record.agreement_id(i) := px_line_record.price_list_id(i);
2149 ELSIF px_line_record.price_list_id(i) IS NULL AND
2150 px_line_record.agreement_id(i) IS NOT NULL AND
2151 px_line_record.agreement_type(i) = 'PL' THEN
2152 px_line_record.price_list_id(i) := px_line_record.agreement_id(i);
2153 END IF;
2154 IF OZF_DEBUG_LOW_ON THEN
2155 ozf_utility_pvt.debug_message('agreement_id' || px_line_record.agreement_id(i));
2156 END IF;
2157
2158 -- Derive Tracing flag
2159 IF px_line_record.tracing_flag(i) IS NULL THEN
2160 IF l_batch_type = 'TRACING' THEN
2161 px_line_record.tracing_flag(i) := 'T';
2162 ELSIF px_line_record.agreement_type(i) IS NULL AND
2163 px_line_record.agreement_id(i) IS NULL AND
2164 px_line_record.agreement_name(i) IS NULL THEN
2165 px_line_record.tracing_flag(i) := 'T';
2166 ELSE
2167 px_line_record.tracing_flag(i) := 'F';
2168 END IF;
2169 END IF;
2170 IF OZF_DEBUG_LOW_ON THEN
2171 ozf_utility_pvt.debug_message('tracing_flag' || px_line_record.tracing_flag(i));
2172 END IF;
2173 END LOOP;
2174
2175 END IF;
2176
2177 IF OZF_DEBUG_HIGH_ON THEN
2178 ozf_utility_pvt.debug_message('Private API: ' || l_api_name || ': End');
2179 END IF;
2180 EXCEPTION
2181 WHEN FND_API.G_EXC_ERROR THEN
2182 x_return_status := FND_API.G_RET_STS_ERROR;
2183 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2184 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2185 WHEN OTHERS THEN
2186 IF OZF_UNEXP_ERROR THEN
2187 FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
2188 END IF;
2189 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2190 END Line_Defaulting;
2191
2192
2193 PROCEDURE Line_Validations(
2194 p_line_count IN NUMBER,
2195 px_batch_record IN OUT NOCOPY ozf_resale_batches_all%ROWTYPE,
2196 px_line_record IN OUT NOCOPY resale_line_int_rec_type,
2197 x_return_status OUT NOCOPY VARCHAR2
2198 )
2199 IS
2200 l_api_name CONSTANT VARCHAR2(30) := 'Line_Validations';
2201 l_api_version_number CONSTANT NUMBER := 1.0;
2202
2203 CURSOR get_order_type_id(pc_date_ordered IN DATE
2204 ,pc_order_type IN VARCHAR2) IS
2205 SELECT transaction_type_id
2206 FROM oe_transaction_types_vl
2207 WHERE transaction_type_code = 'ORDER'
2208 AND TO_DATE(TO_CHAR(pc_date_ordered, 'MM/DD/YYYY'), 'MM/DD/YYYY')
2209 BETWEEN start_date_active AND NVL(end_date_active, SYSDATE)
2210 AND name = pc_order_type;
2211
2212 CURSOR chk_order_type (pc_order_type IN VARCHAR2
2213 ,pc_order_type_id IN NUMBER) IS
2214 SELECT 'X'
2215 FROM oe_transaction_types_vl
2216 WHERE transaction_type_id = pc_order_type_id
2217 UNION ALL
2218 SELECT 'X'
2219 FROM oe_transaction_types_vl
2220 WHERE name = pc_order_type ;
2221
2222 CURSOR get_functional_currency IS
2223 SELECT gs.currency_code
2224 FROM gl_sets_of_books gs,
2225 ozf_sys_parameters osp
2226 WHERE gs.set_of_books_id = osp.set_of_books_id
2227 AND osp.org_id = MO_GLOBAL.get_current_org_id(); -- BUG 5058027
2228
2229 CURSOR get_item_number ( pc_item_id IN NUMBER, pc_org_id IN NUMBER) IS
2230 SELECT concatenated_segments
2231 FROM mtl_system_items_vl
2232 WHERE inventory_item_id = pc_item_id
2233 AND organization_id = pc_org_id;
2234
2235 CURSOR price_list_org(cv_price_list_id IN NUMBER) IS
2236 SELECT b.orig_org_id
2237 FROM qp_list_headers_b b
2238 , qp_list_headers_tl tl
2239 WHERE b.list_header_id = tl.list_header_id
2240 ANd b.list_header_id = cv_price_list_id;
2241
2242 CURSOR spr_org(cv_reqeust_header_id IN NUMBER) IS
2243 SELECT org_id
2244 FROM ozf_request_headers_all_b
2245 WHERE request_header_id = cv_reqeust_header_id;
2246
2247 l_exchange_rate_type VARCHAR2(100);
2248 l_exchange_rate NUMBER;
2249 l_functional_currency VARCHAR2(15);
2250 l_dispute_code VARCHAR2(100);
2251 x VARCHAR2(1);
2252 l_column_name VARCHAR2(300);
2253 l_column_value VARCHAR2(3200);
2254 l_msg_count NUMBER;
2255 l_msg_data VARCHAR2(32000);
2256 l_org_id NUMBER;
2257 l_new_converted_amount NUMBER;
2258 l_agreement_org_id NUMBER;
2259
2260 BEGIN
2261 IF OZF_DEBUG_HIGH_ON THEN
2262 ozf_utility_pvt.debug_message('Private API: ' || l_api_name || ': start');
2263 END IF;
2264
2265 x_return_status := FND_API.G_RET_STS_SUCCESS;
2266
2267 -- Retrieval of all the party related details
2268 -----------------------------------------------------------------------
2269 Line_Party_Validations(
2270 p_line_count => p_line_count,
2271 px_line_record => px_line_record,
2272 x_return_status => x_return_status
2273 );
2274 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
2275 RAISE FND_API.G_EXC_ERROR;
2276 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
2277 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2278 END IF;
2279
2280 FOR i IN 1 .. p_line_count LOOP
2281 IF OZF_DEBUG_LOW_ON THEN
2282 ozf_utility_pvt.debug_message('Direct Customer Flag ('||i||')'|| px_line_record.direct_customer_flag(i));
2283 END IF;
2284
2285 IF px_line_record.sold_from_cust_account_id(i) IS NULL THEN
2286 px_line_record.sold_from_cust_account_id(i) := px_batch_record.partner_cust_account_id;
2287
2288 IF px_line_record.sold_from_cust_account_id(i) IS NULL THEN
2289 IF px_line_record.status_code(i) <> 'DISPUTED' THEN
2290 px_line_record.status_code(i) := 'DISPUTED';
2291 px_line_record.dispute_code(i) := 'OZF_RESALE_SOLD_FROM_MISS';
2292 END IF;
2293
2294 Insert_Resale_Log(
2295 p_id_value => px_line_record.resale_line_int_id(i),
2296 p_id_type => 'IFACE',
2297 p_error_code => 'OZF_RESALE_SOLD_FROM_MISS',
2298 p_column_name => 'SOLD_FROM_CUST_ACCOUNT_ID',
2299 p_column_value => NULL,
2300 x_return_status => x_return_status
2301 );
2302 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
2303 RAISE FND_API.G_EXC_ERROR;
2304 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
2305 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2306 END IF;
2307 END IF;
2308 END IF;
2309
2310 -- Sold From Site ID
2311 IF px_line_record.sold_from_site_id(i) IS NULL THEN
2312 px_line_record.sold_from_site_id(i) := px_batch_record.partner_site_id;
2313 END IF;
2314
2318
2315 -- Ship From Customer Account
2316 IF px_line_record.ship_from_cust_account_id(i) IS NULL THEN
2317 px_line_record.ship_from_cust_account_id(i) := px_batch_record.partner_cust_account_id;
2319 IF px_line_record.ship_from_cust_account_id(i) IS NULL THEN
2320 IF px_line_record.status_code(i) <> 'DISPUTED' THEN
2321 px_line_record.status_code(i) := 'DISPUTED';
2322 px_line_record.dispute_code(i) := 'OZF_RESALE_SHIP_FROM_MISS';
2323 END IF;
2324
2325 Insert_Resale_Log(
2326 p_id_value => px_line_record.resale_line_int_id(i),
2327 p_id_type => 'IFACE',
2328 p_error_code => 'OZF_RESALE_SHIP_FROM_MISS',
2329 p_column_name => 'SHIP_FROM_CUST_ACCOUNT_ID',
2330 p_column_value => NULL,
2331 x_return_status => x_return_status
2332 );
2333 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
2334 RAISE FND_API.G_EXC_ERROR;
2335 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
2336 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2337 END IF;
2338 END IF;
2339 END IF;
2340
2341 -- Ship From Site
2342 IF px_line_record.ship_from_site_id(i) IS NULL THEN
2343 px_line_record.ship_from_site_id(i) := px_batch_record.partner_site_id;
2344 END IF;
2345
2346 --
2347 -- Direct Customer Flag Validations
2348 -- bill_to_ bill_to_ bill_to_
2349 -- cust_account_id party_id party_name direct_customer_flag
2350 -- --------------- -------- ---------- --------------------
2351 -- X X X T
2352 -- X X F
2353 -- X F
2354 -- F
2355 -----------------------------------------------------------------------
2356 IF px_line_record.direct_customer_flag(i) IS NULL THEN
2357 -- [BEGIN OF BUG 4391335 FIXING]
2358 IF px_line_record.bill_to_cust_account_id.exists(i) AND
2359 px_line_record.bill_to_cust_account_id(i) IS NOT NULL AND
2360 px_line_record.bill_to_party_name.exists(i) AND
2361 px_line_record.bill_to_party_name(i) IS NOT NULL THEN
2362 px_line_record.direct_customer_flag(i) := 'T';
2363 ELSE
2364 px_line_record.direct_customer_flag(i) := 'F';
2365 END IF;
2366 -- [END OF BUG 4391335 FIXING]
2367 END IF;
2368
2369 --
2370 -- Bill to Customer Validations
2371 -----------------------------------------------------------------------
2372 IF px_line_record.direct_customer_flag(i) = 'T' THEN
2373 IF px_line_record.bill_to_cust_account_id.exists(i) AND
2374 px_line_record.bill_to_cust_account_id(i) IS NULL THEN
2375 IF px_line_record.status_code(i) <> 'DISPUTED' THEN
2376 px_line_record.status_code(i) := 'DISPUTED';
2377 px_line_record.dispute_code(i) := 'OZF_BILL_TO_ACCT_NULL';
2378 END IF;
2379
2380 Insert_Resale_Log(
2381 p_id_value => px_line_record.resale_line_int_id(i),
2382 p_id_type => 'IFACE',
2383 p_error_code => 'OZF_BILL_TO_ACCT_NULL',
2384 p_column_name => 'BILL_TO_CUST_ACCOUNT_ID',
2385 p_column_value => NULL,
2386 x_return_status => x_return_status
2387 );
2388 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
2389 RAISE FND_API.G_EXC_ERROR;
2390 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
2391 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2392 END IF;
2393 END IF; -- px_line_record.bill_to_cust_account_id(i)
2394 ELSIF px_line_record.direct_customer_flag(i) = 'F' THEN
2395 IF px_batch_record.batch_type = 'CHARGEBACK' OR
2396 px_batch_record.batch_type = 'TRACING' OR
2397 px_batch_record.batch_type = 'TP_ACCRUAL' THEN
2398 IF px_line_record.bill_to_party_name.EXISTS(i) AND
2399 px_line_record.bill_to_party_name(i) IS NULL THEN
2400 IF px_line_record.status_code(i) <> 'DISPUTED' THEN
2401 px_line_record.status_code(i) := 'DISPUTED';
2402 px_line_record.dispute_code(i) := 'OZF_BILL_TO_PARTY_NAME_NULL';
2403 END IF;
2404
2405 Insert_Resale_Log (
2406 p_id_value => px_line_record.resale_line_int_id(i),
2407 p_id_type => 'IFACE',
2408 p_error_code => 'OZF_BILL_TO_PARTY_NAME_NULL',
2409 p_column_name => 'BILL_TO_PARTY_NAME',
2410 p_column_value => NULL,
2411 x_return_status => x_return_status
2412 );
2413 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
2414 RAISE FND_API.G_EXC_ERROR;
2415 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
2416 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2417 END IF;
2418 END IF; -- px_line_record.bill_to_cust_account_id(i)
2419 END IF;
2420 END IF;
2421
2422 --
2423 -- Product Transfer Movement Type Validations
2424 -----------------------------------------------------------------------
2425 IF px_line_record.product_transfer_movement_type(i) IS NULL THEN
2426 IF px_line_record.status_code(i) <> 'DISPUTED' THEN
2427 px_line_record.status_code(i) := 'DISPUTED';
2428 px_line_record.dispute_code(i) := 'OZF_MOVEMENT_TYPE_NULL';
2429 END IF;
2430
2431 Insert_Resale_Log (
2432 p_id_value => px_line_record.resale_line_int_id(i),
2433 p_id_type => 'IFACE',
2434 p_error_code => 'OZF_MOVEMENT_TYPE_NULL',
2435 p_column_name => 'PRODUCT_TRANSFER_MOVEMENT_TYPE',
2436 p_column_value => NULL,
2437 x_return_status => x_return_status
2438 );
2439 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
2440 RAISE FND_API.G_EXC_ERROR;
2441 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
2442 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2443 END IF;
2444 END IF;
2445
2446 --
2447 -- Order Number Validations
2448 -----------------------------------------------------------------------
2449 IF px_line_record.order_number(i) IS NULL THEN
2450 IF px_line_record.status_code(i) <> 'DISPUTED' THEN
2451 px_line_record.status_code(i) := 'DISPUTED';
2452 px_line_record.dispute_code(i) := 'OZF_RESALE_ORD_NUM_MISS';
2453 END IF;
2454
2455 Insert_Resale_Log (
2456 p_id_value => px_line_record.resale_line_int_id(i),
2457 p_id_type => 'IFACE',
2458 p_error_code => 'OZF_RESALE_ORD_NUM_MISS',
2459 p_column_name => 'ORDER_NUMBER',
2460 p_column_value => NULL,
2461 x_return_status => x_return_status
2462 );
2463 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
2464 RAISE FND_API.G_EXC_ERROR;
2465 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
2466 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2467 END IF;
2468 END IF;
2469
2470 --
2471 -- Resale_Transfer_Type Validations
2472 -- 'BN': Return
2473 -- 'SD': Ship Debit Sale
2474 -- 'SS': Stock Sale
2475 -- 'IB': Inter Branch
2476 -----------------------------------------------------------------------
2477 IF ( px_line_record.resale_transfer_type(i) NOT IN ( 'BN', 'SD', 'SS', 'IB') )
2478 -- BUG 4558568 (+)
2479 OR
2480 ( px_line_record.resale_transfer_type(i) = 'BN' AND
2481 SIGN(px_line_record.quantity(i)) = 1 )
2482 OR
2483 ( px_line_record.resale_transfer_type(i) = 'SD' AND
2484 SIGN(px_line_record.quantity(i)) = -1 ) THEN
2485 -- BUG 4558568 (-)
2486 IF px_line_record.status_code(i) <> 'DISPUTED' THEN
2487 px_line_record.status_code(i) := 'DISPUTED';
2488 px_line_record.dispute_code(i) := 'OZF_RESALE_WRNG_TRANSFER_TYPE';
2489 END IF;
2490
2491 Insert_Resale_Log(
2492 p_id_value => px_line_record.resale_line_int_id(i),
2493 p_id_type => 'IFACE',
2494 p_error_code => 'OZF_RESALE_WRNG_TRANSFER_TYPE',
2495 p_column_name => 'RESALE_TRANSFER_TYPE',
2496 p_column_value => px_line_record.resale_transfer_type(i),
2497 x_return_status => x_return_status
2498 );
2499 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
2500 RAISE FND_API.G_EXC_ERROR;
2501 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
2502 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2503 END IF;
2504 END IF;
2505
2506 --
2507 -- Order Category Validations
2508 -----------------------------------------------------------------------
2509 IF px_line_record.order_category(i) NOT IN ('ORDER', 'RETURN' ) THEN
2510 IF px_line_record.status_code(i) <> 'DISPUTED' THEN
2511 px_line_record.status_code(i) := 'DISPUTED';
2512 px_line_record.dispute_code(i) := 'OZF_RESALE_WRNG_ORD_CGRY';
2513 END IF;
2514
2515 Insert_Resale_Log (
2516 p_id_value => px_line_record.resale_line_int_id(i),
2517 p_id_type => 'IFACE',
2518 p_error_code => 'OZF_RESALE_WRNG_ORD_CGRY',
2519 p_column_name => 'ORDER_CATEGORY',
2520 p_column_value => px_line_record.order_category(i),
2521 x_return_status => x_return_status
2522 );
2523 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
2524 RAISE FND_API.G_EXC_ERROR;
2525 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
2526 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2527 END IF;
2528 END IF;
2529
2530 --
2531 -- Date Ordered Validations
2532 -----------------------------------------------------------------------
2533 IF px_line_record.date_ordered(i) IS NULL THEN
2534 IF px_line_record.status_code(i) <> 'DISPUTED' THEN
2535 px_line_record.status_code(i) := 'DISPUTED';
2536 px_line_record.dispute_code(i) := 'OZF_RESALE_ORD_DATE_MISS';
2537 END IF;
2538
2539 l_dispute_code := 'OZF_RESALE_ORD_DATE_MISS';
2540 l_column_name := 'DATE_ORDERED';
2541 l_column_value := NULL;
2542 ELSIF px_line_record.date_ordered(i) < px_batch_record.report_start_date THEN
2543 IF px_line_record.status_code(i) <> 'DISPUTED' THEN
2544 px_line_record.status_code(i) := 'DISPUTED';
2545 px_line_record.dispute_code(i) := 'OZF_ORD_DATE_LT_START';
2546 END IF;
2547 l_dispute_code := 'OZF_ORD_DATE_LT_START';
2548 l_column_name := 'DATE_ORDERED';
2549 l_column_value := px_line_record.date_ordered(i);
2550 ELSIF px_line_record.date_ordered(i) > px_batch_record.report_end_date THEN
2551 IF px_line_record.status_code(i) <> 'DISPUTED' THEN
2552 px_line_record.status_code(i) := 'DISPUTED';
2553 px_line_record.dispute_code(i) := 'OZF_ORD_DATE_GT_END';
2554 END IF;
2555 l_dispute_code := 'OZF_ORD_DATE_GT_END';
2556 l_column_name := 'DATE_ORDERED';
2557 l_column_value := px_line_record.date_ordered(i);
2558 --
2559 -- Order Type Valication
2560 -----------------------------------------------------------------------
2561 ELSE
2562 IF px_line_record.order_type_id(i) IS NULL THEN
2563 IF px_line_record.order_type(i) IS NOT NULL THEN
2564 OPEN get_order_type_id(px_line_record.date_ordered(i)
2565 ,px_line_record.order_type(i));
2566 FETCH get_order_type_id INTO px_line_record.order_type_id(i);
2567 CLOSE get_order_type_id;
2568 END IF; -- px_line_record.order_type(i)
2569 ELSE
2570 OPEN chk_order_type (px_line_record.order_type(i)
2571 ,px_line_record.order_type_id(i));
2572 FETCH chk_order_type INTO x;
2573 CLOSE chk_order_type;
2574
2575 IF x IS NULL THEN
2576 l_dispute_code := 'OZF_WRNG_ORDER_TYPE';
2577 IF px_line_record.order_type(i) IS NOT NULL THEN
2578 l_column_name := 'ORDER_TYPE';
2579 l_column_value := px_line_record.order_type(i);
2580 ELSE
2581 l_column_name := 'ORDER_TYPE_ID';
2582 l_column_value := px_line_record.order_type_id(i);
2583 END IF;
2584 END IF;
2585 END IF; -- px_line_record.order_type_id(i)
2586 END IF; -- px_line_record.date_ordered
2587
2588 IF l_dispute_code IS NOT NULL THEN
2589 Insert_Resale_Log(
2590 p_id_value => px_line_record.resale_line_int_id(i),
2591 p_id_type => 'IFACE',
2592 p_error_code => l_dispute_code,
2593 p_column_name => l_column_name,
2594 p_column_value => l_column_value,
2595 x_return_status => x_return_status
2596 );
2597 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
2598 RAISE FND_API.G_EXC_ERROR;
2599 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
2600 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2601 END IF;
2602 END IF;
2603
2604 --
2605 -- Derive Purchase Price from OM sales transactions
2606 -----------------------------------------------------------------------
2607 IF px_line_record.purchase_price(i) IS NULL THEN
2608 OZF_SALES_TRANSACTIONS_PVT.Get_Purchase_Price(
2609 p_api_version => 1.0
2610 ,p_init_msg_list => FND_API.G_FALSE
2611 ,p_validation_level => FND_API.G_VALID_LEVEL_FULL
2612 ,p_order_date => px_line_record.date_ordered(i)
2613 ,p_sold_from_cust_account_id => px_line_record.sold_from_cust_account_id(i)
2614 ,p_sold_from_site_id => px_line_record.sold_from_site_id(i)
2615 ,p_inventory_item_id => px_line_record.inventory_item_id(i)
2616 ,p_uom_code => px_line_record.uom_code(i)
2617 ,p_quantity => px_line_record.quantity(i)
2618 ,p_currency_code => px_line_record.currency_code(i)
2619 ,p_x_purchase_uom_code => px_line_record.purchase_uom_code(i)
2620 ,x_purchase_price => px_line_record.purchase_price(i)
2621 ,x_return_status => x_return_status
2622 ,x_msg_count => l_msg_count
2623 ,x_msg_data => l_msg_data
2624 );
2625 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
2626 RAISE FND_API.G_EXC_ERROR;
2627 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
2628 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2629 END IF;
2630
2631 IF px_line_record.purchase_price(i) IS NULL THEN
2632 px_line_record.purchase_price(i) := px_line_record.orig_system_purchase_price(i);
2633 END IF;
2634
2635 OPEN get_functional_currency;
2636 FETCH get_functional_currency INTO l_functional_currency;
2637 CLOSE get_functional_currency;
2638
2639 IF px_line_record.purchase_price(i) IS NOT NULL THEN
2640 IF l_functional_currency <> px_line_record.currency_code(i) THEN
2641 IF px_line_record.exchange_rate(i) IS NULL THEN
2642 IF px_line_record.exchange_rate_type(i) IS NULL THEN
2643 OPEN OZF_RESALE_COMMON_PVT.g_exchange_rate_type_csr;
2644 FETCH OZF_RESALE_COMMON_PVT.g_exchange_rate_type_csr INTO px_line_record.exchange_rate_type(i);
2645 CLOSE OZF_RESALE_COMMON_PVT.g_exchange_rate_type_csr;
2649 ,p_to_currency => l_functional_currency
2646 END IF;
2647 OZF_UTILITY_PVT.Convert_Currency(
2648 p_from_currency => px_line_record.currency_code(i)
2650 ,p_conv_type => px_line_record.exchange_rate_type(i)
2651 ,p_conv_rate => px_line_record.exchange_rate(i)
2652 ,p_conv_date => px_line_record.exchange_rate_date(i)
2653 ,p_from_amount => px_line_record.purchase_price(i)
2654 ,x_return_status => x_return_status
2655 ,x_to_amount => l_new_converted_amount
2656 ,x_rate => l_exchange_rate
2657 );
2658 IF x_return_status = FND_API.g_ret_sts_error THEN
2659 RAISE FND_API.g_exc_error;
2660 ELSIF x_return_status = FND_API.g_ret_sts_unexp_error THEN
2661 RAISE FND_API.g_exc_unexpected_error;
2662 END IF;
2663 px_line_record.acctd_purchase_price(i) := l_new_converted_amount;
2664 ELSE
2665 px_line_record.acctd_purchase_price(i)
2666 := OZF_UTILITY_PVT.CurrRound(px_line_record.purchase_price(i)*px_line_record.exchange_rate(i), l_functional_currency);
2667 END IF; -- px_line_record.exchange_rate(i) IS NULL
2668 ELSE
2669 px_line_record.acctd_purchase_price(i) := px_line_record.purchase_price(i);
2670 END IF; -- l_functional_currency <> px_line_record.currency_code(i)
2671 END IF;
2672 END IF;
2673
2674 --
2675 -- Derive purchase_uom / selling_uom / UOM
2676 -----------------------------------------------------------------------
2677 IF px_line_record.purchase_uom_code(i) IS NULL THEN
2678 IF px_line_record.uom_code(i) IS NOT NULL THEN
2679 px_line_record.purchase_uom_code(i) := px_line_record.uom_code(i);
2680 END IF;
2681 END IF;
2682
2683 --
2684 -- Derive claim amount
2685 -----------------------------------------------------------------------
2686 IF px_line_record.claimed_amount(i) IS NULL THEN
2687 IF px_line_record.total_claimed_amount(i) IS NOT NULL THEN
2688 -- Bug fixing: return orders for chargeback 4700019(+)
2689 --px_line_record.claimed_amount(i) := px_line_record.total_claimed_amount(i)/px_line_record.quantity(i);
2690 px_line_record.claimed_amount(i) := px_line_record.total_claimed_amount(i)/ABS(px_line_record.quantity(i));
2691
2692 -- Bug fixing: return orders for chargeback 4700019(-)
2693 ELSIF px_line_record.selling_price(i) IS NOT NULL AND
2694 px_line_record.purchase_price(i) IS NOT NULL THEN
2695 px_line_record.claimed_amount(i) := px_line_record.purchase_price(i)
2696 - px_line_record.selling_price(i);
2697 IF SIGN(px_line_record.quantity(i)) = -1 THEN
2698 px_line_record.claimed_amount(i) := px_line_record.claimed_amount(i)*-1;
2699 END IF;
2700 END IF;
2701 END IF; -- px_line_record.claimed_amount(i)
2702
2703 IF px_line_record.claimed_amount(i) IS NOT NULL THEN
2704 -- Bug fixing: return orders for chargeback 4700019(+)
2705 --px_line_record.total_claimed_amount(i) := px_line_record.claimed_amount(i)*px_line_record.quantity(i);
2706 --px_line_record.total_claimed_amount(i) := px_line_record.claimed_amount(i)*ABS(px_line_record.quantity(i));
2707 -- Bug fixing: return orders for chargeback 4700019(-)
2708 -- bug 5969118 Ship and Debit return order generates positive claim amount
2709 IF px_line_record.resale_transfer_type(i) = 'BN' THEN
2710 px_line_record.total_claimed_amount(i) := ABS(px_line_record.claimed_amount(i) * px_line_record.quantity(i)) * -1;
2711 ELSE
2712 px_line_record.total_claimed_amount(i) := px_line_record.claimed_amount(i)*ABS(px_line_record.quantity(i));
2713 END IF;
2714 -- bug 5969118 end
2715 END IF;
2716
2717 --
2718 -- Derive Item Number
2719 -----------------------------------------------------------------------
2720 IF px_line_record.inventory_item_id(i) IS NOT NULL AND
2721 px_line_record.item_number(i) IS NULL THEN
2722 -- Bug 4520881 (+)
2723 l_org_id := G_ITEM_ORG_ID; --FND_PROFILE.value('AMS_ITEM_ORGANIZATION_ID');
2724 -- SELECT NVL(SUBSTRB(USERENV('CLIENT_INFO'),1,10),-99)
2725 -- INTO l_org_id FROM DUAL;
2726 -- Bug 4520881 (-)
2727 OPEN get_item_number( px_line_record.inventory_item_id(i)
2728 , l_org_id);
2729 FETCH get_item_number INTO px_line_record.item_number(i);
2730 CLOSE get_item_number;
2731 END IF;
2732
2733 -- BUG 4938403 (+)
2734 -- Item/Order Date/UOM/Quantity Validation for Inventory Tracking
2735 -----------------------------------------------------------------------
2736 IF g_inventory_tracking_flag = 'T' THEN
2737 l_dispute_code := NULL;
2738 IF px_line_record.inventory_item_id(i) IS NULL THEN
2739 l_dispute_code := 'OZF_IDSM_INV_ITEM_REQ';
2740 Insert_Resale_Log(
2741 p_id_value => px_line_record.resale_line_int_id(i),
2742 p_id_type => 'IFACE',
2743 p_error_code => 'OZF_IDSM_INV_ITEM_REQ',
2744 p_column_name => 'INVENTORY_ITEM_ID',
2745 p_column_value => NULL,
2749 RAISE FND_API.G_EXC_ERROR;
2746 x_return_status => x_return_status
2747 );
2748 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
2750 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
2751 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2752 END IF;
2753 END IF;
2754
2755 IF px_line_record.date_ordered(i) IS NULL THEN
2756 l_dispute_code := 'OZF_IDSM_INV_ORDER_DATE_REQ';
2757 Insert_Resale_Log(
2758 p_id_value => px_line_record.resale_line_int_id(i),
2759 p_id_type => 'IFACE',
2760 p_error_code => 'OZF_IDSM_INV_ORDER_DATE_REQ',
2761 p_column_name => 'DATE_ORDERED',
2762 p_column_value => NULL,
2763 x_return_status => x_return_status
2764 );
2765 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
2766 RAISE FND_API.G_EXC_ERROR;
2767 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
2768 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2769 END IF;
2770 END IF;
2771
2772 IF px_line_record.uom_code(i) IS NULL THEN
2773 l_dispute_code := 'OZF_IDSM_INV_UOM_REQ';
2774 Insert_Resale_Log(
2775 p_id_value => px_line_record.resale_line_int_id(i),
2776 p_id_type => 'IFACE',
2777 p_error_code => 'OZF_IDSM_INV_UOM_REQ',
2778 p_column_name => 'UOM_CODE',
2779 p_column_value => NULL,
2780 x_return_status => x_return_status
2781 );
2782 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
2783 RAISE FND_API.G_EXC_ERROR;
2784 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
2785 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2786 END IF;
2787 END IF;
2788
2789 IF px_line_record.quantity(i) IS NULL THEN
2790 l_dispute_code := 'OZF_IDSM_INV_QTY_REQ';
2791 Insert_Resale_Log(
2792 p_id_value => px_line_record.resale_line_int_id(i),
2793 p_id_type => 'IFACE',
2794 p_error_code => 'OZF_IDSM_INV_QTY_REQ',
2795 p_column_name => 'QUANTITY',
2796 p_column_value => NULL,
2797 x_return_status => x_return_status
2798 );
2799 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
2800 RAISE FND_API.G_EXC_ERROR;
2801 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
2802 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2803 END IF;
2804 END IF;
2805
2806 IF l_dispute_code IS NOT NULL THEN
2807 IF px_line_record.status_code(i) <> 'DISPUTED' THEN
2808 px_line_record.status_code(i) := 'DISPUTED';
2809 px_line_record.dispute_code(i) := 'OZF_SALES_TRANS_MISS';
2810 END IF;
2811 END IF;
2812 END IF;
2813 -- BUG 4938403 (-)
2814
2815 -- BUG 5153273 (+)
2816 -- Agreement Operating Unit Validation
2817 -----------------------------------------------------------------------
2818 IF px_line_record.agreement_id(i) IS NOT NULL AND
2819 px_line_record.agreement_type(i) IS NOT NULL THEN
2820 l_agreement_org_id := NULL;
2821
2822 IF px_line_record.agreement_type(i) = 'PL' THEN
2823 OPEN price_list_org(px_line_record.agreement_id(i));
2824 FETCH price_list_org INTO l_agreement_org_id;
2825 CLOSE price_list_org;
2826 ELSIF px_line_record.agreement_type(i) = 'SPO' THEN
2827 OPEN spr_org(px_line_record.agreement_id(i));
2828 FETCH spr_org INTO l_agreement_org_id;
2829 CLOSE spr_org;
2830 END IF;
2831
2832 IF l_agreement_org_id IS NOT NULL AND
2833 l_agreement_org_id <> px_line_record.org_id(i) THEN
2834 l_dispute_code := 'OZF_AGRM_MISMATCH_OU';
2835 Insert_Resale_Log(
2836 p_id_value => px_line_record.resale_line_int_id(i),
2837 p_id_type => 'IFACE',
2838 p_error_code => 'OZF_IDSM_AGRM_MISMATCH_OU',
2839 p_column_name => 'AGREEMENT_NAME',
2840 p_column_value => NULL,
2841 x_return_status => x_return_status
2842 );
2843 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
2844 RAISE FND_API.G_EXC_ERROR;
2845 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
2846 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2847 END IF;
2848 END IF;
2849 END IF;
2850 -- BUG 5153273 (-)
2851
2852 IF px_line_record.status_code(i) = 'DISPUTED' THEN
2853 px_line_record.response_code(i) := 'N';
2854 ELSIF px_line_record.status_code(i) = 'OPEN' THEN
2855 px_line_record.response_code(i) := 'Y';
2856 END IF;
2857
2858 END LOOP;
2859
2860 IF OZF_DEBUG_HIGH_ON THEN
2861 ozf_utility_pvt.debug_message('Private API: ' || l_api_name || ': end');
2862 END IF;
2863 EXCEPTION
2864 WHEN FND_API.G_EXC_ERROR THEN
2865 x_return_status := FND_API.G_RET_STS_ERROR;
2866 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2870 IF OZF_UNEXP_ERROR THEN
2867 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2868 WHEN OTHERS THEN
2869 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2871 FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
2872 END IF;
2873 END Line_Validations;
2874
2875
2876 PROCEDURE End_Cust_Party_Mapping
2877 (
2878 p_party_id IN NUMBER,
2879 p_cust_account_id IN NUMBER,
2880 p_party_name_tbl IN OUT NOCOPY VARCHAR2_TABLE,
2881 p_location_tbl IN OUT NOCOPY VARCHAR2_TABLE,
2882 px_site_use_code_tbl IN OUT NOCOPY VARCHAR2_TABLE,
2883 px_site_use_id_tbl IN OUT NOCOPY NUMBER_TABLE,
2884 px_party_id_tbl IN OUT NOCOPY NUMBER_TABLE,
2885 px_party_site_id_tbl IN OUT NOCOPY NUMBER_TABLE,
2886 x_return_status OUT NOCOPY VARCHAR2
2887 )
2888 IS
2889 l_api_name CONSTANT VARCHAR2(30) := 'End_Cust_Party_Mapping';
2890 l_api_version_number CONSTANT NUMBER := 1.0;
2891
2892 l_mapping_flag VARCHAR2(1);
2893 l_site_mapping_flag VARCHAR2(1);
2894
2895 l_msg_count NUMBER;
2896 l_msg_data VARCHAR2(2000);
2897
2898 l_party_tbl VARCHAR2_TABLE;
2899 l_party_site_tbl VARCHAR2_TABLE;
2900
2901 l_party_id NUMBER;
2902 l_cust_account_id NUMBER;
2903
2904 CURSOR get_account_id (pc_party_Id NUMBER)
2905 IS
2906 SELECT cust.cust_account_id
2907 FROM hz_cust_accounts cust
2908 WHERE cust.party_id = pc_party_Id;
2909
2910 CURSOR get_site_use_id ( pc_cust_account_id NUMBER
2911 , pc_site_use VARCHAR2 )
2912 IS
2913 SELECT hcsu.site_use_id
2914 FROM hz_cust_acct_sites hcs --hz_cust_acct_sites_all hcs
2915 , hz_cust_site_uses hcsu --, hz_cust_site_uses_all hcsu
2916 WHERE hcsu.cust_acct_site_id = hcs.cust_acct_site_id
2917 AND hcs.cust_account_id = pc_cust_account_id
2918 AND hcsu.site_use_code = pc_site_use
2919 AND hcsu.primary_flag= 'Y'
2920 AND hcsu.status = 'A';
2921
2922 CURSOR get_party_acc_id (cv_party_site_id IN NUMBER) IS
2923 SELECT hp.party_id , hc.cust_account_id
2924 FROM hz_party_sites hps
2925 , hz_parties hp
2926 , hz_cust_accounts hc
2927 WHERE hps.party_id = hp.party_id
2928 AND hp.party_id = hc.party_id (+)
2929 AND hps.party_site_id = cv_party_site_id;
2930
2931
2932 BEGIN
2933 IF OZF_DEBUG_HIGH_ON THEN
2934 ozf_utility_pvt.debug_message('Private API: ' || l_api_name || ': start');
2935 END IF;
2936 x_return_status := FND_API.G_RET_STS_SUCCESS;
2937
2938 -- Party Site Code Conversions
2939 IF px_site_use_id_tbl.COUNT > 0 THEN
2940
2941 FOR i IN 1 .. px_site_use_id_tbl.COUNT
2942 LOOP
2943 IF px_site_use_id_tbl(i) IS NOT NULL THEN
2944 l_site_mapping_flag := 'N';
2945 --exit;
2946 ELSE
2947 IF px_party_site_id_tbl(i) IS NOT NULL THEN
2948 l_site_mapping_flag := 'N';
2949 --exit;
2950 ELSIF p_location_tbl(i) IS NOT NULL THEN
2951 l_site_mapping_flag := 'Y';
2952 exit;
2953 END IF;
2954 END IF;
2955 END LOOP;
2956 END IF;
2957
2958 IF OZF_DEBUG_LOW_ON THEN
2959 ozf_utility_pvt.debug_message('Mapping Flag ' || l_mapping_flag);
2960 END IF;
2961
2962 IF l_site_mapping_flag = 'Y' AND p_location_tbl.COUNT > 0 THEN
2963
2964 code_conversion
2965 (
2966 p_party_id => p_party_id,
2967 p_cust_account_id => p_cust_account_id ,
2968 p_mapping_type => 'OZF_PARTY_SITE_CODES',
2969 p_external_code_tbl => p_location_tbl,
2970 x_internal_code_tbl => l_party_site_tbl,
2971 x_return_status => x_return_status,
2972 x_msg_count => l_msg_count ,
2973 x_msg_data => l_msg_data
2974 );
2975 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
2976 RAISE FND_API.G_EXC_ERROR;
2977 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
2978 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2979 END IF;
2980 IF l_party_site_tbl.COUNT > 0 THEN
2981 FOR i IN 1 .. l_party_site_tbl.COUNT
2982 LOOP
2983 IF l_party_site_tbl.exists(i) AND l_party_site_tbl(i) IS NOT NULL THEN
2984 px_party_site_id_tbl(i) := to_number(l_party_site_tbl(i));
2985
2986 OPEN get_party_acc_id(px_party_site_id_tbl(i));
2987 FETCH get_party_acc_id INTO l_party_id, l_cust_account_id;
2988 CLOSE get_party_acc_id;
2989
2990 IF px_party_id_tbl(i) IS NULL THEN
2991 px_party_id_tbl(i) := l_party_id;
2992 END IF;
2993
2994 IF l_cust_account_id IS NOT NULL THEN
2995 OPEN get_site_use_id ( l_cust_account_id, 'BILL_TO');
2996 FETCH get_site_use_id INTO px_site_use_id_tbl(i);
2997 CLOSE get_site_use_id;
2998 END IF;
2999 END IF;
3000 END LOOP;
3001 END IF;
3005 IF px_party_id_tbl.COUNT > 0 THEN
3002 END IF; -- l_site_mapping_flag = 'Y'
3003
3004 -- Party Code Conversions
3006
3007 FOR i IN 1 .. px_party_id_tbl.COUNT
3008 LOOP
3009 IF px_party_site_id_tbl(i) IS NOT NULL THEN
3010 l_mapping_flag := 'N';
3011 --exit;
3012 ELSE
3013 IF px_party_id_tbl(i) IS NOT NULL THEN
3014 l_mapping_flag := 'N';
3015 --exit;
3016 ELSIF p_party_name_tbl(i) IS NOT NULL THEN
3017 l_mapping_flag := 'Y';
3018 exit;
3019 END IF;
3020 END IF;
3021 END LOOP;
3022 END IF;
3023
3024 IF OZF_DEBUG_LOW_ON THEN
3025 ozf_utility_pvt.debug_message('Mapping Flag ' || l_mapping_flag);
3026 END IF;
3027
3028 IF l_mapping_flag = 'Y' AND p_party_name_tbl.COUNT > 0 THEN
3029
3030 code_conversion
3031 (
3032 p_party_id => p_party_id,
3033 p_cust_account_id => p_cust_account_id ,
3034 p_mapping_type => 'OZF_PARTY_CODES',
3035 p_external_code_tbl => p_party_name_tbl,
3036 x_internal_code_tbl => l_party_tbl,
3037 x_return_status => x_return_status,
3038 x_msg_count => l_msg_count ,
3039 x_msg_data => l_msg_data
3040 );
3041 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
3042 RAISE FND_API.G_EXC_ERROR;
3043 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
3044 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3045 END IF;
3046 IF l_party_tbl.COUNT > 0 THEN
3047 FOR i IN 1 .. l_party_tbl.COUNT
3048 LOOP
3049 IF l_party_tbl.EXISTS(i) AND l_party_tbl(i) IS NOT NULL THEN
3050 px_party_id_tbl(i) := to_number(l_party_tbl(i));
3051 /*
3052 OPEN get_account_id ( px_party_id_tbl(i)) ;
3053 FETCH get_account_id INTO px_cust_account_id_tbl(i);
3054 CLOSE get_account_id;
3055 */
3056 END IF;
3057 END LOOP;
3058 END IF;
3059 END IF;
3060
3061 IF OZF_DEBUG_HIGH_ON THEN
3062 ozf_utility_pvt.debug_message('Private API: ' || l_api_name || ': end');
3063 END IF;
3064 EXCEPTION
3065 WHEN FND_API.G_EXC_ERROR THEN
3066 x_return_status := FND_API.G_RET_STS_ERROR;
3067 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
3068 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3069 WHEN OTHERS THEN
3070 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3071 IF OZF_UNEXP_ERROR THEN
3072 FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
3073 END IF;
3074 END End_Cust_Party_Mapping;
3075
3076
3077 PROCEDURE Code_ID_Mapping
3078 (
3079 p_batch_record IN ozf_resale_batches_all%ROWTYPE,
3080 px_line_record IN OUT NOCOPY resale_line_int_rec_type,
3081 x_return_status OUT NOCOPY VARCHAR2,
3082 x_msg_data OUT NOCOPY VARCHAR2,
3083 x_msg_count OUT NOCOPY NUMBER
3084 )
3085 IS
3086 l_api_name CONSTANT VARCHAR2(30) := 'Code_ID_Mapping';
3087 l_api_version_number CONSTANT NUMBER := 1.0;
3088
3089 BEGIN
3090 IF OZF_DEBUG_HIGH_ON THEN
3091 ozf_utility_pvt.debug_message('Private API: ' || l_api_name || ': start');
3092 END IF;
3093
3094 x_return_status := FND_API.G_RET_STS_SUCCESS;
3095 Agreement_Default
3096 (
3097 p_party_id => p_batch_record.partner_party_id,
3098 p_cust_account_id => p_batch_record.partner_cust_account_id,
3099 p_batch_type => p_batch_record.batch_type,
3100 p_interface_line_id_tbl => px_line_record.resale_line_int_id,
3101 p_ext_agreement_name => px_line_record.orig_system_agreement_name,
3102 p_ext_agreement_type => px_line_record.orig_system_agreement_type,
3103 px_int_agreement_name => px_line_record.agreement_name,
3104 px_int_agreement_type => px_line_record.agreement_type,
3105 px_agreement_id => px_line_record.agreement_id,
3106 px_corrected_agreement_id => px_line_record.corrected_agreement_id,
3107 px_corrected_agreement_name => px_line_record.corrected_agreement_name,
3108 px_status_tbl => px_line_record.status_code,
3109 px_dispute_code_tbl => px_line_record.dispute_code,
3110 p_resale_transfer_type => px_line_record.resale_transfer_type,
3111 x_return_status => x_return_status,
3112 x_msg_data => x_msg_data,
3113 x_msg_count => x_msg_count
3114 );
3115 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
3116 RAISE FND_API.G_EXC_ERROR;
3117 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
3118 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3119 END IF;
3120 Product_validations
3121 (
3122 p_party_id => p_batch_record.partner_party_id,
3123 p_cust_account_id => p_batch_record.partner_cust_account_id,
3124 p_interface_line_id_tbl => px_line_record.resale_line_int_id,
3125 p_ext_item_number_tbl => px_line_record.orig_system_item_number,
3126 p_item_number_tbl => px_line_record.item_number,
3127 px_item_id_tbl => px_line_record.inventory_item_id,
3131 x_msg_data => x_msg_data,
3128 px_status_tbl => px_line_record.status_code,
3129 px_dispute_code_tbl => px_line_record.dispute_code,
3130 x_return_status => x_return_status,
3132 x_msg_count => x_msg_count
3133 );
3134 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
3135 RAISE FND_API.G_EXC_ERROR;
3136 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
3137 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3138 END IF;
3139
3140 UOM_Code_Mapping
3141 (
3142 p_party_id => p_batch_record.partner_party_id,
3143 p_cust_account_id => p_batch_record.partner_cust_account_id,
3144 p_interface_line_id_tbl => px_line_record.resale_line_int_id,
3145 p_ext_purchase_uom => px_line_record.orig_system_purchase_uom,
3146 p_ext_uom => px_line_record.orig_system_uom,
3147 p_ext_agreement_uom => px_line_record.orig_system_agreement_uom,
3148 px_int_purchase_uom => px_line_record.purchase_uom_code,
3149 px_int_uom => px_line_record.uom_code,
3150 px_int_agreement_uom => px_line_record.agreement_uom_code,
3151 px_status_tbl => px_line_record.status_code,
3152 px_dispute_code_tbl => px_line_record.dispute_code,
3153 x_return_status => x_return_status,
3154 x_msg_data => x_msg_data,
3155 x_msg_count => x_msg_count
3156 );
3157
3158 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
3159 RAISE FND_API.G_EXC_ERROR;
3160 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
3161 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3162 END IF;
3163
3164
3165 Party_Mapping
3166 (
3167 p_party_id => p_batch_record.partner_party_id,
3168 p_cust_account_id => p_batch_record.partner_cust_account_id,
3169 p_party_type => 'SHIP_TO',
3170 p_party_name_tbl => px_line_record.ship_to_party_name,
3171 p_location_tbl => px_line_record.ship_to_location,
3172 px_cust_account_id_tbl => px_line_record.ship_to_cust_account_id,
3173 px_site_use_id_tbl => px_line_record.ship_to_site_use_id,
3174 px_party_id_tbl => px_line_record.ship_to_party_id,
3175 px_party_site_id_tbl => px_line_record.ship_to_party_site_id,
3176 x_return_status => x_return_status
3177 );
3178 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
3179 RAISE FND_API.G_EXC_ERROR;
3180 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
3181 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3182 END IF;
3183
3184 Party_Mapping
3185 (
3186 p_party_id => p_batch_record.partner_party_id,
3187 p_cust_account_id => p_batch_record.partner_cust_account_id,
3188 p_party_type => 'BILL_TO',
3189 p_party_name_tbl => px_line_record.bill_to_party_name,
3190 p_location_tbl => px_line_record.bill_to_location,
3191 px_cust_account_id_tbl => px_line_record.bill_to_cust_account_id,
3192 px_site_use_id_tbl => px_line_record.bill_to_site_use_id,
3193 px_party_id_tbl => px_line_record.bill_to_party_id,
3194 px_party_site_id_tbl => px_line_record.bill_to_party_site_id,
3195 x_return_status => x_return_status
3196 );
3197 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
3198 RAISE FND_API.G_EXC_ERROR;
3199 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
3200 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3201 END IF;
3202
3203 -- Add code to derive bill_to based on ship_to jxwu
3204
3205 -- Bug 4469837 (+)
3206 End_Cust_Party_Mapping(
3207 p_party_id => p_batch_record.partner_party_id,
3208 p_cust_account_id => p_batch_record.partner_cust_account_id,
3209 p_party_name_tbl => px_line_record.end_cust_party_name,
3210 p_location_tbl => px_line_record.end_cust_location,
3211 px_site_use_code_tbl => px_line_record.end_cust_site_use_code,
3212 px_site_use_id_tbl => px_line_record.end_cust_site_use_id,
3213 px_party_id_tbl => px_line_record.end_cust_party_id,
3214 px_party_site_id_tbl => px_line_record.end_cust_party_site_id,
3215 x_return_status => x_return_status
3216 );
3217 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
3218 RAISE FND_API.G_EXC_ERROR;
3219 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
3220 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3221 END IF;
3222 -- Bug 4469837 (-)
3223
3224
3225 -- end
3226 IF OZF_DEBUG_HIGH_ON THEN
3227 ozf_utility_pvt.debug_message('Private API: ' || l_api_name || ': End');
3228 END IF;
3229
3230 EXCEPTION
3231 WHEN FND_API.G_EXC_ERROR THEN
3232 x_return_status := FND_API.G_RET_STS_ERROR;
3233 -- Standard call to get message count and if count=1, get the message
3234 FND_MSG_PUB.Count_And_Get (
3235 p_encoded => FND_API.G_FALSE,
3236 p_count => x_msg_count,
3237 p_data => x_msg_data
3238 );
3239 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
3240 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3241 -- Standard call to get message count and if count=1, get the message
3242 FND_MSG_PUB.Count_And_Get (
3243 p_encoded => FND_API.G_FALSE,
3247 WHEN OTHERS THEN
3244 p_count => x_msg_count,
3245 p_data => x_msg_data
3246 );
3248
3249 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3250 IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
3251 THEN
3252 FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
3253 END IF;
3254 -- Standard call to get message count and if count=1, get the message
3255 FND_MSG_PUB.Count_And_Get (
3256 p_encoded => FND_API.G_FALSE,
3257 p_count => x_msg_count,
3258 p_data => x_msg_data
3259 );
3260 END Code_ID_Mapping;
3261
3262
3263 PROCEDURE Line_Party_Validations
3264 (
3265 p_line_count IN NUMBER,
3266 px_line_record IN OUT NOCOPY resale_line_int_rec_type,
3267 x_return_status OUT NOCOPY VARCHAR2
3268 )
3269 IS
3270 l_api_name CONSTANT VARCHAR2(50) := 'Line_Party_Validations';
3271 l_api_version_number CONSTANT NUMBER := 1.0;
3272
3273 l_party_site_id NUMBER_TABLE;
3274 l_party_id NUMBER_TABLE;
3275 l_site_use_type VARCHAR2_TABLE;
3276 l_null_flag VARCHAR2(1);
3277
3278
3279 BEGIN
3280 IF OZF_DEBUG_HIGH_ON THEN
3281 ozf_utility_pvt.debug_message('Private API: ' || l_api_name || ' start');
3282 END IF;
3283
3284 x_return_status := FND_API.G_RET_STS_SUCCESS;
3285
3286 -- ----------------------------------------------------------
3287 -- SHIP_FROM Customer
3288 -- ----------------------------------------------------------
3289 IF OZF_DEBUG_LOW_ON THEN
3290 ozf_utility_pvt.debug_message('++++++++++++++ SHIP FROM Customer ++++++++++++++ (+)');
3291 END IF;
3292 Party_Validations
3293 ( p_resale_line_int_id => px_line_record.resale_line_int_id
3294 , p_location => px_line_record.ship_from_location
3295 , p_address => px_line_record.ship_from_address
3296 , p_city => px_line_record.ship_from_city
3297 , p_state => px_line_record.ship_from_state
3298 , p_postal_code => px_line_record.ship_from_postal_code
3299 , p_country => px_line_record.ship_from_country
3300 , p_contact_name => px_line_record.ship_from_contact_name
3301 , p_email => px_line_record.ship_from_email
3302 , p_fax => px_line_record.ship_from_fax
3303 , p_phone => px_line_record.ship_from_phone
3304 , p_site_use_type => l_site_use_type
3305 , p_direct_customer_flag => px_line_record.direct_customer_flag
3306 , p_party_type => 'SHIP_FROM'
3307 , p_line_count => p_line_count
3308 , px_party_name => px_line_record.ship_from_party_name
3309 , px_cust_account_id => px_line_record.ship_from_cust_account_id
3310 , px_site_use_id => px_line_record.ship_from_site_id
3311 , px_party_id => l_party_id
3312 , px_party_site_id => l_party_site_id
3313 , px_contact_party_id => px_line_record.ship_from_contact_party_id
3314 , px_status_code_tbl => px_line_record.status_code
3315 , px_dispute_code_tbl => px_line_record.dispute_code
3316 , x_return_status => x_return_status
3317 );
3318 IF OZF_DEBUG_LOW_ON THEN
3319 FOR i IN 1..px_line_record.ship_from_cust_account_id.count LOOP
3320 ozf_utility_pvt.debug_message ('ship_from_cust_account_id ('||i||')'||px_line_record.ship_from_cust_account_id(i));
3321 ozf_utility_pvt.debug_message ('ship_from_site_id ('||i||')'||px_line_record.ship_from_site_id(i));
3322 END LOOP;
3323 END IF;
3324 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
3325 RAISE FND_API.G_EXC_ERROR;
3326 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
3327 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3328 END IF;
3329 l_party_site_id.delete;
3330 l_party_id.delete;
3331 IF OZF_DEBUG_LOW_ON THEN
3332 ozf_utility_pvt.debug_message('++++++++++++++ SHIP FROM Customer ++++++++++++++ (-)');
3333 END IF;
3334
3335
3336 -- ----------------------------------------------------------
3337 -- SOLD_FROM Customer
3338 -- Derive from ship_from if null
3339 -- ----------------------------------------------------------
3340 IF OZF_DEBUG_LOW_ON THEN
3341 ozf_utility_pvt.debug_message('++++++++++++++ SOLD FROM Customer ++++++++++++++ (+)');
3342 END IF;
3343 l_null_flag := NULL;
3344 chk_party_record_null
3345 ( p_line_count => p_line_count
3346 , p_party_type => 'SOLD_FROM'
3347 , p_cust_account_id => px_line_record.sold_from_cust_account_id
3348 , p_acct_site_id => px_line_record.sold_from_site_id
3349 , p_party_id => l_party_id
3350 , p_party_site_id => l_party_site_id
3351 , p_location => px_line_record.sold_from_location
3352 , p_party_name => px_line_record.sold_from_party_name
3353 , x_null_flag => l_null_flag
3354 , x_return_status => x_return_status
3355 );
3356 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
3357 RAISE FND_API.G_EXC_ERROR;
3358 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
3359 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3360 END IF;
3361
3365 , p_line_count => p_line_count
3362 IF l_null_flag = 'Y' THEN
3363 Derive_party
3364 ( p_resale_line_int_id => px_line_record.resale_line_int_id
3366 , p_party_type => 'SOLD_FROM'
3367 , p_cust_account_id => px_line_record.ship_from_cust_account_id
3368 , p_site_id => px_line_record.ship_from_site_id
3369 , x_cust_account_id => px_line_record.sold_from_cust_account_id
3370 , x_site_id => px_line_record.sold_from_site_id
3371 , x_site_use_id => l_party_site_id
3372 , x_party_id => l_party_id
3373 , x_party_name => px_line_record.sold_from_party_name
3374 , px_status_code_tbl => px_line_record.status_code
3375 , px_dispute_code_tbl => px_line_record.dispute_code
3376 , x_return_status => x_return_status
3377 );
3378 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
3379 RAISE FND_API.G_EXC_ERROR;
3380 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
3381 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3382 END IF;
3383
3384 ELSIF l_null_flag IS NULL OR l_null_flag = 'N' THEN
3385 Party_Validations
3386 ( p_resale_line_int_id => px_line_record.resale_line_int_id
3387 , p_location => px_line_record.sold_from_location
3388 , p_address => px_line_record.sold_from_address
3389 , p_city => px_line_record.sold_from_city
3390 , p_state => px_line_record.sold_from_state
3391 , p_postal_code => px_line_record.sold_from_postal_code
3392 , p_country => px_line_record.sold_from_country
3393 , p_contact_name => px_line_record.sold_from_contact_name
3394 , p_email => px_line_record.sold_from_email
3395 , p_fax => px_line_record.sold_from_fax
3396 , p_phone => px_line_record.sold_from_phone
3397 , p_site_use_type => l_site_use_type
3398 , p_direct_customer_flag => px_line_record.direct_customer_flag
3399 , p_party_type => 'SOLD_FROM'
3400 , p_line_count => p_line_count
3401 , px_party_name => px_line_record.sold_from_party_name
3402 , px_cust_account_id => px_line_record.sold_from_cust_account_id
3403 , px_site_use_id => px_line_record.sold_from_site_id
3404 , px_party_id => l_party_id
3405 , px_party_site_id => l_party_site_id
3406 , px_contact_party_id => px_line_record.sold_from_contact_party_id
3407 , px_status_code_tbl => px_line_record.status_code
3408 , px_dispute_code_tbl => px_line_record.dispute_code
3409 , x_return_status => x_return_status
3410 );
3411 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
3412 RAISE FND_API.G_EXC_ERROR;
3413 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
3414 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3415 END IF;
3416 END IF;
3417 IF OZF_DEBUG_LOW_ON THEN
3418 FOR i IN 1..px_line_record.sold_from_cust_account_id.count LOOP
3419 ozf_utility_pvt.debug_message ('sold_from_cust_account_id ('||i||')'||px_line_record.sold_from_cust_account_id(i));
3420 ozf_utility_pvt.debug_message ('sold_from_site_id ('||i||')'||px_line_record.sold_from_site_id(i));
3421 END LOOP;
3422 END IF;
3423 l_party_site_id.delete;
3424 l_party_id.delete;
3425 IF OZF_DEBUG_LOW_ON THEN
3426 ozf_utility_pvt.debug_message('++++++++++++++ SOLD FROM Customer ++++++++++++++ (-)');
3427 END IF;
3428
3429
3430 -- ----------------------------------------------------------
3431 -- SHIP_TO Customer
3432 -- ----------------------------------------------------------
3433 IF OZF_DEBUG_LOW_ON THEN
3434 ozf_utility_pvt.debug_message('++++++++++++++ SHIP TO Customer ++++++++++++++ (+)');
3435 END IF;
3436 Party_Validations
3437 ( p_resale_line_int_id => px_line_record.resale_line_int_id
3438 , p_location => px_line_record.ship_to_location
3439 , p_address => px_line_record.ship_to_address
3440 , p_city => px_line_record.ship_to_city
3441 , p_state => px_line_record.ship_to_state
3442 , p_postal_code => px_line_record.ship_to_postal_code
3443 , p_country => px_line_record.ship_to_country
3444 , p_contact_name => px_line_record.ship_to_contact_name
3445 , p_email => px_line_record.ship_to_email
3446 , p_fax => px_line_record.ship_to_fax
3447 , p_phone => px_line_record.ship_to_phone
3448 , p_site_use_type => l_site_use_type
3449 , p_direct_customer_flag => px_line_record.direct_customer_flag
3450 , p_party_type => 'SHIP_TO'
3451 , p_line_count => p_line_count
3452 , px_party_name => px_line_record.ship_to_party_name
3453 , px_cust_account_id => px_line_record.ship_to_cust_account_id
3454 , px_site_use_id => px_line_record.ship_to_site_use_id
3455 , px_party_id => px_line_record.ship_to_party_id
3456 , px_party_site_id => px_line_record.ship_to_party_site_id
3457 , px_contact_party_id => px_line_record.ship_to_contact_party_id
3461 );
3458 , px_status_code_tbl => px_line_record.status_code
3459 , px_dispute_code_tbl => px_line_record.dispute_code
3460 , x_return_status => x_return_status
3462 IF OZF_DEBUG_LOW_ON THEN
3463 FOR i IN 1..px_line_record.ship_to_cust_account_id.count LOOP
3464 ozf_utility_pvt.debug_message ('ship_to_cust_account_id ('||i||')'||px_line_record.ship_to_cust_account_id(i));
3465 ozf_utility_pvt.debug_message ('ship_to_site_use_id ('||i||')'||px_line_record.ship_to_site_use_id(i));
3466 ozf_utility_pvt.debug_message ('ship_to_party_id ('||i||')'||px_line_record.ship_to_party_id(i));
3467 ozf_utility_pvt.debug_message ('ship_to_party_site_id ('||i||')'||px_line_record.ship_to_party_site_id(i));
3468 END LOOP;
3469 END IF;
3470 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
3471 RAISE FND_API.G_EXC_ERROR;
3472 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
3473 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3474 END IF;
3475 IF OZF_DEBUG_LOW_ON THEN
3476 ozf_utility_pvt.debug_message('++++++++++++++ SHIP TO Customer ++++++++++++++ (-)');
3477 END IF;
3478
3479 -- ----------------------------------------------------------
3480 -- BILL_TO Customer
3481 -- Derive from ship_from if null
3482 -- ----------------------------------------------------------
3483 IF OZF_DEBUG_LOW_ON THEN
3484 ozf_utility_pvt.debug_message('++++++++++++++ BILL TO Customer ++++++++++++++ (+)');
3485 END IF;
3486 l_null_flag := NULL;
3487 chk_party_record_null
3488 ( p_line_count => p_line_count
3489 , p_party_type => 'BILL_TO'
3490 , p_cust_account_id => px_line_record.bill_to_cust_account_id
3491 , p_acct_site_id => px_line_record.bill_to_site_use_id
3492 , p_party_id => px_line_record.bill_to_party_id
3493 , p_party_site_id => px_line_record.bill_to_party_site_id
3494 , p_location => px_line_record.bill_to_location
3495 , p_party_name => px_line_record.bill_to_party_name
3496 , x_null_flag => l_null_flag
3497 , x_return_status => x_return_status
3498 );
3499 IF OZF_DEBUG_LOW_ON THEN
3500 ozf_utility_pvt.debug_message ('Null Flag '||l_null_flag);
3501 END IF;
3502 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
3503 RAISE FND_API.G_EXC_ERROR;
3504 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
3505 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3506 END IF;
3507
3508 IF l_null_flag = 'Y' THEN
3509 Derive_Party
3510 ( p_resale_line_int_id => px_line_record.resale_line_int_id
3511 , p_line_count => p_line_count
3512 , p_party_type => 'BILL_TO'
3513 , p_cust_account_id => px_line_record.ship_to_cust_account_id
3514 , p_site_id => px_line_record.ship_to_site_use_id
3515 , x_cust_account_id => px_line_record.bill_to_cust_account_id
3516 , x_site_id => px_line_record.bill_to_party_site_id
3517 , x_site_use_id => px_line_record.bill_to_site_use_id
3518 , x_party_id => px_line_record.bill_to_party_id
3519 , x_party_name => px_line_record.bill_to_party_name
3520 , px_status_code_tbl => px_line_record.status_code
3521 , px_dispute_code_tbl => px_line_record.dispute_code
3522 , x_return_status => x_return_status
3523 );
3524 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
3525 RAISE FND_API.G_EXC_ERROR;
3526 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
3527 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3528 END IF;
3529
3530 ELSIF l_null_flag IS NULL OR l_null_flag = 'N' THEN
3531 Party_Validations
3532 ( p_resale_line_int_id => px_line_record.resale_line_int_id
3533 , p_location => px_line_record.bill_to_location
3534 , p_address => px_line_record.bill_to_address
3535 , p_city => px_line_record.bill_to_city
3536 , p_state => px_line_record.bill_to_state
3537 , p_postal_code => px_line_record.bill_to_postal_code
3538 , p_country => px_line_record.bill_to_country
3539 , p_contact_name => px_line_record.bill_to_contact_name
3540 , p_email => px_line_record.bill_to_email
3541 , p_fax => px_line_record.bill_to_fax
3542 , p_phone => px_line_record.bill_to_phone
3543 , p_site_use_type => l_site_use_type
3544 , p_direct_customer_flag => px_line_record.direct_customer_flag
3545 , p_party_type => 'BILL_TO'
3546 , p_line_count => p_line_count
3547 , px_party_name => px_line_record.bill_to_party_name
3548 , px_cust_account_id => px_line_record.bill_to_cust_account_id
3549 , px_site_use_id => px_line_record.bill_to_site_use_id
3550 , px_party_id => px_line_record.bill_to_party_id
3551 , px_party_site_id => px_line_record.bill_to_party_site_id
3552 , px_contact_party_id => px_line_record.bill_to_contact_party_id
3553 , px_status_code_tbl => px_line_record.status_code
3554 , px_dispute_code_tbl => px_line_record.dispute_code
3555 , x_return_status => x_return_status
3559 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
3556 );
3557 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
3558 RAISE FND_API.G_EXC_ERROR;
3560 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3561 END IF;
3562 END IF;
3563 IF OZF_DEBUG_LOW_ON THEN
3564 FOR i IN 1 .. px_line_record.ship_to_cust_account_id.count
3565 LOOP
3566 ozf_utility_pvt.debug_message ('bill_to_cust_account_id ('||i||')'||px_line_record.bill_to_cust_account_id(i));
3567 ozf_utility_pvt.debug_message ('bill_to_site_use_id ('||i||')'||px_line_record.bill_to_site_use_id(i));
3568 ozf_utility_pvt.debug_message ('bill_to_party_id ('||i||')'||px_line_record.bill_to_party_id(i));
3569 ozf_utility_pvt.debug_message ('bill_to_party_site_id ('||i||')'||px_line_record.bill_to_party_site_id(i));
3570 END LOOP;
3571 ozf_utility_pvt.debug_message('++++++++++++++ BILL TO Customer ++++++++++++++ (-)');
3572 END IF;
3573
3574
3575 -- ----------------------------------------------------------
3576 -- END Customer
3577 -- ----------------------------------------------------------
3578 IF OZF_DEBUG_LOW_ON THEN
3579 ozf_utility_pvt.debug_message('++++++++++++++ END Customer ++++++++++++++ (+)');
3580 END IF;
3581 Party_Validations
3582 ( p_resale_line_int_id => px_line_record.resale_line_int_id
3583 , p_location => px_line_record.end_cust_location
3584 , p_address => px_line_record.end_cust_address
3585 , p_city => px_line_record.end_cust_city
3586 , p_state => px_line_record.end_cust_state
3587 , p_postal_code => px_line_record.end_cust_postal_code
3588 , p_country => px_line_record.end_cust_country
3589 , p_contact_name => px_line_record.end_cust_contact_name
3590 , p_email => px_line_record.end_cust_email
3591 , p_fax => px_line_record.end_cust_fax
3592 , p_phone => px_line_record.end_cust_phone
3593 , p_site_use_type => px_line_record.end_cust_site_use_code
3594 , p_direct_customer_flag => px_line_record.direct_customer_flag
3595 , p_party_type => 'END_CUST'
3596 , p_line_count => p_line_count
3597 , px_party_name => px_line_record.end_cust_party_name
3598 , px_cust_account_id => l_party_id
3599 , px_site_use_id => px_line_record.end_cust_site_use_id
3600 , px_party_id => px_line_record.end_cust_party_id
3601 , px_party_site_id => px_line_record.end_cust_party_site_id
3602 , px_contact_party_id => px_line_record.end_cust_contact_party_id
3603 , px_status_code_tbl => px_line_record.status_code
3604 , px_dispute_code_tbl => px_line_record.dispute_code
3605 , x_return_status => x_return_status
3606 );
3607 IF OZF_DEBUG_LOW_ON THEN
3608 FOR i IN 1..px_line_record.ship_to_cust_account_id.count LOOP
3609 ozf_utility_pvt.debug_message ('end_cust_party_id ('||i||')'||px_line_record.end_cust_party_id(i));
3610 ozf_utility_pvt.debug_message ('end_cust_site_use_id ('||i||')'||px_line_record.end_cust_site_use_id(i));
3611 ozf_utility_pvt.debug_message ('bill_to_party_id ('||i||')'||px_line_record.bill_to_party_id(i));
3612 END LOOP;
3613 END IF;
3614 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
3615 RAISE FND_API.G_EXC_ERROR;
3616 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
3617 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3618 END IF;
3619 IF OZF_DEBUG_LOW_ON THEN
3620 ozf_utility_pvt.debug_message('++++++++++++++ END Customer ++++++++++++++ (-)');
3621 END IF;
3622
3623
3624 EXCEPTION
3625 WHEN FND_API.G_EXC_ERROR THEN
3626 x_return_status := FND_API.G_RET_STS_ERROR;
3627 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
3628 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3629 WHEN OTHERS THEN
3630 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3631 IF OZF_UNEXP_ERROR THEN
3632 FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
3633 END IF;
3634 END Line_Party_Validations;
3635
3636
3637
3638 PROCEDURE Line_Currency_Price_Derivation
3639 (
3640 p_line_count IN NUMBER,
3641 px_line_record IN OUT NOCOPY resale_line_int_rec_type,
3642 x_return_status OUT NOCOPY VARCHAR2
3643 )
3644 IS
3645 l_api_name CONSTANT VARCHAR2(50) := 'Line_Currency_Price_Derivation';
3646 l_api_version_number CONSTANT NUMBER := 1.0;
3647
3648 l_mapping_flag VARCHAR2(1);
3649 l_acctd_price_tbl NUMBER_TABLE;
3650
3651 BEGIN
3652 IF OZF_DEBUG_HIGH_ON THEN
3653 ozf_utility_pvt.debug_message('Private API: ' || l_api_name || ' start');
3654 END IF;
3655 x_return_status := FND_API.G_RET_STS_SUCCESS;
3656
3657 -- Selling Price and Currency Derivation
3658
3659 Currency_Price_Derivation(
3660 p_line_count => p_line_count,
3661 p_conversion_type => 'ORIG_SYSTEM',
3662 p_int_line_id_tbl => px_line_record.resale_line_int_id,
3663 p_external_price_tbl => px_line_record.orig_system_selling_price,
3664 p_conversion_date_tbl => px_line_record.exchange_rate_date,
3665 p_ext_currency_tbl => px_line_record.orig_system_currency_code,
3666 px_internal_price_tbl => px_line_record.selling_price,
3667 px_currency_tbl => px_line_record.currency_code,
3668 px_exchange_rate_tbl => px_line_record.exchange_rate,
3669 px_rate_type_tbl => px_line_record.exchange_rate_type,
3670 x_accounted_price_tbl => px_line_record.acctd_selling_price,
3671 px_status_tbl => px_line_record.status_code,
3672 px_dispute_code_tbl => px_line_record.dispute_code,
3673 x_return_status => x_return_status
3674 );
3675 IF x_return_status = FND_API.g_ret_sts_error THEN
3676 RAISE FND_API.g_exc_error;
3677 ELSIF x_return_status = FND_API.g_ret_sts_unexp_error THEN
3678 RAISE FND_API.g_exc_unexpected_error;
3679 END IF;
3680
3681 -- Agreement Price and Currency Derivation
3682 Currency_Price_Derivation(
3683 p_line_count => p_line_count,
3684 p_conversion_type => 'AGREEMENT',
3685 p_int_line_id_tbl => px_line_record.resale_line_int_id,
3686 p_external_price_tbl => px_line_record.orig_system_agreement_price,
3687 p_conversion_date_tbl => px_line_record.exchange_rate_date,
3688 p_ext_currency_tbl => px_line_record.orig_system_agreement_curr,
3689 px_internal_price_tbl => px_line_record.agreement_price,
3690 px_currency_tbl => px_line_record.currency_code,
3691 px_exchange_rate_tbl => px_line_record.exchange_rate,
3692 px_rate_type_tbl => px_line_record.exchange_rate_type,
3693 x_accounted_price_tbl => l_acctd_price_tbl,
3694 px_status_tbl => px_line_record.status_code,
3695 px_dispute_code_tbl => px_line_record.dispute_code,
3696 x_return_status => x_return_status
3697 );
3698 IF x_return_status = FND_API.g_ret_sts_error THEN
3699 RAISE FND_API.g_exc_error;
3700 ELSIF x_return_status = FND_API.g_ret_sts_unexp_error THEN
3701 RAISE FND_API.g_exc_unexpected_error;
3702 END IF;
3703
3704 -- Purchase Price and Currency Derivation
3705 Currency_Price_Derivation(
3706 p_line_count => p_line_count,
3707 p_conversion_type => 'PURCHASE',
3708 p_int_line_id_tbl => px_line_record.resale_line_int_id,
3709 p_external_price_tbl => px_line_record.orig_system_purchase_price,
3710 p_conversion_date_tbl => px_line_record.exchange_rate_date,
3711 p_ext_currency_tbl => px_line_record.orig_system_purchase_curr,
3712 px_internal_price_tbl => px_line_record.purchase_price,
3713 px_currency_tbl => px_line_record.currency_code,
3714 px_exchange_rate_tbl => px_line_record.exchange_rate,
3715 px_rate_type_tbl => px_line_record.exchange_rate_type,
3716 x_accounted_price_tbl => px_line_record.acctd_purchase_price,
3717 px_status_tbl => px_line_record.status_code,
3718 px_dispute_code_tbl => px_line_record.dispute_code,
3719 x_return_status => x_return_status
3720 );
3721 IF x_return_status = FND_API.g_ret_sts_error THEN
3722 RAISE FND_API.g_exc_error;
3723 ELSIF x_return_status = FND_API.g_ret_sts_unexp_error THEN
3724 RAISE FND_API.g_exc_unexpected_error;
3725 END IF;
3726
3727 IF OZF_DEBUG_HIGH_ON THEN
3728 ozf_utility_pvt.debug_message('Private API: ' || l_api_name || ': end');
3729 END IF;
3730 EXCEPTION
3731 WHEN FND_API.G_EXC_ERROR THEN
3732 x_return_status := FND_API.G_RET_STS_ERROR;
3733 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
3734 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3735 WHEN OTHERS THEN
3736 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3737 IF OZF_UNEXP_ERROR THEN
3738 FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
3739 END IF;
3740 END Line_Currency_Price_Derivation;
3741
3742 PROCEDURE Currency_Price_Derivation
3743 (
3744 p_line_count IN NUMBER,
3745 p_conversion_type IN VARCHAR2,
3746 p_int_line_id_tbl IN NUMBER_TABLE,
3747 p_external_price_tbl IN NUMBER_TABLE,
3748 p_conversion_date_tbl IN DATE_TABLE,
3749 p_ext_currency_tbl IN VARCHAR2_TABLE,
3750 px_internal_price_tbl IN OUT NOCOPY NUMBER_TABLE,
3751 px_currency_tbl IN OUT NOCOPY VARCHAR2_TABLE,
3752 px_exchange_rate_tbl IN OUT NOCOPY NUMBER_TABLE,
3753 px_rate_type_tbl IN OUT NOCOPY VARCHAR2_TABLE,
3754 x_accounted_price_tbl OUT NOCOPY NUMBER_TABLE,
3755 px_status_tbl IN OUT NOCOPY VARCHAR2_TABLE,
3756 px_dispute_code_tbl IN OUT NOCOPY VARCHAR2_TABLE,
3757 x_return_status OUT NOCOPY VARCHAR2
3758 )
3759 IS
3760
3761
3762 l_api_name CONSTANT VARCHAR2(30) := 'Currency_Price_Derivation';
3763 l_api_version_number CONSTANT NUMBER := 1.0;
3764
3765 CURSOR get_functional_currency
3766 IS
3767 SELECT gs.currency_code
3768 FROM gl_sets_of_books gs,
3769 ozf_sys_parameters osp
3770 WHERE gs.set_of_books_id = osp.set_of_books_id
3771 AND osp.org_id = MO_GLOBAL.get_current_org_id();
3772
3773
3774 l_set_of_books_id NUMBER;
3775 l_sob_type_code VARCHAR2(30);
3776 l_functional_currency VARCHAR2(15);
3777
3778 l_internal_currency VARCHAR2(15);
3779 l_internal_price NUMBER;
3780 l_exchange_rate_type VARCHAR2(100);
3781 l_exchange_rate NUMBER;
3782
3783 CURSOR get_currency_code_csr(p_name in VARCHAR2) IS
3784 SELECT currency_code
3785 FROM fnd_currencies_vl
3786 WHERE name = p_name;
3787
3788 l_converted_currency VARCHAR2(15);
3792 IF OZF_DEBUG_HIGH_ON THEN
3789 l_converted_amount NUMBER;
3790
3791 BEGIN
3793 ozf_utility_pvt.debug_message('Private API: ' || l_api_name || ' start');
3794 ozf_utility_pvt.debug_message('Line Count ' || p_line_count);
3795 END IF;
3796 x_return_status := FND_API.G_RET_STS_SUCCESS;
3797
3798 OPEN get_functional_currency;
3799 FETCH get_functional_currency INTO l_functional_currency;
3800 CLOSE get_functional_currency;
3801
3802 FOR i IN 1 .. px_internal_price_tbl.COUNT LOOP
3803
3804 -- This logic is OK since currency code is the only colum that will be populated.
3805 IF px_currency_tbl(i) IS NULL THEN
3806 IF p_ext_currency_tbl(i) IS NOT NULL THEN
3807 OPEN get_currency_code_csr(p_ext_currency_tbl(i));
3808 FETCH get_currency_code_csr INTO l_converted_currency;
3809 CLOSE get_currency_code_csr;
3810 px_currency_tbl(i) := l_converted_currency;
3811 ELSE
3812 px_currency_tbl(i) := G_BATCH_CURRENCY_CODE;
3813 END IF;
3814 END IF;
3815
3816 IF OZF_DEBUG_LOW_ON THEN
3817 ozf_utility_pvt.debug_message('Internal Price Tbl ('|| i ||') '|| px_internal_price_tbl(i));
3818 ozf_utility_pvt.debug_message('External Price Tbl ('|| i ||') '|| p_external_price_tbl(i));
3819 END IF;
3820 IF px_internal_price_tbl(i) IS NOT NULL THEN
3821 NULL;
3822 ELSIF p_external_price_tbl(i) IS NOT NULL THEN
3823 IF OZF_DEBUG_LOW_ON THEN
3824 ozf_utility_pvt.debug_message('External Price Tbl ('|| i ||') '|| p_external_price_tbl(i));
3825 ozf_utility_pvt.debug_message('External Currency Tbl ('|| i ||') '|| p_ext_currency_tbl(i));
3826 END IF;
3827 IF p_conversion_type = 'ORIG_SYSTEM' THEN
3828 px_internal_price_tbl(i) := p_external_price_tbl(i);
3829 ELSE
3830 -- Don't understand why this has anything to do with invnetory tracking
3831 -- IF ( g_inventory_tracking_flag = 'F' AND p_conversion_type = 'PURCHASE' )
3832 -- OR p_conversion_type = 'AGREEMENT' THEN
3833 l_exchange_rate_type := NULL;
3834 l_exchange_rate := NULL;
3835 l_converted_currency := NULL;
3836 -- convert the orig_system to internal code and then compare
3837 OPEN get_currency_code_csr(p_ext_currency_tbl(i));
3838 FETCH get_currency_code_csr INTO l_converted_currency;
3839 CLOSE get_currency_code_csr;
3840
3841 IF l_converted_currency IS NULL OR
3842 l_converted_currency = px_currency_tbl(i) THEN
3843 px_internal_price_tbl(i) := p_external_price_tbl(i);
3844 ELSE
3845 IF l_converted_currency <> px_currency_tbl(i) THEN
3846 IF px_exchange_rate_tbl(i) IS NULL THEN
3847 IF px_rate_type_tbl(i) IS NULL THEN
3848 OPEN OZF_RESALE_COMMON_PVT.g_exchange_rate_type_csr;
3849 FETCH OZF_RESALE_COMMON_PVT.g_exchange_rate_type_csr INTO px_rate_type_tbl(i);
3850 CLOSE OZF_RESALE_COMMON_PVT.g_exchange_rate_type_csr;
3851 END IF;
3852
3853 IF OZF_DEBUG_LOW_ON THEN
3854 ozf_utility_pvt.debug_message('Exchange Rate Type ('|| i ||') '|| px_rate_type_tbl(i));
3855 ozf_utility_pvt.debug_message('Calling convert currency');
3856 END IF;
3857
3858 OZF_UTILITY_PVT.Convert_Currency(
3859 p_from_currency => l_converted_currency
3860 ,p_to_currency => px_currency_tbl(i)
3861 ,p_conv_type => px_rate_type_tbl(i)
3862 ,p_conv_rate => NULL
3863 ,p_conv_date => nvl(p_conversion_date_tbl(i),sysdate)
3864 ,p_from_amount => p_external_price_tbl(i)
3865 ,x_return_status => x_return_status
3866 ,x_to_amount => l_converted_amount
3867 ,x_rate => l_exchange_rate);
3868
3869 IF OZF_DEBUG_LOW_ON THEN
3870 ozf_utility_pvt.debug_message('Exchange Rate Type ('|| i ||') '|| px_rate_type_tbl(i));
3871 END IF;
3872
3873 IF x_return_status <> FND_API.g_ret_sts_success THEN
3874 IF px_status_tbl(i) <> 'DISPUTED' THEN
3875 px_status_tbl(i) := 'DISPUTED';
3876 px_dispute_code_tbl(i) := 'OZF_CURR_CONV_ERROR';
3877 END IF;
3878 insert_resale_log (
3879 p_id_value => p_int_line_id_tbl(i),
3880 p_id_type => 'IFACE',
3881 p_error_code => 'OZF_CURR_CONV_ERROR',
3882 p_column_name => 'CURRENCY_CODE',
3883 p_column_value => p_ext_currency_tbl(i),
3884 x_return_status => x_return_status
3885 );
3886 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
3887 RAISE FND_API.G_EXC_ERROR;
3888 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
3889 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3890 END IF;
3891 END IF;
3892
3893 IF l_exchange_rate IS NOT NULL THEN
3894 px_exchange_rate_tbl(i) := l_exchange_rate;
3895 END IF;
3896 px_internal_price_tbl(i) := l_converted_amount;
3897 ELSE
3898 px_internal_price_tbl(i) := OZF_UTILITY_PVT.CurrRound(p_external_price_tbl(i)*px_exchange_rate_tbl(i), px_currency_tbl(i));
3899 END IF; -- px_exchange_rate_tbl(i) IS NULL
3900 ELSE
3901 px_internal_price_tbl(i) :=p_external_price_tbl(i);
3902 END IF; -- l_convert_currency = internal currency
3903 END IF; -- l_converted_currency IS NULL
3904 -- END IF; -- g_inventory_tracking_flag
3905 END IF; -- p_conversion_type = 'ORIG_SYSTEM'
3906 END IF; -- p_external_price_tbl(i)
3907
3908 IF OZF_DEBUG_LOW_ON THEN
3909 ozf_utility_pvt.debug_message('p_external_price_tbl ('||i||')'|| p_external_price_tbl(i));
3910 ozf_utility_pvt.debug_message('p_conversion_date_tbl ('||i||')'|| p_conversion_date_tbl(i));
3911 ozf_utility_pvt.debug_message('p_ext_currency_tbl ('||i||')'|| p_ext_currency_tbl(i));
3912 ozf_utility_pvt.debug_message('l_converted_concurrency:'|| l_converted_currency);
3913 ozf_utility_pvt.debug_message('px_currency_tbl ('||i||')'|| px_currency_tbl(i));
3914 ozf_utility_pvt.debug_message('px_rate_type_tbl ('||i||')'|| px_rate_type_tbl(i));
3915 ozf_utility_pvt.debug_message('px_internal_price_tbl ('||i||')'|| px_internal_price_tbl(i));
3916 ozf_utility_pvt.debug_message('px_exchange_rate_tbl ('||i||')'|| px_exchange_rate_tbl(i));
3917 END IF;
3918
3919 --
3920 -- --------------------- Accounted Price Calculations -------------------------
3921 -- ----------------------------------------------------------------------------
3922 IF px_internal_price_tbl.exists(i) AND px_internal_price_tbl(i) IS NOT NULL THEN
3923 IF l_functional_currency <> px_currency_tbl(i) THEN
3924 IF px_exchange_rate_tbl(i) IS NULL THEN
3925 IF px_rate_type_tbl(i) IS NULL THEN
3926 OPEN OZF_RESALE_COMMON_PVT.g_exchange_rate_type_csr;
3927 FETCH OZF_RESALE_COMMON_PVT.g_exchange_rate_type_csr INTO px_rate_type_tbl(i);
3928 CLOSE OZF_RESALE_COMMON_PVT.g_exchange_rate_type_csr;
3929 END IF;
3930 OZF_UTILITY_PVT.Convert_Currency(
3931 p_from_currency => px_currency_tbl(i)
3932 ,p_to_currency => l_functional_currency
3933 ,p_conv_type => px_rate_type_tbl(i)
3934 ,p_conv_rate => px_exchange_rate_tbl(i)
3935 ,p_conv_date => nvl(p_conversion_date_tbl(i),sysdate)
3936 ,p_from_amount => px_internal_price_tbl(i)
3937 ,x_return_status => x_return_status
3938 ,x_to_amount => l_converted_amount
3939 ,x_rate => l_exchange_rate);
3940 IF x_return_status <> FND_API.g_ret_sts_success THEN
3941 IF px_status_tbl(i) <> 'DISPUTED' THEN
3942 px_status_tbl(i) := 'DISPUTED';
3943 px_dispute_code_tbl(i) := 'OZF_CURR_CONV_ERROR';
3944 END IF;
3945 insert_resale_log (
3946 p_id_value => p_int_line_id_tbl(i),
3947 p_id_type => 'IFACE',
3948 p_error_code => 'OZF_CURR_CONV_ERROR',
3949 p_column_name => 'CURRENCY_CODE',
3950 p_column_value => px_currency_tbl(i),
3951 x_return_status => x_return_status
3952 );
3953 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
3954 RAISE FND_API.G_EXC_ERROR;
3955 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
3956 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3957 END IF;
3958 END IF;
3959 x_accounted_price_tbl(i) := l_converted_amount;
3960 ELSE
3961 x_accounted_price_tbl(i) := OZF_UTILITY_PVT.CurrRound(px_internal_price_tbl(i)*px_exchange_rate_tbl(i), l_functional_currency);
3962 END IF;
3963 ELSE
3964 x_accounted_price_tbl(i) := px_internal_price_tbl(i);
3965 END IF;
3966 ELSE
3967 x_accounted_price_tbl(i) := NULL;
3968 END IF;
3969 END LOOP;
3970
3971 IF OZF_DEBUG_HIGH_ON THEN
3972 ozf_utility_pvt.debug_message('Private API: ' || l_api_name || ' end');
3973 END IF;
3974
3975 EXCEPTION
3976 WHEN FND_API.G_EXC_ERROR THEN
3977 x_return_status := FND_API.G_RET_STS_ERROR;
3978 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
3979 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3980 WHEN OTHERS THEN
3981 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3982 IF OZF_UNEXP_ERROR THEN
3983 FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
3984 END IF;
3985 END Currency_Price_Derivation;
3986
3987
3988 ---------------------------------------------------------------------
3989 -- PROCEDURE
3990 -- Get_Agreement_Name
3991 --
3992 -- PURPOSE
3993 -- This procedure derives the name of an agreement based on agreement id.
3994 --
3995 -- PARAMETERS
3996 --
3997 --
3998 -- NOTES
3999 ---------------------------------------------------------------------
4000 PROCEDURE Get_Agreement_Name
4001 (
4002 p_type IN VARCHAR2,
4003 p_agreement_id IN NUMBER,
4004 x_agreement_name OUT NOCOPY VARCHAR2,
4005 x_return_status OUT NOCOPY VARCHAR2
4006 )
4007 IS
4008 l_api_name CONSTANT VARCHAR2(30) := 'Get_Agreement_Name';
4009 l_api_version_number CONSTANT NUMBER := 1.0;
4010
4011 CURSOR get_pl_agreement_name_csr(pc_agreement_id NUMBER)
4012 IS
4013 SELECT name
4014 FROM qp_list_headers_vl
4015 WHERE list_header_id = pc_agreement_id
4016 AND list_type_code = 'PRL';
4017
4018 CURSOR get_spo_agreement_name_csr(pc_agreement_id NUMBER)
4019 IS
4020 SELECT agreement_number
4021 FROM ozf_request_headers_all_b
4022 WHERE request_header_id = pc_agreement_id;
4023
4024 BEGIN
4025 x_return_status := FND_API.G_RET_STS_SUCCESS;
4026 x_agreement_name := NULL;
4027
4028 -- Debug Message
4029 IF OZF_DEBUG_HIGH_ON THEN
4030 OZF_UTILITY_PVT.debug_message(l_api_name||': Start');
4031 END IF;
4032
4033 -- ??? What to do if no name is found.
4034 IF p_type = 'PL' THEN
4035 OPEN get_pl_agreement_name_csr (p_agreement_id);
4036 FETCH get_pl_agreement_name_csr INTO x_agreement_name;
4037 CLOSE get_pl_agreement_name_csr;
4038 ELSIF p_type = 'SPO' THEN
4039 OPEN get_spo_agreement_name_csr (p_agreement_id);
4040 FETCH get_spo_agreement_name_csr INTO x_agreement_name;
4041 CLOSE get_spo_agreement_name_csr;
4042 END IF;
4043
4044 EXCEPTION
4045 WHEN FND_API.G_EXC_ERROR THEN
4046 x_return_status := FND_API.G_RET_STS_ERROR;
4047 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
4048 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4049 WHEN OTHERS THEN
4050 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4051 IF OZF_UNEXP_ERROR THEN
4052 FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
4053 END IF;
4054 END Get_Agreement_Name;
4055
4056
4057 ---------------------------------------------------------------------
4058 -- PROCEDURE
4059 -- Agreement_Default
4060 --
4061 -- PURPOSE
4062 -- This procedure assigns values for agreement related columns. We are not
4063 -- considering update from WEBADI at this point as most of the other columns.
4064 -- We need to come up with a strategy to deal with this issue for all the columns.
4065 -- Notice there is no way AGREEMENT_NAME exists without agreement_id.
4066 --
4067 -- PARAMETERS
4068 --
4069 --
4070 -- NOTES
4071 ---------------------------------------------------------------------
4072 PROCEDURE Agreement_Default
4073 (
4074 p_party_id IN NUMBER,
4075 p_cust_account_id IN NUMBER,
4076 p_batch_type IN VARCHAR2,
4077 p_interface_line_id_tbl IN NUMBER_TABLE,
4078 p_ext_agreement_name IN VARCHAR2_TABLE,
4079 p_ext_agreement_type IN VARCHAR2_TABLE,
4080 px_int_agreement_name IN OUT NOCOPY VARCHAR2_TABLE,
4081 px_int_agreement_type IN OUT NOCOPY VARCHAR2_TABLE,
4082 px_agreement_id IN OUT NOCOPY NUMBER_TABLE,
4083 px_corrected_agreement_id IN OUT NOCOPY NUMBER_TABLE,
4084 px_corrected_agreement_name IN OUT NOCOPY VARCHAR2_TABLE,
4085 px_status_tbl IN OUT NOCOPY VARCHAR2_TABLE,
4086 px_dispute_code_tbl IN OUT NOCOPY VARCHAR2_TABLE,
4087 p_resale_transfer_type IN VARCHAR2_TABLE,
4088 x_return_status OUT NOCOPY VARCHAR2,
4089 x_msg_count OUT NOCOPY NUMBER,
4090 x_msg_data OUT NOCOPY VARCHAR2
4091 )
4092 IS
4093 l_api_name CONSTANT VARCHAR2(30) := 'Agreement_Default';
4094 l_api_version_number CONSTANT NUMBER := 1.0;
4095
4096 l_agreement_id_str VARCHAR2(200);
4097
4098 CURSOR get_spo_agreement_csr (pc_agreement_name VARCHAR2)
4099 IS
4100 SELECT request_header_id
4101 FROM ozf_request_headers_all_b
4102 WHERE agreement_number = pc_agreement_name;
4103
4104 /*
4105
4106 CURSOR chk_pl_agreement ( pc_agreement_id NUMBER )
4107 IS
4108 SELECT 'X'
4109 FROM qp_list_headers_vl
4110 WHERE list_header_id = pc_agreement_id
4111 AND list_type_code = 'PRL';
4112
4113 CURSOR chk_spo_agreement ( pc_agreement_id NUMBER )
4114 IS
4115 SELECT 'X'
4116 FROM ozf_request_headers_all_b
4117 WHERE request_header_id = pc_agreement_id;
4118 */
4119
4120 -- [BEGINN OF BUG FIXING: Agreement is null]
4121 CURSOR get_pl_agreement_id(pc_agreement_name VARCHAR2)
4122 IS
4123 SELECT list_header_id
4124 FROM qp_list_headers_vl
4125 WHERE name = pc_agreement_name
4126 AND list_type_code = 'PRL';
4127 --*/
4128 -- [END OF BUG FIXING: Agreement is null]
4129
4130 -- [BEGIN OF BUG 4237990 FIXING]
4131 CURSOR get_spo_agreement_id(cv_agreement_name VARCHAR) IS
4132 SELECT a.request_header_id
4133 FROM ozf_request_headers_all_b a
4134 , qp_list_headers_vl b
4135 WHERE a.offer_id = b.list_header_id
4136 AND a.status_code = 'APPROVED'
4137 AND b.name = cv_agreement_name;
4138 -- [END OF BUG 4237990 FIXING]
4139
4140 BEGIN
4141 IF OZF_DEBUG_HIGH_ON THEN
4142 ozf_utility_pvt.debug_message('Private API: ' || l_api_name || ' start');
4143 END IF;
4144
4145 x_return_status := FND_API.G_RET_STS_SUCCESS;
4146
4147 IF px_int_agreement_type.COUNT > 0 AND
4148 px_int_agreement_type.EXISTS(1) THEN
4149 FOR i IN 1 .. px_int_agreement_type.COUNT LOOP
4150 IF px_int_agreement_type(i) IS NULL THEN
4151 IF p_ext_agreement_type(i) IS NULL AND
4152 ( px_int_agreement_name(i) IS NOT NULL OR
4153 px_agreement_id(i) IS NOT NULL ) THEN
4154 IF p_batch_type = 'CHARGEBACK' THEN
4155 px_int_agreement_type(i) := 'PL';
4156 ELSIF p_batch_type = 'SHIP_DEBIT' THEN
4157 px_int_agreement_type(i) := 'SPO';
4158 END IF; -- p_batch_type
4159 ELSE
4160 px_int_agreement_type(i) := p_ext_agreement_type(i) ;
4161 END IF; -- p_ext_agreement_type(i)
4162 END IF; -- px_int_agreement_type(i) IS NULL
4163
4164 IF px_int_agreement_type(i) IS NOT NULL AND
4165 px_int_agreement_type(i) NOT IN ( G_SPECIAL_PRICE, G_PRICE_LIST ) THEN
4166 IF px_status_tbl(i) <> 'DISPUTED' THEN
4167 px_status_tbl(i) := 'DISPUTED';
4168 px_dispute_code_tbl(i) := 'OZF_INVALID_AGREEMENT_TYPE';
4169 END IF;
4170 Insert_Resale_Log(
4171 p_id_value => p_interface_line_id_tbl(i),
4172 p_id_type => 'IFACE',
4173 p_error_code => 'OZF_INVALID_AGREEMENT_TYPE',
4174 p_column_name => 'AGREEMENT_TYPE',
4175 p_column_value => px_int_agreement_type(i),
4176 x_return_status => x_return_status
4177 );
4178 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
4179 RAISE FND_API.G_EXC_ERROR;
4180 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4181 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4182 END IF;
4183 ELSIF px_int_agreement_type(i) = G_SPECIAL_PRICE THEN
4184 IF p_ext_agreement_name.EXISTS(i) AND
4185 p_ext_agreement_name(i) IS NOT NULL AND
4186 px_int_agreement_name(i) IS NULL THEN -- bug 5331553
4187 px_int_agreement_name(i):= p_ext_agreement_name(i);
4188 END IF;
4189 END IF; -- px_int_agreement_type(i) NOT IN
4190
4191 IF px_corrected_agreement_id(i) IS NOT NULL THEN
4192 IF px_corrected_agreement_name(i) IS NOT NULL THEN
4193 NULL;
4194 ELSE
4195 -- popluate the px_int_agreement_name(i);
4196 Get_Agreement_Name(
4197 p_type => px_int_agreement_type(i),
4198 p_agreement_id => px_corrected_agreement_id(i),
4199 x_agreement_name => px_corrected_agreement_name(i),
4200 x_return_status => x_return_status
4201 );
4202 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
4203 RAISE FND_API.G_EXC_ERROR;
4204 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4205 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4206 END IF;
4207 END IF;
4208 ELSE --px_corrected_agreement_id(i) is NULL
4209
4210 IF px_agreement_id(i) IS NOT NULL THEN
4211 IF px_int_agreement_name(i) IS NOT NULL THEN
4212 NULL;
4213 ELSE
4214 -- popluate the px_int_agreement_name(i);
4215 Get_Agreement_Name(
4216 p_type => px_int_agreement_type(i),
4217 p_agreement_id => px_agreement_id(i),
4218 x_agreement_name => px_int_agreement_name(i),
4219 x_return_status => x_return_status
4220 );
4221 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
4222 RAISE FND_API.G_EXC_ERROR;
4223 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4224 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4225 END IF;
4226 END IF;
4227 -- assign values to corrected_agreement
4228 px_corrected_agreement_id(i) := px_agreement_id(i);
4229 px_corrected_agreement_name(i) := px_int_agreement_name(i);
4230 ELSE -- px_agreement_id(i) is NULL
4231 -- Where there is no internal agreement id,
4232 -- then we need to check the external agreement
4233 IF px_int_agreement_type(i) IS NOT NULL AND
4234 px_int_agreement_name(i) IS NOT NULL THEN
4235 IF px_int_agreement_type(i) = 'PL' THEN
4236 OPEN get_pl_agreement_id(px_int_agreement_name(i));
4237 FETCH get_pl_agreement_id INTO px_agreement_id(i);
4238 CLOSE get_pl_agreement_id;
4239 ELSIF px_int_agreement_type(i) = 'SPO' THEN
4240 OPEN get_spo_agreement_id(px_int_agreement_name(i));
4241 FETCH get_spo_agreement_id INTO px_agreement_id(i);
4242 CLOSE get_spo_agreement_id;
4243 END IF;
4244 px_corrected_agreement_id(i) := px_agreement_id(i);
4245 px_corrected_agreement_name(i) := px_int_agreement_name(i);
4246 END IF;
4247
4248 IF px_int_agreement_name(i) IS NULL AND
4249 px_corrected_agreement_id(i) IS NULL AND
4250 px_corrected_agreement_name(i) IS NULL AND
4251 p_ext_agreement_name(i) IS NOT NULL THEN
4252 -- convert external code to internal code
4253 -- get agreement_id based on agreement_type
4254 IF px_int_agreement_type(i) = 'PL' THEN
4255 OZF_CODE_CONVERSION_PVT.Convert_Code(
4256 p_cust_account_id => p_cust_account_id,
4257 p_party_id => p_party_id,
4258 p_code_conversion_type => 'OZF_AGREEMENT_CODES',
4259 p_external_code => p_ext_agreement_name(i),
4260 x_internal_code => l_agreement_id_str,
4261 x_return_status => x_return_status,
4262 x_msg_count => x_msg_count,
4263 x_msg_data => x_msg_data
4264 );
4265 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
4266 RAISE FND_API.G_EXC_ERROR;
4267 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4268 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4269 END IF;
4270 px_agreement_id(i) := TO_NUMBER(l_agreement_id_str);
4271 ELSIF px_int_agreement_type(i) = 'SPO' THEN
4272 -- get id
4273 OPEN get_spo_agreement_csr(p_ext_agreement_name(i));
4274 FETCH get_spo_agreement_csr INTO px_agreement_id(i);
4275 CLOSE get_spo_agreement_csr;
4276 -- ????? What to do if no id is found.
4277 END IF;
4278 -- popluate the px_int_agreement_name(i) in both case
4279 Get_Agreement_Name(
4280 p_type => px_int_agreement_type(i),
4281 p_agreement_id => px_agreement_id(i),
4282 x_agreement_name => px_int_agreement_name(i),
4283 x_return_status => x_return_status
4284 );
4285 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
4286 RAISE FND_API.G_EXC_ERROR;
4287 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4288 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4289 END IF;
4290
4291 px_corrected_agreement_id(i) := px_agreement_id(i);
4292 px_corrected_agreement_name(i) := px_int_agreement_name(i);
4293 END IF;
4294 END IF;
4295 END IF;
4296
4297 IF px_corrected_agreement_id(i) IS NULL THEN
4298 -- FINISAR mandatory agreement fix
4299 -- TRACING and SHIP_DEBIT/stock sale don't need agreement
4300 -- Third party accrual batch doesn't need agreement
4301 IF p_batch_type = 'TRACING' THEN
4302 NULL;
4303 ELSIF p_batch_type = 'SHIP_DEBIT' AND p_resale_transfer_type(i) = g_tsfr_stock_sale THEN
4304 NULL;
4305 ELSIF p_batch_type = 'SHIP_DEBIT' AND p_resale_transfer_type(i) = g_tsfr_return THEN
4306 NULL;
4307 ELSIF p_batch_type = 'TP_ACCRUAL' THEN
4308 NULL;
4309 ELSE
4310 IF px_status_tbl(i) <> 'DISPUTED' THEN
4311 px_status_tbl(i) := 'DISPUTED';
4312 px_dispute_code_tbl(i) := 'OZF_AGREEMENT_MISS';
4313 Insert_Resale_Log(
4314 p_id_value => p_interface_line_id_tbl(i),
4315 p_id_type => 'IFACE',
4316 p_error_code => 'OZF_AGREEMENT_MISS',
4317 p_column_name => 'AGREEMENT_NAME',
4318 p_column_value => NULL,
4319 x_return_status => x_return_status
4320 );
4321 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
4322 RAISE FND_API.G_EXC_ERROR;
4323 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4324 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4325 END IF;
4326 END IF;
4327 END IF;
4328 END IF;
4329
4330 END LOOP;
4331 END IF; -- px_int_agreement_type.COUNT > 0
4332 -- Debug Message
4333 IF OZF_DEBUG_HIGH_ON THEN
4334 ozf_utility_pvt.debug_message('Private API: ' || l_api_name || ' end');
4335 END IF;
4336 -- Standard call to get message count and if count is 1, get message info.
4337 FND_MSG_PUB.Count_And_Get
4338 (p_count => x_msg_count,
4339 p_data => x_msg_data
4340 );
4341
4342 EXCEPTION
4343 WHEN FND_API.G_EXC_ERROR THEN
4344 x_return_status := FND_API.G_RET_STS_ERROR;
4345 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
4346 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4347 WHEN OTHERS THEN
4348 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4349 IF OZF_UNEXP_ERROR THEN
4350 FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
4351 END IF;
4352
4353 END Agreement_Default;
4354
4355
4356 PROCEDURE Product_validations
4357 (
4358 p_party_id IN VARCHAR2,
4359 p_cust_account_id IN VARCHAR2,
4360 p_interface_line_id_tbl IN NUMBER_TABLE,
4361 p_ext_item_number_tbl IN VARCHAR2_TABLE,
4362 p_item_number_tbl IN VARCHAR2_TABLE,
4363 px_item_id_tbl IN OUT NOCOPY NUMBER_TABLE,
4364 px_status_tbl IN OUT NOCOPY VARCHAR2_TABLE,
4365 px_dispute_code_tbl IN OUT NOCOPY VARCHAR2_TABLE,
4366 x_return_status OUT NOCOPY VARCHAR2,
4367 x_msg_count OUT NOCOPY NUMBER,
4368 x_msg_data OUT NOCOPY VARCHAR2
4369 )
4370 IS
4371 l_api_name CONSTANT VARCHAR2(30) := 'product_validations';
4372 l_api_version_number CONSTANT NUMBER := 1.0;
4373
4374 l_item_number_tbl VARCHAR2_TABLE;
4375 l_org_id NUMBER;
4376 l_mapping_flag VARCHAR2(1);
4377 l_check_flag VARCHAR2(1);
4378
4379 CURSOR get_inventory_item_id( pc_item_number IN VARCHAR2
4380 , pc_org_id IN NUMBER
4381 ) IS
4382 SELECT inventory_item_id
4383 FROM mtl_system_items_vl
4384 WHERE concatenated_segments = pc_item_number
4385 AND organization_id = pc_org_id;
4386
4387 CURSOR chk_inventory_item_id (pc_item_id IN NUMBER) IS
4388 SELECT 'X'
4389 FROM mtl_system_items
4390 WHERE inventory_item_id = pc_item_id;
4391
4392 BEGIN
4393 IF OZF_DEBUG_HIGH_ON THEN
4394 ozf_utility_pvt.debug_message('Private API: ' || l_api_name || ' start');
4395 END IF;
4396 x_return_status := FND_API.G_RET_STS_SUCCESS;
4397
4398 IF px_item_id_tbl.COUNT > 0 THEN
4399 FOR i IN 1 .. px_item_id_tbl.COUNT LOOP
4400 IF p_ext_item_number_tbl(i) IS NOT NULL AND
4401 p_item_number_tbl(i) IS NULL THEN -- bug 5331553
4402 l_mapping_flag := 'Y';
4403 EXIT;
4404 ELSE
4405 IF px_item_id_tbl(i) IS NOT NULL THEN
4406 l_mapping_flag := 'N';
4407 --exit;
4408 ELSIF p_item_number_tbl(i) IS NOT NULL THEN
4409 l_mapping_flag := 'N';
4410 --exit;
4411 END IF;
4412 END IF;
4413 END LOOP;
4414 END IF;
4415
4416 IF OZF_DEBUG_HIGH_ON THEN
4417 ozf_utility_pvt.debug_message('Mapping Flag ' || l_mapping_flag);
4418 END IF;
4419
4420 IF l_mapping_flag = 'Y' AND
4421 p_ext_item_number_tbl.COUNT > 0 THEN
4422 Code_Conversion(
4423 p_party_id => p_party_id,
4424 p_cust_account_id => p_cust_account_id ,
4425 p_mapping_type => 'OZF_PRODUCT_CODES',
4426 p_external_code_tbl => p_ext_item_number_tbl,
4427 x_internal_code_tbl => l_item_number_tbl,
4428 x_return_status => x_return_status,
4429 x_msg_count => x_msg_count,
4430 x_msg_data => x_msg_data
4431 );
4432 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
4433 RAISE FND_API.G_EXC_ERROR;
4434 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4435 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4436 END IF;
4437 END IF;
4438
4439 IF p_item_number_tbl.COUNT > 0 THEN
4440 FOR i IN 1..p_item_number_tbl.COUNT LOOP
4441 IF p_item_number_tbl(i) IS NOT NULL THEN
4442 l_org_id := G_ITEM_ORG_ID; --FND_PROFILE.value('AMS_ITEM_ORGANIZATION_ID');
4443 IF OZF_DEBUG_LOW_ON THEN
4444 ozf_utility_pvt.debug_message('p_item_number_tbl(i) ' || p_item_number_tbl(i));
4445 END IF;
4446 OPEN get_inventory_item_id(p_item_number_tbl(i),
4447 l_org_id);
4448 FETCH get_inventory_item_id INTO px_item_id_tbl(i);
4449 CLOSE get_inventory_item_id;
4450 IF OZF_DEBUG_LOW_ON THEN
4451 ozf_utility_pvt.debug_message('px_item_id_tbl(i) ' || px_item_id_tbl(i));
4452 END IF;
4453
4454 ELSIF px_item_id_tbl(i) IS NOT NULL THEN
4455 OPEN chk_inventory_item_id( px_item_id_tbl(i));
4456 FETCH chk_inventory_item_id INTO l_check_flag;
4457 CLOSE chk_inventory_item_id;
4458
4459 IF l_check_flag IS NULL THEN
4460 IF px_status_tbl(i) <> 'DISPUTED' THEN
4461 px_status_tbl(i) := 'DISPUTED';
4462 px_dispute_code_tbl(i) := 'OZF_RESALE_PRODUCT_NOT_IN_DB';
4463 END IF;
4464 Insert_Resale_Log(
4465 p_id_value => p_interface_line_id_tbl(i),
4466 p_id_type => 'IFACE',
4467 p_error_code => 'OZF_RESALE_PRODUCT_NOT_IN_DB',
4468 p_column_name => 'INVENTORY_ITEM_ID',
4469 p_column_value => p_ext_item_number_tbl(i),
4470 x_return_status => x_return_status
4471 );
4472 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
4473 RAISE FND_API.G_EXC_ERROR;
4474 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4475 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4476 END IF;
4477 END IF; -- l_check_flag IS NULL
4478
4479 ELSIF l_mapping_flag = 'Y' THEN
4480 IF l_item_number_tbl.EXISTS(i) AND
4481 l_item_number_tbl(i) IS NOT NULL THEN
4482 px_item_id_tbl(i) := TO_NUMBER(l_item_number_tbl(i));
4483 ELSIF p_item_number_tbl(i) IS NULL AND
4484 px_item_id_tbl(i) IS NULL AND
4485 l_item_number_tbl(i) IS NULL THEN
4486 IF px_status_tbl(i) <> 'DISPUTED' THEN
4487 px_status_tbl(i) := 'DISPUTED';
4488 px_dispute_code_tbl(i) := 'OZF_PRODUCT_CODE_MAP_MISS';
4489 END IF;
4490 Insert_Resale_Log(
4491 p_id_value => p_interface_line_id_tbl(i),
4492 p_id_type => 'IFACE',
4493 p_error_code => 'OZF_PRODUCT_CODE_MAP_MISS',
4494 p_column_name => 'INVENTORY_ITEM_ID',
4495 p_column_value => p_ext_item_number_tbl(i),
4496 x_return_status => x_return_status
4497 );
4498 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
4499 RAISE FND_API.G_EXC_ERROR;
4500 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4501 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4502 END IF;
4503 END IF;
4504 END IF; -- px_item_id_tbl(i) IS NOT NULL
4505
4506 IF px_item_id_tbl(i) IS NULL THEN
4507 IF px_status_tbl(i) <> 'DISPUTED' THEN
4508 px_status_tbl(i) := 'DISPUTED';
4509 px_dispute_code_tbl(i) := 'OZF_RESALE_PRODUCT_ID_MISS';
4510 END IF;
4511
4512 Insert_Resale_Log(
4513 p_id_value => p_interface_line_id_tbl(i),
4514 p_id_type => 'IFACE',
4515 p_error_code => 'OZF_RESALE_PRODUCT_ID_MISS',
4516 p_column_name => 'INVENTORY_ITEM_ID',
4517 p_column_value => p_item_number_tbl(i),
4518 x_return_status => x_return_status
4519 );
4520 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
4521 RAISE FND_API.G_EXC_ERROR;
4522 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4523 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4524 END IF;
4525 END IF; -- px_item_id_tbl(i) IS NULL
4526 END LOOP;
4527 END IF;
4528
4529 -- Debug Message
4530 IF OZF_DEBUG_HIGH_ON THEN
4531 ozf_utility_pvt.debug_message('Private API: ' || l_api_name || ': end');
4532 END IF;
4533
4534 -- Standard call to get message count and if count is 1, get message info.
4535 FND_MSG_PUB.Count_And_Get(
4536 p_count => x_msg_count,
4537 p_data => x_msg_data
4538 );
4539
4540 EXCEPTION
4541 WHEN FND_API.G_EXC_ERROR THEN
4542 x_return_status := FND_API.G_RET_STS_ERROR;
4543 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
4544 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4545 WHEN OTHERS THEN
4546 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4547 IF OZF_UNEXP_ERROR THEN
4548 FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
4549 END IF;
4550
4551 END Product_Validations;
4552
4553
4554 PROCEDURE UOM_Code_Mapping(
4555 p_party_id IN NUMBER,
4556 p_cust_account_id IN NUMBER,
4557 p_interface_line_id_tbl IN NUMBER_TABLE,
4558 p_ext_purchase_uom IN VARCHAR2_TABLE,
4559 p_ext_uom IN VARCHAR2_TABLE,
4560 p_ext_agreement_uom IN VARCHAR2_TABLE,
4561 px_int_purchase_uom IN OUT NOCOPY VARCHAR2_TABLE,
4562 px_int_uom IN OUT NOCOPY VARCHAR2_TABLE,
4563 px_int_agreement_uom IN OUT NOCOPY VARCHAR2_TABLE,
4564 px_status_tbl IN OUT NOCOPY VARCHAR2_TABLE,
4565 px_dispute_code_tbl IN OUT NOCOPY VARCHAR2_TABLE,
4566 x_return_status OUT NOCOPY VARCHAR2,
4567 x_msg_count OUT NOCOPY NUMBER,
4568 x_msg_data OUT NOCOPY VARCHAR2
4569 )
4570 IS
4571 l_api_name CONSTANT VARCHAR2(30) := 'UOM_Code_Mapping';
4572 l_api_version_number CONSTANT NUMBER := 1.0;
4573
4574 l_mapping_flag VARCHAR2(1);
4575 l_temp_code_tbl VARCHAR2_TABLE;
4576
4577 BEGIN
4578 IF OZF_DEBUG_HIGH_ON THEN
4579 ozf_utility_pvt.debug_message('Private API: ' || l_api_name || ': start');
4580 END IF;
4581 x_return_status := FND_API.G_RET_STS_SUCCESS;
4582
4583 l_mapping_flag := 'N';
4584 Mapping_Required(
4585 p_internal_code_tbl => px_int_purchase_uom
4586 , p_external_code_tbl => p_ext_purchase_uom
4587 , x_mapping_flag => l_mapping_flag
4588 );
4589 IF l_mapping_flag = 'Y' THEN
4590 Code_Conversion(
4591 p_party_id => p_party_id,
4592 p_cust_account_id => p_cust_account_id ,
4593 p_mapping_type => 'OZF_UOM_CODES',
4594 p_external_code_tbl => p_ext_purchase_uom,
4595 x_internal_code_tbl => l_temp_code_tbl,
4596 x_return_status => x_return_status,
4597 x_msg_count => x_msg_count,
4598 x_msg_data => x_msg_data
4599 );
4600 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
4601 RAISE FND_API.G_EXC_ERROR;
4602 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4603 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4604 END IF;
4605
4606 IF l_temp_code_tbl.EXISTS(1) THEN
4607 FOR i IN 1..l_temp_code_tbl.COUNT LOOP
4608 IF px_int_purchase_uom(i) IS NULL THEN
4609 IF l_temp_code_tbl(i) IS NULL THEN
4610 IF px_status_tbl(i) <> 'DISPUTED' THEN
4611 px_status_tbl(i) := 'DISPUTED';
4612 px_dispute_code_tbl(i) := 'OZF_UOM_CODE_MAP_MISS';
4613 END IF;
4614
4615 Insert_Resale_Log(
4616 p_id_value => p_interface_line_id_tbl(i),
4617 p_id_type => 'IFACE',
4618 p_error_code => 'OZF_UOM_CODE_MAP_MISS',
4619 p_column_name => 'PURCHASE_UOM',
4620 p_column_value => p_ext_purchase_uom(i),
4621 x_return_status => x_return_status
4622 );
4623 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
4624 RAISE FND_API.G_EXC_ERROR;
4625 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4626 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4627 END IF;
4628 ELSE
4629 px_int_purchase_uom(i) := l_temp_code_tbl(i);
4630 END IF;
4631 END IF;
4632 END LOOP;
4633 ELSE
4634 IF OZF_DEBUG_LOW_ON THEN
4635 ozf_utility_pvt.debug_message('External purchase uom might be null ');
4636 END IF;
4637 END IF;
4638 END IF;
4639
4640 l_temp_code_tbl.DELETE;
4641 l_mapping_flag := 'N';
4642 Mapping_Required(
4643 p_internal_code_tbl => px_int_uom
4644 , p_external_code_tbl => p_ext_uom
4645 , x_mapping_flag => l_mapping_flag
4646 );
4647 IF l_mapping_flag = 'Y' THEN
4648 Code_Conversion(
4649 p_party_id => p_party_id,
4650 p_cust_account_id => p_cust_account_id ,
4651 p_mapping_type => 'OZF_UOM_CODES',
4652 p_external_code_tbl => p_ext_uom,
4653 x_internal_code_tbl => l_temp_code_tbl,
4654 x_return_status => x_return_status,
4655 x_msg_count => x_msg_count,
4656 x_msg_data => x_msg_data
4657 );
4658 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
4659 RAISE FND_API.G_EXC_ERROR;
4660 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4661 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4662 END IF;
4663
4664 IF l_temp_code_tbl.EXISTS(1) THEN
4665 FOR i IN 1 .. l_temp_code_tbl.COUNT LOOP
4666 IF px_int_uom(i) IS NULL THEN
4667 IF l_temp_code_tbl(i) IS NULL THEN
4668 IF px_status_tbl(i) <> 'DISPUTED' THEN
4669 px_status_tbl(i) := 'DISPUTED';
4670 px_dispute_code_tbl(i) := 'OZF_UOM_CODE_MAP_MISS';
4671 END IF;
4672
4673 Insert_Resale_Log(
4674 p_id_value => p_interface_line_id_tbl(i),
4675 p_id_type => 'IFACE',
4676 p_error_code => 'OZF_UOM_CODE_MAP_MISS',
4677 p_column_name => 'UOM',
4678 p_column_value => p_ext_uom(i),
4679 x_return_status => x_return_status
4680 );
4681 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
4682 RAISE FND_API.G_EXC_ERROR;
4683 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4684 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4685 END IF;
4686 ELSE
4687 px_int_uom(i) := l_temp_code_tbl(i);
4688 END IF;
4689 END IF;
4690 END LOOP;
4691 ELSE
4692 IF OZF_DEBUG_HIGH_ON THEN
4693 ozf_utility_pvt.debug_message('External uom might be null ');
4694 END IF;
4695 END IF;
4696 END IF;
4697
4698 l_temp_code_tbl.DELETE;
4699 l_mapping_flag := 'N';
4700 Mapping_Required(
4701 p_internal_code_tbl => px_int_agreement_uom
4702 , p_external_code_tbl => p_ext_agreement_uom
4703 , x_mapping_flag => l_mapping_flag
4704 );
4705 IF l_mapping_flag = 'Y' THEN
4706 Code_Conversion(
4707 p_party_id => p_party_id,
4708 p_cust_account_id => p_cust_account_id ,
4709 p_mapping_type => 'OZF_UOM_CODES',
4710 p_external_code_tbl => p_ext_agreement_uom,
4711 x_internal_code_tbl => l_temp_code_tbl,
4712 x_return_status => x_return_status,
4713 x_msg_count => x_msg_count,
4714 x_msg_data => x_msg_data
4715 );
4716 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
4717 RAISE FND_API.G_EXC_ERROR;
4718 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4719 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4720 END IF;
4721
4722 IF l_temp_code_tbl.EXISTS(1) THEN
4723 FOR i IN 1 .. l_temp_code_tbl.COUNT LOOP
4724 IF px_int_agreement_uom(i) IS NULL THEN
4725 IF l_temp_code_tbl(i) IS NULL THEN
4726 IF px_status_tbl(i) <> 'DISPUTED' THEN
4727 px_status_tbl(i) := 'DISPUTED';
4728 px_dispute_code_tbl(i) := 'OZF_UOM_CODE_MAP_MISS';
4729 END IF;
4730
4731 Insert_Resale_Log(
4732 p_id_value => p_interface_line_id_tbl(i),
4733 p_id_type => 'IFACE',
4734 p_error_code => 'OZF_UOM_CODE_MAP_MISS',
4735 p_column_name => 'AGREEMENT_UOM',
4736 p_column_value => p_ext_agreement_uom(i),
4737 x_return_status => x_return_status
4738 );
4739 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
4740 RAISE FND_API.G_EXC_ERROR;
4741 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4742 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4743 END IF;
4744 ELSE
4745 px_int_agreement_uom(i) := l_temp_code_tbl(i);
4746 END IF;
4747 END IF;
4748 END LOOP;
4749 ELSE
4750 IF OZF_DEBUG_LOW_ON THEN
4751 ozf_utility_pvt.debug_message('External uom might be null ');
4752 END IF;
4753 END IF;
4754
4755 END IF;
4756 IF OZF_DEBUG_HIGH_ON THEN
4757 ozf_utility_pvt.debug_message('Private API: ' || l_api_name || ' end');
4758 END IF;
4759
4760 EXCEPTION
4761 WHEN FND_API.G_EXC_ERROR THEN
4762 x_return_status := FND_API.G_RET_STS_ERROR;
4763 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
4764 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4765 WHEN OTHERS THEN
4766 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4767 IF OZF_UNEXP_ERROR THEN
4768 FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
4769 END IF;
4770 END UOM_Code_Mapping;
4771
4772 PROCEDURE Party_Mapping
4773 (
4774 p_party_id IN NUMBER,
4775 p_cust_account_id IN NUMBER,
4776 p_party_type IN VARCHAR2,
4777 p_party_name_tbl IN OUT NOCOPY VARCHAR2_TABLE,
4778 p_location_tbl IN OUT NOCOPY VARCHAR2_TABLE,
4779 px_cust_account_id_tbl IN OUT NOCOPY NUMBER_TABLE,
4780 px_site_use_id_tbl IN OUT NOCOPY NUMBER_TABLE,
4781 px_party_id_tbl IN OUT NOCOPY NUMBER_TABLE,
4782 px_party_site_id_tbl IN OUT NOCOPY NUMBER_TABLE,
4783 x_return_status OUT NOCOPY VARCHAR2
4784 )
4785 IS
4786 l_api_name CONSTANT VARCHAR2(30) := 'Party_Mapping';
4787 l_api_version_number CONSTANT NUMBER := 1.0;
4788
4789 l_mapping_flag VARCHAR2(1);
4790 l_site_mapping_flag VARCHAR2(1);
4791
4792 l_msg_count NUMBER;
4793 l_msg_data VARCHAR2(2000);
4794
4795 l_party_tbl VARCHAR2_TABLE;
4796 l_party_site_tbl VARCHAR2_TABLE;
4797
4798 l_party_id NUMBER;
4799 l_cust_account_id NUMBER;
4800
4801 CURSOR get_account_id (pc_party_Id NUMBER)
4802 IS
4803 SELECT cust.cust_account_id
4804 FROM hz_cust_accounts cust
4805 WHERE cust.party_id = pc_party_Id;
4806
4807 CURSOR get_site_use_id ( pc_cust_account_id NUMBER
4808 , pc_site_use VARCHAR2 )
4809 IS
4810 SELECT hcsu.site_use_id
4811 FROM hz_cust_acct_sites hcs --hz_cust_acct_sites_all hcs
4812 , hz_cust_site_uses hcsu --, hz_cust_site_uses_all hcsu
4813 WHERE hcsu.cust_acct_site_id = hcs.cust_acct_site_id
4814 AND hcs.cust_account_id = pc_cust_account_id
4815 AND hcsu.site_use_code = pc_site_use
4816 AND hcsu.primary_flag= 'Y'
4817 AND hcsu.status = 'A';
4818
4819 /*
4820 SELECT hcsu.site_use_id , hp.party_id , hc.cust_account_id
4821 FROM hz_cust_acct_sites hcs --hz_cust_acct_sites_all hcs
4822 , hz_cust_site_uses hcsu --, hz_cust_site_uses_all hcsu
4823 , hz_party_sites hps
4824 , hz_parties hp
4825 , hz_cust_accounts hc
4826 WHERE hcsu.cust_acct_site_id = hcs.cust_acct_site_id
4827 AND hcs.party_site_id = hps.party_site_id
4828 AND hps.party_id = hp.party_id
4829 AND hcs.cust_account_id = hc.cust_account_id
4830 AND hc.party_id = hp.party_id
4831 AND hcsu.site_use_code = pc_site_use
4832 AND hps.party_site_id = pc_party_site_id;
4833 */
4834
4835 CURSOR get_party_acc_id (cv_party_site_id IN NUMBER) IS
4836 SELECT hp.party_id , hc.cust_account_id
4837 FROM hz_party_sites hps
4838 , hz_parties hp
4839 , hz_cust_accounts hc
4840 WHERE hps.party_id = hp.party_id
4841 AND hp.party_id = hc.party_id (+)
4842 AND hps.party_site_id = cv_party_site_id;
4843
4844 BEGIN
4845 IF OZF_DEBUG_HIGH_ON THEN
4846 ozf_utility_pvt.debug_message('Private API: ' || l_api_name || ' start');
4847 END IF;
4848 x_return_status := FND_API.G_RET_STS_SUCCESS;
4849
4850 -- -----------
4851 -- Party Site
4852 -- -----------
4853 IF OZF_DEBUG_LOW_ON THEN
4854 ozf_utility_pvt.debug_message('+++ Party Site Mapping +++');
4855 FOR i IN 1 .. px_site_use_id_tbl.COUNT LOOP
4856 ozf_utility_pvt.debug_message('px_site_use_id_tbl('||i||')='||px_site_use_id_tbl(i));
4857 ozf_utility_pvt.debug_message('px_party_site_id_tbl('||i||')='||px_party_site_id_tbl(i));
4858 ozf_utility_pvt.debug_message('p_location_tbl('||i||')='||p_location_tbl(i));
4859 END LOOP;
4860 END IF;
4861
4862 IF px_site_use_id_tbl.COUNT > 0 THEN
4863 l_site_mapping_flag := 'N';
4864 FOR i IN 1 .. px_site_use_id_tbl.COUNT
4865 LOOP
4866 IF px_site_use_id_tbl(i) IS NOT NULL THEN
4867 l_site_mapping_flag := 'N';
4868 --exit;
4869 ELSE
4870 IF px_party_site_id_tbl(i) IS NOT NULL THEN
4871 l_site_mapping_flag := 'N';
4872 --exit;
4873 ELSIF p_location_tbl(i) IS NOT NULL THEN
4874 l_site_mapping_flag := 'Y';
4875 exit;
4876 END IF;
4877 END IF;
4878 END LOOP;
4879 END IF;
4880 IF OZF_DEBUG_LOW_ON THEN
4881 ozf_utility_pvt.debug_message('PARTY SITE Code Mapping Flag ' || l_site_mapping_flag);
4882 ENd IF;
4883 IF l_site_mapping_flag = 'Y' AND p_location_tbl.COUNT > 0 THEN
4884
4885 code_conversion
4886 (
4887 p_party_id => p_party_id,
4888 p_cust_account_id => p_cust_account_id ,
4889 p_mapping_type => 'OZF_PARTY_SITE_CODES',
4890 p_external_code_tbl => p_location_tbl,
4891 x_internal_code_tbl => l_party_site_tbl,
4892 x_return_status => x_return_status,
4893 x_msg_count => l_msg_count ,
4894 x_msg_data => l_msg_data
4895 );
4896 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
4897 RAISE FND_API.G_EXC_ERROR;
4898 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4899 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4900 END IF;
4901 IF l_party_site_tbl.COUNT > 0 THEN
4902 FOR i IN 1 .. l_party_site_tbl.COUNT
4903 LOOP
4904 IF OZF_DEBUG_LOW_ON THEN
4905 ozf_utility_pvt.debug_message('l_party_site_tbl('||i||')='||l_party_site_tbl(i));
4906 END IF;
4907
4908 IF l_party_site_tbl.exists(i) AND l_party_site_tbl(i) IS NOT NULL THEN
4909
4910 px_party_site_id_tbl(i) := to_number(l_party_site_tbl(i));
4911
4912 OPEN get_party_acc_id(px_party_site_id_tbl(i));
4913 FETCH get_party_acc_id INTO l_party_id, l_cust_account_id;
4914 CLOSE get_party_acc_id;
4915
4916 IF px_cust_account_id_tbl(i) IS NULL THEN
4917 px_cust_account_id_tbl(i) := l_cust_account_id;
4918 END IF;
4919
4920 IF px_party_id_tbl(i) IS NULL THEN
4921 px_party_id_tbl(i) := l_party_id;
4922 END IF;
4923
4924 IF l_cust_account_id IS NOT NULL THEN
4925 OPEN get_site_use_id ( l_cust_account_id, p_party_type);
4926 FETCH get_site_use_id INTO px_site_use_id_tbl(i);
4927 CLOSE get_site_use_id;
4928 END IF;
4929 END IF;
4930 END LOOP;
4931 END IF;
4932 END IF; -- l_site_mapping_flag = 'Y'
4933
4934 -- ------
4935 -- Party
4936 -- ------
4937 IF OZF_DEBUG_LOW_ON THEN
4938 ozf_utility_pvt.debug_message('+++ Party Mapping +++');
4939 FOR i IN 1 .. px_cust_account_id_tbl.COUNT LOOP
4940 ozf_utility_pvt.debug_message('px_cust_account_id_tbl('||i||')='||px_cust_account_id_tbl(i));
4941 ozf_utility_pvt.debug_message('px_party_id_tbl('||i||')='||px_party_id_tbl(i));
4942 ozf_utility_pvt.debug_message('p_party_name_tbl('||i||')='||p_party_name_tbl(i));
4943 END LOOP;
4944 END IF;
4945
4946 IF px_cust_account_id_tbl.COUNT > 0 THEN
4947 l_mapping_flag := 'N';
4948 FOR i IN 1 .. px_cust_account_id_tbl.COUNT
4949 LOOP
4950 IF px_cust_account_id_tbl(i) IS NOT NULL THEN
4951 l_mapping_flag := 'N';
4952 --exit;
4953 ELSE
4954 IF px_party_id_tbl(i) IS NOT NULL THEN
4955 l_mapping_flag := 'N';
4956 --exit;
4957 ELSIF p_party_name_tbl(i) IS NOT NULL THEN
4958 l_mapping_flag := 'Y';
4959 exit;
4960 END IF;
4961 END IF;
4962 END LOOP;
4963 END IF;
4964 IF OZF_DEBUG_LOW_ON THEN
4965 ozf_utility_pvt.debug_message('PARTY Code Mapping Flag ' || l_mapping_flag);
4966 END IF;
4967 IF l_mapping_flag = 'Y' AND p_party_name_tbl.COUNT > 0 THEN
4968 code_conversion
4969 (
4970 p_party_id => p_party_id,
4971 p_cust_account_id => p_cust_account_id ,
4972 p_mapping_type => 'OZF_PARTY_CODES',
4973 p_external_code_tbl => p_party_name_tbl,
4974 x_internal_code_tbl => l_party_tbl,
4975 x_return_status => x_return_status,
4976 x_msg_count => l_msg_count ,
4977 x_msg_data => l_msg_data
4978 );
4979 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
4980 RAISE FND_API.G_EXC_ERROR;
4981 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4985 IF l_party_tbl.COUNT > 0 THEN
4982 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4983 END IF;
4984
4986 FOR i IN 1 .. l_party_tbl.COUNT
4987 LOOP
4988 IF OZF_DEBUG_LOW_ON THEN
4989 ozf_utility_pvt.debug_message('l_party_tbl('||i||')='||l_party_tbl(i));
4990 END IF;
4991
4992 IF l_party_tbl.EXISTS(i) AND l_party_tbl(i) IS NOT NULL THEN
4993
4994 px_party_id_tbl(i) := to_number(l_party_tbl(i));
4995
4996 OPEN get_account_id ( px_party_id_tbl(i)) ;
4997 FETCH get_account_id INTO px_cust_account_id_tbl(i);
4998 CLOSE get_account_id;
4999 END IF;
5000 END LOOP;
5001 END IF;
5002
5003 END IF;
5004 IF OZF_DEBUG_HIGH_ON THEN
5005 ozf_utility_pvt.debug_message('Private API: ' || l_api_name || ' end');
5006 END IF;
5007 EXCEPTION
5008 WHEN FND_API.G_EXC_ERROR THEN
5009 x_return_status := FND_API.G_RET_STS_ERROR;
5010 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
5011 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5012 WHEN OTHERS THEN
5013 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5014 IF OZF_UNEXP_ERROR THEN
5015 FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
5016 END IF;
5017 END Party_Mapping;
5018
5019
5020 PROCEDURE Party_Validations
5021 (
5022 p_resale_line_int_id IN NUMBER_TABLE,
5023 p_location IN VARCHAR2_TABLE,
5024 p_address IN VARCHAR2_TABLE,
5025 p_city IN VARCHAR2_TABLE,
5026 p_state IN VARCHAR2_TABLE,
5027 p_postal_code IN VARCHAR2_TABLE,
5028 p_country IN VARCHAR2_TABLE,
5029 p_contact_name IN VARCHAR2_TABLE,
5030 p_email IN VARCHAR2_TABLE,
5031 p_fax IN VARCHAR2_TABLE,
5032 p_phone IN VARCHAR2_TABLE,
5033 p_site_use_type IN VARCHAR2_TABLE,
5034 p_direct_customer_flag IN VARCHAR2_TABLE,
5035 p_party_type IN VARCHAR2,
5036 p_line_count IN NUMBER,
5037 px_party_name IN OUT NOCOPY VARCHAR2_TABLE,
5038 px_cust_account_id IN OUT NOCOPY NUMBER_TABLE,
5039 px_site_use_id IN OUT NOCOPY NUMBER_TABLE,
5040 px_party_id IN OUT NOCOPY NUMBER_TABLE,
5041 px_party_site_id IN OUT NOCOPY NUMBER_TABLE,
5042 px_contact_party_id IN OUT NOCOPY NUMBER_TABLE,
5043 px_status_code_tbl IN OUT NOCOPY VARCHAR2_TABLE,
5044 px_dispute_code_tbl IN OUT NOCOPY VARCHAR2_TABLE,
5045 x_return_status OUT NOCOPY VARCHAR2
5046 )
5047 IS
5048
5049 l_api_name CONSTANT VARCHAR2(30) := 'Party_Validations';
5050 l_api_version_number CONSTANT NUMBER := 1.0;
5051
5052 l_party_rec party_rec_type;
5053 l_party_site_rec party_site_rec_type;
5054 l_party_cntct_rec party_cntct_rec_type;
5055
5056 l_site_use_code VARCHAR2(100);
5057 l_dispute_code VARCHAR2(100) := NULL;
5058 l_run_dqm_flag VARCHAR2(1);
5059 l_site_id NUMBER := null;
5060 l_party_site_id NUMBER;
5061 l_dqm_party_rule VARCHAR2(50);
5062 l_dqm_party_site_rule VARCHAR2(50);
5063 l_dqm_contact_rule VARCHAR2(50);
5064 l_party_id NUMBER;
5065 l_rule_id NUMBER;
5066 l_search_context_id NUMBER;
5067 l_msg_count NUMBER;
5068 l_msg_data VARCHAR2(2000);
5069 l_num_matches NUMBER;
5070 l_org_contact_id NUMBER(15);
5071 l_contact_point_id NUMBER(15);
5072 l_creation_date DATE;
5073 l_score NUMBER;
5074 l_highest_score_cnt NUMBER := 0;
5075 l_party_contact_id NUMBER;
5076 l_party_number VARCHAR2(30);
5077 l_party_site_number VARCHAR2(30);
5078 l_chk_flag VARCHAR2(1);
5079 l_no_cust_account VARCHAR2(1) := 'N';
5080 l_cust_account_id NUMBER := null;
5081 l_no_loc_run_flag VARCHAR2(1);
5082
5083 l_acct_site_id NUMBER := null;
5084 l_p_party_id NUMBER := Null;
5085
5086 CURSOR get_party_id(pc_account_Id NUMBER) IS
5087 SELECT cust.party_id
5088 , pt.party_name
5089 FROM hz_cust_accounts cust, hz_parties pt
5090 WHERE cust_account_id = pc_account_Id
5091 AND cust.party_id = pt.party_id ;
5092
5093
5094
5095 CURSOR get_site_use_from_acct ( pc_account_id NUMBER
5096 , pc_location VARCHAR2
5097 , pc_site_use VARCHAR2 ) IS
5098 SELECT hcsu.site_use_id
5099 , hcas.party_site_id
5100 , hp.party_id
5101 FROM hz_cust_acct_sites hcas, --hz_cust_acct_sites_all hcas,
5102 hz_cust_site_uses hcsu, -- hz_cust_site_uses_all hcsu,
5103 hz_party_sites hps,
5104 hz_parties hp
5105 WHERE hcas.party_site_id = hps.party_site_id
5106 AND hcsu.cust_acct_site_id = hcas.cust_acct_site_id
5107 AND hps.party_id = hp.party_id
5108 AND hcas.cust_account_id = pc_account_id
5109 AND hcsu.location = pc_location
5110 AND hcsu.site_use_code = pc_site_use;
5111
5112 CURSOR get_site_from_acct ( pc_account_id NUMBER
5113 , pc_location VARCHAR2
5114 , pc_site_use VARCHAR2 ) IS
5115 SELECT hcas.cust_acct_site_id
5116 FROM hz_cust_acct_sites hcas, --hz_cust_acct_sites_all hcas,
5117 hz_cust_site_uses hcsu, --hz_cust_site_uses_all hcsu,
5118 hz_party_sites hps
5119 WHERE hcas.party_site_id = hps.party_site_id
5120 AND hcsu.cust_acct_site_id = hcas.cust_acct_site_id
5121 AND hcas.cust_account_id = pc_account_id
5122 AND hcsu.location = pc_location
5123 AND hcsu.site_use_code = pc_site_use;
5124
5125 CURSOR get_acct_from_site_use ( pc_site_use_id NUMBER ) IS
5126 SELECT hcas.cust_account_id
5127 , hps.party_site_id
5128 , hp.party_id
5129 , hp.party_name
5130 FROM hz_cust_acct_sites hcas, --hz_cust_acct_sites_all hcas,
5131 hz_cust_site_uses hcsu, --hz_cust_site_uses_all hcsu,
5132 hz_party_sites hps,
5133 hz_parties hp
5134 WHERE hcas.party_site_id = hps.party_site_id
5135 AND hcsu.cust_acct_site_id = hcas.cust_acct_site_id
5136 AND hps.party_id = hp.party_id
5137 AND hcsu.site_use_id = pc_site_use_id;
5138
5139 CURSOR get_acct_from_site ( pc_site_id NUMBER ) IS
5140 SELECT hcas.cust_account_id
5141 , hp.party_id
5142 , hp.party_name
5143 FROM hz_cust_acct_sites_all hcas,
5144 hz_party_sites hps,
5145 hz_parties hp
5146 WHERE hcas.party_site_id = hps.party_site_id
5147 AND hps.party_id = hp.party_id
5148 AND hcas.cust_acct_site_id = pc_site_id;
5149
5150 CURSOR get_party_site_id ( pc_site_use_id NUMBER ) IS
5151 SELECT hps.party_site_id
5152 FROM hz_cust_acct_sites hcas, --hz_cust_acct_sites_all hcas,
5153 hz_cust_site_uses hcsu, --hz_cust_site_uses_all hcsu,
5154 hz_party_sites hps
5155 WHERE hcas.party_site_id = hps.party_site_id
5156 AND hcsu.cust_acct_site_id = hcas.cust_acct_site_id
5157 AND hcsu.cust_acct_site_id = pc_site_use_id
5158 UNION
5159 SELECT hps.party_site_id
5160 FROM hz_cust_acct_sites hcas, --hz_cust_acct_sites_all hcas,
5161 hz_cust_site_uses hcsu, --hz_cust_site_uses_all hcsu,
5162 hz_party_sites hps
5163 WHERE hcas.party_site_id = hps.party_site_id
5164 AND hcsu.cust_acct_site_id = hcas.cust_acct_site_id
5165 AND hcsu.site_use_id = pc_site_use_id;
5166
5167 CURSOR get_acct_site_info ( pc_address_id NUMBER ) IS
5168 SELECT hca.cust_account_id,
5169 hp.party_id,
5170 hcas.cust_acct_site_id,
5171 hp.party_name
5172 FROM hz_cust_accounts hca,
5173 hz_parties hp,
5174 hz_cust_acct_sites_all hcas,
5175 hz_party_sites hps
5176 WHERE hcas.party_site_id = hps.party_site_id
5177 AND hcas.cust_account_id = hca.cust_account_id
5178 AND hp.party_id = hca.party_id
5179 AND hps.party_site_id = pc_address_id;
5180
5181 CURSOR get_acct_site_use_info ( pc_address_id NUMBER,
5182 pc_site_use VARCHAR2 )IS
5183 SELECT hca.cust_account_id,
5184 hcsu.site_use_id,
5185 hp.party_id,
5186 hcas.party_site_id,
5187 hp.party_name
5188 FROM hz_cust_accounts hca,
5189 hz_parties hp,
5190 hz_cust_site_uses hcsu, --hz_cust_site_uses_all hcsu,
5191 hz_cust_acct_sites hcas, --hz_cust_acct_sites_all hcas,
5192 hz_party_sites hps,
5193 hz_locations hl
5194 WHERE hcsu.cust_acct_site_id = hcas.cust_acct_site_id
5195 AND hcas.party_site_id = hps.party_site_id
5196 AND hcsu.status = 'A'
5197 AND hps.location_id = hl.location_id
5198 AND hcas.cust_account_id = hca.cust_account_id
5199 AND hp.party_id = hca.party_id
5200 AND hps.party_site_id = pc_address_id
5201 AND hcsu.site_use_code = pc_site_use;
5202
5203 CURSOR get_party_from_location ( pc_location VARCHAR2
5204 , pc_site_use VARCHAR2
5205 , pc_party_name VARCHAR2 ) IS
5206 SELECT hca.cust_account_id,
5207 decode(p_party_type, 'SHIP_FROM',hcas.cust_acct_site_id,
5208 'SOLD_FROM',hcas.cust_acct_site_id,
5209 'BILL_TO', hcsu.site_use_id,
5210 'SHIP_TO', hcsu.site_use_id,
5211 'END_CUST', hcsu.site_use_id ) site_id,
5212 decode(p_party_type,'SHIP_FROM', NULL,
5213 'SOLD_FROM', NULL,
5214 hps.party_site_id) party_site_id,
5215 hp.party_id
5216 FROM hz_cust_accounts hca,
5217 hz_parties hp,
5218 hz_cust_site_uses hcsu, --hz_cust_site_uses_all hcsu,
5219 hz_cust_acct_sites hcas, --hz_cust_acct_sites_all hcas,
5220 hz_party_sites hps,
5221 hz_locations hl
5222 WHERE hcsu.cust_acct_site_id = hcas.cust_acct_site_id
5223 AND hcas.party_site_id = hps.party_site_id
5224 AND hcsu.status = 'A'
5225 AND hps.location_id = hl.location_id
5226 AND hcas.cust_account_id = hca.cust_account_id
5227 AND hp.party_id = hca.party_id
5228 AND hcsu.location = pc_location
5229 AND hcsu.site_use_code = pc_site_use
5230 AND hp.party_name = pc_party_name;
5231
5232
5233 CURSOR get_location_details ( pc_location VARCHAR2
5234 , pc_site_use VARCHAR2 ) IS
5235 SELECT hca.cust_account_id,
5236 decode('SHIP_FROM', 'SHIP_FROM',hcas.cust_acct_site_id,
5237 'SOLD_FROM',hcas.cust_acct_site_id,
5238 'BILL_TO', hcsu.site_use_id,
5239 'SHIP_TO', hcsu.site_use_id,
5240 'END_CUST', hcsu.site_use_id ) site_id,
5241 decode('SHIP_FROM','SHIP_FROM', NULL,
5242 'SOLD_FROM', NULL,
5243 hps.party_site_id) party_site_id,
5244 hp.party_id,
5245 hp.party_name
5246 FROM hz_cust_accounts hca,
5247 hz_parties hp,
5248 hz_cust_site_uses hcsu, --hz_cust_site_uses_all hcsu,
5249 hz_cust_acct_sites hcas, --hz_cust_acct_sites_all hcas,
5250 hz_party_sites hps
5251 WHERE hcsu.cust_acct_site_id = hcas.cust_acct_site_id
5252 AND hcas.party_site_id = hps.party_site_id
5253 AND hcsu.status = 'A'
5254 AND hps.status = 'A'
5255 AND hp.status = 'A'
5256 AND hcsu.primary_flag = 'Y'
5257 AND hcas.cust_account_id = hca.cust_account_id
5258 AND hp.party_id = hca.party_id
5259 AND hcsu.location = pc_location
5260 AND hcsu.site_use_code = pc_site_use;
5261
5262 CURSOR get_location ( pc_location VARCHAR2
5263 , pc_site_use VARCHAR2 ) IS
5264 SELECT hca.cust_account_id,
5265 decode('SHIP_FROM', 'SHIP_FROM',hcas.cust_acct_site_id,
5266 'SOLD_FROM',hcas.cust_acct_site_id,
5267 'BILL_TO', hcsu.site_use_id,
5268 'SHIP_TO', hcsu.site_use_id,
5269 'END_CUST', hcsu.site_use_id ) site_id,
5270 decode('SHIP_FROM','SHIP_FROM', NULL,
5271 'SOLD_FROM', NULL,
5272 hps.party_site_id) party_site_id,
5273 hp.party_id,
5274 hp.party_name
5275 FROM hz_cust_accounts hca,
5276 hz_parties hp,
5277 hz_cust_site_uses hcsu, --hz_cust_site_uses_all hcsu,
5278 hz_cust_acct_sites hcas, --hz_cust_acct_sites_all hcas,
5279 hz_party_sites hps
5280 WHERE hcsu.cust_acct_site_id = hcas.cust_acct_site_id
5281 AND hcas.party_site_id = hps.party_site_id
5282 AND hcsu.status = 'A'
5283 AND hps.status = 'A'
5284 AND hp.status = 'A'
5285 AND hcas.cust_account_id = hca.cust_account_id
5286 AND hp.party_id = hca.party_id
5287 AND hcsu.location = pc_location
5288 AND hcsu.site_use_code = pc_site_use;
5289
5290
5291 CURSOR get_acct_site_use_id ( pc_party_id NUMBER,
5292 pc_party_site_id NUMBER,
5293 pc_site_use_type VARCHAR2) IS
5294 SELECT hca.cust_account_id,
5295 decode(p_party_type, 'SHIP_FROM',hcas.cust_acct_site_id,
5296 'SOLD_FROM',hcas.cust_acct_site_id,
5297 hcsu.site_use_id) site_id,
5298 decode(p_party_type,'SHIP_FROM', NULL,
5299 'SOLD_FROM', NULL,
5300 hps.party_site_id) party_site_id,
5301 hp.party_id
5302 FROM hz_cust_accounts hca,
5303 hz_parties hp,
5304 hz_cust_site_uses hcsu, --hz_cust_site_uses_all hcsu,
5305 hz_cust_acct_sites hcas, --hz_cust_acct_sites_all hcas,
5306 hz_party_sites hps,
5307 hz_locations hl
5308 WHERE hcsu.cust_acct_site_id = hcas.cust_acct_site_id
5309 AND hcas.party_site_id = hps.party_site_id
5310 AND hcsu.status = 'A'
5311 AND hps.location_id = hl.location_id
5312 AND hcas.cust_account_id = hca.cust_account_id
5313 AND hp.party_id = hca.party_id
5314 AND hp.party_id = pc_party_id
5315 AND hps.party_site_id = pc_party_site_id
5316 AND hcsu.site_use_code = pc_site_use_type;
5317
5318 -- [BEGIN OF BUG 4186465 FIXING]
5319 CURSOR get_party_name(cv_party_id IN NUMBER) IS
5320 SELECT party_name
5321 FROM hz_parties
5322 WHERE party_id = cv_party_id;
5323 -- [END OF BUG 4186465 FIXING]
5324
5325 -- Bug 5201195 (+)
5326 CURSOR get_end_cust_location( cv_site_number IN VARCHAR2
5327 , cv_site_use_type IN VARCHAR2) IS
5328 SELECT NULL
5329 , use.party_site_use_id
5330 , site.party_site_id
5331 , party.party_id
5332 , party.party_name
5333 FROM hz_parties party
5334 , hz_party_sites site
5335 , hz_locations loc
5336 , hz_party_site_uses use
5337 WHERE site.location_id = loc.location_id
5338 AND party.party_id = site.party_id
5339 AND party.status = 'A'
5340 AND party.party_type = 'ORGANIZATION'
5341 AND site.party_site_id = use.party_site_id
5342 AND use.site_use_type = cv_site_use_type
5343 AND site.party_site_number = cv_site_number;
5344 -- Bug 5201195 (-)
5345
5346
5347 BEGIN
5348 IF OZF_DEBUG_HIGH_ON THEN
5349 ozf_utility_pvt.debug_message('Private API: ' || l_api_name || ' start');
5353 IF p_party_type IN ('BILL_TO', 'SHIP_TO') THEN
5350 END IF;
5351
5352 -- Site Use Code Defaulting
5354 l_site_use_code := p_party_type;
5355 ELSIF p_party_type = 'SOLD_FROM' THEN
5356 l_site_use_code := 'BILL_TO';
5357 ELSIF p_party_type = 'SHIP_FROM' THEN
5358 l_site_use_code := 'SHIP_TO';
5359 ELSIF p_party_type = 'END_CUST' THEN
5360 l_site_use_code := NULL;
5361 END IF;
5362
5363 IF OZF_DEBUG_LOW_ON THEN
5364 ozf_utility_pvt.debug_message('Line Count ' || p_line_count);
5365 END IF;
5366
5367 IF p_line_count > 0 THEN
5368
5369 FOR i IN 1 .. p_line_count
5370 LOOP
5371 IF OZF_DEBUG_LOW_ON THEN
5372 ozf_utility_pvt.debug_message('p_location('||i||') '||p_location(i) || ' for '||p_party_type);
5373 END IF;
5374 l_run_dqm_flag := NULL;
5375 l_cust_account_id := NULL;
5376 l_party_site_id := NULL;
5377 l_site_id := NULL;
5378
5379 IF p_party_type = 'END_CUST' THEN
5380 l_site_use_code := p_site_use_type(i);
5381 END IF;
5382 IF px_cust_account_id.exists(i) AND px_cust_account_id(i) IS NOT NULL THEN
5383
5384 IF OZF_DEBUG_LOW_ON THEN
5385 ozf_utility_pvt.debug_message('px_cust_account_id('||i||')'||px_cust_account_id(i));
5386 END IF;
5387 OPEN get_party_id (px_cust_account_id(i));
5388 FETCH get_party_id INTO l_party_rec.party_id,
5389 px_party_name(i);
5390
5391 IF get_party_id%NOTFOUND THEN
5392
5393 IF px_status_code_tbl(i) <> 'DISPUTED' THEN
5394 px_status_code_tbl(i) := 'DISPUTED';
5395 px_dispute_code_tbl(i) := 'OZF_CLAIM_CUST_NOT_IN_DB';
5396 END IF;
5397
5398 insert_resale_log
5399 (p_id_value => p_resale_line_int_id(i),
5400 p_id_type => 'IFACE',
5401 p_error_code => 'OZF_CLAIM_CUST_NOT_IN_DB',
5402 p_column_name => p_party_type||'_CUST_ACCOUNT_ID',
5403 p_column_value => px_cust_account_id(i),
5404 x_return_status => x_return_status);
5405
5406 ELSE
5407 l_party_rec.party_name := px_party_name(i);
5408 IF px_party_id.exists(i)AND px_party_id(i) IS NULL THEN
5409 px_party_id(i) := l_party_rec.party_id;
5410 END IF;
5411 IF px_site_use_id.exists(i) AND px_site_use_id(i) IS NULL THEN
5412 IF p_location(i) IS NOT NULL THEN
5413 IF p_party_type IN ('SHIP_FROM', 'SOLD_FROM') THEN
5414 OPEN get_site_from_acct (px_cust_account_id(i), p_location(i),l_site_use_code );
5415 FETCH get_site_from_acct INTO px_site_use_id(i);
5416 CLOSE get_site_from_acct;
5417 IF OZF_DEBUG_LOW_ON THEN
5418 ozf_utility_pvt.debug_message('getting ship from information ');
5419 ozf_utility_pvt.debug_message('px_site_use_id('||i||') '||px_site_use_id(i));
5420 END IF;
5421 ELSE
5422 IF px_party_site_id.exists(i) AND px_party_site_id(i) IS NOT NULL THEN
5423 IF OZF_DEBUG_LOW_ON THEN
5424 ozf_utility_pvt.debug_message('Site Use Information is not present for bill to and ship to ');
5425 END IF;
5426 ELSE
5427 OPEN get_site_use_from_acct (px_cust_account_id(i), p_location(i),l_site_use_code );
5428 FETCH get_site_use_from_acct INTO px_site_use_id(i) , px_party_site_id(i), px_party_id(i);
5429 CLOSE get_site_use_from_acct;
5430 END IF;
5431 END IF; -- p_party_type IN ('SHIP_FROM', 'SOLD_FROM')
5432 END IF; -- p_location(i) IS NOT NULL
5433 END IF; -- px_site_use_id.exists(i) AND px_site_use_id(i) IS NULL
5434 END IF; -- get_party_id%NOTFOUND
5435 CLOSE get_party_id;
5436
5437 ELSIF px_site_use_id.exists(i) AND px_site_use_id(i) IS NOT NULL THEN
5438 IF p_party_type IN ('SHIP_FROM', 'SOLD_FROM') THEN
5439 OPEN get_acct_from_site (px_site_use_id(i));
5440 FETCH get_acct_from_site INTO l_cust_account_id
5441 , l_party_rec.party_id
5442 , px_party_name(i);
5443 CLOSE get_acct_from_site;
5444 ELSE
5445
5446 OPEN get_acct_from_site_use (px_site_use_id(i));
5447 FETCH get_acct_from_site_use INTO l_cust_account_id
5448 , l_site_id
5449 , l_party_rec.party_id
5450 , px_party_name(i);
5451
5452 IF get_acct_from_site_use%NOTFOUND THEN
5453 IF p_party_type IN ('BILL_TO','SHIP_TO') THEN
5457 END IF;
5454 IF px_status_code_tbl(i) <> 'DISPUTED' THEN
5455 px_status_code_tbl(i) := 'DISPUTED';
5456 px_dispute_code_tbl(i) := 'OZF_CLAIM_'||p_party_type||'_ST_WRNG';
5458
5459 insert_resale_log
5460 (p_id_value => p_resale_line_int_id(i),
5461 p_id_type => 'IFACE',
5462 p_error_code => 'OZF_CLAIM_'||p_party_type||'_ST_WRNG',
5463 p_column_name => p_party_type||'_SITE_USE_ID',
5464 p_column_value => px_site_use_id(i),
5465 x_return_status => x_return_status);
5466 END IF;
5467 ELSE
5468 IF px_party_site_id.EXISTS(i) AND px_party_site_id(i) IS NULL THEN
5469 IF l_site_id IS NOT NULL THEN
5470 px_party_site_id(i) := l_site_id;
5471 END IF;
5472 END IF;
5473 END IF; -- get_acct_from_site_use%NOTFOUND
5474 CLOSE get_acct_from_site_use;
5475 IF OZF_DEBUG_LOW_ON THEN
5476 ozf_utility_pvt.debug_message('px_site_use_id('||i||') '||px_site_use_id(i));
5477 END IF;
5478 END IF;
5479 IF px_party_id.exists(i) AND px_party_id(i) IS NULL THEN
5480 px_party_id(i) := l_party_rec.party_id;
5481 END IF;
5482 IF px_cust_account_id.exists(i) AND px_cust_account_id(i) IS NULL THEN
5483 IF l_cust_account_id IS NOT NULL THEN
5484 px_cust_account_id(i) := l_cust_account_id;
5485 END IF;
5486 END IF;
5487 ELSIF p_location(i) IS NOT NULL THEN
5488 IF p_party_type IN ('BILL_TO', 'SHIP_TO') THEN
5489 IF px_party_site_id.exists(i) AND px_party_site_id(i) IS NULL THEN
5490 l_no_loc_run_flag := 'Y';
5491 END IF;
5492 ELSE
5493 l_no_loc_run_flag := 'Y';
5494 END IF;
5495 IF OZF_DEBUG_LOW_ON THEN
5496 ozf_utility_pvt.debug_message('Location ('||i||')' || p_location(i));
5497 END IF;
5498 IF l_no_loc_run_flag = 'Y' THEN
5499
5500 Get_party_site_from_ECX
5501 ( p_location => p_location(i),
5502 x_party_site_id => l_party_site_id,
5503 x_return_status => x_return_status
5504 );
5505 IF OZF_DEBUG_LOW_ON THEN
5506 ozf_utility_pvt.debug_message('Party Site ID from ECX API ' || l_party_site_id);
5507 END IF;
5508 IF l_party_site_id IS NOT NULL THEN
5509 IF p_party_type IN ('SHIP_FROM', 'SOLD_FROM') THEN
5510
5511 OPEN get_acct_site_info( l_party_site_id );
5512 FETCH get_acct_site_info
5513 INTO l_cust_account_id
5514 ,l_party_rec.party_id
5515 ,px_site_use_id(i)
5516 ,px_party_name(i);
5517 CLOSE get_acct_site_info;
5518 ELSE
5519
5520 OPEN get_acct_site_use_info( l_party_site_id
5521 ,p_party_type );
5522 FETCH get_acct_site_use_info
5523 INTO l_cust_account_id
5524 , px_site_use_id(i)
5525 , px_party_id(i)
5526 , px_party_site_id(i)
5527 , px_party_name(i);
5528 CLOSE get_acct_site_use_info;
5529 END IF; -- p_party_type IN ('SHIP_FROM', 'SOLD_FROM')
5530 IF l_cust_account_id IS NOT NULL THEN
5531 px_cust_account_id(i) := l_cust_account_id;
5532 END IF;
5533
5534 l_party_site_rec.party_site_id := l_party_site_id;
5535
5536 ELSE -- l_party_site_id IS NOT NULL
5537
5538 IF px_party_name.exists(i) AND
5539 px_party_name(i) IS NOT NULL AND
5540 -- Bug 4469837 (+)
5541 l_site_use_code IS NOT NULL THEN
5542 -- Bug 4469837 (-)
5543 OPEN get_party_from_location( p_location(i)
5544 , l_site_use_code
5545 , px_party_name(i) );
5546 FETCH get_party_from_location
5547 INTO l_cust_account_id
5548 , px_site_use_id(i)
5549 , px_party_site_id(i)
5550 , px_party_id(i);
5551 CLOSE get_party_from_location;
5552 IF px_cust_account_id(i) IS NULL THEN
5553 px_cust_account_id(i) := l_cust_account_id;
5554 END IF;
5555 IF OZF_DEBUG_LOW_ON THEN
5559 END IF;
5556 ozf_utility_pvt.debug_message('px_cust_account_id('||i||')'||px_cust_account_id(i));
5557 ozf_utility_pvt.debug_message('l_site_use_code ('||i||')'||l_site_use_code);
5558 ozf_utility_pvt.debug_message('px_site_use_id ('||i||')'||px_site_use_id(i));
5560 IF px_party_id.exists(i) AND px_party_id(i) IS NOT NULL THEN
5561 l_party_rec.party_id := px_party_id(i);
5562 END IF;
5563 -- To be commented
5564 -- Bug 4469837 (+)
5565 --ELSE
5566 -- Bug 4469837 (-)
5567 ELSIF l_site_use_code IS NOT NULL THEN
5568 -- Bug 5201195 (+)
5569 IF p_party_type = 'END_CUST' THEN
5570 OPEN get_end_cust_location( p_location(i)
5571 , l_site_use_code);
5572 FETCH get_end_cust_location INTO l_cust_account_id
5573 , px_site_use_id(i)
5574 , px_party_site_id(i)
5575 , px_party_id(i)
5576 , px_party_name(i);
5577 CLOSE get_end_cust_location;
5578 -- Bug 5201195 (-)
5579 ELSE
5580 OPEN get_location_details( p_location(i)
5581 , l_site_use_code);
5582
5583 FETCH get_location_details
5584 INTO l_cust_account_id
5585 , px_site_use_id(i)
5586 , px_party_site_id(i)
5587 , px_party_id(i)
5588 , px_party_name(i);
5589 CLOSE get_location_details;
5590 END IF;
5591
5592 IF OZF_DEBUG_LOW_ON THEN
5593 ozf_utility_pvt.debug_message('l_site_use_code '||l_site_use_code);
5594 ozf_utility_pvt.debug_message('p_location('||i||') '||p_location(i));
5595 END IF;
5596 IF l_cust_account_id IS NULL THEN
5597 OPEN get_location( p_location(i)
5598 , l_site_use_code
5599 );
5600 FETCH get_location
5601 INTO l_cust_account_id
5602 , px_site_use_id(i)
5603 , px_party_site_id(i)
5604 , px_party_id(i)
5605 , px_party_name(i);
5606 CLOSE get_location;
5607
5608 END IF;
5609
5610 IF px_cust_account_id.EXISTS(i) AND px_cust_account_id(i) IS NULL THEN
5611 px_cust_account_id(i) := l_cust_account_id;
5612 END IF;
5613 IF px_party_id.exists(i) AND px_party_id(i) IS NOT NULL THEN
5614 l_party_rec.party_id := px_party_id(i);
5615 END IF;
5616 --
5617 END IF;
5618 END IF; -- l_party_site_id IS NOT NULL
5619 END IF; -- -- l_no_loc_run_flag
5620 END IF; -- p_location(i) is null
5621 IF p_direct_customer_flag.exists(i) AND p_direct_customer_flag(i) = 'F' THEN
5622 IF p_party_type IN ('BILL_TO', 'SHIP_TO') THEN
5623 l_run_dqm_flag := 'N';
5624 END IF;
5625 END IF;
5626
5627 IF l_run_dqm_flag IS NULL OR l_run_dqm_flag = 'Y' THEN
5628 IF px_cust_account_id.exists(i) AND px_cust_account_id(i) IS NOT NULL THEN
5629 IF OZF_DEBUG_LOW_ON THEN
5630 ozf_utility_pvt.debug_message('px_cust_account_id('||i||')'||px_cust_account_id(i));
5631 END IF;
5632 IF px_party_id.exists(i) AND px_party_id(i) IS NULL THEN
5633 OPEN get_party_id (px_cust_account_id(i));
5634 FETCH get_party_id INTO l_party_rec.party_id,
5635 l_party_rec.party_name;
5636 CLOSE get_party_id;
5637 IF OZF_DEBUG_LOW_ON THEN
5638 ozf_utility_pvt.debug_message('l_party_rec.party_id '||l_party_rec.party_id);
5639 ozf_utility_pvt.debug_message('l_party_rec.party_name '||l_party_rec.party_name);
5640 END IF;
5641 END IF;
5642 ELSIF px_party_id.exists(i) AND px_party_id(i) IS NOT NULL THEN
5643 l_party_rec.party_id := px_party_id(i);
5644 -- [BEGIN OF BUG 4186465 FIXING]
5645 OPEN get_party_name(l_party_rec.party_id);
5646 FETCH get_party_name INTO px_party_name(i);
5647 CLOSE get_party_name;
5648 -- [END OF BUG 4186465 FIXING]
5649 ELSIF px_party_name(i) IS NOT NULL THEN
5650 IF OZF_DEBUG_LOW_ON THEN
5651 ozf_utility_pvt.debug_message('px_party_name('||i||') '||px_party_name(i));
5652 END IF;
5653 l_party_rec.party_id := NULL;
5657 l_party_site_rec.city := p_city(i);
5654 l_party_rec.party_name := px_party_name(i);
5655
5656 l_party_site_rec.address := p_address(i);
5658 l_party_site_rec.state := p_state(i);
5659 l_party_site_rec.postal_code := p_postal_code(i);
5660 l_party_site_rec.country := p_country(i);
5661 ELSE
5662 IF OZF_DEBUG_LOW_ON THEN
5663 ozf_utility_pvt.debug_message('party record is null ');
5664 ozf_utility_pvt.debug_message('px_party_name('||i||') for '||l_site_use_code||' '||px_party_name(i));
5665 END IF;
5666 l_party_rec.party_name := NULL;
5667 l_party_rec.party_id := NULL;
5668 END IF;
5669 IF OZF_DEBUG_LOW_ON THEN
5670 ozf_utility_pvt.debug_message('Address starting .......................');
5671 END IF;
5672 IF px_party_site_id.exists(i) AND px_party_site_id(i) IS NOT NULL THEN
5673 l_party_site_rec.party_site_id := px_party_site_id(i);
5674 IF OZF_DEBUG_LOW_ON THEN
5675 ozf_utility_pvt.debug_message('px_party_site_id('||i||') '||px_party_site_id(i));
5676 END IF;
5677 ELSIF px_site_use_id.exists(i) AND px_site_use_id(i) IS NOT NULL THEN
5678
5679
5680 OPEN get_party_site_id (px_site_use_id(i) );
5681 FETCH get_party_site_id INTO px_party_site_id(i);
5682 CLOSE get_party_site_id;
5683 IF px_party_site_id.exists(i) AND px_party_site_id(i) IS NOT NULL THEN
5684 l_party_site_rec.party_site_id := px_party_site_id(i);
5685 IF OZF_DEBUG_LOW_ON THEN
5686 ozf_utility_pvt.debug_message('px_party_site_id('||i||') '||px_party_site_id(i));
5687 END IF;
5688 ELSE
5689 px_party_site_id(i) := NULL;
5690 END IF;
5691 ELSIF p_address(i) IS NOT NULL THEN
5692 IF OZF_DEBUG_LOW_ON THEN
5693 ozf_utility_pvt.debug_message('p_address('||i||') '||p_address(i));
5694 END IF;
5695 l_party_site_rec.party_site_id := null;
5696 l_party_site_rec.address := p_address(i);
5697 l_party_site_rec.city := p_city(i);
5698 l_party_site_rec.state := p_state(i);
5699 l_party_site_rec.postal_code := p_postal_code(i);
5700 l_party_site_rec.country := p_country(i);
5701 ELSE
5702 IF OZF_DEBUG_LOW_ON THEN
5703 ozf_utility_pvt.debug_message('Address is null ');
5704 END IF;
5705 END IF;
5706
5707 IF px_contact_party_id.exists(i) AND px_contact_party_id(i) IS NULL THEN
5708 IF p_contact_name.exists(i) AND p_contact_name(i) IS NOT NULL THEN
5709
5710 l_party_cntct_rec.contact_name := p_contact_name(i);
5711 l_party_cntct_rec.party_email_id := p_email(i);
5712 l_party_cntct_rec.party_phone := p_phone(i);
5713 l_party_cntct_rec.party_fax := p_fax(i);
5714 END IF;
5715 END IF;
5716 END IF;
5717
5718 IF l_run_dqm_flag IS NULL AND l_party_rec.party_id IS NULL THEN
5719 IF l_party_rec.party_name IS NOT NULL THEN
5720 l_run_dqm_flag := 'Y';
5721 END IF;
5722 END IF;
5723
5724 IF l_run_dqm_flag IS NULL THEN
5725 IF l_party_rec.party_id IS NOT NULL THEN
5726 IF l_party_site_rec.address IS NOT NULL AND
5727 l_party_site_rec.party_site_id IS NULL AND
5728 -- Bug 4469837 (+)
5729 p_party_type IN ('BILL_TO', 'SHIP_TO', 'SOLD_FROM', 'SHIP_FROM') THEN
5730 -- Bug 4469837 (-)
5731 l_run_dqm_flag := 'Y';
5732 END IF;
5733 END IF;
5734 IF px_contact_party_id.exists(i) AND px_contact_party_id(i) IS NULL THEN
5735 IF l_party_rec.party_id IS NOT NULL
5736 AND p_contact_name.exists(i)
5737 AND p_contact_name(i) IS NOT NULL THEN
5738 l_run_dqm_flag := 'Y';
5739 END IF;
5740 END IF; -- px_contact_party_id(i) IS NULL
5741
5742 END IF;
5743
5744
5745 IF l_run_dqm_flag = 'Y' THEN
5746
5747 l_dqm_party_rule := G_DQM_PARTY_RULE; --fnd_profile.value('OZF_RESALE_PARTY_DQM_RULE');
5748 l_dqm_party_site_rule := G_DQM_PARTY_SITE_RULE; --fnd_profile.value('OZF_RESALE_PARTY_SITE_DQM_RULE');
5749 l_dqm_contact_rule := G_DQM_CONTACT_RULE; --fnd_profile.value('OZF_RESALE_CONTACT_DQM_RULE');
5750
5751 IF OZF_DEBUG_LOW_ON THEN
5752 ozf_utility_pvt.debug_message( 'Party DQM Rule '|| l_dqm_party_rule );
5753 ozf_utility_pvt.debug_message( 'Party Site DQM Rule '|| l_dqm_party_site_rule );
5754 ozf_utility_pvt.debug_message( 'Contact DQM Rule '|| l_dqm_contact_rule );
5755 END IF;
5756 -- Rules
5757 --
5758 IF l_party_rec.party_id IS NULL THEN
5759 IF l_dqm_party_rule IS NULL THEN
5763 l_dispute_code := 'OZF_NO_PARTY_DQM_RULE';
5760 IF OZF_DEBUG_LOW_ON THEN
5761 ozf_utility_pvt.debug_message('Party DQM Search Rule cannot be null,please set OZF:Resale DQM Party Rule profile with a valid value');
5762 END IF;
5764 END IF ;
5765 END IF;
5766 IF l_party_site_rec.party_site_id IS NULL THEN
5767 IF l_dispute_code IS NULL AND l_dqm_party_site_rule IS NULL
5768 AND l_party_site_rec.address IS NOT NULL THEN
5769 IF OZF_DEBUG_LOW_ON THEN
5770 ozf_utility_pvt.debug_message('Party Site DQM Search Rule cannot be null,please set OZF:Resale DQM Party Site Rule profile with a valid value');
5771 END IF;
5772 l_dispute_code := 'OZF_NO_SITE_DQM_RULE';
5773 END IF ;
5774 END IF;
5775 IF l_party_cntct_rec.contact_name IS NOT NULL AND
5776 l_dispute_code IS NULL AND l_dqm_contact_rule IS NULL THEN
5777 IF OZF_DEBUG_LOW_ON THEN
5778 ozf_utility_pvt.debug_message('Contact DQM Search Rule cannot be null,please set OZF:Resale DQM Contact Rule profile with a valid value');
5779 END IF;
5780 l_dispute_code := 'OZF_NO_CONTACT_DQM_RULE';
5781 END IF ;
5782
5783
5784 IF l_dispute_code IS NULL AND l_run_dqm_flag = 'Y' THEN
5785 --
5786 l_party_rec.party_rule_name := l_dqm_party_rule;
5787 l_party_site_rec.party_site_rule_name := l_dqm_party_site_rule;
5788 l_party_cntct_rec.contact_rule_name := l_dqm_contact_rule;
5789 --
5790 IF OZF_DEBUG_LOW_ON THEN
5791 ozf_utility_pvt.debug_message('DQM Process started ........');
5792 END IF;
5793 l_party_id := NULL;
5794 l_party_site_id := NULL;
5795 l_party_contact_id:= NULL;
5796
5797 DQM_Processing (
5798 p_api_version_number => 1.0,
5799 p_init_msg_list => FND_API.G_FALSE,
5800 P_Commit => FND_API.G_FALSE,
5801 p_validation_level => FND_API.G_VALID_LEVEL_FULL,
5802 p_party_rec => l_party_rec,
5803 p_party_site_rec => l_party_site_rec,
5804 p_contact_rec => l_party_cntct_rec,
5805 x_party_id => l_party_id,
5806 x_party_site_id => l_party_site_id,
5807 x_party_contact_id => l_party_contact_id,
5808 x_return_status => x_return_status,
5809 x_msg_count => l_msg_count,
5810 x_msg_data => l_msg_data);
5811
5812 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
5813 l_dispute_code := 'OZF_DQM_PROCESS_ERROR';
5814 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
5815 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5816 END IF;
5817 px_contact_party_id(i) := NVL( l_party_contact_id,'');
5818 IF OZF_DEBUG_LOW_ON THEN
5819 ozf_utility_pvt.debug_message( 'Party ID '|| l_party_id );
5820 ozf_utility_pvt.debug_message( 'Party Site ID '|| l_party_site_id );
5821 END IF;
5822 IF l_party_site_rec.party_site_id IS NULL THEN
5823 IF l_party_id IS NOT NULL AND l_party_site_id IS NOT NULL THEN
5824 IF p_party_type IN ('SOLD_FROM','SHIP_FROM','BILL_TO','SHIP_TO') THEN
5825
5826 -- Initialzing
5827 l_cust_account_id := NULL;
5828 l_acct_site_id := NULL;
5829 l_p_party_id := NULL;
5830 l_site_id := NULL;
5831
5832 OPEN get_acct_site_use_id( l_party_id
5833 ,l_party_site_id
5834 ,l_site_use_code );
5835 FETCH get_acct_site_use_id
5836 INTO l_cust_account_id
5837 , l_acct_site_id
5838 , l_site_id
5839 , l_p_party_id ;
5840 CLOSE get_acct_site_use_id;
5841
5842 IF OZF_DEBUG_LOW_ON THEN
5843 ozf_utility_pvt.debug_message( 'Account ID from get_acct_site_use_id '|| l_cust_account_id );
5844 ozf_utility_pvt.debug_message( 'Site Use ID from get_acct_site_use_id'|| l_acct_site_id );
5845 ozf_utility_pvt.debug_message( 'Party ID from get_acct_site_use_id '|| l_p_party_id );
5846 ozf_utility_pvt.debug_message( 'Party Site ID from get_acct_site_use_id '|| l_site_id );
5847 END IF;
5848
5849 IF l_cust_account_id IS NOT NULL THEN
5850 px_cust_account_id(i) := l_cust_account_id;
5851 END IF;
5852 IF l_acct_site_id IS NOT NULL THEN
5853 px_site_use_id(i) := l_acct_site_id;
5854 END IF;
5855
5856 IF l_site_id IS NOT NULL THEN
5857 px_party_site_id(i) := l_site_id;
5858 ELSE
5859 px_party_site_id(i) := l_party_site_id;
5860 END IF;
5864 ELSE
5861
5862 IF l_p_party_id IS NOT NULL THEN
5863 px_party_id(i) := l_p_party_id;
5865 px_party_id(i) := l_party_id;
5866 END IF;
5867 ELSE -- p_party_type IN ('SOLD_FROM','SHIP_FROM','BILL_TO','SHIP_TO')
5868 px_party_id(i) := l_party_id;
5869 px_party_site_id(i) := l_party_site_id;
5870 END IF;
5871 ELSE
5872 IF px_site_use_id.exists(i) AND px_site_use_id(i) IS NULL THEN
5873 px_site_use_id(i) := NULL;
5874 END IF;
5875 IF px_party_site_id.exists(i) AND px_party_site_id(i) IS NULL THEN
5876 px_party_site_id(i) := NULL;
5877 END IF;
5878 IF px_party_id.exists(i) AND px_party_id(i) IS NULL THEN
5879 px_party_id(i) := NULL;
5880 END IF;
5881 END IF; -- l_party_id IS NOT NULL AND l_party_site_id IS NOT NULL
5882 END IF;
5883 END IF;
5884 END IF; -- l_run_dqm_flag = 'Y'
5885 IF OZF_DEBUG_LOW_ON THEN
5886 ozf_utility_pvt.debug_message('px_status_code ('||i||') '||px_status_code_tbl(i));
5887 ozf_utility_pvt.debug_message('px_dispute_code_tbl ('||i||') '||px_dispute_code_tbl(i));
5888 END IF;
5889 -- ozf_utility_pvt.debug_message(lower(p_party_type)||'_cust_account_id('||i||')'||px_cust_account_id(i));
5890 -- ozf_utility_pvt.debug_message(lower(p_party_type)||'_party_site_id('||i||')'||px_party_site_id(i));
5891 -- ozf_utility_pvt.debug_message(lower(p_party_type)||'_party_id('||i||')'||px_party_id(i));
5892 -- ozf_utility_pvt.debug_message(lower(p_party_type)||'_site_use_id('||i||')'||px_site_use_id(i));
5893
5894 IF l_dispute_code IS NOT NULL THEN
5895 IF px_status_code_tbl(i) <> 'DISPUTED' THEN
5896 px_status_code_tbl(i) := 'DISPUTED';
5897 px_dispute_code_tbl(i) := l_dispute_code;
5898 END IF;
5899
5900 insert_resale_log
5901 (p_id_value => p_resale_line_int_id(i),
5902 p_id_type => 'IFACE',
5903 p_error_code => l_dispute_code,
5904 p_column_name => NULL,
5905 p_column_value => NULL,
5906 x_return_status => x_return_status);
5907
5908 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
5909 RAISE FND_API.G_EXC_ERROR;
5910 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
5911 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5912 END IF;
5913 END IF;
5914 END LOOP;
5915 END IF; -- p_line_count > 0
5916 -- Debug Message
5917 IF OZF_DEBUG_HIGH_ON THEN
5918 ozf_utility_pvt.debug_message('Private API: ' || l_api_name || ' end');
5919 END IF;
5920
5921 EXCEPTION
5922 WHEN FND_API.G_EXC_ERROR THEN
5923 x_return_status := FND_API.G_RET_STS_ERROR;
5924 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
5925 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5926 WHEN OTHERS THEN
5927 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5928 IF OZF_UNEXP_ERROR THEN
5929 FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
5930 END IF;
5931 END Party_Validations;
5932
5933
5934 PROCEDURE DQM_Processing (
5935 p_api_version_number IN NUMBER,
5936 p_init_msg_list IN VARCHAR2 := FND_API.G_FALSE,
5937 p_Commit IN VARCHAR2 := FND_API.G_FALSE,
5938 p_validation_level IN NUMBER := FND_API.G_VALID_LEVEL_FULL,
5939 p_party_rec IN party_rec_type,
5940 p_party_site_rec IN party_site_rec_type,
5941 p_contact_rec IN party_cntct_rec_type,
5942 x_party_id OUT NOCOPY NUMBER,
5943 x_party_site_id OUT NOCOPY NUMBER,
5944 x_party_contact_id OUT NOCOPY NUMBER,
5945 x_return_status OUT NOCOPY VARCHAR2,
5946 x_msg_count OUT NOCOPY NUMBER,
5947 x_msg_data OUT NOCOPY VARCHAR2
5948 )
5949 IS
5950
5951 l_api_name CONSTANT VARCHAR2(30) := 'DQM_processing';
5952 l_api_version_number CONSTANT NUMBER := 1.0;
5953
5954 -- Cursor for getting matched party_id from hz_matched_parties_gt
5955 CURSOR C_matched_party ( pc_search_id NUMBER)
5956 IS
5957 SELECT party_id
5958 FROM ( SELECT hzmp.party_id,
5959 score
5960 FROM hz_matched_parties_gt hzmp,
5961 hz_parties hzp
5962 WHERE search_context_id = pc_search_id
5963 AND hzp.party_id = hzmp.party_id
5964 ORDER BY score desc, hzp.creation_date desc )
5965 WHERE rownum = 1;
5966
5967 -- Cursor for getting matched party_site from hz_matched_party_sites_gt
5968 CURSOR C_matched_party_sites ( pc_search_id NUMBER)
5969 IS
5970 SELECT hzmps.party_id,
5971 hzmps.party_site_id,
5972 score ,
5973 hzps.creation_date
5974 FROM hz_matched_party_sites_gt hzmps,
5975 hz_party_sites hzps
5976 WHERE search_context_id = pc_search_id
5977 AND hzps.party_site_id = hzmps.party_site_id
5981 -- Cursor for getting matched contacts from hz_matched_contacts_gt
5978 AND hzps.party_id = hzmps.party_id
5979 ORDER BY score desc, hzps.creation_date desc;
5980
5982 CURSOR C_matched_contacts ( pc_search_id NUMBER)
5983 IS
5984 SELECT hzmc.party_id,
5985 hzmc.org_contact_id,
5986 score
5987 FROM hz_matched_contacts_gt hzmc
5988 WHERE search_context_id = pc_search_id;
5989
5990
5991 CURSOR get_match_rule ( pc_rule_name VARCHAR2)
5992 IS
5993 SELECT match_rule_id
5994 FROM hz_match_rules_vl
5995 WHERE active_flag = 'Y'
5996 AND compilation_flag = 'C'
5997 AND rule_name = pc_rule_name;
5998
5999 -- DQM Record Types
6000 l_party_cond HZ_PARTY_SEARCH.PARTY_SEARCH_REC_TYPE;
6001 l_party_site_cond HZ_PARTY_SEARCH.PARTY_SITE_LIST;
6002 l_contact_cond HZ_PARTY_SEARCH.CONTACT_LIST;
6003 l_contact_point_cond HZ_PARTY_SEARCH.CONTACT_POINT_LIST;
6004
6005
6006 l_rule_id NUMBER;
6007 l_partner_id NUMBER;
6008 l_search_context_id NUMBER;
6009 l_return_status VARCHAR2(1);
6010 l_msg_count NUMBER;
6011 l_msg_data VARCHAR2(2000);
6012 l_num_matches NUMBER;
6013 l_org_contact_id NUMBER(15);
6014 l_party_id NUMBER(15);
6015 l_party_site_id NUMBER(15);
6016 l_contact_point_id NUMBER(15);
6017 l_creation_date DATE;
6018 l_score NUMBER;
6019 l_highest_score_cnt NUMBER := 0;
6020 l_create_party VARCHAR2(1);
6021 l_create_party_site VARCHAR2(1);
6022 l_create_contact VARCHAR2(1);
6023 l_index NUMBER;
6024
6025
6026
6027 BEGIN
6028
6029 -- Standard call to check for call compatibility.
6030 IF NOT FND_API.Compatible_API_Call ( l_api_version_number,
6031 p_api_version_number,
6032 l_api_name,
6033 G_PKG_NAME)
6034 THEN
6035 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6036 END IF;
6037
6038 -- Initialize message list if p_init_msg_list is set to TRUE.
6039 IF FND_API.to_Boolean( p_init_msg_list )
6040 THEN
6041 FND_MSG_PUB.initialize;
6042 END IF;
6043
6044 -- Debug Message
6045 IF OZF_DEBUG_HIGH_ON THEN
6046 ozf_utility_pvt.debug_message('Private API: ' || l_api_name || ' start');
6047 END IF;
6048 -- Initialize API return status to SUCCESS
6049 x_return_status := FND_API.G_RET_STS_SUCCESS;
6050
6051 -- Data Assignment to DQM datatypes
6052 --
6053 -- 1. Pass Party search criteria in party_cond
6054 -- -------------------------------------------------------------------
6055
6056 -- l_party_cond.party_type := p_party_rec.party_type;
6057 l_party_cond.duns_number_c := p_party_rec.duns_number;
6058 l_party_cond.party_name := p_party_rec.party_name;
6059
6060 --
6061 -- 2. Pass Party Site search criteria in party_site_cond
6062 -- --------------------------------------------------------------------
6063 l_party_site_cond(1).address := p_party_site_rec.address;
6064 l_party_site_cond(1).city := p_party_site_rec.city;
6065 l_party_site_cond(1).postal_code := p_party_site_rec.postal_code;
6066 -- l_party_site_cond(1).country := p_party_site_rec.country;
6067 -- l_party_site_cond(1).state := p_party_site_rec.state;
6068
6069 --
6070 -- 3. Pass Contact search criteria in contact_cond
6071 -- -------------------------------------------------------------------
6072 l_contact_cond(1).contact_name := p_contact_rec.contact_name;
6073
6074 --
6075 -- 4. Pass Contact Point search criteria in contact_point_cond
6076 -- -------------------------------------------------------------------
6077 l_index := 1;
6078 IF p_contact_rec.party_email_id IS NOT NULL THEN
6079 l_contact_point_cond(l_index).CONTACT_POINT_TYPE := 'EMAIL';
6080 l_contact_point_cond(l_index).EMAIL_ADDRESS := p_contact_rec.party_email_id;
6081 l_index := l_index+1;
6082 END IF;
6083
6084 IF p_contact_rec.party_phone IS NOT NULL THEN
6085 l_contact_point_cond(l_index).CONTACT_POINT_TYPE := 'PHONE';
6086 l_contact_point_cond(l_index).RAW_PHONE_NUMBER := p_contact_rec.party_phone;
6087 l_index := l_index+1;
6088 END IF;
6089
6090 IF p_contact_rec.party_fax IS NOT NULL THEN
6091 l_contact_point_cond(l_index).CONTACT_POINT_TYPE := 'PHONE';
6092 l_contact_point_cond(l_index).PHONE_LINE_TYPE := 'FAX';
6093 l_contact_point_cond(l_index).raw_phone_number:= p_contact_rec.party_fax;
6094 l_index := l_index+1;
6095 END IF;
6096
6097 IF OZF_DEBUG_LOW_ON THEN
6098 ozf_utility_pvt.debug_message (' Party Rule name '|| p_party_rec.party_rule_name);
6099 ozf_utility_pvt.debug_message ('Party Name '|| p_party_rec.party_name );
6100 ozf_utility_pvt.debug_message ('Party ID '|| p_party_rec.party_id );
6101 END IF;
6102 --
6103 -- Party DQM Search
6104 -- -------------------------------------------------------------------------------
6105 IF p_party_rec.party_id IS NULL THEN
6106
6107 l_rule_id := p_party_rec.party_rule_name;
6108
6109 IF l_rule_id IS NOT NULL THEN
6110
6114 IF OZF_DEBUG_LOW_ON THEN
6111 IF p_party_rec.party_name IS NOT NULL
6112 OR p_party_rec.duns_number IS NOT NULL
6113 THEN
6115 ozf_utility_pvt.debug_message ('calling find parties ');
6116 END IF;
6117 HZ_PARTY_SEARCH.find_parties
6118 (p_init_msg_list => 'T',
6119 x_rule_id => l_rule_id,
6120 p_party_search_rec => l_party_cond,
6121 p_party_site_list => l_party_site_cond,
6122 p_contact_list => l_contact_cond ,
6123 p_contact_point_list => l_contact_point_cond,
6124 p_restrict_sql => NULL,
6125 p_search_merged => 'N',
6126 x_search_ctx_id => l_search_context_id,
6127 x_num_matches => l_num_matches,
6128 x_return_status => l_return_status,
6129 x_msg_count => l_msg_count,
6130 x_msg_data => l_msg_data);
6131
6132 IF l_return_status = FND_API.G_RET_STS_ERROR THEN
6133 RAISE FND_API.G_EXC_ERROR;
6134 ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
6135 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6136 END IF;
6137 IF OZF_DEBUG_LOW_ON THEN
6138 ozf_utility_pvt.debug_message('Number of matches'|| l_num_matches);
6139 END IF;
6140 IF l_num_matches >= 1 THEN
6141
6142 OPEN C_matched_party(l_search_context_id);
6143 LOOP
6144 FETCH C_matched_party INTO l_party_id;
6145 EXIT WHEN C_matched_party%NOTFOUND;
6146 l_highest_score_cnt := l_highest_score_cnt +1;
6147 END LOOP;
6148 CLOSE C_matched_party;
6149 IF OZF_DEBUG_LOW_ON THEN
6150 ozf_utility_pvt.debug_message('Matched party - '||to_char(l_party_id)||' score '||to_char(l_score));
6151 END IF;
6152 x_party_id := l_party_id; --assign the matched party_id
6153
6154 ELSIF l_num_matches = 0 AND p_party_rec.party_id IS NULL THEN
6155 IF OZF_DEBUG_LOW_ON THEN
6156 ozf_utility_pvt.debug_message('No party match found !');
6157 END IF;
6158 END IF; -- l_num_matches >= 1
6159
6160 ELSE
6161 IF OZF_DEBUG_LOW_ON THEN
6162 ozf_utility_pvt.debug_message('Party Name/DUNS Number is not supplied. DQM Search cannot be performed');
6163 END IF;
6164
6165 END IF; -- p_party_rec.party_name IS NOT NULL
6166
6167 ELSE
6168 IF OZF_DEBUG_LOW_ON THEN
6169 ozf_utility_pvt.debug_message('Match Rule for Party Search is not active or uncompiled. Check the match rule');
6170 END IF;
6171 RAISE FND_API.g_exc_error;
6172 END IF; -- l_rule_id IS NOT NULL
6173
6174 ELSE
6175 l_party_id := p_party_rec.party_id;
6176 x_party_id := l_party_id; --assign the matched party_id
6177 END IF; -- p_party_rec.party_id IS NULL
6178
6179
6180 l_rule_id := NULL;
6181 -- ----------------------------------------- End PARTY SEARCH --------------------------------------
6182 --
6183 -- Party Site DQM Search
6184 -- -------------------------------------------------------------------------------------------------
6185
6186
6187 IF p_party_site_rec.party_site_id IS NULL THEN
6188
6189 IF l_party_id IS NOT NULL AND p_party_site_rec.address IS NOT NULL THEN
6190 IF OZF_DEBUG_LOW_ON THEN
6191 ozf_utility_pvt.debug_message ('Site Rule name '|| p_party_site_rec.party_site_rule_name);
6192 END IF;
6193 l_rule_id := p_party_site_rec.party_site_rule_name;
6194
6195 IF l_rule_id IS NOT NULL THEN
6196
6197 IF p_party_site_rec.address IS NOT NULL
6198 AND (p_party_site_rec.postal_code IS NOT NULL
6199 OR ( p_party_site_rec.city IS NOT NULL
6200 AND
6201 p_party_site_rec.state IS NOT NULL ))
6202 THEN
6203
6204 HZ_PARTY_SEARCH.get_matching_party_sites
6205 ('T',
6206 l_rule_id,
6207 l_party_id,
6208 l_party_site_cond,
6209 l_contact_point_cond,
6210 l_search_context_id,
6211 l_return_status,
6212 l_msg_count,
6213 l_msg_data);
6214
6215 IF l_return_status = FND_API.G_RET_STS_ERROR THEN
6216 RAISE FND_API.G_EXC_ERROR;
6217 ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
6218 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6219 END IF;
6220
6221 OPEN C_matched_party_sites(l_search_context_id);
6222 FETCH C_matched_party_sites INTO l_party_id,
6223 l_party_site_id,
6224 l_score,
6225 l_creation_date;
6226 CLOSE C_matched_party_sites;
6227
6228 IF l_party_site_id IS NOT NULL THEN
6229 x_party_site_id := l_party_site_id;
6233 END IF;
6230 ELSE
6231 IF OZF_DEBUG_LOW_ON THEN
6232 ozf_utility_pvt.debug_message('No party site found !');
6234 l_create_party_site := 'Y';
6235 END IF;
6236 ELSE
6237 IF OZF_DEBUG_LOW_ON THEN
6238 ozf_utility_pvt.debug_message('Required parameters are missing. DQM Search for party site cannot be performed');
6239 END IF;
6240
6241 END IF; -- party site check
6242
6243 ELSE --if rule_id is null then
6244 IF OZF_DEBUG_LOW_ON THEN
6245 ozf_utility_pvt.debug_message('Match Rule for Party Site is not active or uncompiled. Check the match rule');
6246 END IF;
6247 RAISE FND_API.g_exc_error;
6248 END IF;
6249
6250 l_rule_id := NULL;
6251
6252 END IF; -- l_party_id IS NOT NULL
6253 ELSE
6254
6255 l_party_site_id := p_party_site_rec.party_site_id;
6256 x_party_site_id := l_party_site_id;
6257
6258 END IF; -- p_party_site_rec.party_site_id IS NULL
6259
6260 -- ------------------------------------------ End Party Site Search --------------------------------
6261 IF OZF_DEBUG_LOW_ON THEN
6262 ozf_utility_pvt.debug_message ('Contact Rule name '|| p_contact_rec.contact_rule_name);
6263 END IF;
6264
6265 l_rule_id := null;
6266
6267
6268 -- Contact DQM Search
6269 -- -------------------------------------------------------------------------------------------------
6270 l_rule_id := p_contact_rec.contact_rule_name;
6271
6272 IF p_party_rec.party_id IS NOT NULL THEN
6273 l_party_id := p_party_rec.party_id;
6274 END IF;
6275
6276 IF l_party_id IS NOT NULL THEN
6277
6278 IF l_rule_id IS NOT NULL THEN
6279 IF OZF_DEBUG_LOW_ON THEN
6280 ozf_utility_pvt.debug_message('contact name ........'|| l_contact_cond(1).contact_name);
6281 ozf_utility_pvt.debug_message('Email ........'|| p_contact_rec.party_email_id );
6282 ozf_utility_pvt.debug_message('Phone ........'||p_contact_rec.party_phone );
6283 ozf_utility_pvt.debug_message('Fax ........'||p_contact_rec.party_fax );
6284 END IF;
6285
6286 IF p_contact_rec.contact_name IS NOT NULL THEN
6287
6288 HZ_PARTY_SEARCH.get_matching_contacts
6289 (p_init_msg_list => 'T',
6290 p_rule_id => l_rule_id,
6291 p_party_id => l_party_id,
6292 p_contact_list => l_contact_cond,
6293 p_contact_point_list => l_contact_point_cond,
6294 x_search_ctx_id => l_search_context_id,
6295 x_return_status => l_return_status,
6296 x_msg_count => l_msg_count,
6297 x_msg_data => l_msg_data);
6298
6299 IF l_return_status = FND_API.G_RET_STS_ERROR THEN
6300 RAISE FND_API.G_EXC_ERROR;
6301 ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
6302 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6303 END IF;
6304 IF OZF_DEBUG_LOW_ON THEN
6305 ozf_utility_pvt.debug_message('l_search_context_id ........'|| l_search_context_id );
6306 END IF;
6307
6308
6309 OPEN C_matched_contacts(l_search_context_id);
6310 FETCH C_matched_contacts INTO l_party_id, l_org_contact_id, l_score;
6311 CLOSE C_matched_contacts;
6312 IF OZF_DEBUG_LOW_ON THEN
6313 ozf_utility_pvt.debug_message('contact info from DQM ........'|| l_party_id || ' : '||l_org_contact_id);
6314 END IF;
6315
6316 IF l_org_contact_id is not null THEN
6317 x_party_contact_id := l_org_contact_id;
6318 ELSE
6319 IF OZF_DEBUG_LOW_ON THEN
6320 ozf_utility_pvt.debug_message('No contact match found !');
6321 END IF;
6322 END IF;
6323 ELSE
6324 IF OZF_DEBUG_LOW_ON THEN
6325 ozf_utility_pvt.debug_message('DQM Search for contact cannot be performed');
6326 END IF;
6327 END IF; --p_contact_rec.contact_name IS NOT NULL
6328
6329
6330 ELSE
6331 IF OZF_DEBUG_LOW_ON THEN
6332 ozf_utility_pvt.debug_message('Match Rule for Party Contact is not active or uncompiled. Check the match rule');
6333 END IF;
6334 RAISE FND_API.g_exc_error;
6335 END IF; -- l_rule_id IS NOT NULL
6336
6337 END IF; -- l_party_id IS NOT NULL
6338 ------------------------------------------ End CONTACT SEARCH ---------------------------------------
6339
6340 -- Standard check for p_commit
6341
6342
6343 -- Debug Message
6344 IF OZF_DEBUG_LOW_ON THEN
6345 ozf_utility_pvt.debug_message('Private API: ' || l_api_name || ' end');
6346 END IF;
6347
6348 -- Standard call to get message count and if count is 1, get message info.
6349 FND_MSG_PUB.Count_And_Get
6350 (p_count => x_msg_count,
6351 p_data => x_msg_data
6352 );
6353
6354 EXCEPTION
6355 WHEN FND_API.G_EXC_ERROR THEN
6356 x_return_status := FND_API.G_RET_STS_ERROR;
6357 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
6358 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6359 WHEN OTHERS THEN
6360 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6361 IF OZF_UNEXP_ERROR THEN
6362 FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
6363 END IF;
6364
6365 END DQM_Processing;
6366
6367
6368 -- =========================================================================================
6369 -- Code Conversions
6370 -- =========================================================================================
6371
6372 PROCEDURE code_conversion
6373 (
6374 p_party_id IN VARCHAR2,
6375 p_cust_account_id IN VARCHAR2,
6376 p_mapping_type IN VARCHAR2,
6377 p_external_code_tbl IN VARCHAR2_TABLE,
6378 x_internal_code_tbl OUT NOCOPY VARCHAR2_TABLE,
6379 x_return_status OUT NOCOPY VARCHAR2,
6380 x_msg_count OUT NOCOPY NUMBER,
6381 x_msg_data OUT NOCOPY VARCHAR2
6382 )
6383 IS
6384
6385 l_api_name CONSTANT VARCHAR2(30) := 'code_conversion';
6386 l_api_version_number CONSTANT NUMBER := 1.0;
6387
6388 l_mapping_flag VARCHAR2(1);
6389 l_previous_code VARCHAR2(3200) := NULL;
6390 l_temp_code_tbl VARCHAR2_TABLE;
6391 idx NUMBER;
6392
6393 BEGIN
6394
6395 -- Debug Message
6396 IF OZF_DEBUG_HIGH_ON THEN
6397 ozf_utility_pvt.debug_message('Private API: ' || l_api_name || ' start');
6398 END IF;
6399
6400 -- Initialize API return status to SUCCESS
6401 x_return_status := FND_API.G_RET_STS_SUCCESS;
6402
6403
6404 IF p_external_code_tbl.COUNT > 0 THEN
6405
6406 FOR i IN 1 .. p_external_code_tbl.COUNT
6407 LOOP
6408 IF p_external_code_tbl(i) IS NOT NULL THEN
6409 IF OZF_DEBUG_LOW_ON THEN
6410 ozf_utility_pvt.debug_message('Party ID: ' || p_party_id);
6411 ozf_utility_pvt.debug_message('p_cust_account_id ' || p_cust_account_id);
6412 ozf_utility_pvt.debug_message('External Code: ' || p_external_code_tbl(i));
6413 ozf_utility_pvt.debug_message('Length of External Code: ' || length(p_external_code_tbl(i)));
6414 ozf_utility_pvt.debug_message('Mapping Type: ' || p_mapping_type);
6415 END IF;
6416 SELECT dbms_utility.get_hash_value( p_external_code_tbl(i),1, 2048)
6417 INTO idx
6418 FROM DUAL;
6419 IF l_temp_code_tbl.exists(idx) THEN
6420 x_internal_code_tbl(i) := l_temp_code_tbl(idx);
6421 IF OZF_DEBUG_LOW_ON THEN
6422 ozf_utility_pvt.debug_message('Internal Code: ' || x_internal_code_tbl(i));
6423 END IF;
6424
6425 ELSE
6426 OZF_CODE_CONVERSION_PVT.convert_code
6427 (p_cust_account_id => p_cust_account_id,
6428 p_party_id => p_party_id,
6429 p_code_conversion_type => p_mapping_type,
6430 p_external_code => p_external_code_tbl(i),
6431 x_internal_code => x_internal_code_tbl(i),
6432 x_return_status => x_return_status,
6433 x_msg_count => x_msg_count,
6434 x_msg_data => x_msg_data);
6435
6436 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
6437 RAISE FND_API.G_EXC_ERROR;
6438 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
6439 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6440 END IF;
6441 IF OZF_DEBUG_LOW_ON THEN
6442 ozf_utility_pvt.debug_message('Internal Code'||x_internal_code_tbl(i));
6443 END IF;
6444
6445 IF x_internal_code_tbl(i) IS NOT NULL THEN
6446 l_temp_code_tbl(idx) := x_internal_code_tbl(i);
6447 ELSE
6448 l_temp_code_tbl(idx) := '';
6449 END IF;
6450 END IF;
6451 ELSE
6452 IF OZF_DEBUG_LOW_ON THEN
6453 ozf_utility_pvt.debug_message('Code Conversion cannot be performed ');
6454 END IF;
6455 x_internal_code_tbl(i) := NULL;
6456 END IF; -- p_external_code_tbl(i) IS NOT NULL
6457 END LOOP;
6458
6459 END IF; -- p_external_code_tbl.COUNT > 0
6460
6461 -- Debug Message
6462 IF OZF_DEBUG_HIGH_ON THEN
6463 ozf_utility_pvt.debug_message('Private API: ' || l_api_name || ' end');
6464 END IF;
6465 -- Standard call to get message count and if count is 1, get message info.
6466 FND_MSG_PUB.Count_And_Get
6467 (p_count => x_msg_count,
6468 p_data => x_msg_data
6469 );
6470
6471
6472 EXCEPTION
6473 WHEN FND_API.G_EXC_ERROR THEN
6474 x_return_status := FND_API.G_RET_STS_ERROR;
6475 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
6476 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6477 WHEN OTHERS THEN
6478 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6479 IF OZF_UNEXP_ERROR THEN
6480 FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
6481 END IF;
6482
6483 END Code_Conversion;
6484
6485 PROCEDURE Mapping_Required
6486 (
6487 p_internal_code_tbl IN VARCHAR2_TABLE,
6491 IS
6488 p_external_code_tbl IN VARCHAR2_TABLE,
6489 x_mapping_flag OUT NOCOPY VARCHAR2
6490 )
6492 l_api_name CONSTANT VARCHAR2(30) := 'Mapping_Required';
6493 l_api_version_number CONSTANT NUMBER := 1.0;
6494 BEGIN
6495
6496 IF p_internal_code_tbl.COUNT > 0 THEN
6497 FOR i IN 1 .. p_internal_code_tbl.COUNT
6498 LOOP
6499 IF p_internal_code_tbl.EXISTS(i) AND
6500 p_internal_code_tbl(i) IS NOT NULL THEN
6501 x_mapping_flag := 'N';
6502 ELSIF p_external_code_tbl.EXISTS(i) AND
6503 p_external_code_tbl(i) IS NOT NULL THEN
6504 x_mapping_flag := 'Y';
6505 exit;
6506 ELSE
6507 x_mapping_flag := 'N';
6508 END IF;
6509 END LOOP;
6510 END IF;
6511 END Mapping_Required;
6512
6513
6514 PROCEDURE Number_Mapping_Required
6515 (
6516 p_internal_code_tbl IN NUMBER_TABLE,
6517 x_mapping_flag OUT NOCOPY VARCHAR2
6518 )
6519 IS
6520 l_api_name CONSTANT VARCHAR2(30) := 'Number_Mapping_Required';
6521 l_api_version_number CONSTANT NUMBER := 1.0;
6522 BEGIN
6523
6524 IF p_internal_code_tbl.COUNT > 0 THEN
6525 FOR i IN 1 .. p_internal_code_tbl.COUNT
6526 LOOP
6527 IF p_internal_code_tbl(i) IS NOT NULL THEN
6528 x_mapping_flag := 'N';
6529 exit;
6530 ELSE
6531 x_mapping_flag := 'Y';
6532 END IF;
6533 END LOOP;
6534 END IF;
6535 END Number_Mapping_Required;
6536
6537
6538 FUNCTION set_line_status
6539 ( p_count IN NUMBER,
6540 p_status_code IN VARCHAR2)
6541 RETURN VARCHAR2_TABLE
6542 IS
6543 l_api_name CONSTANT VARCHAR2(30) := 'set_line_status';
6544 l_api_version_number CONSTANT NUMBER := 1.0;
6545
6546 l_tbl VARCHAR2_TABLE;
6547 BEGIN
6548 FOR i IN 1 .. p_count
6549 loop
6550 l_tbl(i) := p_status_code;
6551 END LOOP;
6552 RETURN l_tbl;
6553 END set_line_status;
6554
6555
6556 PROCEDURE Get_Customer_Accnt_Id(
6557 p_party_id IN NUMBER,
6558 p_party_site_id IN NUMBER,
6559 x_return_status OUT NOCOPY VARCHAR2,
6560 x_cust_acct_id OUT NOCOPY NUMBER
6561 )
6562 IS
6563 l_api_name CONSTANT VARCHAR2(30) := 'Get_Customer_Accnt_Id';
6564 l_api_version_number CONSTANT NUMBER := 1.0;
6565
6566 CURSOR c_get_cust_accnt_id(pc_party_site_id NUMBER)
6567 IS
6568 SELECT s.cust_account_id
6569 FROM hz_cust_acct_sites s
6570 WHERE s.party_site_id = pc_party_site_id
6571 AND status = 'A';
6572
6573 CURSOR c_get_customer_accnt_id(pc_party_id NUMBER)
6574 IS
6575 SELECT a.cust_account_id
6576 FROM hz_cust_accounts a
6577 WHERE a.party_id = pc_party_id
6578 AND status = 'A';
6579
6580 l_msg_count number;
6581 l_msg_data varchar2(200);
6582 l_return_status VARCHAR2(1);
6583
6584 BEGIN
6585
6586 x_return_status := FND_API.G_RET_STS_SUCCESS;
6587
6588 IF p_party_id IS NULL AND
6589 p_party_site_id IS NULL
6590 THEN
6591 FND_MESSAGE.set_name('OZF', 'OZF_BATCH_PARTNER_NULL');
6592 FND_MSG_PUB.add;
6593 RAISE FND_API.G_EXC_ERROR;
6594 END IF;
6595
6596 -- get customer account based on party site id
6597 IF p_party_site_id is not null THEN
6598 OPEN c_get_cust_accnt_id(p_party_site_id);
6599 FETCH c_get_cust_accnt_id INTO x_cust_acct_id;
6600 CLOSE c_get_cust_accnt_id;
6601 END IF;
6602
6603 IF x_cust_acct_id is null THEN
6604 IF p_party_id is not null THEN
6605 OPEN c_get_customer_accnt_id(p_party_id);
6606 FETCH c_get_customer_accnt_id INTO x_cust_acct_id;
6607 CLOSE c_get_customer_accnt_id;
6608 END IF;
6609 END IF;
6610
6611 IF x_cust_acct_id IS NULL THEN
6612 ozf_utility_pvt.error_message('OZF_BATCH_PARTNER_NULL');
6613 END IF;
6614
6615 EXCEPTION
6616 WHEN FND_API.G_EXC_ERROR THEN
6617 x_return_status := FND_API.G_RET_STS_ERROR;
6618 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
6619 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6620 WHEN OTHERS THEN
6621 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6622 IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
6623 THEN
6624 FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
6625 END IF;
6626 END Get_Customer_Accnt_Id;
6627
6628 PROCEDURE Get_party_site_from_ECX
6629 (
6630 p_location IN VARCHAR2,
6631 x_party_site_id OUT NOCOPY NUMBER,
6632 x_return_status OUT NOCOPY VARCHAR2
6633 )
6634 IS
6635 l_api_name CONSTANT VARCHAR2(30) := 'Get_party_site_from_ECX';
6636 l_api_version_number CONSTANT NUMBER := 1.0;
6637
6638 l_address_id NUMBER;
6639 l_ecx_org_id NUMBER;
6640 l_return_code PLS_INTEGER;
6641 l_return_message VARCHAR2(32000);
6642
6643 BEGIN
6644 IF OZF_DEBUG_HIGH_ON THEN
6645 ozf_utility_pvt.debug_message('Private API: ' || l_api_name || ' start');
6646 END IF;
6647
6648 x_return_status := FND_API.G_RET_STS_SUCCESS;
6649
6650 ECX_TRADING_PARTNER_PVT.Get_Address_id
6651 (
6652 p_location_code_ext => p_location,
6653 p_info_type => ECX_Trading_Partner_PVT.G_CUSTOMER,
6654 p_entity_address_id => l_address_id,
6655 p_org_id => l_ecx_org_id,
6656 retcode => l_return_code,
6657 retmsg => l_return_message
6658 );
6659 IF OZF_DEBUG_LOW_ON THEN
6660 ozf_utility_pvt.debug_message('Address ID '|| l_address_id || 'Return Code '|| l_return_code);
6661 END IF;
6662
6663 IF l_return_code = 0 THEN
6664 x_party_site_id := l_address_id;
6665 ELSE
6666 x_party_site_id := NULL;
6667 END IF;
6668 IF OZF_DEBUG_HIGH_ON THEN
6669 ozf_utility_pvt.debug_message('Private API: ' || l_api_name || ' End');
6670 END IF;
6671 EXCEPTION
6672 WHEN FND_API.G_EXC_ERROR THEN
6673 x_return_status := FND_API.G_RET_STS_ERROR;
6674 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
6675 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6676 WHEN OTHERS THEN
6677 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6678 IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
6679 THEN
6680 FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
6681 END IF;
6682
6683 END Get_party_site_from_ECX;
6684
6685 PROCEDURE Chk_party_record_null(
6686 p_line_count IN NUMBER,
6687 p_party_type IN VARCHAR2,
6688 p_cust_account_id IN NUMBER_TABLE,
6689 p_acct_site_id IN NUMBER_TABLE,
6690 p_party_id IN NUMBER_TABLE,
6691 p_party_site_id IN NUMBER_TABLE,
6692 p_location IN VARCHAR2_TABLE,
6693 p_party_name IN VARCHAR2_TABLE,
6694 x_null_flag OUT NOCOPY VARCHAR2,
6695 x_return_status OUT NOCOPY VARCHAR2
6696 )
6697 IS
6698 l_api_name CONSTANT VARCHAR2(30) := 'Chk_party_record_null';
6699 l_api_version_number CONSTANT NUMBER := 1.0;
6700
6701 BEGIN
6702
6703 IF OZF_DEBUG_HIGH_ON THEN
6704 ozf_utility_pvt.debug_message('Private API: ' || l_api_name || ' start');
6705 END IF;
6706
6707 x_return_status := FND_API.G_RET_STS_SUCCESS;
6708 x_null_flag := 'Y';
6709
6710 IF p_line_count > 0 THEN
6711 FOR i IN 1 .. p_line_count LOOP
6712 IF OZF_DEBUG_LOW_ON THEN
6713 IF p_cust_account_id.exists(i) THEN
6714 ozf_utility_pvt.debug_message('p_cust_account_id = '||p_cust_account_id(i));
6715 END IF;
6716 IF p_acct_site_id.exists(i) THEN
6717 ozf_utility_pvt.debug_message('p_acct_site_id = '||p_acct_site_id(i));
6718 END IF;
6719 IF p_party_id.exists(i) THEN
6720 ozf_utility_pvt.debug_message('p_party_id = '||p_party_id(i));
6721 END IF;
6722 IF p_party_site_id.exists(i) THEN
6723 ozf_utility_pvt.debug_message('p_party_site_id = '||p_party_site_id(i));
6724 END IF;
6725 IF p_location.exists(i) THEN
6726 ozf_utility_pvt.debug_message('p_location = '||p_location(i));
6727 END IF;
6728 IF p_party_name.exists(i) THEN
6729 ozf_utility_pvt.debug_message('p_party_name = '||p_party_name(i));
6730 END IF;
6731 END IF;
6732
6733
6734 IF p_cust_account_id.exists(i) AND p_cust_account_id(i) IS NOT NULL THEN
6735 x_null_flag := 'N';
6736 ELSE
6737 IF p_acct_site_id.exists(i) AND p_acct_site_id(i) IS NOT NULL THEN
6738 x_null_flag := 'N';
6739 ELSE
6740 IF p_location.exists(i) AND p_location(i) IS NOT NULL THEN
6741 x_null_flag := 'N';
6742 ELSE
6743 --IF p_party_type = 'SHIP_TO' THEN -- [Bug 4186465 Fixing]
6744 IF p_party_site_id.exists(i) AND p_party_site_id(i) IS NOT NULL THEN
6745 x_null_flag := 'N';
6746 ELSE
6747 IF p_party_id.exists(i) AND p_party_id(i) IS NOT NULL THEN
6748 x_null_flag := 'N';
6749 ELSE
6750 IF p_party_name.exists(i) AND p_party_name(i) IS NOT NULL THEN
6751 x_null_flag := 'N';
6752 ELSE
6753 x_null_flag := 'Y';
6754 END IF; -- p_party_name
6755 END IF; -- p_party_id
6756 END IF; -- p_party_site_id
6757 --END IF; -- [Bug 4186465 Fixing]
6758 --IF x_null_flag IS NULL AND p_party_name.exists(i) AND p_party_name(i) IS NOT NULL THEN
6759 -- x_null_flag := 'N';
6760 --ELSIF p_party_name.exists(i) AND p_party_name(i) IS NULL THEN
6761 -- x_null_flag := 'Y';
6762 --END IF; -- p_party_name
6763 END IF; -- p_location
6764 END IF; -- p_acct_site_id
6765 END IF; -- p_cust_account_id
6766 END LOOP;
6767 END IF;
6768
6769 IF OZF_DEBUG_HIGH_ON THEN
6770 ozf_utility_pvt.debug_message('x_null_flag in check party record: ' || x_null_flag);
6771 ozf_utility_pvt.debug_message('Private API: ' || l_api_name || ' end');
6772 END IF;
6773 EXCEPTION
6774 WHEN FND_API.G_EXC_ERROR THEN
6775 x_return_status := FND_API.G_RET_STS_ERROR;
6776 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
6777 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6778 WHEN OTHERS THEN
6779 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6780 IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
6781 THEN
6782 FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
6783 END IF;
6784
6785 END Chk_party_record_null;
6786
6787
6788 PROCEDURE Derive_Party
6789 ( p_resale_line_int_id IN NUMBER_TABLE
6790 , p_line_count IN NUMBER
6791 , p_party_type IN VARCHAR2
6792 , p_cust_account_id IN NUMBER_TABLE
6793 , p_site_id IN NUMBER_TABLE
6794 , x_cust_account_id OUT NOCOPY NUMBER_TABLE
6795 , x_site_id OUT NOCOPY NUMBER_TABLE
6796 , x_site_use_id OUT NOCOPY NUMBER_TABLE
6797 , x_party_id OUT NOCOPY NUMBER_TABLE
6798 , x_party_name OUT NOCOPY VARCHAR2_TABLE
6799 , px_status_code_tbl IN OUT NOCOPY VARCHAR2_TABLE
6800 , px_dispute_code_tbl IN OUT NOCOPY VARCHAR2_TABLE
6801 , x_return_status OUT NOCOPY VARCHAR2
6802 )
6803 IS
6804 l_api_name CONSTANT VARCHAR2(30) := 'Derive_Party';
6805 l_api_version_number CONSTANT NUMBER := 1.0;
6806
6807 -- SOLD_FROM (ship_from_cust_account_id)
6808 CURSOR get_sf_cust(cv_cust_account_id IN NUMBER) IS
6809 SELECT hcas.cust_account_id
6810 , hps.party_site_id
6811 , hp.party_id
6812 , hp.party_name
6813 FROM hz_cust_acct_sites hcas,
6814 hz_cust_site_uses hcsu,
6815 hz_party_sites hps,
6816 hz_parties hp
6817 WHERE hp.party_id = hcas.cust_account_id
6818 AND hp.party_id = hps.party_id
6819 AND hps.party_site_id = hcas.party_site_id
6820 AND hcas.cust_account_id = cv_cust_account_id
6821 AND hcas.cust_acct_site_id = hcsu.cust_acct_site_id
6822 AND hcsu.primary_flag = 'Y'
6823 AND hcsu.site_use_code = 'BILL_TO';
6824
6825 -- SOLD_FROM (ship_from_cust_account_id, ship_from_site_id)
6826 CURSOR get_sf_cust_and_site(cv_cust_account_id IN NUMBER) IS
6827 SELECT hp.party_id
6828 , hp.party_name
6829 FROM hz_cust_accounts hca,
6830 hz_parties hp
6831 WHERE hp.party_id = hca.party_id
6832 AND hca.cust_account_id = cv_cust_account_id;
6833
6834 -- SOLD_FROM (ship_from_site_id)
6835 CURSOR get_sf_site(cv_party_site_id IN NUMBER) IS
6836 SELECT hcas.cust_account_id
6837 , hps.party_site_id
6838 , hp.party_id
6839 , hp.party_name
6840 FROM hz_cust_acct_sites hcas,
6841 hz_cust_site_uses hcsu,
6842 hz_party_sites hps,
6843 hz_parties hp
6844 WHERE hp.party_id = hcas.cust_account_id
6845 AND hp.party_id = hps.party_id
6846 AND hps.party_site_id = hcas.party_site_id
6847 AND hcas.cust_acct_site_id = hcsu.cust_acct_site_id
6848 AND hcas.party_site_id = cv_party_site_id
6849 AND hcsu.site_use_code = 'BILL_TO';
6850
6851 -- BILL_TO (ship_to_cust_account_id)
6852 CURSOR get_bt_cust(cv_cust_account_id IN NUMBER) IS
6853 SELECT hcas.cust_account_id
6854 , hcsu.site_use_id
6855 , hps.party_site_id
6856 , hp.party_id
6857 , hp.party_name
6858 FROM hz_cust_acct_sites hcas,
6859 hz_cust_site_uses hcsu,
6860 hz_party_sites hps,
6861 hz_parties hp
6862 WHERE hp.party_id = hcas.cust_account_id
6863 AND hp.party_id = hps.party_id
6864 AND hps.party_site_id = hcas.party_site_id
6865 AND hcas.cust_account_id = cv_cust_account_id
6866 AND hcas.cust_acct_site_id = hcsu.cust_acct_site_id
6867 AND hcsu.primary_flag = 'Y'
6868 AND hcsu.site_use_code = 'BILL_TO';
6869
6870
6871 -- BILL_TO (ship_to_cust_account_id, ship_to_site_use_id)
6872 CURSOR get_bt_cust_and_site(cv_cust_account_id IN NUMBER
6873 ,cv_site_use_id IN NUMBER) IS
6874 SELECT hcas.cust_account_id
6875 , hcsu.site_use_id
6876 , hps.party_site_id
6877 , hp.party_id
6878 , hp.party_name
6879 FROM hz_cust_acct_sites hcas,
6880 hz_cust_site_uses hcsu,
6881 hz_party_sites hps,
6882 hz_parties hp,
6883 hz_cust_site_uses shcsu
6884 WHERE hp.party_id = hcas.cust_account_id
6885 AND hp.party_id = hps.party_id
6886 AND hps.party_site_id = hcas.party_site_id
6887 AND hcas.cust_account_id = cv_cust_account_id
6888 AND hcas.cust_acct_site_id = hcsu.cust_acct_site_id
6889 AND hcsu.site_use_code = 'BILL_TO'
6890 AND shcsu.bill_to_site_use_id = hcsu.site_use_id
6891 AND shcsu.site_use_code = 'SHIP_TO'
6892 AND shcsu.site_use_id = cv_site_use_id;
6893
6894 -- BILL_TO (ship_to_site_use_id)
6895 CURSOR get_bt_site(cv_site_use_id IN NUMBER) IS
6896 SELECT hcas.cust_account_id
6897 , hcsu.site_use_id
6898 , hps.party_site_id
6899 , hp.party_id
6900 , hp.party_name
6901 FROM hz_cust_acct_sites hcas,
6902 hz_cust_site_uses hcsu,
6903 hz_party_sites hps,
6904 hz_parties hp,
6905 hz_cust_acct_sites shcas,
6906 hz_cust_site_uses shcsu
6907 WHERE hp.party_id = hcas.cust_account_id
6908 AND hp.party_id = hps.party_id
6909 AND hps.party_site_id = hcas.party_site_id
6910 AND hcas.cust_acct_site_id = hcsu.cust_acct_site_id
6911 AND hcsu.site_use_code = 'BILL_TO'
6912 AND hcas.cust_account_id = shcas.cust_account_id
6913 AND shcas.cust_acct_site_id = shcsu.cust_acct_site_id
6914 AND shcsu.bill_to_site_use_id = hcsu.site_use_id
6915 AND shcsu.site_use_code = 'SHIP_TO'
6916 AND shcsu.site_use_id = cv_site_use_id;
6917
6918 l_cust_account_id NUMBER;
6919 l_site_use_id NUMBER;
6920 l_party_site_id NUMBER;
6921 l_party_id NUMBER;
6922 l_party_name VARCHAR2(1000);
6923
6924 BEGIN
6925 IF OZF_DEBUG_HIGH_ON THEN
6926 ozf_utility_pvt.debug_message('Private API: ' || l_api_name || ' start');
6927 END IF;
6928
6929 -- Initialize API return status to SUCCESS
6930 x_return_status := FND_API.G_RET_STS_SUCCESS;
6931
6932 IF p_line_count > 0 THEN
6933 IF OZF_DEBUG_LOW_ON THEN
6934 FOR i IN 1 .. p_line_count LOOP
6935 ozf_utility_pvt.debug_message('p_cust_account_id('||i||')'||p_cust_account_id(i));
6936 ozf_utility_pvt.debug_message('p_site_id('||i||')'||p_site_id(i));
6937 END LOOP;
6938 END IF;
6939
6940 FOR i IN 1 .. p_line_count LOOP
6941 x_cust_account_id(i) := NULL;
6942 x_site_id(i) := NULL;
6943 x_party_name(i) := NULL;
6944 x_site_use_id(i) := NULL;
6945 x_party_id(i) := NULL;
6946
6947 IF OZF_DEBUG_LOW_ON THEN
6948 ozf_utility_pvt.debug_message('px_status_code_tbl('||i||')'||px_status_code_tbl(i));
6949 ozf_utility_pvt.debug_message('px_dispute_code_tbl('||i||')'||px_dispute_code_tbl(i));
6950 END IF;
6951
6952 IF p_party_type = 'SOLD_FROM' AND
6953 px_status_code_tbl(i) = 'DISPUTED' AND
6954 px_dispute_code_tbl(i) = 'OZF_SHIP_FROM_ACCOUNT_NULL' THEN
6955 EXIT;
6956 ELSE
6957 IF OZF_DEBUG_LOW_ON THEN
6958 ozf_utility_pvt.debug_message('p_party_type'||p_party_type);
6959 ozf_utility_pvt.debug_message('p_cust_account_id('||i||')'||p_cust_account_id(i));
6960 ozf_utility_pvt.debug_message('p_site_id('||i||')'||p_site_id(i));
6961 END IF;
6962
6963 IF p_cust_account_id.exists(i) AND
6964 p_cust_account_id(i) IS NOT NULL THEN
6965 IF p_site_id.exists(i) AND
6966 p_site_id(i) IS NOT NULL THEN
6967 IF p_party_type = 'SOLD_FROM' THEN
6968 x_cust_account_id(i) := p_cust_account_id(i);
6969 x_site_id(i) := p_site_id(i);
6970 x_site_use_id(i) := NULL;
6971
6972 OPEN get_sf_cust_and_site (p_cust_account_id(i));
6973 FETCH get_sf_cust_and_site INTO x_party_id(i)
6974 , x_party_name(i);
6975 CLOSE get_sf_cust_and_site;
6976 ELSE
6977 OPEN get_bt_cust_and_site (p_cust_account_id(i), p_site_id(i));
6978 FETCH get_bt_cust_and_site INTO x_cust_account_id(i)
6979 , x_site_use_id(i)
6980 , x_site_id(i)
6981 , x_party_id(i)
6982 , x_party_name(i);
6983 CLOSE get_bt_cust_and_site;
6984 END IF;
6985 ELSE
6986 IF p_party_type = 'SOLD_FROM' THEN
6987 x_site_use_id(i) := NULL;
6988 OPEN get_sf_cust(p_cust_account_id(i));
6989 FETCH get_sf_cust INTO x_cust_account_id(i)
6990 , x_site_id(i)
6991 , x_party_id(i)
6992 , x_party_name(i);
6993 CLOSE get_sf_cust;
6994 ELSE
6995 OPEN get_bt_cust_and_site (p_cust_account_id(i), p_site_id(i));
6996 FETCH get_bt_cust_and_site INTO x_cust_account_id(i)
6997 , x_site_use_id(i)
6998 , x_site_id(i)
6999 , x_party_id(i)
7000 , x_party_name(i);
7001 CLOSE get_bt_cust_and_site;
7002 END IF;
7003 END IF;
7004 ELSE
7005 IF p_site_id.exists(i) AND
7006 p_site_id(i) IS NOT NULL THEN
7007 IF p_party_type = 'SOLD_FROM' THEN
7008 x_site_use_id(i) := NULL;
7009 OPEN get_sf_site (p_site_id(i));
7010 FETCH get_sf_site INTO x_cust_account_id(i)
7011 , x_site_id(i)
7012 , x_party_id(i)
7013 , x_party_name(i);
7014 CLOSE get_sf_site;
7015 ELSE
7016 x_site_use_id(i) := NULL;
7017 OPEN get_bt_site (p_site_id(i));
7018 FETCH get_bt_site INTO x_cust_account_id(i)
7019 , x_site_use_id(i)
7020 , x_site_id(i)
7021 , x_party_id(i)
7022 , x_party_name(i);
7023 CLOSE get_bt_site;
7024 END IF;
7025 END IF;
7026 END IF;
7027
7028 IF OZF_DEBUG_LOW_ON THEN
7029 ozf_utility_pvt.debug_message('-------');
7030 ozf_utility_pvt.debug_message('x_cust_account_id('||i||')'||x_cust_account_id(i));
7031 ozf_utility_pvt.debug_message('x_site_id('||i||')'||x_site_id(i));
7032 ozf_utility_pvt.debug_message('x_party_name('||i||')'||x_party_name(i));
7033 ozf_utility_pvt.debug_message('x_site_use_id('||i||')'||x_site_use_id(i));
7034 ozf_utility_pvt.debug_message('x_party_id('||i||')'||x_party_id(i));
7035 END IF;
7036
7037 END IF;
7038 END LOOP;
7039 END IF; -- end of if p_line_count > 0
7040
7041 IF OZF_DEBUG_HIGH_ON THEN
7042 ozf_utility_pvt.debug_message('Private API: ' || l_api_name || ' end');
7043 END IF;
7044
7045 EXCEPTION
7046 WHEN FND_API.G_EXC_ERROR THEN
7047 x_return_status := FND_API.G_RET_STS_ERROR;
7048 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
7049 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
7050 WHEN OTHERS THEN
7051 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
7052 IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
7053 THEN
7054 FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
7055 END IF;
7056
7057 END derive_party;
7058
7059 PROCEDURE Update_interface_line
7060 (
7061 p_api_version_number IN NUMBER,
7062 p_init_msg_list IN VARCHAR2 := FND_API.G_FALSE,
7063 p_Commit IN VARCHAR2 := FND_API.G_FALSE,
7064 p_validation_level IN NUMBER := FND_API.G_VALID_LEVEL_FULL,
7065 p_int_line_tbl IN resale_line_int_tbl_type,
7066 x_return_status OUT NOCOPY VARCHAR2,
7067 x_msg_count OUT NOCOPY NUMBER,
7068 x_msg_data OUT NOCOPY VARCHAR2
7069 )
7070 IS
7071
7072 l_api_name CONSTANT VARCHAR2(30) := 'update_interface_line';
7073 l_api_version_number CONSTANT NUMBER := 1.0;
7074
7075 BEGIN
7076 IF OZF_DEBUG_HIGH_ON THEN
7077 -- Debug Message
7078 ozf_utility_pvt.debug_message('Private API: ' || l_api_name || ' start');
7079 END IF;
7080 -- Initialize API return status to SUCCESS
7081 x_return_status := FND_API.G_RET_STS_SUCCESS;
7082
7083 BEGIN
7084 IF p_int_line_tbl.count > 0 THEN
7085
7086 FOR l_count in p_int_line_tbl.FIRST .. p_int_line_tbl.LAST
7087 LOOP
7088 IF OZF_DEBUG_LOW_ON THEN
7089 ozf_utility_pvt.debug_message('p_int_line_tbl(l_count).resale_line_int_id ' || p_int_line_tbl(l_count).resale_line_int_id );
7090 END IF;
7091
7092 OZF_RESALE_LINES_INT_PKG.Update_Row(
7093 p_resale_line_int_id => p_int_line_tbl(l_count).resale_line_int_id,
7094 p_object_version_number => p_int_line_tbl(l_count).object_version_number,
7095 p_last_update_date => p_int_line_tbl(l_count).last_update_date,
7096 p_last_updated_by => p_int_line_tbl(l_count).last_updated_by,
7097 p_request_id => p_int_line_tbl(l_count).request_id,
7098 p_created_from => p_int_line_tbl(l_count).created_from,
7099 p_last_update_login => p_int_line_tbl(l_count).last_update_login,
7100 p_program_application_id => p_int_line_tbl(l_count).program_application_id,
7101 p_program_update_date => p_int_line_tbl(l_count).program_update_date,
7102 p_program_id => p_int_line_tbl(l_count).program_id,
7103 p_response_type => p_int_line_tbl(l_count).response_type,
7104 p_response_code => p_int_line_tbl(l_count).response_code,
7105 p_reject_reason_code => p_int_line_tbl(l_count).reject_reason_code,
7106 p_followup_action_code => p_int_line_tbl(l_count).followup_action_code,
7107 p_resale_transfer_type => p_int_line_tbl(l_count).resale_transfer_type,
7108 p_product_trans_movement_type => p_int_line_tbl(l_count).product_transfer_movement_type,
7109 p_product_transfer_date => p_int_line_tbl(l_count).product_transfer_date,
7110 p_resale_batch_id => p_int_line_tbl(l_count).resale_batch_id,
7111 p_status_code => p_int_line_tbl(l_count).status_code,
7112 p_end_cust_party_id => p_int_line_tbl(l_count).end_cust_party_id,
7113 p_end_cust_site_use_id => p_int_line_tbl(l_count).end_cust_site_use_id,
7114 p_end_cust_site_use_code => p_int_line_tbl(l_count).end_cust_site_use_code,
7115 p_end_cust_party_site_id => p_int_line_tbl(l_count).end_cust_party_site_id,
7116 p_end_cust_party_name => p_int_line_tbl(l_count).end_cust_party_name,
7117 p_end_cust_location => p_int_line_tbl(l_count).end_cust_location,
7118 p_end_cust_address => p_int_line_tbl(l_count).end_cust_address,
7119 p_end_cust_city => p_int_line_tbl(l_count).end_cust_city,
7120 p_end_cust_state => p_int_line_tbl(l_count).end_cust_state,
7121 p_end_cust_postal_code => p_int_line_tbl(l_count).end_cust_postal_code,
7122 p_end_cust_country => p_int_line_tbl(l_count).end_cust_country,
7123 p_end_cust_contact_party_id => p_int_line_tbl(l_count).end_cust_contact_party_id,
7124 p_end_cust_contact_name => p_int_line_tbl(l_count).end_cust_contact_name,
7125 p_end_cust_email => p_int_line_tbl(l_count).end_cust_email,
7126 p_end_cust_phone => p_int_line_tbl(l_count).end_cust_phone,
7127 p_end_cust_fax => p_int_line_tbl(l_count).end_cust_fax,
7128 p_bill_to_cust_account_id => p_int_line_tbl(l_count).bill_to_cust_account_id,
7129 p_bill_to_site_use_id => p_int_line_tbl(l_count).bill_to_site_use_id,
7130 p_bill_to_PARTY_NAME => p_int_line_tbl(l_count).bill_to_party_name,
7131 p_bill_to_PARTY_ID => p_int_line_tbl(l_count).bill_to_PARTY_ID,
7132 p_bill_to_PARTY_site_id => p_int_line_tbl(l_count).bill_to_PARTY_site_id,
7133 p_bill_to_location => p_int_line_tbl(l_count).bill_to_location,
7134 p_bill_to_duns_number => p_int_line_tbl(l_count).bill_to_duns_number,
7135 p_bill_to_address => p_int_line_tbl(l_count).bill_to_address,
7136 p_bill_to_city => p_int_line_tbl(l_count).bill_to_city,
7137 p_bill_to_state => p_int_line_tbl(l_count).bill_to_state,
7138 p_bill_to_postal_code => p_int_line_tbl(l_count).bill_to_postal_code,
7139 p_bill_to_country => p_int_line_tbl(l_count).bill_to_country,
7140 p_bill_to_contact_party_id => p_int_line_tbl(l_count).bill_to_contact_party_id,
7141 p_bill_to_contact_name => p_int_line_tbl(l_count).bill_to_contact_name,
7142 p_bill_to_email => p_int_line_tbl(l_count).bill_to_email,
7143 p_bill_to_phone => p_int_line_tbl(l_count).bill_to_phone,
7144 p_bill_to_fax => p_int_line_tbl(l_count).bill_to_fax,
7145 p_ship_to_cust_account_id => p_int_line_tbl(l_count).ship_to_cust_account_id,
7146 p_ship_to_site_use_id => p_int_line_tbl(l_count).ship_to_site_use_id,
7147 p_ship_to_party_name => p_int_line_tbl(l_count).ship_to_party_name,
7148 p_ship_to_party_id => p_int_line_tbl(l_count).ship_to_party_id,
7149 p_ship_to_party_site_id => p_int_line_tbl(l_count).ship_to_party_site_id,
7150 p_ship_to_duns_number => p_int_line_tbl(l_count).ship_to_duns_number,
7151 p_ship_to_location => p_int_line_tbl(l_count).ship_to_location,
7152 p_ship_to_address => p_int_line_tbl(l_count).ship_to_address,
7153 p_ship_to_city => p_int_line_tbl(l_count).ship_to_city,
7154 p_ship_to_state => p_int_line_tbl(l_count).ship_to_state,
7155 p_ship_to_postal_code => p_int_line_tbl(l_count).ship_to_postal_code,
7156 p_ship_to_country => p_int_line_tbl(l_count).ship_to_country,
7157 p_ship_to_contact_party_id => p_int_line_tbl(l_count).ship_to_contact_party_id,
7158 p_ship_to_contact_name => p_int_line_tbl(l_count).ship_to_contact_name,
7159 p_ship_to_email => p_int_line_tbl(l_count).ship_to_email,
7160 p_ship_to_phone => p_int_line_tbl(l_count).ship_to_phone,
7161 p_ship_to_fax => p_int_line_tbl(l_count).ship_to_fax,
7162 p_ship_from_cust_account_id => p_int_line_tbl(l_count).ship_from_cust_account_id,
7163 p_ship_from_site_id => p_int_line_tbl(l_count).ship_from_site_id,
7164 p_ship_from_party_name => p_int_line_tbl(l_count).ship_from_party_name,
7165 p_ship_from_location => p_int_line_tbl(l_count).ship_from_location,
7166 p_ship_from_address => p_int_line_tbl(l_count).ship_from_address,
7167 p_ship_from_city => p_int_line_tbl(l_count).ship_from_city,
7168 p_ship_from_state => p_int_line_tbl(l_count).ship_from_state,
7169 p_ship_from_postal_code => p_int_line_tbl(l_count).ship_from_postal_code,
7170 p_ship_from_country => p_int_line_tbl(l_count).ship_from_country,
7171 p_ship_from_contact_party_id => p_int_line_tbl(l_count).ship_from_contact_party_id,
7172 p_ship_from_contact_name => p_int_line_tbl(l_count).ship_from_contact_name,
7173 p_ship_from_email => p_int_line_tbl(l_count).ship_from_email,
7174 p_ship_from_phone => p_int_line_tbl(l_count).ship_from_phone,
7175 p_ship_from_fax => p_int_line_tbl(l_count).ship_from_fax,
7176 p_sold_from_cust_account_id => p_int_line_tbl(l_count).sold_from_cust_account_id,
7177 p_sold_from_site_id => p_int_line_tbl(l_count).sold_from_site_id,
7178 p_sold_from_party_name => p_int_line_tbl(l_count).sold_from_party_name,
7179 p_sold_from_location => p_int_line_tbl(l_count).sold_from_location,
7180 p_sold_from_address => p_int_line_tbl(l_count).sold_from_address,
7181 p_sold_from_city => p_int_line_tbl(l_count).sold_from_city,
7182 p_sold_from_state => p_int_line_tbl(l_count).sold_from_state,
7183 p_sold_from_postal_code => p_int_line_tbl(l_count).sold_from_postal_code,
7184 p_sold_from_country => p_int_line_tbl(l_count).sold_from_country,
7185 p_sold_from_contact_party_id => p_int_line_tbl(l_count).sold_from_contact_party_id,
7186 p_sold_from_contact_name => p_int_line_tbl(l_count).sold_from_contact_name,
7187 p_sold_from_email => p_int_line_tbl(l_count).sold_from_email,
7188 p_sold_from_phone => p_int_line_tbl(l_count).sold_from_phone,
7189 p_sold_from_fax => p_int_line_tbl(l_count).sold_from_fax,
7190 p_order_number => p_int_line_tbl(l_count).order_number,
7191 p_date_ordered => p_int_line_tbl(l_count).date_ordered,
7192 p_po_number => p_int_line_tbl(l_count).po_number,
7193 p_po_release_number => p_int_line_tbl(l_count).po_release_number,
7194 p_po_type => p_int_line_tbl(l_count).po_type,
7195 p_agreement_id => p_int_line_tbl(l_count).agreement_id,
7196 p_agreement_name => p_int_line_tbl(l_count).agreement_name,
7197 p_agreement_type => p_int_line_tbl(l_count).agreement_type,
7198 p_agreement_price => p_int_line_tbl(l_count).agreement_price,
7199 p_agreement_uom_code => p_int_line_tbl(l_count).agreement_uom_code,
7200 p_corrected_agreement_id => p_int_line_tbl(l_count).corrected_agreement_id,
7201 p_corrected_agreement_name => p_int_line_tbl(l_count).corrected_agreement_name,
7202 p_price_list_id => p_int_line_tbl(l_count).price_list_id,
7203 p_price_list_name => p_int_line_tbl(l_count).price_list_name,
7204 p_orig_system_quantity => p_int_line_tbl(l_count).orig_system_quantity,
7205 p_orig_system_uom => p_int_line_tbl(l_count).orig_system_uom,
7206 p_orig_system_currency_code => p_int_line_tbl(l_count).orig_system_currency_code,
7207 p_orig_system_selling_price => p_int_line_tbl(l_count).orig_system_selling_price,
7208 p_orig_system_reference => p_int_line_tbl(l_count).orig_system_reference,
7209 p_orig_system_line_reference => p_int_line_tbl(l_count).orig_system_line_reference,
7210 p_orig_system_purchase_uom => p_int_line_tbl(l_count).orig_system_purchase_uom,
7211 p_orig_system_purchase_curr => p_int_line_tbl(l_count).orig_system_purchase_curr,
7212 p_orig_system_purchase_price => p_int_line_tbl(l_count).orig_system_purchase_price,
7213 p_orig_system_purchase_quant => p_int_line_tbl(l_count).orig_system_purchase_quantity,
7214 p_orig_system_agreement_uom => p_int_line_tbl(l_count).orig_system_agreement_uom,
7215 p_orig_system_agreement_name => p_int_line_tbl(l_count).orig_system_agreement_name,
7216 p_orig_system_agreement_type => p_int_line_tbl(l_count).orig_system_agreement_type,
7217 p_orig_system_agreement_status => p_int_line_tbl(l_count).orig_system_agreement_status,
7218 p_orig_system_agreement_curr => p_int_line_tbl(l_count).orig_system_agreement_curr,
7219 p_orig_system_agreement_price => p_int_line_tbl(l_count).orig_system_agreement_price,
7220 p_orig_system_agreement_quant => p_int_line_tbl(l_count).orig_system_agreement_quantity,
7221 p_orig_system_item_number => p_int_line_tbl(l_count).orig_system_item_number,
7222 p_quantity => p_int_line_tbl(l_count).quantity,
7223 p_uom_code => p_int_line_tbl(l_count).uom_code,
7224 p_currency_code => p_int_line_tbl(l_count).currency_code,
7225 p_exchange_rate => p_int_line_tbl(l_count).exchange_rate,
7226 p_exchange_rate_type => p_int_line_tbl(l_count).exchange_rate_type,
7227 p_exchange_rate_date => p_int_line_tbl(l_count).exchange_rate_date,
7228 p_selling_price => p_int_line_tbl(l_count).selling_price,
7229 p_purchase_uom_code => p_int_line_tbl(l_count).purchase_uom_code,
7230 p_invoice_number => p_int_line_tbl(l_count).invoice_number,
7231 p_date_invoiced => p_int_line_tbl(l_count).date_invoiced,
7232 p_date_shipped => p_int_line_tbl(l_count).date_shipped,
7233 p_credit_advice_date => p_int_line_tbl(l_count).credit_advice_date,
7234 p_product_category_id => p_int_line_tbl(l_count).product_category_id,
7235 p_category_name => p_int_line_tbl(l_count).category_name,
7236 p_inventory_item_segment1 => p_int_line_tbl(l_count).inventory_item_segment1,
7237 p_inventory_item_segment2 => p_int_line_tbl(l_count).inventory_item_segment2,
7238 p_inventory_item_segment3 => p_int_line_tbl(l_count).inventory_item_segment3,
7239 p_inventory_item_segment4 => p_int_line_tbl(l_count).inventory_item_segment4,
7240 p_inventory_item_segment5 => p_int_line_tbl(l_count).inventory_item_segment5,
7241 p_inventory_item_segment6 => p_int_line_tbl(l_count).inventory_item_segment6,
7242 p_inventory_item_segment7 => p_int_line_tbl(l_count).inventory_item_segment7,
7243 p_inventory_item_segment8 => p_int_line_tbl(l_count).inventory_item_segment8,
7244 p_inventory_item_segment9 => p_int_line_tbl(l_count).inventory_item_segment9,
7245 p_inventory_item_segment10 => p_int_line_tbl(l_count).inventory_item_segment10,
7246 p_inventory_item_segment11 => p_int_line_tbl(l_count).inventory_item_segment11,
7247 p_inventory_item_segment12 => p_int_line_tbl(l_count).inventory_item_segment12,
7248 p_inventory_item_segment13 => p_int_line_tbl(l_count).inventory_item_segment13,
7249 p_inventory_item_segment14 => p_int_line_tbl(l_count).inventory_item_segment14,
7250 p_inventory_item_segment15 => p_int_line_tbl(l_count).inventory_item_segment15,
7251 p_inventory_item_segment16 => p_int_line_tbl(l_count).inventory_item_segment16,
7252 p_inventory_item_segment17 => p_int_line_tbl(l_count).inventory_item_segment17,
7253 p_inventory_item_segment18 => p_int_line_tbl(l_count).inventory_item_segment18,
7254 p_inventory_item_segment19 => p_int_line_tbl(l_count).inventory_item_segment19,
7255 p_inventory_item_segment20 => p_int_line_tbl(l_count).inventory_item_segment20,
7256 p_inventory_item_id => p_int_line_tbl(l_count).inventory_item_id,
7257 p_item_description => p_int_line_tbl(l_count).item_description,
7258 p_upc_code => p_int_line_tbl(l_count).upc_code,
7259 p_item_number => p_int_line_tbl(l_count).item_number,
7260 p_claimed_amount => p_int_line_tbl(l_count).claimed_amount,
7261 p_purchase_price => p_int_line_tbl(l_count).purchase_price,
7262 p_acctd_purchase_price => p_int_line_tbl(l_count).acctd_purchase_price,
7263 p_net_adjusted_amount => p_int_line_tbl(l_count).net_adjusted_amount,
7264 p_accepted_amount => p_int_line_tbl(l_count).accepted_amount,
7265 p_total_accepted_amount => p_int_line_tbl(l_count).total_accepted_amount,
7266 p_allowed_amount => p_int_line_tbl(l_count).allowed_amount,
7267 p_total_allowed_amount => p_int_line_tbl(l_count).total_allowed_amount,
7268 p_calculated_price => p_int_line_tbl(l_count).calculated_price,
7269 p_acctd_calculated_price => p_int_line_tbl(l_count).acctd_calculated_price,
7270 p_calculated_amount => p_int_line_tbl(l_count).calculated_amount,
7271 p_line_tolerance_amount => p_int_line_tbl(l_count).line_tolerance_amount,
7272 p_total_claimed_amount => p_int_line_tbl(l_count).total_claimed_amount,
7273 p_credit_code => p_int_line_tbl(l_count).credit_code,
7274 p_direct_customer_flag => p_int_line_tbl(l_count).direct_customer_flag,
7275 p_duplicated_line_id => p_int_line_tbl(l_count).duplicated_line_id,
7276 p_duplicated_adjustment_id => p_int_line_tbl(l_count).duplicated_adjustment_id,
7277 p_order_type_id => p_int_line_tbl(l_count).order_type_id,
7278 p_order_type => p_int_line_tbl(l_count).order_type,
7279 p_order_category => p_int_line_tbl(l_count).order_category,
7280 p_dispute_code => p_int_line_tbl(l_count).dispute_code,
7281 p_data_source_code => p_int_line_tbl(l_count).data_source_code,
7282 p_tracing_flag => p_int_line_tbl(l_count).tracing_flag,
7283 p_header_attribute_category => p_int_line_tbl(l_count).header_attribute_category,
7284 p_header_attribute1 => p_int_line_tbl(l_count).header_attribute1,
7285 p_header_attribute2 => p_int_line_tbl(l_count).header_attribute2,
7286 p_header_attribute3 => p_int_line_tbl(l_count).header_attribute3,
7287 p_header_attribute4 => p_int_line_tbl(l_count).header_attribute4,
7288 p_header_attribute5 => p_int_line_tbl(l_count).header_attribute5,
7289 p_header_attribute6 => p_int_line_tbl(l_count).header_attribute6,
7290 p_header_attribute7 => p_int_line_tbl(l_count).header_attribute7,
7291 p_header_attribute8 => p_int_line_tbl(l_count).header_attribute8,
7292 p_header_attribute9 => p_int_line_tbl(l_count).header_attribute9,
7293 p_header_attribute10 => p_int_line_tbl(l_count).header_attribute10,
7294 p_header_attribute11 => p_int_line_tbl(l_count).header_attribute11,
7295 p_header_attribute12 => p_int_line_tbl(l_count).header_attribute12,
7296 p_header_attribute13 => p_int_line_tbl(l_count).header_attribute13,
7297 p_header_attribute14 => p_int_line_tbl(l_count).header_attribute14,
7298 p_header_attribute15 => p_int_line_tbl(l_count).header_attribute15,
7299 p_line_attribute_category => p_int_line_tbl(l_count).line_attribute_category,
7300 p_line_attribute1 => p_int_line_tbl(l_count).line_attribute1,
7301 p_line_attribute2 => p_int_line_tbl(l_count).line_attribute2,
7302 p_line_attribute3 => p_int_line_tbl(l_count).line_attribute3,
7303 p_line_attribute4 => p_int_line_tbl(l_count).line_attribute4,
7304 p_line_attribute5 => p_int_line_tbl(l_count).line_attribute5,
7305 p_line_attribute6 => p_int_line_tbl(l_count).line_attribute6,
7306 p_line_attribute7 => p_int_line_tbl(l_count).line_attribute7,
7307 p_line_attribute8 => p_int_line_tbl(l_count).line_attribute8,
7308 p_line_attribute9 => p_int_line_tbl(l_count).line_attribute9,
7309 p_line_attribute10 => p_int_line_tbl(l_count).line_attribute10,
7310 p_line_attribute11 => p_int_line_tbl(l_count).line_attribute11,
7311 p_line_attribute12 => p_int_line_tbl(l_count).line_attribute12,
7312 p_line_attribute13 => p_int_line_tbl(l_count).line_attribute13,
7313 p_line_attribute14 => p_int_line_tbl(l_count).line_attribute14,
7314 p_line_attribute15 => p_int_line_tbl(l_count).line_attribute15,
7315 p_org_id => p_int_line_tbl(l_count).org_id );
7316
7317
7318 END LOOP;
7319 END IF;
7320 EXCEPTION
7321
7322 WHEN OTHERS THEN
7323 OZF_UTILITY_PVT.error_message('OZF_API_DEBUG_MESSAGE','TEXT','Problem with updating line record'||sqlcode ||' '||sqlerrm);
7324 RAISE FND_API.G_EXC_ERROR;
7325
7326 END;
7327
7328 -- Standard check for p_commit
7329 IF FND_API.to_Boolean( p_commit )
7330 THEN
7331 COMMIT WORK;
7332 END IF;
7333
7334
7335 -- Debug Message
7336 IF OZF_DEBUG_HIGH_ON THEN
7337 ozf_utility_pvt.debug_message('Private API: ' || l_api_name || ' end');
7338 END IF;
7339
7340 -- Standard call to get message count and if count is 1, get message info.
7341 FND_MSG_PUB.Count_And_Get
7342 (p_count => x_msg_count,
7343 p_data => x_msg_data
7344 );
7345
7346 EXCEPTION
7347 WHEN FND_API.G_EXC_ERROR THEN
7348 x_return_status := FND_API.G_RET_STS_ERROR;
7349 -- Standard call to get message count and if count=1, get the message
7350 FND_MSG_PUB.Count_And_Get (
7351 p_encoded => FND_API.G_FALSE,
7352 p_count => x_msg_count,
7353 p_data => x_msg_data
7354 );
7355 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
7356 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
7357 -- Standard call to get message count and if count=1, get the message
7358 FND_MSG_PUB.Count_And_Get (
7359 p_encoded => FND_API.G_FALSE,
7360 p_count => x_msg_count,
7361 p_data => x_msg_data
7362 );
7363 WHEN OTHERS THEN
7364 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
7365 IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
7366 THEN
7367 FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
7368 END IF;
7369 -- Standard call to get message count and if count=1, get the message
7370 FND_MSG_PUB.Count_And_Get (
7371 p_encoded => FND_API.G_FALSE,
7372 p_count => x_msg_count,
7373 p_data => x_msg_data
7374 );
7375
7376
7377 END Update_interface_line;
7378
7379
7380 procedure Update_interface_batch (
7381 p_api_version_number IN NUMBER,
7382 p_init_msg_list IN VARCHAR2 := FND_API.G_FALSE,
7383 p_Commit IN VARCHAR2 := FND_API.G_FALSE,
7384 p_validation_level IN NUMBER := FND_API.G_VALID_LEVEL_FULL,
7385 p_int_batch_rec IN ozf_resale_batches_all%rowtype,
7386 x_return_status OUT NOCOPY VARCHAR2,
7387 x_msg_count OUT NOCOPY NUMBER,
7388 x_msg_data OUT NOCOPY VARCHAR2
7389 )
7390 IS
7391 l_api_name CONSTANT VARCHAR2(30) := 'update_interface_batch';
7392 l_api_version_number CONSTANT NUMBER := 1.0;
7393 BEGIN
7394 -- Debug Message
7395 IF OZF_DEBUG_HIGH_ON THEN
7396 ozf_utility_pvt.debug_message('Private API: ' || l_api_name || ' start');
7397 END IF;
7398
7399 -- Initialize API return status to SUCCESS
7400 x_return_status := FND_API.G_RET_STS_SUCCESS;
7401 IF OZF_DEBUG_HIGH_ON THEN
7402 ozf_utility_pvt.debug_message('x_return_status '||x_return_status);
7403 END IF;
7404
7405 BEGIN
7406 IF OZF_DEBUG_LOW_ON THEN
7407 ozf_utility_pvt.debug_message('Resale Batch ID ' || p_int_batch_rec.resale_batch_id);
7408 END IF;
7409 OZF_RESALE_BATCHES_PKG.Update_Row(
7410 p_resale_batch_id => p_int_batch_rec.resale_batch_id,
7411 p_object_version_number => p_int_batch_rec.object_version_number ,
7412 p_last_update_date => p_int_batch_rec.last_update_date,
7413 p_last_updated_by => p_int_batch_rec.last_updated_by,
7414 p_request_id => p_int_batch_rec.request_id,
7415 p_created_from => p_int_batch_rec.created_from,
7416 p_last_update_login => p_int_batch_rec.last_update_login,
7417 p_program_application_id => p_int_batch_rec.program_application_id,
7418 p_program_update_date => p_int_batch_rec.program_update_date,
7419 p_program_id => p_int_batch_rec.program_id,
7420 p_batch_number => p_int_batch_rec.batch_number,
7421 p_batch_type => p_int_batch_rec.batch_type,
7422 p_batch_count => p_int_batch_rec.batch_count,
7423 p_year => p_int_batch_rec.year,
7424 p_month => p_int_batch_rec.month,
7425 p_report_date => p_int_batch_rec.report_date,
7426 p_report_start_date => p_int_batch_rec.report_start_date,
7427 p_report_end_date => p_int_batch_rec.report_end_date,
7428 p_status_code => p_int_batch_rec.status_code,
7429 -- p_date_source_code => p_int_batch_rec.data_source_code, -- BUG 5077213
7430 p_reference_type => p_int_batch_rec.reference_type,
7431 p_reference_number => p_int_batch_rec.reference_number,
7432 p_comments => p_int_batch_rec.comments,
7433 p_partner_claim_number => p_int_batch_rec.partner_claim_number,
7434 p_transaction_purpose_code => p_int_batch_rec.transaction_purpose_code,
7435 p_transaction_type_code => p_int_batch_rec.transaction_type_code,
7436 p_partner_type => p_int_batch_rec.partner_type,
7437 p_partner_id => p_int_batch_rec.partner_id,
7438 p_partner_party_id => p_int_batch_rec.partner_party_id,
7439 p_partner_cust_account_id => p_int_batch_rec.partner_cust_account_id,
7440 p_partner_site_id => p_int_batch_rec.partner_site_id,
7441 p_partner_contact_party_id => p_int_batch_rec.partner_contact_party_id,
7442 p_partner_contact_name => p_int_batch_rec.partner_contact_name,
7443 p_partner_email => p_int_batch_rec.partner_email,
7444 p_partner_phone => p_int_batch_rec.partner_phone,
7445 p_partner_fax => p_int_batch_rec.partner_fax,
7446 p_header_tolerance_operand => p_int_batch_rec.header_tolerance_operand,
7447 p_header_tolerance_calc_code => p_int_batch_rec.header_tolerance_calc_code,
7448 p_line_tolerance_operand => p_int_batch_rec.line_tolerance_operand,
7449 p_line_tolerance_calc_code => p_int_batch_rec.line_tolerance_calc_code,
7450 p_currency_code => p_int_batch_rec.currency_code,
7451 p_claimed_amount => p_int_batch_rec.claimed_amount,
7452 p_allowed_amount => p_int_batch_rec.allowed_amount,
7453 p_paid_amount => p_int_batch_rec.paid_amount,
7454 p_disputed_amount => p_int_batch_rec.disputed_amount,
7455 p_accepted_amount => p_int_batch_rec.accepted_amount,
7456 p_lines_invalid => p_int_batch_rec.lines_invalid,
7457 p_lines_w_tolerance => p_int_batch_rec.lines_w_tolerance,
7458 p_lines_disputed => p_int_batch_rec.lines_disputed,
7459 p_batch_set_id_code => p_int_batch_rec.batch_set_id_code,
7460 p_credit_code => p_int_batch_rec.credit_code,
7461 p_credit_advice_date => p_int_batch_rec.credit_advice_date,
7462 p_purge_flag => p_int_batch_rec.purge_flag,
7463 p_attribute_category => p_int_batch_rec.attribute_category,
7464 p_attribute1 => p_int_batch_rec.attribute1,
7465 p_attribute2 => p_int_batch_rec.attribute2,
7466 p_attribute3 => p_int_batch_rec.attribute3,
7467 p_attribute4 => p_int_batch_rec.attribute4,
7468 p_attribute5 => p_int_batch_rec.attribute5,
7469 p_attribute6 => p_int_batch_rec.attribute6,
7470 p_attribute7 => p_int_batch_rec.attribute7,
7471 p_attribute8 => p_int_batch_rec.attribute8,
7472 p_attribute9 => p_int_batch_rec.attribute9,
7473 p_attribute10 => p_int_batch_rec.attribute10,
7474 p_attribute11 => p_int_batch_rec.attribute11,
7475 p_attribute12 => p_int_batch_rec.attribute12,
7476 p_attribute13 => p_int_batch_rec.attribute13,
7477 p_attribute14 => p_int_batch_rec.attribute14,
7478 p_attribute15 => p_int_batch_rec.attribute15,
7479 p_org_id => p_int_batch_rec.org_id );
7480
7481 EXCEPTION
7482
7483 WHEN OTHERS THEN
7484 OZF_UTILITY_PVT.error_message('OZF_API_DEBUG_MESSAGE','TEXT','Problem with updating batch record'||sqlcode ||' '||sqlerrm);
7485 RAISE FND_API.G_EXC_ERROR;
7486
7487 END;
7488
7489 -- Standard check for p_commit
7490 IF FND_API.to_Boolean( p_commit )
7491 THEN
7492 COMMIT WORK;
7493 END IF;
7494 -- Debug Message
7495 IF OZF_DEBUG_HIGH_ON THEN
7496 ozf_utility_pvt.debug_message('Private API: ' || l_api_name || ' end');
7497 END IF;
7498
7499 -- Standard call to get message count and if count is 1, get message info.
7500 FND_MSG_PUB.Count_And_Get
7501 (p_count => x_msg_count,
7502 p_data => x_msg_data
7503 );
7504
7505 EXCEPTION
7506
7507 WHEN FND_API.G_EXC_ERROR THEN
7508 x_return_status := FND_API.G_RET_STS_ERROR;
7509 -- Standard call to get message count and if count=1, get the message
7510 FND_MSG_PUB.Count_And_Get (
7511 p_encoded => FND_API.G_FALSE,
7512 p_count => x_msg_count,
7513 p_data => x_msg_data
7514 );
7515 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
7516 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
7517 -- Standard call to get message count and if count=1, get the message
7518 FND_MSG_PUB.Count_And_Get (
7519 p_encoded => FND_API.G_FALSE,
7520 p_count => x_msg_count,
7521 p_data => x_msg_data
7522 );
7523 WHEN OTHERS THEN
7524
7525 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
7526 IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
7527 THEN
7528 FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
7529 END IF;
7530 -- Standard call to get message count and if count=1, get the message
7531 FND_MSG_PUB.Count_And_Get (
7532 p_encoded => FND_API.G_FALSE,
7533 p_count => x_msg_count,
7534 p_data => x_msg_data
7535 );
7536 END update_interface_batch;
7537
7538 PROCEDURE Confirm_BOD_Enabled
7539 (
7540 itemtype in VARCHAR2,
7541 itemkey in VARCHAR2,
7542 actid in NUMBER,
7543 funcmode in VARCHAR2,
7544 result in out NOCOPY VARCHAR2
7545 )
7546 IS
7547 l_api_name CONSTANT VARCHAR2(30) := 'Confirm_BOD_Enabled';
7548 l_api_version_number CONSTANT NUMBER := 1.0;
7549
7550 l_trans_type ecx_tp_details_v.transaction_type%TYPE;
7551 l_trans_subtype ecx_tp_details_v.transaction_subtype%TYPE;
7552 l_party_id ecx_tp_headers_v.party_id%TYPE;
7553 l_party_site_id ecx_tp_headers_v.party_site_id%TYPE;
7554 l_resale_batch_id NUMBER;
7555
7556 l_enabled NUMBER;
7557 l_admin_email VARCHAR2(1000);
7558
7559 l_msg_count NUMBER;
7560 l_msg_data VARCHAR2(2000);
7561 l_return_status VARCHAR2(1);
7562 CURSOR get_confirmation ( pc_party_id NUMBER
7563 , pc_site_id NUMBER
7564 , pc_transaction_type VARCHAR2
7565 , pc_txn_sub_type VARCHAR2 )
7566 IS
7567 SELECT etd.confirmation, eth.company_admin_email
7568 FROM ecx_tp_headers_v eth
7569 , ecx_tp_details_v etd
7570 WHERE eth.tp_header_id = etd.tp_header_id
7571 AND eth.party_id = pc_party_id
7572 AND eth.party_site_id = pc_site_id
7573 AND etd.transaction_type = pc_transaction_type
7574 AND etd.transaction_subtype = pc_txn_sub_type;
7575
7576 CURSOR get_party ( pc_batch_id NUMBER )
7577 IS
7578 SELECT partner_party_id
7579 , partner_site_id
7580 FROM ozf_resale_batches
7581 WHERE resale_batch_id = pc_batch_id;
7582
7583
7584
7585 BEGIN
7586 IF OZF_DEBUG_HIGH_ON THEN
7587 ozf_utility_pvt.debug_message('In: ' || l_api_name || ' Funcmode: ' || funcmode);
7588 END IF;
7589
7590 IF (funcmode = 'RUN') THEN
7591
7592 l_party_id := wf_engine.GetItemAttrText(itemtype =>itemtype,
7593 itemkey =>itemkey,
7594 aname =>'PARAMETER2');
7595
7596 l_party_site_id := wf_engine.GetItemAttrText(itemtype =>itemtype,
7597 itemkey =>itemkey,
7598 aname =>'PARAMETER3');
7599
7600 l_trans_type := wf_engine.GetItemAttrText(itemtype =>itemtype,
7601 itemkey =>itemkey,
7602 aname =>'PARAMETER4');
7603
7604 l_trans_subtype := wf_engine.GetItemAttrText(itemtype =>itemtype,
7605 itemkey =>itemkey,
7606 aname =>'PARAMETER5');
7607
7608 IF l_party_id IS NULL AND l_party_site_id IS NULL THEN
7609 l_resale_batch_id := wf_engine.GetItemAttrText(itemtype =>itemtype,
7610 itemkey =>itemkey,
7611 aname =>'PARAMETER1');
7612 IF l_resale_batch_id IS NOT NULL THEN
7613 OPEN get_party ( l_resale_batch_id );
7614 FETCH get_party INTO l_party_id, l_party_site_id ;
7615 CLOSE get_party;
7616 END IF;
7617 l_trans_type := 'OZF';
7618 l_trans_subtype := 'POSI';
7619
7620 END IF;
7621
7622 OPEN get_confirmation ( l_party_id
7623 , l_party_site_id
7624 , l_trans_type
7625 , l_trans_subtype);
7626 FETCH get_confirmation INTO l_enabled, l_admin_email;
7627 CLOSE get_confirmation;
7628
7629 END IF;
7630 IF (l_enabled = 0 or l_enabled= 1) THEN
7631 result := 'F';
7632 ELSE
7633 result := 'T';
7637 aname => 'ECX_ADMINISTRATOR',
7634
7635 Wf_engine.setItemAttrText(itemtype => itemtype,
7636 itemkey => itemkey,
7638 avalue => l_admin_email);
7639
7640 END IF;
7641
7642 return;
7643
7644 EXCEPTION
7645 WHEN FND_API.G_EXC_ERROR THEN
7646 fnd_msg_pub.Count_And_Get(
7647 p_encoded => FND_API.G_TRUE
7648 ,p_count => l_msg_count
7649 ,p_data => l_msg_data);
7650
7651 wf_core.context(G_PKG_NAME, l_api_name,l_msg_data);
7652 raise;
7653 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
7654 fnd_msg_pub.Count_And_Get(
7655 p_encoded => FND_API.G_TRUE
7656 ,p_count => l_msg_count
7657 ,p_data => l_msg_data);
7658
7659 wf_core.context(G_PKG_NAME, l_api_name,l_msg_data);
7660 raise;
7661 WHEN OTHERS THEN
7662 fnd_msg_pub.Count_And_Get(
7663 p_encoded => FND_API.G_TRUE
7664 ,p_count => l_msg_count
7665 ,p_data => l_msg_data);
7666
7667 wf_core.context(G_PKG_NAME, l_api_name,l_msg_data);
7668 raise;
7669 END Confirm_BOD_Enabled;
7670
7671 PROCEDURE Send_Success_CBOD
7672 (
7673 itemtype in VARCHAR2,
7674 itemkey in VARCHAR2,
7675 actid in NUMBER,
7676 funcmode in VARCHAR2,
7677 result in out NOCOPY VARCHAR2
7678 )
7679 IS
7680 l_api_name CONSTANT VARCHAR2(30) := 'Send_Success_CBOD';
7681 l_api_version_number CONSTANT NUMBER := 1.0;
7682
7683 l_event_name VARCHAR2(120);
7684 l_icn NUMBER;
7685 l_event_key VARCHAR2(30);
7686 l_msg_count NUMBER;
7687 l_msg_data VARCHAR2(2000);
7688 l_return_status VARCHAR2(1);
7689
7690 BEGIN
7691 IF OZF_DEBUG_HIGH_ON THEN
7692 ozf_utility_pvt.debug_message('In: ' || l_api_name || ' Funcmode: ' || funcmode);
7693 END IF;
7694 IF( funcmode = 'RUN' ) THEN
7695
7696 l_event_key := wf_engine.GetItemAttrText(itemtype => itemtype,
7697 itemkey => itemkey,
7698 aname => 'EVENTKEY');
7699
7700
7701 raise_event
7702 (
7703 p_batch_id => to_number(l_event_key),
7704 p_event_name => g_xml_confirm_bod_event,
7705 x_return_status => l_return_status
7706 );
7707
7708 result := 'COMPLETE';
7709
7710 ELSIF (funcmode = 'CANCEL') THEN
7711 result := 'COMPLETE';
7712
7713 ELSIF (funcmode in ('RESPOND', 'FORWARD', 'TRANSFER')) THEN
7714 result := 'COMPLETE';
7715
7716 ELSIF (funcmode = 'TIMEOUT') THEN
7717 result := 'COMPLETE';
7718
7719 END IF;
7720 return;
7721 EXCEPTION
7722 WHEN FND_API.G_EXC_ERROR THEN
7723 fnd_msg_pub.Count_And_Get(
7724 p_encoded => FND_API.G_TRUE
7725 ,p_count => l_msg_count
7726 ,p_data => l_msg_data);
7727
7728 wf_core.context(G_PKG_NAME, l_api_name,l_msg_data);
7729 raise;
7730 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
7731 fnd_msg_pub.Count_And_Get(
7732 p_encoded => FND_API.G_TRUE
7733 ,p_count => l_msg_count
7734 ,p_data => l_msg_data);
7735
7736 wf_core.context(G_PKG_NAME, l_api_name,l_msg_data);
7737 raise;
7738 WHEN OTHERS THEN
7739 fnd_msg_pub.Count_And_Get(
7740 p_encoded => FND_API.G_TRUE
7741 ,p_count => l_msg_count
7742 ,p_data => l_msg_data);
7743
7744 wf_core.context(G_PKG_NAME, l_api_name,l_msg_data);
7745 raise;
7746 END Send_Success_CBOD;
7747
7748 PROCEDURE Send_Outbound
7749 (
7750 itemtype IN VARCHAR2,
7751 itemkey IN VARCHAR2,
7752 actid IN NUMBER,
7753 funcmode IN VARCHAR2,
7754 resultout IN OUT NOCOPY VARCHAR2
7755 )
7756 IS
7757 l_api_name CONSTANT VARCHAR2(30) := 'Send_Outbound';
7758 l_api_version_number CONSTANT NUMBER := 1.0;
7759
7760 l_resultout VARCHAR2(30);
7761 l_batch_id NUMBER;
7762 l_return_status VARCHAR2(1);
7763 l_msg_count NUMBER;
7764 l_msg_data VARCHAR2(2000);
7765 l_batch_status VARCHAR2(30);
7766 BEGIN
7767 IF OZF_DEBUG_HIGH_ON THEN
7768 ozf_utility_pvt.debug_message('In: ' || l_api_name || ' Funcmode: ' || funcmode);
7769 END IF;
7770
7771 IF (funcmode = 'RUN') THEN
7772
7773 IF itemtype = g_xml_import_workflow THEN
7774
7775 l_batch_id := wf_engine.GetItemAttrText(itemtype => itemtype,
7776 itemkey => itemkey,
7777 aname => 'PARAMETER1');
7778
7779 ELSIF itemtype = g_data_process_workflow THEN
7780
7781 l_batch_id := wf_engine.GetItemAttrText(itemtype => itemtype,
7782 itemkey => itemkey,
7783 aname => 'OZF_RESALE_BATCH_ID');
7784
7785 END IF;
7786 IF OZF_DEBUG_LOW_ON THEN
7787 ozf_utility_pvt.debug_message('Batch ID '|| l_batch_id);
7788 END IF;
7789 IF l_batch_id IS NOT NULL THEN
7790
7791 raise_event
7792 (
7793 p_batch_id => l_batch_id ,
7794 p_event_name => g_xml_outbound_event ,
7795 x_return_status => l_return_status
7796 );
7797 IF OZF_DEBUG_LOW_ON THEN
7798 ozf_utility_pvt.debug_message('Pre Process is complete '||l_return_status);
7799 END IF;
7800
7801 END IF;
7802
7803 l_resultout := 'COMPLETE:SUCCESS';
7804
7805 ELSIF (funcmode = 'CANCEL') THEN
7806 l_resultout := 'COMPLETE:SUCCESS';
7807
7808 ELSIF (funcmode in ('RESPOND', 'FORWARD', 'TRANSFER')) THEN
7809 l_resultout := 'COMPLETE:SUCCESS';
7810
7811 ELSIF (funcmode = 'TIMEOUT') THEN
7812 l_resultout := 'COMPLETE:SUCCESS';
7813
7814 END IF;
7815
7816 resultout := l_resultout;
7817
7818 EXCEPTION
7819 WHEN FND_API.G_EXC_ERROR THEN
7820 fnd_msg_pub.Count_And_Get(
7821 p_encoded => FND_API.G_TRUE
7822 ,p_count => l_msg_count
7823 ,p_data => l_msg_data);
7824
7825 wf_core.context(G_PKG_NAME, l_api_name,l_msg_data);
7826 raise;
7827 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
7828 fnd_msg_pub.Count_And_Get(
7829 p_encoded => FND_API.G_TRUE
7830 ,p_count => l_msg_count
7831 ,p_data => l_msg_data);
7832
7833 wf_core.context(G_PKG_NAME, l_api_name,l_msg_data);
7834 raise;
7835 WHEN OTHERS THEN
7836 fnd_msg_pub.Count_And_Get(
7837 p_encoded => FND_API.G_TRUE
7838 ,p_count => l_msg_count
7839 ,p_data => l_msg_data);
7840
7841 wf_core.context(G_PKG_NAME, l_api_name,l_msg_data);
7842 raise;
7843 END Send_Outbound;
7844
7845 PROCEDURE Raise_data_process
7846 (
7847 itemtype IN VARCHAR2,
7848 itemkey IN VARCHAR2,
7849 actid IN NUMBER,
7850 funcmode IN VARCHAR2,
7851 resultout IN OUT NOCOPY VARCHAR2
7852 )
7853 IS
7854 l_api_name CONSTANT VARCHAR2(30) := 'Raise_data_process';
7855 l_api_version_number CONSTANT NUMBER := 1.0;
7856
7857 l_resultout VARCHAR2(30);
7858 l_batch_id NUMBER;
7859 l_return_status VARCHAR2(1);
7860 l_msg_count NUMBER;
7861 l_msg_data VARCHAR2(2000);
7862 l_batch_status VARCHAR2(30);
7863 BEGIN
7864 IF OZF_DEBUG_HIGH_ON THEN
7865 ozf_utility_pvt.debug_message('In: ' || l_api_name || ' Funcmode: ' || funcmode);
7866 END IF;
7867
7868 IF (funcmode = 'RUN') THEN
7869
7870 l_batch_id := wf_engine.GetItemAttrText(itemtype => itemtype,
7871 itemkey => itemkey,
7872 aname => 'PARAMETER1');
7873 IF OZF_DEBUG_LOW_ON THEN
7874 ozf_utility_pvt.debug_message('Batch ID '|| l_batch_id);
7875 END IF;
7876
7877 IF l_batch_id IS NOT NULL THEN
7878
7879 raise_event
7880 (
7881 p_batch_id => l_batch_id ,
7882 p_event_name => g_xml_data_process_event ,
7883 x_return_status => l_return_status
7884 );
7885 IF OZF_DEBUG_LOW_ON THEN
7886 ozf_utility_pvt.debug_message('Pre Process is complete '||l_return_status);
7887 END IF;
7888
7889 END IF;
7890
7891 l_resultout := 'COMPLETE';
7892
7893 ELSIF (funcmode = 'CANCEL') THEN
7894 l_resultout := 'COMPLETE';
7895
7896 ELSIF (funcmode in ('RESPOND', 'FORWARD', 'TRANSFER')) THEN
7897 l_resultout := 'COMPLETE';
7898
7899 ELSIF (funcmode = 'TIMEOUT') THEN
7900 l_resultout := 'COMPLETE';
7901
7902 END IF;
7903
7904 resultout := l_resultout;
7905
7906 EXCEPTION
7907 WHEN FND_API.G_EXC_ERROR THEN
7908 fnd_msg_pub.Count_And_Get(
7909 p_encoded => FND_API.G_TRUE
7910 ,p_count => l_msg_count
7911 ,p_data => l_msg_data);
7912
7913 wf_core.context(G_PKG_NAME, l_api_name,l_msg_data);
7914 raise;
7915 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
7916 fnd_msg_pub.Count_And_Get(
7917 p_encoded => FND_API.G_TRUE
7918 ,p_count => l_msg_count
7919 ,p_data => l_msg_data);
7920
7921 wf_core.context(G_PKG_NAME, l_api_name,l_msg_data);
7922 raise;
7923 WHEN OTHERS THEN
7924 fnd_msg_pub.Count_And_Get(
7925 p_encoded => FND_API.G_TRUE
7926 ,p_count => l_msg_count
7927 ,p_data => l_msg_data);
7928
7929 wf_core.context(G_PKG_NAME, l_api_name,l_msg_data);
7930 raise;
7931 END Raise_data_process;
7932
7933
7934 PROCEDURE raise_event
7935 (
7936 p_batch_id IN NUMBER,
7937 p_event_name IN VARCHAR2,
7938 x_return_status OUT NOCOPY VARCHAR2
7939 )
7940 IS
7941
7942 l_api_name CONSTANT VARCHAR2(30) := 'raise_event';
7943 l_api_version_number CONSTANT NUMBER := 1.0;
7944
7945 l_event_name VARCHAR2 (120);
7946 l_event_key VARCHAR2 (100);
7947
7948 l_Return_Status VARCHAR2 (1);
7949 l_transaction_code VARCHAR2 (100);
7950 l_org_id NUMBER;
7951 l_party_id NUMBER;
7952 l_party_site_id NUMBER;
7953 l_confirm_descrtn VARCHAR2 (4000);
7954 l_msg_parameter_list WF_PARAMETER_LIST_T;
7955
7956 CURSOR get_batch ( pc_batch_id NUMBER)
7957 IS
7958 SELECT partner_party_id
7959 , partner_site_id
7960 FROM ozf_resale_batches
7961 WHERE resale_batch_id = pc_batch_id;
7962
7963 BEGIN
7964 IF OZF_DEBUG_HIGH_ON THEN
7965 ozf_utility_pvt.debug_message('Private API: ' || l_api_name || ' start');
7966 END IF;
7967
7968 -- Initialize API return status to SUCCESS
7969 x_return_status := FND_API.G_RET_STS_SUCCESS;
7970 IF OZF_DEBUG_LOW_ON THEN
7971 ozf_utility_pvt.debug_message('p_batch_id ' || p_batch_id);
7972 ozf_utility_pvt.debug_message('Event : ' || p_event_name || ' start');
7973 END IF;
7974
7975 IF p_batch_id IS NOT NULL THEN
7976 -- XML Outbound Event
7977
7978 IF p_event_name = g_xml_outbound_event THEN
7979 OPEN get_batch ( p_batch_id );
7980 FETCH get_batch INTO l_party_id, l_party_site_id;
7981 CLOSE get_batch;
7982
7983
7984 IF l_party_id IS NOT NULL AND l_party_site_id IS NOT NULL THEN
7985
7986 WF_EVENT.AddParameterToList (p_name => 'ECX_PARTY_ID',
7987 p_value => l_party_id,
7988 p_parameterlist => l_msg_parameter_list);
7989 WF_EVENT.AddParameterToList (p_name => 'ECX_PARTY_SITE_ID',
7990 p_value => l_party_site_id,
7991 p_parameterlist => l_msg_parameter_list);
7992 WF_EVENT.AddParameterToList (p_name => 'DOCUMENT_ID',
7993 p_value => p_batch_id,
7994 p_parameterlist => l_msg_parameter_list);
7995 WF_EVENT.AddParameterToList (p_name => 'ECX_TRANSACTION_TYPE',
7996 p_value => 'OZF',
7997 p_parameterlist => l_msg_parameter_list);
7998 WF_EVENT.AddParameterToList (p_name => 'ECX_TRANSACTION_SUBTYPE',
7999 p_value => 'POSO',
8000 p_parameterlist => l_msg_parameter_list);
8001 WF_EVENT.AddParameterToList (p_name => 'ECX_PARAMETER1',
8002 p_value => null,
8003 p_parameterlist => l_msg_parameter_list);
8004 WF_EVENT.AddParameterToList (p_name => 'ECX_PARAMETER2',
8005 p_value => null,
8006 p_parameterlist => l_msg_parameter_list);
8007 WF_EVENT.AddParameterToList (p_name => 'ECX_PARAMETER3',
8008 p_value => null,
8009 p_parameterlist => l_msg_parameter_list);
8010 WF_EVENT.AddParameterToList (p_name => 'ECX_PARAMETER4',
8011 p_value => null,
8012 p_parameterlist => l_msg_parameter_list);
8013 WF_EVENT.AddParameterToList (p_name => 'ECX_PARAMETER5',
8014 p_value => null,
8015 p_parameterlist => l_msg_parameter_list);
8016
8017 WF_EVENT.AddParameterToList(p_name=>'ECX_DEBUG_LEVEL',
8018 p_value=>'3',
8019 p_parameterlist=>l_msg_parameter_list);
8020
8021 l_event_key := p_batch_id||'-POSO-'||to_char(sysdate,'MM/DD/YYYY HH:MI:SS');
8022
8023 END IF;
8024 END IF;
8025 IF p_event_name = g_xml_data_process_event THEN
8026
8027 WF_EVENT.AddParameterToList( p_name => 'OZF_RESALE_BATCH_ID',
8028 p_value => p_batch_id,
8029 p_parameterlist => l_msg_parameter_list);
8030
8031 WF_EVENT.AddParameterToList( p_name => 'OZF_RESALE_BATCH_CALLER',
8032 p_value => 'XML',
8033 p_parameterlist => l_msg_parameter_list);
8034 IF p_event_name = g_xml_data_process_event THEN
8035 l_event_key := p_batch_id ||'-'||to_char(sysdate,'MM/DD/YYYY HH:MI:SS');
8036 ELSE
8037 l_event_key := 'Payment - '||p_batch_id ||'-'||to_char(sysdate,'MM/DD/YYYY HH:MI:SS');
8038 END IF;
8039 END IF;
8040 IF p_event_name = g_webadi_data_process_event THEN
8041
8042 WF_EVENT.AddParameterToList( p_name => 'OZF_RESALE_BATCH_ID',
8043 p_value => p_batch_id,
8044 p_parameterlist => l_msg_parameter_list);
8045
8046 WF_EVENT.AddParameterToList( p_name => 'OZF_RESALE_BATCH_CALLER',
8047 p_value => 'WEBADI',
8048 p_parameterlist => l_msg_parameter_list);
8052 END IF;
8049
8050 l_event_key := p_batch_id ||'-'||to_char(sysdate,'MM/DD/YYYY HH:MI:SS');
8051
8053
8054 IF p_event_name = g_xml_confirm_bod_event THEN
8055
8056 WF_EVENT.AddParameterToList( p_name=>'ECX_TRANSACTION_TYPE',
8057 p_value=>'ECX',
8058 p_parameterlist=>l_msg_parameter_list);
8059
8060 WF_EVENT.AddParameterToList( p_name=>'ECX_TRANSACTION_SUBTYPE',
8061 p_value=>'CBODO',
8062 p_parameterlist=>l_msg_parameter_list);
8063
8064
8065 WF_EVENT.AddParameterToList( p_name=>'CONFIRM_STATUSLVL',
8066 p_value=>'00',
8067 p_parameterlist=>l_msg_parameter_list);
8068
8069 FND_MESSAGE.set_name('OZF', 'OZF_XML_CONFIRM_INBOUND');
8070 l_confirm_descrtn := FND_MESSAGE.get;
8071
8072 WF_EVENT.AddParameterToList( p_name=>'CONFIRM_DESCRTN',
8073 p_value=>l_confirm_descrtn,
8074 p_parameterlist=>l_msg_parameter_list);
8075
8076
8077 WF_EVENT.AddParameterToList( p_name=>'ECX_DEBUG_LEVEL',
8078 p_value=>'3',
8079 p_parameterlist=>l_msg_parameter_list);
8080
8081 WF_EVENT.AddParameterToList( p_name=>'ECX_DOCUMENT_ID',
8082 p_value=>p_batch_id,
8083 p_parameterlist=>l_msg_parameter_list);
8084
8085
8086
8087 l_event_key := p_batch_id||'CBODO';
8088 END IF;
8089
8090 WF_EVENT.raise ( p_event_name => p_event_name,
8091 p_event_key => l_event_key,
8092 p_parameters => l_msg_parameter_list );
8093
8094 END IF;
8095 IF OZF_DEBUG_HIGH_ON THEN
8096 ozf_utility_pvt.debug_message('Private API: ' || l_api_name || ' end');
8097 END IF;
8098 EXCEPTION
8099 WHEN FND_API.G_EXC_ERROR THEN
8100 x_return_status := FND_API.G_RET_STS_ERROR;
8101 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
8102 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
8103 WHEN OTHERS THEN
8104
8105 OZF_UTILITY_PVT.error_message('OZF_API_DEBUG_MESSAGE','TEXT',sqlcode ||' '||sqlerrm);
8106 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
8107 END raise_event;
8108
8109
8110 PROCEDURE Insert_Resale_Log (
8111 p_id_value IN VARCHAR2,
8112 p_id_type IN VARCHAR2,
8113 p_error_code IN VARCHAR2,
8114 p_column_name IN VARCHAR2,
8115 p_column_value IN VARCHAR2,
8116 x_return_status OUT NOCOPY VARCHAR2 )
8117 IS
8118 l_api_name CONSTANT VARCHAR2(30) := 'Insert_Resale_Log';
8119 l_api_version_number CONSTANT NUMBER := 1.0;
8120 l_log_id NUMBER;
8121 l_org_id NUMBER;
8122 BEGIN
8123 IF OZF_DEBUG_HIGH_ON THEN
8124 ozf_utility_pvt.debug_message(l_api_name||': Start');
8125 END IF;
8126 --
8127 IF p_error_code IS NOT NULL THEN
8128 BEGIN
8129
8130 SELECT ozf_resale_logs_all_s.nextval into l_log_id from dual;
8131
8132 -- julou bug 6317120. get org_id from table
8133 IF p_id_type = 'BATCH' THEN
8134 OPEN OZF_RESALE_COMMON_PVT.gc_batch_org_id(p_id_value);
8135 FETCH OZF_RESALE_COMMON_PVT.gc_batch_org_id INTO l_org_id;
8136 CLOSE OZF_RESALE_COMMON_PVT.gc_batch_org_id;
8137 ELSIF p_id_type = 'LINE' THEN
8138 OPEN OZF_RESALE_COMMON_PVT.gc_line_org_id(p_id_value);
8139 FETCH OZF_RESALE_COMMON_PVT.gc_line_org_id INTO l_org_id;
8140 CLOSE OZF_RESALE_COMMON_PVT.gc_line_org_id;
8141 ELSIF p_id_type = 'IFACE' THEN
8142 OPEN OZF_RESALE_COMMON_PVT.gc_iface_org_id(p_id_value);
8143 FETCH OZF_RESALE_COMMON_PVT.gc_iface_org_id INTO l_org_id;
8144 CLOSE OZF_RESALE_COMMON_PVT.gc_iface_org_id;
8145 END IF;
8146
8147 OZF_RESALE_LOGS_PKG.Insert_Row(
8148 px_resale_log_id => l_log_id,
8149 p_resale_id => p_id_value,
8150 p_resale_id_type => p_id_type,
8151 p_error_code => p_error_code,
8152 p_error_message => fnd_message.get_string('OZF',p_error_code),
8153 p_column_name => p_column_name,
8154 p_column_value => p_column_value,
8155 --px_org_id => OZF_RESALE_COMMON_PVT.g_org_id
8156 px_org_id => l_org_id
8157 );
8158 EXCEPTION
8159 WHEN OTHERS THEN
8160 OZF_UTILITY_PVT.error_message('OZF_INS_RESALE_LOG_WRG');
8161 RAISE FND_API.g_exc_unexpected_error;
8162 END;
8163 END IF;
8164 --
8165 IF OZF_DEBUG_HIGH_ON THEN
8166 ozf_utility_pvt.debug_message(l_api_name||': End');
8167 END IF;
8168 EXCEPTION
8169 WHEN FND_API.G_EXC_ERROR THEN
8170 x_return_status := FND_API.G_RET_STS_ERROR;
8171 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
8172 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
8173 WHEN OTHERS THEN
8174 IF OZF_UNEXP_ERROR THEN
8175 FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
8176 END IF;
8177 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
8178 END Insert_Resale_Log;
8179
8180 END OZF_PRE_PROCESS_PVT;