DBA Data[Home] [Help]
Skip to content

PACKAGE BODY: APPS.PO_REQ_WF_BUILD_ACCOUNT_INIT

Source


1 PACKAGE BODY PO_REQ_WF_BUILD_ACCOUNT_INIT AS
2 /* $Header: POXWRQSB.pls 120.4.12020000.2 2013/06/06 14:39:17 gjyothi 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  |   POXWRQSB.pls
10  |
11  | DESCRIPTION
12  |   PL/SQL body for package:  PO_REQ_WF_BUILD_ACCOUNT_INIT
13  |
14  | NOTES        Imran Ali Created 9/9/97
15  | MODIFIED    (MM/DD/YY)	  03/31/98
16  |              David Chan        05/29/98 Modify for bug 669011
17  *=======================================================================*/
18 
19 /*
20     * A Global variable to set the debug mode
21 */
22 debug_acc_generator_wf BOOLEAN := FALSE;
23 
24 /*****************************************************************************
25 * The following are local/Private procedure that support the workflow APIs:  *
26 *****************************************************************************/
27 
28 PROCEDURE Call_WF_API_to_set_Att (ItemType varchar2, ItemKey varchar2,
29 				  aname varchar2, avalue varchar2);
30 PROCEDURE Call_WF_API_to_set_no_Att (ItemType varchar2, ItemKey varchar2,
31 				  aname varchar2, avalue number);
32 PROCEDURE Call_WF_API_to_set_date_Att (ItemType varchar2, ItemKey varchar2,
33 				  aname varchar2, avalue date);
34 
35 
36 /**************************************************************************************
37 * The following are the global APIs.						      *
38 **************************************************************************************/
39 
40 --
41 --  Start_Workflow
42 --  Generates the itemkey, sets up the Item Attributes,
43 --  then starts the workflow process.
44 --
45 FUNCTION Start_Workflow (
46    x_charge_success       IN OUT NOCOPY  BOOLEAN,  x_budget_success        IN OUT NOCOPY   BOOLEAN,
47    x_accrual_success      IN OUT NOCOPY  BOOLEAN,  x_variance_success      IN OUT NOCOPY   BOOLEAN,
48    x_code_combination_id  IN OUT NOCOPY  NUMBER,   x_budget_account_id     IN OUT NOCOPY   NUMBER,
49    x_accrual_account_id   IN OUT NOCOPY  NUMBER,   x_variance_account_id   IN OUT NOCOPY   NUMBER,
50    x_charge_account_flex  IN OUT NOCOPY  VARCHAR2, x_budget_account_flex   IN OUT NOCOPY   VARCHAR2,
51    x_accrual_account_flex IN OUT NOCOPY  VARCHAR2, x_variance_account_flex IN OUT NOCOPY   VARCHAR2,
52    x_charge_account_desc  IN OUT NOCOPY  VARCHAR2, x_budget_account_desc   IN OUT NOCOPY   VARCHAR2,
53    x_accrual_account_desc IN OUT NOCOPY  VARCHAR2, x_variance_account_desc IN OUT NOCOPY   VARCHAR2,
54    x_coa_id                       NUMBER,   x_bom_resource_id                NUMBER,
55    x_bom_cost_element_id          NUMBER,   x_category_id                    NUMBER,
56    x_destination_type_code        VARCHAR2, x_deliver_to_location_id         NUMBER,
57    x_destination_organization_id  NUMBER,   x_destination_subinventory       VARCHAR2,
58    x_expenditure_type             VARCHAR2,
59    x_expenditure_organization_id  NUMBER,   x_expenditure_item_date          DATE,
60    x_item_id                      NUMBER,   x_line_type_id                   NUMBER,
61    x_result_billable_flag         VARCHAR2, x_preparer_id                    NUMBER,
62    x_project_id                   NUMBER,
63    x_document_type_code		  VARCHAR2,
64    x_blanket_po_header_id	  NUMBER,
65    x_source_type_code		  VARCHAR2,
66    x_source_organization_id	  NUMBER,
67    x_source_subinventory	  VARCHAR2,
68    x_task_id                      NUMBER,   x_deliver_to_person_id           NUMBER,
69    x_type_lookup_code             VARCHAR2, x_suggested_vendor_id            NUMBER,
70    x_wip_entity_id                NUMBER,   x_wip_entity_type                VARCHAR2,
71    x_wip_line_id                  NUMBER,   x_wip_repetitive_schedule_id     NUMBER,
72    x_wip_operation_seq_num        NUMBER,   x_wip_resource_seq_num           NUMBER,
73    x_po_encumberance_flag         VARCHAR2, x_gl_encumbered_date             DATE,
74    WF_itemkey		  IN OUT NOCOPY  VARCHAR2, -- because of changes due to WF synch mode this input parameter is not used.
75    x_new_combination	  IN OUT NOCOPY  BOOLEAN,
76 
77    header_att1  VARCHAR2, header_att2   VARCHAR2, header_att3  VARCHAR2, header_att4  VARCHAR2,
78    header_att5  VARCHAR2, header_att6   VARCHAR2, header_att7  VARCHAR2, header_att8  VARCHAR2,
79    header_att9   VARCHAR2, header_att10  VARCHAR2, header_att11  VARCHAR2,
80    header_att12  VARCHAR2, header_att13  VARCHAR2, header_att14  VARCHAR2,header_att15  VARCHAR2,
81 
82    line_att1   VARCHAR2, line_att2   VARCHAR2, line_att3   VARCHAR2, line_att4   VARCHAR2,
83    line_att5   VARCHAR2, line_att6   VARCHAR2, line_att7   VARCHAR2, line_att8   VARCHAR2,
84    line_att9   VARCHAR2, line_att10  VARCHAR2, line_att11  VARCHAR2, line_att12  VARCHAR2,
85    line_att13  VARCHAR2, line_att14  VARCHAR2, line_att15  VARCHAR2,
86 
87    distribution_att1   VARCHAR2, distribution_att2   VARCHAR2, distribution_att3   VARCHAR2,
88    distribution_att4   VARCHAR2, distribution_att5   VARCHAR2, distribution_att6   VARCHAR2,
89    distribution_att7   VARCHAR2, distribution_att8   VARCHAR2, distribution_att9   VARCHAR2,
90    distribution_att10  VARCHAR2, distribution_att11  VARCHAR2, distribution_att12  VARCHAR2,
91    distribution_att13  VARCHAR2, distribution_att14  VARCHAR2, distribution_att15  VARCHAR2,
92 
93    FB_ERROR_MSG               IN OUT NOCOPY VARCHAR2,
94    x_award_id	              NUMBER default NULL, -- OGM_0.0 changes...
95    x_suggested_vendor_site_id NUMBER default NULL, -- B1548597 Common Receiving RVK
96    p_unit_price               IN NUMBER DEFAULT NULL,  --<BUG 3407630>
97    p_blanket_po_line_num      IN NUMBER DEFAULT NULL,   --<BUG 3611341>
98    p_misc_loa IN VARCHAR2 DEFAULT NULL
99 ) RETURN Boolean IS
100 
101 ItemType                varchar2(8);
102 ccid			NUMBER;
103 
104 -- Bug 752384: Increase the size of flexfield to 2000
105 
106 concat_segs		varchar2(2000);
107 concat_ids		varchar2(240);
108 concat_descrs		varchar2(2000);
109 
110 x_block_activity_label  varchar2(60);
111 x_insert_if_new		BOOLEAN := TRUE;
112 x_new_ccid_generated	BOOLEAN := FALSE;
113 x_success		BOOLEAN;
114 x_progress              varchar2(5000);
115 x_appl_short_name       varchar2(40);
116 x_flex_field_code       varchar2(150);
117 x_flex_field_struc_num  number;                        -- x_coa_id
118 
119 was_ccid_passed_in_from_form     BOOLEAN := FALSE;
120 
121 -- PA project accounting parameters to the WF
122 
123   l_class_code			pa_class_codes.class_code%TYPE;
124   l_direct_flag			pa_project_types_all.direct_flag%TYPE;
125   l_expenditure_category	pa_expenditure_categories.expenditure_category%TYPE;
126   l_expenditure_org_name	hr_organization_units.name%TYPE;
127   l_project_number		pa_projects_all.segment1%TYPE;
128   l_project_organization_name	hr_organization_units.name%TYPE;
129   l_project_organization_id	hr_organization_units.organization_id %TYPE;
130   l_project_type		pa_project_types_all.project_type%TYPE;
131 
132   l_public_sector_flag		pa_projects_all.public_sector_flag%TYPE;
133   l_revenue_category		pa_expenditure_types.revenue_category_code%TYPE;
134   -- Bug 16919294 pointing declaration of x_task
135 -- to pa_tasks_expend_v
136   l_task_number			pa_tasks_expend_v.task_number%TYPE;
137   l_task_organization_name	hr_organization_units.name%TYPE;
138   l_task_organization_id	hr_organization_units.organization_id %TYPE;
139   l_task_service_type		pa_tasks.service_type_code%TYPE;
140   l_top_task_id			pa_tasks.task_id%TYPE;
141   -- Bug 16919294 pointing declaration of x_task
142 -- to pa_tasks_expend_v
143   l_top_task_number		pa_tasks_expend_v.task_number%TYPE;
144   l_vendor_employee_id		per_people_f.person_id%TYPE;
145   l_vendor_employee_number	per_people_f.employee_number%TYPE;
146   l_vendor_type			po_vendors.vendor_type_lookup_code%TYPE;
147 
148 BEGIN
149 /*
150   If (debug_acc_generator_wf) then
151  	dbms_output.put_line ('Beginning  Account Generation');
152   end if;
153 */
154 /* Bug 2249061. Added the following code to clear the temporary cache
155                 before calling the workflow so that there will be no
156                 errors in the account generator workflow.
157 */
158 
159 
160   -- Note from bug5075361: We probably don't need to keep the clearcache
161   -- at the beginning of the procedure since they're called at the end
162   -- but it doesn't hurt to keep them anyway
163   WF_ENGINE_UTIL.CLEARCACHE;
164   WF_ACTIVITY.CLEARCACHE;
165   WF_ITEM_ACTIVITY_STATUS.CLEARCACHE;
166   WF_ITEM.CLEARCACHE;
167   WF_PROCESS_ACTIVITY.CLEARCACHE;
168 
169 
170 -- Bug 2249061. Changes End.
171 
172 
173   ItemType := 'POWFRQAG';            -- PO Requisition Account Generator Workflow
174   x_appl_short_name      := 'SQLGL';
175   x_flex_field_code      := 'GL#';
176   x_flex_field_struc_num := x_coa_id;
177 
178   WF_ItemKey := FND_FLEX_WORKFLOW.INITIALIZE (x_appl_short_name, x_flex_field_code, x_flex_field_struc_num, ItemType);
179 
180 /*  If (debug_acc_generator_wf) then dbms_output.put_line ('WF Itemkey is : ' || WF_ItemKey);  end if;
181 */
182 
183   x_progress :=  'ITEM KEY FOR REQ ACCOUNT:' || WF_ItemKey;
184   IF (g_po_wf_debug = 'Y') THEN
185      /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,WF_ItemKey,x_progress);
186   END IF;
187 
188   IF  ( ItemType is not NULL ) AND ( WF_ItemKey is not NULL)  THEN
189         	-- Initialize workflow item attributes
190         	--
191 	IF (x_project_id IS NOT NULL) THEN
192 
193         	-- Calling AP routine to get raw and derived parameters for project accounting accounts.
194 
195 		BEGIN
196 
197 	   	x_progress :=  'Calling pa_acc_gen_wf_pkg.wf_acc_derive_params with project_id:' ||
198 			   to_char(x_project_id);
199 	   	IF (g_po_wf_debug = 'Y') THEN
200    	   	/* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,WF_ItemKey,x_progress);
201 	   	END IF;
202 
203            	pa_acc_gen_wf_pkg.wf_acc_derive_params (p_project_id => x_project_id,
204                 				p_task_id  => x_task_id,
205                 				p_expenditure_type  => x_expenditure_type,
206                 				p_vendor_id  => x_suggested_vendor_id,
207                        				p_expenditure_organization_id => x_expenditure_organization_id,
208                 				p_expenditure_item_date => x_expenditure_item_date,
209                      				x_class_code  => l_class_code,
210                 				x_direct_flag => l_direct_flag,
211                 				x_expenditure_category  => l_expenditure_category,
212                       				x_expenditure_org_name  => l_expenditure_org_name,
213                 				x_project_number  => l_project_number,
214                 				x_project_organization_name => l_project_organization_name,
215                 				x_project_organization_id => l_project_organization_id,
216                 				x_project_type => l_project_type,
217                 				x_public_sector_flag => l_public_sector_flag,
218                 				x_revenue_category => l_revenue_category,
219                 				x_task_number => l_task_number,
220                 				x_task_organization_name => l_task_organization_name,
221                 				x_task_organization_id => l_task_organization_id,
222                 				x_task_service_type => l_task_service_type,
223                 				x_top_task_id => l_top_task_id,
224                 				x_top_task_number => l_top_task_number,
225                 				x_vendor_employee_id => l_vendor_employee_id,
226                 				x_vendor_employee_number => l_vendor_employee_number,
227                 				x_vendor_type => l_vendor_type);
228 		EXCEPTION
229 			when others then
230 			NULL;
231 		END;
232 
233 	   	Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'CLASS_CODE', l_class_code);
234 	   	Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'DIRECT_FLAG', l_direct_flag);
235 	   	Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'EXPENDITURE_CATEGORY', l_expenditure_category);
236 	   	Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'EXPENDITURE_ORG_NAME', l_expenditure_org_name);
237 	   	Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'PROJECT_NUMBER', l_project_number);
238 	   	Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'PROJECT_ORGANIZATION_NAME', l_project_organization_name);
239 	   	Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'PROJECT_ORGANIZATION_ID', l_project_organization_id);
240 	   	Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'PROJECT_TYPE', l_project_type);
241 	   	Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'PUBLIC_SECTOR_FLAG', l_public_sector_flag);
242 	   	Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'REVENUE_CATEGORY', l_revenue_category);
243 	   	Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'TASK_NUMBER', l_task_number);
244 	   	Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'TASK_ORGANIZATION_NAME', l_task_organization_name);
245 	   	Call_WF_API_to_set_no_Att (ItemType, WF_ItemKey, 'TASK_ORGANIZATION_ID', l_task_organization_id);
246 	   	Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'TASK_SERVICE_TYPE', l_task_service_type);
247 	   	Call_WF_API_to_set_no_Att (ItemType, WF_ItemKey, 'TOP_TASK_ID', l_top_task_id);
248 	   	Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'TOP_TASK_NUMBER', l_top_task_number);
249 	   	Call_WF_API_to_set_no_Att (ItemType, WF_ItemKey, 'VENDOR_EMPLOYEE_ID', l_vendor_employee_id);
250 	   	Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'VENDOR_EMPLOYEE_NUMBER', l_vendor_employee_number);
251 	   	Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'VENDOR_TYPE', l_vendor_type);
252 
253                 -- -----------------------------------------------------------------------
254 		-- OGM_0.0 changes . Set award_id into award_set_id item attribute..
255 		-- OGM stores award_set_id into award_id and award_id is derived from
256 		-- award_distribution table.
257 		-- ------------------------------------------------------------------------
258 		IF x_award_id is not NULL then
259 	   		Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'AWARD_SET_ID', x_award_id); -- OGM_0.0 changes...
260 		END IF ;
261 
262 	END IF;
263 
264 	-- done setting AP project accounting attributes.
265 
266 	IF (ItemType IN ('POWFRQBA', 'POWFRQAA', 'POWFRQVA')) THEN
267 	   Call_WF_API_to_set_no_Att (ItemType, WF_ItemKey, 'CODE_COMBINATION_ID', x_code_combination_id);
268      	END IF;
269 
270     	IF (ItemType IN ('POWFRQAA', 'POWFRQVA')) THEN
271 	   Call_WF_API_to_set_no_Att (ItemType, WF_ItemKey, 'BUDGET_ACCOUNT_ID', x_budget_account_id);
272     	END IF;
273 
274     	IF (ItemType IN ('POWFRQVA')) THEN
275 	   Call_WF_API_to_set_no_Att (ItemType, WF_ItemKey, 'ACCRUAL_ACCOUNT_ID', x_accrual_account_id);
276     	END IF;
277 
278 	Call_WF_API_to_set_no_Att (ItemType, WF_ItemKey, 'CHART_OF_ACCOUNTS_ID', x_coa_id);
279 	Call_WF_API_to_set_no_Att (ItemType, WF_ItemKey, 'BOM_COST_ELEMENT_ID', x_bom_cost_element_id);
280 	Call_WF_API_to_set_no_Att (ItemType, WF_ItemKey, 'BOM_RESOURCE_ID', x_bom_resource_id);
281 	Call_WF_API_to_set_no_Att (ItemType, WF_ItemKey, 'CATEGORY_ID', x_category_id);
282 	Call_WF_API_to_set_no_Att (ItemType, WF_ItemKey, 'DELIVER_TO_LOCATION_ID', x_deliver_to_location_id);
283 	Call_WF_API_to_set_no_Att (ItemType, WF_ItemKey, 'DESTINATION_ORGANIZATION_ID',
284 							x_destination_organization_id);
285 	Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'DESTINATION_SUBINVENTORY',
286 							x_destination_subinventory);
287 
288 	Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'DESTINATION_TYPE_CODE', x_destination_type_code);
289 
290 	wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
291         	                       itemkey    =>  WF_ItemKey,
292                 	               aname      =>  'PO_ENCUMBRANCE_FLAG',
293                         	       avalue     =>  x_po_encumberance_flag );
294 
295 -- Header
296 
297 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'HEADER_ATT1',  header_att1);
298 	If header_att1 is not null then
299 	   begin
300 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
301         	                               itemkey    =>  WF_ItemKey,
302                 	                       aname      =>  'HEADER_ATT1',
303                         	               avalue     =>  header_att1 );
304 	   exception when others then
305 		null;
306 	   end;
307 	end if;
308 
309 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'HEADER_ATT2',  header_att2);
310 	If header_att2 is not null then
311 	   begin
312 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
313         	                               itemkey    =>  WF_ItemKey,
314                 	                       aname      =>  'HEADER_ATT2',
315                         	               avalue     =>  header_att2 );
316 	   exception  when others then
317 		null;
318 	   end;
319 	end if;
320 
321 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'HEADER_ATT3',  header_att3);
322 	If header_att3 is not null then
323 	   begin
324 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
325         	                               itemkey    =>  WF_ItemKey,
326                 	                       aname      =>  'HEADER_ATT3',
327                         	               avalue     =>  header_att3 );
328 	   exception  when others then
329 		null;
330 	   end;
331 	end if;
332 
333 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'HEADER_ATT4',  header_att4);
334 	If header_att4 is not null then
335 	   begin
336 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
337         	                               itemkey    =>  WF_ItemKey,
338                 	                       aname      =>  'HEADER_ATT4',
339                         	               avalue     =>  header_att4 );
340 	   exception  when others then
341 		null;
342 	   end;
343 	end if;
344 
345 	-- Call_WF_API_to_set_Att (ItemType, ItemKey, 'HEADER_ATT5',  header_att5);
346 	If header_att5 is not null then
347 	   begin
348 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
349         	                               itemkey    =>  WF_ItemKey,
350                 	                       aname      =>  'HEADER_ATT5',
351                         	               avalue     =>  header_att5 );
352 	   exception  when others then
353 		null;
354 	   end;
355 	end if;
356 
357 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'HEADER_ATT6',  header_att6);
358 	If header_att6 is not null then
359 	   begin
360 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
361         	                               itemkey    =>  WF_ItemKey,
362                 	                       aname      =>  'HEADER_ATT6',
363                         	               avalue     =>  header_att6 );
364 	   exception  when others then
365 		null;
366 	   end;
367 	end if;
368 
369 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'HEADER_ATT7',  header_att7);
370 	If header_att7 is not null then
371 	   begin
372 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
373         	                               itemkey    =>  WF_ItemKey,
374                 	                       aname      =>  'HEADER_ATT7',
375                         	               avalue     =>  header_att7 );
376 	   exception  when others then
377 		null;
378 	   end;
379 	end if;
380 
381 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'HEADER_ATT8',  header_att8);
382 	If header_att8 is not null then
383 	   begin
384 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
385         	                               itemkey    =>  WF_ItemKey,
386                 	                       aname      =>  'HEADER_ATT8',
387                         	               avalue     =>  header_att8 );
388 	   exception  when others then
389 		null;
390 	   end;
391 	end if;
392 
393 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'HEADER_ATT9',  header_att9);
394 	If header_att9 is not null then
395 	   begin
396 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
397         	                               itemkey    =>  WF_ItemKey,
398                 	                       aname      =>  'HEADER_ATT9',
399                         	               avalue     =>  header_att9 );
400 	   exception  when others then
401 		null;
402 	   end;
403 	end if;
404 
405 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'HEADER_ATT10', header_att10);
406 	If header_att10 is not null then
407 	   begin
408 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
409         	                               itemkey    =>  WF_ItemKey,
410                 	                       aname      =>  'HEADER_ATT10',
411                         	               avalue     =>  header_att10 );
412 	   exception  when others then
413 		null;
414 	   end;
415 	end if;
416 
417 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'HEADER_ATT11', header_att11);
418 	If header_att11 is not null then
419 	   begin
420 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
421         	                               itemkey    =>  WF_ItemKey,
422                 	                       aname      =>  'HEADER_ATT11',
423                         	               avalue     =>  header_att11 );
424 	   exception  when others then
425 		null;
426 	   end;
427 	end if;
428 
429 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'HEADER_ATT12', header_att12);
430 	If header_att12 is not null then
431 	   begin
432 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
433         	                               itemkey    =>  WF_ItemKey,
434                 	                       aname      =>  'HEADER_ATT12',
435                         	               avalue     =>  header_att12 );
436 	   exception  when others then
437 		null;
438 	   end;
439 	end if;
440 
441 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'HEADER_ATT13', header_att13);
442 	If header_att13 is not null then
443 	   begin
444 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
445         	                               itemkey    =>  WF_ItemKey,
446                 	                       aname      =>  'HEADER_ATT13',
447                         	               avalue     =>  header_att13 );
448 	   exception  when others then
449 		null;
450 	   end;
451 	end if;
452 
453 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'HEADER_ATT14', header_att14);
454 	If header_att14 is not null then
455 	   begin
456 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
457         	                               itemkey    =>  WF_ItemKey,
458                 	                       aname      =>  'HEADER_ATT14',
459                         	               avalue     =>  header_att14 );
460 	   exception  when others then
461 		null;
462 	   end;
463 	end if;
464 
465 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'HEADER_ATT15', header_att15);
466 	If header_att15 is not null then
467 	   begin
468 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
469         	                               itemkey    =>  WF_ItemKey,
470                 	                       aname      =>  'HEADER_ATT15',
471                         	               avalue     =>  header_att15 );
472 	   exception  when others then
473 		null;
474 	   end;
475 	end if;
476 
477 -- Line
478 
479 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'LINE_ATT1',  line_att1);
480 	If line_att1 is not null then
481 	   begin
482 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
483         	                               itemkey    =>  WF_ItemKey,
484                 	                       aname      =>  'LINE_ATT1',
485                         	               avalue     =>  line_att1 );
486 	   exception  when others then
487 		null;
488 	   end;
489 	end if;
490 
491 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'LINE_ATT2',  line_att2);
492 	If line_att2 is not null then
493 	   begin
494 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
495         	                               itemkey    =>  WF_ItemKey,
496                 	                       aname      =>  'LINE_ATT2',
497                         	               avalue     =>  line_att2 );
498 	   exception  when others then
499 		null;
500 	   end;
501 	end if;
502 
503 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'LINE_ATT3',  line_att3);
504 	If line_att3 is not null then
505 	   begin
506 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
507         	                               itemkey    =>  WF_ItemKey,
508                 	                       aname      =>  'LINE_ATT3',
509                         	               avalue     =>  line_att3 );
510 	   exception  when others then
511 		null;
512 	   end;
513 	end if;
514 
515 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'LINE_ATT4',  line_att4);
516 	If line_att4 is not null then
517 	   begin
518 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
519         	                               itemkey    =>  WF_ItemKey,
520                 	                       aname      =>  'LINE_ATT4',
521                         	               avalue     =>  line_att4 );
522 	   exception  when others then
523 		null;
524 	   end;
525 	end if;
526 
527 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'LINE_ATT5',  line_att5);
528 	If line_att5 is not null then
529 	   begin
530 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
531         	                               itemkey    =>  WF_ItemKey,
532                 	                       aname      =>  'LINE_ATT5',
533                         	               avalue     =>  line_att5 );
534 	   exception  when others then
535 		null;
536 	   end;
537 	end if;
538 
539 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'LINE_ATT6',  line_att6);
540 	If line_att6 is not null then
541 	   begin
542 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
543         	                               itemkey    =>  WF_ItemKey,
544                 	                       aname      =>  'LINE_ATT6',
545                         	               avalue     =>  line_att6 );
546 	   exception  when others then
547 		null;
548 	   end;
549 	end if;
550 
551 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'LINE_ATT7',  line_att7);
552 	If line_att7 is not null then
553 	   begin
554 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
555         	                               itemkey    =>  WF_ItemKey,
556                 	                       aname      =>  'LINE_ATT7',
557                         	               avalue     =>  line_att7 );
558 	   exception  when others then
559 		null;
560 	   end;
561 	end if;
562 
563 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'LINE_ATT8',  line_att8);
564 	If line_att8 is not null then
565 	   begin
566 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
567         	                               itemkey    =>  WF_ItemKey,
568                 	                       aname      =>  'LINE_ATT8',
569                         	               avalue     =>  line_att8 );
570 	   exception  when others then
571 		null;
572 	   end;
573 	end if;
574 
575 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'LINE_ATT9',  line_att9);
576 	If line_att9 is not null then
577 	   begin
578 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
579         	                               itemkey    =>  WF_ItemKey,
580                 	                       aname      =>  'LINE_ATT9',
581                         	               avalue     =>  line_att9 );
582 	   exception  when others then
583 		null;
584 	   end;
585 	end if;
586 
587 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'LINE_ATT10', line_att10);
588 	If line_att10 is not null then
589 	   begin
590 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
591         	                               itemkey    =>  WF_ItemKey,
592                 	                       aname      =>  'LINE_ATT10',
593                         	               avalue     =>  line_att10 );
594 	   exception  when others then
595 		null;
596 	   end;
597 	end if;
598 
599 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'LINE_ATT11', line_att11);
600 	If line_att11 is not null then
601 	   begin
602 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
603         	                               itemkey    =>  WF_ItemKey,
604                 	                       aname      =>  'LINE_ATT11',
605                         	               avalue     =>  line_att11 );
606 	   exception  when others then
607 		null;
608 	   end;
609 	end if;
610 
611 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'LINE_ATT12', line_att12);
612 	If line_att12 is not null then
613 	   begin
614 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
615         	                               itemkey    =>  WF_ItemKey,
616                 	                       aname      =>  'LINE_ATT12',
617                         	               avalue     =>  line_att12 );
618 	   exception  when others then
619 		null;
620 	   end;
621 	end if;
622 
623 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'LINE_ATT13', line_att13);
624 	If line_att13 is not null then
625 	   begin
626 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
627         	                               itemkey    =>  WF_ItemKey,
628                 	                       aname      =>  'LINE_ATT13',
629                         	               avalue     =>  line_att13 );
630 	   exception  when others then
631 		null;
632 	   end;
633 	end if;
634 
635 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'LINE_ATT14', line_att14);
636 	If line_att14 is not null then
637 	   begin
638 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
639         	                               itemkey    =>  WF_ItemKey,
640                 	                       aname      =>  'LINE_ATT14',
641                         	               avalue     =>  line_att14 );
642 	   exception  when others then
643 		null;
644 	   end;
645 	end if;
646 
647 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'LINE_ATT15', line_att15);
648 	If line_att15 is not null then
649 	   begin
650 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
651         	                               itemkey    =>  WF_ItemKey,
652                 	                       aname      =>  'LINE_ATT15',
653                         	               avalue     =>  line_att15 );
654 	   exception  when others then
655 		null;
656 	   end;
657 	end if;
658 
659 -- Distribution
660 
661 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'DISTRIBUTION_ATT1',  distribution_att1);
662 	If distribution_att1 is not null then
663 	   begin
664 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
665         	                               itemkey    =>  WF_ItemKey,
666                 	                       aname      =>  'DISTRIBUTION_ATT1',
667                         	               avalue     =>  distribution_att1 );
668 	   exception  when others then
669 		null;
670 	   end;
671 	end if;
672 
673 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'DISTRIBUTION_ATT2',  distribution_att2);
674 	If distribution_att2 is not null then
675 	   begin
676 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
677         	                               itemkey    =>  WF_ItemKey,
678                 	                       aname      =>  'DISTRIBUTION_ATT2',
679                         	               avalue     =>  distribution_att2 );
680 	   exception  when others then
681 		null;
682 	   end;
683 	end if;
684 
685 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'DISTRIBUTION_ATT3',  distribution_att3);
686 	If distribution_att3 is not null then
687 	   begin
688 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
689         	                               itemkey    =>  WF_ItemKey,
690                 	                       aname      =>  'DISTRIBUTION_ATT3',
691                         	               avalue     =>  distribution_att3 );
692 	   exception  when others then
693 		null;
694 	   end;
695 	end if;
696 
697 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'DISTRIBUTION_ATT4',  distribution_att4);
698 	If distribution_att4 is not null then
699 	   begin
700 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
701         	                               itemkey    =>  WF_ItemKey,
702                 	                       aname      =>  'DISTRIBUTION_ATT4',
703                         	               avalue     =>  distribution_att4 );
704 	   exception  when others then
705 		null;
706 	   end;
707 	end if;
708 
709 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'DISTRIBUTION_ATT5',  distribution_att5);
710 	If distribution_att5 is not null then
711 	   begin
712 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
713         	                               itemkey    =>  WF_ItemKey,
714                 	                       aname      =>  'DISTRIBUTION_ATT5',
715                         	               avalue     =>  distribution_att5 );
716 	   exception  when others then
717 		null;
718 	   end;
719 	end if;
720 
721 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'DISTRIBUTION_ATT6',  distribution_att6);
722 	If distribution_att6 is not null then
723 	   begin
724 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
725         	                               itemkey    =>  WF_ItemKey,
726                 	                       aname      =>  'DISTRIBUTION_ATT6',
727                         	               avalue     =>  distribution_att6 );
728 	   exception  when others then
729 		null;
730 	   end;
731 	end if;
732 
733 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'DISTRIBUTION_ATT7',  distribution_att7);
734 	If distribution_att7 is not null then
735 	   begin
736 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
737         	                               itemkey    =>  WF_ItemKey,
738                 	                       aname      =>  'DISTRIBUTION_ATT7',
739                         	               avalue     =>  distribution_att7 );
740 	   exception  when others then
741 		null;
742 	   end;
743 	end if;
744 
745 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'DISTRIBUTION_ATT8',  distribution_att8);
746 	If distribution_att8 is not null then
747 	   begin
748 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
749         	                               itemkey    =>  WF_ItemKey,
750                 	                       aname      =>  'DISTRIBUTION_ATT8',
751                         	               avalue     =>  distribution_att8 );
752 	   exception  when others then
753 		null;
754 	   end;
755 	end if;
756 
757 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'DISTRIBUTION_ATT9',  distribution_att9);
758 	If distribution_att9 is not null then
759 	   begin
760 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
761         	                               itemkey    =>  WF_ItemKey,
762                 	                       aname      =>  'DISTRIBUTION_ATT9',
763                         	               avalue     =>  distribution_att9 );
764 	   exception  when others then
765 		null;
766 	   end;
767 	end if;
768 
769 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'DISTRIBUTION_ATT10', distribution_att10);
770 	If distribution_att10 is not null then
771 	   begin
772 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
773         	                               itemkey    =>  WF_ItemKey,
774                 	                       aname      =>  'DISTRIBUTION_ATT10',
775                         	               avalue     =>  distribution_att10 );
776 	   exception  when others then
777 		null;
778 	   end;
779 	end if;
780 
781 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'DISTRIBUTION_ATT11', distribution_att11);
782 	If distribution_att11 is not null then
783 	   begin
784 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
785         	                               itemkey    =>  WF_ItemKey,
786                 	                       aname      =>  'DISTRIBUTION_ATT11',
787                         	               avalue     =>  distribution_att11 );
788 	   exception  when others then
789 		null;
790 	   end;
791 	end if;
792 
793 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'DISTRIBUTION_ATT12', distribution_att12);
794 	If distribution_att12 is not null then
795 	   begin
796 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
797         	                               itemkey    =>  WF_ItemKey,
798                 	                       aname      =>  'DISTRIBUTION_ATT12',
799                         	               avalue     =>  distribution_att12 );
800 	   exception  when others then
801 		null;
802 	   end;
803 	end if;
804 
805 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'DISTRIBUTION_ATT13', distribution_att13);
806 	If distribution_att13 is not null then
807 	   begin
808 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
809         	                               itemkey    =>  WF_ItemKey,
810                 	                       aname      =>  'DISTRIBUTION_ATT13',
811                         	               avalue     =>  distribution_att13 );
812 	   exception  when others then
813 		null;
814 	   end;
815 	end if;
816 
817 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'DISTRIBUTION_ATT14', distribution_att14);
818 	If distribution_att14 is not null then
819 	   begin
820 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
821         	                               itemkey    =>  WF_ItemKey,
822                 	                       aname      =>  'DISTRIBUTION_ATT14',
823                         	               avalue     =>  distribution_att14 );
824 	   exception  when others then
825 		null;
826 	   end;
827 	end if;
828 
829 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'DISTRIBUTION_ATT15', distribution_att15);
830 	If distribution_att15 is not null then
831 	   begin
832 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
833         	                               itemkey    =>  WF_ItemKey,
834                 	                       aname      =>  'DISTRIBUTION_ATT15',
835                         	               avalue     =>  distribution_att15 );
836 	   exception  when others then
837 		null;
838 	   end;
839 	end if;
840 
841 	/* Added by sjanakir for Fed Fields */
842 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'CLM_MISC_LOA', p_misc_loa);
843 	If p_misc_loa is not null then
844 	   begin
845 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
846         	                               itemkey    =>  WF_ItemKey,
847                 	                       aname      =>  'CLM_MISC_LOA',
848                         	               avalue     =>  p_misc_loa );
849 	   exception  when others then
850 		null;
851 	   end;
852 	end if;
853 
854 
855 	Call_WF_API_to_set_date_Att (ItemType, WF_ItemKey, 'EXPENDITURE_ITEM_DATE', x_expenditure_item_date);
856 	Call_WF_API_to_set_no_Att (ItemType, WF_ItemKey, 'EXPENDITURE_ORGANIZATION_ID',
857 							x_expenditure_organization_id);
858 	Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'EXPENDITURE_TYPE', x_expenditure_type);
859 	Call_WF_API_to_set_no_Att (ItemType, WF_ItemKey, 'ITEM_ID', x_item_id);
860 	Call_WF_API_to_set_no_Att (ItemType, WF_ItemKey, 'LINE_TYPE_ID', x_line_type_id);
861 	Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'PA_BILLABLE_FLAG', x_result_billable_flag);
862 
863 	Call_WF_API_to_set_no_Att (ItemType, WF_ItemKey, 'PREPARER_ID', x_preparer_id);
864 	Call_WF_API_to_set_no_Att (ItemType, WF_ItemKey, 'PROJECT_ID', x_project_id);
865 
866 	Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'DOCUMENT_TYPE_CODE', x_document_type_code);
867 	Call_WF_API_to_set_no_Att (ItemType, WF_ItemKey, 'BLANKET_PO_HEADER_ID', x_blanket_po_header_id);
868 	Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'SOURCE_TYPE_CODE', x_source_type_code);
869 	Call_WF_API_to_set_no_Att (ItemType, WF_ItemKey, 'SOURCE_ORGANIZATION_ID',
870 							x_source_organization_id);
871 	Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'SOURCE_SUBINVENTORY', x_source_subinventory);
872 
873 	Call_WF_API_to_set_no_Att (ItemType, WF_ItemKey, 'TASK_ID', x_task_id);
874 	Call_WF_API_to_set_no_Att (ItemType, WF_ItemKey, 'TO_PERSON_ID', x_deliver_to_person_id);
875 	Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'TYPE_LOOKUP_CODE', x_type_lookup_code);
876 	Call_WF_API_to_set_no_Att (ItemType, WF_ItemKey, 'SUGGESTED_VENDOR_ID', x_suggested_vendor_id);
877 	Call_WF_API_to_set_no_Att (ItemType, WF_ItemKey, 'VENDOR_SITE_ID', x_suggested_vendor_site_id); /* B1548597 Common Receiving RVK */
878 	Call_WF_API_to_set_no_Att (ItemType, WF_ItemKey, 'WIP_ENTITY_ID', x_wip_entity_id);
879 
880 
881 	Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'WIP_ENTITY_TYPE', x_wip_entity_type);
882 	Call_WF_API_to_set_no_Att (ItemType, WF_ItemKey, 'WIP_LINE_ID', x_wip_line_id );
883 	Call_WF_API_to_set_no_Att (ItemType, WF_ItemKey, 'WIP_OPERATION_SEQ_NUM', x_wip_operation_seq_num);
884 	Call_WF_API_to_set_no_Att (ItemType, WF_ItemKey, 'WIP_REPETITIVE_SCHEDULE_ID',
885 							x_wip_repetitive_schedule_id);
886 	Call_WF_API_to_set_no_Att (ItemType, WF_ItemKey, 'WIP_RESOURCE_SEQ_NUM', x_wip_resource_seq_num);
887 
888         --<BUG 3407630 START>
889         --Call WF API to set unit_price attribute.
890         --unit_price will be taken into consideration when generating accounts.
891 
892         PO_WF_UTIL_PKG.SetItemAttrNumber (itemtype   =>  itemtype,
893         	                          itemkey    =>  wf_itemkey,
894                 	                  aname      =>  'UNIT_PRICE',
895                         	          avalue     =>  p_unit_price);
896 
897    	IF (g_po_wf_debug = 'Y') THEN
898           PO_WF_DEBUG_PKG.insert_debug(itemtype,
899                                        wf_itemkey,
900                                        'Set WF item UNIT_PRICE to ' ||
901                                         PO_WF_UTIL_PKG.GetItemAttrNumber (
902                                                   itemtype   =>  itemtype,
903         	                                  itemkey    =>  wf_itemkey,
904                 	                          aname      =>  'UNIT_PRICE'));
905 	END IF;
906         --<BUG 3407630 END>
907 
908         --<BUG 3611341 START>
909         -- Call WF API to set blanket_po_line_num attribute.
910         -- blanket_po_line_num will be taken into consideration when generating accounts.
911         PO_WF_UTIL_PKG.SetItemAttrNumber(itemtype => itemtype,
912                                          itemkey  => wf_itemkey,
913                                          aname    => 'BLANKET_PO_LINE_NUM',
914                                          avalue   => p_blanket_po_line_num);
915 
916         IF (g_po_wf_debug = 'Y') THEN
917           PO_WF_DEBUG_PKG.insert_debug(itemtype, wf_itemkey,
918                                        'Set WF item BLANKET_PO_LINE_NUM to ' ||
919                                        PO_WF_UTIL_PKG.GetItemAttrNumber(
920                                        itemtype => itemtype,
921                                        itemkey  => wf_itemkey,
922                                        aname    => 'BLANKET_PO_LINE_NUM'));
923         END IF;
924         --<BUG 3611341 END>
925 
926 
927 	-- Done setting WF item attributes
928 
929 	if x_code_combination_id is null then
930 
931            x_progress :=  'FND_FLEX_WORKFLOW.GENERATE: Before call';
932            IF (g_po_wf_debug = 'Y') THEN
933               /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,WF_ItemKey,x_progress);
934            END IF;
935 
936 /*	   If (debug_acc_generator_wf) then  dbms_output.put_line ('Calling generate to build Charge Account'); end if;
937 */
938 
939 	   x_block_activity_label := NULL;
940 
941            -- Bug 1497909 : Set the encumbrance date for validation
942            po_wf_util_pkg.SetItemAttrDate(itemtype   =>  itemtype,
943                                         itemkey    =>  wf_itemkey,
944                                         aname      =>  'ENCUMBRANCE_DATE',
945                                         avalue     =>  x_gl_encumbered_date);
946 
947 	   x_success := FND_FLEX_WORKFLOW.GENERATE_PARTIAL ( ItemType,
948 						  	  WF_ItemKey,
949 							  'DEFAULT_CHARGE_ACC_GENERATION',
950 							  x_block_activity_label,
951 							  x_insert_if_new,
952 						  	  ccid,
953 						  	  concat_segs,
954 						  	  concat_ids,
955 						  	  concat_descrs,
956 						  	  FB_ERROR_MSG,
957 							  x_new_combination );
958 
959 	   if (x_success  and ( ccid is null or ccid = 0 or ccid = -1 )) then
960 
961 		-- Complete the blocked workflow as it may be running in synch mode and cause problems for consequent
962 		-- account generation runs for this session.
963 		begin
964 			wf_engine.CompleteActivity(itemtype, wf_itemkey, 'BLOCK_BUDGET_ACC_GENERATION', 'FAILURE');
965 		exception
966 			when others then
967 			IF (g_po_wf_debug = 'Y') THEN
968    			PO_WF_DEBUG_PKG.insert_debug(itemtype,wf_itemkey,'Exception when completing WF' ||  Wf_Itemkey);
969 			END IF;
970 --			DBMS_OUTPUT.put_line ('Exception completing blocked WF');
971 		end;
972 	   end if;
973 
974 	   x_charge_success := x_success;
975 
976 	   if x_new_combination then
977 		x_new_ccid_generated	:= TRUE;
978 		-- commit; Need this commit else the entire GL_CODE_COMBINATIONS table will be locked. commit in form.
979 	   end if;
980 
981 	   -- Copy the returned value into appropriate function parameters to pass them
982 	   -- back to the form.
983 
984            x_progress :=  'ccid:' || to_char(ccid) || ' concat_segs:' || concat_segs || ' concat_ids:' || concat_ids ||
985 			' concat_descrs:' || concat_descrs || ' FB_ERROR_MSG:' || FB_ERROR_MSG;
986            IF (g_po_wf_debug = 'Y') THEN
987               /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,WF_ItemKey,x_progress);
988            END IF;
989 
990 	   x_code_combination_id := ccid;
991            x_charge_account_flex := concat_segs;
992            x_charge_account_desc := concat_descrs;
993 
994 	   was_ccid_passed_in_from_form := false;
995 
996 	else
997 
998 	   x_charge_success := TRUE;
999 	   x_success := TRUE;
1000 	   was_ccid_passed_in_from_form := true;
1001 
1002 	end if;
1003 
1004 
1005      	If (x_success and (x_code_combination_id IS NOT NULL) and (x_code_combination_id <> 0) and
1006 		(x_code_combination_id <> -1))   then
1007 
1008 		wf_engine.SetItemAttrNumber (  itemtype   =>  itemtype,
1009         	        	               itemkey    =>  WF_ItemKey,
1010                 	        	       aname      =>  'CODE_COMBINATION_ID',
1011                         	               avalue     =>  x_code_combination_id );
1012 
1013 		x_charge_success := x_success;
1014 
1015 		-- Generate Budget Account if encumbrance is on
1016 
1017 		if ((x_po_encumberance_flag = 'Y')  and (x_destination_type_code <> 'SHOP FLOOR'
1018                                                          OR (x_destination_type_code = 'SHOP FLOOR' AND x_wip_entity_type = 6) )) then
1019       /* Condition added for Encumbrance Project - To enable Encumbrance for Destination type Shop Floor and WIP entity type EAM   */
1020 /*		    If (debug_acc_generator_wf) then dbms_output.put_line ('Calling generate to build Budget Account'); end if;
1021 */
1022 		    if was_ccid_passed_in_from_form = false then
1023 		       x_block_activity_label := 'BLOCK_BUDGET_ACC_GENERATION';
1024                     else
1025                        x_block_activity_label := NULL;
1026                     end if;
1027 
1028                     -- Bug 1497909 : Set the encumbrance date for validation
1029                     po_wf_util_pkg.SetItemAttrDate(itemtype   =>  itemtype,
1030                                         itemkey    =>  wf_itemkey,
1031                                         aname      =>  'ENCUMBRANCE_DATE',
1032                                         avalue     =>  x_gl_encumbered_date);
1033 
1034 		    x_success := FND_FLEX_WORKFLOW.GENERATE_PARTIAL ( 	ItemType,
1035 						  	  	      	WF_ItemKey,
1036 									'DEFAULT_BUDGET_ACC_GENERATION',
1037 							  		x_block_activity_label,
1038 									x_insert_if_new,
1039 						  	  		ccid,
1040 						  	  		concat_segs,
1041 						  	  		concat_ids,
1042 						  	  		concat_descrs,
1043 						  	  		FB_ERROR_MSG,
1044 									x_new_combination);
1045 		    x_budget_success := x_success;
1046 
1047 	   	    if x_new_combination then
1048 			x_new_ccid_generated	:= TRUE;
1049 	   	    end if;
1050 
1051 		    x_budget_account_id := ccid;
1052 		    x_budget_account_flex := concat_segs;
1053 		    x_budget_account_desc := concat_descrs;
1054 
1055 
1056         	    x_progress :=  'ccid:' || to_char(ccid) || ' concat_segs:' || concat_segs || ' concat_ids:' ||
1057 				    concat_ids || ' concat_descrs:' || concat_descrs || ' FB_ERROR_MSG:' ||
1058 				    FB_ERROR_MSG;
1059 
1060 	        else
1061 			x_success := TRUE;
1062 		        x_budget_success := x_success;
1063 		end if;
1064 
1065 		if x_success then
1066 
1067 		    wf_engine.SetItemAttrNumber (  itemtype   =>  itemtype,
1068         	        	                   itemkey    =>  WF_ItemKey,
1069                 	        	           aname      =>  'BUDGET_ACCOUNT_ID',
1070                         	        	   avalue     =>  x_budget_account_id );
1071 
1072 		    -- Generate Accrual Account
1073 
1074 /*		    If (debug_acc_generator_wf) then dbms_output.put_line ('Calling generate to build Accrual Account'); end if;
1075 */
1076                     if was_ccid_passed_in_from_form = false then
1077                        if ((x_po_encumberance_flag = 'Y')  and (x_destination_type_code <> 'SHOP FLOOR'
1078                                                                 OR (x_destination_type_code = 'SHOP FLOOR' AND x_wip_entity_type = 6) )) then
1079       /* Condition added for Encumbrance Project - To enable Encumbrance for Destination type Shop Floor and WIP entity type EAM   */
1080 		    	   x_block_activity_label := 'BLOCK_ACCRUAL_ACC_GENERATION';
1081 		       else
1082 		    	   x_block_activity_label := 'BLOCK_BUDGET_ACC_GENERATION';
1083 		       end if;
1084                     else
1085                        if ((x_po_encumberance_flag = 'Y')  and (x_destination_type_code <> 'SHOP FLOOR'
1086                                                                 OR (x_destination_type_code = 'SHOP FLOOR' AND x_wip_entity_type = 6) )) then
1087       /* Condition added for Encumbrance Project - To enable Encumbrance for Destination type Shop Floor and WIP entity type EAM   */
1088 		    	   x_block_activity_label := 'BLOCK_ACCRUAL_ACC_GENERATION';
1089 		       else
1090 		    	   x_block_activity_label := NULL;
1091 		       end if;
1092                     end if;
1093 
1094                     -- Bug 1497909 : Set the encumbrance date for validation
1095                     po_wf_util_pkg.SetItemAttrDate(itemtype   =>  itemtype,
1096                                         itemkey    =>  wf_itemkey,
1097                                         aname      =>  'ENCUMBRANCE_DATE',
1098                                         avalue     =>  x_gl_encumbered_date);
1099 
1100 		    x_success := FND_FLEX_WORKFLOW.GENERATE_PARTIAL ( 	ItemType,
1101 						  	  	      	WF_ItemKey,
1102 							  		'DEFAULT_ACCRUAL_ACC_GENERATION',
1103 							  		x_block_activity_label,
1104 									x_insert_if_new,
1105 						  	  		ccid,
1106 						  	  		concat_segs,
1107 						  	  		concat_ids,
1108 						  	  		concat_descrs,
1109 						  	  		FB_ERROR_MSG,
1110 									x_new_combination );
1111 		    x_accrual_success := x_success;
1112 
1113 	   	    if x_new_combination then
1114 			x_new_ccid_generated	:= TRUE;
1115 	   	    end if;
1116 
1117 		    x_accrual_account_id := ccid;
1118 		    x_accrual_account_flex := concat_segs;
1119 		    x_accrual_account_desc := concat_descrs;
1120 
1121 
1122         	    x_progress :=  'ccid:' || to_char(ccid) || ' concat_segs:' || concat_segs || ' concat_ids:' ||
1123 				    concat_ids || ' concat_descrs:' || concat_descrs || ' FB_ERROR_MSG:' ||
1124 				    FB_ERROR_MSG;
1125 
1126 		    If x_success then
1127 
1128 		        wf_engine.SetItemAttrNumber (  itemtype   =>  itemtype,
1129         	        	                       itemkey    =>  WF_ItemKey,
1130                 	        	               aname      =>  'ACCRUAL_ACCOUNT_ID',
1131                         	        	       avalue     =>  x_accrual_account_id );
1132 
1133 			-- Generate Variance Account
1134                         -- Bug 1497909 : Set the encumbrance date for validation
1135                         po_wf_util_pkg.SetItemAttrDate(itemtype   =>  itemtype,
1136                                         itemkey    =>  wf_itemkey,
1137                                         aname      =>  'ENCUMBRANCE_DATE',
1138                                         avalue     =>  x_gl_encumbered_date);
1139 
1140 		    	x_success := FND_FLEX_WORKFLOW.GENERATE_PARTIAL ( ItemType,
1141 						  	  	      	  WF_ItemKey,
1142 							  		  'DEFAULT_VARIANCE_ACC_GENERATION',
1143 							  		  'BLOCK_VARIANCE_ACC_GENERATION',
1144 									  x_insert_if_new,
1145 						  	  		  ccid,
1146 						  	  		  concat_segs,
1147 						  	  		  concat_ids,
1148 						  	  		  concat_descrs,
1149 						  	  		  FB_ERROR_MSG,
1150 									  x_new_combination );
1151 
1152 		    	x_variance_success := x_success;
1153 
1154 	   	    	if x_new_combination then
1155 				x_new_ccid_generated	:= TRUE;
1156 	   	    	end if;
1157 
1158 			x_variance_account_id := ccid;
1159 			x_variance_account_flex := concat_segs;
1160 			x_variance_account_desc := concat_descrs;
1161 
1162 
1163         		x_progress :=  'ccid:' || to_char(ccid) || ' concat_segs:' || concat_segs || ' concat_ids:'
1164 					|| concat_ids || ' concat_descrs:' || concat_descrs || ' FB_ERROR_MSG:' ||
1165 					FB_ERROR_MSG;
1166 
1167 /*			If (debug_acc_generator_wf) then
1168 				if (not x_success) then
1169 					dbms_output.put_line (' va failed');
1170 				end if;
1171 			end if;
1172 */
1173 
1174 			x_new_combination := x_new_ccid_generated;
1175 
1176                         PO_WF_UTIL_PKG.clear_wf_cache; -- bug5075361
1177 
1178 			return (x_success);
1179 
1180 		    else		-- accrual acc failed.
1181 
1182 /*			If (debug_acc_generator_wf) then
1183 				dbms_output.put_line (' aa failed');
1184 			end if;   */
1185 
1186                         PO_WF_UTIL_PKG.clear_wf_cache; -- bug5075361
1187 
1188 			return (x_success);
1189 
1190 		    end if;
1191 
1192 		else			-- budget acc failed.
1193 
1194 /*			If (debug_acc_generator_wf) then
1195 				dbms_output.put_line (' ba failed');
1196 			end if;    */
1197 
1198                         PO_WF_UTIL_PKG.clear_wf_cache; -- bug5075361
1199 
1200 			return (x_success);
1201 		end if;
1202 
1203 
1204 	else		-- charge acc failed.
1205 
1206 /*		If (debug_acc_generator_wf) then  dbms_output.put_line (' ca failed');  end if;
1207 */
1208 
1209                 PO_WF_UTIL_PKG.clear_wf_cache; -- bug5075361
1210 
1211 		return (x_success);
1212 
1213      	end if;
1214 
1215         PO_WF_UTIL_PKG.clear_wf_cache; -- bug5075361
1216 
1217      	return x_success;
1218   ELSE
1219 
1220 	FB_ERROR_MSG := 'Invalid Item Type OR Item Key';
1221 
1222         PO_WF_UTIL_PKG.clear_wf_cache; -- bug5075361
1223 
1224 	return FALSE;
1225   END IF;
1226 
1227 EXCEPTION
1228  WHEN OTHERS THEN
1229 
1230    PO_WF_UTIL_PKG.clear_wf_cache; -- bug5075361
1231 
1232    po_message_s.sql_error('PO_REQ_WF_BUILD_ACCOUNT_INIT.Start_Workflow', x_progress, sqlcode);
1233    RAISE;
1234 
1235 END Start_Workflow;
1236 
1237 
1238 /*
1239     * Set the debug mode on
1240 */
1241 
1242 PROCEDURE debug_on IS
1243 BEGIN
1244         debug_acc_generator_wf := TRUE;
1245 
1246         PO_WF_PO_CHARGE_ACC.debug_on;
1247         PO_WF_PO_BUDGET_ACC.debug_on;
1248 --        PO_WF_PO_ACCRUAL_ACC.debug_on;
1249 --        PO_WF_PO_VARIANCE_ACC.debug_on;
1250 
1251 END debug_on;
1252 
1253 /*
1254     * Set the debug mode off
1255 */
1256 
1257 PROCEDURE debug_off IS
1258 BEGIN
1259         debug_acc_generator_wf := FALSE;
1260 
1261         PO_WF_PO_CHARGE_ACC.debug_off;
1262         PO_WF_PO_BUDGET_ACC.debug_off;
1263 --        PO_WF_PO_ACCRUAL_ACC.debug_off;
1264 --        PO_WF_PO_VARIANCE_ACC.debug_off;
1265 
1266 END debug_off;
1267 
1268 
1269 -- ************************************************************************************ --
1270 /*
1271 	PRIVATE PROCEDURES / FUNCTIONS
1272 */
1273 -- ************************************************************************************ --
1274 
1275 
1276 PROCEDURE Call_WF_API_to_set_Att (ItemType varchar2, ItemKey varchar2, aname varchar2,
1277 				  avalue varchar2)
1278 IS
1279 BEGIN
1280 
1281 	wf_engine.SetItemAttrText (    itemtype   =>  itemtype,
1282                                        itemkey    =>  itemkey,
1283                                        aname      =>  aname,
1284                                        avalue     =>  avalue );
1285 END Call_WF_API_to_set_Att;
1286 
1287 PROCEDURE Call_WF_API_to_set_no_Att (ItemType varchar2, ItemKey varchar2, aname varchar2,
1288 				  avalue number)
1289 IS
1290 BEGIN
1291 
1292 	wf_engine.SetItemAttrNumber (  itemtype   =>  itemtype,
1293                                        itemkey    =>  itemkey,
1294                                        aname      =>  aname,
1295                                        avalue     =>  avalue );
1296 END Call_WF_API_to_set_no_Att;
1297 
1298 PROCEDURE Call_WF_API_to_set_date_Att (ItemType varchar2, ItemKey varchar2, aname varchar2,
1299 				  avalue date)
1300 IS
1301 BEGIN
1302 
1303 	wf_engine.SetItemAttrDate (    itemtype   =>  itemtype,
1304                                        itemkey    =>  itemkey,
1305                                        aname      =>  aname,
1306                                        avalue     =>  avalue );
1307 END Call_WF_API_to_set_date_Att;
1308 
1309 end  PO_REQ_WF_BUILD_ACCOUNT_INIT;