1: PACKAGE BODY PO_PDOI_HEADER_GROUPING_PVT AS
2: /* $Header: PO_PDOI_HEADER_GROUPING_PVT.plb 120.12 2012/01/13 12:12:07 sbontala ship $ */
3:
4: d_pkg_name CONSTANT VARCHAR2(50) :=
5: PO_LOG.get_package_base('PO_PDOI_HEADER_GROUPING_PVT');
6:
7: -------------------------------------------------------
8: ----------- PRIVATE PROCEDURES PROTOTYPE --------------
9: -------------------------------------------------------
54:
55: BEGIN
56: d_position := 0;
57:
58: IF (PO_LOG.d_proc) THEN
59: PO_LOG.proc_begin (d_module);
60: END IF;
61:
62: PO_TIMING_UTL.start_time(PO_PDOI_CONSTANTS.g_T_HEADER_GROUPING);
55: BEGIN
56: d_position := 0;
57:
58: IF (PO_LOG.d_proc) THEN
59: PO_LOG.proc_begin (d_module);
60: END IF;
61:
62: PO_TIMING_UTL.start_time(PO_PDOI_CONSTANTS.g_T_HEADER_GROUPING);
63:
96: PO_PDOI_UTL.commit_work;
97:
98: PO_TIMING_UTL.stop_time(PO_PDOI_CONSTANTS.g_T_HEADER_GROUPING);
99:
100: IF (PO_LOG.d_proc) THEN
101: PO_LOG.proc_end (d_module);
102: END IF;
103:
104: EXCEPTION
97:
98: PO_TIMING_UTL.stop_time(PO_PDOI_CONSTANTS.g_T_HEADER_GROUPING);
99:
100: IF (PO_LOG.d_proc) THEN
101: PO_LOG.proc_end (d_module);
102: END IF;
103:
104: EXCEPTION
105: WHEN OTHERS THEN
148:
149: BEGIN
150: d_position := 0;
151:
152: IF (PO_LOG.d_proc) THEN
153: PO_LOG.proc_begin (d_module);
154: END IF;
155:
156: x_all_headers_processed := FND_API.G_FALSE;
149: BEGIN
150: d_position := 0;
151:
152: IF (PO_LOG.d_proc) THEN
153: PO_LOG.proc_begin (d_module);
154: END IF;
155:
156: x_all_headers_processed := FND_API.G_FALSE;
157:
157:
158: -- Increment round number
159: PO_PDOI_PARAMS.g_current_round_num := PO_PDOI_PARAMS.g_current_round_num + 1;
160:
161: IF (PO_LOG.d_stmt) THEN
162: PO_LOG.stmt(d_module, d_position, 'Current Round Number: ' ||
163: PO_PDOI_PARAMS.g_current_round_num);
164: END IF;
165:
158: -- Increment round number
159: PO_PDOI_PARAMS.g_current_round_num := PO_PDOI_PARAMS.g_current_round_num + 1;
160:
161: IF (PO_LOG.d_stmt) THEN
162: PO_LOG.stmt(d_module, d_position, 'Current Round Number: ' ||
163: PO_PDOI_PARAMS.g_current_round_num);
164: END IF;
165:
166: IF (PO_PDOI_PARAMS.g_original_doc_processed = FND_API.G_FALSE) THEN
186: -- mark g_original_doc_processed to TRUE so that we won't process
187: -- NEW documents the next time we come here
188: PO_PDOI_PARAMS.g_original_doc_processed := FND_API.G_TRUE;
189:
190: IF (PO_LOG.d_stmt) THEN
191: PO_LOG.stmt(d_module, d_position, 'Finished progressing doc with ' ||
192: 'action = original ');
193: END IF;
194:
187: -- NEW documents the next time we come here
188: PO_PDOI_PARAMS.g_original_doc_processed := FND_API.G_TRUE;
189:
190: IF (PO_LOG.d_stmt) THEN
191: PO_LOG.stmt(d_module, d_position, 'Finished progressing doc with ' ||
192: 'action = original ');
193: END IF;
194:
195: -- IF there is no new doucment to create, we can go ahead and look for
203: UPDATE po_headers_interface
204: SET processing_round_num = PO_PDOI_PARAMS.g_current_round_num
205: WHERE interface_header_id = l_intf_header_id_tbl(i);
206:
207: IF (PO_LOG.d_stmt) THEN
208: PO_LOG.stmt(d_module, d_position, 'updated ' || SQL%ROWCOUNT ||
209: 'rows with current round number ');
210: END IF;
211: END IF;
204: SET processing_round_num = PO_PDOI_PARAMS.g_current_round_num
205: WHERE interface_header_id = l_intf_header_id_tbl(i);
206:
207: IF (PO_LOG.d_stmt) THEN
208: PO_LOG.stmt(d_module, d_position, 'updated ' || SQL%ROWCOUNT ||
209: 'rows with current round number ');
210: END IF;
211: END IF;
212:
249: l_process_list(l_po_header_id_tbl(i)) := l_intf_header_id_tbl(i);
250: END IF;
251:
252: IF (l_process_list.COUNT >= PO_PDOI_PARAMS.g_request.batch_size) THEN
253: IF (PO_LOG.d_stmt) THEN
254: PO_LOG.stmt(d_module, d_position, '# of documents to process has ' ||
255: 'reached the limit. Wait for the next round');
256: END IF;
257:
250: END IF;
251:
252: IF (l_process_list.COUNT >= PO_PDOI_PARAMS.g_request.batch_size) THEN
253: IF (PO_LOG.d_stmt) THEN
254: PO_LOG.stmt(d_module, d_position, '# of documents to process has ' ||
255: 'reached the limit. Wait for the next round');
256: END IF;
257:
258: -- exit the loop if the number of document to process exceeds
269: UPDATE po_headers_interface
270: SET processing_round_num = PO_PDOI_PARAMS.g_current_round_num
271: WHERE interface_header_id = l_process_list(i);
272:
273: IF (PO_LOG.d_stmt) THEN
274: PO_LOG.stmt(d_module, d_position, 'updated ' || SQL%ROWCOUNT ||
275: 'rows with current round number ');
276: END IF;
277:
270: SET processing_round_num = PO_PDOI_PARAMS.g_current_round_num
271: WHERE interface_header_id = l_process_list(i);
272:
273: IF (PO_LOG.d_stmt) THEN
274: PO_LOG.stmt(d_module, d_position, 'updated ' || SQL%ROWCOUNT ||
275: 'rows with current round number ');
276: END IF;
277:
278: ELSE
276: END IF;
277:
278: ELSE
279:
280: IF (PO_LOG.d_stmt) THEN
281: PO_LOG.stmt(d_module, d_position, '** No more doc to process ***');
282: END IF;
283:
284: x_all_headers_processed := FND_API.G_TRUE;
277:
278: ELSE
279:
280: IF (PO_LOG.d_stmt) THEN
281: PO_LOG.stmt(d_module, d_position, '** No more doc to process ***');
282: END IF;
283:
284: x_all_headers_processed := FND_API.G_TRUE;
285: END IF;
285: END IF;
286:
287: END IF;
288:
289: IF (PO_LOG.d_proc) THEN
290: PO_LOG.proc_end (d_module);
291: END IF;
292:
293: EXCEPTION
286:
287: END IF;
288:
289: IF (PO_LOG.d_proc) THEN
290: PO_LOG.proc_end (d_module);
291: END IF;
292:
293: EXCEPTION
294: WHEN OTHERS THEN
348: l_temp NUMBER;
349: BEGIN
350: d_position := 0;
351:
352: IF (PO_LOG.d_proc) THEN
353: PO_LOG.proc_begin (d_module);
354: END IF;
355:
356: --SQL What: get all records that will be processed in current round. It also
349: BEGIN
350: d_position := 0;
351:
352: IF (PO_LOG.d_proc) THEN
353: PO_LOG.proc_begin (d_module);
354: END IF;
355:
356: --SQL What: get all records that will be processed in current round. It also
357: -- locks the po_Headers of documents that are being updated
420:
421: d_position := 30;
422:
423: IF (l_tmp_draft_id IS NULL) THEN
424: IF (PO_LOG.d_stmt) THEN
425: PO_LOG.stmt(d_module, d_position, 'draft id not found');
426: END IF;
427:
428: d_position := 40;
421: d_position := 30;
422:
423: IF (l_tmp_draft_id IS NULL) THEN
424: IF (PO_LOG.d_stmt) THEN
425: PO_LOG.stmt(d_module, d_position, 'draft id not found');
426: END IF;
427:
428: d_position := 40;
429:
437: PO_DRAFTS_PVT.g_status_PDOI_ERROR)) THEN
438:
439: d_position := 50;
440:
441: IF (PO_LOG.d_stmt) THEN
442: PO_LOG.stmt(d_module, d_position, 'existing draft is processed ' ||
443: 'by PDOI. check whether the previous PDOI is still ' ||
444: 'working on it');
445: END IF;
438:
439: d_position := 50;
440:
441: IF (PO_LOG.d_stmt) THEN
442: PO_LOG.stmt(d_module, d_position, 'existing draft is processed ' ||
443: 'by PDOI. check whether the previous PDOI is still ' ||
444: 'working on it');
445: END IF;
446:
458:
459: IF (l_new_draft_needed = FND_API.G_TRUE) THEN
460: d_position := 70;
461:
462: IF (PO_LOG.d_stmt) THEN
463: PO_LOG.stmt(d_module, d_position, 'old draft can be removed. ' ||
464: 'Creating a new one');
465: END IF;
466:
459: IF (l_new_draft_needed = FND_API.G_TRUE) THEN
460: d_position := 70;
461:
462: IF (PO_LOG.d_stmt) THEN
463: PO_LOG.stmt(d_module, d_position, 'old draft can be removed. ' ||
464: 'Creating a new one');
465: END IF;
466:
467: PO_DRAFTS_PVT.remove_draft_changes
476: l_draft_id_tbl(i) := PO_DRAFTS_PVT.draft_id_nextval;
477: ELSE
478: d_position := 80;
479:
480: IF (PO_LOG.d_stmt) THEN
481: PO_LOG.stmt(d_module, d_position, 'old draft is still being ' ||
482: 'worked on. Fail the current intf record');
483: END IF;
484:
477: ELSE
478: d_position := 80;
479:
480: IF (PO_LOG.d_stmt) THEN
481: PO_LOG.stmt(d_module, d_position, 'old draft is still being ' ||
482: 'worked on. Fail the current intf record');
483: END IF;
484:
485: PO_PDOI_ERR_UTL.add_fatal_error
499: ELSE
500:
501: d_position := 90;
502:
503: IF (PO_LOG.d_stmt) THEN
504: PO_LOG.stmt(d_module, d_position, 'draft with id ' ||
505: l_tmp_draft_id || ' can be reused.');
506: END IF;
507:
500:
501: d_position := 90;
502:
503: IF (PO_LOG.d_stmt) THEN
504: PO_LOG.stmt(d_module, d_position, 'draft with id ' ||
505: l_tmp_draft_id || ' can be reused.');
506: END IF;
507:
508: -- other draft status -- reuse the draft
590: END LOOP;
591:
592: d_position := 150;
593:
594: IF (PO_LOG.d_stmt) THEN
595: PO_LOG.stmt(d_module, d_position,
596: 'Number of existing drafts: ' || l_existing_dft_idx_tbl.COUNT);
597: END IF;
598:
591:
592: d_position := 150;
593:
594: IF (PO_LOG.d_stmt) THEN
595: PO_LOG.stmt(d_module, d_position,
596: 'Number of existing drafts: ' || l_existing_dft_idx_tbl.COUNT);
597: END IF;
598:
599: -- Since DB 10g has probems using VALUES OF against EMPTYCOLLECTION,
611: last_updated_by = FND_GLOBAL.user_id
612: WHERE draft_id = l_draft_id_tbl(i);
613: END IF;
614:
615: IF (PO_LOG.d_proc) THEN
616: PO_LOG.proc_end (d_module);
617: END IF;
618:
619: EXCEPTION
612: WHERE draft_id = l_draft_id_tbl(i);
613: END IF;
614:
615: IF (PO_LOG.d_proc) THEN
616: PO_LOG.proc_end (d_module);
617: END IF;
618:
619: EXCEPTION
620: WHEN OTHERS THEN
650: l_record_exist_tbl PO_TBL_VARCHAR1;
651: BEGIN
652: d_position := 0;
653:
654: IF (PO_LOG.d_proc) THEN
655: PO_LOG.proc_begin (d_module);
656: END IF;
657:
658: --SQL What: Get all the existing lines that match the category name given
651: BEGIN
652: d_position := 0;
653:
654: IF (PO_LOG.d_proc) THEN
655: PO_LOG.proc_begin (d_module);
656: END IF;
657:
658: --SQL What: Get all the existing lines that match the category name given
659: -- Make sure that the lines are not cancelled, closed or expired
672: AND NVL(POL.cancel_flag, 'N') = 'N'
673: AND NVL(POL.closed_code, 'OPEN') <> 'FINALLY CLOSED'
674: AND NVL(POL.expiration_date, SYSDATE+1) > SYSDATE;
675:
676: IF (PO_LOG.d_stmt) THEN
677: PO_LOG.stmt(d_module, d_position, 'Number of lines to expire',
678: l_line_id_tbl.COUNT);
679: END IF;
680:
673: AND NVL(POL.closed_code, 'OPEN') <> 'FINALLY CLOSED'
674: AND NVL(POL.expiration_date, SYSDATE+1) > SYSDATE;
675:
676: IF (PO_LOG.d_stmt) THEN
677: PO_LOG.stmt(d_module, d_position, 'Number of lines to expire',
678: l_line_id_tbl.COUNT);
679: END IF;
680:
681: IF (l_line_id_tbl.COUNT > 0) THEN
701: AND draft_id = l_draft_id_tbl(i);
702:
703: END IF;
704:
705: IF (PO_LOG.d_proc) THEN
706: PO_LOG.proc_end (d_module);
707: END IF;
708:
709: EXCEPTION
702:
703: END IF;
704:
705: IF (PO_LOG.d_proc) THEN
706: PO_LOG.proc_end (d_module);
707: END IF;
708:
709: EXCEPTION
710: WHEN OTHERS THEN
746:
747: BEGIN
748: d_position := 0;
749:
750: IF (PO_LOG.d_proc) THEN
751: PO_LOG.proc_begin (d_module);
752: END IF;
753:
754: PO_PDOI_PARAMS.g_docs_info.DELETE;
747: BEGIN
748: d_position := 0;
749:
750: IF (PO_LOG.d_proc) THEN
751: PO_LOG.proc_begin (d_module);
752: END IF;
753:
754: PO_PDOI_PARAMS.g_docs_info.DELETE;
755:
778: PO_PDOI_PARAMS.g_docs_info(l_id).has_lines_to_notify := FND_API.G_FALSE;
779: PO_PDOI_PARAMS.g_docs_info(l_id).new_draft := FND_API.G_FALSE; -- bug5129752
780: END LOOP;
781:
782: IF (PO_LOG.d_proc) THEN
783: PO_LOG.proc_end (d_module);
784: END IF;
785:
786: EXCEPTION
779: PO_PDOI_PARAMS.g_docs_info(l_id).new_draft := FND_API.G_FALSE; -- bug5129752
780: END LOOP;
781:
782: IF (PO_LOG.d_proc) THEN
783: PO_LOG.proc_end (d_module);
784: END IF;
785:
786: EXCEPTION
787: WHEN OTHERS THEN
830:
831: BEGIN
832: d_position := 0;
833:
834: IF (PO_LOG.d_proc) THEN
835: PO_LOG.proc_begin (d_module, 'p_draft_id', p_draft_id);
836: PO_LOG.proc_begin (d_module, 'p_status', p_status);
837: END IF;
838:
831: BEGIN
832: d_position := 0;
833:
834: IF (PO_LOG.d_proc) THEN
835: PO_LOG.proc_begin (d_module, 'p_draft_id', p_draft_id);
836: PO_LOG.proc_begin (d_module, 'p_status', p_status);
837: END IF;
838:
839: x_new_draft_needed := FND_API.G_FALSE;
832: d_position := 0;
833:
834: IF (PO_LOG.d_proc) THEN
835: PO_LOG.proc_begin (d_module, 'p_draft_id', p_draft_id);
836: PO_LOG.proc_begin (d_module, 'p_status', p_status);
837: END IF;
838:
839: x_new_draft_needed := FND_API.G_FALSE;
840:
858: );
859:
860: END IF; -- if status = p_status = PO_DRAFTS_PVT.g_status_PDOI_ERROR
861:
862: IF (PO_LOG.d_proc) THEN
863: PO_LOG.proc_end (d_module, 'x_new_draft_needed', x_new_draft_needed);
864: END IF;
865:
866: EXCEPTION
859:
860: END IF; -- if status = p_status = PO_DRAFTS_PVT.g_status_PDOI_ERROR
861:
862: IF (PO_LOG.d_proc) THEN
863: PO_LOG.proc_end (d_module, 'x_new_draft_needed', x_new_draft_needed);
864: END IF;
865:
866: EXCEPTION
867: WHEN OTHERS THEN