DBA Data[Home] [Help]

PACKAGE BODY: APPS.OKL_ACC_CALL_PVT

Source


1 PACKAGE BODY Okl_Acc_Call_Pvt AS
2 /* $Header: OKLRACCB.pls 120.28.12010000.3 2008/10/01 23:33:51 rkuttiya ship $ */
3 -- Start of wraper code generated automatically by Debug code generator
4   L_MODULE VARCHAR2(40) := 'LEASE.RECEIVABLES.LOCKBOX';
5   L_DEBUG_ENABLED CONSTANT VARCHAR2(10) := OKL_DEBUG_PUB.CHECK_LOG_ENABLED;
6   L_LEVEL_PROCEDURE NUMBER;
7   IS_DEBUG_PROCEDURE_ON BOOLEAN;
8 -- End of wraper code generated automatically by Debug code generator
9 
10   ------------------------------------------------------------------
11   -- Function GET_TRX_TYPE to extract transaction type
12   ------------------------------------------------------------------
13 
14 
15   FUNCTION get_trx_type
16 	(p_name		VARCHAR2,
17 	p_language	VARCHAR2)
18 	RETURN		NUMBER IS
19 
20 	CURSOR c_trx_type (cp_name VARCHAR2, cp_language VARCHAR2) IS
21 		SELECT	id
22 		FROM	okl_trx_types_tl
23 		WHERE	name	= cp_name
24 		AND	LANGUAGE	= cp_language;
25 
26     -- Replace with following query
27 	CURSOR c_trx_id( p_sob_id   NUMBER, p_org_id   NUMBER ) IS
28 	   SELECT  ID1
29 	   FROM OKX_CUST_TRX_TYPES_V
30 	   WHERE name = 'Invoice-OKL' 			AND
31 	   		 set_of_books_id = p_sob_id 	AND
32 			 org_id			 = p_org_id;
33 
34 	l_trx_type	okl_trx_types_v.id%TYPE;
35 
36   BEGIN
37 
38 	l_trx_type := NULL;
39 
40 	OPEN	c_trx_type (p_name, p_language);
41 	FETCH	c_trx_type INTO l_trx_type;
42 	CLOSE	c_trx_type;
43 
44 	RETURN	l_trx_type;
45 
46   END get_trx_type;
47 
48 
49 PROCEDURE      Okl_Populate_Acc_Gen (
50 	p_contract_id		IN NUMBER,
51 	p_contract_line_id	IN NUMBER,
52 	x_acc_gen_tbl		OUT NOCOPY Okl_Account_Dist_Pub.acc_gen_primary_key,
53 	x_return_status	 OUT NOCOPY VARCHAR2) IS
54 
55 	l_acc_gen_tbl		Okl_Account_Dist_Pub.acc_gen_primary_key;
56 	l_return_status		VARCHAR2(1)	:= Okl_Api.G_RET_STS_SUCCESS;
57 	l_ind			NUMBER		:= 0;
58 	l_value			VARCHAR2(100)	:= NULL;
59 
60 
61 	-- Get Payables Financial Options
62 	CURSOR	l_fin_sys_parms_csr IS
63 		SELECT	fnd_profile.value ('ORG_ID')
64 		FROM	dual;
65 
66 	-- Get Receivables Transaction Type
67 	CURSOR	l_cust_trx_type_csr IS
68 		SELECT	ctt.cust_trx_type_id
69 		FROM	ra_cust_trx_types	ctt
70 		WHERE	ctt.name		= 'Invoice-OKL';
71 
72 	-- Get Customer Bill_To Address
73 	CURSOR	l_cust_acct_site_csr (cp_chr_id IN NUMBER) IS
74 		SELECT	khr.bill_to_site_use_id
75 		FROM    okc_k_headers_b khr
76 		WHERE	khr.id = cp_chr_id;
77 
78 	-- Get Contract Salesperson
79 	CURSOR	l_salesperson_csr (cp_chr_id IN NUMBER) IS
80 		SELECT	con.object1_id1
81 		FROM	okc_k_headers_b 	CHR,
82 			okc_contact_sources	cso,
83 			okc_k_party_roles_b	kpr,
84 			okc_contacts		con
85 		WHERE	CHR.id			= cp_chr_id
86 		AND	cso.cro_code		= 'SALESPERSON'
87 		AND	cso.rle_code		= 'LESSOR'
88 		AND	cso.buy_or_sell		= CHR.buy_or_sell
89 		AND	kpr.chr_id		= CHR.id
90 		AND	kpr.dnz_chr_id		= CHR.id
91 		AND	kpr.rle_code		= cso.rle_code
92 		AND	con.cpl_id		= kpr.id
93 		AND	con.dnz_chr_id		= CHR.id
94 		AND	con.cro_code		= cso.cro_code
95 		AND	con.jtot_object1_code	= cso.jtot_object_code;
96 
97 	-- Get Master Item from Financial Asset Line
98 	CURSOR	l_mtl_sys_item_csr (cp_chr_id IN NUMBER, cp_cle_id IN NUMBER) IS
99 		SELECT	--ite.object1_id1
100         RPAD (ite.object1_id1, 50, ' ') || khr.inv_organization_id
101 		FROM	okc_k_lines_b		kle_fa,
102 			okc_line_styles_b	lse_fa,
103 			okc_k_lines_b		kle_ml,
104 			okc_line_styles_b	lse_ml,
105 			okc_k_items		ite,
106             okl_k_headers_full_v khr
107 		WHERE	kle_fa.id		= cp_cle_id
108 		AND	kle_fa.chr_id		= cp_chr_id
109 		AND	lse_fa.id		= kle_fa.lse_id
110 		AND	lse_fa.lty_code		= 'FREE_FORM1'
111 		AND	kle_ml.cle_id		= kle_fa.id
112 		AND	lse_ml.id		= kle_ml.lse_id
113 		AND	lse_ml.lty_code		= 'ITEM'
114 		AND	ite.cle_id		= kle_ml.id
115         AND kle_fa.dnz_chr_id = khr.id
116 		AND	ite.jtot_object1_code	= 'OKX_SYSITEM';
117 
118 	-- Get Fixed Asset Info from Financial Asset Line
119 	CURSOR	l_fa_asset_line_csr (cp_chr_id IN NUMBER, cp_cle_id IN NUMBER) IS
120 		SELECT	RPAD (oal.depreciation_category, 50, ' ') || oal.corporate_book
121 		FROM	okx_asset_lines_v	oal
122 		WHERE	oal.parent_line_id	= cp_cle_id
123 		AND	oal.dnz_chr_id		= cp_chr_id;
124 
125 BEGIN
126 
127 	-- ******************************
128 	-- Get Payables Financial Options
129 	-- ******************************
130 
131         -- gboomina Bug 5265083 - commented - Start
132 	/*OPEN	l_fin_sys_parms_csr;
133 	FETCH	l_fin_sys_parms_csr INTO l_value;
134 	CLOSE	l_fin_sys_parms_csr;*/
135 
136         l_value := OKL_AM_UTIL_PVT.get_chr_org_id(p_contract_id);
137         -- gboomina Bug 5265083 - End
138 
139 	IF l_value IS NOT NULL THEN
140 		l_ind	:= l_ind + 1;
141 		l_acc_gen_tbl(l_ind).source_table	:= 'FINANCIALS_SYSTEM_PARAMETERS';
142 		l_acc_gen_tbl(l_ind).primary_key_column	:= l_value;
143 		l_value	:= NULL;
144 	END IF;
145 
146 	-- ********************************
147 	-- Get Receivables Transaction Type
148 	-- ********************************
149 
150 	OPEN	l_cust_trx_type_csr;
151 	FETCH	l_cust_trx_type_csr INTO l_value;
152 	CLOSE	l_cust_trx_type_csr;
153 
154 	IF l_value IS NOT NULL THEN
155 		l_ind	:= l_ind + 1;
156 		l_acc_gen_tbl(l_ind).source_table	:= 'RA_CUST_TRX_TYPES';
157 		l_acc_gen_tbl(l_ind).primary_key_column	:= l_value;
158 		l_value	:= NULL;
159 	END IF;
160 
161 	-- ****************************
162 	-- Get Customer Bill TO Address
163 	-- ****************************
164 
165 	IF NVL (p_contract_id, G_MISS_NUM) <> G_MISS_NUM THEN
166 
167 	    OPEN  l_cust_acct_site_csr (p_contract_id);
168 	    FETCH l_cust_acct_site_csr INTO l_value;
169 	    CLOSE l_cust_acct_site_csr;
170 
171 	    IF l_value IS NOT NULL THEN
172 		l_ind	:= l_ind + 1;
173 		l_acc_gen_tbl(l_ind).source_table	:= 'AR_SITE_USES_V';
174 		l_acc_gen_tbl(l_ind).primary_key_column	:= l_value;
175 		l_value	:= NULL;
176 	    END IF;
177 
178 	END IF;
179 
180 	-- ************************
181 	-- Get Contract Salesperson
182 	-- ************************
183 
184 	IF NVL (p_contract_id, G_MISS_NUM) <> G_MISS_NUM THEN
185 
186 	    OPEN  l_salesperson_csr (p_contract_id);
187 	    FETCH l_salesperson_csr INTO l_value;
188 	    CLOSE l_salesperson_csr;
189 
190 	    IF l_value IS NOT NULL THEN
191 		l_ind	:= l_ind + 1;
192 		l_acc_gen_tbl(l_ind).source_table	:= 'JTF_RS_SALESREPS_MO_V';
193 		l_acc_gen_tbl(l_ind).primary_key_column	:= l_value;
194 		l_value	:= NULL;
195 	    END IF;
196 
197 	END IF;
198 
199 	-- *****************************************
200 	-- Get Master Item from Financial Asset Line
201 	-- *****************************************
202 
203 	IF  NVL (p_contract_id,      G_MISS_NUM) <> G_MISS_NUM
204 	AND NVL (p_contract_line_id, G_MISS_NUM) <> G_MISS_NUM THEN
205 
206 	    OPEN  l_mtl_sys_item_csr (p_contract_id, p_contract_line_id);
207 	    FETCH l_mtl_sys_item_csr INTO l_value;
208 	    CLOSE l_mtl_sys_item_csr;
209 
210 	    IF l_value IS NOT NULL THEN
211 		l_ind	:= l_ind + 1;
212 		l_acc_gen_tbl(l_ind).source_table	:= 'MTL_SYSTEM_ITEMS_VL';
213 		l_acc_gen_tbl(l_ind).primary_key_column	:= l_value;
214 		l_value	:= NULL;
215 	    END IF;
216 
217 	END IF;
218 
219 	-- **********************************************
220 	-- Get Fixed Asset Info from Financial Asset Line
221 	-- **********************************************
222 
223 	IF  NVL (p_contract_id,      G_MISS_NUM) <> G_MISS_NUM
224 	AND NVL (p_contract_line_id, G_MISS_NUM) <> G_MISS_NUM THEN
225 
226 	    OPEN  l_fa_asset_line_csr (p_contract_id, p_contract_line_id);
227 	    FETCH l_fa_asset_line_csr INTO l_value;
228 	    CLOSE l_fa_asset_line_csr;
229 
230 	    IF l_value IS NOT NULL THEN
231 		l_ind	:= l_ind + 1;
232 		l_acc_gen_tbl(l_ind).source_table	:= 'FA_CATEGORY_BOOKS';
233 		l_acc_gen_tbl(l_ind).primary_key_column	:= l_value;
234 		l_value	:= NULL;
235 	    END IF;
236 
237 	END IF;
238 
239 	-- **************
240 	-- Return Results
241 	-- **************
242 
243 	x_return_status	:= l_return_status;
244 	x_acc_gen_tbl	:= l_acc_gen_tbl;
245 
246 EXCEPTION
247 
248 	WHEN OTHERS THEN
249 
250 		-- close open cursors
251                 -- gboomina Bug 5265083 - Start
252 		/* IF l_fin_sys_parms_csr%ISOPEN THEN
253 			CLOSE	l_fin_sys_parms_csr;
254 		END IF; */
255                 -- gboomina Bug 5265083 - End
256 		IF l_cust_trx_type_csr%ISOPEN THEN
257 			CLOSE	l_cust_trx_type_csr;
258 		END IF;
259 
260 		IF l_cust_acct_site_csr%ISOPEN THEN
261 			CLOSE	l_cust_acct_site_csr;
262 		END IF;
263 
264 		IF l_salesperson_csr%ISOPEN THEN
265 			CLOSE	l_salesperson_csr;
266 		END IF;
267 
268 		IF l_mtl_sys_item_csr%ISOPEN THEN
269 			CLOSE	l_mtl_sys_item_csr;
270 		END IF;
271 
272 		IF l_fa_asset_line_csr%ISOPEN THEN
273 			CLOSE	l_fa_asset_line_csr;
274 		END IF;
275 
276 		-- store SQL error message on message stack for caller
277 		Okl_Api.SET_MESSAGE (
278 			 p_app_name	=> G_APP_NAME
279 			,p_msg_name	=> G_UNEXPECTED_ERROR
280 			,p_token1	=> G_SQLCODE_TOKEN
281 			,p_token1_value	=> SQLCODE
282 			,p_token2	=> G_SQLERRM_TOKEN
283 			,p_token2_value	=> SQLERRM);
284 
285 		-- notify caller of an UNEXPECTED error
286 		x_return_status := Okl_Api.G_RET_STS_UNEXP_ERROR;
287 
288 END Okl_Populate_Acc_Gen;
289 
290 
291 PROCEDURE create_acc_trans(
292      p_api_version                  IN  NUMBER
293     ,p_init_msg_list                IN  VARCHAR2
294     ,x_return_status                OUT NOCOPY VARCHAR2
295     ,x_msg_count                    OUT NOCOPY NUMBER
296     ,x_msg_data                     OUT NOCOPY VARCHAR2
297   	,p_bpd_acc_rec  				IN  bpd_acc_rec_type
298 ) IS
299 
300 -- Local instance of AE rec/tbl Types
301 
302   	l_tmpl_identify_rec    		    Okl_Account_Dist_Pub.TMPL_IDENTIFY_REC_TYPE;
303   	l_dist_info_rec        			Okl_Account_Dist_Pub.dist_info_REC_TYPE;
304   	l_ctxt_val_tbl         			Okl_Account_Dist_Pub.CTXT_VAL_TBL_TYPE;
305   	l_acc_gen_primary_key_tbl  		Okl_Account_Dist_Pub.acc_gen_primary_key;
306   	l_template_tbl         			Okl_Account_Dist_Pub.AVLV_TBL_TYPE;
307   	l_amount_tbl           			Okl_Account_Dist_Pub.AMOUNT_TBL_TYPE;
308 
309 
310     p_taiv_rec						taiv_rec_type;
311     x_taiv_rec                 		taiv_rec_type;
312 
313     l_hd_id							NUMBER;
314     i                               NUMBER;
315     l_return_status                 VARCHAR2(1)   := Okc_Api.G_RET_STS_SUCCESS;
316     l_found							BOOLEAN;
317 
318     CURSOR l_acc_lines_csr(l_id IN NUMBER) IS
319 		   SELECT khr.pdt_id pdt_id,
320 		   		  LN.sty_id sty_id,
321 				  hd.try_id Try_id,
322 				  LN.Amount line_amount,
323 		   		  hd.date_invoiced,
324 				  hd.currency_code,
325 --Start code added by pgomes on 11/22/2002
326                   hd.currency_conversion_type      currency_conversion_type,
327                   hd.currency_conversion_rate      currency_conversion_rate,
328                   hd.currency_conversion_date      currency_conversion_date,
329 --End code added by pgomes on 11/22/2002
330 				  LN.id line_id,
331 				  'OKL_TXL_AR_INV_LNS_B' source_table,
332 				  hd.ID header_id,
333 				  hd.khr_id,
334                   -- Added for bug 4228207
335                   hd.qte_id,
336 				  LN.kle_id,
337 				  LN.til_id_reverses,
338                                   -- Bug# 4488818
339                                   LN.qte_line_id
340 		   FROM   okl_txl_ar_inv_lns_v LN,
341 		   		  okl_trx_ar_invoices_v hd,
342 				  okl_k_headers_v khr
343 		   WHERE  hd.id = LN.Tai_id	   		AND
344 		   		  khr.id = hd.khr_id			AND
345 		   		  LN.ID = l_id;
346 
347     CURSOR l_acc_dtls_csr(l_id IN NUMBER) IS
348 		   SELECT khr.pdt_id   pdt_id,
349 		   		  dtls.sty_id  sty_id,
350 				  hd.try_id    Try_id,
351 				  dtls.Amount  line_amount,
352 		   		  hd.date_invoiced date_invoiced,
353 				  hd.currency_code,
354 --Start code added by pgomes on 11/22/2002
355                   hd.currency_conversion_type      currency_conversion_type,
356                   hd.currency_conversion_rate      currency_conversion_rate,
357                   hd.currency_conversion_date      currency_conversion_date,
358 --End code added by pgomes on 11/22/2002
359 				  dtls.id line_id,
360 				  'OKL_TXD_AR_LN_DTLS_B' source_table,
361 				  hd.ID header_id,
362 				  hd.khr_id,
363                   -- Added for bug 4228207
364                   hd.qte_id,
365 				  LN.kle_id,
366                                   --Bug# 4488818
367 				  dtls.tld_id_reverses,
368                                   -- Bug# 4488818
369                                   LN.qte_line_id
370 		   FROM   okl_txl_ar_inv_lns_v LN,
371 		   		  okl_trx_ar_invoices_v hd,
372 				  okl_txd_ar_ln_dtls_v dtls,
373 				  okl_k_headers_v khr
374 		   WHERE hd.id = LN.Tai_id 	 	   		 AND
375 		       	 LN.ID = dtls.til_id_details	 AND
376 		   		 khr.ID = hd.KHR_ID				 AND
377 		   		 dtls.ID = l_id;
378 
379     -- Get currency attributes
380     CURSOR l_curr_csr (cp_currency_code VARCHAR2) IS
381     	   SELECT c.minimum_accountable_unit, c.precision
382     	   FROM fnd_currencies c
383     	   WHERE c.currency_code = cp_currency_code;
384 
385 	-- Get Currency Code
386 	CURSOR get_curr_code_csr ( p_sob_id NUMBER ) IS
387 		   SELECT currency_code
388 		   FROM GL_LEDGERS_PUBLIC_V
389 		   WHERE ledger_id = p_sob_id;
390 
391 
392     l_min_acct_unit 			    fnd_currencies.minimum_accountable_unit%TYPE;
393     l_precision     			    fnd_currencies.precision%TYPE;
394     l_acct_call_rec                 l_acc_dtls_csr%ROWTYPE;
395     l_rounded_amount	            okl_txl_ar_inv_lns_v.amount%type;
396 	l_sob_id						okl_ext_sell_invs_v.SET_OF_BOOKS_ID%TYPE;
397 	l_curr_code					    GL_LEDGERS_PUBLIC_V.currency_code%TYPE;
398 	l_trx_name						VARCHAR2(20);
399 
400     --Start code added by pgomes on 11/22/2002
401     SUBTYPE khr_id_type IS okl_k_headers_v.khr_id%type;
402     l_khr_id khr_id_type;
403     l_currency_code okl_ext_sell_invs_b.currency_code%type;
404     l_currency_conversion_type okl_ext_sell_invs_b.currency_conversion_type%type;
405     l_currency_conversion_rate okl_ext_sell_invs_b.currency_conversion_rate%type;
406     l_currency_conversion_date okl_ext_sell_invs_b.currency_conversion_date%type;
407 
408     --Get currency conversion attributes for a contract
409     CURSOR l_curr_conv_csr(cp_khr_id IN khr_id_type) IS
410     SELECT  currency_code
411            ,currency_conversion_type
412            ,currency_conversion_rate
413            ,currency_conversion_date
414     FROM    okl_k_headers_full_v
415     WHERE   id = cp_khr_id;
416 
417     --End code added by pgomes on 11/22/2002
418 
419 	--Start code changes for rev rec by fmiao on 10/05/2004
420     CURSOR l_get_accrual_csr (cp_sty_id IN NUMBER) IS
421 	       SELECT NVL(accrual_yn, '1')
422 	       FROM   okl_strm_type_b
423 	       WHERE  id = cp_sty_id;
424 
425     -- stmathew BUG#4547180/ 4573599 start
426 	CURSOR l_dstrs_count_csr (cp_source_id IN NUMBER, cp_source_table IN VARCHAR2) IS
427 	       SELECT count(*)
428 	       FROM   okl_trns_acc_dstrs
429 	       WHERE  source_id = cp_source_id
430 		   AND    source_table = cp_source_table;
431     -- stmathew BUG#4547180/ 4573599 end
432 
433 	l_rev_rec_basis okl_strm_type_b.accrual_yn%type;
434 	l_count NUMBER;
435 	--End code changes for rev rec by fmiao on 10/05/2004
436 
437     --Bug# 4488818: Changes for Upfront Tax Billing: Start
438     lp_txsv_rec  OKL_TAX_SOURCES_PUB.txsv_rec_type;
439     lx_txsv_rec  OKL_TAX_SOURCES_PUB.txsv_rec_type;
440 
441     lp_ttdv_tbl  OKL_TAX_TRX_DETAILS_PUB.ttdv_tbl_type;
442     lx_ttdv_tbl  OKL_TAX_TRX_DETAILS_PUB.ttdv_tbl_type;
443     --akrangan billing impacts coding start
444     /*
445     CURSOR upfront_tax_csr(p_khr_id IN NUMBER) IS
446     SELECT rl.rule_information1 asset_upfront_tax
447     FROM okc_rule_groups_b rg,
448          okc_rules_b rl
449     WHERE  rg.dnz_chr_id = p_khr_id
450     AND    rg.rgd_code = 'LAHDTX'
451     AND    rl.rgp_id = rg.id
452     AND    rl.dnz_chr_id = rg.dnz_chr_id
453     AND    rl.rule_information_category = 'LASTPR';
454 
455     upfront_tax_rec upfront_tax_csr%ROWTYPE;
456 
457     CURSOR tax_details_line1_csr(p_khr_id IN NUMBER,
458                                  p_trx_id IN NUMBER) IS
459     SELECT SUM(NVL(tax_amt,0)) tax_amt,
460            SUM(NVL(taxable_amt,0)) taxable_amt,
461            tax_rate_code
462     FROM (
463       SELECT NVL(tax_amt,0) tax_amt,
464              NVL(taxable_amt,0) taxable_amt,
465              tax_rate_code
466       FROM   okl_tax_sources txs,
467              okl_tax_trx_details txl,
468              okc_rule_groups_b rg,
469              okc_rules_b rl
470       WHERE  txs.khr_id = p_khr_id
471       AND    txs.trx_id = p_trx_id
472       AND    txs.tax_line_status_code = 'ACTIVE'
473       AND    txs.tax_call_type_code = 'UPFRONT_TAX'
474       AND    txl.txs_id = txs.id
475       AND    rg.dnz_chr_id = txs.khr_id
476       AND    rg.cle_id = txs.kle_id
477       AND    rg.rgd_code = 'LAASTX'
478       AND    rl.rgp_id = rg.id
479       AND    rl.dnz_chr_id = txs.khr_id
480       AND    rl.rule_information_category = 'LAASTX'
481       AND    NVL(rl.rule_information11,'BILLED') = 'BILLED'
482       UNION ALL
483       SELECT NVL(tax_amt,0) tax_amt,
484              NVL(taxable_amt,0) taxable_amt,
485              tax_rate_code
486       FROM   okl_tax_sources txs,
487              okl_tax_trx_details txl
488       WHERE  txs.khr_id = p_khr_id
489       AND    txs.kle_id IS NULL
490       AND    txs.trx_id = p_trx_id
491       AND    txs.tax_line_status_code = 'ACTIVE'
492       AND    txs.tax_call_type_code = 'UPFRONT_TAX'
493       AND    txl.txs_id = txs.id
494     )
495     GROUP BY tax_rate_code;
496 
497     CURSOR tax_details_line2_csr(p_khr_id IN NUMBER,
498                                  p_trx_id IN NUMBER) IS
499     SELECT SUM(NVL(tax_amt,0)) tax_amt,
500            SUM(NVL(taxable_amt,0)) taxable_amt,
501            tax_rate_code
502     FROM
503     (
504       SELECT NVL(tax_amt,0) tax_amt,
505              NVL(taxable_amt,0) taxable_amt,
506              tax_rate_code
507       FROM   okl_tax_sources txs,
508              okl_tax_trx_details txl,
509              okc_rule_groups_b rg,
510              okc_rules_b rl
511       WHERE  txs.khr_id = p_khr_id
512       AND    txs.trx_id = p_trx_id
513       AND    txs.tax_line_status_code = 'ACTIVE'
514       AND    txs.tax_call_type_code = 'UPFRONT_TAX'
515       AND    txl.txs_id = txs.id
516       AND    rg.dnz_chr_id = txs.khr_id
517       AND    rg.cle_id = txs.kle_id
518       AND    rg.rgd_code = 'LAASTX'
519       AND    rl.rgp_id = rg.id
520       AND    rl.dnz_chr_id = txs.khr_id
521       AND    rl.rule_information_category = 'LAASTX'
522       AND    rl.rule_information11 = 'BILLED'
523       UNION ALL
524       SELECT NVL(tax_amt,0) tax_amt,
525              NVL(taxable_amt,0) taxable_amt,
526              tax_rate_code
527       FROM   okl_tax_sources txs,
528              okl_tax_trx_details txl
529       WHERE  txs.khr_id = p_khr_id
530       AND    txs.kle_id IS NULL
531       AND    txs.trx_id = p_trx_id
532       AND    txs.tax_line_status_code = 'ACTIVE'
533       AND    txs.tax_call_type_code = 'UPFRONT_TAX'
534       AND    txl.txs_id = txs.id
535     )
536     GROUP BY tax_rate_code;
537 
538     l_ttdv_count NUMBER;
539     --Bug# 4488818: Changes for Upfront Tax Billing: End
540 
541     --Bug# 4488818: Changes for Rollover, Release Billing: Start
542 
543     CURSOR trx_type_csr(p_id NUMBER, p_language VARCHAR2) IS
544     SELECT name
545     FROM   okl_trx_types_tl
546     WHERE  id = p_id
547     AND    language = p_language;
548 
549     trx_type_rec trx_type_csr%ROWTYPE;
550     l_orig_try_id okl_trx_types_tl.id%TYPE;
551 
552     CURSOR orig_billing_csr(p_orig_qte_id        NUMBER,
553                             p_orig_quote_line_id NUMBER,
554                             p_orig_try_id        NUMBER)
555     IS
556     SELECT til.tai_id orig_tai_id,
557            til.id orig_til_id
558     FROM  okl_trx_ar_invoices_b tai,
559           okl_txl_ar_inv_lns_b til
560     WHERE tai.qte_id = p_orig_qte_id
561     AND   tai.try_id = p_orig_try_id
562     AND   til.tai_id = tai.id
563     AND   til.qte_line_id = p_orig_quote_line_id;
564 
565     CURSOR orig_txs_csr(p_orig_trx_id        NUMBER,
566                         p_orig_trx_line_id   NUMBER)
567     IS
568     SELECT txs.id,
569            txs.khr_id,
570            txs.kle_id,
571            txs.line_name,
572            txs.trx_id,
573            txs.trx_line_id,
574            txs.entity_code,
575            txs.event_class_code,
576            txs.trx_level_type,
577            txs.adjusted_doc_entity_code,
578            txs.adjusted_doc_event_class_code,
579            txs.adjusted_doc_trx_id,
580            txs.adjusted_doc_trx_line_id,
581            txs.adjusted_doc_trx_level_type,
582            txs.adjusted_doc_number,
583            txs.adjusted_doc_date,
584            txs.tax_call_type_code,
585            txs.sty_id,
586            txs.trx_business_category,
587            txs.tax_line_status_code,
588            txs.sel_id,
589 	   -- Modified by dcshanmu for eBTax - modification starts
590            txs.tax_reporting_flag,
591            txs.application_id,
592            txs.default_taxation_country,
593            txs.product_category,
594            txs.user_defined_fisc_class,
595            txs.line_intended_use,
596            txs.inventory_item_id,
597            txs.bill_to_cust_acct_id,
598            txs.org_id,
599            txs.legal_entity_id,
600            txs.line_amt,
601            txs.assessable_value,
602            txs.total_tax,
603            txs.product_type,
604            txs.product_fisc_classification,
605            txs.trx_date,
606            txs.provnl_tax_determination_date,
607            txs.try_id,
608            txs.ship_to_location_id,
609            txs.ship_from_location_id,
610            txs.trx_currency_code,
611            txs.currency_conversion_type,
612            txs.currency_conversion_rate,
613            txs.currency_conversion_date
614 	   -- Modified by dcshanmu for eBTax - modification end
615     FROM  okl_tax_sources txs
616     WHERE txs.trx_id = p_orig_trx_id
617     AND txs.trx_line_id =p_orig_trx_line_id;
618 
619     CURSOR orig_ttd_csr(p_orig_txs_id        NUMBER)
620     IS
621     SELECT  ttd.txs_id,
622             ttd.tax_determine_date,
623             ttd.tax_rate_id,
624             ttd.tax_rate_code,
625             ttd.taxable_amt,
626             ttd.tax_exemption_id,
627             ttd.tax_rate,
628             ttd.tax_amt,
629             ttd.billed_yn,
630 	    -- Modified by dcshanmu for eBTax - modification starts
631             ttd.tax_call_type_code,
632             ttd.tax_date,
633             ttd.line_amt,
634             ttd.internal_organization_id,
635             ttd.application_id,
636             ttd.entity_code,
637             ttd.event_class_code,
638             ttd.event_type_code,
639             ttd.trx_id,
640             ttd.trx_line_id,
641             ttd.trx_level_type,
642             ttd.trx_line_number,
643             ttd.tax_line_number,
644             ttd.tax_regime_id,
645             ttd.tax_regime_code,
646             ttd.tax_id,
647             ttd.tax,
648             ttd.tax_status_id,
649             ttd.tax_status_code,
650             ttd.tax_apportionment_line_number,
651             ttd.legal_entity_id,
652             ttd.trx_number,
653             ttd.trx_date,
654             ttd.tax_jurisdiction_id,
655             ttd.tax_jurisdiction_code,
656             ttd.tax_type_code,
657             ttd.tax_currency_code,
658             ttd.taxable_amt_tax_curr,
659             ttd.trx_currency_code,
660             ttd.minimum_accountable_unit,
661             ttd.precision,
662             ttd.currency_conversion_type,
663             ttd.currency_conversion_rate,
664             ttd.currency_conversion_date
665 	    -- Modified by dcshanmu for eBTax - modification end
666     FROM  okl_tax_trx_details ttd
667     WHERE ttd.txs_id = p_orig_txs_id;
668 
669     --Bug# 4488818: Changes for Rollover, Release Billing: End
670 
671     --Bug# 4488818: Changes for Credit Memo processing: Start
672 
673     CURSOR orig_til_csr(p_til_id NUMBER)
674     IS
675     SELECT til.amount,
676            til.tai_id
677     FROM   okl_txl_ar_inv_lns_b til
678     WHERE  til.id = p_til_id;
679 
680     CURSOR orig_tld_csr(p_tld_id NUMBER)
681     IS
682     SELECT tld.amount,
683            til.tai_id
684     FROM   okl_txd_ar_ln_dtls_b  tld,
685            okl_txl_ar_inv_lns_b  til
686     WHERE  tld.id = p_tld_id
687     AND    til.id = tld.til_id_details;
688 
689     orig_til_tld_rec orig_til_csr%ROWTYPE;
690 
691     l_cm_ratio       NUMBER;
692     l_taxable_amount NUMBER;
693     l_tax_amount     NUMBER;
694 
695     --Bug# 4488818: Changes for Credit Memo processing: End
696 
697     --Bug# 4622963: Changes for Mass Rebook: Start
698     CURSOR  l_chk_mass_rbk_csr (p_chr_id IN NUMBER,
699                                 p_trx_id IN NUMBER) IS
700     SELECT '!'
701     FROM   okl_trx_contracts ktrx
702     WHERE  ktrx.khr_id     = p_chr_id
703     AND    ktrx.id         = p_trx_id
704     AND    ktrx.tsu_code   = 'ENTERED'
705     AND    ktrx.rbr_code   IS NOT NULL
706     AND    ktrx.tcn_type   = 'TRBK'
707     AND    EXISTS (SELECT '1'
708                    FROM   okl_rbk_selected_contract rbk_khr
709                    WHERE  rbk_khr.khr_id = ktrx.khr_id
710                    AND    rbk_khr.status <> 'PROCESSED');
711 
712    l_mass_rbk_khr  VARCHAR2(1);
713 
714    CURSOR tax_details_line3_csr(p_khr_id IN NUMBER,
715                                 p_trx_id IN NUMBER) IS
716    SELECT NVL(tax_amt,0) tax_amt,
717           NVL(taxable_amt,0) taxable_amt,
718           tax_rate_code
719    FROM   okl_tax_sources txs,
720           okl_tax_trx_details txl
721    WHERE  txs.khr_id = p_khr_id
722    AND    txs.trx_id = p_trx_id
723    AND    txs.tax_line_status_code = 'ACTIVE'
724    AND    txs.tax_call_type_code = 'UPFRONT_TAX'
725    AND    txl.txs_id = txs.id
726    GROUP BY tax_rate_code;
727    --Bug# 4622963: Changes for Mass Rebook: End
728   --akrangan ebtax  billing imapcts ends
729   */
730 BEGIN
731 
732   IF p_bpd_acc_rec.source_table = 'OKL_TXD_AR_LN_DTLS_B' THEN
733     OPEN l_acc_dtls_csr(p_bpd_acc_rec.id);
734     FETCH l_acc_dtls_csr INTO l_acct_call_rec;
735       --l_found := l_acc_dtls_csr%FOUND;
736       --dbms_output.put_line('RECORD: '||l_acct_call_rec.line_id);
737     CLOSE l_acc_dtls_csr;
738   ELSE
739     OPEN l_acc_lines_csr(p_bpd_acc_rec.id);
740     FETCH l_acc_lines_csr INTO l_acct_call_rec;
741     --l_found := l_acc_lines_csr%FOUND;
742     --  dbms_output.put_line('RECORD: '||l_acct_call_rec.line_id);
743     CLOSE l_acc_lines_csr;
744   END IF;
745 
746   -- Bug# 4488818: Changes for Upfront Sales Tax
747   -- Tax Only invoices to be created for Upfront Sales Tax
748   -- are indentified by Zero Line Amounts
749   IF (NVL(l_acct_call_rec.line_amount,0) <> 0 ) THEN
750 
751   --Start code added by pgomes on 11/22/2002
752   --get contract currency parameters
753   l_khr_id := l_acct_call_rec.khr_id;
754 
755   l_currency_code := null;
756   l_currency_conversion_type := null;
757   l_currency_conversion_rate := null;
758   l_currency_conversion_date := null;
759 
760   FOR cur IN l_curr_conv_csr(l_khr_id) LOOP
761          l_currency_code := cur.currency_code;
762          l_currency_conversion_type := cur.currency_conversion_type;
763          l_currency_conversion_rate := cur.currency_conversion_rate;
764          l_currency_conversion_date := cur.currency_conversion_date;
765   END LOOP;
766   --End code added by pgomes on 11/22/2002
767 
768 
769   -- Populate Records for Accounting Call.
770   l_tmpl_identify_rec.PRODUCT_ID             := l_acct_call_rec.pdt_id;
771 
772   -- Changes for bug 3431579
773   IF l_acct_call_rec.line_amount > 0 THEN
774     l_tmpl_identify_rec.TRANSACTION_TYPE_ID := get_trx_type ('Billing', 'US');
775 	l_trx_name :=  'Billing';
776   ELSE
777     l_tmpl_identify_rec.TRANSACTION_TYPE_ID := get_trx_type ('Credit Memo', 'US');
778 	l_trx_name :=  'Credit Memo';
779   END IF;
780 
781   -- Changes for bug 4228207
782   IF l_acct_call_rec.qte_id IS NOT NULL THEN
783       IF l_acct_call_rec.try_id IS NOT NULL THEN
784         l_tmpl_identify_rec.TRANSACTION_TYPE_ID
785                                              := l_acct_call_rec.try_id;
786       END IF;
787   END IF;
788 
789   l_tmpl_identify_rec.STREAM_TYPE_ID         := l_acct_call_rec.sty_id;
790   l_tmpl_identify_rec.ADVANCE_ARREARS        := NULL;
791   l_tmpl_identify_rec.FACTORING_SYND_FLAG    := NULL;
792   l_tmpl_identify_rec.SYNDICATION_CODE       := NULL;
793   l_tmpl_identify_rec.FACTORING_CODE         := NULL;
794   l_tmpl_identify_rec.MEMO_YN                := 'N';
795 
796   -- Start Bug 4622198
797   Okl_Securitization_Pvt.check_khr_ia_associated(p_api_version    => p_api_version
798                                                 ,p_init_msg_list  => p_init_msg_list
799                                                 ,x_return_status  => x_return_status
800                                                 ,x_msg_count      => x_msg_count
801                                                 ,x_msg_data       => x_msg_data
802                                                 ,p_khr_id         => l_acct_call_rec.khr_id
803                                                 ,p_scs_code       => NULL
804                                                 ,p_trx_date       => l_acct_call_rec.date_invoiced
805                                                 ,x_fact_synd_code => l_tmpl_identify_rec.FACTORING_SYND_FLAG
806                                                 ,x_inv_acct_code  => l_tmpl_identify_rec.INVESTOR_CODE);
807   -- End Bug 4622198
808 
809   --Start code changes for rev rec by fmiao on 10/05/2004
810   OPEN l_get_accrual_csr (l_tmpl_identify_rec.STREAM_TYPE_ID);
811   FETCH l_get_accrual_csr INTO l_rev_rec_basis;
812   CLOSE l_get_accrual_csr;
813 
814   IF (l_rev_rec_basis = 'CASH_RECEIPT' ) THEN
815     -- bug5046450 Start rseela 03/29/2006
816     IF l_acct_call_rec.line_amount >= 0 THEN
817             l_tmpl_identify_rec.REV_REC_FLAG           := 'Y';
818     ELSE
819             l_tmpl_identify_rec.REV_REC_FLAG           := 'N';
820     END IF;
821     -- bug5046450 End rseela 03/29/2006
822   ELSE
823 	l_tmpl_identify_rec.REV_REC_FLAG           := 'N';
824   END IF;
825   --End code changes for rev rec by fmiao on 10/05/2004
826 
827   l_tmpl_identify_rec.PRIOR_YEAR_YN          := 'N';
828 
829   l_dist_info_rec.SOURCE_ID                  := l_acct_call_rec.line_id;
830   l_dist_info_rec.SOURCE_TABLE               := l_acct_call_rec.source_table;
831   l_dist_info_rec.ACCOUNTING_DATE            := l_acct_call_rec.date_invoiced;
832   l_dist_info_rec.GL_REVERSAL_FLAG           := 'N';
833   l_dist_info_rec.POST_TO_GL                 := 'N';
834 
835   -- *************************************
836   -- Get Set of Books and Currency_Code
837   -- *************************************
838   l_sob_id := NULL;
839   l_sob_id := Okl_Accounting_Util.GET_SET_OF_BOOKS_ID;
840 
841   l_curr_code := NULL;
842 
843   --Start code added by pgomes on 11/22/2002
844 
845   --Check for currency code
846   IF l_acct_call_rec.currency_code IS NULL THEN
847     l_curr_code := l_currency_code;
848   ELSE
849     l_curr_code := l_acct_call_rec.currency_code;
850   END IF;
851 
852   --End code added by pgomes on 11/22/2002
853 
854   -- *************************************
855   -- Rounded Amount
856   -- *************************************
857 
858   --pgomes, 12/06/2002, commented out below code
859   /*OPEN  l_curr_csr ( l_curr_code );
860   FETCH l_curr_csr INTO l_min_acct_unit, l_precision;
861   CLOSE l_curr_csr;
862 
863   IF (nvl(l_min_acct_unit,0) <> 0 ) THEN
864        -- Round the amount to the nearest Min Accountable Unit
865        l_rounded_amount := ROUND (l_acct_call_rec.line_amount / l_min_acct_unit) * l_min_acct_unit;
866   ELSE
867        -- Round the amount to the nearest precision
868        l_rounded_amount := ROUND (l_acct_call_rec.line_amount, l_precision);
869   END IF;*/
870 
871   --pgomes, 12/06/2002, code for rounding call
872   l_rounded_amount := okl_accounting_util.cross_currency_round_amount(p_amount => l_acct_call_rec.line_amount,
873                            p_currency_code => l_curr_code);
874 
875 
876   -- *************************************
877   -- Rounded Amount
878   -- *************************************
879 
880   l_dist_info_rec.AMOUNT                     := ABS(l_rounded_amount);
881   l_dist_info_rec.CURRENCY_CODE              := l_curr_code;
882 
883   l_dist_info_rec.CURRENCY_CONVERSION_TYPE   := NULL;
884 
885   --Start code added by pgomes on 11/22/2002
886 
887   --Check for currency conversion type
888   IF l_acct_call_rec.currency_conversion_type IS NULL THEN
889       l_dist_info_rec.currency_conversion_type := l_currency_conversion_type;
890   ELSE
891       l_dist_info_rec.currency_conversion_type := l_acct_call_rec.currency_conversion_type;
892   END IF;
893 
894 
895   l_dist_info_rec.CURRENCY_CONVERSION_DATE   := NULL;
896 
897   --Check for currency conversion date
898   IF l_acct_call_rec.currency_conversion_date IS NULL THEN
899       l_dist_info_rec.currency_conversion_date := l_currency_conversion_date;
900   ELSE
901       l_dist_info_rec.currency_conversion_date := l_acct_call_rec.currency_conversion_date;
902   END IF;
903 
904 
905   --Uncommented the below block of code to handle currency conversion rate
906   IF (l_dist_info_rec.currency_conversion_type = 'User') THEN
907     IF (l_dist_info_rec.currency_code = okl_accounting_util.get_func_curr_code) THEN
908        l_dist_info_rec.currency_conversion_rate := 1;
909     ELSE
910       IF l_acct_call_rec.currency_conversion_rate IS NULL THEN
911         l_dist_info_rec.currency_conversion_rate := l_currency_conversion_rate;
912       ELSE
913         l_dist_info_rec.currency_conversion_rate := l_acct_call_rec.currency_conversion_rate;
914       END IF;
915     END IF;
916   --pgomes 01/10/2003 added below code to get curr conv rate
917   ELSIF (l_dist_info_rec.currency_conversion_type = 'Spot' OR l_dist_info_rec.currency_conversion_type = 'Corporate') THEN
918     l_dist_info_rec.currency_conversion_rate := okl_accounting_util.get_curr_con_rate
919                                                 (p_from_curr_code => l_dist_info_rec.currency_code,
920 	                                         p_to_curr_code => okl_accounting_util.get_func_curr_code,
921 	                                         p_con_date => l_dist_info_rec.currency_conversion_date,
922 	                                         p_con_type => l_dist_info_rec.currency_conversion_type);
923   END IF;
924 
925   --pgomes 01/10/2003 added below code to default rate so that acct dist are created
926   l_dist_info_rec.currency_conversion_rate := NVL(l_dist_info_rec.currency_conversion_rate, 1);
927 
928   --End code added by pgomes on 11/22/2002
929 
930   l_dist_info_rec.CONTRACT_ID                := NULL;
931   l_dist_info_rec.CONTRACT_LINE_ID           := NULL;
932 
933     p_taiv_rec.id := l_acct_call_rec.header_id;
934 
935 
936     Okl_Populate_Acc_Gen (
937 	p_contract_id	     => l_acct_call_rec.khr_id,
938 	p_contract_line_id	=> l_acct_call_rec.kle_id,
939 	x_acc_gen_tbl		=> l_acc_gen_primary_key_tbl,
940 	x_return_status		=> x_return_status);
941 
942    IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
943       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
944    ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
945       RAISE OKL_API.G_EXCEPTION_ERROR;
946    END IF;
947 
948 -- Start of wraper code generated automatically by Debug code generator for Okl_Account_Dist_Pub.CREATE_ACCOUNTING_DIST
949   IF(L_DEBUG_ENABLED='Y') THEN
950     L_LEVEL_PROCEDURE :=FND_LOG.LEVEL_PROCEDURE;
951     IS_DEBUG_PROCEDURE_ON := OKL_DEBUG_PUB.Check_Log_On(L_MODULE, L_LEVEL_PROCEDURE);
952   END IF;
953   IF(IS_DEBUG_PROCEDURE_ON) THEN
954     BEGIN
955         OKL_DEBUG_PUB.LOG_DEBUG(L_LEVEL_PROCEDURE,L_MODULE,'Begin Debug OKLRACCB.pls call Okl_Account_Dist_Pub.CREATE_ACCOUNTING_DIST ');
956     END;
957   END IF;
958     Okl_Account_Dist_Pub.CREATE_ACCOUNTING_DIST(
959 								   p_api_version             => p_api_version
960                                   ,p_init_msg_list  		 => p_init_msg_list
961                                   ,x_return_status  		 => x_return_status
962                                   ,x_msg_count      		 => x_msg_count
963                                   ,x_msg_data       		 => x_msg_data
964                                   ,p_tmpl_identify_rec 		 => l_tmpl_identify_rec
965                                   ,p_dist_info_rec           => l_dist_info_rec
966                                   ,p_ctxt_val_tbl            => l_ctxt_val_tbl
967                                   ,p_acc_gen_primary_key_tbl => l_acc_gen_primary_key_tbl
968                                   ,x_template_tbl            => l_template_tbl
969                                   ,x_amount_tbl              => l_amount_tbl);
970 
971     IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
972       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
973     ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
974       RAISE OKL_API.G_EXCEPTION_ERROR;
975     END IF;
976 
977   IF(IS_DEBUG_PROCEDURE_ON) THEN
978     BEGIN
979         OKL_DEBUG_PUB.LOG_DEBUG(L_LEVEL_PROCEDURE,L_MODULE,'End Debug OKLRACCB.pls call Okl_Account_Dist_Pub.CREATE_ACCOUNTING_DIST ');
980     END;
981   END IF;
982 -- End of wraper code generated automatically by Debug code generator for Okl_Account_Dist_Pub.CREATE_ACCOUNTING_DIST
983 
984 	--Start code changes for rev rec by fmiao on 10/05/2004
985 	--rseela..bug# 5046450..added AND clause to check for 4 dists only for Billing txns and not CMs
986 	IF (l_rev_rec_basis = 'CASH_RECEIPT'  AND l_acct_call_rec.line_amount > 0) THEN
987 	   -- stmathew bug#4547180 / 4573599 start
988 	   OPEN l_dstrs_count_csr(l_dist_info_rec.SOURCE_ID, l_dist_info_rec.SOURCE_TABLE);
989 	   -- stmathew bug#4547180 / 4573599 end
990 	   FETCH l_dstrs_count_csr INTO l_count;
991 	   CLOSE l_dstrs_count_csr;
992 	   IF (l_count < 4) THEN
993 	   	  x_return_status := Okl_Api.G_RET_STS_ERROR;
994    	   END IF;
995 	END IF;
996 	--End code changes for rev rec by fmiao on 10/05/2004
997 
998       IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
999         RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
1000       ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
1001         RAISE OKL_API.G_EXCEPTION_ERROR;
1002       END IF;
1003 
1004     /*IF x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR THEN
1005          NULL;
1006        	 --RAISE G_EXCEPTION_HALT_VALIDATION;
1007     ELSE
1008       IF x_return_status <> Okl_Api.G_RET_STS_SUCCESS THEN
1009          l_return_status := x_return_status;
1010       END IF;
1011     END IF;
1012 
1013     IF x_return_status <> Okl_Api.G_RET_STS_SUCCESS THEN
1014 	   p_taiv_rec.trx_status_code := 'ERROR';
1015 	ELSE
1016 	   p_taiv_rec.trx_status_code := 'SUBMITTED';
1017 	END IF;*/
1018 /*
1019 	Okl_Tai_Pvt.update_row(
1020     p_api_version              =>    p_api_version,
1021     p_init_msg_list            =>    p_init_msg_list,
1022     x_return_status            =>    x_return_status,
1023     x_msg_count                =>    x_msg_count,
1024     x_msg_data                 =>    x_msg_data,
1025     p_taiv_rec                 =>    p_taiv_rec,
1026     x_taiv_rec                 =>    x_taiv_rec);
1027 */
1028 --akrangan ebtax billing impacts start here
1029   /**
1030   --Bug# 4488818: Changes for Rollover, Release Billing: Start
1031   OPEN trx_type_csr(p_id => l_acct_call_rec.try_id,
1032                     p_language => 'US');
1033   FETCH trx_type_csr INTO trx_type_rec;
1034   CLOSE trx_type_csr;
1035   */
1036   --akrangan ebtax billing impacts end here
1037 
1038 --ebtax impact on billing akrangan commented code starts here
1039 /*
1040   IF trx_type_rec.name IN ('Rollover Billing'    , 'Release Billing',
1041                            'Rollover Credit Memo', 'Release Credit Memo') THEN
1042 
1043     IF trx_type_rec.name IN ('Rollover Billing', 'Release Billing') THEN
1044       l_orig_try_id := get_trx_type ('Billing', 'US');
1045 
1046     ELSIF trx_type_rec.name IN ('Rollover Credit Memo', 'Release Credit Memo') THEN
1047       l_orig_try_id := get_trx_type ('Credit Memo', 'US');
1048 
1049     END IF;
1050 -- akrangan billing impact on ebtax start
1051     FOR orig_billing_rec IN orig_billing_csr(p_orig_qte_id  => l_acct_call_rec.qte_id,
1052                                              p_orig_quote_line_id => l_acct_call_rec.qte_line_id,
1053                                              p_orig_try_id  => l_orig_try_id)
1054     LOOP
1055 --tax cursor
1056       FOR orig_txs_rec IN orig_txs_csr(p_orig_trx_id       => orig_billing_rec.orig_tai_id,
1057                                        p_orig_trx_line_id  => orig_billing_rec.orig_til_id)
1058       LOOP
1059 
1060         -- Populate Tax Sources Record
1061 
1062         lp_txsv_rec.khr_id                        := orig_txs_rec.khr_id;
1063         lp_txsv_rec.kle_id                        := orig_txs_rec.kle_id;
1064         lp_txsv_rec.asset_number                  := orig_txs_rec.line_name;
1065         lp_txsv_rec.trx_id                        := l_acct_call_rec.header_id;
1066         lp_txsv_rec.trx_line_id                   := l_acct_call_rec.line_id;
1067         lp_txsv_rec.entity_code                   := orig_txs_rec.entity_code;
1068         lp_txsv_rec.event_class_code              := orig_txs_rec.event_class_code;
1069         lp_txsv_rec.trx_level_type                := orig_txs_rec.trx_level_type;
1070         lp_txsv_rec.adjusted_doc_entity_code      := orig_txs_rec.adjusted_doc_entity_code;
1071         lp_txsv_rec.adjusted_doc_event_class_code := orig_txs_rec.adjusted_doc_event_class_code;
1072         lp_txsv_rec.adjusted_doc_trx_id           := orig_txs_rec.adjusted_doc_trx_id;
1073         lp_txsv_rec.adjusted_doc_trx_line_id      := orig_txs_rec.adjusted_doc_trx_line_id;
1074         lp_txsv_rec.adjusted_doc_trx_level_type   := orig_txs_rec.adjusted_doc_trx_level_type;
1075         lp_txsv_rec.adjusted_doc_number           := orig_txs_rec.adjusted_doc_number;
1076         lp_txsv_rec.adjusted_doc_date             := orig_txs_rec.adjusted_doc_date;
1077         lp_txsv_rec.tax_call_type_code            := orig_txs_rec.tax_call_type_code;
1078         lp_txsv_rec.sty_id                        := orig_txs_rec.sty_id;
1079         lp_txsv_rec.trx_business_category         := orig_txs_rec.trx_business_category;
1080         lp_txsv_rec.tax_line_status_code          := orig_txs_rec.tax_line_status_code;
1081         lp_txsv_rec.sel_id                        := orig_txs_rec.sel_id;
1082         lp_txsv_rec.reported_yn                   := orig_txs_rec.tax_reporting_flag;
1083 	-- Modified by dcshanmu for eBTax - modification starts
1084         lp_txsv_rec.application_id := orig_txs_rec.application_id;
1085         lp_txsv_rec.default_taxation_country := orig_txs_rec.default_taxation_country;
1086         lp_txsv_rec.product_category := orig_txs_rec.product_category;
1087         lp_txsv_rec.user_defined_fisc_class := orig_txs_rec.user_defined_fisc_class;
1088         lp_txsv_rec.line_intended_use := orig_txs_rec.line_intended_use;
1089         lp_txsv_rec.inventory_item_id := orig_txs_rec.inventory_item_id;
1090         lp_txsv_rec.bill_to_cust_acct_id := orig_txs_rec.bill_to_cust_acct_id;
1091         lp_txsv_rec.org_id := orig_txs_rec.org_id;
1092         lp_txsv_rec.legal_entity_id := orig_txs_rec.legal_entity_id;
1093         lp_txsv_rec.line_amt := orig_txs_rec.line_amt;
1094         lp_txsv_rec.assessable_value := orig_txs_rec.assessable_value;
1095         lp_txsv_rec.total_tax := orig_txs_rec.total_tax;
1096         lp_txsv_rec.product_type := orig_txs_rec.product_type;
1097         lp_txsv_rec.product_fisc_classification := orig_txs_rec.product_fisc_classification;
1098         lp_txsv_rec.trx_date := orig_txs_rec.trx_date;
1099         lp_txsv_rec.provnl_tax_determination_date := orig_txs_rec.provnl_tax_determination_date;
1100         lp_txsv_rec.try_id := orig_txs_rec.try_id;
1101         lp_txsv_rec.ship_to_location_id := orig_txs_rec.ship_to_location_id;
1102         lp_txsv_rec.ship_from_location_id := orig_txs_rec.ship_from_location_id;
1103         lp_txsv_rec.trx_currency_code := orig_txs_rec.trx_currency_code;
1104         lp_txsv_rec.currency_conversion_type := orig_txs_rec.currency_conversion_type;
1105         lp_txsv_rec.currency_conversion_rate := orig_txs_rec.currency_conversion_rate;
1106         lp_txsv_rec.currency_conversion_date := orig_txs_rec.currency_conversion_date;
1107 	-- Modified by dcshanmu for eBTax - modification end
1108 
1109         IF(IS_DEBUG_PROCEDURE_ON) THEN
1110           BEGIN
1111             OKL_DEBUG_PUB.LOG_DEBUG(L_LEVEL_PROCEDURE,L_MODULE,'Begin Debug OKLRACCB.pls call OKL_TAX_SOURCES_PUB.insert_tax_sources ');
1112           END;
1113         END IF;
1114 
1115         -- Create Tax Sources Record
1116         OKL_TAX_SOURCES_PUB.insert_tax_sources(
1117           p_api_version    => p_api_version,
1118           p_init_msg_list  => p_init_msg_list,
1119           x_return_status  => x_return_status,
1120           x_msg_count      => x_msg_count,
1121           x_msg_data       => x_msg_data,
1122           p_txsv_rec       => lp_txsv_rec,
1123           x_txsv_rec       => lx_txsv_rec);
1124 
1125         IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
1126            RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
1127         ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
1128            RAISE OKL_API.G_EXCEPTION_ERROR;
1129         END IF;
1130 
1131         IF(IS_DEBUG_PROCEDURE_ON) THEN
1132           BEGIN
1133             OKL_DEBUG_PUB.LOG_DEBUG(L_LEVEL_PROCEDURE,L_MODULE,'End Debug OKLRACCB.pls call OKL_TAX_SOURCES_PUB.insert_tax_sources ');
1134           END;
1135         END IF;
1136 
1137         -- Populate Tax Details Record
1138         l_ttdv_count := 0;
1139 
1140         FOR orig_ttd_rec IN orig_ttd_csr(p_orig_txs_id => orig_txs_rec.id)
1141         LOOP
1142           l_ttdv_count :=  l_ttdv_count + 1;
1143           lp_ttdv_tbl(l_ttdv_count).txs_id                 := lx_txsv_rec.id;
1144           lp_ttdv_tbl(l_ttdv_count).tax_determine_date := orig_ttd_rec.tax_determine_date;
1145           lp_ttdv_tbl(l_ttdv_count).tax_rate_id            := orig_ttd_rec.tax_rate_id;
1146           lp_ttdv_tbl(l_ttdv_count).tax_rate_code          := orig_ttd_rec.tax_rate_code;
1147           lp_ttdv_tbl(l_ttdv_count).taxable_amt         := (-1 * orig_ttd_rec.taxable_amt);
1148           lp_ttdv_tbl(l_ttdv_count).tax_exemption_id       := orig_ttd_rec.tax_exemption_id;
1149           lp_ttdv_tbl(l_ttdv_count).tax_rate               := orig_ttd_rec.tax_rate;
1150           lp_ttdv_tbl(l_ttdv_count).tax_amt             := (-1 * orig_ttd_rec.tax_amt);
1151           lp_ttdv_tbl(l_ttdv_count).billed_yn              := orig_ttd_rec.billed_yn;
1152           lp_ttdv_tbl(l_ttdv_count).tax_call_type_code     := orig_ttd_rec.tax_call_type_code;
1153 	  -- Modified by dcshanmu for eBTax - modification starts
1154           lp_ttdv_tbl(l_ttdv_count).tax_date	:= orig_ttd_rec.tax_date;
1155           lp_ttdv_tbl(l_ttdv_count).line_amt	:= orig_ttd_rec.line_amt;
1156           lp_ttdv_tbl(l_ttdv_count).internal_organization_id               	:= orig_ttd_rec.internal_organization_id;
1157           lp_ttdv_tbl(l_ttdv_count).application_id                         	:= orig_ttd_rec.application_id;
1158           lp_ttdv_tbl(l_ttdv_count).entity_code                            	:= orig_ttd_rec.entity_code;
1159           lp_ttdv_tbl(l_ttdv_count).event_class_code                       	:= orig_ttd_rec.event_class_code;
1160           lp_ttdv_tbl(l_ttdv_count).event_type_code                        	:= orig_ttd_rec.event_type_code;
1161           lp_ttdv_tbl(l_ttdv_count).trx_id                                 	:= orig_ttd_rec.trx_id;
1162           lp_ttdv_tbl(l_ttdv_count).trx_line_id                            	:= orig_ttd_rec.trx_line_id;
1163           lp_ttdv_tbl(l_ttdv_count).trx_level_type                         	:= orig_ttd_rec.trx_level_type;
1164           lp_ttdv_tbl(l_ttdv_count).trx_line_number                        	:= orig_ttd_rec.trx_line_number;
1165           lp_ttdv_tbl(l_ttdv_count).tax_line_number                        	:= orig_ttd_rec.tax_line_number;
1166           lp_ttdv_tbl(l_ttdv_count).tax_regime_id                          	:= orig_ttd_rec.tax_regime_id;
1167           lp_ttdv_tbl(l_ttdv_count).tax_regime_code                        	:= orig_ttd_rec.tax_regime_code;
1168           lp_ttdv_tbl(l_ttdv_count).tax_id                                 	:= orig_ttd_rec.tax_id;
1169           lp_ttdv_tbl(l_ttdv_count).tax                                    	:= orig_ttd_rec.tax;
1170           lp_ttdv_tbl(l_ttdv_count).tax_status_id                          	:= orig_ttd_rec.tax_status_id;
1171           lp_ttdv_tbl(l_ttdv_count).tax_status_code                        	:= orig_ttd_rec.tax_status_code;
1172           lp_ttdv_tbl(l_ttdv_count).tax_apportionment_line_number          	:= orig_ttd_rec.tax_apportionment_line_number;
1173           lp_ttdv_tbl(l_ttdv_count).legal_entity_id                        	:= orig_ttd_rec.legal_entity_id;
1174           lp_ttdv_tbl(l_ttdv_count).trx_number                             	:= orig_ttd_rec.trx_number;
1175           lp_ttdv_tbl(l_ttdv_count).trx_date                               	:= orig_ttd_rec.trx_date;
1176           lp_ttdv_tbl(l_ttdv_count).tax_jurisdiction_id                    	:= orig_ttd_rec.tax_jurisdiction_id;
1177           lp_ttdv_tbl(l_ttdv_count).tax_jurisdiction_code                  	:= orig_ttd_rec.tax_jurisdiction_code;
1178           lp_ttdv_tbl(l_ttdv_count).tax_type_code                          	:= orig_ttd_rec.tax_type_code;
1179           lp_ttdv_tbl(l_ttdv_count).tax_currency_code                      	:= orig_ttd_rec.tax_currency_code;
1180           lp_ttdv_tbl(l_ttdv_count).taxable_amt_tax_curr                   	:= orig_ttd_rec.taxable_amt_tax_curr;
1181           lp_ttdv_tbl(l_ttdv_count).trx_currency_code                      	:= orig_ttd_rec.trx_currency_code;
1182           lp_ttdv_tbl(l_ttdv_count).minimum_accountable_unit               	:= orig_ttd_rec.minimum_accountable_unit;
1183           lp_ttdv_tbl(l_ttdv_count).precision                              	:= orig_ttd_rec.precision;
1184           lp_ttdv_tbl(l_ttdv_count).currency_conversion_type               	:= orig_ttd_rec.currency_conversion_type;
1185           lp_ttdv_tbl(l_ttdv_count).currency_conversion_rate               	:= orig_ttd_rec.currency_conversion_rate;
1186           lp_ttdv_tbl(l_ttdv_count).currency_conversion_date               	:= orig_ttd_rec.currency_conversion_date;
1187 	  -- Modified by dcshanmu for eBTax - modification end
1188         END LOOP;
1189 
1190         IF(IS_DEBUG_PROCEDURE_ON) THEN
1191           BEGIN
1192             OKL_DEBUG_PUB.LOG_DEBUG(L_LEVEL_PROCEDURE,L_MODULE,'Begin Debug OKLRACCB.pls call OKL_TAX_TRX_DETAILS_PUB.insert_tax_trx_details ');
1193           END;
1194         END IF;
1195 
1196         -- Create Tax Details Record
1197         OKL_TAX_TRX_DETAILS_PUB.insert_tax_trx_details(
1198           p_api_version    => p_api_version,
1199           p_init_msg_list  => p_init_msg_list,
1200           x_return_status  => x_return_status,
1201           x_msg_count      => x_msg_count,
1202           x_msg_data       => x_msg_data,
1203           p_ttdv_tbl       => lp_ttdv_tbl,
1204           x_ttdv_tbl       => lx_ttdv_tbl);
1205 
1206         IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
1207            RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
1208         ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
1209            RAISE OKL_API.G_EXCEPTION_ERROR;
1210         END IF;
1211 
1212         IF(IS_DEBUG_PROCEDURE_ON) THEN
1213           BEGIN
1214             OKL_DEBUG_PUB.LOG_DEBUG(L_LEVEL_PROCEDURE,L_MODULE,'End Debug OKLRACCB.pls call OKL_TAX_TRX_DETAILS_PUB.insert_tax_trx_details ');
1215           END;
1216         END IF;
1217 
1218       END LOOP;
1219     END LOOP;
1220 
1221   ELSE
1222     -- Tax processing for Invoice and on-account Credit Memo
1223     IF l_acct_call_rec.tld_id_reverses IS NULL THEN
1224 
1225       --Start code changes for Tax API call by varao on 05/04/2005
1226       IF(IS_DEBUG_PROCEDURE_ON) THEN
1227         BEGIN
1228           OKL_DEBUG_PUB.LOG_DEBUG(L_LEVEL_PROCEDURE,L_MODULE,'Begin Debug OKLRACCB.pls call OKL_PROCESS_SALES_TAX_PUB.calculate_sales_tax ');
1229         END;
1230       END IF;
1231       -- Call the Tax API for Invoice and on-account Credit Memo
1232 
1233       OKL_PROCESS_SALES_TAX_PVT.calculate_sales_tax(
1234                           p_api_version             => p_api_version,
1235                           p_init_msg_list  		    => p_init_msg_list,
1236                           x_return_status  		    => x_return_status,
1237                           x_msg_count      		    => x_msg_count,
1238                           x_msg_data       		    => x_msg_data,
1239                           p_source_trx_id       	=> p_bpd_acc_rec.id,
1240                           p_source_trx_name        	=> l_trx_name,
1241                           p_source_table       		=> p_bpd_acc_rec.source_table);
1242 
1243       IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
1244          RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
1245       ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
1246          RAISE OKL_API.G_EXCEPTION_ERROR;
1247       END IF;
1248 
1249       IF(IS_DEBUG_PROCEDURE_ON) THEN
1250         BEGIN
1251           OKL_DEBUG_PUB.LOG_DEBUG(L_LEVEL_PROCEDURE,L_MODULE,'End Debug OKLRACCB.pls call OKL_PROCESS_SALES_TAX_PUB.calculate_sales_tax ');
1252         END;
1253       END IF;
1254 
1255     --Bug# 4488818: Tax Processing for Invoice Based Credit Memo
1256     ELSE
1257 
1258       IF l_acct_call_rec.source_table = 'OKL_TXL_AR_INV_LNS_B' THEN
1259         OPEN orig_til_csr(p_til_id => l_acct_call_rec.tld_id_reverses);
1260         FETCH orig_til_csr INTO orig_til_tld_rec;
1261         CLOSE orig_til_csr;
1262       ELSIF l_acct_call_rec.source_table = 'OKL_TXD_AR_LN_DTLS_B' THEN
1263         OPEN orig_tld_csr(p_tld_id => l_acct_call_rec.tld_id_reverses);
1264         FETCH orig_tld_csr INTO orig_til_tld_rec;
1265         CLOSE orig_tld_csr;
1266       END IF;
1267 
1268       l_cm_ratio := l_acct_call_rec.line_amount/orig_til_tld_rec.amount;
1269 
1270       FOR orig_txs_rec IN orig_txs_csr(p_orig_trx_id       => orig_til_tld_rec.tai_id,
1271                                        p_orig_trx_line_id  => l_acct_call_rec.tld_id_reverses)
1272       LOOP
1273 
1274         -- Populate Tax Sources Record
1275 
1276         lp_txsv_rec.khr_id                        := orig_txs_rec.khr_id;
1277         lp_txsv_rec.kle_id                        := orig_txs_rec.kle_id;
1278         lp_txsv_rec.asset_number                  := orig_txs_rec.line_name;
1279         lp_txsv_rec.trx_id                        := l_acct_call_rec.header_id;
1280         lp_txsv_rec.trx_line_id                   := l_acct_call_rec.line_id;
1281         lp_txsv_rec.entity_code                   := orig_txs_rec.entity_code;
1282         lp_txsv_rec.event_class_code              := orig_txs_rec.event_class_code;
1283         lp_txsv_rec.trx_level_type                := orig_txs_rec.trx_level_type;
1284         lp_txsv_rec.adjusted_doc_entity_code      := orig_txs_rec.adjusted_doc_entity_code;
1285         lp_txsv_rec.adjusted_doc_event_class_code := orig_txs_rec.adjusted_doc_event_class_code;
1286         lp_txsv_rec.adjusted_doc_trx_id           := orig_txs_rec.adjusted_doc_trx_id;
1287         lp_txsv_rec.adjusted_doc_trx_line_id      := orig_txs_rec.adjusted_doc_trx_line_id;
1288         lp_txsv_rec.adjusted_doc_trx_level_type   := orig_txs_rec.adjusted_doc_trx_level_type;
1289         lp_txsv_rec.adjusted_doc_number           := orig_txs_rec.adjusted_doc_number;
1290         lp_txsv_rec.adjusted_doc_date             := orig_txs_rec.adjusted_doc_date;
1291         lp_txsv_rec.tax_call_type_code            := orig_txs_rec.tax_call_type_code;
1292         lp_txsv_rec.sty_id                        := orig_txs_rec.sty_id;
1293         lp_txsv_rec.trx_business_category         := orig_txs_rec.trx_business_category;
1294         lp_txsv_rec.tax_line_status_code          := orig_txs_rec.tax_line_status_code;
1295         lp_txsv_rec.sel_id                        := orig_txs_rec.sel_id;
1296         lp_txsv_rec.reported_yn                   := orig_txs_rec.tax_reporting_flag;
1297 	-- Modified by dcshanmu for eBTax - modification starts
1298         lp_txsv_rec.application_id := orig_txs_rec.application_id;
1299         lp_txsv_rec.default_taxation_country := orig_txs_rec.default_taxation_country;
1300         lp_txsv_rec.product_category := orig_txs_rec.product_category;
1301         lp_txsv_rec.user_defined_fisc_class := orig_txs_rec.user_defined_fisc_class;
1302         lp_txsv_rec.line_intended_use := orig_txs_rec.line_intended_use;
1303         lp_txsv_rec.inventory_item_id := orig_txs_rec.inventory_item_id;
1304         lp_txsv_rec.bill_to_cust_acct_id := orig_txs_rec.bill_to_cust_acct_id;
1305         lp_txsv_rec.org_id := orig_txs_rec.org_id;
1306         lp_txsv_rec.legal_entity_id := orig_txs_rec.legal_entity_id;
1307         lp_txsv_rec.line_amt := orig_txs_rec.line_amt;
1308         lp_txsv_rec.assessable_value := orig_txs_rec.assessable_value;
1309         lp_txsv_rec.total_tax := orig_txs_rec.total_tax;
1310         lp_txsv_rec.product_type := orig_txs_rec.product_type;
1311         lp_txsv_rec.product_fisc_classification := orig_txs_rec.product_fisc_classification;
1312         lp_txsv_rec.trx_date := orig_txs_rec.trx_date;
1313         lp_txsv_rec.provnl_tax_determination_date := orig_txs_rec.provnl_tax_determination_date;
1314         lp_txsv_rec.try_id := orig_txs_rec.try_id;
1315         lp_txsv_rec.ship_to_location_id := orig_txs_rec.ship_to_location_id;
1316         lp_txsv_rec.ship_from_location_id := orig_txs_rec.ship_from_location_id;
1317         lp_txsv_rec.trx_currency_code := orig_txs_rec.trx_currency_code;
1318         lp_txsv_rec.currency_conversion_type := orig_txs_rec.currency_conversion_type;
1319         lp_txsv_rec.currency_conversion_rate := orig_txs_rec.currency_conversion_rate;
1320         lp_txsv_rec.currency_conversion_date := orig_txs_rec.currency_conversion_date;
1321 	-- Modified by dcshanmu for eBTax - modification end
1322 
1323         IF(IS_DEBUG_PROCEDURE_ON) THEN
1324           BEGIN
1325             OKL_DEBUG_PUB.LOG_DEBUG(L_LEVEL_PROCEDURE,L_MODULE,'Begin Debug OKLRACCB.pls call OKL_TAX_SOURCES_PUB.insert_tax_sources ');
1326           END;
1327         END IF;
1328 
1329         -- Create Tax Sources Record
1330         OKL_TAX_SOURCES_PUB.insert_tax_sources(
1331           p_api_version    => p_api_version,
1332           p_init_msg_list  => p_init_msg_list,
1333           x_return_status  => x_return_status,
1334           x_msg_count      => x_msg_count,
1335           x_msg_data       => x_msg_data,
1336           p_txsv_rec       => lp_txsv_rec,
1337           x_txsv_rec       => lx_txsv_rec);
1338 
1339         IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
1340            RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
1341         ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
1342            RAISE OKL_API.G_EXCEPTION_ERROR;
1343         END IF;
1344 
1345         IF(IS_DEBUG_PROCEDURE_ON) THEN
1346           BEGIN
1347             OKL_DEBUG_PUB.LOG_DEBUG(L_LEVEL_PROCEDURE,L_MODULE,'End Debug OKLRACCB.pls call OKL_TAX_SOURCES_PUB.insert_tax_sources ');
1348           END;
1349         END IF;
1350 
1351         -- Populate Tax Details Record
1352         l_ttdv_count := 0;
1353 
1354         FOR orig_ttd_rec IN orig_ttd_csr(p_orig_txs_id => orig_txs_rec.id)
1355         LOOP
1356           l_ttdv_count :=  l_ttdv_count + 1;
1357           lp_ttdv_tbl(l_ttdv_count).txs_id                 := lx_txsv_rec.id;
1358           lp_ttdv_tbl(l_ttdv_count).tax_determine_date := orig_ttd_rec.tax_determine_date;
1359           lp_ttdv_tbl(l_ttdv_count).tax_rate_id            := orig_ttd_rec.tax_rate_id;
1360           lp_ttdv_tbl(l_ttdv_count).tax_rate_code          := orig_ttd_rec.tax_rate_code;
1361           lp_ttdv_tbl(l_ttdv_count).tax_exemption_id       := orig_ttd_rec.tax_exemption_id;
1362           lp_ttdv_tbl(l_ttdv_count).tax_rate               := orig_ttd_rec.tax_rate;
1363           lp_ttdv_tbl(l_ttdv_count).billed_yn              := orig_ttd_rec.billed_yn;
1364           lp_ttdv_tbl(l_ttdv_count).tax_call_type_code     := orig_ttd_rec.tax_call_type_code;
1365 	  -- Modified by dcshanmu for eBTax - modification starts
1366           lp_ttdv_tbl(l_ttdv_count).tax_date	:= orig_ttd_rec.tax_date;
1367           lp_ttdv_tbl(l_ttdv_count).line_amt	:= orig_ttd_rec.line_amt;
1368           lp_ttdv_tbl(l_ttdv_count).internal_organization_id               	:= orig_ttd_rec.internal_organization_id;
1369           lp_ttdv_tbl(l_ttdv_count).application_id                         	:= orig_ttd_rec.application_id;
1370           lp_ttdv_tbl(l_ttdv_count).entity_code                            	:= orig_ttd_rec.entity_code;
1371           lp_ttdv_tbl(l_ttdv_count).event_class_code                       	:= orig_ttd_rec.event_class_code;
1372           lp_ttdv_tbl(l_ttdv_count).event_type_code                        	:= orig_ttd_rec.event_type_code;
1373           lp_ttdv_tbl(l_ttdv_count).trx_id                                 	:= orig_ttd_rec.trx_id;
1374           lp_ttdv_tbl(l_ttdv_count).trx_line_id                            	:= orig_ttd_rec.trx_line_id;
1375           lp_ttdv_tbl(l_ttdv_count).trx_level_type                         	:= orig_ttd_rec.trx_level_type;
1376           lp_ttdv_tbl(l_ttdv_count).trx_line_number                        	:= orig_ttd_rec.trx_line_number;
1377           lp_ttdv_tbl(l_ttdv_count).tax_line_number                        	:= orig_ttd_rec.tax_line_number;
1378           lp_ttdv_tbl(l_ttdv_count).tax_regime_id                          	:= orig_ttd_rec.tax_regime_id;
1379           lp_ttdv_tbl(l_ttdv_count).tax_regime_code                        	:= orig_ttd_rec.tax_regime_code;
1380           lp_ttdv_tbl(l_ttdv_count).tax_id                                 	:= orig_ttd_rec.tax_id;
1381           lp_ttdv_tbl(l_ttdv_count).tax                                    	:= orig_ttd_rec.tax;
1382           lp_ttdv_tbl(l_ttdv_count).tax_status_id                          	:= orig_ttd_rec.tax_status_id;
1383           lp_ttdv_tbl(l_ttdv_count).tax_status_code                        	:= orig_ttd_rec.tax_status_code;
1384           lp_ttdv_tbl(l_ttdv_count).tax_apportionment_line_number          	:= orig_ttd_rec.tax_apportionment_line_number;
1385           lp_ttdv_tbl(l_ttdv_count).legal_entity_id                        	:= orig_ttd_rec.legal_entity_id;
1386           lp_ttdv_tbl(l_ttdv_count).trx_number                             	:= orig_ttd_rec.trx_number;
1387           lp_ttdv_tbl(l_ttdv_count).trx_date                               	:= orig_ttd_rec.trx_date;
1388           lp_ttdv_tbl(l_ttdv_count).tax_jurisdiction_id                    	:= orig_ttd_rec.tax_jurisdiction_id;
1389           lp_ttdv_tbl(l_ttdv_count).tax_jurisdiction_code                  	:= orig_ttd_rec.tax_jurisdiction_code;
1390           lp_ttdv_tbl(l_ttdv_count).tax_type_code                          	:= orig_ttd_rec.tax_type_code;
1391           lp_ttdv_tbl(l_ttdv_count).tax_currency_code                      	:= orig_ttd_rec.tax_currency_code;
1392           lp_ttdv_tbl(l_ttdv_count).taxable_amt_tax_curr                   	:= orig_ttd_rec.taxable_amt_tax_curr;
1393           lp_ttdv_tbl(l_ttdv_count).trx_currency_code                      	:= orig_ttd_rec.trx_currency_code;
1394           lp_ttdv_tbl(l_ttdv_count).minimum_accountable_unit               	:= orig_ttd_rec.minimum_accountable_unit;
1395           lp_ttdv_tbl(l_ttdv_count).precision                              	:= orig_ttd_rec.precision;
1396           lp_ttdv_tbl(l_ttdv_count).currency_conversion_type               	:= orig_ttd_rec.currency_conversion_type;
1397           lp_ttdv_tbl(l_ttdv_count).currency_conversion_rate               	:= orig_ttd_rec.currency_conversion_rate;
1398           lp_ttdv_tbl(l_ttdv_count).currency_conversion_date               	:= orig_ttd_rec.currency_conversion_date;
1399 	  -- Modified by dcshanmu for eBTax - modification end
1400 
1401           l_taxable_amount := orig_ttd_rec.taxable_amt * l_cm_ratio;
1402           lp_ttdv_tbl(l_ttdv_count).taxable_amt :=
1403                                okl_accounting_util.cross_currency_round_amount
1404                                  (p_amount        => l_taxable_amount,
1405                                   p_currency_code => l_curr_code);
1406 
1407            l_tax_amount := orig_ttd_rec.tax_amt * l_cm_ratio;
1408            lp_ttdv_tbl(l_ttdv_count).tax_amt :=
1409                                okl_accounting_util.cross_currency_round_amount
1410                                  (p_amount        => l_tax_amount,
1411                                   p_currency_code => l_curr_code);
1412 
1413         END LOOP;
1414 
1415         IF(IS_DEBUG_PROCEDURE_ON) THEN
1416           BEGIN
1417             OKL_DEBUG_PUB.LOG_DEBUG(L_LEVEL_PROCEDURE,L_MODULE,'Begin Debug OKLRACCB.pls call OKL_TAX_TRX_DETAILS_PUB.insert_tax_trx_details ');
1418           END;
1419         END IF;
1420 
1421         -- Create Tax Details Record
1422         OKL_TAX_TRX_DETAILS_PUB.insert_tax_trx_details(
1423           p_api_version    => p_api_version,
1424           p_init_msg_list  => p_init_msg_list,
1425           x_return_status  => x_return_status,
1426           x_msg_count      => x_msg_count,
1427           x_msg_data       => x_msg_data,
1428           p_ttdv_tbl       => lp_ttdv_tbl,
1429           x_ttdv_tbl       => lx_ttdv_tbl);
1430 
1431         IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
1432            RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
1433         ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
1434            RAISE OKL_API.G_EXCEPTION_ERROR;
1435         END IF;
1436 
1437         IF(IS_DEBUG_PROCEDURE_ON) THEN
1438           BEGIN
1439             OKL_DEBUG_PUB.LOG_DEBUG(L_LEVEL_PROCEDURE,L_MODULE,'End Debug OKLRACCB.pls call OKL_TAX_TRX_DETAILS_PUB.insert_tax_trx_details ');
1440           END;
1441         END IF;
1442 
1443       END LOOP;
1444 
1445     END IF;
1446     --End code changes for Tax API call by varao on 05/04/2005
1447   END IF;
1448    */
1449     --ebtax impact on billing akrangan commented code ends here
1450   --Bug# 4488818: Changes for Rollover, Release Billing: End
1451 
1452     /*IF x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR THEN
1453          NULL;
1454        	 --RAISE G_EXCEPTION_HALT_VALIDATION;
1455     ELSE
1456       IF x_return_status <> Okl_Api.G_RET_STS_SUCCESS THEN
1457          l_return_status := x_return_status;
1458       END IF;
1459     END IF;*/
1460 
1461   --Bug# 4488818: Changes for Upfront Sales Tax: Start
1462   -- Tax only invoice - Line Amount is equal to zero.
1463   ELSE
1464     NULL;
1465    --Bug# 4622963: Changes for Mass Rebook: Start
1466    --check for mass rebook contract
1467    --akrangan ebtax billing impacts start here
1468    /*
1469    l_mass_rbk_khr := '?';
1470    OPEN l_chk_mass_rbk_csr (p_chr_id => l_acct_call_rec.khr_id,
1471                             p_trx_id => p_bpd_acc_rec.source_trx_id);
1472    FETCH l_chk_mass_rbk_csr INTO l_mass_rbk_khr;
1473    CLOSE l_chk_mass_rbk_csr;
1474 
1475    -- Populate Tax Details Record
1476     l_ttdv_count := 0;
1477 
1478    --If Mass Rebook
1479 
1480    IF l_mass_rbk_khr = '!' THEN
1481 
1482      -- Fetch all Upfront Tax Lines.
1483      -- Upfront Tax is always to be Billed for Mass Rebook
1484 
1485      FOR tax_details_line_rec IN
1486          tax_details_line3_csr(p_khr_id => l_acct_call_rec.khr_id,
1487                                p_trx_id => p_bpd_acc_rec.source_trx_id)
1488      LOOP
1489        l_ttdv_count :=  l_ttdv_count + 1;
1490        lp_ttdv_tbl(l_ttdv_count).tax_amt := tax_details_line_rec.tax_amt;
1491        lp_ttdv_tbl(l_ttdv_count).taxable_amt := tax_details_line_rec.taxable_amt;
1492        lp_ttdv_tbl(l_ttdv_count).tax_rate_code := tax_details_line_rec.tax_rate_code;
1493        lp_ttdv_tbl(l_ttdv_count).tax_call_type_code := 'TAX_ONLY_INVOICE_TAX';
1494      END LOOP;
1495    --Bug# 4622963: Changes for Mass Rebook: End
1496 
1497    ELSE
1498 
1499     OPEN upfront_tax_csr(p_khr_id => l_acct_call_rec.khr_id);
1500     FETCH upfront_tax_csr INTO upfront_tax_rec;
1501     CLOSE upfront_tax_csr;
1502 
1503     -- Contract Level Asset Upfront Tax is set to 'BILLED'
1504     IF (upfront_tax_rec.asset_upfront_tax = 'BILLED') THEN
1505 
1506       -- Fetch Tax Lines for Assets having Line level Asset Upfront Tax
1507       -- Rule undefined or set to 'BILLED'.
1508       FOR tax_details_line_rec IN
1509           tax_details_line1_csr(p_khr_id => l_acct_call_rec.khr_id,
1510                                 p_trx_id => p_bpd_acc_rec.source_trx_id)
1511       LOOP
1512          l_ttdv_count :=  l_ttdv_count + 1;
1513          lp_ttdv_tbl(l_ttdv_count).tax_amt := tax_details_line_rec.tax_amt;
1514          lp_ttdv_tbl(l_ttdv_count).taxable_amt := tax_details_line_rec.taxable_amt;
1515          lp_ttdv_tbl(l_ttdv_count).tax_rate_code := tax_details_line_rec.tax_rate_code;
1516          lp_ttdv_tbl(l_ttdv_count).tax_call_type_code := 'TAX_ONLY_INVOICE_TAX';
1517       END LOOP;
1518 
1519     -- Contract Level Asset Upfront Tax is not set to 'BILLED'
1520     ELSE
1521 
1522       -- Fetch Tax Lines for Assets having Line level Asset Upfront Tax
1523       -- Rule set to 'BILLED'.
1524       FOR tax_details_line_rec IN
1525           tax_details_line2_csr(p_khr_id => l_acct_call_rec.khr_id,
1526                                 p_trx_id => p_bpd_acc_rec.source_trx_id)
1527       LOOP
1528          l_ttdv_count :=  l_ttdv_count + 1;
1529          lp_ttdv_tbl(l_ttdv_count).tax_amt := tax_details_line_rec.tax_amt;
1530          lp_ttdv_tbl(l_ttdv_count).taxable_amt := tax_details_line_rec.taxable_amt;
1531          lp_ttdv_tbl(l_ttdv_count).tax_rate_code := tax_details_line_rec.tax_rate_code;
1532          lp_ttdv_tbl(l_ttdv_count).tax_call_type_code := 'TAX_ONLY_INVOICE_TAX';
1533       END LOOP;
1534 
1535     END IF;
1536    END IF;
1537    */
1538    --akrangan ebtax billing impacts end here
1539 
1540  --akrangan ebtax billing impacts start
1541   /*  IF (l_ttdv_count > 0) THEN
1542 
1543       -- Populate Tax Sources Record
1544       lp_txsv_rec.khr_id := l_acct_call_rec.khr_id;
1545       lp_txsv_rec.trx_id := l_acct_call_rec.header_id;
1546       lp_txsv_rec.trx_line_id := l_acct_call_rec.line_id;
1547       lp_txsv_rec.entity_code := 'OKL_TXL_AR_INV_LNS_B';
1548       lp_txsv_rec.event_class_code := 'SALES_TRANSACTION_TAX_QUOTE';
1549       lp_txsv_rec.trx_level_type := 'LINE';
1550       lp_txsv_rec.tax_call_type_code := 'TAX_ONLY_INVOICE_TAX';
1551       lp_txsv_rec.sty_id := l_acct_call_rec.sty_id;
1552       lp_txsv_rec.tax_line_status_code := 'ACTIVE';
1553       lp_txsv_rec.reported_yn := 'N';
1554 
1555       IF(IS_DEBUG_PROCEDURE_ON) THEN
1556         BEGIN
1557           OKL_DEBUG_PUB.LOG_DEBUG(L_LEVEL_PROCEDURE,L_MODULE,'Begin Debug OKLRACCB.pls call OKL_TAX_SOURCES_PUB.insert_tax_sources ');
1558         END;
1559       END IF;
1560 
1561       -- Create Tax Sources Record
1562       OKL_TAX_SOURCES_PUB.insert_tax_sources(
1563         p_api_version    => p_api_version,
1564         p_init_msg_list  => p_init_msg_list,
1565         x_return_status  => x_return_status,
1566         x_msg_count      => x_msg_count,
1567         x_msg_data       => x_msg_data,
1568         p_txsv_rec       => lp_txsv_rec,
1569         x_txsv_rec       => lx_txsv_rec);
1570 
1571       IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
1572         RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
1573       ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
1574         RAISE OKL_API.G_EXCEPTION_ERROR;
1575       END IF;
1576 
1577       IF(IS_DEBUG_PROCEDURE_ON) THEN
1578         BEGIN
1579           OKL_DEBUG_PUB.LOG_DEBUG(L_LEVEL_PROCEDURE,L_MODULE,'End Debug OKLRACCB.pls call OKL_TAX_SOURCES_PUB.insert_tax_sources ');
1580         END;
1581       END IF;
1582 
1583       -- Populate txs_id in lp_ttdv_tbl
1584       FOR l_count IN lp_ttdv_tbl.FIRST..lp_ttdv_tbl.LAST
1585       LOOP
1586         lp_ttdv_tbl(l_count).txs_id := lx_txsv_rec.id;
1587       END LOOP;
1588 
1589       IF(IS_DEBUG_PROCEDURE_ON) THEN
1590         BEGIN
1591           OKL_DEBUG_PUB.LOG_DEBUG(L_LEVEL_PROCEDURE,L_MODULE,'Begin Debug OKLRACCB.pls call OKL_TAX_TRX_DETAILS_PUB.insert_tax_trx_details ');
1592         END;
1593       END IF;
1594 
1595       -- Create Tax Details Record
1596       OKL_TAX_TRX_DETAILS_PUB.insert_tax_trx_details(
1597         p_api_version    => p_api_version,
1598         p_init_msg_list  => p_init_msg_list,
1599         x_return_status  => x_return_status,
1600         x_msg_count      => x_msg_count,
1601         x_msg_data       => x_msg_data,
1602         p_ttdv_tbl       => lp_ttdv_tbl,
1603         x_ttdv_tbl       => lx_ttdv_tbl);
1604 
1605       IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
1606         RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
1607       ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
1608         RAISE OKL_API.G_EXCEPTION_ERROR;
1609       END IF;
1610 
1611       IF(IS_DEBUG_PROCEDURE_ON) THEN
1612         BEGIN
1613           OKL_DEBUG_PUB.LOG_DEBUG(L_LEVEL_PROCEDURE,L_MODULE,'End Debug OKLRACCB.pls call OKL_TAX_TRX_DETAILS_PUB.insert_tax_trx_details ');
1614         END;
1615       END IF;
1616 
1617     END IF; */
1618      --akrangan ebtax billing impacts end
1619   END IF;
1620   --Bug# 4488818: Changes for Upfront Sales Tax: End
1621 
1622   x_return_status := Okl_Api.G_RET_STS_SUCCESS;
1623 
1624 EXCEPTION
1625     WHEN OKL_API.G_EXCEPTION_ERROR THEN
1626       x_return_status := Okl_Api.G_RET_STS_ERROR;
1627 
1628     WHEN OKL_API.G_EXCEPTION_UNEXPECTED_ERROR THEN
1629       x_return_status := Okl_Api.G_RET_STS_UNEXP_ERROR;
1630 
1631     WHEN G_EXCEPTION_HALT_VALIDATION THEN
1632       Okl_Api.SET_MESSAGE(p_app_name          => g_app_name
1633                          ,p_msg_name          => g_unexpected_error
1634                          ,p_token1            => g_sqlcode_token
1635                          ,p_token1_value      => SQLCODE
1636                          ,p_token2            => g_sqlerrm_token
1637                          ,p_token2_value      => SQLERRM);
1638       x_return_status := Okl_Api.G_RET_STS_UNEXP_ERROR;
1639     WHEN OTHERS THEN
1640       Okl_Api.SET_MESSAGE(p_app_name          => g_app_name
1641                          ,p_msg_name          => g_unexpected_error
1642                          ,p_token1            => g_sqlcode_token
1643                          ,p_token1_value      => SQLCODE
1644                          ,p_token2            => g_sqlerrm_token
1645                          ,p_token2_value      => SQLERRM);
1646       x_return_status := Okl_Api.G_RET_STS_UNEXP_ERROR;
1647 END create_acc_trans;
1648 
1649 PROCEDURE create_acc_trans(
1650      p_api_version                  IN  NUMBER
1651     ,p_init_msg_list                IN  VARCHAR2
1652     ,x_return_status                OUT NOCOPY VARCHAR2
1653     ,x_msg_count                    OUT NOCOPY NUMBER
1654     ,x_msg_data                     OUT NOCOPY VARCHAR2
1655   	,p_bpd_acc_tbl  				IN  bpd_acc_tbl_type
1656 ) IS
1657 
1658   p_bpd_acc_rec 					bpd_acc_rec_type;
1659 
1660   l_msg_count 						NUMBER ;
1661   l_msg_data 						VARCHAR2(2000);
1662 
1663 BEGIN
1664 
1665   SAVEPOINT bpd_acc_create;
1666 
1667   FOR i IN  p_bpd_acc_tbl.first..p_bpd_acc_tbl.COUNT LOOP
1668 	 	 p_bpd_acc_rec := p_bpd_acc_tbl(i);
1669 		 create_acc_trans(
1670      	 		 p_api_version
1671     			,p_init_msg_list
1672     			,x_return_status
1673     			,x_msg_count
1674     			,x_msg_data
1675   				,p_bpd_acc_rec
1676 		  );
1677   END LOOP;
1678 EXCEPTION
1679     WHEN Fnd_Api.G_EXC_ERROR THEN
1680       ROLLBACK TO bpd_acc_create;
1681       x_return_status := Fnd_Api.G_RET_STS_ERROR;
1682       x_msg_count := l_msg_count ;
1683       x_msg_data := l_msg_data ;
1684       Fnd_Msg_Pub.count_and_get(
1685              p_count   => x_msg_count
1686             ,p_data    => x_msg_data);
1687     WHEN Fnd_Api.G_EXC_UNEXPECTED_ERROR THEN
1688       ROLLBACK TO bpd_acc_create;
1689       x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
1690       x_msg_count := l_msg_count ;
1691       x_msg_data := l_msg_data ;
1692       Fnd_Msg_Pub.count_and_get(
1693              p_count   => x_msg_count
1694             ,p_data    => x_msg_data);
1695     WHEN OTHERS THEN
1696       ROLLBACK TO bpd_acc_create;
1697       x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
1698       x_msg_count := l_msg_count ;
1699       x_msg_data := l_msg_data ;
1700       Fnd_Msg_Pub.ADD_EXC_MSG('Okl_Acc_Call_Pvt','create_acc_trans');
1701       Fnd_Msg_Pub.count_and_get(
1702              p_count   => x_msg_count
1703             ,p_data    => x_msg_data);
1704 END create_acc_trans;
1705 
1706 
1707 
1708 PROCEDURE create_acc_trans_new(
1709      p_api_version                  IN  NUMBER
1710     ,p_init_msg_list                IN  VARCHAR2
1711     ,x_return_status                OUT NOCOPY VARCHAR2
1712     ,x_msg_count                    OUT NOCOPY NUMBER
1713     ,x_msg_data                     OUT NOCOPY VARCHAR2
1714   	,p_bpd_acc_rec  				IN  bpd_acc_rec_type
1715     ,x_tmpl_identify_rec            OUT NOCOPY Okl_Account_Dist_Pub.TMPL_IDENTIFY_REC_TYPE
1716     ,x_dist_info_rec                OUT NOCOPY Okl_Account_Dist_Pub.DIST_INFO_REC_TYPE
1717     ,x_ctxt_val_tbl                 OUT NOCOPY Okl_Account_Dist_Pub.CTXT_VAL_TBL_TYPE
1718     ,x_acc_gen_primary_key_tbl      OUT NOCOPY Okl_Account_Dist_Pub.ACC_GEN_PRIMARY_KEY
1719 ) IS
1720 
1721 -- Local instance of AE rec/tbl Types
1722 
1723   	l_tmpl_identify_rec    		    Okl_Account_Dist_Pub.TMPL_IDENTIFY_REC_TYPE;
1724   	l_dist_info_rec        			Okl_Account_Dist_Pub.DIST_INFO_REC_TYPE;
1725   	l_ctxt_val_tbl         			Okl_Account_Dist_Pub.CTXT_VAL_TBL_TYPE;
1726   	l_acc_gen_primary_key_tbl  		Okl_Account_Dist_Pub.ACC_GEN_PRIMARY_KEY;
1727 
1728     l_template_tbl         			Okl_Account_Dist_Pub.AVLV_TBL_TYPE;
1729   	l_amount_tbl           			Okl_Account_Dist_Pub.AMOUNT_TBL_TYPE;
1730 
1731     p_taiv_rec						taiv_rec_type;
1732     x_taiv_rec                 		taiv_rec_type;
1733 
1734     l_hd_id							NUMBER;
1735     i                               NUMBER;
1736     l_return_status                 VARCHAR2(1)   := Okc_Api.G_RET_STS_SUCCESS;
1737     l_found							BOOLEAN;
1738 
1739     CURSOR l_acc_lines_csr(l_id IN NUMBER) IS
1740 		   SELECT khr.pdt_id pdt_id,
1741 		   		  LN.sty_id sty_id,
1742 				  hd.try_id Try_id,
1743 				  LN.Amount line_amount,
1744 		   		  hd.date_invoiced,
1745 				  hd.currency_code,
1746 --Start code added by pgomes on 11/22/2002
1747                   hd.currency_conversion_type      currency_conversion_type,
1748                   hd.currency_conversion_rate      currency_conversion_rate,
1749                   hd.currency_conversion_date      currency_conversion_date,
1750 --End code added by pgomes on 11/22/2002
1751 				  LN.id line_id,
1752 				  'OKL_TXL_AR_INV_LNS_B' source_table,
1753 				  hd.ID header_id,
1754 				  hd.khr_id,
1755                   -- Added for bug 4228207
1756                   hd.qte_id,
1757 				  LN.kle_id,
1758 				  LN.til_id_reverses,
1759                                   -- Bug# 4488818
1760                                   LN.qte_line_id
1761 		   FROM   okl_txl_ar_inv_lns_v LN,
1762 		   		  okl_trx_ar_invoices_v hd,
1763 				  okl_k_headers_v khr
1764 		   WHERE  hd.id = LN.Tai_id	   		AND
1765 		   		  khr.id = hd.khr_id			AND
1766 		   		  LN.ID = l_id;
1767 
1768     CURSOR l_acc_dtls_csr(l_id IN NUMBER) IS
1769 		   SELECT khr.pdt_id   pdt_id,
1770 		   		  dtls.sty_id  sty_id,
1771 				  hd.try_id    Try_id,
1772 				  dtls.Amount  line_amount,
1773 		   		  hd.date_invoiced date_invoiced,
1774 				  hd.currency_code,
1775 --Start code added by pgomes on 11/22/2002
1776                   hd.currency_conversion_type      currency_conversion_type,
1777                   hd.currency_conversion_rate      currency_conversion_rate,
1778                   hd.currency_conversion_date      currency_conversion_date,
1779 --End code added by pgomes on 11/22/2002
1780 				  dtls.id line_id,
1781 				  'OKL_TXD_AR_LN_DTLS_B' source_table,
1782 				  hd.ID header_id,
1783 				  hd.khr_id,
1784                   -- Added for bug 4228207
1785                   hd.qte_id,
1786 				  LN.kle_id,
1787                                   --Bug# 4488818
1788 				  dtls.tld_id_reverses,
1789                                   -- Bug# 4488818
1790                                   LN.qte_line_id
1791 		   FROM   okl_txl_ar_inv_lns_v LN,
1792 		   		  okl_trx_ar_invoices_v hd,
1793 				  okl_txd_ar_ln_dtls_v dtls,
1794 				  okl_k_headers_v khr
1795 		   WHERE hd.id = LN.Tai_id 	 	   		 AND
1796 		       	 LN.ID = dtls.til_id_details	 AND
1797 		   		 khr.ID = hd.KHR_ID				 AND
1798 		   		 dtls.ID = l_id;
1799 
1800     -- Get currency attributes
1801     CURSOR l_curr_csr (cp_currency_code VARCHAR2) IS
1802     	   SELECT c.minimum_accountable_unit, c.precision
1803     	   FROM fnd_currencies c
1804     	   WHERE c.currency_code = cp_currency_code;
1805 
1806 	-- Get Currency Code
1807 	CURSOR get_curr_code_csr ( p_sob_id NUMBER ) IS
1808 		   SELECT currency_code
1809 		   FROM GL_LEDGERS_PUBLIC_V
1810 		   WHERE ledger_id = p_sob_id;
1811 
1812 
1813     l_min_acct_unit 			    fnd_currencies.minimum_accountable_unit%TYPE;
1814     l_precision     			    fnd_currencies.precision%TYPE;
1815     l_acct_call_rec                 l_acc_dtls_csr%ROWTYPE;
1816     l_rounded_amount	            okl_txl_ar_inv_lns_v.amount%type;
1817 	l_sob_id						okl_ext_sell_invs_v.SET_OF_BOOKS_ID%TYPE;
1818 	l_curr_code					    GL_LEDGERS_PUBLIC_V.currency_code%TYPE;
1819 	l_trx_name						VARCHAR2(20);
1820 
1821     --Start code added by pgomes on 11/22/2002
1822     SUBTYPE khr_id_type IS okl_k_headers_v.khr_id%type;
1823     l_khr_id khr_id_type;
1824     l_currency_code okl_ext_sell_invs_b.currency_code%type;
1825     l_currency_conversion_type okl_ext_sell_invs_b.currency_conversion_type%type;
1826     l_currency_conversion_rate okl_ext_sell_invs_b.currency_conversion_rate%type;
1827     l_currency_conversion_date okl_ext_sell_invs_b.currency_conversion_date%type;
1828 
1829     --Get currency conversion attributes for a contract
1830     CURSOR l_curr_conv_csr(cp_khr_id IN khr_id_type) IS
1831     SELECT  currency_code
1832            ,currency_conversion_type
1833            ,currency_conversion_rate
1834            ,currency_conversion_date
1835     FROM    okl_k_headers_full_v
1836     WHERE   id = cp_khr_id;
1837 
1838     --End code added by pgomes on 11/22/2002
1839 
1840 	--Start code changes for rev rec by fmiao on 10/05/2004
1841     CURSOR l_get_accrual_csr (cp_sty_id IN NUMBER) IS
1842 	       SELECT NVL(accrual_yn, '1')
1843 	       FROM   okl_strm_type_b
1844 	       WHERE  id = cp_sty_id;
1845 
1846     -- stmathew BUG#4547180/ 4573599 start
1847 	CURSOR l_dstrs_count_csr (cp_source_id IN NUMBER, cp_source_table IN VARCHAR2) IS
1848 	       SELECT count(*)
1849 	       FROM   okl_trns_acc_dstrs
1850 	       WHERE  source_id = cp_source_id
1851 		   AND    source_table = cp_source_table;
1852     -- stmathew BUG#4547180/ 4573599 end
1853 
1854 	l_rev_rec_basis okl_strm_type_b.accrual_yn%type;
1855 	l_count NUMBER;
1856 	--End code changes for rev rec by fmiao on 10/05/2004
1857 
1858     --Bug# 4488818: Changes for Upfront Tax Billing: Start
1859     lp_txsv_rec  OKL_TAX_SOURCES_PUB.txsv_rec_type;
1860     lx_txsv_rec  OKL_TAX_SOURCES_PUB.txsv_rec_type;
1861 
1862     lp_ttdv_tbl  OKL_TAX_TRX_DETAILS_PUB.ttdv_tbl_type;
1863     lx_ttdv_tbl  OKL_TAX_TRX_DETAILS_PUB.ttdv_tbl_type;
1864     --akrangan billing impacts coding start
1865     /*
1866     CURSOR upfront_tax_csr(p_khr_id IN NUMBER) IS
1867     SELECT rl.rule_information1 asset_upfront_tax
1868     FROM okc_rule_groups_b rg,
1869          okc_rules_b rl
1870     WHERE  rg.dnz_chr_id = p_khr_id
1871     AND    rg.rgd_code = 'LAHDTX'
1872     AND    rl.rgp_id = rg.id
1873     AND    rl.dnz_chr_id = rg.dnz_chr_id
1874     AND    rl.rule_information_category = 'LASTPR';
1875 
1876     upfront_tax_rec upfront_tax_csr%ROWTYPE;
1877 
1878     CURSOR tax_details_line1_csr(p_khr_id IN NUMBER,
1879                                  p_trx_id IN NUMBER) IS
1880     SELECT SUM(NVL(tax_amt,0)) tax_amt,
1881            SUM(NVL(taxable_amt,0)) taxable_amt,
1882            tax_rate_code
1883     FROM (
1884       SELECT NVL(tax_amt,0) tax_amt,
1885              NVL(taxable_amt,0) taxable_amt,
1886              tax_rate_code
1887       FROM   okl_tax_sources txs,
1888              okl_tax_trx_details txl,
1889              okc_rule_groups_b rg,
1890              okc_rules_b rl
1891       WHERE  txs.khr_id = p_khr_id
1892       AND    txs.trx_id = p_trx_id
1893       AND    txs.tax_line_status_code = 'ACTIVE'
1894       AND    txs.tax_call_type_code = 'UPFRONT_TAX'
1895       AND    txl.txs_id = txs.id
1896       AND    rg.dnz_chr_id = txs.khr_id
1897       AND    rg.cle_id = txs.kle_id
1898       AND    rg.rgd_code = 'LAASTX'
1899       AND    rl.rgp_id = rg.id
1900       AND    rl.dnz_chr_id = txs.khr_id
1901       AND    rl.rule_information_category = 'LAASTX'
1902       AND    NVL(rl.rule_information11,'BILLED') = 'BILLED'
1903       UNION ALL
1904       SELECT NVL(tax_amt,0) tax_amt,
1905              NVL(taxable_amt,0) taxable_amt,
1906              tax_rate_code
1907       FROM   okl_tax_sources txs,
1908              okl_tax_trx_details txl
1909       WHERE  txs.khr_id = p_khr_id
1910       AND    txs.kle_id IS NULL
1911       AND    txs.trx_id = p_trx_id
1912       AND    txs.tax_line_status_code = 'ACTIVE'
1913       AND    txs.tax_call_type_code = 'UPFRONT_TAX'
1914       AND    txl.txs_id = txs.id
1915     )
1916     GROUP BY tax_rate_code;
1917 
1918     CURSOR tax_details_line2_csr(p_khr_id IN NUMBER,
1919                                  p_trx_id IN NUMBER) IS
1920     SELECT SUM(NVL(tax_amt,0)) tax_amt,
1921            SUM(NVL(taxable_amt,0)) taxable_amt,
1922            tax_rate_code
1923     FROM
1924     (
1925       SELECT NVL(tax_amt,0) tax_amt,
1926              NVL(taxable_amt,0) taxable_amt,
1927              tax_rate_code
1928       FROM   okl_tax_sources txs,
1929              okl_tax_trx_details txl,
1930              okc_rule_groups_b rg,
1931              okc_rules_b rl
1932       WHERE  txs.khr_id = p_khr_id
1933       AND    txs.trx_id = p_trx_id
1934       AND    txs.tax_line_status_code = 'ACTIVE'
1935       AND    txs.tax_call_type_code = 'UPFRONT_TAX'
1936       AND    txl.txs_id = txs.id
1937       AND    rg.dnz_chr_id = txs.khr_id
1938       AND    rg.cle_id = txs.kle_id
1939       AND    rg.rgd_code = 'LAASTX'
1940       AND    rl.rgp_id = rg.id
1941       AND    rl.dnz_chr_id = txs.khr_id
1942       AND    rl.rule_information_category = 'LAASTX'
1943       AND    rl.rule_information11 = 'BILLED'
1944       UNION ALL
1945       SELECT NVL(tax_amt,0) tax_amt,
1946              NVL(taxable_amt,0) taxable_amt,
1947              tax_rate_code
1948       FROM   okl_tax_sources txs,
1949              okl_tax_trx_details txl
1950       WHERE  txs.khr_id = p_khr_id
1951       AND    txs.kle_id IS NULL
1952       AND    txs.trx_id = p_trx_id
1953       AND    txs.tax_line_status_code = 'ACTIVE'
1954       AND    txs.tax_call_type_code = 'UPFRONT_TAX'
1955       AND    txl.txs_id = txs.id
1956     )
1957     GROUP BY tax_rate_code;
1958 
1959     l_ttdv_count NUMBER;
1960     --Bug# 4488818: Changes for Upfront Tax Billing: End
1961 
1962     --Bug# 4488818: Changes for Rollover, Release Billing: Start
1963 
1964     CURSOR trx_type_csr(p_id NUMBER, p_language VARCHAR2) IS
1965     SELECT name
1966     FROM   okl_trx_types_tl
1967     WHERE  id = p_id
1968     AND    language = p_language;
1969 
1970     trx_type_rec trx_type_csr%ROWTYPE;
1971     l_orig_try_id okl_trx_types_tl.id%TYPE;
1972 
1973     CURSOR orig_billing_csr(p_orig_qte_id        NUMBER,
1974                             p_orig_quote_line_id NUMBER,
1975                             p_orig_try_id        NUMBER)
1976     IS
1977     SELECT til.tai_id orig_tai_id,
1978            til.id orig_til_id
1979     FROM  okl_trx_ar_invoices_b tai,
1980           okl_txl_ar_inv_lns_b til
1981     WHERE tai.qte_id = p_orig_qte_id
1982     AND   tai.try_id = p_orig_try_id
1983     AND   til.tai_id = tai.id
1984     AND   til.qte_line_id = p_orig_quote_line_id;
1985 
1986     CURSOR orig_txs_csr(p_orig_trx_id        NUMBER,
1987                         p_orig_trx_line_id   NUMBER)
1988     IS
1989     SELECT txs.id,
1990            txs.khr_id,
1991            txs.kle_id,
1992            txs.line_name,
1993            txs.trx_id,
1994            txs.trx_line_id,
1995            txs.entity_code,
1996            txs.event_class_code,
1997            txs.trx_level_type,
1998            txs.adjusted_doc_entity_code,
1999            txs.adjusted_doc_event_class_code,
2000            txs.adjusted_doc_trx_id,
2001            txs.adjusted_doc_trx_line_id,
2002            txs.adjusted_doc_trx_level_type,
2003            txs.adjusted_doc_number,
2004            txs.adjusted_doc_date,
2005            txs.tax_call_type_code,
2006            txs.sty_id,
2007            txs.trx_business_category,
2008            txs.tax_line_status_code,
2009            txs.sel_id,
2010 	   -- Modified by dcshanmu for eBTax - modification starts
2011            txs.tax_reporting_flag,
2012            txs.application_id,
2013            txs.default_taxation_country,
2014            txs.product_category,
2015            txs.user_defined_fisc_class,
2016            txs.line_intended_use,
2017            txs.inventory_item_id,
2018            txs.bill_to_cust_acct_id,
2019            txs.org_id,
2020            txs.legal_entity_id,
2021            txs.line_amt,
2022            txs.assessable_value,
2023            txs.total_tax,
2024            txs.product_type,
2025            txs.product_fisc_classification,
2026            txs.trx_date,
2027            txs.provnl_tax_determination_date,
2028            txs.try_id,
2029            txs.ship_to_location_id,
2030            txs.ship_from_location_id,
2031            txs.trx_currency_code,
2032            txs.currency_conversion_type,
2033            txs.currency_conversion_rate,
2034            txs.currency_conversion_date
2035 	   -- Modified by dcshanmu for eBTax - modification end
2036     FROM  okl_tax_sources txs
2037     WHERE txs.trx_id = p_orig_trx_id
2038     AND txs.trx_line_id =p_orig_trx_line_id;
2039 
2040     CURSOR orig_ttd_csr(p_orig_txs_id        NUMBER)
2041     IS
2042     SELECT  ttd.txs_id,
2043             ttd.tax_determine_date,
2044             ttd.tax_rate_id,
2045             ttd.tax_rate_code,
2046             ttd.taxable_amt,
2047             ttd.tax_exemption_id,
2048             ttd.tax_rate,
2049             ttd.tax_amt,
2050             ttd.billed_yn,
2051 	    -- Modified by dcshanmu for eBTax - modification starts
2052             ttd.tax_call_type_code,
2053             ttd.tax_date,
2054             ttd.line_amt,
2055             ttd.internal_organization_id,
2056             ttd.application_id,
2057             ttd.entity_code,
2058             ttd.event_class_code,
2059             ttd.event_type_code,
2060             ttd.trx_id,
2061             ttd.trx_line_id,
2062             ttd.trx_level_type,
2063             ttd.trx_line_number,
2064             ttd.tax_line_number,
2065             ttd.tax_regime_id,
2066             ttd.tax_regime_code,
2067             ttd.tax_id,
2068             ttd.tax,
2069             ttd.tax_status_id,
2070             ttd.tax_status_code,
2071             ttd.tax_apportionment_line_number,
2072             ttd.legal_entity_id,
2073             ttd.trx_number,
2074             ttd.trx_date,
2075             ttd.tax_jurisdiction_id,
2076             ttd.tax_jurisdiction_code,
2077             ttd.tax_type_code,
2078             ttd.tax_currency_code,
2079             ttd.taxable_amt_tax_curr,
2080             ttd.trx_currency_code,
2081             ttd.minimum_accountable_unit,
2082             ttd.precision,
2083             ttd.currency_conversion_type,
2084             ttd.currency_conversion_rate,
2085             ttd.currency_conversion_date
2086 	    -- Modified by dcshanmu for eBTax - modification end
2087     FROM  okl_tax_trx_details ttd
2088     WHERE ttd.txs_id = p_orig_txs_id;
2089 
2090     --Bug# 4488818: Changes for Rollover, Release Billing: End
2091 
2092     --Bug# 4488818: Changes for Credit Memo processing: Start
2093 
2094     CURSOR orig_til_csr(p_til_id NUMBER)
2095     IS
2096     SELECT til.amount,
2097            til.tai_id
2098     FROM   okl_txl_ar_inv_lns_b til
2099     WHERE  til.id = p_til_id;
2100 
2101     CURSOR orig_tld_csr(p_tld_id NUMBER)
2102     IS
2103     SELECT tld.amount,
2104            til.tai_id
2105     FROM   okl_txd_ar_ln_dtls_b  tld,
2106            okl_txl_ar_inv_lns_b  til
2107     WHERE  tld.id = p_tld_id
2108     AND    til.id = tld.til_id_details;
2109 
2110     orig_til_tld_rec orig_til_csr%ROWTYPE;
2111 
2112     l_cm_ratio       NUMBER;
2113     l_taxable_amount NUMBER;
2114     l_tax_amount     NUMBER;
2115 
2116     --Bug# 4488818: Changes for Credit Memo processing: End
2117 
2118     --Bug# 4622963: Changes for Mass Rebook: Start
2119     CURSOR  l_chk_mass_rbk_csr (p_chr_id IN NUMBER,
2120                                 p_trx_id IN NUMBER) IS
2121     SELECT '!'
2122     FROM   okl_trx_contracts ktrx
2123     WHERE  ktrx.khr_id     = p_chr_id
2124     AND    ktrx.id         = p_trx_id
2125     AND    ktrx.tsu_code   = 'ENTERED'
2126     AND    ktrx.rbr_code   IS NOT NULL
2127     AND    ktrx.tcn_type   = 'TRBK'
2128     AND    EXISTS (SELECT '1'
2129                    FROM   okl_rbk_selected_contract rbk_khr
2130                    WHERE  rbk_khr.khr_id = ktrx.khr_id
2131                    AND    rbk_khr.status <> 'PROCESSED');
2132 
2133    l_mass_rbk_khr  VARCHAR2(1);
2134 
2135    CURSOR tax_details_line3_csr(p_khr_id IN NUMBER,
2136                                 p_trx_id IN NUMBER) IS
2137    SELECT NVL(tax_amt,0) tax_amt,
2138           NVL(taxable_amt,0) taxable_amt,
2139           tax_rate_code
2140    FROM   okl_tax_sources txs,
2141           okl_tax_trx_details txl
2142    WHERE  txs.khr_id = p_khr_id
2143    AND    txs.trx_id = p_trx_id
2144    AND    txs.tax_line_status_code = 'ACTIVE'
2145    AND    txs.tax_call_type_code = 'UPFRONT_TAX'
2146    AND    txl.txs_id = txs.id
2147    GROUP BY tax_rate_code;
2148    --Bug# 4622963: Changes for Mass Rebook: End
2149   --akrangan ebtax  billing imapcts ends
2150   */
2151 BEGIN
2152 
2153   IF p_bpd_acc_rec.source_table = 'OKL_TXD_AR_LN_DTLS_B' THEN
2154     OPEN l_acc_dtls_csr(p_bpd_acc_rec.id);
2155     FETCH l_acc_dtls_csr INTO l_acct_call_rec;
2156       --l_found := l_acc_dtls_csr%FOUND;
2157       --dbms_output.put_line('RECORD: '||l_acct_call_rec.line_id);
2158     CLOSE l_acc_dtls_csr;
2159   ELSE
2160     OPEN l_acc_lines_csr(p_bpd_acc_rec.id);
2161     FETCH l_acc_lines_csr INTO l_acct_call_rec;
2162     --l_found := l_acc_lines_csr%FOUND;
2163     --  dbms_output.put_line('RECORD: '||l_acct_call_rec.line_id);
2164     CLOSE l_acc_lines_csr;
2165   END IF;
2166 
2167   -- Bug# 4488818: Changes for Upfront Sales Tax
2168   -- Tax Only invoices to be created for Upfront Sales Tax
2169   -- are indentified by Zero Line Amounts
2170   IF (NVL(l_acct_call_rec.line_amount,0) <> 0 ) THEN
2171 
2172   --Start code added by pgomes on 11/22/2002
2173   --get contract currency parameters
2174   l_khr_id := l_acct_call_rec.khr_id;
2175 
2176   l_currency_code := null;
2177   l_currency_conversion_type := null;
2178   l_currency_conversion_rate := null;
2179   l_currency_conversion_date := null;
2180 
2181   FOR cur IN l_curr_conv_csr(l_khr_id) LOOP
2182          l_currency_code := cur.currency_code;
2183          l_currency_conversion_type := cur.currency_conversion_type;
2184          l_currency_conversion_rate := cur.currency_conversion_rate;
2185          l_currency_conversion_date := cur.currency_conversion_date;
2186   END LOOP;
2187   --End code added by pgomes on 11/22/2002
2188 
2189 
2190   -- Populate Records for Accounting Call.
2191   l_tmpl_identify_rec.PRODUCT_ID             := l_acct_call_rec.pdt_id;
2192 
2193   -- Changes for bug 3431579
2194   IF l_acct_call_rec.line_amount > 0 THEN
2195     l_tmpl_identify_rec.TRANSACTION_TYPE_ID := get_trx_type ('Billing', 'US');
2196 	l_trx_name :=  'Billing';
2197   ELSE
2198     l_tmpl_identify_rec.TRANSACTION_TYPE_ID := get_trx_type ('Credit Memo', 'US');
2199 	l_trx_name :=  'Credit Memo';
2200   END IF;
2201 
2202   -- Changes for bug 4228207
2203   IF l_acct_call_rec.qte_id IS NOT NULL THEN
2204       IF l_acct_call_rec.try_id IS NOT NULL THEN
2205         l_tmpl_identify_rec.TRANSACTION_TYPE_ID
2206                                              := l_acct_call_rec.try_id;
2207       END IF;
2208   END IF;
2209 
2210   l_tmpl_identify_rec.STREAM_TYPE_ID         := l_acct_call_rec.sty_id;
2211   l_tmpl_identify_rec.ADVANCE_ARREARS        := NULL;
2212   l_tmpl_identify_rec.FACTORING_SYND_FLAG    := NULL;
2213   l_tmpl_identify_rec.SYNDICATION_CODE       := NULL;
2214   l_tmpl_identify_rec.FACTORING_CODE         := NULL;
2215   l_tmpl_identify_rec.MEMO_YN                := 'N';
2216 
2217   -- Start Bug 4622198
2218   Okl_Securitization_Pvt.check_khr_ia_associated(p_api_version    => p_api_version
2219                                                 ,p_init_msg_list  => p_init_msg_list
2220                                                 ,x_return_status  => x_return_status
2221                                                 ,x_msg_count      => x_msg_count
2222                                                 ,x_msg_data       => x_msg_data
2223                                                 ,p_khr_id         => l_acct_call_rec.khr_id
2224                                                 ,p_scs_code       => NULL
2225                                                 ,p_trx_date       => l_acct_call_rec.date_invoiced
2226                                                 ,x_fact_synd_code => l_tmpl_identify_rec.FACTORING_SYND_FLAG
2227                                                 ,x_inv_acct_code  => l_tmpl_identify_rec.INVESTOR_CODE);
2228   -- End Bug 4622198
2229 
2230   --Start code changes for rev rec by fmiao on 10/05/2004
2231   OPEN l_get_accrual_csr (l_tmpl_identify_rec.STREAM_TYPE_ID);
2232   FETCH l_get_accrual_csr INTO l_rev_rec_basis;
2233   CLOSE l_get_accrual_csr;
2234 
2235   IF (l_rev_rec_basis = 'CASH_RECEIPT' ) THEN
2236     -- bug5046450 Start rseela 03/29/2006
2237    --gkhuntet added for Forward Port Bug#5946084 Start.
2238    -- IF l_acct_call_rec.line_amount >= 0 THEN
2239 	l_tmpl_identify_rec.REV_REC_FLAG           := 'Y';
2240    -- ELSE
2241    --         l_tmpl_identify_rec.REV_REC_FLAG           := 'N';
2242    -- END IF;
2243    --   --gkhuntet added for Forward Port Bug#5946084 End.
2244    -- bug5046450 End rseela 03/29/2006
2245   ELSE
2246 	l_tmpl_identify_rec.REV_REC_FLAG           := 'N';
2247   END IF;
2248   --End code changes for rev rec by fmiao on 10/05/2004
2249 
2250   l_tmpl_identify_rec.PRIOR_YEAR_YN          := 'N';
2251 
2252   l_dist_info_rec.SOURCE_ID                  := l_acct_call_rec.line_id;
2253   l_dist_info_rec.SOURCE_TABLE               := l_acct_call_rec.source_table;
2254   l_dist_info_rec.ACCOUNTING_DATE            := l_acct_call_rec.date_invoiced;
2255   l_dist_info_rec.GL_REVERSAL_FLAG           := 'N';
2256   l_dist_info_rec.POST_TO_GL                 := 'N';
2257 
2258   -- *************************************
2259   -- Get Set of Books and Currency_Code
2260   -- *************************************
2261   l_sob_id := NULL;
2262   l_sob_id := Okl_Accounting_Util.GET_SET_OF_BOOKS_ID;
2263 
2264   l_curr_code := NULL;
2265 
2266   --Start code added by pgomes on 11/22/2002
2267 
2268   --Check for currency code
2269   IF l_acct_call_rec.currency_code IS NULL THEN
2270     l_curr_code := l_currency_code;
2271   ELSE
2272     l_curr_code := l_acct_call_rec.currency_code;
2273   END IF;
2274 
2275   --End code added by pgomes on 11/22/2002
2276 
2277   -- *************************************
2278   -- Rounded Amount
2279   -- *************************************
2280 
2281   --pgomes, 12/06/2002, commented out below code
2282   /*OPEN  l_curr_csr ( l_curr_code );
2283   FETCH l_curr_csr INTO l_min_acct_unit, l_precision;
2284   CLOSE l_curr_csr;
2285 
2286   IF (nvl(l_min_acct_unit,0) <> 0 ) THEN
2287        -- Round the amount to the nearest Min Accountable Unit
2288        l_rounded_amount := ROUND (l_acct_call_rec.line_amount / l_min_acct_unit) * l_min_acct_unit;
2289   ELSE
2290        -- Round the amount to the nearest precision
2291        l_rounded_amount := ROUND (l_acct_call_rec.line_amount, l_precision);
2292   END IF;*/
2293 
2294   --pgomes, 12/06/2002, code for rounding call
2295   l_rounded_amount := okl_accounting_util.cross_currency_round_amount(p_amount => l_acct_call_rec.line_amount,
2296                            p_currency_code => l_curr_code);
2297 
2298 
2299   -- *************************************
2300   -- Rounded Amount
2301   -- *************************************
2302 
2303   l_dist_info_rec.AMOUNT                     := ABS(l_rounded_amount);
2304   l_dist_info_rec.CURRENCY_CODE              := l_curr_code;
2305 
2306   l_dist_info_rec.CURRENCY_CONVERSION_TYPE   := NULL;
2307 
2308   --Start code added by pgomes on 11/22/2002
2309 
2310   --Check for currency conversion type
2311   IF l_acct_call_rec.currency_conversion_type IS NULL THEN
2312       l_dist_info_rec.currency_conversion_type := l_currency_conversion_type;
2313   ELSE
2314       l_dist_info_rec.currency_conversion_type := l_acct_call_rec.currency_conversion_type;
2315   END IF;
2316 
2317 
2318   l_dist_info_rec.CURRENCY_CONVERSION_DATE   := NULL;
2319 
2320   --Check for currency conversion date
2321   IF l_acct_call_rec.currency_conversion_date IS NULL THEN
2322       l_dist_info_rec.currency_conversion_date := l_currency_conversion_date;
2323   ELSE
2324       l_dist_info_rec.currency_conversion_date := l_acct_call_rec.currency_conversion_date;
2325   END IF;
2326 
2327 
2328   --Uncommented the below block of code to handle currency conversion rate
2329   IF (l_dist_info_rec.currency_conversion_type = 'User') THEN
2330     IF (l_dist_info_rec.currency_code = okl_accounting_util.get_func_curr_code) THEN
2331        l_dist_info_rec.currency_conversion_rate := 1;
2332     ELSE
2333       IF l_acct_call_rec.currency_conversion_rate IS NULL THEN
2334         l_dist_info_rec.currency_conversion_rate := l_currency_conversion_rate;
2335       ELSE
2336         l_dist_info_rec.currency_conversion_rate := l_acct_call_rec.currency_conversion_rate;
2337       END IF;
2338     END IF;
2339   --pgomes 01/10/2003 added below code to get curr conv rate
2340   ELSIF (l_dist_info_rec.currency_conversion_type = 'Spot' OR l_dist_info_rec.currency_conversion_type = 'Corporate') THEN
2341     l_dist_info_rec.currency_conversion_rate := okl_accounting_util.get_curr_con_rate
2342                                                 (p_from_curr_code => l_dist_info_rec.currency_code,
2343 	                                         p_to_curr_code => okl_accounting_util.get_func_curr_code,
2344 	                                         p_con_date => l_dist_info_rec.currency_conversion_date,
2345 	                                         p_con_type => l_dist_info_rec.currency_conversion_type);
2346   END IF;
2347 
2348   --pgomes 01/10/2003 added below code to default rate so that acct dist are created
2349   l_dist_info_rec.currency_conversion_rate := NVL(l_dist_info_rec.currency_conversion_rate, 1);
2350 
2351   --End code added by pgomes on 11/22/2002
2352 
2353   l_dist_info_rec.CONTRACT_ID                := NULL;
2354   l_dist_info_rec.CONTRACT_LINE_ID           := NULL;
2355 
2356     p_taiv_rec.id := l_acct_call_rec.header_id;
2357 
2358 
2359     Okl_Populate_Acc_Gen (
2360 	p_contract_id	     => l_acct_call_rec.khr_id,
2361 	p_contract_line_id	=> l_acct_call_rec.kle_id,
2362 	x_acc_gen_tbl		=> l_acc_gen_primary_key_tbl,
2363 	x_return_status		=> x_return_status);
2364 
2365    IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
2366       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
2367    ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
2368       RAISE OKL_API.G_EXCEPTION_ERROR;
2369    END IF;
2370 
2371 -- Start of wraper code generated automatically by Debug code generator for Okl_Account_Dist_Pub.CREATE_ACCOUNTING_DIST
2372   IF(L_DEBUG_ENABLED='Y') THEN
2373     L_LEVEL_PROCEDURE :=FND_LOG.LEVEL_PROCEDURE;
2374     IS_DEBUG_PROCEDURE_ON := OKL_DEBUG_PUB.Check_Log_On(L_MODULE, L_LEVEL_PROCEDURE);
2375   END IF;
2376   IF(IS_DEBUG_PROCEDURE_ON) THEN
2377     BEGIN
2378         OKL_DEBUG_PUB.LOG_DEBUG(L_LEVEL_PROCEDURE,L_MODULE,'Begin Debug OKLRACCB.pls call Okl_Account_Dist_Pub.CREATE_ACCOUNTING_DIST ');
2379     END;
2380   END IF;
2381 
2382 
2383   x_tmpl_identify_rec   := l_tmpl_identify_rec;
2384   x_dist_info_rec       := l_dist_info_rec;
2385   x_ctxt_val_tbl        := l_ctxt_val_tbl;
2386   x_acc_gen_primary_key_tbl := l_acc_gen_primary_key_tbl;
2387 
2388   /* -- Commented by Vpanwar -- for calling this API with new signature from one single time After the call of create_acc_trans_new in loop.
2389     Okl_Account_Dist_Pub.CREATE_ACCOUNTING_DIST(
2390 								   p_api_version             => p_api_version
2391                                   ,p_init_msg_list  		 => p_init_msg_list
2392                                   ,x_return_status  		 => x_return_status
2393                                   ,x_msg_count      		 => x_msg_count
2394                                   ,x_msg_data       		 => x_msg_data
2395                                   ,p_tmpl_identify_rec 		 => l_tmpl_identify_rec
2396                                   ,p_dist_info_rec           => l_dist_info_rec
2397                                   ,p_ctxt_val_tbl            => l_ctxt_val_tbl
2398                                   ,p_acc_gen_primary_key_tbl => l_acc_gen_primary_key_tbl
2399                                   ,x_template_tbl            => l_template_tbl
2400                                   ,x_amount_tbl              => l_amount_tbl);
2401 
2402     IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
2403       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
2404     ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
2405       RAISE OKL_API.G_EXCEPTION_ERROR;
2406     END IF;
2407 */
2408   IF(IS_DEBUG_PROCEDURE_ON) THEN
2409     BEGIN
2410         OKL_DEBUG_PUB.LOG_DEBUG(L_LEVEL_PROCEDURE,L_MODULE,'End Debug OKLRACCB.pls call Okl_Account_Dist_Pub.CREATE_ACCOUNTING_DIST ');
2411     END;
2412   END IF;
2413 -- End of wraper code generated automatically by Debug code generator for Okl_Account_Dist_Pub.CREATE_ACCOUNTING_DIST
2414 
2415 	--Start code changes for rev rec by fmiao on 10/05/2004
2416 	--rseela..bug# 5046450..added AND clause to check for 4 dists only for Billing txns and not CMs
2417         /*  -- Bug 6441837
2418 	IF (l_rev_rec_basis = 'CASH_RECEIPT'  AND l_acct_call_rec.line_amount > 0) THEN
2419 	   -- stmathew bug#4547180 / 4573599 start
2420 	   OPEN l_dstrs_count_csr(l_dist_info_rec.SOURCE_ID, l_dist_info_rec.SOURCE_TABLE);
2421 	   -- stmathew bug#4547180 / 4573599 end
2422 	   FETCH l_dstrs_count_csr INTO l_count;
2423 	   CLOSE l_dstrs_count_csr;
2424 	   IF (l_count < 4) THEN
2425 	   	  x_return_status := Okl_Api.G_RET_STS_ERROR;
2426    	   END IF;
2427 	END IF;
2428 	--End code changes for rev rec by fmiao on 10/05/2004
2429 
2430       IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
2431         RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
2432       ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
2433         RAISE OKL_API.G_EXCEPTION_ERROR;
2434       END IF; */
2435 
2436     /*IF x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR THEN
2437          NULL;
2438        	 --RAISE G_EXCEPTION_HALT_VALIDATION;
2439     ELSE
2440       IF x_return_status <> Okl_Api.G_RET_STS_SUCCESS THEN
2441          l_return_status := x_return_status;
2442       END IF;
2443     END IF;
2444 
2445     IF x_return_status <> Okl_Api.G_RET_STS_SUCCESS THEN
2446 	   p_taiv_rec.trx_status_code := 'ERROR';
2447 	ELSE
2448 	   p_taiv_rec.trx_status_code := 'SUBMITTED';
2449 	END IF;*/
2450 /*
2451 	Okl_Tai_Pvt.update_row(
2452     p_api_version              =>    p_api_version,
2453     p_init_msg_list            =>    p_init_msg_list,
2454     x_return_status            =>    x_return_status,
2455     x_msg_count                =>    x_msg_count,
2456     x_msg_data                 =>    x_msg_data,
2457     p_taiv_rec                 =>    p_taiv_rec,
2458     x_taiv_rec                 =>    x_taiv_rec);
2459 */
2460 --akrangan ebtax billing impacts start here
2461   /**
2462   --Bug# 4488818: Changes for Rollover, Release Billing: Start
2463   OPEN trx_type_csr(p_id => l_acct_call_rec.try_id,
2464                     p_language => 'US');
2465   FETCH trx_type_csr INTO trx_type_rec;
2466   CLOSE trx_type_csr;
2467   */
2468   --akrangan ebtax billing impacts end here
2469 
2470 --ebtax impact on billing akrangan commented code starts here
2471 /*
2472   IF trx_type_rec.name IN ('Rollover Billing'    , 'Release Billing',
2473                            'Rollover Credit Memo', 'Release Credit Memo') THEN
2474 
2475     IF trx_type_rec.name IN ('Rollover Billing', 'Release Billing') THEN
2476       l_orig_try_id := get_trx_type ('Billing', 'US');
2477 
2478     ELSIF trx_type_rec.name IN ('Rollover Credit Memo', 'Release Credit Memo') THEN
2479       l_orig_try_id := get_trx_type ('Credit Memo', 'US');
2480 
2481     END IF;
2482 -- akrangan billing impact on ebtax start
2483     FOR orig_billing_rec IN orig_billing_csr(p_orig_qte_id  => l_acct_call_rec.qte_id,
2484                                              p_orig_quote_line_id => l_acct_call_rec.qte_line_id,
2485                                              p_orig_try_id  => l_orig_try_id)
2486     LOOP
2487 --tax cursor
2488       FOR orig_txs_rec IN orig_txs_csr(p_orig_trx_id       => orig_billing_rec.orig_tai_id,
2489                                        p_orig_trx_line_id  => orig_billing_rec.orig_til_id)
2490       LOOP
2491 
2492         -- Populate Tax Sources Record
2493 
2494         lp_txsv_rec.khr_id                        := orig_txs_rec.khr_id;
2495         lp_txsv_rec.kle_id                        := orig_txs_rec.kle_id;
2496         lp_txsv_rec.asset_number                  := orig_txs_rec.line_name;
2497         lp_txsv_rec.trx_id                        := l_acct_call_rec.header_id;
2498         lp_txsv_rec.trx_line_id                   := l_acct_call_rec.line_id;
2499         lp_txsv_rec.entity_code                   := orig_txs_rec.entity_code;
2500         lp_txsv_rec.event_class_code              := orig_txs_rec.event_class_code;
2501         lp_txsv_rec.trx_level_type                := orig_txs_rec.trx_level_type;
2502         lp_txsv_rec.adjusted_doc_entity_code      := orig_txs_rec.adjusted_doc_entity_code;
2503         lp_txsv_rec.adjusted_doc_event_class_code := orig_txs_rec.adjusted_doc_event_class_code;
2504         lp_txsv_rec.adjusted_doc_trx_id           := orig_txs_rec.adjusted_doc_trx_id;
2505         lp_txsv_rec.adjusted_doc_trx_line_id      := orig_txs_rec.adjusted_doc_trx_line_id;
2506         lp_txsv_rec.adjusted_doc_trx_level_type   := orig_txs_rec.adjusted_doc_trx_level_type;
2507         lp_txsv_rec.adjusted_doc_number           := orig_txs_rec.adjusted_doc_number;
2508         lp_txsv_rec.adjusted_doc_date             := orig_txs_rec.adjusted_doc_date;
2509         lp_txsv_rec.tax_call_type_code            := orig_txs_rec.tax_call_type_code;
2510         lp_txsv_rec.sty_id                        := orig_txs_rec.sty_id;
2511         lp_txsv_rec.trx_business_category         := orig_txs_rec.trx_business_category;
2512         lp_txsv_rec.tax_line_status_code          := orig_txs_rec.tax_line_status_code;
2513         lp_txsv_rec.sel_id                        := orig_txs_rec.sel_id;
2514         lp_txsv_rec.reported_yn                   := orig_txs_rec.tax_reporting_flag;
2515 	-- Modified by dcshanmu for eBTax - modification starts
2516         lp_txsv_rec.application_id := orig_txs_rec.application_id;
2517         lp_txsv_rec.default_taxation_country := orig_txs_rec.default_taxation_country;
2518         lp_txsv_rec.product_category := orig_txs_rec.product_category;
2519         lp_txsv_rec.user_defined_fisc_class := orig_txs_rec.user_defined_fisc_class;
2520         lp_txsv_rec.line_intended_use := orig_txs_rec.line_intended_use;
2521         lp_txsv_rec.inventory_item_id := orig_txs_rec.inventory_item_id;
2522         lp_txsv_rec.bill_to_cust_acct_id := orig_txs_rec.bill_to_cust_acct_id;
2523         lp_txsv_rec.org_id := orig_txs_rec.org_id;
2524         lp_txsv_rec.legal_entity_id := orig_txs_rec.legal_entity_id;
2525         lp_txsv_rec.line_amt := orig_txs_rec.line_amt;
2526         lp_txsv_rec.assessable_value := orig_txs_rec.assessable_value;
2527         lp_txsv_rec.total_tax := orig_txs_rec.total_tax;
2528         lp_txsv_rec.product_type := orig_txs_rec.product_type;
2529         lp_txsv_rec.product_fisc_classification := orig_txs_rec.product_fisc_classification;
2530         lp_txsv_rec.trx_date := orig_txs_rec.trx_date;
2531         lp_txsv_rec.provnl_tax_determination_date := orig_txs_rec.provnl_tax_determination_date;
2532         lp_txsv_rec.try_id := orig_txs_rec.try_id;
2533         lp_txsv_rec.ship_to_location_id := orig_txs_rec.ship_to_location_id;
2534         lp_txsv_rec.ship_from_location_id := orig_txs_rec.ship_from_location_id;
2535         lp_txsv_rec.trx_currency_code := orig_txs_rec.trx_currency_code;
2536         lp_txsv_rec.currency_conversion_type := orig_txs_rec.currency_conversion_type;
2537         lp_txsv_rec.currency_conversion_rate := orig_txs_rec.currency_conversion_rate;
2538         lp_txsv_rec.currency_conversion_date := orig_txs_rec.currency_conversion_date;
2539 	-- Modified by dcshanmu for eBTax - modification end
2540 
2541         IF(IS_DEBUG_PROCEDURE_ON) THEN
2542           BEGIN
2543             OKL_DEBUG_PUB.LOG_DEBUG(L_LEVEL_PROCEDURE,L_MODULE,'Begin Debug OKLRACCB.pls call OKL_TAX_SOURCES_PUB.insert_tax_sources ');
2544           END;
2545         END IF;
2546 
2547         -- Create Tax Sources Record
2548         OKL_TAX_SOURCES_PUB.insert_tax_sources(
2549           p_api_version    => p_api_version,
2550           p_init_msg_list  => p_init_msg_list,
2551           x_return_status  => x_return_status,
2552           x_msg_count      => x_msg_count,
2553           x_msg_data       => x_msg_data,
2554           p_txsv_rec       => lp_txsv_rec,
2555           x_txsv_rec       => lx_txsv_rec);
2556 
2557         IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
2558            RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
2559         ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
2560            RAISE OKL_API.G_EXCEPTION_ERROR;
2561         END IF;
2562 
2563         IF(IS_DEBUG_PROCEDURE_ON) THEN
2564           BEGIN
2565             OKL_DEBUG_PUB.LOG_DEBUG(L_LEVEL_PROCEDURE,L_MODULE,'End Debug OKLRACCB.pls call OKL_TAX_SOURCES_PUB.insert_tax_sources ');
2566           END;
2567         END IF;
2568 
2569         -- Populate Tax Details Record
2570         l_ttdv_count := 0;
2571 
2572         FOR orig_ttd_rec IN orig_ttd_csr(p_orig_txs_id => orig_txs_rec.id)
2573         LOOP
2574           l_ttdv_count :=  l_ttdv_count + 1;
2575           lp_ttdv_tbl(l_ttdv_count).txs_id                 := lx_txsv_rec.id;
2576           lp_ttdv_tbl(l_ttdv_count).tax_determine_date := orig_ttd_rec.tax_determine_date;
2577           lp_ttdv_tbl(l_ttdv_count).tax_rate_id            := orig_ttd_rec.tax_rate_id;
2578           lp_ttdv_tbl(l_ttdv_count).tax_rate_code          := orig_ttd_rec.tax_rate_code;
2579           lp_ttdv_tbl(l_ttdv_count).taxable_amt         := (-1 * orig_ttd_rec.taxable_amt);
2580           lp_ttdv_tbl(l_ttdv_count).tax_exemption_id       := orig_ttd_rec.tax_exemption_id;
2581           lp_ttdv_tbl(l_ttdv_count).tax_rate               := orig_ttd_rec.tax_rate;
2582           lp_ttdv_tbl(l_ttdv_count).tax_amt             := (-1 * orig_ttd_rec.tax_amt);
2583           lp_ttdv_tbl(l_ttdv_count).billed_yn              := orig_ttd_rec.billed_yn;
2584           lp_ttdv_tbl(l_ttdv_count).tax_call_type_code     := orig_ttd_rec.tax_call_type_code;
2585 	  -- Modified by dcshanmu for eBTax - modification starts
2586           lp_ttdv_tbl(l_ttdv_count).tax_date	:= orig_ttd_rec.tax_date;
2587           lp_ttdv_tbl(l_ttdv_count).line_amt	:= orig_ttd_rec.line_amt;
2588           lp_ttdv_tbl(l_ttdv_count).internal_organization_id               	:= orig_ttd_rec.internal_organization_id;
2589           lp_ttdv_tbl(l_ttdv_count).application_id                         	:= orig_ttd_rec.application_id;
2590           lp_ttdv_tbl(l_ttdv_count).entity_code                            	:= orig_ttd_rec.entity_code;
2591           lp_ttdv_tbl(l_ttdv_count).event_class_code                       	:= orig_ttd_rec.event_class_code;
2592           lp_ttdv_tbl(l_ttdv_count).event_type_code                        	:= orig_ttd_rec.event_type_code;
2593           lp_ttdv_tbl(l_ttdv_count).trx_id                                 	:= orig_ttd_rec.trx_id;
2594           lp_ttdv_tbl(l_ttdv_count).trx_line_id                            	:= orig_ttd_rec.trx_line_id;
2595           lp_ttdv_tbl(l_ttdv_count).trx_level_type                         	:= orig_ttd_rec.trx_level_type;
2596           lp_ttdv_tbl(l_ttdv_count).trx_line_number                        	:= orig_ttd_rec.trx_line_number;
2597           lp_ttdv_tbl(l_ttdv_count).tax_line_number                        	:= orig_ttd_rec.tax_line_number;
2598           lp_ttdv_tbl(l_ttdv_count).tax_regime_id                          	:= orig_ttd_rec.tax_regime_id;
2599           lp_ttdv_tbl(l_ttdv_count).tax_regime_code                        	:= orig_ttd_rec.tax_regime_code;
2600           lp_ttdv_tbl(l_ttdv_count).tax_id                                 	:= orig_ttd_rec.tax_id;
2601           lp_ttdv_tbl(l_ttdv_count).tax                                    	:= orig_ttd_rec.tax;
2602           lp_ttdv_tbl(l_ttdv_count).tax_status_id                          	:= orig_ttd_rec.tax_status_id;
2603           lp_ttdv_tbl(l_ttdv_count).tax_status_code                        	:= orig_ttd_rec.tax_status_code;
2604           lp_ttdv_tbl(l_ttdv_count).tax_apportionment_line_number          	:= orig_ttd_rec.tax_apportionment_line_number;
2605           lp_ttdv_tbl(l_ttdv_count).legal_entity_id                        	:= orig_ttd_rec.legal_entity_id;
2606           lp_ttdv_tbl(l_ttdv_count).trx_number                             	:= orig_ttd_rec.trx_number;
2607           lp_ttdv_tbl(l_ttdv_count).trx_date                               	:= orig_ttd_rec.trx_date;
2608           lp_ttdv_tbl(l_ttdv_count).tax_jurisdiction_id                    	:= orig_ttd_rec.tax_jurisdiction_id;
2609           lp_ttdv_tbl(l_ttdv_count).tax_jurisdiction_code                  	:= orig_ttd_rec.tax_jurisdiction_code;
2610           lp_ttdv_tbl(l_ttdv_count).tax_type_code                          	:= orig_ttd_rec.tax_type_code;
2611           lp_ttdv_tbl(l_ttdv_count).tax_currency_code                      	:= orig_ttd_rec.tax_currency_code;
2612           lp_ttdv_tbl(l_ttdv_count).taxable_amt_tax_curr                   	:= orig_ttd_rec.taxable_amt_tax_curr;
2613           lp_ttdv_tbl(l_ttdv_count).trx_currency_code                      	:= orig_ttd_rec.trx_currency_code;
2614           lp_ttdv_tbl(l_ttdv_count).minimum_accountable_unit               	:= orig_ttd_rec.minimum_accountable_unit;
2615           lp_ttdv_tbl(l_ttdv_count).precision                              	:= orig_ttd_rec.precision;
2616           lp_ttdv_tbl(l_ttdv_count).currency_conversion_type               	:= orig_ttd_rec.currency_conversion_type;
2617           lp_ttdv_tbl(l_ttdv_count).currency_conversion_rate               	:= orig_ttd_rec.currency_conversion_rate;
2618           lp_ttdv_tbl(l_ttdv_count).currency_conversion_date               	:= orig_ttd_rec.currency_conversion_date;
2619 	  -- Modified by dcshanmu for eBTax - modification end
2620         END LOOP;
2621 
2622         IF(IS_DEBUG_PROCEDURE_ON) THEN
2623           BEGIN
2624             OKL_DEBUG_PUB.LOG_DEBUG(L_LEVEL_PROCEDURE,L_MODULE,'Begin Debug OKLRACCB.pls call OKL_TAX_TRX_DETAILS_PUB.insert_tax_trx_details ');
2625           END;
2626         END IF;
2627 
2628         -- Create Tax Details Record
2629         OKL_TAX_TRX_DETAILS_PUB.insert_tax_trx_details(
2630           p_api_version    => p_api_version,
2631           p_init_msg_list  => p_init_msg_list,
2632           x_return_status  => x_return_status,
2633           x_msg_count      => x_msg_count,
2634           x_msg_data       => x_msg_data,
2635           p_ttdv_tbl       => lp_ttdv_tbl,
2636           x_ttdv_tbl       => lx_ttdv_tbl);
2637 
2638         IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
2639            RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
2640         ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
2641            RAISE OKL_API.G_EXCEPTION_ERROR;
2642         END IF;
2643 
2644         IF(IS_DEBUG_PROCEDURE_ON) THEN
2645           BEGIN
2646             OKL_DEBUG_PUB.LOG_DEBUG(L_LEVEL_PROCEDURE,L_MODULE,'End Debug OKLRACCB.pls call OKL_TAX_TRX_DETAILS_PUB.insert_tax_trx_details ');
2647           END;
2648         END IF;
2649 
2650       END LOOP;
2651     END LOOP;
2652 
2653   ELSE
2654     -- Tax processing for Invoice and on-account Credit Memo
2655     IF l_acct_call_rec.tld_id_reverses IS NULL THEN
2656 
2657       --Start code changes for Tax API call by varao on 05/04/2005
2658       IF(IS_DEBUG_PROCEDURE_ON) THEN
2659         BEGIN
2660           OKL_DEBUG_PUB.LOG_DEBUG(L_LEVEL_PROCEDURE,L_MODULE,'Begin Debug OKLRACCB.pls call OKL_PROCESS_SALES_TAX_PUB.calculate_sales_tax ');
2661         END;
2662       END IF;
2663       -- Call the Tax API for Invoice and on-account Credit Memo
2664 
2665       OKL_PROCESS_SALES_TAX_PVT.calculate_sales_tax(
2666                           p_api_version             => p_api_version,
2667                           p_init_msg_list  		    => p_init_msg_list,
2668                           x_return_status  		    => x_return_status,
2669                           x_msg_count      		    => x_msg_count,
2670                           x_msg_data       		    => x_msg_data,
2671                           p_source_trx_id       	=> p_bpd_acc_rec.id,
2672                           p_source_trx_name        	=> l_trx_name,
2673                           p_source_table       		=> p_bpd_acc_rec.source_table);
2674 
2675       IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
2676          RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
2677       ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
2678          RAISE OKL_API.G_EXCEPTION_ERROR;
2679       END IF;
2680 
2681       IF(IS_DEBUG_PROCEDURE_ON) THEN
2682         BEGIN
2683           OKL_DEBUG_PUB.LOG_DEBUG(L_LEVEL_PROCEDURE,L_MODULE,'End Debug OKLRACCB.pls call OKL_PROCESS_SALES_TAX_PUB.calculate_sales_tax ');
2684         END;
2685       END IF;
2686 
2687     --Bug# 4488818: Tax Processing for Invoice Based Credit Memo
2688     ELSE
2689 
2690       IF l_acct_call_rec.source_table = 'OKL_TXL_AR_INV_LNS_B' THEN
2691         OPEN orig_til_csr(p_til_id => l_acct_call_rec.tld_id_reverses);
2692         FETCH orig_til_csr INTO orig_til_tld_rec;
2693         CLOSE orig_til_csr;
2694       ELSIF l_acct_call_rec.source_table = 'OKL_TXD_AR_LN_DTLS_B' THEN
2695         OPEN orig_tld_csr(p_tld_id => l_acct_call_rec.tld_id_reverses);
2696         FETCH orig_tld_csr INTO orig_til_tld_rec;
2697         CLOSE orig_tld_csr;
2698       END IF;
2699 
2700       l_cm_ratio := l_acct_call_rec.line_amount/orig_til_tld_rec.amount;
2701 
2702       FOR orig_txs_rec IN orig_txs_csr(p_orig_trx_id       => orig_til_tld_rec.tai_id,
2703                                        p_orig_trx_line_id  => l_acct_call_rec.tld_id_reverses)
2704       LOOP
2705 
2706         -- Populate Tax Sources Record
2707 
2708         lp_txsv_rec.khr_id                        := orig_txs_rec.khr_id;
2709         lp_txsv_rec.kle_id                        := orig_txs_rec.kle_id;
2710         lp_txsv_rec.asset_number                  := orig_txs_rec.line_name;
2711         lp_txsv_rec.trx_id                        := l_acct_call_rec.header_id;
2712         lp_txsv_rec.trx_line_id                   := l_acct_call_rec.line_id;
2713         lp_txsv_rec.entity_code                   := orig_txs_rec.entity_code;
2714         lp_txsv_rec.event_class_code              := orig_txs_rec.event_class_code;
2715         lp_txsv_rec.trx_level_type                := orig_txs_rec.trx_level_type;
2716         lp_txsv_rec.adjusted_doc_entity_code      := orig_txs_rec.adjusted_doc_entity_code;
2717         lp_txsv_rec.adjusted_doc_event_class_code := orig_txs_rec.adjusted_doc_event_class_code;
2718         lp_txsv_rec.adjusted_doc_trx_id           := orig_txs_rec.adjusted_doc_trx_id;
2719         lp_txsv_rec.adjusted_doc_trx_line_id      := orig_txs_rec.adjusted_doc_trx_line_id;
2720         lp_txsv_rec.adjusted_doc_trx_level_type   := orig_txs_rec.adjusted_doc_trx_level_type;
2721         lp_txsv_rec.adjusted_doc_number           := orig_txs_rec.adjusted_doc_number;
2722         lp_txsv_rec.adjusted_doc_date             := orig_txs_rec.adjusted_doc_date;
2723         lp_txsv_rec.tax_call_type_code            := orig_txs_rec.tax_call_type_code;
2724         lp_txsv_rec.sty_id                        := orig_txs_rec.sty_id;
2725         lp_txsv_rec.trx_business_category         := orig_txs_rec.trx_business_category;
2726         lp_txsv_rec.tax_line_status_code          := orig_txs_rec.tax_line_status_code;
2727         lp_txsv_rec.sel_id                        := orig_txs_rec.sel_id;
2728         lp_txsv_rec.reported_yn                   := orig_txs_rec.tax_reporting_flag;
2729 	-- Modified by dcshanmu for eBTax - modification starts
2730         lp_txsv_rec.application_id := orig_txs_rec.application_id;
2731         lp_txsv_rec.default_taxation_country := orig_txs_rec.default_taxation_country;
2732         lp_txsv_rec.product_category := orig_txs_rec.product_category;
2733         lp_txsv_rec.user_defined_fisc_class := orig_txs_rec.user_defined_fisc_class;
2734         lp_txsv_rec.line_intended_use := orig_txs_rec.line_intended_use;
2735         lp_txsv_rec.inventory_item_id := orig_txs_rec.inventory_item_id;
2736         lp_txsv_rec.bill_to_cust_acct_id := orig_txs_rec.bill_to_cust_acct_id;
2737         lp_txsv_rec.org_id := orig_txs_rec.org_id;
2738         lp_txsv_rec.legal_entity_id := orig_txs_rec.legal_entity_id;
2739         lp_txsv_rec.line_amt := orig_txs_rec.line_amt;
2740         lp_txsv_rec.assessable_value := orig_txs_rec.assessable_value;
2741         lp_txsv_rec.total_tax := orig_txs_rec.total_tax;
2742         lp_txsv_rec.product_type := orig_txs_rec.product_type;
2743         lp_txsv_rec.product_fisc_classification := orig_txs_rec.product_fisc_classification;
2744         lp_txsv_rec.trx_date := orig_txs_rec.trx_date;
2745         lp_txsv_rec.provnl_tax_determination_date := orig_txs_rec.provnl_tax_determination_date;
2746         lp_txsv_rec.try_id := orig_txs_rec.try_id;
2747         lp_txsv_rec.ship_to_location_id := orig_txs_rec.ship_to_location_id;
2748         lp_txsv_rec.ship_from_location_id := orig_txs_rec.ship_from_location_id;
2749         lp_txsv_rec.trx_currency_code := orig_txs_rec.trx_currency_code;
2750         lp_txsv_rec.currency_conversion_type := orig_txs_rec.currency_conversion_type;
2751         lp_txsv_rec.currency_conversion_rate := orig_txs_rec.currency_conversion_rate;
2752         lp_txsv_rec.currency_conversion_date := orig_txs_rec.currency_conversion_date;
2753 	-- Modified by dcshanmu for eBTax - modification end
2754 
2755         IF(IS_DEBUG_PROCEDURE_ON) THEN
2756           BEGIN
2757             OKL_DEBUG_PUB.LOG_DEBUG(L_LEVEL_PROCEDURE,L_MODULE,'Begin Debug OKLRACCB.pls call OKL_TAX_SOURCES_PUB.insert_tax_sources ');
2758           END;
2759         END IF;
2760 
2761         -- Create Tax Sources Record
2762         OKL_TAX_SOURCES_PUB.insert_tax_sources(
2763           p_api_version    => p_api_version,
2764           p_init_msg_list  => p_init_msg_list,
2765           x_return_status  => x_return_status,
2766           x_msg_count      => x_msg_count,
2767           x_msg_data       => x_msg_data,
2768           p_txsv_rec       => lp_txsv_rec,
2769           x_txsv_rec       => lx_txsv_rec);
2770 
2771         IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
2772            RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
2773         ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
2774            RAISE OKL_API.G_EXCEPTION_ERROR;
2775         END IF;
2776 
2777         IF(IS_DEBUG_PROCEDURE_ON) THEN
2778           BEGIN
2779             OKL_DEBUG_PUB.LOG_DEBUG(L_LEVEL_PROCEDURE,L_MODULE,'End Debug OKLRACCB.pls call OKL_TAX_SOURCES_PUB.insert_tax_sources ');
2780           END;
2781         END IF;
2782 
2783         -- Populate Tax Details Record
2784         l_ttdv_count := 0;
2785 
2786         FOR orig_ttd_rec IN orig_ttd_csr(p_orig_txs_id => orig_txs_rec.id)
2787         LOOP
2788           l_ttdv_count :=  l_ttdv_count + 1;
2789           lp_ttdv_tbl(l_ttdv_count).txs_id                 := lx_txsv_rec.id;
2790           lp_ttdv_tbl(l_ttdv_count).tax_determine_date := orig_ttd_rec.tax_determine_date;
2791           lp_ttdv_tbl(l_ttdv_count).tax_rate_id            := orig_ttd_rec.tax_rate_id;
2792           lp_ttdv_tbl(l_ttdv_count).tax_rate_code          := orig_ttd_rec.tax_rate_code;
2793           lp_ttdv_tbl(l_ttdv_count).tax_exemption_id       := orig_ttd_rec.tax_exemption_id;
2794           lp_ttdv_tbl(l_ttdv_count).tax_rate               := orig_ttd_rec.tax_rate;
2795           lp_ttdv_tbl(l_ttdv_count).billed_yn              := orig_ttd_rec.billed_yn;
2796           lp_ttdv_tbl(l_ttdv_count).tax_call_type_code     := orig_ttd_rec.tax_call_type_code;
2797 	  -- Modified by dcshanmu for eBTax - modification starts
2798           lp_ttdv_tbl(l_ttdv_count).tax_date	:= orig_ttd_rec.tax_date;
2799           lp_ttdv_tbl(l_ttdv_count).line_amt	:= orig_ttd_rec.line_amt;
2800           lp_ttdv_tbl(l_ttdv_count).internal_organization_id               	:= orig_ttd_rec.internal_organization_id;
2801           lp_ttdv_tbl(l_ttdv_count).application_id                         	:= orig_ttd_rec.application_id;
2802           lp_ttdv_tbl(l_ttdv_count).entity_code                            	:= orig_ttd_rec.entity_code;
2803           lp_ttdv_tbl(l_ttdv_count).event_class_code                       	:= orig_ttd_rec.event_class_code;
2804           lp_ttdv_tbl(l_ttdv_count).event_type_code                        	:= orig_ttd_rec.event_type_code;
2805           lp_ttdv_tbl(l_ttdv_count).trx_id                                 	:= orig_ttd_rec.trx_id;
2806           lp_ttdv_tbl(l_ttdv_count).trx_line_id                            	:= orig_ttd_rec.trx_line_id;
2807           lp_ttdv_tbl(l_ttdv_count).trx_level_type                         	:= orig_ttd_rec.trx_level_type;
2808           lp_ttdv_tbl(l_ttdv_count).trx_line_number                        	:= orig_ttd_rec.trx_line_number;
2809           lp_ttdv_tbl(l_ttdv_count).tax_line_number                        	:= orig_ttd_rec.tax_line_number;
2810           lp_ttdv_tbl(l_ttdv_count).tax_regime_id                          	:= orig_ttd_rec.tax_regime_id;
2811           lp_ttdv_tbl(l_ttdv_count).tax_regime_code                        	:= orig_ttd_rec.tax_regime_code;
2812           lp_ttdv_tbl(l_ttdv_count).tax_id                                 	:= orig_ttd_rec.tax_id;
2813           lp_ttdv_tbl(l_ttdv_count).tax                                    	:= orig_ttd_rec.tax;
2814           lp_ttdv_tbl(l_ttdv_count).tax_status_id                          	:= orig_ttd_rec.tax_status_id;
2815           lp_ttdv_tbl(l_ttdv_count).tax_status_code                        	:= orig_ttd_rec.tax_status_code;
2816           lp_ttdv_tbl(l_ttdv_count).tax_apportionment_line_number          	:= orig_ttd_rec.tax_apportionment_line_number;
2817           lp_ttdv_tbl(l_ttdv_count).legal_entity_id                        	:= orig_ttd_rec.legal_entity_id;
2818           lp_ttdv_tbl(l_ttdv_count).trx_number                             	:= orig_ttd_rec.trx_number;
2819           lp_ttdv_tbl(l_ttdv_count).trx_date                               	:= orig_ttd_rec.trx_date;
2820           lp_ttdv_tbl(l_ttdv_count).tax_jurisdiction_id                    	:= orig_ttd_rec.tax_jurisdiction_id;
2821           lp_ttdv_tbl(l_ttdv_count).tax_jurisdiction_code                  	:= orig_ttd_rec.tax_jurisdiction_code;
2822           lp_ttdv_tbl(l_ttdv_count).tax_type_code                          	:= orig_ttd_rec.tax_type_code;
2823           lp_ttdv_tbl(l_ttdv_count).tax_currency_code                      	:= orig_ttd_rec.tax_currency_code;
2824           lp_ttdv_tbl(l_ttdv_count).taxable_amt_tax_curr                   	:= orig_ttd_rec.taxable_amt_tax_curr;
2825           lp_ttdv_tbl(l_ttdv_count).trx_currency_code                      	:= orig_ttd_rec.trx_currency_code;
2826           lp_ttdv_tbl(l_ttdv_count).minimum_accountable_unit               	:= orig_ttd_rec.minimum_accountable_unit;
2827           lp_ttdv_tbl(l_ttdv_count).precision                              	:= orig_ttd_rec.precision;
2828           lp_ttdv_tbl(l_ttdv_count).currency_conversion_type               	:= orig_ttd_rec.currency_conversion_type;
2829           lp_ttdv_tbl(l_ttdv_count).currency_conversion_rate               	:= orig_ttd_rec.currency_conversion_rate;
2830           lp_ttdv_tbl(l_ttdv_count).currency_conversion_date               	:= orig_ttd_rec.currency_conversion_date;
2831 	  -- Modified by dcshanmu for eBTax - modification end
2832 
2833           l_taxable_amount := orig_ttd_rec.taxable_amt * l_cm_ratio;
2834           lp_ttdv_tbl(l_ttdv_count).taxable_amt :=
2835                                okl_accounting_util.cross_currency_round_amount
2836                                  (p_amount        => l_taxable_amount,
2837                                   p_currency_code => l_curr_code);
2838 
2839            l_tax_amount := orig_ttd_rec.tax_amt * l_cm_ratio;
2840            lp_ttdv_tbl(l_ttdv_count).tax_amt :=
2841                                okl_accounting_util.cross_currency_round_amount
2842                                  (p_amount        => l_tax_amount,
2843                                   p_currency_code => l_curr_code);
2844 
2845         END LOOP;
2846 
2847         IF(IS_DEBUG_PROCEDURE_ON) THEN
2848           BEGIN
2849             OKL_DEBUG_PUB.LOG_DEBUG(L_LEVEL_PROCEDURE,L_MODULE,'Begin Debug OKLRACCB.pls call OKL_TAX_TRX_DETAILS_PUB.insert_tax_trx_details ');
2850           END;
2851         END IF;
2852 
2853         -- Create Tax Details Record
2854         OKL_TAX_TRX_DETAILS_PUB.insert_tax_trx_details(
2855           p_api_version    => p_api_version,
2856           p_init_msg_list  => p_init_msg_list,
2857           x_return_status  => x_return_status,
2858           x_msg_count      => x_msg_count,
2859           x_msg_data       => x_msg_data,
2860           p_ttdv_tbl       => lp_ttdv_tbl,
2861           x_ttdv_tbl       => lx_ttdv_tbl);
2862 
2863         IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
2864            RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
2865         ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
2866            RAISE OKL_API.G_EXCEPTION_ERROR;
2867         END IF;
2868 
2869         IF(IS_DEBUG_PROCEDURE_ON) THEN
2870           BEGIN
2871             OKL_DEBUG_PUB.LOG_DEBUG(L_LEVEL_PROCEDURE,L_MODULE,'End Debug OKLRACCB.pls call OKL_TAX_TRX_DETAILS_PUB.insert_tax_trx_details ');
2872           END;
2873         END IF;
2874 
2875       END LOOP;
2876 
2877     END IF;
2878     --End code changes for Tax API call by varao on 05/04/2005
2879   END IF;
2880    */
2881     --ebtax impact on billing akrangan commented code ends here
2882   --Bug# 4488818: Changes for Rollover, Release Billing: End
2883 
2884     /*IF x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR THEN
2885          NULL;
2886        	 --RAISE G_EXCEPTION_HALT_VALIDATION;
2887     ELSE
2888       IF x_return_status <> Okl_Api.G_RET_STS_SUCCESS THEN
2889          l_return_status := x_return_status;
2890       END IF;
2891     END IF;*/
2892 
2893   --Bug# 4488818: Changes for Upfront Sales Tax: Start
2894   -- Tax only invoice - Line Amount is equal to zero.
2895   ELSE
2896     NULL;
2897    --Bug# 4622963: Changes for Mass Rebook: Start
2898    --check for mass rebook contract
2899    --akrangan ebtax billing impacts start here
2900    /*
2901    l_mass_rbk_khr := '?';
2902    OPEN l_chk_mass_rbk_csr (p_chr_id => l_acct_call_rec.khr_id,
2903                             p_trx_id => p_bpd_acc_rec.source_trx_id);
2904    FETCH l_chk_mass_rbk_csr INTO l_mass_rbk_khr;
2905    CLOSE l_chk_mass_rbk_csr;
2906 
2907    -- Populate Tax Details Record
2908     l_ttdv_count := 0;
2909 
2910    --If Mass Rebook
2911 
2912    IF l_mass_rbk_khr = '!' THEN
2913 
2914      -- Fetch all Upfront Tax Lines.
2915      -- Upfront Tax is always to be Billed for Mass Rebook
2916 
2917      FOR tax_details_line_rec IN
2918          tax_details_line3_csr(p_khr_id => l_acct_call_rec.khr_id,
2919                                p_trx_id => p_bpd_acc_rec.source_trx_id)
2920      LOOP
2921        l_ttdv_count :=  l_ttdv_count + 1;
2922        lp_ttdv_tbl(l_ttdv_count).tax_amt := tax_details_line_rec.tax_amt;
2923        lp_ttdv_tbl(l_ttdv_count).taxable_amt := tax_details_line_rec.taxable_amt;
2924        lp_ttdv_tbl(l_ttdv_count).tax_rate_code := tax_details_line_rec.tax_rate_code;
2925        lp_ttdv_tbl(l_ttdv_count).tax_call_type_code := 'TAX_ONLY_INVOICE_TAX';
2926      END LOOP;
2927    --Bug# 4622963: Changes for Mass Rebook: End
2928 
2929    ELSE
2930 
2931     OPEN upfront_tax_csr(p_khr_id => l_acct_call_rec.khr_id);
2932     FETCH upfront_tax_csr INTO upfront_tax_rec;
2933     CLOSE upfront_tax_csr;
2934 
2935     -- Contract Level Asset Upfront Tax is set to 'BILLED'
2936     IF (upfront_tax_rec.asset_upfront_tax = 'BILLED') THEN
2937 
2938       -- Fetch Tax Lines for Assets having Line level Asset Upfront Tax
2939       -- Rule undefined or set to 'BILLED'.
2940       FOR tax_details_line_rec IN
2941           tax_details_line1_csr(p_khr_id => l_acct_call_rec.khr_id,
2942                                 p_trx_id => p_bpd_acc_rec.source_trx_id)
2943       LOOP
2944          l_ttdv_count :=  l_ttdv_count + 1;
2945          lp_ttdv_tbl(l_ttdv_count).tax_amt := tax_details_line_rec.tax_amt;
2946          lp_ttdv_tbl(l_ttdv_count).taxable_amt := tax_details_line_rec.taxable_amt;
2947          lp_ttdv_tbl(l_ttdv_count).tax_rate_code := tax_details_line_rec.tax_rate_code;
2948          lp_ttdv_tbl(l_ttdv_count).tax_call_type_code := 'TAX_ONLY_INVOICE_TAX';
2949       END LOOP;
2950 
2951     -- Contract Level Asset Upfront Tax is not set to 'BILLED'
2952     ELSE
2953 
2954       -- Fetch Tax Lines for Assets having Line level Asset Upfront Tax
2955       -- Rule set to 'BILLED'.
2956       FOR tax_details_line_rec IN
2957           tax_details_line2_csr(p_khr_id => l_acct_call_rec.khr_id,
2958                                 p_trx_id => p_bpd_acc_rec.source_trx_id)
2959       LOOP
2960          l_ttdv_count :=  l_ttdv_count + 1;
2961          lp_ttdv_tbl(l_ttdv_count).tax_amt := tax_details_line_rec.tax_amt;
2962          lp_ttdv_tbl(l_ttdv_count).taxable_amt := tax_details_line_rec.taxable_amt;
2963          lp_ttdv_tbl(l_ttdv_count).tax_rate_code := tax_details_line_rec.tax_rate_code;
2964          lp_ttdv_tbl(l_ttdv_count).tax_call_type_code := 'TAX_ONLY_INVOICE_TAX';
2965       END LOOP;
2966 
2967     END IF;
2968    END IF;
2969    */
2970    --akrangan ebtax billing impacts end here
2971 
2972  --akrangan ebtax billing impacts start
2973   /*  IF (l_ttdv_count > 0) THEN
2974 
2975       -- Populate Tax Sources Record
2976       lp_txsv_rec.khr_id := l_acct_call_rec.khr_id;
2977       lp_txsv_rec.trx_id := l_acct_call_rec.header_id;
2978       lp_txsv_rec.trx_line_id := l_acct_call_rec.line_id;
2979       lp_txsv_rec.entity_code := 'OKL_TXL_AR_INV_LNS_B';
2980       lp_txsv_rec.event_class_code := 'SALES_TRANSACTION_TAX_QUOTE';
2981       lp_txsv_rec.trx_level_type := 'LINE';
2982       lp_txsv_rec.tax_call_type_code := 'TAX_ONLY_INVOICE_TAX';
2983       lp_txsv_rec.sty_id := l_acct_call_rec.sty_id;
2984       lp_txsv_rec.tax_line_status_code := 'ACTIVE';
2985       lp_txsv_rec.reported_yn := 'N';
2986 
2987       IF(IS_DEBUG_PROCEDURE_ON) THEN
2988         BEGIN
2989           OKL_DEBUG_PUB.LOG_DEBUG(L_LEVEL_PROCEDURE,L_MODULE,'Begin Debug OKLRACCB.pls call OKL_TAX_SOURCES_PUB.insert_tax_sources ');
2990         END;
2991       END IF;
2992 
2993       -- Create Tax Sources Record
2994       OKL_TAX_SOURCES_PUB.insert_tax_sources(
2995         p_api_version    => p_api_version,
2996         p_init_msg_list  => p_init_msg_list,
2997         x_return_status  => x_return_status,
2998         x_msg_count      => x_msg_count,
2999         x_msg_data       => x_msg_data,
3000         p_txsv_rec       => lp_txsv_rec,
3001         x_txsv_rec       => lx_txsv_rec);
3002 
3003       IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
3004         RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
3005       ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
3006         RAISE OKL_API.G_EXCEPTION_ERROR;
3007       END IF;
3008 
3009       IF(IS_DEBUG_PROCEDURE_ON) THEN
3010         BEGIN
3011           OKL_DEBUG_PUB.LOG_DEBUG(L_LEVEL_PROCEDURE,L_MODULE,'End Debug OKLRACCB.pls call OKL_TAX_SOURCES_PUB.insert_tax_sources ');
3012         END;
3013       END IF;
3014 
3015       -- Populate txs_id in lp_ttdv_tbl
3016       FOR l_count IN lp_ttdv_tbl.FIRST..lp_ttdv_tbl.LAST
3017       LOOP
3018         lp_ttdv_tbl(l_count).txs_id := lx_txsv_rec.id;
3019       END LOOP;
3020 
3021       IF(IS_DEBUG_PROCEDURE_ON) THEN
3022         BEGIN
3023           OKL_DEBUG_PUB.LOG_DEBUG(L_LEVEL_PROCEDURE,L_MODULE,'Begin Debug OKLRACCB.pls call OKL_TAX_TRX_DETAILS_PUB.insert_tax_trx_details ');
3024         END;
3025       END IF;
3026 
3027       -- Create Tax Details Record
3028       OKL_TAX_TRX_DETAILS_PUB.insert_tax_trx_details(
3029         p_api_version    => p_api_version,
3030         p_init_msg_list  => p_init_msg_list,
3031         x_return_status  => x_return_status,
3032         x_msg_count      => x_msg_count,
3033         x_msg_data       => x_msg_data,
3034         p_ttdv_tbl       => lp_ttdv_tbl,
3035         x_ttdv_tbl       => lx_ttdv_tbl);
3036 
3037       IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
3038         RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
3039       ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
3040         RAISE OKL_API.G_EXCEPTION_ERROR;
3041       END IF;
3042 
3043       IF(IS_DEBUG_PROCEDURE_ON) THEN
3044         BEGIN
3045           OKL_DEBUG_PUB.LOG_DEBUG(L_LEVEL_PROCEDURE,L_MODULE,'End Debug OKLRACCB.pls call OKL_TAX_TRX_DETAILS_PUB.insert_tax_trx_details ');
3046         END;
3047       END IF;
3048 
3049     END IF; */
3050      --akrangan ebtax billing impacts end
3051   END IF;
3052   --Bug# 4488818: Changes for Upfront Sales Tax: End
3053 
3054   x_return_status := Okl_Api.G_RET_STS_SUCCESS;
3055 
3056 EXCEPTION
3057     WHEN OKL_API.G_EXCEPTION_ERROR THEN
3058       x_return_status := Okl_Api.G_RET_STS_ERROR;
3059 
3060     WHEN OKL_API.G_EXCEPTION_UNEXPECTED_ERROR THEN
3061       x_return_status := Okl_Api.G_RET_STS_UNEXP_ERROR;
3062 
3063     WHEN G_EXCEPTION_HALT_VALIDATION THEN
3064       Okl_Api.SET_MESSAGE(p_app_name          => g_app_name
3065                          ,p_msg_name          => g_unexpected_error
3066                          ,p_token1            => g_sqlcode_token
3067                          ,p_token1_value      => SQLCODE
3068                          ,p_token2            => g_sqlerrm_token
3069                          ,p_token2_value      => SQLERRM);
3070       x_return_status := Okl_Api.G_RET_STS_UNEXP_ERROR;
3071     WHEN OTHERS THEN
3072       Okl_Api.SET_MESSAGE(p_app_name          => g_app_name
3073                          ,p_msg_name          => g_unexpected_error
3074                          ,p_token1            => g_sqlcode_token
3075                          ,p_token1_value      => SQLCODE
3076                          ,p_token2            => g_sqlerrm_token
3077                          ,p_token2_value      => SQLERRM);
3078       x_return_status := Okl_Api.G_RET_STS_UNEXP_ERROR;
3079 END create_acc_trans_new;
3080 
3081 
3082 
3083 END Okl_Acc_Call_Pvt;