[Home] [Help]
PACKAGE BODY: APPS.AP_WEB_EXPENSE_WF
Source
1 PACKAGE BODY AP_WEB_EXPENSE_WF AS
2 /* $Header: apwxwkfb.pls 120.328.12020000.4 2013/01/29 11:41:31 saprayag ship $ */
3
4
5 --
6 -- Private Variables
7 --
8 -- copied from WF_NOTIFICATION package
9 -- /fnddev/fnd/11.5/patch/115/sql/wfntfb.pls
10 --
11
12 table_width varchar2(6) := '"100%"';
13 table_border varchar2(3) := '"0"';
14 table_cellpadding varchar2(3) := '"3"';
15 table_cellspacing varchar2(3) := '"1"';
16 table_bgcolor varchar2(7) := '"white"';
17 th_bgcolor varchar2(9) := '"#cccc99"';
18 th_fontcolor varchar2(9) := '"#336699"';
19 th_fontface varchar2(80) := '"Arial, Helvetica, Geneva, sans-serif"';
20 td_bgcolor varchar2(9) := '"#f7f7e7"';
21 td_fontcolor varchar2(7) := '"black"';
22 td_fontface varchar2(80) := '"Arial, Helvetica, Geneva, sans-serif"';
23
24
25 startOraFieldTextFont varchar2(200) := '<font style="{font-family:Arial,Helvetica,Geneva,sans-serif;font-size:10pt;color:#000000}">';
26 endOraFieldTextFont varchar2(50) := '</font>';
27
28 indent_start varchar2(200) := '<table style="{background-color:#ffffff}" width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td width="20"></td><td>';
29 indent_end varchar2(200) := '</td></tr></table>';
30
31 ----------------------------------
32 --.OraTableTitle {font-family:Arial,Helvetica,Geneva,sans-serif;font-size:13pt;background-color:#ffffff;color:#336699}
33 ----------------------------------
34 table_title_start varchar2(200) := '<br><font style="{font-family:Arial,Helvetica,Geneva,sans-serif;font-size:11pt;font-weight:bold;background-color:#ffffff;color:#336699}">';
35 table_title_end varchar2(200) := '</font><br><table width="100%"><tr bgcolor="#cccc99"><td height="1"></td></tr><tr bgcolor="#ffffff"><td height="2"></td></tr></table>';
36
37 ----------------------------------
38 --.OraTable {background-color:#999966}
39 ----------------------------------
40 table_start varchar2(200) := '<table style="{background-color:#999966}" width="100%" border="0" cellpadding="3" cellspacing="1">';
41 table_end varchar2(15) := '</table>';
42
43 tr_start varchar2(80) := '<tr bgcolor="#cccc99">';
44 tr_end varchar2(15) := '</tr>';
45
46 ----------------------------------
47 --.OraTableColumnHeaderIconButton {font-family:Arial,Helvetica,Geneva,sans-serif;font-size:10pt;font-weight:bold;background-color:#cccc99;color:#336699;vertical-align:bottom;text-align:center}
48 ----------------------------------
49 th_select varchar2(200) := '<td style="{font-family:Arial,Helvetica,Geneva,sans-serif;font-size:10pt;font-weight:bold;background-color:#cccc99;color:#336699;vertical-align:bottom;text-align:center}">';
50
51 ----------------------------------
52 -- .OraTableColumnHeader {font-family:Arial,Helvetica,Geneva,sans-serif;font-size:10pt;font-weight:bold;text-align:left;background-color:#cccc99;color:#336699;vertical-align:bottom}
53 ----------------------------------
54 th_text varchar2(200) := '<td style="{font-family:Arial,Helvetica,Geneva,sans-serif;font-size:10pt;font-weight:bold;text-align:left;background-color:#cccc99;color:#336699;vertical-align:bottom}">';
55
56 ----------------------------------
57 -- .OraTableColumnHeaderNumber {font-family:Arial,Helvetica,Geneva,sans-serif;font-size:10pt;font-weight:bold;background-color:#cccc99;color:#336699;vertical-align:bottom;text-align:right}
58 ----------------------------------
59 th_number varchar2(200) := '<td style="{font-family:Arial,Helvetica,Geneva,sans-serif;font-size:10pt;font-weight:bold;background-color:#cccc99;color:#336699;vertical-align:bottom;text-align:right}">';
60
61 ----------------------------------
62 -- .OraTableCellSelect {font-family:Arial,Helvetica,Geneva,sans-serif;font-size:10pt;text-align:center;background-color:#f7f7e7;color:#000000;vertical-align:baseline}
63 ----------------------------------
64 td_select varchar2(200) := '<td style="{font-family:Arial,Helvetica,Geneva,sans-serif;font-size:10pt;text-align:center;background-color:#f7f7e7;color:#000000;vertical-align:baseline}">';
65
66 ----------------------------------
67 -- .OraTableCellText {font-family:Arial,Helvetica,Geneva,sans-serif;font-size:10pt;background-color:#f7f7e7;color:#000000;vertical-align:baseline}
68 ----------------------------------
69 td_text varchar2(200) := '<td style="{font-family:Arial,Helvetica,Geneva,sans-serif;font-size:10pt;background-color:#f7f7e7;color:#000000;vertical-align:baseline}">';
70
71 ----------------------------------
72 -- .OraTableCellNumber {font-family:Arial,Helvetica,Geneva,sans-serif;font-size:10pt;text-align:right;background-color:#f7f7e7;color:#000000;vertical-align:baseline}
73 ----------------------------------
74 td_number varchar2(200) := '<td style="{font-family:Arial,Helvetica,Geneva,sans-serif;font-size:10pt;text-align:right;background-color:#f7f7e7;color:#000000;vertical-align:baseline}">';
75
76 td_start varchar2(10) := '<td>';
77 td_end varchar2(10) := '</td>';
78
79 ------------------------
80 -- Constants definition
81 ------------------------
82
83 -- Start from process from server validation, manager approval, ap approval
84 C_START_FROM_SERVER_VALIDATION CONSTANT VARCHAR2(40) := 'SERVER_VALIDATION';
85 C_START_FROM_MANAGER_APPROVAL CONSTANT VARCHAR2(40) := 'MANAGER_APPROVAL';
86 C_START_FROM_AP_APPROVAL CONSTANT VARCHAR2(40) := 'AP_APPROVAL';
87
88 -- Reject Status in Shortpay
89 C_APReject_Status CONSTANT VARCHAR2(10) := 'AP_REJECT';
90
91 -- Number of LINE_INFO attributes
92 C_NUM_LINE_INFO_ATTRS CONSTANT NUMBER := 200;
93 C_NUM_ADJ_LINE_ATTRS CONSTANT NUMBER := 20;
94
95 -- Number for mileage process
96 C_KILOMETERS CONSTANT VARCHAR2(20) := 'KM';
97 C_MILES CONSTANT VARCHAR2(20) := 'MILES';
98 C_SWMILES CONSTANT VARCHAR2(20) := 'SWMILES';
99 KILOMETERS_TO_MILES CONSTANT NUMBER := 0.621370;
100 MILES_TO_KILOMETERS CONSTANT NUMBER := 1.609347;
101 SWMILES_TO_MILES CONSTANT NUMBER := 6.21370;
102 MILES_TO_SWMILES CONSTANT NUMBER := 0.160934;
103 KILOMETERS_TO_SWMILES CONSTANT NUMBER := 0.1;
104 SWMILES_TO_KILOMETERS CONSTANT NUMBER := 10.0;
105 C_THRESHOLD_TOLERANCE CONSTANT NUMBER := 1;
106
107 -- Constants for YES_NO lookup
108 C_YES_NO FND_LOOKUPS.LOOKUP_TYPE%type := 'YES_NO';
109 C_Y FND_LOOKUPS.LOOKUP_CODE%type := 'Y';
110 C_N FND_LOOKUPS.LOOKUP_CODE%type := 'N';
111
112 -- Constants for notification type
113 C_EMP CONSTANT VARCHAR2(3) := 'EMP';
114 C_OTHER CONSTANT VARCHAR2(5) := 'OTHER';
115
116 -- Constants for Policy violation value
117 C_ALLOW_NO_WARNINGS VARCHAR2(50):='ALLOW_NO_WARNINGS';
118
119 -- Constants for Business Events
120 C_SUBMIT_EVENT_NAME CONSTANT VARCHAR2(80) := 'oracle.apps.ap.oie.expenseReport.submit';
121
122 C_ROUNDING CONSTANT VARCHAR2(20) := 'ROUNDING';
123
124 -- Constant for multiple current approvers
125 C_AME_MULTIPLE_CURR_APPROVER CONSTANT NUMBER := -99999;
126
127 -- Constant For Distance Field
128 C_DISTANCE_FIELD CONSTANT VARCHAR2(50) := 'DAILY_DISTANCE';
129
130 -----------------------------------------------------------------------
131 FUNCTION GetFlowVersion(p_item_type IN VARCHAR2,
132 p_item_key IN VARCHAR2) RETURN NUMBER
133 ---------------------------------------------------------------------------
134 IS
135 l_version_num NUMBER := 0;
136 BEGIN
137
138 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start GetFlowVersion');
139
140 l_version_num := WF_ENGINE.GetItemAttrNumber(p_item_type,
141 p_item_key,
142 'VERSION');
143
144 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end GetFlowVersion');
145
146 RETURN l_version_num;
147
148 EXCEPTION
149 WHEN NO_DATA_FOUND THEN
150 RETURN 0;
151 WHEN OTHERS THEN
152 RETURN 0;
153 END GetFlowVersion;
154
155 ----------------------------------------------------------------------
156 PROCEDURE SetFromRole(
157 p_item_type IN VARCHAR2,
158 p_item_key IN VARCHAR2,
159 p_actid IN NUMBER,
160 p_from_role IN VARCHAR2,
161 p_called_from IN VARCHAR2) IS
162 ----------------------------------------------------------------------
163 l_debug_info VARCHAR2(500);
164 l_role_valid VARCHAR2(1);
165 tvalue varchar2(4000);
166 role_info_tbl wf_directory.wf_local_roles_tbl_type;
167 BEGIN
168
169 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start SetFromRole');
170
171 l_role_valid := 'Y';
172 tvalue := p_from_role;
173 Wf_Directory.GetRoleInfo2(p_from_role,role_info_tbl);
174 tvalue := role_info_tbl(1).name;
175 -- If not internal name, check for display_name
176 if (tvalue is null) then
177 begin
178 SELECT name
179 INTO tvalue
180 FROM wf_role_lov_vl
181 WHERE upper(display_name) = upper(p_from_role)
182 AND rownum = 1;
183 exception
184 when no_data_found then
185 -- Not displayed or internal role name, error
186 l_role_valid := 'N';
187 end;
188 end if;
189
190 if l_role_valid <> 'N' then
191 ----------------------------------------------------------------
192 l_debug_info := 'Set #FROM_ROLE : called from : ' || p_called_from;
193 ----------------------------------------------------------------
194 WF_ENGINE.SetItemAttrText(p_item_type,
195 p_item_key,
196 '#FROM_ROLE',
197 tvalue);
198 end if;
199
200 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end SetFromRole');
201
202 EXCEPTION
203 WHEN OTHERS THEN
204 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'SetFromRole:Called From' ||
205 p_called_from,
206 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
207 raise;
208 END SetFromRole;
209
210 ---------------------------------------------------------------------------
211 PROCEDURE StartExpenseReportProcess(p_report_header_id IN NUMBER,
212 p_preparer_id IN NUMBER,
213 p_employee_id IN NUMBER,
214 p_document_number IN VARCHAR2,
215 p_total IN NUMBER,
216 p_new_total IN NUMBER,
217 p_reimb_curr IN VARCHAR2,
218 p_cost_center IN VARCHAR2,
219 p_purpose IN VARCHAR2,
220 p_approver_id IN NUMBER,
221 p_week_end_date IN DATE,
222 p_workflow_flag IN VARCHAR2,
223 p_submit_from_oie IN VARCHAR2,
224 p_event_raised IN VARCHAR2 DEFAULT 'N') IS
225 ---------------------------------------------------------------------------
226 l_item_type VARCHAR2(100) := 'APEXP';
227 l_item_key VARCHAR2(100) := to_char(p_report_header_id);
228 l_preparer_name wf_users.name%type;
229 l_preparer_display_name wf_users.display_name%type;
230 l_employee_display_name wf_users.display_name%type;
231 l_approver_name wf_users.name%type;
232 l_approver_display_name wf_users.display_name%type;
233 l_emp_cost_center VARCHAR2(240);
234 l_dummy_emp_name VARCHAR2(240);
235 l_emp_num VARCHAR2(30);
236 l_emp_name wf_users.name%type;
237 l_total NUMBER;
238 l_total_dsp VARCHAR2(50);
239 l_new_total_dsp VARCHAR2(50);
240 l_credit_total_dsp VARCHAR2(50);
241 l_credit_total NUMBER;
242 l_url VARCHAR2(1000);
243 l_debug_info VARCHAR2(200);
244 l_employee_project_enabled VARCHAR2(1);
245 C_CreditLineVersion CONSTANT NUMBER := 1;
246 C_WF_Version NUMBER := 0;
247 l_err_name VARCHAR2(30);
248 l_ResubmitReport BOOLEAN := FALSE;
249
250 -- for bug 1652106
251 l_n_org_id NUMBER;
252
253 -- for bug 2069362
254 l_AMEEnabled VARCHAR2(1);
255 l_bAMEProfileDefined BOOLEAN;
256
257 -- Grants Integration
258 l_grants_enabled VARCHAR2(1);
259
260 l_textNameArr Wf_Engine.NameTabTyp;
261 l_textValArr Wf_Engine.TextTabTyp;
262 l_numNameArr Wf_Engine.NameTabTyp;
263 l_numValArr Wf_Engine.NumTabTyp;
264 iNum NUMBER :=0;
265 iText NUMBER :=0;
266
267 --ER 1552747 - withdraw expense report
268 l_mess Wf_Item_Attribute_Values.TEXT_VALUE%TYPE;
269
270 -- Policy Violation
271 l_violation_count NUMBER:=0;
272 l_policy_violation_value VARCHAR2(50);
273 l_policy_violation_defined BOOLEAN;
274
275 l_n_resp_id Number;
276 l_userid VARCHAR2(80);
277 l_card_program_id NUMBER := 0;
278 l_wf_exists VARCHAR2(1) := 'Y';
279
280 BEGIN
281
282 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start StartExpenseReportProcess');
283
284 -- org_context should be set while calling icx_sec.validatesession
285 --IF AP_WEB_INFRASTRUCTURE_PKG.ValidateSession(NULL, FALSE, FALSE) THEN
286
287 UpdateHeaderLines(p_report_header_id); --Bug 2777245
288
289 -- Fix 2178792 : Added the below select
290 select nvl(AMT_DUE_CCARD_COMPANY,0)+nvl(AMT_DUE_EMPLOYEE,0)+nvl(MAXIMUM_AMOUNT_TO_APPLY,0)
291 into l_total
292 from ap_expense_report_headers_all
293 where report_header_id = p_report_header_id;
294
295 l_total_dsp := to_char(l_total,
296 FND_CURRENCY.Get_Format_Mask(p_reimb_curr,22));
297 l_new_total_dsp := to_char(p_new_total,
298 FND_CURRENCY.Get_Format_Mask(p_reimb_curr,22));
299 l_credit_total := p_total - p_new_total;
300 l_credit_total_dsp := to_char(l_credit_total,
301 FND_CURRENCY.Get_Format_Mask(p_reimb_curr,22));
302 AP_WEB_PROJECT_PKG.IsSessionProjectEnabled(
303 p_employee_id,
304 FND_PROFILE.VALUE('USER_ID'),
305 l_employee_project_enabled);
306
307 l_ResubmitReport := AP_WEB_DB_EXPRPT_PKG.ResubmitExpenseReport(
308 p_workflow_flag);
309
310 -- Grants Integration
311 IF (GMS_OIE_INT_PKG.IsGrantsEnabled()) THEN
312 l_grants_enabled := 'Y';
313 ELSE
314 l_grants_enabled := 'N';
315 END IF;
316
317 BEGIN
318 SELECT 'Y' INTO l_wf_exists
319 FROM wf_items
320 WHERE item_type = l_item_type
321 AND item_key = l_item_key;
322
323 l_wf_exists := 'Y';
324 EXCEPTION
325 WHEN NO_DATA_FOUND THEN
326 l_wf_exists := 'N';
327 l_ResubmitReport := FALSE;
328 END;
329
330 IF (NOT l_ResubmitReport and p_event_raised <> 'Y') THEN
331 BEGIN
332 -- We need to create a process when we are submitting for the first time or
333 -- expense was withdrawn.
334 -- For resubmitting a rejected/returned report, we just need to start up the
335 -- workflow process from the blocked activity.
336
337 --------------------------------------------------
338 l_debug_info := 'Calling WorkFlow Create Process';
339 --------------------------------------------------
340 WF_ENGINE.CreateProcess(l_item_type,
341 l_item_key,
342 'AP_EXPENSE_REPORT_PROCESS');
343 EXCEPTION
344 when others then
345 l_err_name := wf_core.error_name;
346 if (l_err_name = 'WFENG_ITEM_UNIQUE') then
347 -- the workflow process with l_item_key has been created
348 -- previously. we should still allow users to submit the
349 -- same report for bug 2203698.
350 wf_core.clear;
351 else
352 raise;
353 end if;
354 END;
355 END IF;
356
357
358 -- for bug 1652106
359 --------------------------------------------------------------
360 l_debug_info := 'Get Org_ID value ';
361 --------------------------------------------------------------
362
363 /* Bug 2945379 : The org_id retrieved from the table will
364 always be the correct one */
365 -- FND_PROFILE.GET('ORG_ID' , l_n_org_id );
366
367 SELECT org_id
368 INTO l_n_org_id
369 FROM ap_expense_report_headers_all
370 WHERE report_header_id = l_item_key;
371
372
373 -- ORG_ID was added later; therefore, it needs to be tested for upgrade purpose, and
374 -- is not included in the bulk update.
375 begin
376
377 WF_ENGINE.SetItemAttrNumber(l_item_type,
378 l_item_key,
379 'ORG_ID',
380 l_n_Org_ID);
381 exception
382 when others then
383 if (wf_core.error_name = 'WFENG_ITEM_ATTR') then
384 -- ORG_ID item attribute doesn't exist, need to add it
385 WF_ENGINE.AddItemAttr(l_item_type, l_item_key, 'ORG_ID');
386 WF_ENGINE.SetItemAttrNumber(l_item_type,
387 l_item_key,
388 'ORG_ID',
389 l_n_Org_ID);
390 else
391 raise;
392 end if;
393
394 end;
395
396
397 begin
398
399 /* Bug 2351528. Need to set the user_key for easier query */
400 WF_ENGINE.SetItemUserKey(l_item_type,
401 l_item_key,
402 p_document_number);
403
404 --------------------------------------------------------------
405 l_debug_info := 'Set User_ID value ';
406 --------------------------------------------------------------
407 WF_ENGINE.SetItemAttrNumber(l_item_type,
408 l_item_key,
409 'USER_ID',
410 FND_PROFILE.VALUE('USER_ID'));
411
412 --------------------------------------------------------------
413 l_debug_info := 'Set Resp_ID value ';
414 --------------------------------------------------------------
415 WF_ENGINE.SetItemAttrNumber(l_item_type,
416 l_item_key,
417 'RESPONSIBILITY_ID',
418 FND_PROFILE.VALUE('RESP_ID'));
419
420 --------------------------------------------------------------
421 l_debug_info := 'Set Resp_Appl_ID value ';
422 --------------------------------------------------------------
423 WF_ENGINE.SetItemAttrNumber(l_item_type,
424 l_item_key,
425 'APPLICATION_ID',
426 FND_PROFILE.VALUE('RESP_APPL_ID'));
427
428 ------------------------------------------------------------
429 l_debug_info := 'Get responsibility id';
430 ------------------------------------------------------------
431 l_n_resp_id := WF_ENGINE.GetItemAttrNumber(l_item_type,
432 l_item_key,
433 'RESPONSIBILITY_ID');
434
435 exception
436 when others then
437 if (wf_core.error_name = 'WFENG_ITEM_ATTR') then
438 null;
439 else
440 raise;
441 end if;
442 end;
443
444 ----------------------------------------------------
445 l_debug_info := 'Retrieve profile option AME Enabled?';
446 ----------------------------------------------------
447 FND_PROFILE.GET_SPECIFIC('AME_INSTALLED_FLAG', null, l_n_resp_id, 200, l_AMEEnabled, l_bAMEProfileDefined);
448
449 if l_bAMEProfileDefined then
450 l_AMEEnabled := NVL(l_AMEENABLED,'N'); -- Default to 'N' if null
451 else
452 l_AMEEnabled := 'N';
453 end if;
454
455 WF_ENGINE.SetItemAttrText(l_item_type,
456 l_item_key,
457 'AME_ENABLED',
458 l_AMEEnabled);
459
460 -------------------------------------------------
461 l_debug_info := 'Update Withdraw Message';
462 -------------------------------------------------
463 --ER 1552747 - withdraw expense report
464 if p_workflow_flag = AP_WEB_DB_EXPRPT_PKG.C_WORKFLOW_APPROVED_WITHDRAW then
465 FND_MESSAGE.SET_NAME('SQLAP','OIE_WITHDRAW_WARNING');
466 l_mess := FND_MESSAGE.GET;
467 WF_ENGINE.SetItemAttrText(l_item_type,
468 l_item_key,
469 'WITHDRAW_WARNING',
470 l_mess);
471 end if;
472
473 ----------------------------------------------------
474 l_debug_info := 'Set Grants Enabled Item Attribute';
475 ----------------------------------------------------
476 WF_ENGINE.SetItemAttrText(l_item_type,
477 l_item_key,
478 'GRANTS_ENABLED',
479 l_grants_enabled);
480
481
482 -------------------------------------------------
483 l_debug_info := 'Set WF Purpose Item Attribute';
484 -------------------------------------------------
485 iText := iText + 1;
486 l_textNameArr(iText) := 'PURPOSE';
487 l_textValArr(iText) := p_purpose;
488
489 ------------------------------------------------------
490 l_debug_info := 'Set LINE_TABLE Item Attribute';
491 ------------------------------------------------------
492
493 iText := iText + 1;
494 l_textNameArr(iText) := 'LINE_TABLE';
495 l_textValArr(iText) := 'plsqlclob:AP_WEB_EXPENSE_WF.generateExpClobLines/'||l_item_type||':'||l_item_key;
496
497 ------------------------------------------------------
498 l_debug_info := 'Set EMP_LINE_TABLE Item Attribute';
499 ------------------------------------------------------
500
501 iText := iText + 1;
502 l_textNameArr(iText) := 'EMP_LINE_TABLE';
503 l_textValArr(iText) := 'plsqlclob:AP_WEB_EXPENSE_WF.generateExpClobLines/'||l_item_type||':'||l_item_key||':'||C_EMP;
504 ----------------------------------------------------------
505 l_debug_info := 'Set WF Expense_Report_ID Item Attribute';
506 ----------------------------------------------------------
507 iNum := iNum + 1;
508 l_numNameArr(iNum) := 'EXPENSE_REPORT_ID';
509 l_numValArr(iNum) := p_report_header_id;
510
511 --------------------------------------------------------
512 l_debug_info := 'Set WF Document_Number Item Attribute';
513 --------------------------------------------------------
514 iText := iText + 1;
515 l_textNameArr(iText) := 'DOCUMENT_NUMBER';
516 l_textValArr(iText) := p_document_number;
517
518 ------------------------------------------------------------
519 l_debug_info := 'Get Name Info Associated With Preparer_Id';
520 ------------------------------------------------------------
521 WF_DIRECTORY.GetUserName('PER',
522 p_preparer_id,
523 l_preparer_name,
524 l_preparer_display_name);
525
526 ----------------------------------------------------------
527 l_debug_info := 'Set the Owner of Workflow Process.';
528 ----------------------------------------------------------
529 WF_ENGINE.SetItemOwner(l_item_type, l_item_key, l_preparer_name);
530
531 ------------------------------------------------------------
532 l_debug_info := 'Get Name Info Associated With Employee_Id';
533 ------------------------------------------------------------
534 WF_DIRECTORY.GetUserName('PER',
535 p_employee_id,
536 l_emp_name,
537 l_employee_display_name);
538
539 ---------------------------------------------------------------------------
540 l_debug_info := 'Get the Employee Cost Center Associated With Preparer_Id';
541 ---------------------------------------------------------------------------
542 AP_WEB_UTILITIES_PKG.GetEmployeeInfo(l_dummy_emp_name,
543 l_emp_num,
544 l_emp_cost_center,
545 p_employee_id);
546
547 ------------------------------------------------------
548 l_debug_info := 'Set WF Preparer_ID Item Attribute';
549 ------------------------------------------------------
550 iNum := iNum + 1;
551 l_numNameArr(iNum) := 'PREPARER_ID';
552 l_numValArr(iNum) := p_preparer_id;
553
554 ------------------------------------------------------
555 l_debug_info := 'Set WF Preparer_Name Item Attribute';
556 ------------------------------------------------------
557 iText := iText + 1;
558 l_textNameArr(iText) := 'PREPARER_NAME';
559 l_textValArr(iText) := l_preparer_name;
560
561 --------------------------------------------------------------
562 l_debug_info := 'Set WF Preparer_Display_Name Item Attribute';
563 --------------------------------------------------------------
564 iText := iText + 1;
565 l_textNameArr(iText) := 'PREPARER_DISPLAY_NAME';
566 l_textValArr(iText) := l_preparer_display_name;
567
568 ------------------------------------------------------
569 l_debug_info := 'Set WF Employee_ID Item Attribute';
570 ------------------------------------------------------
571 iNum := iNum + 1;
572 l_numNameArr(iNum) := 'EMPLOYEE_ID';
573 l_numValArr(iNum) := p_employee_id;
574
575 ------------------------------------------------------
576 l_debug_info := 'Set WF Employee_Name Item Attribute';
577 ------------------------------------------------------
578 iText := iText + 1;
579 l_textNameArr(iText) := 'EMPLOYEE_NAME';
580 l_textValArr(iText) := l_emp_name;
581
582 --------------------------------------------------------------
583 l_debug_info := 'Set WF Preparer_Display_Name Item Attribute';
584 --------------------------------------------------------------
585 iText := iText + 1;
586 l_textNameArr(iText) := 'EMPLOYEE_DISPLAY_NAME';
587 l_textValArr(iText) := l_employee_display_name;
588
589 --------------------------------------------------------------
590 l_debug_info := 'Set CC Payment Due From Item Attribute';
591 --------------------------------------------------------------
592 iText := iText + 1;
593 l_textNameArr(iText) := 'PAYMENT_DUE_FROM';
594
595 IF (NOT AP_WEB_DB_EXPRPT_PKG.getPaymentDueFromReport(p_report_header_id,l_textValArr(iText))) THEN
596 l_debug_info := 'Could not set workflow attribute Payment_Due_From';
597 END IF;
598
599 -------------------------------------------------------------
600 l_debug_info := 'Retrieve and Set Approver Item Attributes If
601 Approver_Id is provided by the user';
602 --------------------------------------------------------------
603
604 -- Be sure to clear these values. If we are resubmitting, we don't want
605 -- the values from the previous process traversal to hang around.
606 l_approver_name := NULL;
607 l_approver_display_name := NULL;
608
609 IF (p_approver_id IS NOT NULL) THEN
610
611 WF_DIRECTORY.GetUserName('PER',
612 p_approver_id,
613 l_approver_name,
614 l_approver_display_name);
615
616 iNum := iNum + 1;
617 l_numNameArr(iNum) := 'APPROVER_ID';
618 l_numValArr(iNum) := p_approver_id;
619
620 iText := iText + 1;
621 l_textNameArr(iText) := 'APPROVER_NAME';
622 l_textValArr(iText) := l_approver_name;
623
624 iText := iText + 1;
625 l_textNameArr(iText) := 'APPROVER_DISPLAY_NAME';
626 l_textValArr(iText) := l_approver_display_name;
627 END IF;
628
629 ---------------------------------------------------------------
630 l_debug_info := 'Set WF (Expense Report) Total Item Attribute';
631 ---------------------------------------------------------------
632 iNum := iNum + 1;
633 l_numNameArr(iNum) := 'TOTAL';
634 l_numValArr(iNum) := l_total;
635
636 ------------------------------------------------------------------------
637 l_debug_info := 'Set WF (Expense Report) Display_Total Item Attribute';
638 ------------------------------------------------------------------------
639 iText := iText + 1;
640 l_textNameArr(iText) := 'DISPLAY_TOTAL';
641 l_textValArr(iText) := l_total_dsp || ' ' || p_reimb_curr;
642
643 -----------------------------------------------------
644 l_debug_info := 'Get Workflow Version Number 0';
645 -----------------------------------------------------
646 C_WF_Version := GetFlowVersion(l_item_type, l_item_key);
647
648 IF (C_WF_Version >= C_CreditLineVersion) THEN
649
650 ---------------------------------------------------------------
651 l_debug_info := 'Set WF (Expense Report) New Expense Total Item Attribute';
652 ---------------------------------------------------------------
653 iNum := iNum + 1;
654 l_numNameArr(iNum) := 'POS_NEW_EXPENSE_TOTAL';
655 l_numValArr(iNum) := p_new_total;
656
657 ------------------------------------------------------------------------
658 l_debug_info := 'Set WF (Expense Report) New Expense Display Total Item Attribute';
659 ------------------------------------------------------------------------
660 iText := iText + 1;
661 l_textNameArr(iText) := 'POS_NEW_EXPENSE_DISPLAY_TOTAL';
662 l_textValArr(iText) := l_new_total_dsp;
663
664 ---------------------------------------------------------------
665 l_debug_info := 'Set WF (Expense Report) Credit Total Item Attribute';
666 ---------------------------------------------------------------
667 iNum := iNum + 1;
668 l_numNameArr(iNum) := 'NEG_CREDIT_TOTAL';
669 l_numValArr(iNum) := l_credit_total;
670
671 ------------------------------------------------------------------------
672 l_debug_info := 'Set WF (Expense Report) Credit Display Total Item Attribute';
673 ------------------------------------------------------------------------
674 iText := iText + 1;
675 l_textNameArr(iText) := 'NEG_CREDIT_DISPLAY_TOTAL';
676 l_textValArr(iText) := l_credit_total_dsp;
677 END IF;
678
679 IF (C_WF_Version >= C_ProjectIntegrationVersion) THEN
680
681 -------------------------------------------------
682 l_debug_info := 'Set WF Week End Date Item Attribute';
683 -------------------------------------------------
684 WF_ENGINE.SetItemAttrDate(l_item_type,
685 l_item_key,
686 'WEEK_END_DATE',
687 p_week_end_date);
688
689 END IF;
690
691 IF (C_WF_Version >= AP_WEB_EXPENSE_WF.C_11_0_3Version) THEN
692 -------------------------------------------------
693 l_debug_info := 'Set whether employee is project enabled';
694 -------------------------------------------------
695 iText := iText + 1;
696 l_textNameArr(iText) := 'EMPLOYEE_PROJECT_ENABLED';
697 l_textValArr(iText) := l_employee_project_enabled;
698 END IF;
699
700 ---------------------------------------------------------------
701 l_debug_info := 'Set WF (Expense Report) Currency Item Attribute';
702 ---------------------------------------------------------------
703 iText := iText + 1;
704 l_textNameArr(iText) := 'CURRENCY';
705 l_textValArr(iText) := p_reimb_curr;
706
707 -------------------------------------------------------------
708 l_debug_info := 'Set WF Document Cost Center Item Attribute';
709 -------------------------------------------------------------
710 iText := iText + 1;
711 l_textNameArr(iText) := 'DOC_COST_CENTER';
712 l_textValArr(iText) := p_cost_center;
713
714 -------------------------------------------------------------
715 l_debug_info := 'Set WF Employee Cost Center Item Attribute';
716 -------------------------------------------------------------
717 iText := iText + 1;
718 l_textNameArr(iText) := 'EMP_COST_CENTER';
719 l_textValArr(iText) := l_emp_cost_center;
720
721 -------------------------------------------------------------
722 l_debug_info := 'Set Header Attachments';
723 -------------------------------------------------------------
724 IF (C_WF_Version >= AP_WEB_EXPENSE_WF.C_OIEJ_Version) THEN
725
726 iText := iText + 1;
727 l_textNameArr(iText) := 'HEADER_ATTACHMENTS';
728 l_textValArr(iText) := 'FND:entity=OIE_HEADER_ATTACHMENTS'|| '&' || 'pk1name=REPORT_HEADER_ID'||'&' ||'pk1value=' || l_item_key;
729
730 END IF;
731
732 ----------------------------------------------------
733 l_debug_info := 'Set SUBMIT_FROM_OIE Item Attribute';
734 ----------------------------------------------------
735 WF_ENGINE.SetItemAttrText(l_item_type,
736 l_item_key,
737 'SUBMIT_FROM_OIE',
738 p_submit_from_oie);
739
740 --------------------------------------------------------
741 l_debug_info := 'Call JumpIntoFunction to retrieve URL';
742 --------------------------------------------------------
743 AP_WEB_INFRASTRUCTURE_PKG.JumpIntoFunction(p_report_header_id,
744 'EXPENSE REPORT',
745 l_url);
746
747 -----------------------------------------------------
748 l_debug_info := 'Set EXPENSE DETAILS Item Attribute';
749 -----------------------------------------------------
750
751 -- Be sure to clear these values. If we are resubmitting, we don't want
752 -- the values from the previous process traversal to hang around.
753 iText := iText + 1;
754 l_textNameArr(iText) := 'EXPENSE_DETAILS';
755 l_textValArr(iText) := l_url;
756
757 -----------------------------------------------------
758 l_debug_info := 'Retrieve user id';
759 -----------------------------------------------------
760 AP_WEB_OA_MAINFLOW_PKG.GetUserID(p_employee_id, l_userid);
761
762 ------------------------------------------------------------
763 l_debug_info := 'Retrieve policy profile option';
764 ------------------------------------------------------------
765 FND_PROFILE.get_specific('AP_WEB_POLICY_VIOLATION_SUBMIT', l_userid,
766 l_n_resp_id, 200, l_policy_violation_value, l_policy_violation_defined);
767
768 if l_policy_violation_defined then
769 l_policy_violation_value := NVL(l_policy_violation_value, C_ALLOW_NO_WARNINGS);
770 else
771 l_policy_violation_value := C_ALLOW_NO_WARNINGS;
772 end if;
773
774 --Bug 3581975:Select the policy lines with distribution_line_number > 0.
775 SELECT count(*)
776 INTO l_violation_count
777 FROM ap_pol_violations
778 WHERE report_header_id = p_report_header_id
779 and distribution_line_number > 0;
780
781 ------------------------------------------------------------
782 l_debug_info := 'Do NOT set EMP_VIOLATION_NOTE when policy profile is Approver Only';
783 ------------------------------------------------------------
784 IF (l_violation_count > 0) THEN
785 IF (l_policy_violation_value <> C_ALLOW_NO_WARNINGS) THEN
786 FND_MESSAGE.SET_NAME('SQLAP','OIE_WF_VIOLATION_NOTE');
787 l_mess := FND_MESSAGE.GET;
788 iText := iText + 1;
789 l_textNameArr(iText) := 'EMP_VIOLATION_NOTE';
790 l_textValArr(iText) := l_mess;
791 END IF;
792
793 FND_MESSAGE.SET_NAME('SQLAP','OIE_WF_VIOLATION_NOTE');
794 l_mess := FND_MESSAGE.GET;
795 iText := iText + 1;
796 l_textNameArr(iText) := 'VIOLATION_NOTE';
797 l_textValArr(iText) := l_mess;
798
799 ELSE
800 iText := iText + 1;
801 l_textNameArr(iText) := 'VIOLATION_NOTE';
802 l_textValArr(iText) := '';
803
804 END IF;
805
806 -----------------------------------------------------
807 l_debug_info := 'Set MILEAGE_NOTE Item Attribute';
808 -----------------------------------------------------
809 iText := iText + 1;
810 l_textNameArr(iText) := 'MILEAGE_NOTE';
811 l_textValArr(iText) := '';
812
813 -----------------------------------------------------
814 l_debug_info := 'Set VERIFY_NOTE Item Attribute';
815 -----------------------------------------------------
816 iText := iText + 1;
817 l_textNameArr(iText) := 'VERIFY_NOTE';
818 l_textValArr(iText) := '';
819
820 -----------------------------------------------------
821 l_debug_info := 'Set all number Attributes';
822 -----------------------------------------------------
823 WF_ENGINE.SetItemAttrNumberArray(l_item_type, l_item_key, l_numNameArr, l_numValArr);
824
825 -----------------------------------------------------
826 l_debug_info := 'Set all text Attributes';
827 -----------------------------------------------------
828 WF_ENGINE.SetItemAttrTextArray(l_item_type, l_item_key, l_textNameArr, l_textValArr);
829
830 BEGIN
831 IF (NOT l_ResubmitReport and p_event_raised <> 'Y') THEN
832
833 ------------------------------------------------------------
834 l_debug_info := 'Start the Expense Report Workflow Process';
835 ------------------------------------------------------------
836 WF_ENGINE.StartProcess(l_item_type,
837 l_item_key);
838
839 ELSIF (l_ResubmitReport) THEN
840
841 ------------------------------------------------------------
842 l_debug_info := 'clear the header/line level return/audit reason/instructions in AERH/AERL';
843 ------------------------------------------------------------
844 AP_WEB_DB_EXPRPT_PKG.clearAuditReturnReasonInstr(p_report_header_id);
845 AP_WEB_DB_EXPLINE_PKG.clearAuditReturnReasonInstr(p_report_header_id);
846
847 ----------------------------------------------------------
848 l_debug_info := 'clear Item Attribute AUDIT_RETURN_REASON';
849 ---------------------------------------------------------
850 WF_ENGINE.SetItemAttrText(l_item_type,
851 l_item_key,
852 'AUDIT_RETURN_REASON',
853 '');
854
855 ----------------------------------------------------------
856 l_debug_info := 'Set Item Attribute AUDIT_INSTRUCTIONS';
857 ---------------------------------------------------------
858 WF_ENGINE.SetItemAttrText(l_item_type,
859 l_item_key,
860 'AUDIT_INSTRUCTIONS',
861 '');
862
863 ------------------------------------------------------------
864 l_debug_info := 'Restart the Expense Report Workflow Process';
865 ------------------------------------------------------------
866 WF_ENGINE.CompleteActivity(l_item_type,
867 l_item_key,
868 'RESUBMIT_BLOCK',
869 '');
870
871
872 END IF;
873
874 EXCEPTION
875 WHEN OTHERS THEN
876 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'StartExpenseReportProcess',
877 l_item_type, l_item_key, to_char(0), l_debug_info);
878 raise;
879 END;
880 --END IF; --validatesession
881
882 /*Bug 3389386:For Expense report with Both Pay only personal transactions,
883 set the expense_status_code as PAID .
884 */
885 AP_WEB_EXPENSE_WF.SetExpenseStatusCode(p_report_header_id);
886
887 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end StartExpenseReportProcess');
888
889 EXCEPTION
890 WHEN OTHERS THEN
891
892 -- bug 2203689, set workflow_approved_flag to S so that users can
893 -- re-submit the report without re-entering data again
894
895 -- Bug 3248874 : Also set expense_status_code as NULL.
896 -- Source as NonValidateWebExpense.
897
898 UPDATE ap_expense_report_headers erh
899 SET workflow_approved_flag = 'S',
900 expense_status_code = null,
901 source = 'NonValidatedWebExpense'
902 WHERE report_header_id = p_report_header_id;
903 COMMIT;
904
905
906 IF (SQLCODE <> -20001) THEN
907 FND_MESSAGE.SET_NAME('SQLAP','AP_DEBUG');
908 FND_MESSAGE.SET_TOKEN('ERROR',SQLERRM);
909 FND_MESSAGE.SET_TOKEN('CALLING_SEQUENCE', 'StartExpenseReportProcess');
910 FND_MESSAGE.SET_TOKEN('DEBUG_INFO',l_debug_info);
911 END IF;
912
913 -- always raise exceptions regardless it from StartExpenseReportProcess
914 -- or other callees
915 APP_EXCEPTION.RAISE_EXCEPTION;
916
917 END StartExpenseReportProcess;
918
919
920 ---------------------------------------------------
921 PROCEDURE GenerateLineErrorsClob(document_id in varchar2,
922 display_type in varchar2,
923 document in out nocopy clob,
924 document_type in out nocopy varchar2,
925 p_is_ccard in boolean,
926 p_is_ap in boolean) IS
927 ---------------------------------------------------
928
929 l_debug_info VARCHAR2(200);
930
931 l_colon NUMBER;
932 l_item_type VARCHAR2(7);
933 l_item_key VARCHAR2(15);
934
935 l_currency VARCHAR2(50);
936 l_report_header_id AP_WEB_DB_EXPRPT_PKG.expHdr_headerID;
937 l_num_lines NUMBER := 0;
938
939 l_n_org_id Number;
940
941 ---------------------------------------------------------
942 -- local procedure to build table header columns
943 ---------------------------------------------------------
944 PROCEDURE GenTableHeader(document in out nocopy clob,
945 p_is_ccard in boolean,
946 p_is_ap in boolean) IS
947
948 l_prompts AP_WEB_UTILITIES_PKG.prompts_table;
949 l_title AK_REGIONS_VL.name%TYPE;
950 l_table_header VARCHAR2(2000);
951
952 l_debug_info VARCHAR2(200);
953
954 BEGIN
955 ---------------------------------------------------------
956 l_debug_info := 'Get AP_WEB_WF_SS_ERROR prompts';
957 ---------------------------------------------------------
958 AP_WEB_DISC_PKG.getPrompts(200,'AP_WEB_WF_SS_ERROR', l_title, l_prompts);
959
960 ---------------------------------------------------------
961 l_debug_info := 'Build the table column headers for sysadmin/preparer';
962 ---------------------------------------------------------
963 if (p_is_ccard = true) then
964 l_table_header := indent_start || table_title_start || l_prompts(2) || table_title_end;
965 elsif (p_is_ccard = false) then
966 l_table_header := indent_start || table_title_start || l_prompts(3) || table_title_end;
967 end if;
968
969 l_table_header := l_table_header || table_start;
970 l_table_header := l_table_header || tr_start;
971 -- display Line Number
972 l_table_header := l_table_header || th_select || l_prompts(4) || td_end;
973 -- display Date
974 l_table_header := l_table_header || th_text || l_prompts(5) || td_end;
975 -- display Expense Type
976 l_table_header := l_table_header || th_text || l_prompts(6) || td_end;
977 -- display Amount
978 l_table_header := l_table_header || th_number || l_prompts(7) ||' (' || l_currency || ')' || td_end;
979
980 ---------------------------------------------------------
981 l_debug_info := 'Add the Reason column to the Sys Admin table';
982 ---------------------------------------------------------
983 if (p_is_ap = true) then
984 l_table_header := l_table_header || th_text || l_prompts(8) || td_end;
985 end if;
986
987 l_table_header := l_table_header || tr_end;
988
989 WF_NOTIFICATION.WriteToClob(document, l_table_header);
990
991 EXCEPTION
992 WHEN OTHERS THEN
993 IF (SQLCODE <> -20001) THEN
994 FND_MESSAGE.SET_NAME('SQLAP','AP_DEBUG');
995 FND_MESSAGE.SET_TOKEN('ERROR',SQLERRM);
996 FND_MESSAGE.SET_TOKEN('CALLING_SEQUENCE', 'GenTableHeader');
997 FND_MESSAGE.SET_TOKEN('DEBUG_INFO',l_debug_info);
998 END IF;
999 APP_EXCEPTION.RAISE_EXCEPTION;
1000
1001 END GenTableHeader;
1002
1003 ---------------------------------------------------------
1004 -- local procedure to build table rows
1005 ---------------------------------------------------------
1006 PROCEDURE GenTableRows(document in out nocopy clob,
1007 p_is_ccard in boolean,
1008 p_is_ap in boolean) IS
1009
1010 l_prompts AP_WEB_UTILITIES_PKG.prompts_table;
1011 l_title AK_REGIONS_VL.name%TYPE;
1012
1013 l_table_row VARCHAR2(2000);
1014 l_line_num NUMBER := 0;
1015
1016 ExpenseReportLinesCursor AP_WEB_DB_EXPLINE_PKG.XpenseLineAcctCursor;
1017 V_DistLineNumber AP_WEB_DB_EXPLINE_PKG.expLines_distLineNum;
1018 l_report_distribution_id AP_WEB_DB_EXPDIST_PKG.expDist_REPORT_DISTRIBUTION_ID;
1019 V_StartExpenseDate AP_WEB_DB_EXPLINE_PKG.expLines_startExpDate;
1020 V_Amount AP_WEB_DB_EXPLINE_PKG.expLines_amount;
1021 V_ExpenseType AP_EXPENSE_REPORT_PARAMS.web_friendly_prompt%TYPE;
1022 V_CreditCardTrxID AP_WEB_DB_EXPLINE_PKG.expLines_crdCardTrxID;
1023 V_ProjectID AP_WEB_DB_EXPLINE_PKG.expLines_projID;
1024 V_TaskID AP_WEB_DB_EXPLINE_PKG.expLines_taskID;
1025 -- Grants Integration
1026 V_AwardID GMS_OIE_INT_PKG.gms_awardId;
1027 V_AwardSetID NUMBER := NULL;
1028 V_ExpenditureItemDate AP_WEB_DB_EXPLINE_PKG.expLines_expendItemDate;
1029 V_ExpenditureType AP_WEB_DB_EXPLINE_PKG.expLines_expendType;
1030 V_PAQuantity AP_WEB_DB_EXPLINE_PKG.expLines_paQuantity;
1031 V_ExpenditureOrganizationID AP_WEB_DB_EXPLINE_PKG.expLines_expOrgID;
1032 V_WebParamID AP_WEB_DB_EXPLINE_PKG.expLines_webParamID;
1033 V_AdjustmentReason AP_WEB_DB_EXPLINE_PKG.expLines_adjReason;
1034 V_CategoryCode AP_WEB_DB_EXPLINE_PKG.expLines_categorycode;
1035 V_FlexConcactenated AP_EXPENSE_REPORT_PARAMS.flex_concactenated%TYPE;
1036 V_LineAttributeCategory AP_WEB_DB_EXPLINE_PKG.expLines_attrCategory;
1037 V_LineAttribute1 AP_WEB_DB_EXPLINE_PKG.expLines_attr1;
1038 V_LineAttribute2 AP_WEB_DB_EXPLINE_PKG.expLines_attr2;
1039 V_LineAttribute3 AP_WEB_DB_EXPLINE_PKG.expLines_attr3;
1040 V_LineAttribute4 AP_WEB_DB_EXPLINE_PKG.expLines_attr4;
1041 V_LineAttribute5 AP_WEB_DB_EXPLINE_PKG.expLines_attr5;
1042 V_LineAttribute6 AP_WEB_DB_EXPLINE_PKG.expLines_attr6;
1043 V_LineAttribute7 AP_WEB_DB_EXPLINE_PKG.expLines_attr7;
1044 V_LineAttribute8 AP_WEB_DB_EXPLINE_PKG.expLines_attr8;
1045 V_LineAttribute9 AP_WEB_DB_EXPLINE_PKG.expLines_attr9;
1046 V_LineAttribute10 AP_WEB_DB_EXPLINE_PKG.expLines_attr10;
1047 V_LineAttribute11 AP_WEB_DB_EXPLINE_PKG.expLines_attr11;
1048 V_LineAttribute12 AP_WEB_DB_EXPLINE_PKG.expLines_attr12;
1049 V_LineAttribute13 AP_WEB_DB_EXPLINE_PKG.expLines_attr13;
1050 V_LineAttribute14 AP_WEB_DB_EXPLINE_PKG.expLines_attr14;
1051 V_LineAttribute15 AP_WEB_DB_EXPLINE_PKG.expLines_attr15;
1052 V_LineFlexConcat AP_WEB_DB_EXPLINE_PKG.expLines_LineFlexConcat;
1053 V_APValidationError AP_WEB_DB_EXPLINE_PKG.expLines_APValidationError;
1054 V_ReportLineId AP_WEB_DB_EXPLINE_PKG.expLines_report_line_id;
1055
1056
1057 l_debug_info VARCHAR2(200);
1058
1059 BEGIN
1060
1061 ------------------------------------------------------------------------
1062 l_debug_info := 'calling AP_WEB_DB_EXPLINE_PKG.GetExpDistAcctCursor';
1063 ------------------------------------------------------------------------
1064 IF (AP_WEB_DB_EXPLINE_PKG.GetExpDistAcctCursor(l_report_header_id,
1065 ExpenseReportLinesCursor)) THEN
1066
1067 LOOP
1068 FETCH ExpenseReportLinesCursor INTO
1069 V_DistLineNumber,
1070 l_report_distribution_id,
1071 V_StartExpenseDate,
1072 V_Amount,
1073 V_ExpenseType,
1074 V_CreditCardTrxID,
1075 V_ProjectID,
1076 V_TaskID,
1077 V_AwardID,
1078 V_ExpenditureItemDate,
1079 V_ExpenditureType,
1080 V_PAQuantity,
1081 V_ExpenditureOrganizationID,
1082 V_WebParamID,
1083 V_AdjustmentReason,
1084 V_FlexConcactenated,
1085 V_CategoryCode,
1086 V_LineAttributeCategory,
1087 V_LineAttribute1,
1088 V_LineAttribute2,
1089 V_LineAttribute3,
1090 V_LineAttribute4,
1091 V_LineAttribute5,
1092 V_LineAttribute6,
1093 V_LineAttribute7,
1094 V_LineAttribute8,
1095 V_LineAttribute9,
1096 V_LineAttribute10,
1097 V_LineAttribute11,
1098 V_LineAttribute12,
1099 V_LineAttribute13,
1100 V_LineAttribute14,
1101 V_LineAttribute15,
1102 V_LineFlexConcat,
1103 V_APValidationError,
1104 V_ReportLineId;
1105 EXIT WHEN ExpenseReportLinesCursor%NOTFOUND;
1106
1107 ---------------------------------------------------------
1108 l_debug_info := 'Build the row cells for sysadmin/preparer';
1109 ---------------------------------------------------------
1110 if (((p_is_ccard = true and V_CreditCardTrxID is not null) or
1111 (p_is_ccard = false and V_CreditCardTrxID is null)) and
1112 V_APValidationError is not null) then
1113
1114 l_line_num := l_line_num + 1;
1115
1116 l_table_row := tr_start;
1117 l_table_row := l_table_row || td_select || to_char(l_line_num) || td_end;
1118 l_table_row := l_table_row || td_text || V_StartExpenseDate || td_end;
1119 l_table_row := l_table_row || td_text || V_ExpenseType || td_end;
1120 l_table_row := l_table_row || td_number || to_char(V_Amount, FND_CURRENCY.Get_Format_Mask(l_currency,22)) || td_end;
1121
1122 ---------------------------------------------------------
1123 l_debug_info := 'Add the Reason column to the Sys Admin table';
1124 ---------------------------------------------------------
1125 if (p_is_ap = true) then
1126 l_table_row := l_table_row || td_text || V_APValidationError || td_end;
1127 end if;
1128
1129 l_table_row := l_table_row || tr_end;
1130
1131 WF_NOTIFICATION.WriteToClob(document, l_table_row);
1132 end if;
1133
1134 END LOOP; /* ExpenseReportLinesCursor */
1135
1136 END IF; /* GetExpDistAcctCursor */
1137
1138 if ExpenseReportLinesCursor%isopen then
1139 CLOSE ExpenseReportLinesCursor;
1140 end if;
1141
1142 l_table_row := table_end || indent_end;
1143
1144 WF_NOTIFICATION.WriteToClob(document, l_table_row);
1145
1146 EXCEPTION
1147 WHEN OTHERS THEN
1148 IF (SQLCODE <> -20001) THEN
1149 FND_MESSAGE.SET_NAME('SQLAP','AP_DEBUG');
1150 FND_MESSAGE.SET_TOKEN('ERROR',SQLERRM);
1151 FND_MESSAGE.SET_TOKEN('CALLING_SEQUENCE', 'GenTableRows');
1152 FND_MESSAGE.SET_TOKEN('DEBUG_INFO',l_debug_info);
1153 END IF;
1154 APP_EXCEPTION.RAISE_EXCEPTION;
1155
1156 END GenTableRows;
1157
1158 BEGIN
1159
1160 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start GenerateLineErrorsClob');
1161
1162 ------------------------------------------------------------
1163 l_debug_info := 'Decode document_id';
1164 ------------------------------------------------------------
1165 l_colon := instrb(document_id, ':');
1166 l_item_type := substrb(document_id, 1, l_colon - 1);
1167 l_item_key := substrb(document_id, l_colon + 1);
1168
1169 ----------------------------------------------------
1170 l_debug_info := 'Retrieve Currency Item Attribute';
1171 ----------------------------------------------------
1172 l_currency := WF_ENGINE.GetItemAttrText(l_item_type,
1173 l_item_key,
1174 'CURRENCY');
1175
1176 ------------------------------------------------------------
1177 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
1178 ------------------------------------------------------------
1179 l_report_header_id := WF_ENGINE.GetItemAttrNumber(l_item_type,
1180 l_item_key,
1181 'EXPENSE_REPORT_ID');
1182
1183 --------------------------------------------
1184 l_debug_info := 'Get Org Id';
1185 --------------------------------------------
1186 begin
1187
1188 l_n_org_id := WF_ENGINE.GetItemAttrNumber(l_item_type,
1189 l_item_key,
1190 'ORG_ID');
1191 exception
1192 when others then
1193 if (wf_core.error_name = 'WFENG_ITEM_ATTR') then
1194 -- ORG_ID item attribute doesn't exist, need to add it
1195 WF_ENGINE.AddItemAttr(l_item_type, l_item_key, 'ORG_ID');
1196 IF (AP_WEB_DB_EXPRPT_PKG.GetOrgIdByReportHeaderId(
1197 to_number(l_item_key),
1198 l_n_org_id) <> TRUE ) THEN
1199 l_n_org_id := NULL;
1200 END IF;
1201
1202 WF_ENGINE.SetItemAttrNumber(l_item_type,
1203 l_item_key,
1204 'ORG_ID',
1205 l_n_org_ID);
1206 else
1207 raise;
1208 end if;
1209
1210 end;
1211
1212 -- MOAC UPTAKE --
1213 -- Should not have to initialize the org context
1214 -- This is done via callbackfunction()
1215 /*--------------------
1216 if (l_n_org_id is not null) then
1217 fnd_client_info.set_org_context(l_n_org_id);
1218 else
1219 -- Report was submitted before org_id being added, hence org_id
1220 -- item attributes hasn't been set yet. Need to get it from
1221 -- report header
1222 IF (AP_WEB_DB_EXPRPT_PKG.GetOrgIdByReportHeaderId(to_number(l_item_key), l_n_org_id) <> TRUE ) THEN
1223 l_n_org_id := NULL;
1224 END IF;
1225
1226 IF (l_n_org_id is not null) then
1227 fnd_client_info.set_org_context(l_n_org_id);
1228 END IF;
1229 end if; -- l_n_org_id
1230 ----------------------*/
1231
1232 if (p_is_ccard) then
1233
1234 ------------------------------------------------------------
1235 l_debug_info := 'Checking number of credit card lines with errors';
1236 ------------------------------------------------------------
1237 select count(*)
1238 into l_num_lines
1239 from ap_expense_report_lines
1240 where report_header_id = l_report_header_id
1241 and credit_card_trx_id is not null
1242 and ap_validation_error is not null;
1243
1244 if (l_num_lines = 0) then
1245 return;
1246 end if;
1247
1248 else
1249
1250 ------------------------------------------------------------
1251 l_debug_info := 'Checking number of cash lines with errors';
1252 ------------------------------------------------------------
1253 select count(*)
1254 into l_num_lines
1255 from ap_expense_report_lines
1256 where report_header_id = l_report_header_id
1257 and credit_card_trx_id is null
1258 and ap_validation_error is not null;
1259
1260 if (l_num_lines = 0) then
1261 return;
1262 end if;
1263
1264 end if;
1265
1266 GenTableHeader(document, p_is_ccard, p_is_ap);
1267 GenTableRows(document, p_is_ccard, p_is_ap);
1268
1269 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end GenerateLineErrorsClob');
1270
1271 EXCEPTION
1272 WHEN OTHERS THEN
1273 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'GenerateLineErrorsClob',
1274 document_id, l_debug_info);
1275 raise;
1276 END GenerateLineErrorsClob;
1277
1278 ---------------------------------------------------
1279 PROCEDURE CashLineErrorsAP(document_id in varchar2,
1280 display_type in varchar2,
1281 document in out nocopy clob,
1282 document_type in out nocopy varchar2) IS
1283 ---------------------------------------------------
1284
1285 l_debug_info VARCHAR2(200);
1286
1287 BEGIN
1288
1289 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start CashLineErrorsAP');
1290
1291 GenerateLineErrorsClob(document_id,
1292 display_type,
1293 document,
1294 document_type,
1295 p_is_ccard => false,
1296 p_is_ap => true);
1297
1298 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end CashLineErrorsAP');
1299
1300 EXCEPTION
1301 WHEN OTHERS THEN
1302 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'CashLineErrorsAP',
1303 document_id, l_debug_info);
1304 raise;
1305 END CashLineErrorsAP;
1306
1307 ---------------------------------------------------
1308 PROCEDURE CashLineErrorsPreparer(document_id in varchar2,
1309 display_type in varchar2,
1310 document in out nocopy clob,
1311 document_type in out nocopy varchar2) IS
1312 ---------------------------------------------------
1313
1314 l_debug_info VARCHAR2(200);
1315
1316 BEGIN
1317
1318 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start CashLineErrorsPreparer');
1319
1320 GenerateLineErrorsClob(document_id,
1321 display_type,
1322 document,
1323 document_type,
1324 p_is_ccard => false,
1325 p_is_ap => false);
1326
1327 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end CashLineErrorsPreparer');
1328
1329 EXCEPTION
1330 WHEN OTHERS THEN
1331 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'CashLineErrorsPreparer',
1332 document_id, l_debug_info);
1333 raise;
1334 END CashLineErrorsPreparer;
1335
1336 ---------------------------------------------------
1337 PROCEDURE CCardLineErrorsAP(document_id in varchar2,
1338 display_type in varchar2,
1339 document in out nocopy clob,
1340 document_type in out nocopy varchar2) IS
1341 ---------------------------------------------------
1342
1343 l_debug_info VARCHAR2(200);
1344
1345 BEGIN
1346
1347 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start CCardLineErrorsAP');
1348
1349 GenerateLineErrorsClob(document_id,
1350 display_type,
1351 document,
1352 document_type,
1353 p_is_ccard => true,
1354 p_is_ap => true);
1355
1356 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end CCardLineErrorsAP');
1357
1358 EXCEPTION
1359 WHEN OTHERS THEN
1360 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'CCardLineErrorsAP',
1361 document_id, l_debug_info);
1362 raise;
1363 END CCardLineErrorsAP;
1364
1365 ---------------------------------------------------
1366 PROCEDURE CCardLineErrorsPreparer(document_id in varchar2,
1367 display_type in varchar2,
1368 document in out nocopy clob,
1369 document_type in out nocopy varchar2) IS
1370 ---------------------------------------------------
1371
1372 l_debug_info VARCHAR2(200);
1373
1374 BEGIN
1375
1376 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start CCardLineErrorsPreparer');
1377
1378 GenerateLineErrorsClob(document_id,
1379 display_type,
1380 document,
1381 document_type,
1382 p_is_ccard => true,
1383 p_is_ap => false);
1384
1385 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end CCardLineErrorsPreparer');
1386
1387 EXCEPTION
1388 WHEN OTHERS THEN
1389 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'CCardLineErrorsPreparer',
1390 document_id, l_debug_info);
1391 raise;
1392 END CCardLineErrorsPreparer;
1393
1394
1395
1396
1397
1398 ---------------------------------------------------
1399 PROCEDURE ResetAPValidationAttrValues(p_item_type IN VARCHAR2,
1400 p_item_key IN VARCHAR2,
1401 p_actid IN NUMBER)
1402 ---------------------------------------------------
1403 IS
1404 --
1405 -- Reset the AP Validation attribute values which are not set explicitly by
1406 -- StartExpenseReportProcess before the returned report is resubmitted.
1407 -- We need to clear these because we will be revisiting nodes in the process.
1408 --
1409
1410 l_textNameArr Wf_Engine.NameTabTyp;
1411 l_textValArr Wf_Engine.TextTabTyp;
1412 iText NUMBER :=0;
1413
1414 l_report_header_id NUMBER;
1415 C_WF_Version NUMBER := 0;
1416
1417 l_debug_info VARCHAR2(200);
1418
1419 BEGIN
1420
1421 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start ResetAPValidationAttrValues');
1422
1423 ----------------------------------------------------------------
1424 l_debug_info := 'Unset Header and Setup errors';
1425 -----------------------------------------------------------------
1426 iText := iText + 1;
1427 l_textNameArr(iText) := 'HEADER_ERRORS';
1428 l_textValArr(iText) := '';
1429
1430 ------------------------------------------------------------
1431 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
1432 ------------------------------------------------------------
1433 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
1434 p_item_key,
1435 'EXPENSE_REPORT_ID');
1436
1437 ------------------------------------------------------
1438 l_debug_info := 'Get version of Workflow';
1439 ------------------------------------------------------
1440 C_WF_Version := GetFlowVersion(p_item_type, p_item_key);
1441
1442 ------------------------------------------------------
1443 l_debug_info := 'Set GEN_HEADER_ERRORS Item Attribute';
1444 ------------------------------------------------------
1445 iText := iText + 1;
1446 l_textNameArr(iText) := 'GEN_HEADER_ERRORS';
1447 l_textValArr(iText) := 'plsql:AP_WEB_EXPENSE_WF.GenerateHeaderErrors/'||p_item_type||':'||p_item_key;
1448
1449 ------------------------------------------------------
1450 l_debug_info := 'Set CASH_LINE_ERRORS_AP Item Attribute';
1451 ------------------------------------------------------
1452 iText := iText + 1;
1453 l_textNameArr(iText) := 'CASH_LINE_ERRORS_AP';
1454 l_textValArr(iText) := 'plsqlclob:AP_WEB_EXPENSE_WF.CashLineErrorsAP/'||p_item_type||':'||p_item_key;
1455
1456 ------------------------------------------------------
1457 l_debug_info := 'Set CASH_LINE_ERRORS_PREPARER Item Attribute';
1458 ------------------------------------------------------
1459 iText := iText + 1;
1460 l_textNameArr(iText) := 'CASH_LINE_ERRORS_PREPARER';
1461 l_textValArr(iText) := 'plsqlclob:AP_WEB_EXPENSE_WF.CashLineErrorsPreparer/'||p_item_type||':'||p_item_key;
1462
1463 ------------------------------------------------------
1464 l_debug_info := 'Set CCARD_LINE_ERRORS_AP Item Attribute';
1465 ------------------------------------------------------
1466 iText := iText + 1;
1467 l_textNameArr(iText) := 'CCARD_LINE_ERRORS_AP';
1468 l_textValArr(iText) := 'plsqlclob:AP_WEB_EXPENSE_WF.CCardLineErrorsAP/'||p_item_type||':'||p_item_key;
1469
1470 ------------------------------------------------------
1471 l_debug_info := 'Set CCARD_LINE_ERRORS_PREPARER Item Attribute';
1472 ------------------------------------------------------
1473 iText := iText + 1;
1474 l_textNameArr(iText) := 'CCARD_LINE_ERRORS_PREPARER';
1475 l_textValArr(iText) := 'plsqlclob:AP_WEB_EXPENSE_WF.CCardLineErrorsPreparer/'||p_item_type||':'||p_item_key;
1476
1477 ----------------------------------------------------------------
1478 l_debug_info := 'Reset AP Validation errors';
1479 -----------------------------------------------------------------
1480 AP_WEB_DB_EXPLINE_PKG.ResetAPValidationErrors(l_report_header_id);
1481
1482 ----------------------------------------------------------------
1483 l_debug_info := 'Unset Is Default Cost Center Used?';
1484 -----------------------------------------------------------------
1485 iText := iText + 1;
1486 l_textNameArr(iText) := 'IS_DEFAULT_COST_CENTER_USED';
1487 l_textValArr(iText) := '';
1488
1489 ----------------------------------------------------------------
1490 l_debug_info := 'Unset Is Projects Expense Report?';
1491 -----------------------------------------------------------------
1492 iText := iText + 1;
1493 l_textNameArr(iText) := 'IS_PROJECTS_REPORT';
1494 l_textValArr(iText) := '';
1495
1496 ----------------------------------------------------------------
1497 l_debug_info := 'Unset WF Administrators Note';
1498 -----------------------------------------------------------------
1499 iText := iText + 1;
1500 l_textNameArr(iText) := 'WF_ADMIN_NOTE';
1501 l_textValArr(iText) := '';
1502
1503 ----------------------------------------------------------------
1504 l_debug_info := 'Unset EXP_ALLOCATION_ERRORS';
1505 -----------------------------------------------------------------
1506 IF (C_WF_Version >= AP_WEB_EXPENSE_WF.C_OIEJ_Version) THEN
1507 iText := iText + 1;
1508 l_textNameArr(iText) := 'EXP_ALLOCATION_ERRORS';
1509 l_textValArr(iText) := '';
1510 END IF;
1511
1512 -----------------------------------------------------
1513 l_debug_info := 'Set all text Attributes';
1514 -----------------------------------------------------
1515 WF_ENGINE.SetItemAttrTextArray(p_item_type, p_item_key, l_textNameArr, l_textValArr);
1516
1517
1518 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end ResetAPValidationAttrValues');
1519
1520 EXCEPTION
1521 WHEN OTHERS THEN
1522 NULL;
1523 END ResetAPValidationAttrValues;
1524
1525 ------------------------------------------------------------------------
1526 PROCEDURE APValidateExpenseReport(p_item_type IN VARCHAR2,
1527 p_item_key IN VARCHAR2,
1528 p_actid IN NUMBER,
1529 p_funmode IN VARCHAR2,
1530 p_result OUT NOCOPY VARCHAR2) IS
1531 ------------------------------------------------------------------------
1532 l_report_header_id AP_WEB_DB_EXPRPT_PKG.expHdr_headerID;
1533
1534 l_emp_cost_center VARCHAR2(240);
1535 l_doc_cost_center VARCHAR2(240);
1536
1537 l_header_errors VARCHAR2(2000) := NULL;
1538 l_other_errors VARCHAR2(2000) := NULL;
1539 l_exp_alloc_errors VARCHAR2(2000) := NULL;
1540 l_num_line_errors NUMBER := 0;
1541
1542 l_yes VARCHAR2(80);
1543 l_no VARCHAR2(80);
1544
1545 l_debug_info VARCHAR2(200);
1546 C_WF_Version NUMBER := 0;
1547
1548
1549 BEGIN
1550
1551 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start APValidateExpenseReport');
1552
1553 IF (p_funmode = 'RUN') THEN
1554
1555 ------------------------------------------------------------
1556 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
1557 ------------------------------------------------------------
1558 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
1559 p_item_key,
1560 'EXPENSE_REPORT_ID');
1561
1562 ----------------------------------------------------------------
1563 l_debug_info := 'Reset AP Validation Attributes';
1564 ----------------------------------------------------------------
1565 ResetAPValidationAttrValues(p_item_type,
1566 p_item_key,
1567 p_actid);
1568
1569 ---------------------------------------
1570 l_debug_info := 'Call DoAPValidation';
1571 ---------------------------------------
1572 DoAPValidation(p_item_type,
1573 p_item_key,
1574 l_report_header_id);
1575
1576 ------------------------------------------------------------
1577 l_debug_info := 'Retrieve HEADER_ERRORS Item Attribute';
1578 ------------------------------------------------------------
1579 l_header_errors := WF_ENGINE.GetItemAttrText(p_item_type,
1580 p_item_key,
1581 'HEADER_ERRORS');
1582 if (l_header_errors IS NOT NULL) then
1583 WF_ENGINE.SetItemAttrText(p_item_type,
1584 p_item_key,
1585 'HEADER_ERRORS',
1586 l_header_errors || '<br>');
1587 end if;
1588
1589 ------------------------------------------------------------
1590 l_debug_info := 'Retrieve OTHER_ERRORS Item Attribute';
1591 ------------------------------------------------------------
1592 l_other_errors := WF_ENGINE.GetItemAttrText(p_item_type,
1593 p_item_key,
1594 'OTHER_ERRORS');
1595 if (l_other_errors IS NOT NULL) then
1596 WF_ENGINE.SetItemAttrText(p_item_type,
1597 p_item_key,
1598 'OTHER_ERRORS',
1599 l_other_errors || '<br>');
1600 end if;
1601
1602 ------------------------------------------------------
1603 l_debug_info := 'Get version of Workflow';
1604 ------------------------------------------------------
1605 C_WF_Version := GetFlowVersion(p_item_type, p_item_key);
1606
1607 ------------------------------------------------------------
1608 l_debug_info := 'Retrieve EXP_ALLOCATION_ERRORS Item Attribute';
1609 ------------------------------------------------------------
1610 IF (C_WF_Version >= AP_WEB_EXPENSE_WF.C_OIEJ_Version) THEN
1611 l_exp_alloc_errors := WF_ENGINE.GetItemAttrText(p_item_type,
1612 p_item_key,
1613 'EXP_ALLOCATION_ERRORS',
1614 true);
1615 if (l_exp_alloc_errors IS NOT NULL) then
1616 WF_ENGINE.SetItemAttrText(p_item_type,
1617 p_item_key,
1618 'EXP_ALLOCATION_ERRORS',
1619 l_exp_alloc_errors );
1620 end if;
1621 END IF;
1622
1623 ----------------------------------------------------------------
1624 l_debug_info := 'Retrieve Employee Cost Center Item Attribute';
1625 ----------------------------------------------------------------
1626 l_emp_cost_center := WF_ENGINE.GetItemAttrText(p_item_type,
1627 p_item_key,
1628 'EMP_COST_CENTER');
1629
1630 ----------------------------------------------------------------
1631 l_debug_info := 'Retrieve Document Cost Center Item Attribute';
1632 ----------------------------------------------------------------
1633 l_doc_cost_center := WF_ENGINE.GetItemAttrText(p_item_type,
1634 p_item_key,
1635 'DOC_COST_CENTER');
1636
1637 ----------------------------------------------------------------
1638 l_debug_info := 'Set IS_DEFAULT_COST_CENTER_USED';
1639 ----------------------------------------------------------------
1640 if (l_emp_cost_center = l_doc_cost_center) then
1641
1642 SELECT fndl.meaning
1643 INTO l_yes
1644 FROM FND_LOOKUPS fndl
1645 WHERE fndl.LOOKUP_TYPE = C_YES_NO
1646 AND fndl.LOOKUP_CODE = C_Y;
1647
1648 WF_ENGINE.SetItemAttrText(p_item_type,
1649 p_item_key,
1650 'IS_DEFAULT_COST_CENTER_USED',
1651 l_yes);
1652 else
1653
1654 SELECT fndl.meaning
1655 INTO l_no
1656 FROM FND_LOOKUPS fndl
1657 WHERE fndl.LOOKUP_TYPE = C_YES_NO
1658 AND fndl.LOOKUP_CODE = C_N;
1659
1660 WF_ENGINE.SetItemAttrText(p_item_type,
1661 p_item_key,
1662 'IS_DEFAULT_COST_CENTER_USED',
1663 l_no);
1664 end if;
1665
1666 ----------------------------------------------------------------
1667 l_debug_info := 'Get number of line errors';
1668 -----------------------------------------------------------------
1669 select count(*)
1670 into l_num_line_errors
1671 from ap_expense_report_lines
1672 where report_header_id = l_report_header_id
1673 and ap_validation_error is not null;
1674
1675 ----------------------------------------------------------------
1676 l_debug_info := 'Return Pass If No Header or Line Errors,
1677 otherwise Return Fail';
1678 -----------------------------------------------------------------
1679 IF (l_header_errors IS NULL AND l_num_line_errors = 0 AND l_other_errors IS NULL) then
1680 p_result := 'COMPLETE:AP_PASS';
1681 ELSIF (l_exp_alloc_errors is not null) THEN
1682 p_result := 'COMPLETE:AP_FAIL_EXP_ALLOC';
1683 ELSE
1684 p_result := 'COMPLETE:AP_FAIL';
1685 /*
1686 The following item attributes are also set:
1687 1. Cost Center Entered = DOC_COST_CENTER
1688 This is already set in the WF process
1689 2. IS_DEFAULT_COST_CENTER_USED = 'Yes'/'No'
1690 This is set in APValidateExpenseReport()
1691 3. IS_PROJECTS_REPORT = 'Yes' if report contains Projects lines
1692 This is set in DoAPValidation()
1693 */
1694
1695 END IF;
1696
1697 ELSIF (p_funmode = 'CANCEL') THEN
1698
1699 p_result := 'COMPLETE';
1700
1701 END IF;
1702
1703 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end APValidateExpenseReport');
1704
1705 EXCEPTION
1706 WHEN OTHERS THEN
1707 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'APValidateExpenseReport',
1708 p_item_type, p_item_key, to_char(0), l_debug_info || FND_MESSAGE.GET);
1709 raise;
1710 END APValidateExpenseReport;
1711
1712 ------------------------------------------------------------------------
1713 PROCEDURE AddToWFSSError(p_error_message IN OUT NOCOPY VARCHAR2,
1714 p_new_error IN VARCHAR2) IS
1715 ------------------------------------------------------------------------
1716 l_exceed_error_msg VARCHAR2(80) := 'Error message has exceeded 2000 char limit.';
1717 BEGIN
1718 -- check to see if exceed error message has already been appended
1719 if (instrb(p_error_message, l_exceed_error_msg) = 0) then
1720 if ((lengthb(p_error_message) + lengthb(p_new_error) + lengthb(l_exceed_error_msg)) > 1950) then
1721 p_error_message := p_error_message || l_exceed_error_msg;
1722 else
1723 p_error_message := p_error_message || p_new_error;
1724 end if;
1725 end if;
1726 EXCEPTION
1727 WHEN OTHERS THEN
1728 IF (SQLCODE <> -20001) THEN
1729 FND_MESSAGE.SET_NAME('SQLAP','AP_DEBUG');
1730 FND_MESSAGE.SET_TOKEN('ERROR',SQLERRM);
1731 FND_MESSAGE.SET_TOKEN('CALLING_SEQUENCE', 'AddToWFSSError');
1732 FND_MESSAGE.SET_TOKEN('DEBUG_INFO',l_exceed_error_msg);
1733 END IF;
1734 APP_EXCEPTION.RAISE_EXCEPTION;
1735
1736 END AddToWFSSError;
1737
1738 ----------------------------------------------------------------------
1739 PROCEDURE AddToHeaderErrors(p_item_type IN VARCHAR2,
1740 p_item_key IN VARCHAR2,
1741 p_header_error IN VARCHAR2) IS
1742 ----------------------------------------------------------------------
1743
1744 l_header_errors VARCHAR2(2000) := NULL;
1745
1746 l_prompts AP_WEB_UTILITIES_PKG.prompts_table;
1747 l_title AK_REGIONS_VL.name%TYPE;
1748
1749 l_debug_info VARCHAR2(2000);
1750
1751 BEGIN
1752
1753 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start AddToHeaderErrors');
1754
1755 ---------------------------------------------------------
1756 l_debug_info := 'Add to Header Errors';
1757 ---------------------------------------------------------
1758 l_header_errors := WF_ENGINE.GetItemAttrText(p_item_type,
1759 p_item_key,
1760 'HEADER_ERRORS');
1761 ---------------------------------------------------------
1762 l_debug_info := 'Check to see if error title needed';
1763 ---------------------------------------------------------
1764 if (l_header_errors IS NULL) then
1765 ---------------------------------------------------------
1766 l_debug_info := 'Add font tag';
1767 ---------------------------------------------------------
1768 l_header_errors := startOraFieldTextFont;
1769 else
1770 l_header_errors := l_header_errors || '<br>';
1771 end if;
1772
1773 AddToWFSSError(l_header_errors, p_header_error);
1774
1775 l_header_errors := l_header_errors || endOraFieldTextFont;
1776
1777 WF_ENGINE.SetItemAttrText(p_item_type,
1778 p_item_key,
1779 'HEADER_ERRORS',
1780 l_header_errors);
1781
1782 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end AddToHeaderErrors');
1783
1784 EXCEPTION
1785 WHEN OTHERS THEN
1786 IF (SQLCODE <> -20001) THEN
1787 FND_MESSAGE.SET_NAME('SQLAP','AP_DEBUG');
1788 FND_MESSAGE.SET_TOKEN('ERROR',SQLERRM);
1789 FND_MESSAGE.SET_TOKEN('CALLING_SEQUENCE', 'AddToHeaderErrors');
1790 FND_MESSAGE.SET_TOKEN('DEBUG_INFO',l_debug_info);
1791 END IF;
1792 APP_EXCEPTION.RAISE_EXCEPTION;
1793
1794 END AddToHeaderErrors;
1795
1796
1797 ----------------------------------------------------------------------
1798 PROCEDURE HandleInvalidDistCCID(p_report_header_id IN AP_EXPENSE_REPORT_HEADERS.report_header_id%TYPE,
1799 p_report_distribution_id IN AP_WEB_DB_EXPDIST_PKG.expDist_REPORT_DISTRIBUTION_ID,
1800 p_payment_due IN VARCHAR2,
1801 p_exp_type_parameter_id IN AP_WEB_DB_EXPLINE_PKG.expLines_webParamID,
1802 p_personalParameterId IN AP_WEB_DB_EXPLINE_PKG.expLines_webParamID,
1803 p_CategoryCode IN AP_WEB_DB_EXPLINE_PKG.expLines_categorycode,
1804 p_default_emp_segments IN AP_OIE_KFF_SEGMENTS_T,
1805 p_dist_new_segments IN AP_OIE_KFF_SEGMENTS_T,
1806 p_ReportLineId IN AP_WEB_DB_EXPLINE_PKG.expLines_report_line_id,
1807 p_exp_dist_ccid IN AP_WEB_DB_EXPLINE_PKG.expLines_codeCombID,
1808 p_chart_of_accounts_id IN AP_WEB_DB_AP_INT_PKG.glsob_chartOfAccountsID) IS
1809 ----------------------------------------------------------------------
1810 l_debug_info VARCHAR2(1000);
1811
1812 l_new_segments AP_OIE_KFF_SEGMENTS_T;
1813
1814 BEGIN
1815
1816 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start HandleInvalidDistCCID');
1817
1818 if (p_report_distribution_id is null) then
1819 if ((p_payment_due = C_CompanyPay AND p_exp_type_parameter_id = p_personalParameterId) or
1820 (p_CategoryCode = C_ROUNDING))then
1821 -- if dist does not exist then it adds dist and then updates
1822 -- ccid and segments based on p_exp_dist_ccid
1823 AP_WEB_DB_EXPDIST_PKG.updateAccountValues (
1824 p_report_header_id => p_report_header_id,
1825 p_report_line_id => p_ReportLineId,
1826 p_report_distribution_id => p_report_distribution_id,
1827 p_ccid => p_exp_dist_ccid);
1828 else
1829 -- When error occurs building the ccid we should update the
1830 -- dist table with the correct segments which caused the issue
1831
1832 -----------------------------------------------------
1833 l_debug_info := 'Assign values to l_new_segments';
1834 -----------------------------------------------------
1835 l_new_segments := AP_OIE_KFF_SEGMENTS_T('');
1836 l_new_segments.extend(p_default_emp_segments.count);
1837 FOR i IN 1..p_default_emp_segments.count LOOP
1838 l_new_segments(i) := nvl(p_dist_new_segments(i),p_default_emp_segments(i));
1839 END LOOP;
1840
1841 -----------------------------------------------------
1842 l_debug_info := 'Add Dist for Line';
1843 -----------------------------------------------------
1844 AP_WEB_DB_EXPDIST_PKG.AddDistributionLine(
1845 p_segments => l_new_segments,
1846 p_report_line_id => p_ReportLineId,
1847 p_chart_of_accounts_id => p_chart_of_accounts_id);
1848 end if;
1849 end if; -- (p_report_distribution_id is null)
1850
1851 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end HandleInvalidDistCCID');
1852
1853 EXCEPTION
1854 WHEN OTHERS THEN
1855 IF (SQLCODE <> -20001) THEN
1856 FND_MESSAGE.SET_NAME('SQLAP','AP_DEBUG');
1857 FND_MESSAGE.SET_TOKEN('ERROR',SQLERRM);
1858 FND_MESSAGE.SET_TOKEN('CALLING_SEQUENCE', 'HandleInvalidDistCCID');
1859 FND_MESSAGE.SET_TOKEN('DEBUG_INFO',l_debug_info);
1860 END IF;
1861 APP_EXCEPTION.RAISE_EXCEPTION;
1862 END HandleInvalidDistCCID;
1863
1864
1865 ----------------------------------------------------------------------
1866 PROCEDURE DoAPValidation(p_item_type IN VARCHAR2,
1867 p_item_key IN VARCHAR2,
1868 p_report_header_id IN AP_EXPENSE_REPORT_HEADERS.report_header_id%TYPE) IS
1869 ----------------------------------------------------------------------
1870 l_sys_apply_advances_default AP_WEB_DB_AP_INT_PKG.apSetUp_applyAdvDefault;
1871 l_sys_allow_awt_flag AP_WEB_DB_AP_INT_PKG.apSetUp_allowAwtFlag;
1872 l_sys_default_xrate_type AP_WEB_DB_AP_INT_PKG.apSetUp_defaultExchRateType;
1873 l_sys_make_rate_mandatory AP_WEB_DB_AP_INT_PKG.apSetUp_makeMandatoryFlag;
1874 l_chart_of_accounts_id AP_WEB_DB_AP_INT_PKG.glsob_chartOfAccountsID;
1875 l_default_currency_code AP_WEB_DB_EXPRPT_PKG.expHdr_defaultCurrCode;
1876 l_week_end_date AP_WEB_DB_EXPRPT_PKG.expHdr_weekEndDate;
1877 l_exp_check_address_flag AP_WEB_DB_HR_INT_PKG.empCurrent_checkAddrFlag;
1878 l_ven_allow_awt_flag AP_WEB_DB_AP_INT_PKG.vendors_allowAWTFlag;
1879 l_ven_awt_group_id AP_WEB_DB_AP_INT_PKG.vendors_awtGroupID;
1880 l_default_emp_ccid AP_WEB_DB_HR_INT_PKG.empCurrent_defaultCodeCombID;
1881 l_default_emp_segments AP_OIE_KFF_SEGMENTS_T;
1882 l_exp_dist_ccid AP_WEB_DB_EXPLINE_PKG.expLines_codeCombID;
1883 l_id_flex_structure_name fnd_id_flex_structures_vl.id_flex_structure_name%TYPE;
1884
1885 l_employee_ccid AP_WEB_DB_EXPRPT_PKG.expHdr_employeeCCID;
1886 l_employee_id AP_WEB_DB_EXPRPT_PKG.expHdr_employeeID;
1887 l_personalParameterId AP_WEB_DB_EXPTEMPLATE_PKG.expTempl_paramID;
1888 l_category AP_WEB_DB_CCARD_PKG.ccTrxn_category;
1889 l_default_exchange_rate AP_WEB_DB_EXPRPT_PKG.expHdr_defaultExchRate;
1890 l_base_currency_code AP_WEB_DB_AP_INT_PKG.apSetUp_baseCurrencyCode;
1891 l_sys_base_currency_code AP_WEB_DB_AP_INT_PKG.apSetUp_baseCurrencyCode;
1892 exchange_rate_exception EXCEPTION;
1893 l_available_prepays NUMBER;
1894 l_payment_due VARCHAR2(10) := C_IndividualPay;
1895
1896 l_debug_info VARCHAR2(1000);
1897
1898 V_PADefaultDistCCID AP_WEB_DB_EXPLINE_PKG.expLines_codeCombID;
1899 V_ConcatSegs VARCHAR2(2000);
1900 V_ConcatIDs VARCHAR2(2000);
1901 V_ConcatDescrs VARCHAR2(300);
1902 V_ErrMsg VARCHAR2(2000);--2048712
1903 V_ProcedureReturnCode VARCHAR2(2000);
1904 V_ProcedureBillableFlag VARCHAR2(200);
1905 V_PATCMsgType VARCHAR2(10); -- Value not used in 11.0, but used in 11.5+
1906
1907 V_DefaultExchangeRateType AP_WEB_DB_AP_INT_PKG.apSetUp_defaultExchRateType; -- For PATC: Exchange rate type in AP
1908 V_BaseCurrencyCode AP_WEB_DB_AP_INT_PKG.apSetUp_baseCurrencyCode; -- For PATC: Functional currency
1909 V_ReimbCurrencyCode VARCHAR2(15);
1910 V_DefaultExchangeRate NUMBER; -- For PATC: Exchange rate for func->reimb
1911 V_AcctRawCost NUMBER; -- For PATC: Receipt amount in functional currency
1912 V_WeekEndDate DATE;
1913 C_WF_Version NUMBER := 0;
1914 l_SysInfoRec AP_WEB_DB_AP_INT_PKG.APSysInfoRec;
1915
1916 l_error_message VARCHAR2(2000);
1917
1918 V_UserID NUMBER;
1919 V_UserName VARCHAR2(30);
1920 V_VendorID AP_WEB_DB_AP_INT_PKG.vendors_vendorID;
1921 V_IsSessionProjectEnabled VARCHAR2(1);
1922
1923 V_EmployeeID AP_WEB_DB_EXPRPT_PKG.expHdr_employeeID;
1924 l_cost_center AP_WEB_DB_EXPRPT_PKG.expHdr_flexConcat;
1925 V_HeaderAttributeCategory AP_WEB_DB_EXPRPT_PKG.expHdr_attrCategory;
1926 V_HeaderAttribute1 AP_WEB_DB_EXPRPT_PKG.expHdr_attr1;
1927 V_HeaderAttribute2 AP_WEB_DB_EXPRPT_PKG.expHdr_attr2;
1928 V_HeaderAttribute3 AP_WEB_DB_EXPRPT_PKG.expHdr_attr3;
1929 V_HeaderAttribute4 AP_WEB_DB_EXPRPT_PKG.expHdr_attr4;
1930 V_HeaderAttribute5 AP_WEB_DB_EXPRPT_PKG.expHdr_attr5;
1931 V_HeaderAttribute6 AP_WEB_DB_EXPRPT_PKG.expHdr_attr6;
1932 V_HeaderAttribute7 AP_WEB_DB_EXPRPT_PKG.expHdr_attr7;
1933 V_HeaderAttribute8 AP_WEB_DB_EXPRPT_PKG.expHdr_attr8;
1934 V_HeaderAttribute9 AP_WEB_DB_EXPRPT_PKG.expHdr_attr9;
1935 V_HeaderAttribute10 AP_WEB_DB_EXPRPT_PKG.expHdr_attr10;
1936 V_HeaderAttribute11 AP_WEB_DB_EXPRPT_PKG.expHdr_attr11;
1937 V_HeaderAttribute12 AP_WEB_DB_EXPRPT_PKG.expHdr_attr12;
1938 V_HeaderAttribute13 AP_WEB_DB_EXPRPT_PKG.expHdr_attr13;
1939 V_HeaderAttribute14 AP_WEB_DB_EXPRPT_PKG.expHdr_attr14;
1940 V_HeaderAttribute15 AP_WEB_DB_EXPRPT_PKG.expHdr_attr15;
1941
1942 ExpenseReportLinesCursor AP_WEB_DB_EXPLINE_PKG.XpenseLineAcctCursor;
1943 l_dist_line_number AP_WEB_DB_EXPLINE_PKG.expLines_distLineNum;
1944 l_report_distribution_id AP_WEB_DB_EXPDIST_PKG.expDist_REPORT_DISTRIBUTION_ID;
1945 V_StartExpenseDate AP_WEB_DB_EXPLINE_PKG.expLines_startExpDate;
1946 V_Amount AP_WEB_DB_EXPLINE_PKG.expLines_amount;
1947 V_ExpenseType AP_EXPENSE_REPORT_PARAMS.web_friendly_prompt%TYPE;
1948 V_CreditCardTrxID AP_WEB_DB_EXPLINE_PKG.expLines_crdCardTrxID;
1949 V_ProjectID AP_WEB_DB_EXPLINE_PKG.expLines_projID;
1950 V_TaskID AP_WEB_DB_EXPLINE_PKG.expLines_taskID;
1951 -- Grants Integration
1952 V_AwardID GMS_OIE_INT_PKG.gms_awardId;
1953 V_AwardSetID NUMBER := NULL;
1954 V_ExpenditureItemDate AP_WEB_DB_EXPLINE_PKG.expLines_expendItemDate;
1955 V_ExpenditureType AP_WEB_DB_EXPLINE_PKG.expLines_expendType;
1956 V_PAQuantity AP_WEB_DB_EXPLINE_PKG.expLines_paQuantity;
1957 V_ExpenditureOrganizationID AP_WEB_DB_EXPLINE_PKG.expLines_expOrgID;
1958 l_exp_type_parameter_id AP_WEB_DB_EXPLINE_PKG.expLines_webParamID;
1959 V_AdjustmentReason AP_WEB_DB_EXPLINE_PKG.expLines_adjReason;
1960 V_CategoryCode AP_WEB_DB_EXPLINE_PKG.expLines_categorycode;
1961 V_FlexConcactenated AP_EXPENSE_REPORT_PARAMS.flex_concactenated%TYPE;
1962 V_LineAttributeCategory AP_WEB_DB_EXPLINE_PKG.expLines_attrCategory;
1963 V_LineAttribute1 AP_WEB_DB_EXPLINE_PKG.expLines_attr1;
1964 V_LineAttribute2 AP_WEB_DB_EXPLINE_PKG.expLines_attr2;
1965 V_LineAttribute3 AP_WEB_DB_EXPLINE_PKG.expLines_attr3;
1966 V_LineAttribute4 AP_WEB_DB_EXPLINE_PKG.expLines_attr4;
1967 V_LineAttribute5 AP_WEB_DB_EXPLINE_PKG.expLines_attr5;
1968 V_LineAttribute6 AP_WEB_DB_EXPLINE_PKG.expLines_attr6;
1969 V_LineAttribute7 AP_WEB_DB_EXPLINE_PKG.expLines_attr7;
1970 V_LineAttribute8 AP_WEB_DB_EXPLINE_PKG.expLines_attr8;
1971 V_LineAttribute9 AP_WEB_DB_EXPLINE_PKG.expLines_attr9;
1972 V_LineAttribute10 AP_WEB_DB_EXPLINE_PKG.expLines_attr10;
1973 V_LineAttribute11 AP_WEB_DB_EXPLINE_PKG.expLines_attr11;
1974 V_LineAttribute12 AP_WEB_DB_EXPLINE_PKG.expLines_attr12;
1975 V_LineAttribute13 AP_WEB_DB_EXPLINE_PKG.expLines_attr13;
1976 V_LineAttribute14 AP_WEB_DB_EXPLINE_PKG.expLines_attr14;
1977 V_LineAttribute15 AP_WEB_DB_EXPLINE_PKG.expLines_attr15;
1978 V_LineFlexConcat AP_WEB_DB_EXPLINE_PKG.expLines_LineFlexConcat;
1979 l_line_cost_center AP_WEB_DB_EXPLINE_PKG.expLines_LineFlexConcat;
1980 V_APValidationError AP_WEB_DB_EXPLINE_PKG.expLines_APValidationError;
1981 V_ReportLineId AP_WEB_DB_EXPLINE_PKG.expLines_report_line_id;
1982
1983 l_concatenated_segments varchar2(2000);
1984
1985 l_header_error_message VARCHAR2(2000);
1986 l_return_error_message VARCHAR2(2000);
1987 l_return_status VARCHAR2(30);
1988 l_fatal_error_occurred BOOLEAN := false;
1989 l_header_error_occurred BOOLEAN := false;
1990 l_line_error_occurred BOOLEAN := false;
1991 l_other_error_occurred BOOLEAN := false;
1992 l_add_to_line_error BOOLEAN := false;
1993 l_line_error_message VARCHAR2(2000);
1994 l_other_error_message VARCHAR2(2000);
1995 l_is_projects_report BOOLEAN := false;
1996 l_line_num NUMBER := 0;
1997 l_cash_line_num NUMBER := 0;
1998 l_ccard_line_num NUMBER := 0;
1999 l_yes VARCHAR2(80);
2000 l_no VARCHAR2(80);
2001 l_rounding_error_ccid AP_WEB_DB_EXPLINE_PKG.expLines_codeCombID;
2002 l_card_program_id NUMBER := 0;
2003
2004 l_existing_segments AP_OIE_KFF_SEGMENTS_T;
2005 l_new_segments AP_OIE_KFF_SEGMENTS_T;
2006 l_dist_new_segments AP_OIE_KFF_SEGMENTS_T;
2007
2008 l_transaction_date ap_credit_card_trxns_all.transaction_date%type;
2009
2010 BEGIN
2011
2012 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start DoAPValidation');
2013
2014 ---------------------------------------------------
2015 l_debug_info := 'Clear out potentially rejected/returned status';
2016 ---------------------------------------------------
2017 UPDATE ap_expense_report_headers erh
2018 SET workflow_approved_flag = '',
2019 source = 'NonValidatedWebExpense'
2020 WHERE report_header_id = p_report_header_id;
2021
2022 --------------------------------------------------------------------
2023 l_debug_info := 'Retrieve values from system parameters, employees';
2024 --------------------------------------------------------------------
2025 IF (NOT AP_WEB_DB_EXPRPT_PKG.GetAccountingInfo(
2026 p_report_header_id,
2027 l_sys_apply_advances_default,
2028 l_sys_allow_awt_flag,
2029 l_sys_default_xrate_type,
2030 l_sys_make_rate_mandatory,
2031 l_exp_check_address_flag,
2032 l_default_currency_code,
2033 l_week_end_date,
2034 l_cost_center,
2035 l_employee_id)) THEN
2036 NULL;
2037 END IF; /* GetAccountingInfo */
2038
2039 ------------------------------------------------------------
2040 l_debug_info := 'Get Emp Acctg Info';
2041 ------------------------------------------------------------
2042 begin
2043 AP_WEB_ACCTG_PKG.BuildAccount(
2044 p_report_header_id => null,
2045 p_report_line_id => null,
2046 p_employee_id => l_employee_id,
2047 p_cost_center => l_cost_center,
2048 p_line_cost_center => null,
2049 p_exp_type_parameter_id => null,
2050 p_segments => null,
2051 p_ccid => null,
2052 p_build_mode => AP_WEB_ACCTG_PKG.C_DEFAULT_VALIDATE,
2053 p_new_segments => l_default_emp_segments,
2054 p_new_ccid => l_employee_ccid,
2055 p_return_error_message => l_header_error_message);
2056
2057 -----------------------------------------------------
2058 l_debug_info := 'Get the Employee Chart of Accounts ID';
2059 -----------------------------------------------------
2060 IF (NOT AP_WEB_DB_EXPRPT_PKG.GetChartOfAccountsID(
2061 p_employee_id => l_employee_id,
2062 p_chart_of_accounts_id => l_chart_of_accounts_id)) THEN
2063 NULL;
2064 END IF;
2065
2066 AP_WEB_ACCTG_PKG.GetConcatenatedSegments(
2067 p_chart_of_accounts_id => l_chart_of_accounts_id,
2068 p_segments => l_default_emp_segments,
2069 p_concatenated_segments => l_concatenated_segments);
2070
2071 exception
2072 when AP_WEB_OA_MAINFLOW_PKG.G_EXC_ERROR then
2073 l_header_error_message := FND_MESSAGE.Get;
2074 end;
2075
2076 if (l_header_error_message is not null) then
2077
2078 l_fatal_error_occurred := true;
2079 AddToHeaderErrors(p_item_type,
2080 p_item_key,
2081 l_concatenated_segments||': '||l_header_error_message);
2082 return;
2083 end if;
2084
2085 ------------------------------------------------------------
2086 l_debug_info := 'begin preparation for Project Account Generation';
2087 ------------------------------------------------------------
2088
2089 -- Get version of Workflow
2090 C_WF_Version := GetFlowVersion(p_item_type, p_item_key);
2091
2092 -- Determine whether project enabled
2093 l_debug_info := 'Determine whether project enabled';
2094 V_UserID := WF_ENGINE.GetItemAttrNumber(p_item_type,
2095 p_item_key,
2096 'EMPLOYEE_ID');
2097
2098 ------------------------------------------------------------
2099 l_debug_info := 'Determine whether session is project enabled';
2100 ------------------------------------------------------------
2101 IF (C_WF_Version >= AP_WEB_EXPENSE_WF.C_11_0_3Version) THEN
2102 V_IsSessionProjectEnabled := WF_ENGINE.GetItemAttrText(p_item_type,
2103 p_item_key,
2104 'EMPLOYEE_PROJECT_ENABLED');
2105 ELSE
2106 -- In previous versions we called
2107 -- AP_WEB_PROJECT_PKG.IsSessionProjectEnabled, but that would not work
2108 -- without having ValidateSession called. So, for older versions we
2109 -- will assume that the session is project enabled. Since the receipts
2110 -- will not have any project information, the patc call will not be done.
2111 V_IsSessionProjectEnabled := 'Y';
2112 END IF; /* checking wf version */
2113
2114 ------------------------------------------------------------
2115 l_debug_info := 'end preparation for Project Account Generation';
2116 ------------------------------------------------------------
2117
2118 ------------------------------------------------------------------------
2119 l_debug_info := 'calling AP_WEB_DB_EXPLINE_PKG.GetExpDistAcctCursor';
2120 ------------------------------------------------------------------------
2121 IF (AP_WEB_DB_EXPLINE_PKG.GetExpDistAcctCursor(p_report_header_id,
2122 ExpenseReportLinesCursor)) THEN
2123
2124 ---------------------------------------------------------
2125 l_debug_info := 'Retrieve Payment Due From System Option';
2126 ---------------------------------------------------------
2127 l_payment_due := WF_ENGINE.GetItemAttrText(p_item_type,p_item_key,'PAYMENT_DUE_FROM');
2128
2129 IF (l_payment_due = C_CompanyPay) then
2130 ------------------------------------------------------------------------
2131 l_debug_info := 'calling AP_WEB_DB_EXPTEMPLATE_PKG.GetPersonalParamID';
2132 ------------------------------------------------------------------------
2133 IF (NOT AP_WEB_DB_EXPTEMPLATE_PKG.GetPersonalParamID(l_personalParameterId)) THEN
2134 FND_MESSAGE.SET_NAME('SQLAP','OIE_NO_PERSONAL_EXP_TYPE');
2135 AddToHeaderErrors(p_item_type,
2136 p_item_key,
2137 FND_MESSAGE.GET);
2138 l_header_error_occurred := true;
2139 END IF; /* GetPersonalParamID */
2140
2141 END IF; /* C_CompanyPay */
2142
2143 ------------------------------------------------------------------------
2144 l_debug_info := 'Calling AP_WEB_DB_AP_INT_PKG.GetRoundingErrorCCID';
2145 ------------------------------------------------------------------------
2146 IF (NOT AP_WEB_DB_AP_INT_PKG.GetRoundingErrorCCID(l_rounding_error_ccid)) THEN
2147 l_rounding_error_ccid := NULL;
2148 END IF; /* GetRoundingErrorCCID */
2149
2150 LOOP
2151 FETCH ExpenseReportLinesCursor INTO
2152 l_dist_line_number,
2153 l_report_distribution_id,
2154 V_StartExpenseDate,
2155 V_Amount,
2156 V_ExpenseType,
2157 V_CreditCardTrxID,
2158 V_ProjectID,
2159 V_TaskID,
2160 V_AwardID,
2161 V_ExpenditureItemDate,
2162 V_ExpenditureType,
2163 V_PAQuantity,
2164 V_ExpenditureOrganizationID,
2165 l_exp_type_parameter_id,
2166 V_AdjustmentReason,
2167 V_FlexConcactenated,
2168 V_CategoryCode,
2169 V_LineAttributeCategory,
2170 V_LineAttribute1,
2171 V_LineAttribute2,
2172 V_LineAttribute3,
2173 V_LineAttribute4,
2174 V_LineAttribute5,
2175 V_LineAttribute6,
2176 V_LineAttribute7,
2177 V_LineAttribute8,
2178 V_LineAttribute9,
2179 V_LineAttribute10,
2180 V_LineAttribute11,
2181 V_LineAttribute12,
2182 V_LineAttribute13,
2183 V_LineAttribute14,
2184 V_LineAttribute15,
2185 l_line_cost_center,
2186 V_APValidationError,
2187 V_ReportLineId;
2188 EXIT WHEN ExpenseReportLinesCursor%NOTFOUND;
2189
2190 ------------------------------------------------------------------------
2191 l_debug_info := 'reset l_line_error_message';
2192 ------------------------------------------------------------------------
2193 l_line_error_message := '';
2194 l_add_to_line_error := false;
2195
2196 ------------------------------------------------------------------------
2197 l_debug_info := 'set l_ccard_line_num or l_cash_line_num';
2198 ------------------------------------------------------------------------
2199 if (V_CreditCardTrxID is not null) then
2200 l_ccard_line_num := l_ccard_line_num + 1;
2201 l_line_num := l_ccard_line_num;
2202 else
2203 l_cash_line_num := l_cash_line_num + 1;
2204 l_line_num := l_cash_line_num;
2205 end if;
2206
2207 ------------------------------------------------------------------------
2208 l_debug_info := 'begin Project Account Generation';
2209 ------------------------------------------------------------------------
2210 IF (V_IsSessionProjectEnabled = 'Y' AND V_ProjectID IS NOT NULL) THEN
2211
2212 ------------------------------------------------------------------------
2213 l_debug_info := 'set l_is_projects_report := true';
2214 ------------------------------------------------------------------------
2215 l_is_projects_report := true;
2216
2217 ------------------------------------------------------------------------
2218 l_debug_info := 'AP_WEB_ACCTG_PKG.BuildDistProjectAccount';
2219 ------------------------------------------------------------------------
2220 AP_WEB_ACCTG_PKG.BuildDistProjectAccount(
2221 p_report_header_id => p_report_header_id,
2222 p_report_line_id => V_ReportLineId,
2223 p_report_distribution_id => l_report_distribution_id,
2224 p_exp_type_parameter_id => l_exp_type_parameter_id,
2225 p_new_segments => l_dist_new_segments,
2226 p_new_ccid => l_exp_dist_ccid,
2227 p_return_error_message => l_return_error_message,
2228 p_return_status => l_return_status);
2229
2230 if (l_return_status like '%ERROR%') then
2231 l_line_error_message := l_line_error_message || l_return_error_message || '<br>';
2232 l_add_to_line_error := true;
2233 end if;
2234
2235 --------------------------------------------------------------
2236 l_debug_info:='Credit the Personal lines with a different ccid';
2237 --------------------------------------------------------------
2238 IF (l_payment_due = C_CompanyPay AND l_exp_type_parameter_id = l_personalParameterId) THEN
2239
2240 SELECT card_program_id, transaction_date
2241 INTO l_card_program_id, l_transaction_date
2242 FROM ap_credit_card_trxns
2243 WHERE trx_id = V_CreditCardTrxID;
2244
2245 IF (NOT AP_WEB_DB_AP_INT_PKG.GetExpenseClearingCCID(p_ccid => l_exp_dist_ccid,
2246 p_card_program_id => l_card_program_id,
2247 p_employee_id => l_employee_id,
2248 p_as_of_date => l_transaction_date)) THEN
2249 l_exp_dist_ccid := NULL;
2250 END IF; /* GetExpenseClearingCCID */
2251
2252 --------------------------------------------------------------
2253 l_debug_info:='Personal Expense Clearing CCID is NULL';
2254 --------------------------------------------------------------
2255 IF (l_exp_dist_ccid IS NULL) THEN
2256 l_line_error_message := l_line_error_message || 'Personal Expense Clearing CCID is NULL' || '<br>';
2257 l_add_to_line_error := true;
2258 END IF; /* l_exp_dist_ccid IS NULL */
2259
2260 ELSIF (V_CategoryCode = C_ROUNDING) THEN
2261
2262 --------------------------------------------
2263 l_debug_info := 'Rounding';
2264 --------------------------------------------
2265 l_exp_dist_ccid := l_rounding_error_ccid;
2266 IF (l_rounding_error_ccid IS NULL) THEN
2267 --------------------------------------------
2268 l_debug_info := 'Rounding Error CCID is NULL';
2269 --------------------------------------------
2270 FND_MESSAGE.SET_NAME('SQLAP','OIE_NO_ROUNDING_CCID');
2271 l_other_error_message := FND_MESSAGE.GET;
2272 AddToOtherErrors(p_item_type,
2273 p_item_key,
2274 l_concatenated_segments||': '||l_other_error_message);
2275 l_other_error_occurred := true;
2276 END IF; /* l_rounding_error_ccid IS NULL */
2277
2278 ELSE
2279
2280 -- set the code combination for the line
2281 if (l_exp_dist_ccid is null OR l_exp_dist_ccid = -1) then
2282 l_line_error_message := l_line_error_message;
2283 l_add_to_line_error := true;
2284 end if; /* l_exp_dist_ccid is null */
2285
2286 END IF; /* l_payment_due = C_CompanyPay AND l_exp_type_parameter_id = l_personalParameterId */
2287
2288 if (l_exp_dist_ccid is null OR
2289 l_exp_dist_ccid = -1) then
2290
2291 HandleInvalidDistCCID(p_report_header_id,
2292 l_report_distribution_id,
2293 l_payment_due,
2294 l_exp_type_parameter_id,
2295 l_personalParameterId,
2296 V_CategoryCode,
2297 l_default_emp_segments,
2298 l_dist_new_segments,
2299 V_ReportLineId,
2300 l_exp_dist_ccid,
2301 l_chart_of_accounts_id);
2302 else
2303 /* Also update the segment values in the dist table to ensure the ccid
2304 and the segment values are in sync. */
2305 --------------------------------------------------------------
2306 l_debug_info:='Synch Account Segments with CCID';
2307 -- updateAccountValues calls AddDistributionLine if dist does not
2308 -- exist and then updates the ccid and segments based on l_exp_dist_ccid
2309 --------------------------------------------------------------
2310 AP_WEB_DB_EXPDIST_PKG.updateAccountValues (
2311 p_report_header_id => p_report_header_id,
2312 p_report_line_id => V_ReportLineId,
2313 p_report_distribution_id => l_report_distribution_id,
2314 p_ccid => l_exp_dist_ccid);
2315
2316 end if; /* l_exp_dist_ccid is null */
2317
2318 ------------------------------------------------------------------------
2319 l_debug_info := 'end Project Account Generation';
2320 ------------------------------------------------------------------------
2321
2322 ELSE
2323 ------------------------------------------------------------------------
2324 l_debug_info := 'begin Non-Project Account Generation';
2325 ------------------------------------------------------------------------
2326 --------------------------------------------------------------
2327 l_debug_info:='Credit the Personal lines with a different ccid';
2328 --------------------------------------------------------------
2329 IF (l_payment_due = C_CompanyPay AND l_exp_type_parameter_id = l_personalParameterId) THEN
2330
2331 SELECT card_program_id, transaction_date
2332 INTO l_card_program_id, l_transaction_Date
2333 FROM ap_credit_card_trxns
2334 WHERE trx_id = V_CreditCardTrxID;
2335
2336 IF (NOT AP_WEB_DB_AP_INT_PKG.GetExpenseClearingCCID(p_ccid => l_exp_dist_ccid,
2337 p_card_program_id => l_card_program_id,
2338 p_employee_id => l_employee_id,
2339 p_as_of_date => l_transaction_date)) THEN
2340 l_exp_dist_ccid := NULL;
2341 END IF; /* GetExpenseClearingCCID */
2342
2343 --------------------------------------------------------------
2344 l_debug_info:='Personal Expense Clearing CCID is NULL';
2345 --------------------------------------------------------------
2346 IF (l_exp_dist_ccid IS NULL) THEN
2347 l_line_error_message := l_line_error_message || 'Personal Expense Clearing CCID is NULL' || '<br>';
2348 l_add_to_line_error := true;
2349 END IF; /* l_exp_dist_ccid IS NULL */
2350
2351 ELSIF (V_CategoryCode = 'ROUNDING' ) THEN
2352 l_exp_dist_ccid := l_rounding_error_ccid;
2353 --------------------------------------------
2354 l_debug_info := 'Rounding Error CCID is NULL';
2355 --------------------------------------------
2356 IF ( l_rounding_error_ccid IS NULL) THEN
2357 FND_MESSAGE.SET_NAME('SQLAP','OIE_NO_ROUNDING_CCID');
2358 l_other_error_message := FND_MESSAGE.GET;
2359 AddToOtherErrors(p_item_type,
2360 p_item_key,
2361 l_concatenated_segments||': '||l_other_error_message);
2362 l_other_error_occurred := true;
2363
2364 END IF; /*l_rounding_error_ccid IS NULL*/
2365
2366 ELSE
2367 -- Removed code for 'LLA Enabled with Online Validation';
2368 -- i.e, Removed call to AP_WEB_DB_EXPDIST_PKG.UpdateDistCCID
2369 -- as there is no change in l_exp_dist_ccid
2370
2371 IF (l_report_distribution_id is not null) THEN -- Distribution Exist
2372
2373 IF (NOT AP_WEB_DB_EXPDIST_PKG.foundCCID(l_report_distribution_id, l_exp_dist_ccid)) THEN
2374
2375 --------------------------------------------------------------
2376 l_debug_info:='LLA Enabled without Online Validation';
2377 --------------------------------------------------------------
2378 --------------------------------------------------------------
2379 l_debug_info:='Get Distribution Segments';
2380 --------------------------------------------------------------
2381 AP_WEB_ACCTG_PKG.GetDistributionSegments(
2382 p_chart_of_accounts_id => l_chart_of_accounts_id,
2383 p_report_distribution_id => l_report_distribution_id,
2384 p_segments => l_existing_segments);
2385
2386 --------------------------------------------------------------
2387 l_debug_info:='Build Account';
2388 --------------------------------------------------------------
2389 AP_WEB_ACCTG_PKG.BuildAccount(
2390 p_report_header_id => p_report_header_id,
2391 p_report_line_id => V_ReportLineId,
2392 p_employee_id => l_employee_id,
2393 p_cost_center => l_cost_center,
2394 p_line_cost_center => l_line_cost_center,
2395 p_exp_type_parameter_id => l_exp_type_parameter_id,
2396 p_segments => l_existing_segments,
2397 p_ccid => null,
2398 p_build_mode => AP_WEB_ACCTG_PKG.C_VALIDATE,
2399 p_new_segments => l_dist_new_segments,
2400 p_new_ccid => l_exp_dist_ccid,
2401 p_return_error_message => l_return_error_message);
2402
2403 if (l_return_error_message is not null) then
2404 l_line_error_message := l_line_error_message || l_return_error_message || ' ';
2405 l_add_to_line_error := true;
2406 end if;
2407
2408 END IF; -- (Not AP_WEB_DB_EXPDIST_PKG.foundCCID) 'LLA Enabled without Online Validation';
2409
2410 ELSE -- else of Distribution Exist
2411
2412 --------------------------------------------------------------
2413 l_debug_info:='LLA Disabled';
2414 --------------------------------------------------------------
2415 l_existing_segments := null;
2416 l_new_segments := null;
2417
2418 --------------------------------------------------------------
2419 l_debug_info:='Build Account';
2420 --------------------------------------------------------------
2421 AP_WEB_ACCTG_PKG.BuildAccount(
2422 p_report_header_id => p_report_header_id,
2423 p_report_line_id => V_ReportLineId,
2424 p_employee_id => l_employee_id,
2425 p_cost_center => l_cost_center,
2426 p_line_cost_center => l_line_cost_center,
2427 p_exp_type_parameter_id => l_exp_type_parameter_id,
2428 p_segments => l_existing_segments,
2429 p_ccid => null,
2430 p_build_mode => AP_WEB_ACCTG_PKG.C_DEFAULT_VALIDATE,
2431 p_new_segments => l_dist_new_segments,
2432 p_new_ccid => l_exp_dist_ccid,
2433 p_return_error_message => l_return_error_message);
2434
2435 if (l_return_error_message is not null) then
2436 l_line_error_message := l_line_error_message || l_return_error_message || ' ';
2437 l_add_to_line_error := true;
2438 end if;
2439
2440 END IF; /* foundDistributions */
2441
2442 END IF; /* l_payment_due = C_CompanyPay AND l_exp_type_parameter_id = l_personalParameterId */
2443
2444
2445 if (l_exp_dist_ccid is null OR
2446 l_exp_dist_ccid = -1) then
2447
2448 HandleInvalidDistCCID(p_report_header_id,
2449 l_report_distribution_id,
2450 l_payment_due,
2451 l_exp_type_parameter_id,
2452 l_personalParameterId,
2453 V_CategoryCode,
2454 l_default_emp_segments,
2455 l_dist_new_segments,
2456 V_ReportLineId,
2457 l_exp_dist_ccid,
2458 l_chart_of_accounts_id);
2459
2460 l_line_error_message := l_line_error_message;
2461 l_add_to_line_error := true;
2462
2463 IF (C_WF_Version >= AP_WEB_EXPENSE_WF.C_OIEJ_Version) THEN
2464 WF_ENGINE.SetItemAttrText(p_item_type,
2465 p_item_key,
2466 'EXP_ALLOCATION_ERRORS',
2467 'Y');
2468 END IF;
2469
2470 else
2471
2472 /* Also update the segment values in the dist table to ensure the ccid
2473 and the segment values are in sync. */
2474 --------------------------------------------------------------
2475 l_debug_info:='Synch Account Segments with CCID';
2476 -- updateAccountValues calls AddDistributionLine if dist does not
2477 -- exist and then updates the ccid and segments based on l_exp_dist_ccid
2478 --------------------------------------------------------------
2479 AP_WEB_DB_EXPDIST_PKG.updateAccountValues (
2480 p_report_header_id => p_report_header_id,
2481 p_report_line_id => V_ReportLineId,
2482 p_report_distribution_id => l_report_distribution_id,
2483 p_ccid => l_exp_dist_ccid);
2484
2485 end if; /* l_exp_dist_ccid is null */
2486
2487 ------------------------------------------------------------------------
2488 l_debug_info := 'end Non-Project Account Generation';
2489 ------------------------------------------------------------------------
2490
2491 END IF; /* end Project and non-Project Account Generation */
2492
2493 ------------------------------------------------------------------------
2494 l_debug_info := 'check to see if line error occurred';
2495 ------------------------------------------------------------------------
2496 if (l_add_to_line_error) then
2497
2498 AP_WEB_DB_EXPLINE_PKG.UpdateAPValidationError(
2499 p_report_header_id => p_report_header_id,
2500 p_dist_line_number => l_dist_line_number,
2501 p_ap_validation_error => l_line_error_message);
2502
2503 l_line_error_occurred := true;
2504
2505 end if;
2506
2507 END LOOP; /* ExpenseReportLinesCursor */
2508
2509 END IF; /* GetExpDistAcctCursor */
2510
2511 if ExpenseReportLinesCursor%isopen then
2512 CLOSE ExpenseReportLinesCursor;
2513 end if;
2514
2515 ----------------------------------------------------------------
2516 l_debug_info := 'Set Is Projects Expense Report?';
2517 -----------------------------------------------------------------
2518 if (l_is_projects_report) then
2519
2520 SELECT fndl.meaning
2521 INTO l_yes
2522 FROM FND_LOOKUPS fndl
2523 WHERE fndl.LOOKUP_TYPE = C_YES_NO
2524 AND fndl.LOOKUP_CODE = C_Y;
2525
2526 WF_ENGINE.SetItemAttrText(p_item_type,
2527 p_item_key,
2528 'IS_PROJECTS_REPORT',
2529 l_yes);
2530 else
2531 SELECT fndl.meaning
2532 INTO l_no
2533 FROM FND_LOOKUPS fndl
2534 WHERE fndl.LOOKUP_TYPE = C_YES_NO
2535 AND fndl.LOOKUP_CODE = C_N;
2536
2537 WF_ENGINE.SetItemAttrText(p_item_type,
2538 p_item_key,
2539 'IS_PROJECTS_REPORT',
2540 l_no);
2541 end if; /* l_is_projects_report */
2542
2543 ------------------------------------------------
2544 l_debug_info := 'Retrieve function currency';
2545 ------------------------------------------------
2546 IF (NOT AP_WEB_DB_AP_INT_PKG.GetBaseCurrInfo(l_sys_base_currency_code)) THEN
2547 l_sys_base_currency_code := NULL;
2548 END IF; /* GetBaseCurrInfo */
2549
2550 ------------------------------------------------
2551 l_debug_info := 'Determine if EMU FIXED rate: l_sys_base_currency_code = '||l_sys_base_currency_code||' l_default_currency_code = '||l_default_currency_code;
2552 ------------------------------------------------
2553 IF (gl_currency_api.is_fixed_rate(l_sys_base_currency_code,
2554 l_default_currency_code,
2555 sysdate) = 'Y') THEN
2556
2557 IF (l_sys_base_currency_code <> l_default_currency_code) THEN --euro, bug 1289501
2558 l_sys_default_xrate_type := 'EMU FIXED';
2559 END IF; /* l_sys_base_currency_code <> l_default_currency_code */
2560
2561 END IF; /* is_fixed_rate */
2562
2563 IF (NOT AP_WEB_DB_AP_INT_PKG.GetBaseCurrInfo(l_base_currency_code)) THEN
2564 l_base_currency_code := null;
2565 END IF; /* GetBaseCurrInfo */
2566
2567 ----------------------------------------------
2568 l_debug_info := 'Check for invalid Rate Type';
2569 ----------------------------------------------
2570 IF ((l_sys_default_xrate_type = 'User') AND
2571 (l_sys_make_rate_mandatory = 'Y')) THEN
2572
2573 IF (NOT AP_WEB_DB_EXPRPT_PKG.SetDefaultExchRateType(p_report_header_id, l_sys_default_xrate_type)) THEN
2574 NULL;
2575 END IF; /* SetDefaultExchRateType */
2576
2577 FND_MESSAGE.SET_NAME('SQLAP','AP_WEB_USER_EXCH_RATE_REQD');
2578 l_return_error_message := FND_MESSAGE.GET;
2579 AddToHeaderErrors(p_item_type,
2580 p_item_key,
2581 l_return_error_message);
2582 l_header_error_occurred := true;
2583
2584 ELSE
2585 --Bug 2974741: Replace sysdate with l_week_end_date to get correct rate.
2586 l_default_exchange_rate := AP_UTILITIES_PKG.get_exchange_rate(l_default_currency_code, l_base_currency_code, l_sys_default_xrate_type, l_week_end_date, 'DoAPValidation');
2587 END IF; /* Check for invalid Rate Type */
2588
2589
2590 --------------------------------------------------------------------
2591 l_debug_info := 'Check to see if error occurred before proceeding';
2592 --------------------------------------------------------------------
2593 if (l_header_error_occurred OR l_line_error_occurred OR l_other_error_occurred) then
2594 Return;
2595 end if; /* l_header_error_occurred OR l_line_error_occurred */
2596
2597 --------------------------------------------------------------------
2598 l_debug_info := 'Calculate available prepayments for this employee';
2599 --------------------------------------------------------------------
2600 IF (NOT AP_WEB_DB_AP_INT_PKG.GetAvailablePrepayments(l_employee_id,
2601 l_default_currency_code,
2602 l_available_prepays)) THEN
2603 l_available_prepays := NULL;
2604 END IF; /* GetAvailablePrepayments */
2605
2606 ------------------------------------------------
2607 l_debug_info := 'Retrieve values from vendors';
2608 ------------------------------------------------
2609 IF (NOT AP_WEB_DB_AP_INT_PKG.GetVendorAWTSetupForExpRpt(p_report_header_id,
2610 l_ven_allow_awt_flag,
2611 l_ven_awt_group_id)) THEN
2612
2613 l_ven_allow_awt_flag := NULL;
2614 l_ven_awt_group_id := NULL;
2615
2616 END IF; /* GetVendorAWTSetupForExpRpt */
2617
2618 ---------------------------------------------------
2619 l_debug_info := 'Update ap_expense_report_headers';
2620 ---------------------------------------------------
2621 IF (NOT AP_WEB_DB_EXPRPT_PKG.SetExpenseHeaderInfo(p_report_header_id,
2622 l_exp_check_address_flag,
2623 'WebExpense',
2624 '', -- clear out potentially-rejected/returned status
2625 l_sys_apply_advances_default,
2626 l_available_prepays,
2627 l_sys_allow_awt_flag,
2628 l_ven_allow_awt_flag,
2629 l_ven_awt_group_id,
2630 l_sys_default_xrate_type,
2631 l_week_end_date,
2632 l_default_exchange_rate,
2633 l_employee_ccid ) ) THEN
2634 NULL;
2635 END IF; /* SetExpenseHeaderInfo */
2636
2637 ---------------------------------------------------
2638 l_debug_info := 'Update ap_expense_report_lines';
2639 ---------------------------------------------------
2640 -- 7/24: insertion of receipt_required_flag is moved to the submit package.
2641 IF (NOT AP_WEB_DB_EXPLINE_PKG.SetAWTGroupIDAndJustif(p_report_header_id,
2642 l_sys_allow_awt_flag,
2643 l_ven_allow_awt_flag,
2644 l_ven_awt_group_id)) THEN
2645 NULL;
2646 END IF; /* SetAWTGroupIDAndJustif */
2647
2648 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end DoAPValidation');
2649
2650 EXCEPTION
2651 WHEN OTHERS THEN
2652 IF (SQLCODE <> -20001) THEN
2653 FND_MESSAGE.SET_NAME('SQLAP','AP_DEBUG');
2654 FND_MESSAGE.SET_TOKEN('ERROR',SQLERRM);
2655 FND_MESSAGE.SET_TOKEN('CALLING_SEQUENCE', 'DoAPValidation');
2656 FND_MESSAGE.SET_TOKEN('DEBUG_INFO',l_debug_info);
2657 END IF;
2658 APP_EXCEPTION.RAISE_EXCEPTION;
2659 END DoAPValidation;
2660
2661 -------------------------------------
2662 PROCEDURE OpenExp(p1 varchar2,
2663 p2 varchar2,
2664 p11 varchar2) IS
2665 -------------------------------------
2666 l_param varchar2(240);
2667 c_rowid varchar2(18);
2668 l_session_id number;
2669 l_icx_application_id AK_FLOW_REGION_RELATIONS.flow_application_id%TYPE := AP_WEB_INFRASTRUCTURE_PKG.GetICXApplicationId;
2670 l_url ICX_PARAMETERS.HOME_URL%TYPE := null;
2671
2672 BEGIN
2673
2674 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start OpenExp');
2675
2676 IF AP_WEB_INFRASTRUCTURE_PKG.ValidateSession(NULL, false, false) THEN
2677
2678 l_session_id := icx_sec.getID(icx_sec.PV_SESSION_ID);
2679 AP_WEB_INFRASTRUCTURE_PKG.ICXSetOrgContext(l_session_id, p11);
2680
2681 -- The following information needs to be set up through ON forms, on particular
2682 -- Page rlations.
2683
2684 IF (NOT AP_WEB_DB_UI_SETUP_PKG.GetAKPageRowID('ICX_AP_EXP_RPT_NEW_D',
2685 'ICX_AP_EXP_RPT_D',
2686 'ICX_AP_EXP_LINES_D',
2687 'ICX_INQUIRIES',
2688 l_icx_application_id,
2689 c_rowid)) THEN
2690 NULL;
2691 END IF;
2692
2693 l_param := icx_on_utilities.buildOracleONstring
2694 (p_rowid => c_rowid,
2695 p_primary_key => 'ICX_AP_EXP_RPT_PK',
2696 p1 => icx_call.decrypt(p1),
2697 p2 => icx_call.decrypt(p2));
2698
2699
2700 IF (l_session_id IS NULL) THEN
2701 OracleOn.IC(Y=>icx_call.encrypt2(l_param,-999));
2702 ELSE
2703 OracleOn.IC(Y=>icx_call.encrypt2(l_param,l_session_id));
2704 END IF;
2705
2706 ELSE
2707 -- for bug 1661113
2708 select HOME_URL
2709 into l_url
2710 from ICX_PARAMETERS;
2711
2712 FND_MESSAGE.SET_NAME('SQLAP', 'AP_WEB_NOTIF_LOGON_ERROR');
2713 FND_MESSAGE.SET_TOKEN('URL', l_url);
2714
2715 htp.p('<HTML><BODY>' || FND_MESSAGE.GET || '</BODY></HTML>');
2716
2717 END IF;
2718
2719 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end OpenExp');
2720
2721 EXCEPTION
2722 WHEN OTHERS THEN
2723 htp.p(SQLERRM);
2724 END OpenExp;
2725
2726 ------------------------------------------------------------------------------
2727 PROCEDURE BuildManagerApprvlMessage(p_item_type IN VARCHAR2,
2728 p_item_key IN VARCHAR2,
2729 p_actid IN NUMBER,
2730 p_funmode IN VARCHAR2,
2731 p_result OUT NOCOPY VARCHAR2) IS
2732 ------------------------------------------------------------------------------
2733 l_report_header_id NUMBER;
2734 l_debug_info VARCHAR2(1000);
2735 l_receipts_missing_flag VARCHAR2(1) := 'N';
2736 l_warning_msg VARCHAR2(2000);
2737 l_violation VARCHAR2(1);
2738
2739 /* jrautiai ADJ Fix Start */
2740 l_shortpaid_flag VARCHAR2(1) := 'N';
2741 /* jrautiai ADJ Fix End */
2742
2743 BEGIN
2744
2745 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start BuildManagerApprvlMessage');
2746
2747 IF (p_funmode = 'RUN') THEN
2748
2749 ------------------------------------------------------------
2750 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
2751 ------------------------------------------------------------
2752 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
2753 p_item_key,
2754 'EXPENSE_REPORT_ID');
2755
2756 --chiho:1352284:
2757 ----------------------------------------------------------------
2758 l_debug_info := 'Get the receipts missing flag';
2759 ----------------------------------------------------------------
2760 --chiho:1369557:
2761 IF ( AP_WEB_DB_EXPLINE_PKG.GetReceiptsMissingFlag(
2762 l_report_header_id,
2763 l_receipts_missing_flag) ) THEN
2764
2765 IF ( l_receipts_missing_flag = 'Y' ) THEN
2766
2767 /* jrautiai ADJ Fix Start
2768 * We need to show a message indicating that this is a new report generated due to
2769 * employee requesting approval of shortpaid report due to missing receipts.
2770 * We are assuming here that the only case logic rebuilds the manager approval
2771 * notification while the report was created from another report is due to
2772 * missing receipts.
2773 */
2774
2775 IF AP_WEB_DB_EXPLINE_PKG.GetShortpaidFlag(l_report_header_id, l_shortpaid_flag) THEN
2776 IF (l_shortpaid_flag = 'Y' ) THEN
2777 fnd_message.set_name('SQLAP', 'OIE_WF_APPROVAL_POLICY_NOTE');
2778 l_warning_msg := FND_MESSAGE.Get;
2779
2780 WF_ENGINE.SetItemAttrText(
2781 p_item_type,
2782 p_item_key,
2783 'VIOLATION_NOTE',
2784 WF_ENGINE.GetItemAttrText(p_item_type,
2785 p_item_key,
2786 'VIOLATION_NOTE')||' '|| l_warning_msg );
2787 END IF;
2788 END IF;
2789 /* jrautiai ADJ Fix end */
2790
2791 fnd_message.set_name('SQLAP', 'AP_WEB_EXP_APRVL_RECPTS_MISSIN');
2792 l_warning_msg := FND_MESSAGE.Get;
2793
2794 WF_ENGINE.SetItemAttrText(
2795 p_item_type,
2796 p_item_key,
2797 'VIOLATION_NOTE',
2798 WF_ENGINE.GetItemAttrText(p_item_type,
2799 p_item_key,
2800 'VIOLATION_NOTE')||' '||l_warning_msg );
2801
2802 END IF;
2803 END IF;
2804
2805 IF (AP_WEB_DB_EXPLINE_PKG.AnyPolicyViolation(l_report_header_id)) THEN
2806 fnd_message.set_name('SQLAP', 'AP_WEB_EXP_APRVL_RULES_VIOLATE');
2807 l_warning_msg := FND_MESSAGE.Get;
2808
2809 WF_ENGINE.SetItemAttrText(
2810 p_item_type,
2811 p_item_key,
2812 'VIOLATION_NOTE',
2813 WF_ENGINE.GetItemAttrText(p_item_type,
2814 p_item_key,
2815 'VIOLATION_NOTE')||' '||l_warning_msg );
2816
2817 END IF;
2818
2819
2820 ELSIF (p_funmode = 'CANCEL') THEN
2821
2822 p_result := 'COMPLETE';
2823
2824 END IF;
2825
2826 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end BuildManagerApprvlMessage');
2827
2828 EXCEPTION
2829 WHEN OTHERS THEN
2830 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'BuildManagerApprvlMessage',
2831 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
2832 raise;
2833 END BuildManagerApprvlMessage;
2834
2835 ----------------------------------------------------------------------
2836 PROCEDURE ManagerApproved(p_item_type IN VARCHAR2,
2837 p_item_key IN VARCHAR2,
2838 p_actid IN NUMBER,
2839 p_funmode IN VARCHAR2,
2840 p_result OUT NOCOPY VARCHAR2) IS
2841 ----------------------------------------------------------------------
2842 l_report_header_id AP_WEB_DB_EXPRPT_PKG.expHdr_headerID;
2843 l_debug_info VARCHAR2(200);
2844 BEGIN
2845
2846 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start ManagerApproved');
2847
2848 IF (p_funmode = 'RUN') THEN
2849
2850 ------------------------------------------------------------
2851 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
2852 ------------------------------------------------------------
2853 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
2854 p_item_key,
2855 'EXPENSE_REPORT_ID');
2856
2857
2858 ----------------------------------------------------------------
2859 l_debug_info := 'Update the Expense Report as Manager Approved';
2860 ----------------------------------------------------------------
2861 IF (NOT AP_WEB_DB_EXPRPT_PKG.SetWkflApprvdFlag(l_report_header_id)) THEN
2862 NULL;
2863 END IF;
2864
2865 ----------------------------------------------------------
2866 l_debug_info := 'Update Receipts Status to Missing if Pending Resolution';
2867 ----------------------------------------------------------
2868 update ap_expense_report_headers
2869 set receipts_status = 'MISSING'
2870 where report_header_id = l_report_header_id
2871 and receipts_status = 'RESOLUTN';
2872
2873 ELSIF (p_funmode = 'CANCEL') THEN
2874 p_result := 'COMPLETE';
2875 END IF;
2876
2877 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end ManagerApproved');
2878
2879 EXCEPTION
2880 WHEN OTHERS THEN
2881 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'ManagerApproved',
2882 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
2883 raise;
2884 END ManagerApproved;
2885
2886 ----------------------------------------------------------------------
2887 PROCEDURE CheckSumMissingReceipts(p_item_type IN VARCHAR2,
2888 p_item_key IN VARCHAR2,
2889 p_actid IN NUMBER,
2890 p_funmode IN VARCHAR2,
2891 p_result OUT NOCOPY VARCHAR2) IS
2892 ----------------------------------------------------------------------
2893 l_report_header_id AP_WEB_DB_EXPLINE_PKG.expLines_headerID;
2894 l_sum_limit NUMBER;
2895 l_sum_violations NUMBER;
2896 l_sum_missing_receipts NUMBER;
2897 l_currency VARCHAR2(50);
2898 l_debug_info VARCHAR2(200);
2899 l_sum_missing_display_total VARCHAR2(50);
2900 l_converted_amount NUMBER;
2901 denominator NUMBER;
2902 numerator NUMBER;
2903 rate NUMBER;
2904 l_default_exch_rate_type AP_SYSTEM_PARAMETERS_ALL.default_exchange_rate_type%TYPE;
2905
2906 BEGIN
2907
2908 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start CheckSumMissingReceipts');
2909
2910 IF (p_funmode = 'RUN') THEN
2911
2912 ------------------------------------------------------------
2913 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
2914 ------------------------------------------------------------
2915 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
2916 p_item_key,
2917 'EXPENSE_REPORT_ID');
2918
2919 ----------------------------------------------------
2920 l_debug_info := 'Retrieve Currency Item Attribute';
2921 ----------------------------------------------------
2922 l_currency := WF_ENGINE.GetItemAttrText(p_item_type,
2923 p_item_key,
2924 'CURRENCY');
2925
2926 ---------------------------------------------------------------------------
2927 l_debug_info := 'Retrieve AP Receipt Minnsing Amount Limit Item Attribute';
2928 ---------------------------------------------------------------------------
2929 l_sum_limit := WF_ENGINE.GetActivityAttrNumber(p_item_type,
2930 p_item_key,
2931 p_actid,
2932 'SUM_MISSING_RECEIPTS_LIMIT');
2933
2934 -------------------------------------------------------------------------
2935 l_debug_info := 'Calculate Total Receipt Missing Amt for Expense Report';
2936 -------------------------------------------------------------------------
2937 IF (NOT AP_WEB_DB_EXPLINE_PKG.GetReceiptMissingTotal(l_report_header_id,
2938 l_sum_missing_receipts)) THEN
2939 l_sum_missing_receipts := 0;
2940 END IF;
2941
2942 -------------------------------------------------------------------------
2943 l_debug_info := 'Calculate Total Receipt Violations excluding missing receipt total for Expense Report';
2944 -------------------------------------------------------------------------
2945 IF (NOT AP_WEB_DB_EXPLINE_PKG.GetReceiptViolationsTotal(l_report_header_id,
2946 l_sum_violations)) THEN
2947 l_sum_violations := 0;
2948 END IF;
2949
2950 IF (nvl(l_sum_violations, 0) > 0) THEN
2951 WF_ENGINE.SetItemAttrText(p_item_type,
2952 p_item_key,
2953 'VIOLATIONS_TOTAL',
2954 to_char(l_sum_violations + nvl(l_sum_missing_receipts,0), FND_CURRENCY.Get_Format_Mask(l_currency,22)) || ' ' || l_currency);
2955 END IF;
2956
2957 -- 9412210: if report is in a currency other than USD then convert to USD
2958 -- and compare
2959 if (nvl(l_currency,'USD') <> 'USD') then
2960 BEGIN
2961 -- Bug# 9818634: Get the exchange rate type and then convert the amount
2962 AP_WEB_DB_AP_INT_PKG.GetDefaultExchange(l_default_exch_rate_type);
2963 gl_currency_api.convert_closest_amount( l_currency ,
2964 'USD' ,
2965 SYSDATE ,
2966 l_default_exch_rate_type ,
2967 null ,
2968 l_sum_missing_receipts ,
2969 0 ,
2970 l_converted_amount ,
2971 denominator ,
2972 numerator ,
2973 rate );
2974 EXCEPTION
2975 WHEN OTHERS THEN
2976 -- l_sum_missing_receipts cannot be converted, hence use the same
2977 l_converted_amount := l_sum_missing_receipts;
2978 END;
2979 else
2980 l_converted_amount := l_sum_missing_receipts;
2981 end if;
2982
2983 -----------------------------------------------------------------
2984 l_debug_info := 'If Report Amount is Less than AP Limit Return N
2985 otherwise return Y';
2986 -----------------------------------------------------------------
2987 IF (nvl(l_converted_amount,0) <= nvl(l_sum_limit,0)) THEN
2988
2989 p_result := 'COMPLETE:N';
2990 ELSE
2991 l_sum_missing_display_total := to_char(l_sum_missing_receipts, FND_CURRENCY.Get_Format_Mask(l_currency,22)) || ' ' || l_currency;
2992
2993 WF_ENGINE.SetItemAttrText(p_item_type,
2994 p_item_key,
2995 'MISSING_RECEIPT_TOTAL',
2996 l_sum_missing_display_total);
2997
2998 FND_MESSAGE.SET_NAME('SQLAP','OIE_WF_VERIFY_MISSING_NOTE');
2999 FND_MESSAGE.SET_TOKEN('MISSING_TOTAL',l_sum_missing_display_total);
3000
3001 WF_ENGINE.SetItemAttrText(p_item_type,
3002 p_item_key,
3003 'VERIFY_NOTE',
3004 FND_MESSAGE.GET);
3005
3006
3007
3008 p_result := 'COMPLETE:Y';
3009 END IF;
3010
3011 ELSIF (p_funmode = 'CANCEL') THEN
3012 p_result := 'COMPLETE';
3013 END IF;
3014
3015
3016 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end CheckSumMissingReceipts');
3017
3018 EXCEPTION
3019 WHEN OTHERS THEN
3020 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'CheckSumMissingReceipts',
3021 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
3022 raise;
3023 END CheckSumMissingReceipts;
3024
3025 ----------------------------------------------------------------------
3026 PROCEDURE AnyReceiptRequired(p_item_type IN VARCHAR2,
3027 p_item_key IN VARCHAR2,
3028 p_actid IN NUMBER,
3029 p_funmode IN VARCHAR2,
3030 p_result OUT NOCOPY VARCHAR2) IS
3031 ----------------------------------------------------------------------
3032 l_include_missing_receipts VARCHAR2(1);
3033 l_report_header_id AP_WEB_DB_EXPLINE_PKG.expLines_headerID;
3034 l_num_req_receipts NUMBER;
3035 l_debug_info VARCHAR2(200);
3036 BEGIN
3037
3038 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start AnyReceiptRequired');
3039
3040 IF (p_funmode = 'RUN') THEN
3041
3042 ------------------------------------------------------------
3043 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
3044 ------------------------------------------------------------
3045 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
3046 p_item_key,
3047 'EXPENSE_REPORT_ID');
3048
3049
3050
3051 ------------------------------------------------------------------
3052 l_debug_info := 'Calculate Number of Lines with Receipt Required';
3053 ------------------------------------------------------------------
3054 IF (NOT AP_WEB_DB_EXPLINE_PKG.GetNumReceiptRequiredLines(
3055 l_report_header_id, l_num_req_receipts)) THEN
3056 l_num_req_receipts := 0;
3057 END IF;
3058
3059 IF (l_num_req_receipts > 0) THEN
3060 ------------------------------------------------------------
3061 l_debug_info := 'Return Y if any line has receipt required';
3062 ------------------------------------------------------------
3063 p_result := 'COMPLETE:Y';
3064 ELSE
3065 p_result := 'COMPLETE:N';
3066 END IF;
3067
3068 ELSIF (p_funmode = 'CANCEL') THEN
3069 p_result := 'COMPLETE';
3070 END IF;
3071
3072 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end AnyReceiptRequired');
3073
3074 EXCEPTION
3075 WHEN OTHERS THEN
3076 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'AnyReceiptRequired',
3077 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
3078 raise;
3079 END AnyReceiptRequired;
3080
3081 ----------------------------------------------------------------------
3082 PROCEDURE AnyJustificationRequired(p_item_type IN VARCHAR2,
3083 p_item_key IN VARCHAR2,
3084 p_actid IN NUMBER,
3085 p_funmode IN VARCHAR2,
3086 p_result OUT NOCOPY VARCHAR2) IS
3087 ----------------------------------------------------------------------
3088 l_report_header_id AP_WEB_DB_EXPLINE_PKG.expLines_headerID;
3089 l_num_req_receipt NUMBER;
3090 l_violation VARCHAR2(1);
3091 l_debug_info VARCHAR2(200);
3092 l_mess Wf_Item_Attribute_Values.TEXT_VALUE%TYPE;
3093 BEGIN
3094
3095 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start AnyJustificationRequired');
3096
3097 IF (p_funmode = 'RUN') THEN
3098
3099 ------------------------------------------------------------
3100 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
3101 ------------------------------------------------------------
3102 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
3103 p_item_key,
3104 'EXPENSE_REPORT_ID');
3105
3106
3107 ------------------------------------------------------------------------
3108 l_debug_info := 'Calculate Number of Lines With Justification Required';
3109 ------------------------------------------------------------------------
3110 IF (NOT AP_WEB_DB_EXPLINE_PKG.GetNumJustReqdLines(l_report_header_id,
3111 l_num_req_receipt)) THEN
3112 l_num_req_receipt := 0;
3113 END IF;
3114
3115 ------------------------------------------------------------
3116 l_debug_info := 'Construction the Note';
3117 ------------------------------------------------------------
3118 IF (l_num_req_receipt > 0 ) THEN
3119 FND_MESSAGE.SET_NAME('SQLAP','OIE_WF_JUST_REQUIRED_MSG');
3120 END IF;
3121
3122 IF (AP_WEB_DB_EXPLINE_PKG.AnyPolicyViolation(l_report_header_id)) THEN
3123 -- Bug# 13082536
3124 l_violation := 'Y';
3125 FND_MESSAGE.SET_NAME('SQLAP','OIE_WF_VIOLATION_MSG');
3126 END IF;
3127
3128 IF (l_num_req_receipt > 0 ) AND (l_violation = 'Y' ) THEN
3129 FND_MESSAGE.SET_NAME('SQLAP','OIE_WF_JUST_AND_VIOLATION_MSG');
3130 END IF;
3131
3132
3133 l_mess := FND_MESSAGE.GET;
3134 WF_ENGINE.SetItemAttrText(p_item_type,
3135 p_item_key,
3136 'REVIEW_NOTE',
3137 l_mess);
3138
3139 ------------------------------------------------------------
3140 l_debug_info := 'Construction the Instruction';
3141 ------------------------------------------------------------
3142 IF (l_num_req_receipt > 0 OR l_violation = 'Y' ) THEN
3143
3144 FND_MESSAGE.SET_NAME('SQLAP','OIE_WF_REVIEW_INSTRUCTION');
3145 l_mess := FND_MESSAGE.GET;
3146
3147 WF_ENGINE.SetItemAttrText(p_item_type,
3148 p_item_key,
3149 'INSTRUCTION',
3150 l_mess);
3151
3152
3153 p_result := 'COMPLETE:Y';
3154 ELSE
3155 p_result := 'COMPLETE:N';
3156 END IF;
3157
3158 ELSIF (p_funmode = 'CANCEL') THEN
3159 p_result := 'COMPLETE';
3160 END IF;
3161
3162 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end AnyJustificationRequired');
3163
3164 EXCEPTION
3165 WHEN OTHERS THEN
3166 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'AnyJustificationRequired',
3167 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
3168 raise;
3169 END AnyJustificationRequired;
3170
3171
3172 ----------------------------------------------------------------------
3173 PROCEDURE CreditLinesOnly(p_item_type IN VARCHAR2,
3174 p_item_key IN VARCHAR2,
3175 p_actid IN NUMBER,
3176 p_funmode IN VARCHAR2,
3177 p_result OUT NOCOPY VARCHAR2) IS
3178 ----------------------------------------------------------------------
3179 l_report_header_id NUMBER;
3180 l_debug_info VARCHAR2(200);
3181 l_new_expense_total NUMBER;
3182 BEGIN
3183
3184 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start CreditLinesOnly');
3185
3186 IF (p_funmode = 'RUN') THEN
3187 ----------------------------------------------------------------
3188 l_debug_info := 'Retrieve New Expense Total.';
3189 ----------------------------------------------------------------
3190 l_new_expense_total := WF_ENGINE.GetItemAttrNumber(p_item_type,
3191 p_item_key,
3192 'POS_NEW_EXPENSE_TOTAL');
3193
3194 IF (l_new_expense_total = 0) THEN
3195 p_result := 'COMPLETE:Y';
3196 ELSE
3197 p_result := 'COMPLETE:N';
3198 END IF;
3199
3200
3201 ELSIF (p_funmode = 'CANCEL') THEN
3202 p_result := 'COMPLETE';
3203 END IF;
3204
3205 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end CreditLinesOnly');
3206
3207 EXCEPTION
3208 WHEN OTHERS THEN
3209 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'CreditLinesOnly',
3210 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
3211 raise;
3212
3213 END CreditLinesOnly;
3214
3215
3216
3217
3218 /* This function is used to check if the current process is of the 'old' workflow
3219 which doesn't have the BLOCK activity after the AP_REVIEW_COMPLETE. This code
3220 should be removed after all 10.7 and 11.0.2 customers have upgraded to 11 or 11i.
3221 */
3222 FUNCTION isOldProcess(p_actid IN NUMBER,
3223 p_item_key IN VARCHAR2) return boolean
3224 IS
3225 l_resultType WF_ACTIVITIES.result_type%TYPE;
3226 BEGIN
3227
3228 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start isOldProcess');
3229
3230 select wa.result_type
3231 into l_resultType
3232 from WF_PROCESS_ACTIVITIES WPA, WF_ACTIVITIES WA, wf_items wi
3233 where WPA.INSTANCE_ID = p_actid
3234 and WPA.ACTIVITY_ITEM_TYPE = WA.ITEM_TYPE
3235 and WPA.ACTIVITY_NAME = WA.NAME
3236 and wi.begin_date >= WA.BEGIN_DATE
3237 and wi.begin_date < nvl(WA.END_DATE, wi.begin_date+1)
3238 and wi.item_type = wa.item_type
3239 and wi.item_key = p_item_key;
3240
3241 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end isOldProcess');
3242
3243 --In the 'old' expense report workflow, AP_REVIEW_COMPLETE activity doesn't have result.
3244 if (l_resultType = '*') then
3245 return TRUE;
3246 else
3247 return FALSE;
3248 END IF;
3249 END isOldProcess;
3250
3251
3252 ----------------------------------------------------------------------
3253 PROCEDURE OldAPReviewComplete(p_item_type IN VARCHAR2,
3254 p_item_key IN VARCHAR2,
3255 p_actid IN NUMBER,
3256 p_funmode IN VARCHAR2,
3257 p_result OUT NOCOPY VARCHAR2) IS
3258 ----------------------------------------------------------------------
3259 l_report_header_id NUMBER;
3260 l_ap_review_status VARCHAR2(1);
3261 l_debug_info VARCHAR2(200);
3262 l_wakeup_time DATE;
3263 BEGIN
3264
3265 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start OldAPReviewComplete');
3266
3267 ------------------------------------------------------------
3268 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
3269 ------------------------------------------------------------
3270 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
3271 p_item_key,
3272 'EXPENSE_REPORT_ID');
3273
3274 l_wakeup_time := (Wf_Engine.GetActivityAttrNumber(p_item_type, p_item_key,
3275 p_actid, 'TIME_INTERVAL_BETWEEN_CHECKS')/24) + sysdate;
3276
3277 ----------------------------------
3278 l_debug_info := 'Set Org Context';
3279 ----------------------------------
3280 AP_WEB_UTILITIES_PKG.ExpenseSetOrgContext(l_report_header_id);
3281
3282 -------------------------------------------------
3283 l_debug_info := 'Retrieve The AP Reviewed Flag';
3284 -------------------------------------------------
3285 SELECT nvl(workflow_approved_flag, 'N')
3286 INTO l_ap_review_status
3287 FROM ap_expense_report_headers
3288 WHERE report_header_id = l_report_header_id;
3289
3290 ------------------------------------------------------------------
3291 l_debug_info := 'Check flag to determine if AP Review Complete and
3292 return Y if so, otherwise N';
3293 ------------------------------------------------------------------
3294 IF (l_ap_review_status = 'Y') THEN
3295 p_result := wf_engine.eng_null;
3296 ELSE
3297 -- Set status of activity to deferred with begin_date set to wakeup_date.
3298 -- For Workflow 1.0 we would call:
3299 -- Wf_Item_Activity_Status.Update_Status(p_item_type, p_item_key,
3300 -- p_actid,'DEFERRED', 'WAITING', l_wakeup_time, null);
3301 -- For Workflow 2.0 (update_status nolonger exists, so we would need to
3302 -- call create_status whose parameters changed from 1.0:
3303 -- Wf_Item_Activity_Status.Update_Status(p_item_type, p_item_key,
3304 -- p_actid,'DEFERRED', 'WAITING', l_wakeup_time, null);
3305 -- Since neither call is compatible for both versions and there's no
3306 -- api to determine which version of workflow is installed, we needed
3307 -- to call the update statement directly.
3308 -- In the future (after Workflow 2.0 production), the Workflow team will
3309 -- provide a new interface that will be compatible for both, like us
3310 -- returning a result of 'DEFERED:l_wakeup_time', and they will take care
3311 -- of running the sql statement.
3312
3313 UPDATE WF_ITEM_ACTIVITY_STATUSES
3314 SET begin_date = l_wakeup_time
3315 WHERE item_type = p_item_type
3316 AND item_key = p_item_key
3317 AND process_activity = p_actid;
3318
3319 p_result := wf_engine.eng_deferred;
3320 END IF;
3321
3322
3323 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end OldAPReviewComplete');
3324
3325 EXCEPTION
3326 WHEN OTHERS THEN
3327 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'OldAPReviewComplete',
3328 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
3329 raise;
3330 END OldAPReviewComplete;
3331
3332
3333 ----------------------------------------------------------------------
3334 PROCEDURE APReviewComplete(p_item_type IN VARCHAR2,
3335 p_item_key IN VARCHAR2,
3336 p_actid IN NUMBER,
3337 p_funmode IN VARCHAR2,
3338 p_result OUT NOCOPY VARCHAR2) IS
3339 ----------------------------------------------------------------------
3340 l_report_header_id AP_WEB_DB_EXPRPT_PKG.expHdr_headerID;
3341 l_ap_review_status AP_WEB_DB_EXPRPT_PKG.expHdr_wkflApprvdFlag;
3342 l_debug_info VARCHAR2(200);
3343
3344 l_WorkflowRec AP_WEB_DB_EXPRPT_PKG.ExpWorkflowRec;
3345 C_WF_Version NUMBER := 0;
3346 BEGIN
3347
3348 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start APReviewComplete');
3349
3350 -- Do nothing in cancel mode
3351 IF (p_funmode = wf_engine.eng_cancel) THEN
3352 p_result := wf_engine.eng_null;
3353 return;
3354 end if;
3355
3356
3357 ------------------------------------------------------------
3358 l_debug_info := 'Check for old workflow';
3359 ------------------------------------------------------------
3360 -- Bug 1576769: Should remove this check when there is no 10.7 and 11.0.2 users
3361 IF isOldProcess(p_actid, p_item_key) THEN
3362 OldAPReviewComplete(p_item_type,
3363 p_item_key,
3364 p_actid,
3365 p_funmode,
3366 p_result);
3367 return;
3368 END IF;
3369
3370 -----------------------------------------------------
3371 l_debug_info := 'Get Workflow Version Number';
3372 -----------------------------------------------------
3373 C_WF_Version := AP_WEB_EXPENSE_WF.GetFlowVersion(p_item_type, p_item_key);
3374
3375 ------------------------------------------------------------
3376 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
3377 ------------------------------------------------------------
3378 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
3379 p_item_key,
3380 'EXPENSE_REPORT_ID');
3381
3382
3383 -------------------------------------------------
3384 l_debug_info := 'Retrieve The AP Reviewed Flag';
3385 -------------------------------------------------
3386 IF (AP_WEB_DB_EXPRPT_PKG.GetExpWorkflowInfo(l_report_header_id,
3387 l_WorkflowRec)) THEN
3388 l_ap_review_status := nvl(l_WorkflowRec.workflow_flag, 'N');
3389 END IF;
3390
3391 ------------------------------------------------------------------
3392 l_debug_info := 'Check flag to determine if AP Review Complete and
3393 return Y if so, otherwise N';
3394 ------------------------------------------------------------------
3395 IF (l_ap_review_status = 'Y' or
3396 l_ap_review_status = AP_WEB_DB_EXPRPT_PKG.C_WORKFLOW_APPROVED_REJECTED or -- already AP rejected
3397 l_ap_review_status = AP_WEB_DB_EXPRPT_PKG.C_WORKFLOW_APPROVED_REQUEST) THEN -- already AP requests more info
3398 -- p_result := wf_engine.eng_null;
3399 -- dtong changed p_result for bug # 839208
3400 p_result := 'COMPLETE:Y';
3401 ELSE
3402 --bug 7449880: check the version and update expense_status_code
3403 --for reports submitted prior to oie.g, in later releases its updated in
3404 --SetStatusApproverAndDate which is just prior to AP_VERIFY_BLOCK,
3405
3406 IF (C_WF_Version < AP_WEB_EXPENSE_WF.C_OIEH_Version) THEN
3407 -------------------------------------------------------------------
3408 l_debug_info := 'Set Expense Status Code';
3409 -------------------------------------------------------------------
3410 UPDATE ap_expense_report_headers_all
3411 SET expense_status_code = 'MGRAPPR'
3412 WHERE report_header_id = l_report_header_id;
3413 END IF;
3414
3415 -- Set status of activity to deferred with begin_date set to wakeup_date.
3416 -- For Workflow 1.0 we would call:
3417 -- Wf_Item_Activity_Status.Update_Status(p_item_type, p_item_key,
3418 -- p_actid,'DEFERRED', 'WAITING', l_wakeup_time, null);
3419 -- For Workflow 2.0 (update_status nolonger exists, so we would need to
3420 -- call create_status whose parameters changed from 1.0:
3421 -- Wf_Item_Activity_Status.Update_Status(p_item_type, p_item_key,
3422 -- p_actid,'DEFERRED', 'WAITING', l_wakeup_time, null);
3423 -- Since neither call is compatible for both versions and there's no
3424 -- api to determine which version of workflow is installed, we needed
3425 -- to call the update statement directly.
3426 -- In the future (after Workflow 2.0 production), the Workflow team will
3427 -- provide a new interface that will be compatible for both, like us
3428 -- returning a result of 'DEFERED:l_wakeup_time', and they will take care
3429 -- of running the sql statement.
3430 /*
3431 UPDATE WF_ITEM_ACTIVITY_STATUSES
3432 SET begin_date = l_wakeup_time
3433 WHERE item_type = p_item_type
3434 AND item_key = p_item_key
3435 AND process_activity = p_actid;
3436
3437 p_result := wf_engine.eng_deferred;
3438 */
3439 p_result :='COMPLETE:N';
3440 END IF;
3441
3442
3443 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end APReviewComplete');
3444
3445 EXCEPTION
3446 WHEN OTHERS THEN
3447 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'APReviewComplete',
3448 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
3449 raise;
3450 END APReviewComplete;
3451
3452
3453 ----------------------------------------------------------------------
3454 PROCEDURE AnyAPAdjustments(p_item_type IN VARCHAR2,
3455 p_item_key IN VARCHAR2,
3456 p_actid IN NUMBER,
3457 p_funmode IN VARCHAR2,
3458 p_result OUT NOCOPY VARCHAR2) IS
3459 ----------------------------------------------------------------------
3460 l_report_header_id AP_WEB_DB_EXPLINE_PKG.expLines_headerID;
3461 l_orig_expe_report_amt NUMBER;
3462 l_exp_report_amount AP_WEB_DB_EXPRPT_PKG.expHdr_total;
3463 l_orig_exp_report_amt NUMBER;
3464 l_expense_type AP_WEB_DB_EXPTEMPLATE_PKG.expTempl_webFriendlyPrompt;
3465 l_amount AP_WEB_DB_EXPLINE_PKG.expLines_amount;
3466 l_adjustment_reason AP_WEB_DB_EXPLINE_PKG.expLines_adjReason;
3467
3468 l_currency VARCHAR2(50);
3469 l_adjustment_line VARCHAR2(2000);
3470 l_adj_info_body VARCHAR2(2000);
3471 l_debug_info VARCHAR2(200);
3472 l_num_lines INTEGER := 0;
3473 i INTEGER;
3474 j INTEGER;
3475 l_payment_due VARCHAR2(10) := C_IndividualPay;
3476 l_total NUMBER := 0;
3477 l_ccard_amt AP_WEB_DB_EXPRPT_PKG.expHdr_amtDueCCardCompany;
3478 l_emp_amt AP_WEB_DB_EXPRPT_PKG.expHdr_amtDueEmployee;
3479 C_CreditLineVersion CONSTANT NUMBER := 1;
3480 C_WF_Version NUMBER := 0;
3481
3482 /* jrautiai ADJ Fix Start */
3483 AdjustmentsCursor AP_WEB_DB_EXPLINE_PKG.AdjustmentCursorType;
3484 adjustment_rec AP_WEB_DB_EXPLINE_PKG.AdjustmentRecordType;
3485
3486 l_mess Wf_Item_Attribute_Values.TEXT_VALUE%TYPE;
3487 l_crd_card_count NUMBER := 0;
3488
3489 l_no_receipts_ccard_amt NUMBER := 0;
3490 l_no_receipts_emp_amt NUMBER := 0;
3491 l_policy_ccard_amt NUMBER := 0;
3492 l_policy_emp_amt NUMBER := 0;
3493 l_policy_shortpay_total NUMBER := 0;
3494 /* jrautiai ADJ Fix End */
3495
3496 l_ExpRec AP_WEB_DB_EXPRPT_PKG.ExpInfoRec;
3497 l_reimb_currency ap_expense_report_headers_all.payment_currency_code%type;
3498 BEGIN
3499
3500 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start AnyAPAdjustments');
3501
3502 IF (p_funmode = 'RUN') THEN
3503
3504
3505 -----------------------------------------------------
3506 l_debug_info := 'Get Workflow Version Number 2';
3507 -----------------------------------------------------
3508 C_WF_Version := GetFlowVersion(p_item_type, p_item_key);
3509
3510 ------------------------------------------------------------
3511 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
3512 ------------------------------------------------------------
3513 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
3514 p_item_key,
3515 'EXPENSE_REPORT_ID');
3516
3517 ------------------------------------------------------------
3518 l_debug_info := 'Retrieve Currency Item Attribute';
3519 ------------------------------------------------------------
3520 l_currency := WF_ENGINE.GetItemAttrText(p_item_type,
3521 p_item_key,
3522 'CURRENCY');
3523
3524 -------------------------------------------------------
3525 l_debug_info := 'Retrieve Orignal Expense Report Total';
3526 -------------------------------------------------------
3527 l_orig_exp_report_amt := WF_ENGINE.GetItemAttrNumber(p_item_type,
3528 p_item_key,
3529 'TOTAL');
3530
3531 ----------------------------------------------------
3532 l_debug_info := 'Retrieve Currency Item Attribute';
3533 ----------------------------------------------------
3534 l_reimb_currency := WF_ENGINE.GetItemAttrText(p_item_type,
3535 p_item_key,
3536 'CURRENCY');
3537
3538 /* jrautiai ADJ Fix Start */
3539 ----------------------------------------------------------------
3540 l_debug_info := 'Set #FROM_ROLE to AP';
3541 ----------------------------------------------------------------
3542 SetFromRoleAP(p_item_type, p_item_key, p_actid, p_funmode, p_result);
3543
3544 ---------------------------------------------------------
3545 l_debug_info := 'Retrieve Payment Due From';
3546 ---------------------------------------------------------
3547 l_payment_due := WF_ENGINE.GetItemAttrText(p_item_type,p_item_key,'PAYMENT_DUE_FROM');
3548
3549 IF (NOT AP_WEB_DB_EXPLINE_PKG.GetNumCCLinesIncluded(l_report_header_id,
3550 l_crd_card_count)) THEN
3551 l_crd_card_count := 0;
3552 END IF;
3553
3554 IF l_payment_due = C_BothPay AND nvl(l_crd_card_count,0) > 0 THEN
3555 FND_MESSAGE.SET_NAME('SQLAP','OIE_WF_ADJ_REIMBURSEMENT_INST2');
3556 l_mess := FND_MESSAGE.GET;
3557 ELSE
3558 FND_MESSAGE.SET_NAME('SQLAP','OIE_WF_ADJ_REIMBURSEMENT_INST1');
3559 l_mess := FND_MESSAGE.GET;
3560 END IF;
3561
3562 WF_ENGINE.SetItemAttrText(p_item_type,
3563 p_item_key,
3564 'INSTRUCTION',
3565 l_mess);
3566
3567 FND_MESSAGE.SET_NAME('SQLAP','OIE_WF_ADJUSTMENT_NOTE');
3568 l_mess := FND_MESSAGE.GET;
3569
3570 WF_ENGINE.SetItemAttrText(p_item_type,
3571 p_item_key,
3572 'WF_NOTE',
3573 l_mess);
3574 /* jrautiai ADJ Fix End */
3575
3576 --------------------------------------------------------
3577 l_debug_info := 'Retrieve Current Expense Report Total';
3578 --------------------------------------------------------
3579 IF (AP_WEB_DB_EXPRPT_PKG.GetReportInfo(l_report_header_id, l_ExpRec)) THEN
3580 l_exp_report_amount := l_ExpRec.total;
3581 ELSE
3582 l_exp_report_amount := 0;
3583 END IF;
3584
3585 --------------------------------------------------------------------------
3586 l_debug_info := 'If Original Total and Current Total Different Then
3587 Adjustment was made, return Y and retrieve adjusted lines';
3588 --------------------------------------------------------------------------
3589 -- bug 3404699:round to reimbursment currency precision
3590 IF (AP_WEB_UTILITIES_PKG.Oie_Round_Currency(l_orig_exp_report_amt,l_reimb_currency) <>
3591 l_exp_report_amount OR AP_WEB_DB_EXPLINE_PKG.GetAdjustedLineExists(l_report_header_id)) THEN
3592 p_result := 'COMPLETE:Y';
3593
3594 --------------------------------------------
3595 l_debug_info := 'Calculate Amt Due and Total';
3596 --------------------------------------------
3597 /* jrautiai ADJ Fix Start */
3598 IF (NOT AP_WEB_DB_EXPLINE_PKG.CalculateAmtsDue(l_report_header_id,
3599 l_payment_due,
3600 l_emp_amt,
3601 l_ccard_amt,
3602 l_total)) THEN
3603 l_emp_amt:=0;
3604 l_ccard_amt:=0;
3605 l_total := 0;
3606 END IF;
3607 /* jrautiai ADJ Fix End */
3608
3609 ----------------------------------------------------------
3610 l_debug_info := 'Update the Headers table with the new Amt
3611 Dues and Total columns';
3612 ----------------------------------------------------------
3613 IF (NOT AP_WEB_DB_EXPRPT_PKG.SetAmtDuesAndTotal(
3614 l_report_header_id,
3615 nvl(l_ccard_amt,0),
3616 nvl(l_emp_amt,0),
3617 l_total)) THEN
3618 NULL;
3619 END IF;
3620
3621 IF (C_WF_VERSION < AP_WEB_EXPENSE_WF.C_NoMultiLineVersion) THEN
3622 ------------------------------------------
3623 l_debug_info := 'Open Adjustments Cursor';
3624 ------------------------------------------
3625 -- jrautiai ADJ Fix
3626 IF (AP_WEB_DB_EXPLINE_PKG.GetAdjustmentsCursor(l_report_header_id, 'ADJUSTMENT', AdjustmentsCursor)) THEN
3627 FOR i IN 1..10 LOOP
3628
3629 ------------------------------------------
3630 l_debug_info := 'Fetch Adjustments Cursor';
3631 ------------------------------------------
3632 -- jrautiai ADJ Fix, fetching the results into a record instead of variable.
3633 FETCH AdjustmentsCursor INTO adjustment_rec;
3634 EXIT WHEN AdjustmentsCursor%NOTFOUND;
3635
3636 -----------------------------------------
3637 l_debug_info := 'Format Adjustment Line';
3638 -----------------------------------------
3639 -- jrautiai ADJ Fix, taking the results from a record instead of variable.
3640 l_adjustment_line := adjustment_rec.expense_type_disp || ' ' || to_char(adjustment_rec.amount,FND_CURRENCY.Get_Format_Mask(l_currency,22)) || ' ' || adjustment_rec.adjustment_reason;
3641
3642 -----------------------------------------------------
3643 l_debug_info := 'Set Adjustment Line Item Attribute';
3644 -----------------------------------------------------
3645
3646 WF_ENGINE.SetItemAttrText(p_item_type,
3647 p_item_key,
3648 'ADJ_LINE' || to_char(i),
3649 l_adjustment_line);
3650
3651 l_num_lines := i;
3652 END LOOP;
3653 END IF;
3654
3655 if AdjustmentsCursor%isopen then
3656 CLOSE AdjustmentsCursor;
3657 end if;
3658
3659 END IF;
3660
3661 IF (C_WF_VERSION >= AP_WEB_EXPENSE_WF.C_NoMultiLineVersion) THEN
3662
3663 ----------------------------------------------------------
3664 l_debug_info := 'Set Item Attribute Line_Info_Body1';
3665 ---------------------------------------------------------
3666 WF_ENGINE.SetItemAttrText(p_item_type,
3667 p_item_key,
3668 'LINE_INFO_BODY',
3669 'plsql:AP_WEB_EXPENSE_WF.generateAdjustmentInfo/'|| p_item_type || ':' || p_item_key || ':ADJUSTMENT');
3670
3671 ELSE
3672 l_adj_info_body := '';
3673 ---------------------------------------------------------
3674 l_debug_info := 'Populating line_info_body with tokens';
3675 ---------------------------------------------------------
3676 FOR j in 1..l_num_lines LOOP
3677
3678 l_adj_info_body := l_adj_info_body || '
3679 ' || '&' || 'ADJ_LINE' || to_char(j);
3680
3681 END LOOP;
3682
3683 ---------------------------------------------------------
3684 l_debug_info := 'Set Item Attribute Line_Info_Body1';
3685 ---------------------------------------------------------
3686 WF_ENGINE.SetItemAttrText(p_item_type,
3687 p_item_key,
3688 'LINE_INFO_BODY',
3689 l_adj_info_body);
3690 IF (C_WF_Version >= C_CreditLineVersion) THEN
3691 ---------------------------------------------------------
3692 l_debug_info := 'Set Item Attribute Credit_Line_Info_Body1';
3693 ---------------------------------------------------------
3694 WF_ENGINE.SetItemAttrText(p_item_type,
3695 p_item_key,
3696 'CREDIT_LINE_INFO_BODY',
3697 '');
3698 END IF;
3699 END IF;
3700
3701
3702 /* jrautiai ADJ Fix Start */
3703 -----------------------------------------------------
3704 l_debug_info := 'Set New Adjusted Total Item Attribute';
3705 -----------------------------------------------------
3706 WF_ENGINE.SetItemAttrNumber(p_item_type,
3707 p_item_key,
3708 'TOTAL',
3709 l_total);
3710
3711 -----------------------------------------------------------------
3712 l_debug_info := 'Set New Adjusted Display_Total Item Attribute';
3713 -----------------------------------------------------------------
3714 WF_ENGINE.SetItemAttrText(p_item_type,
3715 p_item_key,
3716 'DISPLAY_TOTAL',
3717 to_char(l_total,FND_CURRENCY.Get_Format_Mask(l_currency,22)) || ' ' || l_currency);
3718
3719 /* jrautiai ADJ Fix end */
3720
3721 IF (C_WF_Version >= C_CreditLineVersion) THEN
3722 -----------------------------------------------------
3723 l_debug_info := 'Set New Credit Total Item Attribute';
3724 -----------------------------------------------------
3725 WF_ENGINE.SetItemAttrNumber(p_item_type,
3726 p_item_key,
3727 'NEG_CREDIT_TOTAL',
3728 0);
3729
3730 -----------------------------------------------------------------
3731 l_debug_info := 'Set New Credit_Display_Total Item Attribute';
3732 -----------------------------------------------------------------
3733 WF_ENGINE.SetItemAttrText(p_item_type,
3734 p_item_key,
3735 'NEG_CREDIT_DISPLAY_TOTAL',
3736 to_char(0,FND_CURRENCY.Get_Format_Mask(l_currency,22)));
3737
3738
3739 -----------------------------------------------------
3740 l_debug_info := 'Set New New_Expense_Total Item Attribute';
3741 -----------------------------------------------------
3742 WF_ENGINE.SetItemAttrNumber(p_item_type,
3743 p_item_key,
3744 'POS_NEW_EXPENSE_TOTAL',
3745 0);
3746
3747 -----------------------------------------------------------------
3748 l_debug_info := 'Set New New_Expense_Display_Total Item Attribute';
3749 -----------------------------------------------------------------
3750 WF_ENGINE.SetItemAttrText(p_item_type,
3751 p_item_key,
3752 'POS_NEW_EXPENSE_DISPLAY_TOTAL',
3753 to_char(0,FND_CURRENCY.Get_Format_Mask(l_currency,22)));
3754
3755
3756 END IF;
3757
3758 ELSE
3759
3760 -------------------------------------------------
3761 l_debug_info := 'Return N if no adjustment made';
3762 -------------------------------------------------
3763 p_result := 'COMPLETE:N';
3764
3765 END IF;
3766
3767 ELSIF (p_funmode = 'CANCEL') THEN
3768
3769 p_result := 'COMPLETE';
3770
3771 END IF;
3772
3773 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end AnyAPAdjustments');
3774
3775 EXCEPTION
3776 WHEN OTHERS THEN
3777 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'AnyAPAdjustments',
3778 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
3779 raise;
3780 END AnyAPAdjustments;
3781
3782 ----------------------------------------------------------------------
3783 PROCEDURE AllReqReceiptsVerified(p_item_type IN VARCHAR2,
3784 p_item_key IN VARCHAR2,
3785 p_actid IN NUMBER,
3786 p_funmode IN VARCHAR2,
3787 p_result OUT NOCOPY VARCHAR2) IS
3788 ----------------------------------------------------------------------
3789 l_report_header_id AP_WEB_DB_EXPLINE_PKG.expLines_headerID;
3790 l_num_req_receipt_not_verified NUMBER;
3791 l_debug_info VARCHAR2(200);
3792 BEGIN
3793
3794 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start AllReqReceiptsVerified');
3795
3796 IF (p_funmode = 'RUN') THEN
3797
3798 ------------------------------------------------------------
3799 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
3800 ------------------------------------------------------------
3801 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
3802 p_item_key,
3803 'EXPENSE_REPORT_ID');
3804
3805 ----------------------------------------------------------------------
3806 l_debug_info := 'Calculate Number of Lines With Receipt Required that
3807 have not been verified';
3808 ----------------------------------------------------------------------
3809 IF (NOT AP_WEB_DB_EXPLINE_PKG.GetNumReceiptShortpaidLines(
3810 l_report_header_id,
3811 l_num_req_receipt_not_verified)) THEN
3812 l_num_req_receipt_not_verified := 0;
3813 END IF;
3814
3815 IF (l_num_req_receipt_not_verified > 0) THEN
3816 ----------------------------------------------------------------------
3817 l_debug_info := 'Return N if there exists a line with receipt required
3818 and has not been verified';
3819 ----------------------------------------------------------------------
3820 p_result := 'COMPLETE:N';
3821 ELSE
3822 p_result := 'COMPLETE:Y';
3823 END IF;
3824
3825
3826 ELSIF (p_funmode = 'CANCEL') THEN
3827 p_result := 'COMPLETE';
3828 END IF;
3829
3830 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end AllReqReceiptsVerified');
3831
3832 EXCEPTION
3833 WHEN OTHERS THEN
3834 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'AllReqReceiptsVerified',
3835 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
3836 raise;
3837 END AllReqReceiptsVerified;
3838
3839 ----------------------------------------------------------------------
3840 PROCEDURE AllPassAPApproval(p_item_type IN VARCHAR2,
3841 p_item_key IN VARCHAR2,
3842 p_actid IN NUMBER,
3843 p_funmode IN VARCHAR2,
3844 p_result OUT NOCOPY VARCHAR2) IS
3845 ----------------------------------------------------------------------
3846 l_report_header_id AP_WEB_DB_EXPLINE_PKG.expLines_headerID;
3847 l_num_req_receipt_not_verified NUMBER;
3848 l_debug_info VARCHAR2(200);
3849 BEGIN
3850
3851 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start AllPassAPApproval');
3852
3853 IF (p_funmode = 'RUN') THEN
3854
3855 ------------------------------------------------------------
3856 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
3857 ------------------------------------------------------------
3858 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
3859 p_item_key,
3860 'EXPENSE_REPORT_ID');
3861
3862
3863 ----------------------------------------------------------------------
3864 l_debug_info := 'Calculate Number of Lines With Receipt Required that
3865 have not been verified';
3866 ----------------------------------------------------------------------
3867 IF (NOT AP_WEB_DB_EXPLINE_PKG.GetNumShortpaidLines(l_report_header_id,
3868 l_num_req_receipt_not_verified)) THEN
3869 l_num_req_receipt_not_verified := 0;
3870 END IF;
3871
3872 IF (l_num_req_receipt_not_verified > 0) THEN
3873 ----------------------------------------------------------------------
3874 l_debug_info := 'Return N if there exists a line with receipt required
3875 and has not been verified';
3876 ----------------------------------------------------------------------
3877 p_result := 'COMPLETE:N';
3878 ELSE
3879 p_result := 'COMPLETE:Y';
3880 END IF;
3881
3882
3883 ELSIF (p_funmode = 'CANCEL') THEN
3884 p_result := 'COMPLETE';
3885 END IF;
3886
3887 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end AllPassAPApproval');
3888
3889 EXCEPTION
3890 WHEN OTHERS THEN
3891 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'AllPassAPApproval',
3892 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
3893 raise;
3894 END AllPassAPApproval;
3895
3896 ----------------------------------------------------------------------
3897 PROCEDURE Approved(p_item_type IN VARCHAR2,
3898 p_item_key IN VARCHAR2,
3899 p_actid IN NUMBER,
3900 p_funmode IN VARCHAR2,
3901 p_result OUT NOCOPY VARCHAR2) IS
3902 ----------------------------------------------------------------------
3903 l_report_header_id AP_WEB_DB_EXPRPT_PKG.expHdr_headerID;
3904 l_payment_due VARCHAR2(10) := C_IndividualPay;
3905 l_debug_info VARCHAR2(200);
3906 C_WF_Version NUMBER := 0;
3907 BEGIN
3908
3909 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start Approved');
3910
3911 IF (p_funmode = 'RUN') THEN
3912
3913 -----------------------------------------------------
3914 l_debug_info := 'Get Workflow Version Number';
3915 -----------------------------------------------------
3916 C_WF_Version := AP_WEB_EXPENSE_WF.GetFlowVersion(p_item_type, p_item_key);
3917
3918 ------------------------------------------------------------
3919 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
3920 ------------------------------------------------------------
3921 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
3922 p_item_key,
3923 'EXPENSE_REPORT_ID');
3924
3925 ---------------------------------------------------------
3926 l_debug_info := 'Retrieve Payment Due From System Option';
3927 ---------------------------------------------------------
3928 l_payment_due := WF_ENGINE.GetItemAttrText(p_item_type,p_item_key,'PAYMENT_DUE_FROM');
3929
3930 ------------------------------------------
3931 l_debug_info := 'Call CustomDataTransfer';
3932 ------------------------------------------
3933 AP_WEB_EXPENSE_CUST_WF.CustomDataTransfer(p_item_type,
3934 p_item_key);
3935
3936 ----------------------------------------------------------------------
3937 l_debug_info := 'Update the Expense Report as Approved, if the expense
3938 report has only been manager approved then mark it as
3939 approved automatic';
3940 ----------------------------------------------------------------------
3941 --bug 7449880: check the version and update source for reports submitted
3942 --prior to oie.j, from oiej the source is updated at the end in
3943 --SetStatusApproverAndDate, from oie.g expense_status_code is updated
3944 --at the end in SetStatusApproverAndDate
3945
3946 IF (C_WF_Version >= AP_WEB_EXPENSE_WF.C_OIEJ_Version) THEN
3947 IF (NOT AP_WEB_DB_EXPRPT_PKG.SetWkflApprvdFlagAndSource(
3948 l_report_header_id, NULL, NULL)) THEN
3949 NULL;
3950 END IF;
3951 ELSE
3952 IF (NOT AP_WEB_DB_EXPRPT_PKG.SetWkflApprvdFlagAndSource(
3953 l_report_header_id, NULL, 'SelfService')) THEN
3954 NULL;
3955 END IF;
3956 END IF;
3957
3958 IF (C_WF_Version < AP_WEB_EXPENSE_WF.C_OIEH_Version) THEN
3959 -------------------------------------------------------------------
3960 l_debug_info := 'Set Expense Status Code';
3961 -------------------------------------------------------------------
3962 UPDATE ap_expense_report_headers_all
3963 SET expense_status_code = 'INVOICED',
3964 last_update_date = SYSDATE
3965 --last_updated_by = Decode(Nvl(fnd_global.user_id,-1),-1,last_updated_by,fnd_global.user_id)
3966 WHERE report_header_id = l_report_header_id;
3967 END IF;
3968
3969 ----------------------------------------------------------------------
3970 l_debug_info := 'Update the Credit Card Trxns associated with the Expense
3971 Report as Approved';
3972 ----------------------------------------------------------------------
3973 IF (l_payment_due = C_BothPay OR l_payment_due = C_CompanyPay) THEN
3974 IF (NOT AP_WEB_DB_CCARD_PKG.SetStatus(l_report_header_id, 'APPROVED')) THEN
3975 NULL;
3976 END IF;
3977 END IF;
3978
3979 ELSIF (p_funmode = 'CANCEL') THEN
3980 p_result := 'COMPLETE';
3981 END IF;
3982
3983 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end Approved');
3984
3985 EXCEPTION
3986 WHEN NO_DATA_FOUND THEN
3987 null;
3988 WHEN OTHERS THEN
3989 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'Approved',
3990 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
3991 raise;
3992 END Approved;
3993
3994 ------------------------------------------------------------------------
3995 PROCEDURE SetShortPaidLinesInfo(p_item_type IN VARCHAR2,
3996 p_item_key IN VARCHAR2,
3997 p_actid IN NUMBER,
3998 p_funmode IN VARCHAR2,
3999 p_notification_type IN VARCHAR2,
4000 p_result OUT NOCOPY VARCHAR2) IS
4001 -------------------------------------------------------------------------
4002 l_exp_report_id AP_WEB_DB_EXPLINE_PKG.expLines_headerID;
4003 l_currency VARCHAR2(15);
4004 l_shortpay_line VARCHAR2(2000);
4005 l_shortpay_info_body VARCHAR2(2000) := '';
4006 l_num_lines NUMBER := 0;
4007 i NUMBER;
4008 j NUMBER;
4009 l_debug_info VARCHAR2(2000);
4010
4011 C_CreditLineVersion CONSTANT NUMBER := 1;
4012 C_WF_Version NUMBER := 0;
4013
4014 -- jrautiai ADJ Fix, changed shortpay to refer the new cursor type.
4015 ShortpaidLinesCursor AP_WEB_DB_EXPLINE_PKG.AdjustmentCursorType;
4016
4017 -- jrautiai ADJ Fix, fetching the shortpay results into a record of a common type.
4018 shortpay_rec AP_WEB_DB_EXPLINE_PKG.AdjustmentRecordType;
4019
4020
4021 BEGIN
4022
4023 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start SetShortPaidLinesInfo');
4024
4025 -----------------------------------------------------
4026 l_debug_info := 'Get Workflow Version Number 3';
4027 -----------------------------------------------------
4028 C_WF_Version := GetFlowVersion(p_item_type, p_item_key);
4029
4030 ------------------------------------------------------------
4031 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
4032 ------------------------------------------------------------
4033 l_exp_report_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
4034 p_item_key,
4035 'EXPENSE_REPORT_ID');
4036
4037 ------------------------------------------------------------
4038 l_debug_info := 'Retrieve Currency Item Attribute';
4039 ------------------------------------------------------------
4040 l_currency := WF_ENGINE.GetItemAttrText(p_item_type,
4041 p_item_key,
4042 'CURRENCY');
4043
4044
4045
4046 ----------------------------------
4047 l_debug_info := 'Check to see if the version is before 2.0.3';
4048 ----------------------------------
4049 IF (C_WF_VERSION < AP_WEB_EXPENSE_WF.C_NoMultiLineVersion) THEN
4050 -----------------------------------------------------
4051 l_debug_info := 'Clear Adjustment Line Item Attributes';
4052 -----------------------------------------------------
4053 FOR i IN 1..10 LOOP
4054 WF_ENGINE.SetItemAttrText(p_item_type,
4055 p_item_key,
4056 'ADJ_LINE' || to_char(i),
4057 '');
4058
4059 END LOOP;
4060 END IF;
4061
4062 i := 1;
4063
4064 ------------------------------------------
4065 l_debug_info := 'Open ShortPaidLines Cursor';
4066 ------------------------------------------
4067 -- jrautiai ADJ Fix, using common cursor with adjustments.
4068 IF (AP_WEB_DB_EXPLINE_PKG.GetAdjustmentsCursor(l_exp_report_id, 'SHORTPAY', ShortpaidLinesCursor)) THEN
4069
4070 FOR i IN 1..10 LOOP
4071
4072 ------------------------------------------
4073 l_debug_info := 'Fetch ShortPaidLiness Cursor';
4074 ------------------------------------------
4075 -- jrautiai ADJ Fix, fetching the results into a record instead of variable.
4076 FETCH ShortpaidLinesCursor INTO shortpay_rec;
4077 EXIT WHEN ShortpaidLinesCursor%NOTFOUND;
4078
4079 -----------------------------------------
4080 l_debug_info := 'Format ShortPay Line';
4081 -----------------------------------------
4082 l_shortpay_line := shortpay_rec.expense_type_disp || ' ' || to_char(shortpay_rec.amount,FND_CURRENCY.Get_Format_Mask(l_currency,22)) || ' ' || l_currency || ' ' || shortpay_rec.adjustment_reason;
4083
4084 -----------------------------------------------------
4085 l_debug_info := 'Reuse Adjustment Line Item Attribute';
4086 -----------------------------------------------------
4087 IF (C_WF_VERSION < AP_WEB_EXPENSE_WF.C_NoMultiLineVersion) THEN
4088 WF_ENGINE.SetItemAttrText(p_item_type,
4089 p_item_key,
4090 'ADJ_LINE' || to_char(i),
4091 l_shortpay_line);
4092 END IF;
4093 l_num_lines := i;
4094
4095 END LOOP;
4096 END IF;
4097
4098 if ShortpaidLinesCursor%isopen then
4099 CLOSE ShortpaidLinesCursor;
4100 end if;
4101
4102 IF (C_WF_VERSION < AP_WEB_EXPENSE_WF.C_NoMultiLineVersion) THEN
4103 l_shortpay_info_body := '';
4104 ---------------------------------------------------------
4105 l_debug_info := 'Populating line_info_body with tokens ' || to_char(l_num_lines) || '-' || to_char(l_exp_report_id);
4106 ---------------------------------------------------------
4107 FOR j in 1..l_num_lines LOOP
4108 -----------------------------------------------------
4109 l_debug_info := 'Assigning shortpay_info_body';
4110 -----------------------------------------------------
4111
4112 l_shortpay_info_body := l_shortpay_info_body || '
4113 ' || '&' || 'ADJ_LINE' || to_char(j);
4114
4115 END LOOP;
4116 ---------------------------------------------------------
4117 l_debug_info := 'Set Item Attribute Line_Info_Body1';
4118 ---------------------------------------------------------
4119 WF_ENGINE.SetItemAttrText(p_item_type,
4120 p_item_key,
4121 'LINE_INFO_BODY',
4122 l_shortpay_info_body);
4123 ELSE
4124 ---------------------------------------------------------
4125 l_debug_info := 'Set Item Attribute Line_Info_Body1';
4126 ---------------------------------------------------------
4127 -- jrautiai ADJ Fix, Need to be able to distinguish between policy violation and missing receipts notifications.
4128 WF_ENGINE.SetItemAttrText(p_item_type,
4129 p_item_key,
4130 'LINE_INFO_BODY',
4131 'plsql:AP_WEB_EXPENSE_WF.generateAdjustmentInfo/'||p_item_type||':'||p_item_key||':'||NVL(p_notification_type,'SHORTPAY'));
4132
4133 END IF;
4134
4135 IF (C_WF_Version >= C_CreditLineVersion AND
4136 C_WF_VERSION < AP_WEB_EXPENSE_WF.C_NoMultiLineVersion) THEN
4137 ---------------------------------------------------------
4138 l_debug_info := 'Set Item Attribute Credit_Line_Info_Body1';
4139 ---------------------------------------------------------
4140 WF_ENGINE.SetItemAttrText(p_item_type,
4141 p_item_key,
4142 'CREDIT_LINE_INFO_BODY',
4143 '');
4144 END IF;
4145
4146
4147 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end SetShortPaidLinesInfo');
4148
4149 EXCEPTION
4150 WHEN OTHERS THEN
4151 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'SetShortPaidLinesInfo',
4152 p_item_type, p_item_key, null, l_debug_info);
4153 raise;
4154 END SetShortPaidLinesInfo;
4155
4156 -----------------------------------------------------------------------------
4157 PROCEDURE MissingReceiptShortPay(p_item_type IN VARCHAR2,
4158 p_item_key IN VARCHAR2,
4159 p_actid IN NUMBER,
4160 p_funmode IN VARCHAR2,
4161 p_result OUT NOCOPY VARCHAR2)
4162 -----------------------------------------------------------------------------
4163 IS
4164 l_no_receipts_shortpay_id NUMBER;
4165 l_debug_info VARCHAR2(2000);
4166 l_receipt_type VARCHAR2(50);
4167 BEGIN
4168
4169 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start MissingReceiptShortPay');
4170
4171 IF (p_funmode = 'RUN') THEN
4172
4173 -- Bug 14134416: To handle 'MISSING_RECEIPT_TYPE' error for the upgraded expense reports
4174 BEGIN
4175 l_receipt_type := WF_ENGINE.GetActivityAttrText(p_item_type,
4176 p_item_key,
4177 p_actid,
4178 'MISSING_RECEIPT_TYPE');
4179 EXCEPTION
4180 WHEN OTHERS THEN
4181 if (wf_core.error_name = 'WFENG_ACTIVITY_ATTR') then
4182 l_receipt_type := 'ORIGINAL';
4183 else
4184 raise;
4185 end if;
4186 END;
4187 IF (l_receipt_type = 'ORIGINAL') THEN
4188 ------------------------------------------------------------
4189 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
4190 ------------------------------------------------------------
4191 l_no_receipts_shortpay_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
4192 p_item_key,
4193 'NO_RECEIPTS_SHORTPAY_ID');
4194 IF (l_no_receipts_shortpay_id IS NOT NULL) THEN
4195 p_result := 'COMPLETE:Y';
4196 ELSE
4197 p_result := 'COMPLETE:N';
4198 END IF;
4199 ELSIF (l_receipt_type = 'IMAGE') THEN
4200 l_no_receipts_shortpay_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
4201 p_item_key,
4202 'NO_IMG_RECEIPTS_SHORTPAY_ID');
4203 IF (l_no_receipts_shortpay_id IS NOT NULL) THEN
4204 p_result := 'COMPLETE:Y';
4205 ELSE
4206 p_result := 'COMPLETE:N';
4207 END IF;
4208 ELSIF (l_receipt_type = 'BOTH') THEN
4209 l_no_receipts_shortpay_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
4210 p_item_key,
4211 'NO_BOTH_RECEIPTS_SHORTPAY_ID');
4212 IF (l_no_receipts_shortpay_id IS NOT NULL) THEN
4213 p_result := 'COMPLETE:Y';
4214 ELSE
4215 p_result := 'COMPLETE:N';
4216 END IF;
4217 ELSE
4218 p_result := 'COMPLETE:N';
4219 END IF;
4220
4221 ELSIF (p_funmode = 'CANCEL') THEN
4222
4223 p_result := 'COMPLETE';
4224
4225 NULL;
4226
4227 END IF;
4228
4229 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end MissingReceiptShortPay');
4230
4231 EXCEPTION
4232 WHEN OTHERS THEN
4233 IF (SQLCODE <> -20001) THEN
4234 FND_MESSAGE.SET_NAME('SQLAP','AP_DEBUG');
4235 FND_MESSAGE.SET_TOKEN('ERROR',SQLERRM);
4236 FND_MESSAGE.SET_TOKEN('CALLING_SEQUENCE', 'MissingReceiptShortPay');
4237 FND_MESSAGE.SET_TOKEN('DEBUG_INFO',l_debug_info);
4238 END IF;
4239 APP_EXCEPTION.RAISE_EXCEPTION;
4240 END MissingReceiptShortPay;
4241
4242 -----------------------------------------------------------------------------
4243 PROCEDURE PolicyViolationShortPay(p_item_type IN VARCHAR2,
4244 p_item_key IN VARCHAR2,
4245 p_actid IN NUMBER,
4246 p_funmode IN VARCHAR2,
4247 p_result OUT NOCOPY VARCHAR2)
4248 -----------------------------------------------------------------------------
4249 IS
4250 l_policy_shortpay_id NUMBER;
4251 l_debug_info VARCHAR2(2000);
4252 BEGIN
4253
4254 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start PolicyViolationShortPay');
4255
4256 IF (p_funmode = 'RUN') THEN
4257
4258 ------------------------------------------------------------
4259 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
4260 ------------------------------------------------------------
4261 l_policy_shortpay_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
4262 p_item_key,
4263 'POLICY_SHORTPAY_ID');
4264 IF (l_policy_shortpay_id IS NOT NULL) THEN
4265 p_result := 'COMPLETE:Y';
4266 ELSE
4267 p_result := 'COMPLETE:N';
4268 END IF;
4269
4270 ELSIF (p_funmode = 'CANCEL') THEN
4271
4272 p_result := 'COMPLETE';
4273
4274 NULL;
4275
4276 END IF;
4277
4278 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end PolicyViolationShortPay');
4279
4280 EXCEPTION
4281 WHEN OTHERS THEN
4282 IF (SQLCODE <> -20001) THEN
4283 FND_MESSAGE.SET_NAME('SQLAP','AP_DEBUG');
4284 FND_MESSAGE.SET_TOKEN('ERROR',SQLERRM);
4285 FND_MESSAGE.SET_TOKEN('CALLING_SEQUENCE', 'PolicyViolationShortPay');
4286 FND_MESSAGE.SET_TOKEN('DEBUG_INFO',l_debug_info);
4287 END IF;
4288 APP_EXCEPTION.RAISE_EXCEPTION;
4289 END PolicyViolationShortPay;
4290
4291 -----------------------------------------------------------------------------
4292 FUNCTION GetNewShortPayDocumentNum(p_last_document_num IN VARCHAR2) RETURN VARCHAR2 IS
4293 l_new_document_number VARCHAR2(50);
4294 l_position NUMBER;
4295 l_num VARCHAR2(5);
4296 l_debug_info VARCHAR2(2000);
4297 -----------------------------------------------------------------------------
4298 BEGIN
4299
4300 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start GetNewShortPayDocumentNum');
4301
4302 -------------------------------------------------------------------
4303 l_debug_info := 'Check for _ in the document_number to determine if
4304 the expense report has been short paid before';
4305 -------------------------------------------------------------------
4306 l_position := INSTRB(p_last_document_num, '-');
4307
4308 ------------------------------------------------------------
4309 l_debug_info := 'If position is greater than 0 then expense report
4310 has been short paid, so we need to increment the number
4311 suffix at the end, otherwise the new_document_number
4312 just the old with _1 appended at the end';
4313 ------------------------------------------------------------
4314 IF (l_position > 0) THEN
4315
4316 l_num := to_char(to_number(substrb(p_last_document_num, l_position+1)) + 2);
4317
4318 l_new_document_number := substrb(p_last_document_num,1,l_position) || l_num;
4319 ELSE
4320 l_new_document_number := p_last_document_num || '-1';
4321 END IF;
4322
4323 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end GetNewShortPayDocumentNum');
4324
4325 return(l_new_document_number);
4326
4327 END GetNewShortPayDocumentNum;
4328
4329 ------------------------------------------------------------------------------
4330 PROCEDURE CreateShortPayExpReport(p_orig_expense_report_id IN AP_WEB_DB_EXPRPT_PKG.expHdr_headerID,
4331 p_new_expense_report_id IN AP_WEB_DB_EXPRPT_PKG.expHdr_headerID,
4332 p_new_expense_report_num IN AP_WEB_DB_EXPRPT_PKG.expHdr_invNum,
4333 p_new_expense_report_total IN AP_WEB_DB_EXPRPT_PKG.expHdr_total,
4334 p_new_ccard_amt IN AP_WEB_DB_EXPRPT_PKG.expHdr_amtDueCcardCompany,
4335 p_new_emp_amt IN AP_WEB_DB_EXPRPT_PKG.expHdr_amtDueEmployee,
4336 p_shortpay_type IN VARCHAR2)
4337 ------------------------------------------------------------------------------
4338 IS
4339 l_debug_info VARCHAR2(2000);
4340 l_ExpenseRec AP_WEB_DB_EXPRPT_PKG.XpenseInfoRec;
4341 l_receipts_status AP_EXPENSE_REPORT_HEADERS.receipts_status%TYPE;
4342 l_received_date AP_EXPENSE_REPORT_HEADERS.receipts_received_date%TYPE;
4343 l_img_receipts_status AP_EXPENSE_REPORT_HEADERS.image_receipts_status%TYPE;
4344 l_img_received_date AP_EXPENSE_REPORT_HEADERS.image_receipts_received_date%TYPE;
4345
4346 BEGIN
4347
4348 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start CreateShortPayExpReport');
4349
4350 -------------------------------------------------------------------
4351 l_debug_info := 'Create new expense report by creating new record in
4352 ap_expense_report_headers, with same info as old
4353 expense report except new id, number and total';
4354 --------------------------------------------------------------------
4355 l_ExpenseRec.report_header_id := p_new_expense_report_id;
4356 l_ExpenseRec.employee_id := NULL;
4357 l_ExpenseRec.preparer_id := NULL;
4358 l_ExpenseRec.last_updated_by := NULL;
4359 l_ExpenseRec.vouchno := 0;
4360 l_ExpenseRec.total := p_new_expense_report_total;
4361 l_ExpenseRec.vendor_id := NULL;
4362 l_ExpenseRec.vendor_site_id := NULL;
4363 l_ExpenseRec.expense_check_address_flag := NULL;
4364 l_ExpenseRec.document_number := p_new_expense_report_num;
4365 l_ExpenseRec.last_update_login := NULL;
4366 l_ExpenseRec.org_id := NULL;
4367 l_ExpenseRec.workflow_flag := p_shortpay_type;
4368 l_ExpenseRec.amt_due_employee := p_new_emp_amt;
4369 l_ExpenseRec.amt_due_ccard := NVL(p_new_ccard_amt,0);
4370 l_ExpenseRec.description := NULL;
4371 l_ExpenseRec.bothpay_report_header_id := NULL;
4372 l_ExpenseRec.shortpay_parent_id := p_orig_expense_report_id;
4373 l_ExpenseRec.behalf_employee_id := NULL;
4374 l_ExpenseRec.approver_id := NULL;
4375 l_ExpenseRec.week_end_date := NULL;
4376 l_ExpenseRec.set_of_books_id := NULL;
4377 l_ExpenseRec.source := NULL;
4378 l_ExpenseRec.accts_pay_comb_id := NULL;
4379 l_ExpenseRec.expense_status_code := NULL;
4380 l_ExpenseRec.receipts_status := NULL;
4381 l_ExpenseRec.receipts_received_date := NULL;
4382 l_ExpenseRec.image_receipts_status := NULL;
4383 l_ExpenseRec.image_receipts_received_date := NULL;
4384
4385 SELECT receipts_status, receipts_received_date, image_receipts_status, image_receipts_received_date
4386 INTO l_receipts_status, l_received_date, l_img_receipts_status, l_img_received_date
4387 FROM ap_expense_report_headers WHERE report_header_id = p_orig_expense_report_id;
4388
4389 IF (p_shortpay_type = 'NO_RECEIPTS') THEN
4390 l_ExpenseRec.receipts_status := NULL;
4391 l_ExpenseRec.receipts_received_date := NULL;
4392 l_ExpenseRec.image_receipts_status := l_img_receipts_status;
4393 l_ExpenseRec.image_receipts_received_date := l_img_received_date;
4394 ELSIF (p_shortpay_type = 'NO_IMAGE_RECEIPTS') THEN
4395 l_ExpenseRec.receipts_status := l_receipts_status;
4396 l_ExpenseRec.receipts_received_date := l_received_date;
4397 l_ExpenseRec.image_receipts_status := NULL;
4398 l_ExpenseRec.image_receipts_received_date := NULL;
4399 ELSIF (p_shortpay_type = 'POLICY') THEN
4400 l_ExpenseRec.receipts_status := l_receipts_status;
4401 l_ExpenseRec.receipts_received_date := l_received_date;
4402 l_ExpenseRec.image_receipts_status := l_img_receipts_status;
4403 l_ExpenseRec.image_receipts_received_date := l_img_received_date;
4404 END IF;
4405
4406 IF (NOT AP_WEB_DB_EXPRPT_PKG.InsertReportHeaderLikeExisting(
4407 p_orig_expense_report_id, l_ExpenseRec)) THEN
4408 NULL;
4409 END IF;
4410
4411 /*Bug#8976900 - Add Reference for attachments from parent expense report
4412 to the short-paid expense report*/
4413 --------------------------------------------------------------------
4414 l_debug_info := 'Creating reference for Header Attachments';
4415 --------------------------------------------------------------------
4416
4417 AP_WEB_DB_EXPRPT_PKG.CopyAttachments(p_orig_expense_report_id,
4418 p_new_expense_report_id,
4419 'OIE_HEADER_ATTACHMENTS');
4420
4421 IF (p_shortpay_type = 'POLICY') THEN
4422 --------------------------------------------------------------------
4423 l_debug_info := 'Insert the lines that cannot be paid into
4424 ap_expense_report_lines with new report_header_id';
4425 --------------------------------------------------------------------
4426
4427 IF (AP_WEB_DB_EXPLINE_PKG.AddPolicyShortPaidExpLines(p_new_expense_report_id, p_orig_expense_report_id)) THEN
4428 NULL;
4429 END IF;
4430
4431 --------------------------------------------------------------------
4432 l_debug_info := 'Set the report header id of the CC charges that
4433 are attached to the shortpaid report due to policy
4434 violation with the new expense report id';
4435 --------------------------------------------------------------------
4436 IF (NOT AP_WEB_DB_CCARD_PKG.SetCCPolicyShortpaidReportID(p_orig_expense_report_id, p_new_expense_report_id)) THEN
4437 NULL;
4438 END IF;
4439
4440 --------------------------------------------------------------------
4441 l_debug_info := 'Update the report header id in the violations table
4442 with the new expense report id';
4443 --------------------------------------------------------------------
4444 AP_WEB_DB_VIOLATIONS_PKG.SetVioPolicyShortpaidReportID(
4445 p_orig_expense_report_id => p_orig_expense_report_id,
4446 p_new_report_header_id => p_new_expense_report_id);
4447 ELSE
4448
4449 --------------------------------------------------------------------
4450 l_debug_info := 'Insert the lines that cannot be paid into
4451 ap_expense_report_lines with new report_header_id for
4452 missing receipts shortpay';
4453 --------------------------------------------------------------------
4454
4455 IF (p_shortpay_type = 'NO_RECEIPTS') THEN
4456 IF (AP_WEB_DB_EXPLINE_PKG.AddUnverifiedShortpaidLines(
4457 p_new_expense_report_id, p_orig_expense_report_id)) THEN
4458 NULL;
4459 END IF;
4460 ELSIF (p_shortpay_type = 'NO_IMAGE_RECEIPTS') THEN
4461 IF (AP_WEB_DB_EXPLINE_PKG.AddUnverifiedImgShortpaidLines(
4462 p_new_expense_report_id, p_orig_expense_report_id)) THEN
4463 NULL;
4464 END IF;
4465 ELSE
4466 IF (AP_WEB_DB_EXPLINE_PKG.AddUnverifiedBtShortpaidLines(
4467 p_new_expense_report_id, p_orig_expense_report_id)) THEN
4468 NULL;
4469 END IF;
4470 END IF;
4471
4472
4473 --------------------------------------------------------------------
4474 l_debug_info := 'Set the report header id of the CC charges that
4475 are attached to the shortpaid report due to missing
4476 receipts with the new expense report id';
4477 --------------------------------------------------------------------
4478 IF (NOT AP_WEB_DB_CCARD_PKG.SetCCReceiptShortpaidReportID(
4479 p_orig_expense_report_id, p_new_expense_report_id)) THEN
4480 NULL;
4481 END IF;
4482
4483 --------------------------------------------------------------------
4484 l_debug_info := 'Update the report header id in the violations table
4485 with the new expense report id';
4486 --------------------------------------------------------------------
4487 AP_WEB_DB_VIOLATIONS_PKG.SetVioReceiptShortpaidReportID(
4488 p_orig_expense_report_id => p_orig_expense_report_id,
4489 p_new_report_header_id => p_new_expense_report_id);
4490
4491
4492 END IF;
4493
4494 --------------------------------------------------------------------
4495 l_debug_info := 'Copy Notes from original report';
4496 --------------------------------------------------------------------
4497 AP_WEB_NOTES_PKG.CopyERNotes (
4498 p_src_report_header_id => p_orig_expense_report_id,
4499 p_tgt_report_header_id => p_new_expense_report_id
4500 );
4501
4502
4503 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end CreateShortPayExpReport');
4504
4505 EXCEPTION
4506 WHEN OTHERS THEN
4507 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'CreateShortPayExpReport',
4508 null, to_char(p_orig_expense_report_id), null, l_debug_info);
4509 raise;
4510 END CreateShortPayExpReport;
4511
4512
4513
4514 ----------------------------------------------------------------------
4515 PROCEDURE SplitExpenseReport(p_item_type IN VARCHAR2,
4516 p_item_key IN VARCHAR2,
4517 p_actid IN NUMBER,
4518 p_funmode IN VARCHAR2,
4519 p_result OUT NOCOPY VARCHAR2) IS
4520 ----------------------------------------------------------------------
4521 l_report_header_id AP_WEB_DB_EXPRPT_PKG.expHdr_headerID;
4522 l_num_req_receipt_not_verified NUMBER;
4523 l_policy_shortpay_total AP_WEB_DB_EXPRPT_PKG.expHdr_total;
4524 l_no_receipts_shortpay_total AP_WEB_DB_EXPRPT_PKG.expHdr_total;
4525 l_policy_shortpay_id AP_WEB_DB_EXPRPT_PKG.expHdr_headerID;
4526 l_no_receipts_shortpay_id AP_WEB_DB_EXPRPT_PKG.expHdr_headerID;
4527 l_no_img_receipts_shortpay_id AP_WEB_DB_EXPRPT_PKG.expHdr_headerID;
4528 l_no_both_receipts_shortpay_id AP_WEB_DB_EXPRPT_PKG.expHdr_headerID;
4529 l_policy_shortpay_doc_num AP_WEB_DB_EXPRPT_PKG.expHdr_invNum;
4530 l_no_receipts_shortpay_doc_num AP_WEB_DB_EXPRPT_PKG.expHdr_invNum;
4531 l_document_number AP_WEB_DB_EXPRPT_PKG.expHdr_invNum;
4532 l_payment_due VARCHAR2(10) := C_IndividualPay;
4533 l_count NUMBER;
4534 l_personal_total NUMBER := 0;
4535 l_policy_ccard_amt AP_WEB_DB_EXPRPT_PKG.expHdr_amtDueCcardCompany;
4536 l_no_receipts_ccard_amt AP_WEB_DB_EXPRPT_PKG.expHdr_amtDueCcardCompany;
4537 l_policy_emp_amt AP_WEB_DB_EXPRPT_PKG.expHdr_amtDueEmployee;
4538 l_no_receipts_emp_amt AP_WEB_DB_EXPRPT_PKG.expHdr_amtDueEmployee;
4539 l_ccard_amt AP_WEB_DB_EXPRPT_PKG.expHdr_amtDueCcardCompany;
4540 l_emp_amt AP_WEB_DB_EXPRPT_PKG.expHdr_amtDueEmployee;
4541 l_currency VARCHAR2(50);
4542 l_debug_info VARCHAR2(500);
4543 l_audit_tag VARCHAR2(80);
4544
4545 l_no_data_found_flag1 BOOLEAN := TRUE;
4546 l_no_data_found_flag2 BOOLEAN := TRUE;
4547 l_amtDueCCardCompany AP_WEB_DB_EXPRPT_PKG.expHdr_amtDueCcardCompany;
4548 l_amtDueEmp AP_WEB_DB_EXPRPT_PKG.expHdr_amtDueEmployee;
4549
4550 /* jrautiai ADJ Fix - Start */
4551 l_total NUMBER := 0;
4552 l_policy_count NUMBER := 0;
4553 l_image_count NUMBER := 0;
4554 l_both_count NUMBER := 0;
4555 l_shortpaid_count NUMBER := 0;
4556 l_missing_receipt_count NUMBER := 0;
4557 /* jrautiai ADJ Fix - End */
4558 l_shortpay_suffix VARCHAR2(3) := '-1';
4559 BEGIN
4560
4561 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start SplitExpenseReport');
4562
4563 IF (p_funmode = 'RUN') THEN
4564
4565 ------------------------------------------------------------
4566 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
4567 ------------------------------------------------------------
4568 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
4569 p_item_key,
4570 'EXPENSE_REPORT_ID');
4571
4572 ------------------------------------------------------------
4573 l_debug_info := 'Retrieve Document Number Item Attribute';
4574 ------------------------------------------------------------
4575 l_document_number := WF_ENGINE.GetItemAttrText(p_item_type,
4576 p_item_key,
4577 'DOCUMENT_NUMBER');
4578
4579 -----------------------------------------------------
4580 l_debug_info := 'Retrieve Currency Item Attribute';
4581 -----------------------------------------------------
4582 l_currency := WF_ENGINE.GetItemAttrText(p_item_type,
4583 p_item_key,
4584 'CURRENCY');
4585
4586
4587 l_payment_due := WF_ENGINE.GetItemAttrText(p_item_type,p_item_key,'PAYMENT_DUE_FROM');
4588
4589 /* jrautiai ADJ Fix Start */
4590 -----------------------------------------------------------------
4591 l_debug_info := 'Get number of lines not adhereing to policies.';
4592 ------------------------------------------------------------------
4593 IF (NOT AP_WEB_DB_EXPLINE_PKG.GetNumShortpaidLines(l_report_header_id, l_shortpaid_count)) THEN
4594 l_shortpaid_count := 0;
4595 END IF;
4596
4597 -----------------------------------------------------------------
4598 l_debug_info := 'Get number of lines with policy shortpay.';
4599 ------------------------------------------------------------------
4600 IF (NOT AP_WEB_DB_EXPLINE_PKG.GetNumPolicyShortpaidLines(l_report_header_id, l_policy_count)) THEN
4601 l_policy_count := 0;
4602 END IF;
4603 /* A line can contain both scenarios, missing receipt and policy violation flag. In that case
4604 * the line is moved to the '-1' report created for the policy violation flag. The variable
4605 * l_shortpaid_count contains the number of lines with either missing receipts and / or with
4606 * policy violation flag. The variable l_policy_count contains lines with only the policy
4607 * violation flag. So the number of lines to be moved to the new missing receipt report
4608 * can be calculated with 'l_shortpaid_count - l_policy_count'. We are not using the function
4609 * AP_WEB_DB_EXPLINE_PKG.GetNumReceiptShortpaidLines
4610 * since that will return all the lines with missing receipts, including ones with also policy
4611 * shortpay flag set to Y, which will not be moved to the missing receipts report.
4612 */
4613 IF (NOT AP_WEB_DB_EXPLINE_PKG.GetNumImageShortpaidLines(l_report_header_id, l_image_count)) THEN
4614 l_image_count := 0;
4615 END IF;
4616
4617 IF (NOT AP_WEB_DB_EXPLINE_PKG.GetNumBothShortpaidLines(l_report_header_id, l_both_count)) THEN
4618 l_both_count := 0;
4619 END IF;
4620
4621 --l_missing_receipt_count := l_shortpaid_count - l_policy_count - l_image_count - l_both_count;
4622 IF (NOT AP_WEB_DB_EXPLINE_PKG.GetNumOriginalShortpaidLines(l_report_header_id, l_missing_receipt_count)) THEN
4623 l_missing_receipt_count := 0;
4624 END IF;
4625
4626 IF (l_policy_count > 0) THEN
4627 /* jrautiai ADJ Fix end */
4628
4629 -----------------------------------------------------------------
4630 l_debug_info := 'Retrieve Policy ShortPay New Expense Report Id';
4631 -----------------------------------------------------------------
4632 IF (NOT AP_WEB_DB_EXPRPT_PKG.GetNextExpReportID(l_policy_shortpay_id)) THEN
4633 NULL;
4634 END IF;
4635
4636 l_policy_shortpay_doc_num := l_document_number || '-1';
4637 l_shortpay_suffix := '-2';
4638
4639 /* jrautiai ADJ Fix
4640 * Not passing in amounts, they are calculated after the shortpaid report has been created.
4641 * This is because in company pay scenario the personal lines are moved with all the other
4642 * lines using the transaction. If the amounts are calculated prior to creating the report
4643 * and several personal lines exists on the original report the totals incorrectly reflect
4644 * all the personal amounts. */
4645 CreateShortpayExpReport(l_report_header_id,
4646 l_policy_shortpay_id,
4647 l_policy_shortpay_doc_num,
4648 0, --l_policy_shortpay_total,
4649 0, --l_policy_ccard_amt,
4650 0, --l_policy_emp_amt,
4651 'POLICY');
4652
4653 /* jrautiai ADJ Fix Start
4654 * recalculate the shortpaid totals after it has been created*/
4655 IF (NOT AP_WEB_DB_EXPLINE_PKG.CalculateAmtsDue(l_policy_shortpay_id,
4656 l_payment_due,
4657 l_policy_emp_amt,
4658 l_policy_ccard_amt,
4659 l_policy_shortpay_total)) THEN
4660 l_policy_emp_amt:=0;
4661 l_policy_ccard_amt:=0;
4662 l_policy_shortpay_total := 0;
4663 END IF;
4664 IF (NOT AP_WEB_DB_EXPRPT_PKG.SetAmtDuesAndTotal(l_policy_shortpay_id,
4665 l_policy_ccard_amt,
4666 l_policy_emp_amt,
4667 l_policy_shortpay_total)) THEN
4668 NULL;
4669 END IF;
4670 /* jrautiai ADJ Fix End */
4671
4672 ------------------------------------------------------------
4673 l_debug_info := 'Set the New_Expense_Report_ID Item Attribute';
4674 ------------------------------------------------------------
4675 WF_ENGINE.SetItemAttrNumber(p_item_type,
4676 p_item_key,
4677 'POLICY_SHORTPAY_ID',
4678 l_policy_shortpay_id);
4679
4680 WF_ENGINE.SetItemAttrText(p_item_type,
4681 p_item_key,
4682 'POLICY_SHORTPAY_DOC_NUM',
4683 l_policy_shortpay_doc_num);
4684
4685 WF_ENGINE.SetItemAttrNumber(p_item_type,
4686 p_item_key,
4687 'POLICY_SHORTPAY_TOTAL',
4688 l_policy_shortpay_total);
4689
4690
4691 END IF;
4692
4693 IF (l_missing_receipt_count > 0) THEN
4694 -----------------------------------------------------------------
4695 l_debug_info := 'Retrieve Policy ShortPay New Expense Report Id';
4696 -----------------------------------------------------------------
4697 IF (NOT AP_WEB_DB_EXPRPT_PKG.GetNextExpReportID(l_no_receipts_shortpay_id)) THEN
4698 l_no_receipts_shortpay_id := NULL;
4699 END IF;
4700
4701 IF (l_policy_count > 0) THEN
4702 l_no_receipts_shortpay_doc_num := l_document_number || '-2';
4703 l_shortpay_suffix := '-3';
4704 ELSE
4705 l_no_receipts_shortpay_doc_num := l_document_number || '-1';
4706 l_shortpay_suffix := '-2';
4707 END IF;
4708
4709 /* jrautiai ADJ Fix
4710 * Not passing in amounts, they are calculated after the shortpaid report has been created.
4711 * This is because in company pay scenario the personal lines are moved with all the other
4712 * lines using the transaction. If the amounts are calculated prior to creating the report
4713 * and several personal lines exists on the original report the totals incorrectly reflect
4714 * all the personal amounts. */
4715 CreateShortpayExpReport(l_report_header_id,
4716 l_no_receipts_shortpay_id,
4717 l_no_receipts_shortpay_doc_num,
4718 0,
4719 0,
4720 0,
4721 'NO_RECEIPTS');
4722
4723 /* jrautiai ADJ Fix Start
4724 * recalculate the shortpaid totals after it has been created*/
4725 IF (NOT AP_WEB_DB_EXPLINE_PKG.CalculateAmtsDue(l_no_receipts_shortpay_id,
4726 l_payment_due,
4727 l_no_receipts_emp_amt,
4728 l_no_receipts_ccard_amt,
4729 l_no_receipts_shortpay_total)) THEN
4730 l_no_receipts_emp_amt:=0;
4731 l_no_receipts_ccard_amt:=0;
4732 l_no_receipts_shortpay_total := 0;
4733 END IF;
4734 IF (NOT AP_WEB_DB_EXPRPT_PKG.SetAmtDuesAndTotal(l_no_receipts_shortpay_id,
4735 l_no_receipts_ccard_amt,
4736 l_no_receipts_emp_amt,
4737 l_no_receipts_shortpay_total)) THEN
4738 NULL;
4739 END IF;
4740 /* jrautiai ADJ Fix End */
4741
4742 WF_ENGINE.SetItemAttrNumber(p_item_type,
4743 p_item_key,
4744 'NO_RECEIPTS_SHORTPAY_ID',
4745 l_no_receipts_shortpay_id);
4746
4747 WF_ENGINE.SetItemAttrText(p_item_type,
4748 p_item_key,
4749 'NO_RECEIPTS_SHORTPAY_DOC_NUM',
4750 l_no_receipts_shortpay_doc_num);
4751
4752 WF_ENGINE.SetItemAttrNumber(p_item_type,
4753 p_item_key,
4754 'NO_RECEIPTS_SHORTPAY_TOTAL',
4755 l_no_receipts_shortpay_total);
4756
4757 END IF;
4758
4759 IF (l_image_count > 0) THEN
4760 -----------------------------------------------------------------
4761 l_debug_info := 'Retrieve Policy ShortPay New Expense Report Id';
4762 -----------------------------------------------------------------
4763 IF (NOT AP_WEB_DB_EXPRPT_PKG.GetNextExpReportID(l_no_img_receipts_shortpay_id)) THEN
4764 l_no_img_receipts_shortpay_id := NULL;
4765 END IF;
4766
4767 IF (l_policy_count > 0 AND l_missing_receipt_count > 0) THEN
4768 l_no_receipts_shortpay_doc_num := l_document_number || '-3';
4769 l_shortpay_suffix := '-4';
4770 ELSIF (l_policy_count > 0 OR l_missing_receipt_count > 0) THEN
4771 l_no_receipts_shortpay_doc_num := l_document_number || '-2';
4772 l_shortpay_suffix := '-3';
4773 ELSE
4774 l_no_receipts_shortpay_doc_num := l_document_number || '-1';
4775 l_shortpay_suffix := '-2';
4776 END IF;
4777
4778
4779 /* jrautiai ADJ Fix
4780 * Not passing in amounts, they are calculated after the shortpaid report has been created.
4781 * This is because in company pay scenario the personal lines are moved with all the other
4782 * lines using the transaction. If the amounts are calculated prior to creating the report
4783 * and several personal lines exists on the original report the totals incorrectly reflect
4784 * all the personal amounts. */
4785
4786 CreateShortpayExpReport(l_report_header_id,
4787 l_no_img_receipts_shortpay_id,
4788 l_no_receipts_shortpay_doc_num,
4789 0,
4790 0,
4791 0,
4792 'NO_IMAGE_RECEIPTS');
4793
4794 /* jrautiai ADJ Fix Start
4795 * recalculate the shortpaid totals after it has been created*/
4796 IF (NOT AP_WEB_DB_EXPLINE_PKG.CalculateAmtsDue(l_no_img_receipts_shortpay_id,
4797 l_payment_due,
4798 l_no_receipts_emp_amt,
4799 l_no_receipts_ccard_amt,
4800 l_no_receipts_shortpay_total)) THEN
4801 l_no_receipts_emp_amt:=0;
4802 l_no_receipts_ccard_amt:=0;
4803 l_no_receipts_shortpay_total := 0;
4804 END IF;
4805 IF (NOT AP_WEB_DB_EXPRPT_PKG.SetAmtDuesAndTotal(l_no_img_receipts_shortpay_id,
4806 l_no_receipts_ccard_amt,
4807 l_no_receipts_emp_amt,
4808 l_no_receipts_shortpay_total)) THEN
4809 NULL;
4810 END IF;
4811 /* jrautiai ADJ Fix End */
4812
4813 WF_ENGINE.SetItemAttrNumber(p_item_type,
4814 p_item_key,
4815 'NO_IMG_RECEIPTS_SHORTPAY_ID',
4816 l_no_img_receipts_shortpay_id);
4817
4818 WF_ENGINE.SetItemAttrText(p_item_type,
4819 p_item_key,
4820 'NO_IMG_RECPT_SHORTPAY_DOC_NUM',
4821 l_no_receipts_shortpay_doc_num);
4822
4823 WF_ENGINE.SetItemAttrNumber(p_item_type,
4824 p_item_key,
4825 'NO_IMG_RECPT_SHORTPAY_TOTAL',
4826 l_no_receipts_shortpay_total);
4827
4828 END IF;
4829
4830 IF (l_both_count > 0) THEN
4831 -----------------------------------------------------------------
4832 l_debug_info := 'Retrieve Policy ShortPay New Expense Report Id';
4833 -----------------------------------------------------------------
4834 IF (NOT AP_WEB_DB_EXPRPT_PKG.GetNextExpReportID(l_no_both_receipts_shortpay_id)) THEN
4835 l_no_img_receipts_shortpay_id := NULL;
4836 END IF;
4837
4838
4839 l_no_receipts_shortpay_doc_num := l_document_number || l_shortpay_suffix;
4840
4841 /* jrautiai ADJ Fix
4842 * Not passing in amounts, they are calculated after the shortpaid report has been created.
4843 * This is because in company pay scenario the personal lines are moved with all the other
4844 * lines using the transaction. If the amounts are calculated prior to creating the report
4845 * and several personal lines exists on the original report the totals incorrectly reflect
4846 * all the personal amounts. */
4847
4848 CreateShortpayExpReport(l_report_header_id,
4849 l_no_both_receipts_shortpay_id,
4850 l_no_receipts_shortpay_doc_num,
4851 0,
4852 0,
4853 0,
4854 'NO_BOTH_RECEIPTS');
4855
4856 /* jrautiai ADJ Fix Start
4857 * recalculate the shortpaid totals after it has been created*/
4858 IF (NOT AP_WEB_DB_EXPLINE_PKG.CalculateAmtsDue(l_no_both_receipts_shortpay_id,
4859 l_payment_due,
4860 l_no_receipts_emp_amt,
4861 l_no_receipts_ccard_amt,
4862 l_no_receipts_shortpay_total)) THEN
4863 l_no_receipts_emp_amt:=0;
4864 l_no_receipts_ccard_amt:=0;
4865 l_no_receipts_shortpay_total := 0;
4866 END IF;
4867 IF (NOT AP_WEB_DB_EXPRPT_PKG.SetAmtDuesAndTotal(l_no_both_receipts_shortpay_id,
4868 l_no_receipts_ccard_amt,
4869 l_no_receipts_emp_amt,
4870 l_no_receipts_shortpay_total)) THEN
4871 NULL;
4872 END IF;
4873 /* jrautiai ADJ Fix End */
4874
4875 WF_ENGINE.SetItemAttrNumber(p_item_type,
4876 p_item_key,
4877 'NO_BOTH_RECEIPTS_SHORTPAY_ID',
4878 l_no_both_receipts_shortpay_id);
4879
4880 WF_ENGINE.SetItemAttrText(p_item_type,
4881 p_item_key,
4882 'NO_BOTH_RECPT_SHORTPAY_DOC_NUM',
4883 l_no_receipts_shortpay_doc_num);
4884
4885 WF_ENGINE.SetItemAttrNumber(p_item_type,
4886 p_item_key,
4887 'NO_BOTH_RECPT_SHORTPAY_TOTAL',
4888 l_no_receipts_shortpay_total);
4889
4890 END IF;
4891
4892
4893 -----------------------------------------------------------------------
4894 l_debug_info := 'Handle the receipts management event MR '||to_char(l_no_receipts_shortpay_id);
4895 -----------------------------------------------------------------------
4896 -- Bug# 10385358: To insert the audit reasons for the shortpaid expense report
4897 IF l_no_receipts_shortpay_id IS NOT NULL THEN
4898 AP_WEB_RECEIPT_MANAGEMENT_UTIL.handle_event(l_no_receipts_shortpay_id,AP_WEB_RECEIPT_MANAGEMENT_UTIL.C_EVENT_MR_SHORTPAY);
4899 l_audit_tag := AP_WEB_AUDIT_PROCESS.process_expense_report (l_no_receipts_shortpay_id);
4900 END IF;
4901
4902 IF l_no_img_receipts_shortpay_id IS NOT NULL THEN
4903 AP_WEB_RECEIPT_MANAGEMENT_UTIL.handle_event(l_no_img_receipts_shortpay_id,AP_WEB_RECEIPT_MANAGEMENT_UTIL.C_EVENT_MIR_SHORTPAY);
4904 l_audit_tag := AP_WEB_AUDIT_PROCESS.process_expense_report (l_no_img_receipts_shortpay_id);
4905 END IF;
4906
4907 IF l_no_both_receipts_shortpay_id IS NOT NULL THEN
4908 AP_WEB_RECEIPT_MANAGEMENT_UTIL.handle_event(l_no_both_receipts_shortpay_id,AP_WEB_RECEIPT_MANAGEMENT_UTIL.C_EVENT_MBR_SHORTPAY);
4909 l_audit_tag := AP_WEB_AUDIT_PROCESS.process_expense_report (l_no_both_receipts_shortpay_id);
4910 END IF;
4911
4912 -----------------------------------------------------------------------
4913 l_debug_info := 'Handle the receipts management event PV'||to_char(l_policy_shortpay_id);
4914 -----------------------------------------------------------------------
4915 IF l_policy_shortpay_id IS NOT NULL THEN
4916 AP_WEB_RECEIPT_MANAGEMENT_UTIL.handle_event(l_policy_shortpay_id,AP_WEB_RECEIPT_MANAGEMENT_UTIL.C_EVENT_PV_SHORTPAY);
4917 l_audit_tag := AP_WEB_AUDIT_PROCESS.process_expense_report (l_policy_shortpay_id);
4918 END IF;
4919
4920 -----------------------------------------------------------------------
4921 l_debug_info := 'Handle the receipts management event original';
4922 -----------------------------------------------------------------------
4923 AP_WEB_RECEIPT_MANAGEMENT_UTIL.handle_event(l_report_header_id,AP_WEB_RECEIPT_MANAGEMENT_UTIL.C_EVENT_SHORTPAY);
4924
4925 -----------------------------------------------------------------------
4926 l_debug_info := 'Count the lines remaining in the original expense
4927 report';
4928 -----------------------------------------------------------------------
4929 IF (NOT AP_WEB_DB_EXPLINE_PKG.GetNumberOfExpLines(l_report_header_id,l_count) OR l_count = 0) THEN
4930 -----------------------------------------
4931 l_debug_info := 'Delete the original expense report if everything
4932 is getting shortpaid';
4933 ----------------------------------------------------------------------
4934 IF (NOT AP_WEB_DB_EXPRPT_PKG.DeleteExpenseReport(l_report_header_id)) THEN
4935 NULL;
4936 END IF;
4937
4938 ELSE
4939
4940 ----------------------------------------------------------------------
4941 l_debug_info := 'Update the total of the original expense report
4942 to not include the amount of the new expense report';
4943 ----------------------------------------------------------------------
4944 /* jrautiai ADJ Fix Start */
4945 IF (NOT AP_WEB_DB_EXPLINE_PKG.CalculateAmtsDue(l_report_header_id,
4946 l_payment_due,
4947 l_amtDueEmp,
4948 l_amtDueCCardCompany,
4949 l_total)) THEN
4950 l_amtDueEmp:=0;
4951 l_amtDueCCardCompany:=0;
4952 l_total := 0;
4953 END IF;
4954
4955 IF (NOT AP_WEB_DB_EXPRPT_PKG.SetAmtDuesAndTotal(l_report_header_id,
4956 l_amtDueCCardCompany,
4957 l_amtDueEmp,
4958 l_total)) THEN
4959 /* jrautiai ADJ Fix End */
4960 NULL;
4961 END IF;
4962
4963 END IF;
4964
4965 ELSIF (p_funmode = 'CANCEL') THEN
4966
4967 p_result := 'COMPLETE';
4968
4969 END IF;
4970
4971 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end SplitExpenseReport');
4972
4973 EXCEPTION
4974 WHEN OTHERS THEN
4975 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'SplitExpenseReport',
4976 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
4977 raise;
4978 END SplitExpenseReport;
4979
4980
4981
4982 PROCEDURE DeleteExpReportFromAPTables(p_report_header_id IN AP_WEB_DB_EXPRPT_PKG.expHdr_headerID) IS
4983 l_debug_info VARCHAR2(200);
4984 l_payment_due VARCHAR2(10) := C_IndividualPay;
4985 l_item_type VARCHAR2(100) := 'APEXP';
4986 l_item_key VARCHAR2(100) := to_char(p_report_header_id);
4987
4988 BEGIN
4989
4990 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start DeleteExpReportFromAPTables');
4991
4992 ----------------------------------------------------------------
4993 l_debug_info := 'Retrive the Payment Due From Profile Option';
4994 ----------------------------------------------------------------
4995 l_payment_due := WF_ENGINE.GetItemAttrText(l_item_type,
4996 l_item_key,'PAYMENT_DUE_FROM');
4997
4998 ---------------------------------------------------------------------
4999 l_debug_info := 'Update manager rejected/returned credit card transactions that
5000 are deleted after a timeout';
5001 ---------------------------------------------------------------------
5002 IF (l_payment_due = C_BothPay OR l_payment_due = C_CompanyPay) THEN
5003 IF (NOT AP_WEB_DB_CCARD_PKG.ResetCCMgrRejectedCCLines(p_report_header_id)) THEN
5004 NULL;
5005 END IF;
5006 END IF;
5007
5008
5009
5010 ---------------------------------------------------------------------------
5011 l_debug_info := 'Update shortpaid credit card transactions';
5012 ---------------------------------------------------------------------------
5013 IF (NOT AP_WEB_DB_CCARD_PKG.ResetCCLines(p_report_header_id)) THEN
5014 NULL;
5015 END IF;
5016
5017 ---------------------------------------------------------------------------
5018 l_debug_info := 'Delete the expense lines for the given expense report id';
5019 ---------------------------------------------------------------------------
5020 IF (NOT AP_WEB_DB_EXPLINE_PKG.DeleteReportLines(p_report_header_id)) THEN
5021 NULL;
5022 END IF;
5023
5024 ----------------------------------------------------
5025 l_debug_info := 'Delete the expense report header';
5026 ----------------------------------------------------
5027 IF (NOT AP_WEB_DB_EXPRPT_PKG.DeleteExpenseReport(p_report_header_id)) THEN
5028 NULL;
5029 END IF;
5030
5031 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end DeleteExpReportFromAPTables');
5032
5033 EXCEPTION
5034 WHEN OTHERS THEN
5035 IF (SQLCODE <> -20001) THEN
5036 FND_MESSAGE.SET_NAME('SQLAP','AP_DEBUG');
5037 FND_MESSAGE.SET_TOKEN('ERROR',SQLERRM);
5038 FND_MESSAGE.SET_TOKEN('CALLING_SEQUENCE', 'DeleteExpReportFromAPTables');
5039 FND_MESSAGE.SET_TOKEN('DEBUG_INFO',l_debug_info);
5040 END IF;
5041 APP_EXCEPTION.RAISE_EXCEPTION;
5042 END DeleteExpReportFromAPTables;
5043
5044 ---------------------------------------------------
5045 PROCEDURE ResetAttrValues(p_item_type IN VARCHAR2,
5046 p_item_key IN VARCHAR2,
5047 p_actid IN NUMBER) IS
5048 ---------------------------------------------------
5049 --
5050 -- Reset the attribute values which are not set explicitly by
5051 -- StartExpenseReportProcess before the rejected/returned report is resubmitted.
5052 -- We need to clear these because we will be revisiting nodes in the process.
5053 --
5054
5055 I NUMBER;
5056 l_debug_info VARCHAR2(200);
5057 C_WF_VERSION NUMBER := 0;
5058 -- Bug 668037
5059 l_override_approver_id AP_WEB_DB_EXPRPT_PKG.expHdr_overrideApprID;
5060
5061 BEGIN
5062
5063 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start ResetAttrValues');
5064
5065 C_WF_VERSION := GetFlowVersion(p_item_type, p_item_key);
5066 IF (C_WF_VERSION < AP_WEB_EXPENSE_WF.C_NoMultiLineVersion) THEN
5067 -----------------------------------------------------
5068 l_debug_info := 'Unset Adjustment Line Item Attribute';
5069 -----------------------------------------------------
5070 FOR I IN 1..C_NUM_ADJ_LINE_ATTRS LOOP
5071
5072 WF_ENGINE.SetItemAttrText(p_item_type,
5073 p_item_key,
5074 'ADJ_LINE' || to_char(I),
5075 '');
5076
5077 END LOOP;
5078 ELSE
5079 WF_ENGINE.SetItemAttrText(p_item_type,
5080 p_item_key,
5081 'LINE_INFO_BODY',
5082 'plsql:AP_WEB_EXPENSE_WF.resetLineInfo/');
5083 END IF;
5084
5085 ----------------------------------------------------------------
5086 l_debug_info := 'Unset error message';
5087 -----------------------------------------------------------------
5088 WF_ENGINE.SetItemAttrText(p_item_type,
5089 p_item_key,
5090 'ERROR_MESSAGE',
5091 '');
5092
5093
5094
5095 ----------------------------------------------------------------------
5096 l_debug_info := 'Unset Find Approver Count';
5097 ----------------------------------------------------------------------
5098 WF_ENGINE.SetItemAttrNumber(p_item_type,
5099 p_item_key,
5100 'FIND_APPROVER_COUNT',
5101 0);
5102
5103 ----------------------------------------------------------------------
5104 l_debug_info := 'Unset Forward_From Item Attributes With Approver Info';
5105 ----------------------------------------------------------------------
5106 WF_ENGINE.SetItemAttrText(p_item_type,
5107 p_item_key,
5108 'FORWARD_FROM_DISPLAY_NAME',
5109 '');
5110
5111 WF_ENGINE.SetItemAttrNUMBER(p_item_type,
5112 p_item_key,
5113 'FORWARD_FROM_ID',
5114 '');
5115
5116 WF_ENGINE.SetItemAttrText(p_item_type,
5117 p_item_key,
5118 'FORWARD_FROM_NAME',
5119 '');
5120
5121 IF (C_WF_VERSION < AP_WEB_EXPENSE_WF.C_NoMultiLineVersion) THEN
5122 ------------------------------------------------------------------------
5123 l_debug_info := 'Set Line_Info Item Attribute with formatted expense line';
5124 ---------------------------------------------------------------------------
5125 FOR I IN 1..200 LOOP
5126
5127 WF_ENGINE.SetItemAttrText(p_item_type,
5128 p_item_key,
5129 'LINE_INFO' || TO_CHAR(I),
5130 '');
5131
5132 END LOOP;
5133 ---------------------------------------------------------
5134 l_debug_info := 'Unset Item Attribute Line_Info_Body1';
5135 ---------------------------------------------------------
5136 WF_ENGINE.SetItemAttrText(p_item_type,
5137 p_item_key,
5138 'LINE_INFO_BODY',
5139 '');
5140
5141 END IF;
5142
5143 --------------------------------------------------------------------------
5144 l_debug_info := 'Reset
5145 Manager_Approval_Send_Count Item Attribute and return Y';
5146 --------------------------------------------------------------------------
5147 WF_ENGINE.SetItemAttrNumber(p_item_type,
5148 p_item_key,
5149 'MANAGER_APPROVAL_SEND_COUNT',
5150 0);
5151
5152 ---------------------------------------------------------------
5153 l_debug_info := 'Unset Manager_Display_Name Info Item Attribute';
5154 ---------------------------------------------------------------
5155 WF_ENGINE.SetItemAttrText(p_item_type,
5156 p_item_key,
5157 'MANAGER_DISPLAY_NAME',
5158 '');
5159
5160 --------------------------------------------------------
5161 l_debug_info := 'Unset Manager_ID Info Item Attribute';
5162 --------------------------------------------------------
5163 WF_ENGINE.SetItemAttrText(p_item_type,
5164 p_item_key,
5165 'MANAGER_ID',
5166 '');
5167
5168 --------------------------------------------------------
5169 l_debug_info := 'Unset Manager_Name Info Item Attribute';
5170 --------------------------------------------------------
5171 WF_ENGINE.SetItemAttrText(p_item_type,
5172 p_item_key,
5173 'MANAGER_NAME',
5174 '');
5175
5176
5177 -----------------------------------------------------------------
5178 l_debug_info := 'Unset Missing Receipt Total';
5179 -----------------------------------------------------------------
5180 WF_ENGINE.SetItemAttrText(p_item_type,
5181 p_item_key,
5182 'MISSING_RECEIPT_TOTAL',
5183 '');
5184
5185 ---------------------------------------------------------------
5186 l_debug_info := 'Reset rejection reason';
5187 ---------------------------------------------------------------
5188 WF_ENGINE.SetItemAttrText(p_item_type,
5189 p_item_key,
5190 'WF_NOTE',
5191 '');
5192
5193 ---------------------------------------------------------------
5194 l_debug_info := 'Reset violation note';
5195 ---------------------------------------------------------------
5196 WF_ENGINE.SetItemAttrText(p_item_type,
5197 p_item_key,
5198 'VIOLATION_NOTE',
5199 '');
5200
5201 ---------------------------------------------------------------
5202 l_debug_info := 'Reset Employee violation note';
5203 ---------------------------------------------------------------
5204 WF_ENGINE.SetItemAttrText(p_item_type,
5205 p_item_key,
5206 'EMP_VIOLATION_NOTE',
5207 '');
5208
5209 ---------------------------------------------------------------
5210 l_debug_info := 'Reset violation total';
5211 ---------------------------------------------------------------
5212 WF_ENGINE.SetItemAttrText(p_item_type,
5213 p_item_key,
5214 'VIOLATIONS_TOTAL',
5215 '');
5216
5217 --Bug 4425821: Uptake AME parallel approvers
5218 ---------------------------------------------------------------
5219 l_debug_info := 'Reset AME Approver Response';
5220 ---------------------------------------------------------------
5221 IF (C_WF_Version >= AP_WEB_EXPENSE_WF.C_R120_Version) THEN
5222 WF_ENGINE.SetItemAttrText(p_item_type,
5223 p_item_key,
5224 'AME_APPROVER_RESPONSE',
5225 '');
5226 WF_ENGINE.SetItemAttrText(p_item_type,
5227 p_item_key,
5228 'AME_REJECTED_CHILD_ITEM_KEY',
5229 '');
5230 begin
5231 WF_ENGINE.SetItemAttrText(p_item_type,
5232 p_item_key,
5233 'AME_APPROVED_CHILD_ITEM_KEY',
5234 '');
5235 exception
5236 when others then
5237 if (wf_core.error_name = 'WFENG_ITEM_ATTR') then
5238 null;
5239 else
5240 raise;
5241 end if;
5242 end;
5243 END IF;
5244
5245 --
5246 -- Bug 668037
5247 -- Reset approver attributes
5248 --
5249 IF (NOT AP_WEB_DB_EXPRPT_PKG.GetOverrideApproverID(to_number(p_item_key), l_override_approver_id)) THEN
5250 l_override_approver_id := NULL;
5251 END IF;
5252
5253 IF (l_override_approver_id IS NOT NULL) THEN
5254 AP_WEB_EXPENSE_WF.SetPersonAs(l_override_approver_id,
5255 p_item_type,
5256 p_item_key,
5257 'APPROVER');
5258 ELSE
5259 --------------------------------------------------------
5260 l_debug_info := 'Set Approver_ID Info Item Attribute';
5261 --------------------------------------------------------
5262 WF_ENGINE.SetItemAttrText(p_item_type,
5263 p_item_key,
5264 'APPROVER_ID',
5265 null);
5266
5267 --------------------------------------------------------
5268 l_debug_info := 'Set Approver_Name Info Item Attribute';
5269 --------------------------------------------------------
5270 WF_ENGINE.SetItemAttrText(p_item_type,
5271 p_item_key,
5272 'APPROVER_NAME',
5273 '');
5274
5275 ----------------------------------------------------------------
5276 l_debug_info := 'Set Approver_Display_Name Info Item Attribute';
5277 ----------------------------------------------------------------
5278 WF_ENGINE.SetItemAttrText(p_item_type,
5279 p_item_key,
5280 'APPROVER_DISPLAY_NAME',
5281 '');
5282 END IF;
5283
5284 ----------------------------------------------------------------
5285 l_debug_info := 'Reset AP Validation Attributes';
5286 ----------------------------------------------------------------
5287 ResetAPValidationAttrValues(p_item_type,
5288 p_item_key,
5289 p_actid);
5290
5291 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end ResetAttrValues');
5292
5293 EXCEPTION
5294 WHEN OTHERS THEN
5295 NULL;
5296 END ResetAttrValues;
5297
5298 /*----------------------------------------------------------------------------*
5299 | Procedure |
5300 | ResetCCardTxns |
5301 | |
5302 | DESCRIPTION |
5303 | Private procedure for resetting credit card transactions |
5304 | PARAMETERS |
5305 | INPUT |
5306 | p_report_header_id NUMBER -- Expense Report Header ID |
5307 | RETURNS |
5308 | none |
5309 *----------------------------------------------------------------------------*/
5310
5311 PROCEDURE ResetCCardTxns (
5312 p_report_header_id IN AP_WEB_DB_EXPLINE_PKG.expLines_headerID,
5313 p_item_type IN VARCHAR2,
5314 p_item_key IN VARCHAR2)
5315 IS
5316 l_payment_due VARCHAR2(50) := C_IndividualPay;
5317 l_debug_info VARCHAR2(200);
5318 BEGIN
5319
5320 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF',
5321 'start ResetCCardTxns');
5322
5323 l_payment_due := WF_ENGINE.GetItemAttrText(p_item_type, p_item_key,
5324 'PAYMENT_DUE_FROM');
5325
5326 l_debug_info := 'Update for Credit Card Integration';
5327 IF (l_payment_due = C_CompanyPay) THEN
5328 IF (NOT AP_WEB_DB_EXPLINE_PKG.DeletePersonalLines(p_report_header_id))
5329 THEN
5330 NULL;
5331 END IF;
5332 END IF;
5333
5334 /* Bug 2356968. When an expense report contains a Personal CC txn, and if
5335 the approver rejects that Expense Report upon submission, the following
5336 call to ResetMgrRejectPersonalTrxns will remove the Personal CC txn
5337 from the expense report, whereby it becomes part of the common queue again
5338 allowing other users to use the same CC txn on other expense reports. Hence
5339 commenting the call because the expense report should maintian its original
5340 data on rejected reports.
5341 l_debug_info := 'Update for Credit Card Integration Bothpay';
5342 IF (l_payment_due = C_CompanyPay OR
5343 l_payment_due = AP_WEB_EXPENSE_WF.C_BothPay) THEN
5344 IF (NOT AP_WEB_DB_CCARD_PKG.ResetMgrRejectPersonalTrxns(
5345 p_report_header_id)) THEN
5346 NULL;
5347 END IF;
5348 END IF;
5349 */
5350
5351 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF',
5352 'end ResetCCardTxns');
5353
5354 EXCEPTION
5355 WHEN OTHERS THEN
5356 ROLLBACK;
5357 APP_EXCEPTION.RAISE_EXCEPTION;
5358 END ResetCCardTxns;
5359
5360 PROCEDURE AMEAbortRequestApprovals(
5361 p_rep_header_id IN AP_WEB_DB_EXPLINE_PKG.expLines_headerID,
5362 p_withdraw IN VARCHAR2 DEFAULT 'N')
5363 IS
5364 l_debug_info VARCHAR2(200);
5365 l_wf_active BOOLEAN := FALSE;
5366 l_wf_exist BOOLEAN := FALSE;
5367 l_end_date wf_items.end_date%TYPE;
5368 l_childItemKeySeq NUMBER;
5369 l_childItemKey varchar2(30);
5370 l_itemkey varchar2(30);
5371 l_itemtype varchar2(30);
5372 l_AmeRejectedChildItemKey varchar2(30);
5373 l_AmeApprovedChildItemKey varchar2(30);
5374 l_ap_reject_return varchar2(1);
5375 l_ap_review_status AP_WEB_DB_EXPRPT_PKG.expHdr_wkflApprvdFlag;
5376 l_WorkflowRec AP_WEB_DB_EXPRPT_PKG.ExpWorkflowRec;
5377 BEGIN
5378
5379 l_itemtype := 'APEXP';
5380 l_itemkey := to_char(p_rep_header_id);
5381
5382 ---------------------------------------------
5383 l_debug_info := 'Start AMEAbortRequestApprovals';
5384 ---------------------------------------------
5385 l_childItemKeySeq := WF_ENGINE.GetItemAttrNumber(l_itemtype,
5386 l_itemkey,
5387 'AME_CHILD_ITEM_KEY_SEQ');
5388
5389 l_AmeRejectedChildItemKey := WF_ENGINE.GetItemAttrText(l_itemtype,
5390 l_itemkey,
5391 'AME_REJECTED_CHILD_ITEM_KEY');
5392
5393 -- bug 6686996
5394 begin
5395 l_AmeApprovedChildItemKey := WF_ENGINE.GetItemAttrText(l_itemtype,
5396 l_itemkey,
5397 'AME_APPROVED_CHILD_ITEM_KEY');
5398 exception
5399 when others then
5400 if (wf_core.error_name = 'WFENG_ITEM_ATTR') then
5401 l_AmeApprovedChildItemKey := null;
5402 else
5403 raise;
5404 end if;
5405 end;
5406
5407 -------------------------------------------------
5408 l_debug_info := 'Retrieve The AP Reviewed Flag';
5409 -------------------------------------------------
5410 IF (AP_WEB_DB_EXPRPT_PKG.GetExpWorkflowInfo(to_number(l_itemkey),
5411 l_WorkflowRec)) THEN
5412 l_ap_review_status := nvl(l_WorkflowRec.workflow_flag, 'N');
5413 END IF;
5414
5415 l_ap_reject_return := 'N';
5416 IF (l_ap_review_status = AP_WEB_DB_EXPRPT_PKG.C_WORKFLOW_APPROVED_REJECTED or -- already AP rejected
5417 l_ap_review_status = AP_WEB_DB_EXPRPT_PKG.C_WORKFLOW_APPROVED_REQUEST) THEN -- already AP requests more info
5418 l_ap_reject_return := 'Y';
5419 END IF;
5420
5421 if (l_childItemKeySeq >= 1) then
5422
5423 FOR i in 1 .. l_childItemKeySeq LOOP
5424 l_childItemKey := l_itemkey || '-' || to_char(i);
5425 l_end_date := null;
5426 l_wf_active := FALSE;
5427 l_wf_exist := FALSE;
5428
5429 ---------------------------------------------------------------------------
5430 l_debug_info := 'l_childItemKey :' || l_childItemKey;
5431 l_debug_info := 'l_AmeRejectedChildItemKey: ' || l_AmeRejectedChildItemKey;
5432 ---------------------------------------------------------------------------
5433
5434 if ((((l_AmeRejectedChildItemKey is null) or (l_childItemKey <> l_AmeRejectedChildItemKey)) and
5435 ((l_ap_reject_return = 'N') or
5436 (l_ap_reject_return = 'Y' and (l_AmeApprovedChildItemKey is null or l_childItemKey <> l_AmeApprovedChildItemKey))) )
5437 or
5438 (p_withdraw = 'Y'))
5439 then
5440
5441 begin
5442 select end_date
5443 into l_end_date
5444 from wf_items
5445 where item_type = l_itemtype
5446 and item_key = l_childItemKey;
5447
5448 if l_end_date is NULL then
5449 l_wf_active := TRUE;
5450 else
5451 l_wf_active := FALSE;
5452 end if;
5453 l_wf_exist := TRUE;
5454 exception
5455 when no_data_found then
5456 l_wf_active := FALSE;
5457 l_wf_exist := FALSE;
5458 end;
5459
5460 if l_wf_exist then
5461
5462 if l_wf_active then
5463 --------------------------------------------------------
5464 l_debug_info := 'Abort Child Process' || l_childItemKey;
5465 --------------------------------------------------------
5466 wf_engine.AbortProcess (itemtype => l_itemtype,
5467 itemkey => l_childItemKey,
5468 cascade => TRUE);
5469 end if;
5470
5471 ---------------------------------------------------------
5472 l_debug_info := 'Purge child workflow' || l_childItemKey;
5473 ---------------------------------------------------------
5474 wf_purge.Items(itemtype => l_itemtype,
5475 itemkey => l_childItemKey);
5476
5477 wf_purge.TotalPerm(itemtype => l_itemtype,
5478 itemkey => l_childItemKey,
5479 runtimeonly => TRUE);
5480
5481 ---------------------------------------------------------------
5482 l_debug_info := 'After Purge child workflow' || l_childItemKey;
5483 ---------------------------------------------------------------
5484
5485 end if;
5486 end if;
5487
5488 END LOOP;
5489
5490 end if;
5491 END AMEAbortRequestApprovals;
5492
5493 ----------------------------------------------------------------------
5494 PROCEDURE SetRejectStatusAndResetAttr(p_item_type IN VARCHAR2,
5495 p_item_key IN VARCHAR2,
5496 p_actid IN NUMBER,
5497 p_funmode IN VARCHAR2,
5498 p_result OUT NOCOPY VARCHAR2) IS
5499 ----------------------------------------------------------------------
5500 l_debug_info VARCHAR2(200);
5501 l_report_header_id AP_WEB_DB_EXPRPT_PKG.expHdr_headerID;
5502 l_payment_due VARCHAR2(10) := C_IndividualPay;
5503 l_AMEEnabled VARCHAR2(1);
5504 l_No VARCHAR2(1) := 'N';
5505 C_WF_Version NUMBER := 0;
5506 l_n_resp_id NUMBER;
5507 BEGIN
5508
5509 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start SetRejectStatusAndResetAttr');
5510
5511 IF (p_funmode = 'RUN') THEN
5512
5513 -----------------------------------------------------
5514 l_debug_info := 'Get Workflow Version Number';
5515 -----------------------------------------------------
5516 C_WF_Version := AP_WEB_EXPENSE_WF.GetFlowVersion(p_item_type, p_item_key);
5517
5518 ------------------------------------------------------------
5519 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
5520 ------------------------------------------------------------
5521 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
5522 p_item_key,
5523 'EXPENSE_REPORT_ID');
5524
5525 l_payment_due := WF_ENGINE.GetItemAttrText(p_item_type,p_item_key,'PAYMENT_DUE_FROM');
5526
5527 ------------------------------------------------------------
5528 l_debug_info := 'Set reject status in report header';
5529 ------------------------------------------------------------
5530 IF (NOT AP_WEB_DB_EXPRPT_PKG.SetWkflApprvdFlagAndSource(l_report_header_id,
5531 AP_WEB_DB_EXPRPT_PKG.C_WORKFLOW_APPROVED_REJECTED,
5532 'NonValidatedWebExpense')) THEN
5533 NULL;
5534 END IF;
5535
5536 /* This is required for AME integration with Expenses in 11i
5537 In 11, this procedure is only a stub */
5538 /*
5539 AP_WEB_WRAPPER_PKG.SetRejectStatusInAME(p_item_key,
5540 p_item_type);*/
5541
5542 -- Bug 3560082 - Comment the call to SetRejectStatusInAME and add the call
5543 -- AME_API.clearAllApprovals
5544 l_AMEEnabled := WF_ENGINE.GetItemAttrText(p_item_type,
5545 p_item_key,
5546 'AME_ENABLED');
5547 IF (l_AMEEnabled = 'Y') THEN
5548 --Bug 4425821: Uptake AME parallel approvers
5549 IF (C_WF_Version >= AP_WEB_EXPENSE_WF.C_R120_Version) THEN
5550 ---------------------------------------------------------------------------
5551 l_debug_info := 'Call AMEAbortRequestApprovals' || to_char(l_report_header_id);
5552 ---------------------------------------------------------------------------
5553 AMEAbortRequestApprovals(l_report_header_id);
5554 END IF;
5555
5556 -----------------------------------------------------------------
5557 l_debug_info := 'Call clearAllApprovals' || to_char(p_item_key) ;
5558 -----------------------------------------------------------------
5559 AME_API2.clearAllApprovals(applicationIdIn => AP_WEB_DB_UTIL_PKG.GetApplicationID,
5560 transactionIdIn => p_item_key,
5561 transactionTypeIn => p_item_type);
5562
5563 END IF;
5564
5565 -----------------------------------------------------------------
5566 l_debug_info := 'Call AP_WEB_AUDIT_QUEUE_UTILS.remove_from_queue';
5567 -----------------------------------------------------------------
5568 AP_WEB_AUDIT_QUEUE_UTILS.remove_from_queue(l_report_header_id);
5569
5570 ----------------------------------------------------------
5571 l_debug_info := 'Clearing out lines in AP_AUD_AUDIT_REASONS';
5572 ----------------------------------------------------------
5573 -- Bug 4394168
5574 AP_WEB_AUDIT_UTILS.clear_audit_reason_codes(l_report_header_id);
5575
5576 ------------------------------------------------------------
5577 l_debug_info := 'call reset credit card transactions';
5578 ------------------------------------------------------------
5579 ResetCCardTxns(l_report_header_id, p_item_type, p_item_key);
5580
5581 -- 4001778/3654956 : reset the Apply Advances
5582 --5060928: reset the Apply Advnaces only if OIE:Enable Advances = "Payables"
5583
5584 begin
5585
5586 l_n_resp_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
5587 p_item_key,
5588 'RESPONSIBILITY_ID');
5589
5590 exception
5591 when others then
5592 if (wf_core.error_name = 'WFENG_ITEM_ATTR') then
5593 null;
5594 else
5595 raise;
5596 end if;
5597 end;
5598
5599 IF FND_PROFILE.VALUE_SPECIFIC('OIE_ENABLE_ADVANCES',NULL,l_n_resp_id,200) = 'PAYABLES' THEN
5600
5601 AP_WEB_DB_EXPLINE_PKG.resetApplyAdvances(l_report_header_id);
5602 END IF;
5603
5604
5605 /* Bug 4019412 */
5606 AP_WEB_DB_EXPLINE_PKG.resetAPflags(l_report_header_id);
5607
5608 ------------------------------------------------------------
5609 l_debug_info := 'Set which process to start from';
5610 ------------------------------------------------------------
5611 -- Indicate which process to start from
5612 -- (skip ServerValidate, Manager Approval)
5613 WF_ENGINE.SetItemAttrText(p_item_type,
5614 p_item_key,
5615 'START_FROM_PROCESS',
5616 C_START_FROM_SERVER_VALIDATION);
5617
5618 -- Reset the attributes which will not be set by code to initialize a
5619 -- process
5620 ----------------------------------------------------------
5621 l_debug_info := 'Reset attribute';
5622 ----------------------------------------------------------
5623 ResetAttrValues(p_item_type, p_item_key, p_actid);
5624
5625 ----------------------------------------------------------
5626 l_debug_info := 'Reset Receipt Verified Flag to N';
5627 ----------------------------------------------------------
5628 -- Bug 4094871
5629 begin
5630 update ap_expense_report_lines
5631 set receipt_verified_flag = l_No
5632 where report_header_id = l_report_header_id;
5633 exception
5634 when others then null;
5635 end;
5636
5637 -----------------------------------------------
5638 l_debug_info := 'Raise Receipts Aborted Event';
5639 -----------------------------------------------
5640 AP_WEB_RECEIPTS_WF.RaiseAbortedEvent(l_report_header_id);
5641
5642 -----------------------------------------------------
5643 l_debug_info := 'After Raise Receipts Aborted Event';
5644 -----------------------------------------------------
5645 p_result := 'COMPLETE:Y';
5646 ELSIF (p_funmode = 'CANCEL') THEN
5647 p_result := 'COMPLETE';
5648 END IF;
5649
5650 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end SetRejectStatusAndResetAttr');
5651
5652 EXCEPTION
5653 WHEN OTHERS THEN
5654 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'SetRejectStatusAndResetAttr',
5655
5656 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
5657 RAISE;
5658
5659 END SetRejectStatusAndResetAttr;
5660
5661 ----------------------------------------------------------------------
5662 PROCEDURE DeleteExpenseReport(p_item_type IN VARCHAR2,
5663 p_item_key IN VARCHAR2,
5664 p_actid IN NUMBER,
5665 p_funmode IN VARCHAR2,
5666 p_result OUT NOCOPY VARCHAR2) IS
5667 ----------------------------------------------------------------------
5668 l_report_header_id AP_WEB_DB_EXPRPT_PKG.expHdr_headerID;
5669 l_debug_info VARCHAR2(200);
5670 BEGIN
5671
5672 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start DeleteExpenseReport');
5673
5674 IF (p_funmode = 'RUN') THEN
5675
5676 ------------------------------------------------------------
5677 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
5678 ------------------------------------------------------------
5679 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
5680 p_item_key,
5681 'EXPENSE_REPORT_ID');
5682
5683 DeleteExpReportFromAPTables(l_report_header_id);
5684
5685 AP_WEB_DB_VIOLATIONS_PKG.deleteViolationEntry(l_report_header_id);
5686
5687 ELSIF (p_funmode = 'CANCEL') THEN
5688 p_result := 'COMPLETE';
5689 END IF;
5690
5691 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end DeleteExpenseReport');
5692
5693 EXCEPTION
5694 WHEN OTHERS THEN
5695 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'DeleteExpenseReport',
5696 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
5697 raise;
5698 END DeleteExpenseReport;
5699
5700 ----------------------------------------------------------------
5701 PROCEDURE StartAPApprvlSubProcess(p_item_type IN VARCHAR2,
5702 p_item_key IN VARCHAR2,
5703 p_actid IN NUMBER,
5704 p_funmode IN VARCHAR2,
5705 p_result OUT NOCOPY VARCHAR2) IS
5706 -----------------------------------------------------------------
5707 l_item_key VARCHAR2(100);
5708 l_preparer_id NUMBER;
5709 l_preparer_name wf_users.name%type;
5710 l_preparer_display_name wf_users.display_name%type;
5711 l_employee_id NUMBER;
5712 l_employee_name wf_users.name%type;
5713 l_employee_display_name wf_users.display_name%type;
5714 l_report_header_id NUMBER;
5715 l_document_number VARCHAR2(50);
5716 l_emp_cost_center VARCHAR2(240);
5717 l_doc_cost_center VARCHAR2(240);
5718 l_total NUMBER;
5719 l_payment_due VARCHAR2(10) := C_IndividualPay;
5720 l_currency VARCHAR2(25);
5721 l_debug_info VARCHAR2(200);
5722 BEGIN
5723
5724 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start StartAPApprvlSubProcess');
5725
5726 ------------------------------------------------------------
5727 l_debug_info := 'Retrieve New Expense_Report_ID Item Attribute';
5728 ------------------------------------------------------------
5729 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
5730 p_item_key,
5731 'NEW_EXPENSE_REPORT_ID');
5732
5733 --------------------------------------------------------------
5734 l_debug_info := 'Retrieve New Document Number Item Attribute';
5735 ---------------------------------------------------------------
5736 l_document_number := WF_ENGINE.GetItemAttrText(p_item_type,
5737 p_item_key,
5738 'NEW_DOCUMENT_NUMBER');
5739
5740
5741 ----------------------------------------------------------------
5742 l_debug_info := 'Retrieve Employee Cost Center Item Attribute';
5743 ----------------------------------------------------------------
5744 l_emp_cost_center := WF_ENGINE.GetItemAttrText(p_item_type,
5745 p_item_key,
5746 'EMP_COST_CENTER');
5747
5748 ----------------------------------------------------------------
5749 l_debug_info := 'Retrieve Document Cost Center Item Attribute';
5750 ----------------------------------------------------------------
5751 l_doc_cost_center := WF_ENGINE.GetItemAttrText(p_item_type,
5752 p_item_key,
5753 'DOC_COST_CENTER');
5754
5755 -----------------------------------------------------
5756 l_debug_info := 'Retrieve New Total Item Attribute';
5757 -----------------------------------------------------
5758 l_total := WF_ENGINE.GetItemAttrNumber(p_item_type,
5759 p_item_key,
5760 'NEW_TOTAL');
5761
5762 -----------------------------------------------------
5763 l_debug_info := 'Retrieve Currency Item Attribute';
5764 -----------------------------------------------------
5765 l_currency := WF_ENGINE.GetItemAttrText(p_item_type,
5766 p_item_key,
5767 'CURRENCY');
5768
5769 --------------------------------
5770 l_debug_info := 'Set item key';
5771 --------------------------------
5772 l_item_key := to_char(l_report_header_id);
5773
5774
5775 -------------------------------------------------------
5776 l_debug_info := 'Retrieve Preparer_ID Item Attribute';
5777 -------------------------------------------------------
5778 l_preparer_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
5779 p_item_key,
5780 'PREPARER_ID');
5781
5782 -------------------------------------------------------
5783 l_debug_info := 'Retrieve Employee_ID Item Attribute';
5784 -------------------------------------------------------
5785 l_employee_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
5786 p_item_key,
5787 'EMPLOYEE_ID');
5788
5789 -------------------------------------------------------
5790 l_debug_info := 'Retrieve CC Payment Due From Item Attribute';
5791 -------------------------------------------------------
5792 l_payment_due := WF_ENGINE.GetItemAttrText(p_item_type,
5793 p_item_key,
5794 'PAYMENT_DUE_FROM');
5795
5796 -------------------------------------------------
5797 l_debug_info := 'Create AP Approval Subprocess';
5798 -------------------------------------------------
5799 WF_ENGINE.CreateProcess(p_item_type,
5800 l_item_key,
5801 'AP_EXPENSE_REPORT_PROCESS');
5802
5803 --------------------------------------------------------
5804 l_debug_info := 'Set Expense_Report_ID Item Attribute';
5805 --------------------------------------------------------
5806 WF_ENGINE.SetItemAttrNumber(p_item_type,
5807 l_item_key,
5808 'EXPENSE_REPORT_ID',
5809 l_report_header_id);
5810
5811 ------------------------------------------------------
5812 l_debug_info := 'Set Document_Number Item Attribute';
5813 ------------------------------------------------------
5814 WF_ENGINE.SetItemAttrText(p_item_type,
5815 l_item_key,
5816 'DOCUMENT_NUMBER',
5817 l_document_number);
5818
5819 ----------------------------------------------------------
5820 l_debug_info := 'Get Preparer Name Info For Preparer_Id';
5821 ----------------------------------------------------------
5822 WF_DIRECTORY.GetUserName('PER',
5823 l_preparer_id,
5824 l_preparer_name,
5825 l_preparer_display_name);
5826
5827 WF_ENGINE.SetItemAttrText(p_item_type,
5828 l_item_key,
5829 'PREPARER_ID',
5830 l_preparer_id);
5831
5832 ----------------------------------------------------------
5833 l_debug_info := 'Set Preparer Name Info Item Attributes';
5834 ----------------------------------------------------------
5835 WF_ENGINE.SetItemAttrText(p_item_type,
5836 l_item_key,
5837 'PREPARER_NAME',
5838 l_preparer_name);
5839
5840 WF_ENGINE.SetItemAttrText(p_item_type,
5841 l_item_key,
5842 'PREPARER_DISPLAY_NAME',
5843 l_preparer_display_name);
5844
5845 ----------------------------------------------------------
5846 l_debug_info := 'Get Employee Name Info For Employee_Id';
5847 ----------------------------------------------------------
5848 WF_DIRECTORY.GetUserName('PER',
5849 l_employee_id,
5850 l_employee_name,
5851 l_employee_display_name);
5852
5853 WF_ENGINE.SetItemAttrText(p_item_type,
5854 l_item_key,
5855 'EMPLOYEE_ID',
5856 l_employee_id);
5857
5858 ----------------------------------------------------------
5859 l_debug_info := 'Set Employee Name Info Item Attributes';
5860 ----------------------------------------------------------
5861 WF_ENGINE.SetItemAttrText(p_item_type,
5862 l_item_key,
5863 'EMPLOYEE_NAME',
5864 l_employee_name);
5865
5866 WF_ENGINE.SetItemAttrText(p_item_type,
5867 l_item_key,
5868 'EMPLOYEE_DISPLAY_NAME',
5869 l_employee_display_name);
5870
5871 -------------------------------------------------
5872 l_debug_info := 'Set Total Item Attribute';
5873 -------------------------------------------------
5874 WF_ENGINE.SetItemAttrNumber(p_item_type,
5875 l_item_key,
5876 'TOTAL',
5877 l_total);
5878
5879 -----------------------------------------------------------------
5880 l_debug_info := 'Set New Adjusted Display_Total Item Attribute';
5881 -----------------------------------------------------------------
5882 WF_ENGINE.SetItemAttrText(p_item_type,
5883 l_item_key,
5884 'DISPLAY_TOTAL',
5885 to_char(l_total,FND_CURRENCY.Get_Format_Mask(l_currency,22)) || ' ' || l_currency);
5886
5887 ----------------------------------------------
5888 l_debug_info := 'Set Currency Item Attribute';
5889 -----------------------------------------------
5890 WF_ENGINE.SetItemAttrText(p_item_type,
5891 l_item_key,
5892 'CURRENCY',
5893 l_currency);
5894
5895
5896 -----------------------------------------------------------
5897 l_debug_info := 'Set Document Cost Center Item Attribute';
5898 -----------------------------------------------------------
5899 WF_ENGINE.SetItemAttrText(p_item_type,
5900 l_item_key,
5901 'DOC_COST_CENTER',
5902 l_doc_cost_center);
5903
5904 -----------------------------------------------------------
5905 l_debug_info := 'Set Employee Cost Center Item Attribute';
5906 -----------------------------------------------------------
5907 WF_ENGINE.SetItemAttrText(p_item_type,
5908 l_item_key,
5909 'EMP_COST_CENTER',
5910 l_emp_cost_center);
5911
5912 --------------------------------------------------------------
5913 l_debug_info := 'Set CC Payment Due From Item Attribute';
5914 --------------------------------------------------------------
5915 WF_ENGINE.SetItemAttrText(p_item_type,
5916 l_item_key,
5917 'PAYMENT_DUE_FROM',
5918 l_payment_due);
5919
5920 -----------------------------------------------------------
5921 l_debug_info := 'Skip server validation and manager approval';
5922 -----------------------------------------------------------
5923 WF_ENGINE.SetItemAttrText(p_item_type,
5924 l_item_key,
5925 'START_FROM_PROCESS',
5926 C_START_FROM_AP_APPROVAL);
5927
5928 -------------------------------------------------
5929 l_debug_info := 'Start AP Approval Sub Process';
5930 -------------------------------------------------
5931 WF_ENGINE.StartProcess(p_item_type,
5932 l_item_key);
5933
5934 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end StartAPApprvlSubProcess');
5935
5936 EXCEPTION
5937 WHEN OTHERS THEN
5938 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'StartAPApprvlSubProcess',
5939 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
5940 raise;
5941 END StartAPApprvlSubProcess;
5942
5943 ----------------------------------------------------------------------
5944 PROCEDURE StartFromAPApproval(p_item_type IN VARCHAR2,
5945 p_item_key IN VARCHAR2,
5946 p_actid IN NUMBER,
5947 p_funmode IN VARCHAR2,
5948 p_result OUT NOCOPY VARCHAR2) IS
5949 ----------------------------------------------------------------------
5950 l_report_header_id AP_WEB_DB_EXPRPT_PKG.expHdr_headerID;
5951 l_debug_info VARCHAR2(200);
5952 l_No VARCHAR2(1) := 'N';
5953 BEGIN
5954
5955 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start StartFromAPApproval');
5956
5957 IF (p_funmode = 'RUN') THEN
5958
5959 ----------------------------------------------------------------
5960 l_debug_info := 'Retrieve New_Expense_Report_ID Item Attribute';
5961 ----------------------------------------------------------------
5962 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
5963 p_item_key,
5964 'EXPENSE_REPORT_ID');
5965
5966
5967 --------------------------------------------------------------
5968 l_debug_info := 'Update all expense lines as receipt missing';
5969 --------------------------------------------------------------
5970 -- Bug 884248
5971 IF (NOT AP_WEB_DB_EXPRPT_PKG.SetWkflApprvdFlag2(l_report_header_id)) THEN
5972 NULL;
5973 END IF;
5974
5975 ----------------------------------------------------------
5976 l_debug_info := 'Update Receipts Status to Required if Pending Resolution';
5977 ----------------------------------------------------------
5978 update ap_expense_report_headers
5979 set receipts_status = 'IN_TRANSIT'
5980 where report_header_id = l_report_header_id
5981 and receipts_status = 'RESOLUTN';
5982
5983 update ap_expense_report_headers
5984 set image_receipts_status = 'IN_TRANSIT'
5985 where report_header_id = l_report_header_id
5986 and image_receipts_status = 'RESOLUTN';
5987
5988 ----------------------------------------------------------
5989 l_debug_info := 'Reset Receipt Missing Flag';
5990 ----------------------------------------------------------
5991 -- Bug 4075372
5992 update ap_expense_report_lines
5993 set receipt_missing_flag = l_No
5994 where report_header_id = l_report_header_id;
5995
5996 ------------------------------------------------------------
5997 l_debug_info := 'Set which process to start from';
5998 ------------------------------------------------------------
5999 -- Indicate which process to start from
6000 -- (skip ServerValidate, Manager Approval)
6001 WF_ENGINE.SetItemAttrText(p_item_type,
6002 p_item_key,
6003 'START_FROM_PROCESS',
6004 C_START_FROM_AP_APPROVAL);
6005
6006 ELSIF (p_funmode = 'CANCEL') THEN
6007 p_result := 'COMPLETE';
6008 END IF;
6009
6010 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end StartFromAPApproval');
6011
6012 EXCEPTION
6013 WHEN OTHERS THEN
6014 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'StartFromAPApproval',
6015 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
6016 raise;
6017 END StartFromAPApproval;
6018
6019 ----------------------------------------------------------------------
6020 PROCEDURE StartFromManagerApproval(p_item_type IN VARCHAR2,
6021 p_item_key IN VARCHAR2,
6022 p_actid IN NUMBER,
6023 p_funmode IN VARCHAR2,
6024 p_result OUT NOCOPY VARCHAR2) IS
6025 ----------------------------------------------------------------------
6026 l_report_header_id AP_WEB_DB_EXPLINE_PKG.expLines_headerID;
6027 l_debug_info VARCHAR2(200);
6028 BEGIN
6029
6030 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start StartFromManagerApproval');
6031
6032 IF (p_funmode = 'RUN') THEN
6033
6034 ----------------------------------------------------------------
6035 l_debug_info := 'Retrieve New_Expense_Report_ID Item Attribute';
6036 ----------------------------------------------------------------
6037 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
6038 p_item_key,
6039 'EXPENSE_REPORT_ID');
6040
6041
6042 --------------------------------------------------------------
6043 l_debug_info := 'Update all expense lines as receipt missing';
6044 --------------------------------------------------------------
6045 IF (NOT AP_WEB_DB_EXPLINE_PKG.SetReceiptMissing(l_report_header_id,
6046 'Y')) THEN
6047 NULL;
6048 END IF;
6049
6050 ------------------------------------------------------------
6051 l_debug_info := 'Set which process to start from';
6052 ------------------------------------------------------------
6053 -- Indicate which process to start from
6054 -- (skip ServerValidate, Manager Approval)
6055 WF_ENGINE.SetItemAttrText(p_item_type,
6056 p_item_key,
6057 'START_FROM_PROCESS',
6058 C_START_FROM_MANAGER_APPROVAL);
6059
6060 ELSIF (p_funmode = 'CANCEL') THEN
6061 p_result := 'COMPLETE';
6062 END IF;
6063
6064 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end StartFromManagerApproval');
6065
6066 EXCEPTION
6067 WHEN OTHERS THEN
6068 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'StartFromManagerApproval',
6069 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
6070 raise;
6071 END StartFromManagerApproval;
6072
6073
6074 ----------------------------------------------------------------------
6075 PROCEDURE CheckIfShortPaid(p_item_type IN VARCHAR2,
6076 p_item_key IN VARCHAR2,
6077 p_actid IN NUMBER,
6078 p_funmode IN VARCHAR2,
6079 p_result OUT NOCOPY VARCHAR2) IS
6080 ----------------------------------------------------------------------
6081 l_orig_expense_report_num VARCHAR2(50);
6082 l_debug_info VARCHAR2(200);
6083 BEGIN
6084
6085 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start CheckIfShortPaid');
6086
6087 IF (p_funmode = 'RUN') THEN
6088
6089 ----------------------------------------------------------------
6090 l_debug_info := 'Retrieve ShortPay_Flag Item Attribute';
6091 ----------------------------------------------------------------
6092 l_orig_expense_report_num := WF_ENGINE.GetItemAttrText(p_item_type,
6093 p_item_key,
6094 'ORIG_EXPENSE_REPORT_NUM');
6095
6096 IF (l_orig_expense_report_num IS NOT NULL) THEN
6097 p_result := 'COMPLETE:Y';
6098 ELSE
6099 p_result := 'COMPLETE:N';
6100 END IF;
6101
6102 ELSIF (p_funmode = 'CANCEL') THEN
6103 p_result := 'COMPLETE';
6104 END IF;
6105
6106 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end CheckIfShortPaid');
6107
6108 EXCEPTION
6109 WHEN OTHERS THEN
6110 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'CheckIfShortPaid',
6111 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
6112 raise;
6113 END CheckIfShortPaid;
6114
6115
6116
6117 -----------------------------------------------------------------------------
6118 PROCEDURE BuildBothpayExpReport(p_item_type IN VARCHAR2,
6119 p_item_key IN VARCHAR2,
6120 p_actid IN NUMBER,
6121 p_funmode IN VARCHAR2,
6122 p_result OUT NOCOPY VARCHAR2)
6123 ------------------------------------------------------------------------------
6124 IS
6125 l_report_header_id AP_WEB_DB_EXPRPT_PKG.expHdr_headerID;
6126 l_total AP_WEB_DB_EXPRPT_PKG.expHdr_total := NULL;
6127 l_new_report_id AP_WEB_DB_EXPRPT_PKG.expHdr_headerID;
6128 l_document_number AP_WEB_DB_EXPRPT_PKG.expHdr_invNum;
6129 l_description AP_WEB_DB_EXPRPT_PKG.expHdr_description := NULL;
6130 l_vendor_id AP_WEB_DB_CCARD_PKG.cardProgs_vendorID := NULL;
6131 l_vendor_site_id AP_WEB_DB_CCARD_PKG.cardProgs_vendorSiteID := NULL;
6132 l_ccard_amt AP_WEB_DB_EXPRPT_PKG.expHdr_amtDueCcardCompany := 0;
6133 l_XpenseRec AP_WEB_DB_EXPRPT_PKG.XpenseInfoRec;
6134 l_accts_pay_comb_id AP_WEB_DB_EXPRPT_PKG.expHdr_acctsPayCodeCombID := NULL;
6135 l_debug_info VARCHAR2(2000);
6136 l_ccard_exists BOOLEAN := TRUE;
6137 l_report_submitted_date DATE;
6138 l_org_id NUMBER;
6139 l_holds_setup VARCHAR2(2);
6140 l_expense_status_code VARCHAR2(30) := NULL;
6141 BEGIN
6142
6143 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start BuildBothpayExpReport');
6144
6145 ------------------------------------------------------------
6146 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
6147 ------------------------------------------------------------
6148 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
6149 p_item_key,
6150 'EXPENSE_REPORT_ID');
6151
6152 -------------------------------------------------------------------------
6153 l_debug_info := 'Retrieve and create new Document Number Item Attribute';
6154 -------------------------------------------------------------------------
6155 l_document_number := WF_ENGINE.GetItemAttrText(p_item_type,
6156 p_item_key,
6157 'DOCUMENT_NUMBER') || '.1';
6158
6159
6160 -------------------------------------------------------------------------
6161 l_debug_info := 'Check whether both pay report is already created';
6162 -------------------------------------------------------------------------
6163 -- Bug# 9474326: To avoid duplicate bothpay expense report creation
6164 IF (IsBothPayReportExists(l_report_header_id)) THEN
6165 RETURN;
6166 END IF;
6167
6168 -----------------------------------------------------------------
6169 l_debug_info := 'Retrieve Credit Card New Expense Report Id';
6170 -----------------------------------------------------------------
6171 IF (NOT AP_WEB_DB_EXPRPT_PKG.GetNextExpReportID(l_new_report_id) ) THEN
6172 l_new_report_id := NULL;
6173 END IF;
6174
6175
6176 -------------------------------------------------------------------
6177 l_debug_info := 'Obtain the card number and the full name and the
6178 vendor information for the new expense report';
6179 --------------------------------------------------------------------
6180 IF (NOT AP_WEB_DB_EXPRPT_PKG.GetExpReportInfo(l_report_header_id,
6181 l_description, l_ccard_amt, l_total)) THEN
6182 l_description := NULL;
6183 l_total := 0;
6184 l_ccard_amt := 0;
6185 l_ccard_exists := FALSE;
6186 END IF;
6187
6188 -------------------------------------------------------------------
6189 l_debug_info := 'Obtain the Vendor ID item attribute';
6190 --------------------------------------------------------------------
6191 l_vendor_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
6192 p_item_key,
6193 'VENDOR_ID');
6194
6195
6196 -------------------------------------------------------------------
6197 l_debug_info := 'Obtain the Vendor Site ID item attribute';
6198 --------------------------------------------------------------------
6199 l_vendor_site_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
6200 p_item_key,
6201 'VENDOR_SITE_ID');
6202
6203 /* Bug2610233 : Replacing l_ccard_amt check with l_ccard_exists check.
6204 IF (l_ccard_amt <> 0) THEN */
6205
6206 IF (l_ccard_exists = TRUE) THEN
6207 ----------------------------------------------------------------------
6208 l_debug_info := 'Get the accts pay code combination id from vendors';
6209 ----------------------------------------------------------------------
6210 IF (NOT AP_WEB_DB_AP_INT_PKG.GetVendorSitesCodeCombID(l_vendor_site_id,
6211 l_accts_pay_comb_id) OR
6212 l_accts_pay_comb_id = NULL) THEN
6213 IF (NOT AP_WEB_DB_AP_INT_PKG.GetVendorCodeCombID(l_vendor_id,
6214 l_accts_pay_comb_id)) THEN
6215 l_accts_pay_comb_id := NULL;
6216 END IF;
6217 END IF;
6218
6219
6220 /* Bug2610233 : Replacing l_ccard_amt check with l_ccard_exists check.
6221 IF (l_total - l_ccard_amt <> 0) THEN
6222 */
6223 -------------------------------------------------------------------
6224 l_debug_info := 'Create new expense report by creating new record in
6225 ap_expense_report_headers, with same info as old
6226 expense report except new id, doc number, total,
6227 bothpay parent id, paid on behalf employee id, description,
6228 and amt due ccard company';
6229 --------------------------------------------------------------------
6230 l_XpenseRec.report_header_id := l_new_report_id;
6231 l_XpenseRec.document_number := l_document_number;
6232 l_XpenseRec.employee_id := -1; --will become NULL
6233 l_XpenseRec.org_id := NULL;
6234 l_XpenseRec.vouchno := 0;
6235 l_XpenseRec.total := -1;
6236 l_XpenseRec.vendor_id := l_vendor_id;
6237 l_XpenseRec.vendor_site_id := l_vendor_site_id;
6238 l_XpenseRec.amt_due_employee := 0;
6239 l_XpenseRec.amt_due_ccard := NULL;
6240 l_XpenseRec.description := l_description;
6241 l_XpenseRec.preparer_id := NULL;
6242 l_XpenseRec.last_update_login:= NULL;
6243 l_XpenseRec.last_updated_by := NULL;
6244 l_XpenseRec.workflow_flag := NULL;
6245 l_XpenseRec.expense_check_address_flag := NULL;
6246 l_XpenseRec.bothpay_report_header_id := l_report_header_id;
6247 l_XpenseRec.shortpay_parent_id := NULL;
6248 l_XpenseRec.behalf_employee_id := -1;
6249 l_XpenseRec.approver_id := NULL;
6250 l_XpenseRec.week_end_date := NULL;
6251 l_XpenseRec.set_of_books_id := NULL;
6252 l_XpenseRec.source := 'Both Pay';
6253 l_XpenseRec.accts_pay_comb_id := l_accts_pay_comb_id;
6254
6255 ----------------------------------------------------------
6256 l_debug_info := 'Get Expense Report date';
6257 ----------------------------------------------------------
6258 select report_submitted_date
6259 into l_report_submitted_date
6260 from ap_expense_report_headers
6261 where report_header_id = l_report_header_id;
6262
6263 ------------------------------------------------------------
6264 l_debug_info := 'Retrieve ORG_ID Item Attribute';
6265 ------------------------------------------------------------
6266 l_org_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
6267 p_item_key,
6268 'ORG_ID');
6269
6270
6271 l_holds_setup := AP_WEB_HOLDS_WF.IsHoldsRuleSetup(l_org_id,
6272 l_report_submitted_date);
6273
6274 IF (l_holds_setup = 'Y') THEN
6275 l_expense_status_code := AP_WEB_RECEIPTS_WF.C_PENDING_HOLDS;
6276 ELSE
6277 l_expense_status_code := 'INVOICED';
6278 END IF;
6279
6280 l_XpenseRec.expense_status_code := l_expense_status_code;
6281
6282 IF (NOT AP_WEB_DB_EXPRPT_PKG.InsertReportHeaderLikeExisting(
6283 l_report_header_id, l_XpenseRec)) THEN
6284 NULL;
6285 END IF;
6286
6287 /*Bug#8976900 - Add Reference for attachments from parent expense report
6288 to the short-paid expense report*/
6289 --------------------------------------------------------------------
6290 l_debug_info := 'Creating reference for Header Attachments';
6291 --------------------------------------------------------------------
6292
6293 AP_WEB_DB_EXPRPT_PKG.CopyAttachments(l_report_header_id,
6294 l_new_report_id,
6295 'OIE_HEADER_ATTACHMENTS');
6296
6297 ------------------------------------------------------------------
6298 l_debug_info := 'Insert the lines for the credit card company into
6299 ap_expense_report_lines with new report_header_id';
6300 ------------------------------------------------------------------
6301 IF (NOT AP_WEB_DB_EXPLINE_PKG.AddCCReportLines(l_report_header_id,
6302 l_new_report_id)) THEN
6303 NULL;
6304 END IF;
6305
6306 -----------------------------------------------------------------------
6307 l_debug_info := 'Set the Bothpay Document Number Item Attribute with
6308 the new expense report document number';
6309 -----------------------------------------------------------------------
6310 WF_ENGINE.SetItemAttrText(p_item_type,
6311 p_item_key,
6312 'BOTHPAY_DOC_NUM',
6313 l_document_number);
6314
6315 --------------------------------------------------------------------
6316 l_debug_info := 'Copy Notes from original report';
6317 --------------------------------------------------------------------
6318 AP_WEB_NOTES_PKG.CopyERNotes (
6319 p_src_report_header_id => l_report_header_id,
6320 p_tgt_report_header_id => l_new_report_id
6321 );
6322
6323 END IF;
6324
6325 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end BuildBothpayExpReport');
6326
6327 EXCEPTION
6328 WHEN OTHERS THEN
6329 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'BuildBothpayReport',
6330 null, to_char(l_report_header_id) || ' ' || to_char(l_new_report_id), to_char(p_actid), l_debug_info);
6331 raise;
6332 END BuildBothpayExpReport;
6333
6334
6335 ----------------------------------------------------------------------
6336 PROCEDURE CheckIfBothpay(p_item_type IN VARCHAR2,
6337 p_item_key IN VARCHAR2,
6338 p_actid IN NUMBER,
6339 p_funmode IN VARCHAR2,
6340 p_result OUT NOCOPY VARCHAR2) IS
6341 ----------------------------------------------------------------------
6342 l_payment VARCHAR2(10);
6343 l_debug_info VARCHAR2(200);
6344
6345 BEGIN
6346
6347 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start CheckIfBothpay');
6348
6349 IF (p_funmode = 'RUN') THEN
6350
6351
6352 ----------------------------------------------------------------
6353 l_debug_info := 'Retrieve Profile Option Payment Due From';
6354 ----------------------------------------------------------------
6355 l_payment := WF_ENGINE.GetItemAttrText(p_item_type,p_item_key,'PAYMENT_DUE_FROM');
6356
6357 IF (l_payment = C_BothPay) THEN
6358 p_result := 'COMPLETE:Y';
6359 ELSE
6360 p_result := 'COMPLETE:N';
6361 END IF;
6362
6363 ELSIF (p_funmode = 'CANCEL') THEN
6364 p_result := 'COMPLETE';
6365 END IF;
6366
6367 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end CheckIfBothpay');
6368
6369 EXCEPTION
6370 WHEN OTHERS THEN
6371 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'CheckIfBothpay',
6372 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
6373 raise;
6374 END CheckIfBothpay;
6375
6376 ----------------------------------------------------------------------
6377 PROCEDURE FindVendor(p_item_type IN VARCHAR2,
6378 p_item_key IN VARCHAR2,
6379 p_actid IN NUMBER,
6380 p_funmode IN VARCHAR2,
6381 p_result OUT NOCOPY VARCHAR2) IS
6382 ----------------------------------------------------------------------
6383 l_debug_info VARCHAR2(200);
6384 l_vendor_id AP_WEB_DB_CCARD_PKG.cardProgs_vendorID;
6385 l_vendor_site_id AP_WEB_DB_CCARD_PKG.cardProgs_vendorID;
6386 l_report_header_id AP_WEB_DB_CCARD_PKG.ccTrxn_headerID;
6387 l_crd_card_count NUMBER := 0;
6388
6389 BEGIN
6390
6391 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start FindVendor');
6392
6393 IF (p_funmode = 'RUN') THEN
6394
6395 ----------------------------------------------------------------
6396 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
6397 ------------------------------------------------------------
6398 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
6399 p_item_key,
6400 'EXPENSE_REPORT_ID');
6401
6402 ----------------------------------------------------------------
6403 l_debug_info := 'Retrieve Vendor IDs from the table';
6404 ------------------------------------------------------------
6405 IF (NOT AP_WEB_DB_CCARD_PKG.GetVendorIDs(l_report_header_id, l_vendor_id,
6406 l_vendor_site_id)) THEN
6407 l_vendor_id := NULL;
6408 l_vendor_site_id := NULL;
6409 END IF;
6410
6411 ----------------------------------------------------------------
6412 l_debug_info := 'Set the Vendor ID Attribute';
6413 ----------------------------------------------------------------
6414 WF_ENGINE.SetItemAttrNumber(p_item_type,
6415 p_item_key,
6416 'VENDOR_ID',
6417 l_vendor_id);
6418
6419 ----------------------------------------------------------------
6420 l_debug_info := 'Set the Vendor Site ID Attribute';
6421 ----------------------------------------------------------------
6422 WF_ENGINE.SetItemAttrNumber(p_item_type,
6423 p_item_key,
6424 'VENDOR_SITE_ID',
6425 l_vendor_site_id);
6426 IF (NOT AP_WEB_DB_EXPLINE_PKG.GetNumCCLinesIncluded(l_report_header_id,
6427 l_crd_card_count)) THEN
6428 l_crd_card_count := 0;
6429 END IF;
6430
6431 IF ( (l_vendor_id IS NULL OR l_vendor_site_id IS NULL)
6432 AND nvl(l_crd_card_count,0) >0 ) THEN
6433 ----------------------------------------------------------------
6434 l_debug_info := 'Get the FND message for this missing vendor';
6435 ----------------------------------------------------------------
6436 FND_MESSAGE.Set_Name('SQLAP','AP_WEB_CCARD_NO_VENDOR_INFO');
6437
6438 ----------------------------------------------------------------
6439 l_debug_info := 'Set the Error Message Attribute';
6440 ----------------------------------------------------------------
6441 WF_ENGINE.SetItemAttrText(p_item_type,
6442 p_item_key,
6443 'ERROR_MESSAGE',
6444 FND_MESSAGE.Get);
6445 p_result := 'COMPLETE:N';
6446 ELSE
6447 p_result := 'COMPLETE:Y';
6448 END IF;
6449
6450 ELSIF (p_funmode = 'CANCEL') THEN
6451 p_result := 'COMPLETE';
6452 END IF;
6453
6454 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end FindVendor');
6455
6456 EXCEPTION
6457 WHEN OTHERS THEN
6458 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'FindVendor',
6459 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
6460 raise;
6461 END FindVendor;
6462
6463
6464 ----------------------------------------------------------------------
6465 PROCEDURE CheckIfSplit(p_item_type IN VARCHAR2,
6466 p_item_key IN VARCHAR2,
6467 p_actid IN NUMBER,
6468 p_funmode IN VARCHAR2,
6469 p_result OUT NOCOPY VARCHAR2) IS
6470 ----------------------------------------------------------------------
6471 l_doc_num VARCHAR2(50);
6472 l_debug_info VARCHAR2(200);
6473 BEGIN
6474
6475 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start CheckIfSplit');
6476
6477 IF (p_funmode = 'RUN') THEN
6478
6479 /* Bug 4096880 : The Bothpay split notification should not be
6480 * sent from OIE.J onwards. Hence, hard-code the
6481 * return value as 'N'.
6482 */
6483
6484 p_result := 'COMPLETE:N';
6485
6486 ELSIF (p_funmode = 'CANCEL') THEN
6487 p_result := 'COMPLETE';
6488 END IF;
6489
6490 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end CheckIfSplit');
6491
6492 EXCEPTION
6493 WHEN OTHERS THEN
6494 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'CheckIfSplit',
6495 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
6496 raise;
6497 END CheckIfSplit;
6498
6499 ----------------------------------------------------------------
6500 PROCEDURE StartPolicyShortPayProcess(p_item_type IN VARCHAR2,
6501 p_item_key IN VARCHAR2,
6502 p_actid IN NUMBER,
6503 p_funmode IN VARCHAR2,
6504 p_result OUT NOCOPY VARCHAR2) IS
6505 -----------------------------------------------------------------
6506 l_item_type VARCHAR2(100) := 'APEXP'; -- Bug 996020
6507 l_item_key VARCHAR2(100);
6508 l_preparer_id NUMBER;
6509 l_preparer_name wf_users.name%type;
6510 l_preparer_display_name wf_users.display_name%type;
6511 l_employee_id NUMBER;
6512 l_employee_name wf_users.name%type;
6513 l_employee_display_name wf_users.display_name%type;
6514 l_orig_expense_report_num VARCHAR2(50);
6515 l_report_header_id NUMBER;
6516 l_document_number VARCHAR2(50);
6517 l_emp_cost_center VARCHAR2(240);
6518 l_doc_cost_center VARCHAR2(240);
6519 l_total NUMBER;
6520 l_credit_total NUMBER;
6521 l_new_exp_total NUMBER;
6522 l_currency VARCHAR2(25);
6523 l_url VARCHAR2(1000);
6524 l_debug_info VARCHAR2(200);
6525 l_payment_due VARCHAR2(10) := C_IndividualPay;
6526
6527 l_purpose VARCHAR2(2400);
6528 l_approver_id NUMBER;
6529 l_approver_name wf_users.name%type;
6530 l_approver_display_name wf_users.display_name%type;
6531 l_submit_from_oie VARCHAR2(1);
6532
6533 C_CreditLineVersion CONSTANT NUMBER := 1;
6534 C_WF_Version NUMBER := 0;
6535
6536 -- for bug 1652106
6537 l_n_org_id NUMBER;
6538 l_n_user_id Number;
6539 l_n_resp_id Number;
6540 l_n_resp_appl_id Number;
6541
6542 -- for bug 2069362
6543 l_AMEEnabled VARCHAR2(1);
6544
6545 -- jrautiai ADJ Fix
6546 l_mess Wf_Item_Attribute_Values.TEXT_VALUE%TYPE;
6547 BEGIN
6548
6549 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start StartPolicyShortPayProcess');
6550
6551 -----------------------------------------------------
6552 l_debug_info := 'Get Workflow Version Number 4';
6553 -----------------------------------------------------
6554 C_WF_Version := GetFlowVersion(p_item_type, p_item_key);
6555
6556 ----------------------------------
6557 l_debug_info := 'Set Org Context';
6558 ----------------------------------
6559 -- for bug 1652106
6560 begin
6561
6562 l_n_org_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
6563 p_item_key,
6564 'ORG_ID');
6565 exception
6566 when others then
6567 if (wf_core.error_name = 'WFENG_ITEM_ATTR') then
6568 -- ORG_ID item attribute doesn't exist, need to add it
6569 wf_engine.AddItemAttr(p_item_type, p_item_key, 'ORG_ID');
6570 -- get the org_id from header for old reports
6571 IF (AP_WEB_DB_EXPRPT_PKG.GetOrgIdByReportHeaderId(
6572 to_number(p_item_key),
6573 l_n_org_id) <> TRUE ) THEN
6574 l_n_org_id := NULL;
6575 END IF;
6576 WF_ENGINE.SetItemAttrNumber(p_item_type,
6577 p_item_key,
6578 'ORG_ID',
6579 l_n_org_id);
6580 else
6581 raise;
6582 end if;
6583
6584 end;
6585
6586
6587 ----------------------------------
6588 l_debug_info := 'Get User ID';
6589 ----------------------------------
6590 begin
6591 l_n_user_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
6592 p_item_key,
6593 'USER_ID');
6594 l_n_resp_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
6595 p_item_key,
6596 'RESPONSIBILITY_ID');
6597 l_n_resp_appl_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
6598 p_item_key,
6599 'APPLICATION_ID');
6600 exception
6601 when others then
6602 if (wf_core.error_name = 'WFENG_ITEM_ATTR') then
6603 null;
6604 else
6605 raise;
6606 end if;
6607 end;
6608
6609 ------------------------------------------------------------
6610 l_debug_info := 'Retrieve New Expense_Report_ID Item Attribute';
6611 ------------------------------------------------------------
6612 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
6613 p_item_key,
6614 'POLICY_SHORTPAY_ID');
6615
6616 --------------------------------------------------------------
6617 l_debug_info := 'Retrieve New Document Number Item Attribute';
6618 ---------------------------------------------------------------
6619 l_document_number := WF_ENGINE.GetItemAttrText(p_item_type,
6620 p_item_key,
6621 'POLICY_SHORTPAY_DOC_NUM');
6622
6623 --------------------------------------------------------------
6624 l_debug_info := 'Retrieve New Document Number Item Attribute';
6625 ---------------------------------------------------------------
6626 l_orig_expense_report_num := WF_ENGINE.GetItemAttrText(p_item_type,
6627 p_item_key,
6628 'DOCUMENT_NUMBER');
6629
6630
6631 ----------------------------------------------------------------
6632 l_debug_info := 'Retrieve Employee Cost Center Item Attribute';
6633 ----------------------------------------------------------------
6634 l_emp_cost_center := WF_ENGINE.GetItemAttrText(p_item_type,
6635 p_item_key,
6636 'EMP_COST_CENTER');
6637
6638 ----------------------------------------------------------------
6639 l_debug_info := 'Retrieve Payment Due From Item Attribute';
6640 ----------------------------------------------------------------
6641 l_payment_due := WF_ENGINE.GetItemAttrText(p_item_type,p_item_key,'PAYMENT_DUE_FROM');
6642
6643
6644 ----------------------------------------------------------------
6645 l_debug_info := 'Retrieve Document Cost Center Item Attribute';
6646 ----------------------------------------------------------------
6647 l_doc_cost_center := WF_ENGINE.GetItemAttrText(p_item_type,
6648 p_item_key,
6649 'DOC_COST_CENTER');
6650
6651 -----------------------------------------------------
6652 l_debug_info := 'Retrieve New Total Item Attribute';
6653 -----------------------------------------------------
6654 l_total := WF_ENGINE.GetItemAttrNumber(p_item_type,
6655 p_item_key,
6656 'POLICY_SHORTPAY_TOTAL');
6657
6658 l_new_exp_total := l_total;
6659 l_credit_total := 0;
6660
6661 -----------------------------------------------------
6662 l_debug_info := 'Retrieve Currency Item Attribute';
6663 -----------------------------------------------------
6664 l_currency := WF_ENGINE.GetItemAttrText(p_item_type,
6665 p_item_key,
6666 'CURRENCY');
6667
6668 --------------------------------
6669 l_debug_info := 'Set item key';
6670 --------------------------------
6671 l_item_key := to_char(l_report_header_id);
6672
6673
6674 -------------------------------------------------------
6675 l_debug_info := 'Retrieve Preparer_ID Item Attribute';
6676 -------------------------------------------------------
6677 l_preparer_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
6678 p_item_key,
6679 'PREPARER_ID');
6680
6681 -------------------------------------------------------
6682 l_debug_info := 'Retrieve Employee_ID Item Attribute';
6683 -------------------------------------------------------
6684 l_employee_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
6685 p_item_key,
6686 'EMPLOYEE_ID');
6687
6688 ----------------------------------
6689 l_debug_info := 'Get AME_ENABLED';
6690 ----------------------------------
6691 l_AMEEnabled := WF_ENGINE.GetItemAttrText(p_item_type,
6692 p_item_key,
6693 'AME_ENABLED');
6694
6695 ----------------------------------
6696 l_debug_info := 'Get PURPOSE';
6697 ----------------------------------
6698 l_purpose := WF_ENGINE.GetItemAttrText(p_item_type,
6699 p_item_key,
6700 'PURPOSE');
6701
6702 ------------------------------------------------------------
6703 l_debug_info := 'Get Approver Info';
6704 ------------------------------------------------------------
6705 l_approver_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
6706 p_item_key,
6707 'APPROVER_ID');
6708
6709 l_approver_name := WF_ENGINE.GetItemAttrText(p_item_type,
6710 p_item_key,
6711 'APPROVER_NAME');
6712
6713 l_approver_display_name := WF_ENGINE.GetItemAttrText(p_item_type,
6714 p_item_key,
6715 'APPROVER_DISPLAY_NAME');
6716
6717 ----------------------------------
6718 l_debug_info := 'Get SUBMIT_FROM_OIE';
6719 ----------------------------------
6720 l_submit_from_oie := WF_ENGINE.GetItemAttrText(p_item_type,
6721 p_item_key,
6722 'SUBMIT_FROM_OIE');
6723
6724 -------------------------------------------------
6725 l_debug_info := 'Create Policy Violation Shortpay Subprocess';
6726 -------------------------------------------------
6727 WF_ENGINE.CreateProcess(p_item_type,
6728 l_item_key,
6729 'POLICY_VIOLATION_PROCESS');
6730
6731 /* Bug 2351528. Need to set the user_key for easier query */
6732 WF_ENGINE.SetItemUserKey(l_item_type,
6733 l_item_key,
6734 l_document_number);
6735
6736 ----------------------------------------------------
6737 l_debug_info := 'Set SUBMIT_FROM_OIE Item Attribute';
6738 ----------------------------------------------------
6739 WF_ENGINE.SetItemAttrText(l_item_type,
6740 l_item_key,
6741 'SUBMIT_FROM_OIE',
6742 l_submit_from_oie);
6743
6744 ------------------------------------------------------
6745 l_debug_info := 'Set PURPOSE Item Attribute';
6746 ------------------------------------------------------
6747 WF_ENGINE.SetItemAttrText(l_item_type,
6748 l_item_key,
6749 'PURPOSE',
6750 l_purpose);
6751
6752 ------------------------------------------------------
6753 l_debug_info := 'Set Approver Info';
6754 ------------------------------------------------------
6755 WF_ENGINE.SetItemAttrNumber(l_item_type,
6756 l_item_key,
6757 'APPROVER_ID',
6758 l_approver_id);
6759
6760 WF_ENGINE.SetItemAttrText(l_item_type,
6761 l_item_key,
6762 'APPROVER_NAME',
6763 l_approver_name);
6764
6765 WF_ENGINE.SetItemAttrText(l_item_type,
6766 l_item_key,
6767 'APPROVER_DISPLAY_NAME',
6768 l_approver_display_name);
6769
6770
6771 -- Bug 996020
6772 ------------------------------------------------------
6773 l_debug_info := 'Set LINE_TABLE Item Attribute';
6774 ------------------------------------------------------
6775 WF_ENGINE.SetItemAttrText(l_item_type,
6776 l_item_key,
6777 'LINE_TABLE',
6778 'plsqlclob:AP_WEB_EXPENSE_WF.generateExpClobLines/'||l_item_type||':'||l_item_key);
6779
6780 ------------------------------------------------------
6781 l_debug_info := 'Set EMP_LINE_TABLE Item Attribute';
6782 ------------------------------------------------------
6783 WF_ENGINE.SetItemAttrText(l_item_type,
6784 l_item_key,
6785 'EMP_LINE_TABLE',
6786 'plsqlclob:AP_WEB_EXPENSE_WF.generateExpClobLines/'||l_item_type||':'||l_item_key || ':'|| C_EMP);
6787
6788 --------------------------------------------------------
6789 l_debug_info := 'Set Expense_Report_ID Item Attribute';
6790 --------------------------------------------------------
6791 WF_ENGINE.SetItemAttrNumber(p_item_type,
6792 l_item_key,
6793 'EXPENSE_REPORT_ID',
6794 l_report_header_id);
6795
6796 ------------------------------------------------------
6797 l_debug_info := 'Set Document_Number Item Attribute';
6798 ------------------------------------------------------
6799 WF_ENGINE.SetItemAttrText(p_item_type,
6800 l_item_key,
6801 'DOCUMENT_NUMBER',
6802 l_document_number);
6803
6804 ------------------------------------------------------
6805 l_debug_info := 'Set Document_Number Item Attribute';
6806 ------------------------------------------------------
6807 WF_ENGINE.SetItemAttrText(p_item_type,
6808 l_item_key,
6809 'ORIG_EXPENSE_REPORT_NUM',
6810 l_orig_expense_report_num);
6811
6812 ----------------------------------------------------------
6813 l_debug_info := 'Get Preparer Name Info For Preparer_Id';
6814 ----------------------------------------------------------
6815 WF_DIRECTORY.GetUserName('PER',
6816 l_preparer_id,
6817 l_preparer_name,
6818 l_preparer_display_name);
6819
6820 WF_ENGINE.SetItemAttrText(p_item_type,
6821 l_item_key,
6822 'PREPARER_ID',
6823 l_preparer_id);
6824
6825 ----------------------------------------------------------
6826 l_debug_info := 'Set Preparer Name Info Item Attributes';
6827 ----------------------------------------------------------
6828 WF_ENGINE.SetItemAttrText(p_item_type,
6829 l_item_key,
6830 'PREPARER_NAME',
6831 l_preparer_name);
6832
6833 WF_ENGINE.SetItemAttrText(p_item_type,
6834 l_item_key,
6835 'PREPARER_DISPLAY_NAME',
6836 l_preparer_display_name);
6837
6838 ----------------------------------------------------------
6839 l_debug_info := 'Set the Owner of Workflow Process.';
6840 ----------------------------------------------------------
6841 WF_ENGINE.SetItemOwner(p_item_type, l_item_key, l_preparer_name);
6842
6843 ----------------------------------------------------------
6844 l_debug_info := 'Get Employee Name Info For Employee_Id';
6845 ----------------------------------------------------------
6846 WF_DIRECTORY.GetUserName('PER',
6847 l_employee_id,
6848 l_employee_name,
6849 l_employee_display_name);
6850
6851 WF_ENGINE.SetItemAttrText(p_item_type,
6852 l_item_key,
6853 'EMPLOYEE_ID',
6854 l_employee_id);
6855
6856 ----------------------------------------------------------
6857 l_debug_info := 'Set Employee Name Info Item Attributes';
6858 ----------------------------------------------------------
6859 WF_ENGINE.SetItemAttrText(p_item_type,
6860 l_item_key,
6861 'EMPLOYEE_NAME',
6862 l_employee_name);
6863
6864 WF_ENGINE.SetItemAttrText(p_item_type,
6865 l_item_key,
6866 'EMPLOYEE_DISPLAY_NAME',
6867 l_employee_display_name);
6868
6869 -------------------------------------------------
6870 l_debug_info := 'Set Total Item Attribute';
6871 -------------------------------------------------
6872 WF_ENGINE.SetItemAttrNumber(p_item_type,
6873 l_item_key,
6874 'TOTAL',
6875 l_total);
6876
6877 -----------------------------------------------------------------
6878 l_debug_info := 'Set New Adjusted Display_Total Item Attribute';
6879 -----------------------------------------------------------------
6880 WF_ENGINE.SetItemAttrText(p_item_type,
6881 l_item_key,
6882 'DISPLAY_TOTAL',
6883 to_char(l_total,FND_CURRENCY.Get_Format_Mask(l_currency,22)) || ' ' || l_currency);
6884
6885
6886
6887
6888 ---------------------------------------------------------------------------
6889 l_debug_info := 'Set Attribute value for Credit Total and New Expense Total';
6890 ---------------------------------------------------------------------------
6891
6892 IF (C_WF_Version >= C_CreditLineVersion) THEN
6893
6894 WF_ENGINE.SetItemAttrNumber(p_item_type,
6895 l_item_key,
6896 'POS_NEW_EXPENSE_TOTAL',
6897 l_new_exp_total);
6898 WF_ENGINE.SetItemAttrText(p_item_type,
6899 l_item_key,
6900 'POS_NEW_EXPENSE_DISPLAY_TOTAL',
6901 to_char(l_new_exp_total, FND_CURRENCY.Get_Format_Mask(l_currency,22)));
6902
6903 WF_ENGINE.SetItemAttrNumber(p_item_type,
6904 l_item_key,
6905 'NEG_CREDIT_TOTAL',
6906 l_credit_total);
6907 WF_ENGINE.SetItemAttrText(p_item_type,
6908 l_item_key,
6909 'NEG_CREDIT_DISPLAY_TOTAL',
6910 to_char(l_credit_total, FND_CURRENCY.Get_Format_Mask(l_currency,22)));
6911
6912
6913
6914 END IF;
6915
6916 ----------------------------------------------
6917 l_debug_info := 'Set Currency Item Attribute';
6918 -----------------------------------------------
6919 WF_ENGINE.SetItemAttrText(p_item_type,
6920 l_item_key,
6921 'CURRENCY',
6922 l_currency);
6923
6924
6925 -----------------------------------------------------------
6926 l_debug_info := 'Set Document Cost Center Item Attribute';
6927 -----------------------------------------------------------
6928 WF_ENGINE.SetItemAttrText(p_item_type,
6929 l_item_key,
6930 'DOC_COST_CENTER',
6931 l_doc_cost_center);
6932
6933 -----------------------------------------------------------
6934 l_debug_info := 'Set Employee Cost Center Item Attribute';
6935 -----------------------------------------------------------
6936 WF_ENGINE.SetItemAttrText(p_item_type,
6937 l_item_key,
6938 'EMP_COST_CENTER',
6939 l_emp_cost_center);
6940
6941 --------------------------------------------------------------
6942 l_debug_info := 'Set CC Payment Due From Item Attribute';
6943 --------------------------------------------------------------
6944 WF_ENGINE.SetItemAttrText(p_item_type,
6945 l_item_key,
6946 'PAYMENT_DUE_FROM',
6947 l_payment_due);
6948
6949 --------------------------------------------------------
6950 l_debug_info := 'Call JumpIntoFunction to retrieve URL';
6951 --------------------------------------------------------
6952 AP_WEB_INFRASTRUCTURE_PKG.JumpIntoFunction(l_report_header_id,
6953 'EXPENSE REPORT',
6954 l_url);
6955
6956 -----------------------------------------------------
6957 l_debug_info := 'Set EXPENSE DETAILS Item Attribute';
6958 -----------------------------------------------------
6959
6960 -- Be sure to clear these values. If we are resubmitting, we don't want
6961 -- the values from the previous process traversal to hang around.
6962 WF_ENGINE.SetItemAttrText(p_item_type,
6963 l_item_key,
6964 'EXPENSE_DETAILS',
6965 l_url);
6966
6967 -----------------------------------------------------
6968 l_debug_info := 'Set Org ID Item Attribute';
6969 -----------------------------------------------------
6970 begin
6971 WF_ENGINE.SetItemAttrNumber(p_item_type,
6972 l_item_key,
6973 'ORG_ID',
6974 l_n_org_id);
6975 exception
6976 when others then
6977 if (wf_core.error_name = 'WFENG_ITEM_ATTR') then
6978 -- ORG_ID item attribute doesn't exist, need to add it
6979 wf_engine.AddItemAttr(p_item_type, l_item_key, 'ORG_ID');
6980 -- get the org_id from header for old reports
6981 WF_ENGINE.SetItemAttrNumber(p_item_type,
6982 l_item_key,
6983 'ORG_ID',
6984 l_n_org_id);
6985 else
6986 raise;
6987 end if;
6988 end;
6989
6990
6991 begin
6992
6993 --------------------------------------------------------------
6994 l_debug_info := 'Set User_ID value ';
6995 --------------------------------------------------------------
6996 WF_ENGINE.SetItemAttrNumber(p_item_type,
6997 l_item_key,
6998 'USER_ID',
6999 l_n_user_id);
7000
7001
7002 --------------------------------------------------------------
7003 l_debug_info := 'Set Resp_ID value ';
7004 --------------------------------------------------------------
7005 WF_ENGINE.SetItemAttrNumber(p_item_type,
7006 l_item_key,
7007 'RESPONSIBILITY_ID',
7008 l_n_resp_id);
7009
7010 --------------------------------------------------------------
7011 l_debug_info := 'Set Resp_Appl_ID value ';
7012 --------------------------------------------------------------
7013 WF_ENGINE.SetItemAttrNumber(p_item_type,
7014 l_item_key,
7015 'APPLICATION_ID',
7016 l_n_resp_appl_id);
7017
7018 exception
7019 when others then
7020 if (wf_core.error_name = 'WFENG_ITEM_ATTR') then
7021 null;
7022 else
7023 raise;
7024 end if;
7025 end;
7026
7027 --------------------------------------------------------------
7028 l_debug_info := 'Set AME_ENABLED value ';
7029 --------------------------------------------------------------
7030 WF_ENGINE.SetItemAttrText(p_item_type,
7031 l_item_key,
7032 'AME_ENABLED',
7033 l_AMEEnabled);
7034
7035 /* jrautiai ADJ Fix Start */
7036 ----------------------------------------------------------------
7037 l_debug_info := 'Set #FROM_ROLE to AP';
7038 ----------------------------------------------------------------
7039 SetFromRoleAP(p_item_type, l_item_key, p_actid, p_funmode, p_result);
7040
7041 FND_MESSAGE.SET_NAME('SQLAP','OIE_WF_POLICY_NC_NOTE');
7042
7043 FND_MESSAGE.Set_Token('ORIG_REPORT_NUMBER', l_orig_expense_report_num);
7044 l_mess := FND_MESSAGE.GET;
7045
7046 ----------------------------------------------------------------
7047 l_debug_info := 'Set Policy Non-Compliance note';
7048 ----------------------------------------------------------------
7049 WF_ENGINE.SetItemAttrText(p_item_type,
7050 l_item_key,
7051 'WF_NOTE',
7052 l_mess);
7053
7054 /* jrautiai ADJ Fix End */
7055
7056 -------------------------------------------------
7057 l_debug_info := 'Start Policy Violation Shortpay Process';
7058 -------------------------------------------------
7059 WF_ENGINE.StartProcess(p_item_type,
7060 l_item_key);
7061 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end StartPolicyShortPayProcess');
7062
7063 EXCEPTION
7064 WHEN OTHERS THEN
7065 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'StartPolicyShortPayProcess',
7066 p_item_type, l_item_key, to_char(p_actid), l_debug_info);
7067 raise;
7068 END StartPolicyShortPayProcess;
7069
7070 ----------------------------------------------------------------
7071 PROCEDURE StartNoReceiptsShortPayProcess(p_item_type IN VARCHAR2,
7072 p_item_key IN VARCHAR2,
7073 p_actid IN NUMBER,
7074 p_funmode IN VARCHAR2,
7075 p_result OUT NOCOPY VARCHAR2) IS
7076 -----------------------------------------------------------------
7077 l_item_type VARCHAR2(100) := 'APEXP'; -- Bug 996020
7078
7079 l_item_key VARCHAR2(100);
7080 l_preparer_id NUMBER;
7081 l_preparer_name wf_users.name%type;
7082 l_preparer_display_name wf_users.display_name%type;
7083 l_employee_id NUMBER;
7084 l_employee_name wf_users.name%type;
7085 l_employee_display_name wf_users.display_name%type;
7086 l_report_header_id NUMBER;
7087 l_document_number VARCHAR2(50);
7088 l_orig_expense_report_num VARCHAR2(50);
7089 l_emp_cost_center VARCHAR2(240);
7090 l_doc_cost_center VARCHAR2(240);
7091 l_override_approver_id AP_WEB_DB_EXPRPT_PKG.expHdr_overrideApprID;
7092 l_approver_name wf_users.name%type;
7093 l_approver_display_name wf_users.display_name%type;
7094 l_total NUMBER;
7095 l_credit_total NUMBER;
7096 l_new_exp_total NUMBER;
7097 l_currency VARCHAR2(25);
7098 l_url VARCHAR2(1000);
7099 l_debug_info VARCHAR2(200);
7100 V_IsSessionProjectEnabled VARCHAR2(1);
7101 l_payment_due VARCHAR2(10) := C_IndividualPay;
7102
7103 l_purpose VARCHAR2(2400);
7104 l_approver_id NUMBER;
7105 l_submit_from_oie VARCHAR2(1);
7106
7107 C_CreditLineVersion CONSTANT NUMBER := 1;
7108 C_WF_Version NUMBER := 0;
7109
7110 -- for bug 1652106
7111 l_n_org_id NUMBER;
7112 l_n_user_id Number;
7113 l_n_resp_id Number;
7114 l_n_resp_appl_id Number;
7115
7116 -- for bug 2069362
7117 l_AMEEnabled VARCHAR2(1);
7118
7119 -- jrautiai ADJ Fix
7120 l_mess Wf_Item_Attribute_Values.TEXT_VALUE%TYPE;
7121 l_missing_receipt_type VARCHAR2(50);
7122 BEGIN
7123
7124 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start StartNoReceiptsShortPayProcess');
7125
7126 -- Bug 14134416: To handle 'MISSING_RECEIPT_TYPE' error for the upgraded expense reports
7127 BEGIN
7128 l_missing_receipt_type := WF_ENGINE.GetActivityAttrText(p_item_type,
7129 p_item_key,
7130 p_actid,
7131 'MISSING_RECEIPT_TYPE');
7132
7133 EXCEPTION
7134 WHEN OTHERS THEN
7135 if (wf_core.error_name = 'WFENG_ACTIVITY_ATTR') then
7136 l_missing_receipt_type := 'ORIGINAL';
7137 else
7138 raise;
7139 end if;
7140 END;
7141 -----------------------------------------------------
7142 l_debug_info := 'Get Workflow Version Number 5';
7143 -----------------------------------------------------
7144 C_WF_Version := GetFlowVersion(p_item_type, p_item_key);
7145
7146 --------------------------------------------------------------
7147 l_debug_info := 'Retrieve New Document Number Item Attribute';
7148 ---------------------------------------------------------------
7149 l_orig_expense_report_num := WF_ENGINE.GetItemAttrText(p_item_type,
7150 p_item_key,
7151 'DOCUMENT_NUMBER');
7152 ------------------------------------------------------------
7153 l_debug_info := 'Retrieve New Expense_Report_ID Item Attribute';
7154 ------------------------------------------------------------
7155 IF (l_missing_receipt_type = 'ORIGINAL') THEN
7156 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
7157 p_item_key,
7158 'NO_RECEIPTS_SHORTPAY_ID');
7159
7160 --------------------------------------------------------------
7161 l_debug_info := 'Retrieve New Document Number Item Attribute';
7162 ---------------------------------------------------------------
7163 l_document_number := WF_ENGINE.GetItemAttrText(p_item_type,
7164 p_item_key,
7165 'NO_RECEIPTS_SHORTPAY_DOC_NUM');
7166
7167 -----------------------------------------------------
7168 l_debug_info := 'Retrieve New Total Item Attribute';
7169 -----------------------------------------------------
7170 l_total := WF_ENGINE.GetItemAttrNumber(p_item_type,
7171 p_item_key,
7172 'NO_RECEIPTS_SHORTPAY_TOTAL');
7173
7174 FND_MESSAGE.SET_NAME('SQLAP','OIE_WF_POLICY_MR_NOTE');
7175
7176 FND_MESSAGE.Set_Token('ORIG_REPORT_NUMBER', l_orig_expense_report_num);
7177 l_mess := FND_MESSAGE.GET;
7178
7179 ELSIF (l_missing_receipt_type = 'IMAGE') THEN
7180
7181 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
7182 p_item_key,
7183 'NO_IMG_RECEIPTS_SHORTPAY_ID');
7184
7185 --------------------------------------------------------------
7186 l_debug_info := 'Retrieve New Document Number Item Attribute';
7187 ---------------------------------------------------------------
7188 l_document_number := WF_ENGINE.GetItemAttrText(p_item_type,
7189 p_item_key,
7190 'NO_IMG_RECPT_SHORTPAY_DOC_NUM');
7191
7192 l_total := WF_ENGINE.GetItemAttrNumber(p_item_type,
7193 p_item_key,
7194 'NO_IMG_RECPT_SHORTPAY_TOTAL');
7195
7196 FND_MESSAGE.SET_NAME('SQLAP','OIE_MISSING_RECPT_NOTIF_INSTR');
7197
7198 FND_MESSAGE.Set_Token('RPT_ID', l_orig_expense_report_num);
7199 l_mess := FND_MESSAGE.GET;
7200
7201 ELSE
7202 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
7203 p_item_key,
7204 'NO_BOTH_RECEIPTS_SHORTPAY_ID');
7205
7206 --------------------------------------------------------------
7207 l_debug_info := 'Retrieve New Document Number Item Attribute';
7208 ---------------------------------------------------------------
7209 l_document_number := WF_ENGINE.GetItemAttrText(p_item_type,
7210 p_item_key,
7211 'NO_BOTH_RECPT_SHORTPAY_DOC_NUM');
7212
7213 l_total := WF_ENGINE.GetItemAttrNumber(p_item_type,
7214 p_item_key,
7215 'NO_BOTH_RECPT_SHORTPAY_TOTAL');
7216
7217 FND_MESSAGE.SET_NAME('SQLAP','OIE_MISSING_RECPT_NOTIF_INSTR');
7218
7219 FND_MESSAGE.Set_Token('RPT_ID', l_orig_expense_report_num);
7220 l_mess := FND_MESSAGE.GET;
7221 END IF;
7222
7223
7224
7225 ----------------------------------------------------------------
7226 l_debug_info := 'Retrieve Employee Cost Center Item Attribute';
7227 ----------------------------------------------------------------
7228 l_emp_cost_center := WF_ENGINE.GetItemAttrText(p_item_type,
7229 p_item_key,
7230 'EMP_COST_CENTER');
7231
7232 ----------------------------------------------------------------
7233 l_debug_info := 'Retrieve Document Cost Center Item Attribute';
7234 ----------------------------------------------------------------
7235 l_doc_cost_center := WF_ENGINE.GetItemAttrText(p_item_type,
7236 p_item_key,
7237 'DOC_COST_CENTER');
7238
7239
7240
7241 l_new_exp_total := l_total;
7242 l_credit_total := 0;
7243
7244 -----------------------------------------------------
7245 l_debug_info := 'Retrieve Currency Item Attribute';
7246 -----------------------------------------------------
7247 l_currency := WF_ENGINE.GetItemAttrText(p_item_type,
7248 p_item_key,
7249 'CURRENCY');
7250
7251 --------------------------------
7252 l_debug_info := 'Set item key';
7253 --------------------------------
7254 l_item_key := to_char(l_report_header_id);
7255
7256
7257 -------------------------------------------------------
7258 l_debug_info := 'Retrieve Preparer_ID Item Attribute';
7259 -------------------------------------------------------
7260 l_preparer_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
7261 p_item_key,
7262 'PREPARER_ID');
7263
7264 -------------------------------------------------------
7265 l_debug_info := 'Retrieve Employee_ID Item Attribute';
7266 -------------------------------------------------------
7267 l_employee_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
7268 p_item_key,
7269 'EMPLOYEE_ID');
7270
7271 ---------------------------------------------------------
7272 l_debug_info := 'Retrieve Payment Due From System Option';
7273 ---------------------------------------------------------
7274 l_payment_due := WF_ENGINE.GetItemAttrText(p_item_type,p_item_key,'PAYMENT_DUE_FROM');
7275
7276 ------------------------------------------------------------
7277 l_debug_info := 'Determine whether session is project enabled';
7278 ------------------------------------------------------------
7279 IF (C_WF_Version >= AP_WEB_EXPENSE_WF.C_11_0_3Version) THEN
7280 V_IsSessionProjectEnabled := WF_ENGINE.GetItemAttrText(p_item_type,
7281 p_item_key,
7282 'EMPLOYEE_PROJECT_ENABLED');
7283
7284 ELSE
7285 -- In previous versions we called
7286 -- AP_WEB_PROJECT_PKG.IsSessionProjectEnabled, but that would not work
7287 -- without having ValidateSession called. So, for older versions we
7288 -- will assume that the session is project enabled. Since the receipts
7289 -- will not have any project information, the patc call will not be done.
7290 V_IsSessionProjectEnabled := 'Y';
7291 END IF;
7292
7293
7294 ----------------------------------
7295 l_debug_info := 'Set Org Context';
7296 ----------------------------------
7297 -- for bug 1652106
7298 begin
7299
7300 l_n_org_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
7301 p_item_key,
7302 'ORG_ID');
7303 exception
7304 when others then
7305 if (wf_core.error_name = 'WFENG_ITEM_ATTR') then
7306 -- ORG_ID item attribute doesn't exist, need to add it
7307 wf_engine.AddItemAttr(p_item_type, p_item_key, 'ORG_ID');
7308 -- get the org_id from header for old reports
7309 IF (AP_WEB_DB_EXPRPT_PKG.GetOrgIdByReportHeaderId(
7310 to_number(p_item_key),
7311 l_n_org_id) <> TRUE ) THEN
7312 l_n_org_id := NULL;
7313 END IF;
7314 WF_ENGINE.SetItemAttrText(p_item_type,
7315 p_item_key,
7316 'ORG_ID',
7317 l_n_org_id);
7318 else
7319 raise;
7320 end if;
7321
7322 end;
7323
7324 ----------------------------------
7325 l_debug_info := 'Get User ID';
7326 ----------------------------------
7327 begin
7328 l_n_user_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
7329 p_item_key,
7330 'USER_ID');
7331 l_n_resp_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
7332 p_item_key,
7333 'RESPONSIBILITY_ID');
7334 l_n_resp_appl_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
7335 p_item_key,
7336 'APPLICATION_ID');
7337 exception
7338 when others then
7339 if (wf_core.error_name = 'WFENG_ITEM_ATTR') then
7340 null;
7341 else
7342 raise;
7343 end if;
7344 end;
7345
7346 ----------------------------------
7347 l_debug_info := 'Get AME_ENABLED';
7348 ----------------------------------
7349 l_AMEEnabled := WF_ENGINE.GetItemAttrText(p_item_type,
7350 p_item_key,
7351 'AME_ENABLED');
7352
7353 ----------------------------------
7354 l_debug_info := 'Get PURPOSE';
7355 ----------------------------------
7356 l_purpose := WF_ENGINE.GetItemAttrText(p_item_type,
7357 p_item_key,
7358 'PURPOSE');
7359
7360 ------------------------------------------------------------
7361 l_debug_info := 'Get Approver Info';
7362 ------------------------------------------------------------
7363 l_approver_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
7364 p_item_key,
7365 'APPROVER_ID');
7366
7367 l_approver_name := WF_ENGINE.GetItemAttrText(p_item_type,
7368 p_item_key,
7369 'APPROVER_NAME');
7370
7371 l_approver_display_name := WF_ENGINE.GetItemAttrText(p_item_type,
7372 p_item_key,
7373 'APPROVER_DISPLAY_NAME');
7374
7375 ----------------------------------
7376 l_debug_info := 'Get SUBMIT_FROM_OIE';
7377 ----------------------------------
7378 l_submit_from_oie := WF_ENGINE.GetItemAttrText(p_item_type,
7379 p_item_key,
7380 'SUBMIT_FROM_OIE');
7381
7382 -------------------------------------------------
7383 l_debug_info := 'Create Missing Receipts Shortpay Subprocess';
7384 -------------------------------------------------
7385 WF_ENGINE.CreateProcess(p_item_type,
7386 l_item_key,
7387 'NO_RECEIPTS_SHORTPAY_PROCESS');
7388
7389 /* Bug 2351528. Need to set the user_key for easier query */
7390 WF_ENGINE.SetItemUserKey(l_item_type,
7391 l_item_key,
7392 l_document_number);
7393
7394 ----------------------------------------------------
7395 l_debug_info := 'Set SUBMIT_FROM_OIE Item Attribute';
7396 ----------------------------------------------------
7397 WF_ENGINE.SetItemAttrText(l_item_type,
7398 l_item_key,
7399 'SUBMIT_FROM_OIE',
7400 l_submit_from_oie);
7401
7402 ------------------------------------------------------
7403 l_debug_info := 'Set PURPOSE Item Attribute';
7404 ------------------------------------------------------
7405 WF_ENGINE.SetItemAttrText(l_item_type,
7406 l_item_key,
7407 'PURPOSE',
7408 l_purpose);
7409
7410 ------------------------------------------------------
7411 l_debug_info := 'Set Approver Info';
7412 ------------------------------------------------------
7413 WF_ENGINE.SetItemAttrNumber(l_item_type,
7414 l_item_key,
7415 'APPROVER_ID',
7416 l_approver_id);
7417
7418 WF_ENGINE.SetItemAttrText(l_item_type,
7419 l_item_key,
7420 'APPROVER_NAME',
7421 l_approver_name);
7422
7423 WF_ENGINE.SetItemAttrText(l_item_type,
7424 l_item_key,
7425 'APPROVER_DISPLAY_NAME',
7426 l_approver_display_name);
7427
7428 -- Bug 996020
7429 ------------------------------------------------------
7430 l_debug_info := 'Set LINE_TABLE Item Attribute';
7431 ------------------------------------------------------
7432 WF_ENGINE.SetItemAttrText(l_item_type,
7433 l_item_key,
7434 'LINE_TABLE',
7435 'plsqlclob:AP_WEB_EXPENSE_WF.generateExpClobLines/'||l_item_type||':'||l_item_key);
7436
7437 ------------------------------------------------------
7438 l_debug_info := 'Set EMP_LINE_TABLE Item Attribute';
7439 ------------------------------------------------------
7440 WF_ENGINE.SetItemAttrText(l_item_type,
7441 l_item_key,
7442 'EMP_LINE_TABLE',
7443 'plsqlclob:AP_WEB_EXPENSE_WF.generateExpClobLines/'||l_item_type||':'||l_item_key || ':'||C_EMP);
7444
7445 --------------------------------------------------------
7446 l_debug_info := 'Set Expense_Report_ID Item Attribute';
7447 --------------------------------------------------------
7448 WF_ENGINE.SetItemAttrNumber(p_item_type,
7449 l_item_key,
7450 'EXPENSE_REPORT_ID',
7451 l_report_header_id);
7452
7453 ------------------------------------------------------
7454 l_debug_info := 'Set Document_Number Item Attribute';
7455 ------------------------------------------------------
7456 WF_ENGINE.SetItemAttrText(p_item_type,
7457 l_item_key,
7458 'DOCUMENT_NUMBER',
7459 l_document_number);
7460
7461 ------------------------------------------------------
7462 l_debug_info := 'Set Document_Number Item Attribute';
7463 ------------------------------------------------------
7464 WF_ENGINE.SetItemAttrText(p_item_type,
7465 l_item_key,
7466 'ORIG_EXPENSE_REPORT_NUM',
7467 l_orig_expense_report_num);
7468
7469 ----------------------------------------------------------
7470 l_debug_info := 'Get Preparer Name Info For Preparer_Id';
7471 ----------------------------------------------------------
7472 WF_DIRECTORY.GetUserName('PER',
7473 l_preparer_id,
7474 l_preparer_name,
7475 l_preparer_display_name);
7476
7477 WF_ENGINE.SetItemAttrText(p_item_type,
7478 l_item_key,
7479 'PREPARER_ID',
7480 l_preparer_id);
7481
7482 ----------------------------------------------------------
7483 l_debug_info := 'Set Preparer Name Info Item Attributes';
7484 ----------------------------------------------------------
7485 WF_ENGINE.SetItemAttrText(p_item_type,
7486 l_item_key,
7487 'PREPARER_NAME',
7488 l_preparer_name);
7489
7490 WF_ENGINE.SetItemAttrText(p_item_type,
7491 l_item_key,
7492 'PREPARER_DISPLAY_NAME',
7493 l_preparer_display_name);
7494
7495 ----------------------------------------------------------
7496 l_debug_info := 'Set the Owner of Workflow Process.';
7497 ----------------------------------------------------------
7498 WF_ENGINE.SetItemOwner(p_item_type, l_item_key, l_preparer_name);
7499
7500 ----------------------------------------------------------
7501 l_debug_info := 'Get Employee Name Info For Employee_Id';
7502 ----------------------------------------------------------
7503 WF_DIRECTORY.GetUserName('PER',
7504 l_employee_id,
7505 l_employee_name,
7506 l_employee_display_name);
7507
7508 WF_ENGINE.SetItemAttrText(p_item_type,
7509 l_item_key,
7510 'EMPLOYEE_ID',
7511 l_employee_id);
7512
7513 ----------------------------------------------------------
7514 l_debug_info := 'Set Employee Name Info Item Attributes';
7515 ----------------------------------------------------------
7516 WF_ENGINE.SetItemAttrText(p_item_type,
7517 l_item_key,
7518 'EMPLOYEE_NAME',
7519 l_employee_name);
7520
7521 WF_ENGINE.SetItemAttrText(p_item_type,
7522 l_item_key,
7523 'EMPLOYEE_DISPLAY_NAME',
7524 l_employee_display_name);
7525
7526 -------------------------------------------------
7527 l_debug_info := 'Set Total Item Attribute';
7528 -------------------------------------------------
7529 WF_ENGINE.SetItemAttrNumber(p_item_type,
7530 l_item_key,
7531 'TOTAL',
7532 l_total);
7533
7534 -----------------------------------------------------------------
7535 l_debug_info := 'Set New Adjusted Display_Total Item Attribute';
7536 -----------------------------------------------------------------
7537 WF_ENGINE.SetItemAttrText(p_item_type,
7538 l_item_key,
7539 'DISPLAY_TOTAL',
7540 to_char(l_total,FND_CURRENCY.Get_Format_Mask(l_currency,22)) || ' ' || l_currency);
7541
7542 --------------------------------------------------------------
7543 l_debug_info := 'Set CC Payment Due From Item Attribute';
7544 --------------------------------------------------------------
7545 WF_ENGINE.SetItemAttrText(p_item_type,
7546 l_item_key,
7547 'PAYMENT_DUE_FROM',
7548 l_payment_due);
7549
7550 ---------------------------------------------------------------------------
7551 l_debug_info := 'Set Attribute value for Credit Total and New Expense Total';
7552 ---------------------------------------------------------------------------
7553
7554 IF (C_WF_Version >= C_CreditLineVersion) THEN
7555
7556 WF_ENGINE.SetItemAttrNumber(p_item_type,
7557 l_item_key,
7558 'POS_NEW_EXPENSE_TOTAL',
7559 l_new_exp_total);
7560 WF_ENGINE.SetItemAttrText(p_item_type,
7561 l_item_key,
7562 'POS_NEW_EXPENSE_DISPLAY_TOTAL',
7563 to_char(l_new_exp_total, FND_CURRENCY.Get_Format_Mask(l_currency,22)));
7564
7565 WF_ENGINE.SetItemAttrNumber(p_item_type,
7566 l_item_key,
7567 'NEG_CREDIT_TOTAL',
7568 l_credit_total);
7569 WF_ENGINE.SetItemAttrText(p_item_type,
7570 l_item_key,
7571 'NEG_CREDIT_DISPLAY_TOTAL',
7572 to_char(l_credit_total, FND_CURRENCY.Get_Format_Mask(l_currency,22)));
7573
7574 END IF;
7575
7576 ---------------------------------------------------------------------------
7577 l_debug_info := 'Set whether employee is project enabled';
7578 ---------------------------------------------------------------------------
7579 IF (C_WF_Version >= AP_WEB_EXPENSE_WF.C_11_0_3Version) THEN
7580
7581 WF_ENGINE.SetItemAttrText(p_item_type,
7582 l_item_key,
7583 'EMPLOYEE_PROJECT_ENABLED',
7584 V_IsSessionProjectEnabled);
7585 END IF;
7586
7587
7588 ----------------------------------------------
7589 l_debug_info := 'Set Currency Item Attribute';
7590 -----------------------------------------------
7591 WF_ENGINE.SetItemAttrText(p_item_type,
7592 l_item_key,
7593 'CURRENCY',
7594 l_currency);
7595
7596
7597 -----------------------------------------------------------
7598 l_debug_info := 'Set Document Cost Center Item Attribute';
7599 -----------------------------------------------------------
7600 WF_ENGINE.SetItemAttrText(p_item_type,
7601 l_item_key,
7602 'DOC_COST_CENTER',
7603 l_doc_cost_center);
7604
7605 -----------------------------------------------------------
7606 l_debug_info := 'Set Employee Cost Center Item Attribute';
7607 -----------------------------------------------------------
7608 WF_ENGINE.SetItemAttrText(p_item_type,
7609 l_item_key,
7610 'EMP_COST_CENTER',
7611 l_emp_cost_center);
7612
7613 --------------------------------------------------------
7614 l_debug_info := 'Call JumpIntoFunction to retrieve URL';
7615 --------------------------------------------------------
7616 AP_WEB_INFRASTRUCTURE_PKG.JumpIntoFunction(l_report_header_id,
7617 'EXPENSE REPORT',
7618 l_url);
7619
7620 -----------------------------------------------------
7621 l_debug_info := 'Set EXPENSE DETAILS Item Attribute';
7622 -----------------------------------------------------
7623
7624 -- Be sure to clear these values. If we are resubmitting, we don't want
7625 -- the values from the previous process traversal to hang around.
7626 WF_ENGINE.SetItemAttrText(p_item_type,
7627 l_item_key,
7628 'EXPENSE_DETAILS',
7629 l_url);
7630
7631
7632 IF (AP_WEB_DB_EXPRPT_PKG.GetOverrideApproverID(to_number(l_item_key),
7633 l_override_approver_id)) THEN
7634
7635 WF_DIRECTORY.GetUserName('PER',
7636 l_override_approver_id,
7637 l_approver_name,
7638 l_approver_display_name);
7639
7640 WF_ENGINE.SetItemAttrNumber(p_item_type,
7641 l_item_key,
7642 'APPROVER_ID',
7643 l_override_approver_id);
7644
7645 WF_ENGINE.SetItemAttrText(p_item_type,
7646 l_item_key,
7647 'APPROVER_NAME',
7648 l_approver_name);
7649
7650 WF_ENGINE.SetItemAttrText(p_item_type,
7651 l_item_key,
7652 'APPROVER_DISPLAY_NAME',
7653 l_approver_display_name);
7654
7655 END IF;
7656
7657 -----------------------------------------------------
7658 l_debug_info := 'Set Org ID Item Attribute';
7659 -----------------------------------------------------
7660 begin
7661 WF_ENGINE.SetItemAttrNumber(p_item_type,
7662 l_item_key,
7663 'ORG_ID',
7664 l_n_org_id);
7665 exception
7666 when others then
7667 if (wf_core.error_name = 'WFENG_ITEM_ATTR') then
7668 -- ORG_ID item attribute doesn't exist, need to add it
7669 wf_engine.AddItemAttr(p_item_type, l_item_key, 'ORG_ID');
7670 -- get the org_id from header for old reports
7671 WF_ENGINE.SetItemAttrNumber(p_item_type,
7672 l_item_key,
7673 'ORG_ID',
7674 l_n_org_id);
7675 else
7676 raise;
7677 end if;
7678 end;
7679
7680 begin
7681
7682 --------------------------------------------------------------
7683 l_debug_info := 'Set User_ID value ';
7684 --------------------------------------------------------------
7685 WF_ENGINE.SetItemAttrNumber(p_item_type,
7686 l_item_key,
7687 'USER_ID',
7688 l_n_user_id);
7689
7690
7691 --------------------------------------------------------------
7692 l_debug_info := 'Set Resp_ID value ';
7693 --------------------------------------------------------------
7694 WF_ENGINE.SetItemAttrNumber(p_item_type,
7695 l_item_key,
7696 'RESPONSIBILITY_ID',
7697 l_n_resp_id);
7698
7699 --------------------------------------------------------------
7700 l_debug_info := 'Set Resp_Appl_ID value ';
7701 --------------------------------------------------------------
7702 WF_ENGINE.SetItemAttrNumber(p_item_type,
7703 l_item_key,
7704 'APPLICATION_ID',
7705 l_n_resp_appl_id);
7706
7707 exception
7708 when others then
7709 if (wf_core.error_name = 'WFENG_ITEM_ATTR') then
7710 null;
7711 else
7712 raise;
7713 end if;
7714 end;
7715
7716 --------------------------------------------------------------
7717 l_debug_info := 'Set AME_ENABLED value ';
7718 --------------------------------------------------------------
7719 WF_ENGINE.SetItemAttrText(p_item_type,
7720 l_item_key,
7721 'AME_ENABLED',
7722 l_AMEEnabled);
7723
7724 /* jrautiai ADJ Fix Start */
7725
7726 ----------------------------------------------------------------
7727 l_debug_info := 'Set #FROM_ROLE to AP';
7728 ----------------------------------------------------------------
7729 SetFromRoleAP(p_item_type, l_item_key, p_actid, p_funmode, p_result);
7730
7731 ----------------------------------------------------------------
7732 l_debug_info := 'Set Missing receipts note';
7733 ----------------------------------------------------------------
7734 WF_ENGINE.SetItemAttrText(p_item_type,
7735 l_item_key,
7736 'WF_NOTE',
7737 l_mess);
7738
7739 /* jrautiai ADJ Fix End */
7740
7741 -------------------------------------------------------
7742 l_debug_info := 'Start No Receipts Short Pay Process';
7743 -------------------------------------------------------
7744 WF_ENGINE.StartProcess(p_item_type,
7745 l_item_key);
7746
7747
7748 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end StartNoReceiptsShortPayProcess');
7749
7750 EXCEPTION
7751 WHEN OTHERS THEN
7752 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'StartNoReceiptsShortPayProcess',
7753 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
7754 raise;
7755 END StartNoReceiptsShortPayProcess;
7756
7757 ---------------------------------------------------------------------
7758 PROCEDURE StartManagerApprvlSubProcess(p_item_type IN VARCHAR2,
7759 p_item_key IN VARCHAR2,
7760 p_actid IN NUMBER,
7761 p_funmode IN VARCHAR2,
7762 p_result OUT NOCOPY VARCHAR2) IS
7763 ---------------------------------------------------------------------
7764 l_item_key VARCHAR2(100);
7765 l_preparer_id NUMBER;
7766 l_preparer_name wf_users.name%type;
7767 l_preparer_display_name wf_users.display_name%type;
7768 l_employee_id NUMBER;
7769 l_employee_name wf_users.name%type;
7770 l_employee_display_name wf_users.display_name%type;
7771 l_report_header_id AP_WEB_DB_EXPLINE_PKG.expLines_headerID;
7772 l_document_number VARCHAR2(50);
7773 l_total NUMBER;
7774 l_emp_cost_center VARCHAR2(240);
7775 l_doc_cost_center VARCHAR2(240);
7776 l_currency VARCHAR2(50);
7777 l_week_end_date DATE;
7778 l_debug_info VARCHAR2(200);
7779 l_payment_due VARCHAR2(10) := C_IndividualPay;
7780
7781 C_WF_VERSION NUMBER;
7782
7783 BEGIN
7784
7785 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start StartManagerApprvlSubProcess');
7786
7787 ----------------------------------------------------------------
7788 l_debug_info := 'Get the version of the workflow currently using';
7789 ----------------------------------------------------------------
7790 C_WF_VERSION := GetFlowVersion(p_item_type, p_item_key);
7791
7792 ----------------------------------------------------------------
7793 l_debug_info := 'Retrieve New_Expense_Report_ID Item Attribute';
7794 ----------------------------------------------------------------
7795 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
7796 p_item_key,
7797 'NEW_EXPENSE_REPORT_ID');
7798
7799
7800 --------------------------------------------------------------
7801 l_debug_info := 'Update all expense lines as receipt missing';
7802 --------------------------------------------------------------
7803 IF (NOT AP_WEB_DB_EXPLINE_PKG.SetReceiptMissing(l_report_header_id,
7804 'Y')) THEN
7805 NULL;
7806 END IF;
7807
7808 --------------------------------------------------------------
7809 l_debug_info := 'Retrieve New_Document_Number Item Attribute';
7810 --------------------------------------------------------------
7811 l_document_number := WF_ENGINE.GetItemAttrText(p_item_type,
7812 p_item_key,
7813 'NEW_DOCUMENT_NUMBER');
7814
7815 -----------------------------------------------------
7816 l_debug_info := 'Retrieve New_Total Item Attribute';
7817 -----------------------------------------------------
7818 l_total := WF_ENGINE.GetItemAttrNumber(p_item_type,
7819 p_item_key,
7820 'NEW_TOTAL');
7821
7822 -----------------------------------------------------
7823 l_debug_info := 'Retrieve Currency Item Attribute';
7824 -----------------------------------------------------
7825 l_currency := WF_ENGINE.GetItemAttrText(p_item_type,
7826 p_item_key,
7827 'CURRENCY');
7828
7829 --------------------------------
7830 l_debug_info := 'Set Item Key';
7831 --------------------------------
7832 l_item_key := to_char(l_report_header_id);
7833
7834 -------------------------------------------------------
7835 l_debug_info := 'Retrieve Preparer_Id Item Attribute';
7836 -------------------------------------------------------
7837 l_preparer_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
7838 p_item_key,
7839 'PREPARER_ID');
7840
7841 -------------------------------------------------------
7842 l_debug_info := 'Retrieve Employee_Id Item Attribute';
7843 -------------------------------------------------------
7844 l_employee_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
7845 p_item_key,
7846 'EMPLOYEE_ID');
7847
7848 ----------------------------------------------------------------
7849 l_debug_info := 'Retrieve Employee Cost Center Item Attribute';
7850 ----------------------------------------------------------------
7851 l_emp_cost_center := WF_ENGINE.GetItemAttrText(p_item_type,
7852 p_item_key,
7853 'EMP_COST_CENTER');
7854
7855 ----------------------------------------------------------------
7856 l_debug_info := 'Retrieve Document Cost Center Item Attribute';
7857 ----------------------------------------------------------------
7858 l_doc_cost_center := WF_ENGINE.GetItemAttrText(p_item_type,
7859 p_item_key,
7860 'DOC_COST_CENTER');
7861
7862 ---------------------------------------------------------
7863 l_debug_info := 'Retrieve Payment Due From System Option';
7864 ---------------------------------------------------------
7865 l_payment_due := WF_ENGINE.GetItemAttrText(p_item_type,p_item_key,'PAYMENT_DUE_FROM');
7866
7867 -----------------------------------------
7868 l_debug_info := 'Retrieve Week End Date';
7869 -----------------------------------------
7870 IF (C_WF_Version >= C_ProjectIntegrationVersion) THEN
7871
7872 l_week_end_date := WF_ENGINE.GetItemAttrDate(p_item_type,
7873 p_item_key,
7874 'WEEK_END_DATE');
7875
7876 END IF;
7877
7878 ------------------------------------------------------------
7879 l_debug_info := 'Create Approval Subprocess';
7880 ------------------------------------------------------------
7881 WF_ENGINE.CreateProcess(p_item_type,
7882 l_item_key,
7883 'AP_EXPENSE_REPORT_PROCESS');
7884
7885 --------------------------------------------------------
7886 l_debug_info := 'Set Expense_Report_ID Item Attribute';
7887 --------------------------------------------------------
7888 WF_ENGINE.SetItemAttrNumber(p_item_type,
7889 l_item_key,
7890 'EXPENSE_REPORT_ID',
7891 l_report_header_id);
7892
7893 ----------------------------------------------------------
7894 l_debug_info := 'Set Document_Number Item Attribute';
7895 ----------------------------------------------------------
7896 WF_ENGINE.SetItemAttrText(p_item_type,
7897 l_item_key,
7898 'DOCUMENT_NUMBER',
7899 l_document_number);
7900
7901 --------------------------------------------------------------------
7902 l_debug_info := 'Retrieve Preparer_Name Info for given preparer_id';
7903 --------------------------------------------------------------------
7904 WF_DIRECTORY.GetUserName('PER',
7905 l_preparer_id,
7906 l_preparer_name,
7907 l_preparer_display_name);
7908
7909 --------------------------------------------------
7910 l_debug_info := 'Set Preparer_ID Item Attribute';
7911 --------------------------------------------------
7912 WF_ENGINE.SetItemAttrText(p_item_type,
7913 l_item_key,
7914 'PREPARER_ID',
7915 l_preparer_id);
7916
7917 ---------------------------------------------------------
7918 l_debug_info := 'Set Preparer_Name Info Item Attributes';
7919 ---------------------------------------------------------
7920 WF_ENGINE.SetItemAttrText(p_item_type,
7921 l_item_key,
7922 'PREPARER_NAME',
7923 l_preparer_name);
7924
7925 WF_ENGINE.SetItemAttrText(p_item_type,
7926 l_item_key,
7927 'PREPARER_DISPLAY_NAME',
7928 l_preparer_display_name);
7929
7930 --------------------------------------------------------------------
7931 l_debug_info := 'Retrieve Employee_Name Info for given Employee_id';
7932 --------------------------------------------------------------------
7933 WF_DIRECTORY.GetUserName('PER',
7934 l_employee_id,
7935 l_employee_name,
7936 l_employee_display_name);
7937
7938 --------------------------------------------------
7939 l_debug_info := 'Set Employee_ID Item Attribute';
7940 --------------------------------------------------
7941 WF_ENGINE.SetItemAttrText(p_item_type,
7942 l_item_key,
7943 'EMPLOYEE_ID',
7944 l_employee_id);
7945
7946 ---------------------------------------------------------
7947 l_debug_info := 'Set Employee_Name Info Item Attributes';
7948 ---------------------------------------------------------
7949 WF_ENGINE.SetItemAttrText(p_item_type,
7950 l_item_key,
7951 'EMPLOYEE_NAME',
7952 l_employee_name);
7953
7954 WF_ENGINE.SetItemAttrText(p_item_type,
7955 l_item_key,
7956 'EMPLOYEE_DISPLAY_NAME',
7957 l_employee_display_name);
7958
7959 ------------------------------------------------------------
7960 l_debug_info := 'Set Total Item Attribute';
7961 ------------------------------------------------------------
7962 WF_ENGINE.SetItemAttrNumber(p_item_type,
7963 l_item_key,
7964 'TOTAL',
7965 l_total);
7966
7967
7968 -----------------------------------------------------------------
7969 l_debug_info := 'Set New Adjusted Display_Total Item Attribute';
7970 -----------------------------------------------------------------
7971 WF_ENGINE.SetItemAttrText(p_item_type,
7972 l_item_key,
7973 'DISPLAY_TOTAL',
7974 to_char(l_total,FND_CURRENCY.Get_Format_Mask(l_currency,22)) || ' ' || l_currency);
7975
7976 ----------------------------------------------
7977 l_debug_info := 'Set Currency Item Attribute';
7978 -----------------------------------------------
7979 WF_ENGINE.SetItemAttrText(p_item_type,
7980 l_item_key,
7981 'CURRENCY',
7982 l_currency);
7983
7984
7985 -----------------------------------------------------------
7986 l_debug_info := 'Set Document Cost Center Item Attribute';
7987 -----------------------------------------------------------
7988 WF_ENGINE.SetItemAttrText(p_item_type,
7989 l_item_key,
7990 'DOC_COST_CENTER',
7991 l_doc_cost_center);
7992
7993 -----------------------------------------------------------
7994 l_debug_info := 'Set Employee Cost Center Item Attribute';
7995 -----------------------------------------------------------
7996 WF_ENGINE.SetItemAttrText(p_item_type,
7997 l_item_key,
7998 'EMP_COST_CENTER',
7999 l_emp_cost_center);
8000
8001 --------------------------------------------------------------
8002 l_debug_info := 'Set CC Payment Due From Item Attribute';
8003 --------------------------------------------------------------
8004 WF_ENGINE.SetItemAttrText(p_item_type,
8005 l_item_key,
8006 'PAYMENT_DUE_FROM',
8007 l_payment_due);
8008
8009 IF (C_WF_Version >= C_ProjectIntegrationVersion) THEN
8010
8011 -------------------------------------------------
8012 l_debug_info := 'Set Week End Date used in determining PA auto approval';
8013 -------------------------------------------------
8014 WF_ENGINE.SetItemAttrDate(p_item_type,
8015 l_item_key,
8016 'WEEK_END_DATE',
8017 l_week_end_date);
8018
8019 END IF;
8020
8021 -----------------------------------------------------------
8022 l_debug_info := 'Skip server validation';
8023 -----------------------------------------------------------
8024 WF_ENGINE.SetItemAttrText(p_item_type,
8025 l_item_key,
8026 'START_FROM_PROCESS',
8027 C_START_FROM_MANAGER_APPROVAL);
8028
8029 ------------------------------------------------------
8030 l_debug_info := 'Start Manager Approval Sub Process';
8031 ------------------------------------------------------
8032 WF_ENGINE.StartProcess(p_item_type,
8033 l_item_key);
8034
8035 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end StartManagerApprvlSubProcess');
8036
8037 EXCEPTION
8038 WHEN OTHERS THEN
8039 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'StartManagerApprvlSubProcess',
8040 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
8041 raise;
8042 END StartManagerApprvlSubProcess;
8043
8044 -------------------------------------------------------
8045 PROCEDURE GetManager(p_employee_id IN HR_EMPLOYEES_CURRENT_V.employee_id%TYPE,
8046 p_manager_id OUT NOCOPY HR_EMPLOYEES_CURRENT_V.employee_id%TYPE) IS
8047 -------------------------------------------------------
8048 l_debug_info VARCHAR2(200);
8049 BEGIN
8050
8051 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start GetManager');
8052
8053 -------------------------------------------------------
8054 l_debug_info := 'Trying to retrieve employee manager';
8055 -------------------------------------------------------
8056 IF (NOT AP_WEB_DB_HR_INT_PKG.GetSupervisorID(p_employee_id, p_manager_id)) THEN
8057 p_manager_id := NULL;
8058 END IF;
8059
8060 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end GetManager');
8061
8062 EXCEPTION
8063 WHEN OTHERS THEN
8064 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'GetManager',
8065 null, null, null, l_debug_info);
8066 raise;
8067 END GetManager;
8068
8069 --------------------------------------------------------
8070 PROCEDURE SetPersonAs(p_manager_id IN NUMBER,
8071 p_item_type IN VARCHAR2,
8072 p_item_key IN VARCHAR2,
8073 p_manager_target IN VARCHAR2) IS
8074 --------------------------------------------------------
8075 l_manager_name wf_users.name%type;
8076 l_manager_display_name wf_users.display_name%type;
8077 l_report_header_id AP_WEB_DB_EXPRPT_PKG.expHdr_headerID;
8078 l_debug_info VARCHAR2(200);
8079 BEGIN
8080
8081 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start SetPersonAs');
8082
8083 ------------------------------------------------------------
8084 l_debug_info := 'Retrieve Manager_Name Info for Manager_Id';
8085 ------------------------------------------------------------
8086 WF_DIRECTORY.GetUserName('PER',
8087 p_manager_id,
8088 l_manager_name,
8089 l_manager_display_name);
8090
8091 IF (p_manager_target = 'MANAGER') THEN
8092
8093 WF_ENGINE.SetItemAttrText(p_item_type,
8094 p_item_key,
8095 'MANAGER_ID',
8096 p_manager_id);
8097
8098 --------------------------------------------------------
8099 l_debug_info := 'Set Manager_Name Info Item Attribute';
8100 --------------------------------------------------------
8101 WF_ENGINE.SetItemAttrText(p_item_type,
8102 p_item_key,
8103 'MANAGER_NAME',
8104 l_manager_name);
8105
8106 ---------------------------------------------------------------
8107 l_debug_info := 'Set Manager_Display_Name Info Item Attribute';
8108 ---------------------------------------------------------------
8109 WF_ENGINE.SetItemAttrText(p_item_type,
8110 p_item_key,
8111 'MANAGER_DISPLAY_NAME',
8112 l_manager_display_name);
8113
8114 ELSE
8115
8116 --------------------------------------------------------
8117 l_debug_info := 'Set Approver_ID Info Item Attribute';
8118 --------------------------------------------------------
8119 WF_ENGINE.SetItemAttrText(p_item_type,
8120 p_item_key,
8121 'APPROVER_ID',
8122 p_manager_id);
8123
8124 --------------------------------------------------------
8125 l_debug_info := 'Set Approver_Name Info Item Attribute';
8126 --------------------------------------------------------
8127 WF_ENGINE.SetItemAttrText(p_item_type,
8128 p_item_key,
8129 'APPROVER_NAME',
8130 l_manager_name);
8131
8132 ----------------------------------------------------------------
8133 l_debug_info := 'Set Approver_Display_Name Info Item Attribute';
8134 ----------------------------------------------------------------
8135 WF_ENGINE.SetItemAttrText(p_item_type,
8136 p_item_key,
8137 'APPROVER_DISPLAY_NAME',
8138 l_manager_display_name);
8139
8140 ----------------------------------------------------------------
8141 l_debug_info := 'Retrieving EXPENSE_REPORT_ID Item Attribute';
8142 ----------------------------------------------------------------
8143 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
8144 p_item_key,
8145 'EXPENSE_REPORT_ID');
8146 /* Bug 3566496: Need to update expense_current_approver_id since that
8147 * is used to display the approver in the Track expenses page.
8148 */
8149
8150 UPDATE ap_expense_report_headers_all
8151 SET expense_current_approver_id = p_manager_id,
8152 approval_type = 'PER'
8153 WHERE report_header_id = l_report_header_id;
8154
8155 END IF;
8156
8157 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end SetPersonAs');
8158
8159 EXCEPTION
8160 WHEN OTHERS THEN
8161 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'SetPersonAs',
8162 p_item_type, p_item_key, null, l_debug_info);
8163 raise;
8164 END SetPersonAs;
8165
8166 -- 3257576 added new parameters p_error_message, p_instructions,
8167 -- p_special_instr
8168 ---------------------------------------------------------------------------
8169 PROCEDURE GetFinalApprover(p_employee_id IN NUMBER,
8170 p_override_approver_id IN NUMBER,
8171 p_emp_cost_center IN VARCHAR2,
8172 p_doc_cost_center IN VARCHAR2,
8173 p_approval_amount IN NUMBER,
8174 p_item_key IN VARCHAR2,
8175 p_item_type IN VARCHAR2,
8176 p_final_approver_id OUT NOCOPY NUMBER,
8177 p_error_message OUT NOCOPY VARCHAR2,
8178 p_instructions OUT NOCOPY VARCHAR2,
8179 p_special_instr OUT NOCOPY VARCHAR2) IS
8180 ---------------------------------------------------------------------------
8181 l_approver_id NUMBER;
8182 l_approver_id_out NUMBER; -- Bug 2718416
8183 l_debug_info VARCHAR2(200);
8184 TYPE l_ManagerIDList IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
8185 l_manager_id l_ManagerIDList;
8186 l_counter NUMBER := 1;
8187 -- 3257576
8188 l_approver_status per_assignment_status_types.per_system_status%type;
8189 l_approver_name per_people_x.full_name%type;
8190 l_approver_name_out per_people_x.full_name%type;
8191 l_employee_name per_people_x.full_name%type;
8192
8193 l_last_approver_id NUMBER;
8194 l_last_approver_name per_workforce_x.full_name%TYPE;
8195 l_emp_info_rec AP_WEB_DB_HR_INT_PKG.EmployeeInfoRec;
8196
8197 BEGIN
8198
8199 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start GetFinalApprover');
8200
8201 IF (p_override_approver_id IS NULL) THEN
8202
8203 -- bug 3257576
8204 GetManagerInfoAndCheckStatus( p_employee_id,
8205 l_employee_name,
8206 l_approver_id,
8207 l_approver_name,
8208 l_approver_status,
8209 p_error_message,
8210 p_instructions,
8211 p_special_instr);
8212
8213 IF (p_error_message IS NOT NULL) THEN
8214 p_final_approver_id := NULL;
8215 END IF;
8216
8217 ELSE
8218
8219 l_approver_id := p_override_approver_id;
8220
8221 END IF;
8222
8223 -- 3257576
8224 IF ((l_approver_id IS NOT NULL) AND (p_error_message IS NULL)) THEN
8225
8226 /*Bug 2492342 Setting the value of the 1st Manager */
8227 l_manager_id(l_counter) := l_approver_id;
8228
8229 LOOP
8230
8231 l_counter := l_counter + 1;
8232
8233 IF (AP_WEB_EXPENSE_CUST_WF.HasAuthority(l_approver_id,
8234 p_doc_cost_center,
8235 p_approval_amount,
8236 p_item_key,
8237 p_item_type)) THEN
8238 p_final_approver_id := l_approver_id;
8239 return;
8240 END IF;
8241
8242 -- bug 3257576
8243 GetManagerInfoAndCheckStatus(
8244 l_approver_id,
8245 l_approver_name,
8246 l_approver_id_out,
8247 l_approver_name_out,
8248 l_approver_status,
8249 p_error_message,
8250 p_instructions,
8251 p_special_instr);
8252
8253 IF (p_error_message IS NOT NULL) THEN
8254 p_final_approver_id := NULL;
8255 return;
8256 END IF;
8257
8258 -- Bug 2718416 - do not pass in same variable as IN and OUT parameter
8259 l_approver_id := l_approver_id_out;
8260 l_approver_name := l_approver_name_out;
8261
8262 IF (l_approver_id = p_employee_id) THEN
8263 ---------------------------------------------
8264 l_debug_info := 'Loop in Approval Hierarchy';
8265 ---------------------------------------------
8266 -- 3257576
8267 FND_MESSAGE.Set_Name('SQLAP', 'AP_WEB_APRVL_HIERARCHY_LOOP');
8268 p_error_message := FND_MESSAGE.Get;
8269 FND_MESSAGE.Set_Name('SQLAP', 'OIE_NO_APPROVER_INSTR6');
8270 p_instructions := FND_MESSAGE.Get;
8271 FND_MESSAGE.Set_Name('SQLAP', 'OIE_NO_APPROVER_SPL_INSTR');
8272 p_special_instr := FND_MESSAGE.Get;
8273 return;
8274 END IF;
8275
8276 /*Bug 2492342 : Adding the manager to the table and checking whether
8277 this manager has been come across before. If so, there
8278 is a loop in the hierarchy.*/
8279
8280 l_manager_id(l_counter) := l_approver_id;
8281
8282 FOR i in 1..(l_counter -1) LOOP
8283
8284 IF l_approver_id = l_manager_id(i) THEN
8285 ---------------------------------------------
8286 l_debug_info := 'Loop in Approval Hierarchy';
8287 ---------------------------------------------
8288 -- 3257576
8289 FND_MESSAGE.Set_Name('SQLAP', 'OIE_CIRCULAR_REF_APRVL_CHAIN');
8290 p_error_message := FND_MESSAGE.Get;
8291 FND_MESSAGE.Set_Name('SQLAP', 'OIE_NO_APPROVER_INSTR6');
8292 p_instructions := FND_MESSAGE.Get;
8293 FND_MESSAGE.Set_Name('SQLAP', 'OIE_NO_APPROVER_SPL_INSTR');
8294 p_special_instr := FND_MESSAGE.Get;
8295 return;
8296 END IF;
8297
8298 END LOOP;
8299
8300
8301 END LOOP;
8302
8303 END IF; -- l_approver_id is not null and p_error_message is null
8304
8305 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end GetFinalApprover');
8306
8307 EXCEPTION
8308 WHEN OTHERS THEN
8309 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'GetFinalApprover',
8310 p_item_type, null, null, l_debug_info);
8311 raise;
8312 END GetFinalApprover;
8313
8314 ----------------------------------------------------------------------
8315 PROCEDURE GetPreparerManager(p_item_type IN VARCHAR2,
8316 p_item_key IN VARCHAR2,
8317 p_actid IN NUMBER,
8318 p_funmode IN VARCHAR2,
8319 p_result OUT NOCOPY VARCHAR2) IS
8320 ----------------------------------------------------------------------
8321 l_preparer_id NUMBER;
8322 l_manager_id NUMBER;
8323 l_debug_info VARCHAR2(200);
8324 BEGIN
8325
8326 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start GetPreparerManager');
8327
8328 IF (p_funmode = 'RUN') THEN
8329
8330 ------------------------------------------------------
8331 l_debug_info := 'Retrieve Employee_ID Item Attribute';
8332 ------------------------------------------------------
8333 l_preparer_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
8334 p_item_key,
8335 'PREPARER_ID');
8336
8337
8338 ---------------------------------------------
8339 l_debug_info := 'Call Get Manager Procedure';
8340 ----------------------------------------------
8341 GetManager(l_preparer_id,
8342 l_manager_id);
8343
8344 IF (l_manager_id IS NULL) THEN
8345 l_debug_info := 'Manager not found for employee_id ' || to_char(l_preparer_id);
8346 END IF;
8347
8348 SetPersonAs(l_manager_id,
8349 p_item_type,
8350 p_item_key,
8351 'MANAGER');
8352
8353 ELSIF (p_funmode = 'CANCEL') THEN
8354
8355 p_result := 'COMPLETE';
8356
8357 END IF;
8358
8359 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end GetPreparerManager');
8360
8361 EXCEPTION
8362 WHEN OTHERS THEN
8363 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'GetPreparerManager',
8364 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
8365 raise;
8366 END GetPreparerManager;
8367
8368 ----------------------------------------------------------------------
8369 PROCEDURE GetApproverManager(p_item_type IN VARCHAR2,
8370 p_item_key IN VARCHAR2,
8371 p_actid IN NUMBER,
8372 p_funmode IN VARCHAR2,
8373 p_result OUT NOCOPY VARCHAR2) IS
8374 ----------------------------------------------------------------------
8375 l_approver_id NUMBER;
8376 l_manager_id NUMBER;
8377 l_debug_info VARCHAR2(200);
8378 BEGIN
8379
8380 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start GetApproverManager');
8381
8382 IF (p_funmode = 'RUN') THEN
8383
8384 ------------------------------------------------------
8385 l_debug_info := 'Retrieve Approve_ID Item Attribute';
8386 ------------------------------------------------------
8387 l_approver_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
8388 p_item_key,
8389 'APPROVER_ID');
8390
8391 ---------------------------------------------
8392 l_debug_info := 'Call Get Manager Procedure';
8393 ----------------------------------------------
8394 GetManager(l_approver_id,
8395 l_manager_id);
8396
8397 SetPersonAs(l_manager_id,
8398 p_item_type,
8399 p_item_key,
8400 'APPROVER');
8401
8402 /*
8403 SetForwardInfoInAME is called to forward the approval to the approver's
8404 manager when the approver doesn't response and got time-out
8405 */
8406 AP_WEB_WRAPPER_PKG.SetForwardInfoInAME(p_item_key,
8407 p_item_type);
8408
8409 ELSIF (p_funmode = 'CANCEL') THEN
8410
8411 p_result := 'COMPLETE';
8412
8413 END IF;
8414
8415 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end GetApproverManager');
8416
8417 EXCEPTION
8418 WHEN OTHERS THEN
8419 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'GetApproverManager',
8420 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
8421 raise;
8422 END GetApproverManager;
8423
8424 ----------------------------------------------------------------------
8425 PROCEDURE ApproverProvided(p_item_type IN VARCHAR2,
8426 p_item_key IN VARCHAR2,
8427 p_actid IN NUMBER,
8428 p_funmode IN VARCHAR2,
8429 p_result OUT NOCOPY VARCHAR2) IS
8430 ----------------------------------------------------------------------
8431 l_approver_id NUMBER;
8432 l_debug_info VARCHAR2(200);
8433 BEGIN
8434
8435 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start ApproverProvided');
8436
8437 IF (p_funmode = 'RUN') THEN
8438
8439 ------------------------------------------------------
8440 l_debug_info := 'Retrieve Approve_ID Item Attribute';
8441 ------------------------------------------------------
8442 l_approver_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
8443 p_item_key,
8444 'APPROVER_ID');
8445
8446 ---------------------------------------------------------------------------
8447 l_debug_info := 'If l_approver_id is not null return Y otherwise return N';
8448 ---------------------------------------------------------------------------
8449 IF (l_approver_id IS NOT NULL) THEN
8450 p_result := 'COMPLETE:Y';
8451 ELSE
8452 p_result := 'COMPLETE:N';
8453 END IF;
8454
8455 ELSIF (p_funmode = 'CANCEL') THEN
8456
8457 p_result := 'COMPLETE';
8458
8459 END IF;
8460
8461 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end ApproverProvided');
8462
8463 EXCEPTION
8464 WHEN OTHERS THEN
8465 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'ApproverProvided',
8466 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
8467 raise;
8468 END ApproverProvided;
8469
8470 ----------------------------------------------------------------------
8471 PROCEDURE SameCostCenters(p_item_type IN VARCHAR2,
8472 p_item_key IN VARCHAR2,
8473 p_actid IN NUMBER,
8474 p_funmode IN VARCHAR2,
8475 p_result OUT NOCOPY VARCHAR2) IS
8476 ----------------------------------------------------------------------
8477 l_emp_cost_center VARCHAR2(240);
8478 l_report_cost_center VARCHAR2(240);
8479 l_debug_info VARCHAR2(200);
8480 BEGIN
8481
8482 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start SameCostCenters');
8483
8484 IF (p_funmode = 'RUN') THEN
8485
8486 ---------------------------------------------------------------
8487 l_debug_info := 'Retrieve Employee Cost Center Item Attribute';
8488 ---------------------------------------------------------------
8489 l_emp_cost_center := WF_ENGINE.GetItemAttrText(p_item_type,
8490 p_item_key,
8491 'EMP_COST_CENTER');
8492
8493 ---------------------------------------------------------------
8494 l_debug_info := 'Retrieve Document Cost Center Item Attribute';
8495 ---------------------------------------------------------------
8496 l_report_cost_center := WF_ENGINE.GetItemAttrText(p_item_type,
8497 p_item_key,
8498 'DOC_COST_CENTER');
8499
8500 --------------------------------------------------------------------
8501 l_debug_info := 'If Employee and Document Cost Centers are the same
8502 return Y otherwise return N';
8503 --------------------------------------------------------------------
8504 IF (l_emp_cost_center = l_report_cost_center) THEN
8505 p_result := 'COMPLETE:Y';
8506 ELSE
8507 p_result := 'COMPLETE:N';
8508 END IF;
8509
8510 ELSIF (p_funmode = 'CANCEL') THEN
8511
8512 p_result := 'COMPLETE';
8513
8514 END IF;
8515
8516 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end SameCostCenters');
8517
8518 EXCEPTION
8519 WHEN OTHERS THEN
8520 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'SameCostCenters',
8521 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
8522 raise;
8523 END SameCostCenters;
8524
8525 ----------------------------------------------------------------------
8526 PROCEDURE SetApproverEqualManager(p_item_type IN VARCHAR2,
8527 p_item_key IN VARCHAR2,
8528 p_actid IN NUMBER,
8529 p_funmode IN VARCHAR2,
8530 p_result OUT NOCOPY VARCHAR2) IS
8531 ----------------------------------------------------------------------
8532 l_manager_id NUMBER;
8533 l_manager_name wf_users.name%type;
8534 l_manager_display_name wf_users.display_name%type;
8535 l_debug_info VARCHAR2(200);
8536 BEGIN
8537
8538 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start SetApproverEqualManager');
8539
8540 IF (p_funmode = 'RUN') THEN
8541
8542 ------------------------------------------------------
8543 l_debug_info := 'Retrieve Manager_ID Item Attribute';
8544 -------------------------------------------------------
8545 l_manager_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
8546 p_item_key,
8547 'MANAGER_ID');
8548
8549 ------------------------------------------------------------
8550 l_debug_info := 'Retrieve Manager_Name Info Item Attributes';
8551 ------------------------------------------------------------
8552 l_manager_name := WF_ENGINE.GetItemAttrText(p_item_type,
8553 p_item_key,
8554 'MANAGER_NAME');
8555
8556 l_manager_display_name := WF_ENGINE.GetItemAttrText(p_item_type,
8557 p_item_key,
8558 'MANAGER_DISPLAY_NAME');
8559
8560 ----------------------------------------------------------------------
8561 l_debug_info := 'Set Approver Info Item Attributes with Manager Info';
8562 ----------------------------------------------------------------------
8563 WF_ENGINE.SetItemAttrNUMBER(p_item_type,
8564 p_item_key,
8565 'APPROVER_ID',
8566 l_manager_id);
8567
8568 WF_ENGINE.SetItemAttrText(p_item_type,
8569 p_item_key,
8570 'APPROVER_NAME',
8571 l_manager_name);
8572
8573 WF_ENGINE.SetItemAttrText(p_item_type,
8574 p_item_key,
8575 'APPROVER_DISPLAY_NAME',
8576 l_manager_display_name);
8577
8578 ELSIF (p_funmode = 'CANCEL') THEN
8579
8580 p_result := 'COMPLETE';
8581
8582 END IF;
8583
8584 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end SetApproverEqualManager');
8585
8586 EXCEPTION
8587 WHEN OTHERS THEN
8588 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'SetApproverEqualManager',
8589 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
8590 raise;
8591 END SetApproverEqualManager;
8592
8593 ----------------------------------------------------------------------
8594 PROCEDURE RecordForwardFromInfo(p_item_type IN VARCHAR2,
8595 p_item_key IN VARCHAR2,
8596 p_actid IN NUMBER,
8597 p_funmode IN VARCHAR2,
8598 p_result OUT NOCOPY VARCHAR2) IS
8599 ----------------------------------------------------------------------
8600 l_approver_id NUMBER;
8601 l_approver_name wf_users.name%type;
8602 l_approver_display_name wf_users.display_name%type;
8603 l_debug_info VARCHAR2(200);
8604 BEGIN
8605
8606 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start RecordForwardFromInfo');
8607
8608 IF (p_funmode in ('RUN', 'TRANSFER')) THEN
8609
8610 ------------------------------------------------------------
8611 l_debug_info := 'Retrieve Approver_Info Item Attributes';
8612 ------------------------------------------------------------
8613 l_approver_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
8614 p_item_key,
8615 'APPROVER_ID');
8616
8617 l_approver_name := WF_ENGINE.GetItemAttrText(p_item_type,
8618 p_item_key,
8619 'APPROVER_NAME');
8620
8621 l_approver_display_name := WF_ENGINE.GetItemAttrText(p_item_type,
8622 p_item_key,
8623 'APPROVER_DISPLAY_NAME');
8624
8625 ----------------------------------------------------------------------
8626 l_debug_info := 'Set Forward_From Item Attributes With Approver Info';
8627 ----------------------------------------------------------------------
8628 WF_ENGINE.SetItemAttrNUMBER(p_item_type,
8629 p_item_key,
8630 'FORWARD_FROM_ID',
8631 l_approver_id);
8632
8633 WF_ENGINE.SetItemAttrText(p_item_type,
8634 p_item_key,
8635 'FORWARD_FROM_NAME',
8636 l_approver_name);
8637
8638 WF_ENGINE.SetItemAttrText(p_item_type,
8639 p_item_key,
8640 'FORWARD_FROM_DISPLAY_NAME',
8641 l_approver_display_name);
8642
8643 ELSIF (p_funmode = 'CANCEL') THEN
8644
8645 p_result := 'COMPLETE';
8646
8647 END IF;
8648
8649 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end RecordForwardFromInfo');
8650
8651 EXCEPTION
8652 WHEN OTHERS THEN
8653 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'RecordForwardFromInfo',
8654 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
8655 raise;
8656 END RecordForwardFromInfo;
8657
8658 ----------------------------------------------------------------------
8659 PROCEDURE ManagerNotEqualToApprover(p_item_type IN VARCHAR2,
8660 p_item_key IN VARCHAR2,
8661 p_actid IN NUMBER,
8662 p_funmode IN VARCHAR2,
8663 p_result OUT NOCOPY VARCHAR2) IS
8664 ----------------------------------------------------------------------
8665 l_approver_id NUMBER;
8666 l_manager_id NUMBER;
8667 l_debug_info VARCHAR2(200);
8668 BEGIN
8669
8670 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start ManagerNotEqualToApprover');
8671
8672 IF (p_funmode = 'RUN') THEN
8673
8674 ------------------------------------------------------
8675 l_debug_info := 'Retrieve Approver_ID Item Attribute';
8676 ------------------------------------------------------
8677 l_approver_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
8678 p_item_key,
8679 'APPROVER_ID');
8680
8681 ------------------------------------------------------
8682 l_debug_info := 'Retrieve Approve_ID Item Attribute';
8683 ------------------------------------------------------
8684 l_manager_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
8685 p_item_key,
8686 'MANAGER_ID');
8687
8688 IF (l_approver_id <> l_manager_id) THEN
8689 p_result := 'COMPLETE:Y';
8690 ELSE
8691 p_result := 'COMPLETE:N';
8692 END IF;
8693
8694 ELSIF (p_funmode = 'CANCEL') THEN
8695
8696 p_result := 'COMPLETE';
8697
8698 END IF;
8699
8700 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end ManagerNotEqualToApprover');
8701
8702 EXCEPTION
8703 WHEN OTHERS THEN
8704 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'ManagerNotEqualToApprover',
8705 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
8706 raise;
8707 END ManagerNotEqualToApprover;
8708
8709 ----------------------------------------------------------------------
8710 PROCEDURE NotifyPreparer(p_item_type IN VARCHAR2,
8711 p_item_key IN VARCHAR2,
8712 p_actid IN NUMBER,
8713 p_funmode IN VARCHAR2,
8714 p_result OUT NOCOPY VARCHAR2) IS
8715 ----------------------------------------------------------------------
8716 l_approver_id NUMBER;
8717 l_manager_id NUMBER;
8718 l_count NUMBER;
8719 l_limit NUMBER;
8720 l_debug_info VARCHAR2(200);
8721 BEGIN
8722
8723 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start NotifyPreparer');
8724
8725 IF (p_funmode = 'RUN') THEN
8726
8727 -----------------------------------------------------------------------
8728 l_debug_info := 'Retrieve Manager_Approval_Send_Count Item Attribute';
8729 -----------------------------------------------------------------------
8730 l_count := WF_ENGINE.GetItemAttrNumber(p_item_type,
8731 p_item_key,
8732 'MANAGER_APPROVAL_SEND_COUNT');
8733
8734 ---------------------------------------------------------------
8735 l_debug_info := 'Retrieve Manager_Send_Limit Item Attribute';
8736 ---------------------------------------------------------------
8737 l_limit := WF_ENGINE.GetActivityAttrNumber(p_item_type,
8738 p_item_key,
8739 p_actid,
8740 'MANAGER_SEND_LIMIT');
8741
8742 -----------------------------------------------------------------------
8743 l_debug_info := 'Increment Manager_Approval_Send_Count Item Attribute';
8744 -----------------------------------------------------------------------
8745 WF_ENGINE.SetItemAttrNumber(p_item_type,
8746 p_item_key,
8747 'MANAGER_APPROVAL_SEND_COUNT',
8748 l_count+1);
8749
8750
8751 IF (l_count+1 >= l_limit) THEN
8752
8753 ---------------------------------------------------------------
8754 l_debug_info := 'Send_count at least equals limit, clear
8755 Manager_Approval_Send_Count Item Attribute
8756 and return Y';
8757 ---------------------------------------------------------------
8758 WF_ENGINE.SetItemAttrNumber(p_item_type,
8759 p_item_key,
8760 'MANAGER_APPROVAL_SEND_COUNT',
8761 0);
8762
8763 p_result := 'COMPLETE:Y';
8764
8765 ELSE
8766
8767 p_result := 'COMPLETE:N';
8768
8769 END IF;
8770
8771 ELSIF (p_funmode = 'CANCEL') THEN
8772
8773 p_result := 'COMPLETE';
8774
8775 END IF;
8776
8777 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end NotifyPreparer');
8778
8779 EXCEPTION
8780 WHEN OTHERS THEN
8781 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'NotifyPreparer',
8782 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
8783 raise;
8784 END NotifyPreparer;
8785
8786 /*----------------------------------------------------------------------------*
8787 | Procedure
8788 | AMEEnabled
8789 |
8790 | DESCRIPTION
8791 | This procedure is used by workflow to determine whether AME is
8792 | enabled or not
8793 |
8794 | PARAMETERS
8795 |
8796 | RETURNS
8797 | none
8798 *----------------------------------------------------------------------------*/
8799 ---------------------------------------------------------
8800 PROCEDURE AMEEnabled(p_item_type IN VARCHAR2,
8801 p_item_key IN VARCHAR2,
8802 p_actid IN NUMBER,
8803 p_funmode IN VARCHAR2,
8804 p_result OUT NOCOPY VARCHAR2) IS
8805 ---------------------------------------------------------
8806 l_find_approver_count NUMBER;
8807 l_debug_info VARCHAR2(200);
8808 l_AMEEnabled VARCHAR2(1);
8809 l_bAMEProfileDefined BOOLEAN;
8810 l_nRespId Number;
8811
8812 BEGIN
8813
8814 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start AMEEnabled');
8815
8816 IF (p_funmode = 'RUN') THEN
8817
8818 BEGIN
8819 ------------------------------------------------------------
8820 l_debug_info := 'Get responsibility id';
8821 ------------------------------------------------------------
8822 l_nRespId := WF_ENGINE.GetItemAttrNumber(p_item_type,
8823 p_item_key,
8824 'RESPONSIBILITY_ID');
8825
8826 EXCEPTION
8827 WHEN OTHERS THEN
8828 if (wf_core.error_name = 'WFENG_ITEM_ATTR') then
8829 null;
8830 else
8831 raise;
8832 end if;
8833 END;
8834
8835 ----------------------------------------------------
8836 l_debug_info := 'Retrieve profile option AME Enabled';
8837 ----------------------------------------------------
8838 FND_PROFILE.GET_SPECIFIC('AME_INSTALLED_FLAG', null, l_nRespId, 200, l_AMEEnabled, l_bAMEProfileDefined);
8839
8840 if l_bAMEProfileDefined then
8841 -----------------------------------------------
8842 -- for bug 3344280, check the profile option value if it's defined
8843 -----------------------------------------------
8844 if (NVL(l_AMEEnabled,'N') = 'Y') then
8845 p_result := 'COMPLETE:Y';
8846 else
8847 p_result := 'COMPLETE:N';
8848 end if;
8849 else
8850 ---------------------------------------------------
8851 -- return no if AME Installed profile option is not defined
8852 ---------------------------------------------------
8853 p_result := 'COMPLETE:N';
8854 end if;
8855
8856 ELSIF (p_funmode = 'CANCEL') THEN
8857
8858 p_result := 'COMPLETE';
8859
8860 END IF;
8861
8862 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end AMEEnabled');
8863
8864 EXCEPTION
8865 WHEN OTHERS THEN
8866 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'AMEEnabled',
8867 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
8868 raise;
8869 END AMEEnabled;
8870
8871 ---------------------------------------------------------
8872 PROCEDURE FirstApprover(p_item_type IN VARCHAR2,
8873 p_item_key IN VARCHAR2,
8874 p_actid IN NUMBER,
8875 p_funmode IN VARCHAR2,
8876 p_result OUT NOCOPY VARCHAR2) IS
8877 ---------------------------------------------------------
8878 l_find_approver_count NUMBER;
8879 l_debug_info VARCHAR2(200);
8880 BEGIN
8881
8882 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start FirstApprover');
8883
8884 IF (p_funmode = 'RUN') THEN
8885
8886 ----------------------------------------------------------------
8887 l_debug_info := 'Retrieving Find_Approver_Count Item Attribute';
8888 ----------------------------------------------------------------
8889 l_find_approver_count := WF_ENGINE.GetItemAttrNumber(p_item_type,
8890 p_item_key,
8891 'FIND_APPROVER_COUNT');
8892
8893 IF (l_find_approver_count = 1) THEN
8894 -----------------------------------------------
8895 -- return yes when find_approver_count equals 1
8896 -----------------------------------------------
8897 p_result := 'COMPLETE:Y';
8898 ELSE
8899 ---------------------------------------------------
8900 -- return no if find_approver_count doesn't equal 1
8901 ---------------------------------------------------
8902 p_result := 'COMPLETE:N';
8903 END IF;
8904
8905 ELSIF (p_funmode = 'CANCEL') THEN
8906
8907 p_result := 'COMPLETE';
8908
8909 END IF;
8910
8911 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end FirstApprover');
8912
8913 EXCEPTION
8914 WHEN OTHERS THEN
8915 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'FirstApprover',
8916 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
8917 raise;
8918 END FirstApprover;
8919
8920 ---------------------------------------------------------
8921 PROCEDURE ApprovalForwarded(p_item_type IN VARCHAR2,
8922 p_item_key IN VARCHAR2,
8923 p_actid IN NUMBER,
8924 p_funmode IN VARCHAR2,
8925 p_result OUT NOCOPY VARCHAR2) IS
8926 ---------------------------------------------------------
8927 l_forward_from_id NUMBER;
8928 l_debug_info VARCHAR2(200);
8929 BEGIN
8930
8931 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start ApprovalForwarded');
8932
8933 IF (p_funmode = 'RUN') THEN
8934
8935 ----------------------------------------------------------------
8936 l_debug_info := 'Retrieving FORWARD_FROM_ID Item Attribute';
8937 ----------------------------------------------------------------
8938 l_forward_from_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
8939 p_item_key,
8940 'FORWARD_FROM_ID');
8941
8942 IF (l_forward_from_id IS NOT NULL) THEN
8943 -----------------------------------------------
8944 -- return yes when forward_from_id is not null
8945 -----------------------------------------------
8946 p_result := 'COMPLETE:Y';
8947 ELSE
8948 ----------------------------------------
8949 -- return no if forward_from_id is null
8950 ----------------------------------------
8951 p_result := 'COMPLETE:N';
8952 END IF;
8953
8954 ELSIF (p_funmode = 'CANCEL') THEN
8955 p_result := 'COMPLETE';
8956 END IF;
8957
8958 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end ApprovalForwarded');
8959
8960 EXCEPTION
8961 WHEN OTHERS THEN
8962 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'ApprovalForwarded',
8963 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
8964 raise;
8965 END ApprovalForwarded;
8966
8967 ---------------------------------------------------------
8968 PROCEDURE ResetEmpCostCenter(p_item_type IN VARCHAR2,
8969 p_item_key IN VARCHAR2,
8970 p_actid IN NUMBER,
8971 p_funmode IN VARCHAR2,
8972 p_result OUT NOCOPY VARCHAR2) IS
8973 ---------------------------------------------------------
8974 l_preparer_id NUMBER;
8975 l_emp_name wf_users.name%type;
8976 l_emp_num VARCHAR2(30);
8977 l_emp_cost_center VARCHAR2(240);
8978 l_debug_info VARCHAR2(200);
8979 BEGIN
8980
8981 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start ResetEmpCostCenter');
8982
8983 IF (p_funmode = 'RUN') THEN
8984
8985 -------------------------------------------------------------
8986 l_debug_info := 'Retrieving Emp_Cost_Center Item Attribute';
8987 -------------------------------------------------------------
8988 l_emp_cost_center := WF_ENGINE.GetItemAttrText(p_item_type,
8989 p_item_key,
8990 'EMP_COST_CENTER');
8991
8992 ---------------------------------------------------------
8993 l_debug_info := 'Retrieving Preparer_Id Item Attribute';
8994 ---------------------------------------------------------
8995 l_preparer_id := WF_ENGINE.GetItemAttrText(p_item_type,
8996 p_item_key,
8997 'PREPARER_ID');
8998
8999
9000 IF (l_emp_cost_center IS NULL) THEN
9001
9002 ---------------------------------------------------------------
9003 l_debug_info := 'Get the Employee Cost Center Associated With
9004 Preparer_Id';
9005 ---------------------------------------------------------------
9006 AP_WEB_UTILITIES_PKG.GetEmployeeInfo(l_emp_name,
9007 l_emp_num,
9008 l_emp_cost_center,
9009 l_preparer_id);
9010
9011 -------------------------------------------------------------
9012 l_debug_info := 'Set Emp_Cost_Center Item Attribute';
9013 -------------------------------------------------------------
9014 WF_ENGINE.SetItemAttrText(p_item_type,
9015 p_item_key,
9016 'EMP_COST_CENTER',
9017 l_emp_cost_center);
9018
9019 END IF;
9020
9021
9022 ELSIF (p_funmode = 'CANCEL') THEN
9023 p_result := 'COMPLETE';
9024 END IF;
9025
9026 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end ResetEmpCostCenter');
9027
9028 EXCEPTION
9029 WHEN OTHERS THEN
9030 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'ResetEmpCostCenter',
9031 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
9032 raise;
9033 END ResetEmpCostCenter;
9034
9035 ---------------------------------------------------------
9036 PROCEDURE PayablesReviewed(p_item_type IN VARCHAR2,
9037 p_item_key IN VARCHAR2,
9038 p_actid IN NUMBER,
9039 p_funmode IN VARCHAR2,
9040 p_result OUT NOCOPY VARCHAR2) IS
9041 ---------------------------------------------------------
9042 l_report_header_id AP_WEB_DB_EXPRPT_PKG.expHdr_headerID;
9043 l_WorkflowRec AP_WEB_DB_EXPRPT_PKG.ExpWorkflowRec;
9044 l_debug_info VARCHAR2(200);
9045 l_rejection_reason Wf_Item_Attribute_Values.TEXT_VALUE%TYPE := NULL;
9046 BEGIN
9047
9048 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start PayablesReviewed');
9049
9050 IF (p_funmode = 'RUN') THEN
9051
9052 ----------------------------------------------------------------
9053 l_debug_info := 'Retrieving EXPENSE_REPORT_ID Item Attribute';
9054 ----------------------------------------------------------------
9055 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
9056 p_item_key,
9057 'EXPENSE_REPORT_ID');
9058
9059 ----------------------------------------------------------------
9060 l_debug_info := 'Set Rejection Reason to No reason provided if it is null';
9061 ----------------------------------------------------------------
9062 l_rejection_reason := WF_ENGINE.GetItemAttrText(p_item_type,
9063 p_item_key,
9064 'WF_NOTE');
9065
9066 IF (l_rejection_reason IS NULL OR
9067 replace(l_rejection_reason, ' ', '') = '') THEN
9068 FND_MESSAGE.Set_Name('SQLAP', 'OIE_NO_REASON_PROVIDED');
9069 WF_ENGINE.SetItemAttrText(p_item_type,
9070 p_item_key,
9071 'WF_NOTE',
9072 FND_MESSAGE.Get);
9073
9074 END IF;
9075
9076
9077
9078 IF (NOT AP_WEB_DB_EXPRPT_PKG.GetExpWorkflowInfo(l_report_header_id,
9079 l_WorkflowRec)) THEN
9080 l_WorkflowRec.workflow_flag := NULL;
9081 END IF;
9082
9083 IF (l_WorkflowRec.workflow_flag = 'P') THEN
9084 ---------------------------------------------------------
9085 -- return yes when workflow_approved_flag is equal to 'P'
9086 ---------------------------------------------------------
9087 p_result := 'COMPLETE:Y';
9088 ELSE
9089 ----------------------------------------------------------
9090 -- return no if workflow_approved_flag is not equal to 'P'
9091 ----------------------------------------------------------
9092 p_result := 'COMPLETE:N';
9093 END IF;
9094
9095 ELSIF (p_funmode = 'CANCEL') THEN
9096 p_result := 'COMPLETE';
9097 END IF;
9098
9099 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end PayablesReviewed');
9100
9101 EXCEPTION
9102 WHEN OTHERS THEN
9103 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'PayablesReviewed',
9104 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
9105 raise;
9106 END PayablesReviewed;
9107
9108 ----------------------------------------------------------------------
9109 PROCEDURE EmployeeEqualsToPreparer(p_item_type IN VARCHAR2,
9110 p_item_key IN VARCHAR2,
9111 p_actid IN NUMBER,
9112 p_funmode IN VARCHAR2,
9113 p_result OUT NOCOPY VARCHAR2) IS
9114 ----------------------------------------------------------------------
9115 l_employee_id NUMBER(15);
9116 l_preparer_id NUMBER(15);
9117 l_debug_info VARCHAR2(200);
9118 BEGIN
9119
9120 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start EmployeeEqualsToPreparer');
9121
9122 IF (p_funmode = 'RUN') THEN
9123
9124 ---------------------------------------------------------------
9125 l_debug_info := 'Retrieve Employee Id Item Attribute';
9126 ---------------------------------------------------------------
9127 l_employee_id := WF_ENGINE.GetItemAttrText(p_item_type,
9128 p_item_key,
9129 'EMPLOYEE_ID');
9130
9131 ---------------------------------------------------------------
9132 l_debug_info := 'Retrieve Preparer Id Item Attribute';
9133 ---------------------------------------------------------------
9134 l_preparer_id := WF_ENGINE.GetItemAttrText(p_item_type,
9135 p_item_key,
9136 'PREPARER_ID');
9137
9138 --------------------------------------------------------------------
9139 l_debug_info := 'If Employee Id and Preparer Id are the same
9140 return Y otherwise return N';
9141 --------------------------------------------------------------------
9142 IF (l_employee_id = l_preparer_id) THEN
9143 p_result := 'COMPLETE:Y';
9144 ELSE
9145 p_result := 'COMPLETE:N';
9146 END IF;
9147
9148 ELSIF (p_funmode = 'CANCEL') THEN
9149 p_result := 'COMPLETE';
9150 END IF;
9151
9152 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end EmployeeEqualsToPreparer');
9153
9154 EXCEPTION
9155 WHEN OTHERS THEN
9156 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'EmployeeEqualsToPreparer',
9157 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
9158 raise;
9159 END EmployeeEqualsToPreparer;
9160
9161 ----------------------------------------------------------------------
9162 PROCEDURE EmployeeApprovalRequired(p_item_type IN VARCHAR2,
9163 p_item_key IN VARCHAR2,
9164 p_actid IN NUMBER,
9165 p_funmode IN VARCHAR2,
9166 p_result OUT NOCOPY VARCHAR2) IS
9167 ----------------------------------------------------------------------
9168 l_emp_method VARCHAR2(20);
9169 l_debug_info VARCHAR2(200);
9170 BEGIN
9171
9172 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start EmployeeApprovalRequired');
9173
9174 IF (p_funmode = 'RUN') THEN
9175
9176 -------------------------------------------------------------------
9177 l_debug_info := 'Retrieve Find_Approver_Method Activity Attribute';
9178 -------------------------------------------------------------------
9179 l_emp_method := WF_ENGINE.GetActivityAttrText(p_item_type,
9180 p_item_key,
9181 p_actid,
9182 'EMPLOYEE_APPROVAL_REQUIRED_MET');
9183
9184 IF (l_emp_method = 'Y') THEN
9185 p_result := 'COMPLETE:Y';
9186 ELSE
9187 p_result := 'COMPLETE:N';
9188 END IF;
9189
9190 ELSIF (p_funmode = 'CANCEL') THEN
9191 p_result := 'COMPLETE';
9192 END IF;
9193
9194 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end EmployeeApprovalRequired');
9195
9196 EXCEPTION
9197 WHEN OTHERS THEN
9198 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'EmployeeApprovalRequired',
9199 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
9200 raise;
9201 END EmployeeApprovalRequired;
9202
9203 ---------------------------------------------------------
9204 PROCEDURE DetermineStartFromProcess(p_item_type IN VARCHAR2,
9205 p_item_key IN VARCHAR2,
9206 p_actid IN NUMBER,
9207 p_funmode IN VARCHAR2,
9208 p_result OUT NOCOPY VARCHAR2) IS
9209 ---------------------------------------------------------
9210
9211 --
9212 -- Determines from which process to start the workflow: server validation,
9213 -- manager approval, or ap approval.
9214 --
9215
9216 l_start_from_process VARCHAR2(40);
9217 l_workflow_approved_flag VARCHAR2(1);
9218 l_debug_info VARCHAR2(200);
9219 BEGIN
9220
9221 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start DetermineStartFromProcess');
9222
9223 IF (p_funmode = 'RUN') THEN
9224
9225 ----------------------------------------------------------------
9226 l_debug_info := 'Retrieving Start From Process Item Attribute';
9227 ----------------------------------------------------------------
9228 l_start_from_process := WF_ENGINE.GetItemAttrText(p_item_type,
9229 p_item_key,
9230 'START_FROM_PROCESS');
9231 p_result := 'COMPLETE:' || l_start_from_process;
9232 IF l_start_from_process IS NULL THEN
9233 p_result := 'COMPLETE:' || C_START_FROM_SERVER_VALIDATION;
9234 END IF;
9235
9236 ELSIF (p_funmode = 'CANCEL') THEN
9237 p_result := 'COMPLETE';
9238 END IF;
9239
9240 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end DetermineStartFromProcess');
9241
9242 EXCEPTION
9243 WHEN OTHERS THEN
9244 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'DetermineStartFromProcess',
9245 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
9246 RAISE;
9247
9248 END DetermineStartFromProcess;
9249
9250 ---------------------------------------------------------
9251 PROCEDURE SetEmployeeAsApprover(p_item_type IN VARCHAR2,
9252 p_item_key IN VARCHAR2,
9253 p_actid IN NUMBER,
9254 p_funmode IN VARCHAR2,
9255 p_result OUT NOCOPY VARCHAR2) IS
9256 ---------------------------------------------------------
9257
9258 --
9259 -- For the third-party expense report submission, if the employee
9260 -- (not the submitter) rejects the report we must set the approver
9261 -- info to the employee so that the notification sent to the
9262 -- submitter will contain the appropriate rejector name. The approver
9263 -- info is used to determine the actual report approver not the
9264 -- employee in the third party case.
9265 --
9266
9267 V_employee_id NUMBER;
9268 V_employee_name wf_users.name%type;
9269 V_employee_display_name wf_users.display_name%type;
9270 l_debug_info VARCHAR2(200);
9271
9272 BEGIN
9273
9274 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start SetEmployeeAsApprover');
9275
9276 IF (p_funmode = 'RUN') THEN
9277
9278 ------------------------------------------------------
9279 l_debug_info := 'Get WF Employee_ID Item Attribute';
9280 ------------------------------------------------------
9281 V_employee_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
9282 p_item_key,
9283 'EMPLOYEE_ID');
9284
9285 V_employee_name := WF_ENGINE.GetItemAttrText(p_item_type,
9286 p_item_key,
9287 'EMPLOYEE_NAME');
9288
9289
9290 V_employee_display_name := WF_ENGINE.GetItemAttrText(p_item_type,
9291 p_item_key,
9292 'EMPLOYEE_DISPLAY_NAME');
9293
9294
9295 --------------------------------------------------------------
9296 l_debug_info := 'Set WF Preparer_Display_Name Item Attribute';
9297 --------------------------------------------------------------
9298 WF_ENGINE.SetItemAttrNumber(p_item_type,
9299 p_item_key,
9300 'APPROVER_ID',
9301 V_employee_id);
9302
9303 WF_ENGINE.SetItemAttrText(p_item_type,
9304 p_item_key,
9305 'APPROVER_NAME',
9306 V_employee_name);
9307
9308 WF_ENGINE.SetItemAttrText(p_item_type,
9309 p_item_key,
9310 'APPROVER_DISPLAY_NAME',
9311 V_employee_display_name);
9312
9313
9314 ELSIF (p_funmode = 'CANCEL') THEN
9315 p_result := 'COMPLETE';
9316 END IF;
9317
9318 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end SetEmployeeAsApprover');
9319
9320 EXCEPTION
9321 WHEN OTHERS THEN
9322 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'SetEmployeeAsApprover',
9323 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
9324 RAISE;
9325
9326 END SetEmployeeAsApprover;
9327
9328 ----------------------------------------------------------------------
9329 PROCEDURE DeleteShortPayExpReport(p_item_type IN VARCHAR2,
9330 p_item_key IN VARCHAR2,
9331 p_actid IN NUMBER,
9332 p_funmode IN VARCHAR2,
9333 p_result OUT NOCOPY VARCHAR2) IS
9334 ----------------------------------------------------------------------
9335 l_report_header_id AP_WEB_DB_EXPRPT_PKG.expHdr_headerID;
9336 l_debug_info VARCHAR2(200);
9337 BEGIN
9338
9339 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start DeleteShortPayExpReport');
9340
9341 IF (p_funmode = 'RUN') THEN
9342
9343 ----------------------------------------------------------------
9344 l_debug_info := 'Retrieve New_Expense_Report_ID Item Attribute';
9345 ----------------------------------------------------------------
9346 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
9347 p_item_key,
9348 'NEW_EXPENSE_REPORT_ID');
9349
9350 DeleteExpReportFromAPTables(l_report_header_id);
9351
9352 ELSIF (p_funmode = 'CANCEL') THEN
9353 p_result := 'COMPLETE';
9354 END IF;
9355
9356 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end DeleteShortPayExpReport');
9357
9358 EXCEPTION
9359 WHEN OTHERS THEN
9360 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'DeleteShortPayExpReport',
9361 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
9362 raise;
9363 END DeleteShortPayExpReport;
9364
9365 ---------------------------------------------------------
9366 PROCEDURE RequireProofOfPayment(p_item_type IN VARCHAR2,
9367 p_item_key IN VARCHAR2,
9368 p_actid IN NUMBER,
9369 p_funmode IN VARCHAR2,
9370 p_result OUT NOCOPY VARCHAR2) IS
9371 ---------------------------------------------------------
9372 l_require_proof_of_payment VARCHAR2(1);
9373 l_report_header_id AP_WEB_DB_EXPLINE_PKG.expLines_headerID;
9374 l_debug_info VARCHAR2(200);
9375 BEGIN
9376
9377 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start RequireProofOfPayment');
9378
9379 IF (p_funmode = 'RUN') THEN
9380
9381 ---------------------------------------------------------------------------
9382 l_debug_info := 'Retrieve Include_Missing_Receipts Activity Attribute';
9383 ---------------------------------------------------------------------------
9384 l_require_proof_of_payment := WF_ENGINE.GetActivityAttrText(p_item_type,
9385 p_item_key,
9386 p_actid,
9387 'ALWAYS_REQ_PROOF_OF_PAYMENT');
9388
9389 IF (l_require_proof_of_payment = 'N') THEN
9390
9391 ----------------------------------------------------------------
9392 l_debug_info := 'Retrieving EXPENSE_REPORT_ID Item Attribute';
9393 ----------------------------------------------------------------
9394 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
9395 p_item_key,
9396 'EXPENSE_REPORT_ID');
9397
9398
9399 IF (NOT AP_WEB_DB_EXPLINE_PKG.SetReceiptRequired(l_report_header_id, 'N')) THEN
9400 NULL;
9401 END IF;
9402
9403 END IF;
9404
9405 ELSIF (p_funmode = 'CANCEL') THEN
9406 p_result := 'COMPLETE';
9407 END IF;
9408
9409 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end RequireProofOfPayment');
9410
9411 EXCEPTION
9412 WHEN OTHERS THEN
9413 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'RequireProofOfPayment',
9414 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
9415 RAISE;
9416
9417 END RequireProofOfPayment;
9418
9419 /*
9420 Written by:
9421 Quan Le
9422 Purpose:
9423 To generate the value for LINE_TABLE document attribute of Expense Workflow. This procedure follows
9424 predefined API. See Workflow API documentation for more informfation.
9425 Input:
9426 See Workflow API documentation.
9427 Output:
9428 See Workflow API documentation.
9429 Input Output:
9430 See Workflow API documentation.
9431 Assumption:
9432 document_id is assumed to have the following format:
9433 <item_key>:<item_id>
9434 Date:
9435 1/4/99
9436 */
9437
9438 PROCEDURE GenerateExpLines(document_id IN VARCHAR2,
9439 display_type IN VARCHAR2,
9440 document IN OUT NOCOPY VARCHAR2,
9441 document_type IN OUT NOCOPY VARCHAR2) IS
9442
9443 l_document_max NUMBER := 25000; -- 27721 fails
9444 l_debug_info VARCHAR2(1000);
9445 l_message Wf_Item_Attribute_Values.TEXT_VALUE%TYPE;
9446 l_temp_clob CLOB;
9447 l_colon NUMBER;
9448 BEGIN
9449
9450 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start GenerateExpLines');
9451
9452 WF_NOTIFICATION.NewClob(l_temp_clob,document);
9453 GenerateExpClobLines(document_id,
9454 display_type,
9455 l_temp_clob,
9456 document_type);
9457 dbms_lob.read(l_temp_clob,l_document_max,1,document);
9458
9459 if (dbms_lob.getlength(l_temp_clob) > l_document_max) then
9460
9461 l_colon := instr(document, tr_end,-1);
9462 document := substr(document,1,l_colon+4);
9463 document := document || table_end || indent_end;
9464
9465 FND_MESSAGE.SET_NAME('SQLAP','AP_WEB_EXP_UNABLE_TO_SHOWLINES');
9466 l_message := FND_MESSAGE.GET;
9467 document := document || table_start;
9468 document := document || tr_start || '&' || 'nbsp;' || tr_end;
9469 document := document || tr_start || '&' || 'nbsp;' || tr_end;
9470 document := document || tr_start || td_start || l_message || td_end || tr_end;
9471 document := document || table_end || indent_end;
9472
9473 end if;
9474
9475 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end GenerateExpLines');
9476
9477 EXCEPTION
9478 WHEN OTHERS THEN
9479 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'GenerateExpLines',
9480 document_id, l_debug_info);
9481 raise;
9482 END GenerateExpLines;
9483
9484
9485 /*
9486 Written by:
9487 Quan Le
9488 Purpose:
9489 To generate the value for document attribute of Expense Workflow. This procedure follows
9490 predefined API. See Workflow API documentation for more informfation. Currently this procedure
9491 is used for PURPOSE attribute only.
9492 Input:
9493 See Workflow API documentation.
9494 Output:
9495 See Workflow API documentation.
9496 Input Output:
9497 See Workflow API documentation.
9498 Assumption:
9499 document_id is assumed to have the following format:
9500 <item_key>:<item_id>:<item attribute>
9501 Date:
9502 1/4/99
9503 */
9504 PROCEDURE GenerateDocumentAttributeValue(document_id IN VARCHAR2,
9505 display_type IN VARCHAR2,
9506 document IN OUT NOCOPY VARCHAR2,
9507 document_type IN OUT NOCOPY VARCHAR2) IS
9508 l_colon NUMBER;
9509 l_colon2 NUMBER;
9510 l_itemtype VARCHAR2(7);
9511 l_itemkey VARCHAR2(15);
9512 l_attribute VARCHAR2(30);
9513 l_debug_info VARCHAR2(1000);
9514 BEGIN
9515
9516 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start GenerateDocumentAttributeValue');
9517
9518 document := '';
9519
9520 l_debug_info := 'Decode document_id';
9521
9522 l_colon := instrb(document_id, ':');
9523 l_colon2 := instrb(document_id, ':', l_colon+1);
9524 l_itemtype := substrb(document_id, 1, l_colon - 1);
9525 l_itemkey := substrb(document_id, l_colon + 1, l_colon2 - l_colon -1);
9526 l_attribute := substrb(document_id, l_colon2 + 1);
9527
9528 if (display_type = 'text/plain') then
9529 if (l_attribute = 'PURPOSE') then
9530 document := WF_ENGINE.GetItemAttrText(l_itemtype,
9531 l_itemkey,
9532 'PURPOSE');
9533 end if;
9534 else -- html
9535 if (l_attribute = 'PURPOSE') then
9536 document := '<B>' || WF_ENGINE.GetItemAttrText(l_itemtype, l_itemkey, 'PURPOSE') || '</B>';
9537 end if;
9538 end if;
9539 document_type := display_type;
9540
9541 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end GenerateDocumentAttributeValue');
9542
9543 EXCEPTION
9544 WHEN OTHERS THEN
9545 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'GenerateDocumentAttributeValue',
9546 document_id, l_debug_info);
9547 raise;
9548 END GenerateDocumentAttributeValue;
9549
9550
9551
9552 /**
9553 * jrautiai ADJ Fix Removed shortpay and adjustment specific logic form elsewhere, so instead here
9554 * we are dealing with both cases using common logic.
9555 */
9556 PROCEDURE BuildAdjustmentInfoLine(p_display_type IN VARCHAR2,
9557 adjustment_rec IN AP_WEB_DB_EXPLINE_PKG.AdjustmentRecordType,
9558 p_adjustment_type IN VARCHAR2,
9559 p_currency IN VARCHAR2,
9560 p_adjustment_line IN OUT NOCOPY VARCHAR2) IS
9561
9562 l_debug_info VARCHAR2(1000);
9563 l_item_type VARCHAR2(30);
9564 l_report_header_id NUMBER;
9565 l_adjustment_line VARCHAR2(2000);
9566
9567 BEGIN
9568
9569 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start BuildAdjustmentInfoLine');
9570
9571 IF p_adjustment_type = 'ADJUSTMENT' THEN
9572 ------------------------------------------------------------------
9573 l_debug_info := 'Format Adjustment Line with amount' || adjustment_rec.amount;
9574 ------------------------------------------------------------------
9575 IF (p_display_type = 'text/plain') THEN
9576 l_adjustment_line := adjustment_rec.expense_type_disp || ' ' || adjustment_rec.amount || ' ' || adjustment_rec.adjustment_reason;
9577 p_adjustment_line := p_adjustment_line || '
9578 ' || l_adjustment_line;
9579 ELSE -- HTML type
9580 p_adjustment_line := p_adjustment_line || tr_start;
9581 -- 'Receipt Date'
9582 p_adjustment_line := p_adjustment_line || td_text || adjustment_rec.start_expense_date || td_end;
9583 -- 'Expense Type'
9584 p_adjustment_line := p_adjustment_line || td_text || adjustment_rec.expense_type_disp || td_end;
9585 -- 'Original Amount'
9586 p_adjustment_line := p_adjustment_line || td_number ||
9587 NVL(to_char(adjustment_rec.submitted_amount, FND_CURRENCY.Get_Format_Mask(p_currency,22)), '&' || 'nbsp;') || td_end;
9588 -- 'Adjustment'
9589 p_adjustment_line := p_adjustment_line || td_number ||
9590 NVL(to_char(adjustment_rec.adjusted_amount, FND_CURRENCY.Get_Format_Mask(p_currency,22)), '&' || 'nbsp;') || td_end;
9591 -- 'New Amount'
9592 p_adjustment_line := p_adjustment_line || td_number || to_char(adjustment_rec.amount, FND_CURRENCY.Get_Format_Mask(p_currency,22)) || td_end;
9593 -- 'Credit Card Expense'
9594 p_adjustment_line := p_adjustment_line || td_text || NVL(adjustment_rec.credit_card_expense_disp, '&' || 'nbsp;') || td_end;
9595 -- 'Justification'
9596 p_adjustment_line := p_adjustment_line || td_text || nvl(WF_NOTIFICATION.SubstituteSpecialChars(adjustment_rec.justification), '&' || 'nbsp;') || td_end;
9597 -- 'Instructions'
9598 p_adjustment_line := p_adjustment_line || td_text;
9599 if (adjustment_rec.adjustment_reason_code_disp is not null) then
9600 p_adjustment_line := p_adjustment_line || WF_NOTIFICATION.SubstituteSpecialChars(adjustment_rec.adjustment_reason_code_disp) ||'<br>';
9601 else
9602 p_adjustment_line := p_adjustment_line || '&'||'nbsp;';
9603 end if;
9604 if (adjustment_rec.adjustment_reason_description is not null) then
9605 p_adjustment_line := p_adjustment_line || WF_NOTIFICATION.SubstituteSpecialChars(adjustment_rec.adjustment_reason_description) ||'<br>';
9606 else
9607 p_adjustment_line := p_adjustment_line || '&'||'nbsp;';
9608 end if;
9609 if (adjustment_rec.adjustment_reason is not null) then
9610 p_adjustment_line := p_adjustment_line || WF_NOTIFICATION.SubstituteSpecialChars(adjustment_rec.adjustment_reason);
9611 else
9612 p_adjustment_line := p_adjustment_line || '&'||'nbsp;';
9613 end if;
9614 p_adjustment_line := p_adjustment_line || td_end;
9615 p_adjustment_line := p_adjustment_line || tr_end;
9616 END IF;
9617 ELSIF p_adjustment_type = 'AUDIT' THEN
9618 IF (p_display_type = 'text/plain') THEN
9619 l_adjustment_line := adjustment_rec.expense_type_disp || ' ' || adjustment_rec.amount || ' ' || WF_NOTIFICATION.SubstituteSpecialChars(adjustment_rec.adjustment_reason);
9620 p_adjustment_line := p_adjustment_line || '
9621 ' || l_adjustment_line;
9622 ELSE -- HTML type
9623 p_adjustment_line := p_adjustment_line || tr_start;
9624 -- 'Receipt Date'
9625 p_adjustment_line := p_adjustment_line || td_text || adjustment_rec.start_expense_date || td_end;
9626 -- 'Expense Type'
9627 p_adjustment_line := p_adjustment_line || td_text || adjustment_rec.expense_type_disp || td_end;
9628 -- 'Amount'
9629 p_adjustment_line := p_adjustment_line || td_number ||
9630 NVL(to_char(adjustment_rec.amount, FND_CURRENCY.Get_Format_Mask(p_currency,22)), '&' || 'nbsp;') || td_end;
9631 -- 'Justification'
9632 p_adjustment_line := p_adjustment_line || td_text || nvl(WF_NOTIFICATION.SubstituteSpecialChars(adjustment_rec.justification), '&' || 'nbsp;') || td_end;
9633 -- 'Instructions'
9634 p_adjustment_line := p_adjustment_line || td_text;
9635 if (adjustment_rec.adjustment_reason_code_disp is not null) then
9636 p_adjustment_line := p_adjustment_line || WF_NOTIFICATION.SubstituteSpecialChars(adjustment_rec.adjustment_reason_code_disp) ||'<br>';
9637 else
9638 p_adjustment_line := p_adjustment_line || '&'||'nbsp;';
9639 end if;
9640 if (adjustment_rec.adjustment_reason_description is not null) then
9641 p_adjustment_line := p_adjustment_line || WF_NOTIFICATION.SubstituteSpecialChars(adjustment_rec.adjustment_reason_description) ||'<br>';
9642 else
9643 p_adjustment_line := p_adjustment_line || '&'||'nbsp;';
9644 end if;
9645 if (adjustment_rec.adjustment_reason is not null) then
9646 p_adjustment_line := p_adjustment_line || WF_NOTIFICATION.SubstituteSpecialChars(adjustment_rec.adjustment_reason);
9647 else
9648 p_adjustment_line := p_adjustment_line || '&'||'nbsp;';
9649 end if;
9650 p_adjustment_line := p_adjustment_line || td_end;
9651 p_adjustment_line := p_adjustment_line || tr_end;
9652 END IF;
9653 ELSE
9654 IF (p_display_type = 'text/plain') THEN
9655 l_adjustment_line := adjustment_rec.expense_type_disp || ' ' || adjustment_rec.amount || ' ' || WF_NOTIFICATION.SubstituteSpecialChars(adjustment_rec.adjustment_reason);
9656 p_adjustment_line := p_adjustment_line || '
9657 ' || l_adjustment_line;
9658 ELSE -- HTML type
9659 p_adjustment_line := p_adjustment_line || tr_start;
9660 -- 'Receipt Date'
9661 p_adjustment_line := p_adjustment_line || td_text || adjustment_rec.start_expense_date || td_end;
9662 -- 'Expense Type'
9663 p_adjustment_line := p_adjustment_line || td_text || adjustment_rec.expense_type_disp || td_end;
9664 -- 'Amount'
9665 p_adjustment_line := p_adjustment_line || td_number ||
9666 NVL(to_char(adjustment_rec.amount, FND_CURRENCY.Get_Format_Mask(p_currency,22)), '&' || 'nbsp;') || td_end;
9667 -- 'Itemized Expense'
9668 p_adjustment_line := p_adjustment_line || td_text || NVL(adjustment_rec.itemized_expense_disp, '&' || 'nbsp;') || td_end;
9669 -- 'Justification'
9670 p_adjustment_line := p_adjustment_line || td_text || nvl(WF_NOTIFICATION.SubstituteSpecialChars(adjustment_rec.justification), '&' || 'nbsp;') || td_end;
9671 -- 'Instructions'
9672 p_adjustment_line := p_adjustment_line || td_text;
9673 if (adjustment_rec.adjustment_reason_code_disp is not null) then
9674 p_adjustment_line := p_adjustment_line || WF_NOTIFICATION.SubstituteSpecialChars(adjustment_rec.adjustment_reason_code_disp) ||'<br>';
9675 else
9676 p_adjustment_line := p_adjustment_line || '&'||'nbsp;';
9677 end if;
9678 if (adjustment_rec.adjustment_reason_description is not null) then
9679 p_adjustment_line := p_adjustment_line || WF_NOTIFICATION.SubstituteSpecialChars(adjustment_rec.adjustment_reason_description) ||'<br>';
9680 else
9681 p_adjustment_line := p_adjustment_line || '&'||'nbsp;';
9682 end if;
9683 if (adjustment_rec.adjustment_reason is not null) then
9684 p_adjustment_line := p_adjustment_line || WF_NOTIFICATION.SubstituteSpecialChars(adjustment_rec.adjustment_reason);
9685 else
9686 p_adjustment_line := p_adjustment_line || '&'||'nbsp;';
9687 end if;
9688 p_adjustment_line := p_adjustment_line || td_end;
9689 p_adjustment_line := p_adjustment_line || tr_end;
9690 END IF;
9691 END IF; -- p_adjustment_type = 'ADJUSTMENT'
9692
9693 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end BuildAdjustmentInfoLine');
9694
9695 EXCEPTION
9696 WHEN OTHERS THEN
9697 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'BuildAdjustmentInfoLine',
9698 '', l_debug_info);
9699 raise;
9700 END BuildAdjustmentInfoLine;
9701
9702
9703 PROCEDURE GenerateAdjustmentInfo(document_id IN VARCHAR2,
9704 display_type IN VARCHAR2,
9705 document IN OUT NOCOPY VARCHAR2,
9706 document_type IN OUT NOCOPY VARCHAR2) IS
9707 l_document_max NUMBER:=25000;
9708 l_debug_info VARCHAR2(1000);
9709 l_message VARCHAR2(2000);
9710 l_temp_clob CLOB;
9711 l_colon NUMBER;--namrata
9712 BEGIN
9713 WF_NOTIFICATION.NewClob(l_temp_clob,document);
9714
9715 GenerateAdjustmentInfoClob(document_id,
9716 display_type,
9717 l_temp_clob,
9718 document_type);
9719
9720 dbms_lob.read(l_temp_clob,l_document_max,1,document);
9721
9722 if (dbms_lob.getlength(l_temp_clob) > l_document_max) then
9723
9724 l_colon := instr(document, '</tr>',-1);
9725 document := substr(document,1,l_colon+4);
9726 document := document || '</table><br>';
9727
9728 FND_MESSAGE.SET_NAME('SQLAP','AP_WEB_EXP_UNABLE_TO_SHOWLINES');
9729 l_message := FND_MESSAGE.GET;
9730 document := document || '<table>';
9731 document := document || '<tr> </tr>';
9732 document := document || '<tr> </tr>';
9733 document := document || '<tr><td>' || l_message || '</td></tr>';
9734 document := document || '</table>';
9735
9736
9737 end if;
9738 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end GenerateAdjustmentInfo');
9739
9740 EXCEPTION
9741 WHEN OTHERS THEN
9742 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'GenerateAdjustmentInfo',
9743 document_id, l_debug_info);
9744 raise;
9745 END GenerateAdjustmentInfo;
9746
9747 --namrata
9748
9749 PROCEDURE GenerateAdjustmentInfoClob(document_id IN VARCHAR2,
9750 display_type IN VARCHAR2,
9751 document IN OUT NOCOPY CLOB,
9752 document_type IN OUT NOCOPY VARCHAR2) IS
9753
9754 l_document long;--namrata
9755 l_document_max NUMBER:=25000;--namrata
9756 l_debug_info VARCHAR2(1000);
9757 l_item_type VARCHAR2(30);
9758 l_report_header_id AP_WEB_DB_EXPLINE_PKG.expLines_headerID;
9759 l_adjustment_line VARCHAR2(2000);
9760 l_adj_info_body VARCHAR2(2000);
9761 l_itemtype VARCHAR2(7);
9762 l_itemkey VARCHAR2(30);
9763 l_currency VARCHAR2(50);
9764 l_colon NUMBER;
9765
9766 -- Bug 3336259: CC SP and ADJ Fix
9767 l_adj_code VARCHAR2(100) := 'ADJUSTMENT'; --default is Adjustments
9768 l_prompts AP_WEB_UTILITIES_PKG.prompts_table;
9769 l_title AK_REGIONS_VL.name%TYPE;
9770
9771 -- Bug 3336259: CC SP and ADJ Fix, changed to refer the new cursor type.
9772 AdjustmentsCursor AP_WEB_DB_EXPLINE_PKG.AdjustmentCursorType;
9773
9774 -- Bug 3336259: CC SP and ADJ Fix, fetching the results into a record of a common type.
9775 adjustment_rec AP_WEB_DB_EXPLINE_PKG.AdjustmentRecordType;
9776
9777 l_colspan NUMBER :=0;
9778 l_total_adjustment NUMBER :=0;
9779 l_total_amount NUMBER :=0;
9780 l_total_disp NUMBER :=0;
9781
9782 l_n_org_id Number;
9783 BEGIN
9784
9785 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start GenerateAdjustmentInfo');
9786
9787 ------------------------------------------------------------
9788 l_debug_info := 'Decode document_id';
9789 ------------------------------------------------------------
9790 l_colon := instrb(document_id, ':');
9791
9792 ------------------------------------------------------------------------------
9793 l_debug_info := ' First index: ' || to_char(l_colon);
9794 ------------------------------------------------------------------------------
9795 l_itemtype := substrb(document_id, 1, l_colon - 1);
9796 l_itemkey := substrb(document_id, l_colon + 1);
9797
9798 ------------------------------------------------------------
9799 l_debug_info := 'Retrieve Adjustment Code';
9800 ------------------------------------------------------------
9801 l_colon := instrb(l_itemkey, ':');
9802 ------------------------------------------------------------------------------
9803 l_debug_info := 'Second index: ' || to_char(l_colon);
9804 ------------------------------------------------------------------------------
9805 l_adj_code := substrb(l_itemkey, l_colon + 1);
9806 l_itemkey := substrb(l_itemkey, 1, l_colon - 1);
9807
9808 ------------------------------------------------------------
9809 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
9810 ------------------------------------------------------------
9811 l_report_header_id := WF_ENGINE.GetItemAttrNumber(l_itemtype,
9812 l_itemkey,
9813 'EXPENSE_REPORT_ID');
9814
9815 ----------------------------------------------------
9816 l_debug_info := 'Retrieve Currency Item Attribute';
9817 ----------------------------------------------------
9818 l_currency := WF_ENGINE.GetItemAttrText(l_itemtype,
9819 l_itemkey,
9820 'CURRENCY');
9821
9822 --------------------------------------------
9823 l_debug_info := 'Get Org Id';
9824 --------------------------------------------
9825 begin
9826
9827 l_n_org_id := WF_ENGINE.GetItemAttrNumber(l_itemtype,
9828 l_itemkey,
9829 'ORG_ID');
9830 exception
9831 when others then
9832 if (wf_core.error_name = 'WFENG_ITEM_ATTR') then
9833 -- ORG_ID item attribute doesn't exist, need to add it
9834 WF_ENGINE.AddItemAttr(l_itemtype, l_itemkey, 'ORG_ID');
9835 IF (AP_WEB_DB_EXPRPT_PKG.GetOrgIdByReportHeaderId(
9836 to_number(l_itemkey),
9837 l_n_org_id) <> TRUE ) THEN
9838 l_n_org_id := NULL;
9839 END IF;
9840
9841 WF_ENGINE.SetItemAttrNumber(l_itemtype,
9842 l_itemkey,
9843 'ORG_ID',
9844 l_n_org_ID);
9845 else
9846 raise;
9847 end if;
9848
9849 end;
9850
9851 -- MOAC UPTAKE --
9852 -- Should not have to initialize the org context
9853 -- This is done via callbackfunction()
9854 /*--------------------
9855 if (l_n_org_id is not null) then
9856 fnd_client_info.set_org_context(l_n_org_id);
9857 else
9858 -- Report was submitted before org_id being added, hence org_id
9859 -- item attributes hasn't been set yet. Need to get it from
9860 -- report header
9861 IF (AP_WEB_DB_EXPRPT_PKG.GetOrgIdByReportHeaderId(
9862 to_number(l_itemkey),
9863 l_n_org_id) <> TRUE ) THEN
9864 l_n_org_id := NULL;
9865 END IF;
9866
9867 IF (l_n_org_id is not null) then
9868 fnd_client_info.set_org_context(l_n_org_id);
9869 END IF;
9870
9871 end if;
9872 ------------------------*/
9873
9874
9875 IF (display_type = 'text/plain') THEN
9876 l_document := '';
9877 ELSE -- HTML
9878 ----------------------------------
9879 l_debug_info := 'Get prompts';
9880 ----------------------------------
9881 AP_WEB_DISC_PKG.getPrompts(200,'AP_WEB_WF_LINETABLE',l_title,l_prompts);
9882
9883 /**
9884 * Bug 3336259: CC SP and ADJ Fix start
9885 * set the table header depending whether we are building adjustment, policy violation or missing receipts table
9886 */
9887 IF (l_adj_code = 'ADJUSTMENT') THEN
9888 l_document := '<b>' || l_prompts(16) || '</b><br>';
9889 ELSE
9890 IF (l_adj_code = 'POLICY') THEN
9891 l_document := '<b>' || l_prompts(17) || '</b><br>';
9892 ELSIF (l_adj_code = 'AUDIT') THEN -- no table header for AUDIT
9893 document := '<br>';
9894 ELSE -- missing receipts
9895 l_document := '<b>' || l_prompts(18) || '</b><br>';
9896 END IF;
9897 END IF;
9898 /**
9899 * Bug 3336259: CC SP and ADJ Fix end
9900 */
9901
9902 l_document := l_document || '<table bgcolor='||table_bgcolor||' width='||table_width||' border='||table_border||' cellpadding='||table_cellpadding||' cellspacing='||table_cellspacing||'>';
9903
9904 l_document := l_document || '<tr bgcolor='||th_bgcolor||'>';
9905 /**
9906 * Bug 3336259: CC SP and ADJ Fix start
9907 * set the table column headers depending whether we are building adjustment or shortpay table
9908 */
9909 IF (l_adj_code = 'ADJUSTMENT') THEN
9910 -- 'Receipt Date'
9911 l_document := l_document || '<td align="left"><font color='||th_fontcolor||' face='||th_fontface||'><b>' || l_prompts(4) || '</b></td>';
9912 -- 'Expense Type'
9913 l_document := l_document || '<td align="left"><font color='||th_fontcolor||' face='||th_fontface||'><b>' || l_prompts(5) || '</b></td>';
9914 -- 'Original Amount (REIMBURSEMENT_CURRENCY)'
9915 l_document := l_document || '<td align="left"><font color='||th_fontcolor||' face='||th_fontface||'><b>' || l_prompts(19) || ' ('||l_currency||')' || '</b></td>';
9916 -- 'Adjustment (REIMBURSEMENT_CURRENCY)'
9917 l_document := l_document || '<td align="left"><font color='||th_fontcolor||' face='||th_fontface||'><b>' || l_prompts(20) || ' ('||l_currency||')' || '</b></td>';
9918 -- 'New Amount (REIMBURSEMENT_CURRENCY)'
9919 l_document := l_document || '<td align="left"><font color='||th_fontcolor||' face='||th_fontface||'><b>' || l_prompts(21) || ' ('||l_currency||')' || '</b></td>';
9920 -- 'Credit Card Expense'
9921 l_document := l_document || '<td align="left"><font color='||th_fontcolor||' face='||th_fontface||'><b>' || l_prompts(22) || '</b></td>';
9922 -- 'Adjustment Reason'
9923 l_document := l_document || '<td align="left"><font color='||th_fontcolor||' face='||th_fontface||'><b>' || l_prompts(23) || '</b></td>';
9924 -- 'Adjustment Comments'
9925 l_document := l_document || '<td align="left"><font color='||th_fontcolor||' face='||th_fontface||'><b>' || l_prompts(11) || '</b></td></tr>';
9926 ELSE
9927 -- 'Receipt Date'
9928 l_document := l_document || '<td align="left"><font color='||th_fontcolor||' face='||th_fontface||'><b>' || l_prompts(4) || '</b></td>';
9929 -- 'Expense Type'
9930 l_document := l_document || '<td align="left"><font color='||th_fontcolor||' face='||th_fontface||'><b>' || l_prompts(5) || '</b></td>';
9931 -- 'Amount (REIMBURSEMENT_CURRENCY)'
9932 l_document := l_document || '<td align="left"><font color='||th_fontcolor||' face='||th_fontface||'><b>' || l_prompts(9) || ' ('||l_currency||')' || '</b></td>';
9933 -- 'Itemized Expense'
9934 l_document := l_document || '<td align="left"><font color='||th_fontcolor||' face='||th_fontface||'><b>' || l_prompts(24) || '</b></td>';
9935 -- 'Adjustment Reason'
9936 l_document := l_document || '<td align="left"><font color='||th_fontcolor||' face='||th_fontface||'><b>' || l_prompts(25) || '</b></td>';
9937 -- 'Adjustment Comments'
9938 l_document := l_document || '<td align="left"><font color='||th_fontcolor||' face='||th_fontface||'><b>' || l_prompts(26) || '</b></td></tr>';
9939 END IF;
9940 /**
9941 * Bug 3336259: CC SP and ADJ Fix end
9942 */
9943 END IF;
9944
9945 ------------------------------------------
9946 l_debug_info := 'Read Adjustments Cursor';
9947 ------------------------------------------
9948
9949 /**
9950 Bug 3336259: CC SP and ADJ Fix Start - Removed shortpay and adjustment specific logic, instead we are using the same
9951 * logic for both in GetAdjustmentsCursor and BuildAdjustmentInfoLine.
9952 */
9953 IF (AP_WEB_DB_EXPLINE_PKG.GetAdjustmentsCursor(l_report_header_id, l_adj_code, AdjustmentsCursor)) THEN
9954 LOOP
9955 FETCH AdjustmentsCursor INTO adjustment_rec;
9956 EXIT WHEN AdjustmentsCursor%NOTFOUND;
9957 BuildAdjustmentInfoLine(display_type,
9958 adjustment_rec,
9959 l_adj_code,
9960 l_currency,
9961 l_document);--namrata
9962
9963 IF lengthb(l_document)>=l_document_max THEN
9964 WF_NOTIFICATION.WriteToClob(document,l_document);
9965 l_document:='';--namrata
9966 END IF;
9967
9968
9969 l_total_adjustment := l_total_adjustment + adjustment_rec.adjusted_amount;
9970 l_total_amount := l_total_amount + adjustment_rec.amount;
9971 END LOOP;
9972
9973 CLOSE AdjustmentsCursor;
9974 END IF;
9975
9976 /**
9977 * Bug 3336259: CC SP and ADJ Fix end
9978 */
9979
9980 IF (display_type = 'text/html') THEN
9981 /**
9982 * Bug 3336259: CC SP and ADJ Fix Start
9983 */
9984 --------------------------------------------
9985 l_debug_info := 'Generate Total Row';
9986 --------------------------------------------
9987 l_document := l_document || '<tr bgcolor='||th_bgcolor||'>';
9988
9989 IF l_adj_code = 'ADJUSTMENT' THEN
9990 -- display Total
9991 l_document := l_document || '<td colspan=3 align="right"><font color='||th_fontcolor||' face='||th_fontface||'><b>' || l_prompts(12) || '</b></td>';
9992 l_document := l_document || '<td bgcolor='||td_bgcolor||' align="left"><font color='||td_fontcolor||' face='||td_fontface||'>'|| LPAD(to_char(l_total_adjustment, FND_CURRENCY.Get_Format_Mask(l_currency,22)),14) || '</td>';
9993 l_document := l_document || '<td colspan=4 align="right"><font color='||th_fontcolor||' face='||th_fontface||'></td>';
9994 ELSE
9995 l_document := l_document || '<td colspan=2 align="right"><font color='||th_fontcolor||' face='||th_fontface||'><b>' || l_prompts(12) || '</b></td>';
9996 l_document := l_document || '<td bgcolor='||td_bgcolor||' align="left"><font color='||td_fontcolor||' face='||td_fontface||'>'|| LPAD(to_char(l_total_amount, FND_CURRENCY.Get_Format_Mask(l_currency,22)),14) || '</td>';
9997 l_document := l_document || '<td colspan=3 align="right"><font color='||th_fontcolor||' face='||th_fontface||'></td>';
9998 END IF;
9999
10000 l_document := l_document || '</tr>';
10001 l_document := l_document || '</table><br>';
10002 /**
10003 * Bug 3336259: CC SP and ADJ Fix end
10004 */
10005 END IF;
10006
10007 IF l_document is not null THEN
10008 WF_NOTIFICATION.WriteToClob(document,l_document);
10009 END IF;
10010
10011 document_type := display_type;
10012
10013 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end GenerateAdjustmentInfoClob');
10014
10015 EXCEPTION
10016 WHEN OTHERS THEN
10017 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'GenerateAdjustmentInfoClob',
10018 document_id, l_debug_info);
10019 raise;
10020 END GenerateAdjustmentInfoClob;
10021
10022 PROCEDURE ResetLineInfo(document_id IN VARCHAR2,
10023 display_type IN VARCHAR2,
10024 document IN OUT NOCOPY VARCHAR2,
10025 document_type IN OUT NOCOPY VARCHAR2) IS
10026 l_debug_info VARCHAR2(1000);
10027 BEGIN
10028
10029 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start ResetLineInfo');
10030
10031 ------------------------------------------------------------------
10032 l_debug_info := 'Reset Line Info Body';
10033 ------------------------------------------------------------------
10034
10035 document := '';
10036 document_type := display_type;
10037
10038 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end ResetLineInfo');
10039
10040 EXCEPTION
10041 WHEN OTHERS THEN
10042 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'ResetLineInfo',
10043 document_id, l_debug_info);
10044 raise;
10045 END ResetLineInfo;
10046
10047 ----------------------------------------------------------------------
10048 PROCEDURE CallbackFunction( p_s_item_type IN VARCHAR2,
10049 p_s_item_key IN VARCHAR2,
10050 p_n_actid IN NUMBER,
10051 p_s_command IN VARCHAR2,
10052 p_s_result OUT NOCOPY VARCHAR2) IS
10053 ----------------------------------------------------------------------
10054 l_n_org_id Number;
10055 l_n_user_id Number;
10056 l_n_resp_id Number;
10057 l_n_resp_appl_id Number;
10058 l_current_org_id Number;
10059 l_current_user_id Number;
10060 l_current_resp_id Number;
10061 l_current_resp_appl_id Number;
10062
10063
10064 BEGIN
10065
10066 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start CallbackFunction');
10067
10068 begin
10069
10070 l_n_org_id := WF_ENGINE.GetItemAttrNumber(p_s_item_type,
10071 p_s_item_key,
10072 'ORG_ID');
10073 exception
10074 when others then
10075 if (wf_core.error_name = 'WFENG_ITEM_ATTR') then
10076 -- ORG_ID item attribute doesn't exist, need to add it
10077 wf_engine.AddItemAttr(p_s_item_type, p_s_item_key, 'ORG_ID');
10078 -- get the org_id from header for old reports
10079 IF (AP_WEB_DB_EXPRPT_PKG.GetOrgIdByReportHeaderId(
10080 to_number(p_s_item_key),
10081 l_n_org_id) <> TRUE ) THEN
10082 l_n_org_id := NULL;
10083 END IF;
10084 WF_ENGINE.SetItemAttrNumber(p_s_item_type,
10085 p_s_item_key,
10086 'ORG_ID',
10087 l_n_org_id);
10088 else
10089 raise;
10090 end if;
10091
10092 end;
10093
10094 begin
10095 l_n_user_id := WF_ENGINE.GetItemAttrNumber(p_s_item_type,
10096 p_s_item_key,
10097 'USER_ID');
10098
10099 l_n_resp_id := WF_ENGINE.GetItemAttrNumber(p_s_item_type,
10100 p_s_item_key,
10101 'RESPONSIBILITY_ID');
10102
10103 l_n_resp_appl_id := WF_ENGINE.GetItemAttrNumber(p_s_item_type,
10104 p_s_item_key,
10105 'APPLICATION_ID');
10106 exception
10107 when others then
10108 if (wf_core.error_name = 'WFENG_ITEM_ATTR') then
10109 null;
10110 else
10111 raise;
10112 end if;
10113 end;
10114
10115
10116 IF (p_s_command = 'SET_CTX') THEN
10117
10118 -- Set the context
10119 FND_GLOBAL.APPS_INITIALIZE( USER_ID => l_n_user_id,
10120 RESP_ID => l_n_resp_id,
10121 RESP_APPL_ID => l_n_resp_appl_id
10122 );
10123
10124 -- Set Org context
10125 -- Needs to be after FND_GLOBAL.APPS_INITIALIZE because
10126 -- user_id, resp_id, and appl_id may be null because
10127 -- the attributes don't exist or because they are not set
10128 if (l_n_org_id is not null) then
10129 mo_global.set_policy_context(p_access_mode => 'S',
10130 p_org_id => l_n_org_id);
10131 end if;
10132
10133 -- Set Accounting Flexfield validation context
10134 AP_WEB_DB_GL_INT_PKG.set_aff_validation_org_context(l_n_org_id);
10135
10136 ELSIF (p_s_command = 'TEST_CTX') THEN
10137
10138 /* Bug 4319321 : Need to check the values of user_id, resp_id
10139 * and resp_appl_id as well.
10140 */
10141 l_current_user_id := TO_NUMBER(FND_PROFILE.VALUE('USER_ID'));
10142 l_current_resp_id := TO_NUMBER(FND_PROFILE.VALUE('RESP_ID'));
10143 l_current_resp_appl_id := TO_NUMBER(FND_PROFILE.VALUE('RESP_APPL_ID'));
10144 l_current_org_id := nvl(mo_global.get_current_org_id, -99);
10145
10146 /* Bug 4711393 : Should return NOTSET instead of FALSE in test_ctx mode
10147 * so that the actual context can get set via call in
10148 * set_ctx mode. This would avoid incorrect deferred state
10149 */
10150 IF (nvl(mo_global.get_access_mode, 'NULL') <> 'S') THEN
10151 p_s_result := 'NOTSET';
10152 ELSIF l_n_user_id IS NULL
10153 OR l_n_resp_id IS NULL
10154 OR l_n_resp_appl_id IS NULL THEN
10155 /* This condition should not occur. But if it does, do not reset the context*/
10156 p_s_result := 'TRUE';
10157 ELSIF l_current_user_id IS NULL
10158 OR l_current_resp_id IS NULL
10159 OR l_current_resp_appl_id IS NULL
10160 OR l_current_resp_id = -1
10161 OR l_current_resp_appl_id = -1 THEN
10162 /* Context is not set as yet. It will be set in SET_CTX mode call */
10163 p_s_result := 'NOTSET';
10164 ELSIF l_n_user_id=l_current_user_id
10165 AND l_n_resp_id=l_current_resp_id
10166 AND l_n_resp_appl_id=l_current_resp_appl_id THEN
10167 IF l_n_org_id <> l_current_org_id THEN
10168 /* Context is incorrect. Need to set it correctly in SET_CTX mode */
10169 p_s_result := 'NOTSET';
10170 ELSE
10171 /* will come here if either of l_org_id or l_current_org_id is null or both are equal
10172 * l_org_id or l_current_org_id is NULL means single org environment
10173 */
10174 p_s_result := 'TRUE';
10175 END IF;
10176 ELSE
10177 p_s_result := 'NOTSET';
10178 END IF;
10179
10180 END IF;
10181
10182 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end CallbackFunction');
10183
10184 END CallbackFunction;
10185
10186 ----------------------------------------------------------------------
10187 PROCEDURE IsPreparerToAuditorTransferred(
10188 p_item_type IN VARCHAR2,
10189 p_item_key IN VARCHAR2,
10190 p_actid IN NUMBER,
10191 p_funmode IN VARCHAR2,
10192 p_result OUT NOCOPY VARCHAR2) IS
10193 ----------------------------------------------------------------------
10194
10195 l_debug_info VARCHAR2(1000);
10196
10197 l_report_header_id AP_WEB_DB_EXPRPT_PKG.expHdr_headerID;
10198 l_entered_by NUMBER := fnd_global.user_id;
10199 l_role_info_tbl wf_directory.wf_local_roles_tbl_type;
10200
10201 l_orig_language_code ap_expense_params.note_language_code%type := null;
10202 l_orig_language fnd_languages.nls_language%type := null;
10203 l_new_language_code ap_expense_params.note_language_code%type := null;
10204 l_new_language fnd_languages.nls_language%type := null;
10205
10206 BEGIN
10207
10208 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start IsPreparerToAuditorTransferred');
10209
10210 if (p_funmode in ('QUESTION', 'ANSWER')) then
10211
10212 -------------------------------------------------------------------
10213 l_debug_info := 'Need to generate Note based on language setup';
10214 -------------------------------------------------------------------
10215
10216 -------------------------------------------------------------------
10217 l_debug_info := 'Save original language';
10218 -------------------------------------------------------------------
10219 l_orig_language_code := userenv('LANG');
10220 select nls_language
10221 into l_orig_language
10222 from fnd_languages
10223 where language_code = l_orig_language_code;
10224
10225 -------------------------------------------------------------------
10226 l_debug_info := 'Check AP_EXPENSE_PARAMS.NOTE_LANGUAGE_CODE';
10227 -------------------------------------------------------------------
10228 begin
10229 select note_language_code
10230 into l_new_language_code
10231 from ap_expense_params;
10232
10233 exception
10234 when no_data_found then
10235 null;
10236 end;
10237
10238 -------------------------------------------------------------------
10239 l_debug_info := 'Else use instance base language';
10240 -------------------------------------------------------------------
10241 if (l_new_language_code is null) then
10242 select language_code
10243 into l_new_language_code
10244 from fnd_languages
10245 where installed_flag in ('B');
10246 end if;
10247
10248 -------------------------------------------------------------------
10249 l_debug_info := 'Set nls context to new language';
10250 -------------------------------------------------------------------
10251 select nls_language
10252 into l_new_language
10253 from fnd_languages
10254 where language_code = l_new_language_code;
10255
10256 fnd_global.set_nls_context(p_nls_language => l_new_language);
10257
10258 ------------------------------------------------------------
10259 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
10260 ------------------------------------------------------------
10261 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
10262 p_item_key,
10263 'EXPENSE_REPORT_ID');
10264
10265 -----------------------------------------
10266 l_debug_info := 'Get the User Id';
10267 -----------------------------------------
10268 begin
10269
10270 WF_DIRECTORY.GetRoleInfo2(wf_engine.context_user, l_role_info_tbl);
10271 AP_WEB_OA_MAINFLOW_PKG.GetUserId(l_role_info_tbl(1).orig_system_id, l_entered_by);
10272
10273 exception
10274 when no_data_found then
10275 null;
10276 end;
10277
10278 ------------------------------------------------------------
10279 l_debug_info := 'store the Request More Info question/answer as a note';
10280 ------------------------------------------------------------
10281 AP_WEB_NOTES_PKG.CreateERPrepToAudNote (
10282 p_report_header_id => l_report_header_id,
10283 p_note => wf_core.translate(p_funmode)||'
10284 '||wf_engine.context_user_comment,
10285 p_lang => l_new_language_code,
10286 p_entered_by => l_entered_by
10287 );
10288
10289 -------------------------------------------------------------------
10290 l_debug_info := 'Restore nls context to original language';
10291 -------------------------------------------------------------------
10292 fnd_global.set_nls_context(p_nls_language => l_orig_language);
10293 END IF;
10294
10295 EXCEPTION
10296 WHEN OTHERS THEN
10297 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'IsPreparerToAuditorTransferred',
10298 p_item_type, p_item_key, to_char(0), l_debug_info);
10299 RAISE;
10300
10301 END IsPreparerToAuditorTransferred;
10302
10303 ----------------------------------------------------------------------
10304 PROCEDURE IsApprovalRequestTransferred(
10305 p_item_type IN VARCHAR2,
10306 p_item_key IN VARCHAR2,
10307 p_actid IN NUMBER,
10308 p_funmode IN VARCHAR2,
10309 p_result OUT NOCOPY VARCHAR2) IS
10310 ----------------------------------------------------------------------
10311
10312 l_debug_info VARCHAR2(1000);
10313
10314 l_notificationID NUMBER;
10315 l_TransferNotificationID NUMBER;
10316 l_TransferToID NUMBER;
10317 l_Transferee wf_users.name%type;
10318 l_TransferToName wf_users.name%type;
10319 l_preparer_id NUMBER;
10320 l_preparer_name wf_users.name%type;
10321 l_preparer_display_name wf_users.display_name%type;
10322 l_employee_id NUMBER;
10323 l_AMEEnabled VARCHAR2(1);
10324 l_AmeMasterItemKey VARCHAR2(30);
10325 l_forwarder AME_UTIL.approverRecord2 default ame_util.emptyApproverRecord2;
10326 l_forwardee AME_UTIL.approverRecord2 default ame_util.emptyApproverRecord2;
10327 l_notificationIn ame_util2.notificationRecord default ame_util2.emptyNotificationRecord;
10328 l_approver_id NUMBER;
10329 l_approver_name varchar2(240);
10330 l_approverResponse varchar2(80);
10331 l_approvalStatusIn varchar2(20);
10332
10333 l_report_header_id AP_WEB_DB_EXPRPT_PKG.expHdr_headerID;
10334 l_entered_by NUMBER := fnd_global.user_id;
10335 l_role_info_tbl wf_directory.wf_local_roles_tbl_type;
10336
10337 l_orig_language_code ap_expense_params.note_language_code%type := null;
10338 l_orig_language fnd_languages.nls_language%type := null;
10339 l_new_language_code ap_expense_params.note_language_code%type := null;
10340 l_new_language fnd_languages.nls_language%type := null;
10341
10342 C_WF_Version NUMBER := 0;
10343
10344 l_itemkey wf_items.item_key%TYPE;
10345 l_approvalProcessCompleteYNOut varchar2(1);
10346 l_nextApproversOut ame_util.approversTable2;
10347 l_ApproverAuthority varchar2(10);
10348 l_oldApproversOut ame_util.approversTable2;
10349 -- Bug: 7463317
10350 l_approvers ame_util.approversTable2;
10351 l_approvalProcessCompleteYN varchar2(20) := ame_util.booleanFalse;
10352 l_message_name wf_notifications.message_name%type;
10353 l_temp_item_key wf_items.item_key%TYPE := p_item_key;
10354 l_n_org_id Number;
10355 l_temp_entered_by NUMBER;
10356 l_temp_user_name VARCHAR2(200);
10357
10358
10359 CURSOR c_person_id IS
10360 SELECT orig_system_id
10361 FROM wf_roles
10362 WHERE orig_system = 'PER'
10363 AND name = l_TransferToName;
10364
10365 BEGIN
10366
10367 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start IsApprovalRequestTransferred');
10368
10369 BEGIN
10370 IF (p_funmode IN ('RESPOND','VALIDATE') AND substrb(wf_engine.context_text,1,6) = 'email:') THEN
10371 l_temp_item_key := p_item_key;
10372 begin
10373 l_AMEEnabled := WF_ENGINE.GetItemAttrText(p_item_type,
10374 p_item_key,
10375 'AME_ENABLED');
10376 IF(nvl(l_AMEEnabled,'N')='Y') THEN
10377 l_temp_item_key := WF_ENGINE.GetItemAttrText(p_item_type,
10378 p_item_key,
10379 'AME_MASTER_ITEM_KEY');
10380 END IF;
10381
10382 l_n_org_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
10383 l_temp_item_key,
10384 'ORG_ID');
10385 exception
10386 when others then
10387 IF (AP_WEB_DB_EXPRPT_PKG.GetOrgIdByReportHeaderId(
10388 to_number(l_temp_item_key),
10389 l_n_org_id) <> TRUE ) THEN
10390 l_n_org_id := NULL;
10391 END IF;
10392
10393
10394 end;
10395 IF (l_n_org_id IS NOT NULL) THEN
10396 mo_global.set_policy_context(p_access_mode => 'S',
10397 p_org_id => l_n_org_id);
10398 END IF;
10399 END IF;
10400 EXCEPTION
10401 WHEN OTHERS THEN
10402 NULL;
10403 END;
10404
10405 -- Bug 7155445(sodash) Used the AME API AME_API6.updateApprovalStatus so that the comments of one approver is visible to other approvers
10406 -- Bug: 10112521, Time out and Approval Hist issues
10407 IF(p_funmode = 'RESPOND') THEN
10408 l_notificationID := wf_engine.context_nid;
10409
10410 select message_name
10411 into l_message_name
10412 from wf_notifications
10413 where notification_id = l_notificationID;
10414
10415 if (l_message_name = 'OIE_AME_EXPENSE_REPORT_APPRVL' OR
10416 l_message_name = 'OIE_REQ_EXPENSE_REPORT_APPRVL') then
10417
10418 l_AMEEnabled := WF_ENGINE.GetItemAttrText(p_item_type,
10419 p_item_key,
10420 'AME_ENABLED');
10421
10422 IF(nvl(l_AMEEnabled,'N')='Y') THEN
10423 l_AmeMasterItemKey := WF_ENGINE.GetItemAttrText(p_item_type,
10424 p_item_key,
10425 'AME_MASTER_ITEM_KEY');
10426 l_approver_name := WF_ENGINE.GetItemAttrText(p_item_type,
10427 p_item_key,
10428 'APPROVER_NAME');
10429 l_forwarder.name := l_approver_name;
10430 l_approverResponse := WF_NOTIFICATION.GetAttrText(l_notificationID,'RESULT');
10431
10432 IF (l_approverResponse = 'APPROVED') THEN
10433 l_approvalStatusIn := AME_UTIL.approvedStatus;
10434 ELSIF (l_approverResponse = 'REJECTED') THEN
10435 l_approvalStatusIn := AME_UTIL.rejectStatus;
10436 ELSIF (l_approverResponse = 'NO_RESPONSE' or l_approverResponse IS NULL) THEN -- Bug 9011191(sodash): Added this clause because in case of time out, the value of the attribute RESULT is set as NULL by workflow
10437 l_approvalStatusIn := AME_UTIL.noResponseStatus;
10438 ELSIF (l_approverResponse = 'FYI') THEN
10439 l_approvalStatusIn := AME_UTIL.notifiedStatus;
10440 END IF;
10441
10442 l_forwarder.approval_status := l_approvalStatusIn;
10443 l_notificationIn.notification_id := l_notificationID;
10444 l_notificationIn.user_comments := wf_engine.context_user_comment;
10445
10446 AME_API6.updateApprovalStatus(applicationIdIn => AP_WEB_DB_UTIL_PKG.GetApplicationID,
10447 transactionTypeIn => p_item_type,
10448 transactionIdIn => l_AmeMasterItemKey,
10449 approverIn => l_forwarder,
10450 notificationIn => l_notificationIn,
10451 forwardeeIn => l_forwardee);
10452 END IF; -- (nvl(l_AMEEnabled,'N')='Y')
10453 end if;
10454 END IF; -- (p_funmode = 'RESPOND')
10455
10456 if (p_funmode in ('QUESTION', 'ANSWER')) then
10457
10458 -------------------------------------------------------------------
10459 l_debug_info := 'Need to generate Note based on language setup';
10460 -------------------------------------------------------------------
10461
10462 -------------------------------------------------------------------
10463 l_debug_info := 'Save original language';
10464 -------------------------------------------------------------------
10465 l_orig_language_code := userenv('LANG');
10466 select nls_language
10467 into l_orig_language
10468 from fnd_languages
10469 where language_code = l_orig_language_code;
10470
10471 -------------------------------------------------------------------
10472 l_debug_info := 'Check AP_EXPENSE_PARAMS.NOTE_LANGUAGE_CODE';
10473 -------------------------------------------------------------------
10474 begin
10475 select note_language_code
10476 into l_new_language_code
10477 from ap_expense_params;
10478
10479 exception
10480 when no_data_found then
10481 null;
10482 end;
10483
10484 -------------------------------------------------------------------
10485 l_debug_info := 'Else use instance base language';
10486 -------------------------------------------------------------------
10487 if (l_new_language_code is null) then
10488 select language_code
10489 into l_new_language_code
10490 from fnd_languages
10491 where installed_flag in ('B');
10492 end if;
10493
10494 -------------------------------------------------------------------
10495 l_debug_info := 'Set nls context to new language';
10496 -------------------------------------------------------------------
10497 select nls_language
10498 into l_new_language
10499 from fnd_languages
10500 where language_code = l_new_language_code;
10501
10502 fnd_global.set_nls_context(p_nls_language => l_new_language);
10503
10504 -----------------------------------------
10505 l_debug_info := 'Get the Notification ID';
10506 -----------------------------------------
10507 l_notificationID := wf_engine.context_nid;
10508
10509 ------------------------------------------------------------
10510 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
10511 ------------------------------------------------------------
10512 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
10513 p_item_key,
10514 'EXPENSE_REPORT_ID');
10515
10516 -- Bug: 10274331, Request more information is not displayed correct.
10517 ---------------------------------------------------------------------
10518 l_debug_info := 'Get User info from notif';
10519 ---------------------------------------------------------------------
10520 BEGIN
10521 SELECT NVL(MORE_INFO_ROLE, RECIPIENT_ROLE) INTO l_temp_user_name
10522 FROM wf_notifications
10523 WHERE notification_id = l_notificationID;
10524
10525 SELECT user_id INTO l_temp_entered_by FROM fnd_user WHERE user_name = l_temp_user_name;
10526 l_entered_by := l_temp_entered_by;
10527 EXCEPTION
10528 WHEN OTHERS THEN
10529 NULL;
10530 END;
10531 -----------------------------------------
10532 l_debug_info := 'Get the User Id';
10533 -----------------------------------------
10534 begin
10535 IF(l_entered_by IS NULL) THEN
10536 WF_DIRECTORY.GetRoleInfo2(wf_engine.context_user, l_role_info_tbl);
10537 AP_WEB_OA_MAINFLOW_PKG.GetUserId(l_role_info_tbl(1).orig_system_id, l_entered_by);
10538 END IF;
10539 exception
10540 when no_data_found then
10541 null;
10542 end;
10543
10544 ------------------------------------------------------------
10545 l_debug_info := 'store the Request More Info question/answer as a note';
10546 ------------------------------------------------------------
10547 AP_WEB_NOTES_PKG.CreateERPrepToAudNote (
10548 p_report_header_id => l_report_header_id,
10549 p_note => wf_core.translate(p_funmode)||'
10550 '||wf_engine.context_user_comment,
10551 p_lang => l_new_language_code,
10552 p_entered_by => l_entered_by
10553 );
10554
10555 -------------------------------------------------------------------
10556 l_debug_info := 'Restore nls context to original language';
10557 -------------------------------------------------------------------
10558 fnd_global.set_nls_context(p_nls_language => l_orig_language);
10559
10560 elsif (p_funmode in ('TRANSFER','FORWARD')) then
10561 -----------------------------------------
10562 l_debug_info := 'Get the Notification ID';
10563 -----------------------------------------
10564 l_notificationID := wf_engine.context_nid;
10565
10566 -----------------------------------------
10567 l_debug_info := 'Get information on the transfer to';
10568 -----------------------------------------
10569 -- wf_engine.context_text = new responder
10570 l_Transferee := wf_engine.context_text;
10571
10572 -----------------------------------------
10573 l_debug_info := 'check for transferee received through email/web';
10574 -----------------------------------------
10575 IF (substrb(l_Transferee,1,6) = 'email:') THEN
10576 l_TransferToName := substrb(l_Transferee,7);
10577 ELSE
10578 -- response received through web or form
10579 l_TransferToName := l_Transferee;
10580 END IF;
10581
10582 -----------------------------------------
10583 l_debug_info := 'Get the transferee id';
10584 -----------------------------------------
10585 OPEN c_person_id;
10586 FETCH c_person_id into l_TransferToID;
10587 IF c_person_id%NOTFOUND THEN
10588 p_result := wf_engine.eng_completed||':'||wf_engine.eng_null;
10589 Wf_Core.Raise(wf_core.translate('NO_ROLE_FOUND'));
10590 RETURN;
10591 ELSE
10592 IF l_TransferToID IS NULL THEN
10593 p_result := wf_engine.eng_completed||':'||wf_engine.eng_null;
10594 Wf_Core.Raise(wf_core.translate('PERSON_ID_NULL'));
10595 RETURN;
10596 END IF;
10597 END IF;
10598 CLOSE c_person_id;
10599
10600 IF (l_TransferToID IS NOT NULL) THEN
10601 ----------------------------------
10602 l_debug_info := 'Get AME_ENABLED';
10603 ----------------------------------
10604 l_AMEEnabled := WF_ENGINE.GetItemAttrText(p_item_type,
10605 p_item_key,
10606 'AME_ENABLED');
10607
10608 IF (l_AMEEnabled = 'Y') THEN
10609
10610 C_WF_VERSION := GetFlowVersion(p_item_type, p_item_key);
10611 IF (C_WF_Version >= AP_WEB_EXPENSE_WF.C_R120_Version) THEN
10612 l_itemkey := WF_ENGINE.GetItemAttrText(p_item_type,
10613 p_item_key,
10614 'AME_MASTER_ITEM_KEY');
10615 -- Bug 13579133: to reassign the re-approval notification without any errors
10616 IF l_itemkey IS NULL THEN
10617 l_itemkey := p_item_key;
10618 END IF;
10619 ELSE
10620 l_itemkey := p_item_key;
10621 END IF;
10622
10623 -- For bug 3062917, if AME is enabled and the approval is forwarded,
10624 -- need to set approval status to ame_util.forwardStatus so the
10625 -- current approver doesn't have to approve again later.
10626
10627 ----------------------------------------------------------------
10628 l_debug_info := 'Retrieving APPROVER_ID Item Attribute';
10629 ----------------------------------------------------------------
10630 l_approver_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
10631 p_item_key,
10632 'APPROVER_ID');
10633
10634 ------------------------------------------------------
10635 l_debug_info := 'Retrieve Approver_ID Item Attribute';
10636 -------------------------------------------------------
10637 l_approver_name := WF_ENGINE.GetItemAttrText(p_item_type,
10638 p_item_key,
10639 'APPROVER_NAME');
10640 ------------------------------------------------------
10641 -- Bug 7272553
10642 l_debug_info := 'Retrieve ApproverAuthority Item Attribute';
10643 -------------------------------------------------------
10644 begin
10645 l_ApproverAuthority := WF_ENGINE.GetItemAttrText(p_item_type,
10646 p_item_key,
10647 'AME_APPROVER_AUTHORITY');
10648 exception
10649 when others then
10650 if (wf_core.error_name = 'WFENG_ITEM_ATTR') then
10651 ame_api3.getOldApprovers(
10652 applicationIdIn => AP_WEB_DB_UTIL_PKG.GetApplicationID,
10653 transactionTypeIn => 'APEXP',
10654 transactionIdIn => l_itemkey,
10655 oldApproversOut => l_oldApproversOut);
10656
10657 FOR i IN 1 .. l_oldApproversOut.count LOOP
10658 if l_oldApproversOut(i).orig_system_id = l_approver_id then
10659 l_ApproverAuthority := l_oldApproversOut(i).authority;
10660 exit;
10661 end if;
10662 END LOOP;
10663 else
10664 raise;
10665 end if;
10666 end;
10667
10668 /*
10669 l_forwarder.user_id := null;
10670 l_forwarder.person_id := l_approver_id;
10671 l_forwarder.approval_status := ame_util.forwardStatus;
10672 l_forwarder.authority := ame_util.authorityApprover;
10673
10674 l_forwardee.user_id := null;
10675 l_forwardee.person_id := l_TransferToID;
10676 l_forwardee.api_insertion := ame_util.apiAuthorityInsertion;
10677 l_forwardee.authority := ame_util.authorityApprover;
10678 l_forwardee.approval_status := null;
10679
10680
10681 AME_API.updateApprovalStatus(applicationIdIn => AP_WEB_DB_UTIL_PKG.GetApplicationID,
10682 transactionIdIn => p_item_key,
10683 approverIn => l_forwarder,
10684 forwardeeIn => l_forwardee,
10685 transactionTypeIn => p_item_type);
10686 */
10687
10688 /*l_forwarder.name := l_approver_name;
10689 l_forwarder.approval_status := ame_util.forwardStatus;
10690 l_forwarder.authority := nvl(l_ApproverAuthority,ame_util.authorityApprover);*/
10691
10692 -- Bug: 7463317
10693 ame_api2.getAllApprovers7
10694 (applicationIdIn => AP_WEB_DB_UTIL_PKG.GetApplicationID
10695 ,transactionTypeIn => 'APEXP'
10696 ,transactionIdIn => l_itemkey
10697 ,approvalProcessCompleteYNOut => l_approvalProcessCompleteYN
10698 ,approversOut => l_approvers);
10699
10700 -- Bug: 7463317, find the forwarder record. Exit from the loop when found
10701 FOR i IN 1 .. l_approvers.count LOOP
10702 if l_approvers(i).orig_system_id = l_approver_id then
10703 l_forwarder := l_approvers(i);
10704 -- Bug: 7463317, set the approval status to forwarded so that AME does not wait for
10705 -- the approval from the forwarder when vacation rules are set.
10706 l_forwarder.approval_status := ame_util.forwardStatus;
10707 exit;
10708 end if;
10709 END LOOP;
10710
10711 l_forwardee.name := l_TransferToName;
10712 l_forwardee.authority := nvl(l_ApproverAuthority,ame_util.authorityApprover);
10713
10714 -- Bug: 7463317, change the if condition according to the suggestions by AME
10715 if (l_forwarder.authority = ame_util.authorityApprover and
10716 l_forwarder.api_insertion <> ame_util.apiInsertion) then
10717 l_forwardee.api_insertion := ame_util.apiAuthorityInsertion;
10718 else
10719 l_forwardee.api_insertion := ame_util.apiInsertion;
10720 end if;
10721 l_forwardee.approval_status := null;
10722
10723 l_notificationIn.notification_id := l_notificationID;
10724 l_notificationIn.user_comments := wf_engine.context_user_comment;
10725
10726 -- Bug 12836231: Do not call AME_API6.updateApprovalStatus() in the delegate mode
10727 IF (p_funmode in ('TRANSFER')) THEN
10728 -- Bug 7155445(sodash) Used the AME API AME_API6.updateApprovalStatus so that the comments of one approver is visible to other approvers when the notification is transferred or forwarded
10729 AME_API6.updateApprovalStatus(applicationIdIn => AP_WEB_DB_UTIL_PKG.GetApplicationID,
10730 transactionTypeIn => p_item_type,
10731 transactionIdIn => l_itemkey,
10732 approverIn => l_forwarder,
10733 notificationIn => l_notificationIn,
10734 forwardeeIn => l_forwardee);
10735 END IF;
10736
10737 /* AME_API2.updateApprovalStatus(applicationIdIn => AP_WEB_DB_UTIL_PKG.GetApplicationID,
10738 transactionTypeIn => p_item_type,
10739 transactionIdIn => l_itemkey,
10740 approverIn => l_forwarder,
10741 forwardeeIn => l_forwardee); */
10742
10743 -- 5135505: After re-assign the status of forwardee is null
10744 -- calling getNextApprover[n] will return forwardee and set the status to notified.
10745 begin
10746 AME_API2.getNextApprovers4(applicationIdIn => AP_WEB_DB_UTIL_PKG.GetApplicationID,
10747 transactionTypeIn => p_item_type,
10748 transactionIdIn => l_itemkey,
10749 approvalProcessCompleteYNOut => l_approvalProcessCompleteYNOut,
10750 nextApproversOut => l_nextApproversOut);
10751 exception
10752 when others then
10753 null;
10754 end;
10755
10756 END IF;
10757 END IF;
10758
10759 -- Bug 12836231: Do not send the notification to the preparer in the delegate mode
10760 if (p_funmode in ('TRANSFER')) then --OR (l_AMEEnabled = 'Y')) then
10761
10762 -----------------------------------------
10763 l_debug_info := 'set the transferring Approver info to the Transferor';
10764 -----------------------------------------
10765 WF_ENGINE.SetItemAttrText(p_item_type,
10766 p_item_key,
10767 'TRANSFER_APPROVER_DISPLAY_NAME',
10768 WF_ENGINE.GetItemAttrText(p_item_type,
10769 p_item_key,
10770 'APPROVER_DISPLAY_NAME'));
10771
10772 -----------------------------------------------------------
10773 l_debug_info := 'Record the forward from info';
10774 -----------------------------------------------------------
10775 if (l_AMEEnabled = 'Y') then
10776 RecordForwardFromInfo(p_item_type, p_item_key, p_actid, 'TRANSFER', p_result);
10777 else
10778 RecordForwardFromInfo(p_item_type, p_item_key, p_actid, p_funmode, p_result);
10779 end if;
10780
10781 -----------------------------------------
10782 l_debug_info := 'set the current Approver info to the Transferee';
10783 -----------------------------------------
10784 SetPersonAs(l_TransferToID,
10785 p_item_type,
10786 p_item_key,
10787 'APPROVER');
10788
10789 -------------------------------------------------------
10790 l_debug_info := 'Retrieve Preparer_ID Item Attribute';
10791 -------------------------------------------------------
10792 l_preparer_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
10793 p_item_key,
10794 'PREPARER_ID');
10795
10796 -------------------------------------------------------
10797 l_debug_info := 'Retrieve Employee_ID Item Attribute';
10798 -------------------------------------------------------
10799 l_employee_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
10800 p_item_key,
10801 'EMPLOYEE_ID');
10802
10803 --Bug 2742114:raise exception when preparer id and trasferee is same.
10804
10805 IF l_preparer_id = l_TransferToID THEN
10806 FND_MESSAGE.SET_NAME('SQLAP','OIE_TRANSFEREE_CANTBE_PREPARER');
10807 app_exception.raise_exception;
10808
10809 ELSIF ((l_preparer_id <> l_employee_id) and (l_employee_id = l_TransferToID)) THEN
10810 FND_MESSAGE.SET_NAME('SQLAP','OIE_TRANSFEREE_CANTBE_EMPLOYEE');
10811 app_exception.raise_exception;
10812 END IF;
10813
10814
10815 ----------------------------------------------------------
10816 l_debug_info := 'Get Preparer Name Info For Preparer_Id';
10817 ----------------------------------------------------------
10818 WF_DIRECTORY.GetUserName('PER',
10819 l_preparer_id,
10820 l_preparer_name,
10821 l_preparer_display_name);
10822
10823 /* Bug 3545282 : Set the #FROM_ROLE */
10824 -----------------------------------------------------------
10825 l_debug_info := 'Set the FromRole to the previous approver';
10826 -----------------------------------------------------------
10827
10828 SetFromRoleForwardFrom(p_item_type, p_item_key, p_actid, p_funmode, p_result);
10829
10830 -----------------------------------------
10831 l_debug_info := 'send notification Notify Preparer About Approval Request Transfer';
10832 -----------------------------------------
10833 l_TransferNotificationID := WF_NOTIFICATION.SEND(
10834 role => l_preparer_name,
10835 msg_type => 'APEXP',
10836 msg_name => 'OIE_PREPARER_TRANSFER',
10837 due_date => null,
10838 callback => null,
10839 context => p_item_type||':'||p_item_key||':'||to_char(p_actid),
10840 send_comment => null,
10841 priority => null);
10842
10843 if (l_TransferNotificationID is not null) then
10844 -----------------------------------------
10845 l_debug_info := 'set the notification attributes';
10846 -----------------------------------------
10847 WF_NOTIFICATION.SetAttrText(l_TransferNotificationID,
10848 'DOCUMENT_NUMBER',
10849 WF_ENGINE.GetItemAttrText(p_item_type,
10850 p_item_key,
10851 'DOCUMENT_NUMBER'));
10852
10853 WF_NOTIFICATION.SetAttrText(l_TransferNotificationID,
10854 '#HDR_DISPLAY_TOTAL',
10855 WF_ENGINE.GetItemAttrText(p_item_type,
10856 p_item_key,
10857 'DISPLAY_TOTAL'));
10858 WF_NOTIFICATION.SetAttrText(l_TransferNotificationID,
10859 '#FROM_ROLE',
10860 WF_ENGINE.GetItemAttrText(p_item_type,
10861 p_item_key,
10862 'APPROVER_DISPLAY_NAME'));
10863 WF_NOTIFICATION.SetAttrText(l_TransferNotificationID,
10864 '#HDR_DOC_COST_CENTER',
10865 WF_ENGINE.GetItemAttrText(p_item_type,
10866 p_item_key,
10867 'DOC_COST_CENTER'));
10868 WF_NOTIFICATION.SetAttrText(l_TransferNotificationID,
10869 '#HDR_EMPLOYEE_DISPLAY_NAME',
10870 WF_ENGINE.GetItemAttrText(p_item_type,
10871 p_item_key,
10872 'EMPLOYEE_DISPLAY_NAME'));
10873 WF_NOTIFICATION.SetAttrText(l_TransferNotificationID,
10874 '#HDR_PURPOSE',
10875 WF_ENGINE.GetItemAttrText(p_item_type,
10876 p_item_key,
10877 'PURPOSE'));
10878 WF_NOTIFICATION.SetAttrText(l_TransferNotificationID,
10879 'APPROVER_DISPLAY_NAME',
10880 WF_ENGINE.GetItemAttrText(p_item_type,
10881 p_item_key,
10882 'APPROVER_DISPLAY_NAME'));
10883 WF_NOTIFICATION.SetAttrNumber(l_TransferNotificationID,
10884 'EXPENSE_REPORT_ID',
10885 WF_ENGINE.GetItemAttrNumber(p_item_type,
10886 p_item_key,
10887 'EXPENSE_REPORT_ID'));
10888 WF_NOTIFICATION.SetAttrText(l_TransferNotificationID,
10889 'OIE_APEXP_BODY',
10890 WF_ENGINE.GetItemAttrText(p_item_type,
10891 p_item_key,
10892 'OIE_APEXP_BODY'));
10893 WF_NOTIFICATION.SetAttrText(l_TransferNotificationID,
10894 'TRANSFER_APPROVER_DISPLAY_NAME',
10895 WF_ENGINE.GetItemAttrText(p_item_type,
10896 p_item_key,
10897 'TRANSFER_APPROVER_DISPLAY_NAME'));
10898
10899 wf_notification.denormalize_notification(l_TransferNotificationID);
10900 end if;
10901
10902 end if;
10903
10904 end if;
10905
10906
10907 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end IsApprovalRequestTransferred');
10908
10909 EXCEPTION
10910 WHEN OTHERS THEN
10911 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'IsApprovalRequestTransferred',
10912 p_item_type, p_item_key, to_char(0), l_debug_info);
10913 RAISE;
10914
10915 END IsApprovalRequestTransferred;
10916
10917
10918 ----------------------------------------------------------------------
10919 PROCEDURE UpdateApproverIdInHeaders(
10920 p_item_type IN VARCHAR2,
10921 p_item_key IN VARCHAR2,
10922 p_actid IN NUMBER,
10923 p_funmode IN VARCHAR2,
10924 p_result OUT NOCOPY VARCHAR2) IS
10925 ----------------------------------------------------------------------
10926 l_debug_info VARCHAR2(1000);
10927
10928 l_notificationID NUMBER;
10929 l_Transferee wf_users.name%type;
10930 l_TransferToName wf_users.name%type;
10931
10932 l_approver_person_id wf_roles.orig_system_id%TYPE;
10933
10934 BEGIN
10935
10936 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start UpdateApproverIdInHeaders');
10937
10938 IF (p_funmode in ('TRANSFER','FORWARD')) THEN
10939
10940 -----------------------------------------
10941 l_debug_info := 'Get the Notification ID';
10942 -----------------------------------------
10943
10944 l_notificationID := wf_engine.context_nid;
10945
10946 -----------------------------------------
10947 l_debug_info := 'Get information on the transfer to';
10948 -----------------------------------------
10949 -- wf_engine.context_text = new responder
10950 l_Transferee := wf_engine.context_text;
10951
10952 -----------------------------------------
10953 l_debug_info := 'check for transferee received through email/web';
10954 -----------------------------------------
10955 IF (substrb(l_Transferee,1,6) = 'email:') THEN
10956 l_TransferToName := substrb(l_Transferee,7);
10957 ELSE
10958 -- response received through web or form
10959 l_TransferToName := l_Transferee;
10960 END IF;
10961
10962 -----------------------------------------
10963 l_debug_info := 'Get the transferee id';
10964 -----------------------------------------
10965
10966 SELECT orig_system_id INTO l_approver_person_id
10967 FROM wf_roles
10968 WHERE orig_system = 'PER'
10969 AND name = l_TransferToName;
10970
10971
10972 -----------------------------------------------------
10973 l_debug_info := 'Update Headers table with Person Id';
10974 -----------------------------------------------------
10975
10976 UPDATE ap_expense_report_headers
10977 SET expense_current_approver_id = l_approver_person_id
10978 WHERE report_header_id = p_item_key;
10979
10980 END IF;
10981
10982 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end UpdateApproverIdInHeaders');
10983
10984 EXCEPTION
10985 WHEN OTHERS THEN
10986 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'UpdateApproverIdInHeaders',
10987 p_item_type, p_item_key, to_char(0), l_debug_info);
10988 RAISE;
10989 END UpdateApproverIdInHeaders;
10990
10991
10992 ----------------------------------------------------------------------
10993 PROCEDURE CheckWFAdminNote(
10994 p_item_type IN VARCHAR2,
10995 p_item_key IN VARCHAR2,
10996 p_actid IN NUMBER,
10997 p_funmode IN VARCHAR2,
10998 p_result OUT NOCOPY VARCHAR2) IS
10999 ----------------------------------------------------------------------
11000
11001 l_debug_info VARCHAR2(1000);
11002
11003 l_notificationID NUMBER;
11004 l_WFAdminNote VARCHAR2(240) := NULL;
11005
11006 BEGIN
11007
11008 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start CheckWFAdminNote');
11009
11010 if (p_funmode = 'RESPOND') then
11011 -----------------------------------------
11012 l_debug_info := 'Get the Notification ID';
11013 -----------------------------------------
11014 l_notificationID := wf_engine.context_nid;
11015
11016 -----------------------------------------
11017 l_debug_info := 'Get WF Admin Note';
11018 -----------------------------------------
11019 l_WFAdminNote := WF_NOTIFICATION.GetAttrText(l_notificationID,
11020 'WF_ADMIN_NOTE');
11021
11022 /* Bug 2798344: The following code does got fire to raise a sql
11023 exception. However, it appears to be a bug than a desired feature.
11024 IF (l_WFAdminNote IS NULL OR replace(l_WFAdminNote, ' ', '') = '') THEN
11025 l_debug_info := 'Please provide specific instructions in the Note field.';
11026 Wf_Core.Raise('ICX_ALL_FIELDS_REQUIRED');
11027 end if;
11028 */
11029 end if;
11030
11031
11032 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end CheckWFAdminNote');
11033
11034 EXCEPTION
11035 WHEN OTHERS THEN
11036 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'CheckWFAdminNote',
11037 p_item_type, p_item_key, to_char(0), l_debug_info);
11038 RAISE;
11039
11040 END CheckWFAdminNote;
11041
11042 ----------------------------------------------------------------------
11043 PROCEDURE SetReturnStatusAndResetAttr(p_item_type IN VARCHAR2,
11044 p_item_key IN VARCHAR2,
11045 p_actid IN NUMBER,
11046 p_funmode IN VARCHAR2,
11047 p_result OUT NOCOPY VARCHAR2) IS
11048 ----------------------------------------------------------------------
11049 l_debug_info VARCHAR2(200);
11050 l_report_header_id AP_WEB_DB_EXPRPT_PKG.expHdr_headerID;
11051 l_payment_due VARCHAR2(10) := C_IndividualPay;
11052 l_No VARCHAR2(1) := 'N';
11053 l_AMEEnabled VARCHAR2(1);
11054 C_WF_Version NUMBER := 0;
11055 l_n_resp_id NUMBER;
11056 BEGIN
11057
11058 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start SetReturnStatusAndResetAttr');
11059
11060 IF (p_funmode = 'RUN') THEN
11061
11062 -----------------------------------------------------
11063 l_debug_info := 'Get Workflow Version Number';
11064 -----------------------------------------------------
11065 C_WF_Version := AP_WEB_EXPENSE_WF.GetFlowVersion(p_item_type, p_item_key);
11066
11067 ------------------------------------------------------------
11068 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
11069 ------------------------------------------------------------
11070 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
11071 p_item_key,
11072 'EXPENSE_REPORT_ID');
11073
11074 l_AMEEnabled := WF_ENGINE.GetItemAttrText(p_item_type,
11075 p_item_key,
11076 'AME_ENABLED');
11077 IF (l_AMEEnabled = 'Y') THEN
11078
11079 --Bug 4425821: Uptake AME parallel approvers
11080 IF (C_WF_Version >= AP_WEB_EXPENSE_WF.C_R120_Version) THEN
11081 --------------------------------------------
11082 l_debug_info := 'Call AMEAbortRequestApprovals';
11083 --------------------------------------------
11084 AMEAbortRequestApprovals(l_report_header_id);
11085 END IF;
11086
11087 -----------------------------------------
11088 l_debug_info := 'Call clearAllApprovals';
11089 -----------------------------------------
11090 AME_API2.clearAllApprovals(applicationIdIn => AP_WEB_DB_UTIL_PKG.GetApplicationID,
11091 transactionIdIn => p_item_key,
11092 transactionTypeIn => p_item_type);
11093 END IF;
11094
11095 ------------------------------------------------------------
11096 l_debug_info := 'Set Returned status in report header';
11097 ------------------------------------------------------------
11098 /*IF (NOT AP_WEB_DB_EXPRPT_PKG.SetWkflApprvdFlagAndSource(l_report_header_id,
11099 AP_WEB_DB_EXPRPT_PKG.C_WORKFLOW_APPROVED_RETURNED,
11100 'NonValidatedWebExpense')) THEN
11101 NULL;
11102 END IF;*/
11103
11104 --AP_WEB_DB_VIOLATIONS_PKG.deleteViolationEntry(l_report_header_id);
11105 AP_WEB_AUDIT_QUEUE_UTILS.remove_from_queue(l_report_header_id);
11106
11107 ----------------------------------------------------------
11108 l_debug_info := 'Clearing out lines in AP_AUD_AUDIT_REASONS';
11109 ----------------------------------------------------------
11110 -- Bug 4394168
11111 AP_WEB_AUDIT_UTILS.clear_audit_reason_codes(l_report_header_id);
11112
11113
11114 l_payment_due := WF_ENGINE.GetItemAttrText(p_item_type,p_item_key,'PAYMENT_DUE_FROM');
11115
11116 IF (l_payment_due = C_CompanyPay) THEN
11117 IF (NOT AP_WEB_DB_EXPLINE_PKG.DeletePersonalLines(l_report_header_id)) THEN
11118 NULL;
11119 END IF;
11120 END IF;
11121
11122 /* Bug 6502501: cc trxns are detached from expense report when an
11123 expense report is returned.
11124 IF (l_payment_due = C_CompanyPay OR l_payment_due = C_BothPay) THEN
11125 IF (NOT AP_WEB_DB_CCARD_PKG.ResetMgrRejectPersonalTrxns(
11126 l_report_header_id)) THEN
11127 NULL;
11128 END IF;
11129 END IF;
11130 */
11131
11132 -- 4001778/3654956 : reset the Apply Advances
11133 --5060928: reset the Apply Advnaces only if OIE:Enable Advances = "Payables"
11134
11135 begin
11136
11137 l_n_resp_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
11138 p_item_key,
11139 'RESPONSIBILITY_ID');
11140 exception
11141 when others then
11142 if (wf_core.error_name = 'WFENG_ITEM_ATTR') then
11143 null;
11144 else
11145 raise;
11146 end if;
11147 end;
11148
11149 IF FND_PROFILE.VALUE_SPECIFIC('OIE_ENABLE_ADVANCES',NULL,l_n_resp_id,200) = 'PAYABLES' THEN
11150
11151 AP_WEB_DB_EXPLINE_PKG.resetApplyAdvances(l_report_header_id);
11152 END IF;
11153
11154 /* Bug 4019412 */
11155 AP_WEB_DB_EXPLINE_PKG.resetAPflags(l_report_header_id);
11156 ------------------------------------------------------------
11157 l_debug_info := 'Set which process to start from';
11158 ------------------------------------------------------------
11159 -- Indicate which process to start from
11160 -- (skip ServerValidate, Manager Approval)
11161 WF_ENGINE.SetItemAttrText(p_item_type,
11162 p_item_key,
11163 'START_FROM_PROCESS',
11164 C_START_FROM_SERVER_VALIDATION);
11165
11166 -- Reset the attributes which will not be set by code to initialize a
11167 -- process
11168 ------------------------------------------------------------
11169 l_debug_info := 'Reset attribute';
11170 ------------------------------------------------------------
11171 ResetAttrValues(p_item_type, p_item_key, p_actid);
11172
11173 ----------------------------------------------------------
11174 l_debug_info := 'Reset Receipt Verified Flag to N';
11175 ----------------------------------------------------------
11176 -- Bug 4094871
11177 begin
11178 update ap_expense_report_lines
11179 set receipt_verified_flag = l_No
11180 where report_header_id = l_report_header_id;
11181 exception
11182 when others then null;
11183 end;
11184
11185 ------------------------------------------------------------
11186 l_debug_info := 'Raise Receipts Aborted Event';
11187 ------------------------------------------------------------
11188 AP_WEB_RECEIPTS_WF.RaiseAbortedEvent(l_report_header_id);
11189 -- Bug 12859250: Update the workflow approved flag after raising the aborted event
11190 IF (NOT AP_WEB_DB_EXPRPT_PKG.SetWkflApprvdFlagAndSource(l_report_header_id,
11191 AP_WEB_DB_EXPRPT_PKG.C_WORKFLOW_APPROVED_RETURNED,
11192 'NonValidatedWebExpense')) THEN
11193 NULL;
11194 END IF;
11195
11196 p_result := 'COMPLETE:Y';
11197
11198 ELSIF (p_funmode = 'CANCEL') THEN
11199 p_result := 'COMPLETE';
11200 END IF;
11201
11202 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end SetReturnStatusAndResetAttr');
11203
11204 EXCEPTION
11205 WHEN OTHERS THEN
11206 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'SetReturnStatusAndResetAttr',
11207 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
11208 RAISE;
11209
11210 END SetReturnStatusAndResetAttr;
11211
11212 ----------------------------------------------------------------------
11213 PROCEDURE SetFromRoleBeforeApproval(
11214 p_item_type IN VARCHAR2,
11215 p_item_key IN VARCHAR2,
11216 p_actid IN NUMBER,
11217 p_funmode IN VARCHAR2,
11218 p_result OUT NOCOPY VARCHAR2) IS
11219 ----------------------------------------------------------------------
11220 l_debug_info VARCHAR2(200);
11221 l_find_approver_count NUMBER;
11222 BEGIN
11223
11224 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start SetFromRoleBeforeApproval');
11225
11226 IF (p_funmode = 'RUN') THEN
11227 ----------------------------------------------------------------
11228 l_debug_info := 'Retrieving Find_Approver_Count Item Attribute';
11229 ----------------------------------------------------------------
11230 l_find_approver_count := WF_ENGINE.GetItemAttrNumber(p_item_type,
11231 p_item_key,
11232 'FIND_APPROVER_COUNT');
11233
11234 IF (l_find_approver_count = 1) THEN
11235 ----------------------------------------------------------------
11236 l_debug_info := 'Set #FROM_ROLE to Preparer';
11237 ----------------------------------------------------------------
11238 SetFromRoleEmployee(p_item_type, p_item_key, p_actid, p_funmode, p_result);
11239 ELSE
11240 ----------------------------------------------------------------
11241 l_debug_info := 'Set #FROM_ROLE to Forward From';
11242 ----------------------------------------------------------------
11243 SetFromRoleForwardFrom(p_item_type, p_item_key, p_actid, p_funmode, p_result);
11244 END IF;
11245
11246 p_result := 'COMPLETE:Y';
11247
11248 ELSIF (p_funmode = 'CANCEL') THEN
11249 p_result := 'COMPLETE';
11250 END IF;
11251
11252 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end SetFromRoleBeforeApproval');
11253
11254 EXCEPTION
11255 WHEN OTHERS THEN
11256 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'SetFromRoleBeforeApproval',
11257 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
11258 raise;
11259 END SetFromRoleBeforeApproval;
11260
11261 ----------------------------------------------------------------------
11262 PROCEDURE SetFromRolePreparer(
11263 p_item_type IN VARCHAR2,
11264 p_item_key IN VARCHAR2,
11265 p_actid IN NUMBER,
11266 p_funmode IN VARCHAR2,
11267 p_result OUT NOCOPY VARCHAR2) IS
11268 ----------------------------------------------------------------------
11269 l_debug_info VARCHAR2(200);
11270 BEGIN
11271
11272 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start SetFromRolePreparer');
11273
11274 IF (p_funmode = 'RUN') THEN
11275 ----------------------------------------------------------------
11276 l_debug_info := 'Set #FROM_ROLE to Preparer';
11277 ----------------------------------------------------------------
11278 SetFromRole(p_item_type,
11279 p_item_key,
11280 p_actid,
11281 WF_ENGINE.GetItemAttrText(p_item_type,
11282 p_item_key,
11283 'PREPARER_NAME'),
11284 'SetFromRolePreparer'
11285 );
11286 /*
11287 WF_ENGINE.SetItemAttrText(p_item_type,
11288 p_item_key,
11289 '#FROM_ROLE',
11290 WF_ENGINE.GetItemAttrText(p_item_type,
11291 p_item_key,
11292 'PREPARER_NAME'));
11293 */
11294 p_result := 'COMPLETE:Y';
11295
11296 ELSIF (p_funmode = 'CANCEL') THEN
11297 p_result := 'COMPLETE';
11298 END IF;
11299
11300 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end SetFromRolePreparer');
11301
11302 EXCEPTION
11303 WHEN OTHERS THEN
11304 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'SetFromRolePreparer',
11305 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
11306 raise;
11307 END SetFromRolePreparer;
11308
11309 ----------------------------------------------------------------------
11310 PROCEDURE SetFromRoleEmployee(
11311 p_item_type IN VARCHAR2,
11312 p_item_key IN VARCHAR2,
11313 p_actid IN NUMBER,
11314 p_funmode IN VARCHAR2,
11315 p_result OUT NOCOPY VARCHAR2) IS
11316 ----------------------------------------------------------------------
11317 l_debug_info VARCHAR2(200);
11318 BEGIN
11319
11320 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start SetFromRoleEmployee');
11321
11322 IF (p_funmode = 'RUN') THEN
11323 ----------------------------------------------------------------
11324 l_debug_info := 'Set #FROM_ROLE to Employee';
11325 ----------------------------------------------------------------
11326 SetFromRole(p_item_type,
11327 p_item_key,
11328 p_actid,
11329 WF_ENGINE.GetItemAttrText(p_item_type,
11330 p_item_key,
11331 'EMPLOYEE_NAME'),
11332 'SetFromRoleEmployee'
11333 );
11334 /*
11335 WF_ENGINE.SetItemAttrText(p_item_type,
11336 p_item_key,
11337 '#FROM_ROLE',
11338 WF_ENGINE.GetItemAttrText(p_item_type,
11339 p_item_key,
11340 'EMPLOYEE_NAME'));
11341 */
11342 p_result := 'COMPLETE:Y';
11343
11344 ELSIF (p_funmode = 'CANCEL') THEN
11345 p_result := 'COMPLETE';
11346 END IF;
11347
11348 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end SetFromRoleEmployee');
11349
11350 EXCEPTION
11351 WHEN OTHERS THEN
11352 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'SetFromRoleEmployee',
11353 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
11354 raise;
11355 END SetFromRoleEmployee;
11356
11357 ----------------------------------------------------------------------
11358 PROCEDURE SetFromRoleForwardFrom(
11359 p_item_type IN VARCHAR2,
11360 p_item_key IN VARCHAR2,
11361 p_actid IN NUMBER,
11362 p_funmode IN VARCHAR2,
11363 p_result OUT NOCOPY VARCHAR2) IS
11364 ----------------------------------------------------------------------
11365 l_debug_info VARCHAR2(200);
11366 BEGIN
11367
11368 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start SetFromRoleForwardFrom');
11369
11370 IF (p_funmode in ('RUN', 'TRANSFER')) THEN
11371 ----------------------------------------------------------------
11372 l_debug_info := 'Set #FROM_ROLE to Forward From';
11373 ----------------------------------------------------------------
11374 SetFromRole(p_item_type,
11375 p_item_key,
11376 p_actid,
11377 WF_ENGINE.GetItemAttrText(p_item_type,
11378 p_item_key,
11379 'FORWARD_FROM_NAME'),
11380 'SetFromRoleForwardFrom'
11381 );
11382 /*
11383 WF_ENGINE.SetItemAttrText(p_item_type,
11384 p_item_key,
11385 '#FROM_ROLE',
11386 WF_ENGINE.GetItemAttrText(p_item_type,
11387 p_item_key,
11388 'FORWARD_FROM_NAME'));
11389 */
11390 p_result := 'COMPLETE:Y';
11391
11392 ELSIF (p_funmode = 'CANCEL') THEN
11393 p_result := 'COMPLETE';
11394 END IF;
11395
11396 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end SetFromRoleForwardFrom');
11397
11398 EXCEPTION
11399 WHEN OTHERS THEN
11400 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'SetFromRoleForwardFrom',
11401 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
11402 raise;
11403 END SetFromRoleForwardFrom;
11404
11405 ----------------------------------------------------------------------
11406 PROCEDURE SetFromRoleApprover(
11407 p_item_type IN VARCHAR2,
11408 p_item_key IN VARCHAR2,
11409 p_actid IN NUMBER,
11410 p_funmode IN VARCHAR2,
11411 p_result OUT NOCOPY VARCHAR2) IS
11412 ----------------------------------------------------------------------
11413 l_debug_info VARCHAR2(200);
11414 BEGIN
11415
11416 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start SetFromRoleApprover');
11417
11418 IF (p_funmode = 'RUN') THEN
11419 ----------------------------------------------------------------
11420 l_debug_info := 'Set #FROM_ROLE to Approver';
11421 ----------------------------------------------------------------
11422 SetFromRole(p_item_type,
11423 p_item_key,
11424 p_actid,
11425 WF_ENGINE.GetItemAttrText(p_item_type,
11426 p_item_key,
11427 'APPROVER_NAME'),
11428 'SetFromRoleApprover'
11429 );
11430 /*
11431 WF_ENGINE.SetItemAttrText(p_item_type,
11432 p_item_key,
11433 '#FROM_ROLE',
11434 WF_ENGINE.GetItemAttrText(p_item_type,
11435 p_item_key,
11436 'APPROVER_NAME'));
11437 */
11438 p_result := 'COMPLETE:Y';
11439
11440 ELSIF (p_funmode = 'CANCEL') THEN
11441 p_result := 'COMPLETE';
11442 END IF;
11443
11444 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end SetFromRoleApprover');
11445
11446 EXCEPTION
11447 WHEN OTHERS THEN
11448 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'SetFromRoleApprover',
11449 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
11450 raise;
11451 END SetFromRoleApprover;
11452
11453 ----------------------------------------------------------------------
11454 PROCEDURE SetStatusApproverAndDate(p_item_type IN VARCHAR2,
11455 p_item_key IN VARCHAR2,
11456 p_actid IN NUMBER,
11457 p_funmode IN VARCHAR2,
11458 p_result OUT NOCOPY VARCHAR2) IS
11459 ----------------------------------------------------------------------
11460 l_current_approver_id NUMBER := NULL;
11461 l_expense_status_code VARCHAR2(30) := NULL;
11462 l_date_reset VARCHAR2(30) := NULL;
11463
11464 fixable_exception EXCEPTION;
11465 l_error_message VARCHAR2(2000);
11466 l_debug_info VARCHAR2(200);
11467 l_source VARCHAR2(25) := NULL;
11468 l_holds_setup VARCHAR2(2);
11469 l_report_submitted_date DATE;
11470 l_org_id NUMBER;
11471 l_report_header_id NUMBER;
11472 l_employee_id NUMBER;
11473
11474 BEGIN
11475
11476 IF (p_funmode = 'RUN') THEN
11477
11478 -------------------------------------------------------------------
11479 l_debug_info := 'Retrieve Expense Status Code Activity Attribute';
11480 -------------------------------------------------------------------
11481 l_expense_status_code := WF_ENGINE.GetActivityAttrText(p_item_type,
11482 p_item_key,
11483 p_actid,
11484 'EXPENSE_STATUS_CODE');
11485
11486
11487 -------------------------------------------------------------------
11488 l_debug_info := 'Retrieve Current Approver ID Activity Attribute';
11489 -------------------------------------------------------------------
11490 l_current_approver_id := WF_ENGINE.GetActivityAttrNumber(p_item_type,
11491 p_item_key,
11492 p_actid,
11493 'CURRENT_APPROVER_ID');
11494
11495 ------------------------------------------------------------
11496 l_debug_info := 'Retrieve ORG_ID Item Attribute';
11497 ------------------------------------------------------------
11498 l_org_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
11499 p_item_key,
11500 'ORG_ID');
11501
11502 ------------------------------------------------------------
11503 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
11504 ------------------------------------------------------------
11505 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
11506 p_item_key,
11507 'EXPENSE_REPORT_ID');
11508
11509 ----------------------------------------------------------
11510 l_debug_info := 'Get Expense Report data';
11511 ----------------------------------------------------------
11512 select report_submitted_date
11513 into l_report_submitted_date
11514 from ap_expense_report_headers
11515 where report_header_id = l_report_header_id;
11516
11517 SELECT employee_id
11518 INTO l_employee_id
11519 FROM ap_expense_report_headers_all
11520 WHERE report_header_id = l_report_header_id;
11521
11522 IF (l_expense_status_code = 'INVOICED') THEN
11523
11524 l_source := 'SelfService';
11525
11526 l_holds_setup := AP_WEB_HOLDS_WF.IsHoldsRuleSetup(l_org_id,
11527 l_report_submitted_date);
11528
11529 IF (l_holds_setup = 'Y') THEN
11530 l_expense_status_code := AP_WEB_RECEIPTS_WF.C_PENDING_HOLDS;
11531 END IF;
11532 ELSIF (l_expense_status_code = 'REJECTED') THEN
11533
11534 --Delete the duplicate detection violations
11535 AP_WEB_DB_VIOLATIONS_PKG.deleteDupViolationEntry(l_report_header_id);
11536
11537 END IF;
11538
11539 --Bug 4425821: Uptake AME parallel approvers
11540 -- replaced p_item_key with the l_report_header_id
11541 -------------------------------------------------------------------
11542 l_debug_info := 'Set Expense Status Code and Current Approver ID';
11543 -------------------------------------------------------------------
11544 UPDATE ap_expense_report_headers_all
11545 SET expense_status_code = l_expense_status_code,
11546 expense_current_approver_id = l_current_approver_id,
11547 expense_last_status_date=sysdate,
11548 source = nvl(l_source, source),
11549 last_update_date = sysdate
11550 --last_updated_by = Decode(Nvl(fnd_global.user_id,-1),-1,last_updated_by,fnd_global.user_id)
11551 WHERE report_header_id = l_report_header_id
11552 and nvl(expense_status_code, 'NULL') <> 'PAID'; -- Bug: 13482337, 13870204
11553
11554 p_result := 'COMPLETE:Y';
11555
11556 IF (AP_WEB_DB_HR_INT_PKG.IsPersonActive(l_employee_id) = 'Y') THEN
11557 p_result := 'COMPLETE:Y';
11558 ELSE
11559 p_result := 'COMPLETE:N';
11560 END IF;
11561
11562 ELSIF (p_funmode = 'CANCEL') THEN
11563 NULL;
11564 END IF;
11565
11566 EXCEPTION
11567 WHEN fixable_exception THEN
11568 WF_ENGINE.SetItemAttrText(p_item_type,
11569 p_item_key,
11570 'ERROR_MESSAGE',
11571 l_error_message);
11572
11573 p_result := 'COMPLETE:N';
11574 WHEN OTHERS THEN
11575 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'SetStatusApproverAndDate',
11576 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
11577 raise;
11578 END SetStatusApproverAndDate;
11579
11580 ---------------------------------------------------------
11581 PROCEDURE ZeroFindApproverCount(p_item_type IN VARCHAR2,
11582 p_item_key IN VARCHAR2,
11583 p_actid IN NUMBER,
11584 p_funmode IN VARCHAR2,
11585 p_result OUT NOCOPY VARCHAR2) IS
11586 ---------------------------------------------------------
11587 l_find_approver_count NUMBER;
11588 l_debug_info VARCHAR2(200);
11589 BEGIN
11590
11591 IF (p_funmode = 'RUN') THEN
11592
11593 ----------------------------------------------------------------
11594 l_debug_info := 'Retrieving Find_Approver_Count Item Attribute';
11595 ----------------------------------------------------------------
11596 l_find_approver_count := WF_ENGINE.GetItemAttrNumber(p_item_type,
11597 p_item_key,
11598 'FIND_APPROVER_COUNT');
11599
11600 IF (l_find_approver_count = 0) THEN
11601 -----------------------------------------------
11602 -- return yes when find_approver_count equals 0
11603 -----------------------------------------------
11604 p_result := 'COMPLETE:Y';
11605 ELSE
11606 ---------------------------------------------------
11607 -- return no if find_approver_count doesn't equal 0
11608 ---------------------------------------------------
11609 p_result := 'COMPLETE:N';
11610 END IF;
11611
11612 ELSIF (p_funmode = 'CANCEL') THEN
11613
11614 p_result := 'COMPLETE';
11615
11616 END IF;
11617
11618 EXCEPTION
11619 WHEN OTHERS THEN
11620 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'ZeroFindApproverCount',
11621 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
11622 raise;
11623 END ZeroFindApproverCount;
11624
11625 /*----------------------------------------------------------------------------*
11626 | Procedure |
11627 | WithdrawExpenseRep |
11628 | |
11629 | DESCRIPTION |
11630 | Withdraw the expense report from workflow approval |
11631 | bug1552747
11632 | PARAMETERS |
11633 | INPUT |
11634 | p_employee_id NUMBER -- Expense Report Header ID |
11635 | RETURNS |
11636 | none |
11637 *----------------------------------------------------------------------------*/
11638
11639 PROCEDURE WithdrawExpenseRep(
11640 p_rep_header_id IN AP_EXPENSE_REPORT_LINES.report_header_id%TYPE)
11641 IS
11642 l_itemkey wf_items.item_key%TYPE;
11643 l_itemtype wf_items.item_type%TYPE := 'APEXP';
11644 l_document_number AP_WEB_DB_EXPRPT_PKG.expHdr_invNum;
11645 l_doc_cctr VARCHAR2(2000);
11646 l_preparer_name VARCHAR2(2000);
11647 l_employee_name VARCHAR2(2000);
11648 l_purpose VARCHAR2(2400);
11649 l_payable_admin wf_notifications.recipient_role%TYPE;
11650 l_currency VARCHAR2(50);
11651 l_total VARCHAR2(200);
11652 l_payment_due VARCHAR2(100);
11653 l_debug_info VARCHAR2(200);
11654 l_wf_active BOOLEAN := FALSE;
11655 l_wf_exist BOOLEAN := FALSE;
11656 l_end_date wf_items.end_date%TYPE;
11657 l_AMEEnabled VARCHAR2(1);
11658 l_receipts_status VARCHAR2(30);
11659
11660 l_entered_by NUMBER := fnd_global.user_id;
11661 l_note varchar2(2000);
11662 l_message_name fnd_new_messages.message_name%type := 'OIE_WITHDRAWN_NOTE';
11663
11664 l_orig_language_code ap_expense_params.note_language_code%type := null;
11665 l_orig_language fnd_languages.nls_language%type := null;
11666 l_new_language_code ap_expense_params.note_language_code%type := null;
11667 l_new_language fnd_languages.nls_language%type := null;
11668
11669 l_No VARCHAR2(1) := 'N';
11670 C_WF_Version NUMBER := 0;
11671 l_n_resp_id NUMBER := 0;
11672 BEGIN
11673
11674 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF',
11675 'start WF WithdrawExpenseRep');
11676
11677 l_itemkey := to_char(p_rep_header_id);
11678 begin
11679 select end_date
11680 into l_end_date
11681 from wf_items
11682 where item_type = l_itemtype
11683 and item_key = l_itemkey;
11684
11685 if l_end_date is NULL then
11686 l_wf_active := TRUE;
11687 else
11688 l_wf_active := FALSE;
11689 end if;
11690 l_wf_exist := TRUE;
11691 exception
11692 when no_data_found then
11693 l_wf_active := FALSE;
11694 l_wf_exist := FALSE;
11695 end;
11696
11697 -----------------------------------------------------
11698 l_debug_info := 'Get Workflow Version Number';
11699 -----------------------------------------------------
11700 C_WF_Version := AP_WEB_EXPENSE_WF.GetFlowVersion(l_itemtype, l_itemkey);
11701
11702 if l_wf_exist then
11703 l_debug_info := 'Get Attribute values';
11704 l_preparer_name := WF_ENGINE.GetItemAttrText(
11705 itemtype => l_itemtype,
11706 itemkey => l_itemkey,
11707 aname => 'PREPARER_DISPLAY_NAME');
11708 l_employee_name := WF_ENGINE.GetItemAttrText(
11709 itemtype => l_itemtype,
11710 itemkey => l_itemkey,
11711 aname => 'EMPLOYEE_DISPLAY_NAME');
11712 l_document_number := WF_ENGINE.GetItemAttrText(
11713 itemtype => l_itemtype,
11714 itemkey => l_itemkey,
11715 aname => 'DOCUMENT_NUMBER');
11716 l_payable_admin := WF_ENGINE.GetItemAttrText(
11717 itemtype => l_itemtype,
11718 itemkey => l_itemkey,
11719 aname => 'PAYABLES');
11720 l_total := WF_ENGINE.GetItemAttrText(
11721 itemtype => l_itemtype,
11722 itemkey => l_itemkey,
11723 aname => 'DISPLAY_TOTAL');
11724 l_currency := WF_ENGINE.GetItemAttrText(
11725 itemtype => l_itemtype,
11726 itemkey => l_itemkey,
11727 aname => 'CURRENCY');
11728 l_doc_cctr := WF_ENGINE.GetItemAttrText(
11729 itemtype => l_itemtype,
11730 itemkey => l_itemkey,
11731 aname => 'DOC_COST_CENTER');
11732 l_purpose := WF_ENGINE.GetItemAttrText(
11733 itemtype => l_itemtype,
11734 itemkey => l_itemkey,
11735 aname => 'PURPOSE');
11736
11737 -- Bug: 8537082, No workflow exists for reports in error, moved the code here
11738 l_debug_info := 'Update AME as if rejected';
11739 -- Bug 3560082 - Comment the call to SetRejectStatusInAME and add the call
11740 -- AME_API.clearAllApprovals
11741 l_AMEEnabled := WF_ENGINE.GetItemAttrText(l_itemtype,
11742 l_itemkey,
11743 'AME_ENABLED');
11744 if (l_AMEEnabled = 'Y') then
11745 --Bug 4425821: Uptake AME parallel approvers
11746 if (C_WF_Version >= AP_WEB_EXPENSE_WF.C_R120_Version) then
11747 --------------------------------------------
11748 l_debug_info := 'Call AMEAbortRequestApprovals';
11749 --------------------------------------------
11750 AMEAbortRequestApprovals(p_rep_header_id,'Y');
11751 end if;
11752
11753 -----------------------------------------
11754 l_debug_info := 'Call clearAllApprovals';
11755 -----------------------------------------
11756 AME_API2.clearAllApprovals(applicationIdIn => AP_WEB_DB_UTIL_PKG.GetApplicationID,
11757 transactionIdIn => l_itemkey,
11758 transactionTypeIn => l_itemtype);
11759 end if;
11760 end if;
11761
11762
11763 l_debug_info := 'Set withdraw status in report header';
11764 IF (NOT AP_WEB_DB_EXPRPT_PKG.SetWkflApprvdFlagAndSource(p_rep_header_id,
11765 AP_WEB_DB_EXPRPT_PKG.C_WORKFLOW_APPROVED_WITHDRAW,
11766 'NonValidatedWebExpense')) THEN
11767 NULL;
11768 END IF;
11769
11770 AP_WEB_DB_EXPLINE_PKG.resetAPflags(p_rep_header_id);
11771 -- 4001778/3654956
11772 --5060928: reset the Apply Advnaces only if OIE:Enable Advances = "Payables"
11773
11774 IF (l_wf_exist) THEN
11775 begin
11776
11777 l_n_resp_id := WF_ENGINE.GetItemAttrNumber(l_itemtype,
11778 l_itemkey,
11779 'RESPONSIBILITY_ID');
11780
11781 exception
11782 when others then
11783 if (wf_core.error_name = 'WFENG_ITEM_ATTR') then
11784 null;
11785 else
11786 raise;
11787 end if;
11788 end;
11789 END IF;
11790 IF (nvl(l_n_resp_id,0) = 0) THEN
11791 l_n_resp_id := FND_PROFILE.VALUE('RESP_ID');
11792 END IF;
11793 IF FND_PROFILE.VALUE_SPECIFIC('OIE_ENABLE_ADVANCES',NULL,l_n_resp_id,200) = 'PAYABLES' THEN
11794
11795 AP_WEB_DB_EXPLINE_PKG.resetApplyAdvances(p_rep_header_id);
11796 END IF;
11797
11798 --AP_WEB_DB_VIOLATIONS_PKG.deleteViolationEntry(p_rep_header_id);
11799 --Delete the duplicate detection violations
11800 AP_WEB_DB_VIOLATIONS_PKG.deleteDupViolationEntry(p_rep_header_id);
11801 AP_WEB_AUDIT_QUEUE_UTILS.remove_from_queue(p_rep_header_id);
11802
11803 ----------------------------------------------------------
11804 l_debug_info := 'Reset Report Submitted Date to null And Expense Status Code to WITHDRAWN';
11805 ----------------------------------------------------------
11806 -- Bug 4070441
11807 begin
11808 update ap_expense_report_headers
11809 set report_submitted_date = null,
11810 last_update_date = sysdate, -- Bug 8411814 (sodash) added to update the who columns when a report is withdrawn
11811 expense_last_status_date = sysdate,
11812 expense_status_code = AP_WEB_OA_ACTIVE_PKG.C_WITHDRAWN
11813 where report_header_id = p_rep_header_id;
11814 exception
11815 when others then null;
11816 end;
11817
11818 ----------------------------------------------------------
11819 l_debug_info := 'Reset Receipt Verified Flag to N';
11820 ----------------------------------------------------------
11821 -- Bug 4094871
11822 begin
11823 update ap_expense_report_lines
11824 set receipt_verified_flag = l_No
11825 where report_header_id = p_rep_header_id;
11826 exception
11827 when others then null;
11828 end;
11829
11830 ----------------------------------------------------------
11831 l_debug_info := 'Clearing out lines in AP_AUD_AUDIT_REASONS';
11832 ----------------------------------------------------------
11833 -- Bug 4394168
11834 AP_WEB_AUDIT_UTILS.clear_audit_reason_codes(p_rep_header_id);
11835
11836 if l_wf_exist then
11837 l_debug_info := 'call reset credit card transactions 2';
11838 ResetCCardTxns(p_rep_header_id, l_itemtype, l_itemkey);
11839
11840 if l_wf_active then
11841 l_debug_info := 'Workflow Abort Process';
11842 wf_engine.AbortProcess (itemtype => l_itemtype,
11843 itemkey => l_itemkey,
11844 cascade => TRUE);
11845 end if;
11846
11847 l_debug_info := 'Purge workflow';
11848 wf_purge.Items(itemtype => l_itemtype,
11849 itemkey => l_itemkey);
11850
11851 /* Bug 3772025 : Calling wf_purge.TotalPerm to purge workflow with persistence type
11852 as 'Permanent'.
11853 */
11854
11855 wf_purge.TotalPerm(itemtype => l_itemtype,
11856 itemkey => l_itemkey,
11857 runtimeonly => TRUE);
11858
11859 end if;
11860
11861 -------------------------------------------------------------------
11862 l_debug_info := 'Save original language';
11863 -------------------------------------------------------------------
11864 l_orig_language_code := userenv('LANG');
11865 select nls_language
11866 into l_orig_language
11867 from fnd_languages
11868 where language_code = l_orig_language_code;
11869
11870 -------------------------------------------------------------------
11871 l_debug_info := 'Check AP_EXPENSE_PARAMS.NOTE_LANGUAGE_CODE';
11872 -------------------------------------------------------------------
11873 begin
11874 select note_language_code
11875 into l_new_language_code
11876 from ap_expense_params;
11877
11878 exception
11879 when no_data_found then
11880 null;
11881 end;
11882
11883 -------------------------------------------------------------------
11884 l_debug_info := 'Else use instance base language';
11885 -------------------------------------------------------------------
11886 if (l_new_language_code is null) then
11887 select language_code
11888 into l_new_language_code
11889 from fnd_languages
11890 where installed_flag in ('B');
11891 end if;
11892
11893 -------------------------------------------------------------------
11894 l_debug_info := 'Set nls context to new language';
11895 -------------------------------------------------------------------
11896 select nls_language
11897 into l_new_language
11898 from fnd_languages
11899 where language_code = l_new_language_code;
11900
11901 fnd_global.set_nls_context(p_nls_language => l_new_language);
11902
11903 begin
11904 -------------------------------------------------------------------
11905 -- fnd_global.set_nls_context() seems to work for WF but not FND_MESSAGES
11906 -------------------------------------------------------------------
11907 select message_text
11908 into l_note
11909 from fnd_new_messages
11910 where application_id = 200
11911 and message_name = l_message_name
11912 and language_code = l_new_language_code;
11913
11914 exception
11915 when no_data_found then
11916 FND_MESSAGE.SET_NAME('SQLAP', l_message_name);
11917 l_note := FND_MESSAGE.GET;
11918 end;
11919
11920 ------------------------------------------------------------
11921 l_debug_info := 'store the withdrawn note';
11922 ------------------------------------------------------------
11923 AP_WEB_NOTES_PKG.CreateERPrepToAudNote (
11924 p_report_header_id => p_rep_header_id,
11925 p_note => l_note,
11926 p_lang => l_new_language_code
11927 );
11928
11929 -------------------------------------------------------------------
11930 l_debug_info := 'Restore nls context to original language';
11931 -------------------------------------------------------------------
11932 fnd_global.set_nls_context(p_nls_language => l_orig_language);
11933
11934 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF',
11935 'end WF WithdrawExpenseRep');
11936 COMMIT;
11937
11938 ------------------------------------------------------------
11939 l_debug_info := 'Raise Receipts Aborted Event';
11940 ------------------------------------------------------------
11941 AP_WEB_RECEIPTS_WF.RaiseAbortedEvent(p_rep_header_id);
11942
11943 COMMIT;
11944
11945
11946 EXCEPTION
11947 WHEN OTHERS THEN
11948 ROLLBACK;
11949 APP_EXCEPTION.RAISE_EXCEPTION;
11950 END WithdrawExpenseRep;
11951
11952
11953 PROCEDURE GenerateExpClobLines(document_id IN VARCHAR2,
11954 display_type IN VARCHAR2,
11955 document IN OUT NOCOPY CLOB,
11956 document_type IN OUT NOCOPY VARCHAR2) IS
11957
11958 l_colon NUMBER;
11959 l_itemtype VARCHAR2(7);
11960 l_itemkey VARCHAR2(25);
11961
11962 l_report_header_id AP_WEB_DB_EXPLINE_PKG.expLines_headerID;
11963 l_receipt_missing_flag AP_WEB_DB_EXPLINE_PKG.expLines_receiptMissingFlag;
11964 l_start_date AP_WEB_DB_EXPLINE_PKG.expLines_startExpDate;
11965 l_days VARCHAR2(4);
11966 l_daily_amt AP_WEB_DB_EXPLINE_PKG.expLines_dailyAmount;
11967 l_receipt_curr AP_WEB_DB_EXPLINE_PKG.expLines_receiptCurrCode;
11968 l_receipt_rate VARCHAR2(5);
11969 l_receipt_amt VARCHAR2(10);
11970 l_total_amt AP_WEB_DB_EXPLINE_PKG.expLines_amount;
11971 l_expense_report_total_amt AP_WEB_DB_EXPLINE_PKG.expLines_amount;
11972 l_cc_personal_total_amt AP_WEB_DB_EXPLINE_PKG.expLines_amount;
11973 l_justification AP_WEB_DB_EXPLINE_PKG.expLines_justification;
11974 l_expense_type AP_WEB_DB_EXPTEMPLATE_PKG.expTempl_webFriendlyPrompt;
11975 l_project_number PA_PROJECTS.segment1%TYPE;
11976 l_task_number AP_WEB_DB_PA_INT_PKG.tasks_taskNum;
11977 l_award_number GMS_OIE_INT_PKG.gms_awardNum;
11978 l_credit_card_trx_id AP_WEB_DB_EXPLINE_PKG.expLines_crdCardTrxID;
11979 l_distribution_line_number AP_WEB_DB_EXPLINE_PKG.expLines_distLineNum;
11980 l_line_number NUMBER := 0;
11981 l_primary_number NUMBER := 1;
11982 l_line_display VARCHAR2(5);
11983 l_counter NUMBER := 1;
11984 l_violation_type AP_LOOKUP_CODES.DISPLAYED_FIELD%TYPE;
11985 l_employee_project_enabled VARCHAR2(1);
11986 -- Grants Integration
11987 l_grants_enabled VARCHAR2(1) := 'N';
11988 l_project_string VARCHAR2(100);
11989 l_line_info VARCHAR2(2000);
11990 l_num_lines NUMBER := 0;
11991 l_num_cc_lines NUMBER := 0;
11992 l_num_personal_lines NUMBER := 0;
11993 l_num_cash_lines NUMBER := 0;
11994 l_table_loop_counter NUMBER := 0;
11995 l_document_max NUMBER := 25000; -- 27721 fails
11996 l_is_cc_table BOOLEAN;
11997 l_currency VARCHAR2(50);
11998 l_colspan NUMBER := 0;
11999
12000 l_prompts AP_WEB_UTILITIES_PKG.prompts_table;
12001 l_title AK_REGIONS_VL.name%TYPE;
12002 l_debug_info VARCHAR2(1000);
12003
12004 XpenseLinesCursor AP_WEB_DB_EXPLINE_PKG.DisplayXpenseLinesCursor;
12005 PersonalLinesCursor AP_WEB_DB_EXPLINE_PKG.DisplayXpenseLinesCursor;
12006
12007 --Bug 2944363
12008 BothPayPersonalLinesCursor AP_WEB_DB_EXPLINE_PKG.DisplayXpenseLinesCursor;
12009
12010
12011 l_n_org_id Number;
12012
12013 l_show_message VARCHAR2(1) := 'N';
12014 l_message VARCHAR2(2000);
12015 l_rules_violated VARCHAR2(1) := 'N';
12016 l_last_dist_number AP_WEB_DB_EXPLINE_PKG.expLines_distLineNum
12017 := -1;
12018
12019 l_document long;
12020
12021 l_flex_concatenated AP_EXPENSE_REPORT_LINES.flex_concatenated%TYPE;
12022 l_line_accounting_enabled VARCHAR2(30);
12023 l_line_accounting_defined BOOLEAN;
12024 l_policy_violation_value VARCHAR2(50);
12025 l_policy_violation_defined BOOLEAN;
12026 l_n_resp_id Number;
12027 l_mrate_adjusted_flag AP_EXPENSE_REPORT_LINES.mileage_rate_adjusted_flag%TYPE;
12028 l_mileage_note VARCHAR2(2000);
12029 l_notification_type VARCHAR2(10);
12030 l_print_violation VARCHAR2(1) := 'N';
12031 l_merchant_name AP_EXPENSE_REPORT_LINES.merchant_name%TYPE;
12032 l_co_merchant_count NUMBER;
12033
12034 l_num_both_personal_lines NUMBER := 0; --Bug 2944363
12035 l_payment VARCHAR2(10);--Bug 2944363
12036 l_cc_trxn_date VARCHAR2(50);--Bug 2944363
12037 l_cc_expensed_amt AP_WEB_DB_EXPLINE_PKG.expLines_amount;--Bug 2944363
12038 l_cc_curr_code VARCHAR2(20); --Bug 2944363
12039 l_cc_merchant_name AP_CREDIT_CARD_TRXNS_ALL.merchant_name1%TYPE;--Bug 2944363
12040 l_payment_due_from VARCHAR2(10) := 'INDIVIDUAL';
12041
12042 BEGIN
12043
12044 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start GenerateExpClobLines');
12045
12046 ------------------------------------------------------------
12047 l_debug_info := 'Decode document_id';
12048 ------------------------------------------------------------
12049 l_colon := instrb(document_id, ':');
12050 l_debug_info := ' First index: ' || to_char(l_colon);
12051 l_itemtype := substrb(document_id, 1, l_colon - 1);
12052 l_itemkey := substrb(document_id, l_colon + 1);
12053 l_colon := instrb(l_itemkey, ':');
12054
12055 ------------------------------------------------------------
12056 l_debug_info := 'Second index: ' || to_char(l_colon);
12057 ------------------------------------------------------------
12058 IF (l_colon > 0) THEN
12059 l_notification_type := substrb(l_itemkey, l_colon + 1);
12060 l_itemkey := substrb(l_itemkey, 1, l_colon - 1);
12061 ELSE
12062 l_notification_type := C_OTHER;
12063 END IF;
12064
12065 ------------------------------------------------------------
12066 l_debug_info := 'Get prompts';
12067 ------------------------------------------------------------
12068 AP_WEB_DISC_PKG.getPrompts(200,'AP_WEB_WF_LINETABLE',l_title,l_prompts);
12069
12070 ------------------------------------------------------------
12071 l_debug_info := 'Check Projects enabled';
12072 ------------------------------------------------------------
12073 l_employee_project_enabled := WF_ENGINE.GetItemAttrText(l_itemtype,
12074 l_itemkey,
12075 'EMPLOYEE_PROJECT_ENABLED');
12076
12077 ------------------------------------------------------------
12078 l_debug_info := 'Check Grants enabled';
12079 ------------------------------------------------------------
12080 begin
12081 l_grants_enabled := WF_ENGINE.GetItemAttrText(l_itemtype,
12082 l_itemkey,
12083 'GRANTS_ENABLED');
12084
12085 ------------------------------------------------------------
12086 l_debug_info := 'Get responsibility id';
12087 ------------------------------------------------------------
12088 l_n_resp_id := WF_ENGINE.GetItemAttrNumber(l_itemtype,
12089 l_itemkey,
12090 'RESPONSIBILITY_ID');
12091
12092 exception
12093 when others then
12094 if (wf_core.error_name = 'WFENG_ITEM_ATTR') then
12095 null;
12096 else
12097 raise;
12098 end if;
12099 end;
12100
12101 ------------------------------------------------------------
12102 l_debug_info := 'Check line level accounting enabled';
12103 ------------------------------------------------------------
12104 FND_PROFILE.get_specific('OIE_ENABLE_LINE_LEVEL_ACCOUNTING', null,
12105 l_n_resp_id, 200, l_line_accounting_enabled, l_line_accounting_defined);
12106
12107
12108 if l_line_accounting_defined then
12109 l_line_accounting_enabled := NVL(l_line_accounting_enabled,'N');
12110 else
12111 l_line_accounting_enabled := 'N';
12112 end if;
12113
12114 ------------------------------------------------------------
12115 l_debug_info := 'Get policy profile option';
12116 ------------------------------------------------------------
12117 FND_PROFILE.get_specific('AP_WEB_POLICY_VIOLATION_SUBMIT', null,
12118 l_n_resp_id, 200, l_policy_violation_value, l_policy_violation_defined);
12119
12120 if l_policy_violation_defined then
12121 l_policy_violation_value := NVL(l_policy_violation_value, C_ALLOW_NO_WARNINGS);
12122 else
12123 l_policy_violation_value := C_ALLOW_NO_WARNINGS;
12124 end if;
12125
12126 ------------------------------------------------------------
12127 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
12128 ------------------------------------------------------------
12129 l_report_header_id := WF_ENGINE.GetItemAttrNumber(l_itemtype,
12130 l_itemkey,
12131 'EXPENSE_REPORT_ID');
12132
12133 ------------------------------------------------------------
12134 l_debug_info := 'Retrieve Currency Item Attribute';
12135 ------------------------------------------------------------
12136 l_currency := WF_ENGINE.GetItemAttrText(l_itemtype,
12137 l_itemkey,
12138 'CURRENCY');
12139
12140 ------------------------------------------------------------
12141 l_debug_info := 'Retrieve MILEAGE NOTE Item Attribute';
12142 ------------------------------------------------------------
12143 begin
12144 l_mileage_note := WF_ENGINE.GetItemAttrText(l_itemtype,
12145 l_itemkey,
12146 'MILEAGE_NOTE');
12147 exception
12148 when others then
12149 if (wf_core.error_name = 'WFENG_ITEM_ATTR') then
12150 null;
12151 else
12152 raise;
12153 end if;
12154 end;
12155
12156 --------------------------------------------
12157 l_debug_info := 'Get Org Id';
12158 --------------------------------------------
12159 begin
12160
12161 l_n_org_id := WF_ENGINE.GetItemAttrNumber(l_itemtype,
12162 l_itemkey,
12163 'ORG_ID');
12164 exception
12165 when others then
12166 if (wf_core.error_name = 'WFENG_ITEM_ATTR') then
12167 -- ORG_ID item attribute doesn't exist, need to add it
12168 WF_ENGINE.AddItemAttr(l_itemtype, l_itemkey, 'ORG_ID');
12169 IF (AP_WEB_DB_EXPRPT_PKG.GetOrgIdByReportHeaderId(
12170 to_number(l_itemkey),
12171 l_n_org_id) <> TRUE ) THEN
12172 l_n_org_id := NULL;
12173 END IF;
12174
12175 WF_ENGINE.SetItemAttrNumber(l_itemtype,
12176 l_itemkey,
12177 'ORG_ID',
12178 l_n_org_ID);
12179 else
12180 raise;
12181 end if;
12182
12183 end;
12184
12185 -- MOAC UPTAKE --
12186 -- Should not have to initialize the org context
12187 -- This is done via callbackfunction()
12188 /*--------------------
12189 if (l_n_org_id is not null) then
12190 fnd_client_info.set_org_context(l_n_org_id);
12191 else
12192 -- Report was submitted before org_id being added, hence org_id
12193 -- item attributes hasn't been set yet. Need to get it from
12194 -- report header
12195 IF (AP_WEB_DB_EXPRPT_PKG.GetOrgIdByReportHeaderId(to_number(l_itemkey), l_n_org_id) <> TRUE ) THEN
12196 l_n_org_id := NULL;
12197 END IF;
12198
12199 IF (l_n_org_id is not null) then
12200 fnd_client_info.set_org_context(l_n_org_id);
12201 END IF;
12202
12203 end if; -- l_n_org_id
12204 --------------------*/
12205
12206 --------------------------------------------
12207 l_debug_info := 'get Number of ExpLines';
12208 --------------------------------------------
12209 if (AP_WEB_DB_EXPLINE_PKG.GetNumberOfExpLines(l_report_header_id, l_num_lines)) then null; end if;
12210
12211 if (l_num_lines = 0) then
12212
12213 /*Bug 2944363: Dont raise SHORTPAID error if the expense report
12214 does not have any lines. raise it conditionally because
12215 an ER in BOTHPAY having only personal CC trx will
12216 also not have any lines.
12217 */
12218 --AMMISHRA - Both Pay Personal Only Lines project.
12219 if (AP_WEB_DB_EXPLINE_PKG.GetNoOfBothPayPersonalLines(l_report_header_id,l_num_both_personal_lines)) then null; end if;
12220
12221 ----------------------------------------------------------------
12222 l_debug_info := 'Retrieve Profile Option Payment Due From';
12223 ----------------------------------------------------------------
12224
12225 IF (NOT AP_WEB_DB_EXPRPT_PKG.getPaymentDueFromReport(to_number(l_itemkey),l_payment)) THEN
12226 l_debug_info := 'Could not set workflow attribute Payment_Due_From';
12227 END IF;
12228
12229 IF (l_payment = 'BOTH' and l_num_both_personal_lines > 0) THEN
12230 NULL;
12231 ELSE
12232 FND_MESSAGE.SET_NAME('SQLAP','AP_WEB_EXP_REPORT_SHORTPAID');
12233 WF_NOTIFICATION.WriteToClob(document,fnd_message.get);
12234 document_type := display_type;
12235 return;
12236 END IF;
12237 --Bug 2944363 End here.
12238
12239 end if;
12240
12241 l_document := '';
12242 if (display_type = 'text/plain') then
12243 l_num_lines := 0;
12244 --------------------------------------------
12245 l_debug_info := 'Generate Table Header';
12246 --------------------------------------------
12247
12248 --------------------------------------------
12249 l_debug_info := 'Open Expense Lines Cursor';
12250 --------------------------------------------
12251 IF (AP_WEB_DB_EXPLINE_PKG.GetDisplayXpenseLinesCursor(l_report_header_id, XpenseLinesCursor)) THEN
12252
12253 LOOP
12254
12255 --------------------------------------------
12256 l_debug_info := 'Fetch Expense Lines Cursor';
12257 --------------------------------------------
12258 FETCH XpenseLinesCursor INTO l_receipt_missing_flag,
12259 l_start_date,
12260 l_days,
12261 l_daily_amt,
12262 l_receipt_curr,
12263 l_receipt_rate,
12264 l_receipt_amt,
12265 l_total_amt,
12266 l_justification,
12267 l_expense_type,
12268 l_project_number,
12269 l_task_number,
12270 l_credit_card_trx_id,
12271 l_distribution_line_number,
12272 l_award_number,
12273 l_violation_type,
12274 l_merchant_name;
12275
12276 EXIT WHEN XpenseLinesCursor%NOTFOUND;
12277
12278 l_num_lines := l_num_lines + 1;
12279
12280 -------------------------------------------------------------------
12281 l_debug_info := 'Check if Receipt missing, print * next to line and set boolean flag';
12282 -------------------------------------------------------------------
12283 IF (l_receipt_missing_flag = 'Y') THEN
12284 l_line_info := ' * ';
12285 ELSE
12286 l_line_info := ' ';
12287 END IF;
12288
12289 --------------------------------------------
12290 l_debug_info := 'Format Expense Line Info';
12291 --------------------------------------------
12292 l_project_string := '';
12293 IF (l_project_number IS NOT NULL) THEN
12294 l_project_string := l_project_number || ' ' || l_task_number;
12295 if (l_grants_enabled = 'Y') then
12296 l_project_string := l_project_string || ' ' || l_award_number;
12297 end if;
12298 END IF;
12299 l_line_info := '(' || to_char(l_num_lines) || ')' || l_line_info || ' '|| l_start_date
12300 || l_expense_type || ' ' || l_project_string
12301 || ' ' || LPAD(to_char(l_total_amt, FND_CURRENCY.Get_Format_Mask(l_currency,22)),14);
12302 -- set a new line
12303 l_document := l_document || '
12304 ';
12305 l_document := l_document || l_line_info;
12306 -- set a new line
12307 l_document := l_document || '
12308 ';
12309 l_document := l_document || '----> ' || l_justification;
12310 l_line_info := '';
12311
12312 END LOOP; -- GetDisplayXpenseLinesCursor
12313
12314 END IF; -- GetDisplayXpenseLinesCursor
12315
12316 if XpenseLinesCursor%isopen then /*Bug 3422298 */
12317 close XpenseLinesCursor;
12318 end if;
12319
12320 else -- text/html
12321
12322 --------------------------------------------
12323 l_debug_info := 'get Number of Cash/Credit Card lines';
12324 --------------------------------------------
12325 if (AP_WEB_DB_EXPLINE_PKG.GetNumCCLinesIncluded(l_report_header_id, l_num_cc_lines)) then null; end if;
12326 l_num_cash_lines := l_num_lines - l_num_cc_lines;
12327
12328
12329 --------------------------------------------
12330 l_debug_info := 'get Number of Cash/Credit Card lines';
12331 --------------------------------------------
12332 if (AP_WEB_DB_EXPLINE_PKG.GetNumCashLinesWOMerch(l_report_header_id, l_co_merchant_count)) then null; end if;
12333
12334 --------------------------------------------
12335 l_debug_info := 'loop thru Cash/Credit Card lines';
12336 --------------------------------------------
12337 for l_table_loop_counter in 1..2
12338 loop
12339
12340 IF lengthb(l_document) >= l_document_max THEN
12341 -- Appends l_document to end of document (CLOB object)
12342 WF_NOTIFICATION.WriteToClob(document,l_document);
12343 l_document := '';
12344 --l_show_message := 'Y';
12345 --exit;
12346 END IF;
12347
12348 l_expense_report_total_amt := 0;
12349 l_num_lines := 0;
12350 l_line_number := 0;
12351 l_primary_number := 1;
12352 l_counter := 1;
12353
12354 if (l_table_loop_counter = 1) then
12355 l_is_cc_table := true;
12356 else
12357 l_is_cc_table := false;
12358 end if;
12359
12360 --------------------------------------------
12361 l_debug_info := 'Traverse selected lines';
12362 --------------------------------------------
12363 if ((l_is_cc_table AND l_num_cc_lines > 0) OR
12364 (NOT l_is_cc_table AND l_num_cash_lines > 0)) then
12365
12366 --------------------------------------------
12367 l_debug_info := 'Generate Table Header';
12368 --------------------------------------------
12369 if l_is_cc_table then
12370 l_document := l_document || indent_start || table_title_start || l_prompts(1) || table_title_end;
12371 else
12372 l_document := l_document || indent_start || table_title_start || l_prompts(2) || table_title_end;
12373 end if;
12374
12375 l_document := l_document || table_start;
12376
12377 l_document := l_document || tr_start;
12378
12379
12380 IF (AP_WEB_DB_EXPLINE_PKG.AnyPolicyViolation(l_report_header_id)) THEN
12381 l_rules_violated := 'Y';
12382 END IF;
12383
12384 /* If the profile option is set to APPROVER_ONLY
12385 (ALLOW_NO_WARNINGS), do not show any violations to the employee
12386 notifications. */
12387 IF (l_rules_violated = 'Y' ) THEN
12388 IF ((l_policy_violation_value = C_ALLOW_NO_WARNINGS) AND
12389 (l_notification_type <> C_EMP)) OR
12390 (l_policy_violation_value <> C_ALLOW_NO_WARNINGS) THEN
12391 l_print_violation := 'Y';
12392 l_document := l_document || th_text || '&' || 'nbsp;' || td_end;
12393 END IF;
12394 END IF;
12395
12396
12397 -- display Line Number
12398 l_document := l_document || th_select || l_prompts(13) || td_end;
12399
12400
12401 IF (l_rules_violated = 'Y' ) THEN
12402 IF ((l_policy_violation_value = C_ALLOW_NO_WARNINGS) AND
12403 (l_notification_type <> C_EMP)) OR
12404 (l_policy_violation_value <> C_ALLOW_NO_WARNINGS) THEN
12405 l_document := l_document || th_text || l_prompts(14) || td_end;
12406 END IF;
12407 END IF;
12408
12409 -- display Date
12410 l_document := l_document || th_text || l_prompts(4) || td_end;
12411 -- display Expense Type
12412 l_document := l_document || th_text || l_prompts(5) || td_end;
12413 -- display Merchant Name
12414 if ((l_is_cc_table) or (NOT l_is_cc_table and l_co_merchant_count > 0)) then
12415 l_document := l_document || th_text || l_prompts(27) || td_end;
12416 end if;
12417 if (l_employee_project_enabled = 'Y') then
12418 -- display Project/Task only when Projects enabled
12419 l_document := l_document || th_text || l_prompts(6) || td_end;
12420 l_document := l_document || th_text || l_prompts(7) || td_end;
12421 -- Grants Integration
12422 if (l_grants_enabled = 'Y') then
12423 l_document := l_document || th_text || l_prompts(8) || td_end;
12424 end if;
12425 end if;
12426 -- display Amount
12427 l_document := l_document || th_number || l_prompts(9) || td_end;
12428 -- display Justification
12429 l_document := l_document || th_text || l_prompts(10) || td_end;
12430
12431 if (l_line_accounting_enabled = 'Y') then
12432 l_document := l_document || th_text || l_prompts(15) || td_end;
12433 end if;
12434 l_document := l_document || tr_end;
12435
12436 --------------------------------------------
12437 l_debug_info := 'Open Expense Lines Cursor';
12438 --------------------------------------------
12439 IF (AP_WEB_DB_EXPLINE_PKG.GetDisplayXpenseLinesCursor(l_report_header_id, l_is_cc_table, XpenseLinesCursor)) THEN
12440
12441 LOOP
12442
12443 --------------------------------------------
12444 l_debug_info := 'Fetch Expense Lines Cursor';
12445 --------------------------------------------
12446 FETCH XpenseLinesCursor INTO l_receipt_missing_flag,
12447 l_start_date,
12448 l_days,
12449 l_daily_amt,
12450 l_receipt_curr,
12451 l_receipt_rate,
12452 l_receipt_amt,
12453 l_total_amt,
12454 l_justification,
12455 l_expense_type,
12456 l_project_number,
12457 l_task_number,
12458 l_credit_card_trx_id,
12459 l_distribution_line_number,
12460 l_award_number,
12461 l_violation_type,
12462 l_merchant_name,
12463 l_flex_concatenated,
12464 l_mrate_adjusted_flag;
12465
12466 EXIT WHEN XpenseLinesCursor%NOTFOUND;
12467
12468 IF lengthb(l_document) >= l_document_max THEN
12469 -- Appends l_document to end of document (CLOB object)
12470 WF_NOTIFICATION.WriteToClob(document,l_document);
12471 l_document := '';
12472 --l_show_message := 'Y';
12473 --exit;
12474 END IF;
12475
12476 IF ((l_notification_type = C_EMP) AND
12477 (l_policy_violation_value = C_ALLOW_NO_WARNINGS) AND
12478 (l_distribution_line_number = l_last_dist_number)) THEN
12479 null;
12480 ELSE
12481 l_num_lines := l_num_lines + 1;
12482 l_document := l_document || tr_start;
12483 ------------------------------------------------------------
12484 l_debug_info := 'If policy violated, indicate with a gif';
12485 ------------------------------------------------------------
12486 IF (l_rules_violated = 'Y' ) THEN
12487 IF ((l_policy_violation_value = C_ALLOW_NO_WARNINGS) AND
12488 (l_notification_type <> C_EMP)) OR
12489 (l_policy_violation_value <> C_ALLOW_NO_WARNINGS) THEN
12490 IF (l_violation_type is not null ) THEN
12491 l_document := l_document || td_text || '**' || td_end;
12492 -- Bug 2750863: With WF mailer limitation, images can't be
12493 -- displayed on email notifications. Therefore, taking the
12494 -- image out from the following until the WF issue has been
12495 -- addressed.
12496 --face='||td_fontface||'><img src="/OA_MEDIA/warningicon_status.gif">'||td_end;
12497 ELSE
12498 l_document := l_document || td_text || '&' || 'nbsp;' || td_end;
12499 END IF;
12500 END IF;
12501 END IF;
12502
12503 IF l_mileage_note is not null THEN
12504 IF (l_mrate_adjusted_flag is not null) THEN
12505 l_line_info := '* ';
12506 ELSE
12507 l_line_info := '&' || 'nbsp;' || '&' || 'nbsp;';
12508 END IF;
12509
12510 ELSE
12511 ------------------------------------------------------------
12512 l_debug_info := 'If Any Receipts Missing Then Print Warning';
12513 ------------------------------------------------------------
12514 IF (l_receipt_missing_flag = 'Y') THEN
12515 l_line_info := '* ';
12516 ELSE
12517 l_line_info := '&' || 'nbsp;' || '&' || 'nbsp;';
12518 END IF;
12519 END IF;
12520
12521 IF (l_distribution_line_number <> l_last_dist_number) THEN
12522
12523 -- display Line Number
12524 l_document := l_document || td_select;
12525 --l_line_numbr := l_line_number + 1;
12526 l_line_display := l_primary_number;
12527 l_primary_number := l_primary_number + 1;
12528 l_counter := l_counter + 1;
12529 l_document := l_document || l_line_info || ' ' || l_line_display || ' ' || td_end;
12530 ELSE
12531 -- display Line Number
12532 l_document := l_document || td_select;
12533 l_document := l_document || l_line_info || td_end;
12534
12535 END IF;
12536
12537 ------------------------------------------------------------
12538 l_debug_info := 'If policy violated, show the violation type';
12539 ------------------------------------------------------------
12540 IF (l_rules_violated = 'Y' ) THEN
12541 IF ((l_policy_violation_value = C_ALLOW_NO_WARNINGS) AND
12542 (l_notification_type <> C_EMP)) OR
12543 (l_policy_violation_value <> C_ALLOW_NO_WARNINGS) THEN
12544 IF (l_violation_type is not null ) THEN
12545 l_document := l_document || td_text || nvl(l_violation_type, '&' || 'nbsp;') || td_end;
12546 ELSE
12547 l_document := l_document || td_text || '&' || 'nbsp;' || td_end;
12548 END IF;
12549 END IF;
12550 END IF;
12551
12552 IF (l_distribution_line_number <> l_last_dist_number) THEN
12553 -- display Date
12554 l_document := l_document || td_text;
12555 l_document := l_document || l_start_date || td_end;
12556 -- display Expense Type
12557 l_document := l_document || td_text || l_expense_type || td_end;
12558 -- display Merchant Name
12559 if ((l_is_cc_table) or (NOT l_is_cc_table and l_co_merchant_count > 0)) then
12560 l_document := l_document || td_text || WF_NOTIFICATION.SubstituteSpecialChars(l_merchant_name) || td_end;
12561 end if;
12562
12563 if (l_employee_project_enabled = 'Y') then
12564 -- display Project/Task only when Projects enabled
12565 l_document := l_document || td_text || nvl(l_project_number, '&' || 'nbsp;') || td_end;
12566 l_document := l_document || td_text || nvl(l_task_number, '&' || 'nbsp;') || td_end;
12567 if (l_grants_enabled = 'Y') then
12568 l_document := l_document || td_text || nvl(l_award_number, '&' || 'nbsp;') || td_end;
12569 end if;
12570 end if;
12571
12572 -- display Amount
12573 l_document := l_document || td_number || LPAD(to_char(l_total_amt, FND_CURRENCY.Get_Format_Mask(l_currency,22)),14) || td_end;
12574
12575 -- display Justification
12576 l_document := l_document || td_text || nvl(WF_NOTIFICATION.SubstituteSpecialChars(l_justification), '&' || 'nbsp;') || td_end;
12577
12578 if (l_line_accounting_enabled = 'Y') then
12579 l_document := l_document || td_text || nvl(l_flex_concatenated, '&' || 'nbsp;') || td_end;
12580 end if;
12581
12582 ELSE
12583 l_document := l_document || td_text || '&' || 'nbsp;' || td_end;
12584 l_document := l_document || td_text || '&' || 'nbsp;' || td_end;
12585
12586 -- display Merchant Name
12587 if ((l_is_cc_table) or (NOT l_is_cc_table and l_co_merchant_count > 0)) then
12588 l_document := l_document || td_text || WF_NOTIFICATION.SubstituteSpecialChars(l_merchant_name) || td_end;
12589 end if;
12590
12591 if (l_employee_project_enabled = 'Y') then
12592 -- display Project/Task only when Projects enabled
12593 l_document := l_document || td_text || '&' || 'nbsp;' || td_end;
12594 l_document := l_document || td_text || '&' || 'nbsp;' || td_end;
12595 if (l_grants_enabled = 'Y') then
12596 l_document := l_document || td_text || '&' || 'nbsp;' || td_end;
12597 end if;
12598 end if;
12599
12600
12601 -- display Amount
12602 l_document := l_document || td_number || '&' || 'nbsp;'|| td_end;
12603
12604 -- display Justification
12605 l_document := l_document || td_text || '&' || 'nbsp;' || td_end;
12606
12607 if (l_line_accounting_enabled = 'Y') then
12608 l_document := l_document || td_text || '&' || 'nbsp;' || td_end;
12609 end if;
12610
12611 END IF;
12612
12613
12614
12615 l_document := l_document || tr_end;
12616
12617 IF (l_distribution_line_number <> l_last_dist_number) THEN
12618 l_expense_report_total_amt := l_expense_report_total_amt + l_total_amt;
12619 END IF;
12620
12621 END IF;
12622
12623 l_last_dist_number := l_distribution_line_number;
12624 END LOOP; -- GetDisplayXpenseLinesCursor
12625
12626 END IF; -- GetDisplayXpenseLinesCursor
12627
12628 if XpenseLinesCursor%isopen then
12629 close XpenseLinesCursor;
12630 end if;
12631
12632 --------------------------------------------
12633 l_debug_info := 'Generate Total Row';
12634 --------------------------------------------
12635 l_document := l_document || tr_start;
12636 if (l_employee_project_enabled = 'Y') then
12637 if (l_grants_enabled = 'Y') and (l_print_violation = 'Y') then
12638 if ((l_is_cc_table) or (NOT l_is_cc_table and l_co_merchant_count > 0)) then
12639 l_colspan := 9;
12640 else
12641 l_colspan := 8;
12642 end if;
12643 elsif (l_grants_enabled = 'Y') and (l_print_violation = 'N') then
12644 if ((l_is_cc_table) or (NOT l_is_cc_table and l_co_merchant_count > 0)) then
12645 l_colspan := 7;
12646 else
12647 l_colspan := 6;
12648 end if;
12649 elsif (l_grants_enabled = 'N') and (l_print_violation = 'Y') then
12650 if ((l_is_cc_table) or (NOT l_is_cc_table and l_co_merchant_count > 0)) then
12651 l_colspan := 8;
12652 else
12653 l_colspan := 7;
12654 end if;
12655 elsif (l_grants_enabled = 'N') and (l_print_violation = 'N') then
12656 if ((l_is_cc_table) or (NOT l_is_cc_table and l_co_merchant_count > 0)) then
12657 l_colspan := 6;
12658 else
12659 l_colspan := 5;
12660 end if;
12661 end if;
12662 else
12663 if (l_grants_enabled = 'Y') and (l_print_violation = 'Y') then
12664 if ((l_is_cc_table) or (NOT l_is_cc_table and l_co_merchant_count > 0)) then
12665 l_colspan := 7;
12666 else
12667 l_colspan := 6;
12668 end if;
12669 elsif (l_grants_enabled = 'Y') and (l_print_violation = 'N') then
12670 if ((l_is_cc_table) or (NOT l_is_cc_table and l_co_merchant_count > 0)) then
12671 l_colspan := 4;
12672 else
12673 l_colspan := 3;
12674 end if;
12675 elsif (l_grants_enabled = 'N') and (l_print_violation = 'Y') then
12676 if ((l_is_cc_table) or (NOT l_is_cc_table and l_co_merchant_count > 0)) then
12677 l_colspan := 6;
12678 else
12679 l_colspan := 5;
12680 end if;
12681 elsif (l_grants_enabled = 'N') and (l_print_violation = 'N') then
12682 if ((l_is_cc_table) or (NOT l_is_cc_table and l_co_merchant_count > 0)) then
12683 l_colspan := 4;
12684 else
12685 l_colspan := 3;
12686 end if;
12687 end if;
12688 end if;
12689 -- display Total
12690 l_document := l_document || '<td colspan=' || l_colspan ||
12691 ' style="{font-family:Arial,Helvetica,Geneva,sans-serif;font-size:10pt;font-weight:bold;background-color:#cccc99;color:#336699;vertical-align:bottom;text-align:right}">' ||
12692 l_prompts(12) || td_end;
12693
12694 l_document := l_document || td_number || LPAD(to_char(l_expense_report_total_amt, FND_CURRENCY.Get_Format_Mask(l_currency,22)),14) || td_end;
12695 l_document := l_document || th_number || '&' || 'nbsp;' || td_end;
12696
12697 if (l_line_accounting_enabled = 'Y') then
12698 l_document := l_document || th_number || '&' || 'nbsp;' || td_end;
12699 end if;
12700 l_document := l_document || tr_end;
12701 l_document := l_document || table_end || indent_end;
12702
12703 end if; -- traverse selected lines
12704
12705 end loop; -- l_table_loop_counter
12706
12707
12708 --------------------------------------------
12709 l_debug_info := 'Display Company Pay Corporate Credit Card Personal Expenses';
12710 --------------------------------------------
12711
12712 --------------------------------------------
12713 l_debug_info := 'Check to see if Company Pay scenario';
12714 --------------------------------------------
12715 begin
12716 l_payment_due_from := WF_ENGINE.GetItemAttrText(l_itemtype,l_itemkey,'PAYMENT_DUE_FROM');
12717 exception
12718 when others then
12719 if (wf_core.error_name = 'WFENG_ITEM_ATTR') then
12720 null;
12721 else
12722 raise;
12723 end if;
12724 end;
12725 if (l_show_message = 'N' AND C_CompanyPay = l_payment_due_from) then
12726
12727 --------------------------------------------
12728 l_debug_info := 'get Number of Personal Credit Card lines';
12729 --------------------------------------------
12730 if (AP_WEB_DB_EXPLINE_PKG.GetNumberOfPersonalLines(l_report_header_id, l_num_personal_lines)) then null; end if;
12731
12732 if (l_num_personal_lines > 0) then
12733
12734 --------------------------------------------
12735 l_debug_info := 'Generate Table Header';
12736 --------------------------------------------
12737 l_document := l_document || indent_start || table_title_start || l_prompts(3) || table_title_end;
12738
12739 l_document := l_document || table_start;
12740
12741 l_document := l_document || tr_start;
12742 -- display Date
12743 l_document := l_document || th_text || l_prompts(4) || td_end;
12744
12745 -- display Merchant
12746 --Bug 2942773: Add Merchant Name to personal Expenses Table.
12747 l_document := l_document || th_text || l_prompts(27) || td_end;
12748 -- display Amount
12749 l_document := l_document || th_number || l_prompts(9) || td_end;
12750 l_document := l_document || tr_end;
12751
12752 --------------------------------------------
12753 l_debug_info := 'Open Personal Lines Cursor';
12754 --------------------------------------------
12755 IF (AP_WEB_DB_EXPLINE_PKG.GetDisplayPersonalLinesCursor(l_report_header_id, PersonalLinesCursor)) THEN
12756
12757 l_num_lines := 0;
12758 l_cc_personal_total_amt := 0;
12759 LOOP
12760
12761 --------------------------------------------
12762 l_debug_info := 'Fetch Personal Lines Cursor';
12763 --------------------------------------------
12764 FETCH PersonalLinesCursor INTO l_receipt_missing_flag,
12765 l_start_date,
12766 l_days,
12767 l_daily_amt,
12768 l_receipt_curr,
12769 l_receipt_rate,
12770 l_receipt_amt,
12771 l_total_amt,
12772 l_justification,
12773 l_expense_type,
12774 l_project_number,
12775 l_task_number,
12776 l_credit_card_trx_id,
12777 l_distribution_line_number,
12778 l_merchant_name; --Bug 29427743.
12779 EXIT WHEN PersonalLinesCursor%NOTFOUND;
12780
12781 IF lengthb(l_document) >= l_document_max THEN
12782 -- Appends l_document to end of document (CLOB object)
12783 WF_NOTIFICATION.WriteToClob(document,l_document);
12784 l_document := '';
12785 --l_show_message := 'Y';
12786 --exit;
12787 END IF;
12788
12789 l_total_amt := -(l_total_amt) ; -- Bug 2824304. Reversing the sign of Personal Expenses since they are negated and stored in database.
12790 l_num_lines := l_num_lines + 1;
12791
12792 -- Bug 2824304: Removed use of abs function for displaying Personal Expenses Amount and the Total.
12793
12794 l_document := l_document || tr_start;
12795
12796 -- display Date
12797 l_document := l_document || td_text || l_start_date || td_end;
12798
12799 -- display Merchant
12800 --Bug 2942773: Add Merchant name value to personal expense table.
12801 l_document := l_document || td_text || WF_NOTIFICATION.SubstituteSpecialChars(l_merchant_name) || td_end;
12802 -- display Amount
12803 l_document := l_document || td_number || LPAD(to_char(l_total_amt, FND_CURRENCY.Get_Format_Mask(l_currency,22)),14) || td_end;
12804 l_document := l_document || tr_end;
12805
12806 l_cc_personal_total_amt := l_cc_personal_total_amt + l_total_amt;
12807
12808 END LOOP; -- GetDisplayPersonalLinesCursor
12809
12810 END IF; -- GetDisplayPersonalLinesCursor
12811
12812 if PersonalLinesCursor%isopen then
12813 close PersonalLinesCursor;
12814 end if;
12815 --------------------------------------------
12816 l_debug_info := 'Generate Total Row';
12817 --------------------------------------------
12818 l_document := l_document || tr_start;
12819 --Bug 2942773: Add colspans to Total AMount so that it will appear under Amount
12820
12821 -- display Total
12822 l_document := l_document || '<td colspan=2 style="{font-family:Arial,Helvetica,Geneva,sans-serif;font-size:10pt;font-weight:bold;background-color:#cccc99;color:#336699;vertical-align:bottom;text-align:right}">' || l_prompts(12) || td_end;
12823
12824 l_document := l_document || td_number || LPAD(to_char(l_cc_personal_total_amt, FND_CURRENCY.Get_Format_Mask(l_currency,22)),14) || td_end;
12825 l_document := l_document || tr_end;
12826 l_document := l_document || table_end || indent_end;
12827
12828 end if; -- l_num_personal_lines > 0
12829
12830 end if; -- Display Company Pay Corporate Credit Card Personal Expenses
12831
12832 /*Bug 2944363: Added code to show the table for personal expenses in Both Pay.*/
12833
12834 --AMMISHRA - Both Pay Personal Only Lines project.
12835
12836 --------------------------------------------
12837 l_debug_info := 'Check to see if Both Pay scenario';
12838 --------------------------------------------
12839 IF (NOT AP_WEB_DB_EXPRPT_PKG.getPaymentDueFromReport(l_report_header_id,l_payment)) THEN
12840 l_debug_info := 'Could not set workflow attribute Payment_Due_From';
12841 END IF;
12842 if (l_show_message = 'N' AND C_BothPay = l_payment) then
12843 --------------------------------------------
12844 l_debug_info := 'get Number of Personal Credit Card lines Both Pay';
12845 --------------------------------------------
12846 if (AP_WEB_DB_EXPLINE_PKG.GetNoOfBothPayPersonalLines(l_report_header_id, l_num_personal_lines)) then null; end if;
12847 if (l_num_personal_lines > 0) then
12848
12849 --------------------------------------------
12850 l_debug_info := 'Generate Table Header';
12851 --------------------------------------------
12852 l_document := l_document || indent_start || table_title_start || l_prompts(3) || table_title_end;
12853
12854 l_document := l_document || table_start;
12855
12856 l_document := l_document || tr_start;
12857
12858 -- display Date
12859 l_document := l_document || th_text || l_prompts(4) || td_end;
12860
12861 -- display Merchant
12862 l_document := l_document || th_text || l_prompts(27) || td_end;
12863
12864 -- display Amount
12865 l_document := l_document || th_number || l_prompts(9) || td_end;
12866
12867 l_document := l_document || tr_end;
12868
12869 ------------------End Of Table Header------------------
12870 --------------------------------------------
12871 l_debug_info := 'Open BothPay Personal Lines Cursor';
12872 --------------------------------------------
12873 IF (AP_WEB_DB_EXPLINE_PKG.GetBothPayPersonalLinesCursor(l_report_header_id, BothPayPersonalLinesCursor)) THEN
12874
12875 l_num_lines := 0;
12876 l_cc_personal_total_amt := 0;
12877 LOOP
12878
12879 --------------------------------------------
12880 l_debug_info := 'Fetch Personal Lines Cursor';
12881 --------------------------------------------
12882 FETCH BothPayPersonalLinesCursor INTO
12883 l_cc_trxn_date,
12884 l_cc_expensed_amt,
12885 l_cc_curr_code,
12886 l_cc_merchant_name;
12887 EXIT WHEN BothPayPersonalLinesCursor%NOTFOUND;
12888 IF lengthb(l_document) >= l_document_max THEN
12889 -- Appends l_document to end of document (CLOB object)
12890 WF_NOTIFICATION.WriteToClob(document,l_document);
12891 l_document := '';
12892 --l_show_message := 'Y';
12893 --exit;
12894 END IF;
12895 l_num_lines := l_num_lines + 1;
12896
12897 l_document := l_document || tr_start;
12898 -- display Date
12899 l_document := l_document || td_text || l_cc_trxn_date || td_end;
12900 -- display Merchant
12901 l_document := l_document || td_text || WF_NOTIFICATION.SubstituteSpecialChars(l_cc_merchant_name) || td_end;
12902 -- display Amount
12903 l_document := l_document || td_number || LPAD(to_char(l_cc_expensed_amt, FND_CURRENCY.Get_Format_Mask(l_cc_curr_code,22)),14) || td_end;
12904 l_document := l_document || tr_end;
12905
12906 l_cc_personal_total_amt := l_cc_personal_total_amt + to_number(l_cc_expensed_amt);
12907
12908 END LOOP; -- GetDisplayPersonalLinesCursor
12909
12910 END IF; -- GetDisplayPersonalLinesCursor
12911
12912 if BothPayPersonalLinesCursor%isopen then
12913 close BothPayPersonalLinesCursor;
12914 end if;
12915
12916 --------------------------------------------
12917 l_debug_info := 'Generate Total Row';
12918 --------------------------------------------
12919 l_document := l_document || tr_start;
12920 -- display Total
12921 l_document := l_document || '<td colspan=2 style="{font-family:Arial,Helvetica,Geneva,sans-serif;font-size:10pt;font-weight:bold;background-color:#cccc99;color:#336699;vertical-align:bottom;text-align:right}">' || l_prompts(12) || td_end;
12922 l_document := l_document || td_number || LPAD(to_char(l_cc_personal_total_amt, FND_CURRENCY.Get_Format_Mask(l_cc_curr_code,22)),14) || td_end;
12923 l_document := l_document || tr_end;
12924 l_document := l_document || table_end || indent_end;
12925
12926 end if; -- l_num_personal_lines > 0
12927
12928 end if; -- Display Both Pay Corporate Credit Card Personal Expenses
12929
12930 --2944363:End of Both pay Personal Table.
12931
12932 --------------------------------------------
12933 l_debug_info := 'Unable to show more lines';
12934 --------------------------------------------
12935 IF l_show_message = 'Y' THEN
12936 FND_MESSAGE.SET_NAME('SQLAP','AP_WEB_EXP_UNABLE_TO_SHOWLINES');
12937 FND_MESSAGE.SET_TOKEN('NO_OF_LINES',to_char(l_num_lines));
12938 l_message := FND_MESSAGE.GET;
12939 l_document := l_document || table_start;
12940 l_document := l_document || tr_start || '&' || 'nbsp;' || tr_end;
12941 l_document := l_document || tr_start || '&' || 'nbsp;' || tr_end;
12942 l_document := l_document || tr_start || td_start || l_message || td_end || tr_end;
12943 l_document := l_document || table_end || indent_end;
12944 END IF;
12945
12946 end if; -- text/plain vs text/html
12947
12948 /* Bug 3561386 : Should add l_document to the clob only if it is
12949 * not null.
12950 */
12951 IF l_document is not null then
12952 WF_NOTIFICATION.WriteToClob(document,l_document);
12953 END IF;
12954
12955 document_type := display_type;
12956
12957 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end GenerateExpClobLines');
12958
12959 EXCEPTION
12960 WHEN OTHERS THEN
12961 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'GenerateExpClobLines',
12962 document_id, l_debug_info);
12963 raise;
12964 END GenerateExpClobLines;
12965
12966 -------------------------------------------------------------------------------
12967 PROCEDURE determineMileageAdjusted(p_item_type IN VARCHAR2,
12968 p_item_key IN VARCHAR2,
12969 p_actid IN NUMBER,
12970 p_funmode IN VARCHAR2,
12971 p_result OUT NOCOPY VARCHAR2) IS
12972 -------------------------------------------------------------------------------
12973 l_debug_info VARCHAR2(200);
12974 l_report_header_id AP_WEB_DB_EXPLINE_PKG.expLines_HeaderID;
12975 l_modified_count NUMBER :=0;
12976 l_new_count NUMBER :=0;
12977 l_mess Wf_Item_Attribute_Values.TEXT_VALUE%TYPE;
12978
12979 BEGIN
12980
12981 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start determineMileageAdjusted');
12982
12983 IF (p_funmode = 'RUN') THEN
12984
12985 ------------------------------------------------------------
12986 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
12987 ------------------------------------------------------------
12988 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
12989 p_item_key,
12990 'EXPENSE_REPORT_ID');
12991
12992
12993
12994 ------------------------------------------------------------
12995 l_debug_info := 'Construct Mileage Note';
12996 ------------------------------------------------------------
12997 SELECT count(*)
12998 INTO l_modified_count
12999 FROM ap_expense_report_lines xl
13000 WHERE xl.report_header_id = l_report_header_id
13001 AND xl.mileage_rate_adjusted_flag = AP_WEB_DB_EXPLINE_PKG.C_Modified;
13002
13003 /* If the system adjusted the mileage rate by adding new lines
13004 and changing the rate in the same report, the notes on the
13005 notification will only display the modified message. Only
13006 one notification will be send to the preparer and AP. */
13007 IF (l_modified_count > 0) THEN
13008 FND_MESSAGE.SET_NAME('SQLAP','OIE_WF_MRATE_MODIFIED_NOTE');
13009 ELSE
13010 SELECT count(*)
13011 INTO l_new_count
13012 FROM ap_expense_report_lines xl
13013 WHERE xl.report_header_id = l_report_header_id
13014 AND (xl.mileage_rate_adjusted_flag = AP_WEB_DB_EXPLINE_PKG.C_New
13015 OR xl.mileage_rate_adjusted_flag = AP_WEB_DB_EXPLINE_PKG.C_Split);
13016
13017 IF (l_new_count > 0 ) THEN
13018 FND_MESSAGE.SET_NAME('SQLAP','OIE_WF_MRATE_SPLIT_NOTE');
13019 END IF;
13020 END IF;
13021
13022 l_mess := FND_MESSAGE.GET;
13023
13024 WF_ENGINE.SetItemAttrText(p_item_type,
13025 p_item_key,
13026 'MILEAGE_NOTE',
13027 l_mess);
13028
13029 IF (l_modified_count > 0 OR l_new_count > 0 ) THEN
13030 p_result := 'COMPLETE:Y';
13031 ELSE
13032 p_result := 'COMPLETE:N';
13033 END IF;
13034
13035
13036 ELSIF (p_funmode = 'CANCEL') THEN
13037 p_result := 'COMPLETE';
13038 END IF;
13039
13040 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end determineMileageAdjusted');
13041
13042 EXCEPTION
13043 WHEN OTHERS THEN
13044 AP_WEB_DB_UTIL_PKG.RaiseException('determineMileageAdjusted');
13045 APP_EXCEPTION.RAISE_EXCEPTION;
13046 END determineMileageAdjusted;
13047
13048
13049
13050 ---------------------------------------------------------
13051 PROCEDURE getScheduleLineArray(
13052 p_report_header_id IN NUMBER,
13053 p_distribution_line_number IN NUMBER,
13054 p_employee_id IN NUMBER,
13055 p_cumulative_mileage IN NUMBER,
13056 p_schedule_line_array OUT NOCOPY AP_WEB_DB_SCHLINE_PKG.Schedule_Line_Array) IS
13057 ---------------------------------------------------------
13058 l_vehicle_category_code AP_WEB_DB_EXPLINE_PKG.expLines_vehicle_category_code;
13059 l_vehicle_type AP_WEB_DB_EXPLINE_PKG.expLines_vehicle_type;
13060 l_fuel_type AP_WEB_DB_EXPLINE_PKG.expLines_fuel_type;
13061 l_trip_distance AP_WEB_DB_EXPLINE_PKG.expLines_trip_distance;
13062 l_distance_unit_code AP_WEB_DB_EXPLINE_PKG.expLines_distance_unit_code;
13063 l_currency_code AP_WEB_DB_EXPLINE_PKG.expLines_currCode;
13064 l_start_expense_date AP_WEB_DB_EXPLINE_PKG.expLines_startExpDate;
13065 l_end_expense_date AP_WEB_DB_EXPLINE_PKG.expLines_endExpDate;
13066 l_web_parameter_iD AP_WEB_DB_EXPLINE_PKG.expLines_webParamID;
13067 l_policy_id AP_EXPENSE_REPORT_PARAMS.COMPANY_POLICY_ID%TYPE;
13068 l_distance_uom AP_POL_HEADERS.DISTANCE_UOM%TYPE;
13069 l_employee_role_flag AP_POL_HEADERS.EMPLOYEE_ROLE_FLAG%TYPE;
13070 l_distance_thresholds_flag AP_POL_HEADERS.DISTANCE_THRESHOLDS_FLAG%TYPE;
13071 l_debug_info VARCHAR2(200);
13072 l_cumulative_mileage AP_WEB_EMPLOYEE_INFO.NUMERIC_VALUE%TYPE := nvl(p_cumulative_mileage,0);
13073 l_currency_preference AP_POL_HEADERS.CURRENCY_PREFERENCE%TYPE;
13074 bDistanceWithinRange BOOLEAN := FALSE;
13075 bDistanceThresholdCrossed BOOLEAN := FALSE;
13076 bFoundSingleRate BOOLEAN := FALSE;
13077 l_schedule_line_array AP_WEB_DB_SCHLINE_PKG.Schedule_Line_Array;
13078 l_orig_cum_mileage AP_WEB_EMPLOYEE_INFO.VALUE_TYPE%TYPE;
13079 i NUMBER := 1;
13080 j NUMBER := 1;
13081 l_ou_distance_field AP_POL_CAT_OPTIONS.DISTANCE_FIELD%TYPE;
13082 l_threshold_tolerance NUMBER := 0;
13083
13084 c_schedule_line_cursor AP_WEB_DB_SCHLINE_PKG.ScheduleLinesCursor;
13085
13086 BEGIN
13087 --------------------------------------------------
13088 l_debug_info := 'Retrieving info from the Database';
13089 --------------------------------------------------
13090
13091 SELECT XL.VEHICLE_CATEGORY_CODE,
13092 XL.VEHICLE_TYPE,
13093 XL.FUEL_TYPE,
13094 nvl(XL.TRIP_DISTANCE,0),
13095 XL.DISTANCE_UNIT_CODE,
13096 XL.CURRENCY_CODE,
13097 XL.START_EXPENSE_DATE,
13098 XL.END_EXPENSE_DATE,
13099 XL.WEB_PARAMETER_ID,
13100 XP.COMPANY_POLICY_ID,
13101 SH.CURRENCY_PREFERENCE
13102 INTO l_vehicle_category_code,
13103 l_vehicle_type,
13104 l_fuel_type,
13105 l_trip_distance,
13106 l_distance_unit_code,
13107 l_currency_code,
13108 l_start_expense_date,
13109 l_end_expense_date,
13110 l_web_parameter_id,
13111 l_policy_id,
13112 l_currency_preference
13113 FROM ap_expense_report_lines XL,
13114 AP_EXPENSE_REPORT_HEADERS XH,
13115 AP_EXPENSE_REPORT_PARAMS XP,
13116 AP_POL_HEADERS SH
13117 WHERE XH.report_header_id = p_report_header_id
13118 AND XH.report_header_id = XL.report_header_id
13119 AND XL.distribution_line_number = p_distribution_line_number
13120 AND (XP.WEB_ENABLED_FLAG = 'Y'
13121 OR XH.EXPENSE_REPORT_ID = XP.EXPENSE_REPORT_ID)
13122 AND XL.web_parameter_id = XP.parameter_id
13123 AND XP.company_policy_id = SH.policy_id;
13124
13125 --------------------------------------------------
13126 l_debug_info := 'Retrieving info from the ap_pol_headers';
13127 --------------------------------------------------
13128 SELECT AH.DISTANCE_UOM,
13129 AH.DISTANCE_THRESHOLDS_FLAG,
13130 AH.EMPLOYEE_ROLE_FLAG
13131 INTO l_distance_uom,
13132 l_distance_thresholds_flag,
13133 l_employee_role_flag
13134 FROM AP_POL_HEADERS AH
13135 WHERE AH.POLICY_ID = l_policy_id;
13136
13137 IF (l_distance_thresholds_flag is not null) THEN
13138 IF ((l_distance_uom = C_KILOMETERS) AND (l_distance_unit_code = C_MILES)) THEN
13139 -- if l_distance_unit_code = C_MILES then
13140 l_trip_distance := l_trip_distance * MILES_TO_KILOMETERS;
13141 ELSIF ((l_distance_uom = C_MILES) AND (l_distance_unit_code = C_KILOMETERS)) THEN
13142 l_cumulative_mileage := round((l_cumulative_mileage * KILOMETERS_TO_MILES),1);
13143 l_trip_distance := l_trip_distance * KILOMETERS_TO_MILES;
13144 ELSIF ((l_distance_uom = C_SWMILES) AND (l_distance_unit_code = C_KILOMETERS)) THEN
13145 l_cumulative_mileage := round((l_cumulative_mileage * KILOMETERS_TO_SWMILES),1);
13146 l_trip_distance := l_trip_distance * KILOMETERS_TO_SWMILES;
13147 ELSIF ((l_distance_uom = C_SWMILES) AND (l_distance_unit_code = C_MILES)) THEN
13148 l_cumulative_mileage := round((l_cumulative_mileage * MILES_TO_SWMILES),1);
13149 l_trip_distance := l_trip_distance * MILES_TO_SWMILES;
13150 ELSIF ((l_distance_uom = C_KILOMETERS) AND (l_distance_unit_code = C_SWMILES)) then
13151 l_trip_distance := l_trip_distance * SWMILES_TO_KILOMETERS;
13152 ELSIF ((l_distance_uom = C_MILES) AND (l_distance_unit_code = C_SWMILES)) THEN
13153 l_cumulative_mileage := round((l_cumulative_mileage * SWMILES_TO_MILES),1);
13154 l_trip_distance := l_trip_distance * SWMILES_TO_MILES;
13155 ELSIF ((l_distance_uom = C_MILES) AND (l_distance_unit_code = C_MILES)) THEN
13156 l_cumulative_mileage := round((l_cumulative_mileage * KILOMETERS_TO_MILES),1);
13157 ELSIF ((l_distance_uom = C_SWMILES) AND (l_distance_unit_code = C_SWMILES)) THEN
13158 l_cumulative_mileage := round((l_cumulative_mileage * KILOMETERS_TO_SWMILES),1);
13159 -- END IF;
13160 END IF;
13161 END IF;
13162
13163
13164 --------------------------------------------------
13165 l_debug_info := 'Retrieving schedule line from the ap_pol_lines';
13166 --------------------------------------------------
13167 l_orig_cum_mileage := l_cumulative_mileage;
13168 l_cumulative_mileage := l_cumulative_mileage + l_trip_distance;
13169
13170 IF ( AP_WEB_DB_SCHLINE_PKG.GetScheduleLinesCursor(l_policy_id,
13171 l_vehicle_category_code,
13172 l_vehicle_type,
13173 l_fuel_type,
13174 l_currency_code,
13175 p_employee_id,
13176 l_start_expense_date,
13177 c_schedule_line_cursor)) THEN
13178
13179 LOOP
13180 FETCH c_schedule_line_cursor INTO
13181 l_schedule_line_array(i).range_high,
13182 l_schedule_line_array(i).range_low,
13183 l_schedule_line_array(i).start_date,
13184 l_schedule_line_array(i).end_date,
13185 l_schedule_line_array(i).rate,
13186 l_schedule_line_array(i).rate_per_passenger;
13187 EXIT WHEN c_schedule_line_cursor%NOTFOUND;
13188
13189 --------------------------------------------------
13190 l_debug_info := 'Determine whether distance threshold crossed';
13191 --------------------------------------------------
13192 -- Bug 8813146 - Threshold tolerance is used when daily_distance is used or distance_uom's used are different
13193 Begin
13194 SELECT DISTANCE_FIELD
13195 INTO l_ou_distance_field
13196 FROM AP_POL_CAT_OPTIONS
13197 WHERE category_code = 'MILEAGE';
13198 exception
13199 when no_data_found then
13200 l_ou_distance_field := C_DISTANCE_FIELD;
13201 end;
13202
13203 IF ( C_DISTANCE_FIELD = l_ou_distance_field OR l_distance_unit_code <> l_distance_uom) THEN
13204 IF (l_distance_unit_code <> C_KILOMETERS) THEN
13205 l_threshold_tolerance := C_THRESHOLD_TOLERANCE;
13206 END IF;
13207 END IF;
13208
13209 IF (l_distance_thresholds_flag is not null) THEN
13210 IF (l_cumulative_mileage > l_schedule_line_array(i).range_low AND l_orig_cum_mileage <
13211 nvl(l_schedule_line_array(i).range_high,l_orig_cum_mileage + 1)) THEN
13212 IF (l_cumulative_mileage > nvl(l_schedule_line_array(i).range_high + l_threshold_tolerance, l_cumulative_mileage)) THEN
13213 bDistanceThresholdCrossed := TRUE;
13214 ELSE
13215 bDistanceThresholdCrossed := FALSE;
13216 END IF;
13217
13218 p_schedule_line_array(j) := l_schedule_line_array(i);
13219 IF (bDistanceThresholdCrossed = FALSE) THEN
13220 EXIT;
13221 END IF;
13222
13223 j := j+1;
13224 END IF;
13225 END IF;
13226
13227
13228 i := i+1;
13229 END LOOP;
13230
13231 END IF;
13232
13233 EXCEPTION
13234 WHEN OTHERS THEN
13235 AP_WEB_DB_UTIL_PKG.RaiseException('getScheduleLineArray',
13236 l_debug_info);
13237 APP_EXCEPTION.RAISE_EXCEPTION;
13238 END getScheduleLineArray;
13239
13240
13241 -------------------------------------------------------------------------------
13242 PROCEDURE updateCumulativeMileage(
13243 p_cumulative_mileage IN AP_WEB_EMPLOYEE_INFO.NUMERIC_VALUE%TYPE,
13244 p_period_id IN AP_WEB_EMPLOYEE_INFO.PERIOD_ID%TYPE,
13245 p_employee_id IN AP_WEB_EMPLOYEE_INFO.EMPLOYEE_ID%TYPE) IS
13246 -------------------------------------------------------------------------------
13247 l_count NUMBER := 0;
13248 BEGIN
13249
13250 SELECT count(*)
13251 INTO l_count
13252 FROM ap_web_employee_info_all
13253 WHERE value_type = 'CUM_REIMB_DISTANCE'
13254 AND period_id = p_period_id
13255 AND employee_id = p_employee_id;
13256
13257 IF (l_count > 0 ) THEN
13258 UPDATE ap_web_employee_info_all
13259 SET numeric_value = p_cumulative_mileage,
13260 last_update_date = sysdate,
13261 last_updated_by = p_employee_id
13262 WHERE value_type = 'CUM_REIMB_DISTANCE'
13263 AND period_id = p_period_id
13264 AND employee_id = p_employee_id;
13265 ELSE
13266 INSERT INTO ap_web_employee_info_all
13267 (EMPLOYEE_ID,
13268 VALUE_TYPE,
13269 NUMERIC_VALUE,
13270 PERIOD_ID,
13271 CREATION_DATE,
13272 CREATED_BY,
13273 LAST_UPDATE_DATE,
13274 LAST_UPDATED_BY,
13275 ORG_ID)
13276 VALUES(p_employee_id,
13277 'CUM_REIMB_DISTANCE',
13278 p_cumulative_mileage,
13279 p_period_id,
13280 sysdate,
13281 p_employee_id,
13282 sysdate,
13283 p_employee_id,
13284 mo_global.get_current_org_id() );
13285 END IF;
13286
13287 EXCEPTION
13288 WHEN OTHERS THEN
13289 AP_WEB_DB_UTIL_PKG.RaiseException('updateCumulativeMileage');
13290 APP_EXCEPTION.RAISE_EXCEPTION;
13291 END updateCumulativeMileage;
13292
13293
13294 FUNCTION getAddonMileageRatesSum(p_report_header_id IN NUMBER,
13295 p_dist_line_number IN NUMBER)
13296 RETURN NUMBER IS
13297 l_addon_rate_sum NUMBER := 0.0;
13298 BEGIN
13299 -- Bug: 7330731, Null returned from here causes invalid splits
13300 select nvl(sum(mileage_rate),0)
13301 into l_addon_rate_sum
13302 from oie_addon_mileage_rates
13303 where report_line_id = (select report_line_id
13304 from ap_expense_report_lines
13305 where report_header_id = p_report_header_id
13306 and distribution_line_number = p_dist_line_number
13307 and rownum = 1);
13308 return l_addon_rate_sum;
13309 EXCEPTION when others then
13310 return l_addon_rate_sum;
13311 END getAddonMileageRatesSum;
13312
13313 -------------------------------------------------------------------------------
13314 FUNCTION getRate(
13315 p_sh_distance_uom IN AP_POL_HEADERS.distance_uom%TYPE,
13316 p_sh_currency_code IN AP_POL_HEADERS.currency_code%TYPE,
13317 p_mileage_line IN AP_WEB_DB_EXPLINE_PKG.Mileage_Line_Rec,
13318 p_schedule_line IN AP_WEB_DB_SCHLINE_PKG.Schedule_Line_Rec)
13319 RETURN NUMBER IS
13320 -------------------------------------------------------------------------------
13321 l_debug_info VARCHAR2(200);
13322 l_conversion_type VARCHAR2(30);
13323 l_converted_amount NUMBER := 1;
13324 l_denominator NUMBER := 1;
13325 l_numerator NUMBER := 1;
13326 l_rate NUMBER;
13327 l_calc_rate NUMBER;
13328
13329 l_get_ap_system_params boolean;
13330 l_base_curr_code AP_WEB_DB_AP_INT_PKG.apSetup_baseCurrencyCode;
13331 l_set_of_books_id AP_WEB_DB_AP_INT_PKG.apSetup_setOfBooksID;
13332 l_expense_report_id AP_WEB_DB_AP_INT_PKG.apSetup_expenseReportID;
13333
13334 BEGIN
13335
13336 -- Bug 13581067 - Rate Per Passenger Calcluation and Addon Rates included.
13337 l_calc_rate := p_schedule_line.rate + nvl((p_schedule_line.rate_per_passenger * p_mileage_line.number_people),0)
13338 + getAddonMileageRatesSum(p_mileage_line.report_header_id,p_mileage_line.orig_dist_line_number );
13339
13340 -- Need to convert to reimbursement currency if different
13341 IF (p_sh_currency_code <> p_mileage_line.reimbursement_currency_code) THEN
13342
13343 ------------------------------------------------------
13344 l_debug_info := 'Get the rate type';
13345 ------------------------------------------------------
13346 /*l_get_ap_system_params := AP_WEB_DB_AP_INT_PKG.get_ap_system_params(
13347 p_base_curr_code => l_base_curr_code,
13348 p_set_of_books_id => l_set_of_books_id,
13349 p_expense_report_id => l_expense_report_id,
13350 p_default_exch_rate_type => l_conversion_type);*/
13351
13352 AP_WEB_DB_AP_INT_PKG.GetDefaultExchange(p_default_exchange_rate_type => l_conversion_type);
13353
13354 gl_currency_api.convert_closest_amount(
13355 x_from_currency => p_sh_currency_code,
13356 x_to_currency => p_mileage_line.reimbursement_currency_code,
13357 x_conversion_date => p_mileage_line.start_date,
13358 x_conversion_type => l_conversion_type,
13359 x_user_rate => 1,
13360 x_amount => 1,
13361 x_max_roll_days => 0,
13362 x_converted_amount=> l_converted_amount,
13363 x_denominator => l_denominator,
13364 x_numerator => l_numerator,
13365 x_rate => l_rate);
13366 l_rate := l_calc_rate * l_rate;
13367 ELSE
13368 l_rate := l_calc_rate;
13369 END IF;
13370
13371 ------------------------------------------------------
13372 l_debug_info := 'Convert rate to the corresponding UOM';
13373 ------------------------------------------------------
13374 IF (p_sh_distance_uom <> p_mileage_line.distance_unit_code) THEN
13375
13376 IF ((p_sh_distance_uom = C_KILOMETERS) AND (p_mileage_line.distance_unit_code = C_MILES)) THEN
13377 l_rate := round( l_rate * MILES_TO_KILOMETERS, 6);
13378 ELSIF ((p_sh_distance_uom = C_MILES) AND (p_mileage_line.distance_unit_code = C_KILOMETERS)) THEN
13379 l_rate := round( l_rate * KILOMETERS_TO_MILES, 6);
13380 ELSIF ((p_sh_distance_uom = C_SWMILES) AND (p_mileage_line.distance_unit_code = C_KILOMETERS)) THEN
13381 l_rate := round( l_rate * KILOMETERS_TO_SWMILES, 6);
13382 ELSIF ((p_sh_distance_uom = C_SWMILES) AND (p_mileage_line.distance_unit_code = C_MILES)) THEN
13383 l_rate := round( l_rate * MILES_TO_SWMILES, 6);
13384 ELSIF ((p_sh_distance_uom = C_MILES) AND (p_mileage_line.distance_unit_code = C_SWMILES)) THEN
13385 l_rate := round( l_rate * SWMILES_TO_MILES, 6);
13386 ELSIF ((p_sh_distance_uom = C_KILOMETERS) AND (p_mileage_line.distance_unit_code = C_SWMILES)) THEN
13387 l_rate := round( l_rate * SWMILES_TO_KILOMETERS, 6);
13388
13389 END IF;
13390
13391 END IF;
13392
13393 return l_rate;
13394
13395 EXCEPTION
13396 WHEN NO_DATA_FOUND THEN
13397 return 0;
13398 WHEN OTHERS THEN
13399 AP_WEB_DB_UTIL_PKG.RaiseException('getRate');
13400 APP_EXCEPTION.RAISE_EXCEPTION;
13401 return 0;
13402 END getRate;
13403
13404
13405 -------------------------------------------------------------------------------
13406 PROCEDURE copyMileageArray(
13407 p_from_array IN AP_WEB_DB_EXPLINE_PKG.Mileage_Line_Array,
13408 p_to_array OUT NOCOPY AP_WEB_DB_EXPLINE_PKG.Mileage_Line_Array) IS
13409 -------------------------------------------------------------------------------
13410 l_debug_info VARCHAR2(200);
13411
13412 BEGIN
13413 -- Start w/ defaulting the orig_dist_line_number to new_orig_dist_line_number
13414 FOR i IN 1..p_from_array.COUNT LOOP
13415 p_to_array(i).orig_dist_line_number := p_from_array(i).orig_dist_line_number;
13416 p_to_array(i).new_dist_line_number := p_from_array(i).orig_dist_line_number;
13417 p_to_array(i).report_header_id := p_from_array(i).report_header_id;
13418 p_to_array(i).start_date := p_from_array(i).start_date;
13419 p_to_array(i).end_date := p_from_array(i).end_date;
13420 p_to_array(i).number_of_days := p_from_array(i).number_of_days;
13421 p_to_array(i).policy_id := p_from_array(i).policy_id;
13422 p_to_array(i).avg_mileage_rate := p_from_array(i).avg_mileage_rate;
13423 p_to_array(i).trip_distance := p_from_array(i).trip_distance;
13424 p_to_array(i).daily_distance := p_from_array(i).daily_distance;
13425 p_to_array(i).distance_unit_code := p_from_array(i).distance_unit_code;
13426 p_to_array(i).amount := p_from_array(i).amount;
13427
13428 END LOOP;
13429
13430
13431 EXCEPTION
13432 WHEN OTHERS THEN
13433 AP_WEB_DB_UTIL_PKG.RaiseException('copyMileageArray');
13434 APP_EXCEPTION.RAISE_EXCEPTION;
13435 END copyMileageArray;
13436
13437
13438 -------------------------------------------------------------------------------
13439 PROCEDURE addToMileageArray(
13440 p_index IN NUMBER,
13441 p_new_dist_number IN AP_EXPENSE_REPORT_LINES.distribution_line_number%TYPE,
13442 p_trip_dist IN AP_EXPENSE_REPORT_LINES.TRIP_DISTANCE%TYPE,
13443 p_daily_distance IN AP_EXPENSE_REPORT_LINES.DAILY_DISTANCE%TYPE,
13444 p_rate IN AP_EXPENSE_REPORT_LINES.avg_mileage_rate%TYPE,
13445 p_report_header_id IN AP_EXPENSE_REPORT_LINES.report_header_id%TYPE,
13446 p_from_index IN AP_EXPENSE_REPORT_LINES.distribution_line_number%TYPE,
13447 p_mileage_line_array IN OUT NOCOPY AP_WEB_DB_EXPLINE_PKG.Mileage_Line_Array) IS
13448 -------------------------------------------------------------------------------
13449 l_debug_info VARCHAR2(200);
13450
13451 BEGIN
13452
13453 p_mileage_line_array(p_index).orig_dist_line_number := p_new_dist_number;
13454 p_mileage_line_array(p_index).new_dist_line_number := p_new_dist_number;
13455 p_mileage_line_array(p_index).report_header_id := p_report_header_id;
13456 p_mileage_line_array(p_index).start_date := p_mileage_line_array(p_from_index).start_date;
13457 p_mileage_line_array(p_index).end_date := p_mileage_line_array(p_from_index).end_date;
13458 p_mileage_line_array(p_index).number_of_days := p_mileage_line_array(p_from_index).number_of_days;
13459 p_mileage_line_array(p_index).policy_id := p_mileage_line_array(p_from_index).policy_id;
13460 p_mileage_line_array(p_index).avg_mileage_rate := p_rate;
13461 p_mileage_line_array(p_index).trip_distance := p_trip_dist;
13462 p_mileage_line_array(p_index).daily_distance := p_daily_distance;
13463 p_mileage_line_array(p_index).distance_unit_code := p_mileage_line_array(p_from_index).distance_unit_code;
13464 p_mileage_line_array(p_index).amount := p_rate * p_trip_dist;
13465 p_mileage_line_array(p_index).daily_amount := p_rate * p_trip_dist / p_mileage_line_array(p_from_index).number_of_days;
13466 p_mileage_line_array(p_index).copy_From := p_mileage_line_array(p_from_index).orig_dist_line_number;
13467 p_mileage_line_array(p_index).status := AP_WEB_DB_EXPLINE_PKG.C_New;
13468
13469 EXCEPTION
13470 WHEN OTHERS THEN
13471 AP_WEB_DB_UTIL_PKG.RaiseException('addToMileageArray');
13472 APP_EXCEPTION.RAISE_EXCEPTION;
13473 END addToMileageArray;
13474
13475 -------------------------------------------------------------------------------
13476 PROCEDURE updateNewDistNumber(
13477 p_index IN NUMBER,
13478 p_last_index IN NUMBER,
13479 p_added_total IN NUMBER,
13480 p_mileage_line_array IN OUT NOCOPY AP_WEB_DB_EXPLINE_PKG.Mileage_Line_Array)IS
13481 -------------------------------------------------------------------------------
13482 l_debug_info VARCHAR2(200);
13483 i NUMBER;
13484 BEGIN
13485
13486 If (p_last_index > p_index) THEN
13487 FOR i IN p_index..p_last_index LOOP
13488 p_mileage_line_array(i).new_dist_line_number :=
13489 p_mileage_line_array(i).new_dist_line_number + p_added_total;
13490
13491 -- Only the status of existing lines will be updated to M(odifed)
13492 -- All new lines will keep the N(ew) status to ensure they will
13493 -- be added to the database later.
13494
13495 IF (p_mileage_line_array(i).status <> 'N') THEN
13496 p_mileage_line_array(i).status := 'M';
13497 END IF;
13498 END LOOP;
13499
13500 END IF;
13501
13502 EXCEPTION
13503 WHEN OTHERS THEN
13504 AP_WEB_DB_UTIL_PKG.RaiseException('updateNewDistNumber');
13505 APP_EXCEPTION.RAISE_EXCEPTION;
13506 END updateNewDistNumber;
13507
13508 --------------------------------------------------------------------------------
13509 PROCEDURE processCrossThreshold(
13510 p_ml_index IN NUMBER,
13511 p_sh_distance_uom IN AP_POL_HEADERS.DISTANCE_UOM%TYPE,
13512 p_sh_currency_code IN AP_POL_HEADERS.CURRENCY_CODE%TYPE,
13513 p_schedule_line_array IN AP_WEB_DB_SCHLINE_PKG.Schedule_Line_Array,
13514 p_mileage_line_array_count IN OUT NOCOPY NUMBER,
13515 p_cumulative_mileage IN OUT NOCOPY AP_WEB_EMPLOYEE_INFO.NUMERIC_VALUE%TYPE,
13516 p_mileage_line_array IN OUT NOCOPY AP_WEB_DB_EXPLINE_PKG.Mileage_Line_Array)IS
13517 --------------------------------------------------------------------------------
13518 l_cumulative_mileage NUMBER := p_cumulative_mileage;
13519 l_ml_trip_distance NUMBER := p_mileage_line_array(p_ml_index).trip_distance;
13520 l_over_amount NUMBER;
13521 l_cum_distance NUMBER;
13522 l_over_threshold_distance NUMBER := 0;
13523 l_range_high NUMBER;
13524 l_range_low NUMBER;
13525 l_next_dist_number NUMBER;
13526 l_range_size NUMBER;
13527 l_daily_distance NUMBER;
13528 l_updated_trip_dist NUMBER;
13529 l_new_rate NUMBER := 0;
13530 l_insert_index NUMBER := p_mileage_line_array_count + 1;
13531 l_added_total NUMBER := 0;
13532 l_sl_array_count NUMBER := 0;
13533 l_debug_info VARCHAR2(200);
13534 l_ou_distance_field AP_POL_CAT_OPTIONS.DISTANCE_FIELD%TYPE;
13535 l_threshold_tolerance NUMBER := 0;
13536
13537
13538 BEGIN
13539
13540 ------------------------------------------------------
13541 l_debug_info := 'Convert to the appropriate UOM';
13542 ------------------------------------------------------
13543
13544 IF (p_mileage_line_array(p_ml_index).distance_unit_code = C_MILES) THEN
13545 l_cum_distance := round(((l_cumulative_mileage * KILOMETERS_TO_MILES) + p_mileage_line_array(p_ml_index).trip_distance), 1);
13546 ELSIF (p_mileage_line_array(p_ml_index).distance_unit_code = C_SWMILES) THEN
13547 l_cum_distance := round(((l_cumulative_mileage * KILOMETERS_TO_SWMILES) + p_mileage_line_array(p_ml_index).trip_distance), 1);
13548 ELSE
13549 l_cum_distance := l_cumulative_mileage + p_mileage_line_array(p_ml_index).trip_distance;
13550 END IF;
13551
13552 --------------------------------------------
13553 l_debug_info := 'assign p_cumulative_mileage';
13554 --------------------------------------------
13555 IF (p_mileage_line_array(p_ml_index).distance_unit_code = C_MILES) THEN
13556 p_cumulative_mileage := round((l_cum_distance * MILES_TO_KILOMETERS),1);
13557 ELSIF (p_mileage_line_array(p_ml_index).distance_unit_code = C_SWMILES) THEN
13558 p_cumulative_mileage := round((l_cum_distance * SWMILES_TO_KILOMETERS),1);
13559 ELSE
13560 p_cumulative_mileage := l_cum_distance;
13561 END IF;
13562
13563 l_sl_array_count := p_schedule_line_array.COUNT;
13564
13565 FOR i IN 1..l_sl_array_count LOOP
13566 l_range_high := p_schedule_line_array(i).range_high;
13567 l_range_low := p_schedule_line_array(i).range_low;
13568
13569 IF ((p_mileage_line_array(p_ml_index).distance_unit_code = C_MILES) AND (p_sh_distance_uom = C_KILOMETERS)) THEN
13570 l_range_high := p_schedule_line_array(i).range_high * KILOMETERS_TO_MILES;
13571 l_range_low := p_schedule_line_array(i).range_low * KILOMETERS_TO_MILES;
13572 ELSIF ((p_mileage_line_array(p_ml_index).distance_unit_code = C_KILOMETERS) AND (p_sh_distance_uom = C_MILES)) THEN
13573 l_range_high := p_schedule_line_array(i).range_high * MILES_TO_KILOMETERS;
13574 l_range_low := p_schedule_line_array(i).range_low * MILES_TO_KILOMETERS;
13575 ELSIF ((p_mileage_line_array(p_ml_index).distance_unit_code = C_KILOMETERS) AND (p_sh_distance_uom = C_SWMILES)) THEN
13576 l_range_high := p_schedule_line_array(i).range_high * SWMILES_TO_KILOMETERS;
13577 l_range_low := p_schedule_line_array(i).range_low * SWMILES_TO_KILOMETERS;
13578 ELSIF ((p_mileage_line_array(p_ml_index).distance_unit_code = C_MILES) AND (p_sh_distance_uom = C_SWMILES)) THEN
13579 l_range_high := p_schedule_line_array(i).range_high * SWMILES_TO_MILES;
13580 l_range_low := p_schedule_line_array(i).range_low * SWMILES_TO_MILES;
13581 ELSIF ((p_mileage_line_array(p_ml_index).distance_unit_code = C_SWMILES) AND (p_sh_distance_uom = C_MILES)) THEN
13582 l_range_high := p_schedule_line_array(i).range_high * MILES_TO_SWMILES;
13583 l_range_low := p_schedule_line_array(i).range_low * MILES_TO_SWMILES;
13584 ELSIF ((p_mileage_line_array(p_ml_index).distance_unit_code = C_SWMILES) AND (p_sh_distance_uom = C_KILOMETERS)) THEN
13585 l_range_high := p_schedule_line_array(i).range_high * KILOMETERS_TO_SWMILES;
13586 l_range_low := p_schedule_line_array(i).range_low * KILOMETERS_TO_SWMILES;
13587 END IF;
13588
13589 -- Bug 8813146 - Threshold tolerance is used when daily_distance is used or distance_uom's used are different
13590 Begin
13591 SELECT DISTANCE_FIELD
13592 INTO l_ou_distance_field
13593 FROM AP_POL_CAT_OPTIONS
13594 WHERE category_code = 'MILEAGE';
13595 exception
13596 when no_data_found then
13597 l_ou_distance_field := C_DISTANCE_FIELD;
13598 end;
13599
13600 IF ( C_DISTANCE_FIELD = l_ou_distance_field OR p_mileage_line_array(p_ml_index).distance_unit_code <> p_sh_distance_uom) THEN
13601 IF (p_mileage_line_array(p_ml_index).distance_unit_code <> C_KILOMETERS) THEN
13602 l_threshold_tolerance := C_THRESHOLD_TOLERANCE;
13603 END IF;
13604 END IF;
13605
13606 IF (i = 1) THEN
13607 -------------------------------------------
13608 l_debug_info := 'is distance within range';
13609 -------------------------------------------
13610 l_over_threshold_distance := l_cum_distance - nvl(l_range_high, l_cum_distance);
13611
13612 --Bug 5844609
13613 --Line shouldn't be split if over threshold distance is greater than or equal to trip distance.
13614
13615 IF (round(l_over_threshold_distance) <= 0 OR
13616 (round(p_mileage_line_array(p_ml_index).trip_distance - l_over_threshold_distance)) <= 0) THEN
13617
13618 RETURN;
13619
13620 END IF;
13621
13622 IF (l_over_threshold_distance > l_threshold_tolerance) THEN
13623
13624 IF (round(p_mileage_line_array(p_ml_index).trip_distance -
13625 l_over_threshold_distance)) > 0 THEN
13626
13627 p_mileage_line_array(p_ml_index).trip_distance :=
13628 (round(p_mileage_line_array(p_ml_index).trip_distance -
13629 l_over_threshold_distance));
13630 END IF;
13631
13632 p_mileage_line_array(p_ml_index).daily_distance :=
13633 round(p_mileage_line_array(p_ml_index).trip_distance /
13634 p_mileage_line_array(p_ml_index).number_of_days);
13635
13636 ELSE
13637
13638 p_mileage_line_array(p_ml_index).daily_distance :=
13639 round(p_mileage_line_array(p_ml_index).trip_distance /
13640 p_mileage_line_array(p_ml_index).number_of_days);
13641
13642 END IF;
13643 -------------------------------------------
13644 l_debug_info := 'Modify the original line';
13645 -------------------------------------------
13646 l_new_rate := getRate(
13647 p_sh_distance_uom => p_sh_distance_uom,
13648 p_sh_currency_code => p_sh_currency_code,
13649 p_mileage_line => p_mileage_line_array(p_ml_index),
13650 p_schedule_line => p_schedule_line_array(1));
13651
13652 p_mileage_line_array(p_ml_index).avg_mileage_rate := l_new_rate;
13653 p_mileage_line_array(p_ml_index).amount :=
13654 l_new_rate * p_mileage_line_array(p_ml_index).trip_distance;
13655 p_mileage_line_array(p_ml_index).receipt_currency_amount :=
13656 p_mileage_line_array(p_ml_index).amount;
13657 p_mileage_line_array(p_ml_index).daily_amount :=
13658 l_new_rate * p_mileage_line_array(p_ml_index).trip_distance / p_mileage_line_array(p_ml_index).number_of_days;
13659 p_mileage_line_array(p_ml_index).new_dist_line_number :=
13660 p_mileage_line_array(p_ml_index).orig_dist_line_number;
13661 p_mileage_line_array(p_ml_index).status := AP_WEB_DB_EXPLINE_PKG.C_Split;
13662
13663 l_over_threshold_distance := l_cum_distance - nvl(l_range_high, l_cum_distance);
13664
13665 ELSE
13666
13667 /* When a threshold is crossed, the original line will be modified. At
13668 the same time, the system will add new lines to the lines table.
13669 The first row of the scheduleLineArray is used to modified the
13670 original line. We will need to loop through the rest of the array
13671 to decide how many new rows will be added. */
13672
13673 IF (l_over_threshold_distance > l_threshold_tolerance ) THEN
13674
13675 --------------------------------------------
13676 l_debug_info := 'Creat a new receipt line';
13677 --------------------------------------------
13678
13679 SELECT max(distribution_line_number) + 1
13680 INTO l_next_dist_number
13681 FROM AP_EXPENSE_REPORT_LINES
13682 WHERE report_header_id = p_mileage_line_array(p_ml_index).report_header_id;
13683
13684 --------------------------------------------
13685 l_debug_info := 'Find the trip distance';
13686 --------------------------------------------
13687 IF (l_over_threshold_distance >= l_range_high - l_range_low) THEN
13688 l_updated_trip_dist := l_range_high - l_range_low;
13689 else
13690 l_updated_trip_dist := l_over_threshold_distance;
13691 end if;
13692
13693 l_daily_distance := l_updated_trip_dist / p_mileage_line_array(p_ml_index).number_of_days;
13694
13695 /* The rate from the schedule line array is the rate stored in
13696 ap_pol_headers. The unit of measure will be according to
13697 ap_pol_headers. However, when calculating the rate for the
13698 lines, we need to get convert the rate according to the UOM
13699 in ap_expense_report_lines. -Akita */
13700 l_new_rate := getRate(
13701 p_sh_distance_uom => p_sh_distance_uom,
13702 p_sh_currency_code => p_sh_currency_code,
13703 p_mileage_line => p_mileage_line_array(p_ml_index),
13704 p_schedule_line => p_schedule_line_array(i));
13705
13706 addToMileageArray(l_insert_index,
13707 l_next_dist_number,
13708 round(l_updated_trip_dist),
13709 round(l_daily_distance),
13710 l_new_rate,
13711 p_mileage_line_array(p_ml_index).report_header_id,
13712 p_ml_index,
13713 p_mileage_line_array);
13714
13715 p_mileage_line_array_count := l_insert_index ;
13716
13717 l_added_total := l_added_total + 1;
13718
13719 l_over_threshold_distance := l_cum_distance - nvl(l_range_high, l_cum_distance);
13720 END IF; -- l_over_threshold_distance > 0
13721
13722 END IF; -- i = 1
13723
13724 END LOOP;
13725
13726 --------------------------------------------
13727 l_debug_info := 'Reorder l_mileage_array';
13728 --------------------------------------------
13729 /* Using the original count of the array to ensure the new distribution
13730 number assigned to the new rows will not be modified again in
13731 updateNewDistNumber. -Akita */
13732 updateNewDistNumber(p_ml_index + 1,
13733 l_sl_array_count,
13734 l_added_total,
13735 p_mileage_line_array);
13736
13737
13738 EXCEPTION
13739 WHEN NO_DATA_FOUND THEN
13740 AP_WEB_DB_UTIL_PKG.RaiseException('No Data found: processCrossThreshold');
13741 APP_EXCEPTION.RAISE_EXCEPTION;
13742 WHEN OTHERS THEN
13743 AP_WEB_DB_UTIL_PKG.RaiseException('processCrossThreshold');
13744 APP_EXCEPTION.RAISE_EXCEPTION;
13745 END processCrossThreshold;
13746
13747 -------------------------------------------------------------------------------
13748 PROCEDURE ProcessMileageLines(p_item_type IN VARCHAR2,
13749 p_item_key IN VARCHAR2,
13750 p_actid IN NUMBER,
13751 p_funmode IN VARCHAR2,
13752 p_result OUT NOCOPY VARCHAR2) IS
13753 -------------------------------------------------------------------------------
13754 l_report_header_id AP_WEB_DB_EXPLINE_PKG.expLines_headerID;
13755 l_ml_start_date DATE;
13756 l_ml_end_date DATE;
13757 l_ml_numberOfDays NUMBER;
13758 l_ml_distribution_line_number AP_WEB_DB_EXPLINE_PKG.expLines_distLineNum;
13759 l_ml_policy_id AP_POL_HEADERS.policy_id%TYPE;
13760 l_cumulative_mileage AP_WEB_EMPLOYEE_INFO.NUMERIC_VALUE%TYPE;
13761 l_period_id AP_WEB_EMPLOYEE_INFO.PERIOD_ID%TYPE;
13762 l_debug_info VARCHAR2(200);
13763 C_WF_VERSION NUMBER := 0;
13764 l_new_rate NUMBER := 0;
13765 l_ml_avg_mileage_rate AP_WEB_DB_EXPLINE_PKG.expLines_avg_mileage_rate;
13766 l_ml_distance_unit_code AP_WEB_DB_EXPLINE_PKG.expLines_distance_unit_code;
13767 l_ml_trip_distance AP_WEB_DB_EXPLINE_PKG.expLines_trip_distance;
13768 c_expense_lines_cursor AP_WEB_DB_EXPLINE_PKG.ExpLinesCursor;
13769 l_employee_id NUMBER;
13770 l_schedule_line_array AP_WEB_DB_SCHLINE_PKG.Schedule_Line_Array;
13771 l_temp NUMBER;
13772 l_sh_distance_uom AP_POL_HEADERS.distance_uom%TYPE;
13773 l_sh_currency_code AP_POL_HEADERS.currency_code%TYPE;
13774 l_index NUMBER := 0;
13775 l_lines_created NUMBER := 0;
13776 l_temp_mileage_line_array AP_WEB_DB_EXPLINE_PKG.Mileage_Line_Array;
13777 l_mileage_line_array AP_WEB_DB_EXPLINE_PKG.Mileage_Line_Array;
13778 l_mileage_array_count NUMBER;
13779 i NUMBER;
13780 j NUMBER := 1;
13781 l_orig_distance_travel NUMBER;
13782 l_rate NUMBER;
13783
13784 l_base_precision NUMBER;
13785 l_ext_precision NUMBER;
13786 l_base_min_acct_unit NUMBER;
13787 l_total NUMBER;
13788 l_total_dsp VARCHAR2(50);
13789 l_bHeaderUpdated BOOLEAN := FALSE;
13790 l_reimb_curr AP_WEB_DB_EXPRPT_PKG.expHdr_payemntCurrCode;
13791 l_over_threshold_distance NUMBER := 0;
13792 l_sh_distance_thresholds_flag VARCHAR2(1);
13793
13794 l_report_header_info AP_WEB_DFLEX_PKG.ExpReportHeaderRec;
13795 l_custom_array AP_WEB_DFLEX_PKG.CustomFields_A;
13796 l_mileage_line AP_WEB_DFLEX_PKG.ExpReportLineRec;
13797 l_addon_rates OIE_ADDON_RATES_T;
13798 Custom1_Array AP_WEB_DFLEX_PKG.CustomFields_A;
13799 Custom2_Array AP_WEB_DFLEX_PKG.CustomFields_A;
13800 Custom3_Array AP_WEB_DFLEX_PKG.CustomFields_A;
13801 Custom4_Array AP_WEB_DFLEX_PKG.CustomFields_A;
13802 Custom5_Array AP_WEB_DFLEX_PKG.CustomFields_A;
13803 Custom6_Array AP_WEB_DFLEX_PKG.CustomFields_A;
13804 Custom7_Array AP_WEB_DFLEX_PKG.CustomFields_A;
13805 Custom8_Array AP_WEB_DFLEX_PKG.CustomFields_A;
13806 Custom9_Array AP_WEB_DFLEX_PKG.CustomFields_A;
13807 Custom10_Array AP_WEB_DFLEX_PKG.CustomFields_A;
13808 Custom11_Array AP_WEB_DFLEX_PKG.CustomFields_A;
13809 Custom12_Array AP_WEB_DFLEX_PKG.CustomFields_A;
13810 Custom13_Array AP_WEB_DFLEX_PKG.CustomFields_A;
13811 Custom14_Array AP_WEB_DFLEX_PKG.CustomFields_A;
13812 Custom15_Array AP_WEB_DFLEX_PKG.CustomFields_A;
13813 k number;
13814 cursor getAddonRates(l_report_line_id NUMBER) is select addon_rate_type
13815 from oie_addon_mileage_rates
13816 where report_line_id = l_report_line_id;
13817 l_client_extension_enabled VARCHAR2(1);
13818 l_temp_array OIE_PDM_NUMBER_T; -- bug 5358186
13819 BEGIN
13820
13821 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start ProcessMileageLines');
13822
13823 -----------------------------------------------------
13824 l_debug_info := 'Get Workflow Version Number 5';
13825 -----------------------------------------------------
13826 C_WF_Version := AP_WEB_EXPENSE_WF.GetFlowVersion(p_item_type, p_item_key);
13827
13828 ------------------------------------------------------------
13829 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
13830 ------------------------------------------------------------
13831 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
13832 p_item_key,
13833 'EXPENSE_REPORT_ID');
13834 -------------------------------------------------------
13835 l_debug_info := 'Retrieve Employee_ID Item Attribute';
13836 -------------------------------------------------------
13837 l_employee_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
13838 p_item_key,
13839 'EMPLOYEE_ID');
13840
13841
13842 --------------------------------------------
13843 l_debug_info := 'Open Expense Lines Cursor';
13844 --------------------------------------------
13845 IF (AP_WEB_DB_EXPLINE_PKG.GetExpMileageLinesCursor(l_report_header_id, c_expense_lines_cursor)) THEN
13846
13847 LOOP
13848 --------------------------------------------
13849 l_debug_info := 'Fetch Mileage Lines Cursor';
13850 --------------------------------------------
13851 FETCH c_expense_lines_cursor INTO
13852 l_temp_mileage_line_array(j).start_date,
13853 l_temp_mileage_line_array(j).end_date,
13854 l_temp_mileage_line_array(j).number_of_days,
13855 l_temp_mileage_line_array(j).orig_dist_line_number,
13856 l_temp_mileage_line_array(j).policy_id,
13857 l_temp_mileage_line_array(j).avg_mileage_rate,
13858 l_temp_mileage_line_array(j).distance_unit_code,
13859 l_temp_mileage_line_array(j).trip_distance,
13860 l_temp_mileage_line_array(j).daily_distance,
13861 l_temp_mileage_line_array(j).category_code,
13862 l_temp_mileage_line_array(j).reimbursement_currency_code,
13863 l_temp_mileage_line_array(j).amount,
13864 l_temp_mileage_line_array(j).number_people,
13865 l_temp_mileage_line_array(j).web_parameter_id,
13866 l_temp_mileage_line_array(j).rate_per_passenger,
13867 l_temp_mileage_line_array(j).attribute1,
13868 l_temp_mileage_line_array(j).attribute2 ,
13869 l_temp_mileage_line_array(j).attribute3 ,
13870 l_temp_mileage_line_array(j).attribute4 ,
13871 l_temp_mileage_line_array(j).attribute5 ,
13872 l_temp_mileage_line_array(j).attribute6 ,
13873 l_temp_mileage_line_array(j).attribute7 ,
13874 l_temp_mileage_line_array(j).attribute8 ,
13875 l_temp_mileage_line_array(j).attribute9 ,
13876 l_temp_mileage_line_array(j).attribute10 ,
13877 l_temp_mileage_line_array(j).attribute11 ,
13878 l_temp_mileage_line_array(j).attribute12 ,
13879 l_temp_mileage_line_array(j).attribute13 ,
13880 l_temp_mileage_line_array(j).attribute14 ,
13881 l_temp_mileage_line_array(j).attribute15 ,
13882 l_temp_mileage_line_array(j).report_line_id ;
13883 EXIT WHEN c_expense_lines_cursor%NOTFOUND;
13884 l_temp_mileage_line_array(j).report_header_id := l_report_header_id;
13885 l_temp_mileage_line_array(j).new_dist_line_number := l_temp_mileage_line_array(j).orig_dist_line_number;
13886 j := j+1;
13887 END LOOP;
13888 END IF;
13889
13890 l_mileage_array_count := c_expense_lines_cursor%ROWCOUNT;
13891
13892 IF (l_mileage_array_count > 0 ) THEN
13893 FOR j IN 1..l_mileage_array_count LOOP
13894 l_mileage_line_array(j).start_date := l_temp_mileage_line_array(j).start_date;
13895 l_mileage_line_array(j).end_date := l_temp_mileage_line_array(j).end_date;
13896 l_mileage_line_array(j).number_of_days:= l_temp_mileage_line_array(j).number_of_days;
13897 l_mileage_line_array(j).orig_dist_line_number:= l_temp_mileage_line_array(j).orig_dist_line_number;
13898 l_mileage_line_array(j).policy_id:= l_temp_mileage_line_array(j).policy_id;
13899 l_mileage_line_array(j).avg_mileage_rate:= l_temp_mileage_line_array(j).avg_mileage_rate;
13900 l_mileage_line_array(j).distance_unit_code:= l_temp_mileage_line_array(j).distance_unit_code;
13901 l_mileage_line_array(j).trip_distance:= l_temp_mileage_line_array(j).trip_distance;
13902 l_mileage_line_array(j).category_code:= l_temp_mileage_line_array(j).category_code;
13903 l_mileage_line_array(j).reimbursement_currency_code := l_temp_mileage_line_array(j).reimbursement_currency_code;
13904 l_mileage_line_array(j).amount := l_temp_mileage_line_array(j).amount;
13905 l_mileage_line_array(j).report_header_id := l_temp_mileage_line_array(j).report_header_id;
13906 l_mileage_line_array(j).new_dist_line_number := l_temp_mileage_line_array(j).new_dist_line_number;
13907 l_mileage_line_array(j).number_people := l_temp_mileage_line_array(j).number_people;
13908 l_mileage_line_array(j).web_parameter_id := l_temp_mileage_line_array(j).web_parameter_id;
13909 l_mileage_line_array(j).rate_per_passenger := l_temp_mileage_line_array(j).rate_per_passenger;
13910 l_mileage_line_array(j).attribute1 := l_temp_mileage_line_array(j).attribute1;
13911 l_mileage_line_array(j).attribute2 := l_temp_mileage_line_array(j).attribute2;
13912 l_mileage_line_array(j).attribute3 := l_temp_mileage_line_array(j).attribute3;
13913 l_mileage_line_array(j).attribute4 := l_temp_mileage_line_array(j).attribute4;
13914 l_mileage_line_array(j).attribute5 := l_temp_mileage_line_array(j).attribute5;
13915 l_mileage_line_array(j).attribute6 := l_temp_mileage_line_array(j).attribute6;
13916 l_mileage_line_array(j).attribute7 := l_temp_mileage_line_array(j).attribute7;
13917 l_mileage_line_array(j).attribute8 := l_temp_mileage_line_array(j).attribute8;
13918 l_mileage_line_array(j).attribute9 := l_temp_mileage_line_array(j).attribute9;
13919 l_mileage_line_array(j).attribute10 := l_temp_mileage_line_array(j).attribute10;
13920 l_mileage_line_array(j).attribute11 := l_temp_mileage_line_array(j).attribute11;
13921 l_mileage_line_array(j).attribute12 := l_temp_mileage_line_array(j).attribute12;
13922 l_mileage_line_array(j).attribute13 := l_temp_mileage_line_array(j).attribute13;
13923 l_mileage_line_array(j).attribute14 := l_temp_mileage_line_array(j).attribute14;
13924 l_mileage_line_array(j).attribute15 := l_temp_mileage_line_array(j).attribute15;
13925 l_mileage_line_array(j).report_line_id := l_temp_mileage_line_array(j).report_line_id;
13926 END loop;
13927
13928 FOR i IN 1..l_mileage_array_count LOOP
13929 --------------------------------------------
13930 l_debug_info := 'Start processing the mileage line';
13931 --------------------------------------------
13932 IF (l_mileage_line_array(i).category_code = 'MILEAGE') THEN
13933
13934 --------------------------------------------
13935 l_debug_info := 'Get distance UOM from schedule header';
13936 --------------------------------------------
13937 AP_WEB_DB_SCHLINE_PKG.getSchHeaderInfo(
13938 p_policy_id => l_mileage_line_array(i).policy_id,
13939 p_sh_distance_uom => l_sh_distance_uom,
13940 p_sh_currency_code => l_sh_currency_code,
13941 p_sh_distance_thresholds_flag => l_sh_distance_thresholds_flag);
13942
13943 IF (l_sh_distance_thresholds_flag = 'T') THEN
13944 l_cumulative_mileage := 0.0;
13945 l_period_id := 0;
13946 ELSIF (l_sh_distance_thresholds_flag = 'P') THEN
13947 AP_WEB_DB_USER_PREF_PKG.getCumulativeMileage(l_mileage_line_array(i).policy_id,
13948 l_mileage_line_array(i).start_date,
13949 l_mileage_line_array(i).end_date,
13950 l_employee_id,
13951 l_cumulative_mileage,
13952 l_period_id);
13953
13954 --------------------------------------------
13955 l_debug_info := 'Call getScheduleLine';
13956 --------------------------------------------
13957 getScheduleLineArray(l_report_header_id,
13958 l_mileage_line_array(i).orig_dist_line_number,
13959 l_employee_id,
13960 l_cumulative_mileage,
13961 l_schedule_line_array);
13962
13963 l_orig_distance_travel := l_mileage_line_array(i).trip_distance;
13964
13965 IF (l_schedule_line_array.COUNT > 1) THEN
13966
13967 processCrossThreshold(
13968 p_ml_index => i,
13969 p_sh_distance_uom => l_sh_distance_uom,
13970 p_sh_currency_code => l_sh_currency_code,
13971 p_schedule_line_array => l_schedule_line_array,
13972 p_mileage_line_array_count => l_mileage_array_count,
13973 p_cumulative_mileage => l_cumulative_mileage,
13974 p_mileage_line_array => l_mileage_line_array);
13975
13976 ELSIF (l_schedule_line_array.COUNT = 1 ) THEN
13977 -------------------------------------------
13978 l_debug_info := 'is distance within range';
13979 -------------------------------------------
13980 IF l_over_threshold_distance > 1 THEN
13981 l_mileage_line_array(i).trip_distance :=
13982 round(l_mileage_line_array(i).trip_distance -
13983 l_over_threshold_distance);
13984
13985 l_mileage_line_array(i).daily_distance :=
13986 round(l_mileage_line_array(i).trip_distance /
13987 l_mileage_line_array(i).number_of_days);
13988
13989 ELSE
13990
13991 l_mileage_line_array(i).daily_distance :=
13992 round(l_mileage_line_array(i).trip_distance /
13993 l_mileage_line_array(i).number_of_days);
13994
13995 END IF;
13996
13997 /* To determine whether the entire trip distance has met another
13998 * threshold, we compare the reimbursement amount to find it out.
13999 * By doing this, we can avoid the precision error especially
14000 * there is no limit on the precision of a rate when defining a
14001 * schedule.
14002 */
14003 l_rate := getRate(p_sh_distance_uom => l_sh_distance_uom,
14004 p_sh_currency_code => l_sh_currency_code,
14005 p_mileage_line => l_mileage_line_array(i),
14006 p_schedule_line => l_schedule_line_array(1));
14007
14008 /*l_rate := l_schedule_line_array(1).rate;
14009
14010 IF (l_sh_distance_uom <> l_mileage_line_array(i).distance_unit_code) THEN
14011 IF ((l_sh_distance_uom = C_KILOMETERS) AND (l_mileage_line_array(i).distance_unit_code = C_MILES )) THEN
14012 l_rate := round(l_schedule_line_array(1).rate * MILES_TO_KILOMETERS, 6);
14013 ELSIF ((l_sh_distance_uom = C_MILES) AND (l_mileage_line_array(i).distance_unit_code = C_KILOMETERS)) THEN
14014 l_rate := round(l_schedule_line_array(1).rate * KILOMETERS_TO_MILES, 6);
14015 ELSIF ((l_sh_distance_uom = C_SWMILES) AND (l_mileage_line_array(i).distance_unit_code = C_KILOMETERS)) THEN
14016 l_rate := round(l_schedule_line_array(1).rate * KILOMETERS_TO_SWMILES, 6);
14017 ELSIF ((l_sh_distance_uom = C_KILOMETERS) AND (l_mileage_line_array(i).distance_unit_code = C_SWMILES)) THEN
14018 l_rate := round(l_schedule_line_array(1).rate * SWMILES_TO_KILOMETERS, 6);
14019 ELSIF ((l_sh_distance_uom = C_MILES) AND (l_mileage_line_array(i).distance_unit_code = C_SWMILES)) THEN
14020 l_rate := round(l_schedule_line_array(1).rate * SWMILES_TO_MILES, 6);
14021 ELSIF ((l_sh_distance_uom = C_SWMILES) AND (l_mileage_line_array(i).distance_unit_code = C_MILES)) THEN
14022 l_rate := round(l_schedule_line_array(1).rate * MILES_TO_SWMILES, 6);
14023 END IF;
14024 END IF;*/
14025
14026 FND_CURRENCY.GET_INFO(
14027 l_mileage_line_array(i).reimbursement_currency_code,
14028 l_base_precision ,
14029 l_ext_precision ,
14030 l_base_min_acct_unit);
14031
14032 IF (round(l_rate * l_mileage_line_array(i).trip_distance,l_base_precision) <> l_mileage_line_array(i).amount) THEN
14033 -- update reimbursable amount (Rate)
14034
14035 l_new_rate := getRate(
14036 p_sh_distance_uom => l_sh_distance_uom,
14037 p_sh_currency_code => l_sh_currency_code,
14038 p_mileage_line => l_mileage_line_array(i),
14039 p_schedule_line => l_schedule_line_array(1));
14040
14041 /* Bug 3732690 : In ProcessMileageLines rounding the amount before calling
14042 updateExpenseMileageLines.
14043 */
14044
14045 l_mileage_line_array(i).amount :=
14046 AP_WEB_UTILITIES_PKG.OIE_ROUND_CURRENCY(
14047 l_new_rate * l_mileage_line_array(i).trip_distance,
14048 l_mileage_line_array(i).reimbursement_currency_code);
14049
14050 l_mileage_line_array(i).receipt_currency_amount :=
14051 l_mileage_line_array(i).amount;
14052
14053 l_mileage_line_array(i).daily_amount :=
14054 AP_WEB_UTILITIES_PKG.OIE_ROUND_CURRENCY(
14055 l_new_rate * l_mileage_line_array(i).trip_distance /
14056 l_mileage_line_array(i).number_of_days,
14057 l_mileage_line_array(i).reimbursement_currency_code);
14058
14059 l_mileage_line_array(i).avg_mileage_rate := l_new_rate;
14060
14061 l_mileage_line_array(i).new_dist_line_number :=
14062 l_mileage_line_array(i).orig_dist_line_number;
14063
14064 l_mileage_line_array(i).status := AP_WEB_DB_EXPLINE_PKG.C_Modified;
14065
14066
14067 END IF;
14068
14069 IF (l_mileage_line_array(i).distance_unit_code = C_MILES) THEN
14070 l_cumulative_mileage := round(((l_orig_distance_travel * MILES_TO_KILOMETERS) + l_cumulative_mileage),1);
14071 ELSIF (l_mileage_line_array(i).distance_unit_code = C_SWMILES) THEN
14072 l_cumulative_mileage := round(((l_orig_distance_travel * SWMILES_TO_KILOMETERS) + l_cumulative_mileage),1);
14073 ELSE
14074 l_cumulative_mileage := l_orig_distance_travel + l_cumulative_mileage;
14075 END IF;
14076
14077 END IF;
14078
14079
14080 IF (l_sh_distance_thresholds_flag = 'P') THEN
14081 updateCumulativeMileage(l_cumulative_mileage,
14082 l_period_id,
14083 l_employee_id);
14084
14085 END IF;
14086
14087 BEGIN
14088 SELECT CALCULATE_AMOUNT_FLAG
14089 INTO l_client_extension_enabled
14090 FROM ap_expense_report_params
14091 WHERE parameter_id = l_mileage_line_array(i).web_parameter_id;
14092 EXCEPTION WHEN OTHERS THEN
14093 l_client_extension_enabled := 'N';
14094 END;
14095 IF (l_client_extension_enabled = 'Y') THEN
14096
14097 Custom1_Array(1).value := l_mileage_line_array(i).attribute1;
14098 Custom1_Array(2).value := l_mileage_line_array(i).attribute2;
14099 Custom1_Array(3).value := l_mileage_line_array(i).attribute3;
14100 Custom1_Array(4).value := l_mileage_line_array(i).attribute4;
14101 Custom1_Array(5).value := l_mileage_line_array(i).attribute5;
14102 Custom1_Array(6).value := l_mileage_line_array(i).attribute6;
14103 Custom1_Array(7).value := l_mileage_line_array(i).attribute7;
14104 Custom1_Array(8).value := l_mileage_line_array(i).attribute8;
14105 Custom1_Array(9).value := l_mileage_line_array(i).attribute9;
14106 Custom1_Array(10).value := l_mileage_line_array(i).attribute10;
14107 Custom1_Array(11).value := l_mileage_line_array(i).attribute11;
14108 Custom1_Array(12).value := l_mileage_line_array(i).attribute12;
14109 Custom1_Array(13).value := l_mileage_line_array(i).attribute13;
14110 Custom1_Array(14).value := l_mileage_line_array(i).attribute14;
14111 Custom1_Array(15).value := l_mileage_line_array(i).attribute15;
14112
14113 AP_WEB_DFLEX_PKG.GetReceiptCustomFields(l_custom_array,
14114 1, -- from ap_web_oa_mainflow_pkg.validatereceiptline
14115 Custom1_Array,
14116 Custom2_Array,
14117 Custom3_Array,
14118 Custom4_Array,
14119 Custom5_Array,
14120 Custom6_Array,
14121 Custom7_Array,
14122 Custom8_Array,
14123 Custom9_Array,
14124 Custom10_Array,
14125 Custom11_Array,
14126 Custom12_Array,
14127 Custom13_Array,
14128 Custom14_Array,
14129 Custom15_Array
14130 );
14131
14132 -- Bug: 6476888, NO_DATA_FOUND, wrong index used.
14133 l_mileage_line.parameter_id := l_mileage_line_array(i).web_parameter_id;
14134 l_mileage_line.start_date := l_mileage_line_array(i).start_date;
14135 l_mileage_line.end_date := l_mileage_line_array(i).end_date;
14136 l_mileage_line.tripDistance := l_mileage_line_array(i).trip_distance;
14137 l_mileage_line.distanceUnitCode := l_mileage_line_array(i).distance_unit_code;
14138 l_mileage_line.amount := l_mileage_line_array(i).amount;
14139 l_mileage_line.mileageRate := l_mileage_line_array(i).avg_mileage_rate; -- ?? base rate?
14140 l_mileage_line.numberPassengers := l_mileage_line_array(i).number_people;
14141 l_mileage_line.passengerRateUsed := l_mileage_line_array(i).rate_per_passenger;
14142 l_mileage_line.currency_code := l_mileage_line_array(i).reimbursement_currency_code;
14143 l_mileage_line.category_code := l_mileage_line_array(i).category_code;
14144
14145 OPEN getAddonRates(l_mileage_line_array(i).report_line_id);
14146 k := 1;
14147 LOOP
14148 -- l_addon_rates(1) := 'FOREST_ROADS';
14149 FETCH getAddonRates INTO l_addon_rates(k);
14150 EXIT WHEN getAddonRates%NOTFOUND;
14151 k := k + 1;
14152 END LOOP;
14153 CLOSE getAddonRates;
14154
14155 -- Bug: 6617094, Expense Type not populated for CustomCalculateAmount.
14156 AP_WEB_DFLEX_PKG.PopulateExpTypeInLineRec(l_mileage_line);
14157 AP_WEB_CUST_DFLEX_PKG.CustomCalculateAmount( l_report_header_info -- can be null from wf perspective
14158 , l_mileage_line -- should contain all fields as defined in fdd
14159 , l_custom_array-- should contain all fields as defined in fdd
14160 , l_addon_rates -- should contain all fields as defined in fdd
14161 , p_cust_meals_amount => l_temp_array
14162 , p_cust_accommodation_amount => l_temp_array
14163 , p_cust_night_rate_amount => l_temp_array
14164 , p_cust_pdm_rate => l_temp_array);
14165 -- delete reference to temp array as this is used for per diem only
14166 -- deleting prevents inadvertent data corruption
14167 -- Bug: 6476888, VARRAY can be atomically null, CustomCalculateAmount need not initialize this for Mileage
14168 IF (l_temp_array is not null) THEN
14169 l_temp_array.delete; -- bug 5358186
14170 END IF;
14171 l_mileage_line_array(i).amount := l_mileage_line.amount;
14172 END IF; -- if client extension enabled
14173 END IF; -- (l_sh_distance_thresholds_flag = 'P')
14174 END IF; -- IF (category_code = 'MILEAGE')
14175 END LOOP;
14176
14177 AP_WEB_DB_EXPLINE_PKG.updateExpenseMileageLines(l_mileage_line_array, l_bHeaderUpdated);
14178
14179 -----------------------------------------------------------------------
14180 l_debug_info := 'update display_total item attribute if ap_expense_report_headers has been updated';
14181 -----------------------------------------------------------------------
14182 IF (l_bHeaderUpdated = TRUE) THEN
14183 IF (NOT AP_WEB_DB_EXPRPT_PKG.UpdateHeaderTotal(l_report_header_id)) THEN
14184 NULL;
14185 END IF;
14186
14187 IF (NOT AP_WEB_DB_EXPRPT_PKG.GetHeaderTotal(l_report_header_id,
14188 l_total)) THEN
14189 NULL;
14190 END IF;
14191
14192 IF (NOT AP_WEB_DB_EXPRPT_PKG.GetReimbCurr(l_report_header_id,
14193 l_reimb_curr)) THEN
14194
14195 NULL;
14196 END IF;
14197
14198 l_total_dsp := to_char(l_total,
14199 FND_CURRENCY.Get_Format_Mask(l_reimb_curr,22));
14200
14201 WF_ENGINE.SetItemAttrText('APEXP',
14202 to_char(l_report_header_id),
14203 'DISPLAY_TOTAL',
14204 l_total_dsp || ' ' || l_reimb_curr);
14205
14206
14207 END IF;
14208 END IF;
14209
14210 EXCEPTION
14211 WHEN OTHERS THEN
14212 AP_WEB_DB_UTIL_PKG.RaiseException('ProcessMileageLines');
14213 APP_EXCEPTION.RAISE_EXCEPTION;
14214 END ProcessMileageLines;
14215
14216 -------------------------------------------------------------------------------
14217 PROCEDURE hasCompanyViolations( p_item_type IN VARCHAR2,
14218 p_item_key IN VARCHAR2,
14219 p_actid IN NUMBER,
14220 p_funmode IN VARCHAR2,
14221 p_result OUT NOCOPY VARCHAR2) IS
14222 -------------------------------------------------------------------------------
14223 l_debug_info VARCHAR2(200);
14224 l_violations_count NUMBER:=0;
14225 l_report_header_id AP_WEB_DB_EXPRPT_PKG.expHdr_headerID;
14226 BEGIN
14227
14228
14229 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start hasCompanyViolations');
14230
14231 IF (p_funmode = 'RUN') THEN
14232 ------------------------------------------------------------
14233 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
14234 ------------------------------------------------------------
14235 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
14236 p_item_key,
14237 'EXPENSE_REPORT_ID');
14238 ------------------------------------------------------
14239 l_debug_info := 'Select from ap_pol_violations table';
14240 ------------------------------------------------------
14241 --Bug 3581975:Select the policy lines with distribution_line_number > 0.
14242 SELECT count(*)
14243 INTO l_violations_count
14244 FROM ap_pol_violations
14245 WHERE report_header_id = l_report_header_id
14246 and distribution_line_number > 0;
14247
14248 IF (l_violations_count > 0) THEN
14249 p_result := 'COMPLETE:Y';
14250 WF_ENGINE.SetItemAttrText(p_item_type,
14251 p_item_key,
14252 'RULES_VIOLATED',
14253 'Y');
14254 ELSE
14255 p_result := 'COMPLETE:N';
14256 WF_ENGINE.SetItemAttrText(p_item_type,
14257 p_item_key,
14258 'RULES_VIOLATED',
14259 'Y');
14260 END IF;
14261
14262 ELSIF (p_funmode = 'CANCEL') THEN
14263 p_result := 'COMPLETE';
14264 END IF;
14265
14266 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end hasCompanyViolations');
14267
14268 EXCEPTION
14269 WHEN OTHERS THEN
14270 AP_WEB_DB_UTIL_PKG.RaiseException('hasCompanyViolations');
14271 APP_EXCEPTION.RAISE_EXCEPTION;
14272 END hasCompanyViolations;
14273
14274
14275 -------------------------------------------------------------------------------
14276 PROCEDURE GenerateAmountMsg(document_id IN VARCHAR2,
14277 display_type IN VARCHAR2,
14278 document IN OUT NOCOPY VARCHAR2,
14279 document_type IN OUT NOCOPY VARCHAR2) IS
14280
14281 l_colon NUMBER;
14282 l_itemtype VARCHAR2(7);
14283 l_itemkey VARCHAR2(15);
14284
14285 l_report_header_id AP_WEB_DB_EXPLINE_PKG.expLines_headerID;
14286 l_debug_info VARCHAR2(2000);
14287 l_msg VARCHAR2(2000);
14288 l_approver_id NUMBER;
14289 l_total NUMBER;
14290 l_currency VARCHAR2(25);
14291
14292 BEGIN
14293
14294 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start GenerateAmountMsg');
14295
14296 ------------------------------------------------------------
14297 l_debug_info := 'Decode document_id';
14298 ------------------------------------------------------------
14299 l_colon := instrb(document_id, ':');
14300 l_debug_info := ' First index: ' || to_char(l_colon);
14301 l_itemtype := substrb(document_id, 1, l_colon - 1);
14302 l_itemkey := substrb(document_id, l_colon + 1);
14303
14304 ------------------------------------------------------
14305 l_debug_info := 'Retrieve Approve_ID Item Attribute';
14306 ------------------------------------------------------
14307 l_approver_id := WF_ENGINE.GetItemAttrNumber(l_itemtype,
14308 l_itemkey,
14309 'APPROVER_ID');
14310
14311 ------------------------------------------------------
14312 l_debug_info := 'Retrieve TOTAL Item Attribute';
14313 ------------------------------------------------------
14314 l_total := WF_ENGINE.GetItemAttrNumber(l_itemtype,
14315 l_itemkey,
14316 'TOTAL');
14317
14318 ------------------------------------------------------
14319 l_debug_info := 'Retrieve CURRENCY Item Attribute';
14320 ------------------------------------------------------
14321 l_currency := WF_ENGINE.GetItemAttrText(l_itemtype,
14322 l_itemkey,
14323 'CURRENCY');
14324
14325 l_msg := ap_web_amount_util.get_meaningful_amount_msg_emp(
14326 p_employee_id => l_approver_id,
14327 p_amount => l_total,
14328 p_date => SYSDATE,
14329 p_currency_code => l_currency);
14330
14331 document := l_msg;
14332 document_type := display_type;
14333
14334 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end GenerateExpLines');
14335
14336 EXCEPTION
14337 WHEN OTHERS THEN
14338 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'GenerateAmountMsg',
14339 document_id, l_debug_info);
14340 raise;
14341 END GenerateAmountMsg;
14342
14343 -------------------------------------------------------------------------------
14344 PROCEDURE GetRespAppInfo(p_item_key IN VARCHAR2,
14345 p_resp_id OUT NOCOPY NUMBER,
14346 P_appl_id OUT NOCOPY NUMBER) IS
14347 -------------------------------------------------------------------------------
14348 l_debug_info VARCHAR2(2000);
14349
14350 BEGIN
14351
14352 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start GetRespAppInfo');
14353
14354 ------------------------------------------------------
14355 l_debug_info := 'Retrieve RESPONSIBILITY_ID Item Attribute';
14356 ------------------------------------------------------
14357 p_resp_id := WF_ENGINE.GetItemAttrNumber('APEXP',
14358 p_item_key,
14359 'RESPONSIBILITY_ID');
14360
14361 ------------------------------------------------------
14362 l_debug_info := 'Retrieve APPLICATION_ID Item Attribute';
14363 ------------------------------------------------------
14364 p_appl_id := WF_ENGINE.GetItemAttrNumber('APEXP',
14365 p_item_key,
14366 'APPLICATION_ID');
14367
14368 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end GetRespAppInfo');
14369
14370 EXCEPTION
14371 WHEN OTHERS THEN
14372 if (wf_core.error_name = 'WFENG_ITEM_ATTR') then
14373 null;
14374 else
14375 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'GetRespAppInfo',
14376 p_item_key, l_debug_info);
14377 raise;
14378 end if;
14379 END GetRespAppInfo;
14380
14381 -------------------------------------------------------------------------------
14382 PROCEDURE GetAuditType( p_item_type IN VARCHAR2,
14383 p_item_key IN VARCHAR2,
14384 p_actid IN NUMBER,
14385 p_funmode IN VARCHAR2,
14386 p_result OUT NOCOPY VARCHAR2) IS
14387 -------------------------------------------------------------------------------
14388
14389 CURSOR audit_cur(p_report_header_id IN NUMBER) IS
14390 select audit_code
14391 from ap_expense_report_headers
14392 where report_header_id = p_report_header_id;
14393
14394 CURSOR rule_cur(p_report_header_id IN NUMBER) IS
14395 select rs.assign_auditor_stage_code, rs.audit_all,
14396 rs.paperless_audit_cc_only_flag,
14397 rs.paperless_audit_violation_flag,
14398 rs.paperless_audit_pdm_only_flag,
14399 aerh.workflow_approved_flag
14400 from ap_expense_report_headers aerh,
14401 ap_aud_rule_sets rs,
14402 ap_aud_rule_assignments_all rsa
14403 where aerh.report_header_id = p_report_header_id
14404 and aerh.org_id = rsa.org_id
14405 and rsa.rule_set_id = rs.rule_set_id
14406 and rs.rule_set_type = 'RULE'
14407 and TRUNC(SYSDATE)
14408 BETWEEN TRUNC(NVL(rsa.START_DATE,SYSDATE))
14409 AND TRUNC(NVL(rsa.END_DATE,SYSDATE));
14410
14411 CURSOR recpt_cur(p_report_header_id IN NUMBER) IS
14412 select rs.recpt_assign_stage_code,
14413 rs.AUD_IMG_RECEIPT_REQUIRED,
14414 rs.AUD_PAPER_RECEIPT_REQUIRED
14415 from ap_expense_report_headers aerh,
14416 ap_aud_rule_sets rs,
14417 ap_aud_rule_assignments_all rsa
14418 where aerh.report_header_id = p_report_header_id
14419 and aerh.org_id = rsa.org_id
14420 and rsa.rule_set_id = rs.rule_set_id
14421 and rs.rule_set_type = 'RULE'
14422 and TRUNC(SYSDATE)
14423 BETWEEN TRUNC(NVL(rsa.START_DATE,SYSDATE))
14424 AND TRUNC(NVL(rsa.END_DATE,SYSDATE));
14425
14426 l_debug_info VARCHAR2(200);
14427 l_report_header_id AP_WEB_DB_EXPRPT_PKG.expHdr_headerID;
14428 audit_rec audit_cur%ROWTYPE;
14429 rule_rec rule_cur%ROWTYPE;
14430 recpt_rec recpt_cur%ROWTYPE;
14431 l_image_receipts_status VARCHAR2(30);
14432 l_receipts_status VARCHAR2(30);
14433 l_auditor_id AP_AUD_AUDITORS.AUDITOR_ID%TYPE;
14434 BEGIN
14435
14436 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start GetAuditType');
14437
14438 IF (p_funmode = 'RUN') THEN
14439 ------------------------------------------------------------
14440 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
14441 ------------------------------------------------------------
14442 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
14443 p_item_key,
14444 'EXPENSE_REPORT_ID');
14445
14446 IF l_report_header_id IS NULL THEN
14447
14448 p_result := 'COMPLETE:AUDIT';
14449
14450 ELSE
14451
14452 BEGIN
14453 SELECT auditor_id INTO l_auditor_id FROM ap_aud_queues WHERE expense_report_id = l_report_header_id;
14454 EXCEPTION
14455 WHEN OTHERS THEN
14456 l_auditor_id := NULL;
14457 END;
14458
14459 ------------------------------------------------------------
14460 l_debug_info := 'Retrieve Expense Report audit type';
14461 ------------------------------------------------------------
14462 OPEN audit_cur(l_report_header_id);
14463 FETCH audit_cur INTO audit_rec;
14464
14465 IF audit_cur%NOTFOUND THEN
14466 p_result := 'COMPLETE:AUDIT';
14467 ELSIF audit_rec.audit_code is null THEN
14468 p_result := 'COMPLETE:AUDIT';
14469 ELSIF audit_rec.audit_code = 'PAPERLESS_AUDIT' THEN
14470
14471 OPEN rule_cur(l_report_header_id);
14472 FETCH rule_cur INTO rule_rec;
14473 -- Bug: 10373316, do not assign audited reports back to the auditor.
14474 IF (rule_cur%FOUND AND
14475 (NVL(rule_rec.audit_ALL, 'N') = 'Y'
14476 OR (NVL(rule_rec.paperless_audit_cc_only_flag, 'N') = 'Y' AND AP_WEB_UTILITIES_PKG.ReportHasOnlyCCLines(l_report_header_id) = TRUE)
14477 OR (NVL(rule_rec.paperless_audit_violation_flag, 'N') = 'Y' AND AP_WEB_UTILITIES_PKG.ReportHasViolations(l_report_header_id) = TRUE)
14478 OR (NVL(rule_rec.paperless_audit_pdm_only_flag, 'N') = 'Y' AND AP_WEB_UTILITIES_PKG.ReportHasNonRecLines(l_report_header_id) = TRUE)
14479 )
14480 AND
14481 rule_rec.assign_auditor_stage_code = 'MANAGER_APPROVAL'
14482 AND nvl(rule_rec.workflow_approved_flag,'N') = 'M') THEN
14483 IF (l_auditor_id IS NULL) THEN
14484 AP_WEB_AUDIT_QUEUE_UTILS.enqueue_for_audit(l_report_header_id);
14485 END IF;
14486 END IF;
14487
14488 CLOSE rule_cur;
14489
14490 p_result := 'COMPLETE:RULE_BASED_AUDIT';
14491 ELSIF audit_rec.audit_code = 'RECEIPT_BASED' THEN
14492
14493 OPEN recpt_cur(l_report_header_id);
14494 FETCH recpt_cur INTO recpt_rec;
14495
14496 IF recpt_rec.recpt_assign_stage_code = 'MGR_APPR_IMG' THEN
14497
14498
14499 select nvl(image_receipts_status,'NOT_REQUIRED') ,
14500 nvl(receipts_status, 'NOT_REQUIRED') into l_image_receipts_status, l_receipts_status from
14501 ap_expense_report_headers_all where report_header_id = l_report_header_id;
14502
14503 IF ((NVL(recpt_rec.AUD_IMG_RECEIPT_REQUIRED, 'N') = 'Y' AND l_image_receipts_status = 'RECEIVED')
14504 OR (NVL(recpt_rec.AUD_PAPER_RECEIPT_REQUIRED, 'N') = 'Y' AND l_receipts_status = 'RECEIVED')) THEN
14505 IF (l_auditor_id IS NULL) THEN
14506 AP_WEB_AUDIT_QUEUE_UTILS.enqueue_for_audit(l_report_header_id);
14507 END IF;
14508 END IF;
14509
14510 END IF;
14511
14512 CLOSE recpt_cur;
14513
14514 p_result := 'COMPLETE:RECEIPT_BASED';
14515
14516 ELSIF audit_rec.audit_code = 'AUTO_APPROVE' THEN
14517 p_result := 'COMPLETE:AUTO_APPROVED';
14518 ELSIF audit_rec.audit_code = 'AUDIT' THEN
14519 OPEN recpt_cur(l_report_header_id);
14520 FETCH recpt_cur INTO recpt_rec;
14521
14522 IF recpt_rec.recpt_assign_stage_code = 'MGR_APPR_IMG' THEN
14523
14524 select nvl(image_receipts_status,'NOT_REQUIRED') ,
14525 nvl(receipts_status, 'NOT_REQUIRED') into l_image_receipts_status, l_receipts_status from
14526 ap_expense_report_headers_all where report_header_id = l_report_header_id;
14527
14528 IF ((NVL(recpt_rec.AUD_IMG_RECEIPT_REQUIRED, 'N') = 'Y' AND l_image_receipts_status = 'RECEIVED')
14529 OR (NVL(recpt_rec.AUD_PAPER_RECEIPT_REQUIRED, 'N') = 'Y' AND l_receipts_status = 'RECEIVED')) THEN
14530 IF (l_auditor_id IS NULL) THEN
14531 AP_WEB_AUDIT_QUEUE_UTILS.enqueue_for_audit(l_report_header_id);
14532 END IF;
14533 END IF;
14534
14535 END IF;
14536
14537 CLOSE recpt_cur;
14538
14539 p_result := 'COMPLETE:RULE_BASED_AUDIT';
14540 ELSE
14541 OPEN recpt_cur(l_report_header_id);
14542 FETCH recpt_cur INTO recpt_rec;
14543
14544 IF recpt_rec.recpt_assign_stage_code = 'MGR_APPR_IMG' THEN
14545
14546 select nvl(image_receipts_status,'NOT_REQUIRED') ,
14547 nvl(receipts_status, 'NOT_REQUIRED') into l_image_receipts_status, l_receipts_status from
14548 ap_expense_report_headers_all where report_header_id = l_report_header_id;
14549
14550 IF ((NVL(recpt_rec.AUD_IMG_RECEIPT_REQUIRED, 'N') = 'Y' AND l_image_receipts_status = 'RECEIVED')
14551 OR (NVL(recpt_rec.AUD_PAPER_RECEIPT_REQUIRED, 'N') = 'Y' AND l_receipts_status = 'RECEIVED')) THEN
14552 IF (l_auditor_id IS NULL) THEN
14553 AP_WEB_AUDIT_QUEUE_UTILS.enqueue_for_audit(l_report_header_id);
14554 END IF;
14555 END IF;
14556
14557 END IF;
14558
14559 CLOSE recpt_cur;
14560
14561 p_result := 'COMPLETE:AUDIT';
14562 END IF;
14563
14564 CLOSE audit_cur;
14565
14566 END IF;
14567
14568 ELSIF (p_funmode = 'CANCEL') THEN
14569 p_result := 'COMPLETE';
14570 END IF;
14571
14572 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end GetAuditType');
14573
14574 EXCEPTION
14575 WHEN OTHERS THEN
14576 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'GetAuditType',
14577 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
14578 raise;
14579 END GetAuditType;
14580
14581
14582 -------------------------------------------------------------------------------
14583 PROCEDURE ResetWFNote(p_item_type IN VARCHAR2,
14584 p_item_key IN VARCHAR2,
14585 p_actid IN NUMBER,
14586 p_funmode IN VARCHAR2,
14587 p_result OUT NOCOPY VARCHAR2) IS
14588 -------------------------------------------------------------------------------
14589
14590 l_debug_info VARCHAR2(200);
14591
14592 BEGIN
14593
14594
14595 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start ResetWFNote');
14596
14597 ---------------------------------------------------------------
14598 l_debug_info := 'Reset WF_NOTE';
14599 ---------------------------------------------------------------
14600 WF_ENGINE.SetItemAttrText(p_item_type,
14601 p_item_key,
14602 'WF_NOTE',
14603 '');
14604
14605 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end ResetWFNote');
14606
14607 EXCEPTION
14608 WHEN OTHERS THEN
14609 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'ResetWFNote',
14610 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
14611 raise;
14612 END ResetWFNote;
14613
14614 ----------------------------------------------------------------------
14615 PROCEDURE AddToOtherErrors(p_item_type IN VARCHAR2,
14616 p_item_key IN VARCHAR2,
14617 p_other_error IN VARCHAR2) IS
14618 ----------------------------------------------------------------------
14619
14620 l_other_errors VARCHAR2(2000) := NULL;
14621
14622 l_prompts AP_WEB_UTILITIES_PKG.prompts_table;
14623 l_title AK_REGIONS_VL.name%TYPE;
14624
14625 l_debug_info VARCHAR2(2000);
14626
14627 BEGIN
14628
14629 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start AddToOtherErrors');
14630
14631 ---------------------------------------------------------
14632 l_debug_info := 'Add to Other Errors';
14633 ---------------------------------------------------------
14634 l_other_errors := WF_ENGINE.GetItemAttrText(p_item_type,
14635 p_item_key,
14636 'OTHER_ERRORS');
14637 ---------------------------------------------------------
14638 l_debug_info := 'Check to see if error title needed';
14639 ---------------------------------------------------------
14640 if (l_other_errors IS NULL) then
14641 ---------------------------------------------------------
14642 l_debug_info := 'Add font tag';
14643 ---------------------------------------------------------
14644 l_other_errors := startOraFieldTextFont;
14645 else
14646 l_other_errors := l_other_errors || '<br>';
14647 end if;
14648
14649 AddToWFSSError(l_other_errors, p_other_error);
14650 l_other_errors := l_other_errors || endOraFieldTextFont;
14651
14652 WF_ENGINE.SetItemAttrText(p_item_type,
14653 p_item_key,
14654 'OTHER_ERRORS',
14655 l_other_errors);
14656
14657 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end AddToOtherErrors');
14658
14659 EXCEPTION
14660 WHEN OTHERS THEN
14661 IF (SQLCODE <> -20001) THEN
14662 FND_MESSAGE.SET_NAME('SQLAP','AP_DEBUG');
14663 FND_MESSAGE.SET_TOKEN('ERROR',SQLERRM);
14664 FND_MESSAGE.SET_TOKEN('CALLING_SEQUENCE', 'AddToOtherErrors');
14665 FND_MESSAGE.SET_TOKEN('DEBUG_INFO',l_debug_info);
14666 END IF;
14667 APP_EXCEPTION.RAISE_EXCEPTION;
14668
14669 END AddToOtherErrors;
14670
14671 /*
14672 Written by:
14673 Ron Langi
14674 Purpose:
14675 To generate HEADER_ERRORS as a plsql doc attr since OWF.G no longer
14676 supports the use of html tags within a text item.
14677 */
14678 ----------------------------------------------------------------------
14679 PROCEDURE GenerateHeaderErrors(document_id IN VARCHAR2,
14680 display_type IN VARCHAR2,
14681 document IN OUT NOCOPY VARCHAR2,
14682 document_type IN OUT NOCOPY VARCHAR2) IS
14683 ----------------------------------------------------------------------
14684 l_colon NUMBER;
14685 l_itemtype VARCHAR2(7);
14686 l_itemkey VARCHAR2(25);
14687
14688 l_debug_info VARCHAR2(200);
14689
14690 BEGIN
14691 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start GenerateHeaderErrors');
14692
14693 ------------------------------------------------------------
14694 l_debug_info := 'Decode document_id';
14695 ------------------------------------------------------------
14696 l_colon := instrb(document_id, ':');
14697 l_itemtype := substrb(document_id, 1, l_colon - 1);
14698 l_itemkey := substrb(document_id, l_colon + 1);
14699
14700 ------------------------------------------------------------
14701 l_debug_info := 'Retrieve HEADER_ERRORS Item Attribute';
14702 ------------------------------------------------------------
14703 document := WF_ENGINE.GetItemAttrText(l_itemtype,
14704 l_itemkey,
14705 'HEADER_ERRORS');
14706
14707 document_type := display_type;
14708
14709 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end GenerateHeaderErrors');
14710
14711 EXCEPTION
14712 WHEN OTHERS THEN
14713 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'GenerateHeaderErrors', document_id, l_debug_info);
14714 raise;
14715
14716 END GenerateHeaderErrors;
14717
14718
14719 /**
14720 * jrautiai ADJ Fix start
14721 */
14722 ----------------------------------------------------------------------
14723 PROCEDURE SetFromRoleAP(
14724 p_item_type IN VARCHAR2,
14725 p_item_key IN VARCHAR2,
14726 p_actid IN NUMBER,
14727 p_funmode IN VARCHAR2,
14728 p_result OUT NOCOPY VARCHAR2) IS
14729 ----------------------------------------------------------------------
14730 l_debug_info VARCHAR2(200);
14731 l_auditor_name fnd_user.user_name%type;
14732 BEGIN
14733
14734 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start SetFromRoleAP');
14735
14736 IF (p_funmode = 'RUN') THEN
14737 ----------------------------------------------------------------
14738 l_debug_info := 'Set #FROM_ROLE to AP';
14739 ----------------------------------------------------------------
14740 -- Setting the from role to the last auditor Bug 8371199 (sodash)
14741 begin
14742 SELECT user_name INTO l_auditor_name
14743 FROM fnd_user
14744 WHERE user_id=(SELECT last_audited_by
14745 FROM ap_expense_report_headers_all
14746 WHERE report_header_id=p_item_key);
14747 exception
14748 when no_data_found then
14749 l_auditor_name := WF_ENGINE.GetItemAttrText(p_item_type,
14750 p_item_key,
14751 'PAYABLES');
14752 end;
14753
14754 SetFromRole(p_item_type,
14755 p_item_key,
14756 p_actid,
14757 l_auditor_name,
14758 'SetFromRoleAP'
14759 );
14760 /*
14761 WF_ENGINE.SetItemAttrText(p_item_type,
14762 p_item_key,
14763 '#FROM_ROLE',
14764 WF_ENGINE.GetItemAttrText(p_item_type,
14765 p_item_key,
14766 'PAYABLES'));
14767 */
14768 p_result := 'COMPLETE:Y';
14769
14770 ELSIF (p_funmode = 'CANCEL') THEN
14771 p_result := 'COMPLETE';
14772 END IF;
14773
14774 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end SetFromRoleAP');
14775
14776 EXCEPTION
14777 WHEN OTHERS THEN
14778 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'SetFromRoleAP',
14779 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
14780 raise;
14781 END SetFromRoleAP;
14782
14783
14784 ------------------------------------------------------------------------
14785 PROCEDURE SetPolicyInfo(p_item_type IN VARCHAR2,
14786 p_item_key IN VARCHAR2,
14787 p_actid IN NUMBER,
14788 p_funmode IN VARCHAR2,
14789 p_result OUT NOCOPY VARCHAR2) IS
14790 -------------------------------------------------------------------------
14791 l_debug_info VARCHAR2(2000);
14792 BEGIN
14793
14794 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start SetPolicyInfo');
14795 SetShortPaidLinesInfo(p_item_type,
14796 p_item_key,
14797 p_actid,
14798 p_funmode,
14799 'POLICY',
14800 p_result);
14801 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end SetPolicyInfo');
14802
14803 EXCEPTION
14804 WHEN OTHERS THEN
14805 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'SetPolicyInfo',
14806 p_item_type, p_item_key, null, l_debug_info);
14807 raise;
14808 END SetPolicyInfo;
14809
14810 ------------------------------------------------------------------------
14811 PROCEDURE SetMissingReceiptInfo(p_item_type IN VARCHAR2,
14812 p_item_key IN VARCHAR2,
14813 p_actid IN NUMBER,
14814 p_funmode IN VARCHAR2,
14815 p_result OUT NOCOPY VARCHAR2) IS
14816 -------------------------------------------------------------------------
14817 l_debug_info VARCHAR2(2000);
14818 BEGIN
14819
14820 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start SetMissingReceiptInfo');
14821
14822 SetShortPaidLinesInfo(p_item_type,
14823 p_item_key,
14824 p_actid,
14825 p_funmode,
14826 'MISSING_RECEIPT',
14827 p_result);
14828 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end SetMissingReceiptInfo');
14829
14830 EXCEPTION
14831 WHEN OTHERS THEN
14832 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'SetMissingReceiptInfo',
14833 p_item_type, p_item_key, null, l_debug_info);
14834 raise;
14835 END SetMissingReceiptInfo;
14836
14837 ------------------------------------------------------------------------
14838 PROCEDURE SetProvideMissingInfo(p_item_type IN VARCHAR2,
14839 p_item_key IN VARCHAR2,
14840 p_actid IN NUMBER,
14841 p_funmode IN VARCHAR2,
14842 p_result OUT NOCOPY VARCHAR2) IS
14843 ------------------------------------------------------------------------
14844 l_debug_info VARCHAR2(2000);
14845 l_mess Wf_Item_Attribute_Values.TEXT_VALUE%TYPE;
14846 l_document_number AP_WEB_DB_EXPRPT_PKG.expHdr_invNum;
14847 l_preparer_name VARCHAR2(2000);
14848 BEGIN
14849
14850 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start SetProvideMissingInfo');
14851
14852
14853 ----------------------------------------------------------------
14854 l_debug_info := 'Set #FROM_ROLE to Preparer';
14855 ----------------------------------------------------------------
14856 SetFromRolePreparer(p_item_type, p_item_key, p_actid, p_funmode, p_result);
14857
14858 l_document_number := WF_ENGINE.GetItemAttrText(p_item_type,
14859 p_item_key,
14860 'DOCUMENT_NUMBER');
14861
14862 l_preparer_name := WF_ENGINE.GetItemAttrText(p_item_type,
14863 p_item_key,
14864 'PREPARER_DISPLAY_NAME');
14865
14866 FND_MESSAGE.SET_NAME('SQLAP','OIE_WF_PROVIDE_MISSING_NOTE');
14867 FND_MESSAGE.Set_Token('EMPLOYEE_NAME', l_preparer_name);
14868 FND_MESSAGE.Set_Token('REPORT_NUMBER', l_document_number);
14869 l_mess := FND_MESSAGE.GET;
14870
14871 WF_ENGINE.SetItemAttrText(p_item_type,
14872 p_item_key,
14873 'OIENOTES',
14874 l_mess);
14875
14876 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end SetProvideMissingInfo');
14877
14878 EXCEPTION
14879 WHEN OTHERS THEN
14880 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'SetProvideMissingInfo',
14881 p_item_type, p_item_key, null, l_debug_info);
14882 raise;
14883 END SetProvideMissingInfo;
14884
14885 PROCEDURE ResetShortpayAdjustmentInfo(p_item_type IN VARCHAR2,
14886 p_item_key IN VARCHAR2,
14887 p_actid IN NUMBER,
14888 p_funmode IN VARCHAR2,
14889 p_result OUT NOCOPY VARCHAR2) IS
14890 l_debug_info VARCHAR2(2000);
14891 l_report_header_id NUMBER;
14892 BEGIN
14893 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start ResetShortpayAdjustmentInfo');
14894
14895 ------------------------------------------------------------
14896 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
14897 ------------------------------------------------------------
14898 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
14899 p_item_key,
14900 'EXPENSE_REPORT_ID');
14901
14902 ----------------------------------------------------------------
14903 l_debug_info := 'Reset adjustment information';
14904 ----------------------------------------------------------------
14905 AP_WEB_DB_EXPLINE_PKG.ResetShortpayAdjustmentInfo(l_report_header_id);
14906
14907 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end ResetShortpayAdjustmentInfo');
14908 EXCEPTION
14909 WHEN OTHERS THEN
14910 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'ResetShortpayAdjustmentInfo',
14911 p_item_type, p_item_key, null, l_debug_info);
14912 raise;
14913 END ResetShortpayAdjustmentInfo;
14914
14915 /**
14916 * jrautiai ADJ Fix end
14917 */
14918
14919
14920 /*
14921 Written by:
14922 Ron Langi
14923 Purpose:
14924 To check the result of the Audit Review.
14925
14926 The possible results are:
14927 Reviewed - Auditor Complete
14928 Rejected - Auditor Rejected
14929 Request More Info - Auditor Requesting More Info
14930 */
14931 ----------------------------------------------------------------------
14932 PROCEDURE CheckAPReviewResult(
14933 p_item_type IN VARCHAR2,
14934 p_item_key IN VARCHAR2,
14935 p_actid IN NUMBER,
14936 p_funmode IN VARCHAR2,
14937 p_result OUT NOCOPY VARCHAR2) IS
14938 ----------------------------------------------------------------------
14939 l_report_header_id AP_WEB_DB_EXPRPT_PKG.expHdr_headerID;
14940 l_workflow_approved_flag AP_WEB_DB_EXPRPT_PKG.expHdr_wkflApprvdFlag;
14941
14942 l_return_reason VARCHAR2(80);
14943 l_return_instruction Wf_Item_Attribute_Values.TEXT_VALUE%TYPE;
14944
14945 l_debug_info VARCHAR2(200);
14946 BEGIN
14947
14948 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start CheckAPReviewResult');
14949
14950
14951 IF (p_funmode = 'RUN') THEN
14952
14953 ----------------------------------------------------------------
14954 l_debug_info := 'Set #FROM_ROLE to AP';
14955 ----------------------------------------------------------------
14956 SetFromRoleAP(p_item_type, p_item_key, p_actid, p_funmode, p_result);
14957
14958 ------------------------------------------------------------
14959 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
14960 ------------------------------------------------------------
14961 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
14962 p_item_key,
14963 'EXPENSE_REPORT_ID');
14964
14965 ------------------------------------------------------------
14966 l_debug_info := 'Retrieve Return Reason and Instruction';
14967 ------------------------------------------------------------
14968 if (not AP_WEB_DB_EXPRPT_PKG.getAuditReturnReasonInstr(l_report_header_id,
14969 l_return_reason,
14970 l_return_instruction)) then
14971 l_debug_info := 'Could not retrieve Return Reason and Instruction';
14972 end if;
14973
14974 ----------------------------------------------------------
14975 l_debug_info := 'Set Item Attribute AUDIT_RETURN_REASON';
14976 ---------------------------------------------------------
14977 WF_ENGINE.SetItemAttrText(p_item_type,
14978 p_item_key,
14979 'AUDIT_RETURN_REASON',
14980 l_return_reason);
14981
14982 ----------------------------------------------------------
14983 l_debug_info := 'Set Item Attribute AUDIT_INSTRUCTIONS';
14984 ---------------------------------------------------------
14985 WF_ENGINE.SetItemAttrText(p_item_type,
14986 p_item_key,
14987 'AUDIT_INSTRUCTIONS',
14988 l_return_instruction);
14989
14990 ----------------------------------------------------------
14991 l_debug_info := 'Set Item Attribute Line_Info_Body';
14992 ---------------------------------------------------------
14993 WF_ENGINE.SetItemAttrText(p_item_type,
14994 p_item_key,
14995 'LINE_INFO_BODY',
14996 'plsql:AP_WEB_EXPENSE_WF.generateAdjustmentInfo/'|| p_item_type || ':' || p_item_key || ':AUDIT');
14997
14998 ------------------------------------------------------------
14999 l_debug_info := 'Retrieve Workflow_Approved_Flag';
15000 ------------------------------------------------------------
15001 SELECT WORKFLOW_APPROVED_FLAG
15002 INTO l_workflow_approved_flag
15003 FROM AP_EXPENSE_REPORT_HEADERS
15004 WHERE REPORT_HEADER_ID = l_report_header_id;
15005
15006 IF (l_workflow_approved_flag = AP_WEB_DB_EXPRPT_PKG.C_WORKFLOW_APPROVED_REJECTED) THEN
15007 p_result := 'COMPLETE:REJECTED';
15008 ELSIF (l_workflow_approved_flag = AP_WEB_DB_EXPRPT_PKG.C_WORKFLOW_APPROVED_REQUEST) THEN
15009 p_result := 'COMPLETE:REQUEST_MORE_INFO';
15010 ELSE
15011 p_result := 'COMPLETE:REVIEWED';
15012 END IF;
15013
15014 ELSIF (p_funmode = 'CANCEL') THEN
15015 NULL;
15016
15017 END IF;
15018
15019 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end CheckAPReviewResult');
15020
15021 EXCEPTION
15022 WHEN OTHERS THEN
15023 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'CheckAPReviewResult',
15024 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
15025 raise;
15026 END CheckAPReviewResult;
15027
15028
15029 /*
15030 Written by:
15031 Ron Langi
15032 Purpose:
15033 This adds the expense report back to the Audit queue.
15034 */
15035 ----------------------------------------------------------------------
15036 PROCEDURE AddToAuditQueue(
15037 p_item_type IN VARCHAR2,
15038 p_item_key IN VARCHAR2,
15039 p_actid IN NUMBER,
15040 p_funmode IN VARCHAR2,
15041 p_result OUT NOCOPY VARCHAR2) IS
15042 ----------------------------------------------------------------------
15043 l_report_header_id AP_WEB_DB_EXPRPT_PKG.expHdr_headerID;
15044 l_debug_info VARCHAR2(200);
15045 l_manager_approved VARCHAR2(5);
15046 l_workflow_flag VARCHAR2(5);
15047
15048 CURSOR audit_cur(p_report_header_id IN NUMBER) IS
15049 select audit_code, workflow_approved_flag
15050 from ap_expense_report_headers
15051 where report_header_id = p_report_header_id;
15052
15053 audit_rec audit_cur%ROWTYPE;
15054
15055 BEGIN
15056
15057 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start AddToAuditQueue');
15058
15059
15060 IF (p_funmode = 'RUN') THEN
15061
15062 ------------------------------------------------------------
15063 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
15064 ------------------------------------------------------------
15065 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
15066 p_item_key,
15067 'EXPENSE_REPORT_ID');
15068
15069 -------------------------------------------------------------------
15070 l_debug_info := 'Retrieve UPDATE_MANAGER_APPROVED Activity Attribute';
15071 -------------------------------------------------------------------
15072 l_manager_approved := WF_ENGINE.GetActivityAttrText(p_item_type,
15073 p_item_key,
15074 p_actid,
15075 'UPDATE_MANAGER_APPROVED');
15076
15077 ----------------------------------------------------------------------
15078 l_debug_info := 'Retrieve Expense Report audit type and workflow flag';
15079 ----------------------------------------------------------------------
15080 OPEN audit_cur(l_report_header_id);
15081 FETCH audit_cur INTO audit_rec;
15082
15083 IF l_manager_approved = 'Y' THEN
15084
15085 IF audit_rec.workflow_approved_flag in ('P','Y') THEN
15086 l_workflow_flag := 'Y';
15087 ELSE
15088 l_workflow_flag := 'M';
15089 END IF;
15090
15091 ----------------------------------------------------------------------
15092 l_debug_info := 'Update the Expense Report as Mgr Approved so that it can be auditable';
15093 ----------------------------------------------------------------------
15094 IF (NOT AP_WEB_DB_EXPRPT_PKG.SetWkflApprvdFlagAndSource(l_report_header_id,
15095 l_workflow_flag, NULL)) THEN
15096 NULL;
15097 END IF;
15098
15099 END IF;
15100
15101
15102 IF audit_rec.audit_code = 'PAPERLESS_AUDIT' THEN
15103 ------------------------------------------------------------
15104 l_debug_info := 'Add to Audit queue';
15105 ------------------------------------------------------------
15106 AP_WEB_AUDIT_QUEUE_UTILS.enqueue_for_audit(l_report_header_id);
15107 ELSIF (audit_rec.audit_code = 'AUDIT' OR audit_rec.audit_code = 'RECEIPT_BASED') THEN
15108 ------------------------------------------------------------
15109 l_debug_info := 'Add to Audit queue';
15110 ------------------------------------------------------------
15111 --Bug#6618522
15112 AP_WEB_AUDIT_QUEUE_UTILS.assign_to_last_auditor(l_report_header_id);
15113 END IF;
15114
15115 CLOSE audit_cur;
15116
15117 p_result := 'COMPLETE:Y';
15118
15119 ELSIF (p_funmode = 'CANCEL') THEN
15120 NULL;
15121
15122 END IF;
15123
15124 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end AddToAuditQueue');
15125
15126 EXCEPTION
15127 WHEN OTHERS THEN
15128 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'AddToAuditQueue',
15129 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
15130 raise;
15131 END AddToAuditQueue;
15132
15133
15134 /*
15135 Written by:
15136 Ron Langi
15137 Purpose:
15138 This removes the expense report from the Audit queue.
15139 */
15140 ----------------------------------------------------------------------
15141 PROCEDURE RemoveFromAuditQueue(
15142 p_item_type IN VARCHAR2,
15143 p_item_key IN VARCHAR2,
15144 p_actid IN NUMBER,
15145 p_funmode IN VARCHAR2,
15146 p_result OUT NOCOPY VARCHAR2) IS
15147 ----------------------------------------------------------------------
15148 l_report_header_id AP_WEB_DB_EXPRPT_PKG.expHdr_headerID;
15149 l_debug_info VARCHAR2(200);
15150 BEGIN
15151
15152 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start RemoveFromAuditQueue');
15153
15154
15155 IF (p_funmode = 'RUN') THEN
15156
15157 ------------------------------------------------------------
15158 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
15159 ------------------------------------------------------------
15160 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
15161 p_item_key,
15162 'EXPENSE_REPORT_ID');
15163
15164 ------------------------------------------------------------
15165 l_debug_info := 'Remove from Audit queue';
15166 ------------------------------------------------------------
15167 AP_WEB_AUDIT_QUEUE_UTILS.remove_from_queue(l_report_header_id);
15168
15169 p_result := 'COMPLETE:Y';
15170
15171 ELSIF (p_funmode = 'CANCEL') THEN
15172 NULL;
15173
15174 END IF;
15175
15176 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end RemoveFromAuditQueue');
15177
15178 EXCEPTION
15179 WHEN OTHERS THEN
15180 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'RemoveFromAuditQueue',
15181 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
15182 raise;
15183 END RemoveFromAuditQueue;
15184
15185
15186 /*
15187 Written by:
15188 Ron Langi
15189 Purpose:
15190 This stores a Preparer-Auditor note based on the Manager/Preparer/Employee/Sysadmin
15191 action/response from a notification activity.
15192
15193 The following is gathered from the WF:
15194 - RESULT_TYPE contains the lookup type for the result of the Notification.
15195 - RESULT_CODE contains the lookup code for the result of the Notification.
15196 - RESPONSE contains the respond attr for the Notification.
15197
15198 The Preparer-Auditor note is stored in the form of:
15199 Preparer Response: <Preparer Response>
15200 or
15201 Employee Action: <Employee Response> (for 3rd Party Approval)
15202 or
15203 Approver Action: <Approver Response>
15204 or
15205 Sysadmin Action: <Sysadmin Response>
15206 */
15207 ----------------------------------------------------------------------
15208 PROCEDURE StoreNote(
15209 p_item_type IN VARCHAR2,
15210 p_item_key IN VARCHAR2,
15211 p_actid IN NUMBER,
15212 p_funmode IN VARCHAR2,
15213 p_result IN OUT NOCOPY VARCHAR2) IS
15214 ----------------------------------------------------------------------
15215 l_report_header_id AP_WEB_DB_EXPRPT_PKG.expHdr_headerID;
15216 l_debug_info VARCHAR2(200);
15217
15218 l_message_name fnd_new_messages.message_name%type;
15219 l_result_type varchar2(80);
15220 l_result_code varchar2(80);
15221 l_response varchar2(80);
15222 l_type_display_name varchar2(80);
15223 l_code_display_name varchar2(80);
15224 l_note_prefix varchar2(2000);
15225
15226 l_orig_language_code ap_expense_params.note_language_code%type := null;
15227 l_orig_language fnd_languages.nls_language%type := null;
15228 l_new_language_code ap_expense_params.note_language_code%type := null;
15229 l_new_language fnd_languages.nls_language%type := null;
15230
15231 l_entered_by NUMBER := fnd_global.user_id;
15232 l_user_name fnd_user.user_name%TYPE := null;
15233 l_ame_enabled varchar2(1) := 'N';
15234
15235 l_approval_type AP_EXPENSE_REPORT_HEADERS_ALL.APPROVAL_TYPE%TYPE;
15236 l_workflow_flag AP_EXPENSE_REPORT_HEADERS_ALL.WORKFLOW_APPROVED_FLAG%TYPE;
15237
15238 BEGIN
15239
15240 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start StoreNote');
15241
15242 IF (p_funmode = 'RUN') THEN
15243
15244 -------------------------------------------------------------------
15245 l_debug_info := 'Need to generate Note based on language setup';
15246 -------------------------------------------------------------------
15247
15248 -------------------------------------------------------------------
15249 l_debug_info := 'Save original language';
15250 -------------------------------------------------------------------
15251 l_orig_language_code := userenv('LANG');
15252 select nls_language
15253 into l_orig_language
15254 from fnd_languages
15255 where language_code = l_orig_language_code;
15256
15257 -------------------------------------------------------------------
15258 l_debug_info := 'Check AP_EXPENSE_PARAMS.NOTE_LANGUAGE_CODE';
15259 -------------------------------------------------------------------
15260 begin
15261 select note_language_code
15262 into l_new_language_code
15263 from ap_expense_params;
15264
15265 exception
15266 when no_data_found then
15267 null;
15268 end;
15269
15270 -------------------------------------------------------------------
15271 l_debug_info := 'Else use instance base language';
15272 -------------------------------------------------------------------
15273 if (l_new_language_code is null) then
15274 select language_code
15275 into l_new_language_code
15276 from fnd_languages
15277 where installed_flag in ('B');
15278 end if;
15279
15280 -------------------------------------------------------------------
15281 l_debug_info := 'Set nls context to new language';
15282 -------------------------------------------------------------------
15283 select nls_language
15284 into l_new_language
15285 from fnd_languages
15286 where language_code = l_new_language_code;
15287
15288 fnd_global.set_nls_context(p_nls_language => l_new_language);
15289
15290 -------------------------------------------------------------------
15291 l_debug_info := 'Retrieve Activity Result Type';
15292 -------------------------------------------------------------------
15293 l_result_type := WF_ENGINE.GetActivityAttrText(p_item_type,
15294 p_item_key,
15295 p_actid,
15296 'RESULT_TYPE');
15297
15298
15299 BEGIN
15300 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
15301 p_item_key,
15302 'EXPENSE_REPORT_ID');
15303
15304 SELECT approval_type, workflow_approved_flag INTO l_approval_type, l_workflow_flag
15305 FROM AP_EXPENSE_REPORT_HEADERS_ALL
15306 WHERE report_header_id = l_report_header_id;
15307 EXCEPTION
15308 WHEN OTHERS THEN
15309 l_approval_type := null;
15310 l_workflow_flag := null;
15311 END;
15312
15313 -------------------------------------------------------------------
15314 l_debug_info := 'Retrieve Note prefix';
15315 -------------------------------------------------------------------
15316 if (l_result_type = 'WFSTD_APPROVAL') then
15317 l_message_name := 'OIE_NOTES_APPROVER_ACTION';
15318 l_ame_enabled := nvl(WF_ENGINE.GetItemAttrText(p_item_type,
15319 p_item_key,
15320 'AME_ENABLED'),'N');
15321
15322 IF ( l_ame_enabled <> 'Y' ) THEN
15323
15324 BEGIN
15325 SELECT recipient_role INTO l_user_name
15326 FROM wf_notifications
15327 WHERE message_type = 'APEXP'
15328 AND message_name = 'OIE_REQ_EXPENSE_REPORT_APPRVL'
15329 AND ( item_key = p_item_key
15330 OR p_item_key = SubStr(context,7,length(p_item_key)) )
15331 AND status <> 'CANCELED';
15332
15333 AP_WEB_DB_HR_INT_PKG.GetUserIdFromName(l_user_name, l_entered_by);
15334 EXCEPTION
15335 WHEN OTHERS THEN
15336 l_entered_by := -1;
15337 END;
15338
15339 END IF;
15340
15341 IF ( l_ame_enabled = 'Y' OR l_entered_by = -1 ) THEN
15342 -- Bug: 12882504, Approval notes not displayed for non supervisory AME rules.
15343 IF(NVL(l_approval_type, 'X') <> 'PER') THEN
15344 l_entered_by := WF_ENGINE.GetItemAttrNumber(p_item_type,
15345 p_item_key,
15346 'APPROVER_ID');
15347 ELSE
15348 AP_WEB_OA_MAINFLOW_PKG.GetUserId(WF_ENGINE.GetItemAttrNumber(p_item_type,
15349 p_item_key,
15350 'APPROVER_ID'),
15351 l_entered_by);
15352 END IF;
15353
15354 END IF;
15355 elsif (l_result_type = 'EMPLOYEE_APPROVAL') then
15356 l_message_name := 'OIE_NOTES_EMPLOYEE_ACTION';
15357
15358 -- Bug# 15985613 - AUTHOR OF APPROVAL NOTIFICATION IS INCORRECT IN INTERNET EXPENSES HELP DESK
15359 -- AP_WEB_OA_MAINFLOW_PKG.GetUserId(WF_ENGINE.GetItemAttrNumber(p_item_type,
15360 -- p_item_key,
15361 -- 'EMPLOYEE_ID'),
15362 -- l_entered_by);
15363
15364 BEGIN
15365 SELECT recipient_role INTO l_user_name
15366 FROM wf_notifications
15367 WHERE message_type = 'APEXP'
15368 AND message_name = 'OIE_REQUEST_EMPLOYEE_APPROVAL'
15369 AND ( item_key = p_item_key
15370 OR p_item_key = SubStr(context,7,length(p_item_key)) )
15371 AND status <> 'CANCELED';
15372
15373 AP_WEB_DB_HR_INT_PKG.GetUserIdFromName(l_user_name, l_entered_by);
15374
15375 EXCEPTION
15376 WHEN OTHERS THEN
15377 L_ENTERED_BY := -1;
15378 END;
15379
15380 -- EMPLOYEE_APPROVAL is to be treated the same as WFSTD_APPROVAL
15381 l_result_type := 'WFSTD_APPROVAL';
15382 else
15383 l_message_name := 'OIE_NOTES_PREPARER_RESPONSE';
15384 AP_WEB_OA_MAINFLOW_PKG.GetUserId(WF_ENGINE.GetItemAttrNumber(p_item_type,
15385 p_item_key,
15386 'PREPARER_ID'),
15387 l_entered_by);
15388 end if;
15389
15390 begin
15391 -------------------------------------------------------------------
15392 -- fnd_global.set_nls_context() seems to work for WF but not FND_MESSAGES
15393 -------------------------------------------------------------------
15394 select message_text
15395 into l_note_prefix
15396 from fnd_new_messages
15397 where application_id = 200
15398 and message_name = l_message_name
15399 and language_code = l_new_language_code;
15400
15401 exception
15402 when no_data_found then
15403 FND_MESSAGE.SET_NAME('SQLAP', l_message_name);
15404 l_note_prefix := FND_MESSAGE.GET;
15405 end;
15406
15407 -------------------------------------------------------------------
15408 l_debug_info := 'Retrieve Activity Result Code';
15409 -------------------------------------------------------------------
15410 l_result_code := WF_ENGINE.GetActivityAttrText(p_item_type,
15411 p_item_key,
15412 p_actid,
15413 'RESULT_CODE');
15414
15415 -------------------------------------------------------------------
15416 l_debug_info := 'Retrieve Activity Response';
15417 -------------------------------------------------------------------
15418 l_response := WF_ENGINE.GetActivityAttrText(p_item_type,
15419 p_item_key,
15420 p_actid,
15421 'RESPONSE');
15422
15423 ------------------------------------------------------------
15424 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
15425 ------------------------------------------------------------
15426 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
15427 p_item_key,
15428 'EXPENSE_REPORT_ID');
15429
15430 -- Bug 12991336: Notes should not be created for shortpaid reports, when the auditor performs action before preparer
15431 IF (NOT(NVL(l_workflow_flag, 'M') IN ('R', 'Q', 'Y', 'P')
15432 AND ((l_result_type = 'AP_POLICY_SHORTPAY_RESPONSE' AND l_result_code = 'AP_PROVIDE MISSING_INFO')
15433 OR (l_result_type = 'APEXP_PREPARER_RESP_SHORTPAY' AND l_result_code = 'AP_WILL_SUBMIT')
15434 OR (l_result_type = 'MISSING_IMAGE_RESPONSE' AND l_result_code = 'WILL_SEND')))) THEN
15435
15436 ------------------------------------------------------------
15437 l_debug_info := 'Retrieve lookup display name';
15438 ------------------------------------------------------------
15439 WF_LOOKUP_TYPES_PUB.fetch_lookup_display(l_result_type,
15440 l_result_code,
15441 l_type_display_name,
15442 l_code_display_name);
15443
15444 ------------------------------------------------------------
15445 l_debug_info := 'store the result and response as a note';
15446 ------------------------------------------------------------
15447 AP_WEB_NOTES_PKG.CreateERPrepToAudNote (
15448 p_report_header_id => l_report_header_id,
15449 p_note => l_note_prefix||' '||l_code_display_name||'
15450 '||WF_ENGINE.GetItemAttrText(p_item_type, p_item_key, l_response),
15451 p_lang => l_new_language_code,
15452 p_entered_by => l_entered_by
15453 );
15454
15455 END IF;
15456
15457 -------------------------------------------------------------------
15458 l_debug_info := 'Restore nls context to original language';
15459 -------------------------------------------------------------------
15460 fnd_global.set_nls_context(p_nls_language => l_orig_language);
15461
15462 -------------------------------------------------------------------
15463 -- only clear audit issues if it is a preparer response
15464 -------------------------------------------------------------------
15465 if (l_result_type <> 'WFSTD_APPROVAL') then
15466 ------------------------------------------------------------
15467 l_debug_info := 'clear the header/line level return/audit reason/instructions in AERH/AERL';
15468 ------------------------------------------------------------
15469 AP_WEB_DB_EXPRPT_PKG.clearAuditReturnReasonInstr(l_report_header_id);
15470 AP_WEB_DB_EXPLINE_PKG.clearAuditReturnReasonInstr(l_report_header_id);
15471
15472 ----------------------------------------------------------
15473 l_debug_info := 'clear Item Attribute AUDIT_RETURN_REASON';
15474 ---------------------------------------------------------
15475 WF_ENGINE.SetItemAttrText(p_item_type,
15476 p_item_key,
15477 'AUDIT_RETURN_REASON',
15478 '');
15479
15480 ----------------------------------------------------------
15481 l_debug_info := 'Set Item Attribute AUDIT_INSTRUCTIONS';
15482 ---------------------------------------------------------
15483 WF_ENGINE.SetItemAttrText(p_item_type,
15484 p_item_key,
15485 'AUDIT_INSTRUCTIONS',
15486 '');
15487 end if;
15488
15489 p_result := 'COMPLETE:Y';
15490
15491 END IF;
15492
15493 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end StoreNote');
15494
15495 EXCEPTION
15496 WHEN OTHERS THEN
15497 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'StoreNote',
15498 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
15499 raise;
15500 END StoreNote;
15501
15502
15503 --------------------------------------------------------------------------
15504
15505 /*Written By: Amulya Mishra
15506 Purpose : Notification Escalation project.
15507 Gets job level from HR for a person.
15508 */
15509 ----------------------------------------------------------------------
15510
15511 PROCEDURE GetJobLevelAndSupervisor(
15512 p_personId IN NUMBER,
15513 p_jobLevel OUT NOCOPY NUMBER)
15514 IS
15515 ----------------------------------------------------------------------
15516
15517 BEGIN
15518 SELECT
15519 nvl(pj.approval_authority, 0)
15520 INTO p_jobLevel
15521 FROM
15522 per_jobs pj,
15523 per_all_assignments_f pa
15524 WHERE
15525 pj.job_id = pa.job_id
15526 AND pa.person_id = p_personId
15527 AND pa.primary_flag = 'Y'
15528 AND pa.assignment_type in ('E' , 'C') --Support Contingent Workres
15529 AND pa.assignment_status_type_id not in
15530 (select assignment_status_type_id
15531 from per_assignment_status_types
15532 where per_system_status = 'TERM_ASSIGN')
15533 AND trunc(sysdate) between pa.effective_start_date and pa.effective_end_date;
15534
15535 EXCEPTION
15536 WHEN OTHERS THEN
15537 p_jobLevel := 0;
15538 end GetJobLevelAndSupervisor;
15539 ----------------------------------------------------------------------------
15540
15541
15542 ----------------------------------------------------------------------
15543 PROCEDURE IsEmployeeTerminated(p_item_type IN VARCHAR2,
15544 p_item_key IN VARCHAR2,
15545 p_actid IN NUMBER,
15546 p_funmode IN VARCHAR2,
15547 p_result OUT NOCOPY VARCHAR2) IS
15548 ----------------------------------------------------------------------
15549 l_person_id NUMBER := NULL;
15550
15551 fixable_exception EXCEPTION;
15552 l_error_message VARCHAR2(2000);
15553 l_debug_info VARCHAR2(200);
15554
15555 BEGIN
15556
15557 IF (p_funmode = 'RUN') THEN
15558
15559 ---------------------------------------------------------------
15560 l_debug_info := 'Retrieve Employee Id Item Attribute';
15561 ---------------------------------------------------------------
15562 l_person_id := WF_ENGINE.GetItemAttrText(p_item_type,
15563 p_item_key,
15564 'EMPLOYEE_ID');
15565
15566 -- Check whether person is terminated
15567 IF (AP_WEB_DB_HR_INT_PKG.isPersonTerminated(l_person_id)='Y') THEN
15568 p_result := 'COMPLETE:Y';
15569 ELSE
15570 p_result := 'COMPLETE:N';
15571 END IF;
15572
15573 ELSIF (p_funmode = 'CANCEL') THEN
15574 NULL;
15575 END IF;
15576
15577 EXCEPTION
15578 WHEN OTHERS THEN
15579 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'IsPersonTerminated',
15580 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
15581 raise;
15582 END IsEmployeeTerminated;
15583
15584
15585 ----------------------------------------------------------------------
15586 PROCEDURE IsEmployeeActive(p_item_type IN VARCHAR2,
15587 p_item_key IN VARCHAR2,
15588 p_actid IN NUMBER,
15589 p_funmode IN VARCHAR2,
15590 p_result OUT NOCOPY VARCHAR2) IS
15591 ----------------------------------------------------------------------
15592 l_person_id NUMBER := NULL;
15593
15594 fixable_exception EXCEPTION;
15595 l_error_message VARCHAR2(2000);
15596 l_debug_info VARCHAR2(200);
15597
15598 BEGIN
15599
15600 IF (p_funmode = 'RUN') THEN
15601
15602 ---------------------------------------------------------------
15603 l_debug_info := 'Retrieve Employee Id Item Attribute';
15604 ---------------------------------------------------------------
15605 l_person_id := WF_ENGINE.GetItemAttrText(p_item_type,
15606 p_item_key,
15607 'EMPLOYEE_ID');
15608
15609 -- Check whether person is active
15610 IF (AP_WEB_DB_HR_INT_PKG.isPersonActive(l_person_id)='Y') THEN
15611 p_result := 'COMPLETE:Y';
15612 ELSE
15613 p_result := 'COMPLETE:N';
15614 END IF;
15615
15616 ELSIF (p_funmode = 'CANCEL') THEN
15617 NULL;
15618 END IF;
15619
15620 EXCEPTION
15621 WHEN OTHERS THEN
15622 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'IsEmployeeActive',
15623 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
15624 raise;
15625 END IsEmployeeActive;
15626
15627 ----------------------------------------------------------------------
15628 PROCEDURE IsManagerActive(p_item_type IN VARCHAR2,
15629 p_item_key IN VARCHAR2,
15630 p_actid IN NUMBER,
15631 p_funmode IN VARCHAR2,
15632 p_result OUT NOCOPY VARCHAR2) IS
15633 ----------------------------------------------------------------------
15634 l_person_id NUMBER := NULL;
15635
15636 fixable_exception EXCEPTION;
15637 l_error_message VARCHAR2(2000);
15638 l_debug_info VARCHAR2(200);
15639
15640 BEGIN
15641
15642 IF (p_funmode = 'RUN') THEN
15643
15644 ---------------------------------------------------------------
15645 l_debug_info := 'Retrieve Manager Id Item Attribute';
15646 ---------------------------------------------------------------
15647 l_person_id := WF_ENGINE.GetItemAttrText(p_item_type,
15648 p_item_key,
15649 'MANAGER_ID');
15650
15651 -- Check whether person is active
15652 IF (AP_WEB_DB_HR_INT_PKG.isPersonActive(l_person_id)='Y') THEN
15653 p_result := 'COMPLETE:Y';
15654 ELSE
15655 p_result := 'COMPLETE:N';
15656 END IF;
15657
15658 ELSIF (p_funmode = 'CANCEL') THEN
15659 NULL;
15660 END IF;
15661
15662 EXCEPTION
15663 WHEN OTHERS THEN
15664 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'IsManagerActive',
15665 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
15666 raise;
15667 END IsManagerActive;
15668
15669
15670 -- 3257576 - Gets the manager info and sets p_error_message, p_instructions
15671 -- p_special_instr if manager is terminated or does not exist or is suspended
15672 ---------------------------------------------------------------------------
15673 PROCEDURE GetManagerInfoAndCheckStatus(
15674 p_employee_id IN NUMBER,
15675 p_employee_name IN VARCHAR2,
15676 p_manager_id OUT NOCOPY NUMBER,
15677 p_manager_name OUT NOCOPY VARCHAR2,
15678 p_manager_status OUT NOCOPY VARCHAR2,
15679 p_error_message OUT NOCOPY VARCHAR2,
15680 p_instructions OUT NOCOPY VARCHAR2,
15681 p_special_instr OUT NOCOPY VARCHAR2) IS
15682 ---------------------------------------------------------------------------
15683 l_debug_info VARCHAR2(200);
15684 l_emp_info_rec AP_WEB_DB_HR_INT_PKG.EmployeeInfoRec;
15685 l_employee_name per_workforce_x.full_name%TYPE;
15686 BEGIN
15687
15688 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start GetManagerInfoAndCheckStatus');
15689
15690 -----------------------------------------------------------
15691 l_debug_info := 'Trying to retrieve employee manager info';
15692 -----------------------------------------------------------
15693 AP_WEB_DB_HR_INT_PKG.GetManagerIdAndStatus(
15694 p_employee_id,
15695 p_manager_id,
15696 p_manager_name,
15697 p_manager_status);
15698
15699 -----------------------------------------------------------------------
15700 l_debug_info := 'After GetManagerIdAndStatus ' || to_char(p_manager_id)
15701 || 'p_manager_status '||p_manager_status;
15702 -----------------------------------------------------------------------
15703
15704 IF (p_manager_id IS NULL) THEN
15705 IF (p_employee_name IS NULL) THEN
15706 IF AP_WEB_DB_HR_INT_PKG.GetEmployeeInfo(p_employee_id,l_emp_info_rec) THEN
15707 l_employee_name := l_emp_info_rec.employee_name;
15708 END IF;
15709 END IF;
15710 --------------------------------
15711 l_debug_info := 'No supervisor';
15712 --------------------------------
15713 FND_MESSAGE.Set_Name('SQLAP', 'OIE_NO_SUPERVISOR');
15714 FND_MESSAGE.Set_Token('EMPLOYEE_NAME', nvl(p_employee_name,l_employee_name));
15715 p_error_message := FND_MESSAGE.Get;
15716
15717 FND_MESSAGE.Set_Name('SQLAP', 'OIE_NO_APPROVER_INSTR1');
15718 p_instructions := FND_MESSAGE.Get;
15719
15720 FND_MESSAGE.Set_Name('SQLAP', 'OIE_NO_APPROVER_SPL_INSTR');
15721 p_special_instr := FND_MESSAGE.Get;
15722 ELSIF (p_manager_status = 'TERM_ASSIGN') THEN
15723 -----------------------------------------
15724 l_debug_info := 'Approver is terminated';
15725 -----------------------------------------
15726 FND_MESSAGE.Set_Name('SQLAP', 'OIE_APPROVER_TERMINATED');
15727 FND_MESSAGE.Set_Token('APPROVER_NAME', p_manager_name);
15728 p_error_message := FND_MESSAGE.Get;
15729
15730 FND_MESSAGE.Set_Name('SQLAP', 'OIE_NO_APPROVER_INSTR1');
15731 p_instructions := FND_MESSAGE.Get;
15732
15733 FND_MESSAGE.Set_Name('SQLAP', 'OIE_NO_APPROVER_SPL_INSTR');
15734 p_special_instr := FND_MESSAGE.Get;
15735 ELSIF ((p_manager_status = 'SUSP_ASSIGN') or
15736 (p_manager_status = 'SUSP_CWK_ASG')) THEN
15737 -----------------------------------------------------------
15738 l_debug_info := 'Approver is suspended/on temporary leave';
15739 -----------------------------------------------------------
15740 FND_MESSAGE.Set_Name('SQLAP', 'OIE_APPROVER_SUSPENDED');
15741 FND_MESSAGE.Set_Token('APPROVER_NAME', p_manager_name);
15742 p_error_message := FND_MESSAGE.Get;
15743
15744 FND_MESSAGE.Set_Name('SQLAP', 'OIE_NO_APPROVER_INSTR2');
15745 p_instructions := FND_MESSAGE.Get;
15746
15747 FND_MESSAGE.Set_Name('SQLAP', 'OIE_NO_APPROVER_SPL_INSTR');
15748 p_special_instr := FND_MESSAGE.Get;
15749 END IF;
15750
15751 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end GetManagerInfoAndCheckStatus');
15752
15753 EXCEPTION
15754 WHEN OTHERS THEN
15755 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'GetManagerInfoAndCheckStatus',
15756 null, null, null, l_debug_info);
15757 raise;
15758 END GetManagerInfoAndCheckStatus;
15759
15760 ----------------------------------------------------------------------------
15761 /* Written By : Amulya Mishra
15762 Bug 3389386: For Expense report with Both Pay only personal transactions,
15763 set the expense_status_code as PAID because the report gets
15764 automatically manager and payable approved and the header
15765 total is 0.
15766
15767 This is done inorder to avoid any usage of decode in files
15768 TrackExpenseReportsVO.xml and apwvw003.sql
15769 */
15770 ----------------------------------------------------------------------------
15771
15772 Procedure SetExpenseStatusCode(p_report_header_id IN Number)
15773 IS
15774 ----------------------------------------------------------------------------
15775 l_num_both_personal_lines NUMBER := 0;
15776
15777 BEGIN
15778
15779 IF (AP_WEB_DB_EXPLINE_PKG.GetNoOfBothPayPersonalLines(p_report_header_id,l_num_both_personal_lines)) THEN
15780 NULL;
15781 END IF;
15782
15783 IF l_num_both_personal_lines > 0 THEN
15784
15785 UPDATE AP_EXPENSE_REPORT_HEADERS
15786 SET EXPENSE_STATUS_CODE = 'PAID'
15787 WHERE REPORT_HEADER_ID = p_report_header_id;
15788
15789 END IF;
15790
15791
15792 END SetExpenseStatusCode;
15793 -----------------------------------------------------------------------------
15794
15795
15796 ----------------------------------------------------------------------------
15797 /* Written By : Amulya Mishra
15798 Bug 2777245: Update expense report header and lines data after submission
15799 through self-service and just before workflow kicks off.
15800
15801 Note: Customer can use this procedure to manipualte the values in
15802 Header and Lines table.
15803 */
15804 ----------------------------------------------------------------------------
15805
15806 Procedure UpdateHeaderLines(p_report_header_id IN Number)
15807 IS
15808 ----------------------------------------------------------------------------
15809
15810 BEGIN
15811
15812 UPDATE AP_EXPENSE_REPORT_HEADERS
15813 SET DESCRIPTION= AP_WEB_UTILITIES_PKG.RtrimMultiByteSpaces(description)
15814 WHERE REPORT_HEADER_ID = p_report_header_id;
15815
15816 UPDATE AP_EXPENSE_REPORT_LINES
15817 SET JUSTIFICATION = AP_WEB_UTILITIES_PKG.RtrimMultiByteSpaces(justification),
15818 SUBMITTED_AMOUNT = AMOUNT
15819 WHERE REPORT_HEADER_ID = p_report_header_id;
15820
15821
15822 -- Bug:12831314 Update the Expensditure Type and Expenditure Item Date
15823 BEGIN
15824
15825 UPDATE ap_expense_report_lines_all aerl
15826 SET expenditure_type =
15827 (SELECT pa_expenditure_type
15828 FROM ap_expense_report_params_all
15829 WHERE parameter_id = aerl.web_parameter_id
15830 ),
15831 expenditure_item_date = NVL(end_expense_date, start_expense_date)
15832 WHERE report_header_id = p_report_header_id
15833 AND expenditure_type IS NULL
15834 AND expenditure_item_date IS NULL
15835 AND EXISTS
15836 (SELECT project_id
15837 FROM ap_exp_report_dists_all
15838 WHERE report_line_id = aerl.report_line_id
15839 AND project_id IS NOT NULL
15840 );
15841 EXCEPTION
15842 WHEN OTHERS THEN
15843 NULL;
15844 END;
15845
15846 END UpdateHeaderLines;
15847
15848
15849 -----------------------------------------------------------------------------
15850 Procedure RaiseSubmitEvent(
15851 p_report_header_id IN Number,
15852 p_workflow_appr_flag IN VARCHAR2) IS
15853 ----------------------------------------------------------------------------
15854
15855 l_debug_info VARCHAR2(200);
15856
15857 l_user_id NUMBER;
15858 l_resp_id NUMBER;
15859 l_resp_appl_id NUMBER;
15860
15861 l_para_list WF_PARAMETER_LIST_T;
15862
15863 BEGIN
15864
15865 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start RaiseSubmitEvent');
15866
15867 ----------------------------------------------------------
15868 l_debug_info := 'Get USER_ID/RESP_ID/RESP_APPL_ID';
15869 ----------------------------------------------------------
15870 l_user_id := FND_PROFILE.VALUE('USER_ID');
15871 l_resp_id := FND_PROFILE.VALUE('RESP_ID');
15872 l_resp_appl_id := FND_PROFILE.VALUE('RESP_APPL_ID');
15873
15874 ----------------------------------------------------------
15875 l_debug_info := 'Add to event param list USER_ID/RESP_ID/RESP_APPL_ID';
15876 ----------------------------------------------------------
15877 wf_event.AddParameterToList(p_name =>'USER_ID',
15878 p_value =>l_user_id,
15879 p_parameterlist =>l_para_list);
15880
15881 wf_event.AddParameterToList(p_name =>'RESPONSIBILITY_ID',
15882 p_value =>l_resp_id,
15883 p_parameterlist =>l_para_list);
15884
15885 wf_event.AddParameterToList(p_name =>'APPLICATION_ID',
15886 p_value =>l_resp_appl_id,
15887 p_parameterlist =>l_para_list);
15888
15889 ----------------------------------------------------------
15890 l_debug_info := 'Raise Submit Event';
15891 ----------------------------------------------------------
15892 wf_event.raise(p_event_name => C_SUBMIT_EVENT_NAME,
15893 p_event_key => p_report_header_id,
15894 p_parameters => l_para_list);
15895
15896 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end RaiseSubmitEvent');
15897
15898 EXCEPTION
15899 WHEN OTHERS THEN
15900
15901 -- bug 2203689, set workflow_approved_flag to S so that users can
15902 -- re-submit the report without re-entering data again
15903
15904 -- Bug 3248874 : Also set expense_status_code as NULL.
15905 -- Source as NonValidateWebExpense.
15906
15907 UPDATE ap_expense_report_headers erh
15908 SET workflow_approved_flag = 'S',
15909 expense_status_code = null,
15910 source = 'NonValidatedWebExpense'
15911 WHERE report_header_id = p_report_header_id;
15912 COMMIT;
15913
15914
15915 IF (SQLCODE <> -20001) THEN
15916 FND_MESSAGE.SET_NAME('SQLAP','AP_DEBUG');
15917 FND_MESSAGE.SET_TOKEN('ERROR',SQLERRM);
15918 FND_MESSAGE.SET_TOKEN('CALLING_SEQUENCE', 'RaiseSubmitEvent');
15919 FND_MESSAGE.SET_TOKEN('DEBUG_INFO',l_debug_info);
15920 END IF;
15921
15922 -- always raise exceptions regardless it from RaiseSubmitEvent
15923 -- or other callees
15924 APP_EXCEPTION.RAISE_EXCEPTION;
15925
15926 END RaiseSubmitEvent;
15927
15928
15929 ----------------------------------------------------------------------
15930 PROCEDURE InitSubmit(
15931 p_item_type IN VARCHAR2,
15932 p_item_key IN VARCHAR2,
15933 p_actid IN NUMBER,
15934 p_funmode IN VARCHAR2,
15935 p_result IN OUT NOCOPY VARCHAR2) IS
15936 ----------------------------------------------------------------------
15937
15938 l_debug_info VARCHAR2(200);
15939
15940 l_report_header_id ap_expense_report_headers.report_header_id%type;
15941 l_preparer_id ap_expense_report_headers.employee_id%type;
15942 l_employee_id ap_expense_report_headers.employee_id%type;
15943 l_document_number ap_expense_report_headers.invoice_num%type;
15944 l_total ap_expense_report_lines.amount%type;
15945 l_new_total ap_expense_report_lines.amount%type;
15946 l_reimb_curr ap_expense_report_headers.default_currency_code%type;
15947 l_cost_center ap_expense_report_headers.flex_concatenated%type;
15948 l_purpose ap_expense_report_headers.description%type;
15949 l_approver_id ap_expense_report_headers.override_approver_id%type;
15950 l_week_end_date ap_expense_report_headers.week_end_date%type;
15951 l_workflow_flag ap_expense_report_headers.workflow_approved_flag%type;
15952 l_submit_from_oie varchar2(1);
15953
15954 BEGIN
15955
15956 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start InitSubmit');
15957
15958 l_report_header_id := to_number(p_item_key);
15959
15960 select aerh.report_header_id,
15961 fnd.employee_id,
15962 aerh.employee_id,
15963 aerh.invoice_num,
15964 aerh.default_currency_code,
15965 aerh.flex_concatenated,
15966 aerh.description,
15967 aerh.override_approver_id,
15968 aerh.week_end_date,
15969 aerh.workflow_approved_flag
15970 into l_report_header_id,
15971 l_preparer_id,
15972 l_employee_id,
15973 l_document_number,
15974 l_reimb_curr,
15975 l_cost_center,
15976 l_purpose,
15977 l_approver_id,
15978 l_week_end_date,
15979 l_workflow_flag
15980 from ap_expense_report_headers aerh,
15981 fnd_user fnd
15982 where aerh.report_header_id = l_report_header_id
15983 and fnd.user_id = aerh.created_by;
15984
15985 select sum(aerl.amount),
15986 sum(decode(sign(aerl.amount),-1,0,aerl.amount))
15987 into l_total,
15988 l_new_total
15989 from ap_expense_report_lines aerl
15990 where aerl.report_header_id = l_report_header_id
15991 and (itemization_parent_id is null OR itemization_parent_id <> -1);
15992
15993 StartExpenseReportProcess(
15994 l_report_header_id,
15995 l_preparer_id,
15996 l_employee_id,
15997 l_document_number,
15998 l_total,
15999 l_new_total,
16000 l_reimb_curr,
16001 l_cost_center,
16002 l_purpose,
16003 l_approver_id,
16004 l_week_end_date,
16005 l_workflow_flag,
16006 p_submit_from_oie => 'Y',
16007 p_event_raised => 'Y');
16008
16009 p_result := 'COMPLETE';
16010
16011 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end InitSubmit');
16012
16013 EXCEPTION
16014 WHEN OTHERS THEN
16015 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'InitSubmit',
16016 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
16017 raise;
16018 END InitSubmit;
16019
16020 ------------------------------------------------------------------------
16021 FUNCTION CheckAccess(
16022 p_ntf_id IN NUMBER,
16023 p_item_key IN NUMBER,
16024 p_user_name IN VARCHAR2) RETURN VARCHAR2
16025 ------------------------------------------------------------------------
16026 IS
16027
16028 l_item_type wf_items.item_type%type;
16029 l_item_key wf_items.item_key%type;
16030 l_temp_item_key wf_items.item_key%type;
16031 l_access_granted varchar2(1) := 'N';
16032 l_user_name wf_notifications.recipient_role%type;
16033
16034 BEGIN
16035
16036 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start CheckAccess');
16037
16038 -- get the item type for the notif
16039 select message_type, item_key
16040 into l_item_type, l_temp_item_key
16041 from wf_notifications
16042 where notification_id = p_ntf_id
16043 and rownum = 1;
16044
16045 -- check the following:
16046 -- 1. NtfId is valid for ReportHeaderId
16047 if (l_item_type = 'APEXP') then
16048 --Bug 4425821: Uptake AME parallel approvers
16049 BEGIN
16050 select 'Y'
16051 into l_access_granted
16052 from wf_item_activity_statuses
16053 where item_type = l_item_type
16054 and ((item_key = to_char(p_item_key)) or (item_key like to_char(p_item_key) || '-%'))
16055 and notification_id = p_ntf_id
16056 and rownum = 1;
16057 EXCEPTION WHEN NO_DATA_FOUND THEN
16058 select 'Y'
16059 into l_access_granted
16060 from wf_item_activity_statuses_h
16061 where item_type = l_item_type
16062 and ((item_key = to_char(p_item_key)) or (item_key like to_char(p_item_key) || '-%'))
16063 and notification_id = p_ntf_id
16064 and rownum = 1;
16065 END;
16066
16067 elsif (l_item_type = 'APWHOLDS') then
16068
16069 BEGIN
16070 select item_key
16071 into l_item_key
16072 from wf_item_activity_statuses
16073 where item_type = l_item_type
16074 and notification_id = p_ntf_id
16075 and rownum = 1;
16076 EXCEPTION WHEN NO_DATA_FOUND THEN
16077 select item_key
16078 into l_item_key
16079 from wf_item_activity_statuses_h
16080 where item_type = l_item_type
16081 and notification_id = p_ntf_id
16082 and rownum = 1;
16083 END;
16084
16085 select 'Y'
16086 into l_access_granted
16087 from dual
16088 where
16089 (p_item_key = WF_ENGINE.GetItemAttrNumber(l_item_type, l_item_key, 'EXPENSE_REPORT_ID')
16090 or
16091 p_item_key = WF_ENGINE.GetItemAttrNumber(l_item_type, l_item_key, 'HOLDING_EXPENSE_REPORT_ID'))
16092 and rownum = 1;
16093
16094 elsif (l_item_type = 'APWRECPT') then
16095 -- Modified for CISCO ER 8704387
16096 BEGIN
16097 select 'Y'
16098 into l_access_granted
16099 from wf_item_activity_statuses
16100 where item_type = l_item_type
16101 and ((item_key like '%'||to_char(p_item_key)||'%') or (item_key = l_temp_item_key))
16102 and notification_id = p_ntf_id
16103 and rownum = 1;
16104 EXCEPTION WHEN NO_DATA_FOUND THEN
16105 select 'Y'
16106 into l_access_granted
16107 from wf_item_activity_statuses_h
16108 where item_type = l_item_type
16109 and ((item_key like '%'||to_char(p_item_key)||'%') or (item_key = l_temp_item_key))
16110 and notification_id = p_ntf_id
16111 and rownum = 1;
16112 END;
16113 else
16114
16115 -- No Access
16116 RETURN l_access_granted;
16117
16118 end if;
16119
16120 /* bug 5360860: comment out as per wf dev product teams need not make this check
16121 as the check is already performed by Workflow UI and Workflow Mailer doesn't
16122 sends any emails to proxy user for the notification recieved by the originial
16123 recipient. */
16124 /*
16125 -- 2. User has access to the NtfId
16126 select 'Y'
16127 into l_access_granted
16128 from wf_notifications wfn ,
16129 WF_USER_ROLES wur
16130 where wur.user_name = p_user_name
16131 and wfn.notification_id = p_ntf_id
16132 and ( wfn.recipient_role = wur.role_name
16133 OR
16134 ( wfn.more_info_role is not null and wfn.more_info_role = wur.role_name )
16135 OR
16136 ( wfn.from_role is not null and wfn.from_role = wur.role_name ) )
16137 and rownum = 1;
16138 */
16139
16140 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end CheckAccess');
16141
16142 RETURN l_access_granted;
16143
16144 EXCEPTION
16145 WHEN NO_DATA_FOUND THEN
16146 RETURN 'N';
16147 WHEN OTHERS THEN
16148 RETURN 'N';
16149 END CheckAccess;
16150
16151 /*
16152 Bug 4425821: Uptake AME parallel approvers
16153 Called from AME Approval Process.
16154 Gets the next set of approvers, checks if Approval is complete,
16155 If yes return
16156 else spans 'AME Request Approval Process', copies attibute values from AME APproval
16157 process' to render the notification.
16158 */
16159 ----------------------------------------------------------------------
16160 PROCEDURE AMERequestApproval(p_item_type IN VARCHAR2,
16161 p_item_key IN VARCHAR2,
16162 p_actid IN NUMBER,
16163 p_funmode IN VARCHAR2,
16164 p_result OUT NOCOPY VARCHAR2) IS
16165 ----------------------------------------------------------------------
16166
16167 l_debug_info varchar2(200);
16168
16169 l_approvalProcessCompleteYNOut varchar2(1);
16170 l_nextApproversOut ame_util.approversTable2;
16171
16172 l_childItemKeySeq number;
16173 l_childItemKey wf_items.item_key%type;
16174 l_child_item_key wf_items.item_key%type;
16175 l_masterUserKey wf_items.user_key%type;
16176
16177 l_manager_name wf_users.name%type;
16178 l_manager_display_name wf_users.display_name%type;
16179
16180 l_master_report_id number;
16181
16182 fixable_exception EXCEPTION;
16183 continue_exception EXCEPTION;
16184 l_error_message VARCHAR2(2000);
16185 l_instructions fnd_new_messages.message_text%type;
16186 l_special_instr fnd_new_messages.message_text%type;
16187 l_no_notif CONSTANT VARCHAR2(20) := 'NO_NOTIFICATION';
16188 l_payment VARCHAR2(20);
16189 l_num_personal_lines NUMBER := 0;
16190 l_employee_id NUMBER;
16191 l_continue BOOLEAN := TRUE;
16192 l_wf_active BOOLEAN := FALSE;
16193 l_wf_exist BOOLEAN := FALSE;
16194 l_end_date wf_notifications.end_date%TYPE;
16195 l_approver_exist varchar2(1) := 'N'; -- Bug 15928430
16196
16197 BEGIN
16198
16199 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start AMERequestApproval');
16200
16201 IF (p_funmode = 'RUN') THEN
16202
16203 if (AP_WEB_DB_EXPLINE_PKG.GetNoOfBothPayPersonalLines(p_item_key,l_num_personal_lines)) then
16204 null;
16205 end if;
16206
16207 ----------------------------------------------------------------
16208 l_debug_info := 'Retrieve Profile Option Payment Due From';
16209 ----------------------------------------------------------------
16210 IF (NOT AP_WEB_DB_EXPRPT_PKG.getPaymentDueFromReport(p_item_key,l_payment)) THEN
16211 l_debug_info := 'Could not set workflow attribute Payment_Due_From';
16212 END IF;
16213
16214 IF (l_payment = 'BOTH' and l_num_personal_lines > 0 ) THEN
16215 p_result := 'COMPLETE:' || l_no_notif;
16216 return;
16217 END IF;
16218
16219 -------------------------------------------------
16220 l_debug_info := 'Call AMEs getNextApprovers4 api';
16221 -------------------------------------------------
16222 BEGIN
16223 AME_API2.getNextApprovers4(applicationIdIn => AP_WEB_DB_UTIL_PKG.GetApplicationID,
16224 transactionTypeIn => p_item_type,
16225 transactionIdIn => p_item_key,
16226 approvalProcessCompleteYNOut => l_approvalProcessCompleteYNOut,
16227 nextApproversOut => l_nextApproversOut);
16228 EXCEPTION
16229 when others then
16230 FND_MESSAGE.Set_Name('SQLAP', 'OIE_GETNEXTAPPROVER_ERROR');
16231 l_error_message := FND_MESSAGE.Get;
16232 -- bug 3257576
16233 FND_MESSAGE.Set_Name('SQLAP', 'OIE_NO_APPROVER_INSTR4');
16234 l_instructions := FND_MESSAGE.Get;
16235 raise fixable_exception ;
16236 END;
16237
16238 l_childItemKeySeq := WF_ENGINE.GetItemAttrNumber(p_item_type,
16239 p_item_key,
16240 'AME_CHILD_ITEM_KEY_SEQ');
16241
16242 IF (l_approvalProcessCompleteYNOut = ame_util.booleanTrue) THEN
16243 BEGIN
16244 -- Bug 8490741: To cancel other active approval processes
16245 IF (l_childItemKeySeq IS NOT NULL AND l_childItemKeySeq > 0) THEN
16246 FOR i in 1 .. l_childItemKeySeq LOOP
16247 l_child_item_key := p_item_key || '-' || to_char(i);
16248 begin
16249 select end_date
16250 into l_end_date
16251 from wf_notifications
16252 where message_type = 'APEXP'
16253 and message_name = 'OIE_AME_EXPENSE_REPORT_APPRVL'
16254 and item_key = l_child_item_key;
16255 if l_end_date is NULL then
16256 l_wf_active := TRUE;
16257 else
16258 l_wf_active := FALSE;
16259 end if;
16260 l_wf_exist := TRUE;
16261 exception
16262 when no_data_found then
16263 l_wf_active := FALSE;
16264 l_wf_exist := FALSE;
16265 end;
16266 IF l_wf_exist THEN
16267 IF l_wf_active THEN
16268 wf_engine.AbortProcess (itemtype => 'APEXP',
16269 itemkey => l_child_item_key,
16270 cascade => TRUE);
16271 END IF;
16272 END IF;
16273 END LOOP;
16274 END IF;
16275 EXCEPTION
16276 WHEN OTHERS THEN
16277 NULL;
16278 END;
16279 p_result := 'COMPLETE:Y';
16280 return;
16281 ELSIF (l_approvalProcessCompleteYNOut = ame_util2.completeNoApprovers) THEN
16282 p_result := 'COMPLETE:NOAPPROVER';
16283 return;
16284 END IF;
16285
16286 /*l_childItemKeySeq := WF_ENGINE.GetItemAttrNumber(p_item_type,
16287 p_item_key,
16288 'AME_CHILD_ITEM_KEY_SEQ');*/
16289
16290 FOR i IN 1 .. l_nextApproversOut.count LOOP
16291 l_approver_exist := 'Y';
16292 -- Bug: 11848839
16293 l_employee_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
16294 p_item_key,
16295 'EMPLOYEE_ID');
16296 -- Bug:14106331, Do not raise an error for FYI notifications.
16297 IF (l_nextApproversOut(i).orig_system = 'PER' AND (l_employee_id = l_nextApproversOut(i).orig_system_id)
16298 AND (NVL(l_nextApproversOut(i).approver_category,'A') <> 'F')) THEN
16299 ---------------------------------------------
16300 l_debug_info := 'Loop in Approval Hierarchy';
16301 ---------------------------------------------
16302 IF(AP_WEB_CUST_DFLEX_PKG.CustomApprovalStatus(p_item_key, l_employee_id,
16303 l_nextApproversOut(i).orig_system_id, l_continue) = FALSE) THEN
16304 IF(l_continue = TRUE) THEN
16305 FND_MESSAGE.Set_Name('SQLAP', 'AP_WEB_APRVL_HIERARCHY_LOOP');
16306 l_error_message := FND_MESSAGE.Get;
16307 FND_MESSAGE.Set_Name('SQLAP', 'OIE_NO_APPROVER_INSTR6');
16308 l_instructions := FND_MESSAGE.Get;
16309 FND_MESSAGE.Set_Name('SQLAP', 'OIE_NO_APPROVER_SPL_INSTR');
16310 l_special_instr := FND_MESSAGE.Get;
16311 raise fixable_exception ;
16312 ELSE
16313 raise continue_exception;
16314 END IF;
16315 END IF;
16316 END IF;
16317 IF (l_childItemKeySeq is null) THEN
16318 l_childItemKeySeq := 1;
16319 ELSE
16320 l_childItemKeySeq := l_childItemKeySeq + 1;
16321 END IF;
16322
16323 l_childItemKey := p_item_key || '-' || to_char(l_childItemKeySeq);
16324
16325 WF_ENGINE.CreateProcess(p_item_type,
16326 l_childItemKey,
16327 'AME_REQUEST_APPROVAL_PROCESS');
16328
16329 l_masterUserKey := WF_ENGINE.GetItemUserKey(p_item_type,
16330 p_item_key);
16331
16332 WF_ENGINE.SetItemUserKey(p_item_type,
16333 l_childItemKey,
16334 l_masterUserKey);
16335
16336
16337 if (l_nextApproversOut(i).orig_system = 'PER') then
16338 WF_DIRECTORY.GetUserName(l_nextApproversOut(i).orig_system,
16339 l_nextApproversOut(i).orig_system_id,
16340 l_manager_name,
16341 l_manager_display_name);
16342 else
16343 -- 6143415: To support position hierarchy
16344 WF_DIRECTORY.GetRoleName(l_nextApproversOut(i).orig_system,
16345 l_nextApproversOut(i).orig_system_id,
16346 l_manager_name,
16347 l_manager_display_name);
16348 end if;
16349
16350 --------------------------------------------------------
16351 l_debug_info := 'Set Approver_ID Info Item Attribute';
16352 --------------------------------------------------------
16353 WF_ENGINE.SetItemAttrText(p_item_type,
16354 l_childItemKey,
16355 'APPROVER_ID',
16356 l_nextApproversOut(i).orig_system_id);
16357
16358 --------------------------------------------------------
16359 l_debug_info := 'Set Approver_Name Info Item Attribute';
16360 --------------------------------------------------------
16361 WF_ENGINE.SetItemAttrText(p_item_type,
16362 l_childItemKey,
16363 'APPROVER_NAME',
16364 l_manager_name);
16365
16366 ----------------------------------------------------------------
16367 l_debug_info := 'Set Approver_Display_Name Info Item Attribute';
16368 ----------------------------------------------------------------
16369 WF_ENGINE.SetItemAttrText(p_item_type,
16370 l_childItemKey,
16371 'APPROVER_DISPLAY_NAME',
16372 l_manager_display_name);
16373 ----------------------------------------------------------------
16374 -- Bug 7272553: Store approver authority, used during reassign
16375 l_debug_info := 'Set Approver_Authority Info Item Attribute';
16376 ----------------------------------------------------------------
16377 begin
16378 WF_ENGINE.SetItemAttrText(p_item_type,
16379 l_childItemKey,
16380 'AME_APPROVER_AUTHORITY',
16381 l_nextApproversOut(i).authority);
16382 exception
16383 when others then
16384 if (wf_core.error_name = 'WFENG_ITEM_ATTR') then
16385 -- AME_APPROVER_AUTHORITY item attribute doesn't exist, need to add it
16386 WF_ENGINE.AddItemAttr(p_item_type, l_childItemKey, 'AME_APPROVER_AUTHORITY');
16387 WF_ENGINE.SetItemAttrNumber(p_item_type,
16388 l_childItemKey,
16389 'AME_APPROVER_AUTHORITY',
16390 l_nextApproversOut(i).authority);
16391 else
16392 raise;
16393 end if;
16394 end;
16395
16396 l_master_report_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
16397 p_item_key,
16398 'EXPENSE_REPORT_ID');
16399
16400
16401 WF_ENGINE.SetItemAttrText(p_item_type,
16402 l_childItemKey,
16403 'AME_MASTER_ITEM_KEY',
16404 p_item_key);
16405
16406 WF_ENGINE.SetItemAttrText(p_item_type,
16407 l_childItemKey,
16408 'AME_APPROVAL_TYPE',
16409 l_nextApproversOut(i).approver_category);
16410
16411 ----------------------------------------------------------------
16412 l_debug_info := 'Set wf attributes from the master process';
16413 ----------------------------------------------------------------
16414 BEGIN
16415 WF_ENGINE.SetItemAttrNumber(p_item_type,
16416 l_childItemKey,
16417 'ORG_ID',
16418 WF_ENGINE.GetItemAttrNumber(p_item_type,
16419 p_item_key,
16420 'ORG_ID'));
16421
16422 WF_ENGINE.SetItemAttrNumber(p_item_type,
16423 l_childItemKey,
16424 'USER_ID',
16425 WF_ENGINE.GetItemAttrNumber(p_item_type,
16426 p_item_key,
16427 'USER_ID'));
16428
16429 WF_ENGINE.SetItemAttrNumber(p_item_type,
16430 l_childItemKey,
16431 'RESPONSIBILITY_ID',
16432 WF_ENGINE.GetItemAttrNumber(p_item_type,
16433 p_item_key,
16434 'RESPONSIBILITY_ID'));
16435
16436 WF_ENGINE.SetItemAttrNumber(p_item_type,
16437 l_childItemKey,
16438 'APPLICATION_ID',
16439 WF_ENGINE.GetItemAttrNumber(p_item_type,
16440 p_item_key,
16441 'APPLICATION_ID'));
16442 EXCEPTION
16443 WHEN OTHERS THEN
16444 if (wf_core.error_name = 'WFENG_ITEM_ATTR') then
16445 null;
16446 else
16447 raise;
16448 end if;
16449 END;
16450
16451 -- Bug: 7649190, Purpose not shown in the manager approval notification when AME is enabled
16452 WF_ENGINE.SetItemAttrText(p_item_type,
16453 l_childItemKey,
16454 'PURPOSE',
16455 WF_ENGINE.GetItemAttrText(p_item_type,
16456 p_item_key,
16457 'PURPOSE'));
16458 WF_ENGINE.SetItemAttrText(p_item_type,
16459 l_childItemKey,
16460 'AME_ENABLED',
16461 WF_ENGINE.GetItemAttrText(p_item_type,
16462 p_item_key,
16463 'AME_ENABLED'));
16464
16465 WF_ENGINE.SetItemAttrText(p_item_type,
16466 l_childItemKey,
16467 'WITHDRAW_WARNING',
16468 WF_ENGINE.GetItemAttrText(p_item_type,
16469 p_item_key,
16470 'WITHDRAW_WARNING'));
16471
16472 WF_ENGINE.SetItemAttrText(p_item_type,
16473 l_childItemKey,
16474 'GRANTS_ENABLED',
16475 WF_ENGINE.GetItemAttrText(p_item_type,
16476 p_item_key,
16477 'GRANTS_ENABLED'));
16478
16479 WF_ENGINE.SetItemAttrText(p_item_type,
16480 l_childItemKey,
16481 'LINE_TABLE',
16482 WF_ENGINE.GetItemAttrText(p_item_type,
16483 p_item_key,
16484 'LINE_TABLE'));
16485
16486 WF_ENGINE.SetItemAttrText(p_item_type,
16487 l_childItemKey,
16488 'EMP_LINE_TABLE',
16489 WF_ENGINE.GetItemAttrText(p_item_type,
16490 p_item_key,
16491 'EMP_LINE_TABLE'));
16492
16493 WF_ENGINE.SetItemAttrNumber(p_item_type,
16494 l_childItemKey,
16495 'EXPENSE_REPORT_ID',
16496 WF_ENGINE.GetItemAttrNumber(p_item_type,
16497 p_item_key,
16498 'EXPENSE_REPORT_ID'));
16499
16500 WF_ENGINE.SetItemAttrText(p_item_type,
16501 l_childItemKey,
16502 'DOCUMENT_NUMBER',
16503 WF_ENGINE.GetItemAttrText(p_item_type,
16504 p_item_key,
16505 'DOCUMENT_NUMBER'));
16506
16507 WF_ENGINE.SetItemAttrNumber(p_item_type,
16508 l_childItemKey,
16509 'PREPARER_ID',
16510 WF_ENGINE.GetItemAttrNumber(p_item_type,
16511 p_item_key,
16512 'PREPARER_ID'));
16513
16514 WF_ENGINE.SetItemAttrText(p_item_type,
16515 l_childItemKey,
16516 'PREPARER_NAME',
16517 WF_ENGINE.GetItemAttrText(p_item_type,
16518 p_item_key,
16519 'PREPARER_NAME'));
16520
16521 WF_ENGINE.SetItemAttrText(p_item_type,
16522 l_childItemKey,
16523 'PREPARER_DISPLAY_NAME',
16524 WF_ENGINE.GetItemAttrText(p_item_type,
16525 p_item_key,
16526 'PREPARER_DISPLAY_NAME'));
16527
16528 WF_ENGINE.SetItemAttrNumber(p_item_type,
16529 l_childItemKey,
16530 'EMPLOYEE_ID',
16531 WF_ENGINE.GetItemAttrNumber(p_item_type,
16532 p_item_key,
16533 'EMPLOYEE_ID'));
16534
16535 WF_ENGINE.SetItemAttrText(p_item_type,
16536 l_childItemKey,
16537 'EMPLOYEE_NAME',
16538 WF_ENGINE.GetItemAttrText(p_item_type,
16539 p_item_key,
16540 'EMPLOYEE_NAME'));
16541
16542 WF_ENGINE.SetItemAttrText(p_item_type,
16543 l_childItemKey,
16544 'EMPLOYEE_DISPLAY_NAME',
16545 WF_ENGINE.GetItemAttrText(p_item_type,
16546 p_item_key,
16547 'EMPLOYEE_DISPLAY_NAME'));
16548
16549 WF_ENGINE.SetItemAttrText(p_item_type,
16550 l_childItemKey,
16551 'PAYMENT_DUE_FROM',
16552 WF_ENGINE.GetItemAttrText(p_item_type,
16553 p_item_key,
16554 'PAYMENT_DUE_FROM'));
16555
16556 WF_ENGINE.SetItemAttrNumber(p_item_type,
16557 l_childItemKey,
16558 'TOTAL',
16559 WF_ENGINE.GetItemAttrNumber(p_item_type,
16560 p_item_key,
16561 'TOTAL'));
16562
16563 WF_ENGINE.SetItemAttrText(p_item_type,
16564 l_childItemKey,
16565 'DISPLAY_TOTAL',
16566 WF_ENGINE.GetItemAttrText(p_item_type,
16567 p_item_key,
16568 'DISPLAY_TOTAL'));
16569
16570 WF_ENGINE.SetItemAttrDate(p_item_type,
16571 l_childItemKey,
16572 'WEEK_END_DATE',
16573 WF_ENGINE.GetItemAttrDate(p_item_type,
16574 p_item_key,
16575 'WEEK_END_DATE'));
16576
16577 WF_ENGINE.SetItemAttrText(p_item_type,
16578 l_childItemKey,
16579 'EMPLOYEE_PROJECT_ENABLED',
16580 WF_ENGINE.GetItemAttrText(p_item_type,
16581 p_item_key,
16582 'EMPLOYEE_PROJECT_ENABLED'));
16583
16584 WF_ENGINE.SetItemAttrText(p_item_type,
16585 l_childItemKey,
16586 'CURRENCY',
16587 WF_ENGINE.GetItemAttrText(p_item_type,
16588 p_item_key,
16589 'CURRENCY'));
16590
16591 WF_ENGINE.SetItemAttrText(p_item_type,
16592 l_childItemKey,
16593 'DOC_COST_CENTER',
16594 WF_ENGINE.GetItemAttrText(p_item_type,
16595 p_item_key,
16596 'DOC_COST_CENTER'));
16597
16598 WF_ENGINE.SetItemAttrText(p_item_type,
16599 l_childItemKey,
16600 'EMP_COST_CENTER',
16601 WF_ENGINE.GetItemAttrText(p_item_type,
16602 p_item_key,
16603 'EMP_COST_CENTER'));
16604
16605 WF_ENGINE.SetItemAttrText(p_item_type,
16606 l_childItemKey,
16607 'HEADER_ATTACHMENTS',
16608 WF_ENGINE.GetItemAttrText(p_item_type,
16609 p_item_key,
16610 'HEADER_ATTACHMENTS'));
16611
16612 WF_ENGINE.SetItemAttrText(p_item_type,
16613 l_childItemKey,
16614 'SUBMIT_FROM_OIE',
16615 WF_ENGINE.GetItemAttrText(p_item_type,
16616 p_item_key,
16617 'SUBMIT_FROM_OIE'));
16618
16619 WF_ENGINE.SetItemAttrText(p_item_type,
16620 l_childItemKey,
16621 'EXPENSE_DETAILS',
16622 WF_ENGINE.GetItemAttrText(p_item_type,
16623 p_item_key,
16624 'EXPENSE_DETAILS'));
16625
16626 WF_ENGINE.SetItemAttrText(p_item_type,
16627 l_childItemKey,
16628 'EMP_VIOLATION_NOTE',
16629 WF_ENGINE.GetItemAttrText(p_item_type,
16630 p_item_key,
16631 'EMP_VIOLATION_NOTE'));
16632
16633 WF_ENGINE.SetItemAttrText(p_item_type,
16634 l_childItemKey,
16635 'VIOLATION_NOTE',
16636 WF_ENGINE.GetItemAttrText(p_item_type,
16637 p_item_key,
16638 'VIOLATION_NOTE'));
16639
16640 WF_ENGINE.SetItemAttrText(p_item_type,
16641 l_childItemKey,
16642 'MILEAGE_NOTE',
16643 WF_ENGINE.GetItemAttrText(p_item_type,
16644 p_item_key,
16645 'MILEAGE_NOTE'));
16646
16647 WF_ENGINE.SetItemAttrText(p_item_type,
16648 l_childItemKey,
16649 'VERIFY_NOTE',
16650 WF_ENGINE.GetItemAttrText(p_item_type,
16651 p_item_key,
16652 'VERIFY_NOTE'));
16653
16654 WF_ENGINE.SetItemAttrText(p_item_type,
16655 l_childItemKey,
16656 'AUDIT_RETURN_REASON',
16657 WF_ENGINE.GetItemAttrText(p_item_type,
16658 p_item_key,
16659 'AUDIT_RETURN_REASON'));
16660
16661 WF_ENGINE.SetItemAttrText(p_item_type,
16662 l_childItemKey,
16663 'AUDIT_INSTRUCTIONS',
16664 WF_ENGINE.GetItemAttrText(p_item_type,
16665 p_item_key,
16666 'AUDIT_INSTRUCTIONS'));
16667
16668 WF_ENGINE.SetItemAttrText(p_item_type,
16669 l_childItemKey,
16670 'CASH_LINE_ERRORS_AP',
16671 WF_ENGINE.GetItemAttrText(p_item_type,
16672 p_item_key,
16673 'CASH_LINE_ERRORS_AP'));
16674
16675 WF_ENGINE.SetItemAttrText(p_item_type,
16676 l_childItemKey,
16677 'CASH_LINE_ERRORS_PREPARER',
16678 WF_ENGINE.GetItemAttrText(p_item_type,
16679 p_item_key,
16680 'CASH_LINE_ERRORS_PREPARER'));
16681
16682 WF_ENGINE.SetItemAttrText(p_item_type,
16683 l_childItemKey,
16684 'CCARD_LINE_ERRORS_AP',
16685 WF_ENGINE.GetItemAttrText(p_item_type,
16686 p_item_key,
16687 'CCARD_LINE_ERRORS_AP'));
16688
16689 WF_ENGINE.SetItemAttrText(p_item_type,
16690 l_childItemKey,
16691 'CCARD_LINE_ERRORS_PREPARER',
16692 WF_ENGINE.GetItemAttrText(p_item_type,
16693 p_item_key,
16694 'CCARD_LINE_ERRORS_PREPARER'));
16695
16696 WF_ENGINE.SetItemAttrText(p_item_type,
16697 l_childItemKey,
16698 'GEN_HEADER_ERRORS',
16699 WF_ENGINE.GetItemAttrText(p_item_type,
16700 p_item_key,
16701 'GEN_HEADER_ERRORS'));
16702
16703 WF_ENGINE.SetItemAttrText(p_item_type,
16704 l_childItemKey,
16705 'IS_DEFAULT_COST_CENTER_USED',
16706 WF_ENGINE.GetItemAttrText(p_item_type,
16707 p_item_key,
16708 'IS_DEFAULT_COST_CENTER_USED'));
16709
16710 WF_ENGINE.SetItemAttrText(p_item_type,
16711 l_childItemKey,
16712 'IS_PROJECTS_REPORT',
16713 WF_ENGINE.GetItemAttrText(p_item_type,
16714 p_item_key,
16715 'IS_PROJECTS_REPORT'));
16716
16717
16718
16719
16720 ----------------------------------------------------------------
16721 l_debug_info := 'StartProcess ChildItemKey: ' || l_childItemKey;
16722 ----------------------------------------------------------------
16723 WF_ENGINE.StartProcess(p_item_type,
16724 l_childItemKey);
16725
16726 END LOOP;
16727
16728 WF_ENGINE.SetItemAttrText(p_item_type,
16729 p_item_key,
16730 'AME_CHILD_ITEM_KEY_SEQ',
16731 l_childItemKeySeq);
16732
16733 IF l_approver_exist = 'Y' THEN
16734 p_result := 'COMPLETE:N';
16735 ELSE
16736 p_result := 'COMPLETE:NOAPPROVER';
16737 END IF;
16738
16739 ELSIF (p_funmode = 'CANCEL') THEN
16740 NULL;
16741 END IF;
16742
16743 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end AMERequestApproval');
16744
16745 EXCEPTION
16746 WHEN continue_exception THEN
16747 NULL;
16748 WHEN fixable_exception THEN
16749 -- bug 3257576
16750 WF_ENGINE.SetItemAttrText(p_item_type,
16751 p_item_key,
16752 'NO_APPROVER_PROBLEM',
16753 l_error_message);
16754 WF_ENGINE.SetItemAttrText(p_item_type,
16755 p_item_key,
16756 'NO_APPROVER_INSTRUCTIONS',
16757 l_instructions);
16758 WF_ENGINE.SetItemAttrText(p_item_type,
16759 p_item_key,
16760 'NO_APPROVER_SPECIAL_INSTR',
16761 l_special_instr);
16762
16763 p_result := 'COMPLETE:NOAPPROVER';
16764 WHEN OTHERS THEN
16765 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'AMERequestApproval',
16766 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
16767 raise;
16768 END AMERequestApproval;
16769
16770 /*
16771 Bug 4425821: Uptake AME parallel approvers
16772 Called from AME Request Approval process.
16773 Checks and returns if Action/FYI notification to be sent to the approver.
16774 */
16775 ----------------------------------------------------------------------
16776 PROCEDURE AMEGetApprovalType(p_item_type IN VARCHAR2,
16777 p_item_key IN VARCHAR2,
16778 p_actid IN NUMBER,
16779 p_funmode IN VARCHAR2,
16780 p_result OUT NOCOPY VARCHAR2) IS
16781 ----------------------------------------------------------------------
16782
16783 l_debug_info varchar2(200);
16784 l_ActionOrFyi varchar2(1);
16785 BEGIN
16786
16787 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start AMEGetApprovalType');
16788
16789 IF (p_funmode = 'RUN') THEN
16790
16791 --------------------------------------------------------------
16792 l_debug_info := 'Retrieve AME approval category - Action/FYI';
16793 --------------------------------------------------------------
16794 l_ActionOrFyi := WF_ENGINE.GetItemAttrText(p_item_type,
16795 p_item_key,
16796 'AME_APPROVAL_TYPE');
16797
16798 IF (nvl(l_ActionOrFyi,'A') = 'A') THEN
16799 p_result := 'COMPLETE:A';
16800 ELSE
16801 p_result := 'COMPLETE:F';
16802 END IF;
16803
16804 ELSIF (p_funmode = 'CANCEL') THEN
16805 NULL;
16806 END IF;
16807
16808 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end AMEGetApprovalType');
16809
16810 EXCEPTION
16811 WHEN OTHERS THEN
16812 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'AMEGetApprovalType',
16813 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
16814 raise;
16815 END AMEGetApprovalType;
16816
16817 /*
16818 Bug 4425821: Uptake AME parallel approvers
16819 Called from AME Request Approval Process.
16820 We get the approver response and update the attribute 'AME Approver Response'
16821 with approver response, which would be used in AME Approval Process'.
16822 Update AME of approver response.
16823 */
16824 ----------------------------------------------------------------------
16825 PROCEDURE AMEPropagateApprovalResult(p_item_type IN VARCHAR2,
16826 p_item_key IN VARCHAR2,
16827 p_actid IN NUMBER,
16828 p_funmode IN VARCHAR2,
16829 p_result OUT NOCOPY VARCHAR2) IS
16830 ----------------------------------------------------------------------
16831
16832 l_debug_info varchar2(200);
16833 l_AmeMasterItemKey varchar2(30);
16834 l_approverResponse varchar2(30);
16835 l_approver_id number;
16836 l_response varchar2(80);
16837 l_approvalStatusIn varchar2(20);
16838 l_approver_name varchar2(240);
16839
16840 l_approverIn ame_util.approverRecord2;
16841
16842 l_debug varchar2(3000);
16843 BEGIN
16844
16845 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start AMEPropagateApprovalResult');
16846
16847 IF (p_funmode = 'RUN') THEN
16848
16849 l_AmeMasterItemKey := WF_ENGINE.GetItemAttrText(p_item_type,
16850 p_item_key,
16851 'AME_MASTER_ITEM_KEY');
16852
16853 l_approverResponse := WF_ENGINE.GetItemAttrText(p_item_type,
16854 l_AmeMasterItemKey,
16855 'AME_APPROVER_RESPONSE');
16856
16857 l_response := WF_ENGINE.GetActivityAttrText(p_item_type,
16858 p_item_key,
16859 p_actid,
16860 'RESPONSE');
16861 --------------------------------------------------------------
16862 l_debug_info := 'l_response : '|| l_response ||
16863 'l_approverResponse : '|| l_approverResponse ||
16864 'l_AmeMasterItemKey : '|| l_AmeMasterItemKey;
16865 ---------------------------------------------------------------
16866
16867 IF ((l_approverResponse IS NULL) OR (l_approverResponse <> 'REJECTED'))
16868 AND (l_response IS NOT NULL) THEN
16869 WF_ENGINE.SetItemAttrText(p_item_type,
16870 l_AmeMasterItemKey,
16871 'AME_APPROVER_RESPONSE',
16872 l_response);
16873 IF (l_response = 'REJECTED') THEN
16874 WF_ENGINE.SetItemAttrText(p_item_type,
16875 l_AmeMasterItemKey,
16876 'AME_REJECTED_CHILD_ITEM_KEY',
16877 p_item_key);
16878 END IF;
16879 --bug 6686996
16880 IF (l_response = 'APPROVED') THEN
16881 begin
16882 WF_ENGINE.SetItemAttrText(p_item_type,
16883 l_AmeMasterItemKey,
16884 'AME_APPROVED_CHILD_ITEM_KEY',
16885 p_item_key);
16886 exception
16887 when others then
16888 if (wf_core.error_name = 'WFENG_ITEM_ATTR') then
16889 -- AME_APPROVED_CHILD_ITEM_KEY item attribute doesn't exist, need to add it
16890 WF_ENGINE.AddItemAttr(p_item_type, l_AmeMasterItemKey, 'AME_APPROVED_CHILD_ITEM_KEY');
16891
16892 WF_ENGINE.SetItemAttrText(p_item_type,
16893 l_AmeMasterItemKey,
16894 'AME_APPROVED_CHILD_ITEM_KEY',
16895 p_item_key);
16896 else
16897 raise;
16898 end if;
16899 end;
16900 END IF;
16901 --Bug 6411930: copy approver display name and note from rejected
16902 --child to parent, they are used to display the information in the
16903 --rejection notif to the preparer
16904 WF_ENGINE.SetItemAttrText(p_item_type,
16905 l_AmeMasterItemKey,
16906 'APPROVER_ID',
16907 WF_ENGINE.GetItemAttrText(p_item_type,
16908 p_item_key,
16909 'APPROVER_ID'));
16910 WF_ENGINE.SetItemAttrText(p_item_type,
16911 l_AmeMasterItemKey,
16912 'APPROVER_NAME',
16913 WF_ENGINE.GetItemAttrText(p_item_type,
16914 p_item_key,
16915 'APPROVER_NAME'));
16916 WF_ENGINE.SetItemAttrText(p_item_type,
16917 l_AmeMasterItemKey,
16918 'APPROVER_DISPLAY_NAME',
16919 WF_ENGINE.GetItemAttrText(p_item_type,
16920 p_item_key,
16921 'APPROVER_DISPLAY_NAME'));
16922 WF_ENGINE.SetItemAttrText(p_item_type,
16923 l_AmeMasterItemKey,
16924 'WF_NOTE',
16925 WF_ENGINE.GetItemAttrText(p_item_type,
16926 p_item_key,
16927 'WF_NOTE'));
16928
16929 END IF;
16930
16931 ------------------------------------------------------
16932 l_debug_info := 'Retrieve Approver_ID Item Attribute';
16933 -------------------------------------------------------
16934 l_approver_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
16935 l_AmeMasterItemKey,
16936 'APPROVER_ID');
16937
16938 ------------------------------------------------------
16939 l_debug_info := 'Retrieve Approver_ID Item Attribute';
16940 -------------------------------------------------------
16941 l_approver_name := WF_ENGINE.GetItemAttrText(p_item_type,
16942 p_item_key,
16943 'APPROVER_NAME');
16944
16945 IF (l_response = 'APPROVED') THEN
16946 l_approvalStatusIn := AME_UTIL.approvedStatus;
16947 ELSIF (l_response = 'REJECTED') THEN
16948 l_approvalStatusIn := AME_UTIL.rejectStatus;
16949 ELSIF (l_response = 'NO_RESPONSE') THEN
16950 l_approvalStatusIn := AME_UTIL.noResponseStatus;
16951 ELSIF (l_response = 'FYI') THEN
16952 l_approvalStatusIn := AME_UTIL.notifiedStatus;
16953 END IF;
16954
16955 ------------------------------------------------------------------------------------------
16956 l_debug_info := 'l_response:'|| l_response || 'l_approvalStatusIn:' || l_approvalStatusIn;
16957 ------------------------------------------------------------------------------------------
16958 --IF (l_response <> 'FYI') THEN
16959 IF (l_response = 'NO_RESPONSE') THEN
16960
16961 ------------------------------------------------------
16962 l_debug_info := 'Call AME_API2.updateApprovalStatus ';
16963 ------------------------------------------------------
16964 l_approverIn.name := l_approver_name;
16965 --l_approverIn.orig_system := 'PER';
16966 --l_approverIn.orig_system_id := l_approver_id;
16967 l_approverIn.approval_status := l_approvalStatusIn;
16968
16969 -- Bug 7155445 (sodash) status is updated in postnotif function IsApprovalRequestTransferred
16970 -- Bug: 9861597 Revert 7155445
16971 AME_API2.updateApprovalStatus(applicationIdIn => AP_WEB_DB_UTIL_PKG.GetApplicationID,
16972 transactionTypeIn => p_item_type,
16973 transactionIdIn => l_AmeMasterItemKey,
16974 approverIn => l_approverIn);
16975
16976 /*AME_API2.updateApprovalStatus2(applicationIdIn => AP_WEB_DB_UTIL_PKG.GetApplicationID,
16977 transactionIdIn => l_AmeMasterItemKey,
16978 approvalStatusIn => l_approvalStatusIn,
16979 approverNameIn => l_approver_name,
16980 transactionTypeIn => 'APEXP');
16981 */
16982 END IF;
16983
16984 ------------------------------------------------------
16985 l_debug_info := 'End AMEPropagateApprovalResult ' || l_AmeMasterItemKey ;
16986 ------------------------------------------------------
16987
16988 p_result := 'Y';
16989
16990 ELSIF (p_funmode = 'CANCEL') THEN
16991 NULL;
16992 END IF;
16993
16994 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end AMEPropagateApprovalResult');
16995
16996 EXCEPTION
16997 WHEN OTHERS THEN
16998 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'AMEPropagateApprovalResult',
16999 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
17000 raise;
17001 END AMEPropagateApprovalResult;
17002
17003 /*
17004 Bug 4425821: Uptake AME parallel approvers
17005 Called from AME Approval Process.
17006 Checks for Approver Response which is tracked in attribute 'AME Approver Response'
17007 Result : Approve/Reject
17008 */
17009 ----------------------------------------------------------------------
17010 PROCEDURE AMEGetApprovalResult(p_item_type IN VARCHAR2,
17011 p_item_key IN VARCHAR2,
17012 p_actid IN NUMBER,
17013 p_funmode IN VARCHAR2,
17014 p_result OUT NOCOPY VARCHAR2) IS
17015 ----------------------------------------------------------------------
17016
17017 l_debug_info varchar2(200);
17018 l_approverResponse varchar2(30);
17019 BEGIN
17020
17021 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start AMEGetApprovalResult');
17022
17023 IF (p_funmode = 'RUN') THEN
17024
17025 --------------------------------------------------------------
17026 l_debug_info := 'Check Approver Response - APPROVED/REJECTED';
17027 --------------------------------------------------------------
17028 l_approverResponse := WF_ENGINE.GetItemAttrText(p_item_type,
17029 p_item_key,
17030 'AME_APPROVER_RESPONSE');
17031
17032 IF (l_approverResponse = 'APPROVED') THEN
17033 p_result := 'COMPLETE:APPROVED';
17034 ELSIF (l_approverResponse = 'REJECTED') THEN
17035 p_result := 'COMPLETE:REJECTED';
17036 ELSIF (l_approverResponse = 'FYI') THEN
17037 p_result := 'COMPLETE:FYI';
17038 ELSIF (l_approverResponse = 'NO_RESPONSE') THEN
17039 p_result := 'COMPLETE:NO_RESPONSE';
17040 END IF;
17041
17042 ELSIF (p_funmode = 'CANCEL') THEN
17043 NULL;
17044 END IF;
17045
17046 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end AMEGetApprovalResult');
17047
17048 EXCEPTION
17049 WHEN OTHERS THEN
17050 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'AMEGetApprovalResult',
17051 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
17052 raise;
17053 END AMEGetApprovalResult;
17054
17055 /*
17056 Bug 4425821: Uptake AME parallel approvers
17057 Called from AME Request Approval Process.
17058 Completes Block Activity in 'AME Approval Process'.
17059 */
17060 ----------------------------------------------------------------------
17061 PROCEDURE AMECompleteApproval(p_item_type IN VARCHAR2,
17062 p_item_key IN VARCHAR2,
17063 p_actid IN NUMBER,
17064 p_funmode IN VARCHAR2,
17065 p_result OUT NOCOPY VARCHAR2) IS
17066 ----------------------------------------------------------------------
17067
17068 l_debug_info varchar2(200);
17069 l_AmeMasterItemKey varchar2(30);
17070 l_err_name varchar2(30);
17071 l_err_msg varchar2(2000);
17072 l_err_stack varchar2(32000);
17073 l_check_error varchar2(1);
17074 l_result varchar2(1);
17075
17076 l_approvalProcessCompleteYNOut varchar2(1);
17077 l_nextApproversOut ame_util.approversTable2;
17078
17079 BEGIN
17080
17081 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start AMECompleteApproval');
17082
17083 IF (p_funmode = 'RUN') THEN
17084
17085 l_AmeMasterItemKey := WF_ENGINE.GetItemAttrText(p_item_type,
17086 p_item_key,
17087 'AME_MASTER_ITEM_KEY');
17088
17089 ------------------------------------------------------
17090 l_debug_info := 'Call CompleteActivity ' || l_AmeMasterItemKey ;
17091 ------------------------------------------------------
17092 begin
17093 WF_ENGINE.CompleteActivity(itemtype => p_item_type,
17094 itemkey => l_AmeMasterItemKey,
17095 activity => 'AME_APPROVAL_BLOCK',
17096 result => null);
17097 l_result := 'Y';
17098 exception
17099 WHEN others THEN
17100
17101 l_check_error := WF_ENGINE.GetActivityAttrText(p_item_type,
17102 p_item_key,
17103 p_actid,
17104 'CHECK_ERROR');
17105 if l_check_error = 'Y' then
17106 wf_core.get_error(l_err_name, l_err_msg, l_err_stack);
17107 if (l_err_name = 'WFENG_NOT_NOTIFIED') then
17108 l_result := 'N';
17109 else
17110 raise;
17111 end if;
17112 else
17113 -- if approval is complete, complete as 'Y' to avoid error notification
17114 -- from being sent to sysadmin
17115 AME_API2.getNextApprovers4(applicationIdIn => AP_WEB_DB_UTIL_PKG.GetApplicationID,
17116 transactionTypeIn => p_item_type,
17117 transactionIdIn => l_AmeMasterItemKey,
17118 approvalProcessCompleteYNOut => l_approvalProcessCompleteYNOut,
17119 nextApproversOut => l_nextApproversOut);
17120
17121 if (l_approvalProcessCompleteYNOut = ame_util.booleanTrue) then
17122 l_result := 'Y';
17123 else
17124 raise;
17125 end if; -- end if l_approvalProcessCompleteYNOut
17126 end if; -- end if l_check_error = 'Y'
17127
17128 end;
17129
17130
17131 ------------------------------------------------------
17132 l_debug_info := 'End CompleteActivity ' || l_AmeMasterItemKey ;
17133 ------------------------------------------------------
17134 if (nvl(l_result,'N') = 'N') then
17135 p_result := 'COMPLETE:N';
17136 else
17137 p_result := 'COMPLETE:Y';
17138 end if;
17139
17140 ELSIF (p_funmode = 'CANCEL') THEN
17141 NULL;
17142 END IF;
17143
17144 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end AMECompleteApproval');
17145
17146 EXCEPTION
17147 WHEN OTHERS THEN
17148 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'AMECompleteApproval',
17149 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
17150 raise;
17151 END AMECompleteApproval;
17152
17153 /*
17154 Bug 4425821: Uptake AME parallel approvers
17155 Called from AME Approval Process.
17156 Gets the current pending approvers, if the pending approvers is > 1 then
17157 set expense_current_approver_id to -99999, if there is only one pending
17158 approver then set expense_current_approver_id to the approver id.
17159 We need to set it to -99999 inorder to distinguish if there is a single or
17160 multiple current approvers, when displaying current approver in Track Submitted
17161 Expense Reports table in Home Page.
17162 */
17163 ----------------------------------------------------------------------
17164 PROCEDURE AMESetCurrentApprover(p_item_type IN VARCHAR2,
17165 p_item_key IN VARCHAR2,
17166 p_actid IN NUMBER,
17167 p_funmode IN VARCHAR2,
17168 p_result OUT NOCOPY VARCHAR2) IS
17169 ----------------------------------------------------------------------
17170 l_debug_info varchar2(200);
17171 l_approvalProcessCompleteYNOut varchar2(10);
17172 l_approversOut ame_util.approversTable2;
17173 l_report_header_id number;
17174 BEGIN
17175
17176 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start AMESetCurrentApprover');
17177
17178 IF (p_funmode = 'RUN') THEN
17179
17180 l_report_header_id := to_char(p_item_key);
17181 -------------------------------------------------------
17182 l_debug_info := 'Calling ame_api2.getpendingapprovers';
17183 -------------------------------------------------------
17184 ame_api2.getpendingapprovers(applicationidin => AP_WEB_DB_UTIL_PKG.GetApplicationID,
17185 transactiontypein => p_item_type,
17186 transactionidin => p_item_key,
17187 approvalprocesscompleteynout => l_approvalProcessCompleteYNOut,
17188 approversout => l_approversOut);
17189
17190 if (l_approversOut.count > 1) then
17191 UPDATE ap_expense_report_headers_all
17192 SET expense_current_approver_id = C_AME_MULTIPLE_CURR_APPROVER
17193 WHERE report_header_id = l_report_header_id;
17194 elsif (l_approversOut.count = 1) then
17195 UPDATE ap_expense_report_headers_all
17196 SET expense_current_approver_id = l_approversOut(1).orig_system_id,
17197 approval_type = l_approversOut(1).orig_system
17198 WHERE report_header_id = l_report_header_id;
17199 end if;
17200
17201 p_result := 'COMPLETE';
17202
17203 ELSIF (p_funmode = 'CANCEL') THEN
17204 NULL;
17205 END IF;
17206
17207 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end AMESetCurrentApprover');
17208
17209 EXCEPTION
17210 WHEN OTHERS THEN
17211 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'AMESetCurrentApprover',
17212 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
17213 raise;
17214 END AMESetCurrentApprover;
17215
17216 ---------------------------------------------------------------------------
17217 FUNCTION IsExpAccountsUpdated(p_report_line_id IN NUMBER)
17218 RETURN VARCHAR2 IS
17219 -----------------------------------------------------------------------
17220 l_ExpAccountsUpdated VARCHAR2(10);
17221 BEGIN
17222
17223 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start IsExpAccountsUpdated');
17224
17225 select decode(nvl(preparer_modified_flag, 'N'), 'Y', AP_WEB_FND_LOOKUPS_PKG.getYesNoMeaning('Y'), null)
17226 into l_ExpAccountsUpdated
17227 from ap_exp_report_dists
17228 where report_line_id = p_report_line_id
17229 and rownum = 1;
17230
17231
17232 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end IsExpAccountsUpdated');
17233
17234 RETURN l_ExpAccountsUpdated;
17235
17236 EXCEPTION
17237 WHEN OTHERS THEN
17238 RETURN l_ExpAccountsUpdated;
17239 END IsExpAccountsUpdated;
17240
17241 FUNCTION getItemKey(p_notification_id IN NUMBER) RETURN VARCHAR2 IS
17242 l_context wf_notifications.context%type;
17243 l_temp_context wf_notifications.context%type;
17244 l_item_key wf_notifications.context%type;
17245 l_debug_info varchar2(200);
17246 BEGIN
17247 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start getItemKey');
17248
17249 select context into l_context
17250 from wf_notifications
17251 where notification_id = p_notification_id;
17252
17253 --l_context would have something like 'APEXP:22591-2:579934'
17254
17255 l_temp_context := substr(l_context,instrb(l_context, ':')+1); --'22591-2:579934'
17256 l_item_key := substr(l_temp_context,1,instrb(l_temp_context, ':')-1); --'22591-2'
17257
17258 return l_item_key;
17259
17260 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end getItemKey');
17261 EXCEPTION
17262 WHEN OTHERS THEN
17263 AP_WEB_DB_UTIL_PKG.RaiseException('AP_WEB_EXPENSE_WF.getItemKey',
17264 l_debug_info);
17265 APP_EXCEPTION.RAISE_EXCEPTION;
17266 END getItemKey;
17267
17268 ----------------------------------------------------------------------
17269 PROCEDURE IsPreparerActive(p_item_type IN VARCHAR2,
17270 p_item_key IN VARCHAR2,
17271 p_actid IN NUMBER,
17272 p_funmode IN VARCHAR2,
17273 p_result OUT NOCOPY VARCHAR2) IS
17274 ----------------------------------------------------------------------
17275 l_person_id NUMBER := NULL;
17276
17277 l_debug_info VARCHAR2(200);
17278
17279 BEGIN
17280
17281 IF (p_funmode = 'RUN') THEN
17282
17283 ---------------------------------------------------------------
17284 l_debug_info := 'Retrieve Employee Id Item Attribute';
17285 ---------------------------------------------------------------
17286 l_person_id := WF_ENGINE.GetItemAttrText(p_item_type,
17287 p_item_key,
17288 'PREPARER_ID');
17289
17290 -- Check whether person is active
17291 IF (AP_WEB_DB_HR_INT_PKG.isPersonActive(l_person_id)='Y') THEN
17292 p_result := 'COMPLETE:Y';
17293 ELSE
17294 p_result := 'COMPLETE:N';
17295 END IF;
17296
17297 ELSIF (p_funmode = 'CANCEL') THEN
17298 NULL;
17299 END IF;
17300
17301 EXCEPTION
17302 WHEN OTHERS THEN
17303 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'IsPreparerActive',
17304 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
17305 raise;
17306 END IsPreparerActive;
17307
17308 ----------------------------------------------------------------------
17309 PROCEDURE WaitForImagedReceipts(p_item_type IN VARCHAR2,
17310 p_item_key IN VARCHAR2,
17311 p_actid IN NUMBER,
17312 p_funmode IN VARCHAR2,
17313 p_result OUT NOCOPY VARCHAR2) IS
17314 ----------------------------------------------------------------------
17315 l_report_header_id AP_WEB_DB_EXPRPT_PKG.expHdr_headerID;
17316 l_req_mgr_appr VARCHAR2(1);
17317 l_img_recpt_status VARCHAR2(30);
17318 BEGIN
17319 IF (p_funmode = 'RUN') THEN
17320 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
17321 p_item_key,
17322 'EXPENSE_REPORT_ID');
17323 IF (l_report_header_id IS NULL) THEN
17324 p_result := 'COMPLETE:N';
17325 ELSE
17326 select nvl(rs.image_req_appr_flag,'X'),
17327 nvl(aerh.image_receipts_status, 'NOT_REQUIRED') into l_req_mgr_appr,l_img_recpt_status
17328 from ap_expense_report_headers aerh,
17329 ap_aud_rule_sets rs,
17330 ap_aud_rule_assignments_all rsa
17331 where aerh.report_header_id = l_report_header_id
17332 and aerh.org_id = rsa.org_id
17333 and rsa.rule_set_id = rs.rule_set_id
17334 and rs.rule_set_type = 'RECEIPT'
17335 and TRUNC(nvl(aerh.report_submitted_date,SYSDATE))
17336 BETWEEN TRUNC(NVL(rsa.START_DATE,SYSDATE))
17337 AND TRUNC(NVL(rsa.END_DATE,SYSDATE));
17338
17339 IF (l_req_mgr_appr = 'Y' AND l_img_recpt_status NOT IN ('RECEIVED','NOT_REQUIRED')) THEN
17340
17341 update ap_expense_report_headers_all
17342 set expense_status_code = 'PENDING_IMAGE_SUBMISSION'
17343 where report_header_id = l_report_header_id;
17344
17345 p_result := 'COMPLETE:Y';
17346 ELSE
17347 p_result := 'COMPLETE:N';
17348 END IF;
17349 END IF;
17350 END IF;
17351 EXCEPTION
17352 WHEN NO_DATA_FOUND THEN
17353 p_result := 'COMPLETE:N';
17354 END WaitForImagedReceipts;
17355
17356 PROCEDURE CompleteReceiptsBlock(p_report_header_id IN VARCHAR2) IS
17357 BEGIN
17358
17359 WF_ENGINE.CompleteActivity('APEXP',
17360 p_report_header_id,
17361 'HOLD_FOR_IMAGE_RECEIPTS',
17362 '');
17363
17364 EXCEPTION
17365 WHEN OTHERS THEN
17366 NULL;
17367 END CompleteReceiptsBlock;
17368
17369 ----------------------------------------------------------------------
17370 PROCEDURE CheckForManagerReApproval(p_item_type IN VARCHAR2,
17371 p_item_key IN VARCHAR2,
17372 p_actid IN NUMBER,
17373 p_funmode IN VARCHAR2,
17374 p_result OUT NOCOPY VARCHAR2) IS
17375 ----------------------------------------------------------------------
17376 l_re_appr_flag VARCHAR2(1);
17377 l_report_header_id AP_WEB_DB_EXPRPT_PKG.expHdr_headerID;
17378 BEGIN
17379
17380 IF (p_funmode = 'RUN') THEN
17381 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
17382 p_item_key,
17383 'EXPENSE_REPORT_ID');
17384 IF (l_report_header_id IS NULL) THEN
17385 p_result := 'COMPLETE:N';
17386 ELSE
17387 select nvl(rs.req_reappr_flag,'X')
17388 into l_re_appr_flag
17389 from ap_expense_report_headers aerh,
17390 ap_aud_rule_sets rs,
17391 ap_aud_rule_assignments_all rsa
17392 where aerh.report_header_id = l_report_header_id
17393 and aerh.org_id = rsa.org_id
17394 and rsa.rule_set_id = rs.rule_set_id
17395 and rs.rule_set_type = 'RECEIPT'
17396 and TRUNC(nvl(aerh.report_submitted_date,SYSDATE))
17397 BETWEEN TRUNC(NVL(rsa.START_DATE,SYSDATE))
17398 AND TRUNC(NVL(rsa.END_DATE,SYSDATE));
17399
17400 IF(l_re_appr_flag = 'Y') THEN
17401 p_result := 'COMPLETE:Y';
17402 ELSE
17403 p_result := 'COMPLETE:N';
17404 END IF;
17405 END IF;
17406
17407
17408 END IF;
17409 EXCEPTION
17410 WHEN NO_DATA_FOUND THEN
17411 p_result := 'COMPLETE:N';
17412
17413 END CheckForManagerReApproval;
17414
17415 ----------------------------------------------------------------------
17416 PROCEDURE SetImageReceiptsStatus(p_item_type IN VARCHAR2,
17417 p_item_key IN VARCHAR2,
17418 p_actid IN NUMBER,
17419 p_funmode IN VARCHAR2,
17420 p_result OUT NOCOPY VARCHAR2) IS
17421 ----------------------------------------------------------------------
17422
17423 l_report_header_id AP_WEB_DB_EXPRPT_PKG.expHdr_headerID;
17424 l_image_receipts_status VARCHAR2(50);
17425 BEGIN
17426
17427 IF (p_funmode = 'RUN') THEN
17428
17429 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
17430 p_item_key,
17431 'EXPENSE_REPORT_ID');
17432 l_image_receipts_status := WF_ENGINE.GetActivityAttrText(p_item_type,
17433 p_item_key,
17434 p_actid,
17435 'IMAGE_RECEIPTS_STATUS');
17436
17437 UPDATE ap_expense_report_headers
17438 SET image_receipts_status = l_image_receipts_status,
17439 last_update_date = sysdate,
17440 last_updated_by = Decode(Nvl(fnd_global.user_id,-1),-1,last_updated_by,fnd_global.user_id)
17441 WHERE report_header_id = l_report_header_id;
17442
17443
17444
17445 END IF;
17446
17447 END SetImageReceiptsStatus;
17448
17449 ----------------------------------------------------------------------
17450 PROCEDURE SetOriginalReceiptsStatus(p_item_type IN VARCHAR2,
17451 p_item_key IN VARCHAR2,
17452 p_actid IN NUMBER,
17453 p_funmode IN VARCHAR2,
17454 p_result OUT NOCOPY VARCHAR2) IS
17455 ----------------------------------------------------------------------
17456
17457 l_report_header_id AP_WEB_DB_EXPRPT_PKG.expHdr_headerID;
17458 l_orig_receipts_status VARCHAR2(50);
17459 BEGIN
17460
17461 IF (p_funmode = 'RUN') THEN
17462
17463 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
17464 p_item_key,
17465 'EXPENSE_REPORT_ID');
17466
17467 l_orig_receipts_status := WF_ENGINE.GetActivityAttrText(p_item_type,
17468 p_item_key,
17469 p_actid,
17470 'ORIGINAL_RECEIPTS_STATUS');
17471
17472
17473 UPDATE ap_expense_report_headers
17474 SET receipts_status = l_orig_receipts_status,
17475 last_update_date = sysdate,
17476 last_updated_by = Decode(Nvl(fnd_global.user_id,-1),-1,last_updated_by,fnd_global.user_id)
17477 WHERE report_header_id = l_report_header_id;
17478
17479
17480
17481 END IF;
17482
17483 END SetOriginalReceiptsStatus;
17484
17485 ----------------------------------------------------------------------
17486 PROCEDURE UpdateExpenseStatusCode(p_item_type IN VARCHAR2,
17487 p_item_key IN VARCHAR2,
17488 p_actid IN NUMBER,
17489 p_funmode IN VARCHAR2,
17490 p_result OUT NOCOPY VARCHAR2) IS
17491 ----------------------------------------------------------------------
17492
17493 l_report_header_id AP_WEB_DB_EXPRPT_PKG.expHdr_headerID;
17494 l_expense_status_code VARCHAR2(50);
17495 BEGIN
17496
17497 IF (p_funmode = 'RUN') THEN
17498
17499 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
17500 p_item_key,
17501 'EXPENSE_REPORT_ID');
17502
17503 l_expense_status_code := WF_ENGINE.GetActivityAttrText(p_item_type,
17504 p_item_key,
17505 p_actid,
17506 'EXPENSE_STATUS_CODE');
17507
17508
17509 UPDATE ap_expense_report_headers
17510 SET expense_status_code = l_expense_status_code,
17511 last_update_date = sysdate,
17512 last_updated_by = Decode(Nvl(fnd_global.user_id,-1),-1,last_updated_by,fnd_global.user_id)
17513 WHERE report_header_id = l_report_header_id;
17514
17515
17516
17517 END IF;
17518
17519 END UpdateExpenseStatusCode;
17520
17521 ----------------------------------------------------------------------
17522 PROCEDURE CheckShortPayRecptType(p_item_type IN VARCHAR2,
17523 p_item_key IN VARCHAR2,
17524 p_actid IN NUMBER,
17525 p_funmode IN VARCHAR2,
17526 p_result OUT NOCOPY VARCHAR2) IS
17527 ----------------------------------------------------------------------
17528 l_receipts_issue number;
17529 l_line_count number;
17530 l_shortpay_count number;
17531 l_policy_count number;
17532 l_img_count number;
17533 l_both_count number;
17534 l_report_header_id AP_WEB_DB_EXPRPT_PKG.expHdr_headerID;
17535 BEGIN
17536 IF (p_funmode = 'RUN') THEN
17537 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
17538 p_item_key,
17539 'EXPENSE_REPORT_ID');
17540 SELECT count(*) into l_line_count FROM ap_expense_report_lines
17541 WHERE report_header_id = l_report_header_id;
17542
17543 IF (NOT AP_WEB_DB_EXPLINE_PKG.GetNumShortpaidLines(l_report_header_id, l_shortpay_count)) THEN
17544 l_shortpay_count := 0;
17545 END IF;
17546
17547 IF (NOT AP_WEB_DB_EXPLINE_PKG.GetNumPolicyShortpaidLines(l_report_header_id, l_policy_count)) THEN
17548 l_policy_count := 0;
17549 END IF;
17550
17551 IF (NOT AP_WEB_DB_EXPLINE_PKG.GetNumOriginalShortpaidLines(l_report_header_id, l_receipts_issue)) THEN
17552 l_receipts_issue := 0;
17553 END IF;
17554
17555 IF (NOT AP_WEB_DB_EXPLINE_PKG.GetNumImageShortpaidLines(l_report_header_id, l_img_count)) THEN
17556 l_img_count := 0;
17557 END IF;
17558
17559 IF (NOT AP_WEB_DB_EXPLINE_PKG.GetNumBothShortpaidLines(l_report_header_id, l_both_count)) THEN
17560 l_both_count := 0;
17561 END IF;
17562
17563 --l_receipts_issue := l_shortpay_count - l_policy_count - l_img_count - l_both_count;
17564
17565
17566 IF (l_receipts_issue > 0) THEN
17567 p_result := 'COMPLETE:ORIGINAL';
17568 ELSIF(l_img_count > 0) THEN
17569 p_result := 'COMPLETE:IMAGE';
17570 ELSIF(l_both_count > 0) THEN
17571 p_result := 'COMPLETE:BOTH';
17572 ELSE
17573 p_result := 'COMPLETE:NONE';
17574 END IF;
17575 END IF;
17576 EXCEPTION
17577 WHEN NO_DATA_FOUND THEN
17578 p_result := 'COMPLETE:NONE';
17579
17580 END CheckShortPayRecptType;
17581
17582 -------------------------------------------------------------------------------------
17583 FUNCTION GetImageMissingJustification(p_report_header_id IN NUMBER) RETURN VARCHAR2 IS
17584 --------------------------------------------------------------------------------------
17585 l_missing_image_just AP_EXPENSE_REPORT_HEADERS.MISSING_IMG_JUST%TYPE;
17586 BEGIN
17587
17588 SELECT missing_img_just
17589 INTO l_missing_image_just
17590 FROM ap_expense_report_headers
17591 WHERE report_header_id = p_report_header_id;
17592
17593 RETURN l_missing_image_just;
17594 EXCEPTION
17595 WHEN OTHERS THEN
17596 return NULL;
17597
17598 END GetImageMissingJustification;
17599
17600 -------------------------------------------------------------------------------------
17601 FUNCTION IsBothPayReportExists(p_report_header_id IN NUMBER) RETURN BOOLEAN IS
17602 -------------------------------------------------------------------------------------
17603 l_report_header_id AP_EXPENSE_REPORT_HEADERS.REPORT_HEADER_ID%TYPE;
17604 BEGIN
17605
17606 SELECT report_header_id INTO l_report_header_id
17607 FROM ap_expense_report_headers where bothpay_parent_id = p_report_header_id;
17608
17609 RETURN TRUE;
17610
17611 EXCEPTION
17612 WHEN OTHERS THEN
17613 RETURN FALSE;
17614
17615 END IsBothPayReportExists;
17616
17617 FUNCTION CheckSurrogateManager(p_employeeId IN NUMBER,
17618 p_manager_id IN NUMBER,
17619 p_surrogate_mgr_id IN NUMBER) RETURN BOOLEAN IS
17620 l_temp_manager NUMBER;
17621 BEGIN
17622
17623 IF (p_surrogate_mgr_id IS NULL OR p_employeeId = p_surrogate_mgr_id OR p_manager_id IS NULL) THEN
17624 RETURN FALSE;
17625 END IF;
17626
17627 AP_WEB_EXPENSE_WF.GetManager(p_manager_id, l_temp_manager);
17628 IF (l_temp_manager IS NULL) THEN
17629 RETURN TRUE;
17630 END IF;
17631
17632 RETURN FALSE;
17633 END CheckSurrogateManager;
17634
17635
17636 END AP_WEB_EXPENSE_WF;