[Home] [Help]
PACKAGE BODY: APPS.OKE_MILPAC_INTG_WF
Source
1 PACKAGE BODY OKE_MILPAC_INTG_WF AS
2 /* $Header: OKEMIRVB.pls 120.1 2011/02/10 14:12:09 serukull ship $ */
3
4 --
5 -- Global Variables
6 --
7 EventName VARCHAR2(240) := NULL;
8 XmlUrl VARCHAR2(2000):= NULL;
9 --
10 -- Private Procedures and Functions
11 --
12 PROCEDURE GetEventName
13 ( ItemType IN VARCHAR2
14 , ItemKey IN VARCHAR2
15 ) IS
16
17 BEGIN
18
19 EventName := WF_ENGINE.GetItemAttrText
20 ( ItemType => ItemType
21 , ItemKey => ItemKey
22 , AName => 'ECX_EVENT_NAME' );
23
24 END GetEventName;
25
26 PROCEDURE Initialize_DD250
27 ( ItemType IN VARCHAR2
28 , ItemKey IN VARCHAR2
29 ) IS
30
31 CURSOR DeliveryInfo ( C_Form_Header_ID NUMBER ) IS
32 SELECT wd.name
33 , o.name
34 FROM oke_k_form_headers kfh
35 , wsh_deliveries wd
36 , hr_all_organization_units_tl o
37 WHERE kfh.form_header_id = C_Form_Header_ID
38 AND wd.delivery_id = kfh.reference1
39 AND o.organization_id = wd.organization_id
40 AND o.language = userenv('LANG');
41
42 ContractNum VARCHAR2(240) := NULL;
43 OrderNum VARCHAR2(240) := NULL;
44 ShipmentNum VARCHAR2(240) := NULL;
45 Requestor VARCHAR2(30) := NULL;
46 FormHeaderID NUMBER := NULL;
47 DeliveryName VARCHAR2(30) := NULL;
48 ShipFromOrg VARCHAR2(240) := NULL;
49
50 BEGIN
51 --
52 -- Contract Number is stored in Parameter 1
53 --
54 ContractNum := WF_ENGINE.GetItemAttrText
55 ( ItemType => ItemType
56 , ItemKey => ItemKey
57 , AName => 'ECX_PARAMETER1' );
58
59 WF_ENGINE.SetItemAttrText
60 ( ItemType => ItemType
61 , ItemKey => ItemKey
62 , AName => 'CONTRACT_NUM'
63 , AValue => ContractNum );
64
65 --
66 -- Order Number, if any, is stored in Parameter 2
67 --
68 OrderNum := WF_ENGINE.GetItemAttrText
69 ( ItemType => ItemType
70 , ItemKey => ItemKey
71 , AName => 'ECX_PARAMETER2' );
72
73 WF_ENGINE.SetItemAttrText
74 ( ItemType => ItemType
75 , ItemKey => ItemKey
76 , AName => 'ORDER_NUM'
77 , AValue => OrderNum );
78
79 --
80 -- Shipment Number is stored in Parameter 3
81 --
82 ShipmentNum := WF_ENGINE.GetItemAttrText
83 ( ItemType => ItemType
84 , ItemKey => ItemKey
85 , AName => 'ECX_PARAMETER3' );
86
87 WF_ENGINE.SetItemAttrText
88 ( ItemType => ItemType
89 , ItemKey => ItemKey
90 , AName => 'SHIPMENT_NUM'
91 , AValue => ShipmentNum );
92
93 --
94 -- Requestor is stored in Parameter 3
95 --
96 Requestor := WF_ENGINE.GetItemAttrText
97 ( ItemType => ItemType
98 , ItemKey => ItemKey
99 , AName => 'ECX_PARAMETER5' );
100
101 WF_ENGINE.SetItemAttrText
102 ( ItemType => ItemType
103 , ItemKey => ItemKey
104 , AName => 'REQUESTOR'
105 , AValue => Requestor );
106
107 --
108 -- Finally, get Shipping information from the reference column in
109 -- OKE_K_FORM_HEADERS
110 --
111 FormHeaderID := WF_ENGINE.GetItemAttrText
112 ( ItemType => ItemType
113 , ItemKey => ItemKey
114 , AName => 'ECX_DOCUMENT_ID' );
115
116 OPEN DeliveryInfo ( FormHeaderID );
117 FETCH DeliveryInfo INTO DeliveryName , ShipFromOrg;
118 CLOSE DeliveryInfo;
119
120 WF_ENGINE.SetItemAttrText
121 ( ItemType => ItemType
122 , ItemKey => ItemKey
123 , AName => 'DELIVERY_NAME'
124 , AValue => DeliveryName );
125
126 WF_ENGINE.SetItemAttrText
127 ( ItemType => ItemType
128 , ItemKey => ItemKey
129 , AName => 'SHIP_FROM_ORG'
130 , AValue => ShipFromOrg );
131
132
133 END Initialize_DD250;
134
135
136 --
137 -- Public Procedures
138 --
139 PROCEDURE Initialize
140 ( ItemType IN VARCHAR2
141 , ItemKey IN VARCHAR2
142 , ActID IN NUMBER
143 , FuncMode IN VARCHAR2
144 , ResultOut OUT NOCOPY VARCHAR2
145 ) IS
146
147 OutputMimeType VARCHAR2(240);
148
149
150 BEGIN
151
152 OutputMimeType := 'application/vnd.milpac.fex';
153
154 IF ( FuncMode = 'RUN' ) THEN
155 --
156 -- Getting the event name from the Workflow attribute
157 --
158 GetEventName( ItemType , ItemKey );
159
160 --
161 -- The URL should be generic for all types of documents.
162 -- Perform this action before form specific initializations
163 -- so it is possible to override the result on a form-by-form
164 -- basis.
165 --
166
167 XmlUrl := wf_oam_util.getviewXMLURL('ECX_EVENT_MESSAGE',ItemType,ItemKey,OutputMimeType);
168
169 WF_ENGINE.SetItemAttrText
170 ( ItemType => ItemType
171 , ItemKey => ItemKey
172 , AName => 'DOCUMENT_URL'
173 , AValue => XmlUrl
174 );
175
176 IF ( EventName = 'oracle.apps.oke.forms.DD250.Generate' ) THEN
177
178 Initialize_DD250( ItemType , ItemKey );
179
180 END IF;
181
182 ResultOut := 'COMPLETE:';
183 RETURN;
184
185 END IF;
186
187 IF ( FuncMode = 'CANCEL' ) THEN
188 ResultOut := '';
189 RETURN;
190 END IF;
191
192 IF ( FuncMode = 'TIMEOUT' ) THEN
193 ResultOut := '';
194 RETURN;
195 END IF;
196
197 EXCEPTION
198 WHEN OTHERS THEN
199 ResultOut := 'ERROR:';
200 WF_Core.Context
201 ( 'OKE_MILPAC_INTG_WF'
202 , 'INITIALIZE'
203 , ItemType
204 , ItemKey
205 , to_char(ActID)
206 , FuncMode
207 , ResultOut );
208 RAISE;
209
210 END Initialize;
211
212
213 PROCEDURE Create_Attachment
214 ( ItemType IN VARCHAR2
215 , ItemKey IN VARCHAR2
216 , ActID IN NUMBER
217 , FuncMode IN VARCHAR2
218 , ResultOut OUT NOCOPY VARCHAR2
219 ) IS
220
221 RowID VARCHAR2(80);
222 DocumentID NUMBER;
223 MediaID NUMBER;
224 SeqNum NUMBER;
225 FileName VARCHAR2(2000);
226 FormHeaderID NUMBER;
227 FormCreationDate DATE;
228 CategoryID NUMBER;
229 AttachmentDesc VARCHAR2(240);
230
231 CURSOR f IS
232 SELECT form_header_number
233 , print_form_code
234 , k_header_id
235 , fnd_attached_documents_s.nextval attached_document_id
236 FROM oke_k_form_headers
237 WHERE form_header_id = FormHeaderID;
238 frec f%rowtype;
239
240 BEGIN
241
242 IF ( FuncMode = 'RUN' ) THEN
243
244 IF ( WF_ENGINE.GetItemAttrNumber
245 ( ItemType => ItemType
246 , ItemKey => ItemKey
247 , AName => 'ATTACHED_DOCUMENT_ID' ) IS NOT NULL ) THEN
248 ResultOut := 'COMPLETE:';
249 RETURN;
250 END IF;
251
252 FormHeaderID := WF_ENGINE.GetItemAttrText
253 ( ItemType => ItemType
254 , ItemKey => ItemKey
255 , AName => 'ECX_DOCUMENT_ID' );
256
257 FormCreationDate := to_date( WF_ENGINE.GetItemAttrText
258 ( ItemType => ItemType
259 , ItemKey => ItemKey
260 , AName => 'ECX_PARAMETER4' )
261 , 'DDMONRRHH24MISS' );
262
263 FileName := WF_ENGINE.GetItemAttrText
264 ( ItemType => ItemType
265 , ItemKey => ItemKey
266 , AName => 'DOCUMENT_URL' );
267
268 OPEN f;
269 FETCH f INTO frec;
270 CLOSE f;
271
272 SELECT nvl(max(seq_num) , 0) + 1
273 INTO SeqNum
274 FROM fnd_attached_documents
275 WHERE entity_name = 'OKE_K_FORM_HEADERS'
276 AND pk1_value = frec.print_form_code
277 AND pk2_value = to_char(frec.k_header_id)
278 AND pk3_value is null;
279
280 --
281 -- Hardcoded to Miscellaneous for now
282 --
283 CategoryID := 1;
284
285 fnd_message.set_name('OKE' , 'OKE_MILPAC_OUTPUT_DESC');
286 fnd_message.set_token('FORM' , frec.form_header_number);
287 fnd_message.set_token('DATE' , FND_DATE.date_to_displaydt( FormCreationDate,2 ) );
288 AttachmentDesc := fnd_message.get;
289
290 fnd_attached_documents_pkg.insert_row
291 ( X_ROWID => RowID
292 , X_ATTACHED_DOCUMENT_ID => frec.attached_document_id
293 , X_DOCUMENT_ID => DocumentID
294 , X_CREATION_DATE => sysdate
295 , X_CREATED_BY => fnd_global.user_id
296 , X_LAST_UPDATE_DATE => sysdate
297 , X_LAST_UPDATED_BY => fnd_global.user_id
298 , X_LAST_UPDATE_LOGIN => fnd_global.login_id
299 , X_SEQ_NUM => SeqNum
300 , X_ENTITY_NAME => 'OKE_K_FORM_HEADERS'
301 , X_COLUMN1 => NULL
302 , X_PK1_VALUE => frec.print_form_code
303 , X_PK2_VALUE => frec.k_header_id
304 , X_PK3_VALUE => NULL
305 , X_PK4_VALUE => NULL
306 , X_PK5_VALUE => NULL
307 , X_AUTOMATICALLY_ADDED_FLAG => 'Y'
308 , X_DATATYPE_ID => 5
309 , X_CATEGORY_ID => 1
310 , X_SECURITY_TYPE => 4
311 , X_PUBLISH_FLAG => 'Y'
312 , X_USAGE_TYPE => 'O'
313 , X_LANGUAGE => userenv('LANG')
314 , X_DESCRIPTION => AttachmentDesc
315 , X_FILE_NAME => FileName
316 , X_MEDIA_ID => MediaID
317 , X_CREATE_DOC => 'Y'
318 );
319
320 WF_ENGINE.SetItemAttrNumber
321 ( ItemType => ItemType
322 , ItemKey => ItemKey
323 , AName => 'ATTACHED_DOCUMENT_ID'
324 , AValue => frec.attached_document_id
325 );
326
327 ResultOut := 'COMPLETE:';
328 RETURN;
329
330 END IF;
331
332 IF ( FuncMode = 'CANCEL' ) THEN
333 ResultOut := '';
334 RETURN;
335 END IF;
336
337 IF ( FuncMode = 'TIMEOUT' ) THEN
338 ResultOut := '';
339 RETURN;
340 END IF;
341
342 EXCEPTION
343 WHEN OTHERS THEN
344 ResultOut := 'ERROR:';
345 WF_Core.Context
346 ( 'OKE_MILPAC_INTG_WF'
347 , 'CREATE_ATTACHMENT'
348 , ItemType
349 , ItemKey
350 , to_char(ActID)
351 , FuncMode
352 , ResultOut );
353 RAISE;
354
355 END Create_Attachment;
356
357 END OKE_MILPAC_INTG_WF;