DBA Data[Home] [Help]

PACKAGE BODY: APPS.PO_WF_PO_ACCRUAL_ACC

Source


1 PACKAGE BODY PO_WF_PO_ACCRUAL_ACC AS
2 /* $Header: POXWPAAB.pls 120.10 2010/10/25 11:38:20 inagdeo 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  |   POXWPAAB.pls
10  |
11  | DESCRIPTION
12  |   PL/SQL body for package:  PO_WF_PO_ACCRUAL_ACC
13  |
14  | NOTES
15  | MODIFIED    IMRAN ALI (09/08/97) - Created
16  *=====================================================================*/
17 
18 
19 --
20 -- Check Destination Type
21 --
22 procedure destination_type ( itemtype        in  varchar2,
23                              itemkey         in  varchar2,
24 	                     actid           in number,
25                              funcmode        in  varchar2,
26                              result          out NOCOPY varchar2    )
27 is
28 	x_progress              varchar2(100);
29 	x_destination_type	varchar2(25);
30 begin
31 
32   x_progress := 'PO_WF_PO_ACCRUAL_ACC.destination_type: 01';
33   IF (g_po_wf_debug = 'Y') THEN
34      /* DEBUG */  PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
35   END IF;
36 
37 
38   -- Do nothing in cancel or timeout mode
39   --
40   if (funcmode <> wf_engine.eng_run) then
41 
42       result := wf_engine.eng_null;
43       return;
44 
45   end if;
46 
47   x_destination_type := po_wf_util_pkg.GetItemAttrText ( itemtype => itemtype,
48                                    		    itemkey  => itemkey,
49                             	 	            aname    => 'DESTINATION_TYPE_CODE');
50   if x_destination_type = 'EXPENSE' then
51 	result := 'COMPLETE:EXPENSE';
52   elsif x_destination_type = 'INVENTORY' then
53 	result := 'COMPLETE:INVENTORY';
54   elsif x_destination_type = 'SHOP FLOOR' then
55 	result := 'COMPLETE:SHOP_FLOOR';
56   end if;
57 
58   return;
59 
60 EXCEPTION
61   WHEN OTHERS THEN
62     wf_core.context('PO_WF_PO_ACCRUAL_ACC','destination_type',x_progress);
63         raise;
64 end destination_type;
65 
66 -- * ****************************************************************************** *
67 
68 --
69 -- AA_from_org
70 --
71 procedure AA_from_org      ( itemtype        in  varchar2,
72                              itemkey         in  varchar2,
73                     	     actid           in number,
74                              funcmode        in  varchar2,
75                              result          out NOCOPY varchar2    )
76 is
77 	x_progress              varchar2(100);
78 	x_account		number;
79 	x_dest_org_id		number;
80      --Bug# 1902716 togeorge 07/25/2001
81      --EAM: if item id is null get the accrual account from po_system_parameters
82      --     (one time items can be delivered to shopfloor with eam)
83 	x_item_id		number;
84      --
85         --<INVCONV R12 START>
86      	x_status		varchar2(1);
87      	x_vendor_site_id	number;
88 	x_msg_data      varchar2(2000);
89         x_msg_count     number;
90         --<INVCONV R12 END>
91 
92 	dummy   VARCHAR2(40);
93 	ret     BOOLEAN;
94 begin
95 
96   x_progress := 'PO_WF_PO_ACCRUAL_ACC.AA_from_org : 01';
97   IF (g_po_wf_debug = 'Y') THEN
98      /* DEBUG */  PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
99   END IF;
100 
101 
102   -- Do nothing in cancel or timeout mode
103   --
104   if (funcmode <> wf_engine.eng_run) then
105 
106       result := wf_engine.eng_null;
107       return;
108 
109   end if;
110 
111   x_dest_org_id      := po_wf_util_pkg.GetItemAttrNumber ( itemtype => itemtype,
112                                    	              itemkey  => itemkey,
113                             	 	              aname    => 'DESTINATION_ORGANIZATION_ID');
114   x_item_id      := po_wf_util_pkg.GetItemAttrNumber ( itemtype => itemtype,
115                                    	          itemkey  => itemkey,
116                             	 	          aname    => 'ITEM_ID');
117 
118   --Bug 7639037. Uday Phadtare. Commented call to GMF SLA API for process_org because currently
119   --GMF_transaction_accounts_PUB.get_accounts is not getting the account as per SLA setup.
120  /* --<INVCONV R12 START>
121   --call SLA API instead of GML_ACCT_GENERATE
122   if ( PO_GML_DB_COMMON.check_process_org(x_dest_org_id) = 'Y')
123   then
124 	x_vendor_site_id :=  po_wf_util_pkg.GetItemAttrNumber ( itemtype => itemtype,
125                                                itemkey  => itemkey,
126                                                aname    => 'VENDOR_SITE_ID');
127 	GMF_transaction_accounts_PUB.g_gmf_accts_tab_PUR(1).account_type_code := GMF_transaction_accounts_PUB.G_ACCRUAL_ACCT;
128 	GMF_transaction_accounts_PUB.g_gmf_accts_tab_PUR(1).item_type := '';
129 	GMF_transaction_accounts_PUB.g_gmf_accts_tab_PUR(1).subinventory_type := '';
130 	GMF_transaction_accounts_PUB.g_gmf_accts_tab_PUR(1).organization_id := x_dest_org_id;
131 	GMF_transaction_accounts_PUB.g_gmf_accts_tab_PUR(1).inventory_item_id := x_item_id;
132 	GMF_transaction_accounts_PUB.g_gmf_accts_tab_PUR(1).vendor_site_id := x_vendor_site_id;
133 
134 	GMF_transaction_accounts_PUB.get_accounts(
135                                p_api_version                     => 1.0,
136 				p_init_msg_list			 => dummy,
137 				p_source			 => 'PO',
138 				x_return_status                  => X_status,
139 				x_msg_data			 => x_msg_data,
140 				x_msg_count			 => x_msg_count);
141 	x_account := GMF_transaction_accounts_PUB.g_gmf_accts_tab_PUR(1).target_ccid;
142 
143         --GML_ACCT_GENERATE.GENERATE_OPM_ACCT('ACCRUAL','', '', x_dest_org_id, x_item_id, x_vendor_site_id, x_account);
144   	po_wf_util_pkg.SetItemAttrNumber  (  itemtype=>itemtype,
145         	                        itemkey=>itemkey,
146                 	                aname=>'TEMP_ACCOUNT_ID',
147                         	        avalue=>x_account );
148   ELSE
149  */
150   begin
151 
152      --Bug# 1902716 togeorge 07/25/2001
153      --EAM: if item id is null get the accrual account from po_system_parameters
154      --     (one time items can be delivered to shopfloor with eam)
155      IF x_item_id is not null then
156 	select ap_accrual_account into x_account
157 	from mtl_parameters
158 	where organization_id     = x_dest_org_id;
159      ELSE --treating it as an expense item.
160 	select accrued_code_combination_id into x_account
161   	from po_system_parameters;
162      END IF;
163      --
164 
165   	po_wf_util_pkg.SetItemAttrNumber  (  itemtype=>itemtype,
166         	                        itemkey=>itemkey,
167                 	                aname=>'TEMP_ACCOUNT_ID',
168                         	        avalue=>x_account );
169 
170   exception
171 	when no_data_found then
172 	null;
173   end;
174  --END IF; --Bug 7639037
175  --<INVCONV END>
176 
177   if (x_account IS NOT NULL) then
178 	result := 'COMPLETE:SUCCESS';
179   else
180 	result := 'COMPLETE:FAILURE';
181   end if;
182 
183   return;
184 
185 EXCEPTION
186   WHEN OTHERS THEN
187     wf_core.context('PO_WF_PO_ACCRUAL_ACC','AA_from_org',x_progress);
188         raise;
189 end AA_from_org;
190 
191 -- * ****************************************************************************** *
192 
193 --
194 -- AA_for_expense_item
195 --
196 procedure AA_for_expense_item   ( itemtype        in  varchar2,
197                           	  itemkey         in  varchar2,
198                        	  	  actid           in number,
199                           	  funcmode        in  varchar2,
200                           	  result          out NOCOPY varchar2    )
201 is
202 	x_progress	varchar2(100);
203 	x_dest_org_id	number;
204 	x_item_id	number;
205 	x_account       number;
206         --<INVCONV R12 START>
207 	x_status		varchar2(1);
208 	x_vendor_site_id	number;
209 	x_msg_data      varchar2(2000);
210         --<INVCONV R12 END>
211         x_msg_count     number;
212 	dummy   VARCHAR2(40);
213 	ret     BOOLEAN;
214 
215 begin
216 
217   x_progress := 'PO_WF_PO_ACCRUAL_ACC.AA_for_expense_item: 01';
218   IF (g_po_wf_debug = 'Y') THEN
219      /* DEBUG */  PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
220   END IF;
221 
222 
223   -- Do nothing in cancel or timeout mode
224   --
225   if (funcmode <> wf_engine.eng_run) then
226 
227       result := wf_engine.eng_null;
228       return;
229 
230   end if;
231   --<INVCONV START> -- call SLA API instead of GML_ACCT_GENERATE
232  x_dest_org_id      := po_wf_util_pkg.GetItemAttrNumber ( itemtype => itemtype,
233                                    	              itemkey  => itemkey,
234                             	 	              aname    => 'DESTINATION_ORGANIZATION_ID');
235 
236 --  ret := fnd_installation.get_app_info('GMI', X_status, dummy, dummy);
237 
238   --Bug 7639037. Uday Phadtare. Commented call to GMF SLA API for process_org because currently
239   --GMF_transaction_accounts_PUB.get_accounts is not getting the account as per SLA setup.
240  /*
241   if ( PO_GML_DB_COMMON.check_process_org(x_dest_org_id) = 'Y')
242   then
243   	x_item_id     :=  po_wf_util_pkg.GetItemAttrNumber ( itemtype => itemtype,
244                                    	       itemkey  => itemkey,
245                             	 	       aname    => 'ITEM_ID');
246 	x_vendor_site_id :=  po_wf_util_pkg.GetItemAttrNumber ( itemtype => itemtype,
247                                                itemkey  => itemkey,
248                                                aname    => 'VENDOR_SITE_ID');
249 	GMF_transaction_accounts_PUB.g_gmf_accts_tab_PUR(1).account_type_code := GMF_transaction_accounts_PUB.G_ACCRUAL_ACCT;
250 	GMF_transaction_accounts_PUB.g_gmf_accts_tab_PUR(1).item_type := '';
251 	GMF_transaction_accounts_PUB.g_gmf_accts_tab_PUR(1).subinventory_type := '';
252 	GMF_transaction_accounts_PUB.g_gmf_accts_tab_PUR(1).organization_id := x_dest_org_id;
253 	GMF_transaction_accounts_PUB.g_gmf_accts_tab_PUR(1).inventory_item_id := x_item_id;
254 	GMF_transaction_accounts_PUB.g_gmf_accts_tab_PUR(1).vendor_site_id := x_vendor_site_id;
255 
256 	GMF_transaction_accounts_PUB.get_accounts(
257                                p_api_version                     => 1.0,
258 				p_init_msg_list			 => dummy,
259 				p_source			 => 'PO',
260 				x_return_status                  => X_status,
261 				x_msg_data			 => x_msg_data,
262 				x_msg_count			 => x_msg_count);
263 	x_account := GMF_transaction_accounts_PUB.g_gmf_accts_tab_PUR(1).target_ccid;
264 
265         --GML_ACCT_GENERATE.GENERATE_OPM_ACCT('ACCRUAL','', '', x_dest_org_id, x_item_id, x_vendor_site_id, x_account);
266   	po_wf_util_pkg.SetItemAttrNumber  (  itemtype=>itemtype,
267         	                        itemkey=>itemkey,
268                 	                aname=>'TEMP_ACCOUNT_ID',
269                         	        avalue=>x_account );
270   ELSE
271   --<INVCONV END>
272  */
273   begin
274 	select accrued_code_combination_id into x_account
275   	from po_system_parameters;
276 
277   	po_wf_util_pkg.SetItemAttrNumber  (  itemtype=>itemtype,
278         	                        itemkey=>itemkey,
279                 	                aname=>'TEMP_ACCOUNT_ID',
280                         	        avalue=>x_account );
281   exception
282 	when no_data_found then
283 	null;
284   end;
285  --END IF;  --Bug 7639037
286 
287   if (x_account IS NOT NULL) then
288 	result := 'COMPLETE:SUCCESS';
289   else
290 	result := 'COMPLETE:FAILURE';
291   end if;
292 
293   RETURN;
294 
295 EXCEPTION
296   WHEN OTHERS THEN
297     wf_core.context('PO_WF_PO_ACCRUAL_ACC','AA_for_expense_item',x_progress);
298         raise;
299 
300 end AA_for_expense_item;
301 
302 -- * ****************************************************************************** *
303 -- * ****************************************************************************** *
304 
305 --
306 -- is_po_project_related
307 --
308 -- This is a dummy function that should be replaced by the customized function
309 -- activity in the workflow that return TRUE or FALSE based on whether you want to
310 -- use the default PO expense accrual account generation rules or use "CUSTOMIZED"
311 -- project accounting rules.
312 
313 procedure is_po_project_related      (  itemtype        in  varchar2,
314                              	        itemkey         in  varchar2,
315 	                     		actid           in number,
316                              		funcmode        in  varchar2,
317                              		result          out NOCOPY varchar2    )
318 is
319 begin
320 
321 	result := 'COMPLETE:F';
322 	return;
323 
324 end is_po_project_related;
325 
326 --
327 
328 --< Shared Proc FPJ Start >
329 
330 ---------------------------------------------------------------------------
331 --Start of Comments
332 --Name: get_SPS_accrual_account
333 --Pre-reqs:
334 --  None.
335 --Modifies:
336 --  Item Attribute: TEMP_ACCOUNT_ID
337 --Locks:
338 --  None.
339 --Function:
340 --  Gets the Accrual Account associated with a given Purchasing Operating Unit.
341 --Parameters:
342 --IN:
343 --  Standard workflow function parameters
344 --OUT:
345 --  Standard workflow function result parameter
346 --Testing:
347 --End of Comments
348 ---------------------------------------------------------------------------
349 PROCEDURE get_SPS_accrual_account(itemtype IN VARCHAR2,
350                                   itemkey  IN VARCHAR2,
351                                   actid    IN NUMBER,
352                                   funcmode IN VARCHAR2,
353                                   result   OUT NOCOPY VARCHAR2)
354 IS
355   l_progress WF_ITEM_ACTIVITY_STATUSES.error_stack%TYPE; -- VARCHAR2(4000)
356   l_purchasing_ou_id HR_ALL_ORGANIZATION_UNITS.organization_id%TYPE;
357   l_account_id GL_CODE_COMBINATIONS.code_combination_id%TYPE;
358 BEGIN
359   l_progress := '010';
360 
361   -- Do nothing in cancel or timeout mode
362   IF (funcmode <> WF_ENGINE.eng_run) THEN
363     result := WF_ENGINE.eng_null;
364     RETURN;
365   END IF;
366 
367   l_progress := '020';
368   l_purchasing_ou_id := PO_WF_UTIL_PKG.GetItemAttrNumber(
369                                     itemtype => itemtype,
370                                     itemkey => itemkey,
371                                     aname => 'PURCHASING_OU_ID');
372 
373   IF (g_po_wf_debug = 'Y') THEN
374     PO_WF_DEBUG_PKG.insert_debug(itemtype, itemkey,
375            'PO_WF_PO_ACCRUAL_ACC.get_SPS_accrual_account ' ||
376            'l_purchasing_ou_id='||l_purchasing_ou_id);
377   END IF;
378 
379   --SQL WHAT: Get the Accrual Account for associated with an OU
380   --SQL WHY:  To potentially default this as the PO Accrual Account for SPS case
381   BEGIN
382     SELECT accrued_code_combination_id
383     INTO l_account_id
384     FROM PO_SYSTEM_PARAMETERS_ALL
385     WHERE org_id = l_purchasing_ou_id;
386   EXCEPTION
387     WHEN NO_DATA_FOUND THEN
388       l_account_id := NULL;
389   END;
390 
391   l_progress := '030';
392 
393   IF (l_account_id IS NULL ) THEN
394     result := WF_ENGINE.eng_completed || ':FAILURE';
395   ELSE
396   	PO_WF_UTIL_PKG.SetItemAttrNumber(itemtype => itemtype,
397         	                    itemkey  => itemkey,
398                 	            aname    => 'TEMP_ACCOUNT_ID',
399                         	    avalue   => l_account_id );
400 
401     result := WF_ENGINE.eng_completed || ':SUCCESS';
402   END IF;
403 
404   l_progress := '040';
405 
406   IF (g_po_wf_debug = 'Y') THEN
407     PO_WF_DEBUG_PKG.insert_debug(itemtype, itemkey,
408            'PO_WF_PO_ACCRUAL_ACC.get_SPS_accrual_account result='||result);
409     PO_WF_DEBUG_PKG.insert_debug(itemtype, itemkey,
410          'PO_WF_PO_ACCRUAL_ACC.get_SPS_accrual_account l_account_id='||
411          l_account_id);
412   END IF;
413 EXCEPTION
414   WHEN OTHERS THEN
415     IF (g_po_wf_debug = 'Y') THEN
416       PO_WF_DEBUG_PKG.insert_debug(itemtype, itemkey,
417          'PO_WF_PO_ACCRUAL_ACC.get_SPS_accrual_account EXCEPTION at '||
418          l_progress);
419     END IF;
420     WF_CORE.context('PO_WF_PO_ACCRUAL_ACC', 'get_SPS_accrual_account',
421                     l_progress);
422     RAISE;
423 END get_SPS_accrual_account;
424 
425 --< Shared Proc FPJ End >
426 
427 
428 -- Bug 8498318 Added the below procedure to retrieve the FSIO
429 -- Accrual Account if applicable.
430 
431 ---------------------------------------------------------------------------
432 --Start of Comments
433 -- FSIO_AA_FOR_EXPENSE_ITEM
434 --   Get the Accrual Account for EXPENSE destination type from FSIO.
435 --   This holds good only in case FV is installed, else, existing accounts
436 --   will be retained. A call would be made to FV and it will be done using
437 --   dynamic sql. This is done because in case FV is not installed, the procedure
438 --   might not exist. In this case, dynamic call will silently die, does not throw
439 --   any error. We do not RAISE the error in the exception block.
440 -- IN
441 --   itemtype  - A valid item type from (WF_ITEM_TYPES table).
442 --   itemkey   - A string generated by call to AOL's INITIALIZE routine.
443 --   actid     - ID no. of activity this process is called from.
444 --   funcmode  - Run/Cancel
445 -- OUT
446 --   Result
447 --     FAILURE - Account generation failed
448 --     SUCCESS - Account generation successful
449 --End of Comments
450 ---------------------------------------------------------------------------
451  PROCEDURE fsio_aa_for_expense_item
452      (itemtype  IN VARCHAR2,
453       itemkey   IN VARCHAR2,
454       actid     IN NUMBER,
455       funcmode  IN VARCHAR2,
456       result    OUT NOCOPY VARCHAR2)
457  IS
458   x_progress              VARCHAR2(100);
459   x_status                VARCHAR2(1);
460   x_msg_data              VARCHAR2(2000);
461   x_msg_count             NUMBER;
462   x_fsio_accrual_account  NUMBER;
463 
464  BEGIN
465   x_progress := 'PO_WF_PO_ACCRUAL_ACC.fsio_aa_for_expense_item: 01';
466   IF (g_po_wf_debug = 'Y') THEN
467        PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
468   END IF;
469 
470   -- Condition Added for Bug 9890810
471    IF( fv_install.enabled) THEN
472 
473   /* Dynamic Call to FSIO Proc to get the Accrual Account */
474    EXECUTE IMMEDIATE 'BEGIN fv_utility.GET_ACCRUAL_ACCOUNT(:itemtype,:itemkey,:x_fsio_accrual_account); END; '
475      USING IN  itemtype, IN itemkey, OUT x_fsio_accrual_account;
476 
477    END IF;
478 
479   x_progress := 'PO_WF_PO_ACCRUAL_ACC.fsio_aa_for_expense_item: 02';
480   IF (g_po_wf_debug = 'Y') THEN
481        PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
482   END IF;
483 
484   IF (x_fsio_accrual_account IS NOT NULL) THEN
485     po_wf_util_pkg.setitemattrnumber
486            (itemtype => itemtype,
487 	    itemkey => itemkey,
488 	    aname => 'TEMP_ACCOUNT_ID',
489             avalue => x_fsio_accrual_account);
490   END IF;
491 
492   result := wf_engine.eng_completed || ':' || wf_engine.eng_null;
493   RETURN;
494  EXCEPTION
495   WHEN OTHERS THEN
496     wf_core.CONTEXT('PO_WF_PO_ACCRUAL_ACC','FSIO_AA_for_expense_item',
497                     x_progress);
498  END fsio_aa_for_expense_item;
499 
500 end  PO_WF_PO_ACCRUAL_ACC;