[Home] [Help]
PACKAGE BODY: APPS.ARP_ETAX_RECURR_UTIL
Source
1 PACKAGE BODY ARP_ETAX_RECURR_UTIL AS
2 /* $Header: AREBTICB.pls 120.20.12010000.6 2008/12/22 17:50:15 mraymond ship $ */
3
4 /*=======================================================================+
5 | Package Globals
6 +=======================================================================*/
7 g_headers_inserted NUMBER;
8 g_lines_inserted NUMBER;
9 g_tax_lines_inserted NUMBER;
10 l_status VARCHAR2(1); -- junk variable
11 l_industry VARCHAR2(1); -- junk variable
12 g_default_country VARCHAR2(50);
13 g_legal_entity_id NUMBER;
14
15 /*========================================================================
16 | Prototype Declarations Procedures
17 *=======================================================================*/
18
19 PG_DEBUG varchar2(1) := NVL(FND_PROFILE.value('AFLOG_ENABLED'), 'N');
20
21 /*========================================================================
22 | Prototype Declarations Functions
23 *=======================================================================*/
24
25 PROCEDURE debug(text IN VARCHAR2) IS
26 BEGIN
27 fnd_file.put_line(FND_FILE.LOG, text);
28 -- arp_standard.debug(text);
29 END;
30
31 /* Private Procedure - Inserts headers into ZX_TRX_HEADERS_GT */
32 PROCEDURE insert_header(p_customer_trx_id IN NUMBER) IS
33
34 BEGIN
35 IF PG_DEBUG in ('Y', 'C') THEN
36 debug('arp_etax_recurr_util.insert_header()+');
37 END IF;
38
39 INSERT INTO ZX_TRX_HEADERS_GT
40 (
41 internal_organization_id,
42 internal_org_location_id,
43 legal_entity_id,
44 application_id,
45 ledger_id,
46 entity_code,
47 event_class_code,
48 event_type_code,
49 tax_reporting_flag,
50 trx_id,
51 trx_number,
52 trx_description,
53 doc_seq_id,
54 doc_seq_name,
55 doc_seq_value,
56 batch_source_id,
57 batch_source_name,
58 receivables_trx_type_id,
59 trx_type_description,
60 trx_date,
61 trx_communicated_date,
62 trx_due_date,
63 bill_to_cust_acct_site_use_id,
64 trx_currency_code,
65 precision,
66 minimum_accountable_unit,
67 currency_conversion_date,
68 currency_conversion_rate,
69 currency_conversion_type,
70 rounding_bill_to_party_id,
71 rndg_bill_to_party_site_id,
72 application_doc_status,
73 related_doc_application_id,
74 related_doc_entity_code,
75 related_doc_event_class_code,
76 related_doc_trx_id,
77 related_doc_number,
78 related_doc_date
79 )
80 SELECT
81 AR.org_id,
82 HR.location_id,
83 T.legal_entity_id,
84 222,
85 AR.set_of_books_id,
86 'TRANSACTIONS',
87 'INVOICE', -- event_class
88 'INV_CREATE', -- event_type
89 'Y',
90 T.customer_trx_id,
91 T.trx_number,
92 SUBSTRB(T.comments,1,240),
93 T.doc_sequence_id,
94 -- bug 6806843
95 -- TT.name,
96 SEQ.name,
97 T.doc_sequence_value,
98 T.batch_source_id,
99 TB.name,
100 T.cust_trx_type_id,
101 TT.description,
102 T.trx_date,
103 T.printing_original_date,
104 T.term_due_date,
105 T.bill_to_site_use_id,
106 T.invoice_currency_code,
107 C.precision,
108 C.minimum_accountable_unit,
109 T.exchange_date,
110 T.exchange_rate,
111 T.exchange_rate_type,
112 BTCA.party_id,
113 BTPS.party_site_id,
114 DECODE(T.status_trx, 'VD','VD',NULL), -- void
115 DECODE(REL_T.customer_trx_id, NULL, NULL, 222),
116 DECODE(REL_T.customer_trx_id, NULL, NULL, 'TRANSACTIONS'),
117 DECODE(REL_T.customer_trx_id, NULL, NULL,
118 DECODE(REL_TT.type, 'INV', 'INVOICE',
119 'DM', 'DEBIT_MEMO',
120 'CM', 'CREDIT_MEMO')),
121 DECODE(REL_T.customer_trx_id, NULL, NULL, REL_T.customer_trx_id),
122 DECODE(REL_T.customer_trx_id, NULL, NULL, REL_T.trx_number),
123 DECODE(REL_T.customer_trx_id, NULL, NULL, REL_T.trx_date)
124 FROM RA_CUSTOMER_TRX T,
125 RA_CUST_TRX_TYPES TT,
126 RA_BATCH_SOURCES TB,
127 FND_CURRENCIES C,
128 FND_DOCUMENT_SEQUENCES SEQ,
129 AR_SYSTEM_PARAMETERS AR,
130 HZ_CUST_ACCOUNTS BTCA,
131 HZ_CUST_SITE_USES BTCSU,
132 HZ_CUST_ACCT_SITES BTPS,
133 HR_ORGANIZATION_UNITS HR,
134 RA_CUSTOMER_TRX REL_T,
135 RA_CUST_TRX_TYPES REL_TT
136 WHERE T.customer_trx_id = p_customer_trx_id
137 AND T.invoice_currency_code = C.currency_code
138 AND T.org_id = AR.org_id
139 AND T.cust_trx_type_id = TT.cust_trx_type_id
140 AND T.doc_sequence_id = SEQ.doc_sequence_id (+)
141 AND T.batch_source_id = TB.batch_source_id
142 AND T.bill_to_customer_id = BTCA.cust_account_id
143 AND T.bill_to_site_use_id = BTCSU.site_use_id
144 AND BTCSU.cust_acct_site_id = BTPS.cust_acct_site_id
145 AND HR.organization_id = T.org_id
146 AND T.related_customer_trx_id = REL_T.customer_trx_id (+)
147 AND REL_T.cust_trx_type_id = REL_TT.cust_trx_type_id (+);
148
149 /* Store total for output in debug log */
150 g_headers_inserted := SQL%ROWCOUNT;
151
152 IF PG_DEBUG in ('Y', 'C') THEN
153 debug(' headers inserted : ' || g_headers_inserted);
154 debug('arp_etax_recurr_util.insert_header()-');
155 END IF;
156
157 EXCEPTION
158 WHEN NO_DATA_FOUND
159 THEN
160 debug('arp_etax_recurr_util.insert_header()- No transaction headers to process.');
161 RETURN;
162 WHEN OTHERS
163 THEN
164 debug('EXCEPTION: ARP_ETAX_RECURR_UTIL.insert_header()-');
165 RAISE;
166
167 END insert_header;
168
169 /* Private Procedure - Inserts lines (not tax) into ZX_TRANSACTION_LINES_GT.
170 NOTE: In order for tax to work properly for copied invoices, we
171 must populate the source columns for the copied lines with the
172 data from the original (AR) lines.
173
174 DEV NOTE: Questions...
175
176 1) How do I insert manual tax lines in invoice copy? What fields are
177 required?
178
179 RESP: Harsh says that I do not insert anything into the ZX_TAX_LINES
180 table. Rather, I populate the SOURCE columns on the copied invoice
181 lines (in ZX table) with the line info from the original invoice
182 line.
183
184 */
185 PROCEDURE insert_line(
186 p_orig_line_id IN NUMBER,
187 p_new_line_id IN NUMBER) IS
188
189 l_so_org_id VARCHAR2(20);
190 l_lines_updated NUMBER;
191 BEGIN
192 IF PG_DEBUG in ('Y', 'C') THEN
193 debug('arp_etax_recurr_util.insert_line()+');
194 END IF;
195
196 l_so_org_id := oe_profile.value('SO_ORGANIZATION_ID',
197 arp_global.sysparam.org_id);
198
199 /* 4666566 - added support for ship_to and product_org_id to
200 line-level insert. Invoice copy automatically copies ship to
201 to line-level to make it more like autoinvoice. */
202
203 INSERT INTO ZX_TRANSACTION_LINES_GT
204 (
205 application_id,
206 entity_code,
207 event_class_code,
208 interface_entity_code,
209 interface_line_id,
210 trx_id,
211 trx_level_type,
212 trx_line_id,
213 line_class,
214 line_level_action,
215 trx_shipping_date,
216 trx_line_type,
217 trx_line_date,
218 line_amt_includes_tax_flag,
219 line_amt,
220 trx_line_quantity,
221 unit_price,
222 exempt_certificate_number,
223 exempt_reason_code,
224 exemption_control_flag,
225 product_id, -- inventory item or memo line
226 product_org_id, -- warehouse_id
227 uom_code,
228 fob_point,
229 ship_from_party_id, -- warehouse_id
230 ship_from_location_id, -- warehouse location
231 ship_to_party_id,
232 ship_to_party_site_id,
233 bill_to_party_id,
234 bill_to_party_site_id,
235 source_application_id,
236 source_entity_code,
237 source_event_class_code,
238 source_trx_id,
239 source_line_id,
240 source_trx_level_type,
241 output_tax_classification_code,
242 trx_line_number,
243 historical_flag,
244 ctrl_hdr_tx_appl_flag, -- 'N'
245 trx_line_gl_date,
246 ship_to_location_id,
247 bill_to_location_id,
248 trx_line_currency_code,
249 trx_line_precision,
250 trx_line_mau,
251 ship_third_pty_acct_id,
252 ship_third_pty_acct_site_id,
253 ship_to_cust_acct_site_use_id,
254 poa_party_id,
255 poa_location_id,
256 poo_party_id,
257 poo_location_id,
258 cash_discount,
259 bill_from_location_id,
260 account_ccid,
261 trx_line_description,
262 product_category
263 )
264 SELECT
265 222,
266 ZTH.entity_code,
267 ZTH.event_class_code,
268 NULL,
269 NULL,
270 TL.customer_trx_id,
271 'LINE',
272 TL.customer_trx_line_id,
273 'INVOICE',
274 'COPY_AND_CREATE',
275 NVL(TL.sales_order_date,T.ship_date_actual),
276 DECODE(TL.inventory_item_id, NULL, 'MISC', 'ITEM'),
277 NULL,
278 DECODE(TL.amount_includes_tax_flag,'Y','A','N','N','S'),
279 TL.extended_amount,
280 TL.quantity_invoiced,
281 TL.unit_selling_price,
282 TL.tax_exempt_number,
283 TL.tax_exempt_reason_code,
284 TL.tax_exempt_flag,
285 NVL(TL.inventory_item_id, TL.memo_line_id), -- product_id
286 DECODE(TL.memo_line_id, NULL,
287 NVL(TL.warehouse_id,to_number(l_so_org_id)), NULL), -- product_org_id
288 TL.uom_code,
289 T.fob_point,
290 TL.warehouse_id, -- ship_from_party_id
291 HR.location_id, -- ship_from_location_id
292 STCA.party_id, -- ship to party
293 STPS.party_site_id, -- ship to site
294 ZTH.rounding_bill_to_party_id, -- bill to party
295 ZTH.rndg_bill_to_party_site_id, -- bill to site
296 -- null, account_ccid (set in subsequent update)
297 222,
298 ZTH.entity_code,
299 ZTH.event_class_code,
300 TL_ORIG.customer_trx_id,
301 TL_ORIG.customer_trx_line_id,
302 'LINE',
303 TL.tax_classification_code,
304 TL.line_number,
305 TL.historical_flag,
306 'N',
307 NVL(REC.gl_date, TRUNC(sysdate)),
308 STPSU.location_id,
309 BTPSU.location_id,
310 ZTH.trx_currency_code,
311 ZTH.precision,
312 ZTH.minimum_accountable_unit,
313 TL.ship_to_customer_id,
314 STPS.cust_acct_site_id, -- ship_third_pty_site_id
315 STCSU.site_use_id,
316 ZTH.internal_organization_id, -- poa_party_id
317 ZTH.internal_org_location_id, -- poa_location_id
318 ZTH.internal_organization_id, -- poo_party_id (default val)
319 ZTH.internal_org_location_id, -- poo_location_id (default val)
320 TL.extended_amount * arp_etax_util.get_discount_rate(T.customer_trx_id),
321 ZTH.internal_org_location_id, -- bill_from_location_id
322 ( SELECT max(code_combination_id)
323 FROM ra_cust_trx_line_gl_dist gld
324 WHERE gld.customer_trx_line_id = TL.customer_trx_line_id
325 AND gld.account_class = 'REV') account_ccid,
326 TL.description,
327 ML.tax_product_category
328 FROM
329 RA_CUSTOMER_TRX_LINES TL,
330 RA_CUSTOMER_TRX_LINES TL_ORIG,
331 RA_CUSTOMER_TRX T,
332 ZX_TRX_HEADERS_GT ZTH,
333 HZ_CUST_ACCOUNTS STCA,
334 HZ_CUST_ACCT_SITES STPS,
335 HZ_CUST_SITE_USES STCSU,
336 RA_CUST_TRX_LINE_GL_DIST REC,
337 HZ_PARTY_SITES STPSU,
338 HZ_PARTY_SITES BTPSU,
339 HR_ALL_ORGANIZATION_UNITS HR,
340 AR_MEMO_LINES_B ML
341 WHERE
342 TL.customer_trx_line_id = p_new_line_id
343 AND TL.line_type = 'LINE'
344 AND TL.customer_trx_id = T.customer_trx_id
345 AND TL.customer_trx_id = ZTH.trx_id
346 AND TL_ORIG.customer_trx_line_id = p_orig_line_id
347 AND TL.ship_to_customer_id =
348 STCA.cust_account_id (+)
349 AND TL.ship_to_site_use_id =
350 STCSU.site_use_id (+)
351 AND STCSU.cust_acct_site_id = STPS.cust_acct_site_id (+)
352 AND STPS.party_site_id = STPSU.party_site_id (+)
353 AND ZTH.rndg_bill_to_party_site_id = BTPSU.party_site_id
354 AND REC.customer_trx_id (+) = T.customer_trx_id
355 AND REC.account_class (+) = 'REC'
356 AND REC.latest_rec_flag (+) = 'Y'
357 AND TL.warehouse_id = HR.organization_id (+)
358 AND TL.memo_line_id = ML.memo_line_id (+)
359 AND TL.org_id = ML.org_id (+);
360
361 g_lines_inserted := SQL%ROWCOUNT;
362
363 IF PG_DEBUG in ('Y','C') THEN
364 debug('lines inserted = ' || g_lines_inserted);
365 END IF;
366
367 /* 6874006 - removed salesrep/person logic from main insert
368 and shifted it to a separate UPDATE */
369 update zx_transaction_lines ZXL
370 set (poo_party_id, poo_location_id) =
371 (select SR_PER.organization_id, -- poo_party_id
372 SR_HRL.location_id -- poo_location_id
373 from RA_CUSTOMER_TRX TRX,
374 JTF_RS_SALESREPS SR,
375 PER_ALL_ASSIGNMENTS_F SR_PER,
376 HR_ORGANIZATION_UNITS SR_HRL
377 where TRX.customer_trx_id = ZXL.trx_id
378 and TRX.primary_salesrep_id IS NOT NULL
379 and TRX.primary_salesrep_id = SR.salesrep_id
380 and TRX.org_id = SR.org_id
381 and SR.person_id = SR_PER.person_id
382 and TRX.trx_date BETWEEN nvl(SR_PER.effective_start_date, TRX.trx_date)
383 AND nvl(SR_PER.effective_end_date, TRX.trx_date)
384 and NVL(SR_PER.primary_flag, 'Y') = 'Y'
385 and SR_PER.assignment_type = 'E'
386 and SR_PER.organization_id = SR_HRL.organization_id);
387
388 IF PG_DEBUG in ('Y', 'C') THEN
389 l_lines_updated := SQL%ROWCOUNT;
390 debug('lines update (poo columns) = ' || l_lines_updated);
391 debug('arp_etax_recurr_util.insert_line()-');
392 END IF;
393
394
395 EXCEPTION
396 WHEN OTHERS
397 THEN
398 debug('EXCEPTION: ARP_ETAX_RECURR_UTIL.insert_line()- ' ||
399 SQLERRM);
400 RAISE;
401 END insert_line;
402
403 /* Inserts manual tax lines into IMPORT_GT table when
404 then are present in ra_customer_trx_lines (on original invoice)
405 with autotax flag set to 'N'
406
407 DEV NOTE:
408
409 1) What happens to legacy tax lines? By that I mean tax lines that
410 are autotax=N and predate etax. Are they converted? Can I assume
411 that the fab-five columns in zx_lines will be populated?
412
413 sent email 04/06/05 to harsh/isaac
414 RESP: Harsh says legacy lines are converted too. Yes, those columns
415 will be populated.
416
417 To extend that, I need to populate the SOURCE columns on the copied
418 lines (new ones) with info from the original invoice lines. I do not
419 need to populate teh tax lines using this routine.
420 */
421
422 PROCEDURE insert_tax_lines(
423 p_original_line_id IN NUMBER,
424 p_new_customer_trx_id IN NUMBER,
425 p_new_line_id IN NUMBER,
426 p_request_id IN NUMBER) IS
427 BEGIN
428 IF PG_DEBUG in ('Y', 'C') THEN
429 debug('arp_etax_recurr_util.insert_tax_lines()+');
430 END IF;
431
432 /* NOTE: We are passing the line_id of the original tax line
433 into this table. That means that we can get that same line
434 ID back out when inserting the shadow tax lines into
435 RA_CUSTOMER_TRX_LINES. At this point, I'm not sure
436 we need this, but I thought it was worth noting in case
437 we need to copy DFF values, etc. */
438
439 INSERT INTO ZX_IMPORT_TAX_LINES_GT
440 (
441 internal_organization_id,
442 application_id,
443 entity_code,
444 event_class_code,
445 interface_entity_code,
446 interface_tax_line_id,
447 trx_id,
448 trx_line_id,
449 tax_regime_code,
450 tax,
451 tax_status_code,
452 tax_rate_code,
453 tax_rate,
454 tax_jurisdiction_code,
455 tax_amt,
456 tax_amt_included_flag,
457 tax_exception_id,
458 tax_exemption_id,
459 exempt_reason_code,
460 exempt_certificate_number,
461 tax_line_allocation_flag,
462 summary_tax_line_number -- 4698302
463 )
464 SELECT
465 orig_line.org_id,
466 222,
467 'TRANSACTIONS',
468 'INVOICE',
469 'RA_CUSTOMER_TRX', -- interface_entity
470 p_original_line_id, -- interface_line_id
471 p_new_customer_trx_id,
472 p_new_line_id,
473 orig_etax.tax_regime_code,
474 orig_etax.tax,
475 orig_etax.tax_status_code,
476 orig_etax.tax_rate_code,
477 orig_etax.tax_rate,
478 orig_etax.tax_jurisdiction_code,
479 orig_tax.extended_amount,
480 orig_tax.amount_includes_tax_flag,
481 orig_etax.tax_exception_id,
482 orig_etax.tax_exemption_id,
483 orig_etax.exempt_reason_code,
484 orig_etax.exempt_certificate_number,
485 'N', -- no rows in LINK table
486 0 -- 4698302
487 FROM
488 RA_CUSTOMER_TRX_LINES orig_line,
489 RA_CUSTOMER_TRX_LINES orig_tax,
490 ZX_LINES orig_etax
491 WHERE
492 orig_line.customer_trx_line_id = p_original_line_id
493 AND orig_line.customer_trx_line_id = orig_tax.link_to_cust_trx_line_id
494 AND orig_tax.line_type = 'TAX'
495 AND NVL(orig_tax.autotax, 'N') = 'N'
496 AND orig_tax.tax_line_id = orig_etax.tax_line_id (+);
497
498 g_tax_lines_inserted := SQL%ROWCOUNT;
499
500 IF PG_DEBUG in ('Y', 'C') THEN
501 debug('arp_etax_recurr_util.insert_tax_lines()-');
502 END IF;
503
504 EXCEPTION
505 WHEN OTHERS
506 THEN
507 debug('EXCEPTION: ARP_ETAX_RECURR_UTIL.insert_tax_lines()-');
508 RAISE;
509
510 END insert_tax_lines;
511
512
513 /* Procedure to retrieve TAX lines from ZX and populate
514 RA_CUSTOMER_TRX_LINES accordingly */
515 PROCEDURE build_ar_tax_lines(
516 p_request_id IN NUMBER) IS
517
518 l_rows NUMBER;
519
520 BEGIN
521 IF PG_DEBUG in ('Y', 'C') THEN
522 debug('arp_etax_recurr_util.build_ar_tax_lines()+');
523 END IF;
524
525 /* Dev Notes:
526
527 End Dev Notes */
528
529 /* Insert rows into RA_CUSTOMER_TRX_LINES for the
530 new TAX lines */
531 INSERT INTO RA_CUSTOMER_TRX_LINES
532 (
533 CUSTOMER_TRX_LINE_ID,
534 LAST_UPDATE_DATE,
535 LAST_UPDATED_BY,
536 CREATION_DATE,
537 CREATED_BY,
538 LAST_UPDATE_LOGIN,
539 PROGRAM_ID,
540 PROGRAM_APPLICATION_ID,
541 CUSTOMER_TRX_ID,
542 LINE_NUMBER,
543 SET_OF_BOOKS_ID,
544 LINE_TYPE, -- TAX
545 LINK_TO_CUST_TRX_LINE_ID, -- parent line
546 DEFAULT_USSGL_TRANSACTION_CODE,
547 REQUEST_ID,
548 EXTENDED_AMOUNT,
549 TAX_RATE,
550 AUTOTAX,
551 AMOUNT_INCLUDES_TAX_FLAG,
552 TAXABLE_AMOUNT,
553 VAT_TAX_ID,
554 TAX_LINE_ID, -- ID in ZX_ table
555 ORG_ID
556 )
557 SELECT
558 ra_customer_trx_lines_s.nextval,
559 sysdate,
560 arp_standard.profile.user_id,
561 sysdate,
562 arp_standard.profile.user_id,
563 arp_standard.profile.user_id,
564 arp_standard.profile.program_id,
565 arp_standard.application_id,
566 zxt.trx_id,
567 zxt.tax_line_number,
568 arp_standard.sysparm.set_of_books_id,
569 'TAX',
570 zxt.trx_line_id,
571 plin.default_ussgl_transaction_code,
572 p_request_id,
573 zxt.tax_amt,
574 zxt.tax_rate,
575 DECODE(NVL(zxt.manually_entered_flag, 'N'), 'Y', NULL, 'Y'),
576 zxt.tax_amt_included_flag,
577 zxt.taxable_amt,
578 tax_rate_id,
579 zxt.tax_line_id,
580 plin.org_id
581 FROM ZX_LINES zxt,
582 RA_CUSTOMER_TRX_LINES plin
583 WHERE plin.request_id = p_request_id
584 AND zxt.application_id = 222
585 AND zxt.entity_code = 'TRANSACTIONS'
586 AND zxt.event_class_code in ('INVOICE','DEBIT_MEMO')
587 AND zxt.trx_id = plin.customer_trx_id
588 AND zxt.trx_level_type = 'LINE'
589 AND zxt.trx_line_id = plin.customer_trx_line_id;
590
591 l_rows := SQL%ROWCOUNT;
592
593 IF l_rows > 0
594 THEN
595 /* Stamp transaction lines with tax_classification
596 from ZX_LINES_DET_FACTORS */
597 arp_etax_util.set_default_tax_classification(p_request_id);
598
599 /* adjust for inclusive tax */
600 arp_etax_util.adjust_for_inclusive_tax(null, p_request_id, 'INV');
601 END IF;
602
603 /* Set line_recoverable and tax_recoverable */
604 arp_etax_util.set_recoverable(null, p_request_id, 'INV');
605
606 IF PG_DEBUG in ('Y', 'C') THEN
607 debug(' Number of tax lines retrieved = ' || l_rows);
608 debug('arp_etax_recurr_util.build_ar_tax_lines()-');
609 END IF;
610 END build_ar_tax_lines;
611
612 /* Procedure to extract error/validation messages from ZX
613 and insert them into RA_INTERFACE_ERRORS */
614 PROCEDURE retrieve_tax_validation_errors(p_error_count IN OUT NOCOPY NUMBER) IS
615
616 l_errors NUMBER := 0;
617
618 CURSOR zx_val_err IS
619 SELECT trx_id, trx_line_id, message_text
620 FROM zx_validation_errors_gt;
621
622 BEGIN
623
624 IF PG_DEBUG in ('Y', 'C') THEN
625 debug('arp_etax_recurr_util.retrieve_tax_validation_errors()+');
626 END IF;
627
628 /* Dev Notes:
629
630 Just extracting messages directly to log file. In ARXREC,
631 there is no equivalent to ra_interface_errors.
632
633 */
634
635 FOR val_err IN zx_val_err LOOP
636
637 l_errors := l_errors + 1;
638
639 fnd_file.put_line(FND_FILE.LOG,
640 'customer_trx_id = ' || val_err.trx_id);
641 fnd_file.put_line(FND_FILE.LOG,
642 ' customer_trx_line_id = ' || val_err.trx_line_id);
643 fnd_file.put_line(FND_FILE.LOG, val_err.message_text);
644
645 END LOOP;
646
647 p_error_count := l_errors;
648
649 IF PG_DEBUG in ('Y', 'C') THEN
650 debug('Validation errors: ' || l_errors);
651 debug('arp_etax_recurr_util.retrieve_tax_validation_errors()-');
652 END IF;
653
654 END retrieve_tax_validation_errors;
655
656 /* Internal procedure - calculate_tax_for_copy */
657 /* wrapper for call to zx_api_pub.calculate_tax */
658
659 PROCEDURE calculate_tax_for_copy IS
660 l_return_status VARCHAR2(50);
661 l_message_count NUMBER;
662 l_message_data VARCHAR2(2000);
663 l_msg VARCHAR2(2000);
664 BEGIN
665 ZX_API_PUB.calculate_tax(
666 p_api_version => 1.0,
667 p_init_msg_list => FND_API.G_FALSE,
668 p_commit => FND_API.G_FALSE,
669 p_validation_level => FND_API.G_VALID_LEVEL_FULL,
670 x_return_status => l_return_status,
671 x_msg_count => l_message_count,
672 x_msg_data => l_message_data
673 );
674
675 IF l_return_status = FND_API.G_RET_STS_SUCCESS
676 THEN
677 IF PG_DEBUG in ('Y', 'C') THEN
678 arp_standard.debug('calculate_tax returns successfully');
679 END IF;
680 ELSIF l_return_status = FND_API.G_RET_STS_ERROR
681 THEN
682 IF PG_DEBUG in ('Y', 'C') THEN
683 arp_standard.debug('calculate_tax returns with validation errors');
684 END IF;
685 ELSE /* fatal error */
686 IF PG_DEBUG in ('Y', 'C') THEN
687 arp_standard.debug('calculate_tax returns failure');
688 END IF;
689
690 /* Retrieve and log errors */
691 IF l_message_count = 1
692 THEN
693 debug(l_message_data);
694 ELSIF l_message_count > 1
695 THEN
696 LOOP
697 l_msg := FND_MSG_PUB.Get(FND_MSG_PUB.G_NEXT,
698 FND_API.G_FALSE);
699 IF l_msg IS NULL
700 THEN
701 EXIT;
702 ELSE
703 debug(l_msg);
704 END IF;
705 END LOOP;
706 END IF;
707 END IF;
708
709 END calculate_tax_for_copy;
710
711 /* External public call designed for invoice copy. This will
712 calculate the tax,
713 and insert resulting tax lines back into AR */
714 PROCEDURE calculate_tax(p_request_id IN NUMBER,
715 p_error_count IN OUT NOCOPY NUMBER,
716 p_return_status OUT NOCOPY NUMBER) IS
717 l_return_status NUMBER := 0;
718 BEGIN
719 IF PG_DEBUG in ('Y', 'C')
720 THEN
721 debug('arp_etax_recurr_util.calculate_tax()+');
722 debug('request_id = ' || p_request_id);
723 END IF;
724
725 /* Call validate_and_default_tax_attr */
726 arp_etax_util.validate_tax_int(p_return_status => l_return_status,p_called_from_AI => 'Y');
727 p_return_status := l_return_status;
728
729 IF l_return_status = 0
730 THEN
731 /* retrieve validation errors and display them in log */
732 retrieve_tax_validation_errors(p_error_count);
733
734 /* Call import_document_with_tax */
735 calculate_tax_for_copy;
736
737 /* Pull resulting tax lines and populate RA_CUSTOMER_TRX_LINES */
738 build_ar_tax_lines(p_request_id);
739 END IF;
740
741 /* 4904679 - removed detect_missing_tax_lines */
742
743 IF PG_DEBUG in ('Y', 'C')
744 THEN
745 debug('arp_etax_recurr_util.calculate_tax()-');
746 END IF;
747 END calculate_tax;
748
749
750
751 /*
752
753 /*========================================================================
754 | INITIALIZATION SECTION
755 |
756 | DESCRIPTION
757 | Initialized global variables for controlling program flow
758 |
759 | KNOWN ISSUES
760 |
761 | NOTES
762 |
763 | MODIFICATION HISTORY
764 | Date Author Description of Changes
765 | 28-FEB-2005 MRAYMOND Created
766 *=======================================================================*/
767
768 BEGIN
769 NULL;
770
771 EXCEPTION
772 WHEN OTHERS THEN
773 debug('EXCEPTION: ARP_ETAX_RECURR_UTIL.INITIALIZE()');
774 RAISE;
775
776 END ARP_ETAX_RECURR_UTIL;