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.3 2005/09/14 05:05:58 pchintal noship $ */
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   --<INVCONV R12 START>
118   --call SLA API instead of GML_ACCT_GENERATE */
119   if ( PO_GML_DB_COMMON.check_process_org(x_dest_org_id) = 'Y')
120   then
121 	x_vendor_site_id :=  po_wf_util_pkg.GetItemAttrNumber ( itemtype => itemtype,
122                                                itemkey  => itemkey,
123                                                aname    => 'VENDOR_SITE_ID');
124 	GMF_transaction_accounts_PUB.g_gmf_accts_tab_PUR(1).account_type_code := GMF_transaction_accounts_PUB.G_ACCRUAL_ACCT;
125 	GMF_transaction_accounts_PUB.g_gmf_accts_tab_PUR(1).item_type := '';
126 	GMF_transaction_accounts_PUB.g_gmf_accts_tab_PUR(1).subinventory_type := '';
127 	GMF_transaction_accounts_PUB.g_gmf_accts_tab_PUR(1).organization_id := x_dest_org_id;
128 	GMF_transaction_accounts_PUB.g_gmf_accts_tab_PUR(1).inventory_item_id := x_item_id;
129 	GMF_transaction_accounts_PUB.g_gmf_accts_tab_PUR(1).vendor_site_id := x_vendor_site_id;
130 
131 	GMF_transaction_accounts_PUB.get_accounts(
132                                p_api_version                     => 1.0,
133 				p_init_msg_list			 => dummy,
134 				p_source			 => 'PO',
135 				x_return_status                  => X_status,
136 				x_msg_data			 => x_msg_data,
137 				x_msg_count			 => x_msg_count);
138 	x_account := GMF_transaction_accounts_PUB.g_gmf_accts_tab_PUR(1).target_ccid;
139 
140 /* 	GML_ACCT_GENERATE.GENERATE_OPM_ACCT('ACCRUAL','', '', x_dest_org_id, x_item_id, x_vendor_site_id, x_account); */
141   	po_wf_util_pkg.SetItemAttrNumber  (  itemtype=>itemtype,
142         	                        itemkey=>itemkey,
143                 	                aname=>'TEMP_ACCOUNT_ID',
144                         	        avalue=>x_account );
145   ELSE
146 
147   begin
148 
149      --Bug# 1902716 togeorge 07/25/2001
150      --EAM: if item id is null get the accrual account from po_system_parameters
151      --     (one time items can be delivered to shopfloor with eam)
152      IF x_item_id is not null then
153 	select ap_accrual_account into x_account
154 	from mtl_parameters
155 	where organization_id     = x_dest_org_id;
156      ELSE --treating it as an expense item.
157 	select accrued_code_combination_id into x_account
158   	from po_system_parameters;
159      END IF;
160      --
161 
162   	po_wf_util_pkg.SetItemAttrNumber  (  itemtype=>itemtype,
163         	                        itemkey=>itemkey,
164                 	                aname=>'TEMP_ACCOUNT_ID',
165                         	        avalue=>x_account );
166 
167   exception
168 	when no_data_found then
169 	null;
170   end;
171  END IF;
172  --<INVCONV END>
173 
174   if (x_account IS NOT NULL) then
175 	result := 'COMPLETE:SUCCESS';
176   else
177 	result := 'COMPLETE:FAILURE';
178   end if;
179 
180   return;
181 
182 EXCEPTION
183   WHEN OTHERS THEN
184     wf_core.context('PO_WF_PO_ACCRUAL_ACC','AA_from_org',x_progress);
185         raise;
186 end AA_from_org;
187 
188 -- * ****************************************************************************** *
189 
190 --
191 -- AA_for_expense_item
192 --
193 procedure AA_for_expense_item   ( itemtype        in  varchar2,
194                           	  itemkey         in  varchar2,
195                        	  	  actid           in number,
196                           	  funcmode        in  varchar2,
197                           	  result          out NOCOPY varchar2    )
198 is
199 	x_progress	varchar2(100);
200 	x_dest_org_id	number;
201 	x_item_id	number;
202 	x_account       number;
203         --<INVCONV R12 START>
204 	x_status		varchar2(1);
205 	x_vendor_site_id	number;
206 	x_msg_data      varchar2(2000);
207         --<INVCONV R12 END>
208         x_msg_count     number;
209 	dummy   VARCHAR2(40);
210 	ret     BOOLEAN;
211 
212 begin
213 
214   x_progress := 'PO_WF_PO_ACCRUAL_ACC.AA_for_expense_item: 01';
215   IF (g_po_wf_debug = 'Y') THEN
216      /* DEBUG */  PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
217   END IF;
218 
219 
220   -- Do nothing in cancel or timeout mode
221   --
222   if (funcmode <> wf_engine.eng_run) then
223 
224       result := wf_engine.eng_null;
225       return;
226 
227   end if;
228   --<INVCONV START> -- call SLA API instead of GML_ACCT_GENERATE
229  x_dest_org_id      := po_wf_util_pkg.GetItemAttrNumber ( itemtype => itemtype,
230                                    	              itemkey  => itemkey,
231                             	 	              aname    => 'DESTINATION_ORGANIZATION_ID');
232 
233 --  ret := fnd_installation.get_app_info('GMI', X_status, dummy, dummy);
234 
235   if ( PO_GML_DB_COMMON.check_process_org(x_dest_org_id) = 'Y')
236   then
237   	x_item_id     :=  po_wf_util_pkg.GetItemAttrNumber ( itemtype => itemtype,
238                                    	       itemkey  => itemkey,
239                             	 	       aname    => 'ITEM_ID');
240 	x_vendor_site_id :=  po_wf_util_pkg.GetItemAttrNumber ( itemtype => itemtype,
241                                                itemkey  => itemkey,
242                                                aname    => 'VENDOR_SITE_ID');
243 	GMF_transaction_accounts_PUB.g_gmf_accts_tab_PUR(1).account_type_code := GMF_transaction_accounts_PUB.G_ACCRUAL_ACCT;
244 	GMF_transaction_accounts_PUB.g_gmf_accts_tab_PUR(1).item_type := '';
245 	GMF_transaction_accounts_PUB.g_gmf_accts_tab_PUR(1).subinventory_type := '';
246 	GMF_transaction_accounts_PUB.g_gmf_accts_tab_PUR(1).organization_id := x_dest_org_id;
247 	GMF_transaction_accounts_PUB.g_gmf_accts_tab_PUR(1).inventory_item_id := x_item_id;
248 	GMF_transaction_accounts_PUB.g_gmf_accts_tab_PUR(1).vendor_site_id := x_vendor_site_id;
249 
250 	GMF_transaction_accounts_PUB.get_accounts(
251                                p_api_version                     => 1.0,
252 				p_init_msg_list			 => dummy,
253 				p_source			 => 'PO',
254 				x_return_status                  => X_status,
255 				x_msg_data			 => x_msg_data,
256 				x_msg_count			 => x_msg_count);
257 	x_account := GMF_transaction_accounts_PUB.g_gmf_accts_tab_PUR(1).target_ccid;
258 
259 /*	GML_ACCT_GENERATE.GENERATE_OPM_ACCT('ACCRUAL','', '', x_dest_org_id, x_item_id, x_vendor_site_id, x_account); */
260   	po_wf_util_pkg.SetItemAttrNumber  (  itemtype=>itemtype,
261         	                        itemkey=>itemkey,
262                 	                aname=>'TEMP_ACCOUNT_ID',
263                         	        avalue=>x_account );
264   ELSE
265   --<INVCONV END>
266 
267   begin
268 	select accrued_code_combination_id into x_account
269   	from po_system_parameters;
270 
271   	po_wf_util_pkg.SetItemAttrNumber  (  itemtype=>itemtype,
272         	                        itemkey=>itemkey,
273                 	                aname=>'TEMP_ACCOUNT_ID',
274                         	        avalue=>x_account );
275   exception
276 	when no_data_found then
277 	null;
278   end;
279  END IF;
280 
281   if (x_account IS NOT NULL) then
282 	result := 'COMPLETE:SUCCESS';
283   else
284 	result := 'COMPLETE:FAILURE';
285   end if;
286 
287   RETURN;
288 
289 EXCEPTION
290   WHEN OTHERS THEN
291     wf_core.context('PO_WF_PO_ACCRUAL_ACC','AA_for_expense_item',x_progress);
292         raise;
293 
294 end AA_for_expense_item;
295 
296 -- * ****************************************************************************** *
297 -- * ****************************************************************************** *
298 
299 --
300 -- is_po_project_related
301 --
302 -- This is a dummy function that should be replaced by the customized function
303 -- activity in the workflow that return TRUE or FALSE based on whether you want to
304 -- use the default PO expense accrual account generation rules or use "CUSTOMIZED"
305 -- project accounting rules.
306 
307 procedure is_po_project_related      (  itemtype        in  varchar2,
308                              	        itemkey         in  varchar2,
309 	                     		actid           in number,
310                              		funcmode        in  varchar2,
311                              		result          out NOCOPY varchar2    )
312 is
313 begin
314 
315 	result := 'COMPLETE:F';
316 	return;
317 
318 end is_po_project_related;
319 
320 --
321 
322 --< Shared Proc FPJ Start >
323 
324 ---------------------------------------------------------------------------
325 --Start of Comments
326 --Name: get_SPS_accrual_account
327 --Pre-reqs:
328 --  None.
329 --Modifies:
330 --  Item Attribute: TEMP_ACCOUNT_ID
331 --Locks:
332 --  None.
333 --Function:
334 --  Gets the Accrual Account associated with a given Purchasing Operating Unit.
335 --Parameters:
336 --IN:
337 --  Standard workflow function parameters
338 --OUT:
339 --  Standard workflow function result parameter
340 --Testing:
341 --End of Comments
342 ---------------------------------------------------------------------------
343 PROCEDURE get_SPS_accrual_account(itemtype IN VARCHAR2,
344                                   itemkey  IN VARCHAR2,
345                                   actid    IN NUMBER,
346                                   funcmode IN VARCHAR2,
347                                   result   OUT NOCOPY VARCHAR2)
348 IS
349   l_progress WF_ITEM_ACTIVITY_STATUSES.error_stack%TYPE; -- VARCHAR2(4000)
350   l_purchasing_ou_id HR_ALL_ORGANIZATION_UNITS.organization_id%TYPE;
351   l_account_id GL_CODE_COMBINATIONS.code_combination_id%TYPE;
352 BEGIN
353   l_progress := '010';
354 
355   -- Do nothing in cancel or timeout mode
356   IF (funcmode <> WF_ENGINE.eng_run) THEN
357     result := WF_ENGINE.eng_null;
358     RETURN;
359   END IF;
360 
361   l_progress := '020';
362   l_purchasing_ou_id := PO_WF_UTIL_PKG.GetItemAttrNumber(
363                                     itemtype => itemtype,
364                                     itemkey => itemkey,
365                                     aname => 'PURCHASING_OU_ID');
366 
367   IF (g_po_wf_debug = 'Y') THEN
368     PO_WF_DEBUG_PKG.insert_debug(itemtype, itemkey,
369            'PO_WF_PO_ACCRUAL_ACC.get_SPS_accrual_account ' ||
370            'l_purchasing_ou_id='||l_purchasing_ou_id);
371   END IF;
372 
373   --SQL WHAT: Get the Accrual Account for associated with an OU
374   --SQL WHY:  To potentially default this as the PO Accrual Account for SPS case
375   BEGIN
376     SELECT accrued_code_combination_id
377     INTO l_account_id
378     FROM PO_SYSTEM_PARAMETERS_ALL
379     WHERE org_id = l_purchasing_ou_id;
380   EXCEPTION
381     WHEN NO_DATA_FOUND THEN
382       l_account_id := NULL;
383   END;
384 
385   l_progress := '030';
386 
387   IF (l_account_id IS NULL ) THEN
388     result := WF_ENGINE.eng_completed || ':FAILURE';
389   ELSE
390   	PO_WF_UTIL_PKG.SetItemAttrNumber(itemtype => itemtype,
391         	                    itemkey  => itemkey,
392                 	            aname    => 'TEMP_ACCOUNT_ID',
393                         	    avalue   => l_account_id );
394 
395     result := WF_ENGINE.eng_completed || ':SUCCESS';
396   END IF;
397 
398   l_progress := '040';
399 
400   IF (g_po_wf_debug = 'Y') THEN
401     PO_WF_DEBUG_PKG.insert_debug(itemtype, itemkey,
402            'PO_WF_PO_ACCRUAL_ACC.get_SPS_accrual_account result='||result);
403     PO_WF_DEBUG_PKG.insert_debug(itemtype, itemkey,
404          'PO_WF_PO_ACCRUAL_ACC.get_SPS_accrual_account l_account_id='||
405          l_account_id);
406   END IF;
407 EXCEPTION
408   WHEN OTHERS THEN
409     IF (g_po_wf_debug = 'Y') THEN
410       PO_WF_DEBUG_PKG.insert_debug(itemtype, itemkey,
411          'PO_WF_PO_ACCRUAL_ACC.get_SPS_accrual_account EXCEPTION at '||
412          l_progress);
413     END IF;
414     WF_CORE.context('PO_WF_PO_ACCRUAL_ACC', 'get_SPS_accrual_account',
415                     l_progress);
416     RAISE;
417 END get_SPS_accrual_account;
418 
419 --< Shared Proc FPJ End >
420 
421 end  PO_WF_PO_ACCRUAL_ACC;