DBA Data[Home] [Help]

PACKAGE BODY: APPS.OZF_RESALE_WF_PVT

Source


1 PACKAGE BODY OZF_RESALE_WF_PVT AS
2 /* $Header: ozfvrwfb.pls 120.10 2007/11/13 09:59:39 bkunjan ship $ */
3 
4 -- Package name     : OZF_RESALE_WF_PVT
5 -- Purpose          : Called from Resale Data processing and Payment initiation workflows.
6 -- History          : CREATED       VANSUB      02-18-2004
7 --                  : MODIFICATIONS SLKRISHN    02-28-2004
8 -- NOTE             :
9 -- END of Comments
10 
11 G_FILE_NAME         CONSTANT VARCHAR2(30) := 'ozfvrwfb.pls';
12 
13 OZF_DEBUG_HIGH_ON            BOOLEAN := FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.g_msg_lvl_debug_high);
14 OZF_DEBUG_LOW_ON             BOOLEAN := FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.g_msg_lvl_debug_low);
15 OZF_UNEXP_ERROR     CONSTANT BOOLEAN := FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.g_msg_lvl_unexp_error);
16 OZF_ERROR           CONSTANT BOOLEAN := FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.g_msg_lvl_error);
17 
18 ---------------------------------------------------------------------
19 -- PROCEDURE
20 --    Handle_Error
21 --
22 -- PURPOSE
23 --    This procedure handles workflow errors
24 --
25 -- PARAMETERS
26 --
27 --
28 -- NOTES
29 ---------------------------------------------------------------------
30 PROCEDURE Handle_Error (
31     p_itemtype                 IN  VARCHAR2,
32     p_itemkey                  IN  VARCHAR2,
33     p_msg_count                IN  NUMBER,
34     p_msg_data                 IN  VARCHAR2,
35     p_process_name             IN  VARCHAR2,
36     x_error_msg                OUT NOCOPY VARCHAR2
37 )
38 IS
39 l_api_name            VARCHAR2(30) := 'Handle_Error';
40 l_msg_count           NUMBER ;
41 l_msg_data            VARCHAR2(2000);
42 l_error_msg           VARCHAR2(4000);
43 l_final_msg           VARCHAR2(4000);
44 l_msg_index           NUMBER;
45 --
46 l_resale_batch_id     NUMBER;
47 l_temp_mesg           VARCHAR2(2500);
48 BEGIN
49 
50    l_resale_batch_id := WF_ENGINE.GetItemAttrText(
51                            itemtype => p_itemtype,
52                            itemkey  => p_itemkey,
53                            aname    => G_WF_ATTR_BATCH_ID);
54 
55    FOR i IN 1..p_msg_count LOOP
56       FND_MSG_PUB.get(
57          p_msg_index       => p_msg_count - i +1 ,
58          p_encoded         => FND_API.g_false,
59          p_data            => l_msg_data,
60          p_msg_index_out   => l_msg_index
61       );
62       l_temp_mesg := l_msg_index ||': ' ||
63                      l_msg_data || fnd_global.local_chr(10);
64       IF length (l_final_msg ) + length (l_temp_mesg) >= 4000 THEN
65          goto end_loop_error;
66       END IF;
67       l_final_msg := l_final_msg ||
68                      l_msg_index ||': ' ||
69                      l_msg_data || fnd_global.local_chr(10);
70 
71       << end_loop_error >>
72       null;
73    END LOOP ;
74    x_error_msg   := l_final_msg;
75 
76    WF_ENGINE.SetItemAttrText(
77        itemtype   => p_itemtype,
78        itemkey    => p_itemkey ,
79        aname      => G_WF_ATTR_ERROR_MESG,
80        avalue     => l_final_msg );
81 EXCEPTION
82    WHEN OTHERS THEN
83       IF OZF_UNEXP_ERROR THEN
84          FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
85       END IF;
86       RAISE;
87 END Handle_Error;
88 
89 ---------------------------------------------------------------------
90 -- PROCEDURE
91 --    Check_Duplicates
92 --
93 -- PURPOSE
94 --    This procedure validates all the lines IN the batch
95 --
96 -- PARAMETERS
97 --
98 --
99 -- NOTES
100 ---------------------------------------------------------------------
101 PROCEDURE Check_Duplicates
102 (
103    itemtype   IN varchar2,
104    itemkey    IN varchar2,
105    actid      IN number,
106    funcmode   IN varchar2,
107    resultout  IN OUT NOCOPY varchar2
108 )
109 IS
110    l_api_name            CONSTANT VARCHAR2(30) := 'Check_Duplicates';
111    l_api_version_number  CONSTANT NUMBER   := 1.0;
112 
113    l_resultout           VARCHAR2(30);
114    l_batch_id            NUMBER;
115    l_return_status       VARCHAR2(1);
116    l_msg_count           NUMBER;
117    l_msg_data            VARCHAR2(2000);
118    l_error_msg           VARCHAR2(4000);
119    l_batch_type          VARCHAR2(30);
120    l_batch_status        VARCHAR2(30);
121    l_batch_return_status        VARCHAR2(30);
122 
123 CURSOR batch_status_csr(p_id number) IS
124 SELECT status_code
125  --FROM  ozf_resale_batches
126  FROM  ozf_resale_batches_all
127  WHERE resale_batch_id = p_id;
128 
129 l_batch_org_id               NUMBER;
130 
131 BEGIN
132    IF OZF_DEBUG_HIGH_ON THEN
133       OZF_UTILITY_PVT.debug_message('IN: ' || l_api_name || ' Funcmode: ' || funcmode);
134    END IF;
135 
136    -- R12 MOAC Enhancement (+)
137    l_batch_org_id := WF_ENGINE.GetItemAttrText(
138                         itemtype  => itemtype,
139                         itemkey   => itemkey,
140                         aname     => 'OZF_BATCH_ORG_ID'
141                      );
142 
143    IF (funcmode = 'TEST_CTX') THEN
144       IF (NVL(MO_GLOBAL.get_access_mode, 'NULL') <> 'S') OR
145           (NVL(MO_GLOBAL.get_current_org_id, -99) <> l_batch_org_id) THEN
146          resultout := 'FALSE';
147       ELSE
148          resultout := 'TRUE';
149       END IF;
150       RETURN;
151    END IF;
152 
153    IF (funcmode = 'SET_CTX') THEN
154       MO_GLOBAL.set_policy_context(
155          p_access_mode  => 'S',
156          p_org_id       => l_batch_org_id
157       );
158       --resultout := 'COMPLETE:';
159       RETURN;
160    END IF;
161    -- R12 MOAC Enhancement (-)
162 
163    IF (funcmode = 'RUN') THEN
164       --
165       l_batch_id := WF_ENGINE.GetItemAttrText(itemtype   => itemtype,
166                                               itemkey  => itemkey,
167                                               aname    => G_WF_ATTR_BATCH_ID);
168       IF OZF_DEBUG_LOW_ON THEN
169          OZF_UTILITY_PVT.debug_message('Batch ID '|| l_batch_id);
170       END IF;
171 
172       IF l_batch_id IS NOT NULL THEN
173          l_batch_type := WF_ENGINE.GetItemAttrText (itemtype => itemType,
174                                     itemkey  => itemKey,
175                                     aname    => G_WF_ATTR_BATCH_TYPE);
176 
177          OPEN batch_status_csr(l_batch_id);
178          FETCH batch_status_csr into l_batch_status;
179          CLOSE batch_status_csr;
180 
181          IF l_batch_status = OZF_RESALE_COMMON_PVT.G_BATCH_PENDING_PAYMENT THEN
182            l_batch_return_status := l_batch_status;
183          ELSE
184            OZF_RESALE_COMMON_PVT.Update_Duplicates (
185             p_api_version        => 1.0,
186             p_init_msg_list      => FND_API.G_FALSE,
187             p_commit             => FND_API.G_FALSE,
188             p_validation_level   => FND_API.G_VALID_LEVEL_FULL,
189             p_resale_batch_id    => l_batch_id,
190             p_resale_batch_type  => l_batch_type,
191             p_batch_status       => l_batch_status,
192             x_batch_status       => l_batch_return_status,
193             x_return_status      => l_return_status,
194             x_msg_count          => l_msg_count,
195             x_msg_data           => l_msg_data);
196 
197            IF OZF_DEBUG_LOW_ON THEN
198             OZF_UTILITY_PVT.debug_message('Check duplicate line is complete '||l_return_status);
199             OZF_UTILITY_PVT.debug_message('batch status '||l_batch_return_status);
200            END IF;
201            IF l_return_status <>  FND_API.G_RET_STS_SUCCESS THEN
202             RAISE FND_API.G_EXC_ERROR;
203            END IF;
204          END IF;
205       ELSE
206          OZF_UTILITY_PVT.error_message('OZF_RESALE_BATCH_ID_NULL');
207          RAISE FND_API.G_EXC_ERROR;
208       END IF;
209 
210       WF_ENGINE.SetItemAttrText(
211          itemtype   => itemtype,
212          itemkey    => itemkey ,
213          aname      => G_WF_ATTR_BATCH_STATUS,
214          avalue     => l_batch_return_status );
215 
216       IF l_batch_return_status not in (OZF_RESALE_COMMON_PVT.G_BATCH_PROCESSED,
217                                 OZF_RESALE_COMMON_PVT.G_BATCH_REJECTED,
218                                 OZF_RESALE_COMMON_PVT.G_BATCH_CLOSED) THEN
219          l_resultout := 'COMPLETE:OTHER';
220       ELSE
221          l_resultout := 'COMPLETE:' || l_batch_return_status;
222       END IF;
223       --
224    ELSIF (funcmode = 'CANCEL') THEN
225       l_resultout := 'COMPLETE:';
226    ELSIF (funcmode IN ('RESPOND', 'FORWARD', 'TRANSFER')) THEN
227       l_resultout := 'COMPLETE:';
228    ELSIF (funcmode = 'TIMEOUT') THEN
229       l_resultout := 'COMPLETE:';
230    END IF;
231 
232    resultout := l_resultout;
233 
234 EXCEPTION
235    WHEN FND_API.G_EXC_ERROR THEN
236       FND_MSG_PUB.Count_And_Get (
237           p_encoded => FND_API.G_FALSE,
238           p_count => l_msg_count,
239           p_data  => l_msg_data
240       );
241       Handle_Error(
242           p_itemtype     => itemtype
243          ,p_itemkey      => itemkey
244          ,p_msg_count    => l_msg_count
245          ,p_msg_data     => l_msg_data
246          ,p_process_name => l_api_name
247          ,x_error_msg    => l_error_msg
248       );
249       WF_CORE.context( G_PKG_NAME,l_api_name,itemtype,itemkey,actid,l_error_msg);
250       RAISE;
251    WHEN OTHERS THEN
252       IF OZF_UNEXP_ERROR THEN
253          FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
254       END IF;
255       FND_MSG_PUB.Count_And_Get (
256           p_encoded => FND_API.G_FALSE,
257           p_count => l_msg_count,
258           p_data  => l_msg_data
259       );
260       Handle_Error(
261           p_itemtype     => itemtype
262          ,p_itemkey      => itemkey
263          ,p_msg_count    => l_msg_count
264          ,p_msg_data     => l_msg_data
265          ,p_process_name => l_api_name
266          ,x_error_msg    => l_error_msg
267       );
268       WF_CORE.context( G_PKG_NAME,l_api_name,itemtype,itemkey,actid,l_error_msg);
269       RAISE;
270 END Check_Duplicates;
271 
272 ---------------------------------------------------------------------
273 -- PROCEDURE
274 --    Get_Auto_Accrual_Flag
275 --
276 -- PURPOSE
277 --    This procedure returns values of auto_tp_accrual_flag from system parameter
278 --
279 -- PARAMETERS
280 --
281 --
282 -- NOTES
283 --      returns F or T
284 ---------------------------------------------------------------------
285 PROCEDURE Get_Auto_Accrual_Flag(
286    itemtype   in varchar2,
287    itemkey    in varchar2,
288    actid      in number,
289    funcmode   in varchar2,
290    resultout  in OUT NOCOPY varchar2
291 )IS
292 l_api_name            CONSTANT VARCHAR2(30) := 'Get_Auto_Accrual_Flag';
293 l_api_version_number  CONSTANT NUMBER   := 1.0;
294 l_return_status       VARCHAR2(1);
295 l_msg_count           NUMBER;
296 l_msg_data            VARCHAR2(2000);
297 l_error_msg           VARCHAR2(4000);
298 
299 l_resultout            VARCHAR2(30);
300 l_auto_tp_accrual      VARCHAR2(1);
301 --
302 CURSOR auto_tp_accrual_csr IS
303 SELECT auto_tp_accrual_flag
304   FROM ozf_sys_parameters;
305 
306 l_batch_org_id               NUMBER;
307 BEGIN
308    IF OZF_DEBUG_HIGH_ON THEN
309       OZF_UTILITY_PVT.debug_message('IN ' || l_api_name || ' Funcmode: ' || funcmode);
310    END IF;
311 
312    -- R12 MOAC Enhancement (+)
313    l_batch_org_id := WF_ENGINE.GetItemAttrText(
314                         itemtype  => itemtype,
315                         itemkey   => itemkey,
316                         aname     => 'OZF_BATCH_ORG_ID'
317                      );
318 
319    IF (funcmode = 'TEST_CTX') THEN
320       IF (NVL(MO_GLOBAL.get_access_mode, 'NULL') <> 'S') OR
321           (NVL(MO_GLOBAL.get_current_org_id, -99) <> l_batch_org_id) THEN
322          resultout := 'FALSE';
323       ELSE
324          resultout := 'TRUE';
325       END IF;
326       RETURN;
327    END IF;
328 
329    IF (funcmode = 'SET_CTX') THEN
330       MO_GLOBAL.set_policy_context(
331          p_access_mode  => 'S',
332          p_org_id       => l_batch_org_id
333       );
334       --resultout := 'COMPLETE:';
335       RETURN;
336    END IF;
337    -- R12 MOAC Enhancement (-)
338 
339    IF (funcmode = 'RUN') THEN
340       --
341       OPEN auto_tp_accrual_csr;
342       FETCH auto_tp_accrual_csr INTO l_auto_tp_accrual;
343       CLOSE auto_tp_accrual_csr;
344 
345       IF l_auto_tp_accrual is NULL THEN
346          -- 11/23/04 yizhang: default flag to FALSE instead of raising an error
347          l_auto_tp_accrual := 'F';
348          --OZF_UTILITY_PVT.error_message('OZF_RESALE_AUTO_TP_NULL');
349          --RAISE FND_API.G_EXC_ERROR;
350       END IF;
351       l_resultout := 'COMPLETE:' || l_auto_tp_accrual;
352       --
353    ELSIF (funcmode = 'CANCEL') THEN
354       l_resultout := 'COMPLETE:';
355    ELSIF (funcmode IN ('RESPOND', 'FORWARD', 'TRANSFER')) THEN
356       l_resultout := 'COMPLETE:';
357    ELSIF (funcmode = 'TIMEOUT') THEN
358       l_resultout := 'COMPLETE:';
359    END IF;
360 
361    resultout := l_resultout;
362 
363 EXCEPTION
364    WHEN FND_API.G_EXC_ERROR THEN
365       FND_MSG_PUB.Count_And_Get (
366           p_encoded => FND_API.G_FALSE,
367           p_count => l_msg_count,
368           p_data  => l_msg_data
369       );
370       Handle_Error(
371           p_itemtype     => itemtype
372          ,p_itemkey      => itemkey
373          ,p_msg_count    => l_msg_count
374          ,p_msg_data     => l_msg_data
375          ,p_process_name => l_api_name
376          ,x_error_msg    => l_error_msg
377       );
378       WF_CORE.context( G_PKG_NAME,l_api_name,itemtype,itemkey,actid,l_error_msg);
379       RAISE;
380    WHEN OTHERS THEN
381       IF OZF_UNEXP_ERROR THEN
382          FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
383       END IF;
384       FND_MSG_PUB.Count_And_Get (
385           p_encoded => FND_API.G_FALSE,
386           p_count => l_msg_count,
387           p_data  => l_msg_data
388       );
389       Handle_Error(
390           p_itemtype     => itemtype
391          ,p_itemkey      => itemkey
392          ,p_msg_count    => l_msg_count
393          ,p_msg_data     => l_msg_data
394          ,p_process_name => l_api_name
395          ,x_error_msg    => l_error_msg
396       );
397       WF_CORE.context( G_PKG_NAME,l_api_name,itemtype,itemkey,actid,l_error_msg);
398       RAISE;
399 END Get_Auto_Accrual_Flag;
400 
401 ---------------------------------------------------------------------
402 -- PROCEDURE
403 --    Get_Batch_Caller
404 --
405 -- PURPOSE
406 --    This procedure returns the batch type to workflow
407 --
408 -- PARAMETERS
409 --
410 --
411 -- NOTES
412 ---------------------------------------------------------------------
413 PROCEDURE Get_Batch_Caller (
414    itemtype   IN varchar2,
415    itemkey    IN varchar2,
416    actid      IN number,
417    funcmode   IN varchar2,
418    resultout  IN OUT NOCOPY varchar2
419 )
420 IS
421 l_api_name            CONSTANT VARCHAR2(30) := 'Get_Batch_Caller';
422 l_api_version_number  CONSTANT NUMBER   := 1.0;
423 
424 l_resultout            VARCHAR2(30);
425 l_batch_id             NUMBER;
426 l_return_status        VARCHAR2(1);
427 l_msg_count            NUMBER;
428 l_msg_data             VARCHAR2(2000);
429 l_error_msg            VARCHAR2(4000);
430 l_batch_caller         VARCHAR2(30);
431 l_batch_num_w_date     VARCHAR2(240);
432 l_batch_number         VARCHAR2(240);
433 l_batch_org_id               NUMBER;
434 
435 BEGIN
436    IF OZF_DEBUG_HIGH_ON THEN
437       OZF_UTILITY_PVT.debug_message('IN ' || l_api_name || ' Funcmode: ' || funcmode);
438    END IF;
439 
440    -- R12 MOAC Enhancement (+)
441    l_batch_org_id := WF_ENGINE.GetItemAttrText(
442                         itemtype  => itemtype,
443                         itemkey   => itemkey,
444                         aname     => 'OZF_BATCH_ORG_ID'
445                      );
446 
447    IF (funcmode = 'TEST_CTX') THEN
448       IF (NVL(MO_GLOBAL.get_access_mode, 'NULL') <> 'S') OR
449           (NVL(MO_GLOBAL.get_current_org_id, -99) <> l_batch_org_id) THEN
450          resultout := 'FALSE';
451       ELSE
452          resultout := 'TRUE';
453       END IF;
454       RETURN;
455    END IF;
456 
457    IF (funcmode = 'SET_CTX') THEN
458       MO_GLOBAL.set_policy_context(
459          p_access_mode  => 'S',
460          p_org_id       => l_batch_org_id
461       );
462       --resultout := 'COMPLETE:';
463       RETURN;
464    END IF;
465    -- R12 MOAC Enhancement (-)
466 
467    IF (funcmode = 'RUN') THEN
468       --
469       l_batch_caller := WF_ENGINE.GetItemAttrText(itemtype => itemtype,
470                                                 itemkey  => itemkey,
471                                                 aname    => G_WF_ATTR_BATCH_CALLER);
472 
473       IF l_batch_caller is NULL THEN
474          -- default caller to be UI
475          l_batch_caller := G_WF_LKUP_UI;
476          WF_ENGINE.SetItemAttrText(
477             itemtype   => itemtype,
478             itemkey    => itemkey ,
479             aname      => G_WF_ATTR_BATCH_CALLER,
480             avalue     => l_batch_caller);
481       END IF;
482 
483       IF l_batch_caller NOT IN (G_WF_LKUP_UI, G_WF_LKUP_XML, G_WF_LKUP_WEBADI)
484       THEN
485          OZF_UTILITY_PVT.error_message('OZF_API_DEBUG_MESSAGE','TEXT','Invalid Batch caller '|| l_batch_caller);
486          RAISE FND_API.G_EXC_ERROR;
487       END IF;
488 
489       -- SET attribute OZF_BATCH_NUM_W_DATE for event key
490       l_batch_number := WF_ENGINE.GetItemAttrText(
491                         itemtype => itemtype,
492                         itemkey  => itemkey,
493                         aname    => G_WF_ATTR_BATCH_NUMBER
494                   );
495       l_batch_num_w_date :='ResaleBatch:'||l_batch_number||'-'|| to_char(sysdate,'MM/DD/YYYY HH:MI:SS');
496 
497       WF_ENGINE.SetItemAttrText(
498          itemtype   => itemtype,
499          itemkey    => itemkey ,
500          aname      => G_WF_ATTR_BATCH_NUM_W_DATE,
501          avalue     => l_batch_num_w_date);
502 
503       IF OZF_DEBUG_LOW_ON THEN
504          OZF_UTILITY_PVT.debug_message('Batch caller'||   l_batch_caller );
505       END IF;
506       l_resultout := 'COMPLETE:' || l_batch_caller;
507       --
508    ELSIF (funcmode = 'CANCEL') THEN
509       l_resultout := 'COMPLETE:';
510    ELSIF (funcmode IN ('RESPOND', 'FORWARD', 'TRANSFER')) THEN
511       l_resultout := 'COMPLETE:';
512    ELSIF (funcmode = 'TIMEOUT') THEN
513       l_resultout := 'COMPLETE:';
514    END IF;
515 
516    resultout := l_resultout;
517 
518 EXCEPTION
519    WHEN FND_API.G_EXC_ERROR THEN
520       FND_MSG_PUB.Count_And_Get (
521           p_encoded => FND_API.G_FALSE,
522           p_count => l_msg_count,
523           p_data  => l_msg_data
524       );
525       Handle_Error(
526           p_itemtype     => itemtype
527          ,p_itemkey      => itemkey
528          ,p_msg_count    => l_msg_count
529          ,p_msg_data     => l_msg_data
530          ,p_process_name => l_api_name
531          ,x_error_msg    => l_error_msg
532       );
533       WF_CORE.context( G_PKG_NAME,l_api_name,itemtype,itemkey,actid,l_error_msg);
534       RAISE;
535    WHEN OTHERS THEN
536       IF OZF_UNEXP_ERROR THEN
537          FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
538       END IF;
539       FND_MSG_PUB.Count_And_Get (
540           p_encoded => FND_API.G_FALSE,
541           p_count => l_msg_count,
542           p_data  => l_msg_data
543       );
544       Handle_Error(
545           p_itemtype     => itemtype
546          ,p_itemkey      => itemkey
547          ,p_msg_count    => l_msg_count
548          ,p_msg_data     => l_msg_data
549          ,p_process_name => l_api_name
550          ,x_error_msg    => l_error_msg
551       );
552       WF_CORE.context( G_PKG_NAME,l_api_name,itemtype,itemkey,actid,l_error_msg);
553       RAISE;
554 END Get_Batch_Caller;
555 
556 ---------------------------------------------------------------------
557 -- PROCEDURE
558 --    Get_Batch_Status
559 --
560 -- PURPOSE
561 --    This procedure returns the value of batch status
562 --
563 -- PARAMETERS
564 --
565 --
566 -- NOTES
567 ---------------------------------------------------------------------
568 PROCEDURE Get_Batch_Status (
569    itemtype   in varchar2,
570    itemkey    in varchar2,
571    actid      in number,
572    funcmode   in varchar2,
573    resultout  in OUT NOCOPY varchar2 )
574 IS
575    l_api_name            CONSTANT VARCHAR2(30) := 'Get_Batch_Status';
576    l_api_version_number  CONSTANT NUMBER   := 1.0;
577 
578    l_resultout            VARCHAR2(30);
579    l_batch_id             NUMBER;
580    l_return_status        VARCHAR2(1);
581    l_msg_count            NUMBER;
582    l_msg_data             VARCHAR2(2000);
583    l_error_msg            VARCHAR2(4000);
584    l_status_code          VARCHAR2(30);
585 
586 CURSOR batch_status_csr(p_id number) IS
587 SELECT status_code
588  --FROM  ozf_resale_batches
589  FROM  ozf_resale_batches_all
590  WHERE resale_batch_id = p_id;
591 
592 l_batch_org_id               NUMBER;
593 BEGIN
594    IF OZF_DEBUG_HIGH_ON THEN
595       OZF_UTILITY_PVT.debug_message('IN ' || l_api_name || ' Funcmode: ' || funcmode);
596    END IF;
597 
598    -- R12 MOAC Enhancement (+)
599    l_batch_org_id := WF_ENGINE.GetItemAttrText(
600                         itemtype  => itemtype,
601                         itemkey   => itemkey,
602                         aname     => 'OZF_BATCH_ORG_ID'
603                      );
604 
605    IF (funcmode = 'TEST_CTX') THEN
606       IF (NVL(MO_GLOBAL.get_access_mode, 'NULL') <> 'S') OR
607           (NVL(MO_GLOBAL.get_current_org_id, -99) <> l_batch_org_id) THEN
608          resultout := 'FALSE';
609       ELSE
610          resultout := 'TRUE';
611       END IF;
612       RETURN;
613    END IF;
614 
615    IF (funcmode = 'SET_CTX') THEN
616       MO_GLOBAL.set_policy_context(
617          p_access_mode  => 'S',
618          p_org_id       => l_batch_org_id
619       );
620       --resultout := 'COMPLETE:';
621       RETURN;
622    END IF;
623    -- R12 MOAC Enhancement (-)
624 
625    IF (funcmode = 'RUN') THEN
626       --
627       l_batch_id := WF_ENGINE.GetItemAttrText(itemtype => itemtype,
628                                                 itemkey  => itemkey,
629                                                 aname    => G_WF_ATTR_BATCH_ID);
630 
631       OPEN batch_status_csr(l_batch_id);
632       FETCH batch_status_csr into l_status_code;
633       CLOSE batch_status_csr;
634 
635       IF OZF_DEBUG_LOW_ON THEN
636          OZF_UTILITY_PVT.debug_message('Batch status '||   l_status_code );
637       END IF;
638       IF l_status_code not in ( OZF_RESALE_COMMON_PVT.G_BATCH_PROCESSED,
639                                 OZF_RESALE_COMMON_PVT.G_BATCH_REJECTED,
640                                 OZF_RESALE_COMMON_PVT.G_BATCH_CLOSED) THEN
641          l_resultout := 'COMPLETE:OTHER';
642       ELSE
643          l_resultout := 'COMPLETE:' || l_status_code;
644       END IF;
645       --
646    ELSIF (funcmode = 'CANCEL') THEN
647       l_resultout := 'COMPLETE:';
648    ELSIF (funcmode IN ('RESPOND', 'FORWARD', 'TRANSFER')) THEN
649       l_resultout := 'COMPLETE:';
650    ELSIF (funcmode = 'TIMEOUT') THEN
651       l_resultout := 'COMPLETE:';
652    END IF;
653 
654    resultout := l_resultout;
655 
656 EXCEPTION
657    WHEN FND_API.G_EXC_ERROR THEN
658       FND_MSG_PUB.Count_And_Get (
659           p_encoded => FND_API.G_FALSE,
660           p_count => l_msg_count,
661           p_data  => l_msg_data
662       );
663       Handle_Error(
664           p_itemtype     => itemtype
665          ,p_itemkey      => itemkey
666          ,p_msg_count    => l_msg_count
667          ,p_msg_data     => l_msg_data
668          ,p_process_name => l_api_name
669          ,x_error_msg    => l_error_msg
670       );
671       WF_CORE.context( G_PKG_NAME,l_api_name,itemtype,itemkey,actid,l_error_msg);
672       RAISE;
673    WHEN OTHERS THEN
674       IF OZF_UNEXP_ERROR THEN
675          FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
676       END IF;
677       FND_MSG_PUB.Count_And_Get (
678           p_encoded => FND_API.G_FALSE,
679           p_count => l_msg_count,
680           p_data  => l_msg_data
681       );
682       Handle_Error(
683           p_itemtype     => itemtype
684          ,p_itemkey      => itemkey
685          ,p_msg_count    => l_msg_count
686          ,p_msg_data     => l_msg_data
687          ,p_process_name => l_api_name
688          ,x_error_msg    => l_error_msg
689       );
690       WF_CORE.context( G_PKG_NAME,l_api_name,itemtype,itemkey,actid,l_error_msg);
691       RAISE;
692 END Get_Batch_Status;
693 
694 ---------------------------------------------------------------------
695 -- PROCEDURE
696 --    Get_Batch_Type
697 --
698 -- PURPOSE
699 --    This procedure returns the batch type to workflow
700 --
701 -- PARAMETERS
702 --
703 --
704 -- NOTES
705 ---------------------------------------------------------------------
706 PROCEDURE Get_Batch_Type (
707    itemtype   IN varchar2,
708    itemkey    IN varchar2,
709    actid      IN number,
710    funcmode   IN varchar2,
711    resultout  IN OUT NOCOPY varchar2
712 )
713 IS
714    l_api_name            CONSTANT VARCHAR2(30) := 'Get_Batch_Type';
715    l_api_version_number  CONSTANT NUMBER   := 1.0;
716 
717    l_resultout            VARCHAR2(30);
718    l_batch_id             NUMBER;
719    l_return_status        VARCHAR2(1);
720    l_msg_count            NUMBER;
721    l_msg_data             VARCHAR2(2000);
722    l_error_msg            VARCHAR2(4000);
723    l_batch_type           VARCHAR2(30);
724 
725 l_batch_org_id               NUMBER;
726 BEGIN
727    IF OZF_DEBUG_HIGH_ON THEN
728       OZF_UTILITY_PVT.debug_message('IN ' || l_api_name || ' Funcmode: ' || funcmode);
729    END IF;
730 
731    -- R12 MOAC Enhancement (+)
732    l_batch_org_id := WF_ENGINE.GetItemAttrText(
733                         itemtype  => itemtype,
734                         itemkey   => itemkey,
735                         aname     => 'OZF_BATCH_ORG_ID'
736                      );
737 
738    IF (funcmode = 'TEST_CTX') THEN
739       IF (NVL(MO_GLOBAL.get_access_mode, 'NULL') <> 'S') OR
740           (NVL(MO_GLOBAL.get_current_org_id, -99) <> l_batch_org_id) THEN
741          resultout := 'FALSE';
742       ELSE
743          resultout := 'TRUE';
744       END IF;
745       RETURN;
746    END IF;
747 
748    IF (funcmode = 'SET_CTX') THEN
749       MO_GLOBAL.set_policy_context(
750          p_access_mode  => 'S',
751          p_org_id       => l_batch_org_id
752       );
753       --resultout := 'COMPLETE:';
754       RETURN;
755    END IF;
756    -- R12 MOAC Enhancement (-)
757 
758    IF (funcmode = 'RUN') THEN
759       --
760       l_batch_type := WF_ENGINE.GetItemAttrText(itemtype => itemtype,
761                                                 itemkey  => itemkey,
762                                                 aname    => G_WF_ATTR_BATCH_TYPE);
763 
764       IF l_batch_type NOT IN (G_WF_LKUP_CHARGEBACK, G_WF_LKUP_SPECIALPRICE, G_WF_LKUP_TRACING) OR
765          l_batch_type IS NULL
766       THEN
767          OZF_UTILITY_PVT.error_message('OZF_API_DEBUG_MESSAGE','TEXT','Invalid Batch Type '|| l_batch_type);
768          RAISE FND_API.G_EXC_ERROR;
769       END IF;
770 
771       IF OZF_DEBUG_LOW_ON THEN
772          OZF_UTILITY_PVT.debug_message('Batch Type '||   l_batch_type );
773       END IF;
774       l_resultout := 'COMPLETE:' || l_batch_type;
775       --
776    ELSIF (funcmode = 'CANCEL') THEN
777       l_resultout := 'COMPLETE:';
778    ELSIF (funcmode IN ('RESPOND', 'FORWARD', 'TRANSFER')) THEN
779       l_resultout := 'COMPLETE:';
780    ELSIF (funcmode = 'TIMEOUT') THEN
781       l_resultout := 'COMPLETE:';
782    END IF;
783 
784    resultout := l_resultout;
785 
786 EXCEPTION
787    WHEN FND_API.G_EXC_ERROR THEN
788       FND_MSG_PUB.Count_And_Get (
789           p_encoded => FND_API.G_FALSE,
790           p_count => l_msg_count,
791           p_data  => l_msg_data
792       );
793       Handle_Error(
794           p_itemtype     => itemtype
795          ,p_itemkey      => itemkey
796          ,p_msg_count    => l_msg_count
797          ,p_msg_data     => l_msg_data
798          ,p_process_name => l_api_name
799          ,x_error_msg    => l_error_msg
800       );
801       WF_CORE.context( G_PKG_NAME,l_api_name,itemtype,itemkey,actid,l_error_msg);
802       RAISE;
803    WHEN OTHERS THEN
804       IF OZF_UNEXP_ERROR THEN
805          FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
806       END IF;
807       FND_MSG_PUB.Count_And_Get (
808           p_encoded => FND_API.G_FALSE,
809           p_count => l_msg_count,
810           p_data  => l_msg_data
811       );
812       Handle_Error(
813           p_itemtype     => itemtype
814          ,p_itemkey      => itemkey
815          ,p_msg_count    => l_msg_count
816          ,p_msg_data     => l_msg_data
817          ,p_process_name => l_api_name
818          ,x_error_msg    => l_error_msg
819       );
820       WF_CORE.context( G_PKG_NAME,l_api_name,itemtype,itemkey,actid,l_error_msg);
821       RAISE;
822 END Get_Batch_Type;
823 ---------------------------------------------------------------------
824 -- PROCEDURE
825 --    Init_attributes
826 --
827 -- PURPOSE
828 --    This api will be initialize the attributes used IN the workflow
829 --
830 ---------------------------------------------------------------------
831 PROCEDURE Init_Attributes(
832    itemtype    IN     VARCHAR2,
833    itemkey     IN     VARCHAR2,
834    actid       IN     NUMBER,
835    funcmode    IN     VARCHAR2,
836    result      OUT NOCOPY    VARCHAR2
837 )
838 IS
839 l_api_name            CONSTANT VARCHAR2(30) := 'Init_Attributes';
840 l_api_version_number  CONSTANT NUMBER   := 1.0;
841 --
842 l_resale_batch_id NUMBER;
843 --
844 l_batch_number         VARCHAR2(240);
845 l_batch_type           VARCHAR2(30);
846 l_last_updated_by        Number;
847 --
848 --l_emp_id          NUMBER;
849 --l_user_name       VARCHAR2(100);
850 --l_display_name    VARCHAR2(100);
851 l_return_status   VARCHAR2(1);
852 l_error_msg       VARCHAR2(4000);
853 l_msg_count       NUMBER;
854 l_msg_data        VARCHAR2(2000);
855 --
856 CURSOR batch_num_csr(p_id number) IS
857  SELECT batch_number
858      , batch_type
859      , last_updated_by
860      , org_id
861  FROM ozf_resale_batches_all
862  WHERE resale_batch_id = p_id;
863 
864 /*
865 CURSOR emp_infor_csr(p_res_id NUMBER) IS
866 SELECT employee_id
867   FROM ams_jtf_rs_emp_v
868  WHERE  resource_id = p_res_id;
869 */
870 l_batch_org_id     NUMBER;
871 --
872 BEGIN
873    IF OZF_DEBUG_HIGH_ON THEN
874       OZF_UTILITY_PVT.debug_message('IN: ' || l_api_name || ' Funcmode: ' || funcmode);
875    END IF;
876    IF (funcmode = 'RUN') THEN
877       -- Clear the error stack for one time
878       FND_MSG_PUB.initialize;
879 
880       l_resale_batch_id := WF_ENGINE.GetItemAttrText(
881                               itemtype => itemtype,
882                               itemkey  => itemkey,
883                               aname    => G_WF_ATTR_BATCH_ID
884                         );
885       IF l_resale_batch_id is NULL THEN
886          OZF_UTILITY_PVT.error_message('OZF_RESALE_BATCH_ID_NULL');
887          RAISE FND_API.G_EXC_ERROR;
888       END IF;
889 
890       OPEN batch_num_csr (l_resale_batch_id);
891       FETCH batch_num_csr into l_batch_number
892                              , l_batch_type
893                              , l_last_updated_by
894                              , l_batch_org_id;
895       CLOSE batch_num_csr;
896 
897 
898 
899       WF_ENGINE.SetItemAttrText(
900           itemtype   => itemtype,
901           itemkey    => itemkey ,
902           aname      => G_WF_ATTR_BATCH_NUMBER,
903           avalue     => l_batch_number );
904 
905       WF_ENGINE.SetItemAttrText(
906           itemtype   => itemtype,
907           itemkey    => itemkey ,
908           aname      => G_WF_ATTR_BATCH_TYPE,
909           avalue     => l_batch_type );
910 
911       WF_ENGINE.SetItemAttrText(
912           itemtype   => itemtype,
913           itemkey    => itemkey ,
914           aname      => 'OZF_BATCH_ORG_ID',
915           avalue     => l_batch_org_id
916       );
917 
918       /*
919       -- The following is moved to workflow first activity-Set_Batch_Status.
920       OPEN emp_infor_csr(OZF_UTILITY_PVT.get_resource_id(l_last_updated_by));
921       FETCH emp_infor_csr INTO l_emp_id;
922       CLOSE emp_infor_csr;
923 
924       WF_DIRECTORY.GetRoleName
925            ( p_orig_system      => 'PER',
926              p_orig_system_id   => l_emp_id ,
927              p_name             => l_user_name,
928              p_display_name     => l_display_name );
929 
930       WF_ENGINE.SetItemAttrText(
931           itemtype   => itemtype,
932           itemkey    => itemkey ,
933           aname      => G_WF_ATTR_WF_ADMINISTRATOR,
934           avalue     => l_user_name);
935 
936       -- set workflow process owner
937       WF_ENGINE.SetItemOwner(
938           itemtype  => itemtype,
939           itemkey   => itemkey,
940           owner     => l_user_name);
941       */
942    --
943    END IF;
944 
945    --  CANCEL mode  - Normal Process Execution
946    IF (funcmode = 'CANCEL') THEN
947       RETURN;
948    END IF;
949 
950    --  Other mode  - Normal Process Execution
951    IF (funcmode IN ('RESPOND', 'FORWARD', 'TRANSFER')) THEN
952       RETURN;
953    END IF;
954 
955    --  TIMEOUT mode  - Normal Process Execution
956    IF (funcmode = 'TIMEOUT') THEN
957       RETURN;
958    END IF;
959    --
960 EXCEPTION
961    WHEN FND_API.G_EXC_ERROR THEN
962       FND_MSG_PUB.Count_And_Get (
963           p_encoded => FND_API.G_FALSE,
964           p_count => l_msg_count,
965           p_data  => l_msg_data
966       );
967       Handle_Error(
968           p_itemtype     => itemtype
969          ,p_itemkey      => itemkey
970          ,p_msg_count    => l_msg_count
971          ,p_msg_data     => l_msg_data
972          ,p_process_name => l_api_name
973          ,x_error_msg    => l_error_msg
974       );
975       WF_CORE.context( G_PKG_NAME,l_api_name,itemtype,itemkey,actid,l_error_msg);
976       RAISE;
977    WHEN OTHERS THEN
978       IF OZF_UNEXP_ERROR THEN
979          FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
980       END IF;
981       FND_MSG_PUB.Count_And_Get (
982           p_encoded => FND_API.G_FALSE,
983           p_count => l_msg_count,
984           p_data  => l_msg_data
985       );
986       Handle_Error(
987           p_itemtype     => itemtype
988          ,p_itemkey      => itemkey
989          ,p_msg_count    => l_msg_count
990          ,p_msg_data     => l_msg_data
991          ,p_process_name => l_api_name
992          ,x_error_msg    => l_error_msg
993       );
994       WF_CORE.context( G_PKG_NAME,l_api_name,itemtype,itemkey,actid,l_error_msg);
995       RAISE;
996 END Init_Attributes;
997 
998 ---------------------------------------------------------------------
999 -- PROCEDURE
1000 --    Initiate_Payment
1001 --
1002 -- PURPOSE
1003 --    This procedure inities payment processing
1004 --
1005 -- PARAMETERS
1006 --
1007 --
1008 -- NOTES
1009 ---------------------------------------------------------------------
1010 PROCEDURE  Initiate_Payment (
1011    itemtype   IN varchar2,
1012    itemkey    IN varchar2,
1013    actid      IN number,
1014    funcmode   IN varchar2,
1015    resultout  IN OUT NOCOPY varchar2)
1016 IS
1017    l_api_name            CONSTANT VARCHAR2(30) := 'Initiate_Payment';
1018    l_api_version_number  CONSTANT NUMBER   := 1.0;
1019    l_resultout           VARCHAR2(30);
1020    l_resale_batch_id     NUMBER;
1021    l_return_status       VARCHAR2(1);
1022    l_msg_count           NUMBER;
1023    l_msg_data            VARCHAR2(2000);
1024    l_error_msg           VARCHAR2(4000);
1025 
1026 l_batch_org_id               NUMBER;
1027 
1028 BEGIN
1029    IF OZF_DEBUG_HIGH_ON THEN
1030       OZF_UTILITY_PVT.debug_message('IN: ' || l_api_name || ' Funcmode: ' || funcmode);
1031    END IF;
1032 
1033    -- R12 MOAC Enhancement (+)
1034    l_batch_org_id := WF_ENGINE.GetItemAttrText(
1035                         itemtype  => itemtype,
1036                         itemkey   => itemkey,
1037                         aname     => 'OZF_BATCH_ORG_ID'
1038                      );
1039 
1040    IF (funcmode = 'TEST_CTX') THEN
1041       IF (NVL(MO_GLOBAL.get_access_mode, 'NULL') <> 'S') OR
1042           (NVL(MO_GLOBAL.get_current_org_id, -99) <> l_batch_org_id) THEN
1043          resultout := 'FALSE';
1044       ELSE
1045          resultout := 'TRUE';
1046       END IF;
1047       RETURN;
1048    END IF;
1049 
1050    IF (funcmode = 'SET_CTX') THEN
1051       MO_GLOBAL.set_policy_context(
1052          p_access_mode  => 'S',
1053          p_org_id       => l_batch_org_id
1054       );
1055       --resultout := 'COMPLETE:';
1056       RETURN;
1057    END IF;
1058    -- R12 MOAC Enhancement (-)
1059 
1060    IF (funcmode = 'RUN') THEN
1061    --
1062       l_resale_batch_id := WF_ENGINE.GetItemAttrText(itemtype => itemtype,
1063                                               itemkey  => itemkey,
1064                                               aname    => G_WF_ATTR_BATCH_ID);
1065       OZF_RESALE_PVT.Initiate_Payment (
1066           p_api_version      => 1.0
1067          ,p_init_msg_list    => FND_API.G_FALSE
1068          ,p_commit           => FND_API.G_FALSE
1069          ,p_validation_level => FND_API.G_VALID_LEVEL_FULL
1070          ,p_resale_batch_id  => l_resale_batch_id
1071          ,x_return_status    => l_return_status
1072          ,x_msg_data         => l_msg_data
1073          ,x_msg_count        => l_msg_count
1074       );
1075       IF OZF_DEBUG_LOW_ON THEN
1076          OZF_UTILITY_PVT.debug_message('subscribe process iface is complete ');
1077       END IF;
1078       IF l_return_status <>  FND_API.G_RET_STS_SUCCESS THEN
1079          RAISE FND_API.G_EXC_ERROR;
1080       END IF;
1081       l_resultout := 'COMPLETE:SUCCESS';
1082    --
1083    ELSIF (funcmode = 'CANCEL') THEN
1084       l_resultout := 'COMPLETE:';
1085    ELSIF (funcmode IN ('RESPOND', 'FORWARD', 'TRANSFER')) THEN
1086       l_resultout := 'COMPLETE:';
1087    ELSIF (funcmode = 'TIMEOUT') THEN
1088       l_resultout := 'COMPLETE:';
1089    END IF;
1090 
1091    resultout := l_resultout;
1092 
1093 EXCEPTION
1094    WHEN FND_API.G_EXC_ERROR THEN
1095       FND_MSG_PUB.Count_And_Get (
1096           p_encoded => FND_API.G_FALSE,
1097           p_count => l_msg_count,
1098           p_data  => l_msg_data
1099       );
1100       Handle_Error(
1101           p_itemtype     => itemtype
1102          ,p_itemkey      => itemkey
1103          ,p_msg_count    => l_msg_count
1104          ,p_msg_data     => l_msg_data
1105          ,p_process_name => l_api_name
1106          ,x_error_msg    => l_error_msg
1107       );
1108       WF_CORE.context( G_PKG_NAME,l_api_name,itemtype,itemkey,actid,l_error_msg);
1109       resultout := 'COMPLETE:ERROR';
1110       RETURN;
1111    WHEN OTHERS THEN
1112       IF OZF_UNEXP_ERROR THEN
1113          FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
1114       END IF;
1115       FND_MSG_PUB.Count_And_Get (
1116           p_encoded => FND_API.G_FALSE,
1117           p_count => l_msg_count,
1118           p_data  => l_msg_data
1119       );
1120       Handle_Error(
1121           p_itemtype     => itemtype
1122          ,p_itemkey      => itemkey
1123          ,p_msg_count    => l_msg_count
1124          ,p_msg_data     => l_msg_data
1125          ,p_process_name => l_api_name
1126          ,x_error_msg    => l_error_msg
1127       );
1128       WF_CORE.context( G_PKG_NAME,l_api_name,itemtype,itemkey,actid,l_error_msg);
1129       RAISE;
1130 END Initiate_Payment;
1131 
1132 
1133 ---------------------------------------------------------------------
1134 -- PROCEDURE
1135 --    Initiate_Payment_chargeback
1136 --
1137 -- PURPOSE
1138 --    This procedure inities payment processing for chargeback
1139 --
1140 -- PARAMETERS
1141 --
1142 --
1143 -- NOTES
1144 --   returns success or error
1145 ---------------------------------------------------------------------
1146 PROCEDURE  Initiate_Payment_chargeback (
1147    itemtype   in varchar2,
1148    itemkey    in varchar2,
1149    actid      in number,
1150    funcmode   in varchar2,
1151    resultout  in OUT NOCOPY varchar2 )
1152 IS
1153    l_api_name            CONSTANT VARCHAR2(30) := 'Initiate_Payment_chargeback';
1154    l_api_version_number  CONSTANT NUMBER   := 1.0;
1155    l_resultout           VARCHAR2(30);
1156    l_resale_batch_id     NUMBER;
1157    l_return_status       VARCHAR2(1);
1158    l_msg_count           NUMBER;
1159    l_msg_data            VARCHAR2(2000);
1160    l_error_msg           VARCHAR2(4000);
1161 
1162 l_batch_org_id               NUMBER;
1163 
1164 BEGIN
1165    IF OZF_DEBUG_HIGH_ON THEN
1166       OZF_UTILITY_PVT.debug_message('IN: ' || l_api_name || ' Funcmode: ' || funcmode);
1167    END IF;
1168 
1169    -- R12 MOAC Enhancement (+)
1170    l_batch_org_id := WF_ENGINE.GetItemAttrText(
1171                         itemtype  => itemtype,
1172                         itemkey   => itemkey,
1173                         aname     => 'OZF_BATCH_ORG_ID'
1174                      );
1175 
1176    IF (funcmode = 'TEST_CTX') THEN
1177       IF (NVL(MO_GLOBAL.get_access_mode, 'NULL') <> 'S') OR
1178           (NVL(MO_GLOBAL.get_current_org_id, -99) <> l_batch_org_id) THEN
1179          resultout := 'FALSE';
1180       ELSE
1181          resultout := 'TRUE';
1182       END IF;
1183       RETURN;
1184    END IF;
1185 
1186    IF (funcmode = 'SET_CTX') THEN
1187       MO_GLOBAL.set_policy_context(
1188          p_access_mode  => 'S',
1189          p_org_id       => l_batch_org_id
1190       );
1191       --resultout := 'COMPLETE:';
1192       RETURN;
1193    END IF;
1194    -- R12 MOAC Enhancement (-)
1195 
1196    IF (funcmode = 'RUN') THEN
1197    --
1198       l_resale_batch_id := WF_ENGINE.GetItemAttrText(itemtype => itemtype,
1199                                               itemkey  => itemkey,
1200                                               aname    => G_WF_ATTR_BATCH_ID);
1201       OZF_CHARGEBACK_PVT.Initiate_Payment (
1202           p_api_version      => 1.0
1203          ,p_init_msg_list    => FND_API.G_FALSE
1204          ,p_commit           => FND_API.G_FALSE
1205          ,p_validation_level => FND_API.G_VALID_LEVEL_FULL
1206          ,p_resale_batch_id  => l_resale_batch_id
1207          ,x_return_status    => l_return_status
1208          ,x_msg_data         => l_msg_data
1209          ,x_msg_count        => l_msg_count
1210       );
1211       IF l_return_status <>  FND_API.G_RET_STS_SUCCESS THEN
1212          RAISE FND_API.G_EXC_ERROR;
1213       END IF;
1214       l_resultout := 'COMPLETE:SUCCESS';
1215    --
1216    ELSIF (funcmode = 'CANCEL') THEN
1217       l_resultout := 'COMPLETE:';
1218    ELSIF (funcmode IN ('RESPOND', 'FORWARD', 'TRANSFER')) THEN
1219       l_resultout := 'COMPLETE:';
1220    ELSIF (funcmode = 'TIMEOUT') THEN
1221       l_resultout := 'COMPLETE:';
1222    END IF;
1223 
1224    resultout := l_resultout;
1225 
1226 EXCEPTION
1227    WHEN FND_API.G_EXC_ERROR THEN
1228       FND_MSG_PUB.Count_And_Get (
1229           p_encoded => FND_API.G_FALSE,
1230           p_count => l_msg_count,
1231           p_data  => l_msg_data
1232       );
1233       Handle_Error(
1234           p_itemtype     => itemtype
1235          ,p_itemkey      => itemkey
1236          ,p_msg_count    => l_msg_count
1237          ,p_msg_data     => l_msg_data
1238          ,p_process_name => l_api_name
1239          ,x_error_msg    => l_error_msg
1240       );
1241       WF_CORE.context( G_PKG_NAME,l_api_name,itemtype,itemkey,actid,l_error_msg);
1242       resultout := 'COMPLETE:ERROR';
1243       RETURN;
1244    WHEN OTHERS THEN
1245       IF OZF_UNEXP_ERROR THEN
1246          FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
1247       END IF;
1248       FND_MSG_PUB.Count_And_Get (
1249           p_encoded => FND_API.G_FALSE,
1250           p_count => l_msg_count,
1251           p_data  => l_msg_data
1252       );
1253       Handle_Error(
1254           p_itemtype     => itemtype
1255          ,p_itemkey      => itemkey
1256          ,p_msg_count    => l_msg_count
1257          ,p_msg_data     => l_msg_data
1258          ,p_process_name => l_api_name
1259          ,x_error_msg    => l_error_msg
1260       );
1261       WF_CORE.context( G_PKG_NAME,l_api_name,itemtype,itemkey,actid,l_error_msg);
1262       RAISE;
1263 END Initiate_Payment_Chargeback;
1264 
1265 
1266 ---------------------------------------------------------------------
1267 -- PROCEDURE
1268 --    Initiate_Payment__SPP
1269 --
1270 -- PURPOSE
1271 --    This procedure inities payment processing for special pricing
1272 --
1273 -- PARAMETERS
1274 --
1275 --
1276 -- NOTES
1277 ---------------------------------------------------------------------
1278 PROCEDURE  Initiate_Payment_SPP(
1279    itemtype   in varchar2,
1280    itemkey    in varchar2,
1281    actid      in number,
1282    funcmode   in varchar2,
1283    resultout  in OUT NOCOPY varchar2 )
1284 IS
1285    l_api_name            CONSTANT VARCHAR2(30) := 'Initiate_Payment_SPP';
1286    l_api_version_number  CONSTANT NUMBER   := 1.0;
1287    l_resultout           VARCHAR2(30);
1288    l_resale_batch_id     NUMBER;
1289    l_return_status       VARCHAR2(1);
1290    l_msg_count           NUMBER;
1291    l_msg_data            VARCHAR2(2000);
1292    l_error_msg           VARCHAR2(4000);
1293 
1294 l_batch_org_id               NUMBER;
1295 
1296 BEGIN
1297    IF OZF_DEBUG_HIGH_ON THEN
1298       OZF_UTILITY_PVT.debug_message('IN: ' || l_api_name || ' Funcmode: ' || funcmode);
1299    END IF;
1300 
1301    -- R12 MOAC Enhancement (+)
1302    l_batch_org_id := WF_ENGINE.GetItemAttrText(
1303                         itemtype  => itemtype,
1304                         itemkey   => itemkey,
1305                         aname     => 'OZF_BATCH_ORG_ID'
1306                      );
1307 
1308    IF (funcmode = 'TEST_CTX') THEN
1309       IF (NVL(MO_GLOBAL.get_access_mode, 'NULL') <> 'S') OR
1310           (NVL(MO_GLOBAL.get_current_org_id, -99) <> l_batch_org_id) THEN
1311          resultout := 'FALSE';
1312       ELSE
1313          resultout := 'TRUE';
1314       END IF;
1315       RETURN;
1316    END IF;
1317 
1318    IF (funcmode = 'SET_CTX') THEN
1319       MO_GLOBAL.set_policy_context(
1320          p_access_mode  => 'S',
1321          p_org_id       => l_batch_org_id
1322       );
1323       --resultout := 'COMPLETE:';
1324       RETURN;
1325    END IF;
1326    -- R12 MOAC Enhancement (-)
1327 
1328    IF (funcmode = 'RUN') THEN
1329    --
1330       l_resale_batch_id := WF_ENGINE.GetItemAttrText(itemtype => itemtype,
1331                                               itemkey  => itemkey,
1332                                               aname    => G_WF_ATTR_BATCH_ID);
1333       OZF_SPECIAL_PRICING_PVT.Initiate_Payment (
1334           p_api_version      => 1.0
1335          ,p_init_msg_list    => FND_API.G_FALSE
1336          ,p_commit           => FND_API.G_FALSE
1337          ,p_validation_level => FND_API.G_VALID_LEVEL_FULL
1338          ,p_resale_batch_id  => l_resale_batch_id
1339          ,x_return_status    => l_return_status
1340          ,x_msg_data         => l_msg_data
1341          ,x_msg_count        => l_msg_count
1342       );
1343       IF l_return_status <>  FND_API.G_RET_STS_SUCCESS THEN
1344          RAISE FND_API.G_EXC_ERROR;
1345       END IF;
1346       l_resultout := 'COMPLETE:SUCCESS';
1347    --
1348    ELSIF (funcmode = 'CANCEL') THEN
1349       l_resultout := 'COMPLETE:';
1350    ELSIF (funcmode IN ('RESPOND', 'FORWARD', 'TRANSFER')) THEN
1351       l_resultout := 'COMPLETE:';
1352    ELSIF (funcmode = 'TIMEOUT') THEN
1353       l_resultout := 'COMPLETE:';
1354    END IF;
1355 
1356    resultout := l_resultout;
1357 
1358 EXCEPTION
1359    WHEN FND_API.G_EXC_ERROR THEN
1360       FND_MSG_PUB.Count_And_Get (
1361           p_encoded => FND_API.G_FALSE,
1362           p_count => l_msg_count,
1363           p_data  => l_msg_data
1364       );
1365       Handle_Error(
1366           p_itemtype     => itemtype
1367          ,p_itemkey      => itemkey
1368          ,p_msg_count    => l_msg_count
1369          ,p_msg_data     => l_msg_data
1370          ,p_process_name => l_api_name
1371          ,x_error_msg    => l_error_msg
1372       );
1373       WF_CORE.context( G_PKG_NAME,l_api_name,itemtype,itemkey,actid,l_error_msg);
1374       resultout := 'COMPLETE:ERROR';
1375       RETURN;
1376    WHEN OTHERS THEN
1377       IF OZF_UNEXP_ERROR THEN
1378          FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
1379       END IF;
1380       FND_MSG_PUB.Count_And_Get (
1381           p_encoded => FND_API.G_FALSE,
1382           p_count => l_msg_count,
1383           p_data  => l_msg_data
1384       );
1385       Handle_Error(
1386           p_itemtype     => itemtype
1387          ,p_itemkey      => itemkey
1388          ,p_msg_count    => l_msg_count
1389          ,p_msg_data     => l_msg_data
1390          ,p_process_name => l_api_name
1391          ,x_error_msg    => l_error_msg
1392       );
1393       WF_CORE.context( G_PKG_NAME,l_api_name,itemtype,itemkey,actid,l_error_msg);
1394       RAISE;
1395 END Initiate_Payment_SPP;
1396 
1397 
1398 ---------------------------------------------------------------------
1399 -- PROCEDURE
1400 --    Initiate_Payment_Tracing
1401 --
1402 -- PURPOSE
1403 --    This procedure inities payment processing for tracing order
1404 --
1405 -- PARAMETERS
1406 --
1407 --
1408 -- NOTES
1409 ---------------------------------------------------------------------
1410 PROCEDURE  Initiate_Payment_Tracing (
1411    itemtype   in varchar2,
1412    itemkey    in varchar2,
1413    actid      in number,
1414    funcmode   in varchar2,
1415    resultout  in OUT NOCOPY varchar2 )
1416 IS
1417    l_api_name            CONSTANT VARCHAR2(30) := 'Initiate_Payment_Tracing';
1418    l_api_version_number  CONSTANT NUMBER   := 1.0;
1419    l_resultout           VARCHAR2(30);
1420    l_resale_batch_id     NUMBER;
1421    l_return_status       VARCHAR2(1);
1422    l_msg_count           NUMBER;
1423    l_msg_data            VARCHAR2(2000);
1424    l_error_msg           VARCHAR2(4000);
1425 BEGIN
1426    IF OZF_DEBUG_HIGH_ON THEN
1427       OZF_UTILITY_PVT.debug_message('IN: ' || l_api_name || ' Funcmode: ' || funcmode);
1428    END IF;
1429    IF (funcmode = 'RUN') THEN
1430    --
1431       l_resale_batch_id := WF_ENGINE.GetItemAttrText(itemtype => itemtype,
1432                                               itemkey  => itemkey,
1433                                               aname    => G_WF_ATTR_BATCH_ID);
1434       OZF_TRACING_ORDER_PVT.Initiate_Payment (
1435           p_api_version      => 1.0
1436          ,p_init_msg_list    => FND_API.G_FALSE
1437          ,p_commit           => FND_API.G_FALSE
1438          ,p_validation_level => FND_API.G_VALID_LEVEL_FULL
1439          ,p_resale_batch_id  => l_resale_batch_id
1440          ,x_return_status    => l_return_status
1441          ,x_msg_data         => l_msg_data
1442          ,x_msg_count        => l_msg_count
1443       );
1444       IF l_return_status <>  FND_API.G_RET_STS_SUCCESS THEN
1445          RAISE FND_API.G_EXC_ERROR;
1446       END IF;
1447       l_resultout := 'COMPLETE:SUCCESS';
1448    --
1449    ELSIF (funcmode = 'CANCEL') THEN
1450       l_resultout := 'COMPLETE:';
1451    ELSIF (funcmode IN ('RESPOND', 'FORWARD', 'TRANSFER')) THEN
1452       l_resultout := 'COMPLETE:';
1453    ELSIF (funcmode = 'TIMEOUT') THEN
1454       l_resultout := 'COMPLETE:';
1455    END IF;
1456 
1457    resultout := l_resultout;
1458 
1459 EXCEPTION
1460    WHEN FND_API.G_EXC_ERROR THEN
1461       FND_MSG_PUB.Count_And_Get (
1462           p_encoded => FND_API.G_FALSE,
1463           p_count => l_msg_count,
1464           p_data  => l_msg_data
1465       );
1466       Handle_Error(
1467           p_itemtype     => itemtype
1468          ,p_itemkey      => itemkey
1469          ,p_msg_count    => l_msg_count
1470          ,p_msg_data     => l_msg_data
1471          ,p_process_name => l_api_name
1472          ,x_error_msg    => l_error_msg
1473       );
1474       WF_CORE.context( G_PKG_NAME,l_api_name,itemtype,itemkey,actid,l_error_msg);
1475       resultout := 'COMPLETE:ERROR';
1476       RETURN;
1477    WHEN OTHERS THEN
1478       IF OZF_UNEXP_ERROR THEN
1479          FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
1480       END IF;
1481       FND_MSG_PUB.Count_And_Get (
1482           p_encoded => FND_API.G_FALSE,
1483           p_count => l_msg_count,
1484           p_data  => l_msg_data
1485       );
1486       Handle_Error(
1487           p_itemtype     => itemtype
1488          ,p_itemkey      => itemkey
1489          ,p_msg_count    => l_msg_count
1490          ,p_msg_data     => l_msg_data
1491          ,p_process_name => l_api_name
1492          ,x_error_msg    => l_error_msg
1493       );
1494       WF_CORE.context( G_PKG_NAME,l_api_name,itemtype,itemkey,actid,l_error_msg);
1495       RAISE;
1496 END Initiate_Payment_Tracing;
1497 
1498 ---------------------------------------------------------------------
1499 -- PROCEDURE
1500 --    Process_Chargeback
1501 --
1502 -- PURPOSE
1503 --    This procedure inities indirect sales data processing for chargeback
1504 --
1505 -- PARAMETERS
1506 --
1507 --
1508 -- NOTES
1509 ---------------------------------------------------------------------
1510 PROCEDURE  Process_Chargeback (
1511    itemtype   IN varchar2,
1512    itemkey    IN varchar2,
1513    actid      IN number,
1514    funcmode   IN varchar2,
1515    resultout  IN OUT NOCOPY varchar2)
1516 IS
1517    l_api_name            CONSTANT VARCHAR2(30) := 'Process_Chargeback';
1518    l_api_version_number  CONSTANT NUMBER   := 1.0;
1519    l_resultout           VARCHAR2(30);
1520    l_resale_batch_id     NUMBER;
1521    l_return_status       VARCHAR2(1);
1522    l_msg_count           NUMBER;
1523    l_msg_data            VARCHAR2(2000);
1524    l_error_msg           VARCHAR2(4000);
1525 
1526 l_batch_org_id           NUMBER;
1527 
1528 BEGIN
1529    IF OZF_DEBUG_HIGH_ON THEN
1530       OZF_UTILITY_PVT.debug_message('IN: ' || l_api_name || ' Funcmode: ' || funcmode);
1531    END IF;
1532 
1533    -- R12 MOAC Enhancement (+)
1534    l_batch_org_id := WF_ENGINE.GetItemAttrText(
1535                         itemtype  => itemtype,
1536                         itemkey   => itemkey,
1537                         aname     => 'OZF_BATCH_ORG_ID'
1538                      );
1539 
1540    IF (funcmode = 'TEST_CTX') THEN
1541       IF (NVL(MO_GLOBAL.get_access_mode, 'NULL') <> 'S') OR
1542           (NVL(MO_GLOBAL.get_current_org_id, -99) <> l_batch_org_id) THEN
1543          resultout := 'FALSE';
1544       ELSE
1545          resultout := 'TRUE';
1546       END IF;
1547       RETURN;
1548    END IF;
1549 
1550    IF (funcmode = 'SET_CTX') THEN
1551       MO_GLOBAL.set_policy_context(
1552          p_access_mode  => 'S',
1553          p_org_id       => l_batch_org_id
1554       );
1555       --resultout := 'COMPLETE:';
1556       RETURN;
1557    END IF;
1558    -- R12 MOAC Enhancement (-)
1559 
1560    IF (funcmode = 'RUN') THEN
1561    --
1562       l_resale_batch_id := WF_ENGINE.GetItemAttrNumber(itemtype => itemtype,
1563                                               itemkey  => itemkey,
1564                                               aname    => G_WF_ATTR_BATCH_ID);
1565       OZF_CHARGEBACK_PVT.Process_Order(
1566           p_api_version      => 1.0
1567          ,p_init_msg_list    => FND_API.G_FALSE
1568          ,p_commit           => FND_API.G_FALSE
1569          ,p_validation_level => FND_API.G_VALID_LEVEL_FULL
1570          ,p_resale_batch_id  => l_resale_batch_id
1571          ,x_return_status    => l_return_status
1572          ,x_msg_data         => l_msg_data
1573          ,x_msg_count        => l_msg_count
1574       );
1575       IF OZF_DEBUG_LOW_ON THEN
1576          OZF_UTILITY_PVT.debug_message('subscribe process chargeback order complete ');
1577       END IF;
1578       IF l_return_status <>  FND_API.G_RET_STS_SUCCESS THEN
1579          RAISE FND_API.G_EXC_ERROR;
1580       END IF;
1581       l_resultout := 'COMPLETE:SUCCESS';
1582    --
1583    ELSIF (funcmode = 'CANCEL') THEN
1584       l_resultout := 'COMPLETE:';
1585    ELSIF (funcmode IN ('RESPOND', 'FORWARD', 'TRANSFER')) THEN
1586       l_resultout := 'COMPLETE:';
1587    ELSIF (funcmode = 'TIMEOUT') THEN
1588       l_resultout := 'COMPLETE:';
1589    END IF;
1590 
1591    resultout := l_resultout;
1592 
1593 EXCEPTION
1594    WHEN FND_API.G_EXC_ERROR THEN
1595       FND_MSG_PUB.Count_And_Get (
1596           p_encoded => FND_API.G_FALSE,
1597           p_count => l_msg_count,
1598           p_data  => l_msg_data
1599       );
1600       Handle_Error(
1601           p_itemtype     => itemtype
1602          ,p_itemkey      => itemkey
1603          ,p_msg_count    => l_msg_count
1604          ,p_msg_data     => l_msg_data
1605          ,p_process_name => l_api_name
1606          ,x_error_msg    => l_error_msg
1607       );
1608       WF_CORE.context( G_PKG_NAME,l_api_name,itemtype,itemkey,actid,l_error_msg);
1609       resultout := 'COMPLETE:ERROR';
1610       RETURN;
1611    WHEN OTHERS THEN
1612       IF OZF_UNEXP_ERROR THEN
1613          FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
1614       END IF;
1615       FND_MSG_PUB.Count_And_Get (
1616           p_encoded => FND_API.G_FALSE,
1617           p_count => l_msg_count,
1618           p_data  => l_msg_data
1619       );
1620       Handle_Error(
1621           p_itemtype     => itemtype
1622          ,p_itemkey      => itemkey
1623          ,p_msg_count    => l_msg_count
1624          ,p_msg_data     => l_msg_data
1625          ,p_process_name => l_api_name
1626          ,x_error_msg    => l_error_msg
1627       );
1628       WF_CORE.context( G_PKG_NAME,l_api_name,itemtype,itemkey,actid,l_error_msg);
1629       resultout := 'COMPLETE:ERROR';
1630       RAISE;
1631 END Process_Chargeback;
1632 
1633 
1634 ---------------------------------------------------------------------
1635 -- PROCEDURE
1636 --    Process_Resale
1637 --
1638 -- PURPOSE
1639 --    This procedure initiates third party accrual process for resale data
1640 --
1641 -- PARAMETERS
1642 --
1643 --
1644 -- NOTES
1645 ---------------------------------------------------------------------
1646 PROCEDURE Process_Resale(
1647    itemtype   in varchar2,
1648    itemkey    in varchar2,
1649    actid      in number,
1650    funcmode   in varchar2,
1651    resultout  in OUT NOCOPY varchar2)
1652 IS
1653    l_api_name            CONSTANT VARCHAR2(30) := 'Process_Resale';
1654    l_api_version_number  CONSTANT NUMBER   := 1.0;
1655    l_resultout           VARCHAR2(30);
1656    l_resale_batch_id     NUMBER;
1657    l_return_status       VARCHAR2(1);
1658    l_msg_count           NUMBER;
1659    l_msg_data            VARCHAR2(2000);
1660    l_error_msg           VARCHAR2(4000);
1661 
1662 l_batch_org_id               NUMBER;
1663 
1664 BEGIN
1665    IF OZF_DEBUG_HIGH_ON THEN
1666       OZF_UTILITY_PVT.debug_message('IN: ' || l_api_name || ' Funcmode: ' || funcmode);
1667    END IF;
1668 
1669    -- R12 MOAC Enhancement (+)
1670    l_batch_org_id := WF_ENGINE.GetItemAttrText(
1671                         itemtype  => itemtype,
1672                         itemkey   => itemkey,
1673                         aname     => 'OZF_BATCH_ORG_ID'
1674                      );
1675 
1676    IF (funcmode = 'TEST_CTX') THEN
1677       IF (NVL(MO_GLOBAL.get_access_mode, 'NULL') <> 'S') OR
1678           (NVL(MO_GLOBAL.get_current_org_id, -99) <> l_batch_org_id) THEN
1679          resultout := 'FALSE';
1680       ELSE
1681          resultout := 'TRUE';
1682       END IF;
1683       RETURN;
1684    END IF;
1685 
1686    IF (funcmode = 'SET_CTX') THEN
1687       MO_GLOBAL.set_policy_context(
1688          p_access_mode  => 'S',
1689          p_org_id       => l_batch_org_id
1690       );
1691       --resultout := 'COMPLETE:';
1692       RETURN;
1693    END IF;
1694    -- R12 MOAC Enhancement (-)
1695 
1696    IF (funcmode = 'RUN') THEN
1697    --
1698       l_resale_batch_id := WF_ENGINE.GetItemAttrNumber(itemtype => itemtype,
1699                                               itemkey  => itemkey,
1700                                               aname    => G_WF_ATTR_BATCH_ID);
1701       OZF_RESALE_PVT.Process_Resale (
1702           p_api_version       => 1
1703          ,p_init_msg_list     => FND_API.G_FALSE
1704          ,p_commit            => FND_API.G_FALSE
1705          ,p_validation_level  => FND_API.G_VALID_LEVEL_FULL
1706          ,p_resale_batch_id   => l_resale_batch_id
1707          ,x_return_status     => l_return_status
1708          ,x_msg_data          => l_msg_data
1709          ,x_msg_count         => l_msg_count
1710       );
1711       IF l_return_status <>  FND_API.G_RET_STS_SUCCESS THEN
1712          RAISE FND_API.G_EXC_ERROR;
1713       END IF;
1714       l_resultout := 'COMPLETE:SUCCESS';
1715    --
1716    ELSIF (funcmode = 'CANCEL') THEN
1717       l_resultout := 'COMPLETE:';
1718    ELSIF (funcmode IN ('RESPOND', 'FORWARD', 'TRANSFER')) THEN
1719       l_resultout := 'COMPLETE:';
1720    ELSIF (funcmode = 'TIMEOUT') THEN
1721       l_resultout := 'COMPLETE:';
1722    END IF;
1723 
1724    resultout := l_resultout;
1725 
1726 EXCEPTION
1727    WHEN FND_API.G_EXC_ERROR THEN
1728       FND_MSG_PUB.Count_And_Get (
1729           p_encoded => FND_API.G_FALSE,
1730           p_count => l_msg_count,
1731           p_data  => l_msg_data
1732       );
1733       Handle_Error(
1734           p_itemtype     => itemtype
1735          ,p_itemkey      => itemkey
1736          ,p_msg_count    => l_msg_count
1737          ,p_msg_data     => l_msg_data
1738          ,p_process_name => l_api_name
1739          ,x_error_msg    => l_error_msg
1740       );
1741       WF_CORE.context( G_PKG_NAME,l_api_name,itemtype,itemkey,actid,l_error_msg);
1742       resultout := 'COMPLETE:ERROR';
1743       RETURN;
1744    WHEN OTHERS THEN
1745       IF OZF_UNEXP_ERROR THEN
1746          FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
1747       END IF;
1748       FND_MSG_PUB.Count_And_Get (
1749           p_encoded => FND_API.G_FALSE,
1750           p_count => l_msg_count,
1751           p_data  => l_msg_data
1752       );
1753       Handle_Error(
1754           p_itemtype     => itemtype
1755          ,p_itemkey      => itemkey
1756          ,p_msg_count    => l_msg_count
1757          ,p_msg_data     => l_msg_data
1758          ,p_process_name => l_api_name
1759          ,x_error_msg    => l_error_msg
1760       );
1761       WF_CORE.context( G_PKG_NAME,l_api_name,itemtype,itemkey,actid,l_error_msg);
1762       RAISE;
1763 END Process_Resale;
1764 
1765 
1766 ---------------------------------------------------------------------
1767 -- PROCEDURE
1768 --    Process_Special_Pricing
1769 --
1770 -- PURPOSE
1771 --    This procedure inities indirect sales data processing for special pricing
1772 --
1773 -- PARAMETERS
1774 --
1775 --
1776 -- NOTES
1777 ---------------------------------------------------------------------
1778 PROCEDURE  Process_Special_Pricing(
1779    itemtype   IN varchar2,
1780    itemkey    IN varchar2,
1781    actid      IN number,
1782    funcmode   IN varchar2,
1783    resultout  IN OUT NOCOPY varchar2)
1784 IS
1785    l_api_name            CONSTANT VARCHAR2(30) := 'Process_Special_Pricing';
1786    l_api_version_number  CONSTANT NUMBER   := 1.0;
1787    l_resultout           VARCHAR2(30);
1788    l_resale_batch_id     NUMBER;
1789    l_return_status       VARCHAR2(1);
1790    l_msg_count           NUMBER;
1791    l_msg_data            VARCHAR2(2000);
1792    l_error_msg           VARCHAR2(4000);
1793 
1794 l_batch_org_id               NUMBER;
1795 
1796 BEGIN
1797    IF OZF_DEBUG_HIGH_ON THEN
1798       OZF_UTILITY_PVT.debug_message('IN: ' || l_api_name || ' Funcmode: ' || funcmode);
1799    END IF;
1800 
1801    -- R12 MOAC Enhancement (+)
1802    l_batch_org_id := WF_ENGINE.GetItemAttrText(
1803                         itemtype  => itemtype,
1804                         itemkey   => itemkey,
1805                         aname     => 'OZF_BATCH_ORG_ID'
1806                      );
1807 
1808    IF (funcmode = 'TEST_CTX') THEN
1809       IF (NVL(MO_GLOBAL.get_access_mode, 'NULL') <> 'S') OR
1810           (NVL(MO_GLOBAL.get_current_org_id, -99) <> l_batch_org_id) THEN
1811          resultout := 'FALSE';
1812       ELSE
1813          resultout := 'TRUE';
1814       END IF;
1815       RETURN;
1816    END IF;
1817 
1818    IF (funcmode = 'SET_CTX') THEN
1819       MO_GLOBAL.set_policy_context(
1820          p_access_mode  => 'S',
1821          p_org_id       => l_batch_org_id
1822       );
1823       --resultout := 'COMPLETE:';
1824       RETURN;
1825    END IF;
1826    -- R12 MOAC Enhancement (-)
1827 
1828    IF (funcmode = 'RUN') THEN
1829    --
1830       l_resale_batch_id := WF_ENGINE.GetItemAttrNumber(itemtype => itemtype,
1831                                               itemkey  => itemkey,
1832                                               aname    => G_WF_ATTR_BATCH_ID);
1833       OZF_SPECIAL_PRICING_PVT.Process_Order(
1834           p_api_version      => 1.0
1835          ,p_init_msg_list    => FND_API.G_FALSE
1836          ,p_commit           => FND_API.G_FALSE
1837          ,p_validation_level => FND_API.G_VALID_LEVEL_FULL
1838          ,p_resale_batch_id  => l_resale_batch_id
1839          ,x_return_status    => l_return_status
1840          ,x_msg_data         => l_msg_data
1841          ,x_msg_count        => l_msg_count
1842       );
1843       IF OZF_DEBUG_LOW_ON THEN
1844          OZF_UTILITY_PVT.debug_message('subscribe process chargeback order complete ');
1845       END IF;
1846       IF l_return_status <>  FND_API.G_RET_STS_SUCCESS THEN
1847          RAISE FND_API.G_EXC_ERROR;
1848       END IF;
1849       l_resultout := 'COMPLETE:SUCCESS';
1850    --
1851    ELSIF (funcmode = 'CANCEL') THEN
1852       l_resultout := 'COMPLETE:';
1853    ELSIF (funcmode IN ('RESPOND', 'FORWARD', 'TRANSFER')) THEN
1854       l_resultout := 'COMPLETE:';
1855    ELSIF (funcmode = 'TIMEOUT') THEN
1856       l_resultout := 'COMPLETE:';
1857    END IF;
1858 
1859    resultout := l_resultout;
1860 
1861 EXCEPTION
1862    WHEN FND_API.G_EXC_ERROR THEN
1863       FND_MSG_PUB.Count_And_Get (
1864           p_encoded => FND_API.G_FALSE,
1865           p_count => l_msg_count,
1866           p_data  => l_msg_data
1867       );
1868       Handle_Error(
1869           p_itemtype     => itemtype
1870          ,p_itemkey      => itemkey
1871          ,p_msg_count    => l_msg_count
1872          ,p_msg_data     => l_msg_data
1873          ,p_process_name => l_api_name
1874          ,x_error_msg    => l_error_msg
1875       );
1876       WF_CORE.context( G_PKG_NAME,l_api_name,itemtype,itemkey,actid,l_error_msg);
1877       resultout := 'COMPLETE:ERROR';
1878       RETURN;
1879    WHEN OTHERS THEN
1880       IF OZF_UNEXP_ERROR THEN
1881          FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
1882       END IF;
1883       FND_MSG_PUB.Count_And_Get (
1884           p_encoded => FND_API.G_FALSE,
1885           p_count => l_msg_count,
1886           p_data  => l_msg_data
1887       );
1888       Handle_Error(
1889           p_itemtype     => itemtype
1890          ,p_itemkey      => itemkey
1891          ,p_msg_count    => l_msg_count
1892          ,p_msg_data     => l_msg_data
1893          ,p_process_name => l_api_name
1894          ,x_error_msg    => l_error_msg
1895       );
1896       WF_CORE.context( G_PKG_NAME,l_api_name,itemtype,itemkey,actid,l_error_msg);
1897       RAISE;
1898 END Process_Special_Pricing;
1899 
1900 
1901 ---------------------------------------------------------------------
1902 -- PROCEDURE
1903 --    Process_Tracing
1904 --
1905 -- PURPOSE
1906 --    This procedure inities indirect sales data processing for tracing data
1907 --
1908 -- PARAMETERS
1909 --
1910 --
1911 -- NOTES
1912 ---------------------------------------------------------------------
1913 PROCEDURE  Process_Tracing(
1914    itemtype   IN varchar2,
1915    itemkey    IN varchar2,
1916    actid      IN number,
1917    funcmode   IN varchar2,
1918    resultout  IN OUT NOCOPY varchar2)
1919 IS
1920    l_api_name            CONSTANT VARCHAR2(30) := 'Process_Tracing';
1921    l_api_version_number  CONSTANT NUMBER   := 1.0;
1922    l_resultout           VARCHAR2(30);
1923    l_resale_batch_id     NUMBER;
1924    l_return_status       VARCHAR2(1);
1925    l_msg_count           NUMBER;
1926    l_msg_data            VARCHAR2(2000);
1927    l_error_msg           VARCHAR2(4000);
1928 
1929 l_batch_org_id               NUMBER;
1930 
1931 BEGIN
1932    IF OZF_DEBUG_HIGH_ON THEN
1933       OZF_UTILITY_PVT.debug_message('IN: ' || l_api_name || ' Funcmode: ' || funcmode);
1934    END IF;
1935 
1936    -- R12 MOAC Enhancement (+)
1937    l_batch_org_id := WF_ENGINE.GetItemAttrText(
1938                         itemtype  => itemtype,
1939                         itemkey   => itemkey,
1940                         aname     => 'OZF_BATCH_ORG_ID'
1941                      );
1942 
1943    IF (funcmode = 'TEST_CTX') THEN
1944       IF (NVL(MO_GLOBAL.get_access_mode, 'NULL') <> 'S') OR
1945           (NVL(MO_GLOBAL.get_current_org_id, -99) <> l_batch_org_id) THEN
1946          resultout := 'FALSE';
1947       ELSE
1948          resultout := 'TRUE';
1949       END IF;
1950       RETURN;
1951    END IF;
1952 
1953    IF (funcmode = 'SET_CTX') THEN
1954       MO_GLOBAL.set_policy_context(
1955          p_access_mode  => 'S',
1956          p_org_id       => l_batch_org_id
1957       );
1958       --resultout := 'COMPLETE:';
1959       RETURN;
1960    END IF;
1961    -- R12 MOAC Enhancement (-)
1962 
1963    IF (funcmode = 'RUN') THEN
1964    --
1965       l_resale_batch_id := WF_ENGINE.GetItemAttrNumber(itemtype => itemtype,
1966                                               itemkey  => itemkey,
1967                                               aname    => G_WF_ATTR_BATCH_ID);
1968       OZF_TRACING_ORDER_PVT.Process_Order(
1969           p_api_version      => 1.0
1970          ,p_init_msg_list    => FND_API.G_FALSE
1971          ,p_commit           => FND_API.G_FALSE
1972          ,p_validation_level => FND_API.G_VALID_LEVEL_FULL
1973          ,p_resale_batch_id  => l_resale_batch_id
1974          ,x_return_status    => l_return_status
1975          ,x_msg_data         => l_msg_data
1976          ,x_msg_count        => l_msg_count
1977       );
1978       IF OZF_DEBUG_LOW_ON THEN
1979          OZF_UTILITY_PVT.debug_message('subscribe process tracing order complete ');
1980       END IF;
1981       IF l_return_status <>  FND_API.G_RET_STS_SUCCESS THEN
1982          RAISE FND_API.G_EXC_ERROR;
1983       END IF;
1984       l_resultout := 'COMPLETE:SUCCESS';
1985    --
1986    ELSIF (funcmode = 'CANCEL') THEN
1987       l_resultout := 'COMPLETE:';
1988    ELSIF (funcmode IN ('RESPOND', 'FORWARD', 'TRANSFER')) THEN
1989       l_resultout := 'COMPLETE:';
1990    ELSIF (funcmode = 'TIMEOUT') THEN
1991       l_resultout := 'COMPLETE:';
1992    END IF;
1993 
1994    resultout := l_resultout;
1995 
1996 EXCEPTION
1997    WHEN FND_API.G_EXC_ERROR THEN
1998       FND_MSG_PUB.Count_And_Get (
1999           p_encoded => FND_API.G_FALSE,
2000           p_count => l_msg_count,
2001           p_data  => l_msg_data
2002       );
2003       Handle_Error(
2004           p_itemtype     => itemtype
2005          ,p_itemkey      => itemkey
2006          ,p_msg_count    => l_msg_count
2007          ,p_msg_data     => l_msg_data
2008          ,p_process_name => l_api_name
2009          ,x_error_msg    => l_error_msg
2010       );
2011       WF_CORE.context( G_PKG_NAME,l_api_name,itemtype,itemkey,actid,l_error_msg);
2012       resultout := 'COMPLETE:ERROR';
2013       RETURN;
2014    WHEN OTHERS THEN
2015       IF OZF_UNEXP_ERROR THEN
2016          FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
2017       END IF;
2018       FND_MSG_PUB.Count_And_Get (
2019           p_encoded => FND_API.G_FALSE,
2020           p_count => l_msg_count,
2021           p_data  => l_msg_data
2022       );
2023       Handle_Error(
2024           p_itemtype     => itemtype
2025          ,p_itemkey      => itemkey
2026          ,p_msg_count    => l_msg_count
2027          ,p_msg_data     => l_msg_data
2028          ,p_process_name => l_api_name
2029          ,x_error_msg    => l_error_msg
2030       );
2031       WF_CORE.context( G_PKG_NAME,l_api_name,itemtype,itemkey,actid,l_error_msg);
2032       RAISE;
2033 END Process_Tracing;
2034 
2035 ---------------------------------------------------------------------
2036 -- PROCEDURE
2037 --    Reset_Status
2038 --
2039 -- PURPOSE
2040 --    This procedure is to reset the status of a batch IN case of exceptions
2041 --
2042 -- PARAMETERS
2043 --
2044 --
2045 -- NOTES
2046 ---------------------------------------------------------------------
2047 PROCEDURE Reset_Status (
2048    itemtype    IN     VARCHAR2,
2049    itemkey     IN     VARCHAR2,
2050    actid       IN     NUMBER,
2051    funcmode    IN     VARCHAR2,
2052    result      OUT NOCOPY    VARCHAR2
2053 )IS
2054 l_api_name          CONSTANT VARCHAR2(30) := 'Reset_Status';
2055 l_api_version       CONSTANT NUMBER := 1.0;
2056 l_full_name         CONSTANT VARCHAR2(60) := G_PKG_NAME ||'.'|| l_api_name;
2057 --
2058 l_return_status     varchar2(30);
2059 l_msg_data          varchar2(2000);
2060 l_msg_count         number;
2061 --
2062 l_resale_batch_id NUMBER;
2063 l_batch_status        varchar2(30);
2064 l_lines_disputed      number;
2065 l_resultout           VARCHAR2(30);
2066 l_error_msg           VARCHAR2(4000);
2067 --
2068 CURSOR batch_status_csr(p_id number) IS
2069 SELECT status_code
2070      , lines_disputed
2071  --FROM  ozf_resale_batches
2072  FROM  ozf_resale_batches_all
2073  WHERE resale_batch_id = p_id;
2074 --
2075 BEGIN
2076    IF OZF_DEBUG_HIGH_ON THEN
2077       OZF_UTILITY_PVT.debug_message('IN: ' || l_api_name || ' Funcmode: ' || funcmode);
2078    END IF;
2079    IF (funcmode = 'RUN') THEN
2080       --
2081       l_resale_batch_id := WF_ENGINE.GetItemAttrText(
2082                               itemtype => itemtype,
2083                               itemkey  => itemkey,
2084                               aname    => G_WF_ATTR_BATCH_ID
2085                         );
2086 
2087       OPEN batch_status_csr(l_resale_batch_id);
2088       FETCH batch_status_csr into l_batch_status, l_lines_disputed;
2089       CLOSE batch_status_csr;
2090 
2091       IF l_batch_status is null THEN
2092          OZF_UTILITY_PVT.error_message('OZF_RESALE_BATCH_STATUS_NULL');
2093          RAISE FND_API.G_EXC_ERROR;
2094       END IF;
2095 
2096       -- reset the status based on # of disputed lines
2097       OPEN  OZF_RESALE_COMMON_PVT.g_disputed_line_count_csr (l_resale_batch_id);
2098       FETCH OZF_RESALE_COMMON_PVT.g_disputed_line_count_csr into l_lines_disputed;
2099       CLOSE OZF_RESALE_COMMON_PVT.g_disputed_line_count_csr;
2100 
2101       IF l_batch_status = OZF_RESALE_COMMON_PVT.G_BATCH_PROCESSING THEN
2102          IF l_lines_disputed = 0 THEN
2103             -- update status to Processed
2104             UPDATE ozf_resale_batches_all
2105                SET status_code = OZF_RESALE_COMMON_PVT.G_BATCH_OPEN
2106              WHERE resale_batch_id = l_resale_batch_id;
2107          ELSE
2108             -- update status to Disputed
2109             UPDATE ozf_resale_batches_all
2110                SET status_code = OZF_RESALE_COMMON_PVT.G_BATCH_DISPUTED
2111              WHERE resale_batch_id = l_resale_batch_id;
2112          END IF;
2113       ELSIF l_batch_status = OZF_RESALE_COMMON_PVT.G_BATCH_PENDING_PAYMENT THEN
2114 
2115          IF l_lines_disputed = 0 THEN
2116             -- update status to Processed
2117             UPDATE ozf_resale_batches_all
2118                SET status_code = OZF_RESALE_COMMON_PVT.G_BATCH_PROCESSED
2119              WHERE resale_batch_id = l_resale_batch_id;
2120          ELSE
2121             -- update status to Disputed
2122             UPDATE ozf_resale_batches_all
2123                SET status_code = OZF_RESALE_COMMON_PVT.G_BATCH_DISPUTED
2124              WHERE resale_batch_id = l_resale_batch_id;
2125          END IF;
2126       END IF;
2127       l_resultout := 'COMPLETE';
2128       --
2129    END IF;
2130 
2131    --  CANCEL mode  - Normal Process Execution
2132    IF (funcmode = 'CANCEL') THEN
2133      l_resultout := 'COMPLETE:';
2134    END IF;
2135 
2136    --  TIMEOUT mode  - Normal Process Execution
2137    IF (funcmode = 'TIMEOUT') THEN
2138       l_resultout := 'COMPLETE:';
2139    END IF;
2140 
2141    result := l_resultout;
2142    RETURN;
2143    --
2144 EXCEPTION
2145    WHEN FND_API.G_EXC_ERROR THEN
2146       FND_MSG_PUB.Count_And_Get (
2147           p_encoded => FND_API.G_FALSE,
2148           p_count => l_msg_count,
2149           p_data  => l_msg_data
2150       );
2151       Handle_Error(
2152           p_itemtype     => itemtype
2153          ,p_itemkey      => itemkey
2154          ,p_msg_count    => l_msg_count
2155          ,p_msg_data     => l_msg_data
2156          ,p_process_name => l_api_name
2157          ,x_error_msg    => l_error_msg
2158       );
2159       WF_CORE.context( G_PKG_NAME,l_api_name,itemtype,itemkey,actid,l_error_msg);
2160       RAISE;
2161    WHEN OTHERS THEN
2162       IF OZF_UNEXP_ERROR THEN
2163          FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
2164       END IF;
2165       FND_MSG_PUB.Count_And_Get (
2166           p_encoded => FND_API.G_FALSE,
2167           p_count => l_msg_count,
2168           p_data  => l_msg_data
2169       );
2170       Handle_Error(
2171           p_itemtype     => itemtype
2172          ,p_itemkey      => itemkey
2173          ,p_msg_count    => l_msg_count
2174          ,p_msg_data     => l_msg_data
2175          ,p_process_name => l_api_name
2176          ,x_error_msg    => l_error_msg
2177       );
2178       WF_CORE.context( G_PKG_NAME,l_api_name,itemtype,itemkey,actid,l_error_msg);
2179       RAISE;
2180 END Reset_Status;
2181 
2182 ---------------------------------------------------------------------
2183 -- PROCEDURE
2184 --    Set_Batch_Status
2185 --
2186 -- PURPOSE
2187 --    This procedure is to set the status of a batch
2188 --
2189 -- PARAMETERS
2190 --
2191 --
2192 -- NOTES
2193 ---------------------------------------------------------------------
2194 PROCEDURE Set_Batch_Status (
2195    itemtype    IN     VARCHAR2,
2196    itemkey     IN     VARCHAR2,
2197    actid       IN     NUMBER,
2198    funcmode    IN     VARCHAR2,
2199    resultout  in OUT NOCOPY varchar2
2200 )IS
2201 l_api_name          CONSTANT VARCHAR2(30) := 'Set_Batch_Status';
2202 l_api_version       CONSTANT NUMBER := 1.0;
2203 l_full_name         CONSTANT VARCHAR2(60) := G_PKG_NAME ||'.'|| l_api_name;
2204 --
2205 l_return_status     varchar2(30);
2206 l_msg_data          varchar2(2000);
2207 l_msg_count         number;
2208 --
2209 l_resale_batch_id NUMBER;
2210 l_batch_status        varchar2(30);
2211 l_batch_next_status        varchar2(30);
2212 l_lines_disputed      number;
2213 l_resultout           VARCHAR2(30);
2214 l_error_msg           VARCHAR2(4000);
2215 
2216 l_last_updated_by      NUMBER;
2217 l_emp_id               NUMBER;
2218 l_user_name            VARCHAR2(100);
2219 l_display_name         VARCHAR2(100);
2220 --
2221 CURSOR batch_status_csr(p_id number) IS
2222 SELECT last_updated_by
2223 ,      status_code
2224  --FROM  ozf_resale_batches
2225  FROM  ozf_resale_batches_all
2226  WHERE resale_batch_id = p_id;
2227 
2228 CURSOR emp_infor_csr(p_res_id NUMBER) IS
2229 -- BUBG 4953233 (+)
2230   SELECT  ppl.person_id
2231   FROM jtf_rs_resource_extns rsc
2232      , per_people_f ppl
2233   WHERE rsc.category = 'EMPLOYEE'
2234   AND ppl.person_id = rsc.source_id
2235   AND rsc.resource_id=p_res_id;
2236   -- SELECT employee_id
2237   -- FROM jtf_rs_res_emp_vl
2238   -- WHERE resource_id = p_res_id ;
2239 -- BUBG 4953233 (-)
2240 
2241 l_batch_org_id               NUMBER;
2242 BEGIN
2243    IF OZF_DEBUG_HIGH_ON THEN
2244       OZF_UTILITY_PVT.debug_message('IN: ' || l_api_name || ' Funcmode: ' || funcmode);
2245    END IF;
2246 
2247    -- R12 MOAC Enhancement (+)
2248    l_batch_org_id := WF_ENGINE.GetItemAttrText(
2249                         itemtype  => itemtype,
2250                         itemkey   => itemkey,
2251                         aname     => 'OZF_BATCH_ORG_ID'
2252                      );
2253 
2254    IF (funcmode = 'TEST_CTX') THEN
2255       IF (NVL(MO_GLOBAL.get_access_mode, 'NULL') <> 'S') OR
2256           (NVL(MO_GLOBAL.get_current_org_id, -99) <> l_batch_org_id) THEN
2257          resultout := 'FALSE';
2258       ELSE
2259          resultout := 'TRUE';
2260       END IF;
2261       RETURN;
2262    END IF;
2263 
2264    IF (funcmode = 'SET_CTX') THEN
2265       MO_GLOBAL.set_policy_context(
2266          p_access_mode  => 'S',
2267          p_org_id       => l_batch_org_id
2268       );
2269       --resultout := 'COMPLETE:';
2270       RETURN;
2271    END IF;
2272    -- R12 MOAC Enhancement (-)
2273 
2274    IF (funcmode = 'RUN') THEN
2275       l_resale_batch_id := WF_ENGINE.GetItemAttrText(
2276                               itemtype => itemtype,
2277                               itemkey  => itemkey,
2278                               aname    => G_WF_ATTR_BATCH_ID
2279                         );
2280 
2281       OPEN batch_status_csr(l_resale_batch_id);
2282       FETCH batch_status_csr INTO l_last_updated_by
2283                                 , l_batch_status;
2284       CLOSE batch_status_csr;
2285 
2286 
2287       OPEN emp_infor_csr(OZF_UTILITY_PVT.get_resource_id(l_last_updated_by));
2288       FETCH emp_infor_csr INTO l_emp_id;
2289       CLOSE emp_infor_csr;
2290 
2291       WF_DIRECTORY.GetRoleName(
2292              p_orig_system      => 'PER',
2293              p_orig_system_id   => l_emp_id ,
2294              p_name             => l_user_name,
2295              p_display_name     => l_display_name
2296       );
2297 
2298       WF_ENGINE.SetItemAttrText(
2299              itemtype           => itemtype,
2300              itemkey            => itemkey ,
2301              aname              => G_WF_ATTR_WF_ADMINISTRATOR,
2302              avalue             => l_user_name
2303       );
2304 
2305       -- set workflow process owner
2306       WF_ENGINE.SetItemOwner(
2307              itemtype           => itemtype,
2308              itemkey            => itemkey,
2309              owner              => l_user_name
2310       );
2311 
2312       --
2313       IF l_batch_status is null THEN
2314          OZF_UTILITY_PVT.error_message('OZF_RESALE_BATCH_STATUS_NULL');
2315          RAISE FND_API.G_EXC_ERROR;
2316       END IF;
2317 
2318 
2319       IF l_batch_status in (OZF_RESALE_COMMON_PVT.G_BATCH_PROCESSING,
2320                             OZF_RESALE_COMMON_PVT.G_BATCH_PENDING_PAYMENT) THEN
2321          l_batch_next_status := l_batch_status;
2322       ELSE
2323          IF l_batch_status IN (OZF_RESALE_COMMON_PVT.G_BATCH_OPEN,
2324                                OZF_RESALE_COMMON_PVT.G_BATCH_DISPUTED) THEN
2325             l_batch_next_status := OZF_RESALE_COMMON_PVT.G_BATCH_PROCESSING;
2326 
2327             UPDATE ozf_resale_batches_all
2328                SET status_code = l_batch_next_status
2329              WHERE resale_batch_id = l_resale_batch_id;
2330 
2331          ELSE
2332             OZF_UTILITY_PVT.error_message('OZF_RESALE_BATCH_STATUS_ERR');
2333             RAISE FND_API.G_EXC_ERROR;
2334          END IF;
2335       END IF;
2336 
2337 
2338       l_resultout := 'COMPLETE:' || l_batch_next_status;
2339       --
2340    END IF;
2341 
2342    --  CANCEL mode  - Normal Process Execution
2343    IF (funcmode = 'CANCEL') THEN
2344      l_resultout := 'COMPLETE:';
2345    END IF;
2346 
2347    --  TIMEOUT mode  - Normal Process Execution
2348    IF (funcmode = 'TIMEOUT') THEN
2349       l_resultout := 'COMPLETE:';
2350    END IF;
2351 
2352    resultout := l_resultout;
2353    RETURN;
2354    --
2355 EXCEPTION
2356    WHEN FND_API.G_EXC_ERROR THEN
2357       FND_MSG_PUB.Count_And_Get (
2358           p_encoded => FND_API.G_FALSE,
2359           p_count => l_msg_count,
2360           p_data  => l_msg_data
2361       );
2362       Handle_Error(
2363           p_itemtype     => itemtype
2364          ,p_itemkey      => itemkey
2365          ,p_msg_count    => l_msg_count
2366          ,p_msg_data     => l_msg_data
2367          ,p_process_name => l_api_name
2368          ,x_error_msg    => l_error_msg
2369       );
2370       WF_CORE.context( G_PKG_NAME,l_api_name,itemtype,itemkey,actid,l_error_msg);
2371       RAISE;
2372    WHEN OTHERS THEN
2373       IF OZF_UNEXP_ERROR THEN
2374          FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
2375       END IF;
2376       FND_MSG_PUB.Count_And_Get (
2377           p_encoded => FND_API.G_FALSE,
2378           p_count => l_msg_count,
2379           p_data  => l_msg_data
2380       );
2381       Handle_Error(
2382           p_itemtype     => itemtype
2383          ,p_itemkey      => itemkey
2384          ,p_msg_count    => l_msg_count
2385          ,p_msg_data     => l_msg_data
2386          ,p_process_name => l_api_name
2387          ,x_error_msg    => l_error_msg
2388       );
2389       WF_CORE.context( G_PKG_NAME,l_api_name,itemtype,itemkey,actid,l_error_msg);
2390       RAISE;
2391 END Set_Batch_Status;
2392 
2393 ---------------------------------------------------------------------
2394 -- PROCEDURE
2395 --    Set_Payment_Pending
2396 --
2397 -- PURPOSE
2398 --    This procedure set the batch status to Payment_Pending
2399 --
2400 -- PARAMETERS
2401 --
2402 --
2403 -- NOTES
2404 ---------------------------------------------------------------------
2405 PROCEDURE Set_Payment_Pending(
2406    itemtype   in varchar2,
2407    itemkey    in varchar2,
2408    actid      in number,
2409    funcmode   in varchar2,
2410    resultout  in OUT NOCOPY varchar2 )
2411 IS
2412 l_api_name          CONSTANT VARCHAR2(30) := 'Set_Payment_Pending';
2413 l_api_version       CONSTANT NUMBER := 1.0;
2414 l_full_name         CONSTANT VARCHAR2(60) := G_PKG_NAME ||'.'|| l_api_name;
2415 --
2416 l_return_status     varchar2(30);
2417 l_msg_data          varchar2(2000);
2418 l_msg_count         number;
2419 --
2420 l_resale_batch_id NUMBER;
2421 l_resultout           VARCHAR2(30);
2422 l_error_msg           VARCHAR2(4000);
2423 
2424 l_batch_org_id               NUMBER;
2425 BEGIN
2426    IF OZF_DEBUG_HIGH_ON THEN
2427       OZF_UTILITY_PVT.debug_message('IN: ' || l_api_name || ' Funcmode: ' || funcmode);
2428    END IF;
2429 
2430    -- R12 MOAC Enhancement (+)
2431    l_batch_org_id := WF_ENGINE.GetItemAttrText(
2432                         itemtype  => itemtype,
2433                         itemkey   => itemkey,
2434                         aname     => 'OZF_BATCH_ORG_ID'
2435                      );
2436 
2437    IF (funcmode = 'TEST_CTX') THEN
2438       IF (NVL(MO_GLOBAL.get_access_mode, 'NULL') <> 'S') OR
2439           (NVL(MO_GLOBAL.get_current_org_id, -99) <> l_batch_org_id) THEN
2440          resultout := 'FALSE';
2441       ELSE
2442          resultout := 'TRUE';
2443       END IF;
2444       RETURN;
2445    END IF;
2446 
2447    IF (funcmode = 'SET_CTX') THEN
2448       MO_GLOBAL.set_policy_context(
2449          p_access_mode  => 'S',
2450          p_org_id       => l_batch_org_id
2451       );
2452       --resultout := 'COMPLETE:';
2453       RETURN;
2454    END IF;
2455    -- R12 MOAC Enhancement (-)
2456 
2457    IF (funcmode = 'RUN') THEN
2458       --
2459       l_resale_batch_id := WF_ENGINE.GetItemAttrText(
2460                               itemtype => itemtype,
2461                               itemkey  => itemkey,
2462                               aname    => G_WF_ATTR_BATCH_ID);
2463 
2464       UPDATE ozf_resale_batches_all
2465       SET status_code = OZF_RESALE_COMMON_PVT.G_BATCH_PENDING_PAYMENT
2466       WHERE resale_batch_id = l_resale_batch_id;
2467 
2468       l_resultout := 'COMPLETE';
2469       --
2470    END IF;
2471 
2472    --  CANCEL mode  - Normal Process Execution
2473    IF (funcmode = 'CANCEL') THEN
2474      l_resultout := 'COMPLETE:';
2475    END IF;
2476 
2477    --  TIMEOUT mode  - Normal Process Execution
2478    IF (funcmode = 'TIMEOUT') THEN
2479       l_resultout := 'COMPLETE:';
2480    END IF;
2481 
2482    resultout := l_resultout;
2483    RETURN;
2484    --
2485 EXCEPTION
2486    WHEN FND_API.G_EXC_ERROR THEN
2487       FND_MSG_PUB.Count_And_Get (
2488           p_encoded => FND_API.G_FALSE,
2489           p_count => l_msg_count,
2490           p_data  => l_msg_data
2491       );
2492       Handle_Error(
2493           p_itemtype     => itemtype
2494          ,p_itemkey      => itemkey
2495          ,p_msg_count    => l_msg_count
2496          ,p_msg_data     => l_msg_data
2497          ,p_process_name => l_api_name
2498          ,x_error_msg    => l_error_msg
2499       );
2500       WF_CORE.context( G_PKG_NAME,l_api_name,itemtype,itemkey,actid,l_error_msg);
2501       RAISE;
2502    WHEN OTHERS THEN
2503       IF OZF_UNEXP_ERROR THEN
2504          FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
2505       END IF;
2506       FND_MSG_PUB.Count_And_Get (
2507           p_encoded => FND_API.G_FALSE,
2508           p_count => l_msg_count,
2509           p_data  => l_msg_data
2510       );
2511       Handle_Error(
2512           p_itemtype     => itemtype
2513          ,p_itemkey      => itemkey
2514          ,p_msg_count    => l_msg_count
2515          ,p_msg_data     => l_msg_data
2516          ,p_process_name => l_api_name
2517          ,x_error_msg    => l_error_msg
2518       );
2519       WF_CORE.context( G_PKG_NAME,l_api_name,itemtype,itemkey,actid,l_error_msg);
2520       RAISE;
2521 END Set_Payment_Pending;
2522 
2523 ---------------------------------------------------------------------
2524 -- PROCEDURE
2525 --    Set_Tolerance_Level
2526 --
2527 -- PURPOSE
2528 --    This procedure set the batch status
2529 --
2530 -- PARAMETERS
2531 --
2532 --
2533 -- NOTES
2534 ---------------------------------------------------------------------
2535 PROCEDURE Set_Tolerance_Level(
2536    itemtype   in varchar2,
2537    itemkey    in varchar2,
2538    actid      in number,
2539    funcmode   in varchar2,
2540    resultout  in OUT NOCOPY varchar2 )
2541 IS
2542 l_api_name          CONSTANT VARCHAR2(30) := 'Set_Tolerance_Level';
2543 l_api_version       CONSTANT NUMBER := 1.0;
2544 l_full_name         CONSTANT VARCHAR2(60) := G_PKG_NAME ||'.'|| l_api_name;
2545 --
2546 l_return_status     varchar2(30);
2547 l_msg_data          varchar2(2000);
2548 l_msg_count         number;
2549 --
2550 l_resale_batch_id NUMBER;
2551 l_resultout           VARCHAR2(30);
2552 l_error_msg           VARCHAR2(4000);
2553 --
2554 l_header_tolerance_operand   NUMBER;
2555 l_header_tolerance_calc_code VARCHAR2(30);
2556 
2557 l_line_tolerance_operand     NUMBER;
2558 l_line_tolerance_calc_code   VARCHAR2(30);
2559 
2560 l_creation_date   DATE;
2561 l_last_update_date DATE;
2562 l_partner_party_id       NUMBER;
2563 l_partner_cust_account_id  NUMBER;
2564 
2565 CURSOR batch_info_csr (p_batch_id NUMBER) IS
2566 SELECT creation_date,
2567        last_update_date,
2568        partner_party_id,
2569        partner_cust_account_id
2570 --FROM ozf_resale_batches
2571 FROM ozf_resale_batches_all
2572 WHERE resale_batch_id = p_batch_id;
2573 
2574 CURSOR header_tolerance_sys_csr IS
2575 SELECT header_tolerance_operand,
2576        header_tolerance_calc_code
2577 FROM ozf_sys_parameters;
2578 
2579 CURSOR header_tolerance_account_csr (p_cust_account_id NUMBER)IS
2580 SELECT header_tolerance_operand,
2581        header_tolerance_calc_code
2582 FROM ozf_cust_trd_prfls
2583 WHERE cust_account_id = p_cust_account_id;
2584 
2585 CURSOR header_tolerance_party_csr (p_party_id NUMBER)IS
2586 SELECT header_tolerance_operand,
2587        header_tolerance_calc_code
2588 FROM ozf_cust_trd_prfls
2589 WHERE party_id = p_party_id
2590 and  cust_account_id IS NULL;
2591 
2592 CURSOR line_tolerance_sys_csr IS
2593 SELECT line_tolerance_operand,
2594        line_tolerance_calc_code
2595 FROM ozf_sys_parameters;
2596 
2597 CURSOR line_tolerance_account_csr (p_cust_account_id NUMBER)IS
2598 SELECT line_tolerance_operand,
2599        line_tolerance_calc_code
2600 FROM ozf_cust_trd_prfls
2601 WHERE cust_account_id = p_cust_account_id;
2602 
2603 CURSOR line_tolerance_party_csr (p_party_id NUMBER)IS
2604 SELECT line_tolerance_operand,
2605        line_tolerance_calc_code
2606 FROM ozf_cust_trd_prfls
2607 WHERE party_id = p_party_id
2608 AND   cust_account_id IS NULL;
2609 
2610 l_batch_org_id               NUMBER;
2611 
2612 BEGIN
2613    IF OZF_DEBUG_HIGH_ON THEN
2614       OZF_UTILITY_PVT.debug_message('IN: ' || l_api_name || ' Funcmode: ' || funcmode);
2615    END IF;
2616 
2617    -- R12 MOAC Enhancement (+)
2618    l_batch_org_id := WF_ENGINE.GetItemAttrText(
2619                         itemtype  => itemtype,
2620                         itemkey   => itemkey,
2621                         aname     => 'OZF_BATCH_ORG_ID'
2622                      );
2623 
2624    IF (funcmode = 'TEST_CTX') THEN
2625       IF (NVL(MO_GLOBAL.get_access_mode, 'NULL') <> 'S') OR
2626           (NVL(MO_GLOBAL.get_current_org_id, -99) <> l_batch_org_id) THEN
2627          resultout := 'FALSE';
2628       ELSE
2629          resultout := 'TRUE';
2630       END IF;
2631       RETURN;
2632    END IF;
2633 
2634    IF (funcmode = 'SET_CTX') THEN
2635       MO_GLOBAL.set_policy_context(
2636          p_access_mode  => 'S',
2637          p_org_id       => l_batch_org_id
2638       );
2639       --resultout := 'COMPLETE:';
2640       RETURN;
2641    END IF;
2642    -- R12 MOAC Enhancement (-)
2643 
2644    IF (funcmode = 'RUN') THEN
2645       --
2646       l_resale_batch_id := WF_ENGINE.GetItemAttrText(
2647                               itemtype => itemtype,
2648                               itemkey  => itemkey,
2649                               aname    => G_WF_ATTR_BATCH_ID);
2650 
2651       OPEN batch_info_csr (l_resale_batch_id);
2652       FETCH batch_info_csr INTO  l_creation_date,
2653                                  l_last_update_date,
2654                                  l_partner_party_id,
2655                                  l_partner_cust_account_id;
2656       CLOSE batch_info_csr;
2657 
2658       IF l_creation_date = l_last_update_date THEN
2659          -- It is the first time this batch is processed. default toleracne
2660 
2661          -- Set header tolerance
2662          OPEN  header_tolerance_account_csr(l_partner_cust_account_id);
2663          FETCH header_tolerance_account_csr into l_header_tolerance_operand,
2664                                                       l_header_tolerance_calc_code;
2665          CLOSE header_tolerance_account_csr;
2666 
2667          IF l_header_tolerance_calc_code is NULL THEN
2668             OPEN  header_tolerance_party_csr(l_partner_party_id);
2669             FETCH header_tolerance_party_csr into l_header_tolerance_operand,
2670                                                  l_header_tolerance_calc_code;
2671             CLOSE header_tolerance_party_csr;
2672 
2673             IF l_header_tolerance_calc_code is NULL THEN
2674                OPEN  header_tolerance_sys_csr;
2675                FETCH header_tolerance_sys_csr into l_header_tolerance_operand,
2676                                                    l_header_tolerance_calc_code;
2677                CLOSE header_tolerance_sys_csr;
2678             END IF;
2679          END IF;
2680 
2681          -- Set line tolerance
2682          OPEN  line_tolerance_account_csr(l_partner_cust_account_id);
2683          FETCH line_tolerance_account_csr into l_line_tolerance_operand,
2684                                                     l_line_tolerance_calc_code;
2685          CLOSE line_tolerance_account_csr;
2686 
2687          IF l_line_tolerance_calc_code is NULL THEN
2688             OPEN  line_tolerance_party_csr(l_partner_party_id);
2689             FETCH line_tolerance_party_csr into l_line_tolerance_operand,
2690                                                 l_line_tolerance_calc_code;
2691             CLOSE line_tolerance_party_csr;
2692 
2693             IF l_line_tolerance_calc_code is NULL THEN
2694                OPEN  line_tolerance_sys_csr;
2695                FETCH line_tolerance_sys_csr into l_line_tolerance_operand,
2696                                                  l_line_tolerance_calc_code;
2697                CLOSE line_tolerance_sys_csr;
2698             END IF;
2699          END IF;
2700 
2701       END IF;
2702 
2703       UPDATE ozf_resale_batches_all
2704       SET   header_tolerance_operand = l_header_tolerance_operand,
2705             header_tolerance_calc_code = l_header_tolerance_calc_code,
2706             line_tolerance_operand  = l_line_tolerance_operand,
2707             line_tolerance_calc_code = l_line_tolerance_calc_code
2708       WHERE resale_batch_id = l_resale_batch_id;
2709 
2710       l_resultout := 'COMPLETE';
2711       --
2712    END IF;
2713 
2714    --  CANCEL mode  - Normal Process Execution
2715    IF (funcmode = 'CANCEL') THEN
2716      l_resultout := 'COMPLETE';
2717    END IF;
2718 
2719    --  TIMEOUT mode  - Normal Process Execution
2720    IF (funcmode = 'TIMEOUT') THEN
2721       l_resultout := 'COMPLETE';
2722    END IF;
2723 
2724    resultout := l_resultout;
2725    RETURN;
2726    --
2727 EXCEPTION
2728    WHEN FND_API.G_EXC_ERROR THEN
2729       FND_MSG_PUB.Count_And_Get (
2730           p_encoded => FND_API.G_FALSE,
2731           p_count => l_msg_count,
2732           p_data  => l_msg_data
2733       );
2734       Handle_Error(
2735           p_itemtype     => itemtype
2736          ,p_itemkey      => itemkey
2737          ,p_msg_count    => l_msg_count
2738          ,p_msg_data     => l_msg_data
2739          ,p_process_name => l_api_name
2740          ,x_error_msg    => l_error_msg
2741       );
2742       WF_CORE.context( G_PKG_NAME,l_api_name,itemtype,itemkey,actid,l_error_msg);
2743       RAISE;
2744    WHEN OTHERS THEN
2745       IF OZF_UNEXP_ERROR THEN
2746          FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
2747       END IF;
2748       FND_MSG_PUB.Count_And_Get (
2749           p_encoded => FND_API.G_FALSE,
2750           p_count => l_msg_count,
2751           p_data  => l_msg_data
2752       );
2753       Handle_Error(
2754           p_itemtype     => itemtype
2755          ,p_itemkey      => itemkey
2756          ,p_msg_count    => l_msg_count
2757          ,p_msg_data     => l_msg_data
2758          ,p_process_name => l_api_name
2759          ,x_error_msg    => l_error_msg
2760       );
2761       WF_CORE.context( G_PKG_NAME,l_api_name,itemtype,itemkey,actid,l_error_msg);
2762       RAISE;
2763 END Set_Tolerance_Level;
2764 
2765 
2766 ---------------------------------------------------------------------
2767 -- PROCEDURE
2768 --    Validate_Batch
2769 --
2770 -- PURPOSE
2771 --    This procedure validates the batch details
2772 --
2773 -- PARAMETERS
2774 --
2775 --
2776 -- NOTES
2777 ---------------------------------------------------------------------
2778 PROCEDURE Validate_Batch (
2779    itemtype   IN varchar2,
2780    itemkey    IN varchar2,
2781    actid      IN number,
2782    funcmode   IN varchar2,
2783    resultout  IN OUT NOCOPY varchar2
2784 )
2785 IS
2786    l_api_name            CONSTANT VARCHAR2(30) := 'Validate_Batch';
2787    l_api_version_number  CONSTANT NUMBER   := 1.0;
2788 
2789    l_resultout                    VARCHAR2(30);
2790    l_batch_status                 VARCHAR2(30);
2791    l_batch_id                     NUMBER;
2792    l_return_status                VARCHAR2(1);
2793    l_msg_count                    NUMBER;
2794    l_msg_data                     VARCHAR2(2000);
2795    l_error_msg                    VARCHAR2(4000);
2796 
2797 l_batch_org_id               NUMBER;
2798 
2799 BEGIN
2800    IF OZF_DEBUG_HIGH_ON THEN
2801       OZF_UTILITY_PVT.debug_message('IN: ' || l_api_name || ' Funcmode: ' || funcmode);
2802    END IF;
2803 
2804    -- R12 MOAC Enhancement (+)
2805    l_batch_org_id := WF_ENGINE.GetItemAttrText(
2806                         itemtype  => itemtype,
2807                         itemkey   => itemkey,
2808                         aname     => 'OZF_BATCH_ORG_ID'
2809                      );
2810 
2811    IF (funcmode = 'TEST_CTX') THEN
2812       IF (NVL(MO_GLOBAL.get_access_mode, 'NULL') <> 'S') OR
2813           (NVL(MO_GLOBAL.get_current_org_id, -99) <> l_batch_org_id) THEN
2814          resultout := 'FALSE';
2815       ELSE
2816          resultout := 'TRUE';
2817       END IF;
2818       RETURN;
2819    END IF;
2820 
2821    IF (funcmode = 'SET_CTX') THEN
2822       MO_GLOBAL.set_policy_context(
2823          p_access_mode  => 'S',
2824          p_org_id       => l_batch_org_id
2825       );
2826       --resultout := 'COMPLETE:';
2827       RETURN;
2828    END IF;
2829    -- R12 MOAC Enhancement (-)
2830 
2831    IF (funcmode = 'RUN') THEN
2832    --
2833       l_batch_id := WF_ENGINE.GetItemAttrText(itemtype => itemtype,
2834                                               itemkey  => itemkey,
2835                                               aname    => G_WF_ATTR_BATCH_ID);
2836 
2837       IF OZF_DEBUG_LOW_ON THEN
2838          OZF_UTILITY_PVT.debug_message('Batch ID '|| l_batch_id);
2839       END IF;
2840       IF l_batch_id IS NOT NULL THEN
2841          OZF_RESALE_COMMON_PVT.Validate_Batch (
2842             p_api_version         => 1.0,
2843             p_init_msg_list       => FND_API.G_FALSE,
2844             p_commit              => FND_API.G_FALSE,
2845             p_validation_level    => FND_API.G_VALID_LEVEL_FULL,
2846             p_resale_batch_id     => l_batch_id,
2847             x_batch_status        => l_batch_status,
2848             x_return_status       => l_return_status,
2849             x_msg_count           => l_msg_count,
2850             x_msg_data            => l_msg_data );
2851 
2852          IF OZF_DEBUG_LOW_ON THEN
2853             OZF_UTILITY_PVT.debug_message('Validate Batch is complete '||l_return_status);
2854          END IF;
2855          IF l_return_status <>  FND_API.G_RET_STS_SUCCESS THEN
2856             RAISE FND_API.G_EXC_ERROR;
2857          END IF;
2858          l_resultout := 'COMPLETE:SUCCESS';
2859       ELSE
2860          OZF_UTILITY_PVT.error_message('OZF_RESALE_BATCH_ID_NULL');
2861          RAISE FND_API.G_EXC_ERROR;
2862       END IF;
2863       l_resultout := 'COMPLETE:SUCCESS';
2864    --
2865    ELSIF (funcmode = 'CANCEL') THEN
2866       l_resultout := 'COMPLETE:SUCCESS';
2867    ELSIF (funcmode IN ('RESPOND', 'FORWARD', 'TRANSFER')) THEN
2868       l_resultout := 'COMPLETE:SUCCESS';
2869    ELSIF (funcmode = 'TIMEOUT') THEN
2870       l_resultout := 'COMPLETE:SUCCESS';
2871    END IF;
2872 
2873    resultout := l_resultout;
2874 
2875 EXCEPTION
2876    WHEN FND_API.G_EXC_ERROR THEN
2877       FND_MSG_PUB.Count_And_Get (
2878           p_encoded => FND_API.G_FALSE,
2879           p_count => l_msg_count,
2880           p_data  => l_msg_data
2881       );
2882       Handle_Error(
2883           p_itemtype     => itemtype
2884          ,p_itemkey      => itemkey
2885          ,p_msg_count    => l_msg_count
2886          ,p_msg_data     => l_msg_data
2887          ,p_process_name => l_api_name
2888          ,x_error_msg    => l_error_msg
2889       );
2890       WF_CORE.context( G_PKG_NAME,l_api_name,itemtype,itemkey,actid,l_error_msg);
2891       resultout := 'COMPLETE:ERROR';
2892       RETURN;
2893    WHEN OTHERS THEN
2894       IF OZF_UNEXP_ERROR THEN
2895          FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
2896       END IF;
2897       FND_MSG_PUB.Count_And_Get (
2898           p_encoded => FND_API.G_FALSE,
2899           p_count => l_msg_count,
2900           p_data  => l_msg_data
2901       );
2902       Handle_Error(
2903           p_itemtype     => itemtype
2904          ,p_itemkey      => itemkey
2905          ,p_msg_count    => l_msg_count
2906          ,p_msg_data     => l_msg_data
2907          ,p_process_name => l_api_name
2908          ,x_error_msg    => l_error_msg
2909       );
2910       WF_CORE.context( G_PKG_NAME,l_api_name,itemtype,itemkey,actid,l_error_msg);
2911       RAISE;
2912 END Validate_Batch;
2913 
2914 ---------------------------------------------------------------------
2915 -- PROCEDURE
2916 --    Validate_Order
2917 --
2918 -- PURPOSE
2919 --    This procedure contains order level validations
2920 --
2921 -- PARAMETERS
2922 --
2923 --
2924 -- NOTES
2925 ---------------------------------------------------------------------
2926 PROCEDURE Validate_Order (
2927    itemtype   IN varchar2,
2928    itemkey    IN varchar2,
2929    actid      IN number,
2930    funcmode   IN varchar2,
2931    resultout  IN OUT NOCOPY varchar2
2932 )
2933 IS
2934    l_api_name            CONSTANT VARCHAR2(30) := 'Validate_Order';
2935    l_api_version_number  CONSTANT NUMBER   := 1.0;
2936 
2937    l_resultout                    VARCHAR2(30);
2938    l_batch_id                     NUMBER;
2939    l_return_status                VARCHAR2(1);
2940    l_msg_count                    NUMBER;
2941    l_msg_data                     VARCHAR2(2000);
2942    l_error_msg                    VARCHAR2(4000);
2943 
2944 l_batch_org_id               NUMBER;
2945 BEGIN
2946    IF OZF_DEBUG_HIGH_ON THEN
2947       OZF_UTILITY_PVT.debug_message('IN: ' || l_api_name || ' Funcmode: ' || funcmode);
2948    END IF;
2949 
2950    -- R12 MOAC Enhancement (+)
2951    l_batch_org_id := WF_ENGINE.GetItemAttrText(
2952                         itemtype  => itemtype,
2953                         itemkey   => itemkey,
2954                         aname     => 'OZF_BATCH_ORG_ID'
2955                      );
2956 
2957    IF (funcmode = 'TEST_CTX') THEN
2958       IF (NVL(MO_GLOBAL.get_access_mode, 'NULL') <> 'S') OR
2959           (NVL(MO_GLOBAL.get_current_org_id, -99) <> l_batch_org_id) THEN
2960          resultout := 'FALSE';
2961       ELSE
2962          resultout := 'TRUE';
2963       END IF;
2964       RETURN;
2965    END IF;
2966 
2967    IF (funcmode = 'SET_CTX') THEN
2968       MO_GLOBAL.set_policy_context(
2969          p_access_mode  => 'S',
2970          p_org_id       => l_batch_org_id
2971       );
2972       --resultout := 'COMPLETE:';
2973       RETURN;
2974    END IF;
2975    -- R12 MOAC Enhancement (-)
2976 
2977    IF (funcmode = 'RUN') THEN
2978       --
2979       l_batch_id := WF_ENGINE.GetItemAttrText(itemtype   => itemtype,
2980                                               itemkey  => itemkey,
2981                                               aname    => G_WF_ATTR_BATCH_ID);
2982 
2983       IF OZF_DEBUG_LOW_ON THEN
2984          OZF_UTILITY_PVT.debug_message('Batch ID '|| l_batch_id);
2985       END IF;
2986       IF l_batch_id IS NOT NULL THEN
2987          -- Verify the line information for this batch
2988          OZF_RESALE_COMMON_PVT.Validate_Order_Record (
2989              p_api_version        => 1.0
2990             ,p_init_msg_list      => FND_API.G_FALSE
2991             ,p_commit             => FND_API.G_FALSE
2992             ,p_validation_level   => FND_API.G_VALID_LEVEL_FULL
2993             ,p_resale_batch_id    => l_batch_id
2994             ,x_return_status      => l_return_status
2995             ,x_msg_data           => l_msg_data
2996             ,x_msg_count          => l_msg_count
2997             );
2998          IF l_return_status<> FND_API.G_RET_STS_SUCCESS THEN
2999             OZF_UTILITY_PVT.error_message('OZF_RESALE_VALIDATE_ERR');
3000             RAISE FND_API.G_EXC_ERROR;
3001          END IF;
3002       ELSE
3003          OZF_UTILITY_PVT.error_message('OZF_RESALE_BATCH_ID_NULL');
3004          RAISE FND_API.G_EXC_ERROR;
3005       END IF;
3006 
3007       l_resultout := 'COMPLETE:SUCCESS';
3008       --
3009    ELSIF (funcmode = 'CANCEL') THEN
3010       l_resultout := 'COMPLETE:SUCCESS';
3011    ELSIF (funcmode IN ('RESPOND', 'FORWARD', 'TRANSFER')) THEN
3012       l_resultout := 'COMPLETE:SUCCESS';
3013    ELSIF (funcmode = 'TIMEOUT') THEN
3014       l_resultout := 'COMPLETE:SUCCESS';
3015    END IF;
3016 
3017    resultout := l_resultout;
3018 
3019 EXCEPTION
3020    WHEN FND_API.G_EXC_ERROR THEN
3021       FND_MSG_PUB.Count_And_Get (
3022           p_encoded => FND_API.G_FALSE,
3023           p_count => l_msg_count,
3024           p_data  => l_msg_data
3025       );
3026       Handle_Error(
3027           p_itemtype     => itemtype
3028          ,p_itemkey      => itemkey
3029          ,p_msg_count    => l_msg_count
3030          ,p_msg_data     => l_msg_data
3031          ,p_process_name => l_api_name
3032          ,x_error_msg    => l_error_msg
3033       );
3034       WF_CORE.context( G_PKG_NAME,l_api_name,itemtype,itemkey,actid,l_error_msg);
3035       resultout := 'COMPLETE:ERROR';
3036       RETURN;
3037    WHEN OTHERS THEN
3038       IF OZF_UNEXP_ERROR THEN
3039          FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
3040       END IF;
3041       FND_MSG_PUB.Count_And_Get (
3042           p_encoded => FND_API.G_FALSE,
3043           p_count => l_msg_count,
3044           p_data  => l_msg_data
3045       );
3046       Handle_Error(
3047           p_itemtype     => itemtype
3048          ,p_itemkey      => itemkey
3049          ,p_msg_count    => l_msg_count
3050          ,p_msg_data     => l_msg_data
3051          ,p_process_name => l_api_name
3052          ,x_error_msg    => l_error_msg
3053       );
3054       WF_CORE.context( G_PKG_NAME,l_api_name,itemtype,itemkey,actid,l_error_msg);
3055       RAISE;
3056 END Validate_Order;
3057 
3058 ---------------------------------------------------------------------
3059 -- PROCEDURE
3060 --    Validate_Chargeback
3061 --
3062 -- PURPOSE
3063 --    This procedure contains chargeback validations
3064 --
3065 -- PARAMETERS
3066 --
3067 --
3068 -- NOTES
3069 ---------------------------------------------------------------------
3070 PROCEDURE Validate_Chargeback
3071 (
3072    itemtype   IN varchar2,
3073    itemkey    IN varchar2,
3074    actid      IN number,
3075    funcmode   IN varchar2,
3076    resultout  IN OUT NOCOPY varchar2
3077 )
3078 IS
3079    l_api_name            CONSTANT VARCHAR2(30) := 'Validate_Chargeback';
3080    l_api_version_number  CONSTANT NUMBER   := 1.0;
3081 
3082    l_resultout           VARCHAR2(30);
3083    l_batch_id            NUMBER;
3084    l_return_status       VARCHAR2(1);
3085    l_msg_count           NUMBER;
3086    l_msg_data            VARCHAR2(2000);
3087    l_error_msg           VARCHAR2(4000);
3088 
3089 l_batch_org_id               NUMBER;
3090 
3091 BEGIN
3092    IF OZF_DEBUG_HIGH_ON THEN
3093       OZF_UTILITY_PVT.debug_message('IN: ' || l_api_name || ' Funcmode: ' || funcmode);
3094    END IF;
3095 
3096    -- R12 MOAC Enhancement (+)
3097    l_batch_org_id := WF_ENGINE.GetItemAttrText(
3098                         itemtype  => itemtype,
3099                         itemkey   => itemkey,
3100                         aname     => 'OZF_BATCH_ORG_ID'
3101                      );
3102 
3103    IF (funcmode = 'TEST_CTX') THEN
3104       IF (NVL(MO_GLOBAL.get_access_mode, 'NULL') <> 'S') OR
3105           (NVL(MO_GLOBAL.get_current_org_id, -99) <> l_batch_org_id) THEN
3106          resultout := 'FALSE';
3107       ELSE
3108          resultout := 'TRUE';
3109       END IF;
3110       RETURN;
3111    END IF;
3112 
3113    IF (funcmode = 'SET_CTX') THEN
3114       MO_GLOBAL.set_policy_context(
3115          p_access_mode  => 'S',
3116          p_org_id       => l_batch_org_id
3117       );
3118       --resultout := 'COMPLETE:';
3119       RETURN;
3120    END IF;
3121    -- R12 MOAC Enhancement (-)
3122 
3123    IF (funcmode = 'RUN') THEN
3124       --
3125       l_batch_id := WF_ENGINE.GetItemAttrText(itemtype   => itemtype,
3126                                               itemkey  => itemkey,
3127                                               aname    => G_WF_ATTR_BATCH_ID);
3128       IF OZF_DEBUG_LOW_ON THEN
3129          OZF_UTILITY_PVT.debug_message('Batch ID '|| l_batch_id);
3130       END IF;
3131 
3132       IF l_batch_id IS NOT NULL THEN
3133          -- Verify the line information for this batch
3134          OZF_CHARGEBACK_PVT.Validate_Order_Record (
3135              p_api_version        => 1
3136             ,p_init_msg_list      => FND_API.G_FALSE
3137             ,p_commit             => FND_API.G_FALSE
3138             ,p_validation_level   => FND_API.G_VALID_LEVEL_FULL
3139             ,p_resale_batch_id    => l_batch_id
3140             ,x_return_status      => l_return_status
3141             ,x_msg_data           => l_msg_data
3142             ,x_msg_count          => l_msg_count
3143             );
3144          IF l_return_status<> FND_API.G_RET_STS_SUCCESS THEN
3145             OZF_UTILITY_PVT.error_message('OZF_RESALE_CHBK_VALIDATE_ERR');
3146             RAISE FND_API.G_EXC_ERROR;
3147          END IF;
3148       ELSE
3149          OZF_UTILITY_PVT.error_message('OZF_RESALE_BATCH_ID_NULL');
3150          RAISE FND_API.G_EXC_ERROR;
3151       END IF;
3152       l_resultout := 'COMPLETE:SUCCESS';
3153       --
3154    ELSIF (funcmode = 'CANCEL') THEN
3155         l_resultout := 'COMPLETE:SUCCESS';
3156    ELSIF (funcmode IN ('RESPOND', 'FORWARD', 'TRANSFER')) THEN
3157         l_resultout := 'COMPLETE:SUCCESS';
3158    ELSIF (funcmode = 'TIMEOUT') THEN
3159         l_resultout := 'COMPLETE:SUCCESS';
3160    END IF;
3161 
3162    resultout := l_resultout;
3163 
3164 EXCEPTION
3165    WHEN FND_API.G_EXC_ERROR THEN
3166       FND_MSG_PUB.Count_And_Get (
3167           p_encoded => FND_API.G_FALSE,
3168           p_count => l_msg_count,
3169           p_data  => l_msg_data
3170       );
3171       Handle_Error(
3172           p_itemtype     => itemtype
3173          ,p_itemkey      => itemkey
3174          ,p_msg_count    => l_msg_count
3175          ,p_msg_data     => l_msg_data
3176          ,p_process_name => l_api_name
3177          ,x_error_msg    => l_error_msg
3178       );
3179       WF_CORE.context( G_PKG_NAME,l_api_name,itemtype,itemkey,actid,l_error_msg);
3180       l_resultout := 'COMPLETE:ERROR';
3181       RETURN;
3182    WHEN OTHERS THEN
3183       IF OZF_UNEXP_ERROR THEN
3184          FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
3185       END IF;
3186       FND_MSG_PUB.Count_And_Get (
3187           p_encoded => FND_API.G_FALSE,
3188           p_count => l_msg_count,
3189           p_data  => l_msg_data
3190       );
3191       Handle_Error(
3192           p_itemtype     => itemtype
3193          ,p_itemkey      => itemkey
3194          ,p_msg_count    => l_msg_count
3195          ,p_msg_data     => l_msg_data
3196          ,p_process_name => l_api_name
3197          ,x_error_msg    => l_error_msg
3198       );
3199       WF_CORE.context( G_PKG_NAME,l_api_name,itemtype,itemkey,actid,l_error_msg);
3200       RAISE;
3201 END Validate_Chargeback;
3202 
3203 ---------------------------------------------------------------------
3204 -- PROCEDURE
3205 --    Validate_Special_Pricing
3206 --
3207 -- PURPOSE
3208 --    This procedure contains special pricing validations
3209 --
3210 -- PARAMETERS
3211 --
3212 --
3213 -- NOTES
3214 ---------------------------------------------------------------------
3215 PROCEDURE Validate_Special_Pricing
3216 (
3217    itemtype   IN varchar2,
3218    itemkey    IN varchar2,
3219    actid      IN number,
3220    funcmode   IN varchar2,
3221    resultout  IN OUT NOCOPY varchar2
3222 )
3223 IS
3224    l_api_name            CONSTANT VARCHAR2(30) := 'Validate_Special_Pricing';
3225    l_api_version_number  CONSTANT NUMBER   := 1.0;
3226 
3227    l_resultout           VARCHAR2(30);
3228    l_batch_id            NUMBER;
3229    l_return_status       VARCHAR2(1);
3230    l_msg_count           NUMBER;
3231    l_msg_data            VARCHAR2(2000);
3232    l_error_msg           VARCHAR2(4000);
3233 
3234 l_batch_org_id               NUMBER;
3235 BEGIN
3236    IF OZF_DEBUG_HIGH_ON THEN
3237       OZF_UTILITY_PVT.debug_message('IN: ' || l_api_name || ' Funcmode: ' || funcmode);
3238    END IF;
3239 
3240    -- R12 MOAC Enhancement (+)
3241    l_batch_org_id := WF_ENGINE.GetItemAttrText(
3242                         itemtype  => itemtype,
3243                         itemkey   => itemkey,
3244                         aname     => 'OZF_BATCH_ORG_ID'
3245                      );
3246 
3247    IF (funcmode = 'TEST_CTX') THEN
3248       IF (NVL(MO_GLOBAL.get_access_mode, 'NULL') <> 'S') OR
3249           (NVL(MO_GLOBAL.get_current_org_id, -99) <> l_batch_org_id) THEN
3250          resultout := 'FALSE';
3251       ELSE
3252          resultout := 'TRUE';
3253       END IF;
3254       RETURN;
3255    END IF;
3256 
3257    IF (funcmode = 'SET_CTX') THEN
3258       MO_GLOBAL.set_policy_context(
3259          p_access_mode  => 'S',
3260          p_org_id       => l_batch_org_id
3261       );
3262       --resultout := 'COMPLETE:';
3263       RETURN;
3264    END IF;
3265    -- R12 MOAC Enhancement (-)
3266 
3267    IF (funcmode = 'RUN') THEN
3268       --
3269       l_batch_id := WF_ENGINE.GetItemAttrText(itemtype   => itemtype,
3270                                               itemkey  => itemkey,
3271                                               aname    => G_WF_ATTR_BATCH_ID);
3272       IF OZF_DEBUG_LOW_ON THEN
3273          OZF_UTILITY_PVT.debug_message('Batch ID '|| l_batch_id);
3274       END IF;
3275 
3276       IF l_batch_id IS NOT NULL THEN
3277          -- Verify the line information for this batch
3278          OZF_SPECIAL_PRICING_PVT.Validate_Order_Record (
3279              p_api_version        => 1
3280             ,p_init_msg_list      => FND_API.G_FALSE
3281             ,p_commit             => FND_API.G_FALSE
3282             ,p_validation_level   => FND_API.G_VALID_LEVEL_FULL
3283             ,p_resale_batch_id    => l_batch_id
3284             ,x_return_status      => l_return_status
3285             ,x_msg_data           => l_msg_data
3286             ,x_msg_count          => l_msg_count
3287             );
3288          IF l_return_status<> FND_API.G_RET_STS_SUCCESS THEN
3289             OZF_UTILITY_PVT.error_message('OZF_RESALE_CHBK_VALIDATE_ERR');
3290             RAISE FND_API.G_EXC_ERROR;
3291          END IF;
3292       ELSE
3293          OZF_UTILITY_PVT.error_message('OZF_RESALE_BATCH_ID_NULL');
3294          RAISE FND_API.G_EXC_ERROR;
3295       END IF;
3296       l_resultout := 'COMPLETE:SUCCESS';
3297       --
3298    ELSIF (funcmode = 'CANCEL') THEN
3299         l_resultout := 'COMPLETE:SUCCESS';
3300    ELSIF (funcmode IN ('RESPOND', 'FORWARD', 'TRANSFER')) THEN
3301         l_resultout := 'COMPLETE:SUCCESS';
3302    ELSIF (funcmode = 'TIMEOUT') THEN
3303         l_resultout := 'COMPLETE:SUCCESS';
3304    END IF;
3305 
3306    resultout := l_resultout;
3307 
3308 EXCEPTION
3309    WHEN FND_API.G_EXC_ERROR THEN
3310       FND_MSG_PUB.Count_And_Get (
3311           p_encoded => FND_API.G_FALSE,
3312           p_count => l_msg_count,
3313           p_data  => l_msg_data
3314       );
3315       Handle_Error(
3316           p_itemtype     => itemtype
3317          ,p_itemkey      => itemkey
3318          ,p_msg_count    => l_msg_count
3319          ,p_msg_data     => l_msg_data
3320          ,p_process_name => l_api_name
3321          ,x_error_msg    => l_error_msg
3322       );
3323       WF_CORE.context( G_PKG_NAME,l_api_name,itemtype,itemkey,actid,l_error_msg);
3324       l_resultout := 'COMPLETE:ERROR';
3325       RETURN;
3326    WHEN OTHERS THEN
3327       IF OZF_UNEXP_ERROR THEN
3328          FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
3329       END IF;
3330       FND_MSG_PUB.Count_And_Get (
3331           p_encoded => FND_API.G_FALSE,
3332           p_count => l_msg_count,
3333           p_data  => l_msg_data
3334       );
3335       Handle_Error(
3336           p_itemtype     => itemtype
3337          ,p_itemkey      => itemkey
3338          ,p_msg_count    => l_msg_count
3339          ,p_msg_data     => l_msg_data
3340          ,p_process_name => l_api_name
3341          ,x_error_msg    => l_error_msg
3342       );
3343       WF_CORE.context( G_PKG_NAME,l_api_name,itemtype,itemkey,actid,l_error_msg);
3344       RAISE;
3345 END Validate_Special_Pricing;
3346 
3347 ---------------------------------------------------------------------
3348 -- PROCEDURE
3349 --    Validate_Tracing
3350 --
3351 -- PURPOSE
3352 --    This procedure contains tracing data validations
3353 --
3354 -- PARAMETERS
3355 --
3356 --
3357 -- NOTES
3358 ---------------------------------------------------------------------
3359 PROCEDURE Validate_Tracing
3360 (
3361    itemtype   IN varchar2,
3362    itemkey    IN varchar2,
3363    actid      IN number,
3364    funcmode   IN varchar2,
3365    resultout  IN OUT NOCOPY varchar2
3366 )
3367 IS
3368    l_api_name            CONSTANT VARCHAR2(30) := 'Validate_Tracing';
3369    l_api_version_number  CONSTANT NUMBER   := 1.0;
3370 
3371    l_resultout           VARCHAR2(30);
3372    l_batch_id            NUMBER;
3373    l_return_status       VARCHAR2(1);
3374    l_msg_count           NUMBER;
3375    l_msg_data            VARCHAR2(2000);
3376    l_error_msg           VARCHAR2(4000);
3377 
3378 l_batch_org_id               NUMBER;
3379 
3380 BEGIN
3381    IF OZF_DEBUG_HIGH_ON THEN
3382       OZF_UTILITY_PVT.debug_message('IN: ' || l_api_name || ' Funcmode: ' || funcmode);
3383    END IF;
3384 
3385    -- R12 MOAC Enhancement (+)
3386    l_batch_org_id := WF_ENGINE.GetItemAttrText(
3387                         itemtype  => itemtype,
3388                         itemkey   => itemkey,
3389                         aname     => 'OZF_BATCH_ORG_ID'
3390                      );
3391 
3392    IF (funcmode = 'TEST_CTX') THEN
3393       IF (NVL(MO_GLOBAL.get_access_mode, 'NULL') <> 'S') OR
3394           (NVL(MO_GLOBAL.get_current_org_id, -99) <> l_batch_org_id) THEN
3395          resultout := 'FALSE';
3396       ELSE
3397          resultout := 'TRUE';
3398       END IF;
3399       RETURN;
3400    END IF;
3401 
3402    IF (funcmode = 'SET_CTX') THEN
3403       MO_GLOBAL.set_policy_context(
3404          p_access_mode  => 'S',
3405          p_org_id       => l_batch_org_id
3406       );
3407       --resultout := 'COMPLETE:';
3408       RETURN;
3409    END IF;
3410    -- R12 MOAC Enhancement (-)
3411 
3412    IF (funcmode = 'RUN') THEN
3413       --
3414       l_batch_id := WF_ENGINE.GetItemAttrText(itemtype   => itemtype,
3415                                               itemkey  => itemkey,
3416                                               aname    => G_WF_ATTR_BATCH_ID);
3417       IF OZF_DEBUG_LOW_ON THEN
3418          OZF_UTILITY_PVT.debug_message('Batch ID '|| l_batch_id);
3419       END IF;
3420 
3421       IF l_batch_id IS NOT NULL THEN
3422          -- Verify the line information for this batch
3423          OZF_TRACING_ORDER_PVT.Validate_Order_Record (
3424              p_api_version        => 1
3425             ,p_init_msg_list      => FND_API.G_FALSE
3426             ,p_commit             => FND_API.G_FALSE
3427             ,p_validation_level   => FND_API.G_VALID_LEVEL_FULL
3428             ,p_resale_batch_id    => l_batch_id
3429             ,x_return_status      => l_return_status
3430             ,x_msg_data           => l_msg_data
3431             ,x_msg_count          => l_msg_count
3432             );
3433          IF l_return_status<> FND_API.G_RET_STS_SUCCESS THEN
3434             OZF_UTILITY_PVT.error_message('OZF_RESALE_TRAC_VALIDATE_ERR');
3435             RAISE FND_API.G_EXC_ERROR;
3436          END IF;
3437       ELSE
3438          OZF_UTILITY_PVT.error_message('OZF_RESALE_BATCH_ID_NULL');
3439          RAISE FND_API.G_EXC_ERROR;
3440       END IF;
3441       l_resultout := 'COMPLETE:SUCCESS';
3442       --
3443    ELSIF (funcmode = 'CANCEL') THEN
3444         l_resultout := 'COMPLETE:SUCCESS';
3445    ELSIF (funcmode IN ('RESPOND', 'FORWARD', 'TRANSFER')) THEN
3446         l_resultout := 'COMPLETE:SUCCESS';
3447    ELSIF (funcmode = 'TIMEOUT') THEN
3448         l_resultout := 'COMPLETE:SUCCESS';
3449    END IF;
3450 
3451    resultout := l_resultout;
3452 
3453 EXCEPTION
3454    WHEN FND_API.G_EXC_ERROR THEN
3455       FND_MSG_PUB.Count_And_Get (
3456           p_encoded => FND_API.G_FALSE,
3457           p_count => l_msg_count,
3458           p_data  => l_msg_data
3459       );
3460       Handle_Error(
3461           p_itemtype     => itemtype
3462          ,p_itemkey      => itemkey
3463          ,p_msg_count    => l_msg_count
3464          ,p_msg_data     => l_msg_data
3465          ,p_process_name => l_api_name
3466          ,x_error_msg    => l_error_msg
3467       );
3468       WF_CORE.context( G_PKG_NAME,l_api_name,itemtype,itemkey,actid,l_error_msg);
3469       l_resultout := 'COMPLETE:ERROR';
3470       RETURN;
3471    WHEN OTHERS THEN
3472       IF OZF_UNEXP_ERROR THEN
3473          FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
3474       END IF;
3475       FND_MSG_PUB.Count_And_Get (
3476           p_encoded => FND_API.G_FALSE,
3477           p_count => l_msg_count,
3478           p_data  => l_msg_data
3479       );
3480       Handle_Error(
3481           p_itemtype     => itemtype
3482          ,p_itemkey      => itemkey
3483          ,p_msg_count    => l_msg_count
3484          ,p_msg_data     => l_msg_data
3485          ,p_process_name => l_api_name
3486          ,x_error_msg    => l_error_msg
3487       );
3488       WF_CORE.context( G_PKG_NAME,l_api_name,itemtype,itemkey,actid,l_error_msg);
3489       RAISE;
3490 END Validate_Tracing;
3491 
3492 
3493 PROCEDURE Start_Data_Process(
3494     p_resale_batch_id       IN  NUMBER
3495    ,p_caller_type           IN  VARCHAR2
3496 )
3497 IS
3498 l_api_name          CONSTANT VARCHAR2(30)    := 'Start_Data_Process';
3499 
3500 l_itemtype                   VARCHAR2(8)     := 'OZFRSIFD';
3501 l_process                    VARCHAR2(30)    := 'IFACE_DATA_PROCESS';
3502 l_itemkey                    VARCHAR2(240);
3503 l_itemuserkey                VARCHAR2(240);
3504 
3505 CURSOR get_batch_info(p_resale_batch_id IN NUMBER) IS
3506    SELECT status_code
3507    ,      last_updated_by
3508    ,      batch_type
3509    ,      batch_number
3510    FROM  ozf_resale_batches_all
3511    WHERE resale_batch_id = p_resale_batch_id;
3512 
3513 CURSOR emp_infor_csr(p_res_id NUMBER) IS
3514 -- BUBG 4953233 (+)
3515   SELECT  ppl.person_id
3516   FROM jtf_rs_resource_extns rsc
3517      , per_people_f ppl
3518   WHERE rsc.category = 'EMPLOYEE'
3519   AND ppl.person_id = rsc.source_id
3520   AND rsc.resource_id=p_res_id;
3521   -- SELECT employee_id
3522   -- FROM jtf_rs_res_emp_vl
3523   -- WHERE resource_id = p_res_id ;
3524 -- BUBG 4953233 (-)
3525 
3526 
3527 
3528 l_batch_info                 get_batch_info%ROWTYPE;
3529 l_emp_id                     NUMBER;
3530 l_user_name                  VARCHAR2(100);
3531 l_display_name               VARCHAR2(100);
3532 
3533 BEGIN
3534 
3535    OPEN get_batch_info(p_resale_batch_id);
3536    FETCH get_batch_info INTO l_batch_info;
3537    CLOSE get_batch_info;
3538 
3539    IF l_batch_info.status_code IN ('OPEN', 'DISPUTED') THEN
3540       UPDATE ozf_resale_batches_all
3541       SET status_code = 'PROCESSING'
3542       WHERE resale_batch_id = p_resale_batch_id;
3543    END IF;
3544    --Bugfix: 6510872
3545    --l_itemkey := p_resale_batch_id||'-'||TO_CHAR(sysdate, 'YYYY-MMDD-HH24MISS');
3546    l_itemkey :='IDP-'|| p_resale_batch_id||'-'||TO_CHAR(sysdate, 'YYYY-MMDD-HH24MISS');
3547    l_itemuserkey := l_batch_info.batch_type||'-'||
3548                     l_batch_info.batch_number||'-'||
3549                     TO_CHAR(sysdate, 'YYYY-MMDD-HH24MISS');
3550 
3551 
3552    WF_ENGINE.CreateProcess(
3553          itemType   => l_itemtype,
3554          itemKey    => l_itemkey,
3555          process    => l_process
3556    );
3557 
3558    WF_ENGINE.SetItemUserKey(
3559          itemType   => l_itemtype,
3560          itemKey    => l_itemkey,
3561          userKey    => l_itemuserkey
3562    );
3563 
3564    OPEN emp_infor_csr(OZF_UTILITY_PVT.get_resource_id(l_batch_info.last_updated_by));
3565    FETCH emp_infor_csr INTO l_emp_id;
3566    CLOSE emp_infor_csr;
3567 
3568    WF_DIRECTORY.GetRoleName(
3569           p_orig_system      => 'PER',
3570           p_orig_system_id   => l_emp_id ,
3571           p_name             => l_user_name,
3572           p_display_name     => l_display_name
3573    );
3574 
3575    WF_ENGINE.SetItemOwner(
3576           itemtype           => l_itemtype,
3577           itemkey            => l_itemkey,
3578           owner              => l_user_name
3579    );
3580 
3581    WF_ENGINE.SetItemAttrText(
3582           itemtype           => l_itemtype,
3583           itemkey            => l_itemkey ,
3584           aname              => 'OZF_RESALE_BATCH_ID',
3585           avalue             => p_resale_batch_id
3586    );
3587 
3588    WF_ENGINE.SetItemAttrText(
3589           itemtype           => l_itemtype,
3590           itemkey            => l_itemkey ,
3591           aname              => 'WF_ADMINISTRATOR',
3592           avalue             => l_user_name
3593    );
3594 
3595    WF_ENGINE.SetItemAttrText(
3596           itemtype           => l_itemtype,
3597           itemkey            => l_itemkey ,
3598           aname              => 'OZF_RESALE_BATCH_CALLER',
3599           avalue             => p_caller_type
3600    );
3601 
3602    WF_ENGINE.StartProcess(
3603           itemtype           => l_itemtype,
3604           itemkey            => l_itemkey
3605    );
3606 
3607 
3608 EXCEPTION
3609  WHEN FND_API.G_EXC_ERROR THEN
3610    IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
3611     FND_MESSAGE.Set_Name('OZF','OZF_API_DEBUG_MESSAGE');
3612     FND_MESSAGE.Set_Token('TEXT',G_PKG_NAME||'.'||l_api_name||': Error');
3613     FND_MSG_PUB.Add;
3614    END IF;
3615    RAISE;
3616  WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
3617    IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
3618     FND_MESSAGE.Set_Name('OZF','OZF_API_DEBUG_MESSAGE');
3619     FND_MESSAGE.Set_Token('TEXT',G_PKG_NAME||'.'||l_api_name||': Error');
3620     FND_MSG_PUB.Add;
3621    END IF;
3622    RAISE;
3623  WHEN OTHERS THEN
3624    IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
3625      FND_MSG_PUB.Add_Exc_Msg(G_PKG_NAME, l_api_name);
3626    END IF;
3627    RAISE;
3628 END Start_Data_Process;
3629 
3630 
3631 PROCEDURE Start_Batch_Payment(
3632     p_resale_batch_id       IN  NUMBER
3633    ,p_caller_type           IN  VARCHAR2
3634 )
3635 IS
3636 l_api_name          CONSTANT VARCHAR2(30)    := 'Start_Batch_Payment';
3637 
3638 l_itemtype                   VARCHAR2(8)     := 'OZFRSIFD';
3639 l_process                    VARCHAR2(30)    := 'PAYMENT_INITIATION_PROCESS';
3640 l_itemkey                    VARCHAR2(240);
3641 l_itemuserkey                VARCHAR2(240);
3642 
3643 CURSOR get_batch_info(p_resale_batch_id IN NUMBER) IS
3644    SELECT status_code
3645    ,      last_updated_by
3646    ,      batch_type
3647    ,      batch_number
3648    FROM  ozf_resale_batches_all
3649    WHERE resale_batch_id = p_resale_batch_id;
3650 
3651 CURSOR emp_infor_csr(p_res_id NUMBER) IS
3652 -- BUBG 4953233 (+)
3653   SELECT  ppl.person_id
3654   FROM jtf_rs_resource_extns rsc
3655      , per_people_f ppl
3656   WHERE rsc.category = 'EMPLOYEE'
3657   AND ppl.person_id = rsc.source_id
3658   AND rsc.resource_id=p_res_id;
3659   -- SELECT employee_id
3660   -- FROM jtf_rs_res_emp_vl
3661   -- WHERE resource_id = p_res_id ;
3662 -- BUBG 4953233 (-)
3663 
3664 l_batch_info                 get_batch_info%ROWTYPE;
3665 l_emp_id                     NUMBER;
3666 l_user_name                  VARCHAR2(100);
3667 l_display_name               VARCHAR2(100);
3668 
3669 BEGIN
3670 
3671    OPEN get_batch_info(p_resale_batch_id);
3672    FETCH get_batch_info INTO l_batch_info;
3673    CLOSE get_batch_info;
3674 
3675    IF l_batch_info.status_code IN ('OPEN', 'DISPUTED', 'PROCESSED') THEN
3676       UPDATE ozf_resale_batches_all
3677       SET status_code = 'PENDING_PAYMENT'
3678       WHERE resale_batch_id = p_resale_batch_id;
3679    END IF;
3680    --Bugfix: 6510872
3681    --l_itemkey := p_resale_batch_id||'-'||TO_CHAR(sysdate, 'YYYY-MMDD-HH24MISS');
3682    l_itemkey := 'PIP-'||p_resale_batch_id||'-'||TO_CHAR(sysdate, 'YYYY-MMDD-HH24MISS');
3683    l_itemuserkey := l_batch_info.batch_type||'-'||
3684                     l_batch_info.batch_number||'-'||
3685                     TO_CHAR(sysdate, 'YYYY-MMDD-HH24MISS');
3686 
3687 
3688    WF_ENGINE.CreateProcess(
3689          itemType   => l_itemtype,
3690          itemKey    => l_itemkey,
3691          process    => l_process
3692    );
3693 
3694    WF_ENGINE.SetItemUserKey(
3695          itemType   => l_itemtype,
3696          itemKey    => l_itemkey,
3697          userKey    => l_itemuserkey
3698    );
3699 
3700    OPEN emp_infor_csr(OZF_UTILITY_PVT.get_resource_id(l_batch_info.last_updated_by));
3701    FETCH emp_infor_csr INTO l_emp_id;
3702    CLOSE emp_infor_csr;
3703 
3704    WF_DIRECTORY.GetRoleName(
3705           p_orig_system      => 'PER',
3706           p_orig_system_id   => l_emp_id ,
3707           p_name             => l_user_name,
3708           p_display_name     => l_display_name
3709    );
3710 
3711    WF_ENGINE.SetItemOwner(
3712           itemtype           => l_itemtype,
3713           itemkey            => l_itemkey,
3714           owner              => l_user_name
3715    );
3716 
3717    WF_ENGINE.SetItemAttrText(
3718           itemtype           => l_itemtype,
3719           itemkey            => l_itemkey ,
3720           aname              => 'OZF_RESALE_BATCH_ID',
3721           avalue             => p_resale_batch_id
3722    );
3723 
3724    WF_ENGINE.SetItemAttrText(
3725           itemtype           => l_itemtype,
3726           itemkey            => l_itemkey ,
3727           aname              => 'WF_ADMINISTRATOR',
3728           avalue             => l_user_name
3729    );
3730 
3731    WF_ENGINE.SetItemAttrText(
3732           itemtype           => l_itemtype,
3733           itemkey            => l_itemkey ,
3734           aname              => 'OZF_RESALE_BATCH_CALLER',
3735           avalue             => p_caller_type
3736    );
3737 
3738    WF_ENGINE.StartProcess(
3739           itemtype           => l_itemtype,
3740           itemkey            => l_itemkey
3741    );
3742 
3743 
3744 EXCEPTION
3745  WHEN FND_API.G_EXC_ERROR THEN
3746    IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
3747     FND_MESSAGE.Set_Name('OZF','OZF_API_DEBUG_MESSAGE');
3748     FND_MESSAGE.Set_Token('TEXT',G_PKG_NAME||'.'||l_api_name||': Error');
3749     FND_MSG_PUB.Add;
3750    END IF;
3751    RAISE;
3752  WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
3753    IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
3754     FND_MESSAGE.Set_Name('OZF','OZF_API_DEBUG_MESSAGE');
3755     FND_MESSAGE.Set_Token('TEXT',G_PKG_NAME||'.'||l_api_name||': Error');
3756     FND_MSG_PUB.Add;
3757    END IF;
3758    RAISE;
3759  WHEN OTHERS THEN
3760    IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
3761      FND_MSG_PUB.Add_Exc_Msg(G_PKG_NAME, l_api_name);
3762    END IF;
3763    RAISE;
3764 END Start_Batch_Payment;
3765 
3766 END OZF_RESALE_WF_PVT;