[Home] [Help]
PACKAGE BODY: APPS.OKL_LA_SALES_TAX_PVT
Source
1 PACKAGE BODY OKL_LA_SALES_TAX_PVT AS
2 /* $Header: OKLRSTXB.pls 120.57.12010000.4 2008/10/31 05:48:42 rpillay ship $ */
3
4 G_MODULE VARCHAR2(255) := 'okl.stream.esg.okl_esg_transport_pvt';
5 G_DEBUG_ENABLED CONSTANT VARCHAR2(10) := OKL_DEBUG_PUB.CHECK_LOG_ENABLED;
6 G_IS_DEBUG_STATEMENT_ON BOOLEAN;
7
8 -- Common Cursors
9
10 -- Cursor to check if the sales tax parameter(switch) is set to yes.
11 CURSOR l_tax_system_info IS
12 SELECT nvl(tax_upfront_yn,'N')
13 FROM okl_system_params;
14 l_upfront_tax_yn VARCHAR2(1);
15
16
17 -- R12 - START
18
19 -- Global Cursor to get contract header linformation
20 CURSOR Product_csr (p_contract_id OKC_K_HEADERS_B.ID%TYPE)
21 IS
22 SELECT khr.pdt_id product_id
23 ,NULL product_name
24 ,khr.sts_code contract_status
25 ,khr.start_date start_date
26 ,khr.currency_code currency_code
27 ,khr.authoring_org_id authoring_org_id
28 ,khr.currency_conversion_rate currency_conversion_rate
29 ,khr.currency_conversion_type currency_conversion_type
30 ,khr.currency_conversion_date currency_conversion_date
31 ,khr.scs_code scs_code
32 FROM okl_k_headers_full_v khr
33 WHERE khr.id = p_contract_id;
34
35 g_Product_rec Product_csr%ROWTYPE;
36
37 -- R12 - END
38
39
40 -- Cursor to get Transaction type and status descriptions
41 CURSOR fnd_lookups_csr( lkp_type VARCHAR2, mng VARCHAR2 ) IS
42 select description, lookup_code
43 from fnd_lookup_values
44 where language = 'US'
45 AND lookup_type = lkp_type
46 AND meaning = mng;
47
48 -- The following cursor checks if BILLED is selected on T and C, user should not
49 -- select asset upfront tax to be FINANCED for some assets and CAPITALIZED
50 -- for some. Both Financed and Capitalized fee lines cannot be created
51 -- together for sales tax. We allow either Financed or Capitalize fee lines only
52
53 -- Bug# 6512668: Exclude asset lines in Abandoned status
54 CURSOR check_feetype_csr (p_contract_id IN NUMBER)
55 IS
56 SELECT NVL(rule_information11,'BILLED') feetype
57 FROM okc_rules_b rl,
58 okc_rule_groups_b rgp,
59 okc_k_lines_b cle
60 WHERE rl.dnz_chr_id = p_contract_id
61 AND rl.rule_information_category = 'LAASTX'
62 AND NVL(rule_information11,'BILLED') <> 'BILLED'
63 AND rgp.id = rl.rgp_id
64 AND cle.id = rgp.cle_id
65 AND cle.sts_code <> 'ABANDONED';
66
67 -- Cursor to get rule values
68 CURSOR rule_info_csr (p_contract_id IN NUMBER)
69 IS
70 SELECT rule_information1,
71 rule_information2,
72 rule_information3,
73 rule_information4,
74 rule_information5
75 FROM okc_rules_b rl
76 WHERE rl.dnz_chr_id = p_contract_id
77 AND rl.rule_information_category = 'LASTPR';
78
79 -- The following checks if all the lines have the asset upfront tax as
80 -- selected on T and C. for instance,user might select FINANCED or CAPITALIZED
81 -- on T and C, but might do the opposite for all asset level taxes. If user
82 -- selects FINANCED on T and C but bills all line taxes, we do not need
83 -- to create fee lines at all
84
85 -- Bug# 6512668: Exclude asset lines in Abandoned status
86 CURSOR check_lines_csr (p_contract_id IN NUMBER, l_fee_type IN VARCHAR2 )
87 IS
88 SELECT count(NVL(rule_information11, l_fee_type))
89 FROM okc_rules_b rl,
90 okc_rule_groups_b rgp,
91 okc_k_lines_b cle
92 WHERE rl.dnz_chr_id = p_contract_id
93 AND rl.rule_information_category = 'LAASTX'
94 AND NVL(rule_information11, l_fee_type) = l_fee_type
95 AND rgp.id = rl.rgp_id
96 AND cle.id = rgp.cle_id
97 AND cle.sts_code <> 'ABANDONED';
98
99 -- Cursor to get financed or capitalized tax amount if
100 -- default tax treatment is FINANCED or CAPITALIZED respectively
101
102 -- Bug# 6512668: Exclude asset lines in Abandoned status
103 CURSOR get_fee_amt_csr1(p_contract_id IN NUMBER, p_feetype IN VARCHAR2)
104 IS
105 SELECT NVL(SUM(NVL(TOTAL_TAX,0)),0)
106 FROM okl_tax_sources txs,
107 okc_rule_groups_b rg1,
108 okc_rules_b rl1,
109 okc_rule_groups_b rg2,
110 okc_rules_b rl2,
111 okc_k_lines_b cle
112 WHERE txs.KHR_ID = p_contract_id
113 AND txs.khr_id = rg1.dnz_chr_id
114 AND txs.kle_id = rg1.cle_id
115 AND txs.khr_id = rl1.dnz_chr_id
116 AND rg1.rgd_code = 'LAASTX'
117 AND rg1.id = rl1.rgp_id
118 AND rl1.rule_information_category = 'LAASTX'
119 AND (rl1.rule_information11 = p_feetype
120 OR
121 rl1.rule_information11 IS NULL)
122 AND txs.TAX_LINE_STATUS_CODE = 'ACTIVE'
123 AND txs.TAX_CALL_TYPE_CODE = 'UPFRONT_TAX'
124 AND txs.KHR_ID = rg2.dnz_chr_id
125 AND txs.KHR_ID = rl2.dnz_chr_id
126 AND rg2.id = rl2.rgp_id
127 AND rg2.rgd_code = 'LAHDTX'
128 AND rl2.rule_information_category = 'LASTPR'
129 AND rl2.rule_information1 = p_feetype
130 AND cle.id = rg1.cle_id
131 AND cle.sts_code <> 'ABANDONED';
132
133 -- Cursor to get financed or capitalized tax Amount if
134 -- default tax treatment is BILLED
135
136 -- Bug# 6512668: Exclude asset lines in Abandoned status
137 CURSOR get_fee_amt_csr2 (p_contract_id IN NUMBER, p_feetype IN VARCHAR2)
138 IS
139 SELECT NVL(SUM(NVL(TOTAL_TAX,0)),0)
140 FROM okl_tax_sources txs
141 ,okc_rule_groups_b rg1
142 ,okc_rules_b rl1
143 ,okc_k_lines_b cle
144 WHERE txs.KHR_ID = p_Contract_id
145 AND txs.khr_id = rg1.dnz_chr_id
146 AND txs.kle_id = rg1.cle_id
147 AND txs.khr_id = rl1.dnz_chr_id
148 AND rg1.rgd_code = 'LAASTX'
149 AND rg1.id = rl1.rgp_id
150 AND rl1.rule_information_category = 'LAASTX'
151 AND rl1.rule_information11 = p_feetype
152 AND txs.TAX_LINE_STATUS_CODE = 'ACTIVE'
153 AND txs.TAX_CALL_TYPE_CODE = 'UPFRONT_TAX'
154 AND cle.id = rg1.cle_id
155 AND cle.sts_code <> 'ABANDONED'; -- Bug 5005269
156
157
158 -- Use this cursor for billing trx when T and C asset upfront tax is
159 -- Financed or Capitalized
160 -- R12B eBtax: Added check that upfront tax amount is not zero
161
162 -- Bug# 6512668: Exclude asset lines in Abandoned status
163 CURSOR billing_required_csr1(p_contract_id IN NUMBER,
164 p_transaction_id IN NUMBER) IS
165 SELECT 1
166 FROM okl_tax_sources txs,
167 okc_rule_groups_b rg1,
168 okc_rules_b rl1,
169 okc_k_lines_b cle
170 WHERE txs.khr_id = p_contract_id
171 AND txs.trx_id = p_transaction_id
172 -- R12B ebtax: Active and Inactive lines will be billed during rebook
173 -- AND txs.tax_line_status_code = 'ACTIVE'
174 AND txs.tax_call_type_code = 'UPFRONT_TAX'
175 AND NVL(txs.total_tax,0) <> 0
176 AND rg1.dnz_chr_id = txs.khr_id
177 AND rg1.cle_id = txs.kle_id
178 AND rg1.rgd_code = 'LAASTX'
179 AND rl1.dnz_chr_id = rg1.dnz_chr_id
180 AND rl1.rgp_id = rg1.id
181 AND rl1.rule_information_category = 'LAASTX'
182 AND rl1.rule_information11 = 'BILLED'
183 AND cle.id = rg1.cle_id
184 AND cle.sts_code <> 'ABANDONED';
185
186 -- Use this cursor for billing trx when T and C asset upfront tax is
187 -- Billed
188 -- R12B eBtax: Added check that upfront tax amount is not zero
189
190 -- Bug# 6512668: Exclude asset lines in Abandoned status
191 CURSOR billing_required_csr2(p_contract_id IN NUMBER,
192 p_transaction_id IN NUMBER) IS
193 SELECT 1
194 FROM okl_tax_sources txs,
195 okc_rule_groups_b rg1,
196 okc_rules_b rl1,
197 okc_k_lines_b cle
198 WHERE txs.khr_id = p_contract_id
199 AND txs.trx_id = p_transaction_id
200 -- R12B ebtax: Active and Inactive lines will be billed during rebook
201 -- AND txs.tax_line_status_code = 'ACTIVE'
202 AND txs.tax_call_type_code = 'UPFRONT_TAX'
203 AND NVL(txs.total_tax,0) <> 0
204 AND rg1.dnz_chr_id = txs.khr_id
205 AND rg1.cle_id = txs.kle_id
206 AND rg1.rgd_code = 'LAASTX'
207 AND rl1.dnz_chr_id = rg1.dnz_chr_id
208 AND rl1.rgp_id = rg1.id
209 AND rl1.rule_information_category = 'LAASTX'
210 AND NVL(rl1.rule_information11,'BILLED') = 'BILLED'
211 AND cle.id = rg1.cle_id
212 AND cle.sts_code <> 'ABANDONED';
213
214 --Bug# 6939336
215 -- This cursor gets biling amount at contract header level
216 CURSOR contract_billing_csr(p_contract_id IN NUMBER,
217 p_transaction_id IN NUMBER) IS
218 SELECT 1
219 FROM okl_tax_sources txs
220 WHERE txs.khr_id = p_contract_id
221 AND txs.trx_id = p_transaction_id
222 AND txs.kle_id IS NULL
223 AND txs.tax_line_status_code = 'ACTIVE'
224 AND txs.tax_call_type_code = 'UPFRONT_TAX'
225 AND NVL(txs.total_tax,0) <> 0;
226
227 -- Global Variables
228 g_source_table VARCHAR2(30) := 'OKL_TRX_CONTRACTS';
229
230
231
232 -- Start of comments
233 --
234 -- Procedure Name : create_sales_tax_rules
235 -- Description : Creates sales tax rules after the asset is created. If
236 -- header sales tax information does not exist, the
237 -- default values will get set
238 -- Business Rules :
239 -- Parameters :
240 -- Version : 1.0
241 -- End of comments
242
243
244 PROCEDURE create_sales_tax_rules(
245 p_api_version IN NUMBER,
246 p_init_msg_list IN VARCHAR2 DEFAULT OKC_API.G_FALSE,
247 x_return_status OUT NOCOPY VARCHAR2,
248 x_msg_count OUT NOCOPY NUMBER,
249 x_msg_data OUT NOCOPY VARCHAR2,
250 p_chr_id IN NUMBER,
251 p_cle_id IN NUMBER)
252
253 IS
254 l_rgpv_rec rgpv_rec_type;
255 l_rulv_rec rulv_rec_type;
256 lx_rgpv_rec rgpv_rec_type;
257 lx_rulv_rec rulv_rec_type;
258
259 l_chr_id okc_k_headers_b.id%TYPE;
260 l_cle_id okc_k_lines_v.id%TYPE;
261 l_rgp_id NUMBER;
262
263 lv_k_rule_information1 okc_rules_v.rule_information1%TYPE;
264 lv_k_rule_information3 okc_rules_v.rule_information3%TYPE;
265 lv_k_rule_information4 okc_rules_v.rule_information4%TYPE;
266 lv_k_rule_information5 okc_rules_v.rule_information5%TYPE;
267 lv_k_rule_information6 okc_rules_v.rule_information6%TYPE;
268 lv_k_rule_information7 okc_rules_v.rule_information7%TYPE;
269
270 CURSOR get_contract_deal_type(p_chr_id okc_k_headers_b.id%TYPE) IS
271 select deal_type
272 from okl_k_headers
273 where deal_type = 'LOAN'
274 and id = p_chr_id;
275
276 CURSOR get_contract_sales_tax_info(p_chr_id okc_k_headers_b.id%TYPE) IS
277 SELECT rul.rule_information1, rul.rule_information3, rul.rule_information4,
278 rul.rule_information5, rul.rule_information6, rul.rule_information7
279 FROM OKC_RULES_V rul,
280 OKC_RULE_GROUPS_V rgp
281 WHERE rul.rgp_id = rgp.id
282 AND rgp.dnz_chr_id = p_chr_id
283 AND rgp.cle_id is NULL
284 AND rgp.rgd_code = 'LAHDTX'
285 AND rul.rule_information_category = 'LASTCL';
286
287 CURSOR l_hdr_upfront_tax(p_chr_id okc_k_headers_b.id%TYPE) IS
288 SELECT rul.rule_information1
289 FROM OKC_RULES_V rul,
290 OKC_RULE_GROUPS_V rgp
291 WHERE rul.rgp_id = rgp.id
292 AND rgp.dnz_chr_id = p_chr_id
293 AND rgp.cle_id is NULL
294 AND rgp.rgd_code = 'LAHDTX'
295 AND rul.rule_information_category = 'LASTPR';
296
297 CURSOR l_asset_tax_rule_group(p_chr_id okc_k_headers_b.id%TYPE,
298 p_cle_id NUMBER) IS -- 5179119
299 SELECT id
300 FROM OKC_RULE_GROUPS_B rgp
301 WHERE rgp.dnz_chr_id = p_chr_id
302 AND rgp.cle_id is NOT NULL
303 AND rgp.rgd_code = 'LAASTX'
304 AND rgp.cle_id = p_cle_id; -- 5179119
305 l_asset_tax_rule_group_rec l_asset_tax_rule_group%ROWTYPE;
306 l_row_found BOOLEAN;
307
308 l_api_name CONSTANT VARCHAR2(30) := 'CREATE_SALES_TAX_RULES';
309
310 l_flag VARCHAR2(30) := 'XXXX';
311 l_deal_type okl_k_headers.deal_type%type;
312 l_orig_system_source_code okc_k_headers_b.orig_system_source_code%type;
313 l_header_upfront_tax okc_rules_v.rule_information1%TYPE;
314
315 BEGIN
316
317 x_return_status := OKL_API.G_RET_STS_SUCCESS;
318
319 l_chr_id := p_chr_id;
320 l_cle_id := p_cle_id;
321
322 IF okl_context.get_okc_org_id IS NULL THEN
323 okl_context.set_okc_org_context(p_chr_id => l_chr_id);
324 END IF;
325
326 -- call START_ACTIVITY to create savepoint, check compatibility
327 -- and initialize message list
328 x_return_status := OKL_API.START_ACTIVITY (
329 l_api_name
330 ,p_init_msg_list
331 ,g_api_type
332 ,x_return_status);
333
334 -- check if activity started successfully
335 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
336 RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
337 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
338 RAISE OKL_API.G_EXCEPTION_ERROR;
339 END IF;
340
341 OPEN l_hdr_upfront_tax(p_chr_id);
342 FETCH l_hdr_upfront_tax into l_header_upfront_tax;
343 CLOSE l_hdr_upfront_tax;
344
345 -- get the contract header sales tax info to map to line sales tax
346 -- Also, get 'update line from contract header ' flag to check whether
347 -- to update with contract sales tax info
348
349 OPEN get_contract_sales_tax_info(l_chr_id);
350 FETCH get_contract_sales_tax_info into lv_k_rule_information1,
351 lv_k_rule_information3,
352 lv_k_rule_information4,
353 lv_k_rule_information5,
354 lv_k_rule_information6,
355 lv_k_rule_information7;
356 IF (get_contract_sales_tax_info%NOTFOUND) THEN
357 l_flag := 'DEFAULT';
358 END IF;
359 CLOSE get_contract_sales_tax_info;
360
361 IF(NOT(NVL(lv_k_rule_information1,'N') = 'Y')) THEN
362 l_flag := 'DEFAULT';
363 END IF;
364
365 -- Create the rule group for sales Tax
366 l_rgpv_rec.rgd_code := 'LAASTX';
367 l_rgpv_rec.chr_id := null;
368 l_rgpv_rec.dnz_chr_id := l_chr_id;
369 l_rgpv_rec.cle_id := l_cle_id;
370 l_rgpv_rec.rgp_type := 'KRG';
371
372 --Bug#4990898 ramurt
373 OPEN l_asset_tax_rule_group(p_chr_id, p_cle_id); -- 5179119
374 FETCH l_asset_tax_rule_group INTO l_asset_tax_rule_group_rec;
375 l_row_found := l_asset_tax_rule_group%FOUND;
376 CLOSE l_asset_tax_rule_group;
377
378 IF (l_row_found) THEN
379 l_rgp_id := l_asset_tax_rule_group_rec.id;
380 ELSE
381 OKL_RULE_PUB.create_rule_group(
382 p_api_version => p_api_version,
383 p_init_msg_list => p_init_msg_list,
384 x_return_status => x_return_status,
385 x_msg_count => x_msg_count,
386 x_msg_data => x_msg_data,
387 p_rgpv_rec => l_rgpv_rec,
388 x_rgpv_rec => lx_rgpv_rec);
389 l_rgp_id := lx_rgpv_rec.id;
390
391 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
392 RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
393 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
394 RAISE OKL_API.G_EXCEPTION_ERROR;
395 END IF;
396 END IF;
397
398 -- Create the sales Tax rule
399 l_rulv_rec.dnz_chr_id := l_chr_id;
400 l_rulv_rec.rgp_id := l_rgp_id;
401 l_rulv_rec.rule_information_category := 'LAASTX';
402 l_rulv_rec.sfwt_flag := 'N';
403 l_rulv_rec.std_template_yn := 'N';
404 l_rulv_rec.warn_yn := 'N';
405 l_rulv_rec.template_yn := 'N';
406 l_rulv_rec.rule_information5 := 'N';
407
408 -- if the header sales info doesnt exist set default values
409
410 IF(l_flag = 'DEFAULT') THEN
411
412 l_deal_type := NULL;
413 OPEN get_contract_deal_type(l_chr_id);
414 FETCH get_contract_deal_type into l_deal_type;
415 CLOSE get_contract_deal_type;
416
417 l_rulv_rec.rule_information6 := 'N';
418
419 IF( l_deal_type IS NULL) THEN -- contract deal type is not loan
420 l_rulv_rec.rule_information7 := 'N'; -- Yes for Loan
421 ELSE
422 l_rulv_rec.rule_information7 := 'Y'; -- Yes for Loan
423 END IF;
424
425 l_rulv_rec.rule_information8 := 'N';
426 --l_rulv_rec.rule_information9 := lv_k_rule_information6; -- user specified
427 --l_rulv_rec.rule_information10 := lv_k_rule_information7; -- user specified
428
429 ELSE
430
431 l_rulv_rec.rule_information6 := lv_k_rule_information3;
432 l_rulv_rec.rule_information7 := lv_k_rule_information4;
433 l_rulv_rec.rule_information8 := lv_k_rule_information5;
434 l_rulv_rec.rule_information9 := lv_k_rule_information6;
435 l_rulv_rec.rule_information10 := lv_k_rule_information7;
436 l_rulv_rec.rule_information11 := l_header_upfront_tax;
437
438 END IF;
439
440 OKL_RULE_PUB.create_rule(
441 p_api_version => p_api_version,
442 p_init_msg_list => p_init_msg_list,
443 x_return_status => x_return_status,
444 x_msg_count => x_msg_count,
445 x_msg_data => x_msg_data,
446 p_rulv_rec => l_rulv_rec,
447 x_rulv_rec => lx_rulv_rec);
448
449 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
450 RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
451 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
452 RAISE OKL_API.G_EXCEPTION_ERROR;
453 END IF;
454
455 OKL_API.END_ACTIVITY (x_msg_count => x_msg_count,
456 x_msg_data => x_msg_data);
457 EXCEPTION
458 WHEN OKL_API.G_EXCEPTION_ERROR THEN
459 IF get_contract_sales_tax_info%ISOPEN THEN
460 CLOSE get_contract_sales_tax_info;
461 END IF;
462 IF l_hdr_upfront_tax%ISOPEN THEN
463 CLOSE l_hdr_upfront_tax;
464 END IF;
465 IF l_asset_tax_rule_group%ISOPEN THEN
466 CLOSE l_asset_tax_rule_group;
467 END IF;
468
469
470 x_return_status := OKL_API.HANDLE_EXCEPTIONS(
471 p_api_name => l_api_name,
472 p_pkg_name => g_pkg_name,
473 p_exc_name => 'OKC_API.G_RET_STS_ERROR',
474 x_msg_count => x_msg_count,
475 x_msg_data => x_msg_data,
476 p_api_type => g_api_type);
477
478 WHEN OKL_API.G_EXCEPTION_UNEXPECTED_ERROR THEN
479 IF get_contract_sales_tax_info%ISOPEN THEN
480 CLOSE get_contract_sales_tax_info;
481 END IF;
482 IF l_hdr_upfront_tax%ISOPEN THEN
483 CLOSE l_hdr_upfront_tax;
484 END IF;
485 IF l_asset_tax_rule_group%ISOPEN THEN
486 CLOSE l_asset_tax_rule_group;
487 END IF;
488 x_return_status := OKL_API.HANDLE_EXCEPTIONS(
489 p_api_name => l_api_name,
490 p_pkg_name => g_pkg_name,
491 p_exc_name => 'OKC_API.G_RET_STS_UNEXP_ERROR',
492 x_msg_count => x_msg_count,
493 x_msg_data => x_msg_data,
494 p_api_type => g_api_type);
495
496 WHEN OTHERS THEN
497 IF get_contract_sales_tax_info%ISOPEN THEN
498 CLOSE get_contract_sales_tax_info;
499 END IF;
500 IF l_asset_tax_rule_group%ISOPEN THEN
501 CLOSE l_asset_tax_rule_group;
502 END IF;
503 x_return_status := OKL_API.HANDLE_EXCEPTIONS(
504 p_api_name => l_api_name,
505 p_pkg_name => g_pkg_name,
506 p_exc_name => 'OTHERS',
507 x_msg_count => x_msg_count,
508 x_msg_data => x_msg_data,
509 p_api_type => g_api_type);
510 END create_sales_tax_rules;
511
512 -- Procedure Name : sync_contract_sales_tax
513 -- Description : Sync the contract sales tax rule information with all the assets
514 -- , if the flag 'Update lines from contract header' at the header
515 -- level is checked.
516 -- Business Rules :
517 -- Parameters :
518 -- Version : 1.0
519 -- End of comments
520 PROCEDURE sync_contract_sales_tax(
521 p_api_version IN NUMBER,
522 p_init_msg_list IN VARCHAR2 DEFAULT OKC_API.G_FALSE,
523 x_return_status OUT NOCOPY VARCHAR2,
524 x_msg_count OUT NOCOPY NUMBER,
525 x_msg_data OUT NOCOPY VARCHAR2,
526 p_chr_id IN NUMBER)
527 IS
528 l_rulv_rec rulv_rec_type;
529 lx_rulv_rec rulv_rec_type;
530
531 ln_cle_id okc_k_lines_v.id%TYPE;
532
533 ln_rule_id okc_rules_v.id%TYPE;
534 lv_asset_k_rule_information5 okc_rules_v.rule_information5%TYPE;
535 l_ak_prompt varchar2(100);
536 l_rebook_yn varchar2(1) := 'N';
537 l_orig_system_id1 okc_k_lines_b.orig_system_id1%type;
538
539 lv_k_rule_information1 okc_rules_v.rule_information1%TYPE := null;
540 lv_k_rule_information2 okc_rules_v.rule_information1%TYPE := null;
541 lv_k_rule_information3 okc_rules_v.rule_information3%TYPE := null;
542 lv_k_rule_information4 okc_rules_v.rule_information4%TYPE := null;
543 lv_k_rule_information5 okc_rules_v.rule_information5%TYPE := null;
544 lv_k_rule_information6 okc_rules_v.rule_information6%TYPE := null;
545 lv_k_rule_information7 okc_rules_v.rule_information7%TYPE := null;
546 l_header_upfront_tax okc_rules_v.rule_information1%TYPE;
547
548 l_api_name CONSTANT VARCHAR2(30) := 'SYNC_CONTRACT_SALES_TAX';
549
550 CURSOR get_contract_sales_tax_info(p_chr_id okc_k_headers_b.id%TYPE) IS
551 SELECT rul.rule_information1, rul.rule_information3, rul.rule_information4,
552 rul.rule_information5, rul.rule_information6, rul.rule_information7
553 FROM OKC_RULES_V rul,
554 OKC_RULE_GROUPS_V rgp
555 WHERE rul.rgp_id = rgp.id
556 AND rgp.dnz_chr_id = p_chr_id
557 AND rgp.cle_id is NULL
558 AND rgp.rgd_code = 'LAHDTX'
559 AND rul.rule_information_category = 'LASTCL';
560
561 CURSOR get_contract_lines(p_chr_id okc_k_headers_b.id%TYPE) IS
562 SELECT cle.id
563 FROM OKC_K_LINES_V cle,
564 OKC_LINE_STYLES_V lse
565 WHERE cle.lse_id = lse.id
566 AND lse.lty_code = 'FREE_FORM1'
567 AND lse.lse_type = 'TLS'
568 AND cle.dnz_chr_id = p_chr_id;
569 -- AND cle.orig_system_id1 IS NULL; -- for rebook check
570
571 CURSOR get_rebook_contract_csr(p_chr_id okc_k_headers_b.id%TYPE) IS
572 select 'Y'
573 from okc_k_headers_b
574 where id = p_chr_id
575 and nvl(orig_system_source_code,'XXX')='OKL_REBOOK';
576
577 CURSOR get_asset_sales_tax_info(p_chr_id okc_k_headers_b.id%TYPE,
578 p_cle_id okc_k_lines_v.id%TYPE) IS
579 SELECT rul.id, rul.rule_information5, cle.ORIG_SYSTEM_ID1
580 FROM OKC_RULES_V rul,
581 OKC_RULE_GROUPS_V rgp,
582 okc_k_lines_b cle
583 WHERE rul.rgp_id = rgp.id
584 AND rgp.dnz_chr_id = p_chr_id
585 AND rgp.cle_id = p_cle_id
586 AND rgp.rgd_code = 'LAASTX'
587 AND rul.rule_information_category = 'LAASTX'
588 AND cle.id = rgp.cle_id
589 AND cle.id = p_cle_id;
590
591 CURSOR get_sales_tax_prc_info(p_chr_id okc_k_headers_b.id%TYPE) IS
592 SELECT rul.rule_information1, rul.rule_information2,
593 rul.rule_information3, rul.rule_information4, rul.rule_information4
594 FROM OKC_RULES_V rul,
595 OKC_RULE_GROUPS_V rgp
596 WHERE rul.rgp_id = rgp.id
597 AND rgp.dnz_chr_id = p_chr_id
598 AND rgp.cle_id is NULL
599 AND rgp.rgd_code = 'LAHDTX'
600 AND rul.rule_information_category = 'LASTPR';
601
602 CURSOR get_segment_prompt(p_ri okc_rules_b.rule_information1%TYPE) IS
603 select col.form_left_prompt
604 from fnd_descr_flex_col_usage_vl col,
605 okc_rule_defs_v rdef
606 where col.application_id = 540
607 and col.application_id = rdef.application_id
608 and col.descriptive_flexfield_name=rdef.descriptive_flexfield_name
609 and col.descriptive_flex_context_code=rdef.rule_code
610 and rdef.rule_code = 'LASTPR'
611 and col.application_column_name = p_ri;
612
613 BEGIN
614 IF (G_DEBUG_ENABLED = 'Y') THEN
615 G_IS_DEBUG_STATEMENT_ON := OKL_DEBUG_PUB.CHECK_LOG_ON(G_MODULE, FND_LOG.LEVEL_STATEMENT);
616 END IF;
617
618 x_return_status := OKL_API.G_RET_STS_SUCCESS;
619
620 -- Bug 5129446
621 /*
622 l_upfront_tax_yn := 'N';
623 OPEN l_tax_system_info;
624 FETCH l_tax_system_info INTO l_upfront_tax_yn;
625 CLOSE l_tax_system_info; */
626
627 IF okl_context.get_okc_org_id IS NULL THEN
628 okl_context.set_okc_org_context(p_chr_id => p_chr_id);
629 END IF;
630 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
631 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'sync here1');
632 END IF;
633 -- call START_ACTIVITY to create savepoint, check compatibility
634 -- and initialize message list
635 x_return_status := OKL_API.START_ACTIVITY (
636 l_api_name
637 ,p_init_msg_list
638 ,g_api_type
639 ,x_return_status);
640
641 -- check if activity started successfully
642 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
643 RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
644 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
645 RAISE OKL_API.G_EXCEPTION_ERROR;
646 END IF;
647
648 -- Bug 5129446
649 /*
650 OPEN get_sales_tax_prc_info(p_chr_id);
651 FETCH get_sales_tax_prc_info into lv_k_rule_information1,
652 lv_k_rule_information2,
653 lv_k_rule_information3,
654 lv_k_rule_information4;
655 CLOSE get_sales_tax_prc_info;
656 l_header_upfront_tax := lv_k_rule_information1;
657
658 If((l_upfront_tax_yn = 'Y') AND l_header_upfront_tax is null) Then
659 x_return_status := OKL_API.G_RET_STS_ERROR;
660 OKL_API.set_message(
661 p_app_name => G_APP_NAME,
662 p_msg_name => 'OKL_QA_ST_HEADER_TAX');
663 raise OKL_API.G_EXCEPTION_ERROR;
664 End If;
665
666 --If(lv_k_rule_information1 = G_BILLED and (lv_k_rule_information2 is null or lv_k_rule_information2 = OKL_API.G_MISS_CHAR)) Then
667 If((l_upfront_tax_yn = 'Y') AND (lv_k_rule_information2 is null) or (lv_k_rule_information2 = OKL_API.G_MISS_CHAR)) Then
668
669 OPEN get_segment_prompt('RULE_INFORMATION2');
670 FETCH get_segment_prompt into l_ak_prompt;
671 CLOSE get_segment_prompt;
672
673 x_return_status := OKL_API.g_ret_sts_error;
674 OKL_API.SET_MESSAGE( p_app_name => g_app_name
675 , p_msg_name => 'OKL_REQUIRED_VALUE'
676 , p_token1 => 'COL_NAME'
677 , p_token1_value => l_ak_prompt
678 );
679 raise OKL_API.G_EXCEPTION_ERROR;
680
681 --ElsIf(lv_k_rule_information1 = G_FINANCED and (lv_k_rule_information3 is null or lv_k_rule_information3 = OKL_API.G_MISS_CHAR)) Then
682 ElsIf((l_upfront_tax_yn) = 'Y' AND (lv_k_rule_information3 is null) or (lv_k_rule_information3 = OKL_API.G_MISS_CHAR)) Then
683
684 OPEN get_segment_prompt('RULE_INFORMATION3');
685 FETCH get_segment_prompt into l_ak_prompt;
686 CLOSE get_segment_prompt;
687
688 x_return_status := OKL_API.g_ret_sts_error;
689 OKL_API.SET_MESSAGE( p_app_name => g_app_name
690 , p_msg_name => 'OKL_REQUIRED_VALUE'
691 , p_token1 => 'COL_NAME'
692 , p_token1_value => l_ak_prompt
693 );
694 raise OKL_API.G_EXCEPTION_ERROR;
695
696 --ElsIf(lv_k_rule_information1 = G_CAPITALIZED and (lv_k_rule_information4 is null or lv_k_rule_information4 = OKL_API.G_MISS_CHAR)) Then
697 ElsIf((l_upfront_tax_yn = 'Y') AND (lv_k_rule_information4 is null) or (lv_k_rule_information4 = OKL_API.G_MISS_CHAR)) Then
698
699 OPEN get_segment_prompt('RULE_INFORMATION4');
700 FETCH get_segment_prompt into l_ak_prompt;
701 CLOSE get_segment_prompt;
702
703 x_return_status := OKL_API.g_ret_sts_error;
704 OKL_API.SET_MESSAGE( p_app_name => g_app_name
705 , p_msg_name => 'OKL_REQUIRED_VALUE'
706 , p_token1 => 'COL_NAME'
707 , p_token1_value => l_ak_prompt
708 );
709 raise OKL_API.G_EXCEPTION_ERROR;
710
711 End If;
712 */
713
714 -- get the contract header sales tax info to map to line sales tax
715 -- Also, get 'update line from contract header ' flag to check whether to update
716 -- with contract sales tax info
717
718 OPEN get_contract_sales_tax_info(p_chr_id);
719 FETCH get_contract_sales_tax_info into lv_k_rule_information1,
720 lv_k_rule_information3,
721 lv_k_rule_information4,
722 lv_k_rule_information5,
723 lv_k_rule_information6,
724 lv_k_rule_information7;
725 IF (get_contract_sales_tax_info%NOTFOUND) THEN
726 RETURN;
727 END IF;
728 CLOSE get_contract_sales_tax_info;
729
730 IF(NOT(nvl(lv_k_rule_information1,'N') = 'Y')) THEN
731 OKL_API.END_ACTIVITY (x_msg_count => x_msg_count,
732 x_msg_data => x_msg_data);
733 RETURN;
734 END IF;
735
736 l_rebook_yn := 'N';
737 OPEN get_rebook_contract_csr(p_chr_id => p_chr_id);
738 FETCH get_rebook_contract_csr into l_rebook_yn;
739 CLOSE get_rebook_contract_csr;
740
741 --- get all the contract lines and create/update
742 -- the lines with contract sales tax info
743 FOR r_get_contract_lines IN get_contract_lines(p_chr_id => p_chr_id) LOOP
744
745 lv_asset_k_rule_information5 := null; -- Reset the value
746
747 -- get 'update from contract' flag
748 OPEN get_asset_sales_tax_info(p_chr_id => p_chr_id,
749 p_cle_id => r_get_contract_lines.id);
750 FETCH get_asset_sales_tax_info into ln_rule_id, lv_asset_k_rule_information5, l_orig_system_id1;
751 CLOSE get_asset_sales_tax_info;
752
753 IF( (l_rebook_yn = 'Y' AND l_orig_system_id1 IS NULL) OR (l_rebook_yn = 'N')) THEN
754
755 IF (lv_asset_k_rule_information5 IS NOT NULL AND
756 lv_asset_k_rule_information5 = 'Y') THEN
757
758 l_rulv_rec.id := ln_rule_id;
759 l_rulv_rec.rule_information6 := lv_k_rule_information3;
760 l_rulv_rec.rule_information7 := lv_k_rule_information4;
761 l_rulv_rec.rule_information8 := lv_k_rule_information5;
762 l_rulv_rec.rule_information9 := lv_k_rule_information6;
763 l_rulv_rec.rule_information10 := lv_k_rule_information7;
764 l_rulv_rec.rule_information11 := l_header_upfront_tax;
765
766 OKL_RULE_PUB.update_rule(
767 p_api_version => p_api_version,
768 p_init_msg_list => p_init_msg_list,
769 x_return_status => x_return_status,
770 x_msg_count => x_msg_count,
771 x_msg_data => x_msg_data,
772 p_rulv_rec => l_rulv_rec,
773 x_rulv_rec => lx_rulv_rec);
774
775 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
776 RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
777 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
778 RAISE OKL_API.G_EXCEPTION_ERROR;
779 END IF;
780
781 END IF;
782
783 END IF; -- close of rebook check
784
785 END LOOP;
786
787 OKL_API.END_ACTIVITY (x_msg_count => x_msg_count,
788 x_msg_data => x_msg_data);
789 EXCEPTION
790 WHEN OKL_API.G_EXCEPTION_ERROR THEN
791 IF get_contract_sales_tax_info%ISOPEN THEN
792 CLOSE get_contract_sales_tax_info;
793 END IF;
794 IF get_contract_lines%ISOPEN THEN
795 CLOSE get_contract_lines;
796 END IF;
797 IF get_asset_sales_tax_info%ISOPEN THEN
798 CLOSE get_asset_sales_tax_info;
799 END IF;
800 x_return_status := OKL_API.HANDLE_EXCEPTIONS(
801 l_api_name,
802 g_pkg_name,
803 'OKL_API.G_RET_STS_ERROR',
804 x_msg_count,
805 x_msg_data,
806 g_api_type);
807 WHEN OKL_API.G_EXCEPTION_UNEXPECTED_ERROR THEN
808 IF get_contract_sales_tax_info%ISOPEN THEN
809 CLOSE get_contract_sales_tax_info;
810 END IF;
811 IF get_contract_lines%ISOPEN THEN
812 CLOSE get_contract_lines;
813 END IF;
814 IF get_asset_sales_tax_info%ISOPEN THEN
815 CLOSE get_asset_sales_tax_info;
816 END IF;
817 IF l_tax_system_info%ISOPEN THEN
818 CLOSE l_tax_system_info;
819 END IF;
820 x_return_status :=OKL_API.HANDLE_EXCEPTIONS(
821 l_api_name,
822 g_pkg_name,
823 'OKL_API.G_RET_STS_UNEXP_ERROR',
824 x_msg_count,
825 x_msg_data,
826 g_api_type);
827 WHEN OTHERS THEN
828 IF get_contract_sales_tax_info%ISOPEN THEN
829 CLOSE get_contract_sales_tax_info;
830 END IF;
831 IF get_contract_lines%ISOPEN THEN
832 CLOSE get_contract_lines;
833 END IF;
834 IF get_asset_sales_tax_info%ISOPEN THEN
835 CLOSE get_asset_sales_tax_info;
836 END IF;
837 IF l_tax_system_info%ISOPEN THEN
838 CLOSE l_tax_system_info;
839 END IF;
840 x_return_status :=OKL_API.HANDLE_EXCEPTIONS(
841 l_api_name,
842 g_pkg_name,
843 'OTHERS',
844 x_msg_count,
845 x_msg_data,
846 g_api_type);
847 END sync_contract_sales_tax;
848
849 -- Main Sales Tax Procedures
850 -- Procedure create/update transaction records for pre-booking
851 -- and pre-rebooking processes
852 Procedure populate_transaction(
853 p_api_version IN NUMBER,
854 p_init_msg_list IN VARCHAR2 DEFAULT Okl_Api.G_FALSE,
855 p_contract_id IN okc_k_headers_all_b.id%TYPE,
856 p_transaction_type IN okl_trx_types_tl.name%TYPE,
857 p_transaction_id IN okl_trx_contracts_all.id%TYPE DEFAULT NULL,
858 p_source_trx_id IN okl_trx_contracts_all.source_trx_id%TYPE DEFAULT NULL,
859 p_source_trx_type IN okl_trx_contracts_all.source_trx_type%TYPE DEFAULT NULL,
860 --Bug# 6619311
861 p_transaction_amount IN okl_trx_contracts_all.amount%TYPE DEFAULT NULL,
862 x_transaction_id OUT NOCOPY okl_trx_contracts_all.id%TYPE,
863 x_trxh_out_rec OUT NOCOPY Okl_Trx_Contracts_Pvt.tcnv_rec_type, -- R12 Change
864 x_return_status OUT NOCOPY VARCHAR2,
865 x_msg_count OUT NOCOPY NUMBER,
866 x_msg_data OUT NOCOPY VARCHAR2) IS
867
868 -- Define PL/SQL Records and Tables
869 l_trxH_in_rec Okl_Trx_Contracts_Pvt.tcnv_rec_type;
870 l_trxH_out_rec Okl_Trx_Contracts_Pvt.tcnv_rec_type;
871
872 -- Define variables
873 l_sysdate DATE;
874 l_sysdate_trunc DATE;
875 l_return_status VARCHAR2(1) := Okl_Api.G_RET_STS_SUCCESS;
876 l_post_to_gl_yn VARCHAR2(1);
877
878 CURSOR Transaction_Type_csr (p_transaction_type IN okl_trx_types_v.name%TYPE )
879 IS
880 SELECT id
881 FROM okl_trx_types_tl
882 WHERE name = p_transaction_type
883 AND language = 'US';
884
885 Cursor trx_csr( khrId NUMBER, tcntype VARCHAR2 ) is
886 Select txh.ID HeaderTransID,
887 txh.date_transaction_occurred date_transaction_occurred
888 From okl_trx_contracts txh
889 Where txh.khr_id = khrId
890 --rkuttiya added for 12.1.1 Multi GAAP
891 AND txh.representation_type = 'PRIMARY'
892 --
893 AND txh.tcn_type = tcntype;
894
895 i NUMBER;
896 l_amount NUMBER;
897 l_init_msg_list VARCHAR2(1) := OKL_API.G_FALSE;
898 l_msg_count NUMBER;
899 l_msg_data VARCHAR2(2000);
900 l_currency_code okl_txl_cntrct_lns.currency_code%TYPE;
901 l_fnd_profile VARCHAR2(256);
902 l_cust_trx_type_id NUMBER;
903 l_has_trans VARCHAR2(1);
904
905 l_msg_index_out NUMBER; --TBR
906
907 -- Define constants
908 l_api_name CONSTANT VARCHAR(30) := 'POPULATE_TRANSACTION';
909 l_api_version CONSTANT NUMBER := 1.0;
910
911 -- Cursor Types
912 l_Trx_Type_rec Transaction_Type_csr%ROWTYPE;
913 l_fnd_rec fnd_lookups_csr%ROWTYPE;
914 l_fnd_rec1 fnd_lookups_csr%ROWTYPE;
915 l_trx_rec trx_csr%ROWTYPE;
916
917 p_chr_id VARCHAR2(2000) := TO_CHAR(p_contract_id);
918 l_transaction_type VARCHAR2(256) := p_transaction_type;
919 l_transaction_id NUMBER;
920
921 --Bug# 3153003
922 l_upd_trxH_rec Okl_Trx_Contracts_Pvt.tcnv_rec_type;
923 lx_upd_trxH_rec Okl_Trx_Contracts_Pvt.tcnv_rec_type;
924
925 pop_trx_failed exception;
926
927 --Added by dpsingh for LE uptake
928 CURSOR contract_num_csr (p_ctr_id1 NUMBER) IS
929 SELECT contract_number
930 FROM OKC_K_HEADERS_B
931 WHERE id = p_ctr_id1;
932
933 l_cntrct_number OKC_K_HEADERS_B.CONTRACT_NUMBER%TYPE;
934 l_legal_entity_id NUMBER;
935
936 -- R12 - START
937
938 l_func_curr_code OKL_K_HEADERS_FULL_V.CURRENCY_CODE%TYPE;
939 l_chr_curr_code OKL_K_HEADERS_FULL_V.CURRENCY_CODE%TYPE;
940 x_currency_conversion_rate okl_k_headers_full_v.currency_conversion_rate%TYPE;
941 x_currency_conversion_type okl_k_headers_full_v.currency_conversion_type%TYPE;
942 x_currency_conversion_date okl_k_headers_full_v.currency_conversion_date%TYPE;
943
944 -- R12 - END
945
946
947
948 BEGIN
949
950 okl_debug_pub.logmessage('OKL: POP TRX : START');
951 okl_debug_pub.logmessage('OKL: POP TRX : p_contract_id: ' || p_contract_id);
952 okl_debug_pub.logmessage('OKL: POP TRX : p_transaction_type: ' || p_transaction_type);
953 okl_debug_pub.logmessage('OKL: POP TRX : p_transaction_id: ' || p_transaction_id);
954 okl_debug_pub.logmessage('OKL: POP TRX : p_source_trx_id: ' || p_source_trx_id);
955 okl_debug_pub.logmessage('OKL: POP TRX : p_source_trx_type: ' || p_source_trx_type);
956
957 IF (G_DEBUG_ENABLED = 'Y') THEN
958 G_IS_DEBUG_STATEMENT_ON := OKL_DEBUG_PUB.CHECK_LOG_ON(G_MODULE, FND_LOG.LEVEL_STATEMENT);
959 END IF;
960
961 x_return_status := Okl_Api.G_RET_STS_SUCCESS;
962 l_sysdate := SYSDATE;
963 l_sysdate_trunc := trunc(SYSDATE);
964 i := 0;
965
966 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
967 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: Populate Trx Procedure : START ');
968 END IF;
969
970
971 -- R12 - START
972
973 -- Get product_id
974 OPEN Product_csr (p_contract_id);
975 FETCH Product_csr INTO g_Product_rec;
976 IF Product_csr%NOTFOUND THEN
977 Okl_Api.SET_MESSAGE(G_APP_NAME, G_REQUIRED_VALUE,G_COL_NAME_TOKEN, 'Product');
978 CLOSE Product_csr;
979 RAISE Okl_Api.G_EXCEPTION_ERROR;
980 END IF;
981 CLOSE Product_csr;
982
983 l_chr_curr_code := g_Product_rec.CURRENCY_CODE;
984 l_func_curr_code := OKC_CURRENCY_API.GET_OU_CURRENCY(g_Product_rec.authoring_org_id);
985
986 x_currency_conversion_rate := NULL;
987 x_currency_conversion_type := NULL;
988 x_currency_conversion_date := NULL;
989
990 If ( ( l_func_curr_code IS NOT NULL) AND
991 ( l_chr_curr_code <> l_func_curr_code ) ) Then
992
993 x_currency_conversion_type := g_Product_rec.currency_conversion_type;
994 x_currency_conversion_date := g_Product_rec.start_date;
995
996 If ( g_Product_rec.currency_conversion_type = 'User') Then
997 x_currency_conversion_rate := g_Product_rec.currency_conversion_rate;
998 x_currency_conversion_date := g_Product_rec.currency_conversion_date;
999 Else
1000 x_currency_conversion_rate := okl_accounting_util.get_curr_con_rate(
1001 p_from_curr_code => l_chr_curr_code,
1002 p_to_curr_code => l_func_curr_code,
1003 p_con_date => g_Product_rec.start_date,
1004 p_con_type => g_Product_rec.currency_conversion_type);
1005
1006 End If;
1007
1008 End If;
1009
1010 l_currency_code := g_Product_rec.currency_code;
1011 l_trxH_in_rec.pdt_id := g_Product_rec.product_id;
1012 l_trxH_in_rec.currency_code := l_currency_code;
1013 l_trxH_in_rec.currency_conversion_rate := x_currency_conversion_rate;
1014 l_trxH_in_rec.currency_conversion_type := x_currency_conversion_type;
1015 l_trxH_in_rec.currency_conversion_date := x_currency_conversion_date;
1016
1017 -- R12 - END
1018
1019
1020
1021 -- Validate passed parameters
1022 IF ( p_contract_id = Okl_Api.G_MISS_NUM )
1023 OR ( p_contract_id IS NULL ) THEN
1024 --Okl_Api.Set_Message(G_APP_NAME, G_REQUIRED_VALUE,G_COL_NAME_TOKEN, 'contract');
1025 Okl_Api.Set_Message(G_APP_NAME, 'OKL_LA_ST_K_ID_ERROR');
1026 RAISE pop_trx_failed;
1027 END IF;
1028
1029 IF ( p_transaction_type = Okl_Api.G_MISS_CHAR )
1030 OR ( p_transaction_type IS NULL ) THEN
1031 --Okl_Api.Set_Message(G_APP_NAME, G_REQUIRED_VALUE,G_COL_NAME_TOKEN, l_transaction_type);
1032 Okl_Api.Set_Message(G_APP_NAME, 'OKL_LA_ST_TRX_TYPE_ERROR');
1033 RAISE pop_trx_failed;
1034 END IF;
1035
1036 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
1037 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: Populate Trx Procedure : before Transaction_Type_csr ');
1038 END IF;
1039 -- Check Transaction_Type
1040 OPEN Transaction_Type_csr(l_transaction_type);
1041 FETCH Transaction_Type_csr INTO l_Trx_Type_rec;
1042 IF Transaction_Type_csr%NOTFOUND THEN
1043 Okl_Api.SET_MESSAGE(G_APP_NAME, G_INVALID_VALUE,'TRANSACTION_TYPE', l_transaction_type);
1044 /*OKL_API.SET_MESSAGE(
1045 p_app_name => G_APP_NAME,
1046 p_msg_name => G_INVALID_VALUE,
1047 p_token1 => 'COL_NAME',
1048 p_token1_value => 'TRANSACTION_TYPE');*/
1049
1050 CLOSE Transaction_Type_csr;
1051 RAISE pop_trx_failed;
1052 END IF;
1053 CLOSE Transaction_Type_csr;
1054
1055 okl_debug_pub.logmessage('OKL: POP TRX : Transaction_Type_csr.id: ' || l_Trx_Type_rec.id);
1056
1057 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
1058 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: Populate Trx Procedure : before fnd_lookups_csr ');
1059 END IF;
1060
1061 OPEN fnd_lookups_csr('OKL_TCN_TYPE', l_transaction_type);
1062 FETCH fnd_lookups_csr INTO l_fnd_rec;
1063
1064 IF fnd_lookups_csr%NOTFOUND THEN
1065 Okl_Api.SET_MESSAGE(G_APP_NAME, G_INVALID_VALUE,'TRANSACTION_TYPE', l_transaction_type);
1066 CLOSE fnd_lookups_csr;
1067 RAISE pop_trx_failed;
1068 END IF;
1069 CLOSE fnd_lookups_csr;
1070
1071 okl_debug_pub.logmessage('OKL: POP TRX : transaction type: ' || l_transaction_type);
1072 okl_debug_pub.logmessage('OKL: POP TRX : fnd_lookups_csr: Description ' || l_fnd_rec.description);
1073 okl_debug_pub.logmessage('OKL: POP TRX : fnd_lookups_csr: lookup_code ' || l_fnd_rec.lookup_code);
1074
1075
1076 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
1077 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: Populate Trx Procedure : before trx_csr ');
1078 END IF;
1079
1080 -- gboomina Bug 6487183 - Start
1081 -- For Upfront Tax transaction always create transaction header record
1082 IF (l_transaction_type <> 'Upfront Tax') THEN
1083 OPEN trx_csr(p_contract_id,l_fnd_rec.lookup_code);
1084 FETCH trx_csr INTO l_trx_rec;
1085 IF trx_csr%NOTFOUND THEN -- While activation, create a new trans always.
1086 l_has_trans := OKL_API.G_FALSE;
1087 okl_debug_pub.logmessage('OKL: POP TRX : No Existing TRX: '||l_fnd_rec.lookup_code);
1088 Else
1089 l_has_trans := OKL_API.G_TRUE;
1090 okl_debug_pub.logmessage('OKL: POP TRX : TRX Exists: '|| l_fnd_rec.lookup_code);
1091 END IF;
1092 CLOSE trx_csr;
1093 ELSE
1094 l_has_trans := OKL_API.G_FALSE;
1095 END IF;
1096 -- gboomina Bug 6487183 - End
1097
1098 l_trxH_in_rec.khr_id := p_contract_id;
1099 l_trxH_in_rec.source_trx_id := p_source_trx_id;
1100 l_trxH_in_rec.source_trx_type := p_source_trx_type;
1101 --l_trxH_in_rec.date_transaction_occurred := sysdate; -- OKL.H Code
1102 l_trxH_in_rec.date_transaction_occurred := g_Product_rec.start_date; -- R12 Change
1103 l_trxH_in_rec.try_id := l_Trx_Type_rec.id;
1104 l_trxH_in_rec.tcn_type := l_fnd_rec.lookup_code; --'BKG'/'SYND'/'TRBK';
1105
1106 --Bug# 6619311
1107 IF p_transaction_amount IS NOT NULL THEN
1108 l_trxH_in_rec.amount := p_transaction_amount;
1109 END IF;
1110
1111 okl_debug_pub.logmessage('OKL: POP TRX : l_trxH_in_rec.khr_id : '|| l_trxH_in_rec.khr_id);
1112 okl_debug_pub.logmessage('OKL: POP TRX : l_trxH_in_rec.source_trx_id : '|| l_trxH_in_rec.source_trx_id);
1113 okl_debug_pub.logmessage('OKL: POP TRX : l_trxH_in_rec.source_trx_type : '|| l_trxH_in_rec.source_trx_type);
1114 okl_debug_pub.logmessage('OKL: POP TRX : l_trxH_in_rec.date_transaction_occurred : '|| l_trxH_in_rec.date_transaction_occurred);
1115 okl_debug_pub.logmessage('OKL: POP TRX : l_trxH_in_rec.try_id : '|| l_trxH_in_rec.try_id);
1116 okl_debug_pub.logmessage('OKL: POP TRX : l_trxH_in_rec.tcn_type : '|| l_trxH_in_rec.tcn_type);
1117 okl_debug_pub.logmessage('OKL: POP TRX : l_trxH_in_rec.amount : '|| l_trxH_in_rec.amount);
1118
1119 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
1120 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: Populate Trx Procedure : transaction type '||l_transaction_type);
1121 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: Populate Trx Procedure : try_id '||l_trxH_in_rec.try_id);
1122 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: Populate Trx Procedure : tcn_type '||l_trxH_in_rec.tcn_type);
1123 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: Populate Trx Procedure : l_has_trans '||l_has_trans);
1124 END IF;
1125
1126 If ( l_has_trans = OKL_API.G_FALSE ) Then
1127
1128 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
1129 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: Populate Trx Procedure : before fnd_lookups_csr ');
1130 END IF;
1131
1132 -- The followinf if segment ensures that Upfront Tax transaction is created
1133 -- with 'Processed' status
1134 IF (l_transaction_type = 'Upfront Tax')
1135 THEN
1136 OPEN fnd_lookups_csr('OKL_TRANSACTION_STATUS', 'Processed');
1137 ELSE
1138 OPEN fnd_lookups_csr('OKL_TRANSACTION_STATUS', 'Entered');
1139 END IF;
1140 FETCH fnd_lookups_csr INTO l_fnd_rec;
1141 IF fnd_lookups_csr%NOTFOUND THEN
1142 Okl_Api.SET_MESSAGE(G_APP_NAME, G_INVALID_VALUE,G_COL_NAME_TOKEN,l_transaction_type);
1143 CLOSE fnd_lookups_csr;
1144 RAISE pop_trx_failed;
1145 END IF;
1146 CLOSE fnd_lookups_csr;
1147
1148 l_trxH_in_rec.tsu_code := l_fnd_rec.lookup_code;
1149 l_trxH_in_rec.description := l_fnd_rec.description;
1150
1151 okl_debug_pub.logmessage('OKL: POP TRX : l_trxH_in_rec.tsu_code : '|| l_trxH_in_rec.tsu_code);
1152 okl_debug_pub.logmessage('OKL: POP TRX : l_trxH_in_rec.description : '|| l_trxH_in_rec.description);
1153
1154
1155 --Added by dpsingh for LE Uptake
1156 l_legal_entity_id := OKL_LEGAL_ENTITY_UTIL.get_khr_le_id(p_contract_id) ;
1157 IF l_legal_entity_id IS NOT NULL THEN
1158 l_trxH_in_rec.legal_entity_id := l_legal_entity_id;
1159 ELSE
1160 -- get the contract number
1161 OPEN contract_num_csr(p_contract_id);
1162 FETCH contract_num_csr INTO l_cntrct_number;
1163 CLOSE contract_num_csr;
1164 Okl_Api.set_message(p_app_name => g_app_name,
1165 p_msg_name => 'OKL_LE_NOT_EXIST_CNTRCT',
1166 p_token1 => 'CONTRACT_NUMBER',
1167 p_token1_value => l_cntrct_number);
1168 RAISE OKL_API.G_EXCEPTION_ERROR;
1169 END IF;
1170 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
1171 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT
1172 , G_MODULE
1173 ,'OKL: Populate Trx Procedure : before Okl_Trx_Contracts_Pub.create_trx_contracts ');
1174 END IF;
1175
1176 -- Create Transaction Header, Lines
1177 Okl_Trx_Contracts_Pub.create_trx_contracts(
1178 p_api_version => p_api_version
1179 ,p_init_msg_list => p_init_msg_list
1180 ,x_return_status => x_return_status
1181 ,x_msg_count => x_msg_count
1182 ,x_msg_data => x_msg_data
1183 ,p_tcnv_rec => l_trxH_in_rec
1184 ,x_tcnv_rec => l_trxH_out_rec);
1185
1186 okl_debug_pub.logmessage('OKL: POP TRX : return status '||x_return_status);
1187
1188 IF (x_return_status <> Okl_Api.G_RET_STS_SUCCESS) THEN
1189 RAISE pop_trx_failed;
1190 END IF;
1191
1192 IF ((l_trxH_out_rec.id = OKL_API.G_MISS_NUM) OR
1193 (l_trxH_out_rec.id IS NULL) ) THEN
1194 OKL_API.set_message(G_APP_NAME, G_REQUIRED_VALUE,G_COL_NAME_TOKEN,'TRANSACTION_ID');
1195 --OKL_API.set_message(G_APP_NAME, 'Header Transaction Id is null or invalid');
1196 RAISE pop_trx_failed;
1197 END IF;
1198
1199 l_fnd_rec := null;
1200
1201 -- outbound transaction id
1202 x_transaction_id := l_trxH_out_rec.id;
1203 x_trxh_out_rec := l_trxH_out_rec; -- R12 Change
1204
1205 okl_debug_pub.logmessage('OKL: POP TRX : l_trxH_out_rec.id : '|| l_trxH_out_rec.id);
1206 okl_debug_pub.logmessage('OKL: POP TRX : l_trxH_out_rec.description : '|| l_trxH_out_rec.description);
1207
1208 okl_debug_pub.logmessage('OKL: POP TRX : try id '||l_trxH_out_rec.TRY_ID);
1209 okl_debug_pub.logmessage('OKL: POP TRX : transaction type '||l_trxH_out_rec.TCN_TYPE);
1210 okl_debug_pub.logmessage('OKL: POP TRX : tsu code '||l_trxH_out_rec.TSU_CODE);
1211
1212 ELSE
1213
1214 --if transaction exists change the date transaction occured
1215 l_upd_trxH_rec.id := l_trx_rec.HeaderTransID;
1216 l_upd_trxH_rec.date_transaction_occurred := l_trx_rec.date_transaction_occurred;
1217 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
1218 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: Populate Trx Procedure : transaction ID '||l_trx_rec.HeaderTransID);
1219 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: Populate Trx Procedure : before fnd_lookups_csr ');
1220 END IF;
1221
1222 OPEN fnd_lookups_csr('OKL_TRANSACTION_STATUS', 'Entered');
1223 FETCH fnd_lookups_csr INTO l_fnd_rec;
1224 IF fnd_lookups_csr%NOTFOUND THEN
1225 Okl_Api.SET_MESSAGE(G_APP_NAME, G_INVALID_VALUE,G_COL_NAME_TOKEN,l_transaction_type);
1226 --Okl_Api.SET_MESSAGE(G_APP_NAME, 'Cannot Find Transaction Status');
1227 CLOSE fnd_lookups_csr;
1228 RAISE pop_trx_failed;
1229 END IF;
1230 CLOSE fnd_lookups_csr;
1231
1232 l_upd_trxH_rec.tsu_code := l_fnd_rec.lookup_code;
1233
1234 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
1235 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: Populate Trx Procedure : before Okl_Trx_Contracts_Pub.update_trx_contracts ');
1236 END IF;
1237
1238 Okl_Trx_Contracts_Pub.update_trx_contracts(
1239 p_api_version => p_api_version
1240 ,p_init_msg_list => p_init_msg_list
1241 ,x_return_status => x_return_status
1242 ,x_msg_count => x_msg_count
1243 ,x_msg_data => x_msg_data
1244 ,p_tcnv_rec => l_upd_trxH_rec
1245 ,x_tcnv_rec => lx_upd_trxH_rec);
1246
1247 IF (x_return_status <> Okl_Api.G_RET_STS_SUCCESS) THEN
1248 RAISE pop_trx_failed;
1249 END IF;
1250
1251 IF ((lx_upd_trxH_rec.id = OKL_API.G_MISS_NUM) OR
1252 (lx_upd_trxH_rec.id IS NULL) ) THEN
1253 OKL_API.set_message(G_APP_NAME, G_REQUIRED_VALUE,G_COL_NAME_TOKEN,'TRANSACTION_ID');
1254 --OKL_API.set_message(G_APP_NAME, 'TRANSACTION_ID Missing');
1255 RAISE pop_trx_failed;
1256 END IF;
1257
1258 -- outbound transaction id
1259 x_transaction_id := l_trx_rec.HeaderTransID;
1260 x_trxh_out_rec := lx_upd_trxH_rec; -- R12 Change
1261
1262 okl_debug_pub.logmessage('OKL: POP TRX : return status '||x_return_status);
1263 okl_debug_pub.logmessage('OKL: POP TRX : lx_upd_trxH_rec.id : '|| lx_upd_trxH_rec.id);
1264 okl_debug_pub.logmessage('OKL: POP TRX : lx_upd_trxH_rec.description : '|| lx_upd_trxH_rec.description);
1265
1266 okl_debug_pub.logmessage('OKL: POP TRX : try id '||lx_upd_trxH_rec.TRY_ID);
1267 okl_debug_pub.logmessage('OKL: POP TRX : transaction type '||lx_upd_trxH_rec.TCN_TYPE);
1268 okl_debug_pub.logmessage('OKL: POP TRX : tsu code '||lx_upd_trxH_rec.TSU_CODE);
1269
1270
1271 END IF;
1272
1273 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
1274 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: Populate Trx Procedure : END ');
1275 END IF;
1276
1277 okl_debug_pub.logmessage('OKL: POP TRX : END');
1278
1279 Exception
1280 when pop_trx_failed then
1281 x_return_status := OKL_API.G_RET_STS_ERROR;
1282
1283 END populate_transaction;
1284
1285
1286 -- Function to get total estimated financed amount
1287 Function get_financed_tax ( p_Contract_id IN NUMBER ,
1288 p_default_tax_treatment IN VARCHAR2)
1289 RETURN NUMBER
1290 IS
1291
1292 l_fee_amt NUMBER;
1293
1294 BEGIN
1295
1296 --OPEN get_fee_amt_csr(p_contract_id, p_transaction_id);
1297 IF (p_default_tax_treatment = 'FINANCE') THEN
1298 OPEN get_fee_amt_csr1(p_Contract_id, 'FINANCE');
1299 FETCH get_fee_amt_csr1 INTO l_fee_amt;
1300 CLOSE get_fee_amt_csr1;
1301 END IF;
1302 IF (p_default_tax_treatment = 'BILLED') THEN
1303 OPEN get_fee_amt_csr2(p_Contract_id,'FINANCE');
1304 FETCH get_fee_amt_csr2 INTO l_fee_amt;
1305 CLOSE get_fee_amt_csr2;
1306 END IF;
1307
1308 --Hard Code the value for the time being until tax
1309 -- APIs are ready
1310 --l_fee_amt := 50;
1311
1312 RETURN l_fee_amt;
1313
1314 END get_financed_tax;
1315
1316 -- Function to get total estimated capitalized amount
1317 Function get_capitalized_tax ( p_Contract_id IN NUMBER,
1318 p_default_tax_treatment IN VARCHAR2)
1319
1320 RETURN NUMBER
1321 IS
1322
1323 l_fee_amt NUMBER;
1324
1325 BEGIN
1326
1327 IF (p_default_tax_treatment = 'CAPITALIZE') THEN
1328 OPEN get_fee_amt_csr1 (p_Contract_id, 'CAPITALIZE');
1329 FETCH get_fee_amt_csr1 INTO l_fee_amt;
1330 CLOSE get_fee_amt_csr1;
1331 END IF;
1332 IF (p_default_tax_treatment = 'BILLED') THEN
1333 OPEN get_fee_amt_csr2(p_Contract_id, 'CAPITALIZE');
1334 FETCH get_fee_amt_csr2 INTO l_fee_amt;
1335 CLOSE get_fee_amt_csr2;
1336 END IF;
1337
1338 --Hard Code the value for the time being until tax
1339 -- APIs are ready
1340 --l_fee_amt := 50;
1341
1342 RETURN l_fee_amt;
1343
1344 END get_capitalized_tax;
1345
1346 -- R12B Authoring OA Migration
1347 -- Function to get total estimated billed amount
1348 Function get_billed_tax ( p_Contract_id IN NUMBER,
1349 p_default_tax_treatment IN VARCHAR2)
1350
1351 RETURN NUMBER
1352 IS
1353
1354 l_tax_amt NUMBER;
1355
1356 --Bug# 6668721
1357 -- This cursor gets billed upfront tax amount at contract
1358 -- header level
1359 CURSOR contract_billed_tax_csr(p_contract_id IN NUMBER) IS
1360 SELECT NVL(SUM(NVL(total_tax,0)),0)
1361 FROM okl_tax_sources txs
1362 WHERE txs.khr_id = p_contract_id
1363 AND txs.kle_id IS NULL
1364 AND txs.tax_line_status_code = 'ACTIVE'
1365 AND txs.tax_call_type_code = 'UPFRONT_TAX';
1366
1367 l_contract_billed_tax NUMBER;
1368
1369 BEGIN
1370
1371 IF (p_default_tax_treatment = 'BILLED') THEN
1372 OPEN get_fee_amt_csr1 (p_Contract_id, 'BILLED');
1373 FETCH get_fee_amt_csr1 INTO l_tax_amt;
1374 CLOSE get_fee_amt_csr1;
1375 END IF;
1376 IF (p_default_tax_treatment IN ('CAPITALIZE','FINANCE')) THEN
1377 OPEN get_fee_amt_csr2(p_Contract_id, 'BILLED');
1378 FETCH get_fee_amt_csr2 INTO l_tax_amt;
1379 CLOSE get_fee_amt_csr2;
1380 END IF;
1381
1382 --Bug# 6939336
1383 --Bug# 6668721
1384 OPEN contract_billed_tax_csr(p_contract_id => p_contract_id);
1385 FETCH contract_billed_tax_csr INTO l_contract_billed_tax;
1386 CLOSE contract_billed_tax_csr;
1387
1388 l_tax_amt := l_tax_amt + l_contract_billed_tax;
1389 --Bug# 6668721
1390 --Bug# 6939336
1391
1392 RETURN l_tax_amt;
1393
1394 END get_billed_tax;
1395
1396 FUNCTION get_upfront_tax(p_chr_id IN NUMBER,
1397 p_tax_treatment IN VARCHAR2)
1398 RETURN NUMBER
1399 IS
1400
1401 l_tax_amt NUMBER;
1402 l_rule_info_rec rule_info_csr%ROWTYPE;
1403
1404 BEGIN
1405
1406 OPEN rule_info_csr(p_contract_id => p_chr_id);
1407 FETCH rule_info_csr INTO l_rule_info_rec;
1408 CLOSE rule_info_csr;
1409
1410 IF l_rule_info_rec.rule_information1 IS NOT NULL THEN
1411 IF (p_tax_treatment = 'CAPITALIZED') THEN
1412 l_tax_amt := get_capitalized_tax (p_contract_id => p_chr_id,
1413 p_default_tax_treatment => l_rule_info_rec.rule_information1);
1414 ELSIF (p_tax_treatment = 'FINANCED') THEN
1415 l_tax_amt := get_financed_tax (p_contract_id => p_chr_id,
1416 p_default_tax_treatment => l_rule_info_rec.rule_information1);
1417 ELSIF (p_tax_treatment = 'BILLED') THEN
1418 l_tax_amt := get_billed_tax (p_contract_id => p_chr_id,
1419 p_default_tax_treatment => l_rule_info_rec.rule_information1);
1420 END IF;
1421 END IF;
1422
1423 RETURN l_tax_amt;
1424
1425 END get_upfront_tax;
1426
1427 PROCEDURE update_fee(
1428 p_api_version IN NUMBER,
1429 p_init_msg_list IN VARCHAR2 DEFAULT Okl_Api.G_FALSE,
1430 p_contract_id IN NUMBER,
1431 p_transaction_id IN NUMBER,
1432 p_fee_line_id IN NUMBER,
1433 p_required_feetype IN VARCHAR2,
1434 p_default_feetype IN VARCHAR2,
1435 x_return_status OUT NOCOPY VARCHAR2,
1436 x_msg_count OUT NOCOPY NUMBER,
1437 x_msg_data OUT NOCOPY VARCHAR2
1438 )
1439 IS
1440 l_fee_types_rec OKL_MAINTAIN_FEE_PVT.fee_types_rec_type;
1441 lx_fee_types_rec OKL_MAINTAIN_FEE_PVT.fee_types_rec_type;
1442
1443 l_u_line_item_tbl OKL_CONTRACT_LINE_ITEM_PVT.line_item_tbl_type;
1444 lx_u_line_item_tbl OKL_CONTRACT_LINE_ITEM_PVT.line_item_tbl_type;
1445
1446 l_c_line_item_tbl OKL_CONTRACT_LINE_ITEM_PVT.line_item_tbl_type;
1447 lx_c_line_item_tbl OKL_CONTRACT_LINE_ITEM_PVT.line_item_tbl_type;
1448
1449 l_rgpv_rec rgpv_rec_type;
1450 l_rulv_rec rulv_rec_type;
1451 l_rulv_tbl rulv_tbl_type;
1452 lx_rgpv_rec rgpv_rec_type;
1453 lx_rulv_rec rulv_rec_type;
1454 lx_rulv_tbl rulv_tbl_type;
1455
1456 l_ins_count NUMBER := 0;
1457 l_upd_count NUMBER := 0;
1458 l_del_count NUMBER := 0;
1459 l_upfront_tax_fee_amount NUMBER;
1460
1461 -- Cursor to get assets for financed fee association
1462 -- Bug# 6512668: Exclude asset lines in Abandoned status
1463 CURSOR get_asset_csr1 (p_fee_type IN VARCHAR2)
1464 IS
1465 SELECT cle.id, cle.name, cle.item_description
1466 FROM okc_k_lines_v cle,
1467 okc_rule_groups_b rg1,
1468 okc_rules_b rl1,
1469 okc_line_styles_b lse,
1470 okc_rule_groups_b rg2,
1471 okc_rules_b rl2
1472 WHERE cle.chr_ID = p_contract_id
1473 AND cle.lse_id = lse.id
1474 AND lse.lty_code = 'FREE_FORM1'
1475 AND cle.dnz_chr_id = rg1.dnz_chr_id
1476 AND cle.id = rg1.cle_id
1477 AND cle.dnz_chr_id = rl1.dnz_chr_id
1478 AND rg1.id = rl1.rgp_id
1479 AND rg1.rgd_code = 'LAASTX'
1480 AND rl1.rule_information_category = 'LAASTX'
1481 AND ( rl1.rule_information11 IS NULL
1482 OR
1483 rl1.rule_information11 = p_fee_type)
1484 AND cle.dnz_chr_id = rg2.dnz_chr_id
1485 AND cle.dnz_chr_id = rl2.dnz_chr_id
1486 AND rg2.id = rl2.rgp_id
1487 AND rg2.rgd_code = 'LAHDTX'
1488 AND rl2.rule_information_category = 'LASTPR'
1489 AND rl2.rule_information1 = p_fee_type
1490 AND cle.sts_code <> 'ABANDONED';
1491
1492 -- Cursor to get assets for fee association if T and C Tax treatment is
1493 -- 'BILLED'
1494 -- Bug# 6512668: Exclude asset lines in Abandoned status
1495 CURSOR get_asset_csr2 (p_fee_type IN VARCHAR2)
1496 IS
1497 SELECT cle.id, cle.name, cle.item_description
1498 FROM okc_k_lines_v cle,
1499 okc_rule_groups_b rg1,
1500 okc_rules_b rl1,
1501 okc_line_styles_b lse
1502 WHERE cle.dnz_chr_id = p_contract_id
1503 AND cle.lse_id = lse.id
1504 AND lse.lty_code = 'FREE_FORM1'
1505 AND cle.dnz_chr_id = rg1.dnz_chr_id
1506 AND cle.id = rg1.cle_id
1507 AND cle.dnz_chr_id = rl1.dnz_chr_id
1508 AND rg1.id = rl1.rgp_id
1509 AND rg1.rgd_code = 'LAASTX'
1510 AND rl1.rule_information_category = 'LAASTX'
1511 AND rl1.rule_information11 = p_fee_type
1512 AND cle.sts_code <> 'ABANDONED';
1513
1514 -- Cursor to get tax amounts for assets
1515 CURSOR get_asset_tax_amt_csr (asset_line_id IN NUMBER)
1516 IS
1517 SELECT NVL(SUM(NVL(total_tax,0)),0)
1518 FROM okl_tax_sources txs
1519 WHERE txs.khr_ID = p_contract_id
1520 AND txs.trx_id = p_transaction_id
1521 AND txs.kle_id = asset_line_id
1522 AND txs.tax_line_status_code = 'ACTIVE'
1523 AND txs.tax_call_type_code = 'UPFRONT_TAX';
1524
1525 -- Cursor to get fee details
1526 CURSOR l_fee_csr(p_fee_cle_id IN NUMBER) IS
1527 SELECT NVL(kle_fee.capital_amount,kle_fee.amount) amount,
1528 kle_fee.fee_type,
1529 cleb_fee.start_date,
1530 cleb_fee.end_date,
1531 cim_fee.id cim_fee_id,
1532 cim_fee.object1_id1
1533 FROM okl_k_lines kle_fee,
1534 okc_k_lines_b cleb_fee,
1535 okc_k_items cim_fee
1536 WHERE cleb_fee.id = p_fee_cle_id
1537 AND kle_fee.id = cleb_fee.id
1538 AND cim_fee.cle_id = cleb_fee.id
1539 AND cim_fee.dnz_chr_id = cleb_fee.dnz_chr_id
1540 AND cim_fee.jtot_object1_code = 'OKL_STRMTYP';
1541
1542 l_fee_rec l_fee_csr%ROWTYPE;
1543
1544 -- Cursor to get fee covered asset line
1545 -- Bug# 6512668: Exclude covered asset lines in Abandoned status
1546 CURSOR l_cov_asset_line_csr(p_chr_id IN NUMBER,
1547 p_fee_cle_id IN NUMBER,
1548 p_fin_asset_cle_id IN NUMBER) IS
1549 SELECT cleb_cov_asset.id cleb_cov_asset_id,
1550 NVL(kle_cov_asset.capital_amount,kle_cov_asset.amount) amount,
1551 cim_cov_asset.id cim_cov_asset_id
1552 FROM okc_k_lines_b cleb_cov_asset,
1553 okl_k_lines kle_cov_asset,
1554 okc_k_items cim_cov_asset
1555 WHERE cleb_cov_asset.cle_id = p_fee_cle_id
1556 AND cleb_cov_asset.dnz_chr_id = p_chr_id
1557 AND kle_cov_asset.id = cleb_cov_asset.id
1558 AND cim_cov_asset.cle_id = cleb_cov_asset.id
1559 AND cim_cov_asset.dnz_chr_id = cleb_cov_asset.dnz_chr_id
1560 AND cim_cov_asset.object1_id1 = p_fin_asset_cle_id
1561 AND cim_cov_asset.jtot_object1_code = 'OKX_COVASST'
1562 AND cleb_cov_asset.sts_code <> 'ABANDONED';
1563
1564 l_cov_asset_line_rec l_cov_asset_line_csr%ROWTYPE;
1565
1566 -- Cursor to get fee expensee
1567 CURSOR l_rul_csr(p_chr_id IN NUMBER,
1568 p_fee_cle_id IN NUMBER) IS
1569 SELECT rul_lafexp.id,
1570 rul_lafexp.rgp_id,
1571 rul_lafexp.dnz_chr_id,
1572 rul_lafexp.rule_information_category,
1573 TO_NUMBER(rul_lafexp.rule_information2) amount
1574 FROM okc_rule_groups_b rgp_lafexp,
1575 okc_rules_b rul_lafexp
1576 WHERE rgp_lafexp.dnz_chr_id = p_chr_id
1577 AND rgp_lafexp.cle_id = p_fee_cle_id
1578 AND rgp_lafexp.rgd_code = 'LAFEXP'
1579 AND rul_lafexp.rgp_id = rgp_lafexp.id
1580 AND rul_lafexp.dnz_chr_id = rgp_lafexp.dnz_chr_id
1581 AND rul_lafexp.rule_information_category = 'LAFEXP';
1582
1583 l_rul_rec l_rul_csr%ROWTYPE;
1584
1585 -- Cursor to check if sales tax fee exists
1586 -- Bug# 6512668: Exclude fee lines in Abandoned status
1587 CURSOR check_fee_csr(p_chr_id IN NUMBER,
1588 p_fee_type IN VARCHAR2 ) IS
1589 SELECT cle.id
1590 FROM okc_k_lines_b cle,
1591 okl_k_lines kle
1592 WHERE cle.id = kle.id
1593 AND cle.dnz_chr_id = p_chr_id
1594 AND kle.fee_purpose_code = 'SALESTAX'
1595 AND kle.fee_type = p_fee_type
1596 AND cle.sts_code <> 'ABANDONED';
1597
1598 l_del_fee_line_id OKC_K_LINES_B.id%TYPE;
1599 l_del_fee_types_rec OKL_MAINTAIN_FEE_PVT.fee_types_rec_type;
1600
1601 -- Bug# 6512668: Exclude asset lines in Abandoned status
1602 CURSOR l_del_cov_asset_csr1(p_chr_id IN NUMBER,
1603 p_fee_cle_id IN NUMBER) IS
1604 SELECT cleb_cov_asset.id cleb_cov_asset_id,
1605 cim_cov_asset.id cim_cov_asset_id
1606 FROM okc_k_lines_b cleb_cov_asset,
1607 okc_k_items cim_cov_asset,
1608 okc_k_lines_b cleb_fin,
1609 okc_rule_groups_b rgp,
1610 okc_rules_b rul
1611 WHERE cleb_cov_asset.cle_id = p_fee_cle_id
1612 AND cleb_cov_asset.dnz_chr_id = p_chr_id
1613 AND cim_cov_asset.cle_id = cleb_cov_asset.id
1614 AND cim_cov_asset.dnz_chr_id = cleb_cov_asset.dnz_chr_id
1615 AND cim_cov_asset.jtot_object1_code = 'OKX_COVASST'
1616 AND cleb_fin.id = cim_cov_asset.object1_id1
1617 AND cleb_fin.chr_id = cim_cov_asset.dnz_chr_id
1618 AND cleb_fin.dnz_chr_id = cim_cov_asset.dnz_chr_id
1619 AND rgp.dnz_chr_id = cleb_fin.dnz_chr_id
1620 AND rgp.cle_id = cleb_fin.id
1621 AND rgp.rgd_code = 'LAASTX'
1622 AND rul.dnz_chr_id = rgp.dnz_chr_id
1623 AND rul.rgp_id = rgp.id
1624 AND rul.rule_information_category = 'LAASTX'
1625 AND rul.rule_information11 = 'BILLED'
1626 AND cleb_fin.sts_code <> 'ABANDONED'
1627 AND cleb_cov_asset.sts_code <> 'ABANDONED';
1628
1629 -- Bug# 6512668: Exclude asset lines in Abandoned status
1630 CURSOR l_del_cov_asset_csr2(p_chr_id IN NUMBER,
1631 p_fee_cle_id IN NUMBER) IS
1632 SELECT cleb_cov_asset.id cleb_cov_asset_id,
1633 cim_cov_asset.id cim_cov_asset_id
1634 FROM okc_k_lines_b cleb_cov_asset,
1635 okc_k_items cim_cov_asset,
1636 okc_k_lines_b cleb_fin,
1637 okc_rule_groups_b rgp,
1638 okc_rules_b rul
1639 WHERE cleb_cov_asset.cle_id = p_fee_cle_id
1640 AND cleb_cov_asset.dnz_chr_id = p_chr_id
1641 AND cim_cov_asset.cle_id = cleb_cov_asset.id
1642 AND cim_cov_asset.dnz_chr_id = cleb_cov_asset.dnz_chr_id
1643 AND cim_cov_asset.jtot_object1_code = 'OKX_COVASST'
1644 AND cleb_fin.id = cim_cov_asset.object1_id1
1645 AND cleb_fin.chr_id = cim_cov_asset.dnz_chr_id
1646 AND cleb_fin.dnz_chr_id = cim_cov_asset.dnz_chr_id
1647 AND rgp.dnz_chr_id = cleb_fin.dnz_chr_id
1648 AND rgp.cle_id = cleb_fin.id
1649 AND rgp.rgd_code = 'LAASTX'
1650 AND rul.dnz_chr_id = rgp.dnz_chr_id
1651 AND rul.rgp_id = rgp.id
1652 AND rul.rule_information_category = 'LAASTX'
1653 AND NVL(rul.rule_information11,'BILLED') = 'BILLED'
1654 AND cleb_fin.sts_code <> 'ABANDONED'
1655 AND cleb_cov_asset.sts_code <> 'ABANDONED';
1656
1657 l_d_line_item_tbl OKL_CONTRACT_LINE_ITEM_PVT.line_item_tbl_type;
1658
1659 l_asset_tax_amt NUMBER;
1660 update_fee_exception exception;
1661
1662 x_msg_index_out Number;
1663
1664 BEGIN
1665 IF (G_DEBUG_ENABLED = 'Y') THEN
1666 G_IS_DEBUG_STATEMENT_ON := OKL_DEBUG_PUB.CHECK_LOG_ON(G_MODULE, FND_LOG.LEVEL_STATEMENT);
1667 END IF;
1668
1669 x_return_status := Okl_Api.G_RET_STS_SUCCESS;
1670
1671 -- If upfront tax is 'FINANCED'
1672 IF (p_required_feetype = 'FINANCE') THEN
1673 l_upfront_tax_fee_amount := get_financed_tax (p_contract_id, p_default_feetype);
1674
1675 -- Delete any Sales Tax Fee having Fee Type 'Capitalized'
1676 OPEN check_fee_csr(p_chr_id => p_contract_id,
1677 p_fee_type => 'CAPITALIZED');
1678 FETCH check_fee_csr INTO l_del_fee_line_id;
1679 CLOSE check_fee_csr;
1680
1681 -- If upfront tax is 'CAPITALIZED'
1682 ELSIF (p_required_feetype = 'CAPITALIZE') THEN
1683 l_upfront_tax_fee_amount := get_capitalized_tax (p_contract_id, p_default_feetype);
1684
1685 -- Delete any Sales Tax Fee having Fee Type 'Financed'
1686 OPEN check_fee_csr(p_chr_id => p_contract_id,
1687 p_fee_type => 'FINANCED');
1688 FETCH check_fee_csr INTO l_del_fee_line_id;
1689 CLOSE check_fee_csr;
1690 END IF;
1691
1692 IF (G_IS_DEBUG_STATEMENT_ON = true) THEN
1693 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: Update Fee Procedure: l_upfront_tax_fee_amount: '||l_upfront_tax_fee_amount);
1694 END IF;
1695
1696 IF (l_del_fee_line_id IS NOT NULL) THEN
1697 l_del_fee_types_rec.line_id := l_del_fee_line_id;
1698 l_del_fee_types_rec.dnz_chr_id := p_contract_id;
1699
1700 -- delete fee line
1701 OKL_MAINTAIN_FEE_PVT.delete_fee_type(
1702 p_api_version => p_api_version,
1703 p_init_msg_list => p_init_msg_list,
1704 x_return_status => x_return_status,
1705 x_msg_count => x_msg_count,
1706 x_msg_data => x_msg_data,
1707 p_fee_types_rec => l_del_fee_types_rec
1708 );
1709
1710 IF (G_IS_DEBUG_STATEMENT_ON = true) THEN
1711 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: Update Fee Procedure: after OKL_MAINTAIN_FEE_PVT.delete_fee_type: x_return_status '||x_return_status);
1712 END IF;
1713
1714 -- Check if the call was successful
1715 IF (x_return_status <> Okl_Api.G_RET_STS_SUCCESS) THEN
1716 RAISE update_fee_exception;
1717 END IF;
1718 END IF;
1719
1720 OPEN l_fee_csr(p_fee_cle_id => p_fee_line_id);
1721 FETCH l_fee_csr INTO l_fee_rec;
1722 CLOSE l_fee_csr;
1723
1724 IF (G_IS_DEBUG_STATEMENT_ON = true) THEN
1725 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: Update Fee Procedure: l_fee_rec.amount: '||l_fee_rec.amount);
1726 END IF;
1727
1728 IF (l_upfront_tax_fee_amount <> l_fee_rec.amount) THEN
1729
1730 l_fee_types_rec.line_id := p_fee_line_id;
1731 l_fee_types_rec.dnz_chr_id := p_contract_id;
1732 l_fee_types_rec.amount := l_upfront_tax_fee_amount;
1733 l_fee_types_rec.fee_type := l_fee_rec.fee_type;
1734 l_fee_types_rec.effective_from := l_fee_rec.start_date;
1735 l_fee_types_rec.effective_to := l_fee_rec.end_date;
1736 l_fee_types_rec.item_id := l_fee_rec.cim_fee_id;
1737 l_fee_types_rec.item_id1 := l_fee_rec.object1_id1;
1738
1739 IF (G_IS_DEBUG_STATEMENT_ON = true) THEN
1740 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: Update Fee Procedure: before OKL_MAINTAIN_FEE_PVT.update_fee_type ');
1741 END IF;
1742
1743 -- update fee top line
1744 OKL_MAINTAIN_FEE_PVT.update_fee_type(
1745 p_api_version => p_api_version,
1746 p_init_msg_list => p_init_msg_list,
1747 x_return_status => x_return_status,
1748 x_msg_count => x_msg_count,
1749 x_msg_data => x_msg_data,
1750 p_fee_types_rec => l_fee_types_rec,
1751 x_fee_types_rec => lx_fee_types_rec
1752 );
1753
1754 IF (G_IS_DEBUG_STATEMENT_ON = true) THEN
1755 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: Update Fee Procedure: after OKL_MAINTAIN_FEE_PVT.update_fee_type: x_return_status '||x_return_status);
1756 END IF;
1757
1758 -- Check if the call was successful
1759 IF (x_return_status <> Okl_Api.G_RET_STS_SUCCESS) THEN
1760 RAISE update_fee_exception;
1761 END IF;
1762 END IF;
1763
1764 IF (p_default_feetype IN ('CAPITALIZE','FINANCE')) THEN
1765 l_ins_count :=1;
1766 l_upd_count :=1;
1767 FOR j in get_asset_csr1(p_required_feetype)
1768 LOOP
1769
1770 IF (G_IS_DEBUG_STATEMENT_ON = true) THEN
1771 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: Update Fee Procedure: before get_asset_tax_amt_csr ');
1772 END IF;
1773
1774 -- get asset tax amount
1775 OPEN get_asset_tax_amt_csr(j.id);
1776 FETCH get_asset_tax_amt_csr INTO l_asset_tax_amt;
1777 IF get_asset_tax_amt_csr%NOTFOUND THEN
1778
1779 OKL_API.set_message(G_APP_NAME, 'OKL_LA_ST_ASSET_TAX_AMT_ERROR');
1780 IF (G_IS_DEBUG_STATEMENT_ON = true) THEN
1781 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'Cannot derive asset tax amount for ID'|| j.id);
1782 END IF;
1783 CLOSE get_asset_tax_amt_csr;
1784 RAISE update_fee_exception;
1785 END IF;
1786 CLOSE get_asset_tax_amt_csr;
1787
1788 IF (G_IS_DEBUG_STATEMENT_ON = true) THEN
1789 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: Update Fee Procedure: l_asset_tax_amt '||l_asset_tax_amt);
1790 END IF;
1791
1792 l_cov_asset_line_rec.cleb_cov_asset_id := NULL;
1793 l_cov_asset_line_rec.amount := NULL;
1794 l_cov_asset_line_rec.cim_cov_asset_id := NULL;
1795 OPEN l_cov_asset_line_csr(p_chr_id => p_contract_id,
1796 p_fee_cle_id => p_fee_line_id,
1797 p_fin_asset_cle_id => j.id);
1798 FETCH l_cov_asset_line_csr INTO l_cov_asset_line_rec;
1799 CLOSE l_cov_asset_line_csr;
1800
1801 IF (G_IS_DEBUG_STATEMENT_ON = true) THEN
1802 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: Update Fee Procedure: l_cov_asset_line_rec.cleb_cov_asset_id '||l_cov_asset_line_rec.cleb_cov_asset_id);
1803 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: Update Fee Procedure: l_cov_asset_line_rec.amount '||l_cov_asset_line_rec.amount);
1804 END IF;
1805
1806 -- Update Fee covered asset amount if covered asset line exists, else create covered asset line
1807 IF l_cov_asset_line_rec.cleb_cov_asset_id IS NOT NULL THEN
1808
1809 IF (l_asset_tax_amt <> l_cov_asset_line_rec.amount) THEN
1810
1811 l_u_line_item_tbl(l_upd_count).cle_id := l_cov_asset_line_rec.cleb_cov_asset_id;
1812 l_u_line_item_tbl(l_upd_count).item_id := l_cov_asset_line_rec.cim_cov_asset_id;
1813
1814 l_u_line_item_tbl(l_upd_count).chr_id := p_contract_id;
1815 l_u_line_item_tbl(l_upd_count).parent_cle_id := p_fee_line_id;
1816 l_u_line_item_tbl(l_upd_count).item_id1 := j.id;
1817 l_u_line_item_tbl(l_upd_count).item_id2 := '#';
1818 l_u_line_item_tbl(l_upd_count).item_object1_code := 'OKX_COVASST';
1819 l_u_line_item_tbl(l_upd_count).item_description := j.item_description;
1820 l_u_line_item_tbl(l_upd_count).name := j.name;
1821 l_u_line_item_tbl(l_upd_count).capital_amount := l_asset_tax_amt;
1822
1823 l_upd_count := l_upd_count + 1;
1824 END IF;
1825 ELSE
1826
1827 l_c_line_item_tbl(l_ins_count).chr_id := p_contract_id;
1828 l_c_line_item_tbl(l_ins_count).parent_cle_id := p_fee_line_id;
1829 l_c_line_item_tbl(l_ins_count).item_id1 := j.id;
1830 l_c_line_item_tbl(l_ins_count).item_id2 := '#';
1831 l_c_line_item_tbl(l_ins_count).item_object1_code := 'OKX_COVASST';
1832 l_c_line_item_tbl(l_ins_count).item_description := j.item_description;
1833 l_c_line_item_tbl(l_ins_count).name := j.name;
1834 l_c_line_item_tbl(l_ins_count).capital_amount := l_asset_tax_amt;
1835
1836 l_ins_count := l_ins_count + 1;
1837 END IF;
1838 END LOOP;
1839
1840 l_del_count := 1;
1841 --Delete covered asset lines for assets that have tax treatment 'Billed'
1842 FOR l_del_cov_asset_rec IN l_del_cov_asset_csr1(p_chr_id => p_contract_id,
1843 p_fee_cle_id => p_fee_line_id) LOOP
1844
1845 --Bug# 6512668: Corrected l_upd_count to l_del_count
1846 l_d_line_item_tbl(l_del_count).chr_id := p_contract_id;
1847 l_d_line_item_tbl(l_del_count).parent_cle_id := p_fee_line_id;
1848 l_d_line_item_tbl(l_del_count).cle_id := l_del_cov_asset_rec.cleb_cov_asset_id;
1849 l_d_line_item_tbl(l_del_count).item_id := l_del_cov_asset_rec.cim_cov_asset_id;
1850
1851 l_del_count := l_del_count + 1;
1852
1853 END LOOP;
1854
1855 ELSIF (p_default_feetype = 'BILLED') THEN
1856 l_ins_count :=1;
1857 l_upd_count :=1;
1858 FOR j in get_asset_csr2 (p_required_feetype)
1859 LOOP
1860
1861 IF (G_IS_DEBUG_STATEMENT_ON = true) THEN
1862 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: Update Fee Procedure: before get_asset_tax_amt_csr ');
1863 END IF;
1864
1865 -- get asset tax amount
1866 OPEN get_asset_tax_amt_csr(j.id);
1867 FETCH get_asset_tax_amt_csr INTO l_asset_tax_amt;
1868 IF get_asset_tax_amt_csr%NOTFOUND THEN
1869 OKL_API.set_message( p_app_name => G_APP_NAME,
1870 p_msg_name => 'OKL_LA_ST_ASSET_TAX_AMT_ERROR');
1871 IF (G_IS_DEBUG_STATEMENT_ON = true) THEN
1872 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'Cannot derive asset tax amount. for ID'|| j.id);
1873 END IF;
1874 CLOSE get_asset_tax_amt_csr;
1875 RAISE update_fee_exception;
1876 END IF;
1877 CLOSE get_asset_tax_amt_csr;
1878
1879 l_cov_asset_line_rec.cleb_cov_asset_id := NULL;
1880 l_cov_asset_line_rec.amount := NULL;
1881 l_cov_asset_line_rec.cim_cov_asset_id := NULL;
1882 OPEN l_cov_asset_line_csr(p_chr_id => p_contract_id,
1883 p_fee_cle_id => p_fee_line_id,
1884 p_fin_asset_cle_id => j.id);
1885 FETCH l_cov_asset_line_csr INTO l_cov_asset_line_rec;
1886 CLOSE l_cov_asset_line_csr;
1887
1888 -- Update Fee covered asset amount if covered asset line exists, else create covered asset line
1889 IF l_cov_asset_line_rec.cleb_cov_asset_id IS NOT NULL THEN
1890
1891 IF (l_asset_tax_amt <> l_cov_asset_line_rec.amount) THEN
1892
1893 l_u_line_item_tbl(l_upd_count).cle_id := l_cov_asset_line_rec.cleb_cov_asset_id;
1894 l_u_line_item_tbl(l_upd_count).item_id := l_cov_asset_line_rec.cim_cov_asset_id;
1895
1896 l_u_line_item_tbl(l_upd_count).chr_id := p_contract_id;
1897 l_u_line_item_tbl(l_upd_count).parent_cle_id := p_fee_line_id;
1898 l_u_line_item_tbl(l_upd_count).item_id1 := j.id;
1899 l_u_line_item_tbl(l_upd_count).item_id2 := '#';
1900 l_u_line_item_tbl(l_upd_count).item_object1_code := 'OKX_COVASST';
1901 l_u_line_item_tbl(l_upd_count).item_description := j.item_description;
1902 l_u_line_item_tbl(l_upd_count).name := j.name;
1903 l_u_line_item_tbl(l_upd_count).capital_amount := l_asset_tax_amt;
1904
1905 l_upd_count := l_upd_count + 1;
1906 END IF;
1907 ELSE
1908
1909 l_c_line_item_tbl(l_ins_count).chr_id := p_contract_id;
1910 l_c_line_item_tbl(l_ins_count).parent_cle_id := p_fee_line_id;
1911 l_c_line_item_tbl(l_ins_count).item_id1 := j.id;
1912 l_c_line_item_tbl(l_ins_count).item_id2 := '#';
1913 l_c_line_item_tbl(l_ins_count).item_object1_code := 'OKX_COVASST';
1914 l_c_line_item_tbl(l_ins_count).item_description := j.item_description;
1915 l_c_line_item_tbl(l_ins_count).name := j.name;
1916 l_c_line_item_tbl(l_ins_count).capital_amount := l_asset_tax_amt;
1917
1918 l_ins_count := l_ins_count + 1;
1919 END IF;
1920
1921 END LOOP;
1922
1923 l_del_count := 1;
1924 --Delete covered asset lines for assets that have tax treatment 'BILLED' or NULL
1925 FOR l_del_cov_asset_rec IN l_del_cov_asset_csr2(p_chr_id => p_contract_id,
1926 p_fee_cle_id => p_fee_line_id) LOOP
1927
1928 --Bug# 6512668: Corrected l_upd_count to l_del_count
1929 l_d_line_item_tbl(l_del_count).chr_id := p_contract_id;
1930 l_d_line_item_tbl(l_del_count).parent_cle_id := p_fee_line_id;
1931 l_d_line_item_tbl(l_del_count).cle_id := l_del_cov_asset_rec.cleb_cov_asset_id;
1932 l_d_line_item_tbl(l_del_count).item_id := l_del_cov_asset_rec.cim_cov_asset_id;
1933
1934 l_del_count := l_del_count + 1;
1935
1936 END LOOP;
1937 END IF;
1938
1939 -- Associate Assets to the fee
1940 IF (l_c_line_item_tbl.COUNT > 0) THEN
1941
1942 IF (G_IS_DEBUG_STATEMENT_ON = true) THEN
1943 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: Update Fee Procedure: before okl_contract_line_item_pvt.create_contract_line_item ');
1944 END IF;
1945
1946 okl_contract_line_item_pvt.create_contract_line_item(
1947 p_api_version => p_api_version,
1948 p_init_msg_list => p_init_msg_list,
1949 x_return_status => x_return_status,
1950 x_msg_count => x_msg_count,
1951 x_msg_data => x_msg_data,
1952 p_line_item_tbl => l_c_line_item_tbl,
1953 x_line_item_tbl => lx_c_line_item_tbl);
1954
1955
1956 IF (G_IS_DEBUG_STATEMENT_ON = true) THEN
1957 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: Update Fee Procedure: x_return_status '||x_return_status);
1958 END IF;
1959
1960 -- Check if the call was successful
1961 If (x_return_status <> Okl_Api.G_RET_STS_SUCCESS) then
1962 RAISE update_fee_exception;
1963 End If;
1964 END IF;
1965
1966 IF (l_u_line_item_tbl.COUNT > 0) THEN
1967
1968 IF (G_IS_DEBUG_STATEMENT_ON = true) THEN
1969 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: Update Fee Procedure: before okl_contract_line_item_pvt.update_contract_line_item ');
1970 END IF;
1971
1972 okl_contract_line_item_pvt.update_contract_line_item(
1973 p_api_version => p_api_version,
1974 p_init_msg_list => p_init_msg_list,
1975 x_return_status => x_return_status,
1976 x_msg_count => x_msg_count,
1977 x_msg_data => x_msg_data,
1978 p_line_item_tbl => l_u_line_item_tbl,
1979 x_line_item_tbl => lx_u_line_item_tbl);
1980
1981 IF (G_IS_DEBUG_STATEMENT_ON = true) THEN
1982 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: Update Fee Procedure: x_return_status '||x_return_status);
1983 END IF;
1984
1985 -- Check if the call was successful
1986 If (x_return_status <> Okl_Api.G_RET_STS_SUCCESS) then
1987 RAISE update_fee_exception;
1988 End If;
1989 END IF;
1990
1991 IF (l_d_line_item_tbl.COUNT > 0) THEN
1992
1993 IF (G_IS_DEBUG_STATEMENT_ON = true) THEN
1994 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: Update Fee Procedure: before okl_contract_line_item_pvt.delete_contract_line_item ');
1995 END IF;
1996
1997 okl_contract_line_item_pvt.delete_contract_line_item(
1998 p_api_version => p_api_version,
1999 p_init_msg_list => p_init_msg_list,
2000 x_return_status => x_return_status,
2001 x_msg_count => x_msg_count,
2002 x_msg_data => x_msg_data,
2003 p_line_item_tbl => l_d_line_item_tbl);
2004
2005 IF (G_IS_DEBUG_STATEMENT_ON = true) THEN
2006 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: Update Fee Procedure: x_return_status '||x_return_status);
2007 END IF;
2008
2009 -- Check if the call was successful
2010 If (x_return_status <> Okl_Api.G_RET_STS_SUCCESS) then
2011 RAISE update_fee_exception;
2012 End If;
2013 END IF;
2014
2015 IF (p_required_feetype = 'FINANCE') THEN
2016 -- Following Segment is for updating Expense Item for Financed Fee
2017 OPEN l_rul_csr(p_chr_id => p_contract_id,
2018 p_fee_cle_id => p_fee_line_id);
2019 FETCH l_rul_csr INTO l_rul_rec;
2020 CLOSE l_rul_csr;
2021
2022 IF (l_rul_rec.amount <> l_upfront_tax_fee_amount) THEN
2023
2024 -- Populate Rule Values for Expenses
2025 l_rulv_tbl(1).id := l_rul_rec.id;
2026 l_rulv_tbl(1).rgp_id := l_rul_rec.rgp_id;
2027 l_rulv_tbl(1).dnz_chr_id := l_rul_rec.dnz_chr_id;
2028 l_rulv_tbl(1).rule_information_category := l_rul_rec.rule_information_category;
2029 l_rulv_tbl(1).rule_information2 := TO_CHAR(l_upfront_tax_fee_amount);
2030
2031 IF (G_IS_DEBUG_STATEMENT_ON = true) THEN
2032 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: Update Fee Procedure: before OKL_RULE_PUB.update_rule ');
2033 END IF;
2034 OKL_RULE_PUB.update_rule(
2035 p_api_version => p_api_version,
2036 p_init_msg_list => p_init_msg_list,
2037 x_return_status => x_return_status,
2038 x_msg_count => x_msg_count,
2039 x_msg_data => x_msg_data,
2040 p_rulv_tbl => l_rulv_tbl,
2041 x_rulv_tbl => lx_rulv_tbl);
2042
2043 IF (G_IS_DEBUG_STATEMENT_ON = true) THEN
2044 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: Update Fee Procedure: x_return_status '||x_return_status);
2045 END IF;
2046
2047 If (x_return_status <> Okl_Api.G_RET_STS_SUCCESS) then
2048 RAISE update_fee_exception;
2049 End If;
2050 END IF;
2051 END IF;
2052
2053 EXCEPTION
2054 when update_fee_exception then
2055 x_return_status := OKL_API.G_RET_STS_ERROR;
2056
2057 END update_fee;
2058
2059 PROCEDURE process_tax_override(
2060 p_api_version IN NUMBER,
2061 p_init_msg_list IN VARCHAR2 DEFAULT OKL_API.G_FALSE,
2062 p_chr_id IN NUMBER,
2063 p_transaction_id IN NUMBER,
2064 x_return_status OUT NOCOPY VARCHAR2,
2065 x_msg_count OUT NOCOPY NUMBER,
2066 x_msg_data OUT NOCOPY VARCHAR2
2067 )
2068 IS
2069
2070 l_api_name CONSTANT VARCHAR2(30) := 'UPDATE_FEE';
2071 l_api_version CONSTANT NUMBER := 1.0;
2072
2073 l_rule_info_rec rule_info_csr%ROWTYPE;
2074
2075 -- Cursor to check if Sales Tax fee exists
2076 -- Bug# 6512668: Exclude fee line in Abandoned status
2077 CURSOR l_fee_csr (p_chr_id IN NUMBER) IS
2078 SELECT cle.id,
2079 kle.fee_type
2080 FROM okc_k_lines_b cle,
2081 okl_k_lines kle
2082 WHERE cle.id = kle.id
2083 AND cle.dnz_chr_id = p_chr_id
2084 AND cle.chr_id = p_chr_id
2085 AND kle.fee_purpose_code = 'SALESTAX'
2086 AND cle.sts_code <> 'ABANDONED';
2087
2088 l_fee_rec l_fee_csr%ROWTYPE;
2089
2090 l_upfront_tax_prog_sts OKL_BOOK_CONTROLLER_TRX.progress_status%TYPE;
2091
2092 BEGIN
2093
2094 IF (G_DEBUG_ENABLED = 'Y') THEN
2095 G_IS_DEBUG_STATEMENT_ON := OKL_DEBUG_PUB.CHECK_LOG_ON(G_MODULE, FND_LOG.LEVEL_STATEMENT);
2096 END IF;
2097
2098 x_return_status := OKL_API.START_ACTIVITY(
2099 p_api_name => l_api_name,
2100 p_pkg_name => g_pkg_name,
2101 p_init_msg_list => p_init_msg_list,
2102 l_api_version => l_api_version,
2103 p_api_version => p_api_version,
2104 p_api_type => G_API_TYPE,
2105 x_return_status => x_return_status);
2106
2107 -- check if activity started successfully
2108 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
2109 RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
2110 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
2111 RAISE OKL_API.G_EXCEPTION_ERROR;
2112 END IF;
2113
2114 OPEN rule_info_csr(p_contract_id => p_chr_id);
2115 FETCH rule_info_csr INTO l_rule_info_rec;
2116 IF rule_info_csr%NOTFOUND THEN
2117 OKL_API.set_message( p_app_name => G_APP_NAME,
2118 p_msg_name => 'OKL_QA_ST_MISSING');
2119 CLOSE rule_info_csr;
2120 RAISE OKL_API.G_EXCEPTION_ERROR;
2121 END IF;
2122 CLOSE rule_info_csr;
2123
2124 IF (G_IS_DEBUG_STATEMENT_ON = true) THEN
2125 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: Update Fee Procedure: Default Fee Type '||l_rule_info_rec.rule_information1);
2126 END IF;
2127
2128 OPEN l_fee_csr(p_chr_id => p_chr_id);
2129 FETCH l_fee_csr INTO l_fee_rec;
2130 CLOSE l_fee_csr;
2131
2132 IF (G_IS_DEBUG_STATEMENT_ON = true) THEN
2133 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: Update Fee Procedure: Sales Tax Fee Line Id '||l_fee_rec.id);
2134 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: Update Fee Procedure: Sales Tax Fee Type '||l_fee_rec.fee_type);
2135 END IF;
2136
2137 IF l_fee_rec.id IS NOT NULL THEN
2138
2139 IF (G_IS_DEBUG_STATEMENT_ON = true) THEN
2140 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: Update Fee Procedure: Before OKL_LA_SALES_TAX_PVT.update_fee ');
2141 END IF;
2142
2143 OKL_LA_SALES_TAX_PVT.update_fee
2144 (p_api_version => p_api_version,
2145 p_init_msg_list => p_init_msg_list,
2146 p_contract_id => p_chr_id,
2147 p_transaction_id => p_transaction_id,
2148 p_fee_line_id => l_fee_rec.id,
2149 p_required_feetype => l_fee_rec.fee_type,
2150 p_default_feetype => l_rule_info_rec.rule_information1,
2151 x_return_status => x_return_status,
2152 x_msg_count => x_msg_count,
2153 x_msg_data => x_msg_data);
2154
2155 IF (G_IS_DEBUG_STATEMENT_ON = true) THEN
2156 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: Update Fee Procedure: After OKL_LA_SALES_TAX_PVT.update_fee: x_return_status '||x_return_status);
2157 END IF;
2158
2159 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
2160 RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
2161 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
2162 RAISE OKL_API.G_EXCEPTION_ERROR;
2163 END IF;
2164
2165 OKL_LA_SALES_TAX_PVT.validate_upfront_tax_fee(
2166 p_api_version => p_api_version,
2167 p_init_msg_list => p_init_msg_list,
2168 x_return_status => x_return_status,
2169 x_msg_count => x_msg_count,
2170 x_msg_data => x_msg_data,
2171 p_chr_id => p_chr_id);
2172
2173 IF (G_IS_DEBUG_STATEMENT_ON = true) THEN
2174 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: Update Fee Procedure: After OKL_LA_SALES_TAX_PVT.validate_upfront_tax_fee: x_return_status '||x_return_status);
2175 END IF;
2176
2177 IF (x_return_status <> OKL_API.G_RET_STS_SUCCESS) THEN
2178 l_upfront_tax_prog_sts := OKL_BOOK_CONTROLLER_PVT.G_PROG_STS_ERROR;
2179 ELSE
2180 l_upfront_tax_prog_sts := OKL_BOOK_CONTROLLER_PVT.G_PROG_STS_COMPLETE;
2181 END IF;
2182
2183 OKL_BOOK_CONTROLLER_PVT.update_book_controller_trx(
2184 p_api_version => p_api_version,
2185 p_init_msg_list => p_init_msg_list,
2186 x_return_status => x_return_status,
2187 x_msg_count => x_msg_count,
2188 x_msg_data => x_msg_data,
2189 p_khr_id => p_chr_id ,
2190 p_prog_short_name => OKL_BOOK_CONTROLLER_PVT.G_CALC_UPFRONT_TAX ,
2191 p_progress_status => l_upfront_tax_prog_sts);
2192
2193 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
2194 RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
2195 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
2196 RAISE OKL_API.G_EXCEPTION_ERROR;
2197 END IF;
2198 END IF;
2199
2200 --Update Contract Status to Passed
2201 OKL_CONTRACT_STATUS_PUB.update_contract_status(
2202 p_api_version => p_api_version,
2203 p_init_msg_list => p_init_msg_list,
2204 x_return_status => x_return_status,
2205 x_msg_count => x_msg_count,
2206 x_msg_data => x_msg_data,
2207 p_khr_status => 'PASSED',
2208 p_chr_id => p_chr_id);
2209
2210 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
2211 RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
2212 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
2213 RAISE OKL_API.G_EXCEPTION_ERROR;
2214 END IF;
2215
2216 --call to cascade status on to lines
2217 OKL_CONTRACT_STATUS_PUB.cascade_lease_status
2218 (p_api_version => p_api_version,
2219 p_init_msg_list => p_init_msg_list,
2220 x_return_status => x_return_status,
2221 x_msg_count => x_msg_count,
2222 x_msg_data => x_msg_data,
2223 p_chr_id => p_chr_id);
2224
2225 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
2226 RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
2227 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
2228 RAISE OKL_API.G_EXCEPTION_ERROR;
2229 END IF;
2230
2231 --Update status of Price Contract process to Pending
2232 OKL_BOOK_CONTROLLER_PVT.update_book_controller_trx(
2233 p_api_version => p_api_version,
2234 p_init_msg_list => p_init_msg_list,
2235 x_return_status => x_return_status,
2236 x_msg_count => x_msg_count,
2237 x_msg_data => x_msg_data,
2238 p_khr_id => p_chr_id ,
2239 p_prog_short_name => OKL_BOOK_CONTROLLER_PVT.G_PRICE_CONTRACT,
2240 p_progress_status => OKL_BOOK_CONTROLLER_PVT.G_PROG_STS_PENDING);
2241
2242 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
2243 RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
2244 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
2245 RAISE OKL_API.G_EXCEPTION_ERROR;
2246 END IF;
2247
2248 --Update status of Submit Contract process to Pending
2249 OKL_BOOK_CONTROLLER_PVT.update_book_controller_trx(
2250 p_api_version => p_api_version,
2251 p_init_msg_list => p_init_msg_list,
2252 x_return_status => x_return_status,
2253 x_msg_count => x_msg_count,
2254 x_msg_data => x_msg_data,
2255 p_khr_id => p_chr_id ,
2256 p_prog_short_name => OKL_BOOK_CONTROLLER_PVT.G_SUBMIT_CONTRACT,
2257 p_progress_status => OKL_BOOK_CONTROLLER_PVT.G_PROG_STS_PENDING);
2258
2259 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
2260 RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
2261 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
2262 RAISE OKL_API.G_EXCEPTION_ERROR;
2263 END IF;
2264
2265 EXCEPTION
2266
2267 WHEN OKL_API.G_EXCEPTION_ERROR THEN
2268 x_return_status := OKL_API.HANDLE_EXCEPTIONS(
2269 p_api_name => l_api_name,
2270 p_pkg_name => g_pkg_name,
2271 p_exc_name => 'OKL_API.G_RET_STS_ERROR',
2272 x_msg_count => x_msg_count,
2273 x_msg_data => x_msg_data,
2274 p_api_type => g_api_type);
2275
2276 WHEN OKL_API.G_EXCEPTION_UNEXPECTED_ERROR THEN
2277 x_return_status := OKL_API.HANDLE_EXCEPTIONS(
2278 p_api_name => l_api_name,
2279 p_pkg_name => g_pkg_name,
2280 p_exc_name => 'OKL_API.G_RET_STS_UNEXP_ERROR',
2281 x_msg_count => x_msg_count,
2282 x_msg_data => x_msg_data,
2283 p_api_type => g_api_type);
2284
2285 WHEN OTHERS THEN
2286 x_return_status := OKL_API.HANDLE_EXCEPTIONS(
2287 p_api_name => l_api_name,
2288 p_pkg_name => g_pkg_name,
2289 p_exc_name => 'OTHERS',
2290 x_msg_count => x_msg_count,
2291 x_msg_data => x_msg_data,
2292 p_api_type => g_api_type);
2293
2294 END process_tax_override;
2295 -- R12B Authoring OA Migration
2296
2297 -- Procedure to create Financed fee
2298 Procedure create_fee(
2299 p_api_version IN NUMBER,
2300 p_init_msg_list IN VARCHAR2 DEFAULT Okl_Api.G_FALSE,
2301 p_contract_id IN NUMBER,
2302 p_transaction_id IN NUMBER,
2303 p_default_feetype IN VARCHAR2,
2304 p_required_feetype IN VARCHAR2,
2305 p_stream_id IN NUMBER,
2306 x_return_status OUT NOCOPY VARCHAR2,
2307 x_msg_count OUT NOCOPY NUMBER,
2308 x_msg_data OUT NOCOPY VARCHAR2
2309 )
2310 IS
2311 l_fee_types_rec OKL_MAINTAIN_FEE_PVT.fee_types_rec_type;
2312 lx_fee_types_rec OKL_MAINTAIN_FEE_PVT.fee_types_rec_type;
2313 l_line_item_tbl okl_contract_line_item_pvt.line_item_tbl_type;
2314 lx_line_item_tbl okl_contract_line_item_pvt.line_item_tbl_type;
2315
2316 l_rgpv_rec rgpv_rec_type;
2317 l_rulv_rec rulv_rec_type;
2318 l_rulv_tbl rulv_tbl_type;
2319 lx_rgpv_rec rgpv_rec_type;
2320 lx_rulv_rec rulv_rec_type;
2321 lx_rulv_tbl rulv_tbl_type;
2322
2323 i NUMBER := 0;
2324 l_financed_amount NUMBER;
2325 l_capitalized_amount NUMBER;
2326
2327 -- R12B Authoring OA Migration
2328 -- Cursor to check if financed fee exists
2329 -- Bug# 6512668: Exclude fee line in Abandoned status
2330 CURSOR check_fee_csr ( l_fee_type IN VARCHAR2 ) IS
2331 SELECT cle.id
2332 FROM OKC_K_LINES_b cle,
2333 OKL_K_LINES KLE
2334 WHERE cle.id = kle.id
2335 AND cle.dnz_chr_id = p_contract_id
2336 AND kle.fee_purpose_code = 'SALESTAX'
2337 AND kle.fee_type = l_fee_type
2338 AND cle.sts_code <> 'ABANDONED';
2339
2340 l_fee_line_id OKC_K_LINES_B.id%TYPE;
2341 -- R12B Authoring OA Migration
2342
2343 -- cursor to get item id
2344 CURSOR stream_csr (stream_type_id IN NUMBER) IS
2345 select name
2346 from OKL_STRM_TYPE_TL
2347 where id = stream_type_id;
2348
2349 -- Get contract dates
2350 CURSOR contract_dates_csr IS
2351 SELECT start_date, end_date
2352 FROM okc_k_headers_b
2353 WHERE id = p_contract_id;
2354
2355 -- Cursor to get assets for financed fee association
2356 -- Bug# 6512668: Exclude asset lines in Abandoned status
2357 CURSOR get_asset_csr1 (p_fee_type IN VARCHAR2)
2358 IS
2359 SELECT cle.id, cle.name, cle.item_description
2360 FROM okc_k_lines_v cle,
2361 okc_rule_groups_b rg1,
2362 okc_rules_b rl1,
2363 okc_line_styles_b lse,
2364 okc_rule_groups_b rg2,
2365 okc_rules_b rl2
2366 WHERE cle.chr_ID = p_contract_id
2367 AND cle.lse_id = lse.id
2368 AND lse.lty_code = 'FREE_FORM1'
2369 AND cle.dnz_chr_id = rg1.dnz_chr_id
2370 AND cle.id = rg1.cle_id
2371 AND cle.dnz_chr_id = rl1.dnz_chr_id
2372 AND rg1.id = rl1.rgp_id
2373 AND rg1.rgd_code = 'LAASTX'
2374 AND rl1.rule_information_category = 'LAASTX'
2375 AND ( rl1.rule_information11 IS NULL
2376 OR
2377 rl1.rule_information11 = p_fee_type)
2378 AND cle.dnz_chr_id = rg2.dnz_chr_id
2379 AND cle.dnz_chr_id = rl2.dnz_chr_id
2380 AND rg2.id = rl2.rgp_id
2381 AND rg2.rgd_code = 'LAHDTX'
2382 AND rl2.rule_information_category = 'LASTPR'
2383 AND rl2.rule_information1 = p_fee_type
2384 AND cle.sts_code <> 'ABANDONED';
2385
2386
2387 -- Cursor to get assets for fee association if T and C Tax treatment is
2388 -- 'BILLED'
2389 -- Bug# 6512668: Exclude asset lines in Abandoned status
2390 CURSOR get_asset_csr2 (p_fee_type IN VARCHAR2)
2391 IS
2392 SELECT cle.id, cle.name, cle.item_description
2393 FROM okc_k_lines_v cle,
2394 okc_rule_groups_b rg1,
2395 okc_rules_b rl1,
2396 okc_line_styles_b lse
2397 WHERE cle.dnz_chr_ID = p_contract_id
2398 AND cle.lse_id = lse.id
2399 AND lse.lty_code = 'FREE_FORM1'
2400 AND cle.dnz_chr_id = rg1.dnz_chr_id
2401 AND cle.id = rg1.cle_id
2402 AND cle.dnz_chr_id = rl1.dnz_chr_id
2403 AND rg1.id = rl1.rgp_id
2404 AND rg1.rgd_code = 'LAASTX'
2405 AND rl1.rule_information_category = 'LAASTX'
2406 AND rl1.rule_information11 = p_fee_type
2407 AND cle.sts_code <> 'ABANDONED';
2408
2409
2410 -- Cursor to get tax amounts for assets
2411 CURSOR get_asset_tax_amt_csr (asset_line_id IN NUMBER)
2412 IS
2413 SELECT NVL(SUM(NVL(TOTAL_TAX,0)),0)
2414 FROM okl_tax_sources txs
2415 WHERE txs.KHR_ID = p_contract_id
2416 AND txs.trx_id = p_transaction_id
2417 AND txs.kle_id = asset_line_id
2418 AND txs.TAX_LINE_STATUS_CODE = 'ACTIVE'
2419 AND txs.TAX_CALL_TYPE_CODE = 'UPFRONT_TAX';
2420
2421 -- Cursor Types
2422 contract_dates_csr_rec contract_dates_csr%ROWTYPE;
2423
2424 l_finance_fee_exists VARCHAR(1);
2425 l_capitalized_fee_exists VARCHAR(1);
2426 l_item_name VARCHAR2(150);
2427 l_asset_tax_amt NUMBER;
2428 l_asset_count NUMBER := 0;
2429
2430 -- Define constants
2431 create_fee_exception exception;
2432
2433 x_msg_index_out Number;
2434
2435 BEGIN
2436 IF (G_DEBUG_ENABLED = 'Y') THEN
2437 G_IS_DEBUG_STATEMENT_ON := OKL_DEBUG_PUB.CHECK_LOG_ON(G_MODULE, FND_LOG.LEVEL_STATEMENT);
2438 END IF;
2439
2440 x_return_status := Okl_Api.G_RET_STS_SUCCESS;
2441
2442 -- If upfront tax is 'FINANCED'
2443 If (p_required_feetype = 'FINANCE') THEN
2444
2445 --l_financed_amount := get_financed_tax ( p_Contract_id, p_transaction_id);
2446 l_financed_amount := get_financed_tax ( p_Contract_id, p_default_feetype);
2447 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
2448 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: Pre Book Procedure: FINANCE segment: l_financed_amount: '
2449 ||l_financed_amount);
2450 END IF;
2451
2452 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
2453 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: Create Fee Procedure: FINANCE segment: before check_fee_csr ');
2454 END IF;
2455
2456 -- Check If finance fee already exists
2457 -- if exists do nothing, because we can only create once
2458 OPEN check_fee_csr ('FINANCED');
2459 -- R12B Authoring OA Migration
2460 FETCH check_fee_csr INTO l_fee_line_id;
2461 -- R12B Authoring OA Migration
2462
2463 IF check_fee_csr%NOTFOUND THEN
2464 l_finance_fee_exists := OKL_API.G_FALSE;
2465 Else
2466 l_finance_fee_exists := OKL_API.G_TRUE;
2467 END IF;
2468 CLOSE check_fee_csr;
2469
2470 -- Create Fee only if the amount is > 0 and Sale Tax Fee does not
2471 -- exist already
2472 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
2473 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: Pre Book Procedure: FINANCE segment: before IF condition');
2474 END IF;
2475 If ((l_financed_amount > 0) AND
2476 (l_finance_fee_exists = OKL_API.G_FALSE)) THEN
2477
2478 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
2479 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: Create Fee Procedure: FINANCE segment: before stream_csr ');
2480 END IF;
2481 -- get item_id1 value
2482 OPEN stream_csr(p_stream_id);
2483 FETCH stream_csr INTO l_item_name;
2484 IF stream_csr%NOTFOUND THEN
2485 OKL_API.set_message(
2486 p_app_name => G_APP_NAME,
2487 p_msg_name => 'OKL_LA_ST_STREAM_ERROR',
2488 p_token1 => 'FEE_TYPE',
2489 p_token1_value => p_required_feetype);
2490 CLOSE stream_csr;
2491 RAISE create_fee_exception;
2492 END IF;
2493 CLOSE stream_csr;
2494
2495 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
2496 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: Create Fee Procedure: FINANCE segment: before contract_dates_csr ');
2497 END IF;
2498
2499 -- get contract dates for fee effective date
2500 OPEN contract_dates_csr;
2501 FETCH contract_dates_csr INTO contract_dates_csr_rec;
2502 IF contract_dates_csr%NOTFOUND THEN
2503 --Okl_Api.SET_MESSAGE(G_APP_NAME, G_INVALID_VALUE,G_COL_NAME_TOKEN,'Fee Effective dates cannot be derived');
2504 Okl_Api.SET_MESSAGE(G_APP_NAME, 'Cannot find contract effective dates for sales tax fee creation.');
2505 CLOSE contract_dates_csr;
2506 RAISE create_fee_exception;
2507 END IF;
2508 CLOSE contract_dates_csr;
2509
2510 l_fee_types_rec.item_id1 := to_number(p_stream_id);
2511 l_fee_types_rec.dnz_chr_id := p_contract_id;
2512 l_fee_types_rec.fee_purpose_code := 'SALESTAX';
2513 l_fee_types_rec.fee_type := 'FINANCED';
2514 l_fee_types_rec.item_name := l_item_name;
2515 l_fee_types_rec.amount := l_financed_amount;
2516 l_fee_types_rec.effective_from := contract_dates_csr_rec.start_date;
2517 l_fee_types_rec.effective_to := contract_dates_csr_rec.end_date;
2518
2519 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
2520 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: Create Fee Procedure: FINANCE segment: before OKL_MAINTAIN_FEE_PVT ');
2521 END IF;
2522 -- create fee top line
2523 OKL_MAINTAIN_FEE_PVT.create_fee_type(
2524 p_api_version => p_api_version,
2525 p_init_msg_list => p_init_msg_list,
2526 x_return_status => x_return_status,
2527 x_msg_count => x_msg_count,
2528 x_msg_data => x_msg_data,
2529 p_fee_types_rec => l_fee_types_rec,
2530 x_fee_types_rec => lx_fee_types_rec
2531 );
2532 -- Check if the call was successful
2533 If (x_return_status <> Okl_Api.G_RET_STS_SUCCESS) then
2534 RAISE create_fee_exception;
2535 End If;
2536
2537
2538 IF (p_default_feetype = 'FINANCE') THEN
2539 i:=1;
2540 FOR j in get_asset_csr1 ('FINANCE')
2541 LOOP
2542
2543 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
2544 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: Create Fee Procedure: FINANCE segment: before get_asset_tax_amt_csr ');
2545 END IF;
2546 -- get asset tax amount
2547 OPEN get_asset_tax_amt_csr(j.id);
2548 FETCH get_asset_tax_amt_csr INTO l_asset_tax_amt;
2549 IF get_asset_tax_amt_csr%NOTFOUND THEN
2550 --Okl_Api.SET_MESSAGE(G_APP_NAME, G_INVALID_VALUE,G_COL_NAME_TOKEN,'Asset Tax Amount cannot be derived');
2551 Okl_Api.SET_MESSAGE(G_APP_NAME, 'OKL_LA_ST_K_ID_ERROR');
2552 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
2553 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'Cannot derive asset tax amount for ID'|| j.id);
2554 END IF;
2555 CLOSE get_asset_tax_amt_csr;
2556 RAISE create_fee_exception;
2557 END IF;
2558 CLOSE get_asset_tax_amt_csr;
2559
2560 -- Hard Code Asset Tax Amount for now
2561 --l_asset_tax_amt := 50;
2562
2563 l_line_item_tbl(i).chr_id := p_contract_id;
2564 l_line_item_tbl(i).parent_cle_id := lx_fee_types_rec.line_id ;
2565 l_line_item_tbl(i).item_id1 := j.id;
2566 l_line_item_tbl(i).item_id2 := '#';
2567 l_line_item_tbl(i).item_object1_code := 'OKX_COVASST';
2568 l_line_item_tbl(i).item_description := j.item_description;
2569 l_line_item_tbl(i).name := j.name;
2570 l_line_item_tbl(i).capital_amount := l_asset_tax_amt;
2571
2572 i := i+1;
2573 END LOOP;
2574 END IF;
2575
2576 IF (p_default_feetype = 'BILLED') THEN
2577 i:=1;
2578 FOR j in get_asset_csr2 ('FINANCE')
2579 LOOP
2580
2581 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
2582 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: Create Fee Procedure: FINANCE segment: before get_asset_tax_amt_csr ');
2583 END IF;
2584 -- get asset tax amount
2585 OPEN get_asset_tax_amt_csr(j.id);
2586 FETCH get_asset_tax_amt_csr INTO l_asset_tax_amt;
2587 IF get_asset_tax_amt_csr%NOTFOUND THEN
2588 OKL_API.set_message( p_app_name => G_APP_NAME,
2589 p_msg_name => 'OKL_LA_ST_ASSET_TAX_AMT_ERROR');
2590 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
2591 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'Cannot derive asset tax amount. for ID'|| j.id);
2592 END IF;
2593 CLOSE get_asset_tax_amt_csr;
2594 RAISE create_fee_exception;
2595 END IF;
2596 CLOSE get_asset_tax_amt_csr;
2597
2598 -- Hard Code Asset Tax Amount for now
2599 --l_asset_tax_amt := 50;
2600
2601 l_line_item_tbl(i).chr_id := p_contract_id;
2602 l_line_item_tbl(i).parent_cle_id := lx_fee_types_rec.line_id ;
2603 l_line_item_tbl(i).item_id1 := j.id;
2604 l_line_item_tbl(i).item_id2 := '#';
2605 l_line_item_tbl(i).item_object1_code := 'OKX_COVASST';
2606 l_line_item_tbl(i).item_description := j.item_description;
2607 l_line_item_tbl(i).name := j.name;
2608 l_line_item_tbl(i).capital_amount := l_asset_tax_amt;
2609
2610 i := i+1;
2611 END LOOP;
2612 END IF;
2613
2614
2615
2616 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
2617 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: Create Fee Procedure: FINANCE segment: before okl_contract_line_item_pvt ');
2618 END IF;
2619 -- Associate Assets to the fee
2620 okl_contract_line_item_pvt.create_contract_line_item(
2621 p_api_version => p_api_version,
2622 p_init_msg_list => p_init_msg_list,
2623 --p_init_msg_list => 'T',
2624 x_return_status => x_return_status,
2625 x_msg_count => x_msg_count,
2626 x_msg_data => x_msg_data,
2627 p_line_item_tbl => l_line_item_tbl,
2628 x_line_item_tbl => lx_line_item_tbl);
2629
2630 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
2631 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: Create Fee Procedure: FINANCE segment: x_return_status '||x_return_status);
2632 END IF;
2633 FOR k in 1..x_msg_count LOOP
2634 fnd_msg_pub.get (p_encoded => 'F',
2635 p_data => x_msg_data,
2636 p_msg_index_out => x_msg_index_out
2637 );
2638 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
2639 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: Create Fee Procedure: FINANCE segment:'||to_char(k) || ':' || x_msg_data);
2640 END IF;
2641 END LOOP;
2642
2643 -- Check if the call was successful
2644 If (x_return_status <> Okl_Api.G_RET_STS_SUCCESS) then
2645 RAISE create_fee_exception;
2646 End If;
2647
2648 -- Following Segment is for creating Expense Item for Financed Fee
2649 -- It is implemeted using Rule APIs, so will use the same
2650
2651 -- Populate Rule Group Values for Expenses
2652 l_rgpv_rec.rgd_code := 'LAFEXP';
2653 l_rgpv_rec.dnz_chr_id := p_contract_id;
2654 l_rgpv_rec.cle_id := lx_fee_types_rec.line_id;
2655 l_rgpv_rec.rgp_type := 'KRG';
2656
2657 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
2658 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: Create Fee Procedure: FINANCE segment: before OKL_RULE_PUB.create_rule_group ');
2659 END IF;
2660
2661 OKL_RULE_PUB.create_rule_group(
2662 p_api_version => p_api_version,
2663 p_init_msg_list => p_init_msg_list,
2664 x_return_status => x_return_status,
2665 x_msg_count => x_msg_count,
2666 x_msg_data => x_msg_data,
2667 p_rgpv_rec => l_rgpv_rec,
2668 x_rgpv_rec => lx_rgpv_rec);
2669
2670 If (x_return_status <> Okl_Api.G_RET_STS_SUCCESS) then
2671 RAISE create_fee_exception;
2672 End If;
2673
2674 -- Populate Rule Values for Expenses
2675 l_rulv_tbl(1).rgp_id := lx_rgpv_rec.id;
2676 l_rulv_tbl(1).dnz_chr_id := p_contract_id;
2677 l_rulv_tbl(1).rule_information_category := 'LAFEXP';
2678 l_rulv_tbl(1).rule_information1 := 1;
2679 l_rulv_tbl(1).rule_information2 := l_financed_amount;
2680 l_rulv_tbl(1).WARN_YN := 'N';
2681 l_rulv_tbl(1).STD_TEMPLATE_YN := 'N';
2682 l_rulv_tbl(1).template_yn := 'N';
2683
2684 l_rulv_tbl(2).rgp_id := lx_rgpv_rec.id;
2685 l_rulv_tbl(2).dnz_chr_id := p_contract_id;
2686 l_rulv_tbl(2).rule_information_category := 'LAFREQ';
2687 l_rulv_tbl(2).OBJECT1_ID1 := 'M';
2688 l_rulv_tbl(2).OBJECT1_ID2 := '#';
2689 l_rulv_tbl(2).JTOT_OBJECT1_CODE := 'OKL_TUOM';
2690 l_rulv_tbl(2).WARN_YN := 'N';
2691 l_rulv_tbl(2).STD_TEMPLATE_YN := 'N';
2692 l_rulv_tbl(2).template_yn := 'N';
2693
2694 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
2695 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: Create Fee Procedure: FINANCE segment: before OKL_RULE_PUB.create_rule ');
2696 END IF;
2697 OKL_RULE_PUB.create_rule(
2698 p_api_version => p_api_version,
2699 p_init_msg_list => p_init_msg_list,
2700 x_return_status => x_return_status,
2701 x_msg_count => x_msg_count,
2702 x_msg_data => x_msg_data,
2703 p_rulv_tbl => l_rulv_tbl,
2704 x_rulv_tbl => lx_rulv_tbl);
2705
2706 If (x_return_status <> Okl_Api.G_RET_STS_SUCCESS) then
2707 RAISE create_fee_exception;
2708 End If;
2709
2710 -- R12B Authoring OA Migration
2711 Elsif (l_finance_fee_exists = OKL_API.G_TRUE) Then
2712
2713 OKL_LA_SALES_TAX_PVT.update_fee
2714 (p_api_version => p_api_version,
2715 p_init_msg_list => p_init_msg_list,
2716 p_contract_id => p_contract_id,
2717 p_transaction_id => p_transaction_id,
2718 p_fee_line_id => l_fee_line_id,
2719 p_required_feetype => p_required_feetype,
2720 p_default_feetype => p_default_feetype,
2721 x_return_status => x_return_status,
2722 x_msg_count => x_msg_count,
2723 x_msg_data => x_msg_data);
2724
2725 If (x_return_status <> Okl_Api.G_RET_STS_SUCCESS) then
2726 RAISE create_fee_exception;
2727 End If;
2728 -- R12B Authoring OA Migration
2729
2730 End If;
2731
2732 End If;
2733
2734 -- If upfront tax is 'CAPITALIZED'
2735 If (p_required_feetype = 'CAPITALIZE')
2736 THEN
2737
2738 --l_capitalized_amount := get_capitalized_tax ( p_Contract_id
2739 -- ,p_transaction_id
2740 -- ,p_default_feetype);
2741 l_capitalized_amount := get_capitalized_tax ( p_Contract_id
2742 ,p_default_feetype);
2743
2744
2745 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
2746 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: Pre Book Procedure: CAPITALIZE segment: l_capitalized_amount: '
2747 ||l_capitalized_amount);
2748 END IF;
2749 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
2750 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: Pre Book Procedure: CAPITALIZE segment: before check_fee_csr ');
2751 END IF;
2752
2753 OPEN check_fee_csr ('CAPITALIZED');
2754 -- R12B Authoring OA Migration
2755 FETCH check_fee_csr INTO l_fee_line_id;
2756 -- R12B Authoring OA Migration
2757 IF check_fee_csr%NOTFOUND THEN
2758 l_capitalized_fee_exists := OKL_API.G_FALSE;
2759 Else
2760 l_capitalized_fee_exists := OKL_API.G_TRUE;
2761 END IF;
2762 CLOSE check_fee_csr;
2763
2764 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
2765 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: Pre Book Procedure: CAPITALIZE segment: before IF condition');
2766 END IF;
2767 -- Create Fee only if the amount is > 0 and fee does not exist
2768 If ((l_capitalized_amount > 0) AND
2769 (l_capitalized_fee_exists = OKL_API.G_FALSE)) THEN
2770
2771 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
2772 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: Pre Book Procedure: CAPITALIZE segment: before stream_csr ');
2773 END IF;
2774 -- get item_id1 value
2775 OPEN stream_csr(p_stream_id);
2776 FETCH stream_csr INTO l_item_name;
2777
2778 IF stream_csr%NOTFOUND THEN
2779 OKL_API.set_message(
2780 p_app_name => G_APP_NAME,
2781 p_msg_name => 'OKL_LA_ST_STREAM_ERROR',
2782 p_token1 => 'FEE_TYPE',
2783 p_token1_value => p_required_feetype);
2784 CLOSE stream_csr;
2785 RAISE create_fee_exception;
2786 END IF;
2787 CLOSE stream_csr;
2788
2789 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
2790 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: Pre Book Procedure: CAPITALIZE segment: before contract_dates_csr ');
2791 END IF;
2792 -- get contract dates for fee effective date
2793 OPEN contract_dates_csr;
2794 FETCH contract_dates_csr INTO contract_dates_csr_rec;
2795 IF contract_dates_csr%NOTFOUND THEN
2796 --Okl_Api.SET_MESSAGE(G_APP_NAME, G_INVALID_VALUE,G_COL_NAME_TOKEN,'Fee Effective dates cannot be derived');
2797 Okl_Api.SET_MESSAGE(G_APP_NAME, 'Cannot find contract effective dates for sales tax fee creation.');
2798 CLOSE contract_dates_csr;
2799 RAISE create_fee_exception;
2800 END IF;
2801 CLOSE contract_dates_csr;
2802
2803 l_fee_types_rec.dnz_chr_id := p_contract_id;
2804 l_fee_types_rec.fee_type := 'CAPITALIZED';
2805 l_fee_types_rec.fee_purpose_code := 'SALESTAX';
2806 l_fee_types_rec.item_name := l_item_name;
2807 l_fee_types_rec.item_id1 := to_number(p_stream_id);
2808 l_fee_types_rec.amount := l_capitalized_amount;
2809 l_fee_types_rec.effective_from := contract_dates_csr_rec.start_date;
2810 l_fee_types_rec.effective_to := contract_dates_csr_rec.end_date;
2811
2812 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
2813 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: Pre Book Procedure: CAPITALIZE segment: before OKL_MAINTAIN_FEE_PVT ');
2814 END IF;
2815 -- Create Fee Top Line
2816 OKL_MAINTAIN_FEE_PVT.create_fee_type(
2817 p_api_version => p_api_version,
2818 p_init_msg_list => p_init_msg_list,
2819 x_return_status => x_return_status,
2820 x_msg_count => x_msg_count,
2821 x_msg_data => x_msg_data,
2822 p_fee_types_rec => l_fee_types_rec,
2823 x_fee_types_rec => lx_fee_types_rec
2824 );
2825 -- Check if the call was successful
2826 If (x_return_status <> Okl_Api.G_RET_STS_SUCCESS) then
2827 RAISE create_fee_exception;
2828 End If;
2829
2830 IF (p_default_feetype = 'CAPITALIZE') THEN
2831 i:=1;
2832 FOR j in get_asset_csr1 ('CAPITALIZE')
2833 LOOP
2834 -- get asset tax amount
2835 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
2836 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: Pre Book Procedure: CAPITALIZE segment: before get_asset_tax_amt_csr ');
2837 END IF;
2838 OPEN get_asset_tax_amt_csr(j.id);
2839 FETCH get_asset_tax_amt_csr INTO l_asset_tax_amt;
2840 IF get_asset_tax_amt_csr%NOTFOUND THEN
2841 OKL_API.set_message( p_app_name => G_APP_NAME,
2842 p_msg_name => 'OKL_LA_ST_ASSET_TAX_AMT_ERROR');
2843 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
2844 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'Cannot derive asset tax amount. for ID'|| j.id);
2845 END IF;
2846 CLOSE get_asset_tax_amt_csr;
2847 RAISE create_fee_exception;
2848 END IF;
2849 CLOSE get_asset_tax_amt_csr;
2850
2851 -- Hard Code Asset Tax Amount for now
2852 --l_asset_tax_amt := 50;
2853
2854 l_line_item_tbl(i).chr_id := p_contract_id;
2855 l_line_item_tbl(i).parent_cle_id := lx_fee_types_rec.line_id;
2856 l_line_item_tbl(i).item_id1 := j.id;
2857 l_line_item_tbl(i).item_id2 := '#';
2858 l_line_item_tbl(i).item_object1_code := 'OKX_COVASST';
2859 l_line_item_tbl(i).item_description := j.item_description;
2860 l_line_item_tbl(i).name := j.name;
2861 l_line_item_tbl(i).capital_amount := l_asset_tax_amt;
2862
2863 i := i+1;
2864
2865 END LOOP;
2866 END IF;
2867
2868 IF (p_default_feetype = 'BILLED') THEN
2869 i:=1;
2870 FOR j in get_asset_csr2 ('CAPITALIZE')
2871 LOOP
2872
2873 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
2874 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: Create Fee Procedure: CAPITALIZE segment: before get_asset_tax_amt_csr ');
2875 END IF;
2876 -- get asset tax amount
2877 OPEN get_asset_tax_amt_csr(j.id);
2878 FETCH get_asset_tax_amt_csr INTO l_asset_tax_amt;
2879 IF get_asset_tax_amt_csr%NOTFOUND THEN
2880 OKL_API.set_message( p_app_name => G_APP_NAME,
2881 p_msg_name => 'OKL_LA_ST_ASSET_TAX_AMT_ERROR');
2882 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
2883 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'Cannot derive asset tax amount. for ID'|| j.id);
2884 END IF;
2885 CLOSE get_asset_tax_amt_csr;
2886 RAISE create_fee_exception;
2887 END IF;
2888 CLOSE get_asset_tax_amt_csr;
2889
2890 -- Hard Code Asset Tax Amount for now
2891 --l_asset_tax_amt := 50;
2892
2893 l_line_item_tbl(i).chr_id := p_contract_id;
2894 l_line_item_tbl(i).parent_cle_id := lx_fee_types_rec.line_id ;
2895 l_line_item_tbl(i).item_id1 := j.id;
2896 l_line_item_tbl(i).item_id2 := '#';
2897 l_line_item_tbl(i).item_object1_code := 'OKX_COVASST';
2898 l_line_item_tbl(i).item_description := j.item_description;
2899 l_line_item_tbl(i).name := j.name;
2900 l_line_item_tbl(i).capital_amount := l_asset_tax_amt;
2901
2902 i := i+1;
2903 END LOOP;
2904 END IF;
2905
2906
2907
2908 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
2909 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: Pre Book Procedure: CAPITALIZE segment: before okl_contract_line_item_pvt ');
2910 END IF;
2911 -- Associate Assets to the fee
2912 okl_contract_line_item_pvt.create_contract_line_item(
2913 p_api_version => p_api_version,
2914 p_init_msg_list => p_init_msg_list,
2915 x_return_status => x_return_status,
2916 x_msg_count => x_msg_count,
2917 x_msg_data => x_msg_data,
2918 p_line_item_tbl => l_line_item_tbl,
2919 x_line_item_tbl => lx_line_item_tbl);
2920
2921 -- Check if the call was successful
2922 If (x_return_status <> Okl_Api.G_RET_STS_SUCCESS) then
2923 RAISE create_fee_exception;
2924 End If;
2925
2926 -- R12B Authoring OA Migration
2927 Elsif (l_capitalized_fee_exists = OKL_API.G_TRUE) Then
2928
2929 OKL_LA_SALES_TAX_PVT.update_fee
2930 (p_api_version => p_api_version,
2931 p_init_msg_list => p_init_msg_list,
2932 p_contract_id => p_contract_id,
2933 p_transaction_id => p_transaction_id,
2934 p_fee_line_id => l_fee_line_id,
2935 p_required_feetype => p_required_feetype,
2936 p_default_feetype => p_default_feetype,
2937 x_return_status => x_return_status,
2938 x_msg_count => x_msg_count,
2939 x_msg_data => x_msg_data);
2940
2941 If (x_return_status <> Okl_Api.G_RET_STS_SUCCESS) then
2942 RAISE create_fee_exception;
2943 End If;
2944 -- R12B Authoring OA Migration
2945
2946 End If;
2947
2948 End If;
2949
2950 Exception
2951 when create_fee_exception then
2952 x_return_status := OKL_API.G_RET_STS_ERROR;
2953
2954 END create_fee;
2955
2956 -- R12 - START
2957
2958 -- Following procedures introduced to meet R12 upfront tax accounting requirements
2959
2960 -- Start of comments
2961 --
2962 -- Procedure Name : populate_account_api_data
2963 -- Description : This is a private procedure used by create_upfront_tax_accounting
2964 -- to populate accounting data tables prior to calling central OKL a/c API
2965 -- Business Rules :
2966 -- Parameters :
2967 -- Version : 1.0
2968 -- End of comments
2969
2970 PROCEDURE populate_account_data(
2971 p_api_version IN NUMBER
2972 ,p_init_msg_list IN VARCHAR2 DEFAULT OKC_API.G_FALSE
2973 ,p_trxh_out_rec IN Okl_Trx_Contracts_Pvt.tcnv_rec_type
2974 ,p_tclv_tbl IN okl_trx_contracts_pvt.tclv_tbl_type
2975 ,p_acc_gen_tbl IN OUT NOCOPY okl_account_dist_pvt.ACC_GEN_TBL_TYPE
2976 ,p_tmpl_identify_tbl IN OUT NOCOPY okl_account_dist_pvt.tmpl_identify_tbl_type
2977 ,p_dist_info_tbl IN OUT NOCOPY okl_account_dist_pvt.dist_info_tbl_type
2978 ,x_return_status OUT NOCOPY VARCHAR2
2979 ,x_msg_count OUT NOCOPY NUMBER
2980 ,x_msg_data OUT NOCOPY VARCHAR2)
2981 IS
2982 -- Cursors plucked from OKL_LA_JE_PVT for a/c - START
2983 CURSOR fnd_pro_csr
2984 IS
2985 SELECT mo_global.get_current_org_id() l_fnd_profile
2986 FROM dual;
2987
2988 fnd_pro_rec fnd_pro_csr%ROWTYPE;
2989
2990 CURSOR ra_cust_csr
2991 IS
2992 SELECT cust_trx_type_id l_cust_trx_type_id
2993 FROM ra_cust_trx_types
2994 WHERE name = 'Invoice-OKL';
2995
2996 ra_cust_rec ra_cust_csr%ROWTYPE;
2997
2998 CURSOR salesP_csr
2999 IS
3000 SELECT ct.object1_id1 id
3001 ,chr.scs_code scs_code
3002 FROM okc_contacts ct,
3003 okc_contact_sources csrc,
3004 okc_k_party_roles_b pty,
3005 okc_k_headers_b chr
3006 WHERE ct.cpl_id = pty.id
3007 AND ct.cro_code = csrc.cro_code
3008 AND ct.jtot_object1_code = csrc.jtot_object_code
3009 AND ct.dnz_chr_id = chr.id
3010 AND pty.rle_code = csrc.rle_code
3011 AND csrc.cro_code = 'SALESPERSON'
3012 AND csrc.rle_code = 'LESSOR'
3013 AND csrc.buy_or_sell = chr.buy_or_sell
3014 AND pty.dnz_chr_id = chr.id
3015 AND pty.chr_id = chr.id
3016 AND chr.id = p_trxh_out_rec.khr_id;
3017
3018 l_salesP_rec salesP_csr%ROWTYPE;
3019
3020 CURSOR custBillTo_csr
3021 IS
3022 SELECT bill_to_site_use_id cust_acct_site_id
3023 FROM okc_k_headers_b
3024 WHERE id = p_trxh_out_rec.khr_id;
3025
3026 l_custBillTo_rec custBillTo_csr%ROWTYPE;
3027
3028 -- Cursors plucked from OKL_LA_JE_PVT for a/c - END
3029 l_acc_gen_primary_key_tbl okl_account_dist_pvt.acc_gen_primary_key;
3030 l_fact_synd_code FND_LOOKUPS.Lookup_code%TYPE;
3031 l_inv_acct_code OKC_RULES_B.Rule_Information1%TYPE;
3032
3033 account_data_exception EXCEPTION;
3034
3035 --Bug# 6619311
3036 CURSOR assetBillTo_csr(p_cle_id IN NUMBER)
3037 IS
3038 SELECT bill_to_site_use_id cust_acct_site_id
3039 FROM okc_k_lines_b
3040 WHERE id = p_cle_id;
3041
3042 l_assetBillTo_rec assetBillTo_csr%ROWTYPE;
3043 l_acc_gen_primary_key_tbl1 okl_account_dist_pvt.acc_gen_primary_key;
3044
3045 BEGIN
3046
3047 okl_debug_pub.logmessage('OKL: populate_account_data : START');
3048
3049 x_return_status := Okl_Api.G_RET_STS_SUCCESS;
3050
3051 l_acc_gen_primary_key_tbl(1).source_table := 'FINANCIALS_SYSTEM_PARAMETERS';
3052 OPEN fnd_pro_csr;
3053 FETCH fnd_pro_csr INTO fnd_pro_rec;
3054 IF ( fnd_pro_csr%NOTFOUND )
3055 THEN
3056 l_acc_gen_primary_key_tbl(1).primary_key_column := '';
3057 ELSE
3058 l_acc_gen_primary_key_tbl(1).primary_key_column := fnd_pro_rec.l_fnd_profile;
3059 End IF;
3060 CLOSE fnd_pro_csr;
3061
3062 l_acc_gen_primary_key_tbl(2).source_table := 'AR_SITE_USES_V';
3063 OPEN custBillTo_csr;
3064 FETCH custBillTo_csr INTO l_custBillTo_rec;
3065 CLOSE custBillTo_csr;
3066 l_acc_gen_primary_key_tbl(2).primary_key_column := l_custBillTo_rec.cust_acct_site_id;
3067
3068 l_acc_gen_primary_key_tbl(3).source_table := 'RA_CUST_TRX_TYPES';
3069 OPEN ra_cust_csr;
3070 FETCH ra_cust_csr INTO ra_cust_rec;
3071 IF ( ra_cust_csr%NOTFOUND ) THEN
3072 l_acc_gen_primary_key_tbl(3).primary_key_column := '';
3073 ELSE
3074 l_acc_gen_primary_key_tbl(3).primary_key_column := TO_CHAR(ra_cust_rec.l_cust_trx_type_id);
3075 END IF;
3076 CLOSE ra_cust_csr;
3077
3078 l_acc_gen_primary_key_tbl(4).source_table := 'JTF_RS_SALESREPS_MO_V';
3079 OPEN salesP_csr;
3080 FETCH salesP_csr INTO l_salesP_rec;
3081 CLOSE salesP_csr;
3082 l_acc_gen_primary_key_tbl(4).primary_key_column := l_salesP_rec.id;
3083
3084 IF (G_IS_DEBUG_STATEMENT_ON = TRUE)
3085 THEN
3086 OKL_DEBUG_PUB.LOG_DEBUG( FND_LOG.LEVEL_STATEMENT
3087 ,G_MODULE
3088 , 'OKL: populate_account_data Procedure: Calling OKL_SECURITIZATION_PVT ');
3089 END IF;
3090
3091 OKL_SECURITIZATION_PVT.Check_Khr_ia_associated(
3092 p_api_version => p_api_version,
3093 p_init_msg_list => p_init_msg_list,
3094 x_return_status => x_return_status,
3095 x_msg_count => x_msg_count,
3096 x_msg_data => x_msg_data,
3097 p_khr_id => p_trxh_out_rec.khr_id,
3098 p_scs_code => l_salesP_rec.scs_code,
3099 p_trx_date => p_trxh_out_rec.date_transaction_occurred,
3100
3101 x_fact_synd_code => l_fact_synd_code,
3102 x_inv_acct_code => l_inv_acct_code
3103 );
3104
3105
3106 okl_debug_pub.logmessage('OKL: populate_account_data : OKL_SECURITIZATION_PVT : '||x_return_status);
3107
3108 IF (x_return_status <> Okl_Api.G_RET_STS_SUCCESS)
3109 THEN
3110 RAISE account_data_exception;
3111 END IF;
3112
3113 FOR i in p_tclv_tbl.FIRST..p_tclv_tbl.LAST
3114 LOOP
3115
3116 --Bug# 6619311: Populate asset level bill-to site if defined
3117 l_acc_gen_primary_key_tbl1 := l_acc_gen_primary_key_tbl;
3118 IF p_tclv_tbl(i).kle_id IS NOT NULL THEN
3119 l_assetBillTo_rec := NULL;
3120 OPEN assetBillTo_csr(p_cle_id => p_tclv_tbl(i).kle_id);
3121 FETCH assetBillTo_csr INTO l_assetBillTo_rec;
3122 CLOSE assetBillTo_csr;
3123
3124 IF l_assetBillTo_rec.cust_acct_site_id IS NOT NULL THEN
3125 l_acc_gen_primary_key_tbl1(2).primary_key_column := l_assetBillTo_rec.cust_acct_site_id;
3126 END IF;
3127 END IF;
3128
3129 -- Populate account source
3130 p_acc_gen_tbl(i).acc_gen_key_tbl := l_acc_gen_primary_key_tbl1;
3131 p_acc_gen_tbl(i).source_id := p_tclv_tbl(i).id;
3132
3133 -- Populate template info
3134 p_tmpl_identify_tbl(i).product_id := p_trxh_out_rec.pdt_id;
3135 p_tmpl_identify_tbl(i).transaction_type_id := p_trxh_out_rec.try_id;
3136 p_tmpl_identify_tbl(i).stream_type_id := p_tclv_tbl(i).sty_id;
3137 p_tmpl_identify_tbl(i).advance_arrears := NULL;
3138 p_tmpl_identify_tbl(i).prior_year_yn := 'N';
3139 p_tmpl_identify_tbl(i).memo_yn := 'N';
3140 p_tmpl_identify_tbl(i).factoring_synd_flag := l_fact_synd_code;
3141 p_tmpl_identify_tbl(i).investor_code := l_inv_acct_code;
3142
3143 -- Populate distribution info
3144 p_dist_info_tbl(i).SOURCE_ID := p_tclv_tbl(i).id;
3145 p_dist_info_tbl(i).amount := p_tclv_tbl(i).amount;
3146 p_dist_info_tbl(i).ACCOUNTING_DATE := p_trxh_out_rec.date_transaction_occurred;
3147 p_dist_info_tbl(i).SOURCE_TABLE := 'OKL_TXL_CNTRCT_LNS';
3148 p_dist_info_tbl(i).GL_REVERSAL_FLAG := 'N';
3149 p_dist_info_tbl(i).POST_TO_GL := 'Y';
3150 p_dist_info_tbl(i).CONTRACT_ID := p_trxh_out_rec.khr_id;
3151 p_dist_info_tbl(i).currency_conversion_rate := p_trxh_out_rec.currency_conversion_rate;
3152 p_dist_info_tbl(i).currency_conversion_type := p_trxh_out_rec.currency_conversion_type;
3153 p_dist_info_tbl(i).currency_conversion_date := p_trxh_out_rec.currency_conversion_date;
3154 p_dist_info_tbl(i).currency_code := p_trxh_out_rec.currency_code;
3155 okl_debug_pub.logmessage('OKL: populate_account_data : p_tclv_tbl loop : l_dist_info_tbl(i).amount : '||p_dist_info_tbl(i).amount);
3156
3157 END LOOP;
3158
3159 okl_debug_pub.logmessage('OKL: populate_account_data : END');
3160
3161 EXCEPTION
3162 WHEN account_data_exception
3163 THEN
3164 x_return_status := OKL_API.G_RET_STS_ERROR;
3165
3166 END populate_account_data;
3167
3168
3169 -- Start of comments
3170 --
3171 -- Procedure Name : create_upfront_tax_accounting
3172 -- Description : This procedure creates a/c journal entries for upfront tax lines.
3173 -- This procedure logic will be executed in its entirety, only if SLA accounting
3174 -- option AMB is enabled.
3175 -- When enabled, it creates:
3176 -- 1. TRX header in OKL_TRX_CONTRACTS for type 'Upfront Tax'
3177 -- 2. TRX lines in OKL_TXL_CNTRCT_LNS for each line in ZX_LINES,
3178 -- store values for cle-id, tax_line_id, tax_amount, etc.
3179 -- 3. Identify tax treatment for each asset line, to derive stream type
3180 -- 4. Call a/c API for upfront tax records in OKL_TXL_CNTRCT_LNS
3181 -- Business Rules :
3182 -- Parameters :
3183 -- Version : 1.0
3184 -- End of comments
3185
3186 PROCEDURE create_upfront_tax_accounting(
3187 p_api_version IN NUMBER
3188 ,p_init_msg_list IN VARCHAR2 DEFAULT OKC_API.G_FALSE
3189 ,p_contract_id IN okc_k_headers_all_b.id%TYPE
3190 ,p_transaction_id IN okl_trx_contracts_all.khr_id%TYPE
3191 ,p_transaction_type IN VARCHAR2
3192 ,x_return_status OUT NOCOPY VARCHAR2
3193 ,x_msg_count OUT NOCOPY NUMBER
3194 ,x_msg_data OUT NOCOPY VARCHAR2)
3195 IS
3196
3197 -- Cursor to check system level accounting option
3198 -- Upfront tax a/c is done if AMB is enabled
3199 CURSOR acct_opt_csr
3200 IS
3201 SELECT account_derivation
3202 FROM okl_sys_acct_opts;
3203 l_acct_opt okl_sys_acct_opts.account_derivation%TYPE;
3204
3205 --Bug# 6619311
3206 -- Cursor to fetch tax lines from EBTax table
3207 -- for assets having tax treatment same as the
3208 -- Default tax treatment
3209 CURSOR tax_line_csr1 (p_default_tax_treatment VARCHAR2)
3210 IS
3211 SELECT NVL(rul.rule_information11, p_default_tax_treatment)
3212 tax_treatment
3213 , rgp.cle_id asset_id
3214 , txs.id tax_header_id
3215 , txl.tax_line_id tax_line_id
3216 , txl.tax_amt tax_amount
3217 FROM OKC_RULES_V rul
3218 , OKC_RULE_GROUPS_V rgp
3219 , okl_tax_sources txs
3220 , zx_lines txl
3221 WHERE rul.rgp_id = rgp.id
3222 AND rgp.dnz_chr_id = p_contract_id
3223 AND rgp.rgd_code = 'LAASTX'
3224 AND rul.rule_information_category = 'LAASTX'
3225 AND (rul.rule_information11 = p_default_tax_treatment
3226 OR
3227 rul.rule_information11 IS NULL)
3228 AND txs.khr_id = rgp.dnz_chr_id
3229 AND txs.kle_id = rgp.cle_id
3230 AND txs.kle_id IS NOT NULL -- change
3231 AND txs.TAX_LINE_STATUS_CODE = 'ACTIVE'
3232 AND txs.TAX_CALL_TYPE_CODE = 'UPFRONT_TAX'
3233 AND txs.trx_id = txl.trx_id
3234 AND txs.trx_line_id = txl.trx_line_id
3235 AND txl.entity_code = 'CONTRACTS' -- change
3236 AND txl.event_class_code = 'BOOKING' -- change
3237 AND txs.entity_code = txl.entity_code -- change
3238 AND txs.event_class_code = txl.event_class_code -- change
3239 AND txl.application_id = 540
3240 AND txl.trx_level_type = 'LINE'
3241 AND txs.application_id = txl.application_id
3242 AND txs.trx_level_type = txl.trx_level_type;
3243
3244 --Bug# 6619311
3245 -- Cursor to fetch tax lines from EBTax table
3246 -- for assets having tax treatment as Capitalized or Financed
3247 -- when the default tax treatment is Billed
3248 CURSOR tax_line_csr2
3249 IS
3250 SELECT rul.rule_information11 tax_treatment
3251 , rgp.cle_id asset_id
3252 , txs.id tax_header_id
3253 , txl.tax_line_id tax_line_id
3254 , txl.tax_amt tax_amount
3255 FROM OKC_RULES_V rul
3256 , OKC_RULE_GROUPS_V rgp
3257 , okl_tax_sources txs
3258 , zx_lines txl
3259 WHERE rul.rgp_id = rgp.id
3260 AND rgp.dnz_chr_id = p_contract_id
3261 AND rgp.rgd_code = 'LAASTX'
3262 AND rul.rule_information_category = 'LAASTX'
3263 AND rul.rule_information11 <> 'BILLED'
3264 AND txs.khr_id = rgp.dnz_chr_id
3265 AND txs.kle_id = rgp.cle_id
3266 AND txs.kle_id IS NOT NULL -- change
3267 AND txs.TAX_LINE_STATUS_CODE = 'ACTIVE'
3268 AND txs.TAX_CALL_TYPE_CODE = 'UPFRONT_TAX'
3269 AND txs.trx_id = txl.trx_id
3270 AND txs.trx_line_id = txl.trx_line_id
3271 AND txl.entity_code = 'CONTRACTS' -- change
3272 AND txl.event_class_code = 'BOOKING' -- change
3273 AND txs.entity_code = txl.entity_code -- change
3274 AND txs.event_class_code = txl.event_class_code -- change
3275 AND txl.application_id = 540
3276 AND txl.trx_level_type = 'LINE'
3277 AND txs.application_id = txl.application_id
3278 AND txs.trx_level_type = txl.trx_level_type;
3279
3280 --Bug# 6619311
3281 -- Cursor to fetch tax lines from EBTax table
3282 -- for assets having tax treatment as Billed
3283 -- when the default tax treatment is Capitalized or Financed
3284 CURSOR tax_line_csr3
3285 IS
3286 SELECT rul.rule_information11 tax_treatment
3287 , rgp.cle_id asset_id
3288 , txs.id tax_header_id
3289 , txl.tax_line_id tax_line_id
3290 , txl.tax_amt tax_amount
3291 FROM OKC_RULES_V rul
3292 , OKC_RULE_GROUPS_V rgp
3293 , okl_tax_sources txs
3294 , zx_lines txl
3295 WHERE rul.rgp_id = rgp.id
3296 AND rgp.dnz_chr_id = p_contract_id
3297 AND rgp.rgd_code = 'LAASTX'
3298 AND rul.rule_information_category = 'LAASTX'
3299 AND rul.rule_information11 = 'BILLED'
3300 AND txs.khr_id = rgp.dnz_chr_id
3301 AND txs.kle_id = rgp.cle_id
3302 AND txs.kle_id IS NOT NULL -- change
3303 AND txs.TAX_LINE_STATUS_CODE = 'ACTIVE'
3304 AND txs.TAX_CALL_TYPE_CODE = 'UPFRONT_TAX'
3305 AND txs.trx_id = txl.trx_id
3306 AND txs.trx_line_id = txl.trx_line_id
3307 AND txl.entity_code = 'CONTRACTS' -- change
3308 AND txl.event_class_code = 'BOOKING' -- change
3309 AND txs.entity_code = txl.entity_code -- change
3310 AND txs.event_class_code = txl.event_class_code -- change
3311 AND txl.application_id = 540
3312 AND txl.trx_level_type = 'LINE'
3313 AND txs.application_id = txl.application_id
3314 AND txs.trx_level_type = txl.trx_level_type;
3315
3316 --Bug# 6619311
3317 -- Cursor to fetch tax lines from EBTax table
3318 -- for contract level taxes
3319 CURSOR tax_line_csr4
3320 IS
3321 SELECT 'BILLED' tax_treatment
3322 , txs.kle_id asset_id
3323 , txs.id tax_header_id
3324 , txl.tax_line_id tax_line_id
3325 , txl.tax_amt tax_amount
3326 FROM okl_tax_sources txs
3327 , zx_lines txl
3328 WHERE txs.khr_id = p_contract_id
3329 AND txs.kle_id IS NULL
3330 AND txs.TAX_LINE_STATUS_CODE = 'ACTIVE'
3331 AND txs.TAX_CALL_TYPE_CODE = 'UPFRONT_TAX'
3332 AND txs.trx_id = txl.trx_id
3333 AND txs.trx_line_id = txl.trx_line_id
3334 AND txl.entity_code = 'CONTRACTS'
3335 AND txl.event_class_code = 'BOOKING'
3336 AND txs.entity_code = txl.entity_code
3337 AND txs.event_class_code = txl.event_class_code
3338 AND txl.application_id = 540
3339 AND txl.trx_level_type = 'LINE'
3340 AND txs.application_id = txl.application_id
3341 AND txs.trx_level_type = txl.trx_level_type;
3342
3343 -- Cursor to check if previous upfront tax TRX exists,
3344 -- This will be used by rebook logic to decide if there
3345 -- is a need for reversal accounting. If the cursor does not
3346 -- return any rows, skip the reversal accounting part
3347 CURSOR check_upfront_trx_csr
3348 IS
3349 SELECT 1
3350 FROM dual
3351 WHERE EXISTS (SELECT a.id
3352 FROM okl_trx_contracts_all a
3353 ,okl_trx_types_v b
3354 WHERE a.khr_id = p_contract_id
3355 AND a.try_id = b.id
3356 --rkuttiya added for 12.1.1 Multi GAAP
3357 AND a.representation_type = 'PRIMARY'
3358 --
3359 AND b.name = 'Upfront Tax');
3360
3361 --Bug# 6619311
3362 -- Cursor to get reversed tax lines for rebook TRX
3363 -- for assets having tax treatment same as the
3364 -- Default tax treatment
3365 CURSOR rev_taxline_csr1( p_rbk_trx_id NUMBER
3366 ,p_default_tax_treatment VARCHAR2)
3367 IS
3368 SELECT NVL(rul.rule_information11,p_default_tax_treatment)
3369 tax_treatment
3370 , rgp.cle_id asset_id
3371 , txs.id tax_header_id
3372 , txl.tax_line_id tax_line_id
3373 , txl.tax_amt tax_amount
3374 FROM OKC_RULES_V rul
3375 , OKC_RULE_GROUPS_V rgp
3376 , okl_tax_sources txs
3377 , zx_lines txl
3378 WHERE rul.rgp_id = rgp.id
3379 AND rgp.dnz_chr_id = p_contract_id
3380 AND rgp.rgd_code = 'LAASTX'
3381 AND rul.rule_information_category = 'LAASTX'
3382 AND (rul.rule_information11 = p_default_tax_treatment
3383 OR
3384 rul.rule_information11 IS NULL)
3385 AND txs.khr_id = rgp.dnz_chr_id
3386 AND txs.kle_id = rgp.cle_id
3387 AND txs.kle_id IS NOT NULL
3388 AND txs.TAX_LINE_STATUS_CODE = 'INACTIVE'
3389 AND txs.TAX_CALL_TYPE_CODE = 'UPFRONT_TAX'
3390 AND txs.trx_id = txl.trx_id
3391 AND txs.trx_line_id = txl.trx_line_id
3392 AND txl.entity_code IN ('CONTRACTS','ASSETS')
3393 AND txl.event_class_code IN ('BOOKING','ASSET_RELOCATION')
3394 AND txs.entity_code = txl.entity_code
3395 AND txs.event_class_code = txl.event_class_code
3396 AND txl.application_id = 540
3397 AND txl.trx_level_type = 'LINE'
3398 AND txs.application_id = txl.application_id
3399 AND txs.trx_level_type = txl.trx_level_type
3400 AND (txs.trx_id,txs.trx_line_id)
3401 IN
3402 (SELECT adjusted_doc_trx_id
3403 ,adjusted_doc_trx_line_id
3404 FROM okl_tax_sources
3405 WHERE trx_id = p_rbk_trx_id
3406 AND tax_line_status_code = 'INACTIVE'
3407 AND adjusted_doc_trx_id IS NOT NULL
3408 AND adjusted_doc_trx_line_id IS NOT NULL);
3409
3410 --Bug# 6619311
3411 -- Cursor to get reversed tax lines for rebook TRX
3412 -- for assets having tax treatment as Capitalized or Financed
3413 -- when the default tax treatment is Billed
3414 CURSOR rev_taxline_csr2( p_rbk_trx_id NUMBER)
3415 IS
3416 SELECT rul.rule_information11 tax_treatment
3417 , rgp.cle_id asset_id
3418 , txs.id tax_header_id
3419 , txl.tax_line_id tax_line_id
3420 , txl.tax_amt tax_amount
3421 FROM OKC_RULES_V rul
3422 , OKC_RULE_GROUPS_V rgp
3423 , okl_tax_sources txs
3424 , zx_lines txl
3425 WHERE rul.rgp_id = rgp.id
3426 AND rgp.dnz_chr_id = p_contract_id
3427 AND rgp.rgd_code = 'LAASTX'
3428 AND rul.rule_information_category = 'LAASTX'
3429 AND rul.rule_information11 <> 'BILLED'
3430 AND txs.khr_id = rgp.dnz_chr_id
3431 AND txs.kle_id = rgp.cle_id
3432 AND txs.kle_id IS NOT NULL
3433 AND txs.TAX_LINE_STATUS_CODE = 'INACTIVE'
3434 AND txs.TAX_CALL_TYPE_CODE = 'UPFRONT_TAX'
3435 AND txs.trx_id = txl.trx_id
3436 AND txs.trx_line_id = txl.trx_line_id
3437 AND txl.entity_code IN ('CONTRACTS','ASSETS')
3438 AND txl.event_class_code IN ('BOOKING','ASSET_RELOCATION')
3439 AND txs.entity_code = txl.entity_code
3440 AND txs.event_class_code = txl.event_class_code
3441 AND txl.application_id = 540
3442 AND txl.trx_level_type = 'LINE'
3443 AND txs.application_id = txl.application_id
3444 AND txs.trx_level_type = txl.trx_level_type
3445 AND (txs.trx_id,txs.trx_line_id)
3446 IN
3447 (SELECT adjusted_doc_trx_id
3448 ,adjusted_doc_trx_line_id
3449 FROM okl_tax_sources
3450 WHERE trx_id = p_rbk_trx_id
3451 AND tax_line_status_code = 'INACTIVE'
3452 AND adjusted_doc_trx_id IS NOT NULL
3453 AND adjusted_doc_trx_line_id IS NOT NULL);
3454
3455 --Bug# 6619311
3456 -- Cursor to get reversed tax lines for rebook TRX
3457 -- for assets having tax treatment as Billed
3458 -- when the default tax treatment is Capitalized or Financed
3459 CURSOR rev_taxline_csr3( p_rbk_trx_id NUMBER)
3460 IS
3461 SELECT rul.rule_information11 tax_treatment
3462 , rgp.cle_id asset_id
3463 , txs.id tax_header_id
3464 , txl.tax_line_id tax_line_id
3465 , txl.tax_amt tax_amount
3466 FROM OKC_RULES_V rul
3467 , OKC_RULE_GROUPS_V rgp
3468 , okl_tax_sources txs
3469 , zx_lines txl
3470 WHERE rul.rgp_id = rgp.id
3471 AND rgp.dnz_chr_id = p_contract_id
3472 AND rgp.rgd_code = 'LAASTX'
3473 AND rul.rule_information_category = 'LAASTX'
3474 AND rul.rule_information11 = 'BILLED'
3475 AND txs.khr_id = rgp.dnz_chr_id
3476 AND txs.kle_id = rgp.cle_id
3477 AND txs.kle_id IS NOT NULL
3478 AND txs.TAX_LINE_STATUS_CODE = 'INACTIVE'
3479 AND txs.TAX_CALL_TYPE_CODE = 'UPFRONT_TAX'
3480 AND txs.trx_id = txl.trx_id
3481 AND txs.trx_line_id = txl.trx_line_id
3482 AND txl.entity_code IN ('CONTRACTS','ASSETS')
3483 AND txl.event_class_code IN ('BOOKING','ASSET_RELOCATION')
3484 AND txs.entity_code = txl.entity_code
3485 AND txs.event_class_code = txl.event_class_code
3486 AND txl.application_id = 540
3487 AND txl.trx_level_type = 'LINE'
3488 AND txs.application_id = txl.application_id
3489 AND txs.trx_level_type = txl.trx_level_type
3490 AND (txs.trx_id,txs.trx_line_id)
3491 IN
3492 (SELECT adjusted_doc_trx_id
3493 ,adjusted_doc_trx_line_id
3494 FROM okl_tax_sources
3495 WHERE trx_id = p_rbk_trx_id
3496 AND tax_line_status_code = 'INACTIVE'
3497 AND adjusted_doc_trx_id IS NOT NULL
3498 AND adjusted_doc_trx_line_id IS NOT NULL);
3499
3500 --Bug# 6619311
3501 -- Cursor to get reversed tax lines for rebook TRX
3502 -- for contract level taxes
3503 CURSOR rev_taxline_csr4( p_rbk_trx_id NUMBER)
3504 IS
3505 SELECT 'BILLED' tax_treatment
3506 , txs.kle_id asset_id
3507 , txs.id tax_header_id
3508 , txl.tax_line_id tax_line_id
3509 , txl.tax_amt tax_amount
3510 FROM okl_tax_sources txs
3511 , zx_lines txl
3512 WHERE txs.khr_id = p_contract_id
3513 AND txs.kle_id IS NULL
3514 AND txs.TAX_LINE_STATUS_CODE = 'INACTIVE'
3515 AND txs.TAX_CALL_TYPE_CODE = 'UPFRONT_TAX'
3516 AND txs.trx_id = txl.trx_id
3517 AND txs.trx_line_id = txl.trx_line_id
3518 AND txl.entity_code = 'CONTRACTS'
3519 AND txl.event_class_code = 'BOOKING'
3520 AND txs.entity_code = txl.entity_code
3521 AND txs.event_class_code = txl.event_class_code
3522 AND txl.application_id = 540
3523 AND txl.trx_level_type = 'LINE'
3524 AND txs.application_id = txl.application_id
3525 AND txs.trx_level_type = txl.trx_level_type
3526 AND (txs.trx_id,txs.trx_line_id)
3527 IN
3528 (SELECT adjusted_doc_trx_id
3529 ,adjusted_doc_trx_line_id
3530 FROM okl_tax_sources
3531 WHERE trx_id = p_rbk_trx_id
3532 AND tax_line_status_code = 'INACTIVE'
3533 AND adjusted_doc_trx_id IS NOT NULL
3534 AND adjusted_doc_trx_line_id IS NOT NULL);
3535
3536 l_tclv_tbl okl_trx_contracts_pvt.tclv_tbl_type;
3537 x_tclv_tbl okl_trx_contracts_pvt.tclv_tbl_type;
3538
3539
3540 l_tmpl_identify_rec okl_account_dist_pvt.tmpl_identify_rec_type;
3541 l_tmpl_identify_tbl okl_account_dist_pvt.tmpl_identify_tbl_type;
3542 l_template_tbl okl_account_dist_pvt.avlv_tbl_type;
3543 l_dist_info_tbl okl_account_dist_pvt.dist_info_tbl_type;
3544 l_template_out_tbl okl_account_dist_pvt.avlv_out_tbl_type;
3545 l_amount_tbl okl_account_dist_pvt.amount_out_tbl_type;
3546 l_ctxt_val_tbl okl_account_dist_pvt.CTXT_VAL_TBL_TYPE;
3547 l_acc_gen_tbl okl_account_dist_pvt.ACC_GEN_TBL_TYPE;
3548 l_ctxt_tbl okl_account_dist_pvt.CTXT_TBL_TYPE;
3549
3550 counter NUMBER := 0;
3551 j NUMBER := 0;
3552 l_trx_id NUMBER;
3553 l_fnd_rec fnd_lookups_csr%ROWTYPE;
3554 l_trxh_out_rec Okl_Trx_Contracts_Pvt.tcnv_rec_type;
3555 l_financed_sty_id NUMBER;
3556 l_capitalized_sty_id NUMBER;
3557 l_upfront_trx_exists NUMBER := 0;
3558 l_rule_info_csr rule_info_csr%ROWTYPE;
3559 subtype ac_tax_line_rec is tax_line_csr2%ROWTYPE;
3560 TYPE ac_tax_line_tbl IS TABLE OF ac_tax_line_rec
3561 INDEX BY BINARY_INTEGER;
3562 l_accoutable_tax_lines ac_tax_line_tbl;
3563 l_fact_synd_code FND_LOOKUPS.Lookup_code%TYPE;
3564 l_inv_acct_code OKC_RULES_B.Rule_Information1%TYPE;
3565 upfront_tax_acct_exception EXCEPTION;
3566
3567 --Bug# 6619311
3568 l_billed_sty_id NUMBER;
3569 l_transaction_amount NUMBER;
3570
3571 BEGIN
3572
3573 okl_debug_pub.logmessage('OKL: UPF A/C : START');
3574
3575 x_return_status := Okl_Api.G_RET_STS_SUCCESS;
3576
3577 IF (G_IS_DEBUG_STATEMENT_ON = TRUE)
3578 THEN
3579 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT
3580 , G_MODULE
3581 , 'OKL: Booking Procedure: deriving Accounting option ');
3582 END IF;
3583
3584 OPEN acct_opt_csr;
3585 FETCH acct_opt_csr INTO l_acct_opt;
3586
3587 IF acct_opt_csr%NOTFOUND
3588 THEN
3589 OKL_API.set_message( p_app_name => G_APP_NAME,
3590 p_msg_name => 'OKL_LA_ST_ACCT_ERROR');
3591 CLOSE acct_opt_csr;
3592 RAISE upfront_tax_acct_exception;
3593 END IF;
3594
3595 CLOSE acct_opt_csr;
3596
3597 IF (G_IS_DEBUG_STATEMENT_ON = TRUE)
3598 THEN
3599 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT
3600 , G_MODULE
3601 , 'OKL: Booking Procedure: Validating Accounting option ');
3602 END IF;
3603
3604 IF (l_acct_opt IS NULL)
3605 THEN
3606 OKL_API.set_message( p_app_name => G_APP_NAME,
3607 p_msg_name => 'OKL_LA_ST_ACCT_ERROR');
3608 RAISE upfront_tax_acct_exception;
3609 END IF;
3610
3611 OPEN rule_info_csr(p_contract_id);
3612 FETCH rule_info_csr INTO l_rule_info_csr;
3613 CLOSE rule_info_csr;
3614
3615 -- execute the whole logic only if AMB is enabled, otherwise get out
3616 IF (l_acct_opt <> 'AMB' )
3617 THEN
3618 NULL;
3619 ELSE
3620
3621 IF (G_IS_DEBUG_STATEMENT_ON = TRUE)
3622 THEN
3623 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT
3624 , G_MODULE
3625 ,'OKL: create_upfront_tax_accounting Procedure : before fnd_lookups_csr ');
3626 END IF;
3627
3628 OPEN fnd_lookups_csr('OKL_TCN_TYPE', 'Upfront Tax');
3629 FETCH fnd_lookups_csr INTO l_fnd_rec;
3630
3631 IF fnd_lookups_csr%NOTFOUND
3632 THEN
3633 Okl_Api.SET_MESSAGE( G_APP_NAME
3634 ,G_INVALID_VALUE
3635 ,'TRANSACTION_TYPE'
3636 ,'Upfront Tax');
3637 CLOSE fnd_lookups_csr;
3638 RAISE upfront_tax_acct_exception;
3639 END IF;
3640
3641 CLOSE fnd_lookups_csr;
3642
3643 -- Get Stream ID's for 'Financed' and 'Capitalized' Fee stream purposes,
3644 -- this ID will be populated in OKL_TXL_CNTRCT_LNS depending on
3645 -- each inserted record's tax treatment
3646
3647 IF (G_IS_DEBUG_STATEMENT_ON = TRUE)
3648 THEN
3649 OKL_DEBUG_PUB.LOG_DEBUG( FND_LOG.LEVEL_STATEMENT
3650 ,G_MODULE
3651 ,'OKL: create_upfront_tax_accounting Procedure: deriving financed stream ID ');
3652 END IF;
3653
3654 OKL_STREAMS_UTIL.get_primary_stream_type(
3655 p_khr_id => p_contract_id,
3656 p_primary_sty_purpose => 'UPFRONT_TAX_FINANCED',
3657 x_return_status => x_return_status,
3658 x_primary_sty_id => l_financed_sty_id);
3659
3660 okl_debug_pub.logmessage('OKL: UPF A/C : UPFRONT_TAX_FINANCED : '||l_financed_sty_id);
3661
3662 IF (x_return_status <> Okl_Api.G_RET_STS_SUCCESS)
3663 THEN
3664 RAISE upfront_tax_acct_exception;
3665 End If;
3666
3667 IF (G_IS_DEBUG_STATEMENT_ON = TRUE)
3668 THEN
3669 OKL_DEBUG_PUB.LOG_DEBUG( FND_LOG.LEVEL_STATEMENT
3670 ,G_MODULE
3671 ,'OKL: create_upfront_tax_accounting Procedure: deriving capitalized stream ID ');
3672 END IF;
3673
3674 OKL_STREAMS_UTIL.get_primary_stream_type(
3675 p_khr_id => p_contract_id,
3676 p_primary_sty_purpose => 'UPFRONT_TAX_CAPITALIZED',
3677 x_return_status => x_return_status,
3678 x_primary_sty_id => l_capitalized_sty_id);
3679
3680 okl_debug_pub.logmessage('OKL: UPF A/C : UPFRONT_TAX_CAPITALIZED : '||l_capitalized_sty_id);
3681
3682 IF (x_return_status <> Okl_Api.G_RET_STS_SUCCESS) THEN
3683 RAISE upfront_tax_acct_exception;
3684 End If;
3685
3686 --Bug# 6619311
3687 IF (G_IS_DEBUG_STATEMENT_ON = TRUE)
3688 THEN
3689 OKL_DEBUG_PUB.LOG_DEBUG( FND_LOG.LEVEL_STATEMENT
3690 ,G_MODULE
3691 ,'OKL: create_upfront_tax_accounting Procedure: deriving billed stream ID ');
3692 END IF;
3693
3694 OKL_STREAMS_UTIL.get_primary_stream_type(
3695 p_khr_id => p_contract_id,
3696 p_primary_sty_purpose => 'UPFRONT_TAX_BILLED',
3697 x_return_status => x_return_status,
3698 x_primary_sty_id => l_billed_sty_id);
3699
3700 okl_debug_pub.logmessage('OKL: UPF A/C : UPFRONT_TAX_BILLED : '||l_billed_sty_id);
3701
3702 IF (x_return_status <> Okl_Api.G_RET_STS_SUCCESS) THEN
3703 RAISE upfront_tax_acct_exception;
3704 End If;
3705 --End Bug# 6619311
3706
3707 IF (G_IS_DEBUG_STATEMENT_ON = TRUE)
3708 THEN
3709 OKL_DEBUG_PUB.LOG_DEBUG( FND_LOG.LEVEL_STATEMENT
3710 ,G_MODULE
3711 ,'OKL: create_upfront_tax_accounting Procedure: deriving default tax treatment ');
3712 END IF;
3713
3714 -- For Rebook transactions a reversal TRX needs to be created
3715 -- prior to an activation TRX. Hence this condition to perform
3716 -- reversal a/c
3717 IF (p_transaction_type = 'Rebook')
3718 THEN
3719
3720 l_upfront_trx_exists := 0;
3721
3722 OPEN check_upfront_trx_csr;
3723 FETCH check_upfront_trx_csr INTO l_upfront_trx_exists;
3724 CLOSE check_upfront_trx_csr;
3725
3726 -- Perform Rebook reversal a/c only if previous 'Upfront Tax' exists.
3727 IF (l_upfront_trx_exists = 1)
3728 THEN
3729
3730 IF (G_IS_DEBUG_STATEMENT_ON = TRUE)
3731 THEN
3732 OKL_DEBUG_PUB.LOG_DEBUG( FND_LOG.LEVEL_STATEMENT
3733 ,G_MODULE
3734 ,'OKL: create_upfront_tax_accounting Procedure: deriving asset tax information ');
3735 END IF;
3736
3737 --Bug# 6619311
3738 l_accoutable_tax_lines.DELETE;
3739 j := 0;
3740 l_trx_id := NULL;
3741 l_trxh_out_rec := NULL;
3742 l_tclv_tbl.DELETE;
3743 l_acc_gen_tbl.DELETE;
3744 l_tmpl_identify_tbl.DELETE;
3745 l_dist_info_tbl.DELETE;
3746 l_ctxt_tbl.DELETE;
3747
3748 -- Derive accountable tax lines, based on default tax treatment,
3749 -- into temporary table prior to processing
3750 IF (l_rule_info_csr.rule_information1 <> 'BILLED')
3751 THEN
3752 --Bug# 6619311: Fetch tax lines for assets having tax treatment as
3753 -- Capitalized or Financed
3754 FOR i IN rev_taxline_csr1( p_transaction_id
3755 , l_rule_info_csr.rule_information1)
3756 LOOP
3757 j := j+1;
3758 l_accoutable_tax_lines(j) := i;
3759 END LOOP;
3760
3761 --Bug# 6619311: Fetch tax lines for assets having tax treatment as
3762 -- Billed
3763 FOR i IN rev_taxline_csr3( p_transaction_id )
3764 LOOP
3765 j := j+1;
3766 l_accoutable_tax_lines(j) := i;
3767 END LOOP;
3768
3769 ELSE
3770 --Bug# 6619311: Fetch tax lines for assets having tax treatment as
3771 -- Billed
3772 FOR i IN rev_taxline_csr1( p_transaction_id
3773 , l_rule_info_csr.rule_information1)
3774 LOOP
3775 j := j+1;
3776 l_accoutable_tax_lines(j) := i;
3777 END LOOP;
3778
3779 --Bug# 6619311: Fetch tax lines for assets having tax treatment as
3780 -- Capitalized or Financed
3781 FOR i IN rev_taxline_csr2( p_transaction_id )
3782 LOOP
3783 j := j+1;
3784 l_accoutable_tax_lines(j) := i;
3785 END LOOP;
3786 END IF;
3787
3788 --Bug# 6619311: Fetch tax lines for contract level taxes
3789 FOR i IN rev_taxline_csr4( p_transaction_id )
3790 LOOP
3791 j := j+1;
3792 l_accoutable_tax_lines(j) := i;
3793 END LOOP;
3794
3795
3796 --Bug# 7506009
3797 -- Create Upfront Tax accounting only if Tax lines exist
3798 IF (l_accoutable_tax_lines.COUNT > 0) THEN
3799
3800 --Bug# 6619311
3801 l_transaction_amount := 0;
3802 FOR i IN l_accoutable_tax_lines.FIRST..l_accoutable_tax_lines.LAST
3803 LOOP
3804 l_transaction_amount := l_transaction_amount + (-1 * l_accoutable_tax_lines(i).tax_amount);
3805 END LOOP;
3806
3807 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
3808 OKL_DEBUG_PUB.LOG_DEBUG( FND_LOG.LEVEL_STATEMENT
3809 , G_MODULE
3810 ,'OKL: create_upfront_tax_accounting Procedure: Calling populate_transaction procedure ');
3811 END IF;
3812
3813 -- Create Upfront Tax Header TRX record in OKL_TRX_CONTRACTS table
3814 populate_transaction(
3815 p_api_version => p_api_version,
3816 p_init_msg_list => p_init_msg_list,
3817 p_contract_id => p_contract_id,
3818 p_transaction_type => 'Upfront Tax',
3819 p_transaction_id => NULL,
3820 p_source_trx_id => p_transaction_id,
3821 p_source_trx_type => 'TCN',
3822 --Bug# 6619311
3823 p_transaction_amount => l_transaction_amount,
3824 x_transaction_id => l_trx_id,
3825 x_trxh_out_rec => l_trxh_out_rec,
3826 x_return_status => x_return_status,
3827 x_msg_count => x_msg_count,
3828 x_msg_data => x_msg_data);
3829
3830 okl_debug_pub.logmessage('OKL: UPF A/C : populate_transaction : return status '||x_return_status);
3831 -- check transaction creation was successful
3832 IF (x_return_status <> Okl_Api.G_RET_STS_SUCCESS)
3833 THEN
3834 RAISE upfront_tax_acct_exception;
3835 End If;
3836
3837 -- Get Asset tax treatment (Financed or Capitalized),
3838 -- Tax line Amount for each asset, etc., for processing reversal
3839 FOR i IN l_accoutable_tax_lines.FIRST..l_accoutable_tax_lines.LAST
3840 LOOP
3841
3842 -- Populate TRX line array
3843 l_tclv_tbl(i).line_number := i;
3844 l_tclv_tbl(i).tcn_id := l_trx_id;
3845 l_tclv_tbl(i).khr_id := p_contract_id;
3846 l_tclv_tbl(i).kle_id := l_accoutable_tax_lines(i).asset_id;
3847 l_tclv_tbl(i).tcl_type := l_fnd_rec.lookup_code;
3848 l_tclv_tbl(i).tax_line_id := l_accoutable_tax_lines(i).tax_line_id;
3849 l_tclv_tbl(i).amount := -1 * l_accoutable_tax_lines(i).tax_amount; -- (-ve) amount
3850 l_tclv_tbl(i).currency_code :=l_trxh_out_rec.currency_code;
3851
3852 IF (l_accoutable_tax_lines(i).tax_treatment = 'FINANCE')
3853 THEN
3854 l_tclv_tbl(i).sty_id := l_financed_sty_id;
3855 END IF;
3856
3857 IF (l_accoutable_tax_lines(i).tax_treatment = 'CAPITALIZE')
3858 THEN
3859 l_tclv_tbl(i).sty_id := l_capitalized_sty_id;
3860 END IF;
3861
3862 --Bug# 6619311
3863 IF (l_accoutable_tax_lines(i).tax_treatment = 'BILLED')
3864 THEN
3865 l_tclv_tbl(i).sty_id := l_billed_sty_id;
3866 END IF;
3867 --End Bug# 6619311
3868
3869 END LOOP;
3870
3871 -- Create TRX lines with the data gathered
3872
3873 IF (G_IS_DEBUG_STATEMENT_ON = TRUE)
3874 THEN
3875 OKL_DEBUG_PUB.LOG_DEBUG( FND_LOG.LEVEL_STATEMENT
3876 ,G_MODULE
3877 , 'OKL: create_upfront_tax_accounting Procedure: Calling Okl_Trx_Contracts_Pub.create_trx_cntrct_lines ');
3878 END IF;
3879
3880 Okl_Trx_Contracts_Pub.create_trx_cntrct_lines(
3881 p_api_version => p_api_version,
3882 p_init_msg_list => p_init_msg_list,
3883 x_return_status => x_return_status,
3884 x_msg_count => x_msg_count,
3885 x_msg_data => x_msg_data,
3886 p_tclv_tbl => l_tclv_tbl,
3887 x_tclv_tbl => x_tclv_tbl);
3888
3889 okl_debug_pub.logmessage('OKL: UPF A/C : create_trx_cntrct_lines : '||x_return_status);
3890
3891 -- check transaction line creation was successful
3892 IF (x_return_status <> Okl_Api.G_RET_STS_SUCCESS)
3893 THEN
3894 RAISE upfront_tax_acct_exception;
3895 END IF;
3896
3897 -- Populate accounting API data structures
3898 populate_account_data(
3899 p_api_version
3900 ,p_init_msg_list
3901 ,l_trxh_out_rec
3902 ,x_tclv_tbl
3903 ,l_acc_gen_tbl
3904 ,l_tmpl_identify_tbl
3905 ,l_dist_info_tbl
3906 ,x_return_status
3907 ,x_msg_count
3908 ,x_msg_data);
3909
3910 okl_debug_pub.logmessage('OKL: UPF A/C : populate_account_data : '||x_return_status);
3911
3912 -- check transaction line creation was successful
3913 IF (x_return_status <> Okl_Api.G_RET_STS_SUCCESS)
3914 THEN
3915 RAISE upfront_tax_acct_exception;
3916 END IF;
3917
3918 IF (G_IS_DEBUG_STATEMENT_ON = TRUE)
3919 THEN
3920 OKL_DEBUG_PUB.LOG_DEBUG( FND_LOG.LEVEL_STATEMENT
3921 ,G_MODULE
3922 ,'OKL: create_upfront_tax_accounting Procedure: Calling Okl_Account_Dist_Pub.CREATE_ACCOUNTING_DIST');
3923 END IF;
3924
3925 okl_account_dist_pvt.create_accounting_dist(
3926 p_api_version => 1.0,
3927 p_init_msg_list => p_init_msg_list,
3928 x_return_status => x_return_status,
3929 x_msg_count => x_msg_count,
3930 x_msg_data => x_msg_data,
3931 p_tmpl_identify_tbl => l_tmpl_identify_tbl,
3932 p_dist_info_tbl => l_dist_info_tbl,
3933 p_ctxt_val_tbl => l_ctxt_tbl,
3934 p_acc_gen_primary_key_tbl => l_acc_gen_tbl,
3935 x_template_tbl => l_template_out_tbl,
3936 x_amount_tbl => l_amount_tbl,
3937 p_trx_header_id => l_trxh_out_rec.id);
3938
3939 IF (x_return_status <> Okl_Api.G_RET_STS_SUCCESS)
3940 THEN
3941 RAISE upfront_tax_acct_exception;
3942 END IF;
3943
3944 OKL_MULTIGAAP_ENGINE_PVT.CREATE_SEC_REP_TRX
3945 (p_api_version => p_api_version
3946 ,p_init_msg_list => p_init_msg_list
3947 ,x_return_status => x_return_status
3948 ,x_msg_count => x_msg_count
3949 ,x_msg_data => x_msg_data
3950 ,P_TCNV_REC => l_trxh_out_rec
3951 ,P_TCLV_TBL => x_tclv_tbl
3952 ,p_ctxt_val_tbl => l_ctxt_tbl
3953 ,p_acc_gen_primary_key_tbl => l_acc_gen_tbl(1).acc_gen_key_tbl);
3954
3955 IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
3956 RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
3957 ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
3958 RAISE Okl_Api.G_EXCEPTION_ERROR;
3959 END IF;
3960
3961 END IF;
3962 --Bug# 7506009
3963
3964 END IF; -- upfront tax exists
3965 END IF; -- Rebook condition
3966
3967
3968 --Bug# 6619311
3969 l_accoutable_tax_lines.DELETE;
3970 j := 0;
3971 l_trx_id := NULL;
3972 l_trxh_out_rec := NULL;
3973 l_tclv_tbl.DELETE;
3974 l_acc_gen_tbl.DELETE;
3975 l_tmpl_identify_tbl.DELETE;
3976 l_dist_info_tbl.DELETE;
3977 l_ctxt_tbl.DELETE;
3978
3979 IF (G_IS_DEBUG_STATEMENT_ON = TRUE)
3980 THEN
3981 OKL_DEBUG_PUB.LOG_DEBUG( FND_LOG.LEVEL_STATEMENT
3982 ,G_MODULE
3983 ,'OKL: create_upfront_tax_accounting Procedure: deriving asset tax information ');
3984 END IF;
3985
3986 -- Derive accountable tax lines, based on default tax treatment,
3987 -- into temporary table prior to processing
3988 IF (l_rule_info_csr.rule_information1 <> 'BILLED')
3989 THEN
3990
3991 --Bug# 6619311: Fetch tax lines for assets having tax treatment as
3992 -- Capitalized or Financed
3993 FOR i IN tax_line_csr1(p_default_tax_treatment => l_rule_info_csr.rule_information1)
3994 LOOP
3995 j := j+1;
3996 l_accoutable_tax_lines(j) := i;
3997 END LOOP;
3998
3999 --Bug# 6619311: Fetch tax lines for assets having tax treatment as
4000 -- Billed
4001 FOR i IN tax_line_csr3
4002 LOOP
4003 j := j+1;
4004 l_accoutable_tax_lines(j) := i;
4005 END LOOP;
4006
4007 ELSE
4008
4009 --Bug# 6619311: Fetch tax lines for assets having tax treatment as
4010 -- Billed
4011 FOR i IN tax_line_csr1(p_default_tax_treatment => l_rule_info_csr.rule_information1)
4012 LOOP
4013 j := j+1;
4014 l_accoutable_tax_lines(j) := i;
4015 END LOOP;
4016
4017 --Bug# 6619311: Fetch tax lines for assets having tax treatment as
4018 -- Capitalized or Financed
4019 FOR i IN tax_line_csr2
4020 LOOP
4021 j := j+1;
4022 l_accoutable_tax_lines(j) := i;
4023 END LOOP;
4024
4025 END IF;
4026
4027 --Bug# 6619311: Fetch tax lines for contract level taxes
4028 FOR i IN tax_line_csr4
4029 LOOP
4030 j := j+1;
4031 l_accoutable_tax_lines(j) := i;
4032 END LOOP;
4033
4034
4035 --Bug# 7506009
4036 -- Create Upfront Tax accounting only if Tax lines exist
4037 IF (l_accoutable_tax_lines.COUNT > 0) THEN
4038
4039 --Bug# 6619311
4040 l_transaction_amount := 0;
4041 FOR i IN l_accoutable_tax_lines.FIRST..l_accoutable_tax_lines.LAST
4042 LOOP
4043 l_transaction_amount := l_transaction_amount + l_accoutable_tax_lines(i).tax_amount;
4044 END LOOP;
4045
4046 IF (G_IS_DEBUG_STATEMENT_ON = TRUE)
4047 THEN
4048 OKL_DEBUG_PUB.LOG_DEBUG( FND_LOG.LEVEL_STATEMENT
4049 , G_MODULE
4050 ,'OKL: create_upfront_tax_accounting Procedure: Calling populate_transaction procedure ');
4051 END IF;
4052
4053 -- Create Upfront Tax Header TRX record in OKL_TRX_CONTRACTS table
4054 populate_transaction(
4055 p_api_version => p_api_version,
4056 p_init_msg_list => p_init_msg_list,
4057 p_contract_id => p_contract_id,
4058 p_transaction_type => 'Upfront Tax',
4059 p_transaction_id => NULL,
4060 p_source_trx_id => p_transaction_id,
4061 p_source_trx_type => 'TCN',
4062 --Bug# 6619311
4063 p_transaction_amount => l_transaction_amount,
4064 x_transaction_id => l_trx_id,
4065 x_trxh_out_rec => l_trxh_out_rec,
4066 x_return_status => x_return_status,
4067 x_msg_count => x_msg_count,
4068 x_msg_data => x_msg_data);
4069
4070 okl_debug_pub.logmessage('OKL: UPF A/C : populate_transaction : return status '||x_return_status);
4071
4072 -- check transaction creation was successful
4073 IF (x_return_status <> Okl_Api.G_RET_STS_SUCCESS)
4074 THEN
4075 RAISE upfront_tax_acct_exception;
4076 END IF;
4077
4078 -- Get Asset tax treatment (Financed or Capitalized), Tax line Amount for each asset, etc., for processing
4079 FOR i IN l_accoutable_tax_lines.FIRST..l_accoutable_tax_lines.LAST
4080 LOOP
4081
4082 -- Populate TRX line array
4083 l_tclv_tbl(i).line_number := i;
4084 l_tclv_tbl(i).tcn_id := l_trx_id;
4085 l_tclv_tbl(i).khr_id := p_contract_id;
4086 l_tclv_tbl(i).kle_id := l_accoutable_tax_lines(i).asset_id;
4087 l_tclv_tbl(i).tcl_type := l_fnd_rec.lookup_code;
4088 l_tclv_tbl(i).tax_line_id := l_accoutable_tax_lines(i).tax_line_id;
4089 l_tclv_tbl(i).amount := l_accoutable_tax_lines(i).tax_amount;
4090 l_tclv_tbl(i).currency_code := l_trxh_out_rec.currency_code;
4091
4092 IF (l_accoutable_tax_lines(i).tax_treatment = 'FINANCE') THEN
4093 l_tclv_tbl(i).sty_id := l_financed_sty_id;
4094 END IF;
4095
4096 IF (l_accoutable_tax_lines(i).tax_treatment = 'CAPITALIZE') THEN
4097 l_tclv_tbl(i).sty_id := l_capitalized_sty_id;
4098 END IF;
4099
4100 --Bug# 6619311
4101 IF (l_accoutable_tax_lines(i).tax_treatment = 'BILLED')
4102 THEN
4103 l_tclv_tbl(i).sty_id := l_billed_sty_id;
4104 END IF;
4105 --End Bug# 6619311
4106
4107 END LOOP;
4108
4109 -- Create TRX lines with the data gathered
4110
4111 IF (G_IS_DEBUG_STATEMENT_ON = TRUE)
4112 THEN
4113 OKL_DEBUG_PUB.LOG_DEBUG( FND_LOG.LEVEL_STATEMENT
4114 ,G_MODULE
4115 , 'OKL: create_upfront_tax_accounting Procedure: Calling Okl_Trx_Contracts_Pub.create_trx_cntrct_lines ');
4116 END IF;
4117
4118 Okl_Trx_Contracts_Pub.create_trx_cntrct_lines(
4119 p_api_version => p_api_version,
4120 p_init_msg_list => p_init_msg_list,
4121 x_return_status => x_return_status,
4122 x_msg_count => x_msg_count,
4123 x_msg_data => x_msg_data,
4124 p_tclv_tbl => l_tclv_tbl,
4125 x_tclv_tbl => x_tclv_tbl);
4126
4127 okl_debug_pub.logmessage('OKL: UPF A/C : create_trx_cntrct_lines : '||x_return_status);
4128
4129 -- check transaction line creation was successful
4130 IF (x_return_status <> Okl_Api.G_RET_STS_SUCCESS)
4131 THEN
4132 RAISE upfront_tax_acct_exception;
4133 END IF;
4134
4135 -- Populate accounting API data structures
4136 populate_account_data(
4137 p_api_version
4138 ,p_init_msg_list
4139 ,l_trxh_out_rec
4140 ,x_tclv_tbl
4141 ,l_acc_gen_tbl
4142 ,l_tmpl_identify_tbl
4143 ,l_dist_info_tbl
4144 ,x_return_status
4145 ,x_msg_count
4146 ,x_msg_data);
4147
4148 okl_debug_pub.logmessage('OKL: UPF A/C : populate_account_data : '||x_return_status);
4149
4150 -- check transaction line creation was successful
4151 IF (x_return_status <> Okl_Api.G_RET_STS_SUCCESS)
4152 THEN
4153 RAISE upfront_tax_acct_exception;
4154 END IF;
4155
4156 IF (G_IS_DEBUG_STATEMENT_ON = TRUE)
4157 THEN
4158 OKL_DEBUG_PUB.LOG_DEBUG( FND_LOG.LEVEL_STATEMENT
4159 ,G_MODULE
4160 ,'OKL: create_upfront_tax_accounting Procedure: Calling Okl_Account_Dist_Pub.CREATE_ACCOUNTING_DIST');
4161 END IF;
4162
4163 okl_debug_pub.logmessage('OKL: UPF A/C : before calling okl_account_dist_pvt');
4164
4165 -- Call Accounting API to create distributions
4166 okl_account_dist_pvt.create_accounting_dist(
4167 p_api_version => 1.0,
4168 p_init_msg_list => p_init_msg_list,
4169 x_return_status => x_return_status,
4170 x_msg_count => x_msg_count,
4171 x_msg_data => x_msg_data,
4172 p_tmpl_identify_tbl => l_tmpl_identify_tbl,
4173 p_dist_info_tbl => l_dist_info_tbl,
4174 p_ctxt_val_tbl => l_ctxt_tbl,
4175 p_acc_gen_primary_key_tbl => l_acc_gen_tbl,
4176 x_template_tbl => l_template_out_tbl,
4177 x_amount_tbl => l_amount_tbl,
4178 p_trx_header_id => l_trxh_out_rec.id);
4179
4180 okl_debug_pub.logmessage('OKL: UPF A/C : after calling okl_account_dist_pvt : '|| x_return_status);
4181
4182 IF (x_return_status <> Okl_Api.G_RET_STS_SUCCESS)
4183 THEN
4184 RAISE upfront_tax_acct_exception;
4185 END IF;
4186
4187 OKL_MULTIGAAP_ENGINE_PVT.CREATE_SEC_REP_TRX
4188 (p_api_version => p_api_version
4189 ,p_init_msg_list => p_init_msg_list
4190 ,x_return_status => x_return_status
4191 ,x_msg_count => x_msg_count
4192 ,x_msg_data => x_msg_data
4193 ,P_TCNV_REC => l_trxh_out_rec
4194 ,P_TCLV_TBL => x_tclv_tbl
4195 ,p_ctxt_val_tbl => l_ctxt_tbl
4196 ,p_acc_gen_primary_key_tbl => l_acc_gen_tbl(1).acc_gen_key_tbl);
4197
4198 IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
4199 RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
4200 ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
4201 RAISE Okl_Api.G_EXCEPTION_ERROR;
4202 END IF;
4203
4204 END IF;
4205 --Bug# 7506009
4206
4207 END IF; -- AMB Check
4208
4209 okl_debug_pub.logmessage('OKL: UPF A/C : END');
4210
4211 EXCEPTION
4212 WHEN upfront_tax_acct_exception
4213 THEN
4214 x_return_status := OKL_API.G_RET_STS_ERROR;
4215
4216 END create_upfront_tax_accounting;
4217
4218 -- R12 - END
4219
4220
4221 -- Process to process pre booking tax lines
4222 Procedure process_prebook_tax(
4223 p_api_version IN NUMBER,
4224 p_init_msg_list IN VARCHAR2 DEFAULT Okl_Api.G_FALSE,
4225 p_contract_id IN NUMBER,
4226 p_transaction_id IN NUMBER,
4227 p_transaction_type IN VARCHAR2,
4228 x_return_status OUT NOCOPY VARCHAR2,
4229 x_msg_count OUT NOCOPY NUMBER,
4230 x_msg_data OUT NOCOPY VARCHAR2
4231 )
4232 IS
4233
4234 rule_info_csr_rec rule_info_csr%ROWTYPE;
4235 l_asset_count NUMBER := 0;
4236 l_stream_id NUMBER := 0;
4237 l_fee_type OKC_RULES_B.rule_information1%TYPE;
4238 l_prev_fee_type OKC_RULES_B.rule_information1%TYPE;
4239 l_multiple_fee_type VARCHAR2(1) := Okl_Api.G_FALSE;
4240 pre_book_exception exception;
4241
4242 -- Cursor to check if sales tax fee exists
4243 -- Bug# 6512668: Exclude fee line in Abandoned status
4244 CURSOR check_st_fee_csr(p_chr_id IN NUMBER,
4245 p_fee_type IN VARCHAR2) IS
4246 SELECT cle.id
4247 FROM okc_k_lines_b cle,
4248 okl_k_lines kle
4249 WHERE cle.id = kle.id
4250 AND cle.dnz_chr_id = p_chr_id
4251 AND kle.fee_purpose_code = 'SALESTAX'
4252 AND kle.fee_type = NVL(p_fee_type,kle.fee_type)
4253 AND cle.sts_code <> 'ABANDONED';
4254
4255 l_del_fee_line_id OKC_K_LINES_B.id%TYPE;
4256 l_del_fee_types_rec OKL_MAINTAIN_FEE_PVT.fee_types_rec_type;
4257 l_fee_type_to_delete OKL_K_LINES.fee_type%TYPE;
4258
4259 BEGIN
4260 IF (G_DEBUG_ENABLED = 'Y') THEN
4261 G_IS_DEBUG_STATEMENT_ON := OKL_DEBUG_PUB.CHECK_LOG_ON(G_MODULE, FND_LOG.LEVEL_STATEMENT);
4262 END IF;
4263
4264 x_return_status := Okl_Api.G_RET_STS_SUCCESS;
4265 -- Get rule value to identify upfront tax type
4266
4267 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
4268 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: '||p_transaction_type||' Procedure: START ');
4269 END IF;
4270
4271 OPEN rule_info_csr(p_contract_id);
4272 FETCH rule_info_csr INTO rule_info_csr_rec;
4273 IF rule_info_csr%NOTFOUND THEN
4274 OKL_API.set_message( p_app_name => G_APP_NAME,
4275 p_msg_name => 'OKL_QA_ST_MISSING');
4276 CLOSE rule_info_csr;
4277 RAISE pre_book_exception;
4278 END IF;
4279 CLOSE rule_info_csr;
4280
4281 l_asset_count := 0;
4282 OPEN check_lines_csr (p_contract_id, rule_info_csr_rec.rule_information1);
4283 FETCH check_lines_csr INTO l_asset_count;
4284 CLOSE check_lines_csr;
4285
4286 -- If upfront tax is 'FINANCED'
4287 If (rule_info_csr_rec.rule_information1 = 'FINANCE'
4288 AND
4289 l_asset_count > 0)
4290 THEN
4291 IF (G_IS_DEBUG_STATEMENT_ON = TRUE)
4292 THEN
4293 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: '||p_transaction_type||' Procedure: before calling create fee in FINANCE if');
4294 END IF;
4295 create_fee(
4296 p_api_version => p_api_version,
4297 p_init_msg_list => p_init_msg_list,
4298 p_contract_id => p_contract_id,
4299 p_transaction_id => p_transaction_id,
4300 p_default_feetype => rule_info_csr_rec.rule_information1,
4301 p_required_feetype => rule_info_csr_rec.rule_information1,
4302 p_stream_id => to_number(rule_info_csr_rec.rule_information3),
4303 x_return_status => x_return_status,
4304 x_msg_count => x_msg_count,
4305 x_msg_data => x_msg_data);
4306 -- Check if the call was successful
4307 If (x_return_status <> Okl_Api.G_RET_STS_SUCCESS) then
4308 RAISE pre_book_exception;
4309 End If;
4310
4311 -- R12B Authoring OA Migration
4312 -- Delete Sales Tax Fee of Fee Type Capitalized
4313 l_del_fee_line_id := NULL;
4314
4315 -- Check if Sales Tax Fee exists
4316 OPEN check_st_fee_csr(p_chr_id => p_contract_id,
4317 p_fee_type => 'CAPITALIZED');
4318 FETCH check_st_fee_csr INTO l_del_fee_line_id;
4319 CLOSE check_st_fee_csr;
4320
4321 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
4322 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: '||p_transaction_type||': CAPITALIZED Sales Tax Fee to Delete: '|| l_del_fee_line_id);
4323 END IF;
4324
4325 IF l_del_fee_line_id IS NOT NULL THEN
4326
4327 l_del_fee_types_rec.line_id := l_del_fee_line_id;
4328 l_del_fee_types_rec.dnz_chr_id := p_contract_id;
4329
4330 -- delete fee line
4331 OKL_MAINTAIN_FEE_PVT.delete_fee_type(
4332 p_api_version => p_api_version,
4333 p_init_msg_list => p_init_msg_list,
4334 x_return_status => x_return_status,
4335 x_msg_count => x_msg_count,
4336 x_msg_data => x_msg_data,
4337 p_fee_types_rec => l_del_fee_types_rec
4338 );
4339
4340 IF (G_IS_DEBUG_STATEMENT_ON = true) THEN
4341 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: '||p_transaction_type||' Procedure: after calling OKL_MAINTAIN_FEE_PVT.delete_fee_type: x_return_status '|| x_return_status );
4342 END IF;
4343
4344 -- Check if the call was successful
4345 IF (x_return_status <> Okl_Api.G_RET_STS_SUCCESS) THEN
4346 RAISE pre_book_exception;
4347 END IF;
4348 END IF;
4349 -- R12B Authoring OA Migration
4350
4351 End If;
4352
4353 -- If upfront tax is 'CAPITALIZED'
4354 If (rule_info_csr_rec.rule_information1 = 'CAPITALIZE' AND l_asset_count > 0)
4355 THEN
4356 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
4357 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: '||p_transaction_type||' Procedure: before calling create fee in CAPITALIZE if ');
4358 END IF;
4359 create_fee(
4360 p_api_version => p_api_version,
4361 p_init_msg_list => p_init_msg_list,
4362 p_contract_id => p_contract_id,
4363 p_transaction_id => p_transaction_id,
4364 p_default_feetype => rule_info_csr_rec.rule_information1,
4365 p_required_feetype => rule_info_csr_rec.rule_information1,
4366 p_stream_id => to_number(rule_info_csr_rec.rule_information4),
4367 x_return_status => x_return_status,
4368 x_msg_count => x_msg_count,
4369 x_msg_data => x_msg_data);
4370 -- Check if the call was successful
4371 If (x_return_status <> Okl_Api.G_RET_STS_SUCCESS) then
4372 RAISE pre_book_exception;
4373 End If;
4374
4375 -- R12B Authoring OA Migration
4376 -- Delete Sales Tax Fee of Fee Type Financed
4377 l_del_fee_line_id := NULL;
4378
4379 -- Check if Sales Tax Fee exists
4380 OPEN check_st_fee_csr(p_chr_id => p_contract_id,
4381 p_fee_type => 'FINANCED');
4382 FETCH check_st_fee_csr INTO l_del_fee_line_id;
4383 CLOSE check_st_fee_csr;
4384
4385 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
4386 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: '||p_transaction_type||': FINANCED Sales Tax Fee to Delete: '|| l_del_fee_line_id);
4387 END IF;
4388
4389 IF l_del_fee_line_id IS NOT NULL THEN
4390
4391 l_del_fee_types_rec.line_id := l_del_fee_line_id;
4392 l_del_fee_types_rec.dnz_chr_id := p_contract_id;
4393
4394 -- delete fee line
4395 OKL_MAINTAIN_FEE_PVT.delete_fee_type(
4396 p_api_version => p_api_version,
4397 p_init_msg_list => p_init_msg_list,
4398 x_return_status => x_return_status,
4399 x_msg_count => x_msg_count,
4400 x_msg_data => x_msg_data,
4401 p_fee_types_rec => l_del_fee_types_rec
4402 );
4403
4404 IF (G_IS_DEBUG_STATEMENT_ON = true) THEN
4405 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: '||p_transaction_type||' Procedure: after calling OKL_MAINTAIN_FEE_PVT.delete_fee_type: x_return_status '|| x_return_status );
4406 END IF;
4407
4408 -- Check if the call was successful
4409 IF (x_return_status <> Okl_Api.G_RET_STS_SUCCESS) THEN
4410 RAISE pre_book_exception;
4411 END IF;
4412 END IF;
4413 -- R12B Authoring OA Migration
4414 End If;
4415
4416 -- If upfront tax is 'BILLED'
4417 IF (rule_info_csr_rec.rule_information1 = 'BILLED') THEN
4418
4419 l_multiple_fee_type := Okl_Api.G_FALSE;
4420 l_fee_type := NULL;
4421
4422 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
4423 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: '||p_transaction_type||' Procedure: verifying if multiple fee treatments are selected ');
4424 END IF;
4425 FOR i in check_feetype_csr (p_contract_id)
4426 LOOP
4427 l_fee_type := i.feetype;
4428 IF (l_fee_type <> l_prev_fee_type) THEN
4429 l_multiple_fee_type := Okl_Api.G_TRUE;
4430 EXIT;
4431 END IF;
4432 l_prev_fee_type := i.feetype;
4433 END LOOP;
4434
4435 IF (l_multiple_fee_type = Okl_Api.G_FALSE AND l_fee_type IS NOT NULL)
4436 THEN
4437 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
4438 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: '||p_transaction_type||' Procedure: if multiple fee treatments are NOT selected');
4439 END IF;
4440 IF (l_fee_type = 'FINANCE') THEN
4441 l_stream_id := to_number(rule_info_csr_rec.rule_information3);
4442 END IF;
4443
4444 IF (l_fee_type = 'CAPITALIZE') THEN
4445 l_stream_id := to_number(rule_info_csr_rec.rule_information4);
4446 END IF;
4447
4448 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
4449 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: '||p_transaction_type||' Procedure: before calling create fee for '||l_fee_type|| ' in BILLED if ');
4450 END IF;
4451 create_fee(
4452 p_api_version => p_api_version,
4453 p_init_msg_list => p_init_msg_list,
4454 p_contract_id => p_contract_id,
4455 p_transaction_id => p_transaction_id,
4456 p_default_feetype => 'BILLED',
4457 p_required_feetype => l_fee_type,
4458 p_stream_id => to_number(l_stream_id),
4459 x_return_status => x_return_status,
4460 x_msg_count => x_msg_count,
4461 x_msg_data => x_msg_data);
4462 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
4463 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: '||p_transaction_type||' Procedure: after calling create fee for '||
4464 l_fee_type
4465 || ' in BILLED if return status '|| x_return_status );
4466 END IF;
4467 -- Check if the call was successful
4468 If (x_return_status <> Okl_Api.G_RET_STS_SUCCESS) then
4469 RAISE pre_book_exception;
4470 End If;
4471
4472 -- R12B Authoring OA Migration
4473 -- Delete Sales Tax Fee of Fee Type Financed
4474 l_del_fee_line_id := NULL;
4475 IF (l_fee_type = 'FINANCE') THEN
4476 l_fee_type_to_delete := 'CAPITALIZED';
4477 ELSIF (l_fee_type = 'CAPITALIZE') THEN
4478 l_fee_type_to_delete := 'FINANCED';
4479 END IF;
4480
4481 -- Check if Sales Tax Fee exists
4482 OPEN check_st_fee_csr(p_chr_id => p_contract_id,
4483 p_fee_type => l_fee_type_to_delete);
4484 FETCH check_st_fee_csr INTO l_del_fee_line_id;
4485 CLOSE check_st_fee_csr;
4486
4487 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
4488 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: '||p_transaction_type||': '||l_fee_type_to_delete||' Sales Tax Fee to Delete: '|| l_del_fee_line_id);
4489 END IF;
4490
4491 IF l_del_fee_line_id IS NOT NULL THEN
4492
4493 l_del_fee_types_rec.line_id := l_del_fee_line_id;
4494 l_del_fee_types_rec.dnz_chr_id := p_contract_id;
4495
4496 -- delete fee line
4497 OKL_MAINTAIN_FEE_PVT.delete_fee_type(
4498 p_api_version => p_api_version,
4499 p_init_msg_list => p_init_msg_list,
4500 x_return_status => x_return_status,
4501 x_msg_count => x_msg_count,
4502 x_msg_data => x_msg_data,
4503 p_fee_types_rec => l_del_fee_types_rec
4504 );
4505
4506 IF (G_IS_DEBUG_STATEMENT_ON = true) THEN
4507 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: '||p_transaction_type||' Procedure: after calling OKL_MAINTAIN_FEE_PVT.delete_fee_type: x_return_status '|| x_return_status );
4508 END IF;
4509
4510 -- Check if the call was successful
4511 IF (x_return_status <> Okl_Api.G_RET_STS_SUCCESS) THEN
4512 RAISE pre_book_exception;
4513 END IF;
4514 END IF;
4515 -- R12B Authoring OA Migration
4516 End If;
4517 End If;
4518
4519 -- R12B Authoring OA Migration
4520 -- Delete Sales Tax Fee line if no Assets have tax treatment as Financed or Capitalized
4521 IF (rule_info_csr_rec.rule_information1 IN ('CAPITALIZE','FINANCE') AND l_asset_count = 0) OR
4522 (rule_info_csr_rec.rule_information1 = 'BILLED' AND NVL(l_fee_type,'BILLED') = 'BILLED') THEN
4523
4524 l_del_fee_line_id := NULL;
4525
4526 -- Check if Sales Tax Fee exists
4527 OPEN check_st_fee_csr(p_chr_id => p_contract_id,
4528 p_fee_type => NULL);
4529 FETCH check_st_fee_csr INTO l_del_fee_line_id;
4530 CLOSE check_st_fee_csr;
4531
4532 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
4533 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: '||p_transaction_type||': Sales Tax Fee to Delete: '|| l_del_fee_line_id);
4534 END IF;
4535
4536 IF l_del_fee_line_id IS NOT NULL THEN
4537
4538 l_del_fee_types_rec.line_id := l_del_fee_line_id;
4539 l_del_fee_types_rec.dnz_chr_id := p_contract_id;
4540
4541 -- delete fee line
4542 OKL_MAINTAIN_FEE_PVT.delete_fee_type(
4543 p_api_version => p_api_version,
4544 p_init_msg_list => p_init_msg_list,
4545 x_return_status => x_return_status,
4546 x_msg_count => x_msg_count,
4547 x_msg_data => x_msg_data,
4548 p_fee_types_rec => l_del_fee_types_rec
4549 );
4550
4551 IF (G_IS_DEBUG_STATEMENT_ON = true) THEN
4552 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: '||p_transaction_type||' Procedure: after calling OKL_MAINTAIN_FEE_PVT.delete_fee_type: x_return_status '|| x_return_status );
4553 END IF;
4554
4555 -- Check if the call was successful
4556 IF (x_return_status <> Okl_Api.G_RET_STS_SUCCESS) THEN
4557 RAISE pre_book_exception;
4558 END IF;
4559 END IF;
4560 END IF;
4561 -- R12B Authoring OA Migration
4562
4563 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
4564 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: '||p_transaction_type||' Procedure: END ');
4565 END IF;
4566
4567 Exception
4568 when pre_book_exception then
4569 x_return_status := OKL_API.G_RET_STS_ERROR;
4570
4571 END process_prebook_tax;
4572
4573 -- Procedure to process Booking
4574 Procedure process_booking_tax(
4575 p_api_version IN NUMBER,
4576 p_init_msg_list IN VARCHAR2 DEFAULT okl_Api.G_FALSE,
4577 p_contract_id IN NUMBER,
4578 p_transaction_id IN NUMBER,
4579 p_transaction_type IN VARCHAR2,
4580 x_return_status OUT NOCOPY VARCHAR2,
4581 x_msg_count OUT NOCOPY NUMBER,
4582 x_msg_data OUT NOCOPY VARCHAR2 )
4583 IS
4584
4585 -- Cursor to get contract start date for billing
4586 CURSOR contract_csr IS
4587 SELECT start_date
4588 FROM okc_k_headers_b
4589 WHERE id = p_contract_id;
4590
4591 rule_info_csr_rec rule_info_csr%ROWTYPE;
4592 l_ST_params_exist VARCHAR2(1);
4593 l_api_name CONSTANT VARCHAR(30) := 'process_booking_tax';
4594 l_booking_financed_tax NUMBER;
4595 l_prebook_financed_tax NUMBER;
4596 l_booking_capitalized_tax NUMBER;
4597 L_prebook_capitalized_tax NUMBER;
4598 l_booking_billable_tax NUMBER;
4599 l_contract_start_date OKC_K_HEADERS_B.START_DATE%TYPE;
4600 l_source_table VARCHAR2(30) := 'OKL_TRX_CONTRACTS';
4601 l_billed_assets NUMBER :=0;
4602 l_asset_count NUMBER :=0;
4603 l_multiple_fee_type VARCHAR2(1) := Okl_Api.G_FALSE;
4604 l_fee_type OKC_RULES_B.rule_information1%TYPE;
4605 l_prev_fee_type OKC_RULES_B.rule_information1%TYPE;
4606 l_contract_bill_tax NUMBER :=0;
4607 booking_exception exception;
4608
4609 BEGIN
4610
4611 okl_debug_pub.logmessage('OKL: process_booking_tax : START' );
4612
4613 IF (G_DEBUG_ENABLED = 'Y')
4614 THEN
4615 G_IS_DEBUG_STATEMENT_ON := OKL_DEBUG_PUB.CHECK_LOG_ON(G_MODULE
4616 , FND_LOG.LEVEL_STATEMENT);
4617 END IF;
4618
4619 x_return_status := okl_Api.G_RET_STS_SUCCESS;
4620
4621 IF (G_IS_DEBUG_STATEMENT_ON = TRUE)
4622 THEN
4623 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT
4624 ,G_MODULE
4625 ,'OKL: Booking Procedure: START');
4626 END IF;
4627
4628 -- 1. Check if user selected Sales Tax parameters. There is a posibility
4629 -- user does not create Sales Tax T and C
4630
4631 IF (G_IS_DEBUG_STATEMENT_ON = TRUE)
4632 THEN
4633 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT
4634 ,G_MODULE
4635 ,'OKL: Booking Procedure: before rule_info_csr');
4636 END IF;
4637
4638 OPEN rule_info_csr(p_contract_id);
4639 FETCH rule_info_csr INTO rule_info_csr_rec;
4640
4641 IF rule_info_csr%NOTFOUND
4642 THEN
4643 OKL_API.set_message( p_app_name => G_APP_NAME,
4644 p_msg_name => 'OKL_QA_ST_MISSING');
4645 CLOSE rule_info_csr;
4646 RAISE booking_exception;
4647 END IF;
4648
4649 CLOSE rule_info_csr;
4650
4651 -- Call Tax API
4652 IF (G_IS_DEBUG_STATEMENT_ON = TRUE)
4653 THEN
4654 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT
4655 , G_MODULE
4656 ,'OKL: Booking Procedure: before calling tax API');
4657 END IF;
4658
4659 OKL_PROCESS_SALES_TAX_PUB.calculate_sales_tax(
4660 p_api_version => p_api_version,
4661 p_init_msg_list => p_init_msg_list,
4662 x_return_status => x_return_status,
4663 x_msg_count => x_msg_count,
4664 x_msg_data => x_msg_data,
4665 p_source_trx_id => p_transaction_id,
4666 p_source_trx_name => p_transaction_type,
4667 p_source_table => l_source_table,
4668 p_tax_call_type => 'ACTUAL' );
4669
4670 okl_debug_pub.logmessage('OKL: process_booking_tax : OKL_PROCESS_SALES_TAX_PUB.calculate_sales_tax: ACTUAL : '|| x_return_status );
4671
4672 -- Check if the tax call was successful
4673 IF (x_return_status <> okl_Api.G_RET_STS_SUCCESS)
4674 THEN
4675 RAISE booking_exception;
4676 END IF;
4677
4678 --Bug# 6619311: Create upfront tax accounting for all tax treatments
4679 IF (G_IS_DEBUG_STATEMENT_ON = TRUE)
4680 THEN
4681 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT
4682 ,G_MODULE
4683 ,'OKL: Booking Procedure: Calling create_upfront_tax_accounting ');
4684 END IF;
4685
4686 create_upfront_tax_accounting
4687 (
4688 p_api_version => p_api_version,
4689 p_init_msg_list => p_init_msg_list,
4690 p_contract_id => p_contract_id,
4691 p_transaction_id => p_transaction_id,
4692 p_transaction_type => p_transaction_type,
4693 x_return_status => x_return_status,
4694 x_msg_count => x_msg_count,
4695 x_msg_data => x_msg_data
4696 );
4697
4698 IF (x_return_status <> Okl_Api.G_RET_STS_SUCCESS) THEN
4699 RAISE booking_exception;
4700 END IF;
4701
4702 -- This segment will be executed when user selected Financed or Capitalized
4703 -- T and C but selected billed option for one or more asset at line level
4704 IF (rule_info_csr_rec.rule_information1 = 'CAPITALIZE'
4705 OR
4706 rule_info_csr_rec.rule_information1 = 'FINANCE')
4707 THEN
4708
4709 -- Check if billing required and call billing API as required
4710
4711 --R12B ebTax changes
4712 l_billed_assets := 0;
4713 OPEN billing_required_csr1(p_contract_id,p_transaction_id);
4714 FETCH billing_required_csr1 into l_billed_assets;
4715 CLOSE billing_required_csr1;
4716
4717 --Bug# 6939336
4718 l_contract_bill_tax := 0;
4719 OPEN contract_billing_csr(p_contract_id, p_transaction_id);
4720 FETCH contract_billing_csr INTO l_contract_bill_tax;
4721 CLOSE contract_billing_csr;
4722
4723 --Bug# 6939336
4724 IF (l_billed_assets <> 0 OR l_contract_bill_tax <> 0)
4725 THEN
4726
4727 IF (G_IS_DEBUG_STATEMENT_ON = TRUE)
4728 THEN
4729 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT
4730 , G_MODULE
4731 ,'OKL: Booking Procedure: before contract_csr');
4732 END IF;
4733
4734 OPEN contract_csr;
4735 FETCH contract_csr INTO l_contract_start_date;
4736
4737 IF contract_csr%NOTFOUND
4738 THEN
4739 OKL_API.set_message( p_app_name => G_APP_NAME,
4740 p_msg_name => 'OKL_LA_ST_K_DATE_ERROR');
4741 CLOSE contract_csr;
4742 RAISE booking_exception;
4743 END IF;
4744
4745 CLOSE contract_csr;
4746
4747 OKL_BILL_UPFRONT_TAX_PVT.Bill_Upfront_Tax(
4748 p_api_version => p_api_version,
4749 p_init_msg_list => p_init_msg_list,
4750 p_khr_id => p_contract_id,
4751 p_trx_id => p_transaction_id,
4752 p_invoice_date => l_contract_start_date,
4753 x_return_status => x_return_status,
4754 x_msg_count => x_msg_count,
4755 x_msg_data => x_msg_data);
4756
4757 IF (x_return_status <> Okl_Api.G_RET_STS_SUCCESS) THEN
4758 RAISE booking_exception;
4759 END IF;
4760
4761 END IF;
4762
4763 END IF;
4764
4765 -- But we will bill any amount that comes for Billing Tax
4766 IF (rule_info_csr_rec.rule_information1 = 'BILLED')
4767 THEN
4768
4769 -- Check if any of the assets is financed or capitalized and
4770 -- check tax pre-book and booking tax amounts
4771 l_multiple_fee_type := Okl_Api.G_FALSE;
4772 l_fee_type := NULL;
4773
4774 IF (G_IS_DEBUG_STATEMENT_ON = TRUE)
4775 THEN
4776 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT
4777 , G_MODULE
4778 ,'OKL: Booking Procedure: verifying if multiple fee treatments are selected ');
4779 END IF;
4780
4781 FOR i in check_feetype_csr (p_contract_id)
4782 LOOP
4783 l_fee_type := i.feetype;
4784
4785 IF (l_fee_type <> l_prev_fee_type)
4786 THEN
4787 l_multiple_fee_type := okl_Api.G_TRUE;
4788 EXIT;
4789 END IF;
4790
4791 l_prev_fee_type := i.feetype;
4792 END LOOP;
4793
4794 -- User cannot create both Financed and Capitalized sales tax fee lines
4795 IF (l_multiple_fee_type = okl_Api.G_TRUE)
4796 THEN
4797 OKL_API.set_message( p_app_name => G_APP_NAME,
4798 p_msg_name => 'OKL_LA_ST_MIX_FEE_ERROR');
4799 RAISE booking_exception;
4800 END IF;
4801
4802 -- Now Billing transaction creation logic starts
4803 -- Check if billing required and call billing API as required
4804 l_billed_assets := 0;
4805 OPEN billing_required_csr2(p_contract_id,p_transaction_id);
4806 FETCH billing_required_csr2 into l_billed_assets;
4807 CLOSE billing_required_csr2;
4808
4809 -- R12B eBtax changes
4810 l_contract_bill_tax := 0;
4811 OPEN contract_billing_csr(p_contract_id, p_transaction_id);
4812 FETCH contract_billing_csr INTO l_contract_bill_tax;
4813 CLOSE contract_billing_csr;
4814
4815 -- R12B eBtax changes
4816 IF (l_billed_assets <> 0 OR l_contract_bill_tax <> 0)
4817 THEN
4818 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
4819 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT
4820 , G_MODULE
4821 ,'OKL: Booking Procedure: before contract_csr');
4822 END IF;
4823 OPEN contract_csr;
4824 FETCH contract_csr INTO l_contract_start_date;
4825 IF contract_csr%NOTFOUND THEN
4826 OKL_API.set_message( p_app_name => G_APP_NAME,
4827 p_msg_name => 'OKL_LA_ST_K_DATE_ERROR');
4828 CLOSE contract_csr;
4829 RAISE booking_exception;
4830 END IF;
4831 CLOSE contract_csr;
4832
4833 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
4834 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: Booking Procedure: before OKL_BILL_UPFRONT_TAX_PVT ');
4835 END IF;
4836
4837 OKL_BILL_UPFRONT_TAX_PVT.Bill_Upfront_Tax(
4838 p_api_version => p_api_version,
4839 p_init_msg_list => p_init_msg_list,
4840 p_khr_id => p_contract_id,
4841 p_trx_id => p_transaction_id,
4842 p_invoice_date => l_contract_start_date,
4843 x_return_status => x_return_status,
4844 x_msg_count => x_msg_count,
4845 x_msg_data => x_msg_data);
4846
4847 IF (x_return_status <> Okl_Api.G_RET_STS_SUCCESS) THEN
4848 RAISE booking_exception;
4849 END IF;
4850 END IF;
4851 END IF;
4852
4853 IF (G_IS_DEBUG_STATEMENT_ON = TRUE)
4854 THEN
4855 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT
4856 , G_MODULE
4857 ,'OKL: Booking Procedure: END');
4858 END IF;
4859
4860 okl_debug_pub.logmessage('OKL: process_booking_tax : END' );
4861
4862 Exception
4863 when booking_exception then
4864 x_return_status := OKL_API.G_RET_STS_ERROR;
4865
4866 END process_booking_tax;
4867
4868
4869 -- Procedure to process Booking
4870 Procedure process_rebook_tax(
4871 p_api_version IN NUMBER,
4872 p_init_msg_list IN VARCHAR2 DEFAULT Okl_Api.G_FALSE,
4873 p_contract_id IN NUMBER,
4874 p_transaction_id IN NUMBER,
4875 p_transaction_type IN VARCHAR2,
4876 p_transaction_date IN DATE,
4877 p_rbk_contract_id IN NUMBER,
4878 x_return_status OUT NOCOPY VARCHAR2,
4879 x_msg_count OUT NOCOPY NUMBER,
4880 x_msg_data OUT NOCOPY VARCHAR2 )
4881 IS
4882
4883 -- R12 - START
4884 CURSOR acct_opt_csr
4885 IS
4886 SELECT account_derivation
4887 FROM okl_sys_acct_opts;
4888
4889 l_acct_opt okl_sys_acct_opts.account_derivation%TYPE;
4890 -- R12 - END
4891
4892 l_contract_bill_tax NUMBER :=0;
4893 rule_info_csr_rec rule_info_csr%ROWTYPE;
4894 l_asset_count NUMBER;
4895 l_billed_assets NUMBER :=0;
4896 l_multiple_fee_type VARCHAR2(1) := Okl_Api.G_FALSE;
4897 l_fee_type OKC_RULES_B.rule_information1%TYPE;
4898 l_prev_fee_type OKC_RULES_B.rule_information1%TYPE;
4899 rebook_exception EXCEPTION;
4900
4901 BEGIN
4902
4903 okl_debug_pub.logmessage('OKL: process_rebook_tax : START' );
4904
4905 x_return_status := Okl_Api.G_RET_STS_SUCCESS;
4906
4907 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
4908 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT
4909 ,G_MODULE
4910 ,'OKL: Rebook Procedure: START');
4911 END IF;
4912
4913 OPEN rule_info_csr (p_contract_id);
4914 FETCH rule_info_csr INTO rule_info_csr_rec;
4915
4916 IF rule_info_csr%NOTFOUND
4917 THEN
4918 OKL_API.set_message( p_app_name => G_APP_NAME,
4919 p_msg_name => 'OKL_QA_ST_MISSING');
4920 CLOSE rule_info_csr;
4921 RAISE rebook_exception;
4922 END IF;
4923
4924 CLOSE rule_info_csr;
4925
4926 l_asset_count := 0;
4927 OPEN check_lines_csr (p_contract_id, rule_info_csr_rec.rule_information1);
4928 FETCH check_lines_csr INTO l_asset_count;
4929 CLOSE check_lines_csr;
4930
4931 OKL_PROCESS_SALES_TAX_PUB.calculate_sales_tax(
4932 p_api_version => p_api_version,
4933 p_init_msg_list => p_init_msg_list,
4934 x_return_status => x_return_status,
4935 x_msg_count => x_msg_count,
4936 x_msg_data => x_msg_data,
4937 p_source_trx_id => p_transaction_id,
4938 p_source_trx_name => p_transaction_type,
4939 p_source_table => g_source_table,
4940 p_tax_call_type => 'ACTUAL' );
4941
4942 okl_debug_pub.logmessage('OKL: process_rebook_tax : OKL_PROCESS_SALES_TAX_PUB.calculate_sales_tax: ACTUAL : '|| x_return_status );
4943
4944 -- Check if the tax call was successful
4945 IF (x_return_status <> Okl_Api.G_RET_STS_SUCCESS)
4946 THEN
4947 RAISE rebook_exception;
4948 END IF;
4949
4950 --Bug# 6619311: Create upfront tax accounting for all tax treatments
4951 IF (G_IS_DEBUG_STATEMENT_ON = TRUE)
4952 THEN
4953 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT
4954 ,G_MODULE
4955 ,'OKL: Booking Procedure: Calling create_upfront_tax_accounting ');
4956 END IF;
4957
4958 create_upfront_tax_accounting
4959 (
4960 p_api_version => p_api_version,
4961 p_init_msg_list => p_init_msg_list,
4962 p_contract_id => p_contract_id,
4963 p_transaction_id => p_transaction_id,
4964 p_transaction_type => p_transaction_type,
4965 x_return_status => x_return_status,
4966 x_msg_count => x_msg_count,
4967 x_msg_data => x_msg_data
4968 );
4969
4970 IF (x_return_status <> Okl_Api.G_RET_STS_SUCCESS) THEN
4971 RAISE rebook_exception;
4972 END IF;
4973
4974 -- This segment will be executed when user selected Financed or Capitalized
4975 -- T and C but selected billed option for one or more asset at line level
4976 IF (rule_info_csr_rec.rule_information1 = 'CAPITALIZE'
4977 OR
4978 rule_info_csr_rec.rule_information1 = 'FINANCE')
4979 THEN
4980
4981 -- Check if billing required and call billing API as required
4982 -- R12B eBTax changes
4983 l_billed_assets := 0;
4984 OPEN billing_required_csr1(p_contract_id,p_transaction_id);
4985 FETCH billing_required_csr1 into l_billed_assets;
4986 CLOSE billing_required_csr1;
4987
4988 --Bug# 6939336
4989 l_contract_bill_tax := 0;
4990 OPEN contract_billing_csr(p_contract_id, p_transaction_id);
4991 FETCH contract_billing_csr INTO l_contract_bill_tax;
4992 CLOSE contract_billing_csr;
4993
4994 --Bug# 6939336
4995 IF (l_billed_assets <> 0 OR l_contract_bill_tax <> 0)
4996 THEN
4997
4998 OKL_BILL_UPFRONT_TAX_PVT.Bill_Upfront_Tax(
4999 p_api_version => p_api_version,
5000 p_init_msg_list => p_init_msg_list,
5001 p_khr_id => p_contract_id,
5002 p_trx_id => p_transaction_id,
5003 p_invoice_date => p_transaction_date,
5004 x_return_status => x_return_status,
5005 x_msg_count => x_msg_count,
5006 x_msg_data => x_msg_data);
5007
5008 IF (x_return_status <> Okl_Api.G_RET_STS_SUCCESS) THEN
5009 RAISE rebook_exception;
5010 END IF;
5011
5012 END IF;
5013
5014 END IF; -- rule_info_csr_rec.rule_information1 = 'CAPITALIZE' or 'FINANCED
5015
5016
5017 -- But we will bill any amount that comes for Billing Tax
5018 IF (rule_info_csr_rec.rule_information1 = 'BILLED')
5019 THEN
5020
5021 -- Check if any of the assets is financed or capitalized and
5022 -- check tax pre-book and booking tax amounts
5023 l_multiple_fee_type := Okl_Api.G_FALSE;
5024 l_fee_type := NULL;
5025
5026 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
5027 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT
5028 ,G_MODULE
5029 ,'OKL: Rebook Procedure: verifying if multiple fee treatments are selected ');
5030 END IF;
5031 FOR i in check_feetype_csr (p_contract_id)
5032 LOOP
5033 l_fee_type := i.feetype;
5034 IF (l_fee_type <> l_prev_fee_type) THEN
5035 l_multiple_fee_type := Okl_Api.G_TRUE;
5036 EXIT;
5037 END IF;
5038 l_prev_fee_type := i.feetype;
5039 END LOOP;
5040
5041 -- User cannot create both Financed and Capitalized sales tax fee lines
5042 IF (l_multiple_fee_type = Okl_Api.G_TRUE) THEN
5043 OKL_API.set_message( p_app_name => G_APP_NAME,
5044 p_msg_name => 'OKL_LA_ST_MIX_FEE_ERROR');
5045 RAISE rebook_exception;
5046 END IF;
5047
5048 -- Now Billing transaction creation logic starts
5049 -- Check if billing required and call billing API as required
5050 l_billed_assets := 0;
5051 OPEN billing_required_csr2(p_contract_id,p_transaction_id);
5052 FETCH billing_required_csr2 into l_billed_assets;
5053 CLOSE billing_required_csr2;
5054
5055 -- R12B eBTax changes
5056 l_contract_bill_tax := 0;
5057 OPEN contract_billing_csr(p_contract_id, p_transaction_id);
5058 FETCH contract_billing_csr INTO l_contract_bill_tax;
5059 CLOSE contract_billing_csr;
5060
5061 -- R12B eBtax changes
5062 IF (l_billed_assets <> 0 OR l_contract_bill_tax <> 0) THEN
5063
5064 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
5065 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: Rebook Procedure: before OKL_BILL_UPFRONT_TAX_PVT ');
5066 END IF;
5067
5068 OKL_BILL_UPFRONT_TAX_PVT.Bill_Upfront_Tax(
5069 p_api_version => p_api_version,
5070 p_init_msg_list => p_init_msg_list,
5071 p_khr_id => p_contract_id,
5072 p_trx_id => p_transaction_id,
5073 p_invoice_date => p_transaction_date,
5074 x_return_status => x_return_status,
5075 x_msg_count => x_msg_count,
5076 x_msg_data => x_msg_data);
5077
5078 IF (x_return_status <> Okl_Api.G_RET_STS_SUCCESS) THEN
5079 RAISE rebook_exception;
5080 END IF;
5081
5082 END IF;
5083
5084 END IF; -- rule_info_csr_rec.rule_information1 = 'BILLED'
5085
5086 IF (G_IS_DEBUG_STATEMENT_ON = TRUE)
5087 THEN
5088 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT
5089 ,G_MODULE
5090 ,'OKL: rebook Procedure: END');
5091 END IF;
5092
5093 okl_debug_pub.logmessage('OKL: process_rebook_tax : END' );
5094
5095 Exception
5096 when rebook_exception then
5097 x_return_status := OKL_API.G_RET_STS_ERROR;
5098
5099 END process_rebook_tax;
5100
5101
5102
5103
5104 -- Main proccedure to call for all authoring
5105 -- processes to process upfront sales tax
5106
5107 Procedure process_sales_tax(
5108 p_api_version IN NUMBER,
5109 p_init_msg_list IN VARCHAR2 DEFAULT Okl_Api.G_FALSE,
5110 p_commit IN VARCHAR2 DEFAULT Okl_Api.G_FALSE,
5111 p_contract_id IN NUMBER,
5112 p_transaction_type IN VARCHAR2,
5113 p_transaction_id IN NUMBER DEFAULT NULL,
5114 p_transaction_date IN DATE DEFAULT NULL,
5115 p_rbk_contract_id IN NUMBER DEFAULT NULL,
5116 x_return_status OUT NOCOPY VARCHAR2,
5117 x_msg_count OUT NOCOPY NUMBER,
5118 x_msg_data OUT NOCOPY VARCHAR2) IS
5119
5120 -- Define PL/SQL Records and Tables
5121 l_trxH_in_rec Okl_Trx_Contracts_Pvt.tcnv_rec_type;
5122 l_trxL_in_rec Okl_Trx_Contracts_Pvt.tclv_rec_type;
5123 l_trxH_out_rec Okl_Trx_Contracts_Pvt.tcnv_rec_type;
5124 l_trxL_out_rec Okl_Trx_Contracts_Pvt.tclv_rec_type;
5125
5126 -- Define variables
5127 l_return_status VARCHAR2(1) := Okl_Api.G_RET_STS_SUCCESS;
5128 l_transaction_id NUMBER;
5129 l_has_trans VARCHAR2(1);
5130 -- Bug 4769822 - START
5131 l_contract_id NUMBER;
5132 -- Bug 4769822 - END
5133
5134
5135 -- R12 Change - START
5136 rule_info_csr_rec rule_info_csr%ROWTYPE;
5137 -- R12 Change - END
5138
5139
5140 -- Define constants
5141 l_api_name CONSTANT VARCHAR(30) := 'PROCESS_SALES_TAX';
5142
5143 CURSOR sys_param_csr IS
5144 SELECT nvl(tax_upfront_yn,'N')
5145 --, nvl(tax_schedule_yn,'N') -- added for Bug 4748910 -- Not required in R12
5146 FROM okl_system_params;
5147
5148 -- Cursor Types
5149 l_fnd_rec fnd_lookups_csr%ROWTYPE;
5150
5151 l_transaction_type VARCHAR2(256) := p_transaction_type;
5152 l_source_table VARCHAR2(30) := 'OKL_TRX_CONTRACTS';
5153 l_tax_upfront_yn okl_system_params.tax_upfront_yn%TYPE;
5154 -- l_tax_schedule_yn VARCHAR2(1) := NULL; -- this variable is not required in R12
5155
5156 -- Bug 4748910 - START
5157
5158 CURSOR c_currency_code(p_khr_id IN NUMBER) IS
5159 SELECT start_date, end_date, currency_code
5160 FROM OKC_K_HEADERS_B
5161 WHERE ID = p_contract_id;
5162
5163 CURSOR c_try_type(p_name IN VARCHAR2) IS
5164 SELECT ID
5165 FROM OKL_TRX_TYPES_TL
5166 WHERE name = p_name
5167 AND LANGUAGE = 'US';
5168
5169 l_currency_code VARCHAR2(15);
5170 l_start_date DATE;
5171 l_end_date DATE;
5172 l_try_id NUMBER;
5173 l_try_name VARCHAR2(100) := 'Tax Schedule';
5174 l_trqv_tbl okl_trx_requests_pub.trqv_tbl_type;
5175 x_trqv_tbl okl_trx_requests_pub.trqv_tbl_type;
5176
5177 -- BUG 4748910 - END
5178
5179 -- Bug 6155565
5180 CURSOR l_chk_rel_ast_csr (p_chr_id IN NUMBER) IS
5181 SELECT NVL(rule_information1,'N')
5182 FROM okc_rules_b rul
5183 WHERE rul.dnz_chr_id = p_chr_id
5184 AND rul.rule_information_category = 'LARLES';
5185
5186 l_release_asset_yn VARCHAR2(1);
5187
5188 BEGIN
5189
5190 okl_debug_pub.logmessage('OKL: process_sales_tax : START');
5191
5192 IF (G_DEBUG_ENABLED = 'Y') THEN
5193 G_IS_DEBUG_STATEMENT_ON := OKL_DEBUG_PUB.CHECK_LOG_ON(G_MODULE, FND_LOG.LEVEL_STATEMENT);
5194 END IF;
5195
5196 x_return_status := Okl_Api.G_RET_STS_SUCCESS;
5197
5198 x_return_status := OKL_API.START_ACTIVITY(
5199 p_api_name => l_api_name,
5200 p_pkg_name => g_pkg_name,
5201 p_init_msg_list => p_init_msg_list,
5202 l_api_version => p_api_version,
5203 P_api_version => p_api_version,
5204 p_api_type => G_API_TYPE,
5205 x_return_status => x_return_status);
5206
5207 -- check if activity started successfully
5208 If (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) then
5209 raise OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
5210 ElSIF (x_return_status = OKL_API.G_RET_STS_ERROR) then
5211 raise OKL_API.G_EXCEPTION_ERROR;
5212 End If;
5213
5214 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
5215 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT,
5216 G_MODULE,
5217 'OKL: Process Sales Tax : START ');
5218 END IF;
5219
5220 OPEN sys_param_csr;
5221 FETCH sys_param_csr INTO l_tax_upfront_yn;
5222 IF sys_param_csr%NOTFOUND THEN
5223 Okl_Api.SET_MESSAGE(G_APP_NAME, 'OKL_LA_ST_OU_UPFRONT_TAX_ERROR');
5224 CLOSE sys_param_csr;
5225 RAISE Okl_Api.G_EXCEPTION_ERROR;
5226 END IF;
5227 CLOSE sys_param_csr;
5228
5229
5230 -- First off check upfront tax is enabled, if not
5231 -- Sales Tax processing is not required for the contract
5232 IF (l_tax_upfront_yn = 'Y' ) THEN
5233
5234 -- Bug 6155565
5235 OPEN l_chk_rel_ast_csr(p_contract_id);
5236 FETCH l_chk_rel_ast_csr INTO l_release_asset_yn;
5237 CLOSE l_chk_rel_ast_csr;
5238
5239 IF (l_release_asset_yn = 'Y') THEN
5240 NULL; -- Do not calculate upfront tax for contracts having re-leased assets
5241 ELSE
5242
5243 l_transaction_id := p_transaction_id;
5244
5245 -- Create or update tax transaction
5246 -- In R12, we will no longer create Pre-Rebook
5247 -- TRX as we used to in previous release, OKL.H
5248 -- For Pre-Rebook ebTax calls, we will reuse Rebook
5249 -- TRX. Remove Pre-Rebook reference in the following
5250 -- Code segment
5251
5252 IF (p_transaction_type = 'Pre-Booking') THEN
5253
5254 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
5255 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT,
5256 G_MODULE,
5257 'OKL: Process Sales Tax : before populate_transaction ');
5258 END IF;
5259
5260 -- R12 Change - START
5261
5262 l_contract_id := p_contract_id;
5263
5264 -- create booking transaction at 'Validation' time
5265 -- instead of 'Pre-Booking' transaction
5266 populate_transaction(
5267 p_api_version => p_api_version,
5268 p_init_msg_list => p_init_msg_list,
5269 p_contract_id => l_contract_id,
5270 -- p_transaction_type => p_transaction_type, -- R12 Change
5271 p_transaction_type => 'Booking', -- R12 Change
5272 p_transaction_id => p_transaction_id,
5273 p_source_trx_id => NULL,
5274 p_source_trx_type => NULL,
5275 x_transaction_id => l_transaction_id,
5276 x_trxh_out_rec => l_trxh_out_rec,
5277 x_return_status => x_return_status,
5278 x_msg_count => x_msg_count,
5279 x_msg_data => x_msg_data);
5280
5281 okl_debug_pub.logmessage('OKL: process_sales_tax : populate_transaction : '|| x_return_status );
5282
5283 -- check transaction creation was successful
5284 If (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) then
5285 raise OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
5286 ElSIF (x_return_status = OKL_API.G_RET_STS_ERROR) then
5287 raise OKL_API.G_EXCEPTION_ERROR;
5288 End If;
5289
5290 -- R12 Change - END
5291 End If;
5292
5293 -- Process Pre Booking Tax Call
5294 If (p_transaction_type = 'Pre-Booking'
5295 OR
5296 p_transaction_type = 'Pre-Rebook') -- Bug 4769822
5297 THEN
5298
5299 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
5300 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT,
5301 G_MODULE,
5302 'OKL: Process Sales Tax : '||p_transaction_type||' before calculate_sales_tax ');
5303 END IF;
5304
5305 -- Call Tax API
5306
5307 -- R12 Change - START
5308
5309 IF (p_transaction_type = 'Pre-Booking')
5310 THEN
5311 l_contract_id := p_contract_id;
5312 l_transaction_type := 'Booking';
5313 ELSIF (p_transaction_type = 'Pre-Rebook') THEN
5314 l_contract_id := p_rbk_contract_id;
5315 l_transaction_type := 'Rebook';
5316 End If;
5317
5318 -- R12 Change - END
5319
5320 OKL_PROCESS_SALES_TAX_PUB.calculate_sales_tax(
5321 p_api_version => p_api_version,
5322 p_init_msg_list => p_init_msg_list,
5323 x_return_status => x_return_status,
5324 x_msg_count => x_msg_count,
5325 x_msg_data => x_msg_data,
5326 p_source_trx_id => l_transaction_id,
5327 -- p_source_trx_name => p_transaction_type, -- R12 Change
5328 p_source_trx_name => l_transaction_type, -- R12 Change
5329 p_source_table => l_source_table,
5330 p_tax_call_type => 'ESTIMATED');
5331
5332 okl_debug_pub.logmessage('OKL: process_sales_tax : OKL_PROCESS_SALES_TAX_PUB.calculate_sales_tax: ESTIMATED : '|| x_return_status );
5333
5334 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
5335 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT,
5336 G_MODULE,
5337 'OKL: Process Sales Tax...3'|| x_return_status);
5338 END IF;
5339 -- Check if the tax call was successful
5340 If (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) then
5341 raise OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
5342 ElSIF (x_return_status = OKL_API.G_RET_STS_ERROR) then
5343 raise OKL_API.G_EXCEPTION_ERROR;
5344 End If;
5345
5346 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
5347 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT,
5348 G_MODULE,
5349 'OKL: Process Sales Tax : '||p_transaction_type||' before process_prebook_tax ');
5350 END IF;
5351
5352 process_prebook_tax(
5353 p_api_version => p_api_version,
5354 p_init_msg_list => p_init_msg_list,
5355 p_contract_id => l_contract_id, -- Bug 4769822
5356 p_transaction_id => l_transaction_id,
5357 -- p_transaction_type => p_transaction_type, -- R12 change
5358 p_transaction_type => l_transaction_type, -- R12 change
5359 x_return_status => x_return_status,
5360 x_msg_count => x_msg_count,
5361 x_msg_data => x_msg_data
5362 );
5363
5364 okl_debug_pub.logmessage('OKL: process_sales_tax : process_prebook_tax : '|| x_return_status );
5365
5366 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
5367 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT,
5368 G_MODULE,
5369 'OKL: Process Sales Tax : '||p_transaction_type||
5370 ' after process_prebook_tax: x_return_status' ||x_return_status);
5371 END IF;
5372
5373 -- Check if the call was successful
5374 -- Following code enabled for bug 5005269
5375
5376 If (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) then
5377 raise OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
5378 ElSIF (x_return_status = OKL_API.G_RET_STS_ERROR) then
5379 raise OKL_API.G_EXCEPTION_ERROR;
5380 End If;
5381
5382 End If; -- Prebook
5383
5384 -- Process Booking Activation Tax Call
5385 If (p_transaction_type = 'Booking') THEN
5386
5387 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
5388 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: Process Sales Tax : '||p_transaction_type||' before process_booking_tax ');
5389 END IF;
5390
5391 process_booking_tax(
5392 p_api_version => p_api_version,
5393 p_init_msg_list => p_init_msg_list,
5394 p_contract_id => p_contract_id,
5395 p_transaction_id => l_transaction_id,
5396 p_transaction_type => p_transaction_type,
5397 x_return_status => x_return_status,
5398 x_msg_count => x_msg_count,
5399 x_msg_data => x_msg_data);
5400
5401 okl_debug_pub.logmessage('OKL: process_sales_tax : process_booking_tax : '|| x_return_status );
5402 -- Check if the call was successful
5403 -- Bug 5002042
5404 If (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) then
5405 raise OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
5406 ElSIF (x_return_status = OKL_API.G_RET_STS_ERROR) then
5407 raise OKL_API.G_EXCEPTION_ERROR;
5408 End If;
5409
5410 End If; -- Booking
5411
5412 -- Process Rebook Activation Tax Call
5413 IF (p_transaction_type = 'Rebook') THEN
5414
5415 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
5416 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: Process Sales Tax : '||p_transaction_type||' before process_rebook_tax ');
5417 END IF;
5418
5419 process_rebook_tax(
5420 p_api_version => p_api_version,
5421 p_init_msg_list => p_init_msg_list,
5422 p_contract_id => p_contract_id,
5423 p_transaction_id => p_transaction_id,
5424 p_transaction_type => p_transaction_type,
5425 p_transaction_date => p_transaction_date,
5426 p_rbk_contract_id => p_rbk_contract_id,
5427 x_return_status => x_return_status,
5428 x_msg_count => x_msg_count,
5429 x_msg_data => x_msg_data);
5430
5431 okl_debug_pub.logmessage('OKL: process_sales_tax : process_rebook_tax : '|| x_return_status );
5432
5433 End If; -- Rebook
5434
5435 -- Process Mass Rebook trx
5436 -- R12 Change - Code segment to process 'Mass-Rebook'
5437 -- is removed from this location. It is not required as per IA.
5438 -- If required, take it from OKL.H code line
5439
5440 -- R12 Change - Code segment to update transaction records to 'Processed'
5441 -- is removed from this location. It is not required as per IA.
5442 -- If required, take it from OKL.H code line
5443
5444 END IF; -- Bug 6155565
5445 END IF;
5446
5447 -- R12 Change - Start
5448
5449
5450 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
5451 OKL_DEBUG_PUB.LOG_DEBUG( FND_LOG.LEVEL_STATEMENT
5452 , G_MODULE
5453 ,'OKL: Process Sales Tax : Tax schedule csr ');
5454 END IF;
5455
5456 OPEN rule_info_csr(p_contract_id);
5457 FETCH rule_info_csr INTO rule_info_csr_rec;
5458 IF rule_info_csr%NOTFOUND THEN
5459 -- R12B Authoring OA Migration - Corrected error message
5460 OKL_API.set_message( p_app_name => G_APP_NAME,
5461 p_msg_name => 'OKL_QA_ST_MISSING');
5462 CLOSE rule_info_csr;
5463 RAISE Okl_Api.G_EXCEPTION_ERROR;
5464 END IF;
5465 CLOSE rule_info_csr;
5466
5467 -- R12 Change - End
5468
5469 -- Bug 4748910 - START
5470
5471 -- Process Tax schedule
5472 IF (nvl(rule_info_csr_rec.rule_information5,'N') = 'Y'
5473 AND
5474 (p_transaction_type = 'Booking'
5475 OR
5476 p_transaction_type = 'Rebook')
5477 )
5478 THEN
5479
5480 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
5481 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT,
5482 G_MODULE,
5483 'OKL: Process Sales Tax : START tax schedule ');
5484 END IF;
5485
5486 OPEN c_currency_code(p_contract_id);
5487 FETCH c_currency_code INTO l_start_date, l_end_date, l_currency_code;
5488 CLOSE c_currency_code;
5489 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
5490 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT,
5491 G_MODULE,
5492 'OKL: Process Sales Tax : after currency code csr ');
5493 END IF;
5494
5495 OPEN c_try_type(l_try_name);
5496 FETCH c_try_type INTO l_try_id;
5497 CLOSE c_try_type;
5498
5499 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
5500 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT,
5501 G_MODULE,
5502 'OKL: Process Sales Tax : after try type csr');
5503 END IF;
5504
5505 l_trqv_tbl(1).request_status_code := 'PROCESSED';
5506 l_trqv_tbl(1).request_type_code := 'TAX_SCHEDULES';
5507 l_trqv_tbl(1).dnz_khr_id := p_contract_id;
5508 l_trqv_tbl(1).currency_code := l_currency_code;
5509 l_trqv_tbl(1).start_date := l_start_date;
5510 l_trqv_tbl(1).end_date := l_end_date;
5511 l_trqv_tbl(1).try_id := l_try_id;
5512
5513 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
5514 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT,
5515 G_MODULE,
5516 'OKL: Process Sales Tax : before creating trx requests');
5517 END IF;
5518
5519 okl_trx_requests_pub.insert_trx_requests(
5520 p_api_version => p_api_version,
5521 p_init_msg_list => p_init_msg_list,
5522 x_return_status => x_return_status,
5523 x_msg_count => x_msg_count,
5524 x_msg_data => x_msg_data,
5525 p_trqv_tbl => l_trqv_tbl,
5526 x_trqv_tbl => x_trqv_tbl);
5527
5528 okl_debug_pub.logmessage('OKL: process_sales_tax : okl_trx_requests_pub.insert_trx_requests : '|| x_return_status );
5529
5530 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
5531 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT,
5532 G_MODULE,
5533 'OKL: Process Sales Tax : after creating trx requests: status-> '|| x_return_status);
5534 END IF;
5535
5536 If (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) then
5537 raise OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
5538 ElSIF (x_return_status = OKL_API.G_RET_STS_ERROR) then
5539 raise OKL_API.G_EXCEPTION_ERROR;
5540 End If;
5541
5542 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
5543 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT,
5544 G_MODULE,
5545 'OKL: Process Sales Tax : before OKL_PROCESS_SALES_TAX_PUB');
5546 END IF;
5547
5548 OKL_PROCESS_SALES_TAX_PUB.calculate_sales_tax(
5549 p_api_version => p_api_version,
5550 p_init_msg_list => p_init_msg_list,
5551 x_return_status => x_return_status,
5552 x_msg_count => x_msg_count,
5553 x_msg_data => x_msg_data,
5554 p_source_trx_id => x_trqv_tbl(1).id,
5555 p_source_trx_name => l_try_name,
5556 p_source_table => 'OKL_TRX_REQUESTS',
5557 p_tax_call_type => NULL);
5558
5559 okl_debug_pub.logmessage('OKL: process_sales_tax : after creating tax schedule : '|| x_return_status );
5560
5561 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
5562 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT,
5563 G_MODULE,'OKL: Process Sales Tax : after OKL_PROCESS_SALES_TAX_PUB: status-> '|| x_return_status);
5564 END IF;
5565
5566 -- Check if the tax call was successful
5567 If (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) then
5568 raise OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
5569 ElSIF (x_return_status = OKL_API.G_RET_STS_ERROR) then
5570 raise OKL_API.G_EXCEPTION_ERROR;
5571 End If;
5572
5573 -- R12 Change - Code segment to update transaction records to 'Processed'
5574 -- is removed from this location. It is not required as per IA.
5575 -- If required, take it from OKL.H code line
5576
5577 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
5578 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT,
5579 G_MODULE,
5580 'OKL: Process Sales Tax : END tax schedule ');
5581 END IF;
5582
5583 End If; -- Tax Schedule
5584
5585 -- Bug 4748910 - END
5586
5587 OKC_API.END_ACTIVITY (x_msg_count => x_msg_count,
5588 x_msg_data => x_msg_data);
5589
5590 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
5591 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'OKL: Process Sales Tax : END ');
5592 END IF;
5593
5594 okl_debug_pub.logmessage('OKL: process_sales_tax : END');
5595
5596 Exception
5597 when OKL_API.G_EXCEPTION_ERROR then
5598 x_return_status := OKL_API.HANDLE_EXCEPTIONS(
5599 p_api_name => l_api_name,
5600 p_pkg_name => g_pkg_name,
5601 p_exc_name => 'OKL_API.G_RET_STS_ERROR',
5602 x_msg_count => x_msg_count,
5603 x_msg_data => x_msg_data,
5604 p_api_type => g_api_type);
5605
5606 when OKL_API.G_EXCEPTION_UNEXPECTED_ERROR then
5607 x_return_status := OKL_API.HANDLE_EXCEPTIONS(
5608 p_api_name => l_api_name,
5609 p_pkg_name => g_pkg_name,
5610 p_exc_name => 'OKL_API.G_RET_STS_UNEXP_ERROR',
5611 x_msg_count => x_msg_count,
5612 x_msg_data => x_msg_data,
5613 p_api_type => g_api_type);
5614
5615 when OTHERS then
5616 x_return_status := OKL_API.HANDLE_EXCEPTIONS(
5617 p_api_name => l_api_name,
5618 p_pkg_name => g_pkg_name,
5619 p_exc_name => 'OTHERS',
5620 x_msg_count => x_msg_count,
5621 x_msg_data => x_msg_data,
5622 p_api_type => g_api_type);
5623
5624 END process_sales_tax;
5625
5626
5627 -- Start of comments
5628 --
5629 -- Procedure Name : check_sales_tax
5630 -- Description : Qa Checker Validation for sales tax.
5631 -- Called by Qa Checker to check for header,
5632 -- asset level rules and validates Sales Tax
5633 -- Fee lines
5634 -- Business Rules :
5635 -- Parameters :
5636 -- Version : 1.0, ramurt Created. Bug#4373029
5637 -- End of comments
5638
5639 PROCEDURE check_sales_tax(
5640 p_chr_id IN NUMBER,
5641 x_return_status OUT NOCOPY VARCHAR2
5642 ) IS
5643
5644 cursor fnd_csr( fndType VARCHAR2, fndCode VARCHAR2 ) IS
5645 Select meaning,
5646 description
5647 From fnd_lookups
5648 Where lookup_type = fndType
5649 and lookup_code = fndCode;
5650
5651 CURSOR l_hdr_csr IS
5652 SELECT authoring_org_id
5653 FROM okc_k_headers_b
5654 WHERE id = p_chr_id;
5655 l_authoring_org_id OKC_K_HEADERS_B.AUTHORING_ORG_ID%TYPE;
5656
5657 cursor l_hdrrl_csr( rgcode OKC_RULE_GROUPS_B.RGD_CODE%TYPE,
5658 rlcat OKC_RULES_B.RULE_INFORMATION_CATEGORY%TYPE,
5659 chrId NUMBER) IS
5660 select crl.object1_id1,
5661 crl.RULE_INFORMATION1,
5662 crl.RULE_INFORMATION2,
5663 crl.RULE_INFORMATION3,
5664 crl.RULE_INFORMATION4,
5665 crl.RULE_INFORMATION5,
5666 crl.RULE_INFORMATION6,
5667 crl.RULE_INFORMATION7,
5668 crl.RULE_INFORMATION10,
5669 crl.RULE_INFORMATION11
5670 from OKC_RULE_GROUPS_B crg,
5671 OKC_RULES_B crl
5672 where crl.rgp_id = crg.id
5673 and crg.RGD_CODE = rgcode
5674 and crl.RULE_INFORMATION_CATEGORY = rlcat
5675 and crg.dnz_chr_id = chrId;
5676
5677
5678 cursor l_rl_csr1( rgcode OKC_RULE_GROUPS_B.RGD_CODE%TYPE,
5679 rlcat OKC_RULES_B.RULE_INFORMATION_CATEGORY%TYPE,
5680 chrId NUMBER,
5681 cleId NUMBER ) IS
5682 select crl.id slh_id,
5683 crl.object1_id1,
5684 crl.RULE_INFORMATION1,
5685 crl.RULE_INFORMATION2,
5686 crl.RULE_INFORMATION3,
5687 crl.RULE_INFORMATION5,
5688 crl.RULE_INFORMATION6,
5689 crl.RULE_INFORMATION7,
5690 crl.RULE_INFORMATION8,
5691 crl.RULE_INFORMATION10
5692 from OKC_RULE_GROUPS_B crg,
5693 OKC_RULES_B crl
5694 where crl.rgp_id = crg.id
5695 and crg.RGD_CODE = rgcode
5696 and crl.RULE_INFORMATION_CATEGORY = rlcat
5697 and crg.dnz_chr_id = chrId
5698 and nvl(crg.cle_id,-1) = cleId
5699 order by crl.RULE_INFORMATION1;
5700
5701 l_hdrrl_rec l_hdrrl_csr%ROWTYPE;
5702 l_exists boolean;
5703 l_pmnt_exists boolean;
5704 l_linked_asset_exists boolean;
5705 --l_tax_treatment VARCHAR2(100);
5706 l_tax_header VARCHAR2(100);
5707 l_fnd_rec fnd_csr%ROWTYPE;
5708 l_line_fnd_rec fnd_csr%ROWTYPE;
5709 l_hdr_fnd_rec fnd_csr%ROWTYPE;
5710 l_fnd_meaning fnd_lookups.MEANING%TYPE;
5711 l_line_fnd_meaning fnd_lookups.MEANING%TYPE;
5712 l_hdr_fnd_meaning fnd_lookups.MEANING%TYPE;
5713 l_fee_type_meaning fnd_lookups.MEANING%TYPE;
5714 --l_tax_treatment_fee fnd_lookups.MEANING%TYPE;
5715 l_tax_fee_meaning fnd_lookups.MEANING%TYPE;
5716 l_st_fee_code fnd_lookups.LOOKUP_CODE%TYPE;
5717 l_count NUMBER;
5718 l_amt_link_asset NUMBER;
5719 l_no_link_assets NUMBER;
5720 l_bill_strm_type NUMBER;
5721 l_line_asset_upfront_tax VARCHAR2(150);
5722 l_prev_line_asset_upfront_tax VARCHAR2(150);
5723 l_fee_line_found BOOLEAN;
5724 l_found_asset_not_billed BOOLEAN;
5725 l_rl_rec l_rl_csr1%ROWTYPE;
5726
5727 CURSOR st_fee_csr (p_chrId OKC_K_HEADERS_V.ID%TYPE) IS
5728 SELECT cleb.id,
5729 kle.fee_type,
5730 kle.amount
5731 --decode(kle.fee_type,'CAPITALIZED',kle.capital_amount,kle.amount) amount
5732 FROM
5733 okc_k_lines_b cleb,
5734 okc_k_lines_tl clet,
5735 okl_k_lines kle,
5736 okc_line_styles_v sty,
5737 okc_statuses_v sts
5738 WHERE cleb.lse_id = sty.id
5739 AND cleb.sts_code = sts.code
5740 AND sts.ste_code not in ( 'HOLD', 'TERMINATED', 'EXPIRED', 'CANCELLED')
5741 AND sty.lty_code = 'FEE'
5742 AND kle.FEE_PURPOSE_CODE='SALESTAX'
5743 AND cleb.dnz_chr_id = p_chrId
5744 AND cleb.id = clet.id
5745 AND clet.LANGUAGE = USERENV('LANG')
5746 AND kle.id = cleb.id;
5747 l_st_fee_rec st_fee_csr%ROWTYPE;
5748 l_fee_amount okl_k_lines.amount%TYPE;
5749
5750 CURSOR st_fee_link_asset_csr(p_cleId OKC_K_LINES_B.ID%TYPE) IS
5751 SELECT cleb.id,
5752 nvl(kle.amount,0) amount,
5753 nvl(kle.capital_amount,0) capital_amount
5754 FROM okc_k_lines_b cleb,
5755 okl_k_lines kle,
5756 okc_line_styles_b sty
5757 WHERE cle_id = p_cleId
5758 AND cleb.id = kle.id
5759 AND cleb.lse_id = sty.id
5760 AND sty.lty_code = 'LINK_FEE_ASSET';
5761
5762 l_st_fee_link_asset_rec st_fee_link_asset_csr%ROWTYPE;
5763
5764 CURSOR l_asset_tax_rule_csr(p_cleId OKC_K_LINES_B.ID%TYPE) IS
5765 SELECT crl.id slh_id,
5766 crl.object1_id1,
5767 crl.RULE_INFORMATION11
5768 FROM OKC_RULE_GROUPS_B crg,
5769 OKC_RULES_B crl
5770 WHERE crl.rgp_id = crg.id
5771 AND crg.RGD_CODE = 'LAASTX'
5772 AND crl.RULE_INFORMATION_CATEGORY = 'LAASTX'
5773 AND crg.dnz_chr_id = p_chr_id
5774 AND nvl(crg.cle_id,-1) = p_cleId;
5775 l_asset_tax_rule_rec l_asset_tax_rule_csr%ROWTYPE;
5776
5777 CURSOR l_asset_csr IS
5778 SELECT cle.id,
5779 name
5780 FROM okc_k_lines_v cle,
5781 okc_line_styles_b sty,
5782 okc_statuses_b sts
5783 WHERE cle.lse_id = sty.id
5784 AND cle.dnz_chr_id = p_chr_id
5785 AND lty_code = 'FREE_FORM1'
5786 AND cle.sts_code = sts.code
5787 AND sts.ste_code not in ( 'HOLD', 'TERMINATED', 'EXPIRED', 'CANCELLED');
5788
5789 --CURSOR l_fee_asset_csr(p_assetId OKC_K_LINES_B.ID%TYPE, p_fee_type OKL_K_LINES.FEE_TYPE%TYPE) IS
5790 CURSOR l_fee_asset_csr(p_assetId OKC_K_LINES_B.ID%TYPE) IS
5791 SELECT item.object1_id1,cleb.id,cleb.cle_id,
5792 clet_asset.name,
5793 kle.amount,
5794 kle.fee_type
5795 FROM okc_k_lines_b fee_line,
5796 okc_k_lines_b cleb,
5797 okl_k_lines kle,
5798 okc_k_items item,
5799 okc_k_lines_tl clet_asset,
5800 okc_line_styles_b sty
5801 WHERE fee_line.id = kle.id
5802 AND kle.FEE_PURPOSE_CODE='SALESTAX'
5803 AND cleb.lse_id = sty.id
5804 AND sty.lty_code = 'LINK_FEE_ASSET'
5805 AND item.cle_id = cleb.id
5806 AND item.dnz_chr_id = p_chr_id
5807 AND cleb.dnz_chr_id = p_chr_id
5808 AND cleb.cle_id = fee_line.id
5809 AND clet_asset.id = item.object1_id1
5810 AND clet_asset.id = p_assetId
5811 AND clet_asset.language = USERENV('LANG');
5812 --AND kle.fee_type = p_fee_type;
5813 --l_fee_asset_rec l_fee_asset_csr%ROWTYPE;
5814
5815 CURSOR l_tax_amt_csr IS
5816 SELECT SUM(NVL(TOTAL_TAX,0))
5817 FROM okl_tax_sources txs
5818 --,okl_tax_trx_details txl
5819 WHERE txs.khr_id = p_chr_id
5820 --AND txs.id = txl.txs_id
5821 AND txs.tax_line_status_code = 'ACTIVE'
5822 AND txs.tax_call_type_code = 'UPFRONT_TAX';
5823 l_tax_amount NUMBER;
5824
5825 CURSOR l_tax_line_amt_csr(p_asset_id OKC_K_LINES_B.ID%TYPE) IS
5826 SELECT SUM(NVL(TOTAL_TAX,0)) tax_amount -- SUM added for 4740150 issue
5827 FROM okl_tax_sources txs
5828 --,okl_tax_trx_details txl
5829 WHERE txs.khr_id = p_chr_id
5830 -- AND txs.id = txl.txs_id
5831 AND txs.tax_line_status_code = 'ACTIVE'
5832 AND txs.tax_call_type_code = 'UPFRONT_TAX'
5833 AND txs.kle_id = p_asset_id;
5834 l_asset_tax_amount NUMBER;
5835
5836 -- R12B Authoring OA Migration
5837 CURSOR st_fee_count_csr (p_chr_id OKC_K_HEADERS_B.ID%TYPE) IS
5838 SELECT COUNT(cleb.id)
5839 FROM okc_k_lines_b cleb,
5840 okl_k_lines kle,
5841 okc_line_styles_b sty,
5842 okc_statuses_b sts
5843 WHERE cleb.lse_id = sty.id
5844 AND sty.lty_code = 'FEE'
5845 AND cleb.sts_code = sts.code
5846 AND sts.ste_code not in ( 'HOLD', 'TERMINATED', 'EXPIRED', 'CANCELLED')
5847 AND kle.fee_purpose_code = 'SALESTAX'
5848 AND cleb.dnz_chr_id = p_chr_id
5849 AND cleb.chr_id = p_chr_id
5850 AND kle.id = cleb.id;
5851
5852 BEGIN
5853 IF (G_DEBUG_ENABLED = 'Y') THEN
5854 G_IS_DEBUG_STATEMENT_ON := OKL_DEBUG_PUB.CHECK_LOG_ON(G_MODULE, FND_LOG.LEVEL_STATEMENT);
5855 END IF;
5856 x_return_status := OKL_API.G_RET_STS_SUCCESS;
5857
5858 --OPEN l_hdr_csr;
5859 --FETCH l_hdr_csr INTO l_authoring_org_id;
5860 --CLOSE l_hdr_csr;
5861
5862 --DBMS_APPLICATION_INFO.SET_CLIENT_INFO(l_authoring_org_id);
5863
5864 l_upfront_tax_yn := 'N';
5865 OPEN l_tax_system_info;
5866 FETCH l_tax_system_info INTO l_upfront_tax_yn;
5867 CLOSE l_tax_system_info;
5868
5869 IF (nvl(l_upfront_tax_yn,'N') <> 'Y') THEN
5870 x_return_status := OKL_API.G_RET_STS_SUCCESS;
5871 return;
5872 END IF;
5873
5874 OPEN l_hdrrl_csr('LAHDTX','LASTPR', p_chr_id);
5875 FETCH l_hdrrl_csr INTO l_hdrrl_rec;
5876 l_exists := l_hdrrl_csr%FOUND;
5877 CLOSE l_hdrrl_csr;
5878 l_tax_header := l_hdrrl_rec.RULE_INFORMATION1;
5879 l_bill_strm_type := l_hdrrl_rec.RULE_INFORMATION2;
5880
5881 IF (l_tax_header IS NULL) THEN
5882 OKL_API.set_message(
5883 p_app_name => G_APP_NAME,
5884 p_msg_name => 'OKL_QA_ST_HEADER_TAX');
5885 x_return_status := OKL_API.G_RET_STS_ERROR;
5886 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
5887 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'Error: '||'OKL_QA_ST_HEADER_TAX The Upfront Sales Tax at Contract header can not be null.');
5888 END IF;
5889 END IF;
5890
5891
5892 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
5893 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'rule_info1'||l_hdrrl_rec.RULE_INFORMATION1);
5894 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'rule_info2'||l_hdrrl_rec.RULE_INFORMATION2);
5895 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'rule_info3'||l_hdrrl_rec.RULE_INFORMATION3);
5896 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'rule_info4'||l_hdrrl_rec.RULE_INFORMATION4);
5897 END IF;
5898
5899 --IF (NOT l_exists OR l_tax_treatment IS NULL) THEN
5900 IF (NOT l_exists) THEN
5901 OKL_API.set_message(
5902 p_app_name => G_APP_NAME,
5903 p_msg_name => 'OKL_QA_ST_MISSING');
5904 x_return_status := OKL_API.G_RET_STS_ERROR;
5905 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
5906 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'Error: '||'OKL_QA_ST_MISSING');
5907 END IF;
5908 END IF;
5909
5910
5911 IF ( l_hdrrl_rec.RULE_INFORMATION2 IS NULL ) THEN
5912 OPEN fnd_csr('OKL_ASSET_UPFRONT_TAX','BILLED');
5913 FETCH fnd_csr INTO l_fnd_rec;
5914 l_fnd_meaning := l_fnd_rec.meaning;
5915 CLOSE fnd_csr;
5916 OKL_API.set_message(
5917 p_app_name => G_APP_NAME,
5918 p_msg_name => 'OKL_QA_ST_STREAM_MISSING',
5919 p_token1 => 'UPFRONT_TAX',
5920 p_token1_value => l_fnd_meaning);
5921 x_return_status := OKL_API.G_RET_STS_ERROR;
5922 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
5923 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'Error: '||'OKL_QA_ST_STREAM_MISSING '||'Please enter '
5924 ||l_fnd_meaning ||' stream type on Taxes (Sales Tax Processing)'
5925 ||' terms and condition for the contract.');
5926 END IF;
5927 END IF;
5928 IF ( l_hdrrl_rec.RULE_INFORMATION3 IS NULL ) THEN
5929 OPEN fnd_csr('OKL_ASSET_UPFRONT_TAX','FINANCE');
5930 FETCH fnd_csr INTO l_fnd_rec;
5931 l_fnd_meaning := l_fnd_rec.meaning;
5932 CLOSE fnd_csr;
5933 OKL_API.set_message(
5934 p_app_name => G_APP_NAME,
5935 p_msg_name => 'OKL_QA_ST_STREAM_MISSING',
5936 p_token1 => 'UPFRONT_TAX',
5937 p_token1_value => l_fnd_meaning);
5938 x_return_status := OKL_API.G_RET_STS_ERROR;
5939 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
5940 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'Error: '||'OKL_QA_ST_STREAM_MISSING '||'Please enter '
5941 ||l_fnd_meaning ||' stream type on Taxes (Sales Tax Processing)'
5942 ||' terms and condition for the contract.');
5943 END IF;
5944 END IF;
5945 IF ( l_hdrrl_rec.RULE_INFORMATION4 IS NULL ) THEN
5946 OPEN fnd_csr('OKL_ASSET_UPFRONT_TAX','CAPITALIZE');
5947 FETCH fnd_csr INTO l_fnd_rec;
5948 l_fnd_meaning := l_fnd_rec.meaning;
5949 CLOSE fnd_csr;
5950 OKL_API.set_message(
5951 p_app_name => G_APP_NAME,
5952 p_msg_name => 'OKL_QA_ST_STREAM_MISSING',
5953 p_token1 => 'UPFRONT_TAX',
5954 p_token1_value => l_fnd_meaning);
5955 x_return_status := OKL_API.G_RET_STS_ERROR;
5956 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
5957 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'Error: '||'OKL_QA_ST_STREAM_MISSING '||'Please enter '
5958 ||l_fnd_meaning ||' stream type on Taxes (Sales Tax Processing)'
5959 ||' terms and condition for the contract.');
5960 END IF;
5961 END IF;
5962
5963 IF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
5964 RAISE G_EXCEPTION_HALT_VALIDATION;
5965 END IF;
5966
5967 -- R12B Authoring OA Migration
5968 /*
5969 l_count := 0;
5970 l_fee_line_found := false;
5971 FOR l_st_fee_rec IN st_fee_csr(p_chr_id)
5972 LOOP
5973 l_count := l_count + 1;
5974 OPEN fnd_csr('OKL_FEE_TYPES',l_st_fee_rec.fee_type);
5975 FETCH fnd_csr INTO l_fnd_rec;
5976 l_fee_type_meaning := l_fnd_rec.meaning;
5977 CLOSE fnd_csr;
5978
5979 IF ( l_st_fee_rec.fee_type = 'FINANCED' )
5980 OR ( l_st_fee_rec.fee_type = 'CAPITALIZED' ) THEN
5981 l_fee_line_found := TRUE;
5982 END IF;
5983 l_fee_amount := l_st_fee_rec.amount;
5984
5985 IF ( l_st_fee_rec.amount = 0 ) THEN
5986 OKL_API.set_message(
5987 p_app_name => G_APP_NAME,
5988 p_msg_name => 'OKL_QA_ST_FEE_ZERO',
5989 p_token1 => 'FEE_TYPE',
5990 p_token1_value => l_fee_type_meaning);
5991 x_return_status := OKL_API.G_RET_STS_ERROR;
5992 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
5993 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'Error: '||'OKL_QA_ST_FEE_ZERO '||'The sales tax fee line (type='
5994 ||l_fee_type_meaning||') amount can not be zero or negative.');
5995 END IF;
5996 END IF;
5997
5998 IF ( l_st_fee_rec.fee_type = 'FINANCED')
5999 OR ( l_st_fee_rec.fee_type = 'CAPITALIZED') THEN
6000 l_amt_link_asset := 0;
6001 l_no_link_assets := 0;
6002 FOR l_st_fee_link_asset_rec IN st_fee_link_asset_csr(l_st_fee_rec.id)
6003 LOOP
6004 IF (l_st_fee_rec.fee_type = 'FINANCED') THEN
6005 l_amt_link_asset := l_amt_link_asset + l_st_fee_link_asset_rec.amount;
6006 ELSIF (l_st_fee_rec.fee_type = 'CAPITALIZED') THEN
6007 l_amt_link_asset := l_amt_link_asset + l_st_fee_link_asset_rec.capital_amount;
6008 END IF;
6009 l_no_link_assets := l_no_link_assets + 1;
6010 END LOOP; --l_st_fee_link_asset_rec
6011 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
6012 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,l_st_fee_rec.amount || ':' || l_amt_link_asset);
6013 END IF;
6014 IF (l_st_fee_rec.amount <> l_amt_link_asset) THEN
6015 OKL_API.set_message(
6016 p_app_name => G_APP_NAME,
6017 p_msg_name => 'OKL_QA_ST_FEE_ASSET_AMT',
6018 p_token1 => 'LINE_TYPE',
6019 p_token1_value => l_fee_type_meaning);
6020 x_return_status := OKL_API.G_RET_STS_ERROR;
6021 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
6022 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'Error: OKL_QA_ST_FEE_ASSET_AMT '||'The sales tax Fee line ('
6023 ||l_fee_type_meaning||') amount must be equal to the total amount on corresponding linked Fee asset(s).');
6024 END IF;
6025 END IF;
6026 END IF;
6027 END LOOP;
6028 */
6029 -- R12B Authoring OA Migration
6030
6031 -- R12B Authoring OA Migration
6032 OPEN st_fee_count_csr(p_chr_id => p_chr_id);
6033 FETCH st_fee_count_csr INTO l_count;
6034 CLOSE st_fee_count_csr;
6035
6036 --IF ( (l_tax_treatment IN ('FINANCE','CAPITALIZE') ) AND l_count > 1 ) THEN
6037 IF ( l_count > 1 ) THEN
6038 OKL_API.set_message(
6039 p_app_name => G_APP_NAME,
6040 p_msg_name => 'OKL_QA_ST_FEE_GT1');
6041 x_return_status := OKL_API.G_RET_STS_ERROR;
6042 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
6043 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'Error: '||'OKL_QA_ST_FEE_GT1 ' || 'The contract can not have more than one Sales Tax Fee line defined.');
6044 END IF;
6045 END IF;
6046
6047
6048 --raise exception as we want to halt validation at this.
6049 IF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
6050 RAISE G_EXCEPTION_HALT_VALIDATION;
6051 END IF;
6052
6053 l_line_asset_upfront_tax := 'XXX';
6054 l_prev_line_asset_upfront_tax := 'XXX';
6055 l_found_asset_not_billed := false;
6056 FOR l_asset_rec IN l_asset_csr
6057 LOOP
6058 OPEN l_asset_tax_rule_csr(l_asset_rec.Id);
6059 FETCH l_asset_tax_rule_csr INTO l_asset_tax_rule_rec;
6060 CLOSE l_asset_tax_rule_csr;
6061 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
6062 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'l_asset_rec.id: '||l_asset_rec.id || ' ' || l_asset_rec.name);
6063 END IF;
6064 l_line_asset_upfront_tax := nvl(l_asset_tax_rule_rec.RULE_INFORMATION11,'XXX');
6065
6066 IF (l_line_asset_upfront_tax <> 'BILLED' AND l_line_asset_upfront_tax <> 'XXX') THEN
6067 l_found_asset_not_billed := TRUE;
6068 END IF;
6069
6070 --raise error capitalized and finance mix not allowed. For sales tax purposes all non billed asset
6071 --lines should be either capitalized or financed throughout.
6072 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
6073 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'l_line_asset_upfront_tax:'||l_line_asset_upfront_tax);
6074 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'l_prev_line_asset_upfront_tax:'||l_prev_line_asset_upfront_tax);
6075 END IF;
6076 IF (l_line_asset_upfront_tax IN ('FINANCE','CAPITALIZE')
6077 AND l_line_asset_upfront_tax <> l_prev_line_asset_upfront_tax) THEN
6078 IF (l_prev_line_asset_upfront_tax <> 'XXX') THEN
6079 OKL_API.set_message(
6080 p_app_name => G_APP_NAME,
6081 p_msg_name => 'OKL_QA_ST_ALL_CAP_OR_FIN');
6082 x_return_status := OKL_API.G_RET_STS_ERROR;
6083 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
6084 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'Error: '||'OKL_QA_ST_ALL_CAP_OR_FIN All asset lines must have sales upfront tax as either Financed or Capitalized.');
6085 END IF;
6086 EXIT;
6087 --RAISE G_EXCEPTION_HALT_VALIDATION;
6088 END IF;
6089 l_prev_line_asset_upfront_tax := l_line_asset_upfront_tax;
6090 END IF;
6091
6092 IF ((l_line_asset_upfront_tax <> l_tax_header)
6093 AND l_line_asset_upfront_tax IN ('FINANCE','CAPITALIZE')
6094 AND l_tax_header IN ('FINANCE','CAPITALIZE')) THEN
6095 --raise error capitalized and financed mix not allowed.
6096 OPEN fnd_csr('OKL_ASSET_UPFRONT_TAX',l_tax_header);
6097 FETCH fnd_csr INTO l_hdr_fnd_rec;
6098 l_hdr_fnd_meaning := l_hdr_fnd_rec.meaning;
6099 CLOSE fnd_csr;
6100 OPEN fnd_csr('OKL_ASSET_UPFRONT_TAX',l_line_asset_upfront_tax);
6101 FETCH fnd_csr INTO l_line_fnd_rec;
6102 l_line_fnd_meaning := l_line_fnd_rec.meaning;
6103 CLOSE fnd_csr;
6104 OKL_API.set_message(
6105 p_app_name => G_APP_NAME,
6106 p_msg_name => 'OKL_QA_ST_CAP_FIN_MIX',
6107 p_token1 => 'UPFRONT_TAX',
6108 p_token1_value => l_hdr_fnd_meaning,
6109 p_token2 => 'UPFRONT_LN_TAX',
6110 p_token2_value => l_line_fnd_meaning,
6111 p_token3 => 'ASSET_NUMBER',
6112 p_token3_value => l_asset_rec.name);
6113 x_return_status := OKL_API.G_RET_STS_ERROR;
6114 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
6115 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'Error: '||'OKL_QA_ST_CAP_FIN_MIX The upfront tax for the asset line ' ||
6116 l_asset_rec.name||' is different from asset upfront tax at Contract header.' );
6117 END IF;
6118 null;
6119 END IF;
6120
6121 -- R12B Authoring OA Migration
6122 /*
6123 IF (l_line_asset_upfront_tax = 'FINANCE') THEN
6124 l_st_fee_code := 'FINANCED';
6125 END IF;
6126 IF (l_line_asset_upfront_tax = 'CAPITALIZE') THEN
6127 l_st_fee_code := 'CAPITALIZED';
6128 END IF;
6129
6130 --debug_message('l_bill_asset_overide: '||l_bill_asset_overide);
6131 l_linked_asset_exists := FALSE;
6132 FOR l_fee_asset_rec IN l_fee_asset_csr(l_asset_rec.id)
6133 LOOP
6134
6135 OPEN fnd_csr('OKL_FEE_TYPES',l_fee_asset_rec.fee_type);
6136 FETCH fnd_csr INTO l_fnd_rec;
6137 l_fee_type_meaning := l_fnd_rec.meaning;
6138 CLOSE fnd_csr;
6139
6140 IF (l_line_asset_upfront_tax IN ('FINANCE', 'CAPITALIZE')) THEN
6141 l_linked_asset_exists := TRUE;
6142 END IF;
6143
6144 --IF (l_line_asset_upfront_tax = 'BILLED' AND l_linked_asset_exists) THEN
6145 IF (l_line_asset_upfront_tax = 'BILLED' ) THEN
6146 OPEN fnd_csr('OKL_FEE_TYPES','BILLED');
6147 FETCH fnd_csr INTO l_fnd_rec;
6148 CLOSE fnd_csr;
6149 l_tax_fee_meaning := l_fnd_rec.meaning;
6150 OKL_API.set_message(
6151 p_app_name => G_APP_NAME,
6152 p_msg_name => 'OKL_QA_ST_FEE_ASSET_ERROR',
6153 p_token1 => 'FEE_TYPE',
6154 p_token1_value => l_tax_fee_meaning,
6155 p_token2 => 'ASSET_NUMBER',
6156 p_token2_value => l_asset_rec.name);
6157 x_return_status := OKL_API.G_RET_STS_ERROR;
6158 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
6159 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'Error: '||'OKL_QA_ST_FEE_ASSET_ERROR '||'The "Bill Upfront Tax" is selected for the asset = '
6160 ||l_asset_rec.name||'. Please remove this asset association from Sales Tax Fee line ('||l_tax_fee_meaning||').');
6161 END IF;
6162 null;
6163 END IF;
6164 END LOOP;
6165
6166 --raise exception as we want to halt validation at this.
6167 IF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
6168 RAISE G_EXCEPTION_HALT_VALIDATION;
6169 END IF;
6170
6171 IF ( (l_line_asset_upfront_tax IN ('FINANCE','CAPITALIZE') ) AND (NOT l_linked_asset_exists ) AND l_fee_line_found)THEN
6172 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
6173 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'Here00001' ||l_line_asset_upfront_tax );
6174 END IF;
6175 OPEN fnd_csr('OKL_FEE_TYPES',l_st_fee_code);
6176 FETCH fnd_csr INTO l_fnd_rec;
6177 CLOSE fnd_csr;
6178 l_tax_fee_meaning := l_fnd_rec.meaning;
6179 OKL_API.set_message(
6180 p_app_name => G_APP_NAME,
6181 p_msg_name => 'OKL_QA_ST_FEE_ASSET_MISSING',
6182 p_token1 => 'ASSET_NUMBER',
6183 p_token1_value => l_asset_rec.name,
6184 p_token2 => 'LINE_TYPE',
6185 p_token2_value => l_tax_fee_meaning );
6186 x_return_status := OKL_API.G_RET_STS_ERROR;
6187 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
6188 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'Error: OKL_QA_ST_FEE_ASSET_MISSING '||'The sales tax Fee line ('
6189 ||l_tax_fee_meaning ||') does not have corresponding linked asset('||l_asset_rec.name||') defined.');
6190 END IF;
6191 END IF;
6192 */
6193 -- R12B Authoring OA Migration
6194
6195 END LOOP;
6196
6197 -- R12B Authoring OA Migration
6198 /*
6199 --Bug#4693357 ramurt
6200 l_tax_amount := 0;
6201 OPEN l_tax_amt_csr;
6202 FETCH l_tax_amt_csr INTO l_tax_amount;
6203 CLOSE l_tax_amt_csr;
6204
6205 IF ( (l_tax_amount <> 0) AND NOT l_fee_line_found AND l_found_asset_not_billed) THEN
6206 OKL_API.set_message(
6207 p_app_name => G_APP_NAME,
6208 p_msg_name => 'OKL_QA_ST_NO_FEE');
6209 x_return_status := OKL_API.G_RET_STS_ERROR;
6210 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
6211 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'Error: OKL_QA_ST_NO_FEE '||'The sales tax Fee line must be present for the Contract');
6212 END IF;
6213 END IF;
6214
6215 --Bug#4699379 ramurt
6216 -- getting the total tax engine calculated sales upfront tax amount by summing calculated amounts
6217 -- for each asset.
6218 l_tax_amount := 0;
6219 l_asset_tax_amount := 0;
6220 FOR l_asset_rec IN l_asset_csr
6221 LOOP
6222 OPEN l_asset_tax_rule_csr(l_asset_rec.Id);
6223 FETCH l_asset_tax_rule_csr INTO l_asset_tax_rule_rec;
6224 CLOSE l_asset_tax_rule_csr;
6225 l_line_asset_upfront_tax := nvl(l_asset_tax_rule_rec.RULE_INFORMATION11,'XXX');
6226
6227 IF (l_line_asset_upfront_tax IN ('FINANCE','CAPITALIZE')) THEN
6228 OPEN l_tax_line_amt_csr(l_asset_rec.id);
6229 FETCH l_tax_line_amt_csr INTO l_asset_tax_amount;
6230 l_tax_amount := l_tax_amount + l_asset_tax_amount;
6231 CLOSE l_tax_line_amt_csr;
6232 END IF;
6233 END LOOP;
6234
6235 OPEN fnd_csr('OKL_FEE_TYPES',l_st_fee_code);
6236 FETCH fnd_csr INTO l_fnd_rec;
6237 CLOSE fnd_csr;
6238 l_tax_fee_meaning := l_fnd_rec.meaning;
6239
6240 IF (l_tax_amount <> l_fee_amount) THEN
6241 OKL_API.set_message(
6242 p_app_name => G_APP_NAME,
6243 p_msg_name => 'OKL_QA_ST_FEE_AMT',
6244 p_token1 => 'FEE_TYPE',
6245 p_token1_value => l_tax_fee_meaning,
6246 p_token2 => 'UPFRONT_TAX',
6247 p_token2_value => l_tax_fee_meaning);
6248 x_return_status := OKL_API.G_RET_STS_ERROR;
6249 END IF;
6250 */
6251 -- R12B Authoring OA Migration
6252
6253 EXCEPTION
6254 WHEN G_EXCEPTION_HALT_VALIDATION THEN
6255 -- no processing necessary; validation can continue with next column
6256 IF st_fee_csr%ISOPEN THEN
6257 CLOSE st_fee_csr;
6258 END IF;
6259 IF l_hdrrl_csr%ISOPEN THEN
6260 CLOSE l_hdrrl_csr;
6261 END IF;
6262 IF l_rl_csr1%ISOPEN THEN
6263 CLOSE l_rl_csr1;
6264 END IF;
6265 IF l_asset_tax_rule_csr%ISOPEN THEN
6266 CLOSE l_asset_tax_rule_csr;
6267 END IF;
6268 IF fnd_csr%ISOPEN THEN
6269 CLOSE fnd_csr;
6270 END IF;
6271 IF l_hdr_csr%ISOPEN THEN
6272 CLOSE l_hdr_csr;
6273 END IF;
6274 IF l_fee_asset_csr%ISOPEN THEN
6275 CLOSE l_fee_asset_csr;
6276 END IF;
6277 IF l_asset_csr%ISOPEN THEN
6278 CLOSE l_asset_csr;
6279 END IF;
6280 IF st_fee_link_asset_csr%ISOPEN THEN
6281 CLOSE st_fee_link_asset_csr;
6282 END IF;
6283 IF l_tax_system_info%ISOPEN THEN
6284 CLOSE l_tax_system_info;
6285 END IF;
6286 IF l_tax_amt_csr%ISOPEN THEN
6287 CLOSE l_tax_amt_csr;
6288 END IF;
6289 IF l_tax_line_amt_csr%ISOPEN THEN
6290 CLOSE l_tax_line_amt_csr;
6291 END IF;
6292 NULL;
6293 WHEN OTHERS THEN
6294 -- store SQL error message on message stack
6295 OKL_API.SET_MESSAGE(
6296 p_app_name => G_APP_NAME,
6297 p_msg_name => G_UNEXPECTED_ERROR,
6298 p_token1 => G_SQLCODE_TOKEN,
6299 p_token1_value => SQLCODE,
6300 p_token2 => G_SQLERRM_TOKEN,
6301 p_token2_value => SQLERRM);
6302 x_return_status := OKL_API.G_RET_STS_UNEXP_ERROR;
6303 IF st_fee_csr%ISOPEN THEN
6304 CLOSE st_fee_csr;
6305 END IF;
6306 IF l_hdrrl_csr%ISOPEN THEN
6307 CLOSE l_hdrrl_csr;
6308 END IF;
6309 IF l_rl_csr1%ISOPEN THEN
6310 CLOSE l_rl_csr1;
6311 END IF;
6312 IF l_asset_tax_rule_csr%ISOPEN THEN
6313 CLOSE l_asset_tax_rule_csr;
6314 END IF;
6315 IF fnd_csr%ISOPEN THEN
6316 CLOSE fnd_csr;
6317 END IF;
6318 IF l_hdr_csr%ISOPEN THEN
6319 CLOSE l_hdr_csr;
6320 END IF;
6321 IF l_fee_asset_csr%ISOPEN THEN
6322 CLOSE l_fee_asset_csr;
6323 END IF;
6324 IF l_asset_csr%ISOPEN THEN
6325 CLOSE l_asset_csr;
6326 END IF;
6327 IF st_fee_link_asset_csr%ISOPEN THEN
6328 CLOSE st_fee_link_asset_csr;
6329 END IF;
6330 IF l_tax_system_info%ISOPEN THEN
6331 CLOSE l_tax_system_info;
6332 END IF;
6333 IF l_tax_amt_csr%ISOPEN THEN
6334 CLOSE l_tax_amt_csr;
6335 END IF;
6336 IF l_tax_line_amt_csr%ISOPEN THEN
6337 CLOSE l_tax_line_amt_csr;
6338 END IF;
6339
6340 END check_sales_tax;
6341
6342 -- Start of comments
6343 --
6344 -- Procedure Name : check_sales_tax_asset_rules
6345 -- Description : Page level Validation for sales tax
6346 -- terms and conditions at asset level
6347 -- This is called by process_line_rule_group_rules
6348 -- in okl_rgrp_rules_process_pvt
6349 -- Business Rules :
6350 -- Parameters :
6351 -- Version : 1.0, ramurt Created. Bug#4658944
6352 -- End of comments
6353 PROCEDURE check_sales_tax_asset_rules(
6354 p_api_version IN NUMBER,
6355 p_init_msg_list IN VARCHAR2 DEFAULT OKC_API.G_FALSE,
6356 x_return_status OUT NOCOPY VARCHAR2,
6357 x_msg_count OUT NOCOPY NUMBER,
6358 x_msg_data OUT NOCOPY VARCHAR2,
6359 p_chr_id IN NUMBER,
6360 p_line_id IN NUMBER,
6361 p_rule_group_id IN NUMBER,
6362 p_rgr_rec IN rgr_rec_type) IS
6363
6364 l_exists boolean;
6365 l_mix_fin_cap VARCHAR2(1);
6366
6367 -- Bug# 6512668: Exclude asset lines in Abandoned status
6368 CURSOR l_upfront_tax_other_assets(p_line_upfront_tax OKC_RULES_B.RULE_INFORMATION11%TYPE) IS
6369 SELECT 'Y'
6370 FROM okc_rule_groups_b rgp,
6371 okc_rules_b rule,
6372 okc_k_lines_b cle
6373 WHERE rule.rgp_id = rgp.id
6374 AND rgd_code = 'LAASTX'
6375 AND rule_information_category = 'LAASTX'
6376 AND rgp.dnz_chr_id = p_chr_id
6377 AND nvl(rgp.cle_id,-1) <> p_line_id
6378 AND nvl(RULE_INFORMATION11,'XXX') NOT IN (p_line_upfront_tax,'BILLED','XXX')
6379 AND cle.id = rgp.cle_id
6380 AND cle.sts_code <> 'ABANDONED';
6381
6382 BEGIN
6383 x_return_status := OKL_API.G_RET_STS_SUCCESS;
6384
6385 l_upfront_tax_yn := 'N';
6386 OPEN l_tax_system_info;
6387 FETCH l_tax_system_info INTO l_upfront_tax_yn;
6388 CLOSE l_tax_system_info;
6389
6390 IF (nvl(l_upfront_tax_yn,'N') <> 'Y') THEN
6391 x_return_status := OKL_API.G_RET_STS_SUCCESS;
6392 return;
6393 END IF;
6394
6395 --Murthy
6396 l_exists := false;
6397 IF (p_rgr_rec.RULE_INFORMATION11 = 'CAPITALIZE') THEN
6398 OPEN l_upfront_tax_other_assets('CAPITALIZE');
6399 FETCH l_upfront_tax_other_assets INTO l_mix_fin_cap;
6400 l_exists := l_upfront_tax_other_assets%FOUND;
6401 CLOSE l_upfront_tax_other_assets;
6402 ELSIF (p_rgr_rec.RULE_INFORMATION11 = 'FINANCE') THEN
6403 OPEN l_upfront_tax_other_assets('FINANCE');
6404 FETCH l_upfront_tax_other_assets INTO l_mix_fin_cap;
6405 l_exists := l_upfront_tax_other_assets%FOUND;
6406 CLOSE l_upfront_tax_other_assets;
6407 END IF;
6408 IF (l_exists) THEN
6409 OKL_API.set_message(
6410 p_app_name => G_APP_NAME,
6411 p_msg_name => 'OKL_QA_ST_ALL_CAP_OR_FIN');
6412 x_return_status := OKL_API.G_RET_STS_ERROR;
6413 END IF;
6414
6415 EXCEPTION
6416 WHEN G_EXCEPTION_HALT_VALIDATION THEN
6417 -- no processing necessary; validation can continue with next column
6418 IF l_upfront_tax_other_assets%ISOPEN THEN
6419 CLOSE l_upfront_tax_other_assets;
6420 END IF;
6421 IF l_tax_system_info%ISOPEN THEN
6422 CLOSE l_tax_system_info;
6423 END IF;
6424 WHEN OTHERS THEN
6425 IF l_upfront_tax_other_assets%ISOPEN THEN
6426 CLOSE l_upfront_tax_other_assets;
6427 END IF;
6428 IF l_tax_system_info%ISOPEN THEN
6429 CLOSE l_tax_system_info;
6430 END IF;
6431 -- store SQL error message on message stack
6432 OKL_API.SET_MESSAGE(
6433 p_app_name => G_APP_NAME,
6434 p_msg_name => G_UNEXPECTED_ERROR,
6435 p_token1 => G_SQLCODE_TOKEN,
6436 p_token1_value => SQLCODE,
6437 p_token2 => G_SQLERRM_TOKEN,
6438 p_token2_value => SQLERRM);
6439 x_return_status := OKL_API.G_RET_STS_UNEXP_ERROR;
6440
6441 END check_sales_tax_asset_rules;
6442
6443 -----------------------------------------------------------------------------
6444 -- PROCEDURE validate_upfront_tax_fee
6445 -----------------------------------------------------------------------------
6446 -- Start of comments
6447 --
6448 -- Procedure Name : validate_upfront_tax_fee
6449 -- Description : Procedure will be called to validate upfront tax fee and
6450 -- payments during online and batch contract activation.
6451 -- Business Rules :
6452 -- Parameters : p_chr_id
6453 -- Version : 1.0
6454 -- History : 24-Apr-2007 rpillay Created
6455 -- End of comments
6456
6457 PROCEDURE validate_upfront_tax_fee(
6458 p_api_version IN NUMBER,
6459 p_init_msg_list IN VARCHAR2 DEFAULT OKL_API.G_FALSE,
6460 x_return_status OUT NOCOPY VARCHAR2,
6461 x_msg_count OUT NOCOPY NUMBER,
6462 x_msg_data OUT NOCOPY VARCHAR2,
6463 p_chr_id IN VARCHAR2) IS
6464
6465 l_api_name CONSTANT VARCHAR2(30) := 'VALIDATE_UPFRONT_TAX_FEE';
6466 l_api_version CONSTANT NUMBER := 1.0;
6467
6468 /* Cursor to get the top fee line for Sales Tax financed fee of a given contract. */
6469 CURSOR l_fn_top_fee_ln_csr (p_chr_id IN OKC_K_HEADERS_B.ID%TYPE) IS
6470 SELECT kle.id,
6471 kle.amount,
6472 clev.name,
6473 lsev.name line_type
6474 FROM okc_k_lines_v clev,
6475 okl_k_lines kle,
6476 okc_statuses_b okcsts,
6477 okc_line_styles_v lsev
6478 WHERE clev.dnz_chr_id = p_chr_id
6479 AND clev.chr_id = p_chr_id
6480 AND kle.id = clev.id
6481 AND kle.fee_type = 'FINANCED'
6482 AND kle.fee_purpose_code = 'SALESTAX'
6483 AND lsev.id = clev.lse_id
6484 AND okcsts.code = clev.sts_code
6485 AND okcsts.ste_code NOT IN ('EXPIRED','HOLD','CANCELLED','TERMINATED', 'ABANDONED');
6486
6487 /* Cursor to get the financed fee sub-lines (applied to assets) for a
6488 given contract. */
6489 CURSOR l_fn_sub_ln_fee_csr ( p_chr_id IN OKC_K_HEADERS_B.ID%TYPE,
6490 p_fee_line_id IN OKL_K_LINES.ID%TYPE) IS
6491 SELECT kle.id,
6492 kle.amount,
6493 cleb.end_date,
6494 cleb.start_date
6495 FROM okc_k_lines_b cleb,
6496 okl_k_lines kle,
6497 okc_statuses_b okcsts
6498 WHERE cleb.dnz_chr_id = p_chr_id
6499 AND kle.id = cleb.id
6500 AND cleb.cle_id = p_fee_line_id
6501 AND okcsts.code = cleb.sts_code
6502 AND okcsts.ste_code NOT IN ('EXPIRED','HOLD','CANCELLED','ABANDONED');
6503
6504 /* Cursor to get the financed fee top/sub-line payments for a
6505 given contract. */
6506 CURSOR l_fn_fee_pmt_csr (p_chr_id IN OKC_K_HEADERS_B.ID%TYPE,
6507 p_fee_line_id IN OKL_K_LINES.ID%TYPE) IS
6508 SELECT Fnd_Date.canonical_to_date(sll.rule_information2) start_date,
6509 SLL.rule_information3 periods,
6510 DECODE(sll.object1_id1, 'M', 1, 'Q', 3, 'S', 6, 'A', 12) mpp,
6511 TRUNC(ADD_MONTHS(Fnd_Date.canonical_to_date(sll.rule_information2),
6512 TO_NUMBER(sll.rule_information3)*DECODE(sll.object1_id1, 'M', 1, 'Q', 3, 'S', 6, 'A', 12)) - 1) end_date,
6513 styt.name stream_type
6514 FROM okc_rules_b sll,
6515 okc_rules_b slh,
6516 okc_rule_groups_b rgp,
6517 okl_strm_type_b sty,
6518 okl_strm_type_tl styt
6519 WHERE rgp.dnz_chr_id = p_chr_id
6520 AND rgp.cle_id = p_fee_line_id
6521 AND rgp.rgd_code = 'LALEVL'
6522 AND rgp.id = slh.rgp_id
6523 AND slh.rule_information_category = 'LASLH'
6524 AND slh.object1_id1 = TO_CHAR(sty.id)
6525 AND styt.language = USERENV('LANG')
6526 AND sty.id = styt.id
6527 AND TO_CHAR(slh.id) = sll.object2_id1
6528 AND sll.rule_information_category = 'LASLL';
6529
6530 /* Cursor to get the financed fee top/sub-line payments HEADER for a
6531 given contract. */
6532 CURSOR l_fn_fee_pmtH_csr (p_chr_id IN OKC_K_HEADERS_B.ID%TYPE,
6533 p_fee_line_id IN OKL_K_LINES.ID%TYPE) IS
6534
6535 SELECT slh.id
6536 FROM okc_rules_b slh,
6537 okc_rule_groups_b rgp,
6538 okl_strm_type_b sty,
6539 okl_strm_type_tl styt
6540 WHERE rgp.dnz_chr_id = p_chr_id
6541 AND rgp.cle_id = p_fee_line_id
6542 AND rgp.rgd_code = 'LALEVL'
6543 AND rgp.id = slh.rgp_id
6544 AND slh.rule_information_category = 'LASLH'
6545 AND slh.object1_id1 = TO_CHAR(sty.id)
6546 AND styt.language = USERENV('LANG')
6547 AND sty.id = styt.id;
6548
6549 CURSOR l_strm_slh_csr (p_khr_id OKC_K_HEADERS_B.ID%TYPE,
6550 p_kle_id OKC_K_LINES_B.ID%TYPE) IS
6551 SELECT styt.name stream_type,
6552 rule.id rule_id,
6553 rgp.id rgp_id
6554 FROM okc_rules_b rule,
6555 okc_rule_groups_b rgp,
6556 okl_strm_type_b sty,
6557 okl_strm_type_tl styt
6558 WHERE NVL(rgp.cle_id, -1) = p_kle_id
6559 AND rgp.dnz_chr_id = p_khr_id
6560 AND rgp.rgd_code = 'LALEVL'
6561 AND rgp.id = rule.rgp_id
6562 AND rule.rule_information_category = 'LASLH'
6563 AND TO_NUMBER(rule.object1_id1) = sty.id
6564 AND styt.LANGUAGE = USERENV('LANG')
6565 AND sty.id = styt.id;
6566
6567 CURSOR l_strm_sll_csr (p_rule_id OKC_RULES_B.ID%TYPE,
6568 p_rgp_id OKC_RULE_GROUPS_B.ID%TYPE) IS
6569 SELECT Fnd_Date.canonical_to_date(sll.rule_information2) start_date,
6570 sll.rule_information1 seq,
6571 sll.rule_information6 amt,
6572 sll.rule_information7 stub_day,
6573 sll.rule_information13 rate
6574 FROM okc_rules_b sll
6575 WHERE sll.rgp_id = p_rgp_id
6576 AND sll.object2_id1 = TO_CHAR(p_rule_id)
6577 AND sll.rule_information_category = 'LASLL'
6578 ORDER BY 1,2;
6579
6580 l_prev_pmnt NUMBER;
6581
6582
6583 x_err_msg VARCHAR2(1000);
6584
6585 l_fn_sub_ln_fee_cnt NUMBER := 0;
6586 l_payment_top_ln_cnt NUMBER := 0; -- Counter for financed payments top lines
6587 l_payment_sub_ln_cnt NUMBER := 0; -- Counter for financed payments sub-lines
6588 l_fn_top_ln_fee_amt NUMBER := 0; -- Financed top line total fee amount.
6589 l_fn_sub_ln_fee_amt NUMBER := 0; -- Financed sum of sub-line fee amount.
6590 l_top_ln_pmt_exist BOOLEAN := FALSE;
6591 l_fn_sln_fee_amt_chk BOOLEAN := FALSE; -- If there are sub-lines payments exists.
6592
6593 l_fn_top_fee_ln_rec l_fn_top_fee_ln_csr%ROWTYPE;
6594 l_fn_fee_pmtH_rec l_fn_fee_pmtH_csr%ROWTYPE;
6595
6596 --Bug# 6609598
6597 l_tot_pmnt NUMBER;
6598
6599 BEGIN
6600
6601 x_return_status := OKL_API.START_ACTIVITY(
6602 p_api_name => l_api_name,
6603 p_pkg_name => g_pkg_name,
6604 p_init_msg_list => p_init_msg_list,
6605 l_api_version => l_api_version,
6606 p_api_version => p_api_version,
6607 p_api_type => G_API_TYPE,
6608 x_return_status => x_return_status);
6609
6610 -- check if activity started successfully
6611 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
6612 RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
6613 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
6614 RAISE OKL_API.G_EXCEPTION_ERROR;
6615 END IF;
6616
6617 OPEN l_fn_top_fee_ln_csr(p_chr_id => p_chr_id);
6618 FETCH l_fn_top_fee_ln_csr INTO l_fn_top_fee_ln_rec;
6619 CLOSE l_fn_top_fee_ln_csr;
6620
6621 -- If Sales tax Financed Fee exists
6622 IF (l_fn_top_fee_ln_rec.id IS NOT NULL) THEN
6623
6624 /* Check Payments for the top fee line if they exist. */
6625 --Bug# 6609598
6626 /* FEE line should have only 1 payment defined. */
6627 l_tot_pmnt := 0;
6628 FOR l_fn_fee_pmtH_rec IN l_fn_fee_pmtH_csr(p_chr_id => p_chr_id,
6629 p_fee_line_id => l_fn_top_fee_ln_rec.id)
6630 LOOP
6631 l_tot_pmnt := l_tot_pmnt + 1;
6632 l_top_ln_pmt_exist := TRUE;
6633 END LOOP;
6634
6635 IF ( l_tot_pmnt > 1 ) THEN
6636 x_return_status := Okl_Api.G_RET_STS_ERROR;
6637 OKL_API.set_message(
6638 p_app_name => G_APP_NAME,
6639 p_msg_name => 'OKL_QA_ONLY_1PAY',
6640 p_token1 => 'line',
6641 p_token1_value => l_fn_top_fee_ln_rec.name
6642 );
6643 END IF;
6644
6645 /* Check payments for financed fee sub-line, if it exist both for top
6646 line and sub-line error out. If payment end date is past fee line end date error out. */
6647
6648 FOR l_fn_sub_ln_fee_rec IN l_fn_sub_ln_fee_csr (p_chr_id => p_chr_id,
6649 p_fee_line_id => l_fn_top_fee_ln_rec.id)
6650 LOOP
6651
6652 l_fn_sub_ln_fee_cnt := l_fn_sub_ln_fee_cnt + 1;
6653
6654 /* Store the sum of financed fee sub-line amount. */
6655 l_fn_sub_ln_fee_amt := l_fn_sub_ln_fee_amt + l_fn_sub_ln_fee_rec.amount;
6656
6657 /* Sub-line fees exists. */
6658 l_fn_sln_fee_amt_chk := TRUE;
6659
6660 /* Check Payments for the financed fee sub-line if they exist. */
6661
6662 FOR l_fn_fee_pmtH IN l_fn_fee_pmtH_csr (p_chr_id => p_chr_id,
6663 p_fee_line_id => l_fn_sub_ln_fee_rec.id )
6664 LOOP
6665 IF (l_top_ln_pmt_exist) THEN
6666 x_return_status := Okl_Api.G_RET_STS_ERROR;
6667 OKL_API.set_message(
6668 p_app_name => G_APP_NAME,
6669 p_msg_name => 'OKL_QA_FN_PMTS_TOP_SUB_EXIST',
6670 p_token1 => 'FEE_LINE',
6671 p_token1_value => l_fn_top_fee_ln_rec.name);
6672 END IF;
6673
6674 l_payment_sub_ln_cnt := l_payment_sub_ln_cnt + 1;
6675
6676 END LOOP;
6677
6678 FOR l_fn_fee_pmt_rec IN l_fn_fee_pmt_csr (p_chr_id => p_chr_id,
6679 p_fee_line_id => l_fn_sub_ln_fee_rec.id)
6680 LOOP
6681 /* Check if the payment end date is within in the financed
6682 fee sub-line's end date, if not error out. */
6683
6684 IF ( TRUNC(l_fn_fee_pmt_rec.start_date) < TRUNC(l_fn_sub_ln_fee_rec.start_date) ) THEN
6685
6686 x_return_status := Okl_Api.G_RET_STS_ERROR;
6687 OKL_API.set_message(
6688 p_app_name => G_APP_NAME,
6689 p_msg_name => 'OKL_QA_FN_SLN_PMT_SD',
6690 p_token1 => 'FEE_LINE',
6691 p_token1_value => l_fn_top_fee_ln_rec.name);
6692 END IF;
6693
6694 IF ( TRUNC(l_fn_fee_pmt_rec.end_date) > TRUNC(l_fn_sub_ln_fee_rec.end_date) ) THEN
6695 x_return_status := Okl_Api.G_RET_STS_ERROR;
6696 OKL_API.set_message(
6697 p_app_name => G_APP_NAME,
6698 p_msg_name => 'OKL_QA_FN_SLN_PMT_ED',
6699 p_token1 => 'FEE_LINE',
6700 p_token1_value => l_fn_top_fee_ln_rec.name);
6701 END IF;
6702
6703 END LOOP;
6704 END LOOP;
6705
6706 /* Check if a financed top line fee amount is not equal to sub-line fee amount,
6707 if exists, if not error out. */
6708
6709 IF ( (l_fn_sln_fee_amt_chk) AND (l_fn_top_fee_ln_rec.amount <> l_fn_sub_ln_fee_amt)) THEN
6710 x_return_status := Okl_Api.G_RET_STS_ERROR;
6711 OKL_API.set_message(
6712 p_app_name => G_APP_NAME,
6713 p_msg_name => 'OKL_QA_FN_FEE_AMT_NEQ',
6714 p_token1 => 'FEE_LINE',
6715 p_token1_value => l_fn_top_fee_ln_rec.name);
6716 END IF;
6717
6718 /* If no payments are defiend for the fee line then error out. */
6719
6720 IF ((NOT l_top_ln_pmt_exist) AND (NOT l_fn_sln_fee_amt_chk)) THEN
6721 x_return_status := Okl_Api.G_RET_STS_ERROR;
6722 OKL_API.set_message(
6723 p_app_name => G_APP_NAME,
6724 p_msg_name => 'OKL_QA_RQ_NO_PMTS',
6725 p_token1 => 'FEE_LINE',
6726 p_token1_value => l_fn_top_fee_ln_rec.name);
6727 END IF;
6728
6729 /* Check if a payment is defined for EACH of the financed fee sub-lines HEADER,
6730 if not error out. If there are multiple payments defiend for a financed
6731 fee sub-line HEADER error out. */
6732
6733 IF ((NOT l_top_ln_pmt_exist) AND (l_fn_sub_ln_fee_cnt > l_payment_sub_ln_cnt)) THEN
6734 x_return_status := Okl_Api.G_RET_STS_ERROR;
6735 OKL_API.set_message(
6736 p_app_name => G_APP_NAME,
6737 p_msg_name => 'OKL_QA_FN_PMTS_MISS_SLN',
6738 p_token1 => 'FEE_LINE',
6739 p_token1_value => l_fn_top_fee_ln_rec.name);
6740 ELSIF ((NOT l_top_ln_pmt_exist) AND (l_fn_sub_ln_fee_cnt < l_payment_sub_ln_cnt)) THEN
6741 x_return_status := Okl_Api.G_RET_STS_ERROR;
6742 OKL_API.set_message(
6743 p_app_name => G_APP_NAME,
6744 p_msg_name => 'OKL_QA_FN_MUL_SLN_PMTS',
6745 p_token1 => 'FEE_LINE',
6746 p_token1_value => l_fn_top_fee_ln_rec.name);
6747 END IF;
6748
6749
6750 FOR l_strm_slh_rec IN l_strm_slh_csr (p_chr_id,
6751 l_fn_top_fee_ln_rec.id)
6752 LOOP
6753 l_prev_pmnt := NULL;
6754 FOR l_strm_sll_rec IN l_strm_sll_csr (l_strm_slh_rec.rule_id,
6755 l_strm_slh_rec.rgp_id)
6756 LOOP
6757 IF (l_strm_sll_rec.stub_day IS NOT NULL) THEN -- do not check
6758 l_prev_pmnt := NULL; -- reset
6759 ELSE
6760 -- Check payment amount here
6761 IF (l_prev_pmnt = TO_NUMBER(NVL(l_strm_sll_rec.amt,'0'))) THEN
6762 -- Error
6763 Okl_Api.set_message(
6764 G_APP_NAME,
6765 'OKL_QA_INVALID_PMNT',
6766 'LINE_TYPE',
6767 l_fn_top_fee_ln_rec.line_type,
6768 'PMNT_TYPE',
6769 l_strm_slh_rec.stream_type
6770 );
6771 x_return_status := Okl_Api.G_RET_STS_ERROR;
6772 ELSE
6773 l_prev_pmnt := TO_NUMBER(NVL(l_strm_sll_rec.amt,'0'));
6774 END IF; --check
6775
6776 END IF; --stub
6777 END LOOP; --l_strm_sll_csr
6778 END LOOP; --l_strm_slh_csr
6779
6780 END IF;
6781
6782 OKL_API.END_ACTIVITY(x_msg_count => x_msg_count, x_msg_data => x_msg_data);
6783
6784 EXCEPTION
6785 WHEN OKL_API.G_EXCEPTION_ERROR THEN
6786 x_return_status := OKL_API.HANDLE_EXCEPTIONS(
6787 p_api_name => l_api_name,
6788 p_pkg_name => g_pkg_name,
6789 p_exc_name => 'OKL_API.G_RET_STS_ERROR',
6790 x_msg_count => x_msg_count,
6791 x_msg_data => x_msg_data,
6792 p_api_type => g_api_type);
6793
6794 WHEN OKL_API.G_EXCEPTION_UNEXPECTED_ERROR THEN
6795 x_return_status := OKL_API.HANDLE_EXCEPTIONS(
6796 p_api_name => l_api_name,
6797 p_pkg_name => g_pkg_name,
6798 p_exc_name => 'OKL_API.G_RET_STS_UNEXP_ERROR',
6799 x_msg_count => x_msg_count,
6800 x_msg_data => x_msg_data,
6801 p_api_type => g_api_type);
6802
6803 WHEN OTHERS THEN
6804 x_return_status := OKL_API.HANDLE_EXCEPTIONS(
6805 p_api_name => l_api_name,
6806 p_pkg_name => g_pkg_name,
6807 p_exc_name => 'OTHERS',
6808 x_msg_count => x_msg_count,
6809 x_msg_data => x_msg_data,
6810 p_api_type => g_api_type);
6811
6812 END validate_upfront_tax_fee;
6813
6814 END OKL_LA_SALES_TAX_PVT;