DBA Data[Home] [Help]

PACKAGE BODY: APPS.OZF_CLAIM_PVT

Source


1 PACKAGE BODY OZF_CLAIM_PVT AS
2 /* $Header: ozfvclab.pls 120.29.12010000.3 2008/09/05 09:15:39 bkunjan ship $ */
3 
4 -- Package name     : OZF_CLAIM_PVT
5 -- Purpose          :
6 -- History          :
7 -- NOTE             :
8 -- End of Comments
9 
10 G_PKG_NAME      CONSTANT VARCHAR2(30) := 'OZF_CLAIM_PVT';
11 G_FILE_NAME     CONSTANT VARCHAR2(12) := 'ozfvclab.pls';
12 
13 -- status
14 G_CLAIM_STATUS  CONSTANT VARCHAR2(30) := 'OZF_CLAIM_STATUS';
15 G_INIT_STATUS   CONSTANT VARCHAR2(30) :=  NVL(fnd_profile.value('OZF_CLAIM_DEFAULT_STATUS'), 'NEW'); -- R12 Enhancements
16 G_OPEN_STATUS   CONSTANT VARCHAR2(30) := 'OPEN';
17 G_DUPLICATE_STATUS CONSTANT VARCHAR2(30) := 'DUPLICATE';
18 G_PENDING_STATUS CONSTANT VARCHAR2(30) := 'PENDING';
19 G_CANCELLED_STATUS CONSTANT VARCHAR2(30) := 'CANCELLED';
20 
21 -- object_type
22 G_EMPLOYEE_CAT  CONSTANT VARCHAR2(30) := 'EMPLOYEE';
23 G_RS_EMPLOYEE_TYPE  CONSTANT VARCHAR2(30) := 'RS_EMPLOYEE';
24 G_RS_GROUP_TYPE  CONSTANT VARCHAR2(30) := 'RS_GROUP';
25 G_RS_TEAM_TYPE  CONSTANT VARCHAR2(30) := 'RS_TEAM';
26 G_OBJECT_TYPE   CONSTANT VARCHAR2(10) := 'OZF_CLAM';
27 G_CLAIM_OBJECT_TYPE    CONSTANT VARCHAR2(30) := 'CLAM';
28 G_DEDUCTION_OBJECT_TYPE CONSTANT VARCHAR2(30) := 'DEDU';
29 G_CLAIM_LINE_OBJECT_TYPE    CONSTANT VARCHAR2(30) := 'LINE';
30 G_TASK_OBJECT_TYPE    CONSTANT VARCHAR2(30) := 'TASK';
31 
32 -- CLASS
33 G_CLAIM_CLASS           CONSTANT VARCHAR2(30) := 'CLAIM';
34 G_DEDUCTION_CLASS       CONSTANT VARCHAR2(30) := 'DEDUCTION';
35 G_OVERPAYMENT_CLASS     CONSTANT  VARCHAR2(20) := 'OVERPAYMENT';
36 G_CHARGE_CLASS          CONSTANT  VARCHAR2(20) := 'CHARGE';
37 G_GROUP_CLASS           CONSTANT  VARCHAR2(20) := 'GROUP';
38 
39 -- events
40 G_UPDATE_EVENT  CONSTANT VARCHAR2(30) := 'UPDATE';
41 G_NEW_EVENT     CONSTANT VARCHAR2(30) := 'NEW';
42 G_CREATION_EVENT_DESC  CONSTANT VARCHAR2(30) :='OZF_CLAIM_CREATE';
43 
44 --others
45 G_CLAIM_HISTORY_TYPE   CONSTANT VARCHAR2(30) := 'OZF_CLAMHIST';
46 G_CLAIM_TYPE           CONSTANT VARCHAR2(30) := 'OZF_CLAM';
47 
48 G_SYSTEM_DATE_TYPE     CONSTANT VARCHAR2(30) :='SYSTEM_DATE';
49 G_CLAIM_DATE_TYPE      CONSTANT VARCHAR2(30) :='CLAIM_DATE';
50 G_DUE_DATE_TYPE        CONSTANT VARCHAR2(30) :='DUE_DATE';
51 
52 
53 G_UPDATE_CALLED   boolean := false;  -- This variable is used in the update_claim procedure.
54                                      -- It is to see whether an update_claim is called upon already.
55                                      -- We use this to avoid multiple save_point setting for settlment.
56 G_YES       CONSTANT VARCHAR2(1) :='Y';
57 
58 G_ALLOW_UNREL_SHIPTO_FLAG VARCHAR2(1) := NVL(fnd_profile.value('OZF_CLAIM_UR_SHIPTO'),'N'); -- 4334023
59 
60 OZF_DEBUG_HIGH_ON BOOLEAN := FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_debug_high);
61 OZF_DEBUG_LOW_ON BOOLEAN := FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_debug_low);
62 
63 ---------------------------------------------------------------------
64 -- Definitions of some packagewise cursors.
65 ---------------------------------------------------------------------
66  -- fix for bug 5042046
67 CURSOR gp_func_currency_cd_csr IS
68 SELECT gs.currency_code
69 FROM   gl_sets_of_books gs,
70        ozf_sys_parameters osp
71 WHERE  gs.set_of_books_id = osp.set_of_books_id
72 AND    osp.org_id = MO_GLOBAL.GET_CURRENT_ORG_ID();
73 
74 ---------------------------------------------------------------------
75 -- Definitions of some packagewise data type.
76 ---------------------------------------------------------------------
77 Type gp_access_list_type is table of ams_access_pvt.access_rec_type INDEX BY BINARY_INTEGER;
78 
79 
80 ---------------------------------------------------------------------
81 -- PROCEDURE
82 --    Get_System_Status
83 --
84 -- PURPOSE
85 --    This procedure maps a user_status_id to a system status.
86 --
87 -- PARAMETERS
88 --    p_user_status_id: Id of the status defined by a user.
89 --    p_status_type:
90 --    x_system_status: the system status corresponding a user status id
91 --    x_msg_data
92 --    x_msg_count
93 --    x_return_status
94 --
95 -- NOTES
96 ---------------------------------------------------------------------
97 PROCEDURE Get_System_Status( p_user_status_id IN NUMBER,
98                              p_status_type    IN VARCHAR2,
99                              x_system_status  OUT NOCOPY VARCHAR,
100               x_msg_data       OUT NOCOPY VARCHAR2,
101                              x_msg_count      OUT NOCOPY NUMBER,
102               x_return_status  OUT NOCOPY VARCHAR2)
103 IS
104 CURSOR system_status_csr(p_user_status_id IN NUMBER,
105                          p_status_type    IN VARCHAR2)IS
106 SELECT system_status_code
107 FROM   ams_user_statuses_vl
108 WHERE  system_status_type = p_status_type
109 AND    user_status_id = p_user_status_id;
110 
111 BEGIN
112    -- Initialize API return status to sucess
113    x_return_status := FND_API.G_RET_STS_SUCCESS;
114 
115    OPEN system_status_csr(p_user_status_id, p_status_type);
116    FETCH system_status_csr INTO x_system_status;
117    CLOSE system_status_csr;
118 
119 EXCEPTION
120    WHEN OTHERS THEN
121       x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
122       IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_unexp_error) THEN
123          FND_MESSAGE.set_name('OZF', 'OZF_CLAIM_INVALID_STATUS_CODE');
124          FND_MSG_PUB.add;
125       END IF;
126       -- Standard call to get message count and if count=1, get the message
127       FND_MSG_PUB.Count_And_Get (
128          p_encoded => FND_API.G_FALSE,
129          p_count   => x_msg_count,
130          p_data    => x_msg_data
131       );
132 END Get_System_Status;
133 ---------------------------------------------------------------------
134 -- PROCEDURE
135 --    get_seeded_user_status
136 --
137 -- PURPOSE
138 --    This procedure maps system status to a seeded user status.
139 --
140 -- PARAMETERS
141 --    p_status_code: status code of a system status.
142 --    p_status_type:
143 --    x_user_status_id: the system status corresponding a user status id
144 --    x_return_status
145 --
146 -- NOTES
147 ---------------------------------------------------------------------
148 PROCEDURE get_seeded_user_status( p_status_code      IN VARCHAR2,
149                                   p_status_type      IN VARCHAR2,
150                                   x_user_status_id   OUT NOCOPY NUMBER,
151                                   x_return_status    OUT NOCOPY VARCHAR2)
152 IS
153 CURSOR Get_Status_csr IS
154 SELECT user_status_id
155 FROM   ams_user_statuses_vl
156 WHERE  system_status_type = p_status_type
157 AND    system_status_code = p_status_code
158 AND    seeded_flag = 'Y';
159 
160 BEGIN
161    -- Initialize API return status to sucess
162    x_return_status := FND_API.G_RET_STS_SUCCESS;
163 
164    OPEN Get_Status_csr;
165    FETCH Get_Status_csr INTO x_user_status_id;
166    CLOSE Get_Status_csr;
167 EXCEPTION
168   WHEN OTHERS THEN
169      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
170      IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_unexp_error) THEN
171         FND_MESSAGE.set_name('OZF', 'OZF_CLAIM_INVALID_USER_STATUS');
172         FND_MSG_PUB.add;
173      END IF;
174 END get_seeded_user_status;
175 ---------------------------------------------------------------------
176 -- PROCEDURE
177 --    Get_Claim_Number
178 --
179 -- PURPOSE
180 --    This procedure retrieves a claim number based on the object_type
181 --    and class.
182 --
183 -- PARAMETERS
184 --    p_claim  : The claim record passed in.
185 --    p_object_type : The type of object.
186 --    p_class       : class.
187 --    x_claim_number :claim number based on the object_type and class.
188 --    x_return_status
189 --
190 -- NOTES
191 ---------------------------------------------------------------------
192 PROCEDURE Get_Claim_Number( p_split_from_claim_id IN NUMBER,
193                             p_custom_setup_id IN NUMBER,
194                             x_claim_number   OUT NOCOPY VARCHAR2,
195                             x_msg_data       OUT NOCOPY VARCHAR2,
196                             x_msg_count      OUT NOCOPY NUMBER,
197                             x_return_status  OUT NOCOPY VARCHAR2)
198 
199 IS
200 CURSOR Claim_Number_csr(p_claim_id in number) IS
201 SELECT claim_number
202 FROM ozf_claims_all
203 WHERE claim_id = p_claim_id;
204 
205 CURSOR Number_of_Split_csr(p_split_from_claim_id in number) IS
206 SELECT count(claim_id)
207 FROM ozf_claims_all
208 WHERE split_from_claim_id = p_split_from_claim_id;
209 
210 CURSOR c_seq_csr IS
211 SELECT TO_CHAR(ams_source_codes_gen_s.NEXTVAL)
212 FROM DUAL;
213 
214 CURSOR prefix_csr (p_id in number) IS
215 SELECT source_code_suffix
216 FROM ams_custom_setups_b
217 WHERE custom_setup_id = p_id;
218 
219 CURSOR claim_number_count_csr(p_claim_number in varchar2) IS
220 SELECT count(claim_number)
221 FROM   ozf_claims_all
222 WHERE  upper(claim_number) = p_claim_number;
223 
224 l_count number := -1;
225 
226 l_prefix       VARCHAR2(30);
227 l_seq          NUMBER;
228 l_claim_number VARCHAR2(30);
229 l_temp_claim_number varchar2(30);
230 l_parent_claim_number VARCHAR2(30);
231 l_number_of_split_claim NUMBER;
232 
233 l_claim_number_length   NUMBER;
234 
235 BEGIN
236    -- Initialize API return status to sucess
237    x_return_status := FND_API.G_RET_STS_SUCCESS;
238 
239    IF (p_split_from_claim_id is null OR
240        p_split_from_claim_id = FND_API.G_MISS_NUM) THEN
241 
242        OPEN prefix_csr(p_custom_setup_id);
243        FETCH prefix_csr INTO l_prefix;
244        CLOSE prefix_csr;
245 
246        IF l_prefix is NULL THEN
247           IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
248              FND_MESSAGE.set_name('OZF', 'OZF_CLAIM_SUFFIX_NOT_FOUND');
249              FND_MSG_PUB.add;
250           END IF;
251      RAISE FND_API.G_EXC_ERROR;
252        END IF;
253 
254        OPEN c_seq_csr;
255        FETCH c_seq_csr INTO l_seq;
256        CLOSE c_seq_csr;
257 
258        l_claim_number := l_prefix || l_seq;
259        LOOP
260           OPEN claim_number_count_csr(l_claim_number);
261           FETCH claim_number_count_csr into l_count;
262           CLOSE claim_number_count_csr;
263 
264           -- Find the correct claim number
265           EXIT WHEN l_count = 0;
266 
267           -- get the next available number
268           OPEN c_seq_csr;
269           FETCH c_seq_csr INTO l_seq;
270           CLOSE c_seq_csr;
271           l_claim_number := l_prefix || l_seq;
272        END LOOP;
273    ELSE
274       -- Get the parent_claim_number
275       OPEN Claim_Number_csr(p_split_from_claim_id);
276       FETCH Claim_Number_csr INTO l_parent_claim_number;
277       ClOSE Claim_Number_csr;
278 
279       -- Get the number of split claims
280       OPEN Number_of_Split_csr(p_split_from_claim_id);
281       FETCH Number_of_Split_csr INTO l_number_of_split_claim;
282       CLOSE Number_of_Split_csr;
283 
284       l_number_of_split_claim := l_number_of_split_claim +1;
285 
286       --Bug fix 3354592
287       l_claim_number_length := length(l_parent_claim_number || '_' || l_number_of_split_claim);
288       IF  l_claim_number_length > 30 THEN
289         IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
290            FND_MESSAGE.set_name('OZF', 'OZF_CLAIM_NUMBER_TOO_LARGE');
291            FND_MSG_PUB.add;
292         END IF;
293         RAISE FND_API.G_EXC_ERROR;
294       END IF;
295       --Bug fix 3354592
296       l_claim_number := l_parent_claim_number || '_' || l_number_of_split_claim;
297    END IF;
298    x_claim_number := l_claim_number;
299 
300 EXCEPTION
301    WHEN FND_API.G_EXC_ERROR THEN
302      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
303    WHEN OTHERS THEN
304      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
305      IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
306         FND_MESSAGE.set_name('OZF', 'OZF_CLAIM_NO_CLAIM_NUMBER');
307         FND_MSG_PUB.add;
308      END IF;
309      FND_MSG_PUB.Count_And_Get (
310         p_encoded => FND_API.G_FALSE,
311         p_count   => x_msg_count,
312         p_data    => x_msg_data
313      );
314 END Get_Claim_Number;
315 
316 ---------------------------------------------------------------------
317 -- PROCEDURE
318 --    get_customer_info
319 --
320 -- PURPOSE
321 --    This procedure default the cusomter information
322 --
323 -- PARAMETERS
324 --    p_claim        : claim record
325 --    x_claim        : defaulted record
326 --
327 -- NOTES
328 ---------------------------------------------------------------------
329 PROCEDURE get_customer_info (p_claim          in  claim_rec_type,
330                              x_claim          OUT NOCOPY claim_rec_type,
331               x_return_status  OUT NOCOPY VARCHAR2)
332 IS
333 
334 l_claim  claim_rec_type := p_claim;
335 
336 -- get shipto customer based on shipto site
337 CURSOR shipto_cust_account_id_csr(p_site_use_id in number) is
338 select a.cust_account_id
339 FROM   HZ_CUST_ACCT_SITES a
340 ,      HZ_CUST_SITE_USES s
341 WHERE  a.cust_acct_site_id = s.cust_acct_site_id
342 and    s.site_use_id = p_site_use_id;
343 l_shipto_cust_account_id number;
344 
345 --default bill_to based on ship_to
346 CURSOR bill_to_bsd_ship_to_csr (p_shipto_id in number) is
347 SELECT bill_to_site_use_id
348 FROM   HZ_CUST_SITE_USES
349 WHERE  site_use_id = p_shipto_id;
350 
351 -- default get billto_site and pseudo salesrep_id, contact_id
352 -- from customer account table
353 -- not good performance
354 CURSOR cust_info_csr (p_cust_acct_id in NUMBER) is
355 SELECT s.site_use_id  -- b	illto site
356 ,      s.contact_id     -- party relation id (do not store this value- see SQL below)
357 FROM   HZ_CUST_ACCT_SITES a
358 ,      HZ_CUST_SITE_USES s
359 WHERE  a.cust_account_id = p_cust_acct_id
360 AND    a.cust_acct_site_id = s.cust_acct_site_id
361 AND    s.site_use_code = 'BILL_TO'
362 AND    s.primary_flag = 'Y';
363 
364 l_bill_to_id   number;
365 l_pseudo_contact_id    number;
366 
367 -- get primary ship to information
368 CURSOR cust_shipinfo_csr (p_cust_acct_id in NUMBER) is
369 SELECT s.site_use_id  --shipto site
370 FROM   HZ_CUST_ACCT_SITES a
371 ,      HZ_CUST_SITE_USES s
372 WHERE  a.cust_account_id = p_cust_acct_id
373 AND    a.cust_acct_site_id = s.cust_acct_site_id
374 AND    s.site_use_code = 'SHIP_TO'
375 AND    s.primary_flag = 'Y';
376 
377 
378 -- default contact id based on cust_acct_id and pseudo contact_id
379 CURSOR contact_id_csr(p_cust_account_id in number,
380                       p_party_relationship_id in number) is
381 SELECT p.party_id --     ,p.party_name
382 FROM   hz_relationships r -- Bug 4654753
383 ,      hz_parties p
384 ,      hz_cust_accounts c
385 WHERE  r.subject_id = p.party_id
386 AND    r.relationship_id = p_party_relationship_id -- Bug 4654753
387 AND    r.object_id = c.party_id
388 AND    c.cust_account_id = p_cust_account_id;
389 
390 -- default salesrep resource based on bill to/ship to
391 CURSOR salesrep_csr(p_site_use_id  in number) is
392 SELECT s.primary_salesrep_id -- salesrep id, r.name, r.resource_id -- resource id
393 FROM   HZ_CUST_SITE_USES s
394 WHERE  s.site_use_id = p_site_use_id;
395 
396 CURSOR PRM_SALES_REP_CSR (p_source_object_id in number)is
397 select primary_salesrep_id
398 from ra_customer_trx_all
399 where customer_trx_id = p_source_object_id;
400 
401 CURSOR billto_contact_CSR (p_source_object_id in number)is
402 select bill_to_contact_id
403 from ra_customer_trx
404 where customer_trx_id = p_source_object_id;
405 l_contact_id number;
406 
407 CURSOR contact_party_id_csr (p_contact_id in number) is
408 select p.party_id
409 from hz_parties p
410 ,    hz_cust_account_roles r
411 ,    hz_relationships rel
412 where   r.cust_account_role_id = p_contact_id
413 and  r.party_id = rel.party_id
414 and  rel.subject_id = p.party_id
415 and SUBJECT_TABLE_NAME = 'HZ_PARTIES'
416 AND OBJECT_TABLE_NAME = 'HZ_PARTIES'
417 AND DIRECTIONAL_FLAG = 'F';
418 
419 BEGIN
420 
421    -- Initialize API return status to sucess
422    x_return_status := FND_API.G_RET_STS_SUCCESS;
423 
424    -- Get customer info
425    OPEN cust_info_csr (l_claim.cust_account_id);
426    FETCH cust_info_csr INTO l_bill_to_id, l_pseudo_contact_id;
427    CLOSE cust_info_csr;
428 
429    -- Bug4334023: Default Ship To Information
430    -- if shipto_cust_account_id is null then
431    --    if ship to site info is not null then
432    --        get it from ship to site (AR passes only ship to site)
433    --    else
434    --        default it to cust_account_id if not a source deduction
435    --    end if
436    -- end if
437    IF (l_claim.ship_to_cust_account_id IS NULL OR
438           l_claim.ship_to_cust_account_id = FND_API.G_MISS_NUM) THEN
439       IF (l_claim.cust_shipto_acct_site_id is not null AND
440            l_claim.cust_shipto_acct_site_id <> FND_API.G_MISS_NUM) THEN
441             OPEN shipto_cust_account_id_csr(l_claim.cust_shipto_acct_site_id);
442             FETCH shipto_cust_account_id_csr INTO l_claim.ship_to_cust_account_id;
443             CLOSE shipto_cust_account_id_csr;
444       ELSE
445           IF (l_claim.SOURCE_OBJECT_ID IS NULL OR
446 		     l_claim.SOURCE_OBJECT_ID = FND_API.G_MISS_NUM) THEN
447               l_claim.ship_to_cust_account_id := l_claim.cust_account_id;
448           ELSE -- Added the condition for 6338281
449             IF ((l_claim.SOURCE_OBJECT_ID IS NOT NULL OR
450 		     l_claim.SOURCE_OBJECT_ID <> FND_API.G_MISS_NUM) AND l_claim.cust_shipto_acct_site_id is null
451              OR l_claim.cust_shipto_acct_site_id = FND_API.G_MISS_NUM ) THEN
452 		        l_claim.ship_to_cust_account_id := l_claim.cust_account_id;
453 		     END IF;
454           END IF;
455       END IF;
456    END IF;
457 
458    -- Bug4334023: Default Ship To Information
459    -- if ship to site info is null then
460    --       default to primary ship to of shipto_cust_account_id if not a source deduction
461    -- end if
462    -- Added the souce_object_class check for 6338281
463     IF (l_claim.cust_shipto_acct_site_id is null OR l_claim.cust_shipto_acct_site_id = FND_API.G_MISS_NUM)
464     AND (l_claim.SOURCE_OBJECT_ID IS NULL OR  l_claim.SOURCE_OBJECT_ID = FND_API.G_MISS_NUM OR
465         l_claim.SOURCE_OBJECT_CLASS IN ('BATCH','SOFT_FUND','SPECIAL_PRICE')) THEN
466          OPEN cust_shipinfo_csr (l_claim.ship_to_cust_account_id);
467          FETCH cust_shipinfo_csr INTO l_claim.cust_shipto_acct_site_id;
468          CLOSE cust_shipinfo_csr;
469    END IF;
470 
471 
472    IF (l_claim.cust_shipto_acct_site_id is null OR l_claim.cust_shipto_acct_site_id = FND_API.G_MISS_NUM)
473    THEN
474       l_claim.ship_to_cust_account_id := NULL;
475    END IF;
476 
477    -- Bug4334023: Default Bill To Information
478    -- if bill_to site is null Then
479    --    if shipto_cust_account_id is same as cust account id and ship to site is not null
480    --       default bill_to site based on the ship_to site
481    --    if still null then
482    --       default bill_to site based on the cust_account_id
483    -- end if;
484    IF (l_claim.cust_billto_acct_site_id is null OR
485        l_claim.cust_billto_acct_site_id = FND_API.G_MISS_NUM) THEN
486        IF l_claim.cust_shipto_acct_site_id IS NOT NULL AND l_claim.ship_to_cust_account_id = l_claim.cust_account_id THEN
487               OPEN bill_to_bsd_ship_to_csr (l_claim.cust_shipto_acct_site_id);
488               FETCH bill_to_bsd_ship_to_csr INTO l_claim.cust_billto_acct_site_id;
489               CLOSE bill_to_bsd_ship_to_csr;
490        END IF;
491        IF l_claim.cust_billto_acct_site_id is null THEN
492               l_claim.cust_billto_acct_site_id := l_bill_to_id;
493        END IF;
494    END IF;
495 
496 
497    -- default salesrep_id:
498    -- If ship_to site is not null Then
499    --    default salesrep_id based on the ship_to site
500    -- elsif bill_to site is not null
501    --    default salesrep_id based on the bill_to site
502    -- end if;
503    IF (l_claim.sales_rep_id is null OR
504        l_claim.sales_rep_id = FND_API.G_MISS_NUM) THEN
505 
506       -- If this is a deduction, we will try to get the salesrep_id from the transaction.
507       -- If we can't, we will try to default it based on shipto, billto and cust_acct_id.
508       --//Bug Fix: 7378832
509       IF l_claim.SOURCE_OBJECT_CLASS IN ('INVOICE','DM') THEN
510          IF (l_claim.SOURCE_OBJECT_ID is not NULL AND
511 		    l_claim.SOURCE_OBJECT_ID <> FND_API.G_MISS_NUM) THEN
512             OPEN PRM_SALES_REP_CSR (l_claim.source_object_id);
513             FETCH PRM_SALES_REP_CSR INTO l_claim.sales_rep_id;
514             CLOSE PRM_SALES_REP_CSR;
515          END IF;
516       END IF;
517 
518       IF (l_claim.sales_rep_id is null) THEN
519          IF l_claim.cust_shipto_acct_site_id is not null AND
520 	    l_claim.cust_shipto_acct_site_id <> FND_API.G_MISS_NUM AND
521 	    l_shipto_cust_account_id is not null AND
522 	    l_shipto_cust_account_id = l_claim.cust_account_id THEN
523 
524 	    OPEN salesrep_csr(l_claim.cust_shipto_acct_site_id);
525 	    FETCH salesrep_csr INTO l_claim.sales_rep_id;
526 	    CLOSE salesrep_csr;
527 	END IF;
528 
529 	-- Try billto_acct_site_id if salesrep id is still null
530 	IF (l_claim.sales_rep_id is null AND
531             l_claim.cust_billto_acct_site_id is not null AND
532 	    l_claim.cust_billto_acct_site_id <> FND_API.G_MISS_NUM) THEN
533 
534 	    OPEN salesrep_csr(l_claim.cust_billto_acct_site_id);
535             FETCH salesrep_csr INTO l_claim.sales_rep_id;
536 	    CLOSE salesrep_csr;
537 	END IF;
538       END IF;
539    END IF;
540 
541    -- default contact_id
542    -- if pseudo_contact_id is not null
543    --    default contact_id based on pseudo_contact_id and cust_account_id
544    -- end if;
545    IF (l_claim.CONTACT_ID is null OR
546        l_claim.contact_id = FND_API.G_MISS_NUM) THEN
547 
548 		 -- If this is a deduction, we will try to get the salesrep_id from the transaction.
549        -- If we can't, we will try to default it based on shipto, billto and cust_acct_id.
550        IF (l_claim.SOURCE_OBJECT_ID is not NULL AND
551 		     l_claim.SOURCE_OBJECT_ID <> FND_API.G_MISS_NUM) THEN
552           OPEN billto_contact_CSR (l_claim.source_object_id);
553           FETCH billto_contact_CSR INTO l_contact_id;
554           CLOSE billto_contact_CSR;
555 
556 			 IF l_contact_id is not null THEN
557 			    -- We need to transfer this id to party id
558 			    OPEN contact_party_id_csr (l_contact_id);
559 				 FETCH contact_party_id_csr into l_claim.contact_id;
560 				 CLOSE contact_party_id_csr;
561 			 END IF;
562        END IF;
563 
564        IF l_claim.contact_id is null and l_pseudo_contact_id is not null THEN
565           OPEN contact_id_csr(l_claim.cust_account_id, l_pseudo_contact_id);
566 			 FETCH contact_id_csr INTO l_claim.contact_id;
567 			 CLOSE contact_id_csr;
568        END IF;
569    END IF;
570 
571    x_claim := l_claim;
572 EXCEPTION
573    WHEN FND_API.G_EXC_ERROR THEN
574      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
575    WHEN OTHERS THEN
576      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
577      IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
578         FND_MESSAGE.set_name('OZF', 'OZF_CLAIM_CUSTOMER_INFO_ERR');
579         FND_MSG_PUB.add;
580      END IF;
581 END get_customer_info;
582 
583 ---------------------------------------------------------------------
584 -- PROCEDURE
585 --    get_days_due
586 --
587 -- PURPOSE
588 --    This procedure maps gets the days_due
589 --
590 -- PARAMETERS
591 --    p_cust_account : custome account id
592 --    x_days_due     : days due
593 --
594 -- NOTES
595 ---------------------------------------------------------------------
596 PROCEDURE get_days_due (p_cust_accout_id IN  NUMBER,
597                         x_days_due       OUT NOCOPY NUMBER,
598 			x_return_status  OUT NOCOPY VARCHAR2)
599 IS
600 CURSOR days_due_csr(p_customer_account_id in number) IS
601 SELECT days_due
602 FROM   ozf_cust_trd_prfls
603 WHERE  cust_account_id = p_customer_account_id;
604 
605 -- fix for bug 5042046
606 CURSOR sys_parameters_days_due_csr IS
607 SELECT days_due
608 FROM   ozf_sys_parameters
609 where   org_id = MO_GLOBAL.GET_CURRENT_ORG_ID();
610 
611 l_days_due  number;
612 BEGIN
613 
614    -- Initialize API return status to sucess
615     x_return_status := FND_API.G_RET_STS_SUCCESS;
616 
617    -- get customer info from trade profile
618    OPEN days_due_csr(p_cust_accout_id);
619    FETCH days_due_csr into l_days_due;
620    CLOSE days_due_csr;
621 
622    -- get days_due from ozf_sys_parameters.
623    IF l_days_due is null  THEN
624       OPEN sys_parameters_days_due_csr;
625       FETCH sys_parameters_days_due_csr INTO l_days_due;
626       CLOSE sys_parameters_days_due_csr;
627       IF l_days_due is null THEN
628          l_days_due := 0;
629       END IF;
630    END IF;
631    x_days_due:= l_days_due;
632 EXCEPTION
633    WHEN FND_API.G_EXC_ERROR THEN
634      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
635    WHEN OTHERS THEN
636      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
637      IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
638         FND_MESSAGE.set_name('OZF', 'OZF_CLAIM_DAYS_DUE_ERR');
639         FND_MSG_PUB.add;
640      END IF;
641 END get_days_due;
642 
643 ---------------------------------------------------------------------
644 -- PROCEDURE
645 --    get_offer_qualifiers
646 --
647 -- PURPOSE
648 --    This procedure gets the values of offer qualifiers
649 --
650 -- PARAMETERS
651 --
652 --
653 -- NOTES
654 ---------------------------------------------------------------------
655 PROCEDURE get_offer_qualifiers(
656         p_cust_account_id    IN NUMBER,
657 	p_billto_site_id     IN NUMBER,
658 	p_shipto_site_id     IN NUMBER,
659 	x_account_code       OUT NOCOPY NUMBER,
660 	x_customer_category  OUT NOCOPY VARCHAR2,
661 	x_customer_id      OUT NOCOPY NUMBER,
662 	x_sales_channel      OUT NOCOPY VARCHAR2,
663 	x_customer_profile   OUT NOCOPY NUMBER,
664 	x_site_class         OUT NOCOPY VARCHAR2,
665 	x_city               OUT NOCOPY VARCHAR2,
666 	x_county             OUT NOCOPY VARCHAR2,
667 	x_country            OUT NOCOPY VARCHAR2,
668 	x_postal_code        OUT NOCOPY VARCHAR2,
669 	x_state              OUT NOCOPY VARCHAR2,
670 	x_province           OUT NOCOPY VARCHAR2,
671 	x_party_relation     OUT NOCOPY VARCHAR2,
672 	x_account_classification OUT NOCOPY NUMBER,
673 	x_account_hierarchy  OUT NOCOPY NUMBER,
674 	x_return_status      OUT NOCOPY VARCHAR2
675 )IS
676 l_account_code                number:=null;
677 l_customer_category           varchar2(30):=null;
678 l_customer_id                 number;
679 l_sales_channel               varchar2(30):=null;
680 l_customer_profile_id         number;
681 l_site_class                  varchar2(30):=null;
682 l_city                        varchar2(60):=null;
683 l_county                      varchar2(60):=null;
684 l_country                     varchar2(60):=null;
685 l_postal_code                 varchar2(60):=null;
686 l_state                       varchar2(60):=null;
687 l_province                    varchar2(60):=null;
688 l_party_relation              varchar2(60):=null;
689 l_account_classification      number;
690 l_account_hierarchy           number;
691 
692 CURSOR account_code_csr(p_site_id in number)is
693 SELECT party_site_id
694 FROM hz_cust_acct_sites
695 WHERE cust_acct_site_id = p_site_id;
696 
697 CURSOR cust_account_info_csr(p_cust_account_id in number) is
698 SELECT party_id, sales_channel_code
699 FROM hz_cust_accounts
700 WHERE CUST_ACCOUNT_ID = p_cust_account_id;
701 
702 -- waiting for customer_class_code query
703 --CURSOR cust_account_info_csr(p_cust_account_id in number) is
704 --SELECT party_id, customer_class_code, sales_channel_code
705 --FROM hz_cust_accounts
706 --WHERE CUST_ACCOUNT_ID = p_cust_account_id;
707 
708 CURSOR party_info_csr(p_party_id in number)is
709 SELECT category_code
710 FROM hz_parties
711 WHERE party_id = p_party_id;
712 
713 CURSOR cust_profile_csr(p_account_id in number,
714                         p_site_use_id in number) is
715 SELECT profile_class_id
716 FROM hz_customer_profiles
717 WHERE cust_account_id = p_account_id
718 AND   site_use_id = p_site_use_id;
719 
720 CURSOR site_use_code_csr(p_site_use_id in number) is
721 SELECT site_use_code
722 FROM hz_cust_site_uses
723 WHERE site_use_id = p_site_use_id;
724 
725 --based on ship to site if found, else bill to site.
726 -- location_id is the primary key for hz_locations.
727 --to get location_id (verify the sqls)
728 CURSOR location_id_csr(p_site_id in number) IS
729 SELECT ps.location_id
730 FROM   hz_party_sites ps
731 ,      hz_cust_acct_sites ac
732 ,      hz_cust_site_uses su
733 WHERE  ps.party_site_id = ac.party_site_id
734 AND    ac.cust_acct_site_id = su.cust_acct_site_id
735 AND    su.site_use_id = p_site_id;
736 l_location_id number;
737 
738 CURSOR location_info_csr(p_location_id in number) is
739 SELECT  city, county, country, postal_code, state, province
740 FROM hz_locations
741 WHERE location_id = p_location_id;
742 
743 BEGIN
744    -- Initialize API return status to sucess
745    x_return_status := FND_API.G_RET_STS_SUCCESS;
746 
747   -- get account_code
748   IF p_shipto_site_id is not null THEN
749      OPEN account_code_csr(p_shipto_site_id);
750      FETCH account_code_csr into l_account_code;
751      CLOSE account_code_csr;
752   END IF;
753 
754   IF l_account_code is null and p_billto_site_id is not null THEN
755      OPEN account_code_csr(p_billto_site_id);
756      FETCH account_code_csr into l_account_code;
757      CLOSE account_code_csr;
758   END IF;
759 
760   OPEN cust_account_info_csr(p_cust_account_id);
761 --  FETCH cust_account_info_csr into l_customer_id, l_account_classification, l_sales_channel;
762   FETCH cust_account_info_csr into l_customer_id, l_sales_channel;
763   CLOSE cust_account_info_csr;
764 
765   OPEN party_info_csr(l_customer_id);
766   FETCH party_info_csr into l_customer_category;
767   CLOSE party_info_csr;
768 
769   IF p_shipto_site_id is not null THEN
770      OPEN cust_profile_csr(p_cust_account_id, p_shipto_site_id);
771      FETCH cust_profile_csr into l_customer_profile_id;
772      CLOSE cust_profile_csr;
773   END IF;
774 
775   -- get customer profile
776   IF l_customer_profile_id is null THEN
777      IF p_billto_site_id is not null THEN
778         OPEN cust_profile_csr(p_cust_account_id, p_billto_site_id);
779         FETCH cust_profile_csr into l_customer_profile_id;
780         CLOSE cust_profile_csr;
781 
782 	IF l_customer_profile_id is null THEN
783            OPEN cust_profile_csr(p_cust_account_id, null);
784            FETCH cust_profile_csr into l_customer_profile_id;
785            CLOSE cust_profile_csr;
786 	END IF;
787      ELSE
788         OPEN cust_profile_csr(p_cust_account_id, null);
789         FETCH cust_profile_csr into l_customer_profile_id;
790         CLOSE cust_profile_csr;
791      END IF;
792   END IF;
793 
794   -- get site classification
795   IF p_shipto_site_id is not null THEN
796      OPEN site_use_code_csr(p_shipto_site_id);
797      FETCH site_use_code_csr into l_site_class;
798      CLOSE site_use_code_csr;
799   END IF;
800 
801   IF l_site_class is null AND p_billto_site_id is not null THEN
802      OPEN site_use_code_csr(p_billto_site_id);
803      FETCH site_use_code_csr into l_site_class;
804      CLOSE site_use_code_csr;
805   END IF;
806 
807   -- get location_id
808   IF p_shipto_site_id is not null THEN
809      OPEN location_id_csr(p_shipto_site_id);
810      FETCH location_id_csr into l_location_id;
811      CLOSE location_id_csr;
812   END IF;
813 
814   IF l_location_id is null AND p_billto_site_id is not null THEN
815      OPEN location_id_csr(p_billto_site_id);
816      FETCH location_id_csr into l_location_id;
817      CLOSE location_id_csr;
818   END IF;
819 
820   -- If location_id is not null, then put the address info
821   IF l_location_id is not null THEN
822      OPEN location_info_csr (l_location_id);
823      FETCH location_info_csr into l_city, l_county, l_country, l_postal_code, l_state, l_province;
824      CLOSE location_info_csr;
825   END IF;
826 
827   x_account_code      := l_account_code;
828   x_customer_category := l_customer_category;
829   x_customer_id       := l_customer_id;
830   x_sales_channel     := l_sales_channel;
831   x_customer_profile  := l_customer_profile_id;
832   x_site_class        := l_site_class;
833   x_city              := l_city;
834   x_county            := l_county;
835   x_country           := l_country;
836   x_postal_code       := l_postal_code;
837   x_state             := l_state;
838   x_province          := l_province;
839   x_party_relation    := l_party_relation;
840   x_account_classification := l_account_classification;
841   x_account_hierarchy := l_account_hierarchy;
842 
843 EXCEPTION
844    WHEN FND_API.G_EXC_ERROR THEN
845      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
846    WHEN OTHERS THEN
847      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
848      IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
849         FND_MESSAGE.set_name('OZF', 'OZF_CLAIM_OFF_QUAL_ERR');
850         FND_MSG_PUB.add;
851      END IF;
852 END get_offer_qualifiers;
853 ---------------------------------------------------------------------
854 -- PROCEDURE
855 --    get_owner
856 --
857 -- PURPOSE
858 --    This procedure gets the owner of a claim by call jft_terr assignment manager
859 --
860 -- PARAMETERS
861 --
862 --
863 -- NOTES
864 ---------------------------------------------------------------------
865 PROCEDURE get_owner (p_claim_type_id   IN NUMBER,
866                      p_claim_id        IN NUMBER,
867                      p_reason_code_id  IN NUMBER,
868                      p_vendor_id       IN NUMBER,
869                      p_vendor_site_id  IN NUMBER,
870                      p_cust_account_id IN NUMBER,
871                      p_billto_site_id  IN NUMBER,
872                      p_shipto_site_id  IN NUMBER,
873                      p_claim_class     IN VARCHAR2,
874                      x_owner_id       OUT NOCOPY NUMBER,
875                      x_access_list    OUT NOCOPY gp_access_list_type,
876                      x_return_status  OUT NOCOPY VARCHAR2)
877 IS
878 lp_gen_bulk_Rec               JTF_TERR_ASSIGN_PUB.bulk_trans_rec_type;
879 l_gen_return_Rec              JTF_TERR_ASSIGN_PUB.bulk_winners_rec_type;
880 l_use_type                    VARCHAR2(30);
881 l_Return_Status               VARCHAR2(01);
882 l_Msg_Count                   NUMBER;
883 l_Msg_Data                    VARCHAR2(2000);
884 l_counter                     NUMBER;
885 l_rank                        NUMBER;
886 l_account_code                number;
887 l_customer_category           varchar2(30);
888 l_customer_id                 number;
889 l_sales_channel               varchar2(30);
890 l_customer_profile_id         number;
891 l_site_class                  varchar2(30);
892 l_city                        varchar2(60);
893 l_county                      varchar2(60);
894 l_country                     varchar2(60);
895 l_postal_code                 varchar2(60);
896 l_state                       varchar2(60);
897 l_province                    varchar2(60);
898 l_party_relation              varchar2(60);
899 l_account_classification      varchar2(60);
900 l_account_hierarchy           number;
901 l_access_list gp_access_list_type;
902 
903 CURSOR group_member_csr(p_id in number) is
904 select b.category, b.resource_id
905 from jtf_rs_group_members a, ams_jtf_rs_emp_v b
906 where a.resource_id = b.resource_id
907 and a.group_id = p_id
908 and a.delete_flag = 'N';
909 
910 TYPE group_member_list_TYPE is table of group_member_csr%rowType
911                                INDEX BY BINARY_INTEGER;
912 l_group_member_list group_member_list_type;
913 
914 -- R12 enhancements
915 
916 CURSOR team_member_csr(p_id in number) is
917 select team_resource_id , c.lead_flag
918 from jtf_rs_team_members a,  jtf_rs_defresroles_vl c
919 where a.team_member_id = c.role_resource_id(+)
920 and a.team_id = p_id
921 and a.delete_flag = 'N'
922 and c.delete_flag(+) = 'N'
923 and c.role_resource_type(+) = 'RS_TEAM_MEMBER';
924 
925 l_team_member_resource_id number := null;
926 l_team_member_lead_flag varchar2(5) := null;
927 
928 l_primary_group_id number:= null;
929 
930 l_access_list_index number;
931 BEGIN
932 
933     -- Initialize API return status to sucess
934     x_return_status := FND_API.G_RET_STS_SUCCESS;
935 
936     x_owner_id := null;
937 
938     get_offer_qualifiers(
939         p_cust_account_id => p_cust_account_id,
940         p_billto_site_id  => p_billto_site_id,
941         p_shipto_site_id  => p_shipto_site_id,
942         x_account_code    => l_account_code,
943         x_customer_category => l_customer_category,
944         x_customer_id   => l_customer_id,
945         x_sales_channel   => l_sales_channel,
946         x_customer_profile=> l_customer_profile_id,
947         x_site_class      => l_site_class,
948         x_city            => l_city,
949         x_county          => l_county,
950         x_country         => l_country,
951         x_postal_code     => l_postal_code,
952         x_state           => l_state,
953         x_province        => l_province,
954         x_party_relation  => l_party_relation,
955         x_account_classification => l_account_classification,
956         x_account_hierarchy => l_account_hierarchy,
957         x_return_status   => x_return_status
958     );
959     IF x_return_status = FND_API.g_ret_sts_error THEN
960        RAISE FND_API.g_exc_error;
961     ELSIF x_return_status = FND_API.g_ret_sts_unexp_error THEN
962        RAISE FND_API.g_exc_error;
963     END IF;
964 
965     -- bulk_trans_rec_type instantiation
966     -- logic control properties
967     lp_gen_bulk_rec.trans_object_id         := JTF_TERR_NUMBER_LIST(null);
968     lp_gen_bulk_rec.trans_detail_object_id  := JTF_TERR_NUMBER_LIST(null);
969 
970     -- extend qualifier elements
971     lp_gen_bulk_rec.SQUAL_NUM01.EXTEND;
972     lp_gen_bulk_rec.SQUAL_NUM02.EXTEND;
973     lp_gen_bulk_rec.SQUAL_NUM03.EXTEND;
974     lp_gen_bulk_rec.SQUAL_NUM04.EXTEND;
975     lp_gen_bulk_rec.SQUAL_NUM05.EXTEND;
976     lp_gen_bulk_rec.SQUAL_NUM06.EXTEND;
977     lp_gen_bulk_rec.SQUAL_NUM07.EXTEND;
978     lp_gen_bulk_rec.SQUAL_NUM08.EXTEND;
979     lp_gen_bulk_rec.SQUAL_NUM09.EXTEND;
980     lp_gen_bulk_rec.SQUAL_NUM10.EXTEND;
981     lp_gen_bulk_rec.SQUAL_NUM11.EXTEND;
982     lp_gen_bulk_rec.SQUAL_NUM12.EXTEND;
983     lp_gen_bulk_rec.SQUAL_NUM13.EXTEND;
984     lp_gen_bulk_rec.SQUAL_NUM14.EXTEND;
985     lp_gen_bulk_rec.SQUAL_NUM15.EXTEND;
986     lp_gen_bulk_rec.SQUAL_NUM16.EXTEND;
987     lp_gen_bulk_rec.SQUAL_NUM17.EXTEND;
988     lp_gen_bulk_rec.SQUAL_NUM18.EXTEND;
989     lp_gen_bulk_rec.SQUAL_NUM19.EXTEND;
990     lp_gen_bulk_rec.SQUAL_NUM20.EXTEND;
991     lp_gen_bulk_rec.SQUAL_NUM21.EXTEND;
992     lp_gen_bulk_rec.SQUAL_NUM22.EXTEND;
993     lp_gen_bulk_rec.SQUAL_NUM23.EXTEND;
994     lp_gen_bulk_rec.SQUAL_NUM24.EXTEND;
995     lp_gen_bulk_rec.SQUAL_NUM25.EXTEND;
996     lp_gen_bulk_rec.SQUAL_NUM26.EXTEND;
997     lp_gen_bulk_rec.SQUAL_NUM27.EXTEND;
998     lp_gen_bulk_rec.SQUAL_NUM28.EXTEND;
999     lp_gen_bulk_rec.SQUAL_NUM29.EXTEND;
1000     lp_gen_bulk_rec.SQUAL_NUM30.EXTEND;
1001     lp_gen_bulk_rec.SQUAL_NUM31.EXTEND;
1002     lp_gen_bulk_rec.SQUAL_NUM32.EXTEND;
1003     lp_gen_bulk_rec.SQUAL_NUM33.EXTEND;
1004     lp_gen_bulk_rec.SQUAL_NUM34.EXTEND;
1005     lp_gen_bulk_rec.SQUAL_NUM35.EXTEND;
1006     lp_gen_bulk_rec.SQUAL_NUM36.EXTEND;
1007     lp_gen_bulk_rec.SQUAL_NUM37.EXTEND;
1008     lp_gen_bulk_rec.SQUAL_NUM38.EXTEND;
1009     lp_gen_bulk_rec.SQUAL_NUM39.EXTEND;
1010     lp_gen_bulk_rec.SQUAL_NUM40.EXTEND;
1011     lp_gen_bulk_rec.SQUAL_NUM41.EXTEND;
1012     lp_gen_bulk_rec.SQUAL_NUM42.EXTEND;
1013     lp_gen_bulk_rec.SQUAL_NUM43.EXTEND;
1014     lp_gen_bulk_rec.SQUAL_NUM44.EXTEND;
1015     lp_gen_bulk_rec.SQUAL_NUM45.EXTEND;
1016     lp_gen_bulk_rec.SQUAL_NUM46.EXTEND;
1017     lp_gen_bulk_rec.SQUAL_NUM47.EXTEND;
1018     lp_gen_bulk_rec.SQUAL_NUM48.EXTEND;
1019     lp_gen_bulk_rec.SQUAL_NUM49.EXTEND;
1020     lp_gen_bulk_rec.SQUAL_NUM50.EXTEND;
1021 
1022 
1023     lp_gen_bulk_rec.SQUAL_CHAR01.EXTEND;
1024     lp_gen_bulk_rec.SQUAL_CHAR02.EXTEND;
1025     lp_gen_bulk_rec.SQUAL_CHAR03.EXTEND;
1026     lp_gen_bulk_rec.SQUAL_CHAR04.EXTEND;
1027     lp_gen_bulk_rec.SQUAL_CHAR05.EXTEND;
1028     lp_gen_bulk_rec.SQUAL_CHAR06.EXTEND;
1029     lp_gen_bulk_rec.SQUAL_CHAR07.EXTEND;
1030     lp_gen_bulk_rec.SQUAL_CHAR08.EXTEND;
1031     lp_gen_bulk_rec.SQUAL_CHAR09.EXTEND;
1032     lp_gen_bulk_rec.SQUAL_CHAR10.EXTEND;
1033     lp_gen_bulk_rec.SQUAL_CHAR11.EXTEND;
1034     lp_gen_bulk_rec.SQUAL_CHAR12.EXTEND;
1035     lp_gen_bulk_rec.SQUAL_CHAR13.EXTEND;
1036     lp_gen_bulk_rec.SQUAL_CHAR14.EXTEND;
1037     lp_gen_bulk_rec.SQUAL_CHAR15.EXTEND;
1038     lp_gen_bulk_rec.SQUAL_CHAR16.EXTEND;
1039     lp_gen_bulk_rec.SQUAL_CHAR17.EXTEND;
1040     lp_gen_bulk_rec.SQUAL_CHAR18.EXTEND;
1041     lp_gen_bulk_rec.SQUAL_CHAR19.EXTEND;
1042     lp_gen_bulk_rec.SQUAL_CHAR20.EXTEND;
1043     lp_gen_bulk_rec.SQUAL_CHAR21.EXTEND;
1044     lp_gen_bulk_rec.SQUAL_CHAR22.EXTEND;
1045     lp_gen_bulk_rec.SQUAL_CHAR23.EXTEND;
1046     lp_gen_bulk_rec.SQUAL_CHAR24.EXTEND;
1047     lp_gen_bulk_rec.SQUAL_CHAR25.EXTEND;
1048     lp_gen_bulk_rec.SQUAL_CHAR26.EXTEND;
1049     lp_gen_bulk_rec.SQUAL_CHAR27.EXTEND;
1050     lp_gen_bulk_rec.SQUAL_CHAR28.EXTEND;
1051     lp_gen_bulk_rec.SQUAL_CHAR29.EXTEND;
1052     lp_gen_bulk_rec.SQUAL_CHAR30.EXTEND;
1053     lp_gen_bulk_rec.SQUAL_CHAR31.EXTEND;
1054     lp_gen_bulk_rec.SQUAL_CHAR32.EXTEND;
1055     lp_gen_bulk_rec.SQUAL_CHAR33.EXTEND;
1056     lp_gen_bulk_rec.SQUAL_CHAR34.EXTEND;
1057     lp_gen_bulk_rec.SQUAL_CHAR35.EXTEND;
1058     lp_gen_bulk_rec.SQUAL_CHAR36.EXTEND;
1059     lp_gen_bulk_rec.SQUAL_CHAR37.EXTEND;
1060     lp_gen_bulk_rec.SQUAL_CHAR38.EXTEND;
1061     lp_gen_bulk_rec.SQUAL_CHAR39.EXTEND;
1062     lp_gen_bulk_rec.SQUAL_CHAR40.EXTEND;
1063     lp_gen_bulk_rec.SQUAL_CHAR41.EXTEND;
1064     lp_gen_bulk_rec.SQUAL_CHAR42.EXTEND;
1065     lp_gen_bulk_rec.SQUAL_CHAR43.EXTEND;
1066     lp_gen_bulk_rec.SQUAL_CHAR44.EXTEND;
1067     lp_gen_bulk_rec.SQUAL_CHAR45.EXTEND;
1068     lp_gen_bulk_rec.SQUAL_CHAR46.EXTEND;
1069     lp_gen_bulk_rec.SQUAL_CHAR47.EXTEND;
1070     lp_gen_bulk_rec.SQUAL_CHAR48.EXTEND;
1071     lp_gen_bulk_rec.SQUAL_CHAR49.EXTEND;
1072     lp_gen_bulk_rec.SQUAL_CHAR50.EXTEND;
1073 
1074     -- transaction qualifier values
1075     lp_gen_bulk_rec.SQUAL_NUM01(1) := l_customer_id;
1076     lp_gen_bulk_rec.SQUAL_NUM02(1) := l_account_code;
1077     lp_gen_bulk_rec.SQUAL_NUM03(1) := null;
1078     lp_gen_bulk_rec.SQUAL_NUM04(1) := l_account_hierarchy;
1079     lp_gen_bulk_rec.SQUAL_NUM05(1) := null;
1080     lp_gen_bulk_rec.SQUAL_NUM06(1) := null;
1081     lp_gen_bulk_rec.SQUAL_NUM07(1) := l_account_classification;
1082     lp_gen_bulk_rec.SQUAL_NUM08(1) := null;
1083     lp_gen_bulk_rec.SQUAL_NUM09(1) := null;
1084     lp_gen_bulk_rec.SQUAL_NUM10(1) := null;
1085     lp_gen_bulk_rec.SQUAL_NUM11(1) := null;
1086     lp_gen_bulk_rec.SQUAL_NUM12(1) := null;
1087     lp_gen_bulk_rec.SQUAL_NUM13(1) := null;
1088     lp_gen_bulk_rec.SQUAL_NUM14(1) := null;
1089     lp_gen_bulk_rec.SQUAL_NUM15(1) := l_customer_profile_id;
1090     lp_gen_bulk_rec.SQUAL_NUM16(1) := null;
1091     lp_gen_bulk_rec.SQUAL_NUM17(1) := null;
1092     lp_gen_bulk_rec.SQUAL_NUM18(1) := null;
1093     lp_gen_bulk_rec.SQUAL_NUM19(1) := null;
1094     lp_gen_bulk_rec.SQUAL_NUM20(1) := null;
1095     lp_gen_bulk_rec.SQUAL_NUM21(1) := p_claim_type_id; -- claim_type_id: sal01: 4 Promotion Good Request;; sal03: 5 Invoice deduction
1096     lp_gen_bulk_rec.SQUAL_NUM22(1) := p_reason_code_id; -- reason_code_id: sal01: 3 Promotion;; sal03: 82 1 year agreement
1097     lp_gen_bulk_rec.SQUAL_NUM23(1) := p_vendor_id;
1098     lp_gen_bulk_rec.SQUAL_NUM24(1) := p_vendor_site_id;
1099     lp_gen_bulk_rec.SQUAL_NUM25(1) := null;
1100     lp_gen_bulk_rec.SQUAL_NUM26(1) := null;
1101     lp_gen_bulk_rec.SQUAL_NUM27(1) := null;
1102     lp_gen_bulk_rec.SQUAL_NUM28(1) := null;
1103     lp_gen_bulk_rec.SQUAL_NUM29(1) := null;
1104     lp_gen_bulk_rec.SQUAL_NUM30(1) := null;
1105     lp_gen_bulk_rec.SQUAL_NUM31(1) := null;
1106     lp_gen_bulk_rec.SQUAL_NUM32(1) := null;
1107     lp_gen_bulk_rec.SQUAL_NUM33(1) := null;
1108     lp_gen_bulk_rec.SQUAL_NUM34(1) := null;
1109     lp_gen_bulk_rec.SQUAL_NUM35(1) := null;
1110     lp_gen_bulk_rec.SQUAL_NUM36(1) := null;
1111     lp_gen_bulk_rec.SQUAL_NUM37(1) := null;
1112     lp_gen_bulk_rec.SQUAL_NUM38(1) := null;
1113     lp_gen_bulk_rec.SQUAL_NUM39(1) := null;
1114     lp_gen_bulk_rec.SQUAL_NUM40(1) := null;
1115     lp_gen_bulk_rec.SQUAL_NUM41(1) := null;
1116     lp_gen_bulk_rec.SQUAL_NUM42(1) := null;
1117     lp_gen_bulk_rec.SQUAL_NUM43(1) := null;
1118     lp_gen_bulk_rec.SQUAL_NUM44(1) := null;
1119     lp_gen_bulk_rec.SQUAL_NUM45(1) := null;
1120     lp_gen_bulk_rec.SQUAL_NUM46(1) := null;
1121     lp_gen_bulk_rec.SQUAL_NUM47(1) := null;
1122     lp_gen_bulk_rec.SQUAL_NUM48(1) := null;
1123     lp_gen_bulk_rec.SQUAL_NUM49(1) := null;
1124     lp_gen_bulk_rec.SQUAL_NUM50(1) := null;
1125 
1126     lp_gen_bulk_rec.SQUAL_CHAR01(1) := null;
1127     lp_gen_bulk_rec.SQUAL_CHAR02(1) := l_city;
1128     lp_gen_bulk_rec.SQUAL_CHAR03(1) := l_county;
1129     lp_gen_bulk_rec.SQUAL_CHAR04(1) := l_state;
1130     lp_gen_bulk_rec.SQUAL_CHAR05(1) := l_province;
1131     lp_gen_bulk_rec.SQUAL_CHAR06(1) := l_postal_code;
1132     lp_gen_bulk_rec.SQUAL_CHAR07(1) := l_country;
1133     lp_gen_bulk_rec.SQUAL_CHAR08(1) := null;
1134     lp_gen_bulk_rec.SQUAL_CHAR09(1) := l_customer_category;
1135     lp_gen_bulk_rec.SQUAL_CHAR10(1) := null;
1136     lp_gen_bulk_rec.SQUAL_CHAR11(1) := null;
1137     lp_gen_bulk_rec.SQUAL_CHAR12(1) := null;
1138     lp_gen_bulk_rec.SQUAL_CHAR13(1) := null;
1139     lp_gen_bulk_rec.SQUAL_CHAR14(1) := null;
1140     lp_gen_bulk_rec.SQUAL_CHAR15(1) := l_party_relation;
1141     lp_gen_bulk_rec.SQUAL_CHAR16(1) := l_sales_channel;
1142     lp_gen_bulk_rec.SQUAL_CHAR17(1) := l_site_class;
1143     lp_gen_bulk_rec.SQUAL_CHAR18(1) := null;
1144     lp_gen_bulk_rec.SQUAL_CHAR19(1) := null;
1145     lp_gen_bulk_rec.SQUAL_CHAR20(1) := p_claim_class;
1146     lp_gen_bulk_rec.SQUAL_CHAR21(1) := null;
1147     lp_gen_bulk_rec.SQUAL_CHAR22(1) := null;
1148     lp_gen_bulk_rec.SQUAL_CHAR23(1) := null;
1149     lp_gen_bulk_rec.SQUAL_CHAR24(1) := null;
1150     lp_gen_bulk_rec.SQUAL_CHAR25(1) := null;
1151     lp_gen_bulk_rec.SQUAL_CHAR26(1) := null;
1152     lp_gen_bulk_rec.SQUAL_CHAR27(1) := null;
1153     lp_gen_bulk_rec.SQUAL_CHAR28(1) := null;
1154     lp_gen_bulk_rec.SQUAL_CHAR29(1) := null;
1155     lp_gen_bulk_rec.SQUAL_CHAR30(1) := null;
1156     lp_gen_bulk_rec.SQUAL_CHAR31(1) := null;
1157     lp_gen_bulk_rec.SQUAL_CHAR32(1) := null;
1158     lp_gen_bulk_rec.SQUAL_CHAR33(1) := null;
1159     lp_gen_bulk_rec.SQUAL_CHAR34(1) := null;
1160     lp_gen_bulk_rec.SQUAL_CHAR35(1) := null;
1161     lp_gen_bulk_rec.SQUAL_CHAR36(1) := null;
1162     lp_gen_bulk_rec.SQUAL_CHAR37(1) := null;
1163     lp_gen_bulk_rec.SQUAL_CHAR38(1) := null;
1164     lp_gen_bulk_rec.SQUAL_CHAR39(1) := null;
1165     lp_gen_bulk_rec.SQUAL_CHAR40(1) := null;
1166     lp_gen_bulk_rec.SQUAL_CHAR41(1) := null;
1167     lp_gen_bulk_rec.SQUAL_CHAR42(1) := null;
1168     lp_gen_bulk_rec.SQUAL_CHAR43(1) := null;
1169     lp_gen_bulk_rec.SQUAL_CHAR44(1) := null;
1170     lp_gen_bulk_rec.SQUAL_CHAR45(1) := null;
1171     lp_gen_bulk_rec.SQUAL_CHAR46(1) := null;
1172     lp_gen_bulk_rec.SQUAL_CHAR47(1) := null;
1173     lp_gen_bulk_rec.SQUAL_CHAR48(1) := null;
1174     lp_gen_bulk_rec.SQUAL_CHAR49(1) := null;
1175     lp_gen_bulk_rec.SQUAL_CHAR50(1) := null;
1176 
1177     l_use_type := 'RESOURCE';                      -- OR l_use_type := 'LOOKUP';
1178     -- source_id : TM :-1003
1179     -- trasns_id : -1007 : offer, -1302: claim
1180     JTF_TERR_ASSIGN_PUB.get_winners
1181     (   p_api_version_number       => 1.0,
1182         p_init_msg_list            => FND_API.G_FALSE,
1183 
1184         p_use_type                 => l_use_type,
1185         p_source_id                => -1003,
1186         p_trans_id                 => -1302,
1187         p_trans_rec                => lp_gen_bulk_rec,
1188 
1189         p_resource_type            => FND_API.G_MISS_CHAR,
1190         p_role                     => FND_API.G_MISS_CHAR,
1191         p_top_level_terr_id        => FND_API.G_MISS_NUM,
1192         p_num_winners              => FND_API.G_MISS_NUM,
1193 
1194         x_return_status            => l_return_status,
1195         x_msg_count                => l_msg_count,
1196         x_msg_data                 => l_msg_data,
1197         x_winners_rec              => l_gen_return_rec
1198     );
1199    IF l_return_status = FND_API.g_ret_sts_error THEN
1200       RAISE FND_API.g_exc_error;
1201    ELSIF l_return_status = FND_API.g_ret_sts_unexp_error THEN
1202       RAISE FND_API.g_exc_unexpected_error;
1203    END IF;
1204 
1205    IF OZF_DEBUG_HIGH_ON THEN
1206       ozf_utility_PVT.debug_message('winner count:' || l_gen_return_Rec.terr_id.count );
1207    END IF;
1208    IF (l_gen_return_Rec.terr_id.LAST >= 1) THEN
1209 
1210       -- For the list of winners, we need to do two things.
1211       -- 1. find the owner
1212       -- 2. create the access list based on the ranking and territory.
1213        -- We only need to consider the winners in the first ranking.
1214 
1215      l_rank := l_gen_return_Rec.absolute_rank(l_gen_return_Rec.terr_id.FIRST);
1216      For i in 1..l_gen_return_Rec.terr_id.LAST LOOP
1217          l_access_list(i).arc_act_access_to_object := G_CLAIM_OBJECT_TYPE;
1218          l_access_list(i).user_or_role_id := l_gen_return_Rec.RESOURCE_ID(i);
1219 
1220          IF OZF_DEBUG_HIGH_ON THEN
1221            ozf_utility_PVT.debug_message('winner :'||i||' resource_id:' || l_gen_return_Rec.resource_id(i) );
1222            ozf_utility_PVT.debug_message('winner :'||i||' type:' || l_gen_return_Rec.resource_type(i) );
1223            ozf_utility_PVT.debug_message('winner :'||i||' group_id:' || l_gen_return_Rec.group_id(i) );
1224          END IF;
1225 
1226          l_access_list(i).admin_flag := 'N';
1227          l_access_list(i).owner_flag := 'N';
1228 
1229          IF l_gen_return_Rec.RESOURCE_TYPE(i) = G_RS_EMPLOYEE_TYPE THEN
1230              l_access_list(i).arc_user_or_role_type := 'USER';
1231              IF l_gen_return_Rec.primary_contact_flag(i) = 'Y' THEN
1232                 x_owner_id := l_gen_return_Rec.RESOURCE_ID(i);
1233              ELSE IF x_owner_id is null THEN
1234                      x_owner_id := l_gen_return_Rec.RESOURCE_ID(i);
1235                   END IF;
1236              END IF;
1237          ELSIF l_gen_return_Rec.RESOURCE_TYPE(i) = G_RS_GROUP_TYPE THEN
1238              l_access_list(i).arc_user_or_role_type := 'GROUP';
1239              IF l_gen_return_Rec.primary_contact_flag(i) = 'Y' THEN
1240                 l_primary_group_id := l_gen_return_Rec.RESOURCE_ID(i);
1241              END IF;
1242 	 ELSIF l_gen_return_Rec.RESOURCE_TYPE(i) = G_RS_TEAM_TYPE THEN
1243              -- Loop through all the team members and add them to the access list
1244              l_access_list_index := l_access_list.LAST;
1245              OPEN team_member_csr(l_gen_return_Rec.RESOURCE_ID(i));
1246                LOOP
1247                  FETCH team_member_csr into l_team_member_resource_id, l_team_member_lead_flag;
1248                  EXIT when team_member_csr%NOTFOUND;
1249                    l_access_list(l_access_list_index).arc_user_or_role_type := 'USER';
1250                    l_access_list(l_access_list_index).user_or_role_id := l_team_member_resource_id;
1251                    l_access_list(l_access_list_index).arc_act_access_to_object := G_CLAIM_OBJECT_TYPE;
1252                    l_access_list(l_access_list_index).act_access_to_object_id := p_claim_id;
1253                    l_access_list(l_access_list_index).owner_flag := 'N';
1254                    IF l_gen_return_Rec.full_access_flag(i) = 'Y' THEN
1255                         l_access_list(l_access_list_index).admin_flag := 'Y';
1256                    END IF;
1257                    IF (l_gen_return_Rec.primary_contact_flag(i) = 'Y'
1258                      AND l_team_member_lead_flag = 'Y') THEN
1259                        x_owner_id := l_team_member_resource_id;
1260                    ELSIF ( x_owner_id is null ) AND (l_team_member_lead_flag = 'Y') THEN
1261                        x_owner_id := l_team_member_resource_id;
1262                    ELSE
1263                      IF x_owner_id is null THEN
1264                        x_owner_id := l_team_member_resource_id;
1265                       END IF;
1266                    END IF;
1267                    l_access_list_index := l_access_list_index +1;
1268                END LOOP;
1269              CLOSE team_member_csr;
1270          END IF;
1271          EXIT WHEN l_gen_return_Rec.absolute_rank(i) <> l_rank;
1272      END LOOP;
1273 
1274      -- In case there is no owner defined. We need to pick up a owner from the group
1275      IF x_owner_id is null THEN
1276         -- pick up the first group as the owner group.
1277         IF l_primary_group_id is null THEN
1278            l_primary_group_id := l_access_list(1).user_or_role_id;
1279         END IF;
1280         l_counter := 1;
1281         OPEN group_member_csr(l_primary_group_id);
1282         LOOP
1283           EXIT when group_member_csr%NOTFOUND;
1284           FETCH group_member_csr into l_group_member_list(l_counter);
1285           l_counter:= l_counter + 1;
1286         END LOOP;
1287         CLOSE group_member_csr;
1288 
1289         ---pick one person from the group to be the owner.
1290 	l_access_list_index := l_access_list.LAST;
1291          For i in 1..l_group_member_list.LAST LOOP
1292 	     IF OZF_DEBUG_HIGH_ON THEN
1293                ozf_utility_PVT.debug_message('l_group_member_list :'||i||' category:' || l_group_member_list(i).category );
1294                ozf_utility_PVT.debug_message('l_group_member_list :'||i||' resource_id:' || l_group_member_list(i).resource_id );
1295              END IF;
1296 
1297              IF l_group_member_list(i).category = G_EMPLOYEE_CAT THEN
1298                 x_owner_id := l_group_member_list(i).resource_id;
1299           		 l_access_list_index := l_access_list_index +1;
1300                 l_access_list(l_access_list_index).arc_act_access_to_object := G_CLAIM_OBJECT_TYPE;
1301                 l_access_list(l_access_list_index).user_or_role_id := l_group_member_list(i).resource_id;
1302                 l_access_list(l_access_list_index).admin_flag := 'Y';
1303                 l_access_list(l_access_list_index).owner_flag := 'Y';
1304                 l_access_list(l_access_list_index).arc_user_or_role_type := 'USER';
1305 
1306                  IF OZF_DEBUG_HIGH_ON THEN
1307                    ozf_utility_PVT.debug_message('end of assign');
1308                END IF;
1309 		exit;
1310              END IF;
1311          END LOOP;
1312      ELSE
1313          -- find the owner in the access list, update its field value
1314          FOR I in 1..l_access_list.last Loop
1315              IF l_access_list(i).user_or_role_id = x_owner_id THEN
1316                 l_access_list(i).admin_flag := 'Y';
1317                 l_access_list(i).owner_flag := 'Y';
1318              END IF;
1319          EXIT WHEN l_access_list(i).user_or_role_id = x_owner_id;
1320          END LOOP;
1321      END IF;
1322    ELSE
1323       x_owner_id := null;
1324    END IF;
1325    x_access_list := l_access_list;
1326 
1327 EXCEPTION
1328    WHEN FND_API.G_EXC_ERROR THEN
1329      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1330    WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1331      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1332    WHEN OTHERS THEN
1333      IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
1334          FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,'Get_owner');
1335       END IF;
1336      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1337      IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
1338         FND_MESSAGE.set_name('OZF', 'OZF_CLAIM_GET_OWNER_ERR');
1339         FND_MSG_PUB.add;
1340      END IF;
1341 END get_owner;
1342 
1343 ---------------------------------------------------------------------
1344 -- PROCEDURE
1345 --    generate_tasks
1346 --
1347 -- PURPOSE
1348 --    This procedure maps generate a task list for a claim based on the
1349 --    reason code.
1350 --
1351 -- PARAMETERS
1352 --    p_task_template_group_id : task_template_group_id
1353 --    p_owner_id    : person who is going to perform the task
1354 --    p_claim_id       : claim id
1355 --    x_return_status
1356 --
1357 -- NOTES
1358 ---------------------------------------------------------------------
1359 PROCEDURE generate_tasks( p_task_template_group_id   IN  NUMBER
1360                          ,p_owner_id         IN  NUMBER
1361                          ,p_claim_number     IN  VARCHAR2
1362                          ,p_claim_id         IN  NUMBER
1363                          ,x_return_status    OUT NOCOPY   VARCHAR2
1364                          )
1365 IS
1366 l_api_version          CONSTANT NUMBER := 1.0;
1367 l_claim_id             NUMBER := p_claim_id;
1368 l_source_object_name   varchar2(30) := p_task_template_group_id;
1369 l_task_details_tbl     JTF_TASKS_PUB.task_details_tbl;
1370 l_assignment_status_id NUMBER;
1371 l_task_assignment_id   NUMBER;
1372 l_return_status        VARCHAR2(30);
1373 l_msg_data             VARCHAR2(2000);
1374 l_msg_count            NUMBER;
1375 
1376 CURSOR task_status_csr (p_task_id in number) IS
1377 SELECT task_status_id
1378 FROM   jtf_tasks_vl
1379 WHERE  task_id = p_task_id;
1380 
1381 BEGIN
1382    -- Initialize API return status to sucess
1383    x_return_status := FND_API.G_RET_STS_SUCCESS;
1384 
1385    IF OZF_DEBUG_LOW_ON THEN
1386       FND_MESSAGE.Set_Name('OZF','OZF_API_DEBUG_MESSAGE');
1387       FND_MESSAGE.Set_Token('TEXT','create task from template');
1388       FND_MSG_PUB.Add;
1389    END IF;
1390 
1391    -- Generate taks template
1392    JTF_TASKS_PUB.create_task_from_template(
1393        p_api_version       => l_api_version
1394       ,p_init_msg_list     => FND_API.g_false
1395       ,p_commit            => FND_API.g_false
1396       ,x_return_status     => l_return_status
1397       ,x_msg_count         => l_msg_count
1398       ,x_msg_data          => l_msg_data
1399       ,p_task_template_group_id => p_task_template_group_id
1400       ,p_owner_type_code   => G_RS_EMPLOYEE_TYPE
1401       ,p_owner_id          => p_owner_id
1402       ,p_source_object_id  => l_claim_id
1403       ,p_source_object_name=> p_claim_number
1404       ,x_task_details_tbl  => l_task_details_tbl
1405    );
1406    IF l_return_status = FND_API.G_RET_STS_SUCCESS THEN
1407       -- Generate tasks
1408       FOR i in 1..l_task_details_tbl.count LOOP
1409 
1410           OPEN task_status_csr(l_task_details_tbl(i).task_id);
1411           FETCH task_status_csr INTO l_assignment_status_id;
1412           CLOSE task_status_csr;
1413 
1414           IF OZF_DEBUG_LOW_ON THEN
1415              FND_MESSAGE.Set_Name('OZF','OZF_API_DEBUG_MESSAGE');
1416              FND_MESSAGE.Set_Token('TEXT','create task assignment');
1417              FND_MSG_PUB.Add;
1418           END IF;
1419 
1420           JTF_TASK_ASSIGNMENTS_PUB.create_task_assignment (
1421               p_api_version             => l_api_version,
1422               p_task_id                 => l_task_details_tbl(i).task_id,
1423               P_RESOURCE_TYPE_CODE      => G_RS_EMPLOYEE_TYPE,
1424               P_RESOURCE_ID             => p_owner_id ,
1425               p_assignment_status_id    => l_assignment_status_id,
1426               x_return_status           => l_return_status,
1427               x_msg_count               => l_msg_count ,
1428               x_msg_data                => l_msg_data,
1429               X_TASK_ASSIGNMENT_ID      => l_task_assignment_id
1430 	  );
1431           IF l_return_status = FND_API.g_ret_sts_error THEN
1432              RAISE FND_API.g_exc_error;
1433           ELSIF l_return_status = FND_API.g_ret_sts_unexp_error THEN
1434              RAISE FND_API.g_exc_unexpected_error;
1435           END IF;
1436 
1437       END LOOP;
1438    ELSIF l_return_status = FND_API.g_ret_sts_error THEN
1439       RAISE FND_API.g_exc_error;
1440    ELSIF l_return_status = FND_API.g_ret_sts_unexp_error THEN
1441       RAISE FND_API.g_exc_unexpected_error;
1442    END IF;
1443 EXCEPTION
1444    WHEN FND_API.G_EXC_ERROR THEN
1445       x_return_status := FND_API.G_RET_STS_ERROR;
1446    WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1447       x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1448    WHEN OTHERS THEN
1449       x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1450       IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_unexp_error) THEN
1451          FND_MESSAGE.set_name('OZF', 'OZF_CLAIM_TASK_API_ERR');
1452          FND_MSG_PUB.add;
1453       END IF;
1454 END generate_tasks;
1455 
1456 
1457 
1458 ---------------------------------------------------------------------
1459 -- PROCEDURE
1460 --    get_write_off_threshold
1461 --
1462 -- PURPOSE
1463 --    This procedure gets (-VE and +VE)threshold value from customer profile
1464 --    and system parameters.
1465 --
1466 --
1467 -- PARAMETERS
1468 --    p_cust_account_id : claim cust_account_id
1469 --    x_ded_pos_write_off_threshold : Positive threshold value
1470 --    x_opy_neg_write_off_threshold : Negetive threshold value
1471 --
1472 -- NOTES :
1473 --
1474 -- BUG         : 2710047
1475 -- CHANAGED BY : (uday poluri) 28-May-2003
1476 -- COMMENTS    : New procedure in OZF_CLAIM_PVT package called from
1477 --               OZF_CLAIM_PVT.get_write_off_eligibility and
1478 --               OZF_SETTLEMENT_DOC_PVT.Process_Tax_Impact.
1479 ----------------------------------------------------------------------
1480 PROCEDURE get_write_off_threshold ( p_cust_account_id              IN NUMBER,
1481                                     x_ded_pos_write_off_threshold  OUT NOCOPY NUMBER,
1482                                     x_opy_neg_write_off_threshold  OUT NOCOPY NUMBER,
1483                                     x_return_status                OUT NOCOPY VARCHAR2
1484                                    )
1485 IS
1486 
1487    --Variable declarations.
1488    l_cust_account_id                NUMBER := p_cust_account_id;
1489 
1490    l_ded_pos_write_off_threshold    NUMBER;
1491    l_opy_neg_write_off_threshold    NUMBER;
1492    l_party_id                        NUMBER;
1493    l_get_thr_frm_sysparam           BOOLEAN := false;
1494 
1495    --Cursor to get the party_id of the customer.
1496    CURSOR   get_party_id_csr( p_cust_account_id IN NUMBER )IS
1497    SELECT   party_id
1498    FROM     HZ_CUST_ACCOUNTS
1499    WHERE    cust_account_id = p_cust_account_id;
1500 
1501 
1502    --Cursor to get the Threshold amounts from the customers
1503    --trade profile based on the account id
1504    CURSOR   get_cst_trd_prfl_wo_thr_csr(p_cust_account_id IN NUMBER) IS
1505    SELECT   pos_write_off_threshold
1506           , neg_write_off_threshold
1507    FROM     OZF_CUST_TRD_PRFLS
1508    WHERE    cust_account_id = p_cust_account_id;
1509 
1510    --Cursor to get the Threshold amounts from the customers
1511    --Tradeprofile based on the party_id
1512    CURSOR get_prt_trd_prfl_wo_thr_csr(p_party_id IN NUMBER) IS
1513    SELECT pos_write_off_threshold
1514         , neg_write_off_threshold
1515    FROM   OZF_CUST_TRD_PRFLS
1516    WHERE  party_id = p_party_id
1517    AND    (pos_write_off_threshold is not null
1518    AND    neg_write_off_threshold is not null)
1519    AND    rownum = 1;
1520 
1521 
1522    -- fix for bug 5042046
1523    --Cursor to get the Threshold amounts from the system parameters.
1524    CURSOR   get_sys_parm_wo_thr_csr IS
1525    SELECT   pos_write_off_threshold
1526           , neg_write_off_threshold
1527    FROM     OZF_SYS_PARAMETERS
1528    WHERE    org_id = MO_GLOBAL.GET_CURRENT_ORG_ID();
1529 
1530 BEGIN
1531 
1532    x_return_status := FND_API.G_RET_STS_SUCCESS;
1533 
1534    IF (l_cust_account_id IS NOT NULL)
1535    OR (l_cust_account_id <> FND_API.G_MISS_NUM)
1536    THEN
1537       --Get the thresholds from customer trade profile based on account id
1538       OPEN get_cst_trd_prfl_wo_thr_csr(l_cust_account_id);
1539       FETCH get_cst_trd_prfl_wo_thr_csr
1540       INTO l_ded_pos_write_off_threshold, l_opy_neg_write_off_threshold;
1541       CLOSE get_cst_trd_prfl_wo_thr_csr;
1542 
1543       --START 1
1544       IF (l_ded_pos_write_off_threshold IS NULL OR l_ded_pos_write_off_threshold = FND_API.G_MISS_NUM)
1545          AND(l_opy_neg_write_off_threshold IS NULL OR l_opy_neg_write_off_threshold = FND_API.G_MISS_NUM)
1546       THEN
1547 
1548          --Get the customers party_id
1549          OPEN get_party_id_csr(l_cust_account_id);
1550          FETCH get_party_id_csr INTO l_party_id;
1551          CLOSE get_party_id_csr;
1552 
1553          IF (l_party_id IS NOT NULL AND l_party_id <> FND_API.G_MISS_NUM)
1554          THEN
1555             --Get the thresholds from customer trade profile based on party id
1556             OPEN get_prt_trd_prfl_wo_thr_csr(l_party_id);
1557             FETCH get_prt_trd_prfl_wo_thr_csr
1558             INTO l_ded_pos_write_off_threshold, l_opy_neg_write_off_threshold;
1559             CLOSE get_prt_trd_prfl_wo_thr_csr;
1560 
1561             IF (l_ded_pos_write_off_threshold IS NULL OR l_ded_pos_write_off_threshold = FND_API.G_MISS_NUM)
1562             AND(l_opy_neg_write_off_threshold IS NULL OR l_opy_neg_write_off_threshold = FND_API.G_MISS_NUM)
1563             THEN
1564                --if the thresholds are null then get from the system paramters.
1565                l_get_thr_frm_sysparam := true;
1566             END IF;
1567          ELSE
1568             --If trade profile is not configured for the party
1569             --Get the thresholds from Sysparameters
1570               l_get_thr_frm_sysparam := true;
1571          END IF; --End of Party_id is not null if block
1572       END IF; --END OF START 1
1573    ELSE
1574       --If the cust_account_id is null then also
1575       --get the thresholds from system paramters
1576       l_get_thr_frm_sysparam := true;
1577    END IF;
1578    --End of l_cust_account_id is not NULL If block.
1579 
1580    IF (l_get_thr_frm_sysparam = true) THEN
1581       OPEN get_sys_parm_wo_thr_csr;
1582       FETCH get_sys_parm_wo_thr_csr INTO l_ded_pos_write_off_threshold, l_opy_neg_write_off_threshold;
1583       CLOSE get_sys_parm_wo_thr_csr;
1584    END IF;
1585 
1586    --If the thresholds are null then assign zero
1587    l_ded_pos_write_off_threshold := NVL(l_ded_pos_write_off_threshold,0);
1588    l_opy_neg_write_off_threshold := NVL(l_opy_neg_write_off_threshold,0);
1589 
1590    x_ded_pos_write_off_threshold := l_ded_pos_write_off_threshold;
1591    x_opy_neg_write_off_threshold := l_opy_neg_write_off_threshold;
1592 
1593 EXCEPTION
1594    WHEN FND_API.G_EXC_ERROR THEN
1595       x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1596    WHEN OTHERS THEN
1597       x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1598    IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
1599       FND_MESSAGE.set_name('OZF', 'OZF_CLAIM_WO_THRESHOLD_ERROR');
1600       FND_MSG_PUB.ADD;
1601    END IF;
1602 END get_write_off_threshold;
1603 
1604 ---------------------------------------------------------------------
1605 -- PROCEDURE
1606 --    get_write_off_eligibility
1607 --
1608 -- PURPOSE
1609 --    This procedure checks the eligibility of a deduction/overpayment
1610 --    for the write off and sets the write off flag.
1611 -- PARAMETERS
1612 --    p_claim : Claim record
1613 --    x_claim : Claim record
1614 --    x_return_status
1615 --
1616 -- NOTES : This procedure will be called only if Status_Code is OPEN.
1617 --
1618 -- BUG         : 2710047
1619 -- CHANAGED BY : (uday poluri)
1620 -- COMMENTS    : New procedure in OZF_CLAIM_PVT package called from
1621 --               OZF_CLAIM_PVT.Check_Claim_Common_Elements.
1622 
1623 ---------------------------------------------------------------------
1624 PROCEDURE get_write_off_eligibility ( p_cust_account_id   IN  NUMBER
1625                                     , px_currency_code     IN OUT NOCOPY  VARCHAR2
1626                                     , px_exchange_rate_type IN OUT NOCOPY VARCHAR2
1627                                     , px_exchange_rate_date IN OUT NOCOPY DATE
1628                                     , p_exchange_rate      IN NUMBER
1629                                     , p_set_of_books_id    IN NUMBER
1630                                     , p_amount             IN NUMBER
1631                                     , px_acctd_amount      IN OUT NOCOPY NUMBER
1632                                     , px_acctd_amount_remaining IN OUT NOCOPY NUMBER
1633                                     , x_write_off_flag     OUT NOCOPY VARCHAR2
1634                                     , x_write_off_threshold_amount OUT NOCOPY NUMBER
1635                                     , x_under_write_off_threshold  OUT NOCOPY VARCHAR2
1636                                     , x_return_status  OUT NOCOPY VARCHAR2)
1637 IS
1638 
1639 --Variable declations
1640 l_cust_account_id       NUMBER := p_cust_account_id;
1641 l_currency_code         VARCHAR2(15) := px_currency_code;
1642 l_exchange_rate_type    VARCHAR2(30) := px_exchange_rate_type;
1643 l_exchange_rate_date    DATE := px_exchange_rate_date;
1644 l_exchange_rate         NUMBER := p_exchange_rate;
1645 l_set_of_books_id       NUMBER := p_set_of_books_id;
1646 l_amount                NUMBER := p_amount;
1647 
1648 l_acctd_amount          NUMBER := px_acctd_amount;
1649 l_acctd_amount_remaining NUMBER := px_acctd_amount_remaining;
1650 
1651 l_acc_amount            NUMBER;
1652 l_rate                  NUMBER;
1653 
1654 l_ded_pos_threshold_amount    NUMBER;
1655 l_opy_neg_threshold_amount    NUMBER;
1656 l_functional_currency_code    VARCHAR2(15);
1657 l_write_off_flag              VARCHAR2(1);
1658 l_write_off_threshold_amount  NUMBER;
1659 l_under_write_off_threshold   VARCHAR2(5);
1660 
1661 l_return_status   VARCHAR2(30);
1662 
1663 -- fix for bug 5042046
1664 --Cursor to get the exchange rate type.
1665 CURSOR get_exchange_rate_type_csr IS
1666 SELECT exchange_rate_type
1667 FROM  OZF_SYS_PARAMETERS
1668 WHERE org_id = MO_GLOBAL.GET_CURRENT_ORG_ID();
1669 
1670 BEGIN
1671 
1672    x_return_status := FND_API.G_RET_STS_SUCCESS;
1673 
1674    --Get the write-off thresholds
1675    get_write_off_threshold( p_cust_account_id   => l_cust_account_id
1676                           , x_ded_pos_write_off_threshold => l_ded_pos_threshold_amount
1677                           , x_opy_neg_write_off_threshold => l_opy_neg_threshold_amount
1678                           , x_return_status           => l_return_status
1679                           );
1680 
1681    IF (l_return_status = FND_API.G_RET_STS_ERROR) THEN
1682       RAISE FND_API.g_exc_error;
1683    ELSIF (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
1684       RAISE FND_API.g_exc_unexpected_error;
1685    END IF;
1686 
1687    --Get the functional currency code
1688    OPEN   gp_func_currency_cd_csr;
1689    FETCH  gp_func_currency_cd_csr INTO l_functional_currency_code;
1690    CLOSE  gp_func_currency_cd_csr;
1691 
1692    --Default the transaction currency code to functional currency
1693    -- if the transaction currency code is null
1694    IF (l_currency_code IS NULL
1695       OR l_currency_code = FND_API.G_MISS_CHAR) THEN
1696       l_currency_code := l_functional_currency_code;
1697    END IF;
1698 
1699    --If the transaction currency code is different from the functional currency code
1700    -- ensure that the exchange type is not null.
1701    IF (l_currency_code <> l_functional_currency_code) THEN
1702       IF (l_exchange_rate_type IS NULL
1703          OR l_exchange_rate_type = FND_API.G_MISS_CHAR) THEN
1704          --Get the default exchange rate type
1705          OPEN get_exchange_rate_type_csr;
1706          FETCH get_exchange_rate_type_csr INTO l_exchange_rate_type;
1707          CLOSE get_exchange_rate_type_csr;
1708 
1709 
1710          --If the exchange rate type is null then raise an error
1711          IF (l_exchange_rate_type IS NULL
1712             OR l_exchange_rate_type = FND_API.G_MISS_CHAR) THEN
1713             IF FND_MSG_PUB.check_msg_level(fnd_msg_pub.g_msg_lvl_error) THEN
1714                FND_MESSAGE.set_name('OZF', 'OZF_CLAIM_CONTYPE_MISSING');
1715                FND_MSG_PUB.add;
1716             END IF;
1717             RAISE FND_API.G_EXC_ERROR;
1718          END IF;
1719       END IF;
1720 
1721       --Check the exchange rate date.
1722       IF (l_exchange_rate_date IS NULL
1723 	 OR l_exchange_rate_date = FND_API.G_MISS_DATE) THEN
1724 	 l_exchange_rate_date := SYSDATE;
1725       END IF;
1726 
1727       IF OZF_DEBUG_HIGH_ON THEN
1728          ozf_utility_PVT.debug_message('rate_type:'||l_exchange_rate_type);
1729       END IF;
1730 
1731       IF (l_amount <> 0) THEN
1732          OZF_UTILITY_PVT.Convert_Currency(
1733               P_SET_OF_BOOKS_ID => l_set_of_books_id,
1734               P_FROM_CURRENCY   => l_currency_code,
1735               P_CONVERSION_DATE => l_exchange_rate_date,
1736               P_CONVERSION_TYPE => l_exchange_rate_type,
1737               P_CONVERSION_RATE => l_exchange_rate,
1738               P_AMOUNT          => l_amount,
1739               X_RETURN_STATUS   => l_return_status,
1740               X_ACC_AMOUNT      => l_acc_amount,
1741               X_RATE            => l_rate);
1742          IF (l_return_status = FND_API.g_ret_sts_error) THEN
1743             RAISE FND_API.g_exc_error;
1744          ELSIF (l_return_status = FND_API.g_ret_sts_unexp_error) THEN
1745             RAISE FND_API.g_exc_unexpected_error;
1746          END IF;
1747 
1748          l_exchange_rate := l_rate;
1749          l_acctd_amount  := l_acc_amount;
1750          l_acctd_amount_remaining := l_acc_amount;
1751       ELSE
1752          l_acctd_amount := l_amount;
1753       END IF;
1754       --Round off the amount and acctd_amount according to the currency.
1755       --As threshold amounts are stored in functional currency, we need to round off by functional currency code.
1756       l_acctd_amount := OZF_UTILITY_PVT.CurrRound(l_acctd_amount, l_functional_currency_code);
1757    ELSE --else of IF (l_claim.currency_code <> l_functional_currency_code)
1758       l_acctd_amount := l_amount;
1759       l_exchange_rate_type := null;
1760       l_exchange_rate_date := null;
1761       l_exchange_rate := 1;
1762    END IF; -- end of IF (l_claim.currency_code <> l_functional_currency_code)
1763 
1764 
1765    IF (l_acctd_amount < 0) THEN
1766       --Perform -ve threshold comparison.
1767       l_opy_neg_threshold_amount := NVL(l_opy_neg_threshold_amount, 0);
1768       IF( abs(l_acctd_amount) < l_opy_neg_threshold_amount )
1769       THEN
1770          l_write_off_flag := 'T';
1771          l_write_off_threshold_amount := l_opy_neg_threshold_amount * -1;
1772          l_under_write_off_threshold := 'UNDER';
1773       ELSE
1774          l_write_off_flag := 'F';
1775          l_write_off_threshold_amount := l_opy_neg_threshold_amount * -1;
1776          l_under_write_off_threshold := 'OVER';
1777       END IF;
1778    END IF;
1779 
1780    --Check for the +ve (Deduction) amount.
1781    IF (l_acctd_amount > 0) THEN
1782       l_ded_pos_threshold_amount := NVL(l_ded_pos_threshold_amount, 0);
1783       IF (l_acctd_amount < l_ded_pos_threshold_amount)
1784       THEN
1785          l_write_off_flag := 'T';
1786          l_write_off_threshold_amount := l_ded_pos_threshold_amount;
1787          l_under_write_off_threshold := 'UNDER';
1788       ELSE
1789          l_write_off_flag := 'F';
1790          l_write_off_threshold_amount := l_ded_pos_threshold_amount;
1791          l_under_write_off_threshold := 'OVER';
1792       END IF;
1793    END IF;
1794 
1795    x_write_off_flag := l_write_off_flag;
1796    x_write_off_threshold_amount := l_write_off_threshold_amount;
1797    x_under_write_off_threshold := l_under_write_off_threshold;
1798    px_currency_code := l_currency_code;
1799    px_exchange_rate_type := l_exchange_rate_type;
1800    px_exchange_rate_date := l_exchange_rate_date;
1801    px_acctd_amount := l_acctd_amount;
1802    px_acctd_amount_remaining := l_acctd_amount_remaining;
1803 
1804 
1805 EXCEPTION
1806    WHEN FND_API.G_EXC_ERROR THEN
1807        x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1808    WHEN OTHERS THEN
1809        x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1810    IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
1811       FND_MESSAGE.set_name('OZF', 'OZF_CLAIM_WRITE_OFF_SETUP_ERR');
1812       FND_MSG_PUB.add;
1813    END IF;
1814 
1815 END get_write_off_eligibility;
1816 
1817 
1818 ---------------------------------------------------------------------
1819 -- PROCEDURE
1820 --    Get_Customer_Reason
1821 --
1822 -- PURPOSE
1823 --    This procedure will call get_claim_reason procedure from
1824 --    OZF_Cust_Reason_Mapping_Pvt.
1825 --
1826 -- PARAMETERS
1827 --    p_claim        : claim record
1828 --    x_claim        : defaulted record
1829 --
1830 -- NOTES :
1831 --
1832 -- BUG         : 2732290
1833 -- CHANAGED BY : (Uday Poluri)
1834 -- COMMENTS    : New procedure in OZF_CLAIM_PVT package called from
1835 --               Create_Claim, Update_Claim, Create_Claim_Tbl
1836 ----------------------------------------------------------------------
1837 PROCEDURE Get_Customer_Reason( p_cust_account_id     IN NUMBER
1838                           , px_reason_code_id     IN OUT NOCOPY  NUMBER
1839                           , p_customer_reason     IN VARCHAR2
1840                          , x_return_status       OUT NOCOPY  VARCHAR2)
1841 IS
1842 
1843 
1844 --Variable declaration.
1845 l_cust_account_id    NUMBER := p_cust_account_id;
1846 l_party_id           NUMBER;
1847 l_reason_code_id     NUMBER := px_reason_code_id;
1848 l_customer_reason    VARCHAR2(30) := p_customer_reason;
1849 l_code_conversion_type VARCHAR2(20) :=  'OZF_REASON_CODES';
1850 
1851 
1852 l_claim_reason_code_id  NUMBER;
1853 l_internal_code         VARCHAR2(150);
1854 
1855 l_msg_data           VARCHAR2(2000);
1856 l_return_status      VARCHAR2(30);
1857 l_msg_count          NUMBER;
1858 
1859 CURSOR c_party_id(p_cust_id in number) IS
1860 SELECT h.party_id
1861 FROM HZ_CUST_ACCOUNTS H
1862 WHERE h.cust_account_id = p_cust_id;
1863 
1864 BEGIN
1865 
1866    x_return_status := FND_API.g_ret_sts_success;
1867 
1868    OPEN c_party_id(l_cust_account_id);
1869    FETCH c_party_id INTO l_party_id;
1870    CLOSE c_party_id;
1871 
1872   IF (l_customer_reason is not NULL or l_customer_reason <> FND_API.G_MISS_CHAR) AND
1873      (l_reason_code_id is NULL or l_reason_code_id = FND_API.G_MISS_NUM) THEN
1874        -- ----------------------------------------------------------------------------
1875        -- Call OZF_CODE_CONVERSION_PVT.convert_code.
1876        -- ----------------------------------------------------------------------------
1877        OZF_CODE_CONVERSION_PVT.convert_code(
1878                                p_cust_account_id      => l_cust_account_id,
1879                                p_party_id             => l_party_id,
1880                                p_code_conversion_type => l_code_conversion_type,
1881                                p_external_code        => l_customer_reason,
1882                                x_internal_code        => l_internal_code,
1883                                X_Return_Status        => l_return_status,
1884                                X_Msg_Count            => l_msg_count,
1885                                X_Msg_Data             => l_msg_data );
1886 
1887        IF l_return_status = FND_API.g_ret_sts_error THEN
1888          RAISE FND_API.g_exc_error;
1889        ELSIF l_return_status = FND_API.g_ret_sts_unexp_error THEN
1890          RAISE FND_API.g_exc_unexpected_error;
1891        END IF;
1892 
1893        IF l_internal_code is not null THEN
1894          l_claim_reason_code_id := to_number(l_internal_code);
1895        END IF;
1896 
1897        IF l_claim_reason_code_id is NOT NULL THEN
1898          l_reason_code_id := l_claim_reason_code_id;
1899        ELSE
1900          -- Mapping for the custome reason is not available. Throw an exception
1901           IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error)
1902           THEN
1903              FND_MESSAGE.set_name('OZF', 'OZF_CLAIM_NO_REASON_MAPPING');
1904              FND_MSG_PUB.add;
1905           END IF;
1906           RAISE FND_API.G_EXC_ERROR;
1907        END IF;
1908   END IF;
1909 
1910    px_reason_code_id := l_reason_code_id;
1911 EXCEPTION
1912    WHEN FND_API.G_EXC_ERROR THEN
1913      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1914    WHEN OTHERS THEN
1915      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1916 END Get_Customer_Reason;
1917 
1918 
1919 
1920 
1921 ---------------------------------------------------------------------
1922 -- PROCEDURE
1923 --    check_amount
1924 --
1925 -- PURPOSE
1926 --    This procedure checks whether there is a need to change the
1927 --    amount field in the ozf_claims_all table.
1928 --
1929 -- PARAMETERS
1930 --    p_claim              in claim_rec_type,
1931 --    p_mode               in varchar2
1932 --    x_amount_changed     OUT NOCOPY boolean,
1933 --    x_exchange_changed   OUT NOCOPY boolean,
1934 --    x_return_status      OUT NOCOPY varchar2
1935 --
1936 -- NOTES
1937 --   Modified by: Uday Poluri    Date: 03-JUN-2003
1938 --   Comments: Added new parameter p_mode.
1939 ---------------------------------------------------------------------
1940 PROCEDURE check_amount(p_claim              in claim_rec_type,
1941                        p_mode               in varchar2,
1942                        x_amount_changed     OUT NOCOPY boolean,
1943                        x_exchange_changed   OUT NOCOPY boolean,
1944                        x_pass               OUT NOCOPY boolean,
1945                        x_return_status      OUT NOCOPY varchar2
1946                        )
1947 IS
1948 CURSOR amount_csr(p_id in number) IS
1949 SELECT currency_code,
1950        exchange_rate_date,
1951        exchange_rate_type,
1952        exchange_rate,
1953        amount,
1954        amount_adjusted,
1955        amount_settled,
1956        cust_account_id
1957 FROM   ozf_claims_all
1958 WHERE  claim_id = p_id;
1959 
1960 l_info amount_csr%rowtype;
1961 
1962 BEGIN
1963 
1964    -- Initialize API return status to sucess
1965    x_return_status := FND_API.G_RET_STS_SUCCESS;
1966    x_pass := true;
1967 
1968    OPEN amount_csr(p_claim.claim_id);
1969    FETCH amount_csr into l_info;
1970    CLOSE amount_csr;
1971 
1972    IF p_mode = 'MANU' AND
1973       (p_claim.claim_class = G_DEDUCTION_CLASS OR
1974        p_claim.claim_class = G_OVERPAYMENT_CLASS) THEN
1975        x_pass :=p_claim.currency_code      = l_info.currency_code AND
1976               ((p_claim.exchange_rate_date is null AND
1977                 l_info.exchange_rate_date is null) OR
1978                (p_claim.exchange_rate_date is not null AND
1979                 l_info.exchange_rate_date is not null AND
1980                 p_claim.exchange_rate_date = l_info.exchange_rate_date)) AND
1981               ((p_claim.exchange_rate_type is null AND
1982                 l_info.exchange_rate_type is null) OR
1983                (p_claim.exchange_rate_type is not null AND
1984                 l_info.exchange_rate_type is not null AND
1985                 p_claim.exchange_rate_type = l_info.exchange_rate_type)) AND
1986               p_claim.exchange_rate      = l_info.exchange_rate AND
1987               p_claim.amount             = l_info.amount;
1988 
1989       IF x_pass = true THEN
1990          x_pass := p_claim.cust_account_id = l_info.cust_account_id;
1991          IF x_pass = false THEN
1992             IF FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
1993                FND_MESSAGE.Set_Name('OZF', 'OZF_CLAIM_DED_CUST_CHANGED');
1994                FND_MSG_PUB.ADD;
1995             END IF;
1996         END IF;
1997       ELSE
1998         IF FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
1999            FND_MESSAGE.Set_Name('OZF', 'OZF_CLAIM_DED_AMT_CHANGED');
2000            FND_MSG_PUB.ADD;
2001         END IF;
2002       END IF;
2003    END IF;
2004 
2005 
2006    IF x_pass = true AND
2007       p_claim.root_claim_id <> p_claim.claim_id AND
2008       -- mchang 04/21/2004: add p_mode checking for subsequent receipt amount update in case of split
2009       p_mode = 'MANU' THEN
2010       x_pass := p_claim.amount        = l_info.amount;
2011       IF x_pass = false THEN
2012          IF FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
2013             FND_MESSAGE.Set_Name('OZF', 'OZF_CLAIM_CHLD_AMT_CHANGED');
2014             FND_MSG_PUB.ADD;
2015          END IF;
2016       END IF;
2017    END IF;
2018 
2019    x_amount_changed := (
2020        (p_claim.currency_code      <> l_info.currency_code) OR
2021        (p_claim.exchange_rate_date is null and
2022         l_info.exchange_rate_date is not null) OR
2023        (p_claim.exchange_rate_date is not null and
2024         l_info.exchange_rate_date is null) OR
2025        (p_claim.exchange_rate_date is not null and
2026         l_info.exchange_rate_date is not null and
2027         p_claim.exchange_rate_date <> l_info.exchange_rate_date) OR
2028        (p_claim.exchange_rate_type is null and
2029         l_info.exchange_rate_type is not null) OR
2030        (p_claim.exchange_rate_type is not null and
2031         l_info.exchange_rate_type is null) OR
2032        (p_claim.exchange_rate_type is not null and
2033         l_info.exchange_rate_type is not null and
2034         p_claim.exchange_rate_type <> l_info.exchange_rate_type) OR
2035        (p_claim.exchange_rate      <> l_info.exchange_rate) OR
2036        (p_claim.amount             <> l_info.amount) OR
2037        (p_claim.amount_adjusted    <> l_info.amount_adjusted) OR
2038        (p_claim.amount_settled     <> l_info.amount_settled));
2039 
2040     x_exchange_changed := (
2041        (p_claim.currency_code      <> l_info.currency_code) OR
2042        (p_claim.exchange_rate_date is null and
2043         l_info.exchange_rate_date is not null) OR
2044        (p_claim.exchange_rate_date is not null and
2045         l_info.exchange_rate_date is null) OR
2046        (p_claim.exchange_rate_date is not null and
2047         l_info.exchange_rate_date is not null and
2048         p_claim.exchange_rate_date <> l_info.exchange_rate_date) OR
2049        (p_claim.exchange_rate_type is null and
2050         l_info.exchange_rate_type is not null) OR
2051        (p_claim.exchange_rate_type is not null and
2052         l_info.exchange_rate_type is null) OR
2053        (p_claim.exchange_rate_type is not null and
2054         l_info.exchange_rate_type is not null and
2055         p_claim.exchange_rate_type <> l_info.exchange_rate_type) OR
2056        (p_claim.exchange_rate      <> l_info.exchange_rate));
2057 
2058 EXCEPTION
2059    WHEN OTHERS THEN
2060       x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2061       IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_unexp_error) THEN
2062          FND_MESSAGE.set_name('OZF', 'OZF_CLAIM_AMOUNT_CHANGE_ERR');
2063          FND_MSG_PUB.add;
2064       END IF;
2065 END check_amount;
2066 ---------------------------------------------------------------------
2067 -- PROCEDURE
2068 --    check_claim_number
2069 --
2070 -- PURPOSE
2071 --    This procedure check whether there is a duplication for a cliam
2072 --    number in the database.
2073 --
2074 -- PARAMETERS
2075 --    p_claim_id       : claim id
2076 --    p_claim_number
2077 --    x_return_status
2078 --
2079 -- NOTES
2080 ---------------------------------------------------------------------
2081 PROCEDURE check_claim_number(p_claim_id      IN  NUMBER,
2082                              p_claim_number  IN  VARCHAR2,
2083                              x_return_status OUT NOCOPY VARCHAR2)
2084 IS
2085 l_claim_id    NUMBER;
2086 
2087 CURSOR get_claim_id_csr(p_id in number) IS
2088 SELECT count(claim_id)
2089 FROM   ozf_claims_all
2090 WHERE  claim_id = p_id;
2091 
2092 CURSOR get_claim_id_num_csr(p_num in varchar2) IS
2093 SELECT count(claim_id)
2094 FROM   ozf_claims_all
2095 WHERE  claim_number = p_num;
2096 
2097 CURSOR get_count_csr(p_number in varchar2,
2098                      p_claim_id in number) IS
2099 SELECT count(claim_id)
2100 FROM   ozf_claims_all
2101 WHERE  claim_number = p_number
2102 AND    claim_id     = p_claim_id;
2103 
2104 l_count  number:=0;
2105 BEGIN
2106    -- Initialize API return status to sucess
2107    x_return_status := FND_API.G_RET_STS_SUCCESS;
2108 
2109    IF ((p_claim_number is null) OR
2110        (p_claim_number = FND_API.G_MISS_CHAR)) THEN
2111       IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
2112          FND_MESSAGE.set_name('OZF', 'OZF_CLAIM_MISSING_CLAIM_NUM');
2113          FND_MSG_PUB.add;
2114       END IF;
2115       x_return_status := FND_API.g_ret_sts_error;
2116    ELSE
2117       -- claim_id will never be not null at this point.
2118       -- so we first check whether this is a new claim or not.
2119       l_count := 0;
2120       OPEN get_claim_id_csr(p_claim_id);
2121       FETCH get_claim_id_csr INTO l_count;
2122       CLOSE get_claim_id_csr;
2123 
2124       IF (l_count = 0) THEN
2125          -- check claim_number for new claim. Here claim_number should not exist
2126 
2127          l_count := 0;
2128          OPEN get_claim_id_num_csr(p_claim_number);
2129          FETCH get_claim_id_num_csr INTO l_count;
2130          CLOSE get_claim_id_num_csr;
2131 
2132          IF l_count <> 0 THEN
2133             IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
2134                FND_MESSAGE.set_name('OZF', 'OZF_CLAIM_DUP_CLAIM_NUM_NEW');
2135                FND_MSG_PUB.add;
2136             END IF;
2137             x_return_status := FND_API.g_ret_sts_error;
2138          END IF;
2139       ELSE
2140          -- check claim_number for an old claim. Here claim_number and claim_id should match
2141          -- and claim_number should be unique.
2142 
2143          OPEN get_count_csr(p_claim_number, p_claim_id);
2144          FETCH get_count_csr INTO l_count;
2145          CLOSE get_count_csr;
2146 
2147          IF l_count <> 1 THEN
2148             IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
2149          	   FND_MESSAGE.set_name('OZF', 'OZF_CLAIM_ID_NUM_MISS');
2150          	   FND_MSG_PUB.add;
2151             END IF;
2152             x_return_status := FND_API.g_ret_sts_error;
2153          ELSE
2154             l_count := 0;
2155             OPEN get_claim_id_num_csr(p_claim_number);
2156 			   FETCH get_claim_id_num_csr INTO l_count;
2157 			   CLOSE get_claim_id_num_csr;
2158 
2159 			   IF l_count <> 1 THEN
2160 				   IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
2161 					   FND_MESSAGE.set_name('OZF', 'OZF_CLAIM_DUP_CLAIM_NUM');
2162 					   FND_MSG_PUB.add;
2163 				   END IF;
2164 				   x_return_status := FND_API.g_ret_sts_error;
2165 			   END IF;
2166 			END IF;
2167       END IF;
2168    END IF;
2169 
2170 EXCEPTION
2171    WHEN OTHERS THEN
2172       IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_unexp_error) THEN
2173          FND_MESSAGE.set_name('OZF', 'OZF_CLAIM_NUM_CHECK_ERROR');
2174          FND_MSG_PUB.add;
2175       END IF;
2176       x_return_status := FND_API.g_ret_sts_unexp_error;
2177 END check_claim_number;
2178 
2179 ---------------------------------------------------------------------
2180 -- PROCEDURE
2181 --    Check_Claim_Items
2182 --
2183 -- PURPOSE
2184 --    Perform the item level checking including unique keys,
2185 --    required columns, foreign keys, , flag items, domain constraints.
2186 --
2187 -- PARAMETERS
2188 --    p_validation_mode
2189 --    p_claim_rec      : the record to be validated
2190 --    x_return_status
2191 --
2192 -- NOTES
2193 ---------------------------------------------------------------------
2194 PROCEDURE Check_Claim_Items( p_validation_mode   IN  VARCHAR2 := JTF_PLSQL_API.g_create,
2195                              p_claim_rec         IN claim_rec_type,
2196                              x_return_status     OUT NOCOPY VARCHAR2
2197 )
2198 IS
2199 l_return_status varchar2(30);
2200 BEGIN
2201    -- Initialize API return status to sucess
2202    x_return_status := FND_API.G_RET_STS_SUCCESS;
2203 
2204    -- check for duplicate claim numbers
2205    check_claim_number(
2206       p_claim_id      => p_claim_rec.claim_id,
2207       p_claim_number  => p_claim_rec.claim_number,
2208       x_return_status => l_return_status
2209    );
2210 
2211    x_return_status := l_return_status;
2212 END Check_Claim_Items;
2213 
2214 ---------------------------------------------------------------------
2215 -- FUNCTION
2216 --    get_action_id
2217 --
2218 -- PURPOSE
2219 --    This returns an action_id based on the reason_code_id
2220 --
2221 -- PARAMETERS
2222 --    p_reason_code_id
2223 --    x_return_status
2224 --
2225 -- NOTES
2226 ---------------------------------------------------------------------
2227 FUNCTION get_action_id(p_reason_code_id in number)
2228 return number
2229 IS
2230 CURSOR default_action_id_csr (p_id in number) is
2231 select t.task_template_group_id
2232 from ozf_reasons r,
2233 jtf_task_temp_groups_vl t
2234 where t.source_object_type_code = 'AMS_CLAM'
2235 and r.active_flag = 'T'
2236 and r.default_flag = 'T'
2237 and t.task_template_group_id = r.task_template_group_id
2238 and nvl(t.start_date_active, sysdate) <= sysdate
2239 and nvl(t.end_date_active, sysdate) >= sysdate
2240 and r.reason_code_id = p_id;
2241 
2242 l_default_action_id number;
2243 BEGIN
2244 
2245    If (p_reason_code_id is not null and
2246        p_reason_code_id <> FND_API.G_MISS_NUM) THEN
2247        OPEN default_action_id_csr(p_reason_code_id);
2248        FETCH default_action_id_csr into l_default_action_id;
2249        CLOSE default_action_id_csr;
2250 
2251    ELSE
2252       l_default_action_id := null;
2253    END IF;
2254 	return l_default_action_id;
2255 END get_action_id;
2256 
2257 ---------------------------------------------------------------------
2258 -- PROCEDURE
2259 --    check_deduction
2260 --
2261 -- PURPOSE
2262 --    This procedure validate some deduction information.
2263 --
2264 -- PARAMETERS
2265 --    p_claim              : claim_rec_type
2266 --    p_mode               : varchar2
2267 --    x_pass               : boolean
2268 --    x_return_status
2269 --
2270 -- NOTES
2271 ---------------------------------------------------------------------
2272 PROCEDURE check_deduction(p_claim              in claim_rec_type,
2273                           p_mode               in  varchar2,
2274                           x_pass               OUT NOCOPY boolean,
2275                           x_return_status      OUT NOCOPY varchar2
2276                           )
2277 IS
2278 CURSOR deduction_info_csr(p_id in number) IS
2279 SELECT currency_code,
2280        exchange_rate_date,
2281        exchange_rate_type,
2282        exchange_rate,
2283        amount,
2284        cust_account_id
2285 FROM   ozf_claims_all
2286 WHERE  claim_id = p_id;
2287 
2288 l_deduction_info deduction_info_csr%rowtype;
2289 
2290 BEGIN
2291 
2292    -- Initialize API return status to sucess
2293    x_return_status := FND_API.G_RET_STS_SUCCESS;
2294    x_pass := true;
2295 
2296    OPEN deduction_info_csr(p_claim.claim_id);
2297    FETCH deduction_info_csr into l_deduction_info;
2298    CLOSE deduction_info_csr;
2299 
2300    -- -------------------------------------------------------------------------------------------
2301    -- Bug        : 2781186
2302    -- Changed by : (Uday Poluri)  Date: 03-JUN-2003
2303    -- Comments   : Add p_mode check, If it is AUTO then allow amount change on claim.
2304    -- -------------------------------------------------------------------------------------------
2305    IF p_mode <> OZF_claim_Utility_pvt.G_AUTO_MODE THEN    --Bug:2781186
2306       IF ((p_claim.currency_code      <> l_deduction_info.currency_code) OR
2307           (p_claim.exchange_rate_date <> l_deduction_info.exchange_rate_date) OR
2308           (p_claim.exchange_rate_type <> l_deduction_info.exchange_rate_type) OR
2309           (p_claim.exchange_rate      <> l_deduction_info.exchange_rate) OR
2310           (p_claim.amount             <> l_deduction_info.amount)) THEN
2311 
2312           x_pass := false;
2313           IF FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
2314              FND_MESSAGE.Set_Name('OZF', 'OZF_CLAIM_DED_AMT_CHANGED');
2315              FND_MSG_PUB.ADD;
2316           END IF;
2317       END IF;
2318    END IF; -- End of BUG#2781186
2319 
2320    IF p_claim.cust_account_id      <> l_deduction_info.cust_account_id THEN
2321        x_pass := false;
2322        IF FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
2323           FND_MESSAGE.Set_Name('OZF', 'OZF_CLAIM_DED_CUST_CHANGED');
2324           FND_MSG_PUB.ADD;
2325        END IF;
2326    END IF;
2327 
2328 EXCEPTION
2329    WHEN OTHERS THEN
2330       x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2331       IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_unexp_error) THEN
2332          FND_MESSAGE.set_name('OZF', 'OZF_CLAIM_DED_CHK_ERR');
2333          FND_MSG_PUB.add;
2334       END IF;
2335 END check_deduction;
2336 
2337 ---------------------------------------------------------------------
2338 -- PROCEDURE
2339 --    Complete_Claim_Rec
2340 --
2341 -- PURPOSE
2342 --    For Update_Claim, some attributes may be passed in as
2343 --    FND_API.g_miss_char/num/date if the user doesn't want to
2344 --    update those attributes. This procedure will replace the
2345 --    "g_miss" attributes with current database values.
2346 --
2347 -- PARAMETERS
2348 --    p_claim_rec  : the record which may contain attributes as
2349 --                    FND_API.g_miss_char/num/date
2350 --    x_complete_rec: the complete record after all "g_miss" items
2351 --                    have been replaced by current database values
2352 ---------------------------------------------------------------------
2353 PROCEDURE Complete_Claim_Rec (
2354    p_claim_rec        IN   claim_rec_type
2355   ,x_complete_rec     OUT NOCOPY  claim_rec_type
2356   ,x_return_status    OUT NOCOPY  varchar2
2357 )
2358 IS
2359 CURSOR c_claim (cv_claim_id NUMBER) IS
2360 SELECT * FROM ozf_claims_all
2361 WHERE CLAIM_ID = cv_claim_id;
2362 
2363 l_claim_rec    c_claim%ROWTYPE;
2364 
2365 BEGIN
2366 
2367    -- Initialize API return status to sucess
2368    x_return_status := FND_API.G_RET_STS_SUCCESS;
2369 
2370    x_complete_rec  := p_claim_rec;
2371 
2372   OPEN c_claim(p_claim_rec.claim_id);
2373   FETCH c_claim INTO l_claim_rec;
2374      IF c_claim%NOTFOUND THEN
2375         CLOSE c_claim;
2376         IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
2377            FND_MESSAGE.set_name('OZF','OZF_API_RECORD_NOT_FOUND');
2378            FND_MSG_PUB.add;
2379         END IF;
2380         RAISE FND_API.g_exc_error;
2381      END IF;
2382   CLOSE c_claim;
2383 
2384   IF p_claim_rec.claim_id         = FND_API.G_MISS_NUM  THEN
2385      x_complete_rec.claim_id       := NULL;
2386   END IF;
2387   IF p_claim_rec.claim_id         IS NULL THEN
2388      x_complete_rec.claim_id       := l_claim_rec.claim_id;
2389   END IF;
2390   IF p_claim_rec.batch_id         = FND_API.G_MISS_NUM  THEN
2391      x_complete_rec.batch_id       := NULL;
2392   END IF;
2393   IF p_claim_rec.batch_id         IS NULL THEN
2394      x_complete_rec.batch_id       := l_claim_rec.batch_id;
2395   END IF;
2396   IF p_claim_rec.claim_number         = FND_API.G_MISS_CHAR  THEN
2397      x_complete_rec.claim_number       := NULL;
2398   END IF;
2399   IF p_claim_rec.claim_number         IS NULL THEN
2400      x_complete_rec.claim_number       := l_claim_rec.claim_number;
2401   END IF;
2402   IF p_claim_rec.claim_type_id         = FND_API.G_MISS_NUM  THEN
2403      x_complete_rec.claim_type_id       := NULL;
2404   END IF;
2405   IF p_claim_rec.claim_type_id         IS NULL THEN
2406      x_complete_rec.claim_type_id       := l_claim_rec.claim_type_id;
2407   END IF;
2408   IF p_claim_rec.claim_class         = FND_API.G_MISS_CHAR  THEN
2409      x_complete_rec.claim_class       := NULL;
2410   END IF;
2411   IF p_claim_rec.claim_class         IS NULL THEN
2412      x_complete_rec.claim_class       := l_claim_rec.claim_class;
2413   END IF;
2414   IF p_claim_rec.claim_date         = FND_API.G_MISS_DATE  THEN
2415      x_complete_rec.claim_date       := NULL;
2416   END IF;
2417   IF p_claim_rec.claim_date         IS NULL THEN
2418      x_complete_rec.claim_date       := l_claim_rec.claim_date;
2419   END IF;
2420   IF p_claim_rec.due_date         = FND_API.G_MISS_DATE  THEN
2421      x_complete_rec.due_date       := NULL;
2422   END IF;
2423   IF p_claim_rec.due_date         IS NULL THEN
2424      x_complete_rec.due_date       := l_claim_rec.due_date;
2425   END IF;
2426   IF p_claim_rec.owner_id  = FND_API.G_MISS_NUM  THEN
2427      x_complete_rec.owner_id := NULL;
2428   END IF;
2429   IF p_claim_rec.owner_id  IS NULL THEN
2430      x_complete_rec.owner_id := l_claim_rec.owner_id;
2431   END IF;
2432   IF p_claim_rec.history_event  = FND_API.G_MISS_CHAR  THEN
2433      x_complete_rec.history_event := NULL;
2434   END IF;
2435   IF p_claim_rec.history_event  IS NULL THEN
2436      x_complete_rec.history_event := l_claim_rec.history_event;
2437   END IF;
2438   IF p_claim_rec.history_event_date  = FND_API.G_MISS_DATE  THEN
2439      x_complete_rec.history_event_date := NULL;
2440   END IF;
2441   IF p_claim_rec.history_event_date  IS NULL THEN
2442      x_complete_rec.history_event_date := l_claim_rec.history_event_date;
2443   END IF;
2444   IF p_claim_rec.history_event_description  = FND_API.G_MISS_CHAR  THEN
2445      x_complete_rec.history_event_description := NULL;
2446   END IF;
2447   IF p_claim_rec.history_event_description  IS NULL THEN
2448      x_complete_rec.history_event_description := l_claim_rec.history_event_description;
2449   END IF;
2450   IF p_claim_rec.split_from_claim_id  = FND_API.G_MISS_NUM  THEN
2451      x_complete_rec.split_from_claim_id       := NULL;
2452   END IF;
2453   IF p_claim_rec.split_from_claim_id  IS NULL THEN
2454      x_complete_rec.split_from_claim_id       := l_claim_rec.split_from_claim_id;
2455   END IF;
2456   IF p_claim_rec.duplicate_claim_id  = FND_API.G_MISS_NUM  THEN
2457      x_complete_rec.duplicate_claim_id       := NULL;
2458   END IF;
2459   IF p_claim_rec.duplicate_claim_id  IS NULL THEN
2460      x_complete_rec.duplicate_claim_id       := l_claim_rec.duplicate_claim_id;
2461   END IF;
2462   IF p_claim_rec.split_date  = FND_API.G_MISS_DATE  THEN
2463      x_complete_rec.split_date := NULL;
2464   END IF;
2465   IF p_claim_rec.split_date  IS NULL THEN
2466      x_complete_rec.split_date := l_claim_rec.split_date;
2467   END IF;
2468 
2469  IF p_claim_rec.root_claim_id  = FND_API.G_MISS_NUM  THEN
2470      x_complete_rec.root_claim_id       := NULL;
2471   END IF;
2472  IF p_claim_rec.root_claim_id  IS NULL THEN
2473      x_complete_rec.root_claim_id       := l_claim_rec.root_claim_id;
2474   END IF;
2475   IF p_claim_rec.amount  = FND_API.G_MISS_NUM  THEN
2476      x_complete_rec.amount       := NULL;
2477   END IF;
2478   IF p_claim_rec.amount  IS NULL THEN
2479      x_complete_rec.amount       := l_claim_rec.amount;
2480   END IF;
2481   IF p_claim_rec.amount_adjusted  = FND_API.G_MISS_NUM  THEN
2482      x_complete_rec.amount_adjusted       := NULL;
2483   END IF;
2484   IF p_claim_rec.amount_adjusted  IS NULL THEN
2485      x_complete_rec.amount_adjusted       := l_claim_rec.amount_adjusted;
2486   END IF;
2487   IF p_claim_rec.amount_remaining  = FND_API.G_MISS_NUM  THEN
2488      x_complete_rec.amount_remaining       := NULL;
2489   END IF;
2490   IF p_claim_rec.amount_remaining  IS NULL THEN
2491      x_complete_rec.amount_remaining       := l_claim_rec.amount_remaining;
2492   END IF;
2493   IF p_claim_rec.amount_settled  = FND_API.G_MISS_NUM  THEN
2494      x_complete_rec.amount_settled       := NULL;
2495   END IF;
2496   IF p_claim_rec.amount_settled  IS NULL THEN
2497      x_complete_rec.amount_settled       := l_claim_rec.amount_settled;
2498   END IF;
2499   IF p_claim_rec.acctd_amount  = FND_API.G_MISS_NUM  THEN
2500      x_complete_rec.acctd_amount       := NULL;
2501   END IF;
2502   IF p_claim_rec.acctd_amount  IS NULL THEN
2503      x_complete_rec.acctd_amount       := l_claim_rec.acctd_amount;
2504   END IF;
2505   IF p_claim_rec.acctd_amount_remaining   = FND_API.G_MISS_NUM  THEN
2506      x_complete_rec.acctd_amount_remaining        := NULL;
2507   END IF;
2508   IF p_claim_rec.acctd_amount_remaining   IS NULL THEN
2509      x_complete_rec.acctd_amount_remaining        := l_claim_rec.acctd_amount_remaining ;
2510   END IF;
2511   IF p_claim_rec.acctd_amount_adjusted  = FND_API.G_MISS_NUM  THEN
2512      x_complete_rec.acctd_amount_adjusted       := NULL;
2513   END IF;
2514   IF p_claim_rec.acctd_amount_adjusted  IS NULL THEN
2515      x_complete_rec.acctd_amount_adjusted       := l_claim_rec.acctd_amount_adjusted;
2516   END IF;
2517   IF p_claim_rec.acctd_amount_settled  = FND_API.G_MISS_NUM  THEN
2518      x_complete_rec.acctd_amount_settled       := NULL;
2519   END IF;
2520   IF p_claim_rec.acctd_amount_settled  IS NULL THEN
2521      x_complete_rec.acctd_amount_settled       := l_claim_rec.acctd_amount_settled;
2522   END IF;
2523   IF p_claim_rec.tax_amount   = FND_API.G_MISS_NUM  THEN
2524      x_complete_rec.tax_amount        := NULL;
2525   END IF;
2526   IF p_claim_rec.tax_amount   IS NULL THEN
2527      x_complete_rec.tax_amount        := l_claim_rec.tax_amount ;
2528   END IF;
2529   IF p_claim_rec.tax_code   = FND_API.G_MISS_CHAR  THEN
2530      x_complete_rec.tax_code        := NULL;
2531   END IF;
2532   IF p_claim_rec.tax_code   IS NULL THEN
2533      x_complete_rec.tax_code        := l_claim_rec.tax_code ;
2534   END IF;
2535   IF p_claim_rec.tax_calculation_flag   = FND_API.G_MISS_CHAR  THEN
2536      x_complete_rec.tax_calculation_flag        := NULL;
2537   END IF;
2538   IF p_claim_rec.tax_calculation_flag   IS NULL THEN
2539      x_complete_rec.tax_calculation_flag        := l_claim_rec.tax_calculation_flag ;
2540   END IF;
2541   IF p_claim_rec.currency_code         = FND_API.G_MISS_CHAR  THEN
2542      x_complete_rec.currency_code       := NULL;
2543   END IF;
2544   IF p_claim_rec.currency_code         IS NULL THEN
2545      x_complete_rec.currency_code       := l_claim_rec.currency_code;
2546   END IF;
2547   IF p_claim_rec.exchange_rate_type         = FND_API.G_MISS_CHAR  THEN
2548      x_complete_rec.exchange_rate_type       := NULL;
2549   END IF;
2550   IF p_claim_rec.exchange_rate_type         IS NULL THEN
2551      x_complete_rec.exchange_rate_type       := l_claim_rec.exchange_rate_type;
2552   END IF;
2553   IF p_claim_rec.exchange_rate_date         = FND_API.G_MISS_DATE  THEN
2554      x_complete_rec.exchange_rate_date       := NULL;
2555   END IF;
2556   IF p_claim_rec.exchange_rate_date         IS NULL THEN
2557      x_complete_rec.exchange_rate_date       := l_claim_rec.exchange_rate_date;
2558   END IF;
2559   IF p_claim_rec.exchange_rate  = FND_API.G_MISS_NUM  THEN
2560      x_complete_rec.exchange_rate       := NULL;
2561   END IF;
2562   IF p_claim_rec.exchange_rate  IS NULL THEN
2563      x_complete_rec.exchange_rate       := l_claim_rec.exchange_rate;
2564   END IF;
2565   IF p_claim_rec.set_of_books_id  = FND_API.G_MISS_NUM  THEN
2566      x_complete_rec.set_of_books_id       := NULL;
2567   END IF;
2568   IF p_claim_rec.set_of_books_id  IS NULL THEN
2569      x_complete_rec.set_of_books_id       := l_claim_rec.set_of_books_id;
2570   END IF;
2571   IF p_claim_rec.original_claim_date         = FND_API.G_MISS_DATE  THEN
2572      x_complete_rec.original_claim_date       := NULL;
2573   END IF;
2574   IF p_claim_rec.original_claim_date         IS NULL THEN
2575      x_complete_rec.original_claim_date       := l_claim_rec.original_claim_date;
2576   END IF;
2577   IF p_claim_rec.source_object_id  = FND_API.G_MISS_NUM  THEN
2578      x_complete_rec.source_object_id       := NULL;
2579   END IF;
2580   IF p_claim_rec.source_object_id  IS NULL THEN
2581      x_complete_rec.source_object_id       := l_claim_rec.source_object_id;
2582   END IF;
2583   IF p_claim_rec.source_object_class  = FND_API.G_MISS_CHAR  THEN
2584      x_complete_rec.source_object_class       := NULL;
2585   END IF;
2586   IF p_claim_rec.source_object_class  IS NULL THEN
2587      x_complete_rec.source_object_class       := l_claim_rec.source_object_class;
2588   END IF;
2589   IF p_claim_rec.source_object_type_id  = FND_API.G_MISS_NUM  THEN
2590      x_complete_rec.source_object_type_id       := NULL;
2591   END IF;
2592   IF p_claim_rec.source_object_type_id  IS NULL THEN
2593      x_complete_rec.source_object_type_id       := l_claim_rec.source_object_type_id;
2594   END IF;
2595   IF p_claim_rec.source_object_number  = FND_API.G_MISS_CHAR  THEN
2596      x_complete_rec.source_object_number       := NULL;
2597   END IF;
2598   IF p_claim_rec.source_object_number  IS NULL THEN
2599      x_complete_rec.source_object_number       := l_claim_rec.source_object_number;
2600   END IF;
2601   IF p_claim_rec.cust_account_id  = FND_API.G_MISS_NUM  THEN
2602      x_complete_rec.cust_account_id       := NULL;
2603   END IF;
2604   IF p_claim_rec.cust_account_id  IS NULL THEN
2605      x_complete_rec.cust_account_id       := l_claim_rec.cust_account_id;
2606   END IF;
2607   IF p_claim_rec.cust_billto_acct_site_id  = FND_API.G_MISS_NUM  THEN
2608      x_complete_rec.cust_billto_acct_site_id       := NULL;
2609   END IF;
2610   IF p_claim_rec.cust_billto_acct_site_id  IS NULL THEN
2611      x_complete_rec.cust_billto_acct_site_id       := l_claim_rec.cust_billto_acct_site_id;
2612   END IF;
2613   IF p_claim_rec.cust_shipto_acct_site_id  = FND_API.G_MISS_NUM  THEN
2614      x_complete_rec.cust_shipto_acct_site_id := NULL;
2615   END IF;
2616   IF p_claim_rec.cust_shipto_acct_site_id  IS NULL THEN
2617      x_complete_rec.cust_shipto_acct_site_id := l_claim_rec.cust_shipto_acct_site_id;
2618   END IF;
2619   IF p_claim_rec.location_id  = FND_API.G_MISS_NUM  THEN
2620      x_complete_rec.location_id       := NULL;
2621   END IF;
2622   IF p_claim_rec.location_id  IS NULL THEN
2623      x_complete_rec.location_id       := l_claim_rec.location_id;
2624   END IF;
2625   IF p_claim_rec.pay_related_account_flag  = FND_API.G_MISS_CHAR  THEN
2626      x_complete_rec.pay_related_account_flag := NULL;
2627   END IF;
2628   IF p_claim_rec.pay_related_account_flag  IS NULL THEN
2629      x_complete_rec.pay_related_account_flag := l_claim_rec.pay_related_account_flag;
2630   END IF;
2631   IF p_claim_rec.related_cust_account_id  = FND_API.G_MISS_NUM  THEN
2632      x_complete_rec.related_cust_account_id := NULL;
2633   END IF;
2634   IF p_claim_rec.related_cust_account_id  IS NULL THEN
2635      x_complete_rec.related_cust_account_id := l_claim_rec.related_cust_account_id;
2636   END IF;
2637   IF p_claim_rec.related_site_use_id  = FND_API.G_MISS_NUM  THEN
2638      x_complete_rec.related_site_use_id := NULL;
2639   END IF;
2640   IF p_claim_rec.related_site_use_id  IS NULL THEN
2641      x_complete_rec.related_site_use_id := l_claim_rec.related_site_use_id;
2642   END IF;
2643   IF p_claim_rec.relationship_type = FND_API.G_MISS_CHAR  THEN
2644      x_complete_rec.relationship_type := NULL;
2645   END IF;
2646   IF p_claim_rec.relationship_type IS NULL THEN
2647      x_complete_rec.relationship_type := l_claim_rec.relationship_type;
2648   END IF;
2649   IF p_claim_rec.vendor_id   = FND_API.G_MISS_NUM  THEN
2650      x_complete_rec.vendor_id := NULL;
2651   END IF;
2652   IF p_claim_rec.vendor_id   IS NULL THEN
2653      x_complete_rec.vendor_id := l_claim_rec.vendor_id;
2654   END IF;
2655   IF p_claim_rec.vendor_site_id = FND_API.G_MISS_NUM  THEN
2656      x_complete_rec.vendor_site_id := NULL;
2657   END IF;
2658   IF p_claim_rec.vendor_site_id IS NULL THEN
2659      x_complete_rec.vendor_site_id := l_claim_rec.vendor_site_id;
2660   END IF;
2661   IF p_claim_rec.reason_type  = FND_API.G_MISS_CHAR  THEN
2662      x_complete_rec.reason_type       := NULL;
2663   END IF;
2664   IF p_claim_rec.reason_type  IS NULL THEN
2665      x_complete_rec.reason_type       := l_claim_rec.reason_type;
2666   END IF;
2667   IF p_claim_rec.reason_code_id  = FND_API.G_MISS_NUM  THEN
2668      x_complete_rec.reason_code_id       := NULL;
2669   END IF;
2670   IF p_claim_rec.reason_code_id  IS NULL THEN
2671      x_complete_rec.reason_code_id       := l_claim_rec.reason_code_id;
2672   END IF;
2673   IF p_claim_rec.task_template_group_id  = FND_API.G_MISS_NUM  THEN
2674      x_complete_rec.task_template_group_id       := NULL;
2675   END IF;
2676   IF p_claim_rec.task_template_group_id  IS NULL THEN
2677      x_complete_rec.task_template_group_id       := l_claim_rec.task_template_group_id;
2678   END IF;
2679   IF p_claim_rec.status_code  = FND_API.G_MISS_CHAR  THEN
2680      x_complete_rec.status_code       := NULL;
2681   END IF;
2682   IF p_claim_rec.status_code  IS NULL THEN
2683      x_complete_rec.status_code       := l_claim_rec.status_code;
2684   END IF;
2685   IF p_claim_rec.user_status_id  = FND_API.G_MISS_NUM  THEN
2686      x_complete_rec.user_status_id       := NULL;
2687   END IF;
2688   IF p_claim_rec.user_status_id  IS NULL THEN
2689      x_complete_rec.user_status_id       := l_claim_rec.user_status_id;
2690   END IF;
2691   IF p_claim_rec.sales_rep_id  = FND_API.G_MISS_NUM  THEN
2692      x_complete_rec.sales_rep_id       := NULL;
2693   END IF;
2694   IF p_claim_rec.close_status_id  = FND_API.G_MISS_NUM  THEN
2695      x_complete_rec.close_status_id       := NULL;
2696   END IF;
2697   IF p_claim_rec.close_status_id  IS NULL THEN
2698      x_complete_rec.close_status_id       := l_claim_rec.close_status_id;
2699   END IF;
2700   IF p_claim_rec.open_status_id  = FND_API.G_MISS_NUM  THEN
2701      x_complete_rec.open_status_id       := NULL;
2702   END IF;
2703   IF p_claim_rec.open_status_id  IS NULL THEN
2704      x_complete_rec.open_status_id       := l_claim_rec.open_status_id;
2705   END IF;
2706   IF p_claim_rec.sales_rep_id  IS NULL THEN
2707      x_complete_rec.sales_rep_id       := l_claim_rec.sales_rep_id;
2708   END IF;
2709   IF p_claim_rec.collector_id  = FND_API.G_MISS_NUM  THEN
2710      x_complete_rec.collector_id       := NULL;
2711   END IF;
2712   IF p_claim_rec.collector_id  IS NULL THEN
2713      x_complete_rec.collector_id       := l_claim_rec.collector_id;
2714   END IF;
2715   IF p_claim_rec.contact_id  = FND_API.G_MISS_NUM  THEN
2716      x_complete_rec.contact_id       := NULL;
2717   END IF;
2718   IF p_claim_rec.contact_id  IS NULL THEN
2719      x_complete_rec.contact_id       := l_claim_rec.contact_id;
2720   END IF;
2721   IF p_claim_rec.broker_id  = FND_API.G_MISS_NUM  THEN
2722      x_complete_rec.broker_id       := NULL;
2723   END IF;
2724   IF p_claim_rec.broker_id  IS NULL THEN
2725      x_complete_rec.broker_id       := l_claim_rec.broker_id;
2726   END IF;
2727   IF p_claim_rec.territory_id  = FND_API.G_MISS_NUM  THEN
2728      x_complete_rec.territory_id       := NULL;
2729   END IF;
2730   IF p_claim_rec.territory_id  IS NULL THEN
2731      x_complete_rec.territory_id       := l_claim_rec.territory_id;
2732   END IF;
2733   IF p_claim_rec.customer_ref_date         = FND_API.G_MISS_DATE  THEN
2734      x_complete_rec.customer_ref_date       := NULL;
2735   END IF;
2736   IF p_claim_rec.customer_ref_date         IS NULL THEN
2737      x_complete_rec.customer_ref_date       := l_claim_rec.customer_ref_date;
2738   END IF;
2739   IF p_claim_rec.customer_ref_number  = FND_API.G_MISS_CHAR  THEN
2740      x_complete_rec.customer_ref_number       := NULL;
2741   END IF;
2742   IF p_claim_rec.customer_ref_number  IS NULL THEN
2743      x_complete_rec.customer_ref_number       := l_claim_rec.customer_ref_number;
2744   END IF;
2745   IF p_claim_rec.receipt_id  = FND_API.G_MISS_NUM  THEN
2746      x_complete_rec.receipt_id       := NULL;
2747   END IF;
2748   IF p_claim_rec.receipt_id  IS NULL THEN
2749      x_complete_rec.receipt_id       := l_claim_rec.receipt_id;
2750   END IF;
2751   IF p_claim_rec.receipt_number  = FND_API.G_MISS_CHAR  THEN
2752      x_complete_rec.receipt_number       := NULL;
2753   END IF;
2754   IF p_claim_rec.receipt_number  IS NULL THEN
2755      x_complete_rec.receipt_number       := l_claim_rec.receipt_number;
2756   END IF;
2757   IF p_claim_rec.doc_sequence_id  = FND_API.G_MISS_NUM  THEN
2758      x_complete_rec.doc_sequence_id       := NULL;
2759   END IF;
2760   IF p_claim_rec.doc_sequence_id  IS NULL THEN
2761      x_complete_rec.doc_sequence_id       := l_claim_rec.doc_sequence_id;
2762   END IF;
2763   IF p_claim_rec.doc_sequence_value  = FND_API.G_MISS_NUM  THEN
2764      x_complete_rec.doc_sequence_value       := NULL;
2765   END IF;
2766   IF p_claim_rec.doc_sequence_value  IS NULL THEN
2767      x_complete_rec.doc_sequence_value       := l_claim_rec.doc_sequence_value;
2768   END IF;
2769   IF p_claim_rec.gl_date  = FND_API.G_MISS_DATE  THEN
2770      x_complete_rec.gl_date       := NULL;
2771   END IF;
2772   IF p_claim_rec.gl_date  IS NULL THEN
2773      x_complete_rec.gl_date       := l_claim_rec.gl_date;
2774   END IF;
2775   IF p_claim_rec.payment_method  = FND_API.G_MISS_CHAR  THEN
2776      x_complete_rec.payment_method       := NULL;
2777   END IF;
2778   IF p_claim_rec.payment_method  IS NULL THEN
2779      x_complete_rec.payment_method       := l_claim_rec.payment_method;
2780   END IF;
2781   IF p_claim_rec.voucher_id  = FND_API.G_MISS_NUM  THEN
2782      x_complete_rec.voucher_id       := NULL;
2783   END IF;
2784   IF p_claim_rec.voucher_id  IS NULL THEN
2785      x_complete_rec.voucher_id       := l_claim_rec.voucher_id;
2786   END IF;
2787   IF p_claim_rec.voucher_number  = FND_API.G_MISS_CHAR  THEN
2788      x_complete_rec.voucher_number       := NULL;
2789   END IF;
2790   IF p_claim_rec.voucher_number  IS NULL THEN
2791      x_complete_rec.voucher_number       := l_claim_rec.voucher_number;
2792   END IF;
2793   IF p_claim_rec.payment_reference_id  = FND_API.G_MISS_NUM  THEN
2794      x_complete_rec.payment_reference_id       := NULL;
2795   END IF;
2796   IF p_claim_rec.payment_reference_id  IS NULL THEN
2797      x_complete_rec.payment_reference_id       := l_claim_rec.payment_reference_id;
2798   END IF;
2799   IF p_claim_rec.payment_reference_number  = FND_API.G_MISS_CHAR  THEN
2800      x_complete_rec.payment_reference_number := NULL;
2801   END IF;
2802   IF p_claim_rec.payment_reference_number  IS NULL THEN
2803      x_complete_rec.payment_reference_number := l_claim_rec.payment_reference_number;
2804   END IF;
2805   IF p_claim_rec.payment_reference_date  = FND_API.G_MISS_DATE  THEN
2806      x_complete_rec.payment_reference_date := NULL;
2807   END IF;
2808   IF p_claim_rec.payment_reference_date  IS NULL THEN
2809      x_complete_rec.payment_reference_date := l_claim_rec.payment_reference_date;
2810   END IF;
2811   IF p_claim_rec.payment_status  = FND_API.G_MISS_CHAR  THEN
2812      x_complete_rec.payment_status := NULL;
2813   END IF;
2814   IF p_claim_rec.payment_status  IS NULL THEN
2815      x_complete_rec.payment_status := l_claim_rec.payment_status;
2816   END IF;
2817   IF p_claim_rec.approved_flag  = FND_API.G_MISS_CHAR  THEN
2818      x_complete_rec.approved_flag := NULL;
2819   END IF;
2820   IF p_claim_rec.approved_flag  IS NULL THEN
2821      x_complete_rec.approved_flag := l_claim_rec.approved_flag;
2822   END IF;
2823   IF p_claim_rec.approved_date  = FND_API.G_MISS_DATE  THEN
2824      x_complete_rec.approved_date := NULL;
2825   END IF;
2826   IF p_claim_rec.approved_date  IS NULL THEN
2827      x_complete_rec.approved_date := l_claim_rec.approved_date;
2828   END IF;
2829   IF p_claim_rec.approved_by  = FND_API.G_MISS_NUM  THEN
2830      x_complete_rec.approved_by := NULL;
2831   END IF;
2832   IF p_claim_rec.approved_by  IS NULL THEN
2833      x_complete_rec.approved_by := l_claim_rec.approved_by;
2834   END IF;
2835   IF p_claim_rec.settled_date  = FND_API.G_MISS_DATE  THEN
2836      x_complete_rec.settled_date := NULL;
2837   END IF;
2838   IF p_claim_rec.settled_date  IS NULL THEN
2839      x_complete_rec.settled_date := l_claim_rec.settled_date;
2840   END IF;
2841   IF p_claim_rec.settled_by  = FND_API.G_MISS_NUM  THEN
2842      x_complete_rec.settled_by := NULL;
2843   END IF;
2844   IF p_claim_rec.settled_by  IS NULL THEN
2845      x_complete_rec.settled_by := l_claim_rec.settled_by;
2846   END IF;
2847   IF p_claim_rec.effective_date  = FND_API.G_MISS_DATE  THEN
2848      x_complete_rec.effective_date := NULL;
2849   END IF;
2850   IF p_claim_rec.effective_date  IS NULL THEN
2851      x_complete_rec.effective_date := l_claim_rec.effective_date;
2852   END IF;
2853   IF p_claim_rec.custom_setup_id = FND_API.G_MISS_NUM  THEN
2854      x_complete_rec.custom_setup_id := NULL;
2855   END IF;
2856   IF p_claim_rec.custom_setup_id IS NULL THEN
2857      x_complete_rec.custom_setup_id := l_claim_rec.custom_setup_id;
2858   END IF;
2859   IF p_claim_rec.task_id  = FND_API.G_MISS_NUM  THEN
2860      x_complete_rec.task_id := NULL;
2861   END IF;
2862   IF p_claim_rec.task_id  IS NULL THEN
2863      x_complete_rec.task_id := l_claim_rec.task_id;
2864   END IF;
2865   IF p_claim_rec.country_id = FND_API.G_MISS_NUM  THEN
2866      x_complete_rec.country_id := NULL;
2867   END IF;
2868   IF p_claim_rec.country_id IS NULL THEN
2869      x_complete_rec.country_id := l_claim_rec.country_id;
2870   END IF;
2871   IF p_claim_rec.order_type_id = FND_API.G_MISS_NUM  THEN
2872      x_complete_rec.order_type_id := NULL;
2873   END IF;
2874   IF p_claim_rec.order_type_id IS NULL THEN
2875      x_complete_rec.order_type_id := l_claim_rec.order_type_id;
2876   END IF;
2877   IF p_claim_rec.comments  = FND_API.G_MISS_CHAR  THEN
2878      x_complete_rec.comments := NULL;
2879   END IF;
2880   IF p_claim_rec.comments  IS NULL THEN
2881      x_complete_rec.comments := l_claim_rec.comments;
2882   END IF;
2883   IF p_claim_rec.attribute_category  = FND_API.G_MISS_CHAR  THEN
2884      x_complete_rec.attribute_category := NULL;
2885   END IF;
2886   IF p_claim_rec.attribute_category  IS NULL THEN
2887      x_complete_rec.attribute_category := l_claim_rec.attribute_category;
2888   END IF;
2889   IF p_claim_rec.attribute1  = FND_API.G_MISS_CHAR  THEN
2890      x_complete_rec.attribute1 := NULL;
2891   END IF;
2892   IF p_claim_rec.attribute1  IS NULL THEN
2893      x_complete_rec.attribute1 := l_claim_rec.attribute1;
2894   END IF;
2895   IF p_claim_rec.attribute2  = FND_API.G_MISS_CHAR  THEN
2896      x_complete_rec.attribute2 := NULL;
2897   END IF;
2898   IF p_claim_rec.attribute2  IS NULL THEN
2899      x_complete_rec.attribute2 := l_claim_rec.attribute2;
2900   END IF;
2901   IF p_claim_rec.attribute3  = FND_API.G_MISS_CHAR  THEN
2902      x_complete_rec.attribute3 := NULL;
2903   END IF;
2904   IF p_claim_rec.attribute3  IS NULL THEN
2905      x_complete_rec.attribute3 := l_claim_rec.attribute3;
2906   END IF;
2907   IF p_claim_rec.attribute4  = FND_API.G_MISS_CHAR  THEN
2908      x_complete_rec.attribute4 := NULL;
2909   END IF;
2910   IF p_claim_rec.attribute4  IS NULL THEN
2911      x_complete_rec.attribute4 := l_claim_rec.attribute4;
2912   END IF;
2913   IF p_claim_rec.attribute5  = FND_API.G_MISS_CHAR  THEN
2914      x_complete_rec.attribute5 := NULL;
2915   END IF;
2916   IF p_claim_rec.attribute5  IS NULL THEN
2917      x_complete_rec.attribute5 := l_claim_rec.attribute5;
2918   END IF;
2919   IF p_claim_rec.attribute6  = FND_API.G_MISS_CHAR  THEN
2920      x_complete_rec.attribute6 := NULL;
2921   END IF;
2922   IF p_claim_rec.attribute6  IS NULL THEN
2923      x_complete_rec.attribute6 := l_claim_rec.attribute6;
2924   END IF;
2925   IF p_claim_rec.attribute7  = FND_API.G_MISS_CHAR  THEN
2926      x_complete_rec.attribute7 := NULL;
2927   END IF;
2928   IF p_claim_rec.attribute7  IS NULL THEN
2929      x_complete_rec.attribute7 := l_claim_rec.attribute7;
2930   END IF;
2931   IF p_claim_rec.attribute8  = FND_API.G_MISS_CHAR  THEN
2932      x_complete_rec.attribute8 := NULL;
2933   END IF;
2934   IF p_claim_rec.attribute8  IS NULL THEN
2935      x_complete_rec.attribute8 := l_claim_rec.attribute8;
2936   END IF;
2937   IF p_claim_rec.attribute9  = FND_API.G_MISS_CHAR  THEN
2938      x_complete_rec.attribute9 := NULL;
2939   END IF;
2940   IF p_claim_rec.attribute9  IS NULL THEN
2941      x_complete_rec.attribute9 := l_claim_rec.attribute9;
2942   END IF;
2943   IF p_claim_rec.attribute10  = FND_API.G_MISS_CHAR  THEN
2944      x_complete_rec.attribute10 := NULL;
2945   END IF;
2946   IF p_claim_rec.attribute10  IS NULL THEN
2947      x_complete_rec.attribute10 := l_claim_rec.attribute10;
2948   END IF;
2949   IF p_claim_rec.attribute11  = FND_API.G_MISS_CHAR  THEN
2950      x_complete_rec.attribute11 := NULL;
2951   END IF;
2952   IF p_claim_rec.attribute11  IS NULL THEN
2953      x_complete_rec.attribute11 := l_claim_rec.attribute11;
2954   END IF;
2955   IF p_claim_rec.attribute12  = FND_API.G_MISS_CHAR  THEN
2956      x_complete_rec.attribute12 := NULL;
2957   END IF;
2958   IF p_claim_rec.attribute12  IS NULL THEN
2959      x_complete_rec.attribute12 := l_claim_rec.attribute12;
2960   END IF;
2961   IF p_claim_rec.attribute13  = FND_API.G_MISS_CHAR  THEN
2962      x_complete_rec.attribute13 := NULL;
2963   END IF;
2964   IF p_claim_rec.attribute13  IS NULL THEN
2965      x_complete_rec.attribute13 := l_claim_rec.attribute13;
2966   END IF;
2967   IF p_claim_rec.attribute14  = FND_API.G_MISS_CHAR  THEN
2968      x_complete_rec.attribute14 := NULL;
2969   END IF;
2970   IF p_claim_rec.attribute14  IS NULL THEN
2971      x_complete_rec.attribute14 := l_claim_rec.attribute14;
2972   END IF;
2973   IF p_claim_rec.attribute15  = FND_API.G_MISS_CHAR  THEN
2974      x_complete_rec.attribute15 := NULL;
2975   END IF;
2976   IF p_claim_rec.attribute15  IS NULL THEN
2977      x_complete_rec.attribute15 := l_claim_rec.attribute15;
2978   END IF;
2979   IF p_claim_rec.deduction_attribute_category  = FND_API.G_MISS_CHAR  THEN
2980      x_complete_rec.deduction_attribute_category := NULL;
2981   END IF;
2982   IF p_claim_rec.deduction_attribute_category  IS NULL THEN
2983      x_complete_rec.deduction_attribute_category := l_claim_rec.deduction_attribute_category;
2984   END IF;
2985   IF p_claim_rec.deduction_attribute1  = FND_API.G_MISS_CHAR  THEN
2986      x_complete_rec.deduction_attribute1 := NULL;
2987   END IF;
2988   IF p_claim_rec.deduction_attribute1  IS NULL THEN
2989      x_complete_rec.deduction_attribute1 := l_claim_rec.deduction_attribute1;
2990   END IF;
2991   IF p_claim_rec.deduction_attribute2  = FND_API.G_MISS_CHAR  THEN
2992      x_complete_rec.deduction_attribute2 := NULL;
2993   END IF;
2994   IF p_claim_rec.deduction_attribute2  IS NULL THEN
2995      x_complete_rec.deduction_attribute2 := l_claim_rec.deduction_attribute2;
2996   END IF;
2997   IF p_claim_rec.deduction_attribute3  = FND_API.G_MISS_CHAR  THEN
2998      x_complete_rec.deduction_attribute3 := NULL;
2999   END IF;
3000   IF p_claim_rec.deduction_attribute3  IS NULL THEN
3001      x_complete_rec.deduction_attribute3 := l_claim_rec.deduction_attribute3;
3002   END IF;
3003   IF p_claim_rec.deduction_attribute4  = FND_API.G_MISS_CHAR  THEN
3004      x_complete_rec.deduction_attribute4 := NULL;
3005   END IF;
3006   IF p_claim_rec.deduction_attribute4  IS NULL THEN
3007      x_complete_rec.deduction_attribute4 := l_claim_rec.deduction_attribute4;
3008   END IF;
3009   IF p_claim_rec.deduction_attribute5  = FND_API.G_MISS_CHAR  THEN
3010      x_complete_rec.deduction_attribute5 := NULL;
3011   END IF;
3012   IF p_claim_rec.deduction_attribute5  IS NULL THEN
3013      x_complete_rec.deduction_attribute5 := l_claim_rec.deduction_attribute5;
3014   END IF;
3015   IF p_claim_rec.attribute6  = FND_API.G_MISS_CHAR  THEN
3016      x_complete_rec.deduction_attribute6 := NULL;
3017   END IF;
3018   IF p_claim_rec.attribute6  IS NULL THEN
3019      x_complete_rec.deduction_attribute6 := l_claim_rec.deduction_attribute6;
3020   END IF;
3021   IF p_claim_rec.deduction_attribute7  = FND_API.G_MISS_CHAR  THEN
3022      x_complete_rec.deduction_attribute7 := NULL;
3023   END IF;
3024   IF p_claim_rec.deduction_attribute7  IS NULL THEN
3025      x_complete_rec.deduction_attribute7 := l_claim_rec.deduction_attribute7;
3026   END IF;
3027   IF p_claim_rec.deduction_attribute8  = FND_API.G_MISS_CHAR  THEN
3028      x_complete_rec.deduction_attribute8 := NULL;
3029   END IF;
3030   IF p_claim_rec.deduction_attribute8  IS NULL THEN
3031      x_complete_rec.deduction_attribute8 := l_claim_rec.deduction_attribute8;
3032   END IF;
3033   IF p_claim_rec.deduction_attribute9  = FND_API.G_MISS_CHAR  THEN
3034      x_complete_rec.deduction_attribute9 := NULL;
3035   END IF;
3036   IF p_claim_rec.deduction_attribute9  IS NULL THEN
3037      x_complete_rec.deduction_attribute9 := l_claim_rec.deduction_attribute9;
3038   END IF;
3039   IF p_claim_rec.deduction_attribute10  = FND_API.G_MISS_CHAR  THEN
3040      x_complete_rec.deduction_attribute10 := NULL;
3041   END IF;
3042   IF p_claim_rec.deduction_attribute10  IS NULL THEN
3043      x_complete_rec.deduction_attribute10 := l_claim_rec.deduction_attribute10;
3044   END IF;
3045   IF p_claim_rec.deduction_attribute11  = FND_API.G_MISS_CHAR  THEN
3046      x_complete_rec.deduction_attribute11 := NULL;
3047   END IF;
3048   IF p_claim_rec.deduction_attribute11  IS NULL THEN
3049      x_complete_rec.deduction_attribute11 := l_claim_rec.deduction_attribute11;
3050   END IF;
3051   IF p_claim_rec.deduction_attribute12  = FND_API.G_MISS_CHAR  THEN
3052      x_complete_rec.deduction_attribute12 := NULL;
3053   END IF;
3054   IF p_claim_rec.deduction_attribute12  IS NULL THEN
3055      x_complete_rec.deduction_attribute12 := l_claim_rec.deduction_attribute12;
3056   END IF;
3057   IF p_claim_rec.deduction_attribute13  = FND_API.G_MISS_CHAR  THEN
3058      x_complete_rec.deduction_attribute13 := NULL;
3059   END IF;
3060   IF p_claim_rec.deduction_attribute13  IS NULL THEN
3061      x_complete_rec.deduction_attribute13 := l_claim_rec.deduction_attribute13;
3062   END IF;
3063   IF p_claim_rec.deduction_attribute14  = FND_API.G_MISS_CHAR  THEN
3064      x_complete_rec.deduction_attribute14 := NULL;
3065   END IF;
3066   IF p_claim_rec.deduction_attribute14  IS NULL THEN
3067      x_complete_rec.deduction_attribute14 := l_claim_rec.deduction_attribute14;
3068   END IF;
3069   IF p_claim_rec.deduction_attribute15  = FND_API.G_MISS_CHAR  THEN
3070      x_complete_rec.deduction_attribute15 := NULL;
3071   END IF;
3072   IF p_claim_rec.deduction_attribute15  IS NULL THEN
3073      x_complete_rec.deduction_attribute15 := l_claim_rec.deduction_attribute15;
3074   END IF;
3075   IF p_claim_rec.org_id  = FND_API.G_MISS_NUM  THEN
3076      x_complete_rec.org_id := NULL;
3077   END IF;
3078   IF p_claim_rec.org_id  IS NULL THEN
3079      x_complete_rec.org_id := l_claim_rec.org_id;
3080   END IF;
3081   --  Added by Kishore
3082   IF p_claim_rec.legal_entity_id  = FND_API.G_MISS_NUM  THEN
3083      x_complete_rec.legal_entity_id := NULL;
3084   END IF;
3085   IF p_claim_rec.legal_entity_id  IS NULL THEN
3086      x_complete_rec.legal_entity_id := l_claim_rec.legal_entity_id;
3087   END IF;
3088  --Auto Write-off changes (Added by Uday Poluri)
3089   IF p_claim_rec.write_off_flag  = FND_API.G_MISS_CHAR  THEN
3090      x_complete_rec.write_off_flag := NULL;
3091   END IF;
3092   IF p_claim_rec.write_off_flag  IS NULL  THEN
3093      x_complete_rec.write_off_flag := l_claim_rec.write_off_flag;
3094   END IF;
3095 
3096   IF p_claim_rec.write_off_threshold_amount  = FND_API.G_MISS_NUM  THEN
3097      x_complete_rec.write_off_threshold_amount := NULL;
3098   END IF;
3099   IF p_claim_rec.write_off_threshold_amount  IS NULL  THEN
3100      x_complete_rec.write_off_threshold_amount := l_claim_rec.write_off_threshold_amount;
3101   END IF;
3102 
3103   IF p_claim_rec.under_write_off_threshold  = FND_API.G_MISS_CHAR  THEN
3104      x_complete_rec.under_write_off_threshold := NULL;
3105   END IF;
3106   IF p_claim_rec.under_write_off_threshold  IS NULL  THEN
3107      x_complete_rec.under_write_off_threshold := l_claim_rec.under_write_off_threshold;
3108   END IF;
3109 
3110   IF p_claim_rec.customer_reason  = FND_API.G_MISS_CHAR  THEN
3111      x_complete_rec.customer_reason := NULL;
3112   END IF;
3113   IF p_claim_rec.customer_reason  IS NULL  THEN
3114      x_complete_rec.customer_reason := l_claim_rec.customer_reason;
3115   END IF;
3116 
3117   IF p_claim_rec.ship_to_cust_account_id  = FND_API.G_MISS_NUM  THEN
3118      x_complete_rec.ship_to_cust_account_id       := NULL;
3119   END IF;
3120   IF p_claim_rec.ship_to_cust_account_id  IS NULL  THEN
3121      x_complete_rec.ship_to_cust_account_id       := l_claim_rec.ship_to_cust_account_id;
3122   END IF;
3123   --End of Auto Write-off changes (Added by Uday Poluri)
3124 
3125   -- Start Bug:2781186 (Subsequent Receipt Application changes)
3126   IF p_claim_rec.amount_applied  = FND_API.G_MISS_NUM  THEN
3127      x_complete_rec.amount_applied := NULL;
3128   END IF;
3129   IF p_claim_rec.amount_applied  IS NULL  THEN
3130      x_complete_rec.amount_applied := l_claim_rec.amount_applied;
3131   END IF;
3132 
3133   IF p_claim_rec.applied_receipt_id  = FND_API.G_MISS_NUM  THEN
3134      x_complete_rec.applied_receipt_id := NULL;
3135   END IF;
3136   IF p_claim_rec.applied_receipt_id  IS NULL  THEN
3137      x_complete_rec.applied_receipt_id := l_claim_rec.applied_receipt_id;
3138   END IF;
3139 
3140   IF p_claim_rec.applied_receipt_number  = FND_API.G_MISS_CHAR  THEN
3141      x_complete_rec.applied_receipt_number := NULL;
3142   END IF;
3143   IF p_claim_rec.applied_receipt_number  IS NULL  THEN
3144      x_complete_rec.applied_receipt_number := l_claim_rec.applied_receipt_number;
3145   END IF;
3146   -- End Bug:2781186
3147   IF p_claim_rec.wo_rec_trx_id  = FND_API.G_MISS_NUM  THEN
3148      x_complete_rec.wo_rec_trx_id := NULL;
3149   END IF;
3150   IF p_claim_rec.wo_rec_trx_id  IS NULL  THEN
3151      x_complete_rec.wo_rec_trx_id := l_claim_rec.wo_rec_trx_id;
3152   END IF;
3153 
3154 
3155   IF p_claim_rec.group_claim_id  = FND_API.G_MISS_NUM  THEN
3156      x_complete_rec.group_claim_id := NULL;
3157   END IF;
3158   IF p_claim_rec.group_claim_id  IS NULL  THEN
3159      x_complete_rec.group_claim_id := l_claim_rec.group_claim_id;
3160   END IF;
3161   IF p_claim_rec.appr_wf_item_key  = FND_API.G_MISS_CHAR  THEN
3162      x_complete_rec.appr_wf_item_key := NULL;
3163   END IF;
3164   IF p_claim_rec.appr_wf_item_key  IS NULL  THEN
3165      x_complete_rec.appr_wf_item_key := l_claim_rec.appr_wf_item_key;
3166   END IF;
3167   IF p_claim_rec.cstl_wf_item_key  = FND_API.G_MISS_CHAR  THEN
3168      x_complete_rec.cstl_wf_item_key := NULL;
3169   END IF;
3170   IF p_claim_rec.cstl_wf_item_key  IS NULL  THEN
3171      x_complete_rec.cstl_wf_item_key := l_claim_rec.cstl_wf_item_key;
3172   END IF;
3173   IF p_claim_rec.batch_type  = FND_API.G_MISS_CHAR  THEN
3174      x_complete_rec.batch_type := NULL;
3175   END IF;
3176   IF p_claim_rec.batch_type  IS NULL  THEN
3177      x_complete_rec.batch_type := l_claim_rec.batch_type;
3178   END IF;
3179 
3180   IF p_claim_rec.created_from  = FND_API.G_MISS_CHAR  THEN
3181      x_complete_rec.created_from := NULL;
3182   END IF;
3183   IF p_claim_rec.created_from  IS NULL  THEN
3184      x_complete_rec.created_from := l_claim_rec.created_from;
3185   END IF;
3186 
3187    IF p_claim_rec.program_id  = FND_API.G_MISS_NUM  THEN
3188      x_complete_rec.program_id := NULL;
3189   END IF;
3190   IF p_claim_rec.program_id  IS NULL  THEN
3191      x_complete_rec.program_id := l_claim_rec.program_id;
3192   END IF;
3193 
3194   IF p_claim_rec.program_update_date         = FND_API.G_MISS_DATE  THEN
3195      x_complete_rec.program_update_date       := NULL;
3196   END IF;
3197   IF p_claim_rec.program_update_date         IS NULL THEN
3198      x_complete_rec.program_update_date       := l_claim_rec.program_update_date;
3199   END IF;
3200 
3201    IF p_claim_rec.program_application_id  = FND_API.G_MISS_NUM  THEN
3202      x_complete_rec.program_application_id := NULL;
3203   END IF;
3204   IF p_claim_rec.program_application_id  IS NULL  THEN
3205      x_complete_rec.program_application_id := l_claim_rec.program_application_id;
3206   END IF;
3207 
3208    IF p_claim_rec.request_id  = FND_API.G_MISS_NUM  THEN
3209      x_complete_rec.request_id := NULL;
3210   END IF;
3211   IF p_claim_rec.request_id  IS NULL  THEN
3212      x_complete_rec.request_id := l_claim_rec.request_id;
3213   END IF;
3214 
3215 
3216  EXCEPTION
3217    WHEN FND_API.G_EXC_ERROR THEN
3218       x_return_status := FND_API.G_RET_STS_ERROR;
3219    WHEN OTHERS THEN
3220       IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_unexp_error) THEN
3221          FND_MESSAGE.set_name('OZF', 'OZF_CLAIM_COMPLETE_ERROR');
3222          FND_MSG_PUB.add;
3223       END IF;
3224       x_return_status := FND_API.g_ret_sts_unexp_error;
3225 END Complete_Claim_Rec;
3226 ---------------------------------------------------------------------
3227 -- PROCEDURE
3228 --    Create_Claim
3229 --
3230 -- PURPOSE
3231 --    Create a claim
3232 --
3233 -- PARAMETERS
3234 --
3235 --    x_claim_id  : return the claim_id of the new claim record
3236 --
3237 -- NOTES
3238 --    1. object_version_number will be set to 1.
3239 --    2. If claim_id is passed in, the uniqueness will be checked.
3240 --       Raise exception in case of duplicates.
3241 --    3. If claim_id is not passed in, generate a unique one from
3242 --       the sequence.
3243 --    4. If a flag column is passed in, check if it is 'Y' or 'N'.
3244 --       Raise exception for invalid flag.
3245 --    5. If a flag column is not passed in, default it to 'Y'.
3246 --    6. Please don't pass in any FND_API.g_mess_char/num/date.
3247 --    7. The program assumes that the cust_account_id and
3248 --       cust_billto_acct_site_id that passed in the program are valid
3249 ---------------------------------------------------------------------
3250 PROCEDURE  Create_Claim (
3251     p_api_version            IN    NUMBER
3252    ,p_init_msg_list          IN    VARCHAR2 := FND_API.G_FALSE
3253    ,p_commit                 IN    VARCHAR2 := FND_API.G_FALSE
3254    ,p_validation_level       IN    NUMBER   := FND_API.G_VALID_LEVEL_FULL
3255 
3256    ,x_return_status          OUT NOCOPY   VARCHAR2
3257    ,x_msg_data               OUT NOCOPY   VARCHAR2
3258    ,x_msg_count              OUT NOCOPY   NUMBER
3259 
3260    ,p_claim                  IN    claim_rec_type
3261    ,x_claim_id               OUT NOCOPY   NUMBER
3262 )
3263 IS
3264 l_api_name               CONSTANT VARCHAR2(30) := 'Create_Claim';
3265 l_api_version            CONSTANT NUMBER := 1.0;
3266 l_full_name              CONSTANT VARCHAR2(60) := G_PKG_NAME ||'.'|| l_api_name;
3267 --
3268 l_resource_id            number;
3269 l_user_id                number;
3270 l_login_user_id          number;
3271 l_login_user_status      varchar2(30);
3272 l_Error_Msg              varchar2(2000);
3273 l_Error_Token            varchar2(80);
3274 l_object_version_number  number := 1;
3275 l_claim                  claim_rec_type := p_claim;
3276 l_complete_claim         claim_rec_type;
3277 l_claim_id               number;
3278 l_cust_number            varchar2(80);
3279 
3280 l_customer_ref_norm      varchar2(30);
3281 l_acc_amount             number;
3282 l_rate                   number;
3283 l_object_type            varchar2(30) := G_CLAIM_OBJECT_TYPE;
3284 l_custom_setup_id        number;
3285 
3286 --l_mc_transaction_rec     OZF_mc_transactions_PVT.mc_transactions_rec_type;
3287 --l_mc_transaction_id      NUMBER;
3288 
3289 l_claim_number           varchar2(30);
3290 l_gl_date                date;
3291 l_gl_date_type           varchar2(30);
3292 l_days_due       number;
3293 l_sales_rep_id           number;
3294 l_customer_name          varchar2(250);
3295 l_broker_id              number;
3296 l_contact_id             number;
3297 l_user_status_id         number;
3298 l_status_code            varchar2(30);
3299 l_org_id                 number;
3300 l_sob_id                 number;
3301 l_functional_currency_code varchar2(15);
3302 
3303 l_return_status          varchar2(30);
3304 l_msg_data               varchar2(2000);
3305 l_msg_count              number;
3306 
3307 l_claim_reason_code_id         number;   --Bug:2732290  (Added by Uday Poluri)
3308 l_reason_code_id               number;   --Bug:2732290
3309 l_short_payment_reason_code_id number;   --Bug:2732290
3310 l_need_to_create        varchar2(1) := 'N';
3311 l_claim_history_id      number;
3312 l_clam_def_rec_type     ozf_claim_def_rule_pvt.clam_def_rec_type;
3313 l_default_owner                NUMBER;   -- [BUG 3835800 Fixing]
3314 
3315 CURSOR custom_setup_id_csr(p_claim_class in varchar2) IS
3316 SELECT custom_setup_id
3317 FROM ams_custom_setups_vl
3318 WHERE object_type = G_CLAIM_OBJECT_TYPE
3319 AND  activity_type_code = p_claim_class;
3320 
3321 -- fix for bug 5042046
3322 CURSOR sob_csr IS
3323 SELECT set_of_books_id
3324 FROM   ozf_sys_parameters
3325 WHERE org_id = MO_GLOBAL.GET_CURRENT_ORG_ID();
3326 
3327 CURSOR sys_parameters_csr IS
3328 SELECT gl_date_type
3329 FROM   ozf_sys_parameters
3330 WHERE org_id = MO_GLOBAL.GET_CURRENT_ORG_ID();
3331 
3332 CURSOR exchange_rate_type_csr IS
3333 SELECT exchange_rate_type
3334 FROM   ozf_sys_parameters
3335 WHERE org_id = MO_GLOBAL.GET_CURRENT_ORG_ID();
3336 
3337 CURSOR default_owner_id_csr IS
3338 SELECT default_owner_id
3339 FROM   ozf_sys_parameters
3340 WHERE org_id = MO_GLOBAL.GET_CURRENT_ORG_ID();
3341 
3342 CURSOR auto_assign_flag_csr IS
3343 SELECT auto_assign_flag
3344 FROM   ozf_sys_parameters
3345 WHERE org_id = MO_GLOBAL.GET_CURRENT_ORG_ID();
3346 
3347 l_auto_assign_flag varchar2(1);
3348 
3349 CURSOR claim_id_csr IS
3350 SELECT ozf_claims_all_s.nextval FROM dual;
3351 
3352 CURSOR trade_profile_csr(p_customer_account_id in number) IS
3353 SELECT vendor_id, vendor_site_id
3354 FROM   ozf_cust_trd_prfls
3355 WHERE  cust_account_id = p_customer_account_id;
3356 
3357 l_trade_profile trade_profile_csr%ROWTYPE;
3358 
3359 -- This cursor get the account_name of a cust_acc. We might not need it.
3360 CURSOR cust_account_name_csr(p_customer_account_id in number) IS
3361 SELECT account_name
3362 FROM   hz_cust_accounts
3363 WHERE  cust_account_id = p_customer_account_id;
3364 
3365 /* CURSOR org_id_csr IS  -- R12 Enhancements
3366 SELECT (TO_NUMBER(SUBSTRB(USERENV('CLIENT_INFO'), 1, 10)))
3367 FROM   dual; */
3368 
3369 CURSOR claim_number_count_csr(p_claim_number in varchar2) IS
3370 SELECT count(claim_number)
3371 FROM   ozf_claims_all
3372 WHERE  upper(claim_number) = p_claim_number;
3373 l_temp_claim_number varchar2(30);
3374 
3375 l_count number:=0;
3376 
3377 CURSOR claim_id_count_csr(p_id in number) is
3378 select count(*)
3379 from ozf_claims
3380 where claim_id =p_id;
3381 
3382 l_claim_id_count number:=0;
3383 
3384 l_access_list gp_access_list_type;
3385 -- [BEGIN OF BUG 3835800 Fixing]
3386 l_access_comp_list gp_access_list_type;
3387 l_dup_resource     BOOLEAN := FALSE;
3388 -- [END OF BUG 3835800 Fixing]
3389 l_access_id number;
3390 l_last_index  number;
3391 
3392 l_errbuf       VARCHAR2(3000);
3393 l_retcode      VARCHAR2(30);
3394 
3395 CURSOR default_action_id_csr (p_id in number) is
3396 select t.task_template_group_id
3397 from ozf_reasons r,
3398 jtf_task_temp_groups_vl t
3399 where t.source_object_type_code = 'OZF_CLAM'
3400 and r.active_flag = 'T'
3401 and r.default_flag = 'T'
3402 and t.task_template_group_id = r.task_template_group_id
3403 and nvl(t.start_date_active, sysdate) <= sysdate
3404 and nvl(t.end_date_active, sysdate) >= sysdate
3405 and r.reason_code_id = p_id;
3406 
3407 
3408 l_default_action_id number;
3409 
3410 BEGIN
3411 
3412     -- Standard begin of API savepoint
3413     SAVEPOINT  Create_Claim_PVT;
3414     -- Standard call to check for call compatibility.
3415     IF NOT FND_API.Compatible_API_Call (
3416         l_api_version,
3417         p_api_version,
3418         l_api_name,
3419         G_PKG_NAME)
3420     THEN
3421         RAISE  FND_API.G_EXC_UNEXPECTED_ERROR;
3422     END IF;
3423     -- Debug Message
3424     IF OZF_DEBUG_LOW_ON THEN
3425        FND_MESSAGE.Set_Name('OZF','OZF_API_DEBUG_MESSAGE');
3426        FND_MESSAGE.Set_Token('TEXT',l_full_name||': Start');
3427        FND_MSG_PUB.Add;
3428     END IF;
3429     --Initialize message list if p_init_msg_list is TRUE.
3430     IF FND_API.To_Boolean (p_init_msg_list) THEN
3431        FND_MSG_PUB.initialize;
3432     END IF;
3433 
3434     -- Initialize API return status to sucess
3435     x_return_status := FND_API.G_RET_STS_SUCCESS;
3436 
3437 
3438     -- Default claim_class
3439     IF (l_claim.claim_class is null OR
3440         l_claim.claim_class = FND_API.G_MISS_CHAR) THEN
3441        if l_claim.amount >0 then
3442           l_claim.claim_class := G_CLAIM_CLASS;
3443        else
3444           l_claim.claim_class := G_CHARGE_CLASS;
3445         end if;
3446     ELSE
3447        /* check claim class value */
3448        IF l_claim.claim_class <> G_CLAIM_CLASS AND
3449           l_claim.claim_class <> G_DEDUCTION_CLASS AND
3450 	       l_claim.claim_class <> G_OVERPAYMENT_CLASS AND
3451           l_claim.claim_class <> G_CHARGE_CLASS AND
3452           l_claim.claim_class <> G_GROUP_CLASS
3453       THEN
3454 
3455           IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error)
3456           THEN
3457              FND_MESSAGE.set_name('OZF', 'OZF_CLAIM_CLAIM_CLASS_WRG');
3458              FND_MSG_PUB.add;
3459           END IF;
3460           RAISE FND_API.G_EXC_ERROR;
3461        END IF;
3462     END IF;
3463 
3464     IF l_claim.cust_account_id is NULL OR
3465 	      l_claim.cust_account_id = FND_API.G_MISS_NUM
3466     THEN
3467         IF FND_MSG_PUB.Check_Msg_level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
3468 	        FND_MESSAGE.Set_Name('OZF','OZF_CLAIM_CUST_ID_MISSING');
3469            FND_MSG_PUB.Add;
3470       	END IF;
3471       	RAISE FND_API.G_EXC_ERROR;
3472     END IF;
3473 
3474     --Call Get Customer Reason to get the reason code
3475     --if the customer reason is not null.
3476     IF (l_claim.reason_code_id is NULL
3477        OR l_claim.reason_code_id = FND_API.G_MISS_NUM)
3478        AND (l_claim.customer_reason is NOT NULL
3479        AND l_claim.customer_reason <> FND_API.G_MISS_CHAR)
3480     THEN
3481       Get_Customer_Reason(p_cust_account_id => l_claim.cust_account_id,
3482                           px_reason_code_id => l_claim.reason_code_id,
3483                           p_customer_reason => l_claim.customer_reason,
3484                           x_return_status  => l_return_status);
3485 
3486       --in case of ded/opm don't raise the error in case if we fail to
3487       --retrieve the reason code. Instead default it from the Claim Defaults.
3488       IF  l_claim.claim_class <> G_DEDUCTION_CLASS AND
3489 	       l_claim.claim_class <> G_OVERPAYMENT_CLASS
3490       THEN
3491          IF l_return_status = FND_API.g_ret_sts_error
3492          THEN
3493            RAISE FND_API.g_exc_error;
3494          ELSIF l_return_status = FND_API.g_ret_sts_unexp_error THEN
3495            RAISE FND_API.g_exc_unexpected_error;
3496          END IF;
3497       END IF;
3498     END IF;
3499     --end of get_customer_reason if block.
3500 
3501 
3502     -- Call Claim defaults to default the reason code, Claim type and custom setup.
3503     -- set the default values only incase user has not specified any of these values.
3504     OZF_CLAIM_DEF_RULE_PVT.get_clam_def_rule (
3505                   p_claim_rec               => l_claim,
3506                   x_clam_def_rec_type       => l_clam_def_rec_type,
3507                   x_return_status           => l_return_status,
3508                   x_msg_count               => l_msg_count,
3509                   x_msg_data                => l_msg_data);
3510 
3511    IF l_return_status = FND_API.g_ret_sts_error THEN
3512       RAISE FND_API.G_EXC_ERROR;
3513    ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
3514      RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3515    END IF;
3516 
3517    --Default custom setup Id
3518    IF l_claim.custom_setup_id IS NULL
3519    OR l_claim.custom_setup_id = FND_API.G_MISS_NUM
3520    THEN
3521       l_claim.custom_setup_id := l_clam_def_rec_type.custom_setup_id;
3522    END IF;
3523 
3524    IF l_claim.custom_setup_id is NULL OR
3525       l_claim.custom_setup_id = FND_API.G_MISS_NUM
3526    THEN
3527       IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error)
3528       THEN
3529          FND_MESSAGE.set_name('OZF', 'OZF_CLAIM_CUST_SETUP_MISSING');
3530          FND_MSG_PUB.add;
3531        END IF;
3532        RAISE FND_API.G_EXC_ERROR;
3533  END IF;
3534 
3535 
3536    --Default Claim type Id.
3537    IF l_claim.claim_type_id IS NULL
3538    OR l_claim.claim_type_id = FND_API.G_MISS_NUM
3539    THEN
3540       l_claim.claim_type_id := l_clam_def_rec_type.claim_type_id;
3541    END IF;
3542 
3543     IF l_claim.claim_type_id is NULL OR
3544          l_claim.claim_type_id = FND_API.G_MISS_NUM
3545     THEN
3546         IF FND_MSG_PUB.Check_Msg_level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
3547 	        FND_MESSAGE.Set_Name('OZF','OZF_CLAIM_CLAIM_TYPE_MISSING');
3548            FND_MSG_PUB.Add;
3549       	END IF;
3550       	RAISE FND_API.G_EXC_ERROR;
3551     END IF;
3552 
3553 
3554    --Default reason code
3555    IF (l_claim.reason_code_id IS NULL
3556       OR l_claim.reason_code_id = FND_API.G_MISS_NUM)
3557    THEN
3558       l_claim.reason_code_id := l_clam_def_rec_type.reason_code_id;
3559    END IF;
3560 
3561 
3562     -- End Bug: 2732290 -----------------------------------------------------------
3563     IF l_claim.reason_code_id is NULL
3564     THEN
3565      IF FND_MSG_PUB.Check_Msg_level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
3566          FND_MESSAGE.Set_Name('OZF','OZF_CLAIM_REASON_CD_MISSING');
3567          FND_MSG_PUB.Add;
3568       END IF;
3569       RAISE FND_API.G_EXC_ERROR;
3570     END IF;
3571    --End of defalting values from Claim defaults.
3572 
3573 
3574     IF (l_claim.amount is NULL OR
3575        l_claim.amount = FND_API.G_MISS_NUM OR
3576        l_claim.amount = 0) AND
3577        l_claim.claim_class <>'GROUP' THEN
3578 
3579     IF OZF_DEBUG_LOW_ON THEN
3580        FND_MESSAGE.Set_Name('OZF','OZF_API_DEBUG_MESSAGE');
3581        FND_MESSAGE.Set_Token('TEXT','l_claim.amount='||l_claim.amount);
3582        FND_MSG_PUB.Add;
3583     END IF;
3584 
3585 	IF FND_MSG_PUB.Check_Msg_level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
3586 	   FND_MESSAGE.Set_Name('OZF','OZF_CLAIM_AMOUNT_MISSING');
3587            FND_MSG_PUB.Add;
3588 	END IF;
3589 	RAISE FND_API.G_EXC_ERROR;
3590     END IF;
3591 
3592     -- Now we will default some values for this claim record
3593     --
3594     -- get org_id
3595     /* OPEN org_id_csr;
3596     FETCH org_id_csr INTO l_org_id;
3597     IF org_id_csr%NOTFOUND THEN
3598        CLOSE org_id_csr;
3599        IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_error) THEN
3600           fnd_message.set_name('OZF', 'OZF_CLAIM_ORG_ID_MISSING');
3601           fnd_msg_pub.add;
3602        END IF;
3603        RAISE fnd_api.g_exc_error;
3604     END IF;
3605     CLOSE org_id_csr;
3606     l_claim.org_id := l_org_id;  */
3607 
3608     -- If org_id is null, then needs to get current_org_id.
3609      IF (l_claim.org_id IS NULL ) THEN
3610          l_org_id := MO_GLOBAL.GET_CURRENT_ORG_ID();  -- R12 Enhancements
3611          l_claim.org_id  := l_org_id;
3612      ELSE
3613          l_org_id := l_claim.org_id;
3614      END IF;
3615 
3616     -- If legal_entity_id is null, then needs to get from profile.
3617     IF (l_claim.legal_entity_id IS NULL) THEN
3618       l_claim.legal_entity_id  := FND_PROFILE.VALUE('OZF_DEFAULT_LE_FOR_CLAIM');
3619     END IF;
3620 
3621     IF OZF_DEBUG_HIGH_ON THEN
3622        ozf_utility_PVT.debug_message('legal_entity_id:'||l_claim.legal_entity_id);
3623     END IF;
3624 
3625     -- BUG 4600325 is fixed.
3626     IF l_claim.legal_entity_id is NULL OR
3627 	    l_claim.legal_entity_id = FND_API.G_MISS_NUM
3628     THEN
3629         IF FND_MSG_PUB.Check_Msg_level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
3630 	       FND_MESSAGE.Set_Name('OZF','OZF_LE_FOR_CLAIM_MISSING');
3631            FND_MSG_PUB.Add;
3632       	END IF;
3633       	RAISE FND_API.G_EXC_ERROR;
3634     END IF;
3635 
3636     -- get sob
3637     OPEN sob_csr;
3638     FETCH sob_csr INTO l_sob_id;
3639     CLOSE sob_csr;
3640     l_claim.set_of_books_id := l_sob_id;
3641 
3642 
3643 
3644     -- Default claim_number if it's null
3645     IF ((l_claim.claim_number is null) OR
3646         (l_claim.claim_number = FND_API.G_MISS_CHAR))THEN
3647 
3648        Get_Claim_Number(
3649           p_split_from_claim_id => l_claim.split_from_claim_id,
3650           p_custom_setup_id => l_claim.custom_setup_id,
3651           x_claim_number => l_claim_number,
3652           x_msg_data     => l_msg_data,
3653           x_msg_count    => l_msg_count,
3654           x_return_status=> l_return_status
3655        );
3656        IF l_return_status = FND_API.G_RET_STS_ERROR THEN
3657           RAISE FND_API.G_EXC_ERROR;
3658        ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
3659           RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3660        END IF;
3661 
3662        l_claim.claim_number := l_claim_number;
3663     ELSE
3664        l_temp_claim_number := Upper(l_claim.claim_number);
3665        OPEN claim_number_count_csr(l_temp_claim_number);
3666        FETCH claim_number_count_csr INTO l_count;
3667        CLOSE claim_number_count_csr;
3668 
3669        IF l_count > 0 THEN
3670           IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
3671              FND_MESSAGE.set_name('OZF', 'OZF_CLAIM_DUP_CLAIM_NUM');
3672              FND_MSG_PUB.add;
3673           END IF;
3674           RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3675        END IF;
3676     END IF;
3677 
3678     -- Default CLAIM_DATE if it's null
3679     IF (l_claim.claim_date is null OR
3680         l_claim.claim_date = FND_API.G_MISS_DATE)THEN
3681        l_claim.claim_date := TRUNC(sysdate);
3682     END IF;
3683 
3684     -- get customer info from trade profile
3685     OPEN trade_profile_csr(l_claim.cust_account_id);
3686     IF trade_profile_csr%NOTFOUND THEN
3687        l_trade_profile.vendor_id := null;
3688        l_trade_profile.vendor_site_id := null;
3689        CLOSE trade_profile_csr;
3690     ELSE
3691        FETCH trade_profile_csr into l_trade_profile;
3692        CLOSE trade_profile_csr;
3693     END IF;
3694 
3695     -- Default vendor info
3696     IF l_claim.vendor_id is null OR
3697        l_claim.vendor_id = FND_API.G_MISS_NUM THEN
3698        l_claim.vendor_id := l_trade_profile.vendor_id;
3699 
3700        IF l_claim.vendor_site_id is null OR
3701           l_claim.vendor_site_id = FND_API.G_MISS_NUM THEN
3702           l_claim.vendor_site_id := l_trade_profile.vendor_site_id;
3703        END IF;
3704     END IF;
3705 
3706     -- Default DUE_DATE if it's null
3707     IF (l_claim.DUE_DATE is null OR
3708         l_claim.due_date = FND_API.G_MISS_DATE) THEN
3709 
3710        get_days_due (p_cust_accout_id => l_claim.cust_account_id,
3711                      x_days_due       => l_days_due,
3712                      x_return_status  => l_return_status);
3713        IF l_return_status = FND_API.g_ret_sts_error THEN
3714           RAISE FND_API.g_exc_error;
3715        ELSIF l_return_status = FND_API.g_ret_sts_unexp_error THEN
3716           RAISE FND_API.g_exc_unexpected_error;
3717        END IF;
3718        l_claim.DUE_DATE := TRUNC(l_claim.claim_date + l_days_due);
3719     END IF;
3720 
3721     -- Default user_status_id if it's null
3722     IF (l_claim.user_status_id is null OR
3723         l_claim.user_status_id = FND_API.G_MISS_NUM) THEN
3724        l_claim.user_status_id := to_number( ozf_utility_pvt.GET_DEFAULT_USER_STATUS(
3725                                           P_STATUS_TYPE=> G_CLAIM_STATUS,
3726                                           P_STATUS_CODE=> G_INIT_STATUS
3727                                       )
3728                                     );
3729 
3730     END IF;
3731 
3732     -- Default action id i.e. task_template_group_id if possible
3733       l_claim.TASK_TEMPLATE_GROUP_ID := get_action_id(l_claim.reason_code_id);
3734 
3735     -- Default status_code according to user_status_id if it's null
3736     IF (l_claim.status_code is null OR
3737         l_claim.status_code = FND_API.G_MISS_CHAR) THEN
3738 	Get_System_Status( p_user_status_id => l_claim.user_status_id,
3739                       p_status_type    => G_CLAIM_STATUS,
3740                       x_system_status  => l_status_code,
3741                       x_msg_data       => l_msg_data,
3742                       x_msg_count      => l_msg_count,
3743                       x_return_status  => l_return_status
3744        );
3745        l_claim.status_code := l_status_code;
3746     END IF;
3747 
3748     IF l_claim.status_code = G_OPEN_STATUS THEN
3749        l_claim.open_status_id := l_claim.user_status_id;
3750     END IF;
3751     -----------------* Deal with customer information *---------------------------
3752     get_customer_info (p_claim => l_claim,
3753                        x_claim => l_complete_claim,
3754                        x_return_status  => l_return_status);
3755     IF l_return_status = FND_API.g_ret_sts_error THEN
3756        RAISE FND_API.g_exc_error;
3757     ELSIF l_return_status = FND_API.g_ret_sts_unexp_error THEN
3758        RAISE FND_API.g_exc_unexpected_error;
3759     END IF;
3760 
3761     l_claim := l_complete_claim;
3762 
3763     -- Default broker if it's null
3764 --    IF (l_claim.BROKER_ID is null OR
3765 --        l_claim.broker_id = FND_API.G_MISS_NUM)THEN
3766 --       OPEN broker_id_csr(l_claim.cust_account_id);
3767 --       FETCH broker_id_csr INTO l_broker_id;
3768 --       CLOSE broker_id_csr;
3769 --       l_claim.broker_id := l_broker_id;
3770 --    END IF;
3771     -----------------* End of customer information *---------------------------
3772 
3773     -- if owner is specified, I will add it to the access list.
3774     -- else I will check if the auto assign flag is turned on.
3775     --      If it is then call the get owner routine.
3776     --      If there is still no owner after this. get the owner from sys parameter and add it to access list
3777 
3778     IF (l_claim.owner_id is not null AND
3779         l_claim.owner_id <> FND_API.G_MISS_NUM) THEN
3780 
3781         l_access_list(1).arc_act_access_to_object := G_CLAIM_OBJECT_TYPE;
3782         l_access_list(1).user_or_role_id := l_claim.owner_id;
3783         l_access_list(1).arc_user_or_role_type := 'USER';
3784         l_access_list(1).admin_flag := 'Y';
3785         l_access_list(1).owner_flag := 'Y';
3786         l_access_list(1).act_access_to_object_id := l_claim_id;
3787     ELSE
3788 
3789       -- Default owner_id if Auto assign is turned on
3790 
3791       OPEN auto_assign_flag_csr;
3792       FETCH auto_assign_flag_csr INTO l_auto_assign_flag;
3793       CLOSE auto_assign_flag_csr;
3794 
3795       IF l_auto_assign_flag = 'T' THEN
3796 
3797          get_owner (p_claim_type_id   => l_claim.claim_type_id,
3798                   p_claim_id        => l_claim.claim_id,
3799                   p_reason_code_id  => l_claim.reason_code_id,
3800                   p_vendor_id       => l_claim.vendor_id,
3801                   p_vendor_site_id  => l_claim.vendor_site_id,
3802                   p_cust_account_id => l_claim.cust_account_id,
3803                   p_billto_site_id  => l_claim.cust_billto_acct_site_id,
3804                   p_shipto_site_id  => l_claim.cust_shipto_acct_site_id,
3805                   p_claim_class     => l_claim.claim_class,
3806                   x_owner_id        => l_default_owner, --l_claim.owner_id, [BUG 3835800 Fixing]
3807                   x_access_list     => l_access_list,
3808                   x_return_status   => l_return_status);
3809          IF l_return_status = FND_API.g_ret_sts_error THEN
3810             RAISE FND_API.g_exc_error;
3811          ELSIF l_return_status = FND_API.g_ret_sts_unexp_error THEN
3812             RAISE FND_API.g_exc_unexpected_error;
3813          END IF;
3814          l_claim.owner_id := l_default_owner; -- [BUG 3835800 Fixing]
3815       END IF;
3816       IF (l_claim.owner_id is null OR
3817           l_claim.owner_id = FND_API.G_MISS_NUM) THEN
3818           OPEN default_owner_id_csr;
3819           FETCH default_owner_id_csr into l_claim.owner_id;
3820           CLOSE default_owner_id_csr;
3821 
3822           -- Now we need to add the owner to the access list
3823           IF l_access_list.count = 0 THEN
3824              l_last_index :=1;
3825           ELSE
3826              l_last_index := l_access_list.LAST +1;
3827           END IF;
3828           l_access_list(l_last_index).arc_act_access_to_object := G_CLAIM_OBJECT_TYPE;
3829           l_access_list(l_last_index).user_or_role_id := l_claim.owner_id;
3830           l_access_list(l_last_index).arc_user_or_role_type := 'USER';
3831           l_access_list(l_last_index).admin_flag := 'Y';
3832           l_access_list(l_last_index).owner_flag := 'Y';
3833           l_access_list(l_last_index).act_access_to_object_id := l_claim_id;
3834       END IF;
3835     END IF;
3836 
3837   -- R12 Enhancements
3838   -- Add creator for to access list
3839 
3840     IF l_access_list.count = 0 THEN
3841         l_last_index :=1;
3842     ELSE
3843         l_last_index := l_access_list.LAST +1;
3844     END IF;
3845 
3846     IF  l_claim.created_from = 'MASS_CREATE' THEN
3847         l_access_list(l_last_index).arc_act_access_to_object := G_CLAIM_OBJECT_TYPE;
3848         l_access_list(l_last_index).user_or_role_id := OZF_UTILITY_PVT.get_resource_id(FND_GLOBAL.user_id) ;
3849         l_access_list(l_last_index).arc_user_or_role_type := 'USER';
3850         l_access_list(l_last_index).admin_flag := 'Y';
3851         l_access_list(l_last_index).owner_flag := 'N';
3852         l_access_list(l_last_index).act_access_to_object_id := l_claim_id;
3853 
3854     END IF;
3855 
3856     --Calculate amounts
3857     l_claim.amount_adjusted := 0;
3858     l_claim.amount_settled := 0;
3859     l_claim.acctd_amount_adjusted := 0;
3860     l_claim.acctd_amount_settled := 0;
3861 
3862     IF (l_claim.amount is NULL OR
3863         l_claim.amount = FND_API.G_MISS_NUM) THEN
3864        l_claim.amount := 0;
3865     END IF;
3866     l_claim.amount_remaining := l_claim.amount;
3867 
3868     -- get functional currency code
3869     OPEN  gp_func_currency_cd_csr;
3870     FETCH gp_func_currency_cd_csr INTO l_functional_currency_code;
3871     CLOSE gp_func_currency_cd_csr;
3872 
3873     -- Default the transaction currency code to functional currency code
3874     -- if it's null.
3875     IF (l_claim.currency_code is NULL OR
3876         l_claim.currency_code = FND_API.G_MISS_CHAR)THEN
3877        l_claim.currency_code := l_functional_currency_code;
3878     END IF;
3879 
3880     -- If transaction currency_code is different from functional currency_code,
3881     -- We need to make sure that exchange_type is not null
3882     IF l_claim.currency_code <> l_functional_currency_code THEN
3883        IF  l_claim.exchange_rate_type is null OR
3884            l_claim.exchange_rate_type = FND_API.G_MISS_CHAR THEN
3885            OPEN exchange_rate_type_csr;
3886            FETCH exchange_rate_type_csr into l_claim.exchange_rate_type;
3887            CLOSE exchange_rate_type_csr;
3888 
3889            IF  l_claim.exchange_rate_type is null OR
3890                l_claim.exchange_rate_type = FND_API.G_MISS_CHAR THEN
3891                IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_error) THEN
3892                   fnd_message.set_name('OZF', 'OZF_CLAIM_CONTYPE_MISSING');
3893                   fnd_msg_pub.add;
3894                END IF;
3895                RAISE fnd_api.g_exc_error;
3896            END IF;
3897        END IF;
3898 
3899 
3900        IF l_claim.exchange_rate_date is null OR
3901           l_claim.exchange_rate_date = FND_API.G_MISS_DATE THEN
3902 
3903           -- Default exchange_rate_date to sysdate
3904           l_claim.exchange_rate_date := SYSDATE;
3905        END IF;
3906 
3907     ELSE
3908        l_claim.exchange_rate_type := null;
3909        l_claim.exchange_rate_date := null;
3910        l_claim.exchange_rate :=1;
3911     END IF;
3912 
3913     IF OZF_DEBUG_HIGH_ON THEN
3914        ozf_utility_PVT.debug_message('rate_type:'||l_claim.exchange_rate_type);
3915     END IF;
3916 
3917     IF (l_claim.amount <> 0 )THEN
3918        OZF_UTILITY_PVT.Convert_Currency(
3919            P_SET_OF_BOOKS_ID => l_claim.set_of_books_id,
3920            P_FROM_CURRENCY   => l_claim.currency_code,
3921            P_CONVERSION_DATE => l_claim.exchange_rate_date,
3922            P_CONVERSION_TYPE => l_claim.exchange_rate_type,
3923            P_CONVERSION_RATE => l_claim.exchange_rate,
3924            P_AMOUNT          => l_claim.amount,
3925            X_RETURN_STATUS   => l_return_status,
3926            X_ACC_AMOUNT      => l_acc_amount,
3927            X_RATE            => l_rate);
3928            IF l_return_status = FND_API.g_ret_sts_error THEN
3929               RAISE FND_API.g_exc_error;
3930            ELSIF l_return_status = FND_API.g_ret_sts_unexp_error THEN
3931               RAISE FND_API.g_exc_unexpected_error;
3932            END IF;
3933        l_claim.exchange_rate := l_rate;
3934        l_claim.ACCTD_AMOUNT := l_acc_amount;
3935        l_claim.ACCTD_AMOUNT_REMAINING := l_acc_amount;
3936     ELSE
3937        l_claim.acctd_amount :=l_claim.amount;
3938        l_claim.acctd_amount_remaining := l_claim.amount;
3939     END IF;
3940 
3941     -- We need to round the amount and account_amount according to the currency.
3942     l_claim.amount := OZF_UTILITY_PVT.CurrRound(l_claim.amount, l_claim.currency_code);
3943     l_claim.amount_remaining := OZF_UTILITY_PVT.CurrRound(l_claim.amount_remaining, l_claim.currency_code);
3944     l_claim.acctd_amount := OZF_UTILITY_PVT.CurrRound(l_claim.acctd_amount,l_functional_currency_code);
3945     l_claim.acctd_amount_remaining := OZF_UTILITY_PVT.CurrRound(l_claim.acctd_amount_remaining, l_functional_currency_code);
3946 
3947 
3948     --Default the Claim_id only if the in coming claim_id is null.
3949     IF l_claim.claim_id is NULL
3950     OR l_claim.claim_id = FND_API.G_MISS_NUM
3951     THEN
3952        --fetch claim_id
3953        OPEN claim_id_csr;
3954        FETCH claim_id_csr INTO l_claim_id;
3955        CLOSE claim_id_csr;
3956 
3957        LOOP
3958          -- Get the identifier
3959          OPEN claim_id_csr;
3960             FETCH claim_id_csr INTO l_claim_id;
3961             CLOSE claim_id_csr;
3962 
3963             -- Check the uniqueness of the identifier
3964             OPEN  claim_id_count_csr(l_claim_id);
3965             FETCH claim_id_count_csr INTO l_claim_id_count;
3966             CLOSE claim_id_count_csr;
3967             -- Exit when the identifier uniqueness is established
3968             EXIT WHEN l_claim_id_count = 0;
3969        END LOOP;
3970        l_claim.claim_id := l_claim_id;
3971     END IF;
3972 
3973     --set it back to l_claim_id to ensure that it is set properly, as it is accessed at serveral places
3974     --down the line.
3975     l_claim_id := l_claim.claim_id;
3976 
3977     -- default root_claim_id
3978     IF l_claim.root_claim_id is NULL OR
3979        l_claim.root_claim_id = FND_API.G_MISS_NUM THEN
3980        l_claim.root_claim_id := l_claim_id;
3981     END IF;
3982 
3983     -- END of default
3984 
3985     -- normalize customer reference number if it isn't null
3986     IF l_claim.customer_ref_number is not NULL AND
3987        l_claim.customer_ref_number <> FND_API.G_MISS_CHAR THEN
3988        OZF_Claim_Utility_PVT.Normalize_Customer_Reference(
3989           p_customer_reference   => l_claim.customer_ref_number,
3990           x_normalized_reference => l_customer_ref_norm
3991        );
3992     END IF;
3993 
3994     -- Validate Claim
3995     Validate_Claim (
3996        p_api_version       => l_api_version,
3997        p_init_msg_list     => p_init_msg_list,
3998        p_validation_level  => p_validation_level,
3999        x_return_status     => l_return_status,
4000        x_msg_count         => l_msg_count,
4001        x_msg_data          => l_msg_data,
4002        p_claim             => l_claim
4003     );
4004 
4005     IF l_return_status = FND_API.G_RET_STS_ERROR THEN
4006         RAISE FND_API.G_EXC_ERROR;
4007     ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4008         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4009     END IF;
4010 
4011 -- -------------------------------------------------------------------------------------------
4012     -- Bug        : 2781186
4013     -- Changed by : (Uday Poluri)  Date: 03-JUN-2003
4014     -- Comments   : In case of creatiion of cliam pass receipt info to applied receipt info
4015     -- -------------------------------------------------------------------------------------------
4016     --l_claim.AMOUNT_APPLIED         := l_claim.AMOUNT; --This needs to come from AR.
4017     l_claim.APPLIED_RECEIPT_ID     := l_claim.RECEIPT_ID;
4018     l_claim.APPLIED_RECEIPT_NUMBER := l_claim.RECEIPT_NUMBER;
4019 
4020     -- End Bug:2781186 ---------------------------------------------------------------------------
4021 
4022     BEGIN
4023        OZF_claims_PKG.Insert_Row(
4024           px_CLAIM_ID => l_claim_id,
4025           px_OBJECT_VERSION_NUMBER => l_object_version_number,
4026           p_LAST_UPDATE_DATE => SYSDATE,
4027           p_LAST_UPDATED_BY => NVL(FND_GLOBAL.user_id,-1),
4028           p_CREATION_DATE => SYSDATE,
4029           p_CREATED_BY => NVL(FND_GLOBAL.user_id,-1),
4030           p_LAST_UPDATE_LOGIN => NVL(FND_GLOBAL.conc_login_id,-1),
4031           p_REQUEST_ID => FND_GLOBAL.CONC_REQUEST_ID,
4032           p_PROGRAM_APPLICATION_ID => FND_GLOBAL.PROG_APPL_ID,
4033           p_PROGRAM_UPDATE_DATE => SYSDATE,
4034           p_PROGRAM_ID => FND_GLOBAL.CONC_PROGRAM_ID,
4035           p_CREATED_FROM => l_claim.CREATED_FROM,
4036           p_BATCH_ID => l_claim.BATCH_ID,
4037           p_CLAIM_NUMBER => l_claim.CLAIM_NUMBER,
4038           p_CLAIM_TYPE_ID => l_claim.CLAIM_TYPE_ID,
4039           p_CLAIM_CLASS  => l_claim.CLAIM_CLASS,
4040           p_CLAIM_DATE => l_claim.CLAIM_DATE,
4041           p_DUE_DATE => l_claim.DUE_DATE,
4042           p_OWNER_ID   => l_claim.owner_id,
4043           p_HISTORY_EVENT => G_NEW_EVENT,
4044           p_HISTORY_EVENT_DATE => sysdate,
4045           p_HISTORY_EVENT_DESCRIPTION => G_CREATION_EVENT_DESC,
4046           p_SPLIT_FROM_CLAIM_ID => l_claim.SPLIT_FROM_CLAIM_ID,
4047           p_duplicate_claim_id  => l_claim.duplicate_claim_id,
4048           p_SPLIT_DATE => l_claim.SPLIT_DATE,
4049           p_ROOT_CLAIM_ID  => l_claim.ROOT_CLAIM_ID,
4050           p_AMOUNT => l_claim.AMOUNT,
4051           p_AMOUNT_ADJUSTED => l_claim.AMOUNT_ADJUSTED,
4052           p_AMOUNT_REMAINING => l_claim.AMOUNT_REMAINING,
4053           p_AMOUNT_SETTLED => l_claim.AMOUNT_SETTLED,
4054           p_ACCTD_AMOUNT => l_claim.ACCTD_AMOUNT,
4055           p_acctd_amount_remaining  => l_claim.acctd_amount_remaining,
4056           p_acctd_AMOUNT_ADJUSTED => l_claim.acctd_AMOUNT_ADJUSTED,
4057           p_acctd_AMOUNT_SETTLED => l_claim.acctd_AMOUNT_SETTLED,
4058           p_tax_amount  => l_claim.tax_amount,
4059           p_tax_code  => l_claim.tax_code,
4060           p_tax_calculation_flag  => l_claim.tax_calculation_flag,
4061           p_CURRENCY_CODE => l_claim.CURRENCY_CODE,
4062           p_EXCHANGE_RATE_TYPE => l_claim.EXCHANGE_RATE_TYPE,
4063           p_EXCHANGE_RATE_DATE => l_claim.EXCHANGE_RATE_DATE,
4064           p_EXCHANGE_RATE => l_claim.EXCHANGE_RATE,
4065           p_SET_OF_BOOKS_ID => l_claim.SET_OF_BOOKS_ID,
4066           p_ORIGINAL_CLAIM_DATE => l_claim.ORIGINAL_CLAIM_DATE,
4067           p_SOURCE_OBJECT_ID => l_claim.SOURCE_OBJECT_ID,
4068           p_SOURCE_OBJECT_CLASS => l_claim.SOURCE_OBJECT_CLASS,
4069           p_SOURCE_OBJECT_TYPE_ID => l_claim.SOURCE_OBJECT_TYPE_ID,
4070           p_SOURCE_OBJECT_NUMBER => l_claim.SOURCE_OBJECT_NUMBER,
4071           p_CUST_ACCOUNT_ID => l_claim.CUST_ACCOUNT_ID,
4072           p_CUST_BILLTO_ACCT_SITE_ID => l_claim.CUST_BILLTO_ACCT_SITE_ID,
4073           P_CUST_SHIPTO_ACCT_SITE_ID  => L_CLAIM.CUST_SHIPTO_ACCT_SITE_ID,
4074           p_LOCATION_ID => l_claim.LOCATION_ID,
4075           p_PAY_RELATED_ACCOUNT_FLAG  => l_claim.PAY_RELATED_ACCOUNT_FLAG,
4076           p_RELATED_CUST_ACCOUNT_ID  => l_claim.related_cust_account_id,
4077           p_RELATED_SITE_USE_ID  => l_claim.RELATED_SITE_USE_ID,
4078           p_RELATIONSHIP_TYPE  => l_claim.RELATIONSHIP_TYPE,
4079           p_VENDOR_ID  => l_claim.VENDOR_ID,
4080           p_VENDOR_SITE_ID  => l_claim.VENDOR_SITE_ID,
4081           p_REASON_TYPE => l_claim.REASON_TYPE,
4082           p_REASON_CODE_ID => l_claim.REASON_CODE_ID,
4083           p_TASK_TEMPLATE_GROUP_ID  => l_claim.TASK_TEMPLATE_GROUP_ID,
4084           p_STATUS_CODE => l_claim.STATUS_CODE,
4085           p_USER_STATUS_ID => l_claim.USER_STATUS_ID,
4086           p_SALES_REP_ID => l_claim.SALES_REP_ID,
4087           p_COLLECTOR_ID => l_claim.COLLECTOR_ID,
4088           p_CONTACT_ID => l_claim.CONTACT_ID,
4089           p_BROKER_ID => l_claim.BROKER_ID,
4090           p_TERRITORY_ID => l_claim.TERRITORY_ID,
4091           p_CUSTOMER_REF_DATE => l_claim.CUSTOMER_REF_DATE,
4092           p_CUSTOMER_REF_NUMBER => l_claim.CUSTOMER_REF_NUMBER,
4093           p_CUSTOMER_REF_NORMALIZED => l_customer_ref_norm,
4094           p_ASSIGNED_TO => l_claim.ASSIGNED_TO,
4095           p_RECEIPT_ID => l_claim.RECEIPT_ID,
4096           p_RECEIPT_NUMBER => l_claim.RECEIPT_NUMBER,
4097           p_DOC_SEQUENCE_ID => l_claim.DOC_SEQUENCE_ID,
4098           p_DOC_SEQUENCE_VALUE => l_claim.DOC_SEQUENCE_VALUE,
4099           p_GL_DATE    => l_claim.gl_date,
4100           p_PAYMENT_METHOD => l_claim.PAYMENT_METHOD,
4101           p_VOUCHER_ID => l_claim.VOUCHER_ID,
4102           p_VOUCHER_NUMBER => l_claim.VOUCHER_NUMBER,
4103           p_PAYMENT_REFERENCE_ID => l_claim.PAYMENT_REFERENCE_ID,
4104           p_PAYMENT_REFERENCE_NUMBER => l_claim.PAYMENT_REFERENCE_NUMBER,
4105           p_PAYMENT_REFERENCE_DATE => l_claim.PAYMENT_REFERENCE_DATE,
4106           p_PAYMENT_STATUS => l_claim.PAYMENT_STATUS,
4107           p_APPROVED_FLAG => l_claim.APPROVED_FLAG,
4108           p_APPROVED_DATE => l_claim.APPROVED_DATE,
4109           p_APPROVED_BY => l_claim.APPROVED_BY,
4110           p_SETTLED_DATE => l_claim.SETTLED_DATE,
4111           p_SETTLED_BY => l_claim.SETTLED_BY,
4112           p_effective_date  => l_claim.effective_date,
4113           p_CUSTOM_SETUP_ID  => l_claim.CUSTOM_SETUP_ID,
4114           p_TASK_ID  => l_claim.TASK_ID,
4115           p_COUNTRY_ID  => l_claim.COUNTRY_ID,
4116           p_ORDER_TYPE_ID  => l_claim.ORDER_TYPE_ID,
4117           p_COMMENTS   => l_claim.COMMENTS,
4118           p_ATTRIBUTE_CATEGORY => l_claim.ATTRIBUTE_CATEGORY,
4119           p_ATTRIBUTE1 => l_claim.ATTRIBUTE1,
4120           p_ATTRIBUTE2 => l_claim.ATTRIBUTE2,
4121           p_ATTRIBUTE3 => l_claim.ATTRIBUTE3,
4122           p_ATTRIBUTE4 => l_claim.ATTRIBUTE4,
4123           p_ATTRIBUTE5 => l_claim.ATTRIBUTE5,
4124           p_ATTRIBUTE6 => l_claim.ATTRIBUTE6,
4125           p_ATTRIBUTE7 => l_claim.ATTRIBUTE7,
4126           p_ATTRIBUTE8 => l_claim.ATTRIBUTE8,
4127           p_ATTRIBUTE9 => l_claim.ATTRIBUTE9,
4128           p_ATTRIBUTE10 => l_claim.ATTRIBUTE10,
4129           p_ATTRIBUTE11 => l_claim.ATTRIBUTE11,
4130           p_ATTRIBUTE12 => l_claim.ATTRIBUTE12,
4131           p_ATTRIBUTE13 => l_claim.ATTRIBUTE13,
4132           p_ATTRIBUTE14 => l_claim.ATTRIBUTE14,
4133           p_ATTRIBUTE15 => l_claim.ATTRIBUTE15,
4134           p_DEDUCTION_ATTRIBUTE_CATEGORY  => l_claim.DEDUCTION_ATTRIBUTE_CATEGORY,
4135           p_DEDUCTION_ATTRIBUTE1  => l_claim.DEDUCTION_ATTRIBUTE1,
4136           p_DEDUCTION_ATTRIBUTE2  => l_claim.DEDUCTION_ATTRIBUTE2,
4137           p_DEDUCTION_ATTRIBUTE3  => l_claim.DEDUCTION_ATTRIBUTE3,
4138           p_DEDUCTION_ATTRIBUTE4  => l_claim.DEDUCTION_ATTRIBUTE4,
4139           p_DEDUCTION_ATTRIBUTE5  => l_claim.DEDUCTION_ATTRIBUTE5,
4140           p_DEDUCTION_ATTRIBUTE6  => l_claim.DEDUCTION_ATTRIBUTE6,
4141           p_DEDUCTION_ATTRIBUTE7  => l_claim.DEDUCTION_ATTRIBUTE7,
4142           p_DEDUCTION_ATTRIBUTE8  => l_claim.DEDUCTION_ATTRIBUTE8,
4143           p_DEDUCTION_ATTRIBUTE9  => l_claim.DEDUCTION_ATTRIBUTE9,
4144           p_DEDUCTION_ATTRIBUTE10  => l_claim.DEDUCTION_ATTRIBUTE10,
4145           p_DEDUCTION_ATTRIBUTE11  => l_claim.DEDUCTION_ATTRIBUTE11,
4146           p_DEDUCTION_ATTRIBUTE12  => l_claim.DEDUCTION_ATTRIBUTE12,
4147           p_DEDUCTION_ATTRIBUTE13  => l_claim.DEDUCTION_ATTRIBUTE13,
4148           p_DEDUCTION_ATTRIBUTE14  => l_claim.DEDUCTION_ATTRIBUTE14,
4149           p_DEDUCTION_ATTRIBUTE15  => l_claim.DEDUCTION_ATTRIBUTE15,
4150           px_ORG_ID =>  l_org_id,
4151 	  p_LEGAL_ENTITY_ID   => l_claim.legal_entity_id,
4152           p_WRITE_OFF_FLAG =>  l_claim.WRITE_OFF_FLAG,
4153           p_WRITE_OFF_THRESHOLD_AMOUNT =>  l_claim.WRITE_OFF_THRESHOLD_AMOUNT,
4154           p_UNDER_WRITE_OFF_THRESHOLD =>  l_claim.UNDER_WRITE_OFF_THRESHOLD,
4155           p_CUSTOMER_REASON =>  l_claim.CUSTOMER_REASON,
4156           p_SHIP_TO_CUST_ACCOUNT_ID => l_claim.SHIP_TO_CUST_ACCOUNT_ID,
4157           p_AMOUNT_APPLIED             => l_claim.AMOUNT_APPLIED,              --BUG:2781186
4158           p_APPLIED_RECEIPT_ID         => l_claim.APPLIED_RECEIPT_ID,          --BUG:2781186
4159           p_APPLIED_RECEIPT_NUMBER     => l_claim.APPLIED_RECEIPT_NUMBER,       --BUG:2781186
4160           p_WO_REC_TRX_ID              => l_claim.WO_REC_TRX_ID,                --Write-off Activity
4161           p_GROUP_CLAIM_ID             => l_claim.GROUP_CLAIM_ID,
4162           p_APPR_WF_ITEM_KEY           => l_claim.APPR_WF_ITEM_KEY,
4163           p_CSTL_WF_ITEM_KEY           => l_claim.CSTL_WF_ITEM_KEY,
4164           p_BATCH_TYPE                 => l_claim.BATCH_TYPE,
4165           p_OPEN_STATUS_ID             => l_claim.open_status_id,
4166           p_close_status_id             => l_claim.close_status_id
4167        );
4168     EXCEPTION
4169        WHEN OTHERS THEN
4170           IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
4171              FND_MESSAGE.set_name('OZF', 'OZF_TABLE_HANDLER_ERROR');
4172              FND_MSG_PUB.add;
4173           END IF;
4174           RAISE FND_API.g_exc_error;
4175     END;
4176 
4177     --  Create Tasks for the claim created if task_template_group_id is not null
4178     IF (l_claim.task_template_group_id is not NULL AND
4179         l_claim.task_template_group_id <> FND_API.G_MISS_NUM ) THEN
4180 
4181         generate_tasks(
4182           p_task_template_group_id => l_claim.task_template_group_id
4183          ,p_owner_id       => l_claim.owner_id
4184          ,p_claim_number   => l_claim.claim_number
4185          ,p_claim_id       => l_claim_id
4186          ,x_return_status  => l_return_status
4187         );
4188 
4189        IF OZF_DEBUG_LOW_ON THEN
4190           FND_MESSAGE.Set_Name('OZF','OZF_API_DEBUG_MESSAGE');
4191           FND_MESSAGE.Set_Token('TEXT','After generate_task: '|| l_return_status);
4192           FND_MSG_PUB.Add;
4193        END IF;
4194     END IF;
4195 
4196     IF l_return_status = FND_API.g_ret_sts_error THEN
4197        RAISE FND_API.g_exc_error;
4198     ELSIF l_return_status = FND_API.g_ret_sts_unexp_error THEN
4199        RAISE FND_API.g_exc_unexpected_error;
4200     END IF;
4201 
4202     -- This loop should always run
4203     IF l_access_list.count > 0 THEN
4204        -- [BEGIN OF BUG 3835800 Fiing]
4205        l_access_comp_list := l_access_list;
4206        For i in 1..l_access_list.LAST LOOP
4207          IF i > 1 THEN
4208             FOR j IN 1..(i-1) LOOP
4209                IF l_access_list(i).user_or_role_id = l_access_comp_list(j).user_or_role_id THEN
4210                   l_dup_resource := TRUE;
4211                END IF;
4212             END LOOP;
4213          END IF;
4214 
4215          IF NOT l_dup_resource THEN
4216          -- [END OF BUG 3835800 Fiing]
4217            l_access_list(i).act_access_to_object_id := l_claim_id;
4218            ams_access_pvt.create_access(
4219                p_api_version => l_api_version
4220               ,p_init_msg_list => fnd_api.g_false
4221               ,p_validation_level => p_validation_level
4222               ,x_return_status => l_return_status
4223               ,x_msg_count => x_msg_count
4224               ,x_msg_data => x_msg_data
4225               ,p_commit => fnd_api.g_false
4226               ,p_access_rec => l_access_list(i)
4227               ,x_access_id => l_access_id);
4228            IF l_return_status = fnd_api.g_ret_sts_error THEN
4229               RAISE fnd_api.g_exc_error;
4230            ELSIF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
4231               RAISE fnd_api.g_exc_unexpected_error;
4232            END IF;
4233          END IF; -- end of l_dup_resource checking BUG 3835800 Fixing
4234       END LOOP;
4235     END IF;
4236 
4237     -- pass claim id
4238     x_claim_id := l_claim_id;
4239 
4240     --create history call (uday)
4241     Create_Claim_History (
4242            p_api_version    => l_api_version
4243           ,p_init_msg_list  => FND_API.G_FALSE
4244           ,p_commit         => FND_API.G_FALSE
4245           ,p_validation_level => FND_API.G_VALID_LEVEL_FULL
4246           ,x_return_status  => l_return_status
4247           ,x_msg_data       => l_msg_data
4248           ,x_msg_count      => l_msg_count
4249           ,p_claim          => l_claim
4250           ,p_event          => G_NEW_EVENT
4251           ,x_need_to_create => l_need_to_create
4252           ,x_claim_history_id => l_claim_history_id
4253     );
4254     IF l_return_status = FND_API.g_ret_sts_error THEN
4255        RAISE FND_API.g_exc_error;
4256     ELSIF l_return_status = FND_API.g_ret_sts_unexp_error THEN
4257        RAISE FND_API.g_exc_unexpected_error;
4258     END IF;
4259     --end of history call (uday)
4260 
4261    --------------------------
4262    -- Raise Business Event --
4263    --------------------------
4264    OZF_CLAIM_SETTLEMENT_PVT.Raise_Business_Event(
4265        p_api_version            => l_api_version
4266       ,p_init_msg_list          => FND_API.g_false
4267       ,p_commit                 => FND_API.g_false
4268       ,p_validation_level       => FND_API.g_valid_level_full
4269       ,x_return_status          => l_return_status
4270       ,x_msg_data               => x_msg_data
4271       ,x_msg_count              => x_msg_count
4272 
4273       ,p_claim_id               => l_claim_id
4274       ,p_old_status             => NULL
4275       ,p_new_status             => l_claim.status_code
4276       ,p_event_name             => 'oracle.apps.ozf.claim.create'
4277    );
4278    IF l_return_status = FND_API.g_ret_sts_error THEN
4279       RAISE FND_API.g_exc_error;
4280    ELSIF l_return_status = FND_API.g_ret_sts_unexp_error THEN
4281       RAISE FND_API.g_exc_unexpected_error;
4282    END IF;
4283 
4284 
4285     --Standard check of commit
4286     IF FND_API.To_Boolean ( p_commit ) THEN
4287         COMMIT WORK;
4288     END IF;
4289     -- Debug Message
4290     IF OZF_DEBUG_LOW_ON THEN
4291         FND_MESSAGE.Set_Name('OZF','OZF_API_DEBUG_MESSAGE');
4292         FND_MESSAGE.Set_Token('TEXT',l_full_name||': End');
4293         FND_MSG_PUB.Add;
4294     END IF;
4295 
4296     --Standard call to get message count AND if count=1, get the message
4297     FND_MSG_PUB.Count_And_Get (
4298         p_encoded => FND_API.G_FALSE,
4299         p_count => x_msg_count,
4300         p_data  => x_msg_data
4301     );
4302 EXCEPTION
4303    WHEN FND_API.G_EXC_ERROR THEN
4304       ROLLBACK TO  Create_Claim_PVT;
4305       x_return_status := FND_API.G_RET_STS_ERROR;
4306       -- Standard call to get message count AND if count=1, get the message
4307       FND_MSG_PUB.Count_And_Get (
4308          p_encoded => FND_API.G_FALSE,
4309          p_count => x_msg_count,
4310          p_data  => x_msg_data
4311       );
4312    WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
4313       ROLLBACK TO  Create_Claim_PVT;
4314       x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4315       -- Standard call to get message count AND if count=1, get the message
4316       FND_MSG_PUB.Count_And_Get (
4317          p_encoded => FND_API.G_FALSE,
4318          p_count => x_msg_count,
4319          p_data  => x_msg_data
4320       );
4321    WHEN OTHERS THEN
4322       ROLLBACK TO  Create_Claim_PVT;
4323       x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4324       IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
4325          FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
4326       END IF;
4327       -- Standard call to get message count AND if count=1, get the message
4328       FND_MSG_PUB.Count_And_Get (
4329          p_encoded => FND_API.G_FALSE,
4330          p_count => x_msg_count,
4331          p_data  => x_msg_data
4332       );
4333 END Create_Claim;
4334 
4335 ---------------------------------------------------------------------
4336 -- PROCEDURE
4337 --    Validate_Delete_Claim
4338 --
4339 -- PURPOSE
4340 --    This procedure identify the list of deletable or non deletalbe dependent object
4341 --    for a claim.
4342 --
4343 -- PARAMETERS
4344 --    p_object_id                  IN   NUMBER,
4345 --    p_object_version_number      IN   NUMBER,
4346 --    x_dependent_object_tbl       OUT  ozf_utility_pvt.dependent_objects_tbl_type
4347 --
4348 -- We will only delete claim with status of NEW.  At this stage, all dependent objects
4349 -- are deleteable and we don't have to worry about split and duplications.
4350 -- Also noted, we have not implemented Attachments and NOTES so far. Nor have I found
4351 -- any API to delete these two objects. Checks on these will have to be added later.
4352 -- So here I'm only add line and task information in the dependent objects table.
4353 
4354 --TYPE dependent_objects_rec_type IS RECORD
4355 -- view_name/table_name                ozf_claim_lines_b	jtf_tasks_v
4356 -- name                  VARCHAR2(240) line_number         Task_number
4357 --type                  VARCHAR2(30)  LINE						TASK
4358 --status                VARCHAR2(30)  NEW						Task_status
4359 --owner                 VARCHAR2(240) ozf_claims_v.owner_id	      owner
4360 --deletable_flag        VARCHAR2(1)   Y
4361 
4362 
4363 ---------------------------------------------------------------------
4364 PROCEDURE Validate_Delete_Claim (
4365     p_api_version_number         IN   NUMBER,
4366     p_init_msg_list              IN   VARCHAR2     := FND_API.G_FALSE,
4367     p_commit                     IN   VARCHAR2     := FND_API.G_FALSE,
4368     p_object_id                  IN   NUMBER,
4369     p_object_version_number      IN   NUMBER,
4370     x_dependent_object_tbl       OUT NOCOPY  ams_utility_pvt.dependent_objects_tbl_type,
4371     x_return_status              OUT NOCOPY  VARCHAR2,
4372     x_msg_count                  OUT NOCOPY  NUMBER,
4373     x_msg_data                   OUT NOCOPY  VARCHAR2
4374 ) IS
4375 l_api_name          CONSTANT VARCHAR2(30) := 'Validate_Delete_Claim';
4376 l_api_version       CONSTANT NUMBER := 1.0;
4377 l_full_name         CONSTANT VARCHAR2(60) := G_PKG_NAME ||'.'|| l_api_name;
4378 --
4379 l_return_status          varchar2(1);
4380 l_msg_data               varchar2(2000);
4381 l_msg_count              number;
4382 
4383 CURSOR claim_info_csr (p_id in number) IS
4384 SELECT object_version_number, owner_id, status_code
4385 FROM   ozf_claims_v
4386 WHERE  claim_id = p_id;
4387 l_object_version_number  number;
4388 l_status_code  varchar2(30);
4389 l_owner_id      number;
4390 
4391 CURSOR owner_name_csr(p_id in number) is
4392 SELECT FULL_NAME
4393 FROM AMS_JTF_RS_EMP_V
4394 WHERE RESOURCE_ID = p_id;
4395 l_owner_name varchar2(2000);
4396 
4397 CURSOR lines_info_csr(p_id in number)IS
4398 SELECT line_number
4399 FROM ozf_claim_lines
4400 WHERE claim_id = p_id;
4401 
4402 CURSOR line_count_csr(p_id in number)IS
4403 select count(*)
4404 from ozf_claim_lines
4405 where claim_id = p_id;
4406 l_line_count number :=0;
4407 
4408 TYPE lines_info_tbl_type is table of lines_info_csr%rowType INDEX BY BINARY_INTEGER;
4409 l_lines_info_tbl lines_info_tbl_type;
4410 
4411 CURSOR tasks_info_csr(p_id in number) IS
4412 SELECT jta.task_number,
4413               jtst.name task_status,
4414               substrb(jtf_task_utl.get_owner(jta.owner_type_code, jta.owner_id),1,239) owner_name
4415 FROM jtf_tasks_b jta,  jtf_task_statuses_tl jtst
4416 WHERE jta.source_object_type_code = G_CLAIM_TYPE
4417 AND   jta.source_object_id = p_id
4418 AND   jtst.language = userenv('lang')
4419 AND   jtst.task_status_id = jta.task_status_id;
4420 
4421 TYPE tasks_info_tbl_type is table of tasks_info_csr%rowType index by binary_integer;
4422 l_tasks_info_tbl tasks_info_tbl_type;
4423 
4424 CURSOR task_count_csr(p_id in number)IS
4425 select count(task_id)
4426 from jtf_tasks_b
4427 WHERE source_object_type_code = G_CLAIM_TYPE
4428 AND   source_object_id = p_id;
4429 l_task_count number :=0;
4430 
4431 l_index number := 1;
4432 l_rec_num number;
4433 BEGIN
4434     -- Standard begin of API savepoint
4435     SAVEPOINT Val_Delete_Claim_PVT;
4436     -- Standard call to check for call compatibility.
4437     IF NOT FND_API.Compatible_API_Call (
4438         l_api_version,
4439         p_api_version_number,
4440         l_api_name,
4441         G_PKG_NAME)
4442     THEN
4443         RAISE  FND_API.G_EXC_UNEXPECTED_ERROR;
4444     END IF;
4445     -- Debug Message
4446     IF OZF_DEBUG_LOW_ON THEN
4447         FND_MESSAGE.Set_Name('OZF','OZF_API_DEBUG_MESSAGE');
4448         FND_MESSAGE.Set_Token('TEXT',l_full_name||': Start');
4449         FND_MSG_PUB.Add;
4450     END IF;
4451     --Initialize message list if p_init_msg_list is TRUE.
4452     IF FND_API.To_Boolean (p_init_msg_list) THEN
4453         FND_MSG_PUB.initialize;
4454     END IF;
4455     -- Initialize API return status to sucess
4456     x_return_status := FND_API.G_RET_STS_SUCCESS;
4457 
4458     OPEN claim_info_csr(p_object_id);
4459     FETCH claim_info_csr INTO l_object_version_number, l_owner_id, l_status_code;
4460     CLOSE claim_info_csr;
4461 
4462     IF p_object_version_number = l_object_version_number THEN
4463        -- check the status of the claim. We can only delete a claim with status NEW
4464        IF l_status_code = G_INIT_STATUS THEN
4465 		    -- get owner name
4466 			 OPEN owner_name_csr(l_owner_id);
4467 			 FETCH owner_name_csr into l_owner_name;
4468 			 CLOSE owner_name_csr;
4469 
4470 			 -- get claim_line_info
4471 			 open line_count_csr(p_object_id);
4472 			 fetch line_count_csr into l_line_count;
4473                          close line_count_csr;
4474 
4475 			 IF l_line_count > 0 THEN
4476 			    l_rec_num := 1;
4477 			    OPEN lines_info_csr(p_object_id);
4478 			    LOOP
4479 			       EXIT WHEN lines_info_csr%NOTFOUND;
4480                                FETCH lines_info_csr INTO l_lines_info_tbl(l_rec_num);
4481                                l_rec_num := l_rec_num + 1;
4482                             END LOOP;
4483 			    CLOSE lines_info_csr;
4484 
4485                             For i in 1..l_lines_info_tbl.LAST LOOP
4486 			            x_dependent_object_tbl(i).name:= l_lines_info_tbl(i).line_number;
4487 				    x_dependent_object_tbl(i).type:= ams_utility_pvt.get_lookup_meaning('AMS_SYS_ARC_QUALIFIER', G_CLAIM_LINE_OBJECT_TYPE);
4488 				    x_dependent_object_tbl(i).status:= l_status_code;
4489 				    x_dependent_object_tbl(i).owner:= l_owner_name;
4490 				    x_dependent_object_tbl(i).deletable_flag:= G_YES;
4491 			    END LOOP;
4492 			    l_index := l_lines_info_tbl.LAST +1;
4493                        END IF;
4494 
4495 
4496 			-- get tasks info
4497 			l_rec_num := 1;
4498 			open task_count_csr(p_object_id);
4499 			fetch task_count_csr into l_task_count;
4500                          close task_count_csr;
4501 
4502 			 IF l_task_count > 0 THEN
4503 			    OPEN tasks_info_csr(p_object_id);
4504 			    LOOP
4505 			             EXIT WHEN tasks_info_csr%NOTFOUND;
4506                                      FETCH tasks_info_csr INTO l_tasks_info_tbl(l_rec_num);
4507                                      l_rec_num := l_rec_num + 1;
4508                             END LOOP;
4509 			    CLOSE tasks_info_csr;
4510 
4511                            For i in 1..l_tasks_info_tbl.LAST LOOP
4512     		                    x_dependent_object_tbl(l_index).name:= l_tasks_info_tbl(i).task_number;
4513 				    x_dependent_object_tbl(l_index).type:= ams_utility_pvt.get_lookup_meaning('AMS_SYS_ARC_QUALIFIER', G_TASK_OBJECT_TYPE);
4514 				    x_dependent_object_tbl(l_index).status:= l_tasks_info_tbl(i).task_status;
4515 				    x_dependent_object_tbl(l_index).owner:= l_tasks_info_tbl(i).owner_name;
4516 				    x_dependent_object_tbl(l_index).deletable_flag:= G_YES;
4517 				    l_index := l_index +1;
4518 			    END LOOP;
4519 		        END IF;
4520         ELSE
4521              IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
4522                  FND_MESSAGE.set_name('OZF', 'OZF_CLAIM_CANT_DEL_CLAIM');
4523                 FND_MSG_PUB.add;
4524             END IF;
4525 	END IF;
4526     ELSE
4527        IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
4528           FND_MESSAGE.set_name('OZF', 'OZF_REC_VERSION_CHANGED');
4529           FND_MSG_PUB.add;
4530        END IF;
4531        RAISE FND_API.g_exc_error;
4532     END IF;
4533 
4534      --Standard check of commit
4535     IF FND_API.To_Boolean ( p_commit ) THEN
4536         COMMIT WORK;
4537     END IF;
4538     -- Debug Message
4539     IF OZF_DEBUG_LOW_ON THEN
4540         FND_MESSAGE.Set_Name('OZF','OZF_API_DEBUG_MESSAGE');
4541         FND_MESSAGE.Set_Token('TEXT',l_full_name||': End');
4542         FND_MSG_PUB.Add;
4543     END IF;
4544 
4545     --Standard call to get message count AND if count=1, get the message
4546     FND_MSG_PUB.Count_And_Get (
4547         p_encoded => FND_API.G_FALSE,
4548         p_count => x_msg_count,
4549         p_data  => x_msg_data
4550     );
4551 EXCEPTION
4552    WHEN FND_API.G_EXC_ERROR THEN
4553       ROLLBACK TO  Val_Delete_Claim_PVT;
4554       x_return_status := FND_API.G_RET_STS_ERROR;
4555       -- Standard call to get message count AND if count=1, get the message
4556       FND_MSG_PUB.Count_And_Get (
4557          p_encoded => FND_API.G_FALSE,
4558          p_count => x_msg_count,
4559          p_data  => x_msg_data
4560       );
4561    WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
4562       ROLLBACK TO  Val_Delete_Claim_PVT;
4563       x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4564       -- Standard call to get message count AND if count=1, get the message
4565       FND_MSG_PUB.Count_And_Get (
4566          p_encoded => FND_API.G_FALSE,
4567          p_count => x_msg_count,
4568          p_data  => x_msg_data
4569       );
4570    WHEN OTHERS THEN
4571       ROLLBACK TO  Val_Delete_Claim_PVT;
4572       x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4573       IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
4574          FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
4575       END IF;
4576       -- Standard call to get message count AND if count=1, get the message
4577       FND_MSG_PUB.Count_And_Get (
4578          p_encoded => FND_API.G_FALSE,
4579          p_count => x_msg_count,
4580          p_data  => x_msg_data
4581       );
4582 End Validate_Delete_Claim;
4583 
4584 ---------------------------------------------------------------------
4585 -- PROCEDURE
4586 --    Delete_Claim
4587 --
4588 -- PURPOSE
4589 --    Update a claim code.
4590 --
4591 -- PARAMETERS
4592 --    p_object_id   : the record with new items.
4593 --    p_object_version_number   : object version number
4594 --
4595 -- NOTES
4596 --    1. Raise exception if the object_version_number doesn't match.
4597 -- Also noted, we have not implemented Attachments and NOTES so far. Nor have I found
4598 -- any API to delete these two objects. Checks on these will have to be added later.
4599 ----------------------------------------------------------------------
4600 PROCEDURE  Delete_Claim (
4601     p_api_version_number     IN    NUMBER
4602    ,p_init_msg_list          IN    VARCHAR2 := FND_API.G_FALSE
4603    ,p_commit                 IN    VARCHAR2 := FND_API.G_FALSE
4604    ,p_object_id               IN    NUMBER
4605    ,p_object_version_number  IN    NUMBER
4606 	,x_return_status          OUT NOCOPY   VARCHAR2
4607    ,x_msg_count              OUT NOCOPY   NUMBER
4608 	,x_msg_data               OUT NOCOPY   VARCHAR2
4609 )
4610 
4611 IS
4612 l_api_name          CONSTANT VARCHAR2(30) := 'Delete_Claim';
4613 l_api_version       CONSTANT NUMBER := 1.0;
4614 l_full_name         CONSTANT VARCHAR2(60) := G_PKG_NAME ||'.'|| l_api_name;
4615 --
4616 l_resource_id       number;
4617 l_user_id           number;
4618 l_login_user_id     number;
4619 l_login_user_status      varchar2(30);
4620 l_Error_Msg              varchar2(2000);
4621 l_Error_Token            varchar2(80);
4622 
4623 l_return_status          varchar2(30);
4624 l_msg_data               varchar2(2000);
4625 l_msg_count              number;
4626 
4627 -- Fix for 5048675
4628 l_claim_history_id      number;
4629 l_claim_line_hist_id      number;
4630 
4631 CURSOR claim_info_csr (p_id in number) IS
4632 SELECT object_version_number, status_code
4633 FROM   ozf_claims_all
4634 WHERE  claim_id = p_id;
4635 l_object_version_number  number;
4636 l_status_code        varchar2(30);
4637 
4638 l_error_index number;
4639 l_claim_line_tbl  OZF_Claim_Line_PVT.claim_line_tbl_type;
4640 
4641 CURSOR claim_line_id_csr(p_id in number)is
4642 select claim_line_id, object_version_number
4643 from ozf_claim_lines_all
4644 where claim_id = p_id;
4645 
4646 l_claim_line_id number;
4647 l_line_object_version_number number;
4648 l_ind number :=1;
4649 
4650 CURSOR tasks_id_csr(p_id in number) IS
4651 SELECT task_id, object_version_number
4652 FROM jtf_tasks_b
4653 WHERE source_object_type_code = G_CLAIM_TYPE
4654 AND   source_object_id = p_id;
4655 
4656 -- Fix for 5048675
4657 CURSOR claim_history_id_csr(p_id in number) is
4658 select claim_history_id, object_version_number
4659 from ozf_claims_history_all
4660 where claim_id = p_id;
4661 
4662 CURSOR claim_line_his_id_csr(p_id in number) is
4663 select claim_line_history_id, object_version_number
4664 from OZF_CLAIM_LINES_HIST_ALL
4665 where claim_id = p_id;
4666 
4667 TYPE tasks_id_tbl_type is table of tasks_id_csr%rowType index by binary_integer;
4668 l_tasks_id_tbl tasks_id_tbl_type;
4669 
4670 l_rec_num number;
4671 --
4672 BEGIN
4673     -- Standard begin of API savepoint
4674     SAVEPOINT  Delete_Claim_PVT;
4675     -- Standard call to check for call compatibility.
4676     IF NOT FND_API.Compatible_API_Call (
4677         l_api_version,
4678         p_api_version_number,
4679         l_api_name,
4680         G_PKG_NAME)
4681     THEN
4682         RAISE  FND_API.G_EXC_UNEXPECTED_ERROR;
4683     END IF;
4684     -- Debug Message
4685     IF OZF_DEBUG_LOW_ON THEN
4686         FND_MESSAGE.Set_Name('OZF','OZF_API_DEBUG_MESSAGE');
4687         FND_MESSAGE.Set_Token('TEXT',l_full_name||': Start');
4688         FND_MSG_PUB.Add;
4689     END IF;
4690     --Initialize message list if p_init_msg_list is TRUE.
4691     IF FND_API.To_Boolean (p_init_msg_list) THEN
4692         FND_MSG_PUB.initialize;
4693     END IF;
4694     -- Initialize API return status to sucess
4695     x_return_status := FND_API.G_RET_STS_SUCCESS;
4696 
4697     OPEN claim_info_csr(p_object_id);
4698     FETCH claim_info_csr INTO l_object_version_number, l_status_code;
4699     CLOSE claim_info_csr;
4700 
4701     IF p_object_version_number = l_object_version_number THEN
4702        -- check the status of the claim. We can only delete a claim with status NEW
4703        IF l_status_code = G_INIT_STATUS THEN
4704 
4705           l_rec_num := 1;
4706           OPEN tasks_id_csr(p_object_id);
4707           LOOP
4708             FETCH tasks_id_csr INTO l_tasks_id_tbl(l_rec_num);
4709             EXIT WHEN tasks_id_csr%NOTFOUND;
4710             l_rec_num := l_rec_num + 1;
4711           END LOOP;
4712           CLOSE tasks_id_csr;
4713 
4714           For i in 1..l_tasks_id_tbl.count LOOP
4715              --  Leave p_object_version_number and p_delete_future_recurrences out for delete_task
4716              JTF_TASKS_PUB.delete_task(
4717                p_api_version           => l_api_version
4718               ,p_object_version_number => l_tasks_id_tbl(i).object_version_number
4719               ,p_task_id               => l_tasks_id_tbl(i).task_id
4720               ,p_delete_future_recurrences => FND_API.G_TRUE
4721               ,x_return_status         => l_return_status
4722               ,x_msg_count             => l_msg_count
4723               ,x_msg_data              => l_msg_data
4724              );
4725              IF l_return_status = FND_API.g_ret_sts_error THEN
4726                 RAISE FND_API.g_exc_error;
4727              ELSIF l_return_status = FND_API.g_ret_sts_unexp_error THEN
4728                 RAISE FND_API.g_exc_unexpected_error;
4729              END IF;
4730           END LOOP;
4731 
4732           -- Fix for 5048675
4733            -- delete claim history and claim line history records before deleting the claim records.
4734           OPEN claim_history_id_csr(p_object_id);
4735           LOOP
4736             FETCH claim_history_id_csr into l_claim_history_id, l_object_version_number;
4737             EXIT When claim_history_id_csr%NOTFOUND;
4738 
4739             OZF_claims_history_PVT.Delete_claims_history(
4740             P_Api_Version_Number         => l_api_version
4741             ,P_Init_Msg_List              => FND_API.g_false
4742             ,P_Commit                     => FND_API.g_false
4743             ,p_validation_level           => FND_API.g_valid_level_full
4744             ,X_Return_Status              => l_return_status
4745             ,X_Msg_Count                  => l_msg_count
4746             ,X_Msg_Data                   => l_msg_data
4747             ,P_CLAIM_HISTORY_ID           => l_claim_history_id
4748             ,P_Object_Version_Number      => l_object_version_number
4749             );
4750 
4751             IF l_return_status = FND_API.g_ret_sts_error THEN
4752                RAISE FND_API.g_exc_unexpected_error;
4753             ELSIF l_return_status = FND_API.g_ret_sts_unexp_error THEN
4754                RAISE FND_API.g_exc_unexpected_error;
4755             END IF;
4756           END LOOP;
4757           CLOSE claim_history_id_csr;
4758 
4759           -- delete claim line history
4760           OPEN claim_line_his_id_csr(p_object_id);
4761           LOOP
4762             FETCH claim_line_his_id_csr into l_claim_line_hist_id, l_object_version_number;
4763             EXIT When claim_line_his_id_csr%NOTFOUND;
4764 
4765             OZF_Claim_Line_Hist_PVT.Delete_Claim_Line_Hist(
4766             p_api_version_number         => l_api_version
4767             ,p_init_msg_list              => FND_API.g_false
4768             ,p_commit                     => FND_API.g_false
4769             ,p_validation_level           => FND_API.g_valid_level_full
4770             ,x_return_status              => l_return_status
4771             ,x_msg_count                  => l_msg_count
4772             ,x_msg_data                   => l_msg_data
4773             ,p_claim_line_history_id      => l_claim_line_hist_id
4774             ,p_object_version_number      => l_object_version_number
4775             );
4776 
4777             IF l_return_status = FND_API.g_ret_sts_error THEN
4778                RAISE FND_API.g_exc_unexpected_error;
4779             ELSIF l_return_status = FND_API.g_ret_sts_unexp_error THEN
4780                RAISE FND_API.g_exc_unexpected_error;
4781             END IF;
4782           END LOOP;
4783           CLOSE claim_line_his_id_csr;
4784 
4785           -- get claim line information
4786           l_ind :=1;
4787           OPEN claim_line_id_csr(p_object_id);
4788             LOOP
4789               FETCH claim_line_id_csr into l_claim_line_id, l_line_object_version_number;
4790               EXIT when claim_line_id_csr%NOTFOUND;
4791               l_claim_line_tbl(l_ind).claim_line_id := l_claim_line_id;
4792               l_claim_line_tbl(l_ind).object_version_number := l_line_object_version_number;
4793               l_ind := l_ind +1;
4794             END LOOP;
4795           CLOSE claim_line_id_csr;
4796 
4797           OZF_Claim_Line_PVT.Delete_Claim_Line_Tbl(
4798              p_api_version       => l_api_version
4799             ,p_init_msg_list     => FND_API.g_false
4800             ,p_commit            => FND_API.g_false
4801             ,p_validation_level  => FND_API.g_valid_level_full
4802             ,x_return_status     => l_return_status
4803             ,x_msg_count         => l_msg_count
4804             ,x_msg_data          => l_msg_data
4805             ,p_claim_line_tbl         => l_claim_line_tbl
4806             ,p_change_object_version  => FND_API.g_false
4807             ,x_error_index            => l_error_index
4808           );
4809           IF l_return_status = FND_API.g_ret_sts_error THEN
4810              RAISE FND_API.g_exc_unexpected_error;
4811           ELSIF l_return_status = FND_API.g_ret_sts_unexp_error THEN
4812              RAISE FND_API.g_exc_unexpected_error;
4813           END IF;
4814 
4815           OZF_claims_PKG.Delete_Row(p_object_id);
4816        ELSE
4817           IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
4818              FND_MESSAGE.set_name('OZF', 'OZF_CLAIM_CANT_DEL_CLAIM');
4819              FND_MSG_PUB.add;
4820           END IF;
4821        END IF;
4822 
4823     ELSE
4824        IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
4825           FND_MESSAGE.set_name('OZF', 'OZF_REC_VERSION_CHANGED');
4826           FND_MSG_PUB.add;
4827        END IF;
4828        RAISE FND_API.g_exc_error;
4829     END IF;
4830 
4831     --Standard check of commit
4832     IF FND_API.To_Boolean ( p_commit ) THEN
4833         COMMIT WORK;
4834     END IF;
4835 
4836     -- Debug Message
4837     IF OZF_DEBUG_LOW_ON THEN
4838         FND_MESSAGE.Set_Name('OZF','OZF_API_DEBUG_MESSAGE');
4839         FND_MESSAGE.Set_Token('TEXT',l_full_name||': End');
4840         FND_MSG_PUB.Add;
4841     END IF;
4842 
4843     --Standard call to get message count and if count=1, get the message
4844     FND_MSG_PUB.Count_And_Get (
4845         p_encoded => FND_API.G_FALSE,
4846         p_count => x_msg_count,
4847         p_data  => x_msg_data
4848     );
4849 EXCEPTION
4850    WHEN FND_API.G_EXC_ERROR THEN
4851       ROLLBACK TO  Delete_Claim_PVT;
4852       x_return_status := FND_API.G_RET_STS_ERROR;
4853       -- Standard call to get message count and if count=1, get the message
4854       FND_MSG_PUB.Count_And_Get (
4855          p_encoded => FND_API.G_FALSE,
4856          p_count => x_msg_count,
4857          p_data  => x_msg_data
4858       );
4859    WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
4860       ROLLBACK TO  Delete_Claim_PVT;
4861       x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4862       -- Standard call to get message count and if count=1, get the message
4863       FND_MSG_PUB.Count_And_Get (
4864          p_encoded => FND_API.G_FALSE,
4865          p_count => x_msg_count,
4866          p_data  => x_msg_data
4867       );
4868    WHEN OTHERS THEN
4869       ROLLBACK TO  Delete_Claim_PVT;
4870       x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4871       IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
4872          FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
4873       END IF;
4874       -- Standard call to get message count and if count=1, get the message
4875       FND_MSG_PUB.Count_And_Get (
4876          p_encoded => FND_API.G_FALSE,
4877          p_count => x_msg_count,
4878          p_data  => x_msg_data
4879       );
4880 END Delete_Claim;
4881 
4882 ---------------------------------------------------------------------
4883 -- PROCEDURE
4884 --    reason_changed
4885 --
4886 -- PURPOSE
4887 --    Check whether the reason code id has changed.
4888 --
4889 -- PARAMETERS
4890 --    p_claim_id
4891 --    p_task_template_group_id
4892 --    x_changed
4893 --    x_return_status
4894 --
4895 -- NOTES
4896 ---------------------------------------------------------------------
4897 PROCEDURE reason_changed(p_claim_id       in number,
4898                          p_claim_number   in varchar2,
4899                          p_owner_id       in number,
4900                          p_reason_code_id in number,
4901                          p_task_template_group_id in number,
4902                          x_changed        OUT NOCOPY boolean,
4903                          x_return_status  OUT NOCOPY varchar2)
4904 IS
4905 l_task_template_group_id number;
4906 l_reason_code_id         number;
4907 l_return_status varchar2(3);
4908 
4909 CURSOR reason_csr(p_id in number) IS
4910 SELECT reason_code_id, task_template_group_id
4911 FROM   ozf_claims_all
4912 WHERE  claim_id = p_id;
4913 
4914 BEGIN
4915    -- Initialize API return status to sucess
4916    x_return_status := FND_API.G_RET_STS_SUCCESS;
4917 
4918    OPEN reason_csr(p_claim_id);
4919    FETCH reason_csr into l_reason_code_id, l_task_template_group_id;
4920    CLOSE reason_csr;
4921 
4922 
4923    IF ((l_reason_code_id is not null AND
4924         p_reason_code_id is not null AND
4925         p_reason_code_id <> l_reason_code_id) OR
4926        (l_reason_code_id is null AND p_reason_code_id is not null) OR
4927        (l_reason_code_id is not null AND p_reason_code_id is null )) THEN
4928       x_changed := TRUE;
4929    ELSE
4930       x_changed := FALSE;
4931    END IF;
4932 
4933    IF not x_changed THEN
4934      IF ((l_task_template_group_id is not null AND
4935         p_task_template_group_id is not null AND
4936         p_task_template_group_id <> l_task_template_group_id) OR
4937        (l_task_template_group_id is null AND p_task_template_group_id is not null) OR
4938        (l_task_template_group_id is not null AND p_task_template_group_id is null )) THEN
4939       x_changed := TRUE;
4940      ELSE
4941       x_changed := FALSE;
4942      END IF;
4943    END IF;
4944 
4945 /*   -- Here I will generate task if there is no task generated.
4946    IF (l_task_template_group_id is null AND (p_task_template_group_id is not null AND p_task_template_group_id <> FND_API.G_MISS_NUM)) THEN
4947       generate_tasks(
4948           p_task_template_group_id => p_task_template_group_id
4949          ,p_owner_id       => p_owner_id
4950 	 ,p_claim_number   => p_claim_number
4951          ,p_claim_id       => p_claim_id
4952          ,x_return_status  => l_return_status
4953         );
4954 	IF l_return_status = FND_API.g_ret_sts_error THEN
4955           RAISE FND_API.g_exc_unexpected_error;
4956         ELSIF l_return_status = FND_API.g_ret_sts_unexp_error THEN
4957           RAISE FND_API.g_exc_unexpected_error;
4958         END IF;
4959    END IF;
4960 */
4961 EXCEPTION
4962    WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
4963       x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4964   WHEN OTHERS THEN
4965      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4966      IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_unexp_error) THEN
4967         FND_MESSAGE.set_name('OZF', 'OZF_CLAIM_REASON_CHANGE_ERR');
4968         FND_MSG_PUB.add;
4969      END IF;
4970 END reason_changed;
4971 
4972 ---------------------------------------------------------------------
4973 -- PROCEDURE
4974 --    Create_Claim_History
4975 --
4976 -- PURPOSE
4977 --    Create a history record of a claim.
4978 --
4979 -- PARAMETERS
4980 --    p_claim   : the record with new items.
4981 --
4982 -- NOTES
4983 ----------------------------------------------------------------------
4984 PROCEDURE  Create_Claim_History (
4985     p_api_version            IN    NUMBER
4986    ,p_init_msg_list          IN    VARCHAR2
4987    ,p_commit                 IN    VARCHAR2
4988    ,p_validation_level       IN    NUMBER
4989    ,x_return_status          OUT NOCOPY   VARCHAR2
4990    ,x_msg_data               OUT NOCOPY   VARCHAR2
4991    ,x_msg_count              OUT NOCOPY   NUMBER
4992    ,p_claim                  IN    claim_rec_type
4993    ,p_event                  IN    VARCHAR2
4994    ,x_need_to_create         OUT NOCOPY   VARCHAR2
4995    ,x_claim_history_id       OUT NOCOPY   NUMBER
4996 )
4997 IS
4998 l_api_name              CONSTANT VARCHAR2(30) := 'Create_Claim_History';
4999 l_api_version           CONSTANT NUMBER := 1.0;
5000 l_full_name             CONSTANT VARCHAR2(60) := G_PKG_NAME ||'.'|| l_api_name;
5001 --
5002 l_return_status  varchar2(30);
5003 l_msg_count      number;
5004 l_msg_data       varchar2(2000);
5005 
5006 l_history_event_description VARCHAR2(2000);
5007 l_history_event         VARCHAR2(30);
5008 l_needed_to_create        VARCHAR2(1) := 'N';
5009 l_claim_history_id        NUMBER := null;
5010 l_status_code           varchar2(30);
5011 CURSOR user_status_id_csr(p_id in number) is
5012 select user_status_id
5013 from ozf_claims_all
5014 where claim_id = p_id;
5015 
5016 l_user_status_id number;
5017 BEGIN
5018     -- Standard begin of API savepoint
5019     SAVEPOINT  Create_Claim_Hist_PVT;
5020 
5021     -- Standard call to check for call compatibility.
5022     IF NOT FND_API.Compatible_API_Call (
5023         l_api_version,
5024         p_api_version,
5025         l_api_name,
5026         G_PKG_NAME)
5027     THEN
5028         RAISE  FND_API.G_EXC_UNEXPECTED_ERROR;
5029     END IF;
5030     -- Debug Message
5031     IF OZF_DEBUG_LOW_ON THEN
5032         FND_MESSAGE.Set_Name('OZF','OZF_API_DEBUG_MESSAGE');
5033         FND_MESSAGE.Set_Token('TEXT',l_full_name||': Start');
5034         FND_MSG_PUB.Add;
5035     END IF;
5036     --Initialize message list if p_init_msg_list is TRUE.
5037     IF FND_API.To_Boolean (p_init_msg_list) THEN
5038         FND_MSG_PUB.initialize;
5039     END IF;
5040     -- Initialize API return status to sucess
5041     x_return_status := FND_API.G_RET_STS_SUCCESS;
5042 
5043     OPEN user_status_id_csr (p_claim.claim_id);
5044 	 FETCH user_status_id_csr into l_user_status_id;
5045 	 CLOSe user_status_id_csr;
5046 
5047     Get_System_Status( p_user_status_id => l_user_status_id,
5048                       p_status_type    => G_CLAIM_STATUS,
5049                       x_system_status  => l_status_code,
5050                       x_msg_data       => l_msg_data,
5051                       x_msg_count      => l_msg_count,
5052                       x_return_status  => l_return_status
5053     );
5054 
5055     IF l_return_status = FND_API.G_RET_STS_ERROR THEN
5056        RAISE FND_API.G_EXC_ERROR;
5057     ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
5058        RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5059     END IF;
5060 
5061     -- If the status_code is not new, then I will to create_claim_history
5062     --Comment out the below line (uday) since we will be creating the history
5063     -- at the time of claim creation also.
5064     --IF l_status_code <> G_INIT_STATUS THEN
5065        OZF_claims_history_PVT.Check_Create_History(
5066          p_claim => p_claim,
5067          p_event => p_event,
5068          x_history_event => l_history_event,
5069          x_history_event_description => l_history_event_description,
5070          x_needed_to_create => l_needed_to_create,
5071          x_return_status => l_return_status
5072        );
5073        IF l_return_status = FND_API.g_ret_sts_error THEN
5074            RAISE FND_API.g_exc_error;
5075        ELSIF l_return_status = FND_API.g_ret_sts_unexp_error THEN
5076            RAISE FND_API.g_exc_unexpected_error;
5077        END IF;
5078 
5079        IF (l_needed_to_create = 'Y') THEN
5080            -- CREATE history
5081            OZF_claims_history_PVT.Create_History(
5082               p_claim_id      => p_claim.claim_id,
5083               p_history_event => l_history_event,
5084               p_history_event_description => l_history_event_description,
5085               x_claim_history_id => l_claim_history_id,
5086               x_return_status => l_return_status
5087            );
5088            IF l_return_status = FND_API.g_ret_sts_error THEN
5089               RAISE FND_API.g_exc_error;
5090            ELSIF l_return_status = FND_API.g_ret_sts_unexp_error THEN
5091               RAISE FND_API.g_exc_unexpected_error;
5092            END IF;
5093        END IF;
5094     --END IF; (uday)
5095     x_need_to_create := l_needed_to_create;
5096     x_claim_history_id := l_claim_history_id;
5097     --Standard check of commit
5098     IF FND_API.To_Boolean ( p_commit ) THEN
5099         COMMIT WORK;
5100     END IF;
5101     -- Debug Message
5102     IF OZF_DEBUG_LOW_ON THEN
5103         FND_MESSAGE.Set_Name('OZF','OZF_API_DEBUG_MESSAGE');
5104         FND_MESSAGE.Set_Token('TEXT',l_full_name||': End');
5105         FND_MSG_PUB.Add;
5106     END IF;
5107     --Standard call to get message count and if count=1, get the message
5108     FND_MSG_PUB.Count_And_Get (
5109         p_encoded => FND_API.G_FALSE,
5110         p_count => x_msg_count,
5111         p_data  => x_msg_data
5112     );
5113 EXCEPTION
5114     WHEN FND_API.G_EXC_ERROR THEN
5115         ROLLBACK TO  Create_Claim_Hist_PVT;
5116         x_return_status := FND_API.G_RET_STS_ERROR;
5117         -- Standard call to get message count and if count=1, get the message
5118         FND_MSG_PUB.Count_And_Get (
5119             p_encoded => FND_API.G_FALSE,
5120             p_count => x_msg_count,
5121             p_data  => x_msg_data
5122         );
5123     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
5124         ROLLBACK TO  Create_Claim_Hist_PVT;
5125         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5126         -- Standard call to get message count and if count=1, get the message
5127         FND_MSG_PUB.Count_And_Get (
5128             p_encoded => FND_API.G_FALSE,
5129             p_count => x_msg_count,
5130             p_data  => x_msg_data
5131         );
5132     WHEN OTHERS THEN
5133         ROLLBACK TO  Create_Claim_Hist_PVT;
5134         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5135         IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
5136         THEN
5137             FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
5138         END IF;
5139         -- Standard call to get message count and if count=1, get the message
5140         FND_MSG_PUB.Count_And_Get (
5141             p_encoded => FND_API.G_FALSE,
5142             p_count => x_msg_count,
5143             p_data  => x_msg_data
5144         );
5145 --
5146 END Create_Claim_History;
5147 
5148 
5149 ---------------------------------------------------------------------
5150 -- PROCEDURE
5151 --    Update_Claim
5152 --
5153 -- PURPOSE
5154 --    Update a claim code.
5155 --
5156 -- PARAMETERS
5157 --    p_claim   : the record with new items.
5158 --
5159 -- NOTES
5160 --    1. Raise exception if the object_version_number doesn't match.
5161 --    2. If an attribute is passed in as FND_API.g_miss_char/num/date,
5162 --       that column won't be updated.
5163 ----------------------------------------------------------------------
5164 PROCEDURE  Update_Claim (
5165     p_api_version            IN    NUMBER
5166    ,p_init_msg_list          IN    VARCHAR2 := FND_API.G_FALSE
5167    ,p_commit                 IN    VARCHAR2 := FND_API.G_FALSE
5168    ,p_validation_level       IN    NUMBER   := FND_API.G_VALID_LEVEL_FULL
5169 
5170    ,x_return_status          OUT NOCOPY   VARCHAR2
5171    ,x_msg_data               OUT NOCOPY   VARCHAR2
5172    ,x_msg_count              OUT NOCOPY   NUMBER
5173    ,p_claim                  IN    claim_rec_type
5174    ,p_event                  IN    VARCHAR2
5175 	,p_mode                   IN    VARCHAR2 := OZF_claim_Utility_pvt.G_AUTO_MODE
5176    ,x_object_version_number  OUT NOCOPY   NUMBER
5177 )
5178 IS
5179 l_api_name              CONSTANT VARCHAR2(30) := 'Update_Claim';
5180 l_api_version           CONSTANT NUMBER := 1.0;
5181 l_full_name             CONSTANT VARCHAR2(60) := G_PKG_NAME ||'.'|| l_api_name;
5182 --
5183 l_user_id               number;
5184 l_login_user_id         number;
5185 l_login_user_status     varchar2(30);
5186 l_Error_Msg             varchar2(2000);
5187 l_Error_Token           varchar2(80);
5188 l_object_version_number number(9);
5189 
5190 l_claim                 claim_rec_type := p_claim;
5191 l_complete_claim        claim_rec_type;
5192 l_acc_amount            number;
5193 l_rate                  number;
5194 
5195 l_claim_history_id      number;
5196 
5197 l_rec_num               number :=1;
5198 l_need_to_create        varchar2(1) := 'N';
5199 l_amount_changed        boolean;
5200 l_exchange_changed      boolean;
5201 l_pass              boolean;
5202 l_reason_code_changed   boolean;
5203 l_hist_obj_ver_num      number;
5204 l_claim_lines_sum       number;
5205 l_customer_ref_norm     varchar2(30);
5206 
5207 l_return_status  varchar2(30);
5208 l_msg_count      number;
5209 l_msg_data       varchar2(2000);
5210 
5211 l_user_sel_status_code_id   number;
5212 l_curr_status_code          varchar2(30);
5213 l_close_status_id  number;
5214 l_open_status_id  number;
5215 
5216 CURSOR claim_currency_amount_sum_csr(p_id in NUMBER) IS
5217 select NVL(sum(claim_currency_amount), 0)
5218 from ozf_claim_lines_all
5219 where claim_id = p_id;
5220 
5221 CURSOR object_version_number_csr (p_id in number) is
5222 select object_version_number
5223 from ozf_claims_all
5224 where claim_id = p_id;
5225 
5226 CURSOR tasks_csr(p_claim_id in number,
5227                  p_completed_flag in varchar2) IS
5228 SELECT a.task_id, a.object_version_number
5229 FROM jtf_tasks_vl a, jtf_task_statuses_vl b
5230 WHERE b.completed_flag = p_completed_flag
5231 AND   a.deleted_flag   = 'N'
5232 AND   a.task_status_id = b.task_status_id
5233 AND   a.source_object_type_code = G_OBJECT_TYPE
5234 AND   a.source_object_id = p_claim_id;
5235 
5236 TYPE  tasks_csr_Tbl_Type IS TABLE OF tasks_csr%rowtype
5237                                INDEX BY BINARY_INTEGER;
5238 l_completed_tasks_tbl   tasks_csr_Tbl_Type;
5239 l_uncompleted_tasks_tbl tasks_csr_Tbl_Type;
5240 
5241 CURSOR claim_history_tbl_csr(p_claim_id in number) IS
5242 SELECT claim_history_id, object_version_number
5243 FROM ozf_claims_history_all
5244 WHERE task_source_object_id = p_claim_id
5245 AND   task_source_object_type_code = G_CLAIM_TYPE
5246 AND   claim_id = p_claim_id;
5247 
5248 TYPE  CLAIMS_HISTORY_Tbl_Type      IS TABLE OF CLAIM_HISTORY_tbl_csr%rowtype
5249                                                     INDEX BY BINARY_INTEGER;
5250 l_claim_history_tbl       CLAIMS_HISTORY_Tbl_Type;
5251 
5252 l_claim_history_rec OZF_claims_history_PVT.claims_history_Rec_Type;
5253 
5254 
5255 CURSOR old_info_csr (p_id in number) IS
5256 SELECT user_status_id,
5257        status_code,
5258        reason_code_id,
5259        task_template_group_id,
5260        cust_account_id,
5261        owner_id,
5262        customer_ref_number,
5263        customer_ref_normalized,
5264        write_off_flag
5265 FROM ozf_claims_all
5266 WHERE claim_id = p_id;
5267 l_old_status_code         varchar2(30);
5268 l_prev_status_code        varchar2(30);
5269 l_old_user_status_id      number;
5270 l_old_reason_code_id      number;
5271 l_old_task_template_group_id        number;
5272 l_old_cust_acct_id        number;
5273 l_old_owner_id            number;
5274 l_old_customer_ref_number varchar2(30);
5275 l_functional_currency_code          varchar2(30);
5276 
5277 --Bug#:2732290 Date:29-May-2003 added following variable.
5278 l_old_write_off_flag      varchar2(1);
5279 
5280 CURSOR claim_lines_csr(p_id in number)IS
5281 SELECT *
5282 FROM ozf_claim_lines_all
5283 WHERE claim_id = p_id;
5284 
5285 TYPE  Claim_Lines_Type      IS TABLE OF claim_lines_csr%rowtype
5286                                INDEX BY BINARY_INTEGER;
5287 l_claim_lines             Claim_Lines_Type;
5288 l_claim_line_tbl          OZF_Claim_Line_PVT.claim_line_tbl_type;
5289 l_error_index             number;
5290 l_days_due                number;
5291 
5292 CURSOR primary_sales_rep_id_csr(p_customer_account_id in number) IS
5293 SELECT primary_salesrep_id
5294 FROM   HZ_CUST_ACCOUNTS
5295 WHERE  cust_account_id = p_customer_account_id;
5296 l_sales_rep_id  NUMBER;
5297 
5298 CURSOR user_status_id_csr (p_id in number) IS
5299 SELECT user_status_id
5300 FROM ozf_claims_all
5301 WHERE claim_id = p_id;
5302 
5303 CURSOR status_code_csr (p_id in number) IS
5304 SELECT status_code
5305 FROM ozf_claims_all
5306 WHERE claim_id = p_id;
5307 
5308 -- fix for bug 5042046
5309 CURSOR auto_assign_flag_csr IS
5310 SELECT auto_assign_flag
5311 FROM   ozf_sys_parameters
5312 WHERE org_id = MO_GLOBAL.GET_CURRENT_ORG_ID();
5313 
5314 l_auto_assign_flag varchar2(1);
5315 
5316 CURSOR default_owner_id_csr IS
5317 SELECT default_owner_id
5318 FROM   ozf_sys_parameters
5319 WHERE org_id = MO_GLOBAL.GET_CURRENT_ORG_ID();
5320 
5321 CURSOR resource_id_csr(p_user_id in number) is
5322 SELECT resource_id
5323 FROM   jtf_rs_resource_extns
5324 WHERE  user_id = p_user_id
5325 AND    category = 'EMPLOYEE';
5326 
5327 l_resource_id number;
5328 
5329 CURSOR tax_amount_csr(p_id in number) IS
5330 SELECT tax_amount
5331 FROM ozf_claims_all
5332 WHERE claim_id = p_id;
5333 
5334 l_tax_amount number;
5335 
5336 l_access_list      gp_access_list_type;
5337 -- [BEGIN OF BUG 3835800 Fixing]
5338 l_access_comp_list gp_access_list_type;
5339 l_dup_resource     BOOLEAN := FALSE;
5340 -- [END OF BUG 3835800 Fixing]
5341 l_access varchar2(1) := 'N';
5342 l_access_id number;
5343 l_access_obj_ver number;
5344 
5345 CURSOR claim_access_csr(p_id in number) is
5346 select activity_access_id, object_version_number
5347 FROM ams_act_access
5348 WHERE arc_act_access_to_object = 'CLAM'
5349 and   act_access_to_object_id = p_id;
5350 
5351 TYPE  claim_access_list_Type   IS TABLE OF claim_access_csr%rowtype
5352                                INDEX BY BINARY_INTEGER;
5353 l_claim_access_list  claim_access_list_Type;
5354 l_access_index number:=0;
5355 
5356 CURSOR owner_access_csr(p_claim_id in number, p_user_id in number) is
5357 select activity_access_id, object_version_number
5358 FROM ams_act_access
5359 WHERE arc_act_access_to_object = 'CLAM'
5360 and act_access_to_object_id = p_claim_id
5361 and user_or_role_id = p_user_id
5362 and arc_user_or_role_type = 'USER'
5363 and rownum =1;
5364 
5365 l_owner_changed boolean:= false;
5366 
5367 -- get shipto customer based on shipto site
5368 CURSOR shipto_cust_account_id_csr(p_site_use_id in number) is
5369 select a.cust_account_id
5370 FROM   HZ_CUST_ACCT_SITES a
5371 ,      HZ_CUST_SITE_USES s
5372 WHERE  a.cust_acct_site_id = s.cust_acct_site_id
5373 and    s.site_use_id = p_site_use_id;
5374 
5375 CURSOR csr_user_status_info(p_claim_id in number) is
5376 SELECT open_status_id,
5377        close_status_id
5378 FROM ozf_claims_all
5379 WHERE claim_id = p_claim_id;
5380 --
5381 BEGIN
5382     -- Standard begin of API savepoint
5383 --    IF ( NOT G_UPDATE_CALLED ) THEN
5384        SAVEPOINT  Update_Claim_PVT;
5385 --       G_UPDATE_CALLED := true;
5386 --    END IF;
5387     -- Standard call to check for call compatibility.
5388     IF NOT FND_API.Compatible_API_Call (
5389         l_api_version,
5390         p_api_version,
5391         l_api_name,
5392         G_PKG_NAME)
5393     THEN
5394         RAISE  FND_API.G_EXC_UNEXPECTED_ERROR;
5395     END IF;
5396     -- Debug Message
5397     IF OZF_DEBUG_LOW_ON THEN
5398         FND_MESSAGE.Set_Name('OZF','OZF_API_DEBUG_MESSAGE');
5399         FND_MESSAGE.Set_Token('TEXT',l_full_name||': Start');
5400         FND_MSG_PUB.Add;
5401     END IF;
5402     --Initialize message list if p_init_msg_list is TRUE.
5403     IF FND_API.To_Boolean (p_init_msg_list) THEN
5404         FND_MSG_PUB.initialize;
5405     END IF;
5406     -- Initialize API return status to sucess
5407     x_return_status := FND_API.G_RET_STS_SUCCESS;
5408 
5409     -- Varify object_version_number
5410     IF (l_claim.object_version_number is NULL or
5411         l_claim.object_version_number = FND_API.G_MISS_NUM ) THEN
5412         IF FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
5413            FND_MESSAGE.Set_Name('OZF', 'OZF_API_NO_OBJ_VER_NUM');
5414           FND_MSG_PUB.ADD;
5415         END IF;
5416         RAISE FND_API.G_EXC_ERROR;
5417     END IF;
5418 
5419     OPEN object_version_number_csr(l_claim.claim_id);
5420     FETCH object_version_number_csr INTO l_object_version_number;
5421     CLOSE object_version_number_csr;
5422 
5423     IF l_object_version_number <> l_claim.object_version_number THEN
5424        IF FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
5425           FND_MESSAGE.Set_Name('OZF', 'OZF_API_RESOURCE_LOCKED');
5426           FND_MSG_PUB.ADD;
5427        END IF;
5428        RAISE FND_API.G_EXC_ERROR;
5429     END IF;
5430 
5431     --  Bug: 2732290 -----------------------------------------------------------
5432     IF (l_claim.customer_reason is not NULL
5433         AND l_claim.customer_reason <> FND_API.g_miss_char )
5434     THEN
5435        Get_Customer_Reason(p_cust_account_id => l_claim.cust_account_id,
5436                        px_reason_code_id => l_claim.reason_code_id,
5437                        p_customer_reason => l_claim.customer_reason,
5438                        x_return_status  => l_return_status);
5439       IF l_return_status = FND_API.g_ret_sts_error THEN
5440         RAISE FND_API.g_exc_error;
5441       ELSIF l_return_status = FND_API.g_ret_sts_unexp_error THEN
5442         RAISE FND_API.g_exc_unexpected_error;
5443       END IF;
5444     END IF;
5445     -- End Bug: 2732290 -----------------------------------------------------------
5446 
5447     l_user_id := NVL(FND_GLOBAL.user_id,-1);
5448     IF (l_user_id = -1) THEN
5449        l_resource_id := -1;
5450     ELSE
5451        OPEN resource_id_csr(l_user_id);
5452        FETCH resource_id_csr into l_resource_id;
5453        CLOSE resource_id_csr;
5454     END IF;
5455 
5456     IF p_mode = OZF_claim_Utility_pvt.G_MANU_MODE THEN
5457        OZF_CLAIM_UTILITY_PVT.Check_Claim_access(
5458           P_Api_Version_Number => 1.0,
5459           P_Init_Msg_List      => FND_API.G_FALSE,
5460           p_validation_level   => FND_API.G_VALID_LEVEL_FULL,
5461           P_Commit             => FND_API.G_FALSE,
5462           P_object_id          => p_claim.claim_id,
5463           P_object_type        => G_CLAIM_OBJECT_TYPE,
5464           P_user_id            => OZF_UTILITY_PVT.get_resource_id(NVL(FND_GLOBAL.user_id,-1)),
5465           X_Return_Status      => l_return_status,
5466           X_Msg_Count          => l_msg_count,
5467           X_Msg_Data           => l_msg_data,
5468           X_access             => l_access);
5469 
5470 	    IF l_access = 'N' THEN
5471 	       IF FND_MSG_PUB.Check_Msg_level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
5472 	          FND_MESSAGE.Set_Name('OZF','OZF_CLAIM_NO_ACCESS');
5473              FND_MSG_PUB.Add;
5474 	       END IF;
5475 	       RAISE FND_API.G_EXC_ERROR;
5476 	    END IF;
5477     END IF;
5478 
5479     -- Now the object_version_number matches, we can increase it.
5480     l_object_version_number := l_claim.object_version_number + 1;
5481 
5482     -- Retrieve user_status_id if it is not changed.
5483     IF l_claim.user_status_id is null OR
5484        l_claim.user_status_id = FND_API.G_MISS_NUM THEN
5485        IF l_claim.status_code is null OR
5486           l_claim.status_code = FND_API.G_MISS_CHAR THEN
5487 
5488           OPEN user_status_id_csr(l_claim.claim_id);
5489           FETCH user_status_id_csr INTO l_claim.user_status_id;
5490           CLOSE user_status_id_csr;
5491        ELSE
5492           l_claim.user_status_id := to_number( ozf_utility_pvt.GET_DEFAULT_USER_STATUS(
5493                                           P_STATUS_TYPE=> G_CLAIM_STATUS,
5494                                           P_STATUS_CODE=> l_claim.status_code
5495                                      )
5496 				    );
5497     END IF;
5498        END IF;
5499 
5500     -- First, we need to update the status code. Status code is not updated
5501     -- from screen. In order to keep the data integerty, we need to update it first.
5502     -- modify status_code accordingly
5503     Get_System_Status( p_user_status_id => l_claim.user_status_id,
5504                       p_status_type    => G_CLAIM_STATUS,
5505                       x_system_status  => l_claim.status_code,
5506                       x_msg_data       => l_msg_data,
5507                       x_msg_count      => l_msg_count,
5508                       x_return_status  => l_return_status
5509     );
5510 
5511     IF l_return_status = FND_API.G_RET_STS_ERROR THEN
5512        RAISE FND_API.G_EXC_ERROR;
5513     ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
5514        RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5515     END IF;
5516 
5517     OPEN  csr_user_status_info(l_claim.claim_id);
5518     FETCH csr_user_status_info INTO l_open_status_id, l_close_status_id;
5519     CLOSE csr_user_status_info;
5520 
5521     --***************************************************************
5522     -- Start Fix for Bug 5613926
5523 
5524     IF l_claim.status_code = 'CLOSED' THEN
5525         l_claim.close_status_id := l_claim.user_status_id;
5526     END IF;
5527 
5528    /*
5529     IF l_claim.status_code = 'CLOSED' AND l_close_status_id IS NULL THEN
5530        l_claim.close_status_id := l_claim.user_status_id;
5531     END IF;
5532     */
5533 
5534    -- End Fix for bug 5613926
5535    --***************************************************************
5536 
5537     IF l_claim.status_code = G_OPEN_STATUS AND l_claim.user_status_id IS NOT NULL THEN
5538        l_claim.open_status_id := l_claim.user_status_id;
5539     END IF;
5540 
5541     l_prev_status_code := l_claim.status_code;
5542 
5543     -- Replace g_miss_char/num/date with current column values
5544     -- We can not complete the claim_rec first, since that will overwrite the new event.
5545     Complete_Claim_Rec(
5546        p_claim_rec      => l_claim,
5547        x_complete_rec   => l_complete_claim,
5548        x_return_status  => l_return_status
5549     );
5550     IF l_return_status = FND_API.g_ret_sts_error THEN
5551        RAISE FND_API.g_exc_error;
5552     ELSIF l_return_status = FND_API.g_ret_sts_unexp_error THEN
5553        RAISE FND_API.g_exc_unexpected_error;
5554     END IF;
5555 
5556     l_claim := l_complete_claim;
5557 
5558     -- check amount first, throw any error if amount for deduction is changed.
5559     -- round the amount first
5560     l_claim.amount          := OZF_UTILITY_PVT.CurrRound(l_claim.amount, l_claim.currency_code);
5561     l_claim.amount_adjusted := OZF_UTILITY_PVT.CurrRound(l_claim.amount_adjusted, l_claim.currency_code);
5562     l_claim.amount_settled  := OZF_UTILITY_PVT.CurrRound(l_claim.amount_settled, l_claim.currency_code);
5563     l_claim.amount_remaining  :=  OZF_UTILITY_PVT.CurrRound(l_claim.amount_remaining, l_claim.currency_code);
5564 --    l_claim.acctd_amount    :=  OZF_UTILITY_PVT.CurrRound(l_claim.acctd_amount, l_claim.currency_code);
5565 --    l_claim.acctd_amount_remaining :=  OZF_UTILITY_PVT.CurrRound(l_claim.acctd_amount_remaining, l_claim.currency_code);
5566 
5567     -- Calculate currency conversions if amount is changed
5568     check_amount(
5569        p_claim              => l_claim,
5570        p_mode               => p_mode,
5571        x_amount_changed     => l_amount_changed,
5572        x_exchange_changed   => l_exchange_changed,
5573        x_pass               => l_pass,
5574        x_return_status      => l_return_status
5575     );
5576     IF l_return_status = FND_API.g_ret_sts_error THEN
5577        RAISE FND_API.g_exc_error;
5578     ELSIF l_return_status = FND_API.g_ret_sts_unexp_error THEN
5579        RAISE FND_API.g_exc_unexpected_error;
5580     END IF;
5581 
5582     IF l_pass = false THEN
5583        RAISE FND_API.G_EXC_ERROR;
5584     END IF;
5585 
5586 
5587     -- Bug: 3359914 -----------------------------------------------------------
5588     -- Reason is a required field when the claim is updated.
5589     IF l_claim.reason_code_id is null
5590     OR l_claim.reason_code_id =  FND_API.G_MISS_NUM
5591     THEN
5592       IF FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
5593          FND_MESSAGE.Set_Name('OZF','OZF_CLAIM_REASON_CD_MISSING');
5594          FND_MSG_PUB.Add;
5595       END IF;
5596       RAISE FND_API.G_EXC_ERROR;
5597     END IF;
5598     -- End Bug: 3359914 -----------------------------------------------------------
5599 
5600 
5601     -- check if action has changes.
5602     reason_changed(
5603        p_claim_id       => l_claim.claim_id,
5604        p_claim_number   => l_claim.claim_number,
5605        p_owner_id       => l_claim.owner_id,
5606        p_reason_code_id => l_claim.reason_code_id,
5607        p_task_template_group_id => l_claim.task_template_group_id,
5608        x_changed        => l_reason_code_changed,
5609        x_return_status  => l_return_status
5610     );
5611     IF l_return_status = FND_API.g_ret_sts_error THEN
5612        RAISE FND_API.g_exc_error;
5613     ELSIF l_return_status = FND_API.g_ret_sts_unexp_error THEN
5614        RAISE FND_API.g_exc_unexpected_error;
5615     END IF;
5616 
5617     -- ----------------------------------------------------------------------------
5618     -- Bug        : 2732290
5619     -- Changed by : Uday Poluri  Date: 29-May-2003
5620     -- Comments   : Add write_off_flag to following cursor as l_old_write_off_flag
5621     -- Note       : This is to avoid update of write off flag if status is not Open.
5622     -- ----------------------------------------------------------------------------
5623     -- Retrieve some information before the update
5624     OPEN old_info_csr(l_claim.claim_id);
5625     FETCH old_info_csr INTO l_old_user_status_id, l_old_status_code, l_old_reason_code_id,
5626     l_old_task_template_group_id, l_old_cust_acct_id, l_old_owner_id, l_old_customer_ref_number,
5627     l_customer_ref_norm, l_old_write_off_flag;
5628     CLOSE old_info_csr;
5629 
5630     -- If reason_codes_id has changed, I will try to reset the action to the default action according to the new reason_code
5631     -- Code commented for bug# - 5954318 : psomyaju/26.03.2007
5632     -- Bug#-5954318 : Start
5633     IF (l_old_reason_code_id <> l_claim.reason_code_id AND
5634        (--l_old_task_template_group_id = l_claim.task_template_group_id OR
5635         l_claim.task_template_group_id is null OR
5636         l_claim.task_template_group_id = fnd_api.g_miss_num))THEN
5637        l_claim.task_template_group_id := get_action_id(l_claim.reason_code_id);
5638     END IF;
5639      -- Bug#-5954318 : End
5640 
5641     -----------* Now Make sure status_code and user_status_id matches
5642     -- If user_status_id does not change, We need to assigned the
5643     -- default user_status_id.
5644     IF l_old_status_code <> l_claim.status_code AND
5645        l_old_user_status_id = l_claim.user_status_id THEN
5646 
5647        l_claim.user_status_id := to_number( ozf_utility_pvt.GET_DEFAULT_USER_STATUS(
5648                                  P_STATUS_TYPE=> G_CLAIM_STATUS,
5649                                  P_STATUS_CODE=> l_claim.status_code)
5650 		                           );
5651     END IF;
5652     -----------* Done with status
5653 
5654     -----------* Deal with duplicate claim
5655     -- deal with duplicate claim
5656     IF l_old_status_code <> l_claim.status_code THEN
5657        -- if user change status to dupliate, we need to have duplicate_claim_id as inputs
5658        IF l_claim.status_code = G_DUPLICATE_STATUS THEN
5659           IF l_claim.duplicate_claim_id is null OR
5660 	     l_claim.duplicate_claim_id = FND_API.G_MISS_NUM THEN
5661 	     IF FND_MSG_PUB.Check_Msg_level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
5662                 FND_MESSAGE.set_name('OZF', 'OZF_CLAIM_DUP_CLM_ID_MISSING');
5663                 FND_MSG_PUB.add;
5664 	     END IF;
5665 	     RAISE FND_API.G_EXC_ERROR;
5666 	  END IF;
5667 
5668           -- Raise an error
5669           -- if the duplicate_claim_id equal to the current claim_id
5670           IF l_claim.duplicate_claim_id = l_claim.claim_id THEN
5671              IF FND_MSG_PUB.Check_Msg_level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
5672                 FND_MESSAGE.Set_Name('OZF','OZF_CLAIM_DUP_ID_SAME');
5673                 FND_MSG_PUB.Add;
5674              END IF;
5675              RAISE FND_API.G_EXC_ERROR;
5676           END IF;
5677        END IF;
5678 
5679        -- if user change status from duplicate, we need to set duplicate_claim_id as null
5680        IF l_old_status_code = G_DUPLICATE_STATUS THEN
5681           l_claim.duplicate_claim_id := null;
5682        END IF;
5683     END IF;
5684     -----------* Done with duplicated claim
5685 
5686     -- checking access of the claim if owner_id changes
5687     IF ((l_claim.owner_id is null AND l_old_owner_id is not null) OR
5688         (l_claim.owner_id is not null AND l_claim.owner_id <> l_old_owner_id)) THEN
5689 
5690         l_owner_changed := true;
5691 
5692         -- throw exception if user is not the owner nor does he has admin access
5693         --  (OZF_access_PVT.Check_Admin_Access(l_resource_id) = false)) THEN
5694         IF ((l_old_owner_id <> l_resource_id) AND
5695             (l_access <> 'F') AND
5696             (p_mode = OZF_claim_Utility_pvt.G_MANU_MODE) ) THEN
5697            IF FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
5698               FND_MESSAGE.Set_Name('OZF', 'OZF_CLAIM_UPDT_OWNER_PERM');
5699               FND_MSG_PUB.ADD;
5700            END IF;
5701            RAISE FND_API.G_EXC_ERROR;
5702         END IF;
5703         -- delete access for the current owner
5704         OPEN owner_access_csr(l_claim.claim_id, l_old_owner_id);
5705         FETCH owner_access_csr into l_access_id, l_access_obj_ver;
5706         CLOSE owner_access_csr;
5707 
5708         AMS_ACCESS_PVT.delete_access(
5709              p_api_version => l_api_version
5710                 ,p_init_msg_list => fnd_api.g_false
5711                 ,p_validation_level => p_validation_level
5712                 ,x_return_status => l_return_status
5713                 ,x_msg_count => x_msg_count
5714                 ,x_msg_data => x_msg_data
5715                 ,p_commit => fnd_api.g_false
5716                 ,p_access_id =>l_access_id
5717                 ,p_object_version =>l_access_obj_ver
5718         );
5719         IF l_return_status = fnd_api.g_ret_sts_error THEN
5720            RAISE fnd_api.g_exc_error;
5721         ELSIF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
5722            RAISE fnd_api.g_exc_unexpected_error;
5723         END IF;
5724 
5725 
5726  	   -- Added for bug fix 4247328
5727          -- If the new owner is already a part of the access,
5728          -- the error "The specified User or User Group is already part of the Team"
5729          -- is displayed. To fix this issue, we need to check if the new owner is
5730          -- already a part of team access. If yes, we need to delete access
5731          -- and then create access again as the owner of the claim.
5732          OPEN owner_access_csr(l_claim.claim_id, l_claim.owner_id);
5733          FETCH owner_access_csr into l_access_id, l_access_obj_ver;
5734          CLOSE owner_access_csr;
5735 
5736          AMS_ACCESS_PVT.delete_access(
5737              p_api_version => l_api_version
5738                 ,p_init_msg_list => fnd_api.g_false
5739                 ,p_validation_level => p_validation_level
5740                 ,x_return_status => l_return_status
5741                 ,x_msg_count => x_msg_count
5742                 ,x_msg_data => x_msg_data
5743                 ,p_commit => fnd_api.g_false
5744                 ,p_access_id =>l_access_id
5745                 ,p_object_version =>l_access_obj_ver
5746          );
5747          IF l_return_status = fnd_api.g_ret_sts_error THEN
5748             RAISE fnd_api.g_exc_error;
5749          ELSIF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
5750             RAISE fnd_api.g_exc_unexpected_error;
5751          END IF;
5752 
5753     END IF;
5754 
5755     -- Default owner_id if necessary
5756 
5757     IF (l_claim.owner_id is not null AND
5758         l_claim.owner_id <> FND_API.G_MISS_NUM) THEN
5759 
5760        -- Add the new owner to the access list
5761        l_access_list(1).arc_act_access_to_object := G_CLAIM_OBJECT_TYPE;
5762        l_access_list(1).user_or_role_id := l_claim.owner_id;
5763        l_access_list(1).arc_user_or_role_type := 'USER';
5764        l_access_list(1).admin_flag := 'Y';
5765        l_access_list(1).owner_flag := 'Y';
5766        l_access_list(1).act_access_to_object_id := l_claim.claim_id;
5767     ELSE
5768         OPEN auto_assign_flag_csr;
5769         FETCH auto_assign_flag_csr INTO l_auto_assign_flag;
5770         CLOSE auto_assign_flag_csr;
5771 
5772         IF l_auto_assign_flag = 'T' THEN
5773 
5774            get_owner (p_claim_type_id   => l_claim.claim_type_id,
5775                   p_claim_id        => l_claim.claim_id,
5776                   p_reason_code_id  => l_claim.reason_code_id,
5777                   p_vendor_id       => l_claim.vendor_id,
5778                   p_vendor_site_id  => l_claim.vendor_site_id,
5779                   p_cust_account_id => l_claim.cust_account_id,
5780                   p_billto_site_id  => l_claim.cust_billto_acct_site_id,
5781                   p_shipto_site_id  => l_claim.cust_shipto_acct_site_id,
5782                   p_claim_class     => l_claim.claim_class,
5783                   x_owner_id        => l_claim.owner_id,
5784                   x_access_list     => l_access_list,
5785                   x_return_status   => l_return_status);
5786            IF l_return_status = FND_API.g_ret_sts_error THEN
5787               RAISE FND_API.g_exc_error;
5788            ELSIF l_return_status = FND_API.g_ret_sts_unexp_error THEN
5789               RAISE FND_API.g_exc_unexpected_error;
5790            END IF;
5791 
5792           -- Default to system parameter if can not find an owner_id
5793           IF (l_claim.owner_id is null OR
5794               l_claim.owner_id = FND_API.G_MISS_NUM) THEN
5795 
5796              OPEN default_owner_id_csr;
5797              FETCH default_owner_id_csr into l_claim.owner_id;
5798              CLOSE default_owner_id_csr;
5799 
5800              -- Now we need to add owner to the access list
5801              IF l_access_list.count = 0 THEN
5802                 l_access_index :=1;
5803              ELSE
5804                 l_access_index := l_access_list.LAST +1;
5805              END IF;
5806              l_access_list(l_access_index).arc_act_access_to_object := G_CLAIM_OBJECT_TYPE;
5807              l_access_list(l_access_index).user_or_role_id := l_claim.owner_id;
5808              l_access_list(l_access_index).arc_user_or_role_type := 'USER';
5809              l_access_list(l_access_index).admin_flag := 'Y';
5810              l_access_list(l_access_index).owner_flag := 'Y';
5811              l_access_list(l_access_index).act_access_to_object_id := l_claim.claim_id;
5812           END IF;
5813 
5814           l_access_index := 1;
5815           -- Now we need to delete the current access list.
5816            OPEN claim_access_csr(l_claim.claim_id);
5817            LOOP
5818             FETCH claim_access_csr into l_claim_access_list(l_access_index);
5819             exit when claim_access_csr%NOTFOUND;
5820             l_access_index := l_access_index +1;
5821           END LOOP;
5822           CLOSE claim_access_csr;
5823 
5824            IF l_claim_access_list.COUNT <>0 THEN
5825              FOR i in 1..l_claim_access_list.LAST LOOP
5826               AMS_ACCESS_PVT.delete_access(
5827                  p_api_version => l_api_version
5828                 ,p_init_msg_list => fnd_api.g_false
5829                 ,p_validation_level => p_validation_level
5830                 ,x_return_status => l_return_status
5831                 ,x_msg_count => x_msg_count
5832                 ,x_msg_data => x_msg_data
5833                 ,p_commit => fnd_api.g_false
5834                 ,p_access_id =>l_claim_access_list(i).activity_access_id
5835                 ,p_object_version =>l_claim_access_list(i).object_version_number
5836                );
5837                IF l_return_status = fnd_api.g_ret_sts_error THEN
5838                   RAISE fnd_api.g_exc_error;
5839                ELSIF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
5840                   RAISE fnd_api.g_exc_unexpected_error;
5841                END IF;
5842               END LOOP;
5843            END IF;
5844         ELSE
5845            -- Should never be in this block.
5846           IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_unexp_error) THEN
5847               FND_MESSAGE.set_name('OZF', 'OZF_CLAIM_UPDATE_OWNER_ERR');
5848               FND_MSG_PUB.add;
5849            END IF;
5850            RAISE FND_API.g_exc_error;
5851         END IF;
5852     END IF;
5853 
5854     -----------* Deal with currency code issues
5855 
5856     IF l_amount_changed THEN
5857 
5858        -- get functional currency code
5859        OPEN  gp_func_currency_cd_csr;
5860        FETCH gp_func_currency_cd_csr INTO l_functional_currency_code;
5861        IF gp_func_currency_cd_csr%NOTFOUND THEN
5862           CLOSE gp_func_currency_cd_csr;
5863           IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_error) THEN
5864              fnd_message.set_name('OZF', 'OZF_CLAIM_GL_FUNCUR_MISSING');
5865              fnd_msg_pub.add;
5866           END IF;
5867           RAISE fnd_api.g_exc_error;
5868        END IF;
5869        CLOSE gp_func_currency_cd_csr;
5870 
5871  --      l_functional_currency_code := fnd_profile.value('JTF_PROFILE_DEFAULT_CURRENCY');
5872 
5873        -- If transaction currency_code is different from functional currency_code,
5874        -- We need to make sure that exchange_type is not null
5875        IF l_claim.currency_code <> l_functional_currency_code THEN
5876           IF  l_claim.exchange_rate_type is null OR
5877               l_claim.exchange_rate_type = FND_API.G_MISS_CHAR THEN
5878               IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_error) THEN
5879                  fnd_message.set_name('OZF', 'OZF_CLAIM_CONTYPE_MISSING');
5880                  fnd_msg_pub.add;
5881               END IF;
5882               RAISE fnd_api.g_exc_error;
5883           END IF;
5884 
5885  	  IF l_claim.exchange_rate_date is null OR
5886              l_claim.exchange_rate_date = FND_API.G_MISS_DATE THEN
5887 
5888 	     -- Default exchange_rate_date to sysdate
5889              l_claim.exchange_rate_date := SYSDATE;
5890           END IF;
5891        ELSE
5892           l_claim.exchange_rate_type := null;
5893           l_claim.exchange_rate_date := null;
5894           l_claim.exchange_rate :=1;
5895        END IF;
5896 
5897        -- Convert amount now
5898        OZF_UTILITY_PVT.Convert_Currency(
5899            P_SET_OF_BOOKS_ID => l_claim.set_of_books_id,
5900            P_FROM_CURRENCY   => l_claim.currency_code,
5901            P_CONVERSION_DATE => l_claim.exchange_rate_date,
5902            P_CONVERSION_TYPE => l_claim.exchange_rate_type,
5903            P_CONVERSION_RATE => l_claim.exchange_rate,
5904            P_AMOUNT          => l_claim.amount,
5905            X_RETURN_STATUS   => l_return_status,
5906            X_ACC_AMOUNT      => l_acc_amount,
5907            X_RATE => l_rate
5908        );
5909        IF l_return_status = FND_API.g_ret_sts_error THEN
5910           RAISE FND_API.g_exc_error;
5911        ELSIF l_return_status = FND_API.g_ret_sts_unexp_error THEN
5912           RAISE FND_API.g_exc_unexpected_error;
5913        END IF;
5914        l_claim.exchange_rate := l_rate;
5915        l_claim.ACCTD_AMOUNT  := l_acc_amount;
5916 
5917        -- We need to round the amount and account_amount according to the currency.
5918        l_claim.acctd_amount := OZF_UTILITY_PVT.CurrRound(l_claim.acctd_amount,l_functional_currency_code);
5919 
5920        -- get claim_lines_sum
5921        OPEN claim_currency_amount_sum_csr(l_claim.claim_id);
5922        FETCH claim_currency_amount_sum_csr INTO l_claim_lines_sum;
5923        CLOSE claim_currency_amount_sum_csr;
5924 
5925        IF l_claim_lines_sum is null THEN
5926           l_claim_lines_sum := 0;
5927        ELSE
5928        -- [BEGIN FIX 04/29/02] mchang: claim_currency_amount in claim lines is stored as claim currency code
5929        --                              not functional currency code.
5930           --l_claim_lines_sum := OZF_UTILITY_PVT.CurrRound(l_claim_lines_sum, l_functional_currency_code);
5931           l_claim_lines_sum := OZF_UTILITY_PVT.CurrRound(l_claim_lines_sum, l_claim.currency_code);
5932        -- [END FIX 04/29/02] mchang:
5933        END IF;
5934 
5935        -- if amount_adjusted = amount then change the status to cancell;
5936        -- This will happen if we split all the amount of a claim to its children.
5937        IF l_claim.amount = l_claim.amount_adjusted THEN
5938           l_claim.status_code    := G_CANCELLED_STATUS;
5939           l_claim.user_status_id := to_number( ozf_utility_pvt.GET_DEFAULT_USER_STATUS(
5940                                           P_STATUS_TYPE=> G_CLAIM_STATUS,
5941                                           P_STATUS_CODE=> G_CANCELLED_STATUS
5942                                       )
5943 				     );
5944 
5945        END IF;
5946 
5947        -- IF l_claim.tax_amount is not null, we need to deduct it from amount_remaining
5948        OPEN tax_amount_csr (l_claim.claim_id);
5949        FETCH tax_amount_csr into l_tax_amount;
5950        CLOSE tax_amount_csr;
5951 
5952        IF l_tax_amount is null THEN
5953           l_tax_amount := 0;
5954        END IF;
5955 
5956        IF OZF_DEBUG_HIGH_ON THEN
5957           OZF_Utility_PVT.debug_message('UC:STEP 0: Before amount_remaining:'||l_claim.amount_remaining);
5958        END IF;
5959        l_claim.amount_remaining := l_claim.amount - l_claim.amount_adjusted - l_claim.amount_settled- l_tax_amount;
5960 
5961        IF OZF_DEBUG_HIGH_ON THEN
5962           OZF_Utility_PVT.debug_message('UC:STEP 1: After amount_remaining:'||l_claim.amount_remaining);
5963           OZF_Utility_PVT.debug_message('UC:STEP 2: amount_adjusted:'||l_claim.amount_adjusted);
5964           OZF_Utility_PVT.debug_message('UC:STEP 3: amount_settled:'||l_claim.amount_settled);
5965           OZF_Utility_PVT.debug_message('UC:STEP 4: l_tax_amount:'||l_tax_amount);
5966           OZF_Utility_PVT.debug_message('UC:STEP 2: lines_sum: '||l_claim_lines_sum );
5967        END IF;
5968        -- Raise an error if amount_remaining < claim_lines_sum
5969        -- [BEGIN FIX 04/29/02] mchang: Add ABS function for claim and line amount checking in case of overpayment.
5970        -- [BEGIN FIX 05/08/02] mchang: the amount_remaining checking is not doing when claim status is from PENDING_CLOSE to CLOSED.
5971        -- -------------------------------------------------------------------------------------------
5972        -- Bug        : 2781186
5973        -- Changed by : (Uday Poluri)  Date: 03-Jun-2003
5974        -- Comments   : Add p_mode check, If it is AUTO then allow amount change on claim.
5975        --              (Relax this rule for Auto Mode)
5976        -- -------------------------------------------------------------------------------------------
5977        IF p_mode <> OZF_claim_Utility_pvt.G_AUTO_MODE THEN    --Bug:2781186
5978           IF l_claim.status_code NOT IN ('PENDING_CLOSE', 'CLOSED') AND
5979              ABS(l_claim.amount_remaining + l_claim.amount_settled) < ABS(l_claim_lines_sum) THEN
5980           -- [END FIX 04/29/02]
5981              IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
5982                 FND_MESSAGE.set_name('OZF', 'OZF_CLAIM_AMT_REM_ERR');
5983                 FND_MSG_PUB.add;
5984              END IF;
5985              RAISE FND_API.g_exc_error;
5986           END IF;
5987       END IF; --End of relaxation.
5988 
5989        -- convert amount_remaing.
5990        l_acc_amount := null;
5991        OZF_UTILITY_PVT.Convert_Currency(
5992            P_SET_OF_BOOKS_ID => l_claim.set_of_books_id,
5993            P_FROM_CURRENCY   => l_claim.currency_code,
5994            P_CONVERSION_DATE => l_claim.exchange_rate_date,
5995            P_CONVERSION_TYPE => l_claim.exchange_rate_type,
5996            P_CONVERSION_RATE => l_claim.exchange_rate,
5997            P_AMOUNT          => l_claim.amount_remaining,
5998            X_RETURN_STATUS   => l_return_status,
5999            X_ACC_AMOUNT      => l_acc_amount,
6000            X_RATE            => l_rate
6001        );
6002        IF l_return_status = FND_API.g_ret_sts_error THEN
6003           RAISE FND_API.g_exc_error;
6004        ELSIF l_return_status = FND_API.g_ret_sts_unexp_error THEN
6005           RAISE FND_API.g_exc_unexpected_error;
6006        END IF;
6007        l_claim.ACCTD_AMOUNT_REMAINING  := l_acc_amount;
6008 
6009        l_claim.amount_remaining := OZF_UTILITY_PVT.CurrRound(l_claim.amount_remaining, l_claim.currency_code);
6010        l_claim.acctd_amount_remaining := OZF_UTILITY_PVT.CurrRound(l_claim.acctd_amount_remaining,l_functional_currency_code);
6011 
6012        IF OZF_DEBUG_HIGH_ON THEN
6013          OZF_Utility_PVT.debug_message('UC:AJ STEP 11: After amount_remaining:'||l_claim.amount_remaining);
6014        END IF;
6015 
6016        -- convert amount_settled.
6017        l_acc_amount := null;
6018        OZF_UTILITY_PVT.Convert_Currency(
6019            P_SET_OF_BOOKS_ID => l_claim.set_of_books_id,
6020            P_FROM_CURRENCY   => l_claim.currency_code,
6021            P_CONVERSION_DATE => l_claim.exchange_rate_date,
6022            P_CONVERSION_TYPE => l_claim.exchange_rate_type,
6023            P_CONVERSION_RATE => l_claim.exchange_rate,
6024            P_AMOUNT          => l_claim.amount_settled,
6025            X_RETURN_STATUS   => l_return_status,
6026            X_ACC_AMOUNT      => l_acc_amount,
6027            X_RATE            => l_rate
6028        );
6029        IF l_return_status = FND_API.g_ret_sts_error THEN
6030           RAISE FND_API.g_exc_error;
6031        ELSIF l_return_status = FND_API.g_ret_sts_unexp_error THEN
6032           RAISE FND_API.g_exc_unexpected_error;
6033        END IF;
6034        l_claim.ACCTD_amount_settled  := l_acc_amount;
6035 
6036        l_claim.acctd_amount_settled := OZF_UTILITY_PVT.CurrRound(l_claim.acctd_amount_settled,l_functional_currency_code);
6037 
6038        -- convert amount_adjusted.
6039        l_acc_amount := null;
6040        OZF_UTILITY_PVT.Convert_Currency(
6041            P_SET_OF_BOOKS_ID => l_claim.set_of_books_id,
6042            P_FROM_CURRENCY   => l_claim.currency_code,
6043            P_CONVERSION_DATE => l_claim.exchange_rate_date,
6044            P_CONVERSION_TYPE => l_claim.exchange_rate_type,
6045            P_CONVERSION_RATE => l_claim.exchange_rate,
6046            P_AMOUNT          => l_claim.amount_adjusted,
6047            X_RETURN_STATUS   => l_return_status,
6048            X_ACC_AMOUNT      => l_acc_amount,
6049            X_RATE            => l_rate
6050        );
6051        IF l_return_status = FND_API.g_ret_sts_error THEN
6052           RAISE FND_API.g_exc_error;
6053        ELSIF l_return_status = FND_API.g_ret_sts_unexp_error THEN
6054           RAISE FND_API.g_exc_unexpected_error;
6055        END IF;
6056        l_claim.ACCTD_amount_adjusted  := l_acc_amount;
6057 
6058        l_claim.acctd_amount_adjusted := OZF_UTILITY_PVT.CurrRound(l_claim.acctd_amount_adjusted,l_functional_currency_code);
6059     END IF;
6060 
6061    -- If the cust_account_id has changed, we need to change the followings accordingly.
6062    -- Days due and others
6063     IF l_old_cust_acct_id <> l_claim.cust_account_id THEN
6064        get_days_due (p_cust_accout_id => l_claim.cust_account_id,
6065                      x_days_due       => l_days_due,
6066 		     x_return_status  => l_return_status);
6067        IF l_return_status = FND_API.g_ret_sts_error THEN
6068           RAISE FND_API.g_exc_error;
6069        ELSIF l_return_status = FND_API.g_ret_sts_unexp_error THEN
6070           RAISE FND_API.g_exc_unexpected_error;
6071        END IF;
6072        l_claim.DUE_DATE := TRUNC(l_claim.claim_date + l_days_due);
6073 
6074        get_customer_info(p_claim => l_claim,
6075                          x_claim => l_complete_claim,
6076 		         x_return_status  => l_return_status);
6077        IF l_return_status = FND_API.g_ret_sts_error THEN
6078           RAISE FND_API.g_exc_error;
6079        ELSIF l_return_status = FND_API.g_ret_sts_unexp_error THEN
6080           RAISE FND_API.g_exc_unexpected_error;
6081        END IF;
6082 
6083        l_claim := l_complete_claim;
6084     END IF;
6085 
6086    -- Bug4334023: User entered only shipto site then default shipto customer
6087    IF l_claim.ship_to_cust_account_id IS NULL THEN
6088       IF (l_claim.cust_shipto_acct_site_id is not null AND
6089            l_claim.cust_shipto_acct_site_id <> FND_API.G_MISS_NUM) THEN
6090             OPEN shipto_cust_account_id_csr(l_claim.cust_shipto_acct_site_id);
6091             FETCH shipto_cust_account_id_csr INTO l_claim.ship_to_cust_account_id;
6092             CLOSE shipto_cust_account_id_csr;
6093       END IF;
6094     END IF;
6095 
6096     -- normalize the customer reference number if changed
6097     -- normalize the customer reference number if changed
6098     -- Fixed: uday poluri date:03-Jun-2003. following if condition is added to avoid normalize in case of null
6099     --        customer_ref_number.
6100     IF (l_claim.customer_ref_number is not null or l_claim.customer_ref_number <> FND_API.g_miss_char) then
6101        IF (l_old_customer_ref_number IS NULL AND l_claim.customer_ref_number IS NOT NULL) OR
6102           (l_old_customer_ref_number IS NOT NULL AND l_claim.customer_ref_number IS NULL) OR
6103           l_old_customer_ref_number <> l_claim.customer_ref_number THEN
6104 
6105           OZF_Claim_Utility_PVT.Normalize_Customer_Reference(
6106              p_customer_reference => l_claim.customer_ref_number
6107             ,x_normalized_reference => l_customer_ref_norm
6108           );
6109        END IF;
6110     END IF;
6111 
6112 
6113     OZF_CLAIM_SETTLEMENT_PVT.complete_settlement(
6114        p_api_version      => 1.0
6115       ,p_init_msg_list    => FND_API.G_FALSE
6116       ,p_commit           => FND_API.G_FALSE
6117       ,p_validation_level => FND_API.G_VALID_LEVEL_FULL
6118       ,x_return_status    => l_return_status
6119       ,x_msg_data         => l_msg_data
6120       ,x_msg_count        => l_msg_count
6121       ,p_claim_rec        => l_claim
6122       ,x_claim_rec        => l_complete_claim
6123     );
6124     IF l_return_status = FND_API.g_ret_sts_error THEN
6125        RAISE FND_API.g_exc_error;
6126     ELSIF l_return_status = FND_API.g_ret_sts_unexp_error THEN
6127        RAISE FND_API.g_exc_unexpected_error;
6128     END IF;
6129     l_claim := l_complete_claim;
6130 
6131     -- Validate the record
6132     Validate_Claim (
6133        p_api_version       => l_api_version
6134       ,x_return_status     => l_return_status
6135       ,x_msg_count         => l_msg_count
6136       ,x_msg_data          => l_msg_data
6137       ,p_claim             => l_claim
6138     );
6139     IF l_return_status = FND_API.G_RET_STS_ERROR THEN
6140        RAISE FND_API.G_EXC_ERROR;
6141     ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
6142        RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6143     END IF;
6144 
6145    -- R12: eTax Uptake Make call to validate claim tax
6146    -- bugfix 4754589 added condition  l_claim.tax_action <> FND_API.G_MISS_CHAR
6147    IF  (l_claim.tax_action IS NOT NULL AND  l_claim.tax_action <> FND_API.G_MISS_CHAR) THEN
6148            OZF_CLAIM_TAX_PVT. Validate_Claim_For_Tax(
6149 	        p_api_version    => l_api_version
6150 	       ,p_init_msg_list  => FND_API.G_FALSE
6151 	       ,p_validation_level => FND_API.G_VALID_LEVEL_FULL
6152 	       ,x_return_status    => l_return_status
6153 	       ,x_msg_data          => l_msg_data
6154 	       ,x_msg_count         => l_msg_count
6155 	       ,p_claim_rec          => l_claim) ;
6156            IF l_return_status = FND_API.g_ret_sts_error THEN
6157                RAISE FND_API.g_exc_error;
6158            ELSIF l_return_status = FND_API.g_ret_sts_unexp_error THEN
6159                RAISE FND_API.g_exc_unexpected_error;
6160            END IF;
6161    END IF;
6162 
6163     OZF_CLAIM_LINE_PVT.Update_Line_Fm_Claim(
6164         p_api_version    => l_api_version
6165        ,p_init_msg_list  => FND_API.G_FALSE
6166        ,p_commit         => FND_API.G_FALSE
6167        ,p_validation_level => FND_API.G_VALID_LEVEL_FULL
6168        ,x_return_status  => l_return_status
6169        ,x_msg_data       => l_msg_data
6170        ,x_msg_count      => l_msg_count
6171        ,p_new_claim_rec  => l_claim
6172     );
6173     IF l_return_status = FND_API.g_ret_sts_error THEN
6174        RAISE FND_API.g_exc_error;
6175     ELSIF l_return_status = FND_API.g_ret_sts_unexp_error THEN
6176        RAISE FND_API.g_exc_unexpected_error;
6177     END IF;
6178 
6179 -- ----------------------------------------------------------------------------
6180     -- Bug        : 2732290
6181     -- Changed by : Uday Poluri  Date: 29-May-2003
6182     -- Comments   : if write off flag is change and status is not open then raise error.
6183     -- ----------------------------------------------------------------------------
6184     -- Varify status code if NOT OPEN then raise error.
6185 
6186     IF (l_old_write_off_flag <> l_claim.write_off_flag AND
6187        upper(l_claim.status_code) <> 'OPEN')  then
6188       --Initialize message list if p_init_msg_list is TRUE.
6189       -- mchang 12/05/2003: comment out the following message initialization code.
6190       --                    message stack only allow to initialize in the begining
6191       --                    of api, not at this point.
6192       /*
6193       IF FND_API.To_Boolean (p_init_msg_list) THEN
6194         FND_MSG_PUB.initialize;
6195       END IF;
6196       */
6197 
6198       IF FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
6199         FND_MESSAGE.Set_Name('AMS', 'OZF_CLAIM_API_NO_OPEN_STATUS');
6200         FND_MSG_PUB.ADD;
6201       END IF;
6202       RAISE FND_API.G_EXC_ERROR;
6203     END IF;
6204     -- End Bug: 2732290 -----------------------------------------------------------
6205 
6206     BEGIN
6207        OZF_claims_PKG.Update_Row(
6208           p_CLAIM_ID => l_claim.CLAIM_ID,
6209           p_OBJECT_VERSION_NUMBER => l_object_version_number,
6210           p_LAST_UPDATE_DATE => SYSDATE,
6211           p_LAST_UPDATED_BY => NVL(FND_GLOBAL.user_id,-1),
6212           p_LAST_UPDATE_LOGIN => NVL(FND_GLOBAL.conc_login_id,-1),
6213           p_REQUEST_ID => l_claim.request_id,
6214           p_PROGRAM_APPLICATION_ID => l_claim.program_application_id,
6215           p_PROGRAM_UPDATE_DATE => l_claim.program_update_date,
6216           p_PROGRAM_ID => l_claim.program_id,
6217           p_CREATED_FROM => l_claim.CREATED_FROM,
6218           p_BATCH_ID => l_claim.BATCH_ID,
6219           p_CLAIM_NUMBER => l_claim.CLAIM_NUMBER,
6220           p_CLAIM_TYPE_ID => l_claim.CLAIM_TYPE_ID,
6221           p_CLAIM_CLASS  => l_claim.CLAIM_CLASS,
6222 	       p_CLAIM_DATE => l_claim.CLAIM_DATE,
6223           p_DUE_DATE => l_claim.DUE_DATE,
6224           p_OWNER_ID   => l_claim.OWNER_ID,
6225           p_HISTORY_EVENT => l_claim.hISTORY_EVENT,
6226           p_HISTORY_EVENT_DATE => l_claim.HISTORY_EVENT_DATE,
6227           p_HISTORY_EVENT_DESCRIPTION => l_claim.HISTORY_EVENT_DESCRIPTION,
6228           p_SPLIT_FROM_CLAIM_ID => l_claim.SPLIT_FROM_CLAIM_ID,
6229           p_duplicate_claim_id  => l_claim.duplicate_claim_id,
6230           p_SPLIT_DATE => l_claim.SPLIT_DATE,
6231           p_ROOT_CLAIM_ID  => l_claim.ROOT_CLAIM_ID,
6232           p_AMOUNT => l_claim.AMOUNT,
6233           p_AMOUNT_ADJUSTED => l_claim.AMOUNT_ADJUSTED,
6234           p_AMOUNT_REMAINING => l_claim.AMOUNT_REMAINING,
6235           p_AMOUNT_SETTLED => l_claim.AMOUNT_SETTLED,
6236           p_ACCTD_AMOUNT => l_claim.ACCTD_AMOUNT,
6237           p_acctd_amount_remaining => l_claim.acctd_amount_remaining,
6238           p_acctd_AMOUNT_ADJUSTED => l_claim.acctd_AMOUNT_ADJUSTED,
6239           p_acctd_AMOUNT_SETTLED => l_claim.acctd_AMOUNT_SETTLED,
6240           p_tax_amount  => l_claim.tax_amount,
6241           p_tax_code  => l_claim.tax_code,
6242           p_tax_calculation_flag  => l_claim.tax_calculation_flag,
6243           p_CURRENCY_CODE => l_claim.CURRENCY_CODE,
6244           p_EXCHANGE_RATE_TYPE => l_claim.EXCHANGE_RATE_TYPE,
6245           p_EXCHANGE_RATE_DATE => l_claim.EXCHANGE_RATE_DATE,
6246           p_EXCHANGE_RATE => l_claim.EXCHANGE_RATE,
6247           p_SET_OF_BOOKS_ID => l_claim.SET_OF_BOOKS_ID,
6248           p_ORIGINAL_CLAIM_DATE => l_claim.ORIGINAL_CLAIM_DATE,
6249           p_SOURCE_OBJECT_ID => l_claim.SOURCE_OBJECT_ID,
6250           p_SOURCE_OBJECT_CLASS => l_claim.SOURCE_OBJECT_CLASS,
6251           p_SOURCE_OBJECT_TYPE_ID => l_claim.SOURCE_OBJECT_TYPE_ID,
6252           p_SOURCE_OBJECT_NUMBER => l_claim.SOURCE_OBJECT_NUMBER,
6253           p_CUST_ACCOUNT_ID => l_claim.CUST_ACCOUNT_ID,
6254           p_CUST_BILLTO_ACCT_SITE_ID => l_claim.CUST_BILLTO_ACCT_SITE_ID,
6255           p_cust_shipto_acct_site_id  => l_claim.cust_shipto_acct_site_id,
6256           p_LOCATION_ID => l_claim.LOCATION_ID,
6257           p_PAY_RELATED_ACCOUNT_FLAG  => l_claim.PAY_RELATED_ACCOUNT_FLAG,
6258           p_RELATED_CUST_ACCOUNT_ID  => l_claim.related_cust_account_id,
6259           p_RELATED_SITE_USE_ID  => l_claim.RELATED_SITE_USE_ID,
6260           p_RELATIONSHIP_TYPE  => l_claim.RELATIONSHIP_TYPE,
6261           p_VENDOR_ID  => l_claim.VENDOR_ID,
6262           p_VENDOR_SITE_ID  => l_claim.VENDOR_SITE_ID,
6263           p_REASON_TYPE => l_claim.REASON_TYPE,
6264           p_REASON_CODE_ID => l_claim.REASON_CODE_ID,
6265           p_TASK_TEMPLATE_GROUP_ID  => l_claim.TASK_TEMPLATE_GROUP_ID,
6266           p_STATUS_CODE => l_claim.STATUS_CODE,
6267           p_USER_STATUS_ID => l_claim.USER_STATUS_ID,
6268           p_SALES_REP_ID => l_claim.SALES_REP_ID,
6269           p_COLLECTOR_ID => l_claim.COLLECTOR_ID,
6270           p_CONTACT_ID => l_claim.CONTACT_ID,
6271           p_BROKER_ID => l_claim.BROKER_ID,
6272           p_TERRITORY_ID => l_claim.TERRITORY_ID,
6273           p_CUSTOMER_REF_DATE => l_claim.CUSTOMER_REF_DATE,
6274           p_CUSTOMER_REF_NUMBER => l_claim.CUSTOMER_REF_NUMBER,
6275           p_CUSTOMER_REF_NORMALIZED => l_customer_ref_norm,
6276           p_ASSIGNED_TO => l_claim.ASSIGNED_TO,
6277           p_RECEIPT_ID => l_claim.RECEIPT_ID,
6278           p_RECEIPT_NUMBER => l_claim.RECEIPT_NUMBER,
6279           p_DOC_SEQUENCE_ID => l_claim.DOC_SEQUENCE_ID,
6280           p_DOC_SEQUENCE_VALUE => l_claim.DOC_SEQUENCE_VALUE,
6281           p_GL_DATE    => l_claim.gl_date,
6282           p_PAYMENT_METHOD => l_claim.PAYMENT_METHOD,
6283           p_VOUCHER_ID => l_claim.VOUCHER_ID,
6284           p_VOUCHER_NUMBER => l_claim.VOUCHER_NUMBER,
6285           p_PAYMENT_REFERENCE_ID => l_claim.PAYMENT_REFERENCE_ID,
6286           p_PAYMENT_REFERENCE_NUMBER => l_claim.PAYMENT_REFERENCE_NUMBER,
6287           p_PAYMENT_REFERENCE_DATE => l_claim.PAYMENT_REFERENCE_DATE,
6288           p_PAYMENT_STATUS => l_claim.PAYMENT_STATUS,
6289           p_APPROVED_FLAG => l_claim.APPROVED_FLAG,
6290           p_APPROVED_DATE => l_claim.APPROVED_DATE,
6291           p_APPROVED_BY => l_claim.APPROVED_BY,
6292           p_SETTLED_DATE => l_claim.SETTLED_DATE,
6293           p_SETTLED_BY => l_claim.SETTLED_BY,
6294           p_effective_date  => l_claim.effective_date,
6295 	       p_CUSTOM_SETUP_ID  => l_claim.CUSTOM_SETUP_ID,
6296           p_TASK_ID  => l_claim.TASK_ID,
6297           p_COUNTRY_ID  => l_claim.COUNTRY_ID,
6298           p_ORDER_TYPE_ID  => l_claim.ORDER_TYPE_ID,
6299           p_COMMENTS   => l_claim.COMMENTS,
6300           p_ATTRIBUTE_CATEGORY => l_claim.ATTRIBUTE_CATEGORY,
6301           p_ATTRIBUTE1 => l_claim.ATTRIBUTE1,
6302           p_ATTRIBUTE2 => l_claim.ATTRIBUTE2,
6303           p_ATTRIBUTE3 => l_claim.ATTRIBUTE3,
6304           p_ATTRIBUTE4 => l_claim.ATTRIBUTE4,
6305           p_ATTRIBUTE5 => l_claim.ATTRIBUTE5,
6306           p_ATTRIBUTE6 => l_claim.ATTRIBUTE6,
6307           p_ATTRIBUTE7 => l_claim.ATTRIBUTE7,
6308           p_ATTRIBUTE8 => l_claim.ATTRIBUTE8,
6309           p_ATTRIBUTE9 => l_claim.ATTRIBUTE9,
6310           p_ATTRIBUTE10 => l_claim.ATTRIBUTE10,
6311           p_ATTRIBUTE11 => l_claim.ATTRIBUTE11,
6312           p_ATTRIBUTE12 => l_claim.ATTRIBUTE12,
6313           p_ATTRIBUTE13 => l_claim.ATTRIBUTE13,
6314           p_ATTRIBUTE14 => l_claim.ATTRIBUTE14,
6315           p_ATTRIBUTE15 => l_claim.ATTRIBUTE15,
6316           p_DEDUCTION_ATTRIBUTE_CATEGORY  => l_claim.DEDUCTION_ATTRIBUTE_CATEGORY,
6317           p_DEDUCTION_ATTRIBUTE1  => l_claim.DEDUCTION_ATTRIBUTE1,
6318           p_DEDUCTION_ATTRIBUTE2  => l_claim.DEDUCTION_ATTRIBUTE2,
6319           p_DEDUCTION_ATTRIBUTE3  => l_claim.DEDUCTION_ATTRIBUTE3,
6320           p_DEDUCTION_ATTRIBUTE4  => l_claim.DEDUCTION_ATTRIBUTE4,
6321           p_DEDUCTION_ATTRIBUTE5  => l_claim.DEDUCTION_ATTRIBUTE5,
6322           p_DEDUCTION_ATTRIBUTE6  => l_claim.DEDUCTION_ATTRIBUTE6,
6323           p_DEDUCTION_ATTRIBUTE7  => l_claim.DEDUCTION_ATTRIBUTE7,
6324           p_DEDUCTION_ATTRIBUTE8  => l_claim.DEDUCTION_ATTRIBUTE8,
6325           p_DEDUCTION_ATTRIBUTE9  => l_claim.DEDUCTION_ATTRIBUTE9,
6326           p_DEDUCTION_ATTRIBUTE10  => l_claim.DEDUCTION_ATTRIBUTE10,
6327           p_DEDUCTION_ATTRIBUTE11  => l_claim.DEDUCTION_ATTRIBUTE11,
6328           p_DEDUCTION_ATTRIBUTE12  => l_claim.DEDUCTION_ATTRIBUTE12,
6329           p_DEDUCTION_ATTRIBUTE13  => l_claim.DEDUCTION_ATTRIBUTE13,
6330           p_DEDUCTION_ATTRIBUTE14  => l_claim.DEDUCTION_ATTRIBUTE14,
6331           p_DEDUCTION_ATTRIBUTE15  => l_claim.DEDUCTION_ATTRIBUTE15,
6332           -- Bug 3313062 Fixing: ORG_ID cannot be set to null at any time.
6333 	  p_ORG_ID => l_claim.org_id,    -- R12 Enhancements
6334 	  p_LEGAL_ENTITY_ID   => l_claim.legal_entity_id,  -- R12 Enhancements
6335           p_WRITE_OFF_FLAG  => l_claim.WRITE_OFF_FLAG,
6336           p_WRITE_OFF_THRESHOLD_AMOUNT  => l_claim.WRITE_OFF_THRESHOLD_AMOUNT,
6337           p_UNDER_WRITE_OFF_THRESHOLD  => l_claim.UNDER_WRITE_OFF_THRESHOLD,
6338           p_CUSTOMER_REASON  => l_claim.CUSTOMER_REASON,
6339           p_SHIP_TO_CUST_ACCOUNT_ID => l_claim.SHIP_TO_CUST_ACCOUNT_ID,
6340           p_AMOUNT_APPLIED              => l_claim.AMOUNT_APPLIED,              --BUG:2781186
6341           p_APPLIED_RECEIPT_ID          => l_claim.APPLIED_RECEIPT_ID,          --BUG:2781186
6342           p_APPLIED_RECEIPT_NUMBER      => l_claim.APPLIED_RECEIPT_NUMBER,     --BUG:2781186
6343           p_WO_REC_TRX_ID               => l_claim.WO_REC_TRX_ID,               --Write-off Activity
6344           p_GROUP_CLAIM_ID              => l_claim.GROUP_CLAIM_ID,
6345           p_APPR_WF_ITEM_KEY            => l_claim.APPR_WF_ITEM_KEY,
6346           p_CSTL_WF_ITEM_KEY            => l_claim.CSTL_WF_ITEM_KEY,
6347           p_BATCH_TYPE                  => l_claim.BATCH_TYPE,
6348           p_close_status_id              => l_claim.close_status_id,
6349           p_open_status_id              => l_claim.open_status_id
6350     );
6351 
6352     EXCEPTION
6353        WHEN OTHERS THEN
6354          IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_unexp_error) THEN
6355              FND_MESSAGE.set_name('OZF', 'OZF_TABLE_HANDLER_ERROR');
6356              FND_MSG_PUB.add;
6357          END IF;
6358          RAISE FND_API.g_exc_error;
6359     END;
6360     l_rec_num := 1;
6361 
6362     IF l_user_sel_status_code_id IS NOT NULL THEN
6363        UPDATE ozf_claims_all
6364        SET close_status_id = l_user_sel_status_code_id
6365        WHERE claim_id = l_claim.claim_id;
6366     END IF;
6367 
6368     -- set the system status
6369     IF l_old_status_code <> l_claim.status_code THEN
6370 
6371        OZF_CLAIM_SETTLEMENT_PVT.settle_claim(
6372           p_api_version      => 1.0
6373          ,p_init_msg_list    => FND_API.G_FALSE
6374          ,p_commit           => FND_API.G_FALSE
6375          ,p_validation_level => FND_API.G_VALID_LEVEL_FULL
6376          ,x_return_status    => l_return_status
6377          ,x_msg_data         => l_msg_data
6378          ,x_msg_count        => l_msg_count
6379          ,p_claim_id         => l_claim.claim_id
6380          ,p_curr_status      => l_prev_status_code
6381          ,p_prev_status      => l_old_status_code
6382        );
6383        IF l_return_status = FND_API.g_ret_sts_error THEN
6384           RAISE FND_API.g_exc_error;
6385        ELSIF l_return_status = FND_API.g_ret_sts_unexp_error THEN
6386           RAISE FND_API.g_exc_unexpected_error;
6387        END IF;
6388     END IF;
6389 
6390     -- start bug# 4363588
6391     -- Fetch the current claim status code
6392     OPEN status_code_csr(l_claim.claim_id);
6393     FETCH status_code_csr INTO l_curr_status_code;
6394     CLOSE status_code_csr;
6395 
6396     -- Update the claim with the user selected Close status id
6397     IF l_curr_status_code = 'CLOSED'  THEN
6398        UPDATE ozf_claims_all
6399        SET user_status_id = close_status_id
6400        WHERE claim_id = l_claim.claim_id
6401        AND close_status_id IS NOT NULL;
6402     END IF;
6403     -- end bug# 4363588
6404 
6405     --Call the create history from here only after the claim update goes successfully(uday)
6406     Create_Claim_History (
6407            p_api_version    => l_api_version
6408           ,p_init_msg_list  => FND_API.G_FALSE
6409           ,p_commit         => FND_API.G_FALSE
6410           ,p_validation_level => FND_API.G_VALID_LEVEL_FULL
6411           ,x_return_status  => l_return_status
6412           ,x_msg_data       => l_msg_data
6413           ,x_msg_count      => l_msg_count
6414           ,p_claim          => l_claim
6415           ,p_event          => p_event
6416           ,x_need_to_create => l_need_to_create
6417           ,x_claim_history_id => l_claim_history_id
6418     );
6419     IF l_return_status = FND_API.g_ret_sts_error THEN
6420        RAISE FND_API.g_exc_error;
6421     ELSIF l_return_status = FND_API.g_ret_sts_unexp_error THEN
6422        RAISE FND_API.g_exc_unexpected_error;
6423     END IF;
6424 
6425 
6426     --  Create Tasks for the claim if the reason code has been changed and a history record is created.
6427     IF l_reason_code_changed THEN
6428 
6429        -- Delete the uncompleted task for this claim. The completed_flag is set to 'N'
6430        l_rec_num := 1;
6431        OPEN tasks_csr(l_claim.claim_id, 'N');
6432        LOOP
6433             FETCH tasks_csr INTO l_uncompleted_tasks_tbl(l_rec_num);
6434             EXIT WHEN tasks_csr%NOTFOUND;
6435             l_rec_num := l_rec_num + 1;
6436        END LOOP;
6437        CLOSE tasks_csr;
6438 
6439        For i in 1..l_uncompleted_tasks_tbl.count LOOP
6440 
6441            --  Leave p_object_version_number and p_delete_future_recurrences out for delete_task
6442            JTF_TASKS_PUB.delete_task(
6443                p_api_version           => l_api_version
6444               ,p_object_version_number => l_uncompleted_tasks_tbl(i).object_version_number
6445               ,p_task_id               => l_uncompleted_tasks_tbl(i).task_id
6446               ,p_delete_future_recurrences => FND_API.G_FALSE
6447               ,x_return_status         => l_return_status
6448               ,x_msg_count             => l_msg_count
6449               ,x_msg_data              => l_msg_data
6450            );
6451            IF l_return_status = FND_API.g_ret_sts_error THEN
6452               RAISE FND_API.g_exc_error;
6453            ELSIF l_return_status = FND_API.g_ret_sts_unexp_error THEN
6454               RAISE FND_API.g_exc_unexpected_error;
6455            END IF;
6456        END LOOP;
6457 
6458        -- point the completed tasks to claim_history. The completed_flag is set to 'Y'
6459        IF l_need_to_create = 'Y' THEN
6460           l_rec_num :=1;
6461           OPEN tasks_csr(l_claim.claim_id, 'Y');
6462           LOOP
6463             FETCH tasks_csr INTO l_completed_tasks_tbl(l_rec_num);
6464             EXIT WHEN tasks_csr%NOTFOUND;
6465             l_rec_num := l_rec_num + 1;
6466           END LOOP;
6467           CLOSE tasks_csr;
6468 
6469           For i in 1..l_completed_tasks_tbl.count LOOP
6470               --  change the source_object_id and source_object_type_code for the tasks.
6471 	      JTF_TASKS_PUB.update_task(
6472                 p_api_version       => l_api_version
6473                ,p_object_version_number => l_completed_tasks_tbl(i).object_version_number
6474                ,p_init_msg_list     => FND_API.g_false
6475                ,p_commit            => FND_API.g_false
6476                ,x_return_status     => l_return_status
6477                ,x_msg_count         => l_msg_count
6478                ,x_msg_data          => l_msg_data
6479                ,p_task_id           => l_completed_tasks_tbl(i).task_id
6480                ,p_source_object_type_code =>G_CLAIM_HISTORY_TYPE
6481                ,p_source_object_id  => l_claim_history_id
6482               );
6483 
6484              IF l_return_status = FND_API.g_ret_sts_error THEN
6485                 RAISE FND_API.g_exc_error;
6486              ELSIF l_return_status = FND_API.g_ret_sts_unexp_error THEN
6487                 RAISE FND_API.g_exc_unexpected_error;
6488              END IF;
6489           END LOOP;
6490        END IF;
6491 
6492 /*       --- Temp solution for updating the tasks
6493        update jtf_tasks_b
6494        set source_object_id =l_claim_history_id,
6495            source_object_type_code = G_CLAIM_HISTORY_TYPE,
6496 	   source_object_name = l_claim.claim_number
6497        where source_object_id = l_claim.claim_id
6498        and source_object_type_code = G_OBJECT_TYPE;
6499 */
6500        --  Create Tasks for the claim created if there is any
6501        IF (l_claim.task_template_group_id is not null and
6502            l_claim.task_template_group_id <> FND_API.G_MISS_NUM) THEN
6503            generate_tasks(
6504               p_task_template_group_id => l_claim.task_template_group_id
6505              ,p_owner_id       => l_claim.owner_id
6506              ,p_claim_number   => l_claim.claim_number
6507              ,p_claim_id       => l_claim.claim_id
6508              ,x_return_status  => l_return_status
6509            );
6510           IF l_return_status = FND_API.g_ret_sts_error THEN
6511              RAISE FND_API.g_exc_error;
6512           ELSIF l_return_status = FND_API.g_ret_sts_unexp_error THEN
6513              RAISE FND_API.g_exc_unexpected_error;
6514           END IF;
6515        END IF;
6516 /*
6517        -- Temp solution for update the claim history
6518        update ozf_claims_history_all
6519        set task_source_object_id = l_claim_history_id,
6520            task_source_object_type_code = G_CLAIM_HISTORY_TYPE
6521         where task_source_object_id = l_claim.claim_id
6522 	and   task_source_object_id = G_OBJECT_TYPE
6523 	and   claim_id = l_claim.claim_id;
6524 
6525 */
6526        -- update the task_source_object_id and task_source_object_type in the ozf_claim_history_all table.
6527        IF l_need_to_create = 'Y' THEN
6528           l_rec_num := 1;
6529           OPEN claim_history_tbl_csr(l_claim.claim_id);
6530           LOOP
6531              FETCH claim_history_tbl_csr INTO l_claim_history_tbl(l_rec_num);
6532              EXIT WHEN claim_history_tbl_csr%NOTFOUND;
6533              l_rec_num := l_rec_num + 1;
6534           END LOOP;
6535           CLOSE claim_history_tbl_csr;
6536 
6537           For i in 1..l_claim_history_tbl.count LOOP
6538 --           l_claim_history_rec := OZF_claims_history_PVT.claims_history_rec_type;
6539             l_claim_history_rec.object_version_number := l_claim_history_tbl(i).object_version_number;
6540             l_claim_history_rec.claim_history_id := l_claim_history_tbl(i).claim_history_id;
6541             l_claim_history_rec.task_source_object_id := l_claim_history_id;
6542             l_claim_history_rec.task_source_object_type_code := G_CLAIM_HISTORY_TYPE;
6543 
6544             OZF_claims_history_PVT.Update_claims_history(
6545                P_Api_Version_Number => 1.0,
6546                P_Init_Msg_List      => FND_API.G_FALSE,
6547                P_Commit             => FND_API.G_FALSE,
6548                p_validation_level   => FND_API.G_VALID_LEVEL_FULL,
6549                x_return_status      => l_return_status,
6550                x_msg_count          => l_msg_count,
6551                x_msg_data           => l_msg_data,
6552                P_CLAIMS_HISTORY_Rec => l_claim_history_rec,
6553                X_Object_Version_Number => l_hist_obj_ver_num
6554             );
6555 
6556 	    IF l_return_status = FND_API.g_ret_sts_error THEN
6557                RAISE FND_API.g_exc_error;
6558             ELSIF l_return_status = FND_API.g_ret_sts_unexp_error THEN
6559                RAISE FND_API.g_exc_unexpected_error;
6560             END IF;
6561           END LOOP;
6562        END IF;
6563     END IF;
6564 
6565     IF OZF_DEBUG_HIGH_ON THEN
6566        ozf_utility_PVT.debug_message('Before create access');
6567     END IF;
6568 
6569     IF l_owner_changed THEN
6570      IF l_access_list.count > 0 THEN
6571        -- [BEGIN OF BUG 3835800 Fiing]
6572        l_access_comp_list := l_access_list;
6573        For i in 1..l_access_list.LAST LOOP
6574          IF i > 1 THEN
6575             FOR j IN 1..(i-1) LOOP
6576                IF l_access_list(i).user_or_role_id = l_access_comp_list(j).user_or_role_id THEN
6577                   l_dup_resource := TRUE;
6578                END IF;
6579             END LOOP;
6580          END IF;
6581 
6582          IF NOT l_dup_resource THEN
6583          -- [END OF BUG 3835800 Fiing]
6584            l_access_list(i).act_access_to_object_id := l_claim.claim_id;
6585            ams_access_pvt.create_access(
6586                p_api_version => l_api_version
6587               ,p_init_msg_list => fnd_api.g_false
6588               ,p_validation_level => p_validation_level
6589               ,x_return_status => l_return_status
6590               ,x_msg_count => x_msg_count
6591               ,x_msg_data => x_msg_data
6592               ,p_commit => fnd_api.g_false
6593               ,p_access_rec => l_access_list(i)
6594               ,x_access_id => l_access_id);
6595            IF l_return_status = fnd_api.g_ret_sts_error THEN
6596               RAISE fnd_api.g_exc_error;
6597            ELSIF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
6598               RAISE fnd_api.g_exc_unexpected_error;
6599            END IF;
6600          END IF; -- end of l_dup_resource checking BUG  3835800 Fiing
6601        END LOOP;
6602      END IF;
6603     END IF;
6604 
6605    -------------------------------------------------
6606    -- Raise Business Event (claim status change ) --
6607    -------------------------------------------------
6608    IF l_old_status_code <> l_claim.status_code THEN
6609       OZF_CLAIM_SETTLEMENT_PVT.Raise_Business_Event(
6610           p_api_version            => l_api_version
6611          ,p_init_msg_list          => FND_API.g_false
6612          ,p_commit                 => FND_API.g_false
6613          ,p_validation_level       => FND_API.g_valid_level_full
6614          ,x_return_status          => l_return_status
6615          ,x_msg_data               => x_msg_data
6616          ,x_msg_count              => x_msg_count
6617 
6618          ,p_claim_id               => l_claim.claim_id
6619          ,p_old_status             => l_old_status_code
6620          ,p_new_status             => l_claim.status_code
6621          ,p_event_name             => 'oracle.apps.ozf.claim.updateStatus'
6622       );
6623       IF l_return_status = FND_API.g_ret_sts_error THEN
6624          RAISE FND_API.g_exc_error;
6625       ELSIF l_return_status = FND_API.g_ret_sts_unexp_error THEN
6626          RAISE FND_API.g_exc_unexpected_error;
6627       END IF;
6628    END IF;
6629 
6630     -- pass the new version number
6631     x_object_version_number := l_object_version_number;
6632 
6633     --Standard check of commit
6634     IF FND_API.To_Boolean ( p_commit ) THEN
6635         COMMIT WORK;
6636     END IF;
6637     -- Debug Message
6638     IF OZF_DEBUG_LOW_ON THEN
6639         FND_MESSAGE.Set_Name('OZF','OZF_API_DEBUG_MESSAGE');
6640         FND_MESSAGE.Set_Token('TEXT',l_full_name||': End');
6641         FND_MSG_PUB.Add;
6642     END IF;
6643     --Standard call to get message count and if count=1, get the message
6644     FND_MSG_PUB.Count_And_Get (
6645         p_encoded => FND_API.G_FALSE,
6646         p_count => x_msg_count,
6647         p_data  => x_msg_data
6648     );
6649 EXCEPTION
6650     WHEN FND_API.G_EXC_ERROR THEN
6651 --        IF ( NOT G_UPDATE_CALLED ) THEN
6652            ROLLBACK TO  Update_Claim_PVT;
6653 --        END IF;
6654         x_return_status := FND_API.G_RET_STS_ERROR;
6655         -- Standard call to get message count and if count=1, get the message
6656         FND_MSG_PUB.Count_And_Get (
6657             p_encoded => FND_API.G_FALSE,
6658             p_count => x_msg_count,
6659             p_data  => x_msg_data
6660         );
6661     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
6662  --       IF ( NOT G_UPDATE_CALLED ) THEN
6663            ROLLBACK TO  Update_Claim_PVT;
6664  --       END IF;
6665         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6666         -- Standard call to get message count and if count=1, get the message
6667         FND_MSG_PUB.Count_And_Get (
6668             p_encoded => FND_API.G_FALSE,
6669             p_count => x_msg_count,
6670             p_data  => x_msg_data
6671         );
6672     WHEN OTHERS THEN
6673  --       IF ( NOT G_UPDATE_CALLED ) THEN
6674            ROLLBACK TO  Update_Claim_PVT;
6675  --       END IF;
6676         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6677         IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
6678         THEN
6679             FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
6680         END IF;
6681         -- Standard call to get message count and if count=1, get the message
6682         FND_MSG_PUB.Count_And_Get (
6683             p_encoded => FND_API.G_FALSE,
6684             p_count => x_msg_count,
6685             p_data  => x_msg_data
6686         );
6687 --
6688 END Update_Claim;
6689 
6690 ---------------------------------------------------------------------
6691 -- PROCEDURE
6692 --    Validate_Claim
6693 --
6694 -- PURPOSE
6695 --    Validate a claim code record.
6696 --
6697 -- PARAMETERS
6698 --    p_claim : the claim code record to be validated
6699 --
6700 -- NOTES
6701 --
6702 ----------------------------------------------------------------------
6703 PROCEDURE  Validate_Claim (
6704     p_api_version            IN   NUMBER
6705    ,p_init_msg_list          IN   VARCHAR2 := FND_API.G_FALSE
6706    ,p_validation_level       IN   NUMBER   := FND_API.G_VALID_LEVEL_FULL
6707    ,x_return_status          OUT NOCOPY  VARCHAR2
6708    ,x_msg_count              OUT NOCOPY  NUMBER
6709    ,x_msg_data               OUT NOCOPY  VARCHAR2
6710    ,p_claim                 IN  claim_rec_type
6711    )
6712 IS
6713 l_api_name          CONSTANT VARCHAR2(30) := 'Validate_Claim';
6714 l_api_version       CONSTANT NUMBER := 1.0;
6715 l_full_name         CONSTANT VARCHAR2(60) := G_PKG_NAME ||'.'|| l_api_name;
6716 --
6717 l_resource_id       number;
6718 l_user_id           number;
6719 l_login_user_id     number;
6720 l_login_user_status varchar2(30);
6721 l_Error_Msg         varchar2(2000);
6722 l_Error_Token       varchar2(80);
6723 l_claim             claim_rec_type := p_claim;
6724 l_return_status     varchar2(30);
6725 
6726 -- Fix for bug 5374006
6727 CURSOR party_csr(p_cust_id in number,
6728                  p_relation_type in varchar2,
6729 		 p_party_id in number) IS
6730 SELECT count(p.party_id)
6731 FROM   hz_parties p,
6732        hz_relationships r,
6733        hz_cust_accounts c
6734 WHERE  p.party_id = r.subject_id
6735 AND    r.relationship_code = p_relation_type
6736 AND    r.object_id = c.party_id
6737 AND    c.cust_account_id = p_cust_id
6738 AND    p.party_id = p_party_id;
6739 
6740 l_count number := 0;
6741 
6742 CURSOR cust_site_csr(p_cust_id in number,
6743                      p_site_use_code in varchar2,
6744 		     p_site_use_id in number) IS
6745 SELECT count(hcsu.site_use_id)
6746 FROM   hz_cust_accounts hca,
6747        hz_cust_acct_sites hcas,
6748        hz_cust_site_uses hcsu
6749 WHERE  hcas.cust_acct_site_id = hcsu.cust_acct_site_id
6750 AND    hcas.cust_account_id = hca.cust_account_id
6751 AND    hcsu.status = 'A'
6752 AND    hca.cust_account_id = p_cust_id
6753 AND    hcsu.site_use_code = p_site_use_code
6754 AND    hcsu.site_use_id = p_site_use_id;
6755 
6756 -- Add cursor for matching actions and task.
6757 CURSOR action_count_csr(p_reason_code_id in number,
6758                         p_task_template_id in number) IS
6759 SELECT count(t.task_template_group_id)
6760 FROM jtf_task_temp_groups_vl t,
6761      ozf_reasons r
6762 WHERE t.source_object_type_code = 'OZF_CLAM'
6763 AND r.active_flag = 'T'
6764 AND t.task_template_group_id = r.task_template_group_id
6765 AND NVL(t.start_date_active, SYSDATE) <= SYSDATE
6766 AND NVL(t.end_date_active, SYSDATE) >= SYSDATE
6767 AND r.reason_code_id = p_reason_code_id
6768 AND r.task_template_group_id = p_task_template_id;
6769 
6770 CURSOR status_count_csr(p_status_code    in varchar2,
6771 			p_user_status_id in number) IS
6772 SELECT count(user_status_id)
6773 FROM   ams_user_statuses_vl
6774 WHERE  system_status_type = G_CLAIM_STATUS
6775 AND    system_status_code = p_status_code
6776 AND    user_status_id = p_user_status_id
6777 AND    enabled_flag = 'Y';
6778 
6779 CURSOR sales_rep_num_csr (p_id in NUMBER) IS
6780 SELECT count(salesrep_id)
6781 FROM   jtf_rs_salesreps s,
6782        jtf_rs_resource_extns r,
6783        fnd_lookups l
6784 WHERE  s.start_date_active <= SYSDATE
6785 AND NVL(s.end_date_active, SYSDATE) >= SYSDATE
6786 AND s.salesrep_id = p_id
6787 AND s.resource_id = r.resource_id
6788 AND r.category = l.lookup_code
6789 AND l.lookup_type ='JTF_RS_RESOURCE_CATEGORY';
6790 
6791 l_sales_rep_num number := 0;
6792 
6793 -- cursor to check payment_method
6794 CURSOR payment_method_csr (p_lookup_code in VARCHAR) IS
6795 SELECT count(lookup_code)
6796 FROM ozf_lookups
6797 WHERE lookup_type = 'OZF_PAYMENT_METHOD'
6798 AND   lookup_code = p_lookup_code;
6799 
6800 l_lookup_code_count  number := 0;
6801 
6802 CURSOR order_type_count_csr(p_id in number) is
6803 SELECT count(transaction_type_id)
6804 FROM oe_transaction_types_vl
6805 WHERE transaction_type_code = 'ORDER'
6806 AND order_category_code IN ('MIXED', 'RETURN')
6807 AND default_inbound_line_type_id IS NOT NULL
6808 AND transaction_type_id = p_id;
6809 
6810 l_order_type_count number :=0;
6811 
6812 CURSOR rel_cust_csr(p_cust_id IN NUMBER, p_rel_cust_id IN NUMBER) IS
6813 SELECT count(related_cust_account_id)
6814 FROM   hz_cust_acct_relate_all
6815 WHERE  cust_account_id = p_cust_id
6816 AND    related_cust_account_id = p_rel_cust_id;
6817 
6818 BEGIN
6819     -- Standard begin of API savepoint
6820     SAVEPOINT  Validate_Claim_PVT;
6821     -- Standard call to check for call compatibility.
6822     IF NOT FND_API.Compatible_API_Call (
6823         l_api_version,
6824         p_api_version,
6825         l_api_name,
6826         G_PKG_NAME)
6827     THEN
6828         RAISE  FND_API.G_EXC_UNEXPECTED_ERROR;
6829     END IF;
6830 
6831     -- Debug Message
6832     IF OZF_DEBUG_LOW_ON THEN
6833         FND_MESSAGE.Set_Name('OZF','OZF_API_DEBUG_MESSAGE');
6834         FND_MESSAGE.Set_Token('TEXT',l_full_name||': Start');
6835         FND_MSG_PUB.Add;
6836     END IF;
6837 
6838     --Initialize message list if p_init_msg_list is TRUE.
6839     IF FND_API.To_Boolean (p_init_msg_list) THEN
6840         FND_MSG_PUB.initialize;
6841     END IF;
6842 
6843     -- Initialize API return status to sucess
6844     x_return_status := FND_API.G_RET_STS_SUCCESS;
6845 
6846     IF p_validation_level >= JTF_PLSQL_API.g_valid_level_item THEN
6847        Check_Claim_Items(
6848           p_claim_rec         => l_claim,
6849           p_validation_mode   => JTF_PLSQL_API.g_update,
6850           x_return_status     => l_return_status
6851        );
6852 
6853        IF l_return_status = FND_API.G_RET_STS_ERROR THEN
6854           RAISE FND_API.G_EXC_ERROR;
6855        ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
6856           RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6857        END IF;
6858     END IF;
6859 
6860     -- Raise an error
6861     -- Due_date must be later than the claim_date
6862     IF trunc(l_claim.DUE_DATE) < trunc(l_claim.claim_date) THEN
6863           IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
6864              FND_MESSAGE.set_name('OZF', 'OZF_CLAIM_DUE_DATE_ERR');
6865              FND_MSG_PUB.add;
6866           END IF;
6867 	  IF OZF_DEBUG_HIGH_ON THEN
6868              ozf_utility_PVT.debug_message('claim date: ' || l_claim.claim_date);
6869              ozf_utility_PVT.debug_message('due date: ' || l_claim.DUE_DATE);
6870           END IF;
6871           RAISE FND_API.G_EXC_ERROR;
6872     END IF;
6873 
6874     -- Raise an error
6875     -- if the current status code is not duplicate but the duplicate_claim_id is not null
6876     IF ((l_claim.status_code <> G_DUPLICATE_STATUS) AND
6877        (l_claim.duplicate_claim_id is not null) AND
6878        (l_claim.duplicate_claim_id <> FND_API.G_MISS_NUM)) THEN
6879        IF FND_MSG_PUB.Check_Msg_level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
6880           FND_MESSAGE.Set_Name('OZF','OZF_CLAIM_CANT_DUP');
6881           FND_MSG_PUB.Add;
6882        END IF;
6883        RAISE FND_API.G_EXC_ERROR;
6884     END IF;
6885 
6886     -- Raise an error
6887     -- if billto_site and shipto_site do not belong to the customer
6888     IF (l_claim.cust_account_id is not null AND
6889         l_claim.cust_account_id <> FND_API.G_MISS_NUM) THEN
6890 
6891 	-- check cust_billto_acct_site_id
6892 	IF (l_claim.cust_billto_acct_site_id is not null AND
6893 	    l_claim.cust_account_id <> FND_API.G_MISS_NUM) THEN
6894 
6895 	   OPEN cust_site_csr(l_claim.cust_account_id, 'BILL_TO', l_claim.cust_billto_acct_site_id);
6896 	   FETCH cust_site_csr INTO l_count;
6897 	   CLOSE cust_site_csr;
6898 
6899 	   IF (l_count = 0) THEN
6900               IF FND_MSG_PUB.Check_Msg_level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
6901 	         FND_MESSAGE.Set_Name('OZF','OZF_CLAIM_BILL_TO_ST_WRNG');
6902                  FND_MSG_PUB.Add;
6903               END IF;
6904 	      RAISE FND_API.G_EXC_ERROR;
6905 	   END IF;
6906 	END IF;
6907 
6908       -- 4334023: check for unrelated shipto if profile does not allow unrelated
6909       IF l_claim.ship_to_cust_account_id IS NOT NULL AND G_ALLOW_UNREL_SHIPTO_FLAG = 'N'
6910               AND l_claim.ship_to_cust_account_id  <>  l_claim.cust_account_id THEN
6911           l_count := 0;
6912 	    OPEN rel_cust_csr(l_claim.cust_account_id, l_claim.ship_to_cust_account_id);
6913 	    FETCH rel_cust_csr INTO l_count;
6914 	    CLOSE rel_cust_csr;
6915 
6916 	    IF (l_count = 0) THEN
6917 	       IF FND_MSG_PUB.Check_Msg_level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
6918 	          FND_MESSAGE.Set_Name('OZF','OZF_CLAIM_UNRELATED_SHIPTO');
6919                   FND_MSG_PUB.Add;
6920                END IF;
6921 	       RAISE FND_API.G_EXC_ERROR;
6922            END IF;
6923       END IF;
6924 
6925     -- Bug 5498540 -- Removed validation for SHIP_TO Site address
6926 	-- check cust_shipto_acct_site_id
6927   /*IF (l_claim.cust_shipto_acct_site_id is not null AND
6928 	    l_claim.cust_shipto_acct_site_id <> FND_API.G_MISS_NUM) THEN
6929 
6930 	    l_count := 0;
6931 	    OPEN cust_site_csr(l_claim.ship_to_cust_account_id, 'SHIP_TO', l_claim.cust_shipto_acct_site_id);
6932 	    FETCH cust_site_csr INTO l_count;
6933 	    CLOSE cust_site_csr;
6934 
6935 	    IF (l_count = 0) THEN
6936 	       IF FND_MSG_PUB.Check_Msg_level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
6937 	          FND_MESSAGE.Set_Name('OZF','OZF_CLAIM_SHIP_TO_ST_WRNG');
6938                   FND_MSG_PUB.Add;
6939                END IF;
6940 	       RAISE FND_API.G_EXC_ERROR;
6941            END IF;
6942 	END IF; */
6943 
6944 /* phase out this check since
6945 
6946 	-- check contact_id
6947 	IF (l_claim.contact_id is not null AND
6948 	    l_claim.contact_id <> FND_API.G_MISS_NUM) THEN
6949 
6950 	    l_count := 0;
6951 	    OPEN party_csr(l_claim.cust_account_id, 'CONTACT_OF', l_claim.contact_id);
6952 	    FETCH party_csr INTO l_count;
6953 	    CLOSE party_csr;
6954 
6955 	    IF (l_count = 0) THEN
6956 	       IF FND_MSG_PUB.Check_Msg_level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
6957 	          FND_MESSAGE.Set_Name('OZF','OZF_CLAIM_CONTACT_WRNG');
6958                   FND_MSG_PUB.Add;
6959 	       END IF;
6960                RAISE FND_API.G_EXC_ERROR;
6961             END IF;
6962 	END IF;
6963  -- end of phase out this check */
6964 
6965 	-- check broker_id
6966         IF (l_claim.broker_id is not null AND
6967 	    l_claim.broker_id <> FND_API.G_MISS_NUM) THEN
6968 
6969 	    l_count := 0;
6970 	    OPEN party_csr(l_claim.cust_account_id, 'BROKER_OF', l_claim.broker_id);
6971 	    FETCH party_csr INTO l_count;
6972 	    CLOSE party_csr;
6973 
6974 	    IF (l_count = 0) THEN
6975 	       IF FND_MSG_PUB.Check_Msg_level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
6976 	          FND_MESSAGE.Set_Name('OZF','OZF_CLAIM_BROKER_WRNG');
6977                   FND_MSG_PUB.Add;
6978 	       END IF;
6979                RAISE FND_API.G_EXC_ERROR;
6980             END IF;
6981 	END IF;
6982 
6983 	-- check sales_rep
6984     -- 04-MAR-2002 mchang updated: comment out the following section to avoid the sales_rep_id checking
6985     --   since the sales_rep_id might not be valied over time when claim is updated.
6986     /*
6987    	  IF (l_claim.sales_rep_id is not NULL AND
6988             l_claim.sales_rep_id <> FND_API.G_MISS_NUM) THEN
6989             OPEN sales_rep_num_csr(l_claim.sales_rep_id);
6990             FETCH sales_rep_num_csr INTO l_sales_rep_num;
6991             CLOSE sales_rep_num_csr;
6992 
6993             IF l_sales_rep_num = 0 THEN
6994                IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
6995                   FND_MESSAGE.set_name('OZF', 'OZF_CLAIM_SALES_REP_MISSING');
6996                   FND_MSG_PUB.add;
6997                END IF;
6998                RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6999             END IF;
7000        END IF;
7001      */
7002 
7003     ELSE
7004        IF FND_MSG_PUB.Check_Msg_level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
7005           FND_MESSAGE.Set_Name('OZF','OZF_CLAIM_CUST_ID_MISSING');
7006           FND_MSG_PUB.Add;
7007        END IF;
7008        RAISE FND_API.G_EXC_ERROR;
7009     END IF;
7010 
7011 
7012     -- 04-MAR-2002 mchang updated: comment out the following section to avoid the status code checking
7013     --   since the status_code and user_status_id mathing is done from the on-line screen already.
7014     /*
7015     l_count := 0;
7016     -- Check whether status_code and user_status_id matches
7017     -- Note: Neither Status_code nor user_status_id of a claim can be null at any given time
7018     OPEN status_count_csr(l_claim.status_code, l_claim.user_status_id);
7019     FETCH status_count_csr INTO l_count;
7020     CLOSE status_count_csr;
7021 
7022     IF l_count <> 1 THEN
7023        IF FND_MSG_PUB.Check_Msg_level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
7024           FND_MESSAGE.Set_Name('OZF','OZF_CLAIM_STATUS_NOT_MAT');
7025           FND_MSG_PUB.Add;
7026 
7027 	   FND_MESSAGE.Set_Name('OZF','OZF_API_DEBUG_MESSAGE');
7028         FND_MESSAGE.Set_Token('TEXT','code: '||l_claim.status_code||' id:'||l_claim.user_status_id);
7029         FND_MSG_PUB.Add;
7030        END IF;
7031        RAISE FND_API.G_EXC_ERROR;
7032     END IF;
7033     */
7034 
7035     -- Check to see whether the reason_code_id and task_template_id matches.
7036     -- 04-MAR-2002 mchang updated: comment out the following section to avoid the reason_code_id and reason_code_id checking
7037     --   since the reason_code_id and reason_code_id might not be valied over time when the claim is updated.
7038     /*
7039     IF l_claim.reason_code_id is not null AND l_claim.reason_code_id <> FND_API.G_MISS_NUM AND
7040        l_claim.task_template_group_id is not null AND l_claim.task_template_group_id <> FND_API.G_MISS_NUM THEN
7041        l_count := 0;
7042 
7043        OPEN action_count_csr(l_claim.reason_code_id, l_claim.task_template_group_id);
7044        FETCH action_count_csr INTO l_count;
7045        CLOSE action_count_csr;
7046 
7047        IF l_count <> 1 THEN
7048           IF FND_MSG_PUB.Check_Msg_level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
7049 	     FND_MESSAGE.Set_Name('OZF','OZF_CLAIM_ACTION_NOT_MAT');
7050              FND_MSG_PUB.Add;
7051 	  END IF;
7052           RAISE FND_API.G_EXC_ERROR;
7053        END IF;
7054     END IF;
7055     */
7056 
7057    -- raise an error if owner_id is not found
7058    IF (l_claim.owner_id is null OR
7059        l_claim.owner_id = FND_API.G_MISS_NUM) THEN
7060        IF FND_MSG_PUB.Check_Msg_level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
7061 	  FND_MESSAGE.Set_Name('OZF','OZF_CLAIM_OWNER_NOT_FOUND');
7062           FND_MSG_PUB.Add;
7063        END IF;
7064        RAISE FND_API.G_EXC_ERROR;
7065     END IF;
7066 
7067    -- raise an error if status_code is open and amount_remaining is 0
7068    IF (l_claim.status_code = G_OPEN_STATUS AND
7069        l_claim.amount_remaining = 0) THEN
7070        IF FND_MSG_PUB.Check_Msg_level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
7071 	  FND_MESSAGE.Set_Name('OZF','OZF_CLAIM_AMT_ZERO_WOPEN');
7072           FND_MSG_PUB.Add;
7073        END IF;
7074        RAISE FND_API.G_EXC_ERROR;
7075    END IF;
7076 
7077    -- raise an error if amount is <0 and claim_class = Claim or DEDUCTION
7078    -- raise an error if amount is >0 and claim_class = OVERPAYMENT or charge
7079    IF (l_claim.amount < 0 AND
7080        (l_claim.claim_class = G_CLAIM_CLASS OR
7081         l_claim.claim_class = G_DEDUCTION_CLASS)) THEN
7082        IF FND_MSG_PUB.Check_Msg_level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
7083           FND_MESSAGE.Set_Name('OZF','OZF_CLAIM_AMT_NEG');
7084           FND_MSG_PUB.Add;
7085        END IF;
7086        RAISE FND_API.G_EXC_ERROR;
7087    END IF;
7088 
7089    IF (l_claim.amount > 0 AND
7090        (l_claim.claim_class = G_OVERPAYMENT_CLASS OR
7091         l_claim.claim_class = G_CHARGE_CLASS )) THEN
7092        IF FND_MSG_PUB.Check_Msg_level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
7093           FND_MESSAGE.Set_Name('OZF','OZF_CLAIM_AMT_POS_OPM');
7094           FND_MSG_PUB.Add;
7095        END IF;
7096        RAISE FND_API.G_EXC_ERROR;
7097    END IF;
7098 
7099    -- if source_object_id is set, all info about source_object has to be set
7100    IF (l_claim.claim_class = G_DEDUCTION_CLASS AND
7101        (l_claim.source_object_id IS NOT NULL AND
7102        l_claim.source_object_id <> FND_API.G_MISS_NUM)) THEN
7103 
7104       IF ((l_claim.source_object_class IS NULL OR
7105            l_claim.source_object_class = FND_API.G_MISS_CHAR) OR
7106 	  (l_claim.source_object_type_id IS NULL OR
7107            l_claim.source_object_type_id = FND_API.G_MISS_NUM) OR
7108           (l_claim.source_object_number IS NULL OR
7109            l_claim.source_object_number = FND_API.G_MISS_CHAR)) THEN
7110 
7111           IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
7112              FND_MESSAGE.set_name('OZF', 'OZF_CLAIM_SRC_INFO_MISSING');
7113              FND_MSG_PUB.add;
7114           END IF;
7115           RAISE FND_API.g_exc_error;
7116       END IF;
7117    END IF;
7118 
7119    -- check payment_method
7120    IF l_claim.payment_method IS NOT NULL AND
7121       l_claim.payment_method <> FND_API.G_MISS_CHAR THEN
7122 
7123        OPEN payment_method_csr(l_claim.payment_method);
7124        FETCH payment_method_csr into l_lookup_code_count;
7125        CLOSE payment_method_csr;
7126 
7127        IF l_lookup_code_count = 0 THEN
7128           IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
7129              FND_MESSAGE.set_name('OZF', 'OZF_CLAIM_PAY_MTHD_WRG');
7130              FND_MSG_PUB.add;
7131           END IF;
7132           RAISE FND_API.g_exc_error;
7133       END IF;
7134    END IF;
7135 
7136    -- check pay_related_account_flag
7137    IF (l_claim.pay_related_account_flag IS NOT NULL AND
7138        l_claim.pay_related_account_flag <> FND_API.G_MISS_CHAR) THEN
7139 
7140       IF (l_claim.pay_related_account_flag <> 'F' AND
7141           l_claim.pay_related_account_flag <> 'T') THEN
7142 
7143           IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
7144              FND_MESSAGE.set_name('OZF', 'OZF_CLAIM_PAY_REL_FLG_WRG');
7145              FND_MSG_PUB.add;
7146           END IF;
7147           RAISE FND_API.g_exc_error;
7148       END IF;
7149    END IF;
7150 
7151    -- check order_type_id
7152    IF (l_claim.order_type_id IS NOT NULL AND
7153        l_claim.order_type_id <> FND_API.G_MISS_NUM) THEN
7154 
7155        OPEN order_type_count_csr(l_claim.order_type_id);
7156        FETCH order_type_count_csr into l_order_type_count;
7157        CLOSE order_type_count_csr;
7158        IF l_order_type_count = 0 then
7159 	  IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
7160              FND_MESSAGE.set_name('OZF', 'OZF_CLAIM_ODTYPE_WRG');
7161              FND_MSG_PUB.add;
7162           END IF;
7163           RAISE FND_API.g_exc_error;
7164       END IF;
7165    END IF;
7166 
7167    -- Debug Message
7168    IF OZF_DEBUG_LOW_ON THEN
7169        FND_MESSAGE.Set_Name('OZF','OZF_API_DEBUG_MESSAGE');
7170        FND_MESSAGE.Set_Token('TEXT',l_full_name||': End');
7171        FND_MSG_PUB.Add;
7172    END IF;
7173    --Standard call to get message count and if count=1, get the message
7174    FND_MSG_PUB.Count_And_Get (
7175        p_encoded => FND_API.G_FALSE,
7176        p_count => x_msg_count,
7177        p_data  => x_msg_data
7178    );
7179 EXCEPTION
7180     WHEN FND_API.G_EXC_ERROR THEN
7181         ROLLBACK TO  Validate_Claim_PVT;
7182         x_return_status := FND_API.G_RET_STS_ERROR;
7183         -- Standard call to get message count and if count=1, get the message
7184         FND_MSG_PUB.Count_And_Get (
7185             p_encoded => FND_API.G_FALSE,
7186             p_count => x_msg_count,
7187             p_data  => x_msg_data
7188         );
7189     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
7190         ROLLBACK TO  Validate_Claim_PVT;
7191         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
7192         -- Standard call to get message count and if count=1, get the message
7193         FND_MSG_PUB.Count_And_Get (
7194             p_encoded => FND_API.G_FALSE,
7195             p_count => x_msg_count,
7196             p_data  => x_msg_data
7197         );
7198     WHEN OTHERS THEN
7199         ROLLBACK TO  Validate_Claim_PVT;
7200         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
7201         IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
7202         THEN
7203             FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
7204         END IF;
7205         -- Standard call to get message count and if count=1, get the message
7206         FND_MSG_PUB.Count_And_Get (
7207             p_encoded => FND_API.G_FALSE,
7208             p_count => x_msg_count,
7209             p_data  => x_msg_data
7210         );
7211 END Validate_Claim;
7212 
7213 ---------------------------------------------------------------------
7214 -- PROCEDURE
7215 --    Check_Claim_Common_Element
7216 --
7217 -- PURPOSE
7218 --    The precedure does validations on claim elements that was not enforced by UI at claim creation.
7219 --    These elements are: claim_type_id, reason_code_id, cust_account_id
7220 --    It should only be called when either of the above field are not mendatory from the inputs.
7221 --
7222 -- PARAMETERS
7223 --    p_validate_claim : the claim code record to be validated
7224 --
7225 -- NOTES
7226 --
7227 ----------------------------------------------------------------------
7228 PROCEDURE  Check_Claim_Common_Element (
7229     p_api_version            IN   NUMBER
7230    ,p_init_msg_list          IN   VARCHAR2 := FND_API.G_FALSE
7231    ,p_validation_level       IN   NUMBER   := FND_API.G_VALID_LEVEL_FULL
7232    ,x_return_status          OUT NOCOPY  VARCHAR2
7233    ,x_msg_count              OUT NOCOPY  NUMBER
7234    ,x_msg_data               OUT NOCOPY  VARCHAR2
7235    ,p_claim                  IN  claim_rec_type
7236    ,x_claim                  OUT NOCOPY claim_rec_type
7237    ,p_mode                   IN  VARCHAR2 := OZF_claim_Utility_pvt.G_AUTO_MODE
7238    )
7239 IS
7240 l_api_name          CONSTANT VARCHAR2(30) := 'Check_Claim_Common_Element';
7241 l_api_version       CONSTANT NUMBER := 1.0;
7242 l_full_name         CONSTANT VARCHAR2(60) := G_PKG_NAME ||'.'|| l_api_name;
7243 --
7244 l_claim             claim_rec_type := p_claim;
7245 l_resource_id       number;
7246 l_user_id           number;
7247 l_login_user_id     number;
7248 l_login_user_status varchar2(30);
7249 l_Error_Msg         varchar2(2000);
7250 l_Error_Token       varchar2(80);
7251 l_return_status     varchar2(30);
7252 
7253 --CURSOR claim_type_id_csr IS
7254 --SELECT claim_type_id
7255 --FROM   ozf_sys_parameters;
7256 
7257 -- This cursor checks whether a given claim_type_id is of deduction class.
7258 -- and whether it is in the database.
7259 --CURSOR number_of_claim_type_id_csr(p_claim_type_id in number) IS
7260 --SELECT count(claim_type_id)
7261 --FROM   ozf_claim_types_all_b
7262 --WHERE  claim_type_id = p_claim_type_id;
7263 
7264 --l_number_of_claim_type_id  NUMBER;
7265 
7266 --CURSOR reason_code_id_csr IS
7267 --SELECT reason_code_id
7268 --FROM   ozf_sys_parameters;
7269 
7270 -- This cursor checks whether a given reason_type is in the database
7271 --CURSOR number_of_reason_code_id_csr(p_reason_code_id in number) IS
7272 --SELECT count(reason_code_id)
7273 --FROM   ozf_reason_codes_all_b
7274 --WHERE  reason_code_id = p_reason_code_id;
7275 
7276 --l_number_of_reason_code_id number;
7277 
7278 CURSOR num_of_cust_acctid_csr(l_id in number) IS
7279 SELECT count(hca.cust_account_id)
7280 FROM  hz_cust_accounts hca
7281 WHERE hca.cust_account_id = l_id;
7282 -- remove this condition for now AND hca.status = 'A'
7283 
7284 l_number_of_cust number;
7285 
7286 BEGIN
7287    -- Standard begin of API savepoint
7288     SAVEPOINT  Check_Clm_Cmn_Element_PVT;
7289     -- Standard call to check for call compatibility.
7290     IF NOT FND_API.Compatible_API_Call (
7291         l_api_version,
7292         p_api_version,
7293         l_api_name,
7294         G_PKG_NAME)
7295     THEN
7296         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
7297     END IF;
7298 
7299     -- Debug Message
7300     IF OZF_DEBUG_LOW_ON THEN
7301         FND_MESSAGE.Set_Name('OZF','OZF_API_DEBUG_MESSAGE');
7302         FND_MESSAGE.Set_Token('TEXT',l_full_name||': Start');
7303         FND_MSG_PUB.Add;
7304     END IF;
7305 
7306     --Initialize message list if p_init_msg_list is TRUE.
7307     IF FND_API.To_Boolean (p_init_msg_list) THEN
7308         FND_MSG_PUB.initialize;
7309     END IF;
7310 
7311     -- Initialize API return status to sucess
7312     x_return_status := FND_API.G_RET_STS_SUCCESS;
7313 
7314 
7315     -- Begin of  minimum required data for claims in general.
7316     -- We will check: claim_type_id, reason_code_id
7317 
7318 -- 11.5.10(uday) Removed check for Claim type id and Reason code id
7319 -- as these values are defaulted from Claim Defaults.
7320     -- Check claim_type_id
7321 --    IF l_claim.claim_type_id is NULL OR
7322 --       l_claim.claim_type_id = FND_API.G_MISS_NUM  THEN
7323 
7324 --      OPEN claim_type_id_csr;
7325 --      FETCH claim_type_id_csr into l_claim.claim_type_id;
7326 --      CLOSE claim_type_id_csr;
7327 --      IF l_claim.claim_type_id is NULL THEN
7328 --         IF FND_MSG_PUB.Check_Msg_level (FND_MSG_PUB.g_msg_lvl_error) THEN
7329 --            FND_MESSAGE.Set_Name('OZF','OZF_CLAIM_CLAIM_TYPE_MISSING');
7330 --            FND_MSG_PUB.Add;
7331 --	 END IF;
7332 --	 RAISE FND_API.G_EXC_ERROR;
7333 --      END IF;
7334 --   ELSE
7335 --      -- check whether the claim_type_id is in the database.
7336 --      OPEN number_of_claim_type_id_csr(l_claim.claim_type_id);
7337 --      FETCH number_of_claim_type_id_csr INTO l_number_of_claim_type_id;
7338 --      CLOSE number_of_claim_type_id_csr;
7339 --
7340 --      IF l_number_of_claim_type_id = 0 THEN
7341 --         IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
7342 --            FND_MESSAGE.set_name('OZF', 'OZF_CLAIM_CLAIM_TYPE_NOT_IN_DB');
7343 --            FND_MSG_PUB.add;
7344 --         END IF;
7345 --         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
7346 --      END IF;
7347 --   END IF;
7348 
7349 --   -- Check reason_code_id
7350 --   IF l_claim.reason_code_id is NULL OR
7351 --      l_claim.reason_code_id = FND_API.G_MISS_NUM  THEN
7352 
7353 --   ELSE
7354       -- check whether reason code exists
7355 --      OPEN number_of_reason_code_id_csr(l_claim.reason_code_id);
7356 --      FETCH number_of_reason_code_id_csr INTO l_number_of_reason_code_id;
7357 --      CLOSE number_of_reason_code_id_csr;
7358 
7359 --      IF l_number_of_reason_code_id = 0 THEN
7360 --         IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
7361 --            FND_MESSAGE.set_name('OZF', 'OZF_CLAIM_REASON_CD_NOT_IN_DB');
7362 --            FND_MSG_PUB.add;
7363 --         END IF;
7364 --         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
7365 --      END IF;
7366 --   END IF;
7367 
7368    -- Check cust_account_id
7369    IF l_claim.cust_account_id is NULL OR
7370       l_claim.cust_account_id = FND_API.G_MISS_NUM  THEN
7371 
7372       IF FND_MSG_PUB.Check_Msg_level (FND_MSG_PUB.g_msg_lvl_error) THEN
7373             FND_MESSAGE.Set_Name('OZF','OZF_CLAIM_CUST_ID_MISSING');
7374             FND_MSG_PUB.Add;
7375       END IF;
7376       RAISE FND_API.G_EXC_ERROR;
7377    ELSE
7378       -- check whether the customer is in the database.
7379       OPEN num_of_cust_acctid_csr(l_claim.cust_account_id);
7380       FETCH num_of_cust_acctid_csr INTO l_number_of_cust;
7381       CLOSE num_of_cust_acctid_csr;
7382 
7383       IF l_number_of_cust = 0 THEN
7384          IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
7385             FND_MESSAGE.set_name('OZF', 'OZF_CLAIM_CUST_NOT_IN_DB');
7386 	    FND_MSG_PUB.add;
7387          END IF;
7388          RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
7389       END IF;
7390    END IF;
7391    -- End of minimum checking
7392 
7393    -- -----------------------------------------------------------
7394    -- Bug        : 2710047
7395    -- Changed by : Uday Poluri          Date: 28-May-2003
7396    -- Comments   : Call get_write_off_eligibility flag
7397    -- -----------------------------------------------------------
7398 
7399       IF (p_mode = OZF_claim_Utility_pvt.G_AUTO_MODE)
7400       THEN
7401          get_write_off_eligibility( p_cust_account_id  => l_claim.cust_account_id
7402                                   , px_currency_code  => l_claim.currency_code
7403                                   , px_exchange_rate_type => l_claim.exchange_rate_type
7404                                   , px_exchange_rate_date => l_claim.exchange_rate_date
7405                                   , p_exchange_rate => l_claim.exchange_rate
7406                                   , p_set_of_books_id => l_claim.set_of_books_id
7407                                   , p_amount => l_claim.amount
7408                                   , px_acctd_amount => l_claim.acctd_amount
7409                                   , px_acctd_amount_remaining => l_claim.acctd_amount_remaining
7410                                   , x_write_off_flag => l_claim.write_off_flag
7411                                   , x_write_off_threshold_amount => l_claim.write_off_threshold_amount
7412                                   , x_under_write_off_threshold => l_claim.under_write_off_threshold
7413                                    ,x_return_status => l_return_status);
7414         IF l_return_status = FND_API.g_ret_sts_error THEN
7415           RAISE FND_API.g_exc_error;
7416         ELSIF l_return_status = FND_API.g_ret_sts_unexp_error THEN
7417           RAISE FND_API.g_exc_unexpected_error;
7418         END IF;
7419       END IF;
7420    -- -----------------------------------------------------------
7421    -- End of Bug  : 2710047
7422    -- -----------------------------------------------------------
7423 
7424    x_claim := l_claim;
7425     -- Debug Message
7426     IF OZF_DEBUG_LOW_ON THEN
7427         FND_MESSAGE.Set_Name('OZF','OZF_API_DEBUG_MESSAGE');
7428         FND_MESSAGE.Set_Token('TEXT',l_full_name||': End');
7429         FND_MSG_PUB.Add;
7430     END IF;
7431     --Standard call to get message count and if count=1, get the message
7432     FND_MSG_PUB.Count_And_Get (
7433         p_encoded => FND_API.G_FALSE,
7434         p_count => x_msg_count,
7435         p_data  => x_msg_data
7436     );
7437 EXCEPTION
7438     WHEN FND_API.G_EXC_ERROR THEN
7439         ROLLBACK TO  Check_Clm_Cmn_Element_PVT;
7440         x_return_status := FND_API.G_RET_STS_ERROR;
7441         -- Standard call to get message count and if count=1, get the message
7442         FND_MSG_PUB.Count_And_Get (
7443             p_encoded => FND_API.G_FALSE,
7444             p_count => x_msg_count,
7445             p_data  => x_msg_data
7446         );
7447     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
7448         ROLLBACK TO  Check_Clm_Cmn_Element_PVT;
7449         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
7450         -- Standard call to get message count and if count=1, get the message
7451         FND_MSG_PUB.Count_And_Get (
7452             p_encoded => FND_API.G_FALSE,
7453             p_count => x_msg_count,
7454             p_data  => x_msg_data
7455         );
7456     WHEN OTHERS THEN
7457         ROLLBACK TO  Check_Clm_Cmn_Element_PVT;
7458         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
7459         IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
7460         THEN
7461             FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
7462         END IF;
7463         -- Standard call to get message count and if count=1, get the message
7464         FND_MSG_PUB.Count_And_Get (
7465             p_encoded => FND_API.G_FALSE,
7466             p_count => x_msg_count,
7467             p_data  => x_msg_data
7468         );
7469 END Check_Claim_Common_Element;
7470 
7471 ---------------------------------------------------------------------
7472 -- PROCEDURE
7473 --    Create_Claim_tbl
7474 --
7475 -- PURPOSE
7476 --    Create mutiple claims at one time.
7477 --
7478 -- PARAMETERS
7479 --    p_claim_tbl     : the new record to be inserted
7480 --
7481 -- NOTES: for all the claims to be created
7482 --    1. object_version_number will be set to 1.
7483 --    2. If claim_number is passed in, the uniqueness will be checked.
7484 --       Raise exception in case of duplicates.
7485 ---------------------------------------------------------------------
7486 PROCEDURE  Create_Claim_tbl (
7487     p_api_version            IN    NUMBER
7488    ,p_init_msg_list          IN    VARCHAR2 := FND_API.G_FALSE
7489    ,p_commit                 IN    VARCHAR2 := FND_API.G_FALSE
7490    ,p_validation_level       IN    NUMBER   := FND_API.G_VALID_LEVEL_FULL
7491 
7492    ,x_return_status          OUT NOCOPY   VARCHAR2
7493    ,x_msg_data               OUT NOCOPY   VARCHAR2
7494    ,x_msg_count              OUT NOCOPY   NUMBER
7495    ,p_claim_tbl              IN    claim_tbl_type
7496    ,x_error_index            OUT NOCOPY   NUMBER
7497 )
7498 IS
7499 l_api_name          CONSTANT VARCHAR2(30) := 'Create_Claim_tbl';
7500 l_api_version       CONSTANT NUMBER := 1.0;
7501 l_full_name         CONSTANT VARCHAR2(60) := G_PKG_NAME ||'.'|| l_api_name;
7502 --
7503 l_claim             claim_rec_type;
7504 l_x_claim           claim_rec_type;
7505 l_msg_data         varchar2(2000);
7506 l_Msg_count         number;
7507 l_Error_Token       varchar2(80);
7508 l_return_status     varchar2(30);
7509 l_mode              varchar2(30) := OZF_claim_Utility_pvt.G_MANU_MODE;
7510 
7511 l_default_curr_code varchar2(30):= fnd_profile.value('JTF_PROFILE_DEFAULT_CURRENCY');
7512 l_claim_id number;
7513 l_err_row number:=0;
7514 BEGIN
7515    -- Standard begin of API savepoint
7516     SAVEPOINT  Create_Claim_Tbl_PVT;
7517     -- Standard call to check for call compatibility.
7518     IF NOT FND_API.Compatible_API_Call (
7519         l_api_version,
7520         p_api_version,
7521         l_api_name,
7522         G_PKG_NAME)
7523     THEN
7524         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
7525     END IF;
7526     x_error_index := -1;
7527 
7528     -- Debug Message
7529     IF OZF_DEBUG_LOW_ON THEN
7530         FND_MESSAGE.Set_Name('OZF','OZF_API_DEBUG_MESSAGE');
7531         FND_MESSAGE.Set_Token('TEXT',l_full_name||': Start');
7532         FND_MSG_PUB.Add;
7533     END IF;
7534 
7535     --Initialize message list if p_init_msg_list is TRUE.
7536     IF FND_API.To_Boolean (p_init_msg_list) THEN
7537         FND_MSG_PUB.initialize;
7538     END IF;
7539 
7540     -- Initialize API return status to sucess
7541     x_return_status := FND_API.G_RET_STS_SUCCESS;
7542 
7543     For i in 1..p_claim_tbl.count LOOP
7544 
7545 	    l_claim := p_claim_tbl(i);
7546 
7547 	    -- default claim_type_id, reason_code_id if necessary.
7548 	    OZF_claim_PVT.Check_Claim_Common_Element (
7549           p_api_version      => 1.0,
7550           p_init_msg_list    => FND_API.G_FALSE,
7551           p_validation_level => FND_API.G_VALID_LEVEL_FULL,
7552           x_Return_Status      => l_return_status,
7553           x_Msg_Count          => l_msg_count,
7554           x_Msg_Data           => l_msg_data,
7555           p_claim              => l_claim,
7556           x_claim              => l_x_claim,
7557           p_mode               => l_mode
7558          );
7559       -- Check return status from the above procedure call
7560       IF l_return_status = FND_API.G_RET_STS_ERROR THEN
7561          x_error_index := i;
7562          RAISE FND_API.G_EXC_ERROR;
7563       ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
7564          x_error_index := i;
7565          RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
7566       END IF;
7567 
7568       l_claim := l_x_claim;
7569 
7570 	   -- default currency code if necessary.
7571       -- Default the transaction currency code to functional currency code
7572       -- if it's null.
7573       IF (l_claim.currency_code is NULL OR
7574           l_claim.currency_code = FND_API.G_MISS_CHAR)THEN
7575           l_claim.currency_code := l_default_curr_code;
7576       END IF;
7577 
7578 --		l_claim.claim_class := G_CLAIM_CLASS;
7579       --
7580       -- Calling Private package: Create_claim
7581       -- Hint: Primary key needs to be returned
7582       OZF_claim_PVT.Create_Claim(
7583          P_Api_Version        => 1.0,
7584          P_Init_Msg_List      => FND_API.G_FALSE,
7585          P_Commit             => FND_API.G_FALSE,
7586          P_Validation_Level   => FND_API.G_VALID_LEVEL_FULL,
7587          X_Return_Status      => l_return_status,
7588          X_Msg_Count          => l_msg_count,
7589          X_Msg_Data           => l_msg_data,
7590          P_claim              => l_claim,
7591          X_CLAIM_ID           => l_claim_id
7592       );
7593 
7594       -- Check return status from the above procedure call
7595       IF l_return_status = FND_API.G_RET_STS_ERROR THEN
7596          x_error_index := i;
7597 	 RAISE FND_API.G_EXC_ERROR;
7598       ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
7599          x_error_index := i;
7600 	 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
7601       END IF;
7602 
7603 	 END LOOP;
7604 
7605     -- Debug Message
7606     IF OZF_DEBUG_LOW_ON THEN
7607         FND_MESSAGE.Set_Name('OZF','OZF_API_DEBUG_MESSAGE');
7608         FND_MESSAGE.Set_Token('TEXT',l_full_name||': End');
7609         FND_MSG_PUB.Add;
7610     END IF;
7611     --Standard call to get message count and if count=1, get the message
7612     FND_MSG_PUB.Count_And_Get (
7613         p_encoded => FND_API.G_FALSE,
7614         p_count => x_msg_count,
7615         p_data  => x_msg_data
7616     );
7617 EXCEPTION
7618     WHEN FND_API.G_EXC_ERROR THEN
7619         ROLLBACK TO  Create_Claim_Tbl_PVT;
7620         x_return_status := FND_API.G_RET_STS_ERROR;
7621 /*	IF FND_MSG_PUB.Check_Msg_level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
7622            FND_MESSAGE.Set_Name('OZF','OZF_CLAIM_TBL_ERR');
7623            FND_MESSAGE.Set_Token('ROW',l_err_row);
7624            FND_MSG_PUB.Add;
7625         END IF;
7626 */
7627         -- Standard call to get message count and if count=1, get the message
7628         FND_MSG_PUB.Count_And_Get (
7629             p_encoded => FND_API.G_FALSE,
7630             p_count => x_msg_count,
7631             p_data  => x_msg_data
7632         );
7633     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
7634         ROLLBACK TO  Create_Claim_Tbl_PVT;
7635         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
7636 /*	IF FND_MSG_PUB.Check_Msg_level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
7637            FND_MESSAGE.Set_Name('OZF','OZF_CLAIM_TBL_ERR');
7638            FND_MESSAGE.Set_Token('ROW',l_err_row);
7639            FND_MSG_PUB.Add;
7640         END IF;
7641 */
7642         -- Standard call to get message count and if count=1, get the message
7643         FND_MSG_PUB.Count_And_Get (
7644             p_encoded => FND_API.G_FALSE,
7645             p_count => x_msg_count,
7646             p_data  => x_msg_data
7647         );
7648     WHEN OTHERS THEN
7649         ROLLBACK TO  Create_Claim_Tbl_PVT;
7650         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
7651 /*        IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
7652         THEN
7653 	   FND_MESSAGE.Set_Name('OZF','OZF_CLAIM_TBL_ERR');
7654            FND_MESSAGE.Set_Token('ROW',l_err_row);
7655            FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
7656         END IF;
7657 */        -- Standard call to get message count and if count=1, get the message
7658         FND_MSG_PUB.Count_And_Get (
7659             p_encoded => FND_API.G_FALSE,
7660             p_count => x_msg_count,
7661             p_data  => x_msg_data
7662         );
7663 END Create_Claim_tbl;
7664 
7665 
7666 
7667 
7668 ---------------------------------------------------------------------
7669 -- PROCEDURE
7670 --    Update_Claim_tbl
7671 --
7672 -- PURPOSE
7673 --    Update mutiple claims at one time from summary screen.
7674 --
7675 -- PARAMETERS
7676 --    p_claim_tbl     : the new record to be inserted
7677 --
7678 -- NOTES: for all the claims to be created
7679 --    1. object_version_number will be set to 1.
7680 --    2. If claim_number is passed in, the uniqueness will be checked.
7681 --       Raise exception in case of duplicates.
7682 --
7683 -- BUG         : 2732290
7684 -- CHANAGED BY : (Uday Poluri)
7685 -- COMMENTS    : New procedure to Update claim details from Claim Summary Screen
7686 --
7687 ---------------------------------------------------------------------
7688 PROCEDURE  Update_Claim_tbl (
7689     p_api_version            IN    NUMBER
7690    ,p_init_msg_list          IN    VARCHAR2 := FND_API.G_FALSE
7691    ,p_commit                 IN    VARCHAR2 := FND_API.G_FALSE
7692    ,p_validation_level       IN    NUMBER   := FND_API.G_VALID_LEVEL_FULL
7693 
7694    ,x_return_status          OUT NOCOPY  VARCHAR2
7695    ,x_msg_data               OUT NOCOPY  VARCHAR2
7696    ,x_msg_count              OUT NOCOPY  NUMBER
7697    ,p_claim_tbl              IN    claim_tbl_type
7698 )
7699 IS
7700 l_api_name          CONSTANT VARCHAR2(30) := 'Update_Claim_tbl';
7701 l_api_version       CONSTANT NUMBER := 1.0;
7702 l_full_name         CONSTANT VARCHAR2(60) := G_PKG_NAME ||'.'|| l_api_name;
7703 --l_object_version_number  number := 1;
7704 l_object_version_number  number;
7705 --
7706 l_claim             claim_rec_type;
7707 l_msg_data          varchar2(2000);
7708 l_Msg_count         number;
7709 l_Error_Token       varchar2(80);
7710 l_return_status     varchar2(30);
7711 
7712 l_default_curr_code varchar2(30):= fnd_profile.value('JTF_PROFILE_DEFAULT_CURRENCY');
7713 l_claim_id number;
7714 l_err_row number:=0;
7715 BEGIN
7716    -- Standard begin of API savepoint
7717    SAVEPOINT  Update_Claim_Tbl_PVT;
7718    -- Standard call to check for call compatibility.
7719    IF NOT FND_API.Compatible_API_Call (
7720        l_api_version,
7721        p_api_version,
7722        l_api_name,
7723        G_PKG_NAME) THEN
7724      RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
7725    END IF;
7726 
7727    -- Debug Message
7728    IF FND_MSG_PUB.Check_Msg_level (FND_MSG_PUB.G_MSG_LVL_DEBUG_LOW) THEN
7729      FND_MESSAGE.Set_Name('OZF','OZF_API_DEBUG_MESSAGE');
7730      FND_MESSAGE.Set_Token('TEXT',l_full_name||': Start');
7731      FND_MSG_PUB.Add;
7732    END IF;
7733 
7734    --Initialize message list if p_init_msg_list is TRUE.
7735    IF FND_API.To_Boolean (p_init_msg_list) THEN
7736      FND_MSG_PUB.initialize;
7737    END IF;
7738 
7739    -- Initialize API return status to sucess
7740    x_return_status := FND_API.G_RET_STS_SUCCESS;
7741 
7742    For i in 1..p_claim_tbl.count LOOP
7743      l_claim := p_claim_tbl(i);
7744 
7745      -- Varify status code if NOT OPEN then raise error.
7746      IF upper(l_claim.status_code) <> 'OPEN' then
7747        IF FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
7748          l_err_row := i;
7749          FND_MESSAGE.Set_Name('OZF', 'OZF_CLAIM_API_NO_OPEN_STATUS');
7750          FND_MESSAGE.Set_Token('ROW',l_err_row);
7751          FND_MSG_PUB.ADD;
7752        END IF;
7753        RAISE FND_API.G_EXC_ERROR;
7754      END IF;
7755 
7756      -- If incoming value for write-off flag is unchecked then set the values in database is 'N'.
7757      IF (l_claim.write_off_flag is NULL OR
7758        l_claim.write_off_flag = FND_API.G_MISS_CHAR)THEN
7759        l_claim.write_off_flag := 'F';
7760      END IF;
7761 
7762      -- Calling Private package: Update_claim
7763      OZF_claim_PVT.Update_Claim (
7764           p_api_version       => l_api_version
7765          ,p_init_msg_list     => FND_API.G_FALSE
7766          ,p_commit            => FND_API.G_FALSE
7767          ,p_validation_level  => FND_API.G_VALID_LEVEL_FULL
7768          ,x_return_status     => l_return_status
7769          ,x_msg_data          => l_msg_data
7770          ,x_msg_count         => l_msg_count
7771          ,p_claim             => l_claim
7772          ,p_event             => 'UPDATE'
7773          ,p_mode              => OZF_claim_Utility_pvt.G_AUTO_MODE
7774          ,x_object_version_number  => l_object_version_number
7775        );
7776 
7777      IF l_return_status = FND_API.g_ret_sts_error THEN
7778        l_err_row := i;
7779        RAISE FND_API.g_exc_error;
7780      ELSIF l_return_status = FND_API.g_ret_sts_unexp_error THEN
7781        l_err_row := i;
7782        RAISE FND_API.g_exc_unexpected_error;
7783      END IF;
7784    END LOOP;
7785 
7786    -- Debug Message
7787    IF FND_MSG_PUB.Check_Msg_level (FND_MSG_PUB.G_MSG_LVL_DEBUG_LOW) THEN
7788      FND_MESSAGE.Set_Name('OZF','OZF_API_DEBUG_MESSAGE');
7789      FND_MESSAGE.Set_Token('TEXT',l_full_name||': End');
7790      FND_MSG_PUB.Add;
7791    END IF;
7792    --Standard call to get message count and if count=1, get the message
7793    FND_MSG_PUB.Count_And_Get (
7794        p_encoded => FND_API.G_FALSE,
7795        p_count => x_msg_count,
7796        p_data  => x_msg_data
7797    );
7798 EXCEPTION
7799     WHEN FND_API.G_EXC_ERROR THEN
7800         ROLLBACK TO  Update_Claim_Tbl_PVT;
7801         x_return_status := FND_API.G_RET_STS_ERROR;
7802 	  IF FND_MSG_PUB.Check_Msg_level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
7803            FND_MESSAGE.Set_Name('OZF','OZF_CLAIM_TBL_ERR');
7804            FND_MESSAGE.Set_Token('ROW',l_err_row);
7805            FND_MSG_PUB.Add;
7806         END IF;
7807         -- Standard call to get message count and if count=1, get the message
7808         FND_MSG_PUB.Count_And_Get (
7809             p_encoded => FND_API.G_FALSE,
7810             p_count => x_msg_count,
7811             p_data  => x_msg_data
7812         );
7813     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
7814         ROLLBACK TO  Update_Claim_Tbl_PVT;
7815         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
7816 	  IF FND_MSG_PUB.Check_Msg_level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
7817            FND_MESSAGE.Set_Name('OZF','OZF_CLAIM_TBL_ERR');
7818            FND_MESSAGE.Set_Token('ROW',l_err_row);
7819            FND_MSG_PUB.Add;
7820         END IF;
7821         -- Standard call to get message count and if count=1, get the message
7822         FND_MSG_PUB.Count_And_Get (
7823             p_encoded => FND_API.G_FALSE,
7824             p_count => x_msg_count,
7825             p_data  => x_msg_data
7826         );
7827     WHEN OTHERS THEN
7828         ROLLBACK TO  Update_Claim_Tbl_PVT;
7829         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
7830         IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
7831 	     FND_MESSAGE.Set_Name('OZF','OZF_CLAIM_TBL_ERR');
7832            FND_MESSAGE.Set_Token('ROW',l_err_row);
7833            FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
7834         END IF;
7835         -- Standard call to get message count and if count=1, get the message
7836         FND_MSG_PUB.Count_And_Get (
7837             p_encoded => FND_API.G_FALSE,
7838             p_count => x_msg_count,
7839             p_data  => x_msg_data
7840         );
7841 END Update_Claim_tbl;
7842 -- --End Bug: 2732290 -----------------------------------------
7843 
7844 END OZF_CLAIM_PVT;