[Home] [Help]
PACKAGE BODY: APPS.OKL_LA_JE_PVT
Source
1 PACKAGE BODY OKL_LA_JE_PVT as
2 /* $Header: OKLRJNLB.pls 120.10.12010000.4 2008/09/10 17:54:03 rkuttiya 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 BEGIN
308
309 --Bug# 5964482
310 IF (G_DEBUG_ENABLED = 'Y') THEN
311 G_IS_DEBUG_STATEMENT_ON := OKL_DEBUG_PUB.CHECK_LOG_ON(G_MODULE, FND_LOG.LEVEL_STATEMENT);
312 END IF;
313 --Bug# 5964482 End
314
315 x_return_status := Okl_Api.G_RET_STS_SUCCESS;
316 l_sysdate := SYSDATE;
317 l_sysdate_trunc := trunc(SYSDATE);
318 i := 0;
319
320
321 x_return_status := OKL_API.START_ACTIVITY(
322 p_api_name => l_api_name,
323 p_pkg_name => g_pkg_name,
324 p_init_msg_list => p_init_msg_list,
325 l_api_version => l_api_version,
326 p_api_version => p_api_version,
327 p_api_type => G_API_TYPE,
328 x_return_status => x_return_status);
329
330 -- check if activity started successfully
331 If (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) then
332 raise OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
333 ElSIF (x_return_status = OKL_API.G_RET_STS_ERROR) then
334 raise OKL_API.G_EXCEPTION_ERROR;
335 End If;
336
337 --Bug# 5964482 : Disable draft Accounting
338 If (p_draft_yn = OKL_API.G_TRUE) Then
339 Null; -- do not do anything
340 ELSE --do normal accounting
341
342 -- Get product_id
343 OPEN Product_csr(p_contract_id);
344 FETCH Product_csr INTO l_Product_rec;
345 IF Product_csr%NOTFOUND THEN
346 Okl_Api.SET_MESSAGE(G_APP_NAME, G_REQUIRED_VALUE,G_COL_NAME_TOKEN, 'Product');
347 CLOSE Product_csr;
348 RAISE Okl_Api.G_EXCEPTION_ERROR;
349 END IF;
350 CLOSE Product_csr;
351
352 If ( p_transaction_date IS NULL ) Then
353 l_transaction_date := l_Product_rec.start_date;
354 Else
355 l_transaction_date := p_transaction_date;
356 End If;
357
358 l_chr_curr_code := l_Product_rec.CURRENCY_CODE;
359 l_func_curr_code := OKC_CURRENCY_API.GET_OU_CURRENCY(l_Product_rec.authoring_org_id);
360
361 x_currency_conversion_rate := NULL;
362 x_currency_conversion_type := NULL;
363 x_currency_conversion_date := NULL;
364
365 If ( ( l_func_curr_code IS NOT NULL) AND
366 ( l_chr_curr_code <> l_func_curr_code ) ) Then
367
368 x_currency_conversion_type := l_Product_rec.currency_conversion_type;
369 x_currency_conversion_date := l_Product_rec.start_date;
370
371 If ( l_Product_rec.currency_conversion_type = 'User') Then
372 x_currency_conversion_rate := l_Product_rec.currency_conversion_rate;
373 x_currency_conversion_date := l_Product_rec.currency_conversion_date;
374 Else
375 x_currency_conversion_rate := okl_accounting_util.get_curr_con_rate(
376 p_from_curr_code => l_chr_curr_code,
377 p_to_curr_code => l_func_curr_code,
378 p_con_date => l_Product_rec.start_date,
379 p_con_type => l_Product_rec.currency_conversion_type);
380
381 End If;
382
383 End If;
384
385 IF ((p_draft_yn = OKL_API.G_TRUE) AND (l_Product_rec.contract_status <> 'BOOKED')) Then
386 /*--Bug# 5964482 Commenting the code as Draft Accounting is being disabled
387 okl_contract_status_pub.get_contract_status(l_api_version,
388 p_init_msg_list,
389 x_return_status,
390 x_msg_count,
391 x_msg_data,
392 l_isJrnlGenAllowed,
393 l_passStatus,
394 l_failStatus,
395 OKL_CONTRACT_STATUS_PUB.G_K_JOURNAL,
396 p_chr_id);
397
398
399 If ( l_isJrnlGenAllowed = FALSE ) then
400 x_return_status := OKL_API.G_RET_STS_ERROR;
401 okl_api.set_message(
402 p_app_name => G_APP_NAME,
403 p_msg_name => OKL_CONTRACT_STATUS_PUB.G_CANNOT_GENJRNL);
404 raise OKL_API.G_EXCEPTION_ERROR;
405 ElsIf (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) then
406 raise OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
407 ElSIF (x_return_status = OKL_API.G_RET_STS_ERROR) then
408 raise OKL_API.G_EXCEPTION_ERROR;
409 End If;
410 -----Bug# 5964482 End of comments - Draft Accounting Disabled*/
411 Null;
412
413 End If;
414
415 -- Validate passed parameters
416 IF ( p_contract_id = Okl_Api.G_MISS_NUM )
417 OR ( p_contract_id IS NULL ) THEN
418 Okl_Api.Set_Message(G_APP_NAME, G_REQUIRED_VALUE,G_COL_NAME_TOKEN, 'contract');
419 RAISE Okl_Api.G_EXCEPTION_ERROR;
420 END IF;
421
422 --Bug 5909373
423 /*
424 If ( is_release_contract( p_contract_id ) = 'Y' ) Then
425 l_transaction_type := 'Release';
426 End If;*/
427 --Bug 5909373
428
429 IF ( l_transaction_type = Okl_Api.G_MISS_CHAR )
430 OR ( l_transaction_type IS NULL ) THEN
431 Okl_Api.Set_Message(G_APP_NAME, G_REQUIRED_VALUE,G_COL_NAME_TOKEN, l_transaction_type);
432 RAISE Okl_Api.G_EXCEPTION_ERROR;
433 END IF;
434
435 -- set POST_TO_GL and MEMO_YN flag always to YES !!!!
436 l_memo_yn := OKL_API.G_MISS_CHAR;
437 IF (p_draft_yn = OKL_API.G_TRUE) THEN
438 --Bug# 5964482 : Disable Draft Accounting
439 --l_post_to_gl_yn := 'N';
440 --l_memo_yn := 'Y';
441 Null;
442 --Bug# 5964482 End
443 ELSE
444 l_post_to_gl_yn := 'Y';
445 END IF;
446
447 l_currency_code := l_Product_rec.currency_code;
448
449 -- Check Transaction_Type
450 OPEN Transaction_Type_csr(l_transaction_type);
451 FETCH Transaction_Type_csr INTO l_Trx_Type_rec;
452 IF Transaction_Type_csr%NOTFOUND THEN
453 Okl_Api.SET_MESSAGE(G_APP_NAME, G_INVALID_VALUE,G_COL_NAME_TOKEN, l_transaction_type);
454 CLOSE Transaction_Type_csr;
455 RAISE Okl_Api.G_EXCEPTION_ERROR;
456 END IF;
457 CLOSE Transaction_Type_csr;
458
459 OPEN fnd_lookups_csr('OKL_TCN_TYPE', l_transaction_type);
460 FETCH fnd_lookups_csr INTO l_fnd_rec;
461 IF fnd_lookups_csr%NOTFOUND THEN
462 CLOSE fnd_lookups_csr;
463 OPEN fnd_lookups_csr('OKL_TCN_TYPE', 'Miscellaneous');
464 FETCH fnd_lookups_csr INTO l_fnd_rec;
465 IF fnd_lookups_csr%NOTFOUND THEN
466 Okl_Api.SET_MESSAGE(G_APP_NAME, G_INVALID_VALUE,G_COL_NAME_TOKEN, l_transaction_type);
467 CLOSE fnd_lookups_csr;
468 RAISE Okl_Api.G_EXCEPTION_ERROR;
469 End If;
470 END IF;
471 CLOSE fnd_lookups_csr;
472
473 OPEN trx_csr(p_contract_id,l_fnd_rec.lookup_code);
474 FETCH trx_csr INTO l_trx_rec;
475 IF (l_fnd_rec.lookup_code = 'TRBK') THEN -- For Rebook, create a new trans always
476 l_has_trans := OKL_API.G_FALSE;
477 ELSIF (trx_csr%FOUND AND l_trx_rec.tsu_code = 'ENTERED') THEN -- Otherwise use existing transaction, if it is in Entered status
478 l_has_trans := OKL_API.G_TRUE;
479 ELSE
480 l_has_trans := OKL_API.G_FALSE; -- In all other cases, create a new trans
481 END IF;
482 CLOSE trx_csr;
483
484 l_trxH_in_rec.khr_id := p_contract_id;
485 l_trxH_in_rec.pdt_id := l_Product_rec.product_id;
486 l_trxH_in_rec.tcn_type := l_fnd_rec.lookup_code; --'BKG'/'SYND'/'TRBK';
487 l_trxH_in_rec.currency_code := l_currency_code;
488 l_trxH_in_rec.try_id := l_Trx_Type_rec.trx_try_id;
489
490 --Added by dpsingh for LE Uptake
491 l_legal_entity_id := OKL_LEGAL_ENTITY_UTIL.get_khr_le_id(p_contract_id) ;
492 IF l_legal_entity_id IS NOT NULL THEN
493 l_trxH_in_rec.legal_entity_id := l_legal_entity_id;
494 ELSE
495 -- get the contract number
496 OPEN contract_num_csr(p_contract_id);
497 FETCH contract_num_csr INTO l_cntrct_number;
498 CLOSE contract_num_csr;
499 Okl_Api.set_message(p_app_name => g_app_name,
500 p_msg_name => 'OKL_LE_NOT_EXIST_CNTRCT',
501 p_token1 => 'CONTRACT_NUMBER',
502 p_token1_value => l_cntrct_number);
503 RAISE OKL_API.G_EXCEPTION_ERROR;
504 END IF;
505 If ( p_draft_yn = OKL_API.G_TRUE ) Then
506 --Bug# 5964482 : Disable draft Accounting
507 Null;
508 --l_trxH_in_rec.description := 'Draft Journals - ' || l_transaction_type;
509 Else
510 l_trxH_in_rec.description := 'Journals - ' || l_transaction_type;
511 End If;
512
513 l_trxH_in_rec.currency_conversion_rate := x_currency_conversion_rate;
514 l_trxH_in_rec.currency_conversion_type := x_currency_conversion_type;
515 l_trxH_in_rec.currency_conversion_date := x_currency_conversion_date;
516
517 --Bug# 5964482 : code for l_trxL_in_rec not changed here
518 -- But, l_trxL_in_rec will not be used because of
519 -- changes for accounting CR.
520 l_trxL_in_rec.khr_id := p_contract_id;
521 l_trxL_in_rec.line_number := 1;
522 l_trxL_in_rec.currency_code := l_currency_code;
523 If ( p_draft_yn = OKL_API.G_TRUE ) Then
524 -- Bug# 5964482 : Disable draft accounting
525 Null;
526 --l_trxL_in_rec.description := 'Draft Journals - ' || l_transaction_type;
527 Else
528 l_trxL_in_rec.description := 'Journals - ' || l_transaction_type;
529 End If;
530
531 --Bug# 5964482
532 If (l_transaction_type = 'Rebook') then
533 l_tcl_type := 'Rebooking';
534 Else
535 l_tcl_type := l_transaction_type;
536 End If;
537 --Bug# 5964482
538
539 --OPEN fnd_lookups_csr('OKL_TCL_TYPE', l_transaction_type);
540 OPEN fnd_lookups_csr('OKL_TCL_TYPE', l_tcl_type);
541 FETCH fnd_lookups_csr INTO l_fnd_rec1;
542 IF fnd_lookups_csr%NOTFOUND THEN
543 l_trxL_in_rec.tcl_type := 'MAE';
544 Else
545 l_trxL_in_rec.tcl_type := l_fnd_rec1.lookup_code;
546 END IF;
547 CLOSE fnd_lookups_csr;
548
549 If ( l_has_trans = OKL_API.G_FALSE ) Then
550
551 If (UPPER(l_fnd_rec.lookup_code) = 'TRBK') THEN
552 l_trxH_in_rec.rbr_code := ''; -- lokup 'OKL_REBOOK_REASON'
553 l_trxH_in_rec.rpy_code := ''; -- lokup 'OKL_REBOOK_PROCESS_TYPE'
554 End If;
555
556 OPEN fnd_lookups_csr('OKL_TRANSACTION_STATUS', 'Submitted');
557 FETCH fnd_lookups_csr INTO l_fnd_rec;
558 IF fnd_lookups_csr%NOTFOUND THEN
559 Okl_Api.SET_MESSAGE(G_APP_NAME, G_INVALID_VALUE,G_COL_NAME_TOKEN,l_transaction_type);
560 CLOSE fnd_lookups_csr;
561 RAISE Okl_Api.G_EXCEPTION_ERROR;
562 END IF;
563 CLOSE fnd_lookups_csr;
564
565 l_trxH_in_rec.tsu_code := l_fnd_rec.lookup_code;
566
567 l_trxH_in_rec.date_transaction_occurred := l_transaction_date;
568 l_trxH_in_rec.description := l_fnd_rec.description;
569 --Bug# 5964482 : Accounting engine CR for uniform accounting call
570 --Bug# 6073872: DFF attributes to be taken from okl_k_headers
571 l_trxH_in_rec.attribute_category := l_product_rec.khr_attribute_category;
572 l_trxH_in_rec.attribute1 := l_product_rec.khr_attribute1;
573 l_trxH_in_rec.attribute2 := l_product_rec.khr_attribute2;
574 l_trxH_in_rec.attribute3 := l_product_rec.khr_attribute3;
575 l_trxH_in_rec.attribute4 := l_product_rec.khr_attribute4;
576 l_trxH_in_rec.attribute5 := l_product_rec.khr_attribute5;
577 l_trxH_in_rec.attribute6 := l_product_rec.khr_attribute6;
578 l_trxH_in_rec.attribute7 := l_product_rec.khr_attribute7;
579 l_trxH_in_rec.attribute8 := l_product_rec.khr_attribute8;
580 l_trxH_in_rec.attribute9 := l_product_rec.khr_attribute9;
581 l_trxH_in_rec.attribute10 := l_product_rec.khr_attribute10;
582 l_trxH_in_rec.attribute11 := l_product_rec.khr_attribute11;
583 l_trxH_in_rec.attribute12 := l_product_rec.khr_attribute12;
584 l_trxH_in_rec.attribute13 := l_product_rec.khr_attribute13;
585 l_trxH_in_rec.attribute14 := l_product_rec.khr_attribute14;
586 l_trxH_in_rec.attribute15 := l_product_rec.khr_attribute15;
587 --Bug# 5964482 : End
588
589 -- Create Transaction Header, Lines
590 Okl_Trx_Contracts_Pub.create_trx_contracts(
591 p_api_version => l_api_version
592 ,p_init_msg_list => l_init_msg_list
593 ,x_return_status => x_return_status
594 ,x_msg_count => l_msg_count
595 ,x_msg_data => l_msg_data
596 ,p_tcnv_rec => l_trxH_in_rec
597 ,x_tcnv_rec => l_trxH_out_rec);
598
599 IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
600 RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
601 ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
602 RAISE Okl_Api.G_EXCEPTION_ERROR;
603 END IF;
604
605 IF ((l_trxH_out_rec.id = OKL_API.G_MISS_NUM) OR
606 (l_trxH_out_rec.id IS NULL) ) THEN
607 OKL_API.set_message(G_APP_NAME, G_REQUIRED_VALUE,G_COL_NAME_TOKEN,'TRANSACTION_ID');
608 RAISE OKL_API.G_EXCEPTION_ERROR;
609 END IF;
610
611 -- populate the output transaction record
612 x_trxH_rec := l_trxH_out_rec;
613
614 l_fnd_rec := null;
615
616 /*--------------Bug# 5964482 : Commenting creation of transaction lines
617 -- as transaction lines will be created based on unified accounting call
618 -- Create Transaction Line
619 --l_trxL_in_rec.tcn_id := l_trxH_out_rec.id;
620
621 -- Create Transaction Header, Lines
622 --Okl_Trx_Contracts_Pub.create_trx_cntrct_lines(
623 --p_api_version => l_api_version
624 --,p_init_msg_list => l_init_msg_list
625 --,x_return_status => x_return_status
626 --,x_msg_count => l_msg_count
627 --,x_msg_data => l_msg_data
628 --,p_tclv_rec => l_trxL_in_rec
629 --,x_tclv_rec => l_trxL_out_rec);
630
631 --IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
632 -- RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
633 --ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
634 -- RAISE Okl_Api.G_EXCEPTION_ERROR;
635 --END IF;
636 --IF ((l_trxL_out_rec.id = OKL_API.G_MISS_NUM) OR
637 -- (l_trxL_out_rec.id IS NULL) ) THEN
638 -- OKL_API.set_message(G_APP_NAME, G_REQUIRED_VALUE,G_COL_NAME_TOKEN,'TRANSACTION_ID');
639 -- RAISE OKL_API.G_EXCEPTION_ERROR;
640 --END IF;
641
642 --l_dist_info_rec.SOURCE_ID := l_trxL_out_rec.id;
643 --l_dist_info_rec.ACCOUNTING_DATE := l_trxH_out_rec.date_transaction_occurred;
644 -------------Bug# 5964482 - End of Comments -------------------------*/
645 ELSE
646
647 ------------------
648 --Bug# : 3153003
649 -----------------
650 --if transaction exists change the date transaction occured
651 l_upd_trxH_rec.id := l_trx_rec.HeaderTransID;
652 l_upd_trxH_rec.date_transaction_occurred := l_transaction_date;
653 Okl_Trx_Contracts_Pub.update_trx_contracts(
654 p_api_version => l_api_version
655 ,p_init_msg_list => l_init_msg_list
656 ,x_return_status => x_return_status
657 ,x_msg_count => l_msg_count
658 ,x_msg_data => l_msg_data
659 ,p_tcnv_rec => l_upd_trxH_rec
660 ,x_tcnv_rec => lx_upd_trxH_rec);
661
662 IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
663 RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
664 ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
665 RAISE Okl_Api.G_EXCEPTION_ERROR;
666 END IF;
667
668 IF ((lx_upd_trxH_rec.id = OKL_API.G_MISS_NUM) OR
669 (lx_upd_trxH_rec.id IS NULL) ) THEN
670 OKL_API.set_message(G_APP_NAME, G_REQUIRED_VALUE,G_COL_NAME_TOKEN,'TRANSACTION_ID');
671 RAISE OKL_API.G_EXCEPTION_ERROR;
672 END IF;
673
674 -- populate the output transaction record
675 x_trxH_rec := lx_upd_trxH_rec;
676 l_trxH_out_rec := lx_upd_trxH_rec;
677
678
679 --Bug# 5964482 : Coomented for Accounting engine CR
680 --l_dist_info_rec.SOURCE_ID := l_trx_rec.LineTransId;
681 --l_dist_info_rec.ACCOUNTING_DATE := l_trx_rec.date_transaction_occurred;
682 --l_dist_info_rec.ACCOUNTING_DATE := lx_upd_trxH_rec.date_transaction_occurred;
683 --Bug# 5964482 : End of Comments
684
685 -----------------------
686 --Bug# : 3153003
687 -----------------------
688
689 ----------------------
690 --Bug# 5964482
691 -----------------------
692 --delete existing lines
693 -- Commented out code to delete_trx_cntrct_lines since draft journal entry is always FALSE
694 /*l_trxl_del_tbl.delete;
695 For l_trx_rec in trx_csr(p_contract_id,l_fnd_rec.lookup_code)
696 Loop
697 l_trxl_del_tbl(i).id := l_trx_rec.linetransid;
698 End Loop;
699
700 okl_trx_contracts_pub.delete_trx_cntrct_lines(
701 p_api_version => l_api_version,
702 p_init_msg_list => l_init_msg_list,
703 x_return_status => x_return_status,
704 x_msg_count => l_msg_count,
705 x_msg_data => l_msg_data,
706 p_tclv_tbl => l_trxl_del_tbl);
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 --End delete existing lines
714 ---------------------------
715 --End Bug# 5964482
716 ---------------------------*/
717
718 END IF;
719
720 l_tmpl_identify_rec.TRANSACTION_TYPE_ID := l_Trx_Type_rec.trx_try_id;
721 l_tmpl_identify_rec.PRODUCT_ID := l_Product_rec.product_id;
722 l_tmpl_identify_rec.memo_yn := l_memo_yn;
723
724 --Bug# 4622198 :For special accounting treatment
725 OKL_SECURITIZATION_PVT.Check_Khr_ia_associated(
726 p_api_version => p_api_version,
727 p_init_msg_list => p_init_msg_list,
728 x_return_status => x_return_status,
729 x_msg_count => x_msg_count,
730 x_msg_data => x_msg_data,
731 p_khr_id => p_chr_id,
732 p_scs_code => l_product_rec.scs_code,
733 p_trx_date => l_transaction_date,
734 x_fact_synd_code => l_fact_synd_code,
735 x_inv_acct_code => l_inv_acct_code
736 );
737
738 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
739 RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
740 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
741 RAISE OKL_API.G_EXCEPTION_ERROR;
742 END IF;
743
744 l_tmpl_identify_rec.factoring_synd_flag := l_fact_synd_code;
745 l_tmpl_identify_rec.investor_code := l_inv_acct_code;
746 --Bug# 4622198
747
748 -----------------
749 --Bug 5964482 : Accounting CR - get template information and build template line records
750 -------------------
751 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
752 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'Before Call to OKL_ACCOUNT_DIST_PUB.GET_TEMPLATE_INFO : '||x_return_status);
753 END IF;
754 --Call to get_template_info to determine the number of transaction lines to be created
755 Okl_Account_Dist_Pub.GET_TEMPLATE_INFO(p_api_version => p_api_version,
756 p_init_msg_list => p_init_msg_list,
757 x_return_status => x_return_status,
758 x_msg_count => x_msg_count,
759 x_msg_data => x_msg_data,
760 p_tmpl_identify_rec => l_tmpl_identify_rec,
761 x_template_tbl => l_template_tbl,
762 p_validity_date => l_trxH_out_rec.date_transaction_occurred);
763 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
764 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'After Call to OKL_ACCOUNT_DIST_PUB.GET_TEMPLATE_INFO : '||x_return_status);
765 END IF;
766 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
767 RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
768 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
769 RAISE OKL_API.G_EXCEPTION_ERROR;
770 END IF;
771 -- gboomina Bug 6151201 - Start
772 -- check whether templates present or not. If not throw error.
773 IF l_template_tbl.COUNT = 0 THEN
774 Okl_Api.set_message(p_app_name => g_app_name,
775 p_msg_name => 'OKL_LA_NO_ACCOUNTING_TMPLTS',
776 p_token1 => 'TRANSACTION_TYPE',
777 p_token1_value => l_transaction_type);
778 RAISE OKL_API.G_EXCEPTION_ERROR;
779 END IF;
780 -- gboomina Bug 6151201 - End
781
782 --Build the transaction line table of records
783 FOR i IN l_template_tbl.FIRST..l_template_tbl.LAST
784 LOOP
785 l_tclv_tbl(i).line_number := i;
786 l_tclv_tbl(i).khr_id := p_contract_id;
787 l_tclv_tbl(i).sty_id := l_template_tbl(i).sty_id;
788 l_tclv_tbl(i).tcl_type := l_trxl_in_rec.tcl_type;
789 If ( p_draft_yn = OKL_API.G_TRUE ) Then
790 --Bug# 5964482 : disbale draft accounting
791 Null;
792 --l_tclv_tbl(i).description := 'Draft Journals - ' || l_transaction_type;
793 Else
794 l_tclv_tbl(i).description := 'Journals - ' || l_transaction_type;
795 End If;
796 l_tclv_tbl(i).tcn_id := l_trxh_out_rec.id;
797 l_tclv_tbl(i).currency_code := l_currency_code;
798 END LOOP;
799
800
801 --Call to create transaction lines
802 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
803 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'Before OKL_TRX_CONTRACTS_PUB.create_trx_cntrct_lines :'|| x_return_status);
804 END IF;
805 Okl_Trx_Contracts_Pub.create_trx_cntrct_lines(
806 p_api_version => l_api_version
807 ,p_init_msg_list => l_init_msg_list
808 ,x_return_status => x_return_status
809 ,x_msg_count => l_msg_count
810 ,x_msg_data => l_msg_data
811 ,p_tclv_tbl => l_tclv_tbl
812 ,x_tclv_tbl => x_tclv_tbl);
813 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
814 OKL_DEBUG_PUB.LOG_DEBUG(FND_LOG.LEVEL_STATEMENT, G_MODULE,'Before OKL_TRX_CONTRACTS_PUB.create_trx_cntrct_lines :'|| x_return_status);
815 END IF;
816 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
817 RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
818 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
819 RAISE OKL_API.G_EXCEPTION_ERROR;
820 END IF;
821
822 /* Populating the tmpl_identify_tbl from the template_tbl returned by get_template_info*/
823
824 FOR i in l_template_tbl.FIRST.. l_template_tbl.LAST
825 LOOP
826 l_tmpl_identify_tbl(i).product_id := l_Product_rec.product_id;
827 l_tmpl_identify_tbl(i).transaction_type_id := l_Trx_Type_rec.trx_try_id;
828 l_tmpl_identify_tbl(i).stream_type_id := l_template_tbl(i).sty_id;
829 l_tmpl_identify_tbl(i).advance_arrears := l_template_tbl(i).advance_arrears;
830 l_tmpl_identify_tbl(i).prior_year_yn := l_template_tbl(i).prior_year_yn;
831 l_tmpl_identify_tbl(i).memo_yn := l_template_tbl(i).memo_yn;
832 l_tmpl_identify_tbl(i).factoring_synd_flag := l_template_tbl(i).factoring_synd_flag;
833 l_tmpl_identify_tbl(i).investor_code := l_template_tbl(i).inv_code;
834 l_tmpl_identify_tbl(i).SYNDICATION_CODE := l_template_tbl(i).syt_code;
835 l_tmpl_identify_tbl(i).FACTORING_CODE := l_template_tbl(i).fac_code;
836 END LOOP;
837 --Bug# 5964482 END
838
839 /* -- Bug# 5964482 - code commented
840 --l_dist_info_rec.SOURCE_TABLE := 'OKL_TXL_CNTRCT_LNS';
841 --l_dist_info_rec.GL_REVERSAL_FLAG := 'N';
842 --l_dist_info_rec.POST_TO_GL := l_post_to_gl_yn;
843 --l_dist_info_rec.CONTRACT_ID := p_contract_id;
844
845 --l_dist_info_rec.currency_conversion_rate := x_currency_conversion_rate;
846 --l_dist_info_rec.currency_conversion_type := x_currency_conversion_type;
847 --l_dist_info_rec.currency_conversion_date := x_currency_conversion_date;
848 --l_dist_info_rec.currency_code := l_currency_code;
849 ----Bug# 5964482 - end of commented code */
850
851 l_acc_gen_primary_key_tbl(1).source_table := 'FINANCIALS_SYSTEM_PARAMETERS';
852 OPEN fnd_pro_csr;
853 FETCH fnd_pro_csr INTO fnd_pro_rec;
854 If ( fnd_pro_csr%NOTFOUND ) Then
855 l_acc_gen_primary_key_tbl(1).primary_key_column := '';
856 Else
857 l_acc_gen_primary_key_tbl(1).primary_key_column := fnd_pro_rec.l_fnd_profile;
858 End If;
859 CLOSE fnd_pro_csr;
860
861 l_acc_gen_primary_key_tbl(2).source_table := 'AR_SITE_USES_V';
862 OPEN custBillTo_csr(p_contract_id);
863 FETCH custBillTo_csr INTO l_custBillTo_rec;
864 CLOSE custBillTo_csr;
865 l_acc_gen_primary_key_tbl(2).primary_key_column := l_custBillTo_rec.cust_acct_site_id;
866
867 l_acc_gen_primary_key_tbl(3).source_table := 'RA_CUST_TRX_TYPES';
868 OPEN ra_cust_csr;
869 FETCH ra_cust_csr INTO ra_cust_rec;
870 If ( ra_cust_csr%NOTFOUND ) Then
871 l_acc_gen_primary_key_tbl(3).primary_key_column := '';
872 Else
873 l_acc_gen_primary_key_tbl(3).primary_key_column := TO_CHAR(ra_cust_rec.l_cust_trx_type_id);
874 End If;
875 CLOSE ra_cust_csr;
876
877 l_acc_gen_primary_key_tbl(4).source_table := 'JTF_RS_SALESREPS_MO_V';
878 OPEN salesP_csr(p_contract_id);
879 FETCH salesP_csr INTO l_salesP_rec;
880 CLOSE salesP_csr;
881 l_acc_gen_primary_key_tbl(4).primary_key_column := l_salesP_rec.id;
882
883
884 --Bug# 5964482 : Accounting engine CR
885 /* Populating the dist_info_Tbl */
886 FOR i in x_tclv_tbl.FIRST..x_tclv_tbl.LAST
887 LOOP
888 --Assigning the account generator table
889 l_acc_gen_tbl(i).acc_gen_key_tbl := l_acc_gen_primary_key_tbl;
890 l_acc_gen_tbl(i).source_id := x_tclv_tbl(i).id;
891
892 IF (l_ctxt_val_tbl.COUNT > 0) THEN
893 l_ctxt_tbl(i).ctxt_val_tbl := l_ctxt_val_tbl;
894 l_ctxt_tbl(i).source_id := x_tclv_tbl(i).id;
895 END IF;
896
897 l_dist_info_tbl(i).SOURCE_ID := x_tclv_tbl(i).id;
898 l_dist_info_tbl(i).SOURCE_TABLE := 'OKL_TXL_CNTRCT_LNS';
899 l_dist_info_tbl(i).GL_REVERSAL_FLAG := 'N';
900 l_dist_info_tbl(i).POST_TO_GL := l_post_to_gl_yn;
901 l_dist_info_tbl(i).CONTRACT_ID := p_contract_id;
902
903 l_dist_info_tbl(i).currency_conversion_rate := x_currency_conversion_rate;
904 l_dist_info_tbl(i).currency_conversion_type := x_currency_conversion_type;
905 l_dist_info_tbl(i).currency_conversion_date := x_currency_conversion_date;
906 l_dist_info_tbl(i).currency_code := l_currency_code;
907 l_dist_info_tbl(i).ACCOUNTING_DATE := l_trxh_out_rec.date_transaction_occurred;
908 END LOOP;
909
910 --Assigning transaction header id from the transaction header record created
911 l_tcn_id := l_trxH_out_rec.id;
912
913
914 /* Making the new single accounting engine call*/
915
916 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
917 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);
918 END IF;
919 Okl_Account_Dist_Pvt.CREATE_ACCOUNTING_DIST(
920 p_api_version => l_api_version,
921 p_init_msg_list => p_init_msg_list,
922 x_return_status => x_return_status,
923 x_msg_count => x_msg_count,
924 x_msg_data => x_msg_data,
925 p_tmpl_identify_tbl => l_tmpl_identify_tbl,
926 p_dist_info_tbl => l_dist_info_tbl,
927 p_ctxt_val_tbl => l_ctxt_tbl,
928 p_acc_gen_primary_key_tbl => l_acc_gen_tbl,
929 x_template_tbl => l_template_out_tbl,
930 x_amount_tbl => l_amount_out_tbl,
931 p_trx_header_id => l_tcn_id);
932
933 IF (G_IS_DEBUG_STATEMENT_ON = TRUE) THEN
934 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);
935 END IF;
936
937 IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
938 RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
939 ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
940 RAISE Okl_Api.G_EXCEPTION_ERROR;
941 END IF;
942
943 /* --Bug# 5964482 : Code commented
944 --If ( l_has_trans = OKL_API.G_TRUE ) Then
945 -- l_trxH_in_rec.id := l_trx_rec.HeaderTransId;
946 --Else
947 -- l_trxH_in_rec.id := l_trxH_out_rec.id;
948 --End If;
949
950 --l_trxL_in_rec.id := l_dist_info_rec.source_id;
951 ----Bug# 5964482 : End of Comments */
952
953 OPEN fnd_lookups_csr('OKL_TRANSACTION_STATUS', 'Processed');
954 FETCH fnd_lookups_csr INTO l_fnd_rec;
955 IF fnd_lookups_csr%NOTFOUND THEN
956 Okl_Api.SET_MESSAGE(G_APP_NAME, G_INVALID_VALUE,G_COL_NAME_TOKEN,l_transaction_type);
957 CLOSE fnd_lookups_csr;
958 RAISE Okl_Api.G_EXCEPTION_ERROR;
959 END IF;
960 CLOSE fnd_lookups_csr;
961
962 --From the l_amount_out_tbl returned , the transaction line amount and header amount need to be updated back on the contract
963 l_tclv_tbl := x_tclv_tbl;
964 l_tcnv_rec := l_trxH_out_rec;
965
966 If l_tclv_tbl.COUNT > 0 then
967 FOR i in l_tclv_tbl.FIRST..l_tclv_tbl.LAST LOOP
968 l_amount_tbl.delete;
969 If l_amount_out_tbl.COUNT > 0 then
970 For k in l_amount_out_tbl.FIRST..l_amount_out_tbl.LAST LOOP
971 IF l_tclv_tbl(i).id = l_amount_out_tbl(k).source_id THEN
972 l_amount_tbl := l_amount_out_tbl(k).amount_tbl;
973 l_tclv_tbl(i).currency_code := l_currency_code;
974 IF l_amount_tbl.COUNT > 0 THEN
975 FOR j in l_amount_tbl.FIRST..l_amount_tbl.LAST LOOP
976 l_tclv_tbl(i).amount := nvl(l_tclv_tbl(i).amount,0) + l_amount_tbl(j);
977 END LOOP; -- for j in
978 END IF;-- If l_amount_tbl.COUNT
979 END IF; ---- IF l_tclv_tbl(i).id
980 END LOOP; -- For k in
981 END IF; -- If l_amount_out_tbl.COUNT
982 l_tcnv_rec.amount := nvl(l_tcnv_rec.amount,0) + l_tclv_tbl(i).amount;
983 l_tcnv_rec.currency_code := l_currency_code;
984 l_tcnv_rec.tsu_code := l_fnd_rec.lookup_code;
985 END LOOP; -- For i in
986 End If; -- If l_tclv_tbl.COUNT
987
988
989 --Making the call to update the amounts on transaction header and line
990 Okl_Trx_Contracts_Pub.update_trx_contracts
991 (p_api_version => p_api_version
992 ,p_init_msg_list => p_init_msg_list
993 ,x_return_status => x_return_status
994 ,x_msg_count => x_msg_count
995 ,x_msg_data => x_msg_data
996 ,p_tcnv_rec => l_tcnv_rec
997 ,p_tclv_tbl => l_tclv_tbl
998 ,x_tcnv_rec => x_tcnv_rec
999 ,x_tclv_tbl => x_tclv_tbl );
1000
1001 IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
1002 RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
1003 ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
1004 RAISE Okl_Api.G_EXCEPTION_ERROR;
1005 END IF;
1006
1007 OKL_MULTIGAAP_ENGINE_PVT.CREATE_SEC_REP_TRX
1008 (p_api_version => p_api_version
1009 ,p_init_msg_list => p_init_msg_list
1010 ,x_return_status => x_return_status
1011 ,x_msg_count => x_msg_count
1012 ,x_msg_data => x_msg_data
1013 ,P_TCNV_REC => x_tcnv_rec
1014 ,P_TCLV_TBL => x_tclv_tbl
1015 ,p_ctxt_val_tbl => l_ctxt_tbl
1016 ,p_acc_gen_primary_key_tbl => l_acc_gen_primary_key_tbl);
1017
1018
1019 IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
1020 RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
1021 ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
1022 RAISE Okl_Api.G_EXCEPTION_ERROR;
1023 END IF;
1024 /*-------Bug# 5964482 : Commented code to update header and Lines with Amount--------------------
1025 --as new code has been incorporated above-----------------------------------------------------
1026 -- Check Status
1027 IF(x_return_status = Okl_Api.G_RET_STS_SUCCESS) THEN
1028
1029 l_trxH_in_rec.amount := 0;
1030 FOR i in 1..l_amount_tbl.COUNT
1031 LOOP
1032 l_trxH_in_rec.amount := l_trxH_in_rec.amount + l_amount_tbl(i);
1033 END LOOP;
1034 l_trxH_in_rec.currency_code := l_currency_code;
1035
1036 OPEN fnd_lookups_csr('OKL_TRANSACTION_STATUS', 'Processed');
1037 FETCH fnd_lookups_csr INTO l_fnd_rec;
1038 IF fnd_lookups_csr%NOTFOUND THEN
1039 Okl_Api.SET_MESSAGE(G_APP_NAME, G_INVALID_VALUE,G_COL_NAME_TOKEN,l_transaction_type);
1040 CLOSE fnd_lookups_csr;
1041 RAISE Okl_Api.G_EXCEPTION_ERROR;
1042 END IF;
1043 CLOSE fnd_lookups_csr;
1044 l_trxH_in_rec.tsu_code := l_fnd_rec.lookup_code;
1045
1046 l_trxL_in_rec.amount := 0;
1047 FOR i in 1..l_amount_tbl.COUNT
1048 LOOP
1049 l_trxL_in_rec.amount := l_trxL_in_rec.amount + l_amount_tbl(i);
1050 END LOOP;
1051 l_trxL_in_rec.currency_code := l_currency_code;
1052
1053
1054 Else
1055
1056 OPEN fnd_lookups_csr('OKL_TRANSACTION_STATUS', 'Error');
1057 FETCH fnd_lookups_csr INTO l_fnd_rec;
1058 IF fnd_lookups_csr%NOTFOUND THEN
1059 Okl_Api.SET_MESSAGE(G_APP_NAME, G_INVALID_VALUE,G_COL_NAME_TOKEN,l_transaction_type);
1060 CLOSE fnd_lookups_csr;
1061 RAISE Okl_Api.G_EXCEPTION_ERROR;
1062 END IF;
1063 CLOSE fnd_lookups_csr;
1064 l_trxH_in_rec.tsu_code := l_fnd_rec.lookup_code;
1065 l_trxH_in_rec.amount := null;
1066
1067 l_trxL_in_rec.amount := null;
1068
1069 End If;
1070
1071 Okl_Trx_Contracts_Pub.update_trx_contracts(
1072 p_api_version => l_api_version
1073 ,p_init_msg_list => l_init_msg_list
1074 ,x_return_status => x_return_status
1075 ,x_msg_count => l_msg_count
1076 ,x_msg_data => l_msg_data
1077 ,p_tcnv_rec => l_trxH_in_rec
1078 ,x_tcnv_rec => l_trxH_out_rec);
1079
1080 Okl_Trx_Contracts_Pub.update_trx_cntrct_lines(
1081 p_api_version => l_api_version
1082 ,p_init_msg_list => l_init_msg_list
1083 ,x_return_status => x_return_status
1084 ,x_msg_count => l_msg_count
1085 ,x_msg_data => l_msg_data
1086 ,p_tclv_rec => l_trxL_in_rec
1087 ,x_tclv_rec => l_trxL_out_rec);
1088 -------Bug# 5964482 : End of comments ------------------------------------------------------*/
1089
1090 IF (p_draft_yn = OKL_API.G_TRUE) Then
1091 --Bug# 5964482: disable draft Accounting
1092 Null;
1093 /*-----------Commented Code-----------------------
1094 IF (x_return_status = Okl_Api.G_RET_STS_SUCCESS) THEN
1095
1096 okl_contract_status_pub.update_contract_status(
1097 l_api_version,
1098 p_init_msg_list,
1099 x_return_status,
1100 x_msg_count,
1101 x_msg_data,
1102 l_passStatus,
1103 p_chr_id );
1104
1105 --call to cascade status on to lines
1106 OKL_CONTRACT_STATUS_PUB.cascade_lease_status
1107 (p_api_version => p_api_version,
1108 p_init_msg_list => p_init_msg_list,
1109 x_return_status => x_return_status,
1110 x_msg_count => x_msg_count,
1111 x_msg_data => x_msg_data,
1112 p_chr_id => p_contract_id);
1113
1114 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
1115 RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
1116 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
1117 RAISE OKL_API.G_EXCEPTION_ERROR;
1118 END IF;
1119
1120 ELSE
1121 okl_contract_status_pub.update_contract_status(
1122 l_api_version,
1123 p_init_msg_list,
1124 x_return_status,
1125 x_msg_count,
1126 x_msg_data,
1127 l_failStatus,
1128 p_chr_id );
1129 IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
1130 RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
1131 ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
1132 RAISE Okl_Api.G_EXCEPTION_ERROR;
1133 END IF;
1134
1135 --call to cascade status on to lines
1136 OKL_CONTRACT_STATUS_PUB.cascade_lease_status
1137 (p_api_version => p_api_version,
1138 p_init_msg_list => p_init_msg_list,
1139 x_return_status => x_return_status,
1140 x_msg_count => x_msg_count,
1141 x_msg_data => x_msg_data,
1142 p_chr_id => p_contract_id);
1143
1144 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
1145 RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
1146 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
1147 RAISE OKL_API.G_EXCEPTION_ERROR;
1148 END IF;
1149
1150 END IF;
1151 ----------End of commented Code-----------------------*/
1152 --Bug# 5964482
1153 End If; --Bug# 5964482 Disable Draft Accounting
1154 End If; --Bug# 5964482 Disable Draft Accounting
1155
1156 OKL_API.END_ACTIVITY(x_msg_count => x_msg_count, x_msg_data => x_msg_data);
1157
1158 Exception
1159 when OKL_API.G_EXCEPTION_ERROR then
1160 x_return_status := OKL_API.HANDLE_EXCEPTIONS(
1161 p_api_name => l_api_name,
1162 p_pkg_name => g_pkg_name,
1163 p_exc_name => 'OKL_API.G_RET_STS_ERROR',
1164 x_msg_count => x_msg_count,
1165 x_msg_data => x_msg_data,
1166 p_api_type => g_api_type);
1167
1168 when OKL_API.G_EXCEPTION_UNEXPECTED_ERROR then
1169 x_return_status := OKL_API.HANDLE_EXCEPTIONS(
1170 p_api_name => l_api_name,
1171 p_pkg_name => g_pkg_name,
1172 p_exc_name => 'OKL_API.G_RET_STS_UNEXP_ERROR',
1173 x_msg_count => x_msg_count,
1174 x_msg_data => x_msg_data,
1175 p_api_type => g_api_type);
1176
1177 when OTHERS then
1178 x_return_status := OKL_API.HANDLE_EXCEPTIONS(
1179 p_api_name => l_api_name,
1180 p_pkg_name => g_pkg_name,
1181 p_exc_name => 'OTHERS',
1182 x_msg_count => x_msg_count,
1183 x_msg_data => x_msg_data,
1184 p_api_type => g_api_type);
1185
1186
1187 END generate_journal_entries;
1188
1189 Procedure generate_journal_entries(
1190 p_api_version IN NUMBER,
1191 p_init_msg_list IN VARCHAR2 DEFAULT Okl_Api.G_FALSE,
1192 p_commit IN VARCHAR2 DEFAULT Okl_Api.G_FALSE,
1193 p_contract_id IN NUMBER,
1194 p_transaction_type IN VARCHAR2,
1195 p_transaction_date IN DATE,
1196 p_draft_yn IN VARCHAR2 DEFAULT Okl_Api.G_TRUE,
1197 p_memo_yn IN VARCHAR2 DEFAULT Okl_Api.G_FALSE,
1198 x_return_status OUT NOCOPY VARCHAR2,
1199 x_msg_count OUT NOCOPY NUMBER,
1200 x_msg_data OUT NOCOPY VARCHAR2) IS
1201
1202 l_trxH_out_rec Okl_Trx_Contracts_Pvt.tcnv_rec_type;
1203
1204 Begin
1205
1206 generate_journal_entries(
1207 p_api_version => p_api_version,
1208 p_init_msg_list => p_init_msg_list,
1209 p_commit => p_commit,
1210 p_contract_id => p_contract_id,
1211 p_transaction_type => p_transaction_type,
1212 p_transaction_date => p_transaction_date,
1213 p_draft_yn => p_draft_yn,
1214 p_memo_yn => p_memo_yn,
1215 x_return_status => x_return_status,
1216 x_msg_count => x_msg_count,
1217 x_msg_data => x_msg_data,
1218 x_trxH_rec => l_trxH_out_rec
1219 );
1220
1221 End generate_journal_entries;
1222
1223 Procedure generate_journal_entries(
1224 p_api_version IN NUMBER,
1225 p_init_msg_list IN VARCHAR2 DEFAULT Okl_Api.G_FALSE,
1226 p_commit IN VARCHAR2 DEFAULT Okl_Api.G_FALSE,
1227 p_contract_id IN NUMBER,
1228 p_transaction_type IN VARCHAR2,
1229 p_draft_yn IN VARCHAR2 DEFAULT Okl_Api.G_TRUE,
1230 p_memo_yn IN VARCHAR2 DEFAULT Okl_Api.G_FALSE,
1231 x_return_status OUT NOCOPY VARCHAR2,
1232 x_msg_count OUT NOCOPY NUMBER,
1233 x_msg_data OUT NOCOPY VARCHAR2) IS
1234
1235 Begin
1236
1237 generate_journal_entries(
1238 p_api_version => p_api_version,
1239 p_init_msg_list => p_init_msg_list,
1240 p_commit => p_commit,
1241 p_contract_id => p_contract_id,
1242 p_transaction_type => p_transaction_type,
1243 p_transaction_date => NULL,
1244 p_draft_yn => p_draft_yn,
1245 p_memo_yn => p_memo_yn,
1246 x_return_status => x_return_status,
1247 x_msg_count => x_msg_count,
1248 x_msg_data => x_msg_data);
1249
1250 End generate_journal_entries;
1251
1252 End OKL_LA_JE_PVT;