[Home] [Help]
PACKAGE BODY: APPS.PO_WF_PO_BUDGET_ACC
Source
1 PACKAGE BODY PO_WF_PO_BUDGET_ACC AS
2 /* $Header: POXWPBAB.pls 120.1 2010/11/26 08:25:35 srkotika ship $ */
3
4 -- Read the profile option that enables/disables the debug log
5 g_po_wf_debug VARCHAR2(1) := NVL(FND_PROFILE.VALUE('PO_SET_DEBUG_WORKFLOW_ON'),'N');
6
7 /*=======================================================================+
8 | FILENAME
9 | POXWPBAB.pls
10 |
11 | DESCRIPTION
12 | PL/SQL body for package: PO_WF_PO_BUDGET_ACC
13 |
14 | NOTES
15 | MODIFIED IMRAN ALI (09/03/97) - Created
16 *=====================================================================*/
17
18 /*
19 * A Global variable to set the debug mode
20 */
21 debug_acc_generator_wf BOOLEAN := FALSE;
22
23 --
24 -- BA_from_item_sub
25 --
26 procedure BA_from_item_sub ( itemtype in varchar2,
27 itemkey in varchar2,
28 actid in number,
29 funcmode in varchar2,
30 result out NOCOPY varchar2 )
31 is
32 x_progress varchar2(100);
33 x_destination_type varchar2(25);
34 x_dest_sub_inv varchar2(25);
35 x_account number;
36 x_item_id number;
37 x_dest_org_id number;
38 begin
39
40 x_progress := 'PO_WF_PO_BUDGET_ACC.BA_from_item_sub: 01';
41 IF (g_po_wf_debug = 'Y') THEN
42 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
43 END IF;
44
45
46 -- Do nothing in cancel or timeout mode
47 --
48 if (funcmode <> wf_engine.eng_run) then
49
50 result := wf_engine.eng_null;
51 return;
52
53 end if;
54
55 x_destination_type := wf_engine.GetItemAttrText ( itemtype => itemtype,
56 itemkey => itemkey,
57 aname => 'DESTINATION_TYPE_CODE');
58
59 x_dest_org_id := wf_engine.GetItemAttrNumber ( itemtype => itemtype,
60 itemkey => itemkey,
61 aname => 'DESTINATION_ORGANIZATION_ID');
62
63 x_dest_sub_inv := wf_engine.GetItemAttrText ( itemtype => itemtype,
64 itemkey => itemkey,
65 aname => 'DESTINATION_SUBINVENTORY');
66
67 x_item_id := wf_engine.GetItemAttrNumber ( itemtype => itemtype,
68 itemkey => itemkey,
69 aname => 'ITEM_ID');
70 /*
71 If (debug_acc_generator_wf) then
72 dbms_output.put_line ('Procedure PO_WF_PO_BUDGET_ACC.BA_from_item_sub');
73 dbms_output.put_line ('DESTINATION_TYPE_CODE: ' || x_destination_type);
74 dbms_output.put_line ('DESTINATION_ORGANIZATION_ID: ' || to_char(x_dest_org_id));
75 dbms_output.put_line ('ITEM_ID: ' || to_char(x_item_id));
76 dbms_output.put_line ('DESTINATION_SUBINVENTORY: ' || x_dest_sub_inv);
77 end if;
78 */
79 if (x_destination_type = 'INVENTORY') and (x_dest_sub_inv IS NOT NULL) then
80
81 Begin
82 select encumbrance_account into x_account
83 from mtl_secondary_inventories
84 where secondary_inventory_name = x_dest_sub_inv
85 and organization_id = x_dest_org_id;
86
87 Exception
88 when no_data_found then
89 null;
90 End;
91
92 if (x_account IS NOT NULL) then
93
94 wf_engine.SetItemAttrNumber ( itemtype=>itemtype,
95 itemkey=>itemkey,
96 aname=>'TEMP_ACCOUNT_ID',
97 avalue=>x_account );
98
99 result := 'COMPLETE:SUCCESS';
100
101 else
102 result := 'COMPLETE:FAILURE';
103 end if;
104
105 else
106 result := 'COMPLETE:FAILURE';
107 end if;
108
109 return;
110
111 EXCEPTION
112 WHEN OTHERS THEN
113 wf_core.context('PO_WF_PO_BUDGET_ACC','BA_from_item_sub',x_progress);
114 raise;
115 end BA_from_item_sub;
116
117 -- * ****************************************************************************** *
118
119 --
120 -- pre_defined_item
121 --
122 procedure pre_defined_item ( itemtype in varchar2,
123 itemkey in varchar2,
124 actid in number,
125 funcmode in varchar2,
126 result out NOCOPY varchar2 )
127 is
128 x_progress varchar2(100);
129 x_item_id number;
130 begin
131
132 x_progress := 'PO_WF_PO_BUDGET_ACC.pre_defined_item: 01';
133 IF (g_po_wf_debug = 'Y') THEN
134 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
135 END IF;
136
137
138 -- Do nothing in cancel or timeout mode
139 --
140 if (funcmode <> wf_engine.eng_run) then
141
142 result := wf_engine.eng_null;
143 return;
144
145 end if;
146
147 x_item_id := wf_engine.GetItemAttrNumber ( itemtype => itemtype,
148 itemkey => itemkey,
149 aname => 'ITEM_ID');
150
151 if (x_item_id is NULL) then
152 result := 'COMPLETE:FALSE';
153 else
154 result := 'COMPLETE:TRUE';
155 end if;
156
157 RETURN;
158
159 EXCEPTION
160 WHEN OTHERS THEN
161 wf_core.context('PO_WF_PO_BUDGET_ACC','pre_defined_item',x_progress);
162 raise;
163
164 end pre_defined_item;
165
166 -- * ****************************************************************************** *
167
168 --
169 -- get_item_BA
170 --
171 procedure get_item_BA ( itemtype in varchar2,
172 itemkey in varchar2,
173 actid in number,
174 funcmode in varchar2,
175 result out NOCOPY varchar2 )
176 is
177 x_progress varchar2(100);
178 x_dest_org_id number;
179 x_item_id number;
180 x_account number;
181 begin
182
183 x_progress := 'PO_WF_PO_BUDGET_ACC.get_item_BA: 01';
184 IF (g_po_wf_debug = 'Y') THEN
185 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
186 END IF;
187
188
189 -- Do nothing in cancel or timeout mode
190 --
191 if (funcmode <> wf_engine.eng_run) then
192
193 result := wf_engine.eng_null;
194 return;
195
196 end if;
197
198 x_dest_org_id := wf_engine.GetItemAttrNumber ( itemtype => itemtype,
199 itemkey => itemkey,
200 aname => 'DESTINATION_ORGANIZATION_ID');
201
202 x_item_id := wf_engine.GetItemAttrNumber ( itemtype => itemtype,
203 itemkey => itemkey,
204 aname => 'ITEM_ID');
205 /*
206 If (debug_acc_generator_wf) then
207 dbms_output.put_line ('Procedure PO_WF_PO_BUDGET_ACC.get_item_BA');
208 dbms_output.put_line ('DESTINATION_ORGANIZATION_ID: ' || to_char(x_dest_org_id));
209 dbms_output.put_line ('ITEM_ID: ' || to_char(x_item_id));
210 end if;
211 */
212 begin
213
214 select encumbrance_account into x_account
215 from MTL_SYSTEM_ITEMS
216 where organization_id = x_dest_org_id
217 and inventory_item_id = x_item_id;
218
219 wf_engine.SetItemAttrNumber ( itemtype=>itemtype,
220 itemkey=>itemkey,
221 aname=>'TEMP_ACCOUNT_ID',
222 avalue=>x_account );
223 exception
224 when no_data_found then
225 null;
226 end;
227
228 if (x_account IS NOT NULL) then
229 result := 'COMPLETE:SUCCESS';
230 else
231 result := 'COMPLETE:FAILURE';
232 end if;
233
234 RETURN;
235
236 EXCEPTION
237 WHEN OTHERS THEN
238 wf_core.context('PO_WF_PO_BUDGET_ACC','get_item_BA',x_progress);
239 raise;
240
241 end get_item_BA;
242
243 -- * ****************************************************************************** *
244
245 --
246 -- get_org_BA
247 --
248 procedure get_org_BA ( itemtype in varchar2,
249 itemkey in varchar2,
250 actid in number,
251 funcmode in varchar2,
252 result out NOCOPY varchar2 )
253 is
254 x_progress varchar2(100);
255 x_dest_org_id number;
256 x_account number;
257 begin
258
259 x_progress := 'PO_WF_PO_BUDGET_ACC.get_org_BA: 01';
260 IF (g_po_wf_debug = 'Y') THEN
261 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
262 END IF;
263
264
265 -- Do nothing in cancel or timeout mode
266 --
267 if (funcmode <> wf_engine.eng_run) then
268
269 result := wf_engine.eng_null;
270 return;
271
272 end if;
273
274 x_dest_org_id := wf_engine.GetItemAttrNumber ( itemtype => itemtype,
275 itemkey => itemkey,
276 aname => 'DESTINATION_ORGANIZATION_ID');
277 /*
278 If (debug_acc_generator_wf) then
279 dbms_output.put_line ('Procedure PO_WF_PO_BUDGET_ACC.get_org_BA');
280 dbms_output.put_line ('DESTINATION_ORGANIZATION_ID: ' || to_char(x_dest_org_id));
281 end if;
282 */
283 begin
284 select encumbrance_account into x_account
285 from mtl_parameters
286 where organization_id = x_dest_org_id;
287
288 exception
289 when no_data_found then
290 null;
291 end;
292
293 if (x_account IS NOT NULL) then
294
295 wf_engine.SetItemAttrNumber ( itemtype=>itemtype,
296 itemkey=>itemkey,
297 aname=>'TEMP_ACCOUNT_ID',
298 avalue=>x_account );
299
300 result := 'COMPLETE:SUCCESS';
301 else
302 result := 'COMPLETE:FAILURE';
303 end if;
304
305 RETURN;
306
307 EXCEPTION
308 WHEN OTHERS THEN
309 wf_core.context('PO_WF_PO_BUDGET_ACC','get_org_BA',x_progress);
310 raise;
311
312 end get_org_BA;
313
314 -- * ****************************************************************************** *
315
316 --
317 -- get_charge_account
318 --
319 procedure get_charge_account ( itemtype in varchar2,
320 itemkey in varchar2,
321 actid in number,
322 funcmode in varchar2,
323 result out NOCOPY varchar2 )
324 is
325 x_progress varchar2(100);
326 x_account number;
327 begin
328
329 x_progress := 'PO_WF_PO_BUDGET_ACC.get_charge_account: 01';
330 IF (g_po_wf_debug = 'Y') THEN
331 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
332 END IF;
333
334
335 -- Do nothing in cancel or timeout mode
336 --
337 if (funcmode <> wf_engine.eng_run) then
338
339 result := wf_engine.eng_null;
340 return;
341
342 end if;
343
344 x_account := wf_engine.GetItemAttrNumber ( itemtype => itemtype,
345 itemkey => itemkey,
346 aname => 'CODE_COMBINATION_ID');
347 /*
348 If (debug_acc_generator_wf) then
349 dbms_output.put_line ('Procedure PO_WF_PO_BUDGET_ACC.get_charge_account');
350 dbms_output.put_line ('CODE_COMBINATION_ID: ' || to_char(x_account));
351 end if;
352 */
353 if (x_account IS NOT NULL) then
354
355 wf_engine.SetItemAttrNumber ( itemtype=>itemtype,
356 itemkey=>itemkey,
357 aname=>'TEMP_ACCOUNT_ID',
358 avalue=>x_account );
359
360 result := 'COMPLETE:SUCCESS';
361 return;
362 else
363 result := 'COMPLETE:FAILURE';
364 return;
365 end if;
366
367 EXCEPTION
368 WHEN OTHERS THEN
369 wf_core.context('PO_WF_PO_BUDGET_ACC','get_charge_account',x_progress);
370 raise;
371
372 end get_charge_account;
373
374 --
375
376 --
377 -- is_po_project_related
378 --
379 -- This is a dummy function that should be replaced by the customized function
380 -- activity in the workflow that return TRUE or FALSE based on whether you want to
381 -- use the default PO budget account generation rules or use "CUSTOMIZED"
382 -- project accounting rules.
383
384 procedure is_po_project_related ( itemtype in varchar2,
385 itemkey in varchar2,
386 actid in number,
387 funcmode in varchar2,
388 result out NOCOPY varchar2 )
389 is
390 begin
391
392 result := 'COMPLETE:F';
393 return;
394
395 end is_po_project_related;
396
397 /* Proc IS_EAM_JOB added for Encumbrance Project */
398
399 PROCEDURE IS_EAM_JOB ( itemtype in varchar2,
400 itemkey in varchar2,
401 actid in NUMBER,
402 funcmode in varchar2,
403 result out NOCOPY VARCHAR2 )
404
405 IS
406 x_wip_entity_type NUMBER;
407 x_progress varchar2(100);
408
409 BEGIN
410
411 x_progress := 'PO_WF_PO_BUDGET_ACC.Is_eam_job: 01';
412
413 IF (g_po_wf_debug = 'Y') THEN
414 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
415 END IF;
416
417
418 -- Do nothing in cancel or timeout mode
419 --
420 if (funcmode <> wf_engine.eng_run) then
421
422 result := wf_engine.eng_null;
423 return;
424
425 end if;
426
427 x_wip_entity_type := po_wf_util_pkg.GetItemAttrText ( itemtype => itemtype,
428 itemkey => itemkey,
429 aname => 'WIP_ENTITY_TYPE');
430
431 if x_wip_entity_type = 6 then
432 result := 'COMPLETE:Y';
433 ELSE
434 result := 'COMPLETE:N';
435 end if;
436
437 return;
438
439 EXCEPTION
440 WHEN OTHERS THEN
441 wf_core.context('PO_WF_PO_BUDGET_ACC','Is_eam_job',x_progress);
442 raise;
443 END IS_EAM_JOB;
444
445
446 /* Proc GET_BA_FOR_SHOP_FLOOR added for Encumbrance project */
447 -- GET_BA_FOR_SHOP_FLOOR
448 -- Get the Budget Account based on Costing API
449 -- IN
450 -- itemtype - A valid item type from (WF_ITEM_TYPES table).
451 -- itemkey - A string generated by call to AOL's INITIALIZE routine.
452 -- actid - ID no. of activity this process is called from.
453 -- funcmode - Run/Cancel
454 -- OUT
455 -- Result
456 -- FAILURE - Account generation failed
457 -- SUCCESS - Account generation successful
458
459
460
461
462 PROCEDURE GET_BA_FOR_SHOP_FLOOR ( itemtype in varchar2,
463 itemkey in varchar2,
464 actid in NUMBER,
465 funcmode in varchar2,
466 result out NOCOPY VARCHAR2 )
467
468 IS
469 x_wip_entity_id NUMBER;
470 x_progress varchar2(100);
471 x_api_version NUMBER DEFAULT 1;
472 x_item_id NUMBER;
473 l_acct NUMBER;
474 l_return_status VARCHAR2(100);
475 l_msg_count NUMBER;
476 l_msg_data VARCHAR2(500);
477
478 BEGIN
479
480 x_progress := 'PO_WF_PO_BUDGET_ACC.get_BA_for_shop_floor: 01';
481 IF (g_po_wf_debug = 'Y') THEN
482 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
483 END IF;
484
485
486 -- Do nothing in cancel or timeout mode
487 --
488 if (funcmode <> wf_engine.eng_run) then
489
490 result := wf_engine.eng_null;
491 return;
492
493 end if;
494
495 x_wip_entity_id := po_wf_util_pkg.GetItemAttrText ( itemtype => itemtype,
496 itemkey => itemkey,
497 aname => 'WIP_ENTITY_ID');
498
499
500 x_item_id := po_wf_util_pkg.GetItemAttrText ( itemtype => itemtype,
501 itemkey => itemkey,
502 aname => 'ITEM_ID');
503
504 -- Calling Costing API
505
506 CST_EAMCOST_PUB.get_account
507 (p_wip_entity_id => x_wip_entity_id,
508 p_item_id => x_item_id,
509 p_account_name => 'ENCUMBRANCE',
510 p_api_version => x_api_version,
511 x_acct => l_acct,
512 x_return_status => l_return_status,
513 x_msg_count => l_msg_count,
514 x_msg_data => l_msg_data );
515
516
517
518 if (l_acct IS NOT NULL) then
519
520 wf_engine.SetItemAttrNumber ( itemtype=>itemtype,
521 itemkey=>itemkey,
522 aname=>'TEMP_ACCOUNT_ID',
523 avalue=>l_acct );
524
525 result := 'COMPLETE:SUCCESS';
526 else
527 result := 'COMPLETE:FAILURE';
528 end if;
529
530
531 RETURN;
532
533 EXCEPTION
534 WHEN OTHERS THEN
535 wf_core.context('PO_WF_PO_BUDGET_ACC','get_BA_for_shop_floor',x_progress);
536 raise;
537
538 END GET_BA_FOR_SHOP_FLOOR;
539
540
541
542 --
543
544 /*
545 * Set the debug mode on
546 */
547
548 PROCEDURE debug_on IS
549 BEGIN
550 debug_acc_generator_wf := TRUE;
551
552 END debug_on;
553
554 /*
555 * Set the debug mode off
556 */
557
558 PROCEDURE debug_off IS
559 BEGIN
560 debug_acc_generator_wf := FALSE;
561
562 END debug_off;
563
564
565 end PO_WF_PO_BUDGET_ACC;