DBA Data[Home] [Help]

PACKAGE BODY: APPS.PO_DOCUMENT_ARCHIVE_GRP

Source


1 PACKAGE BODY PO_DOCUMENT_ARCHIVE_GRP AS
2 /* $Header: POXPOARB.pls 120.2 2011/02/07 20:49:16 sautrive ship $ */
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_is_clm_doc varchar2(1) := 'N'; --<CLM View Base Document>
203   l_when_to_archive	PO_DOCUMENT_TYPES.archive_external_revision_code%TYPE;
204 BEGIN
205 
206   -- Initialize OUT parameters
207   x_return_status :=  FND_API.G_RET_STS_SUCCESS;
208   x_msg_count := 0;
209   x_msg_data := NULL;
210 
211   l_progress := '000';
212   --check p_process
213   IF (p_process is NULL OR
214       p_process NOT IN ('PRINT', 'APPROVE')) THEN
215     FND_MESSAGE.set_name('PO', 'PO_ARC_GENERAL_ERROR');
216     FND_MESSAGE.set_token('ERROR_TEXT', 'Invalid process value');
217     FND_MSG_PUB.Add;
218     RAISE FND_API.G_EXC_ERROR;
219   END IF; /* p_process NOT IN ('PRINT', 'APPROVE')*/
220 
221   l_progress := '010';
222   -- Check if we need to archive the document
223   SELECT archive_external_revision_code
224   INTO   l_when_to_archive
225   FROM   po_document_types
226   WHERE  document_type_code = p_document_type
227   AND    document_subtype   = p_document_subtype;
228 
229   l_progress := '020';
230   --<CLM View Base Document> For CLM Documents, always and only, archive on approval
231   l_is_clm_doc := PO_CLM_INTG_GRP.is_clm_document(p_doc_type => p_document_type,
232                                                   p_document_id => p_document_id);
233 
234   IF ((l_is_clm_doc = 'Y' AND p_process = 'APPROVE') OR
235      (l_is_clm_doc = 'N' AND p_process = l_when_to_archive)) THEN
236     PO_DOCUMENT_ARCHIVE_GRP.Archive_PO(
237       p_api_version => p_api_version,
238       p_document_id => p_document_id,
239       p_document_type => p_document_type,
240       p_document_subtype => p_document_subtype,
241       x_return_status => x_return_status,
242       x_msg_count => x_msg_count,
243       x_msg_data => x_msg_data);
244   END IF; /*p_process = l_when_to_archive*/
245 
246   l_progress := '100';
247   -- Standard call to get message count and if count is 1,
248   -- get message info.
249   FND_MSG_PUB.Count_And_Get
250   (p_count => x_msg_count,
251    p_data  => x_msg_data
252   );
253 
254 EXCEPTION
255   WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
256     x_msg_data := FND_MSG_PUB.GET(p_msg_index => FND_MSG_PUB.G_LAST,
257                                   p_encoded => 'F');
258     x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
259   WHEN FND_API.G_EXC_ERROR THEN
260     x_msg_data := FND_MSG_PUB.GET(p_msg_index => FND_MSG_PUB.G_LAST,
261                                   p_encoded => 'F');
262     x_return_status := FND_API.G_RET_STS_ERROR;
263   WHEN OTHERS THEN
264     IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_unexp_error) THEN
265       FND_MSG_PUB.add_exc_msg(G_PKG_NAME, l_api_name);
266     END IF;
267 
268     IF (g_fnd_debug = 'Y') THEN
269       IF (FND_LOG.G_CURRENT_RUNTIME_LEVEL <= FND_LOG.LEVEL_UNEXPECTED) THEN
270         FND_LOG.string(FND_LOG.level_unexpected, c_log_head ||
271                      l_api_name || '.others_exception', 'EXCEPTION: Location is '
272                      || l_progress || ' SQL CODE is '||sqlcode
273                      || ', EXCEPTION: '||sqlerrm);
274       END IF;
275     END IF;
276 
277     x_msg_data := FND_MSG_PUB.GET(p_msg_index => FND_MSG_PUB.G_LAST,
278                                   p_encoded => 'F');
279     x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
280 
281 END archive_po;
282 
283 /**
284 * Public Procedure: archive_po
285 * This precedure overloads archive_po to eliminate OUT parameter x_msg_count
286 */
287 PROCEDURE archive_po(p_api_version         IN         NUMBER,
288                      p_document_id         IN         NUMBER,
289                      p_document_type       IN         VARCHAR2,
290                      p_document_subtype    IN         VARCHAR2,
291                      x_return_status       OUT NOCOPY VARCHAR2,
292                      x_msg_data            OUT NOCOPY VARCHAR2)
293 IS
294   l_msg_count		NUMBER;
295 BEGIN
296   archive_po(
297     p_api_version	=> p_api_version,
298     p_document_id	=> p_document_id,
299     p_document_type	=> p_document_type,
300     p_document_subtype	=> p_document_subtype,
301     x_return_status	=> x_return_status,
302     x_msg_count		=> l_msg_count,
303     x_msg_data		=> x_msg_data);
304 END archive_po;
305 
306 END PO_DOCUMENT_ARCHIVE_GRP; -- Package spec