DBA Data[Home] [Help]

PACKAGE BODY: APPS.PO_WF_PO_BUDGET_ACC

Source


1 PACKAGE BODY PO_WF_PO_BUDGET_ACC AS
2 /* $Header: POXWPBAB.pls 115.4 2002/11/22 22:08:09 sbull 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 --
398 
399 /*
400     * Set the debug mode on
401 */
402 
403 PROCEDURE debug_on IS
404 BEGIN
405         debug_acc_generator_wf := TRUE;
406 
407 END debug_on;
408 
409 /*
410     * Set the debug mode off
411 */
412 
413 PROCEDURE debug_off IS
414 BEGIN
415         debug_acc_generator_wf := FALSE;
416 
417 END debug_off;
418 
419 
420 end  PO_WF_PO_BUDGET_ACC;