DBA Data[Home] [Help]

PACKAGE BODY: APPS.OE_ATCHMT_UTIL

Source


1 PACKAGE BODY OE_Atchmt_UTIL as
2 /* $Header: OEXUATTB.pls 120.0 2005/06/01 23:10:08 appldev noship $ */
3 
4 --  Global constant holding the package name
5 G_PKG_NAME                    CONSTANT VARCHAR2(30) := 'OE_Atchmt_UTIL';
6 
7 G_DEFAULT_DOC_CATEGORY_ID	CONSTANT NUMBER := 1000035;
8 
9 
10 -- LOCAL PROCEDURES/FUNCTIONS
11 
12 FUNCTION Get_Document_Entity(p_entity_code IN VARCHAR2)
13 RETURN VARCHAR2
14 IS
15 --
16 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
17 --
18 BEGIN
19 
20 	IF p_entity_code = OE_GLOBALS.G_ENTITY_HEADER THEN
21 		RETURN OE_Atchmt_UTIL.G_DOC_ENTITY_ORDER_HEADER;
22 	ELSIF p_entity_code = OE_GLOBALS.G_ENTITY_LINE THEN
23 		RETURN OE_Atchmt_UTIL.G_DOC_ENTITY_ORDER_LINE;
24 	END IF;
25 
26 END Get_Document_Entity;
27 
28 
29 -- PUBLIC PROCEDURES/FUNCTIONS
30 
31 ---------------------------------------------------------
32 PROCEDURE Apply_Automatic_Attachments
33 (
34  p_init_msg_list				in   varchar2 default fnd_api.g_false,
35  p_entity_code                     in   varchar2,
36  p_entity_id                       in   number,
37  p_is_user_action				in   varchar2 default 'Y',
38 x_attachment_count out nocopy number,
39 
40 x_return_status out nocopy varchar2,
41 
42 x_msg_count out nocopy number,
43 
44 x_msg_data out nocopy varchar2
45 
46 )
47 ---------------------------------------------------------
48 IS
49 l_entity_name					VARCHAR2(30);
50 l_line_number					NUMBER;
51 --
52 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
53 --
54 BEGIN
55 
56     -- Initialize API return status to success
57     x_return_status := FND_API.G_RET_STS_SUCCESS;
58 
59     --  Initialize message list.
60     IF FND_API.to_Boolean(p_init_msg_list) THEN
61         OE_MSG_PUB.initialize;
62     END IF;
63 
64 
65 	-- is_user_action is 'N' therefore check the profile option value
66 	-- find out if attachments should be applied automatically.
67      IF p_is_user_action = 'N'
68       AND NVL(FND_PROFILE.VALUE('OE_APPLY_AUTOMATIC_ATCHMT'),'Y') = 'N' THEN
69           IF l_debug_level  > 0 THEN
70               oe_debug_pub.add(  'PROFILE OM: APPLY AUTOMATIC ATTACHMENTS IS NO' , 1 ) ;
71           END IF;
72                RETURN;
73      END IF;
74 
75 	l_entity_name := Get_Document_Entity(p_entity_code);
76 
77 	IF l_entity_name IS NOT NULL THEN
78 
79 		OE_FND_Attachments_PVT.Add_Attachments_Automatic
80 			(p_api_version		=> 1.0
81 			,p_entity_name		=> l_entity_name
82 			,p_pk1_value		=> to_char(p_entity_id)
83 			,x_attachment_count		=> x_attachment_count
84 			,x_return_status		=> x_return_status
85 			,x_msg_count			=> x_msg_count
86 			,x_msg_data			=> x_msg_data
87 			);
88 
89 	END IF;
90 
91      IF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
92           RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
93      ELSIF x_return_status = FND_API.G_RET_STS_ERROR THEN
94           RAISE FND_API.G_EXC_ERROR;
95      END IF;
96 
97 	-- Add information messages to indicate if automatic attachments
98 	-- were applied or not if it is a user action
99 	IF p_is_user_action = 'Y' THEN
100 
101        IF x_attachment_count > 0 THEN
102 
103           IF p_entity_code = OE_GLOBALS.G_ENTITY_HEADER THEN
104                FND_MESSAGE.SET_NAME('ONT','OE_ORDER_ATTACHMENTS_APPLIED');
105                FND_MESSAGE.SET_TOKEN('ORDER_COUNT',to_char(x_attachment_count));
106                OE_MSG_PUB.ADD;
107           ELSIF p_entity_code = OE_GLOBALS.G_ENTITY_LINE THEN
108                SELECT line_number
109                INTO l_line_number
110                FROM oe_order_lines
111                WHERE line_id = p_entity_id;
112                FND_MESSAGE.SET_NAME('ONT','OE_LINE_ATTACHMENTS_APPLIED');
113                FND_MESSAGE.SET_TOKEN('LINE_COUNT',to_char(x_attachment_count));
114                FND_MESSAGE.SET_TOKEN('LINE_NUMBER',to_char(l_line_number));
115                OE_MSG_PUB.ADD;
116           END IF;
117 
118        ELSIF x_attachment_count = 0 THEN
119 
120           IF p_entity_code = OE_GLOBALS.G_ENTITY_HEADER THEN
121                FND_MESSAGE.SET_NAME('ONT','OE_NO_ORDER_ATCHMT_APPLIED');
122                OE_MSG_PUB.ADD;
123           ELSIF p_entity_code = OE_GLOBALS.G_ENTITY_LINE THEN
124                FND_MESSAGE.SET_NAME('ONT','OE_NO_LINE_ATCHMT_APPLIED');
125                OE_MSG_PUB.ADD;
126           END IF;
127 
128 	  END IF;
129 
130      END IF;
131 
132 	OE_MSG_PUB.Count_And_Get
133                 (   p_count     =>      x_msg_count
134                 ,   p_data      =>      x_msg_data
135                 );
136 
137 EXCEPTION
138     WHEN FND_API.G_EXC_ERROR THEN
139         x_return_status := FND_API.G_RET_STS_ERROR;
140 	   OE_MSG_PUB.Count_And_Get
141                 (   p_count     =>      x_msg_count
142                 ,   p_data      =>      x_msg_data
143                 );
144     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
145         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
146 	   OE_MSG_PUB.Count_And_Get
147                 (   p_count     =>      x_msg_count
148                 ,   p_data      =>      x_msg_data
149                 );
150     WHEN OTHERS THEN
151         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
152         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
153         THEN
154             OE_MSG_PUB.Add_Exc_Msg
155             (   G_PKG_NAME
156             ,   'Apply_Automatic_Attachments'
157 			);
158         END IF;
159 	   OE_MSG_PUB.Count_And_Get
160                 (   p_count     =>      x_msg_count
161                 ,   p_data      =>      x_msg_data
162                 );
163 END Apply_Automatic_Attachments;
164 
165 
166 ------------------------------------------
167 PROCEDURE Delete_Attachments
168 (
169  p_entity_code                     in   varchar2,
170  p_entity_id                       in   number,
171 x_return_status out nocopy varchar2
172 
173 )
174 ------------------------------------------
175 IS
176 l_entity_name					VARCHAR2(30);
177 --
178 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
179 --
180 BEGIN
181 
182     -- Initialize API return status to success
183     x_return_status := FND_API.G_RET_STS_SUCCESS;
184 
185 	l_entity_name := Get_Document_Entity(p_entity_code);
186 
187 	IF l_entity_name IS NOT NULL THEN
188 
189 		FND_ATTACHED_DOCUMENTS2_PKG.Delete_Attachments
190 			(x_entity_name		=> l_entity_name
191 			,x_pk1_value		=> to_char(p_entity_id)
192 			,x_automatically_added_flag	=> null
193                 -- Bug 3280106
194                 -- Delete all FND one-time documents specific to this entity
195                         ,x_delete_document_flag => 'Y'
196 			);
197 
198 	END IF;
199 
200 EXCEPTION
201     WHEN FND_API.G_EXC_ERROR THEN
202         x_return_status := FND_API.G_RET_STS_ERROR;
203     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
204         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
205     WHEN OTHERS THEN
206         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
207         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
208         THEN
209             OE_MSG_PUB.Add_Exc_Msg
210             (   G_PKG_NAME
211             ,   'Delete_Attachments'
212 			);
213         END IF;
214 END Delete_Attachments;
215 
216 
217 -----------------------------------------------------------------
218 PROCEDURE Copy_Attachments
219 (
220  p_entity_code			in   varchar2,
221  p_from_entity_id		in   number,
222  p_to_entity_id			in   number,
223  p_manual_attachments_only			in   varchar2 default 'N',
224 x_return_status out nocopy varchar2
225 
226 )
227 -----------------------------------------------------------------
228 IS
229 l_entity_name						VARCHAR2(30);
230 --
231 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
232 --
233 BEGIN
234 
235 	x_return_status := FND_API.G_RET_STS_SUCCESS;
236 
237 	l_entity_name := Get_Document_Entity(p_entity_code);
238 
239 	IF l_debug_level  > 0 THEN
240 	    oe_debug_pub.add(  'ENTITY NAME :'||L_ENTITY_NAME ) ;
241 	END IF;
242 
243 	IF l_entity_name IS NOT NULL THEN
244 
245 	  IF p_manual_attachments_only = 'Y' THEN
246 
247 		IF l_debug_level  > 0 THEN
248 		    oe_debug_pub.add(  'CPY MANUAL ATCHMT' , 1 ) ;
249 		END IF;
250 
251 		FND_ATTACHED_DOCUMENTS2_PKG.Copy_Attachments
252 			( x_from_entity_name		=> l_entity_name
253 			, x_from_pk1_value			=> to_char(p_from_entity_id)
254 			, x_to_entity_name			=> l_entity_name
255 			, x_to_pk1_value			=> to_char(p_to_entity_id)
256 			, x_automatically_added_flag  => 'N'
257 			);
258 	  ELSE
259 
260 		IF l_debug_level  > 0 THEN
261 		    oe_debug_pub.add(  'CPY ALL ATCHMT' , 1 ) ;
262 		END IF;
263 
264 		FND_ATTACHED_DOCUMENTS2_PKG.Copy_Attachments
265 			( x_from_entity_name		=> l_entity_name
266 			, x_from_pk1_value			=> to_char(p_from_entity_id)
267 			, x_to_entity_name			=> l_entity_name
268 			, x_to_pk1_value			=> to_char(p_to_entity_id)
269 			, x_automatically_added_flag  => null
270 			);
271 
272 	  END IF;
273 
274 	END IF;
275 
276 EXCEPTION
277     WHEN FND_API.G_EXC_ERROR THEN
278         x_return_status := FND_API.G_RET_STS_ERROR;
279     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
280         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
281     WHEN OTHERS THEN
282         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
283         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
284         THEN
285             OE_MSG_PUB.Add_Exc_Msg
286             (   G_PKG_NAME
287             ,   'Copy_Attachments'
288 			);
289         END IF;
290 END Copy_Attachments;
291 
292 
293 -------------------------------------
294 PROCEDURE Add_Attachment
295 (
296  p_api_version		in   number,
297  p_entity_code  		in   varchar2,
298  p_entity_id	  	in   number,
299  p_document_desc    	in   varchar2 default null,
300  p_document_text  	in   varchar2 default null,
301  p_category_id  		in   number   default null,
302  p_document_id   		in   number default null,
303 x_attachment_id out nocopy number,
304 
305 x_return_status out nocopy varchar2,
306 
307 x_msg_count out nocopy number,
308 
309 x_msg_data out nocopy varchar2
310 
311 )
312 IS
313    l_return_status 	varchar2(1);
314    l_msg_count		number;
315    l_msg_data		varchar2(80);
316    l_entity_name  	varchar2(30);
317    l_media_id		number;
318    l_category_id   	number   := p_category_id;
319    l_document_id		number := p_document_id;
320    l_seq_num			number;
321    --
322    l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
323    --
324 BEGIN
325 
326 	l_entity_name := Get_Document_Entity(p_entity_code);
327 
328     if (l_category_id IS NULL or l_category_id =  fnd_api.G_MISS_NUM ) then
329         l_category_id := G_DEFAULT_DOC_CATEGORY_ID;
330     end if;
331 
332 
333    -- document ID not passed therfore
334    -- create the short text document and attach to the entity
335    if (l_document_id = fnd_api.G_MISS_NUM OR l_document_id IS NULL) then
336 
337       select (nvl(max(seq_num),0) + 10)
338       into l_seq_num
339       from fnd_attached_documents
340       where entity_name = l_entity_name
341         and pk1_value = to_char(p_entity_id);
342 
343 	FND_WEBATTCH.Add_Attachment
344 		(seq_num				=> l_seq_num
345 		,category_id			=> l_category_id
346 		,document_description	=> p_document_desc
347 		,datatype_id			=> G_DATATYPE_SHORT_TEXT
348 		,text				=> p_document_text
349 		,file_name			=> null
350 		,url					=> null
351 		,function_name			=> null
352 		,entity_name			=> l_entity_name
353 		,pk1_value			=> to_char(p_entity_id)
354 		,pk2_value			=> null
355 		,pk3_value			=> null
356 		,pk4_value			=> null
357 		,pk5_value			=> null
358 		,media_id				=> l_media_id
359 		,user_id				=> FND_GLOBAL.USER_ID
360 		);
361 
362    -- document id passed, just attach the document
363    else
364 
365    	-- attach the document to the entity
366    	Oe_Fnd_Attachments_PVT.Add_Attachment(
367 			p_api_version			=> 1.0,
368 		     p_entity_name			=> l_entity_name,
369 			p_pk1_value			=> to_char(p_entity_id),
370 			p_automatic_flag		=> 'N',
371 			p_document_id 			=> l_document_id,
372 			x_attachment_id 		=> x_attachment_id,
373 			x_return_status		=> x_return_status,
374 			x_msg_count			=> x_msg_count,
375 			x_msg_data			=> x_msg_data
376                );
377 
378    end if;
379 
380 END Add_Attachment;
381 -----------------------------------------------------------------------------
382 
383 
384 END OE_Atchmt_UTIL;