DBA Data[Home] [Help]

PACKAGE BODY: APPS.OZF_PRE_PROCESS_PVT

Source


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