[Home] [Help]
PACKAGE BODY: APPS.PO_TAX_INTERFACE_PVT
Source
1 PACKAGE BODY PO_TAX_INTERFACE_PVT AS
2 /* $Header: PO_TAX_INTERFACE_PVT.plb 120.59.12010000.3 2008/11/06 08:57:42 cvardia ship $ */
3 G_PACKAGE_NAME CONSTANT VARCHAR2(30) := 'PO_TAX_INTERFACE_PVT';
4
5 -- Logging global constants
6 D_PACKAGE_BASE CONSTANT VARCHAR2(100) := PO_LOG.get_package_base(G_PACKAGE_NAME);
7
8 -- Private procedure declarations
9 PROCEDURE populate_zx_headers_with_po(p_po_header_id_tbl IN PO_TBL_NUMBER,
10 p_calling_program IN VARCHAR2);
11
12 PROCEDURE populate_header_po(p_po_header_id IN NUMBER);
13
14 PROCEDURE populate_zx_headers_with_rel(p_po_release_id_tbl IN PO_TBL_NUMBER,
15 p_calling_program IN VARCHAR2);
16
17 PROCEDURE populate_header_rel(p_po_release_id IN NUMBER);
18
19 PROCEDURE populate_zx_headers_with_req(p_requisition_header_id IN NUMBER,
20 p_calling_program IN VARCHAR2);
21
22 PROCEDURE populate_zx_lines_with_po(p_po_header_id_tbl IN PO_TBL_NUMBER,
23 p_calling_program IN VARCHAR2);
24
25 PROCEDURE populate_zx_lines_with_rel(p_po_release_id_tbl IN PO_TBL_NUMBER,
26 p_calling_program IN VARCHAR2);
27
28 PROCEDURE populate_zx_lines_with_req(p_requisition_header_id IN NUMBER,
29 p_calling_program IN VARCHAR2);
30
31 PROCEDURE populate_zx_dists_with_po(p_po_header_id_tbl IN PO_TBL_NUMBER,
32 p_calling_program IN VARCHAR2);
33
34 PROCEDURE populate_all_dists_po(p_po_header_id IN NUMBER);
35
36 PROCEDURE populate_zx_dists_with_rel(p_po_release_id_tbl IN PO_TBL_NUMBER,
37 p_calling_program IN VARCHAR2);
38
39 PROCEDURE populate_all_dists_rel(p_po_release_id IN NUMBER);
40
41 PROCEDURE populate_zx_dists_with_req(p_requisition_header_id IN NUMBER,
42 p_calling_program IN VARCHAR2);
43
44 PROCEDURE populate_zx_record(p_requisition_header_id IN NUMBER);
45
46 PROCEDURE initialize_zx_gt_tables;
47
48 PROCEDURE wipe_zx_gt_tables;
49
50 PROCEDURE log_header_tax_attributes(p_module_base IN VARCHAR2,
51 p_progress IN NUMBER);
52
53 PROCEDURE log_line_tax_attributes(p_module_base IN VARCHAR2,
54 p_progress IN NUMBER);
55
56 PROCEDURE log_dist_tax_attributes(p_module_base IN VARCHAR2,
57 p_progress IN NUMBER);
58
59 PROCEDURE log_po_tauc(p_module_base IN VARCHAR2,
60 p_progress IN NUMBER,
61 p_po_header_id_tbl IN PO_TBL_NUMBER);
62
63 PROCEDURE log_rel_tauc(p_module_base IN VARCHAR2,
64 p_progress IN NUMBER,
65 p_po_release_id_tbl IN PO_TBL_NUMBER);
66
67 PROCEDURE log_req_tauc(p_module_base IN VARCHAR2,
68 p_progress IN NUMBER,
69 p_requisition_header_id IN NUMBER);
70
71 PROCEDURE log_global_error_record(p_module_base IN VARCHAR2,
72 p_progress IN NUMBER);
73
74 CURSOR successful_documents_csr(p_requisition_header_id IN NUMBER) IS
75 SELECT zxlgt.trx_line_id
76 FROM zx_transaction_lines_gt zxlgt
77 WHERE p_requisition_header_id=zxlgt.trx_id
78 AND p_requisition_header_id NOT IN (SELECT trx_id FROM zx_errors_gt zxegt)
79 AND zxlgt.application_id = PO_CONSTANTS_SV.APPLICATION_ID
80 AND zxlgt.entity_code = PO_CONSTANTS_SV.REQ_ENTITY_CODE
81 AND zxlgt.event_class_code = PO_CONSTANTS_SV.REQ_EVENT_CLASS_CODE;
82
83
84 -----------------------------------------------------------------------------
85 --Start of Comments
86 --Name: calculate_tax
87 --Pre-reqs:
88 -- Should be called when transaction data has been posted to the database
89 -- but not yet committed
90 --Modifies:
91 -- PO_LINE_LOCATIONS_ALL.tax_attribute_update_code
92 -- PO_LINE_LOCATIONS_ALL.original_shipment_id
93 -- PO_LINE_LOCATIONS_ALL.taxable_flag
94 -- PO_DISTRIBUTIONS_ALL.nonrecoverable_tax
95 -- PO_DISTRIBUTIONS_ALL.recoverable_tax
96 --Locks:
97 -- Transaction tables if update is allowed
98 --Function:
99 -- Calculate tax amounts for the documents passed in
100 --Parameters:
101 --IN:
102 --p_po_header_id_tbl
103 -- Table of po_header_id values for which tax is to be calculated
104 --p_po_release_id_tbl
105 -- Table of po_release_id values for which tax is to be calculated
106 --p_calling_program
107 -- Identifies the module that calls this procedure eg. 'PDOI'
108 --OUT:
109 --x_return_status
110 -- Standard API specification parameter
111 -- Can hold one of the following values:
112 -- FND_API.G_RET_STS_SUCCESS (='S')
113 -- FND_API.G_RET_STS_ERROR (='E')
114 -- FND_API.G_RET_STS_UNEXP_ERROR (='U')
115 --Notes:
116 -- 1. Calls out to EBTax APIs calculate_tax and determine recovery to
117 -- generate tax lines and distributions. Populates recoverable_tax and
118 -- nonrecoverable_tax columns in distributions with the corrsponding tax
119 -- amounts calculated.
120 -- 2. Returns all expected errors from etax API's in global tax error record
121 --End of Comments
122 -----------------------------------------------------------------------------
123 PROCEDURE calculate_tax(p_po_header_id_tbl IN PO_TBL_NUMBER,
124 p_po_release_id_tbl IN PO_TBL_NUMBER,
125 p_calling_program IN VARCHAR2,
126 x_return_status OUT NOCOPY VARCHAR2
127 ) IS
128 l_module_name CONSTANT VARCHAR2(100) := 'CALCULATE_TAX';
129 d_module_base CONSTANT VARCHAR2(100) := PO_LOG.get_subprogram_base(
130 D_PACKAGE_BASE, l_module_name);
131 d_progress NUMBER;
132 l_msg_count NUMBER;
133 l_msg_data VARCHAR2(1000);
134 l_count NUMBER;
135 l_return_status VARCHAR2(1);
136 l_po_session_gt_key PO_SESSION_GT.key%TYPE;
137 l_transaction_line_rec_type ZX_API_PUB.transaction_line_rec_type;
138 BEGIN
139 -- PO_SESSION_GT mappings:
140 --------------------------------------------------
141 -- / INDEX_NUM1 = trx_id \
142 -- / NUM1 = trx_line_id \
143 -- / NUM2 = trx_line_dist_id \
144 -- / CHAR1 = event_class_code \
145 -- \ CHAR2 = message_text /
146 -- \ CHAR3 = error_level /
147 -- \ CHAR4 = trx_num /
148 -- \ /
149
150 SAVEPOINT calculate_tax_savepoint;
151
152 IF (PO_LOG.d_proc) THEN
153 PO_LOG.proc_begin(d_module_base);
154 PO_LOG.proc_begin(d_module_base, 'p_po_header_id_tbl', p_po_header_id_tbl);
155 PO_LOG.proc_begin(d_module_base, 'p_po_release_id_tbl', p_po_release_id_tbl);
156 PO_LOG.proc_begin(d_module_base, 'p_calling_program', p_calling_program);
157 END IF;
158
159 d_progress := 0;
160
161 -- By default return status is SUCCESS if no exception occurs
162 x_return_status := FND_API.G_RET_STS_SUCCESS;
163 -- Set global error record to uninitialized local record to set all its
164 -- components to null
165 G_TAX_ERRORS_TBL := null;
166 d_progress := 10;
167 initialize_zx_gt_tables(); -- Wipe ZX GT tables clean
168 d_progress := 20;
169 initialize_global_error_record();
170 d_progress := 30;
171 SELECT po_session_gt_s.NEXTVAL INTO l_po_session_gt_key FROM dual;
172
173 IF PO_LOG.d_stmt THEN
174 PO_LOG.stmt(d_module_base,d_progress,'l_po_session_gt_key='||l_po_session_gt_key);
175 END IF;
176
177 d_progress := 40;
178 IF PO_LOG.d_stmt THEN
179 PO_LOG.stmt(d_module_base,d_progress,'initial values of tax_attribute_update_codes');
180 log_po_tauc(d_module_base,d_progress,p_po_header_id_tbl);
181 log_rel_tauc(d_module_base,d_progress,p_po_release_id_tbl);
182 END IF;
183 -- Percolate header and line level tax_attribute_update_code values to
184 -- shipment level so that the shipment level values get filled up
185
186 -- 1. If shipment tax_attribute_update_code is anything other than null
187 -- or DIST_DELETE then don't update (note that even if it is DIST_DELETE,
188 -- it will be overridden by line or headers value - last where clause
189 -- 2. If both line and header level tax_attribute_update_code are null
190 -- then keep the shipment level value. So the inner query is wrapped
191 -- inside an nvl that rewrites the shipment tax_attribute_update_code
192 -- if the shipment tax_attribute_update_code is being updated to null
193 -- 3. If none of the above problems exist then update shipment
194 -- tax_attribute_update_code with line or header tax_attribute_update_code
195 -- whichever is non-null in that order
196 FORALL i IN 1..p_po_header_id_tbl.COUNT
197 UPDATE po_line_locations_all pll
198 SET pll.tax_attribute_update_code =
199 NVL(
200 (SELECT NVL(pl.tax_attribute_update_code, ph.tax_attribute_update_code)
201 FROM po_headers_all ph, po_lines_all pl
202 WHERE pll.po_line_id = pl.po_line_id
203 AND pll.po_header_id = ph.po_header_id
204 -- following AND written only for clarity
205 --AND (pl.tax_attribute_update_code IS NOT NULL
206 -- or ph.tax_attribute_update_code IS NOT NULL)
207 )
208 ,pll.tax_attribute_update_code
209 )
210 WHERE
211 pll.po_header_id = p_po_header_id_tbl(i)
212 AND (pll.tax_attribute_update_code IS NULL
213 OR pll.tax_attribute_update_code = 'DIST_DELETE');
214
215 d_progress := 50;
216 FORALL i IN 1..p_po_release_id_tbl.COUNT
217 UPDATE po_line_locations_all pll
218 SET pll.tax_attribute_update_code =
219 NVL(
220 (SELECT ph.tax_attribute_update_code
221 FROM po_headers_all ph
222 WHERE pll.po_header_id = ph.po_header_id
223 -- following AND written only for clarity
224 --AND ph.tax_attribute_update_code IS NOT NULL
225 )
226 ,pll.tax_attribute_update_code
227 )
228 WHERE
229 pll.po_release_id = p_po_release_id_tbl(i)
230 AND (pll.tax_attribute_update_code IS NULL
231 OR pll.tax_attribute_update_code = 'DIST_DELETE');
232
233 IF PO_LOG.d_stmt THEN
234 PO_LOG.stmt(d_module_base,d_progress,'tax_attribute_update_codes after denormalization');
235 log_po_tauc(d_module_base,d_progress,p_po_header_id_tbl);
236 log_rel_tauc(d_module_base,d_progress,p_po_release_id_tbl);
237 END IF;
238
239 -- Populate ZX headers and lines GT tables with transaction data
240 d_progress := 60;
241 populate_zx_headers_with_po(p_po_header_id_tbl, p_calling_program);
242 d_progress := 70;
243 populate_zx_headers_with_rel(p_po_release_id_tbl, p_calling_program);
244 d_progress := 80;
245 populate_zx_lines_with_po(p_po_header_id_tbl, p_calling_program);
246 d_progress := 90;
247 populate_zx_lines_with_rel(p_po_release_id_tbl, p_calling_program);
248
249 d_progress := 100;
250 -- Call eTax API calculate_tax to construct tax lines
251 -- For lines wih line_level_action of COPY_AND_CREATE eTax will use
252 -- Additional Tax Attributes from source doucment to create the tax lines
253 BEGIN
254 SELECT COUNT(1) INTO l_count FROM zx_transaction_lines_gt;
255 EXCEPTION WHEN OTHERS THEN
256 l_count := 0;
257 IF PO_LOG.d_stmt THEN
258 PO_LOG.stmt(d_module_base,d_progress,'Exception while selecting from zx_transaction_lines_gt');
259 END IF;
260 END;
261
262 IF PO_LOG.d_stmt THEN
263 PO_LOG.stmt(d_module_base,d_progress,'Number of rows in zx_transaction_lines_gt='||l_count);
264 END IF;
265
266 IF (l_count <> 0) THEN
267
268 d_progress := 110;
269 -- Log table parameters
270 IF PO_LOG.d_stmt THEN
271 PO_LOG.stmt(d_module_base,d_progress,'Table parameters before eTax default/redefault');
272 log_header_tax_attributes(d_module_base,d_progress);
273 log_line_tax_attributes(d_module_base,d_progress);
274 END IF;
275
276 -- Call the eTax defaulting/redefaulting APIs which populate the
277 -- Additional Tax Attributes back into the ZX GT tables
278 IF (p_calling_program = 'PDOI') THEN
279 d_progress := 120;
280 -- For PDOI, eTax needs to do extra validations since data is entered by
281 -- user in interface tables. So call validate_and_default_tax_attribs
282 -- Only need to default, not redefault because through PDOI POs can only
283 -- be added to, not updated
284 IF PO_LOG.d_stmt THEN
285 PO_LOG.stmt(d_module_base,d_progress,'Calling validate_and_default_tax_attr');
286 END IF;
287 ZX_API_PUB.validate_and_default_tax_attr(
288 p_api_version => 1.0,
289 p_init_msg_list => FND_API.G_TRUE,
290 p_commit => FND_API.G_FALSE,
291 p_validation_level => FND_API.G_VALID_LEVEL_FULL,
292 x_return_status => l_return_status,
293 x_msg_count => l_msg_count,
294 x_msg_data => l_msg_data
295 );
296
297 d_progress := 130;
298 IF PO_LOG.d_stmt THEN
299 PO_LOG.stmt(d_module_base,d_progress,'validate_and_default_tax_attr returned with status '||l_return_status);
300 END IF;
301
302 -- Raise if any unexpected error
303 IF (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
304 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
305 END IF;
306
307 -- If expected errors, store error details in po_session_gt temporarily
308 IF (l_return_status = FND_API.G_RET_STS_ERROR) THEN
309 d_progress := 140;
310 x_return_status := l_return_status;
311 INSERT INTO po_session_gt(
312 key
313 ,index_num1
314 ,num1
315 ,num2
316 ,char1
317 ,char2
318 ,char3
319 ,char4
320 )
321 SELECT
322 l_po_session_gt_key
323 ,zxvegt.trx_id
324 ,zxvegt.trx_line_id
325 ,null
326 ,zxvegt.event_class_code
327 ,zxvegt.message_text
328 ,'VALIDATE'
329 ,ph.segment1
330 FROM zx_validation_errors_gt zxvegt, po_headers_all ph
331 WHERE zxvegt.event_class_code = PO_CONSTANTS_SV.PO_EVENT_CLASS_CODE
332 AND zxvegt.trx_id = ph.po_header_id;
333
334 d_progress := 150;
335 INSERT INTO po_session_gt(
336 key
337 ,index_num1
338 ,num1
339 ,num2
340 ,char1
341 ,char2
342 ,char3
343 ,char4
344 )
345 SELECT
346 l_po_session_gt_key
347 ,zxvegt.trx_id
348 ,zxvegt.trx_line_id
349 ,null
350 ,zxvegt.event_class_code
351 ,zxvegt.message_text
352 ,'VALIDATE'
353 ,ph.segment1
354 FROM zx_validation_errors_gt zxvegt, po_headers_all ph,
355 po_releases_all pr
356 WHERE zxvegt.event_class_code = PO_CONSTANTS_SV.REL_EVENT_CLASS_CODE
357 AND zxvegt.trx_id = pr.po_release_id
358 AND pr.po_header_id = ph.po_header_id;
359
360 BEGIN
361 SELECT COUNT(1) INTO l_count FROM zx_validation_errors_gt;
362 EXCEPTION WHEN OTHERS THEN
363 IF PO_LOG.d_stmt THEN
364 PO_LOG.stmt(d_module_base,d_progress,'Exception while hitting zx_validation_errors_gt');
365 END IF;
366 l_count := 0;
367 END;
368
369 IF PO_LOG.d_stmt THEN
370 PO_LOG.stmt(d_module_base,d_progress,'Number of records in zx_validation_errors_gt '||l_count);
371 END IF;
372
373 END IF;
374
375 d_progress := 160;
376 -- Delete data from zx gt tables for which defaulting/redefaulting failed
377 DELETE FROM zx_trx_headers_gt
378 WHERE trx_id IN (SELECT DISTINCT index_num1 FROM po_session_gt psgt
379 WHERE psgt.key = l_po_session_gt_key
380 AND psgt.char1 = PO_CONSTANTS_SV.PO_EVENT_CLASS_CODE);
381 d_progress := 170;
382 DELETE FROM zx_transaction_lines_gt
383 WHERE trx_id IN (SELECT DISTINCT index_num1 FROM po_session_gt psgt
384 WHERE psgt.key = l_po_session_gt_key
385 AND psgt.char1 = PO_CONSTANTS_SV.PO_EVENT_CLASS_CODE);
386
387 ELSIF (p_calling_program <> 'COPY_DOCUMENT') THEN
388 d_progress := 180;
389 -- This API cannot handle the presence of COPY_AND_CREATE line level
390 -- actions so call is prevented if calling program is COPY_DOCUMENT
391 IF PO_LOG.d_stmt THEN
392 PO_LOG.stmt(d_module_base,d_progress,'Calling get_default_tax_det_attribs');
393 END IF;
394 ZX_API_PUB.get_default_tax_det_attribs(
395 p_api_version => 1.0,
396 p_init_msg_list => FND_API.G_TRUE,
397 p_commit => FND_API.G_FALSE,
398 p_validation_level => FND_API.G_VALID_LEVEL_FULL,
399 x_return_status => l_return_status,
400 x_msg_count => l_msg_count,
401 x_msg_data => l_msg_data
402 );
403
404 d_progress := 190;
405 IF PO_LOG.d_stmt THEN
406 PO_LOG.stmt(d_module_base,d_progress,'get_default_tax_det_attribs returned with status '||l_return_status);
407 END IF;
408
409 -- This API cannot give expected errors. However raise unexpected errors
410 IF (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
411 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
412 END IF;
413
414 END IF; -- IF (p_calling_program = 'PDOI')
415
416
417 d_progress := 200;
418 -- Override product_type Additional Tax Attribute if not already populated
419 -- by eTax defaulting/redefaulting API
420 UPDATE zx_transaction_lines_gt zxlgt
421 SET zxlgt.product_type =
422 (SELECT DECODE(pl.purchase_basis,
423 'GOODS', 'GOODS',
424 'SERVICES')
425 FROM po_line_locations_all pll, po_lines_all pl
426 WHERE pll.line_location_id = zxlgt.trx_line_id
427 AND pll.po_line_id = pl.po_line_id)
428 WHERE zxlgt.product_type IS NULL
429 AND zxlgt.line_level_action = 'CREATE';
430
431 d_progress := 210;
432
433 -- Log table parameters
434 IF PO_LOG.d_stmt THEN
435 PO_LOG.stmt(d_module_base,d_progress,'Table parameters before calculate_tax');
436 log_header_tax_attributes(d_module_base,d_progress);
437 log_line_tax_attributes(d_module_base,d_progress);
438 END IF;
439
440 ZX_API_PUB.calculate_tax(
441 p_api_version => 1.0,
442 p_init_msg_list => FND_API.G_TRUE,
443 p_commit => FND_API.G_FALSE,
444 p_validation_level => FND_API.G_VALID_LEVEL_FULL,
445 x_return_status => l_return_status,
446 x_msg_count => l_msg_count,
447 x_msg_data => l_msg_data
448 );
449
450 d_progress := 220;
451 IF PO_LOG.d_stmt THEN
452 PO_LOG.stmt(d_module_base,d_progress,'calculate_tax returned with status '||l_return_status);
453 END IF;
454
455 -- Raise if any unexpected error
456 IF (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
457 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
458 END IF;
459
460 -- If expected errors, store error details in po_session_gt temporarily
461 IF (l_return_status = FND_API.G_RET_STS_ERROR) THEN
462 x_return_status := l_return_status;
463 d_progress := 230;
464 INSERT INTO po_session_gt(
465 key
466 ,index_num1
467 ,num1
468 ,num2
469 ,char1
470 ,char2
471 ,char3
472 ,char4
473 )
474 SELECT
475 l_po_session_gt_key
476 ,zxegt.trx_id
477 ,zxegt.trx_line_id
478 ,zxegt.trx_line_dist_id
479 ,zxegt.event_class_code
480 ,zxegt.message_text
481 ,'CALCULATE_TAX'
482 ,ph.segment1
483 FROM zx_errors_gt zxegt, po_headers_all ph
484 WHERE zxegt.event_class_code = PO_CONSTANTS_SV.PO_EVENT_CLASS_CODE
485 AND zxegt.trx_id = ph.po_header_id;
486
487 d_progress := 240;
488 INSERT INTO po_session_gt(
489 key
490 ,index_num1
491 ,num1
492 ,num2
493 ,char1
494 ,char2
495 ,char3
496 ,char4
497 )
498 SELECT
499 l_po_session_gt_key
500 ,zxegt.trx_id
501 ,zxegt.trx_line_id
502 ,zxegt.trx_line_dist_id
503 ,zxegt.event_class_code
504 ,zxegt.message_text
505 ,'CALCULATE_TAX'
506 ,ph.segment1
507 FROM zx_errors_gt zxegt, po_headers_all ph, po_releases_all pr
508 WHERE zxegt.event_class_code = PO_CONSTANTS_SV.REL_EVENT_CLASS_CODE
509 AND zxegt.trx_id = pr.po_release_id
510 AND pr.po_header_id = ph.po_header_id;
511
512 BEGIN
513 SELECT COUNT(1) INTO l_count FROM zx_errors_gt;
514 EXCEPTION WHEN OTHERS THEN
515 IF PO_LOG.d_stmt THEN
516 PO_LOG.stmt(d_module_base,d_progress,'Exception while hitting zx_errors_gt');
517 END IF;
518 l_count := 0;
519 END;
520
521 IF PO_LOG.d_stmt THEN
522 PO_LOG.stmt(d_module_base,d_progress,'Number of records in zx_errors_gt '||l_count);
523 END IF;
524
525 END IF;
526
527 d_progress := 250;
528 -- Delete data from zx gt tables for which defaulting/redefaulting failed
529 DELETE FROM zx_trx_headers_gt
530 WHERE trx_id IN (SELECT DISTINCT index_num1 FROM po_session_gt psgt
531 WHERE psgt.key = l_po_session_gt_key
532 AND psgt.char1 = PO_CONSTANTS_SV.PO_EVENT_CLASS_CODE
533 AND psgt.char3 = 'CALCULATE_TAX');
534 d_progress := 260;
535 DELETE FROM zx_trx_headers_gt
536 WHERE trx_id IN (SELECT DISTINCT index_num1 FROM po_session_gt psgt
537 WHERE psgt.key = l_po_session_gt_key
538 AND psgt.char1 = PO_CONSTANTS_SV.REL_EVENT_CLASS_CODE
539 AND psgt.char3 = 'CALCULATE_TAX');
540 d_progress := 270;
541 DELETE FROM zx_transaction_lines_gt
542 WHERE trx_id IN (SELECT DISTINCT index_num1 FROM po_session_gt psgt
543 WHERE psgt.key = l_po_session_gt_key
544 AND psgt.char1 = PO_CONSTANTS_SV.PO_EVENT_CLASS_CODE
545 AND psgt.char3 = 'CALCULATE_TAX');
546 d_progress := 280;
547 DELETE FROM zx_transaction_lines_gt
548 WHERE trx_id IN (SELECT DISTINCT index_num1 FROM po_session_gt psgt
549 WHERE psgt.key = l_po_session_gt_key
550 AND psgt.char1 = PO_CONSTANTS_SV.REL_EVENT_CLASS_CODE
551 AND psgt.char3 = 'CALCULATE_TAX');
552
553 END IF; -- IF (l_count <> 0)
554
555 d_progress := 290;
556 -- Populate ZX distributions GT table with transaction distribution data
557 populate_zx_dists_with_po(p_po_header_id_tbl, p_calling_program);
558 d_progress := 300;
559 populate_zx_dists_with_rel(p_po_release_id_tbl, p_calling_program);
560
561 d_progress := 310;
562 -- Call eTax API determine_recovery to distribute tax lines
563 BEGIN
564 SELECT COUNT(1) INTO l_count FROM zx_itm_distributions_gt;
565 EXCEPTION WHEN OTHERS THEN
566 l_count := 0;
567 IF PO_LOG.d_stmt THEN
568 PO_LOG.stmt(d_module_base,d_progress,'Exception while selecting from zx_itm_distributions_gt');
569 END IF;
570 END;
571
572 IF PO_LOG.d_stmt THEN
573 PO_LOG.stmt(d_module_base,d_progress,'Number of rows in zx_itm_distributions_gt='||l_count);
574 END IF;
575
576 IF (l_count <> 0) THEN
577 d_progress := 320;
578 -- Update event_type_code on zx headers as required by determine_recovery API
579 -- Update to DISTRIBUTED only if all distributions have
580 -- tax_attribute_update_code = 'CREATE'
581 UPDATE zx_trx_headers_gt zxhgt
582 SET zxhgt.event_type_code =
583 DECODE(zxhgt.event_class_code,
584 PO_CONSTANTS_SV.PO_EVENT_CLASS_CODE,
585 NVL2((SELECT 'EXISTING DISTRIBUTIONS'
586 FROM DUAL
587 WHERE EXISTS
588 (SELECT 'Y'
589 FROM po_distributions_all pd
590 WHERE pd.po_header_id = zxhgt.trx_id
591 AND (pd.tax_attribute_update_code <> 'CREATE'
592 OR pd.tax_attribute_update_code IS NULL)
593 )
594 ),
595 PO_CONSTANTS_SV.PO_REDISTRIBUTED,
596 PO_CONSTANTS_SV.PO_DISTRIBUTED
597 ),
598 --Release
599 NVL2((SELECT 'EXISTING DISTRIBUTIONS'
600 FROM DUAL
601 WHERE EXISTS
602 (SELECT 'Y'
603 FROM po_distributions_all pd
604 WHERE pd.po_release_id = zxhgt.trx_id
605 AND (pd.tax_attribute_update_code <> 'CREATE'
606 OR pd.tax_attribute_update_code IS NULL)
607 )
608 ),
609 PO_CONSTANTS_SV.REL_REDISTRIBUTED,
610 PO_CONSTANTS_SV.REL_DISTRIBUTED
611 )
612 );
613
614 d_progress := 330;
615
616 -- Log table parameters
617 IF PO_LOG.d_stmt THEN
618 PO_LOG.stmt(d_module_base,d_progress,'Table parameters before determine_recovery');
619 log_header_tax_attributes(d_module_base,d_progress);
620 log_line_tax_attributes(d_module_base,d_progress);
621 log_dist_tax_attributes(d_module_base,d_progress);
622 END IF;
623
624 ZX_API_PUB.determine_recovery(
625 p_api_version => 1.0,
626 p_init_msg_list => FND_API.G_TRUE,
627 p_commit => FND_API.G_FALSE,
628 p_validation_level => FND_API.G_VALID_LEVEL_FULL,
629 x_return_status => l_return_status,
630 x_msg_count => l_msg_count,
631 x_msg_data => l_msg_data
632 );
633
634 d_progress := 340;
635 IF PO_LOG.d_stmt THEN
636 PO_LOG.stmt(d_module_base,d_progress,'determine_recovery returned with status '||l_return_status);
637 END IF;
638
639 -- Raise if any unexpected error
640 IF (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
641 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
642 END IF;
643
644 -- If expected errors, store error details in po_session_gt temporarily
645 IF (l_return_status = FND_API.G_RET_STS_ERROR) THEN
646 x_return_status := l_return_status;
647 d_progress := 350;
648 INSERT INTO po_session_gt(
649 key
650 ,index_num1
651 ,num1
652 ,num2
653 ,char1
654 ,char2
655 ,char3
656 ,char4
657 )
658 SELECT
659 l_po_session_gt_key
660 ,zxegt.trx_id
661 ,zxegt.trx_line_id
662 ,zxegt.trx_line_dist_id
663 ,zxegt.event_class_code
664 ,zxegt.message_text
665 ,'DETERMINE_RECOVERY'
666 ,ph.segment1
667 FROM zx_errors_gt zxegt, po_headers_all ph
668 WHERE zxegt.event_class_code = PO_CONSTANTS_SV.PO_EVENT_CLASS_CODE
669 AND zxegt.trx_id = ph.po_header_id;
670
671 d_progress := 360;
672 INSERT INTO po_session_gt(
673 key
674 ,index_num1
675 ,num1
676 ,num2
677 ,char1
678 ,char2
679 ,char3
680 ,char4
681 )
682 SELECT
683 l_po_session_gt_key
684 ,zxegt.trx_id
685 ,zxegt.trx_line_id
686 ,zxegt.trx_line_dist_id
687 ,zxegt.event_class_code
688 ,zxegt.message_text
689 ,'DETERMINE_RECOVERY'
690 ,ph.segment1
691 FROM zx_errors_gt zxegt, po_headers_all ph, po_releases_all pr
692 WHERE zxegt.event_class_code = PO_CONSTANTS_SV.REL_EVENT_CLASS_CODE
693 AND zxegt.trx_id = pr.po_release_id
694 AND pr.po_header_id = ph.po_header_id;
695
696 d_progress := 370;
697 BEGIN
698 SELECT COUNT(1) INTO l_count FROM zx_errors_gt;
699 EXCEPTION WHEN OTHERS THEN
700 IF PO_LOG.d_stmt THEN
701 PO_LOG.stmt(d_module_base,d_progress,'Exception while hitting zx_errors_gt');
702 END IF;
703 l_count := 0;
704 END;
705
706 IF PO_LOG.d_stmt THEN
707 PO_LOG.stmt(d_module_base,d_progress,'Number of records in zx_errors_gt '||l_count);
708 END IF;
709
710 -- Bug 5169449. Removed deletions from headers and lines gt tables
711 -- because if the control has come till determine_recovery then the
712 -- tax lines for the document have been calculated correctly. Hence,
713 -- for failure of determine_recovery, only the tauc's at distribution
714 -- level should be retained. The tauc's at header and shipment level
715 -- should be nulled out otherwise the header and line level action will
716 -- get passed as CREATE in the next tax calculation (ie at the time of
717 -- approve)
718 d_progress := 380;
719 DELETE FROM zx_itm_distributions_gt
720 WHERE trx_id IN (SELECT DISTINCT index_num1 FROM po_session_gt psgt
721 WHERE psgt.key = l_po_session_gt_key
722 AND psgt.char1 = PO_CONSTANTS_SV.PO_EVENT_CLASS_CODE
723 AND psgt.char3 = 'DETERMINE_RECOVERY');
724 d_progress := 390;
725 DELETE FROM zx_itm_distributions_gt
726 WHERE trx_id IN (SELECT DISTINCT index_num1 FROM po_session_gt psgt
727 WHERE psgt.key = l_po_session_gt_key
728 AND psgt.char1 = PO_CONSTANTS_SV.REL_EVENT_CLASS_CODE
729 AND psgt.char3 = 'DETERMINE_RECOVERY');
730
731 d_progress := 400;
732 -- Update the distributions that errored out and yet have a tauc of null
733 -- If this is not done, it is possible that all dist tauc's for a
734 -- document get nulled out and hence tax redistribution does not take
735 -- place despite determine_recovery erroring out for some of them
736 UPDATE po_distributions_all
737 SET tax_attribute_update_code = 'NO_ACTION'
738 WHERE tax_attribute_update_code IS NULL
739 AND po_distribution_id IN (SELECT psgt.NUM2 FROM po_session_gt psgt
740 WHERE psgt.key = l_po_session_gt_key
741 AND psgt.char3 = 'DETERMINE_RECOVERY');
742
743 END IF; --IF (l_return_status = FND_API.G_RET_STS_ERROR)
744
745 d_progress := 450;
746
747 -- bug5650927
748 -- Modified the subquery by adding a where clause so that trx_id is joined
749 -- to different columns based on entity_code and event_class_code
750
751 -- Populate recoverable/nonrecoverable tax columns in distributions table
752 UPDATE po_distributions_all pd
753 SET pd.recoverable_tax =
754 (SELECT SUM(zxdist.rec_nrec_tax_amt)
755 FROM zx_rec_nrec_dist zxdist
756 WHERE zxdist.trx_line_dist_id = pd.po_distribution_id
757 AND zxdist.recoverable_flag = 'Y'
758 AND zxdist.application_id = PO_CONSTANTS_SV.APPLICATION_ID
759 AND ( (zxdist.entity_code = PO_CONSTANTS_SV.PO_ENTITY_CODE
760 AND zxdist.event_class_code =
761 PO_CONSTANTS_SV.PO_EVENT_CLASS_CODE
762 AND zxdist.trx_id = pd.po_header_id)
763 OR
764 (zxdist.entity_code = PO_CONSTANTS_SV.REL_ENTITY_CODE
765 AND zxdist.event_class_code =
766 PO_CONSTANTS_SV.REL_EVENT_CLASS_CODE
767 AND zxdist.trx_id = pd.po_release_id)))
768 ,pd.nonrecoverable_tax =
769 (SELECT SUM(zxdist.rec_nrec_tax_amt)
770 FROM zx_rec_nrec_dist zxdist
771 WHERE zxdist.trx_line_dist_id = pd.po_distribution_id
772 AND zxdist.recoverable_flag = 'N'
773 AND zxdist.application_id = PO_CONSTANTS_SV.APPLICATION_ID
774 AND ( (zxdist.entity_code = PO_CONSTANTS_SV.PO_ENTITY_CODE
775 AND zxdist.event_class_code =
776 PO_CONSTANTS_SV.PO_EVENT_CLASS_CODE
777 AND zxdist.trx_id = pd.po_header_id)
778 OR
779 (zxdist.entity_code = PO_CONSTANTS_SV.REL_ENTITY_CODE
780 AND zxdist.event_class_code =
781 PO_CONSTANTS_SV.REL_EVENT_CLASS_CODE
782 AND zxdist.trx_id = pd.po_release_id)))
783 WHERE pd.po_distribution_id IN
784 (SELECT trx_line_dist_id FROM zx_itm_distributions_gt);
785
786 END IF;
787
788 d_progress := 460;
789
790 -- Null out tax_attribute_update_code columns
791
792 -- Headers and lines tables can be nulled out because they were
793 -- denormalized. However in headers, the exception is where CREATE
794 -- needs to be passed to eTax on PO updation as during an error occured
795 -- during creation. For lines, this is not an issue because eTax requires
796 -- no action for a line (while correct actions are required for header and
797 -- shipment levels). So if an error occurs during creation, and user then
798 -- updates a line, tax_attribute_update_code at line will be UPDATE, but
799 -- shipment level tax_attribute_update_code's will be correct (because of
800 -- denormalization) and will have a higher priority than those of the line
801 FORALL i IN 1..p_po_header_id_tbl.COUNT
802 UPDATE po_headers_all ph
803 SET ph.tax_attribute_update_code = null
804 WHERE ph.po_header_id = p_po_header_id_tbl(i)
805 -- Bug 4774900 null out if even a single shipment has been processed
806 -- correctly. That would mean that the header has been recorded
807 -- in eTax, and next time we need to pass UPDATE
808 AND EXISTS (SELECT 'Y'
809 FROM zx_transaction_lines_gt zxlgt
810 WHERE zxlgt.trx_id=ph.po_header_id);
811
812 d_progress := 470;
813 FORALL i IN 1..p_po_release_id_tbl.COUNT
814 UPDATE po_releases_all pr
815 SET pr.tax_attribute_update_code = null
816 WHERE pr.po_release_id = p_po_release_id_tbl(i)
817 AND EXISTS (SELECT 'Y'
818 FROM zx_transaction_lines_gt zxlgt
819 WHERE zxlgt.trx_id=pr.po_release_id);
820
821 d_progress := 480;
822 FORALL i IN 1..p_po_header_id_tbl.COUNT
823 UPDATE po_lines_all
824 SET tax_attribute_update_code = null
825 WHERE po_header_id = p_po_header_id_tbl(i);
826
827 d_progress := 490;
828
829 -- bug5219124 START
830 -- Separate the original update statement into two
831
832 UPDATE po_line_locations_all
833 SET tax_attribute_update_code = null,
834 original_shipment_id = null
835 WHERE line_location_id IN (SELECT trx_line_id FROM zx_transaction_lines_gt);
836
837 UPDATE po_line_locations_all
838 SET tax_attribute_update_code = null,
839 original_shipment_id = null
840 WHERE tax_attribute_update_code = 'DIST_DELETE'
841 AND line_location_id IN (SELECT trx_line_id FROM zx_itm_distributions_gt);
842
843
844 -- bug5219124 END
845
846 d_progress := 500;
847 UPDATE po_distributions_all
848 SET tax_attribute_update_code = null
849 WHERE po_distribution_id IN (SELECT trx_line_dist_id
850 FROM zx_itm_distributions_gt);
851
852 d_progress := 510;
853
854 -- bug5685869
855 -- Add a join to zl.trx_id so that the index on zx_lines can be used
856 -- more efficiently
857
858 -- Set the taxable flag column of shipments which have tax lines
859 UPDATE po_line_locations_all pll
860 SET pll.taxable_flag =
861 DECODE((SELECT COUNT(1) FROM zx_lines zl
862 WHERE zl.trx_line_id = pll.line_location_id
863 AND zl.application_id = PO_CONSTANTS_SV.APPLICATION_ID
864 AND ( (zl.entity_code = PO_CONSTANTS_SV.PO_ENTITY_CODE
865 AND zl.event_class_code = PO_CONSTANTS_SV.PO_EVENT_CLASS_CODE
866 AND zl.trx_id = pll.po_header_id)
867 OR
868 (zl.entity_code = PO_CONSTANTS_SV.REL_ENTITY_CODE
869 AND zl.event_class_code = PO_CONSTANTS_SV.REL_EVENT_CLASS_CODE
870 AND zl.trx_id = pll.po_release_id))),
871 0, 'N',
872 'Y'
873 )
874 WHERE
875 pll.line_location_id IN (SELECT trx_line_id FROM zx_transaction_lines_gt);
876
877
878 d_progress := 520;
879 -- Pour all errors in po_session_gt into global tax error record
880 SELECT
881 psgt.char3 --error_level
882 ,decode(psgt.char1,--document_type_code
883 PO_CONSTANTS_SV.PO_EVENT_CLASS_CODE, PO_CONSTANTS_SV.PO,
884 PO_CONSTANTS_SV.REL_EVENT_CLASS_CODE, PO_CONSTANTS_SV.RELEASE
885 )
886 ,psgt.index_num1 --document_id
887 ,psgt.char4 --document_num
888 ,null --line_id
889 ,null --line_num
890 ,pll.line_location_id --line_location_id
891 ,pll.shipment_num --shipment_num
892 ,pd.po_distribution_id --distribution_id
893 ,pd.distribution_num --distribution_num
894 ,psgt.char2 --message_text
895 BULK COLLECT INTO G_TAX_ERRORS_TBL
896 FROM po_session_gt psgt, po_line_locations_all pll, po_distributions_all pd
897 WHERE psgt.num1 = pll.line_location_id
898 AND psgt.num2 = pd.po_distribution_id(+)
899 AND psgt.key = l_po_session_gt_key;
900
901 IF PO_LOG.d_stmt THEN
902 PO_LOG.stmt(d_module_base,d_progress,'Number of error records collected '||G_TAX_ERRORS_TBL.error_level.COUNT);
903 log_global_error_record(d_module_base, d_progress);
904 END IF;
905
906 -- Bug 5363122. Wipe out ZX GT tables at the end of tax call
907 wipe_zx_gt_tables();
908
909 IF (PO_LOG.d_proc) THEN
910 PO_LOG.proc_end(d_module_base);
911 PO_LOG.proc_end(d_module_base, 'x_return_status', x_return_status);
912 END IF;
913 d_progress := 540;
914
915 EXCEPTION
916 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
917 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
918 ROLLBACK TO SAVEPOINT calculate_tax_savepoint;
919
920 -- Initialize to flush out expected errors if any
921 initialize_global_error_record();
922 -- Add a new error
923 append_error(p_error_level => null,
924 p_document_type_code => null,
925 p_document_id => null,
926 p_document_num => null,
927 p_line_id => null,
928 p_line_num => null,
929 p_line_location_id => null,
930 p_shipment_num => null,
931 p_distribution_id => null,
932 p_distribution_num => null,
933 p_message_text => l_msg_data);
934
935 IF (PO_LOG.d_exc) THEN
936 PO_LOG.exc(d_module_base, d_progress, l_msg_data);
937 PO_LOG.proc_end(d_module_base, 'x_return_status', x_return_status);
938 END IF;
939
940 WHEN OTHERS THEN
941 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
942 ROLLBACK TO SAVEPOINT calculate_tax_savepoint;
943
944 -- Initialize to flush out expected errors if any
945 initialize_global_error_record();
946 -- Add a new error
947 append_error(p_error_level => null,
948 p_document_type_code => null,
949 p_document_id => null,
950 p_document_num => null,
951 p_line_id => null,
952 p_line_num => null,
953 p_line_location_id => null,
954 p_shipment_num => null,
955 p_distribution_id => null,
956 p_distribution_num => null,
957 p_message_text => d_module_base||'#'||d_progress||':'
958 ||SQLCODE || SQLERRM);
959
960 IF (PO_LOG.d_exc) THEN
961 PO_LOG.exc(d_module_base, d_progress, SQLCODE || SQLERRM);
962 PO_LOG.proc_end(d_module_base, 'x_return_status', x_return_status);
963 END IF;
964
965 END calculate_tax;
966
967
968 -----------------------------------------------------------------------------
969 --Start of Comments
970 --Name: calculate_tax
971 --Pre-reqs:
972 -- Should be called when transaction data has been posted to the database
973 -- but not yet committed
974 --Modifies:
975 -- PO_LINE_LOCATIONS_ALL.tax_attribute_update_code
976 -- PO_LINE_LOCATIONS_ALL.original_shipment_id
977 -- PO_LINE_LOCATIONS_ALL.taxable_flag
978 -- PO_DISTRIBUTIONS_ALL.nonrecoverable_tax
979 -- PO_DISTRIBUTIONS_ALL.recoverable_tax
980 --Locks:
981 -- Transaction tables if update is allowed
982 --Function:
983 -- Calculate tax amounts for the documents passed in
984 --Parameters:
985 --IN:
986 --p_po_header_id
987 -- po_header_id of the PO for which tax is to be calculated
988 --p_po_release_id
989 -- po_release_id of the Releasefor which tax is to be calculated
990 --p_calling_program
991 -- Identifies the module that calls this procedure eg. 'PDOI'
992 --OUT:
993 --x_return_status
994 -- Standard API specification parameter
995 -- Can hold one of the following values:
996 -- FND_API.G_RET_STS_SUCCESS (='S')
997 -- FND_API.G_RET_STS_ERROR (='E')
998 -- FND_API.G_RET_STS_UNEXP_ERROR (='U')
999 --Notes:
1000 -- 1. Wrapper procedure that calls its overloaded bulk version
1001 -- Called from forms (where passing a pl/sql table from client side is not
1002 -- possible and other modules where only a single document is processed
1003 -- at a time
1004 -- 2. Returns all expected errors from etax API's in global tax error record
1005 --End of Comments
1006 -----------------------------------------------------------------------------
1007 PROCEDURE calculate_tax(p_po_header_id IN NUMBER,
1008 p_po_release_id IN NUMBER,
1009 p_calling_program IN VARCHAR2,
1010 x_return_status OUT NOCOPY VARCHAR2
1011 ) IS
1012 l_module_name CONSTANT VARCHAR2(100) := 'CALCULATE_TAX_WRAPPER';
1013 d_module_base CONSTANT VARCHAR2(100) := PO_LOG.get_subprogram_base(
1014 D_PACKAGE_BASE, l_module_name);
1015 d_progress NUMBER;
1016 l_po_header_id_tbl PO_TBL_NUMBER;
1017 l_po_release_id_tbl PO_TBL_NUMBER;
1018 BEGIN
1019
1020 IF (PO_LOG.d_proc) THEN
1021 PO_LOG.proc_begin(d_module_base);
1022 PO_LOG.proc_begin(d_module_base, 'p_po_header_id', p_po_header_id);
1023 PO_LOG.proc_begin(d_module_base, 'p_po_release_id', p_po_release_id);
1024 PO_LOG.proc_begin(d_module_base, 'p_calling_program', p_calling_program);
1025 END IF;
1026
1027 d_progress := 0;
1028
1029 IF (p_po_header_id IS NULL) THEN
1030 l_po_header_id_tbl := PO_TBL_NUMBER();
1031 ELSE
1032 l_po_header_id_tbl := PO_TBL_NUMBER(p_po_header_id);
1033 END IF;
1034
1035 IF (p_po_release_id IS NULL) THEN
1036 l_po_release_id_tbl := PO_TBL_NUMBER();
1037 ELSE
1038 l_po_release_id_tbl := PO_TBL_NUMBER(p_po_release_id);
1039 END IF;
1040
1041 calculate_tax(p_po_header_id_tbl => l_po_header_id_tbl,
1042 p_po_release_id_tbl => l_po_release_id_tbl,
1043 p_calling_program => p_calling_program,
1044 x_return_status => x_return_status
1045 );
1046
1047 d_progress := 10;
1048 IF PO_LOG.d_stmt THEN
1049 PO_LOG.stmt(d_module_base,d_progress,'PO calculate_tax returned with status '||x_return_status);
1050 END IF;
1051
1052 IF (PO_LOG.d_proc) THEN
1053 PO_LOG.proc_end(d_module_base);
1054 PO_LOG.proc_end(d_module_base, 'x_return_status', x_return_status);
1055 END IF;
1056
1057 d_progress := 20;
1058 EXCEPTION
1059 WHEN OTHERS THEN
1060 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
1061
1062 -- Initialize to flush out expected errors if any
1063 initialize_global_error_record();
1064 -- Add a new error
1065 append_error(p_error_level => null,
1066 p_document_type_code => null,
1067 p_document_id => null,
1068 p_document_num => null,
1069 p_line_id => null,
1070 p_line_num => null,
1071 p_line_location_id => null,
1072 p_shipment_num => null,
1073 p_distribution_id => null,
1074 p_distribution_num => null,
1075 p_message_text => d_module_base||'#'||d_progress||':'
1076 ||SQLCODE || SQLERRM);
1077
1078 IF (PO_LOG.d_exc) THEN
1079 PO_LOG.exc(d_module_base, d_progress, SQLCODE || SQLERRM);
1080 PO_LOG.proc_end(d_module_base, 'x_return_status', x_return_status);
1081 END IF;
1082 END calculate_tax;
1083
1084
1085 -----------------------------------------------------------------------------
1086 --Start of Comments
1087 --Name: calculate_tax_requisition
1088 --Pre-reqs:
1089 -- Should be called when transaction data has been posted to the database
1090 -- but not yet committed
1091 --Modifies:
1092 -- PO_REQUISITION_LINES_ALL.tax_attribute_update_code
1093 -- PO_REQUISITION_LINES_ALL.original_shipment_id
1094 -- PO_REQ_DISTRIBUTIONS_ALL.nonrecoverable_tax
1095 -- PO_REQ_DISTRIBUTIONS_ALL.recoverable_tax
1096 --Locks:
1097 -- Transaction tables if update is allowed
1098 --Function:
1099 -- Calculate tax amounts for the requisition passed in
1100 --Parameters:
1101 --IN:
1102 --p_requisition_header_id
1103 -- requisition_header_id for which tax is to be calculated
1104 --p_calling_program
1105 -- Identifies the module that calls this procedure eg. 'REQIMPORT'
1106 --OUT:
1107 --x_return_status
1108 -- Standard API specification parameter
1109 -- Can hold one of the following values:
1110 -- FND_API.G_RET_STS_SUCCESS (='S')
1111 -- FND_API.G_RET_STS_ERROR (='E')
1112 -- FND_API.G_RET_STS_UNEXP_ERROR (='U')
1113 --Notes:
1114 -- 1. Calls out to EBTax APIs calculate_tax and determine recovery to
1115 -- calculaterecoverable_tax and nonrecoverable_tax
1116 -- 2. Returns all expected errors from etax API's in global tax error record
1117 --End of Comments
1118 -----------------------------------------------------------------------------
1119 PROCEDURE calculate_tax_requisition(p_requisition_header_id IN NUMBER,
1120 p_calling_program IN VARCHAR2,
1121 x_return_status OUT NOCOPY VARCHAR2
1122 ) IS
1123 l_module_name CONSTANT VARCHAR2(100) := 'CALCULATE_TAX_REQUISITION';
1124 d_module_base CONSTANT VARCHAR2(100) := PO_LOG.get_subprogram_base(
1125 D_PACKAGE_BASE, l_module_name);
1126 d_progress NUMBER;
1127 l_count NUMBER;
1128 l_line_count NUMBER;
1129 l_msg_count NUMBER;
1130 l_msg_data VARCHAR2(1000);
1131 l_trx_rec ZX_API_PUB.transaction_rec_type;
1132 l_org_id PO_HEADERS_ALL.org_id%TYPE;
1133 l_return_status VARCHAR2(1);
1134 BEGIN
1135
1136 SAVEPOINT calculate_tax_req_savepoint;
1137
1138 IF (PO_LOG.d_proc) THEN
1139 PO_LOG.proc_begin(d_module_base);
1140 PO_LOG.proc_begin(d_module_base, 'p_requisition_header_id', p_requisition_header_id);
1141 PO_LOG.proc_begin(d_module_base, 'p_calling_program', p_calling_program);
1142 END IF;
1143
1144 d_progress := 0;
1145
1146 -- By default return status is SUCCESS if no exception occurs
1147 x_return_status := FND_API.G_RET_STS_SUCCESS;
1148
1149 --<Bug 5242803> Skip all processing if requisition_header_id is null
1150 IF p_requisition_header_id IS NOT NULL THEN
1151 -- Set global error record to uninitialized local record to set all its
1152 -- components to null
1153 G_TAX_ERRORS_TBL := null;
1154 d_progress := 10;
1155 initialize_zx_gt_tables(); -- Wipe ZX GT tables clean
1156 d_progress := 20;
1157 initialize_global_error_record();
1158
1159 IF PO_LOG.d_stmt THEN
1160 PO_LOG.stmt(d_module_base,d_progress,'initial values of tax_attribute_update_codes');
1161 log_req_tauc(d_module_base,d_progress,p_requisition_header_id);
1162 END IF;
1163
1164 -- Populate ZX headers and lines GT tables with transaction data
1165 d_progress := 30;
1166 populate_zx_headers_with_req(p_requisition_header_id, p_calling_program);
1167
1168 d_progress := 40;
1169 populate_zx_lines_with_req(p_requisition_header_id, p_calling_program);
1170
1171 d_progress := 50;
1172 -- Check if zx lines gt table is empty
1173 BEGIN
1174 SELECT COUNT(1) INTO l_line_count FROM zx_transaction_lines_gt;
1175 EXCEPTION WHEN OTHERS THEN
1176 l_line_count := 0;
1177 IF PO_LOG.d_stmt THEN
1178 PO_LOG.stmt(d_module_base,d_progress,'Exception while selecting from zx_transaction_lines_gt');
1179 END IF;
1180 END;
1181
1182 d_progress := 60;
1183 IF PO_LOG.d_stmt THEN
1184 PO_LOG.stmt(d_module_base,d_progress,'Number of rows in zx_transaction_lines_gt='||l_line_count);
1185 END IF;
1186
1187 IF (l_line_count <> 0) THEN
1188 d_progress := 70;
1189 -- Log table parameters
1190 IF PO_LOG.d_stmt THEN
1191 PO_LOG.stmt(d_module_base,d_progress,'Table parameters before eTax default/redefault');
1192 log_header_tax_attributes(d_module_base,d_progress);
1193 log_line_tax_attributes(d_module_base,d_progress);
1194 END IF;
1195
1196 -- Call the eTax defaulting/redefaulting APIs which populate the
1197 -- Additional Tax Attributes back into the ZX GT tables
1198 IF (p_calling_program = 'REQIMPORT') THEN
1199 d_progress := 80;
1200 -- For Req Import, eTax needs to do extra validations since data is
1201 -- entered by user in interface tables. So call
1202 -- validate_and_default_tax_attribs
1203 ZX_API_PUB.validate_and_default_tax_attr(
1204 p_api_version => 1.0,
1205 p_init_msg_list => FND_API.G_TRUE,
1206 p_commit => FND_API.G_FALSE,
1207 p_validation_level => FND_API.G_VALID_LEVEL_FULL,
1208 x_return_status => l_return_status,
1209 x_msg_count => l_msg_count,
1210 x_msg_data => l_msg_data
1211 );
1212
1213 d_progress := 90;
1214 IF PO_LOG.d_stmt THEN
1215 PO_LOG.stmt(d_module_base,d_progress,'validate_and_default_tax_attr returned with status '||l_return_status);
1216 END IF;
1217
1218 -- Raise if any unexpected error
1219 IF (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
1220 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1221 END IF;
1222
1223 -- If there are any expected errors then set the return status
1224 -- accordingly and copy over errors into global tax errors record
1225 IF (l_return_status = FND_API.G_RET_STS_ERROR) THEN
1226 d_progress := 100;
1227 -- Read validation errors from zx_validation_errors_gt into the global
1228 -- error record defined in the spec
1229 SELECT
1230 'VALIDATE' --error_level,
1231 ,PO_CONSTANTS_SV.REQUISITION --document_type_code,
1232 ,p_requisition_header_id --document_id,
1233 ,prh.segment1 --document_num,
1234 ,zxvegt.trx_line_id --line_id,
1235 ,prl.line_num --line_num,
1236 ,null --line_location_id,
1237 ,null --shipment_num,
1238 ,null --distribution_id,
1239 ,null --distribution_num,
1240 ,zxvegt.message_text --message_text
1241 BULK COLLECT INTO G_TAX_ERRORS_TBL
1242 FROM zx_validation_errors_gt zxvegt, po_requisition_headers_all prh,
1243 po_requisition_lines_all prl
1244 WHERE zxvegt.trx_id = prh.requisition_header_id
1245 AND zxvegt.trx_line_id = prl.requisition_line_id(+);
1246
1247 d_progress := 110;
1248 BEGIN
1249 SELECT COUNT(1) INTO l_count FROM zx_validation_errors_gt;
1250 EXCEPTION WHEN OTHERS THEN
1251 IF PO_LOG.d_stmt THEN
1252 PO_LOG.stmt(d_module_base,d_progress,'Exception while hitting zx_validation_errors_gt');
1253 END IF;
1254 l_count := 0;
1255 END;
1256
1257 IF PO_LOG.d_stmt THEN
1258 PO_LOG.stmt(d_module_base,d_progress,'Number of records in zx_validation_errors_gt '||l_count);
1259 PO_LOG.stmt(d_module_base,d_progress,'Number of error records collected '||G_TAX_ERRORS_TBL.error_level.COUNT);
1260 END IF;
1261
1262 d_progress := 120;
1263 RAISE FND_API.G_EXC_ERROR;
1264 END IF;
1265
1266 ELSE
1267 d_progress := 130;
1268 ZX_API_PUB.get_default_tax_det_attribs(
1269 p_api_version => 1.0,
1270 p_init_msg_list => FND_API.G_TRUE,
1271 p_commit => FND_API.G_FALSE,
1272 p_validation_level => FND_API.G_VALID_LEVEL_FULL,
1273 x_return_status => l_return_status,
1274 x_msg_count => l_msg_count,
1275 x_msg_data => l_msg_data
1276 );
1277
1278 d_progress := 140;
1279 IF PO_LOG.d_stmt THEN
1280 PO_LOG.stmt(d_module_base,d_progress,'get_default_tax_det_attribs returned with status '||l_return_status);
1281 END IF;
1282
1283 -- This API cannot give expected errors. However raise unexpected errors
1284 IF (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
1285 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1286 END IF;
1287
1288 END IF; -- IF (p_calling_program = 'REQIMPORT')
1289
1290 d_progress := 150;
1291 -- Override product_type Additional Tax Attribute if not already populated
1292 -- by eTax defaulting/redefaulting API
1293 UPDATE zx_transaction_lines_gt zxlgt
1294 SET zxlgt.product_type =
1295 (SELECT DECODE(prl.purchase_basis,
1296 'GOODS', 'GOODS',
1297 'SERVICES')
1298 FROM po_requisition_lines_all prl
1299 WHERE prl.requisition_line_id = zxlgt.trx_line_id)
1300 WHERE zxlgt.product_type IS NULL
1301 AND zxlgt.line_level_action = 'CREATE';
1302
1303 d_progress := 160;
1304
1305 -- Log table parameters
1306 IF PO_LOG.d_stmt THEN
1307 PO_LOG.stmt(d_module_base,d_progress,'Table parameters before calculate_tax');
1308 log_header_tax_attributes(d_module_base,d_progress);
1309 log_line_tax_attributes(d_module_base,d_progress);
1310 END IF;
1311
1312 ZX_API_PUB.calculate_tax(
1313 p_api_version => 1.0,
1314 p_init_msg_list => FND_API.G_FALSE,
1315 p_commit => FND_API.G_FALSE,
1316 p_validation_level => FND_API.G_VALID_LEVEL_FULL,
1317 x_return_status => l_return_status,
1318 x_msg_count => l_msg_count,
1319 x_msg_data => l_msg_data
1320 );
1321
1322 d_progress := 170;
1323 IF PO_LOG.d_stmt THEN
1324 PO_LOG.stmt(d_module_base,d_progress,'calculate_tax returned with status '||l_return_status);
1325 END IF;
1326
1327
1328 -- Raise if any unexpected error
1329 IF (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
1330 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1331 END IF;
1332
1333 -- If there are any expected errors then set the return status accordingly
1334 -- and copy over errors into global tax errors record
1335 IF (l_return_status = FND_API.G_RET_STS_ERROR) THEN
1336 x_return_status := l_return_status;
1337 d_progress := 180;
1338 -- Read validation errors from zx_errors_gt into the global
1339 -- error record defined in the spec
1340 SELECT
1341 'CALCULATE_TAX' --error_level,
1342 ,PO_CONSTANTS_SV.REQUISITION --document_type_code,
1343 ,p_requisition_header_id --document_id,
1344 ,prh.segment1 --document_num,
1345 ,zxegt.trx_line_id --line_id,
1346 ,prl.line_num --line_num,
1347 ,null --line_location_id,
1348 ,null --shipment_num,
1349 ,null --distribution_id,
1350 ,null --distribution_num,
1351 ,zxegt.message_text --message_text
1352 BULK COLLECT INTO G_TAX_ERRORS_TBL
1353 FROM zx_errors_gt zxegt, po_requisition_headers_all prh,
1354 po_requisition_lines_all prl
1355 WHERE zxegt.trx_id = prh.requisition_header_id
1356 AND zxegt.trx_line_id = prl.requisition_line_id(+);
1357
1358 BEGIN
1359 SELECT COUNT(1) INTO l_count FROM zx_errors_gt;
1360 EXCEPTION WHEN OTHERS THEN
1361 IF PO_LOG.d_stmt THEN
1362 PO_LOG.stmt(d_module_base,d_progress,'Exception while hitting zx_errors_gt');
1363 END IF;
1364 l_count := 0;
1365 END;
1366
1367 IF PO_LOG.d_stmt THEN
1368 PO_LOG.stmt(d_module_base,d_progress,'Number of records in zx_errors_gt '||l_count);
1369 PO_LOG.stmt(d_module_base,d_progress,'Number of error records collected '||G_TAX_ERRORS_TBL.error_level.COUNT);
1370 END IF;
1371
1372 d_progress := 190;
1373 RAISE FND_API.G_EXC_ERROR;
1374 END IF;
1375
1376 END IF; -- IF (l_line_count <> 0)
1377
1378 d_progress := 200;
1379 -- Populate ZX distributions GT table with transaction distribution data
1380 populate_zx_dists_with_req(p_requisition_header_id, p_calling_program);
1381
1382 d_progress := 210;
1383 -- Call eTax API determine_recovery if zx distributions gt is not empty
1384 BEGIN
1385 SELECT COUNT(1) INTO l_count FROM zx_itm_distributions_gt;
1386 EXCEPTION WHEN OTHERS THEN
1387 l_count := 0;
1388 IF PO_LOG.d_stmt THEN
1389 PO_LOG.stmt(d_module_base,d_progress,'Exception while selecting from zx_itm_distributions_gt');
1390 END IF;
1391 END;
1392
1393 d_progress := 220;
1394 IF PO_LOG.d_stmt THEN
1395 PO_LOG.stmt(d_module_base,d_progress,'Number of rows in zx_itm_distributions_gt='||l_count);
1396 END IF;
1397
1398 IF (l_count <> 0) THEN
1399 d_progress := 230;
1400 -- Update event_type_code on zx headers as required by determine_recovery API
1401 UPDATE zx_trx_headers_gt
1402 SET event_type_code = PO_CONSTANTS_SV.REQ_DISTRIBUTED;
1403
1404 d_progress := 240;
1405
1406 -- Log table parameters
1407 IF PO_LOG.d_stmt THEN
1408 PO_LOG.stmt(d_module_base,d_progress,'Table parameters before determine_recovery');
1409 log_header_tax_attributes(d_module_base,d_progress);
1410 log_line_tax_attributes(d_module_base,d_progress);
1411 log_dist_tax_attributes(d_module_base,d_progress);
1412 END IF;
1413
1414 ZX_API_PUB.determine_recovery(
1415 p_api_version => 1.0,
1416 p_init_msg_list => FND_API.G_FALSE,
1417 p_commit => FND_API.G_FALSE,
1418 p_validation_level => FND_API.G_VALID_LEVEL_FULL,
1419 x_return_status => l_return_status,
1420 x_msg_count => l_msg_count,
1421 x_msg_data => l_msg_data
1422 );
1423
1424 d_progress := 250;
1425 IF PO_LOG.d_stmt THEN
1426 PO_LOG.stmt(d_module_base,d_progress,'determine_recovery returned with status '||l_return_status);
1427 END IF;
1428
1429 -- Raise if any unexpected error
1430 IF (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
1431 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1432 END IF;
1433
1434 -- If there are any expected errors then set the return status accordingly
1435 -- and copy over errors into global tax errors record
1436 IF (l_return_status = FND_API.G_RET_STS_ERROR) THEN
1437 x_return_status := l_return_status;
1438 -- Read validation errors from zx_errors_gt into the global
1439 -- error record defined in the spec
1440 d_progress := 260;
1441 SELECT
1442 'DETERMINE_RECOVERY' --error_level,
1443 ,PO_CONSTANTS_SV.REQUISITION --document_type_code,
1444 ,p_requisition_header_id --document_id,
1445 ,prh.segment1 --document_num,
1446 ,zxegt.trx_line_id --line_id,
1447 ,prl.line_num --line_num,
1448 ,null --line_location_id,
1449 ,null --shipment_num,
1450 ,zxegt.trx_line_dist_id --distribution_id,
1451 ,prd.distribution_id --distribution_num,
1452 ,zxegt.message_text --message_text
1453 BULK COLLECT INTO G_TAX_ERRORS_TBL
1454 FROM zx_errors_gt zxegt, po_requisition_headers_all prh,
1455 po_requisition_lines_all prl, po_req_distributions_all prd
1456 WHERE zxegt.trx_id = prh.requisition_header_id
1457 AND zxegt.trx_line_id = prl.requisition_line_id(+)
1458 AND zxegt.trx_line_dist_id = prd.distribution_id(+);
1459
1460 d_progress := 270;
1461 BEGIN
1462 SELECT COUNT(1) INTO l_count FROM zx_errors_gt;
1463 EXCEPTION WHEN OTHERS THEN
1464 IF PO_LOG.d_stmt THEN
1465 PO_LOG.stmt(d_module_base,d_progress,'Exception while hitting zx_errors_gt');
1466 END IF;
1467 l_count := 0;
1468 END;
1469
1470 IF PO_LOG.d_stmt THEN
1471 PO_LOG.stmt(d_module_base,d_progress,'Number of records in zx_errors_gt '||l_count);
1472 PO_LOG.stmt(d_module_base,d_progress,'Number of error records collected '||G_TAX_ERRORS_TBL.error_level.COUNT);
1473 END IF;
1474
1475 d_progress := 280;
1476 RAISE FND_API.G_EXC_ERROR;
1477 END IF;
1478
1479 d_progress := 290;
1480 -- Populate recoverable/nonrecoverable tax columns in distributions table
1481 UPDATE po_req_distributions_all prd
1482 SET prd.recoverable_tax =
1483 (SELECT SUM(zxdist.rec_nrec_tax_amt)
1484 FROM zx_rec_nrec_dist_gt zxdist
1485 WHERE zxdist.trx_line_dist_id = prd.distribution_id
1486 AND zxdist.recoverable_flag = 'Y'
1487 AND zxdist.application_id = PO_CONSTANTS_SV.APPLICATION_ID
1488 AND zxdist.entity_code = PO_CONSTANTS_SV.REQ_ENTITY_CODE
1489 AND zxdist.event_class_code = PO_CONSTANTS_SV.REQ_EVENT_CLASS_CODE)
1490 ,prd.nonrecoverable_tax =
1491 (SELECT SUM(zxdist.rec_nrec_tax_amt)
1492 FROM zx_rec_nrec_dist_gt zxdist
1493 WHERE zxdist.trx_line_dist_id = prd.distribution_id
1494 AND zxdist.recoverable_flag = 'N'
1495 AND zxdist.application_id = PO_CONSTANTS_SV.APPLICATION_ID
1496 AND zxdist.entity_code = PO_CONSTANTS_SV.REQ_ENTITY_CODE
1497 AND zxdist.event_class_code = PO_CONSTANTS_SV.REQ_EVENT_CLASS_CODE)
1498 WHERE prd.distribution_id IN
1499 (SELECT trx_line_dist_id FROM zx_itm_distributions_gt);
1500
1501 END IF; -- IF (l_count <> 0)
1502
1503 -- If any lines were processed then update eTax repository with the line
1504 -- determining factors
1505 IF (l_line_count <> 0) THEN
1506 d_progress := 300;
1507 SELECT prh.org_id
1508 INTO l_org_id
1509 FROM po_requisition_headers_all prh
1510 WHERE prh.requisition_header_id=p_requisition_header_id;
1511
1512 IF PO_LOG.d_stmt THEN
1513 PO_LOG.stmt(d_module_base,d_progress,'org_id = '||l_org_id);
1514 END IF;
1515
1516 d_progress := 310;
1517 -- Call global_document_update API to delete all data for this requistion
1518 l_trx_rec.internal_organization_id := l_org_id;
1519 l_trx_rec.application_id := PO_CONSTANTS_SV.APPLICATION_ID;
1520 l_trx_rec.entity_code := PO_CONSTANTS_SV.REQ_ENTITY_CODE;
1521 l_trx_rec.event_class_code := PO_CONSTANTS_SV.REQ_EVENT_CLASS_CODE;
1522 l_trx_rec.event_type_code := PO_CONSTANTS_SV.REQ_DELETED;
1523 l_trx_rec.trx_id := p_requisition_header_id;
1524 l_trx_rec.application_doc_status := null;
1525
1526 d_progress := 320;
1527 ZX_API_PUB.global_document_update(
1528 p_api_version => 1.0,
1529 p_init_msg_list => FND_API.G_FALSE,
1530 p_commit => FND_API.G_FALSE,
1531 p_validation_level => FND_API.G_VALID_LEVEL_FULL,
1532 x_return_status => l_return_status,
1533 x_msg_count => l_msg_count,
1534 x_msg_data => l_msg_data,
1535 p_transaction_rec => l_trx_rec);
1536
1537 -- Raise if any unexpected error
1538 IF (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
1539 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1540 END IF;
1541
1542 d_progress := 330;
1543 -- Populate zx record TRX_LINE_DIST_TBL
1544 populate_zx_record(p_requisition_header_id);
1545 d_progress := 340;
1546 -- Populate the tax determining attributes in eTax repository if there were
1547 -- no errors in processing the document. Control will reach here only if
1548 -- all l_return_status until now have been successful
1549 ZX_API_PUB.insert_line_det_factors(
1550 p_api_version => 1.0,
1551 p_init_msg_list => FND_API.G_FALSE,
1552 p_commit => FND_API.G_FALSE,
1553 p_validation_level => FND_API.G_VALID_LEVEL_FULL,
1554 x_return_status => l_return_status,
1555 x_msg_count => l_msg_count,
1556 x_msg_data => l_msg_data);
1557
1558 d_progress := 350;
1559 IF PO_LOG.d_stmt THEN
1560 PO_LOG.stmt(d_module_base,d_progress,'insert_line_det_factors returned with status '||l_return_status);
1561 END IF;
1562
1563 -- Raise if any unexpected error
1564 IF (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
1565 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1566 END IF;
1567
1568 END IF; --IF (l_line_count <> 0)
1569
1570 d_progress := 360;
1571 -- Null out tax_attribute_update_code columns
1572 update po_requisition_headers_all
1573 set tax_attribute_update_code = null
1574 where requisition_header_id = p_requisition_header_id;
1575
1576 d_progress := 370;
1577 update po_requisition_lines_all
1578 set tax_attribute_update_code = null
1579 where requisition_header_id = p_requisition_header_id;
1580
1581 -- Bug 5363122. Wipe out ZX GT tables at the end of tax call
1582 wipe_zx_gt_tables();
1583
1584 END IF; -- IF p_requisition_header_id IS NOT NULL
1585
1586 IF (PO_LOG.d_proc) THEN
1587 PO_LOG.proc_end(d_module_base);
1588 PO_LOG.proc_end(d_module_base, 'x_return_status', x_return_status);
1589 END IF;
1590 d_progress := 380;
1591
1592 EXCEPTION
1593 WHEN FND_API.G_EXC_ERROR THEN
1594 x_return_status := FND_API.G_RET_STS_ERROR ;
1595 ROLLBACK TO SAVEPOINT calculate_tax_req_savepoint;
1596
1597 IF (PO_LOG.d_exc) THEN
1598 PO_LOG.exc(d_module_base,d_progress,'Number of error records collected '||G_TAX_ERRORS_TBL.error_level.COUNT);
1599 log_global_error_record(d_module_base, d_progress);
1600 PO_LOG.exc(d_module_base, d_progress, null);
1601 PO_LOG.proc_end(d_module_base, 'x_return_status', x_return_status);
1602 END IF;
1603
1604 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1605 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
1606 ROLLBACK TO SAVEPOINT calculate_tax_req_savepoint;
1607
1608 -- Initialize to flush out expected errors if any
1609 initialize_global_error_record();
1610 -- Add a new error
1611 append_error(p_error_level => null,
1612 p_document_type_code => null,
1613 p_document_id => null,
1614 p_document_num => null,
1615 p_line_id => null,
1616 p_line_num => null,
1617 p_line_location_id => null,
1618 p_shipment_num => null,
1619 p_distribution_id => null,
1620 p_distribution_num => null,
1621 p_message_text => l_msg_data);
1622
1623 IF (PO_LOG.d_exc) THEN
1624 PO_LOG.exc(d_module_base, d_progress, l_msg_data);
1625 PO_LOG.proc_end(d_module_base, 'x_return_status', x_return_status);
1626 END IF;
1627
1628 WHEN OTHERS THEN
1629 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
1630 ROLLBACK TO SAVEPOINT calculate_tax_req_savepoint;
1631
1632 -- Initialize to flush out expected errors if any
1633 initialize_global_error_record();
1634 -- Add a new error
1635 append_error(p_error_level => null,
1636 p_document_type_code => null,
1637 p_document_id => null,
1638 p_document_num => null,
1639 p_line_id => null,
1640 p_line_num => null,
1641 p_line_location_id => null,
1642 p_shipment_num => null,
1643 p_distribution_id => null,
1644 p_distribution_num => null,
1645 p_message_text => d_module_base||'#'||d_progress||':'
1646 ||SQLCODE || SQLERRM);
1647
1648 IF (PO_LOG.d_exc) THEN
1649 PO_LOG.exc(d_module_base, d_progress, SQLCODE || SQLERRM);
1650 PO_LOG.proc_end(d_module_base, 'x_return_status', x_return_status);
1651 END IF;
1652 END calculate_tax_requisition;
1653
1654
1655
1656 -----------------------------------------------------------------------------
1657 --Start of Comments
1658 --Name: determine_recovery_po
1659 --Pre-reqs:
1660 -- None
1661 --Modifies:
1662 -- PO_DISTRIBUTIONS_ALL.nonrecoverable_tax
1663 -- PO_DISTRIBUTIONS_ALL.recoverable_tax
1664 --Locks:
1665 -- Transaction tables if update is allowed
1666 --Function:
1667 -- Distribute tax lines and calculate recoverable and nonrecoverable tax
1668 -- amounts
1669 --Parameters:
1670 --IN:
1671 --p_po_header_id
1672 -- po_header_id for which tax is to be distributed
1673 --OUT:
1674 --x_return_status
1675 -- Standard API specification parameter
1676 -- Can hold one of the following values:
1677 -- FND_API.G_RET_STS_SUCCESS (='S')
1678 -- FND_API.G_RET_STS_ERROR (='E')
1679 -- FND_API.G_RET_STS_UNEXP_ERROR (='U')
1680 --Notes:
1681 -- 1. Calls out to EBTax API determine recovery to distribute tax lines
1682 -- Populates recoverable_tax and nonrecoverable_tax columns in distributions
1683 -- with the corrsponding tax amounts calculated.
1684 -- 2. Returns all expected errors from etax API's in global tax error record
1685 --End of Comments
1686 -----------------------------------------------------------------------------
1687 PROCEDURE determine_recovery_po(p_po_header_id IN NUMBER,
1688 x_return_status OUT NOCOPY VARCHAR2
1689 ) IS
1690 l_module_name CONSTANT VARCHAR2(100) := 'DETERMINE_RECOVERY_PO';
1691 d_module_base CONSTANT VARCHAR2(100) := PO_LOG.get_subprogram_base(
1692 D_PACKAGE_BASE, l_module_name);
1693 d_progress NUMBER;
1694 l_msg_count NUMBER;
1695 l_msg_data VARCHAR2(1000);
1696 l_count NUMBER;
1697 l_return_status VARCHAR2(1);
1698 BEGIN
1699 SAVEPOINT det_recovery_po_savepoint;
1700
1701 IF (PO_LOG.d_proc) THEN
1702 PO_LOG.proc_begin(d_module_base);
1703 PO_LOG.proc_begin(d_module_base, 'p_po_header_id', p_po_header_id);
1704 END IF;
1705
1706 d_progress := 0;
1707
1708 -- By default return status is SUCCESS if no exception occurs
1709 x_return_status := FND_API.G_RET_STS_SUCCESS;
1710 -- Set global error record to uninitialized local record to set all its
1711 -- components to null
1712 G_TAX_ERRORS_TBL := null;
1713 initialize_zx_gt_tables(); -- Wipe ZX GT tables clean
1714 initialize_global_error_record();
1715
1716 d_progress := 10;
1717 -- Populate ZX headers GT table with transaction header data
1718 populate_header_po(p_po_header_id);
1719 d_progress := 20;
1720 -- Populate ZX distributions GT table with transaction distribution data
1721 populate_all_dists_po(p_po_header_id);
1722
1723 d_progress := 30;
1724 -- Call eTax API determine_recovery to distribute tax lines
1725 BEGIN
1726 SELECT COUNT(1) INTO l_count FROM zx_itm_distributions_gt;
1727 EXCEPTION WHEN OTHERS THEN
1728 l_count := 0;
1729 END;
1730
1731 IF (l_count <> 0) THEN
1732 d_progress := 40;
1733
1734 -- Log table parameters
1735 IF PO_LOG.d_stmt THEN
1736 PO_LOG.stmt(d_module_base,d_progress,'Table parameters before determine_recovery');
1737 log_header_tax_attributes(d_module_base,d_progress);
1738 log_dist_tax_attributes(d_module_base,d_progress);
1739 END IF;
1740
1741 ZX_API_PUB.determine_recovery(
1742 p_api_version => 1.0,
1743 p_init_msg_list => FND_API.G_TRUE,
1744 p_commit => FND_API.G_FALSE,
1745 p_validation_level => FND_API.G_VALID_LEVEL_FULL,
1746 x_return_status => l_return_status,
1747 x_msg_count => l_msg_count,
1748 x_msg_data => l_msg_data
1749 );
1750
1751 -- Raise if any unexpected error
1752 IF (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
1753 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1754 END IF;
1755
1756 -- If expected errors, store error details in po_session_gt temporarily
1757 IF (l_return_status = FND_API.G_RET_STS_ERROR) THEN
1758 x_return_status := l_return_status;
1759 -- Read validation errors from zx_errors_gt into the global
1760 -- error record defined in the spec
1761 SELECT
1762 'DETERMINE_RECOVERY' --error_level,
1763 ,PO_CONSTANTS_SV.PO --document_type_code,
1764 ,p_po_header_id --document_id,
1765 ,ph.segment1 --document_num,
1766 ,null --line_id,
1767 ,null --line_num,
1768 ,zxegt.trx_line_id --line_location_id,
1769 ,pll.shipment_num --shipment_num,
1770 ,zxegt.trx_line_dist_id --distribution_id,
1771 ,pd.distribution_num --distribution_num,
1772 ,zxegt.message_text --message_text
1773 BULK COLLECT INTO G_TAX_ERRORS_TBL
1774 FROM zx_errors_gt zxegt, po_headers_all ph,
1775 po_line_locations_all pll, po_distributions_all pd
1776 WHERE zxegt.trx_id = ph.po_header_id
1777 AND zxegt.trx_line_id = pll.line_location_id(+)
1778 AND zxegt.trx_line_dist_id = pd.po_distribution_id(+);
1779
1780 BEGIN
1781 SELECT COUNT(1) INTO l_count FROM zx_errors_gt;
1782 EXCEPTION WHEN OTHERS THEN
1783 IF PO_LOG.d_stmt THEN
1784 PO_LOG.stmt(d_module_base,d_progress,'Exception while hitting zx_errors_gt');
1785 END IF;
1786 l_count := 0;
1787 END;
1788
1789 IF PO_LOG.d_stmt THEN
1790 PO_LOG.stmt(d_module_base,d_progress,'Number of records in zx_errors_gt '||l_count);
1791 PO_LOG.stmt(d_module_base,d_progress,'Number of error records collected '||G_TAX_ERRORS_TBL.error_level.COUNT);
1792 END IF;
1793
1794 RAISE FND_API.G_EXC_ERROR;
1795 END IF; --IF (l_return_status = FND_API.G_RET_STS_ERROR)
1796
1797 d_progress := 50;
1798 -- Populate recoverable/nonrecoverable tax columns in distributions table
1799 UPDATE po_distributions_all pd
1800 SET pd.recoverable_tax =
1801 (SELECT SUM(zxdist.rec_nrec_tax_amt)
1802 FROM zx_rec_nrec_dist zxdist
1803 WHERE zxdist.trx_line_dist_id = pd.po_distribution_id
1804 AND zxdist.recoverable_flag = 'Y'
1805 AND zxdist.application_id = PO_CONSTANTS_SV.APPLICATION_ID
1806 AND zxdist.entity_code = PO_CONSTANTS_SV.PO_ENTITY_CODE
1807 AND zxdist.event_class_code = PO_CONSTANTS_SV.PO_EVENT_CLASS_CODE)
1808 ,pd.nonrecoverable_tax =
1809 (SELECT SUM(zxdist.rec_nrec_tax_amt)
1810 FROM zx_rec_nrec_dist zxdist
1811 WHERE zxdist.trx_line_dist_id = pd.po_distribution_id
1812 AND zxdist.recoverable_flag = 'N'
1813 AND zxdist.application_id = PO_CONSTANTS_SV.APPLICATION_ID
1814 AND zxdist.entity_code = PO_CONSTANTS_SV.PO_ENTITY_CODE
1815 AND zxdist.event_class_code = PO_CONSTANTS_SV.PO_EVENT_CLASS_CODE)
1816 WHERE pd.po_distribution_id IN
1817 (SELECT trx_line_dist_id FROM zx_itm_distributions_gt);
1818
1819 /* Bug 6157632 Start */
1820 UPDATE po_line_locations_all pll
1821 SET pll.taxable_flag =
1822 DECODE((SELECT COUNT(1) FROM zx_lines zl
1823 WHERE zl.trx_line_id = pll.line_location_id
1824 AND zl.application_id = PO_CONSTANTS_SV.APPLICATION_ID
1825 AND ( (zl.entity_code = PO_CONSTANTS_SV.PO_ENTITY_CODE
1826 AND zl.event_class_code = PO_CONSTANTS_SV.PO_EVENT_CLASS_CODE
1827 AND zl.trx_id = pll.po_header_id)
1828 OR
1829 (zl.entity_code = PO_CONSTANTS_SV.REL_ENTITY_CODE
1830 AND zl.event_class_code = PO_CONSTANTS_SV.REL_EVENT_CLASS_CODE
1831 AND zl.trx_id = pll.po_release_id))),
1832 0, 'N',
1833 'Y'
1834 )
1835 WHERE
1836 pll.line_location_id IN (SELECT line_location_id FROM po_distributions_all pd,zx_itm_distributions_gt zi WHERE pd.po_distribution_id=zi.trx_line_dist_id);
1837 /* Bug 6157632 End */
1838 END IF;
1839
1840 d_progress := 60;
1841 UPDATE po_distributions_all
1842 SET tax_attribute_update_code = null
1843 WHERE po_distribution_id IN (SELECT trx_line_dist_id
1844 FROM zx_itm_distributions_gt);
1845
1846 IF (PO_LOG.d_proc) THEN
1847 PO_LOG.proc_end(d_module_base);
1848 PO_LOG.proc_end(d_module_base, 'x_return_status', x_return_status);
1849 END IF;
1850 d_progress := 70;
1851
1852 EXCEPTION
1853 WHEN FND_API.G_EXC_ERROR THEN
1854 x_return_status := FND_API.G_RET_STS_ERROR ;
1855 ROLLBACK TO SAVEPOINT det_recovery_po_savepoint;
1856
1857 IF (PO_LOG.d_exc) THEN
1858 PO_LOG.exc(d_module_base, d_progress, null);
1859 PO_LOG.proc_end(d_module_base, 'x_return_status', x_return_status);
1860 END IF;
1861
1862 WHEN OTHERS THEN
1863 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
1864 ROLLBACK TO SAVEPOINT det_recovery_po_savepoint;
1865
1866 IF (PO_LOG.d_exc) THEN
1867 PO_LOG.exc(d_module_base, d_progress, SQLCODE || SQLERRM);
1868 PO_LOG.proc_end(d_module_base, 'x_return_status', x_return_status);
1869 END IF;
1870
1871 END determine_recovery_po;
1872
1873
1874 -----------------------------------------------------------------------------
1875 --Start of Comments
1876 --Name: determine_recovery_rel
1877 --Pre-reqs:
1878 -- None
1879 --Modifies:
1880 -- PO_DISTRIBUTIONS_ALL.nonrecoverable_tax
1881 -- PO_DISTRIBUTIONS_ALL.recoverable_tax
1882 --Locks:
1883 -- Transaction tables if update is allowed
1884 --Function:
1885 -- Distribute tax lines and calculate recoverable and nonrecoverable tax
1886 -- amounts
1887 --Parameters:
1888 --IN:
1889 --p_po_release_id
1890 -- po_release_id for which tax is to be distributed
1891 --OUT:
1892 --x_return_status
1893 -- Standard API specification parameter
1894 -- Can hold one of the following values:
1895 -- FND_API.G_RET_STS_SUCCESS (='S')
1896 -- FND_API.G_RET_STS_ERROR (='E')
1897 -- FND_API.G_RET_STS_UNEXP_ERROR (='U')
1898 --Notes:
1899 -- 1. Calls out to EBTax API determine recovery to distribute tax lines
1900 -- Populates recoverable_tax and nonrecoverable_tax columns in distributions
1901 -- with the corrsponding tax amounts calculated.
1902 -- 2. Returns all expected errors from etax API's in global tax error record
1903 --End of Comments
1904 -----------------------------------------------------------------------------
1905 PROCEDURE determine_recovery_rel(p_po_release_id IN NUMBER,
1906 x_return_status OUT NOCOPY VARCHAR2
1907 ) IS
1908 l_module_name CONSTANT VARCHAR2(100) := 'DETERMINE_RECOVERY_REL';
1909 d_module_base CONSTANT VARCHAR2(100) := PO_LOG.get_subprogram_base(
1910 D_PACKAGE_BASE, l_module_name);
1911 d_progress NUMBER;
1912 l_msg_count NUMBER;
1913 l_msg_data VARCHAR2(1000);
1914 l_count NUMBER;
1915 l_return_status VARCHAR2(1);
1916 BEGIN
1917 SAVEPOINT det_recovery_rel_savepoint;
1918
1919 IF (PO_LOG.d_proc) THEN
1920 PO_LOG.proc_begin(d_module_base);
1921 PO_LOG.proc_begin(d_module_base, 'p_po_release_id', p_po_release_id);
1922 END IF;
1923
1924 d_progress := 0;
1925
1926 -- By default return status is SUCCESS if no exception occurs
1927 x_return_status := FND_API.G_RET_STS_SUCCESS;
1928 -- Set global error record to uninitialized local record to set all its
1929 -- components to null
1930 G_TAX_ERRORS_TBL := null;
1931 initialize_zx_gt_tables(); -- Wipe ZX GT tables clean
1932 initialize_global_error_record();
1933
1934 d_progress := 10;
1935 -- Populate ZX headers GT table with transaction header data
1936 populate_header_rel(p_po_release_id);
1937 d_progress := 20;
1938 -- Populate ZX distributions GT table with transaction distribution data
1939 populate_all_dists_rel(p_po_release_id);
1940
1941 d_progress := 30;
1942 -- Call eTax API determine_recovery to distribute tax lines
1943 BEGIN
1944 SELECT COUNT(1) INTO l_count FROM zx_itm_distributions_gt;
1945 EXCEPTION WHEN OTHERS THEN
1946 l_count := 0;
1947 END;
1948
1949 IF (l_count <> 0) THEN
1950 d_progress := 40;
1951
1952 -- Log table parameters
1953 IF PO_LOG.d_stmt THEN
1954 PO_LOG.stmt(d_module_base,d_progress,'Table parameters before determine_recovery');
1955 log_header_tax_attributes(d_module_base,d_progress);
1956 log_dist_tax_attributes(d_module_base,d_progress);
1957 END IF;
1958
1959 ZX_API_PUB.determine_recovery(
1960 p_api_version => 1.0,
1961 p_init_msg_list => FND_API.G_TRUE,
1962 p_commit => FND_API.G_FALSE,
1963 p_validation_level => FND_API.G_VALID_LEVEL_FULL,
1964 x_return_status => l_return_status,
1965 x_msg_count => l_msg_count,
1966 x_msg_data => l_msg_data
1967 );
1968
1969 -- Raise if any unexpected error
1970 IF (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
1971 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1972 END IF;
1973
1974 -- If expected errors, store error details in po_session_gt temporarily
1975 IF (l_return_status = FND_API.G_RET_STS_ERROR) THEN
1976 x_return_status := l_return_status;
1977 -- Read validation errors from zx_errors_gt into the global
1978 -- error record defined in the spec
1979 SELECT
1980 'DETERMINE_RECOVERY' --error_level,
1981 ,PO_CONSTANTS_SV.PO --document_type_code,
1982 ,p_po_release_id --document_id,
1983 ,ph.segment1 --document_num,
1984 ,null --line_id,
1985 ,null --line_num,
1986 ,zxegt.trx_line_id --line_location_id,
1987 ,pll.shipment_num --shipment_num,
1988 ,zxegt.trx_line_dist_id --distribution_id,
1989 ,pd.distribution_num --distribution_num,
1990 ,zxegt.message_text --message_text
1991 BULK COLLECT INTO G_TAX_ERRORS_TBL
1992 FROM zx_errors_gt zxegt, po_releases_all pr, po_headers_all ph,
1993 po_line_locations_all pll, po_distributions_all pd
1994 WHERE zxegt.trx_id = pr.po_release_id
1995 AND pr.po_header_id = ph.po_header_id
1996 AND zxegt.trx_line_id = pll.line_location_id(+)
1997 AND zxegt.trx_line_dist_id = pd.po_distribution_id(+);
1998
1999 BEGIN
2000 SELECT COUNT(1) INTO l_count FROM zx_errors_gt;
2001 EXCEPTION WHEN OTHERS THEN
2002 IF PO_LOG.d_stmt THEN
2003 PO_LOG.stmt(d_module_base,d_progress,'Exception while hitting zx_errors_gt');
2004 END IF;
2005 l_count := 0;
2006 END;
2007
2008 IF PO_LOG.d_stmt THEN
2009 PO_LOG.stmt(d_module_base,d_progress,'Number of records in zx_errors_gt '||l_count);
2010 PO_LOG.stmt(d_module_base,d_progress,'Number of error records collected '||G_TAX_ERRORS_TBL.error_level.COUNT);
2011 END IF;
2012
2013 RAISE FND_API.G_EXC_ERROR;
2014 END IF; --IF (l_return_status = FND_API.G_RET_STS_ERROR)
2015
2016 d_progress := 50;
2017 -- Populate recoverable/nonrecoverable tax columns in distributions table
2018 UPDATE po_distributions_all pd
2019 SET pd.recoverable_tax =
2020 (SELECT SUM(zxdist.rec_nrec_tax_amt)
2021 FROM zx_rec_nrec_dist zxdist
2022 WHERE zxdist.trx_line_dist_id = pd.po_distribution_id
2023 AND zxdist.recoverable_flag = 'Y'
2024 AND zxdist.application_id = PO_CONSTANTS_SV.APPLICATION_ID
2025 AND zxdist.entity_code = PO_CONSTANTS_SV.REL_ENTITY_CODE
2026 AND zxdist.event_class_code = PO_CONSTANTS_SV.REL_EVENT_CLASS_CODE)
2027 ,pd.nonrecoverable_tax =
2028 (SELECT SUM(zxdist.rec_nrec_tax_amt)
2029 FROM zx_rec_nrec_dist zxdist
2030 WHERE zxdist.trx_line_dist_id = pd.po_distribution_id
2031 AND zxdist.recoverable_flag = 'N'
2032 AND zxdist.application_id = PO_CONSTANTS_SV.APPLICATION_ID
2033 AND zxdist.entity_code = PO_CONSTANTS_SV.REL_ENTITY_CODE
2034 AND zxdist.event_class_code = PO_CONSTANTS_SV.REL_EVENT_CLASS_CODE)
2035 WHERE pd.po_distribution_id IN
2036 (SELECT trx_line_dist_id FROM zx_itm_distributions_gt);
2037
2038 /* Bug 6157632 Start */
2039 UPDATE po_line_locations_all pll
2040 SET pll.taxable_flag =
2041 DECODE((SELECT COUNT(1) FROM zx_lines zl
2042 WHERE zl.trx_line_id = pll.line_location_id
2043 AND zl.application_id = PO_CONSTANTS_SV.APPLICATION_ID
2044 AND ( (zl.entity_code = PO_CONSTANTS_SV.PO_ENTITY_CODE
2045 AND zl.event_class_code = PO_CONSTANTS_SV.PO_EVENT_CLASS_CODE
2046 AND zl.trx_id = pll.po_header_id)
2047 OR
2048 (zl.entity_code = PO_CONSTANTS_SV.REL_ENTITY_CODE
2049 AND zl.event_class_code = PO_CONSTANTS_SV.REL_EVENT_CLASS_CODE
2050 AND zl.trx_id = pll.po_release_id))),
2051 0, 'N',
2052 'Y'
2053 )
2054 WHERE
2055 pll.line_location_id IN (SELECT line_location_id FROM po_distributions_all pd,zx_itm_distributions_gt zi WHERE pd.po_distribution_id=zi.trx_line_dist_id);
2056 /* Bug 6157632 End */
2057
2058
2059 END IF;
2060
2061 d_progress := 60;
2062 UPDATE po_distributions_all
2063 SET tax_attribute_update_code = null
2064 WHERE po_distribution_id IN (SELECT trx_line_dist_id
2065 FROM zx_itm_distributions_gt);
2066
2067 IF (PO_LOG.d_proc) THEN
2068 PO_LOG.proc_end(d_module_base);
2069 PO_LOG.proc_end(d_module_base, 'x_return_status', x_return_status);
2070 END IF;
2071 d_progress := 70;
2072
2073 EXCEPTION
2074 WHEN FND_API.G_EXC_ERROR THEN
2075 x_return_status := FND_API.G_RET_STS_ERROR ;
2076 ROLLBACK TO SAVEPOINT det_recovery_rel_savepoint;
2077
2078 IF (PO_LOG.d_exc) THEN
2079 PO_LOG.exc(d_module_base, d_progress, null);
2080 PO_LOG.proc_end(d_module_base, 'x_return_status', x_return_status);
2081 END IF;
2082
2083 WHEN OTHERS THEN
2084 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
2085 ROLLBACK TO SAVEPOINT det_recovery_rel_savepoint;
2086
2087 IF (PO_LOG.d_exc) THEN
2088 PO_LOG.exc(d_module_base, d_progress, SQLCODE || SQLERRM);
2089 PO_LOG.proc_end(d_module_base, 'x_return_status', x_return_status);
2090 END IF;
2091
2092 END determine_recovery_rel;
2093
2094
2095 -----------------------------------------------------------------------------
2096 --Start of Comments
2097 --Name: determine_recovery_req
2098 --Pre-reqs:
2099 -- None
2100 --Modifies:
2101 -- PO_REQ_DISTRIBUTIONS_ALL.nonrecoverable_tax
2102 -- PO_REQ_DISTRIBUTIONS_ALL.recoverable_tax
2103 --Locks:
2104 -- Transaction tables if update is allowed
2105 --Function:
2106 -- Distributes tax lines and calculates_recoverable and nonrecoverable tax
2107 -- amounts
2108 --Parameters:
2109 --IN:
2110 --p_requisition_header_id
2111 -- requisition_header_id for which tax is to be distributed
2112 --OUT:
2113 --x_return_status
2114 -- Standard API specification parameter
2115 -- Can hold one of the following values:
2116 -- FND_API.G_RET_STS_SUCCESS (='S')
2117 -- FND_API.G_RET_STS_ERROR (='E')
2118 -- FND_API.G_RET_STS_UNEXP_ERROR (='U')
2119 --Notes:
2120 -- 1. Calls out to EBTax API determine recovery to calculate recoverable_tax
2121 -- and nonrecoverable_tax
2122 -- 2. Returns all expected errors from etax API in global tax error record
2123 --End of Comments
2124 -----------------------------------------------------------------------------
2125 PROCEDURE determine_recovery_req(p_requisition_header_id IN NUMBER,
2126 x_return_status OUT NOCOPY VARCHAR2
2127 ) IS
2128 l_module_name CONSTANT VARCHAR2(100) := 'DETERMINE_RECOVERY_REQ';
2129 d_module_base CONSTANT VARCHAR2(100) := PO_LOG.get_subprogram_base(
2130 D_PACKAGE_BASE, l_module_name);
2131 d_progress NUMBER;
2132 l_count NUMBER;
2133 l_msg_count NUMBER;
2134 l_msg_data VARCHAR2(1000);
2135 l_return_status VARCHAR2(1);
2136 BEGIN
2137
2138 SAVEPOINT det_recovery_req_savepoint;
2139
2140 IF (PO_LOG.d_proc) THEN
2141 PO_LOG.proc_begin(d_module_base);
2142 PO_LOG.proc_begin(d_module_base, 'p_requisition_header_id', p_requisition_header_id);
2143 END IF;
2144
2145 d_progress := 0;
2146
2147 -- By default return status is SUCCESS if no exception occurs
2148 x_return_status := FND_API.G_RET_STS_SUCCESS;
2149 -- Set global error record to uninitialized local record to set all its
2150 -- components to null
2151 G_TAX_ERRORS_TBL := null;
2152 initialize_zx_gt_tables(); -- Wipe ZX GT tables clean
2153 initialize_global_error_record();
2154
2155 d_progress := 10;
2156 -- Populate ZX headers GT table with transaction header data
2157 populate_zx_headers_with_req(p_requisition_header_id, 'DETERMINE_RECOVERY_REQ');
2158
2159 d_progress := 20;
2160 -- Populate ZX distributions GT table with transaction distribution data
2161 populate_zx_dists_with_req(p_requisition_header_id, 'DETERMINE_RECOVERY_REQ');
2162
2163 d_progress := 30;
2164 -- Call eTax API determine_recovery if zx distributions gt is not empty
2165 BEGIN
2166 SELECT COUNT(1) INTO l_count FROM zx_itm_distributions_gt;
2167 EXCEPTION WHEN OTHERS THEN
2168 l_count := 0;
2169 END;
2170
2171 IF (l_count <> 0) THEN
2172 d_progress := 40;
2173
2174 -- Log table parameters
2175 IF PO_LOG.d_stmt THEN
2176 PO_LOG.stmt(d_module_base,d_progress,'Table parameters before determine_recovery');
2177 log_header_tax_attributes(d_module_base,d_progress);
2178 log_dist_tax_attributes(d_module_base,d_progress);
2179 END IF;
2180
2181 ZX_API_PUB.determine_recovery(
2182 p_api_version => 1.0,
2183 p_init_msg_list => FND_API.G_FALSE,
2184 p_commit => FND_API.G_FALSE,
2185 p_validation_level => FND_API.G_VALID_LEVEL_FULL,
2186 x_return_status => l_return_status,
2187 x_msg_count => l_msg_count,
2188 x_msg_data => l_msg_data
2189 );
2190
2191 -- Raise if any unexpected error
2192 IF (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
2193 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2194 END IF;
2195
2196 -- If there are any expected errors then set the return status accordingly
2197 -- and copy over errors into global tax errors record
2198 IF (l_return_status = FND_API.G_RET_STS_ERROR) THEN
2199 x_return_status := l_return_status;
2200 -- Read validation errors from zx_errors_gt into the global
2201 -- error record defined in the spec
2202 SELECT
2203 'DETERMINE_RECOVERY' --error_level,
2204 ,PO_CONSTANTS_SV.REQUISITION --document_type_code,
2205 ,p_requisition_header_id --document_id,
2206 ,prh.segment1 --document_num,
2207 ,zxegt.trx_line_id --line_id,
2208 ,prl.line_num --line_num,
2209 ,null --line_location_id,
2210 ,null --shipment_num,
2211 ,zxegt.trx_line_dist_id --distribution_id,
2212 ,prd.distribution_num --distribution_num,
2213 ,zxegt.message_text --message_text
2214 BULK COLLECT INTO G_TAX_ERRORS_TBL
2215 FROM zx_errors_gt zxegt, po_requisition_headers_all prh,
2216 po_requisition_lines_all prl, po_req_distributions_all prd
2217 WHERE zxegt.trx_id = prh.requisition_header_id
2218 AND zxegt.trx_line_id = prl.requisition_line_id(+)
2219 AND zxegt.trx_line_dist_id = prd.distribution_id(+);
2220
2221 BEGIN
2222 SELECT COUNT(1) INTO l_count FROM zx_errors_gt;
2223 EXCEPTION WHEN OTHERS THEN
2224 IF PO_LOG.d_stmt THEN
2225 PO_LOG.stmt(d_module_base,d_progress,'Exception while hitting zx_errors_gt');
2226 END IF;
2227 l_count := 0;
2228 END;
2229
2230 IF PO_LOG.d_stmt THEN
2231 PO_LOG.stmt(d_module_base,d_progress,'Number of records in zx_errors_gt '||l_count);
2232 PO_LOG.stmt(d_module_base,d_progress,'Number of error records collected '||G_TAX_ERRORS_TBL.error_level.COUNT);
2233 END IF;
2234
2235 RAISE FND_API.G_EXC_ERROR;
2236 END IF;
2237
2238 d_progress := 50;
2239 -- Populate recoverable/nonrecoverable tax columns in distributions table
2240 UPDATE po_req_distributions_all prd
2241 SET prd.recoverable_tax =
2242 (SELECT SUM(zxdist.rec_nrec_tax_amt)
2243 FROM zx_rec_nrec_dist_gt zxdist
2244 WHERE zxdist.trx_line_dist_id = prd.distribution_id
2245 AND zxdist.recoverable_flag = 'Y'
2246 AND zxdist.application_id = PO_CONSTANTS_SV.APPLICATION_ID
2247 AND zxdist.entity_code = PO_CONSTANTS_SV.REQ_ENTITY_CODE
2248 AND zxdist.event_class_code = PO_CONSTANTS_SV.REQ_EVENT_CLASS_CODE)
2249 ,prd.nonrecoverable_tax =
2250 (SELECT SUM(zxdist.rec_nrec_tax_amt)
2251 FROM zx_rec_nrec_dist_gt zxdist
2252 WHERE zxdist.trx_line_dist_id = prd.distribution_id
2253 AND zxdist.recoverable_flag = 'N'
2254 AND zxdist.application_id = PO_CONSTANTS_SV.APPLICATION_ID
2255 AND zxdist.entity_code = PO_CONSTANTS_SV.REQ_ENTITY_CODE
2256 AND zxdist.event_class_code = PO_CONSTANTS_SV.REQ_EVENT_CLASS_CODE)
2257 WHERE prd.distribution_id IN
2258 (SELECT trx_line_dist_id FROM zx_itm_distributions_gt);
2259
2260 END IF; -- IF (l_count <> 0)
2261
2262 IF (PO_LOG.d_proc) THEN
2263 PO_LOG.proc_end(d_module_base);
2264 PO_LOG.proc_end(d_module_base, 'x_return_status', x_return_status);
2265 END IF;
2266 d_progress := 60;
2267
2268 EXCEPTION
2269 WHEN FND_API.G_EXC_ERROR THEN
2270 x_return_status := FND_API.G_RET_STS_ERROR ;
2271 ROLLBACK TO SAVEPOINT det_recovery_req_savepoint;
2272
2273 IF (PO_LOG.d_exc) THEN
2274 PO_LOG.exc(d_module_base, d_progress, null);
2275 PO_LOG.proc_end(d_module_base, 'x_return_status', x_return_status);
2276 END IF;
2277
2278 WHEN OTHERS THEN
2279 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
2280 ROLLBACK TO SAVEPOINT det_recovery_req_savepoint;
2281
2282 IF (PO_LOG.d_exc) THEN
2283 PO_LOG.exc(d_module_base, d_progress, SQLCODE || SQLERRM);
2284 PO_LOG.proc_end(d_module_base, 'x_return_status', x_return_status);
2285 END IF;
2286 END determine_recovery_req;
2287
2288
2289 -----------------------------------------------------------------------------
2290 --Start of Comments
2291 --Name: populate_zx_headers_with_po
2292 --Pre-reqs:
2293 -- None
2294 --Modifies:
2295 -- ZX_TRX_HEADERS_GT
2296 --Locks:
2297 -- ZX_TRX_HEADERS_GT
2298 --Function:
2299 -- Populate ZX_TRX_HEADERS_GT with transaction header data
2300 --Parameters:
2301 --IN:
2302 --p_po_header_id_tbl
2303 -- PL/SQL table with list of po_header_id's to process for tax_calculation
2304 --p_calling_program
2305 -- Identifies the module that calls this procedure eg. 'PDOI'
2306 --Notes:
2307 -- Used by calculate_tax procedure. Not to be used externally
2308 --End of Comments
2309 -----------------------------------------------------------------------------
2310 PROCEDURE populate_zx_headers_with_po(p_po_header_id_tbl IN PO_TBL_NUMBER,
2311 p_calling_program IN VARCHAR2
2312 ) IS
2313 BEGIN
2314
2315 -- Populate zx_trx_headers_gt for POs
2316 FORALL i IN 1..p_po_header_id_tbl.COUNT
2317 INSERT INTO zx_trx_headers_gt(
2318 internal_organization_id
2319 ,application_id
2320 ,entity_code
2321 ,event_class_code
2322 ,event_type_code
2323 ,trx_id
2324 ,trx_date
2325 ,trx_doc_revision
2326 ,ledger_id
2327 ,trx_currency_code
2328 ,currency_conversion_date
2329 ,currency_conversion_rate
2330 ,currency_conversion_type
2331 ,minimum_accountable_unit --Bug 5474336. Pass mau to EBTax
2332 ,precision
2333 ,legal_entity_id
2334 ,rounding_ship_from_party_id
2335 ,default_taxation_country
2336 ,quote_flag
2337 ,trx_number
2338 ,trx_description
2339 ,trx_communicated_date
2340 ,document_sub_type
2341 ,provnl_tax_determination_date
2342 -- Bug 5025018. Updated tax attribute mappings
2343 ,rounding_bill_to_party_id
2344 ,rndg_ship_from_party_site_id
2345 )
2346 SELECT
2347 ph.org_id --internal_organization_id
2348 ,PO_CONSTANTS_SV.APPLICATION_ID --application_id
2349 ,PO_CONSTANTS_SV.PO_ENTITY_CODE --entity_code
2350 ,PO_CONSTANTS_SV.PO_EVENT_CLASS_CODE --event_class_code
2351 ,DECODE(ph.tax_attribute_update_code, --event_type_code
2352 'CREATE', PO_CONSTANTS_SV.PO_CREATED,
2353 'COPY_AND_CREATE', PO_CONSTANTS_SV.PO_CREATED,
2354 PO_CONSTANTS_SV.PO_ADJUSTED) --for null and 'UPDATE'
2355 ,ph.po_header_id --trx_id
2356 ,sysdate --trx_date
2357 ,ph.revision_num --trx_doc_revision
2358 ,(SELECT set_of_books_id --ledger_id
2359 FROM financials_system_params_all WHERE org_id=ph.org_id)
2360 ,ph.currency_code --trx_currency_code
2361 ,ph.rate_date --currency_conversion_date
2362 ,ph.rate --currency_conversion_rate
2363 ,ph.rate_type --currency_conversion_type
2364 --Bug 5474336. Pass mau to EBTax
2365 ,fc.minimum_accountable_unit --minimum_accountable_unit
2366 ,NVL(fc.precision, 2) --precision
2367 ,PO_CORE_S.get_default_legal_entity_id(ph.org_id) --legal_entity_id
2368 ,(SELECT pv.party_id FROM po_vendors pv --rounding_ship_from_party_id
2369 WHERE pv.vendor_id=ph.vendor_id)
2370 ,DECODE(p_calling_program, --default_taxation_country
2371 'COPY_DOCUMENT', null,
2372 zxldet.default_taxation_country)
2373 ,'N' --quote_flag
2374 ,ph.segment1 --trx_number
2375 ,ph.comments --trx_description
2376 ,sysdate --ph.print_date --trx_communicated_date
2377 ,DECODE(p_calling_program, --document_sub_type
2378 'COPY_DOCUMENT', null,
2379 zxldet.document_sub_type)
2380 ,DECODE(ph.document_creation_method, --provnl_tax_determination_date
2381 'CREATE_CONSUMPTION',
2382 (SELECT pll.need_by_date
2383 FROM po_line_locations_all pll
2384 WHERE pll.po_header_id=ph.po_header_id
2385 AND pll.need_by_date IS NOT NULL
2386 AND rownum=1),
2387 null)
2388 -- Bug 5025018. Updated tax attribute mappings
2389 ,ph.org_id --rounding_bill_to_party_id
2390 ,(SELECT pvs.party_site_id from po_vendor_sites_all pvs --rndg_ship_from_party_site_id
2391 WHERE pvs.vendor_site_id=ph.vendor_site_id)
2392 FROM po_headers_all ph, zx_lines_det_factors zxldet, fnd_currencies fc
2393 WHERE ph.po_header_id = p_po_header_id_tbl(i)
2394 AND fc.currency_code = ph.currency_code
2395 -- Conditions for getting Additional Tax Attributes
2396 -- Note that the po_header_id is of current document being processed,
2397 -- not of any source document. Get the first row obtained from join
2398 -- with zx_lines_det_factors because that table is denormalized
2399 AND zxldet.trx_id(+) = ph.po_header_id
2400 AND zxldet.application_id(+) = PO_CONSTANTS_SV.APPLICATION_ID
2401 AND zxldet.entity_code(+) = PO_CONSTANTS_SV.PO_ENTITY_CODE
2402 AND zxldet.event_class_code(+) = PO_CONSTANTS_SV.PO_EVENT_CLASS_CODE
2403 AND zxldet.trx_level_type(+) = PO_CONSTANTS_SV.PO_TRX_LEVEL_TYPE
2404 AND rownum = 1;
2405
2406 END populate_zx_headers_with_po;
2407
2408
2409 -----------------------------------------------------------------------------
2410 --Start of Comments
2411 --Name: populate_header_po
2412 --Pre-reqs:
2413 -- None
2414 --Modifies:
2415 -- ZX_TRX_HEADERS_GT
2416 --Locks:
2417 -- ZX_TRX_HEADERS_GT
2418 --Function:
2419 -- Populate ZX_TRX_HEADERS_GT with transaction header data
2420 --Parameters:
2421 --IN:
2422 --p_po_header_id
2423 -- po__header_id to process for tax distribution
2424 --Notes:
2425 -- Used by determine_recovery_po procedure. Not to be used externally
2426 --End of Comments
2427 -----------------------------------------------------------------------------
2428 PROCEDURE populate_header_po(p_po_header_id IN NUMBER) IS
2429 BEGIN
2430
2431 -- Populate zx_trx_headers_gt for the PO
2432 INSERT INTO zx_trx_headers_gt(
2433 internal_organization_id
2434 ,application_id
2435 ,entity_code
2436 ,event_class_code
2437 ,event_type_code
2438 ,trx_id
2439 ,trx_date
2440 ,trx_doc_revision
2441 ,ledger_id
2442 ,trx_currency_code
2443 ,currency_conversion_date
2444 ,currency_conversion_rate
2445 ,currency_conversion_type
2446 ,minimum_accountable_unit --Bug 5474336. Pass mau to EBTax
2447 ,precision
2448 ,legal_entity_id
2449 ,rounding_ship_from_party_id
2450 ,default_taxation_country
2451 ,quote_flag
2452 ,trx_number
2453 ,trx_description
2454 ,trx_communicated_date
2455 ,document_sub_type
2456 ,provnl_tax_determination_date
2457 -- Bug 5025018. Updated tax attribute mappings
2458 ,rounding_bill_to_party_id
2459 ,rndg_ship_from_party_site_id
2460 )
2461 SELECT
2462 ph.org_id --internal_organization_id
2463 ,PO_CONSTANTS_SV.APPLICATION_ID --application_id
2464 ,PO_CONSTANTS_SV.PO_ENTITY_CODE --entity_code
2465 ,PO_CONSTANTS_SV.PO_EVENT_CLASS_CODE --event_class_code
2466 ,PO_CONSTANTS_SV.PO_REDISTRIBUTED --event_type_code
2467 ,ph.po_header_id --trx_id
2468 ,sysdate --trx_date
2469 ,ph.revision_num --trx_doc_revision
2470 ,(SELECT set_of_books_id --ledger_id
2471 FROM financials_system_params_all WHERE org_id=ph.org_id)
2472 ,ph.currency_code --trx_currency_code
2473 ,ph.rate_date --currency_conversion_date
2474 ,ph.rate --currency_conversion_rate
2475 ,ph.rate_type --currency_conversion_type
2476 --Bug 5474336. Pass mau to EBTax
2477 ,fc.minimum_accountable_unit --minimum_accountable_unit
2478 ,NVL(fc.precision, 2) --precision
2479 ,PO_CORE_S.get_default_legal_entity_id(ph.org_id) --legal_entity_id
2480 ,(SELECT pv.party_id FROM po_vendors pv --rounding_ship_from_party_id
2481 WHERE pv.vendor_id=ph.vendor_id)
2482 ,null --default_taxation_country
2483 ,'N' --quote_flag
2484 ,ph.segment1 --trx_number
2485 ,ph.comments --trx_description
2486 ,sysdate --ph.print_date --trx_communicated_date
2487 ,null --document_sub_type
2488 ,DECODE(ph.document_creation_method, --provnl_tax_determination_date
2489 'CREATE_CONSUMPTION',
2490 (SELECT pll.need_by_date
2491 FROM po_line_locations_all pll
2492 WHERE pll.po_header_id=ph.po_header_id
2493 AND pll.need_by_date IS NOT NULL
2494 AND rownum=1),
2495 null)
2496 -- Bug 5025018. Updated tax attribute mappings
2497 ,ph.org_id --rounding_bill_to_party_id
2498 ,(SELECT pvs.party_site_id from po_vendor_sites_all pvs --rndg_ship_from_party_site_id
2499 WHERE pvs.vendor_site_id=ph.vendor_site_id)
2500 FROM po_headers_all ph, fnd_currencies fc
2501 WHERE ph.po_header_id = p_po_header_id
2502 AND fc.currency_code = ph.currency_code;
2503
2504 END populate_header_po;
2505
2506
2507 -----------------------------------------------------------------------------
2508 --Start of Comments
2509 --Name: populate_zx_headers_with_rel
2510 --Pre-reqs:
2511 -- None
2512 --Modifies:
2513 -- ZX_TRX_HEADERS_GT
2514 --Locks:
2515 -- ZX_TRX_HEADERS_GT
2516 --Function:
2517 -- Populate ZX_TRX_HEADERS_GT with transaction header data
2518 --Parameters:
2519 --IN:
2520 --p_po_release_id_tbl
2521 -- PL/SQL table with list of po_release_id's to process for tax_calculation
2522 --p_calling_program
2523 -- Identifies the module that calls this procedure eg. 'PDOI'
2524 --Notes:
2525 -- Used by calculate_tax procedure. Not to be used externally
2526 --End of Comments
2527 -----------------------------------------------------------------------------
2528 PROCEDURE populate_zx_headers_with_rel(p_po_release_id_tbl IN PO_TBL_NUMBER,
2529 p_calling_program IN VARCHAR2
2530 ) IS
2531 BEGIN
2532 -- Populate zx_trx_headers_gt for Releases
2533 FORALL i in 1..p_po_release_id_tbl.COUNT
2534 INSERT INTO zx_trx_headers_gt(
2535 internal_organization_id
2536 ,application_id
2537 ,entity_code
2538 ,event_class_code
2539 ,event_type_code
2540 ,trx_id
2541 ,trx_date
2542 ,trx_doc_revision
2543 ,ledger_id
2544 ,trx_currency_code
2545 ,currency_conversion_date
2546 ,currency_conversion_rate
2547 ,currency_conversion_type
2548 ,minimum_accountable_unit --Bug 5474336. Pass mau to EBTax
2549 ,precision
2550 ,legal_entity_id
2551 ,rounding_ship_from_party_id
2552 ,default_taxation_country
2553 ,quote_flag
2554 ,trx_number
2555 ,trx_description
2556 ,trx_communicated_date
2557 ,document_sub_type
2558 ,provnl_tax_determination_date
2559 -- Bug 5025018. Updated tax attribute mappings
2560 ,rounding_bill_to_party_id
2561 ,rndg_ship_from_party_site_id
2562 )
2563 SELECT
2564 pr.org_id --internal_organization_id
2565 ,PO_CONSTANTS_SV.APPLICATION_ID --application_id
2566 ,PO_CONSTANTS_SV.REL_ENTITY_CODE --entity_code
2567 ,PO_CONSTANTS_SV.REL_EVENT_CLASS_CODE --event_class_code
2568 ,DECODE(pr.tax_attribute_update_code, --event_type_code
2569 'CREATE', PO_CONSTANTS_SV.REL_CREATED,
2570 'COPY_AND_CREATE', PO_CONSTANTS_SV.REL_CREATED,
2571 PO_CONSTANTS_SV.REL_ADJUSTED) -- for null and 'UPDATE'
2572 ,pr.po_release_id --trx_id
2573 ,sysdate --trx_date
2574 ,pr.revision_num --trx_doc_revision
2575 ,(select set_of_books_id --ledger_id
2576 from financials_system_params_all where org_id=pr.org_id)
2577 ,ph.currency_code --trx_currency_code
2578 ,ph.rate_date --currency_conversion_date
2579 ,ph.rate --currency_conversion_rate
2580 ,ph.rate_type --currency_conversion_type
2581 --Bug 5474336. Pass mau to EBTax
2582 ,fc.minimum_accountable_unit --minimum_accountable_unit
2583 ,NVL(fc.precision, 2) --precision
2584 ,PO_CORE_S.get_default_legal_entity_id(pr.org_id) --legal_entity_id
2585 ,(SELECT pv.party_id FROM po_vendors pv --rounding_ship_from_party_id
2586 WHERE pv.vendor_id=ph.vendor_id)
2587 ,zxldet.default_taxation_country --default_taxation_country
2588 ,'N' --quote_flag
2589 ,ph.segment1 --trx_number
2590 ,null --trx_description
2591 ,sysdate --pr.print_date --trx_communicated_date
2592 ,zxldet.document_sub_type --document_sub_type
2593 ,DECODE(pr.document_creation_method, --provnl_tax_determination_date
2594 'CREATE_CONSUMPTION',
2595 (SELECT pll.need_by_date
2596 FROM po_line_locations_all pll
2597 WHERE pll.po_release_id=pr.po_release_id
2598 AND pll.need_by_date IS NOT NULL
2599 AND rownum=1),
2600 null)
2601 -- Bug 5025018. Updated tax attribute mappings
2602 ,pr.org_id --rounding_bill_to_party_id
2603 ,(SELECT pvs.party_site_id from po_vendor_sites_all pvs --rndg_ship_from_party_site_id
2604 WHERE pvs.vendor_site_id=ph.vendor_site_id)
2605 -- Using OUTER JOIN in FROM clause syntax here because (+) operator
2606 -- is not flexible enough to be used inside an OR condition
2607 FROM po_headers_all ph
2608 ,fnd_currencies fc
2609 ,po_releases_all pr
2610 -- Conditions for getting Additional Tax Attributes
2611 -- Copy from Planned PO if its a newly created Scheduled Release
2612 -- ELSE simply copy from existing release header (ie. in case of a
2613 -- shipment split or regular blanket/scheduled release create/update
2614 LEFT OUTER JOIN zx_lines_det_factors zxldet
2615 ON ((pr.po_header_id = zxldet.trx_id
2616 AND PO_CONSTANTS_SV.APPLICATION_ID = zxldet.application_id
2617 AND PO_CONSTANTS_SV.PO_ENTITY_CODE = zxldet.entity_code
2618 AND PO_CONSTANTS_SV.PO_EVENT_CLASS_CODE = zxldet.event_class_code
2619 AND PO_CONSTANTS_SV.PO_TRX_LEVEL_TYPE = zxldet.trx_level_type
2620 AND pr.release_type = PO_CONSTANTS_SV.SCHEDULED
2621 AND pr.tax_attribute_update_code = 'CREATE')
2622 OR
2623 (pr.po_release_id = zxldet.trx_id
2624 AND PO_CONSTANTS_SV.APPLICATION_ID = zxldet.application_id
2625 AND PO_CONSTANTS_SV.REL_ENTITY_CODE = zxldet.entity_code
2626 AND PO_CONSTANTS_SV.REL_EVENT_CLASS_CODE = zxldet.event_class_code
2627 AND PO_CONSTANTS_SV.REL_TRX_LEVEL_TYPE = zxldet.trx_level_type)
2628 )
2629 WHERE pr.po_release_id = p_po_release_id_tbl(i)
2630 AND pr.po_header_id = ph.po_header_id
2631 AND fc.currency_code = ph.currency_code
2632 AND rownum = 1;
2633
2634 END populate_zx_headers_with_rel;
2635
2636
2637 -----------------------------------------------------------------------------
2638 --Start of Comments
2639 --Name: populate_header_rel
2640 --Pre-reqs:
2641 -- None
2642 --Modifies:
2643 -- ZX_TRX_HEADERS_GT
2644 --Locks:
2645 -- ZX_TRX_HEADERS_GT
2646 --Function:
2647 -- Populate ZX_TRX_HEADERS_GT with transaction header data
2648 --Parameters:
2649 --IN:
2650 --p_po_release_id
2651 -- po_release_id to process for tax distribution
2652 --Notes:
2653 -- Used by determine_recovery_rel procedure. Not to be used externally
2654 --End of Comments
2655 -----------------------------------------------------------------------------
2656 PROCEDURE populate_header_rel(p_po_release_id IN NUMBER) IS
2657 BEGIN
2658
2659 -- Populate zx_trx_headers_gt for Releases
2660 INSERT INTO zx_trx_headers_gt(
2661 internal_organization_id
2662 ,application_id
2663 ,entity_code
2664 ,event_class_code
2665 ,event_type_code
2666 ,trx_id
2667 ,trx_date
2668 ,trx_doc_revision
2669 ,ledger_id
2670 ,trx_currency_code
2671 ,currency_conversion_date
2672 ,currency_conversion_rate
2673 ,currency_conversion_type
2674 ,minimum_accountable_unit --Bug 5474336. Pass mau to EBTax
2675 ,precision
2676 ,legal_entity_id
2677 ,rounding_ship_from_party_id
2678 ,default_taxation_country
2679 ,quote_flag
2680 ,trx_number
2681 ,trx_description
2682 ,trx_communicated_date
2683 ,document_sub_type
2684 ,provnl_tax_determination_date
2685 -- Bug 5025018. Updated tax attribute mappings
2686 ,rounding_bill_to_party_id
2687 ,rndg_ship_from_party_site_id
2688 )
2689 SELECT
2690 pr.org_id --internal_organization_id
2691 ,PO_CONSTANTS_SV.APPLICATION_ID --application_id
2692 ,PO_CONSTANTS_SV.REL_ENTITY_CODE --entity_code
2693 ,PO_CONSTANTS_SV.REL_EVENT_CLASS_CODE --event_class_code
2694 ,PO_CONSTANTS_SV.REL_REDISTRIBUTED --event_type_code
2695 ,pr.po_release_id --trx_id
2696 ,sysdate --trx_date
2697 ,pr.revision_num --trx_doc_revision
2698 ,(select set_of_books_id --ledger_id
2699 from financials_system_params_all where org_id=pr.org_id)
2700 ,ph.currency_code --trx_currency_code
2701 ,ph.rate_date --currency_conversion_date
2702 ,ph.rate --currency_conversion_rate
2703 ,ph.rate_type --currency_conversion_type
2704 --Bug 5474336. Pass mau to EBTax
2705 ,fc.minimum_accountable_unit --minimum_accountable_unit
2706 ,NVL(fc.precision, 2) --precision
2707 ,PO_CORE_S.get_default_legal_entity_id(pr.org_id) --legal_entity_id
2708 ,(SELECT pv.party_id FROM po_vendors pv --rounding_ship_from_party_id
2709 WHERE pv.vendor_id=ph.vendor_id)
2710 ,null --default_taxation_country
2711 ,'N' --quote_flag
2712 ,ph.segment1 --trx_number
2713 ,null --trx_description
2714 ,sysdate --pr.print_date --trx_communicated_date
2715 ,null --document_sub_type
2716 ,DECODE(pr.document_creation_method, --provnl_tax_determination_date
2717 'CREATE_CONSUMPTION',
2718 (SELECT pll.need_by_date
2719 FROM po_line_locations_all pll
2720 WHERE pll.po_release_id=pr.po_release_id
2721 AND pll.need_by_date IS NOT NULL
2722 AND rownum=1),
2723 null)
2724 -- Bug 5025018. Updated tax attribute mappings
2725 ,ph.org_id --rounding_bill_to_party_id
2726 ,(SELECT pvs.party_site_id from po_vendor_sites_all pvs --rndg_ship_from_party_site_id
2727 WHERE pvs.vendor_site_id=ph.vendor_site_id)
2728 FROM po_releases_all pr, po_headers_all ph, fnd_currencies fc
2729 WHERE pr.po_release_id = p_po_release_id
2730 AND pr.po_header_id = ph.po_header_id
2731 AND fc.currency_code = ph.currency_code;
2732
2733 END populate_header_rel;
2734
2735
2736 -----------------------------------------------------------------------------
2737 --Start of Comments
2738 --Name: populate_zx_headers_with_req
2739 --Pre-reqs:
2740 -- None
2741 --Modifies:
2742 -- ZX_TRX_HEADERS_GT
2743 --Locks:
2744 -- ZX_TRX_HEADERS_GT
2745 --Function:
2746 -- Populate ZX_TRX_HEADERS_GT with transaction header data
2747 --Parameters:
2748 --IN:
2749 --p_requisition_header_id
2750 -- PL/SQL table with list of po_header_id's to process for tax_calculation
2751 --p_calling_program
2752 -- Identifies the module that calls this procedure eg. 'PDOI'
2753 --Notes:
2754 -- Used by calculate_tax_requisition procedure. Not to be used externally
2755 --End of Comments
2756 -----------------------------------------------------------------------------
2757 PROCEDURE populate_zx_headers_with_req(p_requisition_header_id IN NUMBER,
2758 p_calling_program IN VARCHAR2
2759 ) IS
2760 BEGIN
2761 -- populate zx_trx_headers_gt for the requisition
2762 -- Addition/Removal of any attribute entails similar change in
2763 -- populate_zx_record as well
2764 INSERT INTO zx_trx_headers_gt(
2765 internal_organization_id
2766 ,application_id
2767 ,entity_code
2768 ,event_class_code
2769 ,event_type_code
2770 ,trx_id
2771 ,trx_date
2772 ,ledger_id
2773 ,legal_entity_id
2774 ,rounding_bill_to_party_id
2775 ,quote_flag
2776 ,document_sub_type
2777 ,default_taxation_country
2778 ,icx_session_id
2779 )
2780 SELECT
2781 prh.org_id --internal_organization_id
2782 ,PO_CONSTANTS_SV.APPLICATION_ID --application_id
2783 ,PO_CONSTANTS_SV.REQ_ENTITY_CODE --entity_code
2784 ,PO_CONSTANTS_SV.REQ_EVENT_CLASS_CODE --event_class_code
2785 ,DECODE(p_calling_program, --event_type_code
2786 --If calling determine_recovery from ATI page flow
2787 'DETERMINE_RECOVERY_REQ', PO_CONSTANTS_SV.REQ_DISTRIBUTED,
2788 --Regular UI flow
2789 PO_CONSTANTS_SV.REQ_CREATED)
2790 ,prh.requisition_header_id --trx_id
2791 ,sysdate --trx_date
2792 ,(select set_of_books_id --ledger_id
2793 from financials_system_params_all where org_id=prh.org_id)
2794 ,PO_CORE_S.get_default_legal_entity_id(prh.org_id) --legal_entity_id
2795 ,prh.org_id --rounding_bill_to_party_id
2796 ,'Y' --quote_flag
2797 ,zxldet.document_sub_type --document_sub_type
2798 ,zxldet.default_taxation_country --default_taxation_country
2799 ,DECODE(p_calling_program, --icx_session_id
2800 'DETERMINE_RECOVERY_REQ', null,
2801 FND_GLOBAL.session_id)
2802 FROM po_requisition_headers_all prh, zx_lines_det_factors zxldet
2803 WHERE prh.requisition_header_id = p_requisition_header_id
2804 -- Conditions for getting Additional Tax Attributes
2805 -- Note that the req_header_id is of current document being processed,
2806 -- not of any source document. Get the first row obtained from join
2807 -- with zx_lines_det_factors because that table is denormalized
2808 AND zxldet.trx_id(+) = prh.requisition_header_id
2809 AND zxldet.application_id(+) = PO_CONSTANTS_SV.APPLICATION_ID
2810 AND zxldet.entity_code(+) = PO_CONSTANTS_SV.REQ_ENTITY_CODE
2811 AND zxldet.event_class_code(+) = PO_CONSTANTS_SV.REQ_EVENT_CLASS_CODE
2812 AND zxldet.trx_level_type(+) = PO_CONSTANTS_SV.REQ_TRX_LEVEL_TYPE
2813 AND rownum = 1;
2814
2815 END populate_zx_headers_with_req;
2816
2817
2818 -----------------------------------------------------------------------------
2819 --Start of Comments
2820 --Name: populate_zx_lines_with_po
2821 --Pre-reqs:
2822 -- None
2823 --Modifies:
2824 -- ZX_TRANSACTION_LINES_GT
2825 --Locks:
2826 -- ZX_TRANSACTION_LINES_GT
2827 --Function:
2828 -- Populate ZX_TRANSACTION_LINES_GT with transaction line and shipment data
2829 --Parameters:
2830 --IN:
2831 --p_po_header_id_tbl
2832 -- PL/SQL table with list of po_header_id's to process for tax_calculation
2833 --p_calling_program
2834 -- Identifies the module that calls this procedure eg. 'PDOI'
2835 --Notes:
2836 -- Used by calculate_tax procedure. Not to be used externally
2837 --End of Comments
2838 -----------------------------------------------------------------------------
2839 PROCEDURE populate_zx_lines_with_po(p_po_header_id_tbl IN PO_TBL_NUMBER,
2840 p_calling_program IN VARCHAR2
2841 ) IS
2842 BEGIN
2843
2844 -- Populate zx_transaction_lines_gt for POs
2845 FORALL i in 1..p_po_header_id_tbl.COUNT
2846 INSERT INTO zx_transaction_lines_gt(
2847 application_id
2848 ,entity_code
2849 ,event_class_code
2850 ,trx_id
2851 ,trx_level_type
2852 ,trx_line_id
2853 ,line_level_action
2854 ,line_class
2855 ,trx_line_type
2856 ,trx_line_date
2857 ,trx_business_category
2858 ,line_intended_use
2859 ,user_defined_fisc_class
2860 ,line_amt
2861 ,trx_line_quantity
2862 ,product_id
2863 ,product_org_id
2864 ,product_fisc_classification
2865 ,uom_code
2866 ,product_type
2867 ,product_code
2868 ,product_category
2869 ,fob_point
2870 ,ship_from_party_id
2871 ,bill_from_party_id
2872 ,ship_from_party_site_id
2873 ,bill_from_party_site_id
2874 ,ship_to_location_id
2875 ,ship_from_location_id
2876 ,bill_to_location_id
2877 ,bill_from_location_id /* 6524317 */
2878 ,account_ccid
2879 ,ref_doc_application_id
2880 ,ref_doc_entity_code
2881 ,ref_doc_event_class_code
2882 ,ref_doc_trx_id
2883 ,ref_doc_line_id
2884 ,line_trx_user_key1
2885 ,line_trx_user_key2
2886 -- Bug 5079867. Ordering of complex work payment lines in ATI page
2887 ,line_trx_user_key3
2888 ,trx_line_number
2889 ,trx_line_description
2890 ,product_description
2891 ,assessable_value
2892 ,line_amt_includes_tax_flag
2893 ,input_tax_classification_code
2894 ,source_application_id
2895 ,source_entity_code
2896 ,source_event_class_code
2897 ,source_trx_id
2898 ,source_line_id
2899 ,source_trx_level_type
2900 ,unit_price
2901 ,ref_doc_trx_level_type
2902 -- Bug 5025018. Updated tax attribute mappings
2903 ,ship_third_pty_acct_id
2904 ,bill_third_pty_acct_id
2905 ,ship_third_pty_acct_site_id
2906 ,bill_third_pty_acct_site_id
2907 ,ship_to_party_id
2908 ,user_upd_det_factors_flag --Bug 5632300
2909 ,defaulting_attribute1 --Bug#6902111
2910 )
2911 SELECT
2912 PO_CONSTANTS_SV.APPLICATION_ID --application_id
2913 ,PO_CONSTANTS_SV.PO_ENTITY_CODE --entity_code
2914 ,PO_CONSTANTS_SV.PO_EVENT_CLASS_CODE --event_class_code
2915 ,ph.po_header_id --trx_id
2916 ,PO_CONSTANTS_SV.PO_TRX_LEVEL_TYPE --trx_level_type
2917 ,pll.line_location_id --trx_line_id
2918 ,pll.tax_attribute_update_code --line_level_action
2919 ,DECODE(pll.shipment_type,--line_class
2920 'PREPAYMENT', DECODE(pll.payment_type,
2921 'ADVANCE', 'ADVANCE',
2922 'FINANCING'),
2923 DECODE(pll.value_basis,
2924 'QUANTITY', 'INVOICE',
2925 'AMOUNT')
2926 )
2927 ,'ITEM' --trx_line_type
2928 ,COALESCE(pll.need_by_date, pll.promised_date, sysdate) --trx_line_date
2929 ,DECODE(p_calling_program, --trx_business_category
2930 'COPY_DOCUMENT', null,
2931 zxldet.trx_business_category)
2932 ,DECODE(p_calling_program, --line_intended_use
2933 'COPY_DOCUMENT', null,
2934 zxldet.line_intended_use)
2935 ,DECODE(p_calling_program, --user_defined_fisc_class
2936 'COPY_DOCUMENT', null,
2937 zxldet.user_defined_fisc_class)
2938 ,NVL(pll.amount, pll.price_override*pll.quantity) --line_amt
2939 ,pll.quantity --trx_line_quantity
2940 ,pl.item_id --product_id
2941 -- Bug 5335818. Pass in inventory_organization_id
2942 ,(SELECT fsp.inventory_organization_id --product_org_id
2943 FROM financials_system_params_all fsp
2944 WHERE fsp.org_id=pll.org_id)
2945 ,DECODE(p_calling_program, --product_fisc_classification
2946 'COPY_DOCUMENT', null,
2947 zxldet.product_fisc_classification)
2948 ,(SELECT mum.uom_code FROM mtl_units_of_measure mum
2949 WHERE mum.unit_of_measure=pll.unit_meas_lookup_code) --uom_code
2950 ,DECODE(p_calling_program, --product_type
2951 'COPY_DOCUMENT', null,
2952 zxldet.product_type)
2953 ,msib.segment1 --product_code
2954 ,DECODE(p_calling_program, --product_category
2955 'COPY_DOCUMENT', null,
2956 zxldet.product_category)
2957 ,ph.fob_lookup_code --fob_point
2958 ,pv.party_id --ship_from_party_id
2959 ,pv.party_id --bill_from_party_id
2960 ,pvs.party_site_id --ship_from_party_site_id
2961 ,pvs.party_site_id --bill_from_party_site_id
2962 ,pll.ship_to_location_id --ship_to_location_id
2963 ,(SELECT hzps.location_id --ship_from_location_id
2964 FROM hz_party_sites hzps
2965 WHERE hzps.party_site_id = pvs.party_site_id)
2966 ,ph.bill_to_location_id --bill_to_location_id
2967 ,(SELECT pvs.location_id from po_vendor_sites_all pvs /* 6524317 - Passing Location Id as Bill From Location Id */
2968 WHERE pvs.vendor_site_id=ph.vendor_site_id)
2969 -- Get account id from first distribution, if created
2970 -- otherwise from the expense account of the item
2971 ,NVL((SELECT pd.code_combination_id --account_ccid
2972 FROM po_distributions_all pd
2973 WHERE pd.line_location_id = pll.line_location_id
2974 AND rownum = 1),
2975 msib.expense_account
2976 )
2977 ,null --ref_doc_application_id
2978 ,null --ref_doc_entity_code
2979 ,null --ref_doc_event_class_code
2980 ,null --ref_doc_trx_id
2981 ,null --ref_doc_line_id
2982 ,pl.line_num --line_trx_user_key1
2983 ,PO_LOCATIONS_S.get_location_code(pll.ship_to_location_id) --line_trx_user_key2
2984 -- Bug 5079867. Ordering of complex work payment lines in ATI page
2985 ,DECODE(pll.payment_type, null, 0, --line_trx_user_key3
2986 'DELIVERY', 1,
2987 'ADVANCE', 2, 3)
2988 ,DECODE(pll.payment_type, --trx_line_number
2989 'ADVANCE', null,
2990 'DELIVERY', null,
2991 pll.shipment_num)
2992 ,DECODE(pll.shipment_type, --trx_line_description
2993 'STANDARD', DECODE(pll.payment_type,
2994 null, pl.item_description, --non complex work Standard PO
2995 pll.description --complex work Standard PO
2996 ),
2997 pl.item_description -- for shipment_type='PLANNED'
2998 )
2999 ,DECODE(pll.shipment_type, --product_description
3000 'STANDARD', DECODE(pll.payment_type,
3001 null, pl.item_description, --non complex work Standard PO
3002 pll.description --complex work Standard PO
3003 ),
3004 pl.item_description -- for shipment_type='PLANNED'
3005 )
3006 ,DECODE(p_calling_program, --assessable_value
3007 'COPY_DOCUMENT', null,
3008 zxldet.assessable_value)
3009 ,'N' --line_amt_includes_tax_flag
3010 -- Only newly added lines can come in through PDOI (no updated
3011 -- lines), so tax_name can be populated to override.
3012 -- Once the new line has been created, if it is modified
3013 -- through any other program, tax_name field will be populated
3014 -- but will not get populated as overridden tax_classification
3015 ,DECODE(p_calling_program, --input_tax_classification_code
3016 'PDOI', pll.tax_name,
3017 'COPY_DOCUMENT', null,
3018 zxldet.input_tax_classification_code)
3019 -- Bug 7337548
3020 -- Copying requisition information as Source Document Information
3021 -- in case of Autocreate. This information will be used to copy
3022 -- Tax attributes when the attributes are overridden in requisition.
3023 -- Calling program for autocreate is 'POXBWVRP_PO','AUTOCREATED_DOC_WF'
3024 -- and 'PORELGEB'
3025 ,DECODE(p_calling_program, --source_application_id
3026 'COPY_DOCUMENT', PO_CONSTANTS_SV.APPLICATION_ID,
3027 'POXBWVRP_PO', PO_CONSTANTS_SV.APPLICATION_ID,
3028 'AUTOCREATED_DOC_WF' ,PO_CONSTANTS_SV.APPLICATION_ID,
3029 'PORELGEB',PO_CONSTANTS_SV.APPLICATION_ID,
3030 null)
3031 ,DECODE(p_calling_program, --source_entity_code
3032 'COPY_DOCUMENT', PO_CONSTANTS_SV.PO_ENTITY_CODE,
3033 'POXBWVRP_PO', PO_CONSTANTS_SV.REQ_ENTITY_CODE,
3034 'AUTOCREATED_DOC_WF', PO_CONSTANTS_SV.REQ_ENTITY_CODE,
3035 'PORELGEB', PO_CONSTANTS_SV.REQ_ENTITY_CODE,
3036 null)
3037 ,DECODE(p_calling_program, --source_event_class_code
3038 'COPY_DOCUMENT', PO_CONSTANTS_SV.PO_EVENT_CLASS_CODE,
3039 'POXBWVRP_PO', PO_CONSTANTS_SV.REQ_EVENT_CLASS_CODE,
3040 'AUTOCREATED_DOC_WF', PO_CONSTANTS_SV.REQ_EVENT_CLASS_CODE,
3041 'PORELGEB', PO_CONSTANTS_SV.REQ_EVENT_CLASS_CODE,
3042 null)
3043 ,DECODE(p_calling_program, -- source_trx_id
3044 'COPY_DOCUMENT', (SELECT source_shipment.po_header_id --source_trx_id
3045 FROM po_line_locations_all source_shipment
3046 WHERE source_shipment.line_location_id = pll.original_shipment_id
3047 AND p_calling_program = 'COPY_DOCUMENT'),
3048
3049 'POXBWVRP_PO', (SELECT requisition_header_id FROM
3050 po_requisition_lines_all
3051 WHERE requisition_line_id IN (SELECT Min(requisition_line_id) --source_trx_id
3052 FROM po_requisition_lines_all prl
3053 WHERE prl.line_location_id = pll.line_location_id)
3054 AND p_calling_program = 'POXBWVRP_PO'),
3055 'AUTOCREATED_DOC_WF', (SELECT requisition_header_id FROM
3056 po_requisition_lines_all
3057 WHERE requisition_line_id IN (SELECT Min(requisition_line_id) --source_trx_id
3058 FROM po_requisition_lines_all prl
3059 WHERE prl.line_location_id = pll.line_location_id)
3060 AND p_calling_program = 'AUTOCREATED_DOC_WF'),
3061 'PORELGEB', (SELECT requisition_header_id FROM
3062 po_requisition_lines_all
3063 WHERE requisition_line_id IN (SELECT Min(requisition_line_id) --source_trx_id
3064 FROM po_requisition_lines_all prl
3065 WHERE prl.line_location_id = pll.line_location_id)
3066 AND p_calling_program = 'PORELGEB'),
3067 null)
3068 ,DECODE(p_calling_program, --source_line_id
3069 'COPY_DOCUMENT', pll.original_shipment_id,
3070 'POXBWVRP_PO',(SELECT Min(requisition_line_id) --source_line_id
3071 FROM po_requisition_lines_all prl
3072 WHERE prl.line_location_id = pll.line_location_id
3073 AND p_calling_program = 'POXBWVRP_PO'),
3074 'AUTOCREATED_DOC_WF',(SELECT Min(requisition_line_id) --source_line_id
3075 FROM po_requisition_lines_all prl
3076 WHERE prl.line_location_id = pll.line_location_id
3077 AND p_calling_program = 'AUTOCREATED_DOC_WF'),
3078 'PORELGEB',(SELECT Min(requisition_line_id) --source_line_id
3079 FROM po_requisition_lines_all prl
3080 WHERE prl.line_location_id = pll.line_location_id
3081 AND p_calling_program = 'PORELGEB'),
3082 null)
3083 ,DECODE(p_calling_program, --source_trx_level_type
3084 'COPY_DOCUMENT', PO_CONSTANTS_SV.PO_TRX_LEVEL_TYPE,
3085 'POXBWVRP_PO', PO_CONSTANTS_SV.REQ_TRX_LEVEL_TYPE ,
3086 'AUTOCREATED_DOC_WF', PO_CONSTANTS_SV.REQ_TRX_LEVEL_TYPE ,
3087 'PORELGEB', PO_CONSTANTS_SV.REQ_TRX_LEVEL_TYPE ,
3088 null)
3089 ,pll.price_override --unit_price
3090 ,null --ref_doc_trx_level_type
3091 -- Bug 5025018. Updated tax attribute mappings
3092 ,pv.vendor_id --ship_third_pty_acct_id
3093 ,pv.vendor_id --bill_third_pty_acct_id
3094 ,pvs.vendor_site_id --ship_third_pty_acct_site_id
3095 ,pvs.vendor_site_id --bill_third_pty_acct_site_id
3096 ,pll.ship_to_organization_id --ship_to_party_id
3097 --Bug 5632300. Parameter to confirm that tax classification is overridden
3098 ,(SELECT 'Y' FROM DUAL --user_upd_det_factors_flag
3099 WHERE p_calling_program = 'PDOI'
3100 AND pll.tax_name IS NOT NULL)
3101 ,pll.ship_to_organization_id --Bug#6902111
3102 FROM po_headers_all ph, po_lines_all pl, po_line_locations_all pll,
3103 zx_lines_det_factors zxldet, po_vendors pv,
3104 po_vendor_sites_all pvs, mtl_system_items_b msib
3105 WHERE ph.po_header_id = pll.po_header_id
3106 AND pl.po_line_id = pll.po_line_id
3107 AND pll.tax_attribute_update_code IS NOT NULL
3108 AND pll.tax_attribute_update_code <> 'DIST_DELETE'
3109 AND ph.po_header_id = p_po_header_id_tbl(i)
3110 -- Conditions for getting Additional Tax Attributes
3111 -- Do not put a condition on zxldet.trx_id here because that would
3112 -- entail bringing the source_header_id for the shipment being currently
3113 -- processed. Join with trx_line_id itself is unique because the document
3114 -- type has been classified with event_class_code and line_location_id
3115 -- will always be unique whether PO shipment or Release shipment
3116 AND zxldet.application_id(+) = PO_CONSTANTS_SV.APPLICATION_ID
3117 AND zxldet.entity_code(+) = PO_CONSTANTS_SV.PO_ENTITY_CODE
3118 AND zxldet.event_class_code(+) = PO_CONSTANTS_SV.PO_EVENT_CLASS_CODE
3119 AND zxldet.trx_level_type(+) = PO_CONSTANTS_SV.PO_TRX_LEVEL_TYPE
3120 AND zxldet.trx_line_id(+) = pll.original_shipment_id
3121 -- Join with vendor tables to get party and party site information
3122 AND pv.vendor_id(+) = ph.vendor_id
3123 AND pvs.vendor_site_id(+) = ph.vendor_site_id
3124 -- Join with items table for item information
3125 AND msib.inventory_item_id(+) = pl.item_id
3126 AND msib.organization_id(+) = pl.org_id;
3127 -- Conditions that determine that po line is 'Active'
3128 --AND nvl(pl.cancel_flag,'N') = 'N'
3129 --AND nvl(pl.closed_code,'OPEN') <> 'FINALLY CLOSED'
3130 --AND nvl(pll.cancel_flag,'N') = 'N'
3131 --AND nvl(pll.closed_code,'OPEN') <> 'FINALLY CLOSED';
3132
3133 END populate_zx_lines_with_po;
3134
3135
3136 -----------------------------------------------------------------------------
3137 --Start of Comments
3138 --Name: populate_zx_lines_with_rel
3139 --Pre-reqs:
3140 -- None
3141 --Modifies:
3142 -- ZX_TRANSACTION_LINES_GT
3143 --Locks:
3144 -- ZX_TRANSACTION_LINES_GT
3145 --Function:
3146 -- Populate ZX_TRANSACTION_LINES_GT with transaction line and shipment data
3147 --Parameters:
3148 --IN:
3149 --p_po_release_id_tbl
3150 -- PL/SQL table with list of po_release_id's to process for tax_calculation
3151 --p_calling_program
3152 -- Identifies the module that calls this procedure eg. 'PDOI'
3153 --Notes:
3154 -- Used by calculate_tax procedure. Not to be used externally
3155 --End of Comments
3156 -----------------------------------------------------------------------------
3157 PROCEDURE populate_zx_lines_with_rel(p_po_release_id_tbl IN PO_TBL_NUMBER,
3158 p_calling_program IN VARCHAR2
3159 ) IS
3160 BEGIN
3161 -- Populate zx_transaction_lines_gt for Releases
3162 FORALL i IN 1..p_po_release_id_tbl.COUNT
3163 INSERT INTO zx_transaction_lines_gt(
3164 application_id
3165 ,entity_code
3166 ,event_class_code
3167 ,trx_id
3168 ,trx_level_type
3169 ,trx_line_id
3170 ,line_level_action
3171 ,line_class
3172 ,trx_line_type
3173 ,trx_line_date
3174 ,trx_business_category
3175 ,line_intended_use
3176 ,user_defined_fisc_class
3177 ,line_amt
3178 ,trx_line_quantity
3179 ,product_id
3180 ,product_org_id
3181 ,product_fisc_classification
3182 ,uom_code
3183 ,product_type
3184 ,product_code
3185 ,product_category
3186 ,fob_point
3187 ,ship_from_party_id
3188 ,bill_from_party_id
3189 ,ship_from_party_site_id
3190 ,bill_from_party_site_id
3191 ,ship_to_location_id
3192 ,ship_from_location_id
3193 ,bill_to_location_id
3194 ,bill_from_location_id /* 6524317 */
3195 ,account_ccid
3196 ,ref_doc_application_id
3197 ,ref_doc_entity_code
3198 ,ref_doc_event_class_code
3199 ,ref_doc_trx_id
3200 ,ref_doc_line_id
3201 ,line_trx_user_key1
3202 ,line_trx_user_key2
3203 ,trx_line_number
3204 ,trx_line_description
3205 ,product_description
3206 ,assessable_value
3207 ,line_amt_includes_tax_flag
3208 ,input_tax_classification_code
3209 ,source_application_id
3210 ,source_entity_code
3211 ,source_event_class_code
3212 ,source_trx_id
3213 ,source_line_id
3214 ,source_trx_level_type
3215 ,unit_price
3216 ,ref_doc_trx_level_type
3217 -- Bug 5025018. Updated tax attribute mappings
3218 ,ref_doc_line_quantity
3219 ,ship_third_pty_acct_id
3220 ,bill_third_pty_acct_id
3221 ,ship_third_pty_acct_site_id
3222 ,bill_third_pty_acct_site_id
3223 ,ship_to_party_id
3224 ,defaulting_attribute1 --Bug#6902111
3225 )
3226 SELECT
3227 PO_CONSTANTS_SV.APPLICATION_ID --application_id
3228 ,PO_CONSTANTS_SV.REL_ENTITY_CODE --entity_code
3229 ,PO_CONSTANTS_SV.REL_EVENT_CLASS_CODE --event_class_code
3230 ,pr.po_release_id --trx_id
3231 ,PO_CONSTANTS_SV.REL_TRX_LEVEL_TYPE --trx_level_type
3232 ,pll.line_location_id --trx_line_id
3233 ,pll.tax_attribute_update_code --line_level_action
3234 ,DECODE(pll.shipment_type,--line_class
3235 'PREPAYMENT', DECODE(pll.payment_type,
3236 'ADVANCE', 'ADVANCE',
3237 'FINANCING'),
3238 DECODE(pll.value_basis,
3239 'QUANTITY', 'INVOICE',
3240 'AMOUNT')
3241 )
3242 ,'ITEM' --trx_line_type
3243 ,COALESCE(pll.need_by_date, pll.promised_date, sysdate) --trx_line_date
3244 ,zxldet.trx_business_category --trx_business_category
3245 ,zxldet.line_intended_use --line_intended_use
3246 ,zxldet.user_defined_fisc_class --user_defined_fisc_class
3247 ,nvl(pll.amount, pll.price_override*pll.quantity) --line_amt
3248 ,pll.quantity --trx_line_quantity
3249 ,pl.item_id --product_id
3250 -- Bug 5335818. Pass in inventory_organization_id
3251 ,(SELECT fsp.inventory_organization_id --product_org_id
3252 FROM financials_system_params_all fsp
3253 WHERE fsp.org_id=pll.org_id)
3254 ,zxldet.product_fisc_classification --product_fisc_classification
3255 ,(SELECT mum.uom_code FROM mtl_units_of_measure mum
3256 WHERE mum.unit_of_measure=pll.unit_meas_lookup_code) --uom_code
3257 ,zxldet.product_type --product_type
3258 ,msib.segment1 --product_code
3259 ,zxldet.product_category --product_category
3260 ,ph.fob_lookup_code --fob_point
3261 ,pov.party_id --ship_from_party_id
3262 ,pov.party_id --bill_from_party_id
3263 ,pvs.party_site_id --ship_from_party_site_id
3264 ,pvs.party_site_id --bill_from_party_site_id
3265 ,pll.ship_to_location_id --ship_to_location_id
3266 ,(SELECT hzps.location_id --ship_from_location_id
3267 FROM hz_party_sites hzps
3268 WHERE hzps.party_site_id = pvs.party_site_id)
3269 ,ph.bill_to_location_id --bill_to_location_id
3270 ,(SELECT pvs.location_id from po_vendor_sites_all pvs /* 6524317 - Passing Location Id as Bill From Location Id */
3271 WHERE pvs.vendor_site_id=ph.vendor_site_id)
3272 -- Get account id from first distribution, if created
3273 -- otherwise from the expense account of the item
3274 ,NVL((SELECT pd.code_combination_id --account_ccid
3275 FROM po_distributions_all pd
3276 WHERE pd.line_location_id = pll.line_location_id
3277 AND rownum = 1),
3278 msib.expense_account
3279 )
3280 -- If scheduled release, pass Planned PO as a reference
3281 ,DECODE(pr.release_type, --ref_doc_application_id
3282 PO_CONSTANTS_SV.SCHEDULED, PO_CONSTANTS_SV.APPLICATION_ID,
3283 null)
3284 ,DECODE(pr.release_type, --ref_doc_entity_code
3285 PO_CONSTANTS_SV.SCHEDULED, PO_CONSTANTS_SV.PO_ENTITY_CODE,
3286 null)
3287 ,DECODE(pr.release_type, --ref_doc_event_class_code
3288 PO_CONSTANTS_SV.SCHEDULED, PO_CONSTANTS_SV.PO_EVENT_CLASS_CODE,
3289 null)
3290 ,DECODE(pr.release_type, --ref_doc_trx_id
3291 PO_CONSTANTS_SV.SCHEDULED, pr.po_header_id,
3292 null)
3293 ,DECODE(pr.release_type, --ref_doc_line_id
3294 PO_CONSTANTS_SV.SCHEDULED, pll.po_line_id,
3295 null)
3296 ,pl.line_num --line_trx_user_key1
3297 ,PO_LOCATIONS_S.get_location_code(pll.ship_to_location_id) --line_trx_user_key2
3298 ,DECODE(pll.payment_type, --trx_line_number
3299 'ADVANCE', null,
3300 'DELIVERY', null,
3301 pll.shipment_num)
3302 ,DECODE(pll.shipment_type, --trx_line_description
3303 'STANDARD', DECODE(pll.payment_type,
3304 null, pl.item_description, --non complex work Standard PO
3305 pll.description --complex work Standard PO
3306 ),
3307 pl.item_description -- for shipment_type='PLANNED'
3308 )
3309 ,DECODE(pll.shipment_type, --product_description
3310 'STANDARD', DECODE(pll.payment_type,
3311 null, pl.item_description, --non complex work Standard PO
3312 pll.description --complex work Standard PO
3313 ),
3314 pl.item_description -- for shipment_type='PLANNED'
3315 )
3316 ,zxldet.assessable_value --assessable_value
3317 ,'N' --line_amt_includes_tax_flag
3318 -- Releases cannot be created through PDOI
3319 ,zxldet.input_tax_classification_code --input_tax_classification_code
3320 -- Bug 7337548
3321 -- Copying requisition information as Source Document Information
3322 -- in case of Autocreate. This information will be used to copy
3323 -- Tax attributes when the attributes are overridden in requisition.
3324 -- Calling program for autocreate is 'POXBWVRP_PO','AUTOCREATED_DOC_WF'
3325 -- and 'PORELGEB'
3326 ,DECODE(p_calling_program, --source_application_id
3327 'POXBWVRP_PO', PO_CONSTANTS_SV.APPLICATION_ID,
3328 'AUTOCREATED_DOC_WF', PO_CONSTANTS_SV.APPLICATION_ID,
3329 'PORELGEB', PO_CONSTANTS_SV.APPLICATION_ID,
3330 null)
3331 ,DECODE(p_calling_program, --source_entity_code
3332 'POXBWVRP_PO', PO_CONSTANTS_SV.REQ_ENTITY_CODE,
3333 'AUTOCREATED_DOC_WF', PO_CONSTANTS_SV.REQ_ENTITY_CODE,
3334 'PORELGEB', PO_CONSTANTS_SV.REQ_ENTITY_CODE,
3335 null)
3336 ,DECODE(p_calling_program, --source_event_class_code
3337 'POXBWVRP_PO', PO_CONSTANTS_SV.REQ_EVENT_CLASS_CODE,
3338 'AUTOCREATED_DOC_WF', PO_CONSTANTS_SV.REQ_EVENT_CLASS_CODE,
3339 'PORELGEB', PO_CONSTANTS_SV.REQ_EVENT_CLASS_CODE,
3340 null)
3341 ,DECODE(p_calling_program, -- source_trx_id
3342 'POXBWVRP_PO', (SELECT requisition_header_id FROM
3343 po_requisition_lines_all
3344 WHERE requisition_line_id IN (SELECT Min(requisition_line_id) --source_trx_id
3345 FROM po_requisition_lines_all prl
3346 WHERE prl.line_location_id = pll.line_location_id)
3347 AND p_calling_program = 'POXBWVRP_PO'),
3348 'AUTOCREATED_DOC_WF', (SELECT requisition_header_id FROM
3349 po_requisition_lines_all
3350 WHERE requisition_line_id IN (SELECT Min(requisition_line_id) --source_trx_id
3351 FROM po_requisition_lines_all prl
3352 WHERE prl.line_location_id = pll.line_location_id)
3353 AND p_calling_program = 'AUTOCREATED_DOC_WF'),
3354 'PORELGEB', (SELECT requisition_header_id FROM
3355 po_requisition_lines_all
3356 WHERE requisition_line_id IN (SELECT Min(requisition_line_id) --source_trx_id
3357 FROM po_requisition_lines_all prl
3358 WHERE prl.line_location_id = pll.line_location_id)
3359 AND p_calling_program = 'PORELGEB'),
3360 null)
3361 ,DECODE(p_calling_program, --source_line_id
3362 'POXBWVRP_PO',(SELECT Min(requisition_line_id) --source_line_id
3363 FROM po_requisition_lines_all prl
3364 WHERE prl.line_location_id = pll.line_location_id
3365 AND p_calling_program = 'POXBWVRP_PO'),
3366 'AUTOCREATED_DOC_WF',(SELECT Min(requisition_line_id) --source_line_id
3367 FROM po_requisition_lines_all prl
3368 WHERE prl.line_location_id = pll.line_location_id
3369 AND p_calling_program = 'AUTOCREATED_DOC_WF'),
3370 'PORELGEB',(SELECT Min(requisition_line_id) --source_line_id
3371 FROM po_requisition_lines_all prl
3372 WHERE prl.line_location_id = pll.line_location_id
3373 AND p_calling_program = 'PORELGEB'),
3374 null)
3375 ,DECODE(p_calling_program, --source_trx_level_type
3376 'POXBWVRP_PO', PO_CONSTANTS_SV.REQ_TRX_LEVEL_TYPE ,
3377 'AUTOCREATED_DOC_WF', PO_CONSTANTS_SV.REQ_TRX_LEVEL_TYPE ,
3378 'PORELGEB', PO_CONSTANTS_SV.REQ_TRX_LEVEL_TYPE ,
3379 null)
3380 ,pll.price_override --unit_price
3381 ,DECODE(pr.release_type, --ref_doc_trx_level_type
3382 PO_CONSTANTS_SV.SCHEDULED, PO_CONSTANTS_SV.PO_TRX_LEVEL_TYPE,
3383 null)
3384 -- Bug 5025018. Updated tax attribute mappings
3385 ,DECODE(pr.release_type, --ref_doc_line_quantity
3386 PO_CONSTANTS_SV.SCHEDULED, pll.quantity,
3387 null)
3388 ,pov.vendor_id --ship_third_pty_acct_id
3389 ,pov.vendor_id --bill_third_pty_acct_id
3390 ,pvs.vendor_site_id --ship_third_pty_acct_site_id
3391 ,pvs.vendor_site_id --bill_third_pty_acct_site_id
3392 ,pll.ship_to_organization_id --ship_to_party_id
3393 ,pll.ship_to_organization_id --Bug#6902111
3394 -- Using OUTER JOIN in FROM clause syntax here because (+) operator
3395 -- is not flexible enough to be used inside an OR condition
3396 FROM po_releases_all pr
3397 ,po_headers_all ph
3398 -- Join with vendor tables to get party and party site information
3399 LEFT OUTER JOIN po_vendors pov ON (ph.vendor_id = pov.vendor_id)
3400 LEFT OUTER JOIN po_vendor_sites_all pvs
3401 ON (ph.vendor_site_id = pvs.vendor_site_id)
3402 ,po_lines_all pl--Blanket/Scheduled header and line
3403 -- Join with items table for item information
3404 LEFT OUTER JOIN mtl_system_items_b msib
3405 ON (pl.item_id = msib.inventory_item_id
3406 AND pl.org_id = msib.organization_id)
3407 ,po_line_locations_all pll
3408 -- Conditions for getting Additional Tax Attributes
3409 -- Do not put a condition on zxldet.trx_id here because that would
3410 -- entail bringing the source_header_id for the shipment being
3411 -- currently processed. Join with trx_line_id itself is unique
3412 -- because the document type has been classified with
3413 -- event_class_code and line_location_id will always be unique
3414 -- whether PO shipment or Release shipment
3415 LEFT OUTER JOIN zx_lines_det_factors zxldet ON
3416 ((PO_CONSTANTS_SV.APPLICATION_ID = zxldet.application_id
3417 AND PO_CONSTANTS_SV.REL_ENTITY_CODE = zxldet.entity_code
3418 AND PO_CONSTANTS_SV.REL_EVENT_CLASS_CODE = zxldet.event_class_code
3419 AND PO_CONSTANTS_SV.REL_TRX_LEVEL_TYPE = zxldet.trx_level_type
3420 AND pll.original_shipment_id = zxldet.trx_line_id
3421 AND pll.original_shipment_id IS NOT NULL)
3422 OR
3423 (PO_CONSTANTS_SV.APPLICATION_ID = zxldet.application_id
3424 AND PO_CONSTANTS_SV.PO_ENTITY_CODE = zxldet.entity_code
3425 AND PO_CONSTANTS_SV.PO_EVENT_CLASS_CODE = zxldet.event_class_code
3426 AND PO_CONSTANTS_SV.PO_TRX_LEVEL_TYPE = zxldet.trx_level_type
3427 AND pll.source_shipment_id = zxldet.trx_line_id
3428 AND pll.shipment_type = PO_CONSTANTS_SV.SCHEDULED
3429 AND pll.tax_attribute_update_code = 'CREATE'
3430 AND pll.original_shipment_id IS NULL)
3431 )
3432 WHERE pr.po_release_id = pll.po_release_id
3433 AND pll.tax_attribute_update_code IS NOT NULL
3434 AND pll.tax_attribute_update_code <> 'DIST_DELETE'
3435 AND pr.po_release_id = p_po_release_id_tbl(i)
3436 AND ph.po_header_id = pr.po_header_id
3437 AND pl.po_line_id = pll.po_line_id;
3438
3439 END populate_zx_lines_with_rel;
3440
3441
3442 -----------------------------------------------------------------------------
3443 --Start of Comments
3444 --Name: populate_zx_lines_with_req
3445 --Pre-reqs:
3446 -- None
3447 --Modifies:
3448 -- ZX_TRANSACTION_LINES_GT
3449 --Locks:
3450 -- ZX_TRANSACTION_LINES_GT
3451 --Function:
3452 -- Populate ZX_TRANSACTION_LINES_GT with transaction line data
3453 --Parameters:
3454 --IN:
3455 --p_requisition_header_id
3456 -- requisition_header_id of the requisition to process for tax_calculation
3457 --p_calling_program
3458 -- Identifies the module that calls this procedure eg. 'PDOI'
3459 --Notes:
3460 -- Used by calculate_tax_requisition procedure. Not to be used externally
3461 --End of Comments
3462 -----------------------------------------------------------------------------
3463 PROCEDURE populate_zx_lines_with_req(p_requisition_header_id IN NUMBER,
3464 p_calling_program IN VARCHAR2
3465 ) IS
3466 l_functional_currency_code PO_REQUISITION_LINES_ALL.currency_code%TYPE;
3467 l_set_of_books_id FINANCIALS_SYSTEM_PARAMS_ALL.set_of_books_id%TYPE;
3468 l_rate_type PO_REQUISITION_LINES_ALL.rate_type%TYPE;
3469 l_rate PO_REQUISITION_LINES_ALL.rate%TYPE;
3470 BEGIN
3471
3472 -- <Bug 4742335 Start> Get the requisition's functional currency info.
3473 -- This piece of code is similar to PO_GA_PVT.get_currency_info except that
3474 -- this works for a requisition
3475 SELECT sob.currency_code, fsp.set_of_books_id, psp.default_rate_type
3476 INTO l_functional_currency_code, l_set_of_books_id, l_rate_type
3477 FROM financials_system_params_all fsp, gl_sets_of_books sob,
3478 po_requisition_headers_all prh, po_system_parameters_all psp
3479 WHERE fsp.set_of_books_id = sob.set_of_books_id
3480 AND fsp.org_id = prh.org_id
3481 AND prh.requisition_header_id = p_requisition_header_id
3482 AND psp.org_id = prh.org_id;
3483
3484 -- Retrieve rate based on above values
3485 l_rate := PO_CORE_S.get_conversion_rate(
3486 x_set_of_books_id => l_set_of_books_id,
3487 x_from_currency => l_functional_currency_code,
3488 x_conversion_date => sysdate,
3489 x_conversion_type => l_rate_type);
3490 -- <Bug 4742335 End>
3491
3492 -- Populate zx_transaction_lines_gt for Requisitions
3493 -- Addition/Removal of any attribute entails similar change in
3494 -- populate_zx_record as well
3495 INSERT INTO zx_transaction_lines_gt(
3496 application_id
3497 ,entity_code
3498 ,event_class_code
3499 ,trx_id
3500 ,trx_level_type
3501 ,trx_line_id
3502 ,line_class
3503 ,line_level_action
3504 ,trx_line_type
3505 ,trx_line_date
3506 ,line_amt_includes_tax_flag
3507 ,line_amt
3508 ,trx_line_quantity
3509 ,unit_price
3510 ,product_id
3511 ,product_org_id
3512 ,uom_code
3513 ,product_code
3514 ,ship_to_party_id
3515 ,ship_from_party_id
3516 ,bill_to_party_id
3517 ,bill_from_party_id
3518 ,ship_from_party_site_id
3519 ,bill_from_party_site_id
3520 ,ship_to_location_id
3521 ,ship_from_location_id
3522 ,bill_to_location_id
3523 ,ship_third_pty_acct_id
3524 ,ship_third_pty_acct_site_id
3525 ,historical_flag
3526 ,trx_line_currency_code
3527 ,trx_line_currency_conv_date
3528 ,trx_line_currency_conv_rate
3529 ,trx_line_currency_conv_type
3530 ,trx_line_mau
3531 ,trx_line_precision
3532 ,historical_tax_code_id
3533 ,trx_business_category
3534 ,product_category
3535 ,product_fisc_classification
3536 ,line_intended_use
3537 ,product_type
3538 ,user_defined_fisc_class
3539 ,assessable_value
3540 ,input_tax_classification_code
3541 ,account_ccid
3542 -- Bug 5025018. Updated tax attribute mappings
3543 ,bill_third_pty_acct_id
3544 ,bill_third_pty_acct_site_id
3545 -- Bug 5079867. Line number and description in ATI page
3546 ,trx_line_number
3547 ,trx_line_description
3548 ,product_description
3549 ,user_upd_det_factors_flag --Bug 5632300
3550 ,defaulting_attribute1 --Bug#6902111
3551 )
3552 SELECT
3553 PO_CONSTANTS_SV.APPLICATION_ID --application_id
3554 ,PO_CONSTANTS_SV.REQ_ENTITY_CODE --entity_code
3555 ,PO_CONSTANTS_SV.REQ_EVENT_CLASS_CODE --event_class_code
3556 ,prl.requisition_header_id --trx_id
3557 ,PO_CONSTANTS_SV.REQ_TRX_LEVEL_TYPE --trx_level_type
3558 ,prl.requisition_line_id --trx_line_id
3559 ,'INVOICE' --line_class
3560 ,nvl(prl.tax_attribute_update_code,'UPDATE') --line_level_action
3561 ,'ITEM' --trx_line_type
3562 ,NVL(prl.need_by_date, sysdate) --trx_line_date
3563 ,'N' --line_amt_includes_tax_flag
3564 ,nvl(prl.amount, prl.unit_price*prl.quantity) --line_amt
3565 ,prl.quantity --trx_line_quantity
3566 ,prl.unit_price --unit_price
3567 ,prl.item_id --product_id
3568 -- Bug 5335818. Pass in inventory_organization_id
3569 ,(SELECT fsp.inventory_organization_id --product_org_id
3570 FROM financials_system_params_all fsp
3571 WHERE fsp.org_id=prl.org_id)
3572 ,(SELECT mum.uom_code FROM mtl_units_of_measure mum
3573 WHERE mum.unit_of_measure=prl.unit_meas_lookup_code) --uom_code
3574 ,msib.segment1 --product_code
3575 ,prl.destination_organization_id --ship_to_party_id
3576 ,pv.party_id --ship_from_party_id
3577 ,prh.org_id --bill_to_party_id
3578 ,pv.party_id --bill_from_party_id
3579 ,pvs.party_site_id --ship_from_party_site_id
3580 ,pvs.party_site_id --bill_from_party_site_id
3581 ,prl.deliver_to_location_id --ship_to_location_id
3582 ,(SELECT hzps.location_id --ship_from_location_id
3583 FROM hz_party_sites hzps
3584 WHERE hzps.party_site_id = pvs.party_site_id)
3585 ,(SELECT location_id FROM hr_all_organization_units --bill_to_location_id
3586 WHERE organization_id=prh.org_id)
3587 ,prl.vendor_id --ship_third_pty_acct_id
3588 ,prl.vendor_site_id --ship_third_pty_acct_site_id
3589 ,null --historical_flag
3590 -- If prl.currency_code is null, insert values corresponding to functional
3591 -- currency for currency_code, rate_date, rate and rate_type
3592 ,NVL(prl.currency_code, l_functional_currency_code) --trx_line_currency_code
3593 ,NVL2(prl.currency_code, prl.rate_date, sysdate) --trx_line_currency_conv_date
3594 ,NVL2(prl.currency_code, prl.rate, l_rate) --trx_line_currency_conv_rate
3595 ,NVL2(prl.currency_code, prl.rate_type, l_rate_type) --trx_line_currency_conv_type
3596 ,fc.minimum_accountable_unit --trx_line_mau
3597 ,NVL(fc.precision, 2) --trx_line_precision
3598 ,null --historical_tax_code_id
3599 -- parent_req_line_id is persistent and is not nulled out as in case of
3600 -- PO, so need to insert ATAs(Additional Tax Attributes) here only if the
3601 -- action is create and parent_req_line_id is not null (so that ATAs
3602 -- are populated only for the req line split case)
3603 ,DECODE(prl.tax_attribute_update_code, --trx_business_category
3604 'CREATE', NVL2(prl.parent_req_line_id,
3605 zxldet.trx_business_category, null),
3606 null
3607 )
3608 ,DECODE(prl.tax_attribute_update_code, --product_category
3609 'CREATE', NVL2(prl.parent_req_line_id,
3610 zxldet.product_category, null),
3611 null
3612 )
3613 ,DECODE(prl.tax_attribute_update_code, --product_fisc_classification
3614 'CREATE', NVL2(prl.parent_req_line_id,
3615 zxldet.product_fisc_classification, null),
3616 null
3617 )
3618 ,DECODE(prl.tax_attribute_update_code, --line_intended_use
3619 'CREATE', NVL2(prl.parent_req_line_id,
3620 zxldet.line_intended_use, null),
3621 null
3622 )
3623 ,DECODE(prl.tax_attribute_update_code, --product_type
3624 'CREATE', NVL2(prl.parent_req_line_id,
3625 zxldet.product_type, null),
3626 null
3627 )
3628 ,DECODE(prl.tax_attribute_update_code, --user_defined_fisc_class
3629 'CREATE', NVL2(prl.parent_req_line_id,
3630 zxldet.user_defined_fisc_class, null),
3631 null
3632 )
3633 ,DECODE(prl.tax_attribute_update_code, --assessable_value
3634 'CREATE', NVL2(prl.parent_req_line_id,
3635 zxldet.assessable_value, null),
3636 null
3637 )
3638 ,DECODE(p_calling_program, --input_tax_classification_code
3639 'REQIMPORT', prl.tax_name,
3640 DECODE(prl.tax_attribute_update_code,
3641 'CREATE', NVL2(prl.parent_req_line_id,
3642 zxldet.input_tax_classification_code, null),
3643 null
3644 )
3645 )
3646 -- Get account id from first distribution, if created
3647 -- otherwise from the expense account of the item
3648 ,NVL((SELECT prd.code_combination_id --account_ccid
3649 FROM po_req_distributions_all prd
3650 WHERE prd.requisition_line_id = prl.requisition_line_id
3651 AND rownum = 1),
3652 msib.expense_account
3653 )
3654 -- Bug 5025018. Updated tax attribute mappings
3655 ,pv.vendor_id --bill_third_pty_acct_id
3656 ,pvs.vendor_site_id --bill_third_pty_acct_site_id
3657 -- Bug 5079867. Line number and description in ATI page
3658 ,prl.line_num --trx_line_number
3659 ,prl.item_description --trx_line_description
3660 ,prl.item_description --product_description
3661 --Bug 5632300. Parameter to confirm that tax classification is overridden
3662 ,(SELECT 'Y' FROM DUAL --user_upd_det_factors_flag
3663 WHERE p_calling_program = 'REQIMPORT'
3664 AND prl.tax_name IS NOT NULL)
3665 ,prl.destination_organization_id --Bug#6902111
3666 FROM po_requisition_headers_all prh, po_requisition_lines_all prl,
3667 zx_lines_det_factors zxldet, po_vendors pv, po_vendor_sites_all pvs,
3668 mtl_system_items_b msib, fnd_currencies fc
3669 WHERE prh.requisition_header_id = p_requisition_header_id
3670 AND prh.requisition_header_id = prl.requisition_header_id
3671 -- Conditions for getting Additional Tax Attributes
3672 -- Do not put a condition on zxldet.trx_id here because that would
3673 -- entail bringing the source_header_id for the shipment being currently
3674 -- processed. Join with trx_line_id itself is unique because the document
3675 -- type has been classified with event_class_code and requisition_line_id
3676 -- will always be unique
3677 AND zxldet.application_id(+) = PO_CONSTANTS_SV.APPLICATION_ID
3678 AND zxldet.entity_code(+) = PO_CONSTANTS_SV.REQ_ENTITY_CODE
3679 AND zxldet.event_class_code(+) = PO_CONSTANTS_SV.REQ_EVENT_CLASS_CODE
3680 AND zxldet.trx_level_type(+) = PO_CONSTANTS_SV.REQ_TRX_LEVEL_TYPE
3681 AND zxldet.trx_line_id(+) = prl.parent_req_line_id
3682 -- Join with vendor tables to get party and party site information
3683 AND pv.vendor_id(+) = prl.vendor_id
3684 AND pvs.vendor_site_id(+) = prl.vendor_site_id
3685 -- Join with items table for item information
3686 AND msib.inventory_item_id(+) = prl.item_id
3687 AND msib.organization_id(+) = prl.org_id
3688 -- Join with fnd_currencies for currency information
3689 AND fc.currency_code(+) = prl.currency_code
3690 -- Conditions that determine that requisition line is 'Active'
3691 AND nvl(prl.modified_by_agent_flag, 'N') = 'N'
3692 AND nvl(prl.cancel_flag, 'N') = 'N'
3693 AND nvl(prl.closed_code, 'OPEN') <> 'FINALLY CLOSED'
3694 AND prl.line_location_id IS NULL
3695 AND prl.at_sourcing_flag IS NULL;
3696
3697 END populate_zx_lines_with_req;
3698
3699
3700 -----------------------------------------------------------------------------
3701 --Start of Comments
3702 --Name: populate_zx_dists_with_po
3703 --Pre-reqs:
3704 -- None
3705 --Modifies:
3706 -- ZX_ITM_DISTRIBUTIONS_GT
3707 --Locks:
3708 -- ZX_ITM_DISTRIBUTIONS_GT
3709 --Function:
3710 -- Populate ZX_ITM_DISTRIBUTIONS_GT with transaction distribution data
3711 --Parameters:
3712 --IN:
3713 --p_po_header_id_tbl
3714 -- PL/SQL table with list of po_header_id's to process for tax_calculation
3715 --p_calling_program
3716 -- Identifies the module that calls this procedure eg. 'PDOI'
3717 --Notes:
3718 -- Used by calculate_tax procedure. Not to be used externally
3719 --End of Comments
3720 -----------------------------------------------------------------------------
3721 PROCEDURE populate_zx_dists_with_po(p_po_header_id_tbl IN PO_TBL_NUMBER,
3722 p_calling_program IN VARCHAR2
3723 ) IS
3724 BEGIN
3725 -- Populate ZX_ITM_DISTRIBUTIONS_GT with all such distributions for which:
3726 -- 1. A sibling distribution was changed OR
3727 -- 2. There was a change at a parent level (header, line, shipment) OR
3728 -- 3. A distribution was deleted, hence its shipment is marked as 'DIST_DELETE'
3729 -- All the above cases are in one sql so that the same distribution is not
3730 -- populated twice, hence the OR conditions
3731
3732 FORALL i in 1..p_po_header_id_tbl.COUNT
3733 INSERT INTO zx_itm_distributions_gt(
3734 application_id
3735 ,entity_code
3736 ,event_class_code
3737 ,trx_id
3738 ,trx_line_id
3739 ,trx_level_type
3740 ,trx_line_dist_id
3741 ,dist_level_action
3742 ,trx_line_dist_date
3743 ,item_dist_number
3744 ,task_id
3745 ,award_id
3746 ,project_id
3747 ,expenditure_type
3748 ,expenditure_organization_id
3749 ,expenditure_item_date
3750 ,trx_line_dist_amt
3751 ,trx_line_dist_qty
3752 ,trx_line_quantity
3753 ,account_ccid
3754 ,currency_exchange_rate
3755 ,overriding_recovery_rate
3756 )
3757 SELECT
3758 PO_CONSTANTS_SV.APPLICATION_ID --application_id
3759 ,PO_CONSTANTS_SV.PO_ENTITY_CODE --entity_code
3760 ,PO_CONSTANTS_SV.PO_EVENT_CLASS_CODE --event_class_code
3761 ,pd1.po_header_id --trx_id
3762 ,pll.line_location_id --trx_line_id
3763 ,PO_CONSTANTS_SV.PO_TRX_LEVEL_TYPE --trx_level_type
3764 ,pd1.po_distribution_id --trx_line_dist_id
3765 ,NVL(pd1.tax_attribute_update_code, 'NO_ACTION') --dist_level_action
3766 ,sysdate --trx_line_dist_date
3767 ,pd1.distribution_num --item_dist_number
3768 ,pd1.task_id --task_id
3769 ,pd1.award_id --award_id
3770 ,pd1.project_id --project_id
3771 ,pd1.expenditure_type --expenditure_type
3772 ,pd1.expenditure_organization_id --expenditure_organization_id
3773 ,pd1.expenditure_item_date --expenditure_item_date
3774 ,DECODE(nvl(pll.matching_basis,pl.matching_basis), --trx_line_dist_amt
3775 'AMOUNT', pd1.amount_ordered,
3776 pd1.quantity_ordered*pll.price_override)
3777 ,pd1.quantity_ordered --trx_line_dist_qty
3778 ,pll.quantity --trx_line_quantity
3779 ,pd1.code_combination_id --account_ccid
3780 ,pd1.rate --currency_exchange_rate
3781 , decode(pd1.tax_recovery_override_flag, 'Y', pd1.recovery_rate, null) --overriding_recovery_rate
3782 FROM po_distributions_all pd1, po_line_locations_all pll, po_lines_all pl
3783 WHERE pd1.po_header_id = p_po_header_id_tbl(i)
3784 AND pd1.line_location_id=pll.line_location_id
3785 AND pll.po_line_id=pl.po_line_id
3786 AND (EXISTS(SELECT 'SIBLING DIST WITH TAUC'
3787 FROM po_distributions_all pd2
3788 WHERE pd2.line_location_id = pd1.line_location_id
3789 --AND pd2.po_distribution_id<>pd1.po_distribution_id
3790 AND pd2.tax_attribute_update_code IS NOT NULL
3791 )
3792 --OR pd1.tax_attribute_update_code IS NOT NULL
3793 OR pll.tax_attribute_update_code IS NOT NULL
3794 )
3795 AND pd1.po_header_id IN
3796 (SELECT trx_id FROM zx_trx_headers_gt
3797 WHERE event_class_code = PO_CONSTANTS_SV.PO_EVENT_CLASS_CODE);
3798
3799 END populate_zx_dists_with_po;
3800
3801
3802 -----------------------------------------------------------------------------
3803 --Start of Comments
3804 --Name: populate_all_dists_po
3805 --Pre-reqs:
3806 -- None
3807 --Modifies:
3808 -- ZX_ITM_DISTRIBUTIONS_GT
3809 --Locks:
3810 -- ZX_ITM_DISTRIBUTIONS_GT
3811 --Function:
3812 -- Populate ZX_ITM_DISTRIBUTIONS_GT with transaction distribution data
3813 --Parameters:
3814 --IN:
3815 --p_po_header_id
3816 -- po_header_id to process
3817 --Notes:
3818 -- Used by determine_recovery_po procedure. Not to be used externally
3819 --End of Comments
3820 -----------------------------------------------------------------------------
3821 PROCEDURE populate_all_dists_po(p_po_header_id IN NUMBER) IS
3822 BEGIN
3823 -- Populate ZX_ITM_DISTRIBUTIONS_GT with all distributions of the given PO
3824
3825 INSERT INTO zx_itm_distributions_gt(
3826 application_id
3827 ,entity_code
3828 ,event_class_code
3829 ,trx_id
3830 ,trx_line_id
3831 ,trx_level_type
3832 ,trx_line_dist_id
3833 ,dist_level_action
3834 ,trx_line_dist_date
3835 ,item_dist_number
3836 ,task_id
3837 ,award_id
3838 ,project_id
3839 ,expenditure_type
3840 ,expenditure_organization_id
3841 ,expenditure_item_date
3842 ,trx_line_dist_amt
3843 ,trx_line_dist_qty
3844 ,trx_line_quantity
3845 ,account_ccid
3846 ,currency_exchange_rate
3847 ,overriding_recovery_rate
3848 )
3849 SELECT
3850 PO_CONSTANTS_SV.APPLICATION_ID --application_id
3851 ,PO_CONSTANTS_SV.PO_ENTITY_CODE --entity_code
3852 ,PO_CONSTANTS_SV.PO_EVENT_CLASS_CODE --event_class_code
3853 ,pd.po_header_id --trx_id
3854 ,pll.line_location_id --trx_line_id
3855 ,PO_CONSTANTS_SV.PO_TRX_LEVEL_TYPE --trx_level_type
3856 ,pd.po_distribution_id --trx_line_dist_id
3857 ,'NO_ACTION' --dist_level_action
3858 ,sysdate --trx_line_dist_date
3859 ,pd.distribution_num --item_dist_number
3860 ,pd.task_id --task_id
3861 ,pd.award_id --award_id
3862 ,pd.project_id --project_id
3863 ,pd.expenditure_type --expenditure_type
3864 ,pd.expenditure_organization_id --expenditure_organization_id
3865 ,pd.expenditure_item_date --expenditure_item_date
3866 -- Bug 5202059. Pass in correct amount
3867 ,DECODE(nvl(pll.matching_basis,pl.matching_basis), --trx_line_dist_amt
3868 'AMOUNT', pd.amount_ordered,
3869 pd.quantity_ordered*pll.price_override)
3870 ,pd.quantity_ordered --trx_line_dist_qty
3871 ,pll.quantity --trx_line_quantity
3872 ,pd.code_combination_id --account_ccid
3873 ,pd.rate --currency_exchange_rate
3874 , decode(pd.tax_recovery_override_flag, 'Y', pd.recovery_rate, null) --overriding_recovery_rate
3875 FROM po_distributions_all pd, po_line_locations_all pll, po_lines_all pl
3876 WHERE pd.po_header_id = p_po_header_id
3877 AND pd.line_location_id=pll.line_location_id
3878 AND pll.po_line_id = pl.po_line_id
3879 -- Conditions that determine that po line is 'Active'
3880 AND nvl(pl.cancel_flag,'N') = 'N'
3881 AND nvl(pl.closed_code,'OPEN') <> 'FINALLY CLOSED'
3882 AND nvl(pll.cancel_flag,'N') = 'N'
3883 AND nvl(pll.closed_code,'OPEN') <> 'FINALLY CLOSED';
3884
3885 END populate_all_dists_po;
3886
3887
3888 -----------------------------------------------------------------------------
3889 --Start of Comments
3890 --Name: populate_zx_dists_with_rel
3891 --Pre-reqs:
3892 -- None
3893 --Modifies:
3894 -- ZX_ITM_DISTRIBUTIONS_GT
3895 --Locks:
3896 -- ZX_ITM_DISTRIBUTIONS_GT
3897 --Function:
3898 -- Populate ZX_ITM_DISTRIBUTIONS_GT with transaction distribution data
3899 --Parameters:
3900 --IN:
3901 --p_po_release_id_tbl
3902 -- PL/SQL table with list of po_release_id's to process for tax_calculation
3903 --p_calling_program
3904 -- Identifies the module that calls this procedure eg. 'PDOI'
3905 --Notes:
3906 -- Used by calculate_tax procedure. Not to be used externally
3907 --End of Comments
3908 -----------------------------------------------------------------------------
3909 PROCEDURE populate_zx_dists_with_rel(p_po_release_id_tbl IN PO_TBL_NUMBER,
3910 p_calling_program IN VARCHAR2
3911 ) IS
3912 BEGIN
3913 -- Populate ZX_ITM_DISTRIBUTIONS_GT with all such distributions for which:
3914 -- 1. A sibling distribution was changed OR
3915 -- 2. There was a change at a parent level (header, line, shipment) OR
3916 -- 3. A distribution was deleted, hence its shipment is marked as 'DIST_DELETE'
3917 -- All the above cases are in one sql so that the same distribution is not
3918 -- populated twice, hence the OR conditions
3919
3920 FORALL i in 1..p_po_release_id_tbl.COUNT
3921 INSERT INTO zx_itm_distributions_gt(
3922 application_id
3923 ,entity_code
3924 ,event_class_code
3925 ,trx_id
3926 ,trx_line_id
3927 ,trx_level_type
3928 ,trx_line_dist_id
3929 ,dist_level_action
3930 ,trx_line_dist_date
3931 ,item_dist_number
3932 ,task_id
3933 ,award_id
3934 ,project_id
3935 ,expenditure_type
3936 ,expenditure_organization_id
3937 ,expenditure_item_date
3938 ,trx_line_dist_amt
3939 ,trx_line_dist_qty
3940 ,trx_line_quantity
3941 ,account_ccid
3942 ,currency_exchange_rate
3943 ,overriding_recovery_rate
3944 )
3945 SELECT
3946 PO_CONSTANTS_SV.APPLICATION_ID --application_id
3947 ,PO_CONSTANTS_SV.REL_ENTITY_CODE --entity_code
3948 ,PO_CONSTANTS_SV.REL_EVENT_CLASS_CODE --event_class_code
3949 ,pd1.po_release_id --trx_id
3950 ,pll.line_location_id --trx_line_id
3951 ,PO_CONSTANTS_SV.REL_TRX_LEVEL_TYPE --trx_level_type
3952 ,pd1.po_distribution_id --trx_line_dist_id
3953 ,nvl(pd1.tax_attribute_update_code, 'NO_ACTION') --dist_level_action
3954 ,sysdate --trx_line_dist_date
3955 ,pd1.distribution_num --item_dist_number
3956 ,pd1.task_id --task_id
3957 ,pd1.award_id --award_id
3958 ,pd1.project_id --project_id
3959 ,pd1.expenditure_type --expenditure_type
3960 ,pd1.expenditure_organization_id --expenditure_organization_id
3961 ,pd1.expenditure_item_date --expenditure_item_date
3962 ,DECODE(pl.matching_basis, --trx_line_dist_amt
3963 'AMOUNT', pd1.amount_ordered,
3964 pd1.quantity_ordered*pll.price_override)
3965 ,pd1.quantity_ordered --trx_line_dist_qty
3966 ,pll.quantity --trx_line_quantity
3967 ,pd1.code_combination_id --account_ccid
3968 ,pd1.rate --currency_exchange_rate
3969 , decode(pd1.tax_recovery_override_flag, 'Y', pd1.recovery_rate, null) --overriding_recovery_rate
3970 FROM po_distributions_all pd1, po_line_locations_all pll, po_lines_all pl
3971 WHERE pd1.po_release_id = p_po_release_id_tbl(i)
3972 AND pd1.line_location_id=pll.line_location_id
3973 AND pll.po_line_id=pl.po_line_id
3974 AND (EXISTS(SELECT 'SIBLING DIST WITH TAUC'
3975 FROM po_distributions_all pd2
3976 WHERE pd2.line_location_id = pd1.line_location_id
3977 --AND pd2.po_distribution_id<>pd1.po_distribution_id
3978 AND pd2.tax_attribute_update_code IS NOT NULL
3979 )
3980 --OR pd1.tax_attribute_update_code IS NOT NULL
3981 OR pll.tax_attribute_update_code IS NOT NULL
3982 )
3983 AND pd1.po_release_id IN
3984 (SELECT trx_id FROM zx_trx_headers_gt
3985 WHERE event_class_code = PO_CONSTANTS_SV.REL_EVENT_CLASS_CODE);
3986
3987 END populate_zx_dists_with_rel;
3988
3989
3990 -----------------------------------------------------------------------------
3991 --Start of Comments
3992 --Name: populate_all_dists_rel
3993 --Pre-reqs:
3994 -- None
3995 --Modifies:
3996 -- ZX_ITM_DISTRIBUTIONS_GT
3997 --Locks:
3998 -- ZX_ITM_DISTRIBUTIONS_GT
3999 --Function:
4000 -- Populate ZX_ITM_DISTRIBUTIONS_GT with transaction distribution data
4001 --Parameters:
4002 --IN:
4003 --p_po_release_id
4004 -- po_release_id to process
4005 --Notes:
4006 -- Used by determine_recovery_rel procedure. Not to be used externally
4007 --End of Comments
4008 -----------------------------------------------------------------------------
4009 PROCEDURE populate_all_dists_rel(p_po_release_id IN NUMBER) IS
4010 BEGIN
4011 -- Populate ZX_ITM_DISTRIBUTIONS_GT with all distributions of the given Release
4012
4013 INSERT INTO zx_itm_distributions_gt(
4014 application_id
4015 ,entity_code
4016 ,event_class_code
4017 ,trx_id
4018 ,trx_line_id
4019 ,trx_level_type
4020 ,trx_line_dist_id
4021 ,dist_level_action
4022 ,trx_line_dist_date
4023 ,item_dist_number
4024 ,task_id
4025 ,award_id
4026 ,project_id
4027 ,expenditure_type
4028 ,expenditure_organization_id
4029 ,expenditure_item_date
4030 ,trx_line_dist_amt
4031 ,trx_line_dist_qty
4032 ,trx_line_quantity
4033 ,account_ccid
4034 ,currency_exchange_rate
4035 ,overriding_recovery_rate
4036 )
4037 SELECT
4038 PO_CONSTANTS_SV.APPLICATION_ID --application_id
4039 ,PO_CONSTANTS_SV.REL_ENTITY_CODE --entity_code
4040 ,PO_CONSTANTS_SV.REL_EVENT_CLASS_CODE --event_class_code
4041 ,pd.po_release_id --trx_id
4042 ,pll.line_location_id --trx_line_id
4043 ,PO_CONSTANTS_SV.REL_TRX_LEVEL_TYPE --trx_level_type
4044 ,pd.po_distribution_id --trx_line_dist_id
4045 ,'NO_ACTION' --dist_level_action
4046 ,sysdate --trx_line_dist_date
4047 ,pd.distribution_num --item_dist_number
4048 ,pd.task_id --task_id
4049 ,pd.award_id --award_id
4050 ,pd.project_id --project_id
4051 ,pd.expenditure_type --expenditure_type
4052 ,pd.expenditure_organization_id --expenditure_organization_id
4053 ,pd.expenditure_item_date --expenditure_item_date
4054 -- Bug 5202059. Pass in correct amount
4055 ,DECODE(pl.matching_basis, --trx_line_dist_amt
4056 'AMOUNT', pd.amount_ordered,
4057 pd.quantity_ordered*pll.price_override)
4058 ,pd.quantity_ordered --trx_line_dist_qty
4059 ,pll.quantity --trx_line_quantity
4060 ,pd.code_combination_id --account_ccid
4061 ,pd.rate --currency_exchange_rate
4062 , decode(pd.tax_recovery_override_flag, 'Y', pd.recovery_rate, null) --overriding_recovery_rate
4063 FROM po_distributions_all pd, po_line_locations_all pll, po_lines_all pl
4064 WHERE pd.po_release_id = p_po_release_id
4065 AND pd.line_location_id = pll.line_location_id
4066 AND pll.po_line_id = pl.po_line_id
4067 -- Conditions that determine that po line is 'Active'
4068 AND nvl(pl.cancel_flag,'N') = 'N'
4069 AND nvl(pl.closed_code,'OPEN') <> 'FINALLY CLOSED'
4070 AND nvl(pll.cancel_flag,'N') = 'N'
4071 AND nvl(pll.closed_code,'OPEN') <> 'FINALLY CLOSED';
4072
4073 END populate_all_dists_rel;
4074
4075
4076
4077 -----------------------------------------------------------------------------
4078 --Start of Comments
4079 --Name: populate_zx_dists_with_req
4080 --Pre-reqs:
4081 -- None
4082 --Modifies:
4083 -- ZX_TRX_DISTS_GT
4084 --Locks:
4085 -- ZX_TRX_DISTS_GT
4086 --Function:
4087 -- Populate ZX_TRX_DISTS_GT with transaction distribution data
4088 --Parameters:
4089 --IN:
4090 --p_requisition_header_id
4091 -- requisition_header_id of the requisition to process for tax_calculation
4092 --p_calling_program
4093 -- Identifies the module that calls this procedure eg. 'PDOI'
4094 --Notes:
4095 -- Used by calculate_tax_requisition procedure. Not to be used externally
4096 --End of Comments
4097 -----------------------------------------------------------------------------
4098 PROCEDURE populate_zx_dists_with_req(p_requisition_header_id IN NUMBER,
4099 p_calling_program IN VARCHAR2
4100 ) IS
4101 BEGIN
4102 -- Populate zx distributions table with requisition distributions data
4103 INSERT INTO zx_itm_distributions_gt(
4104 application_id
4105 ,entity_code
4106 ,event_class_code
4107 ,trx_id
4108 ,trx_line_id
4109 ,trx_level_type
4110 ,trx_line_dist_id
4111 ,dist_level_action
4112 ,trx_line_dist_date
4113 ,item_dist_number
4114 ,dist_intended_use
4115 ,task_id
4116 ,award_id
4117 ,project_id
4118 ,expenditure_type
4119 ,expenditure_organization_id
4120 ,expenditure_item_date
4121 ,trx_line_dist_amt
4122 ,trx_line_dist_qty
4123 ,trx_line_quantity
4124 ,account_ccid
4125 ,historical_flag
4126 ,overriding_recovery_rate)
4127 SELECT
4128 PO_CONSTANTS_SV.APPLICATION_ID --application_id
4129 ,PO_CONSTANTS_SV.REQ_ENTITY_CODE --entity_code
4130 ,PO_CONSTANTS_SV.REQ_EVENT_CLASS_CODE --event_class_code
4131 ,prl.requisition_header_id --trx_id
4132 ,prl.requisition_line_id --trx_line_id
4133 ,PO_CONSTANTS_SV.REQ_TRX_LEVEL_TYPE --trx_level_type
4134 ,prd.distribution_id --trx_line_dist_id
4135 ,'CREATE' --dist_level_action
4136 ,sysdate --trx_line_dist_date
4137 ,prd.distribution_num --item_dist_number
4138 ,null --dist_intended_use
4139 ,prd.task_id --task_id
4140 ,prd.award_id --award_id
4141 ,prd.project_id --project_id
4142 ,prd.expenditure_type --expenditure_type
4143 ,prd.expenditure_organization_id --expenditure_organization_id
4144 ,prd.expenditure_item_date --expenditure_item_date
4145 ,DECODE(prl.matching_basis,'AMOUNT', prd.REQ_LINE_AMOUNT, prd.req_line_quantity*prl.unit_price) --trx_line_dist_amt
4146 ,prd.req_line_quantity --trx_line_dist_qty
4147 ,prl.quantity --trx_line_quantity
4148 ,prd.code_combination_id --account_ccid
4149 ,null --historical_flag
4150 ,decode(prd.tax_recovery_override_flag, 'Y', prd.recovery_rate, null) --overriding_recovery_rate
4151 FROM po_requisition_lines_all prl, po_req_distributions_all prd
4152 WHERE prl.requisition_header_id = p_requisition_header_id
4153 AND prl.requisition_line_id = prd.requisition_line_id
4154 -- Conditions that determine that requisition line is 'Active'
4155 AND prl.SOURCE_TYPE_CODE<>'INVENTORY'
4156 AND nvl(prl.modified_by_agent_flag, 'N') = 'N'
4157 AND nvl(prl.cancel_flag, 'N') = 'N'
4158 AND nvl(prl.closed_code, 'OPEN') <> 'FINALLY CLOSED'
4159 AND prl.line_location_id IS NULL
4160 AND prl.at_sourcing_flag IS NULL;
4161
4162 END populate_zx_dists_with_req;
4163
4164
4165
4166 -----------------------------------------------------------------------------
4167 --Start of Comments
4168 --Name: calculate_tax_yes_no
4169 --Pre-reqs:
4170 -- Should be called before document is to be submitted for approval
4171 --Modifies:
4172 -- None
4173 --Locks:
4174 -- None
4175 --Function:
4176 -- Checks if tax needs to be re-calculated for a document before approval
4177 --Parameters:
4178 --IN:
4179 --p_po_header_id
4180 -- po_header_id of document for which tax re-calculation check has to be done
4181 --p_po_release_id
4182 -- po_header_id of document for which tax re-calculation check has to be done
4183 --p_req_header_id
4184 -- req_header_id of document for which tax re-calculation check has to be done
4185 --OUT:
4186 -- None
4187 --RETURN:
4188 -- Returns true if tax needs to be re-calculated else returns false
4189 --Notes:
4190 -- Checks if tax_attribute_update_code flag has a NOT NULL value
4191 -- at any level in the document, if yes then return true else return false
4192 --End of Comments
4193 -----------------------------------------------------------------------------
4194 FUNCTION calculate_tax_yes_no
4195 (p_po_header_id IN NUMBER,
4196 p_po_release_id IN NUMBER,
4197 p_req_header_id IN NUMBER)
4198 RETURN VARCHAR2
4199 IS
4200
4201 l_Result VARCHAR2(4);
4202 l_module_name CONSTANT VARCHAR2(100) := 'CALCULATE_TAX_YES_NO';
4203 d_module_base CONSTANT VARCHAR2(100) := PO_LOG.get_subprogram_base(
4204 D_PACKAGE_BASE, l_module_name);
4205 d_progress NUMBER;
4206
4207 BEGIN
4208
4209 IF (PO_LOG.d_proc) THEN
4210 PO_LOG.proc_begin(d_module_base);
4211 PO_LOG.proc_begin(d_module_base, 'p_po_header_id', p_po_header_id);
4212 PO_LOG.proc_begin(d_module_base, 'p_po_release_id', p_po_release_id);
4213 PO_LOG.proc_begin(d_module_base, 'p_req_header_id', p_req_header_id);
4214 END IF;
4215
4216 d_progress := 0;
4217 l_result := 'N';
4218
4219 BEGIN
4220
4221 IF p_po_header_id IS NOT NULL THEN
4222
4223 d_progress := 10;
4224
4225 SELECT 'Y' INTO l_result
4226 FROM DUAL
4227 WHERE EXISTS
4228 (SELECT 'Y'
4229 FROM po_headers_all POH,
4230 po_lines_all POL,
4231 po_line_locations_all PLL,
4232 po_distributions_all POD
4233 WHERE POH.po_header_id = p_po_header_id
4234 AND POH.po_header_id = POL.po_header_id
4235 AND POL.po_line_id = PLL.po_line_id
4236 AND PLL.line_location_id = POD.line_location_id
4237 AND NVL(POL.cancel_flag,'N') = 'N'
4238 AND NVL(POL.closed_code,'OPEN') <> 'FINALLY CLOSED'
4239 AND NVL(PLL.cancel_flag,'N') = 'N'
4240 AND NVL(PLL.closed_code,'OPEN') <> 'FINALLY CLOSED'
4241 AND (POH.tax_attribute_update_code IS NOT NULL OR
4242 POL.tax_attribute_update_code IS NOT NULL OR
4243 PLL.tax_attribute_update_code IS NOT NULL OR
4244 POD.tax_attribute_update_code IS NOT NULL
4245 )
4246 );
4247
4248 ELSIF p_po_release_id IS NOT NULL THEN
4249
4250 d_progress := 20;
4251
4252 SELECT 'Y' INTO l_Result
4253 FROM DUAL
4254 WHERE EXISTS
4255 (SELECT 'Y'
4256 FROM po_releases_all POR,
4257 po_line_locations_all PLL,
4258 po_distributions_all POD
4259 WHERE POR.po_release_id = p_po_release_id
4260 AND POR.po_release_id = PLL.po_release_id
4261 AND PLL.line_location_id = POD.line_location_id
4262 AND NVL(PLL.cancel_flag,'N') = 'N'
4263 AND NVL(PLL.closed_code,'OPEN') <> 'FINALLY CLOSED'
4264 AND (POR.tax_attribute_update_code IS NOT NULL OR
4265 PLL.tax_attribute_update_code IS NOT NULL OR
4266 POD.tax_attribute_update_code IS NOT NULL
4267 )
4268 );
4269 ELSIF p_req_header_id IS NOT NULL THEN
4270
4271 d_progress := 30;
4272
4273 SELECT 'Y' INTO l_Result
4274 FROM DUAL
4275 WHERE EXISTS
4276 (SELECT 'Y'
4277 FROM po_requisition_headers_all PRH,
4278 po_requisition_lines_all PRL
4279 WHERE PRH.requisition_header_id = p_req_header_id
4280 AND PRH.requisition_header_id = PRL.requisition_header_id
4281 AND NVL(PRL.cancel_flag, 'N') = 'N'
4282 AND NVL(PRL.closed_code, 'OPEN') <> 'FINALLY CLOSED'
4283 AND (PRH.tax_attribute_update_code IS NOT NULL OR
4284 PRL.tax_attribute_update_code IS NOT NULL
4285 )
4286 );
4287 END IF;
4288
4289 d_progress := 40;
4290
4291 EXCEPTION
4292 WHEN NO_DATA_FOUND THEN
4293 l_result := 'N';
4294 END;
4295
4296 d_progress := 50;
4297
4298 IF (PO_LOG.d_proc) THEN
4299 PO_LOG.proc_end(d_module_base);
4300 PO_LOG.proc_end(d_module_base, 'l_result', l_result);
4301 END IF;
4302
4303 RETURN l_result;
4304
4305 EXCEPTION
4306 WHEN OTHERS THEN
4307 IF (PO_LOG.d_exc) THEN
4308 PO_LOG.exc(d_module_base, d_progress, SQLCODE || SQLERRM);
4309 END IF;
4310 RAISE;
4311 END calculate_tax_yes_no;
4312
4313
4314
4315 -----------------------------------------------------------------------------
4316 --Start of Comments
4317 --Name: populate_zx_record
4318 --Pre-reqs:
4319 -- None
4320 --Modifies:
4321 -- None
4322 --Locks:
4323 -- None
4324 --Function:
4325 -- Populates zx record TRX_LINE_DIST_TBL
4326 --Parameters:
4327 --IN:
4328 --p_req_header_id
4329 -- req_header_id of requisition
4330 --OUT:
4331 -- None
4332 --End of Comments
4333 -----------------------------------------------------------------------------
4334 PROCEDURE populate_zx_record(p_requisition_header_id IN NUMBER) IS
4335 l_count NUMBER;
4336 BEGIN
4337 l_count :=0;
4338 FOR i IN successful_documents_csr(p_requisition_header_id) LOOP
4339 l_count := l_count + 1;
4340 ZX_GLOBAL_STRUCTURES_PKG.INIT_TRX_LINE_DIST_TBL(l_count);
4341
4342 SELECT
4343 zxhgt.internal_organization_id
4344 ,zxhgt.application_id
4345 ,zxhgt.entity_code
4346 ,zxhgt.event_class_code
4347 ,zxhgt.event_type_code
4348 ,zxhgt.trx_id
4349 ,zxhgt.trx_date
4350 ,zxhgt.ledger_id
4351 ,zxhgt.legal_entity_id
4352 ,zxhgt.rounding_bill_to_party_id
4353 ,zxhgt.quote_flag
4354 ,zxhgt.document_sub_type
4355 ,zxhgt.default_taxation_country
4356
4357 ,zxlgt.trx_level_type
4358 ,zxlgt.trx_line_id
4359 ,zxlgt.line_class
4360 ,zxlgt.line_level_action
4361 ,zxlgt.trx_line_type
4362 ,zxlgt.trx_line_date
4363 ,zxlgt.trx_business_category
4364 ,zxlgt.line_intended_use
4365 ,zxlgt.user_defined_fisc_class
4366 ,zxlgt.line_amt_includes_tax_flag
4367 ,zxlgt.line_amt
4368 ,zxlgt.trx_line_quantity
4369 ,zxlgt.unit_price
4370 ,zxlgt.product_id
4371 ,zxlgt.product_fisc_classification
4372 ,zxlgt.product_org_id
4373 ,zxlgt.uom_code
4374 ,zxlgt.product_type
4375 ,zxlgt.product_code
4376 ,zxlgt.product_category
4377 ,zxlgt.ship_to_party_id
4378 ,zxlgt.ship_from_party_id
4379 ,zxlgt.bill_to_party_id
4380 ,zxlgt.bill_from_party_id
4381 ,zxlgt.ship_from_party_site_id
4382 ,zxlgt.bill_from_party_site_id
4383 ,zxlgt.ship_to_location_id
4384 ,ship_from_location_id
4385 ,zxlgt.bill_to_location_id
4386 ,zxlgt.ship_third_pty_acct_id
4387 ,zxlgt.ship_third_pty_acct_site_id
4388 ,zxlgt.assessable_value
4389 ,zxlgt.historical_flag
4390 ,zxlgt.trx_line_currency_code
4391 ,zxlgt.trx_line_currency_conv_date
4392 ,zxlgt.trx_line_currency_conv_rate
4393 ,zxlgt.trx_line_currency_conv_type
4394 ,zxlgt.trx_line_mau
4395 ,zxlgt.trx_line_precision
4396 ,zxlgt.historical_tax_code_id
4397 ,zxlgt.input_tax_classification_code
4398 ,zxlgt.account_ccid
4399 -- Bug 5025018. Updated tax attribute mappings
4400 ,zxlgt.bill_third_pty_acct_id
4401 ,zxlgt.bill_third_pty_acct_site_id
4402 -- Bug 5079867. Line number and description in ATI page
4403 ,zxlgt.trx_line_number
4404 ,zxlgt.trx_line_description
4405 ,zxlgt.product_description
4406 -- Bug 5082762. Product Type dropped when line is updated
4407 ,zxlgt.user_upd_det_factors_flag
4408 ,zxlgt.DEFAULTING_ATTRIBUTE1 --Bug#6902111
4409
4410 INTO
4411 ZX_GLOBAL_STRUCTURES_PKG.TRX_LINE_DIST_TBL.internal_organization_id(l_count)
4412 ,ZX_GLOBAL_STRUCTURES_PKG.TRX_LINE_DIST_TBL.application_id(l_count)
4413 ,ZX_GLOBAL_STRUCTURES_PKG.TRX_LINE_DIST_TBL.entity_code(l_count)
4414 ,ZX_GLOBAL_STRUCTURES_PKG.TRX_LINE_DIST_TBL.event_class_code(l_count)
4415 ,ZX_GLOBAL_STRUCTURES_PKG.TRX_LINE_DIST_TBL.event_type_code(l_count)
4416 ,ZX_GLOBAL_STRUCTURES_PKG.TRX_LINE_DIST_TBL.trx_id(l_count)
4417 ,ZX_GLOBAL_STRUCTURES_PKG.TRX_LINE_DIST_TBL.trx_date(l_count)
4418 ,ZX_GLOBAL_STRUCTURES_PKG.TRX_LINE_DIST_TBL.ledger_id(l_count)
4419 ,ZX_GLOBAL_STRUCTURES_PKG.TRX_LINE_DIST_TBL.legal_entity_id(l_count)
4420 ,ZX_GLOBAL_STRUCTURES_PKG.TRX_LINE_DIST_TBL.rounding_bill_to_party_id(l_count)
4421 ,ZX_GLOBAL_STRUCTURES_PKG.TRX_LINE_DIST_TBL.quote_flag(l_count)
4422 ,ZX_GLOBAL_STRUCTURES_PKG.TRX_LINE_DIST_TBL.document_sub_type(l_count)
4423 ,ZX_GLOBAL_STRUCTURES_PKG.TRX_LINE_DIST_TBL.default_taxation_country(l_count)
4424
4425 ,ZX_GLOBAL_STRUCTURES_PKG.TRX_LINE_DIST_TBL.trx_level_type(l_count)
4426 ,ZX_GLOBAL_STRUCTURES_PKG.TRX_LINE_DIST_TBL.trx_line_id(l_count)
4427 ,ZX_GLOBAL_STRUCTURES_PKG.TRX_LINE_DIST_TBL.line_class(l_count)
4428 ,ZX_GLOBAL_STRUCTURES_PKG.TRX_LINE_DIST_TBL.line_level_action(l_count)
4429 ,ZX_GLOBAL_STRUCTURES_PKG.TRX_LINE_DIST_TBL.trx_line_type(l_count)
4430 ,ZX_GLOBAL_STRUCTURES_PKG.TRX_LINE_DIST_TBL.trx_line_date(l_count)
4431 ,ZX_GLOBAL_STRUCTURES_PKG.TRX_LINE_DIST_TBL.trx_business_category(l_count)
4432 ,ZX_GLOBAL_STRUCTURES_PKG.TRX_LINE_DIST_TBL.line_intended_use(l_count)
4433 ,ZX_GLOBAL_STRUCTURES_PKG.TRX_LINE_DIST_TBL.user_defined_fisc_class(l_count)
4434 ,ZX_GLOBAL_STRUCTURES_PKG.TRX_LINE_DIST_TBL.line_amt_includes_tax_flag(l_count)
4435 ,ZX_GLOBAL_STRUCTURES_PKG.TRX_LINE_DIST_TBL.line_amt(l_count)
4436 ,ZX_GLOBAL_STRUCTURES_PKG.TRX_LINE_DIST_TBL.trx_line_quantity(l_count)
4437 ,ZX_GLOBAL_STRUCTURES_PKG.TRX_LINE_DIST_TBL.unit_price(l_count)
4438 ,ZX_GLOBAL_STRUCTURES_PKG.TRX_LINE_DIST_TBL.product_id(l_count)
4439 ,ZX_GLOBAL_STRUCTURES_PKG.TRX_LINE_DIST_TBL.product_fisc_classification(l_count)
4440 ,ZX_GLOBAL_STRUCTURES_PKG.TRX_LINE_DIST_TBL.product_org_id(l_count)
4441 ,ZX_GLOBAL_STRUCTURES_PKG.TRX_LINE_DIST_TBL.uom_code(l_count)
4442 ,ZX_GLOBAL_STRUCTURES_PKG.TRX_LINE_DIST_TBL.product_type(l_count)
4443 ,ZX_GLOBAL_STRUCTURES_PKG.TRX_LINE_DIST_TBL.product_code(l_count)
4444 ,ZX_GLOBAL_STRUCTURES_PKG.TRX_LINE_DIST_TBL.product_category(l_count)
4445 ,ZX_GLOBAL_STRUCTURES_PKG.TRX_LINE_DIST_TBL.ship_to_party_id(l_count)
4446 ,ZX_GLOBAL_STRUCTURES_PKG.TRX_LINE_DIST_TBL.ship_from_party_id(l_count)
4447 ,ZX_GLOBAL_STRUCTURES_PKG.TRX_LINE_DIST_TBL.bill_to_party_id(l_count)
4448 ,ZX_GLOBAL_STRUCTURES_PKG.TRX_LINE_DIST_TBL.bill_from_party_id(l_count)
4449 ,ZX_GLOBAL_STRUCTURES_PKG.TRX_LINE_DIST_TBL.ship_from_party_site_id(l_count)
4450 ,ZX_GLOBAL_STRUCTURES_PKG.TRX_LINE_DIST_TBL.bill_from_party_site_id(l_count)
4451 ,ZX_GLOBAL_STRUCTURES_PKG.TRX_LINE_DIST_TBL.ship_to_location_id(l_count)
4452 ,ZX_GLOBAL_STRUCTURES_PKG.TRX_LINE_DIST_TBL.ship_from_location_id(l_count)
4453 ,ZX_GLOBAL_STRUCTURES_PKG.TRX_LINE_DIST_TBL.bill_to_location_id(l_count)
4454 ,ZX_GLOBAL_STRUCTURES_PKG.TRX_LINE_DIST_TBL.ship_third_pty_acct_id(l_count)
4455 ,ZX_GLOBAL_STRUCTURES_PKG.TRX_LINE_DIST_TBL.ship_third_pty_acct_site_id(l_count)
4456 ,ZX_GLOBAL_STRUCTURES_PKG.TRX_LINE_DIST_TBL.assessable_value(l_count)
4457 ,ZX_GLOBAL_STRUCTURES_PKG.TRX_LINE_DIST_TBL.historical_flag(l_count)
4458 ,ZX_GLOBAL_STRUCTURES_PKG.TRX_LINE_DIST_TBL.trx_line_currency_code(l_count)
4459 ,ZX_GLOBAL_STRUCTURES_PKG.TRX_LINE_DIST_TBL.trx_line_currency_conv_date(l_count)
4460 ,ZX_GLOBAL_STRUCTURES_PKG.TRX_LINE_DIST_TBL.trx_line_currency_conv_rate(l_count)
4461 ,ZX_GLOBAL_STRUCTURES_PKG.TRX_LINE_DIST_TBL.trx_line_currency_conv_type(l_count)
4462 ,ZX_GLOBAL_STRUCTURES_PKG.TRX_LINE_DIST_TBL.trx_line_mau(l_count)
4463 ,ZX_GLOBAL_STRUCTURES_PKG.TRX_LINE_DIST_TBL.trx_line_precision(l_count)
4464 ,ZX_GLOBAL_STRUCTURES_PKG.TRX_LINE_DIST_TBL.historical_tax_code_id(l_count)
4465 ,ZX_GLOBAL_STRUCTURES_PKG.TRX_LINE_DIST_TBL.input_tax_classification_code(l_count)
4466 ,ZX_GLOBAL_STRUCTURES_PKG.TRX_LINE_DIST_TBL.account_ccid(l_count)
4467 -- Bug 5025018. Updated tax attribute mappings
4468 ,ZX_GLOBAL_STRUCTURES_PKG.TRX_LINE_DIST_TBL.bill_third_pty_acct_id(l_count)
4469 ,ZX_GLOBAL_STRUCTURES_PKG.TRX_LINE_DIST_TBL.bill_third_pty_acct_site_id(l_count)
4470 -- Bug 5079867. Line number and description in ATI page
4471 ,ZX_GLOBAL_STRUCTURES_PKG.TRX_LINE_DIST_TBL.trx_line_number(l_count)
4472 ,ZX_GLOBAL_STRUCTURES_PKG.TRX_LINE_DIST_TBL.trx_line_description(l_count)
4473 ,ZX_GLOBAL_STRUCTURES_PKG.TRX_LINE_DIST_TBL.product_description(l_count)
4474 -- Bug 5082762. Product Type dropped when line is updated
4475 ,ZX_GLOBAL_STRUCTURES_PKG.TRX_LINE_DIST_TBL.user_upd_det_factors_flag(l_count)
4476 ,ZX_GLOBAL_STRUCTURES_PKG.TRX_LINE_DIST_TBL.DEFAULTING_ATTRIBUTE1(l_count) --Bug#6902111
4477 FROM zx_trx_headers_gt zxhgt, zx_transaction_lines_gt zxlgt
4478 WHERE zxlgt.trx_line_id = i.trx_line_id
4479 AND zxlgt.trx_id = zxhgt.trx_id;
4480
4481 END LOOP;
4482
4483 END populate_zx_record;
4484
4485
4486
4487 -----------------------------------------------------------------------------
4488 --Start of Comments
4489 --Name: shipments_deleted_from_oa
4490 --Pre-reqs:
4491 -- Should be called before document is to be submitted for approval
4492 --Modifies:
4493 -- None
4494 --Locks:
4495 -- None
4496 --Function:
4497 -- Checks if tax needs to be re-calculated for a document before approval
4498 --Parameters:
4499 --IN:
4500 --p_po_header_id
4501 -- po_header_id of document for which shipments or distributions are deleted
4502 --p_del_shipment_table
4503 -- PL/SQL table of Numbers holding non-repeated deleted shipments Ids
4504 -- deleted
4505 --p_del_dist_shipment_table
4506 -- /SQL table of Numbers holding non-repeated deleted shipments Ids for which
4507 -- corresponding distributions are deleted
4508 --OUT:
4509 -- None
4510 --Notes:
4511 -- This routine populates zx tables with the shipments that are deleted or have
4512 -- their distribution deleted
4513 --End of Comments
4514 -----------------------------------------------------------------------------
4515 PROCEDURE SHIPMENT_DIST_DELETED_FROM_OA
4516 (
4517 P_PO_HEADER_ID IN NUMBER,
4518 P_DEL_SHIPMENT_TABLE IN PO_TBL_NUMBER,
4519 P_DEL_DIST_SHIPMENT_TABLE IN PO_TBL_NUMBER
4520 )
4521 IS
4522 l_module_name CONSTANT VARCHAR2(100) := 'shipment_dist_deleted_from_oa';
4523 d_module_base CONSTANT VARCHAR2(100) := PO_LOG.get_subprogram_base(
4524 D_PACKAGE_BASE, l_module_name);
4525 d_progress NUMBER;
4526
4527 BEGIN
4528 IF (PO_LOG.d_proc) THEN
4529 PO_LOG.proc_begin(d_module_base);
4530 PO_LOG.proc_begin(d_module_base, 'p_po_header_id', p_po_header_id);
4531 PO_LOG.proc_begin(d_module_base, 'p_del_shipment_table', P_DEL_SHIPMENT_TABLE.COUNT);
4532 PO_LOG.proc_begin(d_module_base, 'p_del_dist_shipment_table', P_DEL_DIST_SHIPMENT_TABLE.COUNT);
4533 END IF;
4534
4535 d_progress := 0;
4536 --
4537 -- Update line tax_attribute_code to DIST_DELETE
4538 -- for which distributions are deleted
4539 --
4540
4541 FORALL i IN 1..p_del_dist_shipment_table.COUNT
4542 UPDATE po_line_locations_all
4543 SET tax_attribute_update_code = NVL(tax_attribute_update_code,'DIST_DELETE')
4544 WHERE line_location_id = p_del_dist_shipment_table(i);
4545
4546 d_progress := 10;
4547
4548 --
4549 -- Insert shipments ids that are deleted. However do not insert rows if
4550 -- there are no corresponding tax lines to delete
4551 --
4552
4553 FORALL i IN 1..p_del_shipment_table.COUNT
4554 INSERT INTO zx_transaction_lines_gt
4555 (
4556 application_id,
4557 entity_code,
4558 event_class_code,
4559 trx_id,
4560 trx_level_type,
4561 trx_line_id,
4562 line_level_action,
4563 line_amt,
4564 line_amt_includes_tax_flag
4565 )
4566 SELECT
4567 PO_CONSTANTS_SV.APPLICATION_ID, --application_id
4568 PO_CONSTANTS_SV.PO_ENTITY_CODE, --entity_code
4569 PO_CONSTANTS_SV.PO_EVENT_CLASS_CODE, --event_class_code
4570 p_po_header_id, --trx_id
4571 PO_CONSTANTS_SV.PO_TRX_LEVEL_TYPE, --trx_level_type
4572 p_del_shipment_table(i), --trx_line_id
4573 'DELETE', --line_level_action
4574 -1,
4575 'N'
4576 --<Bug 5135037> Added the EXISTS clause so that only one row is inserted
4577 --into gt table even if there are multiple tax lines for each shipment
4578 FROM dual
4579 WHERE EXISTS
4580 (SELECT 'TAX LINES EXIST'
4581 FROM zx_lines zl
4582 -- Restrict to only rows that have corresponding tax lines
4583 -- Since this is called from OA, so conditions are only for SPO
4584 WHERE zl.trx_id = p_po_header_id
4585 AND zl.trx_line_id = p_del_shipment_table(i)
4586 AND zl.application_id = PO_CONSTANTS_SV.APPLICATION_ID
4587 AND zl.entity_code = PO_CONSTANTS_SV.PO_ENTITY_CODE
4588 AND zl.event_class_code = PO_CONSTANTS_SV.PO_EVENT_CLASS_CODE
4589 AND zl.trx_level_type = PO_CONSTANTS_SV.PO_TRX_LEVEL_TYPE
4590 );
4591
4592 d_progress := 20;
4593 IF (PO_LOG.d_proc) THEN
4594 PO_LOG.proc_end(d_module_base);
4595 END IF;
4596
4597 EXCEPTION
4598 WHEN OTHERS THEN
4599 IF (PO_LOG.d_exc) THEN
4600 PO_LOG.exc(d_module_base, d_progress, SQLCODE || SQLERRM);
4601 END IF;
4602 RAISE;
4603 END SHIPMENT_DIST_DELETED_FROM_OA;
4604
4605
4606
4607 -----------------------------------------------------------------------------
4608 --Start of Comments
4609 --Name: append_error
4610 --Pre-reqs:
4611 -- None
4612 --Modifies:
4613 -- None
4614 --Locks:
4615 -- None
4616 --Function:
4617 -- Append an error to the global error record G_TAX_ERRORS_TBL
4618 --Parameters:
4619 --IN:
4620 --p_error_level
4621 -- The depth in current flow at which error occured
4622 --p_document_type_code
4623 -- Type of document for which error occured
4624 --p_document_id
4625 -- Id of document for which error occured
4626 --p_document_num
4627 -- Number of document for which error occured
4628 --p_line_id
4629 -- Id of line in the document for which error occured
4630 --p_line_num
4631 -- Number of line in the document for which error occured
4632 --p_line_location_id
4633 -- Id of shipment in the document for which error occured
4634 --p_shipment_num
4635 -- Number of shipment in the document for which error occured
4636 --p_distribution_id
4637 -- Id of distribution in the document for which error occured
4638 --p_distribution_num
4639 -- Number of distribution in the document for which error occured
4640 --p_message_text
4641 -- Error message to add
4642 --End of Comments
4643 -----------------------------------------------------------------------------
4644 PROCEDURE append_error(p_error_level IN VARCHAR2,
4645 p_document_type_code IN VARCHAR2,
4646 p_document_id IN NUMBER,
4647 p_document_num IN NUMBER,
4648 p_line_id IN NUMBER,
4649 p_line_num IN NUMBER,
4650 p_line_location_id IN NUMBER,
4651 p_shipment_num IN NUMBER,
4652 p_distribution_id IN NUMBER,
4653 p_distribution_num IN NUMBER,
4654 p_message_text IN VARCHAR2
4655 ) IS
4656 l_module_name CONSTANT VARCHAR2(100) := 'APPEND_ERROR';
4657 d_module_base CONSTANT VARCHAR2(100) := PO_LOG.get_subprogram_base(
4658 D_PACKAGE_BASE, l_module_name);
4659 d_progress NUMBER;
4660 l_length NUMBER;
4661 BEGIN
4662 IF (PO_LOG.d_proc) THEN
4663 PO_LOG.proc_begin(d_module_base);
4664 PO_LOG.proc_begin(d_module_base, 'p_error_level', p_error_level);
4665 PO_LOG.proc_begin(d_module_base, 'p_document_type_code', p_document_type_code);
4666 PO_LOG.proc_begin(d_module_base, 'p_document_id', p_document_id);
4667 PO_LOG.proc_begin(d_module_base, 'p_document_num', p_document_num);
4668 PO_LOG.proc_begin(d_module_base, 'p_line_id', p_line_id);
4669 PO_LOG.proc_begin(d_module_base, 'p_line_num', p_line_num);
4670 PO_LOG.proc_begin(d_module_base, 'p_line_location_id', p_line_location_id);
4671 PO_LOG.proc_begin(d_module_base, 'p_shipment_num', p_shipment_num);
4672 PO_LOG.proc_begin(d_module_base, 'p_distribution_id', p_distribution_id);
4673 PO_LOG.proc_begin(d_module_base, 'p_distribution_num', p_distribution_num);
4674 PO_LOG.proc_begin(d_module_base, 'p_message_text', p_message_text);
4675 END IF;
4676
4677 d_progress := 0;
4678 G_TAX_ERRORS_TBL.error_level.extend;
4679 G_TAX_ERRORS_TBL.document_type_code.extend;
4680 G_TAX_ERRORS_TBL.document_id.extend;
4681 G_TAX_ERRORS_TBL.document_num.extend;
4682 G_TAX_ERRORS_TBL.line_id.extend;
4683 G_TAX_ERRORS_TBL.line_num.extend;
4684 G_TAX_ERRORS_TBL.line_location_id.extend;
4685 G_TAX_ERRORS_TBL.shipment_num.extend;
4686 G_TAX_ERRORS_TBL.distribution_id.extend;
4687 G_TAX_ERRORS_TBL.distribution_num.extend;
4688 G_TAX_ERRORS_TBL.message_text.extend;
4689
4690 d_progress := 10;
4691 l_length := G_TAX_ERRORS_TBL.error_level.COUNT;
4692
4693 d_progress := 20;
4694 IF PO_LOG.d_stmt THEN
4695 PO_LOG.stmt(d_module_base,d_progress,'l_length= '||l_length);
4696 END IF;
4697
4698 d_progress := 30;
4699 G_TAX_ERRORS_TBL.error_level(l_length) := p_error_level;
4700 G_TAX_ERRORS_TBL.document_type_code(l_length) := p_document_type_code;
4701 G_TAX_ERRORS_TBL.document_id(l_length) := p_document_id;
4702 G_TAX_ERRORS_TBL.document_num(l_length) := p_document_num;
4703 G_TAX_ERRORS_TBL.line_id(l_length) := p_line_id;
4704 G_TAX_ERRORS_TBL.line_num(l_length) := p_line_num;
4705 G_TAX_ERRORS_TBL.line_location_id(l_length) := p_line_location_id;
4706 G_TAX_ERRORS_TBL.shipment_num(l_length) := p_shipment_num;
4707 G_TAX_ERRORS_TBL.distribution_id(l_length) := p_distribution_id;
4708 G_TAX_ERRORS_TBL.distribution_num(l_length) := p_distribution_num;
4709 G_TAX_ERRORS_TBL.message_text(l_length) := p_message_text;
4710
4711 d_progress := 40;
4712 IF (PO_LOG.d_proc) THEN
4713 PO_LOG.proc_end(d_module_base);
4714 END IF;
4715 EXCEPTION
4716 WHEN OTHERS THEN
4717 IF (PO_LOG.d_exc) THEN
4718 PO_LOG.exc(d_module_base, d_progress, SQLCODE || SQLERRM);
4719 END IF;
4720 END append_error;
4721
4722
4723
4724 -----------------------------------------------------------------------------
4725 --Start of Comments
4726 --Name: initialize_zx_gt_tables
4727 --Pre-reqs:
4728 -- None
4729 --Modifies:
4730 -- ZX_TRX_HEADERS_GT
4731 -- ZX_TRANSACTION_LINES_GT
4732 -- ZX_ITM_DISTRIBUTIONS_GT
4733 -- ZX_VALIDATION_ERRORS_GT
4734 -- ZX_ERRORS_GT
4735 --Locks:
4736 -- ZX_TRX_HEADERS_GT
4737 -- ZX_TRANSACTION_LINES_GT
4738 -- ZX_ITM_DISTRIBUTIONS_GT
4739 -- ZX_VALIDATION_ERRORS_GT
4740 -- ZX_ERRORS_GT
4741 --Function:
4742 -- Wipe out all data from ZX Global Temporary tables used in PO transaction
4743 -- except if there are lines populated that have action='DELETE'. This
4744 -- exception is for HTML Orders case where deletions come pre-populated in
4745 -- the GT tables
4746 --Parameters:
4747 --IN:
4748 --Notes:
4749 -- For internal use only. Used within this package by calculate_tax,
4750 -- calculate_tax_requisition and determine_recovery.. procedures
4751 --End of Comments
4752 -----------------------------------------------------------------------------
4753 PROCEDURE initialize_zx_gt_tables IS
4754 l_module_name CONSTANT VARCHAR2(100) := 'INITIALIZE_ZX_GT_TABLES';
4755 d_module_base CONSTANT VARCHAR2(100) := PO_LOG.get_subprogram_base(
4756 D_PACKAGE_BASE, l_module_name);
4757 d_progress NUMBER;
4758 l_clear_tables VARCHAR2(1);
4759 BEGIN
4760 d_progress := 0;
4761
4762 IF PO_LOG.d_stmt THEN
4763 PO_LOG.stmt(d_module_base,d_progress,'Initial state of zx gt tables:');
4764 log_header_tax_attributes(d_module_base,d_progress);
4765 log_line_tax_attributes(d_module_base,d_progress);
4766 log_dist_tax_attributes(d_module_base,d_progress);
4767 END IF;
4768
4769 BEGIN
4770 SELECT 'Y'
4771 INTO l_clear_tables
4772 FROM dual
4773 WHERE EXISTS
4774 (SELECT 'CLEAR'
4775 FROM zx_transaction_lines_gt zxlgt
4776 WHERE zxlgt.line_level_action <> 'DELETE');
4777 EXCEPTION
4778 WHEN NO_DATA_FOUND THEN
4779 l_clear_tables := 'N';
4780 END;
4781
4782 d_progress := 10;
4783 IF PO_LOG.d_stmt THEN
4784 PO_LOG.stmt(d_module_base,d_progress,'l_clear_tables = '||l_clear_tables);
4785 END IF;
4786
4787 IF (l_clear_tables = 'Y') THEN
4788 wipe_zx_gt_tables();
4789 END IF;
4790 d_progress := 20;
4791
4792 IF (PO_LOG.d_proc) THEN
4793 PO_LOG.proc_end(d_module_base);
4794 END IF;
4795 EXCEPTION
4796 WHEN OTHERS THEN
4797 IF (PO_LOG.d_exc) THEN
4798 PO_LOG.exc(d_module_base, d_progress, SQLCODE || SQLERRM);
4799 END IF;
4800 END initialize_zx_gt_tables;
4801
4802
4803
4804 -----------------------------------------------------------------------------
4805 --Start of Comments
4806 --Name: wipe_zx_gt_tables
4807 --Pre-reqs:
4808 -- None
4809 --Modifies:
4810 -- ZX_TRX_HEADERS_GT
4811 -- ZX_TRANSACTION_LINES_GT
4812 -- ZX_ITM_DISTRIBUTIONS_GT
4813 -- ZX_VALIDATION_ERRORS_GT
4814 -- ZX_ERRORS_GT
4815 --Locks:
4816 -- ZX_TRX_HEADERS_GT
4817 -- ZX_TRANSACTION_LINES_GT
4818 -- ZX_ITM_DISTRIBUTIONS_GT
4819 -- ZX_VALIDATION_ERRORS_GT
4820 -- ZX_ERRORS_GT
4821 --Function:
4822 -- Wipe out all data from ZX Global Temporary tables
4823 --Parameters:
4824 --IN:
4825 --Notes:
4826 -- For internal use only. Used within this package by calculate_tax,
4827 -- calculate_tax_requisition and initialize_zx_gt_tables
4828 -- Introduced with Bug 5363122
4829 --End of Comments
4830 -----------------------------------------------------------------------------
4831 PROCEDURE wipe_zx_gt_tables IS
4832 l_module_name CONSTANT VARCHAR2(100) := 'WIPE_ZX_GT_TABLES';
4833 d_module_base CONSTANT VARCHAR2(100) := PO_LOG.get_subprogram_base(
4834 D_PACKAGE_BASE, l_module_name);
4835 d_progress NUMBER;
4836 l_clear_tables VARCHAR2(1);
4837 BEGIN
4838 d_progress := 0;
4839 IF (PO_LOG.d_proc) THEN
4840 PO_LOG.proc_begin(d_module_base);
4841 END IF;
4842
4843 DELETE ZX_TRX_HEADERS_GT;
4844 d_progress := 10;
4845 DELETE ZX_TRANSACTION_LINES_GT;
4846 d_progress := 20;
4847 DELETE ZX_ITM_DISTRIBUTIONS_GT;
4848 d_progress := 30;
4849 DELETE ZX_VALIDATION_ERRORS_GT;
4850 d_progress := 40;
4851 DELETE ZX_ERRORS_GT;
4852
4853 d_progress := 50;
4854 IF (PO_LOG.d_proc) THEN
4855 PO_LOG.proc_end(d_module_base);
4856 END IF;
4857 EXCEPTION
4858 WHEN OTHERS THEN
4859 IF (PO_LOG.d_exc) THEN
4860 PO_LOG.exc(d_module_base, d_progress, SQLCODE || SQLERRM);
4861 END IF;
4862 END wipe_zx_gt_tables;
4863
4864
4865
4866 -----------------------------------------------------------------------------
4867 --Start of Comments
4868 --Name: initialize_global_error_record
4869 --Pre-reqs:
4870 -- None
4871 --Modifies:
4872 -- None
4873 --Locks:
4874 -- None
4875 --Function:
4876 -- Initialized global error record and resets its counter to 0
4877 --Parameters:
4878 --IN:
4879 --OUT:
4880 --End of Comments
4881 -----------------------------------------------------------------------------
4882 PROCEDURE initialize_global_error_record IS BEGIN
4883 G_TAX_ERRORS_TBL.error_level := PO_TBL_VARCHAR20();
4884 G_TAX_ERRORS_TBL.document_type_code := PO_TBL_VARCHAR25();
4885 G_TAX_ERRORS_TBL.document_id := PO_TBL_NUMBER();
4886 G_TAX_ERRORS_TBL.document_num := PO_TBL_NUMBER();
4887 G_TAX_ERRORS_TBL.line_id := PO_TBL_NUMBER();
4888 G_TAX_ERRORS_TBL.line_num := PO_TBL_NUMBER();
4889 G_TAX_ERRORS_TBL.line_location_id := PO_TBL_NUMBER();
4890 G_TAX_ERRORS_TBL.shipment_num := PO_TBL_NUMBER();
4891 G_TAX_ERRORS_TBL.distribution_id := PO_TBL_NUMBER();
4892 G_TAX_ERRORS_TBL.distribution_num := PO_TBL_NUMBER();
4893 G_TAX_ERRORS_TBL.message_text := PO_TBL_VARCHAR2000();
4894 END initialize_global_error_record;
4895
4896
4897
4898 -----------------------------------------------------------------------------
4899 --Start of Comments
4900 --Name: any_tax_attributes_updated
4901 --Pre-reqs:
4902 -- None
4903 --Modifies:
4904 -- None
4905 --Locks:
4906 -- None
4907 --Function
4908 -- Determine whether any tax attributes are modified or not.
4909 --Parameters:
4910 --IN:
4911 --p_doc_type
4912 -- document type
4913 --p_doc_level
4914 -- this determines the level of the document HEADER,LINE
4915 --p_doc_level_id
4916 -- unique identifier of the level
4917 --p_trx_currency
4918 -- currency of the transaction
4919 --p_rate_type
4920 -- rate type of the document
4921 --p_rate_date
4922 -- rate date of the document
4923 --p_rate
4924 -- currency rate
4925 --p_fob :
4926 -- FOB of the document
4927 --p_vendor_id
4928 -- Supplier id
4929 --p_vendor_site_id
4930 -- Supplier Site id
4931 --p_uom
4932 -- Unit of measure
4933 --p_price
4934 -- unit price
4935 --p_qty
4936 -- quantity
4937 --p_amt
4938 -- Amount
4939 --p_ship_to_org
4940 -- Ship to Org
4941 --p_ship_to_loc
4942 -- Ship to Location ID
4943 --p_need_by_date
4944 -- Need by date
4945 --p_src_doc
4946 -- Source document
4947 --p_src_ship
4948 -- Source Shipment
4949 --p_ccid
4950 -- Code combination id
4951 --p_tax_rec_rate
4952 -- Tax Recovery Rate
4953 --p_project
4954 -- Project
4955 --p_task
4956 -- Project Task
4957 --p_award
4958 -- Project Award
4959 --p_exp_type
4960 -- Project Expenditure Type
4961 --p_exp_org
4962 -- Project Expenditure Organization
4963 --p_exp_date
4964 -- Project Expenditure date
4965 -- OUT:
4966 --End of Comments
4967 -----------------------------------------------------------------------------
4968 FUNCTION any_tax_attributes_updated(
4969 p_doc_type IN VARCHAR2,
4970 p_doc_level IN VARCHAR2,
4971 p_doc_level_id IN NUMBER,
4972 p_trx_currency IN VARCHAR2 DEFAULT NULL,
4973 p_rate_type IN VARCHAR2 DEFAULT NULL,
4974 p_rate_date IN DATE DEFAULT NULL,
4975 p_rate IN NUMBER DEFAULT NULL,
4976 p_fob IN VARCHAR2 DEFAULT NULL,
4977 p_vendor_id IN NUMBER DEFAULT NULL,
4978 p_vendor_site_id IN NUMBER DEFAULT NULL,
4979 p_bill_to_loc IN NUMBER DEFAULT NULL, --<ECO 5524555>
4980 p_uom IN VARCHAR2 DEFAULT NULL,
4981 p_price IN NUMBER DEFAULT NULL,
4982 p_qty IN NUMBER DEFAULT NULL,
4983 p_price_override IN NUMBER DEFAULT NULL, --<Bug 5647417>
4984 p_amt IN NUMBER DEFAULT NULL,
4985 p_ship_to_org IN NUMBER DEFAULT NULL,
4986 p_ship_to_loc IN NUMBER DEFAULT NULL,
4987 p_need_by_date IN DATE DEFAULT NULL,
4988 p_src_doc IN NUMBER DEFAULT NULL,
4989 p_src_ship IN NUMBER DEFAULT NULL,
4990 p_ccid IN NUMBER DEFAULT NULL,
4991 p_tax_rec_rate IN NUMBER DEFAULT NULL,
4992 p_project IN NUMBER DEFAULT NULL,
4993 p_task IN NUMBER DEFAULT NULL,
4994 p_award IN NUMBER DEFAULT NULL,
4995 p_exp_type IN VARCHAR2 DEFAULT NULL,
4996 p_exp_org IN NUMBER DEFAULT NULL,
4997 p_exp_date IN DATE DEFAULT NULL,
4998 p_dist_quantity_ordered IN NUMBER DEFAULT NULL,
4999 p_dist_amount_ordered IN NUMBER DEFAULT NULL
5000 ) RETURN BOOLEAN IS
5001 pragma AUTONOMOUS_TRANSACTION;
5002
5003 l_trx_currency PO_HEADERS_ALL.CURRENCY_CODE%type;
5004 l_rate_type PO_HEADERS_ALL.RATE_TYPE %type;
5005 l_rate_date PO_HEADERS_ALL. RATE_DATE%type;
5006 l_rate PO_HEADERS_ALL. RATE%type;
5007 l_fob PO_HEADERS_ALL.FOB_LOOKUP_CODE%type ;
5008 l_vendor_id PO_HEADERS_ALL.VENDOR_ID%type;
5009 l_vendor_site_id PO_HEADERS_ALL.VENDOR_SITE_ID%type ;
5010 l_bill_to_loc PO_HEADERS_ALL.BILL_TO_LOCATION_ID%type; --<ECO 5524555>
5011 l_uom PO_LINES_ALL.UNIT_MEAS_LOOKUP_CODE%type;
5012 l_price PO_LINES_ALL.UNIT_PRICE%type;
5013 l_qty PO_LINE_LOCATIONS_ALL.QUANTITY%type;
5014 l_price_override PO_LINE_LOCATIONS_ALL.PRICE_OVERRIDE%type; --<Bug 5647417>
5015 l_amt PO_LINE_LOCATIONS_ALL.AMOUNT%type;
5016 l_ship_to_org PO_LINE_LOCATIONS_ALL.SHIP_TO_ORGANIZATION_ID%type;
5017 l_ship_to_loc PO_LINE_LOCATIONS_ALL.SHIP_TO_LOCATION_ID%type;
5018 l_need_by_date PO_LINE_LOCATIONS_ALL.NEED_BY_DATE%type ;
5019 l_ccid PO_DISTRIBUTIONS_ALL.CODE_COMBINATION_ID%type;
5020 l_tax_rec_rate PO_DISTRIBUTIONS_ALL.RECOVERY_RATE%type;
5021 l_project PO_DISTRIBUTIONS_ALL.PROJECT_ID%type;
5022 l_task PO_DISTRIBUTIONS_ALL.TASK_ID%type;
5023 l_award PO_DISTRIBUTIONS_ALL.AWARD_ID%type;
5024 l_exp_type PO_DISTRIBUTIONS_ALL.EXPENDITURE_TYPE%type;
5025 l_exp_org PO_DISTRIBUTIONS_ALL.EXPENDITURE_ORGANIZATION_ID%type;
5026 l_exp_date PO_DISTRIBUTIONS_ALL.EXPENDITURE_ITEM_DATE%type;
5027 l_dist_quantity_ordered PO_DISTRIBUTIONS_ALL.QUANTITY_ORDERED%type;
5028 l_dist_amount_ordered PO_DISTRIBUTIONS_ALL.AMOUNT_ORDERED%type;
5029
5030 l_module_name CONSTANT VARCHAR2(100) := 'ANY_TAX_ATTRIBUTES_UPDATED';
5031 d_module_base CONSTANT VARCHAR2(100) := PO_LOG.get_subprogram_base(
5032 D_PACKAGE_BASE, l_module_name);
5033 d_progress NUMBER;
5034 BEGIN
5035
5036 IF (PO_LOG.d_proc) THEN
5037 PO_LOG.proc_begin(d_module_base);
5038 PO_LOG.proc_begin(d_module_base, 'p_doc_type', p_doc_type);
5039 PO_LOG.proc_begin(d_module_base, 'p_doc_level', p_doc_level);
5040 PO_LOG.proc_begin(d_module_base, 'p_doc_level_id',p_doc_level_id );
5041 PO_LOG.proc_begin(d_module_base,'p_trx_currency',p_trx_currency);
5042 PO_LOG.proc_begin(d_module_base,'p_rate_type',p_rate_type);
5043 PO_LOG.proc_begin(d_module_base,'p_rate_date',p_rate_date);
5044 PO_LOG.proc_begin(d_module_base,'p_rate',p_rate);
5045 PO_LOG.proc_begin(d_module_base,'p_fob',p_fob);
5046 PO_LOG.proc_begin(d_module_base,'p_vendor_id',p_vendor_id);
5047 PO_LOG.proc_begin(d_module_base,'p_vendor_site_id',p_vendor_site_id);
5048 PO_LOG.proc_begin(d_module_base,'p_bill_to_loc',p_bill_to_loc);
5049 PO_LOG.proc_begin(d_module_base,'p_uom',p_uom);
5050 PO_LOG.proc_begin(d_module_base,'p_price',p_price);
5051 PO_LOG.proc_begin(d_module_base,'p_qty',p_qty);
5052 PO_LOG.proc_begin(d_module_base,'p_price_override',p_price_override);
5053 PO_LOG.proc_begin(d_module_base,'p_amt',p_amt);
5054 PO_LOG.proc_begin(d_module_base,'p_ship_to_org',p_ship_to_org);
5055 PO_LOG.proc_begin(d_module_base,'p_ship_to_loc',p_ship_to_loc);
5056 PO_LOG.proc_begin(d_module_base,'p_need_by_date',p_need_by_date);
5057 PO_LOG.proc_begin(d_module_base,'p_src_doc',p_src_doc);
5058 PO_LOG.proc_begin(d_module_base,'p_src_ship',p_src_ship);
5059 PO_LOG.proc_begin(d_module_base,'p_ccid',p_ccid);
5060 PO_LOG.proc_begin(d_module_base,'p_tax_rec_rate',p_tax_rec_rate);
5061 PO_LOG.proc_begin(d_module_base,'p_project',p_project);
5062 PO_LOG.proc_begin(d_module_base,'p_task',p_task);
5063 PO_LOG.proc_begin(d_module_base,'p_award',p_award);
5064 PO_LOG.proc_begin(d_module_base,'p_exp_type',p_exp_type);
5065 PO_LOG.proc_begin(d_module_base,'p_exp_org',p_exp_org);
5066 PO_LOG.proc_begin(d_module_base,'p_exp_date',p_exp_date);
5067 END IF;
5068
5069 d_progress := 0;
5070 IF (p_doc_type = 'PO') THEN
5071 CASE p_doc_level
5072 WHEN 'HEADER' THEN
5073 BEGIN
5074 -- PO Header Tax determining attributes
5075 d_progress := 10;
5076 SELECT currency_code,
5077 rate_type,
5078 rate_date,
5079 rate,
5080 fob_lookup_code,
5081 vendor_id,
5082 vendor_site_id,
5083 bill_to_location_id --<ECO 5524555>
5084 INTO l_trx_currency,
5085 l_rate_type,
5086 l_rate_date,
5087 l_rate,
5088 l_fob,
5089 l_vendor_id,
5090 l_vendor_site_id,
5091 l_bill_to_loc --<ECO 5524555>
5092 FROM po_headers_all
5093 WHERE po_header_id = p_doc_level_id;
5094 END;
5095 IF ((nvl(l_trx_currency,'-99') = nvl(p_trx_currency,'-99')) AND
5096 (nvl(l_rate_type,'-99') = nvl(p_rate_type,'-99')) AND
5097 (nvl(l_rate_date,sysdate) = nvl(p_rate_date,sysdate)) AND
5098 (nvl(l_rate,99) = nvl(p_rate,99)) AND
5099 (nvl(l_fob,99) = nvl(p_fob,99)) AND
5100 (nvl(l_vendor_id,99) = nvl(p_vendor_id,99)) AND
5101 (nvl(l_vendor_site_id,99) = nvl(p_vendor_site_id,99)) AND
5102 (nvl(l_bill_to_loc,-99) = nvl(p_bill_to_loc,-99)) ) --<ECO 5524555>
5103 THEN
5104 PO_LOG.stmt(d_module_base,d_progress,'header is unchanged');
5105 return(FALSE);
5106 ELSE
5107 PO_LOG.stmt(d_module_base,d_progress,'header is changed');
5108 return (TRUE);
5109 END IF;
5110 WHEN 'LINE' THEN
5111 -- Line Tax determining attributes
5112 d_progress := 20;
5113 SELECT unit_meas_lookup_code,
5114 unit_price
5115 INTO l_uom,
5116 l_price
5117 FROM po_lines_all
5118 WHERE po_line_id =p_doc_level_id;
5119
5120 IF nvl(l_uom,-99) = nvl(p_uom,-99) AND
5121 nvl(l_price,-99) = nvl(p_price,-99)
5122 THEN
5123 PO_LOG.stmt(d_module_base,d_progress,'line is unchanged');
5124 return(FALSE);
5125 ELSE
5126 PO_LOG.stmt(d_module_base,d_progress,'line is changed');
5127 return (TRUE);
5128 END IF;
5129
5130 WHEN 'SHIPMENT' THEN
5131 -- Shipment Tax determining attributes
5132 d_progress := 30;
5133 SELECT quantity,
5134 price_override, --<Bug 5647417>
5135 amount,
5136 ship_to_organization_id,
5137 ship_to_location_id,
5138 need_by_date
5139 INTO l_qty,
5140 l_price_override, --<Bug 5647417>
5141 l_amt,
5142 l_ship_to_org,
5143 l_ship_to_loc,
5144 l_need_by_date
5145 FROM po_line_locations_all
5146 WHERE line_location_id = p_doc_level_id;
5147
5148 IF nvl(l_qty ,-99) = nvl(p_qty ,-99) AND
5149 --<Bug 5647417> Shipment level price is also tax determining
5150 -- attribute because it results in change of amount
5151 nvl(l_price_override ,-99) = nvl(p_price_override ,-99) AND
5152 nvl(l_amt ,-99) = nvl(p_amt ,-99) AND
5153 nvl(l_ship_to_org ,-99) = nvl(p_ship_to_org,-99) AND
5154 nvl(l_ship_to_loc,-99) = nvl(p_ship_to_loc ,-99) AND
5155 nvl(l_need_by_date ,sysdate) = nvl(p_need_by_date,sysdate)
5156 THEN
5157 PO_LOG.stmt(d_module_base,d_progress,'shipment is unchanged');
5158 return(FALSE);
5159 ELSE
5160 PO_LOG.stmt(d_module_base,d_progress,'shipment is changed');
5161 return (TRUE);
5162 END IF;
5163
5164 WHEN 'DISTRIBUTION' THEN
5165 -- Distribution Level Tax determining attributes
5166 d_progress := 40;
5167 SELECT CODE_COMBINATION_ID,
5168 RECOVERY_RATE,
5169 PROJECT_ID,
5170 TASK_ID,
5171 AWARD_ID,
5172 EXPENDITURE_TYPE,
5173 EXPENDITURE_ORGANIZATION_ID,
5174 EXPENDITURE_ITEM_DATE,
5175 QUANTITY_ORDERED,
5176 AMOUNT_ORDERED
5177 INTO l_ccid,
5178 l_tax_rec_rate,
5179 l_project,
5180 l_task ,
5181 l_award,
5182 l_exp_type,
5183 l_exp_org,
5184 l_exp_date,
5185 l_dist_quantity_ordered,
5186 l_dist_amount_ordered
5187 FROM po_distributions_all
5188 WHERE po_distribution_id =p_doc_level_id;
5189
5190 IF nvl(l_tax_rec_rate,-99) = nvl(p_tax_rec_rate ,-99) AND
5191 nvl(l_project,-99) = nvl(p_project,-99) AND
5192 nvl(l_task,-99) = nvl(p_task,-99) AND
5193 nvl(l_award,-99) = nvl(p_award,-99) AND
5194 nvl(l_exp_type,-99) = nvl(p_exp_type,-99) AND
5195 nvl(l_exp_org,-99) = nvl(p_exp_org,-99) AND
5196 nvl(l_exp_date,sysdate) = nvl(p_exp_date,sysdate) AND
5197 nvl(l_ccid,-99) = nvl(p_ccid,-99) AND
5198 nvl(l_dist_quantity_ordered,-99) = nvl(p_dist_quantity_ordered,-99) AND
5199 nvl(l_dist_amount_ordered ,-99) = nvl(p_dist_amount_ordered,-99)
5200 THEN
5201 PO_LOG.stmt(d_module_base,d_progress,'distribution is unchanged');
5202 return(FALSE);
5203 ELSE
5204 PO_LOG.stmt(d_module_base,d_progress,'distribution is changed');
5205 return (TRUE);
5206 END IF;
5207
5208 END CASE;
5209
5210 ELSIF (p_doc_type = 'RELEASE') THEN
5211 CASE p_doc_level
5212 WHEN 'HEADER' THEN
5213 -- RELEASE Header Tax determining attributes
5214 d_progress := 50;
5215 SELECT currency_code,
5216 rate_type,
5217 rate_date,
5218 rate,
5219 fob_lookup_code,
5220 vendor_id,
5221 vendor_site_id
5222 INTO l_trx_currency,
5223 l_rate_type,
5224 l_rate_date,
5225 l_rate,
5226 l_fob,
5227 l_vendor_id,
5228 l_vendor_site_id
5229 FROM po_headers_all
5230 WHERE po_header_id = p_doc_level_id;
5231
5232 IF ((nvl(l_trx_currency,'-99') = nvl(p_trx_currency,'-99')) AND
5233 (nvl(l_rate_type,'-99') = nvl(p_rate_type,'-99')) AND
5234 (nvl(l_rate_date,sysdate) = nvl(p_rate_date,sysdate)) AND
5235 (nvl(l_rate,99) = nvl(p_rate,99)) AND
5236 (nvl(l_fob,99) = nvl(p_fob,99)) AND
5237 (nvl(l_vendor_id,99) = nvl(p_vendor_id,99)) AND
5238 (nvl(l_vendor_site_id,99) = nvl(p_vendor_site_id,99)) AND
5239 (nvl(l_bill_to_loc,-99) = nvl(p_bill_to_loc,-99)) ) --<ECO 5524555>
5240 THEN
5241 PO_LOG.stmt(d_module_base,d_progress,'release header is unchanged');
5242 return(FALSE);
5243 ELSE
5244 PO_LOG.stmt(d_module_base,d_progress,'release header is changed');
5245 return (TRUE);
5246 END IF;
5247
5248 END CASE;
5249
5250 END IF;
5251 d_progress := 60;
5252 EXCEPTION
5253 WHEN OTHERS THEN
5254 IF (PO_LOG.d_exc) THEN
5255 PO_LOG.exc(d_module_base, d_progress, SQLCODE || SQLERRM);
5256 END IF;
5257 return(TRUE);
5258
5259 END any_tax_attributes_updated;
5260
5261
5262
5263 -----------------------------------------------------------------------------
5264 --Start of Comments
5265 --Name: log_header_tax_attributes
5266 --Pre-reqs:
5267 -- None
5268 --Modifies:
5269 -- None
5270 --Locks:
5271 -- None
5272 --Function:
5273 -- Logs attributes in table zx_trx_headers_all
5274 --Parameters:
5275 --IN:
5276 --p_module_base
5277 -- Unique identifier for module in the package
5278 --p_progress
5279 -- Measure of depth traversed in the procedure
5280 --Notes:
5281 -- Used by calculate_tax, calculate_tax_req and determine_recovery_po/rel/req
5282 -- procedures. For use within this package only.
5283 --End of Comments
5284 -----------------------------------------------------------------------------
5285 PROCEDURE log_header_tax_attributes(p_module_base IN VARCHAR2,
5286 p_progress IN NUMBER) IS
5287 d_module_base CONSTANT VARCHAR2(100) := p_module_base;
5288 d_progress NUMBER := p_progress;
5289 TYPE zx_headers_type IS TABLE OF ZX_TRX_HEADERS_GT%ROWTYPE;
5290 l_zx_headers_tbl zx_headers_type;
5291 BEGIN
5292 PO_LOG.stmt(d_module_base,d_progress,'Contents of zx_trx_headers_gt:');
5293
5294 SELECT *
5295 BULK COLLECT INTO l_zx_headers_tbl
5296 FROM zx_trx_headers_gt;
5297
5298 FOR i IN 1..l_zx_headers_tbl.COUNT LOOP
5299 PO_LOG.stmt(d_module_base,d_progress,' row '||i||':');
5300 PO_LOG.stmt(d_module_base,d_progress,' internal_organization_id = '||l_zx_headers_tbl(i).internal_organization_id);
5301 PO_LOG.stmt(d_module_base,d_progress,' application_id = '||l_zx_headers_tbl(i).application_id);
5302 PO_LOG.stmt(d_module_base,d_progress,' entity_code = '||l_zx_headers_tbl(i).entity_code);
5303 PO_LOG.stmt(d_module_base,d_progress,' event_class_code = '||l_zx_headers_tbl(i).event_class_code);
5304 PO_LOG.stmt(d_module_base,d_progress,' event_type_code = '||l_zx_headers_tbl(i).event_type_code);
5305 PO_LOG.stmt(d_module_base,d_progress,' trx_id = '||l_zx_headers_tbl(i).trx_id);
5306 PO_LOG.stmt(d_module_base,d_progress,' trx_date = '||l_zx_headers_tbl(i).trx_date);
5307 PO_LOG.stmt(d_module_base,d_progress,' trx_doc_revision = '||l_zx_headers_tbl(i).trx_doc_revision);
5308 PO_LOG.stmt(d_module_base,d_progress,' ledger_id = '||l_zx_headers_tbl(i).ledger_id);
5309 PO_LOG.stmt(d_module_base,d_progress,' trx_currency_code = '||l_zx_headers_tbl(i).trx_currency_code);
5310 PO_LOG.stmt(d_module_base,d_progress,' currency_conversion_date = '||l_zx_headers_tbl(i).currency_conversion_date);
5311 PO_LOG.stmt(d_module_base,d_progress,' currency_conversion_rate = '||l_zx_headers_tbl(i).currency_conversion_rate);
5312 PO_LOG.stmt(d_module_base,d_progress,' currency_conversion_type = '||l_zx_headers_tbl(i).currency_conversion_type);
5313 PO_LOG.stmt(d_module_base,d_progress,' minimum_accountable_unit = '||l_zx_headers_tbl(i).minimum_accountable_unit);
5314 PO_LOG.stmt(d_module_base,d_progress,' precision = '||l_zx_headers_tbl(i).precision);
5315 PO_LOG.stmt(d_module_base,d_progress,' legal_entity_id = '||l_zx_headers_tbl(i).legal_entity_id);
5316 PO_LOG.stmt(d_module_base,d_progress,' rounding_ship_from_party_id = '||l_zx_headers_tbl(i).rounding_ship_from_party_id);
5317 PO_LOG.stmt(d_module_base,d_progress,' default_taxation_country = '||l_zx_headers_tbl(i).default_taxation_country);
5318 PO_LOG.stmt(d_module_base,d_progress,' quote_flag = '||l_zx_headers_tbl(i).quote_flag);
5319 PO_LOG.stmt(d_module_base,d_progress,' trx_number = '||l_zx_headers_tbl(i).trx_number);
5320 PO_LOG.stmt(d_module_base,d_progress,' trx_description = '||l_zx_headers_tbl(i).trx_description);
5321 PO_LOG.stmt(d_module_base,d_progress,' trx_communicated_date = '||l_zx_headers_tbl(i).trx_communicated_date);
5322 PO_LOG.stmt(d_module_base,d_progress,' document_sub_type = '||l_zx_headers_tbl(i).document_sub_type);
5323 PO_LOG.stmt(d_module_base,d_progress,' provnl_tax_determination_date = '||l_zx_headers_tbl(i).provnl_tax_determination_date);
5324 PO_LOG.stmt(d_module_base,d_progress,' rounding_bill_to_party_id = '||l_zx_headers_tbl(i).rounding_bill_to_party_id);
5325 PO_LOG.stmt(d_module_base,d_progress,' icx_session_id = '||l_zx_headers_tbl(i).icx_session_id);
5326 END LOOP;
5327 EXCEPTION
5328 WHEN OTHERS THEN
5329 PO_LOG.stmt(d_module_base,d_progress,'Failure while writing log '||SQLCODE||SQLERRM);
5330 END log_header_tax_attributes;
5331
5332
5333
5334 -----------------------------------------------------------------------------
5335 --Start of Comments
5336 --Name: log_line_tax_attributes
5337 --Pre-reqs:
5338 -- None
5339 --Modifies:
5340 -- None
5341 --Locks:
5342 -- None
5343 --Function:
5344 -- Logs attributes in table zx_transaction_lines_all
5345 --Parameters:
5346 --IN:
5347 --p_module_base
5348 -- Unique identifier for module in the package
5349 --p_progress
5350 -- Measure of depth traversed in the procedure
5351 --Notes:
5352 -- Used by calculate_tax, calculate_tax_req and determine_recovery_po/rel/req
5353 -- procedures. For use within this package only.
5354 --End of Comments
5355 -----------------------------------------------------------------------------
5356 PROCEDURE log_line_tax_attributes(p_module_base IN VARCHAR2,
5357 p_progress IN NUMBER) IS
5358 d_module_base CONSTANT VARCHAR2(100) := p_module_base;
5359 d_progress NUMBER := p_progress;
5360 TYPE zx_lines_type IS TABLE OF ZX_TRANSACTION_LINES_GT%ROWTYPE;
5361 l_zx_lines_tbl zx_lines_type;
5362 BEGIN
5363 PO_LOG.stmt(d_module_base,d_progress,'Contents of zx_transaction_lines_gt:');
5364
5365 SELECT *
5366 BULK COLLECT INTO l_zx_lines_tbl
5367 FROM zx_transaction_lines_gt;
5368
5369 FOR i IN 1..l_zx_lines_tbl.COUNT LOOP
5370 PO_LOG.stmt(d_module_base,d_progress,' row '||i||':');
5371 PO_LOG.stmt(d_module_base,d_progress,' application_id = '||l_zx_lines_tbl(i).application_id);
5372 PO_LOG.stmt(d_module_base,d_progress,' entity_code = '||l_zx_lines_tbl(i).entity_code);
5373 PO_LOG.stmt(d_module_base,d_progress,' event_class_code = '||l_zx_lines_tbl(i).event_class_code);
5374 PO_LOG.stmt(d_module_base,d_progress,' trx_id = '||l_zx_lines_tbl(i).trx_id);
5375 PO_LOG.stmt(d_module_base,d_progress,' trx_level_type = '||l_zx_lines_tbl(i).trx_level_type);
5376 PO_LOG.stmt(d_module_base,d_progress,' trx_line_id = '||l_zx_lines_tbl(i).trx_line_id);
5377 PO_LOG.stmt(d_module_base,d_progress,' line_level_action = '||l_zx_lines_tbl(i).line_level_action);
5378 PO_LOG.stmt(d_module_base,d_progress,' line_class = '||l_zx_lines_tbl(i).line_class);
5379 PO_LOG.stmt(d_module_base,d_progress,' trx_line_type = '||l_zx_lines_tbl(i).trx_line_type);
5380 PO_LOG.stmt(d_module_base,d_progress,' trx_line_date = '||l_zx_lines_tbl(i).trx_line_date);
5381 PO_LOG.stmt(d_module_base,d_progress,' trx_business_category = '||l_zx_lines_tbl(i).trx_business_category);
5382 PO_LOG.stmt(d_module_base,d_progress,' line_intended_use = '||l_zx_lines_tbl(i).line_intended_use);
5383 PO_LOG.stmt(d_module_base,d_progress,' user_defined_fisc_class = '||l_zx_lines_tbl(i).user_defined_fisc_class);
5384 PO_LOG.stmt(d_module_base,d_progress,' line_amt = '||l_zx_lines_tbl(i).line_amt);
5385 PO_LOG.stmt(d_module_base,d_progress,' trx_line_quantity = '||l_zx_lines_tbl(i).trx_line_quantity);
5386 PO_LOG.stmt(d_module_base,d_progress,' product_id = '||l_zx_lines_tbl(i).product_id);
5387 PO_LOG.stmt(d_module_base,d_progress,' product_fisc_classification = '||l_zx_lines_tbl(i).product_fisc_classification);
5388 PO_LOG.stmt(d_module_base,d_progress,' uom_code = '||l_zx_lines_tbl(i).uom_code);
5389 PO_LOG.stmt(d_module_base,d_progress,' product_type = '||l_zx_lines_tbl(i).product_type);
5390 PO_LOG.stmt(d_module_base,d_progress,' product_code = '||l_zx_lines_tbl(i).product_code);
5391 PO_LOG.stmt(d_module_base,d_progress,' product_category = '||l_zx_lines_tbl(i).product_category);
5392 PO_LOG.stmt(d_module_base,d_progress,' fob_point = '||l_zx_lines_tbl(i).fob_point);
5393 PO_LOG.stmt(d_module_base,d_progress,' ship_from_party_id = '||l_zx_lines_tbl(i).ship_from_party_id);
5394 PO_LOG.stmt(d_module_base,d_progress,' bill_from_party_id = '||l_zx_lines_tbl(i).bill_from_party_id);
5395 PO_LOG.stmt(d_module_base,d_progress,' ship_from_party_site_id = '||l_zx_lines_tbl(i).ship_from_party_site_id);
5396 PO_LOG.stmt(d_module_base,d_progress,' bill_from_party_site_id = '||l_zx_lines_tbl(i).bill_from_party_site_id);
5397 PO_LOG.stmt(d_module_base,d_progress,' ship_to_location_id = '||l_zx_lines_tbl(i).ship_to_location_id);
5398 PO_LOG.stmt(d_module_base,d_progress,' ship_from_location_id = '||l_zx_lines_tbl(i).ship_from_location_id);
5399 PO_LOG.stmt(d_module_base,d_progress,' bill_to_location_id = '||l_zx_lines_tbl(i).bill_to_location_id);
5400 PO_LOG.stmt(d_module_base,d_progress,' account_ccid = '||l_zx_lines_tbl(i).account_ccid);
5401 PO_LOG.stmt(d_module_base,d_progress,' ref_doc_application_id = '||l_zx_lines_tbl(i).ref_doc_application_id);
5402 PO_LOG.stmt(d_module_base,d_progress,' ref_doc_entity_code = '||l_zx_lines_tbl(i).ref_doc_entity_code);
5403 PO_LOG.stmt(d_module_base,d_progress,' ref_doc_event_class_code = '||l_zx_lines_tbl(i).ref_doc_event_class_code);
5404 PO_LOG.stmt(d_module_base,d_progress,' ref_doc_trx_id = '||l_zx_lines_tbl(i).ref_doc_trx_id);
5405 PO_LOG.stmt(d_module_base,d_progress,' ref_doc_line_id = '||l_zx_lines_tbl(i).ref_doc_line_id);
5406 PO_LOG.stmt(d_module_base,d_progress,' line_trx_user_key1 = '||l_zx_lines_tbl(i).line_trx_user_key1);
5407 PO_LOG.stmt(d_module_base,d_progress,' line_trx_user_key2 = '||l_zx_lines_tbl(i).line_trx_user_key2);
5408 PO_LOG.stmt(d_module_base,d_progress,' trx_line_number = '||l_zx_lines_tbl(i).trx_line_number);
5409 PO_LOG.stmt(d_module_base,d_progress,' trx_line_description = '||l_zx_lines_tbl(i).trx_line_description);
5410 PO_LOG.stmt(d_module_base,d_progress,' product_description = '||l_zx_lines_tbl(i).product_description);
5411 PO_LOG.stmt(d_module_base,d_progress,' assessable_value = '||l_zx_lines_tbl(i).assessable_value);
5412 PO_LOG.stmt(d_module_base,d_progress,' line_amt_includes_tax_flag = '||l_zx_lines_tbl(i).line_amt_includes_tax_flag);
5413 PO_LOG.stmt(d_module_base,d_progress,' input_tax_classification_code = '||l_zx_lines_tbl(i).input_tax_classification_code);
5414 PO_LOG.stmt(d_module_base,d_progress,' source_application_id = '||l_zx_lines_tbl(i).source_application_id);
5415 PO_LOG.stmt(d_module_base,d_progress,' source_entity_code = '||l_zx_lines_tbl(i).source_entity_code);
5416 PO_LOG.stmt(d_module_base,d_progress,' source_event_class_code = '||l_zx_lines_tbl(i).source_event_class_code);
5417 PO_LOG.stmt(d_module_base,d_progress,' source_trx_id = '||l_zx_lines_tbl(i).source_trx_id);
5418 PO_LOG.stmt(d_module_base,d_progress,' source_line_id = '||l_zx_lines_tbl(i).source_line_id);
5419 PO_LOG.stmt(d_module_base,d_progress,' source_trx_level_type = '||l_zx_lines_tbl(i).source_trx_level_type);
5420 PO_LOG.stmt(d_module_base,d_progress,' unit_price = '||l_zx_lines_tbl(i).unit_price);
5421 PO_LOG.stmt(d_module_base,d_progress,' ref_doc_trx_level_type = '||l_zx_lines_tbl(i).ref_doc_trx_level_type);
5422 PO_LOG.stmt(d_module_base,d_progress,' product_org_id = '||l_zx_lines_tbl(i).product_org_id);
5423 PO_LOG.stmt(d_module_base,d_progress,' ship_to_party_id = '||l_zx_lines_tbl(i).ship_to_party_id);
5424 PO_LOG.stmt(d_module_base,d_progress,' bill_to_party_id = '||l_zx_lines_tbl(i).bill_to_party_id);
5425 PO_LOG.stmt(d_module_base,d_progress,' trx_line_currency_code = '||l_zx_lines_tbl(i).trx_line_currency_code);
5426 PO_LOG.stmt(d_module_base,d_progress,' trx_line_currency_conv_date = '||l_zx_lines_tbl(i).trx_line_currency_conv_date);
5427 PO_LOG.stmt(d_module_base,d_progress,' trx_line_currency_conv_rate = '||l_zx_lines_tbl(i).trx_line_currency_conv_rate);
5428 PO_LOG.stmt(d_module_base,d_progress,' trx_line_currency_conv_type = '||l_zx_lines_tbl(i).trx_line_currency_conv_type);
5429 PO_LOG.stmt(d_module_base,d_progress,' trx_line_mau = '||l_zx_lines_tbl(i).trx_line_mau);
5430 PO_LOG.stmt(d_module_base,d_progress,' trx_line_precision = '||l_zx_lines_tbl(i).trx_line_precision);
5431 PO_LOG.stmt(d_module_base,d_progress,' user_upd_det_factors_flag = '||l_zx_lines_tbl(i).user_upd_det_factors_flag);
5432 END LOOP;
5433 EXCEPTION
5434 WHEN OTHERS THEN
5435 PO_LOG.stmt(d_module_base,d_progress,'Failure while writing log '||SQLCODE||SQLERRM);
5436 END log_line_tax_attributes;
5437
5438
5439
5440 -----------------------------------------------------------------------------
5441 --Start of Comments
5442 --Name: log_dist_tax_attributes
5443 --Pre-reqs:
5444 -- None
5445 --Modifies:
5446 -- None
5447 --Locks:
5448 -- None
5449 --Function:
5450 -- Logs attributes in table zx_itm_distributions_all
5451 --Parameters:
5452 --IN:
5453 --p_module_base
5454 -- Unique identifier for module in the package
5455 --p_progress
5456 -- Measure of depth traversed in the procedure
5457 --Notes:
5458 -- Used by calculate_tax, calculate_tax_req and determine_recovery_po/rel/req
5459 -- procedures. For use within this package only.
5460 --End of Comments
5461 -----------------------------------------------------------------------------
5462 PROCEDURE log_dist_tax_attributes(p_module_base IN VARCHAR2,
5463 p_progress IN NUMBER) IS
5464 d_module_base CONSTANT VARCHAR2(100) := p_module_base;
5465 d_progress NUMBER := p_progress;
5466 TYPE zx_dists_type IS TABLE OF ZX_ITM_DISTRIBUTIONS_GT%ROWTYPE;
5467 l_zx_dists_tbl zx_dists_type;
5468 BEGIN
5469 PO_LOG.stmt(d_module_base,d_progress,'Contents of zx_itm_distributions_gt:');
5470
5471 SELECT *
5472 BULK COLLECT INTO l_zx_dists_tbl
5473 FROM zx_itm_distributions_gt;
5474
5475 FOR i IN 1..l_zx_dists_tbl.COUNT LOOP
5476 PO_LOG.stmt(d_module_base,d_progress,' row '||i||':');
5477 PO_LOG.stmt(d_module_base,d_progress,' application_id = '||l_zx_dists_tbl(i).application_id);
5478 PO_LOG.stmt(d_module_base,d_progress,' entity_code = '||l_zx_dists_tbl(i).entity_code);
5479 PO_LOG.stmt(d_module_base,d_progress,' event_class_code = '||l_zx_dists_tbl(i).event_class_code);
5480 PO_LOG.stmt(d_module_base,d_progress,' trx_id = '||l_zx_dists_tbl(i).trx_id);
5481 PO_LOG.stmt(d_module_base,d_progress,' trx_line_id = '||l_zx_dists_tbl(i).trx_line_id);
5482 PO_LOG.stmt(d_module_base,d_progress,' trx_level_type = '||l_zx_dists_tbl(i).trx_level_type);
5483 PO_LOG.stmt(d_module_base,d_progress,' trx_line_dist_id = '||l_zx_dists_tbl(i).trx_line_dist_id);
5484 PO_LOG.stmt(d_module_base,d_progress,' dist_level_action = '||l_zx_dists_tbl(i).dist_level_action);
5485 PO_LOG.stmt(d_module_base,d_progress,' trx_line_dist_date = '||l_zx_dists_tbl(i).trx_line_dist_date);
5486 PO_LOG.stmt(d_module_base,d_progress,' item_dist_number = '||l_zx_dists_tbl(i).item_dist_number);
5487 PO_LOG.stmt(d_module_base,d_progress,' task_id = '||l_zx_dists_tbl(i).task_id);
5488 PO_LOG.stmt(d_module_base,d_progress,' award_id = '||l_zx_dists_tbl(i).award_id);
5489 PO_LOG.stmt(d_module_base,d_progress,' project_id = '||l_zx_dists_tbl(i).project_id);
5490 PO_LOG.stmt(d_module_base,d_progress,' expenditure_type = '||l_zx_dists_tbl(i).expenditure_type);
5491 PO_LOG.stmt(d_module_base,d_progress,' expenditure_organization_id = '||l_zx_dists_tbl(i).expenditure_organization_id);
5492 PO_LOG.stmt(d_module_base,d_progress,' expenditure_item_date = '||l_zx_dists_tbl(i).expenditure_item_date);
5493 PO_LOG.stmt(d_module_base,d_progress,' trx_line_dist_amt = '||l_zx_dists_tbl(i).trx_line_dist_amt);
5494 PO_LOG.stmt(d_module_base,d_progress,' trx_line_dist_qty = '||l_zx_dists_tbl(i).trx_line_dist_qty);
5495 PO_LOG.stmt(d_module_base,d_progress,' trx_line_quantity = '||l_zx_dists_tbl(i).trx_line_quantity);
5496 PO_LOG.stmt(d_module_base,d_progress,' account_ccid = '||l_zx_dists_tbl(i).account_ccid);
5497 PO_LOG.stmt(d_module_base,d_progress,' currency_exchange_rate = '||l_zx_dists_tbl(i).currency_exchange_rate);
5498 PO_LOG.stmt(d_module_base,d_progress,' overriding_recovery_rate = '||l_zx_dists_tbl(i).overriding_recovery_rate);
5499 PO_LOG.stmt(d_module_base,d_progress,' dist_intended_use = '||l_zx_dists_tbl(i).dist_intended_use);
5500 PO_LOG.stmt(d_module_base,d_progress,' historical_flag = '||l_zx_dists_tbl(i).historical_flag);
5501 END LOOP;
5502 EXCEPTION
5503 WHEN OTHERS THEN
5504 PO_LOG.stmt(d_module_base,d_progress,'Failure while writing log '||SQLCODE||SQLERRM);
5505 END log_dist_tax_attributes;
5506
5507
5508
5509 -----------------------------------------------------------------------------
5510 --Start of Comments
5511 --Name: log_po_tauc
5512 --Pre-reqs:
5513 -- None
5514 --Modifies:
5515 -- None
5516 --Locks:
5517 -- None
5518 --Function:
5519 -- Logs tax_attribute_update_code values for the given list of po's
5520 --Parameters:
5521 --IN:
5522 --p_module_base
5523 -- Unique identifier for module in the package
5524 --p_progress
5525 -- Measure of depth traversed in the procedure
5526 --p_po_header_id_tbl
5527 -- List of po header id's to log for
5528 --Notes:
5529 -- 1. Used by calculate_tax procedure. For use within this package only
5530 -- 2. Everything is not collected in bulk because requirement is to log data
5531 -- in a structured format. In any case, this procedure is called only
5532 -- statement logging is on
5533 --End of Comments
5534 -----------------------------------------------------------------------------
5535 PROCEDURE log_po_tauc(p_module_base IN VARCHAR2,
5536 p_progress IN NUMBER,
5537 p_po_header_id_tbl IN PO_TBL_NUMBER) IS
5538 d_module_base CONSTANT VARCHAR2(100) := p_module_base;
5539 d_progress NUMBER := p_progress;
5540 l_line_id_tbl PO_TBL_NUMBER;
5541 l_ship_id_tbl PO_TBL_NUMBER;
5542 l_dist_id_tbl PO_TBL_NUMBER;
5543 l_header_tauc PO_HEADERS_ALL.tax_attribute_update_code%TYPE;
5544 l_line_tauc_tbl PO_TBL_VARCHAR15;
5545 l_ship_tauc_tbl PO_TBL_VARCHAR15;
5546 l_dist_tauc_tbl PO_TBL_VARCHAR15;
5547 BEGIN
5548
5549 FOR i IN 1..p_po_header_id_tbl.COUNT LOOP
5550
5551 SELECT ph.tax_attribute_update_code
5552 INTO l_header_tauc
5553 FROM po_headers_all ph
5554 WHERE ph.po_header_id = p_po_header_id_tbl(i);
5555
5556 PO_LOG.stmt(d_module_base,d_progress,' po_header_id = '||p_po_header_id_tbl(i)||':'||l_header_tauc);
5557
5558 l_line_id_tbl := null; l_line_tauc_tbl := null;
5559 SELECT pl.po_line_id, pl.tax_attribute_update_code
5560 BULK COLLECT INTO l_line_id_tbl, l_line_tauc_tbl
5561 FROM po_lines_all pl
5562 WHERE pl.po_header_id = p_po_header_id_tbl(i);
5563
5564 FOR j IN 1..l_line_id_tbl.COUNT LOOP
5565 PO_LOG.stmt(d_module_base,d_progress,' po_line_id = '||l_line_id_tbl(j)||':'||l_line_tauc_tbl(j));
5566
5567 l_ship_id_tbl := null; l_ship_tauc_tbl := null;
5568 SELECT pll.line_location_id, pll.tax_attribute_update_code
5569 BULK COLLECT INTO l_ship_id_tbl, l_ship_tauc_tbl
5570 FROM po_line_locations_all pll
5571 WHERE pll.po_line_id = l_line_id_tbl(j);
5572
5573 FOR k IN 1..l_ship_id_tbl.COUNT LOOP
5574 PO_LOG.stmt(d_module_base,d_progress,' line_location_id = '||l_ship_id_tbl(k)||':'||l_ship_tauc_tbl(k));
5575
5576 l_dist_id_tbl := null; l_dist_tauc_tbl := null;
5577 SELECT pd.po_distribution_id, pd.tax_attribute_update_code
5578 BULK COLLECT INTO l_dist_id_tbl, l_dist_tauc_tbl
5579 FROM po_distributions_all pd
5580 WHERE pd.line_location_id = l_ship_id_tbl(k);
5581
5582 FOR l IN 1..l_dist_id_tbl.COUNT LOOP
5583 PO_LOG.stmt(d_module_base,d_progress,' po_distribution_id = '||l_dist_id_tbl(l)||':'||l_dist_tauc_tbl(l));
5584 END LOOP;
5585
5586 END LOOP;
5587
5588 END LOOP;
5589
5590 END LOOP;
5591
5592 EXCEPTION
5593 WHEN OTHERS THEN
5594 PO_LOG.stmt(d_module_base,d_progress,'Failure while writing log '||SQLCODE||SQLERRM);
5595 END log_po_tauc;
5596
5597
5598
5599 -----------------------------------------------------------------------------
5600 --Start of Comments
5601 --Name: log_rel_tauc
5602 --Pre-reqs:
5603 -- None
5604 --Modifies:
5605 -- None
5606 --Locks:
5607 -- None
5608 --Function:
5609 -- Logs tax_attribute_update_code values for the given list of releaes
5610 --Parameters:
5611 --IN:
5612 --p_module_base
5613 -- Unique identifier for module in the package
5614 --p_progress
5615 -- Measure of depth traversed in the procedure
5616 --p_po_release_id_tbl
5617 -- List of po header id's to log for
5618 --Notes:
5619 -- 1. Used by calculate_tax procedure. For use within this package only
5620 -- 2. Everything is not collected in bulk because requirement is to log data
5621 -- in a structured format. In any case, this procedure is called only
5622 -- statement logging is on
5623 --End of Comments
5624 -----------------------------------------------------------------------------
5625 PROCEDURE log_rel_tauc(p_module_base IN VARCHAR2,
5626 p_progress IN NUMBER,
5627 p_po_release_id_tbl IN PO_TBL_NUMBER) IS
5628 d_module_base CONSTANT VARCHAR2(100) := p_module_base;
5629 d_progress NUMBER := p_progress;
5630 l_ship_id_tbl PO_TBL_NUMBER;
5631 l_dist_id_tbl PO_TBL_NUMBER;
5632 l_header_tauc PO_RELEASES_ALL.tax_attribute_update_code%TYPE;
5633 l_ship_tauc_tbl PO_TBL_VARCHAR15;
5634 l_dist_tauc_tbl PO_TBL_VARCHAR15;
5635 BEGIN
5636
5637 FOR i IN 1..p_po_release_id_tbl.COUNT LOOP
5638
5639 SELECT pr.tax_attribute_update_code
5640 INTO l_header_tauc
5641 FROM po_releases_all pr
5642 WHERE pr.po_release_id = p_po_release_id_tbl(i);
5643
5644 PO_LOG.stmt(d_module_base,d_progress,' po_release_id = '||p_po_release_id_tbl(i)||':'||l_header_tauc);
5645
5646 l_ship_id_tbl := null; l_ship_tauc_tbl := null;
5647 SELECT pll.line_location_id, pll.tax_attribute_update_code
5648 BULK COLLECT INTO l_ship_id_tbl, l_ship_tauc_tbl
5649 FROM po_line_locations_all pll
5650 WHERE pll.po_release_id = p_po_release_id_tbl(i);
5651
5652 FOR j IN 1..l_ship_id_tbl.COUNT LOOP
5653 PO_LOG.stmt(d_module_base,d_progress,' line_location_id = '||l_ship_id_tbl(j)||':'||l_ship_tauc_tbl(j));
5654
5655 l_dist_id_tbl := null; l_dist_tauc_tbl := null;
5656 SELECT pd.po_distribution_id, pd.tax_attribute_update_code
5657 BULK COLLECT INTO l_dist_id_tbl, l_dist_tauc_tbl
5658 FROM po_distributions_all pd
5659 WHERE pd.line_location_id = l_ship_id_tbl(j);
5660
5661 FOR k IN 1..l_dist_id_tbl.COUNT LOOP
5662 PO_LOG.stmt(d_module_base,d_progress,' po_distribution_id = '||l_dist_id_tbl(k)||':'||l_dist_tauc_tbl(k));
5663 END LOOP;
5664
5665 END LOOP;
5666
5667 END LOOP;
5668
5669 EXCEPTION
5670 WHEN OTHERS THEN
5671 PO_LOG.stmt(d_module_base,d_progress,'Failure while writing log '||SQLCODE||SQLERRM);
5672 END log_rel_tauc;
5673
5674
5675
5676 -----------------------------------------------------------------------------
5677 --Start of Comments
5678 --Name: log_req_tauc
5679 --Pre-reqs:
5680 -- None
5681 --Modifies:
5682 -- None
5683 --Locks:
5684 -- None
5685 --Function:
5686 -- Logs tax_attribute_update_code values for the given requisition
5687 --Parameters:
5688 --IN:
5689 --p_module_base
5690 -- Unique identifier for module in the package
5691 --p_progress
5692 -- Measure of depth traversed in the procedure
5693 --p_requisition_header_id
5694 -- req header id to log for
5695 --Notes:
5696 -- Used by calculate_tax_requisition procedure. For use within this
5697 -- package only
5698 --End of Comments
5699 -----------------------------------------------------------------------------
5700 PROCEDURE log_req_tauc(p_module_base IN VARCHAR2,
5701 p_progress IN NUMBER,
5702 p_requisition_header_id IN NUMBER) IS
5703 d_module_base CONSTANT VARCHAR2(100) := p_module_base;
5704 d_progress NUMBER := p_progress;
5705 l_line_id_tbl PO_TBL_NUMBER;
5706 l_header_tauc PO_REQUISITION_HEADERS_ALL.tax_attribute_update_code%TYPE;
5707 l_line_tauc_tbl PO_TBL_VARCHAR15;
5708 BEGIN
5709
5710 SELECT prh.tax_attribute_update_code
5711 INTO l_header_tauc
5712 FROM po_requisition_headers_all prh
5713 WHERE prh.requisition_header_id = p_requisition_header_id;
5714
5715 PO_LOG.stmt(d_module_base,d_progress,' requisition_header_id = '||p_requisition_header_id||':'||l_header_tauc);
5716
5717 l_line_id_tbl := null; l_line_tauc_tbl := null;
5718 SELECT prl.requisition_line_id, prl.tax_attribute_update_code
5719 BULK COLLECT INTO l_line_id_tbl, l_line_tauc_tbl
5720 FROM po_requisition_lines_all prl
5721 WHERE prl.requisition_header_id = p_requisition_header_id;
5722
5723 FOR i IN 1..l_line_id_tbl.COUNT LOOP
5724 PO_LOG.stmt(d_module_base,d_progress,' requisition_line_id = '||l_line_id_tbl(i)||':'||l_line_tauc_tbl(i));
5725 END LOOP;
5726
5727 EXCEPTION
5728 WHEN OTHERS THEN
5729 PO_LOG.stmt(d_module_base,d_progress,'Failure while writing log '||SQLCODE||SQLERRM);
5730 END log_req_tauc;
5731
5732
5733 -----------------------------------------------------------------------------
5734 --Start of Comments
5735 --Name: log_global_error_record
5736 --Pre-reqs:
5737 -- None
5738 --Modifies:
5739 -- None
5740 --Locks:
5741 -- None
5742 --Function:
5743 -- Logs global tax error record G_TAX_ERRORS_TBL
5744 --Parameters:
5745 --IN:
5746 --p_module_base
5747 -- Unique identifier for module in the package
5748 --p_progress
5749 -- Measure of depth traversed in the procedure
5750 --Notes:
5751 -- Used by calculate_tax and calculate_tax_requisition procedures.
5752 -- For use within this package only
5753 --End of Comments
5754 -----------------------------------------------------------------------------
5755 PROCEDURE log_global_error_record(p_module_base IN VARCHAR2,
5756 p_progress IN NUMBER) IS
5757 d_module_base CONSTANT VARCHAR2(100) := p_module_base;
5758 d_progress NUMBER := p_progress;
5759 BEGIN
5760 PO_LOG.stmt(d_module_base,d_progress,'Global tax error record:');
5761 FOR i in 1..G_TAX_ERRORS_TBL.error_level.COUNT LOOP
5762 PO_LOG.stmt(d_module_base,d_progress,' error level '||G_TAX_ERRORS_TBL.error_level(i));
5763 PO_LOG.stmt(d_module_base,d_progress,' '||G_TAX_ERRORS_TBL.document_type_code(i)||' '||
5764 G_TAX_ERRORS_TBL.document_num(i)||'(id '||
5765 G_TAX_ERRORS_TBL.document_id(i)||'), '||
5766 'Line '||G_TAX_ERRORS_TBL.line_num(i)||'(id '||
5767 G_TAX_ERRORS_TBL.line_id(i)||'), '||
5768 'Shipment '||G_TAX_ERRORS_TBL.shipment_num(i)||'(id '||
5769 G_TAX_ERRORS_TBL.line_location_id(i)||'), '||
5770 'Distribution '||G_TAX_ERRORS_TBL.distribution_num(i)||'(id '||
5771 G_TAX_ERRORS_TBL.distribution_id(i)||')');
5772 PO_LOG.stmt(d_module_base,d_progress,' '||G_TAX_ERRORS_TBL.message_text(i));
5773 END LOOP;
5774 EXCEPTION
5775 WHEN OTHERS THEN
5776 PO_LOG.exc(d_module_base,d_progress,'Failure while logging global error record '||SQLCODE||SQLERRM);
5777 END log_global_error_record;
5778
5779
5780 -----------------------------------------------------------------------------
5781 --Start of Comments
5782 --Name: cancel_tax_lines
5783 --Pre-reqs:
5784 -- ZX GT tables should be populated with required data to cancel tax lines
5785 --Modifies:
5786 -- None
5787 --Locks:
5788 -- None
5789 --Function:
5790 -- Cancels tax lines after corresponding PO shipment has been cancelled
5791 --Parameters:
5792 --IN:
5793 --p_api_version
5794 -- Standard API specification parameter
5795 --p_init_msg_list
5796 -- Standard API specification parameter
5797 --p_commit
5798 -- Standard API specification parameter
5799 --p_validation_level
5800 -- Standard API specification parameter
5801 --OUT:
5802 --x_return_status
5803 -- Standard API specification parameter
5804 --x_msg_count
5805 -- Standard API specification parameter
5806 --x_msg_data
5807 -- Standard API specification parameter
5808 --Notes:
5809 -- Wrapper over ZX_API_PUB.calculate_tax for cancel. Called from pocca.lpc.
5810 -- Introduced with Bug 4695557.
5811 --End of Comments
5812 -----------------------------------------------------------------------------
5813 PROCEDURE cancel_tax_lines(p_document_type IN VARCHAR2,
5814 p_document_id IN NUMBER,
5815 p_line_id IN NUMBER,
5816 p_shipment_id IN NUMBER,
5817 x_return_status OUT NOCOPY VARCHAR2,
5818 x_msg_count OUT NOCOPY NUMBER,
5819 x_msg_data OUT NOCOPY VARCHAR2
5820 ) IS
5821 l_module_name CONSTANT VARCHAR2(100) := 'CANCEL_TAX_LINES';
5822 d_module_base CONSTANT VARCHAR2(100) := PO_LOG.get_subprogram_base(
5823 D_PACKAGE_BASE, l_module_name);
5824 d_progress NUMBER;
5825 l_org_id PO_HEADERS_ALL.org_id%TYPE;
5826 BEGIN
5827
5828 IF (PO_LOG.d_proc) THEN
5829 PO_LOG.proc_begin(d_module_base);
5830 PO_LOG.proc_begin(d_module_base, 'p_document_type', p_document_type);
5831 PO_LOG.proc_begin(d_module_base, 'p_document_id', p_document_id);
5832 PO_LOG.proc_begin(d_module_base, 'p_line_id', p_line_id);
5833 PO_LOG.proc_begin(d_module_base, 'p_shipment_id', p_shipment_id);
5834 END IF;
5835
5836 d_progress := 0;
5837 IF p_document_type = PO_CONSTANTS_SV.PO THEN
5838 d_progress := 10;
5839 IF p_shipment_id <> 0 THEN
5840 d_progress := 20;
5841 INSERT INTO zx_trx_headers_gt
5842 (
5843 internal_organization_id,
5844 application_id,
5845 entity_code,
5846 event_class_code,
5847 event_type_code,
5848 trx_id,
5849 trx_date,
5850 legal_entity_id,
5851 rounding_ship_from_party_id
5852 )
5853 SELECT
5854 ph.org_id,
5855 PO_CONSTANTS_SV.APPLICATION_ID,
5856 PO_CONSTANTS_SV.PO_ENTITY_CODE,
5857 PO_CONSTANTS_SV.PO_EVENT_CLASS_CODE,
5858 PO_CONSTANTS_SV.PO_ADJUSTED,
5859 ph.po_header_id,
5860 sysdate, -- dummy value
5861 PO_CORE_S.get_default_legal_entity_id(ph.org_id),
5862 (SELECT party_id FROM po_vendors --rounding_ship_from_party_id
5863 WHERE vendor_id=ph.vendor_id)
5864 FROM po_headers_all ph
5865 WHERE ph.po_header_id = p_document_id;
5866
5867 d_progress := 30;
5868 INSERT INTO zx_transaction_lines_gt
5869 (
5870 application_id,
5871 entity_code,
5872 event_class_code,
5873 trx_id,
5874 trx_level_type,
5875 trx_line_id,
5876 line_level_action,
5877 line_amt_includes_tax_flag,
5878 line_amt
5879 )
5880 VALUES
5881 (
5882 PO_CONSTANTS_SV.APPLICATION_ID,
5883 PO_CONSTANTS_SV.PO_ENTITY_CODE,
5884 PO_CONSTANTS_SV.PO_EVENT_CLASS_CODE,
5885 p_document_id,
5886 PO_CONSTANTS_SV.PO_TRX_LEVEL_TYPE,
5887 p_shipment_id,
5888 'CANCEL',
5889 'N', -- dummy value
5890 0 -- dummy value
5891 );
5892
5893 d_progress := 40;
5894 log_header_tax_attributes(d_module_base,d_progress);
5895 log_line_tax_attributes(d_module_base,d_progress);
5896
5897 d_progress := 50;
5898 IF (PO_LOG.d_stmt) THEN
5899 PO_LOG.stmt(d_module_base,d_progress,'Before Calling ZX_API_PUB.calculate_tax');
5900 END IF;
5901
5902 ZX_API_PUB.calculate_tax(
5903 p_api_version => 1.0,
5904 p_init_msg_list => FND_API.G_TRUE,
5905 p_commit => FND_API.G_FALSE,
5906 p_validation_level => FND_API.G_VALID_LEVEL_FULL,
5907 x_return_status => x_return_status,
5908 x_msg_count => x_msg_count,
5909 x_msg_data => x_msg_data);
5910
5911 d_progress := 60;
5912 IF (PO_LOG.d_stmt) THEN
5913 PO_LOG.stmt(d_module_base,d_progress,'After Calling ZX_API_PUB.calculate_tax');
5914 PO_LOG.stmt(d_module_base,d_progress,'x_return_status', x_return_status);
5915 PO_LOG.stmt(d_module_base,d_progress,'x_msg_count', x_msg_count);
5916 PO_LOG.stmt(d_module_base,d_progress,'x_msg_data', x_msg_data);
5917 END IF;
5918
5919 ELSIF p_line_id <> 0 THEN
5920 -- Partial document cancel. Populate eTax GT tables and call calculate_tax
5921 d_progress := 70;
5922 INSERT INTO zx_trx_headers_gt
5923 (
5924 internal_organization_id,
5925 application_id,
5926 entity_code,
5927 event_class_code,
5928 event_type_code,
5929 trx_id,
5930 trx_date,
5931 legal_entity_id,
5932 rounding_ship_from_party_id
5933 )
5934 SELECT
5935 ph.org_id,
5936 PO_CONSTANTS_SV.APPLICATION_ID,
5937 PO_CONSTANTS_SV.PO_ENTITY_CODE,
5938 PO_CONSTANTS_SV.PO_EVENT_CLASS_CODE,
5939 PO_CONSTANTS_SV.PO_ADJUSTED,
5940 ph.po_header_id,
5941 sysdate, -- dummy value
5942 PO_CORE_S.get_default_legal_entity_id(ph.org_id),
5943 (SELECT party_id FROM po_vendors --rounding_ship_from_party_id
5944 WHERE vendor_id=ph.vendor_id)
5945 FROM po_headers_all ph
5946 WHERE ph.po_header_id = p_document_id;
5947
5948 d_progress := 80;
5949 INSERT INTO zx_transaction_lines_gt
5950 (
5951 application_id,
5952 entity_code,
5953 event_class_code,
5954 trx_id,
5955 trx_level_type,
5956 trx_line_id,
5957 line_level_action,
5958 line_amt_includes_tax_flag,
5959 line_amt
5960 )
5961 SELECT
5962 PO_CONSTANTS_SV.APPLICATION_ID,
5963 PO_CONSTANTS_SV.PO_ENTITY_CODE,
5964 PO_CONSTANTS_SV.PO_EVENT_CLASS_CODE,
5965 pll.po_header_id,
5966 PO_CONSTANTS_SV.PO_TRX_LEVEL_TYPE,
5967 pll.line_location_id,
5968 'CANCEL', --line_level_action
5969 'N', -- dummy value
5970 0 -- dummy value
5971 FROM po_line_locations_all pll
5972 WHERE pll.po_line_id = p_line_id;
5973
5974 d_progress := 90;
5975 log_header_tax_attributes(d_module_base,d_progress);
5976 log_line_tax_attributes(d_module_base,d_progress);
5977
5978 d_progress := 100;
5979 IF (PO_LOG.d_stmt) THEN
5980 PO_LOG.stmt(d_module_base,d_progress,'Before Calling ZX_API_PUB.calculate_tax');
5981 END IF;
5982
5983 ZX_API_PUB.calculate_tax(
5984 p_api_version => 1.0,
5985 p_init_msg_list => FND_API.G_TRUE,
5986 p_commit => FND_API.G_FALSE,
5987 p_validation_level => FND_API.G_VALID_LEVEL_FULL,
5988 x_return_status => x_return_status,
5989 x_msg_count => x_msg_count,
5990 x_msg_data => x_msg_data);
5991
5992 d_progress := 110;
5993 IF (PO_LOG.d_stmt) THEN
5994 PO_LOG.stmt(d_module_base,d_progress,'After Calling ZX_API_PUB.calculate_tax');
5995 PO_LOG.stmt(d_module_base,d_progress,'x_return_status', x_return_status);
5996 PO_LOG.stmt(d_module_base,d_progress,'x_msg_count', x_msg_count);
5997 PO_LOG.stmt(d_module_base,d_progress,'x_msg_data', x_msg_data);
5998 END IF;
5999 ELSIF p_document_id <> 0 THEN
6000 -- Complete document cancel. Call global_document_update API
6001 -- in Cancel mode
6002 d_progress := 120;
6003 SELECT ph.org_id
6004 INTO l_org_id
6005 FROM po_headers_all ph
6006 WHERE ph.po_header_id = p_document_id;
6007
6008 d_progress := 130;
6009 IF (PO_LOG.d_stmt) THEN
6010 PO_LOG.stmt(d_module_base,d_progress,'l_org_id', l_org_id);
6011 END IF;
6012
6013 d_progress := 140;
6014 PO_TAX_INTERFACE_PVT.global_document_update(
6015 p_api_version => 1.0,
6016 p_init_msg_list => FND_API.G_FALSE,
6017 p_commit => FND_API.G_FALSE,
6018 p_validation_level => FND_API.G_VALID_LEVEL_FULL,
6019 x_return_status => x_return_status,
6020 x_msg_count => x_msg_count,
6021 x_msg_data => x_msg_data,
6022 p_org_id => l_org_id,
6023 p_document_type => PO_CONSTANTS_SV.PO,
6024 p_document_id => p_document_id,
6025 p_event_type_code => PO_CONSTANTS_SV.PO_CANCELLED);
6026
6027 d_progress := 150;
6028 IF (PO_LOG.d_stmt) THEN
6029 PO_LOG.stmt(d_module_base,d_progress,'After Calling PO_TAX_INTERFACE_PVT.global_document_update');
6030 PO_LOG.stmt(d_module_base,d_progress,'x_return_status', x_return_status);
6031 PO_LOG.stmt(d_module_base,d_progress,'x_msg_count', x_msg_count);
6032 PO_LOG.stmt(d_module_base,d_progress,'x_msg_data', x_msg_data);
6033 END IF;
6034 END IF; --IF p_shipment_id IS NOT NULL
6035 ELSIF p_document_type = PO_CONSTANTS_SV.RELEASE THEN
6036 d_progress := 160;
6037 IF p_shipment_id <> 0 THEN
6038 d_progress := 170;
6039 INSERT INTO zx_trx_headers_gt
6040 (
6041 internal_organization_id,
6042 application_id,
6043 entity_code,
6044 event_class_code,
6045 event_type_code,
6046 trx_id,
6047 trx_date,
6048 legal_entity_id,
6049 rounding_ship_from_party_id
6050 )
6051 SELECT
6052 pr.org_id, -- dummy value
6053 PO_CONSTANTS_SV.APPLICATION_ID,
6054 PO_CONSTANTS_SV.REL_ENTITY_CODE,
6055 PO_CONSTANTS_SV.REL_EVENT_CLASS_CODE,
6056 PO_CONSTANTS_SV.REL_ADJUSTED,
6057 pr.po_release_id,
6058 sysdate, -- dummy value
6059 PO_CORE_S.get_default_legal_entity_id(pr.org_id),
6060 (SELECT party_id FROM po_vendors --rounding_ship_from_party_id
6061 WHERE vendor_id=ph.vendor_id)
6062 FROM po_releases_all pr, po_headers_all ph
6063 WHERE pr.po_release_id = p_document_id
6064 AND pr.po_header_id = ph.po_header_id;
6065
6066 d_progress := 180;
6067 INSERT INTO zx_transaction_lines_gt
6068 (
6069 application_id,
6070 entity_code,
6071 event_class_code,
6072 trx_id,
6073 trx_level_type,
6074 trx_line_id,
6075 line_level_action,
6076 line_amt_includes_tax_flag,
6077 line_amt
6078 )
6079 VALUES
6080 (
6081 PO_CONSTANTS_SV.APPLICATION_ID,
6082 PO_CONSTANTS_SV.REL_ENTITY_CODE,
6083 PO_CONSTANTS_SV.REL_EVENT_CLASS_CODE,
6084 p_document_id,
6085 PO_CONSTANTS_SV.REL_TRX_LEVEL_TYPE,
6086 p_shipment_id,
6087 'CANCEL',
6088 'N', -- dummy value
6089 0 -- dummy value
6090 );
6091
6092 d_progress := 190;
6093 log_header_tax_attributes(d_module_base,d_progress);
6094 log_line_tax_attributes(d_module_base,d_progress);
6095
6096 d_progress := 200;
6097 IF (PO_LOG.d_stmt) THEN
6098 PO_LOG.stmt(d_module_base,d_progress,'Before Calling ZX_API_PUB.calculate_tax');
6099 END IF;
6100
6101 ZX_API_PUB.calculate_tax(
6102 p_api_version => 1.0,
6103 p_init_msg_list => FND_API.G_TRUE,
6104 p_commit => FND_API.G_FALSE,
6105 p_validation_level => FND_API.G_VALID_LEVEL_FULL,
6106 x_return_status => x_return_status,
6107 x_msg_count => x_msg_count,
6108 x_msg_data => x_msg_data);
6109
6110 d_progress := 210;
6111 IF (PO_LOG.d_stmt) THEN
6112 PO_LOG.stmt(d_module_base,d_progress,'After Calling ZX_API_PUB.calculate_tax');
6113 PO_LOG.stmt(d_module_base,d_progress,'x_return_status', x_return_status);
6114 PO_LOG.stmt(d_module_base,d_progress,'x_msg_count', x_msg_count);
6115 PO_LOG.stmt(d_module_base,d_progress,'x_msg_data', x_msg_data);
6116 END IF;
6117
6118 ELSIF p_document_id <> 0 THEN
6119 -- Complete document cancel. Call global_document_update API
6120 -- in Cancel mode
6121 d_progress := 220;
6122 SELECT pr.org_id
6123 INTO l_org_id
6124 FROM po_releases_all pr
6125 WHERE pr.po_release_id = p_document_id;
6126
6127 d_progress := 230;
6128 IF (PO_LOG.d_stmt) THEN
6129 PO_LOG.stmt(d_module_base,d_progress,'l_org_id', l_org_id);
6130 END IF;
6131
6132 d_progress := 240;
6133 PO_TAX_INTERFACE_PVT.global_document_update(
6134 p_api_version => 1.0,
6135 p_init_msg_list => FND_API.G_FALSE,
6136 p_commit => FND_API.G_FALSE,
6137 p_validation_level => FND_API.G_VALID_LEVEL_FULL,
6138 x_return_status => x_return_status,
6139 x_msg_count => x_msg_count,
6140 x_msg_data => x_msg_data,
6141 p_org_id => l_org_id,
6142 p_document_type => PO_CONSTANTS_SV.RELEASE,
6143 p_document_id => p_document_id,
6144 p_event_type_code => PO_CONSTANTS_SV.REL_CANCELLED);
6145
6146 d_progress := 250;
6147 IF (PO_LOG.d_stmt) THEN
6148 PO_LOG.stmt(d_module_base,d_progress,'After Calling PO_TAX_INTERFACE_PVT.global_document_update');
6149 PO_LOG.stmt(d_module_base,d_progress,'x_return_status', x_return_status);
6150 PO_LOG.stmt(d_module_base,d_progress,'x_msg_count', x_msg_count);
6151 PO_LOG.stmt(d_module_base,d_progress,'x_msg_data', x_msg_data);
6152 END IF;
6153
6154 END IF; --IF p_shipment_id IS NOT NULL
6155 END IF; --IF p_document_type = PO_CONSTANTS_SV.PO
6156
6157 d_progress := 260;
6158 IF (PO_LOG.d_proc) THEN
6159 PO_LOG.proc_end(d_module_base);
6160 PO_LOG.proc_end(d_module_base, 'x_return_status', x_return_status);
6161 PO_LOG.proc_end(d_module_base, 'x_msg_count', x_msg_count);
6162 PO_LOG.proc_end(d_module_base, 'x_msg_data', x_msg_data);
6163 END IF;
6164
6165 d_progress := 30;
6166 EXCEPTION
6167 WHEN OTHERS THEN
6168 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6169 IF (PO_LOG.d_exc) THEN
6170 PO_LOG.exc(d_module_base, d_progress, 'Unhandled exception in procedure cancel_tax_lines');
6171 PO_LOG.proc_end(d_module_base, 'x_return_status', x_return_status);
6172 PO_LOG.proc_end(d_module_base, 'x_msg_count', x_msg_count);
6173 PO_LOG.proc_end(d_module_base, 'x_msg_data', x_msg_data);
6174 END IF;
6175 END cancel_tax_lines;
6176
6177
6178 -----------------------------------------------------------------------------
6179 --Start of Comments
6180 --Name: global_document_update
6181 --Pre-reqs:
6182 -- None
6183 --Modifies:
6184 -- None
6185 --Locks:
6186 -- None
6187 --Function:
6188 -- Wrapper over Etax API ZX_API_PUB.global_document_update
6189 --Parameters:
6190 --IN:
6191 --p_api_version
6192 -- Standard API specification parameter
6193 --p_init_msg_list
6194 -- Standard API specification parameter
6195 --p_commit
6196 -- Standard API specification parameter
6197 --p_validation_level
6198 -- Standard API specification parameter
6199 --p_org_id
6200 -- organization id on the document
6201 --p_document_type
6202 -- 'PO' or 'RELEASE'
6203 --p_document_id
6204 -- po_header_id or po_release_id of the document
6205 --p_event_type_code
6206 -- document level action code taken from PO_CONSTANTS_SV
6207 --OUT:
6208 --x_return_status
6209 -- Standard API specification parameter
6210 --x_msg_count
6211 -- Standard API specification parameter
6212 --x_msg_data
6213 -- Standard API specification parameter
6214 --End of Comments
6215 -----------------------------------------------------------------------------
6216 PROCEDURE global_document_update(p_api_version IN NUMBER,
6217 p_init_msg_list IN VARCHAR2,
6218 p_commit IN VARCHAR2,
6219 p_validation_level IN NUMBER,
6220 x_return_status OUT NOCOPY VARCHAR2,
6221 x_msg_count OUT NOCOPY NUMBER,
6222 x_msg_data OUT NOCOPY VARCHAR2,
6223 p_org_id IN NUMBER,
6224 p_document_type IN VARCHAR2,
6225 p_document_id IN NUMBER,
6226 p_event_type_code IN VARCHAR2
6227 ) IS
6228 l_module_name CONSTANT VARCHAR2(100) := 'GLOBAL_DOCUMENT_UPDATE';
6229 d_module_base CONSTANT VARCHAR2(100) := PO_LOG.get_subprogram_base(
6230 D_PACKAGE_BASE, l_module_name);
6231 d_progress NUMBER;
6232 l_trx_rec ZX_API_PUB.transaction_rec_type;
6233 BEGIN
6234 IF (PO_LOG.d_proc) THEN
6235 PO_LOG.proc_begin(d_module_base);
6236 PO_LOG.proc_begin(d_module_base, 'p_api_version', p_api_version);
6237 PO_LOG.proc_begin(d_module_base, 'p_init_msg_list', p_init_msg_list);
6238 PO_LOG.proc_begin(d_module_base, 'p_commit', p_commit);
6239 PO_LOG.proc_begin(d_module_base, 'p_validation_level', p_validation_level);
6240 PO_LOG.proc_begin(d_module_base, 'p_org_id', p_org_id);
6241 PO_LOG.proc_begin(d_module_base, 'p_document_type', p_document_type);
6242 PO_LOG.proc_begin(d_module_base, 'p_document_id', p_document_id);
6243 PO_LOG.proc_begin(d_module_base, 'p_event_type_code', p_event_type_code);
6244 END IF;
6245
6246 d_progress := 0;
6247 IF p_document_type = PO_CONSTANTS_SV.PO THEN
6248 l_trx_rec.entity_code := PO_CONSTANTS_SV.PO_ENTITY_CODE;
6249 l_trx_rec.event_class_code := PO_CONSTANTS_SV.PO_EVENT_CLASS_CODE;
6250 ELSIF p_document_type = PO_CONSTANTS_SV.RELEASE THEN
6251 l_trx_rec.entity_code := PO_CONSTANTS_SV.REL_ENTITY_CODE;
6252 l_trx_rec.event_class_code := PO_CONSTANTS_SV.REL_EVENT_CLASS_CODE;
6253 END IF;
6254
6255 d_progress := 10;
6256 l_trx_rec.application_id := PO_CONSTANTS_SV.APPLICATION_ID;
6257 l_trx_rec.internal_organization_id := p_org_id;
6258 l_trx_rec.event_type_code := p_event_type_code;
6259 l_trx_rec.trx_id := p_document_id;
6260 l_trx_rec.application_doc_status := null;
6261
6262 d_progress := 20;
6263 IF (PO_LOG.d_stmt) THEN
6264 PO_LOG.stmt(d_module_base,d_progress,'l_trx_rec.application_id', l_trx_rec.application_id);
6265 PO_LOG.stmt(d_module_base,d_progress,'l_trx_rec.entity_code', l_trx_rec.entity_code);
6266 PO_LOG.stmt(d_module_base,d_progress,'l_trx_rec.event_class_code', l_trx_rec.event_class_code);
6267 PO_LOG.stmt(d_module_base,d_progress,'l_trx_rec.internal_organization_id', l_trx_rec.internal_organization_id);
6268 PO_LOG.stmt(d_module_base,d_progress,'l_trx_rec.event_type_code', l_trx_rec.event_type_code);
6269 PO_LOG.stmt(d_module_base,d_progress,'l_trx_rec.trx_id', l_trx_rec.trx_id);
6270 PO_LOG.stmt(d_module_base,d_progress,'l_trx_rec.application_doc_status', l_trx_rec.application_doc_status);
6271 PO_LOG.stmt(d_module_base,d_progress,'Before Calling ZX_API_PUB.global_document_update');
6272 END IF;
6273
6274 d_progress := 30;
6275 ZX_API_PUB.global_document_update(
6276 p_api_version => p_api_version,
6277 p_init_msg_list => p_init_msg_list,
6278 p_commit => p_commit,
6279 p_validation_level => p_validation_level,
6280 x_return_status => x_return_status,
6281 x_msg_count => x_msg_count,
6282 x_msg_data => x_msg_data,
6283 p_transaction_rec => l_trx_rec);
6284
6285 d_progress := 40;
6286 IF (PO_LOG.d_proc) THEN
6287 PO_LOG.proc_end(d_module_base);
6288 PO_LOG.proc_end(d_module_base, 'x_return_status', x_return_status);
6289 PO_LOG.proc_end(d_module_base, 'x_msg_count', x_msg_count);
6290 PO_LOG.proc_end(d_module_base, 'x_msg_data', x_msg_data);
6291 END IF;
6292
6293 d_progress := 50;
6294 EXCEPTION
6295 WHEN OTHERS THEN
6296 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6297 IF (PO_LOG.d_exc) THEN
6298 PO_LOG.exc(d_module_base, d_progress, 'Unhandled exception in procedure global_document_update');
6299 PO_LOG.proc_end(d_module_base, 'x_return_status', x_return_status);
6300 PO_LOG.proc_end(d_module_base, 'x_msg_count', x_msg_count);
6301 PO_LOG.proc_end(d_module_base, 'x_msg_data', x_msg_data);
6302 END IF;
6303 END global_document_update;
6304
6305
6306 -----------------------------------------------------------------------------
6307 --Start of Comments
6308 --Name: unapprove_doc_header
6309 --Pre-reqs:
6310 -- None
6311 --Modifies:
6312 -- PO_HEADERS_ALL.authorization_status
6313 -- PO_HEADERS_ALL.approved_flag
6314 -- PO_RELEASES_ALL.authorization_status
6315 -- PO_RELEASES_ALL.approved_flag
6316 --Locks:
6317 -- PO_HEADERS_ALL
6318 -- PO_RELEASES_ALL
6319 --Function:
6320 -- Unapprove the header for the given document
6321 --Parameters:
6322 --IN:
6323 --p_document_id
6324 -- Unique identifier for the document header that is to be unapproved
6325 --p_document_type
6326 -- Document Type (PO or RELEASE) for the document that is to be unapproved
6327 --OUT:
6328 --x_return_status
6329 -- Standard API specification parameter
6330 -- Can hold one of the following values:
6331 -- FND_API.G_RET_STS_SUCCESS (='S')
6332 -- FND_API.G_RET_STS_ERROR (='E')
6333 -- FND_API.G_RET_STS_UNEXP_ERROR (='U')
6334 --Notes:
6335 -- Called from ManageTaxSvrCmd when the user changes any Additional Tax
6336 -- Attribute on the Additional Tax Information page and presses Apply
6337 --End of Comments
6338 -----------------------------------------------------------------------------
6339 PROCEDURE unapprove_doc_header(p_document_id IN NUMBER,
6340 p_document_type IN VARCHAR2,
6341 x_return_status OUT NOCOPY VARCHAR2
6342 ) IS
6343 l_module_name CONSTANT VARCHAR2(100) := 'UNAPPROVE_DOC_HEADER';
6344 d_module_base CONSTANT VARCHAR2(100) := PO_LOG.get_subprogram_base(
6345 D_PACKAGE_BASE, l_module_name);
6346 d_progress NUMBER;
6347 l_authorization_status PO_HEADERS_ALL.authorization_status%TYPE;
6348 BEGIN
6349
6350 IF (PO_LOG.d_proc) THEN
6351 PO_LOG.proc_begin(d_module_base);
6352 PO_LOG.proc_begin(d_module_base, 'p_document_id', p_document_id);
6353 PO_LOG.proc_begin(d_module_base, 'p_document_type', p_document_type);
6354 END IF;
6355
6356 d_progress := 0;
6357 -- By default return status is SUCCESS if no exception occurs
6358 x_return_status := FND_API.G_RET_STS_SUCCESS;
6359
6360 d_progress := 10;
6361 IF p_document_type = PO_CONSTANTS_SV.PO THEN
6362 SELECT ph.authorization_status
6363 INTO l_authorization_status
6364 FROM po_headers_all ph
6365 WHERE ph.po_header_id = p_document_id;
6366 ELSIF p_document_type = PO_CONSTANTS_SV.RELEASE THEN
6367 SELECT pr.authorization_status
6368 INTO l_authorization_status
6369 FROM po_releases_all pr
6370 WHERE pr.po_release_id = p_document_id;
6371 END IF;
6372
6373 IF PO_LOG.d_stmt THEN
6374 PO_LOG.stmt(d_module_base,d_progress,'l_authorization_status='||l_authorization_status);
6375 END IF;
6376
6377 IF l_authorization_status = PO_CONSTANTS_SV.PRE_APPROVED THEN
6378
6379 d_progress := 20;
6380 IF p_document_type = PO_CONSTANTS_SV.PO THEN
6381 UPDATE po_headers_all ph
6382 SET ph.authorization_status = PO_CONSTANTS_SV.IN_PROCESS,
6383 ph.approved_flag = 'N'
6384 WHERE ph.po_header_id = p_document_id;
6385 ELSIF p_document_type = PO_CONSTANTS_SV.RELEASE THEN
6386 UPDATE po_releases_all pr
6387 SET pr.authorization_status = PO_CONSTANTS_SV.IN_PROCESS,
6388 pr.approved_flag = 'N'
6389 WHERE pr.po_release_id = p_document_id;
6390 END IF;
6391
6392 ELSIF l_authorization_status = PO_CONSTANTS_SV.APPROVED THEN
6393
6394 d_progress := 30;
6395 IF p_document_type = PO_CONSTANTS_SV.PO THEN
6396 UPDATE po_headers_all ph
6397 SET ph.authorization_status = PO_CONSTANTS_SV.REQUIRES_REAPPROVAL,
6398 ph.approved_flag = 'R'
6399 WHERE ph.po_header_id = p_document_id;
6400 ELSIF p_document_type = PO_CONSTANTS_SV.RELEASE THEN
6401 UPDATE po_releases_all pr
6402 SET pr.authorization_status = PO_CONSTANTS_SV.REQUIRES_REAPPROVAL,
6403 pr.approved_flag = 'R'
6404 WHERE pr.po_release_id = p_document_id;
6405 END IF;
6406
6407 END IF;
6408
6409 d_progress := 40;
6410 IF (PO_LOG.d_proc) THEN
6411 PO_LOG.proc_end(d_module_base);
6412 PO_LOG.proc_end(d_module_base, 'x_return_status', x_return_status);
6413 END IF;
6414
6415 EXCEPTION
6416 WHEN OTHERS THEN
6417 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
6418
6419 IF (PO_LOG.d_exc) THEN
6420 PO_LOG.exc(d_module_base, d_progress, SQLCODE || SQLERRM);
6421 PO_LOG.proc_end(d_module_base, 'x_return_status', x_return_status);
6422 END IF;
6423 END unapprove_doc_header;
6424
6425
6426 -----------------------------------------------------------------------------
6427 --Start of Comments
6428 --Name: unapprove_schedules
6429 --Pre-reqs:
6430 -- None
6431 --Modifies:
6432 -- PO_LINE_LOCATIONS_ALL.approved_flag
6433 --Locks:
6434 -- PO_LINE_LOCATIONS_ALL
6435 --Function:
6436 -- Unapprove the given schedules if they are approved
6437 --Parameters:
6438 --IN:
6439 --p_line_location_id_tbl
6440 -- List of schedule ids that were modified in the Additional Tax Information
6441 -- page
6442 --OUT:
6443 --x_return_status
6444 -- Standard API specification parameter
6445 -- Can hold one of the following values:
6446 -- FND_API.G_RET_STS_SUCCESS (='S')
6447 -- FND_API.G_RET_STS_ERROR (='E')
6448 -- FND_API.G_RET_STS_UNEXP_ERROR (='U')
6449 --Notes:
6450 -- Called from ManageTaxSvrCmd when the user changes any schedule level
6451 -- Additional Tax Attribute on the Additional Tax Information page and
6452 -- presses Apply
6453 --End of Comments
6454 -----------------------------------------------------------------------------
6455 PROCEDURE unapprove_schedules(p_line_location_id_tbl IN PO_TBL_NUMBER,
6456 x_return_status OUT NOCOPY VARCHAR2
6457 ) IS
6458 l_module_name CONSTANT VARCHAR2(100) := 'UNAPPROVE_SCHEDULES';
6459 d_module_base CONSTANT VARCHAR2(100) := PO_LOG.get_subprogram_base(
6460 D_PACKAGE_BASE, l_module_name);
6461 d_progress NUMBER;
6462 BEGIN
6463
6464 IF (PO_LOG.d_proc) THEN
6465 PO_LOG.proc_begin(d_module_base);
6466 PO_LOG.proc_begin(d_module_base, 'p_line_location_id_tbl', p_line_location_id_tbl);
6467 END IF;
6468
6469 d_progress := 0;
6470 -- By default return status is SUCCESS if no exception occurs
6471 x_return_status := FND_API.G_RET_STS_SUCCESS;
6472
6473 -- Unapprove line locations that are approved
6474 d_progress := 10;
6475 FORALL i IN 1..p_line_location_id_tbl.COUNT
6476 UPDATE po_line_locations_all pll
6477 SET pll.approved_flag = 'R'
6478 WHERE pll.line_location_id = p_line_location_id_tbl(i)
6479 AND pll.approved_flag = 'Y';
6480
6481 d_progress := 20;
6482 IF (PO_LOG.d_proc) THEN
6483 PO_LOG.proc_end(d_module_base);
6484 PO_LOG.proc_end(d_module_base, 'x_return_status', x_return_status);
6485 END IF;
6486
6487 EXCEPTION
6488 WHEN OTHERS THEN
6489 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
6490
6491 IF (PO_LOG.d_exc) THEN
6492 PO_LOG.exc(d_module_base, d_progress, SQLCODE || SQLERRM);
6493 PO_LOG.proc_end(d_module_base, 'x_return_status', x_return_status);
6494 END IF;
6495 END unapprove_schedules;
6496
6497
6498 END PO_TAX_INTERFACE_PVT;