[Home] [Help]
PACKAGE BODY: APPS.PO_DOCUMENT_ARCHIVE_GRP
Source
1 PACKAGE BODY PO_DOCUMENT_ARCHIVE_GRP AS
2 /* $Header: POXPOARB.pls 120.1 2005/06/29 18:40:18 shsiung noship $ */
3
4 G_PKG_NAME CONSTANT varchar2(30) := 'PO_DOCUMENT_ARCHIVE_GRP';
5
6 c_log_head CONSTANT VARCHAR2(50) := 'po.plsql.'|| G_PKG_NAME || '.';
7
8 -- Read the profile option that enables/disables the debug log
9 g_fnd_debug VARCHAR2(1) := NVL(FND_PROFILE.VALUE('AFLOG_ENABLED'),'N');
10
11 /**
12 * Public Procedure: archive_po
13 * Requires:
14 * IN PARAMETERS:
15 * p_api_version: Version number of API that caller expects. It
16 * should match the l_api_version defined in the
17 * procedure (expected value : 1.0)
18 * p_document_id: The id of the document that needs to be archived.
19 * p_document_type: The type of the document to archive
20 * PO : For Standard/Planned
21 * PA : For Blanket/Contract
22 * RELEASE : Release
23 * p_document_subtype: The subtype of the document.
24 * Valid Document types and Document subtypes are
25 * Document Type Document Subtype
26 * RELEASE ---> SCHEDULED/BLANKET
27 * PO ---> PLANNED/STANDARD
28 * PA ---> CONTRACT/BLANKET
29 *
30 * Modifies: Arcives the document. Inserts an copy of the document in the
31 * archive tables
32 * Effects: This procedure archives the document that is passed in
33 *
34 * Returns:
35 * x_return_status: FND_API.G_RET_STS_SUCCESS if API succeeds
36 * FND_API.G_RET_STS_ERROR if API fails
37 * FND_API.G_RET_STS_UNEXP_ERROR if unexpected error occurs
38 * x_msg_data: Contains error msg in case x_return_status returned
39 * FND_API.G_RET_STS_ERROR or FND_API.G_RET_STS_UNEXP_ERROR
40 */
41
42 PROCEDURE archive_po(p_api_version IN NUMBER,
43 p_document_id IN NUMBER,
44 p_document_type IN VARCHAR2,
45 p_document_subtype IN VARCHAR2,
46 x_return_status OUT NOCOPY VARCHAR2,
47 x_msg_count OUT NOCOPY NUMBER,
48 x_msg_data OUT NOCOPY VARCHAR2)
49 IS
50
51 l_api_name CONSTANT varchar2(30) := 'ARCHIVE_PO';
52 l_api_version CONSTANT NUMBER := 1.0;
53 l_progress VARCHAR2(3);
54 l_document_id NUMBER;
55
56 BEGIN
57
58 -- Initialize OUT parameters
59 x_return_status := FND_API.G_RET_STS_SUCCESS;
60 x_msg_count := 0;
61 x_msg_data := NULL;
62
63 l_progress := '000';
64 -- Standard call to check for call compatibility
65 IF NOT FND_API.Compatible_API_Call(l_api_version, p_api_version, l_api_name, G_PKG_NAME)
66 THEN
67 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
68 END IF;
69
70 l_progress := '010';
71 IF g_fnd_debug = 'Y' THEN
72 IF (FND_LOG.G_CURRENT_RUNTIME_LEVEL <= FND_LOG.LEVEL_STATEMENT) THEN
73 FND_LOG.string(FND_LOG.LEVEL_STATEMENT,c_log_head || '.'||l_api_name||'.'
74 || l_progress,'Doing Validation on passed in data');
75 END IF;
76 END IF;
77
78 l_progress := '020';
79 -- Check the required fields
80 IF ((p_document_id is NULL) OR (p_document_type is NULL) OR
81 (p_document_subtype IS NULL)) THEN
82 FND_MESSAGE.set_name('PO', 'PO_ARC_GENERAL_ERROR');
83 FND_MESSAGE.set_token('ERROR_TEXT', 'Mandatory parameters are NULL');
84 FND_MSG_PUB.Add;
85 RAISE FND_API.G_EXC_ERROR;
86 END IF; /*(p_document_id is NULL) OR (p_document_type is NULL)*/
87
88 l_progress := '030';
89 --check p_document_type
90 IF p_document_type NOT IN ('RELEASE', 'PO', 'PA') THEN
91 FND_MESSAGE.set_name('PO', 'PO_ARC_GENERAL_ERROR');
92 FND_MESSAGE.set_token('ERROR_TEXT', 'Invalid document type');
93 FND_MSG_PUB.Add;
94 RAISE FND_API.G_EXC_ERROR;
95 END IF; /*p_document_type NOT IN ('RELEASE', 'PO', 'PA')*/
96
97 l_progress := '040';
98 --check that document_subtype matches
99 IF p_document_type = 'RELEASE' THEN
100 IF p_document_subtype NOT IN ('SCHEDULED', 'BLANKET') THEN
101 FND_MESSAGE.set_name('PO', 'PO_ARC_GENERAL_ERROR');
102 FND_MESSAGE.set_token('ERROR_TEXT', 'Invalid Release document subtype');
103 FND_MSG_PUB.Add;
104 RAISE FND_API.G_EXC_ERROR;
105 END IF;
106 ELSIF p_document_type = 'PO' THEN
107 IF p_document_subtype NOT IN ('STANDARD', 'PLANNED') THEN
108 FND_MESSAGE.set_name('PO', 'PO_ARC_GENERAL_ERROR');
109 FND_MESSAGE.set_token('ERROR_TEXT', 'Invalid PO document subtype');
110 FND_MSG_PUB.Add;
111 RAISE FND_API.G_EXC_ERROR;
112 END IF;
113 ELSIF p_document_type = 'PA' THEN
114 IF p_document_subtype NOT IN ('BLANKET', 'CONTRACT') THEN
115 FND_MESSAGE.set_name('PO', 'PO_ARC_GENERAL_ERROR');
116 FND_MESSAGE.set_token('ERROR_TEXT', 'Invalid PA document subtype');
117 FND_MSG_PUB.Add;
118 RAISE FND_API.G_EXC_ERROR;
119 END IF;
120 END IF; /*p_document_type = 'RELEASE'*/
121
122 l_progress := '040';
123 --check that document_id passed exists
124 BEGIN
125 IF p_document_type IN ('PO', 'PA') THEN
126 SELECT po_header_id
127 INTO l_document_id
128 FROM PO_HEADERS_ALL
129 WHERE po_header_id= p_document_id;
130 ELSE --Its a release
131 SELECT po_release_id
132 INTO l_document_id
133 FROM PO_RELEASES_ALL
134 WHERE po_release_id= p_document_id;
135 END IF; /*p_document_type IN ('PO', 'PA')*/
136 EXCEPTION
137 WHEN NO_DATA_FOUND THEN
138 FND_MESSAGE.set_name('PO', 'PO_ARC_GENERAL_ERROR');
139 FND_MESSAGE.set_token('ERROR_TEXT', 'Invalid document_id passed');
140 FND_MSG_PUB.Add;
141 RAISE FND_API.G_EXC_ERROR;
142 END;
143
144 l_progress := '100';
145 --Call the private Archive_PO
146 PO_DOCUMENT_ARCHIVE_PVT.Archive_PO(
147 p_api_version => p_api_version,
148 p_document_id => p_document_id,
149 p_document_type => p_document_type,
150 p_document_subtype => p_document_subtype,
151 x_return_status => x_return_status,
152 x_msg_count => x_msg_count,
153 x_msg_data => x_msg_data);
154
155 l_progress := '200';
156 EXCEPTION
157 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
158 x_msg_data := FND_MSG_PUB.GET(p_msg_index => FND_MSG_PUB.G_LAST,
159 p_encoded => 'F');
160 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
161 WHEN FND_API.G_EXC_ERROR THEN
162 x_msg_data := FND_MSG_PUB.GET(p_msg_index => FND_MSG_PUB.G_LAST,
163 p_encoded => 'F');
164 x_return_status := FND_API.G_RET_STS_ERROR;
165 WHEN OTHERS THEN
166 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_unexp_error) THEN
167 FND_MSG_PUB.add_exc_msg(G_PKG_NAME, l_api_name);
168 END IF;
169
170 IF (g_fnd_debug = 'Y') THEN
171 IF (FND_LOG.G_CURRENT_RUNTIME_LEVEL <= FND_LOG.LEVEL_UNEXPECTED) THEN
172 FND_LOG.string(FND_LOG.level_unexpected, c_log_head ||
173 l_api_name || '.others_exception', 'EXCEPTION: Location is '
174 || l_progress || ' SQL CODE is '||sqlcode
175 || ', EXCEPTION: '||sqlerrm);
176 END IF;
177 END IF;
178
179 x_msg_data := FND_MSG_PUB.GET(p_msg_index => FND_MSG_PUB.G_LAST,
180 p_encoded => 'F');
181 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
182
183 END archive_po;
184
185 /**
186 * Public Procedure: archive_po
187 * This precedure accepts one more required IN PARAMETERS:
188 * p_process: Process that called this routine: 'PRINT' or 'APPROVE'
189 */
190 PROCEDURE archive_po(p_api_version IN NUMBER,
191 p_document_id IN NUMBER,
192 p_document_type IN VARCHAR2,
193 p_document_subtype IN VARCHAR2,
194 p_process IN VARCHAR2,
195 x_return_status OUT NOCOPY VARCHAR2,
196 x_msg_count OUT NOCOPY NUMBER,
197 x_msg_data OUT NOCOPY VARCHAR2)
198 IS
199 l_api_name CONSTANT varchar2(30) := 'ARCHIVE_PO';
200 l_api_version CONSTANT NUMBER := 1.0;
201 l_progress VARCHAR2(3);
202 l_when_to_archive PO_DOCUMENT_TYPES.archive_external_revision_code%TYPE;
203 BEGIN
204
205 -- Initialize OUT parameters
206 x_return_status := FND_API.G_RET_STS_SUCCESS;
207 x_msg_count := 0;
208 x_msg_data := NULL;
209
210 l_progress := '000';
211 --check p_process
212 IF (p_process is NULL OR
213 p_process NOT IN ('PRINT', 'APPROVE')) THEN
214 FND_MESSAGE.set_name('PO', 'PO_ARC_GENERAL_ERROR');
215 FND_MESSAGE.set_token('ERROR_TEXT', 'Invalid process value');
216 FND_MSG_PUB.Add;
217 RAISE FND_API.G_EXC_ERROR;
218 END IF; /* p_process NOT IN ('PRINT', 'APPROVE')*/
219
220 l_progress := '010';
221 -- Check if we need to archive the document
222 SELECT archive_external_revision_code
223 INTO l_when_to_archive
224 FROM po_document_types
225 WHERE document_type_code = p_document_type
226 AND document_subtype = p_document_subtype;
227
228 l_progress := '020';
229 IF p_process = l_when_to_archive THEN
230 PO_DOCUMENT_ARCHIVE_GRP.Archive_PO(
231 p_api_version => p_api_version,
232 p_document_id => p_document_id,
233 p_document_type => p_document_type,
234 p_document_subtype => p_document_subtype,
235 x_return_status => x_return_status,
236 x_msg_count => x_msg_count,
237 x_msg_data => x_msg_data);
238 END IF; /*p_process = l_when_to_archive*/
239
240 l_progress := '100';
241 -- Standard call to get message count and if count is 1,
242 -- get message info.
243 FND_MSG_PUB.Count_And_Get
244 (p_count => x_msg_count,
245 p_data => x_msg_data
246 );
247
248 EXCEPTION
249 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
250 x_msg_data := FND_MSG_PUB.GET(p_msg_index => FND_MSG_PUB.G_LAST,
251 p_encoded => 'F');
252 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
253 WHEN FND_API.G_EXC_ERROR THEN
254 x_msg_data := FND_MSG_PUB.GET(p_msg_index => FND_MSG_PUB.G_LAST,
255 p_encoded => 'F');
256 x_return_status := FND_API.G_RET_STS_ERROR;
257 WHEN OTHERS THEN
258 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_unexp_error) THEN
259 FND_MSG_PUB.add_exc_msg(G_PKG_NAME, l_api_name);
260 END IF;
261
262 IF (g_fnd_debug = 'Y') THEN
263 IF (FND_LOG.G_CURRENT_RUNTIME_LEVEL <= FND_LOG.LEVEL_UNEXPECTED) THEN
264 FND_LOG.string(FND_LOG.level_unexpected, c_log_head ||
265 l_api_name || '.others_exception', 'EXCEPTION: Location is '
266 || l_progress || ' SQL CODE is '||sqlcode
267 || ', EXCEPTION: '||sqlerrm);
268 END IF;
269 END IF;
270
271 x_msg_data := FND_MSG_PUB.GET(p_msg_index => FND_MSG_PUB.G_LAST,
272 p_encoded => 'F');
273 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
274
275 END archive_po;
276
277 /**
278 * Public Procedure: archive_po
279 * This precedure overloads archive_po to eliminate OUT parameter x_msg_count
280 */
281 PROCEDURE archive_po(p_api_version IN NUMBER,
282 p_document_id IN NUMBER,
283 p_document_type IN VARCHAR2,
284 p_document_subtype IN VARCHAR2,
285 x_return_status OUT NOCOPY VARCHAR2,
286 x_msg_data OUT NOCOPY VARCHAR2)
287 IS
288 l_msg_count NUMBER;
289 BEGIN
290 archive_po(
291 p_api_version => p_api_version,
292 p_document_id => p_document_id,
293 p_document_type => p_document_type,
294 p_document_subtype => p_document_subtype,
295 x_return_status => x_return_status,
296 x_msg_count => l_msg_count,
297 x_msg_data => x_msg_data);
298 END archive_po;
299
300 END PO_DOCUMENT_ARCHIVE_GRP; -- Package spec