DBA Data[Home] [Help]

PACKAGE BODY: APPS.FV_AP_CANCEL_PKG

Source


1 PACKAGE BODY FV_AP_CANCEL_PKG AS
2 /* $Header: FVAPCANB.pls 120.0 2006/01/04 21:47:57 ksriniva noship $ */
3     g_module_name VARCHAR2(100) := 'fv.plsql.FV_AP_CANCEL_PKG.';
4 
5 FUNCTION OPEN_PO_SHIPMENT(P_Invoice_Id 	IN   NUMBER,
6 			  P_Return_Code OUT  NOCOPY VARCHAR2 ) return BOOLEAN IS
7 
8   l_module_name         VARCHAR2(200) := g_module_name || 'OPEN_PO_SHIPMENT';
9   l_errbuf              VARCHAR2(1024);
10   l_line_location_id	po_line_locations_all.line_location_id%type;
11   l_po_line_id		po_lines_all.po_line_id%type;
12   l_po_header_id	po_headers_all.po_header_id%type;
13   l_po_doc_type		po_headers.type_lookup_code%type;
14   l_po_sub_type		po_headers.type_lookup_code%type;
15   l_return_code		varchar2(30);
16   l_inv_accounting_date date;
17 
18   -- Start Bug 3706938
19   l_ret_status                  VARCHAR2(100);
20   l_msg_count                   NUMBER;
21   l_msg_data                    VARCHAR2(4000);
22   l_po_line_loc_tab             PO_TBL_NUMBER;
23   -- End Bug 3706938
24 
25 BEGIN
26 
27   SELECT pd.line_location_id,
28 	 pd.po_line_id,
29 	 decode(pd.po_release_id, null, pd.po_header_id, pd.po_release_id),
30 	 decode(ph.type_lookup_code, 'STANDARD', 'PO', 'RELEASE'),
31 	 decode(pd.po_release_id, NULL, ph.type_lookup_code,
32 		pr.release_type),
33 	 MAX(aid.accounting_date)
34   INTO l_line_location_id,
35        l_po_line_id,
36        l_po_header_id,
37        l_po_doc_type,
38        l_po_sub_type,
39        l_inv_accounting_date
40   FROM po_distributions pd,
41        po_headers ph,
42        po_releases pr,
43        ap_invoice_distributions aid,
44        po_line_locations pll								-- Bug 3706938
45   WHERE aid.invoice_id		= P_invoice_id
46   AND   aid.po_distribution_id	= pd.po_distribution_id
47   AND   ph.po_header_id		= pd.po_header_id
48   AND   ph.po_header_id		= pll.po_header_id					-- Bug 3706938
49   AND   pll.line_location_id	= pd.line_location_id
50   AND   pd.po_release_id	= pr.po_release_id(+)
51   -- AND   aid.final_match_flag	= 'D'							-- Bug 3706938
52   AND   decode(PLL.final_match_flag, 'Y', 'D', NVL(AID.final_match_flag, 'N')) = 'D'	-- Bug 3706938
53   GROUP BY pd.line_location_id,
54 	   pd.po_line_id,
55 	   decode(pd.po_release_id, null, pd.po_header_id, pd.po_release_id),
56 	   decode(ph.type_lookup_code, 'STANDARD', 'PO', 'RELEASE'),
57 	   decode(pd.po_release_id, NULL, ph.type_lookup_code,
58 		 pr.release_type);
59 
60   IF (NOT(PO_ACTIONS.Close_PO (p_docid        => l_po_header_id,
61                                p_doctyp       => l_po_doc_type,
62                                p_docsubtyp    => l_po_sub_type,
63                                p_lineid       => l_po_line_id,
64                                p_shipid       => l_line_location_id,
65                                p_action       => 'INVOICE OPEN',
66                                p_reason       => NULL,
67                                p_calling_mode => 'AP',
68                                p_conc_flag    => 'N',
69                                p_return_code  => p_return_code,
70                                p_auto_close   => 'N',
71                                p_action_date  => l_inv_accounting_date,
72 			       p_origin_doc_id  => p_invoice_id))) /*bug3132946*/
73        THEN
74 
75       RETURN(FALSE);
76 
77    ELSE
78       IF p_return_code in ('STATE_FAILED','SUBMISSION_FAILED') THEN
79 
80          RETURN(FALSE);
81 
82       END IF;
83   END IF;
84 
85   -- Start Bug 3706938
86   l_po_line_loc_tab := po_tbl_number();
87   l_po_line_loc_tab.extend;
88   l_po_line_loc_tab(l_po_line_loc_tab.last) := l_line_location_id;
89 
90   PO_AP_INVOICE_MATCH_GRP.set_final_match_flag
91                                 (p_api_version          => '1.0',
92                                  p_entity_type          => 'PO_LINE_LOCATIONS',
93                                  p_entity_id_tbl        => l_po_line_loc_tab,
94                                  p_final_match_flag     => 'N',
95                                  p_init_msg_list        => FND_API.G_FALSE ,
96                                  p_commit               => FND_API.G_FALSE ,
97                                  x_ret_status           => l_ret_status,
98                                  x_msg_count            => l_msg_count,
99                                  x_msg_data             => l_msg_data);
100 
101   IF NOT (l_ret_status = FND_API.G_RET_STS_SUCCESS) THEN
102 
103      RETURN FALSE;
104 
105   END IF;
106   -- End Bug 3706938
107 
108   RETURN(TRUE);
109 
110 EXCEPTION
111   WHEN OTHERS THEN
112     l_errbuf := SQLERRM;
113     FV_UTILITY.LOG_MESG(FND_LOG.LEVEL_UNEXPECTED, l_module_name,l_errbuf);
114     RAISE;
115 
116 END OPEN_PO_SHIPMENT;
117 
118 END FV_AP_CANCEL_PKG;