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