[Home] [Help]
PACKAGE BODY: APPS.OKL_AM_CNTRCT_LN_TRMNT_PVT
Source
1 PACKAGE BODY okl_am_cntrct_ln_trmnt_pvt AS
2 /* $Header: OKLRCLTB.pls 120.38.12010000.9 2009/01/05 20:40:31 rkuttiya ship $ */
3 -- GLOBAL VARIABLES
4
5 g_level_procedure CONSTANT NUMBER := fnd_log.level_procedure;
6 g_level_exception CONSTANT NUMBER := fnd_log.level_exception;
7 g_level_statement CONSTANT NUMBER := fnd_log.level_statement;
8 g_module_name CONSTANT VARCHAR2 (500)
9 := 'okl.am.plsql.okl_am_cntrct_ln_trmnt_pvt.';
10 g_amort_complete_flag VARCHAR2 (1) := 'N';
11
12 --------------- TO DO -----------------------------------------------------
13
14 --invalidating trns once the lines are updated. -- differed for now
15
16 --There may be a change becos of the requirement that mass rebook wont work
17 --synchronously with booking the contract and so there may be a delay in the
18 --booking of the contract. Soln may be to spawn a WF which checks when
19 --contract status changes and then calls the activate insur api.
20
21 --------------------------------------------------------------------------
22
23 -- Start of comments
24 --
25 -- Procedure Name : check_lease_or_loan
26 -- Desciption : Checks if lease or loan
27 -- Business Rules :
28 -- Parameters :
29 -- Version : 1.0
30 -- History : RMUNJULU 02-JAN-03 2724951 created
31 -- : RMUNJULU 06-MAR-03 Performance Fix Replaced K_HDR_FULL
32 --
33 -- End of comments
34 PROCEDURE check_lease_or_loan (
35 p_khr_id IN NUMBER,
36 x_lease_loan_type OUT NOCOPY VARCHAR2
37 )
38 IS
39 -- Get the K scs_code and deal_type
40 -- RMUNJULU 06-MAR-03 Performance Fix Replaced K_HDR_FULL
41 CURSOR k_deal_type_csr (
42 p_khr_id IN NUMBER
43 )
44 IS
45 SELECT CHR.scs_code,
46 khr.deal_type
47 FROM okc_k_headers_v CHR,
48 okl_k_headers_v khr
49 WHERE CHR.ID = p_khr_id AND khr.ID = CHR.ID;
50
51 l_lease_loan_type VARCHAR2 (30) := '$';
52 k_deal_type_rec k_deal_type_csr%ROWTYPE;
53 l_module_name VARCHAR2 (500)
54 := g_module_name || 'check_lease_or_loan';
55 is_debug_exception_on BOOLEAN
56 := okl_debug_pub.check_log_on (l_module_name, g_level_exception);
57 is_debug_procedure_on BOOLEAN
58 := okl_debug_pub.check_log_on (l_module_name, g_level_procedure);
59 is_debug_statement_on BOOLEAN
60 := okl_debug_pub.check_log_on (l_module_name, g_level_statement);
61 BEGIN
62 IF (is_debug_procedure_on)
63 THEN
64 okl_debug_pub.log_debug (g_level_procedure,
65 l_module_name,
66 'Begin(+)'
67 );
68 END IF;
69
70 IF (is_debug_statement_on)
71 THEN
72 okl_debug_pub.log_debug (g_level_statement,
73 l_module_name,
74 'In param, p_khr_id: ' || p_khr_id
75 );
76 END IF;
77
78 OPEN k_deal_type_csr (p_khr_id);
79
80 FETCH k_deal_type_csr
81 INTO k_deal_type_rec;
82
83 IF k_deal_type_csr%FOUND
84 THEN
85 -- Set the lease or loan type
86 -- (If scs_code = Lease and deal_type = Loan then Loan)
87 IF k_deal_type_rec.scs_code = 'LEASE'
88 AND NVL (k_deal_type_rec.deal_type, '?') LIKE 'LOAN%'
89 THEN
90 l_lease_loan_type := 'LOAN';
91 ELSIF k_deal_type_rec.scs_code = 'LEASE'
92 AND NVL (k_deal_type_rec.deal_type, '?') LIKE 'LEASE%'
93 THEN
94 l_lease_loan_type := 'LEASE';
95 ELSIF k_deal_type_rec.scs_code = 'LOAN'
96 THEN
97 l_lease_loan_type := 'LOAN';
98 END IF;
99 END IF;
100
101 CLOSE k_deal_type_csr;
102
103 x_lease_loan_type := l_lease_loan_type;
104
105 IF (is_debug_procedure_on)
106 THEN
107 okl_debug_pub.log_debug (g_level_procedure,
108 l_module_name,
109 'End(-)'
110 );
111 END IF;
112 EXCEPTION
113 WHEN OTHERS
114 THEN
115 IF k_deal_type_csr%ISOPEN
116 THEN
117 CLOSE k_deal_type_csr;
118 END IF;
119
120 -- Set the oracle error message
121 okl_api.set_message (p_app_name => g_app_name_1,
122 p_msg_name => g_unexpected_error,
123 p_token1 => g_sqlcode_token,
124 p_token1_value => SQLCODE,
125 p_token2 => g_sqlerrm_token,
126 p_token2_value => SQLERRM
127 );
128
129 IF (is_debug_exception_on)
130 THEN
131 okl_debug_pub.log_debug (g_level_exception,
132 l_module_name,
133 'EXCEPTION :'
134 || 'OTHERS, SQLCODE: '
135 || SQLCODE
136 || ' , SQLERRM : '
137 || SQLERRM
138 );
139 END IF;
140 END check_lease_or_loan;
141
142
143 -- Start of comments
144 --
145 -- Procedure Name : update_quote_status
146 -- Desciption : UPDATE TERMINATION QUOTES FROM STATUS ACCEPTED TO
147 -- Business Rules :
148 -- Parameters :
149 -- Version : 1.0
150 -- History : RBRUNO BUG 6801022
151 -- 02-sep-2008 rbruno bug 7129269 fix -
152 -- End of comments
153
154 PROCEDURE update_quote_status(p_term_rec IN term_rec_type) IS
155
156 lp_qtev_rec OKL_TRX_QUOTES_PUB.qtev_rec_type;
157 lx_qtev_rec OKL_TRX_QUOTES_PUB.qtev_rec_type;
158
159 l_return_status VARCHAR2(1) := OKL_API.G_RET_STS_SUCCESS;
160
161 l_quote_status VARCHAR2(200) := 'COMPLETE';--'OKL_QUOTE_STATUS'
162
163 lx_msg_count NUMBER;
164 lx_msg_data VARCHAR2(2000);
165
166 l_qst_code varchar2(200);
167
168 l_tmt_status_code VARCHAR2(200);
169
170 lx_return_status VARCHAR2(1) := OKL_API.G_RET_STS_SUCCESS;
171 lx_quotes_found VARCHAR2(1) := 'N';
172 l_api_version NUMBER := 1;
173 l_module_name VARCHAR2 (500)
174 := g_module_name || 'update_quote_status';
175 is_debug_exception_on BOOLEAN
176 := okl_debug_pub.check_log_on (l_module_name, g_level_exception);
177 is_debug_procedure_on BOOLEAN
178 := okl_debug_pub.check_log_on (l_module_name, g_level_procedure);
179 is_debug_statement_on BOOLEAN
180 := okl_debug_pub.check_log_on (l_module_name, g_level_statement);
181 --:= okl_debug_pub.check_log_on (l_module_name, g_level_exception);
182
183
184 -- Fetch tmt_status_code
185
186 CURSOR c_tmt_status_code_csr (p_qte_id IN NUMBER) IS
187 SELECT tmt_status_code
188 FROM okl_trx_contracts trx
189 WHERE trx.qte_id = p_qte_id
190 --rkuttiya added for 12.1.1 Multi GAAP Project
191 AND trx.representation_type = 'PRIMARY';
192 --
193
194 --- Fetch quote satus
195
196 CURSOR k_quotes_csr (p_qte_id IN NUMBER) IS
197 SELECT qst_code
198 FROM okl_trx_quotes_v
199 WHERE id = p_qte_id
200 AND (qtp_code LIKE 'TER%' OR qtp_code LIKE 'RES%');
201
202 BEGIN
203 IF (is_debug_procedure_on)
204 THEN
205 okl_debug_pub.log_debug (g_level_procedure,
206 l_module_name,
207 'Begin(+)'
208 );
209 END IF;
210
211 --Get termination quote status
212
213 OPEN k_quotes_csr(p_term_rec.p_quote_id);
214 FETCH k_quotes_csr into l_qst_code;
215 CLOSE k_quotes_csr;
216
217 IF (is_debug_statement_on)
218 THEN
219 okl_debug_pub.log_debug (g_level_statement,
220 l_module_name,
221 'quote id value :p_term_rec.p_quote_id: '
222 || p_term_rec.p_quote_id
223 );
224 END IF;
225 --check whether cutrrent quote is in status accepted
226 IF p_term_rec.p_quote_id is not null and l_qst_code = 'ACCEPTED' THEN
227
228
229
230 OPEN c_tmt_status_code_csr(p_term_rec.p_quote_id);
231 FETCH c_tmt_status_code_csr INTO l_tmt_status_code;
232 CLOSE c_tmt_status_code_csr;
233
234 IF (is_debug_statement_on)
235 THEN
236 okl_debug_pub.log_debug (g_level_statement,
237 l_module_name,
238 'quote exists and is in status accepted ');
239 okl_debug_pub.log_debug (g_level_statement,
240 l_module_name,
241 'Show value of :l_tmt_status_code '
242 || l_tmt_status_code
243 );
244 end if;
245 -- 02-sep-2008 rbruno bug 7129269 fix commenting line as check is not needed
246 -- IF l_tmt_status_code = 'PROCESSED' THEN
247 lp_qtev_rec.id := p_term_rec.p_quote_id;
248 lp_qtev_rec.qst_code := l_quote_status;
249
250
251 -- Call the update of the quote header api
252 OKL_TRX_QUOTES_PUB.update_trx_quotes (
253 p_api_version => l_api_version,
254 p_init_msg_list => OKL_API.G_FALSE,
255 x_return_status => l_return_status,
256 x_msg_count => lx_msg_count,
257 x_msg_data => lx_msg_data,
258 p_qtev_rec => lp_qtev_rec,
259 x_qtev_rec => lx_qtev_rec);
260
261 IF l_return_status <> OKL_API.G_RET_STS_SUCCESS THEN
262
263 IF (is_debug_statement_on)
264 THEN
265 okl_debug_pub.log_debug (g_level_statement,
266 l_module_name,
267 'failure while updating the quote status ');
268
269 END IF;
270 END IF;
271
272 --END IF;
273
274 END IF;
275
276 END update_quote_status;
277
278
279 -- Start of comments
280 --
281 -- Procedure Name : log_messages
282 -- Desciption : Logs the messages in the output log
283 -- Business Rules :
284 -- Parameters :
285 -- Version : 1.0
286 -- History : RMUNJULU 04-DEC-02 Bug # 2484327. Added exception block
287 --
288 -- End of comments
289 PROCEDURE log_messages
290 IS
291 lx_error_rec okl_api.error_rec_type;
292 l_msg_idx INTEGER := fnd_msg_pub.g_first;
293 BEGIN
294 -- Get the messages in the log
295 LOOP
296 fnd_msg_pub.get (p_msg_index => l_msg_idx,
297 p_encoded => fnd_api.g_false,
298 p_data => lx_error_rec.msg_data,
299 p_msg_index_out => lx_error_rec.msg_count
300 );
301
302 IF (lx_error_rec.msg_count IS NOT NULL)
303 THEN
304 fnd_file.put_line (fnd_file.LOG, lx_error_rec.msg_data);
305 fnd_file.put_line (fnd_file.output, lx_error_rec.msg_data);
306 END IF;
307
308 EXIT WHEN ( (lx_error_rec.msg_count = fnd_msg_pub.count_msg)
309 OR (lx_error_rec.msg_count IS NULL)
310 );
311 l_msg_idx := fnd_msg_pub.g_next;
312 END LOOP;
313 EXCEPTION
314 WHEN OTHERS
315 THEN
316 -- Set the oracle error message
317 okl_api.set_message (p_app_name => g_app_name_1,
318 p_msg_name => g_unexpected_error,
319 p_token1 => g_sqlcode_token,
320 p_token1_value => SQLCODE,
321 p_token2 => g_sqlerrm_token,
322 p_token2_value => SQLERRM
323 );
324 END log_messages;
325
326 -- Start of comments
327 --
328 -- Procedure Name : set_database_values
329 -- Desciption : Set the parameters values from database
330 -- Business Rules :
331 -- Parameters :
332 -- Version : 1.0
333 -- History : RMUNJULU 04-DEC-02 Bug#2484327 Added comments to FOR LOOPs
334 -- : RMUNJULU 06-MAR-03 Performance Fix Replaced K_HDR_FULL
335 --
336 -- End of comments
337 PROCEDURE set_database_values (
338 px_term_rec IN OUT NOCOPY term_rec_type
339 )
340 IS
341 -- Cursor to get the quote details
342 CURSOR get_quote_details_csr (
343 p_quote_id IN NUMBER
344 )
345 IS
346 SELECT qte.qtp_code qtp_code,
347 qte.qrs_code qrs_code
348 FROM okl_trx_quotes_v qte
349 WHERE qte.ID = p_quote_id;
350
351 -- Cursor to get the k details
352 -- RMUNJULU 06-MAR-03 Performance Fix Replaced K_HDR_FULL
353 CURSOR get_k_details_csr (
354 p_khr_id IN NUMBER
355 )
356 IS
357 SELECT khr.contract_number contract_number
358 FROM okc_k_headers_v khr
359 WHERE khr.ID = p_khr_id;
360
361 l_module_name VARCHAR2 (500)
362 := g_module_name || 'set_database_values';
363 is_debug_exception_on BOOLEAN
364 := okl_debug_pub.check_log_on (l_module_name, g_level_exception);
365 is_debug_procedure_on BOOLEAN
366 := okl_debug_pub.check_log_on (l_module_name, g_level_procedure);
367 is_debug_statement_on BOOLEAN
368 := okl_debug_pub.check_log_on (l_module_name, g_level_statement);
369 BEGIN
370 IF (is_debug_procedure_on)
371 THEN
372 okl_debug_pub.log_debug (g_level_procedure,
373 l_module_name,
374 'Begin(+)'
375 );
376 END IF;
377
378 IF (is_debug_statement_on)
379 THEN
380 okl_debug_pub.log_debug (g_level_statement,
381 l_module_name,
382 'In param, px_term_rec.p_contract_id: '
383 || px_term_rec.p_contract_id
384 );
385 okl_debug_pub.log_debug (g_level_statement,
386 l_module_name,
387 'In param, px_term_rec.p_quote_id: '
388 || px_term_rec.p_quote_id
389 );
390 END IF;
391
392 -- RMUNJULU -- Bug # 2484327 Added comments to for loop
393 -- Get the contract number for the contract id passed
394 FOR get_k_details_rec IN get_k_details_csr (px_term_rec.p_contract_id)
395 LOOP
396 px_term_rec.p_contract_number := get_k_details_rec.contract_number;
397 END LOOP;
398
399 -- If the termination request is from quote,
400 -- populate the rest of the quote attributes
401 IF px_term_rec.p_quote_id IS NOT NULL
402 AND px_term_rec.p_quote_id <> g_miss_num
403 THEN
404 -- RMUNJULU -- Bug # 2484327 Added comments to for loop
405 -- Get the quote_type and quote_reason for the quote id passed
406 FOR get_quote_details_rec IN
407 get_quote_details_csr (px_term_rec.p_quote_id)
408 LOOP
409 px_term_rec.p_quote_type := get_quote_details_rec.qtp_code;
410 px_term_rec.p_quote_reason := get_quote_details_rec.qrs_code;
411 END LOOP;
412 END IF;
413
414 IF (is_debug_procedure_on)
415 THEN
416 okl_debug_pub.log_debug (g_level_procedure,
417 l_module_name,
418 'End(-)'
419 );
420 END IF;
421 EXCEPTION
422 WHEN OTHERS
423 THEN
424 -- RMUNJULU -- Bug # 2484327 Added code to close cursors if open
425 IF get_k_details_csr%ISOPEN
426 THEN
427 CLOSE get_k_details_csr;
428 END IF;
429
430 IF get_quote_details_csr%ISOPEN
431 THEN
432 CLOSE get_quote_details_csr;
433 END IF;
434
435 -- Set the oracle error message
436 okl_api.set_message (p_app_name => g_app_name_1,
437 p_msg_name => g_unexpected_error,
438 p_token1 => g_sqlcode_token,
439 p_token1_value => SQLCODE,
440 p_token2 => g_sqlerrm_token,
441 p_token2_value => SQLERRM
442 );
443
444 IF (is_debug_exception_on)
445 THEN
446 okl_debug_pub.log_debug (g_level_exception,
447 l_module_name,
448 'EXCEPTION :'
449 || 'OTHERS, SQLCODE: '
450 || SQLCODE
451 || ' , SQLERRM : '
452 || SQLERRM
453 );
454 END IF;
455 END set_database_values;
456
457 -- Start of comments
458 --
459 -- Procedure Name : set_info_messages
460 -- Desciption : Set the messages before starting the termination process
461 -- Business Rules :
462 -- Parameters :
463 -- Version : 1.0
464 -- History :
465 --
466 -- End of comments
467 PROCEDURE set_info_messages (
468 p_term_rec IN term_rec_type
469 )
470 IS
471 l_quote_type VARCHAR2 (2000);
472 l_module_name VARCHAR2 (500)
473 := g_module_name || 'set_info_messages';
474 is_debug_exception_on BOOLEAN
475 := okl_debug_pub.check_log_on (l_module_name, g_level_exception);
476 is_debug_procedure_on BOOLEAN
477 := okl_debug_pub.check_log_on (l_module_name, g_level_procedure);
478 is_debug_statement_on BOOLEAN
479 := okl_debug_pub.check_log_on (l_module_name, g_level_statement);
480 BEGIN
481 IF (is_debug_procedure_on)
482 THEN
483 okl_debug_pub.log_debug (g_level_procedure,
484 l_module_name,
485 'Begin(+)'
486 );
487 END IF;
488
489 IF (is_debug_statement_on)
490 THEN
491 okl_debug_pub.log_debug (g_level_statement,
492 l_module_name,
493 'In param, p_term_rec.p_control_flag: '
494 || p_term_rec.p_control_flag
495 );
496 okl_debug_pub.log_debug (g_level_statement,
497 l_module_name,
498 'In param, p_term_rec.p_quote_id: '
499 || p_term_rec.p_quote_id
500 );
501 END IF;
502
503 -- Check and Set the message saying where the termination request came from
504 IF (p_term_rec.p_control_flag = 'CONTRACT_TERMINATE_SCRN')
505 THEN
506 -- Termination request from Request Contract Termination screen
507 -- for contract CONTRACT_NUMBER.
508 okl_api.set_message (p_app_name => g_app_name,
509 p_msg_name => 'OKL_AM_TERM_REQ_FRM_SCRN',
510 p_token1 => 'CONTRACT_NUMBER',
511 p_token1_value => p_term_rec.p_contract_number
512 );
513
514 -- Set the additional message to let the user know if there was a quote
515 IF p_term_rec.p_quote_id IS NOT NULL
516 AND p_term_rec.p_quote_id <> g_miss_num
517 THEN
518 -- Get the lookup meaning for quote type
519 l_quote_type :=
520 okl_am_util_pvt.get_lookup_meaning
521 (p_lookup_type => 'OKL_QUOTE_TYPE',
522 p_lookup_code => p_term_rec.p_quote_type,
523 p_validate_yn => g_yes
524 );
525 -- Termination request from accepted QUOTE_TYPE
526 -- for contract CONTRACT_NUMBER.
527 okl_api.set_message
528 (p_app_name => g_app_name,
529 p_msg_name => 'OKL_AM_TERM_REQ_FRM_QTE',
530 p_token1 => 'QUOTE_TYPE',
531 p_token1_value => l_quote_type,
532 p_token2 => 'CONTRACT_NUMBER',
533 p_token2_value => p_term_rec.p_contract_number
534 );
535 END IF;
536 ELSIF (p_term_rec.p_control_flag = 'TRMNT_QUOTE_UPDATE')
537 THEN
538 -- Get the lookup meaning for quote type
539 l_quote_type :=
540 okl_am_util_pvt.get_lookup_meaning
541 (p_lookup_type => 'OKL_QUOTE_TYPE',
542 p_lookup_code => p_term_rec.p_quote_type,
543 p_validate_yn => g_yes
544 );
545 -- Termination request from accepted QUOTE_TYPE
546 -- for contract CONTRACT_NUMBER.
547 okl_api.set_message (p_app_name => g_app_name,
548 p_msg_name => 'OKL_AM_TERM_REQ_FRM_QTE',
549 p_token1 => 'QUOTE_TYPE',
550 p_token1_value => l_quote_type,
551 p_token2 => 'CONTRACT_NUMBER',
552 p_token2_value => p_term_rec.p_contract_number
553 );
554 ELSIF (p_term_rec.p_control_flag = 'BATCH_PROCESS')
555 THEN
556 -- Auto termination request for contract CONTRACT_NUMBER.
557 okl_api.set_message (p_app_name => g_app_name,
558 p_msg_name => 'OKL_AM_AUTO_TERM_REQ',
559 p_token1 => 'CONTRACT_NUMBER',
560 p_token1_value => p_term_rec.p_contract_number
561 );
562 END IF;
563
564 IF (is_debug_procedure_on)
565 THEN
566 okl_debug_pub.log_debug (g_level_procedure,
567 l_module_name,
568 'End(-)'
569 );
570 END IF;
571 EXCEPTION
572 WHEN OTHERS
573 THEN
574 -- Set the oracle error message
575 okl_api.set_message (p_app_name => g_app_name_1,
576 p_msg_name => g_unexpected_error,
577 p_token1 => g_sqlcode_token,
578 p_token1_value => SQLCODE,
579 p_token2 => g_sqlerrm_token,
580 p_token2_value => SQLERRM
581 );
582
583 IF (is_debug_exception_on)
584 THEN
585 okl_debug_pub.log_debug (g_level_exception,
586 l_module_name,
587 'EXCEPTION :'
588 || 'OTHERS, SQLCODE: '
589 || SQLCODE
590 || ' , SQLERRM : '
591 || SQLERRM
592 );
593 END IF;
594 END set_info_messages;
595
596 -- Start of comments
597 --
598 -- Procedure Name : set_overall_status
599 -- Desciption : Set the overall status for the Termination API
600 -- Business Rules :
601 -- Parameters :
602 -- Version : 1.0
603 -- History :
604 --
605 -- End of comments
606 PROCEDURE set_overall_status (
607 p_return_status IN VARCHAR2,
608 px_overall_status IN OUT NOCOPY VARCHAR2
609 )
610 IS
611 BEGIN
612 -- Store the highest degree of error
613 -- Set p_overall_status only if p_overall_status was successful and
614 -- p_return_status is not null
615 IF px_overall_status = g_ret_sts_success
616 AND ( p_return_status IS NOT NULL
617 OR p_return_status <> okl_api.g_miss_char
618 )
619 THEN
620 px_overall_status := p_return_status;
621 END IF;
622 EXCEPTION
623 WHEN OTHERS
624 THEN
625 -- Set the oracle error message
626 okl_api.set_message (p_app_name => g_app_name_1,
627 p_msg_name => g_unexpected_error,
628 p_token1 => g_sqlcode_token,
629 p_token1_value => SQLCODE,
630 p_token2 => g_sqlerrm_token,
631 p_token2_value => SQLERRM
632 );
633 END set_overall_status;
634
635 -- Start of comments
636 --
637 -- Procedure Name : initialize_transaction
638 -- Desciption : Initialize the Transaction Record (okl_trx_contracts rec)
639 -- Business Rules :
640 -- Parameters :
641 -- Version : 1.0
642 -- History :
643 --
644 -- End of comments
645 PROCEDURE initialize_transaction (
646 p_term_rec IN term_rec_type,
647 p_sys_date IN DATE,
648 p_control_flag IN VARCHAR2,
649 px_tcnv_rec IN OUT NOCOPY tcnv_rec_type,
650 x_return_status OUT NOCOPY VARCHAR2
651 )
652 IS
653 l_try_id NUMBER;
654 l_currency_code VARCHAR2 (2000);
655 l_trans_meaning VARCHAR2 (200);
656 l_return_status VARCHAR2 (1) := g_ret_sts_success;
657 l_module_name VARCHAR2 (500)
658 := g_module_name || 'initialize_transaction';
659 is_debug_exception_on BOOLEAN
660 := okl_debug_pub.check_log_on (l_module_name, g_level_exception);
661 is_debug_procedure_on BOOLEAN
662 := okl_debug_pub.check_log_on (l_module_name, g_level_procedure);
663 is_debug_statement_on BOOLEAN
664 := okl_debug_pub.check_log_on (l_module_name, g_level_statement);
665 BEGIN
666 IF (is_debug_procedure_on)
667 THEN
668 okl_debug_pub.log_debug (g_level_procedure,
669 l_module_name,
670 'Begin(+)'
671 );
672 END IF;
673
674 IF (is_debug_statement_on)
675 THEN
676 okl_debug_pub.log_debug (g_level_statement,
677 l_module_name,
678 'In param, p_sys_date: ' || p_sys_date
679 );
680 okl_debug_pub.log_debug (g_level_statement,
681 l_module_name,
682 'In param, p_control_flag: '
683 || p_control_flag
684 );
685 okl_debug_pub.log_debug (g_level_statement,
686 l_module_name,
687 'In param, p_term_rec.p_contract_id: '
688 || p_term_rec.p_contract_id
689 );
690 okl_debug_pub.log_debug (g_level_statement,
691 l_module_name,
692 'In param, p_term_rec.p_quote_id: '
693 || p_term_rec.p_quote_id
694 );
695 okl_debug_pub.log_debug
696 (g_level_statement,
697 l_module_name,
698 'In param, p_term_rec.p_termination_reason: '
699 || p_term_rec.p_termination_reason
700 );
701 END IF;
702
703 IF p_control_flag = 'CREATE'
704 THEN
705 IF (is_debug_statement_on)
706 THEN
707 okl_debug_pub.log_debug
708 (g_level_statement,
709 l_module_name,
710 'calling OKL_AM_UTIL_PVT.get_transaction_id'
711 );
712 END IF;
713
714 -- Get the Accounting Transaction Id
715 okl_am_util_pvt.get_transaction_id
716 (p_try_name => 'Termination',
717 x_return_status => l_return_status,
718 x_try_id => l_try_id
719 );
720
721 IF (is_debug_statement_on)
722 THEN
723 okl_debug_pub.log_debug
724 (g_level_statement,
725 l_module_name,
726 'called OKL_AM_UTIL_PVT.get_transaction_id , l_return_status: '
727 || l_return_status
728 );
729 END IF;
730
731 -- Get the meaning of Accounting lookup
732 l_trans_meaning :=
733 okl_am_util_pvt.get_lookup_meaning
734 (p_lookup_type => 'OKL_ACCOUNTING_EVENT_TYPE',
735 p_lookup_code => 'TERMINATION',
736 p_validate_yn => 'Y'
737 );
738
739 IF l_return_status <> g_ret_sts_success
740 THEN
741 -- Unable to find a transaction type for the transaction TRY_NAME
742 okl_api.set_message (p_app_name => g_app_name,
743 p_msg_name => 'OKL_AM_NO_TRX_TYPE_FOUND',
744 p_token1 => 'TRY_NAME',
745 p_token1_value => l_trans_meaning
746 );
747 RAISE okl_api.g_exception_error;
748 END IF;
749
750 -- Get the contract currency code
751 l_currency_code :=
752 okl_am_util_pvt.get_chr_currency (p_term_rec.p_contract_id);
753 -- initialize the transaction rec
754 px_tcnv_rec.khr_id := p_term_rec.p_contract_id;
755 px_tcnv_rec.tcn_type := 'ALT'; -- TMT
756 px_tcnv_rec.try_id := l_try_id;
757 px_tcnv_rec.currency_code := l_currency_code;
758 END IF;
759
760 -- Set the rest of the transaction rec
761 px_tcnv_rec.qte_id := p_term_rec.p_quote_id;
762 px_tcnv_rec.tsu_code := 'ENTERED';
763 px_tcnv_rec.tmt_status_code := 'ENTERED';
764 --akrangan changes for sla tmt_status_code cr
765 px_tcnv_rec.date_transaction_occurred := p_sys_date;
766 --20-NOV-2006 ANSETHUR R12B - LEGAL ENTITY UPTAKE PROJECT
767 px_tcnv_rec.legal_entity_id :=
768 okl_legal_entity_util.get_khr_le_id (p_term_rec.p_contract_id);
769
770 -- set the termination reason (TRN_CODE)
771 IF (p_term_rec.p_termination_reason <> okl_api.g_miss_char)
772 AND (p_term_rec.p_termination_reason IS NOT NULL)
773 THEN
774 px_tcnv_rec.trn_code := p_term_rec.p_termination_reason;
775 ELSE
776 px_tcnv_rec.trn_code := 'EXP';
777 END IF;
778
779 -- Set the return status
780 x_return_status := l_return_status;
781
782 IF (is_debug_procedure_on)
783 THEN
784 okl_debug_pub.log_debug (g_level_procedure,
785 l_module_name,
786 'End(-)'
787 );
788 END IF;
789 EXCEPTION
790 WHEN okl_api.g_exception_error
791 THEN
792 -- Set the return status
793 x_return_status := g_ret_sts_unexp_error;
794
795 IF (is_debug_exception_on)
796 THEN
797 okl_debug_pub.log_debug (g_level_exception,
798 l_module_name,
799 'EXCEPTION :' || 'G_EXCEPTION_ERROR'
800 );
801 END IF;
802 WHEN OTHERS
803 THEN
804 -- Set the oracle error message
805 okl_api.set_message (p_app_name => g_app_name_1,
806 p_msg_name => g_unexpected_error,
807 p_token1 => g_sqlcode_token,
808 p_token1_value => SQLCODE,
809 p_token2 => g_sqlerrm_token,
810 p_token2_value => SQLERRM
811 );
812 -- Set the return status
813 x_return_status := g_ret_sts_unexp_error;
814
815 IF (is_debug_exception_on)
816 THEN
817 okl_debug_pub.log_debug (g_level_exception,
818 l_module_name,
819 'EXCEPTION :'
820 || 'OTHERS, SQLCODE: '
821 || SQLCODE
822 || ' , SQLERRM : '
823 || SQLERRM
824 );
825 END IF;
826 END initialize_transaction;
827
828 -- Start of comments
829 --
830 -- Procedure Name : set_transaction_rec
831 -- Desciption : Set the Transaction Record (okl_trx_contracts rec)
832 -- Business Rules :
833 -- Parameters :
834 -- Version : 1.0
835 -- History : RMUNJULU 2757312 Added code to set tmt_generic flags
836 --
837 -- End of comments
838 PROCEDURE set_transaction_rec (
839 p_return_status IN VARCHAR2,
840 p_overall_status IN VARCHAR2,
841 p_tmt_flag IN VARCHAR2,
842 p_tsu_code IN VARCHAR2,
843 p_ret_val IN VARCHAR2,
844 px_tcnv_rec IN OUT NOCOPY tcnv_rec_type
845 )
846 IS
847 l_module_name VARCHAR2 (500)
848 := g_module_name || 'set_transaction_rec';
849 is_debug_exception_on BOOLEAN
850 := okl_debug_pub.check_log_on (l_module_name, g_level_exception);
851 is_debug_procedure_on BOOLEAN
852 := okl_debug_pub.check_log_on (l_module_name, g_level_procedure);
853 is_debug_statement_on BOOLEAN
854 := okl_debug_pub.check_log_on (l_module_name, g_level_statement);
855 BEGIN
856 IF (is_debug_procedure_on)
857 THEN
858 okl_debug_pub.log_debug (g_level_procedure,
859 l_module_name,
860 'Begin(+)'
861 );
862 END IF;
863
864 IF (is_debug_statement_on)
865 THEN
866 okl_debug_pub.log_debug (g_level_statement,
867 l_module_name,
868 'In param, p_return_status: '
869 || p_return_status
870 );
871 okl_debug_pub.log_debug (g_level_statement,
872 l_module_name,
873 'In param, p_overall_status: '
874 || p_overall_status
875 );
876 okl_debug_pub.log_debug (g_level_statement,
877 l_module_name,
878 'In param, p_tmt_flag: ' || p_tmt_flag
879 );
880 okl_debug_pub.log_debug (g_level_statement,
881 l_module_name,
882 'In param, p_tsu_code: ' || p_tsu_code
883 );
884 okl_debug_pub.log_debug (g_level_statement,
885 l_module_name,
886 'In param, p_ret_val: ' || p_ret_val
887 );
888 END IF;
889
890 -- set the transaction record
891 IF (p_overall_status = g_ret_sts_success)
892 THEN
893 --px_tcnv_rec.tsu_code := p_tsu_code; --akrangan chaged
894 px_tcnv_rec.tmt_status_code := p_tsu_code;
895 --akrangan changed for sla tmt_status_code cr
896 ELSE
897 px_tcnv_rec.tmt_status_code := 'ERROR';
898 --akrangan changes for sla tmt_status_code cr
899 END IF;
900
901 IF (p_ret_val = okl_api.g_miss_char)
902 THEN
903 -- No value for p_ret_val
904 IF (p_return_status = g_ret_sts_success)
905 THEN
906 -- ret stat success
907 IF (p_tmt_flag = 'TMT_EVERGREEN_YN')
908 THEN
909 px_tcnv_rec.tmt_evergreen_yn := g_yes;
910 ELSIF (p_tmt_flag = 'TMT_CLOSE_BALANCES_YN')
911 THEN
912 px_tcnv_rec.tmt_close_balances_yn := g_yes;
913 ELSIF (p_tmt_flag = 'TMT_ACCOUNTING_ENTRIES_YN')
914 THEN
915 px_tcnv_rec.tmt_accounting_entries_yn := g_yes;
916 ELSIF (p_tmt_flag = 'TMT_CANCEL_INSURANCE_YN')
917 THEN
918 px_tcnv_rec.tmt_cancel_insurance_yn := g_yes;
919 ELSIF (p_tmt_flag = 'TMT_ASSET_DISPOSITION_YN')
920 THEN
921 px_tcnv_rec.tmt_asset_disposition_yn := g_yes;
922 ELSIF (p_tmt_flag = 'TMT_AMORTIZATION_YN')
923 THEN
924 px_tcnv_rec.tmt_amortization_yn := g_yes;
925 ELSIF (p_tmt_flag = 'TMT_ASSET_RETURN_YN')
926 THEN
927 px_tcnv_rec.tmt_asset_return_yn := g_yes;
928 ELSIF (p_tmt_flag = 'TMT_CONTRACT_UPDATED_YN')
929 THEN
930 px_tcnv_rec.tmt_contract_updated_yn := g_yes;
931 ELSIF (p_tmt_flag = 'TMT_STREAMS_UPDATED_YN')
932 THEN
933 px_tcnv_rec.tmt_streams_updated_yn := g_yes;
934 ELSIF (p_tmt_flag = 'TMT_VALIDATED_YN')
935 THEN
936 px_tcnv_rec.tmt_validated_yn := g_yes;
937 ELSIF (p_tmt_flag = 'TMT_SPLIT_ASSET_YN')
938 THEN
939 px_tcnv_rec.tmt_split_asset_yn := g_yes;
940 -- RMUNJULU 2757312 Added
941 ELSIF (p_tmt_flag = 'TMT_GENERIC_FLAG1_YN')
942 THEN
943 px_tcnv_rec.tmt_generic_flag1_yn := g_yes;
944 ELSIF (p_tmt_flag = 'TMT_GENERIC_FLAG2_YN')
945 THEN
946 px_tcnv_rec.tmt_generic_flag2_yn := g_yes;
947 ELSIF (p_tmt_flag = 'TMT_GENERIC_FLAG3_YN')
948 THEN
949 px_tcnv_rec.tmt_generic_flag3_yn := g_yes;
950 END IF;
951 ELSE
952 -- return_status not success
953 IF (p_tmt_flag = 'TMT_EVERGREEN_YN')
954 THEN
955 px_tcnv_rec.tmt_evergreen_yn := g_no;
956 ELSIF (p_tmt_flag = 'TMT_CLOSE_BALANCES_YN')
957 THEN
958 px_tcnv_rec.tmt_close_balances_yn := g_no;
959 ELSIF (p_tmt_flag = 'TMT_ACCOUNTING_ENTRIES_YN')
960 THEN
961 px_tcnv_rec.tmt_accounting_entries_yn := g_no;
962 ELSIF (p_tmt_flag = 'TMT_CANCEL_INSURANCE_YN')
963 THEN
964 px_tcnv_rec.tmt_cancel_insurance_yn := g_no;
965 ELSIF (p_tmt_flag = 'TMT_ASSET_DISPOSITION_YN')
966 THEN
967 px_tcnv_rec.tmt_asset_disposition_yn := g_no;
968 ELSIF (p_tmt_flag = 'TMT_AMORTIZATION_YN')
969 THEN
970 px_tcnv_rec.tmt_amortization_yn := g_no;
971 ELSIF (p_tmt_flag = 'TMT_ASSET_RETURN_YN')
972 THEN
973 px_tcnv_rec.tmt_asset_return_yn := g_no;
974 ELSIF (p_tmt_flag = 'TMT_CONTRACT_UPDATED_YN')
975 THEN
976 px_tcnv_rec.tmt_contract_updated_yn := g_no;
977 ELSIF (p_tmt_flag = 'TMT_STREAMS_UPDATED_YN')
978 THEN
979 px_tcnv_rec.tmt_streams_updated_yn := g_no;
980 ELSIF (p_tmt_flag = 'TMT_VALIDATED_YN')
981 THEN
982 px_tcnv_rec.tmt_validated_yn := g_no;
983 ELSIF (p_tmt_flag = 'TMT_SPLIT_ASSET_YN')
984 THEN
985 px_tcnv_rec.tmt_split_asset_yn := g_no;
986 -- RMUNJULU 2757312 Added
987 ELSIF (p_tmt_flag = 'TMT_GENERIC_FLAG1_YN')
988 THEN
989 px_tcnv_rec.tmt_generic_flag1_yn := g_no;
990 ELSIF (p_tmt_flag = 'TMT_GENERIC_FLAG2_YN')
991 THEN
992 px_tcnv_rec.tmt_generic_flag2_yn := g_no;
993 ELSIF (p_tmt_flag = 'TMT_GENERIC_FLAG3_YN')
994 THEN
995 px_tcnv_rec.tmt_generic_flag3_yn := g_no;
996 END IF;
997 END IF;
998 ELSE
999 -- value for p_ret_val passed ( will override return_status val)
1000 IF (p_tmt_flag = 'TMT_EVERGREEN_YN')
1001 THEN
1002 px_tcnv_rec.tmt_evergreen_yn := p_ret_val;
1003 ELSIF (p_tmt_flag = 'TMT_CLOSE_BALANCES_YN')
1004 THEN
1005 px_tcnv_rec.tmt_close_balances_yn := p_ret_val;
1006 ELSIF (p_tmt_flag = 'TMT_ACCOUNTING_ENTRIES_YN')
1007 THEN
1008 px_tcnv_rec.tmt_accounting_entries_yn := p_ret_val;
1009 ELSIF (p_tmt_flag = 'TMT_CANCEL_INSURANCE_YN')
1010 THEN
1011 px_tcnv_rec.tmt_cancel_insurance_yn := p_ret_val;
1012 ELSIF (p_tmt_flag = 'TMT_ASSET_DISPOSITION_YN')
1013 THEN
1014 px_tcnv_rec.tmt_asset_disposition_yn := p_ret_val;
1015 ELSIF (p_tmt_flag = 'TMT_AMORTIZATION_YN')
1016 THEN
1017 px_tcnv_rec.tmt_amortization_yn := p_ret_val;
1018 ELSIF (p_tmt_flag = 'TMT_ASSET_RETURN_YN')
1019 THEN
1020 px_tcnv_rec.tmt_asset_return_yn := p_ret_val;
1021 ELSIF (p_tmt_flag = 'TMT_CONTRACT_UPDATED_YN')
1022 THEN
1023 px_tcnv_rec.tmt_contract_updated_yn := p_ret_val;
1024 ELSIF (p_tmt_flag = 'TMT_STREAMS_UPDATED_YN')
1025 THEN
1026 px_tcnv_rec.tmt_streams_updated_yn := p_ret_val;
1027 ELSIF (p_tmt_flag = 'TMT_VALIDATED_YN')
1028 THEN
1029 px_tcnv_rec.tmt_validated_yn := p_ret_val;
1030 ELSIF (p_tmt_flag = 'TMT_SPLIT_ASSET_YN')
1031 THEN
1032 px_tcnv_rec.tmt_split_asset_yn := p_ret_val;
1033 -- RMUNJULU 2757312 Added
1034 ELSIF (p_tmt_flag = 'TMT_GENERIC_FLAG1_YN')
1035 THEN
1036 px_tcnv_rec.tmt_generic_flag1_yn := p_ret_val;
1037 ELSIF (p_tmt_flag = 'TMT_GENERIC_FLAG2_YN')
1038 THEN
1039 px_tcnv_rec.tmt_generic_flag2_yn := p_ret_val;
1040 ELSIF (p_tmt_flag = 'TMT_GENERIC_FLAG3_YN')
1041 THEN
1042 px_tcnv_rec.tmt_generic_flag3_yn := p_ret_val;
1043 END IF;
1044 END IF;
1045
1046 IF (is_debug_procedure_on)
1047 THEN
1048 okl_debug_pub.log_debug (g_level_procedure,
1049 l_module_name,
1050 'End(-)'
1051 );
1052 END IF;
1053 EXCEPTION
1054 WHEN OTHERS
1055 THEN
1056 -- Set the oracle error message
1057 okl_api.set_message (p_app_name => g_app_name_1,
1058 p_msg_name => g_unexpected_error,
1059 p_token1 => g_sqlcode_token,
1060 p_token1_value => SQLCODE,
1061 p_token2 => g_sqlerrm_token,
1062 p_token2_value => SQLERRM
1063 );
1064
1065 IF (is_debug_exception_on)
1066 THEN
1067 okl_debug_pub.log_debug (g_level_exception,
1068 l_module_name,
1069 'EXCEPTION :'
1070 || 'OTHERS, SQLCODE: '
1071 || SQLCODE
1072 || ' , SQLERRM : '
1073 || SQLERRM
1074 );
1075 END IF;
1076 END set_transaction_rec;
1077
1078 -- Start of comments
1079 --
1080 -- Procedure Name : process_transaction
1081 -- Desciption : Insert/Update the Transaction Record (okl_trx_contracts )
1082 -- Business Rules :
1083 -- Parameters :
1084 -- Version : 1.0
1085 -- History
1086 --
1087 -- End of comments
1088 PROCEDURE process_transaction (
1089 p_id IN NUMBER,
1090 p_term_rec IN term_rec_type,
1091 p_tcnv_rec IN tcnv_rec_type,
1092 p_trn_mode IN VARCHAR2,
1093 x_id OUT NOCOPY NUMBER,
1094 x_return_status OUT NOCOPY VARCHAR2
1095 )
1096 IS
1097 l_return_status VARCHAR2 (1) := g_ret_sts_success;
1098 lp_tcnv_rec tcnv_rec_type := p_tcnv_rec;
1099 lx_tcnv_rec tcnv_rec_type;
1100 l_api_version CONSTANT NUMBER := g_api_version;
1101 l_msg_count NUMBER := g_miss_num;
1102 l_msg_data VARCHAR2 (2000);
1103 l_module_name VARCHAR2 (500)
1104 := g_module_name || 'process_transaction';
1105 is_debug_exception_on BOOLEAN
1106 := okl_debug_pub.check_log_on (l_module_name, g_level_exception);
1107 is_debug_procedure_on BOOLEAN
1108 := okl_debug_pub.check_log_on (l_module_name, g_level_procedure);
1109 is_debug_statement_on BOOLEAN
1110 := okl_debug_pub.check_log_on (l_module_name, g_level_statement);
1111 BEGIN
1112 IF (is_debug_procedure_on)
1113 THEN
1114 okl_debug_pub.log_debug (g_level_procedure,
1115 l_module_name,
1116 'Begin(+)'
1117 );
1118 END IF;
1119
1120 IF (is_debug_statement_on)
1121 THEN
1122 okl_debug_pub.log_debug (g_level_statement,
1123 l_module_name,
1124 'In param, p_id: ' || p_id
1125 );
1126 okl_debug_pub.log_debug (g_level_statement,
1127 l_module_name,
1128 'In param, p_trn_mode: ' || p_trn_mode
1129 );
1130 END IF;
1131
1132 -- Set the savepoint for this api
1133 SAVEPOINT process_transaction;
1134 -- Clear the recycle flag after processing
1135 lp_tcnv_rec.tmt_recycle_yn := NULL;
1136
1137 -- Based on mode Insert/Update the transaction rec
1138 IF p_trn_mode = 'INSERT'
1139 THEN
1140 IF (is_debug_statement_on)
1141 THEN
1142 okl_debug_pub.log_debug
1143 (g_level_statement,
1144 l_module_name,
1145 'calling OKL_TRX_CONTRACTS_PUB.create_trx_contracts'
1146 );
1147 END IF;
1148
1149 -- insert transaction rec
1150 okl_trx_contracts_pub.create_trx_contracts
1151 (p_api_version => l_api_version,
1152 p_init_msg_list => g_false,
1153 x_return_status => l_return_status,
1154 x_msg_count => l_msg_count,
1155 x_msg_data => l_msg_data,
1156 p_tcnv_rec => lp_tcnv_rec,
1157 x_tcnv_rec => lx_tcnv_rec
1158 );
1159
1160 IF (is_debug_statement_on)
1161 THEN
1162 okl_debug_pub.log_debug
1163 (g_level_statement,
1164 l_module_name,
1165 'called OKL_TRX_CONTRACTS_PUB.create_trx_contracts , return status: '
1166 || l_return_status
1167 );
1168 END IF;
1169 ELSIF p_trn_mode = 'UPDATE'
1170 THEN
1171 IF (is_debug_statement_on)
1172 THEN
1173 okl_debug_pub.log_debug
1174 (g_level_statement,
1175 l_module_name,
1176 'calling OKL_TRX_CONTRACTS_PUB.update_trx_contracts'
1177 );
1178 END IF;
1179
1180 -- update transaction rec
1181 okl_trx_contracts_pub.update_trx_contracts
1182 (p_api_version => l_api_version,
1183 p_init_msg_list => g_false,
1184 x_return_status => l_return_status,
1185 x_msg_count => l_msg_count,
1186 x_msg_data => l_msg_data,
1187 p_tcnv_rec => lp_tcnv_rec,
1188 x_tcnv_rec => lx_tcnv_rec
1189 );
1190
1191 IF (is_debug_statement_on)
1192 THEN
1193 okl_debug_pub.log_debug
1194 (g_level_statement,
1195 l_module_name,
1196 'called OKL_TRX_CONTRACTS_PUB.update_trx_contracts , return status: '
1197 || l_return_status
1198 );
1199 END IF;
1200 END IF;
1201
1202 -- rollback if error
1203 IF (l_return_status = g_ret_sts_unexp_error)
1204 THEN
1205 RAISE okl_api.g_exception_unexpected_error;
1206 ELSIF (l_return_status = g_ret_sts_error)
1207 THEN
1208 RAISE okl_api.g_exception_error;
1209 END IF;
1210
1211 -- set the return values
1212 x_return_status := l_return_status;
1213 x_id := lx_tcnv_rec.ID;
1214
1215 IF (is_debug_procedure_on)
1216 THEN
1217 okl_debug_pub.log_debug (g_level_procedure,
1218 l_module_name,
1219 'End(-)'
1220 );
1221 END IF;
1222 EXCEPTION
1223 WHEN okl_api.g_exception_error
1224 THEN
1225 ROLLBACK TO process_transaction;
1226 x_return_status := g_ret_sts_error;
1227
1228 IF (is_debug_exception_on)
1229 THEN
1230 okl_debug_pub.log_debug (g_level_exception,
1231 l_module_name,
1232 'EXCEPTION :' || 'G_EXCEPTION_ERROR'
1233 );
1234 END IF;
1235 WHEN okl_api.g_exception_unexpected_error
1236 THEN
1237 ROLLBACK TO process_transaction;
1238 x_return_status := g_ret_sts_unexp_error;
1239
1240 IF (is_debug_exception_on)
1241 THEN
1242 okl_debug_pub.log_debug (g_level_exception,
1243 l_module_name,
1244 'EXCEPTION :'
1245 || 'G_EXCEPTION_UNEXPECTED_ERROR'
1246 );
1247 END IF;
1248 WHEN OTHERS
1249 THEN
1250 ROLLBACK TO process_transaction;
1251 x_return_status := g_ret_sts_unexp_error;
1252 -- Set the oracle error message
1253 okl_api.set_message (p_app_name => g_app_name_1,
1254 p_msg_name => g_unexpected_error,
1255 p_token1 => g_sqlcode_token,
1256 p_token1_value => SQLCODE,
1257 p_token2 => g_sqlerrm_token,
1258 p_token2_value => SQLERRM
1259 );
1260
1261 IF (is_debug_exception_on)
1262 THEN
1263 okl_debug_pub.log_debug (g_level_exception,
1264 l_module_name,
1265 'EXCEPTION :'
1266 || 'OTHERS, SQLCODE: '
1267 || SQLCODE
1268 || ' , SQLERRM : '
1269 || SQLERRM
1270 );
1271 END IF;
1272 END process_transaction;
1273
1274 -- Start of comments
1275 --
1276 -- Procedure Name : get_lines
1277 -- Desciption : For the Termination quote get the contract lines
1278 -- Business Rules :
1279 -- Parameters :
1280 -- Version : 1.0
1281 -- History : RMUNJULU -- Bug # 2484327 16-DEC-02 set additional values
1282 -- for lines rec type
1283 --
1284 -- End of comments
1285 PROCEDURE get_lines (
1286 p_term_rec IN term_rec_type,
1287 x_klev_tbl OUT NOCOPY klev_tbl_type,
1288 x_return_status OUT NOCOPY VARCHAR2
1289 )
1290 IS
1291 -- Get the lines for the quote
1292 -- RMUNJULU -- Bug # 2484327 16-DEC-02 Added columns to query
1293 CURSOR get_qte_lines_csr (
1294 p_qte_id IN NUMBER
1295 )
1296 IS
1297 SELECT kle.ID kle_id,
1298 kle.NAME asset_name,
1299 tql.asset_quantity asset_quantity,
1300 tql.ID tql_id,
1301 tql.quote_quantity quote_quantity,
1302 tql.split_kle_name split_kle_name -- RMUNJULU 2757312
1303 FROM okl_txl_quote_lines_v tql,
1304 okc_k_lines_v kle
1305 WHERE tql.qte_id = p_qte_id
1306 AND tql.qlt_code = 'AMCFIA'
1307 AND tql.kle_id = kle.ID;
1308
1309 lx_klev_tbl klev_tbl_type;
1310 i NUMBER := 1;
1311 l_return_status VARCHAR2 (1) := g_ret_sts_success;
1312 l_module_name VARCHAR2 (500) := g_module_name || 'get_lines';
1313 is_debug_exception_on BOOLEAN
1314 := okl_debug_pub.check_log_on (l_module_name, g_level_exception);
1315 is_debug_procedure_on BOOLEAN
1316 := okl_debug_pub.check_log_on (l_module_name, g_level_procedure);
1317 is_debug_statement_on BOOLEAN
1318 := okl_debug_pub.check_log_on (l_module_name, g_level_statement);
1319 BEGIN
1320 IF (is_debug_procedure_on)
1321 THEN
1322 okl_debug_pub.log_debug (g_level_procedure,
1323 l_module_name,
1324 'Begin(+)'
1325 );
1326 END IF;
1327
1328 IF (is_debug_statement_on)
1329 THEN
1330 okl_debug_pub.log_debug (g_level_statement,
1331 l_module_name,
1332 'In param, p_term_rec.p_quote_id: '
1333 || p_term_rec.p_quote_id
1334 );
1335 END IF;
1336
1337 i := 1;
1338
1339 -- Set the klev_tbl
1340 FOR get_qte_lines_rec IN get_qte_lines_csr (p_term_rec.p_quote_id)
1341 LOOP
1342 lx_klev_tbl (i).p_kle_id := get_qte_lines_rec.kle_id;
1343 lx_klev_tbl (i).p_asset_name := get_qte_lines_rec.asset_name;
1344 -- RMUNJULU -- Bug # 2484327 16-DEC-02 -- START --
1345 -- set additional values for lines
1346 lx_klev_tbl (i).p_asset_quantity := get_qte_lines_rec.asset_quantity;
1347 lx_klev_tbl (i).p_tql_id := get_qte_lines_rec.tql_id;
1348 lx_klev_tbl (i).p_quote_quantity := get_qte_lines_rec.quote_quantity;
1349 -- RMUNJULU -- Bug # 2484327 16-DEC-02 -- END --
1350
1351 -- RMUNJULU 2757312
1352 lx_klev_tbl (i).p_split_kle_name := get_qte_lines_rec.split_kle_name;
1353 i := i + 1;
1354 END LOOP;
1355
1356 -- Set the return status
1357 x_return_status := l_return_status;
1358 x_klev_tbl := lx_klev_tbl;
1359
1360 IF (is_debug_procedure_on)
1361 THEN
1362 okl_debug_pub.log_debug (g_level_procedure,
1363 l_module_name,
1364 'End(-)'
1365 );
1366 END IF;
1367 EXCEPTION
1368 WHEN OTHERS
1369 THEN
1370 -- RMUNJULU -- Bug # 2484327 Added code to close cursor if open
1371 IF get_qte_lines_csr%ISOPEN
1372 THEN
1373 CLOSE get_qte_lines_csr;
1374 END IF;
1375
1376 -- Set the oracle error message
1377 okl_api.set_message (p_app_name => g_app_name_1,
1378 p_msg_name => g_unexpected_error,
1379 p_token1 => g_sqlcode_token,
1380 p_token1_value => SQLCODE,
1381 p_token2 => g_sqlerrm_token,
1382 p_token2_value => SQLERRM
1383 );
1384 -- Set the return status
1385 x_return_status := g_ret_sts_unexp_error;
1386
1387 IF (is_debug_exception_on)
1388 THEN
1389 okl_debug_pub.log_debug (g_level_exception,
1390 l_module_name,
1391 'EXCEPTION :'
1392 || 'OTHERS, SQLCODE: '
1393 || SQLCODE
1394 || ' , SQLERRM : '
1395 || SQLERRM
1396 );
1397 END IF;
1398 END get_lines;
1399
1400 -- Start of comments
1401 --
1402 -- Procedure Name : validate_contract_and_lines
1403 -- Desciption : Validates the contract and lines to check they have right
1404 -- statuses (ste_code and sts_code).
1405 -- Business Rules :
1406 -- Parameters :
1407 -- Version : 1.0
1408 -- History : RMUNJULU 20-DEC-02 2484327 Added message when error
1409 -- : RMUNJULU 06-MAR-03 Performance Fix Replaced K_HDR_FULL
1410 --
1411 -- End of comments
1412 PROCEDURE validate_contract_and_lines (
1413 p_term_rec IN term_rec_type,
1414 p_sys_date IN DATE,
1415 p_klev_tbl IN klev_tbl_type,
1416 x_return_status OUT NOCOPY VARCHAR2
1417 )
1418 IS
1419 -- Get the status of the contract
1420 -- RMUNJULU 06-MAR-03 Performance Fix Replaced K_HDR_FULL
1421 CURSOR chr_sts_csr (
1422 p_khr_id IN NUMBER
1423 )
1424 IS
1425 SELECT khr.sts_code sts_code
1426 FROM okc_k_headers_v khr
1427 WHERE khr.ID = p_khr_id;
1428
1429 -- Get the status of the line
1430 -- RMUNJULU 06-MAR-03 Performance Fix Replaced K_LNS_FULL
1431 CURSOR cle_sts_csr (
1432 p_kle_id IN NUMBER
1433 )
1434 IS
1435 SELECT kle.sts_code sts_code
1436 FROM okc_k_lines_v kle
1437 WHERE kle.ID = p_kle_id;
1438
1439 i NUMBER := 1;
1440 l_k_sts VARCHAR2 (30);
1441 l_l_sts VARCHAR2 (30);
1442 l_sts_match VARCHAR2 (1) := g_yes;
1443 l_return_status VARCHAR2 (1) := g_ret_sts_success;
1444 l_module_name VARCHAR2 (500)
1445 := g_module_name || 'validate_contract_and_lines';
1446 is_debug_exception_on BOOLEAN
1447 := okl_debug_pub.check_log_on (l_module_name, g_level_exception);
1448 is_debug_procedure_on BOOLEAN
1449 := okl_debug_pub.check_log_on (l_module_name, g_level_procedure);
1450 is_debug_statement_on BOOLEAN
1451 := okl_debug_pub.check_log_on (l_module_name, g_level_statement);
1452 BEGIN
1453 IF (is_debug_procedure_on)
1454 THEN
1455 okl_debug_pub.log_debug (g_level_procedure,
1456 l_module_name,
1457 'Begin(+)'
1458 );
1459 END IF;
1460
1461 IF (is_debug_statement_on)
1462 THEN
1463 okl_debug_pub.log_debug (g_level_statement,
1464 l_module_name,
1465 'In param, p_sys_date: ' || p_sys_date
1466 );
1467 okl_debug_pub.log_debug (g_level_statement,
1468 l_module_name,
1469 'In param, p_term_rec.p_contract_id: '
1470 || p_term_rec.p_contract_id
1471 );
1472 okl_debug_pub.log_debug
1473 (g_level_statement,
1474 l_module_name,
1475 'In param, p_term_rec.p_contract_number: '
1476 || p_term_rec.p_contract_number
1477 );
1478
1479 IF (p_klev_tbl.COUNT > 0)
1480 THEN
1481 i := p_klev_tbl.FIRST;
1482
1483 LOOP
1484 okl_debug_pub.log_debug (g_level_statement,
1485 l_module_name,
1486 'In param, p_klev_tbl('
1487 || i
1488 || ').p_kle_id: '
1489 || p_klev_tbl (i).p_kle_id
1490 );
1491 EXIT WHEN (i = p_klev_tbl.LAST);
1492 i := p_klev_tbl.NEXT (i);
1493 END LOOP;
1494 END IF;
1495 END IF;
1496
1497 -- Get the contract status
1498 OPEN chr_sts_csr (p_term_rec.p_contract_id);
1499
1500 FETCH chr_sts_csr
1501 INTO l_k_sts;
1502
1503 CLOSE chr_sts_csr;
1504
1505 -- RMUNJULU 3018641 Step Message
1506 -- Step : Validate Contract
1507 okl_api.set_message (p_app_name => g_app_name,
1508 p_msg_name => 'OKL_AM_STEP_VAL');
1509
1510 -- While looping thru the lines get the line status and compare with
1511 -- contract status. If both the statuses doesnot match then error.
1512 IF (p_klev_tbl.COUNT > 0)
1513 THEN
1514 i := p_klev_tbl.FIRST;
1515
1516 LOOP
1517 -- Get the line status
1518 OPEN cle_sts_csr (p_klev_tbl (i).p_kle_id);
1519
1520 FETCH cle_sts_csr
1521 INTO l_l_sts;
1522
1523 CLOSE cle_sts_csr;
1524
1525 -- Check if both statuses match
1526 IF l_k_sts <> l_l_sts
1527 THEN
1528 l_sts_match := g_no;
1529 EXIT;
1530 END IF;
1531
1532 EXIT WHEN (i = p_klev_tbl.LAST);
1533 i := p_klev_tbl.NEXT (i);
1534 END LOOP;
1535 END IF;
1536
1537 -- If statuses do not match set return status
1538 IF l_sts_match <> g_yes
1539 THEN
1540 -- Validation of contract and/or lines failed for contract CONTRACT_NUMBER.
1541 okl_api.set_message (p_app_name => g_app_name,
1542 p_msg_name => 'OKL_AM_VAL_K_LNS_FAILED',
1543 p_token1 => 'CONTRACT_NUMBER',
1544 p_token1_value => p_term_rec.p_contract_number
1545 );
1546 l_return_status := g_ret_sts_error;
1547 END IF;
1548
1549 -- Set the return status
1550 x_return_status := l_return_status;
1551
1552 IF (is_debug_procedure_on)
1553 THEN
1554 okl_debug_pub.log_debug (g_level_procedure,
1555 l_module_name,
1556 'End(-)'
1557 );
1558 END IF;
1559 EXCEPTION
1560 WHEN OTHERS
1561 THEN
1562 -- Close any cursors which are open
1563 IF chr_sts_csr%ISOPEN
1564 THEN
1565 CLOSE chr_sts_csr;
1566 END IF;
1567
1568 IF cle_sts_csr%ISOPEN
1569 THEN
1570 CLOSE cle_sts_csr;
1571 END IF;
1572
1573 -- Set the oracle error message
1574 okl_api.set_message (p_app_name => g_app_name_1,
1575 p_msg_name => g_unexpected_error,
1576 p_token1 => g_sqlcode_token,
1577 p_token1_value => SQLCODE,
1578 p_token2 => g_sqlerrm_token,
1579 p_token2_value => SQLERRM
1580 );
1581 -- Set the return status
1582 x_return_status := g_ret_sts_unexp_error;
1583
1584 IF (is_debug_exception_on)
1585 THEN
1586 okl_debug_pub.log_debug (g_level_exception,
1587 l_module_name,
1588 'EXCEPTION :'
1589 || 'OTHERS, SQLCODE: '
1590 || SQLCODE
1591 || ' , SQLERRM : '
1592 || SQLERRM
1593 );
1594 END IF;
1595 END validate_contract_and_lines;
1596
1597 -- Start of comments
1598 --
1599 -- Procedure Name : do_split_asset_trn
1600 -- Description : This procedure Creates the Split Trn and Updates the Split TRN if needed
1601 -- Business Rules :
1602 -- Parameters :
1603 -- Version : 1.0
1604 -- History : RMUNJULU 2757312 Added this proc
1605 -- This proc will use tmt_generic_flag1_yn to maintain status of
1606 -- whether the split trn was created and updated successfully or not
1607 -- : rmunjulu EDAT Added code to get quote eff dates and call new overloaded split asset API
1608 -- End of comments
1609 PROCEDURE do_split_asset_trn (
1610 p_term_rec IN term_rec_type,
1611 p_sys_date IN DATE,
1612 p_trn_already_set IN VARCHAR2,
1613 px_overall_status IN OUT NOCOPY VARCHAR2,
1614 px_tcnv_rec IN OUT NOCOPY tcnv_rec_type,
1615 px_klev_tbl IN OUT NOCOPY klev_tbl_type,
1616 x_return_status OUT NOCOPY VARCHAR2
1617 )
1618 IS
1619 -- SECHAWLA 23-DEC-02 2484327 Added cursors
1620 -- Get the count of IB lines for the quote_line_id (TQL_ID )
1621 CURSOR get_ib_lines_cnt_csr (
1622 p_tql_id IN NUMBER
1623 )
1624 IS
1625 SELECT COUNT (txd.ID) ib_lines_count
1626 FROM okl_txd_quote_line_dtls txd
1627 WHERE txd.tql_id = p_tql_id;
1628
1629 -- Get the IB Lines for the quote_line_id (tql_id)
1630 CURSOR get_ib_lines_csr (
1631 p_tql_id IN NUMBER
1632 )
1633 IS
1634 SELECT txd.kle_id
1635 FROM okl_txd_quote_line_dtls txd
1636 WHERE txd.tql_id = p_tql_id;
1637
1638 lx_txdv_tbl okl_txd_assets_pub.adpv_tbl_type;
1639 lx_txlv_rec okl_txl_assets_pub.tlpv_rec_type;
1640 lx_trxv_rec okl_trx_assets_pub.thpv_rec_type;
1641 lx_cle_tbl okl_split_asset_pvt.cle_tbl_type;
1642 lx_sno_yn VARCHAR2 (3) := g_false;
1643 lx_clev_tbl okl_okc_migration_pvt.clev_tbl_type;
1644 lp_ib_tbl okl_split_asset_pvt.ib_tbl_type;
1645 lp_empty_ib_tbl okl_split_asset_pvt.ib_tbl_type;
1646 l_api_name CONSTANT VARCHAR2 (30) := 'do_split_asset_trn';
1647 l_return_status VARCHAR2 (1) := g_ret_sts_success;
1648 cle_index NUMBER := 0;
1649 i NUMBER := 0;
1650 ib_id NUMBER := 0;
1651 l_module_name VARCHAR2 (500)
1652 := g_module_name || 'do_split_asset_trn';
1653 is_debug_exception_on BOOLEAN
1654 := okl_debug_pub.check_log_on (l_module_name, g_level_exception);
1655 is_debug_procedure_on BOOLEAN
1656 := okl_debug_pub.check_log_on (l_module_name, g_level_procedure);
1657 is_debug_statement_on BOOLEAN
1658 := okl_debug_pub.check_log_on (l_module_name, g_level_statement);
1659 --SECHAWLA 14-JAN-03 2748110 : New Declarations
1660 ib_line_id NUMBER := 0;
1661 id_exists VARCHAR2 (1);
1662 -- SECHAWLA 23-DEC-02 2484327 Added variable
1663 l_ib_lines_count NUMBER;
1664 l_api_version CONSTANT NUMBER := g_api_version;
1665 l_msg_count NUMBER := g_miss_num;
1666 l_msg_data VARCHAR2 (2000);
1667 lxx_txdv_tbl okl_txd_assets_pub.adpv_tbl_type;
1668 lx_txd_assets_rec okl_txd_assets_pub.adpv_rec_type;
1669 lx_txdv_rec okl_txd_assets_pub.adpv_rec_type;
1670 j NUMBER;
1671 -- rmunjulu EDAT
1672 l_quote_accpt_date DATE;
1673 l_quote_eff_date DATE;
1674 BEGIN
1675 SAVEPOINT do_split_asset_trn;
1676
1677 IF (is_debug_procedure_on)
1678 THEN
1679 okl_debug_pub.log_debug (g_level_procedure,
1680 l_module_name,
1681 'Begin(+)'
1682 );
1683 END IF;
1684
1685 IF (is_debug_statement_on)
1686 THEN
1687 okl_debug_pub.log_debug (g_level_statement,
1688 l_module_name,
1689 'In param, p_trn_already_set: '
1690 || p_trn_already_set
1691 );
1692 okl_debug_pub.log_debug (g_level_statement,
1693 l_module_name,
1694 'In param, px_overall_status: '
1695 || px_overall_status
1696 );
1697 okl_debug_pub.log_debug (g_level_statement,
1698 l_module_name,
1699 'In param, p_sys_date: ' || p_sys_date
1700 );
1701 okl_debug_pub.log_debug
1702 (g_level_statement,
1703 l_module_name,
1704 'In param, px_tcnv_rec.tmt_generic_flag1_yn: '
1705 || px_tcnv_rec.tmt_generic_flag1_yn
1706 );
1707
1708 IF px_klev_tbl.COUNT > 0
1709 THEN
1710 FOR i IN px_klev_tbl.FIRST .. px_klev_tbl.LAST
1711 LOOP
1712 IF (px_klev_tbl.EXISTS (i))
1713 THEN
1714 okl_debug_pub.log_debug (g_level_statement,
1715 l_module_name,
1716 'In param, px_klev_tbl('
1717 || i
1718 || ').p_kle_id: '
1719 || px_klev_tbl (i).p_kle_id
1720 );
1721 okl_debug_pub.log_debug (g_level_statement,
1722 l_module_name,
1723 'In param, px_klev_tbl('
1724 || i
1725 || ').p_asset_quantity: '
1726 || px_klev_tbl (i).p_asset_quantity
1727 );
1728 okl_debug_pub.log_debug (g_level_statement,
1729 l_module_name,
1730 'In param, px_klev_tbl('
1731 || i
1732 || ').p_asset_name: '
1733 || px_klev_tbl (i).p_asset_name
1734 );
1735 okl_debug_pub.log_debug (g_level_statement,
1736 l_module_name,
1737 'In param, px_klev_tbl('
1738 || i
1739 || ').p_quote_quantity: '
1740 || px_klev_tbl (i).p_quote_quantity
1741 );
1742 okl_debug_pub.log_debug (g_level_statement,
1743 l_module_name,
1744 'In param, px_klev_tbl('
1745 || i
1746 || ').p_tql_id: '
1747 || px_klev_tbl (i).p_tql_id
1748 );
1749 okl_debug_pub.log_debug (g_level_statement,
1750 l_module_name,
1751 'In param, px_klev_tbl('
1752 || i
1753 || ').p_split_kle_name: '
1754 || px_klev_tbl (i).p_split_kle_name
1755 );
1756 END IF;
1757 END LOOP;
1758 END IF;
1759 END IF;
1760
1761 x_return_status := okl_api.g_ret_sts_success;
1762
1763 IF ( p_trn_already_set = g_yes
1764 AND NVL (px_tcnv_rec.tmt_generic_flag1_yn, '?') <> g_yes
1765 )
1766 OR (p_trn_already_set = g_no)
1767 THEN
1768 -- rmunjulu +++++++++ Effective Dated Termination -- start ++++++++++++++++
1769
1770 -- rmunjulu EDAT
1771 -- If quote exists then accnting date is quote accept date else sysdate
1772 IF NVL (okl_am_lease_loan_trmnt_pvt.g_quote_exists, 'N') = 'Y'
1773 THEN
1774 l_quote_accpt_date :=
1775 okl_am_lease_loan_trmnt_pvt.g_quote_accept_date;
1776 l_quote_eff_date :=
1777 okl_am_lease_loan_trmnt_pvt.g_quote_eff_from_date;
1778 ELSE
1779 l_quote_accpt_date := p_sys_date;
1780 l_quote_eff_date := p_sys_date;
1781 END IF;
1782
1783 -- rmunjulu +++++++++ Effective Dated Termination -- end ++++++++++++++++
1784 IF px_klev_tbl.COUNT > 0
1785 THEN
1786 FOR i IN px_klev_tbl.FIRST .. px_klev_tbl.LAST
1787 LOOP
1788 IF px_klev_tbl (i).p_kle_id IS NULL
1789 OR px_klev_tbl (i).p_kle_id = g_miss_num
1790 THEN
1791 -- kle id parameter is null
1792 okl_api.set_message (p_app_name => g_app_name_1,
1793 p_msg_name => g_required_value,
1794 p_token1 => g_col_name_token,
1795 p_token1_value => 'Kle Id'
1796 );
1797 RAISE okl_api.g_exception_error;
1798 END IF;
1799
1800 IF px_klev_tbl (i).p_asset_quantity IS NULL
1801 OR px_klev_tbl (i).p_asset_quantity = okl_api.g_miss_num
1802 THEN
1803 -- Asset Quantity parameter is null
1804 okl_api.set_message (p_app_name => g_app_name_1,
1805 p_msg_name => g_required_value,
1806 p_token1 => g_col_name_token,
1807 p_token1_value => 'Asset Quantity'
1808 );
1809 RAISE okl_api.g_exception_error;
1810 END IF;
1811
1812 IF px_klev_tbl (i).p_asset_name IS NULL
1813 OR px_klev_tbl (i).p_asset_name = okl_api.g_miss_char
1814 THEN
1815 -- Asset Name parameter is null
1816 okl_api.set_message (p_app_name => g_app_name_1,
1817 p_msg_name => g_required_value,
1818 p_token1 => g_col_name_token,
1819 p_token1_value => 'Asset Name'
1820 );
1821 RAISE okl_api.g_exception_error;
1822 END IF;
1823
1824 IF px_klev_tbl (i).p_quote_quantity IS NULL
1825 OR px_klev_tbl (i).p_quote_quantity = okl_api.g_miss_num
1826 THEN
1827 -- Quote Quantity parameter is null
1828 okl_api.set_message (p_app_name => g_app_name_1,
1829 p_msg_name => g_required_value,
1830 p_token1 => g_col_name_token,
1831 p_token1_value => 'Quote Quantity'
1832 );
1833 RAISE okl_api.g_exception_error;
1834 END IF;
1835
1836 IF px_klev_tbl (i).p_tql_id IS NULL
1837 OR px_klev_tbl (i).p_tql_id = okl_api.g_miss_num
1838 THEN
1839 -- quote line id parameter is null
1840 okl_api.set_message (p_app_name => g_app_name_1,
1841 p_msg_name => g_required_value,
1842 p_token1 => g_col_name_token,
1843 p_token1_value => 'Quote Line ID'
1844 );
1845 RAISE okl_api.g_exception_error;
1846 END IF;
1847
1848 -- Check if the IB instances for this asset are serialized
1849 -- also get the IB instances which are serialized
1850 IF (is_debug_statement_on)
1851 THEN
1852 okl_debug_pub.log_debug
1853 (g_level_statement,
1854 l_module_name,
1855 'calling OKL_AM_TERMNT_QUOTE_PVT.check_asset_sno'
1856 );
1857 END IF;
1858
1859 x_return_status :=
1860 okl_am_termnt_quote_pvt.check_asset_sno
1861 (p_asset_line => px_klev_tbl (i).p_kle_id,
1862 x_sno_yn => lx_sno_yn,
1863 x_clev_tbl => lx_clev_tbl
1864 );
1865
1866 IF (is_debug_statement_on)
1867 THEN
1868 okl_debug_pub.log_debug
1869 (g_level_statement,
1870 l_module_name,
1871 'called OKL_AM_TERMNT_QUOTE_PVT.check_asset_sno , return status: '
1872 || x_return_status
1873 );
1874 END IF;
1875
1876 IF (x_return_status = g_ret_sts_unexp_error)
1877 THEN
1878 RAISE okl_api.g_exception_unexpected_error;
1879 ELSIF (x_return_status = g_ret_sts_error)
1880 THEN
1881 RAISE okl_api.g_exception_error;
1882 END IF;
1883
1884 -- If Asset serialized
1885 IF lx_sno_yn = g_true
1886 THEN
1887 -- SECHAWLA 23-DEC-02 2484327 Changed processing to get the correct
1888 -- IB lines for the quote
1889
1890 -- Get the IB line count
1891 OPEN get_ib_lines_cnt_csr (px_klev_tbl (i).p_tql_id);
1892
1893 FETCH get_ib_lines_cnt_csr
1894 INTO l_ib_lines_count;
1895
1896 CLOSE get_ib_lines_cnt_csr;
1897
1898 -- If IB line count does not match Quote Qty raise msg and exp
1899 IF l_ib_lines_count <> px_klev_tbl (i).p_quote_quantity
1900 THEN
1901 -- Asset ASSET_NUMBER is serialized. Quote quantity
1902 -- QUOTE_QUANTITY does not match the number of selected asset
1903 -- units ASSET_UNITS.
1904 okl_api.set_message
1905 (p_app_name => 'OKL',
1906 p_msg_name => 'OKL_AM_QTE_QTY_SRL_CNT_ERR',
1907 p_token1 => 'ASSET_NUMBER',
1908 p_token1_value => px_klev_tbl (i).p_asset_name,
1909 p_token2 => 'QUOTE_QUANTITY',
1910 p_token2_value => px_klev_tbl (i).p_quote_quantity,
1911 p_token3 => 'ASSET_UNITS',
1912 p_token3_value => l_ib_lines_count
1913 );
1914 RAISE okl_api.g_exception_error;
1915 END IF;
1916
1917 --SECHAWLA 14-JAN-03 2748110 : Modified the logic to send those ib
1918 -- line ids that do not exist in
1919 --OKL_TXD_QUOTE_LINE_DTLS_V, to create_split_transaction procedure.
1920 -- This change follows the change
1921 -- in p_split_into_units quantity, on 08-JAN-03, to send
1922 -- asset quantity minus quote quantity as split
1923 -- into units.
1924 IF lx_clev_tbl.COUNT > 0
1925 THEN
1926 ib_line_id := lx_clev_tbl.FIRST;
1927 ib_id := 1;
1928
1929 LOOP
1930 id_exists := 'F';
1931
1932 -- Populate the input table of IB line IDs to create split transaction
1933 -- procedure with rows from okl_txd_quote_line_dtls table
1934 FOR get_ib_lines_rec IN
1935 get_ib_lines_csr (px_klev_tbl (i).p_tql_id)
1936 LOOP
1937 IF lx_clev_tbl (ib_line_id).ID =
1938 get_ib_lines_rec.kle_id
1939 THEN
1940 id_exists := 'T';
1941 EXIT;
1942 END IF;
1943 END LOOP;
1944
1945 IF id_exists = 'F'
1946 THEN
1947 lp_ib_tbl (ib_id).ID :=
1948 lx_clev_tbl (ib_line_id).ID;
1949 ib_id := ib_id + 1;
1950 END IF;
1951
1952 EXIT WHEN (ib_line_id = lx_clev_tbl.LAST);
1953 ib_line_id := lx_clev_tbl.NEXT (ib_line_id);
1954 END LOOP;
1955 ELSE
1956 -- IB line ids not found
1957 okl_api.set_message (p_app_name => g_app_name_1,
1958 p_msg_name => g_required_value,
1959 p_token1 => g_col_name_token,
1960 p_token1_value => 'IB Line IDs'
1961 );
1962 RAISE okl_api.g_exception_error;
1963 END IF;
1964 END IF;
1965
1966 -- Create the split asset transactions
1967 -- rmunjulu EDAT Call the new signature of split asset which takes trx date
1968 IF (is_debug_statement_on)
1969 THEN
1970 okl_debug_pub.log_debug
1971 (g_level_statement,
1972 l_module_name,
1973 'calling OKL_SPLIT_ASSET_PUB.create_split_transaction'
1974 );
1975 END IF;
1976
1977 okl_split_asset_pub.create_split_transaction
1978 (p_api_version => l_api_version,
1979 p_init_msg_list => g_false,
1980 x_return_status => x_return_status,
1981 x_msg_count => l_msg_count,
1982 x_msg_data => l_msg_data,
1983 p_cle_id => px_klev_tbl (i).p_kle_id,
1984 p_split_into_individuals_yn => 'N',
1985 -- RMUNJULU Changed was NULL earlier
1986 p_split_into_units => px_klev_tbl (i).p_asset_quantity
1987 - px_klev_tbl (i).p_quote_quantity,
1988 p_ib_tbl => lp_ib_tbl,
1989 p_trx_date => l_quote_eff_date,
1990 -- rmunjulu EDAT
1991 x_txdv_tbl => lx_txdv_tbl,
1992 --okl_asd_pvt
1993 x_txlv_rec => lx_txlv_rec,
1994 x_trxv_rec => lx_trxv_rec
1995 );
1996
1997 IF (is_debug_statement_on)
1998 THEN
1999 okl_debug_pub.log_debug
2000 (g_level_statement,
2001 l_module_name,
2002 'called OKL_SPLIT_ASSET_PUB.create_split_transaction , return status: '
2003 || x_return_status
2004 );
2005 END IF;
2006
2007 IF (x_return_status = g_ret_sts_unexp_error)
2008 THEN
2009 RAISE okl_api.g_exception_unexpected_error;
2010 ELSIF (x_return_status = g_ret_sts_error)
2011 THEN
2012 RAISE okl_api.g_exception_error;
2013 END IF;
2014
2015 -- get the transaction which needs to be updated
2016 IF px_klev_tbl (i).p_split_kle_name IS NOT NULL
2017 AND px_klev_tbl (i).p_split_kle_name <> g_miss_char
2018 THEN
2019 IF lx_txdv_tbl.COUNT > 0
2020 THEN
2021 -- Update the TXDV rec which has no target_kle_id ie which is the
2022 -- new asset created
2023 FOR j IN lx_txdv_tbl.FIRST .. lx_txdv_tbl.LAST
2024 LOOP
2025 IF lx_txdv_tbl (j).target_kle_id IS NULL
2026 THEN
2027 lx_txd_assets_rec.asset_number :=
2028 px_klev_tbl (i).p_split_kle_name;
2029 lx_txd_assets_rec.ID := lx_txdv_tbl (j).ID;
2030
2031 IF (is_debug_statement_on)
2032 THEN
2033 okl_debug_pub.log_debug
2034 (g_level_statement,
2035 l_module_name,
2036 'calling OKL_TXD_ASSETS_PUB.update_txd_asset_def'
2037 );
2038 END IF;
2039
2040 okl_txd_assets_pub.update_txd_asset_def
2041 (p_api_version => l_api_version,
2042 p_init_msg_list => g_false,
2043 x_return_status => x_return_status,
2044 x_msg_count => l_msg_count,
2045 x_msg_data => l_msg_data,
2046 p_adpv_rec => lx_txd_assets_rec,
2047 x_adpv_rec => lx_txdv_rec
2048 );
2049
2050 IF (is_debug_statement_on)
2051 THEN
2052 okl_debug_pub.log_debug
2053 (g_level_statement,
2054 l_module_name,
2055 'called OKL_TXD_ASSETS_PUB.update_txd_asset_def , return status: '
2056 || x_return_status
2057 );
2058 END IF;
2059
2060 IF (x_return_status = g_ret_sts_unexp_error)
2061 THEN
2062 RAISE okl_api.g_exception_unexpected_error;
2063 ELSIF (x_return_status = g_ret_sts_error)
2064 THEN
2065 RAISE okl_api.g_exception_error;
2066 END IF;
2067 END IF;
2068 END LOOP;
2069 ELSE
2070 -- Create Split Trn did not work properly
2071 okl_api.set_message
2072 (p_app_name => g_app_name_1,
2073 p_msg_name => g_invalid_value,
2074 p_token1 => g_col_name_token,
2075 p_token1_value => 'lx_txdv_tbl.COUNT'
2076 );
2077 RAISE okl_api.g_exception_error;
2078 END IF;
2079 END IF;
2080 END LOOP;
2081 END IF;
2082
2083 -- store the highest degree of error
2084 set_overall_status (p_return_status => x_return_status,
2085 px_overall_status => px_overall_status);
2086
2087 IF (is_debug_statement_on)
2088 THEN
2089 okl_debug_pub.log_debug
2090 (g_level_statement,
2091 l_module_name,
2092 'called set_overall_status , return status: '
2093 || x_return_status
2094 );
2095 okl_debug_pub.log_debug (g_level_statement,
2096 l_module_name,
2097 'px_overall_status: '
2098 || px_overall_status
2099 );
2100 END IF;
2101
2102 -- set the transaction record
2103 set_transaction_rec (p_return_status => x_return_status,
2104 p_overall_status => px_overall_status,
2105 p_tmt_flag => 'TMT_GENERIC_FLAG1_YN',
2106 p_tsu_code => 'WORKING',
2107 px_tcnv_rec => px_tcnv_rec
2108 );
2109
2110 IF (is_debug_statement_on)
2111 THEN
2112 okl_debug_pub.log_debug
2113 (g_level_statement,
2114 l_module_name,
2115 'called set_transaction_rec , return status: '
2116 || x_return_status
2117 );
2118 okl_debug_pub.log_debug (g_level_statement,
2119 l_module_name,
2120 'px_overall_status: '
2121 || px_overall_status
2122 );
2123 END IF;
2124 END IF;
2125
2126 IF (is_debug_procedure_on)
2127 THEN
2128 okl_debug_pub.log_debug (g_level_procedure,
2129 l_module_name,
2130 'End(-)'
2131 );
2132 END IF;
2133 EXCEPTION
2134 WHEN okl_api.g_exception_error
2135 THEN
2136 -- SECHAWLA 23-DEC-02 2484327 Closed cursors if open
2137 IF get_ib_lines_cnt_csr%ISOPEN
2138 THEN
2139 CLOSE get_ib_lines_cnt_csr;
2140 END IF;
2141
2142 IF get_ib_lines_csr%ISOPEN
2143 THEN
2144 CLOSE get_ib_lines_csr;
2145 END IF;
2146
2147 ROLLBACK TO do_split_asset_trn;
2148 x_return_status := g_ret_sts_error;
2149 -- store the highest degree of error
2150 set_overall_status (p_return_status => x_return_status,
2151 px_overall_status => px_overall_status);
2152 -- set the transaction record
2153 set_transaction_rec (p_return_status => x_return_status,
2154 p_overall_status => px_overall_status,
2155 p_tmt_flag => 'TMT_GENERIC_FLAG1_YN',
2156 p_tsu_code => 'ERROR',
2157 px_tcnv_rec => px_tcnv_rec
2158 );
2159
2160 IF (is_debug_exception_on)
2161 THEN
2162 okl_debug_pub.log_debug (g_level_exception,
2163 l_module_name,
2164 'EXCEPTION :' || 'G_EXCEPTION_ERROR'
2165 );
2166 END IF;
2167 WHEN okl_api.g_exception_unexpected_error
2168 THEN
2169 -- SECHAWLA 23-DEC-02 2484327 Closed cursors if open
2170 IF get_ib_lines_cnt_csr%ISOPEN
2171 THEN
2172 CLOSE get_ib_lines_cnt_csr;
2173 END IF;
2174
2175 IF get_ib_lines_csr%ISOPEN
2176 THEN
2177 CLOSE get_ib_lines_csr;
2178 END IF;
2179
2180 ROLLBACK TO do_split_asset_trn;
2181 x_return_status := g_ret_sts_unexp_error;
2182 -- store the highest degree of error
2183 set_overall_status (p_return_status => x_return_status,
2184 px_overall_status => px_overall_status);
2185 -- set the transaction record
2186 set_transaction_rec (p_return_status => x_return_status,
2187 p_overall_status => px_overall_status,
2188 p_tmt_flag => 'TMT_GENERIC_FLAG1_YN',
2189 p_tsu_code => 'ERROR',
2190 px_tcnv_rec => px_tcnv_rec
2191 );
2192
2193 IF (is_debug_exception_on)
2194 THEN
2195 okl_debug_pub.log_debug (g_level_exception,
2196 l_module_name,
2197 'EXCEPTION :'
2198 || 'G_EXCEPTION_UNEXPECTED_ERROR'
2199 );
2200 END IF;
2201 WHEN OTHERS
2202 THEN
2203 -- SECHAWLA 23-DEC-02 2484327 Closed cursors if open
2204 IF get_ib_lines_cnt_csr%ISOPEN
2205 THEN
2206 CLOSE get_ib_lines_cnt_csr;
2207 END IF;
2208
2209 IF get_ib_lines_csr%ISOPEN
2210 THEN
2211 CLOSE get_ib_lines_csr;
2212 END IF;
2213
2214 ROLLBACK TO do_split_asset_trn;
2215 x_return_status := g_ret_sts_unexp_error;
2216 -- Set the oracle error message
2217 okl_api.set_message (p_app_name => g_app_name_1,
2218 p_msg_name => g_unexpected_error,
2219 p_token1 => g_sqlcode_token,
2220 p_token1_value => SQLCODE,
2221 p_token2 => g_sqlerrm_token,
2222 p_token2_value => SQLERRM
2223 );
2224 -- store the highest degree of error
2225 set_overall_status (p_return_status => x_return_status,
2226 px_overall_status => px_overall_status);
2227 -- set the transaction record
2228 set_transaction_rec (p_return_status => x_return_status,
2229 p_overall_status => px_overall_status,
2230 p_tmt_flag => 'TMT_GENERIC_FLAG1_YN',
2231 p_tsu_code => 'ERROR',
2232 px_tcnv_rec => px_tcnv_rec
2233 );
2234
2235 IF (is_debug_exception_on)
2236 THEN
2237 okl_debug_pub.log_debug (g_level_exception,
2238 l_module_name,
2239 'EXCEPTION :'
2240 || 'OTHERS, SQLCODE: '
2241 || SQLCODE
2242 || ' , SQLERRM : '
2243 || SQLERRM
2244 );
2245 END IF;
2246 END do_split_asset_trn;
2247
2248 -- Start of comments
2249 --
2250 -- Procedure Name : do_split_asset
2251 -- Description : This procedure splits a financial asset into two
2252 -- Business Rules :
2253 -- Parameters : Input/Output parameters : px_klev_tbl
2254 -- px_klev_tbl is a table of records of the following structure :
2255
2256 -- p_kle_id : Original kle ID
2257 -- p_asset_quantity : Asset Quantity
2258 -- p_asset_name : Asset Number
2259 -- p_quote_quantity : Quantity to Split
2260 -- p_tql_id : Quote Line ID
2261 -- p_split_kle_id : Split (new) Kle Id
2262 --
2263 -- Version : 1.0
2264 -- History : SECHAWLA 16-DEC-02 Bug# 2484327 Created
2265 -- SECHAWLA 23-DEC-02 2484327 Changed the way IB line ids are identified
2266 -- SECHAWLA 08-JAN-03 2736865 Changed the logic to send (asset qty - quote qty)
2267 -- in p_split_into_units parameter, instead of sending the quote qty
2268 -- SECHAWLA 14-JAN-03 2748110 : Modified the logic to send
2269 -- those ib line ids that do not exist in
2270 -- OKL_TXD_QUOTE_LINE_DTLS_V, to create_split_transaction procedure
2271 -- RMUNJULU 2757312 MAJOR CHANGES TO this proc
2272 -- Added parameters, removed create split trn to do_split_trn
2273 -- coded for two flags to maintain split asset status
2274 -- This proc will use tmt_split_asset_yn
2275 -- RMUNJULU 2757312 Added code to check that split trn is not processed
2276 -- RMUNJULU ASSETNUM INPUT 2757312 Added code to make sure error from split
2277 -- asset is becos of uniqueness failure
2278 -- RMUNJULU 3241502 Call asset_number_exists from OKL_AM_CREATE_QUOTE_PVT
2279 -- SECHAWLA Split Asset Enhancements (FPs) Addes a parameter p_source_call in call to
2280 -- OKL_SPLIT_ASSET_PUB.split_fixed_asset
2281 -- End of comments
2282 PROCEDURE do_split_asset (
2283 p_term_rec IN term_rec_type,
2284 --RMUNJULU 2757312 Added
2285 p_sys_date IN DATE, --RMUNJULU 2757312 Added
2286 p_trn_already_set IN VARCHAR2, --RMUNJULU 2757312 Added
2287 px_overall_status IN OUT NOCOPY VARCHAR2, --RMUNJULU 2757312 Added
2288 px_tcnv_rec IN OUT NOCOPY tcnv_rec_type,
2289 --RMUNJULU 2757312 Added
2290 px_klev_tbl IN OUT NOCOPY klev_tbl_type,
2291 x_return_status OUT NOCOPY VARCHAR2
2292 )
2293 IS
2294 -- SECHAWLA 23-DEC-02 2484327 Added cursors
2295 -- Get the count of IB lines for the quote_line_id (TQL_ID )
2296 CURSOR get_ib_lines_cnt_csr (
2297 p_tql_id IN NUMBER
2298 )
2299 IS
2300 SELECT COUNT (txd.ID) ib_lines_count
2301 FROM okl_txd_quote_line_dtls txd
2302 WHERE txd.tql_id = p_tql_id;
2303
2304 -- Get the IB Lines for the quote_line_id (tql_id)
2305 CURSOR get_ib_lines_csr (
2306 p_tql_id IN NUMBER
2307 )
2308 IS
2309 SELECT txd.kle_id
2310 FROM okl_txd_quote_line_dtls txd
2311 WHERE txd.tql_id = p_tql_id;
2312
2313 lx_txdv_tbl okl_txd_assets_pub.adpv_tbl_type;
2314 lx_txlv_rec okl_txl_assets_pub.tlpv_rec_type;
2315 lx_trxv_rec okl_trx_assets_pub.thpv_rec_type;
2316 lx_cle_tbl okl_split_asset_pvt.cle_tbl_type;
2317 lx_sno_yn VARCHAR2 (3) := g_false;
2318 lx_clev_tbl okl_okc_migration_pvt.clev_tbl_type;
2319 lp_ib_tbl okl_split_asset_pvt.ib_tbl_type;
2320 lp_empty_ib_tbl okl_split_asset_pvt.ib_tbl_type;
2321 l_api_name CONSTANT VARCHAR2 (30) := 'do_split_asset';
2322 l_return_status VARCHAR2 (1) := g_ret_sts_success;
2323 cle_index NUMBER := 0;
2324 i NUMBER := 0;
2325 ib_id NUMBER := 0;
2326 l_module_name VARCHAR2 (500)
2327 := g_module_name || 'do_split_asset';
2328 is_debug_exception_on BOOLEAN
2329 := okl_debug_pub.check_log_on (l_module_name, g_level_exception);
2330 is_debug_procedure_on BOOLEAN
2331 := okl_debug_pub.check_log_on (l_module_name, g_level_procedure);
2332 is_debug_statement_on BOOLEAN
2333 := okl_debug_pub.check_log_on (l_module_name, g_level_statement);
2334 --SECHAWLA 14-JAN-03 2748110 : New Declarations
2335 ib_line_id NUMBER := 0;
2336 id_exists VARCHAR2 (1);
2337 -- SECHAWLA 23-DEC-02 2484327 Added variable
2338 l_ib_lines_count NUMBER;
2339 l_api_version CONSTANT NUMBER := g_api_version;
2340 l_msg_count NUMBER := g_miss_num;
2341 l_msg_data VARCHAR2 (2000);
2342 -- RMUNJULU 2757312 added
2343 lp_tqlv_tbl okl_txl_quote_lines_pub.tqlv_tbl_type;
2344 lx_tqlv_tbl okl_txl_quote_lines_pub.tqlv_tbl_type;
2345 l_new_asset_name VARCHAR2 (2000);
2346 l_new_asset_quantity NUMBER;
2347
2348 -- RMUNJULU 2757312 added
2349 -- Get the asset name
2350 CURSOR get_asset_name_csr (
2351 p_kle_id IN NUMBER
2352 )
2353 IS
2354 SELECT kle.NAME NAME
2355 FROM okc_k_lines_v kle
2356 WHERE kle.ID = p_kle_id;
2357
2358 -- RMUNJULU 2757312 added
2359 -- Get the ENTERED split trn
2360 -- RMUNJULU ASSETNUM INPUT 2757312
2361 -- Added txl.id to select
2362 CURSOR get_split_trn_csr (
2363 p_kle_id IN NUMBER
2364 )
2365 IS
2366 SELECT 'N',
2367 txl.ID
2368 FROM okl_txl_assets_b txl,
2369 okl_trx_assets trx,
2370 okc_k_lines_v kle_fin,
2371 okc_k_lines_v kle_fix,
2372 okc_line_styles_b lty_fin,
2373 okc_line_styles_b lty_fix
2374 WHERE txl.tal_type = 'ALI'
2375 AND trx.tsu_code = 'ENTERED'
2376 AND txl.tas_id = trx.ID
2377 AND kle_fin.lse_id = lty_fin.ID
2378 AND lty_fin.lty_code = 'FREE_FORM1'
2379 AND kle_fin.ID = kle_fix.cle_id
2380 AND kle_fix.lse_id = lty_fix.ID
2381 AND lty_fix.lty_code = 'FIXED_ASSET'
2382 AND txl.kle_id = kle_fix.ID
2383 AND kle_fin.ID = p_kle_id;
2384
2385 -- RMUNJULU ASSETNUM INPUT 2757312
2386 -- Get the split asset
2387 CURSOR get_split_asset_csr (
2388 p_tal_id IN NUMBER
2389 )
2390 IS
2391 SELECT asset_number
2392 FROM okl_txd_assets_b
2393 WHERE tal_id = p_tal_id AND target_kle_id IS NULL;
2394
2395 l_split_trn_processed_yn VARCHAR2 (1) := 'Y';
2396 -- RMUNJULU ASSETNUM INPUT 2757312
2397 l_split_trn_id NUMBER;
2398 l_split_asset VARCHAR2 (400);
2399 l_asset_exists VARCHAR2 (3);
2400
2401 -- RMUNJULU ASSETNUM INPUT 2757312 Added function
2402 -- Function to check asset number is not duplicated
2403 FUNCTION asset_number_exists (
2404 p_asset_number IN VARCHAR2
2405 )
2406 RETURN VARCHAR2
2407 IS
2408 l_asset_exists VARCHAR2 (1) DEFAULT 'N';
2409 l_module_name VARCHAR2 (500)
2410 := g_module_name || 'asset_number_exists';
2411
2412 --chk for asset in FA
2413 CURSOR asset_chk_curs1 (
2414 p_asset_number IN VARCHAR2
2415 )
2416 IS
2417 SELECT 'Y' a
2418 FROM okx_assets_v okx
2419 WHERE okx.asset_number = p_asset_number;
2420
2421 --chk for asset on asset line
2422 CURSOR asset_chk_curs2 (
2423 p_asset_number IN VARCHAR2
2424 )
2425 IS
2426 SELECT 'Y' a
2427 FROM okl_k_lines_full_v kle,
2428 okc_line_styles_b lse
2429 WHERE kle.NAME = p_asset_number
2430 AND kle.lse_id = lse.ID
2431 AND lse.lty_code = 'FIXED_ASSET';
2432 BEGIN
2433 IF (is_debug_procedure_on)
2434 THEN
2435 okl_debug_pub.log_debug (g_level_procedure,
2436 l_module_name,
2437 'Begin(+)'
2438 );
2439 END IF;
2440
2441 IF (is_debug_statement_on)
2442 THEN
2443 okl_debug_pub.log_debug (g_level_statement,
2444 l_module_name,
2445 'In param, p_asset_number: '
2446 || p_asset_number
2447 );
2448 END IF;
2449
2450 FOR asset_chk_rec1 IN asset_chk_curs1 (p_asset_number)
2451 LOOP
2452 l_asset_exists := asset_chk_rec1.a;
2453
2454 IF l_asset_exists <> 'Y'
2455 THEN
2456 FOR asset_chk_rec2 IN asset_chk_curs2 (p_asset_number)
2457 LOOP
2458 l_asset_exists := asset_chk_rec2.a;
2459 END LOOP;
2460 END IF;
2461 END LOOP;
2462
2463 IF (is_debug_statement_on)
2464 THEN
2465 okl_debug_pub.log_debug (g_level_statement,
2466 l_module_name,
2467 'Returning l_asset_exists: '
2468 || l_asset_exists
2469 );
2470 END IF;
2471
2472 IF (is_debug_procedure_on)
2473 THEN
2474 okl_debug_pub.log_debug (g_level_procedure,
2475 l_module_name,
2476 'End(-)'
2477 );
2478 END IF;
2479
2480 RETURN (l_asset_exists);
2481 EXCEPTION
2482 WHEN OTHERS
2483 THEN
2484 -- store SQL error message on message stack for caller
2485 okl_api.set_message (g_app_name,
2486 g_unexpected_error,
2487 g_sqlcode_token,
2488 SQLCODE,
2489 g_sqlerrm_token,
2490 SQLERRM
2491 );
2492
2493 IF (is_debug_exception_on)
2494 THEN
2495 okl_debug_pub.log_debug (g_level_exception,
2496 l_module_name,
2497 'EXCEPTION :'
2498 || 'OTHERS, SQLCODE: '
2499 || SQLCODE
2500 || ' , SQLERRM : '
2501 || SQLERRM
2502 );
2503 END IF;
2504
2505 RETURN ('N');
2506 END asset_number_exists;
2507 BEGIN
2508 SAVEPOINT do_split_asset;
2509
2510 IF (is_debug_procedure_on)
2511 THEN
2512 okl_debug_pub.log_debug (g_level_procedure,
2513 l_module_name,
2514 'Begin(+)'
2515 );
2516 END IF;
2517
2518 IF (is_debug_statement_on)
2519 THEN
2520 okl_debug_pub.log_debug
2521 (g_level_statement,
2522 l_module_name,
2523 'In param, p_term_rec.p_contract_number: '
2524 || p_term_rec.p_contract_number
2525 );
2526 okl_debug_pub.log_debug (g_level_statement,
2527 l_module_name,
2528 'In param, p_sys_date: ' || p_sys_date
2529 );
2530 okl_debug_pub.log_debug (g_level_statement,
2531 l_module_name,
2532 'In param, p_trn_already_set: '
2533 || p_trn_already_set
2534 );
2535 okl_debug_pub.log_debug (g_level_statement,
2536 l_module_name,
2537 'In param, px_overall_status: '
2538 || px_overall_status
2539 );
2540 okl_debug_pub.log_debug
2541 (g_level_statement,
2542 l_module_name,
2543 'In param, px_tcnv_rec.tmt_split_asset_yn: '
2544 || px_tcnv_rec.tmt_split_asset_yn
2545 );
2546
2547 IF px_klev_tbl.COUNT > 0
2548 THEN
2549 FOR i IN px_klev_tbl.FIRST .. px_klev_tbl.LAST
2550 LOOP
2551 IF (px_klev_tbl.EXISTS (i))
2552 THEN
2553 okl_debug_pub.log_debug (g_level_statement,
2554 l_module_name,
2555 'In param, px_klev_tbl('
2556 || i
2557 || ').p_kle_id: '
2558 || px_klev_tbl (i).p_kle_id
2559 );
2560 okl_debug_pub.log_debug (g_level_statement,
2561 l_module_name,
2562 'In param, px_klev_tbl('
2563 || i
2564 || ').p_asset_quantity: '
2565 || px_klev_tbl (i).p_asset_quantity
2566 );
2567 okl_debug_pub.log_debug (g_level_statement,
2568 l_module_name,
2569 'In param, px_klev_tbl('
2570 || i
2571 || ').p_asset_name: '
2572 || px_klev_tbl (i).p_asset_name
2573 );
2574 okl_debug_pub.log_debug (g_level_statement,
2575 l_module_name,
2576 'In param, px_klev_tbl('
2577 || i
2578 || ').p_quote_quantity: '
2579 || px_klev_tbl (i).p_quote_quantity
2580 );
2581 okl_debug_pub.log_debug (g_level_statement,
2582 l_module_name,
2583 'In param, px_klev_tbl('
2584 || i
2585 || ').p_tql_id: '
2586 || px_klev_tbl (i).p_tql_id
2587 );
2588 okl_debug_pub.log_debug (g_level_statement,
2589 l_module_name,
2590 'In param, px_klev_tbl('
2591 || i
2592 || ').p_split_kle_name: '
2593 || px_klev_tbl (i).p_split_kle_name
2594 );
2595 END IF;
2596 END LOOP;
2597 END IF;
2598 END IF;
2599
2600 x_return_status := okl_api.g_ret_sts_success;
2601
2602 IF ( p_trn_already_set = g_yes
2603 AND NVL (px_tcnv_rec.tmt_split_asset_yn, '?') <> g_yes
2604 )
2605 OR (p_trn_already_set = g_no)
2606 THEN
2607 IF px_klev_tbl.COUNT > 0
2608 THEN
2609 -- Loop thru financial assets
2610 FOR i IN px_klev_tbl.FIRST .. px_klev_tbl.LAST
2611 LOOP
2612 -- Check the trn if processed if processed then set tmt_split_asset_yn = y and do
2613 -- not do split, but how to get split_kle_id and update the quote with split_kle_id
2614 -- AND split_kle_name
2615 -- For financial asset line - get fixed asset line
2616 -- query for all trns in txl_assets for fixed asset line of tal_type 'ALI'
2617 -- see if the trx_assets trn is not in status other than processed
2618 OPEN get_split_trn_csr (px_klev_tbl (i).p_kle_id);
2619
2620 FETCH get_split_trn_csr
2621 INTO l_split_trn_processed_yn,
2622 l_split_trn_id;
2623 -- RMUNJULU ASSETNUM INPUT 2757312 Added l_split_trn_id
2624
2625 CLOSE get_split_trn_csr;
2626
2627 -- If Not Processed Split Trn exists then our split trn is pending
2628 IF l_split_trn_processed_yn = 'N'
2629 THEN
2630 IF (is_debug_statement_on)
2631 THEN
2632 okl_debug_pub.log_debug
2633 (g_level_statement,
2634 l_module_name,
2635 'calling OKL_SPLIT_ASSET_PUB.split_fixed_asset'
2636 );
2637 END IF;
2638
2639 -- Process split asset transactions
2640 okl_split_asset_pub.split_fixed_asset
2641 (p_api_version => l_api_version,
2642 p_init_msg_list => g_false,
2643 x_return_status => x_return_status,
2644 x_msg_count => l_msg_count,
2645 x_msg_data => l_msg_data,
2646 p_cle_id => px_klev_tbl
2647 (i).p_kle_id,
2648 x_cle_tbl => lx_cle_tbl,
2649 p_source_call => 'PARTIAL_TERM'
2650 );
2651 -- sechawla 18-dec-07 - Split Asset Enhancements
2652
2653 IF (is_debug_statement_on)
2654 THEN
2655 okl_debug_pub.log_debug
2656 (g_level_statement,
2657 l_module_name,
2658 'called OKL_SPLIT_ASSET_PUB.split_fixed_asset , return status: '
2659 || x_return_status
2660 );
2661 END IF;
2662
2663 -- Try doing split for all split assets and get all errors
2664 IF x_return_status <> okl_api.g_ret_sts_success
2665 THEN
2666 -- RMUNJULU ASSETNUM INPUT 2757312
2667 -- Get the split asset from the split transaction
2668 FOR get_split_asset_rec IN
2669 get_split_asset_csr (l_split_trn_id)
2670 LOOP
2671 l_split_asset := get_split_asset_rec.asset_number;
2672
2673 IF (is_debug_statement_on)
2674 THEN
2675 okl_debug_pub.log_debug
2676 (g_level_statement,
2677 l_module_name,
2678 'calling OKL_AM_CREATE_QUOTE_PVT.asset_number_exists'
2679 );
2680 END IF;
2681
2682 -- RMUNJULU 3241502 Call asset_number_exists from OKL_AM_CREATE_QUOTE_PVT
2683 l_return_status :=
2684 okl_am_create_quote_pvt.asset_number_exists
2685 (p_asset_number => l_split_asset,
2686 x_asset_exists => l_asset_exists);
2687
2688 IF (is_debug_statement_on)
2689 THEN
2690 okl_debug_pub.log_debug
2691 (g_level_statement,
2692 l_module_name,
2693 'called OKL_AM_CREATE_QUOTE_PVT.asset_number_exists , return status: '
2694 || l_return_status
2695 );
2696 END IF;
2697
2698 -- Make sure new asset is not unique before throwing message saying so
2699 IF l_asset_exists = 'Y'
2700 THEN
2701 -- New Asset Number NEW_ASSET_NUMBER is not unique. Please update the
2702 -- New Asset Number for the Contract CONTRACT_NUMBER and Original
2703 -- Asset Number ORIG_ASSET_NUMBER from the Split Asset screen.
2704 okl_api.set_message
2705 (p_app_name => g_app_name,
2706 p_msg_name => 'OKL_AM_SPLIT_ASSET_ERROR',
2707 p_token1 => 'NEW_ASSET_NUMBER',
2708 p_token1_value => l_split_asset,
2709 -- RMUNJULU ASSETNUM INPUT 2757312
2710 p_token2 => 'CONTRACT_NUMBER',
2711 p_token2_value => p_term_rec.p_contract_number,
2712 p_token3 => 'ORIG_ASSET_NUMBER',
2713 p_token3_value => px_klev_tbl (i).p_asset_name
2714 );
2715 END IF;
2716 END LOOP;
2717
2718 -- Set Return status
2719 l_return_status := x_return_status;
2720 END IF;
2721
2722 IF x_return_status = okl_api.g_ret_sts_success
2723 THEN
2724 -- RMUNJULU 2757312 Added this IF
2725 IF lx_cle_tbl.COUNT = 2
2726 THEN
2727 -- lx_cle_tbl returns 2 rows. One for the original kle id and
2728 -- the other one for the split (new) kle_id
2729 cle_index := lx_cle_tbl.FIRST;
2730
2731 IF lx_cle_tbl (cle_index).cle_id <>
2732 px_klev_tbl (i).p_kle_id
2733 THEN
2734 -- split kle id is the first one in the table
2735 px_klev_tbl (i).p_split_kle_id :=
2736 lx_cle_tbl (cle_index).cle_id;
2737 ELSE
2738 -- split kle id is the second one in the table
2739 px_klev_tbl (i).p_split_kle_id :=
2740 lx_cle_tbl (cle_index + 1).cle_id;
2741 END IF;
2742 ELSE
2743 -- Invalid value for x_cle_tbl.
2744 okl_api.set_message (p_app_name => g_app_name_1,
2745 p_msg_name => g_invalid_value,
2746 p_token1 => g_col_name_token,
2747 p_token1_value => 'x_cle_tbl'
2748 );
2749 RAISE okl_api.g_exception_error;
2750 END IF;
2751 END IF;
2752 END IF;
2753 END LOOP;
2754 END IF;
2755
2756 -- Raise Exception here after trying to do all splits
2757 IF (l_return_status = g_ret_sts_unexp_error)
2758 THEN
2759 RAISE okl_api.g_exception_unexpected_error;
2760 ELSIF (l_return_status = g_ret_sts_error)
2761 THEN
2762 RAISE okl_api.g_exception_error;
2763 END IF;
2764
2765 --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++START
2766 -- RMUNJULU 2757312 ADD code
2767
2768 -- RMUNJULU Bug # 2484327 16-DEC-02
2769 -- Set the lp_tqlv_tbl and call OKL_TXL_QUOTE_LINES_PUB, set
2770 -- success messages
2771 IF px_klev_tbl.COUNT > 0
2772 THEN
2773 FOR i IN px_klev_tbl.FIRST .. px_klev_tbl.LAST
2774 LOOP
2775 -- Set the TXL_quote_lines rec to set the split_kle_id
2776 lp_tqlv_tbl (i).ID := px_klev_tbl (i).p_tql_id;
2777 lp_tqlv_tbl (i).split_kle_id := px_klev_tbl (i).p_split_kle_id;
2778 END LOOP;
2779 END IF;
2780
2781 IF (is_debug_statement_on)
2782 THEN
2783 okl_debug_pub.log_debug
2784 (g_level_statement,
2785 l_module_name,
2786 'calling OKL_TXL_QUOTE_LINES_PUB.update_txl_quote_lines'
2787 );
2788 END IF;
2789
2790 -- Call the TAPI to update TXL_quote_lines
2791 okl_txl_quote_lines_pub.update_txl_quote_lines
2792 (p_api_version => l_api_version,
2793 p_init_msg_list => g_false,
2794 x_return_status => x_return_status,
2795 x_msg_count => l_msg_count,
2796 x_msg_data => l_msg_data,
2797 p_tqlv_tbl => lp_tqlv_tbl,
2798 x_tqlv_tbl => lx_tqlv_tbl
2799 );
2800
2801 IF (is_debug_statement_on)
2802 THEN
2803 okl_debug_pub.log_debug
2804 (g_level_statement,
2805 l_module_name,
2806 'called OKL_TXL_QUOTE_LINES_PUB.update_txl_quote_lines , return status: '
2807 || x_return_status
2808 );
2809 END IF;
2810
2811 -- Raise exception to rollback to if error
2812 IF (x_return_status = g_ret_sts_unexp_error)
2813 THEN
2814 RAISE okl_api.g_exception_unexpected_error;
2815 ELSIF (x_return_status = g_ret_sts_error)
2816 THEN
2817 RAISE okl_api.g_exception_error;
2818 END IF;
2819
2820 IF px_klev_tbl.COUNT > 0
2821 THEN
2822 -- Set the success messages if successful split and update
2823 FOR i IN px_klev_tbl.FIRST .. px_klev_tbl.LAST
2824 LOOP
2825 OPEN get_asset_name_csr (px_klev_tbl (i).p_split_kle_id);
2826
2827 FETCH get_asset_name_csr
2828 INTO l_new_asset_name;
2829
2830 CLOSE get_asset_name_csr;
2831
2832 l_new_asset_quantity :=
2833 px_klev_tbl (i).p_asset_quantity
2834 - px_klev_tbl (i).p_quote_quantity;
2835 -- Asset ASSET_NUMBER_OLD has been split. Asset ASSET_NUMBER_OLD
2836 -- retains quantity QUANTITY_OLD. New asset ASSET_NUMBER_NEW has
2837 -- been created with quantity QUANTITY_NEW.
2838 -- RMUNJULU 03-JAN-03 2683876 Changed msg token
2839 -- RMUNJULU 21-JAN-03 2760324 Removed additonal msg token
2840 okl_api.set_message
2841 (p_app_name => g_app_name,
2842 p_msg_name => 'OKL_AM_SPLIT_ASSET_MSG',
2843 p_token1 => 'ASSET_NUMBER_OLD',
2844 p_token1_value => px_klev_tbl (i).p_asset_name,
2845 p_token2 => 'QUANTITY_OLD',
2846 p_token2_value => px_klev_tbl (i).p_quote_quantity,
2847 p_token3 => 'ASSET_NUMBER_NEW',
2848 p_token3_value => l_new_asset_name,
2849 p_token4 => 'QUANTITY_NEW',
2850 p_token4_value => l_new_asset_quantity
2851 );
2852 END LOOP;
2853 END IF;
2854
2855 -- store the highest degree of error
2856 set_overall_status (p_return_status => x_return_status,
2857 px_overall_status => px_overall_status);
2858 -- set the transaction record
2859 set_transaction_rec (p_return_status => x_return_status,
2860 p_overall_status => px_overall_status,
2861 p_tmt_flag => 'TMT_SPLIT_ASSET_YN',
2862 p_tsu_code => 'WORKING',
2863 px_tcnv_rec => px_tcnv_rec
2864 );
2865 --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++END
2866 END IF;
2867
2868 IF (is_debug_procedure_on)
2869 THEN
2870 okl_debug_pub.log_debug (g_level_procedure,
2871 l_module_name,
2872 'End(-)'
2873 );
2874 END IF;
2875 EXCEPTION
2876 WHEN okl_api.g_exception_error
2877 THEN
2878 -- SECHAWLA 23-DEC-02 2484327 Closed cursors if open
2879 IF get_ib_lines_cnt_csr%ISOPEN
2880 THEN
2881 CLOSE get_ib_lines_cnt_csr;
2882 END IF;
2883
2884 IF get_ib_lines_csr%ISOPEN
2885 THEN
2886 CLOSE get_ib_lines_csr;
2887 END IF;
2888
2889 -- close open cursors
2890 IF get_asset_name_csr%ISOPEN
2891 THEN
2892 CLOSE get_asset_name_csr;
2893 END IF;
2894
2895 IF get_split_trn_csr%ISOPEN
2896 THEN
2897 CLOSE get_split_trn_csr;
2898 END IF;
2899
2900 ROLLBACK TO do_split_asset;
2901 x_return_status := g_ret_sts_error;
2902 -- store the highest degree of error
2903 set_overall_status (p_return_status => x_return_status,
2904 px_overall_status => px_overall_status);
2905 -- set the transaction record
2906 set_transaction_rec (p_return_status => x_return_status,
2907 p_overall_status => px_overall_status,
2908 p_tmt_flag => 'TMT_SPLIT_ASSET_YN',
2909 p_tsu_code => 'ERROR',
2910 px_tcnv_rec => px_tcnv_rec
2911 );
2912
2913 IF (is_debug_exception_on)
2914 THEN
2915 okl_debug_pub.log_debug (g_level_exception,
2916 l_module_name,
2917 'EXCEPTION :' || 'G_EXCEPTION_ERROR'
2918 );
2919 END IF;
2920 WHEN okl_api.g_exception_unexpected_error
2921 THEN
2922 -- SECHAWLA 23-DEC-02 2484327 Closed cursors if open
2923 IF get_ib_lines_cnt_csr%ISOPEN
2924 THEN
2925 CLOSE get_ib_lines_cnt_csr;
2926 END IF;
2927
2928 IF get_ib_lines_csr%ISOPEN
2929 THEN
2930 CLOSE get_ib_lines_csr;
2931 END IF;
2932
2933 -- close open cursors
2934 IF get_asset_name_csr%ISOPEN
2935 THEN
2936 CLOSE get_asset_name_csr;
2937 END IF;
2938
2939 IF get_split_trn_csr%ISOPEN
2940 THEN
2941 CLOSE get_split_trn_csr;
2942 END IF;
2943
2944 ROLLBACK TO do_split_asset;
2945 x_return_status := g_ret_sts_unexp_error;
2946 -- store the highest degree of error
2947 set_overall_status (p_return_status => x_return_status,
2948 px_overall_status => px_overall_status);
2949 -- set the transaction record
2950 set_transaction_rec (p_return_status => x_return_status,
2951 p_overall_status => px_overall_status,
2952 p_tmt_flag => 'TMT_SPLIT_ASSET_YN',
2953 p_tsu_code => 'ERROR',
2954 px_tcnv_rec => px_tcnv_rec
2955 );
2956
2957 IF (is_debug_exception_on)
2958 THEN
2959 okl_debug_pub.log_debug (g_level_exception,
2960 l_module_name,
2961 'EXCEPTION :'
2962 || 'G_EXCEPTION_UNEXPECTED_ERROR'
2963 );
2964 END IF;
2965 WHEN OTHERS
2966 THEN
2967 -- SECHAWLA 23-DEC-02 2484327 Closed cursors if open
2968 IF get_ib_lines_cnt_csr%ISOPEN
2969 THEN
2970 CLOSE get_ib_lines_cnt_csr;
2971 END IF;
2972
2973 IF get_ib_lines_csr%ISOPEN
2974 THEN
2975 CLOSE get_ib_lines_csr;
2976 END IF;
2977
2978 -- close open cursors
2979 IF get_asset_name_csr%ISOPEN
2980 THEN
2981 CLOSE get_asset_name_csr;
2982 END IF;
2983
2984 IF get_split_trn_csr%ISOPEN
2985 THEN
2986 CLOSE get_split_trn_csr;
2987 END IF;
2988
2989 ROLLBACK TO do_split_asset;
2990 x_return_status := g_ret_sts_unexp_error;
2991 -- Set the oracle error message
2992 okl_api.set_message (p_app_name => g_app_name_1,
2993 p_msg_name => g_unexpected_error,
2994 p_token1 => g_sqlcode_token,
2995 p_token1_value => SQLCODE,
2996 p_token2 => g_sqlerrm_token,
2997 p_token2_value => SQLERRM
2998 );
2999 -- store the highest degree of error
3000 set_overall_status (p_return_status => x_return_status,
3001 px_overall_status => px_overall_status);
3002 -- set the transaction record
3003 set_transaction_rec (p_return_status => x_return_status,
3004 p_overall_status => px_overall_status,
3005 p_tmt_flag => 'TMT_SPLIT_ASSET_YN',
3006 p_tsu_code => 'ERROR',
3007 px_tcnv_rec => px_tcnv_rec
3008 );
3009
3010 IF (is_debug_exception_on)
3011 THEN
3012 okl_debug_pub.log_debug (g_level_exception,
3013 l_module_name,
3014 'EXCEPTION :'
3015 || 'OTHERS, SQLCODE: '
3016 || SQLCODE
3017 || ' , SQLERRM : '
3018 || SQLERRM
3019 );
3020 END IF;
3021 END do_split_asset;
3022
3023 -- Start of comments
3024 --
3025 -- Procedure Name : split_asset
3026 -- Desciption : Checks if split asset needed ( if partial line qte)
3027 -- Calls the do_split_asset if split asset needed and
3028 -- sets the transaction properly
3029 -- Business Rules :
3030 -- Parameters :
3031 -- Version : 1.0
3032 -- History : RMUNJULU Bug # 2484327 16-DEC-02, changed logic to set
3033 -- split_tbl and call do_split_asset and updating TXL_quote_lines
3034 -- and setting success messages
3035 -- RMUNJULU 03-JAN-03 2683876 Changed msg token
3036 -- RMUNJULU 21-JAN-03 2760324 Removed additonal msg token
3037 -- RMUNJULU 2757312 MAJOR CHANGES to the whole procedure
3038 -- will now call do_split_trn which will create + update split
3039 -- trn and then call do_split_asset which will do split_asset
3040 --
3041 -- End of comments
3042 PROCEDURE split_asset (
3043 p_term_rec IN term_rec_type,
3044 p_sys_date IN DATE,
3045 p_klev_tbl IN klev_tbl_type,
3046 p_trn_already_set IN VARCHAR2,
3047 px_overall_status IN OUT NOCOPY VARCHAR2,
3048 px_tcnv_rec IN OUT NOCOPY tcnv_rec_type,
3049 x_klev_tbl OUT NOCOPY klev_tbl_type,
3050 x_return_status OUT NOCOPY VARCHAR2
3051 )
3052 IS
3053 l_split_tbl klev_tbl_type;
3054 i NUMBER;
3055 j NUMBER;
3056 l_return_status VARCHAR2 (1) := g_ret_sts_success;
3057 lp_tqlv_tbl okl_txl_quote_lines_pub.tqlv_tbl_type;
3058 lx_tqlv_tbl okl_txl_quote_lines_pub.tqlv_tbl_type;
3059 l_new_asset_name VARCHAR2 (2000);
3060 l_new_asset_quantity NUMBER;
3061 l_api_version CONSTANT NUMBER := g_api_version;
3062 l_msg_count NUMBER := g_miss_num;
3063 l_msg_data VARCHAR2 (2000);
3064 l_module_name VARCHAR2 (500)
3065 := g_module_name || 'split_asset';
3066 is_debug_exception_on BOOLEAN
3067 := okl_debug_pub.check_log_on (l_module_name, g_level_exception);
3068 is_debug_procedure_on BOOLEAN
3069 := okl_debug_pub.check_log_on (l_module_name, g_level_procedure);
3070 is_debug_statement_on BOOLEAN
3071 := okl_debug_pub.check_log_on (l_module_name, g_level_statement);
3072 BEGIN
3073 -- Start a savepoint to rollback to if error in this block
3074 SAVEPOINT split_asset;
3075
3076 IF (is_debug_procedure_on)
3077 THEN
3078 okl_debug_pub.log_debug (g_level_procedure,
3079 l_module_name,
3080 'Begin(+)'
3081 );
3082 END IF;
3083
3084 IF (is_debug_statement_on)
3085 THEN
3086 okl_debug_pub.log_debug (g_level_statement,
3087 l_module_name,
3088 'In param, p_sys_date: ' || p_sys_date
3089 );
3090 okl_debug_pub.log_debug (g_level_statement,
3091 l_module_name,
3092 'In param, p_trn_already_set: '
3093 || p_trn_already_set
3094 );
3095 okl_debug_pub.log_debug (g_level_statement,
3096 l_module_name,
3097 'In param, px_overall_status: '
3098 || px_overall_status
3099 );
3100 okl_debug_pub.log_debug
3101 (g_level_statement,
3102 l_module_name,
3103 'In param, px_tcnv_rec.tmt_split_asset_yn: '
3104 || px_tcnv_rec.tmt_split_asset_yn
3105 );
3106 okl_debug_pub.log_debug
3107 (g_level_statement,
3108 l_module_name,
3109 'In param, px_tcnv_rec.tmt_generic_flag1_yn: '
3110 || px_tcnv_rec.tmt_generic_flag1_yn
3111 );
3112
3113 IF p_klev_tbl.COUNT > 0
3114 THEN
3115 FOR i IN p_klev_tbl.FIRST .. p_klev_tbl.LAST
3116 LOOP
3117 IF (p_klev_tbl.EXISTS (i))
3118 THEN
3119 okl_debug_pub.log_debug (g_level_statement,
3120 l_module_name,
3121 'In param, p_klev_tbl('
3122 || i
3123 || ').p_kle_id: '
3124 || p_klev_tbl (i).p_kle_id
3125 );
3126 okl_debug_pub.log_debug (g_level_statement,
3127 l_module_name,
3128 'In param, p_klev_tbl('
3129 || i
3130 || ').p_asset_quantity: '
3131 || p_klev_tbl (i).p_asset_quantity
3132 );
3133 okl_debug_pub.log_debug (g_level_statement,
3134 l_module_name,
3135 'In param, p_klev_tbl('
3136 || i
3137 || ').p_asset_name: '
3138 || p_klev_tbl (i).p_asset_name
3139 );
3140 okl_debug_pub.log_debug (g_level_statement,
3141 l_module_name,
3142 'In param, p_klev_tbl('
3143 || i
3144 || ').p_quote_quantity: '
3145 || p_klev_tbl (i).p_quote_quantity
3146 );
3147 okl_debug_pub.log_debug (g_level_statement,
3148 l_module_name,
3149 'In param, p_klev_tbl('
3150 || i
3151 || ').p_tql_id: '
3152 || p_klev_tbl (i).p_tql_id
3153 );
3154 okl_debug_pub.log_debug (g_level_statement,
3155 l_module_name,
3156 'In param, p_klev_tbl('
3157 || i
3158 || ').p_split_kle_name: '
3159 || p_klev_tbl (i).p_split_kle_name
3160 );
3161 okl_debug_pub.log_debug (g_level_statement,
3162 l_module_name,
3163 'In param, p_klev_tbl('
3164 || i
3165 || ').p_split_kle_id: '
3166 || p_klev_tbl (i).p_split_kle_id
3167 );
3168 END IF;
3169 END LOOP;
3170 END IF;
3171 END IF;
3172
3173 -- if split asset step not done
3174 IF ( p_trn_already_set = g_yes
3175 AND ( NVL (px_tcnv_rec.tmt_split_asset_yn, '?') <> g_yes
3176 OR NVL (px_tcnv_rec.tmt_generic_flag1_yn, '?') <> g_yes
3177 )
3178 )
3179 OR (p_trn_already_set = g_no)
3180 THEN
3181 -- For each asset check if split asset needs to be done
3182 -- only if quote qty < asset qty set the klev_tbl to be passed to
3183 -- split asset
3184 IF (p_klev_tbl.COUNT > 0)
3185 THEN
3186 i := p_klev_tbl.FIRST;
3187 j := 1;
3188
3189 LOOP
3190 -- get the assets which needs to be splited into l_split_tbl
3191 -- RMUNJULU Bug # 2484327 16-DEC-02
3192 -- Removed the cursor access and setting of non_splited_tbl
3193 IF p_klev_tbl (i).p_quote_quantity <
3194 p_klev_tbl (i).p_asset_quantity
3195 THEN
3196 l_split_tbl (j).p_kle_id := p_klev_tbl (i).p_kle_id;
3197 l_split_tbl (j).p_asset_quantity :=
3198 p_klev_tbl (i).p_asset_quantity;
3199 l_split_tbl (j).p_asset_name := p_klev_tbl (i).p_asset_name;
3200 l_split_tbl (j).p_quote_quantity :=
3201 p_klev_tbl (i).p_quote_quantity;
3202 l_split_tbl (j).p_tql_id := p_klev_tbl (i).p_tql_id;
3203 l_split_tbl (j).p_split_kle_id :=
3204 p_klev_tbl (i).p_split_kle_id;
3205 -- RMUNJULU 2757312
3206 l_split_tbl (j).p_split_kle_name :=
3207 p_klev_tbl (i).p_split_kle_name;
3208 j := j + 1;
3209 END IF;
3210
3211 EXIT WHEN (i = p_klev_tbl.LAST);
3212 i := p_klev_tbl.NEXT (i);
3213 END LOOP;
3214 END IF;
3215
3216 -- If l_split_tbl is not empty then we do need to do split asset -- IE - Partial Line
3217 IF (l_split_tbl.COUNT > 0)
3218 THEN
3219 -- RMUNJULU 3018641 Step Message
3220 -- Step : Split Asset
3221 okl_api.set_message (p_app_name => g_app_name,
3222 p_msg_name => 'OKL_AM_STEP_SPL');
3223 -- Call the do_split_asset_trn with the l_split_tbl
3224 do_split_asset_trn (p_term_rec => p_term_rec,
3225 p_sys_date => p_sys_date,
3226 p_trn_already_set => p_trn_already_set,
3227 px_overall_status => px_overall_status,
3228 px_tcnv_rec => px_tcnv_rec,
3229 px_klev_tbl => l_split_tbl,
3230 x_return_status => l_return_status
3231 );
3232
3233 IF (is_debug_statement_on)
3234 THEN
3235 okl_debug_pub.log_debug
3236 (g_level_statement,
3237 l_module_name,
3238 'called do_split_asset_trn , return status: '
3239 || l_return_status
3240 );
3241 END IF;
3242
3243 IF l_return_status <> g_ret_sts_success
3244 THEN
3245 -- Split asset failed.
3246 okl_api.set_message (p_app_name => g_app_name,
3247 p_msg_name => 'OKL_AM_ERR_SPLIT_ASST');
3248 x_return_status := l_return_status;
3249 END IF;
3250
3251 IF l_return_status = g_ret_sts_success
3252 THEN
3253 -- Call the do_split_asset with the l_split_tbl
3254 do_split_asset (p_term_rec => p_term_rec,
3255 p_sys_date => p_sys_date,
3256 p_trn_already_set => p_trn_already_set,
3257 px_overall_status => px_overall_status,
3258 px_tcnv_rec => px_tcnv_rec,
3259 px_klev_tbl => l_split_tbl,
3260 x_return_status => l_return_status
3261 );
3262
3263 IF (is_debug_statement_on)
3264 THEN
3265 okl_debug_pub.log_debug
3266 (g_level_statement,
3267 l_module_name,
3268 'called do_split_asset , return status: '
3269 || l_return_status
3270 );
3271 END IF;
3272
3273 IF l_return_status <> g_ret_sts_success
3274 THEN
3275 -- Split asset failed.
3276 okl_api.set_message (p_app_name => g_app_name,
3277 p_msg_name => 'OKL_AM_ERR_SPLIT_ASST');
3278 x_return_status := l_return_status;
3279 END IF;
3280 END IF;
3281 ELSE
3282 --( no need for split asset since no partial line )
3283
3284 -- set the transaction record
3285 set_transaction_rec (p_return_status => l_return_status,
3286 p_overall_status => px_overall_status,
3287 p_tmt_flag => 'TMT_GENERIC_FLAG1_YN',
3288 p_tsu_code => 'WORKING',
3289 p_ret_val => NULL,
3290 px_tcnv_rec => px_tcnv_rec
3291 );
3292 -- set the transaction record
3293 set_transaction_rec (p_return_status => l_return_status,
3294 p_overall_status => px_overall_status,
3295 p_tmt_flag => 'TMT_SPLIT_ASSET_YN',
3296 p_tsu_code => 'WORKING',
3297 p_ret_val => NULL,
3298 px_tcnv_rec => px_tcnv_rec
3299 );
3300 END IF;
3301 END IF;
3302
3303 -- Set the return status
3304 x_return_status := l_return_status;
3305 -- Set the return klev_tbl
3306 x_klev_tbl := p_klev_tbl;
3307
3308 IF (is_debug_procedure_on)
3309 THEN
3310 okl_debug_pub.log_debug (g_level_procedure,
3311 l_module_name,
3312 'End(-)'
3313 );
3314 END IF;
3315 EXCEPTION
3316 WHEN okl_api.g_exception_error
3317 THEN
3318 ROLLBACK TO split_asset;
3319 x_return_status := g_ret_sts_error;
3320
3321 IF (is_debug_exception_on)
3322 THEN
3323 okl_debug_pub.log_debug (g_level_exception,
3324 l_module_name,
3325 'EXCEPTION :' || 'G_EXCEPTION_ERROR'
3326 );
3327 END IF;
3328 WHEN okl_api.g_exception_unexpected_error
3329 THEN
3330 ROLLBACK TO split_asset;
3331 x_return_status := g_ret_sts_unexp_error;
3332
3333 IF (is_debug_exception_on)
3334 THEN
3335 okl_debug_pub.log_debug (g_level_exception,
3336 l_module_name,
3337 'EXCEPTION :'
3338 || 'G_EXCEPTION_UNEXPECTED_ERROR'
3339 );
3340 END IF;
3341 WHEN OTHERS
3342 THEN
3343 ROLLBACK TO split_asset;
3344 x_return_status := g_ret_sts_unexp_error;
3345 -- Set the oracle error message
3346 okl_api.set_message (p_app_name => g_app_name_1,
3347 p_msg_name => g_unexpected_error,
3348 p_token1 => g_sqlcode_token,
3349 p_token1_value => SQLCODE,
3350 p_token2 => g_sqlerrm_token,
3351 p_token2_value => SQLERRM
3352 );
3353
3354 IF (is_debug_exception_on)
3355 THEN
3356 okl_debug_pub.log_debug (g_level_exception,
3357 l_module_name,
3358 'EXCEPTION :'
3359 || 'OTHERS, SQLCODE: '
3360 || SQLCODE
3361 || ' , SQLERRM : '
3362 || SQLERRM
3363 );
3364 END IF;
3365 END split_asset;
3366
3367 -- Start of comments
3368 --
3369 -- Procedure Name : close_streams
3370 -- Desciption : Checks if any active streams for the assets and closes
3371 -- Business Rules :
3372 -- Parameters :
3373 -- Version : 1.0
3374 -- History : RMUNJULU 28-MAR-03 2877278 Changed the cursor and code
3375 -- to get only CURRENT streams and HISTORIZE them
3376 --
3377 -- End of comments
3378 PROCEDURE close_streams (
3379 p_term_rec IN term_rec_type,
3380 p_sys_date IN DATE,
3381 p_klev_tbl IN klev_tbl_type,
3382 p_trn_already_set IN VARCHAR2,
3383 px_overall_status IN OUT NOCOPY VARCHAR2,
3384 px_tcnv_rec IN OUT NOCOPY tcnv_rec_type,
3385 x_return_status OUT NOCOPY VARCHAR2
3386 )
3387 IS
3388 -- Cursor to get the active streams of the asset
3389 -- RMUNJULU 28-MAR-03 2877278 Added conditions to pick only CURRENT
3390 -- streams.
3391 CURSOR k_streams_csr (
3392 p_kle_id IN NUMBER
3393 )
3394 IS
3395 SELECT stm.ID ID
3396 FROM okl_streams_v stm
3397 WHERE stm.kle_id = p_kle_id AND stm.say_code = 'CURR';
3398
3399 k_streams_rec k_streams_csr%ROWTYPE;
3400 l_return_status VARCHAR2 (1) := g_ret_sts_success;
3401 lp_stmv_tbl okl_streams_pub.stmv_tbl_type;
3402 lx_stmv_tbl okl_streams_pub.stmv_tbl_type;
3403 l_streams_found VARCHAR2 (1) := g_no;
3404 i NUMBER;
3405 j NUMBER;
3406 l_id NUMBER;
3407 l_api_version CONSTANT NUMBER := g_api_version;
3408 l_msg_count NUMBER := g_miss_num;
3409 l_msg_data VARCHAR2 (2000);
3410 l_module_name VARCHAR2 (500)
3411 := g_module_name || 'close_streams';
3412 is_debug_exception_on BOOLEAN
3413 := okl_debug_pub.check_log_on (l_module_name, g_level_exception);
3414 is_debug_procedure_on BOOLEAN
3415 := okl_debug_pub.check_log_on (l_module_name, g_level_procedure);
3416 is_debug_statement_on BOOLEAN
3417 := okl_debug_pub.check_log_on (l_module_name, g_level_statement);
3418 BEGIN
3419 -- Start a savepoint to rollback to if error in this block
3420 SAVEPOINT close_streams;
3421
3422 IF (is_debug_procedure_on)
3423 THEN
3424 okl_debug_pub.log_debug (g_level_procedure,
3425 l_module_name,
3426 'Begin(+)'
3427 );
3428 END IF;
3429
3430 IF (is_debug_statement_on)
3431 THEN
3432 okl_debug_pub.log_debug (g_level_statement,
3433 l_module_name,
3434 'In param, p_sys_date: ' || p_sys_date
3435 );
3436 okl_debug_pub.log_debug (g_level_statement,
3437 l_module_name,
3438 'In param, p_trn_already_set: '
3439 || p_trn_already_set
3440 );
3441 okl_debug_pub.log_debug (g_level_statement,
3442 l_module_name,
3443 'In param, px_overall_status: '
3444 || px_overall_status
3445 );
3446 okl_debug_pub.log_debug (g_level_statement,
3447 l_module_name,
3448 'In param, p_term_rec.p_contract_id: '
3449 || p_term_rec.p_contract_id
3450 );
3451 okl_debug_pub.log_debug
3452 (g_level_statement,
3453 l_module_name,
3454 'In param, px_tcnv_rec.tmt_streams_updated_yn: '
3455 || px_tcnv_rec.tmt_streams_updated_yn
3456 );
3457
3458 IF p_klev_tbl.COUNT > 0
3459 THEN
3460 FOR i IN p_klev_tbl.FIRST .. p_klev_tbl.LAST
3461 LOOP
3462 IF (p_klev_tbl.EXISTS (i))
3463 THEN
3464 okl_debug_pub.log_debug (g_level_statement,
3465 l_module_name,
3466 'In param, p_klev_tbl('
3467 || i
3468 || ').p_kle_id: '
3469 || p_klev_tbl (i).p_kle_id
3470 );
3471 okl_debug_pub.log_debug (g_level_statement,
3472 l_module_name,
3473 'In param, p_klev_tbl('
3474 || i
3475 || ').p_asset_quantity: '
3476 || p_klev_tbl (i).p_asset_quantity
3477 );
3478 okl_debug_pub.log_debug (g_level_statement,
3479 l_module_name,
3480 'In param, p_klev_tbl('
3481 || i
3482 || ').p_asset_name: '
3483 || p_klev_tbl (i).p_asset_name
3484 );
3485 okl_debug_pub.log_debug (g_level_statement,
3486 l_module_name,
3487 'In param, p_klev_tbl('
3488 || i
3489 || ').p_quote_quantity: '
3490 || p_klev_tbl (i).p_quote_quantity
3491 );
3492 okl_debug_pub.log_debug (g_level_statement,
3493 l_module_name,
3494 'In param, p_klev_tbl('
3495 || i
3496 || ').p_tql_id: '
3497 || p_klev_tbl (i).p_tql_id
3498 );
3499 okl_debug_pub.log_debug (g_level_statement,
3500 l_module_name,
3501 'In param, p_klev_tbl('
3502 || i
3503 || ').p_split_kle_name: '
3504 || p_klev_tbl (i).p_split_kle_name
3505 );
3506 okl_debug_pub.log_debug (g_level_statement,
3507 l_module_name,
3508 'In param, p_klev_tbl('
3509 || i
3510 || ').p_split_kle_id: '
3511 || p_klev_tbl (i).p_split_kle_id
3512 );
3513 END IF;
3514 END LOOP;
3515 END IF;
3516 END IF;
3517
3518 -- for each line check if streams exists
3519 IF (p_klev_tbl.COUNT > 0)
3520 THEN
3521 i := p_klev_tbl.FIRST;
3522
3523 LOOP
3524 -- check if streams exists
3525 OPEN k_streams_csr (p_klev_tbl (i).p_kle_id);
3526
3527 FETCH k_streams_csr
3528 INTO l_id;
3529
3530 IF k_streams_csr%FOUND
3531 THEN
3532 l_streams_found := g_yes;
3533 END IF;
3534
3535 CLOSE k_streams_csr;
3536
3537 EXIT WHEN (i = p_klev_tbl.LAST);
3538 i := p_klev_tbl.NEXT (i);
3539 END LOOP;
3540 END IF;
3541
3542 -- if close streams need to be done
3543 IF ( p_trn_already_set = g_yes
3544 AND NVL (px_tcnv_rec.tmt_streams_updated_yn, '?') <> g_yes
3545 )
3546 OR (p_trn_already_set = g_no)
3547 THEN
3548 -- if streams found then
3549 IF (l_streams_found = g_yes)
3550 THEN
3551 j := 1;
3552
3553 -- Loop thru the lines table
3554 IF (p_klev_tbl.COUNT > 0)
3555 THEN
3556 i := p_klev_tbl.FIRST;
3557
3558 LOOP
3559 -- for each line's streams set the tbl type for streams pub
3560 FOR k_streams_rec IN k_streams_csr (p_klev_tbl (i).p_kle_id)
3561 LOOP
3562 lp_stmv_tbl (j).khr_id := p_term_rec.p_contract_id;
3563 lp_stmv_tbl (j).active_yn := g_no;
3564 lp_stmv_tbl (j).ID := k_streams_rec.ID;
3565 lp_stmv_tbl (j).kle_id := p_klev_tbl (i).p_kle_id;
3566 -- RMUNJULU 28-MAR-03 2877278 Added code to set say_code to HIST
3567 lp_stmv_tbl (j).say_code := 'HIST';
3568 lp_stmv_tbl (j).date_history := SYSDATE;
3569 j := j + 1;
3570 END LOOP;
3571
3572 EXIT WHEN (i = p_klev_tbl.LAST);
3573 i := p_klev_tbl.NEXT (i);
3574 END LOOP;
3575 END IF;
3576
3577 IF (is_debug_statement_on)
3578 THEN
3579 okl_debug_pub.log_debug
3580 (g_level_statement,
3581 l_module_name,
3582 'calling OKL_STREAMS_PUB.update_streams'
3583 );
3584 END IF;
3585
3586 -- close streams
3587 okl_streams_pub.update_streams
3588 (p_api_version => l_api_version,
3589 p_init_msg_list => g_false,
3590 x_return_status => l_return_status,
3591 x_msg_count => l_msg_count,
3592 x_msg_data => l_msg_data,
3593 p_stmv_tbl => lp_stmv_tbl,
3594 x_stmv_tbl => lx_stmv_tbl
3595 );
3596
3597 IF (is_debug_statement_on)
3598 THEN
3599 okl_debug_pub.log_debug
3600 (g_level_statement,
3601 l_module_name,
3602 'called OKL_STREAMS_PUB.update_streams , return status: '
3603 || l_return_status
3604 );
3605 END IF;
3606
3607 IF l_return_status <> g_ret_sts_success
3608 THEN
3609 -- Streams table update failed.
3610 okl_api.set_message (p_app_name => g_app_name,
3611 p_msg_name => 'OKL_AM_ERR_UPD_STREAMS');
3612 END IF;
3613
3614 -- Raise exception to rollback to if error
3615 IF (l_return_status = g_ret_sts_unexp_error)
3616 THEN
3617 RAISE okl_api.g_exception_unexpected_error;
3618 ELSIF (l_return_status = g_ret_sts_error)
3619 THEN
3620 RAISE okl_api.g_exception_error;
3621 END IF;
3622
3623 -- store the highest degree of error
3624 set_overall_status (p_return_status => l_return_status,
3625 px_overall_status => px_overall_status);
3626 -- set the transaction record
3627 set_transaction_rec (p_return_status => l_return_status,
3628 p_overall_status => px_overall_status,
3629 p_tmt_flag => 'TMT_STREAMS_UPDATED_YN',
3630 p_tsu_code => 'WORKING',
3631 px_tcnv_rec => px_tcnv_rec
3632 );
3633 ELSE
3634 --( no streams found )
3635
3636 -- No future billable streams found.
3637 okl_api.set_message (p_app_name => g_app_name,
3638 p_msg_name => 'OKL_AM_NO_STREAMS');
3639 -- set the transaction record
3640 set_transaction_rec (p_return_status => l_return_status,
3641 p_overall_status => px_overall_status,
3642 p_tmt_flag => 'TMT_STREAMS_UPDATED_YN',
3643 p_tsu_code => 'WORKING',
3644 p_ret_val => NULL,
3645 px_tcnv_rec => px_tcnv_rec
3646 );
3647 END IF;
3648 END IF;
3649
3650 -- Set the return status
3651 x_return_status := l_return_status;
3652
3653 IF (is_debug_procedure_on)
3654 THEN
3655 okl_debug_pub.log_debug (g_level_procedure,
3656 l_module_name,
3657 'End(-)'
3658 );
3659 END IF;
3660 EXCEPTION
3661 WHEN okl_api.g_exception_error
3662 THEN
3663 -- Close any open cursors
3664 IF k_streams_csr%ISOPEN
3665 THEN
3666 CLOSE k_streams_csr;
3667 END IF;
3668
3669 ROLLBACK TO close_streams;
3670 x_return_status := g_ret_sts_error;
3671 -- store the highest degree of error
3672 set_overall_status (p_return_status => x_return_status,
3673 px_overall_status => px_overall_status);
3674 -- set the transaction record
3675 set_transaction_rec (p_return_status => x_return_status,
3676 p_overall_status => px_overall_status,
3677 p_tmt_flag => 'TMT_STREAMS_UPDATED_YN',
3678 p_tsu_code => 'ERROR',
3679 px_tcnv_rec => px_tcnv_rec
3680 );
3681
3682 IF (is_debug_exception_on)
3683 THEN
3684 okl_debug_pub.log_debug (g_level_exception,
3685 l_module_name,
3686 'EXCEPTION :' || 'G_EXCEPTION_ERROR'
3687 );
3688 END IF;
3689 WHEN okl_api.g_exception_unexpected_error
3690 THEN
3691 -- Close any open cursors
3692 IF k_streams_csr%ISOPEN
3693 THEN
3694 CLOSE k_streams_csr;
3695 END IF;
3696
3697 ROLLBACK TO close_streams;
3698 x_return_status := g_ret_sts_unexp_error;
3699 -- store the highest degree of error
3700 set_overall_status (p_return_status => x_return_status,
3701 px_overall_status => px_overall_status);
3702 -- set the transaction record
3703 set_transaction_rec (p_return_status => x_return_status,
3704 p_overall_status => px_overall_status,
3705 p_tmt_flag => 'TMT_STREAMS_UPDATED_YN',
3706 p_tsu_code => 'ERROR',
3707 px_tcnv_rec => px_tcnv_rec
3708 );
3709
3710 IF (is_debug_exception_on)
3711 THEN
3712 okl_debug_pub.log_debug (g_level_exception,
3713 l_module_name,
3714 'EXCEPTION :'
3715 || 'G_EXCEPTION_UNEXPECTED_ERROR'
3716 );
3717 END IF;
3718 WHEN OTHERS
3719 THEN
3720 -- Close any open cursors
3721 IF k_streams_csr%ISOPEN
3722 THEN
3723 CLOSE k_streams_csr;
3724 END IF;
3725
3726 ROLLBACK TO close_streams;
3727 x_return_status := g_ret_sts_unexp_error;
3728 -- store the highest degree of error
3729 set_overall_status (p_return_status => x_return_status,
3730 px_overall_status => px_overall_status);
3731 -- set the transaction record
3732 set_transaction_rec (p_return_status => x_return_status,
3733 p_overall_status => px_overall_status,
3734 p_tmt_flag => 'TMT_STREAMS_UPDATED_YN',
3735 p_tsu_code => 'ERROR',
3736 px_tcnv_rec => px_tcnv_rec
3737 );
3738 -- Set the oracle error message
3739 okl_api.set_message (p_app_name => g_app_name_1,
3740 p_msg_name => g_unexpected_error,
3741 p_token1 => g_sqlcode_token,
3742 p_token1_value => SQLCODE,
3743 p_token2 => g_sqlerrm_token,
3744 p_token2_value => SQLERRM
3745 );
3746
3747 IF (is_debug_exception_on)
3748 THEN
3749 okl_debug_pub.log_debug (g_level_exception,
3750 l_module_name,
3751 'EXCEPTION :'
3752 || 'OTHERS, SQLCODE: '
3753 || SQLCODE
3754 || ' , SQLERRM : '
3755 || SQLERRM
3756 );
3757 END IF;
3758 END close_streams;
3759
3760 -- Start of comments
3761 --
3762 -- Procedure Name : accounting_entries
3763 -- Desciption : Does the accounting entries for the assets
3764 -- Business Rules :
3765 -- Parameters :
3766 -- Version : 1.0
3767 -- History : RMUNJULU 23-DEC-02 2726739 Added code for Multi-Currency settings
3768 -- : RMUNJULU Bug # 3023206 27-JUN-03 Increment the line number before the exit
3769 -- to avoid duplicate line numbers when creating accnting transaction lines
3770 -- : RMUNJULU Bug # 2902876 23-JUL-03 Added code to pass valid GL date to GET_TEMPLATE_INFO
3771 -- : RMUNJULU 3138794 Added code to pass kle_id to Accounting Engine
3772 -- : RMUNJULU 28-APR-04 3596626 Added code to set lp_acc_gen_primary_key_tbl
3773 --
3774 -- : SMODUGA 3061772 Added call to process_discount_subsidy
3775 -- : rmunjulu EDAT Added code to pass quote accpt date as accounting date
3776 -- also passing the contract_id, quote_id, quote_accept_date and line_id to accounting engine
3777 -- : rmunjulu EDAT 29-Dec-04 did to_char to convert to right format
3778 -- : akrangan Bug 5514059 - During termination, do accounting for asset, fees and service
3779 -- : akrangan SLA Single Accounting Engine Call Uptake
3780 -- End of comments
3781 PROCEDURE accounting_entries (
3782 p_term_rec IN term_rec_type,
3783 p_sys_date IN DATE,
3784 p_klev_tbl IN klev_tbl_type,
3785 p_trn_already_set IN VARCHAR2,
3786 px_overall_status IN OUT NOCOPY VARCHAR2,
3787 px_tcnv_rec IN OUT NOCOPY tcnv_rec_type,
3788 x_return_status OUT NOCOPY VARCHAR2
3789 )
3790 IS
3791 -- Cursor to get the product of the contract
3792 CURSOR prod_id_csr (
3793 p_khr_id IN NUMBER
3794 )
3795 IS
3796 SELECT khr.pdt_id pdt_id,
3797 CHR.scs_code -- rmunjulu 4622198
3798 ,
3799 CHR.org_id --akrangan added for sla ae uptake
3800 FROM okl_k_headers_v khr,
3801 okc_k_headers_b CHR -- rmunjulu 4622198
3802 WHERE khr.ID = p_khr_id AND khr.ID = CHR.ID; -- rmunjulu 4622198
3803
3804 -- Get the product type
3805 CURSOR l_product_type_csr (
3806 p_pdt_id IN NUMBER
3807 )
3808 IS
3809 SELECT prd.description description
3810 FROM okl_products_v prd
3811 WHERE prd.ID = p_pdt_id;
3812
3813 l_return_status VARCHAR2 (1) := g_ret_sts_success;
3814 l_pdt_id NUMBER := 0;
3815 l_try_id NUMBER;
3816 lp_tmpl_identify_rec okl_account_dist_pub.tmpl_identify_rec_type;
3817 lp_dist_info_rec okl_account_dist_pub.dist_info_rec_type;
3818 lp_ctxt_val_tbl okl_account_dist_pub.ctxt_val_tbl_type;
3819 lp_acc_gen_primary_key_tbl okl_account_dist_pub.acc_gen_primary_key;
3820 lx_template_tbl okl_account_dist_pub.avlv_tbl_type;
3821 lx_amount_tbl okl_account_dist_pub.amount_tbl_type;
3822 lx_tcnv_tbl okl_trx_contracts_pub.tcnv_tbl_type;
3823 lx_tclv_tbl okl_trx_contracts_pub.tclv_tbl_type;
3824 l_catchup_rec okl_generate_accruals_pub.accrual_rec_type;
3825 l_lprv_rec okl_rev_loss_prov_pub.lprv_rec_type;
3826 l_trans_meaning VARCHAR2 (200);
3827 l_module_name VARCHAR2 (500)
3828 := g_module_name || 'accounting_entries';
3829 is_debug_exception_on BOOLEAN
3830 := okl_debug_pub.check_log_on (l_module_name, g_level_exception);
3831 is_debug_procedure_on BOOLEAN
3832 := okl_debug_pub.check_log_on (l_module_name, g_level_procedure);
3833 is_debug_statement_on BOOLEAN
3834 := okl_debug_pub.check_log_on (l_module_name, g_level_statement);
3835 lp_tclv_rec okl_trx_contracts_pub.tclv_rec_type;
3836 lx_tclv_rec okl_trx_contracts_pub.tclv_rec_type;
3837 li_tclv_rec okl_trx_contracts_pub.tclv_rec_type;
3838 i NUMBER;
3839 l_total_amount NUMBER := 0;
3840 lip_tmpl_identify_rec okl_account_dist_pub.tmpl_identify_rec_type;
3841 lix_template_tbl okl_account_dist_pub.avlv_tbl_type;
3842 lip_tcnv_rec tcnv_rec_type;
3843 lix_tcnv_rec tcnv_rec_type;
3844 l_product_type VARCHAR2 (2000);
3845 l_line_number NUMBER := 1;
3846 j NUMBER;
3847 l_api_version CONSTANT NUMBER := g_api_version;
3848 l_msg_count NUMBER := g_miss_num;
3849 l_msg_data VARCHAR2 (2000);
3850 -- RMUNJULU 23-DEC-02 2726739 Added variables
3851 l_functional_currency_code VARCHAR2 (15);
3852 l_contract_currency_code VARCHAR2 (15);
3853 l_currency_conversion_type VARCHAR2 (30);
3854 l_currency_conversion_rate NUMBER;
3855 l_currency_conversion_date DATE;
3856 l_converted_amount NUMBER;
3857 -- Since we do not use the amount or converted amount
3858 -- set a hardcoded value for the amount (and pass to to
3859 -- OKL_ACCOUNTING_UTIL.convert_to_functional_currency and get back
3860 -- conversion values )
3861 l_hard_coded_amount NUMBER := 100;
3862 -- Bug 2902876
3863 l_valid_gl_date DATE;
3864 -- rmunjulu EDAT
3865 l_quote_accpt_date DATE;
3866 l_quote_eff_date DATE;
3867 -- rmunjulu 4622198
3868 l_scs_code okc_k_headers_b.scs_code%TYPE;
3869 l_fact_synd_code fnd_lookups.lookup_code%TYPE;
3870 l_inv_acct_code okc_rules_b.rule_information1%TYPE;
3871
3872 --akrangan Bug 5514059 start
3873 -- Used to get Assets selected for termination and
3874 -- Fee and Sold Service lines associated to the assets
3875 CURSOR k_asst_fee_srvc_lns_csr (
3876 p_chr_id IN okc_k_headers_b.ID%TYPE,
3877 p_qte_id IN okc_k_lines_b.ID%TYPE
3878 )
3879 IS
3880 SELECT cle.ID cle_id
3881 FROM okc_k_lines_b cle,
3882 okl_txl_quote_lines_b tql
3883 WHERE tql.qte_id = p_qte_id
3884 AND tql.qlt_code = 'AMCFIA'
3885 AND tql.kle_id = cle.ID
3886 UNION
3887 SELECT DISTINCT hdrcle.ID cle_id
3888 FROM okc_k_lines_b cle,
3889 okc_k_lines_b hdrcle,
3890 okc_k_items cim,
3891 okl_txl_quote_lines_b tql,
3892 okc_k_headers_b CHR,
3893 okc_line_styles_b lse
3894 WHERE hdrcle.chr_id = p_chr_id
3895 AND cle.cle_id = hdrcle.ID
3896 AND cim.dnz_chr_id = cle.dnz_chr_id
3897 AND cim.jtot_object1_code = 'OKX_COVASST'
3898 AND cim.cle_id = cle.ID
3899 AND cim.object1_id1 = tql.kle_id
3900 AND tql.qte_id = p_qte_id
3901 AND tql.qlt_code = 'AMCFIA'
3902 AND hdrcle.lse_id = lse.ID
3903 AND lse.lty_code IN ('FEE', 'SOLD_SERVICE')
3904 AND hdrcle.chr_id = CHR.ID
3905 AND hdrcle.sts_code = CHR.sts_code;
3906
3907 --akrangan Bug 5514059 end
3908 --akrangan sla single accounting call to ae uptake starts
3909 l_org_id NUMBER (15);
3910 --txl contracts specific tbl types
3911 l_tclv_tbl okl_trx_contracts_pub.tclv_tbl_type;
3912 --ae new table types declaration
3913 l_tmpl_identify_tbl okl_account_dist_pvt.tmpl_identify_tbl_type;
3914 l_dist_info_tbl okl_account_dist_pvt.dist_info_tbl_type;
3915 l_ctxt_tbl okl_account_dist_pvt.ctxt_tbl_type;
3916 l_template_out_tbl okl_account_dist_pvt.avlv_out_tbl_type;
3917 l_amount_out_tbl okl_account_dist_pvt.amount_out_tbl_type;
3918 l_acc_gen_tbl okl_account_dist_pvt.acc_gen_tbl_type;
3919 l_tcn_id NUMBER;
3920
3921 --hdr dff fields cursor
3922 --this cursor is to populate the
3923 -- desc flex fields columns in okl_trx_contracts
3924 CURSOR trx_contracts_dff_csr (
3925 p_khr_id IN NUMBER
3926 )
3927 IS
3928 SELECT attribute_category,
3929 attribute1,
3930 attribute2,
3931 attribute3,
3932 attribute4,
3933 attribute5,
3934 attribute6,
3935 attribute7,
3936 attribute8,
3937 attribute9,
3938 attribute10,
3939 attribute11,
3940 attribute12,
3941 attribute13,
3942 attribute14,
3943 attribute15
3944 FROM okl_k_headers okl
3945 WHERE okl.ID = p_khr_id;
3946
3947 --line dff fields cursor
3948 --this cursor is to populate the
3949 -- desc flex fields columns in okl_txl_xontract_lines_b
3950 CURSOR txl_contracts_dff_csr (
3951 p_kle_id IN NUMBER
3952 )
3953 IS
3954 SELECT attribute_category,
3955 attribute1,
3956 attribute2,
3957 attribute3,
3958 attribute4,
3959 attribute5,
3960 attribute6,
3961 attribute7,
3962 attribute8,
3963 attribute9,
3964 attribute10,
3965 attribute11,
3966 attribute12,
3967 attribute13,
3968 attribute14,
3969 attribute15
3970 FROM okl_k_lines okl
3971 WHERE okl.ID = p_kle_id;
3972
3973 --record for storing okl_k_lines dffs and linked assets cle_id
3974 TYPE dff_rec_type IS RECORD (
3975 attribute_category okl_k_lines.attribute_category%TYPE,
3976 attribute1 okl_k_lines.attribute1%TYPE,
3977 attribute2 okl_k_lines.attribute2%TYPE,
3978 attribute3 okl_k_lines.attribute3%TYPE,
3979 attribute4 okl_k_lines.attribute4%TYPE,
3980 attribute5 okl_k_lines.attribute5%TYPE,
3981 attribute6 okl_k_lines.attribute6%TYPE,
3982 attribute7 okl_k_lines.attribute7%TYPE,
3983 attribute8 okl_k_lines.attribute8%TYPE,
3984 attribute9 okl_k_lines.attribute9%TYPE,
3985 attribute10 okl_k_lines.attribute10%TYPE,
3986 attribute11 okl_k_lines.attribute11%TYPE,
3987 attribute12 okl_k_lines.attribute12%TYPE,
3988 attribute13 okl_k_lines.attribute13%TYPE,
3989 attribute14 okl_k_lines.attribute14%TYPE,
3990 attribute15 okl_k_lines.attribute15%TYPE
3991 );
3992
3993 txl_contracts_dff_rec dff_rec_type;
3994
3995 --product name and tax owner
3996 CURSOR product_name_csr (
3997 p_pdt_id IN NUMBER
3998 )
3999 IS
4000 SELECT NAME,
4001 tax_owner
4002 FROM okl_product_parameters_v
4003 WHERE ID = p_pdt_id;
4004
4005 l_currency_code okl_trx_contracts.currency_code%TYPE;
4006 --loop variables
4007 k NUMBER;
4008 l NUMBER;
4009 m NUMBER;
4010 --akrangan sla single accounting call to ae uptake ends
4011 BEGIN
4012
4013
4014 IF (is_debug_procedure_on)
4015 THEN
4016 okl_debug_pub.log_debug (g_level_procedure,
4017 l_module_name,
4018 'Begin(+)'
4019 );
4020 END IF;
4021
4022 IF (is_debug_statement_on)
4023 THEN
4024 okl_debug_pub.log_debug (g_level_statement,
4025 l_module_name,
4026 'In param, p_sys_date: ' || p_sys_date
4027 );
4028 okl_debug_pub.log_debug (g_level_statement,
4029 l_module_name,
4030 'In param, p_trn_already_set: '
4031 || p_trn_already_set
4032 );
4033 okl_debug_pub.log_debug (g_level_statement,
4034 l_module_name,
4035 'In param, px_overall_status: '
4036 || px_overall_status
4037 );
4038 okl_debug_pub.log_debug (g_level_statement,
4039 l_module_name,
4040 'In param, p_term_rec.p_quote_id: '
4041 || p_term_rec.p_quote_id
4042 );
4043 okl_debug_pub.log_debug (g_level_statement,
4044 l_module_name,
4045 'In param, p_term_rec.p_contract_id: '
4046 || p_term_rec.p_contract_id
4047 );
4048 okl_debug_pub.log_debug
4049 (g_level_statement,
4050 l_module_name,
4051 'In param, p_term_rec.p_contract_number: '
4052 || p_term_rec.p_contract_number
4053 );
4054 okl_debug_pub.log_debug (g_level_statement,
4055 l_module_name,
4056 'In param, px_tcnv_rec.try_id: '
4057 || px_tcnv_rec.try_id
4058 );
4059 okl_debug_pub.log_debug
4060 (g_level_statement,
4061 l_module_name,
4062 'In param, px_tcnv_rec.tmt_accounting_entries_yn: '
4063 || px_tcnv_rec.tmt_accounting_entries_yn
4064 );
4065 okl_debug_pub.log_debug (g_level_statement,
4066 l_module_name,
4067 'In param, px_tcnv_rec.id: '
4068 || px_tcnv_rec.ID
4069 );
4070 END IF;
4071
4072 -- Logic
4073
4074 --Check the product id
4075 --If product_id NULL Then
4076 -- Error and Exit
4077 --End if
4078
4079 --Get Templates for product ( get sty_id)
4080 --If no templates found Then
4081 -- Error and Exit
4082 --End If
4083
4084 --Loop thru templates
4085 -- Loop thru lines
4086 -- Create TXL Line ( with kle_id)
4087 -- Do Accnt entries (get back amt)
4088 -- Update TXL Line (for amt)
4089 -- Increment total amt
4090 -- Increment line number
4091 -- End Loop
4092 --End Loop
4093 --Update TRX header with total amt
4094
4095 -- Start savepoint for this block
4096 SAVEPOINT accounting_entries;
4097
4098 -- get the product id
4099 OPEN prod_id_csr (p_term_rec.p_contract_id);
4100
4101 FETCH prod_id_csr
4102 INTO l_pdt_id,
4103 l_scs_code,
4104 l_org_id; -- rmunjulu 4622198
4105
4106 CLOSE prod_id_csr;
4107
4108 -- CHECK PRODUCT ID
4109
4110 -- raise error if no pdt_id
4111 IF l_pdt_id IS NULL OR l_pdt_id = 0
4112 THEN
4113 -- Error: Unable to create accounting entries because of a missing
4114 -- Product Type for the contract CONTRACT_NUMBER.
4115 okl_api.set_message (p_app_name => g_app_name,
4116 p_msg_name => 'OKL_AM_PRODUCT_ID_ERROR',
4117 p_token1 => 'CONTRACT_NUMBER',
4118 p_token1_value => p_term_rec.p_contract_number
4119 );
4120 RAISE okl_api.g_exception_error;
4121 END IF;
4122
4123 -- get the product type
4124 OPEN l_product_type_csr (l_pdt_id);
4125
4126 FETCH l_product_type_csr
4127 INTO l_product_type;
4128
4129 CLOSE l_product_type_csr;
4130
4131 -- If accounting entries needed
4132 IF ( p_trn_already_set = g_yes
4133 AND NVL (px_tcnv_rec.tmt_accounting_entries_yn, '?') <> g_yes
4134 )
4135 OR (p_trn_already_set = g_no)
4136 THEN
4137 -- RMUNJULU 3018641 Step Message
4138 -- Step : Accounting Entries
4139 okl_api.set_message (p_app_name => g_app_name,
4140 p_msg_name => 'OKL_AM_STEP_ACT');
4141
4142 -- rmunjulu +++++++++ Effective Dated Termination -- start ++++++++++++++++
4143
4144 -- rmunjulu EDAT
4145 -- If quote exists then accnting date is quote accept date else sysdate
4146 IF NVL (okl_am_lease_loan_trmnt_pvt.g_quote_exists, 'N') = 'Y'
4147 THEN
4148 l_quote_accpt_date :=
4149 okl_am_lease_loan_trmnt_pvt.g_quote_accept_date;
4150 l_quote_eff_date :=
4151 okl_am_lease_loan_trmnt_pvt.g_quote_eff_from_date;
4152 ELSE
4153 l_quote_accpt_date := p_sys_date;
4154 l_quote_eff_date := p_sys_date;
4155 END IF;
4156
4157 -- rmunjulu EDAT
4158 -- set the additional parameters with contract_id, quote_id and transaction_date
4159 -- to be passed to formula engine
4160 lp_ctxt_val_tbl (1).NAME := 'contract_id';
4161 lp_ctxt_val_tbl (1).VALUE := p_term_rec.p_contract_id;
4162 lp_ctxt_val_tbl (2).NAME := 'quote_id';
4163 lp_ctxt_val_tbl (2).VALUE := p_term_rec.p_quote_id;
4164 lp_ctxt_val_tbl (3).NAME := 'transaction_date';
4165 lp_ctxt_val_tbl (3).VALUE :=
4166 TO_CHAR (l_quote_accpt_date, 'MM/DD/YYYY');
4167 -- rmunjulu EDAT 29-Dec-04 did to_char to convert to right format
4168 -- rmunjulu +++++++++ Effective Dated Termination -- end ++++++++++++++++
4169
4170 -- GET TEMPLATES
4171
4172 -- Get the meaning of lookup
4173 l_trans_meaning :=
4174 okl_am_util_pvt.get_lookup_meaning
4175 (p_lookup_type => 'OKL_ACCOUNTING_EVENT_TYPE',
4176 p_lookup_code => 'TERMINATION',
4177 p_validate_yn => 'Y'
4178 );
4179 -- Set the tmpl_identify_rec in parameter to get
4180 -- accounting templates for the product
4181 lip_tmpl_identify_rec.product_id := l_pdt_id;
4182 lip_tmpl_identify_rec.transaction_type_id := px_tcnv_rec.try_id;
4183 lip_tmpl_identify_rec.memo_yn := g_no;
4184 lip_tmpl_identify_rec.prior_year_yn := g_no;
4185 -- Bug 2902876 Added to get the valid GL date
4186 l_valid_gl_date :=
4187 okl_accounting_util.get_valid_gl_date
4188 (p_gl_date => l_quote_accpt_date);
4189 -- rmunjulu EDAT
4190
4191 IF (is_debug_statement_on)
4192 THEN
4193 okl_debug_pub.log_debug
4194 (g_level_statement,
4195 l_module_name,
4196 'calling okl_securitization_pvt.check_khr_ia_associated'
4197 );
4198 END IF;
4199
4200 -- rmunjulu 4622198 SPECIAL_ACCNT Get special accounting details
4201 okl_securitization_pvt.check_khr_ia_associated
4202 (p_api_version => l_api_version,
4203 p_init_msg_list => okl_api.g_false,
4204 x_return_status => l_return_status,
4205 x_msg_count => l_msg_count,
4206 x_msg_data => l_msg_data,
4207 p_khr_id => p_term_rec.p_contract_id,
4208 p_scs_code => l_scs_code,
4209 p_trx_date => l_quote_accpt_date,
4210 x_fact_synd_code => l_fact_synd_code,
4211 x_inv_acct_code => l_inv_acct_code
4212 );
4213
4214 IF (is_debug_statement_on)
4215 THEN
4216 okl_debug_pub.log_debug
4217 (g_level_statement,
4218 l_module_name,
4219 'called okl_securitization_pvt.check_khr_ia_associated , return status: '
4220 || l_return_status
4221 );
4222 END IF;
4223
4224 IF (l_return_status = g_ret_sts_unexp_error)
4225 THEN
4226 RAISE okl_api.g_exception_unexpected_error;
4227 ELSIF (l_return_status = g_ret_sts_error)
4228 THEN
4229 RAISE okl_api.g_exception_error;
4230 END IF;
4231
4232 -- rmunjulu 4622198 SPECIAL_ACCNT set the special accounting parameters
4233 lip_tmpl_identify_rec.factoring_synd_flag := l_fact_synd_code;
4234 lip_tmpl_identify_rec.investor_code := l_inv_acct_code;
4235
4236 IF (is_debug_statement_on)
4237 THEN
4238 okl_debug_pub.log_debug
4239 (g_level_statement,
4240 l_module_name,
4241 'calling okl_account_dist_pub.get_template_info'
4242 );
4243 END IF;
4244
4245 -- Get the accounting templates
4246 okl_account_dist_pub.get_template_info
4247 (p_api_version => l_api_version,
4248 p_init_msg_list => g_false,
4249 x_return_status => l_return_status,
4250 x_msg_count => l_msg_count,
4251 x_msg_data => l_msg_data,
4252 p_tmpl_identify_rec => lip_tmpl_identify_rec,
4253 x_template_tbl => lix_template_tbl,
4254 p_validity_date => l_valid_gl_date
4255 ); -- Bug 2902876 Added to pass valid GL date
4256
4257 IF (is_debug_statement_on)
4258 THEN
4259 okl_debug_pub.log_debug
4260 (g_level_statement,
4261 l_module_name,
4262 'called okl_account_dist_pub.get_template_info , return status: '
4263 || l_return_status
4264 );
4265 END IF;
4266
4267 IF l_return_status <> g_ret_sts_success
4268 THEN
4269 -- No accounting templates found matching the transaction type
4270 -- TRX_TYPE and product PRODUCT.
4271 okl_api.set_message (p_app_name => g_app_name,
4272 p_msg_name => 'OKL_AM_NO_ACC_TEMPLATES',
4273 p_token1 => 'TRX_TYPE',
4274 p_token1_value => l_trans_meaning,
4275 p_token2 => 'PRODUCT',
4276 p_token2_value => l_product_type
4277 );
4278 END IF;
4279
4280 IF (l_return_status = g_ret_sts_unexp_error)
4281 THEN
4282 RAISE okl_api.g_exception_unexpected_error;
4283 ELSIF (l_return_status = g_ret_sts_error)
4284 THEN
4285 RAISE okl_api.g_exception_error;
4286 END IF;
4287
4288 -- If no templates present
4289 IF lix_template_tbl.COUNT = 0
4290 THEN
4291 -- No accounting templates found matching the transaction type
4292 -- TRX_TYPE and product PRODUCT.
4293 okl_api.set_message (p_app_name => g_app_name,
4294 p_msg_name => 'OKL_AM_NO_ACC_TEMPLATES',
4295 p_token1 => 'TRX_TYPE',
4296 p_token1_value => l_trans_meaning,
4297 p_token2 => 'PRODUCT',
4298 p_token2_value => l_product_type
4299 );
4300 RAISE okl_api.g_exception_error;
4301 END IF;
4302
4303 -- ******************
4304 -- CURRENCY CONVERSION OPERATIONS
4305 -- ******************
4306 l_currency_code :=
4307 okl_am_util_pvt.get_chr_currency (p_term_rec.p_contract_id);
4308 l_functional_currency_code :=
4309 okl_am_util_pvt.get_functional_currency
4310 ();
4311
4312 --akrangan Bug 6147049 code fix start
4313 --call functional currency conversion only
4314 --if functional currency and contract currency are not same
4315 IF l_functional_currency_code IS NOT NULL
4316 AND l_functional_currency_code <> l_currency_code
4317 THEN
4318 --akrangan Bug 6147049 code fix end
4319 -- Get the currency conversion details from ACCOUNTING_Util
4320 IF (is_debug_statement_on)
4321 THEN
4322 okl_debug_pub.log_debug
4323 (g_level_statement,
4324 l_module_name,
4325 'calling okl_accounting_util.convert_to_functional_currency'
4326 );
4327 END IF;
4328
4329 okl_accounting_util.convert_to_functional_currency
4330 (p_khr_id => p_term_rec.p_contract_id,
4331 p_to_currency => l_functional_currency_code,
4332 p_transaction_date => l_quote_accpt_date,
4333 -- rmunjulu EDAT
4334 p_amount => l_hard_coded_amount,
4335 x_return_status => l_return_status,
4336 x_contract_currency => l_contract_currency_code,
4337 x_currency_conversion_type => l_currency_conversion_type,
4338 x_currency_conversion_rate => l_currency_conversion_rate,
4339 x_currency_conversion_date => l_currency_conversion_date,
4340 x_converted_amount => l_converted_amount
4341 );
4342
4343 IF (is_debug_statement_on)
4344 THEN
4345 okl_debug_pub.log_debug
4346 (g_level_statement,
4347 l_module_name,
4348 'called okl_accounting_util.convert_to_functional_currency , return status: '
4349 || l_return_status
4350 );
4351 okl_debug_pub.log_debug (g_level_statement,
4352 l_module_name,
4353 'l_contract_currency_code: '
4354 || l_contract_currency_code
4355 );
4356 okl_debug_pub.log_debug (g_level_statement,
4357 l_module_name,
4358 'l_currency_conversion_type: '
4359 || l_currency_conversion_type
4360 );
4361 okl_debug_pub.log_debug (g_level_statement,
4362 l_module_name,
4363 'l_currency_conversion_rate: '
4364 || l_currency_conversion_rate
4365 );
4366 okl_debug_pub.log_debug (g_level_statement,
4367 l_module_name,
4368 'l_currency_conversion_date: '
4369 || l_currency_conversion_date
4370 );
4371 okl_debug_pub.log_debug (g_level_statement,
4372 l_module_name,
4373 'l_converted_amount: '
4374 || l_converted_amount
4375 );
4376 END IF;
4377
4378 -- If error from OKL_ACCOUNTING_UTIL
4379 IF l_return_status <> okl_api.g_ret_sts_success
4380 THEN
4381 -- Error occurred when creating accounting entries for
4382 -- transaction TRX_TYPE.
4383 okl_api.set_message (p_app_name => g_app_name,
4384 p_msg_name => 'OKL_AM_ERR_ACC_ENT',
4385 p_token1 => 'TRX_TYPE',
4386 p_token1_value => l_trans_meaning
4387 );
4388 END IF;
4389
4390 -- Raise exception to rollback to savepoint for this block
4391 IF (l_return_status = okl_api.g_ret_sts_unexp_error)
4392 THEN
4393 RAISE okl_api.g_exception_unexpected_error;
4394 ELSIF (l_return_status = okl_api.g_ret_sts_error)
4395 THEN
4396 RAISE okl_api.g_exception_error;
4397 END IF;
4398 --akrangan Bug 6147049 code fix start
4399 END IF;
4400
4401 --akrangan Bug 6147049 code fix end
4402 -- *****************************
4403 -- CREATE TXL_CNTRCT LINES
4404 -- ****************************
4405 -- currency operations related variables assigned
4406 --Start fix for bug 7204083
4407 l_currency_code := NVL(l_contract_currency_code, l_currency_code);
4408 --End fix for bug 7204083
4409 j := 1;
4410 --looping thru the templates to set line records and template identify tbl
4411 i := lix_template_tbl.FIRST;
4412 -- at this point we know that there are some templates
4413
4414 LOOP
4415 -- Loop thru templates
4416 FOR k_asst_fee_srvc_lns_rec IN
4417 k_asst_fee_srvc_lns_csr (p_term_rec.p_contract_id,
4418 p_term_rec.p_quote_id)
4419 LOOP
4420 -- set the TXL_CNTRCT Line details for template
4421 l_tclv_tbl (j).line_number := l_line_number;
4422 l_tclv_tbl (j).khr_id := p_term_rec.p_contract_id;
4423 l_tclv_tbl (j).tcn_id := px_tcnv_rec.ID;
4424 l_tclv_tbl (j).sty_id := lix_template_tbl (i).sty_id;
4425 l_tclv_tbl (j).tcl_type := 'ALT';
4426 l_tclv_tbl (j).currency_code := l_currency_code;
4427 l_tclv_tbl (j).kle_id := k_asst_fee_srvc_lns_rec.cle_id;
4428 l_tclv_tbl (j).org_id := l_org_id;
4429
4430 FOR txl_contracts_dff_rec IN
4431 txl_contracts_dff_csr (k_asst_fee_srvc_lns_rec.cle_id)
4432 LOOP
4433 --set dffs
4434 l_tclv_tbl (j).attribute_category :=
4435 txl_contracts_dff_rec.attribute_category;
4436 l_tclv_tbl (j).attribute1 :=
4437 txl_contracts_dff_rec.attribute1;
4438 l_tclv_tbl (j).attribute2 :=
4439 txl_contracts_dff_rec.attribute2;
4440 l_tclv_tbl (j).attribute3 :=
4441 txl_contracts_dff_rec.attribute3;
4442 l_tclv_tbl (j).attribute4 :=
4443 txl_contracts_dff_rec.attribute4;
4444 l_tclv_tbl (j).attribute5 :=
4445 txl_contracts_dff_rec.attribute5;
4446 l_tclv_tbl (j).attribute6 :=
4447 txl_contracts_dff_rec.attribute6;
4448 l_tclv_tbl (j).attribute7 :=
4449 txl_contracts_dff_rec.attribute7;
4450 l_tclv_tbl (j).attribute8 :=
4451 txl_contracts_dff_rec.attribute8;
4452 l_tclv_tbl (j).attribute9 :=
4453 txl_contracts_dff_rec.attribute9;
4454 l_tclv_tbl (j).attribute10 :=
4455 txl_contracts_dff_rec.attribute10;
4456 l_tclv_tbl (j).attribute11 :=
4457 txl_contracts_dff_rec.attribute11;
4458 l_tclv_tbl (j).attribute12 :=
4459 txl_contracts_dff_rec.attribute12;
4460 l_tclv_tbl (j).attribute13 :=
4461 txl_contracts_dff_rec.attribute13;
4462 l_tclv_tbl (j).attribute14 :=
4463 txl_contracts_dff_rec.attribute14;
4464 l_tclv_tbl (j).attribute15 :=
4465 txl_contracts_dff_rec.attribute15;
4466 END LOOP;
4467
4468 -- This will calculate the amount and generate accounting entries
4469 -- Set the tmpl_identify_tbl in parameter
4470 l_tmpl_identify_tbl (j).product_id := l_pdt_id;
4471 l_tmpl_identify_tbl (j).transaction_type_id :=
4472 px_tcnv_rec.try_id;
4473 l_tmpl_identify_tbl (j).memo_yn := g_no;
4474 l_tmpl_identify_tbl (j).prior_year_yn := g_no;
4475 l_tmpl_identify_tbl (j).stream_type_id :=
4476 lix_template_tbl (i).sty_id;
4477 l_tmpl_identify_tbl (j).advance_arrears :=
4478 lix_template_tbl (i).advance_arrears;
4479 l_tmpl_identify_tbl (j).factoring_synd_flag :=
4480 lix_template_tbl (i).factoring_synd_flag;
4481 l_tmpl_identify_tbl (j).investor_code :=
4482 lix_template_tbl (i).inv_code;
4483 l_tmpl_identify_tbl (j).syndication_code :=
4484 lix_template_tbl (i).syt_code;
4485 l_tmpl_identify_tbl (j).factoring_code :=
4486 lix_template_tbl (i).fac_code;
4487 --increment looping variable
4488 j := j + 1;
4489 --increment line number
4490 l_line_number := l_line_number + 1;
4491 END LOOP;
4492
4493 EXIT WHEN (i = lix_template_tbl.LAST);
4494 i := lix_template_tbl.NEXT (i);
4495 END LOOP;
4496
4497 IF (is_debug_statement_on)
4498 THEN
4499 okl_debug_pub.log_debug
4500 (g_level_statement,
4501 l_module_name,
4502 'calling okl_trx_contracts_pub.create_trx_cntrct_lines'
4503 );
4504 END IF;
4505
4506 --create trx contract lines table
4507 okl_trx_contracts_pub.create_trx_cntrct_lines
4508 (p_api_version => l_api_version,
4509 p_init_msg_list => g_false,
4510 x_return_status => l_return_status,
4511 x_msg_count => l_msg_count,
4512 x_msg_data => l_msg_data,
4513 p_tclv_tbl => l_tclv_tbl,
4514 x_tclv_tbl => lx_tclv_tbl
4515 );
4516
4517 IF (is_debug_statement_on)
4518 THEN
4519 okl_debug_pub.log_debug
4520 (g_level_statement,
4521 l_module_name,
4522 'called okl_trx_contracts_pub.create_trx_cntrct_lines , return status: '
4523 || l_return_status
4524 );
4525 END IF;
4526
4527 -- If error inserting line then set message
4528 IF l_return_status <> okl_api.g_ret_sts_success
4529 THEN
4530 -- Error occurred when creating accounting entries for transaction TRX_TYPE.
4531 okl_api.set_message (p_app_name => g_app_name,
4532 p_msg_name => 'OKL_AM_ERR_ACC_ENT',
4533 p_token1 => 'TRX_TYPE',
4534 p_token1_value => l_trans_meaning
4535 );
4536 END IF;
4537
4538 -- Raise exception to rollback to savepoint for this block
4539 IF (l_return_status = okl_api.g_ret_sts_unexp_error)
4540 THEN
4541 RAISE okl_api.g_exception_unexpected_error;
4542 ELSIF (l_return_status = okl_api.g_ret_sts_error)
4543 THEN
4544 RAISE okl_api.g_exception_error;
4545 END IF;
4546
4547 --setting the input table type to the obtained outout table type
4548 l_tclv_tbl := lx_tclv_tbl;
4549
4550 -- ***************************
4551 -- POPULATE ACC GEN PRIMARY KEY TABLE
4552 -- ******************************
4553 -- added code to set lp_acc_gen_primary_key_tbl
4554 -- for account generator
4555 -- *********************************************
4556 -- Accounting Engine Call
4557 -- *********************************************
4558 --txl contracts loop
4559 -- udhenuko Bug 6685693 Start. Moving the loop so that the accounting transactions
4560 -- includes fees service lines for the partially terminated asset.
4561 IF l_tclv_tbl.COUNT <> 0
4562 THEN
4563 i := l_tclv_tbl.FIRST;
4564
4565 LOOP
4566 IF (is_debug_statement_on)
4567 THEN
4568 okl_debug_pub.log_debug
4569 (g_level_statement,
4570 l_module_name,
4571 'calling okl_acc_call_pvt.okl_populate_acc_gen'
4572 );
4573 END IF;
4574
4575 okl_acc_call_pvt.okl_populate_acc_gen
4576 (p_contract_id => p_term_rec.p_contract_id,
4577 p_contract_line_id => l_tclv_tbl (i).kle_id,
4578 x_acc_gen_tbl => lp_acc_gen_primary_key_tbl,
4579 x_return_status => l_return_status
4580 );
4581
4582 -- udhenuko Bug 6685693 Bug end.
4583 IF (is_debug_statement_on)
4584 THEN
4585 okl_debug_pub.log_debug
4586 (g_level_statement,
4587 l_module_name,
4588 'called okl_acc_call_pvt.okl_populate_acc_gen , return status: '
4589 || l_return_status
4590 );
4591 END IF;
4592
4593 IF l_return_status <> okl_api.g_ret_sts_success
4594 THEN
4595 -- Error occurred when creating accounting entries for transaction TRX_TYPE.
4596 okl_api.set_message (p_app_name => g_app_name,
4597 p_msg_name => 'OKL_AM_ERR_ACC_ENT',
4598 p_token1 => 'TRX_TYPE',
4599 p_token1_value => l_trans_meaning
4600 );
4601 END IF;
4602
4603 -- Raise exception to rollback to savepoint for this block
4604 IF (l_return_status = okl_api.g_ret_sts_unexp_error)
4605 THEN
4606 RAISE okl_api.g_exception_unexpected_error;
4607 ELSIF (l_return_status = okl_api.g_ret_sts_error)
4608 THEN
4609 RAISE okl_api.g_exception_error;
4610 END IF;
4611
4612 --Assigning the account generator table
4613 l_acc_gen_tbl (i).acc_gen_key_tbl := lp_acc_gen_primary_key_tbl;
4614 l_acc_gen_tbl (i).source_id := l_tclv_tbl (i).ID;
4615 --populating dist info tbl
4616 l_dist_info_tbl (i).source_id := l_tclv_tbl (i).ID;
4617 l_dist_info_tbl (i).source_table := 'OKL_TXL_CNTRCT_LNS';
4618 l_dist_info_tbl (i).accounting_date := l_quote_accpt_date;
4619 l_dist_info_tbl (i).gl_reversal_flag := g_no;
4620 l_dist_info_tbl (i).post_to_gl := g_yes;
4621 l_dist_info_tbl (i).contract_id := l_tclv_tbl (i).khr_id;
4622 l_dist_info_tbl (i).contract_line_id := l_tclv_tbl (i).kle_id;
4623 l_dist_info_tbl (i).currency_code := l_currency_code;
4624
4625 IF ( (l_functional_currency_code IS NOT NULL)
4626 AND (l_currency_code <> l_functional_currency_code)
4627 )
4628 THEN
4629 l_dist_info_tbl (i).currency_conversion_rate :=
4630 l_currency_conversion_rate;
4631 l_dist_info_tbl (i).currency_conversion_type :=
4632 l_currency_conversion_type;
4633 l_dist_info_tbl (i).currency_conversion_date :=
4634 l_currency_conversion_date;
4635 END IF;
4636
4637 --form context val table
4638 IF lp_ctxt_val_tbl.COUNT > 0
4639 THEN
4640 l_ctxt_tbl (i).ctxt_val_tbl := lp_ctxt_val_tbl;
4641 l_ctxt_tbl (i).source_id := l_tclv_tbl (i).ID;
4642 END IF;
4643
4644 EXIT WHEN i = l_tclv_tbl.LAST;
4645 i := l_tclv_tbl.NEXT (i);
4646 END LOOP;
4647 END IF;
4648
4649 l_tcn_id := px_tcnv_rec.ID;
4650
4651 -- call accounting engine
4652 -- This will calculate the amount and generate accounting entries
4653 IF (is_debug_statement_on)
4654 THEN
4655 okl_debug_pub.log_debug
4656 (g_level_statement,
4657 l_module_name,
4658 'calling okl_account_dist_pvt.create_accounting_dist'
4659 );
4660 END IF;
4661
4662 okl_account_dist_pvt.create_accounting_dist
4663 (p_api_version => l_api_version,
4664 p_init_msg_list => g_false,
4665 x_return_status => l_return_status,
4666 x_msg_count => l_msg_count,
4667 x_msg_data => l_msg_data,
4668 p_tmpl_identify_tbl => l_tmpl_identify_tbl,
4669 p_dist_info_tbl => l_dist_info_tbl,
4670 p_ctxt_val_tbl => l_ctxt_tbl,
4671 p_acc_gen_primary_key_tbl => l_acc_gen_tbl,
4672 x_template_tbl => l_template_out_tbl,
4673 x_amount_tbl => l_amount_out_tbl,
4674 p_trx_header_id => l_tcn_id
4675 );
4676
4677 IF (is_debug_statement_on)
4678 THEN
4679 okl_debug_pub.log_debug
4680 (g_level_statement,
4681 l_module_name,
4682 'called okl_account_dist_pvt.create_accounting_dist , return status: '
4683 || l_return_status
4684 );
4685 END IF;
4686
4687 IF l_amount_out_tbl.COUNT = 0
4688 THEN
4689 l_return_status := okl_api.g_ret_sts_error;
4690 END IF;
4691
4692 IF l_return_status <> okl_api.g_ret_sts_success
4693 THEN
4694 -- Error occurred when creating accounting entries for transaction TRX_TYPE.
4695 okl_api.set_message (p_app_name => g_app_name,
4696 p_msg_name => 'OKL_AM_ERR_ACC_ENT',
4697 p_token1 => 'TRX_TYPE',
4698 p_token1_value => l_trans_meaning
4699 );
4700 END IF;
4701
4702 -- Raise exception to rollback to savepoint for this block
4703 IF (l_return_status = okl_api.g_ret_sts_unexp_error)
4704 THEN
4705 RAISE okl_api.g_exception_unexpected_error;
4706 ELSIF (l_return_status = okl_api.g_ret_sts_error)
4707 THEN
4708 RAISE okl_api.g_exception_error;
4709 END IF;
4710
4711 -- ******************************************************
4712 -- Update Trx Contracts with Header and Line Amounts
4713 -- ******************************************************
4714
4715 --call the update trx contract api to update amount per stream type
4716 lip_tcnv_rec := px_tcnv_rec;
4717 --set all the necessary attributes of the record type
4718 lip_tcnv_rec.amount := 0;
4719 lip_tcnv_rec.set_of_books_id :=
4720 okl_accounting_util.get_set_of_books_id
4721 ();
4722 lip_tcnv_rec.org_id := l_org_id;
4723 --akrangan bug 6147049 fix start
4724 lip_tcnv_rec.currency_conversion_rate := l_currency_conversion_rate;
4725 lip_tcnv_rec.currency_conversion_type := l_currency_conversion_type;
4726 lip_tcnv_rec.currency_conversion_date := l_currency_conversion_date;
4727 --akrangan bug 6147049 fix end
4728 --akrangan bug 6215707 fix start
4729 lip_tcnv_rec.tsu_code := 'PROCESSED';
4730
4731 --akrangan bug 6215707 fix end
4732 --product name and tax owner code
4733 OPEN product_name_csr (l_pdt_id);
4734
4735 FETCH product_name_csr
4736 INTO lip_tcnv_rec.product_name,
4737 lip_tcnv_rec.tax_owner_code;
4738
4739 CLOSE product_name_csr;
4740
4741 --trx contracts hdr dffs
4742 OPEN trx_contracts_dff_csr (p_term_rec.p_contract_id);
4743
4744 FETCH trx_contracts_dff_csr
4745 INTO lip_tcnv_rec.attribute_category,
4746 lip_tcnv_rec.attribute1,
4747 lip_tcnv_rec.attribute2,
4748 lip_tcnv_rec.attribute3,
4749 lip_tcnv_rec.attribute4,
4750 lip_tcnv_rec.attribute5,
4751 lip_tcnv_rec.attribute6,
4752 lip_tcnv_rec.attribute7,
4753 lip_tcnv_rec.attribute8,
4754 lip_tcnv_rec.attribute9,
4755 lip_tcnv_rec.attribute10,
4756 lip_tcnv_rec.attribute11,
4757 lip_tcnv_rec.attribute12,
4758 lip_tcnv_rec.attribute13,
4759 lip_tcnv_rec.attribute14,
4760 lip_tcnv_rec.attribute15;
4761
4762 CLOSE trx_contracts_dff_csr;
4763
4764 IF (l_tclv_tbl.COUNT) > 0 AND (l_amount_out_tbl.COUNT > 0)
4765 THEN
4766 k := l_tclv_tbl.FIRST;
4767 m := l_amount_out_tbl.FIRST;
4768
4769 LOOP
4770 l_tclv_tbl (k).amount := 0;
4771
4772 IF l_tclv_tbl (k).ID = l_amount_out_tbl (m).source_id
4773 THEN
4774 lx_amount_tbl := l_amount_out_tbl (m).amount_tbl;
4775 lx_template_tbl := l_template_out_tbl (m).template_tbl;
4776
4777 IF (lx_amount_tbl.COUNT <> 1 OR lx_template_tbl.COUNT <> 1
4778 )
4779 THEN
4780 --raise error
4781 l_return_status := okl_api.g_ret_sts_error;
4782 -- Error occurred when creating accounting entries for transaction TRX_TYPE.
4783 okl_api.set_message (p_app_name => g_app_name,
4784 p_msg_name => 'OKL_AM_ERR_ACC_ENT',
4785 p_token1 => 'TRX_TYPE',
4786 p_token1_value => l_trans_meaning
4787 );
4788 -- Raise exception to rollback to savepoint for this block
4789 RAISE okl_api.g_exception_error;
4790 ELSE
4791 l := lx_amount_tbl.FIRST;
4792 --update line amount
4793 l_tclv_tbl (k).amount := NVL (lx_amount_tbl (l), 0);
4794 END IF;
4795 END IF;
4796
4797 --update total header amount
4798 lip_tcnv_rec.amount :=
4799 lip_tcnv_rec.amount + l_tclv_tbl (k).amount;
4800 EXIT WHEN k = l_tclv_tbl.LAST OR m = l_amount_out_tbl.LAST;
4801 k := l_tclv_tbl.NEXT (k);
4802 m := l_amount_out_tbl.NEXT (m);
4803 END LOOP;
4804 END IF;
4805
4806 IF (is_debug_statement_on)
4807 THEN
4808 okl_debug_pub.log_debug
4809 (g_level_statement,
4810 l_module_name,
4811 'calling okl_trx_contracts_pub.update_trx_contracts'
4812 );
4813 END IF;
4814
4815 --call the api to update trx contracts hdr and lines
4816 okl_trx_contracts_pub.update_trx_contracts
4817 (p_api_version => l_api_version,
4818 p_init_msg_list => g_false,
4819 x_return_status => l_return_status,
4820 x_msg_count => l_msg_count,
4821 x_msg_data => l_msg_data,
4822 p_tcnv_rec => lip_tcnv_rec,
4823 p_tclv_tbl => l_tclv_tbl,
4824 x_tcnv_rec => lix_tcnv_rec,
4825 x_tclv_tbl => lx_tclv_tbl
4826 );
4827
4828 IF (is_debug_statement_on)
4829 THEN
4830 okl_debug_pub.log_debug
4831 (g_level_statement,
4832 l_module_name,
4833 'called okl_trx_contracts_pub.update_trx_contracts , return status: '
4834 || l_return_status
4835 );
4836 END IF;
4837
4838 --handle exception
4839 IF l_return_status <> okl_api.g_ret_sts_success
4840 THEN
4841 -- Error occurred when creating accounting entries for transaction TRX_TYPE.
4842 okl_api.set_message (p_app_name => g_app_name,
4843 p_msg_name => 'OKL_AM_ERR_ACC_ENT',
4844 p_token1 => 'TRX_TYPE',
4845 p_token1_value => l_trans_meaning
4846 );
4847 END IF;
4848
4849 -- Raise exception to rollback to savepoint for this block
4850 IF (l_return_status = okl_api.g_ret_sts_unexp_error)
4851 THEN
4852 RAISE okl_api.g_exception_unexpected_error;
4853 ELSIF (l_return_status = okl_api.g_ret_sts_error)
4854 THEN
4855 RAISE okl_api.g_exception_error;
4856 END IF;
4857
4858 -- Set the return record
4859 px_tcnv_rec := lix_tcnv_rec;
4860
4861 OKL_MULTIGAAP_ENGINE_PVT.CREATE_SEC_REP_TRX
4862 (p_api_version => l_api_version
4863 ,p_init_msg_list => g_false
4864 ,x_return_status => l_return_status
4865 ,x_msg_count => l_msg_count
4866 ,x_msg_data => l_msg_data
4867 ,P_TCNV_REC => lip_tcnv_rec
4868 ,P_TCLV_TBL => l_tclv_tbl
4869 ,p_ctxt_val_tbl => l_ctxt_tbl
4870 ,p_acc_gen_primary_key_tbl => lp_acc_gen_primary_key_tbl);
4871
4872 IF (l_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
4873 RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
4874 ELSIF (l_return_status = Okl_Api.G_RET_STS_ERROR) THEN
4875 RAISE Okl_Api.G_EXCEPTION_ERROR;
4876 END IF;
4877
4878 -- Bug 3061772
4879 -- Call to Process dicount and Subsidy during acceptance of a termination quote
4880 IF (is_debug_statement_on)
4881 THEN
4882 okl_debug_pub.log_debug
4883 (g_level_statement,
4884 l_module_name,
4885 'calling okl_am_lease_loan_trmnt_pvt.process_discount_subsidy'
4886 );
4887 END IF;
4888
4889 okl_am_lease_loan_trmnt_pvt.process_discount_subsidy
4890 (p_api_version => l_api_version,
4891 p_init_msg_list => okl_api.g_false,
4892 x_return_status => l_return_status,
4893 x_msg_count => l_msg_count,
4894 x_msg_data => l_msg_data,
4895 p_term_rec => p_term_rec,
4896 p_call_origin => 'PARTIAL',
4897 p_termination_date => p_sys_date
4898 );
4899
4900 IF (is_debug_statement_on)
4901 THEN
4902 okl_debug_pub.log_debug
4903 (g_level_statement,
4904 l_module_name,
4905 'called okl_am_lease_loan_trmnt_pvt.process_discount_subsidy , return status: '
4906 || l_return_status
4907 );
4908 END IF;
4909
4910 IF l_return_status <> okl_api.g_ret_sts_success
4911 THEN
4912 okl_api.set_message (p_app_name => g_app_name,
4913 p_msg_name => 'OKL_AM_SUBSIDY_PROC_FAIL');
4914 END IF;
4915
4916 IF (l_return_status = g_ret_sts_unexp_error)
4917 THEN
4918 RAISE okl_api.g_exception_unexpected_error;
4919 ELSIF (l_return_status = g_ret_sts_error)
4920 THEN
4921 RAISE okl_api.g_exception_error;
4922 END IF;
4923
4924 -- SUCCESS MESSAGES
4925
4926 -- Set success messages here
4927 -- Get the meaning of lookup
4928 l_trans_meaning :=
4929 okl_am_util_pvt.get_lookup_meaning
4930 (p_lookup_type => 'OKL_ACCOUNTING_EVENT_TYPE',
4931 p_lookup_code => 'TERMINATION',
4932 p_validate_yn => 'Y'
4933 );
4934 -- Accounting entries created for transaction type TRX_TYPE.
4935 okl_api.set_message (p_app_name => g_app_name,
4936 p_msg_name => 'OKL_AM_ACC_ENT_CREATED',
4937 p_token1 => 'TRX_TYPE',
4938 p_token1_value => l_trans_meaning
4939 );
4940 -- store the highest degree of error
4941 set_overall_status (p_return_status => l_return_status,
4942 px_overall_status => px_overall_status);
4943 -- set the transaction record
4944 set_transaction_rec (p_return_status => l_return_status,
4945 p_overall_status => px_overall_status,
4946 p_tmt_flag => 'TMT_ACCOUNTING_ENTRIES_YN',
4947 p_tsu_code => 'WORKING',
4948 px_tcnv_rec => px_tcnv_rec
4949 );
4950 END IF;
4951
4952 x_return_status := l_return_status;
4953
4954 IF (is_debug_procedure_on)
4955 THEN
4956 okl_debug_pub.log_debug (g_level_procedure,
4957 l_module_name,
4958 'End(-)'
4959 );
4960 END IF;
4961 EXCEPTION
4962 WHEN okl_api.g_exception_error
4963 THEN
4964 -- Close any open cursors
4965 IF l_product_type_csr%ISOPEN
4966 THEN
4967 CLOSE l_product_type_csr;
4968 END IF;
4969
4970 IF prod_id_csr%ISOPEN
4971 THEN
4972 CLOSE prod_id_csr;
4973 END IF;
4974
4975 -- Rollback to savepoint
4976 ROLLBACK TO accounting_entries;
4977 -- Set Return status
4978 x_return_status := g_ret_sts_error;
4979 -- store the highest degree of error
4980 set_overall_status (p_return_status => x_return_status,
4981 px_overall_status => px_overall_status);
4982 -- set the transaction record
4983 set_transaction_rec (p_return_status => x_return_status,
4984 p_overall_status => px_overall_status,
4985 p_tmt_flag => 'TMT_ACCOUNTING_ENTRIES_YN',
4986 p_tsu_code => 'ERROR',
4987 px_tcnv_rec => px_tcnv_rec
4988 );
4989
4990 IF (is_debug_exception_on)
4991 THEN
4992 okl_debug_pub.log_debug (g_level_exception,
4993 l_module_name,
4994 'EXCEPTION :' || 'G_EXCEPTION_ERROR'
4995 );
4996 END IF;
4997 WHEN okl_api.g_exception_unexpected_error
4998 THEN
4999 -- Close any open cursors
5000 IF l_product_type_csr%ISOPEN
5001 THEN
5002 CLOSE l_product_type_csr;
5003 END IF;
5004
5005 IF prod_id_csr%ISOPEN
5006 THEN
5007 CLOSE prod_id_csr;
5008 END IF;
5009
5010 -- Rollback to savepoint
5011 ROLLBACK TO accounting_entries;
5012 -- Set Return status
5013 x_return_status := g_ret_sts_unexp_error;
5014 -- store the highest degree of error
5015 set_overall_status (p_return_status => x_return_status,
5016 px_overall_status => px_overall_status);
5017 -- set the transaction record
5018 set_transaction_rec (p_return_status => x_return_status,
5019 p_overall_status => px_overall_status,
5020 p_tmt_flag => 'TMT_ACCOUNTING_ENTRIES_YN',
5021 p_tsu_code => 'ERROR',
5022 px_tcnv_rec => px_tcnv_rec
5023 );
5024
5025 IF (is_debug_exception_on)
5026 THEN
5027 okl_debug_pub.log_debug (g_level_exception,
5028 l_module_name,
5029 'EXCEPTION :'
5030 || 'G_EXCEPTION_UNEXPECTED_ERROR'
5031 );
5032 END IF;
5033 WHEN OTHERS
5034 THEN
5035 -- Close any open cursors
5036 IF l_product_type_csr%ISOPEN
5037 THEN
5038 CLOSE l_product_type_csr;
5039 END IF;
5040
5041 IF prod_id_csr%ISOPEN
5042 THEN
5043 CLOSE prod_id_csr;
5044 END IF;
5045
5046 -- Rollback to savepoint
5047 ROLLBACK TO accounting_entries;
5048 -- Set Return status
5049 x_return_status := g_ret_sts_unexp_error;
5050 -- store the highest degree of error
5051 set_overall_status (p_return_status => x_return_status,
5052 px_overall_status => px_overall_status);
5053 -- set the transaction record
5054 set_transaction_rec (p_return_status => x_return_status,
5055 p_overall_status => px_overall_status,
5056 p_tmt_flag => 'TMT_ACCOUNTING_ENTRIES_YN',
5057 p_tsu_code => 'ERROR',
5058 px_tcnv_rec => px_tcnv_rec
5059 );
5060 -- Set the oracle error message
5061 okl_api.set_message (p_app_name => g_app_name_1,
5062 p_msg_name => g_unexpected_error,
5063 p_token1 => g_sqlcode_token,
5064 p_token1_value => SQLCODE,
5065 p_token2 => g_sqlerrm_token,
5066 p_token2_value => SQLERRM
5067 );
5068
5069 IF (is_debug_exception_on)
5070 THEN
5071 okl_debug_pub.log_debug (g_level_exception,
5072 l_module_name,
5073 'EXCEPTION :'
5074 || 'OTHERS, SQLCODE: '
5075 || SQLCODE
5076 || ' , SQLERRM : '
5077 || SQLERRM
5078 );
5079 END IF;
5080 END accounting_entries;
5081
5082 -- Start of comments
5083 --
5084 -- Procedure Name : dispose_assets
5085 -- Desciption : Call the Asset Dispose API to dispose off assets
5086 -- Business Rules :
5087 -- Parameters :
5088 -- Version : 1.0
5089 -- History : RMUNJULU Bug # 2484327 16-DEC-02, changed parameter value
5090 -- to p_quantity to set the quote_quantity
5091 -- : SECHAWLA 31-DEC-02 Bug #2726739
5092 -- Added logic to convert proceeds of sale amount to functional currency
5093 -- : RMUNJULU 23-JAN-03 2762065 Return E if split asset already
5094 -- done
5095 -- : RMUNJULU 04-FEB-03 2781557 Added code to get and set
5096 -- proceeds of sale properly. Also removed the FA related fix
5097 -- introduced by bug 2762065 since split asset wont retire if
5098 -- dispose also being done
5099 -- : RMUNJULU 06-MAR-03 Performance Fix Replaced K_HDR_FULL
5100 -- : SECHAWLA 11-MAR-03 Modified kle_pur_amt_csr cursor to nvl the purchase amount
5101 -- : rmunjulu EDAT Added code to set trn_date as currency conversion trn date
5102 -- also send quote eff date and quote acceptance date to disposal api.
5103 --
5104 -- End of comments
5105 PROCEDURE dispose_assets (
5106 p_term_rec IN term_rec_type,
5107 p_sys_date IN DATE,
5108 p_klev_tbl IN klev_tbl_type,
5109 p_trn_already_set IN VARCHAR2,
5110 px_overall_status IN OUT NOCOPY VARCHAR2,
5111 px_tcnv_rec IN OUT NOCOPY tcnv_rec_type,
5112 x_return_status OUT NOCOPY VARCHAR2
5113 )
5114 IS
5115 -- Cursor to get the purchase amount for the line
5116 -- RMUNJULU 04-FEB-03 2781557 Changed cursor to get proper purchase amount lines
5117 CURSOR kle_pur_amt_csr (
5118 p_kle_id IN NUMBER,
5119 p_qte_id IN NUMBER
5120 )
5121 IS
5122 SELECT NVL (tql.amount, 0) amount --SECHAWLA 11-MAR-03 : Added nvl
5123 FROM okl_txl_quote_lines_v tql
5124 WHERE tql.kle_id = p_kle_id
5125 AND tql.qte_id = p_qte_id
5126 AND tql.qlt_code = 'AMBPOC'; -- Purchase Amount
5127
5128 kle_pur_amt_rec kle_pur_amt_csr%ROWTYPE;
5129 l_return_status VARCHAR2 (1) := g_ret_sts_success;
5130 l_overall_dispose_status VARCHAR2 (1) := g_ret_sts_success;
5131 l_asset_id NUMBER;
5132 l_line_number VARCHAR2 (200);
5133 i NUMBER := 1;
5134 l_proceeds_of_sale NUMBER;
5135 l_api_version CONSTANT NUMBER := g_api_version;
5136 l_msg_count NUMBER := g_miss_num;
5137 l_msg_data VARCHAR2 (2000);
5138 l_module_name VARCHAR2 (500)
5139 := g_module_name || 'dispose_assets';
5140 is_debug_exception_on BOOLEAN
5141 := okl_debug_pub.check_log_on (l_module_name, g_level_exception);
5142 is_debug_procedure_on BOOLEAN
5143 := okl_debug_pub.check_log_on (l_module_name, g_level_procedure);
5144 is_debug_statement_on BOOLEAN
5145 := okl_debug_pub.check_log_on (l_module_name, g_level_statement);
5146 --SECHAWLA Bug # 2726739 : new declarations
5147 l_func_curr_code gl_ledgers_public_v.currency_code%TYPE;
5148 l_contract_curr_code okc_k_headers_b.currency_code%TYPE;
5149 -- RMUNJULU 06-MAR-03 Performance Fix Replaced K_HDR_FULL
5150 lx_contract_currency okc_k_headers_v.currency_code%TYPE;
5151 lx_currency_conversion_type okl_k_headers_v.currency_conversion_type%TYPE;
5152 lx_currency_conversion_rate okl_k_headers_v.currency_conversion_rate%TYPE;
5153 lx_currency_conversion_date okl_k_headers_v.currency_conversion_date%TYPE;
5154 lx_converted_amount NUMBER;
5155 -- rmunjulu EDAT
5156 l_quote_accpt_date DATE;
5157 l_quote_eff_date DATE;
5158 -- RRAVIKIR Legal Entity changes
5159 l_legal_entity_id NUMBER;
5160 -- Legal Entity changes end
5161 BEGIN
5162 -- Start savepoint to rollback to if the block fails
5163 SAVEPOINT asset_dispose;
5164
5165 IF (is_debug_procedure_on)
5166 THEN
5167 okl_debug_pub.log_debug (g_level_procedure,
5168 l_module_name,
5169 'Begin(+)'
5170 );
5171 END IF;
5172
5173 IF (is_debug_statement_on)
5174 THEN
5175 okl_debug_pub.log_debug (g_level_statement,
5176 l_module_name,
5177 'In param, p_sys_date: ' || p_sys_date
5178 );
5179 okl_debug_pub.log_debug (g_level_statement,
5180 l_module_name,
5181 'In param, p_trn_already_set: '
5182 || p_trn_already_set
5183 );
5184 okl_debug_pub.log_debug (g_level_statement,
5185 l_module_name,
5186 'In param, px_overall_status: '
5187 || px_overall_status
5188 );
5189 okl_debug_pub.log_debug (g_level_statement,
5190 l_module_name,
5191 'In param, p_term_rec.p_quote_id: '
5192 || p_term_rec.p_quote_id
5193 );
5194 okl_debug_pub.log_debug (g_level_statement,
5195 l_module_name,
5196 'In param, p_term_rec.p_contract_id: '
5197 || p_term_rec.p_contract_id
5198 );
5199 okl_debug_pub.log_debug
5200 (g_level_statement,
5201 l_module_name,
5202 'In param, p_term_rec.p_contract_number: '
5203 || p_term_rec.p_contract_number
5204 );
5205 okl_debug_pub.log_debug
5206 (g_level_statement,
5207 l_module_name,
5208 'In param, px_tcnv_rec.tmt_asset_disposition_yn: '
5209 || px_tcnv_rec.tmt_asset_disposition_yn
5210 );
5211
5212 IF p_klev_tbl.COUNT > 0
5213 THEN
5214 FOR i IN p_klev_tbl.FIRST .. p_klev_tbl.LAST
5215 LOOP
5216 IF (p_klev_tbl.EXISTS (i))
5217 THEN
5218 okl_debug_pub.log_debug (g_level_statement,
5219 l_module_name,
5220 'In param, p_klev_tbl('
5221 || i
5222 || ').p_kle_id: '
5223 || p_klev_tbl (i).p_kle_id
5224 );
5225 okl_debug_pub.log_debug (g_level_statement,
5226 l_module_name,
5227 'In param, p_klev_tbl('
5228 || i
5229 || ').p_asset_quantity: '
5230 || p_klev_tbl (i).p_asset_quantity
5231 );
5232 okl_debug_pub.log_debug (g_level_statement,
5233 l_module_name,
5234 'In param, p_klev_tbl('
5235 || i
5236 || ').p_asset_name: '
5237 || p_klev_tbl (i).p_asset_name
5238 );
5239 okl_debug_pub.log_debug (g_level_statement,
5240 l_module_name,
5241 'In param, p_klev_tbl('
5242 || i
5243 || ').p_quote_quantity: '
5244 || p_klev_tbl (i).p_quote_quantity
5245 );
5246 okl_debug_pub.log_debug (g_level_statement,
5247 l_module_name,
5248 'In param, p_klev_tbl('
5249 || i
5250 || ').p_tql_id: '
5251 || p_klev_tbl (i).p_tql_id
5252 );
5253 okl_debug_pub.log_debug (g_level_statement,
5254 l_module_name,
5255 'In param, p_klev_tbl('
5256 || i
5257 || ').p_split_kle_name: '
5258 || p_klev_tbl (i).p_split_kle_name
5259 );
5260 okl_debug_pub.log_debug (g_level_statement,
5261 l_module_name,
5262 'In param, p_klev_tbl('
5263 || i
5264 || ').p_split_kle_id: '
5265 || p_klev_tbl (i).p_split_kle_id
5266 );
5267 END IF;
5268 END LOOP;
5269 END IF;
5270 END IF;
5271
5272 -- Check if disposition done earlier
5273 IF ( p_trn_already_set = g_yes
5274 AND NVL (px_tcnv_rec.tmt_asset_disposition_yn, '?') <> g_yes
5275 )
5276 OR (p_trn_already_set = g_no)
5277 THEN
5278 -- RMUNJULU 3018641 Step Message
5279 -- Step : Asset Dispose
5280 okl_api.set_message (p_app_name => g_app_name,
5281 p_msg_name => 'OKL_AM_STEP_ADP');
5282
5283 -- rmunjulu +++++++++ Effective Dated Termination -- start ++++++++++++++++
5284
5285 -- rmunjulu EDAT
5286 -- If quote exists then accnting date is quote accept date else sysdate
5287 IF NVL (okl_am_lease_loan_trmnt_pvt.g_quote_exists, 'N') = 'Y'
5288 THEN
5289 l_quote_accpt_date :=
5290 okl_am_lease_loan_trmnt_pvt.g_quote_accept_date;
5291 l_quote_eff_date :=
5292 okl_am_lease_loan_trmnt_pvt.g_quote_eff_from_date;
5293 ELSE
5294 l_quote_accpt_date := p_sys_date;
5295 l_quote_eff_date := p_sys_date;
5296 END IF;
5297
5298 -- rmunjulu +++++++++ Effective Dated Termination -- end ++++++++++++++++
5299 IF (p_klev_tbl.COUNT > 0)
5300 THEN
5301 i := p_klev_tbl.FIRST;
5302
5303 LOOP
5304 -- Initialize proceeds_of_sale
5305 l_proceeds_of_sale := 0;
5306
5307 -- Loop in the purchase amounts to set proceeds_of_sale
5308 FOR kle_pur_amt_rec IN
5309 kle_pur_amt_csr (p_klev_tbl (i).p_kle_id,
5310 p_term_rec.p_quote_id)
5311 LOOP
5312 l_proceeds_of_sale :=
5313 l_proceeds_of_sale + kle_pur_amt_rec.amount;
5314 END LOOP;
5315
5316 -- SECHAWLA 11-MAR-03 : Commented the following IF, as it is not necessary
5317
5318 /*
5319 -- RMUNJULU 04-FEB-03 2781557 Added if to set the proceeds of sales if no value
5320 IF l_proceeds_of_sale IS NULL THEN
5321 l_proceeds_of_sale := 0;
5322 END IF;
5323 */
5324
5325 -- SECHAWLA Bug # 2726739 : added the folowing piece of code
5326
5327 -- get the functional currency
5328 l_func_curr_code := okl_am_util_pvt.get_functional_currency;
5329 -- get the contract currency
5330 l_contract_curr_code :=
5331 okl_am_util_pvt.get_chr_currency
5332 (p_chr_id => p_term_rec.p_contract_id);
5333
5334 IF l_contract_curr_code <> l_func_curr_code
5335 THEN
5336 -- convert amount to functional currency
5337 IF (is_debug_statement_on)
5338 THEN
5339 okl_debug_pub.log_debug
5340 (g_level_statement,
5341 l_module_name,
5342 'calling okl_accounting_util.convert_to_functional_currency'
5343 );
5344 END IF;
5345
5346 okl_accounting_util.convert_to_functional_currency
5347 (p_khr_id => p_term_rec.p_contract_id,
5348 p_to_currency => l_func_curr_code,
5349 p_transaction_date => p_sys_date,
5350 p_amount => l_proceeds_of_sale,
5351 x_return_status => x_return_status,
5352 x_contract_currency => lx_contract_currency,
5353 x_currency_conversion_type => lx_currency_conversion_type,
5354 x_currency_conversion_rate => lx_currency_conversion_rate,
5355 x_currency_conversion_date => lx_currency_conversion_date,
5356 x_converted_amount => lx_converted_amount
5357 );
5358
5359 IF (is_debug_statement_on)
5360 THEN
5361 okl_debug_pub.log_debug
5362 (g_level_statement,
5363 l_module_name,
5364 'called okl_accounting_util.convert_to_functional_currency , return status: '
5365 || x_return_status
5366 );
5367 okl_debug_pub.log_debug (g_level_statement,
5368 l_module_name,
5369 'lx_contract_currency_code: '
5370 || lx_contract_currency
5371 );
5372 okl_debug_pub.log_debug
5373 (g_level_statement,
5374 l_module_name,
5375 'lx_currency_conversion_type: '
5376 || lx_currency_conversion_type
5377 );
5378 okl_debug_pub.log_debug
5379 (g_level_statement,
5380 l_module_name,
5381 'lx_currency_conversion_rate: '
5382 || lx_currency_conversion_rate
5383 );
5384 okl_debug_pub.log_debug
5385 (g_level_statement,
5386 l_module_name,
5387 'lx_currency_conversion_date: '
5388 || lx_currency_conversion_date
5389 );
5390 okl_debug_pub.log_debug (g_level_statement,
5391 l_module_name,
5392 'lx_converted_amount: '
5393 || lx_converted_amount
5394 );
5395 END IF;
5396
5397 IF x_return_status <> g_ret_sts_success
5398 THEN
5399 -- Error occurred during disposal of asset NAME.
5400 okl_api.set_message
5401 (p_app_name => g_app_name,
5402 p_msg_name => 'OKL_AM_ERR_DISPOSAL',
5403 p_token1 => 'NAME',
5404 p_token1_value => p_klev_tbl (i).p_asset_name
5405 );
5406 END IF;
5407
5408 -- Raise exception to rollback to savepoint if error
5409 IF (x_return_status = g_ret_sts_unexp_error)
5410 THEN
5411 RAISE okl_api.g_exception_unexpected_error;
5412 ELSIF (x_return_status = g_ret_sts_error)
5413 THEN
5414 RAISE okl_api.g_exception_error;
5415 END IF;
5416
5417 l_proceeds_of_sale := lx_converted_amount;
5418 END IF;
5419
5420 -- -- SECHAWLA Bug # 2726739 : end new code
5421
5422 -- RMUNJULU 23-JAN-03 2762065 -- START --
5423 -- Code fix for FA related error in Asset Retirement
5424 -- We always return error when Asset Dispose called after a split asset
5425
5426 -- RMUNJULU 04-FEB-03 2781557 Removed the temporary FA related fix
5427 -- IF NVL(px_tcnv_rec.tmt_split_asset_yn, 'N') = 'Y' THEN
5428
5429 -- l_return_status := G_RET_STS_ERROR;
5430
5431 -- ELSE
5432
5433 -- RRAVIKIR Legal Entity Changes
5434 -- Populate the legal entity from the contract
5435 l_legal_entity_id :=
5436 okl_legal_entity_util.get_khr_le_id
5437 (p_khr_id => p_term_rec.p_contract_id);
5438
5439 -- Legal Entity Changes end
5440
5441 -- call asset dispose retirement
5442 IF (is_debug_statement_on)
5443 THEN
5444 okl_debug_pub.log_debug
5445 (g_level_statement,
5446 l_module_name,
5447 'calling OKL_AM_ASSET_DISPOSE_PUB.dispose_asset'
5448 );
5449 END IF;
5450
5451 okl_am_asset_dispose_pub.dispose_asset
5452 (p_api_version => l_api_version,
5453 p_init_msg_list => g_false,
5454 x_return_status => l_return_status,
5455 x_msg_count => l_msg_count,
5456 x_msg_data => l_msg_data,
5457 p_financial_asset_id => p_klev_tbl (i).p_kle_id,
5458 p_quantity => NULL,
5459 p_proceeds_of_sale => l_proceeds_of_sale,
5460 p_quote_eff_date => l_quote_eff_date,
5461 -- rmunjulu EDAT Pass additional parameters now required by disposal api
5462 p_quote_accpt_date => l_quote_accpt_date,
5463 -- rmunjulu EDAT Pass additional parameters now required by disposal api
5464 p_legal_entity_id => l_legal_entity_id
5465 ); -- RRAVIKIR Legal Entity Changes
5466
5467 IF (is_debug_statement_on)
5468 THEN
5469 okl_debug_pub.log_debug
5470 (g_level_statement,
5471 l_module_name,
5472 'called OKL_AM_ASSET_DISPOSE_PUB.dispose_asset , return status: '
5473 || l_return_status
5474 );
5475 END IF;
5476
5477 -- call asset dispose API
5478 -- RMUNJULU Bug # 2484327 16-DEC-02, changed parameter value to
5479 -- p_quantity to set the quote_quantity
5480 -- RMUNJULU 04-FEB-03 2781557 Changed value passed to p_quantity
5481 -- from quote_quantity to NULL
5482 /* OKL_AM_ASSET_DISPOSE_PUB.dispose_asset(
5483 p_api_version => l_api_version,
5484 p_init_msg_list => G_FALSE,
5485 x_return_status => l_return_status,
5486 x_msg_count => l_msg_count,
5487 x_msg_data => l_msg_data,
5488 p_financial_asset_id => p_klev_tbl(i).p_kle_id,
5489 p_quantity => NULL,
5490 p_proceeds_of_sale => l_proceeds_of_sale,
5491 p_quote_eff_date => l_quote_eff_date, -- rmunjulu EDAT Pass additional parameters now required by disposal api
5492 p_quote_accpt_date => l_quote_accpt_date); -- rmunjulu EDAT Pass additional parameters now required by disposal api
5493 */
5494
5495 -- END IF;
5496
5497 -- RMUNJULU 23-JAN-03 2762065 -- END --
5498
5499 -- Check the return status
5500 IF l_return_status <> g_ret_sts_success
5501 THEN
5502 -- Error occurred during disposal of asset NAME.
5503 okl_api.set_message
5504 (p_app_name => g_app_name,
5505 p_msg_name => 'OKL_AM_ERR_DISPOSAL',
5506 p_token1 => 'NAME',
5507 p_token1_value => p_klev_tbl (i).p_asset_name
5508 );
5509 END IF;
5510
5511 --08-mar-06 sgorantl -- Bug 3895098
5512 IF l_overall_dispose_status = okl_api.g_ret_sts_success
5513 AND l_return_status IN
5514 (okl_api.g_ret_sts_error,
5515 okl_api.g_ret_sts_unexp_error
5516 )
5517 THEN
5518 l_overall_dispose_status := l_return_status;
5519 END IF;
5520
5521 EXIT WHEN (i = p_klev_tbl.LAST);
5522 i := p_klev_tbl.NEXT (i);
5523 END LOOP;
5524
5525 --08-mar-06 sgorantl -- Bug 3895098
5526 -- Raise exception to rollback to savepoint if error
5527 IF (l_overall_dispose_status = okl_api.g_ret_sts_unexp_error)
5528 THEN
5529 RAISE okl_api.g_exception_unexpected_error;
5530 ELSIF (l_overall_dispose_status = okl_api.g_ret_sts_error)
5531 THEN
5532 RAISE okl_api.g_exception_error;
5533 END IF;
5534
5535 --08-mar-06 sgorantl -- Bug 3895098
5536
5537 -- Asset dispostion for assets of contract CONTRACT_NUMBER
5538 -- done successfully.
5539 okl_api.set_message
5540 (p_app_name => g_app_name,
5541 p_msg_name => 'OKL_AM_ASS_DISPOSE_SUCCESS',
5542 p_token1 => 'CONTRACT_NUMBER',
5543 p_token1_value => p_term_rec.p_contract_number
5544 );
5545 -- store the highest degree of error
5546 set_overall_status (p_return_status => l_overall_dispose_status,
5547 px_overall_status => px_overall_status);
5548 -- set the transaction record for asset disposition
5549 set_transaction_rec (p_return_status => l_overall_dispose_status,
5550 p_overall_status => px_overall_status,
5551 p_tmt_flag => 'TMT_ASSET_DISPOSITION_YN',
5552 p_tsu_code => 'WORKING',
5553 px_tcnv_rec => px_tcnv_rec
5554 );
5555 END IF;
5556 END IF;
5557
5558 -- set the transaction record for amortization
5559 set_transaction_rec (p_return_status => l_return_status,
5560 p_overall_status => px_overall_status,
5561 p_tmt_flag => 'TMT_AMORTIZATION_YN',
5562 p_tsu_code => 'WORKING',
5563 p_ret_val => NULL,
5564 px_tcnv_rec => px_tcnv_rec
5565 );
5566 -- set the transaction record for asset return
5567 set_transaction_rec (p_return_status => l_return_status,
5568 p_overall_status => px_overall_status,
5569 p_tmt_flag => 'TMT_ASSET_RETURN_YN',
5570 p_tsu_code => 'WORKING',
5571 p_ret_val => NULL,
5572 px_tcnv_rec => px_tcnv_rec
5573 );
5574 x_return_status := l_return_status;
5575
5576 IF (is_debug_procedure_on)
5577 THEN
5578 okl_debug_pub.log_debug (g_level_procedure,
5579 l_module_name,
5580 'End(-)'
5581 );
5582 END IF;
5583 EXCEPTION
5584 WHEN okl_api.g_exception_error
5585 THEN
5586 -- Close any open cursors
5587 IF kle_pur_amt_csr%ISOPEN
5588 THEN
5589 CLOSE kle_pur_amt_csr;
5590 END IF;
5591
5592 ROLLBACK TO asset_dispose;
5593 x_return_status := g_ret_sts_error;
5594 -- store the highest degree of error
5595 set_overall_status (p_return_status => x_return_status,
5596 px_overall_status => px_overall_status);
5597 -- set the transaction record
5598 set_transaction_rec (p_return_status => x_return_status,
5599 p_overall_status => px_overall_status,
5600 p_tmt_flag => 'TMT_ASSET_DISPOSITION_YN',
5601 p_tsu_code => 'ERROR',
5602 px_tcnv_rec => px_tcnv_rec
5603 );
5604 -- set the transaction record for amortization
5605 set_transaction_rec (p_return_status => x_return_status,
5606 p_overall_status => px_overall_status,
5607 p_tmt_flag => 'TMT_AMORTIZATION_YN',
5608 p_tsu_code => 'ERROR',
5609 p_ret_val => NULL,
5610 px_tcnv_rec => px_tcnv_rec
5611 );
5612 -- set the transaction record for asset return
5613 set_transaction_rec (p_return_status => x_return_status,
5614 p_overall_status => px_overall_status,
5615 p_tmt_flag => 'TMT_ASSET_RETURN_YN',
5616 p_tsu_code => 'ERROR',
5617 p_ret_val => NULL,
5618 px_tcnv_rec => px_tcnv_rec
5619 );
5620
5621 IF (is_debug_exception_on)
5622 THEN
5623 okl_debug_pub.log_debug (g_level_exception,
5624 l_module_name,
5625 'EXCEPTION :' || 'G_EXCEPTION_ERROR'
5626 );
5627 END IF;
5628 WHEN okl_api.g_exception_unexpected_error
5629 THEN
5630 -- Close any open cursors
5631 IF kle_pur_amt_csr%ISOPEN
5632 THEN
5633 CLOSE kle_pur_amt_csr;
5634 END IF;
5635
5636 ROLLBACK TO asset_dispose;
5637 x_return_status := g_ret_sts_unexp_error;
5638 -- store the highest degree of error
5639 set_overall_status (p_return_status => x_return_status,
5640 px_overall_status => px_overall_status);
5641 -- set the transaction record
5642 set_transaction_rec (p_return_status => x_return_status,
5643 p_overall_status => px_overall_status,
5644 p_tmt_flag => 'TMT_ASSET_DISPOSITION_YN',
5645 p_tsu_code => 'ERROR',
5646 px_tcnv_rec => px_tcnv_rec
5647 );
5648 -- set the transaction record for amortization
5649 set_transaction_rec (p_return_status => x_return_status,
5650 p_overall_status => px_overall_status,
5651 p_tmt_flag => 'TMT_AMORTIZATION_YN',
5652 p_tsu_code => 'ERROR',
5653 p_ret_val => NULL,
5654 px_tcnv_rec => px_tcnv_rec
5655 );
5656 -- set the transaction record for asset return
5657 set_transaction_rec (p_return_status => x_return_status,
5658 p_overall_status => px_overall_status,
5659 p_tmt_flag => 'TMT_ASSET_RETURN_YN',
5660 p_tsu_code => 'ERROR',
5661 p_ret_val => NULL,
5662 px_tcnv_rec => px_tcnv_rec
5663 );
5664
5665 IF (is_debug_exception_on)
5666 THEN
5667 okl_debug_pub.log_debug (g_level_exception,
5668 l_module_name,
5669 'EXCEPTION :'
5670 || 'G_EXCEPTION_UNEXPECTED_ERROR'
5671 );
5672 END IF;
5673 WHEN OTHERS
5674 THEN
5675 -- Close any open cursors
5676 IF kle_pur_amt_csr%ISOPEN
5677 THEN
5678 CLOSE kle_pur_amt_csr;
5679 END IF;
5680
5681 ROLLBACK TO asset_dispose;
5682 x_return_status := g_ret_sts_unexp_error;
5683 -- store the highest degree of error
5684 set_overall_status (p_return_status => x_return_status,
5685 px_overall_status => px_overall_status);
5686 -- set the transaction record
5687 set_transaction_rec (p_return_status => x_return_status,
5688 p_overall_status => px_overall_status,
5689 p_tmt_flag => 'TMT_ASSET_DISPOSITION_YN',
5690 p_tsu_code => 'ERROR',
5691 px_tcnv_rec => px_tcnv_rec
5692 );
5693 -- set the transaction record for amortization
5694 set_transaction_rec (p_return_status => x_return_status,
5695 p_overall_status => px_overall_status,
5696 p_tmt_flag => 'TMT_AMORTIZATION_YN',
5697 p_tsu_code => 'ERROR',
5698 p_ret_val => NULL,
5699 px_tcnv_rec => px_tcnv_rec
5700 );
5701 -- set the transaction record for asset return
5702 set_transaction_rec (p_return_status => x_return_status,
5703 p_overall_status => px_overall_status,
5704 p_tmt_flag => 'TMT_ASSET_RETURN_YN',
5705 p_tsu_code => 'ERROR',
5706 p_ret_val => NULL,
5707 px_tcnv_rec => px_tcnv_rec
5708 );
5709 -- Set the oracle error message
5710 okl_api.set_message (p_app_name => g_app_name_1,
5711 p_msg_name => g_unexpected_error,
5712 p_token1 => g_sqlcode_token,
5713 p_token1_value => SQLCODE,
5714 p_token2 => g_sqlerrm_token,
5715 p_token2_value => SQLERRM
5716 );
5717
5718 IF (is_debug_exception_on)
5719 THEN
5720 okl_debug_pub.log_debug (g_level_exception,
5721 l_module_name,
5722 'EXCEPTION :'
5723 || 'OTHERS, SQLCODE: '
5724 || SQLCODE
5725 || ' , SQLERRM : '
5726 || SQLERRM
5727 );
5728 END IF;
5729 END dispose_assets;
5730
5731 -- Start of comments
5732 --
5733 -- Procedure Name : delink_assets
5734 -- Desciption : Calls the FA adjustment API to delink the asset from contract
5735 -- Business Rules :
5736 -- Parameters :
5737 -- Version : 1.0
5738 -- History : AKRANGAN created
5739 --
5740 -- End of comments
5741 PROCEDURE delink_assets (
5742 p_term_rec IN term_rec_type,
5743 p_sys_date IN DATE,
5744 p_klev_tbl IN klev_tbl_type,
5745 p_trn_already_set IN VARCHAR2,
5746 px_overall_status IN OUT NOCOPY VARCHAR2,
5747 px_tcnv_rec IN OUT NOCOPY tcnv_rec_type,
5748 x_return_status OUT NOCOPY VARCHAR2
5749 )
5750 IS
5751 -- Get all the FA books (corp and tax) that asset belongs to
5752 CURSOR l_fabooks_csr (
5753 cp_asset_number IN VARCHAR2,
5754 cp_sysdate IN DATE
5755 )
5756 IS
5757 SELECT fb.book_type_code,
5758 fb.asset_id,
5759 fb.contract_id
5760 FROM fa_books fb,
5761 fa_additions_b fab,
5762 fa_book_controls fbc
5763 WHERE fb.asset_id = fab.asset_id
5764 AND fb.book_type_code = fbc.book_type_code
5765 AND NVL (fbc.date_ineffective, cp_sysdate + 1) > cp_sysdate
5766 AND fb.transaction_header_id_out IS NULL
5767 AND fab.asset_number = cp_asset_number;
5768
5769 l_return_status VARCHAR2 (1) := g_ret_sts_success;
5770 l_overall_status VARCHAR2 (1) := g_ret_sts_success;
5771 i NUMBER := 1;
5772 l_early_term_yn VARCHAR2 (1) := g_no;
5773 l_k_end_date DATE := g_miss_date;
5774 l_api_version CONSTANT NUMBER := g_api_version;
5775 l_msg_count NUMBER := g_miss_num;
5776 l_msg_data VARCHAR2 (2000);
5777 l_module_name VARCHAR2 (500)
5778 := g_module_name || 'delink_assets';
5779 is_debug_exception_on BOOLEAN
5780 := okl_debug_pub.check_log_on (l_module_name, g_level_exception);
5781 is_debug_procedure_on BOOLEAN
5782 := okl_debug_pub.check_log_on (l_module_name, g_level_procedure);
5783 is_debug_statement_on BOOLEAN
5784 := okl_debug_pub.check_log_on (l_module_name, g_level_statement);
5785 l_evergreen_earlier VARCHAR2 (3) := 'N';
5786 l_quote_accpt_date DATE;
5787 l_quote_eff_date DATE;
5788 l_asset_fin_rec_empty_adj fa_api_types.asset_fin_rec_type;
5789 l_asset_hdr_empty_rec fa_api_types.asset_hdr_rec_type;
5790 l_trans_empty_rec fa_api_types.trans_rec_type;
5791 l_adj_trans_rec fa_api_types.trans_rec_type;
5792 l_adj_asset_hdr_rec fa_api_types.asset_hdr_rec_type;
5793 l_asset_fin_rec_adj fa_api_types.asset_fin_rec_type;
5794 l_asset_fin_rec_new fa_api_types.asset_fin_rec_type;
5795 l_inv_trans_rec fa_api_types.inv_trans_rec_type;
5796 l_adj_inv_tbl fa_api_types.inv_tbl_type;
5797 l_asset_deprn_rec_adj fa_api_types.asset_deprn_rec_type;
5798 l_asset_deprn_rec_new fa_api_types.asset_deprn_rec_type;
5799 l_asset_deprn_mrc_tbl_new fa_api_types.asset_deprn_tbl_type;
5800 l_group_reclass_options_rec fa_api_types.group_reclass_options_rec_type;
5801 l_asset_fin_mrc_tbl_new fa_api_types.asset_fin_tbl_type;
5802 l_transaction_subtype VARCHAR2 (20);
5803 l_tmt_flag VARCHAR2 (50);
5804 BEGIN
5805 -- Start a savepoint
5806 SAVEPOINT asset_delink;
5807
5808 IF (is_debug_procedure_on)
5809 THEN
5810 okl_debug_pub.log_debug (g_level_procedure,
5811 l_module_name,
5812 'Begin(+)'
5813 );
5814 END IF;
5815
5816 IF (is_debug_statement_on)
5817 THEN
5818 okl_debug_pub.log_debug (g_level_statement,
5819 l_module_name,
5820 'In param, p_sys_date: ' || p_sys_date
5821 );
5822 okl_debug_pub.log_debug (g_level_statement,
5823 l_module_name,
5824 'In param, p_trn_already_set: '
5825 || p_trn_already_set
5826 );
5827 okl_debug_pub.log_debug (g_level_statement,
5828 l_module_name,
5829 'In param, px_overall_status: '
5830 || px_overall_status
5831 );
5832 okl_debug_pub.log_debug (g_level_statement,
5833 l_module_name,
5834 'In param, p_term_rec.p_quote_id: '
5835 || p_term_rec.p_quote_id
5836 );
5837 okl_debug_pub.log_debug (g_level_statement,
5838 l_module_name,
5839 'In param, p_term_rec.p_contract_id: '
5840 || p_term_rec.p_contract_id
5841 );
5842 okl_debug_pub.log_debug
5843 (g_level_statement,
5844 l_module_name,
5845 'In param, p_term_rec.p_contract_number: '
5846 || p_term_rec.p_contract_number
5847 );
5848 okl_debug_pub.log_debug
5849 (g_level_statement,
5850 l_module_name,
5851 'In param, px_tcnv_rec.tmt_amortization_yn: '
5852 || px_tcnv_rec.tmt_amortization_yn
5853 );
5854 okl_debug_pub.log_debug (g_level_statement,
5855 l_module_name,
5856 'In param, px_tcnv_rec.id: '
5857 || px_tcnv_rec.ID
5858 );
5859
5860 IF p_klev_tbl.COUNT > 0
5861 THEN
5862 FOR i IN p_klev_tbl.FIRST .. p_klev_tbl.LAST
5863 LOOP
5864 IF (p_klev_tbl.EXISTS (i))
5865 THEN
5866 okl_debug_pub.log_debug (g_level_statement,
5867 l_module_name,
5868 'In param, p_klev_tbl('
5869 || i
5870 || ').p_kle_id: '
5871 || p_klev_tbl (i).p_kle_id
5872 );
5873 okl_debug_pub.log_debug (g_level_statement,
5874 l_module_name,
5875 'In param, p_klev_tbl('
5876 || i
5877 || ').p_asset_name: '
5878 || p_klev_tbl (i).p_asset_name
5879 );
5880 END IF;
5881 END LOOP;
5882 END IF;
5883 END IF;
5884
5885 IF (is_debug_statement_on)
5886 THEN
5887 okl_debug_pub.log_debug
5888 (g_level_statement,
5889 l_module_name,
5890 'calling OKL_AM_LEASE_TRMNT_PVT.check_k_evergreen_ear'
5891 );
5892 END IF;
5893
5894 l_evergreen_earlier :=
5895 okl_am_lease_trmnt_pvt.check_k_evergreen_ear
5896 (p_khr_id => p_term_rec.p_contract_id,
5897 p_tcn_id => px_tcnv_rec.ID,
5898 x_return_status => l_return_status
5899 );
5900
5901 IF (is_debug_statement_on)
5902 THEN
5903 okl_debug_pub.log_debug
5904 (g_level_statement,
5905 l_module_name,
5906 'called OKL_AM_LEASE_TRMNT_PVT.check_k_evergreen_ear , return status: '
5907 || l_return_status
5908 );
5909 okl_debug_pub.log_debug (g_level_statement,
5910 l_module_name,
5911 'l_evergreen_earlier: '
5912 || l_evergreen_earlier
5913 );
5914 END IF;
5915
5916 IF l_return_status <> okl_api.g_ret_sts_success
5917 THEN
5918 -- Error occurred during the creation of an amortization transaction
5919 -- for assets of contract CONTRACT_NUMBER.
5920 okl_api.set_message (p_app_name => g_app_name,
5921 p_msg_name => 'OKL_AM_ERR_AMORTIZE',
5922 p_token1 => 'CONTRACT_NUMBER',
5923 p_token1_value => p_term_rec.p_contract_number
5924 );
5925 END IF;
5926
5927 -- If quote exists then cancelation date is quote eff from date else sysdate
5928 IF NVL (okl_am_lease_loan_trmnt_pvt.g_quote_exists, 'N') = 'Y'
5929 THEN
5930 l_quote_accpt_date :=
5931 okl_am_lease_loan_trmnt_pvt.g_quote_accept_date;
5932 l_quote_eff_date :=
5933 okl_am_lease_loan_trmnt_pvt.g_quote_eff_from_date;
5934 ELSE
5935 l_quote_accpt_date := p_sys_date;
5936 l_quote_eff_date := p_sys_date;
5937 END IF;
5938
5939 IF l_evergreen_earlier = 'Y'
5940 THEN
5941 l_transaction_subtype := '';
5942 l_tmt_flag := '';
5943 ELSE
5944 l_transaction_subtype := 'AMORTIZED';
5945 l_tmt_flag := 'TMT_AMORTIZATION_YN';
5946 END IF;
5947
5948 -- if assets present for contract
5949 IF (p_klev_tbl.COUNT > 0)
5950 THEN
5951 -- Loop thru assets table
5952 i := p_klev_tbl.FIRST;
5953
5954 LOOP
5955 FOR l_fabooks_rec IN l_fabooks_csr (p_klev_tbl (i).p_asset_name,
5956 l_quote_accpt_date)
5957 LOOP
5958 IF l_fabooks_rec.contract_id IS NOT NULL
5959 THEN
5960 l_asset_fin_rec_adj := l_asset_fin_rec_empty_adj;
5961 l_adj_trans_rec := l_trans_empty_rec;
5962 l_adj_asset_hdr_rec := l_asset_hdr_empty_rec;
5963 l_adj_trans_rec.transaction_subtype :=
5964 l_transaction_subtype;
5965 l_adj_asset_hdr_rec.asset_id := l_fabooks_rec.asset_id;
5966 l_adj_asset_hdr_rec.book_type_code :=
5967 l_fabooks_rec.book_type_code;
5968 l_asset_fin_rec_adj.contract_id := fnd_api.g_miss_num;
5969 l_adj_trans_rec.transaction_date_entered :=
5970 l_quote_eff_date;
5971 fa_adjustment_pub.do_adjustment
5972 (p_api_version => l_api_version,
5973 p_init_msg_list => okc_api.g_false,
5974 p_commit => fnd_api.g_false,
5975 p_validation_level => fnd_api.g_valid_level_full,
5976 p_calling_fn => NULL,
5977 x_return_status => l_return_status,
5978 x_msg_count => l_msg_count,
5979 x_msg_data => l_msg_data,
5980 px_trans_rec => l_adj_trans_rec,
5981 px_asset_hdr_rec => l_adj_asset_hdr_rec,
5982 p_asset_fin_rec_adj => l_asset_fin_rec_adj,
5983 x_asset_fin_rec_new => l_asset_fin_rec_new,
5984 x_asset_fin_mrc_tbl_new => l_asset_fin_mrc_tbl_new,
5985 px_inv_trans_rec => l_inv_trans_rec,
5986 px_inv_tbl => l_adj_inv_tbl,
5987 p_asset_deprn_rec_adj => l_asset_deprn_rec_adj,
5988 x_asset_deprn_rec_new => l_asset_deprn_rec_new,
5989 x_asset_deprn_mrc_tbl_new => l_asset_deprn_mrc_tbl_new,
5990 p_group_reclass_options_rec => l_group_reclass_options_rec
5991 );
5992
5993 IF l_return_status <> okc_api.g_ret_sts_success
5994 THEN
5995 -- Error processing TRX_TYPE transaction in Fixed Assets for asset ASSET_NUMBER in book BOOK.
5996 okc_api.set_message
5997 (p_app_name => 'OKL',
5998 p_msg_name => 'OKL_AM_AMT_TRANS_FAILED',
5999 p_token1 => 'TRX_TYPE',
6000 p_token1_value => 'Contract Delink',
6001 p_token2 => 'ASSET_NUMBER',
6002 p_token2_value => p_klev_tbl (i).p_asset_name,
6003 p_token3 => 'BOOK',
6004 p_token3_value => l_fabooks_rec.book_type_code
6005 );
6006 RAISE okl_api.g_exception_error;
6007 END IF;
6008 END IF;
6009 END LOOP;
6010
6011 EXIT WHEN (i = p_klev_tbl.LAST);
6012 i := p_klev_tbl.NEXT (i);
6013 END LOOP;
6014
6015 -- set the transaction record for asset return
6016 set_transaction_rec (p_return_status => l_return_status,
6017 p_overall_status => px_overall_status,
6018 p_tmt_flag => l_tmt_flag,
6019 p_tsu_code => 'WORKING',
6020 px_tcnv_rec => px_tcnv_rec
6021 );
6022 -- Set overall status
6023 set_overall_status (p_return_status => l_return_status,
6024 px_overall_status => px_overall_status);
6025 END IF;
6026
6027 IF (is_debug_procedure_on)
6028 THEN
6029 okl_debug_pub.log_debug (g_level_procedure,
6030 l_module_name,
6031 'End(-)'
6032 );
6033 END IF;
6034 EXCEPTION
6035 WHEN okl_api.g_exception_error
6036 THEN
6037 IF l_fabooks_csr%ISOPEN
6038 THEN
6039 CLOSE l_fabooks_csr;
6040 END IF;
6041
6042 ROLLBACK TO asset_delink;
6043 x_return_status := g_ret_sts_error;
6044 -- store the highest degree of error
6045 set_overall_status (p_return_status => x_return_status,
6046 px_overall_status => px_overall_status);
6047 -- set the transaction record
6048 set_transaction_rec (p_return_status => x_return_status,
6049 p_overall_status => px_overall_status,
6050 p_tmt_flag => l_tmt_flag,
6051 p_tsu_code => 'ERROR',
6052 px_tcnv_rec => px_tcnv_rec
6053 );
6054
6055 IF (is_debug_exception_on)
6056 THEN
6057 okl_debug_pub.log_debug (g_level_exception,
6058 l_module_name,
6059 'EXCEPTION :' || 'G_EXCEPTION_ERROR'
6060 );
6061 END IF;
6062 WHEN okl_api.g_exception_unexpected_error
6063 THEN
6064 IF l_fabooks_csr%ISOPEN
6065 THEN
6066 CLOSE l_fabooks_csr;
6067 END IF;
6068
6069 ROLLBACK TO asset_delink;
6070 x_return_status := g_ret_sts_unexp_error;
6071 -- store the highest degree of error
6072 set_overall_status (p_return_status => x_return_status,
6073 px_overall_status => px_overall_status);
6074 -- set the transaction record
6075 set_transaction_rec (p_return_status => x_return_status,
6076 p_overall_status => px_overall_status,
6077 p_tmt_flag => l_tmt_flag,
6078 p_tsu_code => 'ERROR',
6079 px_tcnv_rec => px_tcnv_rec
6080 );
6081
6082 IF (is_debug_exception_on)
6083 THEN
6084 okl_debug_pub.log_debug (g_level_exception,
6085 l_module_name,
6086 'EXCEPTION :'
6087 || 'G_EXCEPTION_UNEXPECTED_ERROR'
6088 );
6089 END IF;
6090 WHEN OTHERS
6091 THEN
6092 IF l_fabooks_csr%ISOPEN
6093 THEN
6094 CLOSE l_fabooks_csr;
6095 END IF;
6096
6097 ROLLBACK TO asset_delink;
6098 x_return_status := g_ret_sts_unexp_error;
6099 -- store the highest degree of error
6100 set_overall_status (p_return_status => x_return_status,
6101 px_overall_status => px_overall_status);
6102 -- set the transaction record
6103 set_transaction_rec (p_return_status => x_return_status,
6104 p_overall_status => px_overall_status,
6105 p_tmt_flag => l_tmt_flag,
6106 p_tsu_code => 'ERROR',
6107 px_tcnv_rec => px_tcnv_rec
6108 );
6109 -- Set the oracle error message
6110 okl_api.set_message (p_app_name => g_app_name_1,
6111 p_msg_name => g_unexpected_error,
6112 p_token1 => g_sqlcode_token,
6113 p_token1_value => SQLCODE,
6114 p_token2 => g_sqlerrm_token,
6115 p_token2_value => SQLERRM
6116 );
6117
6118 IF (is_debug_exception_on)
6119 THEN
6120 okl_debug_pub.log_debug (g_level_exception,
6121 l_module_name,
6122 'EXCEPTION :'
6123 || 'OTHERS, SQLCODE: '
6124 || SQLCODE
6125 || ' , SQLERRM : '
6126 || SQLERRM
6127 );
6128 END IF;
6129 END delink_assets;
6130
6131 -- Start of comments
6132 --
6133 -- Procedure Name : amortize_assets
6134 -- Desciption : Calls the Amortization API to amortize assets of contract
6135 -- Business Rules :
6136 -- Parameters :
6137 -- Version : 1.0
6138 -- History : RMUNJULU 06-MAR-03 Performance Fix Replaced K_HDR_FULL
6139 -- : RMUNJULU 3485854 12-MAR-04 Added code to check contract was
6140 -- EVERGREEN earlier, if so then amortization was done, DO NOT do again
6141 -- : rmunjulu EDAT Added code to get the quote eff date and check for early term based on that
6142 -- Also pass quote eff date and quote acceptance date to amortize api
6143 -- : SECHAWLA 14-dec-07 6690811 - Delink contract ID from FA asset, upon partial termination of
6144 -- Booked or Evergreen contract.
6145 -- : SECHAWLA 02-Jan-08 6720667 - Check if contract ID is already null, before updating it to Null
6146 --
6147 -- End of comments
6148 PROCEDURE amortize_assets (
6149 p_term_rec IN term_rec_type,
6150 p_sys_date IN DATE,
6151 p_klev_tbl IN klev_tbl_type,
6152 p_trn_already_set IN VARCHAR2,
6153 px_overall_status IN OUT NOCOPY VARCHAR2,
6154 px_tcnv_rec IN OUT NOCOPY tcnv_rec_type,
6155 x_return_status OUT NOCOPY VARCHAR2
6156 )
6157 IS
6158 -- Cursor to get the end date of contract
6159 -- RMUNJULU 06-MAR-03 Performance Fix Replaced K_HDR_FULL
6160 CURSOR get_k_end_date_csr (
6161 p_khr_id IN NUMBER
6162 )
6163 IS
6164 SELECT khr.end_date end_date
6165 FROM okc_k_headers_v khr
6166 WHERE khr.ID = p_khr_id;
6167
6168 l_return_status VARCHAR2 (1) := g_ret_sts_success;
6169 l_overall_status VARCHAR2 (1) := g_ret_sts_success;
6170 i NUMBER := 1;
6171 l_early_term_yn VARCHAR2 (1) := g_no;
6172 l_k_end_date DATE := g_miss_date;
6173 l_api_version CONSTANT NUMBER := g_api_version;
6174 l_msg_count NUMBER := g_miss_num;
6175 l_msg_data VARCHAR2 (2000);
6176 l_module_name VARCHAR2 (500)
6177 := g_module_name || 'amortize_assets';
6178 is_debug_exception_on BOOLEAN
6179 := okl_debug_pub.check_log_on (l_module_name, g_level_exception);
6180 is_debug_procedure_on BOOLEAN
6181 := okl_debug_pub.check_log_on (l_module_name, g_level_procedure);
6182 is_debug_statement_on BOOLEAN
6183 := okl_debug_pub.check_log_on (l_module_name, g_level_statement);
6184 -- RMUNJULU 3485854
6185 l_evergreen_earlier VARCHAR2 (3) := 'N';
6186 -- rmunjulu EDAT
6187 l_quote_accpt_date DATE;
6188 l_quote_eff_date DATE;
6189 BEGIN
6190 -- Start a savepoint
6191 SAVEPOINT asset_amortize;
6192
6193 IF (is_debug_procedure_on)
6194 THEN
6195 okl_debug_pub.log_debug (g_level_procedure,
6196 l_module_name,
6197 'Begin(+)'
6198 );
6199 END IF;
6200
6201 IF (is_debug_statement_on)
6202 THEN
6203 okl_debug_pub.log_debug (g_level_statement,
6204 l_module_name,
6205 'In param, p_sys_date: ' || p_sys_date
6206 );
6207 okl_debug_pub.log_debug (g_level_statement,
6208 l_module_name,
6209 'In param, p_trn_already_set: '
6210 || p_trn_already_set
6211 );
6212 okl_debug_pub.log_debug (g_level_statement,
6213 l_module_name,
6214 'In param, px_overall_status: '
6215 || px_overall_status
6216 );
6217 okl_debug_pub.log_debug (g_level_statement,
6218 l_module_name,
6219 'In param, p_term_rec.p_quote_id: '
6220 || p_term_rec.p_quote_id
6221 );
6222 okl_debug_pub.log_debug (g_level_statement,
6223 l_module_name,
6224 'In param, p_term_rec.p_contract_id: '
6225 || p_term_rec.p_contract_id
6226 );
6227 okl_debug_pub.log_debug
6228 (g_level_statement,
6229 l_module_name,
6230 'In param, p_term_rec.p_contract_number: '
6231 || p_term_rec.p_contract_number
6232 );
6233 okl_debug_pub.log_debug
6234 (g_level_statement,
6235 l_module_name,
6236 'In param, px_tcnv_rec.tmt_amortization_yn: '
6237 || px_tcnv_rec.tmt_amortization_yn
6238 );
6239 okl_debug_pub.log_debug (g_level_statement,
6240 l_module_name,
6241 'In param, px_tcnv_rec.id: '
6242 || px_tcnv_rec.ID
6243 );
6244
6245 IF p_klev_tbl.COUNT > 0
6246 THEN
6247 FOR i IN p_klev_tbl.FIRST .. p_klev_tbl.LAST
6248 LOOP
6249 IF (p_klev_tbl.EXISTS (i))
6250 THEN
6251 okl_debug_pub.log_debug (g_level_statement,
6252 l_module_name,
6253 'In param, p_klev_tbl('
6254 || i
6255 || ').p_kle_id: '
6256 || p_klev_tbl (i).p_kle_id
6257 );
6258 okl_debug_pub.log_debug (g_level_statement,
6259 l_module_name,
6260 'In param, p_klev_tbl('
6261 || i
6262 || ').p_asset_name: '
6263 || p_klev_tbl (i).p_asset_name
6264 );
6265 END IF;
6266 END LOOP;
6267 END IF;
6268 END IF;
6269
6270 -- Check if amortization required
6271 IF ( p_trn_already_set = g_yes
6272 AND NVL (px_tcnv_rec.tmt_amortization_yn, '?') <> g_yes
6273 )
6274 OR (p_trn_already_set = g_no)
6275 THEN
6276
6277 -- rmunjulu bug 7009808 Set the variables outside so that delink can use the values
6278 -- If quote exists then cancelation date is quote eff from date else sysdate
6279 IF NVL (okl_am_lease_loan_trmnt_pvt.g_quote_exists, 'N') = 'Y'
6280 THEN
6281 l_quote_accpt_date :=
6282 okl_am_lease_loan_trmnt_pvt.g_quote_accept_date;
6283 l_quote_eff_date :=
6284 okl_am_lease_loan_trmnt_pvt.g_quote_eff_from_date;
6285 ELSE
6286 l_quote_accpt_date := p_sys_date;
6287 l_quote_eff_date := p_sys_date;
6288 END IF;
6289
6290
6291
6292 -- RMUNJULU 3485854
6293 -- CHECK TO see IF old evergreen transaction exists
6294 -- Check if another transaction exists which is processed and for which tmt_evergreen_yn was Y
6295 -- which means this contract was evergreen earlier
6296 -- so no need to run amortization again
6297 IF (is_debug_statement_on)
6298 THEN
6299 okl_debug_pub.log_debug
6300 (g_level_statement,
6301 l_module_name,
6302 'calling OKL_AM_LEASE_TRMNT_PVT.check_k_evergreen_ear'
6303 );
6304 END IF;
6305
6306 l_evergreen_earlier :=
6307 okl_am_lease_trmnt_pvt.check_k_evergreen_ear
6308 (p_khr_id => p_term_rec.p_contract_id,
6309 p_tcn_id => px_tcnv_rec.ID,
6310 x_return_status => l_return_status
6311 );
6312
6313 IF (is_debug_statement_on)
6314 THEN
6315 okl_debug_pub.log_debug
6316 (g_level_statement,
6317 l_module_name,
6318 'called OKL_AM_LEASE_TRMNT_PVT.check_k_evergreen_ear , return status: '
6319 || l_return_status
6320 );
6321 okl_debug_pub.log_debug (g_level_statement,
6322 l_module_name,
6323 'l_evergreen_earlier: '
6324 || l_evergreen_earlier
6325 );
6326 END IF;
6327
6328 IF l_return_status <> okl_api.g_ret_sts_success
6329 THEN
6330 -- Error occurred during the creation of an amortization transaction
6331 -- for assets of contract CONTRACT_NUMBER.
6332 okl_api.set_message
6333 (p_app_name => g_app_name,
6334 p_msg_name => 'OKL_AM_ERR_AMORTIZE',
6335 p_token1 => 'CONTRACT_NUMBER',
6336 p_token1_value => p_term_rec.p_contract_number
6337 );
6338 END IF;
6339
6340 -- RMUNJULU 3485854
6341 -- Check to make sure amortization was not done
6342 IF NVL (l_evergreen_earlier, 'N') <> 'Y'
6343 THEN
6344 -- RMUNJULU 3018641 Step Message
6345 -- Step : Amortization
6346 okl_api.set_message (p_app_name => g_app_name,
6347 p_msg_name => 'OKL_AM_STEP_AMT');
6348
6349 -- get k end date
6350 OPEN get_k_end_date_csr (p_term_rec.p_contract_id);
6351
6352 FETCH get_k_end_date_csr
6353 INTO l_k_end_date;
6354
6355 CLOSE get_k_end_date_csr;
6356
6357 -- rmunjulu +++++++++ Effective Dated Termination -- start ++++++++++++++++
6358
6359 -- rmunjulu EDAT
6360 -- If quote exists then cancelation date is quote eff from date else sysdate
6361 IF NVL (okl_am_lease_loan_trmnt_pvt.g_quote_exists, 'N') = 'Y'
6362 THEN
6363 l_quote_accpt_date :=
6364 okl_am_lease_loan_trmnt_pvt.g_quote_accept_date;
6365 l_quote_eff_date :=
6366 okl_am_lease_loan_trmnt_pvt.g_quote_eff_from_date;
6367 ELSE
6368 l_quote_accpt_date := p_sys_date;
6369 l_quote_eff_date := p_sys_date;
6370 END IF;
6371
6372 -- rmunjulu +++++++++ Effective Dated Termination -- end ++++++++++++++++
6373
6374 -- Set early termination yn flag
6375 IF (l_k_end_date <> g_miss_date)
6376 AND (TRUNC (l_k_end_date) > TRUNC (l_quote_eff_date))
6377 THEN
6378 -- rmunjulu EDAT Check based on quote eff date
6379 l_early_term_yn := g_yes;
6380 END IF;
6381
6382 -- if assets present for contract
6383 IF (p_klev_tbl.COUNT > 0)
6384 THEN
6385 -- Loop thru assets table
6386 i := p_klev_tbl.FIRST;
6387
6388 LOOP
6389 IF (is_debug_statement_on)
6390 THEN
6391 okl_debug_pub.log_debug
6392 (g_level_statement,
6393 l_module_name,
6394 'calling OKL_AM_AMORTIZE_PUB.create_offlease_asset_trx'
6395 );
6396 END IF;
6397
6398 -- call amortization
6399 okl_am_amortize_pub.create_offlease_asset_trx
6400 (p_api_version => l_api_version,
6401 p_init_msg_list => g_false,
6402 x_return_status => l_return_status,
6403 x_msg_count => l_msg_count,
6404 x_msg_data => l_msg_data,
6405 p_kle_id => p_klev_tbl (i).p_kle_id,
6406 p_early_termination_yn => l_early_term_yn,
6407 p_quote_eff_date => l_quote_eff_date,
6408 -- rmunjulu EDAT
6409 p_quote_accpt_date => l_quote_accpt_date
6410 ); -- rmunjulu EDAT
6411
6412 IF (is_debug_statement_on)
6413 THEN
6414 okl_debug_pub.log_debug
6415 (g_level_statement,
6416 l_module_name,
6417 'called OKL_AM_AMORTIZE_PUB.create_offlease_asset_trx , return status: '
6418 || l_return_status
6419 );
6420 END IF;
6421
6422 IF l_return_status <> g_ret_sts_success
6423 THEN
6424 -- Error occurred during the amortization process for asset NAME.
6425 okl_api.set_message
6426 (p_app_name => g_app_name,
6427 p_msg_name => 'OKL_AM_ERR_LNS_AMORTIZE',
6428 p_token1 => 'NAME',
6429 p_token1_value => p_klev_tbl (i).p_asset_name
6430 );
6431 -- Raise exception to rollback to savepoint if error
6432 RAISE okl_api.g_exception_error;
6433 END IF;
6434
6435 EXIT WHEN (i = p_klev_tbl.LAST);
6436 i := p_klev_tbl.NEXT (i);
6437 END LOOP;
6438
6439 -- set the transaction record for asset return
6440 set_transaction_rec (p_return_status => l_return_status,
6441 p_overall_status => px_overall_status,
6442 p_tmt_flag => 'TMT_AMORTIZATION_YN',
6443 p_tsu_code => 'WORKING',
6444 px_tcnv_rec => px_tcnv_rec
6445 );
6446 -- Set overall status
6447 set_overall_status (p_return_status => l_return_status,
6448 px_overall_status => px_overall_status);
6449 END IF;
6450 END IF;
6451
6452 -- rmunjulu bug 6853566 make call to delink contract from here
6453 -- This call will always be made if amortize is supposed to be run
6454 --
6455 OKL_AM_LEASE_TRMNT_PVT.delink_contract_from_asset(
6456 p_api_version => l_api_version,
6457 x_msg_count => l_msg_count,
6458 x_msg_data => l_msg_data,
6459 p_full_term_yn => 'N', -- not full termination but partial
6460 p_khr_id => p_term_rec.p_contract_id,
6461 p_klev_tbl => p_klev_tbl,
6462 --p_sts_code => l_dummy_sts_code,
6463 p_quote_accpt_date => l_quote_accpt_date,
6464 p_quote_eff_date => l_quote_eff_date,
6465 x_return_status => l_return_status);
6466
6467 IF l_return_status <> g_ret_sts_success THEN
6468 -- Error occurred during the amortization process for asset NAME.
6469 okl_api.set_message
6470 (p_app_name => g_app_name,
6471 p_msg_name => 'OKL_AM_ERR_LNS_AMORTIZE',
6472 p_token1 => 'NAME',
6473 p_token1_value => p_klev_tbl (i).p_asset_name
6474 );
6475 -- Raise exception to rollback to savepoint if error
6476 RAISE okl_api.g_exception_error;
6477 END IF;
6478
6479 -- set the transaction record for asset return
6480 set_transaction_rec (p_return_status => l_return_status,
6481 p_overall_status => px_overall_status,
6482 p_tmt_flag => 'TMT_AMORTIZATION_YN',
6483 p_tsu_code => 'WORKING',
6484 px_tcnv_rec => px_tcnv_rec
6485 );
6486 -- Set overall status
6487 set_overall_status (p_return_status => l_return_status,
6488 px_overall_status => px_overall_status);
6489 END IF;
6490
6491 IF (is_debug_procedure_on)
6492 THEN
6493 okl_debug_pub.log_debug (g_level_procedure,
6494 l_module_name,
6495 'End(-)'
6496 );
6497 END IF;
6498
6499 --SET THE AMORTIZATION FLAG
6500 g_amort_complete_flag := 'Y';
6501 EXCEPTION
6502 WHEN okl_api.g_exception_error
6503 THEN
6504 IF get_k_end_date_csr%ISOPEN
6505 THEN
6506 CLOSE get_k_end_date_csr;
6507 END IF;
6508
6509 ROLLBACK TO asset_amortize;
6510 x_return_status := g_ret_sts_error;
6511 -- store the highest degree of error
6512 set_overall_status (p_return_status => x_return_status,
6513 px_overall_status => px_overall_status);
6514 -- set the transaction record
6515 set_transaction_rec (p_return_status => x_return_status,
6516 p_overall_status => px_overall_status,
6517 p_tmt_flag => 'TMT_AMORTIZATION_YN',
6518 p_tsu_code => 'ERROR',
6519 px_tcnv_rec => px_tcnv_rec
6520 );
6521 -- set the transaction record
6522 set_transaction_rec (p_return_status => x_return_status,
6523 p_overall_status => px_overall_status,
6524 p_tmt_flag => 'TMT_ASSET_DISPOSITION_YN',
6525 p_tsu_code => 'ERROR',
6526 p_ret_val => NULL,
6527 px_tcnv_rec => px_tcnv_rec
6528 );
6529 g_amort_complete_flag := 'N';
6530
6531 IF (is_debug_exception_on)
6532 THEN
6533 okl_debug_pub.log_debug (g_level_exception,
6534 l_module_name,
6535 'EXCEPTION :' || 'G_EXCEPTION_ERROR'
6536 );
6537 END IF;
6538 WHEN okl_api.g_exception_unexpected_error
6539 THEN
6540 IF get_k_end_date_csr%ISOPEN
6541 THEN
6542 CLOSE get_k_end_date_csr;
6543 END IF;
6544
6545 ROLLBACK TO asset_amortize;
6546 x_return_status := g_ret_sts_unexp_error;
6547 -- store the highest degree of error
6548 set_overall_status (p_return_status => x_return_status,
6549 px_overall_status => px_overall_status);
6550 -- set the transaction record
6551 set_transaction_rec (p_return_status => x_return_status,
6552 p_overall_status => px_overall_status,
6553 p_tmt_flag => 'TMT_AMORTIZATION_YN',
6554 p_tsu_code => 'ERROR',
6555 px_tcnv_rec => px_tcnv_rec
6556 );
6557 -- set the transaction record
6558 set_transaction_rec (p_return_status => x_return_status,
6559 p_overall_status => px_overall_status,
6560 p_tmt_flag => 'TMT_ASSET_DISPOSITION_YN',
6561 p_tsu_code => 'ERROR',
6562 p_ret_val => NULL,
6563 px_tcnv_rec => px_tcnv_rec
6564 );
6565 g_amort_complete_flag := 'N';
6566
6567 IF (is_debug_exception_on)
6568 THEN
6569 okl_debug_pub.log_debug (g_level_exception,
6570 l_module_name,
6571 'EXCEPTION :'
6572 || 'G_EXCEPTION_UNEXPECTED_ERROR'
6573 );
6574 END IF;
6575 WHEN OTHERS
6576 THEN
6577 IF get_k_end_date_csr%ISOPEN
6578 THEN
6579 CLOSE get_k_end_date_csr;
6580 END IF;
6581
6582 ROLLBACK TO asset_amortize;
6583 x_return_status := g_ret_sts_unexp_error;
6584 -- store the highest degree of error
6585 set_overall_status (p_return_status => x_return_status,
6586 px_overall_status => px_overall_status);
6587 -- set the transaction record
6588 set_transaction_rec (p_return_status => x_return_status,
6589 p_overall_status => px_overall_status,
6590 p_tmt_flag => 'TMT_AMORTIZATION_YN',
6591 p_tsu_code => 'ERROR',
6592 px_tcnv_rec => px_tcnv_rec
6593 );
6594 -- set the transaction record
6595 set_transaction_rec (p_return_status => x_return_status,
6596 p_overall_status => px_overall_status,
6597 p_tmt_flag => 'TMT_ASSET_DISPOSITION_YN',
6598 p_tsu_code => 'ERROR',
6599 p_ret_val => NULL,
6600 px_tcnv_rec => px_tcnv_rec
6601 );
6602 -- Set the oracle error message
6603 okl_api.set_message (p_app_name => g_app_name_1,
6604 p_msg_name => g_unexpected_error,
6605 p_token1 => g_sqlcode_token,
6606 p_token1_value => SQLCODE,
6607 p_token2 => g_sqlerrm_token,
6608 p_token2_value => SQLERRM
6609 );
6610 g_amort_complete_flag := 'N';
6611
6612 IF (is_debug_exception_on)
6613 THEN
6614 okl_debug_pub.log_debug (g_level_exception,
6615 l_module_name,
6616 'EXCEPTION :'
6617 || 'OTHERS, SQLCODE: '
6618 || SQLCODE
6619 || ' , SQLERRM : '
6620 || SQLERRM
6621 );
6622 END IF;
6623 END amortize_assets;
6624
6625 -- Start of comments
6626 --
6627 -- Procedure Name : return_assets
6628 -- Desciption : Calls the Asset Return API to return assets of contract
6629 -- Business Rules :
6630 -- Parameters :
6631 -- Version : 1.0
6632 -- History : rmunjulu EDAT modified code to check for quote exists to set reason code
6633 -- : PAGARG Bug# 3925453: Set the asset return status as
6634 -- 'RELEASE_IN_PROCESS' for quote type TER_RELEASE_WO_PURCHASE.
6635 -- End of comments
6636 PROCEDURE return_assets (
6637 p_term_rec IN term_rec_type,
6638 p_sys_date IN DATE,
6639 p_klev_tbl IN klev_tbl_type,
6640 p_trn_already_set IN VARCHAR2,
6641 px_overall_status IN OUT NOCOPY VARCHAR2,
6642 px_tcnv_rec IN OUT NOCOPY tcnv_rec_type,
6643 x_return_status OUT NOCOPY VARCHAR2
6644 )
6645 IS
6646 -- Get the non-cancelled asset return for asset
6647 CURSOR get_asset_return_csr (
6648 p_kle_id IN NUMBER
6649 )
6650 IS
6651 SELECT arr.ID ID,
6652 okl_am_util_pvt.get_lookup_meaning ('OKL_ASSET_RETURN_STATUS',
6653 arr.ars_code,
6654 'N'
6655 ) ret_status
6656 FROM okl_asset_returns_v arr
6657 WHERE arr.kle_id = p_kle_id AND arr.ars_code <> 'CANCELLED';
6658
6659 l_return_status VARCHAR2 (1) := g_ret_sts_success;
6660 l_overall_status VARCHAR2 (1) := g_ret_sts_success;
6661 lp_artv_rec okl_am_asset_return_pub.artv_rec_type;
6662 lx_artv_rec okl_am_asset_return_pub.artv_rec_type;
6663 i NUMBER := 1;
6664 j NUMBER := 1;
6665 l_kle_id NUMBER;
6666 l_k_end_date DATE := g_miss_date;
6667 l_return_needed VARCHAR2 (1) := g_no;
6668 l_asset_return_status VARCHAR2 (2000);
6669 l_temp_klev_tbl klev_tbl_type;
6670 l_api_version CONSTANT NUMBER := g_api_version;
6671 l_msg_count NUMBER := g_miss_num;
6672 l_msg_data VARCHAR2 (2000);
6673 l_module_name VARCHAR2 (500)
6674 := g_module_name || 'return_assets';
6675 is_debug_exception_on BOOLEAN
6676 := okl_debug_pub.check_log_on (l_module_name, g_level_exception);
6677 is_debug_procedure_on BOOLEAN
6678 := okl_debug_pub.check_log_on (l_module_name, g_level_procedure);
6679 is_debug_statement_on BOOLEAN
6680 := okl_debug_pub.check_log_on (l_module_name, g_level_statement);
6681 -- rmunjulu EDAT
6682 l_quote_accpt_date DATE;
6683 l_quote_eff_date DATE;
6684 BEGIN
6685 SAVEPOINT asset_return;
6686
6687 IF (is_debug_procedure_on)
6688 THEN
6689 okl_debug_pub.log_debug (g_level_procedure,
6690 l_module_name,
6691 'Begin(+)'
6692 );
6693 END IF;
6694
6695 IF (is_debug_statement_on)
6696 THEN
6697 okl_debug_pub.log_debug (g_level_statement,
6698 l_module_name,
6699 'In param, p_sys_date: ' || p_sys_date
6700 );
6701 okl_debug_pub.log_debug (g_level_statement,
6702 l_module_name,
6703 'In param, p_trn_already_set: '
6704 || p_trn_already_set
6705 );
6706 okl_debug_pub.log_debug (g_level_statement,
6707 l_module_name,
6708 'In param, px_overall_status: '
6709 || px_overall_status
6710 );
6711 okl_debug_pub.log_debug (g_level_statement,
6712 l_module_name,
6713 'In param, p_term_rec.p_quote_type: '
6714 || p_term_rec.p_quote_type
6715 );
6716 okl_debug_pub.log_debug (g_level_statement,
6717 l_module_name,
6718 'In param, p_term_rec.p_quote_id: '
6719 || p_term_rec.p_quote_id
6720 );
6721 okl_debug_pub.log_debug
6722 (g_level_statement,
6723 l_module_name,
6724 'In param, px_tcnv_rec.tmt_asset_return_yn: '
6725 || px_tcnv_rec.tmt_asset_return_yn
6726 );
6727
6728 IF p_klev_tbl.COUNT > 0
6729 THEN
6730 FOR i IN p_klev_tbl.FIRST .. p_klev_tbl.LAST
6731 LOOP
6732 IF (p_klev_tbl.EXISTS (i))
6733 THEN
6734 okl_debug_pub.log_debug (g_level_statement,
6735 l_module_name,
6736 'In param, p_klev_tbl('
6737 || i
6738 || ').p_kle_id: '
6739 || p_klev_tbl (i).p_kle_id
6740 );
6741 okl_debug_pub.log_debug (g_level_statement,
6742 l_module_name,
6743 'In param, p_klev_tbl('
6744 || i
6745 || ').p_asset_name: '
6746 || p_klev_tbl (i).p_asset_name
6747 );
6748 END IF;
6749 END LOOP;
6750 END IF;
6751 END IF;
6752
6753 -- Check if asset return required
6754 IF ( p_trn_already_set = g_yes
6755 AND NVL (px_tcnv_rec.tmt_asset_return_yn, '?') <> g_yes
6756 )
6757 OR (p_trn_already_set = g_no)
6758 THEN
6759 -- RMUNJULU 3018641 Step Message
6760 -- Step : Asset Return
6761 okl_api.set_message (p_app_name => g_app_name,
6762 p_msg_name => 'OKL_AM_STEP_ART');
6763
6764 -- rmunjulu +++++++++ Effective Dated Termination -- start ++++++++++++++++
6765
6766 -- rmunjulu EDAT
6767 -- If quote exists then accnting date is quote accept date else sysdate
6768 IF NVL (okl_am_lease_loan_trmnt_pvt.g_quote_exists, 'N') = 'Y'
6769 THEN
6770 l_quote_accpt_date :=
6771 okl_am_lease_loan_trmnt_pvt.g_quote_accept_date;
6772 l_quote_eff_date :=
6773 okl_am_lease_loan_trmnt_pvt.g_quote_eff_from_date;
6774 ELSE
6775 l_quote_accpt_date := p_sys_date;
6776 l_quote_eff_date := p_sys_date;
6777 END IF;
6778
6779 -- rmunjulu +++++++++ Effective Dated Termination -- end ++++++++++++++++
6780
6781 -- if assets present for contract
6782 IF (p_klev_tbl.COUNT > 0)
6783 THEN
6784 -- Loop thru assets table
6785 i := p_klev_tbl.FIRST;
6786
6787 LOOP
6788 l_return_needed := g_no;
6789
6790 -- Check if return created
6791 OPEN get_asset_return_csr (p_klev_tbl (i).p_kle_id);
6792
6793 FETCH get_asset_return_csr
6794 INTO l_kle_id,
6795 l_asset_return_status;
6796
6797 IF get_asset_return_csr%NOTFOUND OR l_kle_id IS NULL
6798 THEN
6799 l_return_needed := g_yes;
6800 END IF;
6801
6802 CLOSE get_asset_return_csr;
6803
6804 -- if no return try creating else set message
6805 IF l_return_needed = g_yes
6806 THEN
6807 -- set the temp table to contain all assets returned NOW
6808 l_temp_klev_tbl (j).p_kle_id := p_klev_tbl (i).p_kle_id;
6809 l_temp_klev_tbl (j).p_asset_name :=
6810 p_klev_tbl (i).p_asset_name;
6811 j := j + 1;
6812 -- set the asset return id
6813 lp_artv_rec.kle_id := p_klev_tbl (i).p_kle_id;
6814
6815 -- set the art1_code for asset return 'OKL_ASSET_RETURN_TYPE'
6816 -- if early termination assume from quote else contract exp
6817 -- IF (l_k_end_date <> OKL_API.G_MISS_DATE)
6818 -- AND (TRUNC(l_k_end_date) < TRUNC(p_sys_date)) THEN
6819 -- rmunjulu EDAT modified condition to say if quote exists then EXE_TERMINATION_QUOTE else EXPIRATION
6820 IF NVL (okl_am_lease_loan_trmnt_pvt.g_quote_exists, 'N') =
6821 'Y'
6822 THEN
6823 -- rmunjulu EDAT
6824 lp_artv_rec.art1_code := 'EXE_TERMINATION_QUOTE';
6825 ELSE
6826 lp_artv_rec.art1_code := 'CONTRACT_EXPIRATION';
6827 END IF;
6828
6829 --Bug# 3925453: pagarg +++ T and A +++++++ Start ++++++++++
6830 IF p_term_rec.p_quote_type = 'TER_RELEASE_WO_PURCHASE'
6831 THEN
6832 lp_artv_rec.ars_code := 'RELEASE_IN_PROCESS';
6833 ELSE
6834 -- set the ars_code for asset return 'OKL_ASSET_RETURN_STATUS'
6835 lp_artv_rec.ars_code := 'SCHEDULED';
6836 END IF;
6837
6838 --Bug# 3925453: pagarg +++ T and A +++++++ End ++++++++++
6839
6840 --Bug #3925453: pagarg +++ T and A ++++
6841 -- Passing quote_id also to create_asset_return
6842 -- call asset return
6843 IF (is_debug_statement_on)
6844 THEN
6845 okl_debug_pub.log_debug
6846 (g_level_statement,
6847 l_module_name,
6848 'calling OKL_AM_ASSET_RETURN_PUB.create_asset_return'
6849 );
6850 END IF;
6851
6852 okl_am_asset_return_pub.create_asset_return
6853 (p_api_version => l_api_version,
6854 p_init_msg_list => g_false,
6855 x_return_status => l_return_status,
6856 x_msg_count => l_msg_count,
6857 x_msg_data => l_msg_data,
6858 p_artv_rec => lp_artv_rec,
6859 x_artv_rec => lx_artv_rec,
6860 p_quote_id => p_term_rec.p_quote_id
6861 );
6862
6863 IF (is_debug_statement_on)
6864 THEN
6865 okl_debug_pub.log_debug
6866 (g_level_statement,
6867 l_module_name,
6868 'called OKL_AM_ASSET_RETURN_PUB.create_asset_return , return status: '
6869 || l_return_status
6870 );
6871 END IF;
6872
6873 IF l_return_status <> g_ret_sts_success
6874 THEN
6875 -- Error occurred during the creation of an asset
6876 -- return record for asset NAME.
6877 okl_api.set_message
6878 (p_app_name => g_app_name,
6879 p_msg_name => 'OKL_AM_ERR_ASS_RET',
6880 p_token1 => 'NAME',
6881 p_token1_value => p_klev_tbl (i).p_asset_name
6882 );
6883 -- Raise exception to rollback to savepoint if error
6884 RAISE okl_api.g_exception_error;
6885 END IF;
6886 ELSE
6887 -- Asset return already exists -- This is not an error
6888
6889 -- Asset Return already exists for this asset NAME with the
6890 -- status STATUS so cannot create a new asset return now.
6891 okl_api.set_message
6892 (p_app_name => g_app_name,
6893 p_msg_name => 'OKL_AM_ASS_RET_ARS_ERR',
6894 p_token1 => 'NAME',
6895 p_token1_value => p_klev_tbl (i).p_asset_name,
6896 p_token2 => 'STATUS',
6897 p_token2_value => l_asset_return_status
6898 );
6899 END IF;
6900
6901 EXIT WHEN (i = p_klev_tbl.LAST);
6902 i := p_klev_tbl.NEXT (i);
6903 END LOOP;
6904
6905 -- Set success messages once all returns done NOW
6906 IF l_temp_klev_tbl.COUNT > 0
6907 THEN
6908 i := l_temp_klev_tbl.FIRST;
6909
6910 LOOP
6911 -- Asset return created for asset NAME.
6912 okl_api.set_message
6913 (p_app_name => g_app_name,
6914 p_msg_name => 'OKL_AM_ASS_RET_CREATED',
6915 p_token1 => 'NAME',
6916 p_token1_value => l_temp_klev_tbl (i).p_asset_name
6917 );
6918 EXIT WHEN (i = l_temp_klev_tbl.LAST);
6919 i := l_temp_klev_tbl.NEXT (i);
6920 END LOOP;
6921 END IF;
6922
6923 -- set the transaction record for asset return
6924 set_transaction_rec (p_return_status => l_return_status,
6925 p_overall_status => px_overall_status,
6926 p_tmt_flag => 'TMT_ASSET_RETURN_YN',
6927 p_tsu_code => 'WORKING',
6928 px_tcnv_rec => px_tcnv_rec
6929 );
6930 -- Set overall status
6931 set_overall_status (p_return_status => l_return_status,
6932 px_overall_status => px_overall_status);
6933 END IF;
6934 END IF;
6935
6936 IF (is_debug_procedure_on)
6937 THEN
6938 okl_debug_pub.log_debug (g_level_procedure,
6939 l_module_name,
6940 'End(-)'
6941 );
6942 END IF;
6943 EXCEPTION
6944 WHEN okl_api.g_exception_error
6945 THEN
6946 IF get_asset_return_csr%ISOPEN
6947 THEN
6948 CLOSE get_asset_return_csr;
6949 END IF;
6950
6951 ROLLBACK TO asset_return;
6952 x_return_status := g_ret_sts_error;
6953 -- store the highest degree of error
6954 set_overall_status (p_return_status => x_return_status,
6955 px_overall_status => px_overall_status);
6956 -- set the transaction record
6957 set_transaction_rec (p_return_status => x_return_status,
6958 p_overall_status => px_overall_status,
6959 p_tmt_flag => 'TMT_ASSET_RETURN_YN',
6960 p_tsu_code => 'ERROR',
6961 px_tcnv_rec => px_tcnv_rec
6962 );
6963 -- set the transaction record
6964 set_transaction_rec (p_return_status => x_return_status,
6965 p_overall_status => px_overall_status,
6966 p_tmt_flag => 'TMT_ASSET_DISPOSITION_YN',
6967 p_tsu_code => 'ERROR',
6968 p_ret_val => NULL,
6969 px_tcnv_rec => px_tcnv_rec
6970 );
6971
6972 IF (is_debug_exception_on)
6973 THEN
6974 okl_debug_pub.log_debug (g_level_exception,
6975 l_module_name,
6976 'EXCEPTION :' || 'G_EXCEPTION_ERROR'
6977 );
6978 END IF;
6979 WHEN okl_api.g_exception_unexpected_error
6980 THEN
6981 IF get_asset_return_csr%ISOPEN
6982 THEN
6983 CLOSE get_asset_return_csr;
6984 END IF;
6985
6986 ROLLBACK TO asset_return;
6987 x_return_status := g_ret_sts_unexp_error;
6988 -- store the highest degree of error
6989 set_overall_status (p_return_status => x_return_status,
6990 px_overall_status => px_overall_status);
6991 -- set the transaction record
6992 set_transaction_rec (p_return_status => x_return_status,
6993 p_overall_status => px_overall_status,
6994 p_tmt_flag => 'TMT_ASSET_RETURN_YN',
6995 p_tsu_code => 'ERROR',
6996 px_tcnv_rec => px_tcnv_rec
6997 );
6998 -- set the transaction record
6999 set_transaction_rec (p_return_status => x_return_status,
7000 p_overall_status => px_overall_status,
7001 p_tmt_flag => 'TMT_ASSET_DISPOSITION_YN',
7002 p_tsu_code => 'ERROR',
7003 p_ret_val => NULL,
7004 px_tcnv_rec => px_tcnv_rec
7005 );
7006
7007 IF (is_debug_exception_on)
7008 THEN
7009 okl_debug_pub.log_debug (g_level_exception,
7010 l_module_name,
7011 'EXCEPTION :'
7012 || 'G_EXCEPTION_UNEXPECTED_ERROR'
7013 );
7014 END IF;
7015 WHEN OTHERS
7016 THEN
7017 IF get_asset_return_csr%ISOPEN
7018 THEN
7019 CLOSE get_asset_return_csr;
7020 END IF;
7021
7022 ROLLBACK TO asset_return;
7023 x_return_status := g_ret_sts_unexp_error;
7024 -- store the highest degree of error
7025 set_overall_status (p_return_status => x_return_status,
7026 px_overall_status => px_overall_status);
7027 -- set the transaction record
7028 set_transaction_rec (p_return_status => x_return_status,
7029 p_overall_status => px_overall_status,
7030 p_tmt_flag => 'TMT_ASSET_RETURN_YN',
7031 p_tsu_code => 'ERROR',
7032 px_tcnv_rec => px_tcnv_rec
7033 );
7034 -- set the transaction record
7035 set_transaction_rec (p_return_status => x_return_status,
7036 p_overall_status => px_overall_status,
7037 p_tmt_flag => 'TMT_ASSET_DISPOSITION_YN',
7038 p_tsu_code => 'ERROR',
7039 p_ret_val => NULL,
7040 px_tcnv_rec => px_tcnv_rec
7041 );
7042 -- Set the oracle error message
7043 okl_api.set_message (p_app_name => g_app_name_1,
7044 p_msg_name => g_unexpected_error,
7045 p_token1 => g_sqlcode_token,
7046 p_token1_value => SQLCODE,
7047 p_token2 => g_sqlerrm_token,
7048 p_token2_value => SQLERRM
7049 );
7050
7051 IF (is_debug_exception_on)
7052 THEN
7053 okl_debug_pub.log_debug (g_level_exception,
7054 l_module_name,
7055 'EXCEPTION :'
7056 || 'OTHERS, SQLCODE: '
7057 || SQLCODE
7058 || ' , SQLERRM : '
7059 || SQLERRM
7060 );
7061 END IF;
7062 END return_assets;
7063
7064 -- Start of comments
7065 --
7066 -- Procedure Name : close_balances
7067 -- Desciption : Calls the AR adjustments apis for K header and
7068 -- Lines to close balances
7069 -- Business Rules :
7070 -- Parameters :
7071 -- Version : 1.0
7072 -- History : RMUNJULU 03-JAN-03 2683876 Created
7073 -- : RMUNJULU 07-APR-03 2883292 Changed IF to check for NULL
7074 -- tolerance_amt instead of -1
7075 -- : RMUNJULU 28-APR-04 3596626 Added code to set lp_acc_gen_primary_key_tbl
7076 --
7077 -- End of comments
7078 PROCEDURE close_balances (
7079 p_api_version IN NUMBER,
7080 p_init_msg_list IN VARCHAR2,
7081 x_msg_count OUT NOCOPY NUMBER,
7082 x_msg_data OUT NOCOPY VARCHAR2,
7083 x_return_status OUT NOCOPY VARCHAR2,
7084 p_term_rec IN term_rec_type,
7085 p_sys_date IN DATE,
7086 p_tcnv_rec IN tcnv_rec_type,
7087 px_msg_tbl IN OUT NOCOPY g_msg_tbl
7088 )
7089 IS
7090 -- Cursor to get the balances of contract
7091 CURSOR k_balances_csr (
7092 p_khr_id IN NUMBER
7093 )
7094 IS
7095 SELECT SUM (blp.amount_due_remaining)
7096 FROM okl_bpd_leasing_payment_trx_v blp
7097 WHERE blp.contract_id = p_khr_id;
7098
7099 -- Cursor to get the lines with amount due and payment schedule id for the balances
7100 CURSOR k_bal_lns_csr (
7101 p_khr_id IN NUMBER
7102 )
7103 IS
7104 SELECT oblp.amount_due_remaining amount,
7105 oblp.stream_type_id stream_type_id,
7106 osty.NAME stream_meaning,
7107 oblp.payment_schedule_id schedule_id,
7108 oblp.receivables_invoice_number ar_invoice_number,
7109 otil.ID til_id,
7110 -999 tld_id
7111 FROM okl_bpd_leasing_payment_trx_v oblp,
7112 okl_txl_ar_inv_lns_v otil,
7113 okl_strm_type_v osty
7114 WHERE oblp.contract_id = p_khr_id
7115 AND oblp.receivables_invoice_id = otil.receivables_invoice_id
7116 AND oblp.stream_type_id = osty.ID
7117 AND oblp.amount_due_remaining > 0
7118 UNION
7119 SELECT oblp.amount_due_remaining amount,
7120 oblp.stream_type_id stream_type_id,
7121 osty.NAME stream_meaning,
7122 oblp.payment_schedule_id schedule_id,
7123 oblp.receivables_invoice_number ar_invoice_number,
7124 otai.til_id_details til_id,
7125 otai.ID tld_id
7126 FROM okl_bpd_leasing_payment_trx_v oblp,
7127 okl_txd_ar_ln_dtls_v otai,
7128 okl_strm_type_v osty
7129 WHERE oblp.contract_id = p_khr_id
7130 AND oblp.receivables_invoice_id = otai.receivables_invoice_id
7131 AND oblp.stream_type_id = osty.ID
7132 AND oblp.amount_due_remaining > 0;
7133
7134 -- Cursor to get the product of the contract
7135 CURSOR prod_id_csr (
7136 p_khr_id IN NUMBER
7137 )
7138 IS
7139 SELECT khr.pdt_id
7140 FROM okl_k_headers_v khr
7141 WHERE khr.ID = p_khr_id;
7142
7143 -- Cursor to get the distribution for the transaction id and
7144 -- transaction table
7145 -- Make sure we get the debit distribution and also it is 100percent
7146 CURSOR code_combination_id_csr (
7147 p_source_id IN NUMBER,
7148 p_source_table IN VARCHAR2
7149 )
7150 IS
7151 SELECT dst.code_combination_id
7152 FROM okl_trns_acc_dstrs dst
7153 WHERE dst.source_id = p_source_id
7154 AND dst.source_table = p_source_table
7155 AND dst.cr_dr_flag = 'C'
7156 AND dst.percentage = 100;
7157
7158 k_bal_lns_rec k_bal_lns_csr%ROWTYPE;
7159 l_return_status VARCHAR2 (1) := okl_api.g_ret_sts_success;
7160 lp_adjv_rec okl_trx_ar_adjsts_pub.adjv_rec_type;
7161 lx_adjv_rec okl_trx_ar_adjsts_pub.adjv_rec_type;
7162 lp_ajlv_tbl okl_txl_adjsts_lns_pub.ajlv_tbl_type;
7163 lx_ajlv_tbl okl_txl_adjsts_lns_pub.ajlv_tbl_type;
7164 l_early_termination_yn VARCHAR2 (1) := okl_api.g_false;
7165 l_total_amount_due NUMBER := -1;
7166 l_code_combination_id NUMBER := -1;
7167 i NUMBER := 1;
7168 l_tolerance_amt NUMBER := -1;
7169 l_api_name VARCHAR2 (30) := 'close_balances';
7170 l_module_name VARCHAR2 (500)
7171 := g_module_name || 'close_balances';
7172 is_debug_exception_on BOOLEAN
7173 := okl_debug_pub.check_log_on (l_module_name, g_level_exception);
7174 is_debug_procedure_on BOOLEAN
7175 := okl_debug_pub.check_log_on (l_module_name, g_level_procedure);
7176 is_debug_statement_on BOOLEAN
7177 := okl_debug_pub.check_log_on (l_module_name, g_level_statement);
7178 l_pdt_id NUMBER := 0;
7179 lp_tmpl_identify_rec okl_account_dist_pub.tmpl_identify_rec_type;
7180 lp_dist_info_rec okl_account_dist_pub.dist_info_rec_type;
7181 lp_ctxt_val_tbl okl_account_dist_pub.ctxt_val_tbl_type;
7182 lp_acc_gen_primary_key_tbl okl_account_dist_pub.acc_gen_primary_key;
7183 lx_template_tbl okl_account_dist_pub.avlv_tbl_type;
7184 lx_amount_tbl okl_account_dist_pub.amount_tbl_type;
7185 l_try_id NUMBER;
7186 l_trans_meaning VARCHAR2 (200);
7187 l_currency_code VARCHAR2 (200);
7188 l_formatted_bal_amt VARCHAR2 (200);
7189 l_formatted_tol_amt VARCHAR2 (200);
7190 l_formatted_adj_amt VARCHAR2 (200);
7191 l_functional_currency_code VARCHAR2 (15);
7192 l_contract_currency_code VARCHAR2 (15);
7193 l_currency_conversion_type VARCHAR2 (30);
7194 l_currency_conversion_rate NUMBER;
7195 l_currency_conversion_date DATE;
7196 l_converted_amount NUMBER;
7197 -- Since we do not use the amount or converted amount
7198 -- set a hardcoded value for the amount (and pass to to
7199 -- OKL_ACCOUNTING_UTIL.convert_to_functional_currency and get back
7200 -- conversion values )
7201 l_hard_coded_amount NUMBER := 100;
7202 l_count NUMBER;
7203 BEGIN
7204 ---
7205 --get the tolerance limit from profile
7206 -- get the total balances of ARs for the contract
7207 -- if total balance amount within the tolerance limit then
7208 -- close balances
7209 -- end if
7210
7211 -- Establish savepoint so that when error rollback
7212 SAVEPOINT close_balances;
7213
7214 IF (is_debug_procedure_on)
7215 THEN
7216 okl_debug_pub.log_debug (g_level_procedure,
7217 l_module_name,
7218 'Begin(+)'
7219 );
7220 END IF;
7221
7222 IF (is_debug_statement_on)
7223 THEN
7224 okl_debug_pub.log_debug (g_level_statement,
7225 l_module_name,
7226 'In param, p_sys_date: ' || p_sys_date
7227 );
7228 okl_debug_pub.log_debug (g_level_statement,
7229 l_module_name,
7230 'In param, p_term_rec.p_contract_id: '
7231 || p_term_rec.p_contract_id
7232 );
7233 okl_debug_pub.log_debug
7234 (g_level_statement,
7235 l_module_name,
7236 'In param, p_term_rec.p_contract_number: '
7237 || p_term_rec.p_contract_number
7238 );
7239 okl_debug_pub.log_debug (g_level_statement,
7240 l_module_name,
7241 'In param, p_tcnv_rec.id: ' || p_tcnv_rec.ID
7242 );
7243 END IF;
7244
7245 l_count := px_msg_tbl.COUNT;
7246
7247 -- get the total balances of ARs for the contract
7248 OPEN k_balances_csr (p_term_rec.p_contract_id);
7249
7250 FETCH k_balances_csr
7251 INTO l_total_amount_due;
7252
7253 CLOSE k_balances_csr;
7254
7255 -- set the total amount if it is null
7256 IF l_total_amount_due IS NULL
7257 THEN
7258 l_total_amount_due := 0;
7259 END IF;
7260
7261 -- RMUNJULU 3018641 Step Message
7262 -- Step : Close Balances
7263 okl_api.set_message (p_app_name => g_app_name,
7264 p_msg_name => 'OKL_AM_STEP_CLB');
7265
7266 -- Check if total amount due is +ve else set message and exit
7267 IF l_total_amount_due <= 0
7268 THEN
7269 -- No outstanding balances found.
7270 okl_api.set_message (p_app_name => g_app_name,
7271 p_msg_name => 'OKL_AM_NO_BAL');
7272 ELSE
7273 -- can try closing balances
7274
7275 --get the tolerance limit from profile
7276 fnd_profile.get ('OKL_SMALL_BALANCE_TOLERANCE', l_tolerance_amt);
7277
7278 -- if no tolerance amt then assume tolerance amt = 0 ,
7279 -- raise warning msg and proceed
7280 -- RMUNJULU 07-APR-03 2883292 Changed IF to check for NULL instead of -1
7281 IF l_tolerance_amt IS NULL
7282 THEN
7283 l_tolerance_amt := 0;
7284 -- No tolerance amount found for closing of balances.
7285 okl_api.set_message (p_app_name => g_app_name,
7286 p_msg_name => 'OKL_AM_NO_TOL_AMT');
7287 END IF;
7288
7289 -- IF total balance amount within the tolerance limit and amount due>0 then
7290 IF (l_total_amount_due <= l_tolerance_amt)
7291 THEN
7292 -- set the adjusts rec
7293 lp_adjv_rec.trx_status_code := 'WORKING'; -- tsu_code
7294 -- tcn_id is set to transaction id from transaction rec
7295 lp_adjv_rec.tcn_id := p_tcnv_rec.ID;
7296 -- adjustment_reason_code comes from OKL_ADJUSTMENT_REASON
7297 lp_adjv_rec.adjustment_reason_code := 'SMALL AMT REMAINING';
7298 lp_adjv_rec.apply_date := p_sys_date;
7299 lp_adjv_rec.gl_date := p_sys_date;
7300
7301 IF (is_debug_statement_on)
7302 THEN
7303 okl_debug_pub.log_debug
7304 (g_level_statement,
7305 l_module_name,
7306 'calling OKL_TRX_AR_ADJSTS_PUB.insert_trx_ar_adjsts'
7307 );
7308 END IF;
7309
7310 -- call the adjusts api
7311 okl_trx_ar_adjsts_pub.insert_trx_ar_adjsts
7312 (p_api_version => p_api_version,
7313 p_init_msg_list => okl_api.g_false,
7314 x_return_status => l_return_status,
7315 x_msg_count => x_msg_count,
7316 x_msg_data => x_msg_data,
7317 p_adjv_rec => lp_adjv_rec,
7318 x_adjv_rec => lx_adjv_rec
7319 );
7320
7321 IF (is_debug_statement_on)
7322 THEN
7323 okl_debug_pub.log_debug
7324 (g_level_statement,
7325 l_module_name,
7326 'called OKL_TRX_AR_ADJSTS_PUB.insert_trx_ar_adjsts , return status: '
7327 || l_return_status
7328 );
7329 END IF;
7330
7331 IF l_return_status <> g_ret_sts_success
7332 THEN
7333 -- Error occurred when creating adjustment
7334 -- records to write off balances.
7335 okl_api.set_message (p_app_name => g_app_name,
7336 p_msg_name => 'OKL_AM_ERR_ADJST_BAL');
7337 END IF;
7338
7339 -- Raise exception to rollback this whole block
7340 IF (l_return_status = g_ret_sts_unexp_error)
7341 THEN
7342 RAISE okl_api.g_exception_unexpected_error;
7343 ELSIF (l_return_status = g_ret_sts_error)
7344 THEN
7345 RAISE okl_api.g_exception_error;
7346 END IF;
7347
7348 IF (is_debug_statement_on)
7349 THEN
7350 okl_debug_pub.log_debug
7351 (g_level_statement,
7352 l_module_name,
7353 'calling OKL_AM_UTIL_PVT.get_transaction_id'
7354 );
7355 END IF;
7356
7357 -- Get the transaction id for adjustments
7358 okl_am_util_pvt.get_transaction_id
7359 (p_try_name => 'Balance Write off',
7360 x_return_status => l_return_status,
7361 x_try_id => l_try_id
7362 );
7363
7364 IF (is_debug_statement_on)
7365 THEN
7366 okl_debug_pub.log_debug
7367 (g_level_statement,
7368 l_module_name,
7369 'called OKL_AM_UTIL_PVT.get_transaction_id , return status: '
7370 || l_return_status
7371 );
7372 okl_debug_pub.log_debug (g_level_statement,
7373 l_module_name,
7374 'l_try_id: ' || l_try_id
7375 );
7376 END IF;
7377
7378 IF l_return_status <> g_ret_sts_success
7379 THEN
7380 -- Message: Unable to find a transaction type for
7381 -- the transaction TRY_NAME
7382 okl_api.set_message (p_app_name => g_app_name,
7383 p_msg_name => 'OKL_AM_NO_TRX_TYPE_FOUND',
7384 p_token1 => 'TRY_NAME',
7385 p_token1_value => l_trans_meaning
7386 );
7387 END IF;
7388
7389 -- Raise exception to rollback this whole block
7390 IF (l_return_status = g_ret_sts_unexp_error)
7391 THEN
7392 RAISE okl_api.g_exception_unexpected_error;
7393 ELSIF (l_return_status = g_ret_sts_error)
7394 THEN
7395 RAISE okl_api.g_exception_error;
7396 END IF;
7397
7398 -- Get the meaning of lookup BALANCE_WRITE_OFF
7399 l_trans_meaning :=
7400 okl_am_util_pvt.get_lookup_meaning
7401 (p_lookup_type => 'OKL_ACCOUNTING_EVENT_TYPE',
7402 p_lookup_code => 'BALANCE_WRITE_OFF',
7403 p_validate_yn => 'Y'
7404 );
7405
7406 -- get the product id
7407 OPEN prod_id_csr (p_term_rec.p_contract_id);
7408
7409 FETCH prod_id_csr
7410 INTO l_pdt_id;
7411
7412 CLOSE prod_id_csr;
7413
7414 -- raise error message if no pdt_id
7415 IF l_pdt_id IS NULL OR l_pdt_id = 0
7416 THEN
7417 -- Error: Unable to create accounting entries because of a missing
7418 -- Product Type for the contract CONTRACT_NUMBER.
7419 okl_api.set_message
7420 (p_app_name => g_app_name,
7421 p_msg_name => 'OKL_AM_PRODUCT_ID_ERROR',
7422 p_token1 => 'CONTRACT_NUMBER',
7423 p_token1_value => p_term_rec.p_contract_number
7424 );
7425 END IF;
7426
7427 -- Raise exception to rollback to savepoint for this block
7428 IF (l_return_status = g_ret_sts_unexp_error)
7429 THEN
7430 RAISE okl_api.g_exception_unexpected_error;
7431 ELSIF (l_return_status = g_ret_sts_error)
7432 THEN
7433 RAISE okl_api.g_exception_error;
7434 END IF;
7435
7436 -- Get, set and pass the currency conversion parameters
7437 -- Get the functional currency from AM_Util
7438 l_functional_currency_code :=
7439 okl_am_util_pvt.get_functional_currency;
7440
7441 IF (is_debug_statement_on)
7442 THEN
7443 okl_debug_pub.log_debug
7444 (g_level_statement,
7445 l_module_name,
7446 'calling OKL_ACCOUNTING_UTIL.convert_to_functional_currency'
7447 );
7448 END IF;
7449
7450 -- Get the currency conversion details from ACCOUNTING_Util
7451 okl_accounting_util.convert_to_functional_currency
7452 (p_khr_id => p_term_rec.p_contract_id,
7453 p_to_currency => l_functional_currency_code,
7454 p_transaction_date => p_sys_date,
7455 p_amount => l_hard_coded_amount,
7456 x_return_status => l_return_status,
7457 x_contract_currency => l_contract_currency_code,
7458 x_currency_conversion_type => l_currency_conversion_type,
7459 x_currency_conversion_rate => l_currency_conversion_rate,
7460 x_currency_conversion_date => l_currency_conversion_date,
7461 x_converted_amount => l_converted_amount
7462 );
7463
7464 IF (is_debug_statement_on)
7465 THEN
7466 okl_debug_pub.log_debug
7467 (g_level_statement,
7468 l_module_name,
7469 'called okl_accounting_util.convert_to_functional_currency , return status: '
7470 || l_return_status
7471 );
7472 okl_debug_pub.log_debug (g_level_statement,
7473 l_module_name,
7474 'l_contract_currency_code: '
7475 || l_contract_currency_code
7476 );
7477 okl_debug_pub.log_debug (g_level_statement,
7478 l_module_name,
7479 'l_currency_conversion_type: '
7480 || l_currency_conversion_type
7481 );
7482 okl_debug_pub.log_debug (g_level_statement,
7483 l_module_name,
7484 'l_currency_conversion_rate: '
7485 || l_currency_conversion_rate
7486 );
7487 okl_debug_pub.log_debug (g_level_statement,
7488 l_module_name,
7489 'l_currency_conversion_date: '
7490 || l_currency_conversion_date
7491 );
7492 okl_debug_pub.log_debug (g_level_statement,
7493 l_module_name,
7494 'l_converted_amount: '
7495 || l_converted_amount
7496 );
7497 END IF;
7498
7499 -- If error from OKL_ACCOUNTING_UTIL
7500 IF l_return_status <> okl_api.g_ret_sts_success
7501 THEN
7502 -- Error occurred when creating accounting entries for
7503 -- transaction TRX_TYPE.
7504 okl_api.set_message (p_app_name => g_app_name,
7505 p_msg_name => 'OKL_AM_ERR_ACC_ENT',
7506 p_token1 => 'TRX_TYPE',
7507 p_token1_value => l_trans_meaning
7508 );
7509 END IF;
7510
7511 -- Raise exception to rollback to savepoint for this block
7512 IF (l_return_status = g_ret_sts_unexp_error)
7513 THEN
7514 RAISE okl_api.g_exception_unexpected_error;
7515 ELSIF (l_return_status = g_ret_sts_error)
7516 THEN
7517 RAISE okl_api.g_exception_error;
7518 END IF;
7519
7520 i := 1;
7521
7522 FOR k_bal_lns_rec IN k_bal_lns_csr (p_term_rec.p_contract_id)
7523 LOOP
7524 -- do accounting entries to get code_combination_id
7525 -- Set the tmpl_identify_rec in parameter
7526 lp_tmpl_identify_rec.product_id := l_pdt_id;
7527 lp_tmpl_identify_rec.transaction_type_id := l_try_id;
7528 lp_tmpl_identify_rec.memo_yn := g_no;
7529 lp_tmpl_identify_rec.prior_year_yn := g_no;
7530 lp_tmpl_identify_rec.stream_type_id :=
7531 k_bal_lns_rec.stream_type_id;
7532 -- Set the dist_info_rec in parameter
7533 lp_dist_info_rec.source_id := lx_adjv_rec.ID;
7534 lp_dist_info_rec.source_table := 'OKL_TRX_AR_ADJSTS_B';
7535 lp_dist_info_rec.accounting_date := p_sys_date;
7536 lp_dist_info_rec.gl_reversal_flag := g_no;
7537 lp_dist_info_rec.post_to_gl := g_no;
7538 lp_dist_info_rec.contract_id := p_term_rec.p_contract_id;
7539 lp_dist_info_rec.amount := k_bal_lns_rec.amount;
7540 -- Set the p_dist_info_rec for currency code
7541 lp_dist_info_rec.currency_code := l_contract_currency_code;
7542
7543 -- If the functional currency code is different
7544 -- from contract currency code
7545 -- then set the rest of the currency conversion columns
7546 IF l_functional_currency_code <> l_contract_currency_code
7547 THEN
7548 -- Set the p_dist_info_rec currency conversion columns
7549 lp_dist_info_rec.currency_conversion_type :=
7550 l_currency_conversion_type;
7551 lp_dist_info_rec.currency_conversion_rate :=
7552 l_currency_conversion_rate;
7553 lp_dist_info_rec.currency_conversion_date :=
7554 l_currency_conversion_date;
7555 END IF;
7556
7557 -- RMUNJULU 28-APR-04 3596626 Added code to set lp_acc_gen_primary_key_tbl
7558 -- for account generator
7559 IF (is_debug_statement_on)
7560 THEN
7561 okl_debug_pub.log_debug
7562 (g_level_statement,
7563 l_module_name,
7564 'calling OKL_ACC_CALL_PVT.okl_populate_acc_gen'
7565 );
7566 END IF;
7567
7568 okl_acc_call_pvt.okl_populate_acc_gen
7569 (p_contract_id => p_term_rec.p_contract_id,
7570 p_contract_line_id => NULL,
7571 x_acc_gen_tbl => lp_acc_gen_primary_key_tbl,
7572 x_return_status => l_return_status
7573 );
7574
7575 IF (is_debug_statement_on)
7576 THEN
7577 okl_debug_pub.log_debug
7578 (g_level_statement,
7579 l_module_name,
7580 'called OKL_ACC_CALL_PVT.okl_populate_acc_gen , return status: '
7581 || l_return_status
7582 );
7583 END IF;
7584
7585 -- Raise exception to rollback to savepoint for this block
7586 IF (l_return_status = okl_api.g_ret_sts_unexp_error)
7587 THEN
7588 RAISE okl_api.g_exception_unexpected_error;
7589 ELSIF (l_return_status = okl_api.g_ret_sts_error)
7590 THEN
7591 RAISE okl_api.g_exception_error;
7592 END IF;
7593
7594 IF (is_debug_statement_on)
7595 THEN
7596 okl_debug_pub.log_debug
7597 (g_level_statement,
7598 l_module_name,
7599 'calling OKL_ACCOUNT_DIST_PUB.create_accounting_dist'
7600 );
7601 END IF;
7602
7603 -- call accounting engine
7604 -- This will calculate the adjstmnts and generate accounting entries
7605 okl_account_dist_pub.create_accounting_dist
7606 (p_api_version => p_api_version,
7607 p_init_msg_list => okl_api.g_false,
7608 x_return_status => l_return_status,
7609 x_msg_count => x_msg_count,
7610 x_msg_data => x_msg_data,
7611 p_tmpl_identify_rec => lp_tmpl_identify_rec,
7612 p_dist_info_rec => lp_dist_info_rec,
7613 p_ctxt_val_tbl => lp_ctxt_val_tbl,
7614 p_acc_gen_primary_key_tbl => lp_acc_gen_primary_key_tbl,
7615 x_template_tbl => lx_template_tbl,
7616 x_amount_tbl => lx_amount_tbl
7617 );
7618
7619 IF (is_debug_statement_on)
7620 THEN
7621 okl_debug_pub.log_debug
7622 (g_level_statement,
7623 l_module_name,
7624 'called OKL_ACCOUNT_DIST_PUB.create_accounting_dist , return status: '
7625 || l_return_status
7626 );
7627 END IF;
7628
7629 IF l_return_status <> g_ret_sts_success
7630 THEN
7631 -- Error occurred when creating accounting entries
7632 -- for transaction type TRX_TYPE and stream type STREAM_TYPE.
7633 okl_api.set_message
7634 (p_app_name => g_app_name,
7635 p_msg_name => 'OKL_AM_ERR_ACC_ENT_MSG',
7636 p_token1 => 'TRX_TYPE',
7637 p_token1_value => l_trans_meaning,
7638 p_token2 => 'STREAM_TYPE',
7639 p_token2_value => k_bal_lns_rec.stream_meaning
7640 );
7641 END IF;
7642
7643 -- Raise exception to rollback this whole block
7644 IF (l_return_status = g_ret_sts_unexp_error)
7645 THEN
7646 RAISE okl_api.g_exception_unexpected_error;
7647 ELSIF (l_return_status = g_ret_sts_error)
7648 THEN
7649 RAISE okl_api.g_exception_error;
7650 END IF;
7651
7652 -- Get the first code_combination_id for the transaction
7653 -- from OKL_TRNS_ACC_DSTRS_V
7654 OPEN code_combination_id_csr (lx_adjv_rec.ID,
7655 'OKL_TRX_AR_ADJSTS_B');
7656
7657 FETCH code_combination_id_csr
7658 INTO l_code_combination_id;
7659
7660 CLOSE code_combination_id_csr;
7661
7662 -- if code_combination_id not found then raise error
7663 IF l_code_combination_id = -1 OR l_code_combination_id IS NULL
7664 THEN
7665 -- Error: Unable to process small balance
7666 -- adjustments because of a missing Code Combination ID for the
7667 -- contract CONTRACT_NUMBER.
7668 okl_api.set_message
7669 (p_app_name => g_app_name,
7670 p_msg_name => 'OKL_AM_CODE_CMB_ERROR',
7671 p_token1 => 'CONTRACT_NUMBER',
7672 p_token1_value => p_term_rec.p_contract_number
7673 );
7674 RAISE okl_api.g_exception_error;
7675 END IF;
7676
7677 -- Loop thru the code combination ids to set the lns tbl
7678 FOR code_combination_id_rec IN
7679 code_combination_id_csr (lx_adjv_rec.ID,
7680 'OKL_TRX_AR_ADJSTS_B')
7681 LOOP
7682 -- set the tbl for adjsts lns
7683 lp_ajlv_tbl (i).adj_id := lx_adjv_rec.ID;
7684 lp_ajlv_tbl (i).til_id := k_bal_lns_rec.til_id;
7685
7686 IF k_bal_lns_rec.tld_id <> -999
7687 AND k_bal_lns_rec.tld_id IS NOT NULL
7688 AND k_bal_lns_rec.tld_id <> okl_api.g_miss_num
7689 THEN
7690 lp_ajlv_tbl (i).tld_id := k_bal_lns_rec.tld_id;
7691 END IF;
7692
7693 lp_ajlv_tbl (i).amount := k_bal_lns_rec.amount;
7694 lp_ajlv_tbl (i).psl_id := k_bal_lns_rec.schedule_id;
7695 lp_ajlv_tbl (i).code_combination_id :=
7696 code_combination_id_rec.code_combination_id;
7697 i := i + 1;
7698 END LOOP; -- code combination recs
7699 END LOOP; -- balances res
7700
7701 IF (is_debug_statement_on)
7702 THEN
7703 okl_debug_pub.log_debug
7704 (g_level_statement,
7705 l_module_name,
7706 'calling OKL_TXL_ADJSTS_LNS_PUB.insert_txl_adjsts_lns'
7707 );
7708 END IF;
7709
7710 --call the txl_lns_adjsts
7711 okl_txl_adjsts_lns_pub.insert_txl_adjsts_lns
7712 (p_api_version => p_api_version,
7713 p_init_msg_list => okl_api.g_false,
7714 x_return_status => l_return_status,
7715 x_msg_count => x_msg_count,
7716 x_msg_data => x_msg_data,
7717 p_ajlv_tbl => lp_ajlv_tbl,
7718 x_ajlv_tbl => lx_ajlv_tbl
7719 );
7720
7721 IF (is_debug_statement_on)
7722 THEN
7723 okl_debug_pub.log_debug
7724 (g_level_statement,
7725 l_module_name,
7726 'called OKL_TXL_ADJSTS_LNS_PUB.insert_txl_adjsts_lns , return status: '
7727 || l_return_status
7728 );
7729 END IF;
7730
7731 IF l_return_status <> g_ret_sts_success
7732 THEN
7733 -- Error occurred when creating adjustment records to write
7734 -- off balances.
7735 okl_api.set_message (p_app_name => g_app_name,
7736 p_msg_name => 'OKL_AM_ERR_ADJST_BAL');
7737 END IF;
7738
7739 -- Raise exception to rollback this whole block
7740 IF (l_return_status = g_ret_sts_unexp_error)
7741 THEN
7742 RAISE okl_api.g_exception_unexpected_error;
7743 ELSIF (l_return_status = g_ret_sts_error)
7744 THEN
7745 RAISE okl_api.g_exception_error;
7746 END IF;
7747
7748 -- Get the currency code for contract
7749 l_currency_code :=
7750 okl_am_util_pvt.get_chr_currency (p_term_rec.p_contract_id);
7751
7752 -- Set all success messages for all balances
7753 FOR k_bal_lns_rec IN k_bal_lns_csr (p_term_rec.p_contract_id)
7754 LOOP
7755 -- Format the adjustment amt
7756 l_formatted_adj_amt :=
7757 okl_accounting_util.format_amount (k_bal_lns_rec.amount,
7758 l_currency_code);
7759 -- Append adjustment amt with currency code
7760 l_formatted_adj_amt :=
7761 l_formatted_adj_amt || ' ' || l_currency_code;
7762 -- Set the success message in the message table
7763
7764 -- Adjustment transaction for AR invoice AR_INVOICE_NUM of amount AMOUNT
7765 -- has been created.
7766 px_msg_tbl (l_count).msg_desc := 'OKL_AM_ACC_ENT_AR_INV_MSG';
7767 px_msg_tbl (l_count).msg_token1 := 'AR_INVOICE_NUM';
7768 px_msg_tbl (l_count).msg_token1_value :=
7769 k_bal_lns_rec.ar_invoice_number;
7770 px_msg_tbl (l_count).msg_token2 := 'AMOUNT';
7771 px_msg_tbl (l_count).msg_token2_value := l_formatted_adj_amt;
7772 l_count := l_count + 1;
7773 -- Accounting entries created for transaction type TRX_TYPE
7774 -- and stream type STREAM_TYPE.
7775 px_msg_tbl (l_count).msg_desc := 'OKL_AM_ACC_ENT_CREATED_MSG';
7776 px_msg_tbl (l_count).msg_token1 := 'TRX_TYPE';
7777 px_msg_tbl (l_count).msg_token1_value := l_trans_meaning;
7778 px_msg_tbl (l_count).msg_token2 := 'STREAM_TYPE';
7779 px_msg_tbl (l_count).msg_token2_value :=
7780 k_bal_lns_rec.stream_meaning;
7781 l_count := l_count + 1;
7782 END LOOP;
7783 ELSE
7784 --(cannot close all balances since tolerance amt is less)
7785
7786 -- Unable to close all outstanding balances due to tolerance amount.
7787 okl_api.set_message (p_app_name => g_app_name,
7788 p_msg_name => 'OKL_AM_ERR_CLOSE_BAL');
7789 -- Get the currency code for contract
7790 l_currency_code :=
7791 okl_am_util_pvt.get_chr_currency (p_term_rec.p_contract_id);
7792 -- Format the balance amt
7793 l_formatted_bal_amt :=
7794 okl_accounting_util.format_amount (l_total_amount_due,
7795 l_currency_code);
7796 -- Append balance amt with currency code
7797 l_formatted_bal_amt :=
7798 l_formatted_bal_amt || ' ' || l_currency_code;
7799 -- Format the tolerance amt
7800 l_formatted_tol_amt :=
7801 okl_accounting_util.format_amount (l_tolerance_amt,
7802 l_currency_code);
7803 -- Append tolerance amt with currency code
7804 l_formatted_tol_amt :=
7805 l_formatted_tol_amt || ' ' || l_currency_code;
7806 -- Outstanding balance BALANCE_AMT exceeds Tolerance Amount TOLERANCE_AMT.
7807 okl_api.set_message (p_app_name => g_app_name,
7808 p_msg_name => 'OKL_AM_BAL_GTR_TOL',
7809 p_token1 => 'BALANCE_AMT',
7810 p_token1_value => l_formatted_bal_amt,
7811 p_token2 => 'TOLERANCE_AMT',
7812 p_token2_value => l_formatted_tol_amt
7813 );
7814 END IF;
7815 END IF;
7816
7817 x_return_status := l_return_status;
7818
7819 IF (is_debug_procedure_on)
7820 THEN
7821 okl_debug_pub.log_debug (g_level_procedure,
7822 l_module_name,
7823 'End(-)'
7824 );
7825 END IF;
7826 EXCEPTION
7827 WHEN okl_api.g_exception_error
7828 THEN
7829 IF k_balances_csr%ISOPEN
7830 THEN
7831 CLOSE k_balances_csr;
7832 END IF;
7833
7834 IF k_bal_lns_csr%ISOPEN
7835 THEN
7836 CLOSE k_bal_lns_csr;
7837 END IF;
7838
7839 IF code_combination_id_csr%ISOPEN
7840 THEN
7841 CLOSE code_combination_id_csr;
7842 END IF;
7843
7844 ROLLBACK TO close_balances;
7845 x_return_status := okl_api.g_ret_sts_error;
7846
7847 IF (is_debug_exception_on)
7848 THEN
7849 okl_debug_pub.log_debug (g_level_exception,
7850 l_module_name,
7851 'EXCEPTION :' || 'G_EXCEPTION_ERROR'
7852 );
7853 END IF;
7854 WHEN okl_api.g_exception_unexpected_error
7855 THEN
7856 IF k_balances_csr%ISOPEN
7857 THEN
7858 CLOSE k_balances_csr;
7859 END IF;
7860
7861 IF k_bal_lns_csr%ISOPEN
7862 THEN
7863 CLOSE k_bal_lns_csr;
7864 END IF;
7865
7866 IF code_combination_id_csr%ISOPEN
7867 THEN
7868 CLOSE code_combination_id_csr;
7869 END IF;
7870
7871 ROLLBACK TO close_balances;
7872 x_return_status := okl_api.g_ret_sts_unexp_error;
7873
7874 IF (is_debug_exception_on)
7875 THEN
7876 okl_debug_pub.log_debug (g_level_exception,
7877 l_module_name,
7878 'EXCEPTION :'
7879 || 'G_EXCEPTION_UNEXPECTED_ERROR'
7880 );
7881 END IF;
7882 WHEN OTHERS
7883 THEN
7884 IF k_balances_csr%ISOPEN
7885 THEN
7886 CLOSE k_balances_csr;
7887 END IF;
7888
7889 IF k_bal_lns_csr%ISOPEN
7890 THEN
7891 CLOSE k_bal_lns_csr;
7892 END IF;
7893
7894 IF code_combination_id_csr%ISOPEN
7895 THEN
7896 CLOSE code_combination_id_csr;
7897 END IF;
7898
7899 ROLLBACK TO close_balances;
7900 x_return_status := okl_api.g_ret_sts_unexp_error;
7901 -- Set the oracle error message
7902 okl_api.set_message (p_app_name => g_app_name_1,
7903 p_msg_name => g_unexpected_error,
7904 p_token1 => g_sqlcode_token,
7905 p_token1_value => SQLCODE,
7906 p_token2 => g_sqlerrm_token,
7907 p_token2_value => SQLERRM
7908 );
7909
7910 IF (is_debug_exception_on)
7911 THEN
7912 okl_debug_pub.log_debug (g_level_exception,
7913 l_module_name,
7914 'EXCEPTION :'
7915 || 'OTHERS, SQLCODE: '
7916 || SQLCODE
7917 || ' , SQLERRM : '
7918 || SQLERRM
7919 );
7920 END IF;
7921 END close_balances;
7922
7923 -- Start of comments
7924 --
7925 -- Procedure Name : mass_rebook
7926 -- Desciption : Will do a mass rebook of the contract may have some
7927 -- changed lines
7928 -- Business Rules :
7929 -- Parameters :
7930 -- Version : 1.0
7931 -- History : RMUNJULU -- 04-DEC-02 Bug # 2484327, removed unnecessary
7932 -- cursors and changed others, moved the if condition
7933 -- Changed code to set savepoint instead of start/end activity
7934 -- : RMUNJULU 16-DEC-02 Bug # 2484327, changed cursor to get lines
7935 -- which are of the same status as header
7936 -- : RMUNJULU 20-DEC-02 2484327, corrected the cursor for aliases
7937 -- : RMUNJULU 07-JAN-03 2736865 Removed processing messages
7938 -- : RMUNJULU 23-JAN-03 2762065 removed log msgs here, see
7939 -- msgs explanation comments in asset_level_termination
7940 -- : SECHAWLA 10-FEB-03 2793689 Removed the NOT NULL residual
7941 -- value condition from l_okclines_csr
7942 -- cursor, as the LOAN contracts do not have a residual value.
7943 -- Mass Rebook works fine when we pass a null residual value
7944 -- : RMUNJULU 14-FEB-03 2804703 Added new cursor and check to
7945 -- do mass rebook when contract not evergreen
7946 -- : RMUNJULU 06-MAR-03 Performance Fix Replaced K_LNS_FULL
7947 -- : RMUNJULU CONTRACT BLOCKING Changed MASS_REBOOK to check if
7948 -- the Rebook TRN processed. If NOT then x_mrbk_success = 'E' else 'S'
7949 -- : RMUNJULU CONTRACT BLOCKING Changed MASS_REBOOK to Call New
7950 -- Mass Rebook API done only thru terminations
7951 -- : rmunjulu EDAT Added code to get quote eff date and call new overloaded mass_rebook api
7952 -- which takes trx date as parameter
7953 -- End of comments
7954 PROCEDURE mass_rebook (
7955 p_api_version IN NUMBER,
7956 p_init_msg_list IN VARCHAR2,
7957 x_msg_count OUT NOCOPY NUMBER,
7958 x_msg_data OUT NOCOPY VARCHAR2,
7959 x_return_status OUT NOCOPY VARCHAR2,
7960 p_term_rec IN term_rec_type,
7961 p_tcnv_rec IN tcnv_rec_type,
7962 p_sys_date IN DATE, -- rmunjulu EDAT
7963 x_mrbk_success OUT NOCOPY VARCHAR2
7964 )
7965 IS
7966 -- RMUNJULU CONTRACT BLOCKING ADDED
7967
7968 -- RMUNJULU -- Bug # 2484327 changed to cater to plsql standards
7969 -- This cursor is used to get a BOOKED contract line.
7970 -- RMUNJULU 16-DEC-02 Bug # 2484327, get lines which are of the same status as header
7971 -- RMUNJULU 20-DEC-02 2484327, corrected the cursor for aliases
7972 -- SECHAWLA 10-FEB-03 2793689, Removed the NOT NULL residual value condition
7973 -- from the following cursor, as the LOAN contracts do not have a residual value.
7974 -- Mass Rebook works fine when we pass a null residual value
7975 -- RMUNJULU 06-MAR-03 Performance Fix Replaced K_LNS_FULL
7976 CURSOR l_okclines_csr (
7977 p_khr_id IN NUMBER
7978 )
7979 IS
7980 SELECT cle.ID ID,
7981 cle.NAME NAME,
7982 kle.residual_value residual_value
7983 FROM okl_k_lines_v kle,
7984 okc_k_lines_v cle,
7985 okc_k_headers_v khr
7986 WHERE cle.chr_id = p_khr_id
7987 AND cle.chr_id = khr.ID
7988 AND cle.sts_code = khr.sts_code
7989 AND kle.ID = cle.ID
7990 AND ROWNUM < 2;
7991
7992 --Bug# 3999921: pagarg +++ T and A +++++++ Start ++++++++++
7993 --Cursor to obtain all the quote asset lines
7994 CURSOR l_quote_assets_csr (
7995 p_qte_id IN NUMBER
7996 )
7997 IS
7998 SELECT qlt.kle_id
7999 FROM okl_txl_quote_lines_b qlt
8000 WHERE qlt.qlt_code = 'AMCFIA' AND qlt.qte_id = p_qte_id;
8001
8002 l_counter NUMBER;
8003
8004 --Bug# 3999921: pagarg +++ T and A +++++++ End ++++++++++
8005
8006 -- RMUNJULU 14-FEB-03 2804703 Added cursor
8007 -- Get the k sts_code
8008 CURSOR l_k_details_csr (
8009 p_khr_id IN NUMBER
8010 )
8011 IS
8012 SELECT khr.sts_code
8013 FROM okc_k_headers_v khr
8014 WHERE khr.ID = p_khr_id;
8015
8016 -- RMUNJULU CONTRACT BLOCKING
8017 -- RMUNJULU CONTRACT BLOCKING (2)
8018 -- Get the REBOOK TRN details
8019 CURSOR get_trn_details_csr (
8020 p_trx_id IN NUMBER
8021 )
8022 IS
8023 SELECT trn.tsu_code
8024 FROM okl_trx_contracts trn
8025 WHERE trn.ID = p_trx_id;
8026
8027 l_strm_lalevl_empty_tbl okl_mass_rebook_pub.strm_lalevl_tbl_type;
8028 l_rbk_tbl okl_mass_rebook_pub.rbk_tbl_type;
8029 l_return_status VARCHAR2 (1) := g_ret_sts_success;
8030 l_api_name CONSTANT VARCHAR2 (30) := 'mass_rebook';
8031 l_module_name VARCHAR2 (500)
8032 := g_module_name || 'mass_rebook';
8033 is_debug_exception_on BOOLEAN
8034 := okl_debug_pub.check_log_on (l_module_name, g_level_exception);
8035 is_debug_procedure_on BOOLEAN
8036 := okl_debug_pub.check_log_on (l_module_name, g_level_procedure);
8037 is_debug_statement_on BOOLEAN
8038 := okl_debug_pub.check_log_on (l_module_name, g_level_statement);
8039 l_api_version CONSTANT NUMBER := 1;
8040 l_contract_number VARCHAR2 (120);
8041 l_id NUMBER;
8042 l_name VARCHAR2 (150);
8043 l_residual_value NUMBER;
8044 l_dummy VARCHAR2 (1);
8045 l_tcnv_rec tcnv_rec_type := p_tcnv_rec;
8046 -- RMUNJULU 14-FEB-03 2804703 Added variable
8047 l_sts_code VARCHAR2 (200);
8048 -- RMUNJULU CONTRACT BLOCKING (2)
8049 l_mass_rebook_trx_id NUMBER;
8050 -- rmunjulu EDAT
8051 l_quote_accpt_date DATE;
8052 l_quote_eff_date DATE;
8053 BEGIN
8054 -- RMUNJULU Bug # 2484327, added code to set savepoint
8055 -- Start a savepoint to rollback to if error in this block
8056 SAVEPOINT mass_rebook;
8057
8058 IF (is_debug_procedure_on)
8059 THEN
8060 okl_debug_pub.log_debug (g_level_procedure,
8061 l_module_name,
8062 'Begin(+)'
8063 );
8064 END IF;
8065
8066 IF (is_debug_statement_on)
8067 THEN
8068 okl_debug_pub.log_debug (g_level_statement,
8069 l_module_name,
8070 'In param, p_sys_date: ' || p_sys_date
8071 );
8072 okl_debug_pub.log_debug (g_level_statement,
8073 l_module_name,
8074 'In param, p_term_rec.p_quote_id: '
8075 || p_term_rec.p_quote_id
8076 );
8077 okl_debug_pub.log_debug (g_level_statement,
8078 l_module_name,
8079 'In param, p_term_rec.p_contract_id: '
8080 || p_term_rec.p_contract_id
8081 );
8082 okl_debug_pub.log_debug
8083 (g_level_statement,
8084 l_module_name,
8085 'In param, p_term_rec.p_contract_number: '
8086 || p_term_rec.p_contract_number
8087 );
8088 okl_debug_pub.log_debug (g_level_statement,
8089 l_module_name,
8090 'In param, p_tcnv_rec.id: ' || p_tcnv_rec.ID
8091 );
8092 END IF;
8093
8094 -- RMUNJULU CONTRACT BLOCKING
8095 x_mrbk_success := g_ret_sts_success;
8096
8097 -- Get the contract line details
8098 OPEN l_okclines_csr (p_term_rec.p_contract_id);
8099
8100 FETCH l_okclines_csr
8101 INTO l_id,
8102 l_name,
8103 l_residual_value;
8104
8105 CLOSE l_okclines_csr;
8106
8107 -- RMUNJULU Bug # 2484327, moved this if down from above cursor loop
8108 IF l_id IS NULL
8109 THEN
8110 -- SECHAWLA 10-FEB-03 2793689: Modified the following message
8111 -- There are no booked lines for the contract CONTRACT_NUMBER
8112 okl_api.set_message (p_app_name => okl_api.g_app_name,
8113 p_msg_name => 'OKL_AM_NO_BOOKED_LINES',
8114 p_token1 => 'CONTRACT_NUMBER',
8115 p_token1_value => p_term_rec.p_contract_number
8116 );
8117 RAISE okl_api.g_exception_error;
8118 END IF;
8119
8120 -- RMUNJULU 14-FEB-03 2804703 get sts_code for contract
8121 OPEN l_k_details_csr (p_term_rec.p_contract_id);
8122
8123 FETCH l_k_details_csr
8124 INTO l_sts_code;
8125
8126 CLOSE l_k_details_csr;
8127
8128 -- rmunjulu +++++++++ Effective Dated Termination -- start ++++++++++++++++
8129
8130 -- rmunjulu EDAT
8131 -- If quote exists then accnting date is quote accept date else sysdate
8132 IF NVL (okl_am_lease_loan_trmnt_pvt.g_quote_exists, 'N') = 'Y'
8133 THEN
8134 l_quote_accpt_date :=
8135 okl_am_lease_loan_trmnt_pvt.g_quote_accept_date;
8136 l_quote_eff_date :=
8137 okl_am_lease_loan_trmnt_pvt.g_quote_eff_from_date;
8138 ELSE
8139 l_quote_accpt_date := p_sys_date;
8140 l_quote_eff_date := p_sys_date;
8141 END IF;
8142
8143 -- rmunjulu +++++++++ Effective Dated Termination -- end ++++++++++++++++
8144
8145 -- RMUNJULU 14-FEB-03 2804703 Added IF to check contract not already
8146 -- EVERGREEN. Do mass rebook when contract not evergreen
8147 IF l_sts_code <> 'EVERGREEN'
8148 THEN
8149 --Bug# 3999921: pagarg +++ T and A +++++++ Start ++++++++++
8150 --Pass all the quote assets to mass rebook api
8151 l_counter := 0;
8152
8153 FOR l_quote_assets_rec IN l_quote_assets_csr (p_term_rec.p_quote_id)
8154 LOOP
8155 l_counter := l_counter + 1;
8156 l_rbk_tbl (l_counter).khr_id := p_term_rec.p_contract_id;
8157 l_rbk_tbl (l_counter).kle_id := l_quote_assets_rec.kle_id;
8158 END LOOP;
8159
8160 --Bug# 3999921: pagarg +++ T and A +++++++ End ++++++++++
8161 IF (is_debug_statement_on)
8162 THEN
8163 okl_debug_pub.log_debug
8164 (g_level_statement,
8165 l_module_name,
8166 'calling OKL_MASS_REBOOK_PVT.apply_mass_rebook'
8167 );
8168 END IF;
8169
8170 -- rmunjulu EDAT Changed the signature to call new API which takes transaction date
8171 okl_mass_rebook_pvt.apply_mass_rebook
8172 (p_api_version => p_api_version,
8173 p_init_msg_list => g_false, -- Changed
8174 x_return_status => l_return_status,
8175 x_msg_count => x_msg_count,
8176 x_msg_data => x_msg_data,
8177 p_rbk_tbl => l_rbk_tbl,
8178 p_deprn_method_code => NULL,
8179 p_in_service_date => NULL,
8180 p_life_in_months => NULL,
8181 p_basic_rate => NULL,
8182 p_adjusted_rate => NULL,
8183 --Bug# : pagarg +++ T and A ++++
8184 --Pass residual value as null
8185 p_residual_value => NULL,
8186 p_strm_lalevl_tbl => l_strm_lalevl_empty_tbl,
8187 p_source_trx_id => p_tcnv_rec.ID,
8188 -- RMUNJULU CONTRACT BLOCKING (2)
8189 p_source_trx_type => 'TCN',
8190 -- RMUNJULU CONTRACT BLOCKING (2)
8191 p_transaction_date => l_quote_eff_date, -- rmunjulu EDAT
8192 x_mass_rebook_trx_id => l_mass_rebook_trx_id
8193 ); -- RMUNJULU CONTRACT BLOCKING (2)
8194
8195 IF (is_debug_statement_on)
8196 THEN
8197 okl_debug_pub.log_debug
8198 (g_level_statement,
8199 l_module_name,
8200 'called OKL_MASS_REBOOK_PVT.apply_mass_rebook , return status: '
8201 || l_return_status
8202 );
8203 END IF;
8204
8205 IF l_return_status <> g_ret_sts_success
8206 THEN
8207 -- Mass Rebook failed for the contract CONTRACT_NUMBER
8208 okl_api.set_message
8209 (p_app_name => g_app_name,
8210 p_msg_name => 'OKL_AM_MASS_REBOOK_FAILED',
8211 p_token1 => 'CONTRACT_NUMBER',
8212 p_token1_value => p_term_rec.p_contract_number
8213 );
8214 RAISE okl_api.g_exception_error;
8215 -- RMUNJULU CONTRACT BLOCKING (2)
8216 ELSE
8217 -- Mass Rebook successful
8218 FOR get_trn_details_rec IN
8219 get_trn_details_csr (l_mass_rebook_trx_id)
8220 LOOP
8221 -- Mass Rebook is NOT Processed
8222 IF get_trn_details_rec.tsu_code <> 'PROCESSED'
8223 THEN
8224 x_mrbk_success := g_ret_sts_error;
8225 END IF;
8226 END LOOP;
8227 END IF;
8228 END IF;
8229
8230 -- Set the x_return_status
8231 x_return_status := l_return_status;
8232
8233
8234
8235 -- RBRUNO BUG 6801022 START : UPDATE TERMINATION QUOTES FROM STATUS ACCEPTED
8236
8237
8238 IF (is_debug_statement_on) THEN
8239 okl_debug_pub.log_debug (g_level_statement,
8240 l_module_name,
8241 'Invoking updating quote status');
8242 end if;
8243
8244 --IF TERM QUOTE IN STATUS ACCEPTED EXISTS, UPDATE IT TO COMPLETE
8245 update_quote_status(p_term_rec);
8246
8247 IF (is_debug_statement_on) THEN
8248 okl_debug_pub.log_debug (g_level_statement,
8249 l_module_name,
8250 'post updating quote status');
8251 end if;
8252 -- RBRUNO BUG 6801022 END : UPDATE TERMINATION QUOTES FROM STATUS ACCEPTED
8253
8254
8255
8256
8257
8258
8259
8260 IF (is_debug_procedure_on)
8261 THEN
8262 okl_debug_pub.log_debug (g_level_procedure,
8263 l_module_name,
8264 'End(-)'
8265 );
8266 END IF;
8267 EXCEPTION
8268 WHEN okl_api.g_exception_error
8269 THEN
8270 IF l_okclines_csr%ISOPEN
8271 THEN
8272 CLOSE l_okclines_csr;
8273 END IF;
8274
8275 -- RMUNJULU 14-FEB-03 2804703 Added IF to check if cursor still open
8276 IF l_k_details_csr%ISOPEN
8277 THEN
8278 CLOSE l_k_details_csr;
8279 END IF;
8280
8281 -- RMUNJULU Bug # 2484327 added code to rollback to savepoint and set
8282 -- return status
8283 ROLLBACK TO mass_rebook;
8284 x_return_status := g_ret_sts_error;
8285 -- RMUNJULU CONTRACT BLOCKING
8286 x_mrbk_success := g_ret_sts_error;
8287
8288 IF (is_debug_exception_on)
8289 THEN
8290 okl_debug_pub.log_debug (g_level_exception,
8291 l_module_name,
8292 'EXCEPTION :' || 'G_EXCEPTION_ERROR'
8293 );
8294 END IF;
8295 WHEN okl_api.g_exception_unexpected_error
8296 THEN
8297 IF l_okclines_csr%ISOPEN
8298 THEN
8299 CLOSE l_okclines_csr;
8300 END IF;
8301
8302 -- RMUNJULU 14-FEB-03 2804703 Added IF to check if cursor still open
8303 IF l_k_details_csr%ISOPEN
8304 THEN
8305 CLOSE l_k_details_csr;
8306 END IF;
8307
8308 -- RMUNJULU Bug # 2484327 added code to rollback to savepoint and set
8309 -- return status
8310 ROLLBACK TO mass_rebook;
8311 x_return_status := g_ret_sts_unexp_error;
8312 -- RMUNJULU CONTRACT BLOCKING
8313 x_mrbk_success := g_ret_sts_error;
8314
8315 IF (is_debug_exception_on)
8316 THEN
8317 okl_debug_pub.log_debug (g_level_exception,
8318 l_module_name,
8319 'EXCEPTION :'
8320 || 'G_EXCEPTION_UNEXPECTED_ERROR'
8321 );
8322 END IF;
8323 WHEN OTHERS
8324 THEN
8325 IF l_okclines_csr%ISOPEN
8326 THEN
8327 CLOSE l_okclines_csr;
8328 END IF;
8329
8330 -- RMUNJULU 14-FEB-03 2804703 Added IF to check if cursor still open
8331 IF l_k_details_csr%ISOPEN
8332 THEN
8333 CLOSE l_k_details_csr;
8334 END IF;
8335
8336 -- RMUNJULU Bug # 2484327 added code to rollback to savepoint and set
8337 -- return status
8338 ROLLBACK TO mass_rebook;
8339 x_return_status := g_ret_sts_unexp_error;
8340 -- RMUNJULU CONTRACT BLOCKING
8341 x_mrbk_success := g_ret_sts_error;
8342 -- Set the oracle error message
8343 okl_api.set_message (p_app_name => g_app_name_1,
8344 p_msg_name => g_unexpected_error,
8345 p_token1 => g_sqlcode_token,
8346 p_token1_value => SQLCODE,
8347 p_token2 => g_sqlerrm_token,
8348 p_token2_value => SQLERRM
8349 );
8350
8351 IF (is_debug_exception_on)
8352 THEN
8353 okl_debug_pub.log_debug (g_level_exception,
8354 l_module_name,
8355 'EXCEPTION :'
8356 || 'OTHERS, SQLCODE: '
8357 || SQLCODE
8358 || ' , SQLERRM : '
8359 || SQLERRM
8360 );
8361 END IF;
8362 END mass_rebook;
8363
8364 -- Start of comments
8365 --
8366 -- Procedure Name : cancel_activate_insurance
8367 -- Desciption : Will cancel and reactivate the insurances for the contract
8368 -- Business Rules :
8369 -- Parameters :
8370 -- Version : 1.0
8371 -- History : RMUNJULU -- 04-DEC-02 Bug # 2484327
8372 -- Changed code to set savepoint instead of start/end activity
8373 -- : RMUNJULU 14-FEB-03 2804703 Added code to check if contract
8374 -- is EVERGREEN
8375 -- : RMUNJULU 03-MAR-03 2830997 Fixed the exception block
8376 --
8377 -- End of comments
8378 PROCEDURE cancel_activate_insurance (
8379 p_api_version IN NUMBER,
8380 p_init_msg_list IN VARCHAR2,
8381 x_msg_count OUT NOCOPY NUMBER,
8382 x_msg_data OUT NOCOPY VARCHAR2,
8383 x_return_status OUT NOCOPY VARCHAR2,
8384 p_term_rec IN term_rec_type,
8385 p_sys_date IN DATE,
8386 p_klev_tbl IN klev_tbl_type
8387 )
8388 IS
8389 -- Cursor to get the end date of contract
8390 -- RMUNJULU 14-FEB-03 2804703 Added code to get sts_code
8391 CURSOR k_end_date_csr (
8392 p_chr_id IN NUMBER
8393 )
8394 IS
8395 SELECT khr.end_date end_date,
8396 khr.sts_code sts_code
8397 FROM okc_k_headers_v khr
8398 WHERE khr.ID = p_chr_id;
8399
8400 l_k_end_date DATE;
8401 l_return_status VARCHAR2 (1) := g_ret_sts_success;
8402 l_early_termination_yn VARCHAR2 (1) := g_no;
8403 i NUMBER;
8404 l_api_name VARCHAR2 (30) := 'cancel_act_insurance';
8405 l_module_name VARCHAR2 (500)
8406 := g_module_name || 'cancel_activate_insurance';
8407 is_debug_exception_on BOOLEAN
8408 := okl_debug_pub.check_log_on (l_module_name, g_level_exception);
8409 is_debug_procedure_on BOOLEAN
8410 := okl_debug_pub.check_log_on (l_module_name, g_level_procedure);
8411 is_debug_statement_on BOOLEAN
8412 := okl_debug_pub.check_log_on (l_module_name, g_level_statement);
8413 l_api_version CONSTANT NUMBER := 1;
8414 -- RMUNJULU 14-FEB-03 2804703 Added variable
8415 l_sts_code VARCHAR2 (200);
8416 BEGIN
8417 -- RMUNJULU Bug # 2484327, added code to set savepoint
8418 -- Start a savepoint to rollback to if error in this block
8419 SAVEPOINT cancel_activate_insurance;
8420
8421 IF (is_debug_procedure_on)
8422 THEN
8423 okl_debug_pub.log_debug (g_level_procedure,
8424 l_module_name,
8425 'Begin(+)'
8426 );
8427 END IF;
8428
8429 IF (is_debug_statement_on)
8430 THEN
8431 okl_debug_pub.log_debug (g_level_statement,
8432 l_module_name,
8433 'In param, p_sys_date: ' || p_sys_date
8434 );
8435 okl_debug_pub.log_debug
8436 (g_level_statement,
8437 l_module_name,
8438 'In param, p_term_rec.p_early_termination_yn: '
8439 || p_term_rec.p_early_termination_yn
8440 );
8441 okl_debug_pub.log_debug (g_level_statement,
8442 l_module_name,
8443 'In param, p_term_rec.p_contract_id: '
8444 || p_term_rec.p_contract_id
8445 );
8446 END IF;
8447
8448 -- Get k end date
8449 -- RMUNJULU 14-FEB-03 2804703 Added sts_code
8450 OPEN k_end_date_csr (p_term_rec.p_contract_id);
8451
8452 FETCH k_end_date_csr
8453 INTO l_k_end_date,
8454 l_sts_code;
8455
8456 CLOSE k_end_date_csr;
8457
8458 -- check if early termination
8459 IF TRUNC (l_k_end_date) > TRUNC (p_sys_date)
8460 THEN
8461 l_early_termination_yn := g_yes;
8462 END IF;
8463
8464 -- if early termination then
8465 -- RMUNJULU 14-FEB-03 2804703 Added condition to check if contract not
8466 -- already evergreen
8467 IF ( NVL (p_term_rec.p_early_termination_yn, '?') = g_yes
8468 OR l_early_termination_yn = g_yes
8469 )
8470 AND l_sts_code <> 'EVERGREEN'
8471 THEN
8472 IF (is_debug_statement_on)
8473 THEN
8474 okl_debug_pub.log_debug
8475 (g_level_statement,
8476 l_module_name,
8477 'calling OKL_INSURANCE_POLICIES_PUB.cancel_create_policies'
8478 );
8479 END IF;
8480
8481 -- cancel and reactivate insurances
8482 okl_insurance_policies_pub.cancel_create_policies
8483 (p_api_version => p_api_version,
8484 p_init_msg_list => g_false,
8485 x_return_status => l_return_status,
8486 x_msg_count => x_msg_count,
8487 x_msg_data => x_msg_data,
8488 p_khr_id => p_term_rec.p_contract_id,
8489 p_cancellation_date => p_sys_date,
8490 p_transaction_id => NULL
8491 );
8492
8493 IF (is_debug_statement_on)
8494 THEN
8495 okl_debug_pub.log_debug
8496 (g_level_statement,
8497 l_module_name,
8498 'called OKL_INSURANCE_POLICIES_PUB.cancel_create_policies , return status: '
8499 || l_return_status
8500 );
8501 END IF;
8502
8503 IF l_return_status <> g_ret_sts_success
8504 THEN
8505 -- Error in cancelling Insurance.
8506 okl_api.set_message (p_app_name => g_app_name,
8507 p_msg_name => 'OKL_AM_ERR_CAN_INS');
8508 END IF;
8509
8510 -- Raise exception to rollback to the savepoint
8511 IF (l_return_status = g_ret_sts_unexp_error)
8512 THEN
8513 RAISE okl_api.g_exception_unexpected_error;
8514 ELSIF (l_return_status = g_ret_sts_error)
8515 THEN
8516 RAISE okl_api.g_exception_error;
8517 END IF;
8518 END IF;
8519
8520 -- Set the return status
8521 x_return_status := l_return_status;
8522
8523 IF (is_debug_procedure_on)
8524 THEN
8525 okl_debug_pub.log_debug (g_level_procedure,
8526 l_module_name,
8527 'End(-)'
8528 );
8529 END IF;
8530 EXCEPTION
8531 WHEN okl_api.g_exception_error
8532 THEN
8533 -- RMUNJULU 03-MAR-03 2830997 Changed NOTFOUND to ISOPEN
8534 IF k_end_date_csr%ISOPEN
8535 THEN
8536 CLOSE k_end_date_csr;
8537 END IF;
8538
8539 -- RMUNJULU Bug # 2484327 added code to rollback to savepoint and set
8540 -- return status
8541 ROLLBACK TO cancel_activate_insurance;
8542 x_return_status := g_ret_sts_error;
8543
8544 IF (is_debug_exception_on)
8545 THEN
8546 okl_debug_pub.log_debug (g_level_exception,
8547 l_module_name,
8548 'EXCEPTION :' || 'G_EXCEPTION_ERROR'
8549 );
8550 END IF;
8551 WHEN okl_api.g_exception_unexpected_error
8552 THEN
8553 -- RMUNJULU 03-MAR-03 2830997 Changed NOTFOUND to ISOPEN
8554 IF k_end_date_csr%ISOPEN
8555 THEN
8556 CLOSE k_end_date_csr;
8557 END IF;
8558
8559 -- RMUNJULU Bug # 2484327 added code to rollback to savepoint and set
8560 -- return status
8561 ROLLBACK TO cancel_activate_insurance;
8562 x_return_status := g_ret_sts_unexp_error;
8563
8564 IF (is_debug_exception_on)
8565 THEN
8566 okl_debug_pub.log_debug (g_level_exception,
8567 l_module_name,
8568 'EXCEPTION :'
8569 || 'G_EXCEPTION_UNEXPECTED_ERROR'
8570 );
8571 END IF;
8572 WHEN OTHERS
8573 THEN
8574 -- RMUNJULU 03-MAR-03 2830997 Changed NOTFOUND to ISOPEN
8575 IF k_end_date_csr%ISOPEN
8576 THEN
8577 CLOSE k_end_date_csr;
8578 END IF;
8579
8580 -- RMUNJULU Bug # 2484327 added code to rollback to savepoint and set
8581 -- return status
8582 ROLLBACK TO cancel_activate_insurance;
8583 x_return_status := g_ret_sts_unexp_error;
8584 -- Set the oracle error message
8585 okl_api.set_message (p_app_name => g_app_name_1,
8586 p_msg_name => g_unexpected_error,
8587 p_token1 => g_sqlcode_token,
8588 p_token1_value => SQLCODE,
8589 p_token2 => g_sqlerrm_token,
8590 p_token2_value => SQLERRM
8591 );
8592
8593 IF (is_debug_exception_on)
8594 THEN
8595 okl_debug_pub.log_debug (g_level_exception,
8596 l_module_name,
8597 'EXCEPTION :'
8598 || 'OTHERS, SQLCODE: '
8599 || SQLCODE
8600 || ' , SQLERRM : '
8601 || SQLERRM
8602 );
8603 END IF;
8604 END cancel_activate_insurance;
8605
8606 -- Start of comments
8607 --
8608 -- Procedure Name : reverse_loss_provisions
8609 -- Desciption : Will reverse the non-incomes and loss provisions for contract
8610 -- Business Rules :
8611 -- Parameters :
8612 -- Version : 1.0
8613 -- History : RMUNJULU 09-JAN-03 2743604 Created
8614 -- : RMUNJULU 03-MAR-03 2830997 Fixed the exception block
8615 -- : RMUNJULU Bug # 3097068 20-AUG-03 Added code to pass
8616 -- valid GL date to REVERSE LOSS PROVISIONS
8617 -- : RMUNJULU Bug # 3148215 19-SEP-03 Added code to pass
8618 -- valid GL date to CATCHUP OF ACCRUALS
8619 --
8620 -- End of comments
8621 PROCEDURE reverse_loss_provisions (
8622 p_api_version IN NUMBER,
8623 p_init_msg_list IN VARCHAR2,
8624 x_msg_count OUT NOCOPY NUMBER,
8625 x_msg_data OUT NOCOPY VARCHAR2,
8626 x_return_status OUT NOCOPY VARCHAR2,
8627 p_term_rec IN term_rec_type,
8628 p_sys_date IN DATE,
8629 px_msg_tbl IN OUT NOCOPY g_msg_tbl
8630 )
8631 IS
8632 -- Cursor to get the product of the contract
8633 CURSOR prod_id_csr (
8634 p_khr_id IN NUMBER
8635 )
8636 IS
8637 SELECT A.pdt_id, A.MULTI_GAAP_YN, B.REPORTING_PDT_ID
8638 FROM okl_k_headers_v A,
8639 okl_products B
8640 WHERE A.ID = p_khr_id
8641 AND B.ID = A.pdt_id; -- MGAAP 7263041
8642
8643 l_return_status VARCHAR2 (1) := g_ret_sts_success;
8644 l_try_id NUMBER;
8645 l_trans_meaning VARCHAR2 (200);
8646 l_pdt_id NUMBER := 0;
8647
8648 -- MGAAP 7263041 start
8649 l_reporting_pdt_id NUMBER := 0;
8650 l_multi_gaap_yn okl_k_headers.MULTI_GAAP_YN%TYPE := null;
8651 l_valid_gl_date_rep DATE;
8652 l_sob_id_rep NUMBER;
8653 -- MGAAP 7263041 end
8654
8655 l_catchup_rec okl_generate_accruals_pub.accrual_rec_type;
8656 lx_tcnv_tbl okl_trx_contracts_pub.tcnv_tbl_type;
8657 lx_tclv_tbl okl_trx_contracts_pub.tclv_tbl_type;
8658 l_lprv_rec okl_rev_loss_prov_pub.lprv_rec_type;
8659 l_count NUMBER;
8660 l_module_name VARCHAR2 (500)
8661 := g_module_name || 'reverse_loss_provisions';
8662 is_debug_exception_on BOOLEAN
8663 := okl_debug_pub.check_log_on (l_module_name, g_level_exception);
8664 is_debug_procedure_on BOOLEAN
8665 := okl_debug_pub.check_log_on (l_module_name, g_level_procedure);
8666 is_debug_statement_on BOOLEAN
8667 := okl_debug_pub.check_log_on (l_module_name, g_level_statement);
8668 -- Bug 3097068
8669 l_valid_gl_date DATE;
8670 BEGIN
8671 -- Start a savepoint to rollback to if error in this block
8672 SAVEPOINT reverse_loss_provisions;
8673
8674 IF (is_debug_procedure_on)
8675 THEN
8676 okl_debug_pub.log_debug (g_level_procedure,
8677 l_module_name,
8678 'Begin(+)'
8679 );
8680 END IF;
8681
8682 IF (is_debug_statement_on)
8683 THEN
8684 okl_debug_pub.log_debug (g_level_statement,
8685 l_module_name,
8686 'In param, p_sys_date: ' || p_sys_date
8687 );
8688 okl_debug_pub.log_debug (g_level_statement,
8689 l_module_name,
8690 'In param, p_term_rec.p_contract_id: '
8691 || p_term_rec.p_contract_id
8692 );
8693 okl_debug_pub.log_debug
8694 (g_level_statement,
8695 l_module_name,
8696 'In param, p_term_rec.p_contract_number: '
8697 || p_term_rec.p_contract_number
8698 );
8699 END IF;
8700
8701 -- *************
8702 -- REVERSAL OF NON-INCOME
8703 -- *************
8704 IF (is_debug_statement_on)
8705 THEN
8706 okl_debug_pub.log_debug
8707 (g_level_statement,
8708 l_module_name,
8709 'calling OKL_AM_UTIL_PVT.get_transaction_id'
8710 );
8711 END IF;
8712
8713 -- Get the transaction id for Accrual
8714 okl_am_util_pvt.get_transaction_id (p_try_name => 'Accrual',
8715 x_return_status => l_return_status,
8716 x_try_id => l_try_id
8717 );
8718
8719 IF (is_debug_statement_on)
8720 THEN
8721 okl_debug_pub.log_debug
8722 (g_level_statement,
8723 l_module_name,
8724 'called OKL_AM_UTIL_PVT.get_transaction_id , return status: '
8725 || l_return_status
8726 );
8727 okl_debug_pub.log_debug (g_level_statement,
8728 l_module_name,
8729 'l_try_id: ' || l_try_id
8730 );
8731 END IF;
8732
8733 -- Get the meaning of lookup
8734 l_trans_meaning :=
8735 okl_am_util_pvt.get_lookup_meaning
8736 (p_lookup_type => 'OKL_ACCOUNTING_EVENT_TYPE',
8737 p_lookup_code => 'ACCRUAL',
8738 p_validate_yn => 'Y'
8739 );
8740
8741 IF l_return_status <> g_ret_sts_success
8742 THEN
8743 -- Unable to find a transaction type for
8744 -- the transaction TRY_NAME
8745 okl_api.set_message (p_app_name => g_app_name,
8746 p_msg_name => 'OKL_AM_NO_TRX_TYPE_FOUND',
8747 p_token1 => 'TRY_NAME',
8748 p_token1_value => l_trans_meaning
8749 );
8750 -- Unable to do reversal of non-income during termination
8751 -- of contract CONTRACT_NUMBER.
8752 okl_api.set_message (p_app_name => g_app_name,
8753 p_msg_name => 'OKL_AM_REV_NONINC_ERR',
8754 p_token1 => 'CONTRACT_NUMBER',
8755 p_token1_value => p_term_rec.p_contract_number
8756 );
8757 END IF;
8758
8759 -- Raise exception to rollback this whole block
8760 IF (l_return_status = g_ret_sts_unexp_error)
8761 THEN
8762 RAISE okl_api.g_exception_unexpected_error;
8763 ELSIF (l_return_status = g_ret_sts_error)
8764 THEN
8765 RAISE okl_api.g_exception_error;
8766 END IF;
8767
8768 -- get the product id
8769 OPEN prod_id_csr (p_term_rec.p_contract_id);
8770
8771 FETCH prod_id_csr
8772 INTO l_pdt_id,
8773 l_multi_gaap_yn,
8774 l_reporting_pdt_id; -- MGAAP 7263041
8775
8776 CLOSE prod_id_csr;
8777
8778 -- raise error if no pdt_id
8779 IF l_pdt_id IS NULL OR l_pdt_id = 0
8780 THEN
8781 -- Unable to do reversal of non-income during termination
8782 -- of contract CONTRACT_NUMBER.
8783 okl_api.set_message (p_app_name => g_app_name,
8784 p_msg_name => 'OKL_AM_REV_NONINC_ERR',
8785 p_token1 => 'CONTRACT_NUMBER',
8786 p_token1_value => p_term_rec.p_contract_number
8787 );
8788 RAISE okl_api.g_exception_error;
8789 END IF;
8790
8791 -- Bug 3097068 Added to get the valid GL date
8792 l_valid_gl_date :=
8793 okl_accounting_util.get_valid_gl_date (p_gl_date => p_sys_date);
8794 -- Set the l_catchup_rec rec type
8795 l_catchup_rec.contract_id := p_term_rec.p_contract_id;
8796 l_catchup_rec.accrual_date := l_valid_gl_date; -- RMUNJULU 3148215
8797 l_catchup_rec.contract_number := p_term_rec.p_contract_number;
8798 l_catchup_rec.rule_result := g_yes;
8799 l_catchup_rec.override_status := g_no;
8800 l_catchup_rec.product_id := l_pdt_id;
8801 l_catchup_rec.trx_type_id := l_try_id;
8802 l_catchup_rec.advance_arrears := NULL;
8803 l_catchup_rec.factoring_synd_flag := NULL;
8804 l_catchup_rec.post_to_gl := g_yes;
8805 l_catchup_rec.gl_reversal_flag := g_no;
8806 l_catchup_rec.memo_yn := g_no;
8807 l_catchup_rec.description :=
8808 'Catchup of income on termination of the contract';
8809
8810 IF (is_debug_statement_on)
8811 THEN
8812 okl_debug_pub.log_debug
8813 (g_level_statement,
8814 l_module_name,
8815 'calling OKL_GENERATE_ACCRUALS_PUB.catchup_accruals'
8816 );
8817 END IF;
8818
8819 -- Do reversal of non-income
8820 okl_generate_accruals_pub.catchup_accruals
8821 (p_api_version => p_api_version,
8822 p_init_msg_list => g_false,
8823 x_return_status => l_return_status,
8824 x_msg_count => x_msg_count,
8825 x_msg_data => x_msg_data,
8826 p_catchup_rec => l_catchup_rec,
8827 x_tcnv_tbl => lx_tcnv_tbl,
8828 x_tclv_tbl => lx_tclv_tbl
8829 );
8830
8831 IF (is_debug_statement_on)
8832 THEN
8833 okl_debug_pub.log_debug
8834 (g_level_statement,
8835 l_module_name,
8836 'called OKL_GENERATE_ACCRUALS_PUB.catchup_accruals , return status: '
8837 || l_return_status
8838 );
8839 END IF;
8840
8841 IF l_return_status <> g_ret_sts_success
8842 THEN
8843 -- Unable to do reversal of non-income during termination
8844 -- of contract CONTRACT_NUMBER.
8845 okl_api.set_message (p_app_name => g_app_name,
8846 p_msg_name => 'OKL_AM_REV_NONINC_ERR',
8847 p_token1 => 'CONTRACT_NUMBER',
8848 p_token1_value => p_term_rec.p_contract_number
8849 );
8850 END IF;
8851
8852 -- Raise exception to rollback this whole block
8853 IF (l_return_status = g_ret_sts_unexp_error)
8854 THEN
8855 RAISE okl_api.g_exception_unexpected_error;
8856 ELSIF (l_return_status = g_ret_sts_error)
8857 THEN
8858 RAISE okl_api.g_exception_error;
8859 END IF;
8860
8861 -- Bug 7263041 start
8862
8863 IF (l_multi_gaap_yn = 'Y') THEN
8864
8865 l_sob_id_rep := Okl_Accounting_Util.GET_SET_OF_BOOKS_ID(
8866 p_representation_type => 'SECONDARY');
8867
8868 l_valid_gl_date_rep :=
8869 okl_accounting_util.get_valid_gl_date (
8870 p_gl_date => p_sys_date,
8871 p_ledger_id => l_sob_id_rep
8872 );
8873 l_catchup_rec.product_id := l_reporting_pdt_id;
8874 l_catchup_rec.accrual_date := l_valid_gl_date_rep;
8875
8876 IF (is_debug_statement_on)
8877 THEN
8878 okl_debug_pub.log_debug
8879 (g_level_statement,
8880 l_module_name,
8881 'calling OKL_GENERATE_ACCRUALS_PUB.catchup_accruals for SECONDARY'
8882 );
8883 END IF;
8884
8885 -- Do reversal of non-income
8886 okl_generate_accruals_pub.catchup_accruals
8887 (p_api_version => p_api_version,
8888 p_init_msg_list => g_false,
8889 x_return_status => l_return_status,
8890 x_msg_count => x_msg_count,
8891 x_msg_data => x_msg_data,
8892 p_catchup_rec => l_catchup_rec,
8893 x_tcnv_tbl => lx_tcnv_tbl,
8894 x_tclv_tbl => lx_tclv_tbl,
8895 p_representation_type => 'SECONDARY'
8896 );
8897
8898 IF (is_debug_statement_on)
8899 THEN
8900 okl_debug_pub.log_debug
8901 (g_level_statement,
8902 l_module_name,
8903 'called OKL_GENERATE_ACCRUALS_PUB.catchup_accruals for SECONDARY, return status: '
8904 || l_return_status
8905 );
8906 END IF;
8907
8908 IF l_return_status <> g_ret_sts_success
8909 THEN
8910 -- Unable to do reversal of non-income during termination
8911 -- of contract CONTRACT_NUMBER.
8912 okl_api.set_message (p_app_name => g_app_name,
8913 p_msg_name => 'OKL_AM_REV_NONINC_ERR',
8914 p_token1 => 'CONTRACT_NUMBER',
8915 p_token1_value => p_term_rec.p_contract_number
8916 );
8917 END IF;
8918
8919 -- Raise exception to rollback this whole block
8920 IF (l_return_status = g_ret_sts_unexp_error)
8921 THEN
8922 RAISE okl_api.g_exception_unexpected_error;
8923 ELSIF (l_return_status = g_ret_sts_error)
8924 THEN
8925 RAISE okl_api.g_exception_error;
8926 END IF;
8927
8928
8929 END IF;
8930 -- Bug 7263041 end
8931
8932 -- *************
8933 -- REVERSAL OF LOSS-PROVISIONS
8934 -- *************
8935
8936 -- Set the l_lprv_rec rec type
8937 l_lprv_rec.cntrct_num := p_term_rec.p_contract_number;
8938 l_lprv_rec.reversal_type := NULL;
8939 -- RMUNJULU 3097068 Added code to set the reversal date with valid GL date
8940 l_lprv_rec.reversal_date := l_valid_gl_date;
8941
8942 IF (is_debug_statement_on)
8943 THEN
8944 okl_debug_pub.log_debug
8945 (g_level_statement,
8946 l_module_name,
8947 'calling OKL_REV_LOSS_PROV_PUB.reverse_loss_provisions'
8948 );
8949 END IF;
8950
8951 -- Do reversal of loss provisions
8952 okl_rev_loss_prov_pub.reverse_loss_provisions
8953 (p_api_version => p_api_version,
8954 p_init_msg_list => g_false,
8955 x_return_status => l_return_status,
8956 x_msg_count => x_msg_count,
8957 x_msg_data => x_msg_data,
8958 p_lprv_rec => l_lprv_rec
8959 );
8960
8961 IF (is_debug_statement_on)
8962 THEN
8963 okl_debug_pub.log_debug
8964 (g_level_statement,
8965 l_module_name,
8966 'called OKL_REV_LOSS_PROV_PUB.reverse_loss_provisions , return status: '
8967 || l_return_status
8968 );
8969 END IF;
8970
8971 IF l_return_status <> g_ret_sts_success
8972 THEN
8973 -- Unable to do reversal of loss provisions during
8974 -- termination of contract CONTRACT_NUMBER.
8975 okl_api.set_message (p_app_name => g_app_name,
8976 p_msg_name => 'OKL_AM_REV_LOSPROV_ERR',
8977 p_token1 => 'CONTRACT_NUMBER',
8978 p_token1_value => p_term_rec.p_contract_number
8979 );
8980 END IF;
8981
8982 -- Raise exception to rollback this whole block
8983 IF (l_return_status = g_ret_sts_unexp_error)
8984 THEN
8985 RAISE okl_api.g_exception_unexpected_error;
8986 ELSIF (l_return_status = g_ret_sts_error)
8987 THEN
8988 RAISE okl_api.g_exception_error;
8989 END IF;
8990
8991 -- Set the success messages to message table
8992 l_count := px_msg_tbl.COUNT;
8993 -- Reversal of non-income during termination
8994 -- of contract CONTRACT_NUMBER done successfully.
8995 px_msg_tbl (l_count).msg_desc := 'OKL_AM_REV_NONINC_SUC';
8996 px_msg_tbl (l_count).msg_token1 := 'CONTRACT_NUMBER';
8997 px_msg_tbl (l_count).msg_token1_value := p_term_rec.p_contract_number;
8998 l_count := l_count + 1;
8999 -- Reversal of loss provisions during
9000 -- termination of contract CONTRACT_NUMBER done successfully.
9001 px_msg_tbl (l_count).msg_desc := 'OKL_AM_REV_LOSPROV_SUC';
9002 px_msg_tbl (l_count).msg_token1 := 'CONTRACT_NUMBER';
9003 px_msg_tbl (l_count).msg_token1_value := p_term_rec.p_contract_number;
9004 l_count := l_count + 1;
9005 -- Set the return status
9006 x_return_status := l_return_status;
9007
9008 IF (is_debug_procedure_on)
9009 THEN
9010 okl_debug_pub.log_debug (g_level_procedure,
9011 l_module_name,
9012 'End(-)'
9013 );
9014 END IF;
9015 EXCEPTION
9016 WHEN okl_api.g_exception_error
9017 THEN
9018 -- RMUNJULU 03-MAR-03 2830997 Changed NOTFOUND to ISOPEN
9019 IF prod_id_csr%ISOPEN
9020 THEN
9021 CLOSE prod_id_csr;
9022 END IF;
9023
9024 ROLLBACK TO reverse_loss_provisions;
9025 x_return_status := g_ret_sts_error;
9026
9027 IF (is_debug_exception_on)
9028 THEN
9029 okl_debug_pub.log_debug (g_level_exception,
9030 l_module_name,
9031 'EXCEPTION :' || 'G_EXCEPTION_ERROR'
9032 );
9033 END IF;
9034 WHEN okl_api.g_exception_unexpected_error
9035 THEN
9036 -- RMUNJULU 03-MAR-03 2830997 Changed NOTFOUND to ISOPEN
9037 IF prod_id_csr%ISOPEN
9038 THEN
9039 CLOSE prod_id_csr;
9040 END IF;
9041
9042 ROLLBACK TO reverse_loss_provisions;
9043 x_return_status := g_ret_sts_unexp_error;
9044
9045 IF (is_debug_exception_on)
9046 THEN
9047 okl_debug_pub.log_debug (g_level_exception,
9048 l_module_name,
9049 'EXCEPTION :'
9050 || 'G_EXCEPTION_UNEXPECTED_ERROR'
9051 );
9052 END IF;
9053 WHEN OTHERS
9054 THEN
9055 -- RMUNJULU 03-MAR-03 2830997 Changed NOTFOUND to ISOPEN
9056 IF prod_id_csr%ISOPEN
9057 THEN
9058 CLOSE prod_id_csr;
9059 END IF;
9060
9061 ROLLBACK TO reverse_loss_provisions;
9062 x_return_status := g_ret_sts_unexp_error;
9063 -- Set the oracle error message
9064 okl_api.set_message (p_app_name => g_app_name_1,
9065 p_msg_name => g_unexpected_error,
9066 p_token1 => g_sqlcode_token,
9067 p_token1_value => SQLCODE,
9068 p_token2 => g_sqlerrm_token,
9069 p_token2_value => SQLERRM
9070 );
9071
9072 IF (is_debug_exception_on)
9073 THEN
9074 okl_debug_pub.log_debug (g_level_exception,
9075 l_module_name,
9076 'EXCEPTION :'
9077 || 'OTHERS, SQLCODE: '
9078 || SQLCODE
9079 || ' , SQLERRM : '
9080 || SQLERRM
9081 );
9082 END IF;
9083 END reverse_loss_provisions;
9084
9085 -- Start of comments
9086 --
9087 -- Procedure Name : cancel_insurance
9088 -- Desciption : Will cancel the insurances for the contract
9089 -- Business Rules :
9090 -- Parameters :
9091 -- Version : 1.0
9092 -- History : RMUNJULU -- 20-DEC-02 2484327 Created
9093 -- : RMUNJULU 14-FEB-03 2804703 Added code to check if contract
9094 -- is EVERGREEN
9095 -- : RMUNJULU 03-MAR-03 2830997 Fixed the exception block
9096 --
9097 -- End of comments
9098 PROCEDURE cancel_insurance (
9099 p_api_version IN NUMBER,
9100 p_init_msg_list IN VARCHAR2,
9101 x_msg_count OUT NOCOPY NUMBER,
9102 x_msg_data OUT NOCOPY VARCHAR2,
9103 x_return_status OUT NOCOPY VARCHAR2,
9104 p_term_rec IN term_rec_type,
9105 p_sys_date IN DATE,
9106 p_klev_tbl IN klev_tbl_type
9107 )
9108 IS
9109 -- Cursor to get the end date of contract
9110 -- RMUNJULU 14-FEB-03 2804703 Added code to get sts_code
9111 CURSOR k_end_date_csr (
9112 p_chr_id IN NUMBER
9113 )
9114 IS
9115 SELECT khr.end_date end_date,
9116 khr.sts_code sts_code
9117 FROM okc_k_headers_v khr
9118 WHERE khr.ID = p_chr_id;
9119
9120 l_k_end_date DATE;
9121 l_return_status VARCHAR2 (1) := g_ret_sts_success;
9122 l_early_termination_yn VARCHAR2 (1) := g_no;
9123 i NUMBER;
9124 l_api_name VARCHAR2 (30) := 'cancel_insurance';
9125 l_api_version CONSTANT NUMBER := 1;
9126 l_module_name VARCHAR2 (500)
9127 := g_module_name || 'cancel_insurance';
9128 is_debug_exception_on BOOLEAN
9129 := okl_debug_pub.check_log_on (l_module_name, g_level_exception);
9130 is_debug_procedure_on BOOLEAN
9131 := okl_debug_pub.check_log_on (l_module_name, g_level_procedure);
9132 is_debug_statement_on BOOLEAN
9133 := okl_debug_pub.check_log_on (l_module_name, g_level_statement);
9134 -- RMUNJULU 14-FEB-03 2804703 Added variable
9135 l_sts_code VARCHAR2 (200);
9136 BEGIN
9137 -- Start a savepoint to rollback to if error in this block
9138 SAVEPOINT cancel_insurance;
9139
9140 IF (is_debug_procedure_on)
9141 THEN
9142 okl_debug_pub.log_debug (g_level_procedure,
9143 l_module_name,
9144 'Begin(+)'
9145 );
9146 END IF;
9147
9148 IF (is_debug_statement_on)
9149 THEN
9150 okl_debug_pub.log_debug (g_level_statement,
9151 l_module_name,
9152 'In param, p_sys_date: ' || p_sys_date
9153 );
9154 okl_debug_pub.log_debug (g_level_statement,
9155 l_module_name,
9156 'In param, p_term_rec.p_contract_id: '
9157 || p_term_rec.p_contract_id
9158 );
9159 okl_debug_pub.log_debug
9160 (g_level_statement,
9161 l_module_name,
9162 'In param, p_term_rec.p_early_termination_yn: '
9163 || p_term_rec.p_early_termination_yn
9164 );
9165 END IF;
9166
9167 -- Get k end date
9168 -- RMUNJULU 14-FEB-03 2804703 Added sts_code
9169 OPEN k_end_date_csr (p_term_rec.p_contract_id);
9170
9171 FETCH k_end_date_csr
9172 INTO l_k_end_date,
9173 l_sts_code;
9174
9175 CLOSE k_end_date_csr;
9176
9177 -- check if early termination
9178 IF TRUNC (l_k_end_date) > TRUNC (p_sys_date)
9179 THEN
9180 l_early_termination_yn := g_yes;
9181 END IF;
9182
9183 -- if early termination then
9184 -- RMUNJULU 14-FEB-03 2804703 Added condition to check if contract not
9185 -- already evergreen
9186 IF ( NVL (p_term_rec.p_early_termination_yn, '?') = g_yes
9187 OR l_early_termination_yn = g_yes
9188 )
9189 AND l_sts_code <> 'EVERGREEN'
9190 THEN
9191 IF (is_debug_statement_on)
9192 THEN
9193 okl_debug_pub.log_debug
9194 (g_level_statement,
9195 l_module_name,
9196 'calling OKL_INSURANCE_POLICIES_PUB.cancel_policies'
9197 );
9198 END IF;
9199
9200 -- cancel insurances
9201 okl_insurance_policies_pub.cancel_policies
9202 (p_api_version => p_api_version,
9203 p_init_msg_list => g_false,
9204 x_return_status => l_return_status,
9205 x_msg_count => x_msg_count,
9206 x_msg_data => x_msg_data,
9207 p_contract_id => p_term_rec.p_contract_id,
9208 p_cancellation_date => p_sys_date
9209 );
9210
9211 IF (is_debug_statement_on)
9212 THEN
9213 okl_debug_pub.log_debug
9214 (g_level_statement,
9215 l_module_name,
9216 'called OKL_INSURANCE_POLICIES_PUB.cancel_policies , return status: '
9217 || l_return_status
9218 );
9219 END IF;
9220
9221 IF l_return_status <> g_ret_sts_success
9222 THEN
9223 -- Error in cancelling Insurance.
9224 okl_api.set_message (p_app_name => g_app_name,
9225 p_msg_name => 'OKL_AM_ERR_CAN_INS');
9226 END IF;
9227
9228 -- Raise exception to rollback to the savepoint
9229 IF (l_return_status = g_ret_sts_unexp_error)
9230 THEN
9231 RAISE okl_api.g_exception_unexpected_error;
9232 ELSIF (l_return_status = g_ret_sts_error)
9233 THEN
9234 RAISE okl_api.g_exception_error;
9235 END IF;
9236 END IF;
9237
9238 -- Set the return status
9239 x_return_status := l_return_status;
9240
9241 IF (is_debug_procedure_on)
9242 THEN
9243 okl_debug_pub.log_debug (g_level_procedure,
9244 l_module_name,
9245 'End(-)'
9246 );
9247 END IF;
9248 EXCEPTION
9249 WHEN okl_api.g_exception_error
9250 THEN
9251 -- RMUNJULU 03-MAR-03 2830997 Changed NOTFOUND to ISOPEN
9252 IF k_end_date_csr%ISOPEN
9253 THEN
9254 CLOSE k_end_date_csr;
9255 END IF;
9256
9257 ROLLBACK TO cancel_insurance;
9258 x_return_status := g_ret_sts_error;
9259
9260 IF (is_debug_exception_on)
9261 THEN
9262 okl_debug_pub.log_debug (g_level_exception,
9263 l_module_name,
9264 'EXCEPTION :' || 'G_EXCEPTION_ERROR'
9265 );
9266 END IF;
9267 WHEN okl_api.g_exception_unexpected_error
9268 THEN
9269 -- RMUNJULU 03-MAR-03 2830997 Changed NOTFOUND to ISOPEN
9270 IF k_end_date_csr%ISOPEN
9271 THEN
9272 CLOSE k_end_date_csr;
9273 END IF;
9274
9275 ROLLBACK TO cancel_insurance;
9276 x_return_status := g_ret_sts_unexp_error;
9277
9278 IF (is_debug_exception_on)
9279 THEN
9280 okl_debug_pub.log_debug (g_level_exception,
9281 l_module_name,
9282 'EXCEPTION :'
9283 || 'G_EXCEPTION_UNEXPECTED_ERROR'
9284 );
9285 END IF;
9286 WHEN OTHERS
9287 THEN
9288 -- RMUNJULU 03-MAR-03 2830997 Changed NOTFOUND to ISOPEN
9289 IF k_end_date_csr%ISOPEN
9290 THEN
9291 CLOSE k_end_date_csr;
9292 END IF;
9293
9294 ROLLBACK TO cancel_insurance;
9295 x_return_status := g_ret_sts_unexp_error;
9296 -- Set the oracle error message
9297 okl_api.set_message (p_app_name => g_app_name_1,
9298 p_msg_name => g_unexpected_error,
9299 p_token1 => g_sqlcode_token,
9300 p_token1_value => SQLCODE,
9301 p_token2 => g_sqlerrm_token,
9302 p_token2_value => SQLERRM
9303 );
9304
9305 IF (is_debug_exception_on)
9306 THEN
9307 okl_debug_pub.log_debug (g_level_exception,
9308 l_module_name,
9309 'EXCEPTION :'
9310 || 'OTHERS, SQLCODE: '
9311 || SQLCODE
9312 || ' , SQLERRM : '
9313 || SQLERRM
9314 );
9315 END IF;
9316 END cancel_insurance;
9317
9318 -- Start of Commnets
9319 --
9320 -- Procedure Name : validate_chr_cle_id
9321 -- Description : This Local Procedure is used for validation of
9322 -- Chr_id and Asset line.
9323 -- Business Rules :
9324 -- Parameters :
9325 -- Version : 1.0
9326 -- History : RMUNJULU -- 04-DEC-02 Bug # 2484327 Added comments to
9327 -- cursor
9328 -- RMUNJULU 16-DEC-02 Bug # 2484327, changed cursor to get lines
9329 -- which are of the same status as header
9330 --
9331 -- End of Commnets
9332 PROCEDURE validate_chr_cle_id (
9333 p_dnz_chr_id IN okc_k_lines_v.dnz_chr_id%TYPE,
9334 p_top_line_id IN okc_k_lines_v.ID%TYPE,
9335 x_return_status OUT NOCOPY VARCHAR2
9336 )
9337 IS
9338 ln_dummy NUMBER := 0;
9339 l_module_name VARCHAR2 (500)
9340 := g_module_name || 'validate_chr_cle_id';
9341 is_debug_exception_on BOOLEAN
9342 := okl_debug_pub.check_log_on (l_module_name, g_level_exception);
9343 is_debug_procedure_on BOOLEAN
9344 := okl_debug_pub.check_log_on (l_module_name, g_level_procedure);
9345 is_debug_statement_on BOOLEAN
9346 := okl_debug_pub.check_log_on (l_module_name, g_level_statement);
9347
9348 -- RMUNJULU Bug # 2484327 Added comments, changed parameters to IN
9349 -- RMUNJULU 16-DEC-02 Bug # 2484327, get lines which are of the same status as header
9350 -- Cursor to validate the contract and lines to see if they are booked or not
9351 CURSOR l_k_lines_validate_csr (
9352 p_dnz_chr_id IN okc_k_lines_v.dnz_chr_id%TYPE,
9353 p_top_line_id IN okc_k_lines_v.ID%TYPE
9354 )
9355 IS
9356 SELECT 1
9357 FROM DUAL
9358 WHERE EXISTS (
9359 SELECT 1
9360 FROM okc_subclass_top_line stl,
9361 okc_line_styles_v lse,
9362 okc_k_lines_v cle,
9363 okc_k_headers_v khr
9364 WHERE cle.ID = p_top_line_id
9365 AND cle.dnz_chr_id = p_dnz_chr_id
9366 AND cle.cle_id IS NULL
9367 AND cle.chr_id = cle.dnz_chr_id
9368 AND cle.lse_id = lse.ID
9369 AND lse.lty_code = g_fin_line_lty_code
9370 AND lse.lse_type = g_tls_type
9371 AND lse.lse_parent_id IS NULL
9372 AND lse.ID = stl.lse_id
9373 AND cle.sts_code = khr.sts_code
9374 AND cle.dnz_chr_id = khr.ID
9375 AND stl.scs_code IN (g_lease_scs_code, g_loan_scs_code));
9376 BEGIN
9377 IF (is_debug_procedure_on)
9378 THEN
9379 okl_debug_pub.log_debug (g_level_procedure,
9380 l_module_name,
9381 'Begin(+)'
9382 );
9383 END IF;
9384
9385 IF (is_debug_statement_on)
9386 THEN
9387 okl_debug_pub.log_debug (g_level_statement,
9388 l_module_name,
9389 'In param, p_dnz_chr_id: ' || p_dnz_chr_id
9390 );
9391 okl_debug_pub.log_debug (g_level_statement,
9392 l_module_name,
9393 'In param, p_top_line_id: ' || p_top_line_id
9394 );
9395 END IF;
9396
9397 -- initialize return status
9398 x_return_status := g_ret_sts_success;
9399
9400 -- data is required
9401 IF (p_dnz_chr_id = g_miss_num OR p_dnz_chr_id IS NULL)
9402 AND (p_top_line_id = g_miss_num OR p_top_line_id IS NULL)
9403 THEN
9404 -- store SQL error message on message stack
9405 okl_api.set_message
9406 (p_app_name => g_app_name,
9407 p_msg_name => g_required_value,
9408 p_token1 => g_col_name_token,
9409 p_token1_value => 'p_dnz_chr_id and p_top_line_id'
9410 );
9411 -- halt validation as it is a required field
9412 RAISE g_exception_stop_validation;
9413 ELSIF (p_dnz_chr_id = g_miss_num OR p_dnz_chr_id IS NULL)
9414 OR (p_top_line_id = g_miss_num OR p_top_line_id IS NULL)
9415 THEN
9416 -- store SQL error message on message stack
9417 okl_api.set_message
9418 (p_app_name => g_app_name,
9419 p_msg_name => g_required_value,
9420 p_token1 => g_col_name_token,
9421 p_token1_value => 'p_dnz_chr_id and p_top_line_id'
9422 );
9423 -- halt validation as it is a required field
9424 RAISE g_exception_stop_validation;
9425 END IF;
9426
9427 -- Combination of dnz_chr_id and Top line id should be valid one
9428 OPEN l_k_lines_validate_csr (p_dnz_chr_id => p_dnz_chr_id,
9429 p_top_line_id => p_top_line_id);
9430
9431 IF l_k_lines_validate_csr%NOTFOUND
9432 THEN
9433 okl_api.set_message
9434 (p_app_name => g_app_name,
9435 p_msg_name => g_no_matching_record,
9436 p_token1 => g_col_name_token,
9437 p_token1_value => 'p_dnz_chr_id and p_top_line_id'
9438 );
9439 -- halt validation as it has no parent record
9440 RAISE g_exception_halt_validation;
9441 END IF;
9442
9443 FETCH l_k_lines_validate_csr
9444 INTO ln_dummy;
9445
9446 CLOSE l_k_lines_validate_csr;
9447
9448 IF (ln_dummy = 0)
9449 THEN
9450 okl_api.set_message
9451 (p_app_name => g_app_name,
9452 p_msg_name => g_no_matching_record,
9453 p_token1 => g_col_name_token,
9454 p_token1_value => 'p_dnz_chr_id and p_top_line_id'
9455 );
9456 -- halt validation as it has no parent record
9457 RAISE g_exception_halt_validation;
9458 END IF;
9459
9460 IF (is_debug_procedure_on)
9461 THEN
9462 okl_debug_pub.log_debug (g_level_procedure,
9463 l_module_name,
9464 'End(-)'
9465 );
9466 END IF;
9467 EXCEPTION
9468 WHEN g_exception_stop_validation
9469 THEN
9470 -- We are here since the field is required
9471 -- Notify Error
9472 -- RMUNJULU -- Bug # 2484327 -- Added code to close cursor if open
9473 IF l_k_lines_validate_csr%ISOPEN
9474 THEN
9475 CLOSE l_k_lines_validate_csr;
9476 END IF;
9477
9478 x_return_status := g_ret_sts_error;
9479
9480 IF (is_debug_exception_on)
9481 THEN
9482 okl_debug_pub.log_debug (g_level_exception,
9483 l_module_name,
9484 'EXCEPTION :'
9485 || 'G_EXCEPTION_STOP_VALIDATION'
9486 );
9487 END IF;
9488 WHEN g_exception_halt_validation
9489 THEN
9490 -- If the cursor is open then it has to be closed
9491 IF l_k_lines_validate_csr%ISOPEN
9492 THEN
9493 CLOSE l_k_lines_validate_csr;
9494 END IF;
9495
9496 x_return_status := g_ret_sts_error;
9497
9498 IF (is_debug_exception_on)
9499 THEN
9500 okl_debug_pub.log_debug (g_level_exception,
9501 l_module_name,
9502 'EXCEPTION :'
9503 || 'G_EXCEPTION_HALT_VALIDATION'
9504 );
9505 END IF;
9506 WHEN OTHERS
9507 THEN
9508 -- store SQL error message on message stack
9509 okl_api.set_message (p_app_name => g_app_name,
9510 p_msg_name => g_unexpected_error,
9511 p_token1 => g_sqlcode_token,
9512 p_token1_value => SQLCODE,
9513 p_token2 => g_sqlerrm_token,
9514 p_token2_value => SQLERRM
9515 );
9516
9517 -- If the cursor is open then it has to be closed
9518 IF l_k_lines_validate_csr%ISOPEN
9519 THEN
9520 CLOSE l_k_lines_validate_csr;
9521 END IF;
9522
9523 -- notify caller of an error as UNEXPETED error
9524 x_return_status := g_ret_sts_unexp_error;
9525
9526 IF (is_debug_exception_on)
9527 THEN
9528 okl_debug_pub.log_debug (g_level_exception,
9529 l_module_name,
9530 'EXCEPTION :'
9531 || 'OTHERS, SQLCODE: '
9532 || SQLCODE
9533 || ' , SQLERRM : '
9534 || SQLERRM
9535 );
9536 END IF;
9537 END validate_chr_cle_id;
9538
9539 /*========================================================================
9540 | PRIVATE PROCEDURE update_payments
9541 |
9542 | DESCRIPTION
9543 | This procedure updates the financial asset, service line and service
9544 | subline level payments with the proposed payments calculated during
9545 | quote creation
9546 |
9547 | CALLED FROM PROCEDURES/FUNCTIONS
9548 | update_lines
9549 |
9550 | CALLS PROCEDURES/FUNCTIONS
9551 |
9552 |
9553 | PARAMETERS
9554 | p_quote_id IN Quote ID
9555 |
9556 | KNOWN ISSUES
9557 |
9558 | NOTES
9559 |
9560 |
9561 | MODIFICATION HISTORY
9562 | Date Author Description of Changes
9563 | 28-OCT-2003 SECHAWLA 22846988 Created
9564 | 20-SEP-04 SECHAWLA 3816891 : Modified payment processing
9565 | for Arrears
9566 | 29-SEP-04 PAGARG Bug #3921591: Added payment
9567 | processing for Rollover Fee line
9568 | 15-JUN-06 SMADHAVA Bug#5043646: Modified payment processing
9569 | for fee header level payments
9570 *=======================================================================*/
9571 PROCEDURE update_payments (
9572 p_api_version IN NUMBER,
9573 p_init_msg_list IN VARCHAR2 DEFAULT okc_api.g_false,
9574 x_msg_count OUT NOCOPY NUMBER,
9575 x_msg_data OUT NOCOPY VARCHAR2,
9576 x_return_status OUT NOCOPY VARCHAR2,
9577 p_quote_id IN NUMBER
9578 )
9579 IS
9580 -- This cursor returns all the proposed objects of a particular type, created during quote creation
9581 -- some of the proposed objects may not have any associated cash flows
9582 CURSOR l_quoteobjects_csr (
9583 cp_qte_id IN NUMBER
9584 )
9585 IS
9586 SELECT DISTINCT qco.cfo_id cfo_id,
9587 qco.base_source_id line_id,
9588 caf.sts_code,
9589 cfo.oty_code
9590 FROM okl_trx_qte_cf_objects qco,
9591 okl_cash_flows caf,
9592 okl_cash_flow_objects cfo
9593 WHERE cfo.ID = qco.cfo_id
9594 AND cfo.ID =
9595 caf.cfo_id(+)
9596 -- cash flow object is created even if there are no proposed payments (quote eff dt < first level start date)
9597 --Bug #3921591: pagarg +++ Rollover +++
9598 -- Included fee line and fee asset line type cash flow objects also
9599 AND cfo.oty_code IN
9600 ('FINANCIAL_ASSET_LINE',
9601 'SERVICE_LINE',
9602 'SERVICED_ASSET_LINE',
9603 'FEE_LINE',
9604 'FEE_ASSET_LINE'
9605 )
9606 AND qco.qte_id = cp_qte_id
9607 AND NVL (caf.sts_code, 'PROPOSED') = 'PROPOSED';
9608
9609 -- get the quote effective date
9610 CURSOR l_trxquotes_csr (
9611 cp_qte_id IN NUMBER
9612 )
9613 IS
9614 SELECT TRUNC (date_effective_from)
9615 FROM okl_trx_quotes_b
9616 WHERE ID = cp_qte_id;
9617
9618 -- get the quote line info
9619 CURSOR l_quotelines_csr (
9620 cp_qte_id IN NUMBER,
9621 cp_kle_id IN NUMBER
9622 )
9623 IS
9624 SELECT ID tql_id,
9625 asset_quantity asset_quantity,
9626 quote_quantity quote_quantity
9627 FROM okl_txl_quote_lines_b
9628 WHERE qte_id = cp_qte_id
9629 AND qlt_code = 'AMCFIA'
9630 AND kle_id = cp_kle_id;
9631
9632 -- get all the stream types from cashflows, for which proposed payment exists
9633 CURSOR l_cashflowstreams_csr (
9634 cp_cfo_id IN NUMBER
9635 )
9636 IS
9637 SELECT ID caf_id,
9638 sty_id,
9639 dnz_khr_id,
9640 number_of_advance_periods,
9641 due_arrears_yn
9642 FROM okl_cash_flows
9643 WHERE cfo_id = cp_cfo_id
9644 AND sts_code = 'PROPOSED'
9645 AND cft_code = 'PAYMENT_SCHEDULE';
9646
9647 -- get all the cash flow levels for a cashflow header
9648 CURSOR l_cashflowlevels_csr (
9649 cp_caf_id IN NUMBER
9650 )
9651 IS
9652 SELECT ID cfl_id,
9653 amount,
9654 number_of_periods,
9655 fqy_code,
9656 stub_days,
9657 stub_amount,
9658 start_date
9659 FROM okl_cash_flow_levels
9660 WHERE caf_id = cp_caf_id;
9661
9662 -- This cursor returns the rule group ID and slh ID of all the payments for a given line
9663 CURSOR l_rgpslh_csr (
9664 cp_cle_id IN NUMBER
9665 )
9666 IS
9667 SELECT DISTINCT rgp.ID rgp_id,
9668 slh_rul.ID slh_id,
9669 rgp.dnz_chr_id,
9670 sttyp.id1 sty_id,
9671 sll_rul.rule_information5 advance_periods,
9672 sll_rul.rule_information10 due_arrears_yn,
9673 sll_rul.object1_id1 frequency
9674 FROM okc_rules_b sll_rul,
9675 okc_rules_b slh_rul,
9676 okc_rule_groups_b rgp,
9677 okl_strmtyp_source_v sttyp
9678 WHERE sll_rul.object2_id1 = TO_CHAR (slh_rul.ID)
9679 AND sll_rul.rgp_id = rgp.ID
9680 AND sll_rul.rule_information_category = 'LASLL'
9681 AND sttyp.id1 = slh_rul.object1_id1
9682 AND slh_rul.rgp_id = rgp.ID
9683 AND slh_rul.rule_information_category = 'LASLH'
9684 AND rgp.rgd_code = 'LALEVL'
9685 AND rgp.cle_id = cp_cle_id;
9686
9687 -- Get the proposed cashflows for an object, for a given stream type
9688 CURSOR l_cashflows_csr (
9689 cp_cfo_id IN NUMBER,
9690 cp_sty_id IN NUMBER
9691 )
9692 IS
9693 SELECT caf.ID,
9694 caf.sty_id,
9695 cfl.start_date,
9696 cfl.amount,
9697 cfl.number_of_periods,
9698 cfl.stub_days,
9699 cfl.stub_amount,
9700 NVL (caf.due_arrears_yn, 'N') due_arrears_yn,
9701 -- SECHAWLA 20-SEP-04 3816891 : Added
9702 cfl.fqy_code -- SECHAWLA 20-SEP-04 3816891 : Added
9703 FROM okl_cash_flows caf,
9704 okl_cash_flow_levels cfl
9705 WHERE cfo_id = cp_cfo_id
9706 AND caf.sty_id = cp_sty_id
9707 AND caf.ID = cfl.caf_id
9708 AND caf.sts_code = 'PROPOSED'
9709 AND caf.cft_code = 'PAYMENT_SCHEDULE'
9710 ORDER BY cfl.start_date;
9711
9712 -- get the current payments for a line, as they exist after split asset has happened
9713 -- Get the Line Level payments
9714 CURSOR l_lpayments_csr (
9715 cp_cle_id IN NUMBER,
9716 cp_sty_id IN NUMBER
9717 )
9718 IS
9719 SELECT rgp.cle_id cle_id,
9720 sttyp.id1 sty_id,
9721 sttyp.code stream_type,
9722 sll_rul.rule_information2 start_date,
9723 sll_rul.rule_information3 periods,
9724 sll_rul.rule_information6 amount,
9725 sll_rul.rule_information7 stub_days,
9726 sll_rul.rule_information8 stub_amount,
9727 rgp.dnz_chr_id
9728 FROM okc_rules_b sll_rul,
9729 okl_strmtyp_source_v sttyp,
9730 okc_rules_b slh_rul,
9731 okc_rule_groups_b rgp
9732 WHERE sll_rul.object2_id1 = TO_CHAR (slh_rul.ID)
9733 AND sll_rul.rgp_id = rgp.ID
9734 AND sll_rul.rule_information_category = 'LASLL'
9735 AND sttyp.id1 = slh_rul.object1_id1
9736 AND sttyp.id1 = cp_sty_id
9737 AND slh_rul.rgp_id = rgp.ID
9738 AND slh_rul.rule_information_category = 'LASLH'
9739 AND rgp.rgd_code = 'LALEVL'
9740 AND rgp.cle_id = cp_cle_id
9741 ORDER BY start_date;
9742
9743 --Bug #3921591: pagarg +++ Rollover +++
9744 -- Modified the cursor to get financial assets for a given line type
9745
9746 -- Get the financial asset associated with a given line type (subline)
9747 CURSOR l_finasset_csr (
9748 cp_fee_serviced_asset_line_id IN NUMBER,
9749 cp_line_type IN VARCHAR2
9750 )
9751 IS
9752 SELECT cim.object1_id1,
9753 cle.cle_id
9754 FROM okc_k_lines_b cle,
9755 okc_line_styles_b lse,
9756 okc_k_items cim
9757 WHERE cle.lse_id = lse.ID
9758 AND lse.lty_code = cp_line_type
9759 AND cim.cle_id = cle.ID
9760 AND cle.ID = cp_fee_serviced_asset_line_id;
9761
9762 -- smadhava - Bug#5043646 - Added - Start
9763 l_active_assets_flag VARCHAR2 (1);
9764
9765 -- Find if there are ACTIVE assets associated to fees/services (subline)
9766 CURSOR c_find_active_link_assets (
9767 cp_line_id IN NUMBER,
9768 cp_line_type IN VARCHAR2
9769 )
9770 IS
9771 SELECT 'X'
9772 FROM okc_k_lines_b linked_asset,
9773 okc_line_styles_b line_styl,
9774 okc_k_items item,
9775 okc_statuses_b sts
9776 WHERE linked_asset.lse_id = line_styl.ID
9777 AND line_styl.lty_code = cp_line_type
9778 AND item.cle_id = linked_asset.ID
9779 AND linked_asset.cle_id = cp_line_id
9780 AND sts.code = linked_asset.sts_code
9781 AND sts.ste_code = 'ACTIVE';
9782
9783 -- smadhava - Bug#5043646 - Added - End
9784
9785 --Bug #3921591: pagarg +++ Rollover +++
9786 -- Modified the cursor to get the assets for a given line type
9787
9788 -- Get all the assets associated with the service or fee line
9789 -- This cursor might also return assets with status = 'TERMINATED'
9790 -- By the time this procedure is called, financial assets that are included in the quote, will
9791 -- already be terminated (in update_lines procedure)
9792 CURSOR l_lineassets_csr (
9793 cp_line_id IN NUMBER,
9794 cp_line_type IN VARCHAR2
9795 )
9796 IS
9797 SELECT cim.object1_id1,
9798 cle.ID
9799 FROM okc_k_lines_b cle,
9800 okc_line_styles_b lse,
9801 okc_k_items cim
9802 WHERE cle.lse_id = lse.ID
9803 AND lse.lty_code = cp_line_type
9804 AND cim.cle_id = cle.ID
9805 AND cle.cle_id = cp_line_id;
9806
9807 -- SECHAWLA 20-SEP-04 3816891 : new declarations begin
9808
9809 -- Get the next level start date
9810 CURSOR l_nextlevelstartdt_csr (
9811 cp_currlevelstartdt IN DATE,
9812 cp_number_of_months IN NUMBER
9813 )
9814 IS
9815 SELECT ADD_MONTHS (cp_currlevelstartdt, cp_number_of_months)
9816 FROM DUAL;
9817
9818 l_number_of_months NUMBER;
9819 l_next_level_start_date DATE;
9820
9821 -- SECHAWLA 20-SEP-04 3816891 : new declarations end
9822 SUBTYPE pym_hdr_rec_type IS okl_la_payments_pvt.pym_hdr_rec_type;
9823
9824 SUBTYPE pym_tbl_type IS okl_la_payments_pvt.pym_tbl_type;
9825
9826 SUBTYPE rulv_tbl_type IS okl_rule_pub.rulv_tbl_type;
9827
9828 SUBTYPE pym_del_tbl_type IS okl_la_payments_pvt.pym_del_tbl_type;
9829
9830 TYPE splitpymt_rec_type IS RECORD (
9831 p_start_date DATE,
9832 p_number_of_periods NUMBER,
9833 p_amount NUMBER,
9834 p_stub_days NUMBER,
9835 p_stub_amount NUMBER
9836 );
9837
9838 TYPE splitpymt_tbl_type IS TABLE OF splitpymt_rec_type
9839 INDEX BY BINARY_INTEGER;
9840
9841 l_tql_id NUMBER;
9842 l_asset_qty NUMBER;
9843 l_quote_qty NUMBER;
9844 pym_tbl_ind NUMBER;
9845 l_pym_freq VARCHAR2 (30);
9846 lp_pym_tbl pym_tbl_type;
9847 lp_pym_tbl_empty pym_tbl_type;
9848 lp_pym_hdr_rec pym_hdr_rec_type;
9849 l_return_status VARCHAR2 (1) := okl_api.g_ret_sts_success;
9850 lx_rulv_tbl rulv_tbl_type;
9851 l_proppymt_count NUMBER;
9852 l_splitpymt_count NUMBER;
9853 l_date_eff_from DATE;
9854 i NUMBER;
9855 lpym_del_tbl pym_del_tbl_type;
9856 lpym_del_tbl_empty pym_del_tbl_type;
9857 lpym_del_tbl_count NUMBER;
9858 l_freq_found VARCHAR2 (1) := 'N';
9859 l_name VARCHAR2 (150);
9860 l_strm_type_code VARCHAR2 (150);
9861 l_splitpymt_tbl splitpymt_tbl_type;
9862 l_splitpymt_tbl_empty splitpymt_tbl_type;
9863 l_fin_asset_id NUMBER;
9864 l_upd_required VARCHAR2 (1);
9865 l_count NUMBER;
9866 l_service_line_id NUMBER;
9867 --Bug #3921591: pagarg +++ Rollover +++
9868 -- Variable to store fine line id
9869 l_fee_line_id NUMBER;
9870 l_module_name VARCHAR2 (500)
9871 := g_module_name || 'update_payments';
9872 is_debug_exception_on BOOLEAN
9873 := okl_debug_pub.check_log_on (l_module_name, g_level_exception);
9874 is_debug_procedure_on BOOLEAN
9875 := okl_debug_pub.check_log_on (l_module_name, g_level_procedure);
9876 is_debug_statement_on BOOLEAN
9877 := okl_debug_pub.check_log_on (l_module_name, g_level_statement);
9878 BEGIN
9879 SAVEPOINT update_payments;
9880
9881 IF (is_debug_procedure_on)
9882 THEN
9883 okl_debug_pub.log_debug (g_level_procedure,
9884 l_module_name,
9885 'Begin(+)'
9886 );
9887 END IF;
9888
9889 IF (is_debug_statement_on)
9890 THEN
9891 okl_debug_pub.log_debug (g_level_statement,
9892 l_module_name,
9893 'In param, p_quote_id: ' || p_quote_id
9894 );
9895 END IF;
9896
9897 IF p_quote_id IS NULL OR p_quote_id = okl_api.g_miss_num
9898 THEN
9899 -- quote id is required
9900 okc_api.set_message (p_app_name => 'OKC',
9901 p_msg_name => g_required_value,
9902 p_token1 => g_col_name_token,
9903 p_token1_value => 'QUOTE_ID'
9904 );
9905 RAISE okl_api.g_exception_error;
9906 END IF;
9907
9908 OPEN l_trxquotes_csr (p_quote_id);
9909
9910 FETCH l_trxquotes_csr
9911 INTO l_date_eff_from;
9912
9913 IF l_trxquotes_csr%NOTFOUND
9914 THEN
9915 -- quote id is invalid
9916 okc_api.set_message (p_app_name => 'OKC',
9917 p_msg_name => g_invalid_value,
9918 p_token1 => g_col_name_token,
9919 p_token1_value => 'QUOTE_ID'
9920 );
9921 RAISE okl_api.g_exception_error;
9922 END IF;
9923
9924 CLOSE l_trxquotes_csr;
9925
9926 --Bug #3921591: pagarg +++ Rollover +++
9927 -- update payments for all proposed objects of type : financial asset,
9928 -- service line, serviced assets line, fee line, fee asset line
9929 FOR l_quoteobjects_rec IN l_quoteobjects_csr (p_quote_id)
9930 LOOP
9931 l_upd_required := 'N';
9932
9933 -- current payment exists, but no future payments exist.
9934 IF l_quoteobjects_rec.sts_code IS NULL
9935 THEN
9936 -- This will
9937 -- be the case only if quote is created before the first payment start
9938 -- date. This will not happen now since now first payment start dt
9939 -- is the K start date and quote will be created only after the
9940 -- K is created. So quote eff dt will always be >= first pymt start dt
9941
9942 -- delete all the payments, for all stream types
9943 lpym_del_tbl_count := 0;
9944 lpym_del_tbl := lpym_del_tbl_empty;
9945
9946 FOR l_rgpslh_rec IN l_rgpslh_csr (l_quoteobjects_rec.line_id)
9947 LOOP
9948 lpym_del_tbl_count := lpym_del_tbl_count + 1;
9949 lpym_del_tbl (lpym_del_tbl_count).chr_id :=
9950 l_rgpslh_rec.dnz_chr_id;
9951 lpym_del_tbl (lpym_del_tbl_count).rgp_id :=
9952 l_rgpslh_rec.rgp_id;
9953 lpym_del_tbl (lpym_del_tbl_count).slh_id :=
9954 l_rgpslh_rec.slh_id;
9955 END LOOP;
9956
9957 IF (is_debug_statement_on)
9958 THEN
9959 okl_debug_pub.log_debug
9960 (g_level_statement,
9961 l_module_name,
9962 'calling OKL_LA_PAYMENTS_PVT.delete_payment'
9963 );
9964 END IF;
9965
9966 okl_la_payments_pvt.delete_payment
9967 (p_api_version => p_api_version,
9968 p_init_msg_list => okc_api.g_false,
9969 x_return_status => l_return_status,
9970 x_msg_count => x_msg_count,
9971 x_msg_data => x_msg_data,
9972 p_del_pym_tbl => lpym_del_tbl,
9973 --bug #7498330
9974 p_source_trx => 'TQ'
9975 );
9976
9977 IF (is_debug_statement_on)
9978 THEN
9979 okl_debug_pub.log_debug
9980 (g_level_statement,
9981 l_module_name,
9982 'called OKL_LA_PAYMENTS_PVT.delete_payment , return status: '
9983 || l_return_status
9984 );
9985 END IF;
9986
9987 IF (l_return_status = okl_api.g_ret_sts_unexp_error)
9988 THEN
9989 RAISE okl_api.g_exception_unexpected_error;
9990 ELSIF (l_return_status = okl_api.g_ret_sts_error)
9991 THEN
9992 RAISE okl_api.g_exception_error;
9993 END IF;
9994 ELSIF l_quoteobjects_rec.sts_code = 'PROPOSED'
9995 THEN
9996 -- future payment exists for one or more stream types
9997 IF l_quoteobjects_rec.oty_code = 'FINANCIAL_ASSET_LINE'
9998 THEN
9999 l_fin_asset_id := l_quoteobjects_rec.line_id;
10000
10001 -- check if asset belongs to quote
10002 OPEN l_quotelines_csr (p_quote_id, l_fin_asset_id);
10003
10004 FETCH l_quotelines_csr
10005 INTO l_tql_id,
10006 l_asset_qty,
10007 l_quote_qty;
10008
10009 IF l_quotelines_csr%FOUND
10010 THEN
10011 l_upd_required := 'Y';
10012 END IF;
10013
10014 CLOSE l_quotelines_csr;
10015 ELSIF l_quoteobjects_rec.oty_code = 'SERVICED_ASSET_LINE'
10016 THEN
10017 --Bug #3921591: pagarg +++ Rollover +++
10018 -- Modified the call to pass line type code also.
10019 -- get the financial asset associated with the subline
10020 OPEN l_finasset_csr (l_quoteobjects_rec.line_id,
10021 g_srl_line_lty_code);
10022
10023 FETCH l_finasset_csr
10024 INTO l_fin_asset_id,
10025 l_service_line_id;
10026
10027 CLOSE l_finasset_csr;
10028
10029 -- check if asset belongs to quote
10030 OPEN l_quotelines_csr (p_quote_id, l_fin_asset_id);
10031
10032 FETCH l_quotelines_csr
10033 INTO l_tql_id,
10034 l_asset_qty,
10035 l_quote_qty;
10036
10037 IF l_quotelines_csr%FOUND
10038 THEN
10039 l_upd_required := 'Y';
10040 END IF;
10041
10042 CLOSE l_quotelines_csr;
10043 ELSIF l_quoteobjects_rec.oty_code = 'SERVICE_LINE'
10044 THEN
10045 --Bug #3921591: pagarg +++ Rollover +++
10046 -- Modified the call to pass line type code also.
10047 -- check if service line has any quoted assets.
10048 -- Get all the assets associated with the service line
10049 FOR l_servicelineassets_rec IN
10050 l_lineassets_csr (l_quoteobjects_rec.line_id,
10051 g_srl_line_lty_code)
10052 LOOP
10053 -- check if asset belongs to quote
10054 OPEN l_quotelines_csr (p_quote_id,
10055 l_servicelineassets_rec.object1_id1);
10056
10057 FETCH l_quotelines_csr
10058 INTO l_tql_id,
10059 l_asset_qty,
10060 l_quote_qty;
10061
10062 IF l_quotelines_csr%FOUND
10063 THEN
10064 l_upd_required := 'Y';
10065
10066 CLOSE l_quotelines_csr;
10067
10068 EXIT;
10069 END IF;
10070
10071 CLOSE l_quotelines_csr;
10072 END LOOP;
10073 --Bug #3921591: pagarg +++ Rollover +++++++ Start ++++++++++
10074 -- Check whether payment is required to be updated for fee line and fee asset line
10075 ELSIF l_quoteobjects_rec.oty_code = 'FEE_ASSET_LINE'
10076 THEN
10077 -- as of now fee_asset_line type cash flow object is created for rollover fee only.
10078 -- get the financial asset associated with the subline
10079 OPEN l_finasset_csr (l_quoteobjects_rec.line_id,
10080 g_fel_line_lty_code);
10081
10082 FETCH l_finasset_csr
10083 INTO l_fin_asset_id,
10084 l_fee_line_id;
10085
10086 CLOSE l_finasset_csr;
10087
10088 -- check if asset belongs to quote
10089 OPEN l_quotelines_csr (p_quote_id, l_fin_asset_id);
10090
10091 FETCH l_quotelines_csr
10092 INTO l_tql_id,
10093 l_asset_qty,
10094 l_quote_qty;
10095
10096 IF l_quotelines_csr%FOUND
10097 THEN
10098 l_upd_required := 'Y';
10099 END IF;
10100
10101 CLOSE l_quotelines_csr;
10102 ELSIF l_quoteobjects_rec.oty_code = 'FEE_LINE'
10103 THEN
10104 -- check if fee line has any quoted assets.
10105 -- Get all the assets associated with the fee line
10106 FOR l_feelineassets_rec IN
10107 l_lineassets_csr (l_quoteobjects_rec.line_id,
10108 g_fel_line_lty_code)
10109 LOOP
10110 -- check if asset belongs to quote
10111 OPEN l_quotelines_csr (p_quote_id,
10112 l_feelineassets_rec.object1_id1);
10113
10114 FETCH l_quotelines_csr
10115 INTO l_tql_id,
10116 l_asset_qty,
10117 l_quote_qty;
10118
10119 IF l_quotelines_csr%FOUND
10120 THEN
10121 -- smadhava - Bug#5043646 - Added - Start
10122 -- Now CHECK if the all the assets attached to this fee are terminated. Going by this logic
10123 -- as payments are updated in termination flow only after the asset statuses are
10124 -- updated to TERMINATED. Hence checking for statuses of all assets linked to this fee.
10125 -- Never update the header payments for partial termination. This is because for
10126 -- partial temination, by this time, the assets have been split and the orignial
10127 -- individual units prior to split are separate assets linked to this fee line.
10128 l_active_assets_flag := 'N';
10129
10130 IF (l_asset_qty = l_quote_qty)
10131 THEN
10132 -- cursor to check if there are assets associated to this fee which are still ACTIVE
10133 -- if there are ACTIVE assets, then donot update the payment at the header
10134 OPEN c_find_active_link_assets
10135 (l_quoteobjects_rec.line_id,
10136 g_fel_line_lty_code);
10137
10138 FETCH c_find_active_link_assets
10139 INTO l_active_assets_flag;
10140
10141 -- update the payments on header lines only if all the associated assets
10142 -- have been terminated
10143 IF c_find_active_link_assets%NOTFOUND
10144 THEN
10145 l_upd_required := 'Y';
10146 END IF;
10147
10148 CLOSE c_find_active_link_assets;
10149 END IF;
10150
10151 -- Assigning fee line id to the variable
10152 l_fee_line_id := l_quoteobjects_rec.line_id;
10153
10154 -- smadhava - Bug#5043646 - Added - End
10155 CLOSE l_quotelines_csr;
10156
10157 EXIT;
10158 END IF;
10159
10160 CLOSE l_quotelines_csr;
10161 END LOOP;
10162 END IF;
10163
10164 --Bug #3921591: pagarg +++ Rollover +++++++ End ++++++++++
10165 IF l_upd_required = 'Y'
10166 THEN
10167 --Bug #3921591: pagarg +++ Rollover +++
10168 -- Modified the condition to include fee line and fee asset line also
10169 IF ( ( l_quoteobjects_rec.oty_code IN
10170 ('FINANCIAL_ASSET_LINE',
10171 'SERVICED_ASSET_LINE',
10172 'FEE_ASSET_LINE'
10173 )
10174 AND l_asset_qty =
10175 l_quote_qty
10176 -- full line termination, asset was not split
10177 )
10178 OR l_quoteobjects_rec.oty_code IN
10179 ('SERVICE_LINE', 'FEE_LINE')
10180 -- service line level pymts are not split, if
10181 -- any of the attached assets are partially terminated.
10182 -- so we can always overwrite the service line level pymts
10183 )
10184 THEN
10185 -- overwrite the payments
10186 -- delete all the payments, for all stream types
10187 lpym_del_tbl_count := 0;
10188 lpym_del_tbl := lpym_del_tbl_empty;
10189
10190 FOR l_rgpslh_rec IN
10191 l_rgpslh_csr (l_quoteobjects_rec.line_id)
10192 LOOP
10193 lpym_del_tbl_count := lpym_del_tbl_count + 1;
10194 lpym_del_tbl (lpym_del_tbl_count).chr_id :=
10195 l_rgpslh_rec.dnz_chr_id;
10196 lpym_del_tbl (lpym_del_tbl_count).rgp_id :=
10197 l_rgpslh_rec.rgp_id;
10198 lpym_del_tbl (lpym_del_tbl_count).slh_id :=
10199 l_rgpslh_rec.slh_id;
10200 END LOOP;
10201
10202 IF (is_debug_statement_on)
10203 THEN
10204 okl_debug_pub.log_debug
10205 (g_level_statement,
10206 l_module_name,
10207 'calling OKL_LA_PAYMENTS_PVT.delete_payment'
10208 );
10209 END IF;
10210
10211 okl_la_payments_pvt.delete_payment
10212 (p_api_version => p_api_version,
10213 p_init_msg_list => okc_api.g_false,
10214 x_return_status => l_return_status,
10215 x_msg_count => x_msg_count,
10216 x_msg_data => x_msg_data,
10217 p_del_pym_tbl => lpym_del_tbl,
10218 --bug # 7498330
10219 p_source_trx => 'TQ'
10220 );
10221
10222 IF (is_debug_statement_on)
10223 THEN
10224 okl_debug_pub.log_debug
10225 (g_level_statement,
10226 l_module_name,
10227 'calling OKL_LA_PAYMENTS_PVT.delete_payment '
10228 || l_return_status
10229 );
10230 END IF;
10231
10232 IF (l_return_status = okl_api.g_ret_sts_unexp_error)
10233 THEN
10234 RAISE okl_api.g_exception_unexpected_error;
10235 ELSIF (l_return_status = okl_api.g_ret_sts_error)
10236 THEN
10237 RAISE okl_api.g_exception_error;
10238 END IF;
10239
10240 -- create new payments from cash flow tables
10241 -- get all the proposed stream types
10242 FOR l_cashflowstreams_rec IN
10243 l_cashflowstreams_csr (l_quoteobjects_rec.cfo_id)
10244 LOOP
10245 -- create payment for each proposed stream type
10246 l_freq_found := 'N';
10247 pym_tbl_ind := 0;
10248 lp_pym_tbl := lp_pym_tbl_empty;
10249
10250 -- get all the proposed cash flow levels and populate lp_pym_tbl
10251 FOR l_cashflowlevels_rec IN
10252 l_cashflowlevels_csr (l_cashflowstreams_rec.caf_id)
10253 LOOP
10254 IF ( l_freq_found = 'N'
10255 AND l_cashflowlevels_rec.fqy_code IS NOT NULL
10256 )
10257 THEN
10258 l_pym_freq := l_cashflowlevels_rec.fqy_code;
10259 l_freq_found := 'Y';
10260 END IF;
10261
10262 pym_tbl_ind := pym_tbl_ind + 1;
10263 lp_pym_tbl (pym_tbl_ind).stub_days :=
10264 l_cashflowlevels_rec.stub_days;
10265 lp_pym_tbl (pym_tbl_ind).stub_amount :=
10266 l_cashflowlevels_rec.stub_amount;
10267 lp_pym_tbl (pym_tbl_ind).period :=
10268 l_cashflowlevels_rec.number_of_periods;
10269 lp_pym_tbl (pym_tbl_ind).amount :=
10270 l_cashflowlevels_rec.amount;
10271 lp_pym_tbl (pym_tbl_ind).update_type := 'CREATE';
10272 END LOOP;
10273
10274 IF l_freq_found = 'N'
10275 THEN
10276 -- all levels are stub levels
10277 l_pym_freq := 'M';
10278 -- default freq to Monthly for Stub payments, as it is a required field
10279 END IF;
10280
10281 lp_pym_hdr_rec.STRUCTURE :=
10282 l_cashflowstreams_rec.number_of_advance_periods;
10283 lp_pym_hdr_rec.frequency := l_pym_freq;
10284 lp_pym_hdr_rec.arrears :=
10285 l_cashflowstreams_rec.due_arrears_yn;
10286
10287 IF lp_pym_tbl.COUNT > 0
10288 THEN
10289 IF l_quoteobjects_rec.oty_code =
10290 'FINANCIAL_ASSET_LINE'
10291 THEN
10292 -- create asset level payments
10293 IF (is_debug_statement_on)
10294 THEN
10295 okl_debug_pub.log_debug
10296 (g_level_statement,
10297 l_module_name,
10298 'calling OKL_LA_PAYMENTS_PVT.process_payment'
10299 );
10300 END IF;
10301
10302 okl_la_payments_pvt.process_payment
10303 (p_api_version => p_api_version,
10304 p_init_msg_list => okc_api.g_false,
10305 x_return_status => l_return_status,
10306 x_msg_count => x_msg_count,
10307 x_msg_data => x_msg_data,
10308 p_chr_id => l_cashflowstreams_rec.dnz_khr_id,
10309 -- p_service_fee_id => OKC_API.G_MISS_NUM,
10310 p_asset_id => l_quoteobjects_rec.line_id,
10311 p_payment_id => l_cashflowstreams_rec.sty_id,
10312 p_pym_hdr_rec => lp_pym_hdr_rec,
10313 p_pym_tbl => lp_pym_tbl,
10314 p_update_type => 'CREATE',
10315 x_rulv_tbl => lx_rulv_tbl
10316 );
10317
10318 IF (is_debug_statement_on)
10319 THEN
10320 okl_debug_pub.log_debug
10321 (g_level_statement,
10322 l_module_name,
10323 'called OKL_LA_PAYMENTS_PVT.process_payment , return status: '
10324 || l_return_status
10325 );
10326 END IF;
10327 ELSIF l_quoteobjects_rec.oty_code =
10328 'SERVICED_ASSET_LINE'
10329 THEN
10330 IF (is_debug_statement_on)
10331 THEN
10332 okl_debug_pub.log_debug
10333 (g_level_statement,
10334 l_module_name,
10335 'calling OKL_LA_PAYMENTS_PVT.process_payment'
10336 );
10337 END IF;
10338
10339 -- create subline level payments
10340 okl_la_payments_pvt.process_payment
10341 (p_api_version => p_api_version,
10342 p_init_msg_list => okc_api.g_false,
10343 x_return_status => l_return_status,
10344 x_msg_count => x_msg_count,
10345 x_msg_data => x_msg_data,
10346 p_chr_id => l_cashflowstreams_rec.dnz_khr_id,
10347 p_service_fee_id => l_service_line_id,
10348 p_asset_id => l_fin_asset_id,
10349 p_payment_id => l_cashflowstreams_rec.sty_id,
10350 p_pym_hdr_rec => lp_pym_hdr_rec,
10351 p_pym_tbl => lp_pym_tbl,
10352 p_update_type => 'CREATE',
10353 x_rulv_tbl => lx_rulv_tbl
10354 );
10355
10356 IF (is_debug_statement_on)
10357 THEN
10358 okl_debug_pub.log_debug
10359 (g_level_statement,
10360 l_module_name,
10361 'called OKL_LA_PAYMENTS_PVT.process_payment , return status: '
10362 || l_return_status
10363 );
10364 END IF;
10365 ELSIF l_quoteobjects_rec.oty_code = 'SERVICE_LINE'
10366 THEN
10367 -- create service line level payments
10368 IF (is_debug_statement_on)
10369 THEN
10370 okl_debug_pub.log_debug
10371 (g_level_statement,
10372 l_module_name,
10373 'calling OKL_LA_PAYMENTS_PVT.process_payment'
10374 );
10375 END IF;
10376
10377 okl_la_payments_pvt.process_payment
10378 (p_api_version => p_api_version,
10379 p_init_msg_list => okc_api.g_false,
10380 x_return_status => l_return_status,
10381 x_msg_count => x_msg_count,
10382 x_msg_data => x_msg_data,
10383 p_chr_id => l_cashflowstreams_rec.dnz_khr_id,
10384 p_service_fee_id => l_quoteobjects_rec.line_id,
10385 --p_asset_id => l_quoteobjects_rec.line_id,
10386 p_payment_id => l_cashflowstreams_rec.sty_id,
10387 p_pym_hdr_rec => lp_pym_hdr_rec,
10388 p_pym_tbl => lp_pym_tbl,
10389 p_update_type => 'CREATE',
10390 x_rulv_tbl => lx_rulv_tbl
10391 );
10392
10393 IF (is_debug_statement_on)
10394 THEN
10395 okl_debug_pub.log_debug
10396 (g_level_statement,
10397 l_module_name,
10398 'called OKL_LA_PAYMENTS_PVT.process_payment , return status: '
10399 || l_return_status
10400 );
10401 END IF;
10402 --Bug #3921591: pagarg +++ Rollover +++++++ Start ++++++++++
10403 -- creating payments for fee line and fee asset line.
10404 ELSIF l_quoteobjects_rec.oty_code = 'FEE_ASSET_LINE'
10405 THEN
10406 -- create fee asset subline level payments
10407 IF (is_debug_statement_on)
10408 THEN
10409 okl_debug_pub.log_debug
10410 (g_level_statement,
10411 l_module_name,
10412 'calling OKL_LA_PAYMENTS_PVT.process_payment'
10413 );
10414 END IF;
10415
10416 okl_la_payments_pvt.process_payment
10417 (p_api_version => p_api_version,
10418 p_init_msg_list => okc_api.g_false,
10419 x_return_status => l_return_status,
10420 x_msg_count => x_msg_count,
10421 x_msg_data => x_msg_data,
10422 p_chr_id => l_cashflowstreams_rec.dnz_khr_id,
10423 p_service_fee_id => l_fee_line_id,
10424 p_asset_id => l_fin_asset_id,
10425 p_payment_id => l_cashflowstreams_rec.sty_id,
10426 p_pym_hdr_rec => lp_pym_hdr_rec,
10427 p_pym_tbl => lp_pym_tbl,
10428 p_update_type => 'CREATE',
10429 x_rulv_tbl => lx_rulv_tbl
10430 );
10431
10432 IF (is_debug_statement_on)
10433 THEN
10434 okl_debug_pub.log_debug
10435 (g_level_statement,
10436 l_module_name,
10437 'called OKL_LA_PAYMENTS_PVT.process_payment , return status: '
10438 || l_return_status
10439 );
10440 END IF;
10441 ELSIF l_quoteobjects_rec.oty_code = 'FEE_LINE'
10442 THEN
10443 IF (is_debug_statement_on)
10444 THEN
10445 okl_debug_pub.log_debug
10446 (g_level_statement,
10447 l_module_name,
10448 'calling OKL_LA_PAYMENTS_PVT.process_payment'
10449 );
10450 END IF;
10451
10452 -- create fee line level payments
10453 okl_la_payments_pvt.process_payment
10454 (p_api_version => p_api_version,
10455 p_init_msg_list => okc_api.g_false,
10456 x_return_status => l_return_status,
10457 x_msg_count => x_msg_count,
10458 x_msg_data => x_msg_data,
10459 p_chr_id => l_cashflowstreams_rec.dnz_khr_id,
10460 p_service_fee_id => l_fee_line_id,
10461 p_payment_id => l_cashflowstreams_rec.sty_id,
10462 p_pym_hdr_rec => lp_pym_hdr_rec,
10463 p_pym_tbl => lp_pym_tbl,
10464 p_update_type => 'CREATE',
10465 x_rulv_tbl => lx_rulv_tbl
10466 );
10467
10468 --Bug #3921591: pagarg +++ Rollover +++++++ End ++++++++++
10469 IF (is_debug_statement_on)
10470 THEN
10471 okl_debug_pub.log_debug
10472 (g_level_statement,
10473 l_module_name,
10474 'called OKL_LA_PAYMENTS_PVT.process_payment , return status: '
10475 || l_return_status
10476 );
10477 END IF;
10478 END IF;
10479
10480 IF (l_return_status = okl_api.g_ret_sts_unexp_error)
10481 THEN
10482 RAISE okl_api.g_exception_unexpected_error;
10483 ELSIF (l_return_status = okl_api.g_ret_sts_error)
10484 THEN
10485 RAISE okl_api.g_exception_error;
10486 END IF;
10487 END IF;
10488 END LOOP;
10489 ELSE
10490 -- partial line termination (for fin assets and serviced assets only)
10491 -- asset was split. cann't overwrite the split payments with proposed pymts
10492 -- on quote. Adjust the split asset payment, save in a table and then overwrite the
10493 -- existing payments with the adjusted payments
10494
10495 -- get all stream types (from rules), for which payments exist, after split asset
10496 FOR l_rgpslh_rec IN
10497 l_rgpslh_csr (l_quoteobjects_rec.line_id)
10498 LOOP
10499 -- get the payments for this stream type (from rules) as they exist after the split asset, and populate l_splitpymt_tbl
10500 l_splitpymt_count := 0;
10501 l_splitpymt_tbl := l_splitpymt_tbl_empty;
10502
10503 -- populate l_splitpymt_tbl with payments as they exist after split
10504 FOR l_lpayments_rec IN
10505 l_lpayments_csr (l_quoteobjects_rec.line_id,
10506 l_rgpslh_rec.sty_id)
10507 LOOP
10508 l_splitpymt_count := l_splitpymt_count + 1;
10509 l_splitpymt_tbl (l_splitpymt_count).p_start_date :=
10510 TO_DATE (l_lpayments_rec.start_date,
10511 'yyyy/mm/dd hh24:mi:ss');
10512 l_splitpymt_tbl (l_splitpymt_count).p_number_of_periods :=
10513 l_lpayments_rec.periods;
10514 l_splitpymt_tbl (l_splitpymt_count).p_amount :=
10515 l_lpayments_rec.amount;
10516 l_splitpymt_tbl (l_splitpymt_count).p_stub_days :=
10517 l_lpayments_rec.stub_days;
10518 l_splitpymt_tbl (l_splitpymt_count).p_stub_amount :=
10519 l_lpayments_rec.stub_amount;
10520 END LOOP;
10521
10522 -- loop thru the proposed payments, calculated by quote creation process, or this stream type
10523 i := 0;
10524
10525 FOR l_cashflows_rec IN
10526 l_cashflows_csr (l_quoteobjects_rec.cfo_id,
10527 l_rgpslh_rec.sty_id)
10528 LOOP
10529 i := i + 1;
10530
10531 -- if proposed payment exists, current (split) payment will definitely exist
10532 IF l_splitpymt_tbl.EXISTS (i)
10533 THEN
10534 IF l_cashflows_rec.start_date =
10535 l_splitpymt_tbl (i).p_start_date
10536 AND l_cashflows_rec.start_date <=
10537 l_date_eff_from
10538 THEN
10539 IF l_cashflows_rec.due_arrears_yn = 'N'
10540 THEN
10541 -- SECHAWLA 20-SEP-04 3816891 : ADV, Added this condition
10542 -- SECHAWLA 20-SEP-04 3816891 Keep the same logic for Advance : begin
10543 -- update period or stub days
10544 IF l_cashflows_rec.stub_days IS NULL
10545 THEN
10546 IF l_splitpymt_tbl (i).p_number_of_periods <>
10547 l_cashflows_rec.number_of_periods
10548 THEN
10549 l_splitpymt_tbl (i).p_number_of_periods :=
10550 l_cashflows_rec.number_of_periods;
10551 END IF;
10552 ELSE
10553 IF l_splitpymt_tbl (i).p_stub_days <>
10554 l_cashflows_rec.stub_days
10555 THEN
10556 l_splitpymt_tbl (i).p_stub_days :=
10557 l_cashflows_rec.stub_days;
10558 END IF;
10559 END IF;
10560 -- SECHAWLA 20-SEP-04 3816891 Keep the same logic for Advance : end
10561 ELSIF l_cashflows_rec.due_arrears_yn = 'Y'
10562 THEN
10563 -- SECHAWLA 20-SEP-04 3816891 : Arrears, added this section
10564
10565 -- SECHAWLA 20-SEP-04 3816891 : Added following piece of code for Arrears : begin
10566
10567 -----------------------------------
10568 IF l_cashflows_rec.stub_days IS NULL
10569 THEN
10570 -- get the number of months that a payment covers
10571 IF l_cashflows_rec.fqy_code = 'M'
10572 THEN
10573 l_number_of_months :=
10574 (l_cashflows_rec.number_of_periods
10575 );
10576 ELSIF l_cashflows_rec.fqy_code = 'Q'
10577 THEN
10578 l_number_of_months :=
10579 (l_cashflows_rec.number_of_periods
10580 )
10581 * 3;
10582 ELSIF l_cashflows_rec.fqy_code = 'S'
10583 THEN
10584 l_number_of_months :=
10585 (l_cashflows_rec.number_of_periods
10586 )
10587 * 6;
10588 ELSIF l_cashflows_rec.fqy_code = 'A'
10589 THEN
10590 l_number_of_months :=
10591 (l_cashflows_rec.number_of_periods
10592 )
10593 * 12;
10594 END IF;
10595
10596 -- add months
10597 -- Get the first date after the last level period ends
10598 OPEN l_nextlevelstartdt_csr
10599 (l_cashflows_rec.start_date,
10600 l_number_of_months);
10601
10602 FETCH l_nextlevelstartdt_csr
10603 INTO l_next_level_start_date;
10604
10605 CLOSE l_nextlevelstartdt_csr;
10606 ELSE
10607 -- sechawla 20-SEP-04 3816891 : still ok
10608 l_next_level_start_date :=
10609 l_cashflows_rec.start_date
10610 + l_cashflows_rec.stub_days;
10611 END IF;
10612
10613 -----------------------
10614 IF l_date_eff_from >=
10615 (l_next_level_start_date - 1
10616 )
10617 THEN
10618 ---last day of the current level
10619 -- keep the level, update p_number_of_periods/p_stub_days, as above
10620
10621 -- update period or stub days
10622 IF l_cashflows_rec.stub_days IS NULL
10623 THEN
10624 IF l_splitpymt_tbl (i).p_number_of_periods <>
10625 l_cashflows_rec.number_of_periods
10626 THEN
10627 l_splitpymt_tbl (i).p_number_of_periods :=
10628 l_cashflows_rec.number_of_periods;
10629 END IF;
10630 ELSE
10631 IF l_splitpymt_tbl (i).p_stub_days <>
10632 l_cashflows_rec.stub_days
10633 THEN
10634 l_splitpymt_tbl (i).p_stub_days :=
10635 l_cashflows_rec.stub_days;
10636 END IF;
10637 END IF;
10638 ELSE
10639 l_splitpymt_tbl.DELETE
10640 (i,
10641 l_splitpymt_tbl.COUNT);
10642 EXIT;
10643 END IF;
10644 -- SECHAWLA 20-SEP-04 3816891 : Added following piece of code for Arrears : end
10645 END IF; -- SECHAWLA 20-SEP-04 3816891
10646 ELSIF l_cashflows_rec.start_date <
10647 l_splitpymt_tbl (i).p_start_date
10648 -- split has happened in proposed pymt
10649 OR l_cashflows_rec.start_date >
10650 l_date_eff_from
10651 THEN
10652 -- SECHAWLA 20-SEP-04 3816891 : still ok, no changes
10653 l_splitpymt_tbl.DELETE (i,
10654 l_splitpymt_tbl.COUNT);
10655 EXIT;
10656 END IF;
10657 END IF;
10658 END LOOP;
10659
10660 IF i = 0
10661 THEN
10662 -- proposed payment does not exist for this stream type
10663 -- delete the payment from rules, for this stream type
10664 lpym_del_tbl := lpym_del_tbl_empty;
10665 lpym_del_tbl (1).chr_id := l_rgpslh_rec.dnz_chr_id;
10666 lpym_del_tbl (1).rgp_id := l_rgpslh_rec.rgp_id;
10667 lpym_del_tbl (1).slh_id := l_rgpslh_rec.slh_id;
10668
10669 IF (is_debug_statement_on)
10670 THEN
10671 okl_debug_pub.log_debug
10672 (g_level_statement,
10673 l_module_name,
10674 'calling OKL_LA_PAYMENTS_PVT.delete_payment'
10675 );
10676 END IF;
10677
10678 okl_la_payments_pvt.delete_payment
10679 (p_api_version => p_api_version,
10680 p_init_msg_list => okc_api.g_false,
10681 x_return_status => l_return_status,
10682 x_msg_count => x_msg_count,
10683 x_msg_data => x_msg_data,
10684 p_del_pym_tbl => lpym_del_tbl,
10685 --bug # 7498330
10686 p_source_trx => 'TQ'
10687 );
10688
10689 IF (is_debug_statement_on)
10690 THEN
10691 okl_debug_pub.log_debug
10692 (g_level_statement,
10693 l_module_name,
10694 'calling OKL_LA_PAYMENTS_PVT.delete_payment , return status: '
10695 || l_return_status
10696 );
10697 END IF;
10698
10699 IF (l_return_status = okl_api.g_ret_sts_unexp_error)
10700 THEN
10701 RAISE okl_api.g_exception_unexpected_error;
10702 ELSIF (l_return_status = okl_api.g_ret_sts_error)
10703 THEN
10704 RAISE okl_api.g_exception_error;
10705 END IF;
10706 END IF;
10707
10708 IF l_splitpymt_tbl.COUNT > 0
10709 THEN
10710 -- delete the payment for this stream type
10711 lpym_del_tbl := lpym_del_tbl_empty;
10712 lpym_del_tbl (1).chr_id := l_rgpslh_rec.dnz_chr_id;
10713 lpym_del_tbl (1).rgp_id := l_rgpslh_rec.rgp_id;
10714 lpym_del_tbl (1).slh_id := l_rgpslh_rec.slh_id;
10715
10716 IF (is_debug_statement_on)
10717 THEN
10718 okl_debug_pub.log_debug
10719 (g_level_statement,
10720 l_module_name,
10721 'calling OKL_LA_PAYMENTS_PVT.delete_payment'
10722 );
10723 END IF;
10724
10725 okl_la_payments_pvt.delete_payment
10726 (p_api_version => p_api_version,
10727 p_init_msg_list => okc_api.g_false,
10728 x_return_status => l_return_status,
10729 x_msg_count => x_msg_count,
10730 x_msg_data => x_msg_data,
10731 p_del_pym_tbl => lpym_del_tbl,
10732 --bug # 7498330
10733 p_source_trx => 'TQ'
10734 );
10735
10736 IF (is_debug_statement_on)
10737 THEN
10738 okl_debug_pub.log_debug
10739 (g_level_statement,
10740 l_module_name,
10741 'calling OKL_LA_PAYMENTS_PVT.delete_payment , return status: '
10742 || l_return_status
10743 );
10744 END IF;
10745
10746 IF (l_return_status = okl_api.g_ret_sts_unexp_error)
10747 THEN
10748 RAISE okl_api.g_exception_unexpected_error;
10749 ELSIF (l_return_status = okl_api.g_ret_sts_error)
10750 THEN
10751 RAISE okl_api.g_exception_error;
10752 END IF;
10753
10754 -- create payment for this stream type from the l_splitpymt_tbl table
10755 lp_pym_hdr_rec.STRUCTURE :=
10756 l_rgpslh_rec.advance_periods;
10757 lp_pym_hdr_rec.frequency := l_rgpslh_rec.frequency;
10758 lp_pym_hdr_rec.arrears := l_rgpslh_rec.due_arrears_yn;
10759 lp_pym_tbl := lp_pym_tbl_empty;
10760 i := l_splitpymt_tbl.FIRST;
10761
10762 LOOP
10763 lp_pym_tbl (i).stub_days :=
10764 l_splitpymt_tbl (i).p_stub_days;
10765 lp_pym_tbl (i).stub_amount :=
10766 l_splitpymt_tbl (i).p_stub_amount;
10767 lp_pym_tbl (i).period :=
10768 l_splitpymt_tbl (i).p_number_of_periods;
10769 lp_pym_tbl (i).amount :=
10770 l_splitpymt_tbl (i).p_amount;
10771 lp_pym_tbl (i).update_type := 'CREATE';
10772 EXIT WHEN (i = l_splitpymt_tbl.LAST);
10773 i := l_splitpymt_tbl.NEXT (i);
10774 END LOOP;
10775
10776 IF l_quoteobjects_rec.oty_code =
10777 'FINANCIAL_ASSET_LINE'
10778 THEN
10779 -- create asset level payments
10780 IF (is_debug_statement_on)
10781 THEN
10782 okl_debug_pub.log_debug
10783 (g_level_statement,
10784 l_module_name,
10785 'calling OKL_LA_PAYMENTS_PVT.process_payment'
10786 );
10787 END IF;
10788
10789 okl_la_payments_pvt.process_payment
10790 (p_api_version => p_api_version,
10791 p_init_msg_list => okc_api.g_false,
10792 x_return_status => l_return_status,
10793 x_msg_count => x_msg_count,
10794 x_msg_data => x_msg_data,
10795 p_chr_id => l_rgpslh_rec.dnz_chr_id,
10796 -- p_service_fee_id => OKC_API.G_MISS_NUM,
10797 p_asset_id => l_quoteobjects_rec.line_id,
10798 p_payment_id => l_rgpslh_rec.sty_id,
10799 p_pym_hdr_rec => lp_pym_hdr_rec,
10800 p_pym_tbl => lp_pym_tbl,
10801 p_update_type => 'CREATE',
10802 x_rulv_tbl => lx_rulv_tbl
10803 );
10804
10805 IF (is_debug_statement_on)
10806 THEN
10807 okl_debug_pub.log_debug
10808 (g_level_statement,
10809 l_module_name,
10810 'called OKL_LA_PAYMENTS_PVT.process_payment , return status: '
10811 || l_return_status
10812 );
10813 END IF;
10814 ELSIF l_quoteobjects_rec.oty_code =
10815 'SERVICED_ASSET_LINE'
10816 THEN
10817 IF (is_debug_statement_on)
10818 THEN
10819 okl_debug_pub.log_debug
10820 (g_level_statement,
10821 l_module_name,
10822 'calling OKL_LA_PAYMENTS_PVT.process_payment'
10823 );
10824 END IF;
10825
10826 -- create subline level payments
10827 okl_la_payments_pvt.process_payment
10828 (p_api_version => p_api_version,
10829 p_init_msg_list => okc_api.g_false,
10830 x_return_status => l_return_status,
10831 x_msg_count => x_msg_count,
10832 x_msg_data => x_msg_data,
10833 p_chr_id => l_rgpslh_rec.dnz_chr_id,
10834 p_service_fee_id => l_service_line_id,
10835 p_asset_id => l_fin_asset_id,
10836 p_payment_id => l_rgpslh_rec.sty_id,
10837 p_pym_hdr_rec => lp_pym_hdr_rec,
10838 p_pym_tbl => lp_pym_tbl,
10839 p_update_type => 'CREATE',
10840 x_rulv_tbl => lx_rulv_tbl
10841 );
10842
10843 IF (is_debug_statement_on)
10844 THEN
10845 okl_debug_pub.log_debug
10846 (g_level_statement,
10847 l_module_name,
10848 'called OKL_LA_PAYMENTS_PVT.process_payment , return status: '
10849 || l_return_status
10850 );
10851 END IF;
10852 --Bug #3921591: pagarg +++ Rollover +++++++ Start ++++++++++
10853 ELSIF l_quoteobjects_rec.oty_code = 'FEE_ASSET_LINE'
10854 THEN
10855 IF (is_debug_statement_on)
10856 THEN
10857 okl_debug_pub.log_debug
10858 (g_level_statement,
10859 l_module_name,
10860 'calling OKL_LA_PAYMENTS_PVT.process_payment'
10861 );
10862 END IF;
10863
10864 -- create fee asset subline level payments
10865 okl_la_payments_pvt.process_payment
10866 (p_api_version => p_api_version,
10867 p_init_msg_list => okc_api.g_false,
10868 x_return_status => l_return_status,
10869 x_msg_count => x_msg_count,
10870 x_msg_data => x_msg_data,
10871 p_chr_id => l_rgpslh_rec.dnz_chr_id,
10872 p_service_fee_id => l_fee_line_id,
10873 p_asset_id => l_fin_asset_id,
10874 p_payment_id => l_rgpslh_rec.sty_id,
10875 p_pym_hdr_rec => lp_pym_hdr_rec,
10876 p_pym_tbl => lp_pym_tbl,
10877 p_update_type => 'CREATE',
10878 x_rulv_tbl => lx_rulv_tbl
10879 );
10880
10881 --Bug #3921591: pagarg +++ Rollover +++++++ End ++++++++++
10882 IF (is_debug_statement_on)
10883 THEN
10884 okl_debug_pub.log_debug
10885 (g_level_statement,
10886 l_module_name,
10887 'called OKL_LA_PAYMENTS_PVT.process_payment , return status: '
10888 || l_return_status
10889 );
10890 END IF;
10891 END IF;
10892
10893 IF (l_return_status = okl_api.g_ret_sts_unexp_error)
10894 THEN
10895 RAISE okl_api.g_exception_unexpected_error;
10896 ELSIF (l_return_status = okl_api.g_ret_sts_error)
10897 THEN
10898 RAISE okl_api.g_exception_error;
10899 END IF;
10900 END IF;
10901 END LOOP;
10902 END IF;
10903 END IF; -- if asset in quote
10904 END IF;
10905 END LOOP;
10906
10907 x_return_status := l_return_status;
10908
10909 IF (is_debug_procedure_on)
10910 THEN
10911 okl_debug_pub.log_debug (g_level_procedure,
10912 l_module_name,
10913 'End(-)'
10914 );
10915 END IF;
10916 EXCEPTION
10917 WHEN okl_api.g_exception_error
10918 THEN
10919 IF l_quoteobjects_csr%ISOPEN
10920 THEN
10921 CLOSE l_quoteobjects_csr;
10922 END IF;
10923
10924 IF l_trxquotes_csr%ISOPEN
10925 THEN
10926 CLOSE l_trxquotes_csr;
10927 END IF;
10928
10929 IF l_quotelines_csr%ISOPEN
10930 THEN
10931 CLOSE l_quotelines_csr;
10932 END IF;
10933
10934 IF l_cashflowstreams_csr%ISOPEN
10935 THEN
10936 CLOSE l_cashflowstreams_csr;
10937 END IF;
10938
10939 IF l_cashflowlevels_csr%ISOPEN
10940 THEN
10941 CLOSE l_cashflowlevels_csr;
10942 END IF;
10943
10944 IF l_rgpslh_csr%ISOPEN
10945 THEN
10946 CLOSE l_rgpslh_csr;
10947 END IF;
10948
10949 IF l_cashflows_csr%ISOPEN
10950 THEN
10951 CLOSE l_cashflows_csr;
10952 END IF;
10953
10954 IF l_lpayments_csr%ISOPEN
10955 THEN
10956 CLOSE l_lpayments_csr;
10957 END IF;
10958
10959 IF l_finasset_csr%ISOPEN
10960 THEN
10961 CLOSE l_finasset_csr;
10962 END IF;
10963
10964 --Bug #3921591: pagarg +++ Rollover +++
10965 -- Changed the cursor name as made it generalised
10966 IF l_lineassets_csr%ISOPEN
10967 THEN
10968 CLOSE l_lineassets_csr;
10969 END IF;
10970
10971 ROLLBACK TO update_payments;
10972 x_return_status := g_ret_sts_error;
10973
10974 IF (is_debug_exception_on)
10975 THEN
10976 okl_debug_pub.log_debug (g_level_exception,
10977 l_module_name,
10978 'EXCEPTION :' || 'G_EXCEPTION_ERROR'
10979 );
10980 END IF;
10981 WHEN okl_api.g_exception_unexpected_error
10982 THEN
10983 IF l_quoteobjects_csr%ISOPEN
10984 THEN
10985 CLOSE l_quoteobjects_csr;
10986 END IF;
10987
10988 IF l_trxquotes_csr%ISOPEN
10989 THEN
10990 CLOSE l_trxquotes_csr;
10991 END IF;
10992
10993 IF l_quotelines_csr%ISOPEN
10994 THEN
10995 CLOSE l_quotelines_csr;
10996 END IF;
10997
10998 IF l_cashflowstreams_csr%ISOPEN
10999 THEN
11000 CLOSE l_cashflowstreams_csr;
11001 END IF;
11002
11003 IF l_cashflowlevels_csr%ISOPEN
11004 THEN
11005 CLOSE l_cashflowlevels_csr;
11006 END IF;
11007
11008 IF l_rgpslh_csr%ISOPEN
11009 THEN
11010 CLOSE l_rgpslh_csr;
11011 END IF;
11012
11013 IF l_cashflows_csr%ISOPEN
11014 THEN
11015 CLOSE l_cashflows_csr;
11016 END IF;
11017
11018 IF l_lpayments_csr%ISOPEN
11019 THEN
11020 CLOSE l_lpayments_csr;
11021 END IF;
11022
11023 IF l_finasset_csr%ISOPEN
11024 THEN
11025 CLOSE l_finasset_csr;
11026 END IF;
11027
11028 --Bug #3921591: pagarg +++ Rollover +++
11029 -- Changed the cursor name as made it generalised
11030 IF l_lineassets_csr%ISOPEN
11031 THEN
11032 CLOSE l_lineassets_csr;
11033 END IF;
11034
11035 ROLLBACK TO update_payments;
11036 x_return_status := g_ret_sts_unexp_error;
11037
11038 IF (is_debug_exception_on)
11039 THEN
11040 okl_debug_pub.log_debug (g_level_exception,
11041 l_module_name,
11042 'EXCEPTION :'
11043 || 'G_EXCEPTION_UNEXPECTED_ERROR'
11044 );
11045 END IF;
11046 WHEN OTHERS
11047 THEN
11048 IF l_quoteobjects_csr%ISOPEN
11049 THEN
11050 CLOSE l_quoteobjects_csr;
11051 END IF;
11052
11053 IF l_trxquotes_csr%ISOPEN
11054 THEN
11055 CLOSE l_trxquotes_csr;
11056 END IF;
11057
11058 IF l_quotelines_csr%ISOPEN
11059 THEN
11060 CLOSE l_quotelines_csr;
11061 END IF;
11062
11063 IF l_cashflowstreams_csr%ISOPEN
11064 THEN
11065 CLOSE l_cashflowstreams_csr;
11066 END IF;
11067
11068 IF l_cashflowlevels_csr%ISOPEN
11069 THEN
11070 CLOSE l_cashflowlevels_csr;
11071 END IF;
11072
11073 IF l_rgpslh_csr%ISOPEN
11074 THEN
11075 CLOSE l_rgpslh_csr;
11076 END IF;
11077
11078 IF l_cashflows_csr%ISOPEN
11079 THEN
11080 CLOSE l_cashflows_csr;
11081 END IF;
11082
11083 IF l_lpayments_csr%ISOPEN
11084 THEN
11085 CLOSE l_lpayments_csr;
11086 END IF;
11087
11088 IF l_finasset_csr%ISOPEN
11089 THEN
11090 CLOSE l_finasset_csr;
11091 END IF;
11092
11093 --Bug #3921591: pagarg +++ Rollover +++
11094 -- Changed the cursor name as made it generalised
11095 IF l_lineassets_csr%ISOPEN
11096 THEN
11097 CLOSE l_lineassets_csr;
11098 END IF;
11099
11100 ROLLBACK TO update_payments;
11101 x_return_status := g_ret_sts_unexp_error;
11102 -- Set the oracle error message
11103 okl_api.set_message (p_app_name => g_app_name_1,
11104 p_msg_name => g_unexpected_error,
11105 p_token1 => g_sqlcode_token,
11106 p_token1_value => SQLCODE,
11107 p_token2 => g_sqlerrm_token,
11108 p_token2_value => SQLERRM
11109 );
11110
11111 IF (is_debug_exception_on)
11112 THEN
11113 okl_debug_pub.log_debug (g_level_exception,
11114 l_module_name,
11115 'EXCEPTION :'
11116 || 'OTHERS, SQLCODE: '
11117 || SQLCODE
11118 || ' , SQLERRM : '
11119 || SQLERRM
11120 );
11121 END IF;
11122 END update_payments;
11123
11124 -- Start of Commnets
11125 --
11126 -- Procedure Name : update_lines
11127 -- Description : This Procedure is Used to Update the Asset lines by
11128 -- changing the status to TERMINATED
11129 -- also update other lines like FEE, Sold Sevice and
11130 -- Usage Based Billing Lines by
11131 -- changing the status to TERMINATED, where the
11132 -- Terminated Asset lines are referenced.
11133 -- Also Sum the capital amount for fee sub lines and
11134 -- Sold service Sub lines excluding the
11135 -- terminated Asset lines to update the Top lines of FEE,
11136 -- SOLD SERVICE lines. And further
11137 -- pro-rate the payment amount respectively associated
11138 -- to the top lines of FEE, SOLD SERVICE Lines.
11139
11140 -- Business Rules :
11141 -- Parameters :
11142 -- Version :1.0
11143 -- History : 02-DEC-2002 BAKUHCIB 115.2 Bug# 2484327
11144 -- Added code to populate Message Stack in case Failure
11145 -- and Success of Call to an API
11146 -- : RMUNJULU -- 04-DEC-02 Bug # 2484327
11147 -- Moved record and tbl types and constants to spec
11148 -- Moved the setting of message stack to terminate_lines
11149 -- Added parameter p_trn_reason_code and setting that
11150 -- when lines terminated, Added x_msg_tbl parameter
11151 -- Added comments to cursors, Added code to set trn_code
11152 -- Changed code to set savepoint instead of start/end activity
11153 -- : BAKUCHIB 28-MAR-03 2877278 Added code to get the klev_tbl
11154 -- and append to it all the top service and fee lines which
11155 -- are being terminated, this will be passed to close streams
11156 -- which will close the streams for those lines
11157 -- : RMUNJULU 29-AUG-03 OKC RULES MIGRATION changes
11158 -- Changed SLL rule to LASLL
11159 -- : SECHAWLA 28-OCT-03 2846988 Update payments on quote acceptance
11160 -- Added a call to update_payments procedure
11161 -- : rmunjulu EDAT Added code for effective dated terminations
11162 -- : rmunjulu LOANS_ENHANCEMENTS get and set termination value in okl_K_lines and okl_contract_balances
11163 -- End of Comments
11164 PROCEDURE update_lines (
11165 p_api_version IN NUMBER,
11166 p_init_msg_list IN VARCHAR2,
11167 x_msg_count OUT NOCOPY NUMBER,
11168 x_msg_data OUT NOCOPY VARCHAR2,
11169 x_return_status OUT NOCOPY VARCHAR2,
11170 p_term_rec IN term_rec_type,
11171 p_sys_date IN DATE,
11172 p_klev_tbl IN klev_tbl_type,
11173 p_status IN VARCHAR2,
11174 p_trn_reason_code IN VARCHAR2,
11175 x_klev_tbl OUT NOCOPY klev_tbl_type,
11176 -- BAKUCHIB 28-MAR-03 2877278 Added parameter
11177 x_msg_tbl OUT NOCOPY g_msg_tbl
11178 )
11179 IS
11180 -- RMUNJULU Bug # 2484327 changed parameters to IN
11181 -- We need to change the status of lines
11182 CURSOR l_trmnt_line_csr (
11183 p_cle_id IN okc_k_lines_b.ID%TYPE
11184 )
11185 IS
11186 SELECT cle.ID ID
11187 FROM okc_k_lines_b cle
11188 CONNECT BY PRIOR cle.ID = cle.cle_id
11189 START WITH cle.ID = p_cle_id;
11190
11191 -- RMUNJULU Bug # 2484327 changed parameters to IN
11192 -- We need to change the status of Fee, Sold Service and Usage
11193 -- Based Billing lines
11194 CURSOR l_get_sls_csr (
11195 p_chr_id IN okc_k_headers_b.ID%TYPE,
11196 p_sts_code IN okc_k_headers_b.sts_code%TYPE,
11197 p_cle_id IN okc_k_lines_b.ID%TYPE
11198 )
11199 IS
11200 SELECT cim.cle_id cle_id
11201 FROM okc_k_items cim
11202 WHERE cim.dnz_chr_id = p_chr_id
11203 AND cim.jtot_object1_code = 'OKX_COVASST'
11204 AND cim.object1_id1 IN (
11205 SELECT cle.ID
11206 FROM okc_k_lines_b cle,
11207 okc_line_styles_b lse
11208 WHERE cle.dnz_chr_id = p_chr_id
11209 AND cle.lse_id = lse.ID
11210 AND lse.lty_code = g_fin_line_lty_code
11211 AND lse.lse_type = g_tls_type
11212 AND cle.sts_code = p_sts_code
11213 AND cle.ID = p_cle_id);
11214
11215 -- RMUNJULU Bug # 2484327 changed parameters to IN
11216 -- We need to make sure that there are not Orphaned TOP lines of Fee,
11217 -- Sold Service and Usage Based Billing Lines
11218 CURSOR l_scan_sls_csr (
11219 p_cle_id IN okc_k_lines_v.ID%TYPE
11220 )
11221 IS
11222 SELECT kle.sts_code sts_code
11223 FROM okc_k_lines_b kle
11224 WHERE kle.cle_id = p_cle_id;
11225
11226 -- RMUNJULU Bug # 2484327 changed parameters to IN
11227 -- We need to find out weahter we have fee, service, and Usage lines first
11228 -- so that we can Pro- rate and Sum up the Capital amount
11229 --and amount to the Top Lines after excluding Terminated Lines
11230 CURSOR l_chk_other_line_csr (
11231 p_chr_id IN okc_k_headers_b.ID%TYPE
11232 )
11233 IS
11234 SELECT '1'
11235 FROM DUAL
11236 WHERE EXISTS (
11237 SELECT '1'
11238 FROM okc_k_lines_b cle,
11239 okc_line_styles_b lse
11240 WHERE cle.dnz_chr_id = p_chr_id
11241 AND lse.ID = cle.lse_id
11242 AND lse.lty_code IN
11243 (g_ser_line_lty_code,
11244 g_srl_line_lty_code,
11245 g_fee_line_lty_code,
11246 g_fel_line_lty_code,
11247 g_usg_line_lty_code,
11248 g_usl_line_lty_code
11249 ));
11250
11251 -- RMUNJULU Bug # 2484327 changed parameters to IN
11252 -- We need to get the summed up amount for Sub lines of Fee and
11253 -- Sold Service Lines Excluding the terminated Lines
11254 CURSOR l_new_sls_amt_csr (
11255 p_chr_id IN okc_k_lines_v.dnz_chr_id%TYPE,
11256 p_sts_code IN okc_k_headers_b.sts_code%TYPE
11257 )
11258 IS
11259 SELECT SUM (kle.capital_amount) amount,
11260 cle.cle_id cle_id
11261 FROM okc_k_lines_b cle,
11262 okl_k_lines kle,
11263 okc_line_styles_b lse
11264 WHERE kle.ID = cle.ID
11265 AND cle.dnz_chr_id = p_chr_id
11266 AND cle.lse_id = lse.ID
11267 AND lse.lty_code IN (g_srl_line_lty_code, g_fel_line_lty_code)
11268 AND cle.sts_code <> p_sts_code
11269 AND cle.date_terminated IS NULL
11270 GROUP BY cle.cle_id;
11271
11272 -- RMUNJULU Bug # 2484327 changed parameters to IN
11273 -- We need to get the summed up amount for Sub lines of Fee and
11274 -- Sold Service Lines, Including the terminated Lines
11275 CURSOR l_old_sls_amt_csr (
11276 p_chr_id IN okc_k_lines_v.dnz_chr_id%TYPE
11277 )
11278 IS
11279 SELECT SUM (kle.capital_amount) amount,
11280 cle.cle_id cle_id
11281 FROM okc_k_lines_b cle,
11282 okl_k_lines kle,
11283 okc_line_styles_b lse
11284 WHERE kle.ID = cle.ID
11285 AND cle.dnz_chr_id = p_chr_id
11286 AND cle.lse_id = lse.ID
11287 AND lse.lty_code IN (g_srl_line_lty_code, g_fel_line_lty_code)
11288 AND cle.date_terminated IS NULL
11289 GROUP BY cle.cle_id;
11290
11291 -- RMUNJULU Bug # 2484327 changed parameters to IN
11292 -- We need to get the Payment Info for Fee and Sold Service lines
11293 CURSOR l_sls_rule_pymnt_csr (
11294 p_chr_id IN okc_k_lines_v.dnz_chr_id%TYPE,
11295 p_cle_id IN okc_k_lines_v.ID%TYPE,
11296 p_sts_code IN okc_k_headers_b.sts_code%TYPE
11297 )
11298 IS
11299 SELECT rl.ID ID,
11300 rl.rule_information6 payment_amount
11301 FROM okc_rule_groups_b rg,
11302 okc_rules_b rl,
11303 okc_k_lines_v cle,
11304 okc_line_styles_b lse
11305 WHERE cle.dnz_chr_id = p_chr_id
11306 AND cle.ID = p_cle_id
11307 AND cle.lse_id = lse.ID
11308 AND lse.lty_code IN (g_ser_line_lty_code, g_fee_line_lty_code)
11309 AND lse.lse_type = 'TLS'
11310 AND cle.cle_id IS NULL
11311 AND rg.dnz_chr_id = cle.dnz_chr_id
11312 AND rg.cle_id = cle.ID
11313 AND rg.chr_id IS NULL
11314 AND rg.ID = rl.rgp_id
11315 AND rg.rgd_code = 'LALEVL'
11316 AND rl.rule_information_category =
11317 'LASLL'
11318 -- RMUNJULU 29-AUG-03 OKC RULES MIGRATION
11319 AND EXISTS (
11320 SELECT '1'
11321 FROM okc_k_lines_v cle_sl,
11322 okc_line_styles_b lse_sl
11323 WHERE cle_sl.dnz_chr_id = p_chr_id
11324 AND cle_sl.cle_id = cle.ID
11325 AND cle_sl.lse_id = lse_sl.ID
11326 AND cle_sl.sts_code <> p_sts_code
11327 AND lse_sl.lty_code IN
11328 (g_srl_line_lty_code, g_fel_line_lty_code));
11329
11330 l_api_name CONSTANT VARCHAR2 (30) := 'update_lines';
11331 i NUMBER := 0;
11332 j NUMBER := 0;
11333 ln_dummy NUMBER := 0;
11334 l_module_name VARCHAR2 (500)
11335 := g_module_name || 'update_lines';
11336 is_debug_exception_on BOOLEAN
11337 := okl_debug_pub.check_log_on (l_module_name, g_level_exception);
11338 is_debug_procedure_on BOOLEAN
11339 := okl_debug_pub.check_log_on (l_module_name, g_level_procedure);
11340 is_debug_statement_on BOOLEAN
11341 := okl_debug_pub.check_log_on (l_module_name, g_level_statement);
11342 lv_terminate_tls VARCHAR2 (3) := NULL;
11343 ln_sls_payment_amount NUMBER := 0;
11344 ln_new_amount NUMBER := 0;
11345 ln_old_amount NUMBER := 0;
11346 ln_cle_id NUMBER := 0;
11347 l_chr_id okc_k_headers_b.ID%TYPE
11348 := p_term_rec.p_contract_id;
11349 l_akle_tbl klev_tbl_type := p_klev_tbl;
11350 l_clev_rec okl_okc_migration_pvt.clev_rec_type;
11351 l_klev_rec okl_contract_pub.klev_rec_type;
11352 lx_clev_rec okl_okc_migration_pvt.clev_rec_type;
11353 lx_klev_rec okl_contract_pub.klev_rec_type;
11354 r_clev_rec okl_okc_migration_pvt.clev_rec_type;
11355 r_klev_rec okl_contract_pub.klev_rec_type;
11356 rx_clev_rec okl_okc_migration_pvt.clev_rec_type;
11357 rx_klev_rec okl_contract_pub.klev_rec_type;
11358 m_clev_rec okl_okc_migration_pvt.clev_rec_type;
11359 m_klev_rec okl_contract_pub.klev_rec_type;
11360 mx_clev_rec okl_okc_migration_pvt.clev_rec_type;
11361 mx_klev_rec okl_contract_pub.klev_rec_type;
11362 n_clev_rec okl_okc_migration_pvt.clev_rec_type;
11363 n_klev_rec okl_contract_pub.klev_rec_type;
11364 nx_clev_rec okl_okc_migration_pvt.clev_rec_type;
11365 nx_klev_rec okl_contract_pub.klev_rec_type;
11366 l_rulv_rec okl_rule_pub.rulv_rec_type;
11367 lx_rulv_rec okl_rule_pub.rulv_rec_type;
11368 r_rulv_rec okl_rule_pub.rulv_rec_type;
11369 rx_rulv_rec okl_rule_pub.rulv_rec_type;
11370 lt_old_sls_amt g_cle_amt_tbl;
11371 lt_new_sls_amt g_cle_amt_tbl;
11372 k NUMBER := 0;
11373 lt_msg_tbl g_msg_tbl;
11374 lv_id1 okc_k_items.object1_id1%TYPE;
11375 lv_id2 okc_k_items.object1_id2%TYPE;
11376 lv_code okc_k_items.jtot_object1_code%TYPE;
11377 -- SECHAWLA 28-OCT-03 2846988 : New declarations
11378 l_return_status VARCHAR2 (1) := okl_api.g_ret_sts_success;
11379
11380 -- RMUNJULU Bug # 2484327 Added comments, changed parameters to IN
11381 -- We need to find out the object1_id1 and object1_id2 and jtot_object1_code
11382 -- to get the name of the fee or service or ubb line based on jtot_object1_code
11383 CURSOR l_item_line_csr (
11384 p_cle_id IN okc_k_lines_b.ID%TYPE,
11385 p_dnz_chr_id IN okc_k_lines_b.dnz_chr_id%TYPE
11386 )
11387 IS
11388 SELECT cim.object1_id1 object1_id1,
11389 cim.object1_id2 object1_id2,
11390 cim.jtot_object1_code jtot_object1_code
11391 FROM okc_k_items cim
11392 WHERE cim.dnz_chr_id = p_dnz_chr_id AND cim.cle_id = p_cle_id;
11393
11394 -- RMUNJULU Bug # 2484327 Added comments, changed parameters to IN
11395 -- We need to get the name of the service line
11396 CURSOR l_service_line_csr (
11397 p_id1 IN okc_k_items.object1_id1%TYPE,
11398 p_id2 IN okc_k_items.object1_id2%TYPE
11399 )
11400 IS
11401 SELECT siv.NAME NAME
11402 FROM okx_system_items_v siv
11403 WHERE siv.id1 = p_id1 AND siv.id2 = p_id2;
11404
11405 -- RMUNJULU Bug # 2484327 Added comments, changed parameters to IN
11406 -- We need to get the name of the fee line
11407 CURSOR l_fee_line_csr (
11408 p_id1 IN okc_k_items.object1_id1%TYPE,
11409 p_id2 IN okc_k_items.object1_id2%TYPE
11410 )
11411 IS
11412 SELECT ssv.NAME NAME
11413 FROM okl_strmtyp_source_v ssv
11414 WHERE ssv.id1 = p_id1 AND ssv.id2 = p_id2;
11415
11416 -- RMUNJULU Bug # 2484327 Added comments, changed parameters to IN
11417 -- We need to get the name of the UBB line
11418 CURSOR l_usage_line_csr (
11419 p_id1 IN okc_k_items.object1_id1%TYPE,
11420 p_id2 IN okc_k_items.object1_id2%TYPE
11421 )
11422 IS
11423 SELECT siv.NAME NAME
11424 FROM okx_system_items_v siv
11425 WHERE siv.id1 = p_id1 AND siv.id2 = p_id2;
11426
11427 -- BAKUCHIB 28-MAR-03 2877278 Added variable
11428 lx_klev_tbl klev_tbl_type := l_akle_tbl;
11429 -- rmunjulu EDAT
11430 l_quote_accpt_date DATE;
11431 l_quote_eff_date DATE;
11432
11433 -- rmunjulu LOANS_ENHACEMENTS
11434 CURSOR check_balances_rec_exists_csr (
11435 p_kle_id IN NUMBER
11436 )
11437 IS
11438 SELECT 'Y'
11439 FROM okl_contract_balances
11440 WHERE kle_id = p_kle_id;
11441
11442 -- rmunjulu LOANS_ENHACEMENTS
11443 l_termination_value NUMBER;
11444 lap_clev_rec okl_okc_migration_pvt.clev_rec_type;
11445 lap_klev_rec okl_contract_pub.klev_rec_type;
11446 lax_clev_rec okl_okc_migration_pvt.clev_rec_type;
11447 lax_klev_rec okl_contract_pub.klev_rec_type;
11448 p_cblv_rec okl_cbl_pvt.cblv_rec_type;
11449 x_cblv_rec okl_cbl_pvt.cblv_rec_type;
11450 l_empty_clev_rec okl_okc_migration_pvt.clev_rec_type;
11451 l_empty_klev_rec okl_contract_pub.klev_rec_type;
11452 l_balances_rec_exists VARCHAR2 (3);
11453 BEGIN
11454 -- RMUNJULU Bug # 2484327, added code to set savepoint
11455 -- Start a savepoint to rollback to if error in this block
11456 SAVEPOINT update_lines;
11457
11458 IF (is_debug_procedure_on)
11459 THEN
11460 okl_debug_pub.log_debug (g_level_procedure,
11461 l_module_name,
11462 'Begin(+)'
11463 );
11464 END IF;
11465
11466 IF (is_debug_statement_on)
11467 THEN
11468 okl_debug_pub.log_debug (g_level_statement,
11469 l_module_name,
11470 'In param, p_sys_date: ' || p_sys_date
11471 );
11472 okl_debug_pub.log_debug (g_level_statement,
11473 l_module_name,
11474 'In param, p_status: ' || p_status
11475 );
11476 okl_debug_pub.log_debug (g_level_statement,
11477 l_module_name,
11478 'In param, p_trn_reason_code: '
11479 || p_trn_reason_code
11480 );
11481 okl_debug_pub.log_debug (g_level_statement,
11482 l_module_name,
11483 'In param, p_term_rec.p_quote_id: '
11484 || p_term_rec.p_quote_id
11485 );
11486 okl_debug_pub.log_debug (g_level_statement,
11487 l_module_name,
11488 'In param, p_term_rec.p_contract_id: '
11489 || p_term_rec.p_contract_id
11490 );
11491
11492 IF p_klev_tbl.COUNT > 0
11493 THEN
11494 FOR i IN p_klev_tbl.FIRST .. p_klev_tbl.LAST
11495 LOOP
11496 IF (p_klev_tbl.EXISTS (i))
11497 THEN
11498 okl_debug_pub.log_debug (g_level_statement,
11499 l_module_name,
11500 'In param, p_klev_tbl('
11501 || i
11502 || ').p_kle_id: '
11503 || p_klev_tbl (i).p_kle_id
11504 );
11505 okl_debug_pub.log_debug (g_level_statement,
11506 l_module_name,
11507 'In param, p_klev_tbl('
11508 || i
11509 || ').p_asset_name: '
11510 || p_klev_tbl (i).p_asset_name
11511 );
11512 END IF;
11513 END LOOP;
11514 END IF;
11515 END IF;
11516
11517 x_return_status := g_ret_sts_success;
11518
11519 -- rmunjulu +++++++++ Effective Dated Termination -- start ++++++++++++++++
11520
11521 -- rmunjulu EDAT
11522 -- If quote exists then accnting date is quote accept date else sysdate
11523 IF NVL (okl_am_lease_loan_trmnt_pvt.g_quote_exists, 'N') = 'Y'
11524 THEN
11525 l_quote_accpt_date :=
11526 okl_am_lease_loan_trmnt_pvt.g_quote_accept_date;
11527 l_quote_eff_date :=
11528 okl_am_lease_loan_trmnt_pvt.g_quote_eff_from_date;
11529 ELSE
11530 l_quote_accpt_date := p_sys_date;
11531 l_quote_eff_date := p_sys_date;
11532 END IF;
11533
11534 -- rmunjulu +++++++++ Effective Dated Termination -- end ++++++++++++++++
11535
11536 -- Summing up amount of all the sub lines populating Amount and Capital amount
11537 FOR r_old_sls_amt_csr IN l_old_sls_amt_csr (p_chr_id => l_chr_id)
11538 LOOP
11539 lt_old_sls_amt (j).amount := r_old_sls_amt_csr.amount;
11540 lt_old_sls_amt (j).cle_id := r_old_sls_amt_csr.cle_id;
11541 j := j + 1;
11542 END LOOP;
11543
11544 -- Verify the Lines and Contract id
11545 IF l_akle_tbl.COUNT > 0
11546 THEN
11547 i := l_akle_tbl.FIRST;
11548
11549 LOOP
11550 validate_chr_cle_id (p_dnz_chr_id => l_chr_id,
11551 p_top_line_id => l_akle_tbl (i).p_kle_id,
11552 x_return_status => x_return_status
11553 );
11554
11555 IF (is_debug_statement_on)
11556 THEN
11557 okl_debug_pub.log_debug
11558 (g_level_statement,
11559 l_module_name,
11560 'called validate_chr_cle_id , return status: '
11561 || x_return_status
11562 );
11563 END IF;
11564
11565 IF (x_return_status = g_ret_sts_unexp_error)
11566 THEN
11567 EXIT WHEN (x_return_status = g_ret_sts_unexp_error);
11568 ELSIF (x_return_status = g_ret_sts_error)
11569 THEN
11570 EXIT WHEN (x_return_status = g_ret_sts_error);
11571 END IF;
11572
11573 -- Now we Change the status of the Lines
11574 FOR r_trmnt_line_csr IN
11575 l_trmnt_line_csr (p_cle_id => l_akle_tbl (i).p_kle_id)
11576 LOOP
11577 l_clev_rec.ID := r_trmnt_line_csr.ID;
11578 l_klev_rec.ID := r_trmnt_line_csr.ID;
11579 l_clev_rec.date_terminated := l_quote_eff_date;
11580 -- rmunjulu EDAT
11581 l_clev_rec.sts_code := p_status;
11582 -- RMUNJULU -- Bug # 2484327 -- Added code to set trn_code
11583 l_clev_rec.trn_code := p_trn_reason_code;
11584
11585 IF (is_debug_statement_on)
11586 THEN
11587 okl_debug_pub.log_debug
11588 (g_level_statement,
11589 l_module_name,
11590 'calling OKL_CONTRACT_PUB.update_contract_line'
11591 );
11592 END IF;
11593
11594 okl_contract_pub.update_contract_line
11595 (p_api_version => p_api_version,
11596 p_init_msg_list => g_false,
11597 x_return_status => x_return_status,
11598 x_msg_count => x_msg_count,
11599 x_msg_data => x_msg_data,
11600 p_clev_rec => l_clev_rec,
11601 p_klev_rec => l_klev_rec,
11602 x_clev_rec => lx_clev_rec,
11603 x_klev_rec => lx_klev_rec
11604 );
11605
11606 IF (is_debug_statement_on)
11607 THEN
11608 okl_debug_pub.log_debug
11609 (g_level_statement,
11610 l_module_name,
11611 'calling OKL_CONTRACT_PUB.update_contract_line , return status: '
11612 || x_return_status
11613 );
11614 END IF;
11615
11616 IF x_return_status <> g_ret_sts_success
11617 THEN
11618 -- Error in terminating asset ASSET_NAME.
11619 okl_api.set_message
11620 (p_app_name => g_app_name,
11621 p_msg_name => g_am_err_trmt_asset,
11622 p_token1 => 'ASSET_NAME',
11623 p_token1_value => l_akle_tbl (i).p_asset_name
11624 );
11625 ELSIF x_return_status = g_ret_sts_success
11626 THEN
11627 lt_msg_tbl (k).msg_desc := g_am_asset_trmt;
11628 lt_msg_tbl (k).msg_token1 := 'ASSET_NUMBER';
11629 lt_msg_tbl (k).msg_token1_value :=
11630 l_akle_tbl (i).p_asset_name;
11631 END IF;
11632
11633 IF (x_return_status = g_ret_sts_unexp_error)
11634 THEN
11635 EXIT WHEN (x_return_status = g_ret_sts_unexp_error);
11636 ELSIF (x_return_status = g_ret_sts_error)
11637 THEN
11638 EXIT WHEN (x_return_status = g_ret_sts_error);
11639 END IF;
11640 END LOOP;
11641
11642 IF (x_return_status = g_ret_sts_unexp_error)
11643 THEN
11644 EXIT WHEN (x_return_status = g_ret_sts_unexp_error);
11645 ELSIF (x_return_status = g_ret_sts_error)
11646 THEN
11647 EXIT WHEN (x_return_status = g_ret_sts_error);
11648 END IF;
11649
11650 --Now we are terminating the Service Line, Fee line, Ubb Lines,
11651 -- if exists, Where the Asset lines are terminated
11652 FOR r_get_sls_csr IN
11653 l_get_sls_csr (p_chr_id => l_chr_id,
11654 p_sts_code => p_status,
11655 p_cle_id => l_akle_tbl (i).p_kle_id
11656 )
11657 LOOP
11658 r_clev_rec.ID := r_get_sls_csr.cle_id;
11659 r_klev_rec.ID := r_get_sls_csr.cle_id;
11660 r_clev_rec.date_terminated := l_quote_eff_date;
11661 -- rmunjulu EDAT
11662 r_clev_rec.sts_code := p_status;
11663 -- RMUNJULU -- Bug # 2484327 -- Added code to set trn_code
11664 r_clev_rec.trn_code := p_trn_reason_code;
11665
11666 IF (is_debug_statement_on)
11667 THEN
11668 okl_debug_pub.log_debug
11669 (g_level_statement,
11670 l_module_name,
11671 'calling OKL_CONTRACT_PUB.update_contract_line'
11672 );
11673 END IF;
11674
11675 okl_contract_pub.update_contract_line
11676 (p_api_version => p_api_version,
11677 p_init_msg_list => g_false,
11678 x_return_status => x_return_status,
11679 x_msg_count => x_msg_count,
11680 x_msg_data => x_msg_data,
11681 p_clev_rec => r_clev_rec,
11682 p_klev_rec => r_klev_rec,
11683 x_clev_rec => rx_clev_rec,
11684 x_klev_rec => rx_klev_rec
11685 );
11686
11687 IF (is_debug_statement_on)
11688 THEN
11689 okl_debug_pub.log_debug
11690 (g_level_statement,
11691 l_module_name,
11692 'called OKL_CONTRACT_PUB.update_contract_line , return status: '
11693 || x_return_status
11694 );
11695 END IF;
11696
11697 IF x_return_status <> g_ret_sts_success
11698 THEN
11699 -- Error in terminating sublines of service lines, fee lines and
11700 -- UBB lines of asset ASSET_NAME.
11701 okl_api.set_message
11702 (p_app_name => g_app_name,
11703 p_msg_name => g_am_err_trmt_asset_ln,
11704 p_token1 => 'ASSET_NAME',
11705 p_token1_value => l_akle_tbl (i).p_asset_name
11706 );
11707 END IF;
11708
11709 IF (x_return_status = g_ret_sts_unexp_error)
11710 THEN
11711 EXIT WHEN (x_return_status = g_ret_sts_unexp_error);
11712 ELSIF (x_return_status = g_ret_sts_error)
11713 THEN
11714 EXIT WHEN (x_return_status = g_ret_sts_error);
11715 END IF;
11716
11717 -- Now need to make sure we do not have orphaned Top Lines
11718 -- Where the sub lines are terminated.
11719 -- If we have we need to terminate the Top Line also.
11720 FOR r_l_scan_sls_csr IN
11721 l_scan_sls_csr (p_cle_id => rx_clev_rec.cle_id)
11722 LOOP
11723 IF r_l_scan_sls_csr.sts_code <> p_status
11724 THEN
11725 lv_terminate_tls := 'N';
11726 EXIT WHEN (lv_terminate_tls = 'N');
11727 ELSIF r_l_scan_sls_csr.sts_code = p_status
11728 THEN
11729 lv_terminate_tls := 'Y';
11730 END IF;
11731 END LOOP;
11732
11733 IF lv_terminate_tls = 'Y'
11734 THEN
11735 IF rx_clev_rec.cle_id <> g_miss_num
11736 OR rx_clev_rec.cle_id IS NOT NULL
11737 THEN
11738 m_clev_rec.ID := rx_clev_rec.cle_id;
11739 m_klev_rec.ID := rx_clev_rec.cle_id;
11740 m_clev_rec.date_terminated := l_quote_eff_date;
11741 -- rmunjulu EDAT
11742 m_clev_rec.sts_code := p_status;
11743 -- RMUNJULU -- Bug # 2484327 -- Added code to set trn_code
11744 m_clev_rec.trn_code := p_trn_reason_code;
11745
11746 IF (is_debug_statement_on)
11747 THEN
11748 okl_debug_pub.log_debug
11749 (g_level_statement,
11750 l_module_name,
11751 'calling OKL_CONTRACT_PUB.update_contract_line'
11752 );
11753 END IF;
11754
11755 okl_contract_pub.update_contract_line
11756 (p_api_version => p_api_version,
11757 p_init_msg_list => g_false,
11758 x_return_status => x_return_status,
11759 x_msg_count => x_msg_count,
11760 x_msg_data => x_msg_data,
11761 p_clev_rec => m_clev_rec,
11762 p_klev_rec => m_klev_rec,
11763 x_clev_rec => mx_clev_rec,
11764 x_klev_rec => mx_klev_rec
11765 );
11766
11767 IF (is_debug_statement_on)
11768 THEN
11769 okl_debug_pub.log_debug
11770 (g_level_statement,
11771 l_module_name,
11772 'called OKL_CONTRACT_PUB.update_contract_line , return status: '
11773 || x_return_status
11774 );
11775 END IF;
11776
11777 IF x_return_status <> g_ret_sts_success
11778 THEN
11779 -- Error in terminating service lines, fee lines and UBB lines.
11780 okl_api.set_message
11781 (p_app_name => g_app_name,
11782 p_msg_name => g_am_err_trmt_top_ln);
11783 ELSIF x_return_status = g_ret_sts_success
11784 THEN
11785 OPEN l_item_line_csr
11786 (p_cle_id => mx_clev_rec.ID,
11787 p_dnz_chr_id => mx_clev_rec.dnz_chr_id);
11788
11789 FETCH l_item_line_csr
11790 INTO lv_id1,
11791 lv_id2,
11792 lv_code;
11793
11794 CLOSE l_item_line_csr;
11795
11796 IF lv_code = 'OKL_STRMTYP'
11797 THEN
11798 k := k + 1;
11799
11800 OPEN l_fee_line_csr (p_id1 => lv_id1,
11801 p_id2 => lv_id2);
11802
11803 FETCH l_fee_line_csr
11804 INTO lt_msg_tbl (k).msg_token1_value;
11805
11806 CLOSE l_fee_line_csr;
11807
11808 lt_msg_tbl (k).msg_desc := g_am_fee_trmt;
11809 lt_msg_tbl (k).msg_token1 := 'FEE_NAME';
11810 ELSIF lv_code = 'OKX_SERVICE'
11811 THEN
11812 k := k + 1;
11813
11814 OPEN l_service_line_csr (p_id1 => lv_id1,
11815 p_id2 => lv_id2);
11816
11817 FETCH l_service_line_csr
11818 INTO lt_msg_tbl (k).msg_token1_value;
11819
11820 CLOSE l_service_line_csr;
11821
11822 lt_msg_tbl (k).msg_desc := g_am_service_trmt;
11823 lt_msg_tbl (k).msg_token1 := 'SERVICE_NAME';
11824 ELSIF lv_code = 'OKX_USAGE'
11825 THEN
11826 k := k + 1;
11827
11828 OPEN l_usage_line_csr (p_id1 => lv_id1,
11829 p_id2 => lv_id2);
11830
11831 FETCH l_usage_line_csr
11832 INTO lt_msg_tbl (k).msg_token1_value;
11833
11834 CLOSE l_usage_line_csr;
11835
11836 lt_msg_tbl (k).msg_desc := g_am_usage_trmt;
11837 lt_msg_tbl (k).msg_token1 := 'USAGE_NAME';
11838 END IF;
11839 END IF;
11840
11841 -- BAKUCHIB 28-MAR-03 2877278 Append to the klev_tbl this top service/fee
11842 -- line which too is being terminated
11843 lx_klev_tbl (lx_klev_tbl.LAST + 1).p_kle_id :=
11844 mx_clev_rec.ID;
11845
11846 IF (x_return_status = g_ret_sts_unexp_error)
11847 THEN
11848 EXIT WHEN (x_return_status = g_ret_sts_unexp_error);
11849 ELSIF (x_return_status = g_ret_sts_error)
11850 THEN
11851 EXIT WHEN (x_return_status = g_ret_sts_error);
11852 END IF;
11853 ELSE
11854 x_return_status := g_ret_sts_error;
11855 EXIT WHEN (x_return_status = g_ret_sts_error);
11856 END IF;
11857 END IF;
11858 END LOOP;
11859
11860 IF (x_return_status = g_ret_sts_unexp_error)
11861 THEN
11862 EXIT WHEN (x_return_status = g_ret_sts_unexp_error);
11863 ELSIF (x_return_status = g_ret_sts_error)
11864 THEN
11865 EXIT WHEN (x_return_status = g_ret_sts_error);
11866 END IF;
11867
11868 -- rmunjulu LOANS_ENHACEMENTS -- start
11869 -- get termination value for the terminated asset
11870 l_termination_value :=
11871 okl_am_util_pvt.get_actual_asset_residual
11872 (p_khr_id => l_chr_id,
11873 p_kle_id => l_akle_tbl (i).p_kle_id);
11874 -- update okc_k_lines termination value
11875 lap_clev_rec := l_empty_clev_rec;
11876 lap_klev_rec := l_empty_klev_rec;
11877 lap_clev_rec.ID := l_akle_tbl (i).p_kle_id;
11878 lap_klev_rec.ID := l_akle_tbl (i).p_kle_id;
11879 lap_klev_rec.termination_value := l_termination_value;
11880
11881 IF (is_debug_statement_on)
11882 THEN
11883 okl_debug_pub.log_debug
11884 (g_level_statement,
11885 l_module_name,
11886 'calling OKL_CONTRACT_PUB.update_contract_line'
11887 );
11888 END IF;
11889
11890 okl_contract_pub.update_contract_line
11891 (p_api_version => p_api_version,
11892 p_init_msg_list => g_false,
11893 x_return_status => l_return_status,
11894 x_msg_count => x_msg_count,
11895 x_msg_data => x_msg_data,
11896 p_clev_rec => lap_clev_rec,
11897 p_klev_rec => lap_klev_rec,
11898 x_clev_rec => lax_clev_rec,
11899 x_klev_rec => lax_klev_rec
11900 );
11901
11902 IF (is_debug_statement_on)
11903 THEN
11904 okl_debug_pub.log_debug
11905 (g_level_statement,
11906 l_module_name,
11907 'called OKL_CONTRACT_PUB.update_contract_line , return status: '
11908 || l_return_status
11909 );
11910 END IF;
11911
11912 -- Raise exception to rollback to savepoint
11913 IF (l_return_status = g_ret_sts_unexp_error)
11914 THEN
11915 RAISE okl_api.g_exception_unexpected_error;
11916 ELSIF (l_return_status = g_ret_sts_error)
11917 THEN
11918 RAISE okl_api.g_exception_error;
11919 END IF;
11920
11921 -- update balances table
11922 -- check if rec exists if exists then update else create
11923 OPEN check_balances_rec_exists_csr (l_akle_tbl (i).p_kle_id);
11924
11925 FETCH check_balances_rec_exists_csr
11926 INTO l_balances_rec_exists;
11927
11928 CLOSE check_balances_rec_exists_csr;
11929
11930 p_cblv_rec.khr_id := l_chr_id;
11931 p_cblv_rec.kle_id := l_akle_tbl (i).p_kle_id;
11932 p_cblv_rec.termination_value_amt := l_termination_value;
11933 p_cblv_rec.termination_date := l_quote_eff_date;
11934
11935 IF NVL (l_balances_rec_exists, 'N') = 'Y'
11936 THEN
11937 IF (is_debug_statement_on)
11938 THEN
11939 okl_debug_pub.log_debug (g_level_statement,
11940 l_module_name,
11941 'calling OKL_CBL_PVT.update_row'
11942 );
11943 END IF;
11944
11945 okl_cbl_pvt.update_row (p_api_version => p_api_version,
11946 p_init_msg_list => okl_api.g_false,
11947 x_return_status => x_return_status,
11948 x_msg_count => x_msg_count,
11949 x_msg_data => x_msg_data,
11950 p_cblv_rec => p_cblv_rec,
11951 x_cblv_rec => x_cblv_rec
11952 );
11953
11954 IF (is_debug_statement_on)
11955 THEN
11956 okl_debug_pub.log_debug
11957 (g_level_statement,
11958 l_module_name,
11959 'called OKL_CBL_PVT.update_row , return status: '
11960 || x_return_status
11961 );
11962 END IF;
11963
11964 -- Raise exception to rollback to savepoint
11965 IF (l_return_status = g_ret_sts_unexp_error)
11966 THEN
11967 RAISE okl_api.g_exception_unexpected_error;
11968 ELSIF (l_return_status = g_ret_sts_error)
11969 THEN
11970 RAISE okl_api.g_exception_error;
11971 END IF;
11972 ELSE
11973 -- balances rec does not exist so insert
11974 IF (is_debug_statement_on)
11975 THEN
11976 okl_debug_pub.log_debug (g_level_statement,
11977 l_module_name,
11978 'calling OKL_CBL_PVT.insert_row'
11979 );
11980 END IF;
11981
11982 okl_cbl_pvt.insert_row (p_api_version => p_api_version,
11983 p_init_msg_list => okl_api.g_false,
11984 x_return_status => x_return_status,
11985 x_msg_count => x_msg_count,
11986 x_msg_data => x_msg_data,
11987 p_cblv_rec => p_cblv_rec,
11988 x_cblv_rec => x_cblv_rec
11989 );
11990
11991 IF (is_debug_statement_on)
11992 THEN
11993 okl_debug_pub.log_debug
11994 (g_level_statement,
11995 l_module_name,
11996 'called OKL_CBL_PVT.insert_row , return status: '
11997 || x_return_status
11998 );
11999 END IF;
12000
12001 -- Raise exception to rollback to savepoint
12002 IF (l_return_status = g_ret_sts_unexp_error)
12003 THEN
12004 RAISE okl_api.g_exception_unexpected_error;
12005 ELSIF (l_return_status = g_ret_sts_error)
12006 THEN
12007 RAISE okl_api.g_exception_error;
12008 END IF;
12009 END IF;
12010
12011 -- rmunjulu LOANS_ENHACEMENTS -- end
12012 EXIT WHEN (i = l_akle_tbl.LAST);
12013 i := l_akle_tbl.NEXT (i);
12014 k := k + 1;
12015 END LOOP;
12016
12017 IF (x_return_status = g_ret_sts_unexp_error)
12018 THEN
12019 RAISE okl_api.g_exception_unexpected_error;
12020 ELSIF (x_return_status = g_ret_sts_error)
12021 THEN
12022 RAISE okl_api.g_exception_error;
12023 END IF;
12024 ELSE
12025 -- RMUNJULU -- Bug # 2484327 -- Changed to call set_message with =>
12026 -- No assets found for termination.
12027 okl_api.set_message (p_app_name => g_app_name,
12028 p_msg_name => g_required_value,
12029 p_token1 => g_col_name_token,
12030 p_token1_value => 'p_klev_tbl.id'
12031 );
12032 RAISE okl_api.g_exception_error;
12033 END IF;
12034
12035 --29-JUL-04 SECHAWLA 3798158 : Commented out the check for existence of service/fee/usage lines
12036 -- Payments should be updated even if K has no service/fee/usage lines attached
12037
12038 /*
12039 -- We need to find out whether we have fee, service, and Usage lines first
12040 -- so that we can process further
12041 OPEN l_chk_other_line_csr(p_chr_id => l_chr_id);
12042 FETCH l_chk_other_line_csr INTO ln_dummy;
12043 CLOSE l_chk_other_line_csr;
12044
12045 IF ln_dummy = 1 THEN
12046 */
12047 -- SECHAWLA 28-OCT-03 2846988 Added the following procedure call to update payments on the
12048 -- contract, when a partial termination quote is accepted
12049 update_payments (p_api_version => p_api_version,
12050 p_init_msg_list => okc_api.g_false,
12051 x_msg_count => x_msg_count,
12052 x_msg_data => x_msg_data,
12053 x_return_status => l_return_status,
12054 p_quote_id => p_term_rec.p_quote_id
12055 );
12056
12057 IF (is_debug_statement_on)
12058 THEN
12059 okl_debug_pub.log_debug
12060 (g_level_statement,
12061 l_module_name,
12062 'called update_payments , return status: '
12063 || l_return_status
12064 );
12065 END IF;
12066
12067 IF (l_return_status = okl_api.g_ret_sts_unexp_error)
12068 THEN
12069 RAISE okl_api.g_exception_unexpected_error;
12070 ELSIF (l_return_status = okl_api.g_ret_sts_error)
12071 THEN
12072 RAISE okl_api.g_exception_error;
12073 END IF;
12074
12075 -- SECHAWLA 28-OCT-03 2846988 : Commented out the following code. The above call now updates the payments
12076
12077 /* -- Summing up amount of all the sub lines which are not
12078 -- Terminated populating Amount and Capital amount
12079 FOR r_new_sls_amt_csr IN l_new_sls_amt_csr(p_chr_id => l_chr_id,
12080 p_sts_code => p_status) LOOP
12081
12082 ln_new_amount := ROUND(r_new_sls_amt_csr.amount,2);
12083 n_klev_rec.amount := ROUND(r_new_sls_amt_csr.amount,2);
12084 n_klev_rec.capital_amount := ROUND(r_new_sls_amt_csr.amount,2);
12085 n_klev_rec.id := r_new_sls_amt_csr.cle_id;
12086 n_clev_rec.id := r_new_sls_amt_csr.cle_id;
12087
12088 OKL_CONTRACT_PUB.update_contract_line(
12089 p_api_version => p_api_version,
12090 p_init_msg_list => G_FALSE,
12091 x_return_status => x_return_status,
12092 x_msg_count => x_msg_count,
12093 x_msg_data => x_msg_data,
12094 p_clev_rec => n_clev_rec,
12095 p_klev_rec => n_klev_rec,
12096 x_clev_rec => nx_clev_rec,
12097 x_klev_rec => nx_klev_rec);
12098
12099 IF x_return_status <> G_RET_STS_SUCCESS THEN
12100
12101 -- Error in updating amounts of service and fee lines.
12102 OKL_API.set_message(
12103 p_app_name => G_APP_NAME,
12104 p_msg_name => G_AM_ERR_UPD_AMT);
12105
12106
12107 END IF;
12108
12109 IF (x_return_status = G_RET_STS_UNEXP_ERROR) THEN
12110 EXIT WHEN (x_return_status = G_RET_STS_ERROR);
12111 ELSIF (x_return_status = G_RET_STS_ERROR) THEN
12112 EXIT WHEN (x_return_status = G_RET_STS_ERROR);
12113 END IF;
12114
12115 -- We need to pro-rate the payment amount of top service
12116 -- or fee line having Sub lines
12117 FOR r_sls_rule_pymnt_csr IN l_sls_rule_pymnt_csr(
12118 p_chr_id => l_chr_id,
12119 p_cle_id => nx_clev_rec.id,
12120 p_sts_code => p_status) LOOP
12121
12122 IF lt_old_sls_amt.COUNT > 0 THEN
12123 j := lt_old_sls_amt.FIRST;
12124 LOOP
12125 IF lt_old_sls_amt(j).cle_id = nx_clev_rec.id THEN
12126 ln_old_amount := lt_old_sls_amt(j).amount;
12127 EXIT WHEN (lt_old_sls_amt(j).cle_id = nx_clev_rec.id);
12128 END IF;
12129 EXIT WHEN (j = lt_old_sls_amt.LAST);
12130 j := lt_old_sls_amt.NEXT(j);
12131 END LOOP;
12132 END IF;
12133
12134 IF (ln_old_amount IS NOT NULL OR
12135 ln_old_amount <> G_MISS_NUM) AND
12136 (ln_new_amount IS NOT NULL OR
12137 ln_new_amount <> G_MISS_NUM) THEN
12138 IF ln_old_amount <> 0 THEN
12139 ln_sls_payment_amount := r_sls_rule_pymnt_csr.payment_amount *
12140 ln_new_amount/ln_old_amount;
12141 r_rulv_rec.rule_information6 := round(ln_sls_payment_amount,2);
12142 END IF;
12143 END IF;
12144
12145 r_rulv_rec.id := r_sls_rule_pymnt_csr.id;
12146
12147 OKL_RULE_PUB.update_rule(
12148 p_api_version => p_api_version,
12149 p_init_msg_list => G_FALSE,
12150 x_return_status => x_return_status,
12151 x_msg_count => x_msg_count,
12152 x_msg_data => x_msg_data,
12153 p_rulv_rec => r_rulv_rec,
12154 x_rulv_rec => rx_rulv_rec);
12155
12156
12157 IF x_return_status <> G_RET_STS_SUCCESS THEN
12158
12159 -- Error in updating payment amounts of service and fee lines.
12160 OKL_API.set_message(
12161 p_app_name => G_APP_NAME,
12162 p_msg_name => G_AM_ERR_UPD_PAY_AMT);
12163
12164 END IF;
12165
12166
12167
12168 IF (x_return_status = G_RET_STS_UNEXP_ERROR) THEN
12169 EXIT WHEN (x_return_status = G_RET_STS_ERROR);
12170 ELSIF (x_return_status = G_RET_STS_ERROR) THEN
12171 EXIT WHEN (x_return_status = G_RET_STS_ERROR);
12172 END IF;
12173
12174 END LOOP;
12175
12176 IF (x_return_status = G_RET_STS_UNEXP_ERROR) THEN
12177 EXIT WHEN (x_return_status = G_RET_STS_ERROR);
12178 ELSIF (x_return_status = G_RET_STS_ERROR) THEN
12179 EXIT WHEN (x_return_status = G_RET_STS_ERROR);
12180 END IF;
12181
12182 END LOOP;
12183
12184 IF (x_return_status = G_RET_STS_UNEXP_ERROR) THEN
12185 RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
12186 ELSIF (x_return_status = G_RET_STS_ERROR) THEN
12187 RAISE OKL_API.G_EXCEPTION_ERROR;
12188 END IF;
12189 */
12190
12191 -- END IF; --29-JUL-04 SECHAWLA 3798158
12192
12193 -- RMUNJULU -- 04-DEC-02 Bug # 2484327-- Set the x_msg_tbl
12194 x_msg_tbl := lt_msg_tbl;
12195 -- BAKUCHIB 28-MAR-03 2877278 Set new klev_tbl which has the top service and fee
12196 -- lines which too needs to be terminated to x_klev_tbl
12197 x_klev_tbl := lx_klev_tbl;
12198
12199 IF (is_debug_procedure_on)
12200 THEN
12201 okl_debug_pub.log_debug (g_level_procedure,
12202 l_module_name,
12203 'End(-)'
12204 );
12205 END IF;
12206 EXCEPTION
12207 WHEN okl_api.g_exception_error
12208 THEN
12209 IF l_trmnt_line_csr%ISOPEN
12210 THEN
12211 CLOSE l_trmnt_line_csr;
12212 END IF;
12213
12214 IF l_chk_other_line_csr%ISOPEN
12215 THEN
12216 CLOSE l_chk_other_line_csr;
12217 END IF;
12218
12219 IF l_get_sls_csr%ISOPEN
12220 THEN
12221 CLOSE l_get_sls_csr;
12222 END IF;
12223
12224 IF l_scan_sls_csr%ISOPEN
12225 THEN
12226 CLOSE l_scan_sls_csr;
12227 END IF;
12228
12229 IF l_new_sls_amt_csr%ISOPEN
12230 THEN
12231 CLOSE l_new_sls_amt_csr;
12232 END IF;
12233
12234 IF l_old_sls_amt_csr%ISOPEN
12235 THEN
12236 CLOSE l_old_sls_amt_csr;
12237 END IF;
12238
12239 IF l_sls_rule_pymnt_csr%ISOPEN
12240 THEN
12241 CLOSE l_sls_rule_pymnt_csr;
12242 END IF;
12243
12244 IF l_item_line_csr%ISOPEN
12245 THEN
12246 CLOSE l_item_line_csr;
12247 END IF;
12248
12249 IF l_service_line_csr%ISOPEN
12250 THEN
12251 CLOSE l_service_line_csr;
12252 END IF;
12253
12254 IF l_fee_line_csr%ISOPEN
12255 THEN
12256 CLOSE l_fee_line_csr;
12257 END IF;
12258
12259 IF l_usage_line_csr%ISOPEN
12260 THEN
12261 CLOSE l_usage_line_csr;
12262 END IF;
12263
12264 -- RMUNJULU Bug # 2484327 added code to rollback to savepoint and set
12265 -- return status
12266 ROLLBACK TO update_lines;
12267 x_return_status := g_ret_sts_error;
12268
12269 IF (is_debug_exception_on)
12270 THEN
12271 okl_debug_pub.log_debug (g_level_exception,
12272 l_module_name,
12273 'EXCEPTION :' || 'G_EXCEPTION_ERROR'
12274 );
12275 END IF;
12276 WHEN okl_api.g_exception_unexpected_error
12277 THEN
12278 IF l_trmnt_line_csr%ISOPEN
12279 THEN
12280 CLOSE l_trmnt_line_csr;
12281 END IF;
12282
12283 IF l_chk_other_line_csr%ISOPEN
12284 THEN
12285 CLOSE l_chk_other_line_csr;
12286 END IF;
12287
12288 IF l_get_sls_csr%ISOPEN
12289 THEN
12290 CLOSE l_get_sls_csr;
12291 END IF;
12292
12293 IF l_scan_sls_csr%ISOPEN
12294 THEN
12295 CLOSE l_scan_sls_csr;
12296 END IF;
12297
12298 IF l_new_sls_amt_csr%ISOPEN
12299 THEN
12300 CLOSE l_new_sls_amt_csr;
12301 END IF;
12302
12303 IF l_old_sls_amt_csr%ISOPEN
12304 THEN
12305 CLOSE l_old_sls_amt_csr;
12306 END IF;
12307
12308 IF l_sls_rule_pymnt_csr%ISOPEN
12309 THEN
12310 CLOSE l_sls_rule_pymnt_csr;
12311 END IF;
12312
12313 IF l_item_line_csr%ISOPEN
12314 THEN
12315 CLOSE l_item_line_csr;
12316 END IF;
12317
12318 IF l_service_line_csr%ISOPEN
12319 THEN
12320 CLOSE l_service_line_csr;
12321 END IF;
12322
12323 IF l_fee_line_csr%ISOPEN
12324 THEN
12325 CLOSE l_fee_line_csr;
12326 END IF;
12327
12328 IF l_usage_line_csr%ISOPEN
12329 THEN
12330 CLOSE l_usage_line_csr;
12331 END IF;
12332
12333 -- RMUNJULU Bug # 2484327 added code to rollback to savepoint and set
12334 -- return status
12335 ROLLBACK TO update_lines;
12336 x_return_status := g_ret_sts_unexp_error;
12337
12338 IF (is_debug_exception_on)
12339 THEN
12340 okl_debug_pub.log_debug (g_level_exception,
12341 l_module_name,
12342 'EXCEPTION :'
12343 || 'G_EXCEPTION_UNEXPECTED_ERROR'
12344 );
12345 END IF;
12346 WHEN OTHERS
12347 THEN
12348 IF l_trmnt_line_csr%ISOPEN
12349 THEN
12350 CLOSE l_trmnt_line_csr;
12351 END IF;
12352
12353 IF l_chk_other_line_csr%ISOPEN
12354 THEN
12355 CLOSE l_chk_other_line_csr;
12356 END IF;
12357
12358 IF l_get_sls_csr%ISOPEN
12359 THEN
12360 CLOSE l_get_sls_csr;
12361 END IF;
12362
12363 IF l_scan_sls_csr%ISOPEN
12364 THEN
12365 CLOSE l_scan_sls_csr;
12366 END IF;
12367
12368 IF l_new_sls_amt_csr%ISOPEN
12369 THEN
12370 CLOSE l_new_sls_amt_csr;
12371 END IF;
12372
12373 IF l_old_sls_amt_csr%ISOPEN
12374 THEN
12375 CLOSE l_old_sls_amt_csr;
12376 END IF;
12377
12378 IF l_sls_rule_pymnt_csr%ISOPEN
12379 THEN
12380 CLOSE l_sls_rule_pymnt_csr;
12381 END IF;
12382
12383 IF l_item_line_csr%ISOPEN
12384 THEN
12385 CLOSE l_item_line_csr;
12386 END IF;
12387
12388 IF l_service_line_csr%ISOPEN
12389 THEN
12390 CLOSE l_service_line_csr;
12391 END IF;
12392
12393 IF l_fee_line_csr%ISOPEN
12394 THEN
12395 CLOSE l_fee_line_csr;
12396 END IF;
12397
12398 IF l_usage_line_csr%ISOPEN
12399 THEN
12400 CLOSE l_usage_line_csr;
12401 END IF;
12402
12403 -- RMUNJULU Bug # 2484327 added code to rollback to savepoint and set
12404 -- return status
12405 ROLLBACK TO update_lines;
12406 x_return_status := g_ret_sts_unexp_error;
12407 -- Set the oracle error message
12408 okl_api.set_message (p_app_name => g_app_name_1,
12409 p_msg_name => g_unexpected_error,
12410 p_token1 => g_sqlcode_token,
12411 p_token1_value => SQLCODE,
12412 p_token2 => g_sqlerrm_token,
12413 p_token2_value => SQLERRM
12414 );
12415
12416 IF (is_debug_exception_on)
12417 THEN
12418 okl_debug_pub.log_debug (g_level_exception,
12419 l_module_name,
12420 'EXCEPTION :'
12421 || 'OTHERS, SQLCODE: '
12422 || SQLCODE
12423 || ' , SQLERRM : '
12424 || SQLERRM
12425 );
12426 END IF;
12427 END update_lines;
12428
12429 -- Start of comments
12430 --
12431 -- Procedure Name : update_contract
12432 -- Desciption : Will terminate the contract if all lines terminated
12433 -- Business Rules :
12434 -- Parameters :
12435 -- Version : 1.0
12436 -- History : RMUNJULU 04-DEC-02 Bug # 2484327 Procedure Created
12437 -- : RMUNJULU 18-FEB-03 2805703 Changed logic to terminate
12438 -- any hanging lines for the contract before terminating the
12439 -- contract
12440 -- : RMUNJULU 03-MAR-03 2830997 Fixed the exception block
12441 -- : rmunjulu EDAT Added code to get effective dates and set
12442 -- termination date accordingly.
12443 --
12444 -- End of comments
12445 PROCEDURE update_contract (
12446 p_api_version IN NUMBER,
12447 p_init_msg_list IN VARCHAR2,
12448 x_msg_count OUT NOCOPY NUMBER,
12449 x_msg_data OUT NOCOPY VARCHAR2,
12450 x_return_status OUT NOCOPY VARCHAR2,
12451 p_term_rec IN term_rec_type,
12452 p_sys_date IN DATE,
12453 p_status IN VARCHAR2,
12454 p_trn_reason_code IN VARCHAR2,
12455 px_msg_tbl IN OUT NOCOPY g_msg_tbl
12456 )
12457 IS
12458 -- Get the contract details
12459 CURSOR get_k_dtls_csr (
12460 p_khr_id IN NUMBER
12461 )
12462 IS
12463 SELECT khr.object_version_number object_version_number,
12464 khr.sts_code sts_code,
12465 khr.authoring_org_id authoring_org_id
12466 --CDUBEY authoring_org_id added for MOAC
12467 FROM okc_k_headers_v khr
12468 WHERE khr.ID = p_khr_id;
12469
12470 -- Cursor to get the ste code
12471 CURSOR get_old_ste_code_csr (
12472 p_sts_code VARCHAR2
12473 )
12474 IS
12475 SELECT stv.ste_code ste_code
12476 FROM okc_statuses_v stv
12477 WHERE stv.code = p_sts_code;
12478
12479 -- Cursor to get the meaning of the sts_code passed
12480 CURSOR get_sts_meaning_csr (
12481 p_sts_code IN VARCHAR2
12482 )
12483 IS
12484 SELECT stv.meaning meaning
12485 FROM okc_statuses_v stv
12486 WHERE stv.code = p_sts_code;
12487
12488 -- RMUNJULU 18-FEB-03 2805703 cursor to get active
12489 -- service or fee lines attached to contract directly
12490 CURSOR get_k_serv_fee_lines_csr (
12491 p_khr_id IN NUMBER
12492 )
12493 IS
12494 SELECT kle.ID ID
12495 FROM okc_k_lines_v kle,
12496 okc_k_headers_v khr
12497 WHERE kle.dnz_chr_id = p_khr_id
12498 AND kle.sts_code = khr.sts_code
12499 AND kle.chr_id = khr.ID;
12500
12501 l_return_status VARCHAR2 (1) := g_ret_sts_success;
12502 l_api_name CONSTANT VARCHAR2 (30) := 'update_contract';
12503 l_api_version CONSTANT NUMBER := 1;
12504 l_id NUMBER := -9999;
12505 get_k_dtls_rec get_k_dtls_csr%ROWTYPE;
12506 l_ste_code okc_statuses_v.code%TYPE;
12507 lp_chrv_rec okc_contract_pub.chrv_rec_type;
12508 lx_chrv_rec okc_contract_pub.chrv_rec_type;
12509 l_sts_meaning VARCHAR2 (300);
12510 l_msg_tbl g_msg_tbl := px_msg_tbl;
12511 l_count NUMBER;
12512 l_module_name VARCHAR2 (500)
12513 := g_module_name || 'update_contract';
12514 is_debug_exception_on BOOLEAN
12515 := okl_debug_pub.check_log_on (l_module_name, g_level_exception);
12516 is_debug_procedure_on BOOLEAN
12517 := okl_debug_pub.check_log_on (l_module_name, g_level_procedure);
12518 is_debug_statement_on BOOLEAN
12519 := okl_debug_pub.check_log_on (l_module_name, g_level_statement);
12520 -- RMUNJULU 18-FEB-03 2805703 Added variables
12521 l_clev_rec okl_okc_migration_pvt.clev_rec_type;
12522 l_klev_rec okl_contract_pub.klev_rec_type;
12523 lx_clev_rec okl_okc_migration_pvt.clev_rec_type;
12524 lx_klev_rec okl_contract_pub.klev_rec_type;
12525 -- rmunjulu EDAT
12526 l_quote_accpt_date DATE;
12527 l_quote_eff_date DATE;
12528 l_authoring_org_id NUMBER;
12529 --CDUBEY l_authoring_org_id added for MOAC
12530 BEGIN
12531 -- Start a savepoint to rollback to if error
12532 SAVEPOINT update_contract;
12533
12534 IF (is_debug_procedure_on)
12535 THEN
12536 okl_debug_pub.log_debug (g_level_procedure,
12537 l_module_name,
12538 'Begin(+)'
12539 );
12540 END IF;
12541
12542 IF (is_debug_statement_on)
12543 THEN
12544 okl_debug_pub.log_debug (g_level_statement,
12545 l_module_name,
12546 'In param, p_sys_date: ' || p_sys_date
12547 );
12548 okl_debug_pub.log_debug (g_level_statement,
12549 l_module_name,
12550 'In param, p_status: ' || p_status
12551 );
12552 okl_debug_pub.log_debug (g_level_statement,
12553 l_module_name,
12554 'In param, p_trn_reason_code: '
12555 || p_trn_reason_code
12556 );
12557 okl_debug_pub.log_debug (g_level_statement,
12558 l_module_name,
12559 'In param, p_term_rec.p_contract_id: '
12560 || p_term_rec.p_contract_id
12561 );
12562 okl_debug_pub.log_debug
12563 (g_level_statement,
12564 l_module_name,
12565 'In param, p_term_rec.p_contract_number: '
12566 || p_term_rec.p_contract_number
12567 );
12568 okl_debug_pub.log_debug
12569 (g_level_statement,
12570 l_module_name,
12571 'In param, p_term_rec.p_termination_date: '
12572 || p_term_rec.p_termination_date
12573 );
12574 END IF;
12575
12576 -- rmunjulu +++++++++ Effective Dated Termination -- start ++++++++++++++++
12577
12578 -- rmunjulu EDAT
12579 -- If quote exists then accnting date is quote accept date else sysdate
12580 IF NVL (okl_am_lease_loan_trmnt_pvt.g_quote_exists, 'N') = 'Y'
12581 THEN
12582 l_quote_accpt_date :=
12583 okl_am_lease_loan_trmnt_pvt.g_quote_accept_date;
12584 l_quote_eff_date :=
12585 okl_am_lease_loan_trmnt_pvt.g_quote_eff_from_date;
12586 ELSE
12587 l_quote_accpt_date := p_sys_date;
12588 l_quote_eff_date := p_sys_date;
12589 END IF;
12590
12591 -- rmunjulu +++++++++ Effective Dated Termination -- end ++++++++++++++++
12592
12593 -- RMUNJULU 18-FEB-03 2805703 terminate the active service and fee lines
12594 FOR get_k_serv_fee_lines_rec IN
12595 get_k_serv_fee_lines_csr (p_term_rec.p_contract_id)
12596 LOOP
12597 l_klev_rec.ID := get_k_serv_fee_lines_rec.ID;
12598 l_clev_rec.ID := get_k_serv_fee_lines_rec.ID;
12599 l_clev_rec.date_terminated := l_quote_eff_date; -- rmunjulu EDAT
12600 l_clev_rec.sts_code := p_status;
12601 l_clev_rec.trn_code := p_trn_reason_code;
12602
12603 IF (is_debug_statement_on)
12604 THEN
12605 okl_debug_pub.log_debug
12606 (g_level_statement,
12607 l_module_name,
12608 'calling OKL_CONTRACT_PUB.update_contract_line'
12609 );
12610 END IF;
12611
12612 okl_contract_pub.update_contract_line
12613 (p_api_version => p_api_version,
12614 p_init_msg_list => g_false,
12615 x_return_status => x_return_status,
12616 x_msg_count => x_msg_count,
12617 x_msg_data => x_msg_data,
12618 p_clev_rec => l_clev_rec,
12619 p_klev_rec => l_klev_rec,
12620 x_clev_rec => lx_clev_rec,
12621 x_klev_rec => lx_klev_rec
12622 );
12623
12624 IF (is_debug_statement_on)
12625 THEN
12626 okl_debug_pub.log_debug
12627 (g_level_statement,
12628 l_module_name,
12629 'called OKL_CONTRACT_PUB.update_contract_line , return status: '
12630 || x_return_status
12631 );
12632 END IF;
12633
12634 IF l_return_status <> g_ret_sts_success
12635 THEN
12636 -- Contract line table update failed.
12637 okl_api.set_message (p_app_name => g_app_name,
12638 p_msg_name => 'OKL_AM_ERR_K_LINE_UPD');
12639 END IF;
12640
12641 -- Raise exception to rollback to savepoint
12642 IF (l_return_status = g_ret_sts_unexp_error)
12643 THEN
12644 RAISE okl_api.g_exception_unexpected_error;
12645 ELSIF (l_return_status = g_ret_sts_error)
12646 THEN
12647 RAISE okl_api.g_exception_error;
12648 END IF;
12649 END LOOP;
12650
12651 -- Get the contract details
12652 OPEN get_k_dtls_csr (p_term_rec.p_contract_id);
12653
12654 FETCH get_k_dtls_csr
12655 INTO get_k_dtls_rec;
12656
12657 CLOSE get_k_dtls_csr;
12658
12659 -- Get the ste_code
12660 OPEN get_old_ste_code_csr (get_k_dtls_rec.sts_code);
12661
12662 FETCH get_old_ste_code_csr
12663 INTO l_ste_code;
12664
12665 CLOSE get_old_ste_code_csr;
12666
12667 -- Get the sts meaning
12668 OPEN get_sts_meaning_csr (p_status);
12669
12670 FETCH get_sts_meaning_csr
12671 INTO l_sts_meaning;
12672
12673 CLOSE get_sts_meaning_csr;
12674
12675 -- set the lp_chrv_rec record
12676 IF (p_term_rec.p_termination_date IS NOT NULL)
12677 AND (p_term_rec.p_termination_date <> okl_api.g_miss_date)
12678 THEN
12679 lp_chrv_rec.date_terminated := p_term_rec.p_termination_date;
12680 ELSE
12681 lp_chrv_rec.date_terminated := l_quote_eff_date; -- rmunjulu EDAT
12682 END IF;
12683
12684 lp_chrv_rec.ID := p_term_rec.p_contract_id;
12685 lp_chrv_rec.object_version_number :=
12686 get_k_dtls_rec.object_version_number;
12687 lp_chrv_rec.sts_code := p_status;
12688 lp_chrv_rec.old_sts_code := get_k_dtls_rec.sts_code;
12689 lp_chrv_rec.new_sts_code := p_status;
12690 lp_chrv_rec.old_ste_code := l_ste_code;
12691 lp_chrv_rec.new_ste_code := p_status;
12692 lp_chrv_rec.trn_code := p_trn_reason_code;
12693 lp_chrv_rec.org_id := l_authoring_org_id; --CDUBEY added for MOAC
12694
12695 -- Call the okl api to update contract with termination info
12696 IF (is_debug_statement_on)
12697 THEN
12698 okl_debug_pub.log_debug
12699 (g_level_statement,
12700 l_module_name,
12701 'calling OKC_CONTRACT_PUB.update_contract_header'
12702 );
12703 END IF;
12704
12705 okc_contract_pub.update_contract_header
12706 (p_api_version => p_api_version,
12707 p_init_msg_list => g_false,
12708 x_return_status => l_return_status,
12709 x_msg_count => x_msg_count,
12710 x_msg_data => x_msg_data,
12711 p_restricted_update => g_true,
12712 p_chrv_rec => lp_chrv_rec,
12713 x_chrv_rec => lx_chrv_rec
12714 );
12715
12716 IF (is_debug_statement_on)
12717 THEN
12718 okl_debug_pub.log_debug
12719 (g_level_statement,
12720 l_module_name,
12721 'called OKC_CONTRACT_PUB.update_contract_header , return status: '
12722 || l_return_status
12723 );
12724 END IF;
12725
12726 IF l_return_status <> g_ret_sts_success
12727 THEN
12728 -- Error updating contract CONTRACT_NUMBER to status STATUS.
12729 okl_api.set_message (p_app_name => g_app_name,
12730 p_msg_name => 'OKL_AM_K_STATUS_UPD_ERR',
12731 p_token1 => 'CONTRACT_NUMBER',
12732 p_token1_value => p_term_rec.p_contract_number,
12733 p_token2 => 'STATUS',
12734 p_token2_value => l_sts_meaning
12735 );
12736 ELSE
12737 l_count := l_msg_tbl.COUNT;
12738 -- Set the success message in the message table
12739 l_msg_tbl (l_count).msg_desc := g_am_k_status_upd;
12740 l_msg_tbl (l_count).msg_token1 := 'CONTRACT_NUMBER';
12741 l_msg_tbl (l_count).msg_token1_value := p_term_rec.p_contract_number;
12742 l_msg_tbl (l_count).msg_token2 := 'STATUS';
12743 l_msg_tbl (l_count).msg_token2_value := l_sts_meaning;
12744 END IF;
12745
12746 -- Raise exception to rollback to savepoint
12747 IF (l_return_status = g_ret_sts_unexp_error)
12748 THEN
12749 RAISE okl_api.g_exception_unexpected_error;
12750 ELSIF (l_return_status = g_ret_sts_error)
12751 THEN
12752 RAISE okl_api.g_exception_error;
12753 END IF;
12754
12755 -- Set the return status and message table
12756 x_return_status := l_return_status;
12757 px_msg_tbl := l_msg_tbl;
12758
12759 IF (is_debug_procedure_on)
12760 THEN
12761 okl_debug_pub.log_debug (g_level_procedure,
12762 l_module_name,
12763 'End(-)'
12764 );
12765 END IF;
12766 EXCEPTION
12767 WHEN okl_api.g_exception_error
12768 THEN
12769 -- RMUNJULU 03-MAR-03 2830997 Changed NOTFOUND to ISOPEN
12770 IF get_k_dtls_csr%ISOPEN
12771 THEN
12772 CLOSE get_k_dtls_csr;
12773 END IF;
12774
12775 -- RMUNJULU 03-MAR-03 2830997 Changed NOTFOUND to ISOPEN
12776 IF get_old_ste_code_csr%ISOPEN
12777 THEN
12778 CLOSE get_old_ste_code_csr;
12779 END IF;
12780
12781 -- RMUNJULU 03-MAR-03 2830997 Changed NOTFOUND to ISOPEN
12782 IF get_sts_meaning_csr%ISOPEN
12783 THEN
12784 CLOSE get_sts_meaning_csr;
12785 END IF;
12786
12787 ROLLBACK TO update_contract;
12788 x_return_status := g_ret_sts_error;
12789
12790 IF (is_debug_exception_on)
12791 THEN
12792 okl_debug_pub.log_debug (g_level_exception,
12793 l_module_name,
12794 'EXCEPTION :' || 'G_EXCEPTION_ERROR'
12795 );
12796 END IF;
12797 WHEN okl_api.g_exception_unexpected_error
12798 THEN
12799 -- RMUNJULU 03-MAR-03 2830997 Changed NOTFOUND to ISOPEN
12800 IF get_k_dtls_csr%ISOPEN
12801 THEN
12802 CLOSE get_k_dtls_csr;
12803 END IF;
12804
12805 -- RMUNJULU 03-MAR-03 2830997 Changed NOTFOUND to ISOPEN
12806 IF get_old_ste_code_csr%ISOPEN
12807 THEN
12808 CLOSE get_old_ste_code_csr;
12809 END IF;
12810
12811 -- RMUNJULU 03-MAR-03 2830997 Changed NOTFOUND to ISOPEN
12812 IF get_sts_meaning_csr%ISOPEN
12813 THEN
12814 CLOSE get_sts_meaning_csr;
12815 END IF;
12816
12817 ROLLBACK TO update_contract;
12818 x_return_status := g_ret_sts_unexp_error;
12819
12820 IF (is_debug_exception_on)
12821 THEN
12822 okl_debug_pub.log_debug (g_level_exception,
12823 l_module_name,
12824 'EXCEPTION :'
12825 || 'G_EXCEPTION_UNEXPECTED_ERROR'
12826 );
12827 END IF;
12828 WHEN OTHERS
12829 THEN
12830 -- RMUNJULU 03-MAR-03 2830997 Changed NOTFOUND to ISOPEN
12831 IF get_k_dtls_csr%ISOPEN
12832 THEN
12833 CLOSE get_k_dtls_csr;
12834 END IF;
12835
12836 -- RMUNJULU 03-MAR-03 2830997 Changed NOTFOUND to ISOPEN
12837 IF get_old_ste_code_csr%ISOPEN
12838 THEN
12839 CLOSE get_old_ste_code_csr;
12840 END IF;
12841
12842 -- RMUNJULU 03-MAR-03 2830997 Changed NOTFOUND to ISOPEN
12843 IF get_sts_meaning_csr%ISOPEN
12844 THEN
12845 CLOSE get_sts_meaning_csr;
12846 END IF;
12847
12848 ROLLBACK TO update_contract;
12849 x_return_status := g_ret_sts_unexp_error;
12850 -- Set the oracle error message
12851 okl_api.set_message (p_app_name => g_app_name_1,
12852 p_msg_name => g_unexpected_error,
12853 p_token1 => g_sqlcode_token,
12854 p_token1_value => SQLCODE,
12855 p_token2 => g_sqlerrm_token,
12856 p_token2_value => SQLERRM
12857 );
12858
12859 IF (is_debug_exception_on)
12860 THEN
12861 okl_debug_pub.log_debug (g_level_exception,
12862 l_module_name,
12863 'EXCEPTION :'
12864 || 'OTHERS, SQLCODE: '
12865 || SQLCODE
12866 || ' , SQLERRM : '
12867 || SQLERRM
12868 );
12869 END IF;
12870 END update_contract;
12871
12872 -- Start of comments
12873 --
12874 -- Procedure Name : terminate_lines
12875 -- Desciption : Terminate the lines
12876 -- Business Rules :
12877 -- Parameters :
12878 -- Version : 1.0
12879 -- History : RMUNJULU 04-DEC-02 Bug # 2484327
12880 -- Added call to update_contract and code to set messages on
12881 -- message stack from message table
12882 -- Changed logic to do mass_rebook only when BOOKED or
12883 -- EVERGREEN lines found
12884 -- : RMUNJULU 16-DEC-02 Bug # 2484327, changed cursor to get lines
12885 -- which are of the same status as header
12886 -- : RMUNJULU 20-DEC-02 2484327 Added call to cancel_insu procedure
12887 -- when no more lines and moved cancel_activate_insu when
12888 -- some lines exist
12889 -- : RMUNJULU 03-JAN-03 2683876 Added call to close_balances
12890 -- when no more lines
12891 -- : RMUNJULU 20-DEC-02 2683876 Set the trn if cancel insurance
12892 -- and close balances successful
12893 -- : RMUNJULU 09-JAN-03 2743604 Added call to reverse loss provisions
12894 -- : RMUNJULU 18-FEB-03 2805703 Changed cursor to get asset lines
12895 -- : RMUNJULU 14-MAR-03 2852933 Removed call to cancel activate since is
12896 -- now done in Mass Rebook
12897 -- : RMUNJULU 28-MAR-03 2877278 Added code to call close_streams here
12898 -- and changed call to update lines
12899 -- : RMUNJULU CONTRACT BLOCKING : CHANGED CODE FOR DOING MASS_REBOOK
12900 -- MULTIPLE TIMES WHEN IT FAILS
12901 -- : RMUNJULU CONTRACT BLOCKING (2) Changed to update termination trn
12902 -- before mass rebook and update trn after mass rebook properly
12903 -- : RMUNJULU 3485854 12-MAR-04 Added code to update trn to PROCESSED if Mass rebook
12904 -- was not needed, which will be in case of EVERGREEN partial termination
12905 -- : RMUNJULU 3816891 FORWARDPORT Removed close_streams from central processing
12906 -- as rebook does historization
12907 -- : rmunjulu EDAT called mass_rebook with p_sys_date
12908 -- End of comments
12909 PROCEDURE terminate_lines (
12910 p_api_version IN NUMBER,
12911 p_init_msg_list IN VARCHAR2,
12912 x_msg_count OUT NOCOPY NUMBER,
12913 x_msg_data OUT NOCOPY VARCHAR2,
12914 x_return_status OUT NOCOPY VARCHAR2,
12915 px_overall_status IN OUT NOCOPY VARCHAR2,
12916 p_trn_already_set IN VARCHAR2,
12917 -- RMUNJULU CONTRACT BLOCKING
12918 p_term_rec IN term_rec_type,
12919 p_sys_date IN DATE,
12920 p_klev_tbl IN klev_tbl_type,
12921 p_status IN VARCHAR2,
12922 px_tcnv_rec IN OUT NOCOPY tcnv_rec_type
12923 )
12924 IS
12925 -- RMUNJULU Bug # 2484327, added this cursor
12926 -- RMUNJULU 16-DEC-02 Bug # 2484327, get lines which are of the same status as header
12927 -- RMUNJULU 18-FEB-03 2805703 Added code to get only financial asset lines
12928 CURSOR get_k_lines_csr (
12929 p_khr_id IN NUMBER
12930 )
12931 IS
12932 SELECT kle.ID ID
12933 FROM okc_k_lines_v kle,
12934 okc_k_headers_v khr,
12935 okc_line_styles_v lse
12936 WHERE kle.dnz_chr_id = p_khr_id
12937 AND kle.dnz_chr_id = khr.ID
12938 AND kle.sts_code = khr.sts_code
12939 AND kle.lse_id = lse.ID
12940 AND lse.lty_code = g_fin_line_lty_code;
12941
12942 -- RMUNJULU 3485854 12-MAR-04
12943 -- get the trn status
12944 CURSOR get_trn_status_csr (
12945 p_tcn_id IN NUMBER
12946 )
12947 IS
12948 SELECT tcn.tmt_status_code -- akrangan sla tmt_status_code changes
12949 FROM okl_trx_contracts tcn
12950 WHERE tcn.ID = p_tcn_id;
12951
12952 l_return_status VARCHAR2 (1) := g_ret_sts_success;
12953 l_module_name VARCHAR2 (500)
12954 := g_module_name || 'terminate_lines';
12955 is_debug_exception_on BOOLEAN
12956 := okl_debug_pub.check_log_on (l_module_name, g_level_exception);
12957 is_debug_procedure_on BOOLEAN
12958 := okl_debug_pub.check_log_on (l_module_name, g_level_procedure);
12959 is_debug_statement_on BOOLEAN
12960 := okl_debug_pub.check_log_on (l_module_name, g_level_statement);
12961 -- RMUNJULU Bug # 2484327 Added these variables
12962 l_msg_tbl g_msg_tbl;
12963 k NUMBER;
12964 l_id NUMBER := -9999;
12965 lx_klev_tbl klev_tbl_type;
12966 -- RMUNJULU CONTRACT BLOCKING ADDED VARIABLE
12967 lx_mass_rebook_success VARCHAR2 (3) := g_ret_sts_success;
12968 -- CONTRACT BLOCKING (2)
12969 lx_id NUMBER;
12970 BEGIN
12971 -- LOGIC START
12972 -- Update Lines
12973 -- Close Streams
12974 -- If any more active lines then
12975 -- Mass Rebook
12976 -- Cancel Activate Insurance
12977 -- Else -- no more active lines
12978 -- Close Balances
12979 -- Update Contract
12980 -- reverse loss provisions
12981 -- Cancel Insurances
12982 -- End if
12983 -- Set Success msgs to msg stack
12984 -- LOGIC END
12985
12986 -- Create a savepoint
12987 SAVEPOINT terminate_lines;
12988
12989 IF (is_debug_procedure_on)
12990 THEN
12991 okl_debug_pub.log_debug (g_level_procedure,
12992 l_module_name,
12993 'Begin(+)'
12994 );
12995 END IF;
12996
12997 IF (is_debug_statement_on)
12998 THEN
12999 okl_debug_pub.log_debug (g_level_statement,
13000 l_module_name,
13001 'In param, p_sys_date: ' || p_sys_date
13002 );
13003 okl_debug_pub.log_debug (g_level_statement,
13004 l_module_name,
13005 'In param, p_status: ' || p_status
13006 );
13007 okl_debug_pub.log_debug (g_level_statement,
13008 l_module_name,
13009 'In param, p_trn_already_set: '
13010 || p_trn_already_set
13011 );
13012 okl_debug_pub.log_debug (g_level_statement,
13013 l_module_name,
13014 'In param, px_overall_status: '
13015 || px_overall_status
13016 );
13017 okl_debug_pub.log_debug (g_level_statement,
13018 l_module_name,
13019 'In param, p_term_rec.p_contract_id: '
13020 || p_term_rec.p_contract_id
13021 );
13022 okl_debug_pub.log_debug
13023 (g_level_statement,
13024 l_module_name,
13025 'In param, px_tcnv_rec.tmt_generic_flag2_yn: '
13026 || px_tcnv_rec.tmt_generic_flag2_yn
13027 );
13028 okl_debug_pub.log_debug (g_level_statement,
13029 l_module_name,
13030 'In param, px_tcnv_rec.trn_code: '
13031 || px_tcnv_rec.trn_code
13032 );
13033 okl_debug_pub.log_debug (g_level_statement,
13034 l_module_name,
13035 'In param, px_tcnv_rec.id: '
13036 || px_tcnv_rec.ID
13037 );
13038
13039 IF p_klev_tbl.COUNT > 0
13040 THEN
13041 FOR i IN p_klev_tbl.FIRST .. p_klev_tbl.LAST
13042 LOOP
13043 IF (p_klev_tbl.EXISTS (i))
13044 THEN
13045 okl_debug_pub.log_debug (g_level_statement,
13046 l_module_name,
13047 'In param, p_klev_tbl('
13048 || i
13049 || ').p_kle_id: '
13050 || p_klev_tbl (i).p_kle_id
13051 );
13052 okl_debug_pub.log_debug (g_level_statement,
13053 l_module_name,
13054 'In param, p_klev_tbl('
13055 || i
13056 || ').p_asset_quantity: '
13057 || p_klev_tbl (i).p_asset_quantity
13058 );
13059 okl_debug_pub.log_debug (g_level_statement,
13060 l_module_name,
13061 'In param, p_klev_tbl('
13062 || i
13063 || ').p_asset_name: '
13064 || p_klev_tbl (i).p_asset_name
13065 );
13066 okl_debug_pub.log_debug (g_level_statement,
13067 l_module_name,
13068 'In param, p_klev_tbl('
13069 || i
13070 || ').p_quote_quantity: '
13071 || p_klev_tbl (i).p_quote_quantity
13072 );
13073 okl_debug_pub.log_debug (g_level_statement,
13074 l_module_name,
13075 'In param, p_klev_tbl('
13076 || i
13077 || ').p_tql_id: '
13078 || p_klev_tbl (i).p_tql_id
13079 );
13080 okl_debug_pub.log_debug (g_level_statement,
13081 l_module_name,
13082 'In param, p_klev_tbl('
13083 || i
13084 || ').p_split_kle_name: '
13085 || p_klev_tbl (i).p_split_kle_name
13086 );
13087 okl_debug_pub.log_debug (g_level_statement,
13088 l_module_name,
13089 'In param, p_klev_tbl('
13090 || i
13091 || ').p_split_kle_id: '
13092 || p_klev_tbl (i).p_split_kle_id
13093 );
13094 END IF;
13095 END LOOP;
13096 END IF;
13097 END IF;
13098
13099 -- RMUNJULU CONTRACT BLOCKING
13100 -- Added code to check that generic_flag2 which is now used to check
13101 -- if update_lines and close_streams was done earlier or not is checked
13102 -- since we now can recycle if only mass_rebook fails and in that condition
13103 -- we do mass_rebook only
13104
13105 -- Check if Update_Lines and Close Streams required
13106 IF ( p_trn_already_set = g_yes
13107 AND NVL (px_tcnv_rec.tmt_generic_flag2_yn, '?') <> g_yes
13108 )
13109 OR (p_trn_already_set = g_no)
13110 THEN
13111 -- Call the Update Lines to update the lines to terminated
13112 -- BAKUCHIB 28-MAR-03 2877278 Added parameter to call
13113 update_lines
13114 (p_api_version => p_api_version,
13115 p_init_msg_list => g_false,
13116 x_msg_count => x_msg_count,
13117 x_msg_data => x_msg_data,
13118 x_return_status => l_return_status,
13119 p_term_rec => p_term_rec,
13120 p_sys_date => p_sys_date,
13121 p_klev_tbl => p_klev_tbl,
13122 p_status => p_status,
13123 p_trn_reason_code => px_tcnv_rec.trn_code,
13124 x_klev_tbl => lx_klev_tbl,
13125 -- BAKUCHIB 28-MAR-03 2877278 Added
13126 x_msg_tbl => l_msg_tbl
13127 );
13128
13129 IF (is_debug_statement_on)
13130 THEN
13131 okl_debug_pub.log_debug
13132 (g_level_statement,
13133 l_module_name,
13134 'called update_lines , return status: '
13135 || l_return_status
13136 );
13137 END IF;
13138
13139 -- RMUNJULU CONTRACT BLOCKING -- Moved this if from exception
13140 IF l_return_status <> g_ret_sts_success
13141 THEN
13142 -- Contract line table update failed.
13143 okl_api.set_message (p_app_name => g_app_name,
13144 p_msg_name => 'OKL_AM_ERR_K_LINE_UPD');
13145 END IF;
13146
13147 -- rollback if update lines failed
13148 IF (l_return_status = g_ret_sts_unexp_error)
13149 THEN
13150 RAISE okl_api.g_exception_unexpected_error;
13151 ELSIF (l_return_status = g_ret_sts_error)
13152 THEN
13153 RAISE okl_api.g_exception_error;
13154 END IF;
13155
13156 -- BAKUCHIB 28-MAR-03 2877278 Added call to close streams here
13157 -- close streams
13158
13159 /* -- RMUNJULU 3816891 FORWARDPORT Do not historize streams as rebook will do it
13160
13161 close_streams(
13162 p_term_rec => p_term_rec,
13163 p_sys_date => p_sys_date,
13164 p_klev_tbl => lx_klev_tbl,
13165 p_trn_already_set => G_NO,
13166 px_overall_status => px_overall_status,
13167 px_tcnv_rec => px_tcnv_rec,
13168 x_return_status => l_return_status);
13169
13170 -- RMUNJULU CONTRACT BLOCKING -- Moved this if from exception
13171 IF l_return_status <> G_RET_STS_SUCCESS THEN
13172
13173 -- Contract line table update failed.
13174 OKL_API.set_message(
13175 p_app_name => G_APP_NAME,
13176 p_msg_name => 'OKL_AM_ERR_K_LINE_UPD');
13177
13178 END IF;
13179
13180 -- rollback if close streams failed
13181 IF (l_return_status = G_RET_STS_UNEXP_ERROR) THEN
13182 RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
13183 ELSIF (l_return_status = G_RET_STS_ERROR) THEN
13184 RAISE OKL_API.G_EXCEPTION_ERROR;
13185 END IF;
13186 */
13187
13188 -- RMUNJULU CONTRACT BLOCKING
13189 -- set the transaction record for new flag being maintained
13190 set_transaction_rec (p_return_status => l_return_status,
13191 p_overall_status => px_overall_status,
13192 p_tmt_flag => 'TMT_GENERIC_FLAG2_YN',
13193 p_tsu_code => 'WORKING',
13194 px_tcnv_rec => px_tcnv_rec
13195 );
13196 END IF; -- RMUNJULU CONTRACT BLOCKING - END OF IF
13197
13198 -- RMUNJULU Bug # 2484327
13199 -- Get any assets which are in BOOKED or EVERGREEN status
13200 OPEN get_k_lines_csr (p_term_rec.p_contract_id);
13201
13202 FETCH get_k_lines_csr
13203 INTO l_id;
13204
13205 -- RMUNJULU 18-FEB-03 2805703 Added If to set l_id
13206 IF get_k_lines_csr%NOTFOUND
13207 THEN
13208 l_id := -9999;
13209 END IF;
13210
13211 CLOSE get_k_lines_csr;
13212
13213 -- RMUNJULU Bug # 2484327 -- Added this IF
13214 -- If any BOOKED or EVERGREEN lines then do mass_rebook
13215 -- else do update_contract
13216 -- RMUNJULU 18-FEB-03 2805703 Changed IF condition for better check
13217 IF l_id <> -9999
13218 THEN
13219 --+++++++++++++++start -- CONTRACT BLOCKING (2)
13220 -- Update the transaction before mass rebook, since will be updated again by mass rebook
13221 -- update the transaction record
13222 process_transaction (p_id => 0,
13223 p_term_rec => p_term_rec,
13224 p_tcnv_rec => px_tcnv_rec,
13225 p_trn_mode => 'UPDATE',
13226 x_id => lx_id,
13227 x_return_status => l_return_status
13228 );
13229
13230 IF (is_debug_statement_on)
13231 THEN
13232 okl_debug_pub.log_debug
13233 (g_level_statement,
13234 l_module_name,
13235 'called process_transaction , return status: '
13236 || l_return_status
13237 );
13238 END IF;
13239
13240 -- rollback if processing transaction failed
13241 IF (l_return_status = g_ret_sts_unexp_error)
13242 THEN
13243 RAISE okl_api.g_exception_unexpected_error;
13244 ELSIF (l_return_status = g_ret_sts_error)
13245 THEN
13246 RAISE okl_api.g_exception_error;
13247 END IF;
13248
13249 --+++++++++++++++end -- CONTRACT BLOCKING (2)
13250
13251 -- Call the Mass Rebook to rebook the contract lines
13252 mass_rebook (p_api_version => p_api_version,
13253 p_init_msg_list => g_false,
13254 x_msg_count => x_msg_count,
13255 x_msg_data => x_msg_data,
13256 x_return_status => l_return_status,
13257 p_term_rec => p_term_rec,
13258 p_tcnv_rec => px_tcnv_rec,
13259 p_sys_date => p_sys_date, -- rmunjulu EDAT
13260 x_mrbk_success => lx_mass_rebook_success
13261 ); -- RMUNJULU CONTRACT BLOCKING ADDED
13262
13263 IF (is_debug_statement_on)
13264 THEN
13265 okl_debug_pub.log_debug
13266 (g_level_statement,
13267 l_module_name,
13268 'called mass_rebook , return status: '
13269 || l_return_status
13270 );
13271 END IF;
13272 ELSE
13273 -- No more active lines
13274
13275 -- RMUNJULU 03-JAN-03 2683876 Added call to this procedure
13276 -- Call the Close Balances to close the remaining balances
13277 close_balances (p_api_version => p_api_version,
13278 p_init_msg_list => g_false,
13279 x_msg_count => x_msg_count,
13280 x_msg_data => x_msg_data,
13281 x_return_status => l_return_status,
13282 p_term_rec => p_term_rec,
13283 p_sys_date => p_sys_date,
13284 p_tcnv_rec => px_tcnv_rec,
13285 px_msg_tbl => l_msg_tbl
13286 );
13287
13288 IF (is_debug_statement_on)
13289 THEN
13290 okl_debug_pub.log_debug
13291 (g_level_statement,
13292 l_module_name,
13293 'called close_balances , return status: '
13294 || l_return_status
13295 );
13296 END IF;
13297
13298 -- RMUNJULU CONTRACT BLOCKING -- Moved this if from exception
13299 IF l_return_status <> g_ret_sts_success
13300 THEN
13301 -- Contract line table update failed.
13302 okl_api.set_message (p_app_name => g_app_name,
13303 p_msg_name => 'OKL_AM_ERR_K_LINE_UPD');
13304 END IF;
13305
13306 -- rollback if close balances failed
13307 IF (l_return_status = g_ret_sts_unexp_error)
13308 THEN
13309 RAISE okl_api.g_exception_unexpected_error;
13310 ELSIF (l_return_status = g_ret_sts_error)
13311 THEN
13312 RAISE okl_api.g_exception_error;
13313 END IF;
13314
13315 -- RMUNJULU 09-JAN-03 2743604 Added call to this procedure
13316 -- Call to Reverse the non-incomes and loss-provisions
13317 reverse_loss_provisions (p_api_version => p_api_version,
13318 p_init_msg_list => g_false,
13319 x_msg_count => x_msg_count,
13320 x_msg_data => x_msg_data,
13321 x_return_status => l_return_status,
13322 p_term_rec => p_term_rec,
13323 p_sys_date => p_sys_date,
13324 px_msg_tbl => l_msg_tbl
13325 );
13326
13327 IF (is_debug_statement_on)
13328 THEN
13329 okl_debug_pub.log_debug
13330 (g_level_statement,
13331 l_module_name,
13332 'called reverse_loss_provisions , return status: '
13333 || l_return_status
13334 );
13335 END IF;
13336
13337 -- RMUNJULU CONTRACT BLOCKING -- Moved this if from exception
13338 IF l_return_status <> g_ret_sts_success
13339 THEN
13340 -- Contract line table update failed.
13341 okl_api.set_message (p_app_name => g_app_name,
13342 p_msg_name => 'OKL_AM_ERR_K_LINE_UPD');
13343 END IF;
13344
13345 -- rollback if reverse loss provisions failed
13346 IF (l_return_status = g_ret_sts_unexp_error)
13347 THEN
13348 RAISE okl_api.g_exception_unexpected_error;
13349 ELSIF (l_return_status = g_ret_sts_error)
13350 THEN
13351 RAISE okl_api.g_exception_error;
13352 END IF;
13353
13354 -- RMUNJULU Bug # 2484327 Added call to this procedure
13355 -- Call the Update Lines to update the contract to terminated if
13356 -- all lines of the contract are terminated
13357 update_contract (p_api_version => p_api_version,
13358 p_init_msg_list => g_false,
13359 x_msg_count => x_msg_count,
13360 x_msg_data => x_msg_data,
13361 x_return_status => l_return_status,
13362 p_term_rec => p_term_rec,
13363 p_sys_date => p_sys_date,
13364 p_status => p_status,
13365 p_trn_reason_code => px_tcnv_rec.trn_code,
13366 px_msg_tbl => l_msg_tbl
13367 );
13368
13369 IF (is_debug_statement_on)
13370 THEN
13371 okl_debug_pub.log_debug
13372 (g_level_statement,
13373 l_module_name,
13374 'called update_contract , return status: '
13375 || l_return_status
13376 );
13377 END IF;
13378
13379 -- RMUNJULU CONTRACT BLOCKING -- Moved this if from exception
13380 IF l_return_status <> g_ret_sts_success
13381 THEN
13382 -- Contract line table update failed.
13383 okl_api.set_message (p_app_name => g_app_name,
13384 p_msg_name => 'OKL_AM_ERR_K_LINE_UPD');
13385 END IF;
13386
13387 -- rollback if update contract failed
13388 IF (l_return_status = g_ret_sts_unexp_error)
13389 THEN
13390 RAISE okl_api.g_exception_unexpected_error;
13391 ELSIF (l_return_status = g_ret_sts_error)
13392 THEN
13393 RAISE okl_api.g_exception_error;
13394 END IF;
13395
13396 -- RMUNJULU 20-DEC-02 2484327 Added call to this procedure
13397 -- Call to Cancel Insurance to cancel the insurances
13398 cancel_insurance (p_api_version => p_api_version,
13399 p_init_msg_list => g_false,
13400 x_msg_count => x_msg_count,
13401 x_msg_data => x_msg_data,
13402 x_return_status => l_return_status,
13403 p_term_rec => p_term_rec,
13404 p_sys_date => p_sys_date,
13405 p_klev_tbl => p_klev_tbl
13406 );
13407
13408 IF (is_debug_statement_on)
13409 THEN
13410 okl_debug_pub.log_debug
13411 (g_level_statement,
13412 l_module_name,
13413 'called cancel_insurance , return status: '
13414 || l_return_status
13415 );
13416 END IF;
13417
13418 -- RMUNJULU CONTRACT BLOCKING -- Moved this if from exception
13419 IF l_return_status <> g_ret_sts_success
13420 THEN
13421 -- Contract line table update failed.
13422 okl_api.set_message (p_app_name => g_app_name,
13423 p_msg_name => 'OKL_AM_ERR_K_LINE_UPD');
13424 END IF;
13425
13426 -- rollback if cancel insurance failed
13427 IF (l_return_status = g_ret_sts_unexp_error)
13428 THEN
13429 RAISE okl_api.g_exception_unexpected_error;
13430 ELSIF (l_return_status = g_ret_sts_error)
13431 THEN
13432 RAISE okl_api.g_exception_error;
13433 END IF;
13434
13435 -- RMUNJULU 20-DEC-02 2683876 Set the trn if close balances successful
13436 -- set the transaction record
13437 set_transaction_rec (p_return_status => l_return_status,
13438 p_overall_status => px_overall_status,
13439 p_tmt_flag => 'TMT_CLOSE_BALANCES_YN',
13440 p_tsu_code => 'WORKING',
13441 px_tcnv_rec => px_tcnv_rec
13442 );
13443 -- RMUNJULU 20-DEC-02 2683876 Set the trn if cancel insurance successful
13444 -- set the transaction record
13445 set_transaction_rec (p_return_status => l_return_status,
13446 p_overall_status => px_overall_status,
13447 p_tmt_flag => 'TMT_CANCEL_INSURANCE_YN',
13448 p_tsu_code => 'WORKING',
13449 px_tcnv_rec => px_tcnv_rec
13450 );
13451 END IF;
13452
13453 -- RMUNJULU Bug # 2484327. Added code to set the message stack
13454 -- Set all the success messages to message stack
13455 IF l_return_status = g_ret_sts_success AND l_msg_tbl.COUNT > 0
13456 THEN
13457 k := l_msg_tbl.FIRST;
13458
13459 LOOP
13460 okl_api.set_message
13461 (p_app_name => g_app_name,
13462 p_msg_name => l_msg_tbl (k).msg_desc,
13463 p_token1 => l_msg_tbl (k).msg_token1,
13464 p_token1_value => l_msg_tbl (k).msg_token1_value,
13465 p_token2 => l_msg_tbl (k).msg_token2,
13466 p_token2_value => l_msg_tbl (k).msg_token2_value
13467 );
13468 EXIT WHEN (k = l_msg_tbl.LAST);
13469 k := l_msg_tbl.NEXT (k);
13470 END LOOP;
13471 END IF;
13472
13473 -- RMUNJULU CONTRACT BLOCKING : Now since update_lines can succeed and mass_rebook can hang
13474 -- Need to set TMT_CONTRACT_UPDATED_YN to 'E' if mass_rebook hangs so that it can be
13475 -- recycled again
13476 -- Remember : lx_mass_rebook_success will be 'S' if Mass_Rebook was not called
13477 -- Also : lx_mass_rebook_success will be 'E' if Mass_Rebook RBK TRN NOT PROCESSED
13478 -- or IF Mass_Rebook failed and it in that case it would have done rollback
13479 IF l_id <> -9999
13480 THEN
13481 -- When Mass Rebook was called
13482 --++++++++start -- CONTRACT BLOCKING (2)
13483 -- If Mass Rebook failed, It did not touch termination trn, so has to update term trn
13484 IF l_return_status <> g_ret_sts_success
13485 THEN
13486 set_transaction_rec (p_return_status => l_return_status,
13487 p_overall_status => px_overall_status,
13488 p_tmt_flag => 'TMT_CONTRACT_UPDATED_YN',
13489 p_tsu_code => 'ERROR',
13490 px_tcnv_rec => px_tcnv_rec
13491 );
13492 -- update the transaction record
13493 process_transaction (p_id => 0,
13494 p_term_rec => p_term_rec,
13495 p_tcnv_rec => px_tcnv_rec,
13496 p_trn_mode => 'UPDATE',
13497 x_id => lx_id,
13498 x_return_status => l_return_status
13499 );
13500
13501 IF (is_debug_statement_on)
13502 THEN
13503 okl_debug_pub.log_debug
13504 (g_level_statement,
13505 l_module_name,
13506 'called process_transaction , return status: '
13507 || l_return_status
13508 );
13509 END IF;
13510
13511 -- rollback if processing transaction failed
13512 IF (l_return_status = g_ret_sts_unexp_error)
13513 THEN
13514 RAISE okl_api.g_exception_unexpected_error;
13515 ELSIF (l_return_status = g_ret_sts_error)
13516 THEN
13517 RAISE okl_api.g_exception_error;
13518 END IF;
13519 ELSE
13520 -- Mass Rebook Till Streams was successful
13521
13522 -- Whole mass rebook was successful, Mass Rebook will have updated the termination trn
13523 IF lx_mass_rebook_success = g_ret_sts_success
13524 THEN
13525 NULL; --Mass Rebook will have updated the termination trn
13526
13527 -- RMUNJULU 3485854 12-MAR-04
13528 -- get trn tsu_code, if not updated then we update here
13529 -- used when EVERGREEN and partial termination
13530 FOR get_trn_status_rec IN get_trn_status_csr (px_tcnv_rec.ID)
13531 LOOP
13532 IF get_trn_status_rec.tmt_status_code <> 'PROCESSED'
13533 THEN
13534 set_transaction_rec
13535 (p_return_status => l_return_status,
13536 p_overall_status => px_overall_status,
13537 p_tmt_flag => 'TMT_CONTRACT_UPDATED_YN',
13538 p_tsu_code => 'PROCESSED',
13539 px_tcnv_rec => px_tcnv_rec
13540 );
13541 -- update the transaction record
13542 process_transaction (p_id => 0,
13543 p_term_rec => p_term_rec,
13544 p_tcnv_rec => px_tcnv_rec,
13545 p_trn_mode => 'UPDATE',
13546 x_id => lx_id,
13547 x_return_status => l_return_status
13548 );
13549
13550 IF (is_debug_statement_on)
13551 THEN
13552 okl_debug_pub.log_debug
13553 (g_level_statement,
13554 l_module_name,
13555 'called process_transaction , return status: '
13556 || l_return_status
13557 );
13558 END IF;
13559
13560 -- rollback if processing transaction failed
13561 IF (l_return_status = g_ret_sts_unexp_error)
13562 THEN
13563 RAISE okl_api.g_exception_unexpected_error;
13564 ELSIF (l_return_status = g_ret_sts_error)
13565 THEN
13566 RAISE okl_api.g_exception_error;
13567 END IF;
13568 END IF;
13569 END LOOP;
13570 ELSE
13571 -- Mass Rebook hanged becos of stream, has not yet updated term trn, so update term trn
13572
13573 -- Might need to set only tsu_code in this case ***
13574 -- then l_tcnv_rec.id and l_tcnv_rec.tsu_code should be set
13575 px_tcnv_rec.tmt_status_code := 'WORKING';
13576 -- Since mass rebook hanged set status to WORKING
13577 -- update the transaction record
13578 process_transaction (p_id => 0,
13579 p_term_rec => p_term_rec,
13580 p_tcnv_rec => px_tcnv_rec,
13581 p_trn_mode => 'UPDATE',
13582 x_id => lx_id,
13583 x_return_status => l_return_status
13584 );
13585
13586 IF (is_debug_statement_on)
13587 THEN
13588 okl_debug_pub.log_debug
13589 (g_level_statement,
13590 l_module_name,
13591 'called process_transaction , return status: '
13592 || l_return_status
13593 );
13594 END IF;
13595
13596 -- rollback if processing transaction failed
13597 IF (l_return_status = g_ret_sts_unexp_error)
13598 THEN
13599 RAISE okl_api.g_exception_unexpected_error;
13600 ELSIF (l_return_status = g_ret_sts_error)
13601 THEN
13602 RAISE okl_api.g_exception_error;
13603 END IF;
13604 END IF;
13605 END IF;
13606 ELSE
13607 -- When Mass Rebook was not called ie NO MORE ASSETS ie NOT A TRUE PARTIAL TERMINATION
13608
13609 -- At the point it would have already rolled back if there were an error
13610 -- so can assume that contract updation went thru successfully
13611 -- set the transaction record
13612 set_transaction_rec (p_return_status => l_return_status,
13613 p_overall_status => px_overall_status,
13614 p_tmt_flag => 'TMT_CONTRACT_UPDATED_YN',
13615 p_tsu_code => 'PROCESSED',
13616 px_tcnv_rec => px_tcnv_rec
13617 );
13618 -- update the transaction record
13619 process_transaction (p_id => 0,
13620 p_term_rec => p_term_rec,
13621 p_tcnv_rec => px_tcnv_rec,
13622 p_trn_mode => 'UPDATE',
13623 x_id => lx_id,
13624 x_return_status => l_return_status
13625 );
13626
13627 IF (is_debug_statement_on)
13628 THEN
13629 okl_debug_pub.log_debug
13630 (g_level_statement,
13631 l_module_name,
13632 'called process_transaction , return status: '
13633 || l_return_status
13634 );
13635 END IF;
13636
13637 -- rollback if processing transaction failed
13638 IF (l_return_status = g_ret_sts_unexp_error)
13639 THEN
13640 RAISE okl_api.g_exception_unexpected_error;
13641 ELSIF (l_return_status = g_ret_sts_error)
13642 THEN
13643 RAISE okl_api.g_exception_error;
13644 END IF;
13645 END IF;
13646
13647 --+++++++++++++end -- CONTRACT BLOCKING (2)
13648
13649 -- Set the return status
13650 x_return_status := l_return_status;
13651 -- will be 'S' always SHOULD BE OK SINCE THIS IS NOT CONSIDERED GOING FURTHER
13652
13653 IF (is_debug_procedure_on)
13654 THEN
13655 okl_debug_pub.log_debug (g_level_procedure,
13656 l_module_name,
13657 'End(-)'
13658 );
13659 END IF;
13660 EXCEPTION
13661 WHEN okl_api.g_exception_error
13662 THEN
13663 -- RMUNJULU Bug # 2484327 Added IF
13664 IF get_k_lines_csr%ISOPEN
13665 THEN
13666 CLOSE get_k_lines_csr;
13667 END IF;
13668
13669 ROLLBACK TO terminate_lines;
13670 x_return_status := g_ret_sts_error;
13671 -- RMUNJULU CONTRACT BLOCKING -- Moved msg to body above
13672
13673 -- set the transaction record
13674 set_transaction_rec (p_return_status => x_return_status,
13675 p_overall_status => px_overall_status,
13676 p_tmt_flag => 'TMT_CONTRACT_UPDATED_YN',
13677 p_tsu_code => 'ERROR',
13678 px_tcnv_rec => px_tcnv_rec
13679 );
13680
13681 IF (is_debug_exception_on)
13682 THEN
13683 okl_debug_pub.log_debug (g_level_exception,
13684 l_module_name,
13685 'EXCEPTION :' || 'G_EXCEPTION_ERROR'
13686 );
13687 END IF;
13688 WHEN okl_api.g_exception_unexpected_error
13689 THEN
13690 -- RMUNJULU Bug # 2484327 Added IF
13691 IF get_k_lines_csr%ISOPEN
13692 THEN
13693 CLOSE get_k_lines_csr;
13694 END IF;
13695
13696 ROLLBACK TO terminate_lines;
13697 x_return_status := g_ret_sts_unexp_error;
13698 -- RMUNJULU CONTRACT BLOCKING -- Moved msg to body above
13699
13700 -- set the transaction record
13701 set_transaction_rec (p_return_status => x_return_status,
13702 p_overall_status => px_overall_status,
13703 p_tmt_flag => 'TMT_CONTRACT_UPDATED_YN',
13704 p_tsu_code => 'ERROR',
13705 px_tcnv_rec => px_tcnv_rec
13706 );
13707
13708 IF (is_debug_exception_on)
13709 THEN
13710 okl_debug_pub.log_debug (g_level_exception,
13711 l_module_name,
13712 'EXCEPTION :'
13713 || 'G_EXCEPTION_UNEXPECTED_ERROR'
13714 );
13715 END IF;
13716 WHEN OTHERS
13717 THEN
13718 -- RMUNJULU Bug # 2484327 Added IF
13719 IF get_k_lines_csr%ISOPEN
13720 THEN
13721 CLOSE get_k_lines_csr;
13722 END IF;
13723
13724 ROLLBACK TO terminate_lines;
13725 x_return_status := g_ret_sts_unexp_error;
13726 -- RMUNJULU CONTRACT BLOCKING -- Moved msg to body above
13727
13728 -- set the transaction record
13729 set_transaction_rec (p_return_status => x_return_status,
13730 p_overall_status => px_overall_status,
13731 p_tmt_flag => 'TMT_CONTRACT_UPDATED_YN',
13732 p_tsu_code => 'ERROR',
13733 px_tcnv_rec => px_tcnv_rec
13734 );
13735 -- Set the oracle error message
13736 okl_api.set_message (p_app_name => g_app_name_1,
13737 p_msg_name => g_unexpected_error,
13738 p_token1 => g_sqlcode_token,
13739 p_token1_value => SQLCODE,
13740 p_token2 => g_sqlerrm_token,
13741 p_token2_value => SQLERRM
13742 );
13743
13744 IF (is_debug_exception_on)
13745 THEN
13746 okl_debug_pub.log_debug (g_level_exception,
13747 l_module_name,
13748 'EXCEPTION :'
13749 || 'OTHERS, SQLCODE: '
13750 || SQLCODE
13751 || ' , SQLERRM : '
13752 || SQLERRM
13753 );
13754 END IF;
13755 END terminate_lines;
13756
13757 -- Start of comments
13758 --
13759 -- Procedure Name : asset_level_termination
13760 -- Desciption : Use this API to terminate lines for
13761 -- asset level termination
13762 -- Business Rules :
13763 -- Parameters :
13764 -- Version : 1.0
13765 -- History : RMUNJULU 20-DEC-02 2484327 Removed validation message
13766 -- : RMUNJULU 02-JAN-03 2724951 Added code to check lease or loan
13767 -- and processing accordingly
13768 -- : RMUNJULU 07-JAN-03 2736865 Added code to store messages
13769 -- and set stack to true
13770 -- : RMUNJULU 23-JAN-03 2762065 Added code to set msg stack
13771 -- before split asset call
13772 -- : RMUNJULU 31-JAN-03 2780539 Added TER_MAN_PURCHASE check
13773 -- : RMUNJULU 04-FEB-03 2781557 Added code to set trn to
13774 -- WORKING after validation
13775 -- : RMUNJULU 28-MAR-03 2877278 Removed call to close_streams
13776 -- as it moves to Terminate_Lines
13777 -- : RMUNJULU 3061751 Changed code to create a termination
13778 -- trn even when request is NON BATCH and validation has failed
13779 -- : RMUNJULU 3061751 Changed l_return_status to l_validate in set_trn_rec
13780 -- setting the value for tmt_validated_yn properly
13781 -- : RMUNJULU 2730783 Use OKL_AM_BTCH_EXP_LEASE_LOAN_PVT.POP_ASSET_MSG_TBL
13782 -- instead of log_messages to set messages into the POP_ASSET_MSG_TBL
13783 -- of OKL_AM_BTCH_EXP_LEASE_LOAN_PVT which will be used in the output
13784 -- displayed from concurrent program
13785 -- : RMUNJULU 3018641 Added code to get and set TMG_RUN on OKL_TRX_MSGS
13786 -- : RMUNJULU 3018641 Added code to get and set TMG_RUN on OKL_TRX_MSGS in one more place
13787 -- : RMUNJULU CONTRACT BLOCKING : CHANGED CALL TO TERMINATE_LINES
13788 -- and added condition for validate_k_and_lines
13789 -- : RMUNJULU CONTRACT BLOCKING (2) Changed to update termination trn
13790 -- If Overall status not successful or if mass_rebook was not called
13791 -- : RMUNJULU CONTRACT BLOCKING (3) -- Added NVLs to Validate condition
13792 -- : rmunjulu EDAT Added code to get quote eff dates and set them as global
13793 -- End of comments
13794 PROCEDURE asset_level_termination (
13795 p_api_version IN NUMBER,
13796 p_init_msg_list IN VARCHAR2,
13797 p_term_rec IN term_rec_type,
13798 p_tcnv_rec IN tcnv_rec_type,
13799 x_msg_count OUT NOCOPY NUMBER,
13800 x_msg_data OUT NOCOPY VARCHAR2,
13801 x_return_status OUT NOCOPY VARCHAR2
13802 )
13803 IS
13804 l_return_status VARCHAR2 (1) := g_ret_sts_success;
13805 l_overall_status VARCHAR2 (1) := g_ret_sts_success;
13806 lp_tcnv_rec tcnv_rec_type;
13807 lp_klev_tbl klev_tbl_type;
13808 lx_klev_tbl klev_tbl_type;
13809 lx_id NUMBER;
13810 i NUMBER := 1;
13811 l_tran_started VARCHAR2 (1) := g_false;
13812 l_evergreen_status VARCHAR2 (1) := g_false;
13813 l_api_name VARCHAR2 (30) := 'asset_level_termination';
13814 l_module_name VARCHAR2 (500)
13815 := g_module_name || 'asset_level_termination';
13816 is_debug_exception_on BOOLEAN
13817 := okl_debug_pub.check_log_on (l_module_name, g_level_exception);
13818 is_debug_procedure_on BOOLEAN
13819 := okl_debug_pub.check_log_on (l_module_name, g_level_procedure);
13820 is_debug_statement_on BOOLEAN
13821 := okl_debug_pub.check_log_on (l_module_name, g_level_statement);
13822 l_sys_date DATE;
13823 l_trn_already_set VARCHAR2 (1) := g_no;
13824 lx_contract_status VARCHAR2 (200);
13825 l_validate VARCHAR2 (1) := g_ret_sts_error;
13826 l_api_version CONSTANT NUMBER := 1;
13827 l_status VARCHAR2 (200);
13828 l_term_rec term_rec_type := p_term_rec;
13829 l_lease_or_loan VARCHAR2 (30);
13830 BEGIN
13831 IF (is_debug_procedure_on)
13832 THEN
13833 okl_debug_pub.log_debug (g_level_procedure,
13834 l_module_name,
13835 'Begin(+)'
13836 );
13837 END IF;
13838
13839 IF (is_debug_statement_on)
13840 THEN
13841 okl_debug_pub.log_debug (g_level_statement,
13842 l_module_name,
13843 'In param, p_term_rec.p_quote_id: '
13844 || p_term_rec.p_quote_id
13845 );
13846 okl_debug_pub.log_debug (g_level_statement,
13847 l_module_name,
13848 'In param, p_term_rec.p_contract_id: '
13849 || p_term_rec.p_contract_id
13850 );
13851 okl_debug_pub.log_debug
13852 (g_level_statement,
13853 l_module_name,
13854 'In param, p_term_rec.p_contract_number: '
13855 || p_term_rec.p_contract_number
13856 );
13857 okl_debug_pub.log_debug (g_level_statement,
13858 l_module_name,
13859 'In param, p_term_rec.p_quote_type: '
13860 || p_term_rec.p_quote_type
13861 );
13862 okl_debug_pub.log_debug
13863 (g_level_statement,
13864 l_module_name,
13865 'In param, p_term_rec.p_early_termination_yn: '
13866 || p_term_rec.p_early_termination_yn
13867 );
13868 okl_debug_pub.log_debug
13869 (g_level_statement,
13870 l_module_name,
13871 'In param, p_term_rec.p_termination_date: '
13872 || p_term_rec.p_termination_date
13873 );
13874 okl_debug_pub.log_debug
13875 (g_level_statement,
13876 l_module_name,
13877 'In param, p_tcnv_rec.tmt_generic_flag2_yn: '
13878 || p_tcnv_rec.tmt_generic_flag2_yn
13879 );
13880 okl_debug_pub.log_debug (g_level_statement,
13881 l_module_name,
13882 'In param, p_tcnv_rec.id: ' || p_tcnv_rec.ID
13883 );
13884 okl_debug_pub.log_debug
13885 (g_level_statement,
13886 l_module_name,
13887 'In param, p_tcnv_rec.tmt_contract_updated_yn: '
13888 || p_tcnv_rec.tmt_contract_updated_yn
13889 );
13890 okl_debug_pub.log_debug (g_level_statement,
13891 l_module_name,
13892 'In param, p_tcnv_rec.tmt_status_code: '
13893 || p_tcnv_rec.tmt_status_code
13894 );
13895 END IF;
13896
13897 -- RMUNJULU 23-JAN-03 2762065 -- Added comments to explain msgs manipulation
13898 -- Issue with msgs and msg stack is resolved the following way
13899 -- Split asset initializes msg stack so log + process + initialize msgs before
13900 -- split asset
13901 -- Mass rebook initializes msg stack so log + process + initialize msgs before
13902 -- terminate lines
13903 -- There was a concern of msgs being lost which are set in update lines if mass
13904 -- rebook is done after it and is sucessful, but that is not a concern since
13905 -- we are not storing the update lines msgs on stack but in msg_tbl and
13906 -- putting them on stack only if every step in terminate line is sucessful
13907
13908 -- Set the transaction
13909 l_return_status :=
13910 okl_api.start_activity (l_api_name,
13911 g_pkg_name,
13912 p_init_msg_list,
13913 l_api_version,
13914 p_api_version,
13915 '_PVT',
13916 x_return_status
13917 );
13918
13919 -- Rollback if error setting activity for api
13920 IF (l_return_status = g_ret_sts_unexp_error)
13921 THEN
13922 RAISE okl_api.g_exception_unexpected_error;
13923 ELSIF (l_return_status = g_ret_sts_error)
13924 THEN
13925 RAISE okl_api.g_exception_error;
13926 END IF;
13927
13928 -- store the highest degree of error
13929 set_overall_status (p_return_status => l_return_status,
13930 px_overall_status => l_overall_status);
13931 -- If the termination request is from quote
13932 -- populate the rest of the quote attributes
13933 set_database_values (px_term_rec => l_term_rec);
13934 -- Set the info messages intially
13935 set_info_messages (p_term_rec => l_term_rec);
13936
13937 -- check if transaction already exists
13938 IF (p_tcnv_rec.ID IS NOT NULL AND p_tcnv_rec.ID <> g_miss_num)
13939 THEN
13940 l_trn_already_set := g_yes;
13941 END IF;
13942
13943 --get sysdate
13944 SELECT SYSDATE
13945 INTO l_sys_date
13946 FROM DUAL;
13947
13948 -- If the transaction is not already set then initialize and insert
13949 IF l_trn_already_set = g_no
13950 THEN
13951 -- initialize the transaction rec
13952 initialize_transaction (p_term_rec => l_term_rec,
13953 p_sys_date => l_sys_date,
13954 p_control_flag => 'CREATE',
13955 px_tcnv_rec => lp_tcnv_rec,
13956 x_return_status => l_return_status
13957 );
13958
13959 IF (is_debug_statement_on)
13960 THEN
13961 okl_debug_pub.log_debug
13962 (g_level_statement,
13963 l_module_name,
13964 'called initialize_transaction , return status: '
13965 || l_return_status
13966 );
13967 END IF;
13968
13969 -- rollback if intialize transaction failed
13970 IF (l_return_status = g_ret_sts_unexp_error)
13971 THEN
13972 RAISE okl_api.g_exception_unexpected_error;
13973 ELSIF (l_return_status = g_ret_sts_error)
13974 THEN
13975 RAISE okl_api.g_exception_error;
13976 END IF;
13977
13978 -- insert the transaction record
13979 process_transaction (p_id => 0,
13980 p_term_rec => l_term_rec,
13981 p_tcnv_rec => lp_tcnv_rec,
13982 p_trn_mode => 'INSERT',
13983 x_id => lx_id,
13984 x_return_status => l_return_status
13985 );
13986
13987 IF (is_debug_statement_on)
13988 THEN
13989 okl_debug_pub.log_debug
13990 (g_level_statement,
13991 l_module_name,
13992 'called process_transaction , return status: '
13993 || l_return_status
13994 );
13995 END IF;
13996
13997 -- rollback if processing transaction failed
13998 IF (l_return_status = g_ret_sts_unexp_error)
13999 THEN
14000 RAISE okl_api.g_exception_unexpected_error;
14001 ELSIF (l_return_status = g_ret_sts_error)
14002 THEN
14003 RAISE okl_api.g_exception_error;
14004 END IF;
14005
14006 -- set the trn rec id
14007 lp_tcnv_rec.ID := lx_id;
14008 ELSE
14009 -- transaction already set
14010 lp_tcnv_rec := p_tcnv_rec;
14011 -- initialize the transaction rec
14012 initialize_transaction (p_term_rec => l_term_rec,
14013 p_sys_date => l_sys_date,
14014 p_control_flag => 'UPDATE',
14015 px_tcnv_rec => lp_tcnv_rec,
14016 x_return_status => l_return_status
14017 );
14018
14019 IF (is_debug_statement_on)
14020 THEN
14021 okl_debug_pub.log_debug
14022 (g_level_statement,
14023 l_module_name,
14024 'called initialize_transaction , return status: '
14025 || l_return_status
14026 );
14027 END IF;
14028
14029 -- rollback if intialize transaction failed
14030 IF (l_return_status = g_ret_sts_unexp_error)
14031 THEN
14032 RAISE okl_api.g_exception_unexpected_error;
14033 ELSIF (l_return_status = g_ret_sts_error)
14034 THEN
14035 RAISE okl_api.g_exception_error;
14036 END IF;
14037 END IF;
14038
14039 -- rmunjulu +++++++++ Effective Dated Termination -- start ++++++++++++++++
14040
14041 -- rmunjulu EDAT Get the quote effectivity date and quote acceptance date
14042 -- and store as global variables, will be used later on in other procedures
14043 IF (is_debug_statement_on)
14044 THEN
14045 okl_debug_pub.log_debug
14046 (g_level_statement,
14047 l_module_name,
14048 'calling OKL_AM_LEASE_LOAN_TRMNT_PVT.get_set_quote_dates'
14049 );
14050 END IF;
14051
14052 okl_am_lease_loan_trmnt_pvt.get_set_quote_dates
14053 (p_qte_id => l_term_rec.p_quote_id,
14054 x_return_status => l_return_status);
14055
14056 IF (is_debug_statement_on)
14057 THEN
14058 okl_debug_pub.log_debug
14059 (g_level_statement,
14060 l_module_name,
14061 'called OKL_AM_LEASE_LOAN_TRMNT_PVT.get_set_quote_dates , return status: '
14062 || l_return_status
14063 );
14064 END IF;
14065
14066 -- Rollback if error setting activity for api
14067 IF (l_return_status = okl_api.g_ret_sts_unexp_error)
14068 THEN
14069 RAISE okl_api.g_exception_unexpected_error;
14070 ELSIF (l_return_status = okl_api.g_ret_sts_error)
14071 THEN
14072 RAISE okl_api.g_exception_error;
14073 END IF;
14074
14075 -- rmunjulu +++++++++ Effective Dated Termination -- end ++++++++++++++++
14076
14077 -- get the lines
14078 get_lines (p_term_rec => l_term_rec,
14079 x_klev_tbl => lp_klev_tbl,
14080 x_return_status => l_return_status
14081 );
14082
14083 IF (is_debug_statement_on)
14084 THEN
14085 okl_debug_pub.log_debug (g_level_statement,
14086 l_module_name,
14087 'called get_lines , return status: '
14088 || l_return_status
14089 );
14090 END IF;
14091
14092 -- RMUNJULU CONTRACT BLOCKING Do not validate if update_lines done and only mass_rebook pending
14093 -- RMUNJULU CONTRACT BLOCKING (3) -- Added NVLs
14094 IF NVL (lp_tcnv_rec.tmt_contract_updated_yn, 'N') = 'N'
14095 AND NVL (lp_tcnv_rec.tmt_generic_flag2_yn, 'N') = 'Y'
14096 THEN
14097 l_return_status := g_ret_sts_success;
14098 ELSE
14099 -- Not a Mass rebook recycle, so do validate
14100
14101 -- check if lease and lines valid
14102 validate_contract_and_lines (p_term_rec => l_term_rec,
14103 p_sys_date => l_sys_date,
14104 p_klev_tbl => lp_klev_tbl,
14105 x_return_status => l_return_status
14106 );
14107
14108 IF (is_debug_statement_on)
14109 THEN
14110 okl_debug_pub.log_debug
14111 (g_level_statement,
14112 l_module_name,
14113 'called validate_contract_and_lines , return status: '
14114 || l_return_status
14115 );
14116 END IF;
14117 END IF;
14118
14119 -- Store the validation return status
14120 l_validate := l_return_status;
14121 -- store the highest degree of error
14122 set_overall_status (p_return_status => l_return_status,
14123 px_overall_status => l_overall_status);
14124
14125 IF (l_term_rec.p_control_flag = 'BATCH_PROCESS')
14126 THEN
14127 -- Since batch process is not checked initially in LLT check here
14128 IF (is_debug_statement_on)
14129 THEN
14130 okl_debug_pub.log_debug
14131 (g_level_statement,
14132 l_module_name,
14133 'calling OKL_AM_LEASE_LOAN_TRMNT_PUB.validate_contract'
14134 );
14135 END IF;
14136
14137 okl_am_lease_loan_trmnt_pub.validate_contract
14138 (p_api_version => p_api_version,
14139 p_init_msg_list => g_false,
14140 x_return_status => l_return_status,
14141 x_msg_count => x_msg_count,
14142 x_msg_data => x_msg_data,
14143 p_contract_id => l_term_rec.p_contract_id,
14144 p_control_flag => l_term_rec.p_control_flag,
14145 x_contract_status => lx_contract_status
14146 );
14147
14148 IF (is_debug_statement_on)
14149 THEN
14150 okl_debug_pub.log_debug
14151 (g_level_statement,
14152 l_module_name,
14153 'called OKL_AM_LEASE_LOAN_TRMNT_PUB.validate_contract , return status: '
14154 || l_return_status
14155 );
14156 END IF;
14157
14158 -- Store the highest validation return status
14159 -- To capture the return status of validate lease called above
14160 IF (l_validate = g_ret_sts_success)
14161 THEN
14162 l_validate := l_return_status;
14163 END IF;
14164
14165 -- store the highest degree of error
14166 set_overall_status
14167 (p_return_status => l_validate,
14168 -- RMUNJULU 3061751 Changed from l_return_status
14169 px_overall_status => l_overall_status);
14170 -- set the transaction record
14171 set_transaction_rec
14172 (p_return_status => l_validate,
14173 -- RMUNJULU 3061751 Changed from l_return_status
14174 p_overall_status => l_overall_status,
14175 p_tmt_flag => 'TMT_VALIDATED_YN',
14176 p_tsu_code => 'ENTERED',
14177 px_tcnv_rec => lp_tcnv_rec
14178 );
14179
14180 -- if validation failed then insert transaction
14181 -- AND abort else continue next process
14182 IF (l_validate <> g_ret_sts_success)
14183 THEN
14184 -- set the transaction record
14185 set_transaction_rec
14186 (p_return_status => l_validate,
14187 -- RMUNJULU 3061751 Changed from l_return_status
14188 p_overall_status => l_overall_status,
14189 p_tmt_flag => 'TMT_VALIDATED_YN',
14190 p_tsu_code => 'ERROR',
14191 px_tcnv_rec => lp_tcnv_rec
14192 );
14193 -- update the transaction record
14194 process_transaction (p_id => 0,
14195 p_term_rec => l_term_rec,
14196 p_tcnv_rec => lp_tcnv_rec,
14197 p_trn_mode => 'UPDATE',
14198 x_id => lx_id,
14199 x_return_status => l_return_status
14200 );
14201
14202 IF (is_debug_statement_on)
14203 THEN
14204 okl_debug_pub.log_debug
14205 (g_level_statement,
14206 l_module_name,
14207 'called process_transaction , return status: '
14208 || l_return_status
14209 );
14210 END IF;
14211
14212 -- rollback if processing transaction failed
14213 IF (l_return_status = g_ret_sts_unexp_error)
14214 THEN
14215 RAISE okl_api.g_exception_unexpected_error;
14216 ELSIF (l_return_status = g_ret_sts_error)
14217 THEN
14218 RAISE okl_api.g_exception_error;
14219 END IF;
14220
14221 -- Save messages from stack into transaction message table
14222 IF (is_debug_statement_on)
14223 THEN
14224 okl_debug_pub.log_debug
14225 (g_level_statement,
14226 l_module_name,
14227 'calling OKL_AM_UTIL_PVT.process_messages'
14228 );
14229 END IF;
14230
14231 okl_am_util_pvt.process_messages
14232 (p_trx_source_table => 'OKL_TRX_CONTRACTS',
14233 p_trx_id => lp_tcnv_rec.ID,
14234 x_return_status => l_return_status
14235 );
14236
14237 IF (is_debug_statement_on)
14238 THEN
14239 okl_debug_pub.log_debug
14240 (g_level_statement,
14241 l_module_name,
14242 'called OKL_AM_UTIL_PVT.process_messages , return status: '
14243 || l_return_status
14244 );
14245 END IF;
14246
14247 -- RMUNJULU 3018641 Added code to get and set TMG_RUN
14248 IF (is_debug_statement_on)
14249 THEN
14250 okl_debug_pub.log_debug
14251 (g_level_statement,
14252 l_module_name,
14253 'calling OKL_AM_LEASE_LOAN_TRMNT_PVT.get_set_tmg_run'
14254 );
14255 END IF;
14256
14257 okl_am_lease_loan_trmnt_pvt.get_set_tmg_run
14258 (p_trx_id => lp_tcnv_rec.ID,
14259 x_return_status => l_return_status);
14260
14261 IF (is_debug_statement_on)
14262 THEN
14263 okl_debug_pub.log_debug
14264 (g_level_statement,
14265 l_module_name,
14266 'called OKL_AM_LEASE_LOAN_TRMNT_PVT.get_set_tmg_run , return status: '
14267 || l_return_status
14268 );
14269 END IF;
14270
14271 -- abort since validation failed
14272 RAISE g_exception_halt_validation;
14273 END IF;
14274 ELSE
14275 --( not from batch process) then
14276
14277 -- RMUNJULU 3061751 Changed this code to create a termination trn even when
14278 -- request is NON BATCH and validation has failed
14279 IF l_validate <> g_ret_sts_success
14280 THEN
14281 -- set the transaction record
14282 set_transaction_rec
14283 (p_return_status => l_validate,
14284 -- RMUNJULU 3061751 Changed from l_return_status,
14285 p_overall_status => l_overall_status,
14286 p_tmt_flag => 'TMT_VALIDATED_YN',
14287 p_tsu_code => 'ERROR',
14288 px_tcnv_rec => lp_tcnv_rec
14289 );
14290 -- update the transaction record
14291 process_transaction (p_id => 0,
14292 p_term_rec => l_term_rec,
14293 p_tcnv_rec => lp_tcnv_rec,
14294 p_trn_mode => 'UPDATE',
14295 x_id => lx_id,
14296 x_return_status => l_return_status
14297 );
14298
14299 IF (is_debug_statement_on)
14300 THEN
14301 okl_debug_pub.log_debug
14302 (g_level_statement,
14303 l_module_name,
14304 'called process_transaction , return status: '
14305 || l_return_status
14306 );
14307 END IF;
14308
14309 -- rollback if processing transaction failed
14310 IF (l_return_status = g_ret_sts_unexp_error)
14311 THEN
14312 RAISE okl_api.g_exception_unexpected_error;
14313 ELSIF (l_return_status = g_ret_sts_error)
14314 THEN
14315 RAISE okl_api.g_exception_error;
14316 END IF;
14317
14318 -- Save messages from stack into transaction message table
14319 IF (is_debug_statement_on)
14320 THEN
14321 okl_debug_pub.log_debug
14322 (g_level_statement,
14323 l_module_name,
14324 'calling OKL_AM_UTIL_PVT.process_messages'
14325 );
14326 END IF;
14327
14328 okl_am_util_pvt.process_messages
14329 (p_trx_source_table => 'OKL_TRX_CONTRACTS',
14330 p_trx_id => lp_tcnv_rec.ID,
14331 x_return_status => l_return_status
14332 );
14333
14334 IF (is_debug_statement_on)
14335 THEN
14336 okl_debug_pub.log_debug
14337 (g_level_statement,
14338 l_module_name,
14339 'called OKL_AM_UTIL_PVT.process_messages , return status: '
14340 || l_return_status
14341 );
14342 END IF;
14343
14344 -- RMUNJULU 3018641 Added code to get and set TMG_RUN
14345 IF (is_debug_statement_on)
14346 THEN
14347 okl_debug_pub.log_debug
14348 (g_level_statement,
14349 l_module_name,
14350 'calling OKL_AM_LEASE_LOAN_TRMNT_PVT.get_set_tmg_run'
14351 );
14352 END IF;
14353
14354 okl_am_lease_loan_trmnt_pvt.get_set_tmg_run
14355 (p_trx_id => lp_tcnv_rec.ID,
14356 x_return_status => l_return_status);
14357
14358 IF (is_debug_statement_on)
14359 THEN
14360 okl_debug_pub.log_debug
14361 (g_level_statement,
14362 l_module_name,
14363 'called OKL_AM_LEASE_LOAN_TRMNT_PVT.get_set_tmg_run , return status: '
14364 || l_return_status
14365 );
14366 END IF;
14367
14368 -- abort since validation failed
14369 RAISE g_exception_halt_validation;
14370 ELSE
14371 -- Validate was successful -- RMUNJULU CONTRACT BLOCKING -- Validate flag was not set properly earlier
14372
14373 -- set the transaction record
14374 set_transaction_rec (p_return_status => l_validate,
14375 p_overall_status => l_overall_status,
14376 p_tmt_flag => 'TMT_VALIDATED_YN',
14377 p_tsu_code => 'ENTERED',
14378 px_tcnv_rec => lp_tcnv_rec
14379 );
14380 END IF;
14381 END IF;
14382
14383 -- RMUNJULU 23-JAN-03 2762065 -- START
14384 -- Added this code to store msgs in log and tbl since split asset setting the
14385 -- msg stack again
14386
14387 -- If batch process then log the messages from stack
14388 IF p_term_rec.p_control_flag LIKE 'BATCH%'
14389 THEN
14390 -- RMUNJULU 2730738 for proper output file
14391 okl_am_btch_exp_lease_loan_pvt.pop_asset_msg_tbl; --log_messages;
14392 END IF;
14393
14394 -- Store messages in TRX_MSGS
14395 IF (is_debug_statement_on)
14396 THEN
14397 okl_debug_pub.log_debug (g_level_statement,
14398 l_module_name,
14399 'calling OKL_AM_UTIL_PVT.process_messages'
14400 );
14401 END IF;
14402
14403 okl_am_util_pvt.process_messages
14404 (p_trx_source_table => 'OKL_TRX_CONTRACTS',
14405 p_trx_id => lp_tcnv_rec.ID,
14406 x_return_status => l_return_status
14407 );
14408
14409 IF (is_debug_statement_on)
14410 THEN
14411 okl_debug_pub.log_debug
14412 (g_level_statement,
14413 l_module_name,
14414 'called OKL_AM_UTIL_PVT.process_messages , return status: '
14415 || l_return_status
14416 );
14417 END IF;
14418
14419 -- Set message stack to true
14420 okl_api.init_msg_list (g_true);
14421 -- RMUNJULU 23-JAN-03 2762065 -- END
14422
14423 -- RMUNJULU 04-FEB-03 2781557 -- START
14424
14425 -- Update the transaction to WORKING before starting other steps
14426 lp_tcnv_rec.tmt_status_code := 'WORKING';
14427 --akrangan changes for sla tmt_status_code cr
14428 -- update the transaction record with tsu_code = WORKING
14429 process_transaction (p_id => 0,
14430 p_term_rec => l_term_rec,
14431 p_tcnv_rec => lp_tcnv_rec,
14432 p_trn_mode => 'UPDATE',
14433 x_id => lx_id,
14434 x_return_status => l_return_status
14435 );
14436
14437 IF (is_debug_statement_on)
14438 THEN
14439 okl_debug_pub.log_debug
14440 (g_level_statement,
14441 l_module_name,
14442 'called process_transaction , return status: '
14443 || l_return_status
14444 );
14445 END IF;
14446
14447 -- rollback if process transaction failed
14448 IF (l_return_status = g_ret_sts_unexp_error)
14449 THEN
14450 RAISE okl_api.g_exception_unexpected_error;
14451 ELSIF (l_return_status = g_ret_sts_error)
14452 THEN
14453 RAISE okl_api.g_exception_error;
14454 END IF;
14455
14456 -- RMUNJULU 04-FEB-03 2781557 -- END
14457
14458 -- do asset split
14459 split_asset (p_term_rec => l_term_rec,
14460 p_sys_date => l_sys_date,
14461 p_klev_tbl => lp_klev_tbl,
14462 p_trn_already_set => l_trn_already_set,
14463 px_overall_status => l_overall_status,
14464 px_tcnv_rec => lp_tcnv_rec,
14465 x_klev_tbl => lx_klev_tbl,
14466 x_return_status => l_return_status
14467 );
14468
14469 IF (is_debug_statement_on)
14470 THEN
14471 okl_debug_pub.log_debug (g_level_statement,
14472 l_module_name,
14473 'called split_asset , return status: '
14474 || l_return_status
14475 );
14476 END IF;
14477
14478 -- Log error and exit if split asset fails
14479 IF l_return_status <> g_ret_sts_success
14480 THEN
14481 -- update the transaction record
14482 process_transaction (p_id => 0,
14483 p_term_rec => l_term_rec,
14484 p_tcnv_rec => lp_tcnv_rec,
14485 p_trn_mode => 'UPDATE',
14486 x_id => lx_id,
14487 x_return_status => l_return_status
14488 );
14489
14490 IF (is_debug_statement_on)
14491 THEN
14492 okl_debug_pub.log_debug
14493 (g_level_statement,
14494 l_module_name,
14495 'called process_transaction , return status: '
14496 || l_return_status
14497 );
14498 END IF;
14499
14500 -- rollback if processing transaction failed
14501 IF (l_return_status = g_ret_sts_unexp_error)
14502 THEN
14503 RAISE okl_api.g_exception_unexpected_error;
14504 ELSIF (l_return_status = g_ret_sts_error)
14505 THEN
14506 RAISE okl_api.g_exception_error;
14507 END IF;
14508
14509 -- RMUNJULU 2730738 for proper output file
14510 IF p_term_rec.p_control_flag LIKE 'BATCH%'
14511 THEN
14512 okl_am_btch_exp_lease_loan_pvt.pop_asset_msg_tbl;
14513 END IF;
14514
14515 -- Save messages from stack into transaction message table
14516 IF (is_debug_statement_on)
14517 THEN
14518 okl_debug_pub.log_debug
14519 (g_level_statement,
14520 l_module_name,
14521 'calling OKL_AM_UTIL_PVT.process_messages'
14522 );
14523 END IF;
14524
14525 okl_am_util_pvt.process_messages
14526 (p_trx_source_table => 'OKL_TRX_CONTRACTS',
14527 p_trx_id => lp_tcnv_rec.ID,
14528 x_return_status => l_return_status
14529 );
14530
14531 IF (is_debug_statement_on)
14532 THEN
14533 okl_debug_pub.log_debug
14534 (g_level_statement,
14535 l_module_name,
14536 'called OKL_AM_UTIL_PVT.process_messages , return status: '
14537 || l_return_status
14538 );
14539 END IF;
14540
14541 -- RMUNJULU 3018641 Added to get and set latest run - 02-OCT-03
14542 IF (is_debug_statement_on)
14543 THEN
14544 okl_debug_pub.log_debug
14545 (g_level_statement,
14546 l_module_name,
14547 'calling OKL_AM_LEASE_LOAN_TRMNT_PVT.get_set_tmg_run'
14548 );
14549 END IF;
14550
14551 okl_am_lease_loan_trmnt_pvt.get_set_tmg_run
14552 (p_trx_id => lp_tcnv_rec.ID,
14553 x_return_status => l_return_status);
14554
14555 IF (is_debug_statement_on)
14556 THEN
14557 okl_debug_pub.log_debug
14558 (g_level_statement,
14559 l_module_name,
14560 'called OKL_AM_LEASE_LOAN_TRMNT_PVT.get_set_tmg_run , return status: '
14561 || l_return_status
14562 );
14563 END IF;
14564
14565 -- exit since split asset failed
14566 RAISE g_exception_halt_validation;
14567 END IF;
14568
14569 -- do accounting entries
14570 accounting_entries (p_term_rec => l_term_rec,
14571 p_sys_date => l_sys_date,
14572 p_klev_tbl => lx_klev_tbl,
14573 p_trn_already_set => l_trn_already_set,
14574 px_overall_status => l_overall_status,
14575 px_tcnv_rec => lp_tcnv_rec,
14576 x_return_status => l_return_status
14577 );
14578
14579 IF (is_debug_statement_on)
14580 THEN
14581 okl_debug_pub.log_debug
14582 (g_level_statement,
14583 l_module_name,
14584 'called accounting_entries , return status: '
14585 || l_return_status
14586 );
14587 END IF;
14588
14589 -- RMUNJULU 02-JAN-03 2724951 Added code to get lease or loan
14590 -- Check if lease or loan
14591 check_lease_or_loan (p_khr_id => l_term_rec.p_contract_id,
14592 x_lease_loan_type => l_lease_or_loan);
14593
14594 IF (is_debug_statement_on)
14595 THEN
14596 okl_debug_pub.log_debug
14597 (g_level_statement,
14598 l_module_name,
14599 'called check_lease_or_loan , l_lease_or_loan: '
14600 || l_lease_or_loan
14601 );
14602 END IF;
14603
14604 -- RMUNJULU 02-JAN-03 2724951 Added code to check if loan and do dispose else
14605 -- if lease then check if with purchase or without and do accordingly
14606 -- If loan then do only dispose
14607 IF l_lease_or_loan = 'LOAN'
14608 THEN
14609 -- do asset dispose
14610 dispose_assets (p_term_rec => l_term_rec,
14611 p_sys_date => l_sys_date,
14612 p_klev_tbl => lx_klev_tbl,
14613 p_trn_already_set => l_trn_already_set,
14614 px_overall_status => l_overall_status,
14615 px_tcnv_rec => lp_tcnv_rec,
14616 x_return_status => l_return_status
14617 );
14618
14619 IF (is_debug_statement_on)
14620 THEN
14621 okl_debug_pub.log_debug
14622 (g_level_statement,
14623 l_module_name,
14624 'called dispose_assets , return status: '
14625 || l_return_status
14626 );
14627 END IF;
14628 ELSE
14629 -- l_lease_or_loan = 'LEASE'
14630
14631 -- If termination with purchase then do dispose else amortize and return
14632 -- RMUNJULU 31-JAN-03 2780539 Added TER_MAN_PURCHASE which is also a
14633 -- termination with purchase
14634 IF (l_term_rec.p_quote_type IN
14635 ('TER_PURCHASE',
14636 'TER_RECOURSE',
14637 'TER_ROLL_PURCHASE',
14638 'TER_MAN_PURCHASE'
14639 )
14640 )
14641 THEN
14642 -- do asset dispose
14643 dispose_assets (p_term_rec => l_term_rec,
14644 p_sys_date => l_sys_date,
14645 p_klev_tbl => lx_klev_tbl,
14646 p_trn_already_set => l_trn_already_set,
14647 px_overall_status => l_overall_status,
14648 px_tcnv_rec => lp_tcnv_rec,
14649 x_return_status => l_return_status
14650 );
14651
14652 IF (is_debug_statement_on)
14653 THEN
14654 okl_debug_pub.log_debug
14655 (g_level_statement,
14656 l_module_name,
14657 'called dispose_assets , return status: '
14658 || l_return_status
14659 );
14660 END IF;
14661
14662 -- Amortization of assets not needed since termination
14663 -- with purchase.
14664 okl_api.set_message (p_app_name => g_app_name,
14665 p_msg_name => 'OKL_AM_AMORTIZE_NOT_NEED');
14666 -- Return of assets not needed since termination with purchase
14667 okl_api.set_message (p_app_name => g_app_name,
14668 p_msg_name => 'OKL_AM_RETURN_NOT_NEED');
14669 ELSE
14670 -- do amortization
14671 amortize_assets (p_term_rec => l_term_rec,
14672 p_sys_date => l_sys_date,
14673 p_klev_tbl => lx_klev_tbl,
14674 p_trn_already_set => l_trn_already_set,
14675 px_overall_status => l_overall_status,
14676 px_tcnv_rec => lp_tcnv_rec,
14677 x_return_status => l_return_status
14678 );
14679
14680 IF (is_debug_statement_on)
14681 THEN
14682 okl_debug_pub.log_debug
14683 (g_level_statement,
14684 l_module_name,
14685 'called amortize_assets , return status: '
14686 || l_return_status
14687 );
14688 END IF;
14689
14690 /* rmunjulu bug 6853566 do not call delink here, call from amortize.
14691 IF g_amort_complete_flag = 'Y'
14692 THEN
14693 -- do denlink of assets from k if it is going offlease
14694 delink_assets (p_term_rec => l_term_rec,
14695 p_sys_date => l_sys_date,
14696 p_klev_tbl => lx_klev_tbl,
14697 p_trn_already_set => l_trn_already_set,
14698 px_overall_status => l_overall_status,
14699 px_tcnv_rec => lp_tcnv_rec,
14700 x_return_status => l_return_status
14701 );
14702 END IF;
14703 */
14704 -- do asset return
14705 return_assets (p_term_rec => l_term_rec,
14706 p_sys_date => l_sys_date,
14707 p_klev_tbl => lx_klev_tbl,
14708 p_trn_already_set => l_trn_already_set,
14709 px_overall_status => l_overall_status,
14710 px_tcnv_rec => lp_tcnv_rec,
14711 x_return_status => l_return_status
14712 );
14713
14714 IF (is_debug_statement_on)
14715 THEN
14716 okl_debug_pub.log_debug
14717 (g_level_statement,
14718 l_module_name,
14719 'called return_assets , return status: '
14720 || l_return_status
14721 );
14722 END IF;
14723
14724 -- Disposition of assets not needed since termination without purchase
14725 okl_api.set_message (p_app_name => g_app_name,
14726 p_msg_name => 'OKL_AM_DISPOSE_NOT_NEED');
14727 END IF;
14728 END IF;
14729
14730 -- update the lines only if the overall_status is success
14731 IF (l_overall_status = g_ret_sts_success)
14732 THEN
14733 -- Set the p_status (which sets the sts_code) for the contract
14734 IF l_term_rec.p_control_flag = 'BATCH_PROCESS'
14735 AND ( l_term_rec.p_quote_id IS NULL
14736 OR l_term_rec.p_quote_id = g_miss_num
14737 )
14738 THEN
14739 l_status := 'EXPIRED';
14740 ELSE
14741 l_status := 'TERMINATED';
14742 END IF;
14743
14744 -- RMUNJULU 3018641 Step Message
14745 -- Step : Update Contract and Lines
14746 okl_api.set_message (p_app_name => g_app_name,
14747 p_msg_name => 'OKL_AM_STEP_UPD');
14748
14749 -- RMUNJULU 23-JAN-03 2762065
14750 -- If batch process then log the messages from stack
14751 IF p_term_rec.p_control_flag LIKE 'BATCH%'
14752 THEN
14753 -- RMUNJULU 2730738 for proper output file
14754 okl_am_btch_exp_lease_loan_pvt.pop_asset_msg_tbl; --log_messages;
14755 END IF;
14756
14757 -- RMUNJULU 07-JAN-03 2736865 Added code to store messages and set stack to true
14758 -- Store messages in TRX_MSGS
14759 IF (is_debug_statement_on)
14760 THEN
14761 okl_debug_pub.log_debug
14762 (g_level_statement,
14763 l_module_name,
14764 'calling OKL_AM_UTIL_PVT.process_messages'
14765 );
14766 END IF;
14767
14768 okl_am_util_pvt.process_messages
14769 (p_trx_source_table => 'OKL_TRX_CONTRACTS',
14770 p_trx_id => lp_tcnv_rec.ID,
14771 x_return_status => l_return_status
14772 );
14773
14774 IF (is_debug_statement_on)
14775 THEN
14776 okl_debug_pub.log_debug
14777 (g_level_statement,
14778 l_module_name,
14779 'called OKL_AM_UTIL_PVT.process_messages , return status: '
14780 || l_return_status
14781 );
14782 END IF;
14783
14784 -- Set message stack to true
14785 okl_api.init_msg_list (g_true);
14786 -- update lines, do mass rebook and activate insurances
14787 terminate_lines
14788 (p_api_version => p_api_version,
14789 p_init_msg_list => g_false,
14790 x_msg_count => x_msg_count,
14791 x_msg_data => x_msg_data,
14792 x_return_status => l_return_status,
14793 px_overall_status => l_overall_status,
14794 p_trn_already_set => l_trn_already_set,
14795 -- RMUNJULU CONTRACT BLOCKING -- ADDED
14796 p_term_rec => l_term_rec,
14797 p_sys_date => l_sys_date,
14798 p_klev_tbl => lx_klev_tbl,
14799 p_status => l_status,
14800 px_tcnv_rec => lp_tcnv_rec
14801 );
14802
14803 IF (is_debug_statement_on)
14804 THEN
14805 okl_debug_pub.log_debug
14806 (g_level_statement,
14807 l_module_name,
14808 'called terminate_lines , return status: '
14809 || l_return_status
14810 );
14811 END IF;
14812
14813 --++++++++start -- CONTRACT BLOCKING (2)
14814 -- Transaction is now updated in terminate lines (before massrebook and after massrebook if needed)
14815 -- But not if anyproc before mass rebook fails
14816 IF l_return_status <> g_ret_sts_success
14817 THEN
14818 -- update the transaction record
14819 process_transaction (p_id => 0,
14820 p_term_rec => l_term_rec,
14821 p_tcnv_rec => lp_tcnv_rec,
14822 p_trn_mode => 'UPDATE',
14823 x_id => lx_id,
14824 x_return_status => l_return_status
14825 );
14826
14827 IF (is_debug_statement_on)
14828 THEN
14829 okl_debug_pub.log_debug
14830 (g_level_statement,
14831 l_module_name,
14832 'called process_transaction , return status: '
14833 || l_return_status
14834 );
14835 END IF;
14836
14837 -- rollback if processing transaction failed
14838 IF (l_return_status = g_ret_sts_unexp_error)
14839 THEN
14840 RAISE okl_api.g_exception_unexpected_error;
14841 ELSIF (l_return_status = g_ret_sts_error)
14842 THEN
14843 RAISE okl_api.g_exception_error;
14844 END IF;
14845 END IF;
14846 -- END IF;
14847 ELSE
14848 -- Overall Not successfull so update transaction
14849
14850 -- update the transaction record
14851 process_transaction (p_id => 0,
14852 p_term_rec => l_term_rec,
14853 p_tcnv_rec => lp_tcnv_rec,
14854 p_trn_mode => 'UPDATE',
14855 x_id => lx_id,
14856 x_return_status => l_return_status
14857 );
14858
14859 IF (is_debug_statement_on)
14860 THEN
14861 okl_debug_pub.log_debug
14862 (g_level_statement,
14863 l_module_name,
14864 'called process_transaction , return status: '
14865 || l_return_status
14866 );
14867 END IF;
14868
14869 -- rollback if processing transaction failed
14870 IF (l_return_status = g_ret_sts_unexp_error)
14871 THEN
14872 RAISE okl_api.g_exception_unexpected_error;
14873 ELSIF (l_return_status = g_ret_sts_error)
14874 THEN
14875 RAISE okl_api.g_exception_error;
14876 END IF;
14877 END IF;
14878
14879 --+++++++++end -- CONTRACT BLOCKING (2)
14880
14881 -- RMUNJULU 2730738 for proper output file
14882 IF p_term_rec.p_control_flag LIKE 'BATCH%'
14883 THEN
14884 okl_am_btch_exp_lease_loan_pvt.pop_asset_msg_tbl;
14885 END IF;
14886
14887 -- Save messages from stack into transaction message table
14888 IF (is_debug_statement_on)
14889 THEN
14890 okl_debug_pub.log_debug (g_level_statement,
14891 l_module_name,
14892 'calling OKL_AM_UTIL_PVT.process_messages'
14893 );
14894 END IF;
14895
14896 okl_am_util_pvt.process_messages
14897 (p_trx_source_table => 'OKL_TRX_CONTRACTS',
14898 p_trx_id => lp_tcnv_rec.ID,
14899 x_return_status => l_return_status
14900 );
14901
14902 IF (is_debug_statement_on)
14903 THEN
14904 okl_debug_pub.log_debug
14905 (g_level_statement,
14906 l_module_name,
14907 'called OKL_AM_UTIL_PVT.process_messages , return status: '
14908 || l_return_status
14909 );
14910 END IF;
14911
14912 -- RMUNJULU 3018641 Added code to get and set TMG_RUN
14913 IF (is_debug_statement_on)
14914 THEN
14915 okl_debug_pub.log_debug
14916 (g_level_statement,
14917 l_module_name,
14918 'calling OKL_AM_LEASE_LOAN_TRMNT_PVT.get_set_tmg_run'
14919 );
14920 END IF;
14921
14922 okl_am_lease_loan_trmnt_pvt.get_set_tmg_run
14923 (p_trx_id => lp_tcnv_rec.ID,
14924 x_return_status => l_return_status);
14925
14926 IF (is_debug_statement_on)
14927 THEN
14928 okl_debug_pub.log_debug
14929 (g_level_statement,
14930 l_module_name,
14931 'called OKL_AM_LEASE_LOAN_TRMNT_PVT.get_set_tmg_run , return status: '
14932 || l_return_status
14933 );
14934 END IF;
14935
14936 -- Set the return status
14937 x_return_status := g_ret_sts_success;
14938 -- End the activity
14939 okl_api.end_activity (x_msg_count, x_msg_data);
14940
14941 IF (is_debug_procedure_on)
14942 THEN
14943 okl_debug_pub.log_debug (g_level_procedure,
14944 l_module_name,
14945 'End(-)'
14946 );
14947 END IF;
14948 EXCEPTION
14949 WHEN g_exception_halt_validation
14950 THEN
14951 x_return_status := g_ret_sts_success;
14952
14953 IF (is_debug_exception_on)
14954 THEN
14955 okl_debug_pub.log_debug (g_level_exception,
14956 l_module_name,
14957 'EXCEPTION :'
14958 || 'G_EXCEPTION_HALT_VALIDATION'
14959 );
14960 END IF;
14961 WHEN okl_api.g_exception_error
14962 THEN
14963 x_return_status :=
14964 okl_api.handle_exceptions (l_api_name,
14965 g_pkg_name,
14966 'G_RET_STS_ERROR',
14967 x_msg_count,
14968 x_msg_data,
14969 '_PVT'
14970 );
14971
14972 IF (is_debug_exception_on)
14973 THEN
14974 okl_debug_pub.log_debug (g_level_exception,
14975 l_module_name,
14976 'EXCEPTION :' || 'G_EXCEPTION_ERROR'
14977 );
14978 END IF;
14979 WHEN okl_api.g_exception_unexpected_error
14980 THEN
14981 x_return_status :=
14982 okl_api.handle_exceptions (l_api_name,
14983 g_pkg_name,
14984 'G_RET_STS_UNEXP_ERROR',
14985 x_msg_count,
14986 x_msg_data,
14987 '_PVT'
14988 );
14989
14990 IF (is_debug_exception_on)
14991 THEN
14992 okl_debug_pub.log_debug (g_level_exception,
14993 l_module_name,
14994 'EXCEPTION :'
14995 || 'G_EXCEPTION_UNEXPECTED_ERROR'
14996 );
14997 END IF;
14998 WHEN OTHERS
14999 THEN
15000 x_return_status :=
15001 okl_api.handle_exceptions (l_api_name,
15002 g_pkg_name,
15003 'OTHERS',
15004 x_msg_count,
15005 x_msg_data,
15006 '_PVT'
15007 );
15008
15009 IF (is_debug_exception_on)
15010 THEN
15011 okl_debug_pub.log_debug (g_level_exception,
15012 l_module_name,
15013 'EXCEPTION :'
15014 || 'OTHERS, SQLCODE: '
15015 || SQLCODE
15016 || ' , SQLERRM : '
15017 || SQLERRM
15018 );
15019 END IF;
15020 END asset_level_termination;
15021 END okl_am_cntrct_ln_trmnt_pvt;