[Home] [Help]
PACKAGE BODY: APPS.GL_CALCULATE_TAX_PKG
Source
1 PACKAGE BODY GL_CALCULATE_TAX_PKG as
2 /* $Header: glujetxb.pls 120.8 2011/12/01 05:49:29 dthakker ship $ */
3
4 ---
5 --- PRIVATE FUNCTIONS
6 ---
7
8 --
9 -- Procedure
10 -- setup
11 -- Purpose
12 -- Validates the parameters and gets various information
13 -- History
14 -- 10-DEC-96 D. J. Ogg Created
15 -- Arguments
16 -- header_id The header id
17 -- tax_level 'J'ournal or 'B'atch
18 -- lgr_id Ledger id of header or batch
19 -- org_id Org of batch
20 -- per_name Period of header or batch
21 -- calculation_level Calculation level for ledger and org
22 -- base_currency Currency of ledger
23 -- tax_mau Tax mau for ledger and org
24 -- Notes
25 --
26 PROCEDURE setup(header_id NUMBER,
27 tax_level VARCHAR2,
28 lgr_id IN OUT NOCOPY VARCHAR2,
29 org_id IN OUT NOCOPY NUMBER,
30 per_name IN OUT NOCOPY VARCHAR2,
31 calculation_level IN OUT NOCOPY VARCHAR2,
32 base_currency IN OUT NOCOPY VARCHAR2,
33 tax_mau IN OUT NOCOPY VARCHAR2) IS
34
35 tax_status_code VARCHAR2(1); -- Tax status of journal or batch
36 dummy2 NUMBER; -- Dummy variable
37 dummy VARCHAR2(100); -- Dummy variable
38 le_id NUMBER; -- legal entity id
39 x_return_status VARCHAR2(30);
40 x_msg_out VARCHAR2(2000);
41 BEGIN
42
43 -- Validate the header and get batch level information
44 BEGIN
45 -- Lock the header
46 SELECT je_batch_id
47 INTO dummy2
48 FROM gl_je_headers jeh
49 WHERE jeh.je_header_id = header_id
50 FOR UPDATE;
51
52 -- Lock the batch
53 SELECT 'Good batch'
54 INTO dummy
55 FROM gl_je_batches jeb
56 WHERE jeb.je_batch_id = dummy2
57 FOR UPDATE;
58
59 -- Get various information
60 SELECT jeh.tax_status_code, jeh.ledger_id, jeb.org_id,
61 jeb.default_period_name, lgr.currency_code
62 INTO tax_status_code, lgr_id, org_id, per_name,
63 base_currency
64 FROM gl_je_headers jeh, gl_je_batches jeb, gl_ledgers lgr
65 WHERE jeh.je_header_id = header_id
66 AND jeb.je_batch_id = jeh.je_batch_id
67 AND lgr.ledger_id = jeh.ledger_id;
68 EXCEPTION
69 WHEN NO_DATA_FOUND THEN
70 fnd_message.set_name('SQLGL', 'GL_CTAX_BAD_HEADER');
71 fnd_message.set_token('HEADER_ID', to_char(header_id));
72 app_exception.raise_exception;
73 END;
74
75 IF (tax_status_code <> 'R') THEN
76 fnd_message.set_name('SQLGL', 'GL_CTAX_HEADER_TAXED');
77 app_exception.raise_exception;
78 END IF;
79
80 -- Get various information about the tax setup
81 BEGIN
82 --SELECT calculation_level_code,
83 -- decode(tax_mau, NULL, power(10, -1*tax_precision), tax_mau)
84 --INTO calculation_level, tax_mau
85 --FROM gl_tax_options
86 --WHERE ledger_id = lgr_id
87 --AND org_id = current_org_id;
88
89 le_id := XLE_UTILITIES_GRP.Get_DefaultLegalContext_OU(
90 org_id);
91
92 zx_gl_tax_options_pkg.get_ledger_controls(
93 1.0,
94 lgr_id,
95 org_id,
96 le_id,
97 calculation_level,
98 tax_mau,
99 x_return_status,
100 x_msg_out);
101 EXCEPTION
102 WHEN NO_DATA_FOUND THEN
103 BEGIN
104 SELECT nvl(multi_org_flag, 'N')
105 INTO dummy
106 FROM fnd_product_groups;
107 EXCEPTION
108 WHEN NO_DATA_FOUND THEN
109 dummy := 'Y';
110 END;
111
112 IF (dummy = 'N') THEN
113 fnd_message.set_name('SQLGL', 'GL_CTAX_NO_OPTIONS');
114 ELSIF (tax_level = 'J') THEN
115 fnd_message.set_name('SQLGL', 'GL_CTAX_NO_OPTIONS_JOURN_ORG');
116 ELSE
117 fnd_message.set_name('SQLGL', 'GL_CTAX_NO_OPTIONS_BATCH_ORG');
118 END IF;
119 app_exception.raise_exception;
120 END;
121 END setup;
122
123 --
124 -- Procedure
125 -- round_it
126 -- Purpose
127 -- Rounds a number to the appropriate precision
128 -- History
129 -- 10-DEC-96 D. J. Ogg Created
130 -- Arguments
131 -- amount The amount to be rounded
132 -- rounding_rule Rounding rule to be followed: Up, Down, or
133 -- Nearest
134 -- mau Mau of currency
135 -- Notes
136 --
137 FUNCTION round_it(amount NUMBER,
138 rounding_rule VARCHAR2,
139 mau NUMBER) RETURN NUMBER IS
140 BEGIN
141 IF (amount IS NULL) THEN
142 RETURN(NULL);
143 ELSIF (rounding_rule = 'U') THEN
144 IF (sign(amount) >= 0) THEN
145 RETURN(ceil(amount / mau) * mau);
146 ELSE
147 RETURN(-1 * ceil(abs(amount) / mau) * mau);
148 END IF;
149 ELSIF (rounding_rule = 'D') THEN
150 IF (sign(amount) >= 0) THEN
151 RETURN(floor(amount / mau) * mau);
152 ELSE
153 RETURN(-1 * floor(abs(amount) / mau) * mau);
154 END IF;
155 ELSE
156 RETURN(round(amount / mau) * mau);
157 END IF;
158 END round_it;
159
160
161 ---
162 --- PUBLIC FUNCTIONS
163 ---
164
165 PROCEDURE calculate( tax_level VARCHAR2,
166 batch_header_id NUMBER,
167 disp_header_id NUMBER DEFAULT NULL,
168 resp_appl_id NUMBER,
169 resp_id NUMBER,
170 user_id NUMBER,
171 login_id NUMBER,
172 coa_id NUMBER,
173 header_total_dr IN OUT NOCOPY NUMBER,
174 header_total_cr IN OUT NOCOPY NUMBER,
175 header_total_acc_dr IN OUT NOCOPY NUMBER,
176 header_total_acc_cr IN OUT NOCOPY NUMBER,
177 batch_total_dr IN OUT NOCOPY NUMBER,
178 batch_total_cr IN OUT NOCOPY NUMBER,
179 batch_total_acc_dr IN OUT NOCOPY NUMBER,
180 batch_total_acc_cr IN OUT NOCOPY NUMBER,
181 has_bad_accounts IN OUT NOCOPY BOOLEAN
182 ) IS
183
184
185 lgr_id NUMBER; -- Current ledger
186 org_id NUMBER; -- Current operating unit
187 per_name VARCHAR2(15); -- Current period name
188 calculation_level VARCHAR2(1); -- Calculation level: Journal or Line
189 tax_mau NUMBER; -- Minimum accountable unit for tax
190 -- calculations
191 base_currency VARCHAR2(15); -- Functional currency of set of books
192 tax_status_code VARCHAR2(1); -- Tax status code of batch
193
194 header_id NUMBER; -- Id of current header
195 next_line_num NUMBER; -- Next unused line number for current header
196 conv_rate NUMBER; -- Conversion rate for current header
197 header_eff_date DATE; -- Effective date of header
198 currency VARCHAR2(15); -- Currency for header
199 curr_mau NUMBER; -- Minimum accountable unit for header
200
201 line_count NUMBER; -- Total number of lines processed
202
203 line_num NUMBER; -- Number of current line
204 eff_date DATE; -- effective date of line
205 ent_dr NUMBER; -- line debits
206 ent_cr NUMBER; -- line credits
207 description VARCHAR2(250); -- line description
208 rounding_rule VARCHAR2(1); -- line rounding rule
209 incl_tax VARCHAR2(1); -- line includes tax
210 tax_code VARCHAR2(50); -- line tax code
211 tax_rate NUMBER; -- line tax rate
212 tax_ccid NUMBER; -- tax ccid for line
213 tax_group NUMBER; -- tax group for line
214
215 no_more_records BOOLEAN; -- Indicates that all records have been
216 -- fetched
217 last_in_group BOOLEAN; -- Indicates this is the last record in
218 -- the group
219 first_in_group BOOLEAN; -- Indicates this is the first record
220 -- in the group
221
222 bad_acct BOOLEAN; -- Indicates that the current tax
223 -- account is bad
224 bad_csegs VARCHAR2(750); -- Gives the bad tax account
225
226 line_tax_dr NUMBER; -- Tax debits for current line
227 line_tax_cr NUMBER; -- Tax credits for next line
228 line_tax_acc_dr NUMBER; -- Tax accounted debits for current line
229 line_tax_acc_cr NUMBER; -- Tax accounted credits for next line
230
231 total_ent_dr NUMBER; -- Total entered debits
232 total_ent_cr NUMBER; -- Total entered credits
233
234 total_jtax_dr NUMBER; -- Correct tax dr for current tax line
235 total_jtax_cr NUMBER; -- Correct tax cr for current tax line
236 total_jtax_acc_dr NUMBER; -- Correct tax accounted dr for current tax
237 -- line
238 total_jtax_acc_cr NUMBER; -- Correct tax accounted cr current tax line
239
240 total_ltax_dr NUMBER; -- Sum of individual lines tax dr (needed for
241 -- journal method)
242 total_ltax_cr NUMBER; -- Sum of individual lines tax cr (needed for
243 -- journal method)
244 total_ltax_acc_dr NUMBER; -- Correct tax accounted dr for current tax
245 -- line
246 total_ltax_acc_cr NUMBER; -- Correct tax accounted cr current tax line
247
248 tax_line_descr VARCHAR2(240); -- Description of tax line
249 line_curs_init BOOLEAN;
250 /* Added for bug13350390 */
251 rec_next_line_num NUMBER; -- Next unused line number to insert recon lines
252 retval NUMBER;
253
254 CURSOR j_journals IS
255 SELECT max(jeh.je_header_id), max(jel.je_line_num) + 1,
256 max(jeh.currency_conversion_rate),
257 max(jeh.default_effective_date),
258 max(jeh.currency_code),
259 max(decode(curr.minimum_accountable_unit,
260 NULL, power(10, -1*curr.precision),
261 curr.minimum_accountable_unit))
262 FROM gl_je_headers jeh, fnd_currencies curr, gl_je_lines jel
263 WHERE jeh.je_header_id = batch_header_id
264 AND curr.currency_code = jeh.currency_code
265 AND jel.je_header_id = jeh.je_header_id;
266
267 CURSOR b_journals IS
268 SELECT jeh.je_header_id, max(jel.je_line_num) + 1,
269 max(jeh.currency_conversion_rate),
270 max(jeh.default_effective_date),
271 max(jeh.currency_code),
272 max(decode(curr.minimum_accountable_unit,
273 NULL, power(10, -1*curr.precision),
274 curr.minimum_accountable_unit))
275 FROM gl_je_headers jeh, fnd_currencies curr, gl_je_lines jel
276 WHERE jeh.je_batch_id = batch_header_id
277 AND jeh.tax_status_code = 'R'
278 AND curr.currency_code = jeh.currency_code
279 AND jel.je_header_id = jeh.je_header_id
280 GROUP BY jeh.je_header_id;
281 BEGIN
282
283 -- Initially, there are no bad accounts
284 has_bad_accounts := FALSE;
285
286 -- Build a cursor to loop through each journal
287 IF (tax_level = 'J') THEN
288 OPEN j_journals;
289 ELSE
290
291 BEGIN
292 SELECT max(decode(jeh.tax_status_code, 'R', '1', '0'))
293 INTO tax_status_code
294 FROM gl_je_headers jeh
295 WHERE jeh.je_batch_id = batch_header_id;
296 EXCEPTION
297 WHEN NO_DATA_FOUND THEN
298 fnd_message.set_name('SQLGL', 'GL_CTAX_BAD_BATCH');
299 fnd_message.set_token('BATCH_ID', to_char(batch_header_id));
300 app_exception.raise_exception;
301 END;
302
303 IF (nvl(tax_status_code,'0') <> '1') THEN
304 fnd_message.set_name('SQLGL', 'GL_CTAX_BATCH_TAXED');
305 app_exception.raise_exception;
306 END IF;
307
308 OPEN b_journals;
309 END IF;
310
311 line_curs_init := FALSE;
312 LOOP
313 -- Get a journal
314 IF (tax_level = 'J') THEN
315 FETCH j_journals INTO header_id, next_line_num, conv_rate,
316 header_eff_date, currency, curr_mau;
317 EXIT WHEN j_journals%NOTFOUND;
318 ELSE
319 FETCH b_journals INTO header_id, next_line_num, conv_rate,
320 header_eff_date, currency, curr_mau;
321 EXIT WHEN b_journals%NOTFOUND;
322 END IF;
323
324 /* Added for bug13350390 */
325 rec_next_line_num := next_line_num;
326
327 -- Initialize the journal information
328 setup(header_id => header_id,
329 tax_level => tax_level,
330 lgr_id => lgr_id,
331 org_id => org_id,
332 per_name => per_name,
336
333 calculation_level => calculation_level,
334 base_currency => base_currency,
335 tax_mau => tax_mau);
337 -- Setup the lines cursor. Must be done
338 -- after setup call. Close the cursor if it is already open
339 IF (line_curs_init) THEN
340 gl_calculate_tax2_pkg.close_cursor;
341 END IF;
342 gl_calculate_tax2_pkg.define_cursor(
343 coa_id => coa_id,
344 calculation_level => calculation_level);
345 line_curs_init := TRUE;
346
347
348 -- If this is a functional currency journal, then use the tax mau
349 IF (currency = base_currency) THEN
350 curr_mau := tax_mau;
351 END IF;
352
353 -- Prepare the lines cursor for fetch
354 gl_calculate_tax2_pkg.bind_cursor(header_id);
355 gl_calculate_tax2_pkg.execute_cursor;
356
357 -- Initialize everything
358 line_count := 0;
359 first_in_group := TRUE;
360 total_ent_dr := null;
361 total_ent_cr := null;
362 total_jtax_dr := null;
363 total_jtax_cr := null;
364 total_jtax_acc_dr := null;
365 total_jtax_acc_cr := null;
366 total_ltax_dr := null;
367 total_ltax_cr := null;
368 total_ltax_acc_dr := null;
369 total_ltax_acc_cr := null;
370
371
372 LOOP
373
374 gl_calculate_tax2_pkg.fetch_cursor(
375 coa_id => coa_id,
376 lgr_id => lgr_id,
377 org_id => org_id,
378 calculation_level => calculation_level,
379 journal_effective_date => header_eff_date,
380 resp_appl_id => resp_appl_id,
381 resp_id => resp_id,
382 user_id => user_id,
383 no_more_records => no_more_records,
384 last_in_group => last_in_group,
385 bad_acct => bad_acct,
386 bad_csegs => bad_csegs,
387 line_num => line_num,
388 eff_date => eff_date,
389 ent_dr => ent_dr,
390 ent_cr => ent_cr,
391 rounding_rule => rounding_rule,
392 description => description,
393 incl_tax => incl_tax,
394 tax_code => tax_code,
395 tax_rate => tax_rate,
396 tax_ccid => tax_ccid,
397 tax_group => tax_group);
398
399 EXIT WHEN no_more_records;
400
401 line_count := line_count + 1;
402
403 -- Update the entered debits and credits totals
404 IF (first_in_group) THEN
405 total_ent_dr := ent_dr;
406 total_ent_cr := ent_cr;
407 ELSE
408 total_ent_dr := total_ent_dr + ent_dr;
409 total_ent_cr := total_ent_cr + ent_cr;
410 END IF;
411
412 -- If this is the last in the group, then finish the group
413 IF (last_in_group) THEN
414
415 -- Keep track of bad accounts
416 IF (bad_acct) THEN
417 has_bad_accounts := TRUE;
418 END IF;
419
420 IF (calculation_level <> 'L') THEN
421 -- Determine description for tax line
422 fnd_message.set_name('SQLGL', 'GL_CTAX_LINE_DESCRIPTION');
423 fnd_message.set_token('TAX_CODE', tax_code);
424 fnd_message.set_token('PERCENTAGE', to_char(tax_rate*100));
425 IF (bad_acct) THEN
426 tax_line_descr := substrb(bad_csegs||': '||fnd_message.get,
427 1, 240);
428 ELSE
429 tax_line_descr := substrb(fnd_message.get, 1, 240);
430 END IF;
431
432 -- Calculate tax amount for tax line
433 IF (incl_tax = 'Y') THEN
434 total_jtax_dr := round_it((total_ent_dr*tax_rate)/(1+tax_rate),
435 rounding_rule, curr_mau);
436 total_jtax_cr := round_it((total_ent_cr*tax_rate)/(1+tax_rate),
437 rounding_rule, curr_mau);
438 ELSE
439 total_jtax_dr := round_it(total_ent_dr * tax_rate,
440 rounding_rule, curr_mau);
441 total_jtax_cr := round_it(total_ent_cr * tax_rate,
442 rounding_rule, curr_mau);
443 END IF;
444 total_jtax_acc_dr := round_it(total_jtax_dr * conv_rate,
445 rounding_rule, tax_mau);
446 total_jtax_acc_cr := round_it(total_jtax_cr * conv_rate,
447 rounding_rule, tax_mau);
448
449 -- Calculate tax amount for last taxable line
450 IF (first_in_group) THEN
451 line_tax_dr := total_jtax_dr;
452 line_tax_cr := total_jtax_cr;
453 line_tax_acc_dr := total_jtax_acc_dr;
454 line_tax_acc_cr := total_jtax_acc_cr;
455 ELSE
456 line_tax_dr := total_jtax_dr - total_ltax_dr;
457 line_tax_cr := total_jtax_cr - total_ltax_cr;
458 line_tax_acc_dr := total_jtax_acc_dr - total_ltax_acc_dr;
459 line_tax_acc_cr := total_jtax_acc_cr - total_ltax_acc_cr;
460 END IF;
461 ELSE
462 -- Determine description for tax line
466 fnd_message.set_token('LINE_NUM', to_char(line_num));
463 fnd_message.set_name('SQLGL', 'GL_CTAX_JOURNAL_DESCRIPTION');
464 fnd_message.set_token('TAX_CODE', tax_code);
465 fnd_message.set_token('PERCENTAGE', to_char(tax_rate*100));
467 fnd_message.set_token('LINE_DESCRIPTION', description);
468 IF (bad_acct) THEN
469 tax_line_descr := substrb(bad_csegs||': '||fnd_message.get,
470 1, 240);
471 ELSE
472 tax_line_descr := substrb(fnd_message.get,1,240);
473 END IF;
474
475 -- Calculate tax amount for line
476 IF (incl_tax = 'Y') THEN
477 line_tax_dr := round_it((ent_dr*tax_rate)/(1+tax_rate),
478 rounding_rule, curr_mau);
479 line_tax_cr := round_it((ent_cr*tax_rate)/(1+tax_rate),
480 rounding_rule, curr_mau);
481 ELSE
482 line_tax_dr := round_it(ent_dr * tax_rate,
483 rounding_rule, curr_mau);
484 line_tax_cr := round_it(ent_cr * tax_rate,
485 rounding_rule, curr_mau);
486 END IF;
487 line_tax_acc_dr := round_it(line_tax_dr * conv_rate,
488 rounding_rule, tax_mau);
489 line_tax_acc_cr := round_it(line_tax_cr * conv_rate,
490 rounding_rule, tax_mau);
491
492 total_jtax_dr := line_tax_dr;
493 total_jtax_cr := line_tax_cr;
494 total_jtax_acc_dr := line_tax_acc_dr;
495 total_jtax_acc_cr := line_tax_acc_cr;
496 END IF;
497
498 INSERT INTO gl_je_lines
499 (ledger_id, je_header_id, je_line_num,
500 code_combination_id, status,
501 period_name, effective_date,
502 entered_dr, entered_cr,
503 accounted_dr, accounted_cr,
504 taxable_line_flag, tax_line_flag, tax_group_id,
505 description,
506 creation_date, created_by,
507 last_update_date, last_updated_by, last_update_login)
508 VALUES
509 (lgr_id, header_id, next_line_num,
510 tax_ccid, 'U',
511 per_name, eff_date,
512 total_jtax_dr, total_jtax_cr,
513 total_jtax_acc_dr, total_jtax_acc_cr,
514 'N', 'Y', tax_group,
515 ltrim(rtrim(tax_line_descr)),
516 sysdate, user_id,
517 sysdate, user_id, login_id);
518
519 -- Clear everything out
520 total_ent_dr := null;
521 total_ent_cr := null;
522 total_jtax_dr := null;
523 total_jtax_cr := null;
524 total_jtax_acc_dr := null;
525 total_jtax_acc_cr := null;
526 total_ltax_dr := null;
527 total_ltax_cr := null;
528 total_ltax_acc_dr := null;
529 total_ltax_acc_cr := null;
530
531 -- Get the next line number
532 next_line_num := next_line_num + 1;
533 ELSE
534 -- Calculate tax amount for line
535 IF (incl_tax = 'Y') THEN
536 line_tax_dr := round_it((ent_dr*tax_rate)/(1+tax_rate),
537 rounding_rule, curr_mau);
538 line_tax_cr := round_it((ent_cr*tax_rate)/(1+tax_rate),
539 rounding_rule, curr_mau);
540 ELSE
541 line_tax_dr := round_it(ent_dr * tax_rate,
542 rounding_rule, curr_mau);
543 line_tax_cr := round_it(ent_cr * tax_rate,
544 rounding_rule, curr_mau);
545 END IF;
546 line_tax_acc_dr := round_it(line_tax_dr * conv_rate,
547 rounding_rule, tax_mau);
548 line_tax_acc_cr := round_it(line_tax_cr * conv_rate,
549 rounding_rule, tax_mau);
550
551 -- Update the totals
552 IF (first_in_group) THEN
553 total_ltax_dr := line_tax_dr;
554 total_ltax_cr := line_tax_cr;
555 total_ltax_acc_dr := line_tax_acc_dr;
556 total_ltax_acc_cr := line_tax_acc_cr;
557 ELSE
558 total_ltax_dr := total_ltax_dr + line_tax_dr;
559 total_ltax_cr := total_ltax_cr + line_tax_cr;
560 total_ltax_acc_dr := total_ltax_acc_dr + line_tax_acc_dr;
561 total_ltax_acc_cr := total_ltax_acc_cr + line_tax_acc_cr;
562 END IF;
563 END IF;
564
565 UPDATE gl_je_lines jel
566 SET entered_dr = decode(incl_tax,
567 'Y', jel.entered_dr - line_tax_dr,
568 jel.entered_dr),
569 entered_cr = decode(incl_tax,
570 'Y', jel.entered_cr - line_tax_cr,
571 jel.entered_cr),
572 accounted_dr = decode(incl_tax,
573 'Y', jel.accounted_dr - line_tax_acc_dr,
574 jel.accounted_dr),
575 accounted_cr = decode(incl_tax,
576 'Y', jel.accounted_cr - line_tax_acc_cr,
577 jel.accounted_cr),
578 tax_group_id = tax_group,
579 last_update_date = sysdate,
580 last_updated_by = user_id,
581 last_update_login = login_id
582 WHERE jel.je_header_id = header_id
583 AND jel.je_line_num = line_num;
584
585 first_in_group := last_in_group;
586 END LOOP;
590 IF (tax_level = 'B') THEN
587
588 -- Raise an error
589 IF (line_count = 0) THEN
591 fnd_message.set_name('SQLGL', 'GL_CTAX_BATCH_NO_TAX_LINES');
592 app_exception.raise_exception;
593 ELSE
594 fnd_message.set_name('SQLGL', 'GL_CTAX_JOURNAL_NO_TAX_LINES');
595 app_exception.raise_exception;
596 END IF;
597 END IF;
598
599 -- Update the running totals
600 IF ( (tax_level = 'B')
601 AND (nvl(disp_header_id, -1) <> header_id)
602 ) THEN
603 UPDATE gl_je_headers
604 SET tax_status_code = 'T',
605 last_updated_by = user_id,
606 last_update_date = sysdate,
607 last_update_login = login_id,
608 (running_total_dr, running_total_cr,
609 running_total_accounted_dr, running_total_accounted_cr)
610 = (SELECT sum(entered_dr), sum(entered_cr),
611 sum(accounted_dr), sum(accounted_cr)
612 FROM gl_je_lines
613 WHERE je_header_id = header_id)
614 WHERE je_header_id = header_id
615 AND tax_status_code = 'R';
616 ELSE
617 SELECT sum(entered_dr), sum(entered_cr),
618 sum(accounted_dr), sum(accounted_cr)
619 INTO header_total_dr, header_total_cr,
620 header_total_acc_dr, header_total_acc_cr
621 FROM gl_je_lines
622 WHERE je_header_id = header_id;
623 END IF;
624
625 /* Added for bug13350390 */
626 retval := gl_je_lines_recon_pkg.insert_gen_line_recon_lines
627 (
628 X_Je_Header_Id => header_id,
629 X_From_Je_Line_Num => rec_next_line_num,
630 X_Last_Updated_By => user_id,
631 X_Last_Update_Login => login_id
632 );
633
634 END LOOP;
635
636 -- Get the updated batch running totals, if necessary.
637 IF (tax_level = 'B') THEN
638 SELECT sum(running_total_dr), sum(running_total_cr),
639 sum(running_total_accounted_dr),
640 sum(running_total_accounted_cr)
641 INTO batch_total_dr, batch_total_cr,
642 batch_total_acc_dr, batch_total_acc_cr
643 FROM gl_je_headers
644 WHERE je_batch_id = batch_header_id
645 AND je_header_id <> nvl(disp_header_id, -1);
646
647 IF (disp_header_id IS NOT NULL) THEN
648 batch_total_dr := nvl(batch_total_dr, 0) + nvl(header_total_dr, 0);
649 batch_total_cr := nvl(batch_total_cr, 0) + nvl(header_total_cr, 0);
650 batch_total_acc_dr := nvl(batch_total_acc_dr, 0)
651 + nvl(header_total_acc_dr, 0);
652 batch_total_acc_cr := nvl(batch_total_acc_cr, 0)
653 + nvl(header_total_acc_cr, 0);
654 END IF;
655 END IF;
656
657 -- Close the cursors
658 IF (tax_level = 'J') THEN
659 CLOSE j_journals;
660 ELSE
661 CLOSE b_journals;
662 END IF;
663 gl_calculate_tax2_pkg.close_cursor;
664 END calculate;
665
666 END GL_CALCULATE_TAX_PKG;