[Home] [Help]
PACKAGE BODY: APPS.OKL_LA_JE_PVT
Source
1 PACKAGE BODY OKL_LA_JE_PVT as
2 /* $Header: OKLRJNLB.pls 120.13.12020000.4 2013/03/28 10:45:07 racheruv ship $ */
3
4 -------------------------------------------------------------------------------------------------
5 -- GLOBAL MESSAGE CONSTANTS
6 -------------------------------------------------------------------------------------------------
7 G_NO_PARENT_RECORD CONSTANT VARCHAR2(200) := 'OKL_NO_PARENT_RECORD';
8 G_FND_APP CONSTANT VARCHAR2(200) := OKL_API.G_FND_APP;
9 G_REQUIRED_VALUE CONSTANT VARCHAR2(200) := OKL_API.G_REQUIRED_VALUE;
10 G_INVALID_VALUE CONSTANT VARCHAR2(200) := OKL_API.G_INVALID_VALUE;
11 G_UNEXPECTED_ERROR CONSTANT VARCHAR2(200) := 'OKL_CONTRACTS_UNEXP_ERROR';
12 G_SQLERRM_TOKEN CONSTANT VARCHAR2(200) := 'SQLerrm';
13 G_SQLCODE_TOKEN CONSTANT VARCHAR2(200) := 'SQLcode';
14 G_UPPERCASE_REQUIRED CONSTANT VARCHAR2(200) := 'OKL_CONTRACTS_UPPERCASE_REQ';
15 G_COL_NAME_TOKEN CONSTANT VARCHAR2(200) := OKL_API.G_COL_NAME_TOKEN;
16 ------------------------------------------------------------------------------------
17 -- GLOBAL EXCEPTION
18 ------------------------------------------------------------------------------------
19 G_EXCEPTION_HALT_VALIDATION EXCEPTION;
20 G_EXCEPTION_STOP_VALIDATION EXCEPTION;
21 G_API_TYPE CONSTANT VARCHAR2(4) := '_PVT';
22 G_API_VERSION CONSTANT NUMBER := 1.0;
23 G_SCOPE CONSTANT VARCHAR2(4) := '_PVT';
24
25 --Bug# 5964482
26 G_MODULE VARCHAR2(255) := 'okl.lla.okl_la_je_pvt';
27 G_DEBUG_ENABLED CONSTANT VARCHAR2(10) := OKL_DEBUG_PUB.CHECK_LOG_ENABLED;
28 G_IS_DEBUG_STATEMENT_ON BOOLEAN ;
29 --Bug# 5964482
30
31 -- GLOBAL VARIABLES
32 -----------------------------------------------------------------------------------
33
34 Function is_release_contract( p_contract_id NUMBER ) return varchar2 is
35
36 l_is_release_contract VARCHAR2(1) := 'N';
37
38 --cursor to check if contract is a re-lease contract
39 CURSOR l_chk_rel_khr_csr (p_chr_id IN Number) IS
40 SELECT 'Y'
41 FROM okc_k_headers_b CHR
42 where chr.ID = p_chr_id
43 AND nvl(chr.orig_system_source_code,'XXXX') = 'OKL_RELEASE';
44
45 l_rel_khr VARCHAR2(1) DEFAULT 'N';
46
47
48 --cursor to check if contract has re-lease assets
49 CURSOR l_chk_rel_ast_csr (p_chr_id IN Number) IS
50 SELECT 'Y'
51 FROM okc_k_headers_b CHR
52 WHERE nvl(chr.orig_system_source_code,'XXXX') <> 'OKL_RELEASE'
53 and chr.ID = p_chr_id
54 AND exists (SELECT '1'
55 FROM OKC_RULES_B rul
56 WHERE rul.dnz_chr_id = chr.id
57 AND rul.rule_information_category = 'LARLES'
58 AND nvl(rule_information1,'N') = 'Y');
59
60 l_rel_ast VARCHAR2(1) DEFAULT 'N';
61
62 Begin
63
64 OPEN l_chk_rel_khr_csr( p_contract_id );
65 FETCH l_chk_rel_khr_csr INTO l_rel_khr;
66 CLOSE l_chk_rel_khr_csr;
67
68 If ( nvl(l_rel_khr,'N') = 'Y' ) Then
69 l_is_release_contract := 'Y';
70 End If;
71
72 OPEN l_chk_rel_ast_csr( p_contract_id );
73 FETCH l_chk_rel_ast_csr INTO l_rel_ast;
74 CLOSE l_chk_rel_ast_csr;
75
76 If ( nvl(l_rel_ast,'N') = 'Y' ) Then
77 l_is_release_contract := 'Y';
78 End If;
79
80 return l_is_release_contract;
81
82 end is_release_contract;
83
84 -- in the following signature x_trxH_rec is
85 -- introduced as part of Sales Tax Project to return transaction record
86 Procedure generate_journal_entries(
87 p_api_version IN NUMBER,
88 p_init_msg_list IN VARCHAR2 DEFAULT Okl_Api.G_FALSE,
89 p_commit IN VARCHAR2 DEFAULT Okl_Api.G_FALSE,
90 p_contract_id IN NUMBER,
91 p_transaction_type IN VARCHAR2,
92 p_transaction_date IN DATE,
93 p_draft_yn IN VARCHAR2 DEFAULT Okl_Api.G_TRUE,
94 p_memo_yn IN VARCHAR2 DEFAULT Okl_Api.G_FALSE,
95 x_return_status OUT NOCOPY VARCHAR2,
96 x_msg_count OUT NOCOPY NUMBER,
97 x_msg_data OUT NOCOPY VARCHAR2,
98 x_trxH_rec OUT NOCOPY tcnv_rec_type) IS
99
100
101 -- Define PL/SQL Records and Tables
102 l_trxH_in_rec Okl_Trx_Contracts_Pvt.tcnv_rec_type;
103 l_trxL_in_rec Okl_Trx_Contracts_Pvt.tclv_rec_type;
104 l_trxH_out_rec Okl_Trx_Contracts_Pvt.tcnv_rec_type;
105 l_trxL_out_rec Okl_Trx_Contracts_Pvt.tclv_rec_type;
106
107 -- Define variables
108 l_sysdate DATE;
109 l_sysdate_trunc DATE;
110 l_return_status VARCHAR2(1) := Okl_Api.G_RET_STS_SUCCESS;
111 l_post_to_gl_yn VARCHAR2(1);
112
113 i NUMBER;
114 l_amount NUMBER;
115 l_init_msg_list VARCHAR2(1) := OKL_API.G_FALSE;
116 l_msg_count NUMBER;
117 l_msg_data VARCHAR2(2000);
118 l_currency_code okl_txl_cntrct_lns.currency_code%TYPE;
119 l_fnd_profile VARCHAR2(256);
120 l_cust_trx_type_id NUMBER;
121
122 l_msg_index_out NUMBER; --TBR
123
124 -- Define constants
125 l_api_name CONSTANT VARCHAR(30) := 'GENERATE_JOURNAL_ENTRIES';
126 l_api_version CONSTANT NUMBER := 1.0;
127
128 Cursor fnd_pro_csr IS
129 select mo_global.get_current_org_id() l_fnd_profile
130 from dual;
131 fnd_pro_rec fnd_pro_csr%ROWTYPE;
132
133 Cursor ra_cust_csr IS
134 select cust_trx_type_id l_cust_trx_type_id
135 from ra_cust_trx_types
136 where name = 'Invoice-OKL';
137 ra_cust_rec ra_cust_csr%ROWTYPE;
138
139 Cursor salesP_csr( chrId NUMBER) IS
140 select ct.object1_id1 id
141 from okc_contacts ct,
142 okc_contact_sources csrc,
143 okc_k_party_roles_b pty,
144 okc_k_headers_b chr
145 where ct.cpl_id = pty.id
146 and ct.cro_code = csrc.cro_code
147 and ct.jtot_object1_code = csrc.jtot_object_code
148 and ct.dnz_chr_id = chr.id
149 and pty.rle_code = csrc.rle_code
150 and csrc.cro_code = 'SALESPERSON'
151 and csrc.rle_code = 'LESSOR'
152 and csrc.buy_or_sell = chr.buy_or_sell
153 and pty.dnz_chr_id = chr.id
154 and pty.chr_id = chr.id
155 and chr.id = chrId;
156
157 l_salesP_rec salesP_csr%ROWTYPE;
158
159 Cursor custBillTo_csr( chrId NUMBER) IS
160 select bill_to_site_use_id cust_acct_site_id
161 from okc_k_headers_b
162 where id = chrId;
163
164 /* Rule migration - BTO
165
166 Cursor custBillTo_csr( chrId NUMBER) IS
167 select object1_id1 cust_acct_site_id
168 from okc_rules_b rul
169 where rul.rule_information_category = 'BTO'
170 and exists (select '1'
171 from okc_rule_groups_b rgp
172 where rgp.id = rul.rgp_id
173 and rgp.rgd_code = 'LABILL'
174 and rgp.chr_id = rul.dnz_chr_id
175 and rgp.chr_id = chrId );
176 */
177
178 l_custBillTo_rec custBillTo_csr%ROWTYPE;
179
180 CURSOR Product_csr (p_contract_id IN okl_products_v.id%TYPE) IS
181 SELECT khr.pdt_id product_id
182 ,NULL product_name
183 ,khr.sts_code contract_status
184 ,khr.start_date start_date
185 ,khr.currency_code currency_code
186 ,khr.authoring_org_id authoring_org_id
187 ,khr.currency_conversion_rate currency_conversion_rate
188 ,khr.currency_conversion_type currency_conversion_type
189 ,khr.currency_conversion_date currency_conversion_date
190 --Bug# 4622198
191 ,khr.scs_code
192 --Bug# 5964482: Accounting Engine CR
193 --Bug# 6073872: DFF attributes are being taken from okc_k_headers instead of okl_k_headers
194 ,khr.khr_attribute_category
195 ,khr.khr_attribute1
196 ,khr.khr_attribute2
197 ,khr.khr_attribute3
198 ,khr.khr_attribute4
199 ,khr.khr_attribute5
200 ,khr.khr_attribute6
201 ,khr.khr_attribute7
202 ,khr.khr_attribute8
203 ,khr.khr_attribute9
204 ,khr.khr_attribute10
205 ,khr.khr_attribute11
206 ,khr.khr_attribute12
207 ,khr.khr_attribute13
208 ,khr.khr_attribute14
209 ,khr.khr_attribute15
210 FROM okl_k_headers_full_v khr
211 WHERE khr.id = p_contract_id;
212
213 l_func_curr_code OKL_K_HEADERS_FULL_V.CURRENCY_CODE%TYPE;
214 l_chr_curr_code OKL_K_HEADERS_FULL_V.CURRENCY_CODE%TYPE;
215 x_currency_conversion_rate okl_k_headers_full_v.currency_conversion_rate%TYPE;
216 x_currency_conversion_type okl_k_headers_full_v.currency_conversion_type%TYPE;
217 x_currency_conversion_date okl_k_headers_full_v.currency_conversion_date%TYPE;
218
219 CURSOR Transaction_Type_csr (p_transaction_type IN okl_trx_types_v.name%TYPE ) IS
220 SELECT id trx_try_id
221 FROM okl_trx_types_tl
222 WHERE name = p_transaction_type
223 AND language = 'US';
224
225 CURSOR fnd_lookups_csr( lkp_type VARCHAR2, mng VARCHAR2 ) IS
226 select description,
227 lookup_code
228 from fnd_lookup_values
229 where language = 'US'
230 AND lookup_type = lkp_type
231 AND meaning = mng;
232
233 Cursor trx_csr( khrId NUMBER, tcntype VARCHAR2 ) is
234 Select txh.ID HeaderTransID,
235 txh.date_transaction_occurred date_transaction_occurred,
236 txh.tsu_code
237 From okl_trx_contracts txh
238 Where txh.tcn_type = tcntype
239 and txh.khr_id = khrId
240 --rkuttiya added for 12.1.1 Multi GAAP
241 and txh.representation_type = 'PRIMARY';
242 --
243
244 -- Cursor Types
245 l_Product_rec Product_csr%ROWTYPE;
246 l_Trx_Type_rec Transaction_Type_csr%ROWTYPE;
247 l_fnd_rec fnd_lookups_csr%ROWTYPE;
248 l_fnd_rec1 fnd_lookups_csr%ROWTYPE;
249 l_trx_rec trx_csr%ROWTYPE;
250
251
252 l_isJrnlGenAllowed BOOLEAN := TRUE;
253 l_passStatus VARCHAR2(256);
254 l_failStatus VARCHAR2(256);
255 p_chr_id VARCHAR2(2000) := TO_CHAR(p_contract_id);
256 l_transaction_type VARCHAR2(256) := p_transaction_type;
257 l_transaction_date DATE;
258
259
260 l_tmpl_identify_rec OKL_ACCOUNT_DIST_PVT.TMPL_IDENTIFY_REC_TYPE;
261 l_dist_info_rec OKL_ACCOUNT_DIST_PVT.dist_info_REC_TYPE;
262 l_template_tbl OKL_ACCOUNT_DIST_PVT.AVLV_TBL_TYPE;
263 l_amount_tbl OKL_ACCOUNT_DIST_PVT.AMOUNT_TBL_TYPE;
264 l_ctxt_val_tbl OKL_ACCOUNT_DIST_PVT.CTXT_VAL_TBL_TYPE;
265 l_acc_gen_primary_key_tbl OKL_ACCOUNT_DIST_PVT.acc_gen_primary_key;
266 l_has_trans VARCHAR2(1);
267 l_memo_yn VARCHAR2(1);
268
269 --Bug# 3153003
270 l_upd_trxH_rec Okl_Trx_Contracts_Pvt.tcnv_rec_type;
271 lx_upd_trxH_rec Okl_Trx_Contracts_Pvt.tcnv_rec_type;
272 --Bug# 3153003
273
274 --Bug# 4622198
275 l_fact_synd_code FND_LOOKUPS.Lookup_code%TYPE;
276 l_inv_acct_code OKC_RULES_B.Rule_Information1%TYPE;
277 --Bug# 4622198
278
279 --Added by dpsingh for LE uptake
280 CURSOR contract_num_csr (p_ctr_id1 NUMBER) IS
281 SELECT contract_number
282 FROM OKC_K_HEADERS_B
283 WHERE id = p_ctr_id1;
284
285 l_cntrct_number OKC_K_HEADERS_B.CONTRACT_NUMBER%TYPE;
286 l_legal_entity_id NUMBER;
287
288 --Bug# 5964482
289 l_trxl_del_tbl Okl_trx_contracts_pvt.tclv_tbl_type;
290 l_tclv_tbl Okl_trx_contracts_pvt.tclv_tbl_type;
291 x_tclv_tbl Okl_trx_contracts_pvt.tclv_tbl_type;
292 l_tcnv_rec Okl_trx_contracts_pvt.tcnv_rec_type;
293 x_tcnv_rec Okl_trx_contracts_pvt.tcnv_rec_type;
294
295 /* New Type Declarations*/
296 l_tmpl_identify_tbl Okl_Account_Dist_Pvt.tmpl_identify_tbl_type;
297 l_dist_info_tbl Okl_Account_Dist_Pvt.dist_info_tbl_type;
298 l_ctxt_tbl Okl_Account_Dist_Pvt.CTXT_TBL_TYPE;
299 l_template_out_tbl Okl_Account_Dist_Pvt.avlv_out_tbl_type;
300 l_amount_out_tbl Okl_Account_Dist_Pvt.amount_out_tbl_type;
301 l_acc_gen_tbl Okl_Account_Dist_Pvt.ACC_GEN_TBL_TYPE;
302
303 l_tcn_id NUMBER;
304 l_tcl_type okl_trx_types_tl.name%TYPE;
305 --Bug# 5964482 End
306
307 --Bug# 15992711, Start
308 -- cursor : to check whether Contract is having both new and re-leased assets or not
309 CURSOR check_con_csr (chrId NUMBER) IS
310 SELECT COUNT (*)
311 FROM (SELECT COUNT(*)
312 FROM okc_k_lines_b cleb,
313 okl_k_lines kle
314 WHERE kle.id = cleb.id
315 AND cleb.chr_id = chrId
316 --ndani - 27-Mar-2013 - Bug# 16558722 - Start
317 AND cleb.dnz_chr_id = chrid
318 AND cleb.lse_id = 33
319 AND cleb.sts_code <> 'ABANDONED'
320 --ndani - 27-Mar-2013 - Bug# 16558722 - End
321 GROUP BY NVL(kle.re_lease_yn,'N')
322 );
323
324 l_chk_contract_count NUMBER := 0;
325 l_trans_type VARCHAR2 (256) := 'X'; -- ndani - 14-Mar-2013, Bug# 16511024
326 --Bug# 15992711, End
327
328
329 BEGIN
330
331 --ndani - 14-Mar-2013, Start - Rebook accounting fix
332 --Bug# 16511024, Start
333 IF l_transaction_type = 'Rebook-Release' THEN
334 l_trans_type := l_transaction_type;
335 l_transaction_type := 'Rebook';
336
337 ELSIF l_transaction_type = 'Rebook' THEN
338 l_trans_type := l_transaction_type;
339 END IF;
340 --Bug# 16511024, End
341 --ndani - 14-Mar-2013, End - Rebook accounting fix
342
343 --Bug# 5964482
344 IF (G_DEBUG_ENABLED = 'Y') THEN
345 G_IS_DEBUG_STATEMENT_ON := OKL_DEBUG_PUB.CHECK_LOG_ON(G_MODULE, FND_LOG.LEVEL_STATEMENT);
346 END IF;
347 --Bug# 5964482 End
348
349 x_return_status := Okl_Api.G_RET_STS_SUCCESS;
350 l_sysdate := SYSDATE;
351 l_sysdate_trunc := trunc(SYSDATE);
352 i := 0;
353
354
355 x_return_status := OKL_API.START_ACTIVITY(
356 p_api_name => l_api_name,
357 p_pkg_name => g_pkg_name,
358 p_init_msg_list => p_init_msg_list,
359 l_api_version => l_api_version,
360 p_api_version => p_api_version,
361 p_api_type => G_API_TYPE,
362 x_return_status => x_return_status);
363
364 -- check if activity started successfully
365 If (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) then
366 raise OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
367 ElSIF (x_return_status = OKL_API.G_RET_STS_ERROR) then
368 raise OKL_API.G_EXCEPTION_ERROR;
369 End If;
370
371 --Bug# 5964482 : Disable draft Accounting
372 If (p_draft_yn = OKL_API.G_TRUE) Then
373 Null; -- do not do anything
374 ELSE --do normal accounting
375
376 -- Get product_id
377 OPEN Product_csr(p_contract_id);
378 FETCH Product_csr INTO l_Product_rec;
379 IF Product_csr%NOTFOUND THEN
380 Okl_Api.SET_MESSAGE(G_APP_NAME, G_REQUIRED_VALUE,G_COL_NAME_TOKEN, 'Product');
381 CLOSE Product_csr;
382 RAISE Okl_Api.G_EXCEPTION_ERROR;
383 END IF;
384 CLOSE Product_csr;
385
386 If ( p_transaction_date IS NULL ) Then
387 l_transaction_date := l_Product_rec.start_date;
388 Else
389 l_transaction_date := p_transaction_date;
390 End If;
391
392 l_chr_curr_code := l_Product_rec.CURRENCY_CODE;
393 l_func_curr_code := OKC_CURRENCY_API.GET_OU_CURRENCY(l_Product_rec.authoring_org_id);
394
395 x_currency_conversion_rate := NULL;
396 x_currency_conversion_type := NULL;
397 x_currency_conversion_date := NULL;
398
399 If ( ( l_func_curr_code IS NOT NULL) AND
400 ( l_chr_curr_code <> l_func_curr_code ) ) Then
401
402 x_currency_conversion_type := l_Product_rec.currency_conversion_type;
403 x_currency_conversion_date := l_Product_rec.start_date;
404
405 If ( l_Product_rec.currency_conversion_type = 'User') Then
406 x_currency_conversion_rate := l_Product_rec.currency_conversion_rate;
407 x_currency_conversion_date := l_Product_rec.currency_conversion_date;
408 Else
409 x_currency_conversion_rate := okl_accounting_util.get_curr_con_rate(
410 p_from_curr_code => l_chr_curr_code,
411 p_to_curr_code => l_func_curr_code,
412 p_con_date => l_Product_rec.start_date,
413 p_con_type => l_Product_rec.currency_conversion_type);
414
415 End If;
416
417 End If;
418
419 IF ((p_draft_yn = OKL_API.G_TRUE) AND (l_Product_rec.contract_status <> 'BOOKED')) Then
420 /*--Bug# 5964482 Commenting the code as Draft Accounting is being disabled
421 okl_contract_status_pub.get_contract_status(l_api_version,
422 p_init_msg_list,
423 x_return_status,
424 x_msg_count,
425 x_msg_data,
426 l_isJrnlGenAllowed,
427 l_passStatus,
428 l_failStatus,
429 OKL_CONTRACT_STATUS_PUB.G_K_JOURNAL,
430 p_chr_id);
431
432
433 If ( l_isJrnlGenAllowed = FALSE ) then
434 x_return_status := OKL_API.G_RET_STS_ERROR;
435 okl_api.set_message(
436 p_app_name => G_APP_NAME,
437 p_msg_name => OKL_CONTRACT_STATUS_PUB.G_CANNOT_GENJRNL);
438 raise OKL_API.G_EXCEPTION_ERROR;
439 ElsIf (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) then
440 raise OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
441 ElSIF (x_return_status = OKL_API.G_RET_STS_ERROR) then
442 raise OKL_API.G_EXCEPTION_ERROR;
443 End If;
444 -----Bug# 5964482 End of comments - Draft Accounting Disabled*/
445 Null;
446
447 End If;
448
449 -- Validate passed parameters
450 IF ( p_contract_id = Okl_Api.G_MISS_NUM )
451 OR ( p_contract_id IS NULL ) THEN
452 Okl_Api.Set_Message(G_APP_NAME, G_REQUIRED_VALUE,G_COL_NAME_TOKEN, 'contract');
453 RAISE Okl_Api.G_EXCEPTION_ERROR;
454 END IF;
455
456 --Bug 5909373
457 /*
458 If ( is_release_contract( p_contract_id ) = 'Y' ) Then
459 l_transaction_type := 'Release';
460 End If;*/
461 --Bug 5909373
462
463 IF ( l_transaction_type = Okl_Api.G_MISS_CHAR )
464 OR ( l_transaction_type IS NULL ) THEN
465 Okl_Api.Set_Message(G_APP_NAME, G_REQUIRED_VALUE,G_COL_NAME_TOKEN, l_transaction_type);
466 RAISE Okl_Api.G_EXCEPTION_ERROR;
467 END IF;
468
469 -- set POST_TO_GL and MEMO_YN flag always to YES !!!!
470 l_memo_yn := OKL_API.G_MISS_CHAR;
471
472 --ndani - 18-Mar-2013, Start - Rebook accounting fix
473 --Bug# 16511024, Start
474 IF l_trans_type = 'Rebook-Release' THEN
475 l_memo_yn := 'Y';
476
477 ELSIF l_trans_type = 'Rebook' THEN
478 l_memo_yn := 'N';
479 END IF;
480 --Bug# 16511024, End
481 --ndani - 18-Mar-2013, End - Rebook accounting fix
482
483 IF (p_draft_yn = OKL_API.G_TRUE) THEN
484 --Bug# 5964482 : Disable Draft Accounting
485 --l_post_to_gl_yn := 'N';
486 --l_memo_yn := 'Y';
487 Null;
488 --Bug# 5964482 End
489 ELSE
490 l_post_to_gl_yn := 'Y';
491 END IF;
492
493 l_currency_code := l_Product_rec.currency_code;
494
495 -- Check Transaction_Type
496 OPEN Transaction_Type_csr(l_transaction_type);
497 FETCH Transaction_Type_csr INTO l_Trx_Type_rec;
498 IF Transaction_Type_csr%NOTFOUND THEN
499 Okl_Api.SET_MESSAGE(G_APP_NAME, G_INVALID_VALUE,G_COL_NAME_TOKEN, l_transaction_type);
500 CLOSE Transaction_Type_csr;
501 RAISE Okl_Api.G_EXCEPTION_ERROR;
502 END IF;
503 CLOSE Transaction_Type_csr;
504
505 OPEN fnd_lookups_csr('OKL_TCN_TYPE', l_transaction_type);
506 FETCH fnd_lookups_csr INTO l_fnd_rec;
507 IF fnd_lookups_csr%NOTFOUND THEN
508 CLOSE fnd_lookups_csr;
509 OPEN fnd_lookups_csr('OKL_TCN_TYPE', 'Miscellaneous');
510 FETCH fnd_lookups_csr INTO l_fnd_rec;
511 IF fnd_lookups_csr%NOTFOUND THEN
512 Okl_Api.SET_MESSAGE(G_APP_NAME, G_INVALID_VALUE,G_COL_NAME_TOKEN, l_transaction_type);
513 CLOSE fnd_lookups_csr;
514 RAISE Okl_Api.G_EXCEPTION_ERROR;
515 End If;
516 END IF;
517 CLOSE fnd_lookups_csr;
518
519 OPEN trx_csr(p_contract_id,l_fnd_rec.lookup_code);
520 FETCH trx_csr INTO l_trx_rec;
521 IF (l_fnd_rec.lookup_code = 'TRBK') THEN -- For Rebook, create a new trans always
522 l_has_trans := OKL_API.G_FALSE;
523 ELSIF (trx_csr%FOUND AND l_trx_rec.tsu_code = 'ENTERED') THEN -- Otherwise use existing transaction, if it is in Entered status
524 l_has_trans := OKL_API.G_TRUE;
525 ELSE
526 l_has_trans := OKL_API.G_FALSE; -- In all other cases, create a new trans
527 END IF;
528 CLOSE trx_csr;
529
530 l_trxH_in_rec.khr_id := p_contract_id;
531 l_trxH_in_rec.pdt_id := l_Product_rec.product_id;
532 l_trxH_in_rec.tcn_type := l_fnd_rec.lookup_code; --'BKG'/'SYND'/'TRBK';
533 l_trxH_in_rec.currency_code := l_currency_code;
534 l_trxH_in_rec.try_id := l_Trx_Type_rec.trx_try_id;
535
536 --Added by dpsingh for LE Uptake
537 l_legal_entity_id := OKL_LEGAL_ENTITY_UTIL.get_khr_le_id(p_contract_id) ;
538 IF l_legal_entity_id IS NOT NULL THEN
539 l_trxH_in_rec.legal_entity_id := l_legal_entity_id;
540 ELSE
541 -- get the contract number
542 OPEN contract_num_csr(p_contract_id);
543 FETCH contract_num_csr INTO l_cntrct_number;
544 CLOSE contract_num_csr;
545 Okl_Api.set_message(p_app_name => g_app_name,
546 p_msg_name => 'OKL_LE_NOT_EXIST_CNTRCT',
547 p_token1 => 'CONTRACT_NUMBER',
548 p_token1_value => l_cntrct_number);
549 RAISE OKL_API.G_EXCEPTION_ERROR;
550 END IF;
551 If ( p_draft_yn = OKL_API.G_TRUE ) Then
552 --Bug# 5964482 : Disable draft Accounting
553 Null;
554 --l_trxH_in_rec.description := 'Draft Journals - ' || l_transaction_type;
555 Else
556 l_trxH_in_rec.description := 'Journals - ' || l_transaction_type;
557 End If;
558
559 l_trxH_in_rec.currency_conversion_rate := x_currency_conversion_rate;
560 l_trxH_in_rec.currency_conversion_type := x_currency_conversion_type;
561 l_trxH_in_rec.currency_conversion_date := x_currency_conversion_date;
562
563 --Bug# 5964482 : code for l_trxL_in_rec not changed here
564 -- But, l_trxL_in_rec will not be used because of
565 -- changes for accounting CR.
566 l_trxL_in_rec.khr_id := p_contract_id;
567 l_trxL_in_rec.line_number := 1;
568 l_trxL_in_rec.currency_code := l_currency_code;
569 If ( p_draft_yn = OKL_API.G_TRUE ) Then
570 -- Bug# 5964482 : Disable draft accounting
571 Null;
572 --l_trxL_in_rec.description := 'Draft Journals - ' || l_transaction_type;
573 Else
574 l_trxL_in_rec.description := 'Journals - ' || l_transaction_type;
575 End If;
576
577 --Bug# 5964482
578 If (l_transaction_type = 'Rebook') then
579 l_tcl_type := 'Rebooking';
580 Else
581 l_tcl_type := l_transaction_type;
582 End If;
583 --Bug# 5964482
584
585 --OPEN fnd_lookups_csr('OKL_TCL_TYPE', l_transaction_type);
586 OPEN fnd_lookups_csr('OKL_TCL_TYPE', l_tcl_type);
587 FETCH fnd_lookups_csr INTO l_fnd_rec1;
588 IF fnd_lookups_csr%NOTFOUND THEN
589 l_trxL_in_rec.tcl_type := 'MAE';
590 Else
591 l_trxL_in_rec.tcl_type := l_fnd_rec1.lookup_code;
592 END IF;
593 CLOSE fnd_lookups_csr;
594
595 If ( l_has_trans = OKL_API.G_FALSE ) Then
596
597 If (UPPER(l_fnd_rec.lookup_code) = 'TRBK') THEN
598 l_trxH_in_rec.rbr_code := ''; -- lokup 'OKL_REBOOK_REASON'
599 l_trxH_in_rec.rpy_code := ''; -- lokup 'OKL_REBOOK_PROCESS_TYPE'
600 End If;
601
602 OPEN fnd_lookups_csr('OKL_TRANSACTION_STATUS', 'Submitted');
603 FETCH fnd_lookups_csr INTO l_fnd_rec;
604 IF fnd_lookups_csr%NOTFOUND THEN
605 Okl_Api.SET_MESSAGE(G_APP_NAME, G_INVALID_VALUE,G_COL_NAME_TOKEN,l_transaction_type);
606 CLOSE fnd_lookups_csr;
607 RAISE Okl_Api.G_EXCEPTION_ERROR;
608 END IF;
609 CLOSE fnd_lookups_csr;
610
611 l_trxH_in_rec.tsu_code := l_fnd_rec.lookup_code;
612
613 l_trxH_in_rec.date_transaction_occurred := l_transaction_date;
614 l_trxH_in_rec.description := l_fnd_rec.description;
615 --Bug# 5964482 : Accounting engine CR for uniform accounting call
616 --Bug# 6073872: DFF attributes to be taken from okl_k_headers
617 l_trxH_in_rec.attribute_category := l_product_rec.khr_attribute_category;
618 l_trxH_in_rec.attribute1 := l_product_rec.khr_attribute1;
619 l_trxH_in_rec.attribute2 := l_product_rec.khr_attribute2;
620 l_trxH_in_rec.attribute3 := l_product_rec.khr_attribute3;
621 l_trxH_in_rec.attribute4 := l_product_rec.khr_attribute4;
622 l_trxH_in_rec.attribute5 := l_product_rec.khr_attribute5;
623 l_trxH_in_rec.attribute6 := l_product_rec.khr_attribute6;
624 l_trxH_in_rec.attribute7 := l_product_rec.khr_attribute7;
625 l_trxH_in_rec.attribute8 := l_product_rec.khr_attribute8;
626 l_trxH_in_rec.attribute9 := l_product_rec.khr_attribute9;
627 l_trxH_in_rec.attribute10 := l_product_rec.khr_attribute10;
628 l_trxH_in_rec.attribute11 := l_product_rec.khr_attribute11;
629 l_trxH_in_rec.attribute12 := l_product_rec.khr_attribute12;
630 l_trxH_in_rec.attribute13 := l_product_rec.khr_attribute13;
631 l_trxH_in_rec.attribute14 := l_product_rec.khr_attribute14;
632 l_trxH_in_rec.attribute15 := l_product_rec.khr_attribute15;
633 --Bug# 5964482 : End
634
635 -- Create Transaction Header, Lines
636 Okl_Trx_Contracts_Pub.create_trx_contracts(
637 p_api_version => l_api_version
638 ,p_init_msg_list => l_init_msg_list
639 ,x_return_status => x_return_status
640 ,x_msg_count => l_msg_count
641 ,x_msg_data => l_msg_data
642 ,p_tcnv_rec => l_trxH_in_rec
643 ,x_tcnv_rec => l_trxH_out_rec);
644
645 IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
646 RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
647 ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
648 RAISE Okl_Api.G_EXCEPTION_ERROR;
649 END IF;
650
651 IF ((l_trxH_out_rec.id = OKL_API.G_MISS_NUM) OR
652 (l_trxH_out_rec.id IS NULL) ) THEN
653 OKL_API.set_message(G_APP_NAME, G_REQUIRED_VALUE,G_COL_NAME_TOKEN,'TRANSACTION_ID');
654 RAISE OKL_API.G_EXCEPTION_ERROR;
655 END IF;
656
657 -- populate the output transaction record
658 x_trxH_rec := l_trxH_out_rec;
659
660 l_fnd_rec := null;
661
662 /*--------------Bug# 5964482 : Commenting creation of transaction lines
663 -- as transaction lines will be created based on unified accounting call
664 -- Create Transaction Line
665 --l_trxL_in_rec.tcn_id := l_trxH_out_rec.id;
666
667 -- Create Transaction Header, Lines
668 --Okl_Trx_Contracts_Pub.create_trx_cntrct_lines(
669 --p_api_version => l_api_version
670 --,p_init_msg_list => l_init_msg_list
671 --,x_return_status => x_return_status
672 --,x_msg_count => l_msg_count
673 --,x_msg_data => l_msg_data
674 --,p_tclv_rec => l_trxL_in_rec
675 --,x_tclv_rec => l_trxL_out_rec);
676
677 --IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
678 -- RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
679 --ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
680 -- RAISE Okl_Api.G_EXCEPTION_ERROR;
681 --END IF;
682 --IF ((l_trxL_out_rec.id = OKL_API.G_MISS_NUM) OR
683 -- (l_trxL_out_rec.id IS NULL) ) THEN
684 -- OKL_API.set_message(G_APP_NAME, G_REQUIRED_VALUE,G_COL_NAME_TOKEN,'TRANSACTION_ID');
685 -- RAISE OKL_API.G_EXCEPTION_ERROR;
686 --END IF;
687
688 --l_dist_info_rec.SOURCE_ID := l_trxL_out_rec.id;
689 --l_dist_info_rec.ACCOUNTING_DATE := l_trxH_out_rec.date_transaction_occurred;
690 -------------Bug# 5964482 - End of Comments -------------------------*/
691 ELSE
692
693 ------------------
694 --Bug# : 3153003
695 -----------------
696 --if transaction exists change the date transaction occured
697 l_upd_trxH_rec.id := l_trx_rec.HeaderTransID;
698 l_upd_trxH_rec.date_transaction_occurred := l_transaction_date;
699 Okl_Trx_Contracts_Pub.update_trx_contracts(
700 p_api_version => l_api_version
701 ,p_init_msg_list => l_init_msg_list
702 ,x_return_status => x_return_status
703 ,x_msg_count => l_msg_count
704 ,x_msg_data => l_msg_data
705 ,p_tcnv_rec => l_upd_trxH_rec
706 ,x_tcnv_rec => lx_upd_trxH_rec);
707
708 IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
709 RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
710 ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
711 RAISE Okl_Api.G_EXCEPTION_ERROR;
712 END IF;
713
714 IF ((lx_upd_trxH_rec.id = OKL_API.G_MISS_NUM) OR
715 (lx_upd_trxH_rec.id IS NULL) ) THEN
716 OKL_API.set_message(G_APP_NAME, G_REQUIRED_VALUE,G_COL_NAME_TOKEN,'TRANSACTION_ID');
717 RAISE OKL_API.G_EXCEPTION_ERROR;
718 END IF;
719
720 -- populate the output transaction record
721 x_trxH_rec := lx_upd_trxH_rec;
722 l_trxH_out_rec := lx_upd_trxH_rec;
723
724
725 --Bug# 5964482 : Coomented for Accounting engine CR
726 --l_dist_info_rec.SOURCE_ID := l_trx_rec.LineTransId;
727 --l_dist_info_rec.ACCOUNTING_DATE := l_trx_rec.date_transaction_occurred;
728 --l_dist_info_rec.ACCOUNTING_DATE := lx_upd_trxH_rec.date_transaction_occurred;
729 --Bug# 5964482 : End of Comments
730
731 -----------------------
732 --Bug# : 3153003
733 -----------------------
734
735 ----------------------
736 --Bug# 5964482
737 -----------------------
738 --delete existing lines
739 -- Commented out code to delete_trx_cntrct_lines since draft journal entry is always FALSE
740 /*l_trxl_del_tbl.delete;
741 For l_trx_rec in trx_csr(p_contract_id,l_fnd_rec.lookup_code)
742 Loop
743 l_trxl_del_tbl(i).id := l_trx_rec.linetransid;
744 End Loop;
745
746 okl_trx_contracts_pub.delete_trx_cntrct_lines(
747 p_api_version => l_api_version,
748 p_init_msg_list => l_init_msg_list,
749 x_return_status => x_return_status,
750 x_msg_count => l_msg_count,
751 x_msg_data => l_msg_data,
752 p_tclv_tbl => l_trxl_del_tbl);
753
754 IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
755 RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
756 ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
757 RAISE Okl_Api.G_EXCEPTION_ERROR;
758 END IF;
759 --End delete existing lines
760 ---------------------------
761 --End Bug# 5964482
762 ---------------------------*/
763
764 END IF;
765
766 l_tmpl_identify_rec.TRANSACTION_TYPE_ID := l_Trx_Type_rec.trx_try_id;
767 l_tmpl_identify_rec.PRODUCT_ID := l_Product_rec.product_id;
768 l_tmpl_identify_rec.memo_yn := l_memo_yn;
769
770 --Bug# 4622198 :For special accounting treatment
771 OKL_SECURITIZATION_PVT.Check_Khr_ia_associated(
772 p_api_version => p_api_version,
773 p_init_msg_list => p_init_msg_list,
774 x_return_status => x_return_status,
775 x_msg_count => x_msg_count,
776 x_msg_data => x_msg_data,
777 p_khr_id => p_chr_id,
778 p_scs_code => l_product_rec.scs_code,
779 p_trx_date => l_transaction_date,
780 x_fact_synd_code => l_fact_synd_code,
781 x_inv_acct_code => l_inv_acct_code
782 );
783
784 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
785 RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
786 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
787 RAISE OKL_API.G_EXCEPTION_ERROR;
788 END IF;
789
790 l_tmpl_identify_rec.factoring_synd_flag := l_fact_synd_code;
791 l_tmpl_identify_rec.investor_code := l_inv_acct_code;
792 --Bug# 4622198
793
794 -----------------
795 --Bug 5964482 : Accounting CR - get template information and build template line records
796 -------------------
797 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
798 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'Before Call to OKL_ACCOUNT_DIST_PUB.GET_TEMPLATE_INFO : '||x_return_status);
799 END IF;
800 --Call to get_template_info to determine the number of transaction lines to be created
801 Okl_Account_Dist_Pub.GET_TEMPLATE_INFO(p_api_version => p_api_version,
802 p_init_msg_list => p_init_msg_list,
803 x_return_status => x_return_status,
804 x_msg_count => x_msg_count,
805 x_msg_data => x_msg_data,
806 p_tmpl_identify_rec => l_tmpl_identify_rec,
807 x_template_tbl => l_template_tbl,
808 p_validity_date => l_trxH_out_rec.date_transaction_occurred);
809 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
810 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'After Call to OKL_ACCOUNT_DIST_PUB.GET_TEMPLATE_INFO : '||x_return_status);
811 END IF;
812 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
813 RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
814 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
815 RAISE OKL_API.G_EXCEPTION_ERROR;
816 END IF;
817 -- gboomina Bug 6151201 - Start
818 -- check whether templates present or not. If not throw error.
819 IF l_template_tbl.COUNT = 0 THEN
820 Okl_Api.set_message(p_app_name => g_app_name,
821 p_msg_name => 'OKL_LA_NO_ACCOUNTING_TMPLTS',
822 p_token1 => 'TRANSACTION_TYPE',
823 p_token1_value => l_transaction_type);
824 RAISE OKL_API.G_EXCEPTION_ERROR;
825 END IF;
826 -- gboomina Bug 6151201 - End
827
828 --Build the transaction line table of records
829 FOR i IN l_template_tbl.FIRST..l_template_tbl.LAST
830 LOOP
831 l_tclv_tbl(i).line_number := i;
832 l_tclv_tbl(i).khr_id := p_contract_id;
833 l_tclv_tbl(i).sty_id := l_template_tbl(i).sty_id;
834 l_tclv_tbl(i).tcl_type := l_trxl_in_rec.tcl_type;
835 If ( p_draft_yn = OKL_API.G_TRUE ) Then
836 --Bug# 5964482 : disbale draft accounting
837 Null;
838 --l_tclv_tbl(i).description := 'Draft Journals - ' || l_transaction_type;
839 Else
840 l_tclv_tbl(i).description := 'Journals - ' || l_transaction_type;
841 End If;
842 l_tclv_tbl(i).tcn_id := l_trxh_out_rec.id;
843 l_tclv_tbl(i).currency_code := l_currency_code;
844 END LOOP;
845
846
847 --Call to create transaction lines
848 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
849 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'Before OKL_TRX_CONTRACTS_PUB.create_trx_cntrct_lines :'|| x_return_status);
850 END IF;
851 Okl_Trx_Contracts_Pub.create_trx_cntrct_lines(
852 p_api_version => l_api_version
853 ,p_init_msg_list => l_init_msg_list
854 ,x_return_status => x_return_status
855 ,x_msg_count => l_msg_count
856 ,x_msg_data => l_msg_data
857 ,p_tclv_tbl => l_tclv_tbl
858 ,x_tclv_tbl => x_tclv_tbl);
859 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
860 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'Before OKL_TRX_CONTRACTS_PUB.create_trx_cntrct_lines :'|| x_return_status);
861 END IF;
862 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
863 RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
864 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
865 RAISE OKL_API.G_EXCEPTION_ERROR;
866 END IF;
867
868 /* Populating the tmpl_identify_tbl from the template_tbl returned by get_template_info*/
869
870 FOR i in l_template_tbl.FIRST.. l_template_tbl.LAST
871 LOOP
872 l_tmpl_identify_tbl(i).product_id := l_Product_rec.product_id;
873 l_tmpl_identify_tbl(i).transaction_type_id := l_Trx_Type_rec.trx_try_id;
874 l_tmpl_identify_tbl(i).stream_type_id := l_template_tbl(i).sty_id;
875 l_tmpl_identify_tbl(i).advance_arrears := l_template_tbl(i).advance_arrears;
876 l_tmpl_identify_tbl(i).prior_year_yn := l_template_tbl(i).prior_year_yn;
877 l_tmpl_identify_tbl(i).memo_yn := l_template_tbl(i).memo_yn;
878 l_tmpl_identify_tbl(i).factoring_synd_flag := l_template_tbl(i).factoring_synd_flag;
879 l_tmpl_identify_tbl(i).investor_code := l_template_tbl(i).inv_code;
880 l_tmpl_identify_tbl(i).SYNDICATION_CODE := l_template_tbl(i).syt_code;
881 l_tmpl_identify_tbl(i).FACTORING_CODE := l_template_tbl(i).fac_code;
882 --ndani - 27-Mar-2013 - Bug# 16558722 - Start, Added condition to raise error when l_memo_yn is not same as l_template_tbl(i).memo_yn flag
883 IF l_transaction_type = 'Rebook' THEN
884 IF l_template_tbl(i).memo_yn <> l_memo_yn THEN
885 Okl_Api.set_message(p_app_name => g_app_name,
886 p_msg_name => 'OKL_LA_NO_ACCOUNTING_TMPLTS',
887 p_token1 => 'TRANSACTION_TYPE',
888 p_token1_value => l_transaction_type);
889 RAISE OKL_API.G_EXCEPTION_ERROR;
890 END IF;
891 END IF;
892 --ndani - 27-Mar-2013 - Bug# 16558722 - End
893 END LOOP;
894 --Bug# 5964482 END
895
896 /* -- Bug# 5964482 - code commented
897 --l_dist_info_rec.SOURCE_TABLE := 'OKL_TXL_CNTRCT_LNS';
898 --l_dist_info_rec.GL_REVERSAL_FLAG := 'N';
899 --l_dist_info_rec.POST_TO_GL := l_post_to_gl_yn;
900 --l_dist_info_rec.CONTRACT_ID := p_contract_id;
901
902 --l_dist_info_rec.currency_conversion_rate := x_currency_conversion_rate;
903 --l_dist_info_rec.currency_conversion_type := x_currency_conversion_type;
904 --l_dist_info_rec.currency_conversion_date := x_currency_conversion_date;
905 --l_dist_info_rec.currency_code := l_currency_code;
906 ----Bug# 5964482 - end of commented code */
907
908 l_acc_gen_primary_key_tbl(1).source_table := 'FINANCIALS_SYSTEM_PARAMETERS';
909 OPEN fnd_pro_csr;
910 FETCH fnd_pro_csr INTO fnd_pro_rec;
911 If ( fnd_pro_csr%NOTFOUND ) Then
912 l_acc_gen_primary_key_tbl(1).primary_key_column := '';
913 Else
914 l_acc_gen_primary_key_tbl(1).primary_key_column := fnd_pro_rec.l_fnd_profile;
915 End If;
916 CLOSE fnd_pro_csr;
917
918 l_acc_gen_primary_key_tbl(2).source_table := 'AR_SITE_USES_V';
919 OPEN custBillTo_csr(p_contract_id);
920 FETCH custBillTo_csr INTO l_custBillTo_rec;
921 CLOSE custBillTo_csr;
922 l_acc_gen_primary_key_tbl(2).primary_key_column := l_custBillTo_rec.cust_acct_site_id;
923
924 l_acc_gen_primary_key_tbl(3).source_table := 'RA_CUST_TRX_TYPES';
925 OPEN ra_cust_csr;
926 FETCH ra_cust_csr INTO ra_cust_rec;
927 If ( ra_cust_csr%NOTFOUND ) Then
928 l_acc_gen_primary_key_tbl(3).primary_key_column := '';
929 Else
930 l_acc_gen_primary_key_tbl(3).primary_key_column := TO_CHAR(ra_cust_rec.l_cust_trx_type_id);
931 End If;
932 CLOSE ra_cust_csr;
933
934 l_acc_gen_primary_key_tbl(4).source_table := 'JTF_RS_SALESREPS_MO_V';
935 OPEN salesP_csr(p_contract_id);
936 FETCH salesP_csr INTO l_salesP_rec;
937 CLOSE salesP_csr;
938 l_acc_gen_primary_key_tbl(4).primary_key_column := l_salesP_rec.id;
939
940 --Bug# 15992711, Start
941
942 --Check Contract is mixed contract or not
943 OPEN check_con_csr (p_contract_id);
944 FETCH check_con_csr
945 INTO l_chk_contract_count;
946 CLOSE check_con_csr;
947
948 IF (l_chk_contract_count = 2) THEN
949 --Set global parameter
950 IF l_transaction_type = 'Booking' THEN
951 l_ctxt_val_tbl(1).NAME := 'NEW_RELEASE_ASSET';
952 l_ctxt_val_tbl(1).VALUE := 'NEW';
953 ELSIF l_transaction_type = 'Release' THEN
954 l_ctxt_val_tbl(1).NAME := 'NEW_RELEASE_ASSET';
955 l_ctxt_val_tbl(1).VALUE := 'RELEASE';
956 --ndani - 14-Mar-2013, Start Bug# 16511024 - Rebook accounting fix
957 ELSIF l_trans_type = 'Rebook' THEN
958 l_ctxt_val_tbl(1).NAME := 'NEW_RELEASE_ASSET';
959 l_ctxt_val_tbl(1).VALUE := 'NEW';
960 ELSIF l_trans_type = 'Rebook-Release' THEN
961 l_ctxt_val_tbl(1).NAME := 'NEW_RELEASE_ASSET';
962 l_ctxt_val_tbl(1).VALUE := 'RELEASE';
963 --ndani - 14-Mar-2013, End Bug# 16511024 - Rebook accounting fix
964 END IF;
965 END IF;
966 --Bug# 15992711, End
967
968 --Bug# 5964482 : Accounting engine CR
969 /* Populating the dist_info_Tbl */
970 FOR i in x_tclv_tbl.FIRST..x_tclv_tbl.LAST
971 LOOP
972 --Assigning the account generator table
973 l_acc_gen_tbl(i).acc_gen_key_tbl := l_acc_gen_primary_key_tbl;
974 l_acc_gen_tbl(i).source_id := x_tclv_tbl(i).id;
975
976 IF (l_ctxt_val_tbl.COUNT > 0) THEN
977 l_ctxt_tbl(i).ctxt_val_tbl := l_ctxt_val_tbl;
978 l_ctxt_tbl(i).source_id := x_tclv_tbl(i).id;
979 END IF;
980
981 l_dist_info_tbl(i).SOURCE_ID := x_tclv_tbl(i).id;
982 l_dist_info_tbl(i).SOURCE_TABLE := 'OKL_TXL_CNTRCT_LNS';
983 l_dist_info_tbl(i).GL_REVERSAL_FLAG := 'N';
984 l_dist_info_tbl(i).POST_TO_GL := l_post_to_gl_yn;
985 l_dist_info_tbl(i).CONTRACT_ID := p_contract_id;
986
987 l_dist_info_tbl(i).currency_conversion_rate := x_currency_conversion_rate;
988 l_dist_info_tbl(i).currency_conversion_type := x_currency_conversion_type;
989 l_dist_info_tbl(i).currency_conversion_date := x_currency_conversion_date;
990 l_dist_info_tbl(i).currency_code := l_currency_code;
991 l_dist_info_tbl(i).ACCOUNTING_DATE := l_trxh_out_rec.date_transaction_occurred;
992 END LOOP;
993
994 --Assigning transaction header id from the transaction header record created
995 l_tcn_id := l_trxH_out_rec.id;
996
997
998 /* Making the new single accounting engine call*/
999
1000 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
1001 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'Before accounting engine OKL_ACCOUNT_DIST_PVT.CREATE_ACCOUNTING_DIST call :'|| x_return_status);
1002 END IF;
1003 Okl_Account_Dist_Pvt.CREATE_ACCOUNTING_DIST(
1004 p_api_version => l_api_version,
1005 p_init_msg_list => p_init_msg_list,
1006 x_return_status => x_return_status,
1007 x_msg_count => x_msg_count,
1008 x_msg_data => x_msg_data,
1009 p_tmpl_identify_tbl => l_tmpl_identify_tbl,
1010 p_dist_info_tbl => l_dist_info_tbl,
1011 p_ctxt_val_tbl => l_ctxt_tbl,
1012 p_acc_gen_primary_key_tbl => l_acc_gen_tbl,
1013 x_template_tbl => l_template_out_tbl,
1014 x_amount_tbl => l_amount_out_tbl,
1015 p_trx_header_id => l_tcn_id);
1016
1017 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
1018 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'After accounting engine OKL_ACCOUNT_DIST_PVT.CREATE_ACCOUNTING_DIST call :'|| x_return_status);
1019 END IF;
1020
1021 IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
1022 RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
1023 ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
1024 RAISE Okl_Api.G_EXCEPTION_ERROR;
1025 END IF;
1026
1027 /* --Bug# 5964482 : Code commented
1028 --If ( l_has_trans = OKL_API.G_TRUE ) Then
1029 -- l_trxH_in_rec.id := l_trx_rec.HeaderTransId;
1030 --Else
1031 -- l_trxH_in_rec.id := l_trxH_out_rec.id;
1032 --End If;
1033
1034 --l_trxL_in_rec.id := l_dist_info_rec.source_id;
1035 ----Bug# 5964482 : End of Comments */
1036
1037 OPEN fnd_lookups_csr('OKL_TRANSACTION_STATUS', 'Processed');
1038 FETCH fnd_lookups_csr INTO l_fnd_rec;
1039 IF fnd_lookups_csr%NOTFOUND THEN
1040 Okl_Api.SET_MESSAGE(G_APP_NAME, G_INVALID_VALUE,G_COL_NAME_TOKEN,l_transaction_type);
1041 CLOSE fnd_lookups_csr;
1042 RAISE Okl_Api.G_EXCEPTION_ERROR;
1043 END IF;
1044 CLOSE fnd_lookups_csr;
1045
1046 --From the l_amount_out_tbl returned , the transaction line amount and header amount need to be updated back on the contract
1047 l_tclv_tbl := x_tclv_tbl;
1048 l_tcnv_rec := l_trxH_out_rec;
1049
1050 If l_tclv_tbl.COUNT > 0 then
1051 FOR i in l_tclv_tbl.FIRST..l_tclv_tbl.LAST LOOP
1052 l_amount_tbl.delete;
1053 If l_amount_out_tbl.COUNT > 0 then
1054 For k in l_amount_out_tbl.FIRST..l_amount_out_tbl.LAST LOOP
1055 IF l_tclv_tbl(i).id = l_amount_out_tbl(k).source_id THEN
1056 l_amount_tbl := l_amount_out_tbl(k).amount_tbl;
1057 l_tclv_tbl(i).currency_code := l_currency_code;
1058 IF l_amount_tbl.COUNT > 0 THEN
1059 FOR j in l_amount_tbl.FIRST..l_amount_tbl.LAST LOOP
1060 l_tclv_tbl(i).amount := nvl(l_tclv_tbl(i).amount,0) + l_amount_tbl(j);
1061 END LOOP; -- for j in
1062 END IF;-- If l_amount_tbl.COUNT
1063 END IF; ---- IF l_tclv_tbl(i).id
1064 END LOOP; -- For k in
1065 END IF; -- If l_amount_out_tbl.COUNT
1066 l_tcnv_rec.amount := nvl(l_tcnv_rec.amount,0) + l_tclv_tbl(i).amount;
1067 l_tcnv_rec.currency_code := l_currency_code;
1068 l_tcnv_rec.tsu_code := l_fnd_rec.lookup_code;
1069 END LOOP; -- For i in
1070 End If; -- If l_tclv_tbl.COUNT
1071
1072
1073 --Making the call to update the amounts on transaction header and line
1074 Okl_Trx_Contracts_Pub.update_trx_contracts
1075 (p_api_version => p_api_version
1076 ,p_init_msg_list => p_init_msg_list
1077 ,x_return_status => x_return_status
1078 ,x_msg_count => x_msg_count
1079 ,x_msg_data => x_msg_data
1080 ,p_tcnv_rec => l_tcnv_rec
1081 ,p_tclv_tbl => l_tclv_tbl
1082 ,x_tcnv_rec => x_tcnv_rec
1083 ,x_tclv_tbl => x_tclv_tbl );
1084
1085 IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
1086 RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
1087 ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
1088 RAISE Okl_Api.G_EXCEPTION_ERROR;
1089 END IF;
1090
1091 OKL_MULTIGAAP_ENGINE_PVT.CREATE_SEC_REP_TRX
1092 (p_api_version => p_api_version
1093 ,p_init_msg_list => p_init_msg_list
1094 ,x_return_status => x_return_status
1095 ,x_msg_count => x_msg_count
1096 ,x_msg_data => x_msg_data
1097 ,P_TCNV_REC => x_tcnv_rec
1098 ,P_TCLV_TBL => x_tclv_tbl
1099 ,p_ctxt_val_tbl => l_ctxt_tbl
1100 ,p_acc_gen_primary_key_tbl => l_acc_gen_primary_key_tbl);
1101
1102
1103 IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
1104 RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
1105 ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
1106 RAISE Okl_Api.G_EXCEPTION_ERROR;
1107 END IF;
1108 /*-------Bug# 5964482 : Commented code to update header and Lines with Amount--------------------
1109 --as new code has been incorporated above-----------------------------------------------------
1110 -- Check Status
1111 IF(x_return_status = Okl_Api.G_RET_STS_SUCCESS) THEN
1112
1113 l_trxH_in_rec.amount := 0;
1114 FOR i in 1..l_amount_tbl.COUNT
1115 LOOP
1116 l_trxH_in_rec.amount := l_trxH_in_rec.amount + l_amount_tbl(i);
1117 END LOOP;
1118 l_trxH_in_rec.currency_code := l_currency_code;
1119
1120 OPEN fnd_lookups_csr('OKL_TRANSACTION_STATUS', 'Processed');
1121 FETCH fnd_lookups_csr INTO l_fnd_rec;
1122 IF fnd_lookups_csr%NOTFOUND THEN
1123 Okl_Api.SET_MESSAGE(G_APP_NAME, G_INVALID_VALUE,G_COL_NAME_TOKEN,l_transaction_type);
1124 CLOSE fnd_lookups_csr;
1125 RAISE Okl_Api.G_EXCEPTION_ERROR;
1126 END IF;
1127 CLOSE fnd_lookups_csr;
1128 l_trxH_in_rec.tsu_code := l_fnd_rec.lookup_code;
1129
1130 l_trxL_in_rec.amount := 0;
1131 FOR i in 1..l_amount_tbl.COUNT
1132 LOOP
1133 l_trxL_in_rec.amount := l_trxL_in_rec.amount + l_amount_tbl(i);
1134 END LOOP;
1135 l_trxL_in_rec.currency_code := l_currency_code;
1136
1137
1138 Else
1139
1140 OPEN fnd_lookups_csr('OKL_TRANSACTION_STATUS', 'Error');
1141 FETCH fnd_lookups_csr INTO l_fnd_rec;
1142 IF fnd_lookups_csr%NOTFOUND THEN
1143 Okl_Api.SET_MESSAGE(G_APP_NAME, G_INVALID_VALUE,G_COL_NAME_TOKEN,l_transaction_type);
1144 CLOSE fnd_lookups_csr;
1145 RAISE Okl_Api.G_EXCEPTION_ERROR;
1146 END IF;
1147 CLOSE fnd_lookups_csr;
1148 l_trxH_in_rec.tsu_code := l_fnd_rec.lookup_code;
1149 l_trxH_in_rec.amount := null;
1150
1151 l_trxL_in_rec.amount := null;
1152
1153 End If;
1154
1155 Okl_Trx_Contracts_Pub.update_trx_contracts(
1156 p_api_version => l_api_version
1157 ,p_init_msg_list => l_init_msg_list
1158 ,x_return_status => x_return_status
1159 ,x_msg_count => l_msg_count
1160 ,x_msg_data => l_msg_data
1161 ,p_tcnv_rec => l_trxH_in_rec
1162 ,x_tcnv_rec => l_trxH_out_rec);
1163
1164 Okl_Trx_Contracts_Pub.update_trx_cntrct_lines(
1165 p_api_version => l_api_version
1166 ,p_init_msg_list => l_init_msg_list
1167 ,x_return_status => x_return_status
1168 ,x_msg_count => l_msg_count
1169 ,x_msg_data => l_msg_data
1170 ,p_tclv_rec => l_trxL_in_rec
1171 ,x_tclv_rec => l_trxL_out_rec);
1172 -------Bug# 5964482 : End of comments ------------------------------------------------------*/
1173
1174 IF (p_draft_yn = OKL_API.G_TRUE) Then
1175 --Bug# 5964482: disable draft Accounting
1176 Null;
1177 /*-----------Commented Code-----------------------
1178 IF (x_return_status = Okl_Api.G_RET_STS_SUCCESS) THEN
1179
1180 okl_contract_status_pub.update_contract_status(
1181 l_api_version,
1182 p_init_msg_list,
1183 x_return_status,
1184 x_msg_count,
1185 x_msg_data,
1186 l_passStatus,
1187 p_chr_id );
1188
1189 --call to cascade status on to lines
1190 OKL_CONTRACT_STATUS_PUB.cascade_lease_status
1191 (p_api_version => p_api_version,
1192 p_init_msg_list => p_init_msg_list,
1193 x_return_status => x_return_status,
1194 x_msg_count => x_msg_count,
1195 x_msg_data => x_msg_data,
1196 p_chr_id => p_contract_id);
1197
1198 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
1199 RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
1200 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
1201 RAISE OKL_API.G_EXCEPTION_ERROR;
1202 END IF;
1203
1204 ELSE
1205 okl_contract_status_pub.update_contract_status(
1206 l_api_version,
1207 p_init_msg_list,
1208 x_return_status,
1209 x_msg_count,
1210 x_msg_data,
1211 l_failStatus,
1212 p_chr_id );
1213 IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
1214 RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
1215 ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
1216 RAISE Okl_Api.G_EXCEPTION_ERROR;
1217 END IF;
1218
1219 --call to cascade status on to lines
1220 OKL_CONTRACT_STATUS_PUB.cascade_lease_status
1221 (p_api_version => p_api_version,
1222 p_init_msg_list => p_init_msg_list,
1223 x_return_status => x_return_status,
1224 x_msg_count => x_msg_count,
1225 x_msg_data => x_msg_data,
1226 p_chr_id => p_contract_id);
1227
1228 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
1229 RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
1230 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
1231 RAISE OKL_API.G_EXCEPTION_ERROR;
1232 END IF;
1233
1234 END IF;
1235 ----------End of commented Code-----------------------*/
1236 --Bug# 5964482
1237 End If; --Bug# 5964482 Disable Draft Accounting
1238 End If; --Bug# 5964482 Disable Draft Accounting
1239
1240 OKL_API.END_ACTIVITY(x_msg_count => x_msg_count, x_msg_data => x_msg_data);
1241
1242 Exception
1243 when OKL_API.G_EXCEPTION_ERROR then
1244 x_return_status := OKL_API.HANDLE_EXCEPTIONS(
1245 p_api_name => l_api_name,
1246 p_pkg_name => g_pkg_name,
1247 p_exc_name => 'OKL_API.G_RET_STS_ERROR',
1248 x_msg_count => x_msg_count,
1249 x_msg_data => x_msg_data,
1250 p_api_type => g_api_type);
1251
1252 when OKL_API.G_EXCEPTION_UNEXPECTED_ERROR then
1253 x_return_status := OKL_API.HANDLE_EXCEPTIONS(
1254 p_api_name => l_api_name,
1255 p_pkg_name => g_pkg_name,
1256 p_exc_name => 'OKL_API.G_RET_STS_UNEXP_ERROR',
1257 x_msg_count => x_msg_count,
1258 x_msg_data => x_msg_data,
1259 p_api_type => g_api_type);
1260
1261 when OTHERS then
1262 x_return_status := OKL_API.HANDLE_EXCEPTIONS(
1263 p_api_name => l_api_name,
1264 p_pkg_name => g_pkg_name,
1265 p_exc_name => 'OTHERS',
1266 x_msg_count => x_msg_count,
1267 x_msg_data => x_msg_data,
1268 p_api_type => g_api_type);
1269
1270
1271 END generate_journal_entries;
1272
1273 Procedure generate_journal_entries(
1274 p_api_version IN NUMBER,
1275 p_init_msg_list IN VARCHAR2 DEFAULT Okl_Api.G_FALSE,
1276 p_commit IN VARCHAR2 DEFAULT Okl_Api.G_FALSE,
1277 p_contract_id IN NUMBER,
1278 p_transaction_type IN VARCHAR2,
1279 p_transaction_date IN DATE,
1280 p_draft_yn IN VARCHAR2 DEFAULT Okl_Api.G_TRUE,
1281 p_memo_yn IN VARCHAR2 DEFAULT Okl_Api.G_FALSE,
1282 x_return_status OUT NOCOPY VARCHAR2,
1283 x_msg_count OUT NOCOPY NUMBER,
1284 x_msg_data OUT NOCOPY VARCHAR2) IS
1285
1286 l_trxH_out_rec Okl_Trx_Contracts_Pvt.tcnv_rec_type;
1287
1288 Begin
1289
1290 generate_journal_entries(
1291 p_api_version => p_api_version,
1292 p_init_msg_list => p_init_msg_list,
1293 p_commit => p_commit,
1294 p_contract_id => p_contract_id,
1295 p_transaction_type => p_transaction_type,
1296 p_transaction_date => p_transaction_date,
1297 p_draft_yn => p_draft_yn,
1298 p_memo_yn => p_memo_yn,
1299 x_return_status => x_return_status,
1300 x_msg_count => x_msg_count,
1301 x_msg_data => x_msg_data,
1302 x_trxH_rec => l_trxH_out_rec
1303 );
1304
1305 End generate_journal_entries;
1306
1307 Procedure generate_journal_entries(
1308 p_api_version IN NUMBER,
1309 p_init_msg_list IN VARCHAR2 DEFAULT Okl_Api.G_FALSE,
1310 p_commit IN VARCHAR2 DEFAULT Okl_Api.G_FALSE,
1311 p_contract_id IN NUMBER,
1312 p_transaction_type IN VARCHAR2,
1313 p_draft_yn IN VARCHAR2 DEFAULT Okl_Api.G_TRUE,
1314 p_memo_yn IN VARCHAR2 DEFAULT Okl_Api.G_FALSE,
1315 x_return_status OUT NOCOPY VARCHAR2,
1316 x_msg_count OUT NOCOPY NUMBER,
1317 x_msg_data OUT NOCOPY VARCHAR2) IS
1318
1319 Begin
1320
1321 generate_journal_entries(
1322 p_api_version => p_api_version,
1323 p_init_msg_list => p_init_msg_list,
1324 p_commit => p_commit,
1325 p_contract_id => p_contract_id,
1326 p_transaction_type => p_transaction_type,
1327 p_transaction_date => NULL,
1328 p_draft_yn => p_draft_yn,
1329 p_memo_yn => p_memo_yn,
1330 x_return_status => x_return_status,
1331 x_msg_count => x_msg_count,
1332 x_msg_data => x_msg_data);
1333
1334 End generate_journal_entries;
1335
1336 End OKL_LA_JE_PVT;